@rebasepro/types 0.10.1-canary.ff9ccd6 → 0.10.1-canary.g4db1bb1
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/controllers/data.d.ts +38 -12
- package/dist/index.es.js +15 -1
- package/dist/index.es.js.map +1 -1
- package/dist/types/backend.d.ts +23 -0
- package/dist/types/collections.d.ts +78 -0
- package/dist/types/filter-operators.d.ts +18 -0
- package/dist/types/properties.d.ts +26 -74
- package/dist/types/relations.d.ts +232 -248
- package/package.json +1 -1
- package/src/controllers/data.ts +39 -12
- package/src/types/backend.ts +24 -0
- package/src/types/collections.ts +84 -0
- package/src/types/filter-operators.ts +21 -0
- package/src/types/properties.ts +25 -91
- package/src/types/relations.ts +265 -250
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Entity, EntityValues } from "../types/entities";
|
|
2
|
-
import { WhereFilterOp, FilterValues, OrderByTuple } from "../types/filter-operators";
|
|
2
|
+
import { WhereFilterOp, FieldPath, FilterValues, OrderByTuple } from "../types/filter-operators";
|
|
3
3
|
export type WhereValue<T> = T | T[] | null;
|
|
4
4
|
export interface LogicalCondition {
|
|
5
5
|
type: "and" | "or";
|
|
@@ -39,7 +39,7 @@ export interface FilterCondition {
|
|
|
39
39
|
*
|
|
40
40
|
* @group Data
|
|
41
41
|
*/
|
|
42
|
-
export interface FindParams {
|
|
42
|
+
export interface FindParams<M extends Record<string, unknown> = Record<string, unknown>> {
|
|
43
43
|
/** Maximum number of items to return (default: 20). */
|
|
44
44
|
limit?: number;
|
|
45
45
|
/**
|
|
@@ -65,7 +65,7 @@ export interface FindParams {
|
|
|
65
65
|
* { role: ["in", ["admin", "editor"]] }
|
|
66
66
|
* { age: [[">=", 18], ["<", 65]] }
|
|
67
67
|
*/
|
|
68
|
-
where?: FilterValues<
|
|
68
|
+
where?: FilterValues<FieldPath<M>>;
|
|
69
69
|
/**
|
|
70
70
|
* Logical grouping conditions (AND/OR). Use this for anything `where`
|
|
71
71
|
* can't express — notably OR-ing conditions. AND-ed with `where` and
|
|
@@ -76,8 +76,14 @@ export interface FindParams {
|
|
|
76
76
|
* Sort order as a `[field, direction]` tuple.
|
|
77
77
|
* @example orderBy: ["created_at", "desc"]
|
|
78
78
|
*/
|
|
79
|
-
orderBy?: OrderByTuple
|
|
80
|
-
/**
|
|
79
|
+
orderBy?: OrderByTuple<FieldPath<M>>;
|
|
80
|
+
/**
|
|
81
|
+
* Relations to include in the response.
|
|
82
|
+
*
|
|
83
|
+
* Deliberately `string[]` and not checked against `M`: a relation name
|
|
84
|
+
* comes from the collection's `relations`, not from its columns, so nothing
|
|
85
|
+
* in a generated row type can validate one.
|
|
86
|
+
*/
|
|
81
87
|
include?: string[];
|
|
82
88
|
/**
|
|
83
89
|
* Full-text search string. Matched (OR-ed) across the collection's
|
|
@@ -137,7 +143,7 @@ export interface CollectionAccessor<M extends Record<string, unknown> = Record<s
|
|
|
137
143
|
/**
|
|
138
144
|
* Find multiple records with optional filtering, pagination, and sorting.
|
|
139
145
|
*/
|
|
140
|
-
find(params?: FindParams): Promise<FindResponse<M>>;
|
|
146
|
+
find(params?: FindParams<M>): Promise<FindResponse<M>>;
|
|
141
147
|
/**
|
|
142
148
|
* Find a single record by its ID.
|
|
143
149
|
*/
|
|
@@ -171,7 +177,7 @@ export interface CollectionAccessor<M extends Record<string, unknown> = Record<s
|
|
|
171
177
|
* Subscribe to a collection for real-time updates.
|
|
172
178
|
* Optional method, may not be supported by all implementations (like stateless HTTP clients).
|
|
173
179
|
*/
|
|
174
|
-
listen?(params: FindParams | undefined, onUpdate: (response: FindResponse<M>) => void, onError?: (error: Error) => void): () => void;
|
|
180
|
+
listen?(params: FindParams<M> | undefined, onUpdate: (response: FindResponse<M>) => void, onError?: (error: Error) => void): () => void;
|
|
175
181
|
/**
|
|
176
182
|
* Subscribe to a single record for real-time updates.
|
|
177
183
|
* Optional method.
|
|
@@ -180,7 +186,7 @@ export interface CollectionAccessor<M extends Record<string, unknown> = Record<s
|
|
|
180
186
|
/**
|
|
181
187
|
* Count the number of records matching the given filter.
|
|
182
188
|
*/
|
|
183
|
-
count?(params?: FindParams): Promise<number>;
|
|
189
|
+
count?(params?: FindParams<M>): Promise<number>;
|
|
184
190
|
where<K extends keyof M & string>(column: K, operator: WhereFilterOp, value: WhereValue<M[K]>): QueryBuilderInterface<M>;
|
|
185
191
|
where(logicalCondition: LogicalCondition): QueryBuilderInterface<M>;
|
|
186
192
|
orderBy(column: keyof M & string, direction?: "asc" | "desc"): QueryBuilderInterface<M>;
|
|
@@ -259,11 +265,31 @@ export interface SDKQueryBuilderInterface<M extends Record<string, unknown> = Re
|
|
|
259
265
|
*
|
|
260
266
|
* @group Data
|
|
261
267
|
*/
|
|
268
|
+
/**
|
|
269
|
+
* Per-request options for a write.
|
|
270
|
+
* @group Data
|
|
271
|
+
*/
|
|
272
|
+
export interface WriteOptions {
|
|
273
|
+
/**
|
|
274
|
+
* Names this write, so re-sending it is recognised instead of repeated.
|
|
275
|
+
*
|
|
276
|
+
* A client that does not see a response cannot know whether the write
|
|
277
|
+
* committed. Retrying is therefore the only option, and without a key the
|
|
278
|
+
* server has no way to tell a retry from a second, genuinely new write — so
|
|
279
|
+
* it performs it again. On a table with a server-assigned id that is a
|
|
280
|
+
* duplicate row, because the id the client chose was never used.
|
|
281
|
+
*
|
|
282
|
+
* Set by the offline queue on every replay. Honoured for 24 hours and scoped
|
|
283
|
+
* to the authenticated user; a server that cannot store keys ignores it
|
|
284
|
+
* rather than refusing the write.
|
|
285
|
+
*/
|
|
286
|
+
idempotencyKey?: string;
|
|
287
|
+
}
|
|
262
288
|
export interface SDKCollectionClient<M extends Record<string, unknown> = Record<string, unknown>, I = Partial<M>, U = Partial<M>> {
|
|
263
289
|
/**
|
|
264
290
|
* Find multiple records with optional filtering, pagination, and sorting.
|
|
265
291
|
*/
|
|
266
|
-
find(params?: FindParams): Promise<FindResult<M>>;
|
|
292
|
+
find(params?: FindParams<M>): Promise<FindResult<M>>;
|
|
267
293
|
/**
|
|
268
294
|
* Find a single record by its ID.
|
|
269
295
|
*/
|
|
@@ -278,7 +304,7 @@ export interface SDKCollectionClient<M extends Record<string, unknown> = Record<
|
|
|
278
304
|
* columns.
|
|
279
305
|
* @returns The created row
|
|
280
306
|
*/
|
|
281
|
-
create(data: I, id?: string | number): Promise<M>;
|
|
307
|
+
create(data: I, id?: string | number, options?: WriteOptions): Promise<M>;
|
|
282
308
|
/**
|
|
283
309
|
* Write many records in a single request and a single transaction.
|
|
284
310
|
*
|
|
@@ -323,7 +349,7 @@ export interface SDKCollectionClient<M extends Record<string, unknown> = Record<
|
|
|
323
349
|
/**
|
|
324
350
|
* Subscribe to a collection for real-time updates.
|
|
325
351
|
*/
|
|
326
|
-
listen?(params: FindParams | undefined, onUpdate: (response: FindResult<M>) => void, onError?: (error: Error) => void): () => void;
|
|
352
|
+
listen?(params: FindParams<M> | undefined, onUpdate: (response: FindResult<M>) => void, onError?: (error: Error) => void): () => void;
|
|
327
353
|
/**
|
|
328
354
|
* Subscribe to a single record for real-time updates.
|
|
329
355
|
*/
|
|
@@ -331,7 +357,7 @@ export interface SDKCollectionClient<M extends Record<string, unknown> = Record<
|
|
|
331
357
|
/**
|
|
332
358
|
* Count the number of records matching the given filter.
|
|
333
359
|
*/
|
|
334
|
-
count?(params?: FindParams): Promise<number>;
|
|
360
|
+
count?(params?: FindParams<M>): Promise<number>;
|
|
335
361
|
where<K extends keyof M & string>(column: K, operator: WhereFilterOp, value: WhereValue<M[K]>): SDKQueryBuilderInterface<M>;
|
|
336
362
|
where(logicalCondition: LogicalCondition): SDKQueryBuilderInterface<M>;
|
|
337
363
|
orderBy(column: keyof M & string, direction?: "asc" | "desc"): SDKQueryBuilderInterface<M>;
|
package/dist/index.es.js
CHANGED
|
@@ -391,6 +391,20 @@ function getDeclaredSubcollections(collection) {
|
|
|
391
391
|
return collection.subcollections;
|
|
392
392
|
}
|
|
393
393
|
//#endregion
|
|
394
|
+
//#region src/types/relations.ts
|
|
395
|
+
/** @group Models */
|
|
396
|
+
function hasForeignKeyOnTarget(relation) {
|
|
397
|
+
return relation.kind === "hasOne" || relation.kind === "hasMany";
|
|
398
|
+
}
|
|
399
|
+
/** @group Models */
|
|
400
|
+
function isManyToMany(relation) {
|
|
401
|
+
return relation.kind === "manyToMany";
|
|
402
|
+
}
|
|
403
|
+
/** @group Models */
|
|
404
|
+
function isToMany(relation) {
|
|
405
|
+
return relation.cardinality === "many";
|
|
406
|
+
}
|
|
407
|
+
//#endregion
|
|
394
408
|
//#region src/types/policy.ts
|
|
395
409
|
/**
|
|
396
410
|
* The id a request without a logged-in user reports as `auth.uid()`.
|
|
@@ -941,6 +955,6 @@ function isPublicStoragePath(path) {
|
|
|
941
955
|
return p.startsWith("public/") || p.startsWith(`default/public/`);
|
|
942
956
|
}
|
|
943
957
|
//#endregion
|
|
944
|
-
export { ADMIN_COLLECTION_KEYS, ALL_WHERE_FILTER_OPS, ANONYMOUS_USER_ID, BUNDLE_FORMAT_VERSION, CANONICAL_TO_REST, DEFAULT_CAPABILITIES, DEFAULT_DATA_SOURCE_KEY, DEFAULT_LIST_LIMIT, DEFAULT_STORAGE_SOURCE_KEY, DEFAULT_VECTOR_LIST_LIMIT, EntityReference, EntityRelation, FIREBASE_CAPABILITIES, GeoPoint, MAX_LIST_LIMIT, MONGODB_CAPABILITIES, NULL_OPS, POSTGRES_CAPABILITIES, PUBLIC_STORAGE_PREFIX, REST_TO_CANONICAL, RUNTIME_CONTRACT_VERSION, RebaseApiError, RebaseClientError, SCHEMA_VERSION_HEADER, Vector, canonicalSchemaPayload, computeSchemaVersion, deserializeCollections, getCollectionDataPath, getDataSourceCapabilities, getDeclaredSubcollections, isBranchAdmin, isChannelBusInstance, isDocumentAdmin, isFirebaseCollectionConfig, isLazyComponentRef, isMongoDBCollectionConfig, isPostgresCollectionConfig, isPublicStoragePath, isSQLAdmin, isSchemaAdmin, isSerializedCollectionRef, policy, registerDataSourceCapabilities, resolveClientListLimit, serializeCollections, toCanonicalOp };
|
|
958
|
+
export { ADMIN_COLLECTION_KEYS, ALL_WHERE_FILTER_OPS, ANONYMOUS_USER_ID, BUNDLE_FORMAT_VERSION, CANONICAL_TO_REST, DEFAULT_CAPABILITIES, DEFAULT_DATA_SOURCE_KEY, DEFAULT_LIST_LIMIT, DEFAULT_STORAGE_SOURCE_KEY, DEFAULT_VECTOR_LIST_LIMIT, EntityReference, EntityRelation, FIREBASE_CAPABILITIES, GeoPoint, MAX_LIST_LIMIT, MONGODB_CAPABILITIES, NULL_OPS, POSTGRES_CAPABILITIES, PUBLIC_STORAGE_PREFIX, REST_TO_CANONICAL, RUNTIME_CONTRACT_VERSION, RebaseApiError, RebaseClientError, SCHEMA_VERSION_HEADER, Vector, canonicalSchemaPayload, computeSchemaVersion, deserializeCollections, getCollectionDataPath, getDataSourceCapabilities, getDeclaredSubcollections, hasForeignKeyOnTarget, isBranchAdmin, isChannelBusInstance, isDocumentAdmin, isFirebaseCollectionConfig, isLazyComponentRef, isManyToMany, isMongoDBCollectionConfig, isPostgresCollectionConfig, isPublicStoragePath, isSQLAdmin, isSchemaAdmin, isSerializedCollectionRef, isToMany, policy, registerDataSourceCapabilities, resolveClientListLimit, serializeCollections, toCanonicalOp };
|
|
945
959
|
|
|
946
960
|
//# sourceMappingURL=index.es.js.map
|