katanakit-js 6.2.0 → 6.6.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 (116) hide show
  1. package/README.md +11 -3
  2. package/dist/adapters/better-auth/better-auth.service.d.ts +83 -0
  3. package/dist/adapters/better-auth/better-auth.service.d.ts.map +1 -0
  4. package/dist/adapters/better-auth/better-auth.service.js +110 -0
  5. package/dist/adapters/better-auth/better-auth.service.js.map +1 -0
  6. package/dist/adapters/better-auth/client.d.ts +51 -0
  7. package/dist/adapters/better-auth/client.d.ts.map +1 -0
  8. package/dist/adapters/better-auth/client.js +67 -0
  9. package/dist/adapters/better-auth/client.js.map +1 -0
  10. package/dist/adapters/better-auth/index.d.ts +3 -0
  11. package/dist/adapters/better-auth/index.d.ts.map +1 -0
  12. package/dist/adapters/better-auth/index.js +3 -0
  13. package/dist/adapters/better-auth/index.js.map +1 -0
  14. package/dist/adapters/express/server.d.ts +133 -1
  15. package/dist/adapters/express/server.d.ts.map +1 -1
  16. package/dist/adapters/express/server.js +199 -97
  17. package/dist/adapters/express/server.js.map +1 -1
  18. package/dist/adapters/index.d.ts +2 -0
  19. package/dist/adapters/index.d.ts.map +1 -1
  20. package/dist/adapters/index.js +2 -0
  21. package/dist/adapters/index.js.map +1 -1
  22. package/dist/adapters/insforge/insforge.service.d.ts +139 -4
  23. package/dist/adapters/insforge/insforge.service.d.ts.map +1 -1
  24. package/dist/adapters/insforge/insforge.service.js +383 -213
  25. package/dist/adapters/insforge/insforge.service.js.map +1 -1
  26. package/dist/adapters/notion/notion.service.d.ts +130 -144
  27. package/dist/adapters/notion/notion.service.d.ts.map +1 -1
  28. package/dist/adapters/notion/notion.service.js +330 -341
  29. package/dist/adapters/notion/notion.service.js.map +1 -1
  30. package/dist/adapters/photoswipe/index.d.ts +2 -0
  31. package/dist/adapters/photoswipe/index.d.ts.map +1 -0
  32. package/dist/adapters/photoswipe/index.js +2 -0
  33. package/dist/adapters/photoswipe/index.js.map +1 -0
  34. package/dist/adapters/photoswipe/photoswipe.service.d.ts +99 -0
  35. package/dist/adapters/photoswipe/photoswipe.service.d.ts.map +1 -0
  36. package/dist/adapters/photoswipe/photoswipe.service.js +150 -0
  37. package/dist/adapters/photoswipe/photoswipe.service.js.map +1 -0
  38. package/dist/adapters/telegram/telegram.service.d.ts +82 -13
  39. package/dist/adapters/telegram/telegram.service.d.ts.map +1 -1
  40. package/dist/adapters/telegram/telegram.service.js +133 -55
  41. package/dist/adapters/telegram/telegram.service.js.map +1 -1
  42. package/dist/adapters/wordpress/wordpress.service.d.ts +181 -110
  43. package/dist/adapters/wordpress/wordpress.service.d.ts.map +1 -1
  44. package/dist/adapters/wordpress/wordpress.service.js +556 -465
  45. package/dist/adapters/wordpress/wordpress.service.js.map +1 -1
  46. package/dist/config/seo.service.d.ts +1 -1
  47. package/dist/config/seo.service.d.ts.map +1 -1
  48. package/dist/config/seo.service.js +1 -1
  49. package/dist/config/seo.service.js.map +1 -1
  50. package/dist/core/services/access.service.d.ts +167 -4
  51. package/dist/core/services/access.service.d.ts.map +1 -1
  52. package/dist/core/services/access.service.js +241 -31
  53. package/dist/core/services/access.service.js.map +1 -1
  54. package/dist/core/services/agent.service.d.ts +182 -27
  55. package/dist/core/services/agent.service.d.ts.map +1 -1
  56. package/dist/core/services/agent.service.js +296 -164
  57. package/dist/core/services/agent.service.js.map +1 -1
  58. package/dist/core/services/assistant.service.d.ts +96 -5
  59. package/dist/core/services/assistant.service.d.ts.map +1 -1
  60. package/dist/core/services/assistant.service.js +171 -66
  61. package/dist/core/services/assistant.service.js.map +1 -1
  62. package/dist/core/services/dates.service.d.ts +183 -11
  63. package/dist/core/services/dates.service.d.ts.map +1 -1
  64. package/dist/core/services/dates.service.js +256 -57
  65. package/dist/core/services/dates.service.js.map +1 -1
  66. package/dist/core/services/http.service.d.ts +172 -133
  67. package/dist/core/services/http.service.d.ts.map +1 -1
  68. package/dist/core/services/http.service.js +367 -310
  69. package/dist/core/services/http.service.js.map +1 -1
  70. package/dist/core/services/logger.service.d.ts +96 -34
  71. package/dist/core/services/logger.service.d.ts.map +1 -1
  72. package/dist/core/services/logger.service.js +128 -41
  73. package/dist/core/services/logger.service.js.map +1 -1
  74. package/dist/core/services/query.service.d.ts +101 -0
  75. package/dist/core/services/query.service.d.ts.map +1 -1
  76. package/dist/core/services/query.service.js +131 -14
  77. package/dist/core/services/query.service.js.map +1 -1
  78. package/dist/core/services/utils.service.d.ts +286 -131
  79. package/dist/core/services/utils.service.d.ts.map +1 -1
  80. package/dist/core/services/utils.service.js +417 -227
  81. package/dist/core/services/utils.service.js.map +1 -1
  82. package/dist/core/services/validation.service.d.ts +48 -3
  83. package/dist/core/services/validation.service.d.ts.map +1 -1
  84. package/dist/core/services/validation.service.js +75 -23
  85. package/dist/core/services/validation.service.js.map +1 -1
  86. package/dist/infrastructure/decorators/cache.decorator.d.ts +53 -0
  87. package/dist/infrastructure/decorators/cache.decorator.d.ts.map +1 -0
  88. package/dist/infrastructure/decorators/cache.decorator.js +47 -0
  89. package/dist/infrastructure/decorators/cache.decorator.js.map +1 -0
  90. package/dist/infrastructure/decorators/index.d.ts +4 -0
  91. package/dist/infrastructure/decorators/index.d.ts.map +1 -0
  92. package/dist/infrastructure/decorators/index.js +4 -0
  93. package/dist/infrastructure/decorators/index.js.map +1 -0
  94. package/dist/infrastructure/decorators/logger.decorator.d.ts +38 -0
  95. package/dist/infrastructure/decorators/logger.decorator.d.ts.map +1 -0
  96. package/dist/infrastructure/decorators/logger.decorator.js +66 -0
  97. package/dist/infrastructure/decorators/logger.decorator.js.map +1 -0
  98. package/dist/infrastructure/decorators/retry.decorator.d.ts +37 -0
  99. package/dist/infrastructure/decorators/retry.decorator.d.ts.map +1 -0
  100. package/dist/infrastructure/decorators/retry.decorator.js +54 -0
  101. package/dist/infrastructure/decorators/retry.decorator.js.map +1 -0
  102. package/dist/infrastructure/index.d.ts +1 -0
  103. package/dist/infrastructure/index.d.ts.map +1 -1
  104. package/dist/infrastructure/index.js +1 -0
  105. package/dist/infrastructure/index.js.map +1 -1
  106. package/dist/styles.css +2 -0
  107. package/package.json +49 -14
  108. package/scss/_flags.scss +179 -0
  109. package/scss/_functions.scss +168 -0
  110. package/scss/_mixins.scss +658 -0
  111. package/scss/_reset.scss +275 -0
  112. package/scss/_utilities.scss +449 -0
  113. package/scss/_variables.scss +539 -0
  114. package/scss/components/_index.scss +50 -0
  115. package/scss/demo.scss +12 -0
  116. package/scss/main.scss +56 -0
@@ -2,8 +2,6 @@ import { createAdminClient, createClient } from "@insforge/sdk";
2
2
  import { useSplitConfig } from "../../core/services/utils.service.js";
3
3
  import { useValidate } from "../../core/services/validation.service.js";
4
4
  import { IfBucketSchema, IfConfigSchema, IfInsertRowsSchema, IfInvokeOptionsSchema, IfListOptionsSchema, IfRpcCallSchema, IfStorageRefSchema, IfTableNameSchema, IfTableQuerySchema, IfUpdatePatchSchema, IfWriteQuerySchema, } from "../../schemas/insforge.schema.js";
5
- /** Module-level client. InsForge is the database fallback, not the default. */
6
- let client = null;
7
5
  /**
8
6
  * Maps an SDK error (InsForgeError or unknown throw) to the shared `ApiError`.
9
7
  *
@@ -105,7 +103,370 @@ function scopedDatabase(database, schema) {
105
103
  return database;
106
104
  }
107
105
  /**
108
- * Registers the InsForge client and returns your methods alongside it — the
106
+ * InsForgeService - Singleton para el cliente InsForge (fallback de base de datos).
107
+ *
108
+ * Aplica el patrón Singleton: una única instancia mantiene el
109
+ * {@link InsForgeClient} y centraliza las operaciones de tabla, RPC,
110
+ * storage y edge functions, devolviendo siempre Safe Results.
111
+ *
112
+ * @example
113
+ * ```ts
114
+ * const insforge = InsForgeService.getInstance();
115
+ * insforge.useInit({ baseUrl: "https://app.insforge.app", anonKey: "…" });
116
+ * const result = await insforge.useSelect({ table: "posts" });
117
+ * ```
118
+ */
119
+ export class InsForgeService {
120
+ static instance;
121
+ /** InsForge client. InsForge is the database fallback, not the default. */
122
+ client = null;
123
+ /**
124
+ * Constructor privado - enforce singleton.
125
+ */
126
+ constructor() { }
127
+ /**
128
+ * Obtiene la instancia única del InsForgeService (Singleton).
129
+ *
130
+ * @returns La instancia única de {@link InsForgeService}.
131
+ */
132
+ static getInstance() {
133
+ if (!InsForgeService.instance) {
134
+ InsForgeService.instance = new InsForgeService();
135
+ }
136
+ return InsForgeService.instance;
137
+ }
138
+ /**
139
+ * Registers the InsForge client. Call once per app. Prefer `apiKey`
140
+ * (server-only, admin) or `anonKey` (browser-safe) depending on the runtime.
141
+ *
142
+ * @param config - Backend URL + credentials + optional schema.
143
+ * @throws {Error} If the config fails validation.
144
+ *
145
+ * @example
146
+ * ```ts
147
+ * InsForgeService.getInstance().useInit({ baseUrl: "https://app.insforge.app", anonKey: "…" });
148
+ * ```
149
+ */
150
+ useInit(config) {
151
+ const parsed = useValidate(IfConfigSchema, config);
152
+ if (!parsed.ok) {
153
+ throw new Error(`[InsForge] Invalid config: ${parsed.error.message}`);
154
+ }
155
+ const { baseUrl, anonKey, apiKey, accessToken, schema } = parsed.data;
156
+ this.client = apiKey
157
+ ? createAdminClient({ baseUrl, apiKey })
158
+ : createClient({
159
+ baseUrl,
160
+ ...(anonKey !== undefined ? { anonKey } : {}),
161
+ ...(accessToken !== undefined ? { accessToken } : {}),
162
+ ...(schema !== undefined ? { db: { schema } } : {}),
163
+ });
164
+ }
165
+ /**
166
+ * Returns the initialized client (or `null` before `useInit`).
167
+ * Exposed for advanced use - the wrappers cover the supported surface.
168
+ *
169
+ * @returns The InsForge client or `null`.
170
+ */
171
+ useGetClient() {
172
+ return this.client;
173
+ }
174
+ /**
175
+ * Reads rows from a table with equality filters, ordering and pagination.
176
+ *
177
+ * @param query - Table, columns, filters, order, limit and offset.
178
+ * @returns Safe Result with the rows.
179
+ */
180
+ async useSelect(query) {
181
+ const parsed = useValidate(IfTableQuerySchema, query);
182
+ if (!parsed.ok)
183
+ return invalidInput(parsed);
184
+ if (!this.client)
185
+ return notConfigured();
186
+ const db = this.client;
187
+ return run(async () => {
188
+ const database = scopedDatabase(db.database, parsed.data.schema);
189
+ let builder = database.from(parsed.data.table).select(parsed.data.columns ?? "*");
190
+ builder = applyFilters(builder, parsed.data.filters);
191
+ if (parsed.data.order) {
192
+ builder = builder.order(parsed.data.order.column, {
193
+ ascending: parsed.data.order.ascending ?? true,
194
+ });
195
+ }
196
+ if (parsed.data.limit !== undefined)
197
+ builder = builder.limit(parsed.data.limit);
198
+ if (parsed.data.offset !== undefined) {
199
+ const from = parsed.data.offset;
200
+ builder = builder.range(from, from + (parsed.data.limit ?? 100) - 1);
201
+ }
202
+ const outcome = await builder;
203
+ if (outcome.error)
204
+ throw outcome.error;
205
+ return (outcome.data ?? []);
206
+ });
207
+ }
208
+ /**
209
+ * Inserts one or more rows and returns the created rows.
210
+ *
211
+ * @param table - Table name.
212
+ * @param rows - Rows to insert (at least one).
213
+ * @param schema - Optional schema override.
214
+ * @returns Safe Result with the inserted rows.
215
+ */
216
+ async useInsert(table, rows, schema) {
217
+ const tableParsed = useValidate(IfTableNameSchema, table);
218
+ if (!tableParsed.ok)
219
+ return invalidInput(tableParsed);
220
+ const rowsParsed = useValidate(IfInsertRowsSchema, rows);
221
+ if (!rowsParsed.ok)
222
+ return invalidInput(rowsParsed);
223
+ if (!this.client)
224
+ return notConfigured();
225
+ const db = this.client;
226
+ return run(async () => {
227
+ const database = scopedDatabase(db.database, schema);
228
+ const builder = database.from(tableParsed.data).insert(rowsParsed.data);
229
+ const outcome = await builder.select("*");
230
+ if (outcome.error)
231
+ throw outcome.error;
232
+ return (outcome.data ?? []);
233
+ }, 201);
234
+ }
235
+ /**
236
+ * Updates rows matching the filters and returns the updated rows.
237
+ * Filters are REQUIRED - mass updates are refused at validation time.
238
+ *
239
+ * @param query - Table + mandatory filters (+ optional schema).
240
+ * @param patch - Column patch (must not be empty).
241
+ * @returns Safe Result with the updated rows.
242
+ */
243
+ async useUpdate(query, patch) {
244
+ const queryParsed = useValidate(IfWriteQuerySchema, query);
245
+ if (!queryParsed.ok)
246
+ return invalidInput(queryParsed);
247
+ const patchParsed = useValidate(IfUpdatePatchSchema, patch);
248
+ if (!patchParsed.ok)
249
+ return invalidInput(patchParsed);
250
+ if (Object.keys(patchParsed.data).length === 0) {
251
+ return {
252
+ data: null,
253
+ error: { message: "Validation Error: patch must not be empty", status: 400 },
254
+ url: "",
255
+ status: 400,
256
+ ok: false,
257
+ };
258
+ }
259
+ if (!this.client)
260
+ return notConfigured();
261
+ const db = this.client;
262
+ return run(async () => {
263
+ const database = scopedDatabase(db.database, queryParsed.data.schema);
264
+ const updateBuilder = database.from(queryParsed.data.table).update(patchParsed.data);
265
+ const filtered = applyFilters(updateBuilder, queryParsed.data.filters);
266
+ const outcome = await filtered.select("*");
267
+ if (outcome.error)
268
+ throw outcome.error;
269
+ return (outcome.data ?? []);
270
+ });
271
+ }
272
+ /**
273
+ * Deletes rows matching the filters and returns the deleted rows.
274
+ * Filters are REQUIRED - mass deletes are refused at validation time.
275
+ *
276
+ * @param query - Table + mandatory filters (+ optional schema).
277
+ * @returns Safe Result with the deleted rows.
278
+ */
279
+ async useDelete(query) {
280
+ const parsed = useValidate(IfWriteQuerySchema, query);
281
+ if (!parsed.ok)
282
+ return invalidInput(parsed);
283
+ if (!this.client)
284
+ return notConfigured();
285
+ const db = this.client;
286
+ return run(async () => {
287
+ const database = scopedDatabase(db.database, parsed.data.schema);
288
+ const deleteBuilder = database.from(parsed.data.table).delete();
289
+ const filtered = applyFilters(deleteBuilder, parsed.data.filters);
290
+ const outcome = await filtered.select("*");
291
+ if (outcome.error)
292
+ throw outcome.error;
293
+ return (outcome.data ?? []);
294
+ });
295
+ }
296
+ /**
297
+ * Calls a Postgres function (RPC).
298
+ *
299
+ * @param call - Function name, params and optional schema.
300
+ * @returns Safe Result with the function output.
301
+ */
302
+ async useRpc(call) {
303
+ const parsed = useValidate(IfRpcCallSchema, call);
304
+ if (!parsed.ok)
305
+ return invalidInput(parsed);
306
+ if (!this.client)
307
+ return notConfigured();
308
+ const db = this.client;
309
+ return run(async () => {
310
+ const database = scopedDatabase(db.database, parsed.data.schema);
311
+ const outcome = await database.rpc(parsed.data.name, parsed.data.params ?? {});
312
+ if (outcome.error)
313
+ throw outcome.error;
314
+ return outcome.data;
315
+ });
316
+ }
317
+ /**
318
+ * Uploads a file to a bucket (standard PUT semantics: same key replaces).
319
+ *
320
+ * @param ref - Bucket + object key.
321
+ * @param file - File or Blob to upload.
322
+ * @returns Safe Result with the stored file metadata.
323
+ */
324
+ async useUpload(ref, file) {
325
+ const parsed = useValidate(IfStorageRefSchema, ref);
326
+ if (!parsed.ok)
327
+ return invalidInput(parsed);
328
+ if (!this.client)
329
+ return notConfigured();
330
+ const db = this.client;
331
+ return run(async () => {
332
+ const { data, error } = await db.storage.from(parsed.data.bucket).upload(parsed.data.path, file);
333
+ if (error)
334
+ throw error;
335
+ return (data ?? {});
336
+ });
337
+ }
338
+ /**
339
+ * Downloads a file from a bucket.
340
+ *
341
+ * @param ref - Bucket + object key.
342
+ * @returns Safe Result with the file as a Blob.
343
+ */
344
+ async useDownload(ref) {
345
+ const parsed = useValidate(IfStorageRefSchema, ref);
346
+ if (!parsed.ok)
347
+ return invalidInput(parsed);
348
+ if (!this.client)
349
+ return notConfigured();
350
+ const db = this.client;
351
+ const result = await run(async () => {
352
+ const { data, error } = await db.storage.from(parsed.data.bucket).download(parsed.data.path);
353
+ if (error)
354
+ throw error;
355
+ return data;
356
+ });
357
+ if (!result.ok)
358
+ return result;
359
+ if (!result.data) {
360
+ return {
361
+ data: null,
362
+ error: { message: "InsForge Error: object not found", status: 404 },
363
+ url: "",
364
+ status: 404,
365
+ ok: false,
366
+ };
367
+ }
368
+ return { data: result.data, error: null, url: "", status: 200, ok: true };
369
+ }
370
+ /**
371
+ * Removes a file from a bucket.
372
+ *
373
+ * @param ref - Bucket + object key.
374
+ * @returns Safe Result with the deletion response.
375
+ */
376
+ async useRemove(ref) {
377
+ const parsed = useValidate(IfStorageRefSchema, ref);
378
+ if (!parsed.ok)
379
+ return invalidInput(parsed);
380
+ if (!this.client)
381
+ return notConfigured();
382
+ const db = this.client;
383
+ return run(async () => {
384
+ const { data, error } = await db.storage.from(parsed.data.bucket).remove(parsed.data.path);
385
+ if (error)
386
+ throw error;
387
+ return (data ?? {});
388
+ });
389
+ }
390
+ /**
391
+ * Lists objects in a bucket.
392
+ *
393
+ * @param bucket - Bucket name.
394
+ * @param options - Prefix, search, limit and offset.
395
+ * @returns Safe Result with the listing.
396
+ */
397
+ async useListObjects(bucket, options) {
398
+ const bucketParsed = useValidate(IfBucketSchema, bucket);
399
+ if (!bucketParsed.ok)
400
+ return invalidInput(bucketParsed);
401
+ const optionsParsed = useValidate(IfListOptionsSchema, options ?? {});
402
+ if (!optionsParsed.ok)
403
+ return invalidInput(optionsParsed);
404
+ if (!this.client)
405
+ return notConfigured();
406
+ const db = this.client;
407
+ return run(async () => {
408
+ const { data, error } = await db.storage.from(bucketParsed.data).list(optionsParsed.data);
409
+ if (error)
410
+ throw error;
411
+ return (data ?? {});
412
+ });
413
+ }
414
+ /**
415
+ * Builds the public URL for an object in a public bucket (no network call).
416
+ *
417
+ * @param ref - Bucket + object key.
418
+ * @returns Safe Result with `{ publicUrl }`.
419
+ */
420
+ useGetPublicUrl(ref) {
421
+ const parsed = useValidate(IfStorageRefSchema, ref);
422
+ if (!parsed.ok)
423
+ return invalidInput(parsed);
424
+ if (!this.client)
425
+ return notConfigured();
426
+ const { data, error } = this.client.storage
427
+ .from(parsed.data.bucket)
428
+ .getPublicUrl(parsed.data.path);
429
+ if (error)
430
+ return fail(error);
431
+ if (!data) {
432
+ return {
433
+ data: null,
434
+ error: { message: "InsForge Error: public URL unavailable", status: 404 },
435
+ url: "",
436
+ status: 404,
437
+ ok: false,
438
+ };
439
+ }
440
+ return { data, error: null, url: "", status: 200, ok: true };
441
+ }
442
+ /**
443
+ * Invokes an edge function.
444
+ *
445
+ * @param options - Function slug + optional JSON body.
446
+ * @returns Safe Result with the function response.
447
+ */
448
+ async useInvokeFunction(options) {
449
+ const parsed = useValidate(IfInvokeOptionsSchema, options);
450
+ if (!parsed.ok)
451
+ return invalidInput(parsed);
452
+ if (!this.client)
453
+ return notConfigured();
454
+ const db = this.client;
455
+ return run(async () => {
456
+ const { data, error } = await db.functions.invoke(parsed.data.name, {
457
+ body: parsed.data.body,
458
+ });
459
+ if (error)
460
+ throw error;
461
+ return data;
462
+ });
463
+ }
464
+ }
465
+ /* -------------------------------------------------------------------------- */
466
+ /* Initialization */
467
+ /* -------------------------------------------------------------------------- */
468
+ /**
469
+ * Registers the InsForge client and returns your methods alongside it - the
109
470
  * config-file entry point. One call is the whole setup: no separate
110
471
  * `useInitInsforge(...)` step.
111
472
  *
@@ -155,29 +516,20 @@ export function defineInsforgeConfig(input) {
155
516
  * ```
156
517
  */
157
518
  export function useInitInsforge(config) {
158
- const parsed = useValidate(IfConfigSchema, config);
159
- if (!parsed.ok) {
160
- throw new Error(`[InsForge] Invalid config: ${parsed.error.message}`);
161
- }
162
- const { baseUrl, anonKey, apiKey, accessToken, schema } = parsed.data;
163
- client = apiKey
164
- ? createAdminClient({ baseUrl, apiKey })
165
- : createClient({
166
- baseUrl,
167
- ...(anonKey !== undefined ? { anonKey } : {}),
168
- ...(accessToken !== undefined ? { accessToken } : {}),
169
- ...(schema !== undefined ? { db: { schema } } : {}),
170
- });
519
+ InsForgeService.getInstance().useInit(config);
171
520
  }
172
521
  /**
173
522
  * Returns the initialized client (or `null` before `useInitInsforge`).
174
- * Exposed for advanced use — the wrappers cover the supported surface.
523
+ * Exposed for advanced use - the wrappers cover the supported surface.
175
524
  *
176
525
  * @returns The InsForge client or `null`.
177
526
  */
178
527
  export function useGetInsforgeClient() {
179
- return client;
528
+ return InsForgeService.getInstance().useGetClient();
180
529
  }
530
+ /* -------------------------------------------------------------------------- */
531
+ /* Wrappers (backward compatibility) */
532
+ /* -------------------------------------------------------------------------- */
181
533
  /**
182
534
  * Reads rows from a table with equality filters, ordering and pagination.
183
535
  *
@@ -190,32 +542,7 @@ export function useGetInsforgeClient() {
190
542
  * ```
191
543
  */
192
544
  export async function useIfSelect(query) {
193
- const parsed = useValidate(IfTableQuerySchema, query);
194
- if (!parsed.ok)
195
- return invalidInput(parsed);
196
- if (!client)
197
- return notConfigured();
198
- const db = client;
199
- return run(async () => {
200
- const database = scopedDatabase(db.database, parsed.data.schema);
201
- let builder = database.from(parsed.data.table).select(parsed.data.columns ?? "*");
202
- builder = applyFilters(builder, parsed.data.filters);
203
- if (parsed.data.order) {
204
- builder = builder.order(parsed.data.order.column, {
205
- ascending: parsed.data.order.ascending ?? true,
206
- });
207
- }
208
- if (parsed.data.limit !== undefined)
209
- builder = builder.limit(parsed.data.limit);
210
- if (parsed.data.offset !== undefined) {
211
- const from = parsed.data.offset;
212
- builder = builder.range(from, from + (parsed.data.limit ?? 100) - 1);
213
- }
214
- const outcome = await builder;
215
- if (outcome.error)
216
- throw outcome.error;
217
- return (outcome.data ?? []);
218
- });
545
+ return InsForgeService.getInstance().useSelect(query);
219
546
  }
220
547
  /**
221
548
  * Inserts one or more rows and returns the created rows.
@@ -226,84 +553,28 @@ export async function useIfSelect(query) {
226
553
  * @returns Safe Result with the inserted rows.
227
554
  */
228
555
  export async function useIfInsert(table, rows, schema) {
229
- const tableParsed = useValidate(IfTableNameSchema, table);
230
- if (!tableParsed.ok)
231
- return invalidInput(tableParsed);
232
- const rowsParsed = useValidate(IfInsertRowsSchema, rows);
233
- if (!rowsParsed.ok)
234
- return invalidInput(rowsParsed);
235
- if (!client)
236
- return notConfigured();
237
- const db = client;
238
- return run(async () => {
239
- const database = scopedDatabase(db.database, schema);
240
- const builder = database.from(tableParsed.data).insert(rowsParsed.data);
241
- const outcome = await builder.select("*");
242
- if (outcome.error)
243
- throw outcome.error;
244
- return (outcome.data ?? []);
245
- }, 201);
556
+ return InsForgeService.getInstance().useInsert(table, rows, schema);
246
557
  }
247
558
  /**
248
559
  * Updates rows matching the filters and returns the updated rows.
249
- * Filters are REQUIRED — mass updates are refused at validation time.
560
+ * Filters are REQUIRED - mass updates are refused at validation time.
250
561
  *
251
562
  * @param query - Table + mandatory filters (+ optional schema).
252
563
  * @param patch - Column patch (must not be empty).
253
564
  * @returns Safe Result with the updated rows.
254
565
  */
255
566
  export async function useIfUpdate(query, patch) {
256
- const queryParsed = useValidate(IfWriteQuerySchema, query);
257
- if (!queryParsed.ok)
258
- return invalidInput(queryParsed);
259
- const patchParsed = useValidate(IfUpdatePatchSchema, patch);
260
- if (!patchParsed.ok)
261
- return invalidInput(patchParsed);
262
- if (Object.keys(patchParsed.data).length === 0) {
263
- return {
264
- data: null,
265
- error: { message: "Validation Error: patch must not be empty", status: 400 },
266
- url: "",
267
- status: 400,
268
- ok: false,
269
- };
270
- }
271
- if (!client)
272
- return notConfigured();
273
- const db = client;
274
- return run(async () => {
275
- const database = scopedDatabase(db.database, queryParsed.data.schema);
276
- const updateBuilder = database.from(queryParsed.data.table).update(patchParsed.data);
277
- const filtered = applyFilters(updateBuilder, queryParsed.data.filters);
278
- const outcome = await filtered.select("*");
279
- if (outcome.error)
280
- throw outcome.error;
281
- return (outcome.data ?? []);
282
- });
567
+ return InsForgeService.getInstance().useUpdate(query, patch);
283
568
  }
284
569
  /**
285
570
  * Deletes rows matching the filters and returns the deleted rows.
286
- * Filters are REQUIRED — mass deletes are refused at validation time.
571
+ * Filters are REQUIRED - mass deletes are refused at validation time.
287
572
  *
288
573
  * @param query - Table + mandatory filters (+ optional schema).
289
574
  * @returns Safe Result with the deleted rows.
290
575
  */
291
576
  export async function useIfDelete(query) {
292
- const parsed = useValidate(IfWriteQuerySchema, query);
293
- if (!parsed.ok)
294
- return invalidInput(parsed);
295
- if (!client)
296
- return notConfigured();
297
- const db = client;
298
- return run(async () => {
299
- const database = scopedDatabase(db.database, parsed.data.schema);
300
- const deleteBuilder = database.from(parsed.data.table).delete();
301
- const filtered = applyFilters(deleteBuilder, parsed.data.filters);
302
- const outcome = await filtered.select("*");
303
- if (outcome.error)
304
- throw outcome.error;
305
- return (outcome.data ?? []);
306
- });
577
+ return InsForgeService.getInstance().useDelete(query);
307
578
  }
308
579
  /**
309
580
  * Calls a Postgres function (RPC).
@@ -312,19 +583,7 @@ export async function useIfDelete(query) {
312
583
  * @returns Safe Result with the function output.
313
584
  */
314
585
  export async function useIfRpc(call) {
315
- const parsed = useValidate(IfRpcCallSchema, call);
316
- if (!parsed.ok)
317
- return invalidInput(parsed);
318
- if (!client)
319
- return notConfigured();
320
- const db = client;
321
- return run(async () => {
322
- const database = scopedDatabase(db.database, parsed.data.schema);
323
- const outcome = await database.rpc(parsed.data.name, parsed.data.params ?? {});
324
- if (outcome.error)
325
- throw outcome.error;
326
- return outcome.data;
327
- });
586
+ return InsForgeService.getInstance().useRpc(call);
328
587
  }
329
588
  /**
330
589
  * Uploads a file to a bucket (standard PUT semantics: same key replaces).
@@ -334,18 +593,7 @@ export async function useIfRpc(call) {
334
593
  * @returns Safe Result with the stored file metadata.
335
594
  */
336
595
  export async function useIfUpload(ref, file) {
337
- const parsed = useValidate(IfStorageRefSchema, ref);
338
- if (!parsed.ok)
339
- return invalidInput(parsed);
340
- if (!client)
341
- return notConfigured();
342
- const db = client;
343
- return run(async () => {
344
- const { data, error } = await db.storage.from(parsed.data.bucket).upload(parsed.data.path, file);
345
- if (error)
346
- throw error;
347
- return (data ?? {});
348
- });
596
+ return InsForgeService.getInstance().useUpload(ref, file);
349
597
  }
350
598
  /**
351
599
  * Downloads a file from a bucket.
@@ -354,30 +602,7 @@ export async function useIfUpload(ref, file) {
354
602
  * @returns Safe Result with the file as a Blob.
355
603
  */
356
604
  export async function useIfDownload(ref) {
357
- const parsed = useValidate(IfStorageRefSchema, ref);
358
- if (!parsed.ok)
359
- return invalidInput(parsed);
360
- if (!client)
361
- return notConfigured();
362
- const db = client;
363
- const result = await run(async () => {
364
- const { data, error } = await db.storage.from(parsed.data.bucket).download(parsed.data.path);
365
- if (error)
366
- throw error;
367
- return data;
368
- });
369
- if (!result.ok)
370
- return result;
371
- if (!result.data) {
372
- return {
373
- data: null,
374
- error: { message: "InsForge Error: object not found", status: 404 },
375
- url: "",
376
- status: 404,
377
- ok: false,
378
- };
379
- }
380
- return { data: result.data, error: null, url: "", status: 200, ok: true };
605
+ return InsForgeService.getInstance().useDownload(ref);
381
606
  }
382
607
  /**
383
608
  * Removes a file from a bucket.
@@ -386,18 +611,7 @@ export async function useIfDownload(ref) {
386
611
  * @returns Safe Result with the deletion response.
387
612
  */
388
613
  export async function useIfRemove(ref) {
389
- const parsed = useValidate(IfStorageRefSchema, ref);
390
- if (!parsed.ok)
391
- return invalidInput(parsed);
392
- if (!client)
393
- return notConfigured();
394
- const db = client;
395
- return run(async () => {
396
- const { data, error } = await db.storage.from(parsed.data.bucket).remove(parsed.data.path);
397
- if (error)
398
- throw error;
399
- return (data ?? {});
400
- });
614
+ return InsForgeService.getInstance().useRemove(ref);
401
615
  }
402
616
  /**
403
617
  * Lists objects in a bucket.
@@ -407,21 +621,7 @@ export async function useIfRemove(ref) {
407
621
  * @returns Safe Result with the listing.
408
622
  */
409
623
  export async function useIfListObjects(bucket, options) {
410
- const bucketParsed = useValidate(IfBucketSchema, bucket);
411
- if (!bucketParsed.ok)
412
- return invalidInput(bucketParsed);
413
- const optionsParsed = useValidate(IfListOptionsSchema, options ?? {});
414
- if (!optionsParsed.ok)
415
- return invalidInput(optionsParsed);
416
- if (!client)
417
- return notConfigured();
418
- const db = client;
419
- return run(async () => {
420
- const { data, error } = await db.storage.from(bucketParsed.data).list(optionsParsed.data);
421
- if (error)
422
- throw error;
423
- return (data ?? {});
424
- });
624
+ return InsForgeService.getInstance().useListObjects(bucket, options);
425
625
  }
426
626
  /**
427
627
  * Builds the public URL for an object in a public bucket (no network call).
@@ -430,24 +630,7 @@ export async function useIfListObjects(bucket, options) {
430
630
  * @returns Safe Result with `{ publicUrl }`.
431
631
  */
432
632
  export function useIfGetPublicUrl(ref) {
433
- const parsed = useValidate(IfStorageRefSchema, ref);
434
- if (!parsed.ok)
435
- return invalidInput(parsed);
436
- if (!client)
437
- return notConfigured();
438
- const { data, error } = client.storage.from(parsed.data.bucket).getPublicUrl(parsed.data.path);
439
- if (error)
440
- return fail(error);
441
- if (!data) {
442
- return {
443
- data: null,
444
- error: { message: "InsForge Error: public URL unavailable", status: 404 },
445
- url: "",
446
- status: 404,
447
- ok: false,
448
- };
449
- }
450
- return { data, error: null, url: "", status: 200, ok: true };
633
+ return InsForgeService.getInstance().useGetPublicUrl(ref);
451
634
  }
452
635
  /**
453
636
  * Invokes an edge function.
@@ -456,19 +639,6 @@ export function useIfGetPublicUrl(ref) {
456
639
  * @returns Safe Result with the function response.
457
640
  */
458
641
  export async function useIfInvokeFunction(options) {
459
- const parsed = useValidate(IfInvokeOptionsSchema, options);
460
- if (!parsed.ok)
461
- return invalidInput(parsed);
462
- if (!client)
463
- return notConfigured();
464
- const db = client;
465
- return run(async () => {
466
- const { data, error } = await db.functions.invoke(parsed.data.name, {
467
- body: parsed.data.body,
468
- });
469
- if (error)
470
- throw error;
471
- return data;
472
- });
642
+ return InsForgeService.getInstance().useInvokeFunction(options);
473
643
  }
474
644
  //# sourceMappingURL=insforge.service.js.map