@rebasepro/types 0.12.1-canary.gf5f1d39 → 0.13.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.
@@ -83,6 +83,20 @@ export interface AuthClient {
83
83
  * Manually refresh the session token
84
84
  */
85
85
  refreshSession(): Promise<RebaseSession>;
86
+ /**
87
+ * Whether a session could exist that this client has not loaded yet.
88
+ *
89
+ * `false` means the only way this client can hold a session is an explicit
90
+ * sign-in during this page's lifetime: it neither persists sessions nor
91
+ * carries an httpOnly auth cookie, so there is nothing on disk or in the
92
+ * browser to restore from. A caller that would otherwise probe the server
93
+ * — `getUser()` on mount, say — can skip it, because the answer is already
94
+ * known and the request can only ever fail.
95
+ *
96
+ * Optional so that alternative {@link AuthClient} implementations need not
97
+ * supply it; treat a missing implementation as "unknown, go ahead and ask".
98
+ */
99
+ canRestoreSession?: () => boolean;
86
100
  }
87
101
  /**
88
102
  * User record as returned by the Admin API (`GET /admin/users`, etc.).
@@ -337,6 +351,16 @@ export interface RebaseClient<DB = unknown> {
337
351
  apiKeys?: ApiKeysAPI;
338
352
  /** Base HTTP URL of the backend server */
339
353
  baseUrl?: string;
354
+ /**
355
+ * The path every API route is mounted under, appended to {@link baseUrl}.
356
+ *
357
+ * `"/api"` unless the backend was configured with a different `basePath`
358
+ * and the client told to match. Exposed because code that builds a URL by
359
+ * hand — rather than going through the client's own methods — otherwise has
360
+ * to guess, and guessing `/api` is wrong for exactly the projects that set
361
+ * the option.
362
+ */
363
+ apiPath?: string;
340
364
  /** WebSocket client for realtime subscriptions */
341
365
  ws?: RebaseWebSocket;
342
366
  /** Set the auth token for subsequent requests */
@@ -366,19 +390,14 @@ export interface RebaseClient<DB = unknown> {
366
390
  * the admin-scoped {@link dataAsAdmin} accessor, raw {@link sql}, and the
367
391
  * {@link email} service are all present (non-optional).
368
392
  *
369
- * **Trust levels.** Both {@link dataAsAdmin} and the deprecated {@link data}
370
- * alias point at the same admin-scoped, **RLS-bypassing** driver. Prefer
371
- * `dataAsAdmin` so the privilege is explicit at every call site. For user-scoped
372
- * queries inside a request handler use the request-scoped driver
373
- * (`c.var.driver`) instead — never `dataAsAdmin`/`data`.
393
+ * **Trust levels.** {@link dataAsAdmin} is the admin-scoped, **RLS-bypassing**
394
+ * driver, and it is the only name for it here — the `data` alias that used to
395
+ * sit beside it is deliberately `Omit`ted from {@link RebaseClient} so the
396
+ * privilege has to be spelled out at every call site. For user-scoped queries
397
+ * inside a request handler use the request-scoped driver (`c.var.driver`)
398
+ * instead — never `dataAsAdmin`.
374
399
  */
375
- export interface RebaseServerClient<DB = unknown> extends RebaseClient<DB> {
376
- /**
377
- * @deprecated On the server, prefer {@link dataAsAdmin} for admin scope or
378
- * the request-scoped driver (`c.var.driver`) for user scope. This alias
379
- * points at the same admin-scoped, RLS-bypassing accessor as `dataAsAdmin`.
380
- */
381
- data: RebaseSdkData<DB>;
400
+ export interface RebaseServerClient<DB = unknown> extends Omit<RebaseClient<DB>, "data"> {
382
401
  /**
383
402
  * Admin-scoped, **RLS-bypassing** data accessor. Always present server-side.
384
403
  * See {@link RebaseClient.dataAsAdmin} for the full safety contract.
@@ -435,6 +454,16 @@ export interface RebaseBrowserClient<DB = unknown> {
435
454
  apiKeys?: ApiKeysAPI;
436
455
  /** Base HTTP URL of the backend server */
437
456
  baseUrl?: string;
457
+ /**
458
+ * The path every API route is mounted under, appended to {@link baseUrl}.
459
+ *
460
+ * `"/api"` unless the backend was configured with a different `basePath`
461
+ * and the client told to match. Exposed because code that builds a URL by
462
+ * hand — rather than going through the client's own methods — otherwise has
463
+ * to guess, and guessing `/api` is wrong for exactly the projects that set
464
+ * the option.
465
+ */
466
+ apiPath?: string;
438
467
  /** WebSocket client for realtime subscriptions */
439
468
  ws?: RebaseWebSocket;
440
469
  /** Set the auth token for subsequent requests */
@@ -1,6 +1,7 @@
1
1
  import type { EntityStatus, EntityValues } from "../types/entities";
2
2
  import type { CollectionConfig, FilterValues } from "../types/collections";
3
3
  import type { RebaseCallContext } from "../call_context";
4
+ import type { LogicalCondition } from "./data";
4
5
  /**
5
6
  * @internal
6
7
  */
@@ -68,6 +69,14 @@ export interface FetchCollectionProps<M extends Record<string, unknown> = Record
68
69
  path: string;
69
70
  collection?: CollectionConfig<M>;
70
71
  filter?: FilterValues<Extract<keyof M, string>>;
72
+ /**
73
+ * An `or(...)`/`and(...)` group, applied alongside `filter`.
74
+ *
75
+ * The REST layer parsed `?or=` into this and then had nowhere to put it, so
76
+ * the group was dropped and the read ran unfiltered — returning every row
77
+ * the caller's policies allowed rather than the ones they asked for.
78
+ */
79
+ logical?: LogicalCondition;
71
80
  limit?: number;
72
81
  offset?: number;
73
82
  startAfter?: unknown;
@@ -286,6 +295,8 @@ export interface RestFetchService {
286
295
  */
287
296
  fetchCollectionForRest(collectionPath: string, options?: {
288
297
  filter?: FilterValues<string>;
298
+ /** An `or(...)`/`and(...)` group, applied alongside `filter`. */
299
+ logical?: LogicalCondition;
289
300
  orderBy?: string;
290
301
  order?: "desc" | "asc";
291
302
  limit?: number;
package/dist/index.es.js CHANGED
@@ -222,7 +222,7 @@ var REST_TO_CANONICAL = {
222
222
  * Operators that test for null/not-null and therefore ignore their value.
223
223
  * Codecs normalize the value of these conditions to `null`.
224
224
  */
225
- var NULL_OPS = new Set(["is-null", "is-not-null"]);
225
+ var NULL_OPS = /* @__PURE__ */ new Set(["is-null", "is-not-null"]);
226
226
  /**
227
227
  * Every canonical operator, in a stable order. Useful for engine capability
228
228
  * declarations ({@link DataSourceCapabilities.filterOperators}) and for
@@ -313,6 +313,7 @@ var ADMIN_COLLECTION_KEYS = [
313
313
  "exportable",
314
314
  "filterPresets",
315
315
  "fixedFilter",
316
+ "form",
316
317
  "formAutoSave",
317
318
  "formView",
318
319
  "group",
@@ -375,10 +376,10 @@ var ADMIN_PROPERTY_KEYS = [
375
376
  "previewProperties",
376
377
  "readOnly",
377
378
  "sortable",
379
+ "span",
378
380
  "spreadChildren",
379
381
  "urlPreview",
380
- "widget",
381
- "widthPercentage"
382
+ "widget"
382
383
  ];
383
384
  //#endregion
384
385
  //#region src/types/data_source.ts
@@ -602,12 +603,46 @@ function isToMany(relation) {
602
603
  *
603
604
  * The consequence for policy authors is that **`auth.uid() IS NOT NULL` is a
604
605
  * tautology on the user path** — it is true for anonymous visitors too. Use
605
- * {@link policy.authenticated} (or `auth.uid() <> 'anonymous'`) to mean "signed
606
- * in", and {@link policy.serverContext} to mean "the trusted server context".
606
+ * {@link policy.authenticated} to mean "signed in", and
607
+ * {@link policy.serverContext} to mean "the trusted server context". Do not
608
+ * hand-write the comparison: see {@link ANONYMOUS_USER_IDS} for why one
609
+ * literal is not enough.
607
610
  *
608
611
  * @group Models
609
612
  */
610
613
  var ANONYMOUS_USER_ID = "anonymous";
614
+ /**
615
+ * Every uid that has ever meant "nobody is signed in" — newest first.
616
+ *
617
+ * There are two because there were two. The types, the policy compiler, the
618
+ * JavaScript evaluator and the linter were all built on
619
+ * {@link ANONYMOUS_USER_ID}, while the request path scoped unauthenticated
620
+ * callers as `'anon'` — so `policy.authenticated()`, which compiled to
621
+ * `auth.uid() <> 'anonymous'`, was *true* for an anonymous visitor. The
622
+ * sanctioned way to write "signed in" granted to everyone, and the linter
623
+ * flagged the spelling that actually worked as a foreign convention.
624
+ *
625
+ * The request path now reports {@link ANONYMOUS_USER_ID}. `'anon'` stays here
626
+ * because policies outlive the server that generated them: a database still
627
+ * holding policies from before the fix, or a project whose server has not been
628
+ * upgraded yet, must not become a grant in either direction. Compile against
629
+ * this list, not against a single literal.
630
+ *
631
+ * No real user id is ever one of these, so a match is always "not signed in".
632
+ *
633
+ * @group Models
634
+ */
635
+ var ANONYMOUS_USER_IDS = [ANONYMOUS_USER_ID, "anon"];
636
+ /**
637
+ * Whether a uid stands for "no one is signed in", in any spelling rebase has
638
+ * used. `null`/`undefined` is the trusted server context, not an anonymous
639
+ * caller, and is therefore **not** anonymous — see {@link ANONYMOUS_USER_ID}.
640
+ *
641
+ * @group Models
642
+ */
643
+ function isAnonymousUid(uid) {
644
+ return typeof uid === "string" && ANONYMOUS_USER_IDS.includes(uid);
645
+ }
611
646
  /** @group Models */
612
647
  var policy = {
613
648
  true: () => ({ kind: "true" }),
@@ -1145,6 +1180,6 @@ function isPublicStoragePath(path) {
1145
1180
  return p.startsWith("public/") || p.startsWith(`default/public/`);
1146
1181
  }
1147
1182
  //#endregion
1148
- export { ADMIN_COLLECTION_KEYS, ADMIN_PROPERTY_KEYS, ALL_WHERE_FILTER_OPS, ANONYMOUS_USER_ID, BUNDLE_FORMAT_VERSION, CANONICAL_TO_REST, DEFAULT_CAPABILITIES, DEFAULT_DATA_SOURCE_KEY, DEFAULT_FILTERABLE_RELATION_KINDS, 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, findStorageSuffixCollision, getCollectionDataPath, getDataSourceCapabilities, getDeclaredSubcollections, hasForeignKeyOnTarget, isBranchAdmin, isChannelBusInstance, isDocumentAdmin, isFirebaseCollectionConfig, isLazyComponentRef, isManyToMany, isMongoDBCollectionConfig, isPostgresCollectionConfig, isPublicStoragePath, isRelationalCollectionConfig, isSQLAdmin, isSchemaAdmin, isSerializedCollectionRef, isToMany, normalizeStorageSources, policy, registerDataSourceCapabilities, resolveClientListLimit, serializeCollections, storageEnvSuffix, toCanonicalOp };
1183
+ export { ADMIN_COLLECTION_KEYS, ADMIN_PROPERTY_KEYS, ALL_WHERE_FILTER_OPS, ANONYMOUS_USER_ID, ANONYMOUS_USER_IDS, BUNDLE_FORMAT_VERSION, CANONICAL_TO_REST, DEFAULT_CAPABILITIES, DEFAULT_DATA_SOURCE_KEY, DEFAULT_FILTERABLE_RELATION_KINDS, 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, findStorageSuffixCollision, getCollectionDataPath, getDataSourceCapabilities, getDeclaredSubcollections, hasForeignKeyOnTarget, isAnonymousUid, isBranchAdmin, isChannelBusInstance, isDocumentAdmin, isFirebaseCollectionConfig, isLazyComponentRef, isManyToMany, isMongoDBCollectionConfig, isPostgresCollectionConfig, isPublicStoragePath, isRelationalCollectionConfig, isSQLAdmin, isSchemaAdmin, isSerializedCollectionRef, isToMany, normalizeStorageSources, policy, registerDataSourceCapabilities, resolveClientListLimit, serializeCollections, storageEnvSuffix, toCanonicalOp };
1149
1184
 
1150
1185
  //# sourceMappingURL=index.es.js.map