okmodel 0.7.0 → 0.9.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 +14 -0
- package/dist/adapters/capabilities.d.ts +32 -0
- package/dist/adapters/failure.d.ts +1 -1
- package/dist/adapters/pg/bun-sql.d.ts +53 -0
- package/dist/adapters/pg/bunsql-extra.d.ts +1 -1
- package/dist/adapters/pg/bunsql.d.ts +1 -1
- package/dist/adapters/pg/neon-extra.d.ts +18 -0
- package/dist/adapters/pg/neon.d.ts +104 -0
- package/dist/adapters/pg/no-inflight-timeout.d.ts +1 -1
- package/dist/contracts/error.d.ts +1 -1
- package/dist/dialects/pg/ext/btree-gin.d.ts +26 -0
- package/dist/dialects/pg/ext/btree-gin.js +20 -0
- package/dist/dialects/pg/ext/btree-gist.d.ts +26 -0
- package/dist/dialects/pg/ext/btree-gist.js +20 -0
- package/dist/dialects/pg/ext/call.d.ts +53 -0
- package/dist/dialects/pg/ext/citext.js +1 -1
- package/dist/dialects/pg/ext/feature.d.ts +26 -0
- package/dist/dialects/pg/ext/fuzzystrmatch.d.ts +34 -0
- package/dist/dialects/pg/ext/fuzzystrmatch.js +33 -0
- package/dist/dialects/pg/ext/hstore.d.ts +41 -0
- package/dist/dialects/pg/ext/hstore.js +29 -0
- package/dist/dialects/pg/ext/index.d.ts +56 -0
- package/dist/dialects/pg/ext/index.js +1 -1
- package/dist/dialects/pg/ext/ltree.d.ts +41 -0
- package/dist/dialects/pg/ext/ltree.js +29 -0
- package/dist/dialects/pg/ext/pg-trgm.js +4 -13
- package/dist/dialects/pg/ext/pgcrypto.d.ts +33 -0
- package/dist/dialects/pg/ext/pgcrypto.js +33 -0
- package/dist/dialects/pg/ext/unaccent.d.ts +26 -0
- package/dist/dialects/pg/ext/unaccent.js +21 -0
- package/dist/dialects/pg/ext/using.d.ts +23 -0
- package/dist/dialects/pg/ext/versions.d.ts +36 -0
- package/dist/dialects/pg/external.d.ts +19 -0
- package/dist/dialects/pg/fn/index.d.ts +39 -1
- package/dist/dialects/pg/fn/index.js +118 -26
- package/dist/dialects/pg/index.d.ts +3 -0
- package/dist/dialects/pg/index.js +394 -14
- package/dist/dialects/pg/introspect.d.ts +11 -0
- package/dist/dialects/pg/operators.d.ts +1 -1
- package/dist/dialects/pg/ops/fragment.d.ts +119 -0
- package/dist/dialects/pg/ops/lane.d.ts +49 -0
- package/dist/dialects/pg/view/client.d.ts +14 -6
- package/dist/dialects/pg/view/index.d.ts +73 -1
- package/dist/dialects/pg/view/index.js +156 -5
- package/dist/dialects/pg/view/scratch.d.ts +11 -5
- package/dist/runtime/artifact-file.d.ts +22 -0
- package/dist/runtime/client.d.ts +10 -0
- package/dist/runtime/drift-detail.d.ts +2 -1
- package/dist/runtime/drift.d.ts +3 -10
- package/dist/runtime/otel.d.ts +105 -0
- package/dist/runtime/otel.js +97 -0
- package/dist/runtime/pg/bun.js +4 -4
- package/dist/runtime/pg/neon.d.ts +38 -0
- package/dist/runtime/pg/neon.js +64 -0
- package/dist/runtime/pg/pg.js +4 -4
- package/dist/runtime/pg/pglite.js +4 -4
- package/dist/runtime/pg/postgresjs.js +4 -4
- package/dist/runtime/plan.d.ts +1 -1
- package/dist/runtime/server-check.d.ts +36 -6
- package/dist/runtime/sql-fragment.d.ts +43 -0
- package/dist/runtime/tenancy/index.js +10 -10
- package/dist/runtime/topology.d.ts +1 -1
- package/dist/runtime/traits/index.js +16 -17
- package/dist/runtime/types.d.ts +15 -1
- package/dist/runtime/validate/index.js +4 -4
- package/dist/shared/{81ebdx9p.js → 0j6qe91y.js} +4 -4
- package/dist/shared/{qq3899ht.js → 12z7aznj.js} +243 -14
- package/dist/shared/{gzaveazc.js → 1d9q9cv2.js} +29 -2
- package/dist/shared/{w79hsckn.js → 1mxm04fy.js} +5 -5
- package/dist/shared/{7k9grvf6.js → 2szgv6yj.js} +5 -5
- package/dist/shared/{gs74dbj5.js → 2zdxkt7b.js} +933 -111
- package/dist/shared/{m6p12kbr.js → 3456242y.js} +23 -23
- package/dist/shared/3bb7wsqt.js +99 -0
- package/dist/shared/{y6njgyda.js → 3t6kw83m.js} +2 -2
- package/dist/shared/{xhfsfkgk.js → 4vbf83xx.js} +9 -2
- package/dist/shared/{pt94kz7f.js → 5kyb3tqx.js} +1 -1
- package/dist/shared/61bmrmhr.js +35 -0
- package/dist/shared/{x933k9a3.js → 62b603gr.js} +10 -10
- package/dist/shared/{jgqj11w4.js → 6f0z3hzh.js} +4 -0
- package/dist/shared/{tsvww22q.js → 6nae0spm.js} +156 -95
- package/dist/shared/{mtaszv5a.js → 71n0jmhc.js} +102 -4
- package/dist/shared/{5e3tf63j.js → 760ppr76.js} +14 -6
- package/dist/shared/7ba5h6pb.js +17 -0
- package/dist/shared/{sfz1ksn6.js → 8jesqsrk.js} +2 -2
- package/dist/shared/{5v3xf80k.js → 8n688yjg.js} +1 -1
- package/dist/shared/{rs73fca9.js → 8qzkd9f3.js} +6 -6
- package/dist/shared/{ax7qv55k.js → 90sg0w5a.js} +202 -25
- package/dist/shared/{zm0ptry0.js → 99qp9vtg.js} +1 -1
- package/dist/shared/{xnxsed62.js → 9dr2qnx7.js} +14 -14
- package/dist/shared/{1w508jbr.js → 9dtgn1z2.js} +21 -17
- package/dist/shared/{h15jx9bc.js → 9dvh1dr6.js} +1 -1
- package/dist/shared/{q5c6ngn3.js → a62rb2da.js} +1 -1
- package/dist/shared/{te5as7z7.js → aksb89mn.js} +3 -3
- package/dist/shared/{bz84tkzm.js → bphrgwz9.js} +2 -2
- package/dist/shared/bsek72fg.js +225 -0
- package/dist/shared/{7mnme5tn.js → c3mvnq7a.js} +1 -1
- package/dist/shared/{p6qc5gcp.js → ccsmhv9r.js} +25 -7
- package/dist/shared/{pbp1ss85.js → cexb7z6b.js} +2 -2
- package/dist/shared/{ab9gmbwy.js → cf8zdz5p.js} +5 -5
- package/dist/shared/{jvd0mqag.js → ckz05z15.js} +5 -5
- package/dist/shared/{dk8v79p3.js → d5nmj7vv.js} +1 -1
- package/dist/shared/{14vx95q4.js → dd5pmnky.js} +7 -7
- package/dist/shared/{vb6qfyve.js → ds229x4r.js} +2 -2
- package/dist/shared/{1qa0qajz.js → e275q7sd.js} +1 -1
- package/dist/shared/{zp9fmend.js → ebhz8vh6.js} +4 -4
- package/dist/shared/{hyh73qk6.js → ecn8mfdq.js} +5 -5
- package/dist/shared/{je4axnm8.js → fdsz3w80.js} +2 -2
- package/dist/shared/{9s0ypp87.js → fk9vef30.js} +85 -74
- package/dist/shared/{g6evj1j3.js → g89fmz5s.js} +1 -1
- package/dist/shared/{aytqh5y2.js → ghqzdp94.js} +2 -2
- package/dist/shared/h9811jjm.js +17 -0
- package/dist/shared/{dkxgzaqd.js → hqpxf4a4.js} +1 -1
- package/dist/shared/{8skf0cam.js → jpybhf98.js} +1 -1
- package/dist/shared/{67txcrcw.js → kgwp4jdd.js} +4 -4
- package/dist/shared/kzgrnckd.js +29 -0
- package/dist/shared/mazpbcdj.js +233 -0
- package/dist/shared/{kb2sdhfb.js → mfvx6kjx.js} +17 -1
- package/dist/shared/{svncdeh5.js → mgaq2sd3.js} +11 -8
- package/dist/shared/{5mtf6cj3.js → mvmm3xpb.js} +5 -2
- package/dist/shared/{b5pftnn2.js → myk8fswx.js} +66 -21
- package/dist/shared/{2shdbn8q.js → n306gqkd.js} +9 -9
- package/dist/shared/{n816peh1.js → n454kcnw.js} +1 -1
- package/dist/shared/n5whk3mt.js +665 -0
- package/dist/shared/n7kg8mmx.js +61 -0
- package/dist/shared/{vqrjpcqn.js → nmnsgj7x.js} +1 -1
- package/dist/shared/{tbrvgw6z.js → npdftanb.js} +19 -26
- package/dist/shared/{ek2wt2dz.js → pg4ezgyf.js} +11 -30
- package/dist/shared/{5fe3kbsh.js → pgsak1yw.js} +1 -1
- package/dist/shared/{bm22fvzr.js → qfw14tna.js} +2 -2
- package/dist/shared/{wa07eas9.js → qvwwp1mp.js} +62 -41
- package/dist/shared/rbxt795q.js +1766 -0
- package/dist/shared/{xjk7hnn5.js → s7he5e5d.js} +2 -2
- package/dist/shared/{w72kgg4q.js → ss2kv2rs.js} +6 -6
- package/dist/shared/stfa9xcw.js +450 -0
- package/dist/shared/{3v7t1yrv.js → th3be82n.js} +2 -2
- package/dist/shared/{79dt02vc.js → tr64w5p0.js} +1 -1
- package/dist/shared/{cn957f8d.js → tw1nvvfj.js} +3 -3
- package/dist/shared/{ed0b8k4s.js → typ3vy7t.js} +1 -1
- package/dist/shared/{9628a9xt.js → vk7rag46.js} +1 -1
- package/dist/shared/{ze4hxsmy.js → w9ejzaqf.js} +1 -1
- package/dist/shared/{vczs8gd4.js → wvtjg5m3.js} +2 -2
- package/dist/shared/{9y3mmmh1.js → xfhe73sb.js} +1 -1
- package/dist/shared/xqacq37x.js +61 -0
- package/dist/shared/{1est4ezg.js → xtsydxjg.js} +3 -3
- package/dist/shared/xv8qj97g.js +96 -0
- package/dist/shared/{bg3rym3g.js → xwhdcrm4.js} +2 -2
- package/dist/shared/{kr0jzbw2.js → yvabyg9k.js} +7 -7
- package/dist/shared/yybhre6n.js +136 -0
- package/dist/shared/zdqf8k5d.js +8 -0
- package/dist/shared/{jznfax0y.js → zq1he88x.js} +4 -4
- package/dist/tooling/cli.js +108 -23
- package/dist/tooling/driver-run.js +4654 -0
- package/dist/tooling/driver-test.d.ts +36 -0
- package/dist/tooling/github/comment.d.ts +50 -0
- package/dist/tooling/github/post-comment.d.ts +17 -0
- package/dist/tooling/migrate/commands.d.ts +3 -2
- package/dist/tooling/migrate/config.d.ts +13 -0
- package/dist/tooling/migrate/export.d.ts +165 -0
- package/dist/tooling/migrate/ext-surface.d.ts +80 -0
- package/dist/tooling/migrate/ext.d.ts +31 -4
- package/dist/tooling/migrate/import-drizzle.d.ts +40 -0
- package/dist/tooling/migrate/index.d.ts +3 -0
- package/dist/tooling/migrate/index.js +55 -10
- package/dist/tooling/migrate/lint-rules.d.ts +18 -1
- package/dist/tooling/migrate/lint.d.ts +14 -1
- package/dist/tooling/migrate/place.d.ts +18 -0
- package/dist/tooling/migrate/plan-json.d.ts +65 -0
- package/dist/tooling/migrate/project.d.ts +13 -1
- package/dist/tooling/migrate/pull-emit.d.ts +98 -0
- package/dist/tooling/migrate/pull-routines.d.ts +126 -0
- package/dist/tooling/migrate/pull-verify.d.ts +26 -0
- package/dist/tooling/migrate/pull.d.ts +62 -0
- package/dist/tooling/migrate/reprint.d.ts +32 -0
- package/dist/tooling/migrate/sandbox.d.ts +8 -2
- package/dist/tooling/migrate/schema-api.d.ts +43 -0
- package/dist/tooling/migrate/sql-lex.d.ts +18 -0
- package/dist/tooling/shared/04svnxxj.js +344 -0
- package/dist/tooling/shared/0j0jtse1.js +13 -0
- package/dist/tooling/shared/0r05zhyq.js +618 -0
- package/dist/tooling/shared/1800eymw.js +49 -0
- package/dist/tooling/shared/35zemrmf.js +12 -0
- package/dist/tooling/shared/3rmaz3pq.js +140 -0
- package/dist/tooling/shared/3yn79q5m.js +12 -0
- package/dist/tooling/shared/54tqkxja.js +51 -0
- package/dist/tooling/shared/57btdkgm.js +209 -0
- package/dist/tooling/shared/5bmksndh.js +118 -0
- package/dist/tooling/shared/5p8km5jb.js +38 -0
- package/dist/tooling/shared/5x3pf400.js +185 -0
- package/dist/tooling/shared/5zrzffnk.js +6 -0
- package/dist/tooling/shared/62fxpc1p.js +332 -0
- package/dist/tooling/shared/68tf18v4.js +20 -0
- package/dist/tooling/shared/6vk28rjp.js +98 -0
- package/dist/tooling/shared/76pv6qff.js +9 -0
- package/dist/tooling/shared/7aews1zg.js +311 -0
- package/dist/tooling/shared/7b3xp9gc.js +195 -0
- package/dist/tooling/shared/7kms6fvj.js +20 -0
- package/dist/tooling/shared/7pxncnzs.js +40 -0
- package/dist/tooling/shared/829fjxyw.js +198 -0
- package/dist/tooling/shared/8m5znpdt.js +66 -0
- package/dist/tooling/shared/8yr7ges1.js +211 -0
- package/dist/tooling/shared/96ps4g1z.js +32 -0
- package/dist/tooling/shared/9qr9rkbh.js +143 -0
- package/dist/tooling/shared/9sfbtwsk.js +49 -0
- package/dist/tooling/shared/9wsnsvbf.js +10 -0
- package/dist/tooling/shared/a2xe04bm.js +18 -0
- package/dist/tooling/shared/a4pzghha.js +20 -0
- package/dist/tooling/shared/am04v8na.js +233 -0
- package/dist/tooling/shared/asgr07mp.js +194 -0
- package/dist/tooling/shared/c0xevn1h.js +312 -0
- package/dist/tooling/shared/dhatassp.js +134 -0
- package/dist/tooling/shared/ezqn88nj.js +1696 -0
- package/dist/tooling/shared/f77nnfqy.js +231 -0
- package/dist/tooling/shared/fh07z1dt.js +15 -0
- package/dist/tooling/shared/gqwevek4.js +81 -0
- package/dist/tooling/shared/hfq3n3bd.js +4116 -0
- package/dist/tooling/shared/htnaj77v.js +17 -0
- package/dist/tooling/shared/j664qjrt.js +64 -0
- package/dist/tooling/shared/jpgmjsx3.js +38 -0
- package/dist/tooling/shared/jr2nmr81.js +497 -0
- package/dist/tooling/shared/jsjjz875.js +139 -0
- package/dist/tooling/shared/kbqnrs1x.js +1425 -0
- package/dist/tooling/shared/kz715295.js +94 -0
- package/dist/tooling/shared/m3xt8b1h.js +22 -0
- package/dist/tooling/shared/m4hhb8aa.js +9 -0
- package/dist/tooling/shared/mw5npye0.js +16 -0
- package/dist/tooling/shared/n4jqhpqz.js +27 -0
- package/dist/tooling/shared/nxq95eb6.js +42 -0
- package/dist/tooling/shared/qartgazh.js +70 -0
- package/dist/tooling/shared/rcywj2w8.js +190 -0
- package/dist/tooling/shared/s6qha57m.js +16 -0
- package/dist/tooling/shared/shjs0379.js +150 -0
- package/dist/tooling/shared/sjwkt1pg.js +16 -0
- package/dist/tooling/shared/stebqyyd.js +401 -0
- package/dist/tooling/shared/t4xveemq.js +250 -0
- package/dist/tooling/shared/t6zjeake.js +261 -0
- package/dist/tooling/shared/tcwpjvxe.js +9 -0
- package/dist/tooling/shared/tpssp7ac.js +160 -0
- package/dist/tooling/shared/v6j1ep6w.js +42 -0
- package/dist/tooling/shared/vwr2y833.js +270 -0
- package/dist/tooling/shared/w17sj05d.js +7 -0
- package/dist/tooling/shared/w5d89rb4.js +131 -0
- package/dist/tooling/shared/wbwq1jsa.js +157 -0
- package/dist/tooling/shared/wezxf3h8.js +17 -0
- package/dist/tooling/shared/yb4kd19s.js +12 -0
- package/dist/tooling/shared/ybdew6j7.js +294 -0
- package/dist/tooling/shared/yfedr1zb.js +6 -0
- package/dist/tooling/shared/yhp829bx.js +177 -0
- package/dist/tooling/shared/ytk1tjs0.js +604 -0
- package/dist/tooling/shared/zs9aymcp.js +210 -0
- package/dist/tooling/shared/zx3v9phv.js +8 -0
- package/dist/tooling/testing/index.js +3 -3
- package/package.json +50 -9
- package/dist/shared/ktz42yez.js +0 -113
- package/dist/shared/ttsqgp4p.js +0 -71
- package/dist/shared/y34a8714.js +0 -150
- package/dist/shared/zy8r7qvz.js +0 -116
- package/dist/shared/{ywr8hmey.js → 606g0nbf.js} +3 -3
- package/dist/shared/{rpycarcr.js → gcefca6p.js} +4 -4
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OkmError,
|
|
3
|
+
tag
|
|
4
|
+
} from "./hfq3n3bd.js";
|
|
5
|
+
|
|
6
|
+
// src/dialects/pg/filter-parse.ts
|
|
7
|
+
var PARSED = [
|
|
8
|
+
"eq",
|
|
9
|
+
"in",
|
|
10
|
+
"inList",
|
|
11
|
+
"notIn",
|
|
12
|
+
"lt",
|
|
13
|
+
"lte",
|
|
14
|
+
"gt",
|
|
15
|
+
"gte",
|
|
16
|
+
"between",
|
|
17
|
+
"startsWith",
|
|
18
|
+
"endsWith",
|
|
19
|
+
"contains",
|
|
20
|
+
"like",
|
|
21
|
+
"ilike",
|
|
22
|
+
"not",
|
|
23
|
+
"containedBy",
|
|
24
|
+
"overlaps",
|
|
25
|
+
"hasKey",
|
|
26
|
+
"hasAnyKey"
|
|
27
|
+
];
|
|
28
|
+
var PARSED_OPS = `,${PARSED.join(",")},`;
|
|
29
|
+
var PARSED_FIX = "Use eq, in, notIn, lt, lte, gt, gte, between, startsWith, endsWith, contains, like, ilike, not, containedBy, overlaps, hasKey, or hasAnyKey.";
|
|
30
|
+
function parseQuery(allow, sort, query, relations) {
|
|
31
|
+
if (typeof query !== "object" || query === null || Array.isArray(query)) {
|
|
32
|
+
throw new OkmError("OKM1121", "filters parse expects an object of fields.");
|
|
33
|
+
}
|
|
34
|
+
for (const field of Object.keys(allow)) {
|
|
35
|
+
for (const op of allow[field] ?? []) {
|
|
36
|
+
if (PARSED_OPS.includes(`,${op},`))
|
|
37
|
+
continue;
|
|
38
|
+
throw new OkmError("OKM1120", `filters() cannot apply ${op} on ${field}.`, {
|
|
39
|
+
fix: { summary: PARSED_FIX }
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const nested = relations ?? {};
|
|
44
|
+
const whereParts = [];
|
|
45
|
+
let orderBy;
|
|
46
|
+
for (const key of Object.keys(query)) {
|
|
47
|
+
const value = query[key];
|
|
48
|
+
if (key === "sort" && typeof value === "string" && sort.includes(value)) {
|
|
49
|
+
orderBy = { [value]: "asc" };
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (Object.hasOwn(allow, key)) {
|
|
53
|
+
whereParts.push(...clauses(key, allow[key] ?? [], value));
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (Object.hasOwn(nested, key)) {
|
|
57
|
+
whereParts.push(relationClause(key, nested[key] ?? [], value));
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
throw new OkmError("OKM1123", `Field ${key} is not in the allow list.`, {
|
|
61
|
+
fix: { summary: "Remove the field, or add it to filters({ allow }) or relations." }
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
const where = combine(whereParts);
|
|
65
|
+
return orderBy === undefined ? { where } : { where, orderBy };
|
|
66
|
+
}
|
|
67
|
+
function clauses(field, ops, value) {
|
|
68
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
69
|
+
if (!ops.includes("eq")) {
|
|
70
|
+
throw new OkmError("OKM1120", `filters() cannot apply eq on ${field}.`, {
|
|
71
|
+
fix: { summary: "Add eq to that field, or send an object of allowed operators." }
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return [{ [field]: value }];
|
|
75
|
+
}
|
|
76
|
+
const applied = [];
|
|
77
|
+
for (const op of Object.keys(value)) {
|
|
78
|
+
if (!Object.hasOwn(value, op))
|
|
79
|
+
continue;
|
|
80
|
+
if (!ops.includes(op) && !(op === "inList" && ops.includes("in"))) {
|
|
81
|
+
throw new OkmError("OKM1120", `filters() cannot apply ${op} on ${field}.`, {
|
|
82
|
+
fix: { summary: "Send an operator that field's allow list names." }
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
applied.push(one(field, op, value[op]));
|
|
86
|
+
}
|
|
87
|
+
if (applied.length === 0) {
|
|
88
|
+
throw new OkmError("OKM1120", `filters() cannot apply a value on ${field}.`, {
|
|
89
|
+
fix: { summary: "Send eq as a scalar, or an object of allowed operators." }
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return applied;
|
|
93
|
+
}
|
|
94
|
+
function one(field, op, value) {
|
|
95
|
+
switch (op) {
|
|
96
|
+
case "eq":
|
|
97
|
+
return {
|
|
98
|
+
[field]: value !== null && typeof value === "object" ? tag("eq", value) : value
|
|
99
|
+
};
|
|
100
|
+
case "in":
|
|
101
|
+
case "inList":
|
|
102
|
+
return { [field]: tag("inList", list(value, op)) };
|
|
103
|
+
case "notIn":
|
|
104
|
+
return { [field]: tag("notIn", list(value, op)) };
|
|
105
|
+
case "lt":
|
|
106
|
+
return { [field]: tag("lt", value) };
|
|
107
|
+
case "lte":
|
|
108
|
+
return { [field]: tag("lte", value) };
|
|
109
|
+
case "gt":
|
|
110
|
+
return { [field]: tag("gt", value) };
|
|
111
|
+
case "gte":
|
|
112
|
+
return { [field]: tag("gte", value) };
|
|
113
|
+
case "between": {
|
|
114
|
+
if (!Array.isArray(value) || value.length !== 2) {
|
|
115
|
+
throw new OkmError("OKM1120", `between on ${field} needs two bounds.`, {
|
|
116
|
+
fix: { summary: "Send between as [from, to]." }
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return { [field]: tag("between", [value[0], value[1]]) };
|
|
120
|
+
}
|
|
121
|
+
case "startsWith":
|
|
122
|
+
return { [field]: tag("startsWith", text(value, op)) };
|
|
123
|
+
case "endsWith":
|
|
124
|
+
return { [field]: tag("endsWith", text(value, op)) };
|
|
125
|
+
case "contains":
|
|
126
|
+
return { [field]: tag("contains", value) };
|
|
127
|
+
case "not":
|
|
128
|
+
if (value !== null && typeof value === "object") {
|
|
129
|
+
throw new OkmError("OKM1120", `not on ${field} takes a scalar.`, {
|
|
130
|
+
fix: { summary: "Send not a scalar or null. Nested operators are not accepted." }
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return { [field]: tag("not", value) };
|
|
134
|
+
case "containedBy":
|
|
135
|
+
return { [field]: tag("containedBy", value) };
|
|
136
|
+
case "overlaps":
|
|
137
|
+
return { [field]: tag("overlaps", value) };
|
|
138
|
+
case "hasKey":
|
|
139
|
+
return { [field]: tag("hasKey", text(value, "hasKey")) };
|
|
140
|
+
case "hasAnyKey":
|
|
141
|
+
return { [field]: tag("hasAnyKey", strings(value, field)) };
|
|
142
|
+
case "like":
|
|
143
|
+
return { [field]: tag("like", text(value, op)) };
|
|
144
|
+
case "ilike":
|
|
145
|
+
return { [field]: tag("ilike", text(value, op)) };
|
|
146
|
+
default:
|
|
147
|
+
throw new OkmError("OKM1120", `filters() cannot apply ${op} on ${field}.`, {
|
|
148
|
+
fix: { summary: "Use an operator parse applies." }
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function relationClause(name, fields, value) {
|
|
153
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
154
|
+
throw new OkmError("OKM1120", `filters() cannot apply a value on ${name}.`, {
|
|
155
|
+
fix: { summary: "Send the relation an object of allowlisted fields." }
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
const parts = [];
|
|
159
|
+
for (const field of Object.keys(value)) {
|
|
160
|
+
if (!Object.hasOwn(value, field))
|
|
161
|
+
continue;
|
|
162
|
+
if (!fields.includes(field)) {
|
|
163
|
+
throw new OkmError("OKM1123", `Field ${field} is not in the allow list.`, {
|
|
164
|
+
fix: { summary: "Remove the field, or add it to filters({ relations })." }
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
parts.push(...clauses(field, PARSED, value[field]));
|
|
168
|
+
}
|
|
169
|
+
if (parts.length === 0) {
|
|
170
|
+
throw new OkmError("OKM1120", `filters() cannot apply a value on ${name}.`, {
|
|
171
|
+
fix: { summary: "Send the relation an object of allowlisted fields." }
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
return { [name]: tag("has", combine(parts)) };
|
|
175
|
+
}
|
|
176
|
+
function combine(parts) {
|
|
177
|
+
const first = parts[0];
|
|
178
|
+
if (first === undefined)
|
|
179
|
+
return {};
|
|
180
|
+
if (parts.length === 1)
|
|
181
|
+
return first;
|
|
182
|
+
return tag("and", parts);
|
|
183
|
+
}
|
|
184
|
+
function list(value, op) {
|
|
185
|
+
if (!Array.isArray(value)) {
|
|
186
|
+
throw new OkmError("OKM1120", `${op} needs an array.`, {
|
|
187
|
+
fix: { summary: "Send that operator an array of values." }
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
return value;
|
|
191
|
+
}
|
|
192
|
+
function strings(value, field) {
|
|
193
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) {
|
|
194
|
+
throw new OkmError("OKM1120", `hasAnyKey on ${field} needs an array of strings.`, {
|
|
195
|
+
fix: { summary: "Send hasAnyKey an array of strings." }
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
return value;
|
|
199
|
+
}
|
|
200
|
+
function text(value, op) {
|
|
201
|
+
if (typeof value !== "string") {
|
|
202
|
+
throw new OkmError("OKM1120", `${op} needs a string.`, {
|
|
203
|
+
fix: { summary: "Send that operator a string." }
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
return value;
|
|
207
|
+
}
|
|
208
|
+
export {
|
|
209
|
+
parseQuery
|
|
210
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
testing2
|
|
3
|
-
} from "../../shared/
|
|
4
|
-
import"../../shared/
|
|
5
|
-
import"../../shared/
|
|
3
|
+
} from "../../shared/2szgv6yj.js";
|
|
4
|
+
import"../../shared/fk9vef30.js";
|
|
5
|
+
import"../../shared/12z7aznj.js";
|
|
6
6
|
export {
|
|
7
7
|
testing2 as testing
|
|
8
8
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "okmodel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "okmodel is a catalog-first TypeScript ORM, PostgreSQL first.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"migrations",
|
|
@@ -63,6 +63,10 @@
|
|
|
63
63
|
"types": "./dist/runtime/pg/bun.d.ts",
|
|
64
64
|
"import": "./dist/runtime/pg/bun.js"
|
|
65
65
|
},
|
|
66
|
+
"./pg/neon": {
|
|
67
|
+
"types": "./dist/runtime/pg/neon.d.ts",
|
|
68
|
+
"import": "./dist/runtime/pg/neon.js"
|
|
69
|
+
},
|
|
66
70
|
"./ids": {
|
|
67
71
|
"types": "./dist/runtime/ids/index.d.ts",
|
|
68
72
|
"import": "./dist/runtime/ids/index.js"
|
|
@@ -87,6 +91,10 @@
|
|
|
87
91
|
"types": "./dist/runtime/validate/index.d.ts",
|
|
88
92
|
"import": "./dist/runtime/validate/index.js"
|
|
89
93
|
},
|
|
94
|
+
"./otel": {
|
|
95
|
+
"types": "./dist/runtime/otel.d.ts",
|
|
96
|
+
"import": "./dist/runtime/otel.js"
|
|
97
|
+
},
|
|
90
98
|
"./ext": {
|
|
91
99
|
"types": "./dist/dialects/pg/ext/index.d.ts",
|
|
92
100
|
"import": "./dist/dialects/pg/ext/index.js"
|
|
@@ -106,10 +114,38 @@
|
|
|
106
114
|
"./pg/pg_trgm": {
|
|
107
115
|
"types": "./dist/dialects/pg/ext/pg-trgm.d.ts",
|
|
108
116
|
"import": "./dist/dialects/pg/ext/pg-trgm.js"
|
|
117
|
+
},
|
|
118
|
+
"./pg/unaccent": {
|
|
119
|
+
"types": "./dist/dialects/pg/ext/unaccent.d.ts",
|
|
120
|
+
"import": "./dist/dialects/pg/ext/unaccent.js"
|
|
121
|
+
},
|
|
122
|
+
"./pg/hstore": {
|
|
123
|
+
"types": "./dist/dialects/pg/ext/hstore.d.ts",
|
|
124
|
+
"import": "./dist/dialects/pg/ext/hstore.js"
|
|
125
|
+
},
|
|
126
|
+
"./pg/ltree": {
|
|
127
|
+
"types": "./dist/dialects/pg/ext/ltree.d.ts",
|
|
128
|
+
"import": "./dist/dialects/pg/ext/ltree.js"
|
|
129
|
+
},
|
|
130
|
+
"./pg/btree_gist": {
|
|
131
|
+
"types": "./dist/dialects/pg/ext/btree-gist.d.ts",
|
|
132
|
+
"import": "./dist/dialects/pg/ext/btree-gist.js"
|
|
133
|
+
},
|
|
134
|
+
"./pg/btree_gin": {
|
|
135
|
+
"types": "./dist/dialects/pg/ext/btree-gin.d.ts",
|
|
136
|
+
"import": "./dist/dialects/pg/ext/btree-gin.js"
|
|
137
|
+
},
|
|
138
|
+
"./pg/fuzzystrmatch": {
|
|
139
|
+
"types": "./dist/dialects/pg/ext/fuzzystrmatch.d.ts",
|
|
140
|
+
"import": "./dist/dialects/pg/ext/fuzzystrmatch.js"
|
|
141
|
+
},
|
|
142
|
+
"./pg/pgcrypto": {
|
|
143
|
+
"types": "./dist/dialects/pg/ext/pgcrypto.d.ts",
|
|
144
|
+
"import": "./dist/dialects/pg/ext/pgcrypto.js"
|
|
109
145
|
}
|
|
110
146
|
},
|
|
111
147
|
"scripts": {
|
|
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",
|
|
148
|
+
"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/pg/neon.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/runtime/otel.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/dialects/pg/ext/unaccent.ts ./src/dialects/pg/ext/hstore.ts ./src/dialects/pg/ext/ltree.ts ./src/dialects/pg/ext/btree-gist.ts ./src/dialects/pg/ext/btree-gin.ts ./src/dialects/pg/ext/fuzzystrmatch.ts ./src/dialects/pg/ext/pgcrypto.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 --external @neondatabase/serverless && bunx tsc -p tsconfig.build.json && rm -f ./dist/dialects/pg/temporal.local.d.ts && bun build ./packages/harness/src/driver-run.ts --outdir ./dist/tooling --format esm --target node --splitting --chunk-naming=shared/[hash].js --external postgres --external @electric-sql/pglite --external pg --external bun --external @neondatabase/serverless && bun ./scripts/write-bin-wrappers.ts",
|
|
113
149
|
"driver-bench": "bun ./scripts/driver-bench.ts",
|
|
114
150
|
"typecheck": "bunx tsc --noEmit -p tsconfig.json",
|
|
115
151
|
"editor-check": "bun ./scripts/editor-check.ts",
|
|
@@ -153,21 +189,23 @@
|
|
|
153
189
|
"devDependencies": {
|
|
154
190
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
155
191
|
"@electric-sql/pglite-socket": "^0.2.11",
|
|
156
|
-
"@types/bun": "^1.4.
|
|
192
|
+
"@types/bun": "^1.4.3",
|
|
193
|
+
"drizzle-orm": "0.45.4",
|
|
157
194
|
"expect-type": "^1.4.0",
|
|
158
195
|
"fast-check": "^4.10.2",
|
|
159
|
-
"oxc-parser": "
|
|
160
|
-
"oxfmt": "0.
|
|
161
|
-
"oxlint": "^1.
|
|
162
|
-
"oxlint-tsgolint": "^7.0.
|
|
163
|
-
"publint": "^0.3.
|
|
164
|
-
"temporal-polyfill": "^1.0.
|
|
196
|
+
"oxc-parser": "0.154.0",
|
|
197
|
+
"oxfmt": "0.73.0",
|
|
198
|
+
"oxlint": "^1.88.0",
|
|
199
|
+
"oxlint-tsgolint": "^7.0.2004",
|
|
200
|
+
"publint": "^0.3.25",
|
|
201
|
+
"temporal-polyfill": "^1.0.6",
|
|
165
202
|
"temporal-spec": "^1.0.1",
|
|
166
203
|
"typescript": "7",
|
|
167
204
|
"typescript-editor": "npm:typescript@6.0.3"
|
|
168
205
|
},
|
|
169
206
|
"peerDependencies": {
|
|
170
207
|
"@electric-sql/pglite": "^0.5.8",
|
|
208
|
+
"@neondatabase/serverless": "^1.2.0",
|
|
171
209
|
"pg": "^8.16.0",
|
|
172
210
|
"postgres": "^3.4.9"
|
|
173
211
|
},
|
|
@@ -175,6 +213,9 @@
|
|
|
175
213
|
"@electric-sql/pglite": {
|
|
176
214
|
"optional": true
|
|
177
215
|
},
|
|
216
|
+
"@neondatabase/serverless": {
|
|
217
|
+
"optional": true
|
|
218
|
+
},
|
|
178
219
|
"pg": {
|
|
179
220
|
"optional": true
|
|
180
221
|
},
|
package/dist/shared/ktz42yez.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
open2
|
|
3
|
-
} from "./14vx95q4.js";
|
|
4
|
-
import"./qq3899ht.js";
|
|
5
|
-
import"./n442h54c.js";
|
|
6
|
-
import {
|
|
7
|
-
openProject
|
|
8
|
-
} from "./gs74dbj5.js";
|
|
9
|
-
import {
|
|
10
|
-
sessionFailure,
|
|
11
|
-
finishQuiet,
|
|
12
|
-
assertTargetPolicy,
|
|
13
|
-
selectTarget
|
|
14
|
-
} from "./tsvww22q.js";
|
|
15
|
-
import"./9s0ypp87.js";
|
|
16
|
-
import {
|
|
17
|
-
isExactVersion,
|
|
18
|
-
compareExtensionVersions
|
|
19
|
-
} from "./r3j8s5y0.js";
|
|
20
|
-
import {
|
|
21
|
-
OkmError2
|
|
22
|
-
} from "./52szzakm.js";
|
|
23
|
-
|
|
24
|
-
// src/tooling/migrate/ext.ts
|
|
25
|
-
async function extProject(cwd, command, flags) {
|
|
26
|
-
const opened = await openProject(cwd);
|
|
27
|
-
const target = selectTarget(opened.config, flags.target);
|
|
28
|
-
assertTargetPolicy(target, "check", flags.allowProtected);
|
|
29
|
-
const pool = open2({ url: target.url, max: 1 });
|
|
30
|
-
try {
|
|
31
|
-
if (command === "list")
|
|
32
|
-
return formatList(await readExtensions(pool));
|
|
33
|
-
return formatCheck(opened.built.catalog.objects, await readExtensions(pool));
|
|
34
|
-
} catch (error) {
|
|
35
|
-
throw sessionFailure(error) ?? error;
|
|
36
|
-
} finally {
|
|
37
|
-
await finishQuiet(() => pool.close());
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
var LIST_SQL = `
|
|
41
|
-
select a.name, a.default_version, e.extversion, n.nspname
|
|
42
|
-
from pg_available_extensions a
|
|
43
|
-
left join pg_extension e on e.extname = a.name
|
|
44
|
-
left join pg_namespace n on n.oid = e.extnamespace
|
|
45
|
-
order by a.name
|
|
46
|
-
`;
|
|
47
|
-
async function readExtensions(pool) {
|
|
48
|
-
const result = await pool.execute(LIST_SQL);
|
|
49
|
-
return result.rows.map((row) => ({
|
|
50
|
-
name: cell(row[0]),
|
|
51
|
-
defaultVersion: cell(row[1]),
|
|
52
|
-
installedVersion: cell(row[2]),
|
|
53
|
-
schema: cell(row[3])
|
|
54
|
-
}));
|
|
55
|
-
}
|
|
56
|
-
function cell(value) {
|
|
57
|
-
return typeof value === "string" ? value : "";
|
|
58
|
-
}
|
|
59
|
-
function formatList(rows) {
|
|
60
|
-
const lines = ["name\tdefault\tinstalled\tschema"];
|
|
61
|
-
for (const row of rows) {
|
|
62
|
-
lines.push([row.name, row.defaultVersion, row.installedVersion, row.schema].join("\t"));
|
|
63
|
-
}
|
|
64
|
-
return `${lines.join(`
|
|
65
|
-
`)}
|
|
66
|
-
`;
|
|
67
|
-
}
|
|
68
|
-
function formatCheck(objects, server) {
|
|
69
|
-
const declared = objects.filter((object) => object.kind === "extension");
|
|
70
|
-
if (declared.length === 0)
|
|
71
|
-
return `no extensions
|
|
72
|
-
`;
|
|
73
|
-
const installed = new Map(server.map((row) => [row.name, row.installedVersion]));
|
|
74
|
-
const lines = ["name\tdeclared\tinstalled"];
|
|
75
|
-
for (const object of [...declared].sort((left, right) => left.identity.name < right.identity.name ? -1 : 1)) {
|
|
76
|
-
const name = object.identity.name;
|
|
77
|
-
const have = installed.get(name) ?? "";
|
|
78
|
-
if (have.length === 0) {
|
|
79
|
-
throw new OkmError2("OKM1811", `Extension ${name} is not installed on the server.`, {
|
|
80
|
-
fix: { summary: "Install the extension, or remove the declaration." }
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
const want = object.definition.version;
|
|
84
|
-
if (!versionAccepted(want, have)) {
|
|
85
|
-
throw new OkmError2("OKM1812", extensionNeeds(name, want ?? "", have), {
|
|
86
|
-
fix: { summary: "Install a version the declaration accepts, or change the pin." }
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
lines.push([name, want ?? "-", have].join("\t"));
|
|
90
|
-
}
|
|
91
|
-
return `${lines.join(`
|
|
92
|
-
`)}
|
|
93
|
-
`;
|
|
94
|
-
}
|
|
95
|
-
function extensionNeeds(name, want, have) {
|
|
96
|
-
const floor = /^>=(\d+(?:\.\d+)*)$/.exec(want);
|
|
97
|
-
const need = floor?.[1] ?? want;
|
|
98
|
-
const higher = floor === null ? "" : " or higher";
|
|
99
|
-
return `Extension ${name} needs ${need}${higher}. The server has ${have}. Install a version the declaration accepts, or change the pin.`;
|
|
100
|
-
}
|
|
101
|
-
function versionAccepted(declared, installed) {
|
|
102
|
-
if (declared === undefined)
|
|
103
|
-
return true;
|
|
104
|
-
const floor = /^>=(\d+(?:\.\d+)*)$/.exec(declared);
|
|
105
|
-
const minimum = floor?.[1];
|
|
106
|
-
if (minimum !== undefined) {
|
|
107
|
-
return isExactVersion(installed) && compareExtensionVersions(installed, minimum) >= 0;
|
|
108
|
-
}
|
|
109
|
-
return declared === installed;
|
|
110
|
-
}
|
|
111
|
-
export {
|
|
112
|
-
extProject
|
|
113
|
-
};
|
package/dist/shared/ttsqgp4p.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
POSTGRES_FLOOR,
|
|
3
|
-
isPostgresMajor,
|
|
4
|
-
parsePostgresFloor,
|
|
5
|
-
serverNeedsPostgres
|
|
6
|
-
} from "./ga9j92qj.js";
|
|
7
|
-
import {
|
|
8
|
-
withHttp,
|
|
9
|
-
attachHttp
|
|
10
|
-
} from "./tbrvgw6z.js";
|
|
11
|
-
import {
|
|
12
|
-
OkmError2
|
|
13
|
-
} from "./52szzakm.js";
|
|
14
|
-
|
|
15
|
-
// src/runtime/server-check.ts
|
|
16
|
-
var versionQuery = "select current_setting('server_version_num'), version(), (select (xpath('//catalog_hash/text()', query_to_xml('select catalog_hash from okm_meta where id = ''head''', true, false, '')))[1]::text where to_regclass('okm_meta') is not null)";
|
|
17
|
-
async function acceptServer(pool, schema, rows, http, requireMeta, options, source) {
|
|
18
|
-
for (const name in schema.model) {
|
|
19
|
-
if (schema.model[name]?.presets !== undefined) {
|
|
20
|
-
(await import("./m7n9h2a5.js")).checkSchema(schema);
|
|
21
|
-
break;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
const version = rows[0]?.[1];
|
|
25
|
-
if (version === null || version === undefined || !version.startsWith("PostgreSQL")) {
|
|
26
|
-
throw new OkmError2("OKM1801", "The server is not PostgreSQL. The schema dialect is postgres.", withHttp(http, {
|
|
27
|
-
fix: { summary: "Open the schema with the Postgres driver that matches it." }
|
|
28
|
-
}));
|
|
29
|
-
}
|
|
30
|
-
const recorded = rows[0]?.[2];
|
|
31
|
-
if (recorded === null || recorded === undefined || recorded.length === 0) {
|
|
32
|
-
if (requireMeta) {
|
|
33
|
-
throw new OkmError2("OKM1520", "okm_meta has no catalog hash.", withHttp(http, {
|
|
34
|
-
fix: {
|
|
35
|
-
summary: "Apply migrations so okm_meta records the catalog, or omit requireMeta to adopt this database."
|
|
36
|
-
}
|
|
37
|
-
}));
|
|
38
|
-
}
|
|
39
|
-
} else {
|
|
40
|
-
const { assertCompatible } = await import("./ek2wt2dz.js");
|
|
41
|
-
try {
|
|
42
|
-
await assertCompatible(pool, schema, recorded, source, options);
|
|
43
|
-
} catch (error) {
|
|
44
|
-
if (error instanceof OkmError2)
|
|
45
|
-
throw attachHttp(http, error);
|
|
46
|
-
throw error;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
const major = Math.floor(Number(rows[0]?.[0] ?? "0") / 1e4);
|
|
50
|
-
const raw = schema.requires?.postgres;
|
|
51
|
-
if (raw === undefined) {
|
|
52
|
-
if (major < POSTGRES_FLOOR) {
|
|
53
|
-
throw new OkmError2("OKM1803", serverNeedsPostgres(major, POSTGRES_FLOOR), withHttp(http, {
|
|
54
|
-
fix: {
|
|
55
|
-
summary: `Upgrade to PostgreSQL ${String(POSTGRES_FLOOR)} or higher.`
|
|
56
|
-
}
|
|
57
|
-
}));
|
|
58
|
-
}
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
const need = parsePostgresFloor(raw);
|
|
62
|
-
if (!isPostgresMajor(need) || major < need) {
|
|
63
|
-
throw new OkmError2("OKM1802", serverNeedsPostgres(major, isPostgresMajor(need) ? need : POSTGRES_FLOOR), withHttp(http, {
|
|
64
|
-
fix: { summary: "Upgrade the server, or lower minPostgres to a major the server meets." }
|
|
65
|
-
}));
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
export {
|
|
69
|
-
acceptServer,
|
|
70
|
-
versionQuery
|
|
71
|
-
};
|
package/dist/shared/y34a8714.js
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
staticNamespace2,
|
|
3
|
-
assertNamespace2,
|
|
4
|
-
normaliseEdges,
|
|
5
|
-
assertProvenance
|
|
6
|
-
} from "./358zsv4r.js";
|
|
7
|
-
import {
|
|
8
|
-
assertIdentifier2
|
|
9
|
-
} from "./nfzc5z0w.js";
|
|
10
|
-
import {
|
|
11
|
-
catalogError2
|
|
12
|
-
} from "./52szzakm.js";
|
|
13
|
-
|
|
14
|
-
// src/contracts/catalog/routine.ts
|
|
15
|
-
var VOLATILITY = new Set(["volatile", "stable", "immutable"]);
|
|
16
|
-
var SECURITY = new Set(["invoker", "definer"]);
|
|
17
|
-
var TIMING = new Set(["before", "after", "instead"]);
|
|
18
|
-
var LEVEL = new Set(["row", "statement"]);
|
|
19
|
-
var EVENT_ORDER = ["insert", "update", "delete", "truncate"];
|
|
20
|
-
var TYPE_TEXT = /^[A-Za-z][A-Za-z0-9_ ]*(\(\d+(,\s*\d+)?\))?(\[\])*$/;
|
|
21
|
-
function functionObject(input) {
|
|
22
|
-
assertIdentifier2(input.name, "function");
|
|
23
|
-
const namespace = input.namespace ?? staticNamespace2("public");
|
|
24
|
-
assertNamespace2(namespace);
|
|
25
|
-
assertProvenance(input.provenance);
|
|
26
|
-
if (input.language !== "sql" && input.language !== "plpgsql") {
|
|
27
|
-
catalogError2("OKM1020", `Function ${input.name} language must be sql or plpgsql.`);
|
|
28
|
-
}
|
|
29
|
-
const volatility = input.volatility ?? "volatile";
|
|
30
|
-
if (!VOLATILITY.has(volatility)) {
|
|
31
|
-
catalogError2("OKM1020", `Function ${input.name} volatility ${volatility} is not supported.`);
|
|
32
|
-
}
|
|
33
|
-
const security = input.security ?? "invoker";
|
|
34
|
-
if (!SECURITY.has(security)) {
|
|
35
|
-
catalogError2("OKM1020", `Function ${input.name} security ${security} is not supported.`);
|
|
36
|
-
}
|
|
37
|
-
assertTypeName(input.returns, `function ${input.name} return type`);
|
|
38
|
-
const args = (input.arguments ?? []).map((argument) => readArgument(input.name, argument));
|
|
39
|
-
if (input.body.length === 0) {
|
|
40
|
-
catalogError2("OKM1020", `Function ${input.name} needs a body.`);
|
|
41
|
-
}
|
|
42
|
-
const atomic = input.atomic === true;
|
|
43
|
-
if (atomic && input.language !== "sql") {
|
|
44
|
-
catalogError2("OKM1020", `Function ${input.name} BEGIN ATOMIC needs language sql.`);
|
|
45
|
-
}
|
|
46
|
-
if (input.searchPath !== undefined && input.searchPath.trim().length === 0) {
|
|
47
|
-
catalogError2("OKM1020", `Function ${input.name} search_path is empty.`);
|
|
48
|
-
}
|
|
49
|
-
const definition = {
|
|
50
|
-
arguments: args,
|
|
51
|
-
returns: input.returns,
|
|
52
|
-
language: input.language,
|
|
53
|
-
volatility,
|
|
54
|
-
security,
|
|
55
|
-
body: input.body,
|
|
56
|
-
...input.searchPath !== undefined ? { searchPath: input.searchPath } : {},
|
|
57
|
-
...atomic ? { atomic: true } : {}
|
|
58
|
-
};
|
|
59
|
-
return {
|
|
60
|
-
kind: "function",
|
|
61
|
-
identity: {
|
|
62
|
-
kind: "function",
|
|
63
|
-
namespace,
|
|
64
|
-
name: input.name,
|
|
65
|
-
argTypes: args.map((arg) => arg.type)
|
|
66
|
-
},
|
|
67
|
-
owner: input.owner ?? "managed",
|
|
68
|
-
definition,
|
|
69
|
-
dependencies: normaliseEdges(input.dependencies ?? []),
|
|
70
|
-
provenance: input.provenance
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
function triggerObject(input) {
|
|
74
|
-
assertIdentifier2(input.name, "trigger");
|
|
75
|
-
assertNamespace2(input.parent.namespace);
|
|
76
|
-
assertIdentifier2(input.parent.name, "trigger table");
|
|
77
|
-
assertProvenance(input.provenance);
|
|
78
|
-
if (!TIMING.has(input.timing)) {
|
|
79
|
-
catalogError2("OKM1020", `Trigger ${input.name} timing ${input.timing} is not supported.`);
|
|
80
|
-
}
|
|
81
|
-
if (!LEVEL.has(input.level)) {
|
|
82
|
-
catalogError2("OKM1020", `Trigger ${input.name} level ${input.level} is not supported.`);
|
|
83
|
-
}
|
|
84
|
-
const events = EVENT_ORDER.filter((event) => input.events.includes(event));
|
|
85
|
-
if (events.length === 0) {
|
|
86
|
-
catalogError2("OKM1020", `Trigger ${input.name} needs an event.`);
|
|
87
|
-
}
|
|
88
|
-
const updateOf = input.updateOf === undefined ? undefined : [...input.updateOf];
|
|
89
|
-
if (updateOf !== undefined) {
|
|
90
|
-
if (!events.includes("update")) {
|
|
91
|
-
catalogError2("OKM1020", `Trigger ${input.name} lists UPDATE OF columns without an update event.`);
|
|
92
|
-
}
|
|
93
|
-
if (input.level !== "row") {
|
|
94
|
-
catalogError2("OKM1020", `Trigger ${input.name} UPDATE OF columns need level row.`);
|
|
95
|
-
}
|
|
96
|
-
for (const column of updateOf)
|
|
97
|
-
assertIdentifier2(column, "trigger column");
|
|
98
|
-
}
|
|
99
|
-
assertIdentifier2(input.calls.name, "trigger function");
|
|
100
|
-
assertNamespace2(input.calls.namespace);
|
|
101
|
-
for (const typeName of input.calls.argTypes)
|
|
102
|
-
assertTypeName(typeName, `trigger ${input.name}`);
|
|
103
|
-
const edges = [
|
|
104
|
-
{ kind: "table", namespace: input.parent.namespace, name: input.parent.name },
|
|
105
|
-
{
|
|
106
|
-
kind: "function",
|
|
107
|
-
namespace: input.calls.namespace,
|
|
108
|
-
name: input.calls.name,
|
|
109
|
-
argTypes: input.calls.argTypes
|
|
110
|
-
},
|
|
111
|
-
...(updateOf ?? []).map((column) => ({
|
|
112
|
-
kind: "column",
|
|
113
|
-
parent: input.parent,
|
|
114
|
-
name: column
|
|
115
|
-
})),
|
|
116
|
-
...input.dependencies ?? []
|
|
117
|
-
];
|
|
118
|
-
const definition = {
|
|
119
|
-
timing: input.timing,
|
|
120
|
-
events,
|
|
121
|
-
level: input.level,
|
|
122
|
-
calls: {
|
|
123
|
-
namespace: input.calls.namespace,
|
|
124
|
-
name: input.calls.name,
|
|
125
|
-
argTypes: [...input.calls.argTypes]
|
|
126
|
-
},
|
|
127
|
-
...updateOf !== undefined && updateOf.length > 0 ? { updateOf } : {},
|
|
128
|
-
...input.when !== undefined && input.when.length > 0 ? { when: input.when } : {}
|
|
129
|
-
};
|
|
130
|
-
return {
|
|
131
|
-
kind: "trigger",
|
|
132
|
-
identity: { kind: "trigger", parent: input.parent, name: input.name },
|
|
133
|
-
owner: input.owner ?? "managed",
|
|
134
|
-
definition,
|
|
135
|
-
dependencies: normaliseEdges(edges),
|
|
136
|
-
provenance: input.provenance
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
function readArgument(fn, argument) {
|
|
140
|
-
assertIdentifier2(argument.name, `function ${fn} argument`);
|
|
141
|
-
assertTypeName(argument.type, `function ${fn} argument ${argument.name}`);
|
|
142
|
-
return { name: argument.name, type: argument.type };
|
|
143
|
-
}
|
|
144
|
-
function assertTypeName(typeName, role) {
|
|
145
|
-
if (!TYPE_TEXT.test(typeName)) {
|
|
146
|
-
catalogError2("OKM1020", `${role} ${typeName} is not a type name.`);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export { functionObject, triggerObject };
|