okmodel 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +237 -19
- package/dist/adapters/capabilities.d.ts +34 -0
- package/dist/adapters/pg/bunsql-extra.d.ts +17 -0
- package/dist/adapters/pg/bunsql.d.ts +60 -0
- package/dist/adapters/pg/call.d.ts +2 -12
- package/dist/adapters/pg/nodepostgres-extra.d.ts +18 -0
- package/dist/adapters/pg/nodepostgres.d.ts +57 -0
- package/dist/adapters/pg/postgres-extra.d.ts +50 -1
- package/dist/adapters/pg/postgresjs.d.ts +0 -4
- package/dist/adapters/pg/session.d.ts +94 -0
- package/dist/adapters/pg/watch.d.ts +18 -0
- package/dist/contracts/catalog/object.d.ts +1 -0
- package/dist/contracts/catalog/types.d.ts +15 -8
- package/dist/contracts/connection.d.ts +13 -0
- package/dist/contracts/driver.d.ts +18 -5
- package/dist/contracts/error.d.ts +17 -1
- package/dist/contracts/generator.d.ts +63 -0
- package/dist/contracts/index.d.ts +2 -2
- package/dist/contracts/index.js +1 -1
- package/dist/contracts/internal.js +11 -9
- package/dist/contracts/location.d.ts +24 -0
- package/dist/contracts/rows.d.ts +15 -0
- package/dist/dialects/pg/archive-bind.d.ts +22 -0
- package/dist/dialects/pg/column.d.ts +126 -9
- package/dist/dialects/pg/compile.d.ts +1 -0
- package/dist/dialects/pg/custom.d.ts +6 -0
- package/dist/dialects/pg/filter-parse.d.ts +19 -0
- package/dist/dialects/pg/filters.d.ts +19 -0
- package/dist/dialects/pg/index.d.ts +11 -2
- package/dist/dialects/pg/index.js +159 -1063
- package/dist/dialects/pg/keys.d.ts +19 -3
- package/dist/dialects/pg/model.d.ts +223 -2
- package/dist/dialects/pg/operator-fit.d.ts +86 -0
- package/dist/dialects/pg/operators.d.ts +39 -1
- package/dist/dialects/pg/ops/arr-append.d.ts +9 -0
- package/dist/dialects/pg/ops/arr-ns.d.ts +7 -0
- package/dist/dialects/pg/ops/arr-remove.d.ts +9 -0
- package/dist/dialects/pg/ops/containedBy.d.ts +9 -0
- package/dist/dialects/pg/ops/contains.d.ts +8 -4
- package/dist/dialects/pg/ops/hasAnyKey.d.ts +8 -0
- package/dist/dialects/pg/ops/hasKey.d.ts +8 -0
- package/dist/dialects/pg/ops/json-ns.d.ts +6 -0
- package/dist/dialects/pg/ops/json-set.d.ts +12 -0
- package/dist/dialects/pg/ops/matches.d.ts +16 -0
- package/dist/dialects/pg/ops/overlaps.d.ts +9 -0
- package/dist/dialects/pg/ops/path.d.ts +13 -0
- package/dist/dialects/pg/preset.d.ts +76 -0
- package/dist/dialects/pg/relations.d.ts +59 -2
- package/dist/dialects/pg/schema.d.ts +109 -5
- package/dist/dialects/pg/table.d.ts +130 -11
- package/dist/dialects/pg/temporal.d.ts +9 -7
- package/dist/dialects/pg/tenancy.d.ts +94 -0
- package/dist/dialects/pg/through.d.ts +21 -0
- package/dist/dialects/pg/trait.d.ts +141 -0
- package/dist/dialects/pg/where.d.ts +37 -0
- package/dist/runtime/aggregate.d.ts +25 -0
- package/dist/runtime/archive-handle.d.ts +18 -0
- package/dist/runtime/archive-rules.d.ts +12 -0
- package/dist/runtime/archive.d.ts +73 -0
- package/dist/runtime/batch.d.ts +20 -0
- package/dist/runtime/client.d.ts +114 -5
- package/dist/runtime/conflict.d.ts +2 -1
- package/dist/runtime/exposure.d.ts +27 -0
- package/dist/runtime/hookm.d.ts +39 -0
- package/dist/runtime/ids/index.d.ts +11 -0
- package/dist/runtime/ids/index.js +193 -0
- package/dist/runtime/ids/okid-extended.d.ts +19 -0
- package/dist/runtime/ids/okid-generator.d.ts +21 -0
- package/dist/runtime/ids/okid-shared.d.ts +89 -0
- package/dist/runtime/ids/okid.d.ts +24 -0
- package/dist/runtime/ids/uuid.d.ts +21 -0
- package/dist/runtime/lock.d.ts +22 -0
- package/dist/runtime/operator-sql.d.ts +8 -0
- package/dist/runtime/page.d.ts +25 -0
- package/dist/runtime/pg/bun.d.ts +30 -0
- package/dist/runtime/pg/bun.js +52 -0
- package/dist/runtime/pg/pg.d.ts +29 -0
- package/dist/runtime/pg/pg.js +52 -0
- package/dist/runtime/pg/pglite.js +16 -17
- package/dist/runtime/pg/postgresjs.js +14 -24
- package/dist/runtime/plan.d.ts +146 -7
- package/dist/runtime/preset-stack.d.ts +17 -0
- package/dist/runtime/presets.d.ts +48 -0
- package/dist/runtime/read-stream.d.ts +26 -0
- package/dist/runtime/safety/index.d.ts +159 -0
- package/dist/runtime/safety/index.js +294 -0
- package/dist/runtime/safety-hook.d.ts +42 -0
- package/dist/runtime/server-check.d.ts +34 -0
- package/dist/runtime/tenancy/index.d.ts +37 -0
- package/dist/runtime/tenancy/index.js +365 -0
- package/dist/runtime/trait-read.d.ts +30 -0
- package/dist/runtime/traits/index.d.ts +128 -0
- package/dist/runtime/traits/index.js +509 -0
- package/dist/runtime/transaction.d.ts +19 -0
- package/dist/runtime/tx.d.ts +22 -7
- package/dist/runtime/types.d.ts +390 -25
- package/dist/runtime/validate/bind.d.ts +11 -0
- package/dist/runtime/validate/closed.d.ts +16 -0
- package/dist/runtime/validate/engine.d.ts +41 -0
- package/dist/runtime/validate/hook.d.ts +17 -0
- package/dist/runtime/validate/index.d.ts +21 -0
- package/dist/runtime/validate/index.js +175 -0
- package/dist/runtime/validate/load.d.ts +13 -0
- package/dist/runtime/validate/places.d.ts +41 -0
- package/dist/runtime/validate/rules.d.ts +108 -0
- package/dist/runtime/validate/surface.d.ts +102 -0
- package/dist/runtime/write.d.ts +30 -5
- package/dist/shared/{fgqgsb5z.js → 0qkxbm1f.js} +2 -2
- package/dist/shared/0v1g424p.js +26 -0
- package/dist/shared/10tjenmd.js +210 -0
- package/dist/shared/{tb4ze1tr.js → 1dp5knt7.js} +95 -10
- package/dist/shared/38crxbgn.js +229 -0
- package/dist/shared/3a5ne750.js +158 -0
- package/dist/shared/4b9da9d7.js +138 -0
- package/dist/shared/4e4c6vq2.js +62 -0
- package/dist/shared/{ckb1p0a4.js → 4jzzghr6.js} +416 -83
- package/dist/shared/{ycwz42az.js → 52szzakm.js} +6 -26
- package/dist/shared/{kynx7vbm.js → 5z4q2zda.js} +604 -21
- package/dist/shared/672t5vym.js +12 -0
- package/dist/shared/7m88x3e9.js +45 -0
- package/dist/shared/7mht49yd.js +1091 -0
- package/dist/shared/{mtkwv8wx.js → 7p2wbz7f.js} +1 -1
- package/dist/shared/83eaefwr.js +10 -0
- package/dist/shared/96ps4g1z.js +32 -0
- package/dist/shared/97g2jnrw.js +76 -0
- package/dist/shared/{xy79j5hq.js → 9k6vetvf.js} +25 -36
- package/dist/shared/{w8samvk1.js → a1gdp7j9.js} +1 -1
- package/dist/shared/a5sxz52y.js +13 -0
- package/dist/shared/{dynq16vb.js → b066g80h.js} +8 -6
- package/dist/shared/cstgkzdx.js +154 -0
- package/dist/shared/{ax16zpvm.js → d04j53v8.js} +6 -5
- package/dist/shared/{y9m15dfv.js → d2whjz4k.js} +15 -9
- package/dist/shared/dd4f8mnx.js +307 -0
- package/dist/shared/e6wg00wd.js +164 -0
- package/dist/shared/e7a268fy.js +195 -0
- package/dist/shared/{vkm3q4x1.js → eaxwrgby.js} +4 -3
- package/dist/shared/{7ck0dtry.js → ecdzej21.js} +160 -81
- package/dist/shared/{px90pf9p.js → edwqqryd.js} +21 -16
- package/dist/shared/{g2v6gnc8.js → eqmtn1bj.js} +57 -5
- package/dist/shared/g1b5zzj9.js +75 -0
- package/dist/shared/g9f0zqce.js +376 -0
- package/dist/shared/ge03bfca.js +64 -0
- package/dist/shared/{79ggp945.js → jns2wx4t.js} +55 -12
- package/dist/shared/k3ted12y.js +33 -0
- package/dist/shared/k7dwkhvq.js +31 -0
- package/dist/shared/{hd293j9g.js → kyxb62mc.js} +14 -2
- package/dist/shared/m9tv7xn7.js +404 -0
- package/dist/shared/mrq77sgw.js +55 -0
- package/dist/shared/mxmcdsh5.js +450 -0
- package/dist/shared/n442h54c.js +14 -0
- package/dist/shared/n47rd821.js +442 -0
- package/dist/shared/n4jqhpqz.js +27 -0
- package/dist/shared/{mkjmqjv4.js → nfzc5z0w.js} +2 -104
- package/dist/shared/nsva2a6b.js +42 -0
- package/dist/shared/ps43134h.js +69 -0
- package/dist/shared/{8b04d28c.js → py3nh7jy.js} +2 -2
- package/dist/shared/qa5dsc7z.js +86 -0
- package/dist/shared/{g5fhqmwe.js → qxa0yb9j.js} +6 -4
- package/dist/shared/r6nwkxnt.js +86 -0
- package/dist/shared/{4j72449d.js → rtnaqre0.js} +3 -3
- package/dist/shared/rwmrejjz.js +26 -0
- package/dist/shared/{zhc5vmgf.js → s6gqfn5j.js} +2 -2
- package/dist/shared/sacqha1y.js +70 -0
- package/dist/shared/{qk3hxfja.js → sfh4pk75.js} +5 -5
- package/dist/shared/{j5cn2963.js → t4tbsy9h.js} +13 -64
- package/dist/shared/{ngk8gj61.js → tbszx8mz.js} +15 -1
- package/dist/shared/v18jva5b.js +90 -0
- package/dist/shared/x9v1qgeb.js +201 -0
- package/dist/shared/xatfg0gn.js +193 -0
- package/dist/shared/xkz8g6by.js +225 -0
- package/dist/shared/{f5thc1s0.js → xrfnq5k8.js} +237 -418
- package/dist/shared/ytg3xf9p.js +149 -0
- package/dist/shared/yw5c610b.js +48 -0
- package/dist/shared/zd93g3rq.js +31 -0
- package/dist/shared/zt8y0wzb.js +132 -0
- package/dist/shared/{p0cbr3g2.js → zwmqxb0g.js} +1 -1
- package/dist/tooling/cli.js +14 -10
- package/dist/tooling/migrate/commands.d.ts +10 -0
- package/dist/tooling/migrate/engine.d.ts +36 -0
- package/package.json +56 -4
- package/dist/shared/gk7cs7sp.js +0 -566
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
open3
|
|
3
|
-
} from "./
|
|
3
|
+
} from "./0qkxbm1f.js";
|
|
4
4
|
import {
|
|
5
5
|
PGLITE_CAPABILITIES,
|
|
6
6
|
readCapability2,
|
|
7
7
|
hasCapability2
|
|
8
|
-
} from "./
|
|
8
|
+
} from "./9k6vetvf.js";
|
|
9
9
|
export {
|
|
10
10
|
PGLITE_CAPABILITIES as capabilities,
|
|
11
11
|
hasCapability2 as hasCapability,
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import {
|
|
2
|
+
send,
|
|
3
|
+
connectClient
|
|
4
|
+
} from "./38crxbgn.js";
|
|
5
|
+
import {
|
|
6
|
+
isConnectionLost
|
|
7
|
+
} from "./tbszx8mz.js";
|
|
8
|
+
import {
|
|
9
|
+
WireSession
|
|
10
|
+
} from "./cstgkzdx.js";
|
|
11
|
+
import {
|
|
12
|
+
rejectClosed,
|
|
13
|
+
runCall
|
|
14
|
+
} from "./9k6vetvf.js";
|
|
15
|
+
|
|
16
|
+
// src/adapters/pg/nodepostgres-extra.ts
|
|
17
|
+
var RESET_ALL = "RESET ALL";
|
|
18
|
+
var UNLOCK = "SELECT pg_advisory_unlock_all()";
|
|
19
|
+
async function checkout(held) {
|
|
20
|
+
const { pool, counters, named, isClosed } = held;
|
|
21
|
+
if (isClosed())
|
|
22
|
+
return rejectClosed();
|
|
23
|
+
const client = await connectClient(pool, held.acquireMs, counters);
|
|
24
|
+
counters.reserved += 1;
|
|
25
|
+
let lost = false;
|
|
26
|
+
const onError = () => {
|
|
27
|
+
lost = true;
|
|
28
|
+
};
|
|
29
|
+
const events = client;
|
|
30
|
+
events.on("error", onError);
|
|
31
|
+
const local = new Set;
|
|
32
|
+
const session = new WireSession((text, params) => send(client, text, params, named, client), held.notices, isClosed, true, () => {
|
|
33
|
+
counters.reservedBusy += 1;
|
|
34
|
+
}, () => {
|
|
35
|
+
counters.reservedBusy = Math.max(0, counters.reservedBusy - 1);
|
|
36
|
+
}, local);
|
|
37
|
+
const guard = (run) => lost ? rejectClosed("The connection was lost.") : run().catch((error) => {
|
|
38
|
+
if (isConnectionLost(error))
|
|
39
|
+
lost = true;
|
|
40
|
+
throw error;
|
|
41
|
+
});
|
|
42
|
+
let released = false;
|
|
43
|
+
return {
|
|
44
|
+
execute: (text, params, options) => guard(() => runCall(isClosed(), options, (watch) => session.query(text, params, watch))),
|
|
45
|
+
batch: (statements, options) => guard(() => runCall(isClosed(), options, async (watch) => {
|
|
46
|
+
const { runAtomicBatch } = await import("./b066g80h.js");
|
|
47
|
+
return runAtomicBatch(session, statements, watch);
|
|
48
|
+
})),
|
|
49
|
+
cancel() {
|
|
50
|
+
session.cancel();
|
|
51
|
+
},
|
|
52
|
+
async release() {
|
|
53
|
+
if (released)
|
|
54
|
+
return;
|
|
55
|
+
released = true;
|
|
56
|
+
try {
|
|
57
|
+
if (!lost)
|
|
58
|
+
await reset(session, client);
|
|
59
|
+
} finally {
|
|
60
|
+
counters.reserved = Math.max(0, counters.reserved - 1);
|
|
61
|
+
events.removeListener("error", onError);
|
|
62
|
+
client.release(lost);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
async function reset(session, client) {
|
|
68
|
+
const run = (text) => client.query(text);
|
|
69
|
+
if (session.depth() > 0)
|
|
70
|
+
await run("ROLLBACK").catch(() => {
|
|
71
|
+
return;
|
|
72
|
+
});
|
|
73
|
+
try {
|
|
74
|
+
await run(RESET_ALL);
|
|
75
|
+
await run(UNLOCK);
|
|
76
|
+
} catch {
|
|
77
|
+
await run("ROLLBACK").catch(() => {
|
|
78
|
+
return;
|
|
79
|
+
});
|
|
80
|
+
await run(RESET_ALL);
|
|
81
|
+
await run(UNLOCK);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export {
|
|
85
|
+
checkout
|
|
86
|
+
};
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
|
-
CATALOG_VERSION2,
|
|
3
2
|
assertNamespace2,
|
|
4
3
|
identityKey2,
|
|
5
4
|
identityLabel2,
|
|
6
5
|
normaliseEdges,
|
|
7
6
|
compareText,
|
|
8
7
|
assertProvenance
|
|
9
|
-
} from "./
|
|
8
|
+
} from "./t4tbsy9h.js";
|
|
9
|
+
import {
|
|
10
|
+
CATALOG_VERSION2
|
|
11
|
+
} from "./4e4c6vq2.js";
|
|
10
12
|
import {
|
|
11
13
|
assertIdentifier2,
|
|
12
14
|
assertStoredText
|
|
13
|
-
} from "./
|
|
15
|
+
} from "./nfzc5z0w.js";
|
|
14
16
|
import {
|
|
15
17
|
catalogError2
|
|
16
|
-
} from "./
|
|
18
|
+
} from "./52szzakm.js";
|
|
17
19
|
|
|
18
20
|
// src/contracts/catalog/order.ts
|
|
19
21
|
function indexObjects(objects) {
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import {
|
|
2
|
+
stack
|
|
3
|
+
} from "./672t5vym.js";
|
|
4
|
+
import {
|
|
5
|
+
checkPresetNames
|
|
6
|
+
} from "./nsva2a6b.js";
|
|
7
|
+
import {
|
|
8
|
+
isOperator,
|
|
9
|
+
operatorValue
|
|
10
|
+
} from "./cn0n68ft.js";
|
|
11
|
+
import {
|
|
12
|
+
OkmError2
|
|
13
|
+
} from "./52szzakm.js";
|
|
14
|
+
|
|
15
|
+
// src/runtime/presets.ts
|
|
16
|
+
function checkSchema(schema) {
|
|
17
|
+
for (const name in schema.model) {
|
|
18
|
+
const presets = schema.model[name]?.presets;
|
|
19
|
+
if (presets !== undefined)
|
|
20
|
+
checkPresetNames(Object.keys(presets), `table ${name}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function resolve(schema, table, uses) {
|
|
24
|
+
const model = schema.model[table];
|
|
25
|
+
const known = model?.presets ?? {};
|
|
26
|
+
const chain = [];
|
|
27
|
+
for (let use = uses;use !== undefined; use = use[0])
|
|
28
|
+
chain.unshift(use);
|
|
29
|
+
const wheres = [];
|
|
30
|
+
const rules = [];
|
|
31
|
+
for (const [, name, args] of chain) {
|
|
32
|
+
const preset = known[name];
|
|
33
|
+
if (typeof preset !== "function") {
|
|
34
|
+
throw new OkmError2("OKM1120", `Table ${table} has no preset ${name}.`, {
|
|
35
|
+
fix: { summary: `Use one of: ${Object.keys(known).join(", ")}.` }
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const added = [];
|
|
39
|
+
const q = {
|
|
40
|
+
where(filter) {
|
|
41
|
+
added.push(filter);
|
|
42
|
+
return q;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
if (preset(q, ...args) !== q) {
|
|
46
|
+
throw new OkmError2("OKM1121", `Preset ${name} on ${table} must return the builder it was given.`, { fix: { summary: "Return q, as in (q) => q.where({ ... })." } });
|
|
47
|
+
}
|
|
48
|
+
for (const filter of added)
|
|
49
|
+
wheres.push(filter);
|
|
50
|
+
rules.push({
|
|
51
|
+
rule: "preset",
|
|
52
|
+
contribution: `${name} filters ${[...new Set(added.flatMap(fieldsOf))].join(", ") || "nothing"}`,
|
|
53
|
+
provenance: ownerOf(model, name, table),
|
|
54
|
+
...model?.source !== undefined ? { source: model.source } : {}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return { wheres, rules };
|
|
58
|
+
}
|
|
59
|
+
function refine(schema, call, uses) {
|
|
60
|
+
const { wheres, rules } = resolve(schema, call.table, uses);
|
|
61
|
+
return {
|
|
62
|
+
...call,
|
|
63
|
+
where: stack(call.where, wheres),
|
|
64
|
+
ruleLines: [...call.ruleLines ?? [], ...rules]
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function ownerOf(model, name, table) {
|
|
68
|
+
for (const trait of model?.traits ?? []) {
|
|
69
|
+
const presets = trait.presets;
|
|
70
|
+
if (presets !== undefined && Object.hasOwn(presets, name))
|
|
71
|
+
return `trait ${trait.name}`;
|
|
72
|
+
}
|
|
73
|
+
return `table ${table}`;
|
|
74
|
+
}
|
|
75
|
+
function fieldsOf(filter) {
|
|
76
|
+
if (isOperator(filter)) {
|
|
77
|
+
const branches = operatorValue(filter);
|
|
78
|
+
return Array.isArray(branches) ? branches.flatMap(fieldsOf) : [];
|
|
79
|
+
}
|
|
80
|
+
return typeof filter === "object" && filter !== null ? Object.keys(filter) : [];
|
|
81
|
+
}
|
|
82
|
+
export {
|
|
83
|
+
checkSchema,
|
|
84
|
+
refine,
|
|
85
|
+
resolve
|
|
86
|
+
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
catalogHash2,
|
|
3
3
|
parseCatalog2
|
|
4
|
-
} from "./
|
|
4
|
+
} from "./d2whjz4k.js";
|
|
5
5
|
import {
|
|
6
6
|
parsePlan
|
|
7
|
-
} from "./
|
|
7
|
+
} from "./5z4q2zda.js";
|
|
8
8
|
import {
|
|
9
9
|
OkmError2
|
|
10
|
-
} from "./
|
|
10
|
+
} from "./52szzakm.js";
|
|
11
11
|
|
|
12
12
|
// src/tooling/migrate/files.ts
|
|
13
13
|
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// src/contracts/generator.ts
|
|
2
|
+
var CLIENT_DEFAULT = Symbol.for("okmodel.clientDefault");
|
|
3
|
+
function clientGenerator(call, name, options) {
|
|
4
|
+
const marked = call;
|
|
5
|
+
Object.defineProperty(marked, CLIENT_DEFAULT, {
|
|
6
|
+
value: options === undefined ? { label: "client", name } : { label: "client", name, options },
|
|
7
|
+
enumerable: false
|
|
8
|
+
});
|
|
9
|
+
return marked;
|
|
10
|
+
}
|
|
11
|
+
function readClientGenerator(value) {
|
|
12
|
+
if (typeof value !== "function")
|
|
13
|
+
return;
|
|
14
|
+
const mark = value[CLIENT_DEFAULT];
|
|
15
|
+
if (isMark(mark))
|
|
16
|
+
return { label: "client", name: mark.name, call: value };
|
|
17
|
+
return { label: "client", name: "function", call: value };
|
|
18
|
+
}
|
|
19
|
+
function isMark(value) {
|
|
20
|
+
if (typeof value !== "object" || value === null)
|
|
21
|
+
return false;
|
|
22
|
+
const name = value.name;
|
|
23
|
+
return value.label === "client" && typeof name === "string" && name !== "function";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { clientGenerator, readClientGenerator };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isConnectionSqlstate,
|
|
3
3
|
isConnectionFailure
|
|
4
|
-
} from "./
|
|
4
|
+
} from "./tbszx8mz.js";
|
|
5
5
|
import {
|
|
6
6
|
OkmError2,
|
|
7
7
|
stripRowValues,
|
|
8
8
|
matchingParen
|
|
9
|
-
} from "./
|
|
9
|
+
} from "./52szzakm.js";
|
|
10
10
|
|
|
11
11
|
// src/dialects/pg/errors.ts
|
|
12
12
|
function mapPostgresError(error, options) {
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {
|
|
2
|
+
required
|
|
3
|
+
} from "./dd4f8mnx.js";
|
|
4
|
+
import {
|
|
5
|
+
definition,
|
|
6
|
+
rejected
|
|
7
|
+
} from "./xatfg0gn.js";
|
|
8
|
+
|
|
9
|
+
// src/dialects/pg/text.ts
|
|
10
|
+
function text2() {
|
|
11
|
+
return required({ baseType: "text", encode: encodeText, decode: decodeText, sqlForm: "quote" });
|
|
12
|
+
}
|
|
13
|
+
function varchar2(length) {
|
|
14
|
+
const limit = boundedLength(length, "varchar");
|
|
15
|
+
return required({
|
|
16
|
+
baseType: `varchar(${String(limit)})`,
|
|
17
|
+
encode: (value) => encodeLimited(value, limit, "varchar"),
|
|
18
|
+
decode: decodeText,
|
|
19
|
+
sqlForm: "quote"
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function char2(length) {
|
|
23
|
+
const limit = boundedLength(length, "char");
|
|
24
|
+
return required({
|
|
25
|
+
baseType: `char(${String(limit)})`,
|
|
26
|
+
encode: (value) => encodeLimited(value, limit, "char"),
|
|
27
|
+
decode: decodeText,
|
|
28
|
+
sqlForm: "quote"
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function citext2() {
|
|
32
|
+
return required({
|
|
33
|
+
baseType: "citext",
|
|
34
|
+
encode: encodeText,
|
|
35
|
+
decode: decodeText,
|
|
36
|
+
sqlForm: "quote",
|
|
37
|
+
extension: "citext"
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function encodeText(value) {
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
function decodeText(wire) {
|
|
44
|
+
return wire;
|
|
45
|
+
}
|
|
46
|
+
function encodeLimited(value, limit, role) {
|
|
47
|
+
if (characterLength(value) > limit) {
|
|
48
|
+
rejected(`${role} accepts at most ${String(limit)} characters.`);
|
|
49
|
+
}
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
function boundedLength(length, role) {
|
|
53
|
+
if (!Number.isInteger(length) || length < 1 || length > 10485760) {
|
|
54
|
+
definition(`${role} length ${String(length)} must be an integer from 1 to 10485760.`);
|
|
55
|
+
}
|
|
56
|
+
return length;
|
|
57
|
+
}
|
|
58
|
+
function characterLength(value) {
|
|
59
|
+
let count = 0;
|
|
60
|
+
for (let index = 0;index < value.length; index += 1) {
|
|
61
|
+
const code = value.charCodeAt(index);
|
|
62
|
+
if (code >= 55296 && code <= 56319) {
|
|
63
|
+
index += 1;
|
|
64
|
+
}
|
|
65
|
+
count += 1;
|
|
66
|
+
}
|
|
67
|
+
return count;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export { text2, varchar2, char2, citext2, encodeText, decodeText };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
OkmError2
|
|
3
|
-
} from "./
|
|
3
|
+
} from "./52szzakm.js";
|
|
4
4
|
|
|
5
5
|
// src/runtime/drift.ts
|
|
6
6
|
async function assertCompatible(pool, schema, recordedHash, source, options) {
|
|
@@ -8,16 +8,16 @@ async function assertCompatible(pool, schema, recordedHash, source, options) {
|
|
|
8
8
|
if (code.hash === recordedHash)
|
|
9
9
|
return;
|
|
10
10
|
if (code.artifact !== undefined) {
|
|
11
|
-
const { loadTrustedCatalog } = await import("./
|
|
11
|
+
const { loadTrustedCatalog } = await import("./a1gdp7j9.js");
|
|
12
12
|
loadTrustedCatalog(code.artifact.text, code.artifact.hash);
|
|
13
13
|
} else {
|
|
14
14
|
const artifact = await readCatalogFile(source.catalogDir);
|
|
15
15
|
if (artifact !== undefined) {
|
|
16
|
-
const { loadTrustedCatalog } = await import("./
|
|
16
|
+
const { loadTrustedCatalog } = await import("./a1gdp7j9.js");
|
|
17
17
|
loadTrustedCatalog(artifact.text, artifact.hash);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
const { assertDrift } = await import("./
|
|
20
|
+
const { assertDrift } = await import("./zwmqxb0g.js");
|
|
21
21
|
await assertDrift(pool, code.hash, recordedHash, options);
|
|
22
22
|
}
|
|
23
23
|
async function codeHash(schema, source) {
|
|
@@ -26,7 +26,7 @@ async function codeHash(schema, source) {
|
|
|
26
26
|
const listed = await readHashFile(source.catalogDir);
|
|
27
27
|
if (listed !== undefined)
|
|
28
28
|
return { hash: listed };
|
|
29
|
-
const { catalogHash } = await import("./
|
|
29
|
+
const { catalogHash } = await import("./a1gdp7j9.js");
|
|
30
30
|
return { hash: catalogHash(schemaCatalog(schema)) };
|
|
31
31
|
}
|
|
32
32
|
function schemaCatalog(schema) {
|
|
@@ -1,73 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
referentialAction
|
|
3
|
+
} from "./4e4c6vq2.js";
|
|
1
4
|
import {
|
|
2
5
|
assertIdentifier2,
|
|
3
6
|
fitIdentifier2,
|
|
4
7
|
deterministicName2,
|
|
5
8
|
assertStoredText
|
|
6
|
-
} from "./
|
|
9
|
+
} from "./nfzc5z0w.js";
|
|
7
10
|
import {
|
|
8
11
|
catalogError2
|
|
9
|
-
} from "./
|
|
10
|
-
|
|
11
|
-
// src/contracts/catalog/types.ts
|
|
12
|
-
var OWNERS2 = ["managed", "external", "ignored"];
|
|
13
|
-
var OBJECT_KINDS2 = [
|
|
14
|
-
"table",
|
|
15
|
-
"column",
|
|
16
|
-
"index",
|
|
17
|
-
"constraint",
|
|
18
|
-
"sequence",
|
|
19
|
-
"view",
|
|
20
|
-
"materializedView",
|
|
21
|
-
"type",
|
|
22
|
-
"function",
|
|
23
|
-
"trigger",
|
|
24
|
-
"policy",
|
|
25
|
-
"extension",
|
|
26
|
-
"role",
|
|
27
|
-
"grant",
|
|
28
|
-
"defaultPrivilege"
|
|
29
|
-
];
|
|
30
|
-
var BUILT_KINDS2 = ["table", "column", "index", "constraint", "sequence", "type"];
|
|
31
|
-
var OBJECT_OPERATIONS2 = [
|
|
32
|
-
"create",
|
|
33
|
-
"replace",
|
|
34
|
-
"alter",
|
|
35
|
-
"drop",
|
|
36
|
-
"recreateWithDependents"
|
|
37
|
-
];
|
|
38
|
-
var KIND_OPERATIONS2 = {
|
|
39
|
-
table: ["create", "alter", "drop", "recreateWithDependents"],
|
|
40
|
-
column: ["create", "alter", "drop", "recreateWithDependents"],
|
|
41
|
-
index: ["create", "drop", "recreateWithDependents"],
|
|
42
|
-
constraint: ["create", "alter", "drop", "recreateWithDependents"],
|
|
43
|
-
sequence: ["create", "alter", "drop"],
|
|
44
|
-
view: ["create", "replace", "drop", "recreateWithDependents"],
|
|
45
|
-
materializedView: ["create", "drop", "recreateWithDependents"],
|
|
46
|
-
type: ["create", "alter", "drop"],
|
|
47
|
-
function: ["create", "replace", "drop", "recreateWithDependents"],
|
|
48
|
-
trigger: ["create", "drop", "recreateWithDependents"],
|
|
49
|
-
policy: ["create", "alter", "drop"],
|
|
50
|
-
extension: ["create", "alter", "drop"],
|
|
51
|
-
role: ["create", "alter"],
|
|
52
|
-
grant: ["create", "drop"],
|
|
53
|
-
defaultPrivilege: ["create", "alter", "drop"]
|
|
54
|
-
};
|
|
55
|
-
var REFERENTIAL_ACTIONS = [
|
|
56
|
-
"cascade",
|
|
57
|
-
"no action",
|
|
58
|
-
"restrict",
|
|
59
|
-
"set default",
|
|
60
|
-
"set null"
|
|
61
|
-
];
|
|
62
|
-
function referentialAction(value) {
|
|
63
|
-
for (const action of REFERENTIAL_ACTIONS) {
|
|
64
|
-
if (action === value) {
|
|
65
|
-
return action;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
var CATALOG_VERSION2 = 1;
|
|
12
|
+
} from "./52szzakm.js";
|
|
71
13
|
|
|
72
14
|
// src/contracts/catalog/json.ts
|
|
73
15
|
function canonicalJson(value) {
|
|
@@ -431,6 +373,12 @@ function column2(input) {
|
|
|
431
373
|
if (input.defaultExpression !== undefined) {
|
|
432
374
|
assertStoredText(input.defaultExpression, "column default");
|
|
433
375
|
}
|
|
376
|
+
if (input.collation !== undefined) {
|
|
377
|
+
assertStoredText(input.collation, "column collation");
|
|
378
|
+
if (input.collation.length === 0) {
|
|
379
|
+
catalogError2("OKM1020", `Column ${input.name} has an empty collation.`);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
434
382
|
if (input.generated !== undefined) {
|
|
435
383
|
assertStoredText(input.generated.expression, "column generated expression");
|
|
436
384
|
}
|
|
@@ -443,6 +391,7 @@ function column2(input) {
|
|
|
443
391
|
dataType: input.dataType,
|
|
444
392
|
nullable: input.nullable,
|
|
445
393
|
...input.defaultExpression !== undefined ? { defaultExpression: input.defaultExpression } : {},
|
|
394
|
+
...input.collation !== undefined ? { collation: input.collation } : {},
|
|
446
395
|
...input.identity !== undefined ? { identity: { always: input.identity.always } } : {},
|
|
447
396
|
...input.generated !== undefined ? {
|
|
448
397
|
generated: {
|
|
@@ -698,4 +647,4 @@ function copyPartition(partition) {
|
|
|
698
647
|
return { method: partition.method, columns: [...partition.columns] };
|
|
699
648
|
}
|
|
700
649
|
|
|
701
|
-
export {
|
|
650
|
+
export { canonicalJson, staticNamespace2, templateNamespace2, assertNamespace2, resolveNamespace2, identityKey2, identifierLimitApplies2, identityLabel2, sameRef2, sameNamespace2, identityToJson, namespaceToJson, table3, column2, index3, constraint2, sequence2, normaliseEdges, compareText, assertProvenance };
|
|
@@ -30,6 +30,20 @@ function isConnectionFailure(error) {
|
|
|
30
30
|
const message = error.message;
|
|
31
31
|
return message.includes("ECONNREFUSED") || message.includes("ECONNRESET") || message.includes("CONNECTION_CLOSED") || message.includes("terminating connection") || message.includes("The pool is closed");
|
|
32
32
|
}
|
|
33
|
+
function isConnectionLost(error) {
|
|
34
|
+
if (isConnectionFailure(error))
|
|
35
|
+
return true;
|
|
36
|
+
if (typeof error !== "object" || error === null)
|
|
37
|
+
return false;
|
|
38
|
+
if (Reflect.get(error, "kind") === "outcome_unknown")
|
|
39
|
+
return true;
|
|
40
|
+
if (readCode(error, "code") === "ERR_POSTGRES_CONNECTION_CLOSED")
|
|
41
|
+
return true;
|
|
42
|
+
if (error instanceof Error && error.message.includes("Connection terminated"))
|
|
43
|
+
return true;
|
|
44
|
+
const cause = Reflect.get(error, "cause");
|
|
45
|
+
return cause !== undefined && cause !== error && isConnectionLost(cause);
|
|
46
|
+
}
|
|
33
47
|
function readCode(error, key) {
|
|
34
48
|
if (typeof error !== "object" || error === null || !(key in error))
|
|
35
49
|
return;
|
|
@@ -37,4 +51,4 @@ function readCode(error, key) {
|
|
|
37
51
|
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
38
52
|
}
|
|
39
53
|
|
|
40
|
-
export { isConnectionSqlstate, isConnectionFailure };
|
|
54
|
+
export { isConnectionSqlstate, isConnectionFailure, isConnectionLost };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
runWrite
|
|
3
|
+
} from "./n4jqhpqz.js";
|
|
4
|
+
import {
|
|
5
|
+
withHttp,
|
|
6
|
+
settleCall
|
|
7
|
+
} from "./mxmcdsh5.js";
|
|
8
|
+
import {
|
|
9
|
+
rejectKeys,
|
|
10
|
+
isRecord,
|
|
11
|
+
fail
|
|
12
|
+
} from "./xrfnq5k8.js";
|
|
13
|
+
import {
|
|
14
|
+
OkmError2
|
|
15
|
+
} from "./52szzakm.js";
|
|
16
|
+
|
|
17
|
+
// src/runtime/batch.ts
|
|
18
|
+
async function batch(session, ops, options, replica) {
|
|
19
|
+
try {
|
|
20
|
+
if (replica !== undefined) {
|
|
21
|
+
throw new OkmError2("OKM1840", "batch() needs the primary. .replica() is not allowed on a batch.", withHttp(session.http, {
|
|
22
|
+
fix: { summary: "Remove .replica(). A batch always runs on the primary." }
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
if (!Array.isArray(ops))
|
|
26
|
+
fail("OKM1121", "batch expects a list of write operations.");
|
|
27
|
+
const record = options ?? {};
|
|
28
|
+
if (!isRecord(record))
|
|
29
|
+
fail("OKM1121", "batch options must be an object.");
|
|
30
|
+
rejectKeys(record, ["signal", "timeout"], "batch");
|
|
31
|
+
const prepared = [];
|
|
32
|
+
for (const op of ops) {
|
|
33
|
+
const plan = typeof op === "object" && op !== null ? op["~plan"] : undefined;
|
|
34
|
+
if (plan === undefined) {
|
|
35
|
+
fail("OKM1121", "batch takes write operations: insert, update, delete, and archive. Pass them without awaiting.");
|
|
36
|
+
}
|
|
37
|
+
const item = await plan();
|
|
38
|
+
if (item.checked !== undefined) {
|
|
39
|
+
fail("OKM1121", item.checked === "restore" ? "batch does not take restore: it is refused while its parent is archived, and a batch cannot report that after it commits. Use tx()." : "batch does not take a write with expect: the count is checked after the statement ran, and a batch cannot report that after it commits. Use tx().");
|
|
40
|
+
}
|
|
41
|
+
prepared.push(item);
|
|
42
|
+
}
|
|
43
|
+
return await run(session, prepared, record);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
return settleCall(session, error);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async function run(session, prepared, options) {
|
|
49
|
+
await session.connected;
|
|
50
|
+
const statements = [];
|
|
51
|
+
const starts = [];
|
|
52
|
+
for (const item of prepared) {
|
|
53
|
+
starts.push(statements.length);
|
|
54
|
+
statements.push(...item.statements);
|
|
55
|
+
}
|
|
56
|
+
if (statements.length === 0)
|
|
57
|
+
return prepared.map((item) => item.finish([]));
|
|
58
|
+
let results;
|
|
59
|
+
try {
|
|
60
|
+
results = await runWrite(session, statements, call(options), true);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
throw at(error, starts);
|
|
63
|
+
}
|
|
64
|
+
return prepared.map((item, index) => {
|
|
65
|
+
const from = starts[index] ?? 0;
|
|
66
|
+
return item.finish(results.slice(from, from + item.statements.length));
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function call(options) {
|
|
70
|
+
const { signal, timeout } = options;
|
|
71
|
+
if (signal === undefined && timeout === undefined)
|
|
72
|
+
return;
|
|
73
|
+
return {
|
|
74
|
+
...signal !== undefined ? { signal } : {},
|
|
75
|
+
...typeof timeout === "number" ? { timeout } : {}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function at(error, starts) {
|
|
79
|
+
const failed = error?.batchIndex;
|
|
80
|
+
const move = error?.at;
|
|
81
|
+
if (typeof failed !== "number" || typeof move !== "function")
|
|
82
|
+
return error;
|
|
83
|
+
let index = 0;
|
|
84
|
+
while (index + 1 < starts.length && (starts[index + 1] ?? Infinity) <= failed)
|
|
85
|
+
index += 1;
|
|
86
|
+
return index === failed ? error : move.call(error, index);
|
|
87
|
+
}
|
|
88
|
+
export {
|
|
89
|
+
batch
|
|
90
|
+
};
|