okmodel 0.5.1 → 0.7.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.
- package/README.md +100 -1116
- package/dist/adapters/capabilities.d.ts +3 -0
- package/dist/adapters/failure.d.ts +13 -2
- package/dist/adapters/lazy-errors.d.ts +22 -0
- package/dist/adapters/pg/bunsql-extra.d.ts +54 -3
- package/dist/adapters/pg/bunsql.d.ts +14 -1
- package/dist/adapters/pg/cursor.d.ts +17 -0
- package/dist/adapters/pg/no-inflight-timeout.d.ts +20 -0
- package/dist/adapters/pg/nodepostgres-extra.d.ts +22 -1
- package/dist/adapters/pg/nodepostgres.d.ts +12 -0
- package/dist/adapters/pg/pglite-wire.d.ts +24 -0
- package/dist/adapters/pg/pglite.d.ts +10 -0
- package/dist/adapters/pg/postgres-extra.d.ts +41 -3
- package/dist/adapters/pg/reserved.d.ts +42 -0
- package/dist/adapters/pg/session.d.ts +0 -18
- package/dist/contracts/catalog/document.d.ts +19 -5
- package/dist/contracts/catalog/object.d.ts +2 -1
- package/dist/contracts/catalog/policy.d.ts +48 -0
- package/dist/contracts/catalog/types.d.ts +25 -1
- package/dist/contracts/catalog/view.d.ts +2 -0
- package/dist/contracts/connection.d.ts +7 -6
- package/dist/contracts/internal.js +1 -1
- package/dist/contracts/location.d.ts +10 -0
- package/dist/dialects/pg/column.d.ts +13 -2
- package/dist/dialects/pg/ddl.d.ts +37 -1
- package/dist/dialects/pg/emit.d.ts +19 -1
- package/dist/dialects/pg/errors.d.ts +32 -1
- package/dist/dialects/pg/ext/citext.js +1 -1
- package/dist/dialects/pg/ext/index.js +1 -1
- package/dist/dialects/pg/ext/pg-trgm.js +1 -1
- package/dist/dialects/pg/filter-parse.d.ts +5 -4
- package/dist/dialects/pg/floor.d.ts +68 -0
- package/dist/dialects/pg/fn/index.js +2 -2
- package/dist/dialects/pg/index.d.ts +8 -2
- package/dist/dialects/pg/index.js +67 -171
- package/dist/dialects/pg/introspect.d.ts +7 -0
- package/dist/dialects/pg/keys.d.ts +11 -8
- package/dist/dialects/pg/model.d.ts +47 -2
- package/dist/dialects/pg/morph.d.ts +43 -0
- package/dist/dialects/pg/operator-fit.d.ts +2 -2
- package/dist/dialects/pg/operators.d.ts +14 -7
- package/dist/dialects/pg/ops/bucket.d.ts +65 -0
- package/dist/dialects/pg/ops/inc.d.ts +2 -2
- package/dist/dialects/pg/ops/matches.d.ts +9 -12
- package/dist/dialects/pg/ops/relevance.d.ts +13 -0
- package/dist/dialects/pg/ops/search-query.d.ts +22 -0
- package/dist/dialects/pg/ops/window.d.ts +103 -0
- package/dist/dialects/pg/owner.d.ts +42 -0
- package/dist/dialects/pg/path-endpoint.d.ts +20 -0
- package/dist/dialects/pg/preset.d.ts +1 -1
- package/dist/dialects/pg/relations.d.ts +100 -3
- package/dist/dialects/pg/role/check.d.ts +3 -0
- package/dist/dialects/pg/role/index.d.ts +71 -6
- package/dist/dialects/pg/role/sql.d.ts +11 -0
- package/dist/dialects/pg/schema.d.ts +33 -3
- package/dist/dialects/pg/table.d.ts +25 -3
- package/dist/dialects/pg/tenancy.d.ts +45 -3
- package/dist/dialects/pg/view/client.d.ts +19 -1
- package/dist/dialects/pg/view/index.d.ts +4 -0
- package/dist/dialects/pg/view/index.js +21 -178
- package/dist/dialects/pg/view/refresh.d.ts +24 -0
- package/dist/runtime/aggregate.d.ts +8 -2
- package/dist/runtime/batch.d.ts +1 -1
- package/dist/runtime/bucket-group.d.ts +70 -0
- package/dist/runtime/conflict.d.ts +24 -6
- package/dist/runtime/drift.d.ts +9 -0
- package/dist/runtime/include.d.ts +0 -8
- package/dist/runtime/inflight.d.ts +14 -0
- package/dist/runtime/page.d.ts +4 -1
- package/dist/runtime/pg/bun.js +12 -5
- package/dist/runtime/pg/pg.js +5 -5
- package/dist/runtime/pg/pglite.d.ts +1 -0
- package/dist/runtime/pg/pglite.js +9 -8
- package/dist/runtime/pg/postgresjs.js +5 -5
- package/dist/runtime/plan.d.ts +113 -15
- package/dist/runtime/predicate.d.ts +19 -0
- package/dist/runtime/read-stream.d.ts +13 -16
- package/dist/runtime/result-name.d.ts +17 -0
- package/dist/runtime/safety/index.js +1 -1
- package/dist/runtime/server-check.d.ts +3 -3
- package/dist/runtime/sort-bind.d.ts +21 -0
- package/dist/runtime/sort.d.ts +56 -0
- package/dist/runtime/sync.d.ts +70 -0
- package/dist/runtime/tenancy/composite.d.ts +26 -0
- package/dist/runtime/tenancy/context.d.ts +16 -0
- package/dist/runtime/tenancy/index.d.ts +9 -5
- package/dist/runtime/tenancy/index.js +1511 -38
- package/dist/runtime/tenancy/path.d.ts +87 -0
- package/dist/runtime/tenancy/rls.d.ts +67 -0
- package/dist/runtime/tenancy/via.d.ts +22 -0
- package/dist/runtime/text-search.d.ts +20 -0
- package/dist/runtime/traits/index.d.ts +80 -0
- package/dist/runtime/traits/index.js +187 -17
- package/dist/runtime/tree.d.ts +38 -0
- package/dist/runtime/types.d.ts +231 -23
- package/dist/runtime/validate/index.js +4 -4
- package/dist/runtime/version.d.ts +39 -0
- package/dist/runtime/window.d.ts +21 -0
- package/dist/runtime/write.d.ts +55 -3
- package/dist/shared/{krxx77g0.js → 14vx95q4.js} +12 -18
- package/dist/shared/1est4ezg.js +313 -0
- package/dist/shared/{4az561fn.js → 1qa0qajz.js} +8 -23
- package/dist/shared/1w508jbr.js +1611 -0
- package/dist/shared/2c13q96h.js +18 -0
- package/dist/shared/2d3xq4ps.js +9 -0
- package/dist/shared/2shdbn8q.js +23 -0
- package/dist/shared/{t4tbsy9h.js → 358zsv4r.js} +1 -1
- package/dist/shared/3v7t1yrv.js +208 -0
- package/dist/shared/5e3tf63j.js +220 -0
- package/dist/shared/5fe3kbsh.js +10 -0
- package/dist/shared/5v3xf80k.js +37 -0
- package/dist/shared/{51mvgj8w.js → 63qtkrca.js} +130 -3
- package/dist/shared/{gbtcc2d7.js → 67txcrcw.js} +62 -66
- package/dist/shared/79dt02vc.js +12 -0
- package/dist/shared/{v36c5g6p.js → 7k9grvf6.js} +407 -14
- package/dist/shared/7kms6fvj.js +20 -0
- package/dist/shared/7mnme5tn.js +8 -0
- package/dist/shared/7n7ddwt4.js +6 -0
- package/dist/shared/{87jvvhnt.js → 81ebdx9p.js} +48 -68
- package/dist/shared/{szm0cksa.js → 8skf0cam.js} +34 -6
- package/dist/shared/{gjthds9j.js → 9628a9xt.js} +1 -1
- package/dist/shared/9a4ae4p8.js +31 -0
- package/dist/shared/{8xsbagad.js → 9s0ypp87.js} +88 -7
- package/dist/shared/9y3mmmh1.js +436 -0
- package/dist/shared/ab9gmbwy.js +213 -0
- package/dist/shared/{sycnx8gt.js → ax7qv55k.js} +18 -8
- package/dist/shared/{f5cw5q5r.js → aytqh5y2.js} +6 -4
- package/dist/shared/{fancm5pt.js → b5pftnn2.js} +138 -15
- package/dist/shared/{efmy2gcg.js → b76b8d95.js} +2 -2
- package/dist/shared/bdk4sty6.js +58 -0
- package/dist/shared/{32zqc1dw.js → bg3rym3g.js} +63 -32
- package/dist/shared/{0t22wwh1.js → bm22fvzr.js} +16 -14
- package/dist/shared/bz84tkzm.js +342 -0
- package/dist/shared/{31vm914h.js → cm3w0ywp.js} +15 -16
- package/dist/shared/cn957f8d.js +179 -0
- package/dist/shared/{pf0d8f77.js → cnkky55j.js} +25 -14
- package/dist/shared/{5fqx9yh4.js → dk8v79p3.js} +3 -1
- package/dist/shared/{nkaxvt9q.js → dkxgzaqd.js} +224 -19
- package/dist/shared/dzj09cye.js +10 -0
- package/dist/shared/{4m9fn52z.js → ed0b8k4s.js} +1 -1
- package/dist/shared/{z2rnngj4.js → ek2wt2dz.js} +8 -5
- package/dist/shared/exn3sd90.js +359 -0
- package/dist/shared/g6evj1j3.js +66 -0
- package/dist/shared/ga9j92qj.js +25 -0
- package/dist/shared/{qv2ydck9.js → gs74dbj5.js} +651 -76
- package/dist/shared/gzaveazc.js +285 -0
- package/dist/shared/{8rsy3hxz.js → h15jx9bc.js} +1 -1
- package/dist/shared/{dyj86cmj.js → hyh73qk6.js} +3 -3
- package/dist/shared/je4axnm8.js +22 -0
- package/dist/shared/{ycatkxmq.js → jgqj11w4.js} +1 -1
- package/dist/shared/{6qd27mx0.js → jvd0mqag.js} +5 -5
- package/dist/shared/jznfax0y.js +155 -0
- package/dist/shared/{cgbamx3e.js → kb2sdhfb.js} +7 -4
- package/dist/shared/{ps7a6h14.js → kr0jzbw2.js} +12 -8
- package/dist/shared/{janx09m5.js → ktz42yez.js} +20 -8
- package/dist/shared/{gde73es6.js → m6p12kbr.js} +56 -55
- package/dist/shared/{r6nwkxnt.js → m7n9h2a5.js} +4 -4
- package/dist/shared/{672t5vym.js → mss6ctgv.js} +2 -2
- package/dist/shared/{nxdp2ze3.js → mtaszv5a.js} +144 -12
- package/dist/shared/n816peh1.js +45 -0
- package/dist/shared/nbw1z4yd.js +18 -0
- package/dist/shared/{cctw17hj.js → p6qc5gcp.js} +38 -34
- package/dist/shared/{6rk2gen5.js → pbp1ss85.js} +20 -17
- package/dist/shared/pt94kz7f.js +6 -0
- package/dist/shared/{wq9n6pwr.js → pz6rj8ay.js} +82 -9
- package/dist/shared/q5c6ngn3.js +13 -0
- package/dist/shared/{8bwbwy8h.js → qq3899ht.js} +128 -18
- package/dist/shared/{8ktwd3rh.js → r3j8s5y0.js} +1 -1
- package/dist/shared/rhs3xe4k.js +7 -0
- package/dist/shared/{ntneex2a.js → rpycarcr.js} +6 -6
- package/dist/shared/{sdc7r2ww.js → rs73fca9.js} +8 -8
- package/dist/shared/{tm5ab8we.js → sfz1ksn6.js} +7 -4
- package/dist/shared/{6mnp99hx.js → svncdeh5.js} +16 -12
- package/dist/shared/{hf22e0wt.js → tbrvgw6z.js} +62 -42
- package/dist/shared/te5as7z7.js +622 -0
- package/dist/shared/{ga3sfy93.js → tsvww22q.js} +535 -200
- package/dist/shared/{47x8x9ze.js → ttsqgp4p.js} +20 -13
- package/dist/shared/{x72jb7ad.js → v8g1vgv8.js} +1 -1
- package/dist/shared/vb6qfyve.js +152 -0
- package/dist/shared/{r2sp8hrc.js → vczs8gd4.js} +22 -13
- package/dist/shared/{1g0drakv.js → vqrjpcqn.js} +145 -3
- package/dist/shared/{2pqx26h8.js → w72kgg4q.js} +31 -22
- package/dist/shared/{96qcj21c.js → w79hsckn.js} +16 -51
- package/dist/shared/wa07eas9.js +730 -0
- package/dist/shared/{k8v5v5wj.js → x933k9a3.js} +75 -34
- package/dist/shared/{cr74e96e.js → xhfsfkgk.js} +62 -28
- package/dist/shared/xjk7hnn5.js +272 -0
- package/dist/shared/{5enne4ma.js → xnxsed62.js} +66 -113
- package/dist/shared/xqve9598.js +53 -0
- package/dist/shared/{9x25fxhc.js → y34a8714.js} +1 -1
- package/dist/shared/{k7dwkhvq.js → y6jdds7g.js} +4 -1
- package/dist/shared/y6njgyda.js +249 -0
- package/dist/shared/{c9z5g0fm.js → ywr8hmey.js} +5 -2
- package/dist/shared/{g7ez901n.js → ywspezzx.js} +1 -1
- package/dist/shared/z7s6fpxv.js +62 -0
- package/dist/shared/{n7mcc1gk.js → zchaghkf.js} +4 -3
- package/dist/shared/{9m80mkac.js → ze4hxsmy.js} +1 -1
- package/dist/shared/zm0ptry0.js +40 -0
- package/dist/shared/{nsva2a6b.js → znm0bpp5.js} +3 -0
- package/dist/shared/zp9fmend.js +145 -0
- package/dist/shared/{y005b761.js → zy8r7qvz.js} +6 -2
- package/dist/tooling/cli.js +41 -15
- package/dist/tooling/migrate/apply.d.ts +14 -0
- package/dist/tooling/migrate/check.d.ts +3 -4
- package/dist/tooling/migrate/classify.d.ts +4 -0
- package/dist/tooling/migrate/config.d.ts +3 -2
- package/dist/tooling/migrate/engine.d.ts +3 -2
- package/dist/tooling/migrate/files.d.ts +11 -1
- package/dist/tooling/migrate/index.js +14 -14
- package/dist/tooling/migrate/lint.d.ts +1 -1
- package/dist/tooling/migrate/lost.d.ts +28 -0
- package/dist/tooling/migrate/paths.d.ts +14 -0
- package/dist/tooling/migrate/plan.d.ts +6 -3
- package/dist/tooling/migrate/runner.d.ts +25 -0
- package/dist/tooling/migrate/sandbox.d.ts +57 -0
- package/dist/tooling/migrate/sql-lex.d.ts +20 -3
- package/dist/tooling/migrate/text.d.ts +42 -0
- package/dist/tooling/node-version.d.ts +21 -0
- package/dist/tooling/testing/facts.d.ts +33 -5
- package/dist/tooling/testing/index.d.ts +1 -1
- package/dist/tooling/testing/index.js +3 -3
- package/dist/tooling/testing/isolation.d.ts +11 -5
- package/package.json +8 -3
- package/dist/shared/7m88x3e9.js +0 -45
- package/dist/shared/7zwwyh0v.js +0 -448
- package/dist/shared/aj2qxyhj.js +0 -90
- package/dist/shared/caw8b9d8.js +0 -204
- package/dist/shared/jwtxdj06.js +0 -76
- package/dist/shared/kfjp0gck.js +0 -212
- package/dist/shared/q58y17hy.js +0 -21
- package/dist/shared/qm7cdtvr.js +0 -912
- package/dist/shared/r8x5qhd7.js +0 -86
- package/dist/shared/zqrnhwsq.js +0 -31
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result keys a caller chooses.
|
|
3
|
+
*
|
|
4
|
+
* Loaded with the bucket chunk and the window chunk (D258). The startup
|
|
5
|
+
* graph does not import it.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Refuses a result key that would shadow or replace a prototype property.
|
|
9
|
+
*
|
|
10
|
+
* Assigning `__proto__` replaces that object's prototype when the value is an
|
|
11
|
+
* object. The other names shadow methods on the row. `then` makes the row a
|
|
12
|
+
* thenable. The check runs before any SQL.
|
|
13
|
+
*
|
|
14
|
+
* @param name - The result key
|
|
15
|
+
* @param where - The call, such as `rowNumber as` or `bucket as`
|
|
16
|
+
*/
|
|
17
|
+
export declare function refusePrototypeKey(name: string, where: string): void;
|
|
@@ -17,11 +17,11 @@ export declare const versionQuery = "select current_setting('server_version_num'
|
|
|
17
17
|
/**
|
|
18
18
|
* Accepts the `server_version_num` row, or throws OKM1801, OKM1520, OKM1802, or OKM1803.
|
|
19
19
|
*
|
|
20
|
-
* A declared
|
|
21
|
-
*
|
|
20
|
+
* A declared floor is the minimum. With no floor, the minimum is 15.
|
|
21
|
+
* A major below 15 is refused when the schema is built.
|
|
22
22
|
*
|
|
23
23
|
* @param pool - Connection that ran the version query
|
|
24
|
-
* @param schema - Schema whose
|
|
24
|
+
* @param schema - Schema whose floor is the declared minimum
|
|
25
25
|
* @param rows - `server_version_num`, `version()`, and the `okm_meta` hash
|
|
26
26
|
* @param http - Status overrides from `connect`
|
|
27
27
|
* @param requireMeta - When true, a missing hash is OKM1520
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unique index `sortable()` adds.
|
|
3
|
+
*
|
|
4
|
+
* Tenancy has already widened uniques (D168), so this index names the tenant
|
|
5
|
+
* keys itself. The move and insert SQL load later, on the first call.
|
|
6
|
+
*/
|
|
7
|
+
import type { AnyTable } from "../dialects/pg/table.js";
|
|
8
|
+
/**
|
|
9
|
+
* Adds the position unique index on tables this trait applies to.
|
|
10
|
+
*
|
|
11
|
+
* A path table is refused: the tenant key is not a column, so the index could
|
|
12
|
+
* not keep two tenants from sharing a position.
|
|
13
|
+
*
|
|
14
|
+
* @param self - The trait object `schema()` stored
|
|
15
|
+
* @param tables - Tables after the tenancy rewrite
|
|
16
|
+
* @param casing - Schema casing
|
|
17
|
+
* @param schemaTraits - Traits from `schema()`, when any were passed
|
|
18
|
+
* @param group - Field that splits the order, when `sortable` was given one
|
|
19
|
+
* @returns Tables with the index on the ones this trait applies to
|
|
20
|
+
*/
|
|
21
|
+
export declare function rewriteSortable(self: object, tables: readonly AnyTable[], casing: "snake" | undefined, schemaTraits: readonly object[] | undefined, group: string | undefined): readonly AnyTable[];
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Position assignment and `move`.
|
|
3
|
+
*
|
|
4
|
+
* Loaded on the first insert or move of a `sortable()` table. Positions are
|
|
5
|
+
* dense positive integers, unique inside the group (and the tenant). The
|
|
6
|
+
* advisory lock is its own statement. The next statement reads positions.
|
|
7
|
+
* Under READ COMMITTED a statement's snapshot is taken when it starts, which
|
|
8
|
+
* is before a lock in that same statement is granted, so a commit that landed
|
|
9
|
+
* while this transaction waited would be invisible.
|
|
10
|
+
*/
|
|
11
|
+
import type { Statement } from "../contracts/driver.js";
|
|
12
|
+
import type { ColumnModel, QuerySchema } from "../dialects/pg/model.js";
|
|
13
|
+
import { type ArchiveView, type CallScope, type Indexed } from "./plan.js";
|
|
14
|
+
import { type RunHost } from "./tx.js";
|
|
15
|
+
type Host = RunHost & {
|
|
16
|
+
readonly schema: QuerySchema;
|
|
17
|
+
readonly scope?: CallScope;
|
|
18
|
+
readonly connected?: Promise<void>;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Inserts rows at the end of their group.
|
|
22
|
+
*
|
|
23
|
+
* The lock statement runs first. The insert then takes `max(position) + n`
|
|
24
|
+
* from a snapshot taken after that lock is held. A writer that bypasses these
|
|
25
|
+
* statements can still race; the unique index rejects a duplicate.
|
|
26
|
+
*
|
|
27
|
+
* @param table - Target table
|
|
28
|
+
* @param columns - Columns the insert already decided to write
|
|
29
|
+
* @param rows - Stamped rows, in call order
|
|
30
|
+
* @param group - Group field, when the trait has one
|
|
31
|
+
* @param tenantFields - Tenant fields stored on this table
|
|
32
|
+
* @returns The lock, then the insert without `returning`
|
|
33
|
+
*/
|
|
34
|
+
export declare function insertAtEnd(table: Indexed, columns: readonly ColumnModel[], rows: readonly Record<string, unknown>[], group: string | undefined, tenantFields: readonly string[] | undefined): {
|
|
35
|
+
readonly lock: Statement;
|
|
36
|
+
readonly text: string;
|
|
37
|
+
readonly params: (string | null)[];
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Moves one row before or after another in the same group.
|
|
41
|
+
*
|
|
42
|
+
* The result is `{ position }` after the move. A missing id is `not_found`.
|
|
43
|
+
* An anchor in another group is OKM1120 and writes nothing. The same id on
|
|
44
|
+
* both sides leaves the row where it is.
|
|
45
|
+
*
|
|
46
|
+
* @param host - Pool and schema
|
|
47
|
+
* @param tableName - Table the trait is on
|
|
48
|
+
* @param id - Primary key of the row to move, without the tenant key
|
|
49
|
+
* @param place - `{ before }` or `{ after }`, the anchor's primary key
|
|
50
|
+
* @param view - Archive visibility, when the handle narrowed it
|
|
51
|
+
* @returns The row's position after the move
|
|
52
|
+
*/
|
|
53
|
+
export declare function move(host: Host, tableName: string, id: unknown, place: unknown, view: ArchiveView | undefined): Promise<{
|
|
54
|
+
readonly position: number;
|
|
55
|
+
}>;
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sync` (spec §11, §13 tool 10).
|
|
3
|
+
*
|
|
4
|
+
* One transaction sets a to-many relation to an exact set of ids. The first
|
|
5
|
+
* statement locks the parent row. The write is a second statement, so a sync
|
|
6
|
+
* that waited for that lock sees the links the previous sync committed. A join table
|
|
7
|
+
* gains and loses link rows. A one-to-many sets or clears a nullable foreign
|
|
8
|
+
* key and leaves the related row in place. A link that would have to delete
|
|
9
|
+
* that row is refused. Duplicate ids count once. An id that is not in the
|
|
10
|
+
* related table, or a parent id that is not in this table, writes nothing and
|
|
11
|
+
* throws `not_found`. The parent row is locked, so two syncs of the same id
|
|
12
|
+
* run one after the other.
|
|
13
|
+
*
|
|
14
|
+
* Loaded on the first call.
|
|
15
|
+
*/
|
|
16
|
+
import type { Statement } from "../contracts/driver.js";
|
|
17
|
+
import type { PresetUse } from "../dialects/pg/model.js";
|
|
18
|
+
import { type Mods as ReadMods, type Session } from "./client.js";
|
|
19
|
+
import { type ArchiveView } from "./plan.js";
|
|
20
|
+
type Mods = {
|
|
21
|
+
readonly expect?: number;
|
|
22
|
+
readonly archive?: ArchiveView | undefined;
|
|
23
|
+
readonly uses?: PresetUse | undefined;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Runs one `sync`.
|
|
27
|
+
*
|
|
28
|
+
* @param session - Client session
|
|
29
|
+
* @param table - Table that owns the relation
|
|
30
|
+
* @param id - Primary key of that row
|
|
31
|
+
* @param relation - To-many relation name
|
|
32
|
+
* @param ids - Related primary keys the relation should hold
|
|
33
|
+
* @param options - `expect`, `signal`, and `timeout`
|
|
34
|
+
* @param mods - Chained `expect`, archive visibility, and presets
|
|
35
|
+
* @returns The ids whose links were added or removed
|
|
36
|
+
*/
|
|
37
|
+
export declare function execute(session: Session, table: string, id: unknown, relation: unknown, ids: unknown, options: object | undefined, mods: Mods): Promise<{
|
|
38
|
+
readonly added: readonly unknown[];
|
|
39
|
+
readonly removed: readonly unknown[];
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* The statement `sync` would run.
|
|
43
|
+
*
|
|
44
|
+
* @param session - Client session
|
|
45
|
+
* @param table - Table that owns the relation
|
|
46
|
+
* @param id - Primary key of that row
|
|
47
|
+
* @param relation - To-many relation name
|
|
48
|
+
* @param ids - Related primary keys the relation should hold
|
|
49
|
+
* @param options - `expect`, `signal`, and `timeout`
|
|
50
|
+
* @param mods - Chained `expect`, archive visibility, and presets
|
|
51
|
+
* @returns One statement
|
|
52
|
+
*/
|
|
53
|
+
export declare function explain(session: Session, table: string, id: unknown, relation: unknown, ids: unknown, options: object | undefined, mods: Mods): Promise<{
|
|
54
|
+
readonly statements: readonly Statement[];
|
|
55
|
+
}>;
|
|
56
|
+
/**
|
|
57
|
+
* The handle for one `sync`.
|
|
58
|
+
*
|
|
59
|
+
* Await runs the change. `sql` shows the lock and the write. `expect` lives on
|
|
60
|
+
* the outer handle, which calls this again with `mods.expect` set.
|
|
61
|
+
*
|
|
62
|
+
* @param session - Client session
|
|
63
|
+
* @param table - Table that owns the relation
|
|
64
|
+
* @param input - `id`, `relation`, `ids`, and `options`
|
|
65
|
+
* @param mods - Presets, plus `expect` when the outer handle chained it
|
|
66
|
+
* @param view - Archive view. The same value a read on this handle uses
|
|
67
|
+
* @returns A handle. The value is `{ added, removed }`
|
|
68
|
+
*/
|
|
69
|
+
export declare function build(session: Session, table: string, input: object, mods: ReadMods, view: ArchiveView | undefined): Promise<unknown> & Record<string, unknown>;
|
|
70
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composite tenancy (`compositeTenancy()`).
|
|
3
|
+
*
|
|
4
|
+
* Every tenant table carries the key list, in that order. A column-only app
|
|
5
|
+
* does not import this file. `via()` is a separate import: this file calls a
|
|
6
|
+
* table's own `rewrite` and does not load the path compiler.
|
|
7
|
+
*/
|
|
8
|
+
import type { ColumnTenancy } from "../../dialects/pg/tenancy.js";
|
|
9
|
+
/**
|
|
10
|
+
* Composite tenancy for `schema({ tenancy })`.
|
|
11
|
+
*
|
|
12
|
+
* Every table gains each key unless it passes `global("reason")` or `via()`.
|
|
13
|
+
* The keys are guarded uuids, in this order. Insert fills them from `for()`.
|
|
14
|
+
* Reads and writes filter on every key.
|
|
15
|
+
*
|
|
16
|
+
* @typeParam Keys - Field names, at least one
|
|
17
|
+
* @param input - The key list and `uuid`
|
|
18
|
+
* @returns The object `schema()` applies
|
|
19
|
+
*/
|
|
20
|
+
export declare function compositeTenancy<const Keys extends readonly [string, ...string[]]>(input: {
|
|
21
|
+
readonly key: Keys;
|
|
22
|
+
readonly type: "uuid";
|
|
23
|
+
}): ColumnTenancy & {
|
|
24
|
+
readonly key: Keys[number];
|
|
25
|
+
readonly keys: Keys;
|
|
26
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a table tenancy `rewrite` receives.
|
|
3
|
+
*
|
|
4
|
+
* `columnTenancy()` and `compositeTenancy()` pass it. `via()` reads it.
|
|
5
|
+
* This file is types only, so it is not in a bundle.
|
|
6
|
+
*/
|
|
7
|
+
import type { AnyTable } from "../../dialects/pg/table.js";
|
|
8
|
+
import type { ColumnTenancy } from "../../dialects/pg/tenancy.js";
|
|
9
|
+
/** Context for one table whose tenancy mark carries `rewrite`. */
|
|
10
|
+
export type TableRewriteContext = {
|
|
11
|
+
readonly tables: readonly AnyTable[];
|
|
12
|
+
readonly keys: readonly string[];
|
|
13
|
+
readonly encodes: readonly ((value: string) => string)[];
|
|
14
|
+
readonly api: ColumnTenancy;
|
|
15
|
+
readonly extras: Map<string, readonly string[]>;
|
|
16
|
+
};
|
|
@@ -22,16 +22,20 @@ export declare function global(reason: string): {
|
|
|
22
22
|
/**
|
|
23
23
|
* Column tenancy for `schema({ tenancy })`.
|
|
24
24
|
*
|
|
25
|
-
* Every table gains `key` unless it passes `global("reason")
|
|
26
|
-
* guarded uuid. Insert fills it from `for()`. Reads and writes
|
|
25
|
+
* Every table gains `key` unless it passes `global("reason")` or `via()`.
|
|
26
|
+
* The key is a guarded uuid. Insert fills it from `for()`. Reads and writes
|
|
27
|
+
* filter on it. A list of keys is `compositeTenancy()`.
|
|
27
28
|
*
|
|
28
29
|
* @typeParam Key - Field name of the tenant key
|
|
29
30
|
* @param input - Field name and `uuid`
|
|
30
31
|
* @returns The object `schema()` applies
|
|
31
32
|
*/
|
|
32
|
-
export declare function columnTenancy<const Key
|
|
33
|
-
readonly key: Key;
|
|
33
|
+
export declare function columnTenancy<const Key>(input: {
|
|
34
|
+
readonly key: Key extends readonly unknown[] ? "columnTenancy() takes one key. Use compositeTenancy()." : Key extends string ? Key : "columnTenancy() key must be a field name.";
|
|
34
35
|
readonly type: "uuid";
|
|
35
36
|
}): ColumnTenancy & {
|
|
36
|
-
readonly key: Key;
|
|
37
|
+
readonly key: Key extends string ? Key : string;
|
|
37
38
|
};
|
|
39
|
+
export { compositeTenancy } from "./composite.js";
|
|
40
|
+
export { via } from "./via.js";
|
|
41
|
+
export { RlsRoleError, rlsTenancy, type RlsRoleReason } from "./rls.js";
|