appwrite-cli 13.0.1 → 13.1.0-rc.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/CHANGELOG.md +6 -0
- package/README.md +2 -2
- package/cli.ts +2 -0
- package/dist/bundle.cjs +17551 -16864
- package/dist/cli.js +2 -0
- package/dist/cli.js.map +1 -1
- package/dist/lib/commands/config-validations.d.ts +53 -0
- package/dist/lib/commands/config-validations.d.ts.map +1 -0
- package/dist/lib/commands/config-validations.js +130 -0
- package/dist/lib/commands/config-validations.js.map +1 -0
- package/dist/lib/commands/config.d.ts +241 -325
- package/dist/lib/commands/config.d.ts.map +1 -1
- package/dist/lib/commands/config.js +86 -107
- package/dist/lib/commands/config.js.map +1 -1
- package/dist/lib/commands/generate.d.ts +7 -0
- package/dist/lib/commands/generate.d.ts.map +1 -0
- package/dist/lib/commands/generate.js +92 -0
- package/dist/lib/commands/generate.js.map +1 -0
- package/dist/lib/commands/generators/base.d.ts +58 -0
- package/dist/lib/commands/generators/base.d.ts.map +1 -0
- package/dist/lib/commands/generators/base.js +27 -0
- package/dist/lib/commands/generators/base.js.map +1 -0
- package/dist/lib/commands/generators/index.d.ts +26 -0
- package/dist/lib/commands/generators/index.d.ts.map +1 -0
- package/dist/lib/commands/generators/index.js +55 -0
- package/dist/lib/commands/generators/index.js.map +1 -0
- package/dist/lib/commands/generators/language-detector.d.ts +42 -0
- package/dist/lib/commands/generators/language-detector.d.ts.map +1 -0
- package/dist/lib/commands/generators/language-detector.js +127 -0
- package/dist/lib/commands/generators/language-detector.js.map +1 -0
- package/dist/lib/commands/generators/typescript/databases.d.ts +36 -0
- package/dist/lib/commands/generators/typescript/databases.d.ts.map +1 -0
- package/dist/lib/commands/generators/typescript/databases.js +489 -0
- package/dist/lib/commands/generators/typescript/databases.js.map +1 -0
- package/dist/lib/commands/pull.js +3 -3
- package/dist/lib/commands/pull.js.map +1 -1
- package/dist/lib/commands/push.d.ts +6 -3
- package/dist/lib/commands/push.d.ts.map +1 -1
- package/dist/lib/commands/push.js +57 -37
- package/dist/lib/commands/push.js.map +1 -1
- package/dist/lib/commands/schema.d.ts +2 -2
- package/dist/lib/commands/schema.d.ts.map +1 -1
- package/dist/lib/commands/schema.js +2 -2
- package/dist/lib/commands/schema.js.map +1 -1
- package/dist/lib/commands/utils/attributes.d.ts +5 -0
- package/dist/lib/commands/utils/attributes.d.ts.map +1 -1
- package/dist/lib/commands/utils/attributes.js +20 -10
- package/dist/lib/commands/utils/attributes.js.map +1 -1
- package/dist/lib/commands/utils/pools.d.ts +0 -3
- package/dist/lib/commands/utils/pools.d.ts.map +1 -1
- package/dist/lib/commands/utils/pools.js +0 -34
- package/dist/lib/commands/utils/pools.js.map +1 -1
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +28 -131
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/constants.d.ts +1 -1
- package/dist/lib/constants.d.ts.map +1 -1
- package/dist/lib/constants.js +1 -1
- package/dist/lib/constants.js.map +1 -1
- package/dist/lib/utils.d.ts +3 -0
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +26 -0
- package/dist/lib/utils.js.map +1 -1
- package/dist/package.json +1 -1
- package/install.ps1 +2 -2
- package/install.sh +1 -1
- package/lib/commands/config-validations.ts +199 -0
- package/lib/commands/config.ts +94 -125
- package/lib/commands/generate.ts +142 -0
- package/lib/commands/generators/base.ts +91 -0
- package/lib/commands/generators/index.ts +87 -0
- package/lib/commands/generators/language-detector.ts +163 -0
- package/lib/commands/generators/typescript/databases.ts +590 -0
- package/lib/commands/pull.ts +4 -4
- package/lib/commands/push.ts +97 -58
- package/lib/commands/schema.ts +3 -3
- package/lib/commands/utils/attributes.ts +31 -11
- package/lib/commands/utils/pools.ts +0 -67
- package/lib/config.ts +43 -131
- package/lib/constants.ts +1 -1
- package/lib/utils.ts +32 -0
- package/package.json +1 -1
- package/scoop/appwrite.config.json +3 -3
- package/dist/lib/commands/db.d.ts +0 -34
- package/dist/lib/commands/db.d.ts.map +0 -1
- package/dist/lib/commands/db.js +0 -247
- package/dist/lib/commands/db.js.map +0 -1
- package/lib/commands/db.ts +0 -324
package/lib/utils.ts
CHANGED
|
@@ -184,3 +184,35 @@ export function filterBySchema<T extends z.ZodObject<z.ZodRawShape>>(
|
|
|
184
184
|
|
|
185
185
|
return result as z.infer<T>;
|
|
186
186
|
}
|
|
187
|
+
|
|
188
|
+
export function toPascalCase(str: string): string {
|
|
189
|
+
return str
|
|
190
|
+
.replace(/[-_\s]+(.)?/g, (_, char) => (char ? char.toUpperCase() : ""))
|
|
191
|
+
.replace(/^(.)/, (char) => char.toUpperCase());
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export function toUpperSnakeCase(str: string): string {
|
|
195
|
+
return str
|
|
196
|
+
.replace(/([a-z])([A-Z])/g, "$1_$2")
|
|
197
|
+
.replace(/[-\s]+/g, "_")
|
|
198
|
+
.toUpperCase();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function sanitizeEnumKey(key: string): string {
|
|
202
|
+
let sanitized = toUpperSnakeCase(key)
|
|
203
|
+
.replace(/[^A-Z0-9_]/gi, "_") // Replace non-alphanumeric with underscores
|
|
204
|
+
.replace(/_+/g, "_") // Collapse consecutive underscores
|
|
205
|
+
.replace(/^_+|_+$/g, ""); // Trim leading/trailing underscores
|
|
206
|
+
|
|
207
|
+
// Prefix with underscore if starts with a digit
|
|
208
|
+
if (/^[0-9]/.test(sanitized)) {
|
|
209
|
+
sanitized = "_" + sanitized;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Fallback if empty after sanitization
|
|
213
|
+
if (!sanitized) {
|
|
214
|
+
sanitized = "_VALUE";
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return sanitized;
|
|
218
|
+
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"type": "module",
|
|
4
4
|
"homepage": "https://appwrite.io/support",
|
|
5
5
|
"description": "Appwrite is an open-source self-hosted backend server that abstracts and simplifies complex and repetitive development tasks behind a very simple REST API",
|
|
6
|
-
"version": "13.0.1",
|
|
6
|
+
"version": "13.1.0-rc.1",
|
|
7
7
|
"license": "BSD-3-Clause",
|
|
8
8
|
"main": "dist/index.js",
|
|
9
9
|
"types": "dist/index.d.ts",
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://raw.githubusercontent.com/ScoopInstaller/Scoop/master/schema.json",
|
|
3
|
-
"version": "13.0.1",
|
|
3
|
+
"version": "13.1.0-rc.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/13.0.1/appwrite-cli-win-x64.exe",
|
|
9
|
+
"url": "https://github.com/appwrite/sdk-for-cli/releases/download/13.1.0-rc.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/13.0.1/appwrite-cli-win-arm64.exe",
|
|
18
|
+
"url": "https://github.com/appwrite/sdk-for-cli/releases/download/13.1.0-rc.1/appwrite-cli-win-arm64.exe",
|
|
19
19
|
"bin": [
|
|
20
20
|
[
|
|
21
21
|
"appwrite-cli-win-arm64.exe",
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { ConfigType } from "./config.js";
|
|
2
|
-
export interface GenerateOptions {
|
|
3
|
-
strict?: boolean;
|
|
4
|
-
}
|
|
5
|
-
export interface GenerateResult {
|
|
6
|
-
dbContent: string;
|
|
7
|
-
typesContent: string;
|
|
8
|
-
}
|
|
9
|
-
export declare class Db {
|
|
10
|
-
private getType;
|
|
11
|
-
private toPascalCase;
|
|
12
|
-
private toCamelCase;
|
|
13
|
-
private toUpperSnakeCase;
|
|
14
|
-
private generateCollectionType;
|
|
15
|
-
private generateEnums;
|
|
16
|
-
private generateTypesFile;
|
|
17
|
-
private getAppwriteDependency;
|
|
18
|
-
private generateDbFile;
|
|
19
|
-
/**
|
|
20
|
-
* Generates TypeScript code for Appwrite database collections and types based on the provided configuration.
|
|
21
|
-
*
|
|
22
|
-
* This method returns generated content as strings:
|
|
23
|
-
* 1. A types string containing TypeScript interfaces for each collection.
|
|
24
|
-
* 2. A database client string with helper methods for CRUD operations on each collection.
|
|
25
|
-
*
|
|
26
|
-
* @param config - The Appwrite project configuration, including collections and project details.
|
|
27
|
-
* @param options - Optional settings for code generation:
|
|
28
|
-
* - strict: Whether to use strict naming conventions for collections (default: false).
|
|
29
|
-
* @returns A Promise that resolves with an object containing dbContent and typesContent strings.
|
|
30
|
-
* @throws If the configuration is missing a projectId or contains no collections.
|
|
31
|
-
*/
|
|
32
|
-
generate(config: ConfigType, options?: GenerateOptions): Promise<GenerateResult>;
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=db.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../../lib/commands/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,MAAM,aAAa,CAAC;AAK1D,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,EAAE;IACb,OAAO,CAAC,OAAO;IA0Df,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,gBAAgB;IAOxB,OAAO,CAAC,sBAAsB;IAqB9B,OAAO,CAAC,aAAa;IA2BrB,OAAO,CAAC,iBAAiB;IA6BzB,OAAO,CAAC,qBAAqB;IAyB7B,OAAO,CAAC,cAAc;IAqFtB;;;;;;;;;;;;OAYG;IACU,QAAQ,CACnB,MAAM,EAAE,UAAU,EAClB,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,cAAc,CAAC;CA4B3B"}
|
package/dist/lib/commands/db.js
DELETED
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
import * as fs from "fs";
|
|
2
|
-
import * as path from "path";
|
|
3
|
-
export class Db {
|
|
4
|
-
getType(attribute, collections) {
|
|
5
|
-
let type = "";
|
|
6
|
-
switch (attribute.type) {
|
|
7
|
-
case "string":
|
|
8
|
-
case "datetime":
|
|
9
|
-
type = "string";
|
|
10
|
-
if (attribute.format === "enum") {
|
|
11
|
-
type = this.toPascalCase(attribute.key);
|
|
12
|
-
}
|
|
13
|
-
break;
|
|
14
|
-
case "integer":
|
|
15
|
-
type = "number";
|
|
16
|
-
break;
|
|
17
|
-
case "double":
|
|
18
|
-
type = "number";
|
|
19
|
-
break;
|
|
20
|
-
case "boolean":
|
|
21
|
-
type = "boolean";
|
|
22
|
-
break;
|
|
23
|
-
case "relationship":
|
|
24
|
-
const relatedCollection = collections.find((c) => c.$id === attribute.relatedCollection);
|
|
25
|
-
if (!relatedCollection) {
|
|
26
|
-
throw new Error(`Related collection with ID '${attribute.relatedCollection}' not found.`);
|
|
27
|
-
}
|
|
28
|
-
type = this.toPascalCase(relatedCollection.name);
|
|
29
|
-
if ((attribute.relationType === "oneToMany" &&
|
|
30
|
-
attribute.side === "parent") ||
|
|
31
|
-
(attribute.relationType === "manyToOne" &&
|
|
32
|
-
attribute.side === "child") ||
|
|
33
|
-
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 && attribute.default === null) {
|
|
44
|
-
type += " | null";
|
|
45
|
-
}
|
|
46
|
-
return type;
|
|
47
|
-
}
|
|
48
|
-
toPascalCase(str) {
|
|
49
|
-
return str
|
|
50
|
-
.replace(/[-_\s]+(.)?/g, (_, char) => (char ? char.toUpperCase() : ""))
|
|
51
|
-
.replace(/^(.)/, (char) => char.toUpperCase());
|
|
52
|
-
}
|
|
53
|
-
toCamelCase(str) {
|
|
54
|
-
return str
|
|
55
|
-
.replace(/[-_\s]+(.)?/g, (_, char) => (char ? char.toUpperCase() : ""))
|
|
56
|
-
.replace(/^(.)/, (char) => char.toLowerCase());
|
|
57
|
-
}
|
|
58
|
-
toUpperSnakeCase(str) {
|
|
59
|
-
return str
|
|
60
|
-
.replace(/([a-z])([A-Z])/g, "$1_$2")
|
|
61
|
-
.replace(/[-\s]+/g, "_")
|
|
62
|
-
.toUpperCase();
|
|
63
|
-
}
|
|
64
|
-
generateCollectionType(collection, collections, options = {}) {
|
|
65
|
-
if (!collection.attributes) {
|
|
66
|
-
return "";
|
|
67
|
-
}
|
|
68
|
-
const { strict = false } = options;
|
|
69
|
-
const typeName = this.toPascalCase(collection.name);
|
|
70
|
-
const attributes = collection.attributes
|
|
71
|
-
.map((attr) => {
|
|
72
|
-
const key = strict ? this.toCamelCase(attr.key) : attr.key;
|
|
73
|
-
return ` ${key}: ${this.getType(attr, collections)};`;
|
|
74
|
-
})
|
|
75
|
-
.join("\n");
|
|
76
|
-
return `export type ${typeName} = Models.Row & {\n${attributes}\n}`;
|
|
77
|
-
}
|
|
78
|
-
generateEnums(collections) {
|
|
79
|
-
const enumTypes = [];
|
|
80
|
-
for (const collection of collections) {
|
|
81
|
-
if (!collection.attributes)
|
|
82
|
-
continue;
|
|
83
|
-
for (const attribute of collection.attributes) {
|
|
84
|
-
if (attribute.format === "enum" && attribute.elements) {
|
|
85
|
-
const enumName = this.toPascalCase(attribute.key);
|
|
86
|
-
const enumValues = attribute.elements
|
|
87
|
-
.map((element, index) => {
|
|
88
|
-
const key = this.toUpperSnakeCase(element);
|
|
89
|
-
const isLast = index === attribute.elements.length - 1;
|
|
90
|
-
return ` ${key} = "${element}"${isLast ? "" : ","}`;
|
|
91
|
-
})
|
|
92
|
-
.join("\n");
|
|
93
|
-
enumTypes.push(`export enum ${enumName} {\n${enumValues}\n}`);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return enumTypes.join("\n\n");
|
|
98
|
-
}
|
|
99
|
-
generateTypesFile(config, options = {}) {
|
|
100
|
-
if (!config.collections || config.collections.length === 0) {
|
|
101
|
-
return "// No collections found in configuration\n";
|
|
102
|
-
}
|
|
103
|
-
const appwriteDep = this.getAppwriteDependency();
|
|
104
|
-
const enums = this.generateEnums(config.collections);
|
|
105
|
-
const types = config.collections
|
|
106
|
-
.map((collection) => this.generateCollectionType(collection, config.collections, options))
|
|
107
|
-
.join("\n\n");
|
|
108
|
-
const parts = [`import { type Models } from '${appwriteDep}';`, ""];
|
|
109
|
-
if (enums) {
|
|
110
|
-
parts.push(enums);
|
|
111
|
-
parts.push("");
|
|
112
|
-
}
|
|
113
|
-
parts.push(types);
|
|
114
|
-
parts.push("");
|
|
115
|
-
return parts.join("\n");
|
|
116
|
-
}
|
|
117
|
-
getAppwriteDependency() {
|
|
118
|
-
const cwd = process.cwd();
|
|
119
|
-
if (fs.existsSync(path.resolve(cwd, "package.json"))) {
|
|
120
|
-
try {
|
|
121
|
-
const packageJsonRaw = fs.readFileSync(path.resolve(cwd, "package.json"), "utf-8");
|
|
122
|
-
const packageJson = JSON.parse(packageJsonRaw);
|
|
123
|
-
return packageJson.dependencies?.["appwrite"]
|
|
124
|
-
? "appwrite"
|
|
125
|
-
: "node-appwrite";
|
|
126
|
-
}
|
|
127
|
-
catch {
|
|
128
|
-
// Fallback if package.json is invalid
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
if (fs.existsSync(path.resolve(cwd, "deno.json"))) {
|
|
132
|
-
return "https://deno.land/x/appwrite/mod.ts";
|
|
133
|
-
}
|
|
134
|
-
return "appwrite";
|
|
135
|
-
}
|
|
136
|
-
generateDbFile(config, options = {}) {
|
|
137
|
-
const { strict = false } = options;
|
|
138
|
-
const typesFileName = "appwrite.types.ts";
|
|
139
|
-
if (!config.collections || config.collections.length === 0) {
|
|
140
|
-
return "// No collections found in configuration\n";
|
|
141
|
-
}
|
|
142
|
-
const typeNames = config.collections.map((c) => this.toPascalCase(c.name));
|
|
143
|
-
const importPath = typesFileName
|
|
144
|
-
.replace(/\.d\.ts$/, "")
|
|
145
|
-
.replace(/\.ts$/, "");
|
|
146
|
-
const appwriteDep = this.getAppwriteDependency();
|
|
147
|
-
const collectionsCode = config.collections
|
|
148
|
-
.map((collection) => {
|
|
149
|
-
const collectionName = strict
|
|
150
|
-
? this.toCamelCase(collection.name)
|
|
151
|
-
: collection.name;
|
|
152
|
-
const typeName = this.toPascalCase(collection.name);
|
|
153
|
-
return ` ${collectionName}: {
|
|
154
|
-
create: (data: Omit<${typeName}, keyof Models.Row>, options?: { rowId?: string; permissions?: string[] }) =>
|
|
155
|
-
tablesDB.createRow<${typeName}>({
|
|
156
|
-
databaseId: process.env.APPWRITE_DB_ID!,
|
|
157
|
-
tableId: '${collection.$id}',
|
|
158
|
-
rowId: options?.rowId ?? ID.unique(),
|
|
159
|
-
data,
|
|
160
|
-
permissions: [
|
|
161
|
-
Permission.write(Role.user(data.createdBy)),
|
|
162
|
-
Permission.read(Role.user(data.createdBy)),
|
|
163
|
-
Permission.update(Role.user(data.createdBy)),
|
|
164
|
-
Permission.delete(Role.user(data.createdBy))
|
|
165
|
-
]
|
|
166
|
-
}),
|
|
167
|
-
get: (id: string) =>
|
|
168
|
-
tablesDB.getRow<${typeName}>({
|
|
169
|
-
databaseId: process.env.APPWRITE_DB_ID!,
|
|
170
|
-
tableId: '${collection.$id}',
|
|
171
|
-
rowId: id,
|
|
172
|
-
}),
|
|
173
|
-
update: (id: string, data: Partial<Omit<${typeName}, keyof Models.Row>>, options?: { permissions?: string[] }) =>
|
|
174
|
-
tablesDB.updateRow<${typeName}>({
|
|
175
|
-
databaseId: process.env.APPWRITE_DB_ID!,
|
|
176
|
-
tableId: '${collection.$id}',
|
|
177
|
-
rowId: id,
|
|
178
|
-
data,
|
|
179
|
-
...(options?.permissions ? { permissions: options.permissions } : {}),
|
|
180
|
-
}),
|
|
181
|
-
delete: (id: string) =>
|
|
182
|
-
tablesDB.deleteRow({
|
|
183
|
-
databaseId: process.env.APPWRITE_DB_ID!,
|
|
184
|
-
tableId: '${collection.$id}',
|
|
185
|
-
rowId: id,
|
|
186
|
-
}),
|
|
187
|
-
list: (queries?: string[]) =>
|
|
188
|
-
tablesDB.listRows<${typeName}>({
|
|
189
|
-
databaseId: process.env.APPWRITE_DB_ID!,
|
|
190
|
-
tableId: '${collection.$id}',
|
|
191
|
-
queries,
|
|
192
|
-
}),
|
|
193
|
-
}`;
|
|
194
|
-
})
|
|
195
|
-
.join(",\n");
|
|
196
|
-
return `import { Client, TablesDB, ID, type Models, Permission, Role } from '${appwriteDep}';
|
|
197
|
-
import type { ${typeNames.join(", ")} } from './${importPath}';
|
|
198
|
-
|
|
199
|
-
const client = new Client()
|
|
200
|
-
.setEndpoint(process.env.APPWRITE_ENDPOINT!)
|
|
201
|
-
.setProject(process.env.APPWRITE_PROJECT_ID!)
|
|
202
|
-
.setKey(process.env.APPWRITE_API_KEY!);
|
|
203
|
-
|
|
204
|
-
const tablesDB = new TablesDB(client);
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
export const db = {
|
|
208
|
-
${collectionsCode}
|
|
209
|
-
};
|
|
210
|
-
`;
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Generates TypeScript code for Appwrite database collections and types based on the provided configuration.
|
|
214
|
-
*
|
|
215
|
-
* This method returns generated content as strings:
|
|
216
|
-
* 1. A types string containing TypeScript interfaces for each collection.
|
|
217
|
-
* 2. A database client string with helper methods for CRUD operations on each collection.
|
|
218
|
-
*
|
|
219
|
-
* @param config - The Appwrite project configuration, including collections and project details.
|
|
220
|
-
* @param options - Optional settings for code generation:
|
|
221
|
-
* - strict: Whether to use strict naming conventions for collections (default: false).
|
|
222
|
-
* @returns A Promise that resolves with an object containing dbContent and typesContent strings.
|
|
223
|
-
* @throws If the configuration is missing a projectId or contains no collections.
|
|
224
|
-
*/
|
|
225
|
-
async generate(config, options = {}) {
|
|
226
|
-
const { strict = false } = options;
|
|
227
|
-
if (!config.projectId) {
|
|
228
|
-
throw new Error("Project ID is required in configuration");
|
|
229
|
-
}
|
|
230
|
-
if (!config.collections || config.collections.length === 0) {
|
|
231
|
-
console.log("No collections found in configuration. Skipping database generation.");
|
|
232
|
-
return {
|
|
233
|
-
dbContent: "// No collections found in configuration\n",
|
|
234
|
-
typesContent: "// No collections found in configuration\n",
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
// Generate types content
|
|
238
|
-
const typesContent = this.generateTypesFile(config, { strict });
|
|
239
|
-
// Generate database client content
|
|
240
|
-
const dbContent = this.generateDbFile(config, { strict });
|
|
241
|
-
return {
|
|
242
|
-
dbContent,
|
|
243
|
-
typesContent,
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
//# sourceMappingURL=db.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"db.js","sourceRoot":"","sources":["../../../lib/commands/db.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAY7B,MAAM,OAAO,EAAE;IACL,OAAO,CACb,SAA0C,EAC1C,WAAmD;QAEnD,IAAI,IAAI,GAAG,EAAE,CAAC;QAEd,QAAQ,SAAS,CAAC,IA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