appwrite-utils-cli 0.0.268 → 0.0.270
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 +21 -1
- package/dist/main.js +18 -1
- package/dist/migrations/appwriteToX.d.ts +11 -0
- package/dist/migrations/appwriteToX.js +8 -1
- package/dist/migrations/backup.d.ts +48 -2
- package/dist/migrations/collections.js +29 -18
- package/dist/migrations/dataLoader.d.ts +106 -12
- package/dist/migrations/openapi.d.ts +4 -0
- package/dist/migrations/openapi.js +44 -0
- package/dist/migrations/relationships.d.ts +1 -0
- package/dist/migrations/schema.d.ts +358 -49
- package/dist/migrations/schema.js +67 -10
- package/dist/migrations/schemaStrings.js +47 -41
- package/dist/schemas/authUser.d.ts +3 -3
- package/dist/utilsController.d.ts +4 -1
- package/dist/utilsController.js +18 -6
- package/package.json +2 -1
- package/src/main.ts +18 -1
- package/src/migrations/appwriteToX.ts +12 -1
- package/src/migrations/collections.ts +40 -38
- package/src/migrations/openapi.ts +69 -0
- package/src/migrations/schema.ts +89 -10
- package/src/migrations/schemaStrings.ts +49 -42
- package/src/utilsController.ts +22 -6
@@ -0,0 +1,44 @@
|
|
1
|
+
import { OpenAPIRegistry, OpenApiGeneratorV3, OpenApiGeneratorV31, } from "@asteasolutions/zod-to-openapi";
|
2
|
+
import { attributeSchema, collectionSchema, } from "./schema.js";
|
3
|
+
import { z } from "zod";
|
4
|
+
import { writeFileSync } from "fs";
|
5
|
+
const registry = new OpenAPIRegistry();
|
6
|
+
export const generateOpenApi = async (config) => {
|
7
|
+
for (const collection of config.collections) {
|
8
|
+
// Transform and register each attribute schema
|
9
|
+
const attributeSchemas = collection.attributes.map((attribute) => {
|
10
|
+
return transformTypeToOpenApi(attributeSchema);
|
11
|
+
});
|
12
|
+
// Create and register the collection schema with descriptions
|
13
|
+
const updatedCollectionSchema = collectionSchema
|
14
|
+
.extend({
|
15
|
+
// @ts-ignore
|
16
|
+
attributes: z.array(z.union(attributeSchemas)),
|
17
|
+
})
|
18
|
+
.openapi(collection.description ?? "No description");
|
19
|
+
// Register the updated collection schema under the collection name
|
20
|
+
registry.register(collection.name, updatedCollectionSchema);
|
21
|
+
}
|
22
|
+
// Convert the registry to OpenAPI JSON
|
23
|
+
// @ts-ignore
|
24
|
+
const openApiSpec = registry.toOpenAPI();
|
25
|
+
// Output the OpenAPI spec to a file
|
26
|
+
writeFileSync("./appwrite/openapi/openapi.json", JSON.stringify(openApiSpec, null, 2));
|
27
|
+
};
|
28
|
+
export function transformTypeToOpenApi(schema) {
|
29
|
+
return schema.transform((data) => {
|
30
|
+
let finalData = data;
|
31
|
+
if (data._def.attributes) {
|
32
|
+
finalData._def.attributes = data._def.attributes.map((attribute) => {
|
33
|
+
if (attribute.description) {
|
34
|
+
return attribute.openapi(attribute.description);
|
35
|
+
}
|
36
|
+
return attribute;
|
37
|
+
});
|
38
|
+
}
|
39
|
+
if (schema.description) {
|
40
|
+
finalData.openapi(schema.description);
|
41
|
+
}
|
42
|
+
return finalData;
|
43
|
+
});
|
44
|
+
}
|
@@ -19,5 +19,6 @@ export declare const findCollectionsWithRelationships: (config: AppwriteConfig)
|
|
19
19
|
originalIdField: string;
|
20
20
|
targetField?: string | undefined;
|
21
21
|
} | undefined;
|
22
|
+
description?: string | Record<string, string> | null | undefined;
|
22
23
|
}[]>;
|
23
24
|
export declare function resolveAndUpdateRelationships(dbId: string, database: Databases, config: AppwriteConfig): Promise<void>;
|