@prisma-next/extension-paradedb 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +162 -0
- package/dist/control.d.mts +16 -0
- package/dist/control.d.mts.map +1 -0
- package/dist/control.mjs +3 -0
- package/dist/descriptor-meta-BTFnIGJ6.mjs +20 -0
- package/dist/descriptor-meta-BTFnIGJ6.mjs.map +1 -0
- package/dist/index-types.d.mts +110 -0
- package/dist/index-types.d.mts.map +1 -0
- package/dist/index-types.mjs +84 -0
- package/dist/index-types.mjs.map +1 -0
- package/dist/pack.d.mts +16 -0
- package/dist/pack.d.mts.map +1 -0
- package/dist/pack.mjs +9 -0
- package/dist/pack.mjs.map +1 -0
- package/package.json +42 -0
- package/src/core/constants.ts +22 -0
- package/src/core/descriptor-meta.ts +14 -0
- package/src/exports/control.ts +3 -0
- package/src/exports/index-types.ts +12 -0
- package/src/exports/pack.ts +5 -0
- package/src/types/index-types.ts +179 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [2026] [Prisma Data, Inc]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# @prisma-next/extension-paradedb
|
|
2
|
+
|
|
3
|
+
ParadeDB full-text search extension pack for Prisma Next.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This extension pack adds support for [ParadeDB](https://docs.paradedb.com/) BM25 full-text search indexes in the contract authoring layer. It keeps BM25 metadata inside extension-owned index `config` payloads, so `contract.json` and `contract.d.ts` carry the full search schema without hard-coding ParadeDB types into core SQL index IR.
|
|
8
|
+
|
|
9
|
+
This is the **contract-only foundation**. Query-plane support (`@@@` operator, `pdb.*` functions) and migration-plane support (`CREATE INDEX ... USING bm25` DDL generation) are planned as follow-up work.
|
|
10
|
+
|
|
11
|
+
## Responsibilities
|
|
12
|
+
|
|
13
|
+
- **BM25 Index Authoring**: Typed `bm25.*` field builders for defining BM25 indexes in `contract.ts`
|
|
14
|
+
- **Tokenizer Catalog**: `TokenizerId` type union covering all 12 built-in ParadeDB tokenizers
|
|
15
|
+
- **Extension Descriptor**: Declares `paradedb/bm25` capability for contract-level feature detection
|
|
16
|
+
- **Pack Ref Export**: Ships a pure `/pack` entrypoint for TypeScript contract authoring
|
|
17
|
+
|
|
18
|
+
## Dependencies
|
|
19
|
+
|
|
20
|
+
- **`@prisma-next/contract`**: Core contract types
|
|
21
|
+
- **`@prisma-next/contract-authoring`**: Column type descriptor interface
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pnpm add @prisma-next/extension-paradedb
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
### Contract Definition
|
|
32
|
+
|
|
33
|
+
Define BM25 indexes on your tables using `bm25` field builders plus `bm25Index()`:
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { defineContract } from '@prisma-next/sql-contract-ts/contract-builder';
|
|
37
|
+
import { int4Column, textColumn, jsonbColumn } from '@prisma-next/adapter-postgres/column-types';
|
|
38
|
+
import { bm25, bm25Index } from '@prisma-next/extension-paradedb/index-types';
|
|
39
|
+
import paradedb from '@prisma-next/extension-paradedb/pack';
|
|
40
|
+
import postgres from '@prisma-next/target-postgres/pack';
|
|
41
|
+
|
|
42
|
+
export const contract = defineContract()
|
|
43
|
+
.target(postgres)
|
|
44
|
+
.extensionPacks({ paradedb })
|
|
45
|
+
.table('items', (t) =>
|
|
46
|
+
t
|
|
47
|
+
.column('id', { type: int4Column, nullable: false })
|
|
48
|
+
.column('description', { type: textColumn, nullable: false })
|
|
49
|
+
.column('category', { type: textColumn, nullable: false })
|
|
50
|
+
.column('rating', { type: int4Column, nullable: false })
|
|
51
|
+
.column('metadata', { type: jsonbColumn, nullable: false })
|
|
52
|
+
.primaryKey(['id'])
|
|
53
|
+
.index(
|
|
54
|
+
bm25Index({
|
|
55
|
+
keyField: 'id',
|
|
56
|
+
fields: [
|
|
57
|
+
bm25.text('description', { tokenizer: 'simple', stemmer: 'english' }),
|
|
58
|
+
bm25.text('category'),
|
|
59
|
+
bm25.numeric('rating'),
|
|
60
|
+
bm25.json('metadata', { tokenizer: 'ngram', min: 2, max: 3 }),
|
|
61
|
+
],
|
|
62
|
+
name: 'search_idx',
|
|
63
|
+
}),
|
|
64
|
+
),
|
|
65
|
+
)
|
|
66
|
+
.build();
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Field Builders
|
|
70
|
+
|
|
71
|
+
The `bm25` namespace provides typed field builders that produce `Bm25FieldConfig` objects:
|
|
72
|
+
|
|
73
|
+
| Builder | Description | Tokenizer support |
|
|
74
|
+
|---------|-------------|-------------------|
|
|
75
|
+
| `bm25.text(column, opts?)` | Text field (`text`, `varchar`) | Yes — any tokenizer + stemmer, remove_emojis |
|
|
76
|
+
| `bm25.numeric(column)` | Numeric field (filterable, sortable) | No |
|
|
77
|
+
| `bm25.boolean(column)` | Boolean field | No |
|
|
78
|
+
| `bm25.json(column, opts?)` | JSON/JSONB field | Yes — tokenizer + ngram params |
|
|
79
|
+
| `bm25.datetime(column)` | Timestamp/date field | No |
|
|
80
|
+
| `bm25.range(column)` | Range field | No |
|
|
81
|
+
| `bm25.expression(sql, opts)` | Raw SQL expression | Yes — `alias` required |
|
|
82
|
+
|
|
83
|
+
### Expression-Based Fields
|
|
84
|
+
|
|
85
|
+
For computed or JSON sub-field indexing, use `bm25.expression()` with a raw SQL string:
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
.index(
|
|
89
|
+
bm25Index({
|
|
90
|
+
keyField: 'id',
|
|
91
|
+
fields: [
|
|
92
|
+
bm25.text('description'),
|
|
93
|
+
bm25.expression("description || ' ' || category", {
|
|
94
|
+
alias: 'concat',
|
|
95
|
+
tokenizer: 'simple',
|
|
96
|
+
}),
|
|
97
|
+
bm25.expression("(metadata->>'color')", {
|
|
98
|
+
alias: 'meta_color',
|
|
99
|
+
tokenizer: 'ngram',
|
|
100
|
+
min: 2,
|
|
101
|
+
max: 3,
|
|
102
|
+
}),
|
|
103
|
+
],
|
|
104
|
+
}),
|
|
105
|
+
)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### keyField Behavior
|
|
109
|
+
|
|
110
|
+
ParadeDB BM25 indexes require a `key_field` — a unique column that identifies each document:
|
|
111
|
+
|
|
112
|
+
- **Required**: Set `keyField` explicitly in `bm25Index(...)`.
|
|
113
|
+
- **Recommended**: Use the table primary key in most cases.
|
|
114
|
+
- **Override**: You can choose another unique column when needed.
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
.index(bm25Index({ keyField: 'id', fields: [bm25.text('body')] }))
|
|
118
|
+
.index(bm25Index({ keyField: 'uuid', fields: [bm25.text('body')] }))
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Tokenizers
|
|
122
|
+
|
|
123
|
+
All 12 built-in ParadeDB tokenizers are available via the `TokenizerId` type:
|
|
124
|
+
|
|
125
|
+
| Tokenizer | Description |
|
|
126
|
+
|-----------|-------------|
|
|
127
|
+
| `unicode_words` | Default. Unicode word boundaries (UAX #29). Lowercases. |
|
|
128
|
+
| `simple` | Splits on non-alphanumeric. Lowercases. |
|
|
129
|
+
| `ngram` | Character n-grams of configurable length. |
|
|
130
|
+
| `icu` | ICU Unicode standard segmentation. Multilingual. |
|
|
131
|
+
| `regex_pattern` | Regex-based tokenization. |
|
|
132
|
+
| `source_code` | camelCase / snake_case splitting. |
|
|
133
|
+
| `literal` | No splitting. Exact match, sort, aggregation. |
|
|
134
|
+
| `literal_normalized` | Literal + lowercase + token filters. |
|
|
135
|
+
| `whitespace` | Whitespace splitting + lowercase. |
|
|
136
|
+
| `chinese_compatible` | CJK-aware word segmentation. |
|
|
137
|
+
| `jieba` | Chinese segmentation via Jieba. |
|
|
138
|
+
| `lindera` | Japanese/Korean/Chinese via Lindera. |
|
|
139
|
+
|
|
140
|
+
## Capabilities
|
|
141
|
+
|
|
142
|
+
The extension declares:
|
|
143
|
+
|
|
144
|
+
- `paradedb/bm25`: Indicates support for BM25 full-text search indexes
|
|
145
|
+
|
|
146
|
+
## Not Yet Implemented
|
|
147
|
+
|
|
148
|
+
The following are planned for follow-up work:
|
|
149
|
+
|
|
150
|
+
- **Query plane**: `@@@` operator support in the sql-orm query builder
|
|
151
|
+
- **Query plane**: `pdb.*` query builder functions (match, term, phrase, fuzzy, etc.)
|
|
152
|
+
- **Migration plane**: `CREATE INDEX ... USING bm25` DDL generation from contract diffs
|
|
153
|
+
- **Runtime**: Scoring, aggregation, and highlight functions
|
|
154
|
+
- **Database dependencies**: `CREATE EXTENSION pg_search` via migration planner
|
|
155
|
+
|
|
156
|
+
## References
|
|
157
|
+
|
|
158
|
+
- [ParadeDB documentation](https://docs.paradedb.com/)
|
|
159
|
+
- [ParadeDB CREATE INDEX](https://docs.paradedb.com/documentation/indexing/create-index)
|
|
160
|
+
- [ParadeDB Tokenizers](https://docs.paradedb.com/documentation/tokenizers/overview)
|
|
161
|
+
- [pg_search source](https://github.com/paradedb/paradedb/tree/main/pg_search)
|
|
162
|
+
- [Prisma Next Architecture Overview](../../../docs/Architecture%20Overview.md)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/core/descriptor-meta.d.ts
|
|
2
|
+
declare const paradedbPackMeta: {
|
|
3
|
+
readonly kind: "extension";
|
|
4
|
+
readonly id: "paradedb";
|
|
5
|
+
readonly familyId: "sql";
|
|
6
|
+
readonly targetId: "postgres";
|
|
7
|
+
readonly version: "0.0.1";
|
|
8
|
+
readonly capabilities: {
|
|
9
|
+
readonly postgres: {
|
|
10
|
+
readonly 'paradedb/bm25': true;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { paradedbPackMeta };
|
|
16
|
+
//# sourceMappingURL=control.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/descriptor-meta.ts"],"sourcesContent":[],"mappings":";cAEa;EAAA,SAAA,IAAA,EAAA,WAWH"}
|
package/dist/control.mjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/core/constants.ts
|
|
2
|
+
/**
|
|
3
|
+
* Extension ID for ParadeDB pg_search.
|
|
4
|
+
*/
|
|
5
|
+
const PARADEDB_EXTENSION_ID = "paradedb";
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/core/descriptor-meta.ts
|
|
9
|
+
const paradedbPackMeta = {
|
|
10
|
+
kind: "extension",
|
|
11
|
+
id: PARADEDB_EXTENSION_ID,
|
|
12
|
+
familyId: "sql",
|
|
13
|
+
targetId: "postgres",
|
|
14
|
+
version: "0.0.1",
|
|
15
|
+
capabilities: { postgres: { "paradedb/bm25": true } }
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { paradedbPackMeta as t };
|
|
20
|
+
//# sourceMappingURL=descriptor-meta-BTFnIGJ6.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"descriptor-meta-BTFnIGJ6.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\n/**\n * Built-in ParadeDB tokenizer IDs.\n * These correspond to the `pdb.*` casting syntax in `CREATE INDEX ... USING bm25`.\n */\nexport type TokenizerId =\n | 'unicode_words'\n | 'simple'\n | 'ngram'\n | 'icu'\n | 'regex_pattern'\n | 'source_code'\n | 'literal'\n | 'literal_normalized'\n | 'whitespace'\n | 'chinese_compatible'\n | 'jieba'\n | 'lindera';\n","import { 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} as const;\n"],"mappings":";;;;AAGA,MAAa,wBAAwB;;;;ACDrC,MAAa,mBAAmB;CAC9B,MAAM;CACN,IAAI;CACJ,UAAU;CACV,UAAU;CACV,SAAS;CACT,cAAc,EACZ,UAAU,EACR,iBAAiB,MAClB,EACF;CACF"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { IndexDef } from "@prisma-next/contract-authoring";
|
|
2
|
+
|
|
3
|
+
//#region src/core/constants.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Built-in ParadeDB tokenizer IDs.
|
|
7
|
+
* These correspond to the `pdb.*` casting syntax in `CREATE INDEX ... USING bm25`.
|
|
8
|
+
*/
|
|
9
|
+
type TokenizerId = 'unicode_words' | 'simple' | 'ngram' | 'icu' | 'regex_pattern' | 'source_code' | 'literal' | 'literal_normalized' | 'whitespace' | 'chinese_compatible' | 'jieba' | 'lindera';
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/types/index-types.d.ts
|
|
12
|
+
/**
|
|
13
|
+
* BM25 field config for a table column.
|
|
14
|
+
*/
|
|
15
|
+
type Bm25ColumnFieldConfig = {
|
|
16
|
+
readonly column: string;
|
|
17
|
+
readonly expression?: never;
|
|
18
|
+
readonly tokenizer?: string;
|
|
19
|
+
readonly tokenizerParams?: Record<string, unknown>;
|
|
20
|
+
readonly alias?: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* BM25 field config for a SQL expression.
|
|
24
|
+
*/
|
|
25
|
+
type Bm25ExpressionFieldConfig = {
|
|
26
|
+
readonly expression: string;
|
|
27
|
+
readonly column?: never;
|
|
28
|
+
readonly alias: string;
|
|
29
|
+
readonly tokenizer?: string;
|
|
30
|
+
readonly tokenizerParams?: Record<string, unknown>;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* BM25 field config union.
|
|
34
|
+
*/
|
|
35
|
+
type Bm25FieldConfig = Bm25ColumnFieldConfig | Bm25ExpressionFieldConfig;
|
|
36
|
+
/**
|
|
37
|
+
* BM25 index configuration payload stored in `IndexDef.config`.
|
|
38
|
+
*/
|
|
39
|
+
type Bm25IndexConfig = {
|
|
40
|
+
readonly keyField: string;
|
|
41
|
+
readonly fields: readonly Bm25FieldConfig[];
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Options for a BM25 text field (text, varchar columns).
|
|
45
|
+
*/
|
|
46
|
+
type Bm25TextFieldOptions = {
|
|
47
|
+
readonly tokenizer?: TokenizerId | (string & {});
|
|
48
|
+
readonly stemmer?: string;
|
|
49
|
+
readonly alias?: string;
|
|
50
|
+
readonly remove_emojis?: boolean;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Options for a BM25 JSON field (json, jsonb columns).
|
|
54
|
+
*/
|
|
55
|
+
type Bm25JsonFieldOptions = {
|
|
56
|
+
readonly tokenizer?: TokenizerId | (string & {});
|
|
57
|
+
readonly alias?: string;
|
|
58
|
+
/** Ngram-specific params when tokenizer is 'ngram'. */
|
|
59
|
+
readonly min?: number;
|
|
60
|
+
readonly max?: number;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Options for a BM25 expression-based field.
|
|
64
|
+
*/
|
|
65
|
+
type Bm25ExpressionFieldOptions = {
|
|
66
|
+
readonly alias: string;
|
|
67
|
+
readonly tokenizer?: TokenizerId | (string & {});
|
|
68
|
+
readonly min?: number;
|
|
69
|
+
readonly max?: number;
|
|
70
|
+
readonly stemmer?: string;
|
|
71
|
+
readonly pattern?: string;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Options for constructing a BM25 index definition.
|
|
75
|
+
*/
|
|
76
|
+
type Bm25IndexOptions = {
|
|
77
|
+
readonly keyField: string;
|
|
78
|
+
readonly fields: readonly Bm25FieldConfig[];
|
|
79
|
+
readonly name?: string;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Typed BM25 field builders.
|
|
83
|
+
* These produce `Bm25FieldConfig` objects for use in `bm25Index()`.
|
|
84
|
+
*/
|
|
85
|
+
declare const bm25: {
|
|
86
|
+
/** Text field with optional tokenizer config. */
|
|
87
|
+
readonly text: (column: string, opts?: Bm25TextFieldOptions) => Bm25FieldConfig;
|
|
88
|
+
/** Numeric field (filterable, sortable in BM25). */
|
|
89
|
+
readonly numeric: (column: string) => Bm25FieldConfig;
|
|
90
|
+
/** Boolean field. */
|
|
91
|
+
readonly boolean: (column: string) => Bm25FieldConfig;
|
|
92
|
+
/** JSON/JSONB field with optional tokenizer config. */
|
|
93
|
+
readonly json: (column: string, opts?: Bm25JsonFieldOptions) => Bm25FieldConfig;
|
|
94
|
+
/** Datetime (timestamp/date) field. */
|
|
95
|
+
readonly datetime: (column: string) => Bm25FieldConfig;
|
|
96
|
+
/** Range field. */
|
|
97
|
+
readonly range: (column: string) => Bm25FieldConfig;
|
|
98
|
+
/** Raw SQL expression field. `alias` is required. */
|
|
99
|
+
readonly expression: (sql: string, opts: Bm25ExpressionFieldOptions) => Bm25FieldConfig;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Creates a generic index definition with a ParadeDB BM25 payload.
|
|
103
|
+
*
|
|
104
|
+
* `columns` only includes real table columns so core index validation remains
|
|
105
|
+
* target-agnostic. Expression fields stay in extension-owned `config.fields`.
|
|
106
|
+
*/
|
|
107
|
+
declare function bm25Index(opts: Bm25IndexOptions): IndexDef;
|
|
108
|
+
//#endregion
|
|
109
|
+
export { type Bm25ColumnFieldConfig, type Bm25ExpressionFieldConfig, type Bm25ExpressionFieldOptions, type Bm25FieldConfig, type Bm25IndexConfig, type Bm25IndexOptions, type Bm25JsonFieldOptions, type Bm25TextFieldOptions, type TokenizerId, bm25, bm25Index };
|
|
110
|
+
//# sourceMappingURL=index-types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-types.d.mts","names":[],"sources":["../src/core/constants.ts","../src/types/index-types.ts"],"sourcesContent":[],"mappings":";;;;;;;ACMA;AAWY,KDRA,WAAA,GCQA,eAAyB,GAKR,QAAM,GAAA,OAAA,GAAA,KAAA,GAAA,eAAA,GAAA,aAAA,GAAA,SAAA,GAAA,oBAAA,GAAA,YAAA,GAAA,oBAAA,GAAA,OAAA,GAAA,SAAA;;;;ADbnC;;KCHY,qBAAA;;EAAA,SAAA,UAAA,CAAA,EAAA,KAAqB;EAWrB,SAAA,SAAA,CAAA,EAAA,MAAA;EAWA,SAAA,eAAe,CAAA,EAlBE,MAkBC,CAAA,MAAA,EAAA,OAAA,CAAA;EAKlB,SAAA,KAAA,CAAA,EAAA,MAAe;AAQ3B,CAAA;AAUA;AAWA;AAiBA;AAUa,KAxED,yBAAA,GA+HF;EArDoB,SAAA,UAAA,EAAA,MAAA;EAAuB,SAAA,MAAA,CAAA,EAAA,KAAA;EAY1B,SAAA,KAAA,EAAA,MAAA;EAKA,SAAA,SAAA,CAAA,EAAA,MAAA;EAKG,SAAA,eAAA,CAAA,EA3FD,MA2FC,CAAA,MAAA,EAAA,OAAA,CAAA;CAAuB;;;;AAmBQ,KAxGjD,eAAA,GAAkB,qBAwG+B,GAxGP,yBAwGO;;AAoB7D;;KAvHY,eAAA;;4BAEgB;;;;;KAMhB,oBAAA;uBACW;;;;;;;;KASX,oBAAA;uBACW;;;;;;;;;KAUX,0BAAA;;uBAEW;;;;;;;;;KAeX,gBAAA;;4BAEgB;;;;;;;cAQf;;yCAEiB,yBAAuB;;wCAY1B;;wCAKA;;yCAKG,yBAAuB;;yCASzB;;sCAKH;;2CAKO,+BAA6B;;;;;;;;iBAoB7C,SAAA,OAAgB,mBAAmB"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
//#region src/types/index-types.ts
|
|
2
|
+
/**
|
|
3
|
+
* Typed BM25 field builders.
|
|
4
|
+
* These produce `Bm25FieldConfig` objects for use in `bm25Index()`.
|
|
5
|
+
*/
|
|
6
|
+
const bm25 = {
|
|
7
|
+
text(column, opts) {
|
|
8
|
+
return {
|
|
9
|
+
column,
|
|
10
|
+
...buildTokenizerConfig(opts?.tokenizer, {
|
|
11
|
+
stemmer: opts?.stemmer,
|
|
12
|
+
remove_emojis: opts?.remove_emojis
|
|
13
|
+
}),
|
|
14
|
+
...opts?.alias !== void 0 && { alias: opts.alias }
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
numeric(column) {
|
|
18
|
+
return { column };
|
|
19
|
+
},
|
|
20
|
+
boolean(column) {
|
|
21
|
+
return { column };
|
|
22
|
+
},
|
|
23
|
+
json(column, opts) {
|
|
24
|
+
return {
|
|
25
|
+
column,
|
|
26
|
+
...buildTokenizerConfig(opts?.tokenizer, {
|
|
27
|
+
min: opts?.min,
|
|
28
|
+
max: opts?.max
|
|
29
|
+
}),
|
|
30
|
+
...opts?.alias !== void 0 && { alias: opts.alias }
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
datetime(column) {
|
|
34
|
+
return { column };
|
|
35
|
+
},
|
|
36
|
+
range(column) {
|
|
37
|
+
return { column };
|
|
38
|
+
},
|
|
39
|
+
expression(sql, opts) {
|
|
40
|
+
return {
|
|
41
|
+
expression: sql,
|
|
42
|
+
alias: opts.alias,
|
|
43
|
+
...buildTokenizerConfig(opts.tokenizer, {
|
|
44
|
+
min: opts.min,
|
|
45
|
+
max: opts.max,
|
|
46
|
+
stemmer: opts.stemmer,
|
|
47
|
+
pattern: opts.pattern
|
|
48
|
+
})
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Creates a generic index definition with a ParadeDB BM25 payload.
|
|
54
|
+
*
|
|
55
|
+
* `columns` only includes real table columns so core index validation remains
|
|
56
|
+
* target-agnostic. Expression fields stay in extension-owned `config.fields`.
|
|
57
|
+
*/
|
|
58
|
+
function bm25Index(opts) {
|
|
59
|
+
return {
|
|
60
|
+
columns: opts.fields.flatMap((field) => "column" in field ? [field.column] : []),
|
|
61
|
+
...opts.name !== void 0 && { name: opts.name },
|
|
62
|
+
using: "bm25",
|
|
63
|
+
config: {
|
|
64
|
+
keyField: opts.keyField,
|
|
65
|
+
fields: opts.fields
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Builds `{ tokenizer, tokenizerParams? }` from a tokenizer ID and a bag of params.
|
|
71
|
+
* Filters out undefined values and omits `tokenizerParams` when empty.
|
|
72
|
+
*/
|
|
73
|
+
function buildTokenizerConfig(tokenizer, params) {
|
|
74
|
+
if (!tokenizer) return {};
|
|
75
|
+
const filtered = Object.fromEntries(Object.entries(params).filter(([, v]) => v !== void 0));
|
|
76
|
+
return {
|
|
77
|
+
tokenizer,
|
|
78
|
+
...Object.keys(filtered).length > 0 && { tokenizerParams: filtered }
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
//#endregion
|
|
83
|
+
export { bm25, bm25Index };
|
|
84
|
+
//# sourceMappingURL=index-types.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-types.mjs","names":[],"sources":["../src/types/index-types.ts"],"sourcesContent":["import type { IndexDef } from '@prisma-next/contract-authoring';\nimport type { TokenizerId } from '../core/constants';\n\n/**\n * BM25 field config for a table column.\n */\nexport type Bm25ColumnFieldConfig = {\n readonly column: string;\n readonly expression?: never;\n readonly tokenizer?: string;\n readonly tokenizerParams?: Record<string, unknown>;\n readonly alias?: string;\n};\n\n/**\n * BM25 field config for a SQL expression.\n */\nexport type Bm25ExpressionFieldConfig = {\n readonly expression: string;\n readonly column?: never;\n readonly alias: string;\n readonly tokenizer?: string;\n readonly tokenizerParams?: Record<string, unknown>;\n};\n\n/**\n * BM25 field config union.\n */\nexport type Bm25FieldConfig = Bm25ColumnFieldConfig | Bm25ExpressionFieldConfig;\n\n/**\n * BM25 index configuration payload stored in `IndexDef.config`.\n */\nexport type Bm25IndexConfig = {\n readonly keyField: string;\n readonly fields: readonly Bm25FieldConfig[];\n};\n\n/**\n * Options for a BM25 text field (text, varchar columns).\n */\nexport type Bm25TextFieldOptions = {\n readonly tokenizer?: TokenizerId | (string & {});\n readonly stemmer?: string;\n readonly alias?: string;\n readonly remove_emojis?: boolean;\n};\n\n/**\n * Options for a BM25 JSON field (json, jsonb columns).\n */\nexport type Bm25JsonFieldOptions = {\n readonly tokenizer?: TokenizerId | (string & {});\n readonly alias?: string;\n /** Ngram-specific params when tokenizer is 'ngram'. */\n readonly min?: number;\n readonly max?: number;\n};\n\n/**\n * Options for a BM25 expression-based field.\n */\nexport type Bm25ExpressionFieldOptions = {\n readonly alias: string;\n readonly tokenizer?: TokenizerId | (string & {});\n readonly min?: number;\n readonly max?: number;\n readonly stemmer?: string;\n readonly pattern?: string;\n};\n\ntype TokenizerConfig = {\n readonly tokenizer?: string;\n readonly tokenizerParams?: Record<string, unknown>;\n};\n\n/**\n * Options for constructing a BM25 index definition.\n */\nexport type Bm25IndexOptions = {\n readonly keyField: string;\n readonly fields: readonly Bm25FieldConfig[];\n readonly name?: string;\n};\n\n/**\n * Typed BM25 field builders.\n * These produce `Bm25FieldConfig` objects for use in `bm25Index()`.\n */\nexport const bm25 = {\n /** Text field with optional tokenizer config. */\n text(column: string, opts?: Bm25TextFieldOptions): Bm25FieldConfig {\n return {\n column,\n ...buildTokenizerConfig(opts?.tokenizer, {\n stemmer: opts?.stemmer,\n remove_emojis: opts?.remove_emojis,\n }),\n ...(opts?.alias !== undefined && { alias: opts.alias }),\n };\n },\n\n /** Numeric field (filterable, sortable in BM25). */\n numeric(column: string): Bm25FieldConfig {\n return { column };\n },\n\n /** Boolean field. */\n boolean(column: string): Bm25FieldConfig {\n return { column };\n },\n\n /** JSON/JSONB field with optional tokenizer config. */\n json(column: string, opts?: Bm25JsonFieldOptions): Bm25FieldConfig {\n return {\n column,\n ...buildTokenizerConfig(opts?.tokenizer, { min: opts?.min, max: opts?.max }),\n ...(opts?.alias !== undefined && { alias: opts.alias }),\n };\n },\n\n /** Datetime (timestamp/date) field. */\n datetime(column: string): Bm25FieldConfig {\n return { column };\n },\n\n /** Range field. */\n range(column: string): Bm25FieldConfig {\n return { column };\n },\n\n /** Raw SQL expression field. `alias` is required. */\n expression(sql: string, opts: Bm25ExpressionFieldOptions): Bm25FieldConfig {\n return {\n expression: sql,\n alias: opts.alias,\n ...buildTokenizerConfig(opts.tokenizer, {\n min: opts.min,\n max: opts.max,\n stemmer: opts.stemmer,\n pattern: opts.pattern,\n }),\n };\n },\n} as const;\n\n/**\n * Creates a generic index definition with a ParadeDB BM25 payload.\n *\n * `columns` only includes real table columns so core index validation remains\n * target-agnostic. Expression fields stay in extension-owned `config.fields`.\n */\nexport function bm25Index(opts: Bm25IndexOptions): IndexDef {\n return {\n columns: opts.fields.flatMap((field) => ('column' in field ? [field.column] : [])),\n ...(opts.name !== undefined && { name: opts.name }),\n using: 'bm25',\n config: {\n keyField: opts.keyField,\n fields: opts.fields,\n } satisfies Bm25IndexConfig,\n };\n}\n\n/**\n * Builds `{ tokenizer, tokenizerParams? }` from a tokenizer ID and a bag of params.\n * Filters out undefined values and omits `tokenizerParams` when empty.\n */\nfunction buildTokenizerConfig(\n tokenizer: string | undefined,\n params: Record<string, unknown>,\n): TokenizerConfig {\n if (!tokenizer) return {};\n const filtered = Object.fromEntries(Object.entries(params).filter(([, v]) => v !== undefined));\n return {\n tokenizer,\n ...(Object.keys(filtered).length > 0 && { tokenizerParams: filtered }),\n };\n}\n"],"mappings":";;;;;AAyFA,MAAa,OAAO;CAElB,KAAK,QAAgB,MAA8C;AACjE,SAAO;GACL;GACA,GAAG,qBAAqB,MAAM,WAAW;IACvC,SAAS,MAAM;IACf,eAAe,MAAM;IACtB,CAAC;GACF,GAAI,MAAM,UAAU,UAAa,EAAE,OAAO,KAAK,OAAO;GACvD;;CAIH,QAAQ,QAAiC;AACvC,SAAO,EAAE,QAAQ;;CAInB,QAAQ,QAAiC;AACvC,SAAO,EAAE,QAAQ;;CAInB,KAAK,QAAgB,MAA8C;AACjE,SAAO;GACL;GACA,GAAG,qBAAqB,MAAM,WAAW;IAAE,KAAK,MAAM;IAAK,KAAK,MAAM;IAAK,CAAC;GAC5E,GAAI,MAAM,UAAU,UAAa,EAAE,OAAO,KAAK,OAAO;GACvD;;CAIH,SAAS,QAAiC;AACxC,SAAO,EAAE,QAAQ;;CAInB,MAAM,QAAiC;AACrC,SAAO,EAAE,QAAQ;;CAInB,WAAW,KAAa,MAAmD;AACzE,SAAO;GACL,YAAY;GACZ,OAAO,KAAK;GACZ,GAAG,qBAAqB,KAAK,WAAW;IACtC,KAAK,KAAK;IACV,KAAK,KAAK;IACV,SAAS,KAAK;IACd,SAAS,KAAK;IACf,CAAC;GACH;;CAEJ;;;;;;;AAQD,SAAgB,UAAU,MAAkC;AAC1D,QAAO;EACL,SAAS,KAAK,OAAO,SAAS,UAAW,YAAY,QAAQ,CAAC,MAAM,OAAO,GAAG,EAAE,CAAE;EAClF,GAAI,KAAK,SAAS,UAAa,EAAE,MAAM,KAAK,MAAM;EAClD,OAAO;EACP,QAAQ;GACN,UAAU,KAAK;GACf,QAAQ,KAAK;GACd;EACF;;;;;;AAOH,SAAS,qBACP,WACA,QACiB;AACjB,KAAI,CAAC,UAAW,QAAO,EAAE;CACzB,MAAM,WAAW,OAAO,YAAY,OAAO,QAAQ,OAAO,CAAC,QAAQ,GAAG,OAAO,MAAM,OAAU,CAAC;AAC9F,QAAO;EACL;EACA,GAAI,OAAO,KAAK,SAAS,CAAC,SAAS,KAAK,EAAE,iBAAiB,UAAU;EACtE"}
|
package/dist/pack.d.mts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/exports/pack.d.ts
|
|
2
|
+
declare const paradedbPack: {
|
|
3
|
+
readonly kind: "extension";
|
|
4
|
+
readonly id: "paradedb";
|
|
5
|
+
readonly familyId: "sql";
|
|
6
|
+
readonly targetId: "postgres";
|
|
7
|
+
readonly version: "0.0.1";
|
|
8
|
+
readonly capabilities: {
|
|
9
|
+
readonly postgres: {
|
|
10
|
+
readonly 'paradedb/bm25': true;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { paradedbPack as default };
|
|
16
|
+
//# sourceMappingURL=pack.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pack.d.mts","names":[],"sources":["../src/exports/pack.ts"],"sourcesContent":[],"mappings":";cAEM;EAAA,SAAA,IAAA,EAA+B,WAAA"}
|
package/dist/pack.mjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { t as paradedbPackMeta } from "./descriptor-meta-BTFnIGJ6.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/exports/pack.ts
|
|
4
|
+
const paradedbPack = paradedbPackMeta;
|
|
5
|
+
var pack_default = paradedbPack;
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
export { pack_default as default };
|
|
9
|
+
//# sourceMappingURL=pack.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pack.mjs","names":[],"sources":["../src/exports/pack.ts"],"sourcesContent":["import { paradedbPackMeta } from '../core/descriptor-meta';\n\nconst paradedbPack = paradedbPackMeta;\n\nexport default paradedbPack;\n"],"mappings":";;;AAEA,MAAM,eAAe;AAErB,mBAAe"}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@prisma-next/extension-paradedb",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@prisma-next/contract": "0.0.1",
|
|
8
|
+
"@prisma-next/contract-authoring": "0.0.1"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"tsdown": "0.18.4",
|
|
12
|
+
"typescript": "5.9.3",
|
|
13
|
+
"vitest": "4.0.17",
|
|
14
|
+
"@prisma-next/tsconfig": "0.0.0",
|
|
15
|
+
"@prisma-next/tsdown": "0.0.0"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"src"
|
|
20
|
+
],
|
|
21
|
+
"exports": {
|
|
22
|
+
"./control": "./dist/control.mjs",
|
|
23
|
+
"./index-types": "./dist/index-types.mjs",
|
|
24
|
+
"./pack": "./dist/pack.mjs",
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/prisma/prisma-next.git",
|
|
30
|
+
"directory": "packages/3-extensions/paradedb"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsdown",
|
|
34
|
+
"test": "vitest run",
|
|
35
|
+
"test:coverage": "vitest run --coverage",
|
|
36
|
+
"typecheck": "tsc --project tsconfig.json --noEmit",
|
|
37
|
+
"lint": "biome check . --error-on-warnings",
|
|
38
|
+
"lint:fix": "biome check --write .",
|
|
39
|
+
"lint:fix:unsafe": "biome check --write --unsafe .",
|
|
40
|
+
"clean": "rm -rf dist dist-tsc dist-tsc-prod coverage .tmp-output"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extension ID for ParadeDB pg_search.
|
|
3
|
+
*/
|
|
4
|
+
export const PARADEDB_EXTENSION_ID = 'paradedb' as const;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Built-in ParadeDB tokenizer IDs.
|
|
8
|
+
* These correspond to the `pdb.*` casting syntax in `CREATE INDEX ... USING bm25`.
|
|
9
|
+
*/
|
|
10
|
+
export type TokenizerId =
|
|
11
|
+
| 'unicode_words'
|
|
12
|
+
| 'simple'
|
|
13
|
+
| 'ngram'
|
|
14
|
+
| 'icu'
|
|
15
|
+
| 'regex_pattern'
|
|
16
|
+
| 'source_code'
|
|
17
|
+
| 'literal'
|
|
18
|
+
| 'literal_normalized'
|
|
19
|
+
| 'whitespace'
|
|
20
|
+
| 'chinese_compatible'
|
|
21
|
+
| 'jieba'
|
|
22
|
+
| 'lindera';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PARADEDB_EXTENSION_ID } from './constants';
|
|
2
|
+
|
|
3
|
+
export const paradedbPackMeta = {
|
|
4
|
+
kind: 'extension',
|
|
5
|
+
id: PARADEDB_EXTENSION_ID,
|
|
6
|
+
familyId: 'sql',
|
|
7
|
+
targetId: 'postgres',
|
|
8
|
+
version: '0.0.1',
|
|
9
|
+
capabilities: {
|
|
10
|
+
postgres: {
|
|
11
|
+
'paradedb/bm25': true,
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
} as const;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type { TokenizerId } from '../core/constants';
|
|
2
|
+
export type {
|
|
3
|
+
Bm25ColumnFieldConfig,
|
|
4
|
+
Bm25ExpressionFieldConfig,
|
|
5
|
+
Bm25ExpressionFieldOptions,
|
|
6
|
+
Bm25FieldConfig,
|
|
7
|
+
Bm25IndexConfig,
|
|
8
|
+
Bm25IndexOptions,
|
|
9
|
+
Bm25JsonFieldOptions,
|
|
10
|
+
Bm25TextFieldOptions,
|
|
11
|
+
} from '../types/index-types';
|
|
12
|
+
export { bm25, bm25Index } from '../types/index-types';
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import type { IndexDef } from '@prisma-next/contract-authoring';
|
|
2
|
+
import type { TokenizerId } from '../core/constants';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* BM25 field config for a table column.
|
|
6
|
+
*/
|
|
7
|
+
export type Bm25ColumnFieldConfig = {
|
|
8
|
+
readonly column: string;
|
|
9
|
+
readonly expression?: never;
|
|
10
|
+
readonly tokenizer?: string;
|
|
11
|
+
readonly tokenizerParams?: Record<string, unknown>;
|
|
12
|
+
readonly alias?: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* BM25 field config for a SQL expression.
|
|
17
|
+
*/
|
|
18
|
+
export type Bm25ExpressionFieldConfig = {
|
|
19
|
+
readonly expression: string;
|
|
20
|
+
readonly column?: never;
|
|
21
|
+
readonly alias: string;
|
|
22
|
+
readonly tokenizer?: string;
|
|
23
|
+
readonly tokenizerParams?: Record<string, unknown>;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* BM25 field config union.
|
|
28
|
+
*/
|
|
29
|
+
export type Bm25FieldConfig = Bm25ColumnFieldConfig | Bm25ExpressionFieldConfig;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* BM25 index configuration payload stored in `IndexDef.config`.
|
|
33
|
+
*/
|
|
34
|
+
export type Bm25IndexConfig = {
|
|
35
|
+
readonly keyField: string;
|
|
36
|
+
readonly fields: readonly Bm25FieldConfig[];
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Options for a BM25 text field (text, varchar columns).
|
|
41
|
+
*/
|
|
42
|
+
export type Bm25TextFieldOptions = {
|
|
43
|
+
readonly tokenizer?: TokenizerId | (string & {});
|
|
44
|
+
readonly stemmer?: string;
|
|
45
|
+
readonly alias?: string;
|
|
46
|
+
readonly remove_emojis?: boolean;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Options for a BM25 JSON field (json, jsonb columns).
|
|
51
|
+
*/
|
|
52
|
+
export type Bm25JsonFieldOptions = {
|
|
53
|
+
readonly tokenizer?: TokenizerId | (string & {});
|
|
54
|
+
readonly alias?: string;
|
|
55
|
+
/** Ngram-specific params when tokenizer is 'ngram'. */
|
|
56
|
+
readonly min?: number;
|
|
57
|
+
readonly max?: number;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Options for a BM25 expression-based field.
|
|
62
|
+
*/
|
|
63
|
+
export type Bm25ExpressionFieldOptions = {
|
|
64
|
+
readonly alias: string;
|
|
65
|
+
readonly tokenizer?: TokenizerId | (string & {});
|
|
66
|
+
readonly min?: number;
|
|
67
|
+
readonly max?: number;
|
|
68
|
+
readonly stemmer?: string;
|
|
69
|
+
readonly pattern?: string;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
type TokenizerConfig = {
|
|
73
|
+
readonly tokenizer?: string;
|
|
74
|
+
readonly tokenizerParams?: Record<string, unknown>;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Options for constructing a BM25 index definition.
|
|
79
|
+
*/
|
|
80
|
+
export type Bm25IndexOptions = {
|
|
81
|
+
readonly keyField: string;
|
|
82
|
+
readonly fields: readonly Bm25FieldConfig[];
|
|
83
|
+
readonly name?: string;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Typed BM25 field builders.
|
|
88
|
+
* These produce `Bm25FieldConfig` objects for use in `bm25Index()`.
|
|
89
|
+
*/
|
|
90
|
+
export const bm25 = {
|
|
91
|
+
/** Text field with optional tokenizer config. */
|
|
92
|
+
text(column: string, opts?: Bm25TextFieldOptions): Bm25FieldConfig {
|
|
93
|
+
return {
|
|
94
|
+
column,
|
|
95
|
+
...buildTokenizerConfig(opts?.tokenizer, {
|
|
96
|
+
stemmer: opts?.stemmer,
|
|
97
|
+
remove_emojis: opts?.remove_emojis,
|
|
98
|
+
}),
|
|
99
|
+
...(opts?.alias !== undefined && { alias: opts.alias }),
|
|
100
|
+
};
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
/** Numeric field (filterable, sortable in BM25). */
|
|
104
|
+
numeric(column: string): Bm25FieldConfig {
|
|
105
|
+
return { column };
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
/** Boolean field. */
|
|
109
|
+
boolean(column: string): Bm25FieldConfig {
|
|
110
|
+
return { column };
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
/** JSON/JSONB field with optional tokenizer config. */
|
|
114
|
+
json(column: string, opts?: Bm25JsonFieldOptions): Bm25FieldConfig {
|
|
115
|
+
return {
|
|
116
|
+
column,
|
|
117
|
+
...buildTokenizerConfig(opts?.tokenizer, { min: opts?.min, max: opts?.max }),
|
|
118
|
+
...(opts?.alias !== undefined && { alias: opts.alias }),
|
|
119
|
+
};
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
/** Datetime (timestamp/date) field. */
|
|
123
|
+
datetime(column: string): Bm25FieldConfig {
|
|
124
|
+
return { column };
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
/** Range field. */
|
|
128
|
+
range(column: string): Bm25FieldConfig {
|
|
129
|
+
return { column };
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
/** Raw SQL expression field. `alias` is required. */
|
|
133
|
+
expression(sql: string, opts: Bm25ExpressionFieldOptions): Bm25FieldConfig {
|
|
134
|
+
return {
|
|
135
|
+
expression: sql,
|
|
136
|
+
alias: opts.alias,
|
|
137
|
+
...buildTokenizerConfig(opts.tokenizer, {
|
|
138
|
+
min: opts.min,
|
|
139
|
+
max: opts.max,
|
|
140
|
+
stemmer: opts.stemmer,
|
|
141
|
+
pattern: opts.pattern,
|
|
142
|
+
}),
|
|
143
|
+
};
|
|
144
|
+
},
|
|
145
|
+
} as const;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Creates a generic index definition with a ParadeDB BM25 payload.
|
|
149
|
+
*
|
|
150
|
+
* `columns` only includes real table columns so core index validation remains
|
|
151
|
+
* target-agnostic. Expression fields stay in extension-owned `config.fields`.
|
|
152
|
+
*/
|
|
153
|
+
export function bm25Index(opts: Bm25IndexOptions): IndexDef {
|
|
154
|
+
return {
|
|
155
|
+
columns: opts.fields.flatMap((field) => ('column' in field ? [field.column] : [])),
|
|
156
|
+
...(opts.name !== undefined && { name: opts.name }),
|
|
157
|
+
using: 'bm25',
|
|
158
|
+
config: {
|
|
159
|
+
keyField: opts.keyField,
|
|
160
|
+
fields: opts.fields,
|
|
161
|
+
} satisfies Bm25IndexConfig,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Builds `{ tokenizer, tokenizerParams? }` from a tokenizer ID and a bag of params.
|
|
167
|
+
* Filters out undefined values and omits `tokenizerParams` when empty.
|
|
168
|
+
*/
|
|
169
|
+
function buildTokenizerConfig(
|
|
170
|
+
tokenizer: string | undefined,
|
|
171
|
+
params: Record<string, unknown>,
|
|
172
|
+
): TokenizerConfig {
|
|
173
|
+
if (!tokenizer) return {};
|
|
174
|
+
const filtered = Object.fromEntries(Object.entries(params).filter(([, v]) => v !== undefined));
|
|
175
|
+
return {
|
|
176
|
+
tokenizer,
|
|
177
|
+
...(Object.keys(filtered).length > 0 && { tokenizerParams: filtered }),
|
|
178
|
+
};
|
|
179
|
+
}
|