okmodel 0.1.1 → 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 +32 -16
- 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 +376 -27
- 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/{xqbhg6cn.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/{x5x59srr.js → 4jzzghr6.js} +416 -83
- package/dist/shared/{ycwz42az.js → 52szzakm.js} +6 -26
- package/dist/shared/{05w44d8g.js → 5z4q2zda.js} +567 -18
- 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/{523ft3e8.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/{kprcwaha.js → eaxwrgby.js} +4 -3
- package/dist/shared/{dkn3y60a.js → ecdzej21.js} +76 -112
- package/dist/shared/{hadrfb9h.js → edwqqryd.js} +17 -14
- package/dist/shared/{m3ypagh5.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/{yd1kzwn2.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/{jjb7yht9.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/{rgs0st28.js → xrfnq5k8.js} +237 -434
- 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 +41 -4
- package/dist/shared/gk7cs7sp.js +0 -566
|
@@ -1,773 +1,70 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
jsonReplacer2,
|
|
3
|
+
json2,
|
|
4
|
+
jsonb2
|
|
5
|
+
} from "../../shared/yw5c610b.js";
|
|
6
|
+
import {
|
|
7
|
+
encodeInstant,
|
|
8
|
+
decodeInstant,
|
|
9
|
+
encodeDate,
|
|
10
|
+
decodeDate,
|
|
11
|
+
timestamptz2,
|
|
12
|
+
timestamp2,
|
|
13
|
+
date2,
|
|
14
|
+
time2,
|
|
15
|
+
timetz2,
|
|
16
|
+
interval2
|
|
17
|
+
} from "../../shared/xkz8g6by.js";
|
|
18
|
+
import {
|
|
19
|
+
id2,
|
|
20
|
+
uuid2
|
|
21
|
+
} from "../../shared/ps43134h.js";
|
|
22
|
+
import {
|
|
23
|
+
one2,
|
|
24
|
+
many2,
|
|
25
|
+
manyThrough2,
|
|
26
|
+
schema2
|
|
27
|
+
} from "../../shared/7mht49yd.js";
|
|
28
|
+
import {
|
|
29
|
+
text2,
|
|
30
|
+
varchar2,
|
|
31
|
+
char2,
|
|
32
|
+
citext2,
|
|
33
|
+
encodeText,
|
|
34
|
+
decodeText
|
|
35
|
+
} from "../../shared/sacqha1y.js";
|
|
4
36
|
import {
|
|
5
|
-
definition,
|
|
6
|
-
unavailable,
|
|
7
|
-
rejected,
|
|
8
|
-
quoteLiteral,
|
|
9
|
-
ColumnBuilder2,
|
|
10
|
-
required,
|
|
11
|
-
openColumn,
|
|
12
|
-
formatType,
|
|
13
37
|
table2,
|
|
14
38
|
index2,
|
|
15
|
-
sql2
|
|
16
|
-
|
|
17
|
-
emittedTypeName,
|
|
18
|
-
rejectLater
|
|
19
|
-
} from "../../shared/gk7cs7sp.js";
|
|
20
|
-
import {
|
|
21
|
-
catalog,
|
|
22
|
-
enumType,
|
|
23
|
-
sameEnumLabels
|
|
24
|
-
} from "../../shared/g5fhqmwe.js";
|
|
39
|
+
sql2
|
|
40
|
+
} from "../../shared/x9v1qgeb.js";
|
|
25
41
|
import {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
constraint2,
|
|
31
|
-
sequence2,
|
|
32
|
-
compareText
|
|
33
|
-
} from "../../shared/j5cn2963.js";
|
|
42
|
+
ColumnBuilder2,
|
|
43
|
+
required,
|
|
44
|
+
openColumn
|
|
45
|
+
} from "../../shared/dd4f8mnx.js";
|
|
34
46
|
import {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
} from "../../shared/
|
|
47
|
+
definition,
|
|
48
|
+
unavailable,
|
|
49
|
+
rejected
|
|
50
|
+
} from "../../shared/xatfg0gn.js";
|
|
39
51
|
import {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
assertIdentifier2(state.typeDependency, "type");
|
|
55
|
-
dependencies.push({
|
|
56
|
-
kind: "type",
|
|
57
|
-
namespace: input.parent.namespace,
|
|
58
|
-
name: state.typeDependency
|
|
52
|
+
tag
|
|
53
|
+
} from "../../shared/cn0n68ft.js";
|
|
54
|
+
var __defProp = Object.defineProperty;
|
|
55
|
+
var __returnValue = (v) => v;
|
|
56
|
+
function __exportSetter(name, newValue) {
|
|
57
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
58
|
+
}
|
|
59
|
+
var __export = (target, all) => {
|
|
60
|
+
for (var name in all)
|
|
61
|
+
__defProp(target, name, {
|
|
62
|
+
get: all[name],
|
|
63
|
+
enumerable: true,
|
|
64
|
+
configurable: true,
|
|
65
|
+
set: __exportSetter.bind(all, name)
|
|
59
66
|
});
|
|
60
|
-
}
|
|
61
|
-
if (state.renamedFrom !== undefined) {
|
|
62
|
-
assertIdentifier2(state.renamedFrom, "renamed column");
|
|
63
|
-
}
|
|
64
|
-
if (state.comment !== undefined) {
|
|
65
|
-
assertStoredText(state.comment, "column comment");
|
|
66
|
-
}
|
|
67
|
-
if (state.picklist !== undefined) {
|
|
68
|
-
for (const value of state.picklist.values) {
|
|
69
|
-
assertStoredText(value, "picklist value");
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
const built = column2({
|
|
73
|
-
parent: input.parent,
|
|
74
|
-
name,
|
|
75
|
-
dataType: formatType(state.baseType, state.dims),
|
|
76
|
-
nullable: state.nullable,
|
|
77
|
-
provenance: input.provenance,
|
|
78
|
-
...input.owner !== undefined ? { owner: input.owner } : {},
|
|
79
|
-
...state.defaultSql !== undefined ? { defaultExpression: state.defaultSql } : {},
|
|
80
|
-
...state.identity !== undefined ? { identity: state.identity } : {},
|
|
81
|
-
...state.generated !== undefined ? { generated: state.generated } : {},
|
|
82
|
-
...dependencies.length > 0 || (input.dependencies?.length ?? 0) > 0 ? { dependencies: [...dependencies, ...input.dependencies ?? []] } : {}
|
|
83
|
-
});
|
|
84
|
-
const check = state.picklist !== undefined && state.picklist.check ? constraint2({
|
|
85
|
-
parent: input.parent,
|
|
86
|
-
constraintKind: "check",
|
|
87
|
-
columns: [name],
|
|
88
|
-
nameKey: name,
|
|
89
|
-
expression: picklistExpression(name, state.picklist.values),
|
|
90
|
-
provenance: input.provenance,
|
|
91
|
-
...input.owner !== undefined ? { owner: input.owner } : {}
|
|
92
|
-
}) : undefined;
|
|
93
|
-
const unique = state.unique !== undefined ? constraint2({
|
|
94
|
-
parent: input.parent,
|
|
95
|
-
constraintKind: "unique",
|
|
96
|
-
columns: [name],
|
|
97
|
-
nameKey: name,
|
|
98
|
-
provenance: input.provenance,
|
|
99
|
-
...input.owner !== undefined ? { owner: input.owner } : {}
|
|
100
|
-
}) : undefined;
|
|
101
|
-
return {
|
|
102
|
-
column: built,
|
|
103
|
-
guarded: state.guarded,
|
|
104
|
-
hidden: state.hidden,
|
|
105
|
-
...check !== undefined ? { check } : {},
|
|
106
|
-
...unique !== undefined ? { unique } : {},
|
|
107
|
-
...state.renamedFrom !== undefined ? { renamedFrom: state.renamedFrom } : {},
|
|
108
|
-
...state.comment !== undefined ? { comment: state.comment } : {},
|
|
109
|
-
...state.unique?.reason !== undefined ? { uniqueReason: state.unique.reason } : {},
|
|
110
|
-
...state.unique?.global !== undefined ? { uniqueGlobal: state.unique.global } : {},
|
|
111
|
-
...state.domain !== undefined ? { domain: state.domain } : {}
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
function picklistExpression(name, values) {
|
|
115
|
-
const list = values.map((value) => quoteLiteral(value)).join(", ");
|
|
116
|
-
return `(${name} IN (${list}))`;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// src/dialects/pg/relations.ts
|
|
120
|
-
function one(table, field) {
|
|
121
|
-
return { kind: "one", table, field };
|
|
122
|
-
}
|
|
123
|
-
function many(table, field) {
|
|
124
|
-
return { kind: "many", table, field };
|
|
125
|
-
}
|
|
126
|
-
function isRelationCall(value) {
|
|
127
|
-
if (typeof value !== "object" || value === null)
|
|
128
|
-
return false;
|
|
129
|
-
if (!("kind" in value) || !("table" in value))
|
|
130
|
-
return false;
|
|
131
|
-
const kind = value.kind;
|
|
132
|
-
return (kind === "one" || kind === "many") && typeof value.table === "string";
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// src/dialects/pg/text.ts
|
|
136
|
-
function text() {
|
|
137
|
-
return required({ baseType: "text", encode: encodeText, decode: decodeText, sqlForm: "quote" });
|
|
138
|
-
}
|
|
139
|
-
function varchar(length) {
|
|
140
|
-
const limit = boundedLength(length, "varchar");
|
|
141
|
-
return required({
|
|
142
|
-
baseType: `varchar(${String(limit)})`,
|
|
143
|
-
encode: (value) => encodeLimited(value, limit, "varchar"),
|
|
144
|
-
decode: decodeText,
|
|
145
|
-
sqlForm: "quote"
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
function char(length) {
|
|
149
|
-
const limit = boundedLength(length, "char");
|
|
150
|
-
return required({
|
|
151
|
-
baseType: `char(${String(limit)})`,
|
|
152
|
-
encode: (value) => encodeLimited(value, limit, "char"),
|
|
153
|
-
decode: decodeText,
|
|
154
|
-
sqlForm: "quote"
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
function citext() {
|
|
158
|
-
return required({
|
|
159
|
-
baseType: "citext",
|
|
160
|
-
encode: encodeText,
|
|
161
|
-
decode: decodeText,
|
|
162
|
-
sqlForm: "quote",
|
|
163
|
-
extension: "citext"
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
function encodeText(value) {
|
|
167
|
-
return value;
|
|
168
|
-
}
|
|
169
|
-
function decodeText(wire) {
|
|
170
|
-
return wire;
|
|
171
|
-
}
|
|
172
|
-
function encodeLimited(value, limit, role) {
|
|
173
|
-
if (characterLength(value) > limit) {
|
|
174
|
-
rejected(`${role} accepts at most ${String(limit)} characters.`);
|
|
175
|
-
}
|
|
176
|
-
return value;
|
|
177
|
-
}
|
|
178
|
-
function boundedLength(length, role) {
|
|
179
|
-
if (!Number.isInteger(length) || length < 1 || length > 10485760) {
|
|
180
|
-
definition(`${role} length ${String(length)} must be an integer from 1 to 10485760.`);
|
|
181
|
-
}
|
|
182
|
-
return length;
|
|
183
|
-
}
|
|
184
|
-
function characterLength(value) {
|
|
185
|
-
let count = 0;
|
|
186
|
-
for (let index = 0;index < value.length; index += 1) {
|
|
187
|
-
const code = value.charCodeAt(index);
|
|
188
|
-
if (code >= 55296 && code <= 56319) {
|
|
189
|
-
index += 1;
|
|
190
|
-
}
|
|
191
|
-
count += 1;
|
|
192
|
-
}
|
|
193
|
-
return count;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// src/dialects/pg/schema.ts
|
|
197
|
-
var SCHEMA_KNOWN = new Set(["casing", "codecs", "requires", "tables", "types"]);
|
|
198
|
-
var SCHEMA_LATER = {
|
|
199
|
-
extensions: "0.3",
|
|
200
|
-
functions: "0.3",
|
|
201
|
-
tenancy: "0.2",
|
|
202
|
-
traits: "0.2",
|
|
203
|
-
triggers: "0.3",
|
|
204
|
-
validation: "0.2",
|
|
205
|
-
views: "0.3"
|
|
206
67
|
};
|
|
207
|
-
var BIGINT_CODECS = new Set(["string", "number", "bigint"]);
|
|
208
|
-
var NUMERIC_CODECS = new Set(["string", "number"]);
|
|
209
|
-
function stage(jobs, build) {
|
|
210
|
-
jobs.push((objects) => {
|
|
211
|
-
objects.push(build());
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
function schema(config) {
|
|
215
|
-
rejectLater(config, SCHEMA_KNOWN, SCHEMA_LATER, "schema()");
|
|
216
|
-
if (!Array.isArray(config.tables)) {
|
|
217
|
-
definition("schema() needs a tables array.");
|
|
218
|
-
}
|
|
219
|
-
const types = readTypes(config.types);
|
|
220
|
-
const casing = readCasing(config.casing);
|
|
221
|
-
const codecs = readCodecs(config.codecs);
|
|
222
|
-
const requires = readRequires(config.requires);
|
|
223
|
-
const namespace = staticNamespace2("public");
|
|
224
|
-
const accepted = acceptTables(config.tables);
|
|
225
|
-
const jobs = [];
|
|
226
|
-
const prepared = [];
|
|
227
|
-
const sqlNames = new Set;
|
|
228
|
-
const enums = new Map;
|
|
229
|
-
for (const item of config.tables) {
|
|
230
|
-
const built = compileTable(item, namespace, casing, codecs, jobs, enums);
|
|
231
|
-
if (sqlNames.has(built.sqlName)) {
|
|
232
|
-
catalogError2("OKM1023", `Table ${built.tsName} uses SQL name ${built.sqlName}, which another table already uses. Accepted names: ${list(accepted)}.`);
|
|
233
|
-
}
|
|
234
|
-
sqlNames.add(built.sqlName);
|
|
235
|
-
prepared.push(built);
|
|
236
|
-
}
|
|
237
|
-
const byName = new Map;
|
|
238
|
-
for (const item of prepared) {
|
|
239
|
-
byName.set(item.tsName, item);
|
|
240
|
-
}
|
|
241
|
-
const edges = [];
|
|
242
|
-
for (const item of prepared) {
|
|
243
|
-
compileForeignKeys(item, byName, accepted, jobs, edges);
|
|
244
|
-
}
|
|
245
|
-
const model = {};
|
|
246
|
-
for (const item of prepared) {
|
|
247
|
-
model[item.tsName] = tableModel(item, edges, byName, accepted);
|
|
248
|
-
}
|
|
249
|
-
let document;
|
|
250
|
-
return {
|
|
251
|
-
get catalog() {
|
|
252
|
-
if (document === undefined) {
|
|
253
|
-
const objects = [];
|
|
254
|
-
for (const job of jobs)
|
|
255
|
-
job(objects);
|
|
256
|
-
for (const [name, note] of [...enums.entries()].sort((left, right) => compareText(left[0], right[0]))) {
|
|
257
|
-
objects.push(enumType({
|
|
258
|
-
namespace,
|
|
259
|
-
name,
|
|
260
|
-
labels: note.labels,
|
|
261
|
-
provenance: note.provenance
|
|
262
|
-
}));
|
|
263
|
-
}
|
|
264
|
-
document = catalog(objects);
|
|
265
|
-
}
|
|
266
|
-
return document;
|
|
267
|
-
},
|
|
268
|
-
types,
|
|
269
|
-
casing,
|
|
270
|
-
codecs,
|
|
271
|
-
requires,
|
|
272
|
-
tables: config.tables,
|
|
273
|
-
model
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
function acceptTables(tables) {
|
|
277
|
-
const names = [];
|
|
278
|
-
const seen = new Set;
|
|
279
|
-
const emitted = new Map;
|
|
280
|
-
for (const item of tables) {
|
|
281
|
-
if (typeof item.name !== "string" || item.name.length === 0) {
|
|
282
|
-
definition("schema() tables need a name.");
|
|
283
|
-
}
|
|
284
|
-
if (seen.has(item.name)) {
|
|
285
|
-
catalogError2("OKM1023", `Table ${item.name} is declared more than once. Accepted names: ${list([...names].sort())}.`);
|
|
286
|
-
}
|
|
287
|
-
seen.add(item.name);
|
|
288
|
-
names.push(item.name);
|
|
289
|
-
const typeName = emittedTypeName(item.name);
|
|
290
|
-
const previous = emitted.get(typeName);
|
|
291
|
-
if (previous !== undefined) {
|
|
292
|
-
catalogError2("OKM1023", `Table ${item.name} and ${previous} both emit ${typeName}. Accepted names: ${list([...names].sort())}.`);
|
|
293
|
-
}
|
|
294
|
-
emitted.set(typeName, item.name);
|
|
295
|
-
}
|
|
296
|
-
names.sort();
|
|
297
|
-
return names;
|
|
298
|
-
}
|
|
299
|
-
function noteEnum(notes, labels, name, table, provenance) {
|
|
300
|
-
const previous = notes.get(name);
|
|
301
|
-
if (previous !== undefined && !sameEnumLabels(previous.labels, labels)) {
|
|
302
|
-
catalogError2("OKM1020", `Enum ${name} lists ${previous.labels.join(", ")} on ${previous.table} and ${labels.join(", ")} on ${table}. One enum has one label list.`);
|
|
303
|
-
}
|
|
304
|
-
if (previous === undefined || compareText(table, previous.table) < 0) {
|
|
305
|
-
notes.set(name, { labels, table, provenance });
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
function compileTable(item, namespace, casing, codecs, jobs, enums) {
|
|
309
|
-
const options = item.options;
|
|
310
|
-
readTableNames(item.name, options);
|
|
311
|
-
const sqlName = options?.sqlName ?? (casing === "snake" ? snakeCase(item.name) : item.name);
|
|
312
|
-
assertIdentifier2(sqlName, `table ${item.name}`);
|
|
313
|
-
const provenance = { origin: "file", name: item.name };
|
|
314
|
-
const parent = { namespace, name: sqlName };
|
|
315
|
-
stage(jobs, () => table3({ namespace, name: sqlName, provenance }));
|
|
316
|
-
const columns = [];
|
|
317
|
-
const primary = [];
|
|
318
|
-
const byField = new Map;
|
|
319
|
-
const bySql = new Map;
|
|
320
|
-
const handles = {};
|
|
321
|
-
for (const [field, builder] of Object.entries(item.columns)) {
|
|
322
|
-
if (!(builder instanceof ColumnBuilder2)) {
|
|
323
|
-
definition(`Column ${item.name}.${field} must be a column builder.`);
|
|
324
|
-
}
|
|
325
|
-
const column = builder;
|
|
326
|
-
const columnSql = column.state.sqlName ?? (casing === "snake" ? snakeCase(field) : field);
|
|
327
|
-
assertCodec(item.name, field, column, codecs);
|
|
328
|
-
const identity = column.state.identity;
|
|
329
|
-
if (identity !== undefined) {
|
|
330
|
-
const seqName = fitIdentifier2(`${sqlName}_${columnSql}_seq`);
|
|
331
|
-
jobs.push((objects) => {
|
|
332
|
-
const seq = sequence2({
|
|
333
|
-
namespace,
|
|
334
|
-
name: seqName,
|
|
335
|
-
dataType: "bigint",
|
|
336
|
-
provenance,
|
|
337
|
-
dependencies: [{ kind: "table", namespace, name: sqlName }]
|
|
338
|
-
});
|
|
339
|
-
objects.push(seq);
|
|
340
|
-
pushCompiled(objects, column, {
|
|
341
|
-
parent,
|
|
342
|
-
name: columnSql,
|
|
343
|
-
provenance,
|
|
344
|
-
dependencies: [seq.identity]
|
|
345
|
-
});
|
|
346
|
-
});
|
|
347
|
-
} else {
|
|
348
|
-
jobs.push((objects) => {
|
|
349
|
-
pushCompiled(objects, column, { parent, name: columnSql, provenance });
|
|
350
|
-
});
|
|
351
|
-
}
|
|
352
|
-
const decode = column.state.decode;
|
|
353
|
-
const prepared = {
|
|
354
|
-
field,
|
|
355
|
-
sqlName: columnSql,
|
|
356
|
-
dataType: formatType(column.state.baseType, column.state.dims),
|
|
357
|
-
nullable: column.state.nullable,
|
|
358
|
-
references: column.state.references,
|
|
359
|
-
encode: column.state.encode,
|
|
360
|
-
decode: decode === decodeText ? undefined : decode,
|
|
361
|
-
hidden: column.state.hidden,
|
|
362
|
-
guarded: column.state.guarded,
|
|
363
|
-
writable: column.state.guarded !== true && column.state.omitWrite !== true && column.state.generated === undefined,
|
|
364
|
-
unique: column.state.unique !== undefined
|
|
365
|
-
};
|
|
366
|
-
columns.push(prepared);
|
|
367
|
-
byField.set(field, prepared);
|
|
368
|
-
bySql.set(prepared.sqlName, prepared);
|
|
369
|
-
handles[field] = { name: prepared.sqlName };
|
|
370
|
-
if (column.state.primaryKey) {
|
|
371
|
-
primary.push(prepared.sqlName);
|
|
372
|
-
}
|
|
373
|
-
const labels = column.state.enumLabels;
|
|
374
|
-
if (labels !== undefined) {
|
|
375
|
-
noteEnum(enums, labels, column.state.typeDependency ?? prepared.sqlName, sqlName, provenance);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
if (primary.length > 1) {
|
|
379
|
-
catalogError2("OKM1020", `Table ${item.name} has more than one primary key (${primary.join(", ")}). One primary key is accepted.`);
|
|
380
|
-
}
|
|
381
|
-
if (primary.length === 1) {
|
|
382
|
-
stage(jobs, () => constraint2({
|
|
383
|
-
parent,
|
|
384
|
-
constraintKind: "primaryKey",
|
|
385
|
-
columns: primary,
|
|
386
|
-
provenance
|
|
387
|
-
}));
|
|
388
|
-
}
|
|
389
|
-
if (options?.unique !== undefined) {
|
|
390
|
-
compileUniques(item.name, options, parent, provenance, byField, jobs);
|
|
391
|
-
}
|
|
392
|
-
if (options?.indexes !== undefined) {
|
|
393
|
-
compileIndexes(item.name, options, handles, parent, provenance, jobs);
|
|
394
|
-
}
|
|
395
|
-
if (options?.checks !== undefined) {
|
|
396
|
-
compileChecks(item.name, options, handles, parent, provenance, byField, jobs);
|
|
397
|
-
}
|
|
398
|
-
return {
|
|
399
|
-
tsName: item.name,
|
|
400
|
-
sqlName,
|
|
401
|
-
parent,
|
|
402
|
-
provenance,
|
|
403
|
-
columns,
|
|
404
|
-
primary,
|
|
405
|
-
uniques: uniqueTargets(primary, columns, bySql, options),
|
|
406
|
-
byField,
|
|
407
|
-
bySql,
|
|
408
|
-
relationOptions: relationInput(item.name, options)
|
|
409
|
-
};
|
|
410
|
-
}
|
|
411
|
-
function uniqueTargets(primary, columns, bySql, options) {
|
|
412
|
-
const uniques = [];
|
|
413
|
-
if (primary.length > 0) {
|
|
414
|
-
const fields = [];
|
|
415
|
-
for (const sqlName of primary) {
|
|
416
|
-
const column = bySql.get(sqlName);
|
|
417
|
-
if (column !== undefined)
|
|
418
|
-
fields.push(column.field);
|
|
419
|
-
}
|
|
420
|
-
if (fields.length > 0)
|
|
421
|
-
uniques.push(fields);
|
|
422
|
-
}
|
|
423
|
-
for (const column of columns) {
|
|
424
|
-
if (column.unique)
|
|
425
|
-
uniques.push([column.field]);
|
|
426
|
-
}
|
|
427
|
-
const named = options?.unique;
|
|
428
|
-
if (named !== undefined) {
|
|
429
|
-
for (const fields of Object.values(named))
|
|
430
|
-
uniques.push([...fields]);
|
|
431
|
-
}
|
|
432
|
-
return uniques;
|
|
433
|
-
}
|
|
434
|
-
function relationInput(tableName, options) {
|
|
435
|
-
const relations = options?.relations;
|
|
436
|
-
if (relations === undefined)
|
|
437
|
-
return;
|
|
438
|
-
if (typeof relations !== "object" || relations === null || Array.isArray(relations)) {
|
|
439
|
-
definition(`Table ${tableName} relations must be an object of one() and many() calls.`);
|
|
440
|
-
}
|
|
441
|
-
return relations;
|
|
442
|
-
}
|
|
443
|
-
function pushCompiled(objects, column, input) {
|
|
444
|
-
const compiled = compileColumn(column, input);
|
|
445
|
-
objects.push(compiled.column);
|
|
446
|
-
if (compiled.check !== undefined)
|
|
447
|
-
objects.push(compiled.check);
|
|
448
|
-
if (compiled.unique !== undefined)
|
|
449
|
-
objects.push(compiled.unique);
|
|
450
|
-
}
|
|
451
|
-
function compileUniques(tableName, options, parent, provenance, byField, jobs) {
|
|
452
|
-
const unique = options?.unique;
|
|
453
|
-
if (unique === undefined) {
|
|
454
|
-
return;
|
|
455
|
-
}
|
|
456
|
-
const accepted = [...byField.keys()].sort();
|
|
457
|
-
for (const [name, fields] of Object.entries(unique)) {
|
|
458
|
-
if (fields.length === 0) {
|
|
459
|
-
definition(`Unique ${tableName}.${name} needs a column.`);
|
|
460
|
-
}
|
|
461
|
-
const columns = [];
|
|
462
|
-
for (const field of fields) {
|
|
463
|
-
const column = byField.get(field);
|
|
464
|
-
if (column === undefined) {
|
|
465
|
-
throwNamed2("OKM1020", field, accepted, `Unique ${tableName}.${name} names ${field}, which is not a column of ${tableName}. Accepted names: ${list(accepted)}.`);
|
|
466
|
-
}
|
|
467
|
-
columns.push(column.sqlName);
|
|
468
|
-
}
|
|
469
|
-
stage(jobs, () => constraint2({
|
|
470
|
-
parent,
|
|
471
|
-
constraintKind: "unique",
|
|
472
|
-
columns,
|
|
473
|
-
nameKey: name,
|
|
474
|
-
provenance
|
|
475
|
-
}));
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
function compileIndexes(tableName, options, handles, parent, provenance, jobs) {
|
|
479
|
-
const build = options?.indexes;
|
|
480
|
-
if (build === undefined) {
|
|
481
|
-
return;
|
|
482
|
-
}
|
|
483
|
-
const calls = build(handles);
|
|
484
|
-
if (!Array.isArray(calls)) {
|
|
485
|
-
definition(`Table ${tableName} indexes must return an array.`);
|
|
486
|
-
}
|
|
487
|
-
for (const call of calls) {
|
|
488
|
-
const built = readIndex(tableName, call);
|
|
489
|
-
stage(jobs, () => index3({
|
|
490
|
-
parent,
|
|
491
|
-
columns: built.columns,
|
|
492
|
-
unique: built.isUnique === true,
|
|
493
|
-
nameKey: built.columns.join("_"),
|
|
494
|
-
provenance
|
|
495
|
-
}));
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
function compileChecks(tableName, options, handles, parent, provenance, byField, jobs) {
|
|
499
|
-
const checks = options?.checks;
|
|
500
|
-
if (checks === undefined) {
|
|
501
|
-
return;
|
|
502
|
-
}
|
|
503
|
-
for (const [name, build] of Object.entries(checks)) {
|
|
504
|
-
const used = [];
|
|
505
|
-
const value = build(track(handles, used));
|
|
506
|
-
const text = readCheck(tableName, name, value);
|
|
507
|
-
const columns = [];
|
|
508
|
-
for (const field of used) {
|
|
509
|
-
const column = byField.get(field);
|
|
510
|
-
if (column !== undefined) {
|
|
511
|
-
columns.push(column.sqlName);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
stage(jobs, () => constraint2({
|
|
515
|
-
parent,
|
|
516
|
-
constraintKind: "check",
|
|
517
|
-
columns,
|
|
518
|
-
nameKey: name,
|
|
519
|
-
expression: text,
|
|
520
|
-
provenance
|
|
521
|
-
}));
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
function compileForeignKeys(item, byName, accepted, jobs, edges) {
|
|
525
|
-
for (const column of item.columns) {
|
|
526
|
-
const reference = column.references;
|
|
527
|
-
if (reference === undefined) {
|
|
528
|
-
continue;
|
|
529
|
-
}
|
|
530
|
-
const target = byName.get(reference.table);
|
|
531
|
-
if (target === undefined) {
|
|
532
|
-
throwNamed2("OKM1020", reference.table, accepted, `Table ${reference.table} is not in the schema. Accepted names: ${list(accepted)}.`);
|
|
533
|
-
}
|
|
534
|
-
const targetColumns = resolveTarget(item, column, target, reference);
|
|
535
|
-
if (reference.onDelete === "set null" || reference.onUpdate === "set null") {
|
|
536
|
-
if (!column.nullable) {
|
|
537
|
-
definition(`Foreign key ${item.tsName}.${column.field} uses set null. ${item.tsName}.${column.field} must be nullable.`);
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
const localType = column.dataType;
|
|
541
|
-
const remote = targetColumns[0];
|
|
542
|
-
if (remote === undefined || targetColumns.length !== 1) {
|
|
543
|
-
const names = [...target.byField.keys()].sort();
|
|
544
|
-
catalogError2("OKM1021", `Foreign key ${item.tsName}.${column.field} on ${target.tsName} is ambiguous. Accepted columns: ${list(names)}.`);
|
|
545
|
-
}
|
|
546
|
-
if (localType !== remote.dataType) {
|
|
547
|
-
catalogError2("OKM1022", `Foreign key ${item.tsName}.${column.field} is ${localType} and ${target.tsName}.${remote.field} is ${remote.dataType}. Accepted type: ${remote.dataType}.`);
|
|
548
|
-
}
|
|
549
|
-
stage(jobs, () => constraint2({
|
|
550
|
-
parent: item.parent,
|
|
551
|
-
constraintKind: "foreignKey",
|
|
552
|
-
columns: [column.sqlName],
|
|
553
|
-
nameKey: column.sqlName,
|
|
554
|
-
provenance: item.provenance,
|
|
555
|
-
references: {
|
|
556
|
-
parent: target.parent,
|
|
557
|
-
columns: [remote.sqlName],
|
|
558
|
-
...reference.onDelete !== undefined ? { onDelete: reference.onDelete } : {},
|
|
559
|
-
...reference.onUpdate !== undefined ? { onUpdate: reference.onUpdate } : {}
|
|
560
|
-
}
|
|
561
|
-
}));
|
|
562
|
-
edges.push({
|
|
563
|
-
fromTable: item.tsName,
|
|
564
|
-
fromField: column.field,
|
|
565
|
-
fromSql: column.sqlName,
|
|
566
|
-
toTable: target.tsName,
|
|
567
|
-
toSql: remote.sqlName
|
|
568
|
-
});
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
function resolveTarget(item, column, target, reference) {
|
|
572
|
-
const accepted = [...target.byField.keys()].sort();
|
|
573
|
-
const named = reference.columns;
|
|
574
|
-
if (named !== undefined) {
|
|
575
|
-
const found = [];
|
|
576
|
-
for (const name of named) {
|
|
577
|
-
const match = target.byField.get(name) ?? target.bySql.get(name);
|
|
578
|
-
if (match === undefined) {
|
|
579
|
-
throwNamed2("OKM1021", name, accepted, `Foreign key ${item.tsName}.${column.field} references ${name} on ${target.tsName}, which is not a column. Accepted columns: ${list(accepted)}.`);
|
|
580
|
-
}
|
|
581
|
-
found.push(match);
|
|
582
|
-
}
|
|
583
|
-
if (found.length !== 1) {
|
|
584
|
-
catalogError2("OKM1021", `Foreign key ${item.tsName}.${column.field} on ${target.tsName} is ambiguous. Accepted columns: ${list(accepted)}.`);
|
|
585
|
-
}
|
|
586
|
-
return found;
|
|
587
|
-
}
|
|
588
|
-
if (target.primary.length === 0) {
|
|
589
|
-
catalogError2("OKM1021", `Foreign key ${item.tsName}.${column.field} on ${target.tsName} has no primary key. Accepted columns: ${list(accepted)}.`);
|
|
590
|
-
}
|
|
591
|
-
if (target.primary.length !== 1) {
|
|
592
|
-
catalogError2("OKM1021", `Foreign key ${item.tsName}.${column.field} on ${target.tsName} is ambiguous. Accepted columns: ${list(target.primary)}.`);
|
|
593
|
-
}
|
|
594
|
-
const sqlName = target.primary[0] ?? "";
|
|
595
|
-
const match = target.bySql.get(sqlName);
|
|
596
|
-
if (match === undefined) {
|
|
597
|
-
catalogError2("OKM1021", `Foreign key ${item.tsName}.${column.field} on ${target.tsName} is missing its target. Accepted columns: ${list(accepted)}.`);
|
|
598
|
-
}
|
|
599
|
-
return [match];
|
|
600
|
-
}
|
|
601
|
-
function assertCodec(tableName, field, builder, codecs) {
|
|
602
|
-
const base = builder.state.baseType;
|
|
603
|
-
if (base === "bigint" && codecs.bigint !== "string") {
|
|
604
|
-
const label = builder.state.typeLabel ?? "string";
|
|
605
|
-
if (label !== codecs.bigint) {
|
|
606
|
-
definition(`Schema codecs.bigint is ${codecs.bigint}, and ${tableName}.${field} was built as ${label}. Set as: "${codecs.bigint}" on that column.`);
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
if (base.startsWith("numeric") && codecs.numeric !== "string") {
|
|
610
|
-
const label = builder.state.typeLabel ?? "string";
|
|
611
|
-
if (label !== codecs.numeric) {
|
|
612
|
-
definition(`Schema codecs.numeric is ${codecs.numeric}, and ${tableName}.${field} was built as ${label}. Set as: "${codecs.numeric}" on that column.`);
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
function readTableNames(tableName, options) {
|
|
617
|
-
if (options?.sqlName !== undefined) {
|
|
618
|
-
if (options.sqlName.length === 0) {
|
|
619
|
-
definition(`Table ${tableName} sqlName must be a non-empty SQL identifier.`);
|
|
620
|
-
}
|
|
621
|
-
assertIdentifier2(options.sqlName, `table ${tableName} sqlName`);
|
|
622
|
-
}
|
|
623
|
-
if (options?.renamedFrom !== undefined) {
|
|
624
|
-
if (options.renamedFrom.length === 0) {
|
|
625
|
-
definition(`Table ${tableName} renamedFrom must be a non-empty previous name.`);
|
|
626
|
-
}
|
|
627
|
-
assertIdentifier2(options.renamedFrom, `table ${tableName} renamedFrom`);
|
|
628
|
-
}
|
|
629
|
-
if (options?.comment !== undefined) {
|
|
630
|
-
assertStoredText(options.comment, `table ${tableName} comment`);
|
|
631
|
-
if (options.comment.length === 0) {
|
|
632
|
-
definition(`Table ${tableName} comment must be non-empty.`);
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
function readTypes(types) {
|
|
637
|
-
if (types === undefined) {
|
|
638
|
-
return "emitted";
|
|
639
|
-
}
|
|
640
|
-
if (types !== "emitted" && types !== "inferred") {
|
|
641
|
-
definition(`schema() types ${String(types)} must be emitted or inferred.`);
|
|
642
|
-
}
|
|
643
|
-
return types;
|
|
644
|
-
}
|
|
645
|
-
function readCasing(casing) {
|
|
646
|
-
if (casing === undefined) {
|
|
647
|
-
return;
|
|
648
|
-
}
|
|
649
|
-
if (casing !== "snake") {
|
|
650
|
-
definition(`schema() casing ${String(casing)} must be snake.`);
|
|
651
|
-
}
|
|
652
|
-
return casing;
|
|
653
|
-
}
|
|
654
|
-
function readCodecs(codecs) {
|
|
655
|
-
const bigint = codecs?.bigint ?? "string";
|
|
656
|
-
const numeric = codecs?.numeric ?? "string";
|
|
657
|
-
const timestamps = codecs?.timestamps ?? "temporal";
|
|
658
|
-
if (!BIGINT_CODECS.has(bigint)) {
|
|
659
|
-
definition(`schema() codecs.bigint ${String(bigint)} must be string, number, or bigint.`);
|
|
660
|
-
}
|
|
661
|
-
if (!NUMERIC_CODECS.has(numeric)) {
|
|
662
|
-
definition(`schema() codecs.numeric ${String(numeric)} must be string or number.`);
|
|
663
|
-
}
|
|
664
|
-
if (timestamps !== "temporal") {
|
|
665
|
-
definition(`schema() codecs.timestamps ${String(timestamps)} must be temporal.`);
|
|
666
|
-
}
|
|
667
|
-
return { bigint, numeric, timestamps };
|
|
668
|
-
}
|
|
669
|
-
function tableModel(item, edges, byName, accepted) {
|
|
670
|
-
const columns = item.columns.map((column) => ({
|
|
671
|
-
field: column.field,
|
|
672
|
-
sql: column.sqlName,
|
|
673
|
-
dataType: column.dataType,
|
|
674
|
-
encode: column.encode,
|
|
675
|
-
decode: column.decode,
|
|
676
|
-
hidden: column.hidden,
|
|
677
|
-
guarded: column.guarded,
|
|
678
|
-
writable: column.writable
|
|
679
|
-
}));
|
|
680
|
-
const primary = [];
|
|
681
|
-
for (const sqlName of item.primary) {
|
|
682
|
-
const column = item.bySql.get(sqlName);
|
|
683
|
-
if (column !== undefined)
|
|
684
|
-
primary.push(column.field);
|
|
685
|
-
}
|
|
686
|
-
return {
|
|
687
|
-
name: item.tsName,
|
|
688
|
-
sql: item.sqlName,
|
|
689
|
-
primary,
|
|
690
|
-
uniques: item.uniques,
|
|
691
|
-
columns,
|
|
692
|
-
relations: resolveRelations(item, edges, byName, accepted)
|
|
693
|
-
};
|
|
694
|
-
}
|
|
695
|
-
function resolveRelations(item, edges, byName, accepted) {
|
|
696
|
-
const raw = item.relationOptions;
|
|
697
|
-
if (raw === undefined)
|
|
698
|
-
return [];
|
|
699
|
-
const record = raw;
|
|
700
|
-
const names = Object.keys(record);
|
|
701
|
-
const resolved = [];
|
|
702
|
-
const seen = new Set;
|
|
703
|
-
for (const name of names) {
|
|
704
|
-
if (seen.has(name))
|
|
705
|
-
continue;
|
|
706
|
-
seen.add(name);
|
|
707
|
-
const call = record[name];
|
|
708
|
-
if (!isRelationCall(call)) {
|
|
709
|
-
unavailable(`Table ${item.tsName} relation ${name} is not available yet. one() and many() are accepted. manyThrough arrives in 0.2. morph arrives later.`);
|
|
710
|
-
}
|
|
711
|
-
if (!byName.has(call.table)) {
|
|
712
|
-
throwNamed2("OKM1020", call.table, accepted, `Relation ${item.tsName}.${name} names ${call.table}, which is not in the schema. Accepted names: ${list(accepted)}.`);
|
|
713
|
-
}
|
|
714
|
-
const field = call.field;
|
|
715
|
-
const matches = call.kind === "one" ? edges.filter((edge) => edge.fromTable === item.tsName && edge.toTable === call.table && (field === undefined || edge.fromField === field)) : edges.filter((edge) => edge.toTable === item.tsName && edge.fromTable === call.table && (field === undefined || edge.fromField === field));
|
|
716
|
-
if (matches.length !== 1) {
|
|
717
|
-
const hint = matches.map((edge) => edge.fromField).sort();
|
|
718
|
-
const which = hint.length === 0 ? "none" : hint.join(", ");
|
|
719
|
-
catalogError2("OKM1021", `Relation ${item.tsName}.${name} on ${call.table} is ambiguous. Accepted columns: ${which}.`);
|
|
720
|
-
}
|
|
721
|
-
const edge = matches[0];
|
|
722
|
-
if (edge === undefined) {
|
|
723
|
-
catalogError2("OKM1021", `Relation ${item.tsName}.${name} on ${call.table} is ambiguous. Accepted columns: (none).`);
|
|
724
|
-
}
|
|
725
|
-
resolved.push(call.kind === "one" ? { name, kind: "one", table: call.table, local: [edge.fromSql], remote: [edge.toSql] } : { name, kind: "many", table: call.table, local: [edge.toSql], remote: [edge.fromSql] });
|
|
726
|
-
}
|
|
727
|
-
return resolved;
|
|
728
|
-
}
|
|
729
|
-
function readRequires(requires) {
|
|
730
|
-
if (requires === undefined) {
|
|
731
|
-
return;
|
|
732
|
-
}
|
|
733
|
-
const postgres = requires.postgres;
|
|
734
|
-
if (postgres !== undefined && postgres.length === 0) {
|
|
735
|
-
definition("schema() requires.postgres must be a version range such as >=17.");
|
|
736
|
-
}
|
|
737
|
-
return postgres === undefined ? {} : { postgres };
|
|
738
|
-
}
|
|
739
|
-
function readIndex(tableName, call) {
|
|
740
|
-
if (call.columns.length === 0) {
|
|
741
|
-
definition(`Index on ${tableName} needs a column.`);
|
|
742
|
-
}
|
|
743
|
-
for (const name of call.columns) {
|
|
744
|
-
if (typeof name !== "string" || name.length === 0) {
|
|
745
|
-
definition(`Index on ${tableName} must be built from column handles.`);
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
return call;
|
|
749
|
-
}
|
|
750
|
-
function readCheck(tableName, name, value) {
|
|
751
|
-
if (value === undefined || typeof value.text !== "string" || value.text.length === 0) {
|
|
752
|
-
definition(`Check ${tableName}.${name} must return sql text.`);
|
|
753
|
-
}
|
|
754
|
-
assertStoredText(value.text, `check ${tableName}.${name}`);
|
|
755
|
-
return value.text;
|
|
756
|
-
}
|
|
757
|
-
function track(handles, used) {
|
|
758
|
-
return new Proxy(handles, {
|
|
759
|
-
get(target, key) {
|
|
760
|
-
if (typeof key === "string" && Object.hasOwn(target, key)) {
|
|
761
|
-
used.push(key);
|
|
762
|
-
return target[key];
|
|
763
|
-
}
|
|
764
|
-
return;
|
|
765
|
-
}
|
|
766
|
-
});
|
|
767
|
-
}
|
|
768
|
-
function list(names) {
|
|
769
|
-
return names.length === 0 ? "(none)" : names.join(", ");
|
|
770
|
-
}
|
|
771
68
|
// src/dialects/pg/custom.ts
|
|
772
69
|
function custom(spec) {
|
|
773
70
|
if (spec.sqlType.length === 0) {
|
|
@@ -777,6 +74,7 @@ function custom(spec) {
|
|
|
777
74
|
baseType: spec.sqlType,
|
|
778
75
|
encode: spec.encode,
|
|
779
76
|
decode: spec.decode,
|
|
77
|
+
...spec.accepts !== undefined ? { accepts: spec.accepts } : {},
|
|
780
78
|
sqlForm: spec.sqlForm ?? "quote",
|
|
781
79
|
...spec.extension !== undefined ? { extension: spec.extension } : {}
|
|
782
80
|
});
|
|
@@ -1024,6 +322,7 @@ function bytea() {
|
|
|
1024
322
|
baseType: "bytea",
|
|
1025
323
|
encode: encodeBytea,
|
|
1026
324
|
decode: decodeBytea,
|
|
325
|
+
accepts: ["Uint8Array"],
|
|
1027
326
|
sqlForm: "quote"
|
|
1028
327
|
});
|
|
1029
328
|
}
|
|
@@ -1066,276 +365,6 @@ function hexText() {
|
|
|
1066
365
|
return hexPattern;
|
|
1067
366
|
}
|
|
1068
367
|
var hexPattern;
|
|
1069
|
-
// src/dialects/pg/json.ts
|
|
1070
|
-
function jsonReplacer(_key, value) {
|
|
1071
|
-
if (typeof value === "bigint") {
|
|
1072
|
-
return value.toString();
|
|
1073
|
-
}
|
|
1074
|
-
return value;
|
|
1075
|
-
}
|
|
1076
|
-
function json() {
|
|
1077
|
-
return required({
|
|
1078
|
-
baseType: "json",
|
|
1079
|
-
encode: encodeJson,
|
|
1080
|
-
decode: decodeJson,
|
|
1081
|
-
sqlForm: "json"
|
|
1082
|
-
});
|
|
1083
|
-
}
|
|
1084
|
-
function jsonb() {
|
|
1085
|
-
return required({
|
|
1086
|
-
baseType: "jsonb",
|
|
1087
|
-
encode: encodeJson,
|
|
1088
|
-
decode: decodeJson,
|
|
1089
|
-
sqlForm: "jsonb"
|
|
1090
|
-
});
|
|
1091
|
-
}
|
|
1092
|
-
function encodeJson(value) {
|
|
1093
|
-
const text = JSON.stringify(value, jsonReplacer);
|
|
1094
|
-
if (text === undefined) {
|
|
1095
|
-
rejected("json value must be JSON data. undefined and functions are not accepted. bigint is written as a decimal string.");
|
|
1096
|
-
}
|
|
1097
|
-
return text;
|
|
1098
|
-
}
|
|
1099
|
-
function decodeJson(wire) {
|
|
1100
|
-
try {
|
|
1101
|
-
return JSON.parse(wire);
|
|
1102
|
-
} catch {
|
|
1103
|
-
rejected("json text must be JSON, for example null, a string, a number, true, {}, or [].");
|
|
1104
|
-
}
|
|
1105
|
-
}
|
|
1106
|
-
// src/dialects/pg/keys.ts
|
|
1107
|
-
function id() {
|
|
1108
|
-
return openColumn({
|
|
1109
|
-
baseType: "uuid",
|
|
1110
|
-
nullable: false,
|
|
1111
|
-
hasDefault: true,
|
|
1112
|
-
generated: false,
|
|
1113
|
-
guarded: true,
|
|
1114
|
-
hidden: false,
|
|
1115
|
-
omitWrite: true,
|
|
1116
|
-
defaultSql: "uuidv7()",
|
|
1117
|
-
primaryKey: true,
|
|
1118
|
-
encode: encodeUuid,
|
|
1119
|
-
decode: decodeUuid,
|
|
1120
|
-
sqlForm: "quote"
|
|
1121
|
-
});
|
|
1122
|
-
}
|
|
1123
|
-
function uuid() {
|
|
1124
|
-
return required({
|
|
1125
|
-
baseType: "uuid",
|
|
1126
|
-
encode: encodeUuid,
|
|
1127
|
-
decode: decodeUuid,
|
|
1128
|
-
sqlForm: "quote"
|
|
1129
|
-
});
|
|
1130
|
-
}
|
|
1131
|
-
function encodeUuid(value) {
|
|
1132
|
-
const text = value.toLowerCase();
|
|
1133
|
-
if (!uuidText().test(text)) {
|
|
1134
|
-
rejected(`uuid ${value} must be 8-4-4-4-12 hexadecimal digits, for example 01890c5a-8f0e-7c3a-9b2d-6e4f1a0b9c8d.`);
|
|
1135
|
-
}
|
|
1136
|
-
return text;
|
|
1137
|
-
}
|
|
1138
|
-
function decodeUuid(wire) {
|
|
1139
|
-
return encodeUuid(wire);
|
|
1140
|
-
}
|
|
1141
|
-
function uuidText() {
|
|
1142
|
-
uuidPattern ??= /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
1143
|
-
return uuidPattern;
|
|
1144
|
-
}
|
|
1145
|
-
var uuidPattern;
|
|
1146
|
-
// src/dialects/pg/temporal.ts
|
|
1147
|
-
var TEMPORAL_MISSING = "Date and time codecs need the Temporal global. okmodel does not ship a polyfill. Use a runtime that provides Temporal, or assign a polyfill to globalThis.Temporal before using these columns.";
|
|
1148
|
-
function requireTemporal() {
|
|
1149
|
-
const temporal = globalThis.Temporal;
|
|
1150
|
-
if (typeof temporal !== "object" || temporal === null || !("Instant" in temporal)) {
|
|
1151
|
-
rejected(TEMPORAL_MISSING);
|
|
1152
|
-
}
|
|
1153
|
-
}
|
|
1154
|
-
function timePrecision(precision, role) {
|
|
1155
|
-
if (precision === undefined) {
|
|
1156
|
-
return;
|
|
1157
|
-
}
|
|
1158
|
-
if (!Number.isInteger(precision) || precision < 0 || precision > 6) {
|
|
1159
|
-
definition(`${role} precision ${String(precision)} must be an integer from 0 to 6.`);
|
|
1160
|
-
}
|
|
1161
|
-
return precision;
|
|
1162
|
-
}
|
|
1163
|
-
function encodeInstant(value, precision) {
|
|
1164
|
-
requireTemporal();
|
|
1165
|
-
if (precision === undefined) {
|
|
1166
|
-
return value.toString();
|
|
1167
|
-
}
|
|
1168
|
-
return value.toString({ fractionalSecondDigits: precision });
|
|
1169
|
-
}
|
|
1170
|
-
function decodeInstant(wire) {
|
|
1171
|
-
requireTemporal();
|
|
1172
|
-
try {
|
|
1173
|
-
return Temporal.Instant.from(wire);
|
|
1174
|
-
} catch {
|
|
1175
|
-
rejected(`timestamptz ${wire} must be an ISO-8601 instant, for example 2020-01-01T00:00:00Z.`);
|
|
1176
|
-
}
|
|
1177
|
-
}
|
|
1178
|
-
function encodeDateTime(value, precision) {
|
|
1179
|
-
requireTemporal();
|
|
1180
|
-
if (precision === undefined) {
|
|
1181
|
-
return value.toString();
|
|
1182
|
-
}
|
|
1183
|
-
return value.toString({ fractionalSecondDigits: precision });
|
|
1184
|
-
}
|
|
1185
|
-
function decodeDateTime(wire) {
|
|
1186
|
-
requireTemporal();
|
|
1187
|
-
try {
|
|
1188
|
-
return Temporal.PlainDateTime.from(wire);
|
|
1189
|
-
} catch {
|
|
1190
|
-
rejected(`timestamp ${wire} must be an ISO-8601 date-time without a zone, for example 2020-01-01T00:00:00.`);
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
function encodeDate(value) {
|
|
1194
|
-
requireTemporal();
|
|
1195
|
-
return value.toString();
|
|
1196
|
-
}
|
|
1197
|
-
function decodeDate(wire) {
|
|
1198
|
-
requireTemporal();
|
|
1199
|
-
try {
|
|
1200
|
-
return Temporal.PlainDate.from(wire);
|
|
1201
|
-
} catch {
|
|
1202
|
-
rejected(`date ${wire} must be YYYY-MM-DD.`);
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
function encodeTime(value, precision) {
|
|
1206
|
-
requireTemporal();
|
|
1207
|
-
if (precision === undefined) {
|
|
1208
|
-
return value.toString();
|
|
1209
|
-
}
|
|
1210
|
-
return value.toString({ fractionalSecondDigits: precision });
|
|
1211
|
-
}
|
|
1212
|
-
function decodeTime(wire) {
|
|
1213
|
-
requireTemporal();
|
|
1214
|
-
try {
|
|
1215
|
-
return Temporal.PlainTime.from(wire);
|
|
1216
|
-
} catch {
|
|
1217
|
-
rejected(`time ${wire} must be a time of day, for example 00:00:00.`);
|
|
1218
|
-
}
|
|
1219
|
-
}
|
|
1220
|
-
function encodeTimeZone(value, precision) {
|
|
1221
|
-
requireTemporal();
|
|
1222
|
-
if (!offsetText().test(value.offset)) {
|
|
1223
|
-
rejected(`timetz offset ${value.offset} must be ±HH:MM.`);
|
|
1224
|
-
}
|
|
1225
|
-
return `${encodeTime(value.time, precision)}${value.offset}`;
|
|
1226
|
-
}
|
|
1227
|
-
function decodeTimeZone(wire) {
|
|
1228
|
-
const match = timeZoneText().exec(wire);
|
|
1229
|
-
const time = match?.[1];
|
|
1230
|
-
const offset = match?.[2];
|
|
1231
|
-
if (time === undefined || offset === undefined) {
|
|
1232
|
-
rejected(`timetz ${wire} must be a time of day plus ±HH:MM, for example 00:00:00+00:00.`);
|
|
1233
|
-
}
|
|
1234
|
-
return { time: decodeTime(time), offset };
|
|
1235
|
-
}
|
|
1236
|
-
function encodeDuration(value) {
|
|
1237
|
-
requireTemporal();
|
|
1238
|
-
return value.toString();
|
|
1239
|
-
}
|
|
1240
|
-
function decodeDuration(wire) {
|
|
1241
|
-
requireTemporal();
|
|
1242
|
-
try {
|
|
1243
|
-
return Temporal.Duration.from(wire);
|
|
1244
|
-
} catch {
|
|
1245
|
-
rejected(`interval ${wire} must be an ISO-8601 duration, for example PT1H.`);
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
function intervalFields(fields) {
|
|
1249
|
-
switch (fields) {
|
|
1250
|
-
case "year":
|
|
1251
|
-
case "month":
|
|
1252
|
-
case "day":
|
|
1253
|
-
case "hour":
|
|
1254
|
-
case "minute":
|
|
1255
|
-
case "second":
|
|
1256
|
-
case "year to month":
|
|
1257
|
-
case "day to hour":
|
|
1258
|
-
case "day to minute":
|
|
1259
|
-
case "day to second":
|
|
1260
|
-
case "hour to minute":
|
|
1261
|
-
case "hour to second":
|
|
1262
|
-
case "minute to second":
|
|
1263
|
-
return fields;
|
|
1264
|
-
default:
|
|
1265
|
-
definition(`interval fields ${fields} must be one of: year, month, day, hour, minute, second, year to month, day to hour, day to minute, day to second, hour to minute, hour to second, minute to second.`);
|
|
1266
|
-
}
|
|
1267
|
-
}
|
|
1268
|
-
function offsetText() {
|
|
1269
|
-
offsetPattern ??= /^[+-]\d{2}:\d{2}$/;
|
|
1270
|
-
return offsetPattern;
|
|
1271
|
-
}
|
|
1272
|
-
function timeZoneText() {
|
|
1273
|
-
timeZonePattern ??= /^(.+)([+-]\d{2}:\d{2})$/;
|
|
1274
|
-
return timeZonePattern;
|
|
1275
|
-
}
|
|
1276
|
-
var offsetPattern;
|
|
1277
|
-
var timeZonePattern;
|
|
1278
|
-
|
|
1279
|
-
// src/dialects/pg/time.ts
|
|
1280
|
-
function timestamptz(precision) {
|
|
1281
|
-
const digits = timePrecision(precision, "timestamptz");
|
|
1282
|
-
return required({
|
|
1283
|
-
baseType: timed("timestamptz", digits),
|
|
1284
|
-
encode: (value) => encodeInstant(value, digits),
|
|
1285
|
-
decode: decodeInstant,
|
|
1286
|
-
sqlForm: "quote"
|
|
1287
|
-
});
|
|
1288
|
-
}
|
|
1289
|
-
function timestamp(precision) {
|
|
1290
|
-
const digits = timePrecision(precision, "timestamp");
|
|
1291
|
-
return required({
|
|
1292
|
-
baseType: timed("timestamp", digits),
|
|
1293
|
-
encode: (value) => encodeDateTime(value, digits),
|
|
1294
|
-
decode: decodeDateTime,
|
|
1295
|
-
sqlForm: "quote"
|
|
1296
|
-
});
|
|
1297
|
-
}
|
|
1298
|
-
function date() {
|
|
1299
|
-
return required({
|
|
1300
|
-
baseType: "date",
|
|
1301
|
-
encode: encodeDate,
|
|
1302
|
-
decode: decodeDate,
|
|
1303
|
-
sqlForm: "quote"
|
|
1304
|
-
});
|
|
1305
|
-
}
|
|
1306
|
-
function time(precision) {
|
|
1307
|
-
const digits = timePrecision(precision, "time");
|
|
1308
|
-
return required({
|
|
1309
|
-
baseType: timed("time", digits),
|
|
1310
|
-
encode: (value) => encodeTime(value, digits),
|
|
1311
|
-
decode: decodeTime,
|
|
1312
|
-
sqlForm: "quote"
|
|
1313
|
-
});
|
|
1314
|
-
}
|
|
1315
|
-
function timetz(precision) {
|
|
1316
|
-
const digits = timePrecision(precision, "timetz");
|
|
1317
|
-
return required({
|
|
1318
|
-
baseType: timed("timetz", digits),
|
|
1319
|
-
encode: (value) => encodeTimeZone(value, digits),
|
|
1320
|
-
decode: decodeTimeZone,
|
|
1321
|
-
sqlForm: "quote"
|
|
1322
|
-
});
|
|
1323
|
-
}
|
|
1324
|
-
function interval(fields) {
|
|
1325
|
-
const qualifier = fields === undefined ? undefined : intervalFields(fields);
|
|
1326
|
-
return required({
|
|
1327
|
-
baseType: qualifier === undefined ? "interval" : `interval ${qualifier}`,
|
|
1328
|
-
encode: encodeDuration,
|
|
1329
|
-
decode: decodeDuration,
|
|
1330
|
-
sqlForm: "quote"
|
|
1331
|
-
});
|
|
1332
|
-
}
|
|
1333
|
-
function timed(name, precision) {
|
|
1334
|
-
if (precision === undefined) {
|
|
1335
|
-
return name;
|
|
1336
|
-
}
|
|
1337
|
-
return `${name}(${String(precision)})`;
|
|
1338
|
-
}
|
|
1339
368
|
// src/dialects/pg/range.ts
|
|
1340
369
|
function tstzrange() {
|
|
1341
370
|
return rangeColumn("tstzrange", encodeInstant, decodeInstant, true);
|
|
@@ -1357,6 +386,7 @@ function rangeColumn(baseType, encodeBound, decodeBound, quote) {
|
|
|
1357
386
|
baseType,
|
|
1358
387
|
encode: (value) => writeRange(value, encodeBound, quote),
|
|
1359
388
|
decode: (wire) => readRange(wire, decodeBound, quote),
|
|
389
|
+
accepts: ["Object"],
|
|
1360
390
|
sqlForm: "cast"
|
|
1361
391
|
});
|
|
1362
392
|
}
|
|
@@ -1364,6 +394,9 @@ function writeRange(value, encodeBound, quote) {
|
|
|
1364
394
|
if (value.empty) {
|
|
1365
395
|
return "empty";
|
|
1366
396
|
}
|
|
397
|
+
if (value.empty !== false) {
|
|
398
|
+
rejected("range needs empty: true, or empty: false with lower and upper.");
|
|
399
|
+
}
|
|
1367
400
|
const lower = value.lower === null ? "" : boundText(encodeBound(value.lower), quote);
|
|
1368
401
|
const upper = value.upper === null ? "" : boundText(encodeBound(value.upper), quote);
|
|
1369
402
|
const open = value.lowerInclusive ? "[" : "(";
|
|
@@ -1506,6 +539,7 @@ function point() {
|
|
|
1506
539
|
baseType: "point",
|
|
1507
540
|
encode: encodePoint,
|
|
1508
541
|
decode: decodePoint,
|
|
542
|
+
accepts: ["Object"],
|
|
1509
543
|
sqlForm: "quote"
|
|
1510
544
|
});
|
|
1511
545
|
}
|
|
@@ -1514,6 +548,7 @@ function line() {
|
|
|
1514
548
|
baseType: "line",
|
|
1515
549
|
encode: encodeLine,
|
|
1516
550
|
decode: decodeLine,
|
|
551
|
+
accepts: ["Object"],
|
|
1517
552
|
sqlForm: "quote"
|
|
1518
553
|
});
|
|
1519
554
|
}
|
|
@@ -1634,29 +669,29 @@ function domain(_name, _base, _check) {
|
|
|
1634
669
|
}
|
|
1635
670
|
// src/dialects/pg/namespace.ts
|
|
1636
671
|
var t = {
|
|
1637
|
-
id,
|
|
672
|
+
id: id2,
|
|
1638
673
|
identity,
|
|
1639
|
-
uuid,
|
|
674
|
+
uuid: uuid2,
|
|
1640
675
|
smallint,
|
|
1641
676
|
integer,
|
|
1642
677
|
bigint,
|
|
1643
678
|
numeric,
|
|
1644
679
|
real,
|
|
1645
680
|
double,
|
|
1646
|
-
text,
|
|
1647
|
-
varchar,
|
|
1648
|
-
char,
|
|
1649
|
-
citext,
|
|
681
|
+
text: text2,
|
|
682
|
+
varchar: varchar2,
|
|
683
|
+
char: char2,
|
|
684
|
+
citext: citext2,
|
|
1650
685
|
boolean,
|
|
1651
686
|
bytea,
|
|
1652
|
-
json,
|
|
1653
|
-
jsonb,
|
|
1654
|
-
timestamptz,
|
|
1655
|
-
timestamp,
|
|
1656
|
-
date,
|
|
1657
|
-
time,
|
|
1658
|
-
timetz,
|
|
1659
|
-
interval,
|
|
687
|
+
json: json2,
|
|
688
|
+
jsonb: jsonb2,
|
|
689
|
+
timestamptz: timestamptz2,
|
|
690
|
+
timestamp: timestamp2,
|
|
691
|
+
date: date2,
|
|
692
|
+
time: time2,
|
|
693
|
+
timetz: timetz2,
|
|
694
|
+
interval: interval2,
|
|
1660
695
|
tstzrange,
|
|
1661
696
|
daterange,
|
|
1662
697
|
int4range,
|
|
@@ -1674,10 +709,39 @@ var t = {
|
|
|
1674
709
|
domain,
|
|
1675
710
|
custom
|
|
1676
711
|
};
|
|
712
|
+
// src/dialects/pg/ops/arr-ns.ts
|
|
713
|
+
var exports_arr_ns = {};
|
|
714
|
+
__export(exports_arr_ns, {
|
|
715
|
+
append: () => append,
|
|
716
|
+
remove: () => remove
|
|
717
|
+
});
|
|
718
|
+
|
|
719
|
+
// src/dialects/pg/ops/arr-append.ts
|
|
720
|
+
function append(value) {
|
|
721
|
+
return tag("arr.append", value);
|
|
722
|
+
}
|
|
723
|
+
// src/dialects/pg/ops/arr-remove.ts
|
|
724
|
+
function remove(value) {
|
|
725
|
+
return tag("arr.remove", value);
|
|
726
|
+
}
|
|
727
|
+
// src/dialects/pg/ops/json-ns.ts
|
|
728
|
+
var exports_json_ns = {};
|
|
729
|
+
__export(exports_json_ns, {
|
|
730
|
+
set: () => set
|
|
731
|
+
});
|
|
732
|
+
|
|
733
|
+
// src/dialects/pg/ops/json-set.ts
|
|
734
|
+
function set(path, value) {
|
|
735
|
+
return tag("json.set", { path, value });
|
|
736
|
+
}
|
|
1677
737
|
// src/dialects/pg/ops/between.ts
|
|
1678
738
|
function between(from, to) {
|
|
1679
739
|
return tag("between", [from, to]);
|
|
1680
740
|
}
|
|
741
|
+
// src/dialects/pg/ops/containedBy.ts
|
|
742
|
+
function containedBy(value) {
|
|
743
|
+
return tag("containedBy", value);
|
|
744
|
+
}
|
|
1681
745
|
// src/dialects/pg/ops/contains.ts
|
|
1682
746
|
function contains(value) {
|
|
1683
747
|
return tag("contains", value);
|
|
@@ -1710,6 +774,14 @@ function gte(value) {
|
|
|
1710
774
|
function has(where) {
|
|
1711
775
|
return tag("has", where);
|
|
1712
776
|
}
|
|
777
|
+
// src/dialects/pg/ops/hasAnyKey.ts
|
|
778
|
+
function hasAnyKey(keys) {
|
|
779
|
+
return tag("hasAnyKey", keys);
|
|
780
|
+
}
|
|
781
|
+
// src/dialects/pg/ops/hasKey.ts
|
|
782
|
+
function hasKey(key) {
|
|
783
|
+
return tag("hasKey", key);
|
|
784
|
+
}
|
|
1713
785
|
// src/dialects/pg/ops/ilike.ts
|
|
1714
786
|
function ilike(pattern) {
|
|
1715
787
|
return tag("ilike", pattern);
|
|
@@ -1722,6 +794,14 @@ function inList(values) {
|
|
|
1722
794
|
function like(pattern) {
|
|
1723
795
|
return tag("like", pattern);
|
|
1724
796
|
}
|
|
797
|
+
// src/dialects/pg/ops/matches.ts
|
|
798
|
+
function matches(query, options) {
|
|
799
|
+
return tag("matches", {
|
|
800
|
+
query,
|
|
801
|
+
mode: options?.mode ?? "websearch",
|
|
802
|
+
config: options?.config
|
|
803
|
+
});
|
|
804
|
+
}
|
|
1725
805
|
// src/dialects/pg/ops/lt.ts
|
|
1726
806
|
function lt(value) {
|
|
1727
807
|
return tag("lt", value);
|
|
@@ -1746,22 +826,32 @@ function notIn(values) {
|
|
|
1746
826
|
function or(branches) {
|
|
1747
827
|
return tag("or", branches);
|
|
1748
828
|
}
|
|
829
|
+
// src/dialects/pg/ops/overlaps.ts
|
|
830
|
+
function overlaps(value) {
|
|
831
|
+
return tag("overlaps", value);
|
|
832
|
+
}
|
|
833
|
+
// src/dialects/pg/ops/path.ts
|
|
834
|
+
function path(segments, op) {
|
|
835
|
+
return tag("path", { segments, op });
|
|
836
|
+
}
|
|
1749
837
|
// src/dialects/pg/ops/startsWith.ts
|
|
1750
838
|
function startsWith(value) {
|
|
1751
839
|
return tag("startsWith", value);
|
|
1752
840
|
}
|
|
1753
841
|
export {
|
|
1754
842
|
ColumnBuilder2 as ColumnBuilder,
|
|
843
|
+
exports_arr_ns as arr,
|
|
1755
844
|
between,
|
|
1756
845
|
bigint,
|
|
1757
846
|
boolean,
|
|
1758
847
|
bytea,
|
|
1759
|
-
char,
|
|
848
|
+
char2 as char,
|
|
1760
849
|
cidr,
|
|
1761
|
-
citext,
|
|
850
|
+
citext2 as citext,
|
|
851
|
+
containedBy,
|
|
1762
852
|
contains,
|
|
1763
853
|
custom,
|
|
1764
|
-
date,
|
|
854
|
+
date2 as date,
|
|
1765
855
|
daterange,
|
|
1766
856
|
domain,
|
|
1767
857
|
double,
|
|
@@ -1772,7 +862,9 @@ export {
|
|
|
1772
862
|
gt,
|
|
1773
863
|
gte,
|
|
1774
864
|
has,
|
|
1775
|
-
|
|
865
|
+
hasAnyKey,
|
|
866
|
+
hasKey,
|
|
867
|
+
id2 as id,
|
|
1776
868
|
identity,
|
|
1777
869
|
ilike,
|
|
1778
870
|
inList,
|
|
@@ -1782,10 +874,10 @@ export {
|
|
|
1782
874
|
int4range,
|
|
1783
875
|
int8range,
|
|
1784
876
|
integer,
|
|
1785
|
-
interval,
|
|
1786
|
-
json,
|
|
1787
|
-
jsonReplacer,
|
|
1788
|
-
jsonb,
|
|
877
|
+
interval2 as interval,
|
|
878
|
+
exports_json_ns as json,
|
|
879
|
+
jsonReplacer2 as jsonReplacer,
|
|
880
|
+
jsonb2 as jsonb,
|
|
1789
881
|
like,
|
|
1790
882
|
line,
|
|
1791
883
|
lt,
|
|
@@ -1793,29 +885,33 @@ export {
|
|
|
1793
885
|
ltree,
|
|
1794
886
|
macaddr,
|
|
1795
887
|
macaddr8,
|
|
1796
|
-
many,
|
|
888
|
+
many2 as many,
|
|
889
|
+
manyThrough2 as manyThrough,
|
|
890
|
+
matches,
|
|
1797
891
|
none,
|
|
1798
892
|
not,
|
|
1799
893
|
notIn,
|
|
1800
894
|
numeric,
|
|
1801
895
|
numrange,
|
|
1802
|
-
one,
|
|
896
|
+
one2 as one,
|
|
1803
897
|
or,
|
|
898
|
+
overlaps,
|
|
899
|
+
path,
|
|
1804
900
|
point,
|
|
1805
901
|
real,
|
|
1806
|
-
schema,
|
|
902
|
+
schema2 as schema,
|
|
1807
903
|
smallint,
|
|
1808
904
|
sql2 as sql,
|
|
1809
905
|
startsWith,
|
|
1810
906
|
t,
|
|
1811
907
|
table2 as table,
|
|
1812
|
-
text,
|
|
1813
|
-
time,
|
|
1814
|
-
timestamp,
|
|
1815
|
-
timestamptz,
|
|
1816
|
-
timetz,
|
|
908
|
+
text2 as text,
|
|
909
|
+
time2 as time,
|
|
910
|
+
timestamp2 as timestamp,
|
|
911
|
+
timestamptz2 as timestamptz,
|
|
912
|
+
timetz2 as timetz,
|
|
1817
913
|
tstzrange,
|
|
1818
914
|
tsvector,
|
|
1819
|
-
uuid,
|
|
1820
|
-
varchar
|
|
915
|
+
uuid2 as uuid,
|
|
916
|
+
varchar2 as varchar
|
|
1821
917
|
};
|