Skip to content

Commit 8860259

Browse files
authored
Merge branch 'appwrite:master' into unity-client-sdk
2 parents 02707a1 + d69be8d commit 8860259

File tree

41 files changed

+173
-72
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+173
-72
lines changed

templates/android/library/src/main/java/io/package/Client.kt.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ class Client @JvmOverloads constructor(
507507
val warnings = response.headers["x-{{ spec.title | lower }}-warning"]
508508
if (warnings != null) {
509509
warnings.split(";").forEach { warning ->
510-
println("Warning: $warning")
510+
System.err.println("Warning: $warning")
511511
}
512512
}
513513

templates/android/library/src/main/java/io/package/Query.kt.twig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ class Query(
151151
*/
152152
fun orderDesc(attribute: String) = Query("orderDesc", attribute).toJson()
153153

154+
/**
155+
* Sort results randomly.
156+
*
157+
* @returns The query string.
158+
*/
159+
fun orderRandom() = Query("orderRandom").toJson()
160+
154161
/**
155162
* Return results before documentId.
156163
*

templates/apple/Sources/Client.swift.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ open class Client {
304304

305305
if let warning = response.headers["x-{{ spec.title | lower }}-warning"].first {
306306
warning.split(separator: ";").forEach { warning in
307-
print("Warning: \(warning)")
307+
fputs("Warning: \(warning)\n", stderr)
308308
}
309309
}
310310

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -295,15 +295,16 @@ const pullSites = async ({ code, withVariables }) => {
295295
const pullCollection = async () => {
296296
warn("appwrite pull collection has been deprecated. Please consider using 'appwrite pull tables' instead");
297297
log("Fetching collections ...");
298-
let total = 0;
298+
let totalDatabases = 0;
299+
let totalCollections = 0;
299300

300301
const fetchResponse = await databasesList({
301302
queries: [JSON.stringify({ method: 'limit', values: [1] })],
302303
parseOutput: false
303304
});
304305
if (fetchResponse["databases"].length <= 0) {
305306
log("No collections found.");
306-
success(`Successfully pulled ${chalk.bold(total)} collections.`);
307+
success(`Successfully pulled ${chalk.bold(totalCollections)} collections from ${chalk.bold(totalDatabases)} databases.`);
307308
return;
308309
}
309310

@@ -323,7 +324,7 @@ const pullCollection = async () => {
323324
parseOutput: false
324325
});
325326

326-
total++;
327+
totalDatabases++;
327328
log(`Pulling all collections from ${chalk.bold(database['name'])} database ...`);
328329

329330
localConfig.addDatabase(database);
@@ -334,6 +335,7 @@ const pullCollection = async () => {
334335
}, 100, 'collections');
335336

336337
for (const collection of collections) {
338+
totalCollections++;
337339
localConfig.addCollection({
338340
...collection,
339341
'$createdAt': undefined,
@@ -342,20 +344,21 @@ const pullCollection = async () => {
342344
}
343345
}
344346

345-
success(`Successfully pulled ${chalk.bold(total)} collections.`);
347+
success(`Successfully pulled ${chalk.bold(totalCollections)} collections from ${chalk.bold(totalDatabases)} databases.`);
346348
}
347349

348350
const pullTable = async () => {
349351
log("Fetching tables ...");
350-
let total = 0;
352+
let totalTablesDBs = 0;
353+
let totalTables = 0;
351354

352355
const fetchResponse = await tablesDBList({
353356
queries: [JSON.stringify({ method: 'limit', values: [1] })],
354357
parseOutput: false
355358
});
356359
if (fetchResponse["databases"].length <= 0) {
357360
log("No tables found.");
358-
success(`Successfully pulled ${chalk.bold(total)} tables.`);
361+
success(`Successfully pulled ${chalk.bold(totalTables)} tables from ${chalk.bold(totalTablesDBs)} tables databases.`);
359362
return;
360363
}
361364

@@ -375,7 +378,7 @@ const pullTable = async () => {
375378
parseOutput: false
376379
});
377380

378-
total++;
381+
totalTablesDBs++;
379382
log(`Pulling all tables from ${chalk.bold(database['name'])} database ...`);
380383

381384
localConfig.addTablesDB(database);
@@ -386,6 +389,7 @@ const pullTable = async () => {
386389
}, 100, 'tables');
387390

388391
for (const table of tables) {
392+
totalTables++;
389393
localConfig.addTable({
390394
...table,
391395
'$createdAt': undefined,
@@ -394,7 +398,7 @@ const pullTable = async () => {
394398
}
395399
}
396400

397-
success(`Successfully pulled ${chalk.bold(total)} tables.`);
401+
success(`Successfully pulled ${chalk.bold(totalTables)} tables from ${chalk.bold(totalTablesDBs)} tables databases.`);
398402
}
399403

400404
const pullBucket = async () => {
@@ -474,14 +478,16 @@ const pullMessagingTopic = async () => {
474478

475479
const pull = new Command("pull")
476480
.description(commandDescriptions['pull'])
477-
.action(actionRunner(pullResources));
481+
.action(actionRunner(() => pullResources({ skipDeprecated: true })));
478482

479483
pull
480484
.command("all")
481485
.description("Pull all resource.")
482486
.action(actionRunner(() => {
483487
cliConfig.all = true;
484-
return pullResources();
488+
return pullResources({
489+
skipDeprecated: true
490+
});
485491
}));
486492

487493
pull

templates/cli/lib/parser.js.twig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ const commandDescriptions = {
205205
"account": `The account command allows you to authenticate and manage a user account.`,
206206
"graphql": `The graphql command allows you to query and mutate any resource type on your Appwrite server.`,
207207
"avatars": `The avatars command aims to help you complete everyday tasks related to your app image, icons, and avatars.`,
208-
"databases": `The databases command allows you to create structured collections of documents and query and filter lists of documents.`,
208+
"databases": `(Legacy) The databases command allows you to create structured collections of documents and query and filter lists of documents.`,
209+
'tables-db': `The tables-db command allows you to create structured tables of columns and query and filter lists of rows.`,
209210
"init": `The init command provides a convenient wrapper for creating and initializing projects, functions, collections, buckets, teams, and messaging-topics in {{ spec.title|caseUcfirst }}.`,
210211
"push": `The push command provides a convenient wrapper for pushing your functions, collections, buckets, teams, and messaging-topics.`,
211212
"run": `The run command allows you to run the project locally to allow easy development and quick debugging.`,
@@ -218,6 +219,8 @@ const commandDescriptions = {
218219
"teams": `The teams command allows you to group users of your project to enable them to share read and write access to your project resources.`,
219220
"update": `The update command allows you to update the {{ spec.title|caseUcfirst }} CLI to the latest version.`,
220221
"users": `The users command allows you to manage your project users.`,
222+
"projects": `The projects command allows you to manage your projects, add platforms, manage API keys, Dev Keys etc.`,
223+
"project": `The project command allows you to manage project related resources like usage, variables, etc.`,
221224
"client": `The client command allows you to configure your CLI`,
222225
"login": `The login command allows you to authenticate and manage a user account.`,
223226
"logout": `The logout command allows you to log out of your {{ spec.title|caseUcfirst }} account.`,

templates/cli/lib/type-generation/languages/dart.js.twig

Lines changed: 50 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -83,104 +83,101 @@ class Dart extends LanguageMeta {
8383
}
8484

8585
getTemplate() {
86-
return `<% for (const attribute of collection.attributes) { -%>
87-
<% if (attribute.type === 'relationship') { -%>
88-
import '<%- toSnakeCase(collections.find(c => c.$id === attribute.relatedCollection).name) %>.dart';
89-
90-
<% } -%>
91-
<% } -%>
92-
/// This file is auto-generated by the Appwrite CLI.
93-
/// You can regenerate it by running \`appwrite ${process.argv.slice(2).join(' ')}\`.
94-
95-
<% for (const attribute of collection.attributes) { -%>
96-
<% if (attribute.format === 'enum') { -%>
86+
return `// This file is auto-generated by the Appwrite CLI.
87+
// You can regenerate it by running \`appwrite ${process.argv.slice(2).join(' ')}\`.
88+
<% const __relatedImportsSeen = new Set();
89+
const sortedAttributes = collection.attributes.slice().sort((a, b) => {
90+
if (a.required === b.required) return 0;
91+
return a.required ? -1 : 1;
92+
}); -%>
93+
<% const __attrs = sortedAttributes; -%>
94+
<% for (const attribute of __attrs) { -%>
95+
<% if (attribute.type === '${AttributeType.RELATIONSHIP}') { -%>
96+
<% const related = collections.find(c => c.$id === attribute.relatedCollection); -%>
97+
<% if (related && !__relatedImportsSeen.has(toSnakeCase(related.name))) { -%>
98+
import '<%- toSnakeCase(related.name) %>.dart';
99+
<% __relatedImportsSeen.add(toSnakeCase(related.name)); -%>
100+
<% } -%>
101+
<% } -%>
102+
<% } -%>
103+
104+
<% for (const attribute of __attrs) { -%>
105+
<% if (attribute.format === '${AttributeType.ENUM}') { -%>
97106
enum <%- toPascalCase(attribute.key) %> {
98107
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
99-
<%- strict ? toCamelCase(element) : element %><% if (index < attribute.elements.length - 1) { %>,<% } %>
108+
<%- strict ? toCamelCase(element) : element %><% if (index < attribute.elements.length - 1) { -%>,<% } %>
100109
<% } -%>
101110
}
102111

103112
<% } -%>
104113
<% } -%>
105114
class <%= toPascalCase(collection.name) %> {
106-
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
115+
<% for (const [index, attribute] of Object.entries(__attrs)) { -%>
107116
<%- getType(attribute, collections) %> <%= strict ? toCamelCase(attribute.key) : attribute.key %>;
108117
<% } -%>
109118

110119
<%= toPascalCase(collection.name) %>({
111-
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
112-
<% if (attribute.required) { %>required <% } %>this.<%= strict ? toCamelCase(attribute.key) : attribute.key %><% if (index < collection.attributes.length - 1) { %>,<% } %>
120+
<% for (const [index, attribute] of Object.entries(__attrs)) { -%>
121+
<% if (attribute.required) { %>required <% } %>this.<%= strict ? toCamelCase(attribute.key) : attribute.key %><% if (index < __attrs.length - 1) { -%>,<% } %>
113122
<% } -%>
114123
});
115124

116125
factory <%= toPascalCase(collection.name) %>.fromMap(Map<String, dynamic> map) {
117126
return <%= toPascalCase(collection.name) %>(
118-
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
119-
<%= strict ? toCamelCase(attribute.key) : attribute.key %>: <% if (attribute.type === 'string' || attribute.type === 'email' || attribute.type === 'datetime') { -%>
120-
<% if (attribute.format === 'enum') { -%>
127+
<% for (const [index, attribute] of Object.entries(__attrs)) { -%>
128+
<%= strict ? toCamelCase(attribute.key) : attribute.key %>: <% if (attribute.type === '${AttributeType.STRING}' || attribute.type === '${AttributeType.EMAIL}' || attribute.type === '${AttributeType.DATETIME}') { -%>
129+
<% if (attribute.format === '${AttributeType.ENUM}') { -%>
121130
<% if (attribute.array) { -%>
122-
(map['<%= attribute.key %>'] as List<dynamic>?)?.map((e) => <%- toPascalCase(attribute.key) %>.values.firstWhere((element) => element.name == e)).toList()<% if (!attribute.required) { %> ?? []<% } -%>
123-
<% } else { -%>
131+
(map['<%= attribute.key %>'] as List<dynamic>?)?.map((e) => <%- toPascalCase(attribute.key) %>.values.firstWhere((element) => element.name == e)).toList()<% } else { -%>
124132
<% if (!attribute.required) { -%>
125133
map['<%= attribute.key %>'] != null ? <%- toPascalCase(attribute.key) %>.values.where((e) => e.name == map['<%= attribute.key %>']).firstOrNull : null<% } else { -%>
126134
<%- toPascalCase(attribute.key) %>.values.firstWhere((e) => e.name == map['<%= attribute.key %>'])<% } -%>
127135
<% } -%>
128136
<% } else { -%>
129137
<% if (attribute.array) { -%>
130-
List<String>.from(map['<%= attribute.key %>'] ?? [])<% if (!attribute.required) { %> ?? []<% } -%>
131-
<% } else { -%>
132-
map['<%= attribute.key %>']<% if (!attribute.required) { %>?<% } %>.toString()<% if (!attribute.required) { %> ?? null<% } -%>
138+
List<String>.from(map['<%= attribute.key %>'] ?? [])<% } else { -%>
139+
map['<%= attribute.key %>']<% if (!attribute.required) { %>?<% } %>.toString()<% } -%>
133140
<% } -%>
134-
<% } -%>
135-
<% } else if (attribute.type === 'integer') { -%>
141+
<% } else if (attribute.type === '${AttributeType.INTEGER}') { -%>
136142
<% if (attribute.array) { -%>
137-
List<int>.from(map['<%= attribute.key %>'] ?? [])<% if (!attribute.required) { %> ?? []<% } -%>
138-
<% } else { -%>
139-
map['<%= attribute.key %>']<% if (!attribute.required) { %> ?? null<% } -%>
140-
<% } -%>
141-
<% } else if (attribute.type === 'float') { -%>
143+
List<int>.from(map['<%= attribute.key %>'] ?? [])<% } else { -%>
144+
map['<%= attribute.key %>']<% } -%>
145+
<% } else if (attribute.type === '${AttributeType.FLOAT}') { -%>
142146
<% if (attribute.array) { -%>
143-
List<double>.from(map['<%= attribute.key %>'] ?? [])<% if (!attribute.required) { %> ?? []<% } -%>
144-
<% } else { -%>
145-
map['<%= attribute.key %>']<% if (!attribute.required) { %> ?? null<% } -%>
146-
<% } -%>
147-
<% } else if (attribute.type === 'boolean') { -%>
147+
List<double>.from(map['<%= attribute.key %>'] ?? [])<% } else { -%>
148+
map['<%= attribute.key %>']<% } -%>
149+
<% } else if (attribute.type === '${AttributeType.BOOLEAN}') { -%>
148150
<% if (attribute.array) { -%>
149-
List<bool>.from(map['<%= attribute.key %>'] ?? [])<% if (!attribute.required) { %> ?? []<% } -%>
150-
<% } else { -%>
151-
map['<%= attribute.key %>']<% if (!attribute.required) { %> ?? null<% } -%>
152-
<% } -%>
153-
<% } else if (attribute.type === 'relationship') { -%>
151+
List<bool>.from(map['<%= attribute.key %>'] ?? [])<% } else { -%>
152+
map['<%= attribute.key %>']<% } -%>
153+
<% } else if (attribute.type === '${AttributeType.RELATIONSHIP}') { -%>
154154
<% if ((attribute.relationType === 'oneToMany' && attribute.side === 'parent') || (attribute.relationType === 'manyToOne' && attribute.side === 'child') || attribute.relationType === 'manyToMany') { -%>
155-
(map['<%= attribute.key %>'] as List<dynamic>?)?.map((e) => <%- toPascalCase(collections.find(c => c.$id === attribute.relatedCollection).name) %>.fromMap(e)).toList()<% if (!attribute.required) { %> ?? []<% } -%>
155+
(map['<%= attribute.key %>'] as List<dynamic>?)?.map((e) => <%- toPascalCase(collections.find(c => c.$id === attribute.relatedCollection).name) %>.fromMap(e)).toList()
156156
<% } else { -%>
157157
<% if (!attribute.required) { -%>
158158
map['<%= attribute.key %>'] != null ? <%- toPascalCase(collections.find(c => c.$id === attribute.relatedCollection).name) %>.fromMap(map['<%= attribute.key %>']) : null<% } else { -%>
159159
<%- toPascalCase(collections.find(c => c.$id === attribute.relatedCollection).name) %>.fromMap(map['<%= attribute.key %>'])<% } -%>
160160
<% } -%>
161-
<% } -%><% if (index < collection.attributes.length - 1) { %>,<% } %>
161+
<% } -%><% if (index < __attrs.length - 1) { -%>,<% } %>
162162
<% } -%>
163163
);
164164
}
165165

166166
Map<String, dynamic> toMap() {
167167
return {
168-
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
169-
"<%= attribute.key %>": <% if (attribute.type === 'relationship') { -%>
168+
<% for (const [index, attribute] of Object.entries(__attrs)) { -%>
169+
'<%= attribute.key %>': <% if (attribute.type === '${AttributeType.RELATIONSHIP}') { -%>
170170
<% if ((attribute.relationType === 'oneToMany' && attribute.side === 'parent') || (attribute.relationType === 'manyToOne' && attribute.side === 'child') || attribute.relationType === 'manyToMany') { -%>
171-
<%= strict ? toCamelCase(attribute.key) : attribute.key %><% if (!attribute.required) { %>?<% } %>.map((e) => e.toMap()).toList()<% if (!attribute.required) { %> ?? []<% } -%>
171+
<%= strict ? toCamelCase(attribute.key) : attribute.key %><% if (!attribute.required) { %>?<% } %>.map((e) => e.toMap()).toList()
172172
<% } else { -%>
173-
<%= strict ? toCamelCase(attribute.key) : attribute.key %><% if (!attribute.required) { %>?<% } %>.toMap()<% if (!attribute.required) { %> ?? {}<% } -%>
174-
<% } -%>
175-
<% } else if (attribute.format === 'enum') { -%>
173+
<%= strict ? toCamelCase(attribute.key) : attribute.key %><% if (!attribute.required) { %>?<% } %>.toMap()<% } -%>
174+
<% } else if (attribute.format === '${AttributeType.ENUM}') { -%>
176175
<% if (attribute.array) { -%>
177-
<%= strict ? toCamelCase(attribute.key) : attribute.key %><% if (!attribute.required) { %>?<% } %>.map((e) => e.name).toList()<% if (!attribute.required) { %> ?? []<% } -%>
178-
<% } else { -%>
179-
<%= strict ? toCamelCase(attribute.key) : attribute.key %><% if (!attribute.required) { %>?<% } %>.name<% if (!attribute.required) { %> ?? null<% } -%>
180-
<% } -%>
176+
<%= strict ? toCamelCase(attribute.key) : attribute.key %><% if (!attribute.required) { %>?<% } %>.map((e) => e.name).toList()<% } else { -%>
177+
<%= strict ? toCamelCase(attribute.key) : attribute.key %><% if (!attribute.required) { %>?<% } %>.name<% } -%>
181178
<% } else { -%>
182179
<%= strict ? toCamelCase(attribute.key) : attribute.key -%>
183-
<% } -%><% if (index < collection.attributes.length - 1) { %>,<% } %>
180+
<% } -%><% if (index < __attrs.length - 1) { -%>,<% } %>
184181
<% } -%>
185182
};
186183
}

templates/cli/lib/type-generation/languages/typescript.js.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class TypeScript extends LanguageMeta {
6969
}
7070

7171
getTemplate() {
72-
return `import { type Models } from '${this._getAppwriteDependency()}';
72+
return `import type { Models } from '${this._getAppwriteDependency()}';
7373

7474
// This file is auto-generated by the Appwrite CLI.
7575
// You can regenerate it by running \`appwrite ${process.argv.slice(2).join(' ')}\`.

templates/dart/lib/query.dart.twig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ class Query {
153153
static String orderDesc(String attribute) =>
154154
Query._('orderDesc', attribute).toString();
155155

156+
/// Sort results randomly.
157+
static String orderRandom() =>
158+
Query._('orderRandom').toString();
159+
156160
/// Return results before [id].
157161
///
158162
/// Refer to the [Cursor Based Pagination]({{sdk.url}}/docs/pagination#cursor-pagination)

templates/dart/test/query_test.dart.twig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@ void main() {
190190
expect(query['method'], 'orderDesc');
191191
});
192192

193+
test('returns orderRandom', () {
194+
final query = jsonDecode(Query.orderRandom());
195+
expect(query['attribute'], null);
196+
expect(query['values'], null);
197+
expect(query['method'], 'orderRandom');
198+
});
199+
193200
test('returns cursorBefore', () {
194201
final query = jsonDecode(Query.cursorBefore('custom'));
195202
expect(query['attribute'], null);

templates/deno/src/query.ts.twig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ export class Query {
8181
static orderAsc = (attribute: string): string =>
8282
new Query("orderAsc", attribute).toString();
8383

84+
static orderRandom = (): string =>
85+
new Query("orderRandom").toString();
86+
8487
static cursorAfter = (documentId: string): string =>
8588
new Query("cursorAfter", undefined, documentId).toString();
8689

0 commit comments

Comments
 (0)