@prisma-next/extension-paradedb 0.5.0-dev.85 → 0.5.0-dev.87
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/control.d.mts +14 -1
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +38 -2
- package/dist/control.mjs.map +1 -0
- package/dist/descriptor-meta-CmokJ02r.mjs +260 -0
- package/dist/descriptor-meta-CmokJ02r.mjs.map +1 -0
- package/dist/operation-types-DXmTJ7jd.d.mts +135 -0
- package/dist/operation-types-DXmTJ7jd.d.mts.map +1 -0
- package/dist/operation-types.d.mts +2 -0
- package/dist/operation-types.mjs +1 -0
- package/dist/pack.d.mts +9 -0
- package/dist/pack.mjs +1 -1
- package/dist/runtime.d.mts +7 -0
- package/dist/runtime.d.mts.map +1 -0
- package/dist/runtime.mjs +21 -0
- package/dist/runtime.mjs.map +1 -0
- package/package.json +16 -5
- package/src/core/descriptor-meta.ts +198 -0
- package/src/core/proximity-chain.ts +83 -0
- package/src/exports/control.ts +53 -2
- package/src/exports/operation-types.ts +1 -0
- package/src/exports/runtime.ts +20 -0
- package/src/types/operation-types.ts +84 -0
- package/dist/descriptor-meta-BF_fQseQ.mjs +0 -16
- package/dist/descriptor-meta-BF_fQseQ.mjs.map +0 -1
package/dist/control.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as _$_prisma_next_sql_contract_index_types0 from "@prisma-next/sql-contract/index-types";
|
|
2
|
+
import { SqlControlExtensionDescriptor } from "@prisma-next/family-sql/control";
|
|
2
3
|
|
|
3
4
|
//#region src/core/descriptor-meta.d.ts
|
|
4
5
|
declare const paradedbPackMeta: {
|
|
@@ -17,7 +18,19 @@ declare const paradedbPackMeta: {
|
|
|
17
18
|
key_field: string;
|
|
18
19
|
};
|
|
19
20
|
}>>;
|
|
21
|
+
readonly types: {
|
|
22
|
+
readonly queryOperationTypes: {
|
|
23
|
+
readonly import: {
|
|
24
|
+
readonly package: "@prisma-next/extension-paradedb/operation-types";
|
|
25
|
+
readonly named: "QueryOperationTypes";
|
|
26
|
+
readonly alias: "ParadeDbQueryOperationTypes";
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
20
30
|
};
|
|
21
31
|
//#endregion
|
|
22
|
-
|
|
32
|
+
//#region src/exports/control.d.ts
|
|
33
|
+
declare const paradedbExtensionDescriptor: SqlControlExtensionDescriptor<'postgres'>;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { paradedbExtensionDescriptor as default, paradedbExtensionDescriptor, paradedbPackMeta };
|
|
23
36
|
//# sourceMappingURL=control.d.mts.map
|
package/dist/control.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/descriptor-meta.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/descriptor-meta.ts","../src/exports/control.ts"],"mappings":";;;;cAgMa,gBAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;cCtJP,2BAAA,EAA6B,6BAAA"}
|
package/dist/control.mjs
CHANGED
|
@@ -1,2 +1,38 @@
|
|
|
1
|
-
import { t as paradedbPackMeta } from "./descriptor-meta-
|
|
2
|
-
|
|
1
|
+
import { n as paradedbQueryOperations, t as paradedbPackMeta } from "./descriptor-meta-CmokJ02r.mjs";
|
|
2
|
+
//#region src/exports/control.ts
|
|
3
|
+
const paradedbDatabaseDependencies = { init: [{
|
|
4
|
+
id: "postgres.extension.pg_search",
|
|
5
|
+
label: "Enable pg_search extension",
|
|
6
|
+
install: [{
|
|
7
|
+
id: "extension.pg_search",
|
|
8
|
+
label: "Enable extension \"pg_search\"",
|
|
9
|
+
summary: "Ensures the pg_search extension is available for ParadeDB BM25 operations",
|
|
10
|
+
operationClass: "additive",
|
|
11
|
+
target: { id: "postgres" },
|
|
12
|
+
precheck: [{
|
|
13
|
+
description: "verify extension \"pg_search\" is not already enabled",
|
|
14
|
+
sql: "SELECT NOT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'pg_search')"
|
|
15
|
+
}],
|
|
16
|
+
execute: [{
|
|
17
|
+
description: "create extension \"pg_search\"",
|
|
18
|
+
sql: "CREATE EXTENSION IF NOT EXISTS pg_search"
|
|
19
|
+
}],
|
|
20
|
+
postcheck: [{
|
|
21
|
+
description: "confirm extension \"pg_search\" is enabled",
|
|
22
|
+
sql: "SELECT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'pg_search')"
|
|
23
|
+
}]
|
|
24
|
+
}]
|
|
25
|
+
}] };
|
|
26
|
+
const paradedbExtensionDescriptor = {
|
|
27
|
+
...paradedbPackMeta,
|
|
28
|
+
queryOperations: () => paradedbQueryOperations(),
|
|
29
|
+
databaseDependencies: paradedbDatabaseDependencies,
|
|
30
|
+
create: () => ({
|
|
31
|
+
familyId: "sql",
|
|
32
|
+
targetId: "postgres"
|
|
33
|
+
})
|
|
34
|
+
};
|
|
35
|
+
//#endregion
|
|
36
|
+
export { paradedbExtensionDescriptor as default, paradedbExtensionDescriptor, paradedbPackMeta };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=control.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control.mjs","names":[],"sources":["../src/exports/control.ts"],"sourcesContent":["import type {\n ComponentDatabaseDependencies,\n SqlControlExtensionDescriptor,\n} from '@prisma-next/family-sql/control';\nimport { paradedbPackMeta, paradedbQueryOperations } from '../core/descriptor-meta';\n\nconst paradedbDatabaseDependencies: ComponentDatabaseDependencies<unknown> = {\n init: [\n {\n id: 'postgres.extension.pg_search',\n label: 'Enable pg_search extension',\n install: [\n {\n id: 'extension.pg_search',\n label: 'Enable extension \"pg_search\"',\n summary: 'Ensures the pg_search extension is available for ParadeDB BM25 operations',\n operationClass: 'additive',\n target: { id: 'postgres' },\n precheck: [\n {\n description: 'verify extension \"pg_search\" is not already enabled',\n sql: \"SELECT NOT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'pg_search')\",\n },\n ],\n execute: [\n {\n description: 'create extension \"pg_search\"',\n sql: 'CREATE EXTENSION IF NOT EXISTS pg_search',\n },\n ],\n postcheck: [\n {\n description: 'confirm extension \"pg_search\" is enabled',\n sql: \"SELECT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'pg_search')\",\n },\n ],\n },\n ],\n },\n ],\n};\n\nconst paradedbExtensionDescriptor: SqlControlExtensionDescriptor<'postgres'> = {\n ...paradedbPackMeta,\n queryOperations: () => paradedbQueryOperations(),\n databaseDependencies: paradedbDatabaseDependencies,\n create: () => ({\n familyId: 'sql' as const,\n targetId: 'postgres' as const,\n }),\n};\n\nexport { paradedbExtensionDescriptor, paradedbPackMeta };\nexport default paradedbExtensionDescriptor;\n"],"mappings":";;AAMA,MAAM,+BAAuE,EAC3E,MAAM,CACJ;CACE,IAAI;CACJ,OAAO;CACP,SAAS,CACP;EACE,IAAI;EACJ,OAAO;EACP,SAAS;EACT,gBAAgB;EAChB,QAAQ,EAAE,IAAI,YAAY;EAC1B,UAAU,CACR;GACE,aAAa;GACb,KAAK;GACN,CACF;EACD,SAAS,CACP;GACE,aAAa;GACb,KAAK;GACN,CACF;EACD,WAAW,CACT;GACE,aAAa;GACb,KAAK;GACN,CACF;EACF,CACF;CACF,CACF,EACF;AAED,MAAM,8BAAyE;CAC7E,GAAG;CACH,uBAAuB,yBAAyB;CAChD,sBAAsB;CACtB,eAAe;EACb,UAAU;EACV,UAAU;EACX;CACF"}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { t as paradedbIndexTypes } from "./index-types-BWFfNqUb.mjs";
|
|
2
|
+
import { LiteralExpr, OperationExpr } from "@prisma-next/sql-relational-core/ast";
|
|
3
|
+
import { buildOperation, toExpr } from "@prisma-next/sql-relational-core/expression";
|
|
4
|
+
//#region src/core/constants.ts
|
|
5
|
+
/**
|
|
6
|
+
* Extension ID for ParadeDB pg_search.
|
|
7
|
+
*/
|
|
8
|
+
const PARADEDB_EXTENSION_ID = "paradedb";
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/core/proximity-chain.ts
|
|
11
|
+
const TEXT$1 = "pg/text@1";
|
|
12
|
+
var ParadeDbProximityChain = class ParadeDbProximityChain {
|
|
13
|
+
returnType = {
|
|
14
|
+
codecId: TEXT$1,
|
|
15
|
+
nullable: false
|
|
16
|
+
};
|
|
17
|
+
start;
|
|
18
|
+
steps;
|
|
19
|
+
constructor(start, steps = []) {
|
|
20
|
+
this.start = start;
|
|
21
|
+
this.steps = steps;
|
|
22
|
+
}
|
|
23
|
+
within(distance, term, options) {
|
|
24
|
+
if (!Number.isInteger(distance) || distance < 0) throw new Error(`paradeDbProximity.within: distance must be a non-negative integer; got ${String(distance)}`);
|
|
25
|
+
return new ParadeDbProximityChain(this.start, [...this.steps, {
|
|
26
|
+
distance,
|
|
27
|
+
term,
|
|
28
|
+
ordered: options?.ordered === true
|
|
29
|
+
}]);
|
|
30
|
+
}
|
|
31
|
+
buildAst() {
|
|
32
|
+
if (this.steps.length === 0) throw new Error("paradeDbProximity: chain must have at least one .within(distance, term) step");
|
|
33
|
+
const args = [toExpr(this.start, TEXT$1)];
|
|
34
|
+
let template = "({{self}}";
|
|
35
|
+
this.steps.forEach((step, i) => {
|
|
36
|
+
const op = step.ordered ? "##>" : "##";
|
|
37
|
+
args.push(LiteralExpr.of(step.distance));
|
|
38
|
+
args.push(toExpr(step.term, TEXT$1));
|
|
39
|
+
template += ` ${op} {{arg${2 * i}}} ${op} {{arg${2 * i + 1}}}`;
|
|
40
|
+
});
|
|
41
|
+
template += ")";
|
|
42
|
+
const [self, ...rest] = args;
|
|
43
|
+
if (!self) throw new Error("paradeDbProximity: invariant violation — empty args");
|
|
44
|
+
return new OperationExpr({
|
|
45
|
+
method: "paradeDbProximity",
|
|
46
|
+
self,
|
|
47
|
+
args: rest.length > 0 ? rest : void 0,
|
|
48
|
+
returns: this.returnType,
|
|
49
|
+
lowering: {
|
|
50
|
+
targetFamily: "sql",
|
|
51
|
+
strategy: "function",
|
|
52
|
+
template
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/core/descriptor-meta.ts
|
|
59
|
+
const TEXT = "pg/text@1";
|
|
60
|
+
const BOOL = "pg/bool@1";
|
|
61
|
+
const FLOAT4 = "pg/float4@1";
|
|
62
|
+
const INT4 = "pg/int4@1";
|
|
63
|
+
function paradedbQueryOperations() {
|
|
64
|
+
return {
|
|
65
|
+
paradeDbMatch: {
|
|
66
|
+
self: { codecId: TEXT },
|
|
67
|
+
impl: (self, query) => buildOperation({
|
|
68
|
+
method: "paradeDbMatch",
|
|
69
|
+
args: [toExpr(self, TEXT), toExpr(query, TEXT)],
|
|
70
|
+
returns: {
|
|
71
|
+
codecId: BOOL,
|
|
72
|
+
nullable: false
|
|
73
|
+
},
|
|
74
|
+
lowering: {
|
|
75
|
+
targetFamily: "sql",
|
|
76
|
+
strategy: "function",
|
|
77
|
+
template: "{{self}} @@@ {{arg0}}"
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
},
|
|
81
|
+
paradeDbMatchAny: {
|
|
82
|
+
self: { codecId: TEXT },
|
|
83
|
+
impl: (self, query) => buildOperation({
|
|
84
|
+
method: "paradeDbMatchAny",
|
|
85
|
+
args: [toExpr(self, TEXT), toExpr(query, TEXT)],
|
|
86
|
+
returns: {
|
|
87
|
+
codecId: BOOL,
|
|
88
|
+
nullable: false
|
|
89
|
+
},
|
|
90
|
+
lowering: {
|
|
91
|
+
targetFamily: "sql",
|
|
92
|
+
strategy: "function",
|
|
93
|
+
template: "{{self}} ||| {{arg0}}"
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
},
|
|
97
|
+
paradeDbMatchAll: {
|
|
98
|
+
self: { codecId: TEXT },
|
|
99
|
+
impl: (self, query) => buildOperation({
|
|
100
|
+
method: "paradeDbMatchAll",
|
|
101
|
+
args: [toExpr(self, TEXT), toExpr(query, TEXT)],
|
|
102
|
+
returns: {
|
|
103
|
+
codecId: BOOL,
|
|
104
|
+
nullable: false
|
|
105
|
+
},
|
|
106
|
+
lowering: {
|
|
107
|
+
targetFamily: "sql",
|
|
108
|
+
strategy: "function",
|
|
109
|
+
template: "{{self}} &&& {{arg0}}"
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
},
|
|
113
|
+
paradeDbTerm: {
|
|
114
|
+
self: { codecId: TEXT },
|
|
115
|
+
impl: (self, query) => buildOperation({
|
|
116
|
+
method: "paradeDbTerm",
|
|
117
|
+
args: [toExpr(self, TEXT), toExpr(query, TEXT)],
|
|
118
|
+
returns: {
|
|
119
|
+
codecId: BOOL,
|
|
120
|
+
nullable: false
|
|
121
|
+
},
|
|
122
|
+
lowering: {
|
|
123
|
+
targetFamily: "sql",
|
|
124
|
+
strategy: "function",
|
|
125
|
+
template: "{{self}} === {{arg0}}"
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
},
|
|
129
|
+
paradeDbPhrase: {
|
|
130
|
+
self: { codecId: TEXT },
|
|
131
|
+
impl: (self, query) => buildOperation({
|
|
132
|
+
method: "paradeDbPhrase",
|
|
133
|
+
args: [toExpr(self, TEXT), toExpr(query, TEXT)],
|
|
134
|
+
returns: {
|
|
135
|
+
codecId: BOOL,
|
|
136
|
+
nullable: false
|
|
137
|
+
},
|
|
138
|
+
lowering: {
|
|
139
|
+
targetFamily: "sql",
|
|
140
|
+
strategy: "function",
|
|
141
|
+
template: "{{self}} ### {{arg0}}"
|
|
142
|
+
}
|
|
143
|
+
})
|
|
144
|
+
},
|
|
145
|
+
paradeDbScore: {
|
|
146
|
+
self: { codecId: INT4 },
|
|
147
|
+
impl: (self) => buildOperation({
|
|
148
|
+
method: "paradeDbScore",
|
|
149
|
+
args: [toExpr(self, INT4)],
|
|
150
|
+
returns: {
|
|
151
|
+
codecId: FLOAT4,
|
|
152
|
+
nullable: false
|
|
153
|
+
},
|
|
154
|
+
lowering: {
|
|
155
|
+
targetFamily: "sql",
|
|
156
|
+
strategy: "function",
|
|
157
|
+
template: "pdb.score({{self}})"
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
},
|
|
161
|
+
paradeDbFuzzy: {
|
|
162
|
+
self: { codecId: TEXT },
|
|
163
|
+
impl: (self, distance) => {
|
|
164
|
+
if (!Number.isInteger(distance) || distance < 0 || distance > 2) throw new Error(`paradeDbFuzzy: distance must be an integer in [0, 2]; got ${String(distance)}`);
|
|
165
|
+
return buildOperation({
|
|
166
|
+
method: "paradeDbFuzzy",
|
|
167
|
+
args: [toExpr(self, TEXT), LiteralExpr.of(distance)],
|
|
168
|
+
returns: {
|
|
169
|
+
codecId: TEXT,
|
|
170
|
+
nullable: false
|
|
171
|
+
},
|
|
172
|
+
lowering: {
|
|
173
|
+
targetFamily: "sql",
|
|
174
|
+
strategy: "function",
|
|
175
|
+
template: "{{self}}::pdb.fuzzy({{arg0}})"
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
paradeDbBoost: {
|
|
181
|
+
self: { codecId: TEXT },
|
|
182
|
+
impl: (self, weight) => {
|
|
183
|
+
if (!Number.isInteger(weight) || weight < -2048 || weight > 2048) throw new Error(`paradeDbBoost: boost must be an integer in [-2048, 2048]; got ${String(weight)}`);
|
|
184
|
+
return buildOperation({
|
|
185
|
+
method: "paradeDbBoost",
|
|
186
|
+
args: [toExpr(self, TEXT), LiteralExpr.of(weight)],
|
|
187
|
+
returns: {
|
|
188
|
+
codecId: TEXT,
|
|
189
|
+
nullable: false
|
|
190
|
+
},
|
|
191
|
+
lowering: {
|
|
192
|
+
targetFamily: "sql",
|
|
193
|
+
strategy: "function",
|
|
194
|
+
template: "{{self}}::pdb.boost({{arg0}})"
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
paradeDbConst: {
|
|
200
|
+
self: { codecId: TEXT },
|
|
201
|
+
impl: (self, value) => {
|
|
202
|
+
if (!Number.isInteger(value)) throw new Error(`paradeDbConst: value must be an integer; got ${String(value)}`);
|
|
203
|
+
return buildOperation({
|
|
204
|
+
method: "paradeDbConst",
|
|
205
|
+
args: [toExpr(self, TEXT), LiteralExpr.of(value)],
|
|
206
|
+
returns: {
|
|
207
|
+
codecId: TEXT,
|
|
208
|
+
nullable: false
|
|
209
|
+
},
|
|
210
|
+
lowering: {
|
|
211
|
+
targetFamily: "sql",
|
|
212
|
+
strategy: "function",
|
|
213
|
+
template: "{{self}}::pdb.const({{arg0}})"
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
paradeDbSlop: {
|
|
219
|
+
self: { codecId: TEXT },
|
|
220
|
+
impl: (self, slop) => {
|
|
221
|
+
if (!Number.isInteger(slop) || slop < 0) throw new Error(`paradeDbSlop: slop must be a non-negative integer; got ${String(slop)}`);
|
|
222
|
+
return buildOperation({
|
|
223
|
+
method: "paradeDbSlop",
|
|
224
|
+
args: [toExpr(self, TEXT), LiteralExpr.of(slop)],
|
|
225
|
+
returns: {
|
|
226
|
+
codecId: TEXT,
|
|
227
|
+
nullable: false
|
|
228
|
+
},
|
|
229
|
+
lowering: {
|
|
230
|
+
targetFamily: "sql",
|
|
231
|
+
strategy: "function",
|
|
232
|
+
template: "{{self}}::pdb.slop({{arg0}})"
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
paradeDbProximity: {
|
|
238
|
+
self: { codecId: TEXT },
|
|
239
|
+
impl: (start) => new ParadeDbProximityChain(start)
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
const paradedbPackMeta = {
|
|
244
|
+
kind: "extension",
|
|
245
|
+
id: PARADEDB_EXTENSION_ID,
|
|
246
|
+
familyId: "sql",
|
|
247
|
+
targetId: "postgres",
|
|
248
|
+
version: "0.0.1",
|
|
249
|
+
capabilities: { postgres: { "paradedb/bm25": true } },
|
|
250
|
+
indexTypes: paradedbIndexTypes,
|
|
251
|
+
types: { queryOperationTypes: { import: {
|
|
252
|
+
package: "@prisma-next/extension-paradedb/operation-types",
|
|
253
|
+
named: "QueryOperationTypes",
|
|
254
|
+
alias: "ParadeDbQueryOperationTypes"
|
|
255
|
+
} } }
|
|
256
|
+
};
|
|
257
|
+
//#endregion
|
|
258
|
+
export { paradedbQueryOperations as n, paradedbPackMeta as t };
|
|
259
|
+
|
|
260
|
+
//# sourceMappingURL=descriptor-meta-CmokJ02r.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"descriptor-meta-CmokJ02r.mjs","names":["TEXT"],"sources":["../src/core/constants.ts","../src/core/proximity-chain.ts","../src/core/descriptor-meta.ts"],"sourcesContent":["/**\n * Extension ID for ParadeDB pg_search.\n */\nexport const PARADEDB_EXTENSION_ID = 'paradedb' as const;\n","import {\n type AnyExpression,\n LiteralExpr,\n OperationExpr,\n} from '@prisma-next/sql-relational-core/ast';\nimport { type Expression, toExpr } from '@prisma-next/sql-relational-core/expression';\n\nconst TEXT = 'pg/text@1' as const;\n\nexport type ProximityTerm = unknown;\n\nexport interface ProximityWithinOptions {\n readonly ordered?: boolean;\n}\n\ninterface ProximityStep {\n readonly distance: number;\n readonly term: ProximityTerm;\n readonly ordered: boolean;\n}\n\n// https://docs.paradedb.com/documentation/full-text/proximity\nexport class ParadeDbProximityChain\n implements Expression<{ codecId: 'pg/text@1'; nullable: false }>\n{\n readonly returnType = { codecId: TEXT, nullable: false } as const;\n\n private readonly start: ProximityTerm;\n private readonly steps: readonly ProximityStep[];\n\n constructor(start: ProximityTerm, steps: readonly ProximityStep[] = []) {\n this.start = start;\n this.steps = steps;\n }\n\n within(\n distance: number,\n term: ProximityTerm,\n options?: ProximityWithinOptions,\n ): ParadeDbProximityChain {\n if (!Number.isInteger(distance) || distance < 0) {\n throw new Error(\n `paradeDbProximity.within: distance must be a non-negative integer; got ${String(distance)}`,\n );\n }\n return new ParadeDbProximityChain(this.start, [\n ...this.steps,\n { distance, term, ordered: options?.ordered === true },\n ]);\n }\n\n buildAst(): AnyExpression {\n if (this.steps.length === 0) {\n throw new Error(\n 'paradeDbProximity: chain must have at least one .within(distance, term) step',\n );\n }\n const args: AnyExpression[] = [toExpr(this.start, TEXT)];\n let template = '({{self}}';\n this.steps.forEach((step, i) => {\n const op = step.ordered ? '##>' : '##';\n args.push(LiteralExpr.of(step.distance));\n args.push(toExpr(step.term, TEXT));\n template += ` ${op} {{arg${2 * i}}} ${op} {{arg${2 * i + 1}}}`;\n });\n template += ')';\n const [self, ...rest] = args;\n if (!self) {\n throw new Error('paradeDbProximity: invariant violation — empty args');\n }\n return new OperationExpr({\n method: 'paradeDbProximity',\n self,\n args: rest.length > 0 ? rest : undefined,\n returns: this.returnType,\n lowering: {\n targetFamily: 'sql',\n strategy: 'function',\n template,\n },\n });\n }\n}\n","import { LiteralExpr } from '@prisma-next/sql-relational-core/ast';\nimport { buildOperation, toExpr } from '@prisma-next/sql-relational-core/expression';\nimport { paradedbIndexTypes } from '../types/index-types';\nimport type { QueryOperationTypes } from '../types/operation-types';\nimport { PARADEDB_EXTENSION_ID } from './constants';\nimport { ParadeDbProximityChain } from './proximity-chain';\n\ntype CodecTypesBase = Record<string, { readonly input: unknown; readonly output: unknown }>;\n\nconst TEXT = 'pg/text@1' as const;\nconst BOOL = 'pg/bool@1' as const;\nconst FLOAT4 = 'pg/float4@1' as const;\nconst INT4 = 'pg/int4@1' as const;\n\nexport function paradedbQueryOperations<CT extends CodecTypesBase>(): QueryOperationTypes<CT> {\n return {\n // `@@@` accepts both text and structured query types on its RHS.\n // https://docs.paradedb.com/documentation/full-text/match\n paradeDbMatch: {\n self: { codecId: TEXT },\n impl: (self, query) =>\n buildOperation({\n method: 'paradeDbMatch',\n args: [toExpr(self, TEXT), toExpr(query, TEXT)],\n returns: { codecId: BOOL, nullable: false },\n lowering: {\n targetFamily: 'sql',\n strategy: 'function',\n template: '{{self}} @@@ {{arg0}}',\n },\n }),\n },\n paradeDbMatchAny: {\n self: { codecId: TEXT },\n impl: (self, query) =>\n buildOperation({\n method: 'paradeDbMatchAny',\n args: [toExpr(self, TEXT), toExpr(query, TEXT)],\n returns: { codecId: BOOL, nullable: false },\n lowering: {\n targetFamily: 'sql',\n strategy: 'function',\n template: '{{self}} ||| {{arg0}}',\n },\n }),\n },\n paradeDbMatchAll: {\n self: { codecId: TEXT },\n impl: (self, query) =>\n buildOperation({\n method: 'paradeDbMatchAll',\n args: [toExpr(self, TEXT), toExpr(query, TEXT)],\n returns: { codecId: BOOL, nullable: false },\n lowering: {\n targetFamily: 'sql',\n strategy: 'function',\n template: '{{self}} &&& {{arg0}}',\n },\n }),\n },\n // https://docs.paradedb.com/documentation/full-text/term\n paradeDbTerm: {\n self: { codecId: TEXT },\n impl: (self, query) =>\n buildOperation({\n method: 'paradeDbTerm',\n args: [toExpr(self, TEXT), toExpr(query, TEXT)],\n returns: { codecId: BOOL, nullable: false },\n lowering: {\n targetFamily: 'sql',\n strategy: 'function',\n template: '{{self}} === {{arg0}}',\n },\n }),\n },\n // https://docs.paradedb.com/documentation/full-text/phrase\n paradeDbPhrase: {\n self: { codecId: TEXT },\n impl: (self, query) =>\n buildOperation({\n method: 'paradeDbPhrase',\n args: [toExpr(self, TEXT), toExpr(query, TEXT)],\n returns: { codecId: BOOL, nullable: false },\n lowering: {\n targetFamily: 'sql',\n strategy: 'function',\n template: '{{self}} ### {{arg0}}',\n },\n }),\n },\n // https://docs.paradedb.com/documentation/sorting/score\n paradeDbScore: {\n self: { codecId: INT4 },\n impl: (self) =>\n buildOperation({\n method: 'paradeDbScore',\n args: [toExpr(self, INT4)],\n returns: { codecId: FLOAT4, nullable: false },\n lowering: {\n targetFamily: 'sql',\n strategy: 'function',\n template: 'pdb.score({{self}})',\n },\n }),\n },\n // PG rejects parameterized typmods, so the cast argument lowers to a literal.\n // https://docs.paradedb.com/documentation/full-text/fuzzy\n paradeDbFuzzy: {\n self: { codecId: TEXT },\n impl: (self, distance) => {\n if (!Number.isInteger(distance) || distance < 0 || distance > 2) {\n throw new Error(\n `paradeDbFuzzy: distance must be an integer in [0, 2]; got ${String(distance)}`,\n );\n }\n return buildOperation({\n method: 'paradeDbFuzzy',\n args: [toExpr(self, TEXT), LiteralExpr.of(distance)],\n returns: { codecId: TEXT, nullable: false },\n lowering: {\n targetFamily: 'sql',\n strategy: 'function',\n template: '{{self}}::pdb.fuzzy({{arg0}})',\n },\n });\n },\n },\n // https://docs.paradedb.com/documentation/sorting/boost\n paradeDbBoost: {\n self: { codecId: TEXT },\n impl: (self, weight) => {\n if (!Number.isInteger(weight) || weight < -2048 || weight > 2048) {\n throw new Error(\n `paradeDbBoost: boost must be an integer in [-2048, 2048]; got ${String(weight)}`,\n );\n }\n return buildOperation({\n method: 'paradeDbBoost',\n args: [toExpr(self, TEXT), LiteralExpr.of(weight)],\n returns: { codecId: TEXT, nullable: false },\n lowering: {\n targetFamily: 'sql',\n strategy: 'function',\n template: '{{self}}::pdb.boost({{arg0}})',\n },\n });\n },\n },\n paradeDbConst: {\n self: { codecId: TEXT },\n impl: (self, value) => {\n if (!Number.isInteger(value)) {\n throw new Error(`paradeDbConst: value must be an integer; got ${String(value)}`);\n }\n return buildOperation({\n method: 'paradeDbConst',\n args: [toExpr(self, TEXT), LiteralExpr.of(value)],\n returns: { codecId: TEXT, nullable: false },\n lowering: {\n targetFamily: 'sql',\n strategy: 'function',\n template: '{{self}}::pdb.const({{arg0}})',\n },\n });\n },\n },\n paradeDbSlop: {\n self: { codecId: TEXT },\n impl: (self, slop) => {\n if (!Number.isInteger(slop) || slop < 0) {\n throw new Error(`paradeDbSlop: slop must be a non-negative integer; got ${String(slop)}`);\n }\n return buildOperation({\n method: 'paradeDbSlop',\n args: [toExpr(self, TEXT), LiteralExpr.of(slop)],\n returns: { codecId: TEXT, nullable: false },\n lowering: {\n targetFamily: 'sql',\n strategy: 'function',\n template: '{{self}}::pdb.slop({{arg0}})',\n },\n });\n },\n },\n // https://docs.paradedb.com/documentation/full-text/proximity\n paradeDbProximity: {\n self: { codecId: TEXT },\n impl: (start) => new ParadeDbProximityChain(start),\n },\n };\n}\n\nexport const paradedbPackMeta = {\n kind: 'extension',\n id: PARADEDB_EXTENSION_ID,\n familyId: 'sql',\n targetId: 'postgres',\n version: '0.0.1',\n capabilities: {\n postgres: {\n 'paradedb/bm25': true,\n },\n },\n indexTypes: paradedbIndexTypes,\n types: {\n queryOperationTypes: {\n import: {\n package: '@prisma-next/extension-paradedb/operation-types',\n named: 'QueryOperationTypes',\n alias: 'ParadeDbQueryOperationTypes',\n },\n },\n },\n} as const;\n"],"mappings":";;;;;;;AAGA,MAAa,wBAAwB;;;ACIrC,MAAMA,SAAO;AAeb,IAAa,yBAAb,MAAa,uBAEb;CACE,aAAsB;EAAE,SAASA;EAAM,UAAU;EAAO;CAExD;CACA;CAEA,YAAY,OAAsB,QAAkC,EAAE,EAAE;EACtE,KAAK,QAAQ;EACb,KAAK,QAAQ;;CAGf,OACE,UACA,MACA,SACwB;EACxB,IAAI,CAAC,OAAO,UAAU,SAAS,IAAI,WAAW,GAC5C,MAAM,IAAI,MACR,0EAA0E,OAAO,SAAS,GAC3F;EAEH,OAAO,IAAI,uBAAuB,KAAK,OAAO,CAC5C,GAAG,KAAK,OACR;GAAE;GAAU;GAAM,SAAS,SAAS,YAAY;GAAM,CACvD,CAAC;;CAGJ,WAA0B;EACxB,IAAI,KAAK,MAAM,WAAW,GACxB,MAAM,IAAI,MACR,+EACD;EAEH,MAAM,OAAwB,CAAC,OAAO,KAAK,OAAOA,OAAK,CAAC;EACxD,IAAI,WAAW;EACf,KAAK,MAAM,SAAS,MAAM,MAAM;GAC9B,MAAM,KAAK,KAAK,UAAU,QAAQ;GAClC,KAAK,KAAK,YAAY,GAAG,KAAK,SAAS,CAAC;GACxC,KAAK,KAAK,OAAO,KAAK,MAAMA,OAAK,CAAC;GAClC,YAAY,IAA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B,EACnB,QAAQ;EACN,SAAS;EACT,OAAO;EACP,OAAO;EACR,EACF,EACF;CACF"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { AnyExpression } from "@prisma-next/sql-relational-core/ast";
|
|
2
|
+
import { CodecExpression, Expression } from "@prisma-next/sql-relational-core/expression";
|
|
3
|
+
import { SqlQueryOperationTypes } from "@prisma-next/sql-contract/types";
|
|
4
|
+
|
|
5
|
+
//#region src/core/proximity-chain.d.ts
|
|
6
|
+
type ProximityTerm = unknown;
|
|
7
|
+
interface ProximityWithinOptions {
|
|
8
|
+
readonly ordered?: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface ProximityStep {
|
|
11
|
+
readonly distance: number;
|
|
12
|
+
readonly term: ProximityTerm;
|
|
13
|
+
readonly ordered: boolean;
|
|
14
|
+
}
|
|
15
|
+
declare class ParadeDbProximityChain implements Expression<{
|
|
16
|
+
codecId: 'pg/text@1';
|
|
17
|
+
nullable: false;
|
|
18
|
+
}> {
|
|
19
|
+
readonly returnType: {
|
|
20
|
+
readonly codecId: "pg/text@1";
|
|
21
|
+
readonly nullable: false;
|
|
22
|
+
};
|
|
23
|
+
private readonly start;
|
|
24
|
+
private readonly steps;
|
|
25
|
+
constructor(start: ProximityTerm, steps?: readonly ProximityStep[]);
|
|
26
|
+
within(distance: number, term: ProximityTerm, options?: ProximityWithinOptions): ParadeDbProximityChain;
|
|
27
|
+
buildAst(): AnyExpression;
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/types/operation-types.d.ts
|
|
31
|
+
type CodecTypesBase = Record<string, {
|
|
32
|
+
readonly input: unknown;
|
|
33
|
+
readonly output: unknown;
|
|
34
|
+
}>;
|
|
35
|
+
type QueryOperationTypes<CT extends CodecTypesBase> = SqlQueryOperationTypes<CT, {
|
|
36
|
+
readonly paradeDbMatch: {
|
|
37
|
+
readonly self: {
|
|
38
|
+
readonly codecId: 'pg/text@1';
|
|
39
|
+
};
|
|
40
|
+
readonly impl: (self: CodecExpression<'pg/text@1', boolean, CT>, query: CodecExpression<'pg/text@1', boolean, CT>) => Expression<{
|
|
41
|
+
codecId: 'pg/bool@1';
|
|
42
|
+
nullable: false;
|
|
43
|
+
}>;
|
|
44
|
+
};
|
|
45
|
+
readonly paradeDbMatchAny: {
|
|
46
|
+
readonly self: {
|
|
47
|
+
readonly codecId: 'pg/text@1';
|
|
48
|
+
};
|
|
49
|
+
readonly impl: (self: CodecExpression<'pg/text@1', boolean, CT>, query: CodecExpression<'pg/text@1', boolean, CT>) => Expression<{
|
|
50
|
+
codecId: 'pg/bool@1';
|
|
51
|
+
nullable: false;
|
|
52
|
+
}>;
|
|
53
|
+
};
|
|
54
|
+
readonly paradeDbMatchAll: {
|
|
55
|
+
readonly self: {
|
|
56
|
+
readonly codecId: 'pg/text@1';
|
|
57
|
+
};
|
|
58
|
+
readonly impl: (self: CodecExpression<'pg/text@1', boolean, CT>, query: CodecExpression<'pg/text@1', boolean, CT>) => Expression<{
|
|
59
|
+
codecId: 'pg/bool@1';
|
|
60
|
+
nullable: false;
|
|
61
|
+
}>;
|
|
62
|
+
};
|
|
63
|
+
readonly paradeDbTerm: {
|
|
64
|
+
readonly self: {
|
|
65
|
+
readonly codecId: 'pg/text@1';
|
|
66
|
+
};
|
|
67
|
+
readonly impl: (self: CodecExpression<'pg/text@1', boolean, CT>, query: CodecExpression<'pg/text@1', boolean, CT>) => Expression<{
|
|
68
|
+
codecId: 'pg/bool@1';
|
|
69
|
+
nullable: false;
|
|
70
|
+
}>;
|
|
71
|
+
};
|
|
72
|
+
readonly paradeDbPhrase: {
|
|
73
|
+
readonly self: {
|
|
74
|
+
readonly codecId: 'pg/text@1';
|
|
75
|
+
};
|
|
76
|
+
readonly impl: (self: CodecExpression<'pg/text@1', boolean, CT>, query: CodecExpression<'pg/text@1', boolean, CT>) => Expression<{
|
|
77
|
+
codecId: 'pg/bool@1';
|
|
78
|
+
nullable: false;
|
|
79
|
+
}>;
|
|
80
|
+
};
|
|
81
|
+
readonly paradeDbScore: {
|
|
82
|
+
readonly self: {
|
|
83
|
+
readonly codecId: 'pg/int4@1';
|
|
84
|
+
};
|
|
85
|
+
readonly impl: (self: CodecExpression<'pg/int4@1', boolean, CT>) => Expression<{
|
|
86
|
+
codecId: 'pg/float4@1';
|
|
87
|
+
nullable: false;
|
|
88
|
+
}>;
|
|
89
|
+
};
|
|
90
|
+
readonly paradeDbFuzzy: {
|
|
91
|
+
readonly self: {
|
|
92
|
+
readonly codecId: 'pg/text@1';
|
|
93
|
+
};
|
|
94
|
+
readonly impl: (self: CodecExpression<'pg/text@1', boolean, CT>, distance: number) => Expression<{
|
|
95
|
+
codecId: 'pg/text@1';
|
|
96
|
+
nullable: false;
|
|
97
|
+
}>;
|
|
98
|
+
};
|
|
99
|
+
readonly paradeDbBoost: {
|
|
100
|
+
readonly self: {
|
|
101
|
+
readonly codecId: 'pg/text@1';
|
|
102
|
+
};
|
|
103
|
+
readonly impl: (self: CodecExpression<'pg/text@1', boolean, CT>, weight: number) => Expression<{
|
|
104
|
+
codecId: 'pg/text@1';
|
|
105
|
+
nullable: false;
|
|
106
|
+
}>;
|
|
107
|
+
};
|
|
108
|
+
readonly paradeDbConst: {
|
|
109
|
+
readonly self: {
|
|
110
|
+
readonly codecId: 'pg/text@1';
|
|
111
|
+
};
|
|
112
|
+
readonly impl: (self: CodecExpression<'pg/text@1', boolean, CT>, value: number) => Expression<{
|
|
113
|
+
codecId: 'pg/text@1';
|
|
114
|
+
nullable: false;
|
|
115
|
+
}>;
|
|
116
|
+
};
|
|
117
|
+
readonly paradeDbSlop: {
|
|
118
|
+
readonly self: {
|
|
119
|
+
readonly codecId: 'pg/text@1';
|
|
120
|
+
};
|
|
121
|
+
readonly impl: (self: CodecExpression<'pg/text@1', boolean, CT>, slop: number) => Expression<{
|
|
122
|
+
codecId: 'pg/text@1';
|
|
123
|
+
nullable: false;
|
|
124
|
+
}>;
|
|
125
|
+
};
|
|
126
|
+
readonly paradeDbProximity: {
|
|
127
|
+
readonly self: {
|
|
128
|
+
readonly codecId: 'pg/text@1';
|
|
129
|
+
};
|
|
130
|
+
readonly impl: (start: CodecExpression<'pg/text@1', boolean, CT>) => ParadeDbProximityChain;
|
|
131
|
+
};
|
|
132
|
+
}>;
|
|
133
|
+
//#endregion
|
|
134
|
+
export { QueryOperationTypes as t };
|
|
135
|
+
//# sourceMappingURL=operation-types-DXmTJ7jd.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation-types-DXmTJ7jd.d.mts","names":[],"sources":["../src/core/proximity-chain.ts","../src/types/operation-types.ts"],"mappings":";;;;;KASY,aAAA;AAAA,UAEK,sBAAA;EAAA,SACN,OAAA;AAAA;AAAA,UAGD,aAAA;EAAA,SACC,QAAA;EAAA,SACA,IAAA,EAAM,aAAA;EAAA,SACN,OAAA;AAAA;AAAA,cAIE,sBAAA,YACA,UAAA;EAAa,OAAA;EAAsB,QAAA;AAAA;EAAA,SAErC,UAAA;IAAA;;;mBAEQ,KAAA;EAAA,iBACA,KAAA;cAEL,KAAA,EAAO,aAAA,EAAe,KAAA,YAAgB,aAAA;EAKlD,MAAA,CACE,QAAA,UACA,IAAA,EAAM,aAAA,EACN,OAAA,GAAU,sBAAA,GACT,sBAAA;EAYH,QAAA,CAAA,GAAY,aAAA;AAAA;;;KC/CT,cAAA,GAAiB,MAAA;EAAA,SAA0B,KAAA;EAAA,SAAyB,MAAA;AAAA;AAAA,KAE7D,mBAAA,YAA+B,cAAA,IAAkB,sBAAA,CAC3D,EAAA;EAAA,SAEW,aAAA;IAAA,SACE,IAAA;MAAA,SAAiB,OAAA;IAAA;IAAA,SACjB,IAAA,GACP,IAAA,EAAM,eAAA,uBAAsC,EAAA,GAC5C,KAAA,EAAO,eAAA,uBAAsC,EAAA,MAC1C,UAAA;MAAa,OAAA;MAAsB,QAAA;IAAA;EAAA;EAAA,SAEjC,gBAAA;IAAA,SACE,IAAA;MAAA,SAAiB,OAAA;IAAA;I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C,MAAA,aACG,UAAA;MAAa,OAAA;MAAsB,QAAA;IAAA;EAAA;EAAA,SAEjC,aAAA;IAAA,SACE,IAAA;MAAA,SAAiB,OAAA;IAAA;IAAA,SACjB,IAAA,GACP,IAAA,EAAM,eAAA,uBAAsC,EAAA,GAC5C,KAAA,aACG,UAAA;MAAa,OAAA;MAAsB,QAAA;IAAA;EAAA;EAAA,SAEjC,YAAA;IAAA,SACE,IAAA;MAAA,SAAiB,OAAA;IAAA;IAAA,SACjB,IAAA,GACP,IAAA,EAAM,eAAA,uBAAsC,EAAA,GAC5C,IAAA,aACG,UAAA;MAAa,OAAA;MAAsB,QAAA;IAAA;EAAA;EAAA,SAEjC,iBAAA;IAAA,SACE,IAAA;MAAA,SAAiB,OAAA;IAAA;IAAA,SACjB,IAAA,GAAO,KAAA,EAAO,eAAA,uBAAsC,EAAA,MAAQ,sBAAA;EAAA;AAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/pack.d.mts
CHANGED
|
@@ -17,6 +17,15 @@ declare const paradedbPack: {
|
|
|
17
17
|
key_field: string;
|
|
18
18
|
};
|
|
19
19
|
}>>;
|
|
20
|
+
readonly types: {
|
|
21
|
+
readonly queryOperationTypes: {
|
|
22
|
+
readonly import: {
|
|
23
|
+
readonly package: "@prisma-next/extension-paradedb/operation-types";
|
|
24
|
+
readonly named: "QueryOperationTypes";
|
|
25
|
+
readonly alias: "ParadeDbQueryOperationTypes";
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
};
|
|
20
29
|
};
|
|
21
30
|
//#endregion
|
|
22
31
|
export { paradedbPack as default };
|
package/dist/pack.mjs
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SqlRuntimeExtensionDescriptor } from "@prisma-next/sql-runtime";
|
|
2
|
+
|
|
3
|
+
//#region src/exports/runtime.d.ts
|
|
4
|
+
declare const paradedbRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'>;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { paradedbRuntimeDescriptor as default };
|
|
7
|
+
//# sourceMappingURL=runtime.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/exports/runtime.ts"],"mappings":";;;cAGM,yBAAA,EAA2B,6BAAA"}
|
package/dist/runtime.mjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { n as paradedbQueryOperations, t as paradedbPackMeta } from "./descriptor-meta-CmokJ02r.mjs";
|
|
2
|
+
//#region src/exports/runtime.ts
|
|
3
|
+
const paradedbRuntimeDescriptor = {
|
|
4
|
+
kind: "extension",
|
|
5
|
+
id: paradedbPackMeta.id,
|
|
6
|
+
version: paradedbPackMeta.version,
|
|
7
|
+
familyId: "sql",
|
|
8
|
+
targetId: "postgres",
|
|
9
|
+
codecs: () => [],
|
|
10
|
+
queryOperations: () => paradedbQueryOperations(),
|
|
11
|
+
create() {
|
|
12
|
+
return {
|
|
13
|
+
familyId: "sql",
|
|
14
|
+
targetId: "postgres"
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
export { paradedbRuntimeDescriptor as default };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=runtime.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.mjs","names":[],"sources":["../src/exports/runtime.ts"],"sourcesContent":["import type { SqlRuntimeExtensionDescriptor } from '@prisma-next/sql-runtime';\nimport { paradedbPackMeta, paradedbQueryOperations } from '../core/descriptor-meta';\n\nconst paradedbRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'> = {\n kind: 'extension' as const,\n id: paradedbPackMeta.id,\n version: paradedbPackMeta.version,\n familyId: 'sql' as const,\n targetId: 'postgres' as const,\n codecs: () => [],\n queryOperations: () => paradedbQueryOperations(),\n create() {\n return {\n familyId: 'sql' as const,\n targetId: 'postgres' as const,\n };\n },\n};\n\nexport default paradedbRuntimeDescriptor;\n"],"mappings":";;AAGA,MAAM,4BAAuE;CAC3E,MAAM;CACN,IAAI,iBAAiB;CACrB,SAAS,iBAAiB;CAC1B,UAAU;CACV,UAAU;CACV,cAAc,EAAE;CAChB,uBAAuB,yBAAyB;CAChD,SAAS;EACP,OAAO;GACL,UAAU;GACV,UAAU;GACX;;CAEJ"}
|
package/package.json
CHANGED
|
@@ -1,21 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/extension-paradedb",
|
|
3
|
-
"version": "0.5.0-dev.
|
|
3
|
+
"version": "0.5.0-dev.87",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"arktype": "^2.1.25",
|
|
9
|
-
"@prisma-next/contract": "0.5.0-dev.
|
|
10
|
-
"@prisma-next/
|
|
11
|
-
"@prisma-next/
|
|
9
|
+
"@prisma-next/contract": "0.5.0-dev.87",
|
|
10
|
+
"@prisma-next/contract-authoring": "0.5.0-dev.87",
|
|
11
|
+
"@prisma-next/framework-components": "0.5.0-dev.87",
|
|
12
|
+
"@prisma-next/family-sql": "0.5.0-dev.87",
|
|
13
|
+
"@prisma-next/sql-operations": "0.5.0-dev.87",
|
|
14
|
+
"@prisma-next/sql-contract": "0.5.0-dev.87",
|
|
15
|
+
"@prisma-next/sql-relational-core": "0.5.0-dev.87",
|
|
16
|
+
"@prisma-next/sql-runtime": "0.5.0-dev.87"
|
|
12
17
|
},
|
|
13
18
|
"devDependencies": {
|
|
14
19
|
"tsdown": "0.22.0",
|
|
15
20
|
"typescript": "5.9.3",
|
|
16
21
|
"vitest": "4.1.5",
|
|
22
|
+
"@prisma-next/adapter-postgres": "0.5.0-dev.87",
|
|
23
|
+
"@prisma-next/operations": "0.5.0-dev.87",
|
|
24
|
+
"@prisma-next/sql-contract-ts": "0.5.0-dev.87",
|
|
25
|
+
"@prisma-next/tsconfig": "0.0.0",
|
|
17
26
|
"@prisma-next/tsdown": "0.0.0",
|
|
18
|
-
"@prisma-next/
|
|
27
|
+
"@prisma-next/test-utils": "0.0.1"
|
|
19
28
|
},
|
|
20
29
|
"files": [
|
|
21
30
|
"dist",
|
|
@@ -24,7 +33,9 @@
|
|
|
24
33
|
"exports": {
|
|
25
34
|
"./control": "./dist/control.mjs",
|
|
26
35
|
"./index-types": "./dist/index-types.mjs",
|
|
36
|
+
"./operation-types": "./dist/operation-types.mjs",
|
|
27
37
|
"./pack": "./dist/pack.mjs",
|
|
38
|
+
"./runtime": "./dist/runtime.mjs",
|
|
28
39
|
"./package.json": "./package.json"
|
|
29
40
|
},
|
|
30
41
|
"repository": {
|
|
@@ -1,5 +1,194 @@
|
|
|
1
|
+
import { LiteralExpr } from '@prisma-next/sql-relational-core/ast';
|
|
2
|
+
import { buildOperation, toExpr } from '@prisma-next/sql-relational-core/expression';
|
|
1
3
|
import { paradedbIndexTypes } from '../types/index-types';
|
|
4
|
+
import type { QueryOperationTypes } from '../types/operation-types';
|
|
2
5
|
import { PARADEDB_EXTENSION_ID } from './constants';
|
|
6
|
+
import { ParadeDbProximityChain } from './proximity-chain';
|
|
7
|
+
|
|
8
|
+
type CodecTypesBase = Record<string, { readonly input: unknown; readonly output: unknown }>;
|
|
9
|
+
|
|
10
|
+
const TEXT = 'pg/text@1' as const;
|
|
11
|
+
const BOOL = 'pg/bool@1' as const;
|
|
12
|
+
const FLOAT4 = 'pg/float4@1' as const;
|
|
13
|
+
const INT4 = 'pg/int4@1' as const;
|
|
14
|
+
|
|
15
|
+
export function paradedbQueryOperations<CT extends CodecTypesBase>(): QueryOperationTypes<CT> {
|
|
16
|
+
return {
|
|
17
|
+
// `@@@` accepts both text and structured query types on its RHS.
|
|
18
|
+
// https://docs.paradedb.com/documentation/full-text/match
|
|
19
|
+
paradeDbMatch: {
|
|
20
|
+
self: { codecId: TEXT },
|
|
21
|
+
impl: (self, query) =>
|
|
22
|
+
buildOperation({
|
|
23
|
+
method: 'paradeDbMatch',
|
|
24
|
+
args: [toExpr(self, TEXT), toExpr(query, TEXT)],
|
|
25
|
+
returns: { codecId: BOOL, nullable: false },
|
|
26
|
+
lowering: {
|
|
27
|
+
targetFamily: 'sql',
|
|
28
|
+
strategy: 'function',
|
|
29
|
+
template: '{{self}} @@@ {{arg0}}',
|
|
30
|
+
},
|
|
31
|
+
}),
|
|
32
|
+
},
|
|
33
|
+
paradeDbMatchAny: {
|
|
34
|
+
self: { codecId: TEXT },
|
|
35
|
+
impl: (self, query) =>
|
|
36
|
+
buildOperation({
|
|
37
|
+
method: 'paradeDbMatchAny',
|
|
38
|
+
args: [toExpr(self, TEXT), toExpr(query, TEXT)],
|
|
39
|
+
returns: { codecId: BOOL, nullable: false },
|
|
40
|
+
lowering: {
|
|
41
|
+
targetFamily: 'sql',
|
|
42
|
+
strategy: 'function',
|
|
43
|
+
template: '{{self}} ||| {{arg0}}',
|
|
44
|
+
},
|
|
45
|
+
}),
|
|
46
|
+
},
|
|
47
|
+
paradeDbMatchAll: {
|
|
48
|
+
self: { codecId: TEXT },
|
|
49
|
+
impl: (self, query) =>
|
|
50
|
+
buildOperation({
|
|
51
|
+
method: 'paradeDbMatchAll',
|
|
52
|
+
args: [toExpr(self, TEXT), toExpr(query, TEXT)],
|
|
53
|
+
returns: { codecId: BOOL, nullable: false },
|
|
54
|
+
lowering: {
|
|
55
|
+
targetFamily: 'sql',
|
|
56
|
+
strategy: 'function',
|
|
57
|
+
template: '{{self}} &&& {{arg0}}',
|
|
58
|
+
},
|
|
59
|
+
}),
|
|
60
|
+
},
|
|
61
|
+
// https://docs.paradedb.com/documentation/full-text/term
|
|
62
|
+
paradeDbTerm: {
|
|
63
|
+
self: { codecId: TEXT },
|
|
64
|
+
impl: (self, query) =>
|
|
65
|
+
buildOperation({
|
|
66
|
+
method: 'paradeDbTerm',
|
|
67
|
+
args: [toExpr(self, TEXT), toExpr(query, TEXT)],
|
|
68
|
+
returns: { codecId: BOOL, nullable: false },
|
|
69
|
+
lowering: {
|
|
70
|
+
targetFamily: 'sql',
|
|
71
|
+
strategy: 'function',
|
|
72
|
+
template: '{{self}} === {{arg0}}',
|
|
73
|
+
},
|
|
74
|
+
}),
|
|
75
|
+
},
|
|
76
|
+
// https://docs.paradedb.com/documentation/full-text/phrase
|
|
77
|
+
paradeDbPhrase: {
|
|
78
|
+
self: { codecId: TEXT },
|
|
79
|
+
impl: (self, query) =>
|
|
80
|
+
buildOperation({
|
|
81
|
+
method: 'paradeDbPhrase',
|
|
82
|
+
args: [toExpr(self, TEXT), toExpr(query, TEXT)],
|
|
83
|
+
returns: { codecId: BOOL, nullable: false },
|
|
84
|
+
lowering: {
|
|
85
|
+
targetFamily: 'sql',
|
|
86
|
+
strategy: 'function',
|
|
87
|
+
template: '{{self}} ### {{arg0}}',
|
|
88
|
+
},
|
|
89
|
+
}),
|
|
90
|
+
},
|
|
91
|
+
// https://docs.paradedb.com/documentation/sorting/score
|
|
92
|
+
paradeDbScore: {
|
|
93
|
+
self: { codecId: INT4 },
|
|
94
|
+
impl: (self) =>
|
|
95
|
+
buildOperation({
|
|
96
|
+
method: 'paradeDbScore',
|
|
97
|
+
args: [toExpr(self, INT4)],
|
|
98
|
+
returns: { codecId: FLOAT4, nullable: false },
|
|
99
|
+
lowering: {
|
|
100
|
+
targetFamily: 'sql',
|
|
101
|
+
strategy: 'function',
|
|
102
|
+
template: 'pdb.score({{self}})',
|
|
103
|
+
},
|
|
104
|
+
}),
|
|
105
|
+
},
|
|
106
|
+
// PG rejects parameterized typmods, so the cast argument lowers to a literal.
|
|
107
|
+
// https://docs.paradedb.com/documentation/full-text/fuzzy
|
|
108
|
+
paradeDbFuzzy: {
|
|
109
|
+
self: { codecId: TEXT },
|
|
110
|
+
impl: (self, distance) => {
|
|
111
|
+
if (!Number.isInteger(distance) || distance < 0 || distance > 2) {
|
|
112
|
+
throw new Error(
|
|
113
|
+
`paradeDbFuzzy: distance must be an integer in [0, 2]; got ${String(distance)}`,
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
return buildOperation({
|
|
117
|
+
method: 'paradeDbFuzzy',
|
|
118
|
+
args: [toExpr(self, TEXT), LiteralExpr.of(distance)],
|
|
119
|
+
returns: { codecId: TEXT, nullable: false },
|
|
120
|
+
lowering: {
|
|
121
|
+
targetFamily: 'sql',
|
|
122
|
+
strategy: 'function',
|
|
123
|
+
template: '{{self}}::pdb.fuzzy({{arg0}})',
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
// https://docs.paradedb.com/documentation/sorting/boost
|
|
129
|
+
paradeDbBoost: {
|
|
130
|
+
self: { codecId: TEXT },
|
|
131
|
+
impl: (self, weight) => {
|
|
132
|
+
if (!Number.isInteger(weight) || weight < -2048 || weight > 2048) {
|
|
133
|
+
throw new Error(
|
|
134
|
+
`paradeDbBoost: boost must be an integer in [-2048, 2048]; got ${String(weight)}`,
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
return buildOperation({
|
|
138
|
+
method: 'paradeDbBoost',
|
|
139
|
+
args: [toExpr(self, TEXT), LiteralExpr.of(weight)],
|
|
140
|
+
returns: { codecId: TEXT, nullable: false },
|
|
141
|
+
lowering: {
|
|
142
|
+
targetFamily: 'sql',
|
|
143
|
+
strategy: 'function',
|
|
144
|
+
template: '{{self}}::pdb.boost({{arg0}})',
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
paradeDbConst: {
|
|
150
|
+
self: { codecId: TEXT },
|
|
151
|
+
impl: (self, value) => {
|
|
152
|
+
if (!Number.isInteger(value)) {
|
|
153
|
+
throw new Error(`paradeDbConst: value must be an integer; got ${String(value)}`);
|
|
154
|
+
}
|
|
155
|
+
return buildOperation({
|
|
156
|
+
method: 'paradeDbConst',
|
|
157
|
+
args: [toExpr(self, TEXT), LiteralExpr.of(value)],
|
|
158
|
+
returns: { codecId: TEXT, nullable: false },
|
|
159
|
+
lowering: {
|
|
160
|
+
targetFamily: 'sql',
|
|
161
|
+
strategy: 'function',
|
|
162
|
+
template: '{{self}}::pdb.const({{arg0}})',
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
paradeDbSlop: {
|
|
168
|
+
self: { codecId: TEXT },
|
|
169
|
+
impl: (self, slop) => {
|
|
170
|
+
if (!Number.isInteger(slop) || slop < 0) {
|
|
171
|
+
throw new Error(`paradeDbSlop: slop must be a non-negative integer; got ${String(slop)}`);
|
|
172
|
+
}
|
|
173
|
+
return buildOperation({
|
|
174
|
+
method: 'paradeDbSlop',
|
|
175
|
+
args: [toExpr(self, TEXT), LiteralExpr.of(slop)],
|
|
176
|
+
returns: { codecId: TEXT, nullable: false },
|
|
177
|
+
lowering: {
|
|
178
|
+
targetFamily: 'sql',
|
|
179
|
+
strategy: 'function',
|
|
180
|
+
template: '{{self}}::pdb.slop({{arg0}})',
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
// https://docs.paradedb.com/documentation/full-text/proximity
|
|
186
|
+
paradeDbProximity: {
|
|
187
|
+
self: { codecId: TEXT },
|
|
188
|
+
impl: (start) => new ParadeDbProximityChain(start),
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
}
|
|
3
192
|
|
|
4
193
|
export const paradedbPackMeta = {
|
|
5
194
|
kind: 'extension',
|
|
@@ -13,4 +202,13 @@ export const paradedbPackMeta = {
|
|
|
13
202
|
},
|
|
14
203
|
},
|
|
15
204
|
indexTypes: paradedbIndexTypes,
|
|
205
|
+
types: {
|
|
206
|
+
queryOperationTypes: {
|
|
207
|
+
import: {
|
|
208
|
+
package: '@prisma-next/extension-paradedb/operation-types',
|
|
209
|
+
named: 'QueryOperationTypes',
|
|
210
|
+
alias: 'ParadeDbQueryOperationTypes',
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
},
|
|
16
214
|
} as const;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AnyExpression,
|
|
3
|
+
LiteralExpr,
|
|
4
|
+
OperationExpr,
|
|
5
|
+
} from '@prisma-next/sql-relational-core/ast';
|
|
6
|
+
import { type Expression, toExpr } from '@prisma-next/sql-relational-core/expression';
|
|
7
|
+
|
|
8
|
+
const TEXT = 'pg/text@1' as const;
|
|
9
|
+
|
|
10
|
+
export type ProximityTerm = unknown;
|
|
11
|
+
|
|
12
|
+
export interface ProximityWithinOptions {
|
|
13
|
+
readonly ordered?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface ProximityStep {
|
|
17
|
+
readonly distance: number;
|
|
18
|
+
readonly term: ProximityTerm;
|
|
19
|
+
readonly ordered: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// https://docs.paradedb.com/documentation/full-text/proximity
|
|
23
|
+
export class ParadeDbProximityChain
|
|
24
|
+
implements Expression<{ codecId: 'pg/text@1'; nullable: false }>
|
|
25
|
+
{
|
|
26
|
+
readonly returnType = { codecId: TEXT, nullable: false } as const;
|
|
27
|
+
|
|
28
|
+
private readonly start: ProximityTerm;
|
|
29
|
+
private readonly steps: readonly ProximityStep[];
|
|
30
|
+
|
|
31
|
+
constructor(start: ProximityTerm, steps: readonly ProximityStep[] = []) {
|
|
32
|
+
this.start = start;
|
|
33
|
+
this.steps = steps;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
within(
|
|
37
|
+
distance: number,
|
|
38
|
+
term: ProximityTerm,
|
|
39
|
+
options?: ProximityWithinOptions,
|
|
40
|
+
): ParadeDbProximityChain {
|
|
41
|
+
if (!Number.isInteger(distance) || distance < 0) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
`paradeDbProximity.within: distance must be a non-negative integer; got ${String(distance)}`,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
return new ParadeDbProximityChain(this.start, [
|
|
47
|
+
...this.steps,
|
|
48
|
+
{ distance, term, ordered: options?.ordered === true },
|
|
49
|
+
]);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
buildAst(): AnyExpression {
|
|
53
|
+
if (this.steps.length === 0) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
'paradeDbProximity: chain must have at least one .within(distance, term) step',
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
const args: AnyExpression[] = [toExpr(this.start, TEXT)];
|
|
59
|
+
let template = '({{self}}';
|
|
60
|
+
this.steps.forEach((step, i) => {
|
|
61
|
+
const op = step.ordered ? '##>' : '##';
|
|
62
|
+
args.push(LiteralExpr.of(step.distance));
|
|
63
|
+
args.push(toExpr(step.term, TEXT));
|
|
64
|
+
template += ` ${op} {{arg${2 * i}}} ${op} {{arg${2 * i + 1}}}`;
|
|
65
|
+
});
|
|
66
|
+
template += ')';
|
|
67
|
+
const [self, ...rest] = args;
|
|
68
|
+
if (!self) {
|
|
69
|
+
throw new Error('paradeDbProximity: invariant violation — empty args');
|
|
70
|
+
}
|
|
71
|
+
return new OperationExpr({
|
|
72
|
+
method: 'paradeDbProximity',
|
|
73
|
+
self,
|
|
74
|
+
args: rest.length > 0 ? rest : undefined,
|
|
75
|
+
returns: this.returnType,
|
|
76
|
+
lowering: {
|
|
77
|
+
targetFamily: 'sql',
|
|
78
|
+
strategy: 'function',
|
|
79
|
+
template,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
package/src/exports/control.ts
CHANGED
|
@@ -1,3 +1,54 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
|
+
ComponentDatabaseDependencies,
|
|
3
|
+
SqlControlExtensionDescriptor,
|
|
4
|
+
} from '@prisma-next/family-sql/control';
|
|
5
|
+
import { paradedbPackMeta, paradedbQueryOperations } from '../core/descriptor-meta';
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
const paradedbDatabaseDependencies: ComponentDatabaseDependencies<unknown> = {
|
|
8
|
+
init: [
|
|
9
|
+
{
|
|
10
|
+
id: 'postgres.extension.pg_search',
|
|
11
|
+
label: 'Enable pg_search extension',
|
|
12
|
+
install: [
|
|
13
|
+
{
|
|
14
|
+
id: 'extension.pg_search',
|
|
15
|
+
label: 'Enable extension "pg_search"',
|
|
16
|
+
summary: 'Ensures the pg_search extension is available for ParadeDB BM25 operations',
|
|
17
|
+
operationClass: 'additive',
|
|
18
|
+
target: { id: 'postgres' },
|
|
19
|
+
precheck: [
|
|
20
|
+
{
|
|
21
|
+
description: 'verify extension "pg_search" is not already enabled',
|
|
22
|
+
sql: "SELECT NOT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'pg_search')",
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
execute: [
|
|
26
|
+
{
|
|
27
|
+
description: 'create extension "pg_search"',
|
|
28
|
+
sql: 'CREATE EXTENSION IF NOT EXISTS pg_search',
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
postcheck: [
|
|
32
|
+
{
|
|
33
|
+
description: 'confirm extension "pg_search" is enabled',
|
|
34
|
+
sql: "SELECT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'pg_search')",
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const paradedbExtensionDescriptor: SqlControlExtensionDescriptor<'postgres'> = {
|
|
44
|
+
...paradedbPackMeta,
|
|
45
|
+
queryOperations: () => paradedbQueryOperations(),
|
|
46
|
+
databaseDependencies: paradedbDatabaseDependencies,
|
|
47
|
+
create: () => ({
|
|
48
|
+
familyId: 'sql' as const,
|
|
49
|
+
targetId: 'postgres' as const,
|
|
50
|
+
}),
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { paradedbExtensionDescriptor, paradedbPackMeta };
|
|
54
|
+
export default paradedbExtensionDescriptor;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { QueryOperationTypes } from '../types/operation-types';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { SqlRuntimeExtensionDescriptor } from '@prisma-next/sql-runtime';
|
|
2
|
+
import { paradedbPackMeta, paradedbQueryOperations } from '../core/descriptor-meta';
|
|
3
|
+
|
|
4
|
+
const paradedbRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'> = {
|
|
5
|
+
kind: 'extension' as const,
|
|
6
|
+
id: paradedbPackMeta.id,
|
|
7
|
+
version: paradedbPackMeta.version,
|
|
8
|
+
familyId: 'sql' as const,
|
|
9
|
+
targetId: 'postgres' as const,
|
|
10
|
+
codecs: () => [],
|
|
11
|
+
queryOperations: () => paradedbQueryOperations(),
|
|
12
|
+
create() {
|
|
13
|
+
return {
|
|
14
|
+
familyId: 'sql' as const,
|
|
15
|
+
targetId: 'postgres' as const,
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default paradedbRuntimeDescriptor;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { SqlQueryOperationTypes } from '@prisma-next/sql-contract/types';
|
|
2
|
+
import type { CodecExpression, Expression } from '@prisma-next/sql-relational-core/expression';
|
|
3
|
+
import type { ParadeDbProximityChain } from '../core/proximity-chain';
|
|
4
|
+
|
|
5
|
+
type CodecTypesBase = Record<string, { readonly input: unknown; readonly output: unknown }>;
|
|
6
|
+
|
|
7
|
+
export type QueryOperationTypes<CT extends CodecTypesBase> = SqlQueryOperationTypes<
|
|
8
|
+
CT,
|
|
9
|
+
{
|
|
10
|
+
readonly paradeDbMatch: {
|
|
11
|
+
readonly self: { readonly codecId: 'pg/text@1' };
|
|
12
|
+
readonly impl: (
|
|
13
|
+
self: CodecExpression<'pg/text@1', boolean, CT>,
|
|
14
|
+
query: CodecExpression<'pg/text@1', boolean, CT>,
|
|
15
|
+
) => Expression<{ codecId: 'pg/bool@1'; nullable: false }>;
|
|
16
|
+
};
|
|
17
|
+
readonly paradeDbMatchAny: {
|
|
18
|
+
readonly self: { readonly codecId: 'pg/text@1' };
|
|
19
|
+
readonly impl: (
|
|
20
|
+
self: CodecExpression<'pg/text@1', boolean, CT>,
|
|
21
|
+
query: CodecExpression<'pg/text@1', boolean, CT>,
|
|
22
|
+
) => Expression<{ codecId: 'pg/bool@1'; nullable: false }>;
|
|
23
|
+
};
|
|
24
|
+
readonly paradeDbMatchAll: {
|
|
25
|
+
readonly self: { readonly codecId: 'pg/text@1' };
|
|
26
|
+
readonly impl: (
|
|
27
|
+
self: CodecExpression<'pg/text@1', boolean, CT>,
|
|
28
|
+
query: CodecExpression<'pg/text@1', boolean, CT>,
|
|
29
|
+
) => Expression<{ codecId: 'pg/bool@1'; nullable: false }>;
|
|
30
|
+
};
|
|
31
|
+
readonly paradeDbTerm: {
|
|
32
|
+
readonly self: { readonly codecId: 'pg/text@1' };
|
|
33
|
+
readonly impl: (
|
|
34
|
+
self: CodecExpression<'pg/text@1', boolean, CT>,
|
|
35
|
+
query: CodecExpression<'pg/text@1', boolean, CT>,
|
|
36
|
+
) => Expression<{ codecId: 'pg/bool@1'; nullable: false }>;
|
|
37
|
+
};
|
|
38
|
+
readonly paradeDbPhrase: {
|
|
39
|
+
readonly self: { readonly codecId: 'pg/text@1' };
|
|
40
|
+
readonly impl: (
|
|
41
|
+
self: CodecExpression<'pg/text@1', boolean, CT>,
|
|
42
|
+
query: CodecExpression<'pg/text@1', boolean, CT>,
|
|
43
|
+
) => Expression<{ codecId: 'pg/bool@1'; nullable: false }>;
|
|
44
|
+
};
|
|
45
|
+
readonly paradeDbScore: {
|
|
46
|
+
readonly self: { readonly codecId: 'pg/int4@1' };
|
|
47
|
+
readonly impl: (
|
|
48
|
+
self: CodecExpression<'pg/int4@1', boolean, CT>,
|
|
49
|
+
) => Expression<{ codecId: 'pg/float4@1'; nullable: false }>;
|
|
50
|
+
};
|
|
51
|
+
readonly paradeDbFuzzy: {
|
|
52
|
+
readonly self: { readonly codecId: 'pg/text@1' };
|
|
53
|
+
readonly impl: (
|
|
54
|
+
self: CodecExpression<'pg/text@1', boolean, CT>,
|
|
55
|
+
distance: number,
|
|
56
|
+
) => Expression<{ codecId: 'pg/text@1'; nullable: false }>;
|
|
57
|
+
};
|
|
58
|
+
readonly paradeDbBoost: {
|
|
59
|
+
readonly self: { readonly codecId: 'pg/text@1' };
|
|
60
|
+
readonly impl: (
|
|
61
|
+
self: CodecExpression<'pg/text@1', boolean, CT>,
|
|
62
|
+
weight: number,
|
|
63
|
+
) => Expression<{ codecId: 'pg/text@1'; nullable: false }>;
|
|
64
|
+
};
|
|
65
|
+
readonly paradeDbConst: {
|
|
66
|
+
readonly self: { readonly codecId: 'pg/text@1' };
|
|
67
|
+
readonly impl: (
|
|
68
|
+
self: CodecExpression<'pg/text@1', boolean, CT>,
|
|
69
|
+
value: number,
|
|
70
|
+
) => Expression<{ codecId: 'pg/text@1'; nullable: false }>;
|
|
71
|
+
};
|
|
72
|
+
readonly paradeDbSlop: {
|
|
73
|
+
readonly self: { readonly codecId: 'pg/text@1' };
|
|
74
|
+
readonly impl: (
|
|
75
|
+
self: CodecExpression<'pg/text@1', boolean, CT>,
|
|
76
|
+
slop: number,
|
|
77
|
+
) => Expression<{ codecId: 'pg/text@1'; nullable: false }>;
|
|
78
|
+
};
|
|
79
|
+
readonly paradeDbProximity: {
|
|
80
|
+
readonly self: { readonly codecId: 'pg/text@1' };
|
|
81
|
+
readonly impl: (start: CodecExpression<'pg/text@1', boolean, CT>) => ParadeDbProximityChain;
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
>;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { t as paradedbIndexTypes } from "./index-types-BWFfNqUb.mjs";
|
|
2
|
-
//#endregion
|
|
3
|
-
//#region src/core/descriptor-meta.ts
|
|
4
|
-
const paradedbPackMeta = {
|
|
5
|
-
kind: "extension",
|
|
6
|
-
id: "paradedb",
|
|
7
|
-
familyId: "sql",
|
|
8
|
-
targetId: "postgres",
|
|
9
|
-
version: "0.0.1",
|
|
10
|
-
capabilities: { postgres: { "paradedb/bm25": true } },
|
|
11
|
-
indexTypes: paradedbIndexTypes
|
|
12
|
-
};
|
|
13
|
-
//#endregion
|
|
14
|
-
export { paradedbPackMeta as t };
|
|
15
|
-
|
|
16
|
-
//# sourceMappingURL=descriptor-meta-BF_fQseQ.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"descriptor-meta-BF_fQseQ.mjs","names":[],"sources":["../src/core/constants.ts","../src/core/descriptor-meta.ts"],"sourcesContent":["/**\n * Extension ID for ParadeDB pg_search.\n */\nexport const PARADEDB_EXTENSION_ID = 'paradedb' as const;\n","import { paradedbIndexTypes } from '../types/index-types';\nimport { PARADEDB_EXTENSION_ID } from './constants';\n\nexport const paradedbPackMeta = {\n kind: 'extension',\n id: PARADEDB_EXTENSION_ID,\n familyId: 'sql',\n targetId: 'postgres',\n version: '0.0.1',\n capabilities: {\n postgres: {\n 'paradedb/bm25': true,\n },\n },\n indexTypes: paradedbIndexTypes,\n} as const;\n"],"mappings":";;;ACGA,MAAa,mBAAmB;CAC9B,MAAM;CACN,IAAI;CACJ,UAAU;CACV,UAAU;CACV,SAAS;CACT,cAAc,EACZ,UAAU,EACR,iBAAiB,MAClB,EACF;CACD,YAAY;CACb"}
|