okmodel 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/capabilities.d.ts +32 -0
- package/dist/adapters/failure.d.ts +1 -1
- package/dist/adapters/pg/bun-sql.d.ts +53 -0
- package/dist/adapters/pg/bunsql-extra.d.ts +1 -1
- package/dist/adapters/pg/bunsql.d.ts +1 -1
- package/dist/adapters/pg/neon-extra.d.ts +18 -0
- package/dist/adapters/pg/neon.d.ts +104 -0
- package/dist/adapters/pg/no-inflight-timeout.d.ts +1 -1
- package/dist/contracts/error.d.ts +1 -1
- package/dist/dialects/pg/fn/index.d.ts +39 -1
- package/dist/dialects/pg/fn/index.js +118 -26
- package/dist/dialects/pg/index.d.ts +2 -0
- package/dist/dialects/pg/index.js +393 -18
- package/dist/dialects/pg/introspect.d.ts +11 -0
- package/dist/dialects/pg/operators.d.ts +1 -1
- package/dist/dialects/pg/ops/fragment.d.ts +119 -0
- package/dist/dialects/pg/ops/lane.d.ts +49 -0
- package/dist/dialects/pg/view/client.d.ts +14 -6
- package/dist/dialects/pg/view/index.d.ts +73 -1
- package/dist/dialects/pg/view/index.js +156 -5
- package/dist/dialects/pg/view/scratch.d.ts +8 -5
- package/dist/runtime/otel.d.ts +105 -0
- package/dist/runtime/otel.js +97 -0
- package/dist/runtime/pg/bun.js +4 -4
- package/dist/runtime/pg/neon.d.ts +38 -0
- package/dist/runtime/pg/neon.js +64 -0
- package/dist/runtime/pg/pg.js +4 -4
- package/dist/runtime/pg/pglite.js +4 -4
- package/dist/runtime/pg/postgresjs.js +4 -4
- package/dist/runtime/plan.d.ts +1 -1
- package/dist/runtime/sql-fragment.d.ts +43 -0
- package/dist/runtime/tenancy/index.js +10 -10
- package/dist/runtime/topology.d.ts +1 -1
- package/dist/runtime/traits/index.js +15 -16
- package/dist/runtime/types.d.ts +15 -1
- package/dist/runtime/validate/index.js +4 -4
- package/dist/shared/{mtaszv5a.js → 0wrea3jq.js} +102 -4
- package/dist/shared/{qq3899ht.js → 12z7aznj.js} +243 -14
- package/dist/shared/{w79hsckn.js → 14x60fbf.js} +5 -5
- package/dist/shared/{ek2wt2dz.js → 16kvjebh.js} +4 -4
- package/dist/shared/{svncdeh5.js → 195pzzzz.js} +8 -8
- package/dist/shared/{gzaveazc.js → 1d9q9cv2.js} +29 -2
- package/dist/shared/{jvd0mqag.js → 3449rcae.js} +5 -5
- package/dist/shared/{14vx95q4.js → 35q0n9tz.js} +7 -7
- package/dist/shared/3bb7wsqt.js +99 -0
- package/dist/shared/{y6njgyda.js → 3t6kw83m.js} +2 -2
- package/dist/shared/{81ebdx9p.js → 4m6hskg8.js} +4 -4
- package/dist/shared/{xhfsfkgk.js → 4vbf83xx.js} +9 -2
- package/dist/shared/{bg3rym3g.js → 63f4ksbz.js} +2 -2
- package/dist/shared/{pt94kz7f.js → 6m78c8ss.js} +1 -1
- package/dist/shared/{5e3tf63j.js → 760ppr76.js} +14 -6
- package/dist/shared/{zm0ptry0.js → 7ghwamrf.js} +1 -1
- package/dist/shared/{xnxsed62.js → 9dr2qnx7.js} +14 -14
- package/dist/shared/{h15jx9bc.js → 9dvh1dr6.js} +1 -1
- package/dist/shared/{q5c6ngn3.js → a62rb2da.js} +1 -1
- package/dist/shared/{kb2sdhfb.js → ae4j5f42.js} +17 -1
- package/dist/shared/agsfb86s.js +233 -0
- package/dist/shared/{7k9grvf6.js → b6d6p0zc.js} +5 -5
- package/dist/shared/{tbrvgw6z.js → bah9nbg3.js} +17 -16
- package/dist/shared/{5fe3kbsh.js → bnby0esn.js} +1 -1
- package/dist/shared/bsek72fg.js +225 -0
- package/dist/shared/{1w508jbr.js → bxas03mq.js} +21 -17
- package/dist/shared/{dk8v79p3.js → d5nmj7vv.js} +1 -1
- package/dist/shared/{tsvww22q.js → dpc2r7rb.js} +7 -7
- package/dist/shared/{vb6qfyve.js → e8zyaqvj.js} +2 -2
- package/dist/shared/{hyh73qk6.js → ecn8mfdq.js} +5 -5
- package/dist/shared/{gs74dbj5.js → f4jy1j7x.js} +27 -14
- package/dist/shared/{ttsqgp4p.js → fjpnhqan.js} +2 -2
- package/dist/shared/{xjk7hnn5.js → g5yc06ka.js} +2 -2
- package/dist/shared/{w72kgg4q.js → hfqmpasr.js} +6 -6
- package/dist/shared/{kr0jzbw2.js → hm5f8jby.js} +7 -7
- package/dist/shared/{dkxgzaqd.js → hqpxf4a4.js} +1 -1
- package/dist/shared/{cn957f8d.js → jebgrkeq.js} +3 -3
- package/dist/shared/{wa07eas9.js → jp36k7dp.js} +11 -11
- package/dist/shared/jx2m62cs.js +96 -0
- package/dist/shared/{sfz1ksn6.js → k86n8vq3.js} +2 -2
- package/dist/shared/{67txcrcw.js → kgwp4jdd.js} +4 -4
- package/dist/shared/{8skf0cam.js → kj9d8maq.js} +1 -1
- package/dist/shared/{aytqh5y2.js → m4xff2a6.js} +2 -2
- package/dist/shared/{zp9fmend.js → mfedzr74.js} +4 -4
- package/dist/shared/{ax7qv55k.js → mkrn359n.js} +60 -11
- package/dist/shared/{m6p12kbr.js → mnvjvqyp.js} +10 -10
- package/dist/shared/{1qa0qajz.js → mtw6jz76.js} +1 -1
- package/dist/shared/{1est4ezg.js → n05z9nwz.js} +3 -3
- package/dist/shared/{pbp1ss85.js → n0jmpgj1.js} +2 -2
- package/dist/shared/{ktz42yez.js → n41w4fbz.js} +5 -5
- package/dist/shared/{n816peh1.js → n454kcnw.js} +1 -1
- package/dist/shared/n7kg8mmx.js +61 -0
- package/dist/shared/{g6evj1j3.js → needfe47.js} +1 -1
- package/dist/shared/{2shdbn8q.js → njga14v4.js} +9 -9
- package/dist/shared/{vqrjpcqn.js → nmnsgj7x.js} +1 -1
- package/dist/shared/{b5pftnn2.js → p3xbdcvt.js} +14 -18
- package/dist/shared/{te5as7z7.js → p5nh3r8q.js} +3 -3
- package/dist/shared/{p6qc5gcp.js → pan0370z.js} +6 -6
- package/dist/shared/{79dt02vc.js → q0cqt2sp.js} +1 -1
- package/dist/shared/{5v3xf80k.js → qd9hhd8f.js} +1 -1
- package/dist/shared/{bm22fvzr.js → qfw14tna.js} +2 -2
- package/dist/shared/{9s0ypp87.js → sjk86yrx.js} +1 -1
- package/dist/shared/{3v7t1yrv.js → th3be82n.js} +2 -2
- package/dist/shared/{ed0b8k4s.js → typ3vy7t.js} +1 -1
- package/dist/shared/{vczs8gd4.js → v1wad97q.js} +2 -2
- package/dist/shared/{9628a9xt.js → vk7rag46.js} +1 -1
- package/dist/shared/{ze4hxsmy.js → w9ejzaqf.js} +1 -1
- package/dist/shared/{bz84tkzm.js → wcrheftc.js} +2 -2
- package/dist/shared/{ab9gmbwy.js → wvdjznah.js} +5 -5
- package/dist/shared/{7mnme5tn.js → wz2a78mp.js} +1 -1
- package/dist/shared/{9y3mmmh1.js → xfhe73sb.js} +1 -1
- package/dist/shared/{je4axnm8.js → z581d7ny.js} +2 -2
- package/dist/shared/{x933k9a3.js → zbqbmmrp.js} +10 -10
- package/dist/shared/{rs73fca9.js → zgex00fd.js} +6 -6
- package/dist/shared/{jznfax0y.js → zq1he88x.js} +4 -4
- package/dist/tooling/cli.js +26 -13
- package/dist/tooling/driver-run.js +4971 -0
- package/dist/tooling/driver-test.d.ts +36 -0
- package/dist/tooling/migrate/commands.d.ts +2 -2
- package/dist/tooling/migrate/index.js +9 -9
- package/dist/tooling/migrate/project.d.ts +3 -0
- package/dist/tooling/shared/03k6res6.js +210 -0
- package/dist/tooling/shared/08kemxjd.js +10 -0
- package/dist/tooling/shared/2revefqt.js +209 -0
- package/dist/tooling/shared/2wtvc7rw.js +1425 -0
- package/dist/tooling/shared/345tbc2k.js +16 -0
- package/dist/tooling/shared/3m1hkg7z.js +344 -0
- package/dist/tooling/shared/3rrw5w8f.js +81 -0
- package/dist/tooling/shared/3tq8pnb8.js +131 -0
- package/dist/tooling/shared/417zdsk7.js +194 -0
- package/dist/tooling/shared/4d2w25vw.js +40 -0
- package/dist/tooling/shared/54tqkxja.js +51 -0
- package/dist/tooling/shared/5bvw2nev.js +12 -0
- package/dist/tooling/shared/6nyfyw70.js +231 -0
- package/dist/tooling/shared/72fyg4zv.js +160 -0
- package/dist/tooling/shared/733a1tq3.js +38 -0
- package/dist/tooling/shared/7ae7rjmn.js +20 -0
- package/dist/tooling/shared/7kms6fvj.js +20 -0
- package/dist/tooling/shared/8sqrsw3s.js +49 -0
- package/dist/tooling/shared/96ps4g1z.js +32 -0
- package/dist/tooling/shared/9kazs5p6.js +195 -0
- package/dist/tooling/shared/9xzm7hjg.js +38 -0
- package/dist/tooling/shared/a6pp9d12.js +49 -0
- package/dist/tooling/shared/a7q7t4n3.js +22 -0
- package/dist/tooling/shared/aftb2mwr.js +18 -0
- package/dist/tooling/shared/bz2dqhab.js +311 -0
- package/dist/tooling/shared/cmptmb4f.js +12 -0
- package/dist/tooling/shared/ddjtfgnx.js +177 -0
- package/dist/tooling/shared/djydjpqt.js +261 -0
- package/dist/tooling/shared/dw08f3m8.js +9 -0
- package/dist/tooling/shared/dy672fz6.js +16 -0
- package/dist/tooling/shared/dzx85q70.js +66 -0
- package/dist/tooling/shared/ec71zqgt.js +270 -0
- package/dist/tooling/shared/ep8zh3bk.js +6 -0
- package/dist/tooling/shared/f9mphxej.js +3789 -0
- package/dist/tooling/shared/fb9k2qwd.js +89 -0
- package/dist/tooling/shared/g9ad4n80.js +211 -0
- package/dist/tooling/shared/gfvtj6d0.js +94 -0
- package/dist/tooling/shared/gmcf9cxf.js +294 -0
- package/dist/tooling/shared/htnaj77v.js +17 -0
- package/dist/tooling/shared/j9t5s12a.js +7 -0
- package/dist/tooling/shared/jne7b93p.js +42 -0
- package/dist/tooling/shared/ma2340rx.js +118 -0
- package/dist/tooling/shared/mtrqn2hn.js +505 -0
- package/dist/tooling/shared/n4jqhpqz.js +27 -0
- package/dist/tooling/shared/nf7jmhfa.js +20 -0
- package/dist/tooling/shared/p7f08ktn.js +332 -0
- package/dist/tooling/shared/ppnnnvj8.js +13 -0
- package/dist/tooling/shared/pqy21k24.js +312 -0
- package/dist/tooling/shared/pw8fgahx.js +69 -0
- package/dist/tooling/shared/pwsytxm5.js +17 -0
- package/dist/tooling/shared/rf83gr2d.js +94 -0
- package/dist/tooling/shared/rq5kk8j6.js +401 -0
- package/dist/tooling/shared/rs1jb051.js +12 -0
- package/dist/tooling/shared/smn6kz1p.js +157 -0
- package/dist/tooling/shared/spk1jg3r.js +1696 -0
- package/dist/tooling/shared/tn8gay14.js +143 -0
- package/dist/tooling/shared/vraj6d74.js +42 -0
- package/dist/tooling/shared/vs0t6qt8.js +64 -0
- package/dist/tooling/shared/vx86qjv8.js +150 -0
- package/dist/tooling/shared/w7qe8sj1.js +140 -0
- package/dist/tooling/shared/wt7j7nf6.js +15 -0
- package/dist/tooling/shared/wwnekq5n.js +6 -0
- package/dist/tooling/shared/xhrnjch9.js +185 -0
- package/dist/tooling/shared/xjs6zqtc.js +190 -0
- package/dist/tooling/shared/y031jct9.js +16 -0
- package/dist/tooling/shared/y5656f0e.js +233 -0
- package/dist/tooling/shared/yfr8hzhm.js +604 -0
- package/dist/tooling/shared/yk9mp7vb.js +250 -0
- package/dist/tooling/shared/yw30vnq2.js +139 -0
- package/dist/tooling/shared/z8d7ptht.js +618 -0
- package/dist/tooling/shared/zhwnfyb2.js +9 -0
- package/dist/tooling/shared/zvnhh1n0.js +198 -0
- package/dist/tooling/testing/index.js +3 -3
- package/package.json +14 -2
- package/dist/shared/y34a8714.js +0 -150
- package/dist/shared/zy8r7qvz.js +0 -116
- package/dist/shared/{ywr8hmey.js → 606g0nbf.js} +3 -3
- package/dist/shared/{rpycarcr.js → gcefca6p.js} +4 -4
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertNoControl
|
|
3
|
+
} from "./3tq8pnb8.js";
|
|
4
|
+
import {
|
|
5
|
+
throwNamed,
|
|
6
|
+
isOperator,
|
|
7
|
+
operatorName,
|
|
8
|
+
operatorValue,
|
|
9
|
+
tag,
|
|
10
|
+
refuseHidden,
|
|
11
|
+
indexes,
|
|
12
|
+
list,
|
|
13
|
+
isRecord,
|
|
14
|
+
fail2
|
|
15
|
+
} from "./f9mphxej.js";
|
|
16
|
+
|
|
17
|
+
// src/dialects/pg/ops/search-query.ts
|
|
18
|
+
function searchValue(query, options) {
|
|
19
|
+
return {
|
|
20
|
+
query,
|
|
21
|
+
match: options?.match ?? "natural",
|
|
22
|
+
language: options?.language
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// src/runtime/text-search.ts
|
|
27
|
+
var MATCHES = ["natural", "all-words", "phrase", "advanced"];
|
|
28
|
+
var SEARCH_KEYS = ["for", "in", "match", "language"];
|
|
29
|
+
function applyTextSearch(schema, call) {
|
|
30
|
+
const table = indexes(schema).get(call.table);
|
|
31
|
+
if (table === undefined)
|
|
32
|
+
fail2("OKM1120", `Table ${call.table} is not in the schema.`);
|
|
33
|
+
const spec = parseSearch(table, call.search);
|
|
34
|
+
const options = { match: spec.match, language: spec.language };
|
|
35
|
+
const where = withMatch(call.where, spec.column.field, spec.text, options);
|
|
36
|
+
const orderBy = call.op === "find" && call.orderBy === undefined ? ranked(table, spec.column.field, spec.text, options) : call.orderBy;
|
|
37
|
+
const { search: dropped, ...rest } = call;
|
|
38
|
+
return {
|
|
39
|
+
...rest,
|
|
40
|
+
where,
|
|
41
|
+
...orderBy !== undefined ? { orderBy } : {}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function parseSearch(table, search) {
|
|
45
|
+
if (typeof search === "string") {
|
|
46
|
+
return { text: textOf(search), column: columnFor(table, undefined), ...natural() };
|
|
47
|
+
}
|
|
48
|
+
if (!isRecord(search)) {
|
|
49
|
+
fail2("OKM1120", "search needs the text to look for, or { for, in, match, language }.", "Pass a string, or search: { for, in }.");
|
|
50
|
+
}
|
|
51
|
+
for (const key of Object.keys(search)) {
|
|
52
|
+
if (SEARCH_KEYS.includes(key))
|
|
53
|
+
continue;
|
|
54
|
+
fail2("OKM1120", `search does not take ${key}. Accepted: for, in, match, language.`, "Pass for, in, match, and language.");
|
|
55
|
+
}
|
|
56
|
+
if (typeof search.for !== "string") {
|
|
57
|
+
fail2("OKM1120", "search.for needs text to look for.", "Set for to the text you want to find.");
|
|
58
|
+
}
|
|
59
|
+
const named = search.in;
|
|
60
|
+
if (named !== undefined && typeof named !== "string") {
|
|
61
|
+
fail2("OKM1120", "search.in names the column to search.", "Set in to a column name.");
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
text: textOf(search.for),
|
|
65
|
+
column: columnFor(table, named),
|
|
66
|
+
match: matchOf(search.match),
|
|
67
|
+
language: languageOf(search.language)
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function natural() {
|
|
71
|
+
return { match: "natural", language: undefined };
|
|
72
|
+
}
|
|
73
|
+
function textOf(text) {
|
|
74
|
+
if (text.length === 0) {
|
|
75
|
+
fail2("OKM1120", "search needs text to look for.", "Pass the words you want to find.");
|
|
76
|
+
}
|
|
77
|
+
assertNoControl(text, "search");
|
|
78
|
+
return text;
|
|
79
|
+
}
|
|
80
|
+
function matchOf(value) {
|
|
81
|
+
if (value === undefined)
|
|
82
|
+
return "natural";
|
|
83
|
+
if (typeof value === "string" && isMatch(value))
|
|
84
|
+
return value;
|
|
85
|
+
fail2("OKM1120", "search.match must be natural, all-words, phrase, or advanced.", "Use natural, all-words, phrase, or advanced.");
|
|
86
|
+
}
|
|
87
|
+
function isMatch(value) {
|
|
88
|
+
return MATCHES.includes(value);
|
|
89
|
+
}
|
|
90
|
+
function languageOf(value) {
|
|
91
|
+
if (value === undefined)
|
|
92
|
+
return;
|
|
93
|
+
if (typeof value !== "string") {
|
|
94
|
+
fail2("OKM1120", "search.language must be a text search language such as english.", "Pass a language name such as english, or leave it out.");
|
|
95
|
+
}
|
|
96
|
+
return value;
|
|
97
|
+
}
|
|
98
|
+
function columnFor(table, name) {
|
|
99
|
+
const columns = searchable(table);
|
|
100
|
+
const names = columns.map((column) => column.field);
|
|
101
|
+
if (name === undefined) {
|
|
102
|
+
const only = columns[0];
|
|
103
|
+
if (columns.length === 1 && only !== undefined)
|
|
104
|
+
return only;
|
|
105
|
+
if (columns.length === 0) {
|
|
106
|
+
fail2("OKM1120", `Table ${table.model.name} has no column you can search.`, "Add a column built for search.");
|
|
107
|
+
}
|
|
108
|
+
fail2("OKM1120", `Table ${table.model.name} has more than one column you can search. Name one with search: { for, in }. Columns: ${list(names)}.`, `Set in to one of: ${list(names)}.`);
|
|
109
|
+
}
|
|
110
|
+
const column = table.columns.get(name);
|
|
111
|
+
if (column === undefined) {
|
|
112
|
+
throwNamed("OKM1120", name, names, `Column ${name} is not on ${table.model.name}. Columns you can search: ${list(names)}.`);
|
|
113
|
+
}
|
|
114
|
+
if (column.dataType !== "tsvector") {
|
|
115
|
+
fail2("OKM1120", `Column ${name} cannot be searched. Columns you can search: ${list(names)}.`, names.length === 0 ? "This table has no column you can search." : `Search one of: ${list(names)}.`);
|
|
116
|
+
}
|
|
117
|
+
if (column.hidden === true)
|
|
118
|
+
refuseHidden(column);
|
|
119
|
+
return column;
|
|
120
|
+
}
|
|
121
|
+
function searchable(table) {
|
|
122
|
+
const found = [];
|
|
123
|
+
for (const column of table.model.columns) {
|
|
124
|
+
if (column.dataType === "tsvector" && column.hidden !== true)
|
|
125
|
+
found.push(column);
|
|
126
|
+
}
|
|
127
|
+
return found;
|
|
128
|
+
}
|
|
129
|
+
function withMatch(where, field, text, options) {
|
|
130
|
+
const filter = { [field]: tag("matches", searchValue(text, passed(options))) };
|
|
131
|
+
if (where === undefined)
|
|
132
|
+
return filter;
|
|
133
|
+
if (isOperator(where) && operatorName(where) === "and") {
|
|
134
|
+
const branches = operatorValue(where);
|
|
135
|
+
if (Array.isArray(branches))
|
|
136
|
+
return tag("and", [...branches, filter]);
|
|
137
|
+
}
|
|
138
|
+
return tag("and", [where, filter]);
|
|
139
|
+
}
|
|
140
|
+
function ranked(table, field, text, options) {
|
|
141
|
+
const order = {
|
|
142
|
+
[field]: tag("relevance", searchValue(text, passed(options)))
|
|
143
|
+
};
|
|
144
|
+
for (const key of table.model.primary) {
|
|
145
|
+
if (!Object.hasOwn(order, key))
|
|
146
|
+
order[key] = "asc";
|
|
147
|
+
}
|
|
148
|
+
return order;
|
|
149
|
+
}
|
|
150
|
+
function passed(options) {
|
|
151
|
+
if (options.language === undefined)
|
|
152
|
+
return { match: options.match };
|
|
153
|
+
return { match: options.match, language: options.language };
|
|
154
|
+
}
|
|
155
|
+
export {
|
|
156
|
+
applyTextSearch
|
|
157
|
+
};
|