okmodel 0.5.0 → 0.5.1

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.
Files changed (80) hide show
  1. package/README.md +9 -6
  2. package/dist/dialects/pg/filter-parse.d.ts +8 -2
  3. package/dist/dialects/pg/fn/index.js +8 -0
  4. package/dist/dialects/pg/index.js +8 -2
  5. package/dist/dialects/pg/ops/or.d.ts +1 -1
  6. package/dist/dialects/pg/temporal.d.ts +5 -76
  7. package/dist/dialects/pg/view/index.js +1 -1
  8. package/dist/runtime/client.d.ts +6 -1
  9. package/dist/runtime/conflict.d.ts +2 -1
  10. package/dist/runtime/pg/bun.js +5 -5
  11. package/dist/runtime/pg/pg.js +5 -5
  12. package/dist/runtime/pg/pglite.js +5 -5
  13. package/dist/runtime/pg/postgresjs.js +5 -5
  14. package/dist/runtime/plan.d.ts +13 -0
  15. package/dist/runtime/tenancy/index.js +1 -1
  16. package/dist/runtime/traits/index.js +4 -4
  17. package/dist/runtime/validate/index.js +3 -3
  18. package/dist/shared/{ckjbyrt9.js → 0t22wwh1.js} +5 -9
  19. package/dist/shared/{jdgqqx31.js → 2pqx26h8.js} +23 -8
  20. package/dist/shared/{kyxb62mc.js → 31vm914h.js} +9 -1
  21. package/dist/shared/{9tgmr1gh.js → 32zqc1dw.js} +18 -7
  22. package/dist/shared/{47xzb9fc.js → 47x8x9ze.js} +1 -1
  23. package/dist/shared/{zvbjc949.js → 4az561fn.js} +1 -1
  24. package/dist/shared/{s6gqfn5j.js → 51mvgj8w.js} +27 -3
  25. package/dist/shared/{k3ted12y.js → 54tqkxja.js} +20 -2
  26. package/dist/shared/{3p4b1fg0.js → 5enne4ma.js} +1 -1
  27. package/dist/shared/{bzsjtd7c.js → 6mnp99hx.js} +7 -6
  28. package/dist/shared/{ykv7wh5b.js → 6qd27mx0.js} +2 -2
  29. package/dist/shared/{h4nqvjkp.js → 6rk2gen5.js} +2 -2
  30. package/dist/shared/{r73pt594.js → 7zwwyh0v.js} +32 -10
  31. package/dist/shared/{fa9vt245.js → 87jvvhnt.js} +2 -2
  32. package/dist/shared/{c8aghh05.js → 8rsy3hxz.js} +7 -1
  33. package/dist/shared/{6p5k20sm.js → 96qcj21c.js} +3 -3
  34. package/dist/shared/{xsq7v6wp.js → aj2qxyhj.js} +2 -2
  35. package/dist/shared/{5vdm4sgp.js → caw8b9d8.js} +4 -4
  36. package/dist/shared/{xhh1srw3.js → cctw17hj.js} +23 -8
  37. package/dist/shared/{rrstp3kb.js → cgbamx3e.js} +2 -2
  38. package/dist/shared/{tq9afp8d.js → cr74e96e.js} +1 -1
  39. package/dist/shared/{b066g80h.js → efmy2gcg.js} +2 -2
  40. package/dist/shared/{gdh9mrtp.js → f5cw5q5r.js} +2 -2
  41. package/dist/shared/{ayz64vzj.js → ga3sfy93.js} +357 -3
  42. package/dist/shared/{qgvt8nx1.js → gbtcc2d7.js} +44 -3
  43. package/dist/shared/{kdkxh3kb.js → gde73es6.js} +5 -7
  44. package/dist/shared/{bt9sfq0z.js → hf22e0wt.js} +51 -17
  45. package/dist/shared/{990a291j.js → janx09m5.js} +6 -5
  46. package/dist/shared/{4ef7mmqf.js → jwtxdj06.js} +5 -5
  47. package/dist/shared/{sf8m6tfy.js → k8v5v5wj.js} +3 -3
  48. package/dist/shared/{r6pj4fq2.js → kfjp0gck.js} +2 -2
  49. package/dist/shared/{wqem4jed.js → krxx77g0.js} +7 -7
  50. package/dist/shared/{h8ne16fq.js → nkaxvt9q.js} +1 -1
  51. package/dist/shared/{jsd07prz.js → ntneex2a.js} +1 -1
  52. package/dist/shared/{nkc9sfqb.js → nxdp2ze3.js} +40 -4
  53. package/dist/shared/{tbszx8mz.js → pf0d8f77.js} +1 -1
  54. package/dist/shared/{qy9rdq0g.js → ps7a6h14.js} +6 -6
  55. package/dist/shared/{rasvvzgz.js → q58y17hy.js} +5 -5
  56. package/dist/shared/{p7pfx624.js → qm7cdtvr.js} +22 -9
  57. package/dist/shared/{xdpj5kkm.js → qv2ydck9.js} +149 -209
  58. package/dist/shared/{k7cc9nzk.js → r2sp8hrc.js} +6 -3
  59. package/dist/shared/{fb00y8fp.js → r8x5qhd7.js} +5 -5
  60. package/dist/shared/{fyqkk1m0.js → sdc7r2ww.js} +6 -5
  61. package/dist/shared/{wxn4b7pp.js → sycnx8gt.js} +42 -5
  62. package/dist/shared/{dxjp14rk.js → tm5ab8we.js} +2 -2
  63. package/dist/shared/{g516zdsb.js → v36c5g6p.js} +78 -19
  64. package/dist/shared/wq9n6pwr.js +139 -0
  65. package/dist/shared/{7p2wbz7f.js → x72jb7ad.js} +1 -1
  66. package/dist/shared/{922qbgnw.js → zqrnhwsq.js} +3 -3
  67. package/dist/tooling/cli.js +68 -21
  68. package/dist/tooling/migrate/commands.d.ts +1 -2
  69. package/dist/tooling/migrate/drift.d.ts +1 -1
  70. package/dist/tooling/migrate/estimate.d.ts +14 -1
  71. package/dist/tooling/migrate/index.js +8 -7
  72. package/dist/tooling/migrate/lint.d.ts +3 -3
  73. package/dist/tooling/migrate/plan.d.ts +7 -3
  74. package/dist/tooling/migrate/policy.d.ts +11 -0
  75. package/dist/tooling/migrate/sql-lex.d.ts +22 -0
  76. package/dist/tooling/testing/factories.d.ts +10 -0
  77. package/dist/tooling/testing/index.js +1 -1
  78. package/dist/tooling/testing/isolation.d.ts +4 -3
  79. package/package.json +6 -5
  80. package/dist/shared/0v1g424p.js +0 -26
@@ -2,14 +2,14 @@
2
2
  * Runs the migration linter.
3
3
  *
4
4
  * The linter reads a plan and the two catalogs. It does not connect.
5
- * An override is a `-- okm-allow` line on the statement. It silences only
6
- * the code it names, and only with a reason.
5
+ * An override is a `-- okm-allow` line on the step. It silences that code
6
+ * on every statement of the step, and only with a reason.
7
7
  */
8
8
  import type { Catalog } from "../../contracts/catalog/types.js";
9
9
  import { OkmError } from "../../contracts/error.js";
10
10
  import { type LintSeverity } from "./lint-rules.js";
11
11
  import { type MigrationPlan } from "./plan.js";
12
- /** One finding. `place` is `step N` or `table.column`, optionally prefixed with the file. */
12
+ /** One finding. `place` is `step N`, `step N statement M`, or `table.column`. */
13
13
  export type Finding = {
14
14
  readonly severity: LintSeverity;
15
15
  readonly code: string;
@@ -70,10 +70,10 @@ export type PlanStep = {
70
70
  */
71
71
  readonly behavior?: "change";
72
72
  /**
73
- * `-- okm-allow` lines directly above the statement.
73
+ * `-- okm-allow` lines on the step.
74
74
  *
75
- * A reason silences that code only. An empty reason, or a code the
76
- * statement did not trigger, is OKM1510 and silences nothing.
75
+ * A reason silences that code on every statement of the step. An empty
76
+ * reason, or a code no statement triggered, is OKM1510 and silences nothing.
77
77
  */
78
78
  readonly allows?: readonly StepAllow[];
79
79
  };
@@ -128,6 +128,10 @@ export declare function formatPlan(plan: MigrationPlan, lockText?: (step: PlanSt
128
128
  /**
129
129
  * Reads a plan written by {@link formatPlan}.
130
130
  *
131
+ * A blank line ends a step. A blank line inside a quote, a dollar quote, or
132
+ * a block comment stays in that step, and so does a `--` line while the
133
+ * quote is still open.
134
+ *
131
135
  * @param text - SQL file text
132
136
  * @returns The plan. The header class is kept when the file has no steps
133
137
  */
@@ -56,6 +56,17 @@ export declare function assertTargetAlias(targets: readonly TargetRecord[]): voi
56
56
  * @param allowPooler - The invocation opted in
57
57
  */
58
58
  export declare function assertDirectConnection(url: string, allowPooler: boolean): void;
59
+ /**
60
+ * Refuses a session whose backend pid changes between two statements.
61
+ *
62
+ * The two reads are separate round trips and are not wrapped in a
63
+ * transaction. A transaction-mode pooler can hand back a different backend
64
+ * for the second one. `--allow-pooler` skips the probe.
65
+ *
66
+ * @param readPid - Reads `pg_backend_pid()` on the session under test
67
+ * @param allowPooler - The invocation opted in
68
+ */
69
+ export declare function assertStableBackend(readPid: () => Promise<string>, allowPooler: boolean): Promise<void>;
59
70
  /**
60
71
  * Lists configured targets.
61
72
  *
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Splits one migration step into statements.
3
+ *
4
+ * Comments are removed. A semicolon splits only at the top level.
5
+ * `standard_conforming_strings` is on: a plain `'...'` ends on a single
6
+ * quote, and `''` is one quote inside it. `E'...'` still treats a backslash
7
+ * as an escape. A dollar quote runs until the same tag; a different tag
8
+ * inside it is text, so `$outer$ ... $inner$ ... $inner$ ... $outer$` stays
9
+ * one span. An unterminated string, quoted identifier, block comment, or
10
+ * dollar quote is one opaque tail. This function does not throw.
11
+ */
12
+ /** Statements of `sql`, comments removed, with no trailing semicolon. */
13
+ export declare function sqlStatements(sql: string): readonly string[];
14
+ /**
15
+ * Whether `sql` still has an open quote or block comment.
16
+ *
17
+ * A line comment does not count: it ends at the newline or at the end.
18
+ *
19
+ * @param sql - Step text accumulated so far
20
+ * @returns `true` when a later blank line is still inside that quote
21
+ */
22
+ export declare function sqlQuoteOpen(sql: string): boolean;
@@ -114,4 +114,14 @@ export declare function bindFactories(host: FactoryHost, definitions: Readonly<R
114
114
  * @returns The inserted row
115
115
  */
116
116
  export declare function insertRow(host: FactoryHost, table: string, overrides: Readonly<Record<string, unknown>> | undefined, children: Readonly<Record<string, number>> | undefined, inherited: string | undefined): Promise<Record<string, unknown>>;
117
+ /**
118
+ * Drops a cached factory row.
119
+ *
120
+ * `isolation()` deletes the row it inserted. A later table must not reuse that id.
121
+ *
122
+ * @param host - The open harness
123
+ * @param table - Table name
124
+ * @param tenant - Tenant scope, when the table is tenanted
125
+ */
126
+ export declare function forgetCached(host: FactoryHost, table: string, tenant: string | undefined): void;
117
127
  export {};
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  testing2
3
- } from "../../shared/g516zdsb.js";
3
+ } from "../../shared/v36c5g6p.js";
4
4
  import"../../shared/8xsbagad.js";
5
5
  import"../../shared/8bwbwy8h.js";
6
6
  export {
@@ -1,9 +1,10 @@
1
1
  /**
2
2
  * Cross-tenant isolation check.
3
3
  *
4
- * For every tenant table, insert one row as tenant B and run the basic reads
5
- * and writes as tenant A. A returned row, a count above zero, or an update or
6
- * delete that touches a row is a leak. Global tables are skipped and listed.
4
+ * For every tenant table, insert one row as tenant B and run the reads and
5
+ * writes as tenant A against that row's key. A returned row, or an update or
6
+ * delete that touches it, is a leak. The row is deleted afterwards. Global
7
+ * tables are skipped and listed.
7
8
  * Column tenancy is the strategy this version has. A table is tenant when its
8
9
  * predicate says so (D199).
9
10
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "okmodel",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "okmodel is a catalog-first TypeScript ORM, PostgreSQL first.",
5
5
  "keywords": [
6
6
  "migrations",
@@ -23,9 +23,6 @@
23
23
  "okm": "./dist/okm.js",
24
24
  "okmodel": "./dist/okmodel.js"
25
25
  },
26
- "workspaces": [
27
- "packages/*"
28
- ],
29
26
  "files": [
30
27
  "dist",
31
28
  "README.md",
@@ -112,7 +109,7 @@
112
109
  }
113
110
  },
114
111
  "scripts": {
115
- "build": "rm -rf dist && bun build ./src/contracts/index.ts ./src/contracts/internal.ts ./src/dialects/pg/index.ts ./src/runtime/pg/postgresjs.ts ./src/runtime/pg/pglite.ts ./src/runtime/pg/pg.ts ./src/runtime/pg/bun.ts ./src/runtime/ids/index.ts ./src/runtime/safety/index.ts ./src/runtime/traits/index.ts ./src/runtime/tenancy/index.ts ./src/runtime/validate/index.ts ./src/dialects/pg/ext/index.ts ./src/dialects/pg/fn/index.ts ./src/dialects/pg/view/index.ts ./src/dialects/pg/ext/citext.ts ./src/dialects/pg/ext/pg-trgm.ts ./src/tooling/migrate/index.ts ./src/tooling/testing/index.ts ./src/tooling/cli.ts --outdir ./dist --root ./src --format esm --target node --splitting --chunk-naming=shared/[hash].js --external postgres --external @electric-sql/pglite --external pg --external bun && bunx tsc -p tsconfig.build.json && bun ./scripts/write-bin-wrappers.ts",
112
+ "build": "rm -rf dist && bun build ./src/contracts/index.ts ./src/contracts/internal.ts ./src/dialects/pg/index.ts ./src/runtime/pg/postgresjs.ts ./src/runtime/pg/pglite.ts ./src/runtime/pg/pg.ts ./src/runtime/pg/bun.ts ./src/runtime/ids/index.ts ./src/runtime/safety/index.ts ./src/runtime/traits/index.ts ./src/runtime/tenancy/index.ts ./src/runtime/validate/index.ts ./src/dialects/pg/ext/index.ts ./src/dialects/pg/fn/index.ts ./src/dialects/pg/view/index.ts ./src/dialects/pg/ext/citext.ts ./src/dialects/pg/ext/pg-trgm.ts ./src/tooling/migrate/index.ts ./src/tooling/testing/index.ts ./src/tooling/cli.ts --outdir ./dist --root ./src --format esm --target node --splitting --chunk-naming=shared/[hash].js --external postgres --external @electric-sql/pglite --external pg --external bun && bunx tsc -p tsconfig.build.json && rm -f ./dist/dialects/pg/temporal.local.d.ts && bun ./scripts/write-bin-wrappers.ts",
116
113
  "driver-bench": "bun ./scripts/driver-bench.ts",
117
114
  "typecheck": "bunx tsc --noEmit -p tsconfig.json",
118
115
  "editor-check": "bun ./scripts/editor-check.ts",
@@ -129,6 +126,8 @@
129
126
  "compiler-api": "bun ./scripts/compiler-api.ts",
130
127
  "publint": "publint run . --strict --pack bun",
131
128
  "attw": "bun ./scripts/attw.ts",
129
+ "prepack": "bun ./scripts/strip-workspaces.ts strip",
130
+ "postpack": "bun ./scripts/strip-workspaces.ts restore",
132
131
  "size": "bun ./scripts/size.ts",
133
132
  "bundle-purity": "bun ./scripts/bundle-purity.ts",
134
133
  "test": "bun test",
@@ -157,6 +156,8 @@
157
156
  "oxlint": "^1.86.0",
158
157
  "oxlint-tsgolint": "^7.0.2003",
159
158
  "publint": "^0.3.24",
159
+ "temporal-polyfill": "^1.0.5",
160
+ "temporal-spec": "^1.0.1",
160
161
  "typescript": "7",
161
162
  "typescript-editor": "npm:typescript@6.0.3"
162
163
  },
@@ -1,26 +0,0 @@
1
- import {
2
- OkmError2
3
- } from "./52szzakm.js";
4
-
5
- // src/dialects/pg/filter-parse.ts
6
- function parseQuery(allow, sort, query) {
7
- if (typeof query !== "object" || query === null || Array.isArray(query)) {
8
- throw new OkmError2("OKM1121", "filters parse expects an object of fields.");
9
- }
10
- const where = {};
11
- let orderBy;
12
- for (const key of Object.keys(query)) {
13
- const value = query[key];
14
- if (key === "sort" && typeof value === "string" && sort.includes(value)) {
15
- orderBy = { [value]: "asc" };
16
- continue;
17
- }
18
- if (allow[key]?.includes("eq") === true && (value === null || typeof value !== "object")) {
19
- where[key] = value;
20
- }
21
- }
22
- return orderBy === undefined ? { where } : { where, orderBy };
23
- }
24
- export {
25
- parseQuery
26
- };