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
|
@@ -1,25 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
noTimeout
|
|
3
|
+
} from "./79dt02vc.js";
|
|
1
4
|
import {
|
|
2
5
|
PGLITE_CAPABILITIES,
|
|
3
6
|
driverErrors,
|
|
4
7
|
rejectClosed,
|
|
5
8
|
rejectCancelled,
|
|
6
9
|
rejectTimedOut,
|
|
7
|
-
mapFailure,
|
|
8
10
|
nextTransactionDepth,
|
|
9
11
|
runCall,
|
|
10
12
|
EMPTY_NOTICES,
|
|
11
13
|
resultFrom
|
|
12
|
-
} from "./
|
|
14
|
+
} from "./kb2sdhfb.js";
|
|
13
15
|
|
|
14
16
|
// src/adapters/pg/pglite.ts
|
|
15
17
|
import { PGlite } from "@electric-sql/pglite";
|
|
16
|
-
var RESET_ALL = "RESET ALL";
|
|
17
|
-
var UNLOCK = "SELECT pg_advisory_unlock_all()";
|
|
18
18
|
async function open3(config = {}) {
|
|
19
|
+
const wire = await import("./g6evj1j3.js");
|
|
19
20
|
const db = new PGlite({
|
|
20
21
|
dataDir: config.dataDir ?? "memory://",
|
|
21
|
-
parsers:
|
|
22
|
-
serializers:
|
|
22
|
+
parsers: wire.parsers,
|
|
23
|
+
serializers: wire.serializers
|
|
23
24
|
});
|
|
24
25
|
await db.waitReady;
|
|
25
26
|
const acquireMs = config.timeouts?.acquire;
|
|
@@ -27,8 +28,8 @@ async function open3(config = {}) {
|
|
|
27
28
|
const notices = noticeBuffer();
|
|
28
29
|
const queryOptions = {
|
|
29
30
|
rowMode: "array",
|
|
30
|
-
parsers:
|
|
31
|
-
serializers:
|
|
31
|
+
parsers: wire.parsers,
|
|
32
|
+
serializers: wire.serializers,
|
|
32
33
|
onNotice(notice) {
|
|
33
34
|
notices.push(notice);
|
|
34
35
|
}
|
|
@@ -39,24 +40,35 @@ async function open3(config = {}) {
|
|
|
39
40
|
inflight += 1;
|
|
40
41
|
}, () => {
|
|
41
42
|
inflight = Math.max(0, inflight - 1);
|
|
42
|
-
});
|
|
43
|
+
}, (error) => wire.fail(error));
|
|
43
44
|
async function lease() {
|
|
44
45
|
if (closed)
|
|
45
46
|
return rejectClosed();
|
|
46
47
|
await slot.acquire(acquireMs);
|
|
47
48
|
let released = false;
|
|
48
49
|
return {
|
|
49
|
-
execute: (text, params, options) =>
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
execute: (text, params, options) => {
|
|
51
|
+
const refused = noTimeout(options);
|
|
52
|
+
if (refused !== undefined)
|
|
53
|
+
return refused;
|
|
54
|
+
return runCall(closed, options, (watch) => session.query(text, params, watch));
|
|
55
|
+
},
|
|
56
|
+
batch: (statements, options) => {
|
|
57
|
+
const refused = noTimeout(options);
|
|
58
|
+
if (refused !== undefined)
|
|
59
|
+
return refused;
|
|
60
|
+
return runCall(closed, options, async (watch) => {
|
|
61
|
+
const { runAtomicBatch } = await import("./b76b8d95.js");
|
|
62
|
+
return runAtomicBatch(session, statements, watch);
|
|
63
|
+
});
|
|
64
|
+
},
|
|
54
65
|
async release() {
|
|
55
66
|
if (released)
|
|
56
67
|
return;
|
|
57
68
|
released = true;
|
|
58
69
|
try {
|
|
59
|
-
await
|
|
70
|
+
const { resetQueried } = await import("./5fe3kbsh.js");
|
|
71
|
+
await resetQueried(session);
|
|
60
72
|
} finally {
|
|
61
73
|
slot.release();
|
|
62
74
|
}
|
|
@@ -66,6 +78,9 @@ async function open3(config = {}) {
|
|
|
66
78
|
return {
|
|
67
79
|
capabilities: PGLITE_CAPABILITIES,
|
|
68
80
|
execute(text, params, options) {
|
|
81
|
+
const refused = noTimeout(options);
|
|
82
|
+
if (refused !== undefined)
|
|
83
|
+
return refused;
|
|
69
84
|
return runCall(closed, options, async (watch) => {
|
|
70
85
|
await slot.acquire(acquireMs);
|
|
71
86
|
try {
|
|
@@ -76,6 +91,9 @@ async function open3(config = {}) {
|
|
|
76
91
|
});
|
|
77
92
|
},
|
|
78
93
|
async batch(statements, options) {
|
|
94
|
+
const refused = noTimeout(options);
|
|
95
|
+
if (refused !== undefined)
|
|
96
|
+
return refused;
|
|
79
97
|
const connection = await lease();
|
|
80
98
|
try {
|
|
81
99
|
return await connection.batch(statements, options);
|
|
@@ -111,6 +129,12 @@ async function open3(config = {}) {
|
|
|
111
129
|
}
|
|
112
130
|
};
|
|
113
131
|
}
|
|
132
|
+
function seal2(pool) {
|
|
133
|
+
let closed = 0;
|
|
134
|
+
return new Proxy(pool, {
|
|
135
|
+
get: (inner, key) => key === "close" ? () => Promise.resolve(closed = 1) : (inner = inner[key], closed && inner?.call ? () => rejectClosed() : inner)
|
|
136
|
+
});
|
|
137
|
+
}
|
|
114
138
|
|
|
115
139
|
class PgliteSession {
|
|
116
140
|
canCancel = false;
|
|
@@ -120,12 +144,14 @@ class PgliteSession {
|
|
|
120
144
|
notices;
|
|
121
145
|
enter;
|
|
122
146
|
leave;
|
|
123
|
-
|
|
147
|
+
fail;
|
|
148
|
+
constructor(db, options, notices, enter, leave, fail) {
|
|
124
149
|
this.db = db;
|
|
125
150
|
this.options = options;
|
|
126
151
|
this.notices = notices;
|
|
127
152
|
this.enter = enter;
|
|
128
153
|
this.leave = leave;
|
|
154
|
+
this.fail = fail;
|
|
129
155
|
}
|
|
130
156
|
query(text, params, watch) {
|
|
131
157
|
const why = watch?.reason();
|
|
@@ -142,7 +168,7 @@ class PgliteSession {
|
|
|
142
168
|
}, (error) => {
|
|
143
169
|
this.leave();
|
|
144
170
|
this.notices.take();
|
|
145
|
-
return
|
|
171
|
+
return this.fail(stampQuery(error, text)).then((mapped) => {
|
|
146
172
|
throw mapped;
|
|
147
173
|
});
|
|
148
174
|
});
|
|
@@ -226,56 +252,10 @@ class Slot {
|
|
|
226
252
|
return this.waiters.length;
|
|
227
253
|
}
|
|
228
254
|
}
|
|
229
|
-
|
|
230
|
-
if (
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
});
|
|
234
|
-
try {
|
|
235
|
-
await session.query(RESET_ALL, undefined, undefined);
|
|
236
|
-
await session.query(UNLOCK, undefined, undefined);
|
|
237
|
-
} catch {
|
|
238
|
-
await session.rollback().catch(() => {
|
|
239
|
-
return;
|
|
240
|
-
});
|
|
241
|
-
await session.query(RESET_ALL, undefined, undefined);
|
|
242
|
-
await session.query(UNLOCK, undefined, undefined);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
function wireMap(oids) {
|
|
246
|
-
const parsers = {};
|
|
247
|
-
for (const oid of oids)
|
|
248
|
-
parsers[oid] = (value) => value;
|
|
249
|
-
return parsers;
|
|
255
|
+
function stampQuery(error, text) {
|
|
256
|
+
if (typeof error === "object" && error !== null && !("query" in error))
|
|
257
|
+
Reflect.set(error, "query", text);
|
|
258
|
+
return error;
|
|
250
259
|
}
|
|
251
|
-
var WIRE = wireMap([
|
|
252
|
-
16,
|
|
253
|
-
17,
|
|
254
|
-
20,
|
|
255
|
-
21,
|
|
256
|
-
23,
|
|
257
|
-
25,
|
|
258
|
-
114,
|
|
259
|
-
700,
|
|
260
|
-
701,
|
|
261
|
-
1043,
|
|
262
|
-
1082,
|
|
263
|
-
1114,
|
|
264
|
-
1184,
|
|
265
|
-
1700,
|
|
266
|
-
2950,
|
|
267
|
-
3802,
|
|
268
|
-
1000,
|
|
269
|
-
1005,
|
|
270
|
-
1007,
|
|
271
|
-
1009,
|
|
272
|
-
1016,
|
|
273
|
-
1115,
|
|
274
|
-
1182,
|
|
275
|
-
1185,
|
|
276
|
-
1231,
|
|
277
|
-
199,
|
|
278
|
-
3807
|
|
279
|
-
]);
|
|
280
260
|
|
|
281
|
-
export { open3 };
|
|
261
|
+
export { open3, seal2 };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
FUNCTION_ARG_TYPES
|
|
3
|
-
} from "./
|
|
3
|
+
} from "./b5pftnn2.js";
|
|
4
4
|
import {
|
|
5
5
|
OkmError2
|
|
6
6
|
} from "./52szzakm.js";
|
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
async function assertRoleHealth(runner, roles, objects) {
|
|
10
10
|
const managed = new Set((roles.managed ?? []).map((role) => role.name));
|
|
11
11
|
const named = [roles.migration, roles.app];
|
|
12
|
+
if (roles.reporting !== undefined)
|
|
13
|
+
named.push(roles.reporting);
|
|
12
14
|
for (const name of named) {
|
|
13
15
|
if (managed.has(name))
|
|
14
16
|
continue;
|
|
@@ -22,15 +24,16 @@ async function assertRoleHealth(runner, roles, objects) {
|
|
|
22
24
|
if (managed.size > 0)
|
|
23
25
|
await assertCreateRole(runner, await currentUser(runner));
|
|
24
26
|
for (const object of objects) {
|
|
25
|
-
if (object.kind !== "grant"
|
|
27
|
+
if (object.kind !== "grant")
|
|
26
28
|
continue;
|
|
29
|
+
if (managed.has(object.identity.role) && !await roleExists(runner, object.identity.role)) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
27
32
|
await assertGrant(runner, object);
|
|
28
33
|
}
|
|
29
34
|
}
|
|
30
35
|
async function assertCreateRole(runner, role) {
|
|
31
|
-
const result = await runner.execute("select rolcreaterole from pg_roles where rolname = $1", [
|
|
32
|
-
role
|
|
33
|
-
]);
|
|
36
|
+
const result = await runner.execute("select rolsuper or rolcreaterole from pg_roles where rolname = $1", [role]);
|
|
34
37
|
if (!truthy(result.rows[0]?.[0])) {
|
|
35
38
|
throw new OkmError2("forbidden", `Role ${role} lacks CREATEROLE. Nothing was changed.`, {
|
|
36
39
|
kind: "forbidden",
|
|
@@ -62,11 +65,36 @@ async function assertGrant(runner, object) {
|
|
|
62
65
|
missing(object, `${schema}.${fn}`);
|
|
63
66
|
return;
|
|
64
67
|
}
|
|
65
|
-
if (target.kind === "namespace")
|
|
68
|
+
if (target.kind === "namespace") {
|
|
69
|
+
const allowed = await runner.execute(`select exists (
|
|
70
|
+
select 1 from pg_namespace n
|
|
71
|
+
cross join lateral aclexplode(n.nspacl) as a
|
|
72
|
+
where n.nspname = $2
|
|
73
|
+
and a.privilege_type = $3
|
|
74
|
+
and (
|
|
75
|
+
a.grantee = 0
|
|
76
|
+
or a.grantee = (select oid from pg_roles where rolname = $1)
|
|
77
|
+
)
|
|
78
|
+
)`, [object.identity.role, schema, privilege]);
|
|
79
|
+
if (!truthy(allowed.rows[0]?.[0]))
|
|
80
|
+
missing(object, `schema ${schema}`);
|
|
66
81
|
return;
|
|
82
|
+
}
|
|
67
83
|
const relkinds = target.kind === "sequence" ? "'S'" : target.kind === "view" ? "'v'" : target.kind === "materializedView" ? "'m'" : "'r', 'p'";
|
|
68
84
|
if (!await relationExists(runner, schema, target.name, relkinds))
|
|
69
85
|
return;
|
|
86
|
+
const column = /^(SELECT|UPDATE)\(([^)]*)\)$/.exec(privilege);
|
|
87
|
+
const listed = column?.[2];
|
|
88
|
+
const base = column?.[1];
|
|
89
|
+
if (listed !== undefined && base !== undefined) {
|
|
90
|
+
const names = listed.split(",").filter((name) => name.length > 0);
|
|
91
|
+
for (const name of names) {
|
|
92
|
+
const allowed = await runner.execute("select has_column_privilege($1, format('%I.%I', $2::text, $3::text), $4, $5)", [object.identity.role, schema, target.name, name, base]);
|
|
93
|
+
if (!truthy(allowed.rows[0]?.[0]))
|
|
94
|
+
missing(object, `${schema}.${target.name}.${name}`);
|
|
95
|
+
}
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
70
98
|
const probe = target.kind === "sequence" ? "select has_sequence_privilege($1, format('%I.%I', $2::text, $3::text), $4)" : "select has_table_privilege($1, format('%I.%I', $2::text, $3::text), $4)";
|
|
71
99
|
const allowed = await runner.execute(probe, [
|
|
72
100
|
object.identity.role,
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// src/dialects/pg/ops/window.ts
|
|
2
|
+
var RUNTIME = Symbol.for("okmodel.window");
|
|
3
|
+
function isWindow(value) {
|
|
4
|
+
return typeof value === "object" && value !== null && RUNTIME in value;
|
|
5
|
+
}
|
|
6
|
+
function rowNumber2(options) {
|
|
7
|
+
return frame("rowNumber", "row_number", undefined, options);
|
|
8
|
+
}
|
|
9
|
+
function rank2(options) {
|
|
10
|
+
return frame("rank", "rank", undefined, options);
|
|
11
|
+
}
|
|
12
|
+
function denseRank2(options) {
|
|
13
|
+
return frame("denseRank", "dense_rank", undefined, options);
|
|
14
|
+
}
|
|
15
|
+
function runningTotal2(column, options) {
|
|
16
|
+
return frame("runningTotal", "sum", column, options);
|
|
17
|
+
}
|
|
18
|
+
function frame(label, fn, column, options) {
|
|
19
|
+
const spec = options ?? { orderBy: undefined, as: undefined, partitionBy: undefined };
|
|
20
|
+
return {
|
|
21
|
+
[RUNTIME]: true,
|
|
22
|
+
label,
|
|
23
|
+
fn,
|
|
24
|
+
column,
|
|
25
|
+
partitionBy: spec.partitionBy,
|
|
26
|
+
orderBy: spec.orderBy,
|
|
27
|
+
as: spec.as
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { isWindow, rowNumber2, rank2, denseRank2, runningTotal2 };
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
creationOrder2
|
|
3
|
-
} from "./
|
|
3
|
+
} from "./qq3899ht.js";
|
|
4
4
|
import {
|
|
5
5
|
isDomain
|
|
6
|
-
} from "./
|
|
6
|
+
} from "./ywspezzx.js";
|
|
7
7
|
import {
|
|
8
8
|
quoteLiteral
|
|
9
9
|
} from "./94ez8kzh.js";
|
|
10
10
|
import {
|
|
11
11
|
identityKey2
|
|
12
|
-
} from "./
|
|
12
|
+
} from "./358zsv4r.js";
|
|
13
13
|
import {
|
|
14
14
|
fitIdentifier2
|
|
15
15
|
} from "./nfzc5z0w.js";
|
|
@@ -22,6 +22,7 @@ function renderCatalog(source, schema) {
|
|
|
22
22
|
const folded = foldedKeys(source);
|
|
23
23
|
const statements = [];
|
|
24
24
|
const ordered = creationOrder2(source);
|
|
25
|
+
const created = uniqueBeforeForeignKey(ordered);
|
|
25
26
|
for (const object of ordered) {
|
|
26
27
|
if (object.kind !== "type" || object.owner === "ignored")
|
|
27
28
|
continue;
|
|
@@ -29,8 +30,8 @@ function renderCatalog(source, schema) {
|
|
|
29
30
|
if (sql !== undefined)
|
|
30
31
|
statements.push(sql);
|
|
31
32
|
}
|
|
32
|
-
for (const object of
|
|
33
|
-
if (object.kind === "type" || object.kind === "function" || object.kind === "trigger" || object.kind === "view" || object.kind === "materializedView" || ownedByView(object)) {
|
|
33
|
+
for (const object of created) {
|
|
34
|
+
if (object.kind === "type" || object.kind === "function" || object.kind === "trigger" || object.kind === "view" || object.kind === "materializedView" || object.kind === "policy" || ownedByView(object)) {
|
|
34
35
|
continue;
|
|
35
36
|
}
|
|
36
37
|
if (object.owner === "ignored")
|
|
@@ -46,6 +47,12 @@ function renderCatalog(source, schema) {
|
|
|
46
47
|
if (sql !== undefined)
|
|
47
48
|
statements.push(sql);
|
|
48
49
|
}
|
|
50
|
+
for (const object of created) {
|
|
51
|
+
if (object.kind !== "policy" || object.owner === "ignored")
|
|
52
|
+
continue;
|
|
53
|
+
for (const step of policyCreatePlan(object, schema))
|
|
54
|
+
statements.push(step.sql);
|
|
55
|
+
}
|
|
49
56
|
for (const kind of ["function", "trigger"]) {
|
|
50
57
|
for (const object of ordered) {
|
|
51
58
|
if (object.kind !== kind || object.owner === "ignored")
|
|
@@ -73,6 +80,48 @@ function renderCatalog(source, schema) {
|
|
|
73
80
|
}
|
|
74
81
|
return statements;
|
|
75
82
|
}
|
|
83
|
+
function uniqueBeforeForeignKey(objects) {
|
|
84
|
+
const uniques = objects.filter((object) => object.kind === "constraint" && object.definition.constraintKind === "unique");
|
|
85
|
+
if (uniques.length === 0)
|
|
86
|
+
return objects;
|
|
87
|
+
const emitted = new Set;
|
|
88
|
+
const result = [];
|
|
89
|
+
for (const object of objects) {
|
|
90
|
+
if (emitted.has(object))
|
|
91
|
+
continue;
|
|
92
|
+
if (object.kind === "constraint" && object.definition.constraintKind === "foreignKey") {
|
|
93
|
+
const target = object.definition.references;
|
|
94
|
+
if (target !== undefined && !coveredByPrimary(objects, target.parent, target.columns)) {
|
|
95
|
+
const columns = target.columns.join("\x00");
|
|
96
|
+
for (const unique of uniques) {
|
|
97
|
+
if (emitted.has(unique))
|
|
98
|
+
continue;
|
|
99
|
+
if (!sameRef(unique.identity.parent, target.parent))
|
|
100
|
+
continue;
|
|
101
|
+
if (unique.definition.columns.join("\x00") !== columns)
|
|
102
|
+
continue;
|
|
103
|
+
result.push(unique);
|
|
104
|
+
emitted.add(unique);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
result.push(object);
|
|
109
|
+
emitted.add(object);
|
|
110
|
+
}
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
function coveredByPrimary(objects, parent, columns) {
|
|
114
|
+
const key = columns.join("\x00");
|
|
115
|
+
return objects.some((object) => object.kind === "constraint" && object.definition.constraintKind === "primaryKey" && sameRef(object.identity.parent, parent) && object.definition.columns.join("\x00") === key);
|
|
116
|
+
}
|
|
117
|
+
function sameRef(left, right) {
|
|
118
|
+
if (left.name !== right.name || left.namespace.form !== right.namespace.form)
|
|
119
|
+
return false;
|
|
120
|
+
if (left.namespace.form === "static" && right.namespace.form === "static") {
|
|
121
|
+
return left.namespace.name === right.namespace.name;
|
|
122
|
+
}
|
|
123
|
+
return left.namespace.form === "template" && right.namespace.form === "template" ? left.namespace.pattern === right.namespace.pattern : false;
|
|
124
|
+
}
|
|
76
125
|
function ownedByView(object) {
|
|
77
126
|
if (object.kind !== "index")
|
|
78
127
|
return false;
|
|
@@ -149,7 +198,39 @@ function functionSql(object, schema, replace) {
|
|
|
149
198
|
}
|
|
150
199
|
function viewSql(object, schema, replace) {
|
|
151
200
|
const verb = replace ? "create or replace view" : "create view";
|
|
152
|
-
|
|
201
|
+
const invoker = object.definition.securityInvoker === true ? " with (security_invoker = true)" : "";
|
|
202
|
+
return `${verb} ${qualify(schema, object.identity.name)}${invoker} as ${object.definition.query}`;
|
|
203
|
+
}
|
|
204
|
+
function policyCreatePlan(object, schema) {
|
|
205
|
+
const table = qualify(schema, object.identity.parent.name);
|
|
206
|
+
const name = quoteIdent(object.identity.name);
|
|
207
|
+
const command = object.definition.command === "all" ? "all" : "select";
|
|
208
|
+
const check = object.definition.command === "all" ? ` with check ${object.definition.expression}` : "";
|
|
209
|
+
const create = {
|
|
210
|
+
sql: `create policy ${name} on ${table} as permissive for ${command} using ${object.definition.expression}${check}`,
|
|
211
|
+
kind: "create-policy"
|
|
212
|
+
};
|
|
213
|
+
if (object.definition.command !== "all")
|
|
214
|
+
return [create];
|
|
215
|
+
return [
|
|
216
|
+
{ sql: `alter table ${table} enable row level security`, kind: "enable-rls" },
|
|
217
|
+
{ sql: `alter table ${table} force row level security`, kind: "enable-rls" },
|
|
218
|
+
create
|
|
219
|
+
];
|
|
220
|
+
}
|
|
221
|
+
function policyDropPlan(object, schema) {
|
|
222
|
+
const table = qualify(schema, object.identity.parent.name);
|
|
223
|
+
const drop = {
|
|
224
|
+
sql: `drop policy ${quoteIdent(object.identity.name)} on ${table}`,
|
|
225
|
+
kind: "drop-policy"
|
|
226
|
+
};
|
|
227
|
+
if (object.definition.command !== "all")
|
|
228
|
+
return [drop];
|
|
229
|
+
return [
|
|
230
|
+
drop,
|
|
231
|
+
{ sql: `alter table ${table} no force row level security`, kind: "disable-rls" },
|
|
232
|
+
{ sql: `alter table ${table} disable row level security`, kind: "disable-rls" }
|
|
233
|
+
];
|
|
153
234
|
}
|
|
154
235
|
function materializedViewSql(object, schema) {
|
|
155
236
|
return `create materialized view ${qualify(schema, object.identity.name)} as ${object.definition.query} with no data`;
|
|
@@ -315,4 +396,4 @@ function qualify(schema, name) {
|
|
|
315
396
|
return `${quoteIdent(schema)}.${quoteIdent(name)}`;
|
|
316
397
|
}
|
|
317
398
|
|
|
318
|
-
export { quoteIdent, renderCatalog, ownedByView, dropObjectSql, createObjectSql, functionSql, viewSql, refreshMaterializedViewSql, alterColumnSql, identitySequence, createTableSql, qualify };
|
|
399
|
+
export { quoteIdent, renderCatalog, uniqueBeforeForeignKey, ownedByView, dropObjectSql, createObjectSql, functionSql, viewSql, policyCreatePlan, policyDropPlan, refreshMaterializedViewSql, alterColumnSql, identitySequence, createTableSql, qualify };
|