@rebasepro/types 0.10.1-canary.ed8caed → 0.10.1-canary.gdaf6ba4

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.
@@ -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<string>;
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
- /** Relations to include in the response */
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>;
@@ -263,7 +269,7 @@ export interface SDKCollectionClient<M extends Record<string, unknown> = Record<
263
269
  /**
264
270
  * Find multiple records with optional filtering, pagination, and sorting.
265
271
  */
266
- find(params?: FindParams): Promise<FindResult<M>>;
272
+ find(params?: FindParams<M>): Promise<FindResult<M>>;
267
273
  /**
268
274
  * Find a single record by its ID.
269
275
  */
@@ -323,7 +329,7 @@ export interface SDKCollectionClient<M extends Record<string, unknown> = Record<
323
329
  /**
324
330
  * Subscribe to a collection for real-time updates.
325
331
  */
326
- listen?(params: FindParams | undefined, onUpdate: (response: FindResult<M>) => void, onError?: (error: Error) => void): () => void;
332
+ listen?(params: FindParams<M> | undefined, onUpdate: (response: FindResult<M>) => void, onError?: (error: Error) => void): () => void;
327
333
  /**
328
334
  * Subscribe to a single record for real-time updates.
329
335
  */
@@ -331,7 +337,7 @@ export interface SDKCollectionClient<M extends Record<string, unknown> = Record<
331
337
  /**
332
338
  * Count the number of records matching the given filter.
333
339
  */
334
- count?(params?: FindParams): Promise<number>;
340
+ count?(params?: FindParams<M>): Promise<number>;
335
341
  where<K extends keyof M & string>(column: K, operator: WhereFilterOp, value: WhereValue<M[K]>): SDKQueryBuilderInterface<M>;
336
342
  where(logicalCondition: LogicalCondition): SDKQueryBuilderInterface<M>;
337
343
  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