@rebasepro/types 0.26.0 → 0.28.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.
@@ -70,9 +70,22 @@ export interface AuthClient {
70
70
  */
71
71
  getUser(): Promise<User | null>;
72
72
  /**
73
- * Get the currently active session
73
+ * The session as it is now, or `null`.
74
+ *
75
+ * A snapshot: renewing the access token (about hourly) replaces the
76
+ * session with a new object, so one kept from an earlier call carries a
77
+ * token the server refuses once it expires. Read it when you need it, and
78
+ * use {@link getAccessToken} for a token to send.
74
79
  */
75
80
  getSession(): RebaseSession | null;
81
+ /**
82
+ * The access token to send on a request of your own, renewed first when
83
+ * it has expired or is about to; `null` when no one is signed in.
84
+ *
85
+ * Optional so that alternative {@link AuthClient} implementations need not
86
+ * supply it.
87
+ */
88
+ getAccessToken?: () => Promise<string | null>;
76
89
  /**
77
90
  * Get the current user's active sessions
78
91
  */
@@ -95,9 +108,9 @@ export interface AuthClient {
95
108
  * Whether a session could exist that this client has not loaded yet.
96
109
  *
97
110
  * `false` means the only way this client can hold a session is an explicit
98
- * sign-in during this page's lifetime: it neither persists sessions nor
99
- * carries an httpOnly auth cookie, so there is nothing on disk or in the
100
- * browser to restore from. A caller that would otherwise probe the server
111
+ * sign-in during this page's lifetime: it does not persist sessions
112
+ * (`persistSession: false`), so it restores none on load, from storage or,
113
+ * in cookie mode, from the httpOnly auth cookie. A caller that would otherwise probe the server
101
114
  * — `getUser()` on mount, say — can skip it, because the answer is already
102
115
  * known and the request can only ever fail.
103
116
  *
@@ -162,6 +175,38 @@ export interface PickedUser {
162
175
  displayName: string | null;
163
176
  photoURL: string | null;
164
177
  }
178
+ /**
179
+ * A guest as `GET /admin/guests` lists one: a row anonymous sign-in made, that
180
+ * has not become an account.
181
+ *
182
+ * @group Admin
183
+ */
184
+ export interface AdminGuest {
185
+ uid: string;
186
+ createdAt: string;
187
+ /**
188
+ * The last time this guest's session was issued or refreshed: `createdAt`
189
+ * for one that has no refresh token left.
190
+ */
191
+ lastSeenAt: string;
192
+ }
193
+ /**
194
+ * One batch of `DELETE /admin/guests`. Repeat the call while `remaining` is not
195
+ * 0, passing how many have been skipped so far as `offset`.
196
+ *
197
+ * @group Admin
198
+ */
199
+ export interface DeleteGuestsResult {
200
+ deleted: number;
201
+ /** The guests left in place, and why: a `beforeUserDelete` veto, a row of the project's own that requires them. */
202
+ skipped: Array<{
203
+ uid: string;
204
+ code: string;
205
+ message: string;
206
+ }>;
207
+ /** How many matching guests this batch did not reach. */
208
+ remaining: number;
209
+ }
165
210
  /**
166
211
  * Client-side Admin API interface.
167
212
  * Provides user management operations.
@@ -520,7 +565,7 @@ export interface RebaseClient<DB = unknown> {
520
565
  * call through it is refused with `403 SIMULATION_READ_ONLY`, since it
521
566
  * would run as the simulated identity rather than the administrator.
522
567
  */
523
- simulate?(simulation: AccessSimulation): RebaseClient<Record<string, unknown>>;
568
+ simulate?(simulation: AccessSimulation): RebaseClient<DB>;
524
569
  /**
525
570
  * POST to an arbitrary path on the backend — the escape hatch, not the way
526
571
  * to call a function.
@@ -611,6 +656,12 @@ export interface RebaseServerClient<DB = RegisteredDatabase> extends Omit<Rebase
611
656
  * `rebase.dataAsAdmin` go over the same wire wherever they run. A function
612
657
  * that genuinely needs raw SQL can ask `runtimeKey()` and degrade, rather
613
658
  * than discovering it at the call.
659
+ *
660
+ * It is not for making tables. An application table is a collection in
661
+ * `config/collections/`, created by boot with its validation, callbacks,
662
+ * security rules, admin view and SDK type; a `CREATE TABLE`, `ALTER TABLE`,
663
+ * `DROP TABLE` or `CREATE INDEX` run here gets none of those. Such a
664
+ * statement still runs, and logs a warning naming the collection to declare.
614
665
  */
615
666
  sql(query: string, options?: {
616
667
  database?: ResourceRef;
@@ -179,6 +179,70 @@ export declare interface DownloadMetadata {
179
179
  */
180
180
  public?: boolean;
181
181
  }
182
+ /**
183
+ * What serving an object needs to know before deciding whether to read it.
184
+ * See {@link StorageSource.statObject}.
185
+ *
186
+ * @group Models
187
+ */
188
+ export interface StoredObjectInfo {
189
+ /** The whole object's size in bytes. */
190
+ size: number;
191
+ /** The stored content type — the uploader's claim, not a sniffed one. */
192
+ contentType: string;
193
+ /**
194
+ * The object's own modification time, in milliseconds since the epoch.
195
+ * The routes build `ETag`, `Last-Modified` and the transform cache key from
196
+ * it, so it must be the object's version, not the time of the read.
197
+ */
198
+ lastModified: number;
199
+ }
200
+ /**
201
+ * An inclusive byte range, as `Range: bytes=start-end` names one.
202
+ *
203
+ * @group Models
204
+ */
205
+ export interface StoredObjectRange {
206
+ start: number;
207
+ end: number;
208
+ }
209
+ /**
210
+ * An object's bytes as a stream. See {@link StorageSource.getObjectStream}.
211
+ *
212
+ * @group Models
213
+ */
214
+ export interface StoredObjectStream extends StoredObjectInfo {
215
+ /** The bytes: the range when {@link range} is set, the whole object otherwise. */
216
+ stream: ReadableStream<Uint8Array>;
217
+ /**
218
+ * The range {@link stream} holds — the one asked for — or absent when it
219
+ * holds the whole object. A controller may answer a range with the whole
220
+ * object, as HTTP lets a server do; the caller then serves it whole.
221
+ */
222
+ range?: StoredObjectRange;
223
+ }
224
+ /**
225
+ * A write of bytes whose length is not known yet. See
226
+ * {@link StorageSource.putObjectStream}.
227
+ *
228
+ * @group Models
229
+ */
230
+ export interface PutObjectStreamProps {
231
+ /** Read once, to its end. A controller cannot retry a stream it has consumed. */
232
+ stream: ReadableStream<Uint8Array>;
233
+ key: string;
234
+ contentType?: string;
235
+ bucket?: string;
236
+ /** Refuse the write once the stream passes this many bytes. */
237
+ maxBytes?: number;
238
+ }
239
+ /**
240
+ * @group Models
241
+ */
242
+ export interface PutObjectStreamResult extends UploadFileResult {
243
+ /** How many bytes were written. */
244
+ size: number;
245
+ }
182
246
  /**
183
247
  * @group Models
184
248
  */
@@ -204,6 +268,32 @@ export interface StorageSource {
204
268
  * @param bucket
205
269
  */
206
270
  getObject: (key: string, bucket?: string) => Promise<File | null>;
271
+ /**
272
+ * Describe an object without reading its bytes, or `null` when there is no
273
+ * such object. Server-side storage only.
274
+ */
275
+ statObject?: (key: string, bucket?: string) => Promise<StoredObjectInfo | null>;
276
+ /**
277
+ * Read an object, or one byte range of it, as a stream, or `null` when
278
+ * there is no such object. Server-side storage only.
279
+ *
280
+ * The stream holds a file or a connection until it is read to the end or
281
+ * cancelled, so a caller that decides not to read it must cancel it.
282
+ */
283
+ getObjectStream?: (key: string, options?: {
284
+ bucket?: string;
285
+ range?: StoredObjectRange;
286
+ }) => Promise<StoredObjectStream | null>;
287
+ /**
288
+ * Write an object from a stream, holding a chunk at a time however large it
289
+ * is. Server-side storage only.
290
+ *
291
+ * Rejects with `ObjectTooLargeError` past `maxBytes`, and on that or any
292
+ * other failure leaves no object at the key. The controller's upload limits
293
+ * do not apply: this is how the server stores something of its own, and
294
+ * `maxBytes` is its limit.
295
+ */
296
+ putObjectStream?: (props: PutObjectStreamProps) => Promise<PutObjectStreamResult>;
207
297
  /**
208
298
  * Delete an object.
209
299
  * @param key
@@ -221,6 +311,28 @@ export interface StorageSource {
221
311
  pageToken?: string;
222
312
  }) => Promise<StorageListResult>;
223
313
  }
314
+ /**
315
+ * What the SDK's `putObject` takes. The server's controllers need a key; the
316
+ * SDK does not: with none, the server names the object after the uploaded
317
+ * file. And the SDK uploads any `Blob` — one that is not a `File` travels as a
318
+ * file called "blob".
319
+ *
320
+ * @group Models
321
+ */
322
+ export interface ClientUploadFileProps extends Omit<UploadFileProps, "key" | "file"> {
323
+ file: Blob;
324
+ key?: string;
325
+ }
326
+ /**
327
+ * The SDK's storage source (`client.storage`). A {@link StorageSource} whose
328
+ * upload takes {@link ClientUploadFileProps} — a wider argument, so it is
329
+ * still a `StorageSource` wherever one is asked for.
330
+ *
331
+ * @group Models
332
+ */
333
+ export interface ClientStorageSource extends Omit<StorageSource, "putObject"> {
334
+ putObject: (props: ClientUploadFileProps) => Promise<UploadFileResult>;
335
+ }
224
336
  /**
225
337
  * Result returned by list().
226
338
  * @public
package/dist/index.es.js CHANGED
@@ -884,6 +884,29 @@ function isManyToMany(relation) {
884
884
  function isToMany(relation) {
885
885
  return relation.cardinality === "many";
886
886
  }
887
+ /**
888
+ * The conditions of a join step, as a list: one entry for a plain step, one
889
+ * per alternative for a step that joins on any of several.
890
+ * @group Models
891
+ */
892
+ function joinConditions(step) {
893
+ return Array.isArray(step.on) ? step.on : [step.on];
894
+ }
895
+ /**
896
+ * The one condition of a step that has no alternatives — for the write paths,
897
+ * which only run on a writable chain and a chain with alternatives never is.
898
+ * Throws rather than pick one of several: writing a link into the wrong column
899
+ * is the mistake read-only exists to prevent.
900
+ * @group Models
901
+ */
902
+ function soleJoinCondition(step) {
903
+ if (Array.isArray(step.on)) {
904
+ if (step.on.length === 1) return step.on[0];
905
+ if (step.on.length === 0) throw new Error(`The join into '${step.table}' lists no conditions, so it joins nothing.`);
906
+ throw new Error(`The join into '${step.table}' matches any of ${step.on.length} conditions, so it is read-only: there is no one column to write a link into.`);
907
+ }
908
+ return step.on;
909
+ }
887
910
  //#endregion
888
911
  //#region src/types/policy.ts
889
912
  /**
@@ -1953,7 +1976,8 @@ amendResourceKind("bucket", {
1953
1976
  "publicRead",
1954
1977
  "prefix",
1955
1978
  "account",
1956
- "default"
1979
+ "default",
1980
+ "orphanSweep"
1957
1981
  ],
1958
1982
  envBases: [
1959
1983
  "STORAGE_TYPE",
@@ -2240,10 +2264,26 @@ function resourceToStorageSource(declaration) {
2240
2264
  transport: declaration.transport,
2241
2265
  ...typeof declaration.options.account === "string" ? { account: declaration.options.account } : {},
2242
2266
  ...declaration.options.default === true ? { default: true } : {},
2267
+ ...orphanSweepOf(declaration.options.orphanSweep),
2243
2268
  ...declaration.label !== void 0 ? { label: declaration.label } : {}
2244
2269
  };
2245
2270
  }
2246
2271
  /**
2272
+ * A bucket's `orphanSweep` option as a definition carries it: `true` is the
2273
+ * defaults, an object keeps only the fields of the right type. The runtime
2274
+ * checks the values (the grace-period floor, the schedule) and refuses a bad
2275
+ * one loudly; this only refuses to invent one.
2276
+ */
2277
+ function orphanSweepOf(option) {
2278
+ if (option === true) return { orphanSweep: {} };
2279
+ if (!option || typeof option !== "object") return {};
2280
+ const { olderThanHours, schedule } = option;
2281
+ return { orphanSweep: {
2282
+ ...typeof olderThanHours === "number" ? { olderThanHours } : {},
2283
+ ...typeof schedule === "string" ? { schedule } : {}
2284
+ } };
2285
+ }
2286
+ /**
2247
2287
  * The declared databases, as definitions.
2248
2288
  *
2249
2289
  * Both the frontend and a project's own backend entrypoint read this. The
@@ -3815,6 +3855,6 @@ function resolverFromSources(client) {
3815
3855
  };
3816
3856
  }
3817
3857
  //#endregion
3818
- export { ADMIN_COLLECTION_KEYS, ADMIN_PROPERTY_KEYS, ADMIN_ROLE, ADMIN_SCOPES, ALL_WHERE_FILTER_OPS, ANONYMOUS_USER_ID, ANONYMOUS_USER_IDS, BATCH_REF_KEY, BUILT_IN_SCOPES, BUILT_IN_SCOPE_DESCRIPTIONS, BUNDLE_FORMAT_VERSION, CANONICAL_TO_REST, DATA_PLANE_SCOPES, DEFAULT_CAPABILITIES, DEFAULT_COMMIT_PATHS, DEFAULT_DATA_SOURCE_KEY, DEFAULT_FILTERABLE_RELATION_KINDS, DEFAULT_FUZZY_THRESHOLD, DEFAULT_LIST_LIMIT, DEFAULT_RESOURCE_KEY, DEFAULT_SEARCH_COLUMN, DEFAULT_SEARCH_LANGUAGE, DEFAULT_SEARCH_MODE, DEFAULT_SEARCH_WEIGHT, DEFAULT_STORAGE_SOURCE_KEY, DEFAULT_TENANT_BYPASS_ROLES, DEFAULT_VECTOR_LIST_LIMIT, EMPTY_ACCESS_MODEL, EntityReference, EntityRelation, FIELD_OPERATORS, FIREBASE_CAPABILITIES, GeoPoint, IMPERSONATE_HEADER, INCLUDE_COUNT_KEY, JUNCTION_PIVOT_KEY, KEY_MANAGEMENT_SCOPES, LEGACY_RLS_JWT_SQL, LEGACY_RLS_ROLES_SQL, LEGACY_RLS_SCHEMA, LEGACY_RLS_UID_SQL, LIST_OPS, ListLimitError, MAX_INCLUDE_DEPTH, MAX_LIST_LIMIT, MONGODB_CAPABILITIES, NULL_OPS, POSTGRES_CAPABILITIES, PUBLIC_STORAGE_PREFIX, REBASE_SCHEMA, RELEVANCE_SORT_FIELD, RESERVED_BACKEND_PREFIXES, RESOURCE_GRAPH_VERSION, REST_TO_CANONICAL, RLS_IS_ANONYMOUS_SQL, RLS_JWT_SQL, RLS_ROLES_SQL, RLS_UID_SQL, RUNTIME_CONTRACT_VERSION, RUNTIME_ONLY_COLLECTION_KEYS, RebaseApiError, RebaseClientError, SCHEMA_VERSION_HEADER, SCOPE_TARGETS, SIMULATED_CONTEXT_HEADER, SIMULATE_API_KEY_ID_HEADER, SIMULATE_ROLE_HEADER, SIMULATE_USER_ID_HEADER, STORAGE_REFERENCE_SCHEME, Vector, amendResourceKind, applyCollectionPatch, bucket, buildResourceGraph, canonicalSchemaPayload, collectionPatchProblems, computeSchemaVersion, database, declareCron, declareFunction, declareResource, declaredDataSources, declaredDatabaseExtensions, declaredQueueConsumers, declaredResources, declaredStorageSources, declaredSubscriptions, describeScope, deserializeCollections, diffCollections, diffJsonValues, encodeRelationAggregateSort, envBasesForResource, findEnvSuffixCollision, findStorageSuffixCollision, formatSimulatedContext, getCollectionDataPath, getDataSourceCapabilities, getDeclaredSubcollections, hasAdminRole, hasFieldOperation, hasForeignKeyOnTarget, intersectScopes, isAdminScope, isAnonymousUid, isBranchAdmin, isBuiltInScope, isChannelBusInstance, isCollectionPatch, isContentHashedFileName, isDataPlaneScope, isDocumentAdmin, isFieldOperation, isFirebaseCollectionConfig, isLazyComponentRef, isManyToMany, isMongoDBCollectionConfig, isPostgresCollectionConfig, isPublicStorageKey, isPublicStoragePath, isRelationAggregateSort, isRelationalCollectionConfig, isResourceHandle, isSQLAdmin, isSchemaAdmin, isSchemaEditingAdmin, isSerializedCollectionRef, isStorageReference, isTenantClaimSource, isTenantMembershipSource, isToMany, isUnsupported, isValidAppHost, isValidEngine, knownScopes, nestAdminCollectionKeys, nestAdminKeysOf, nestAdminPropertyKeys, nestCollectionPatchPaths, parseAppAddress, parseEnvBoolean, parseRelationAggregateSort, parseScope, parseSimulatedContext, parseStorageReference, policy, queue, registerDataSourceCapabilities, registerResourceKind, reservedPrefixFor, resetDeclaredQueueConsumers, resetDeclaredResources, resetDeclaredSubscriptions, resolveClientListLimit, resolveResourceRefs, resolveStorageReferences, resourceEnvSuffix, resourceId, resourceKeyOf, resourceKind, resourceKinds, resourceToDataSource, resourceToStorageSource, rewriteLegacyRlsFunctions, roleNameProblem, runtimeOnlyKeyIn, scopeAcceptsTarget, scopeGrants, scopeGrantsAny, scopeTargets, scopesBeyond, scopesForRoles, serializeCollections, setQueueRuntime, setTopicRuntime, simulationHeaders, sortKeyToString, storageEnvSuffix, storageObjectPath, storageReference, storageReferencesForDownloadUrls, storageTargetOfDownloadUrl, storageTargetsInText, summarizeRoles, summarizeScopes, toCanonicalOp, toCollectionJson, topic, unsupportedMethod, usesLegacyRlsFunctions, validateScopes };
3858
+ export { ADMIN_COLLECTION_KEYS, ADMIN_PROPERTY_KEYS, ADMIN_ROLE, ADMIN_SCOPES, ALL_WHERE_FILTER_OPS, ANONYMOUS_USER_ID, ANONYMOUS_USER_IDS, BATCH_REF_KEY, BUILT_IN_SCOPES, BUILT_IN_SCOPE_DESCRIPTIONS, BUNDLE_FORMAT_VERSION, CANONICAL_TO_REST, DATA_PLANE_SCOPES, DEFAULT_CAPABILITIES, DEFAULT_COMMIT_PATHS, DEFAULT_DATA_SOURCE_KEY, DEFAULT_FILTERABLE_RELATION_KINDS, DEFAULT_FUZZY_THRESHOLD, DEFAULT_LIST_LIMIT, DEFAULT_RESOURCE_KEY, DEFAULT_SEARCH_COLUMN, DEFAULT_SEARCH_LANGUAGE, DEFAULT_SEARCH_MODE, DEFAULT_SEARCH_WEIGHT, DEFAULT_STORAGE_SOURCE_KEY, DEFAULT_TENANT_BYPASS_ROLES, DEFAULT_VECTOR_LIST_LIMIT, EMPTY_ACCESS_MODEL, EntityReference, EntityRelation, FIELD_OPERATORS, FIREBASE_CAPABILITIES, GeoPoint, IMPERSONATE_HEADER, INCLUDE_COUNT_KEY, JUNCTION_PIVOT_KEY, KEY_MANAGEMENT_SCOPES, LEGACY_RLS_JWT_SQL, LEGACY_RLS_ROLES_SQL, LEGACY_RLS_SCHEMA, LEGACY_RLS_UID_SQL, LIST_OPS, ListLimitError, MAX_INCLUDE_DEPTH, MAX_LIST_LIMIT, MONGODB_CAPABILITIES, NULL_OPS, POSTGRES_CAPABILITIES, PUBLIC_STORAGE_PREFIX, REBASE_SCHEMA, RELEVANCE_SORT_FIELD, RESERVED_BACKEND_PREFIXES, RESOURCE_GRAPH_VERSION, REST_TO_CANONICAL, RLS_IS_ANONYMOUS_SQL, RLS_JWT_SQL, RLS_ROLES_SQL, RLS_UID_SQL, RUNTIME_CONTRACT_VERSION, RUNTIME_ONLY_COLLECTION_KEYS, RebaseApiError, RebaseClientError, SCHEMA_VERSION_HEADER, SCOPE_TARGETS, SIMULATED_CONTEXT_HEADER, SIMULATE_API_KEY_ID_HEADER, SIMULATE_ROLE_HEADER, SIMULATE_USER_ID_HEADER, STORAGE_REFERENCE_SCHEME, Vector, amendResourceKind, applyCollectionPatch, bucket, buildResourceGraph, canonicalSchemaPayload, collectionPatchProblems, computeSchemaVersion, database, declareCron, declareFunction, declareResource, declaredDataSources, declaredDatabaseExtensions, declaredQueueConsumers, declaredResources, declaredStorageSources, declaredSubscriptions, describeScope, deserializeCollections, diffCollections, diffJsonValues, encodeRelationAggregateSort, envBasesForResource, findEnvSuffixCollision, findStorageSuffixCollision, formatSimulatedContext, getCollectionDataPath, getDataSourceCapabilities, getDeclaredSubcollections, hasAdminRole, hasFieldOperation, hasForeignKeyOnTarget, intersectScopes, isAdminScope, isAnonymousUid, isBranchAdmin, isBuiltInScope, isChannelBusInstance, isCollectionPatch, isContentHashedFileName, isDataPlaneScope, isDocumentAdmin, isFieldOperation, isFirebaseCollectionConfig, isLazyComponentRef, isManyToMany, isMongoDBCollectionConfig, isPostgresCollectionConfig, isPublicStorageKey, isPublicStoragePath, isRelationAggregateSort, isRelationalCollectionConfig, isResourceHandle, isSQLAdmin, isSchemaAdmin, isSchemaEditingAdmin, isSerializedCollectionRef, isStorageReference, isTenantClaimSource, isTenantMembershipSource, isToMany, isUnsupported, isValidAppHost, isValidEngine, joinConditions, knownScopes, nestAdminCollectionKeys, nestAdminKeysOf, nestAdminPropertyKeys, nestCollectionPatchPaths, parseAppAddress, parseEnvBoolean, parseRelationAggregateSort, parseScope, parseSimulatedContext, parseStorageReference, policy, queue, registerDataSourceCapabilities, registerResourceKind, reservedPrefixFor, resetDeclaredQueueConsumers, resetDeclaredResources, resetDeclaredSubscriptions, resolveClientListLimit, resolveResourceRefs, resolveStorageReferences, resourceEnvSuffix, resourceId, resourceKeyOf, resourceKind, resourceKinds, resourceToDataSource, resourceToStorageSource, rewriteLegacyRlsFunctions, roleNameProblem, runtimeOnlyKeyIn, scopeAcceptsTarget, scopeGrants, scopeGrantsAny, scopeTargets, scopesBeyond, scopesForRoles, serializeCollections, setQueueRuntime, setTopicRuntime, simulationHeaders, soleJoinCondition, sortKeyToString, storageEnvSuffix, storageObjectPath, storageReference, storageReferencesForDownloadUrls, storageTargetOfDownloadUrl, storageTargetsInText, summarizeRoles, summarizeScopes, toCanonicalOp, toCollectionJson, topic, unsupportedMethod, usesLegacyRlsFunctions, validateScopes };
3819
3859
 
3820
3860
  //# sourceMappingURL=index.es.js.map