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,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DriverError2
|
|
3
|
+
} from "./cm3w0ywp.js";
|
|
4
|
+
import {
|
|
5
|
+
OkmError2
|
|
6
|
+
} from "./52szzakm.js";
|
|
7
|
+
|
|
8
|
+
// src/adapters/lazy-errors.ts
|
|
9
|
+
function refused() {
|
|
10
|
+
return Promise.reject(new OkmError2("OKM1120", "timeout"));
|
|
11
|
+
}
|
|
12
|
+
function closed() {
|
|
13
|
+
return Promise.reject(new DriverError2("The pool is closed.", { sqlstate: "08006" }));
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
closed,
|
|
17
|
+
refused
|
|
18
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// src/runtime/inflight.ts
|
|
2
|
+
async function refuseUncancellableTimeout(pool, timeout) {
|
|
3
|
+
if (pool.capabilities.cancel === true || timeout === undefined || !(timeout > 0))
|
|
4
|
+
return;
|
|
5
|
+
const { refused } = await import("./2c13q96h.js");
|
|
6
|
+
await refused();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { refuseUncancellableTimeout };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ensureMigrationTables2,
|
|
3
|
+
applyTarget2,
|
|
4
|
+
applyProject2,
|
|
5
|
+
pushProject2,
|
|
6
|
+
backfillTiming2
|
|
7
|
+
} from "./p6qc5gcp.js";
|
|
8
|
+
import"./m6p12kbr.js";
|
|
9
|
+
import"./8skf0cam.js";
|
|
10
|
+
import"./b5pftnn2.js";
|
|
11
|
+
import"./gs74dbj5.js";
|
|
12
|
+
import"./tsvww22q.js";
|
|
13
|
+
import"./n442h54c.js";
|
|
14
|
+
import"./9s0ypp87.js";
|
|
15
|
+
import"./qq3899ht.js";
|
|
16
|
+
import"./14vx95q4.js";
|
|
17
|
+
export {
|
|
18
|
+
applyProject2 as applyProject,
|
|
19
|
+
applyTarget2 as applyTarget,
|
|
20
|
+
backfillTiming2 as backfillTiming,
|
|
21
|
+
ensureMigrationTables2 as ensureMigrationTables,
|
|
22
|
+
pushProject2 as pushProject
|
|
23
|
+
};
|
|
@@ -503,7 +503,7 @@ function constraint2(input) {
|
|
|
503
503
|
const name = input.name === undefined ? deterministicName2({
|
|
504
504
|
parent: input.parent.name,
|
|
505
505
|
purpose: input.constraintKind,
|
|
506
|
-
nameKey
|
|
506
|
+
nameKey: input.constraintKind === "check" ? nameKey : defaultNameKey(input.constraintKind, columns)
|
|
507
507
|
}) : fitIdentifier2(input.name);
|
|
508
508
|
const identity = {
|
|
509
509
|
kind: "constraint",
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import {
|
|
2
|
+
refusePrototypeKey
|
|
3
|
+
} from "./q5c6ngn3.js";
|
|
4
|
+
import {
|
|
5
|
+
isBucket
|
|
6
|
+
} from "./nbw1z4yd.js";
|
|
7
|
+
import {
|
|
8
|
+
parseOrder,
|
|
9
|
+
projectExpr,
|
|
10
|
+
quote,
|
|
11
|
+
list,
|
|
12
|
+
isRecord,
|
|
13
|
+
fail2
|
|
14
|
+
} from "./67txcrcw.js";
|
|
15
|
+
import {
|
|
16
|
+
throwNamed2
|
|
17
|
+
} from "./52szzakm.js";
|
|
18
|
+
|
|
19
|
+
// src/runtime/bucket-group.ts
|
|
20
|
+
function readBucket(table, value, fields, aliases) {
|
|
21
|
+
if (!isBucket(value))
|
|
22
|
+
fail2("OKM1120", "bucket group");
|
|
23
|
+
const column = typeof value.column === "string" ? table.columns.get(value.column) : undefined;
|
|
24
|
+
if (typeof value.column !== "string" || column === undefined) {
|
|
25
|
+
throwNamed2("OKM1120", String(value.column), table.names, `Field ${String(value.column)} is not on ${table.model.name}. Accepted names: ${list(table.names)}.`);
|
|
26
|
+
}
|
|
27
|
+
if (column.hidden) {
|
|
28
|
+
fail2("OKM1120", `Field ${column.field} is hidden, so groupBy cannot read it.`);
|
|
29
|
+
}
|
|
30
|
+
const unit = unitOf(value.unit);
|
|
31
|
+
if (unit === undefined) {
|
|
32
|
+
fail2("OKM1120", `bucket() unit ${String(value.unit)} is not a time unit. Accepted units: second, minute, hour, day, week, month, quarter, year.`);
|
|
33
|
+
}
|
|
34
|
+
const shift = weekShift(value.weekStart, unit);
|
|
35
|
+
const kind = temporalKind(column.dataType);
|
|
36
|
+
if (kind !== "timestamptz" && kind !== "date") {
|
|
37
|
+
fail2("OKM1120", `bucket() does not apply to ${kind === "timestamp" ? "timestamp" : column.dataType} column ${column.field}. Use timestamptz or date.`);
|
|
38
|
+
}
|
|
39
|
+
if (kind === "date" && clockUnit(unit)) {
|
|
40
|
+
fail2("OKM1120", `bucket() unit ${unit} does not apply to date column ${column.field}. Accepted units: day, week, month, quarter, year.`);
|
|
41
|
+
}
|
|
42
|
+
let tz;
|
|
43
|
+
if (kind === "timestamptz") {
|
|
44
|
+
if (typeof value.tz !== "string") {
|
|
45
|
+
fail2("OKM1120", `bucket() on timestamptz column ${column.field} needs tz, an IANA time zone.`);
|
|
46
|
+
}
|
|
47
|
+
if (!iana(value.tz))
|
|
48
|
+
fail2("OKM1120", `bucket() tz ${value.tz} is not an IANA time zone.`);
|
|
49
|
+
tz = value.tz;
|
|
50
|
+
} else if (value.tz !== undefined) {
|
|
51
|
+
fail2("OKM1120", `bucket() on date column ${column.field} does not take tz.`);
|
|
52
|
+
}
|
|
53
|
+
if (typeof value.as !== "string" || value.as.length === 0) {
|
|
54
|
+
fail2("OKM1120", "bucket() needs as, the name of the result key.");
|
|
55
|
+
}
|
|
56
|
+
refusePrototypeKey(value.as, "bucket as");
|
|
57
|
+
if (value.as === "count" || value.as === "sum" || value.as === "avg" || value.as === "min" || value.as === "max") {
|
|
58
|
+
fail2("OKM1120", `bucket as ${value.as} clashes with an aggregate key.`);
|
|
59
|
+
}
|
|
60
|
+
if (fields.has(value.as) || aliases.has(value.as)) {
|
|
61
|
+
fail2("OKM1120", `bucket as ${value.as} clashes with another group.`);
|
|
62
|
+
}
|
|
63
|
+
aliases.add(value.as);
|
|
64
|
+
return { kind: "bucket", column, unit, tz, as: value.as, shift, clock: clockUnit(unit) };
|
|
65
|
+
}
|
|
66
|
+
function writeBucket(sink, outputs, wrote, group) {
|
|
67
|
+
if (wrote.at > 0)
|
|
68
|
+
sink.text(", ");
|
|
69
|
+
if (group.clock)
|
|
70
|
+
emitClock(sink, group);
|
|
71
|
+
else
|
|
72
|
+
emitCalendar(sink, group);
|
|
73
|
+
outputs?.fields.push({
|
|
74
|
+
key: `g:${group.as}`,
|
|
75
|
+
at: wrote.at,
|
|
76
|
+
decode: bucketDecode(group)
|
|
77
|
+
});
|
|
78
|
+
wrote.at += 1;
|
|
79
|
+
}
|
|
80
|
+
function writeGrouped(sink, names, orderBy) {
|
|
81
|
+
sink.text(ordinals(names.length));
|
|
82
|
+
if (isRecord(orderBy) && Object.keys(orderBy).length > 0) {
|
|
83
|
+
sink.text(" order by ");
|
|
84
|
+
const keys = Object.keys(orderBy);
|
|
85
|
+
for (let index = 0;index < keys.length; index += 1) {
|
|
86
|
+
const key = keys[index];
|
|
87
|
+
if (key === undefined)
|
|
88
|
+
continue;
|
|
89
|
+
const parsed = parseOrder(key, orderBy[key]);
|
|
90
|
+
if (index > 0)
|
|
91
|
+
sink.text(", ");
|
|
92
|
+
sink.text(String(names.indexOf(key) + 1));
|
|
93
|
+
sink.text(parsed.dir === "asc" ? " asc" : " desc");
|
|
94
|
+
sink.text(parsed.nulls === "first" ? " nulls first" : " nulls last");
|
|
95
|
+
sink.mark(`o:${key}:${parsed.dir}:${parsed.nulls}`);
|
|
96
|
+
}
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
sink.text(" order by ");
|
|
100
|
+
const parts = [];
|
|
101
|
+
for (let index = 1;index <= names.length; index += 1) {
|
|
102
|
+
parts.push(`${String(index)} asc nulls last`);
|
|
103
|
+
}
|
|
104
|
+
sink.text(parts.join(", "));
|
|
105
|
+
}
|
|
106
|
+
function unitOf(value) {
|
|
107
|
+
if (value === "second" || value === "minute" || value === "hour" || value === "day" || value === "week" || value === "month" || value === "quarter" || value === "year") {
|
|
108
|
+
return value;
|
|
109
|
+
}
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
function clockUnit(unit) {
|
|
113
|
+
return unit === "second" || unit === "minute" || unit === "hour";
|
|
114
|
+
}
|
|
115
|
+
function weekShift(value, unit) {
|
|
116
|
+
if (value === undefined)
|
|
117
|
+
return 0;
|
|
118
|
+
if (unit !== "week")
|
|
119
|
+
fail2("OKM1120", "bucket() weekStart applies to unit week.");
|
|
120
|
+
if (value === "monday")
|
|
121
|
+
return 0;
|
|
122
|
+
if (value === "sunday")
|
|
123
|
+
return 1;
|
|
124
|
+
if (value === "saturday")
|
|
125
|
+
return 2;
|
|
126
|
+
return fail2("OKM1120", "bucket() weekStart must be monday, sunday, or saturday.");
|
|
127
|
+
}
|
|
128
|
+
function temporalKind(dataType) {
|
|
129
|
+
if (dataType === "date")
|
|
130
|
+
return "date";
|
|
131
|
+
if (dataType === "timestamptz" || dataType.startsWith("timestamptz("))
|
|
132
|
+
return "timestamptz";
|
|
133
|
+
if (dataType === "timestamp" || dataType.startsWith("timestamp("))
|
|
134
|
+
return "timestamp";
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
function iana(tz) {
|
|
138
|
+
try {
|
|
139
|
+
Intl.DateTimeFormat("en-US", { timeZone: tz });
|
|
140
|
+
return true;
|
|
141
|
+
} catch {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function bucketDecode(group) {
|
|
146
|
+
if (group.clock || !group.column.dataType.startsWith("timestamptz"))
|
|
147
|
+
return group.column.decode;
|
|
148
|
+
return decodeDay;
|
|
149
|
+
}
|
|
150
|
+
function decodeDay(wire) {
|
|
151
|
+
const temporal = globalThis.Temporal;
|
|
152
|
+
if (typeof temporal !== "object" || temporal === null || !("PlainDate" in temporal)) {
|
|
153
|
+
return fail2("OKM1120", "Date and time codecs need the Temporal global. okmodel does not ship a polyfill. Use a runtime that provides Temporal, or assign a polyfill to globalThis.Temporal before using these columns.");
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
return temporal.PlainDate.from(wire);
|
|
157
|
+
} catch {
|
|
158
|
+
return fail2("OKM1120", `date ${wire} must be YYYY-MM-DD.`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
var ZONE = "\x00";
|
|
162
|
+
function emitClock(sink, group) {
|
|
163
|
+
const column = `t.${quote(group.column.sql)}`;
|
|
164
|
+
const wrapped = projectExpr(`date_trunc('${group.unit}', ${column}, ${ZONE})`, "timestamptz");
|
|
165
|
+
const at = wrapped.indexOf(ZONE);
|
|
166
|
+
sink.text(wrapped.slice(0, at));
|
|
167
|
+
sink.param(group.tz ?? "");
|
|
168
|
+
sink.text(wrapped.slice(at + ZONE.length));
|
|
169
|
+
}
|
|
170
|
+
function emitCalendar(sink, group) {
|
|
171
|
+
const column = `t.${quote(group.column.sql)}`;
|
|
172
|
+
sink.text("(date_trunc('");
|
|
173
|
+
sink.text(group.unit);
|
|
174
|
+
sink.text("', ");
|
|
175
|
+
emitLocal(sink, column, group.tz);
|
|
176
|
+
if (group.shift === 0) {
|
|
177
|
+
sink.text("))::date");
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
const days = group.shift === 1 ? "1 day" : "2 days";
|
|
181
|
+
sink.text(" + interval '");
|
|
182
|
+
sink.text(days);
|
|
183
|
+
sink.text("') - interval '");
|
|
184
|
+
sink.text(days);
|
|
185
|
+
sink.text("')::date");
|
|
186
|
+
}
|
|
187
|
+
function emitLocal(sink, column, tz) {
|
|
188
|
+
if (tz === undefined) {
|
|
189
|
+
sink.text(column);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
sink.text("(");
|
|
193
|
+
sink.text(column);
|
|
194
|
+
sink.text(" AT TIME ZONE ");
|
|
195
|
+
sink.param(tz);
|
|
196
|
+
sink.text(")");
|
|
197
|
+
}
|
|
198
|
+
function ordinals(count) {
|
|
199
|
+
const parts = [];
|
|
200
|
+
for (let index = 1;index <= count; index += 1)
|
|
201
|
+
parts.push(String(index));
|
|
202
|
+
return parts.join(", ");
|
|
203
|
+
}
|
|
204
|
+
export {
|
|
205
|
+
readBucket,
|
|
206
|
+
writeBucket,
|
|
207
|
+
writeGrouped
|
|
208
|
+
};
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import {
|
|
2
|
+
encodeUuid,
|
|
3
|
+
decodeUuid
|
|
4
|
+
} from "./hyh73qk6.js";
|
|
5
|
+
import {
|
|
6
|
+
encodeText,
|
|
7
|
+
decodeText
|
|
8
|
+
} from "./ed0b8k4s.js";
|
|
9
|
+
import {
|
|
10
|
+
snakeCase
|
|
11
|
+
} from "./rpycarcr.js";
|
|
12
|
+
import {
|
|
13
|
+
OkmError2
|
|
14
|
+
} from "./52szzakm.js";
|
|
15
|
+
|
|
16
|
+
// src/dialects/pg/view/client.ts
|
|
17
|
+
var globalViews = new WeakMap;
|
|
18
|
+
function viewGlobalReason(model) {
|
|
19
|
+
return globalViews.get(model);
|
|
20
|
+
}
|
|
21
|
+
function viewMentions(query, name) {
|
|
22
|
+
let pattern = '(^|[^A-Za-z0-9_])"?';
|
|
23
|
+
for (const char of name) {
|
|
24
|
+
if ("\\^$[]().*+?|{}".includes(char))
|
|
25
|
+
pattern += "\\";
|
|
26
|
+
pattern += char;
|
|
27
|
+
}
|
|
28
|
+
pattern += '"?(?![A-Za-z0-9_])';
|
|
29
|
+
return new RegExp(pattern).test(query);
|
|
30
|
+
}
|
|
31
|
+
function viewClient(name, columns, query, tenancy, refresh = "plain") {
|
|
32
|
+
const field = camelCase(name);
|
|
33
|
+
const marked = readGlobal(name, tenancy);
|
|
34
|
+
return {
|
|
35
|
+
field,
|
|
36
|
+
install(model, scope, tables, casing, scoped) {
|
|
37
|
+
if (Object.hasOwn(model, field)) {
|
|
38
|
+
throw new OkmError2("OKM1023", `View ${name} uses the client name ${field}.`, {
|
|
39
|
+
fix: { summary: "Give the view a name that no table uses." }
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const exposes = exposesKey(columns, scope);
|
|
43
|
+
if (scope !== undefined && readsTenant(query, tables, casing, scoped)) {
|
|
44
|
+
if (!exposes && marked === undefined) {
|
|
45
|
+
throw new OkmError2("OKM1820", `View ${name} reads a tenant table and does not expose ${scope.key}.`, {
|
|
46
|
+
fix: {
|
|
47
|
+
summary: "Expose the tenant key so the predicate can be applied, or declare global(reason)."
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (exposes) {
|
|
52
|
+
scope.scopeView(field);
|
|
53
|
+
scoped.add(name);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const built = {
|
|
57
|
+
name: field,
|
|
58
|
+
sql: name,
|
|
59
|
+
primary: [],
|
|
60
|
+
uniques: [],
|
|
61
|
+
columns: columnModels(columns, scope),
|
|
62
|
+
relations: []
|
|
63
|
+
};
|
|
64
|
+
if (marked !== undefined)
|
|
65
|
+
globalViews.set(built, marked);
|
|
66
|
+
model[field] = built;
|
|
67
|
+
},
|
|
68
|
+
hook(target, ctx) {
|
|
69
|
+
if (ctx.table === field && ctx.session !== undefined) {
|
|
70
|
+
if (refresh !== "plain")
|
|
71
|
+
target.refresh = refreshHandle(ctx.session, name, refresh);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
publish(field, target, ctx);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function refreshHandle(session, name, mode) {
|
|
79
|
+
const concurrently = mode === "concurrently";
|
|
80
|
+
return () => lazyRefresh(() => import("./z7s6fpxv.js").then((mod) => mod.refreshView(session, name, concurrently)));
|
|
81
|
+
}
|
|
82
|
+
function lazyRefresh(run) {
|
|
83
|
+
let pending;
|
|
84
|
+
const once = () => {
|
|
85
|
+
pending ??= run();
|
|
86
|
+
return pending;
|
|
87
|
+
};
|
|
88
|
+
const self = {
|
|
89
|
+
then(onFulfilled, onRejected) {
|
|
90
|
+
return once().then(onFulfilled, onRejected);
|
|
91
|
+
},
|
|
92
|
+
catch(onRejected) {
|
|
93
|
+
return self.then(undefined, onRejected);
|
|
94
|
+
},
|
|
95
|
+
finally(fn) {
|
|
96
|
+
return self.then((value) => {
|
|
97
|
+
fn();
|
|
98
|
+
return value;
|
|
99
|
+
}, (error) => {
|
|
100
|
+
fn();
|
|
101
|
+
throw error;
|
|
102
|
+
});
|
|
103
|
+
},
|
|
104
|
+
"~refresh": true
|
|
105
|
+
};
|
|
106
|
+
return self;
|
|
107
|
+
}
|
|
108
|
+
function publish(field, target, ctx) {
|
|
109
|
+
if (ctx.tables === undefined || ctx.table !== undefined)
|
|
110
|
+
return;
|
|
111
|
+
const handle = ctx.tables[field];
|
|
112
|
+
if (typeof handle !== "object" || handle === null)
|
|
113
|
+
return;
|
|
114
|
+
const source = handle;
|
|
115
|
+
const views = target.views;
|
|
116
|
+
const map = typeof views === "object" && views !== null ? views : {};
|
|
117
|
+
map[field] = {
|
|
118
|
+
find: source.find,
|
|
119
|
+
one: source.one,
|
|
120
|
+
count: source.count,
|
|
121
|
+
exists: source.exists,
|
|
122
|
+
...typeof source.refresh === "function" ? { refresh: source.refresh } : {}
|
|
123
|
+
};
|
|
124
|
+
target.views = map;
|
|
125
|
+
delete ctx.tables[field];
|
|
126
|
+
delete target[field];
|
|
127
|
+
}
|
|
128
|
+
function columnModels(columns, tenancy) {
|
|
129
|
+
const seen = new Set;
|
|
130
|
+
const models = [];
|
|
131
|
+
for (const column of columns) {
|
|
132
|
+
const field = fieldName(column.name, tenancy);
|
|
133
|
+
if (seen.has(field)) {
|
|
134
|
+
throw new OkmError2("OKM1020", `View column ${column.name} repeats ${field}.`, {
|
|
135
|
+
fix: { summary: "Declare each output column once." }
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
seen.add(field);
|
|
139
|
+
const uuid = column.type.toLowerCase() === "uuid";
|
|
140
|
+
const key = tenancy !== undefined && field === tenancy.key;
|
|
141
|
+
models.push({
|
|
142
|
+
field,
|
|
143
|
+
sql: column.name,
|
|
144
|
+
dataType: column.type,
|
|
145
|
+
encode: uuid ? (value) => encodeUuid(textValue(value)) : (value) => encodeText(textValue(value)),
|
|
146
|
+
decode: uuid ? decodeUuid : decodeText,
|
|
147
|
+
hidden: false,
|
|
148
|
+
sensitive: false,
|
|
149
|
+
guarded: key,
|
|
150
|
+
writable: false,
|
|
151
|
+
guardUpdate: false
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
return models;
|
|
155
|
+
}
|
|
156
|
+
function exposesKey(columns, tenancy) {
|
|
157
|
+
if (tenancy === undefined)
|
|
158
|
+
return false;
|
|
159
|
+
return columns.some((column) => fieldName(column.name, tenancy) === tenancy.key);
|
|
160
|
+
}
|
|
161
|
+
function readsTenant(query, tables, casing, scoped) {
|
|
162
|
+
for (const name of scoped) {
|
|
163
|
+
if (viewMentions(query, name))
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
for (const table of tables) {
|
|
167
|
+
const mark = table.options?.tenancy;
|
|
168
|
+
if (isGlobalMark(mark))
|
|
169
|
+
continue;
|
|
170
|
+
const sql = casing === "snake" ? snakeCase(table.name) : table.name;
|
|
171
|
+
if (viewMentions(query, sql) || viewMentions(query, table.name))
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
function readGlobal(name, tenancy) {
|
|
177
|
+
if (tenancy === undefined)
|
|
178
|
+
return;
|
|
179
|
+
if (!isGlobalMark(tenancy)) {
|
|
180
|
+
throw new OkmError2("OKM1020", `View ${name} tenancy must be global("reason").`, {
|
|
181
|
+
fix: { summary: 'Pass global("reason") from okmodel/tenancy, or omit tenancy.' }
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
return tenancy.reason;
|
|
185
|
+
}
|
|
186
|
+
function isGlobalMark(value) {
|
|
187
|
+
if (typeof value !== "object" || value === null)
|
|
188
|
+
return false;
|
|
189
|
+
const record = value;
|
|
190
|
+
return record.kind === "global" && typeof record.reason === "string" && record.reason.trim().length > 0;
|
|
191
|
+
}
|
|
192
|
+
function fieldName(column, tenancy) {
|
|
193
|
+
const field = camelCase(column);
|
|
194
|
+
if (tenancy !== undefined && (column === tenancy.key || field === tenancy.key))
|
|
195
|
+
return tenancy.key;
|
|
196
|
+
return field;
|
|
197
|
+
}
|
|
198
|
+
function camelCase(name) {
|
|
199
|
+
let out = "";
|
|
200
|
+
let upper = false;
|
|
201
|
+
for (const char of name) {
|
|
202
|
+
if (char === "_") {
|
|
203
|
+
upper = out.length > 0;
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
out += upper ? char.toUpperCase() : char;
|
|
207
|
+
upper = false;
|
|
208
|
+
}
|
|
209
|
+
return out;
|
|
210
|
+
}
|
|
211
|
+
function textValue(value) {
|
|
212
|
+
if (typeof value !== "string") {
|
|
213
|
+
throw new OkmError2("OKM1121", "A view column value must be text.", {
|
|
214
|
+
fix: { summary: "Pass a string." }
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
return value;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export { viewGlobalReason, viewMentions, viewClient };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WRITE_PARAM_BUDGET2,
|
|
3
|
+
executeWrite2,
|
|
4
|
+
explainWrite2,
|
|
5
|
+
updateSliceBody2,
|
|
6
|
+
rejectDuplicateTargets2,
|
|
7
|
+
emitSet2,
|
|
8
|
+
Sql2,
|
|
9
|
+
writeSet2,
|
|
10
|
+
rejectMixedSets2,
|
|
11
|
+
readClaim2,
|
|
12
|
+
rejectUpdateKeys2,
|
|
13
|
+
requireFilter2,
|
|
14
|
+
returningOption2,
|
|
15
|
+
expectOf2,
|
|
16
|
+
allowSet2,
|
|
17
|
+
noteGuarded2
|
|
18
|
+
} from "./1w508jbr.js";
|
|
19
|
+
import"./mss6ctgv.js";
|
|
20
|
+
export {
|
|
21
|
+
Sql2 as Sql,
|
|
22
|
+
WRITE_PARAM_BUDGET2 as WRITE_PARAM_BUDGET,
|
|
23
|
+
allowSet2 as allowSet,
|
|
24
|
+
emitSet2 as emitSet,
|
|
25
|
+
executeWrite2 as executeWrite,
|
|
26
|
+
expectOf2 as expectOf,
|
|
27
|
+
explainWrite2 as explainWrite,
|
|
28
|
+
noteGuarded2 as noteGuarded,
|
|
29
|
+
readClaim2 as readClaim,
|
|
30
|
+
rejectDuplicateTargets2 as rejectDuplicateTargets,
|
|
31
|
+
rejectMixedSets2 as rejectMixedSets,
|
|
32
|
+
rejectUpdateKeys2 as rejectUpdateKeys,
|
|
33
|
+
requireFilter2 as requireFilter,
|
|
34
|
+
returningOption2 as returningOption,
|
|
35
|
+
updateSliceBody2 as updateSliceBody,
|
|
36
|
+
writeSet2 as writeSet
|
|
37
|
+
};
|