@rebasepro/types 0.30.1 → 0.31.0-canary.g902a0ce
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/README.md +16 -18
- package/dist/call_context.d.ts +3 -3
- package/dist/controllers/client.d.ts +29 -0
- package/dist/controllers/data.d.ts +85 -332
- package/dist/controllers/data_driver.d.ts +47 -57
- package/dist/controllers/index.d.ts +0 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +2567 -1151
- package/dist/index.es.js.map +1 -1
- package/dist/schema/column_options.d.ts +336 -0
- package/dist/schema/column_type.d.ts +116 -0
- package/dist/schema/columns.d.ts +646 -0
- package/dist/schema/compiled.d.ts +114 -0
- package/dist/schema/descriptor.d.ts +349 -0
- package/dist/schema/hooks.d.ts +164 -0
- package/dist/schema/index.d.ts +13 -0
- package/dist/schema/infer.d.ts +340 -0
- package/dist/schema/json.d.ts +237 -0
- package/dist/schema/relations.d.ts +205 -0
- package/dist/schema/table.d.ts +304 -0
- package/dist/schema/table_options.d.ts +103 -0
- package/dist/schema/table_patch.d.ts +338 -0
- package/dist/types/auth_adapter.d.ts +5 -5
- package/dist/types/auth_hooks.d.ts +65 -0
- package/dist/types/backend.d.ts +85 -96
- package/dist/types/data_source.d.ts +4 -9
- package/dist/types/database_adapter.d.ts +30 -31
- package/dist/types/entities.d.ts +0 -162
- package/dist/types/filter-operators.d.ts +2 -26
- package/dist/types/history.d.ts +6 -9
- package/dist/types/index.d.ts +3 -9
- package/dist/types/mcp_app_modules.d.ts +0 -2
- package/dist/types/policy.d.ts +85 -10
- package/dist/types/project_manifest.d.ts +113 -46
- package/dist/types/read_query.d.ts +98 -0
- package/dist/types/register.d.ts +35 -5
- package/dist/types/relations.d.ts +0 -430
- package/dist/types/schema_editing.d.ts +54 -2
- package/dist/types/schema_version.d.ts +24 -4
- package/dist/types/security_rules.d.ts +225 -15
- package/dist/types/storage_authorize.d.ts +2 -2
- package/dist/types/tenancy.d.ts +3 -3
- package/dist/types/ui_preferences.d.ts +228 -0
- package/package.json +3 -2
- package/dist/controllers/auth_state.d.ts +0 -23
- package/dist/controllers/collection_registry.d.ts +0 -67
- package/dist/controllers/effective_role.d.ts +0 -4
- package/dist/types/admin_block.d.ts +0 -96
- package/dist/types/chips.d.ts +0 -16
- package/dist/types/collection_contract.d.ts +0 -43
- package/dist/types/collection_patch.d.ts +0 -74
- package/dist/types/collections.d.ts +0 -783
- package/dist/types/component_ref.d.ts +0 -81
- package/dist/types/conditions-contract.types.d.ts +0 -14
- package/dist/types/entity_callbacks.d.ts +0 -393
- package/dist/types/indexes.d.ts +0 -179
- package/dist/types/properties.d.ts +0 -1640
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* 1. {@link RebaseProjectManifest} — `rebase.json`. **Authored** by the developer,
|
|
7
7
|
* committed to the repository. Declares topology only: which runtime major the
|
|
8
8
|
* project targets, and which apps *this repository* contributes to the project.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* Tables, security rules, hooks and functions stay in TypeScript under
|
|
10
|
+
* `backend/` — nothing that needs a type system belongs here.
|
|
11
11
|
*
|
|
12
12
|
* 2. {@link RebaseProjectLink} — the per-checkout link (`.rebase/cloud.json`).
|
|
13
13
|
* **Not committed**, because it is per-developer like a git remote. Says which
|
|
@@ -26,10 +26,11 @@
|
|
|
26
26
|
*/
|
|
27
27
|
import type { StorageSourceDefinition } from "./storage_source.js";
|
|
28
28
|
import type { ResourceGraph } from "./resources.js";
|
|
29
|
+
import type { TableDescriptor } from "../schema/descriptor.js";
|
|
29
30
|
/**
|
|
30
31
|
* Which kind of thing an app is.
|
|
31
32
|
*
|
|
32
|
-
* - `backend` — the
|
|
33
|
+
* - `backend` — the tables/hooks/functions that define the project's API.
|
|
33
34
|
* Exactly one per *project* (not per repository); the registry enforces it.
|
|
34
35
|
* - `static` — a pre-built client bundle (SPA, static site), served from the
|
|
35
36
|
* backend process at its declared `path` or from a CDN. The admin panel is
|
|
@@ -52,7 +53,7 @@ export interface RebaseBackendAppConfig {
|
|
|
52
53
|
* Who owns the process this backend runs in.
|
|
53
54
|
*
|
|
54
55
|
* - `managed` — the platform's runtime image boots this project's bundle.
|
|
55
|
-
* You supply
|
|
56
|
+
* You supply tables, functions, crons and schema; Rebase supplies the
|
|
56
57
|
* server.
|
|
57
58
|
* - `custom` — this repository builds its own image and entrypoint. The
|
|
58
59
|
* escape hatch: full control, no managed-runtime guarantees.
|
|
@@ -67,8 +68,23 @@ export interface RebaseBackendAppConfig {
|
|
|
67
68
|
* land projects on the custom runtime without anyone choosing it.
|
|
68
69
|
*/
|
|
69
70
|
runtime: "managed" | "custom";
|
|
70
|
-
/**
|
|
71
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Directory whose `index.ts` exports the project's tables and views
|
|
73
|
+
* (`defineTable`, `defineAuthTable`, `defineView`) and, optionally,
|
|
74
|
+
* `defaultRls`. Default `backend/schema`.
|
|
75
|
+
*
|
|
76
|
+
* When it has no `index.ts` the project declares no tables, and the runtime
|
|
77
|
+
* introspects them from the live database at boot.
|
|
78
|
+
*
|
|
79
|
+
* Not `schema`: that key already names the *generated* Drizzle module, and
|
|
80
|
+
* a manifest is read by tools of every age.
|
|
81
|
+
*
|
|
82
|
+
* Replaces `config` (the config package, whose `collections/` held
|
|
83
|
+
* `defineCollection` files) and `usersCollection` (the auth table is the one
|
|
84
|
+
* declared with `defineAuthTable`). Both are refused by the CLI with the
|
|
85
|
+
* codemod in the message — see {@link LEGACY_LAYOUT_REMEDY}.
|
|
86
|
+
*/
|
|
87
|
+
tables?: string;
|
|
72
88
|
/** Directory of server functions. Default `backend/functions`. */
|
|
73
89
|
functions?: string;
|
|
74
90
|
/** Directory of cron job definitions. Default `backend/crons` when present. */
|
|
@@ -78,16 +94,11 @@ export interface RebaseBackendAppConfig {
|
|
|
78
94
|
* Default `backend/src/schema.generated.ts`.
|
|
79
95
|
*/
|
|
80
96
|
schema?: string;
|
|
81
|
-
/**
|
|
82
|
-
* Module path (relative to `config`) exporting the auth users collection as
|
|
83
|
-
* its default export. Default `collections/users`.
|
|
84
|
-
*/
|
|
85
|
-
usersCollection?: string;
|
|
86
97
|
/**
|
|
87
98
|
* Type server-side data from the generated `Database`. When `true`, every
|
|
88
99
|
* `rebase generate-sdk` — `rebase dev`'s included, and the first one on a
|
|
89
100
|
* fresh clone — writes the types and the `Register` declaration to
|
|
90
|
-
*
|
|
101
|
+
* `backend/generated/`. `rebase generate-sdk --register` sets it.
|
|
91
102
|
* Default `false`.
|
|
92
103
|
*/
|
|
93
104
|
registerDatabase?: boolean;
|
|
@@ -371,8 +382,30 @@ export interface ManagedCompatibility {
|
|
|
371
382
|
* one of these would find no `mode` and an array where it expects a string, so
|
|
372
383
|
* the bump is what turns that into a refusal to boot instead of a bundle that
|
|
373
384
|
* starts and serves nothing.
|
|
385
|
+
* - **3** — the schema is `entry.tables` (the compiled `backend/schema`
|
|
386
|
+
* directory, whose `index` exports the tables), beside `entry.resources`,
|
|
387
|
+
* `entry.storage` and `entry.hooks`. There is no config package any more:
|
|
388
|
+
* `entry.config`, `entry.collections` and `entry.usersCollection` are not
|
|
389
|
+
* written. A format-2 runtime would find none of the keys it boots from and
|
|
390
|
+
* introspect the database instead of serving the declared tables — so the
|
|
391
|
+
* bump turns that into a refusal.
|
|
392
|
+
*
|
|
393
|
+
* **Format 2 bundles are refused, not upgraded.** Unlike 1 → 2, which was a
|
|
394
|
+
* renaming, a format-2 bundle carries `config/collections` — `defineCollection`
|
|
395
|
+
* objects — and a runtime that reads only `backend/schema` has nothing to read
|
|
396
|
+
* them with. It refuses them at boot with {@link LEGACY_LAYOUT_REMEDY} in the
|
|
397
|
+
* error: run the codemod on the project's source, then rebuild.
|
|
374
398
|
*/
|
|
375
|
-
export declare const BUNDLE_FORMAT_VERSION =
|
|
399
|
+
export declare const BUNDLE_FORMAT_VERSION = 3;
|
|
400
|
+
/**
|
|
401
|
+
* What to do about a project on the `config/collections` layout — the words
|
|
402
|
+
* every refusal of that layout ends with.
|
|
403
|
+
*
|
|
404
|
+
* Shared because two parties refuse it and must say the same thing: the CLI,
|
|
405
|
+
* for a `rebase.json` that still names `config` or `usersCollection`, and the
|
|
406
|
+
* runtime, for a format-2 / contract-1 bundle built from `config/collections`.
|
|
407
|
+
*/
|
|
408
|
+
export declare const LEGACY_LAYOUT_REMEDY: string;
|
|
376
409
|
/**
|
|
377
410
|
* The runtime contract major.
|
|
378
411
|
*
|
|
@@ -381,23 +414,36 @@ export declare const BUNDLE_FORMAT_VERSION = 2;
|
|
|
381
414
|
* the bundle/runtime contract breaks compatibility, and a project's
|
|
382
415
|
* `manifest.runtime` range is matched against *this*.
|
|
383
416
|
*
|
|
384
|
-
* ## v2 —
|
|
417
|
+
* ## v2 — tables, not collections
|
|
418
|
+
*
|
|
419
|
+
* The runtime reads the project's schema from `backend/schema` (bundle format
|
|
420
|
+
* 3, `entry.tables`): `defineTable` / `defineAuthTable` / `defineView` exports
|
|
421
|
+
* and `defaultRls`. It no longer loads `config/collections`, and it no longer
|
|
422
|
+
* reads a config package's `collections` / `callbacks` exports or a
|
|
423
|
+
* `usersCollection` module; global table hooks come from `backend/hooks.ts`,
|
|
424
|
+
* `storageAuthorize` from `backend/storage.ts`, declared resources from
|
|
425
|
+
* `backend/resources.ts`.
|
|
385
426
|
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
427
|
+
* So, plainly: **a format-2 / contract-1 bundle — one built from
|
|
428
|
+
* `config/collections` — is refused by a contract-2 runtime**, at boot, with
|
|
429
|
+
* {@link LEGACY_LAYOUT_REMEDY} in the message. There is no in-runtime adapter
|
|
430
|
+
* from collections to tables; the project's source is migrated once with the
|
|
431
|
+
* codemod and rebuilt. On the managed tier that means the platform keeps such a
|
|
432
|
+
* tenant on a contract-1 image until it is rebuilt — the release order below
|
|
433
|
+
* applies unchanged.
|
|
389
434
|
*
|
|
390
|
-
* This
|
|
391
|
-
* onto new images WITHOUT rebuilding them.
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
435
|
+
* This has to be a major, and the reason is the managed tier: it moves projects
|
|
436
|
+
* onto new images WITHOUT rebuilding them. Without the bump, one image rollout
|
|
437
|
+
* would crash-loop every tenant whose bundle predates the change, in a wave,
|
|
438
|
+
* with the cause in a container log nobody is watching. With it, an older
|
|
439
|
+
* bundle on a newer runtime is refused by `readBundleManifest` with the remedy
|
|
440
|
+
* in the message, and the platform keeps it on an image of its own major until
|
|
441
|
+
* it is rebuilt. That is the whole purpose of this number.
|
|
396
442
|
*
|
|
397
|
-
*
|
|
398
|
-
* `
|
|
399
|
-
*
|
|
400
|
-
*
|
|
443
|
+
* (Declared resources — `database()` / `bucket()` replacing
|
|
444
|
+
* `RebaseBackendConfig.dataSources` / `.storageSources` — once took this number
|
|
445
|
+
* to 2 and were taken back to 1 before launch, when there was no fleet for the
|
|
446
|
+
* major to protect. They are part of v1.)
|
|
401
447
|
*
|
|
402
448
|
* **Release order matters and is not optional.** The control plane is the side
|
|
403
449
|
* that rejects, so it ships FIRST: raise `SUPPORTED_RUNTIME_CONTRACT` in the
|
|
@@ -406,21 +452,41 @@ export declare const BUNDLE_FORMAT_VERSION = 2;
|
|
|
406
452
|
* runtime first turns every deploy into a rejected intake blaming the tenant's
|
|
407
453
|
* bundle.
|
|
408
454
|
*/
|
|
409
|
-
export declare const RUNTIME_CONTRACT_VERSION =
|
|
455
|
+
export declare const RUNTIME_CONTRACT_VERSION = 2;
|
|
410
456
|
/** Where the runtime finds each part of the bundle. Paths are bundle-relative. */
|
|
411
457
|
export interface RebaseBundleEntrypoints {
|
|
412
|
-
/**
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
458
|
+
/**
|
|
459
|
+
* Compiled `backend/schema` directory: its `index.js` exports the tables,
|
|
460
|
+
* views and optional `defaultRls`. Absent when the project declares no
|
|
461
|
+
* tables, which makes the runtime introspect the database instead.
|
|
462
|
+
*
|
|
463
|
+
* Not `schema`, which is the compiled *Drizzle* module below.
|
|
464
|
+
*/
|
|
465
|
+
tables?: string;
|
|
466
|
+
/** Compiled `backend/resources` module — the `database()` / `bucket()` / `topic()` declarations. */
|
|
467
|
+
resources?: string;
|
|
468
|
+
/** Compiled `backend/storage` module, exporting `storageAuthorize`. */
|
|
469
|
+
storage?: string;
|
|
470
|
+
/** Compiled `backend/hooks` module, exporting `hooks` (global table hooks). */
|
|
471
|
+
hooks?: string;
|
|
416
472
|
/** Compiled functions directory. */
|
|
417
473
|
functions?: string;
|
|
418
474
|
/** Compiled crons directory. */
|
|
419
475
|
crons?: string;
|
|
420
476
|
/** Compiled Drizzle schema module. */
|
|
421
477
|
schema?: string;
|
|
422
|
-
/**
|
|
423
|
-
|
|
478
|
+
/**
|
|
479
|
+
* A copy of the frontend's `src/cms/ui-config.json` — the presentation the
|
|
480
|
+
* collection editor saved in development and the frontend ships as
|
|
481
|
+
* `<RebaseCMS uiConfig>` — so the server knows it too: it is the workspace
|
|
482
|
+
* baseline of what the server serves about presentation (the MCP views,
|
|
483
|
+
* `GET /api/admin/ui-config`'s `shipped`).
|
|
484
|
+
*
|
|
485
|
+
* Optional and additive within format 3: absent when the project has no
|
|
486
|
+
* such file, and on bundles built before it existed, which boot as before
|
|
487
|
+
* (the server then knows only the preferences it stores).
|
|
488
|
+
*/
|
|
489
|
+
uiConfig?: string;
|
|
424
490
|
/**
|
|
425
491
|
* Built static apps to serve from this process, in declaration order.
|
|
426
492
|
*
|
|
@@ -531,13 +597,13 @@ export interface RebaseBundleManifest {
|
|
|
531
597
|
contract: number;
|
|
532
598
|
};
|
|
533
599
|
/**
|
|
534
|
-
* Hash of the compiled
|
|
600
|
+
* Hash of the compiled table descriptors (`computeSchemaVersion`).
|
|
535
601
|
*
|
|
536
602
|
* This is the contract stamp. A generated SDK records the value it was built
|
|
537
603
|
* from, a client sends it back, and a mismatch is what lets the platform say
|
|
538
604
|
* "this app was built against an older schema" instead of failing mysteriously
|
|
539
|
-
* at the first request. It covers
|
|
540
|
-
* change a client's contract, so it must not invalidate every SDK.
|
|
605
|
+
* at the first request. It covers tables only — a hook's code does not
|
|
606
|
+
* change a client's contract, so editing it must not invalidate every SDK.
|
|
541
607
|
*/
|
|
542
608
|
schemaVersion: string;
|
|
543
609
|
/** Which app in `rebase.json` this bundle was built from. */
|
|
@@ -553,12 +619,12 @@ export interface RebaseBundleManifest {
|
|
|
553
619
|
*
|
|
554
620
|
* Replaces an earlier `mode: "cms" | "baas" | "static"`. The cms/baas
|
|
555
621
|
* distinction was never a third kind of thing — it is simply whether
|
|
556
|
-
* `entry.
|
|
622
|
+
* `entry.tables` is present, so it is derived rather than declared.
|
|
557
623
|
*/
|
|
558
624
|
kind: "backend" | "static";
|
|
559
625
|
entry: RebaseBundleEntrypoints;
|
|
560
|
-
/**
|
|
561
|
-
|
|
626
|
+
/** Table slugs contained in the bundle, for quick inspection. */
|
|
627
|
+
tables?: string[];
|
|
562
628
|
/**
|
|
563
629
|
* Every custom function in the bundle, named and classified.
|
|
564
630
|
*
|
|
@@ -606,7 +672,7 @@ export interface RebaseBundleManifest {
|
|
|
606
672
|
* Absent on bundles built before this field existed.
|
|
607
673
|
*/
|
|
608
674
|
storage?: {
|
|
609
|
-
/** Whether
|
|
675
|
+
/** Whether `backend/storage` exports a `storageAuthorize` hook. */
|
|
610
676
|
authorize: boolean;
|
|
611
677
|
/**
|
|
612
678
|
* Buckets, on bundles built before {@link RebaseBundleManifest.resources}.
|
|
@@ -691,11 +757,12 @@ export interface RebaseProjectContract {
|
|
|
691
757
|
version: string;
|
|
692
758
|
contract: number;
|
|
693
759
|
};
|
|
694
|
-
/**
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
760
|
+
/**
|
|
761
|
+
* Every table, as `GET /api/schema/tables` serves an administrator: the
|
|
762
|
+
* input to remote SDK generation (`rebase generate-sdk --from`). Hooks are
|
|
763
|
+
* presence flags; private columns are absent.
|
|
764
|
+
*/
|
|
765
|
+
tables: TableDescriptor[];
|
|
699
766
|
}
|
|
700
767
|
/** Header carrying the schema version an SDK was generated from. */
|
|
701
768
|
export declare const SCHEMA_VERSION_HEADER = "x-rebase-schema";
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The read a `beforeQuery` hook narrows: what is being read, and the narrowing
|
|
3
|
+
* it may answer with. Shared by table hooks (`TableHooks.beforeQuery`) and the
|
|
4
|
+
* panel's collection callbacks.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { FilterValues, OrderByTuple } from "./filter-operators.js";
|
|
9
|
+
import type { LogicalCondition } from "../controllers/data.js";
|
|
10
|
+
/**
|
|
11
|
+
* Which read a {@link CollectionCallbacks.beforeQuery} hook is narrowing.
|
|
12
|
+
*
|
|
13
|
+
* Named rather than inferred because the four are not interchangeable to a
|
|
14
|
+
* hook that logs, measures or short-circuits: `"count"` and `"aggregate"` serve
|
|
15
|
+
* a total rather than rows, and `"relation"` is the target collection's own
|
|
16
|
+
* hook firing over rows reached from a parent.
|
|
17
|
+
*
|
|
18
|
+
* @group Models
|
|
19
|
+
*/
|
|
20
|
+
export type ReadOperation = "list" | "get" | "count" | "aggregate" | "relation";
|
|
21
|
+
/**
|
|
22
|
+
* The parsed read, as a {@link CollectionCallbacks.beforeQuery} hook sees it.
|
|
23
|
+
*
|
|
24
|
+
* Read-only throughout, and that is the point rather than a courtesy: a hook
|
|
25
|
+
* that could edit this object would be able to *widen* the read, which is the
|
|
26
|
+
* one thing this hook is built not to permit. Mutating it is a compile error;
|
|
27
|
+
* narrowing is what the return value is for.
|
|
28
|
+
*
|
|
29
|
+
* Fields are present exactly when the caller sent them. An absent `filter` is
|
|
30
|
+
* a query with no filter, not an empty one.
|
|
31
|
+
*
|
|
32
|
+
* @group Models
|
|
33
|
+
*/
|
|
34
|
+
export interface ReadQuery<M extends Record<string, unknown> = Record<string, unknown>> {
|
|
35
|
+
/** The caller's own field filter. */
|
|
36
|
+
readonly filter?: Readonly<FilterValues<Extract<keyof M, string>>>;
|
|
37
|
+
/** The caller's `or(...)` / `and(...)` group, if any. */
|
|
38
|
+
readonly logical?: Readonly<LogicalCondition>;
|
|
39
|
+
/** The text typed into a search box, if this is a search. */
|
|
40
|
+
readonly searchString?: string;
|
|
41
|
+
/** Page size, when the caller asked for one. */
|
|
42
|
+
readonly limit?: number;
|
|
43
|
+
/** Offset pagination, when the caller asked for one. */
|
|
44
|
+
readonly offset?: number;
|
|
45
|
+
/**
|
|
46
|
+
* Sort keys, normalized to tuples — one entry per key, in order of
|
|
47
|
+
* significance, whichever of the several authoring forms the caller used.
|
|
48
|
+
*/
|
|
49
|
+
readonly orderBy?: readonly Readonly<OrderByTuple>[];
|
|
50
|
+
/** Column projection, when the caller narrowed it with `fields`. */
|
|
51
|
+
readonly fields?: readonly string[];
|
|
52
|
+
/**
|
|
53
|
+
* The parent this read hangs off, for `operation: "relation"` and for a
|
|
54
|
+
* nested path like `authors/1/posts`.
|
|
55
|
+
*
|
|
56
|
+
* A hook that scopes by tenant usually ignores it. A hook that needs to
|
|
57
|
+
* know it is looking at *someone's* rows rather than all of them does not.
|
|
58
|
+
*/
|
|
59
|
+
readonly relatedTo?: {
|
|
60
|
+
readonly parentSlug: string;
|
|
61
|
+
readonly parentId?: string | number;
|
|
62
|
+
readonly relationName: string;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* What a {@link CollectionCallbacks.beforeQuery} hook returns: conditions to
|
|
67
|
+
* AND into the read.
|
|
68
|
+
*
|
|
69
|
+
* Returning nothing (`undefined`, or no `return` at all) adds nothing and
|
|
70
|
+
* leaves the compiled SQL byte-identical to what it would have been.
|
|
71
|
+
*
|
|
72
|
+
* Both fields are the same declarative language a caller's own query uses, so
|
|
73
|
+
* a relation path (`author.tenant_id`), a JSON path (`meta->>tier`) and every
|
|
74
|
+
* `WhereFilterOp` works here too. There is no raw-SQL member, and that is
|
|
75
|
+
* deliberate: raw SQL could be `OR`-ed against the caller's conditions and so
|
|
76
|
+
* could widen the read.
|
|
77
|
+
*
|
|
78
|
+
* @group Models
|
|
79
|
+
*/
|
|
80
|
+
export interface QueryNarrowing<M extends Record<string, unknown> = Record<string, unknown>> {
|
|
81
|
+
/**
|
|
82
|
+
* A field filter to AND in.
|
|
83
|
+
*
|
|
84
|
+
* Compiled with unknown fields fatal, always: a scope condition that names
|
|
85
|
+
* a column the table does not have refuses the request rather than running
|
|
86
|
+
* without it.
|
|
87
|
+
*/
|
|
88
|
+
filter?: FilterValues<Extract<keyof M, string>>;
|
|
89
|
+
/**
|
|
90
|
+
* An `or(...)` / `and(...)` group to AND in, for a scope that is a
|
|
91
|
+
* disjunction — "mine, or shared with me", say.
|
|
92
|
+
*
|
|
93
|
+
* Still additive: the group is AND-ed into the query as a whole, so an
|
|
94
|
+
* `or` inside it can only ever choose between rows the rest of the query
|
|
95
|
+
* already admits.
|
|
96
|
+
*/
|
|
97
|
+
logical?: LogicalCondition;
|
|
98
|
+
}
|
package/dist/types/register.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { DatabaseOf } from "../schema/infer.js";
|
|
1
2
|
/**
|
|
2
|
-
* The project-wide registry of
|
|
3
|
+
* The project-wide registry of a project's data types, filled by module augmentation.
|
|
3
4
|
*
|
|
4
5
|
* Empty by default, and every server-side data surface is untyped while it is:
|
|
5
6
|
* `context.data`, `rebase.dataAsAdmin`, a cron's `ctx.rebase` and a function's
|
|
@@ -23,6 +24,21 @@
|
|
|
23
24
|
* sorts, `include`, and the inputs `create` and `update` accept. Nothing about
|
|
24
25
|
* the runtime changes; the registration is a declaration.
|
|
25
26
|
*
|
|
27
|
+
* A project that has not generated anything registers its schema module
|
|
28
|
+
* instead, and is typed straight from its `defineTable`s (see
|
|
29
|
+
* {@link DatabaseOf} for what that can and cannot know):
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* declare module "@rebasepro/types" {
|
|
33
|
+
* interface Register {
|
|
34
|
+
* tables: typeof import("./backend/schema");
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* A generated `database` wins over `tables` when both are registered: it is
|
|
40
|
+
* the exact one.
|
|
41
|
+
*
|
|
26
42
|
* A single function or cron can still name its own type instead —
|
|
27
43
|
* `defineFunction<Database>(…)`, `defineCron<Database>({…})` — which wins over
|
|
28
44
|
* the registration.
|
|
@@ -32,12 +48,26 @@
|
|
|
32
48
|
export interface Register {
|
|
33
49
|
}
|
|
34
50
|
/**
|
|
35
|
-
* The `Database` a project registered on {@link Register}
|
|
36
|
-
*
|
|
37
|
-
*
|
|
51
|
+
* The generated `Database` a project registered on {@link Register}
|
|
52
|
+
* (`Register.database`), or `unknown`. What a table's own hooks are typed
|
|
53
|
+
* from: typing them from `Register.tables` would type a schema from itself.
|
|
38
54
|
*
|
|
39
55
|
* @group Data
|
|
40
56
|
*/
|
|
41
|
-
export type
|
|
57
|
+
export type GeneratedDatabase = Register extends {
|
|
42
58
|
database: infer DB;
|
|
43
59
|
} ? DB : unknown;
|
|
60
|
+
/**
|
|
61
|
+
* The `Database` a project registered on {@link Register} — its generated
|
|
62
|
+
* `database`, or else {@link DatabaseOf} its registered schema module
|
|
63
|
+
* (`tables`) — or `unknown` when it registered neither, which is what keeps an
|
|
64
|
+
* unregistered project's server-side data untyped, exactly as it was before
|
|
65
|
+
* the registry existed.
|
|
66
|
+
*
|
|
67
|
+
* @group Data
|
|
68
|
+
*/
|
|
69
|
+
export type RegisteredDatabase = Register extends {
|
|
70
|
+
database: infer DB;
|
|
71
|
+
} ? DB : Register extends {
|
|
72
|
+
tables: infer M;
|
|
73
|
+
} ? DatabaseOf<M> : unknown;
|