appwrite-cli 7.0.0 → 8.0.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/README.md +2 -2
- package/docs/examples/proxy/create-redirect-rule.md +3 -1
- package/docs/examples/vcs/get-repository-contents.md +1 -0
- package/index.js +2 -2
- package/install.ps1 +2 -2
- package/install.sh +1 -1
- package/lib/client.js +2 -2
- package/lib/commands/databases.js +5 -5
- package/lib/commands/proxy.js +11 -1
- package/lib/commands/types.js +126 -0
- package/lib/commands/vcs.js +6 -1
- package/lib/parser.js +1 -2
- package/lib/type-generation/attribute.js +16 -0
- package/lib/type-generation/languages/dart.js +152 -0
- package/lib/type-generation/languages/java.js +121 -0
- package/lib/type-generation/languages/javascript.js +84 -0
- package/lib/type-generation/languages/kotlin.js +75 -0
- package/lib/type-generation/languages/language.js +125 -0
- package/lib/type-generation/languages/php.js +100 -0
- package/lib/type-generation/languages/swift.js +156 -0
- package/lib/type-generation/languages/typescript.js +97 -0
- package/package.json +2 -1
- package/scoop/appwrite.json +3 -3
- package/docs/examples/assistant/chat.md +0 -2
- package/lib/commands/assistant.js +0 -85
|
@@ -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) %>: string {
|
|
57
|
+
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
|
|
58
|
+
case <%- toUpperSnakeCase(element) %> = '<%- 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 };
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/** @typedef {import('../attribute').Attribute} Attribute */
|
|
2
|
+
const { AttributeType } = require('../attribute');
|
|
3
|
+
const { LanguageMeta } = require("./language");
|
|
4
|
+
|
|
5
|
+
class Swift 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 = `[${type}]`;
|
|
30
|
+
}
|
|
31
|
+
break;
|
|
32
|
+
default:
|
|
33
|
+
throw new Error(`Unknown attribute type: ${attribute.type}`);
|
|
34
|
+
}
|
|
35
|
+
if (attribute.array) {
|
|
36
|
+
type = "[" + type + "]";
|
|
37
|
+
}
|
|
38
|
+
if (!attribute.required) {
|
|
39
|
+
type += "?";
|
|
40
|
+
}
|
|
41
|
+
return type;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
getTemplate() {
|
|
45
|
+
return `import Foundation
|
|
46
|
+
|
|
47
|
+
<% for (const attribute of collection.attributes) { -%>
|
|
48
|
+
<% if (attribute.format === 'enum') { -%>
|
|
49
|
+
public enum <%- toPascalCase(attribute.key) %>: String, Codable, CaseIterable {
|
|
50
|
+
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
|
|
51
|
+
case <%- toSnakeCase(element) %> = "<%- element %>"
|
|
52
|
+
<% } -%>
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
<% } -%>
|
|
56
|
+
<% } -%>
|
|
57
|
+
public class <%- toPascalCase(collection.name) %>: Codable {
|
|
58
|
+
<% for (const attribute of collection.attributes) { -%>
|
|
59
|
+
public let <%- toCamelCase(attribute.key) %>: <%- getType(attribute) %>
|
|
60
|
+
<% } %>
|
|
61
|
+
enum CodingKeys: String, CodingKey {
|
|
62
|
+
<% for (const attribute of collection.attributes) { -%>
|
|
63
|
+
case <%- toCamelCase(attribute.key) %> = "<%- attribute.key %>"
|
|
64
|
+
<% } -%>
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
init(
|
|
68
|
+
<% for (const attribute of collection.attributes) { -%>
|
|
69
|
+
<%- toCamelCase(attribute.key) %>: <%- getType(attribute) %><% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
|
|
70
|
+
<% } -%>
|
|
71
|
+
) {
|
|
72
|
+
<% for (const attribute of collection.attributes) { -%>
|
|
73
|
+
self.<%- toCamelCase(attribute.key) %> = <%- toCamelCase(attribute.key) %>
|
|
74
|
+
<% } -%>
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public required init(from decoder: Decoder) throws {
|
|
78
|
+
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
79
|
+
|
|
80
|
+
<% for (const attribute of collection.attributes) { -%>
|
|
81
|
+
<% if (attribute.required) { -%>
|
|
82
|
+
self.<%- toCamelCase(attribute.key) %> = try container.decode(<%- getType(attribute).replace('?', '') %>.self, forKey: .<%- toCamelCase(attribute.key) %>)
|
|
83
|
+
<% } else { -%>
|
|
84
|
+
self.<%- toCamelCase(attribute.key) %> = try container.decodeIfPresent(<%- getType(attribute).replace('?', '') %>.self, forKey: .<%- toCamelCase(attribute.key) %>)
|
|
85
|
+
<% } -%>
|
|
86
|
+
<% } -%>
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public func encode(to encoder: Encoder) throws {
|
|
90
|
+
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
91
|
+
|
|
92
|
+
<% for (const attribute of collection.attributes) { -%>
|
|
93
|
+
<% if (attribute.required) { -%>
|
|
94
|
+
try container.encode(<%- toCamelCase(attribute.key) %>, forKey: .<%- toCamelCase(attribute.key) %>)
|
|
95
|
+
<% } else { -%>
|
|
96
|
+
try container.encodeIfPresent(<%- toCamelCase(attribute.key) %>, forKey: .<%- toCamelCase(attribute.key) %>)
|
|
97
|
+
<% } -%>
|
|
98
|
+
<% } -%>
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public func toMap() -> [String: Any] {
|
|
102
|
+
return [
|
|
103
|
+
<% for (const attribute of collection.attributes) { -%>
|
|
104
|
+
<% if (attribute.type === 'relationship') { -%>
|
|
105
|
+
"<%- attribute.key %>": <%- toCamelCase(attribute.key) %> as Any<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
|
|
106
|
+
<% } else if (attribute.array && attribute.type !== 'string' && attribute.type !== 'integer' && attribute.type !== 'float' && attribute.type !== 'boolean') { -%>
|
|
107
|
+
"<%- attribute.key %>": <%- toCamelCase(attribute.key) %>?.map { $0.toMap() } as Any<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
|
|
108
|
+
<% } else { -%>
|
|
109
|
+
"<%- attribute.key %>": <%- toCamelCase(attribute.key) %> as Any<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
|
|
110
|
+
<% } -%>
|
|
111
|
+
<% } -%>
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public static func from(map: [String: Any]) -> <%- toPascalCase(collection.name) %> {
|
|
116
|
+
return <%- toPascalCase(collection.name) %>(
|
|
117
|
+
<% for (const attribute of collection.attributes) { -%>
|
|
118
|
+
<% if (attribute.type === 'relationship') { -%>
|
|
119
|
+
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> <%- toPascalCase(attribute.relatedCollection) %><% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
|
|
120
|
+
<% } else if (attribute.array) { -%>
|
|
121
|
+
<% if (attribute.type === 'string') { -%>
|
|
122
|
+
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [String]<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
|
|
123
|
+
<% } else if (attribute.type === 'integer') { -%>
|
|
124
|
+
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [Int]<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
|
|
125
|
+
<% } else if (attribute.type === 'float') { -%>
|
|
126
|
+
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [Double]<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
|
|
127
|
+
<% } else if (attribute.type === 'boolean') { -%>
|
|
128
|
+
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [Bool]<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
|
|
129
|
+
<% } else { -%>
|
|
130
|
+
<%- toCamelCase(attribute.key) %>: (map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [[String: Any]])<% if (!attribute.required) { %>?<% } %>.map { <%- toPascalCase(attribute.type) %>.from(map: $0) }<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
|
|
131
|
+
<% } -%>
|
|
132
|
+
<% } else { -%>
|
|
133
|
+
<% if (attribute.type === 'string' || attribute.type === 'email' || attribute.type === 'datetime' || attribute.type === 'enum') { -%>
|
|
134
|
+
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> String<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
|
|
135
|
+
<% } else if (attribute.type === 'integer') { -%>
|
|
136
|
+
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> Int<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
|
|
137
|
+
<% } else if (attribute.type === 'float') { -%>
|
|
138
|
+
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> Double<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
|
|
139
|
+
<% } else if (attribute.type === 'boolean') { -%>
|
|
140
|
+
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> Bool<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
|
|
141
|
+
<% } else { -%>
|
|
142
|
+
<%- toCamelCase(attribute.key) %>: <%- toPascalCase(attribute.type) %>.from(map: map["<%- attribute.key %>"] as! [String: Any])<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
|
|
143
|
+
<% } -%>
|
|
144
|
+
<% } -%>
|
|
145
|
+
<% } -%>
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
}`;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
getFileName(collection) {
|
|
152
|
+
return LanguageMeta.toPascalCase(collection.name) + ".swift";
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
module.exports = { Swift };
|
|
@@ -0,0 +1,97 @@
|
|
|
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 TypeScript 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 = LanguageMeta.toPascalCase(attribute.key);
|
|
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 = `${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";
|
|
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
|
+
if (fs.existsSync(path.resolve(process.cwd(), 'deno.json'))) {
|
|
61
|
+
return "https://deno.land/x/appwrite/mod.ts";
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return "appwrite";
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
getTemplate() {
|
|
68
|
+
return `import { Models } from '${this._getAppwriteDependency()}';
|
|
69
|
+
|
|
70
|
+
<% for (const collection of collections) { -%>
|
|
71
|
+
<% for (const attribute of collection.attributes) { -%>
|
|
72
|
+
<% if (attribute.format === 'enum') { -%>
|
|
73
|
+
export enum <%- toPascalCase(attribute.key) %> {
|
|
74
|
+
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
|
|
75
|
+
<%- toUpperSnakeCase(element) %> = "<%- element %>",
|
|
76
|
+
<% } -%>
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
<% } -%>
|
|
80
|
+
<% } -%>
|
|
81
|
+
<% } -%>
|
|
82
|
+
<% for (const collection of collections) { -%>
|
|
83
|
+
export type <%- toPascalCase(collection.name) %> = Models.Document & {
|
|
84
|
+
<% for (const attribute of collection.attributes) { -%>
|
|
85
|
+
<%- toCamelCase(attribute.key) %>: <%- getType(attribute) %>;
|
|
86
|
+
<% } -%>
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
<% } %>`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
getFileName(_) {
|
|
93
|
+
return "appwrite.d.ts";
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
module.exports = { TypeScript };
|
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": "
|
|
5
|
+
"version": "8.0.1",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"bin": {
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"undici": "^5.28.2",
|
|
26
|
+
"ejs": "^3.1.9",
|
|
26
27
|
"chalk": "4.1.2",
|
|
27
28
|
"cli-progress": "^3.12.0",
|
|
28
29
|
"cli-table3": "^0.6.2",
|
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": "
|
|
3
|
+
"version": "8.0.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/
|
|
9
|
+
"url": "https://github.com/appwrite/sdk-for-cli/releases/download/8.0.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/
|
|
18
|
+
"url": "https://github.com/appwrite/sdk-for-cli/releases/download/8.0.1/appwrite-cli-win-arm64.exe",
|
|
19
19
|
"bin": [
|
|
20
20
|
[
|
|
21
21
|
"appwrite-cli-win-arm64.exe",
|