Skip to content

Commit 9e1c024

Browse files
committed
Merge remote-tracking branch 'origin/master' into fix-deno-missing-library
2 parents ce07089 + 263ecd9 commit 9e1c024

File tree

19 files changed

+289
-79
lines changed

19 files changed

+289
-79
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

CONTRIBUTING.md

Lines changed: 42 additions & 42 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
**WORK IN PROGRESS - NOT READY FOR GENERAL USAGE**
1010

11-
[Appwrite](https://appwrite.io) SDK generator is a PHP library for auto generating SDK libraries for multiple languages and platforms.
11+
[Appwrite](https://appwrite.io) SDK generator is a PHP library for auto-generating SDK libraries for multiple languages and platforms.
1212

1313
The SDK Generator uses predefined language settings as [Twig templates](https://twig.symfony.com/) to generate codebases based on different API specs.
1414

15-
Currently, the only spec supported is Swagger 2.0, but we intend to add support for more specifications in the near future. This generator is still lacking support for any definition/models specs.
15+
Currently, the only spec supported is Swagger 2.0, but we intend to add support for more specifications in the near future. This generator is still lacking support for any definition/model specs.
1616

1717
## Getting Started
1818

@@ -134,7 +134,7 @@ $sdk->generate(__DIR__ . '/examples/php'); // Generate source code
134134

135135
## Contributing
136136

137-
All code contributions - including those of people having commit access - must go through a pull request and approved by a core developer before being merged. This is to ensure proper review of all the code.
137+
All code contributions, including those by people with commit access, must go through a pull request and be approved by a core developer before being merged. This is to ensure proper review of all the code.
138138

139139
We truly ❤️ pull requests! If you wish to help, you can learn more about how you can contribute to this project in the [contribution guide](CONTRIBUTING.md).
140140

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/flutter/lib/src/client_io.dart.twig

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,18 @@ class ClientIO extends ClientBase with ClientMixin {
133133
Future init() async {
134134
if(_initProgress) return;
135135
_initProgress = true;
136-
// if web skip cookie implementation and origin header as those are automatically handled by browsers
137136
final Directory cookieDir = await _getCookiePath();
138137
_cookieJar = PersistCookieJar(storage: FileStorage(cookieDir.path));
139138
_interceptors.add(CookieManager(_cookieJar));
140-
PackageInfo packageInfo = await PackageInfo.fromPlatform();
141-
addHeader('Origin',
142-
'appwrite-${Platform.operatingSystem}://${packageInfo.packageName}');
143139

144-
//creating custom user agent
145-
DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
146140
var device = '';
147141
try {
142+
PackageInfo packageInfo = await PackageInfo.fromPlatform();
143+
addHeader('Origin',
144+
'appwrite-${Platform.operatingSystem}://${packageInfo.packageName}');
145+
146+
//creating custom user agent
147+
DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
148148
if (Platform.isAndroid) {
149149
final andinfo = await deviceInfoPlugin.androidInfo;
150150
device =
@@ -167,12 +167,14 @@ class ClientIO extends ClientBase with ClientMixin {
167167
final macinfo = await deviceInfoPlugin.macOsInfo;
168168
device = '(Macintosh; ${macinfo.model})';
169169
}
170+
addHeader(
171+
'user-agent', '${packageInfo.packageName}/${packageInfo.version} $device');
170172
} catch (e) {
171173
debugPrint('Error getting device info: $e');
172174
device = Platform.operatingSystem;
175+
addHeader(
176+
'user-agent', '$device');
173177
}
174-
addHeader(
175-
'user-agent', '${packageInfo.packageName}/${packageInfo.version} $device');
176178

177179
_initialized = true;
178180
_initProgress = false;

0 commit comments

Comments
 (0)