@rebasepro/types 0.5.0 → 0.6.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/dist/index.umd.js CHANGED
@@ -1,226 +1,296 @@
1
1
  (function(global, factory) {
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
- })(this, function(exports2) {
4
- "use strict";
5
- class EntityReference {
6
- __type = "reference";
7
- /**
8
- * ID of the entity
9
- */
10
- id;
11
- /**
12
- * A string representing the path of the referenced document (relative
13
- * to the root of the database).
14
- */
15
- path;
16
- /**
17
- * Which driver (e.g., 'postgres', 'firestore').
18
- * Defaults to "(default)" if not specified.
19
- */
20
- driver;
21
- /**
22
- * Which database within the driver.
23
- * Defaults to "(default)" if not specified.
24
- */
25
- databaseId;
26
- /**
27
- * Create a reference to an entity.
28
- *
29
- * @example
30
- * // Simple reference (most common case)
31
- * new EntityReference({ id: "123", path: "users" })
32
- *
33
- * // With driver
34
- * new EntityReference({ id: "123", path: "analytics", driver: "firestore" })
35
- */
36
- constructor(props) {
37
- this.id = props.id;
38
- this.path = props.path;
39
- this.driver = props.driver;
40
- this.databaseId = props.databaseId;
41
- }
42
- get pathWithId() {
43
- return `${this.path}/${this.id}`;
44
- }
45
- /**
46
- * Get the full path including driver and database prefixes if specified.
47
- * For the common case (single driver, single db), this just returns pathWithId.
48
- */
49
- get fullPath() {
50
- const parts = [];
51
- if (this.driver && this.driver !== "(default)") {
52
- parts.push(this.driver);
53
- }
54
- if (this.databaseId && this.databaseId !== "(default)") {
55
- parts.push(this.databaseId);
56
- }
57
- if (parts.length > 0) {
58
- return `${parts.join(":")}:::${this.path}/${this.id}`;
59
- }
60
- return this.pathWithId;
61
- }
62
- isEntityReference() {
63
- return true;
64
- }
65
- }
66
- class EntityRelation {
67
- __type = "relation";
68
- /**
69
- * ID of the entity
70
- */
71
- id;
72
- /**
73
- * A string representing the path of the referenced document (relative
74
- * to the root of the database).
75
- */
76
- path;
77
- /**
78
- * Pre-fetched data payload to eliminate N+1 queries.
79
- * When present, clients can use this directly instead of fetching.
80
- */
81
- data;
82
- constructor(id, path, data) {
83
- this.id = id;
84
- this.path = path;
85
- this.data = data;
86
- }
87
- get pathWithId() {
88
- return `${this.path}/${this.id}`;
89
- }
90
- isEntityReference() {
91
- return false;
92
- }
93
- isEntityRelation() {
94
- return true;
95
- }
96
- }
97
- class GeoPoint {
98
- /**
99
- * The latitude of this GeoPoint instance.
100
- */
101
- latitude;
102
- /**
103
- * The longitude of this GeoPoint instance.
104
- */
105
- longitude;
106
- constructor(latitude, longitude) {
107
- this.latitude = latitude;
108
- this.longitude = longitude;
109
- }
110
- }
111
- class Vector {
112
- value;
113
- constructor(value) {
114
- this.value = value;
115
- }
116
- }
117
- function isPostgresCollection(collection) {
118
- return !collection.driver || collection.driver === "postgres";
119
- }
120
- function isFirebaseCollection(collection) {
121
- return collection.driver === "firestore";
122
- }
123
- function isMongoDBCollection(collection) {
124
- return collection.driver === "mongodb";
125
- }
126
- function isSQLAdmin(admin) {
127
- return !!admin && typeof admin.executeSql === "function";
128
- }
129
- function isDocumentAdmin(admin) {
130
- return !!admin && (typeof admin.executeAggregate === "function" || typeof admin.fetchCollectionStats === "function");
131
- }
132
- function isSchemaAdmin(admin) {
133
- return !!admin && (typeof admin.fetchUnmappedTables === "function" || typeof admin.fetchTableMetadata === "function");
134
- }
135
- function isBranchAdmin(admin) {
136
- return !!admin && typeof admin.createBranch === "function";
137
- }
138
- const POSTGRES_CAPABILITIES = {
139
- key: "postgres",
140
- label: "PostgreSQL",
141
- supportsRelations: true,
142
- supportsSubcollections: false,
143
- supportsRLS: true,
144
- supportsReferences: false,
145
- supportsColumnTypes: true,
146
- supportsRealtime: true,
147
- supportsSQLAdmin: true,
148
- supportsDocumentAdmin: false,
149
- supportsSchemaAdmin: true
150
- };
151
- const FIREBASE_CAPABILITIES = {
152
- key: "firestore",
153
- label: "Firebase / Firestore",
154
- supportsRelations: false,
155
- supportsSubcollections: true,
156
- supportsRLS: false,
157
- supportsReferences: true,
158
- supportsColumnTypes: false,
159
- supportsRealtime: true,
160
- supportsSQLAdmin: false,
161
- supportsDocumentAdmin: false,
162
- supportsSchemaAdmin: false
163
- };
164
- const MONGODB_CAPABILITIES = {
165
- key: "mongodb",
166
- label: "MongoDB",
167
- supportsRelations: false,
168
- supportsSubcollections: true,
169
- supportsRLS: false,
170
- supportsReferences: true,
171
- supportsColumnTypes: false,
172
- supportsRealtime: false,
173
- supportsSQLAdmin: false,
174
- supportsDocumentAdmin: true,
175
- supportsSchemaAdmin: true
176
- };
177
- const DEFAULT_CAPABILITIES = {
178
- key: "(default)",
179
- label: "Default",
180
- supportsRelations: true,
181
- supportsSubcollections: true,
182
- supportsRLS: true,
183
- supportsReferences: true,
184
- supportsColumnTypes: true,
185
- supportsRealtime: true,
186
- supportsSQLAdmin: true,
187
- supportsDocumentAdmin: true,
188
- supportsSchemaAdmin: true
189
- };
190
- const CAPABILITIES_REGISTRY = {
191
- postgres: POSTGRES_CAPABILITIES,
192
- firestore: FIREBASE_CAPABILITIES,
193
- mongodb: MONGODB_CAPABILITIES,
194
- "(default)": DEFAULT_CAPABILITIES
195
- };
196
- function getDataSourceCapabilities(driver) {
197
- if (!driver) return POSTGRES_CAPABILITIES;
198
- return CAPABILITIES_REGISTRY[driver] ?? DEFAULT_CAPABILITIES;
199
- }
200
- function registerDataSourceCapabilities(capabilities) {
201
- CAPABILITIES_REGISTRY[capabilities.key] = capabilities;
202
- }
203
- function isLazyComponentRef(ref) {
204
- return typeof ref === "object" && ref !== null && "__rebaseLazy" in ref && ref.__rebaseLazy === true;
205
- }
206
- exports2.DEFAULT_CAPABILITIES = DEFAULT_CAPABILITIES;
207
- exports2.EntityReference = EntityReference;
208
- exports2.EntityRelation = EntityRelation;
209
- exports2.FIREBASE_CAPABILITIES = FIREBASE_CAPABILITIES;
210
- exports2.GeoPoint = GeoPoint;
211
- exports2.MONGODB_CAPABILITIES = MONGODB_CAPABILITIES;
212
- exports2.POSTGRES_CAPABILITIES = POSTGRES_CAPABILITIES;
213
- exports2.Vector = Vector;
214
- exports2.getDataSourceCapabilities = getDataSourceCapabilities;
215
- exports2.isBranchAdmin = isBranchAdmin;
216
- exports2.isDocumentAdmin = isDocumentAdmin;
217
- exports2.isFirebaseCollection = isFirebaseCollection;
218
- exports2.isLazyComponentRef = isLazyComponentRef;
219
- exports2.isMongoDBCollection = isMongoDBCollection;
220
- exports2.isPostgresCollection = isPostgresCollection;
221
- exports2.isSQLAdmin = isSQLAdmin;
222
- exports2.isSchemaAdmin = isSchemaAdmin;
223
- exports2.registerDataSourceCapabilities = registerDataSourceCapabilities;
224
- Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
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
+ })(this, function(exports) {
4
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
5
+ //#region src/types/entities.ts
6
+ /**
7
+ * Class used to create a reference to an entity in a different path.
8
+ *
9
+ * @example
10
+ * // Simple reference (most common case - single driver, single db)
11
+ * new EntityReference({ id: "123", path: "users" })
12
+ *
13
+ * // Reference to a different driver (e.g., Firestore)
14
+ * new EntityReference({ id: "123", path: "analytics", driver: "firestore" })
15
+ *
16
+ * // Reference to a specific database within a driver
17
+ * new EntityReference({ id: "123", path: "orders", driver: "postgres", databaseId: "orders_db" })
18
+ */
19
+ var EntityReference = class {
20
+ __type = "reference";
21
+ /**
22
+ * ID of the entity
23
+ */
24
+ id;
25
+ /**
26
+ * A string representing the path of the referenced document (relative
27
+ * to the root of the database).
28
+ */
29
+ path;
30
+ /**
31
+ * Which driver (e.g., 'postgres', 'firestore').
32
+ * Defaults to "(default)" if not specified.
33
+ */
34
+ driver;
35
+ /**
36
+ * Which database within the driver.
37
+ * Defaults to "(default)" if not specified.
38
+ */
39
+ databaseId;
40
+ /**
41
+ * Create a reference to an entity.
42
+ *
43
+ * @example
44
+ * // Simple reference (most common case)
45
+ * new EntityReference({ id: "123", path: "users" })
46
+ *
47
+ * // With driver
48
+ * new EntityReference({ id: "123", path: "analytics", driver: "firestore" })
49
+ */
50
+ constructor(props) {
51
+ this.id = props.id;
52
+ this.path = props.path;
53
+ this.driver = props.driver;
54
+ this.databaseId = props.databaseId;
55
+ }
56
+ get pathWithId() {
57
+ return `${this.path}/${this.id}`;
58
+ }
59
+ /**
60
+ * Get the full path including driver and database prefixes if specified.
61
+ * For the common case (single driver, single db), this just returns pathWithId.
62
+ */
63
+ get fullPath() {
64
+ const parts = [];
65
+ if (this.driver && this.driver !== "(default)") parts.push(this.driver);
66
+ if (this.databaseId && this.databaseId !== "(default)") parts.push(this.databaseId);
67
+ if (parts.length > 0) return `${parts.join(":")}:::${this.path}/${this.id}`;
68
+ return this.pathWithId;
69
+ }
70
+ isEntityReference() {
71
+ return true;
72
+ }
73
+ };
74
+ /**
75
+ * Class used to create a reference to an entity in a different path
76
+ */
77
+ var EntityRelation = class {
78
+ __type = "relation";
79
+ /**
80
+ * ID of the entity
81
+ */
82
+ id;
83
+ /**
84
+ * A string representing the path of the referenced document (relative
85
+ * to the root of the database).
86
+ */
87
+ path;
88
+ /**
89
+ * Pre-fetched data payload to eliminate N+1 queries.
90
+ * When present, clients can use this directly instead of fetching.
91
+ */
92
+ data;
93
+ constructor(id, path, data) {
94
+ this.id = id;
95
+ this.path = path;
96
+ this.data = data;
97
+ }
98
+ get pathWithId() {
99
+ return `${this.path}/${this.id}`;
100
+ }
101
+ isEntityReference() {
102
+ return false;
103
+ }
104
+ isEntityRelation() {
105
+ return true;
106
+ }
107
+ };
108
+ var GeoPoint = class {
109
+ /**
110
+ * The latitude of this GeoPoint instance.
111
+ */
112
+ latitude;
113
+ /**
114
+ * The longitude of this GeoPoint instance.
115
+ */
116
+ longitude;
117
+ constructor(latitude, longitude) {
118
+ this.latitude = latitude;
119
+ this.longitude = longitude;
120
+ }
121
+ };
122
+ var Vector = class {
123
+ value;
124
+ constructor(value) {
125
+ this.value = value;
126
+ }
127
+ };
128
+ //#endregion
129
+ //#region src/types/collections.ts
130
+ /**
131
+ * Type guard for PostgreSQL collections.
132
+ * Returns true if the collection uses the Postgres driver (or the default driver).
133
+ * @group Models
134
+ */
135
+ function isPostgresCollection(collection) {
136
+ return !collection.driver || collection.driver === "postgres";
137
+ }
138
+ /**
139
+ * Type guard for Firebase / Firestore collections.
140
+ * @group Models
141
+ */
142
+ function isFirebaseCollection(collection) {
143
+ return collection.driver === "firestore";
144
+ }
145
+ /**
146
+ * Type guard for MongoDB collections.
147
+ * @group Models
148
+ */
149
+ function isMongoDBCollection(collection) {
150
+ return collection.driver === "mongodb";
151
+ }
152
+ //#endregion
153
+ //#region src/types/backend.ts
154
+ /**
155
+ * Type guard: does this admin support SQL operations?
156
+ * @group Admin
157
+ */
158
+ function isSQLAdmin(admin) {
159
+ return !!admin && typeof admin.executeSql === "function";
160
+ }
161
+ /**
162
+ * Type guard: does this admin support document operations?
163
+ * @group Admin
164
+ */
165
+ function isDocumentAdmin(admin) {
166
+ return !!admin && (typeof admin.executeAggregate === "function" || typeof admin.fetchCollectionStats === "function");
167
+ }
168
+ /**
169
+ * Type guard: does this admin support schema management?
170
+ * @group Admin
171
+ */
172
+ function isSchemaAdmin(admin) {
173
+ return !!admin && (typeof admin.fetchUnmappedTables === "function" || typeof admin.fetchTableMetadata === "function");
174
+ }
175
+ /**
176
+ * Type guard: does this admin support database branching?
177
+ * @group Admin
178
+ */
179
+ function isBranchAdmin(admin) {
180
+ return !!admin && typeof admin.createBranch === "function";
181
+ }
182
+ //#endregion
183
+ //#region src/types/data_source.ts
184
+ /** @group Models */
185
+ var POSTGRES_CAPABILITIES = {
186
+ key: "postgres",
187
+ label: "PostgreSQL",
188
+ supportsRelations: true,
189
+ supportsSubcollections: false,
190
+ supportsRLS: true,
191
+ supportsReferences: false,
192
+ supportsColumnTypes: true,
193
+ supportsRealtime: true,
194
+ supportsSQLAdmin: true,
195
+ supportsDocumentAdmin: false,
196
+ supportsSchemaAdmin: true
197
+ };
198
+ /** @group Models */
199
+ var FIREBASE_CAPABILITIES = {
200
+ key: "firestore",
201
+ label: "Firebase / Firestore",
202
+ supportsRelations: false,
203
+ supportsSubcollections: true,
204
+ supportsRLS: false,
205
+ supportsReferences: true,
206
+ supportsColumnTypes: false,
207
+ supportsRealtime: true,
208
+ supportsSQLAdmin: false,
209
+ supportsDocumentAdmin: false,
210
+ supportsSchemaAdmin: false
211
+ };
212
+ /** @group Models */
213
+ var MONGODB_CAPABILITIES = {
214
+ key: "mongodb",
215
+ label: "MongoDB",
216
+ supportsRelations: false,
217
+ supportsSubcollections: true,
218
+ supportsRLS: false,
219
+ supportsReferences: true,
220
+ supportsColumnTypes: false,
221
+ supportsRealtime: false,
222
+ supportsSQLAdmin: false,
223
+ supportsDocumentAdmin: true,
224
+ supportsSchemaAdmin: true
225
+ };
226
+ /**
227
+ * Fallback capabilities when the driver is unknown.
228
+ * Enables everything so nothing is hidden unexpectedly.
229
+ * @group Models
230
+ */
231
+ var DEFAULT_CAPABILITIES = {
232
+ key: "(default)",
233
+ label: "Default",
234
+ supportsRelations: true,
235
+ supportsSubcollections: true,
236
+ supportsRLS: true,
237
+ supportsReferences: true,
238
+ supportsColumnTypes: true,
239
+ supportsRealtime: true,
240
+ supportsSQLAdmin: true,
241
+ supportsDocumentAdmin: true,
242
+ supportsSchemaAdmin: true
243
+ };
244
+ var CAPABILITIES_REGISTRY = {
245
+ postgres: POSTGRES_CAPABILITIES,
246
+ firestore: FIREBASE_CAPABILITIES,
247
+ mongodb: MONGODB_CAPABILITIES,
248
+ "(default)": DEFAULT_CAPABILITIES
249
+ };
250
+ /**
251
+ * Look up capabilities for a given driver key.
252
+ * If `driver` is undefined or not found, returns `DEFAULT_CAPABILITIES`.
253
+ * @group Models
254
+ */
255
+ function getDataSourceCapabilities(driver) {
256
+ if (!driver) return POSTGRES_CAPABILITIES;
257
+ return CAPABILITIES_REGISTRY[driver] ?? DEFAULT_CAPABILITIES;
258
+ }
259
+ /**
260
+ * Register custom capabilities for a third-party driver.
261
+ * @group Models
262
+ */
263
+ function registerDataSourceCapabilities(capabilities) {
264
+ CAPABILITIES_REGISTRY[capabilities.key] = capabilities;
265
+ }
266
+ //#endregion
267
+ //#region src/types/component_ref.ts
268
+ /**
269
+ * Type guard: checks if a value is a `LazyComponentRef` produced by the
270
+ * Vite transform plugin.
271
+ */
272
+ function isLazyComponentRef(ref) {
273
+ return typeof ref === "object" && ref !== null && "__rebaseLazy" in ref && ref.__rebaseLazy === true;
274
+ }
275
+ //#endregion
276
+ exports.DEFAULT_CAPABILITIES = DEFAULT_CAPABILITIES;
277
+ exports.EntityReference = EntityReference;
278
+ exports.EntityRelation = EntityRelation;
279
+ exports.FIREBASE_CAPABILITIES = FIREBASE_CAPABILITIES;
280
+ exports.GeoPoint = GeoPoint;
281
+ exports.MONGODB_CAPABILITIES = MONGODB_CAPABILITIES;
282
+ exports.POSTGRES_CAPABILITIES = POSTGRES_CAPABILITIES;
283
+ exports.Vector = Vector;
284
+ exports.getDataSourceCapabilities = getDataSourceCapabilities;
285
+ exports.isBranchAdmin = isBranchAdmin;
286
+ exports.isDocumentAdmin = isDocumentAdmin;
287
+ exports.isFirebaseCollection = isFirebaseCollection;
288
+ exports.isLazyComponentRef = isLazyComponentRef;
289
+ exports.isMongoDBCollection = isMongoDBCollection;
290
+ exports.isPostgresCollection = isPostgresCollection;
291
+ exports.isSQLAdmin = isSQLAdmin;
292
+ exports.isSchemaAdmin = isSchemaAdmin;
293
+ exports.registerDataSourceCapabilities = registerDataSourceCapabilities;
225
294
  });
226
- //# sourceMappingURL=index.umd.js.map
295
+
296
+ //# sourceMappingURL=index.umd.js.map