@prisma-next/extension-pgvector 0.5.0-dev.7 → 0.5.0-dev.71
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 +5 -2
- 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 +4 -6
- package/dist/control.mjs.map +1 -1
- package/dist/descriptor-meta-CBnWOxms.mjs +182 -0
- package/dist/descriptor-meta-CBnWOxms.mjs.map +1 -0
- package/dist/operation-types.d.mts +57 -44
- package/dist/operation-types.d.mts.map +1 -1
- package/dist/operation-types.mjs +1 -1
- package/dist/pack.d.mts +3 -4
- 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 +18 -16
- package/src/core/codecs.ts +127 -59
- package/src/core/descriptor-meta.ts +55 -28
- package/src/core/registry.ts +11 -0
- package/src/exports/column-types.ts +3 -6
- package/src/exports/control.ts +1 -1
- package/src/exports/runtime.ts +11 -41
- package/src/types/operation-types.ts +24 -30
- 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/README.md
CHANGED
|
@@ -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:
|
|
@@ -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":";;;cAkEM,2BAAA,EAA6B,6BAAA"}
|
package/dist/control.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { n as pgvectorQueryOperations, t as pgvectorPackMeta } from "./descriptor-meta-
|
|
2
|
-
|
|
1
|
+
import { n as pgvectorQueryOperations, t as pgvectorPackMeta } from "./descriptor-meta-CBnWOxms.mjs";
|
|
3
2
|
//#region src/exports/control.ts
|
|
4
3
|
const PGVECTOR_CODEC_ID = "pg/vector@1";
|
|
5
4
|
function buildVectorIdentityValue(typeParams) {
|
|
@@ -47,15 +46,14 @@ const pgvectorExtensionDescriptor = {
|
|
|
47
46
|
controlPlaneHooks: { [PGVECTOR_CODEC_ID]: vectorControlPlaneHooks }
|
|
48
47
|
}
|
|
49
48
|
},
|
|
50
|
-
queryOperations: () => pgvectorQueryOperations,
|
|
49
|
+
queryOperations: () => pgvectorQueryOperations(),
|
|
51
50
|
databaseDependencies: pgvectorDatabaseDependencies,
|
|
52
51
|
create: () => ({
|
|
53
52
|
familyId: "sql",
|
|
54
53
|
targetId: "postgres"
|
|
55
54
|
})
|
|
56
55
|
};
|
|
57
|
-
var control_default = pgvectorExtensionDescriptor;
|
|
58
|
-
|
|
59
56
|
//#endregion
|
|
60
|
-
export {
|
|
57
|
+
export { pgvectorExtensionDescriptor as default, pgvectorExtensionDescriptor };
|
|
58
|
+
|
|
61
59
|
//# 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":[],"sources":["../src/exports/control.ts"],"sourcesContent":["import type {\n CodecControlHooks,\n ComponentDatabaseDependencies,\n SqlControlExtensionDescriptor,\n} from '@prisma-next/family-sql/control';\nimport { pgvectorPackMeta, pgvectorQueryOperations } from '../core/descriptor-meta';\n\nconst PGVECTOR_CODEC_ID = 'pg/vector@1' as const;\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 pgvectorDatabaseDependencies: ComponentDatabaseDependencies<unknown> = {\n init: [\n {\n id: 'postgres.extension.vector',\n label: 'Enable vector extension',\n install: [\n {\n id: 'extension.vector',\n label: 'Enable extension \"vector\"',\n summary: 'Ensures the vector extension is available for pgvector operations',\n operationClass: 'additive',\n target: { id: 'postgres' },\n precheck: [\n {\n description: 'verify extension \"vector\" is not already enabled',\n sql: \"SELECT NOT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'vector')\",\n },\n ],\n execute: [\n {\n description: 'create extension \"vector\"',\n sql: 'CREATE EXTENSION IF NOT EXISTS vector',\n },\n ],\n postcheck: [\n {\n description: 'confirm extension \"vector\" is enabled',\n sql: \"SELECT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'vector')\",\n },\n ],\n },\n ],\n },\n ],\n};\n\nconst pgvectorExtensionDescriptor: SqlControlExtensionDescriptor<'postgres'> = {\n ...pgvectorPackMeta,\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 databaseDependencies: pgvectorDatabaseDependencies,\n create: () => ({\n familyId: 'sql' as const,\n targetId: 'postgres' as const,\n }),\n};\n\nexport { pgvectorExtensionDescriptor };\nexport default pgvectorExtensionDescriptor;\n"],"mappings":";;AAOA,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,+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,OAAO;EACL,GAAG,iBAAiB;EACpB,YAAY;GACV,GAAG,iBAAiB,MAAM;GAC1B,mBAAmB,GAChB,oBAAoB,yBACtB;GACF;EACF;CACD,uBAAuB,yBAAyB;CAChD,sBAAsB;CACtB,eAAe;EACb,UAAU;EACV,UAAU;EACX;CACF"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { n as VECTOR_MAX_DIM, t as VECTOR_CODEC_ID } from "./constants-DX-00vYk.mjs";
|
|
2
|
+
import { buildOperation, refsOf, toExpr } from "@prisma-next/sql-relational-core/expression";
|
|
3
|
+
import { buildCodecDescriptorRegistry } from "@prisma-next/sql-relational-core/codec-descriptor-registry";
|
|
4
|
+
import { CodecDescriptorImpl, CodecImpl } from "@prisma-next/framework-components/codec";
|
|
5
|
+
import { type } from "arktype";
|
|
6
|
+
//#region src/core/authoring.ts
|
|
7
|
+
const pgvectorAuthoringTypes = { pgvector: { Vector: {
|
|
8
|
+
kind: "typeConstructor",
|
|
9
|
+
args: [{
|
|
10
|
+
kind: "number",
|
|
11
|
+
name: "length",
|
|
12
|
+
integer: true,
|
|
13
|
+
minimum: 1,
|
|
14
|
+
maximum: VECTOR_MAX_DIM
|
|
15
|
+
}],
|
|
16
|
+
output: {
|
|
17
|
+
codecId: "pg/vector@1",
|
|
18
|
+
nativeType: "vector",
|
|
19
|
+
typeParams: { length: {
|
|
20
|
+
kind: "arg",
|
|
21
|
+
index: 0
|
|
22
|
+
} }
|
|
23
|
+
}
|
|
24
|
+
} } };
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/core/codecs.ts
|
|
27
|
+
const vectorParamsSchema = type({ length: "number" }).narrow((params, ctx) => {
|
|
28
|
+
const { length } = params;
|
|
29
|
+
if (!Number.isInteger(length)) return ctx.mustBe("an integer");
|
|
30
|
+
if (length < 1 || length > 16e3) return ctx.mustBe(`in the range [1, ${VECTOR_MAX_DIM}]`);
|
|
31
|
+
return true;
|
|
32
|
+
});
|
|
33
|
+
const PG_VECTOR_META = { db: { sql: { postgres: { nativeType: "vector" } } } };
|
|
34
|
+
var PgVectorCodec = class extends CodecImpl {
|
|
35
|
+
length;
|
|
36
|
+
constructor(descriptor, length) {
|
|
37
|
+
super(descriptor);
|
|
38
|
+
this.length = length;
|
|
39
|
+
}
|
|
40
|
+
assertVector(value) {
|
|
41
|
+
if (!Array.isArray(value)) throw new Error("Vector value must be an array of numbers");
|
|
42
|
+
if (!value.every((v) => typeof v === "number")) throw new Error("Vector value must contain only numbers");
|
|
43
|
+
if (this.length !== void 0 && value.length !== this.length) throw new Error(`Vector length mismatch: expected ${this.length}, got ${value.length}`);
|
|
44
|
+
}
|
|
45
|
+
async encode(value, _ctx) {
|
|
46
|
+
this.assertVector(value);
|
|
47
|
+
return `[${value.join(",")}]`;
|
|
48
|
+
}
|
|
49
|
+
async decode(wire, _ctx) {
|
|
50
|
+
if (typeof wire !== "string") throw new Error("Vector wire value must be a string");
|
|
51
|
+
if (!wire.startsWith("[") || !wire.endsWith("]")) throw new Error(`Invalid vector format: expected "[...]", got "${wire}"`);
|
|
52
|
+
const content = wire.slice(1, -1).trim();
|
|
53
|
+
const parsed = content === "" ? [] : content.split(",").map((v) => {
|
|
54
|
+
const num = Number.parseFloat(v.trim());
|
|
55
|
+
if (Number.isNaN(num)) throw new Error(`Invalid vector value: "${v}" is not a number`);
|
|
56
|
+
return num;
|
|
57
|
+
});
|
|
58
|
+
this.assertVector(parsed);
|
|
59
|
+
return parsed;
|
|
60
|
+
}
|
|
61
|
+
encodeJson(value) {
|
|
62
|
+
this.assertVector(value);
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
decodeJson(json) {
|
|
66
|
+
this.assertVector(json);
|
|
67
|
+
return json;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
var PgVectorDescriptor = class extends CodecDescriptorImpl {
|
|
71
|
+
codecId = VECTOR_CODEC_ID;
|
|
72
|
+
traits = ["equality"];
|
|
73
|
+
targetTypes = ["vector"];
|
|
74
|
+
meta = PG_VECTOR_META;
|
|
75
|
+
paramsSchema = vectorParamsSchema;
|
|
76
|
+
renderOutputType(params) {
|
|
77
|
+
return `Vector<${params.length}>`;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 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.
|
|
81
|
+
*/
|
|
82
|
+
factory(params) {
|
|
83
|
+
return () => new PgVectorCodec(this, params?.length);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const codecDescriptorMap = { vector: new PgVectorDescriptor() };
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/core/registry.ts
|
|
89
|
+
/**
|
|
90
|
+
* Registry of every codec descriptor shipped by `@prisma-next/extension-pgvector`.
|
|
91
|
+
*
|
|
92
|
+
* Public consumer surface for the pgvector codec set. Currently a single entry (`pg/vector@1`); the registry shape stays consistent with the other codec-shipping packages so consumers don't need to special-case extensions. See ADR 208.
|
|
93
|
+
*/
|
|
94
|
+
const pgvectorCodecRegistry = buildCodecDescriptorRegistry(Object.values(codecDescriptorMap));
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/core/descriptor-meta.ts
|
|
97
|
+
const pgvectorTypeId = "pg/vector@1";
|
|
98
|
+
function pgvectorQueryOperations() {
|
|
99
|
+
return [{
|
|
100
|
+
method: "cosineDistance",
|
|
101
|
+
self: { codecId: pgvectorTypeId },
|
|
102
|
+
impl: (self, other) => {
|
|
103
|
+
const selfRefs = refsOf(self);
|
|
104
|
+
return buildOperation({
|
|
105
|
+
method: "cosineDistance",
|
|
106
|
+
args: [toExpr(self, pgvectorTypeId, selfRefs), toExpr(other, pgvectorTypeId, selfRefs)],
|
|
107
|
+
returns: {
|
|
108
|
+
codecId: "pg/float8@1",
|
|
109
|
+
nullable: false
|
|
110
|
+
},
|
|
111
|
+
lowering: {
|
|
112
|
+
targetFamily: "sql",
|
|
113
|
+
strategy: "function",
|
|
114
|
+
template: "{{self}} <=> {{arg0}}"
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}, {
|
|
119
|
+
method: "cosineSimilarity",
|
|
120
|
+
self: { codecId: pgvectorTypeId },
|
|
121
|
+
impl: (self, other) => {
|
|
122
|
+
const selfRefs = refsOf(self);
|
|
123
|
+
return buildOperation({
|
|
124
|
+
method: "cosineSimilarity",
|
|
125
|
+
args: [toExpr(self, pgvectorTypeId, selfRefs), toExpr(other, pgvectorTypeId, selfRefs)],
|
|
126
|
+
returns: {
|
|
127
|
+
codecId: "pg/float8@1",
|
|
128
|
+
nullable: false
|
|
129
|
+
},
|
|
130
|
+
lowering: {
|
|
131
|
+
targetFamily: "sql",
|
|
132
|
+
strategy: "function",
|
|
133
|
+
template: "1 - ({{self}} <=> {{arg0}})"
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}];
|
|
138
|
+
}
|
|
139
|
+
const pgvectorPackMeta = {
|
|
140
|
+
kind: "extension",
|
|
141
|
+
id: "pgvector",
|
|
142
|
+
familyId: "sql",
|
|
143
|
+
targetId: "postgres",
|
|
144
|
+
version: "0.0.1",
|
|
145
|
+
capabilities: { postgres: { "pgvector.cosine": true } },
|
|
146
|
+
authoring: { type: pgvectorAuthoringTypes },
|
|
147
|
+
types: {
|
|
148
|
+
codecTypes: {
|
|
149
|
+
codecDescriptors: Array.from(pgvectorCodecRegistry.values()),
|
|
150
|
+
import: {
|
|
151
|
+
package: "@prisma-next/extension-pgvector/codec-types",
|
|
152
|
+
named: "CodecTypes",
|
|
153
|
+
alias: "PgVectorTypes"
|
|
154
|
+
},
|
|
155
|
+
typeImports: [{
|
|
156
|
+
package: "@prisma-next/extension-pgvector/codec-types",
|
|
157
|
+
named: "Vector",
|
|
158
|
+
alias: "Vector"
|
|
159
|
+
}]
|
|
160
|
+
},
|
|
161
|
+
operationTypes: { import: {
|
|
162
|
+
package: "@prisma-next/extension-pgvector/operation-types",
|
|
163
|
+
named: "OperationTypes",
|
|
164
|
+
alias: "PgVectorOperationTypes"
|
|
165
|
+
} },
|
|
166
|
+
queryOperationTypes: { import: {
|
|
167
|
+
package: "@prisma-next/extension-pgvector/operation-types",
|
|
168
|
+
named: "QueryOperationTypes",
|
|
169
|
+
alias: "PgVectorQueryOperationTypes"
|
|
170
|
+
} },
|
|
171
|
+
storage: [{
|
|
172
|
+
typeId: pgvectorTypeId,
|
|
173
|
+
familyId: "sql",
|
|
174
|
+
targetId: "postgres",
|
|
175
|
+
nativeType: "vector"
|
|
176
|
+
}]
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
//#endregion
|
|
180
|
+
export { pgvectorQueryOperations as n, pgvectorCodecRegistry as r, pgvectorPackMeta as t };
|
|
181
|
+
|
|
182
|
+
//# sourceMappingURL=descriptor-meta-CBnWOxms.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"descriptor-meta-CBnWOxms.mjs","names":["arktype"],"sources":["../src/core/authoring.ts","../src/core/codecs.ts","../src/core/registry.ts","../src/core/descriptor-meta.ts"],"sourcesContent":["import type { AuthoringTypeNamespace } from '@prisma-next/framework-components/authoring';\nimport { VECTOR_MAX_DIM } from './constants';\n\nexport const pgvectorAuthoringTypes = {\n pgvector: {\n Vector: {\n kind: 'typeConstructor',\n args: [\n { kind: 'number', name: 'length', integer: true, minimum: 1, maximum: VECTOR_MAX_DIM },\n ],\n output: {\n codecId: 'pg/vector@1',\n nativeType: 'vector',\n typeParams: {\n length: { kind: 'arg', index: 0 },\n },\n },\n },\n },\n} as const satisfies AuthoringTypeNamespace;\n","/**\n * pgvector extension codec.\n *\n * Mirrors the patterns in `postgres/codecs-class.ts` and `sqlite/codecs-class.ts` for the single `pg/vector@1` codec. Three artifacts:\n *\n * 1. `PgVectorCodec` extends {@link CodecImpl} with the runtime encode/decode/encodeJson/decodeJson conversions inline. Conversions are simple enough (PostgreSQL `[1,2,3]` text format) that no shared helper module is warranted; the class body is the source of truth.\n * 2. `PgVectorDescriptor` extends {@link CodecDescriptorImpl} with the codec id, traits, target types, params schema (`{ length: number }`, validated against {@link VECTOR_MAX_DIM}), `meta` (postgres `nativeType: 'vector'`), and the emit-path `renderOutputType` producing `Vector<${length}>`.\n * 3. `pgVectorColumn(length)` per-codec column helper invoking `descriptor.factory({ length })` directly + passing the bare `nativeType: 'vector'`. The family-layer {@link expandNativeType} hook renders the parameterized form (`vector(1536)`) at emit/verify time from `nativeType` + `typeParams`.\n *\n * `length` threads into the runtime codec via the constructor so encode/decode/encodeJson/decodeJson enforce the declared dimension at every ingress path. Without this, `vector(3)` and `vector(1536)` would produce codecs with identical behaviour and a dimension-mismatched value would round-trip undetected.\n */\n\nimport type { JsonValue } from '@prisma-next/contract/types';\nimport {\n type AnyCodecDescriptor,\n type CodecCallContext,\n CodecDescriptorImpl,\n CodecImpl,\n type CodecInstanceContext,\n type ColumnHelperFor,\n type ColumnHelperForStrict,\n column,\n} from '@prisma-next/framework-components/codec';\nimport type { ExtractCodecTypes } from '@prisma-next/sql-relational-core/ast';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { type as arktype } from 'arktype';\nimport { VECTOR_CODEC_ID, VECTOR_MAX_DIM } from './constants';\n\ntype VectorParams = { readonly length: number };\n\nconst vectorParamsSchema = arktype({\n length: 'number',\n}).narrow((params, ctx) => {\n const { length } = params;\n if (!Number.isInteger(length)) {\n return ctx.mustBe('an integer');\n }\n if (length < 1 || length > VECTOR_MAX_DIM) {\n return ctx.mustBe(`in the range [1, ${VECTOR_MAX_DIM}]`);\n }\n return true;\n}) satisfies StandardSchemaV1<VectorParams>;\n\nconst PG_VECTOR_META = { db: { sql: { postgres: { nativeType: 'vector' } } } } as const;\n\nexport class PgVectorCodec extends CodecImpl<\n typeof VECTOR_CODEC_ID,\n readonly ['equality'],\n string,\n number[]\n> {\n readonly length: number | undefined;\n\n constructor(descriptor: AnyCodecDescriptor, length: number | undefined) {\n super(descriptor);\n this.length = length;\n }\n\n assertVector(value: unknown): asserts value is number[] {\n if (!Array.isArray(value)) {\n throw new Error('Vector value must be an array of numbers');\n }\n if (!value.every((v) => typeof v === 'number')) {\n throw new Error('Vector value must contain only numbers');\n }\n if (this.length !== undefined && value.length !== this.length) {\n throw new Error(`Vector length mismatch: expected ${this.length}, got ${value.length}`);\n }\n }\n\n async encode(value: number[], _ctx: CodecCallContext): Promise<string> {\n this.assertVector(value);\n return `[${value.join(',')}]`;\n }\n\n async decode(wire: string, _ctx: CodecCallContext): Promise<number[]> {\n if (typeof wire !== 'string') {\n throw new Error('Vector wire value must be a string');\n }\n if (!wire.startsWith('[') || !wire.endsWith(']')) {\n throw new Error(`Invalid vector format: expected \"[...]\", got \"${wire}\"`);\n }\n const content = wire.slice(1, -1).trim();\n const parsed =\n content === ''\n ? []\n : content.split(',').map((v) => {\n const num = Number.parseFloat(v.trim());\n if (Number.isNaN(num)) {\n throw new Error(`Invalid vector value: \"${v}\" is not a number`);\n }\n return num;\n });\n this.assertVector(parsed);\n return parsed;\n }\n\n encodeJson(value: number[]): JsonValue {\n this.assertVector(value);\n return value;\n }\n\n decodeJson(json: JsonValue): number[] {\n this.assertVector(json);\n return json;\n }\n}\n\nexport class PgVectorDescriptor extends CodecDescriptorImpl<VectorParams> {\n override readonly codecId = VECTOR_CODEC_ID;\n override readonly traits = ['equality'] as const;\n override readonly targetTypes = ['vector'] as const;\n override readonly meta = PG_VECTOR_META;\n override readonly paramsSchema: StandardSchemaV1<VectorParams> = vectorParamsSchema;\n override renderOutputType(params: VectorParams): string {\n return `Vector<${params.length}>`;\n }\n /**\n * 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.\n */\n override factory(params: VectorParams): (ctx: CodecInstanceContext) => PgVectorCodec {\n return () => new PgVectorCodec(this, (params as VectorParams | undefined)?.length);\n }\n}\n\nexport const pgVectorDescriptor = new PgVectorDescriptor();\n\n/**\n * Per-codec column helper for `pg/vector@1`. Generic over `N extends number` so the column site preserves the dimension literal in `typeParams` (e.g. `pgVectorColumn(1536)` packs `typeParams: { length: 1536 }`).\n *\n * Passes the bare `nativeType: 'vector'`; the family-layer `expandNativeType` hook renders the parameterized form (`vector(1536)`) at emit/verify time from `nativeType` + `typeParams`.\n */\nexport const pgVectorColumn = <N extends number>(length: N) =>\n column(pgVectorDescriptor.factory({ length }), pgVectorDescriptor.codecId, { length }, 'vector');\n\npgVectorColumn satisfies ColumnHelperFor<PgVectorDescriptor>;\npgVectorColumn satisfies ColumnHelperForStrict<PgVectorDescriptor>;\n\nconst codecDescriptorMap = {\n vector: pgVectorDescriptor,\n} as const;\n\nexport type CodecTypes = ExtractCodecTypes<typeof codecDescriptorMap>;\n\nexport const codecDescriptors: readonly AnyCodecDescriptor[] = Object.values(codecDescriptorMap);\n","import { buildCodecDescriptorRegistry } from '@prisma-next/sql-relational-core/codec-descriptor-registry';\nimport type { CodecDescriptorRegistry } from '@prisma-next/sql-relational-core/query-lane-context';\nimport { codecDescriptors } from './codecs';\n\n/**\n * Registry of every codec descriptor shipped by `@prisma-next/extension-pgvector`.\n *\n * Public consumer surface for the pgvector codec set. Currently a single entry (`pg/vector@1`); the registry shape stays consistent with the other codec-shipping packages so consumers don't need to special-case extensions. See ADR 208.\n */\nexport const pgvectorCodecRegistry: CodecDescriptorRegistry =\n buildCodecDescriptorRegistry(codecDescriptors);\n","import type { SqlOperationDescriptor } from '@prisma-next/sql-operations';\nimport {\n buildOperation,\n type CodecExpression,\n type Expression,\n refsOf,\n toExpr,\n} from '@prisma-next/sql-relational-core/expression';\nimport type { CodecTypes } from '../types/codec-types';\nimport { pgvectorAuthoringTypes } from './authoring';\nimport { pgvectorCodecRegistry } from './registry';\n\nconst pgvectorTypeId = 'pg/vector@1' as const;\n\ntype CodecTypesBase = Record<string, { readonly input: unknown; readonly output: unknown }>;\n\nexport function pgvectorQueryOperations<\n CT extends CodecTypesBase,\n>(): readonly SqlOperationDescriptor[] {\n return [\n {\n method: 'cosineDistance',\n self: { codecId: pgvectorTypeId },\n impl: (\n self: CodecExpression<'pg/vector@1', boolean, CT>,\n other: CodecExpression<'pg/vector@1', boolean, CT>,\n ): Expression<{ codecId: 'pg/float8@1'; nullable: false }> => {\n const selfRefs = refsOf(self);\n return buildOperation({\n method: 'cosineDistance',\n args: [toExpr(self, pgvectorTypeId, selfRefs), toExpr(other, pgvectorTypeId, selfRefs)],\n returns: { codecId: 'pg/float8@1', nullable: false },\n lowering: {\n targetFamily: 'sql',\n strategy: 'function',\n template: '{{self}} <=> {{arg0}}',\n },\n });\n },\n },\n {\n method: 'cosineSimilarity',\n self: { codecId: pgvectorTypeId },\n impl: (\n self: CodecExpression<'pg/vector@1', boolean, CT>,\n other: CodecExpression<'pg/vector@1', boolean, CT>,\n ): Expression<{ codecId: 'pg/float8@1'; nullable: false }> => {\n const selfRefs = refsOf(self);\n return buildOperation({\n method: 'cosineSimilarity',\n args: [toExpr(self, pgvectorTypeId, selfRefs), toExpr(other, pgvectorTypeId, selfRefs)],\n returns: { codecId: 'pg/float8@1', nullable: false },\n lowering: {\n targetFamily: 'sql',\n strategy: 'function',\n template: '1 - ({{self}} <=> {{arg0}})',\n },\n });\n },\n },\n ];\n}\n\nconst pgvectorPackMetaBase = {\n kind: 'extension',\n id: 'pgvector',\n familyId: 'sql',\n targetId: 'postgres',\n version: '0.0.1',\n capabilities: {\n postgres: {\n 'pgvector.cosine': true,\n },\n },\n authoring: {\n type: pgvectorAuthoringTypes,\n },\n types: {\n codecTypes: {\n codecDescriptors: Array.from(pgvectorCodecRegistry.values()),\n import: {\n package: '@prisma-next/extension-pgvector/codec-types',\n named: 'CodecTypes',\n alias: 'PgVectorTypes',\n },\n typeImports: [\n {\n package: '@prisma-next/extension-pgvector/codec-types',\n named: 'Vector',\n alias: 'Vector',\n },\n ],\n },\n operationTypes: {\n import: {\n package: '@prisma-next/extension-pgvector/operation-types',\n named: 'OperationTypes',\n alias: 'PgVectorOperationTypes',\n },\n },\n queryOperationTypes: {\n import: {\n package: '@prisma-next/extension-pgvector/operation-types',\n named: 'QueryOperationTypes',\n alias: 'PgVectorQueryOperationTypes',\n },\n },\n storage: [\n { typeId: pgvectorTypeId, familyId: 'sql', targetId: 'postgres', nativeType: 'vector' },\n ],\n },\n} as const;\n\nexport const pgvectorPackMeta: typeof pgvectorPackMetaBase & {\n readonly __codecTypes?: CodecTypes;\n} = pgvectorPackMetaBase;\n"],"mappings":";;;;;;AAGA,MAAa,yBAAyB,EACpC,UAAU,EACR,QAAQ;CACN,MAAM;CACN,MAAM,CACJ;EAAE,MAAM;EAAU,MAAM;EAAU,SAAS;EAAM,SAAS;EAAG,SAAS;EAAgB,CACvF;CACD,QAAQ;EACN,SAAS;EACT,YAAY;EACZ,YAAY,EACV,QAAQ;GAAE,MAAM;GAAO,OAAO;GAAG,EAClC;EACF;CACF,EACF,EACF;;;ACWD,MAAM,qBAAqBA,KAAQ,EACjC,QAAQ,UACT,CAAC,CAAC,QAAQ,QAAQ,QAAQ;CACzB,MAAM,EAAE,WAAW;CACnB,IAAI,CAAC,OAAO,UAAU,OAAO,EAC3B,OAAO,IAAI,OAAO,aAAa;CAEjC,IAAI,SAAS,KAAK,SAAA,MAChB,OAAO,IAAI,OAAO,oBAAoB,eAAe,GAAG;CAE1D,OAAO;EACP;AAEF,MAAM,iBAAiB,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,UAAU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AC5D,QAAQ;IACN,SAAS;IACT,OAAO;IACP,OAAO;IACR;GACD,aAAa,CACX;IACE,SAAS;IACT,OAAO;IACP,OAAO;IACR,CACF;GACF;EACD,gBAAgB,EACd,QAAQ;GACN,SAAS;GACT,OAAO;GACP,OAAO;GACR,EACF;EACD,qBAAqB,EACnB,QAAQ;GACN,SAAS;GACT,OAAO;GACP,OAAO;GACR,EACF;EACD,SAAS,CACP;GAAE,QAAQ;GAAgB,UAAU;GAAO,UAAU;GAAY,YAAY;GAAU,CACxF;EACF;CAKC"}
|
|
@@ -1,7 +1,48 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { CodecExpression, Expression } from "@prisma-next/sql-relational-core/expression";
|
|
2
|
+
import { CodecTrait } from "@prisma-next/framework-components/codec";
|
|
3
|
+
//#region ../../2-sql/1-core/contract/dist/types-CjGH62ec.d.mts
|
|
4
|
+
/**
|
|
5
|
+
* Dispatch hint identifying the first-argument target of an operation.
|
|
6
|
+
*
|
|
7
|
+
* Used by ORM column helpers to decide whether an operation is reachable on a
|
|
8
|
+
* field. Either names a concrete codec identity or a set of capability traits
|
|
9
|
+
* that the field's codec must carry.
|
|
10
|
+
*/
|
|
11
|
+
type QueryOperationSelfSpec = {
|
|
12
|
+
readonly codecId: string;
|
|
13
|
+
readonly traits?: never;
|
|
14
|
+
} | {
|
|
15
|
+
readonly traits: readonly CodecTrait[];
|
|
16
|
+
readonly codecId?: never;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Structural shape an operation's impl must return: any value carrying a
|
|
20
|
+
* codec-exact `returnType` descriptor. `Expression<T>` (from
|
|
21
|
+
* `@prisma-next/sql-relational-core/expression`, with `T extends ScopeField`)
|
|
22
|
+
* extends this. Trait-targeted returns are deliberately excluded — predicate
|
|
23
|
+
* detection and result decoding both depend on knowing the concrete return
|
|
24
|
+
* codec.
|
|
25
|
+
*/
|
|
26
|
+
type QueryOperationReturn = {
|
|
27
|
+
readonly returnType: {
|
|
28
|
+
readonly codecId: string;
|
|
29
|
+
readonly nullable: boolean;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
type QueryOperationTypeEntry = {
|
|
33
|
+
readonly self?: QueryOperationSelfSpec;
|
|
34
|
+
readonly impl: (...args: never[]) => QueryOperationReturn;
|
|
35
|
+
};
|
|
36
|
+
type SqlQueryOperationTypes<_CT extends Record<string, {
|
|
37
|
+
readonly input: unknown;
|
|
38
|
+
readonly output: unknown;
|
|
39
|
+
}>, T extends Record<string, QueryOperationTypeEntry>> = T;
|
|
40
|
+
//#endregion
|
|
3
41
|
//#region src/types/operation-types.d.ts
|
|
4
|
-
|
|
42
|
+
type CodecTypesBase = Record<string, {
|
|
43
|
+
readonly input: unknown;
|
|
44
|
+
readonly output: unknown;
|
|
45
|
+
}>;
|
|
5
46
|
/**
|
|
6
47
|
* Operation type definitions for pgvector extension.
|
|
7
48
|
*
|
|
@@ -11,64 +52,36 @@ import { SqlQueryOperationTypes } from "@prisma-next/sql-contract/types";
|
|
|
11
52
|
type OperationTypes = {
|
|
12
53
|
readonly 'pg/vector@1': {
|
|
13
54
|
readonly cosineDistance: {
|
|
14
|
-
readonly
|
|
55
|
+
readonly self: {
|
|
15
56
|
readonly codecId: 'pg/vector@1';
|
|
16
|
-
readonly nullable: false;
|
|
17
|
-
}];
|
|
18
|
-
readonly returns: {
|
|
19
|
-
readonly codecId: 'pg/float8@1';
|
|
20
|
-
readonly nullable: false;
|
|
21
|
-
};
|
|
22
|
-
readonly lowering: {
|
|
23
|
-
readonly targetFamily: 'sql';
|
|
24
|
-
readonly strategy: 'function';
|
|
25
|
-
readonly template: string;
|
|
26
57
|
};
|
|
27
58
|
};
|
|
28
59
|
readonly cosineSimilarity: {
|
|
29
|
-
readonly
|
|
60
|
+
readonly self: {
|
|
30
61
|
readonly codecId: 'pg/vector@1';
|
|
31
|
-
readonly nullable: false;
|
|
32
|
-
}];
|
|
33
|
-
readonly returns: {
|
|
34
|
-
readonly codecId: 'pg/float8@1';
|
|
35
|
-
readonly nullable: false;
|
|
36
|
-
};
|
|
37
|
-
readonly lowering: {
|
|
38
|
-
readonly targetFamily: 'sql';
|
|
39
|
-
readonly strategy: 'function';
|
|
40
|
-
readonly template: string;
|
|
41
62
|
};
|
|
42
63
|
};
|
|
43
64
|
};
|
|
44
65
|
};
|
|
45
66
|
/** Flat operation signatures for the query builder. */
|
|
46
|
-
type QueryOperationTypes = SqlQueryOperationTypes<{
|
|
67
|
+
type QueryOperationTypes<CT extends CodecTypesBase> = SqlQueryOperationTypes<CT, {
|
|
47
68
|
readonly cosineDistance: {
|
|
48
|
-
readonly
|
|
49
|
-
readonly codecId: 'pg/vector@1';
|
|
50
|
-
readonly nullable: boolean;
|
|
51
|
-
}, {
|
|
69
|
+
readonly self: {
|
|
52
70
|
readonly codecId: 'pg/vector@1';
|
|
53
|
-
readonly nullable: boolean;
|
|
54
|
-
}];
|
|
55
|
-
readonly returns: {
|
|
56
|
-
readonly codecId: 'pg/float8@1';
|
|
57
|
-
readonly nullable: false;
|
|
58
71
|
};
|
|
72
|
+
readonly impl: (self: CodecExpression<'pg/vector@1', boolean, CT>, other: CodecExpression<'pg/vector@1', boolean, CT>) => Expression<{
|
|
73
|
+
codecId: 'pg/float8@1';
|
|
74
|
+
nullable: false;
|
|
75
|
+
}>;
|
|
59
76
|
};
|
|
60
77
|
readonly cosineSimilarity: {
|
|
61
|
-
readonly
|
|
62
|
-
readonly codecId: 'pg/vector@1';
|
|
63
|
-
readonly nullable: boolean;
|
|
64
|
-
}, {
|
|
78
|
+
readonly self: {
|
|
65
79
|
readonly codecId: 'pg/vector@1';
|
|
66
|
-
readonly nullable: boolean;
|
|
67
|
-
}];
|
|
68
|
-
readonly returns: {
|
|
69
|
-
readonly codecId: 'pg/float8@1';
|
|
70
|
-
readonly nullable: false;
|
|
71
80
|
};
|
|
81
|
+
readonly impl: (self: CodecExpression<'pg/vector@1', boolean, CT>, other: CodecExpression<'pg/vector@1', boolean, CT>) => Expression<{
|
|
82
|
+
codecId: 'pg/float8@1';
|
|
83
|
+
nullable: false;
|
|
84
|
+
}>;
|
|
72
85
|
};
|
|
73
86
|
}>;
|
|
74
87
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operation-types.d.mts","names":[],"sources":["../src/types/operation-types.ts"],"
|
|
1
|
+
{"version":3,"file":"operation-types.d.mts","names":["ColumnDefault","StorageBase","CodecTrait","StorageColumn","Record","nativeType","codecId","nullable","typeParams","typeRef","default","PrimaryKey","columns","name","UniqueConstraint","Index","using","config","ForeignKeyReferences","table","ReferentialAction","ForeignKeyOptions","onDelete","onUpdate","ForeignKey","references","constraint","index","StorageTable","ReadonlyArray","primaryKey","uniques","indexes","foreignKeys","StorageTypeInstance","SqlStorage","THash","tables","types","SqlModelFieldStorage","column","SqlModelStorage","fields","DEFAULT_FK_CONSTRAINT","DEFAULT_FK_INDEX","applyFkDefaults","fk","overrideDefaults","TypeMaps","TCodecTypes","TOperationTypes","TQueryOperationTypes","TFieldOutputTypes","TFieldInputTypes","output","codecTypes","operationTypes","queryOperationTypes","fieldOutputTypes","fieldInputTypes","CodecTypesOf","T","C","OperationTypesOf","O","QueryOperationSelfSpec","traits","QueryOperationReturn","returnType","QueryOperationTypeEntry","self","impl","args","SqlQueryOperationTypes","_CT","input","QueryOperationTypesBase","QueryOperationTypesOf","Q","TypeMapsPhantomKey","ContractWithTypeMaps","TContract","TTypeMaps","K","ExtractTypeMapsFromContract","NonNullable","FieldOutputTypesOf","F","FieldInputTypesOf","ExtractCodecTypes","ExtractQueryOperationTypes","ExtractFieldOutputTypes","ExtractFieldInputTypes","ResolveCodecTypes","ResolveOperationTypes","_TContract","A","D","E","I","M","N","P","S","_","a","b","c","d","f","g","h","i","j","k","l","m","n","o","p","r","s","t","u","v","w","x","y"],"sources":["../../../2-sql/1-core/contract/dist/types-CjGH62ec.d.mts","../src/types/operation-types.ts"],"mappings":";;;;;;;;;;KAoJKiE,sBAAAA;EAAAA,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ED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|
package/dist/pack.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { t as CodecTypes } from "./codec-types-
|
|
2
|
-
import * as
|
|
3
|
-
|
|
1
|
+
import { t as CodecTypes } from "./codec-types-CQubO6uQ.mjs";
|
|
2
|
+
import * as _$_prisma_next_framework_components_codec0 from "@prisma-next/framework-components/codec";
|
|
4
3
|
//#region src/core/descriptor-meta.d.ts
|
|
5
4
|
declare const pgvectorPackMetaBase: {
|
|
6
5
|
readonly kind: "extension";
|
|
@@ -41,7 +40,7 @@ declare const pgvectorPackMetaBase: {
|
|
|
41
40
|
};
|
|
42
41
|
readonly types: {
|
|
43
42
|
readonly codecTypes: {
|
|
44
|
-
readonly
|
|
43
|
+
readonly codecDescriptors: _$_prisma_next_framework_components_codec0.CodecDescriptor<unknown>[];
|
|
45
44
|
readonly import: {
|
|
46
45
|
readonly package: "@prisma-next/extension-pgvector/codec-types";
|
|
47
46
|
readonly named: "CodecTypes";
|
package/dist/pack.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pack.d.mts","names":[],"sources":["../src/core/descriptor-meta.ts"],"
|
|
1
|
+
{"version":3,"file":"pack.d.mts","names":[],"sources":["../src/core/descriptor-meta.ts"],"mappings":";;;cA+DM,oBAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCAgDI,0CAAA,CAAA,eAAA;MAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAEG,gBAAA,SAAyB,oBAAA;EAAA,SAC3B,YAAA,GAAe,UAAA;AAAA"}
|