okmodel 0.7.0 → 0.8.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/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/fn/index.d.ts +39 -1
- package/dist/dialects/pg/fn/index.js +118 -26
- package/dist/dialects/pg/index.d.ts +2 -0
- package/dist/dialects/pg/index.js +393 -18
- 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 +8 -5
- 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/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 +15 -16
- package/dist/runtime/types.d.ts +15 -1
- package/dist/runtime/validate/index.js +4 -4
- package/dist/shared/{mtaszv5a.js → 0wrea3jq.js} +102 -4
- package/dist/shared/{qq3899ht.js → 12z7aznj.js} +243 -14
- package/dist/shared/{w79hsckn.js → 14x60fbf.js} +5 -5
- package/dist/shared/{ek2wt2dz.js → 16kvjebh.js} +4 -4
- package/dist/shared/{svncdeh5.js → 195pzzzz.js} +8 -8
- package/dist/shared/{gzaveazc.js → 1d9q9cv2.js} +29 -2
- package/dist/shared/{jvd0mqag.js → 3449rcae.js} +5 -5
- package/dist/shared/{14vx95q4.js → 35q0n9tz.js} +7 -7
- package/dist/shared/3bb7wsqt.js +99 -0
- package/dist/shared/{y6njgyda.js → 3t6kw83m.js} +2 -2
- package/dist/shared/{81ebdx9p.js → 4m6hskg8.js} +4 -4
- package/dist/shared/{xhfsfkgk.js → 4vbf83xx.js} +9 -2
- package/dist/shared/{bg3rym3g.js → 63f4ksbz.js} +2 -2
- package/dist/shared/{pt94kz7f.js → 6m78c8ss.js} +1 -1
- package/dist/shared/{5e3tf63j.js → 760ppr76.js} +14 -6
- package/dist/shared/{zm0ptry0.js → 7ghwamrf.js} +1 -1
- package/dist/shared/{xnxsed62.js → 9dr2qnx7.js} +14 -14
- package/dist/shared/{h15jx9bc.js → 9dvh1dr6.js} +1 -1
- package/dist/shared/{q5c6ngn3.js → a62rb2da.js} +1 -1
- package/dist/shared/{kb2sdhfb.js → ae4j5f42.js} +17 -1
- package/dist/shared/agsfb86s.js +233 -0
- package/dist/shared/{7k9grvf6.js → b6d6p0zc.js} +5 -5
- package/dist/shared/{tbrvgw6z.js → bah9nbg3.js} +17 -16
- package/dist/shared/{5fe3kbsh.js → bnby0esn.js} +1 -1
- package/dist/shared/bsek72fg.js +225 -0
- package/dist/shared/{1w508jbr.js → bxas03mq.js} +21 -17
- package/dist/shared/{dk8v79p3.js → d5nmj7vv.js} +1 -1
- package/dist/shared/{tsvww22q.js → dpc2r7rb.js} +7 -7
- package/dist/shared/{vb6qfyve.js → e8zyaqvj.js} +2 -2
- package/dist/shared/{hyh73qk6.js → ecn8mfdq.js} +5 -5
- package/dist/shared/{gs74dbj5.js → f4jy1j7x.js} +27 -14
- package/dist/shared/{ttsqgp4p.js → fjpnhqan.js} +2 -2
- package/dist/shared/{xjk7hnn5.js → g5yc06ka.js} +2 -2
- package/dist/shared/{w72kgg4q.js → hfqmpasr.js} +6 -6
- package/dist/shared/{kr0jzbw2.js → hm5f8jby.js} +7 -7
- package/dist/shared/{dkxgzaqd.js → hqpxf4a4.js} +1 -1
- package/dist/shared/{cn957f8d.js → jebgrkeq.js} +3 -3
- package/dist/shared/{wa07eas9.js → jp36k7dp.js} +11 -11
- package/dist/shared/jx2m62cs.js +96 -0
- package/dist/shared/{sfz1ksn6.js → k86n8vq3.js} +2 -2
- package/dist/shared/{67txcrcw.js → kgwp4jdd.js} +4 -4
- package/dist/shared/{8skf0cam.js → kj9d8maq.js} +1 -1
- package/dist/shared/{aytqh5y2.js → m4xff2a6.js} +2 -2
- package/dist/shared/{zp9fmend.js → mfedzr74.js} +4 -4
- package/dist/shared/{ax7qv55k.js → mkrn359n.js} +60 -11
- package/dist/shared/{m6p12kbr.js → mnvjvqyp.js} +10 -10
- package/dist/shared/{1qa0qajz.js → mtw6jz76.js} +1 -1
- package/dist/shared/{1est4ezg.js → n05z9nwz.js} +3 -3
- package/dist/shared/{pbp1ss85.js → n0jmpgj1.js} +2 -2
- package/dist/shared/{ktz42yez.js → n41w4fbz.js} +5 -5
- package/dist/shared/{n816peh1.js → n454kcnw.js} +1 -1
- package/dist/shared/n7kg8mmx.js +61 -0
- package/dist/shared/{g6evj1j3.js → needfe47.js} +1 -1
- package/dist/shared/{2shdbn8q.js → njga14v4.js} +9 -9
- package/dist/shared/{vqrjpcqn.js → nmnsgj7x.js} +1 -1
- package/dist/shared/{b5pftnn2.js → p3xbdcvt.js} +14 -18
- package/dist/shared/{te5as7z7.js → p5nh3r8q.js} +3 -3
- package/dist/shared/{p6qc5gcp.js → pan0370z.js} +6 -6
- package/dist/shared/{79dt02vc.js → q0cqt2sp.js} +1 -1
- package/dist/shared/{5v3xf80k.js → qd9hhd8f.js} +1 -1
- package/dist/shared/{bm22fvzr.js → qfw14tna.js} +2 -2
- package/dist/shared/{9s0ypp87.js → sjk86yrx.js} +1 -1
- package/dist/shared/{3v7t1yrv.js → th3be82n.js} +2 -2
- package/dist/shared/{ed0b8k4s.js → typ3vy7t.js} +1 -1
- package/dist/shared/{vczs8gd4.js → v1wad97q.js} +2 -2
- package/dist/shared/{9628a9xt.js → vk7rag46.js} +1 -1
- package/dist/shared/{ze4hxsmy.js → w9ejzaqf.js} +1 -1
- package/dist/shared/{bz84tkzm.js → wcrheftc.js} +2 -2
- package/dist/shared/{ab9gmbwy.js → wvdjznah.js} +5 -5
- package/dist/shared/{7mnme5tn.js → wz2a78mp.js} +1 -1
- package/dist/shared/{9y3mmmh1.js → xfhe73sb.js} +1 -1
- package/dist/shared/{je4axnm8.js → z581d7ny.js} +2 -2
- package/dist/shared/{x933k9a3.js → zbqbmmrp.js} +10 -10
- package/dist/shared/{rs73fca9.js → zgex00fd.js} +6 -6
- package/dist/shared/{jznfax0y.js → zq1he88x.js} +4 -4
- package/dist/tooling/cli.js +26 -13
- package/dist/tooling/driver-run.js +4971 -0
- package/dist/tooling/driver-test.d.ts +36 -0
- package/dist/tooling/migrate/commands.d.ts +2 -2
- package/dist/tooling/migrate/index.js +9 -9
- package/dist/tooling/migrate/project.d.ts +3 -0
- package/dist/tooling/shared/03k6res6.js +210 -0
- package/dist/tooling/shared/08kemxjd.js +10 -0
- package/dist/tooling/shared/2revefqt.js +209 -0
- package/dist/tooling/shared/2wtvc7rw.js +1425 -0
- package/dist/tooling/shared/345tbc2k.js +16 -0
- package/dist/tooling/shared/3m1hkg7z.js +344 -0
- package/dist/tooling/shared/3rrw5w8f.js +81 -0
- package/dist/tooling/shared/3tq8pnb8.js +131 -0
- package/dist/tooling/shared/417zdsk7.js +194 -0
- package/dist/tooling/shared/4d2w25vw.js +40 -0
- package/dist/tooling/shared/54tqkxja.js +51 -0
- package/dist/tooling/shared/5bvw2nev.js +12 -0
- package/dist/tooling/shared/6nyfyw70.js +231 -0
- package/dist/tooling/shared/72fyg4zv.js +160 -0
- package/dist/tooling/shared/733a1tq3.js +38 -0
- package/dist/tooling/shared/7ae7rjmn.js +20 -0
- package/dist/tooling/shared/7kms6fvj.js +20 -0
- package/dist/tooling/shared/8sqrsw3s.js +49 -0
- package/dist/tooling/shared/96ps4g1z.js +32 -0
- package/dist/tooling/shared/9kazs5p6.js +195 -0
- package/dist/tooling/shared/9xzm7hjg.js +38 -0
- package/dist/tooling/shared/a6pp9d12.js +49 -0
- package/dist/tooling/shared/a7q7t4n3.js +22 -0
- package/dist/tooling/shared/aftb2mwr.js +18 -0
- package/dist/tooling/shared/bz2dqhab.js +311 -0
- package/dist/tooling/shared/cmptmb4f.js +12 -0
- package/dist/tooling/shared/ddjtfgnx.js +177 -0
- package/dist/tooling/shared/djydjpqt.js +261 -0
- package/dist/tooling/shared/dw08f3m8.js +9 -0
- package/dist/tooling/shared/dy672fz6.js +16 -0
- package/dist/tooling/shared/dzx85q70.js +66 -0
- package/dist/tooling/shared/ec71zqgt.js +270 -0
- package/dist/tooling/shared/ep8zh3bk.js +6 -0
- package/dist/tooling/shared/f9mphxej.js +3789 -0
- package/dist/tooling/shared/fb9k2qwd.js +89 -0
- package/dist/tooling/shared/g9ad4n80.js +211 -0
- package/dist/tooling/shared/gfvtj6d0.js +94 -0
- package/dist/tooling/shared/gmcf9cxf.js +294 -0
- package/dist/tooling/shared/htnaj77v.js +17 -0
- package/dist/tooling/shared/j9t5s12a.js +7 -0
- package/dist/tooling/shared/jne7b93p.js +42 -0
- package/dist/tooling/shared/ma2340rx.js +118 -0
- package/dist/tooling/shared/mtrqn2hn.js +505 -0
- package/dist/tooling/shared/n4jqhpqz.js +27 -0
- package/dist/tooling/shared/nf7jmhfa.js +20 -0
- package/dist/tooling/shared/p7f08ktn.js +332 -0
- package/dist/tooling/shared/ppnnnvj8.js +13 -0
- package/dist/tooling/shared/pqy21k24.js +312 -0
- package/dist/tooling/shared/pw8fgahx.js +69 -0
- package/dist/tooling/shared/pwsytxm5.js +17 -0
- package/dist/tooling/shared/rf83gr2d.js +94 -0
- package/dist/tooling/shared/rq5kk8j6.js +401 -0
- package/dist/tooling/shared/rs1jb051.js +12 -0
- package/dist/tooling/shared/smn6kz1p.js +157 -0
- package/dist/tooling/shared/spk1jg3r.js +1696 -0
- package/dist/tooling/shared/tn8gay14.js +143 -0
- package/dist/tooling/shared/vraj6d74.js +42 -0
- package/dist/tooling/shared/vs0t6qt8.js +64 -0
- package/dist/tooling/shared/vx86qjv8.js +150 -0
- package/dist/tooling/shared/w7qe8sj1.js +140 -0
- package/dist/tooling/shared/wt7j7nf6.js +15 -0
- package/dist/tooling/shared/wwnekq5n.js +6 -0
- package/dist/tooling/shared/xhrnjch9.js +185 -0
- package/dist/tooling/shared/xjs6zqtc.js +190 -0
- package/dist/tooling/shared/y031jct9.js +16 -0
- package/dist/tooling/shared/y5656f0e.js +233 -0
- package/dist/tooling/shared/yfr8hzhm.js +604 -0
- package/dist/tooling/shared/yk9mp7vb.js +250 -0
- package/dist/tooling/shared/yw30vnq2.js +139 -0
- package/dist/tooling/shared/z8d7ptht.js +618 -0
- package/dist/tooling/shared/zhwnfyb2.js +9 -0
- package/dist/tooling/shared/zvnhh1n0.js +198 -0
- package/dist/tooling/testing/index.js +3 -3
- package/package.json +14 -2
- 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,225 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertNoControl
|
|
3
|
+
} from "./zchaghkf.js";
|
|
4
|
+
import {
|
|
5
|
+
isOperator,
|
|
6
|
+
operatorName,
|
|
7
|
+
operatorValue,
|
|
8
|
+
tag
|
|
9
|
+
} from "./cn0n68ft.js";
|
|
10
|
+
import {
|
|
11
|
+
OkmError2
|
|
12
|
+
} from "./52szzakm.js";
|
|
13
|
+
|
|
14
|
+
// src/dialects/pg/ops/fragment.ts
|
|
15
|
+
var IDENT = Symbol("okmodel.sql.ident");
|
|
16
|
+
var COLUMN = Symbol("okmodel.sql.column");
|
|
17
|
+
function fragmentError(message, fix) {
|
|
18
|
+
throw new OkmError2("OKM1125", message, { fix: { summary: fix } });
|
|
19
|
+
}
|
|
20
|
+
function isFragmentParts(value) {
|
|
21
|
+
return Array.isArray(value) && value.every(isPart);
|
|
22
|
+
}
|
|
23
|
+
function isPart(value) {
|
|
24
|
+
if (typeof value !== "object" || value === null || !("k" in value))
|
|
25
|
+
return false;
|
|
26
|
+
const kind = value.k;
|
|
27
|
+
if (kind === "t")
|
|
28
|
+
return "s" in value && typeof value.s === "string";
|
|
29
|
+
if (kind === "p")
|
|
30
|
+
return "v" in value && typeof value.v === "string";
|
|
31
|
+
if (kind === "n" || kind === "c")
|
|
32
|
+
return true;
|
|
33
|
+
if (kind === "i")
|
|
34
|
+
return "n" in value && typeof value.n === "string";
|
|
35
|
+
if (kind === "f")
|
|
36
|
+
return "parts" in value && isFragmentParts(value.parts);
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
function readSelectFragment(value) {
|
|
40
|
+
if (!isOperator(value) || operatorName(value) !== "sql")
|
|
41
|
+
return;
|
|
42
|
+
const named = value;
|
|
43
|
+
if (typeof named.as !== "string") {
|
|
44
|
+
fragmentError("A select fragment needs as(name).", 'Call .as("len") and pass that value in select.');
|
|
45
|
+
}
|
|
46
|
+
const stored = operatorValue(value);
|
|
47
|
+
if (!isFragmentParts(stored)) {
|
|
48
|
+
fragmentError("A fragment was not created by fragment``.", "Call fragment`...`.");
|
|
49
|
+
}
|
|
50
|
+
const textual = named.text === true;
|
|
51
|
+
return textual ? { as: named.as, parts: stored, textual: true } : { as: named.as, parts: stored };
|
|
52
|
+
}
|
|
53
|
+
function scanLiteral(literal, state) {
|
|
54
|
+
for (let index = 0;index < literal.length; index += 1) {
|
|
55
|
+
const char = literal[index] ?? "";
|
|
56
|
+
const code = literal.charCodeAt(index);
|
|
57
|
+
if (state.quote !== undefined) {
|
|
58
|
+
if (char !== state.quote)
|
|
59
|
+
continue;
|
|
60
|
+
if (literal[index + 1] === state.quote) {
|
|
61
|
+
index += 1;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
state.quote = undefined;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (code <= 31 && code !== 9 && code !== 10 && code !== 13 || code === 127) {
|
|
68
|
+
fragmentError("A fragment literal contains a control character.", "Remove NUL and other control characters. A newline, tab, or return is allowed.");
|
|
69
|
+
}
|
|
70
|
+
if (char === "'" || char === '"') {
|
|
71
|
+
state.quote = char;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (char === "(") {
|
|
75
|
+
state.paren += 1;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (char === ")") {
|
|
79
|
+
state.paren -= 1;
|
|
80
|
+
if (state.paren < 0) {
|
|
81
|
+
fragmentError("A fragment has unbalanced SQL.", "Keep parentheses and quotes balanced. A fragment cannot close the surrounding predicate.");
|
|
82
|
+
}
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (char === ";") {
|
|
86
|
+
fragmentError("A fragment cannot include a semicolon.", "Pass the value as an interpolation. The fragment is one expression.");
|
|
87
|
+
}
|
|
88
|
+
if (char === "$") {
|
|
89
|
+
fragmentError("A fragment cannot include a dollar quote or a parameter marker.", "Interpolate the value. The planner numbers parameters.");
|
|
90
|
+
}
|
|
91
|
+
if (char === "-" && literal[index + 1] === "-" || char === "/" && literal[index + 1] === "*") {
|
|
92
|
+
fragmentError("A fragment cannot include a comment.", "Remove the comment. A comment can hide the rest of the predicate.");
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function appendText(parts, literal) {
|
|
97
|
+
if (literal.length === 0)
|
|
98
|
+
return;
|
|
99
|
+
parts.push({ k: "t", s: literal });
|
|
100
|
+
}
|
|
101
|
+
function appendValue(parts, value) {
|
|
102
|
+
if (value === null) {
|
|
103
|
+
parts.push({ k: "n" });
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (typeof value === "string") {
|
|
107
|
+
parts.push({ k: "p", v: value });
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (typeof value === "number") {
|
|
111
|
+
if (!Number.isFinite(value)) {
|
|
112
|
+
fragmentError("A fragment needs a finite number.", "Pass a finite number, or leave it out.");
|
|
113
|
+
}
|
|
114
|
+
parts.push({ k: "p", v: String(value) });
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (typeof value === "boolean") {
|
|
118
|
+
parts.push({ k: "p", v: value ? "true" : "false" });
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (typeof value === "bigint") {
|
|
122
|
+
parts.push({ k: "p", v: String(value) });
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (typeof value === "object") {
|
|
126
|
+
if (COLUMN in value) {
|
|
127
|
+
parts.push({ k: "c" });
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (IDENT in value) {
|
|
131
|
+
const name = value[IDENT];
|
|
132
|
+
if (typeof name === "string") {
|
|
133
|
+
parts.push({ k: "i", n: name });
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (isOperator(value) && operatorName(value) === "sql") {
|
|
138
|
+
const nested = operatorValue(value);
|
|
139
|
+
if (!isFragmentParts(nested)) {
|
|
140
|
+
fragmentError("A fragment was not created by fragment``.", "Call fragment`...`.");
|
|
141
|
+
}
|
|
142
|
+
parts.push({ k: "f", parts: nested });
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
fragmentError("A fragment cannot interpolate that value.", "Interpolate a string, number, boolean, null, ident(name), fragment.column, or another fragment.");
|
|
147
|
+
}
|
|
148
|
+
function hasSql(parts) {
|
|
149
|
+
for (const part of parts) {
|
|
150
|
+
if (part.k === "t") {
|
|
151
|
+
if (part.s.trim().length > 0)
|
|
152
|
+
return true;
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
function compile(strings, values) {
|
|
160
|
+
const state = { quote: undefined, paren: 0 };
|
|
161
|
+
const parts = [];
|
|
162
|
+
for (let index = 0;index < values.length + 1; index += 1) {
|
|
163
|
+
const literal = strings[index] ?? "";
|
|
164
|
+
scanLiteral(literal, state);
|
|
165
|
+
appendText(parts, literal);
|
|
166
|
+
if (index === values.length)
|
|
167
|
+
continue;
|
|
168
|
+
if (state.quote !== undefined) {
|
|
169
|
+
fragmentError("A fragment cannot interpolate inside quotes.", "Do not put an interpolation inside quotes. Write title = ${name}.");
|
|
170
|
+
}
|
|
171
|
+
appendValue(parts, values[index]);
|
|
172
|
+
}
|
|
173
|
+
if (state.quote !== undefined || state.paren !== 0) {
|
|
174
|
+
fragmentError("A fragment has unbalanced SQL.", "Keep parentheses and quotes balanced. A fragment cannot close the surrounding predicate.");
|
|
175
|
+
}
|
|
176
|
+
if (!hasSql(parts)) {
|
|
177
|
+
fragmentError("A fragment needs SQL text.", "Write an expression, or interpolate a value.");
|
|
178
|
+
}
|
|
179
|
+
return parts;
|
|
180
|
+
}
|
|
181
|
+
function isTemplate(value) {
|
|
182
|
+
return Array.isArray(value) && "raw" in value;
|
|
183
|
+
}
|
|
184
|
+
function bind(parts, textual = false) {
|
|
185
|
+
const tagged = tag("sql", parts);
|
|
186
|
+
return Object.assign(tagged, {
|
|
187
|
+
as(name) {
|
|
188
|
+
if (typeof name !== "string" || name.length === 0) {
|
|
189
|
+
fragmentError("as(name) needs a result name.", 'Call .as("len") with a name that is not a column.');
|
|
190
|
+
}
|
|
191
|
+
assertNoControl(name, "fragment as");
|
|
192
|
+
const selected = Object.assign(tag("sql", parts), { as: name });
|
|
193
|
+
return textual ? Object.assign(selected, { text: true }) : selected;
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
function sqlExpression(parts, textual = false) {
|
|
198
|
+
return bind(parts, textual);
|
|
199
|
+
}
|
|
200
|
+
function identName(value) {
|
|
201
|
+
if (typeof value !== "object" || value === null || !(IDENT in value))
|
|
202
|
+
return;
|
|
203
|
+
const stored = value[IDENT];
|
|
204
|
+
return typeof stored === "string" ? stored : undefined;
|
|
205
|
+
}
|
|
206
|
+
function fragmentTag(strings, ...values) {
|
|
207
|
+
if (!isTemplate(strings)) {
|
|
208
|
+
fragmentError("Call fragment as a template: fragment`...`.", "Write fragment`length(${fragment.column}) > ${1}`.");
|
|
209
|
+
}
|
|
210
|
+
return bind(compile(strings, values));
|
|
211
|
+
}
|
|
212
|
+
var fragment2 = Object.assign(fragmentTag, {
|
|
213
|
+
column: { [COLUMN]: true }
|
|
214
|
+
});
|
|
215
|
+
function ident2(name) {
|
|
216
|
+
if (typeof name !== "string" || name.length === 0) {
|
|
217
|
+
throw new OkmError2("OKM1122", "ident needs a name.", {
|
|
218
|
+
fix: { summary: "Pass the field name, such as title." }
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
assertNoControl(name, "ident");
|
|
222
|
+
return { [IDENT]: name };
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export { isFragmentParts, readSelectFragment, sqlExpression, identName, fragment2, ident2 };
|
|
@@ -3,21 +3,21 @@ import {
|
|
|
3
3
|
} from "./mss6ctgv.js";
|
|
4
4
|
import {
|
|
5
5
|
effectivePredicate
|
|
6
|
-
} from "./
|
|
7
|
-
import {
|
|
8
|
-
assertOperatorFits,
|
|
9
|
-
textArray,
|
|
10
|
-
arrayElementType
|
|
11
|
-
} from "./zchaghkf.js";
|
|
6
|
+
} from "./n454kcnw.js";
|
|
12
7
|
import {
|
|
13
8
|
runWrite
|
|
14
9
|
} from "./n4jqhpqz.js";
|
|
15
10
|
import {
|
|
16
11
|
writeWouldValidate
|
|
17
|
-
} from "./
|
|
12
|
+
} from "./w9ejzaqf.js";
|
|
18
13
|
import {
|
|
19
14
|
encodeJson
|
|
20
|
-
} from "./
|
|
15
|
+
} from "./vk7rag46.js";
|
|
16
|
+
import {
|
|
17
|
+
assertOperatorFits,
|
|
18
|
+
textArray,
|
|
19
|
+
arrayElementType
|
|
20
|
+
} from "./zchaghkf.js";
|
|
21
21
|
import {
|
|
22
22
|
withRowFilters,
|
|
23
23
|
archiveRules,
|
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
isRecord,
|
|
33
33
|
registerFailFix,
|
|
34
34
|
fail2
|
|
35
|
-
} from "./
|
|
35
|
+
} from "./kgwp4jdd.js";
|
|
36
36
|
import {
|
|
37
37
|
safetyInstalled,
|
|
38
38
|
runSafety
|
|
@@ -198,7 +198,7 @@ async function planWrite(schema, generators, op, tableName, input, options, mods
|
|
|
198
198
|
}
|
|
199
199
|
if (op === "update") {
|
|
200
200
|
if (traitNamed(table, "versioned")) {
|
|
201
|
-
const { planVersioned } = await import("./
|
|
201
|
+
const { planVersioned } = await import("./3t6kw83m.js");
|
|
202
202
|
return withRowFilters(scope, mods.archive, () => {
|
|
203
203
|
noteArchive(table, mods.archive);
|
|
204
204
|
const planned = planVersioned(schema, table, input, record, mods);
|
|
@@ -244,12 +244,12 @@ async function planInsert(table, input, options, mods, generators, scope, tenanc
|
|
|
244
244
|
keyColumns: undefined
|
|
245
245
|
};
|
|
246
246
|
}
|
|
247
|
-
const conflictMod = options.onConflict === undefined || options.onConflict === "error" ? undefined : await import("./
|
|
247
|
+
const conflictMod = options.onConflict === undefined || options.onConflict === "error" ? undefined : await import("./63f4ksbz.js");
|
|
248
248
|
const conflict = conflictMod?.readConflict(table, options.onConflict, allow, tenantKeyList(tenancy));
|
|
249
249
|
if (conflict?.kind === "update" && traitNamed(table, "versioned")) {
|
|
250
250
|
fail2("OKM1120", `onConflict update on ${table.model.name} does not check the version you read.`, "Read the row and update. ignore and return do not change the existing row.");
|
|
251
251
|
}
|
|
252
|
-
const sortMod = sorting ? await import("./
|
|
252
|
+
const sortMod = sorting ? await import("./xfhe73sb.js") : undefined;
|
|
253
253
|
const chunks = chunkRows(rows.map((row) => cellsFor(columns, row)));
|
|
254
254
|
const statements = [];
|
|
255
255
|
const quiet = [];
|
|
@@ -1086,7 +1086,7 @@ function insertRow(table, value, allow, tenancy) {
|
|
|
1086
1086
|
if (column === undefined)
|
|
1087
1087
|
continue;
|
|
1088
1088
|
tenancy?.guard(table.model.name, key, "insert");
|
|
1089
|
-
if (!writable(table, column, allow))
|
|
1089
|
+
if (!writable(table, column, allow, "insert"))
|
|
1090
1090
|
refuse(table, column);
|
|
1091
1091
|
if (value[key] !== undefined)
|
|
1092
1092
|
row[key] = value[key];
|
|
@@ -1142,7 +1142,7 @@ function writtenColumns(table, rows, allow, tenantKeys) {
|
|
|
1142
1142
|
}
|
|
1143
1143
|
const columns = [];
|
|
1144
1144
|
for (const column of table.model.columns) {
|
|
1145
|
-
if (present.has(column.field) && (writable(table, column, allow) || column.fill !== undefined || tenantKeys?.includes(column.field) === true)) {
|
|
1145
|
+
if (present.has(column.field) && (writable(table, column, allow, "insert") || column.fill !== undefined || tenantKeys?.includes(column.field) === true)) {
|
|
1146
1146
|
columns.push(column);
|
|
1147
1147
|
}
|
|
1148
1148
|
}
|
|
@@ -1206,7 +1206,7 @@ function writeSet2(table, value, allow, tenancy) {
|
|
|
1206
1206
|
if (column === undefined)
|
|
1207
1207
|
continue;
|
|
1208
1208
|
tenancy?.guard(table.model.name, key, "update");
|
|
1209
|
-
if (column.guardUpdate || !writable(table, column, allow))
|
|
1209
|
+
if (column.guardUpdate || !writable(table, column, allow, "update"))
|
|
1210
1210
|
refuse(table, column);
|
|
1211
1211
|
set[key] = value[key];
|
|
1212
1212
|
}
|
|
@@ -1475,12 +1475,16 @@ function refuse(table, column) {
|
|
|
1475
1475
|
}
|
|
1476
1476
|
fail2("OKM1120", `Field ${table.model.name}.${column.field} cannot be written.`);
|
|
1477
1477
|
}
|
|
1478
|
-
function writable(table, column, allow) {
|
|
1478
|
+
function writable(table, column, allow, op) {
|
|
1479
1479
|
if (fieldSealed(table.model, column.field))
|
|
1480
1480
|
return false;
|
|
1481
1481
|
if (column.writable)
|
|
1482
1482
|
return true;
|
|
1483
|
-
|
|
1483
|
+
if (!column.guarded || !allow.has(column.field))
|
|
1484
|
+
return false;
|
|
1485
|
+
if (!table.model.primary.includes(column.field))
|
|
1486
|
+
return true;
|
|
1487
|
+
return op === "insert" && column.fill !== undefined;
|
|
1484
1488
|
}
|
|
1485
1489
|
function allowSet2(table, value) {
|
|
1486
1490
|
if (value === undefined)
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
creationOrder2,
|
|
3
3
|
renameColumn2,
|
|
4
4
|
renameTable2
|
|
5
|
-
} from "./
|
|
5
|
+
} from "./12z7aznj.js";
|
|
6
6
|
import {
|
|
7
7
|
isConnectionLost
|
|
8
8
|
} from "./cnkky55j.js";
|
|
@@ -21,12 +21,7 @@ import {
|
|
|
21
21
|
identitySequence,
|
|
22
22
|
createTableSql,
|
|
23
23
|
qualify
|
|
24
|
-
} from "./
|
|
25
|
-
import {
|
|
26
|
-
isExactVersion,
|
|
27
|
-
compareExtensionVersions,
|
|
28
|
-
sameExtensionDefinition
|
|
29
|
-
} from "./r3j8s5y0.js";
|
|
24
|
+
} from "./sjk86yrx.js";
|
|
30
25
|
import {
|
|
31
26
|
isDomain,
|
|
32
27
|
sameEnumLabels
|
|
@@ -34,6 +29,11 @@ import {
|
|
|
34
29
|
import {
|
|
35
30
|
quoteLiteral
|
|
36
31
|
} from "./94ez8kzh.js";
|
|
32
|
+
import {
|
|
33
|
+
isExactVersion,
|
|
34
|
+
compareExtensionVersions,
|
|
35
|
+
sameExtensionDefinition
|
|
36
|
+
} from "./r3j8s5y0.js";
|
|
37
37
|
import {
|
|
38
38
|
staticNamespace2,
|
|
39
39
|
identityKey2,
|
|
@@ -7,12 +7,12 @@ import {
|
|
|
7
7
|
import {
|
|
8
8
|
withHttp,
|
|
9
9
|
settleCall
|
|
10
|
-
} from "./
|
|
10
|
+
} from "./bah9nbg3.js";
|
|
11
11
|
import {
|
|
12
12
|
rejectKeys,
|
|
13
13
|
isRecord,
|
|
14
14
|
fail2
|
|
15
|
-
} from "./
|
|
15
|
+
} from "./kgwp4jdd.js";
|
|
16
16
|
import {
|
|
17
17
|
OkmError2
|
|
18
18
|
} from "./52szzakm.js";
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
encodeText,
|
|
3
3
|
decodeText
|
|
4
|
-
} from "./
|
|
4
|
+
} from "./typ3vy7t.js";
|
|
5
5
|
import {
|
|
6
6
|
required,
|
|
7
7
|
openColumn
|
|
8
|
-
} from "./
|
|
8
|
+
} from "./606g0nbf.js";
|
|
9
|
+
import {
|
|
10
|
+
readClientGenerator
|
|
11
|
+
} from "./rwmrejjz.js";
|
|
9
12
|
import {
|
|
10
13
|
definition,
|
|
11
14
|
rejected
|
|
12
15
|
} from "./tmbdywx0.js";
|
|
13
|
-
import {
|
|
14
|
-
readClientGenerator
|
|
15
|
-
} from "./rwmrejjz.js";
|
|
16
16
|
|
|
17
17
|
// src/dialects/pg/keys.ts
|
|
18
18
|
function id2(options) {
|
|
@@ -11,10 +11,10 @@ import {
|
|
|
11
11
|
startupCatalog2,
|
|
12
12
|
catalogFileText2,
|
|
13
13
|
parseCatalog2
|
|
14
|
-
} from "./
|
|
14
|
+
} from "./12z7aznj.js";
|
|
15
15
|
import {
|
|
16
16
|
open2
|
|
17
|
-
} from "./
|
|
17
|
+
} from "./35q0n9tz.js";
|
|
18
18
|
import {
|
|
19
19
|
sqlStatements,
|
|
20
20
|
transactionControl,
|
|
@@ -35,14 +35,14 @@ import {
|
|
|
35
35
|
assertTargetAlias,
|
|
36
36
|
listTargets,
|
|
37
37
|
selectTarget
|
|
38
|
-
} from "./
|
|
38
|
+
} from "./dpc2r7rb.js";
|
|
39
39
|
import {
|
|
40
40
|
contributedFields
|
|
41
41
|
} from "./n0dgs0pb.js";
|
|
42
42
|
import {
|
|
43
43
|
assertValidation,
|
|
44
44
|
writeWouldValidate
|
|
45
|
-
} from "./
|
|
45
|
+
} from "./w9ejzaqf.js";
|
|
46
46
|
import {
|
|
47
47
|
tableOwner,
|
|
48
48
|
stampOwnership
|
|
@@ -51,17 +51,17 @@ import {
|
|
|
51
51
|
POSTGRES_FLOOR,
|
|
52
52
|
uuidv7NeedsPostgres
|
|
53
53
|
} from "./ga9j92qj.js";
|
|
54
|
-
import {
|
|
55
|
-
catalog,
|
|
56
|
-
isDomain
|
|
57
|
-
} from "./ywspezzx.js";
|
|
58
54
|
import {
|
|
59
55
|
snakeCase,
|
|
60
56
|
emittedTypeName
|
|
61
|
-
} from "./
|
|
57
|
+
} from "./gcefca6p.js";
|
|
62
58
|
import {
|
|
63
59
|
ColumnBuilder2
|
|
64
|
-
} from "./
|
|
60
|
+
} from "./606g0nbf.js";
|
|
61
|
+
import {
|
|
62
|
+
catalog,
|
|
63
|
+
isDomain
|
|
64
|
+
} from "./ywspezzx.js";
|
|
65
65
|
import {
|
|
66
66
|
staticNamespace2
|
|
67
67
|
} from "./358zsv4r.js";
|
|
@@ -236,6 +236,12 @@ var ERROR_DOCS = [
|
|
|
236
236
|
summary: "An operator does not apply to the column type.",
|
|
237
237
|
fix: "Use an operator the error lists for that column type. Search needs a column built for search, not a plain text column."
|
|
238
238
|
},
|
|
239
|
+
{
|
|
240
|
+
code: "OKM1125",
|
|
241
|
+
title: "Bad SQL fragment",
|
|
242
|
+
summary: "A composed fragment is empty, unbalanced, or interpolates a value it cannot bind. A select fragment that is not a number is the same code.",
|
|
243
|
+
fix: "Interpolate a string, number, boolean, null, ident(name), fragment.column, or another fragment. Keep parentheses and quotes balanced. A select fragment is a numeric expression named with as()."
|
|
244
|
+
},
|
|
239
245
|
{
|
|
240
246
|
code: "OKM1130",
|
|
241
247
|
title: "Cursor order",
|
|
@@ -536,6 +542,12 @@ var ERROR_DOCS = [
|
|
|
536
542
|
summary: "A typed SQL signature no longer matches the database.",
|
|
537
543
|
fix: "Regenerate the typed SQL and commit the new signature."
|
|
538
544
|
},
|
|
545
|
+
{
|
|
546
|
+
code: "OKM1602",
|
|
547
|
+
title: "Bad typed SQL",
|
|
548
|
+
summary: "A raw statement is missing its class, is not one select or one write, or the result class has no column initializers.",
|
|
549
|
+
fix: 'Pass "read" or "write", a fragment`...`, and a class with an initializer on every column. Identifiers are ident(name).'
|
|
550
|
+
},
|
|
539
551
|
{
|
|
540
552
|
code: "OKM1701",
|
|
541
553
|
title: "Tenant context missing",
|
|
@@ -545,8 +557,8 @@ var ERROR_DOCS = [
|
|
|
545
557
|
{
|
|
546
558
|
code: "OKM1702",
|
|
547
559
|
title: "Unverifiable tenant SQL",
|
|
548
|
-
summary: "Raw SQL
|
|
549
|
-
fix:
|
|
560
|
+
summary: "Raw SQL on a tenant table cannot prove the tenant predicate. A raw write is this. A raw read that does not select the primary key with ident is this.",
|
|
561
|
+
fix: 'Use update or delete, or select the primary key with ident(name). unscoped("reason") is the reviewed hatch.'
|
|
550
562
|
},
|
|
551
563
|
{
|
|
552
564
|
code: "OKM1704",
|
|
@@ -2386,12 +2398,13 @@ async function checkProject(cwd, flags) {
|
|
|
2386
2398
|
const target = selectTarget(opened.config, named);
|
|
2387
2399
|
assertTargetPolicy(target, "check", flags?.allowProtected ?? false);
|
|
2388
2400
|
assertTargetPolicy(target, "drift", flags?.allowProtected ?? false);
|
|
2389
|
-
const { assertAuthorDrift } = await import("./
|
|
2401
|
+
const { assertAuthorDrift } = await import("./3449rcae.js");
|
|
2390
2402
|
const allowPooler = flags?.allowPooler === true || opened.config.allowPooler === true;
|
|
2391
2403
|
await assertAuthorDrift(target.url, opened.built.catalog, opened.config.roles, allowPooler);
|
|
2392
2404
|
return findings;
|
|
2393
2405
|
}
|
|
2394
2406
|
function unlistedTableFiles(schemaSource, fileNames) {
|
|
2407
|
+
const folded = schemaSource.toLowerCase();
|
|
2395
2408
|
const missing = [];
|
|
2396
2409
|
for (const file of fileNames) {
|
|
2397
2410
|
if (!file.endsWith(".ts"))
|
|
@@ -2399,7 +2412,7 @@ function unlistedTableFiles(schemaSource, fileNames) {
|
|
|
2399
2412
|
const stem = basename(file, ".ts");
|
|
2400
2413
|
if (stem.length === 0 || stem.startsWith("."))
|
|
2401
2414
|
continue;
|
|
2402
|
-
if (!
|
|
2415
|
+
if (!folded.includes(stem.toLowerCase()))
|
|
2403
2416
|
missing.push(file);
|
|
2404
2417
|
}
|
|
2405
2418
|
return missing;
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
import {
|
|
8
8
|
withHttp,
|
|
9
9
|
attachHttp
|
|
10
|
-
} from "./
|
|
10
|
+
} from "./bah9nbg3.js";
|
|
11
11
|
import {
|
|
12
12
|
OkmError2
|
|
13
13
|
} from "./52szzakm.js";
|
|
@@ -37,7 +37,7 @@ async function acceptServer(pool, schema, rows, http, requireMeta, options, sour
|
|
|
37
37
|
}));
|
|
38
38
|
}
|
|
39
39
|
} else {
|
|
40
|
-
const { assertCompatible } = await import("./
|
|
40
|
+
const { assertCompatible } = await import("./16kvjebh.js");
|
|
41
41
|
try {
|
|
42
42
|
await assertCompatible(pool, schema, recorded, source, options);
|
|
43
43
|
} catch (error) {
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
readHandle,
|
|
3
3
|
readCall,
|
|
4
4
|
attachHttp
|
|
5
|
-
} from "./
|
|
5
|
+
} from "./bah9nbg3.js";
|
|
6
6
|
import {
|
|
7
7
|
decodeResult,
|
|
8
8
|
emitWhere,
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
list,
|
|
16
16
|
isRecord,
|
|
17
17
|
fail2
|
|
18
|
-
} from "./
|
|
18
|
+
} from "./kgwp4jdd.js";
|
|
19
19
|
import {
|
|
20
20
|
OkmError2,
|
|
21
21
|
throwNamed2
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
open2
|
|
3
|
-
} from "./
|
|
4
|
-
import"./
|
|
3
|
+
} from "./35q0n9tz.js";
|
|
4
|
+
import"./12z7aznj.js";
|
|
5
5
|
import {
|
|
6
6
|
createdOf,
|
|
7
7
|
testing2
|
|
8
|
-
} from "./
|
|
8
|
+
} from "./b6d6p0zc.js";
|
|
9
9
|
import"./n442h54c.js";
|
|
10
10
|
import {
|
|
11
11
|
projectPath,
|
|
12
12
|
loadConfig,
|
|
13
13
|
loadSchema
|
|
14
|
-
} from "./
|
|
14
|
+
} from "./f4jy1j7x.js";
|
|
15
15
|
import {
|
|
16
16
|
sessionFailure,
|
|
17
17
|
finishQuiet,
|
|
@@ -19,8 +19,8 @@ import {
|
|
|
19
19
|
assertDirectConnection,
|
|
20
20
|
assertStableBackend,
|
|
21
21
|
selectTarget
|
|
22
|
-
} from "./
|
|
23
|
-
import"./
|
|
22
|
+
} from "./dpc2r7rb.js";
|
|
23
|
+
import"./sjk86yrx.js";
|
|
24
24
|
import {
|
|
25
25
|
OkmError2
|
|
26
26
|
} from "./52szzakm.js";
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
2
|
open2
|
|
3
|
-
} from "./
|
|
4
|
-
import"./
|
|
3
|
+
} from "./35q0n9tz.js";
|
|
4
|
+
import"./12z7aznj.js";
|
|
5
5
|
import"./n442h54c.js";
|
|
6
6
|
import {
|
|
7
7
|
assertRoleHealth
|
|
8
|
-
} from "./
|
|
9
|
-
import"./
|
|
8
|
+
} from "./kj9d8maq.js";
|
|
9
|
+
import"./p3xbdcvt.js";
|
|
10
10
|
import {
|
|
11
11
|
errorDoc,
|
|
12
12
|
openProject
|
|
13
|
-
} from "./
|
|
13
|
+
} from "./f4jy1j7x.js";
|
|
14
14
|
import {
|
|
15
15
|
omitManagedObjects,
|
|
16
16
|
sessionFailure,
|
|
17
17
|
finishQuiet,
|
|
18
18
|
assertTargetPolicy,
|
|
19
19
|
selectTarget
|
|
20
|
-
} from "./
|
|
21
|
-
import"./
|
|
20
|
+
} from "./dpc2r7rb.js";
|
|
21
|
+
import"./sjk86yrx.js";
|
|
22
22
|
import {
|
|
23
23
|
OkmError2
|
|
24
24
|
} from "./52szzakm.js";
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
build3
|
|
3
|
-
} from "./
|
|
3
|
+
} from "./n0jmpgj1.js";
|
|
4
4
|
import {
|
|
5
5
|
attachHttp
|
|
6
|
-
} from "./
|
|
6
|
+
} from "./bah9nbg3.js";
|
|
7
7
|
import {
|
|
8
8
|
rejectKeys,
|
|
9
9
|
readLimit,
|
|
10
10
|
indexes,
|
|
11
11
|
isRecord,
|
|
12
12
|
fail2
|
|
13
|
-
} from "./
|
|
13
|
+
} from "./kgwp4jdd.js";
|
|
14
14
|
import {
|
|
15
15
|
OkmError2
|
|
16
16
|
} from "./52szzakm.js";
|