@rebasepro/types 0.7.0 → 0.9.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 (88) hide show
  1. package/README.md +10 -10
  2. package/dist/controllers/auth.d.ts +1 -1
  3. package/dist/controllers/client.d.ts +237 -7
  4. package/dist/controllers/collection_registry.d.ts +3 -3
  5. package/dist/controllers/customization_controller.d.ts +1 -1
  6. package/dist/controllers/data.d.ts +285 -81
  7. package/dist/controllers/data_driver.d.ts +50 -37
  8. package/dist/controllers/index.d.ts +1 -1
  9. package/dist/controllers/local_config_persistence.d.ts +4 -4
  10. package/dist/controllers/navigation.d.ts +2 -2
  11. package/dist/controllers/registry.d.ts +17 -6
  12. package/dist/controllers/{side_entity_controller.d.ts → side_panel_controller.d.ts} +7 -7
  13. package/dist/controllers/storage.d.ts +39 -0
  14. package/dist/errors.d.ts +64 -0
  15. package/dist/index.d.ts +1 -0
  16. package/dist/index.es.js +290 -16
  17. package/dist/index.es.js.map +1 -1
  18. package/dist/index.umd.js +305 -18
  19. package/dist/index.umd.js.map +1 -1
  20. package/dist/rebase_context.d.ts +8 -4
  21. package/dist/types/auth_adapter.d.ts +9 -6
  22. package/dist/types/backend.d.ts +30 -26
  23. package/dist/types/builders.d.ts +2 -2
  24. package/dist/types/collections.d.ts +211 -136
  25. package/dist/types/component_overrides.d.ts +61 -3
  26. package/dist/types/cron.d.ts +10 -1
  27. package/dist/types/data_source.d.ts +18 -5
  28. package/dist/types/database_adapter.d.ts +4 -3
  29. package/dist/types/entities.d.ts +7 -7
  30. package/dist/types/entity_actions.d.ts +7 -7
  31. package/dist/types/entity_callbacks.d.ts +55 -43
  32. package/dist/types/entity_views.d.ts +3 -3
  33. package/dist/types/filter-operators.d.ts +153 -0
  34. package/dist/types/index.d.ts +3 -2
  35. package/dist/types/modify_collections.d.ts +2 -2
  36. package/dist/types/plugins.d.ts +9 -9
  37. package/dist/types/policy.d.ts +191 -0
  38. package/dist/types/properties.d.ts +153 -43
  39. package/dist/types/property_config.d.ts +1 -1
  40. package/dist/types/relations.d.ts +3 -3
  41. package/dist/types/slots.d.ts +14 -14
  42. package/dist/types/storage_source.d.ts +83 -0
  43. package/dist/types/websockets.d.ts +12 -13
  44. package/dist/users/user.d.ts +21 -9
  45. package/package.json +1 -1
  46. package/src/controllers/auth.tsx +1 -1
  47. package/src/controllers/client.ts +275 -7
  48. package/src/controllers/collection_registry.ts +3 -3
  49. package/src/controllers/customization_controller.tsx +1 -1
  50. package/src/controllers/data.ts +309 -97
  51. package/src/controllers/data_driver.ts +49 -40
  52. package/src/controllers/index.ts +1 -1
  53. package/src/controllers/local_config_persistence.tsx +4 -4
  54. package/src/controllers/navigation.ts +2 -2
  55. package/src/controllers/registry.ts +18 -6
  56. package/src/controllers/{side_entity_controller.tsx → side_panel_controller.tsx} +7 -7
  57. package/src/controllers/storage.ts +60 -1
  58. package/src/errors.ts +80 -0
  59. package/src/index.ts +1 -0
  60. package/src/rebase_context.tsx +8 -4
  61. package/src/types/auth_adapter.ts +9 -6
  62. package/src/types/backend.ts +41 -36
  63. package/src/types/builders.ts +2 -2
  64. package/src/types/collections.ts +256 -172
  65. package/src/types/component_overrides.ts +72 -5
  66. package/src/types/cron.ts +10 -1
  67. package/src/types/data_source.ts +29 -7
  68. package/src/types/database_adapter.ts +4 -3
  69. package/src/types/entities.ts +7 -7
  70. package/src/types/entity_actions.tsx +7 -7
  71. package/src/types/entity_callbacks.ts +58 -47
  72. package/src/types/entity_views.tsx +3 -3
  73. package/src/types/filter-operators.ts +240 -0
  74. package/src/types/index.ts +3 -2
  75. package/src/types/modify_collections.tsx +2 -2
  76. package/src/types/plugins.tsx +9 -9
  77. package/src/types/policy.ts +229 -0
  78. package/src/types/properties.ts +164 -44
  79. package/src/types/property_config.tsx +0 -1
  80. package/src/types/relations.ts +3 -3
  81. package/src/types/slots.tsx +14 -14
  82. package/src/types/storage_source.ts +90 -0
  83. package/src/types/websockets.ts +12 -14
  84. package/src/users/user.ts +22 -9
  85. package/dist/types/backend_hooks.d.ts +0 -109
  86. package/dist/types/entity_overrides.d.ts +0 -10
  87. package/src/types/backend_hooks.ts +0 -114
  88. package/src/types/entity_overrides.tsx +0 -11
package/dist/index.umd.js CHANGED
@@ -2,9 +2,66 @@
2
2
  typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["Rebase Types"] = {}));
3
3
  })(this, function(exports) {
4
4
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
5
+ //#region src/errors.ts
6
+ /**
7
+ * The single error type thrown across the entire Rebase client surface —
8
+ * HTTP data/control-plane calls, realtime/WebSocket operations, and
9
+ * client-side logic errors (e.g. an unknown collection accessor). A `catch`
10
+ * block only ever needs to check for this one class:
11
+ *
12
+ * ```ts
13
+ * import { RebaseApiError } from "@rebasepro/client"; // re-exported
14
+ *
15
+ * try {
16
+ * await client.data.products.update(id, { price: 9 });
17
+ * } catch (e) {
18
+ * if (e instanceof RebaseApiError) {
19
+ * if (e.status === 404) { ... } // HTTP failures carry a status
20
+ * console.error(e.code, e.details);
21
+ * }
22
+ * }
23
+ * ```
24
+ *
25
+ * `status` is present for HTTP failures and `undefined` otherwise, so its
26
+ * presence distinguishes transport-level errors from realtime/logic errors.
27
+ *
28
+ * @group Errors
29
+ */
30
+ var RebaseApiError = class extends Error {
31
+ /** HTTP status code, or `undefined` for non-HTTP errors. */
32
+ status;
33
+ /** Stable machine-readable error code, when the server supplied one. */
34
+ code;
35
+ /** Structured error payload from the server, when present. */
36
+ details;
37
+ constructor(message, init = {}) {
38
+ super(message);
39
+ this.name = "RebaseApiError";
40
+ this.status = init.status;
41
+ this.code = init.code;
42
+ this.details = init.details;
43
+ if (init.cause !== void 0) this.cause = init.cause;
44
+ }
45
+ };
46
+ /**
47
+ * Client-side logic error — raised before any request is made (e.g. accessing
48
+ * an unknown collection accessor when a typed dictionary is configured).
49
+ *
50
+ * A subclass of {@link RebaseApiError} (with no `status`), so a single
51
+ * `catch (e) { if (e instanceof RebaseApiError) ... }` handles it too.
52
+ *
53
+ * @group Errors
54
+ */
55
+ var RebaseClientError = class extends RebaseApiError {
56
+ constructor(message) {
57
+ super(message);
58
+ this.name = "RebaseClientError";
59
+ }
60
+ };
61
+ //#endregion
5
62
  //#region src/types/entities.ts
6
63
  /**
7
- * Class used to create a reference to an entity in a different path.
64
+ * Class used to create a reference to a entity in a different path.
8
65
  *
9
66
  * @example
10
67
  * // Simple reference (most common case - single driver, single db)
@@ -38,7 +95,7 @@
38
95
  */
39
96
  databaseId;
40
97
  /**
41
- * Create a reference to an entity.
98
+ * Create a reference to a entity.
42
99
  *
43
100
  * @example
44
101
  * // Simple reference (most common case)
@@ -72,7 +129,7 @@
72
129
  }
73
130
  };
74
131
  /**
75
- * Class used to create a reference to an entity in a different path
132
+ * Class used to create a reference to a entity in a different path
76
133
  */
77
134
  var EntityRelation = class {
78
135
  __type = "relation";
@@ -126,30 +183,195 @@
126
183
  }
127
184
  };
128
185
  //#endregion
186
+ //#region src/types/filter-operators.ts
187
+ /** Maps canonical operators to their REST short-code equivalents. */
188
+ var CANONICAL_TO_REST = {
189
+ "==": "eq",
190
+ "!=": "neq",
191
+ ">": "gt",
192
+ ">=": "gte",
193
+ "<": "lt",
194
+ "<=": "lte",
195
+ "in": "in",
196
+ "not-in": "nin",
197
+ "array-contains": "cs",
198
+ "array-contains-any": "csa",
199
+ "like": "like",
200
+ "ilike": "ilike",
201
+ "not-like": "nlike",
202
+ "not-ilike": "nilike",
203
+ "is-null": "isnull",
204
+ "is-not-null": "notnull"
205
+ };
206
+ /** Maps REST short-code operators to their canonical equivalents. */
207
+ var REST_TO_CANONICAL = {
208
+ "eq": "==",
209
+ "neq": "!=",
210
+ "gt": ">",
211
+ "gte": ">=",
212
+ "lt": "<",
213
+ "lte": "<=",
214
+ "in": "in",
215
+ "nin": "not-in",
216
+ "cs": "array-contains",
217
+ "csa": "array-contains-any",
218
+ "like": "like",
219
+ "ilike": "ilike",
220
+ "nlike": "not-like",
221
+ "nilike": "not-ilike",
222
+ "isnull": "is-null",
223
+ "notnull": "is-not-null"
224
+ };
225
+ /**
226
+ * Operators that test for null/not-null and therefore ignore their value.
227
+ * Codecs normalize the value of these conditions to `null`.
228
+ */
229
+ var NULL_OPS = new Set(["is-null", "is-not-null"]);
230
+ /**
231
+ * Every canonical operator, in a stable order. Useful for engine capability
232
+ * declarations ({@link DataSourceCapabilities.filterOperators}) and for
233
+ * building operator subsets.
234
+ * @group Models
235
+ */
236
+ var ALL_WHERE_FILTER_OPS = [
237
+ "<",
238
+ "<=",
239
+ "==",
240
+ "!=",
241
+ ">=",
242
+ ">",
243
+ "in",
244
+ "not-in",
245
+ "array-contains",
246
+ "array-contains-any",
247
+ "like",
248
+ "ilike",
249
+ "not-like",
250
+ "not-ilike",
251
+ "is-null",
252
+ "is-not-null"
253
+ ];
254
+ /** All canonical operator strings for runtime validation. */
255
+ var CANONICAL_OPS = new Set(ALL_WHERE_FILTER_OPS);
256
+ /**
257
+ * Resolve any operator string (canonical or REST short-code) to its
258
+ * canonical `WhereFilterOp` form. Returns `undefined` for unknown operators.
259
+ *
260
+ * @example
261
+ * toCanonicalOp("==") // "=="
262
+ * toCanonicalOp("eq") // "=="
263
+ * toCanonicalOp("cs") // "array-contains"
264
+ * toCanonicalOp("xyz") // undefined
265
+ */
266
+ function toCanonicalOp(op) {
267
+ if (CANONICAL_OPS.has(op)) return op;
268
+ return REST_TO_CANONICAL[op];
269
+ }
270
+ //#endregion
129
271
  //#region src/types/collections.ts
130
272
  /**
131
273
  * Type guard for PostgreSQL collections.
132
- * Returns true if the collection uses the Postgres driver (or the default driver).
274
+ * Returns true if the collection uses the Postgres engine (or the default engine).
133
275
  * @group Models
134
276
  */
135
- function isPostgresCollection(collection) {
136
- return !collection.driver || collection.driver === "postgres";
277
+ function isPostgresCollectionConfig(collection) {
278
+ return !collection.engine || collection.engine === "postgres";
137
279
  }
138
280
  /**
139
281
  * Type guard for Firebase / Firestore collections.
140
282
  * @group Models
141
283
  */
142
- function isFirebaseCollection(collection) {
143
- return collection.driver === "firestore";
284
+ function isFirebaseCollectionConfig(collection) {
285
+ return collection.engine === "firestore";
144
286
  }
145
287
  /**
146
288
  * Type guard for MongoDB collections.
147
289
  * @group Models
148
290
  */
149
- function isMongoDBCollection(collection) {
150
- return collection.driver === "mongodb";
291
+ function isMongoDBCollectionConfig(collection) {
292
+ return collection.engine === "mongodb";
293
+ }
294
+ /**
295
+ * Returns the data path for a collection.
296
+ * For Firestore or MongoDB collections with a `path`, returns that value;
297
+ * otherwise falls back to `slug`.
298
+ */
299
+ function getCollectionDataPath(collection) {
300
+ if (isFirebaseCollectionConfig(collection) && collection.path) return collection.path;
301
+ if (isMongoDBCollectionConfig(collection) && collection.path) return collection.path;
302
+ return collection.slug;
303
+ }
304
+ /**
305
+ * Reads a collection's driver-declared subcollections thunk (the `subcollections`
306
+ * field) independent of engine identity, so engine-agnostic code doesn't have to
307
+ * type-guard against a specific driver. Returns `undefined` when the collection
308
+ * declares none.
309
+ *
310
+ * Pair with `getDataSourceCapabilities(engine).supportsSubcollections` to decide
311
+ * whether the engine honours subcollections at all before reading them.
312
+ * @group Models
313
+ */
314
+ function getDeclaredSubcollections(collection) {
315
+ return collection.subcollections;
151
316
  }
152
317
  //#endregion
318
+ //#region src/types/policy.ts
319
+ /** @group Models */
320
+ var policy = {
321
+ true: () => ({ kind: "true" }),
322
+ false: () => ({ kind: "false" }),
323
+ and: (...operands) => ({
324
+ kind: "and",
325
+ operands
326
+ }),
327
+ or: (...operands) => ({
328
+ kind: "or",
329
+ operands
330
+ }),
331
+ not: (operand) => ({
332
+ kind: "not",
333
+ operand
334
+ }),
335
+ compare: (left, op, right) => ({
336
+ kind: "compare",
337
+ op,
338
+ left,
339
+ right
340
+ }),
341
+ rolesOverlap: (roles) => ({
342
+ kind: "rolesOverlap",
343
+ roles
344
+ }),
345
+ rolesContain: (roles) => ({
346
+ kind: "rolesContain",
347
+ roles
348
+ }),
349
+ authenticated: () => ({ kind: "authenticated" }),
350
+ existsIn: (args) => ({
351
+ kind: "existsIn",
352
+ collection: args.collection,
353
+ where: args.where
354
+ }),
355
+ raw: (sql) => ({
356
+ kind: "raw",
357
+ sql
358
+ }),
359
+ field: (name) => ({
360
+ kind: "field",
361
+ name
362
+ }),
363
+ outerField: (name) => ({
364
+ kind: "outerField",
365
+ name
366
+ }),
367
+ literal: (value) => ({
368
+ kind: "literal",
369
+ value
370
+ }),
371
+ authUid: () => ({ kind: "authUid" }),
372
+ authRoles: () => ({ kind: "authRoles" })
373
+ };
374
+ //#endregion
153
375
  //#region src/types/backend.ts
154
376
  /**
155
377
  * Type guard: does this admin support SQL operations?
@@ -198,6 +420,7 @@
198
420
  supportsReferences: false,
199
421
  supportsColumnTypes: true,
200
422
  supportsRealtime: true,
423
+ filterOperators: ALL_WHERE_FILTER_OPS,
201
424
  supportsSQLAdmin: true,
202
425
  supportsDocumentAdmin: false,
203
426
  supportsSchemaAdmin: true
@@ -212,6 +435,7 @@
212
435
  supportsReferences: true,
213
436
  supportsColumnTypes: false,
214
437
  supportsRealtime: true,
438
+ filterOperators: ALL_WHERE_FILTER_OPS.filter((op) => op !== "like" && op !== "ilike" && op !== "not-like" && op !== "not-ilike"),
215
439
  supportsSQLAdmin: false,
216
440
  supportsDocumentAdmin: false,
217
441
  supportsSchemaAdmin: false
@@ -226,6 +450,7 @@
226
450
  supportsReferences: true,
227
451
  supportsColumnTypes: false,
228
452
  supportsRealtime: false,
453
+ filterOperators: ALL_WHERE_FILTER_OPS,
229
454
  supportsSQLAdmin: false,
230
455
  supportsDocumentAdmin: true,
231
456
  supportsSchemaAdmin: true
@@ -244,6 +469,7 @@
244
469
  supportsReferences: true,
245
470
  supportsColumnTypes: true,
246
471
  supportsRealtime: true,
472
+ filterOperators: ALL_WHERE_FILTER_OPS,
247
473
  supportsSQLAdmin: true,
248
474
  supportsDocumentAdmin: true,
249
475
  supportsSchemaAdmin: true
@@ -255,13 +481,13 @@
255
481
  "(default)": DEFAULT_CAPABILITIES
256
482
  };
257
483
  /**
258
- * Look up capabilities for a given driver key.
259
- * If `driver` is undefined or not found, returns `DEFAULT_CAPABILITIES`.
484
+ * Look up capabilities for a given engine key.
485
+ * If `engine` is undefined or not found, returns `DEFAULT_CAPABILITIES`.
260
486
  * @group Models
261
487
  */
262
- function getDataSourceCapabilities(driver) {
263
- if (!driver) return POSTGRES_CAPABILITIES;
264
- return CAPABILITIES_REGISTRY[driver] ?? DEFAULT_CAPABILITIES;
488
+ function getDataSourceCapabilities(engine) {
489
+ if (!engine) return POSTGRES_CAPABILITIES;
490
+ return CAPABILITIES_REGISTRY[engine] ?? DEFAULT_CAPABILITIES;
265
491
  }
266
492
  /**
267
493
  * Register custom capabilities for a third-party driver.
@@ -271,6 +497,27 @@
271
497
  CAPABILITIES_REGISTRY[capabilities.key] = capabilities;
272
498
  }
273
499
  //#endregion
500
+ //#region src/types/storage_source.ts
501
+ /**
502
+ * Describes a named storage backend — a place files live.
503
+ *
504
+ * Declared once and shared front + back: the frontend uses it to decide
505
+ * transport (HTTP proxy vs direct SDK), the backend uses the same `key`
506
+ * to resolve a StorageController, and collection properties reference
507
+ * a definition by its `key` via `StorageConfig.storageSource`.
508
+ *
509
+ * This mirrors the {@link DataSourceDefinition} pattern used for databases.
510
+ *
511
+ * @group Models
512
+ */
513
+ /**
514
+ * The default storage source key, used when a property does not specify
515
+ * a `storageSource`. Shared by the frontend and backend registries so
516
+ * both agree on "the default storage backend".
517
+ * @group Models
518
+ */
519
+ var DEFAULT_STORAGE_SOURCE_KEY = "(default)";
520
+ //#endregion
274
521
  //#region src/types/component_ref.ts
275
522
  /**
276
523
  * Type guard: checks if a value is a `LazyComponentRef` produced by the
@@ -280,25 +527,65 @@
280
527
  return typeof ref === "object" && ref !== null && "__rebaseLazy" in ref && ref.__rebaseLazy === true;
281
528
  }
282
529
  //#endregion
530
+ //#region src/controllers/storage.ts
531
+ /**
532
+ * Path prefix that marks an object as **public**. Files stored under this
533
+ * prefix are served without any auth token via a stable, permanent,
534
+ * CDN-cacheable URL (see {@link StorageSource.getSignedUrl}). Shared by the
535
+ * client SDK and the backend so both agree on which objects are public.
536
+ *
537
+ * @group Models
538
+ */
539
+ var PUBLIC_STORAGE_PREFIX = "public/";
540
+ /**
541
+ * True when a storage key/path points at a public object (lives under
542
+ * {@link PUBLIC_STORAGE_PREFIX}). The check is applied to the key *within the
543
+ * bucket* — strip any `bucket/` and `scheme://` prefixes first.
544
+ *
545
+ * @group Models
546
+ */
547
+ function isPublicStoragePath(path) {
548
+ if (!path) return false;
549
+ let p = path;
550
+ const scheme = p.indexOf("://");
551
+ if (scheme !== -1) p = p.substring(scheme + 3);
552
+ p = p.replace(/^\/+/, "");
553
+ if (p.split("/").some((seg) => seg === "..")) return false;
554
+ return p.startsWith("public/") || p.startsWith(`default/public/`);
555
+ }
556
+ //#endregion
557
+ exports.ALL_WHERE_FILTER_OPS = ALL_WHERE_FILTER_OPS;
558
+ exports.CANONICAL_TO_REST = CANONICAL_TO_REST;
283
559
  exports.DEFAULT_CAPABILITIES = DEFAULT_CAPABILITIES;
284
560
  exports.DEFAULT_DATA_SOURCE_KEY = DEFAULT_DATA_SOURCE_KEY;
561
+ exports.DEFAULT_STORAGE_SOURCE_KEY = DEFAULT_STORAGE_SOURCE_KEY;
285
562
  exports.EntityReference = EntityReference;
286
563
  exports.EntityRelation = EntityRelation;
287
564
  exports.FIREBASE_CAPABILITIES = FIREBASE_CAPABILITIES;
288
565
  exports.GeoPoint = GeoPoint;
289
566
  exports.MONGODB_CAPABILITIES = MONGODB_CAPABILITIES;
567
+ exports.NULL_OPS = NULL_OPS;
290
568
  exports.POSTGRES_CAPABILITIES = POSTGRES_CAPABILITIES;
569
+ exports.PUBLIC_STORAGE_PREFIX = PUBLIC_STORAGE_PREFIX;
570
+ exports.REST_TO_CANONICAL = REST_TO_CANONICAL;
571
+ exports.RebaseApiError = RebaseApiError;
572
+ exports.RebaseClientError = RebaseClientError;
291
573
  exports.Vector = Vector;
574
+ exports.getCollectionDataPath = getCollectionDataPath;
292
575
  exports.getDataSourceCapabilities = getDataSourceCapabilities;
576
+ exports.getDeclaredSubcollections = getDeclaredSubcollections;
293
577
  exports.isBranchAdmin = isBranchAdmin;
294
578
  exports.isDocumentAdmin = isDocumentAdmin;
295
- exports.isFirebaseCollection = isFirebaseCollection;
579
+ exports.isFirebaseCollectionConfig = isFirebaseCollectionConfig;
296
580
  exports.isLazyComponentRef = isLazyComponentRef;
297
- exports.isMongoDBCollection = isMongoDBCollection;
298
- exports.isPostgresCollection = isPostgresCollection;
581
+ exports.isMongoDBCollectionConfig = isMongoDBCollectionConfig;
582
+ exports.isPostgresCollectionConfig = isPostgresCollectionConfig;
583
+ exports.isPublicStoragePath = isPublicStoragePath;
299
584
  exports.isSQLAdmin = isSQLAdmin;
300
585
  exports.isSchemaAdmin = isSchemaAdmin;
586
+ exports.policy = policy;
301
587
  exports.registerDataSourceCapabilities = registerDataSourceCapabilities;
588
+ exports.toCanonicalOp = toCanonicalOp;
302
589
  });
303
590
 
304
591
  //# sourceMappingURL=index.umd.js.map