prisma-ltree 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -8
- package/dist/{codec-types-BJE-5cwk.d.mts → codec-types-B0DtEnU6.d.mts} +16 -13
- package/dist/codec-types-B0DtEnU6.d.mts.map +1 -0
- package/dist/codec-types.d.mts +1 -1
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +236 -16
- package/dist/control.mjs.map +1 -1
- package/dist/{descriptor-meta-2In8FI1I.mjs → descriptor-meta-DwbFei9y.mjs} +341 -34
- package/dist/descriptor-meta-DwbFei9y.mjs.map +1 -0
- package/dist/{operation-types-8su4lbK-.d.mts → operation-types-DD-KyBms.d.mts} +46 -1
- package/dist/{operation-types-8su4lbK-.d.mts.map → operation-types-DD-KyBms.d.mts.map} +1 -1
- package/dist/operation-types.d.mts +1 -1
- package/dist/pack.d.mts +1 -1
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/runtime.d.mts +35 -1
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +34 -1
- package/dist/runtime.mjs.map +1 -1
- package/package.json +11 -10
- package/src/contract.d.ts +87 -20
- package/src/contract.json +22 -1
- package/src/contract.ts +21 -3
- package/src/core/codecs-validation.ts +31 -0
- package/src/core/codecs.ts +32 -55
- package/src/core/contract-space-constants.ts +11 -0
- package/src/core/data-types.ts +36 -2
- package/src/core/descriptor-meta.ts +64 -4
- package/src/core/hierarchy-collection-methods.ts +111 -0
- package/src/core/pattern-validation.ts +313 -0
- package/src/exports/control.ts +36 -1
- package/src/exports/runtime.ts +3 -0
- package/src/types/operation-types.ts +37 -0
- package/dist/codec-types-BJE-5cwk.d.mts.map +0 -1
- package/dist/descriptor-meta-2In8FI1I.mjs.map +0 -1
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightweight structural checks for PostgreSQL `lquery` / `ltxtquery` pattern
|
|
3
|
+
* arguments. These catch empty values, empty path segments, unbalanced
|
|
4
|
+
* operators/parentheses, and obviously illegal syntax before the value is cast
|
|
5
|
+
* in SQL — without inventing framework PN-* error codes.
|
|
6
|
+
*
|
|
7
|
+
* Label bodies intentionally allow Unicode letters/numbers (`\p{L}` / `\p{N}`)
|
|
8
|
+
* plus `_` / `-` so locale-dependent labels that Postgres accepts are not
|
|
9
|
+
* rejected here. Full Postgres parsing still happens at the database.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** Word body chars: locale letters/digits, underscore, hyphen. */
|
|
13
|
+
const WORD_CHAR = /[\p{L}\p{N}_-]/u;
|
|
14
|
+
|
|
15
|
+
function isWordChar(ch: string): boolean {
|
|
16
|
+
return WORD_CHAR.test(ch);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function isDigit(ch: string): boolean {
|
|
20
|
+
return ch >= "0" && ch <= "9";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function fail(kind: "lquery" | "ltxtquery", message: string, value: string): never {
|
|
24
|
+
throw new Error(`${kind} ${message}: "${value}"`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Parse an optional `{n}`, `{n,}`, `{,m}`, `{n,m}`, or `{,}` quantifier starting
|
|
29
|
+
* at `i`. Returns the index after the closing `}`, or `i` when no quantifier
|
|
30
|
+
* begins here. Throws on a malformed `{...}`.
|
|
31
|
+
*/
|
|
32
|
+
function consumeQuantifier(
|
|
33
|
+
kind: "lquery" | "ltxtquery",
|
|
34
|
+
value: string,
|
|
35
|
+
i: number,
|
|
36
|
+
allow: boolean,
|
|
37
|
+
): number {
|
|
38
|
+
if (value[i] !== "{") return i;
|
|
39
|
+
if (!allow) {
|
|
40
|
+
fail(kind, `syntax error at character ${i + 1}`, value);
|
|
41
|
+
}
|
|
42
|
+
let j = i + 1;
|
|
43
|
+
let low: number | undefined;
|
|
44
|
+
let high: number | undefined;
|
|
45
|
+
let sawComma = false;
|
|
46
|
+
|
|
47
|
+
const readNumber = (): number | undefined => {
|
|
48
|
+
if (j >= value.length || !isDigit(value[j]!)) return undefined;
|
|
49
|
+
const start = j;
|
|
50
|
+
while (j < value.length && isDigit(value[j]!)) j += 1;
|
|
51
|
+
return Number(value.slice(start, j));
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
low = readNumber();
|
|
55
|
+
if (j < value.length && value[j] === ",") {
|
|
56
|
+
sawComma = true;
|
|
57
|
+
j += 1;
|
|
58
|
+
high = readNumber();
|
|
59
|
+
}
|
|
60
|
+
if (j >= value.length || value[j] !== "}") {
|
|
61
|
+
fail(kind, `syntax error at character ${i + 1}`, value);
|
|
62
|
+
}
|
|
63
|
+
j += 1;
|
|
64
|
+
|
|
65
|
+
// `{}` is invalid; `{,}` (both ends open) is valid in Postgres.
|
|
66
|
+
if (low === undefined && high === undefined && !sawComma) {
|
|
67
|
+
fail(kind, `syntax error at character ${i + 1}`, value);
|
|
68
|
+
}
|
|
69
|
+
if (low !== undefined && high !== undefined && low > high) {
|
|
70
|
+
fail(kind, "syntax error (quantifier low > high)", value);
|
|
71
|
+
}
|
|
72
|
+
return j;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Consume `@` / `*` / `%` modifiers that follow a non-star word. */
|
|
76
|
+
function consumeModifiers(value: string, i: number): number {
|
|
77
|
+
while (i < value.length) {
|
|
78
|
+
const ch = value[i]!;
|
|
79
|
+
if (ch === "@" || ch === "*" || ch === "%") {
|
|
80
|
+
i += 1;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
return i;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function consumeWord(kind: "lquery" | "ltxtquery", value: string, i: number): number {
|
|
89
|
+
if (i >= value.length || !isWordChar(value[i]!)) {
|
|
90
|
+
fail(kind, `syntax error at character ${i + 1}`, value);
|
|
91
|
+
}
|
|
92
|
+
let j = i;
|
|
93
|
+
while (j < value.length && isWordChar(value[j]!)) j += 1;
|
|
94
|
+
return j;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* One lquery level: either `*` + optional quantifier, or an optional `!`
|
|
99
|
+
* followed by `word mods? (| word mods?)*` and an optional trailing quantifier.
|
|
100
|
+
*/
|
|
101
|
+
function consumeLqueryLevel(value: string, i: number): number {
|
|
102
|
+
if (value[i] === "*") {
|
|
103
|
+
// Star wildcards cannot take `@`/`%` modifiers; only an optional quantifier.
|
|
104
|
+
return consumeQuantifier("lquery", value, i + 1, true);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
let j = i;
|
|
108
|
+
if (value[j] === "!") {
|
|
109
|
+
j += 1;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
j = consumeWord("lquery", value, j);
|
|
113
|
+
j = consumeModifiers(value, j);
|
|
114
|
+
|
|
115
|
+
while (j < value.length && value[j] === "|") {
|
|
116
|
+
j += 1;
|
|
117
|
+
j = consumeWord("lquery", value, j);
|
|
118
|
+
j = consumeModifiers(value, j);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return consumeQuantifier("lquery", value, j, true);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function assertValidLquery(value: unknown): asserts value is string {
|
|
125
|
+
if (typeof value !== "string") {
|
|
126
|
+
throw new Error("lquery pattern must be a string");
|
|
127
|
+
}
|
|
128
|
+
if (value.length === 0) {
|
|
129
|
+
throw new Error('lquery pattern must not be empty: ""');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
let i = 0;
|
|
133
|
+
i = consumeLqueryLevel(value, i);
|
|
134
|
+
while (i < value.length) {
|
|
135
|
+
if (value[i] !== ".") {
|
|
136
|
+
fail("lquery", `syntax error at character ${i + 1}`, value);
|
|
137
|
+
}
|
|
138
|
+
i += 1;
|
|
139
|
+
if (i >= value.length) {
|
|
140
|
+
fail("lquery", "syntax error (trailing '.' / empty label)", value);
|
|
141
|
+
}
|
|
142
|
+
i = consumeLqueryLevel(value, i);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function assertValidLqueryArray(value: unknown): asserts value is readonly string[] {
|
|
147
|
+
if (!Array.isArray(value)) {
|
|
148
|
+
throw new Error("lquery[] patterns must be a string array");
|
|
149
|
+
}
|
|
150
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
151
|
+
const entry = value[index];
|
|
152
|
+
try {
|
|
153
|
+
assertValidLquery(entry);
|
|
154
|
+
} catch (error) {
|
|
155
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
156
|
+
throw new Error(`lquery[] patterns[${index}]: ${message}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
type LtxtToken =
|
|
162
|
+
| { readonly kind: "word"; readonly text: string }
|
|
163
|
+
| { readonly kind: "and" }
|
|
164
|
+
| { readonly kind: "or" }
|
|
165
|
+
| { readonly kind: "not" }
|
|
166
|
+
| { readonly kind: "lparen" }
|
|
167
|
+
| { readonly kind: "rparen" };
|
|
168
|
+
|
|
169
|
+
function tokenizeLtxtquery(value: string): LtxtToken[] {
|
|
170
|
+
const tokens: LtxtToken[] = [];
|
|
171
|
+
let i = 0;
|
|
172
|
+
while (i < value.length) {
|
|
173
|
+
const ch = value[i]!;
|
|
174
|
+
if (ch === " " || ch === "\t" || ch === "\n" || ch === "\r") {
|
|
175
|
+
i += 1;
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
if (ch === "&") {
|
|
179
|
+
tokens.push({ kind: "and" });
|
|
180
|
+
i += 1;
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
if (ch === "|") {
|
|
184
|
+
tokens.push({ kind: "or" });
|
|
185
|
+
i += 1;
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (ch === "!") {
|
|
189
|
+
tokens.push({ kind: "not" });
|
|
190
|
+
i += 1;
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
if (ch === "(") {
|
|
194
|
+
tokens.push({ kind: "lparen" });
|
|
195
|
+
i += 1;
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
if (ch === ")") {
|
|
199
|
+
tokens.push({ kind: "rparen" });
|
|
200
|
+
i += 1;
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (isWordChar(ch)) {
|
|
204
|
+
const start = i;
|
|
205
|
+
i = consumeWord("ltxtquery", value, i);
|
|
206
|
+
i = consumeModifiers(value, i);
|
|
207
|
+
tokens.push({ kind: "word", text: value.slice(start, i) });
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
fail("ltxtquery", `syntax error at character ${i + 1}`, value);
|
|
211
|
+
}
|
|
212
|
+
return tokens;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Recursive-descent check mirroring Postgres ltxtquery operator precedence:
|
|
217
|
+
* OR < AND < NOT < primary (word / parenthesized expr).
|
|
218
|
+
*/
|
|
219
|
+
function parseLtxtExpr(tokens: readonly LtxtToken[], value: string): void {
|
|
220
|
+
let pos = 0;
|
|
221
|
+
|
|
222
|
+
const peek = (): LtxtToken | undefined => tokens[pos];
|
|
223
|
+
const take = (): LtxtToken => {
|
|
224
|
+
const tok = tokens[pos];
|
|
225
|
+
if (!tok) fail("ltxtquery", "syntax error (unexpected end)", value);
|
|
226
|
+
pos += 1;
|
|
227
|
+
return tok;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const parsePrimary = (): void => {
|
|
231
|
+
const tok = peek();
|
|
232
|
+
if (!tok) fail("ltxtquery", "syntax error (missing operand)", value);
|
|
233
|
+
if (tok.kind === "word") {
|
|
234
|
+
take();
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
if (tok.kind === "lparen") {
|
|
238
|
+
take();
|
|
239
|
+
parseOr();
|
|
240
|
+
const close = take();
|
|
241
|
+
if (close.kind !== "rparen") {
|
|
242
|
+
fail("ltxtquery", "syntax error (expected ')')", value);
|
|
243
|
+
}
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
fail("ltxtquery", "syntax error (missing operand)", value);
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const parseFactor = (): void => {
|
|
250
|
+
while (peek()?.kind === "not") take();
|
|
251
|
+
parsePrimary();
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
const parseAnd = (): void => {
|
|
255
|
+
parseFactor();
|
|
256
|
+
while (peek()?.kind === "and") {
|
|
257
|
+
take();
|
|
258
|
+
parseFactor();
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
const parseOr = (): void => {
|
|
263
|
+
parseAnd();
|
|
264
|
+
while (peek()?.kind === "or") {
|
|
265
|
+
take();
|
|
266
|
+
parseAnd();
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
parseOr();
|
|
271
|
+
if (pos !== tokens.length) {
|
|
272
|
+
fail("ltxtquery", "syntax error (unexpected token)", value);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export function assertValidLtxtquery(value: unknown): asserts value is string {
|
|
277
|
+
if (typeof value !== "string") {
|
|
278
|
+
throw new Error("ltxtquery query must be a string");
|
|
279
|
+
}
|
|
280
|
+
if (value.length === 0) {
|
|
281
|
+
throw new Error('ltxtquery query must not be empty: ""');
|
|
282
|
+
}
|
|
283
|
+
const tokens = tokenizeLtxtquery(value);
|
|
284
|
+
if (tokens.length === 0) {
|
|
285
|
+
fail("ltxtquery", "syntax error (missing operand)", value);
|
|
286
|
+
}
|
|
287
|
+
parseLtxtExpr(tokens, value);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Validate a pattern argument when the caller passed a raw JS value. Expression
|
|
292
|
+
* / ParamRef objects are left alone so dynamic binds still round-trip to
|
|
293
|
+
* Postgres (which remains the authority for those).
|
|
294
|
+
*/
|
|
295
|
+
export function assertPatternArg(
|
|
296
|
+
castType: "lquery" | "ltxtquery" | "lquery[]",
|
|
297
|
+
arg: unknown,
|
|
298
|
+
): void {
|
|
299
|
+
if (arg !== null && typeof arg === "object" && !Array.isArray(arg)) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
switch (castType) {
|
|
303
|
+
case "lquery":
|
|
304
|
+
assertValidLquery(arg);
|
|
305
|
+
return;
|
|
306
|
+
case "ltxtquery":
|
|
307
|
+
assertValidLtxtquery(arg);
|
|
308
|
+
return;
|
|
309
|
+
case "lquery[]":
|
|
310
|
+
assertValidLqueryArray(arg);
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
}
|
package/src/exports/control.ts
CHANGED
|
@@ -7,10 +7,25 @@ import { contractSpaceFromJson } from "@prisma/orm-toolchain/migration-tools/spa
|
|
|
7
7
|
import type { SqlStorage } from "@prisma/orm-family-sql/contract/types";
|
|
8
8
|
import baselineMetadata from "../../migrations/20260619T2142_install_ltree/migration.json" with { type: "json" };
|
|
9
9
|
import baselineOps from "../../migrations/20260619T2142_install_ltree/ops.json" with { type: "json" };
|
|
10
|
+
import createMetadata from "../../migrations/20261111T1904_create_ltree_extension/migration.json" with { type: "json" };
|
|
11
|
+
import createOps from "../../migrations/20261111T1904_create_ltree_extension/ops.json" with { type: "json" };
|
|
12
|
+
import declareMetadata from "../../migrations/20261111T1905_declare_ltree_extension/migration.json" with { type: "json" };
|
|
13
|
+
import declareOps from "../../migrations/20261111T1905_declare_ltree_extension/ops.json" with { type: "json" };
|
|
14
|
+
import searchPathMetadata from "../../migrations/20261111T1908_find_ltree_on_search_path/migration.json" with { type: "json" };
|
|
15
|
+
import searchPathOps from "../../migrations/20261111T1908_find_ltree_on_search_path/ops.json" with { type: "json" };
|
|
16
|
+
import searchPathInstallMetadata from "../../migrations/20261111T1908_install_ltree_on_search_path/migration.json" with { type: "json" };
|
|
17
|
+
import searchPathInstallOps from "../../migrations/20261111T1908_install_ltree_on_search_path/ops.json" with { type: "json" };
|
|
10
18
|
import headRef from "../../migrations/refs/head.json" with { type: "json" };
|
|
11
19
|
import contractJson from "../contract.json" with { type: "json" };
|
|
12
20
|
import { LTREE_ARRAY_CODEC_ID, LTREE_CODEC_ID } from "../core/constants";
|
|
13
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
LTREE_BASELINE_MIGRATION_NAME,
|
|
23
|
+
LTREE_CREATE_EXTENSION_MIGRATION_NAME,
|
|
24
|
+
LTREE_DECLARE_EXTENSION_MIGRATION_NAME,
|
|
25
|
+
LTREE_SEARCH_PATH_INSTALL_MIGRATION_NAME,
|
|
26
|
+
LTREE_SEARCH_PATH_MIGRATION_NAME,
|
|
27
|
+
LTREE_SPACE_ID,
|
|
28
|
+
} from "../core/contract-space-constants";
|
|
14
29
|
import { ltreePackMeta, ltreeQueryOperations } from "../core/descriptor-meta";
|
|
15
30
|
|
|
16
31
|
const ltreeControlPlaneHooks: CodecControlHooks = {
|
|
@@ -25,6 +40,26 @@ const ltreeContractSpace = contractSpaceFromJson<Contract<SqlStorage>>({
|
|
|
25
40
|
metadata: baselineMetadata,
|
|
26
41
|
ops: baselineOps,
|
|
27
42
|
},
|
|
43
|
+
{
|
|
44
|
+
dirName: LTREE_DECLARE_EXTENSION_MIGRATION_NAME,
|
|
45
|
+
metadata: declareMetadata,
|
|
46
|
+
ops: declareOps,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
dirName: LTREE_CREATE_EXTENSION_MIGRATION_NAME,
|
|
50
|
+
metadata: createMetadata,
|
|
51
|
+
ops: createOps,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
dirName: LTREE_SEARCH_PATH_MIGRATION_NAME,
|
|
55
|
+
metadata: searchPathMetadata,
|
|
56
|
+
ops: searchPathOps,
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
dirName: LTREE_SEARCH_PATH_INSTALL_MIGRATION_NAME,
|
|
60
|
+
metadata: searchPathInstallMetadata,
|
|
61
|
+
ops: searchPathInstallOps,
|
|
62
|
+
},
|
|
28
63
|
],
|
|
29
64
|
headRef,
|
|
30
65
|
});
|
package/src/exports/runtime.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { SqlRuntimeExtensionDescriptor } from "@prisma/orm-family-sql/runtime";
|
|
2
2
|
import { ltreePackMeta, ltreeQueryOperations } from "../core/descriptor-meta";
|
|
3
|
+
import { ltreeHierarchyMethods } from "../core/hierarchy-collection-methods";
|
|
3
4
|
import { ltreeCodecRegistry } from "../core/registry";
|
|
4
5
|
|
|
5
6
|
const ltreeRuntimeDescriptor: SqlRuntimeExtensionDescriptor<"postgres"> = {
|
|
@@ -16,6 +17,7 @@ const ltreeRuntimeDescriptor: SqlRuntimeExtensionDescriptor<"postgres"> = {
|
|
|
16
17
|
},
|
|
17
18
|
codecs: () => Array.from(ltreeCodecRegistry.values()),
|
|
18
19
|
queryOperations: () => ltreeQueryOperations(),
|
|
20
|
+
collectionMethods: () => [ltreeHierarchyMethods],
|
|
19
21
|
create() {
|
|
20
22
|
return {
|
|
21
23
|
familyId: "sql" as const,
|
|
@@ -24,5 +26,6 @@ const ltreeRuntimeDescriptor: SqlRuntimeExtensionDescriptor<"postgres"> = {
|
|
|
24
26
|
},
|
|
25
27
|
};
|
|
26
28
|
|
|
29
|
+
export type { LtreeHierarchyMethods } from "../core/hierarchy-collection-methods";
|
|
27
30
|
export { ltreeCodecRegistry };
|
|
28
31
|
export default ltreeRuntimeDescriptor;
|
|
@@ -155,6 +155,43 @@ export type QueryOperationTypes<CT extends CodecTypesBase> = SqlQueryOperationTy
|
|
|
155
155
|
query: CodecExpression<"pg/text@1", boolean, CT>,
|
|
156
156
|
) => Expression<{ readonly codecId: "pg/ltree@1"; readonly nullable: false }>;
|
|
157
157
|
};
|
|
158
|
+
// Boolean array operators (ADR-007). Names differ from the scalar methods
|
|
159
|
+
// because the operation registry keys by name only.
|
|
160
|
+
readonly containsAncestorOf: {
|
|
161
|
+
readonly self: { readonly codecId: "pg/ltree-array@1" };
|
|
162
|
+
readonly impl: (
|
|
163
|
+
self: CodecExpression<"pg/ltree-array@1", boolean, CT>,
|
|
164
|
+
other: CodecExpression<"pg/ltree@1", boolean, CT>,
|
|
165
|
+
) => Expression<{ readonly codecId: "pg/bool@1"; readonly nullable: false }>;
|
|
166
|
+
};
|
|
167
|
+
readonly containsDescendantOf: {
|
|
168
|
+
readonly self: { readonly codecId: "pg/ltree-array@1" };
|
|
169
|
+
readonly impl: (
|
|
170
|
+
self: CodecExpression<"pg/ltree-array@1", boolean, CT>,
|
|
171
|
+
other: CodecExpression<"pg/ltree@1", boolean, CT>,
|
|
172
|
+
) => Expression<{ readonly codecId: "pg/bool@1"; readonly nullable: false }>;
|
|
173
|
+
};
|
|
174
|
+
readonly matchesAnyLquery: {
|
|
175
|
+
readonly self: { readonly codecId: "pg/ltree-array@1" };
|
|
176
|
+
readonly impl: (
|
|
177
|
+
self: CodecExpression<"pg/ltree-array@1", boolean, CT>,
|
|
178
|
+
pattern: CodecExpression<"pg/text@1", boolean, CT>,
|
|
179
|
+
) => Expression<{ readonly codecId: "pg/bool@1"; readonly nullable: false }>;
|
|
180
|
+
};
|
|
181
|
+
readonly matchesAnyLqueryArray: {
|
|
182
|
+
readonly self: { readonly codecId: "pg/ltree-array@1" };
|
|
183
|
+
readonly impl: (
|
|
184
|
+
self: CodecExpression<"pg/ltree-array@1", boolean, CT>,
|
|
185
|
+
patterns: CodecExpression<"pg/text-array@1", boolean, CT>,
|
|
186
|
+
) => Expression<{ readonly codecId: "pg/bool@1"; readonly nullable: false }>;
|
|
187
|
+
};
|
|
188
|
+
readonly matchesAnyLtxtquery: {
|
|
189
|
+
readonly self: { readonly codecId: "pg/ltree-array@1" };
|
|
190
|
+
readonly impl: (
|
|
191
|
+
self: CodecExpression<"pg/ltree-array@1", boolean, CT>,
|
|
192
|
+
query: CodecExpression<"pg/text@1", boolean, CT>,
|
|
193
|
+
) => Expression<{ readonly codecId: "pg/bool@1"; readonly nullable: false }>;
|
|
194
|
+
};
|
|
158
195
|
// `lca(ltree[])` — ships as `lcaAll()` (ADR-001, ADR-005); not `lca()`
|
|
159
196
|
// because prisma-next operation names are globally unique across the composed
|
|
160
197
|
// stack. `nullable: false` mirrors the first-match ops (PG can return NULL for
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codec-types-BJE-5cwk.d.mts","names":[],"sources":["../src/core/constants.ts","../src/core/codecs.ts","../src/types/codec-types.ts"],"mappings":";;;;;;cAAa,cAAA;AAAA,cAEA,oBAAA;;;cCkDA,UAAA,SAAmB,SAAA,QACvB,cAAA;EAKD,MAAA,CAAO,KAAA,UAAe,IAAA,EAAM,gBAAA,GAAmB,OAAA;EAK/C,MAAA,CAAO,IAAA,UAAc,IAAA,EAAM,gBAAA,GAAmB,OAAA;EAIpD,UAAA,CAAW,KAAA,WAAgB,SAAA;EAK3B,UAAA,CAAW,IAAA,EAAM,SAAA;AAAA;AAAA,cAMN,eAAA,SAAwB,uBAAA;EAAA,UAChB,cAAA,CAAe,UAAA,EAAY,cAAA,GAAiB,cAAA;EAAA,SAI7C,QAAA,mDAAQ,UAAA;EAAA,SACR,OAAA;EAAA,SACA,MAAA;EAAA,SACA,YAAA;EACT,gBAAA;EAGA,OAAA,KAAY,GAAA,EAAK,oBAAA,KAAyB,UAAA;AAAA;AAAA,cAaxC,eAAA,SAAwB,SAAA,QAC5B,oBAAA;EAKD,MAAA,CAAO,KAAA,qBAA0B,IAAA,EAAM,gBAAA,GAAmB,OAAA;EAO1D,MAAA,CAAO,IAAA,qBAAyB,IAAA,EAAM,gBAAA,GAAmB,OAAA;EAI/D,UAAA,CAAW,KAAA,sBAA2B,SAAA;EAOtC,UAAA,CAAW,IAAA,EAAM,SAAA;AAAA;AAAA,cAWN,oBAAA,SAA6B,uBAAA;EAAA,UACrB,cAAA,CAAe,UAAA,EAAY,cAAA,GAAiB,cAAA;EAAA,SAI7C,QAAA,mDAAQ,UAAA;EAAA,SACR,OAAA;EAAA,SACA,MAAA;EAAA,SACA,YAAA;EACT,gBAAA;EAGA,OAAA,KAAY,GAAA,EAAK,oBAAA,KAAyB,eAAA;AAAA;AAAA,cAc/C,kBAAA;EAAA,SACJ,KAAA,EAAK,eAAA;EAAA,SACL,UAAA,EAAU,oBAAA;AAAA;AAAA,KAGA,YAAA,GAAa,iBAAiB,QAAQ,kBAAA;;;KCvKtC,KAAA;EAAA,SAA4B,OAAO;AAAA;AAAA,KAEnC,UAAA;EAAA,SAA4C,YAAY;AAAA;AAAA,KAExD,UAAA,GAAa,YAAc"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"descriptor-meta-2In8FI1I.mjs","names":[],"sources":["../src/core/authoring.ts","../src/core/data-types.ts","../src/core/codecs.ts","../src/core/registry.ts","../src/core/descriptor-meta.ts"],"sourcesContent":["import type { AuthoringTypeNamespace } from \"@prisma/orm-framework/components/authoring\";\nimport { LTREE_ARRAY_CODEC_ID, LTREE_CODEC_ID } from \"./constants\";\n\nexport const ltreeAuthoringTypes = {\n ltree: {\n Ltree: {\n kind: \"typeConstructor\",\n inferred: true,\n output: {\n codecId: LTREE_CODEC_ID,\n },\n },\n LtreeArray: {\n kind: \"typeConstructor\",\n inferred: true,\n output: {\n codecId: LTREE_ARRAY_CODEC_ID,\n },\n },\n },\n} as const satisfies AuthoringTypeNamespace;\n","/**\n * Data types this extension owns.\n *\n * `ltree` and `ltree[]` are PostgreSQL types the target does not register.\n * A path's canonical form is its label text. An array's canonical form is a\n * JSON array of those texts. Both accept text the contract can already write.\n * The texts are what a migration writes and what the catalog reports.\n */\n\nimport type { DataType } from \"@prisma/orm-framework/components/codec\";\nimport { sqlDataType } from \"@prisma/orm-family-sql/contract/data-type\";\nimport { pgText } from \"@prisma/orm-target-postgres/target/data-types\";\n\nexport const ltreeDataType = sqlDataType(\"ltree/ltree\", {\n texts: [{ text: \"ltree\", written: true, catalog: true }],\n casts: {\n [pgText.id]: (value) => value,\n },\n});\n\n/**\n * `sqlDataType` accepts parentheses in a type name and refuses square brackets.\n * PostgreSQL writes this type as `ltree[]`, and `format_type` reports `ltree[]`.\n * Declare the type first, then set that text so a migration and a catalog check use it.\n */\nconst ltreeArrayDeclared = sqlDataType(\"ltree/ltree-array\", {\n listCast: {\n of: [pgText.id],\n cast: (elements) => [...elements],\n },\n});\n\nexport const ltreeArrayDataType = {\n ...ltreeArrayDeclared,\n sql: {\n ...ltreeArrayDeclared.sql,\n texts: [{ text: \"ltree[]\", written: true as const, catalog: true as const }],\n },\n} as typeof ltreeArrayDeclared;\n\nexport const ltreeDataTypes: readonly DataType[] = [ltreeDataType, ltreeArrayDataType];\n","import type { JsonValue } from \"@prisma/orm-framework/contract/types\";\nimport {\n type CodecCallContext,\n CodecImpl,\n type CodecInstanceContext,\n type ColumnHelperFor,\n type ColumnHelperForStrict,\n column,\n} from \"@prisma/orm-framework/components/codec\";\nimport type { ExtractCodecTypes, ProjectionExpr } from \"@prisma/orm-family-sql/relational-core/ast\";\nimport {\n definePostgresCodecs,\n PostgresCodecDescriptor,\n} from \"@prisma/orm-target-postgres/target/codec-descriptor\";\nimport {\n LTREE_ARRAY_CODEC_ID,\n LTREE_CODEC_ID,\n LTREE_MAX_LABEL_LENGTH,\n LTREE_MAX_LABELS,\n} from \"./constants\";\nimport { ltreeArrayDataType, ltreeDataType } from \"./data-types\";\n\nconst LABEL_PATTERN = /^[A-Za-z0-9_-]+$/;\n\nexport function assertValidLtree(value: unknown): asserts value is string {\n if (typeof value !== \"string\") {\n throw new Error(\"ltree value must be a string\");\n }\n if (value.length === 0) {\n throw new Error(\"ltree value must not be empty\");\n }\n const labels = value.split(\".\");\n if (labels.length > LTREE_MAX_LABELS) {\n throw new Error(`ltree path exceeds max labels: got ${labels.length}, max ${LTREE_MAX_LABELS}`);\n }\n for (const label of labels) {\n if (label.length === 0) {\n throw new Error(`ltree label must not be empty in path \"${value}\"`);\n }\n if (label.length > LTREE_MAX_LABEL_LENGTH) {\n throw new Error(\n `ltree label exceeds max length: got ${label.length}, max ${LTREE_MAX_LABEL_LENGTH}`,\n );\n }\n if (!LABEL_PATTERN.test(label)) {\n throw new Error(\n `ltree label \"${label}\" contains invalid characters; allowed: alphanumeric, underscore, hyphen`,\n );\n }\n }\n}\n\nexport class LtreeCodec extends CodecImpl<\n typeof LTREE_CODEC_ID,\n readonly [\"equality\", \"order\"],\n string,\n string\n> {\n async encode(value: string, _ctx: CodecCallContext): Promise<string> {\n assertValidLtree(value);\n return value;\n }\n\n async decode(wire: string, _ctx: CodecCallContext): Promise<string> {\n return wire;\n }\n\n encodeJson(value: string): JsonValue {\n assertValidLtree(value);\n return value;\n }\n\n decodeJson(json: JsonValue): string {\n assertValidLtree(json);\n return json;\n }\n}\n\nexport class LtreeDescriptor extends PostgresCodecDescriptor<void> {\n protected override jsonProjection(expression: ProjectionExpr): ProjectionExpr {\n // ltree's text form is already its canonical JSON string.\n return expression;\n }\n override readonly dataType = ltreeDataType.id;\n override readonly codecId = LTREE_CODEC_ID;\n override readonly traits = [\"equality\", \"order\"] as const;\n override readonly paramsSchema = undefined;\n override renderOutputType(): string {\n return \"string\";\n }\n override factory(): (ctx: CodecInstanceContext) => LtreeCodec {\n const shared = new LtreeCodec(this);\n return () => shared;\n }\n}\n\nexport const ltreeDescriptor = new LtreeDescriptor();\n\nexport const ltree = () => column(ltreeDescriptor.factory(), ltreeDescriptor.codecId, undefined);\n\nltree satisfies ColumnHelperFor<LtreeDescriptor>;\nltree satisfies ColumnHelperForStrict<LtreeDescriptor>;\n\nexport class LtreeArrayCodec extends CodecImpl<\n typeof LTREE_ARRAY_CODEC_ID,\n readonly [\"equality\"],\n readonly string[],\n readonly string[]\n> {\n async encode(value: readonly string[], _ctx: CodecCallContext): Promise<readonly string[]> {\n for (const entry of value) {\n assertValidLtree(entry);\n }\n return value;\n }\n\n async decode(wire: readonly string[], _ctx: CodecCallContext): Promise<readonly string[]> {\n return wire;\n }\n\n encodeJson(value: readonly string[]): JsonValue {\n for (const entry of value) {\n assertValidLtree(entry);\n }\n return [...value];\n }\n\n decodeJson(json: JsonValue): readonly string[] {\n if (!Array.isArray(json)) {\n return [];\n }\n return json.map((entry) => {\n assertValidLtree(entry);\n return String(entry);\n });\n }\n}\n\nexport class LtreeArrayDescriptor extends PostgresCodecDescriptor<void> {\n protected override jsonProjection(expression: ProjectionExpr): ProjectionExpr {\n // ltree[] text form projects as a JSON string array already.\n return expression;\n }\n override readonly dataType = ltreeArrayDataType.id;\n override readonly codecId = LTREE_ARRAY_CODEC_ID;\n override readonly traits = [\"equality\"] as const;\n override readonly paramsSchema = undefined;\n override renderOutputType(): string {\n return \"readonly string[]\";\n }\n override factory(): (ctx: CodecInstanceContext) => LtreeArrayCodec {\n const shared = new LtreeArrayCodec(this);\n return () => shared;\n }\n}\n\nexport const ltreeArrayDescriptor = new LtreeArrayDescriptor();\n\nexport const ltreeArray = () =>\n column(ltreeArrayDescriptor.factory(), ltreeArrayDescriptor.codecId, undefined);\n\nltreeArray satisfies ColumnHelperFor<LtreeArrayDescriptor>;\nltreeArray satisfies ColumnHelperForStrict<LtreeArrayDescriptor>;\n\nconst codecDescriptorMap = {\n ltree: ltreeDescriptor,\n ltreeArray: ltreeArrayDescriptor,\n} as const;\n\nexport type CodecTypes = ExtractCodecTypes<typeof codecDescriptorMap>;\n\nexport const codecDescriptors = definePostgresCodecs(Object.values(codecDescriptorMap));\n","import { buildCodecDescriptorRegistry } from \"@prisma/orm-family-sql/relational-core/codec-descriptor-registry\";\nimport type { CodecDescriptorRegistry } from \"@prisma/orm-family-sql/relational-core/query-lane-context\";\nimport { codecDescriptors } from \"./codecs\";\n\nexport const ltreeCodecRegistry: CodecDescriptorRegistry =\n buildCodecDescriptorRegistry(codecDescriptors);\n","import type { AnyExpression } from \"@prisma/orm-family-sql/relational-core/ast\";\nimport {\n buildOperation,\n type CodecExpression,\n codecOf,\n type Expression,\n toExpr,\n} from \"@prisma/orm-family-sql/relational-core/expression\";\nimport type { CodecTypes } from \"../types/codec-types\";\nimport type { QueryOperationTypes } from \"../types/operation-types\";\nimport { ltreeAuthoringTypes } from \"./authoring\";\nimport { LTREE_ARRAY_CODEC_ID, LTREE_CODEC_ID } from \"./constants\";\nimport { ltreeDataTypes } from \"./data-types\";\nimport { ltreeCodecRegistry } from \"./registry\";\n\ntype CodecTypesBase = Record<string, { readonly input: unknown; readonly output: unknown }>;\n\ntype BoolReturn = Expression<{ readonly codecId: \"pg/bool@1\"; readonly nullable: false }>;\ntype LtreeReturn = Expression<{ readonly codecId: \"pg/ltree@1\"; readonly nullable: false }>;\ntype IntReturn = Expression<{ readonly codecId: \"pg/int4@1\"; readonly nullable: false }>;\ntype TextReturn = Expression<{ readonly codecId: \"pg/text@1\"; readonly nullable: false }>;\n\nconst BOOL_RETURN = { codecId: \"pg/bool@1\", nullable: false } as const;\nconst LTREE_RETURN = { codecId: \"pg/ltree@1\", nullable: false } as const;\nconst INT_RETURN = { codecId: \"pg/int4@1\", nullable: false } as const;\nconst TEXT_RETURN = { codecId: \"pg/text@1\", nullable: false } as const;\nconst TEXT_CODEC_ID = \"pg/text@1\" as const;\nconst INT_CODEC_ID = \"pg/int4@1\" as const;\n\n/**\n * Build a function-style operation whose SQL is `fnName(self, arg0, arg1, ...)`.\n * The template's placeholder count is derived from the actual argument list, so\n * one helper covers fixed-arity functions (`nlevel`, `subltree`), optional-arg\n * overloads (`subpath`, `index`), and the variadic `lca` (see ADR-001). `args`\n * already carries each value through `toExpr` with its codec; `args[0]` is the\n * `self` receiver.\n */\nfunction funcOp<C extends string>(\n method: string,\n fnName: string,\n returns: { readonly codecId: C; readonly nullable: false },\n args: readonly [AnyExpression, ...AnyExpression[]],\n): Expression<{ readonly codecId: C; readonly nullable: false }> {\n const placeholders = args.map((_, i) => (i === 0 ? \"{{self}}\" : `{{arg${i - 1}}}`)).join(\", \");\n return buildOperation({\n method,\n args,\n returns,\n lowering: {\n targetFamily: \"sql\",\n template: `${fnName}(${placeholders})`,\n },\n });\n}\n\nexport function ltreeQueryOperations<CT extends CodecTypesBase>(): QueryOperationTypes<CT> {\n // Hierarchy operators compare two `ltree` values; the user argument shares the\n // column's `pg/ltree@1` codec. Pattern-match operators take a query/pattern\n // string (or `string[]`) that is NOT an ltree — it is bound as text and cast\n // in-template to `lquery` / `lquery[]` / `ltxtquery` (the validated-string-param\n // approach; verified executable under PGlite).\n const hierarchyOp = (\n method: string,\n operator: string,\n self: CodecExpression<typeof LTREE_CODEC_ID, boolean, CT>,\n other: CodecExpression<typeof LTREE_CODEC_ID, boolean, CT>,\n ): BoolReturn => {\n const selfCodec = codecOf(self);\n return buildOperation({\n method,\n args: [toExpr(self, selfCodec), toExpr(other, selfCodec)],\n returns: BOOL_RETURN,\n lowering: {\n targetFamily: \"sql\",\n template: `{{self}} ${operator} {{arg0}}`,\n },\n });\n };\n\n const patternOp = (\n method: string,\n operator: string,\n castType: string,\n self: CodecExpression<typeof LTREE_CODEC_ID, boolean, CT>,\n arg: unknown,\n many = false,\n ): BoolReturn => {\n const selfCodec = codecOf(self);\n return buildOperation({\n method,\n args: [\n toExpr(self, selfCodec),\n toExpr(arg, many ? { codecId: TEXT_CODEC_ID, many: true } : { codecId: TEXT_CODEC_ID }),\n ],\n returns: BOOL_RETURN,\n lowering: {\n targetFamily: \"sql\",\n template: `{{self}} ${operator} ({{arg0}})::${castType}`,\n },\n });\n };\n\n // Concatenation operators produce a new ltree. `concat` joins two ltree paths\n // (`{{self}} || {{arg0}}`); `concatText`/`prependText` splice a text label onto\n // the right/left. The text operand binds as `pg/text@1` and is cast in-template\n // (PG resolves the `||` overload from the cast). `prependText` places `{{self}}`\n // second because the ltree receiver is the RIGHT operand of `text || ltree`;\n // `args[0]` is still `self` (the renderer binds by placeholder name, not order).\n const concatOp = (\n method: string,\n template: string,\n args: readonly [AnyExpression, ...AnyExpression[]],\n ): LtreeReturn =>\n buildOperation({\n method,\n args,\n returns: LTREE_RETURN,\n lowering: { targetFamily: \"sql\", template },\n });\n\n // Tier 3 — first-match operators on an `ltree[]` receiver (ADR-003).\n const firstMatchOp = (\n method: string,\n operator: string,\n self: CodecExpression<typeof LTREE_ARRAY_CODEC_ID, boolean, CT>,\n arg: unknown,\n argCodecId: typeof LTREE_CODEC_ID | typeof TEXT_CODEC_ID,\n castType?: string,\n ): LtreeReturn => {\n const selfCodec = codecOf(self);\n const template = castType\n ? `{{self}} ${operator} ({{arg0}})::${castType}`\n : `{{self}} ${operator} {{arg0}}`;\n return buildOperation({\n method,\n args: [toExpr(self, selfCodec), toExpr(arg, { codecId: argCodecId })],\n returns: LTREE_RETURN,\n lowering: { targetFamily: \"sql\", template },\n });\n };\n\n return {\n isAncestorOf: {\n self: { codecId: LTREE_CODEC_ID },\n impl: (self, other) => hierarchyOp(\"isAncestorOf\", \"@>\", self, other),\n },\n isDescendantOf: {\n self: { codecId: LTREE_CODEC_ID },\n impl: (self, other) => hierarchyOp(\"isDescendantOf\", \"<@\", self, other),\n },\n matchesLquery: {\n self: { codecId: LTREE_CODEC_ID },\n impl: (self, pattern) => patternOp(\"matchesLquery\", \"~\", \"lquery\", self, pattern),\n },\n matchesLqueryArray: {\n self: { codecId: LTREE_CODEC_ID },\n impl: (self, patterns) =>\n patternOp(\"matchesLqueryArray\", \"?\", \"lquery[]\", self, patterns, true),\n },\n matchesLtxtquery: {\n self: { codecId: LTREE_CODEC_ID },\n impl: (self, query) => patternOp(\"matchesLtxtquery\", \"@\", \"ltxtquery\", self, query),\n },\n nlevel: {\n self: { codecId: LTREE_CODEC_ID },\n impl: (self): IntReturn =>\n funcOp(\"nlevel\", \"nlevel\", INT_RETURN, [toExpr(self, codecOf(self))]),\n },\n subltree: {\n self: { codecId: LTREE_CODEC_ID },\n impl: (self, start, end): LtreeReturn =>\n funcOp(\"subltree\", \"subltree\", LTREE_RETURN, [\n toExpr(self, codecOf(self)),\n toExpr(start, { codecId: INT_CODEC_ID }),\n toExpr(end, { codecId: INT_CODEC_ID }),\n ]),\n },\n // `subpath(self, offset, len?)` — `len` omitted lowers to the 2-arg overload.\n subpath: {\n self: { codecId: LTREE_CODEC_ID },\n impl: (self, offset, len): LtreeReturn => {\n const head: readonly [AnyExpression, AnyExpression] = [\n toExpr(self, codecOf(self)),\n toExpr(offset, { codecId: INT_CODEC_ID }),\n ];\n return funcOp(\n \"subpath\",\n \"subpath\",\n LTREE_RETURN,\n len === undefined ? head : [...head, toExpr(len, { codecId: INT_CODEC_ID })],\n );\n },\n },\n // `index(self, other, offset?)` — `offset` omitted lowers to the 2-arg overload.\n indexOf: {\n self: { codecId: LTREE_CODEC_ID },\n impl: (self, other, offset): IntReturn => {\n const selfCodec = codecOf(self);\n const head: readonly [AnyExpression, AnyExpression] = [\n toExpr(self, selfCodec),\n toExpr(other, selfCodec),\n ];\n return funcOp(\n \"indexOf\",\n \"index\",\n INT_RETURN,\n offset === undefined ? head : [...head, toExpr(offset, { codecId: INT_CODEC_ID })],\n );\n },\n },\n // `lca(self, other, ...rest)` — variadic longest-common-ancestor (ADR-001).\n // PostgreSQL has no single-arg `lca`, so `other` is required (2–8 paths).\n lca: {\n self: { codecId: LTREE_CODEC_ID },\n impl: (self, other, ...rest): LtreeReturn => {\n const selfCodec = codecOf(self);\n return funcOp(\"lca\", \"lca\", LTREE_RETURN, [\n toExpr(self, selfCodec),\n toExpr(other, selfCodec),\n ...rest.map((p) => toExpr(p, selfCodec)),\n ]);\n },\n },\n // Tier 2 — concatenation (`||`).\n concat: {\n self: { codecId: LTREE_CODEC_ID },\n impl: (self, other): LtreeReturn => {\n const selfCodec = codecOf(self);\n return concatOp(\"concat\", \"{{self}} || {{arg0}}\", [\n toExpr(self, selfCodec),\n toExpr(other, selfCodec),\n ]);\n },\n },\n concatText: {\n self: { codecId: LTREE_CODEC_ID },\n impl: (self, label): LtreeReturn =>\n concatOp(\"concatText\", \"{{self}} || ({{arg0}})::text\", [\n toExpr(self, codecOf(self)),\n toExpr(label, { codecId: TEXT_CODEC_ID }),\n ]),\n },\n // `text || ltree` — the ltree receiver is the right operand (ADR-002).\n prependText: {\n self: { codecId: LTREE_CODEC_ID },\n impl: (self, prefix): LtreeReturn =>\n concatOp(\"prependText\", \"({{arg0}})::text || {{self}}\", [\n toExpr(self, codecOf(self)),\n toExpr(prefix, { codecId: TEXT_CODEC_ID }),\n ]),\n },\n // Tier 2 — conversion.\n toText: {\n self: { codecId: LTREE_CODEC_ID },\n impl: (self): TextReturn =>\n funcOp(\"toText\", \"ltree2text\", TEXT_RETURN, [toExpr(self, codecOf(self))]),\n },\n // `text2ltree(text)` — rooted on `pg/text@1` (the only reachable form of the\n // free-function `text2ltree`; see ADR-002). Surfaces as `.toLtree()` on text.\n toLtree: {\n self: { codecId: TEXT_CODEC_ID },\n impl: (self): LtreeReturn =>\n funcOp(\"toLtree\", \"text2ltree\", LTREE_RETURN, [toExpr(self, codecOf(self))]),\n },\n // Tier 3 — array first-match operators (ADR-003).\n firstAncestorOf: {\n self: { codecId: LTREE_ARRAY_CODEC_ID },\n impl: (self, other) => firstMatchOp(\"firstAncestorOf\", \"?@>\", self, other, LTREE_CODEC_ID),\n },\n firstDescendantOf: {\n self: { codecId: LTREE_ARRAY_CODEC_ID },\n impl: (self, other) => firstMatchOp(\"firstDescendantOf\", \"?<@\", self, other, LTREE_CODEC_ID),\n },\n firstMatchLquery: {\n self: { codecId: LTREE_ARRAY_CODEC_ID },\n impl: (self, pattern) =>\n firstMatchOp(\"firstMatchLquery\", \"?~\", self, pattern, TEXT_CODEC_ID, \"lquery\"),\n },\n firstMatchLtxtquery: {\n self: { codecId: LTREE_ARRAY_CODEC_ID },\n impl: (self, query) =>\n firstMatchOp(\"firstMatchLtxtquery\", \"?@\", self, query, TEXT_CODEC_ID, \"ltxtquery\"),\n },\n // `lca(ltree[])` — array-receiver form (ADR-001, ADR-005). Named `lcaAll`\n // because prisma-next keys operations by name only (`createOperationRegistry`\n // throws on a duplicate); `lca` is already the variadic scalar method on\n // `pg/ltree@1`. Declares `nullable: false` for parity with the Tier 3\n // first-match ops even though PG returns NULL for an empty/NULL `ltree[]`\n // (see the empty-array integration test) — a family-wide gap, not specific\n // to `lcaAll`.\n lcaAll: {\n self: { codecId: LTREE_ARRAY_CODEC_ID },\n impl: (self): LtreeReturn =>\n funcOp(\"lcaAll\", \"lca\", LTREE_RETURN, [toExpr(self, codecOf(self))]),\n },\n };\n}\n\nconst ltreePackMetaBase = {\n kind: \"extension\",\n id: \"ltree\",\n familyId: \"sql\",\n targetId: \"postgres\",\n version: \"0.1.0\",\n capabilities: {\n postgres: {\n \"ltree.path\": true,\n },\n },\n authoring: {\n type: ltreeAuthoringTypes,\n },\n dataTypes: ltreeDataTypes,\n types: {\n codecTypes: {\n codecDescriptors: Array.from(ltreeCodecRegistry.values()),\n import: {\n package: \"prisma-ltree/codec-types\",\n named: \"CodecTypes\",\n alias: \"LtreeTypes\",\n },\n typeImports: [\n {\n package: \"prisma-ltree/codec-types\",\n named: \"Ltree\",\n alias: \"Ltree\",\n },\n ],\n },\n queryOperationTypes: {\n import: {\n package: \"prisma-ltree/operation-types\",\n named: \"QueryOperationTypes\",\n alias: \"LtreeQueryOperationTypes\",\n },\n },\n },\n} as const;\n\nexport const ltreePackMeta: typeof ltreePackMetaBase & {\n readonly __codecTypes?: CodecTypes;\n} = ltreePackMetaBase;\n"],"mappings":";;;;;;;;AAGA,MAAa,sBAAsB,EACjC,OAAO;CACL,OAAO;EACL,MAAM;EACN,UAAU;EACV,QAAQ,EACN,SAAS,eACX;CACF;CACA,YAAY;EACV,MAAM;EACN,UAAU;EACV,QAAQ,EACN,SAAS,qBACX;CACF;AACF,EACF;;;ACPA,MAAa,gBAAgB,YAAY,eAAe;CACtD,OAAO,CAAC;EAAE,MAAM;EAAS,SAAS;EAAM,SAAS;CAAK,CAAC;CACvD,OAAO,GACJ,OAAO,MAAM,UAAU,MAC1B;AACF,CAAC;;;;;;AAOD,MAAM,qBAAqB,YAAY,qBAAqB,EAC1D,UAAU;CACR,IAAI,CAAC,OAAO,EAA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