@prisma-next/extension-pgvector 0.5.0-dev.9 → 0.6.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -6
- package/dist/codec-types-CQubO6uQ.d.mts +63 -0
- package/dist/codec-types-CQubO6uQ.d.mts.map +1 -0
- package/dist/codec-types.d.mts +1 -1
- package/dist/codec-types.mjs +1 -1
- package/dist/column-types.d.mts +2 -5
- package/dist/column-types.d.mts.map +1 -1
- package/dist/column-types.mjs +4 -7
- package/dist/column-types.mjs.map +1 -1
- package/dist/{constants-Co5golCK.mjs → constants-DX-00vYk.mjs} +2 -2
- package/dist/{constants-Co5golCK.mjs.map → constants-DX-00vYk.mjs.map} +1 -1
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +163 -30
- package/dist/control.mjs.map +1 -1
- package/dist/descriptor-meta-DEgJjLLi.mjs +178 -0
- package/dist/descriptor-meta-DEgJjLLi.mjs.map +1 -0
- package/dist/operation-types-Bd-jkNN3.d.mts +38 -0
- package/dist/operation-types-Bd-jkNN3.d.mts.map +1 -0
- package/dist/operation-types.d.mts +2 -76
- package/dist/operation-types.mjs +1 -1
- package/dist/pack.d.mts +3 -10
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +2 -3
- package/dist/runtime.d.mts +10 -1
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +6 -25
- package/dist/runtime.mjs.map +1 -1
- package/package.json +32 -17
- package/src/contract.d.ts +91 -0
- package/src/contract.json +40 -0
- package/src/contract.ts +67 -0
- package/src/core/codecs.ts +127 -59
- package/src/core/contract-space-constants.ts +30 -0
- package/src/core/descriptor-meta.ts +40 -36
- package/src/core/registry.ts +11 -0
- package/src/exports/column-types.ts +3 -6
- package/src/exports/control.ts +56 -35
- package/src/exports/operation-types.ts +1 -1
- package/src/exports/runtime.ts +11 -41
- package/src/types/operation-types.ts +19 -36
- package/dist/codec-types-BifaP625.d.mts +0 -27
- package/dist/codec-types-BifaP625.d.mts.map +0 -1
- package/dist/descriptor-meta-BQbvJJxu.mjs +0 -148
- package/dist/descriptor-meta-BQbvJJxu.mjs.map +0 -1
- package/dist/operation-types.d.mts.map +0 -1
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ This extension pack adds support for the `vector` data type and vector similarit
|
|
|
13
13
|
- **CLI Integration**: Provides extension descriptor for `prisma-next.config.ts` configuration
|
|
14
14
|
- **Runtime Extension**: Registers codecs and operations at runtime for vector column operations
|
|
15
15
|
- **Pack Ref Export**: Ships a pure `/pack` entrypoint for TypeScript contract authoring without runtime filesystem access
|
|
16
|
-
- **
|
|
16
|
+
- **Baseline Migration**: Ships an on-disk baseline migration in its contract space that installs the `vector` Postgres extension (`CREATE EXTENSION IF NOT EXISTS vector`) when the extension is composed into an application
|
|
17
17
|
|
|
18
18
|
## Dependencies
|
|
19
19
|
|
|
@@ -30,15 +30,15 @@ pnpm add @prisma-next/extension-pgvector
|
|
|
30
30
|
|
|
31
31
|
## Database Setup
|
|
32
32
|
|
|
33
|
-
The pgvector extension
|
|
33
|
+
The pgvector extension ships an on-disk baseline migration in its contract space; applying that migration installs pgvector with `CREATE EXTENSION IF NOT EXISTS vector`. When the extension is composed into an application via `extensionPacks`, `prisma-next db init` and `prisma-next db update` apply the baseline (and any subsequent migrations) automatically.
|
|
34
34
|
|
|
35
|
-
For manual database setup,
|
|
35
|
+
For manual database setup, the equivalent DDL is:
|
|
36
36
|
|
|
37
37
|
```sql
|
|
38
38
|
CREATE EXTENSION IF NOT EXISTS vector;
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
Ensure the baseline migration (or equivalent DDL) has been applied before running workloads that use vector columns.
|
|
42
42
|
|
|
43
43
|
## Configuration
|
|
44
44
|
|
|
@@ -69,7 +69,7 @@ Add vector columns to your contract and enable the namespace via pack refs:
|
|
|
69
69
|
import { int4Column, textColumn } from '@prisma-next/adapter-postgres/column-types';
|
|
70
70
|
import sqlFamily from '@prisma-next/family-sql/pack';
|
|
71
71
|
import { defineContract, field, model } from '@prisma-next/sql-contract-ts/contract-builder';
|
|
72
|
-
import { vectorColumn } from '@prisma-next/extension-pgvector/column-types';
|
|
72
|
+
import { vector, vectorColumn } from '@prisma-next/extension-pgvector/column-types';
|
|
73
73
|
import pgvector from '@prisma-next/extension-pgvector/pack';
|
|
74
74
|
import postgres from '@prisma-next/target-postgres/pack';
|
|
75
75
|
|
|
@@ -82,13 +82,16 @@ export const contract = defineContract({
|
|
|
82
82
|
fields: {
|
|
83
83
|
id: field.column(int4Column).id(),
|
|
84
84
|
title: field.column(textColumn),
|
|
85
|
-
|
|
85
|
+
// Dimensioned vector — `field.embedding` resolves to `Vector<1536>`.
|
|
86
|
+
embedding: field.column(vector(1536)).optional(),
|
|
86
87
|
},
|
|
87
88
|
}).sql({ table: 'post' }),
|
|
88
89
|
},
|
|
89
90
|
});
|
|
90
91
|
```
|
|
91
92
|
|
|
93
|
+
The `vector(N)` factory is registered through the unified `CodecDescriptor<{ length: number }>` shape — `paramsSchema` validates the dimension at the contract boundary, `renderOutputType: ({ length }) => 'Vector<' + length + '>'` produces the column's TS type for `contract.d.ts`, and the curried `factory` materializes the runtime codec at context construction. See [ADR 208 — Higher-order codecs for parameterized types](../../../docs/architecture%20docs/adrs/ADR%20208%20-%20Higher-order%20codecs%20for%20parameterized%20types.md) for the descriptor model. For undimensioned vector columns (rare; typically only valid in legacy schemas where `vector` was declared without a dimension), use `vectorColumn` instead.
|
|
94
|
+
|
|
92
95
|
### Runtime Setup
|
|
93
96
|
|
|
94
97
|
Register the extension when creating your execution stack:
|
|
@@ -195,10 +198,24 @@ The extension declares the following capabilities:
|
|
|
195
198
|
|
|
196
199
|
- `pgvector.cosine`: Indicates support for cosine distance and similarity operations
|
|
197
200
|
|
|
201
|
+
## Authoring (maintainers)
|
|
202
|
+
|
|
203
|
+
The extension's contract + baseline migration are emitted on-disk inside this package using the same pipeline application authors use:
|
|
204
|
+
|
|
205
|
+
- `pnpm build:contract-space` — runs `prisma-next contract emit` to produce `src/contract.{json,d.ts}` from the TS source at `src/contract.ts`.
|
|
206
|
+
- `pnpm exec prisma-next migration plan --name <slug>` (run from this package directory) — scaffolds a new migration directory under `migrations/<dirName>/` for schema changes that touch tables / models. **Not chained into `pnpm build`**: `migration plan` is non-idempotent (each invocation generates a new timestamped directory), so it runs manually when the contract source changes. Note: pgvector's contract declares only the parameterised `vector` native type under `storage.types` (no tables / models), so the planner currently refuses to scaffold the baseline migration with `PN-CLI-4020 Contract changed but planner produced no operations` (this is **Path B** authoring per [ADR 212](../../../docs/architecture%20docs/adrs/ADR%20212%20-%20Contract%20spaces.md#contract-space-package-layout)). That directory was hand-authored once (Migration subclass + seed `migration.json` preserving the full `toContract`) and `pnpm tsx migrations/<dirName>/migration.ts` re-emits `ops.json` + `migration.json` deterministically. Future migrations that add tables / models can use `migration plan` directly (Path A).
|
|
207
|
+
- `pnpm tsx migrations/<dirName>/migration.ts` (run from this package directory) — re-emits `ops.json` + `migration.json` from the hand-edited subclass. Use `tsx`, not bare `node`, because the Migration subclass imports relative TypeScript siblings which Node's native loader can't resolve without a TS-aware loader.
|
|
208
|
+
- `migrations/refs/head.json` is hand-pinned with the latest migration's `to` hash + `providedInvariants`.
|
|
209
|
+
|
|
210
|
+
The descriptor at `src/exports/control.ts` then JSON-imports those artefacts and synthesises the framework's `MigrationPackage` shape.
|
|
211
|
+
|
|
212
|
+
See [ADR 212 — Contract spaces](../../../docs/architecture%20docs/adrs/ADR%20212%20-%20Contract%20spaces.md) ("Contract-space package layout") for the canonical layout and rationale.
|
|
213
|
+
|
|
198
214
|
## References
|
|
199
215
|
|
|
200
216
|
- [pgvector documentation](https://github.com/pgvector/pgvector)
|
|
201
217
|
- [Prisma Next Architecture Overview](../../../docs/Architecture%20Overview.md)
|
|
202
218
|
- [Extension Packs Guide](../../../docs/reference/Extension-Packs-Naming-and-Layout.md)
|
|
219
|
+
- [ADR 212 — Contract spaces](../../../docs/architecture%20docs/adrs/ADR%20212%20-%20Contract%20spaces.md)
|
|
203
220
|
|
|
204
221
|
Pack refs (`@prisma-next/extension-pgvector/pack`) are pure data objects generated from the hydrated manifest (`src/core/manifest.ts`), so TypeScript contract builders can enable the pgvector namespace in both emit and no-emit workflows without touching the filesystem.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { AnyCodecDescriptor, CodecCallContext, CodecDescriptorImpl, CodecImpl, CodecInstanceContext } from "@prisma-next/framework-components/codec";
|
|
2
|
+
import { JsonValue } from "@prisma-next/contract/types";
|
|
3
|
+
import { ExtractCodecTypes } from "@prisma-next/sql-relational-core/ast";
|
|
4
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
5
|
+
|
|
6
|
+
//#region src/core/constants.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Codec ID for pgvector's vector type.
|
|
9
|
+
*/
|
|
10
|
+
declare const VECTOR_CODEC_ID: "pg/vector@1";
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/core/codecs.d.ts
|
|
13
|
+
type VectorParams = {
|
|
14
|
+
readonly length: number;
|
|
15
|
+
};
|
|
16
|
+
declare class PgVectorCodec extends CodecImpl<typeof VECTOR_CODEC_ID, readonly ['equality'], string, number[]> {
|
|
17
|
+
readonly length: number | undefined;
|
|
18
|
+
constructor(descriptor: AnyCodecDescriptor, length: number | undefined);
|
|
19
|
+
assertVector(value: unknown): asserts value is number[];
|
|
20
|
+
encode(value: number[], _ctx: CodecCallContext): Promise<string>;
|
|
21
|
+
decode(wire: string, _ctx: CodecCallContext): Promise<number[]>;
|
|
22
|
+
encodeJson(value: number[]): JsonValue;
|
|
23
|
+
decodeJson(json: JsonValue): number[];
|
|
24
|
+
}
|
|
25
|
+
declare class PgVectorDescriptor extends CodecDescriptorImpl<VectorParams> {
|
|
26
|
+
readonly codecId: "pg/vector@1";
|
|
27
|
+
readonly traits: readonly ["equality"];
|
|
28
|
+
readonly targetTypes: readonly ["vector"];
|
|
29
|
+
readonly meta: {
|
|
30
|
+
readonly db: {
|
|
31
|
+
readonly sql: {
|
|
32
|
+
readonly postgres: {
|
|
33
|
+
readonly nativeType: "vector";
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
readonly paramsSchema: StandardSchemaV1<VectorParams>;
|
|
39
|
+
renderOutputType(params: VectorParams): string;
|
|
40
|
+
/**
|
|
41
|
+
* The runtime calls `factory(undefined)(ctx)` to materialize a representative codec for parameterized descriptors that ship a no-params column variant (here, `vectorColumn` vs `vector(N)`). The runtime cast widens `params` to `unknown`, so guarding with an optional read keeps the typed call site (`factory({ length })`) strict while still producing a length-agnostic codec for representative use. Encode/decode for an undimensioned column run through this representative; the wire format `[v1,v2,...]` is dimension-independent.
|
|
42
|
+
*/
|
|
43
|
+
factory(params: VectorParams): (ctx: CodecInstanceContext) => PgVectorCodec;
|
|
44
|
+
}
|
|
45
|
+
declare const codecDescriptorMap: {
|
|
46
|
+
readonly vector: PgVectorDescriptor;
|
|
47
|
+
};
|
|
48
|
+
type CodecTypes$1 = ExtractCodecTypes<typeof codecDescriptorMap>;
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/types/codec-types.d.ts
|
|
51
|
+
/**
|
|
52
|
+
* Type-level branded vector.
|
|
53
|
+
*
|
|
54
|
+
* The runtime values are plain number arrays, but parameterized column typing can
|
|
55
|
+
* carry the dimension at the type level (e.g. Vector<1536>).
|
|
56
|
+
*/
|
|
57
|
+
type Vector<N extends number = number> = number[] & {
|
|
58
|
+
readonly __vectorLength?: N;
|
|
59
|
+
};
|
|
60
|
+
type CodecTypes = CodecTypes$1;
|
|
61
|
+
//#endregion
|
|
62
|
+
export { Vector as n, CodecTypes as t };
|
|
63
|
+
//# sourceMappingURL=codec-types-CQubO6uQ.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec-types-CQubO6uQ.d.mts","names":[],"sources":["../src/core/constants.ts","../src/core/codecs.ts","../src/types/codec-types.ts"],"mappings":";;;;;;;;;cAGa,eAAA;;;KCyBR,YAAA;EAAA,SAA0B,MAAA;AAAA;AAAA,cAiBlB,aAAA,SAAsB,SAAA,QAC1B,eAAA;EAAA,SAKE,MAAA;cAEG,UAAA,EAAY,kBAAA,EAAoB,MAAA;EAK5C,YAAA,CAAa,KAAA,oBAAyB,KAAA;EAYhC,MAAA,CAAO,KAAA,YAAiB,IAAA,EAAM,gBAAA,GAAmB,OAAA;EAKjD,MAAA,CAAO,IAAA,UAAc,IAAA,EAAM,gBAAA,GAAmB,OAAA;EAsBpD,UAAA,CAAW,KAAA,aAAkB,SAAA;EAK7B,UAAA,CAAW,IAAA,EAAM,SAAA;AAAA;AAAA,cAMN,kBAAA,SAA2B,mBAAA,CAAoB,YAAA;EAAA,SACxC,OAAA;EAAA,SACA,MAAA;EAAA,SACA,WAAA;EAAA,SACA,IAAA;IAAA;;;;;;;;WACA,YAAA,EAAc,gBAAA,CAAiB,YAAA;EACxC,gBAAA,CAAiB,MAAA,EAAQ,YAAA;EA5C5B;;;EAkDG,OAAA,CAAQ,MAAA,EAAQ,YAAA,IAAgB,GAAA,EAAK,oBAAA,KAAyB,aAAA;AAAA;AAAA,cAkBnE,kBAAA;EAAA,iBAEI,kBAAA;AAAA;AAAA,KAEE,YAAA,GAAa,iBAAA,QAAyB,kBAAA;;;;;;;;AApHY;KCTlD,MAAA;EAAA,SAA0D,cAAA,GAAiB,CAAA;AAAA;AAAA,KAE3E,UAAA,GAAa,YAAA"}
|
package/dist/codec-types.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as Vector, t as CodecTypes } from "./codec-types-
|
|
1
|
+
import { n as Vector, t as CodecTypes } from "./codec-types-CQubO6uQ.mjs";
|
|
2
2
|
export { type CodecTypes, type Vector };
|
package/dist/codec-types.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|
package/dist/column-types.d.mts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { ColumnTypeDescriptor } from "@prisma-next/
|
|
1
|
+
import { ColumnTypeDescriptor } from "@prisma-next/framework-components/codec";
|
|
2
2
|
|
|
3
3
|
//#region src/exports/column-types.d.ts
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
|
-
* Static vector column descriptor without dimension.
|
|
7
|
-
* Use `vector(N)` for dimensioned vectors that produce `vector(N)` DDL.
|
|
5
|
+
* Static vector column descriptor without dimension. Use `vector(N)` for dimensioned vectors that produce `vector(N)` DDL.
|
|
8
6
|
*/
|
|
9
7
|
declare const vectorColumn: {
|
|
10
8
|
readonly codecId: "pg/vector@1";
|
|
@@ -18,7 +16,6 @@ declare const vectorColumn: {
|
|
|
18
16
|
* .column('embedding', { type: vector(1536), nullable: false })
|
|
19
17
|
* // Produces: nativeType: 'vector', typeParams: { length: 1536 }
|
|
20
18
|
* ```
|
|
21
|
-
*
|
|
22
19
|
* @param length - The dimension of the vector (e.g., 1536 for OpenAI embeddings)
|
|
23
20
|
* @returns A column type descriptor with `typeParams.length` set
|
|
24
21
|
* @throws {RangeError} If length is not an integer in the range [1, VECTOR_MAX_DIM]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column-types.d.mts","names":[],"sources":["../src/exports/column-types.ts"],"
|
|
1
|
+
{"version":3,"file":"column-types.d.mts","names":[],"sources":["../src/exports/column-types.ts"],"mappings":";;;;;AA6BA;cAjBa,YAAA;EAAA,SAG4B,OAAA;EAAA,SAAA,UAAA;AAAA;;;;;;;;;;;;;iBAczB,MAAA,kBAAA,CACd,MAAA,EAAQ,CAAA,GACP,oBAAA;EAAA,SAAkC,UAAA;IAAA,SAAuB,MAAA,EAAQ,CAAA;EAAA;AAAA"}
|
package/dist/column-types.mjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { n as VECTOR_MAX_DIM, t as VECTOR_CODEC_ID } from "./constants-
|
|
2
|
-
|
|
1
|
+
import { n as VECTOR_MAX_DIM, t as VECTOR_CODEC_ID } from "./constants-DX-00vYk.mjs";
|
|
3
2
|
//#region src/exports/column-types.ts
|
|
4
3
|
/**
|
|
5
|
-
* Static vector column descriptor without dimension.
|
|
6
|
-
* Use `vector(N)` for dimensioned vectors that produce `vector(N)` DDL.
|
|
4
|
+
* Static vector column descriptor without dimension. Use `vector(N)` for dimensioned vectors that produce `vector(N)` DDL.
|
|
7
5
|
*/
|
|
8
6
|
const vectorColumn = {
|
|
9
7
|
codecId: VECTOR_CODEC_ID,
|
|
@@ -17,20 +15,19 @@ const vectorColumn = {
|
|
|
17
15
|
* .column('embedding', { type: vector(1536), nullable: false })
|
|
18
16
|
* // Produces: nativeType: 'vector', typeParams: { length: 1536 }
|
|
19
17
|
* ```
|
|
20
|
-
*
|
|
21
18
|
* @param length - The dimension of the vector (e.g., 1536 for OpenAI embeddings)
|
|
22
19
|
* @returns A column type descriptor with `typeParams.length` set
|
|
23
20
|
* @throws {RangeError} If length is not an integer in the range [1, VECTOR_MAX_DIM]
|
|
24
21
|
*/
|
|
25
22
|
function vector(length) {
|
|
26
|
-
if (!Number.isInteger(length) || length < 1 || length >
|
|
23
|
+
if (!Number.isInteger(length) || length < 1 || length > 16e3) throw new RangeError(`pgvector: dimension must be an integer in [1, ${VECTOR_MAX_DIM}], got ${length}`);
|
|
27
24
|
return {
|
|
28
25
|
codecId: VECTOR_CODEC_ID,
|
|
29
26
|
nativeType: "vector",
|
|
30
27
|
typeParams: { length }
|
|
31
28
|
};
|
|
32
29
|
}
|
|
33
|
-
|
|
34
30
|
//#endregion
|
|
35
31
|
export { vector, vectorColumn };
|
|
32
|
+
|
|
36
33
|
//# sourceMappingURL=column-types.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column-types.mjs","names":[],"sources":["../src/exports/column-types.ts"],"sourcesContent":["/**\n * Column type descriptors for pgvector extension.\n *\n * These descriptors provide both codecId and nativeType for use in contract authoring
|
|
1
|
+
{"version":3,"file":"column-types.mjs","names":[],"sources":["../src/exports/column-types.ts"],"sourcesContent":["/**\n * Column type descriptors for pgvector extension.\n *\n * These descriptors provide both codecId and nativeType for use in contract authoring. They are derived from the same source of truth as codec definitions and manifests.\n */\n\nimport type { ColumnTypeDescriptor } from '@prisma-next/framework-components/codec';\nimport { VECTOR_CODEC_ID, VECTOR_MAX_DIM } from '../core/constants';\n\n/**\n * Static vector column descriptor without dimension. Use `vector(N)` for dimensioned vectors that produce `vector(N)` DDL.\n */\nexport const vectorColumn = {\n codecId: VECTOR_CODEC_ID,\n nativeType: 'vector',\n} as const satisfies ColumnTypeDescriptor;\n\n/**\n * Factory for creating dimensioned vector column descriptors.\n *\n * @example\n * ```typescript\n * .column('embedding', { type: vector(1536), nullable: false })\n * // Produces: nativeType: 'vector', typeParams: { length: 1536 }\n * ```\n * @param length - The dimension of the vector (e.g., 1536 for OpenAI embeddings)\n * @returns A column type descriptor with `typeParams.length` set\n * @throws {RangeError} If length is not an integer in the range [1, VECTOR_MAX_DIM]\n */\nexport function vector<N extends number>(\n length: N,\n): ColumnTypeDescriptor & { readonly typeParams: { readonly length: N } } {\n if (!Number.isInteger(length) || length < 1 || length > VECTOR_MAX_DIM) {\n throw new RangeError(\n `pgvector: dimension must be an integer in [1, ${VECTOR_MAX_DIM}], got ${length}`,\n );\n }\n return {\n codecId: VECTOR_CODEC_ID,\n nativeType: 'vector',\n typeParams: { length },\n } as const;\n}\n"],"mappings":";;;;;AAYA,MAAa,eAAe;CAC1B,SAAS;CACT,YAAY;CACb;;;;;;;;;;;;;AAcD,SAAgB,OACd,QACwE;CACxE,IAAI,CAAC,OAAO,UAAU,OAAO,IAAI,SAAS,KAAK,SAAA,MAC7C,MAAM,IAAI,WACR,iDAAiD,eAAe,SAAS,SAC1E;CAEH,OAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,EAAE,QAAQ;EACvB"}
|
|
@@ -7,7 +7,7 @@ const VECTOR_CODEC_ID = "pg/vector@1";
|
|
|
7
7
|
* Maximum dimension for pgvector vectors (VECTOR_MAX_DIM from pgvector).
|
|
8
8
|
*/
|
|
9
9
|
const VECTOR_MAX_DIM = 16e3;
|
|
10
|
-
|
|
11
10
|
//#endregion
|
|
12
11
|
export { VECTOR_MAX_DIM as n, VECTOR_CODEC_ID as t };
|
|
13
|
-
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=constants-DX-00vYk.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants-
|
|
1
|
+
{"version":3,"file":"constants-DX-00vYk.mjs","names":[],"sources":["../src/core/constants.ts"],"sourcesContent":["/**\n * Codec ID for pgvector's vector type.\n */\nexport const VECTOR_CODEC_ID = 'pg/vector@1' as const;\n\n/**\n * Maximum dimension for pgvector vectors (VECTOR_MAX_DIM from pgvector).\n */\nexport const VECTOR_MAX_DIM = 16000;\n"],"mappings":";;;;AAGA,MAAa,kBAAkB;;;;AAK/B,MAAa,iBAAiB"}
|
package/dist/control.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/exports/control.ts"],"
|
|
1
|
+
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/exports/control.ts"],"mappings":";;;cAsFM,2BAAA,EAA6B,6BAAA"}
|
package/dist/control.mjs
CHANGED
|
@@ -1,7 +1,154 @@
|
|
|
1
|
-
import { n as pgvectorQueryOperations, t as pgvectorPackMeta } from "./descriptor-meta-
|
|
2
|
-
|
|
1
|
+
import { n as pgvectorQueryOperations, t as pgvectorPackMeta } from "./descriptor-meta-DEgJjLLi.mjs";
|
|
2
|
+
import { contractSpaceFromJson } from "@prisma-next/migration-tools/spaces";
|
|
3
|
+
//#region migrations/20260601T0000_install_vector_extension/migration.json
|
|
4
|
+
var migration_default = {
|
|
5
|
+
from: null,
|
|
6
|
+
to: "sha256:382dae5bb1548e62cbc449530ea08a9ce0a0dbb280401e9588642223f33783ae",
|
|
7
|
+
labels: [],
|
|
8
|
+
providedInvariants: ["pgvector:install-vector-v1"],
|
|
9
|
+
createdAt: "2026-06-01T00:00:00.000Z",
|
|
10
|
+
fromContract: null,
|
|
11
|
+
toContract: {
|
|
12
|
+
"schemaVersion": "1",
|
|
13
|
+
"targetFamily": "sql",
|
|
14
|
+
"target": "postgres",
|
|
15
|
+
"profileHash": "sha256:1a8dbe044289f30a1de958fe800cc5a8378b285d2e126a8c44b58864bac2c18e",
|
|
16
|
+
"roots": {},
|
|
17
|
+
"models": {},
|
|
18
|
+
"storage": {
|
|
19
|
+
"storageHash": "sha256:382dae5bb1548e62cbc449530ea08a9ce0a0dbb280401e9588642223f33783ae",
|
|
20
|
+
"tables": {},
|
|
21
|
+
"types": { "vector": {
|
|
22
|
+
"codecId": "pg/vector@1",
|
|
23
|
+
"nativeType": "vector",
|
|
24
|
+
"typeParams": {}
|
|
25
|
+
} }
|
|
26
|
+
},
|
|
27
|
+
"capabilities": {
|
|
28
|
+
"postgres": {
|
|
29
|
+
"jsonAgg": true,
|
|
30
|
+
"lateral": true,
|
|
31
|
+
"limit": true,
|
|
32
|
+
"orderBy": true,
|
|
33
|
+
"returning": true
|
|
34
|
+
},
|
|
35
|
+
"sql": {
|
|
36
|
+
"defaultInInsert": true,
|
|
37
|
+
"enums": true,
|
|
38
|
+
"returning": true
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"extensionPacks": {},
|
|
42
|
+
"meta": {},
|
|
43
|
+
"_generated": {
|
|
44
|
+
"warning": "⚠️ GENERATED FILE - DO NOT EDIT",
|
|
45
|
+
"message": "This file is automatically generated by \"prisma-next contract emit\".",
|
|
46
|
+
"regenerate": "To regenerate, run: prisma-next contract emit"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
hints: {
|
|
50
|
+
"used": [],
|
|
51
|
+
"applied": [],
|
|
52
|
+
"plannerVersion": "2.0.0"
|
|
53
|
+
},
|
|
54
|
+
migrationHash: "sha256:7419a7bfdac708cff9db1b35e48b035b09f3a883f099483e41385738d146622a"
|
|
55
|
+
};
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region migrations/20260601T0000_install_vector_extension/ops.json
|
|
58
|
+
var ops_default = [{
|
|
59
|
+
"id": "pgvector.install-vector-extension",
|
|
60
|
+
"label": "Enable extension \"vector\"",
|
|
61
|
+
"operationClass": "additive",
|
|
62
|
+
"invariantId": "pgvector:install-vector-v1",
|
|
63
|
+
"target": {
|
|
64
|
+
"id": "postgres",
|
|
65
|
+
"details": {
|
|
66
|
+
"schema": "public",
|
|
67
|
+
"objectType": "dependency",
|
|
68
|
+
"name": "vector"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"precheck": [{
|
|
72
|
+
"description": "verify extension \"vector\" is not already enabled",
|
|
73
|
+
"sql": "SELECT NOT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'vector')"
|
|
74
|
+
}],
|
|
75
|
+
"execute": [{
|
|
76
|
+
"description": "create extension \"vector\"",
|
|
77
|
+
"sql": "CREATE EXTENSION IF NOT EXISTS vector"
|
|
78
|
+
}],
|
|
79
|
+
"postcheck": [{
|
|
80
|
+
"description": "confirm extension \"vector\" is enabled",
|
|
81
|
+
"sql": "SELECT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'vector')"
|
|
82
|
+
}]
|
|
83
|
+
}];
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region migrations/refs/head.json
|
|
86
|
+
var head_default = {
|
|
87
|
+
hash: "sha256:382dae5bb1548e62cbc449530ea08a9ce0a0dbb280401e9588642223f33783ae",
|
|
88
|
+
invariants: ["pgvector:install-vector-v1"]
|
|
89
|
+
};
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/contract.json
|
|
92
|
+
var contract_default = {
|
|
93
|
+
schemaVersion: "1",
|
|
94
|
+
targetFamily: "sql",
|
|
95
|
+
target: "postgres",
|
|
96
|
+
profileHash: "sha256:1a8dbe044289f30a1de958fe800cc5a8378b285d2e126a8c44b58864bac2c18e",
|
|
97
|
+
roots: {},
|
|
98
|
+
models: {},
|
|
99
|
+
storage: {
|
|
100
|
+
"storageHash": "sha256:382dae5bb1548e62cbc449530ea08a9ce0a0dbb280401e9588642223f33783ae",
|
|
101
|
+
"tables": {},
|
|
102
|
+
"types": { "vector": {
|
|
103
|
+
"codecId": "pg/vector@1",
|
|
104
|
+
"nativeType": "vector",
|
|
105
|
+
"typeParams": {}
|
|
106
|
+
} }
|
|
107
|
+
},
|
|
108
|
+
capabilities: {
|
|
109
|
+
"postgres": {
|
|
110
|
+
"jsonAgg": true,
|
|
111
|
+
"lateral": true,
|
|
112
|
+
"limit": true,
|
|
113
|
+
"orderBy": true,
|
|
114
|
+
"returning": true
|
|
115
|
+
},
|
|
116
|
+
"sql": {
|
|
117
|
+
"defaultInInsert": true,
|
|
118
|
+
"enums": true,
|
|
119
|
+
"returning": true
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
extensionPacks: {},
|
|
123
|
+
meta: {},
|
|
124
|
+
_generated: {
|
|
125
|
+
"warning": "⚠️ GENERATED FILE - DO NOT EDIT",
|
|
126
|
+
"message": "This file is automatically generated by \"prisma-next contract emit\".",
|
|
127
|
+
"regenerate": "To regenerate, run: prisma-next contract emit"
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/core/contract-space-constants.ts
|
|
132
|
+
/**
|
|
133
|
+
* Static names and identifiers used across pgvector's contract space.
|
|
134
|
+
*
|
|
135
|
+
* Centralised here so the contract IR (`./contract`), the baseline
|
|
136
|
+
* migration ops (`./migrations`), the head ref, and the descriptor
|
|
137
|
+
* (`../exports/control`) all reference the same values without typos.
|
|
138
|
+
*
|
|
139
|
+
* The space identifier `'pgvector'` is what the framework writes to
|
|
140
|
+
* `migrations/` in the user's repo and what the marker table's
|
|
141
|
+
* `space` column carries for pgvector-owned rows.
|
|
142
|
+
*
|
|
143
|
+
* The `pgvector:*` invariantId namespace is locked here — once
|
|
144
|
+
* published, an invariantId is immutable so downstream consumers can
|
|
145
|
+
* reference it by literal string match.
|
|
146
|
+
*/
|
|
147
|
+
const PGVECTOR_SPACE_ID = "pgvector";
|
|
148
|
+
//#endregion
|
|
3
149
|
//#region src/exports/control.ts
|
|
4
150
|
const PGVECTOR_CODEC_ID = "pg/vector@1";
|
|
151
|
+
const BASELINE_DIR_NAME = "20260601T0000_install_vector_extension";
|
|
5
152
|
function buildVectorIdentityValue(typeParams) {
|
|
6
153
|
const length = typeParams?.["length"];
|
|
7
154
|
if (typeof length !== "number" || !Number.isInteger(length) || length <= 0) return null;
|
|
@@ -15,31 +162,19 @@ const vectorControlPlaneHooks = {
|
|
|
15
162
|
},
|
|
16
163
|
resolveIdentityValue: ({ typeParams }) => buildVectorIdentityValue(typeParams)
|
|
17
164
|
};
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
precheck: [{
|
|
28
|
-
description: "verify extension \"vector\" is not already enabled",
|
|
29
|
-
sql: "SELECT NOT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'vector')"
|
|
30
|
-
}],
|
|
31
|
-
execute: [{
|
|
32
|
-
description: "create extension \"vector\"",
|
|
33
|
-
sql: "CREATE EXTENSION IF NOT EXISTS vector"
|
|
34
|
-
}],
|
|
35
|
-
postcheck: [{
|
|
36
|
-
description: "confirm extension \"vector\" is enabled",
|
|
37
|
-
sql: "SELECT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'vector')"
|
|
38
|
-
}]
|
|
39
|
-
}]
|
|
40
|
-
}] };
|
|
165
|
+
const pgvectorContractSpace = contractSpaceFromJson({
|
|
166
|
+
contractJson: contract_default,
|
|
167
|
+
migrations: [{
|
|
168
|
+
dirName: BASELINE_DIR_NAME,
|
|
169
|
+
metadata: migration_default,
|
|
170
|
+
ops: ops_default
|
|
171
|
+
}],
|
|
172
|
+
headRef: head_default
|
|
173
|
+
});
|
|
41
174
|
const pgvectorExtensionDescriptor = {
|
|
42
175
|
...pgvectorPackMeta,
|
|
176
|
+
id: PGVECTOR_SPACE_ID,
|
|
177
|
+
contractSpace: pgvectorContractSpace,
|
|
43
178
|
types: {
|
|
44
179
|
...pgvectorPackMeta.types,
|
|
45
180
|
codecTypes: {
|
|
@@ -47,15 +182,13 @@ const pgvectorExtensionDescriptor = {
|
|
|
47
182
|
controlPlaneHooks: { [PGVECTOR_CODEC_ID]: vectorControlPlaneHooks }
|
|
48
183
|
}
|
|
49
184
|
},
|
|
50
|
-
queryOperations: () => pgvectorQueryOperations,
|
|
51
|
-
databaseDependencies: pgvectorDatabaseDependencies,
|
|
185
|
+
queryOperations: () => pgvectorQueryOperations(),
|
|
52
186
|
create: () => ({
|
|
53
187
|
familyId: "sql",
|
|
54
188
|
targetId: "postgres"
|
|
55
189
|
})
|
|
56
190
|
};
|
|
57
|
-
var control_default = pgvectorExtensionDescriptor;
|
|
58
|
-
|
|
59
191
|
//#endregion
|
|
60
|
-
export {
|
|
192
|
+
export { pgvectorExtensionDescriptor as default, pgvectorExtensionDescriptor };
|
|
193
|
+
|
|
61
194
|
//# sourceMappingURL=control.mjs.map
|
package/dist/control.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control.mjs","names":["
|
|
1
|
+
{"version":3,"file":"control.mjs","names":["baselineMetadata","baselineOps"],"sources":["../migrations/20260601T0000_install_vector_extension/migration.json","../migrations/20260601T0000_install_vector_extension/ops.json","../migrations/refs/head.json","../src/contract.json","../src/core/contract-space-constants.ts","../src/exports/control.ts"],"sourcesContent":["","","","","/**\n * Static names and identifiers used across pgvector's contract space.\n *\n * Centralised here so the contract IR (`./contract`), the baseline\n * migration ops (`./migrations`), the head ref, and the descriptor\n * (`../exports/control`) all reference the same values without typos.\n *\n * The space identifier `'pgvector'` is what the framework writes to\n * `migrations/` in the user's repo and what the marker table's\n * `space` column carries for pgvector-owned rows.\n *\n * The `pgvector:*` invariantId namespace is locked here — once\n * published, an invariantId is immutable so downstream consumers can\n * reference it by literal string match.\n */\n\nexport const PGVECTOR_SPACE_ID = 'pgvector' as const;\n\nexport const PGVECTOR_NATIVE_TYPE = 'vector' as const;\n\nexport const PGVECTOR_BASELINE_MIGRATION_NAME = '20260601T0000_install_vector_extension' as const;\n\n/**\n * `pgvector:*` invariantIds emitted by the baseline migration. Each id,\n * once published, is immutable: downstream consumers (other extensions,\n * the marker table) reference them by literal string match.\n */\nexport const PGVECTOR_INVARIANTS = {\n installVector: 'pgvector:install-vector-v1',\n} as const;\n","/**\n * Control-plane descriptor for the pgvector extension.\n *\n * **Contract-space package layout.** The extension's contract\n * + migrations are emitted by the same pipeline application authors use:\n *\n * `prisma-next contract emit` → `<package>/src/contract.{json,d.ts}`\n * `prisma-next migration plan` → `<package>/migrations/<dir>/...`\n *\n * The descriptor wires those JSON artefacts via JSON-import declarations\n * so they flow through the consuming application's module resolver\n * without filesystem assumptions, and synthesises the canonical\n * {@link import('@prisma-next/framework-components/control').MigrationPackage}\n * shape for the framework's runner / verifier to consume. Readers in\n * `@prisma-next/migration-tools` add `dirPath` when loading from disk\n * (`OnDiskMigrationPackage`); descriptor-bundled packages do not need\n * it because the framework reads them directly from the descriptor.\n *\n * Wired surfaces:\n *\n * - `contractSpace.{contractJson,migrations,headRef}` — sourced from\n * the on-disk artefacts emitted by `build:contract-space`.\n * - `types.codecTypes.controlPlaneHooks[PGVECTOR_CODEC_ID]` — codec\n * control hooks (`expandNativeType`, `resolveIdentityValue`) the\n * SQL planner extracts via `extractCodecControlHooks` and uses to\n * render `vector(N)` column types and the canonical zero-vector\n * identity literal.\n *\n * @see docs/architecture docs/adrs/ADR 212 - Contract spaces.md\n * (contract-space package layout convention).\n */\n\nimport type { Contract } from '@prisma-next/contract/types';\nimport type {\n CodecControlHooks,\n SqlControlExtensionDescriptor,\n} from '@prisma-next/family-sql/control';\nimport { contractSpaceFromJson } from '@prisma-next/migration-tools/spaces';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport baselineMetadata from '../../migrations/20260601T0000_install_vector_extension/migration.json' with {\n type: 'json',\n};\nimport baselineOps from '../../migrations/20260601T0000_install_vector_extension/ops.json' with {\n type: 'json',\n};\nimport headRef from '../../migrations/refs/head.json' with { type: 'json' };\nimport contractJson from '../contract.json' with { type: 'json' };\nimport { PGVECTOR_SPACE_ID } from '../core/contract-space-constants';\nimport { pgvectorPackMeta, pgvectorQueryOperations } from '../core/descriptor-meta';\n\nconst PGVECTOR_CODEC_ID = 'pg/vector@1' as const;\nconst BASELINE_DIR_NAME = '20260601T0000_install_vector_extension';\n\nfunction buildVectorIdentityValue(typeParams: Record<string, unknown> | undefined): string | null {\n const length = typeParams?.['length'];\n if (typeof length !== 'number' || !Number.isInteger(length) || length <= 0) {\n return null;\n }\n\n const zeroVector = `[${new Array(length).fill('0').join(',')}]`;\n return `'${zeroVector}'::vector`;\n}\n\nconst vectorControlPlaneHooks: CodecControlHooks = {\n expandNativeType: ({ nativeType, typeParams }) => {\n const length = typeParams?.['length'];\n if (typeof length === 'number' && Number.isInteger(length) && length > 0) {\n return `${nativeType}(${length})`;\n }\n return nativeType;\n },\n resolveIdentityValue: ({ typeParams }) => buildVectorIdentityValue(typeParams),\n};\n\nconst pgvectorContractSpace = contractSpaceFromJson<Contract<SqlStorage>>({\n contractJson,\n migrations: [\n {\n dirName: BASELINE_DIR_NAME,\n metadata: baselineMetadata,\n ops: baselineOps,\n },\n ],\n headRef,\n});\n\nconst pgvectorExtensionDescriptor: SqlControlExtensionDescriptor<'postgres'> = {\n ...pgvectorPackMeta,\n id: PGVECTOR_SPACE_ID,\n contractSpace: pgvectorContractSpace,\n types: {\n ...pgvectorPackMeta.types,\n codecTypes: {\n ...pgvectorPackMeta.types.codecTypes,\n controlPlaneHooks: {\n [PGVECTOR_CODEC_ID]: vectorControlPlaneHooks,\n },\n },\n },\n queryOperations: () => pgvectorQueryOperations(),\n create: () => ({\n familyId: 'sql' as const,\n targetId: 'postgres' as const,\n }),\n};\n\nexport { pgvectorExtensionDescriptor };\nexport default pgvectorExtensionDescriptor;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AIgBA,MAAa,oBAAoB;;;ACkCjC,MAAM,oBAAoB;AAC1B,MAAM,oBAAoB;AAE1B,SAAS,yBAAyB,YAAgE;CAChG,MAAM,SAAS,aAAa;CAC5B,IAAI,OAAO,WAAW,YAAY,CAAC,OAAO,UAAU,OAAO,IAAI,UAAU,GACvE,OAAO;CAIT,OAAO,IAAI,IADY,IAAI,MAAM,OAAO,CAAC,KAAK,IAAI,CAAC,KAAK,IAAI,CAAC,GACvC;;AAGxB,MAAM,0BAA6C;CACjD,mBAAmB,EAAE,YAAY,iBAAiB;EAChD,MAAM,SAAS,aAAa;EAC5B,IAAI,OAAO,WAAW,YAAY,OAAO,UAAU,OAAO,IAAI,SAAS,GACrE,OAAO,GAAG,WAAW,GAAG,OAAO;EAEjC,OAAO;;CAET,uBAAuB,EAAE,iBAAiB,yBAAyB,WAAW;CAC/E;AAED,MAAM,wBAAwB,sBAA4C;CACxE,cAAA;CACA,YAAY,CACV;EACE,SAAS;EACT,UAAUA;EACV,KAAKC;EACN,CACF;CACD,SAAA;CACD,CAAC;AAEF,MAAM,8BAAyE;CAC7E,GAAG;CACH,IAAI;CACJ,eAAe;CACf,OAAO;EACL,GAAG,iBAAiB;EACpB,YAAY;GACV,GAAG,iBAAiB,MAAM;GAC1B,mBAAmB,GAChB,oBAAoB,yBACtB;GACF;EACF;CACD,uBAAuB,yBAAyB;CAChD,eAAe;EACb,UAAU;EACV,UAAU;EACX;CACF"}
|