appwrite-cli 8.1.1 → 8.2.1
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.
- package/.github/workflows/npm-publish.yml +1 -1
- package/CHANGELOG.md +22 -0
- package/README.md +2 -2
- package/install.ps1 +2 -2
- package/install.sh +1 -1
- package/lib/client.js +2 -2
- package/lib/commands/push.js +63 -54
- package/lib/commands/types.js +14 -1
- package/lib/config.js +3 -1
- package/lib/parser.js +4 -2
- package/lib/type-generation/languages/dart.js +71 -15
- package/lib/type-generation/languages/java.js +36 -36
- package/lib/type-generation/languages/javascript.js +20 -9
- package/lib/type-generation/languages/kotlin.js +2 -2
- package/lib/type-generation/languages/php.js +13 -13
- package/lib/type-generation/languages/swift.js +47 -47
- package/lib/type-generation/languages/typescript.js +3 -5
- package/package.json +1 -1
- package/scoop/appwrite.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 8.2.1
|
|
4
|
+
|
|
5
|
+
* Added `--with-variables` option to the Sites command for adding/updating environment variables
|
|
6
|
+
* Fixed Functions environment variables not being pushed with `--with-variables`
|
|
7
|
+
* Removed `awaitPools` when wiping old variables
|
|
8
|
+
|
|
9
|
+
> **Note:** Storing environment variables in the `vars` attribute of `appwrite.json` is now deprecated due to security risks. Variables are now synced directly from the `.env` file in the root directory of the function’s or site’s folder.
|
|
10
|
+
|
|
11
|
+
## 8.2.0
|
|
12
|
+
|
|
13
|
+
* Add `encrypt` attribute support
|
|
14
|
+
* Add improved warnings on attribute recreation and deletion
|
|
15
|
+
* Fix `null` parsing error when using create attribute command
|
|
16
|
+
* Type generation fixes and improvements:
|
|
17
|
+
* Add `--strict` / `-s` flag to `appwrite types` command to generate types in strict mode. This automatically converts the casing of attributes to match the language's naming conventions
|
|
18
|
+
* Add automatic package import to `dart` language which uses package detection to import the correct package
|
|
19
|
+
* Add `Document` class extension to generated types in `dart` and `js` language to support internal attributes like `$id` and `$collectionId` etc.
|
|
20
|
+
* Add proper enum support to `js` language
|
|
21
|
+
* Fix indentation in `java`, `kotlin` and `swift` to use 2 spaces instead of 4 for consistency across all languages
|
|
22
|
+
* Fix doc comments to use correct syntax in various languages (for eg. `///` instead of `/*`)
|
|
23
|
+
* Update enums in `dart` to use lowerCamelCase in `strict` mode as per [constant_identifier_names](https://dart.dev/tools/diagnostics/constant_identifier_names?utm_source=dartdev&utm_medium=redir&utm_id=diagcode&utm_content=constant_identifier_names)
|
|
24
|
+
|
|
3
25
|
## 8.1.1
|
|
4
26
|
|
|
5
27
|
* Fix circular dependency issue due to usage of `success` method in `utils.js` file from `parser.js` file
|
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ Once the installation is complete, you can verify the install using
|
|
|
29
29
|
|
|
30
30
|
```sh
|
|
31
31
|
$ appwrite -v
|
|
32
|
-
8.
|
|
32
|
+
8.2.1
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
### Install using prebuilt binaries
|
|
@@ -60,7 +60,7 @@ $ scoop install https://raw.githubusercontent.com/appwrite/sdk-for-cli/master/sc
|
|
|
60
60
|
Once the installation completes, you can verify your install using
|
|
61
61
|
```
|
|
62
62
|
$ appwrite -v
|
|
63
|
-
8.
|
|
63
|
+
8.2.1
|
|
64
64
|
```
|
|
65
65
|
|
|
66
66
|
## Getting Started
|
package/install.ps1
CHANGED
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
# You can use "View source" of this page to see the full script.
|
|
14
14
|
|
|
15
15
|
# REPO
|
|
16
|
-
$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/8.
|
|
17
|
-
$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/8.
|
|
16
|
+
$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/8.2.1/appwrite-cli-win-x64.exe"
|
|
17
|
+
$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/8.2.1/appwrite-cli-win-arm64.exe"
|
|
18
18
|
|
|
19
19
|
$APPWRITE_BINARY_NAME = "appwrite.exe"
|
|
20
20
|
|
package/install.sh
CHANGED
|
@@ -97,7 +97,7 @@ printSuccess() {
|
|
|
97
97
|
downloadBinary() {
|
|
98
98
|
echo "[2/4] Downloading executable for $OS ($ARCH) ..."
|
|
99
99
|
|
|
100
|
-
GITHUB_LATEST_VERSION="8.
|
|
100
|
+
GITHUB_LATEST_VERSION="8.2.1"
|
|
101
101
|
GITHUB_FILE="appwrite-cli-${OS}-${ARCH}"
|
|
102
102
|
GITHUB_URL="https://github.com/$GITHUB_REPOSITORY_NAME/releases/download/$GITHUB_LATEST_VERSION/$GITHUB_FILE"
|
|
103
103
|
|
package/lib/client.js
CHANGED
|
@@ -16,8 +16,8 @@ class Client {
|
|
|
16
16
|
'x-sdk-name': 'Command Line',
|
|
17
17
|
'x-sdk-platform': 'console',
|
|
18
18
|
'x-sdk-language': 'cli',
|
|
19
|
-
'x-sdk-version': '8.
|
|
20
|
-
'user-agent' : `AppwriteCLI/8.
|
|
19
|
+
'x-sdk-version': '8.2.1',
|
|
20
|
+
'user-agent' : `AppwriteCLI/8.2.1 (${os.type()} ${os.version()}; ${os.arch()})`,
|
|
21
21
|
'X-Appwrite-Response-Format' : '1.7.0',
|
|
22
22
|
};
|
|
23
23
|
}
|
package/lib/commands/push.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { parse: parseDotenv } = require('dotenv');
|
|
1
4
|
const chalk = require('chalk');
|
|
2
5
|
const inquirer = require("inquirer");
|
|
3
6
|
const JSONbig = require("json-bigint")({ storeAsString: false });
|
|
@@ -12,7 +15,7 @@ const { proxyCreateFunctionRule, proxyCreateSiteRule, proxyListRules } = require
|
|
|
12
15
|
const { consoleVariables } = require('./console');
|
|
13
16
|
const { sdkForConsole } = require('../sdks')
|
|
14
17
|
const { functionsGet, functionsCreate, functionsUpdate, functionsCreateDeployment, functionsGetDeployment, functionsListVariables, functionsDeleteVariable, functionsCreateVariable } = require('./functions');
|
|
15
|
-
const { sitesGet, sitesCreate, sitesUpdate, sitesCreateDeployment, sitesGetDeployment, sitesCreateVariable } = require('./sites');
|
|
18
|
+
const { sitesGet, sitesCreate, sitesUpdate, sitesCreateDeployment, sitesGetDeployment, sitesCreateVariable, sitesListVariables, sitesDeleteVariable } = require('./sites');
|
|
16
19
|
const {
|
|
17
20
|
databasesGet,
|
|
18
21
|
databasesCreate,
|
|
@@ -149,37 +152,6 @@ const awaitPools = {
|
|
|
149
152
|
iteration + 1
|
|
150
153
|
);
|
|
151
154
|
},
|
|
152
|
-
wipeVariables: async (functionId, iteration = 1) => {
|
|
153
|
-
if (iteration > pollMaxDebounces) {
|
|
154
|
-
return false;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const { total } = await functionsListVariables({
|
|
158
|
-
functionId,
|
|
159
|
-
queries: ['limit(1)'],
|
|
160
|
-
parseOutput: false
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
if (total === 0) {
|
|
164
|
-
return true;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (pollMaxDebounces === POLL_DEFAULT_VALUE) {
|
|
168
|
-
let steps = Math.max(1, Math.ceil(total / STEP_SIZE));
|
|
169
|
-
if (steps > 1 && iteration === 1) {
|
|
170
|
-
pollMaxDebounces *= steps;
|
|
171
|
-
|
|
172
|
-
log('Found a large number of variables, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes')
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
await new Promise(resolve => setTimeout(resolve, POLL_DEBOUNCE));
|
|
177
|
-
|
|
178
|
-
return await awaitPools.wipeVariables(
|
|
179
|
-
functionId,
|
|
180
|
-
iteration + 1
|
|
181
|
-
);
|
|
182
|
-
},
|
|
183
155
|
deleteAttributes: async (databaseId, collectionId, attributeKeys, iteration = 1) => {
|
|
184
156
|
if (iteration > pollMaxDebounces) {
|
|
185
157
|
return false;
|
|
@@ -508,6 +480,7 @@ const createAttribute = (databaseId, collectionId, attribute) => {
|
|
|
508
480
|
required: attribute.required,
|
|
509
481
|
xdefault: attribute.default,
|
|
510
482
|
array: attribute.array,
|
|
483
|
+
encrypt: attribute.encrypt,
|
|
511
484
|
parseOutput: false
|
|
512
485
|
})
|
|
513
486
|
|
|
@@ -844,10 +817,14 @@ const attributesToCreate = async (remoteAttributes, localAttributes, collection,
|
|
|
844
817
|
|
|
845
818
|
if (!cliConfig.force) {
|
|
846
819
|
if (deleting.length > 0 && !isIndex) {
|
|
847
|
-
log(
|
|
820
|
+
console.log(`${chalk.red('-------------------------------------------------------')}`);
|
|
821
|
+
console.log(`${chalk.red('| WARNING: Attribute deletion may cause loss of data |')}`);
|
|
822
|
+
console.log(`${chalk.red('-------------------------------------------------------')}`);
|
|
848
823
|
}
|
|
849
824
|
if (conflicts.length > 0 && !isIndex) {
|
|
850
|
-
log(
|
|
825
|
+
console.log(`${chalk.red('---------------------------------------------------------')}`);
|
|
826
|
+
console.log(`${chalk.red('| WARNING: Attribute recreation may cause loss of data |')}`);
|
|
827
|
+
console.log(`${chalk.red('---------------------------------------------------------')}`);
|
|
851
828
|
}
|
|
852
829
|
|
|
853
830
|
if ((await getConfirmation()) !== true) {
|
|
@@ -1042,7 +1019,7 @@ const pushSettings = async () => {
|
|
|
1042
1019
|
}
|
|
1043
1020
|
}
|
|
1044
1021
|
|
|
1045
|
-
const pushSite = async({ siteId, async, code } = { returnOnZero: false }) => {
|
|
1022
|
+
const pushSite = async({ siteId, async, code, withVariables } = { returnOnZero: false }) => {
|
|
1046
1023
|
process.chdir(localConfig.configDirectoryPath)
|
|
1047
1024
|
|
|
1048
1025
|
const siteIds = [];
|
|
@@ -1175,7 +1152,6 @@ const pushSite = async({ siteId, async, code } = { returnOnZero: false }) => {
|
|
|
1175
1152
|
timeout: site.timeout,
|
|
1176
1153
|
enabled: site.enabled,
|
|
1177
1154
|
logging: site.logging,
|
|
1178
|
-
vars: JSON.stringify(site.vars),
|
|
1179
1155
|
parseOutput: false
|
|
1180
1156
|
});
|
|
1181
1157
|
|
|
@@ -1208,16 +1184,43 @@ const pushSite = async({ siteId, async, code } = { returnOnZero: false }) => {
|
|
|
1208
1184
|
}
|
|
1209
1185
|
}
|
|
1210
1186
|
|
|
1211
|
-
|
|
1187
|
+
if (withVariables) {
|
|
1188
|
+
updaterRow.update({ status: 'Creating variables' }).replaceSpinner(SPINNER_ARC);
|
|
1212
1189
|
|
|
1213
|
-
|
|
1214
|
-
await sitesCreateVariable({
|
|
1190
|
+
const { variables } = await paginate(sitesListVariables, {
|
|
1215
1191
|
siteId: site['$id'],
|
|
1216
|
-
key: variable['key'],
|
|
1217
|
-
value: variable['value'],
|
|
1218
1192
|
parseOutput: false
|
|
1219
|
-
});
|
|
1220
|
-
|
|
1193
|
+
}, 100, 'variables');
|
|
1194
|
+
|
|
1195
|
+
await Promise.all(variables.map(async variable => {
|
|
1196
|
+
await sitesDeleteVariable({
|
|
1197
|
+
siteId: site['$id'],
|
|
1198
|
+
variableId: variable['$id'],
|
|
1199
|
+
parseOutput: false
|
|
1200
|
+
});
|
|
1201
|
+
}));
|
|
1202
|
+
|
|
1203
|
+
const envFileLocation = `${site['path']}/.env`;
|
|
1204
|
+
let envVariables = [];
|
|
1205
|
+
try {
|
|
1206
|
+
if (fs.existsSync(envFileLocation)) {
|
|
1207
|
+
const envObject = parseDotenv(fs.readFileSync(envFileLocation, 'utf8'));
|
|
1208
|
+
envVariables = Object.entries(envObject || {}).map(([key, value]) => ({ key, value }));
|
|
1209
|
+
}
|
|
1210
|
+
} catch (error) {
|
|
1211
|
+
// Handle parsing errors gracefully
|
|
1212
|
+
envVariables = [];
|
|
1213
|
+
}
|
|
1214
|
+
await Promise.all(envVariables.map(async variable => {
|
|
1215
|
+
await sitesCreateVariable({
|
|
1216
|
+
siteId: site['$id'],
|
|
1217
|
+
key: variable.key,
|
|
1218
|
+
value: variable.value,
|
|
1219
|
+
parseOutput: false,
|
|
1220
|
+
secret: false
|
|
1221
|
+
});
|
|
1222
|
+
}));
|
|
1223
|
+
}
|
|
1221
1224
|
|
|
1222
1225
|
if (code === false) {
|
|
1223
1226
|
successfullyPushed++;
|
|
@@ -1470,7 +1473,6 @@ const pushFunction = async ({ functionId, async, code, withVariables } = { retur
|
|
|
1470
1473
|
entrypoint: func.entrypoint,
|
|
1471
1474
|
commands: func.commands,
|
|
1472
1475
|
scopes: func.scopes,
|
|
1473
|
-
vars: JSON.stringify(func.vars),
|
|
1474
1476
|
parseOutput: false
|
|
1475
1477
|
});
|
|
1476
1478
|
|
|
@@ -1519,19 +1521,25 @@ const pushFunction = async ({ functionId, async, code, withVariables } = { retur
|
|
|
1519
1521
|
});
|
|
1520
1522
|
}));
|
|
1521
1523
|
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1524
|
+
const envFileLocation = `${func['path']}/.env`;
|
|
1525
|
+
let envVariables = [];
|
|
1526
|
+
try {
|
|
1527
|
+
if (fs.existsSync(envFileLocation)) {
|
|
1528
|
+
const envObject = parseDotenv(fs.readFileSync(envFileLocation, 'utf8'));
|
|
1529
|
+
envVariables = Object.entries(envObject || {}).map(([key, value]) => ({ key, value }));
|
|
1530
|
+
}
|
|
1531
|
+
} catch (error) {
|
|
1532
|
+
// Handle parsing errors gracefully
|
|
1533
|
+
envVariables = [];
|
|
1526
1534
|
}
|
|
1527
|
-
|
|
1528
|
-
// Deploy local variables
|
|
1529
|
-
await Promise.all((func['vars'] ?? []).map(async variable => {
|
|
1535
|
+
await Promise.all(envVariables.map(async variable => {
|
|
1530
1536
|
await functionsCreateVariable({
|
|
1531
1537
|
functionId: func['$id'],
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1538
|
+
variableId: ID.unique(),
|
|
1539
|
+
key: variable.key,
|
|
1540
|
+
value: variable.value,
|
|
1541
|
+
parseOutput: false,
|
|
1542
|
+
secret: false
|
|
1535
1543
|
});
|
|
1536
1544
|
}));
|
|
1537
1545
|
}
|
|
@@ -2060,6 +2068,7 @@ push
|
|
|
2060
2068
|
.option(`-f, --site-id <site-id>`, `ID of site to run`)
|
|
2061
2069
|
.option(`-A, --async`, `Don't wait for sites deployments status`)
|
|
2062
2070
|
.option("--no-code", "Don't push the site's code")
|
|
2071
|
+
.option("--with-variables", `Push site variables.`)
|
|
2063
2072
|
.action(actionRunner(pushSite));
|
|
2064
2073
|
|
|
2065
2074
|
push
|
package/lib/commands/types.js
CHANGED
|
@@ -58,12 +58,22 @@ const typesLanguageOption = new Option(
|
|
|
58
58
|
.choices(["auto", "ts", "js", "php", "kotlin", "swift", "java", "dart"])
|
|
59
59
|
.default("auto");
|
|
60
60
|
|
|
61
|
-
const
|
|
61
|
+
const typesStrictOption = new Option(
|
|
62
|
+
"-s, --strict",
|
|
63
|
+
"Enable strict mode to automatically convert field names to follow language conventions"
|
|
64
|
+
)
|
|
65
|
+
.default(false);
|
|
66
|
+
|
|
67
|
+
const typesCommand = actionRunner(async (rawOutputDirectory, {language, strict}) => {
|
|
62
68
|
if (language === "auto") {
|
|
63
69
|
language = detectLanguage();
|
|
64
70
|
log(`Detected language: ${language}`);
|
|
65
71
|
}
|
|
66
72
|
|
|
73
|
+
if (strict) {
|
|
74
|
+
log(`Strict mode enabled: Field names will be converted to follow ${language} conventions`);
|
|
75
|
+
}
|
|
76
|
+
|
|
67
77
|
const meta = createLanguageMeta(language);
|
|
68
78
|
|
|
69
79
|
const rawOutputPath = rawOutputDirectory;
|
|
@@ -106,6 +116,7 @@ const typesCommand = actionRunner(async (rawOutputDirectory, {language}) => {
|
|
|
106
116
|
if (meta.isSingleFile()) {
|
|
107
117
|
const content = templater({
|
|
108
118
|
collections,
|
|
119
|
+
strict,
|
|
109
120
|
...templateHelpers,
|
|
110
121
|
getType: meta.getType
|
|
111
122
|
});
|
|
@@ -118,6 +129,7 @@ const typesCommand = actionRunner(async (rawOutputDirectory, {language}) => {
|
|
|
118
129
|
for (const collection of collections) {
|
|
119
130
|
const content = templater({
|
|
120
131
|
collection,
|
|
132
|
+
strict,
|
|
121
133
|
...templateHelpers,
|
|
122
134
|
getType: meta.getType
|
|
123
135
|
});
|
|
@@ -136,6 +148,7 @@ const types = new Command("types")
|
|
|
136
148
|
.description("Generate types for your Appwrite project")
|
|
137
149
|
.addArgument(typesOutputArgument)
|
|
138
150
|
.addOption(typesLanguageOption)
|
|
151
|
+
.addOption(typesStrictOption)
|
|
139
152
|
.action(actionRunner(typesCommand));
|
|
140
153
|
|
|
141
154
|
module.exports = { types };
|
package/lib/config.js
CHANGED
package/lib/parser.js
CHANGED
|
@@ -24,7 +24,9 @@ const parse = (data) => {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
for (let key in data) {
|
|
27
|
-
if (
|
|
27
|
+
if (data[key] === null) {
|
|
28
|
+
console.log(`${chalk.yellow.bold(key)} : null`);
|
|
29
|
+
} else if (Array.isArray(data[key])) {
|
|
28
30
|
console.log(`${chalk.yellow.bold.underline(key)}`);
|
|
29
31
|
if (typeof data[key][0] === 'object') {
|
|
30
32
|
drawTable(data[key]);
|
|
@@ -120,7 +122,7 @@ const parseError = (err) => {
|
|
|
120
122
|
} catch {
|
|
121
123
|
}
|
|
122
124
|
|
|
123
|
-
const version = '8.
|
|
125
|
+
const version = '8.2.1';
|
|
124
126
|
const stepsToReproduce = `Running \`appwrite ${cliConfig.reportData.data.args.join(' ')}\``;
|
|
125
127
|
const yourEnvironment = `CLI version: ${version}\nOperation System: ${os.type()}\nAppwrite version: ${appwriteVersion}\nIs Cloud: ${isCloud()}`;
|
|
126
128
|
|
|
@@ -1,8 +1,45 @@
|
|
|
1
1
|
/** @typedef {import('../attribute').Attribute} Attribute */
|
|
2
2
|
const { AttributeType } = require('../attribute');
|
|
3
3
|
const { LanguageMeta } = require("./language");
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
4
6
|
|
|
5
7
|
class Dart extends LanguageMeta {
|
|
8
|
+
getPackageName() {
|
|
9
|
+
const pubspecPath = path.join(this.getCurrentDirectory(), 'pubspec.yaml');
|
|
10
|
+
if (fs.existsSync(pubspecPath)) {
|
|
11
|
+
const pubspecContent = fs.readFileSync(pubspecPath, 'utf8');
|
|
12
|
+
const lines = pubspecContent.split('\n');
|
|
13
|
+
|
|
14
|
+
const dependenciesIndex = lines.findIndex(line => line.trim() === 'dependencies:');
|
|
15
|
+
|
|
16
|
+
if (dependenciesIndex !== -1) {
|
|
17
|
+
const indent = lines[dependenciesIndex].search(/\S|$/);
|
|
18
|
+
const dependencies = [];
|
|
19
|
+
for (let i = dependenciesIndex + 1; i < lines.length; i++) {
|
|
20
|
+
const line = lines[i];
|
|
21
|
+
if (line.trim() === '') continue;
|
|
22
|
+
|
|
23
|
+
const lineIndent = line.search(/\S|$/);
|
|
24
|
+
if (lineIndent <= indent && line.trim() !== '') {
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
dependencies.push(line.trim());
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (dependencies.some(dep => dep.startsWith('dart_appwrite:'))) {
|
|
32
|
+
return 'dart_appwrite';
|
|
33
|
+
}
|
|
34
|
+
if (dependencies.some(dep => dep.startsWith('appwrite:'))) {
|
|
35
|
+
return 'appwrite';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return 'appwrite';
|
|
41
|
+
}
|
|
42
|
+
|
|
6
43
|
getType(attribute) {
|
|
7
44
|
let type = "";
|
|
8
45
|
switch (attribute.type) {
|
|
@@ -46,42 +83,55 @@ class Dart extends LanguageMeta {
|
|
|
46
83
|
}
|
|
47
84
|
|
|
48
85
|
getTemplate() {
|
|
49
|
-
return
|
|
86
|
+
return `import 'package:${this.getPackageName()}/models.dart';
|
|
87
|
+
<% for (const attribute of collection.attributes) { -%>
|
|
50
88
|
<% if (attribute.type === 'relationship') { -%>
|
|
51
89
|
import '<%- attribute.relatedCollection.toLowerCase() %>.dart';
|
|
52
90
|
|
|
53
91
|
<% } -%>
|
|
54
92
|
<% } -%>
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
* You can regenerate it by running \`appwrite types -l dart ${this.getCurrentDirectory()}\`.
|
|
58
|
-
*/
|
|
93
|
+
/// This file is auto-generated by the Appwrite CLI.
|
|
94
|
+
/// You can regenerate it by running \`appwrite types -l dart ${this.getCurrentDirectory()}\`.
|
|
59
95
|
|
|
60
96
|
<% for (const attribute of collection.attributes) { -%>
|
|
61
97
|
<% if (attribute.format === 'enum') { -%>
|
|
62
98
|
enum <%- toPascalCase(attribute.key) %> {
|
|
63
99
|
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
|
|
64
|
-
<%-
|
|
100
|
+
<%- strict ? toCamelCase(element) : element %><% if (index < attribute.elements.length - 1) { %>,<% } %>
|
|
65
101
|
<% } -%>
|
|
66
102
|
}
|
|
67
103
|
|
|
68
104
|
<% } -%>
|
|
69
105
|
<% } -%>
|
|
70
|
-
class <%= toPascalCase(collection.name) %> {
|
|
106
|
+
class <%= toPascalCase(collection.name) %> extends Document {
|
|
71
107
|
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
|
|
72
|
-
<%- getType(attribute) %> <%= toCamelCase(attribute.key) %>;
|
|
108
|
+
<%- getType(attribute) %> <%= strict ? toCamelCase(attribute.key) : attribute.key %>;
|
|
73
109
|
<% } -%>
|
|
74
110
|
|
|
75
111
|
<%= toPascalCase(collection.name) %>({
|
|
112
|
+
required super.$id,
|
|
113
|
+
required super.$collectionId,
|
|
114
|
+
required super.$databaseId,
|
|
115
|
+
required super.$createdAt,
|
|
116
|
+
required super.$updatedAt,
|
|
117
|
+
required super.$permissions,
|
|
118
|
+
required super.data,
|
|
76
119
|
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
|
|
77
|
-
<% if (attribute.required) { %>required <% } %>this.<%= toCamelCase(attribute.key) %><% if (index < collection.attributes.length - 1) { %>,<% } %>
|
|
120
|
+
<% if (attribute.required) { %>required <% } %>this.<%= strict ? toCamelCase(attribute.key) : attribute.key %><% if (index < collection.attributes.length - 1) { %>,<% } %>
|
|
78
121
|
<% } -%>
|
|
79
122
|
});
|
|
80
123
|
|
|
81
124
|
factory <%= toPascalCase(collection.name) %>.fromMap(Map<String, dynamic> map) {
|
|
82
125
|
return <%= toPascalCase(collection.name) %>(
|
|
126
|
+
$id: map['\\$id'].toString(),
|
|
127
|
+
$collectionId: map['\\$collectionId'].toString(),
|
|
128
|
+
$databaseId: map['\\$databaseId'].toString(),
|
|
129
|
+
$createdAt: map['\\$createdAt'].toString(),
|
|
130
|
+
$updatedAt: map['\\$updatedAt'].toString(),
|
|
131
|
+
$permissions: List<String>.from(map['\\$permissions'] ?? []),
|
|
132
|
+
data: map,
|
|
83
133
|
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
|
|
84
|
-
<%= toCamelCase(attribute.key) %>: <% if (attribute.type === 'string' || attribute.type === 'email' || attribute.type === 'datetime') { -%>
|
|
134
|
+
<%= strict ? toCamelCase(attribute.key) : attribute.key %>: <% if (attribute.type === 'string' || attribute.type === 'email' || attribute.type === 'datetime') { -%>
|
|
85
135
|
<% if (attribute.format === 'enum') { -%>
|
|
86
136
|
<% if (attribute.array) { -%>
|
|
87
137
|
(map['<%= attribute.key %>'] as List<dynamic>?)?.map((e) => <%- toPascalCase(attribute.key) %>.values.firstWhere((element) => element.name == e)).toList()<% if (!attribute.required) { %> ?? []<% } -%>
|
|
@@ -130,21 +180,27 @@ map['<%= attribute.key %>'] != null ? <%- toPascalCase(attribute.relatedCollecti
|
|
|
130
180
|
|
|
131
181
|
Map<String, dynamic> toMap() {
|
|
132
182
|
return {
|
|
183
|
+
"\\$id": $id,
|
|
184
|
+
"\\$collectionId": $collectionId,
|
|
185
|
+
"\\$databaseId": $databaseId,
|
|
186
|
+
"\\$createdAt": $createdAt,
|
|
187
|
+
"\\$updatedAt": $updatedAt,
|
|
188
|
+
"\\$permissions": $permissions,
|
|
133
189
|
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
|
|
134
190
|
"<%= attribute.key %>": <% if (attribute.type === 'relationship') { -%>
|
|
135
191
|
<% if ((attribute.relationType === 'oneToMany' && attribute.side === 'parent') || (attribute.relationType === 'manyToOne' && attribute.side === 'child') || attribute.relationType === 'manyToMany') { -%>
|
|
136
|
-
<%= toCamelCase(attribute.key) %><% if (!attribute.required) { %>?<% } %>.map((e) => e.toMap()).toList()<% if (!attribute.required) { %> ?? []<% } -%>
|
|
192
|
+
<%= strict ? toCamelCase(attribute.key) : attribute.key %><% if (!attribute.required) { %>?<% } %>.map((e) => e.toMap()).toList()<% if (!attribute.required) { %> ?? []<% } -%>
|
|
137
193
|
<% } else { -%>
|
|
138
|
-
<%= toCamelCase(attribute.key) %><% if (!attribute.required) { %>?<% } %>.toMap()<% if (!attribute.required) { %> ?? {}<% } -%>
|
|
194
|
+
<%= strict ? toCamelCase(attribute.key) : attribute.key %><% if (!attribute.required) { %>?<% } %>.toMap()<% if (!attribute.required) { %> ?? {}<% } -%>
|
|
139
195
|
<% } -%>
|
|
140
196
|
<% } else if (attribute.format === 'enum') { -%>
|
|
141
197
|
<% if (attribute.array) { -%>
|
|
142
|
-
<%= toCamelCase(attribute.key) %><% if (!attribute.required) { %>?<% } %>.map((e) => e.name).toList()<% if (!attribute.required) { %> ?? []<% } -%>
|
|
198
|
+
<%= strict ? toCamelCase(attribute.key) : attribute.key %><% if (!attribute.required) { %>?<% } %>.map((e) => e.name).toList()<% if (!attribute.required) { %> ?? []<% } -%>
|
|
143
199
|
<% } else { -%>
|
|
144
|
-
<%= toCamelCase(attribute.key) %><% if (!attribute.required) { %>?<% } %>.name<% if (!attribute.required) { %> ?? null<% } -%>
|
|
200
|
+
<%= strict ? toCamelCase(attribute.key) : attribute.key %><% if (!attribute.required) { %>?<% } %>.name<% if (!attribute.required) { %> ?? null<% } -%>
|
|
145
201
|
<% } -%>
|
|
146
202
|
<% } else { -%>
|
|
147
|
-
<%= toCamelCase(attribute.key) -%>
|
|
203
|
+
<%= strict ? toCamelCase(attribute.key) : attribute.key -%>
|
|
148
204
|
<% } -%><% if (index < collection.attributes.length - 1) { %>,<% } %>
|
|
149
205
|
<% } -%>
|
|
150
206
|
};
|
|
@@ -61,63 +61,63 @@ public class <%- toPascalCase(collection.name) %> {
|
|
|
61
61
|
<% for (const attribute of collection.attributes) { -%>
|
|
62
62
|
<% if (attribute.format === 'enum') { -%>
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
public enum <%- toPascalCase(attribute.key) %> {
|
|
65
65
|
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
|
|
66
|
-
|
|
66
|
+
<%- strict ? toSnakeCase(element) : element %><%- index < attribute.elements.length - 1 ? ',' : ';' %>
|
|
67
67
|
<% } -%>
|
|
68
|
-
|
|
68
|
+
}
|
|
69
69
|
|
|
70
70
|
<% } -%>
|
|
71
71
|
<% } -%>
|
|
72
72
|
<% for (const attribute of collection.attributes) { -%>
|
|
73
|
-
|
|
73
|
+
private <%- getType(attribute) %> <%- strict ? toCamelCase(attribute.key) : attribute.key %>;
|
|
74
74
|
<% } -%>
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
public <%- toPascalCase(collection.name) %>() {
|
|
77
|
+
}
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
public <%- toPascalCase(collection.name) %>(
|
|
80
80
|
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
|
|
81
|
-
|
|
81
|
+
<%- getType(attribute) %> <%= strict ? toCamelCase(attribute.key) : attribute.key %><%- index < collection.attributes.length - 1 ? ',' : '' %>
|
|
82
82
|
<% } -%>
|
|
83
|
-
|
|
83
|
+
) {
|
|
84
84
|
<% for (const attribute of collection.attributes) { -%>
|
|
85
|
-
|
|
85
|
+
this.<%= strict ? toCamelCase(attribute.key) : attribute.key %> = <%= strict ? toCamelCase(attribute.key) : attribute.key %>;
|
|
86
86
|
<% } -%>
|
|
87
|
-
|
|
87
|
+
}
|
|
88
88
|
|
|
89
89
|
<% for (const attribute of collection.attributes) { -%>
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
public <%- getType(attribute) %> get<%- toPascalCase(attribute.key) %>() {
|
|
91
|
+
return <%= strict ? toCamelCase(attribute.key) : attribute.key %>;
|
|
92
|
+
}
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
public void set<%- toPascalCase(attribute.key) %>(<%- getType(attribute) %> <%= strict ? toCamelCase(attribute.key) : attribute.key %>) {
|
|
95
|
+
this.<%= strict ? toCamelCase(attribute.key) : attribute.key %> = <%= strict ? toCamelCase(attribute.key) : attribute.key %>;
|
|
96
|
+
}
|
|
97
97
|
|
|
98
98
|
<% } -%>
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
99
|
+
@Override
|
|
100
|
+
public boolean equals(Object obj) {
|
|
101
|
+
if (this == obj) return true;
|
|
102
|
+
if (obj == null || getClass() != obj.getClass()) return false;
|
|
103
|
+
<%- toPascalCase(collection.name) %> that = (<%- toPascalCase(collection.name) %>) obj;
|
|
104
|
+
return <% collection.attributes.forEach((attr, index) => { %>Objects.equals(<%= toCamelCase(attr.key) %>, that.<%= toCamelCase(attr.key) %>)<% if (index < collection.attributes.length - 1) { %> &&
|
|
105
|
+
<% } }); %>;
|
|
106
|
+
}
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
@Override
|
|
109
|
+
public int hashCode() {
|
|
110
|
+
return Objects.hash(<%= collection.attributes.map(attr => toCamelCase(attr.key)).join(', ') %>);
|
|
111
|
+
}
|
|
112
112
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
<% for (const
|
|
117
|
-
|
|
113
|
+
@Override
|
|
114
|
+
public String toString() {
|
|
115
|
+
return "<%- toPascalCase(collection.name) %>{" +
|
|
116
|
+
<% for (const attribute of collection.attributes) { -%>
|
|
117
|
+
"<%= strict ? toCamelCase(attribute.key) : attribute.key %>=" + <%= strict ? toCamelCase(attribute.key) : attribute.key %> +
|
|
118
118
|
<% } -%>
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
'}';
|
|
120
|
+
}
|
|
121
121
|
}
|
|
122
122
|
`;
|
|
123
123
|
}
|
|
@@ -16,7 +16,7 @@ class JavaScript extends LanguageMeta {
|
|
|
16
16
|
case AttributeType.URL:
|
|
17
17
|
type = "string";
|
|
18
18
|
if (attribute.format === AttributeType.ENUM) {
|
|
19
|
-
type =
|
|
19
|
+
type = LanguageMeta.toPascalCase(attribute.key);
|
|
20
20
|
}
|
|
21
21
|
break;
|
|
22
22
|
case AttributeType.INTEGER:
|
|
@@ -31,7 +31,7 @@ class JavaScript extends LanguageMeta {
|
|
|
31
31
|
case AttributeType.RELATIONSHIP:
|
|
32
32
|
type = LanguageMeta.toPascalCase(attribute.relatedCollection);
|
|
33
33
|
if ((attribute.relationType === 'oneToMany' && attribute.side === 'parent') || (attribute.relationType === 'manyToOne' && attribute.side === 'child') || attribute.relationType === 'manyToMany') {
|
|
34
|
-
type =
|
|
34
|
+
type = `${type}[]`;
|
|
35
35
|
}
|
|
36
36
|
break;
|
|
37
37
|
default:
|
|
@@ -65,21 +65,32 @@ class JavaScript extends LanguageMeta {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
getTemplate() {
|
|
68
|
-
return
|
|
68
|
+
return `
|
|
69
|
+
// This file is auto-generated by the Appwrite CLI.
|
|
70
|
+
// You can regenerate it by running \`appwrite types -l js ${this.getCurrentDirectory()}\`.
|
|
71
|
+
|
|
72
|
+
/**
|
|
69
73
|
* @typedef {import('${this._getAppwriteDependency()}').Models.Document} Document
|
|
70
74
|
*/
|
|
71
75
|
|
|
76
|
+
<% for (const collection of collections) { -%>
|
|
77
|
+
<% for (const attribute of collection.attributes) { -%>
|
|
78
|
+
<% if (attribute.format === 'enum') { -%>
|
|
72
79
|
/**
|
|
73
|
-
*
|
|
74
|
-
* You can regenerate it by running \`appwrite types -l js ${this.getCurrentDirectory()}\`.
|
|
80
|
+
* @typedef {"<%- attribute.elements.join('"|"') %>"} <%- toPascalCase(attribute.key) %>
|
|
75
81
|
*/
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
82
|
+
|
|
83
|
+
<% } -%>
|
|
84
|
+
<% } -%>
|
|
85
|
+
<% } -%>
|
|
86
|
+
<% for (const collection of collections) { %>/**
|
|
87
|
+
* @typedef {Document & {
|
|
79
88
|
<% for (const attribute of collection.attributes) { -%>
|
|
80
|
-
*
|
|
89
|
+
* <%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute) %>;
|
|
81
90
|
<% } -%>
|
|
91
|
+
* }} <%- toPascalCase(collection.name) %>
|
|
82
92
|
*/
|
|
93
|
+
|
|
83
94
|
<% } %>`;
|
|
84
95
|
}
|
|
85
96
|
|
|
@@ -63,7 +63,7 @@ import <%- toPascalCase(attribute.relatedCollection) %>
|
|
|
63
63
|
<% if (attribute.format === 'enum') { -%>
|
|
64
64
|
enum class <%- toPascalCase(attribute.key) %> {
|
|
65
65
|
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
|
|
66
|
-
|
|
66
|
+
<%- strict ? toUpperSnakeCase(element) : element %><%- index < attribute.elements.length - 1 ? ',' : '' %>
|
|
67
67
|
<% } -%>
|
|
68
68
|
}
|
|
69
69
|
|
|
@@ -71,7 +71,7 @@ enum class <%- toPascalCase(attribute.key) %> {
|
|
|
71
71
|
<% } -%>
|
|
72
72
|
data class <%- toPascalCase(collection.name) %>(
|
|
73
73
|
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
|
|
74
|
-
|
|
74
|
+
val <%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute) %><% if (index < collection.attributes.length - 1) { %>,<% } %>
|
|
75
75
|
<% } -%>
|
|
76
76
|
)`;
|
|
77
77
|
}
|
|
@@ -49,10 +49,8 @@ class PHP extends LanguageMeta {
|
|
|
49
49
|
return `<?php
|
|
50
50
|
namespace Appwrite\\Models;
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
* You can regenerate it by running \`appwrite types -l php ${this.getCurrentDirectory()}\`.
|
|
55
|
-
*/
|
|
52
|
+
// This file is auto-generated by the Appwrite CLI.
|
|
53
|
+
// You can regenerate it by running \`appwrite types -l php ${this.getCurrentDirectory()}\`.
|
|
56
54
|
|
|
57
55
|
<% for (const attribute of collection.attributes) { -%>
|
|
58
56
|
<% if (attribute.type === 'relationship' && !(attribute.relationType === 'manyToMany') && !(attribute.relationType === 'oneToMany' && attribute.side === 'parent')) { -%>
|
|
@@ -64,7 +62,7 @@ use Appwrite\\Models\\<%- toPascalCase(attribute.relatedCollection) %>;
|
|
|
64
62
|
<% if (attribute.format === 'enum') { -%>
|
|
65
63
|
enum <%- toPascalCase(attribute.key) %>: string {
|
|
66
64
|
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
|
|
67
|
-
case <%- toUpperSnakeCase(element) %> = '<%- element %>';
|
|
65
|
+
case <%- strict ? toUpperSnakeCase(element) : element %> = '<%- element %>';
|
|
68
66
|
<% } -%>
|
|
69
67
|
}
|
|
70
68
|
|
|
@@ -72,31 +70,33 @@ enum <%- toPascalCase(attribute.key) %>: string {
|
|
|
72
70
|
<% } -%>
|
|
73
71
|
class <%- toPascalCase(collection.name) %> {
|
|
74
72
|
<% for (const attribute of collection.attributes ){ -%>
|
|
75
|
-
private <%- getType(attribute) %> $<%- toCamelCase(attribute.key) %>;
|
|
73
|
+
private <%- getType(attribute) %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %>;
|
|
76
74
|
<% } -%>
|
|
77
75
|
|
|
78
76
|
public function __construct(
|
|
79
77
|
<% for (const attribute of collection.attributes ){ -%>
|
|
80
78
|
<% if (attribute.required) { -%>
|
|
81
|
-
<%- getType(attribute).replace('|null', '') %> $<%- toCamelCase(attribute.key) %><% if (collection.attributes.indexOf(attribute) < collection.attributes.length - 1) { %>,<% } %>
|
|
79
|
+
<%- getType(attribute).replace('|null', '') %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %><% if (collection.attributes.indexOf(attribute) < collection.attributes.length - 1) { %>,<% } %>
|
|
82
80
|
<% } else { -%>
|
|
83
|
-
?<%- getType(attribute).replace('|null', '') %> $<%- toCamelCase(attribute.key) %> = null<% if (collection.attributes.indexOf(attribute) < collection.attributes.length - 1) { %>,<% } %>
|
|
81
|
+
?<%- getType(attribute).replace('|null', '') %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %> = null<% if (collection.attributes.indexOf(attribute) < collection.attributes.length - 1) { %>,<% } %>
|
|
84
82
|
<% } -%>
|
|
85
83
|
<% } -%>
|
|
86
84
|
) {
|
|
87
85
|
<% for (const attribute of collection.attributes ){ -%>
|
|
88
|
-
$this-><%- toCamelCase(attribute.key) %> = $<%- toCamelCase(attribute.key) %>;
|
|
86
|
+
$this-><%- strict ? toCamelCase(attribute.key) : attribute.key %> = $<%- strict ? toCamelCase(attribute.key) : attribute.key %>;
|
|
89
87
|
<% } -%>
|
|
90
88
|
}
|
|
91
89
|
|
|
92
|
-
<% for (const attribute of collection.attributes
|
|
90
|
+
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
|
|
93
91
|
public function get<%- toPascalCase(attribute.key) %>(): <%- getType(attribute) %> {
|
|
94
|
-
return $this-><%- toCamelCase(attribute.key) %>;
|
|
92
|
+
return $this-><%- strict ? toCamelCase(attribute.key) : attribute.key %>;
|
|
95
93
|
}
|
|
96
94
|
|
|
97
|
-
public function set<%- toPascalCase(attribute.key) %>(<%- getType(attribute) %> $<%- toCamelCase(attribute.key) %>): void {
|
|
98
|
-
$this-><%- toCamelCase(attribute.key) %> = $<%- toCamelCase(attribute.key) %>;
|
|
95
|
+
public function set<%- toPascalCase(attribute.key) %>(<%- getType(attribute) %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %>): void {
|
|
96
|
+
$this-><%- strict ? toCamelCase(attribute.key) : attribute.key %> = $<%- strict ? toCamelCase(attribute.key) : attribute.key %>;
|
|
99
97
|
}
|
|
98
|
+
<% if (index < collection.attributes.length - 1) { %>
|
|
99
|
+
<% } -%>
|
|
100
100
|
<% } -%>
|
|
101
101
|
}`;
|
|
102
102
|
}
|
|
@@ -55,7 +55,7 @@ class Swift extends LanguageMeta {
|
|
|
55
55
|
<% if (attribute.format === 'enum') { -%>
|
|
56
56
|
public enum <%- toPascalCase(attribute.key) %>: String, Codable, CaseIterable {
|
|
57
57
|
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
|
|
58
|
-
case <%-
|
|
58
|
+
case <%- strict ? toCamelCase(element) : element %> = "<%- element %>"
|
|
59
59
|
<% } -%>
|
|
60
60
|
}
|
|
61
61
|
|
|
@@ -63,101 +63,101 @@ public enum <%- toPascalCase(attribute.key) %>: String, Codable, CaseIterable {
|
|
|
63
63
|
<% } -%>
|
|
64
64
|
public class <%- toPascalCase(collection.name) %>: Codable {
|
|
65
65
|
<% for (const attribute of collection.attributes) { -%>
|
|
66
|
-
|
|
66
|
+
public let <%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute) %>
|
|
67
67
|
<% } %>
|
|
68
|
-
|
|
68
|
+
enum CodingKeys: String, CodingKey {
|
|
69
69
|
<% for (const attribute of collection.attributes) { -%>
|
|
70
|
-
|
|
70
|
+
case <%- strict ? toCamelCase(attribute.key) : attribute.key %> = "<%- attribute.key %>"
|
|
71
71
|
<% } -%>
|
|
72
|
-
|
|
72
|
+
}
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
<% for (const attribute of collection.attributes) { -%>
|
|
76
|
-
|
|
74
|
+
init(
|
|
75
|
+
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
|
|
76
|
+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute) %><% if (index < collection.attributes.length - 1) { %>,<% } %>
|
|
77
77
|
<% } -%>
|
|
78
|
-
|
|
78
|
+
) {
|
|
79
79
|
<% for (const attribute of collection.attributes) { -%>
|
|
80
|
-
|
|
80
|
+
self.<%- strict ? toCamelCase(attribute.key) : attribute.key %> = <%- strict ? toCamelCase(attribute.key) : attribute.key %>
|
|
81
81
|
<% } -%>
|
|
82
|
-
|
|
82
|
+
}
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
public required init(from decoder: Decoder) throws {
|
|
85
|
+
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
86
86
|
|
|
87
87
|
<% for (const attribute of collection.attributes) { -%>
|
|
88
88
|
<% if (attribute.required) { -%>
|
|
89
|
-
|
|
89
|
+
self.<%- strict ? toCamelCase(attribute.key) : attribute.key %> = try container.decode(<%- getType(attribute).replace('?', '') %>.self, forKey: .<%- strict ? toCamelCase(attribute.key) : attribute.key %>)
|
|
90
90
|
<% } else { -%>
|
|
91
|
-
|
|
91
|
+
self.<%- strict ? toCamelCase(attribute.key) : attribute.key %> = try container.decodeIfPresent(<%- getType(attribute).replace('?', '') %>.self, forKey: .<%- strict ? toCamelCase(attribute.key) : attribute.key %>)
|
|
92
92
|
<% } -%>
|
|
93
93
|
<% } -%>
|
|
94
|
-
|
|
94
|
+
}
|
|
95
95
|
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
public func encode(to encoder: Encoder) throws {
|
|
97
|
+
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
98
98
|
|
|
99
99
|
<% for (const attribute of collection.attributes) { -%>
|
|
100
100
|
<% if (attribute.required) { -%>
|
|
101
|
-
|
|
101
|
+
try container.encode(<%- strict ? toCamelCase(attribute.key) : attribute.key %>, forKey: .<%- strict ? toCamelCase(attribute.key) : attribute.key %>)
|
|
102
102
|
<% } else { -%>
|
|
103
|
-
|
|
103
|
+
try container.encodeIfPresent(<%- strict ? toCamelCase(attribute.key) : attribute.key %>, forKey: .<%- strict ? toCamelCase(attribute.key) : attribute.key %>)
|
|
104
104
|
<% } -%>
|
|
105
105
|
<% } -%>
|
|
106
|
-
|
|
106
|
+
}
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
<% for (const attribute of collection.attributes) { -%>
|
|
108
|
+
public func toMap() -> [String: Any] {
|
|
109
|
+
return [
|
|
110
|
+
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
|
|
111
111
|
<% if (attribute.type === 'relationship') { -%>
|
|
112
|
-
|
|
112
|
+
"<%- attribute.key %>": <%- strict ? toCamelCase(attribute.key) : attribute.key %> as Any<% if (index < collection.attributes.length - 1) { %>,<% } %>
|
|
113
113
|
<% } else if (attribute.array && attribute.type !== 'string' && attribute.type !== 'integer' && attribute.type !== 'float' && attribute.type !== 'boolean') { -%>
|
|
114
|
-
|
|
114
|
+
"<%- attribute.key %>": <%- strict ? toCamelCase(attribute.key) : attribute.key %>?.map { $0.toMap() } as Any<% if (index < collection.attributes.length - 1) { %>,<% } %>
|
|
115
115
|
<% } else { -%>
|
|
116
|
-
|
|
116
|
+
"<%- attribute.key %>": <%- strict ? toCamelCase(attribute.key) : attribute.key %> as Any<% if (index < collection.attributes.length - 1) { %>,<% } %>
|
|
117
117
|
<% } -%>
|
|
118
118
|
<% } -%>
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
121
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
<% for (const attribute of collection.attributes) { -%>
|
|
122
|
+
public static func from(map: [String: Any]) -> <%- toPascalCase(collection.name) %> {
|
|
123
|
+
return <%- toPascalCase(collection.name) %>(
|
|
124
|
+
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
|
|
125
125
|
<% if (attribute.type === 'relationship') { -%>
|
|
126
126
|
<% if ((attribute.relationType === 'oneToMany' && attribute.side === 'parent') || (attribute.relationType === 'manyToOne' && attribute.side === 'child') || attribute.relationType === 'manyToMany') { -%>
|
|
127
|
-
|
|
127
|
+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [<%- toPascalCase(attribute.relatedCollection) %>]<% if (index < collection.attributes.length - 1) { %>,<% } %>
|
|
128
128
|
<% } else { -%>
|
|
129
|
-
|
|
129
|
+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> <%- toPascalCase(attribute.relatedCollection) %><% if (index < collection.attributes.length - 1) { %>,<% } %>
|
|
130
130
|
<% } -%>
|
|
131
131
|
<% } else if (attribute.array) { -%>
|
|
132
132
|
<% if (attribute.type === 'string') { -%>
|
|
133
|
-
|
|
133
|
+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [String]<% if (index < collection.attributes.length - 1) { %>,<% } %>
|
|
134
134
|
<% } else if (attribute.type === 'integer') { -%>
|
|
135
|
-
|
|
135
|
+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [Int]<% if (index < collection.attributes.length - 1) { %>,<% } %>
|
|
136
136
|
<% } else if (attribute.type === 'float') { -%>
|
|
137
|
-
|
|
137
|
+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [Double]<% if (index < collection.attributes.length - 1) { %>,<% } %>
|
|
138
138
|
<% } else if (attribute.type === 'boolean') { -%>
|
|
139
|
-
|
|
139
|
+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [Bool]<% if (index < collection.attributes.length - 1) { %>,<% } %>
|
|
140
140
|
<% } else { -%>
|
|
141
|
-
|
|
141
|
+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: (map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [[String: Any]])<% if (!attribute.required) { %>?<% } %>.map { <%- toPascalCase(attribute.type) %>.from(map: $0) }<% if (index < collection.attributes.length - 1) { %>,<% } %>
|
|
142
142
|
<% } -%>
|
|
143
143
|
<% } else { -%>
|
|
144
144
|
<% if ((attribute.type === 'string' || attribute.type === 'email' || attribute.type === 'datetime') && attribute.format !== 'enum') { -%>
|
|
145
|
-
|
|
145
|
+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> String<% if (index < collection.attributes.length - 1) { %>,<% } %>
|
|
146
146
|
<% } else if (attribute.type === 'string' && attribute.format === 'enum') { -%>
|
|
147
|
-
|
|
147
|
+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- toPascalCase(attribute.key) %>(rawValue: map["<%- attribute.key %>"] as! String)!<% if (index < collection.attributes.length - 1) { %>,<% } %>
|
|
148
148
|
<% } else if (attribute.type === 'integer') { -%>
|
|
149
|
-
|
|
149
|
+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> Int<% if (index < collection.attributes.length - 1) { %>,<% } %>
|
|
150
150
|
<% } else if (attribute.type === 'float') { -%>
|
|
151
|
-
|
|
151
|
+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> Double<% if (index < collection.attributes.length - 1) { %>,<% } %>
|
|
152
152
|
<% } else if (attribute.type === 'boolean') { -%>
|
|
153
|
-
|
|
153
|
+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> Bool<% if (index < collection.attributes.length - 1) { %>,<% } %>
|
|
154
154
|
<% } else { -%>
|
|
155
|
-
|
|
155
|
+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- toPascalCase(attribute.type) %>.from(map: map["<%- attribute.key %>"] as! [String: Any])<% if (index < collection.attributes.length - 1) { %>,<% } %>
|
|
156
156
|
<% } -%>
|
|
157
157
|
<% } -%>
|
|
158
158
|
<% } -%>
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
161
|
}`;
|
|
162
162
|
}
|
|
163
163
|
|
|
@@ -71,10 +71,8 @@ class TypeScript extends LanguageMeta {
|
|
|
71
71
|
getTemplate() {
|
|
72
72
|
return `import { type Models } from '${this._getAppwriteDependency()}';
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
* You can regenerate it by running \`appwrite types -l ts ${this.getCurrentDirectory()}\`.
|
|
77
|
-
*/
|
|
74
|
+
// This file is auto-generated by the Appwrite CLI.
|
|
75
|
+
// You can regenerate it by running \`appwrite types -l ts ${this.getCurrentDirectory()}\`.
|
|
78
76
|
|
|
79
77
|
<% for (const collection of collections) { -%>
|
|
80
78
|
<% for (const attribute of collection.attributes) { -%>
|
|
@@ -92,7 +90,7 @@ export enum <%- toPascalCase(attribute.key) %> {
|
|
|
92
90
|
<% for (const collection of collections) { -%>
|
|
93
91
|
export type <%- toPascalCase(collection.name) %> = Models.Document & {
|
|
94
92
|
<% for (const attribute of collection.attributes) { -%>
|
|
95
|
-
<%- toCamelCase(attribute.key) %>: <%- getType(attribute) %>;
|
|
93
|
+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute) %>;
|
|
96
94
|
<% } -%>
|
|
97
95
|
}
|
|
98
96
|
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "appwrite-cli",
|
|
3
3
|
"homepage": "https://appwrite.io/support",
|
|
4
4
|
"description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API",
|
|
5
|
-
"version": "8.
|
|
5
|
+
"version": "8.2.1",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"bin": {
|
package/scoop/appwrite.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://raw.githubusercontent.com/ScoopInstaller/Scoop/master/schema.json",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.2.1",
|
|
4
4
|
"description": "The Appwrite CLI is a command-line application that allows you to interact with Appwrite and perform server-side tasks using your terminal.",
|
|
5
5
|
"homepage": "https://github.com/appwrite/sdk-for-cli",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
7
7
|
"architecture": {
|
|
8
8
|
"64bit": {
|
|
9
|
-
"url": "https://github.com/appwrite/sdk-for-cli/releases/download/8.
|
|
9
|
+
"url": "https://github.com/appwrite/sdk-for-cli/releases/download/8.2.1/appwrite-cli-win-x64.exe",
|
|
10
10
|
"bin": [
|
|
11
11
|
[
|
|
12
12
|
"appwrite-cli-win-x64.exe",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
]
|
|
16
16
|
},
|
|
17
17
|
"arm64": {
|
|
18
|
-
"url": "https://github.com/appwrite/sdk-for-cli/releases/download/8.
|
|
18
|
+
"url": "https://github.com/appwrite/sdk-for-cli/releases/download/8.2.1/appwrite-cli-win-arm64.exe",
|
|
19
19
|
"bin": [
|
|
20
20
|
[
|
|
21
21
|
"appwrite-cli-win-arm64.exe",
|