appwrite-cli 6.2.3 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/README.md +4 -4
  2. package/docs/examples/console/get-resource.md +3 -0
  3. package/docs/examples/databases/create-documents.md +4 -0
  4. package/docs/examples/databases/create-index.md +1 -0
  5. package/docs/examples/databases/delete-documents.md +4 -0
  6. package/docs/examples/databases/update-documents.md +5 -0
  7. package/docs/examples/databases/upsert-document.md +6 -0
  8. package/docs/examples/databases/upsert-documents.md +4 -0
  9. package/docs/examples/functions/{create-build.md → create-duplicate-deployment.md} +1 -1
  10. package/docs/examples/functions/create-template-deployment.md +7 -0
  11. package/docs/examples/functions/create-variable.md +2 -1
  12. package/docs/examples/functions/create-vcs-deployment.md +5 -0
  13. package/docs/examples/functions/create.md +0 -4
  14. package/docs/examples/functions/get-deployment-download.md +2 -1
  15. package/docs/examples/functions/get-usage.md +1 -0
  16. package/docs/examples/functions/list-executions.md +0 -1
  17. package/docs/examples/functions/list-usage.md +2 -0
  18. package/docs/examples/functions/{update-deployment.md → update-deployment-status.md} +1 -1
  19. package/docs/examples/functions/{update-deployment-build.md → update-function-deployment.md} +1 -1
  20. package/docs/examples/functions/update-variable.md +1 -0
  21. package/docs/examples/migrations/create-csv-migration.md +4 -0
  22. package/docs/examples/project/create-variable.md +2 -1
  23. package/docs/examples/project/update-variable.md +1 -0
  24. package/docs/examples/projects/create-dev-key.md +4 -0
  25. package/docs/examples/projects/delete-dev-key.md +3 -0
  26. package/docs/examples/projects/get-dev-key.md +3 -0
  27. package/docs/examples/projects/list-dev-keys.md +3 -0
  28. package/docs/examples/projects/update-dev-key.md +5 -0
  29. package/docs/examples/proxy/create-a-p-i-rule.md +2 -0
  30. package/docs/examples/proxy/create-function-rule.md +4 -0
  31. package/docs/examples/proxy/create-redirect-rule.md +4 -0
  32. package/docs/examples/proxy/create-site-rule.md +4 -0
  33. package/docs/examples/sites/create-deployment.md +7 -0
  34. package/docs/examples/sites/create-duplicate-deployment.md +3 -0
  35. package/docs/examples/sites/create-template-deployment.md +7 -0
  36. package/docs/examples/sites/create-variable.md +5 -0
  37. package/docs/examples/sites/create-vcs-deployment.md +5 -0
  38. package/docs/examples/sites/create.md +19 -0
  39. package/docs/examples/sites/delete-deployment.md +3 -0
  40. package/docs/examples/sites/delete-log.md +3 -0
  41. package/docs/examples/sites/delete-variable.md +3 -0
  42. package/docs/examples/sites/delete.md +2 -0
  43. package/docs/examples/sites/get-deployment-download.md +4 -0
  44. package/docs/examples/sites/get-deployment.md +3 -0
  45. package/docs/examples/sites/get-log.md +3 -0
  46. package/docs/examples/sites/get-template.md +2 -0
  47. package/docs/examples/sites/get-usage.md +3 -0
  48. package/docs/examples/sites/get-variable.md +3 -0
  49. package/docs/examples/sites/get.md +2 -0
  50. package/docs/examples/sites/list-deployments.md +4 -0
  51. package/docs/examples/sites/list-frameworks.md +1 -0
  52. package/docs/examples/sites/list-logs.md +3 -0
  53. package/docs/examples/sites/list-specifications.md +1 -0
  54. package/docs/examples/sites/list-templates.md +5 -0
  55. package/docs/examples/sites/list-usage.md +2 -0
  56. package/docs/examples/sites/list-variables.md +2 -0
  57. package/docs/examples/sites/list.md +3 -0
  58. package/docs/examples/sites/update-deployment-status.md +3 -0
  59. package/docs/examples/sites/update-site-deployment.md +3 -0
  60. package/docs/examples/sites/update-variable.md +6 -0
  61. package/docs/examples/sites/update.md +19 -0
  62. package/docs/examples/storage/get-file-download.md +2 -1
  63. package/docs/examples/storage/get-file-preview.md +1 -0
  64. package/docs/examples/storage/get-file-view.md +2 -1
  65. package/docs/examples/tokens/create-file-token.md +4 -0
  66. package/docs/examples/tokens/delete.md +2 -0
  67. package/docs/examples/tokens/get.md +2 -0
  68. package/docs/examples/tokens/list.md +4 -0
  69. package/docs/examples/tokens/update.md +3 -0
  70. package/docs/examples/users/list-memberships.md +3 -1
  71. package/docs/examples/vcs/create-repository-detection.md +1 -0
  72. package/docs/examples/vcs/list-repositories.md +1 -0
  73. package/index.js +6 -2
  74. package/install.ps1 +2 -2
  75. package/install.sh +1 -1
  76. package/lib/client.js +8 -4
  77. package/lib/commands/account.js +7 -17
  78. package/lib/commands/avatars.js +7 -14
  79. package/lib/commands/console.js +50 -1
  80. package/lib/commands/databases.js +287 -55
  81. package/lib/commands/functions.js +244 -146
  82. package/lib/commands/generic.js +1 -1
  83. package/lib/commands/health.js +0 -63
  84. package/lib/commands/init.js +191 -0
  85. package/lib/commands/locale.js +0 -8
  86. package/lib/commands/messaging.js +38 -51
  87. package/lib/commands/migrations.js +50 -5
  88. package/lib/commands/project.js +12 -5
  89. package/lib/commands/projects.js +246 -27
  90. package/lib/commands/proxy.js +160 -19
  91. package/lib/commands/pull.js +124 -1
  92. package/lib/commands/push.js +338 -5
  93. package/lib/commands/sites.js +1663 -0
  94. package/lib/commands/storage.js +28 -22
  95. package/lib/commands/teams.js +2 -8
  96. package/lib/commands/tokens.js +261 -0
  97. package/lib/commands/types.js +126 -0
  98. package/lib/commands/users.js +15 -17
  99. package/lib/commands/vcs.js +60 -53
  100. package/lib/config.js +50 -0
  101. package/lib/parser.js +2 -2
  102. package/lib/questions.js +110 -1
  103. package/lib/type-generation/attribute.js +16 -0
  104. package/lib/type-generation/languages/dart.js +152 -0
  105. package/lib/type-generation/languages/java.js +121 -0
  106. package/lib/type-generation/languages/javascript.js +84 -0
  107. package/lib/type-generation/languages/kotlin.js +75 -0
  108. package/lib/type-generation/languages/language.js +125 -0
  109. package/lib/type-generation/languages/php.js +100 -0
  110. package/lib/type-generation/languages/swift.js +156 -0
  111. package/lib/type-generation/languages/typescript.js +95 -0
  112. package/package.json +2 -1
  113. package/scoop/appwrite.json +3 -3
  114. package/docs/examples/assistant/chat.md +0 -2
  115. package/docs/examples/functions/get-function-usage.md +0 -3
  116. package/docs/examples/health/get-queue-stats-usage-dump.md +0 -2
  117. package/docs/examples/proxy/create-rule.md +0 -4
  118. package/lib/commands/assistant.js +0 -85
@@ -0,0 +1,152 @@
1
+ /** @typedef {import('../attribute').Attribute} Attribute */
2
+ const { AttributeType } = require('../attribute');
3
+ const { LanguageMeta } = require("./language");
4
+
5
+ class Dart extends LanguageMeta {
6
+ getType(attribute) {
7
+ let type = "";
8
+ switch (attribute.type) {
9
+ case AttributeType.STRING:
10
+ case AttributeType.EMAIL:
11
+ case AttributeType.DATETIME:
12
+ type = "String";
13
+ if (attribute.format === AttributeType.ENUM) {
14
+ type = LanguageMeta.toPascalCase(attribute.key);
15
+ }
16
+ break;
17
+ case AttributeType.INTEGER:
18
+ type = "int";
19
+ break;
20
+ case AttributeType.FLOAT:
21
+ type = "double";
22
+ break;
23
+ case AttributeType.BOOLEAN:
24
+ type = "bool";
25
+ break;
26
+ case AttributeType.RELATIONSHIP:
27
+ type = LanguageMeta.toPascalCase(attribute.relatedCollection);
28
+ if ((attribute.relationType === 'oneToMany' && attribute.side === 'parent') || (attribute.relationType === 'manyToOne' && attribute.side === 'child') || attribute.relationType === 'manyToMany') {
29
+ type = `List<${type}>`;
30
+ }
31
+ break;
32
+ default:
33
+ throw new Error(`Unknown attribute type: ${attribute.type}`);
34
+ }
35
+ if (attribute.array) {
36
+ type = `List<${type}>`;
37
+ }
38
+ if (!attribute.required) {
39
+ type += "?";
40
+ }
41
+ return type;
42
+ }
43
+
44
+ getTemplate() {
45
+ return `<% for (const attribute of collection.attributes) { -%>
46
+ <% if (attribute.type === 'relationship') { -%>
47
+ import '<%- attribute.relatedCollection.toLowerCase() %>.dart';
48
+
49
+ <% } -%>
50
+ <% } -%>
51
+ <% for (const attribute of collection.attributes) { -%>
52
+ <% if (attribute.format === 'enum') { -%>
53
+ enum <%- toPascalCase(attribute.key) %> {
54
+ <% for (const element of attribute.elements) { -%>
55
+ <%- element %>,
56
+ <% } -%>
57
+ }
58
+
59
+ <% } -%>
60
+ <% } -%>
61
+ class <%= toPascalCase(collection.name) %> {
62
+ <% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
63
+ <%- getType(attribute) %> <%= toCamelCase(attribute.key) %>;
64
+ <% } -%>
65
+
66
+ <%= toPascalCase(collection.name) %>({
67
+ <% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
68
+ <% if (attribute.required) { %>required <% } %>this.<%= toCamelCase(attribute.key) %>,
69
+ <% } -%>
70
+ });
71
+
72
+ factory <%= toPascalCase(collection.name) %>.fromMap(Map<String, dynamic> map) {
73
+ return <%= toPascalCase(collection.name) %>(
74
+ <% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
75
+ <%= toCamelCase(attribute.key) %>: <% if (attribute.type === 'string' || attribute.type === 'email' || attribute.type === 'datetime') { -%>
76
+ <% if (attribute.format === 'enum') { -%>
77
+ <% if (attribute.array) { -%>
78
+ (map['<%= attribute.key %>'] as List<dynamic>?)?.map((e) => <%- toPascalCase(attribute.key) %>.values.firstWhere((element) => element.name == e)).toList()<% if (!attribute.required) { %> ?? []<% } -%>
79
+ <% } else { -%>
80
+ <% if (!attribute.required) { -%>
81
+ map['<%= attribute.key %>'] != null ? <%- toPascalCase(attribute.key) %>.values.where((e) => e.name == map['<%= attribute.key %>']).firstOrNull : null<% } else { -%>
82
+ <%- toPascalCase(attribute.key) %>.values.firstWhere((e) => e.name == map['<%= attribute.key %>'])<% } -%>
83
+ <% } -%>
84
+ <% } else { -%>
85
+ <% if (attribute.array) { -%>
86
+ List<String>.from(map['<%= attribute.key %>'] ?? [])<% if (!attribute.required) { %> ?? []<% } -%>
87
+ <% } else { -%>
88
+ map['<%= attribute.key %>']<% if (!attribute.required) { %>?<% } %>.toString()<% if (!attribute.required) { %> ?? null<% } -%>
89
+ <% } -%>
90
+ <% } -%>
91
+ <% } else if (attribute.type === 'integer') { -%>
92
+ <% if (attribute.array) { -%>
93
+ List<int>.from(map['<%= attribute.key %>'] ?? [])<% if (!attribute.required) { %> ?? []<% } -%>
94
+ <% } else { -%>
95
+ map['<%= attribute.key %>']<% if (!attribute.required) { %> ?? null<% } -%>
96
+ <% } -%>
97
+ <% } else if (attribute.type === 'float') { -%>
98
+ <% if (attribute.array) { -%>
99
+ List<double>.from(map['<%= attribute.key %>'] ?? [])<% if (!attribute.required) { %> ?? []<% } -%>
100
+ <% } else { -%>
101
+ map['<%= attribute.key %>']<% if (!attribute.required) { %> ?? null<% } -%>
102
+ <% } -%>
103
+ <% } else if (attribute.type === 'boolean') { -%>
104
+ <% if (attribute.array) { -%>
105
+ List<bool>.from(map['<%= attribute.key %>'] ?? [])<% if (!attribute.required) { %> ?? []<% } -%>
106
+ <% } else { -%>
107
+ map['<%= attribute.key %>']<% if (!attribute.required) { %> ?? null<% } -%>
108
+ <% } -%>
109
+ <% } else if (attribute.type === 'relationship') { -%>
110
+ <% if ((attribute.relationType === 'oneToMany' && attribute.side === 'parent') || (attribute.relationType === 'manyToOne' && attribute.side === 'child') || attribute.relationType === 'manyToMany') { -%>
111
+ (map['<%= attribute.key %>'] as List<dynamic>?)?.map((e) => <%- toPascalCase(attribute.relatedCollection) %>.fromMap(e)).toList()<% if (!attribute.required) { %> ?? []<% } -%>
112
+ <% } else { -%>
113
+ <% if (!attribute.required) { -%>
114
+ map['<%= attribute.key %>'] != null ? <%- toPascalCase(attribute.relatedCollection) %>.fromMap(map['<%= attribute.key %>']) : null<% } else { -%>
115
+ <%- toPascalCase(attribute.relatedCollection) %>.fromMap(map['<%= attribute.key %>'])<% } -%>
116
+ <% } -%>
117
+ <% } -%>,
118
+ <% } -%>
119
+ );
120
+ }
121
+
122
+ Map<String, dynamic> toMap() {
123
+ return {
124
+ <% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
125
+ "<%= attribute.key %>": <% if (attribute.type === 'relationship') { -%>
126
+ <% if ((attribute.relationType === 'oneToMany' && attribute.side === 'parent') || (attribute.relationType === 'manyToOne' && attribute.side === 'child') || attribute.relationType === 'manyToMany') { -%>
127
+ <%= toCamelCase(attribute.key) %><% if (!attribute.required) { %>?<% } %>.map((e) => e.toMap()).toList()<% if (!attribute.required) { %> ?? []<% } -%>
128
+ <% } else { -%>
129
+ <%= toCamelCase(attribute.key) %><% if (!attribute.required) { %>?<% } %>.toMap()<% if (!attribute.required) { %> ?? {}<% } -%>
130
+ <% } -%>
131
+ <% } else if (attribute.format === 'enum') { -%>
132
+ <% if (attribute.array) { -%>
133
+ <%= toCamelCase(attribute.key) %><% if (!attribute.required) { %>?<% } %>.map((e) => e.name).toList()<% if (!attribute.required) { %> ?? []<% } -%>
134
+ <% } else { -%>
135
+ <%= toCamelCase(attribute.key) %><% if (!attribute.required) { %>?<% } %>.name<% if (!attribute.required) { %> ?? null<% } -%>
136
+ <% } -%>
137
+ <% } else { -%>
138
+ <%= toCamelCase(attribute.key) -%>
139
+ <% } -%>,
140
+ <% } -%>
141
+ };
142
+ }
143
+ }
144
+ `;
145
+ }
146
+
147
+ getFileName(collection) {
148
+ return LanguageMeta.toSnakeCase(collection.name) + ".dart";
149
+ }
150
+ }
151
+
152
+ module.exports = { Dart };
@@ -0,0 +1,121 @@
1
+ /** @typedef {import('../attribute').Attribute} Attribute */
2
+ const { AttributeType } = require('../attribute');
3
+ const { LanguageMeta } = require("./language");
4
+
5
+ class Java extends LanguageMeta {
6
+ getType(attribute) {
7
+ let type = "";
8
+ switch (attribute.type) {
9
+ case AttributeType.STRING:
10
+ case AttributeType.EMAIL:
11
+ case AttributeType.DATETIME:
12
+ type = "String";
13
+ if (attribute.format === AttributeType.ENUM) {
14
+ type = LanguageMeta.toPascalCase(attribute.key);
15
+ }
16
+ break;
17
+ case AttributeType.INTEGER:
18
+ type = "int";
19
+ break;
20
+ case AttributeType.FLOAT:
21
+ type = "double";
22
+ break;
23
+ case AttributeType.BOOLEAN:
24
+ type = "boolean";
25
+ break;
26
+ case AttributeType.RELATIONSHIP:
27
+ type = LanguageMeta.toPascalCase(attribute.relatedCollection);
28
+ if ((attribute.relationType === 'oneToMany' && attribute.side === 'parent') || (attribute.relationType === 'manyToOne' && attribute.side === 'child') || attribute.relationType === 'manyToMany') {
29
+ type = "List<" + type + ">";
30
+ }
31
+ break;
32
+ default:
33
+ throw new Error(`Unknown attribute type: ${attribute.type}`);
34
+ }
35
+ if (attribute.array) {
36
+ type = "List<" + type + ">";
37
+ }
38
+ return type;
39
+ }
40
+
41
+ getTemplate() {
42
+ return `package io.appwrite.models;
43
+
44
+ import java.util.*;
45
+ <% for (const attribute of collection.attributes) { -%>
46
+ <% if (attribute.type === 'relationship') { -%>
47
+ import <%- toPascalCase(attribute.relatedCollection) %>;
48
+
49
+ <% } -%>
50
+ <% } -%>
51
+ public class <%- toPascalCase(collection.name) %> {
52
+ <% for (const attribute of collection.attributes) { -%>
53
+ <% if (attribute.format === 'enum') { -%>
54
+
55
+ public enum <%- toPascalCase(attribute.key) %> {
56
+ <% for (const [index, element] of Object.entries(attribute.elements)) { -%>
57
+ <%- element %><%- index < attribute.elements.length - 1 ? ',' : ';' %>
58
+ <% } -%>
59
+ }
60
+
61
+ <% } -%>
62
+ <% } -%>
63
+ <% for (const attribute of collection.attributes) { -%>
64
+ private <%- getType(attribute) %> <%- toCamelCase(attribute.key) %>;
65
+ <% } -%>
66
+
67
+ public <%- toPascalCase(collection.name) %>() {
68
+ }
69
+
70
+ public <%- toPascalCase(collection.name) %>(
71
+ <% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
72
+ <%- getType(attribute) %> <%= toCamelCase(attribute.key) %><%- index < collection.attributes.length - 1 ? ',' : '' %>
73
+ <% } -%>
74
+ ) {
75
+ <% for (const attribute of collection.attributes) { -%>
76
+ this.<%= toCamelCase(attribute.key) %> = <%= toCamelCase(attribute.key) %>;
77
+ <% } -%>
78
+ }
79
+
80
+ <% for (const attribute of collection.attributes) { -%>
81
+ public <%- getType(attribute) %> get<%- toPascalCase(attribute.key) %>() {
82
+ return <%= toCamelCase(attribute.key) %>;
83
+ }
84
+
85
+ public void set<%- toPascalCase(attribute.key) %>(<%- getType(attribute) %> <%= toCamelCase(attribute.key) %>) {
86
+ this.<%= toCamelCase(attribute.key) %> = <%= toCamelCase(attribute.key) %>;
87
+ }
88
+
89
+ <% } -%>
90
+ @Override
91
+ public boolean equals(Object obj) {
92
+ if (this == obj) return true;
93
+ if (obj == null || getClass() != obj.getClass()) return false;
94
+ <%- toPascalCase(collection.name) %> that = (<%- toPascalCase(collection.name) %>) obj;
95
+ return <% collection.attributes.forEach((attr, index) => { %>Objects.equals(<%= toCamelCase(attr.key) %>, that.<%= toCamelCase(attr.key) %>)<% if (index < collection.attributes.length - 1) { %> &&
96
+ <% } }); %>;
97
+ }
98
+
99
+ @Override
100
+ public int hashCode() {
101
+ return Objects.hash(<%= collection.attributes.map(attr => toCamelCase(attr.key)).join(', ') %>);
102
+ }
103
+
104
+ @Override
105
+ public String toString() {
106
+ return "<%- toPascalCase(collection.name) %>{" +
107
+ <% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
108
+ "<%= toCamelCase(attribute.key) %>=" + <%= toCamelCase(attribute.key) %> +
109
+ <% } -%>
110
+ '}';
111
+ }
112
+ }
113
+ `;
114
+ }
115
+
116
+ getFileName(collection) {
117
+ return LanguageMeta.toPascalCase(collection.name) + ".java";
118
+ }
119
+ }
120
+
121
+ module.exports = { Java };
@@ -0,0 +1,84 @@
1
+ /** @typedef {import('../attribute').Attribute} Attribute */
2
+ const fs = require("fs");
3
+ const path = require("path");
4
+
5
+ const { AttributeType } = require('../attribute');
6
+ const { LanguageMeta } = require("./language");
7
+
8
+ class JavaScript extends LanguageMeta {
9
+ getType(attribute) {
10
+ let type = ""
11
+ switch (attribute.type) {
12
+ case AttributeType.STRING:
13
+ case AttributeType.EMAIL:
14
+ case AttributeType.DATETIME:
15
+ case AttributeType.IP:
16
+ case AttributeType.URL:
17
+ type = "string";
18
+ if (attribute.format === AttributeType.ENUM) {
19
+ type = `"${attribute.elements.join('"|"')}"`;
20
+ }
21
+ break;
22
+ case AttributeType.INTEGER:
23
+ type = "number";
24
+ break;
25
+ case AttributeType.FLOAT:
26
+ type = "number";
27
+ break;
28
+ case AttributeType.BOOLEAN:
29
+ type = "boolean";
30
+ break;
31
+ case AttributeType.RELATIONSHIP:
32
+ type = LanguageMeta.toPascalCase(attribute.relatedCollection);
33
+ if ((attribute.relationType === 'oneToMany' && attribute.side === 'parent') || (attribute.relationType === 'manyToOne' && attribute.side === 'child') || attribute.relationType === 'manyToMany') {
34
+ type = `Array<${type}>`;
35
+ }
36
+ break;
37
+ default:
38
+ throw new Error(`Unknown attribute type: ${attribute.type}`);
39
+ }
40
+ if (attribute.array) {
41
+ type += "[]";
42
+ }
43
+ if (!attribute.required) {
44
+ type += "|null|undefined";
45
+ }
46
+ return type;
47
+ }
48
+
49
+ isSingleFile() {
50
+ return true;
51
+ }
52
+
53
+ _getAppwriteDependency() {
54
+ if (fs.existsSync(path.resolve(process.cwd(), 'package.json'))) {
55
+ const packageJsonRaw = fs.readFileSync(path.resolve(process.cwd(), 'package.json'));
56
+ const packageJson = JSON.parse(packageJsonRaw.toString('utf-8'));
57
+ return packageJson.dependencies['node-appwrite'] ? 'node-appwrite' : 'appwrite';
58
+ }
59
+
60
+ return "appwrite";
61
+ }
62
+
63
+ getTemplate() {
64
+ return `/**
65
+ * @typedef {import('${this._getAppwriteDependency()}').Models.Document} Document
66
+ */
67
+
68
+ <% for (const collection of collections) { %>
69
+ /**
70
+ * @typedef {Object} <%- toPascalCase(collection.name) %>
71
+ <% for (const attribute of collection.attributes) { -%>
72
+ * @property {<%- getType(attribute) %>} <%- toCamelCase(attribute.key) %>
73
+ <% } -%>
74
+ */
75
+
76
+ <% } %>`;
77
+ }
78
+
79
+ getFileName(_) {
80
+ return "appwrite-types.js";
81
+ }
82
+ }
83
+
84
+ module.exports = { JavaScript };
@@ -0,0 +1,75 @@
1
+ /** @typedef {import('../attribute').Attribute} Attribute */
2
+ const { AttributeType } = require('../attribute');
3
+ const { LanguageMeta } = require("./language");
4
+
5
+ class Kotlin extends LanguageMeta {
6
+ getType(attribute) {
7
+ let type = "";
8
+ switch (attribute.type) {
9
+ case AttributeType.STRING:
10
+ case AttributeType.EMAIL:
11
+ case AttributeType.DATETIME:
12
+ type = "String";
13
+ if (attribute.format === AttributeType.ENUM) {
14
+ type = LanguageMeta.toPascalCase(attribute.key);
15
+ }
16
+ break;
17
+ case AttributeType.INTEGER:
18
+ type = "Int";
19
+ break;
20
+ case AttributeType.FLOAT:
21
+ type = "Float";
22
+ break;
23
+ case AttributeType.BOOLEAN:
24
+ type = "Boolean";
25
+ break;
26
+ case AttributeType.RELATIONSHIP:
27
+ type = LanguageMeta.toPascalCase(attribute.relatedCollection);
28
+ if ((attribute.relationType === 'oneToMany' && attribute.side === 'parent') || (attribute.relationType === 'manyToOne' && attribute.side === 'child') || attribute.relationType === 'manyToMany') {
29
+ type = `List<${type}>`;
30
+ }
31
+ break;
32
+ default:
33
+ throw new Error(`Unknown attribute type: ${attribute.type}`);
34
+ }
35
+ if (attribute.array) {
36
+ type = "List<" + type + ">";
37
+ }
38
+ if (!attribute.required) {
39
+ type += "?";
40
+ }
41
+ return type;
42
+ }
43
+
44
+ getTemplate() {
45
+ return `package io.appwrite.models
46
+
47
+ <% for (const attribute of collection.attributes) { -%>
48
+ <% if (attribute.type === 'relationship') { -%>
49
+ import <%- toPascalCase(attribute.relatedCollection) %>
50
+
51
+ <% } -%>
52
+ <% } -%>
53
+ <% for (const attribute of collection.attributes) { -%>
54
+ <% if (attribute.format === 'enum') { -%>
55
+ enum class <%- toPascalCase(attribute.key) %> {
56
+ <% for (const [index, element] of Object.entries(attribute.elements)) { -%>
57
+ <%- element %><%- index < attribute.elements.length - 1 ? ',' : '' %>
58
+ <% } -%>
59
+ }
60
+
61
+ <% } -%>
62
+ <% } -%>
63
+ data class <%- toPascalCase(collection.name) %>(
64
+ <% for (const attribute of collection.attributes) { -%>
65
+ val <%- toCamelCase(attribute.key) %>: <%- getType(attribute) %>,
66
+ <% } -%>
67
+ )`;
68
+ }
69
+
70
+ getFileName(collection) {
71
+ return LanguageMeta.toPascalCase(collection.name) + ".kt";
72
+ }
73
+ }
74
+
75
+ module.exports = { Kotlin };
@@ -0,0 +1,125 @@
1
+ /** @typedef {import('../attribute').Attribute} Attribute */
2
+ /** @typedef {import('../collection').Collection} Collection */
3
+
4
+ const fs = require("fs");
5
+ const path = require("path");
6
+
7
+ class LanguageMeta {
8
+ constructor() {
9
+ if (new.target === LanguageMeta) {
10
+ throw new TypeError("Abstract classes can't be instantiated.");
11
+ }
12
+ }
13
+
14
+ static toKebabCase(string) {
15
+ return string
16
+ .replace(/[^a-zA-Z0-9\s-_]/g, "") // Remove invalid characters
17
+ .replace(/([a-z])([A-Z])/g, "$1-$2") // Add hyphen between camelCase
18
+ .replace(/([A-Z])([A-Z][a-z])/g, "$1-$2") // Add hyphen between PascalCase
19
+ .replace(/[_\s]+/g, "-") // Replace spaces and underscores with hyphens
20
+ .replace(/^-+|-+$/g, "") // Remove leading and trailing hyphens
21
+ .replace(/--+/g, "-") // Replace multiple hyphens with a single hyphen
22
+ .toLowerCase();
23
+ }
24
+
25
+ static toSnakeCase(string) {
26
+ return this.toKebabCase(string).replace(/-/g, "_");
27
+ }
28
+
29
+ static toUpperSnakeCase(string) {
30
+ return this.toSnakeCase(string).toUpperCase();
31
+ }
32
+
33
+ static toCamelCase(string) {
34
+ return this.toKebabCase(string).replace(/-([a-z0-9])/g, (g) =>
35
+ g[1].toUpperCase()
36
+ );
37
+ }
38
+
39
+ static toPascalCase(string) {
40
+ return this.toCamelCase(string).replace(/^./, (g) => g.toUpperCase());
41
+ }
42
+
43
+ /**
44
+ * Get the type literal of the given attribute.
45
+ *
46
+ * @abstract
47
+ * @param {Attribute} attribute
48
+ * @return {string}
49
+ */
50
+ getType(attribute) {
51
+ throw new TypeError("Stub.");
52
+ }
53
+
54
+ /**
55
+ * Returns true if the language uses a single file for all types.
56
+ *
57
+ * @returns {boolean}
58
+ */
59
+ isSingleFile() {
60
+ return false;
61
+ }
62
+
63
+ /**
64
+ * Get the EJS template used to generate the types for this language.
65
+ *
66
+ * @abstract
67
+ * @returns {string}
68
+ */
69
+ getTemplate() {
70
+ throw new TypeError("Stub.");
71
+ }
72
+
73
+ /**
74
+ * Get the file extension used by files of this language.
75
+ *
76
+ * @abstract
77
+ * @param {Collection|undefined} collection
78
+ * @returns {string}
79
+ */
80
+ getFileName(collection) {
81
+ throw new TypeError("Stub.");
82
+ }
83
+ }
84
+
85
+ const existsFiles = (...files) =>
86
+ files.some((file) => fs.existsSync(path.join(process.cwd(), file)));
87
+
88
+ /**
89
+ * @returns {string}
90
+ */
91
+ function detectLanguage() {
92
+ if (existsFiles("tsconfig.json", "deno.json")) {
93
+ return "ts";
94
+ }
95
+ if (existsFiles("package.json")) {
96
+ return "js";
97
+ }
98
+ if (existsFiles("composer.json")) {
99
+ return "php";
100
+ }
101
+ if (existsFiles("requirements.txt", "Pipfile", "pyproject.toml")) {
102
+ return "python";
103
+ }
104
+ if (existsFiles("Gemfile", "Rakefile")) {
105
+ return "ruby";
106
+ }
107
+ if (existsFiles("build.gradle.kts")) {
108
+ return "kotlin";
109
+ }
110
+ if (existsFiles("build.gradle", "pom.xml")) {
111
+ return "java";
112
+ }
113
+ if (existsFiles("*.csproj")) {
114
+ return "dotnet";
115
+ }
116
+ if (existsFiles("Package.swift")) {
117
+ return "swift";
118
+ }
119
+ if (existsFiles("pubspec.yaml")) {
120
+ return "dart";
121
+ }
122
+ throw new Error("Could not detect language, please specify with -l");
123
+ }
124
+
125
+ module.exports = { LanguageMeta, detectLanguage };
@@ -0,0 +1,100 @@
1
+ /** @typedef {import('../attribute').Attribute} Attribute */
2
+ const { AttributeType } = require('../attribute');
3
+ const { LanguageMeta } = require("./language");
4
+
5
+ class PHP extends LanguageMeta {
6
+ getType(attribute) {
7
+ if (attribute.array) {
8
+ return "array";
9
+ }
10
+ let type = ""
11
+ switch (attribute.type) {
12
+ case AttributeType.STRING:
13
+ case AttributeType.EMAIL:
14
+ case AttributeType.DATETIME:
15
+ type = "string";
16
+ if (attribute.format === AttributeType.ENUM) {
17
+ type = LanguageMeta.toPascalCase(attribute.key);
18
+ }
19
+ break;
20
+ case AttributeType.INTEGER:
21
+ type = "int";
22
+ break;
23
+ case AttributeType.FLOAT:
24
+ type = "float";
25
+ break;
26
+ case AttributeType.BOOLEAN:
27
+ type = "bool";
28
+ break;
29
+ case AttributeType.RELATIONSHIP:
30
+ type = LanguageMeta.toPascalCase(attribute.relatedCollection);
31
+ if ((attribute.relationType === 'oneToMany' && attribute.side === 'parent') || (attribute.relationType === 'manyToOne' && attribute.side === 'child') || attribute.relationType === 'manyToMany') {
32
+ type = "array";
33
+ }
34
+ break;
35
+ default:
36
+ throw new Error(`Unknown attribute type: ${attribute.type}`);
37
+ }
38
+ if (!attribute.required) {
39
+ type += "|null";
40
+ }
41
+ return type;
42
+ }
43
+
44
+ getTemplate() {
45
+ return `<?php
46
+ namespace Appwrite\\Models;
47
+
48
+ <% for (const attribute of collection.attributes) { -%>
49
+ <% if (attribute.type === 'relationship' && !(attribute.relationType === 'manyToMany') && !(attribute.relationType === 'oneToMany' && attribute.side === 'parent')) { -%>
50
+ use Appwrite\\Models\\<%- toPascalCase(attribute.relatedCollection) %>;
51
+
52
+ <% } -%>
53
+ <% } -%>
54
+ <% for (const attribute of collection.attributes) { -%>
55
+ <% if (attribute.format === 'enum') { -%>
56
+ enum <%- toPascalCase(attribute.key) %> {
57
+ <% for (const [index, element] of Object.entries(attribute.elements)) { -%>
58
+ case <%- element.toUpperCase() %> = '<%- element %>';
59
+ <% } -%>
60
+ }
61
+
62
+ <% } -%>
63
+ <% } -%>
64
+ class <%- toPascalCase(collection.name) %> {
65
+ <% for (const attribute of collection.attributes ){ -%>
66
+ private <%- getType(attribute) %> $<%- toCamelCase(attribute.key) %>;
67
+ <% } -%>
68
+
69
+ public function __construct(
70
+ <% for (const attribute of collection.attributes ){ -%>
71
+ <% if (attribute.required) { -%>
72
+ <%- getType(attribute).replace('|null', '') %> $<%- toCamelCase(attribute.key) %><% if (collection.attributes.indexOf(attribute) < collection.attributes.length - 1) { %>,<% } %>
73
+ <% } else { -%>
74
+ ?<%- getType(attribute).replace('|null', '') %> $<%- toCamelCase(attribute.key) %> = null<% if (collection.attributes.indexOf(attribute) < collection.attributes.length - 1) { %>,<% } %>
75
+ <% } -%>
76
+ <% } -%>
77
+ ) {
78
+ <% for (const attribute of collection.attributes ){ -%>
79
+ $this-><%- toCamelCase(attribute.key) %> = $<%- toCamelCase(attribute.key) %>;
80
+ <% } -%>
81
+ }
82
+
83
+ <% for (const attribute of collection.attributes ){ -%>
84
+ public function get<%- toPascalCase(attribute.key) %>(): <%- getType(attribute) %> {
85
+ return $this-><%- toCamelCase(attribute.key) %>;
86
+ }
87
+
88
+ public function set<%- toPascalCase(attribute.key) %>(<%- getType(attribute) %> $<%- toCamelCase(attribute.key) %>): void {
89
+ $this-><%- toCamelCase(attribute.key) %> = $<%- toCamelCase(attribute.key) %>;
90
+ }
91
+ <% } -%>
92
+ }`;
93
+ }
94
+
95
+ getFileName(collection) {
96
+ return LanguageMeta.toPascalCase(collection.name) + ".php";
97
+ }
98
+ }
99
+
100
+ module.exports = { PHP };