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.
@@ -0,0 +1,4 @@
1
+ import { type AppwriteConfig } from "./schema.js";
2
+ import { z } from "zod";
3
+ export declare const generateOpenApi: (config: AppwriteConfig) => Promise<void>;
4
+ export declare function transformTypeToOpenApi<T extends z.ZodTypeAny>(schema: T): z.infer<T>;
@@ -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>;