@rebasepro/types 0.8.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.
- package/README.md +10 -10
- package/dist/controllers/auth.d.ts +1 -1
- package/dist/controllers/client.d.ts +184 -6
- package/dist/controllers/collection_registry.d.ts +3 -3
- package/dist/controllers/customization_controller.d.ts +1 -1
- package/dist/controllers/data.d.ts +267 -35
- package/dist/controllers/data_driver.d.ts +50 -37
- package/dist/controllers/index.d.ts +1 -1
- package/dist/controllers/local_config_persistence.d.ts +4 -4
- package/dist/controllers/navigation.d.ts +2 -2
- package/dist/controllers/registry.d.ts +17 -4
- package/dist/controllers/{side_entity_controller.d.ts → side_panel_controller.d.ts} +7 -7
- package/dist/controllers/storage.d.ts +39 -0
- package/dist/errors.d.ts +64 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +142 -15
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +150 -17
- package/dist/index.umd.js.map +1 -1
- package/dist/rebase_context.d.ts +8 -4
- package/dist/types/auth_adapter.d.ts +4 -1
- package/dist/types/backend.d.ts +26 -26
- package/dist/types/builders.d.ts +2 -2
- package/dist/types/collections.d.ts +62 -63
- package/dist/types/component_overrides.d.ts +61 -3
- package/dist/types/cron.d.ts +10 -1
- package/dist/types/data_source.d.ts +15 -2
- package/dist/types/database_adapter.d.ts +4 -3
- package/dist/types/entities.d.ts +7 -7
- package/dist/types/entity_actions.d.ts +7 -7
- package/dist/types/entity_callbacks.d.ts +39 -39
- package/dist/types/entity_views.d.ts +3 -3
- package/dist/types/filter-operators.d.ts +62 -17
- package/dist/types/modify_collections.d.ts +2 -2
- package/dist/types/plugins.d.ts +9 -9
- package/dist/types/policy.d.ts +64 -10
- package/dist/types/properties.d.ts +41 -9
- package/dist/types/relations.d.ts +3 -3
- package/dist/types/slots.d.ts +14 -14
- package/dist/types/websockets.d.ts +12 -13
- package/dist/users/user.d.ts +21 -9
- package/package.json +1 -1
- package/src/controllers/auth.tsx +1 -1
- package/src/controllers/client.ts +214 -6
- package/src/controllers/collection_registry.ts +3 -3
- package/src/controllers/customization_controller.tsx +1 -1
- package/src/controllers/data.ts +290 -39
- package/src/controllers/data_driver.ts +49 -40
- package/src/controllers/index.ts +1 -1
- package/src/controllers/local_config_persistence.tsx +4 -4
- package/src/controllers/navigation.ts +2 -2
- package/src/controllers/registry.ts +18 -4
- package/src/controllers/{side_entity_controller.tsx → side_panel_controller.tsx} +7 -7
- package/src/controllers/storage.ts +60 -1
- package/src/errors.ts +80 -0
- package/src/index.ts +1 -0
- package/src/rebase_context.tsx +8 -4
- package/src/types/auth_adapter.ts +4 -1
- package/src/types/backend.ts +36 -36
- package/src/types/builders.ts +2 -2
- package/src/types/collections.ts +78 -79
- package/src/types/component_overrides.ts +72 -5
- package/src/types/cron.ts +10 -1
- package/src/types/data_source.ts +24 -2
- package/src/types/database_adapter.ts +4 -3
- package/src/types/entities.ts +7 -7
- package/src/types/entity_actions.tsx +7 -7
- package/src/types/entity_callbacks.ts +42 -42
- package/src/types/entity_views.tsx +3 -3
- package/src/types/filter-operators.ts +96 -23
- package/src/types/modify_collections.tsx +2 -2
- package/src/types/plugins.tsx +9 -9
- package/src/types/policy.ts +64 -8
- package/src/types/properties.ts +44 -9
- package/src/types/relations.ts +3 -3
- package/src/types/slots.tsx +14 -14
- package/src/types/websockets.ts +12 -14
- package/src/users/user.ts +22 -9
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
|
|
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
|
|
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
|
|
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";
|
|
@@ -138,7 +195,13 @@
|
|
|
138
195
|
"in": "in",
|
|
139
196
|
"not-in": "nin",
|
|
140
197
|
"array-contains": "cs",
|
|
141
|
-
"array-contains-any": "csa"
|
|
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"
|
|
142
205
|
};
|
|
143
206
|
/** Maps REST short-code operators to their canonical equivalents. */
|
|
144
207
|
var REST_TO_CANONICAL = {
|
|
@@ -151,10 +214,26 @@
|
|
|
151
214
|
"in": "in",
|
|
152
215
|
"nin": "not-in",
|
|
153
216
|
"cs": "array-contains",
|
|
154
|
-
"csa": "array-contains-any"
|
|
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"
|
|
155
224
|
};
|
|
156
|
-
/**
|
|
157
|
-
|
|
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 = [
|
|
158
237
|
"<",
|
|
159
238
|
"<=",
|
|
160
239
|
"==",
|
|
@@ -164,8 +243,16 @@
|
|
|
164
243
|
"in",
|
|
165
244
|
"not-in",
|
|
166
245
|
"array-contains",
|
|
167
|
-
"array-contains-any"
|
|
168
|
-
|
|
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);
|
|
169
256
|
/**
|
|
170
257
|
* Resolve any operator string (canonical or REST short-code) to its
|
|
171
258
|
* canonical `WhereFilterOp` form. Returns `undefined` for unknown operators.
|
|
@@ -187,21 +274,21 @@
|
|
|
187
274
|
* Returns true if the collection uses the Postgres engine (or the default engine).
|
|
188
275
|
* @group Models
|
|
189
276
|
*/
|
|
190
|
-
function
|
|
277
|
+
function isPostgresCollectionConfig(collection) {
|
|
191
278
|
return !collection.engine || collection.engine === "postgres";
|
|
192
279
|
}
|
|
193
280
|
/**
|
|
194
281
|
* Type guard for Firebase / Firestore collections.
|
|
195
282
|
* @group Models
|
|
196
283
|
*/
|
|
197
|
-
function
|
|
284
|
+
function isFirebaseCollectionConfig(collection) {
|
|
198
285
|
return collection.engine === "firestore";
|
|
199
286
|
}
|
|
200
287
|
/**
|
|
201
288
|
* Type guard for MongoDB collections.
|
|
202
289
|
* @group Models
|
|
203
290
|
*/
|
|
204
|
-
function
|
|
291
|
+
function isMongoDBCollectionConfig(collection) {
|
|
205
292
|
return collection.engine === "mongodb";
|
|
206
293
|
}
|
|
207
294
|
/**
|
|
@@ -210,8 +297,8 @@
|
|
|
210
297
|
* otherwise falls back to `slug`.
|
|
211
298
|
*/
|
|
212
299
|
function getCollectionDataPath(collection) {
|
|
213
|
-
if (
|
|
214
|
-
if (
|
|
300
|
+
if (isFirebaseCollectionConfig(collection) && collection.path) return collection.path;
|
|
301
|
+
if (isMongoDBCollectionConfig(collection) && collection.path) return collection.path;
|
|
215
302
|
return collection.slug;
|
|
216
303
|
}
|
|
217
304
|
/**
|
|
@@ -260,6 +347,11 @@
|
|
|
260
347
|
roles
|
|
261
348
|
}),
|
|
262
349
|
authenticated: () => ({ kind: "authenticated" }),
|
|
350
|
+
existsIn: (args) => ({
|
|
351
|
+
kind: "existsIn",
|
|
352
|
+
collection: args.collection,
|
|
353
|
+
where: args.where
|
|
354
|
+
}),
|
|
263
355
|
raw: (sql) => ({
|
|
264
356
|
kind: "raw",
|
|
265
357
|
sql
|
|
@@ -268,6 +360,10 @@
|
|
|
268
360
|
kind: "field",
|
|
269
361
|
name
|
|
270
362
|
}),
|
|
363
|
+
outerField: (name) => ({
|
|
364
|
+
kind: "outerField",
|
|
365
|
+
name
|
|
366
|
+
}),
|
|
271
367
|
literal: (value) => ({
|
|
272
368
|
kind: "literal",
|
|
273
369
|
value
|
|
@@ -324,6 +420,7 @@
|
|
|
324
420
|
supportsReferences: false,
|
|
325
421
|
supportsColumnTypes: true,
|
|
326
422
|
supportsRealtime: true,
|
|
423
|
+
filterOperators: ALL_WHERE_FILTER_OPS,
|
|
327
424
|
supportsSQLAdmin: true,
|
|
328
425
|
supportsDocumentAdmin: false,
|
|
329
426
|
supportsSchemaAdmin: true
|
|
@@ -338,6 +435,7 @@
|
|
|
338
435
|
supportsReferences: true,
|
|
339
436
|
supportsColumnTypes: false,
|
|
340
437
|
supportsRealtime: true,
|
|
438
|
+
filterOperators: ALL_WHERE_FILTER_OPS.filter((op) => op !== "like" && op !== "ilike" && op !== "not-like" && op !== "not-ilike"),
|
|
341
439
|
supportsSQLAdmin: false,
|
|
342
440
|
supportsDocumentAdmin: false,
|
|
343
441
|
supportsSchemaAdmin: false
|
|
@@ -352,6 +450,7 @@
|
|
|
352
450
|
supportsReferences: true,
|
|
353
451
|
supportsColumnTypes: false,
|
|
354
452
|
supportsRealtime: false,
|
|
453
|
+
filterOperators: ALL_WHERE_FILTER_OPS,
|
|
355
454
|
supportsSQLAdmin: false,
|
|
356
455
|
supportsDocumentAdmin: true,
|
|
357
456
|
supportsSchemaAdmin: true
|
|
@@ -370,6 +469,7 @@
|
|
|
370
469
|
supportsReferences: true,
|
|
371
470
|
supportsColumnTypes: true,
|
|
372
471
|
supportsRealtime: true,
|
|
472
|
+
filterOperators: ALL_WHERE_FILTER_OPS,
|
|
373
473
|
supportsSQLAdmin: true,
|
|
374
474
|
supportsDocumentAdmin: true,
|
|
375
475
|
supportsSchemaAdmin: true
|
|
@@ -427,6 +527,34 @@
|
|
|
427
527
|
return typeof ref === "object" && ref !== null && "__rebaseLazy" in ref && ref.__rebaseLazy === true;
|
|
428
528
|
}
|
|
429
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;
|
|
430
558
|
exports.CANONICAL_TO_REST = CANONICAL_TO_REST;
|
|
431
559
|
exports.DEFAULT_CAPABILITIES = DEFAULT_CAPABILITIES;
|
|
432
560
|
exports.DEFAULT_DATA_SOURCE_KEY = DEFAULT_DATA_SOURCE_KEY;
|
|
@@ -436,18 +564,23 @@
|
|
|
436
564
|
exports.FIREBASE_CAPABILITIES = FIREBASE_CAPABILITIES;
|
|
437
565
|
exports.GeoPoint = GeoPoint;
|
|
438
566
|
exports.MONGODB_CAPABILITIES = MONGODB_CAPABILITIES;
|
|
567
|
+
exports.NULL_OPS = NULL_OPS;
|
|
439
568
|
exports.POSTGRES_CAPABILITIES = POSTGRES_CAPABILITIES;
|
|
569
|
+
exports.PUBLIC_STORAGE_PREFIX = PUBLIC_STORAGE_PREFIX;
|
|
440
570
|
exports.REST_TO_CANONICAL = REST_TO_CANONICAL;
|
|
571
|
+
exports.RebaseApiError = RebaseApiError;
|
|
572
|
+
exports.RebaseClientError = RebaseClientError;
|
|
441
573
|
exports.Vector = Vector;
|
|
442
574
|
exports.getCollectionDataPath = getCollectionDataPath;
|
|
443
575
|
exports.getDataSourceCapabilities = getDataSourceCapabilities;
|
|
444
576
|
exports.getDeclaredSubcollections = getDeclaredSubcollections;
|
|
445
577
|
exports.isBranchAdmin = isBranchAdmin;
|
|
446
578
|
exports.isDocumentAdmin = isDocumentAdmin;
|
|
447
|
-
exports.
|
|
579
|
+
exports.isFirebaseCollectionConfig = isFirebaseCollectionConfig;
|
|
448
580
|
exports.isLazyComponentRef = isLazyComponentRef;
|
|
449
|
-
exports.
|
|
450
|
-
exports.
|
|
581
|
+
exports.isMongoDBCollectionConfig = isMongoDBCollectionConfig;
|
|
582
|
+
exports.isPostgresCollectionConfig = isPostgresCollectionConfig;
|
|
583
|
+
exports.isPublicStoragePath = isPublicStoragePath;
|
|
451
584
|
exports.isSQLAdmin = isSQLAdmin;
|
|
452
585
|
exports.isSchemaAdmin = isSchemaAdmin;
|
|
453
586
|
exports.policy = policy;
|