@baasix/sdk 0.1.0

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.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1197 -0
  3. package/dist/client-DeXa-R9w.d.ts +680 -0
  4. package/dist/client-VT7NckyI.d.cts +680 -0
  5. package/dist/index.cjs +4567 -0
  6. package/dist/index.cjs.map +1 -0
  7. package/dist/index.d.cts +1788 -0
  8. package/dist/index.d.ts +1788 -0
  9. package/dist/index.js +4543 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/modules/auth.cjs +650 -0
  12. package/dist/modules/auth.cjs.map +1 -0
  13. package/dist/modules/auth.d.cts +384 -0
  14. package/dist/modules/auth.d.ts +384 -0
  15. package/dist/modules/auth.js +648 -0
  16. package/dist/modules/auth.js.map +1 -0
  17. package/dist/modules/files.cjs +269 -0
  18. package/dist/modules/files.cjs.map +1 -0
  19. package/dist/modules/files.d.cts +187 -0
  20. package/dist/modules/files.d.ts +187 -0
  21. package/dist/modules/files.js +267 -0
  22. package/dist/modules/files.js.map +1 -0
  23. package/dist/modules/items.cjs +640 -0
  24. package/dist/modules/items.cjs.map +1 -0
  25. package/dist/modules/items.d.cts +465 -0
  26. package/dist/modules/items.d.ts +465 -0
  27. package/dist/modules/items.js +637 -0
  28. package/dist/modules/items.js.map +1 -0
  29. package/dist/modules/schemas.cjs +322 -0
  30. package/dist/modules/schemas.cjs.map +1 -0
  31. package/dist/modules/schemas.d.cts +260 -0
  32. package/dist/modules/schemas.d.ts +260 -0
  33. package/dist/modules/schemas.js +320 -0
  34. package/dist/modules/schemas.js.map +1 -0
  35. package/dist/storage/index.cjs +162 -0
  36. package/dist/storage/index.cjs.map +1 -0
  37. package/dist/storage/index.d.cts +96 -0
  38. package/dist/storage/index.d.ts +96 -0
  39. package/dist/storage/index.js +157 -0
  40. package/dist/storage/index.js.map +1 -0
  41. package/dist/types-BdjsGANq.d.cts +40 -0
  42. package/dist/types-BdjsGANq.d.ts +40 -0
  43. package/package.json +108 -0
@@ -0,0 +1,260 @@
1
+ import { H as HttpClient, S as Sort, e as PaginatedResponse, l as SchemaInfo, m as SchemaDefinition, n as RelationshipDefinition, I as IndexDefinition } from '../client-DeXa-R9w.js';
2
+ import '../types-BdjsGANq.js';
3
+
4
+ interface SchemasModuleConfig {
5
+ client: HttpClient;
6
+ }
7
+ /**
8
+ * Schemas module for managing database schemas, relationships, and indexes.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * // Create a new collection
13
+ * await baasix.schemas.create({
14
+ * collectionName: 'products',
15
+ * schema: {
16
+ * name: 'Product',
17
+ * timestamps: true,
18
+ * fields: {
19
+ * id: { type: 'UUID', primaryKey: true, defaultValue: { type: 'UUIDV4' } },
20
+ * name: { type: 'String', allowNull: false },
21
+ * price: { type: 'Decimal', values: { precision: 10, scale: 2 } }
22
+ * }
23
+ * }
24
+ * });
25
+ *
26
+ * // Add a relationship
27
+ * await baasix.schemas.createRelationship('products', {
28
+ * type: 'M2O',
29
+ * target: 'categories',
30
+ * name: 'category',
31
+ * alias: 'products'
32
+ * });
33
+ * ```
34
+ */
35
+ declare class SchemasModule {
36
+ private client;
37
+ constructor(config: SchemasModuleConfig);
38
+ /**
39
+ * List all schemas
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * const { data } = await baasix.schemas.find();
44
+ * console.log(data.map(s => s.collectionName));
45
+ *
46
+ * // With pagination
47
+ * const { data } = await baasix.schemas.find({ page: 1, limit: 50 });
48
+ * ```
49
+ */
50
+ find(params?: {
51
+ page?: number;
52
+ limit?: number;
53
+ sort?: Sort;
54
+ search?: string;
55
+ filter?: Record<string, unknown>;
56
+ }): Promise<PaginatedResponse<SchemaInfo>>;
57
+ /**
58
+ * Get schema for a specific collection
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const schema = await baasix.schemas.findOne('products');
63
+ * console.log(schema.fields);
64
+ * ```
65
+ */
66
+ findOne(collection: string): Promise<SchemaInfo>;
67
+ /**
68
+ * Create a new collection/schema
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * await baasix.schemas.create({
73
+ * collectionName: 'orders',
74
+ * schema: {
75
+ * name: 'Order',
76
+ * timestamps: true,
77
+ * paranoid: true,
78
+ * fields: {
79
+ * id: {
80
+ * type: 'UUID',
81
+ * primaryKey: true,
82
+ * defaultValue: { type: 'UUIDV4' }
83
+ * },
84
+ * orderNumber: {
85
+ * type: 'String',
86
+ * allowNull: false,
87
+ * unique: true
88
+ * },
89
+ * total: {
90
+ * type: 'Decimal',
91
+ * values: { precision: 10, scale: 2 },
92
+ * allowNull: false,
93
+ * defaultValue: 0
94
+ * },
95
+ * status: {
96
+ * type: 'String',
97
+ * allowNull: false,
98
+ * defaultValue: 'pending'
99
+ * },
100
+ * items: {
101
+ * type: 'JSONB',
102
+ * allowNull: true,
103
+ * defaultValue: []
104
+ * }
105
+ * }
106
+ * }
107
+ * });
108
+ * ```
109
+ */
110
+ create(data: {
111
+ collectionName: string;
112
+ schema: SchemaDefinition;
113
+ }): Promise<SchemaInfo>;
114
+ /**
115
+ * Update an existing schema
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * await baasix.schemas.update('products', {
120
+ * schema: {
121
+ * name: 'Product',
122
+ * timestamps: true,
123
+ * fields: {
124
+ * // Updated fields
125
+ * description: { type: 'Text', allowNull: true }
126
+ * }
127
+ * }
128
+ * });
129
+ * ```
130
+ */
131
+ update(collection: string, data: {
132
+ schema: Partial<SchemaDefinition>;
133
+ }): Promise<SchemaInfo>;
134
+ /**
135
+ * Delete a schema (drops the table)
136
+ *
137
+ * @example
138
+ * ```typescript
139
+ * await baasix.schemas.delete('old_collection');
140
+ * ```
141
+ */
142
+ delete(collection: string): Promise<void>;
143
+ /**
144
+ * Create a relationship between collections
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * // Many-to-One (BelongsTo)
149
+ * await baasix.schemas.createRelationship('posts', {
150
+ * type: 'M2O',
151
+ * target: 'baasix_User',
152
+ * name: 'author',
153
+ * alias: 'posts'
154
+ * });
155
+ *
156
+ * // Many-to-Many
157
+ * await baasix.schemas.createRelationship('posts', {
158
+ * type: 'M2M',
159
+ * target: 'tags',
160
+ * name: 'tags',
161
+ * alias: 'posts'
162
+ * });
163
+ * ```
164
+ */
165
+ createRelationship(collection: string, relationship: RelationshipDefinition): Promise<void>;
166
+ /**
167
+ * Delete a relationship
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * await baasix.schemas.deleteRelationship('posts', 'author');
172
+ * ```
173
+ */
174
+ deleteRelationship(collection: string, relationshipName: string): Promise<void>;
175
+ /**
176
+ * Update a relationship
177
+ *
178
+ * @example
179
+ * ```typescript
180
+ * await baasix.schemas.updateRelationship('posts', 'author', {
181
+ * alias: 'authoredPosts',
182
+ * onDelete: 'CASCADE'
183
+ * });
184
+ * ```
185
+ */
186
+ updateRelationship(collection: string, relationshipName: string, data: Partial<RelationshipDefinition>): Promise<void>;
187
+ /**
188
+ * Create an index on a collection
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * // Unique index
193
+ * await baasix.schemas.createIndex('users', {
194
+ * name: 'idx_users_email',
195
+ * fields: ['email'],
196
+ * unique: true
197
+ * });
198
+ *
199
+ * // Composite index
200
+ * await baasix.schemas.createIndex('orders', {
201
+ * name: 'idx_orders_status_created',
202
+ * fields: ['status', 'createdAt']
203
+ * });
204
+ * ```
205
+ */
206
+ createIndex(collection: string, index: IndexDefinition): Promise<void>;
207
+ /**
208
+ * Delete an index
209
+ *
210
+ * @example
211
+ * ```typescript
212
+ * await baasix.schemas.deleteIndex('users', 'idx_users_email');
213
+ * ```
214
+ */
215
+ deleteIndex(collection: string, indexName: string): Promise<void>;
216
+ /**
217
+ * Add a field to an existing schema
218
+ *
219
+ * @example
220
+ * ```typescript
221
+ * await baasix.schemas.addField('products', 'rating', {
222
+ * type: 'Decimal',
223
+ * values: { precision: 3, scale: 2 },
224
+ * allowNull: true,
225
+ * defaultValue: 0
226
+ * });
227
+ * ```
228
+ */
229
+ addField(collection: string, fieldName: string, fieldDefinition: SchemaDefinition["fields"][string]): Promise<SchemaInfo>;
230
+ /**
231
+ * Remove a field from a schema
232
+ *
233
+ * @example
234
+ * ```typescript
235
+ * await baasix.schemas.removeField('products', 'deprecated_field');
236
+ * ```
237
+ */
238
+ removeField(collection: string, fieldName: string): Promise<SchemaInfo>;
239
+ /**
240
+ * Export all schemas as JSON
241
+ *
242
+ * @example
243
+ * ```typescript
244
+ * const schemas = await baasix.schemas.export();
245
+ * // Save to file for backup
246
+ * ```
247
+ */
248
+ export(): Promise<SchemaInfo[]>;
249
+ /**
250
+ * Import schemas from JSON
251
+ *
252
+ * @example
253
+ * ```typescript
254
+ * await baasix.schemas.import(savedSchemas);
255
+ * ```
256
+ */
257
+ import(schemas: SchemaInfo[]): Promise<void>;
258
+ }
259
+
260
+ export { IndexDefinition, RelationshipDefinition, SchemaDefinition, SchemaInfo, SchemasModule, type SchemasModuleConfig };
@@ -0,0 +1,320 @@
1
+ // src/utils/sort.ts
2
+ function normalizeSort(sort) {
3
+ if (!sort) return void 0;
4
+ if (typeof sort === "string") {
5
+ return sort;
6
+ }
7
+ if (Array.isArray(sort)) {
8
+ if (sort.length === 0) return void 0;
9
+ if (typeof sort[0] === "object" && "column" in sort[0]) {
10
+ return sort.map((s) => `${s.column}:${s.order.toLowerCase()}`).join(",");
11
+ }
12
+ return sort.map((s) => {
13
+ if (s.startsWith("-")) {
14
+ return `${s.substring(1)}:desc`;
15
+ }
16
+ if (s.includes(":")) {
17
+ return s;
18
+ }
19
+ return `${s}:asc`;
20
+ }).join(",");
21
+ }
22
+ if (typeof sort === "object") {
23
+ const entries = Object.entries(sort);
24
+ if (entries.length === 0) return void 0;
25
+ return entries.map(([field, direction]) => `${field}:${direction.toLowerCase()}`).join(",");
26
+ }
27
+ return void 0;
28
+ }
29
+
30
+ // src/modules/schemas.ts
31
+ var SchemasModule = class {
32
+ client;
33
+ constructor(config) {
34
+ this.client = config.client;
35
+ }
36
+ /**
37
+ * List all schemas
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const { data } = await baasix.schemas.find();
42
+ * console.log(data.map(s => s.collectionName));
43
+ *
44
+ * // With pagination
45
+ * const { data } = await baasix.schemas.find({ page: 1, limit: 50 });
46
+ * ```
47
+ */
48
+ async find(params) {
49
+ const normalizedParams = params ? {
50
+ ...params,
51
+ sort: normalizeSort(params.sort)
52
+ } : void 0;
53
+ return this.client.get("/schemas", { params: normalizedParams });
54
+ }
55
+ /**
56
+ * Get schema for a specific collection
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * const schema = await baasix.schemas.findOne('products');
61
+ * console.log(schema.fields);
62
+ * ```
63
+ */
64
+ async findOne(collection) {
65
+ const response = await this.client.get(
66
+ `/schemas/${collection}`
67
+ );
68
+ return response.data;
69
+ }
70
+ /**
71
+ * Create a new collection/schema
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * await baasix.schemas.create({
76
+ * collectionName: 'orders',
77
+ * schema: {
78
+ * name: 'Order',
79
+ * timestamps: true,
80
+ * paranoid: true,
81
+ * fields: {
82
+ * id: {
83
+ * type: 'UUID',
84
+ * primaryKey: true,
85
+ * defaultValue: { type: 'UUIDV4' }
86
+ * },
87
+ * orderNumber: {
88
+ * type: 'String',
89
+ * allowNull: false,
90
+ * unique: true
91
+ * },
92
+ * total: {
93
+ * type: 'Decimal',
94
+ * values: { precision: 10, scale: 2 },
95
+ * allowNull: false,
96
+ * defaultValue: 0
97
+ * },
98
+ * status: {
99
+ * type: 'String',
100
+ * allowNull: false,
101
+ * defaultValue: 'pending'
102
+ * },
103
+ * items: {
104
+ * type: 'JSONB',
105
+ * allowNull: true,
106
+ * defaultValue: []
107
+ * }
108
+ * }
109
+ * }
110
+ * });
111
+ * ```
112
+ */
113
+ async create(data) {
114
+ const response = await this.client.post(
115
+ "/schemas",
116
+ data
117
+ );
118
+ return response.data;
119
+ }
120
+ /**
121
+ * Update an existing schema
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * await baasix.schemas.update('products', {
126
+ * schema: {
127
+ * name: 'Product',
128
+ * timestamps: true,
129
+ * fields: {
130
+ * // Updated fields
131
+ * description: { type: 'Text', allowNull: true }
132
+ * }
133
+ * }
134
+ * });
135
+ * ```
136
+ */
137
+ async update(collection, data) {
138
+ const response = await this.client.patch(
139
+ `/schemas/${collection}`,
140
+ data
141
+ );
142
+ return response.data;
143
+ }
144
+ /**
145
+ * Delete a schema (drops the table)
146
+ *
147
+ * @example
148
+ * ```typescript
149
+ * await baasix.schemas.delete('old_collection');
150
+ * ```
151
+ */
152
+ async delete(collection) {
153
+ await this.client.delete(`/schemas/${collection}`);
154
+ }
155
+ /**
156
+ * Create a relationship between collections
157
+ *
158
+ * @example
159
+ * ```typescript
160
+ * // Many-to-One (BelongsTo)
161
+ * await baasix.schemas.createRelationship('posts', {
162
+ * type: 'M2O',
163
+ * target: 'baasix_User',
164
+ * name: 'author',
165
+ * alias: 'posts'
166
+ * });
167
+ *
168
+ * // Many-to-Many
169
+ * await baasix.schemas.createRelationship('posts', {
170
+ * type: 'M2M',
171
+ * target: 'tags',
172
+ * name: 'tags',
173
+ * alias: 'posts'
174
+ * });
175
+ * ```
176
+ */
177
+ async createRelationship(collection, relationship) {
178
+ await this.client.post(
179
+ `/schemas/${collection}/relationships`,
180
+ relationship
181
+ );
182
+ }
183
+ /**
184
+ * Delete a relationship
185
+ *
186
+ * @example
187
+ * ```typescript
188
+ * await baasix.schemas.deleteRelationship('posts', 'author');
189
+ * ```
190
+ */
191
+ async deleteRelationship(collection, relationshipName) {
192
+ await this.client.delete(
193
+ `/schemas/${collection}/relationships/${relationshipName}`
194
+ );
195
+ }
196
+ /**
197
+ * Update a relationship
198
+ *
199
+ * @example
200
+ * ```typescript
201
+ * await baasix.schemas.updateRelationship('posts', 'author', {
202
+ * alias: 'authoredPosts',
203
+ * onDelete: 'CASCADE'
204
+ * });
205
+ * ```
206
+ */
207
+ async updateRelationship(collection, relationshipName, data) {
208
+ await this.client.patch(
209
+ `/schemas/${collection}/relationships/${relationshipName}`,
210
+ data
211
+ );
212
+ }
213
+ /**
214
+ * Create an index on a collection
215
+ *
216
+ * @example
217
+ * ```typescript
218
+ * // Unique index
219
+ * await baasix.schemas.createIndex('users', {
220
+ * name: 'idx_users_email',
221
+ * fields: ['email'],
222
+ * unique: true
223
+ * });
224
+ *
225
+ * // Composite index
226
+ * await baasix.schemas.createIndex('orders', {
227
+ * name: 'idx_orders_status_created',
228
+ * fields: ['status', 'createdAt']
229
+ * });
230
+ * ```
231
+ */
232
+ async createIndex(collection, index) {
233
+ await this.client.post(`/schemas/${collection}/indexes`, index);
234
+ }
235
+ /**
236
+ * Delete an index
237
+ *
238
+ * @example
239
+ * ```typescript
240
+ * await baasix.schemas.deleteIndex('users', 'idx_users_email');
241
+ * ```
242
+ */
243
+ async deleteIndex(collection, indexName) {
244
+ await this.client.delete(`/schemas/${collection}/indexes/${indexName}`);
245
+ }
246
+ /**
247
+ * Add a field to an existing schema
248
+ *
249
+ * @example
250
+ * ```typescript
251
+ * await baasix.schemas.addField('products', 'rating', {
252
+ * type: 'Decimal',
253
+ * values: { precision: 3, scale: 2 },
254
+ * allowNull: true,
255
+ * defaultValue: 0
256
+ * });
257
+ * ```
258
+ */
259
+ async addField(collection, fieldName, fieldDefinition) {
260
+ const currentSchema = await this.findOne(collection);
261
+ const updatedFields = {
262
+ ...currentSchema.schema.fields,
263
+ [fieldName]: fieldDefinition
264
+ };
265
+ return this.update(collection, {
266
+ schema: {
267
+ ...currentSchema.schema,
268
+ fields: updatedFields
269
+ }
270
+ });
271
+ }
272
+ /**
273
+ * Remove a field from a schema
274
+ *
275
+ * @example
276
+ * ```typescript
277
+ * await baasix.schemas.removeField('products', 'deprecated_field');
278
+ * ```
279
+ */
280
+ async removeField(collection, fieldName) {
281
+ const currentSchema = await this.findOne(collection);
282
+ const { [fieldName]: _, ...remainingFields } = currentSchema.schema.fields;
283
+ return this.update(collection, {
284
+ schema: {
285
+ ...currentSchema.schema,
286
+ fields: remainingFields
287
+ }
288
+ });
289
+ }
290
+ /**
291
+ * Export all schemas as JSON
292
+ *
293
+ * @example
294
+ * ```typescript
295
+ * const schemas = await baasix.schemas.export();
296
+ * // Save to file for backup
297
+ * ```
298
+ */
299
+ async export() {
300
+ const response = await this.client.get(
301
+ "/schemas/export"
302
+ );
303
+ return response.data;
304
+ }
305
+ /**
306
+ * Import schemas from JSON
307
+ *
308
+ * @example
309
+ * ```typescript
310
+ * await baasix.schemas.import(savedSchemas);
311
+ * ```
312
+ */
313
+ async import(schemas) {
314
+ await this.client.post("/schemas/import", { schemas });
315
+ }
316
+ };
317
+
318
+ export { SchemasModule };
319
+ //# sourceMappingURL=schemas.js.map
320
+ //# sourceMappingURL=schemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/sort.ts","../../src/modules/schemas.ts"],"names":[],"mappings":";AAkBO,SAAS,cAAc,IAAA,EAA4C;AACxE,EAAA,IAAI,CAAC,MAAM,OAAO,MAAA;AAGlB,EAAA,IAAI,OAAO,SAAS,QAAA,EAAU;AAC5B,IAAA,OAAO,IAAA;AAAA,EACT;AAGA,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,IAAI,CAAA,EAAG;AACvB,IAAA,IAAI,IAAA,CAAK,MAAA,KAAW,CAAA,EAAG,OAAO,MAAA;AAG9B,IAAA,IAAI,OAAO,KAAK,CAAC,CAAA,KAAM,YAAY,QAAA,IAAY,IAAA,CAAK,CAAC,CAAA,EAAG;AACtD,MAAA,OAAQ,IAAA,CACL,GAAA,CAAI,CAAC,CAAA,KAAM,GAAG,CAAA,CAAE,MAAM,CAAA,CAAA,EAAI,CAAA,CAAE,MAAM,WAAA,EAAa,CAAA,CAAE,CAAA,CACjD,KAAK,GAAG,CAAA;AAAA,IACb;AAGA,IAAA,OAAQ,IAAA,CACL,GAAA,CAAI,CAAC,CAAA,KAAM;AACV,MAAA,IAAI,CAAA,CAAE,UAAA,CAAW,GAAG,CAAA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;AAAA;AAAA,EAUA,MAAM,OAAO,OAAA,EAAsC;AACjD,IAAA,MAAM,KAAK,MAAA,CAAO,IAAA,CAAK,iBAAA,EAAmB,EAAE,SAAS,CAAA;AAAA,EACvD;AACF","file":"schemas.js","sourcesContent":["import type { Sort, SortDirection } from \"../types\";\n\n/**\n * Normalize sort parameter to string format \"field:direction,field2:direction2\"\n * This is the format expected by the API for query string parameters.\n * \n * @example\n * ```typescript\n * normalizeSort({ name: 'asc', createdAt: 'desc' })\n * // Returns: \"name:asc,createdAt:desc\"\n * \n * normalizeSort(['-createdAt', 'name'])\n * // Returns: \"createdAt:desc,name:asc\"\n * \n * normalizeSort('name:asc')\n * // Returns: \"name:asc\"\n * ```\n */\nexport function normalizeSort(sort: Sort | undefined): string | undefined {\n if (!sort) return undefined;\n\n // Already a string\n if (typeof sort === \"string\") {\n return sort;\n }\n\n // Array of strings like ['-createdAt', 'name']\n if (Array.isArray(sort)) {\n if (sort.length === 0) return undefined;\n \n // Check if it's array of objects { column, order }\n if (typeof sort[0] === \"object\" && \"column\" in sort[0]) {\n return (sort as { column: string; order: SortDirection }[])\n .map((s) => `${s.column}:${s.order.toLowerCase()}`)\n .join(\",\");\n }\n \n // Array of strings like ['-name', 'createdAt']\n return (sort as string[])\n .map((s) => {\n if (s.startsWith(\"-\")) {\n return `${s.substring(1)}:desc`;\n }\n if (s.includes(\":\")) {\n return s;\n }\n return `${s}:asc`;\n })\n .join(\",\");\n }\n\n // Object like { name: 'asc', createdAt: 'desc' }\n if (typeof sort === \"object\") {\n const entries = Object.entries(sort as Record<string, SortDirection>);\n if (entries.length === 0) return undefined;\n \n return entries\n .map(([field, direction]) => `${field}:${direction.toLowerCase()}`)\n .join(\",\");\n }\n\n return undefined;\n}\n","import type { HttpClient } from \"../client\";\nimport type {\n IndexDefinition,\n PaginatedResponse,\n RelationshipDefinition,\n SchemaDefinition,\n SchemaInfo,\n Sort,\n} from \"../types\";\nimport { normalizeSort } from \"../utils/sort\";\n\nexport interface SchemasModuleConfig {\n client: HttpClient;\n}\n\n/**\n * Schemas module for managing database schemas, relationships, and indexes.\n *\n * @example\n * ```typescript\n * // Create a new collection\n * await baasix.schemas.create({\n * collectionName: 'products',\n * schema: {\n * name: 'Product',\n * timestamps: true,\n * fields: {\n * id: { type: 'UUID', primaryKey: true, defaultValue: { type: 'UUIDV4' } },\n * name: { type: 'String', allowNull: false },\n * price: { type: 'Decimal', values: { precision: 10, scale: 2 } }\n * }\n * }\n * });\n *\n * // Add a relationship\n * await baasix.schemas.createRelationship('products', {\n * type: 'M2O',\n * target: 'categories',\n * name: 'category',\n * alias: 'products'\n * });\n * ```\n */\nexport class SchemasModule {\n private client: HttpClient;\n\n constructor(config: SchemasModuleConfig) {\n this.client = config.client;\n }\n\n /**\n * List all schemas\n *\n * @example\n * ```typescript\n * const { data } = await baasix.schemas.find();\n * console.log(data.map(s => s.collectionName));\n * \n * // With pagination\n * const { data } = await baasix.schemas.find({ page: 1, limit: 50 });\n * ```\n */\n async find(params?: {\n page?: number;\n limit?: number;\n sort?: Sort;\n search?: string;\n filter?: Record<string, unknown>;\n }): Promise<PaginatedResponse<SchemaInfo>> {\n const normalizedParams = params ? {\n ...params,\n sort: normalizeSort(params.sort),\n } : undefined;\n return this.client.get<PaginatedResponse<SchemaInfo>>(\"/schemas\", { params: normalizedParams });\n }\n\n /**\n * Get schema for a specific collection\n *\n * @example\n * ```typescript\n * const schema = await baasix.schemas.findOne('products');\n * console.log(schema.fields);\n * ```\n */\n async findOne(collection: string): Promise<SchemaInfo> {\n const response = await this.client.get<{ data: SchemaInfo }>(\n `/schemas/${collection}`\n );\n return response.data;\n }\n\n /**\n * Create a new collection/schema\n *\n * @example\n * ```typescript\n * await baasix.schemas.create({\n * collectionName: 'orders',\n * schema: {\n * name: 'Order',\n * timestamps: true,\n * paranoid: true,\n * fields: {\n * id: {\n * type: 'UUID',\n * primaryKey: true,\n * defaultValue: { type: 'UUIDV4' }\n * },\n * orderNumber: {\n * type: 'String',\n * allowNull: false,\n * unique: true\n * },\n * total: {\n * type: 'Decimal',\n * values: { precision: 10, scale: 2 },\n * allowNull: false,\n * defaultValue: 0\n * },\n * status: {\n * type: 'String',\n * allowNull: false,\n * defaultValue: 'pending'\n * },\n * items: {\n * type: 'JSONB',\n * allowNull: true,\n * defaultValue: []\n * }\n * }\n * }\n * });\n * ```\n */\n async create(data: {\n collectionName: string;\n schema: SchemaDefinition;\n }): Promise<SchemaInfo> {\n const response = await this.client.post<{ data: SchemaInfo }>(\n \"/schemas\",\n data\n );\n return response.data;\n }\n\n /**\n * Update an existing schema\n *\n * @example\n * ```typescript\n * await baasix.schemas.update('products', {\n * schema: {\n * name: 'Product',\n * timestamps: true,\n * fields: {\n * // Updated fields\n * description: { type: 'Text', allowNull: true }\n * }\n * }\n * });\n * ```\n */\n async update(\n collection: string,\n data: { schema: Partial<SchemaDefinition> }\n ): Promise<SchemaInfo> {\n const response = await this.client.patch<{ data: SchemaInfo }>(\n `/schemas/${collection}`,\n data\n );\n return response.data;\n }\n\n /**\n * Delete a schema (drops the table)\n *\n * @example\n * ```typescript\n * await baasix.schemas.delete('old_collection');\n * ```\n */\n async delete(collection: string): Promise<void> {\n await this.client.delete(`/schemas/${collection}`);\n }\n\n /**\n * Create a relationship between collections\n *\n * @example\n * ```typescript\n * // Many-to-One (BelongsTo)\n * await baasix.schemas.createRelationship('posts', {\n * type: 'M2O',\n * target: 'baasix_User',\n * name: 'author',\n * alias: 'posts'\n * });\n *\n * // Many-to-Many\n * await baasix.schemas.createRelationship('posts', {\n * type: 'M2M',\n * target: 'tags',\n * name: 'tags',\n * alias: 'posts'\n * });\n * ```\n */\n async createRelationship(\n collection: string,\n relationship: RelationshipDefinition\n ): Promise<void> {\n await this.client.post(\n `/schemas/${collection}/relationships`,\n relationship\n );\n }\n\n /**\n * Delete a relationship\n *\n * @example\n * ```typescript\n * await baasix.schemas.deleteRelationship('posts', 'author');\n * ```\n */\n async deleteRelationship(\n collection: string,\n relationshipName: string\n ): Promise<void> {\n await this.client.delete(\n `/schemas/${collection}/relationships/${relationshipName}`\n );\n }\n\n /**\n * Update a relationship\n *\n * @example\n * ```typescript\n * await baasix.schemas.updateRelationship('posts', 'author', {\n * alias: 'authoredPosts',\n * onDelete: 'CASCADE'\n * });\n * ```\n */\n async updateRelationship(\n collection: string,\n relationshipName: string,\n data: Partial<RelationshipDefinition>\n ): Promise<void> {\n await this.client.patch(\n `/schemas/${collection}/relationships/${relationshipName}`,\n data\n );\n }\n\n /**\n * Create an index on a collection\n *\n * @example\n * ```typescript\n * // Unique index\n * await baasix.schemas.createIndex('users', {\n * name: 'idx_users_email',\n * fields: ['email'],\n * unique: true\n * });\n *\n * // Composite index\n * await baasix.schemas.createIndex('orders', {\n * name: 'idx_orders_status_created',\n * fields: ['status', 'createdAt']\n * });\n * ```\n */\n async createIndex(\n collection: string,\n index: IndexDefinition\n ): Promise<void> {\n await this.client.post(`/schemas/${collection}/indexes`, index);\n }\n\n /**\n * Delete an index\n *\n * @example\n * ```typescript\n * await baasix.schemas.deleteIndex('users', 'idx_users_email');\n * ```\n */\n async deleteIndex(collection: string, indexName: string): Promise<void> {\n await this.client.delete(`/schemas/${collection}/indexes/${indexName}`);\n }\n\n /**\n * Add a field to an existing schema\n *\n * @example\n * ```typescript\n * await baasix.schemas.addField('products', 'rating', {\n * type: 'Decimal',\n * values: { precision: 3, scale: 2 },\n * allowNull: true,\n * defaultValue: 0\n * });\n * ```\n */\n async addField(\n collection: string,\n fieldName: string,\n fieldDefinition: SchemaDefinition[\"fields\"][string]\n ): Promise<SchemaInfo> {\n const currentSchema = await this.findOne(collection);\n const updatedFields = {\n ...currentSchema.schema.fields,\n [fieldName]: fieldDefinition,\n };\n\n return this.update(collection, {\n schema: {\n ...currentSchema.schema,\n fields: updatedFields,\n },\n });\n }\n\n /**\n * Remove a field from a schema\n *\n * @example\n * ```typescript\n * await baasix.schemas.removeField('products', 'deprecated_field');\n * ```\n */\n async removeField(\n collection: string,\n fieldName: string\n ): Promise<SchemaInfo> {\n const currentSchema = await this.findOne(collection);\n const { [fieldName]: _, ...remainingFields } = currentSchema.schema.fields;\n\n return this.update(collection, {\n schema: {\n ...currentSchema.schema,\n fields: remainingFields,\n },\n });\n }\n\n /**\n * Export all schemas as JSON\n *\n * @example\n * ```typescript\n * const schemas = await baasix.schemas.export();\n * // Save to file for backup\n * ```\n */\n async export(): Promise<SchemaInfo[]> {\n const response = await this.client.get<{ data: SchemaInfo[] }>(\n \"/schemas/export\"\n );\n return response.data;\n }\n\n /**\n * Import schemas from JSON\n *\n * @example\n * ```typescript\n * await baasix.schemas.import(savedSchemas);\n * ```\n */\n async import(schemas: SchemaInfo[]): Promise<void> {\n await this.client.post(\"/schemas/import\", { schemas });\n }\n}\n\n// Re-export types\nexport type {\n IndexDefinition,\n RelationshipDefinition,\n SchemaDefinition,\n SchemaInfo,\n};\n"]}