Skip to content

Commit b1cf6fa

Browse files
committed
Merge remote-tracking branch 'origin/master' into fix-flutter-websocket-issues
2 parents d3de115 + 3ca24dd commit b1cf6fa

File tree

25 files changed

+280
-57
lines changed

25 files changed

+280
-57
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ env:
2929
- SDK=DartStable
3030
- SDK=Deno1171
3131
- SDK=FlutterStable
32+
- SDK=FlutterBeta
3233
- SDK=Go112
3334
- SDK=Go118
34-
# - SDK=FlutterBeta
3535
- SDK=KotlinJava8
3636
- SDK=KotlinJava11
3737
- SDK=KotlinJava17

src/SDK/Language/Swift.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ public function getFiles(): array
176176
],
177177
[
178178
'scope' => 'default',
179-
'destination' => '/Sources/{{ spec.title | caseUcfirst}}/Extensions/Codable+JSON.swift',
180-
'template' => 'swift/Sources/Extensions/Codable+JSON.swift.twig',
179+
'destination' => '/Sources/JSONCodable/Codable+JSON.swift',
180+
'template' => 'swift/Sources/JSONCodable/Codable+JSON.swift.twig',
181181
],
182182
[
183183
'scope' => 'default',

templates/android/library/src/main/java/io/appwrite/services/ServiceTemplate.kt.twig

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ class {{ service.name | caseUcfirst }} : Service {
6262
{%~ for parameter in method.parameters.query | merge(method.parameters.body) %}
6363
"{{ parameter.name }}" to {{ parameter.name | caseCamel }},
6464
{%~ endfor %}
65+
{%~ if method.auth | length > 0 %}
66+
{%~ for node in method.auth %}
67+
{%~ for key,header in node | keys %}
68+
"{{ header | caseLower }}" to client.config["{{ header | caseLower }}"],
69+
{%~ endfor %}
70+
{%~ endfor %}
71+
{%~ endif %}
6572
)
6673
{%~ if method.type == 'webAuth' %}
6774
val query = mutableListOf<String>()
@@ -121,11 +128,11 @@ class {{ service.name | caseUcfirst }} : Service {
121128
)
122129
{%~ if method.responseModel %}
123130
val converter: (Any) -> {{ method | returnType(spec, sdk.namespace | caseDot) | raw }} = {
124-
{% if method.responseModel == 'any' %}
131+
{%~ if method.responseModel == 'any' %}
125132
it
126-
{% else %}
127-
{{sdk.namespace | caseDot}}.models.{{ method.responseModel | caseUcfirst }}.from(map = it as Map<String, Any>{% if method.responseModel | hasGenericType(spec) %}, nestedType{% endif %})
128-
{% endif %}
133+
{%~ else %}
134+
{{sdk.namespace | caseDot}}.models.{{ method.responseModel | caseUcfirst }}.from(map = it as Map<String, Any>{% if method.responseModel | hasGenericType(spec) %}, nestedType{% endif %})
135+
{%~ endif %}
129136
}
130137
{%~ endif %}
131138
{%~ if 'multipart/form-data' in method.consumes %}

templates/cli/lib/commands/deploy.js.twig

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const inquirer = require("inquirer");
22
const JSONbig = require("json-bigint")({ storeAsString: false });
33
const { Command } = require("commander");
44
const { localConfig } = require("../config");
5-
const { questionsDeployFunctions, questionsGetEntrypoint, questionsDeployCollections, questionsConfirmDeployCollections } = require("../questions");
5+
const { questionsDeployTeams, questionsDeployFunctions, questionsGetEntrypoint, questionsDeployCollections, questionsConfirmDeployCollections } = require("../questions");
66
const { actionRunner, success, log, error, commandDescriptions } = require("../parser");
77
const { functionsGet, functionsCreate, functionsUpdate, functionsCreateDeployment, functionsUpdateDeployment, functionsListVariables, functionsDeleteVariable, functionsCreateVariable } = require('./functions');
88
const {
@@ -25,6 +25,11 @@ const {
2525
databasesListIndexes,
2626
databasesDeleteIndex
2727
} = require("./databases");
28+
const {
29+
teamsGet,
30+
teamsUpdate,
31+
teamsCreate
32+
} = require("./teams");
2833

2934
const POOL_DEBOUNCE = 2000; // in milliseconds
3035
const POOL_MAX_DEBOUNCES = 30;
@@ -593,6 +598,76 @@ const deployCollection = async ({ all, yes } = {}) => {
593598
}
594599
}
595600

601+
const deployTeam = async ({ all, yes } = {}) => {
602+
let response = {};
603+
604+
let teamIds = [];
605+
const configTeams = localConfig.getTeams();
606+
607+
if(all) {
608+
if (configTeams.length === 0) {
609+
throw new Error("No teams found in the current directory. Run `appwrite init team` to fetch all your teams.");
610+
}
611+
teamIds.push(...configTeams.map((t) => t.$id));
612+
}
613+
614+
if(teamIds.length === 0) {
615+
let answers = await inquirer.prompt(questionsDeployTeams[0])
616+
teamIds.push(...answers.teams);
617+
}
618+
619+
let teams = [];
620+
621+
for(const teamId of teamIds) {
622+
const idTeams = configTeams.filter((t) => t.$id === teamId);
623+
teams.push(...idTeams);
624+
}
625+
626+
for (let team of teams) {
627+
log(`Deploying team ${team.name} ( ${team['$id']} )`)
628+
629+
try {
630+
response = await teamsGet({
631+
teamId: team['$id'],
632+
parseOutput: false,
633+
})
634+
log(`Team ${team.name} ( ${team['$id']} ) already exists.`);
635+
636+
if(!yes) {
637+
answers = await inquirer.prompt(questionsDeployTeams[1])
638+
if (answers.override !== "YES") {
639+
log(`Received "${answers.override}". Skipping ${team.name} ( ${team['$id']} )`);
640+
continue;
641+
}
642+
}
643+
644+
log(`Updating team ...`)
645+
646+
await teamsUpdate({
647+
teamId: team['$id'],
648+
name: team.name,
649+
parseOutput: false
650+
});
651+
652+
success(`Deployed ${team.name} ( ${team['$id']} )`);
653+
} catch (e) {
654+
if (e.code == 404) {
655+
log(`Team ${team.name} does not exist in the project. Creating ... `);
656+
657+
response = await teamsCreate({
658+
teamId: team['$id'],
659+
name: team.name,
660+
parseOutput: false
661+
})
662+
663+
success(`Deployed ${team.name} ( ${team['$id']} )`);
664+
} else {
665+
throw e;
666+
}
667+
}
668+
}
669+
}
670+
596671
deploy
597672
.command("function")
598673
.description("Deploy functions in the current directory.")
@@ -608,6 +683,13 @@ deploy
608683
.option(`--yes`, `Flag to confirm all warnings`)
609684
.action(actionRunner(deployCollection));
610685

686+
deploy
687+
.command("team")
688+
.description("Deploy teams in the current project.")
689+
.option(`--all`, `Flag to deploy all teams`)
690+
.option(`--yes`, `Flag to confirm all warnings`)
691+
.action(actionRunner(deployTeam));
692+
611693
module.exports = {
612694
deploy
613695
}

templates/cli/lib/commands/init.js.twig

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const path = require("path");
33
const childProcess = require('child_process');
44
const { Command } = require("commander");
55
const inquirer = require("inquirer");
6-
const { teamsCreate } = require("./teams");
6+
const { teamsCreate, teamsList } = require("./teams");
77
const { projectsCreate } = require("./projects");
88
const { functionsCreate } = require("./functions");
99
const { databasesListCollections, databasesList } = require("./databases");
@@ -186,6 +186,24 @@ const initCollection = async ({ all, databaseId } = {}) => {
186186
success();
187187
}
188188

189+
const initTeam = async () => {
190+
// TODO: Pagination?
191+
let response = await teamsList({
192+
queries: [ 'limit(100)' ],
193+
parseOutput: false
194+
})
195+
196+
let teams = response.teams;
197+
log(`Found ${teams.length} teams`);
198+
199+
teams.forEach(async team => {
200+
log(`Fetching ${team.name} ...`);
201+
localConfig.addTeam(team);
202+
});
203+
204+
success();
205+
}
206+
189207
init
190208
.command("project")
191209
.description("Initialise your {{ spec.title|caseUcfirst }} project")
@@ -203,6 +221,11 @@ init
203221
.option(`--all`, `Flag to initialize all databases`)
204222
.action(actionRunner(initCollection))
205223

224+
init
225+
.command("team")
226+
.description("Initialise your Appwrite teams")
227+
.action(actionRunner(initTeam))
228+
206229
module.exports = {
207230
init,
208231
};

templates/cli/lib/config.js.twig

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,45 @@ class Local extends Config {
166166
this.set("collections", collections);
167167
}
168168

169+
getTeams() {
170+
if (!this.has("teams")) {
171+
return [];
172+
}
173+
return this.get("teams");
174+
}
175+
176+
getTeam($id) {
177+
if (!this.has("teams")) {
178+
return {};
179+
}
180+
181+
let teams = this.get("teams");
182+
for (let i = 0; i < teams.length; i++) {
183+
if (teams[i]['$id'] == $id) {
184+
return teams[i];
185+
}
186+
}
187+
188+
return {};
189+
}
190+
191+
addTeam(props) {
192+
if (!this.has("teams")) {
193+
this.set("teams", []);
194+
}
195+
196+
let teams = this.get("teams");
197+
for (let i = 0; i < teams.length; i++) {
198+
if (teams[i]['$id'] == props['$id']) {
199+
teams[i] = props;
200+
this.set("teams", teams);
201+
return;
202+
}
203+
}
204+
teams.push(props);
205+
this.set("teams", teams);
206+
}
207+
169208
getProject() {
170209
if (!this.has("projectId") || !this.has("projectName")) {
171210
return {};

templates/cli/lib/questions.js.twig

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,39 @@ const questionsGetEntrypoint = [
300300
},
301301
]
302302

303+
const questionsDeployTeams = [
304+
{
305+
type: "checkbox",
306+
name: "teams",
307+
message: "Which teams would you like to deploy?",
308+
choices: () => {
309+
let teams = localConfig.getTeams();
310+
if (teams.length === 0) {
311+
throw new Error("No teams found in the current directory. Run `appwrite init team` to fetch all your teams.");
312+
}
313+
let choices = teams.map((team, idx) => {
314+
return {
315+
name: `${team.name} (${team['$id']})`,
316+
value: team.$id
317+
}
318+
})
319+
return choices;
320+
}
321+
},
322+
{
323+
type: "input",
324+
name: "override",
325+
message: 'Are you sure you want to override this team? This can lead to loss of data! Type "YES" to confirm.'
326+
},
327+
]
328+
303329
module.exports = {
304330
questionsInitProject,
305331
questionsLogin,
306332
questionsInitFunction,
307333
questionsInitCollection,
308334
questionsDeployFunctions,
309335
questionsDeployCollections,
336+
questionsDeployTeams,
310337
questionsGetEntrypoint
311338
};

templates/dart/lib/id.dart.twig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
part of {{ language.params.packageName }};
22

33
class ID {
4+
ID._();
5+
46
static String unique() {
57
return 'unique()';
68
}

templates/dart/lib/permission.dart.twig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
part of {{ language.params.packageName }};
22

33
class Permission {
4+
Permission._();
5+
46
static String read(String role) {
57
return 'read("$role")';
68
}

templates/dart/lib/query.dart.twig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
part of {{ language.params.packageName }};
22

33
class Query {
4+
Query._();
5+
46
static equal(String attribute, dynamic value) =>
57
_addQuery(attribute, 'equal', value);
68

0 commit comments

Comments
 (0)