@tspvivek/baasix-sdk 0.1.0-alpha.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.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +942 -0
  3. package/dist/client-CzF9B60b.d.ts +614 -0
  4. package/dist/client-aXK_gEyr.d.cts +614 -0
  5. package/dist/index.cjs +4159 -0
  6. package/dist/index.cjs.map +1 -0
  7. package/dist/index.d.cts +1498 -0
  8. package/dist/index.d.ts +1498 -0
  9. package/dist/index.js +4135 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/modules/auth.cjs +651 -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 +649 -0
  16. package/dist/modules/auth.js.map +1 -0
  17. package/dist/modules/files.cjs +266 -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 +264 -0
  22. package/dist/modules/files.js.map +1 -0
  23. package/dist/modules/items.cjs +654 -0
  24. package/dist/modules/items.cjs.map +1 -0
  25. package/dist/modules/items.d.cts +472 -0
  26. package/dist/modules/items.d.ts +472 -0
  27. package/dist/modules/items.js +651 -0
  28. package/dist/modules/items.js.map +1 -0
  29. package/dist/modules/schemas.cjs +269 -0
  30. package/dist/modules/schemas.cjs.map +1 -0
  31. package/dist/modules/schemas.d.cts +239 -0
  32. package/dist/modules/schemas.d.ts +239 -0
  33. package/dist/modules/schemas.js +267 -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 +107 -0
@@ -0,0 +1,239 @@
1
+ import { H as HttpClient, e as PaginatedResponse, l as SchemaInfo, m as SchemaDefinition, n as RelationshipDefinition, I as IndexDefinition } from '../client-CzF9B60b.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
+ */
47
+ find(): Promise<PaginatedResponse<SchemaInfo>>;
48
+ /**
49
+ * Get schema for a specific collection
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * const schema = await baasix.schemas.findOne('products');
54
+ * console.log(schema.fields);
55
+ * ```
56
+ */
57
+ findOne(collection: string): Promise<SchemaInfo>;
58
+ /**
59
+ * Create a new collection/schema
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * await baasix.schemas.create({
64
+ * collectionName: 'orders',
65
+ * schema: {
66
+ * name: 'Order',
67
+ * timestamps: true,
68
+ * paranoid: true,
69
+ * fields: {
70
+ * id: {
71
+ * type: 'UUID',
72
+ * primaryKey: true,
73
+ * defaultValue: { type: 'UUIDV4' }
74
+ * },
75
+ * orderNumber: {
76
+ * type: 'String',
77
+ * allowNull: false,
78
+ * unique: true
79
+ * },
80
+ * total: {
81
+ * type: 'Decimal',
82
+ * values: { precision: 10, scale: 2 },
83
+ * allowNull: false,
84
+ * defaultValue: 0
85
+ * },
86
+ * status: {
87
+ * type: 'String',
88
+ * allowNull: false,
89
+ * defaultValue: 'pending'
90
+ * },
91
+ * items: {
92
+ * type: 'JSONB',
93
+ * allowNull: true,
94
+ * defaultValue: []
95
+ * }
96
+ * }
97
+ * }
98
+ * });
99
+ * ```
100
+ */
101
+ create(data: {
102
+ collectionName: string;
103
+ schema: SchemaDefinition;
104
+ }): Promise<SchemaInfo>;
105
+ /**
106
+ * Update an existing schema
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * await baasix.schemas.update('products', {
111
+ * schema: {
112
+ * name: 'Product',
113
+ * timestamps: true,
114
+ * fields: {
115
+ * // Updated fields
116
+ * description: { type: 'Text', allowNull: true }
117
+ * }
118
+ * }
119
+ * });
120
+ * ```
121
+ */
122
+ update(collection: string, data: {
123
+ schema: Partial<SchemaDefinition>;
124
+ }): Promise<SchemaInfo>;
125
+ /**
126
+ * Delete a schema (drops the table)
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * await baasix.schemas.delete('old_collection');
131
+ * ```
132
+ */
133
+ delete(collection: string): Promise<void>;
134
+ /**
135
+ * Create a relationship between collections
136
+ *
137
+ * @example
138
+ * ```typescript
139
+ * // Many-to-One (BelongsTo)
140
+ * await baasix.schemas.createRelationship('posts', {
141
+ * type: 'M2O',
142
+ * target: 'baasix_User',
143
+ * name: 'author',
144
+ * alias: 'posts'
145
+ * });
146
+ *
147
+ * // Many-to-Many
148
+ * await baasix.schemas.createRelationship('posts', {
149
+ * type: 'M2M',
150
+ * target: 'tags',
151
+ * name: 'tags',
152
+ * alias: 'posts'
153
+ * });
154
+ * ```
155
+ */
156
+ createRelationship(collection: string, relationship: RelationshipDefinition): Promise<void>;
157
+ /**
158
+ * Delete a relationship
159
+ *
160
+ * @example
161
+ * ```typescript
162
+ * await baasix.schemas.deleteRelationship('posts', 'author');
163
+ * ```
164
+ */
165
+ deleteRelationship(collection: string, relationshipName: string): Promise<void>;
166
+ /**
167
+ * Create an index on a collection
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * // Unique index
172
+ * await baasix.schemas.createIndex('users', {
173
+ * name: 'idx_users_email',
174
+ * fields: ['email'],
175
+ * unique: true
176
+ * });
177
+ *
178
+ * // Composite index
179
+ * await baasix.schemas.createIndex('orders', {
180
+ * name: 'idx_orders_status_created',
181
+ * fields: ['status', 'createdAt']
182
+ * });
183
+ * ```
184
+ */
185
+ createIndex(collection: string, index: IndexDefinition): Promise<void>;
186
+ /**
187
+ * Delete an index
188
+ *
189
+ * @example
190
+ * ```typescript
191
+ * await baasix.schemas.deleteIndex('users', 'idx_users_email');
192
+ * ```
193
+ */
194
+ deleteIndex(collection: string, indexName: string): Promise<void>;
195
+ /**
196
+ * Add a field to an existing schema
197
+ *
198
+ * @example
199
+ * ```typescript
200
+ * await baasix.schemas.addField('products', 'rating', {
201
+ * type: 'Decimal',
202
+ * values: { precision: 3, scale: 2 },
203
+ * allowNull: true,
204
+ * defaultValue: 0
205
+ * });
206
+ * ```
207
+ */
208
+ addField(collection: string, fieldName: string, fieldDefinition: SchemaDefinition["fields"][string]): Promise<SchemaInfo>;
209
+ /**
210
+ * Remove a field from a schema
211
+ *
212
+ * @example
213
+ * ```typescript
214
+ * await baasix.schemas.removeField('products', 'deprecated_field');
215
+ * ```
216
+ */
217
+ removeField(collection: string, fieldName: string): Promise<SchemaInfo>;
218
+ /**
219
+ * Export all schemas as JSON
220
+ *
221
+ * @example
222
+ * ```typescript
223
+ * const schemas = await baasix.schemas.export();
224
+ * // Save to file for backup
225
+ * ```
226
+ */
227
+ export(): Promise<SchemaInfo[]>;
228
+ /**
229
+ * Import schemas from JSON
230
+ *
231
+ * @example
232
+ * ```typescript
233
+ * await baasix.schemas.import(savedSchemas);
234
+ * ```
235
+ */
236
+ import(schemas: SchemaInfo[]): Promise<void>;
237
+ }
238
+
239
+ export { IndexDefinition, RelationshipDefinition, SchemaDefinition, SchemaInfo, SchemasModule, type SchemasModuleConfig };
@@ -0,0 +1,267 @@
1
+ // src/modules/schemas.ts
2
+ var SchemasModule = class {
3
+ client;
4
+ constructor(config) {
5
+ this.client = config.client;
6
+ }
7
+ /**
8
+ * List all schemas
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const { data } = await baasix.schemas.find();
13
+ * console.log(data.map(s => s.collectionName));
14
+ * ```
15
+ */
16
+ async find() {
17
+ return this.client.get("/schemas");
18
+ }
19
+ /**
20
+ * Get schema for a specific collection
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * const schema = await baasix.schemas.findOne('products');
25
+ * console.log(schema.fields);
26
+ * ```
27
+ */
28
+ async findOne(collection) {
29
+ const response = await this.client.get(
30
+ `/schemas/${collection}`
31
+ );
32
+ return response.data;
33
+ }
34
+ /**
35
+ * Create a new collection/schema
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * await baasix.schemas.create({
40
+ * collectionName: 'orders',
41
+ * schema: {
42
+ * name: 'Order',
43
+ * timestamps: true,
44
+ * paranoid: true,
45
+ * fields: {
46
+ * id: {
47
+ * type: 'UUID',
48
+ * primaryKey: true,
49
+ * defaultValue: { type: 'UUIDV4' }
50
+ * },
51
+ * orderNumber: {
52
+ * type: 'String',
53
+ * allowNull: false,
54
+ * unique: true
55
+ * },
56
+ * total: {
57
+ * type: 'Decimal',
58
+ * values: { precision: 10, scale: 2 },
59
+ * allowNull: false,
60
+ * defaultValue: 0
61
+ * },
62
+ * status: {
63
+ * type: 'String',
64
+ * allowNull: false,
65
+ * defaultValue: 'pending'
66
+ * },
67
+ * items: {
68
+ * type: 'JSONB',
69
+ * allowNull: true,
70
+ * defaultValue: []
71
+ * }
72
+ * }
73
+ * }
74
+ * });
75
+ * ```
76
+ */
77
+ async create(data) {
78
+ const response = await this.client.post(
79
+ "/schemas",
80
+ data
81
+ );
82
+ return response.data;
83
+ }
84
+ /**
85
+ * Update an existing schema
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * await baasix.schemas.update('products', {
90
+ * schema: {
91
+ * name: 'Product',
92
+ * timestamps: true,
93
+ * fields: {
94
+ * // Updated fields
95
+ * description: { type: 'Text', allowNull: true }
96
+ * }
97
+ * }
98
+ * });
99
+ * ```
100
+ */
101
+ async update(collection, data) {
102
+ const response = await this.client.patch(
103
+ `/schemas/${collection}`,
104
+ data
105
+ );
106
+ return response.data;
107
+ }
108
+ /**
109
+ * Delete a schema (drops the table)
110
+ *
111
+ * @example
112
+ * ```typescript
113
+ * await baasix.schemas.delete('old_collection');
114
+ * ```
115
+ */
116
+ async delete(collection) {
117
+ await this.client.delete(`/schemas/${collection}`);
118
+ }
119
+ /**
120
+ * Create a relationship between collections
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * // Many-to-One (BelongsTo)
125
+ * await baasix.schemas.createRelationship('posts', {
126
+ * type: 'M2O',
127
+ * target: 'baasix_User',
128
+ * name: 'author',
129
+ * alias: 'posts'
130
+ * });
131
+ *
132
+ * // Many-to-Many
133
+ * await baasix.schemas.createRelationship('posts', {
134
+ * type: 'M2M',
135
+ * target: 'tags',
136
+ * name: 'tags',
137
+ * alias: 'posts'
138
+ * });
139
+ * ```
140
+ */
141
+ async createRelationship(collection, relationship) {
142
+ await this.client.post(
143
+ `/schemas/${collection}/relationships`,
144
+ relationship
145
+ );
146
+ }
147
+ /**
148
+ * Delete a relationship
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * await baasix.schemas.deleteRelationship('posts', 'author');
153
+ * ```
154
+ */
155
+ async deleteRelationship(collection, relationshipName) {
156
+ await this.client.delete(
157
+ `/schemas/${collection}/relationships/${relationshipName}`
158
+ );
159
+ }
160
+ /**
161
+ * Create an index on a collection
162
+ *
163
+ * @example
164
+ * ```typescript
165
+ * // Unique index
166
+ * await baasix.schemas.createIndex('users', {
167
+ * name: 'idx_users_email',
168
+ * fields: ['email'],
169
+ * unique: true
170
+ * });
171
+ *
172
+ * // Composite index
173
+ * await baasix.schemas.createIndex('orders', {
174
+ * name: 'idx_orders_status_created',
175
+ * fields: ['status', 'createdAt']
176
+ * });
177
+ * ```
178
+ */
179
+ async createIndex(collection, index) {
180
+ await this.client.post(`/schemas/${collection}/indexes`, index);
181
+ }
182
+ /**
183
+ * Delete an index
184
+ *
185
+ * @example
186
+ * ```typescript
187
+ * await baasix.schemas.deleteIndex('users', 'idx_users_email');
188
+ * ```
189
+ */
190
+ async deleteIndex(collection, indexName) {
191
+ await this.client.delete(`/schemas/${collection}/indexes/${indexName}`);
192
+ }
193
+ /**
194
+ * Add a field to an existing schema
195
+ *
196
+ * @example
197
+ * ```typescript
198
+ * await baasix.schemas.addField('products', 'rating', {
199
+ * type: 'Decimal',
200
+ * values: { precision: 3, scale: 2 },
201
+ * allowNull: true,
202
+ * defaultValue: 0
203
+ * });
204
+ * ```
205
+ */
206
+ async addField(collection, fieldName, fieldDefinition) {
207
+ const currentSchema = await this.findOne(collection);
208
+ const updatedFields = {
209
+ ...currentSchema.schema.fields,
210
+ [fieldName]: fieldDefinition
211
+ };
212
+ return this.update(collection, {
213
+ schema: {
214
+ ...currentSchema.schema,
215
+ fields: updatedFields
216
+ }
217
+ });
218
+ }
219
+ /**
220
+ * Remove a field from a schema
221
+ *
222
+ * @example
223
+ * ```typescript
224
+ * await baasix.schemas.removeField('products', 'deprecated_field');
225
+ * ```
226
+ */
227
+ async removeField(collection, fieldName) {
228
+ const currentSchema = await this.findOne(collection);
229
+ const { [fieldName]: _, ...remainingFields } = currentSchema.schema.fields;
230
+ return this.update(collection, {
231
+ schema: {
232
+ ...currentSchema.schema,
233
+ fields: remainingFields
234
+ }
235
+ });
236
+ }
237
+ /**
238
+ * Export all schemas as JSON
239
+ *
240
+ * @example
241
+ * ```typescript
242
+ * const schemas = await baasix.schemas.export();
243
+ * // Save to file for backup
244
+ * ```
245
+ */
246
+ async export() {
247
+ const response = await this.client.get(
248
+ "/schemas/export"
249
+ );
250
+ return response.data;
251
+ }
252
+ /**
253
+ * Import schemas from JSON
254
+ *
255
+ * @example
256
+ * ```typescript
257
+ * await baasix.schemas.import(savedSchemas);
258
+ * ```
259
+ */
260
+ async import(schemas) {
261
+ await this.client.post("/schemas/import", { schemas });
262
+ }
263
+ };
264
+
265
+ export { SchemasModule };
266
+ //# sourceMappingURL=schemas.js.map
267
+ //# sourceMappingURL=schemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/modules/schemas.ts"],"names":[],"mappings":";AAyCO,IAAM,gBAAN,MAAoB;AAAA,EACjB,MAAA;AAAA,EAER,YAAY,MAAA,EAA6B;AACvC,IAAA,IAAA,CAAK,SAAS,MAAA,CAAO,MAAA;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAM,IAAA,GAA+C;AACnD,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,GAAA,CAAmC,UAAU,CAAA;AAAA,EAClE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAM,QAAQ,UAAA,EAAyC;AACrD,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,MAAA,CAAO,GAAA;AAAA,MACjC,YAAY,UAAU,CAAA;AAAA,KACxB;AACA,IAAA,OAAO,QAAA,CAAS,IAAA;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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D,IAAA,MAAM,EAAE,CAAC,SAAS,GAAG,GAAG,GAAG,eAAA,EAAgB,GAAI,aAAA,CAAc,MAAA,CAAO,MAAA;AAEpE,IAAA,OAAO,IAAA,CAAK,OAAO,UAAA,EAAY;AAAA,MAC7B,MAAA,EAAQ;AAAA,QACN,GAAG,aAAA,CAAc,MAAA;AAAA,QACjB,MAAA,EAAQ;AAAA;AACV,KACD,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAM,MAAA,GAAgC;AACpC,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,MAAA,CAAO,GAAA;AAAA,MACjC;AAAA,KACF;AACA,IAAA,OAAO,QAAA,CAAS,IAAA;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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 { HttpClient } from \"../client\";\nimport type {\n IndexDefinition,\n PaginatedResponse,\n RelationshipDefinition,\n SchemaDefinition,\n SchemaInfo,\n} from \"../types\";\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 */\n async find(): Promise<PaginatedResponse<SchemaInfo>> {\n return this.client.get<PaginatedResponse<SchemaInfo>>(\"/schemas\");\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 * 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"]}
@@ -0,0 +1,162 @@
1
+ 'use strict';
2
+
3
+ // src/storage/types.ts
4
+ var STORAGE_KEYS = {
5
+ ACCESS_TOKEN: "baasix_access_token",
6
+ REFRESH_TOKEN: "baasix_refresh_token",
7
+ TOKEN_EXPIRY: "baasix_token_expiry",
8
+ USER: "baasix_user",
9
+ TENANT: "baasix_tenant"
10
+ };
11
+
12
+ // src/storage/localStorage.ts
13
+ var LocalStorageAdapter = class {
14
+ prefix;
15
+ constructor(prefix = "baasix_") {
16
+ this.prefix = prefix;
17
+ }
18
+ getKey(key) {
19
+ if (key.startsWith(this.prefix)) {
20
+ return key;
21
+ }
22
+ return `${this.prefix}${key}`;
23
+ }
24
+ get(key) {
25
+ if (typeof window === "undefined" || !window.localStorage) {
26
+ return null;
27
+ }
28
+ try {
29
+ return localStorage.getItem(this.getKey(key));
30
+ } catch {
31
+ console.warn(`[Baasix SDK] Failed to get item from localStorage: ${key}`);
32
+ return null;
33
+ }
34
+ }
35
+ set(key, value) {
36
+ if (typeof window === "undefined" || !window.localStorage) {
37
+ return;
38
+ }
39
+ try {
40
+ localStorage.setItem(this.getKey(key), value);
41
+ } catch {
42
+ console.warn(`[Baasix SDK] Failed to set item in localStorage: ${key}`);
43
+ }
44
+ }
45
+ remove(key) {
46
+ if (typeof window === "undefined" || !window.localStorage) {
47
+ return;
48
+ }
49
+ try {
50
+ localStorage.removeItem(this.getKey(key));
51
+ } catch {
52
+ console.warn(`[Baasix SDK] Failed to remove item from localStorage: ${key}`);
53
+ }
54
+ }
55
+ clear() {
56
+ if (typeof window === "undefined" || !window.localStorage) {
57
+ return;
58
+ }
59
+ try {
60
+ const keysToRemove = [];
61
+ for (let i = 0; i < localStorage.length; i++) {
62
+ const key = localStorage.key(i);
63
+ if (key?.startsWith(this.prefix)) {
64
+ keysToRemove.push(key);
65
+ }
66
+ }
67
+ keysToRemove.forEach((key) => localStorage.removeItem(key));
68
+ } catch {
69
+ console.warn("[Baasix SDK] Failed to clear localStorage");
70
+ }
71
+ }
72
+ };
73
+
74
+ // src/storage/memoryStorage.ts
75
+ var MemoryStorageAdapter = class {
76
+ store;
77
+ constructor() {
78
+ this.store = /* @__PURE__ */ new Map();
79
+ }
80
+ get(key) {
81
+ return this.store.get(key) ?? null;
82
+ }
83
+ set(key, value) {
84
+ this.store.set(key, value);
85
+ }
86
+ remove(key) {
87
+ this.store.delete(key);
88
+ }
89
+ clear() {
90
+ this.store.clear();
91
+ }
92
+ /**
93
+ * Get all stored keys (useful for debugging)
94
+ */
95
+ keys() {
96
+ return Array.from(this.store.keys());
97
+ }
98
+ /**
99
+ * Get the number of stored items
100
+ */
101
+ size() {
102
+ return this.store.size;
103
+ }
104
+ };
105
+
106
+ // src/storage/asyncStorage.ts
107
+ var AsyncStorageAdapter = class {
108
+ asyncStorage;
109
+ prefix;
110
+ constructor(asyncStorage, prefix = "baasix_") {
111
+ this.asyncStorage = asyncStorage;
112
+ this.prefix = prefix;
113
+ }
114
+ getKey(key) {
115
+ if (key.startsWith(this.prefix)) {
116
+ return key;
117
+ }
118
+ return `${this.prefix}${key}`;
119
+ }
120
+ async get(key) {
121
+ try {
122
+ return await this.asyncStorage.getItem(this.getKey(key));
123
+ } catch {
124
+ console.warn(`[Baasix SDK] Failed to get item from AsyncStorage: ${key}`);
125
+ return null;
126
+ }
127
+ }
128
+ async set(key, value) {
129
+ try {
130
+ await this.asyncStorage.setItem(this.getKey(key), value);
131
+ } catch {
132
+ console.warn(`[Baasix SDK] Failed to set item in AsyncStorage: ${key}`);
133
+ }
134
+ }
135
+ async remove(key) {
136
+ try {
137
+ await this.asyncStorage.removeItem(this.getKey(key));
138
+ } catch {
139
+ console.warn(`[Baasix SDK] Failed to remove item from AsyncStorage: ${key}`);
140
+ }
141
+ }
142
+ async clear() {
143
+ try {
144
+ if (this.asyncStorage.getAllKeys && this.asyncStorage.multiRemove) {
145
+ const allKeys = await this.asyncStorage.getAllKeys();
146
+ const sdkKeys = allKeys.filter((key) => key.startsWith(this.prefix));
147
+ if (sdkKeys.length > 0) {
148
+ await this.asyncStorage.multiRemove(sdkKeys);
149
+ }
150
+ }
151
+ } catch {
152
+ console.warn("[Baasix SDK] Failed to clear AsyncStorage");
153
+ }
154
+ }
155
+ };
156
+
157
+ exports.AsyncStorageAdapter = AsyncStorageAdapter;
158
+ exports.LocalStorageAdapter = LocalStorageAdapter;
159
+ exports.MemoryStorageAdapter = MemoryStorageAdapter;
160
+ exports.STORAGE_KEYS = STORAGE_KEYS;
161
+ //# sourceMappingURL=index.cjs.map
162
+ //# sourceMappingURL=index.cjs.map