@prisma-next/extension-pgvector 0.16.0-dev.32 → 0.16.0-dev.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{codec-types-eUx62rq4.d.mts → codec-types-Dsz8_6Av.d.mts} +7 -4
- package/dist/codec-types-Dsz8_6Av.d.mts.map +1 -0
- package/dist/codec-types.d.mts +1 -1
- package/dist/control.mjs +1 -1
- package/dist/{descriptor-meta-DMPKzaNe.mjs → descriptor-meta-Ct0uJ-Q0.mjs} +11 -4
- package/dist/descriptor-meta-Ct0uJ-Q0.mjs.map +1 -0
- package/dist/pack.d.mts +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/runtime.mjs +1 -1
- package/package.json +22 -22
- package/src/core/codecs.ts +14 -5
- package/dist/codec-types-eUx62rq4.d.mts.map +0 -1
- package/dist/descriptor-meta-DMPKzaNe.mjs.map +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { AnyCodecDescriptor, CodecCallContext,
|
|
1
|
+
import { AnyCodecDescriptor, CodecCallContext, CodecImpl, CodecInstanceContext } from "@prisma-next/framework-components/codec";
|
|
2
|
+
import { PostgresCodecDescriptor } from "@prisma-next/target-postgres/codec-descriptor";
|
|
2
3
|
import { JsonValue } from "@prisma-next/contract/types";
|
|
3
|
-
import { ExtractCodecTypes } from "@prisma-next/sql-relational-core/ast";
|
|
4
|
+
import { ExtractCodecTypes, ProjectionExpr } from "@prisma-next/sql-relational-core/ast";
|
|
4
5
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
5
6
|
//#region src/core/constants.d.ts
|
|
6
7
|
/**
|
|
@@ -22,7 +23,9 @@ declare class PgVectorCodec extends CodecImpl<typeof VECTOR_CODEC_ID, readonly [
|
|
|
22
23
|
encodeJson(value: number[]): JsonValue;
|
|
23
24
|
decodeJson(json: JsonValue): number[];
|
|
24
25
|
}
|
|
25
|
-
declare class PgVectorDescriptor extends
|
|
26
|
+
declare class PgVectorDescriptor extends PostgresCodecDescriptor<VectorParams> {
|
|
27
|
+
protected nativeType(): string;
|
|
28
|
+
protected jsonProjection(expression: ProjectionExpr): ProjectionExpr;
|
|
26
29
|
readonly codecId: "pg/vector@1";
|
|
27
30
|
readonly traits: readonly ["equality"];
|
|
28
31
|
readonly targetTypes: readonly ["vector"];
|
|
@@ -57,4 +60,4 @@ type Vector<N extends number = number> = number[] & {
|
|
|
57
60
|
type CodecTypes = CodecTypes$1;
|
|
58
61
|
//#endregion
|
|
59
62
|
export { Vector as n, CodecTypes as t };
|
|
60
|
-
//# sourceMappingURL=codec-types-
|
|
63
|
+
//# sourceMappingURL=codec-types-Dsz8_6Av.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec-types-Dsz8_6Av.d.mts","names":[],"sources":["../src/core/constants.ts","../src/core/codecs.ts","../src/types/codec-types.ts"],"mappings":";;;;;;;;;cAGa;;;KC6BR;KAEA;WAA0B;;cA+ClB,sBAAsB,iBAC1B;WAKE;cAEG,YAAY,oBAAoB;EAK5C,aAAa,gBAAgB,MAAM,+BAA+B;EAyB5D,OAAO,iBAAiB,MAAM,mBAAmB;EAKjD,OAAO,cAAc,MAAM,mBAAmB;EAWpD,WAAW,kBAAkB;EAK7B,WAAW,MAAM;;cAYN,2BAA2B,wBAAwB;YAC3C;YAGA,eAAe,YAAY,iBAAiB;WAG7C;WACA;WACA;WACA;;;;;;;;;WACA,cAAc,iBAAiB;EACxC,iBAAiB,QAAQ;EAGzB,QAAQ,QAAQ,gBAAgB,KAAK,yBAAyB;;cAkBnE;mBAAA;;KAIM,eAAa,yBAAyB;;;;;;;;;KC5KtC,OAAO;WAAmD,iBAAiB;;KAE3E,aAAa"}
|
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-Dsz8_6Av.mjs";
|
|
2
2
|
export type { CodecTypes, Vector };
|
package/dist/control.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as pgvectorQueryOperations, t as pgvectorPackMeta } from "./descriptor-meta-
|
|
1
|
+
import { n as pgvectorQueryOperations, t as pgvectorPackMeta } from "./descriptor-meta-Ct0uJ-Q0.mjs";
|
|
2
2
|
import { contractSpaceFromJson } from "@prisma-next/migration-tools/spaces";
|
|
3
3
|
//#region migrations/20260601T0000_install_vector_extension/migration.json
|
|
4
4
|
var migration_default = {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { n as VECTOR_CODEC_ID, r as VECTOR_MAX_DIM, t as pgVectorError } from "./errors-BnZLl-sM.mjs";
|
|
2
2
|
import { buildOperation, codecOf, toExpr } from "@prisma-next/sql-relational-core/expression";
|
|
3
3
|
import { buildCodecDescriptorRegistry } from "@prisma-next/sql-relational-core/codec-descriptor-registry";
|
|
4
|
-
import {
|
|
4
|
+
import { CodecImpl } from "@prisma-next/framework-components/codec";
|
|
5
|
+
import { PostgresCodecDescriptor, definePostgresCodecs } from "@prisma-next/target-postgres/codec-descriptor";
|
|
5
6
|
import { type } from "arktype";
|
|
6
7
|
//#region src/core/authoring.ts
|
|
7
8
|
const pgvectorAuthoringTypes = { pgvector: { Vector: {
|
|
@@ -97,7 +98,13 @@ var PgVectorCodec = class extends CodecImpl {
|
|
|
97
98
|
return value;
|
|
98
99
|
}
|
|
99
100
|
};
|
|
100
|
-
var PgVectorDescriptor = class extends
|
|
101
|
+
var PgVectorDescriptor = class extends PostgresCodecDescriptor {
|
|
102
|
+
nativeType() {
|
|
103
|
+
return PG_VECTOR_META.db.sql.postgres.nativeType;
|
|
104
|
+
}
|
|
105
|
+
jsonProjection(expression) {
|
|
106
|
+
return expression;
|
|
107
|
+
}
|
|
101
108
|
codecId = VECTOR_CODEC_ID;
|
|
102
109
|
traits = ["equality"];
|
|
103
110
|
targetTypes = ["vector"];
|
|
@@ -118,7 +125,7 @@ const codecDescriptorMap = { vector: new PgVectorDescriptor() };
|
|
|
118
125
|
*
|
|
119
126
|
* 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.
|
|
120
127
|
*/
|
|
121
|
-
const pgvectorCodecRegistry = buildCodecDescriptorRegistry(Object.values(codecDescriptorMap));
|
|
128
|
+
const pgvectorCodecRegistry = buildCodecDescriptorRegistry(definePostgresCodecs(Object.values(codecDescriptorMap)));
|
|
122
129
|
//#endregion
|
|
123
130
|
//#region src/core/descriptor-meta.ts
|
|
124
131
|
const pgvectorTypeId = "pg/vector@1";
|
|
@@ -207,4 +214,4 @@ const pgvectorPackMeta = {
|
|
|
207
214
|
//#endregion
|
|
208
215
|
export { pgvectorQueryOperations as n, pgvectorCodecRegistry as r, pgvectorPackMeta as t };
|
|
209
216
|
|
|
210
|
-
//# sourceMappingURL=descriptor-meta-
|
|
217
|
+
//# sourceMappingURL=descriptor-meta-Ct0uJ-Q0.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"descriptor-meta-Ct0uJ-Q0.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 PostgresCodecDescriptor} with the codec id, traits, target types, params schema (`{ length: number }`, validated against {@link VECTOR_MAX_DIM}), `meta` (postgres `nativeType: 'vector'`), explicit target behavior, 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 CodecImpl,\n type CodecInstanceContext,\n type ColumnHelperFor,\n type ColumnHelperForStrict,\n column,\n} from '@prisma-next/framework-components/codec';\nimport type { ExtractCodecTypes, ProjectionExpr } from '@prisma-next/sql-relational-core/ast';\nimport {\n definePostgresCodecs,\n PostgresCodecDescriptor,\n} from '@prisma-next/target-postgres/codec-descriptor';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { type as arktype } from 'arktype';\nimport { VECTOR_CODEC_ID, VECTOR_MAX_DIM } from './constants';\nimport { pgVectorError } from './errors';\n\ntype VectorConversionCode = 'RUNTIME.ENCODE_FAILED' | 'RUNTIME.DECODE_FAILED';\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\nfunction parseVector(value: string): number[] {\n if (!value.startsWith('[') || !value.endsWith(']')) {\n throw pgVectorError(\n 'RUNTIME.DECODE_FAILED',\n `Invalid vector format: expected \"[...]\", got \"${value}\"`,\n {\n why: 'The database returned a vector value that is not in the PostgreSQL \"[x,y,z]\" text format.',\n meta: { codecId: VECTOR_CODEC_ID, wirePreview: value },\n },\n );\n }\n const content = value.slice(1, -1).trim();\n return content === ''\n ? []\n : content.split(',').map((entry) => {\n const number = Number.parseFloat(entry.trim());\n if (Number.isNaN(number)) {\n throw pgVectorError(\n 'RUNTIME.DECODE_FAILED',\n `Invalid vector value: \"${entry}\" is not a number`,\n {\n why: 'A vector entry returned by the database could not be parsed as a number.',\n meta: { codecId: VECTOR_CODEC_ID, wirePreview: value },\n },\n );\n }\n return number;\n });\n}\n\nexport class PgVectorCodec extends CodecImpl<\n typeof VECTOR_CODEC_ID,\n readonly ['equality'],\n string,\n number[]\n> {\n readonly length: number;\n\n constructor(descriptor: AnyCodecDescriptor, length: number) {\n super(descriptor);\n this.length = length;\n }\n\n assertVector(value: unknown, code: VectorConversionCode): asserts value is number[] {\n const meta = { codecId: VECTOR_CODEC_ID, expectedLength: this.length };\n if (!Array.isArray(value)) {\n throw pgVectorError(code, 'Vector value must be an array of numbers', { meta });\n }\n for (const element of value) {\n if (typeof element !== 'number') {\n throw pgVectorError(code, 'Vector value must contain only numbers', { meta });\n }\n if (!Number.isFinite(element)) {\n throw pgVectorError(code, 'Vector value must contain only finite numbers', { meta });\n }\n }\n if (value.length !== this.length) {\n throw pgVectorError(\n code,\n `Vector length mismatch: expected ${this.length}, got ${value.length}`,\n {\n why: `This column is declared as vector(${this.length}); every value must have exactly that many dimensions.`,\n meta: { ...meta, receivedLength: value.length },\n },\n );\n }\n }\n\n async encode(value: number[], _ctx: CodecCallContext): Promise<string> {\n this.assertVector(value, 'RUNTIME.ENCODE_FAILED');\n return `[${value.join(',')}]`;\n }\n\n async decode(wire: string, _ctx: CodecCallContext): Promise<number[]> {\n if (typeof wire !== 'string') {\n throw pgVectorError('RUNTIME.DECODE_FAILED', 'Vector wire value must be a string', {\n meta: { codecId: VECTOR_CODEC_ID },\n });\n }\n const value = parseVector(wire);\n this.assertVector(value, 'RUNTIME.DECODE_FAILED');\n return value;\n }\n\n encodeJson(value: number[]): JsonValue {\n this.assertVector(value, 'RUNTIME.ENCODE_FAILED');\n return `[${value.join(',')}]`;\n }\n\n decodeJson(json: JsonValue): number[] {\n if (typeof json !== 'string') {\n throw pgVectorError('RUNTIME.DECODE_FAILED', 'Vector database JSON value must be a string', {\n meta: { codecId: VECTOR_CODEC_ID },\n });\n }\n const value = parseVector(json);\n this.assertVector(value, 'RUNTIME.DECODE_FAILED');\n return value;\n }\n}\n\nexport class PgVectorDescriptor extends PostgresCodecDescriptor<VectorParams> {\n protected override nativeType(): string {\n return PG_VECTOR_META.db.sql.postgres.nativeType;\n }\n protected override jsonProjection(expression: ProjectionExpr): ProjectionExpr {\n return expression;\n }\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 override factory(params: VectorParams): (ctx: CodecInstanceContext) => PgVectorCodec {\n return () => new PgVectorCodec(this, params.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 = definePostgresCodecs(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 {\n buildOperation,\n type CodecExpression,\n codecOf,\n type Expression,\n toExpr,\n} from '@prisma-next/sql-relational-core/expression';\nimport type { CodecTypes } from '../types/codec-types';\nimport type { QueryOperationTypes } from '../types/operation-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<CT extends CodecTypesBase>(): QueryOperationTypes<CT> {\n return {\n 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 selfCodec = codecOf(self);\n return buildOperation({\n method: 'cosineDistance',\n args: [toExpr(self, selfCodec), toExpr(other, selfCodec)],\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 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 selfCodec = codecOf(self);\n return buildOperation({\n method: 'cosineSimilarity',\n args: [toExpr(self, selfCodec), toExpr(other, selfCodec)],\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} = pgvectorPackMet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;AACF;AAoDA,MAAa,mBAET;CAnDF,MAAM;CACN,IAAI;CACJ,UAAU;CACV,UAAU;CACV,SAAS;CACT,cAAc,EACZ,UAAU,EACR,mBAAmB,KACrB,EACF;CACA,WAAW,EACT,MAAM,uBACR;CACA,OAAO;EACL,YAAY;GACV,kBAAkB,MAAM,KAAK,sBAAsB,OAAO,CAAC;GAC3D,QAAQ;IACN,SAAS;IACT,OAAO;IACP,OAAO;GACT;GACA,aAAa,CACX;IACE,SAAS;IACT,OAAO;IACP,OAAO;GACT,CACF;EACF;EACA,gBAAgB,EACd,QAAQ;GACN,SAAS;GACT,OAAO;GACP,OAAO;EACT,EACF;EACA,qBAAqB,EACnB,QAAQ;GACN,SAAS;GACT,OAAO;GACP,OAAO;EACT,EACF;EACA,SAAS,CACP;GAAE,QAAQ;GAAgB,UAAU;GAAO,UAAU;GAAY,YAAY;EAAS,CACxF;CACF;AAKE"}
|
package/dist/pack.d.mts
CHANGED
package/dist/pack.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as pgvectorPackMeta } from "./descriptor-meta-
|
|
1
|
+
import { t as pgvectorPackMeta } from "./descriptor-meta-Ct0uJ-Q0.mjs";
|
|
2
2
|
export { pgvectorPackMeta as default };
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as pgvectorQueryOperations, r as pgvectorCodecRegistry, t as pgvectorPackMeta } from "./descriptor-meta-
|
|
1
|
+
import { n as pgvectorQueryOperations, r as pgvectorCodecRegistry, t as pgvectorPackMeta } from "./descriptor-meta-Ct0uJ-Q0.mjs";
|
|
2
2
|
//#region src/exports/runtime.ts
|
|
3
3
|
const pgvectorRuntimeDescriptor = {
|
|
4
4
|
kind: "extension",
|
package/package.json
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/extension-pgvector",
|
|
3
|
-
"version": "0.16.0-dev.
|
|
3
|
+
"version": "0.16.0-dev.34",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@prisma-next/contract": "0.16.0-dev.
|
|
9
|
-
"@prisma-next/contract-authoring": "0.16.0-dev.
|
|
10
|
-
"@prisma-next/family-sql": "0.16.0-dev.
|
|
11
|
-
"@prisma-next/framework-components": "0.16.0-dev.
|
|
12
|
-
"@prisma-next/migration-tools": "0.16.0-dev.
|
|
13
|
-
"@prisma-next/sql-contract": "0.16.0-dev.
|
|
14
|
-
"@prisma-next/sql-operations": "0.16.0-dev.
|
|
15
|
-
"@prisma-next/sql-relational-core": "0.16.0-dev.
|
|
16
|
-
"@prisma-next/sql-runtime": "0.16.0-dev.
|
|
17
|
-
"@prisma-next/sql-schema-ir": "0.16.0-dev.
|
|
18
|
-
"@prisma-next/
|
|
8
|
+
"@prisma-next/contract": "0.16.0-dev.34",
|
|
9
|
+
"@prisma-next/contract-authoring": "0.16.0-dev.34",
|
|
10
|
+
"@prisma-next/family-sql": "0.16.0-dev.34",
|
|
11
|
+
"@prisma-next/framework-components": "0.16.0-dev.34",
|
|
12
|
+
"@prisma-next/migration-tools": "0.16.0-dev.34",
|
|
13
|
+
"@prisma-next/sql-contract": "0.16.0-dev.34",
|
|
14
|
+
"@prisma-next/sql-operations": "0.16.0-dev.34",
|
|
15
|
+
"@prisma-next/sql-relational-core": "0.16.0-dev.34",
|
|
16
|
+
"@prisma-next/sql-runtime": "0.16.0-dev.34",
|
|
17
|
+
"@prisma-next/sql-schema-ir": "0.16.0-dev.34",
|
|
18
|
+
"@prisma-next/target-postgres": "0.16.0-dev.34",
|
|
19
|
+
"@prisma-next/utils": "0.16.0-dev.34",
|
|
19
20
|
"@standard-schema/spec": "^1.1.0",
|
|
20
21
|
"arktype": "^2.2.2"
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
23
|
-
"@prisma-next/adapter-postgres": "0.16.0-dev.
|
|
24
|
-
"@prisma-next/cli": "0.16.0-dev.
|
|
25
|
-
"@prisma-next/operations": "0.16.0-dev.
|
|
26
|
-
"@prisma-next/postgres": "0.16.0-dev.
|
|
27
|
-
"@prisma-next/sql-contract-ts": "0.16.0-dev.
|
|
28
|
-
"@prisma-next/
|
|
29
|
-
"@prisma-next/
|
|
30
|
-
"@prisma-next/
|
|
31
|
-
"@prisma-next/tsdown": "0.16.0-dev.32",
|
|
24
|
+
"@prisma-next/adapter-postgres": "0.16.0-dev.34",
|
|
25
|
+
"@prisma-next/cli": "0.16.0-dev.34",
|
|
26
|
+
"@prisma-next/operations": "0.16.0-dev.34",
|
|
27
|
+
"@prisma-next/postgres": "0.16.0-dev.34",
|
|
28
|
+
"@prisma-next/sql-contract-ts": "0.16.0-dev.34",
|
|
29
|
+
"@prisma-next/test-utils": "0.16.0-dev.34",
|
|
30
|
+
"@prisma-next/tsconfig": "0.16.0-dev.34",
|
|
31
|
+
"@prisma-next/tsdown": "0.16.0-dev.34",
|
|
32
32
|
"tsdown": "0.22.8",
|
|
33
33
|
"typescript": "5.9.3",
|
|
34
34
|
"vitest": "4.1.10"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@prisma-next/adapter-postgres": "0.16.0-dev.
|
|
37
|
+
"@prisma-next/adapter-postgres": "0.16.0-dev.34",
|
|
38
38
|
"typescript": ">=5.9"
|
|
39
39
|
},
|
|
40
40
|
"peerDependenciesMeta": {
|
package/src/core/codecs.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Mirrors the patterns in `postgres/codecs-class.ts` and `sqlite/codecs-class.ts` for the single `pg/vector@1` codec. Three artifacts:
|
|
5
5
|
*
|
|
6
6
|
* 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.
|
|
7
|
-
* 2. `PgVectorDescriptor` extends {@link
|
|
7
|
+
* 2. `PgVectorDescriptor` extends {@link PostgresCodecDescriptor} with the codec id, traits, target types, params schema (`{ length: number }`, validated against {@link VECTOR_MAX_DIM}), `meta` (postgres `nativeType: 'vector'`), explicit target behavior, and the emit-path `renderOutputType` producing `Vector<${length}>`.
|
|
8
8
|
* 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`.
|
|
9
9
|
*
|
|
10
10
|
* `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.
|
|
@@ -14,14 +14,17 @@ import type { JsonValue } from '@prisma-next/contract/types';
|
|
|
14
14
|
import {
|
|
15
15
|
type AnyCodecDescriptor,
|
|
16
16
|
type CodecCallContext,
|
|
17
|
-
CodecDescriptorImpl,
|
|
18
17
|
CodecImpl,
|
|
19
18
|
type CodecInstanceContext,
|
|
20
19
|
type ColumnHelperFor,
|
|
21
20
|
type ColumnHelperForStrict,
|
|
22
21
|
column,
|
|
23
22
|
} from '@prisma-next/framework-components/codec';
|
|
24
|
-
import type { ExtractCodecTypes } from '@prisma-next/sql-relational-core/ast';
|
|
23
|
+
import type { ExtractCodecTypes, ProjectionExpr } from '@prisma-next/sql-relational-core/ast';
|
|
24
|
+
import {
|
|
25
|
+
definePostgresCodecs,
|
|
26
|
+
PostgresCodecDescriptor,
|
|
27
|
+
} from '@prisma-next/target-postgres/codec-descriptor';
|
|
25
28
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
26
29
|
import { type as arktype } from 'arktype';
|
|
27
30
|
import { VECTOR_CODEC_ID, VECTOR_MAX_DIM } from './constants';
|
|
@@ -147,7 +150,13 @@ export class PgVectorCodec extends CodecImpl<
|
|
|
147
150
|
}
|
|
148
151
|
}
|
|
149
152
|
|
|
150
|
-
export class PgVectorDescriptor extends
|
|
153
|
+
export class PgVectorDescriptor extends PostgresCodecDescriptor<VectorParams> {
|
|
154
|
+
protected override nativeType(): string {
|
|
155
|
+
return PG_VECTOR_META.db.sql.postgres.nativeType;
|
|
156
|
+
}
|
|
157
|
+
protected override jsonProjection(expression: ProjectionExpr): ProjectionExpr {
|
|
158
|
+
return expression;
|
|
159
|
+
}
|
|
151
160
|
override readonly codecId = VECTOR_CODEC_ID;
|
|
152
161
|
override readonly traits = ['equality'] as const;
|
|
153
162
|
override readonly targetTypes = ['vector'] as const;
|
|
@@ -180,4 +189,4 @@ const codecDescriptorMap = {
|
|
|
180
189
|
|
|
181
190
|
export type CodecTypes = ExtractCodecTypes<typeof codecDescriptorMap>;
|
|
182
191
|
|
|
183
|
-
export const codecDescriptors
|
|
192
|
+
export const codecDescriptors = definePostgresCodecs(Object.values(codecDescriptorMap));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codec-types-eUx62rq4.d.mts","names":[],"sources":["../src/core/constants.ts","../src/core/codecs.ts","../src/types/codec-types.ts"],"mappings":";;;;;;;;cAGa;;;KC0BR;KAEA;WAA0B;;cA+ClB,sBAAsB,iBAC1B;WAKE;cAEG,YAAY,oBAAoB;EAK5C,aAAa,gBAAgB,MAAM,+BAA+B;EAyB5D,OAAO,iBAAiB,MAAM,mBAAmB;EAKjD,OAAO,cAAc,MAAM,mBAAmB;EAWpD,WAAW,kBAAkB;EAK7B,WAAW,MAAM;;cAYN,2BAA2B,oBAAoB;WACxC;WACA;WACA;WACA;;;;;;;;;WACA,cAAc,iBAAiB;EACxC,iBAAiB,QAAQ;EAGzB,QAAQ,QAAQ,gBAAgB,KAAK,yBAAyB;;cAkBnE;mBAAA;;KAIM,eAAa,yBAAyB;;;;;;;;;KCnKtC,OAAO;WAAmD,iBAAiB;;KAE3E,aAAa"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"descriptor-meta-DMPKzaNe.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';\nimport { pgVectorError } from './errors';\n\ntype VectorConversionCode = 'RUNTIME.ENCODE_FAILED' | 'RUNTIME.DECODE_FAILED';\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\nfunction parseVector(value: string): number[] {\n if (!value.startsWith('[') || !value.endsWith(']')) {\n throw pgVectorError(\n 'RUNTIME.DECODE_FAILED',\n `Invalid vector format: expected \"[...]\", got \"${value}\"`,\n {\n why: 'The database returned a vector value that is not in the PostgreSQL \"[x,y,z]\" text format.',\n meta: { codecId: VECTOR_CODEC_ID, wirePreview: value },\n },\n );\n }\n const content = value.slice(1, -1).trim();\n return content === ''\n ? []\n : content.split(',').map((entry) => {\n const number = Number.parseFloat(entry.trim());\n if (Number.isNaN(number)) {\n throw pgVectorError(\n 'RUNTIME.DECODE_FAILED',\n `Invalid vector value: \"${entry}\" is not a number`,\n {\n why: 'A vector entry returned by the database could not be parsed as a number.',\n meta: { codecId: VECTOR_CODEC_ID, wirePreview: value },\n },\n );\n }\n return number;\n });\n}\n\nexport class PgVectorCodec extends CodecImpl<\n typeof VECTOR_CODEC_ID,\n readonly ['equality'],\n string,\n number[]\n> {\n readonly length: number;\n\n constructor(descriptor: AnyCodecDescriptor, length: number) {\n super(descriptor);\n this.length = length;\n }\n\n assertVector(value: unknown, code: VectorConversionCode): asserts value is number[] {\n const meta = { codecId: VECTOR_CODEC_ID, expectedLength: this.length };\n if (!Array.isArray(value)) {\n throw pgVectorError(code, 'Vector value must be an array of numbers', { meta });\n }\n for (const element of value) {\n if (typeof element !== 'number') {\n throw pgVectorError(code, 'Vector value must contain only numbers', { meta });\n }\n if (!Number.isFinite(element)) {\n throw pgVectorError(code, 'Vector value must contain only finite numbers', { meta });\n }\n }\n if (value.length !== this.length) {\n throw pgVectorError(\n code,\n `Vector length mismatch: expected ${this.length}, got ${value.length}`,\n {\n why: `This column is declared as vector(${this.length}); every value must have exactly that many dimensions.`,\n meta: { ...meta, receivedLength: value.length },\n },\n );\n }\n }\n\n async encode(value: number[], _ctx: CodecCallContext): Promise<string> {\n this.assertVector(value, 'RUNTIME.ENCODE_FAILED');\n return `[${value.join(',')}]`;\n }\n\n async decode(wire: string, _ctx: CodecCallContext): Promise<number[]> {\n if (typeof wire !== 'string') {\n throw pgVectorError('RUNTIME.DECODE_FAILED', 'Vector wire value must be a string', {\n meta: { codecId: VECTOR_CODEC_ID },\n });\n }\n const value = parseVector(wire);\n this.assertVector(value, 'RUNTIME.DECODE_FAILED');\n return value;\n }\n\n encodeJson(value: number[]): JsonValue {\n this.assertVector(value, 'RUNTIME.ENCODE_FAILED');\n return `[${value.join(',')}]`;\n }\n\n decodeJson(json: JsonValue): number[] {\n if (typeof json !== 'string') {\n throw pgVectorError('RUNTIME.DECODE_FAILED', 'Vector database JSON value must be a string', {\n meta: { codecId: VECTOR_CODEC_ID },\n });\n }\n const value = parseVector(json);\n this.assertVector(value, 'RUNTIME.DECODE_FAILED');\n return value;\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 override factory(params: VectorParams): (ctx: CodecInstanceContext) => PgVectorCodec {\n return () => new PgVectorCodec(this, params.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 {\n buildOperation,\n type CodecExpression,\n codecOf,\n type Expression,\n toExpr,\n} from '@prisma-next/sql-relational-core/expression';\nimport type { CodecTypes } from '../types/codec-types';\nimport type { QueryOperationTypes } from '../types/operation-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<CT extends CodecTypesBase>(): QueryOperationTypes<CT> {\n return {\n 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 selfCodec = codecOf(self);\n return buildOperation({\n method: 'cosineDistance',\n args: [toExpr(self, selfCodec), toExpr(other, selfCodec)],\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 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 selfCodec = codecOf(self);\n return buildOperation({\n method: 'cosineSimilarity',\n args: [toExpr(self, selfCodec), toExpr(other, selfCodec)],\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;CAAe,CACvF;CACA,QAAQ;EACN,SAAS;EACT,YAAY;EACZ,YAAY,EACV,QAAQ;GAAE,MAAM;GAAO,OAAO;EAAE,EAClC;CACF;AACF,EACF,EACF;;;ACcA,MAAM,qBAAqBA,KAAQ,EACjC,QAAQ,SACV,CAAC,CAAC,CAAC,QAAQ,QAAQ,QAAQ;CACzB,MAAM,EAAE,WAAW;CACnB,IAAI,CAAC,OAAO,UAAU,MAAM,GAC1B,OAAO,IAAI,OAAO,YAAY;CAEhC,IAAI,SAAS,KAAK,SAAA,MAChB,OAAO,IAAI,OAAO,oBAAoB,eAAe,EAAE;CAEzD,OAAO;AACT,CAAC;AAED,MAAM,iBAAiB,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,SAAS,EAAE,EAAE,EAAE;AAE7E,SAAS,YAAY,OAAyB;CAC5C,IAAI,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,SAAS,GAAG,GAC/C,MAAM,cACJ,yBACA,iDAAiD,MAAM,IACvD;EACE,KAAK;EACL,MAAM;GAAE,SAAS;GAAiB,aAAa;EAAM;CACvD,CACF;CAEF,MA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