@prisma-next/extension-pgvector 0.3.0-pr.99.6 → 0.4.0-dev.2

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.
Files changed (76) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +50 -30
  3. package/dist/codec-types-BifaP625.d.mts +27 -0
  4. package/dist/codec-types-BifaP625.d.mts.map +1 -0
  5. package/dist/codec-types.d.mts +2 -0
  6. package/dist/codec-types.mjs +1 -0
  7. package/dist/column-types.d.mts +33 -0
  8. package/dist/column-types.d.mts.map +1 -0
  9. package/dist/column-types.mjs +36 -0
  10. package/dist/column-types.mjs.map +1 -0
  11. package/dist/constants-Co5golCK.mjs +13 -0
  12. package/dist/constants-Co5golCK.mjs.map +1 -0
  13. package/dist/control.d.mts +7 -0
  14. package/dist/control.d.mts.map +1 -0
  15. package/dist/control.mjs +61 -0
  16. package/dist/control.mjs.map +1 -0
  17. package/dist/descriptor-meta-CHj8SCio.mjs +147 -0
  18. package/dist/descriptor-meta-CHj8SCio.mjs.map +1 -0
  19. package/dist/operation-types.d.mts +76 -0
  20. package/dist/operation-types.d.mts.map +1 -0
  21. package/dist/operation-types.mjs +1 -0
  22. package/dist/pack.d.mts +86 -0
  23. package/dist/pack.d.mts.map +1 -0
  24. package/dist/pack.mjs +9 -0
  25. package/dist/pack.mjs.map +1 -0
  26. package/dist/runtime.d.mts +7 -0
  27. package/dist/runtime.d.mts.map +1 -0
  28. package/dist/runtime.mjs +41 -0
  29. package/dist/runtime.mjs.map +1 -0
  30. package/package.json +30 -44
  31. package/src/core/authoring.ts +20 -0
  32. package/src/core/codecs.ts +12 -1
  33. package/src/core/constants.ts +9 -0
  34. package/src/core/descriptor-meta.ts +51 -38
  35. package/src/exports/codec-types.ts +1 -1
  36. package/src/exports/column-types.ts +34 -1
  37. package/src/exports/control.ts +32 -26
  38. package/src/exports/operation-types.ts +1 -1
  39. package/src/exports/pack.ts +6 -1
  40. package/src/exports/runtime.ts +37 -27
  41. package/src/types/codec-types.ts +11 -1
  42. package/src/types/operation-types.ts +30 -12
  43. package/dist/chunk-OI5XEHIN.js +0 -67
  44. package/dist/chunk-OI5XEHIN.js.map +0 -1
  45. package/dist/core/codecs.d.ts +0 -23
  46. package/dist/core/codecs.d.ts.map +0 -1
  47. package/dist/core/descriptor-meta.d.ts +0 -56
  48. package/dist/core/descriptor-meta.d.ts.map +0 -1
  49. package/dist/exports/codec-types.d.ts +0 -7
  50. package/dist/exports/codec-types.d.ts.map +0 -1
  51. package/dist/exports/codec-types.js +0 -1
  52. package/dist/exports/codec-types.js.map +0 -1
  53. package/dist/exports/column-types.d.ts +0 -11
  54. package/dist/exports/column-types.d.ts.map +0 -1
  55. package/dist/exports/column-types.js +0 -9
  56. package/dist/exports/column-types.js.map +0 -1
  57. package/dist/exports/control.d.ts +0 -9
  58. package/dist/exports/control.d.ts.map +0 -1
  59. package/dist/exports/control.js +0 -67
  60. package/dist/exports/control.js.map +0 -1
  61. package/dist/exports/operation-types.d.ts +0 -7
  62. package/dist/exports/operation-types.d.ts.map +0 -1
  63. package/dist/exports/operation-types.js +0 -1
  64. package/dist/exports/operation-types.js.map +0 -1
  65. package/dist/exports/pack.d.ts +0 -55
  66. package/dist/exports/pack.d.ts.map +0 -1
  67. package/dist/exports/pack.js +0 -11
  68. package/dist/exports/pack.js.map +0 -1
  69. package/dist/exports/runtime.d.ts +0 -8
  70. package/dist/exports/runtime.d.ts.map +0 -1
  71. package/dist/exports/runtime.js +0 -86
  72. package/dist/exports/runtime.js.map +0 -1
  73. package/dist/types/codec-types.d.ts +0 -10
  74. package/dist/types/codec-types.d.ts.map +0 -1
  75. package/dist/types/operation-types.d.ts +0 -31
  76. package/dist/types/operation-types.d.ts.map +0 -1
@@ -0,0 +1,147 @@
1
+ import { n as VECTOR_MAX_DIM } from "./constants-Co5golCK.mjs";
2
+ import { codec, defineCodecs } from "@prisma-next/sql-relational-core/ast";
3
+
4
+ //#region src/core/authoring.ts
5
+ const pgvectorAuthoringTypes = { pgvector: { Vector: {
6
+ kind: "typeConstructor",
7
+ args: [{
8
+ kind: "number",
9
+ name: "length",
10
+ integer: true,
11
+ minimum: 1,
12
+ maximum: VECTOR_MAX_DIM
13
+ }],
14
+ output: {
15
+ codecId: "pg/vector@1",
16
+ nativeType: "vector",
17
+ typeParams: { length: {
18
+ kind: "arg",
19
+ index: 0
20
+ } }
21
+ }
22
+ } } };
23
+
24
+ //#endregion
25
+ //#region src/core/codecs.ts
26
+ /**
27
+ * Vector codec implementation for pgvector extension.
28
+ *
29
+ * Provides encoding/decoding for the `vector` PostgreSQL type.
30
+ * Wire format is a string like `[1,2,3]` (PostgreSQL vector text format).
31
+ */
32
+ const pgVectorCodec = codec({
33
+ typeId: "pg/vector@1",
34
+ targetTypes: ["vector"],
35
+ traits: ["equality"],
36
+ renderOutputType: (typeParams) => {
37
+ const length = typeParams["length"];
38
+ if (length === void 0) return void 0;
39
+ if (typeof length !== "number" || !Number.isFinite(length) || !Number.isInteger(length)) throw new Error(`renderOutputType: expected positive integer "length" in typeParams for Vector, got ${String(length)}`);
40
+ return `Vector<${length}>`;
41
+ },
42
+ encode: (value) => {
43
+ if (!Array.isArray(value)) throw new Error("Vector value must be an array of numbers");
44
+ if (!value.every((v) => typeof v === "number")) throw new Error("Vector value must contain only numbers");
45
+ return `[${value.join(",")}]`;
46
+ },
47
+ decode: (wire) => {
48
+ if (typeof wire !== "string") throw new Error("Vector wire value must be a string");
49
+ if (!wire.startsWith("[") || !wire.endsWith("]")) throw new Error(`Invalid vector format: expected "[...]", got "${wire}"`);
50
+ const content = wire.slice(1, -1).trim();
51
+ if (content === "") return [];
52
+ return content.split(",").map((v) => {
53
+ const num = Number.parseFloat(v.trim());
54
+ if (Number.isNaN(num)) throw new Error(`Invalid vector value: "${v}" is not a number`);
55
+ return num;
56
+ });
57
+ },
58
+ meta: { db: { sql: { postgres: { nativeType: "vector" } } } }
59
+ });
60
+ const codecs = defineCodecs().add("vector", pgVectorCodec);
61
+ const codecDefinitions = codecs.codecDefinitions;
62
+ const dataTypes = codecs.dataTypes;
63
+
64
+ //#endregion
65
+ //#region src/core/descriptor-meta.ts
66
+ const pgvectorTypeId = "pg/vector@1";
67
+ const pgvectorQueryOperations = [{
68
+ method: "cosineDistance",
69
+ args: [{
70
+ codecId: pgvectorTypeId,
71
+ nullable: false
72
+ }, {
73
+ codecId: pgvectorTypeId,
74
+ nullable: false
75
+ }],
76
+ returns: {
77
+ codecId: "pg/float8@1",
78
+ nullable: false
79
+ },
80
+ lowering: {
81
+ targetFamily: "sql",
82
+ strategy: "function",
83
+ template: "{{self}} <=> {{arg0}}"
84
+ }
85
+ }, {
86
+ method: "cosineSimilarity",
87
+ args: [{
88
+ codecId: pgvectorTypeId,
89
+ nullable: false
90
+ }, {
91
+ codecId: pgvectorTypeId,
92
+ nullable: false
93
+ }],
94
+ returns: {
95
+ codecId: "pg/float8@1",
96
+ nullable: false
97
+ },
98
+ lowering: {
99
+ targetFamily: "sql",
100
+ strategy: "function",
101
+ template: "1 - ({{self}} <=> {{arg0}})"
102
+ }
103
+ }];
104
+ const pgvectorPackMeta = {
105
+ kind: "extension",
106
+ id: "pgvector",
107
+ familyId: "sql",
108
+ targetId: "postgres",
109
+ version: "0.0.1",
110
+ capabilities: { postgres: { "pgvector.cosine": true } },
111
+ authoring: { type: pgvectorAuthoringTypes },
112
+ types: {
113
+ codecTypes: {
114
+ codecInstances: Object.values(codecDefinitions).map((def) => def.codec),
115
+ import: {
116
+ package: "@prisma-next/extension-pgvector/codec-types",
117
+ named: "CodecTypes",
118
+ alias: "PgVectorTypes"
119
+ },
120
+ typeImports: [{
121
+ package: "@prisma-next/extension-pgvector/codec-types",
122
+ named: "Vector",
123
+ alias: "Vector"
124
+ }]
125
+ },
126
+ operationTypes: { import: {
127
+ package: "@prisma-next/extension-pgvector/operation-types",
128
+ named: "OperationTypes",
129
+ alias: "PgVectorOperationTypes"
130
+ } },
131
+ queryOperationTypes: { import: {
132
+ package: "@prisma-next/extension-pgvector/operation-types",
133
+ named: "QueryOperationTypes",
134
+ alias: "PgVectorQueryOperationTypes"
135
+ } },
136
+ storage: [{
137
+ typeId: pgvectorTypeId,
138
+ familyId: "sql",
139
+ targetId: "postgres",
140
+ nativeType: "vector"
141
+ }]
142
+ }
143
+ };
144
+
145
+ //#endregion
146
+ export { pgvectorQueryOperations as n, codecDefinitions as r, pgvectorPackMeta as t };
147
+ //# sourceMappingURL=descriptor-meta-CHj8SCio.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"descriptor-meta-CHj8SCio.mjs","names":["pgvectorQueryOperations: readonly SqlOperationDescriptor[]"],"sources":["../src/core/authoring.ts","../src/core/codecs.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 * Vector codec implementation for pgvector extension.\n *\n * Provides encoding/decoding for the `vector` PostgreSQL type.\n * Wire format is a string like `[1,2,3]` (PostgreSQL vector text format).\n */\n\nimport { codec, defineCodecs } from '@prisma-next/sql-relational-core/ast';\n\nconst pgVectorCodec = codec({\n typeId: 'pg/vector@1',\n targetTypes: ['vector'],\n traits: ['equality'],\n renderOutputType: (typeParams) => {\n const length = typeParams['length'];\n if (length === undefined) return undefined;\n if (typeof length !== 'number' || !Number.isFinite(length) || !Number.isInteger(length)) {\n throw new Error(\n `renderOutputType: expected positive integer \"length\" in typeParams for Vector, got ${String(length)}`,\n );\n }\n return `Vector<${length}>`;\n },\n encode: (value: number[]): string => {\n // Validate that value is an array of numbers\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 // Format as PostgreSQL vector text format: [1,2,3]\n // PostgreSQL's pg library requires the vector format string\n return `[${value.join(',')}]`;\n },\n decode: (wire: string): number[] => {\n // Handle string format from PostgreSQL: [1,2,3]\n if (typeof wire !== 'string') {\n throw new Error('Vector wire value must be a string');\n }\n // Parse PostgreSQL vector format: [1,2,3]\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 if (content === '') {\n return [];\n }\n const values = 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 return values;\n },\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'vector',\n },\n },\n },\n },\n});\n\n// Build codec definitions using the builder DSL\nconst codecs = defineCodecs().add('vector', pgVectorCodec);\n\n// Export derived structures directly from codecs builder\nexport const codecDefinitions = codecs.codecDefinitions;\nexport const dataTypes = codecs.dataTypes;\n\n// Export types derived from codecs builder\nexport type CodecTypes = typeof codecs.CodecTypes;\n","import type { SqlOperationDescriptor } from '@prisma-next/sql-operations';\nimport { pgvectorAuthoringTypes } from './authoring';\nimport { codecDefinitions } from './codecs';\n\nconst pgvectorTypeId = 'pg/vector@1' as const;\n\nexport const pgvectorQueryOperations: readonly SqlOperationDescriptor[] = [\n {\n method: 'cosineDistance',\n args: [\n { codecId: pgvectorTypeId, nullable: false },\n { codecId: pgvectorTypeId, nullable: false },\n ],\n returns: { codecId: 'pg/float8@1', nullable: false },\n lowering: {\n targetFamily: 'sql',\n strategy: 'function',\n template: '{{self}} <=> {{arg0}}',\n },\n },\n {\n method: 'cosineSimilarity',\n args: [\n { codecId: pgvectorTypeId, nullable: false },\n { codecId: pgvectorTypeId, nullable: false },\n ],\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\nexport const pgvectorPackMeta = {\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 codecInstances: Object.values(codecDefinitions).map((def) => def.codec),\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"],"mappings":"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"}
@@ -0,0 +1,76 @@
1
+ import { SqlQueryOperationTypes } from "@prisma-next/sql-contract/types";
2
+
3
+ //#region src/types/operation-types.d.ts
4
+
5
+ /**
6
+ * Operation type definitions for pgvector extension.
7
+ *
8
+ * This file exports type-only definitions for operation method signatures.
9
+ * These types are imported by contract.d.ts files for compile-time type inference.
10
+ */
11
+ type OperationTypes = {
12
+ readonly 'pg/vector@1': {
13
+ readonly cosineDistance: {
14
+ readonly args: readonly [{
15
+ 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
+ };
27
+ };
28
+ readonly cosineSimilarity: {
29
+ readonly args: readonly [{
30
+ 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
+ };
42
+ };
43
+ };
44
+ };
45
+ /** Flat operation signatures for the query builder. */
46
+ type QueryOperationTypes = SqlQueryOperationTypes<{
47
+ readonly cosineDistance: {
48
+ readonly args: readonly [{
49
+ readonly codecId: 'pg/vector@1';
50
+ readonly nullable: boolean;
51
+ }, {
52
+ readonly codecId: 'pg/vector@1';
53
+ readonly nullable: boolean;
54
+ }];
55
+ readonly returns: {
56
+ readonly codecId: 'pg/float8@1';
57
+ readonly nullable: false;
58
+ };
59
+ };
60
+ readonly cosineSimilarity: {
61
+ readonly args: readonly [{
62
+ readonly codecId: 'pg/vector@1';
63
+ readonly nullable: boolean;
64
+ }, {
65
+ readonly codecId: 'pg/vector@1';
66
+ readonly nullable: boolean;
67
+ }];
68
+ readonly returns: {
69
+ readonly codecId: 'pg/float8@1';
70
+ readonly nullable: false;
71
+ };
72
+ };
73
+ }>;
74
+ //#endregion
75
+ export { type OperationTypes, type QueryOperationTypes };
76
+ //# sourceMappingURL=operation-types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operation-types.d.mts","names":[],"sources":["../src/types/operation-types.ts"],"sourcesContent":[],"mappings":";;;;;;AASA;AAwBA;;;KAxBY,cAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAwBA,mBAAA,GAAsB"}
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,86 @@
1
+ import { t as CodecTypes } from "./codec-types-BifaP625.mjs";
2
+ import * as _prisma_next_sql_relational_core_ast0 from "@prisma-next/sql-relational-core/ast";
3
+ import { ExtensionPackRef } from "@prisma-next/framework-components/components";
4
+
5
+ //#region src/core/descriptor-meta.d.ts
6
+ declare const pgvectorPackMeta: {
7
+ readonly kind: "extension";
8
+ readonly id: "pgvector";
9
+ readonly familyId: "sql";
10
+ readonly targetId: "postgres";
11
+ readonly version: "0.0.1";
12
+ readonly capabilities: {
13
+ readonly postgres: {
14
+ readonly 'pgvector.cosine': true;
15
+ };
16
+ };
17
+ readonly authoring: {
18
+ readonly type: {
19
+ readonly pgvector: {
20
+ readonly Vector: {
21
+ readonly kind: "typeConstructor";
22
+ readonly args: readonly [{
23
+ readonly kind: "number";
24
+ readonly name: "length";
25
+ readonly integer: true;
26
+ readonly minimum: 1;
27
+ readonly maximum: 16000;
28
+ }];
29
+ readonly output: {
30
+ readonly codecId: "pg/vector@1";
31
+ readonly nativeType: "vector";
32
+ readonly typeParams: {
33
+ readonly length: {
34
+ readonly kind: "arg";
35
+ readonly index: 0;
36
+ };
37
+ };
38
+ };
39
+ };
40
+ };
41
+ };
42
+ };
43
+ readonly types: {
44
+ readonly codecTypes: {
45
+ readonly codecInstances: _prisma_next_sql_relational_core_ast0.Codec<"pg/vector@1", readonly ["equality"], string, number[], Record<string, unknown>, unknown>[];
46
+ readonly import: {
47
+ readonly package: "@prisma-next/extension-pgvector/codec-types";
48
+ readonly named: "CodecTypes";
49
+ readonly alias: "PgVectorTypes";
50
+ };
51
+ readonly typeImports: readonly [{
52
+ readonly package: "@prisma-next/extension-pgvector/codec-types";
53
+ readonly named: "Vector";
54
+ readonly alias: "Vector";
55
+ }];
56
+ };
57
+ readonly operationTypes: {
58
+ readonly import: {
59
+ readonly package: "@prisma-next/extension-pgvector/operation-types";
60
+ readonly named: "OperationTypes";
61
+ readonly alias: "PgVectorOperationTypes";
62
+ };
63
+ };
64
+ readonly queryOperationTypes: {
65
+ readonly import: {
66
+ readonly package: "@prisma-next/extension-pgvector/operation-types";
67
+ readonly named: "QueryOperationTypes";
68
+ readonly alias: "PgVectorQueryOperationTypes";
69
+ };
70
+ };
71
+ readonly storage: readonly [{
72
+ readonly typeId: "pg/vector@1";
73
+ readonly familyId: "sql";
74
+ readonly targetId: "postgres";
75
+ readonly nativeType: "vector";
76
+ }];
77
+ };
78
+ };
79
+ //#endregion
80
+ //#region src/exports/pack.d.ts
81
+ declare const _default: typeof pgvectorPackMeta & ExtensionPackRef<"sql", "postgres"> & {
82
+ readonly __codecTypes?: CodecTypes;
83
+ };
84
+ //#endregion
85
+ export { _default as default };
86
+ //# sourceMappingURL=pack.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pack.d.mts","names":[],"sources":["../src/core/descriptor-meta.ts","../src/exports/pack.ts"],"sourcesContent":[],"mappings":";;;;;cAmCa;;;EAAA,SAAA,QAAA,EAgDH,KAAA;;;;ICjF6C,SAOpD,QAAA,EAAA;MAHmC,SAAA,iBAAA,EAAA,IAAA;IACpC,CAAA;EAC0B,CAAA;EAAU,SAAA,SAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BD2E5B,qCAAA,CAAA,8DAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cCjF6C,iBAIjB,mBACpC;0BAC0B;AD2B5B,CAAA"}
package/dist/pack.mjs ADDED
@@ -0,0 +1,9 @@
1
+ import { t as pgvectorPackMeta } from "./descriptor-meta-CHj8SCio.mjs";
2
+
3
+ //#region src/exports/pack.ts
4
+ const pgvectorPack = pgvectorPackMeta;
5
+ var pack_default = pgvectorPack;
6
+
7
+ //#endregion
8
+ export { pack_default as default };
9
+ //# sourceMappingURL=pack.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pack.mjs","names":[],"sources":["../src/exports/pack.ts"],"sourcesContent":["import type { ExtensionPackRef } from '@prisma-next/framework-components/components';\nimport { pgvectorPackMeta } from '../core/descriptor-meta';\nimport type { CodecTypes } from '../types/codec-types';\n\nconst pgvectorPack = pgvectorPackMeta;\n\nexport default pgvectorPack as typeof pgvectorPackMeta &\n ExtensionPackRef<'sql', 'postgres'> & {\n readonly __codecTypes?: CodecTypes;\n };\n"],"mappings":";;;AAIA,MAAM,eAAe;AAErB,mBAAe"}
@@ -0,0 +1,7 @@
1
+ import { SqlRuntimeExtensionDescriptor } from "@prisma-next/sql-runtime";
2
+
3
+ //#region src/exports/runtime.d.ts
4
+ declare const pgvectorRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'>;
5
+ //#endregion
6
+ export { pgvectorRuntimeDescriptor as default };
7
+ //# sourceMappingURL=runtime.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/exports/runtime.ts"],"sourcesContent":[],"mappings":";;;cAwCM,2BAA2B"}
@@ -0,0 +1,41 @@
1
+ import { n as VECTOR_MAX_DIM, t as VECTOR_CODEC_ID } from "./constants-Co5golCK.mjs";
2
+ import { n as pgvectorQueryOperations, r as codecDefinitions, t as pgvectorPackMeta } from "./descriptor-meta-CHj8SCio.mjs";
3
+ import { createCodecRegistry } from "@prisma-next/sql-relational-core/ast";
4
+ import { type } from "arktype";
5
+
6
+ //#region src/exports/runtime.ts
7
+ const parameterizedCodecDescriptors = [{
8
+ codecId: VECTOR_CODEC_ID,
9
+ paramsSchema: type({ length: "number" }).narrow((params, ctx) => {
10
+ const { length } = params;
11
+ if (!Number.isInteger(length)) return ctx.mustBe("an integer");
12
+ if (length < 1 || length > VECTOR_MAX_DIM) return ctx.mustBe(`in the range [1, ${VECTOR_MAX_DIM}]`);
13
+ return true;
14
+ })
15
+ }];
16
+ function createPgvectorCodecRegistry() {
17
+ const registry = createCodecRegistry();
18
+ for (const def of Object.values(codecDefinitions)) registry.register(def.codec);
19
+ return registry;
20
+ }
21
+ const pgvectorRuntimeDescriptor = {
22
+ kind: "extension",
23
+ id: pgvectorPackMeta.id,
24
+ version: pgvectorPackMeta.version,
25
+ familyId: "sql",
26
+ targetId: "postgres",
27
+ codecs: createPgvectorCodecRegistry,
28
+ queryOperations: () => pgvectorQueryOperations,
29
+ parameterizedCodecs: () => parameterizedCodecDescriptors,
30
+ create() {
31
+ return {
32
+ familyId: "sql",
33
+ targetId: "postgres"
34
+ };
35
+ }
36
+ };
37
+ var runtime_default = pgvectorRuntimeDescriptor;
38
+
39
+ //#endregion
40
+ export { runtime_default as default };
41
+ //# sourceMappingURL=runtime.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.mjs","names":["arktype","pgvectorRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'>"],"sources":["../src/exports/runtime.ts"],"sourcesContent":["import { createCodecRegistry } from '@prisma-next/sql-relational-core/ast';\nimport type {\n RuntimeParameterizedCodecDescriptor,\n SqlRuntimeExtensionDescriptor,\n} from '@prisma-next/sql-runtime';\nimport { type as arktype } from 'arktype';\nimport { codecDefinitions } from '../core/codecs';\nimport { VECTOR_CODEC_ID, VECTOR_MAX_DIM } from '../core/constants';\nimport { pgvectorPackMeta, pgvectorQueryOperations } from '../core/descriptor-meta';\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});\n\nconst parameterizedCodecDescriptors = [\n {\n codecId: VECTOR_CODEC_ID,\n paramsSchema: vectorParamsSchema,\n },\n] as const satisfies ReadonlyArray<\n RuntimeParameterizedCodecDescriptor<{ readonly length: number }>\n>;\n\nfunction createPgvectorCodecRegistry() {\n const registry = createCodecRegistry();\n for (const def of Object.values(codecDefinitions)) {\n registry.register(def.codec);\n }\n return registry;\n}\n\nconst pgvectorRuntimeDescriptor: SqlRuntimeExtensionDescriptor<'postgres'> = {\n kind: 'extension' as const,\n id: pgvectorPackMeta.id,\n version: pgvectorPackMeta.version,\n familyId: 'sql' as const,\n targetId: 'postgres' as const,\n codecs: createPgvectorCodecRegistry,\n queryOperations: () => pgvectorQueryOperations,\n parameterizedCodecs: () => parameterizedCodecDescriptors,\n create() {\n return {\n familyId: 'sql' as const,\n targetId: 'postgres' as const,\n };\n },\n};\n\nexport default pgvectorRuntimeDescriptor;\n"],"mappings":";;;;;;AAuBA,MAAM,gCAAgC,CACpC;CACE,SAAS;CACT,cAhBuBA,KAAQ,EACjC,QAAQ,UACT,CAAC,CAAC,QAAQ,QAAQ,QAAQ;EACzB,MAAM,EAAE,WAAW;AACnB,MAAI,CAAC,OAAO,UAAU,OAAO,CAC3B,QAAO,IAAI,OAAO,aAAa;AAEjC,MAAI,SAAS,KAAK,SAAS,eACzB,QAAO,IAAI,OAAO,oBAAoB,eAAe,GAAG;AAE1D,SAAO;GACP;CAMC,CACF;AAID,SAAS,8BAA8B;CACrC,MAAM,WAAW,qBAAqB;AACtC,MAAK,MAAM,OAAO,OAAO,OAAO,iBAAiB,CAC/C,UAAS,SAAS,IAAI,MAAM;AAE9B,QAAO;;AAGT,MAAMC,4BAAuE;CAC3E,MAAM;CACN,IAAI,iBAAiB;CACrB,SAAS,iBAAiB;CAC1B,UAAU;CACV,UAAU;CACV,QAAQ;CACR,uBAAuB;CACvB,2BAA2B;CAC3B,SAAS;AACP,SAAO;GACL,UAAU;GACV,UAAU;GACX;;CAEJ;AAED,sBAAe"}
package/package.json CHANGED
@@ -1,65 +1,51 @@
1
1
  {
2
2
  "name": "@prisma-next/extension-pgvector",
3
- "version": "0.3.0-pr.99.6",
3
+ "version": "0.4.0-dev.2",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "dependencies": {
7
7
  "arktype": "^2.0.0",
8
- "@prisma-next/cli": "0.3.0-pr.99.6",
9
- "@prisma-next/contract": "0.3.0-pr.99.6",
10
- "@prisma-next/contract-authoring": "0.3.0-pr.99.6",
11
- "@prisma-next/core-control-plane": "0.3.0-pr.99.6",
12
- "@prisma-next/family-sql": "0.3.0-pr.99.6",
13
- "@prisma-next/sql-operations": "0.3.0-pr.99.6",
14
- "@prisma-next/sql-relational-core": "0.3.0-pr.99.6",
15
- "@prisma-next/sql-runtime": "0.3.0-pr.99.6",
16
- "@prisma-next/sql-schema-ir": "0.3.0-pr.99.6"
8
+ "@prisma-next/contract": "0.4.0-dev.2",
9
+ "@prisma-next/family-sql": "0.4.0-dev.2",
10
+ "@prisma-next/sql-operations": "0.4.0-dev.2",
11
+ "@prisma-next/contract-authoring": "0.4.0-dev.2",
12
+ "@prisma-next/sql-schema-ir": "0.4.0-dev.2",
13
+ "@prisma-next/sql-relational-core": "0.4.0-dev.2",
14
+ "@prisma-next/framework-components": "0.4.0-dev.2",
15
+ "@prisma-next/sql-runtime": "0.4.0-dev.2"
17
16
  },
18
17
  "devDependencies": {
19
- "tsup": "8.5.1",
18
+ "tsdown": "0.18.4",
20
19
  "typescript": "5.9.3",
21
- "vitest": "4.0.16",
22
- "@prisma-next/adapter-postgres": "0.3.0-pr.99.6",
23
- "@prisma-next/operations": "0.3.0-pr.99.6",
24
- "@prisma-next/sql-contract": "0.3.0-pr.99.6",
25
- "@prisma-next/sql-contract-ts": "0.3.0-pr.99.6",
26
- "@prisma-next/sql-lane": "0.3.0-pr.99.6",
20
+ "vitest": "4.0.17",
21
+ "@prisma-next/adapter-postgres": "0.4.0-dev.2",
22
+ "@prisma-next/sql-contract": "0.4.0-dev.2",
23
+ "@prisma-next/operations": "0.4.0-dev.2",
27
24
  "@prisma-next/test-utils": "0.0.1",
28
- "@prisma-next/tsconfig": "0.0.0"
25
+ "@prisma-next/sql-contract-ts": "0.4.0-dev.2",
26
+ "@prisma-next/tsconfig": "0.0.0",
27
+ "@prisma-next/tsdown": "0.0.0"
29
28
  },
30
29
  "files": [
31
30
  "dist",
32
31
  "src"
33
32
  ],
34
33
  "exports": {
35
- "./package.json": "./package.json",
36
- "./control": {
37
- "types": "./dist/exports/control.d.ts",
38
- "import": "./dist/exports/control.js"
39
- },
40
- "./runtime": {
41
- "types": "./dist/exports/runtime.d.ts",
42
- "import": "./dist/exports/runtime.js"
43
- },
44
- "./pack": {
45
- "types": "./dist/exports/pack.d.ts",
46
- "import": "./dist/exports/pack.js"
47
- },
48
- "./codec-types": {
49
- "types": "./dist/exports/codec-types.d.ts",
50
- "import": "./dist/exports/codec-types.js"
51
- },
52
- "./column-types": {
53
- "types": "./dist/exports/column-types.d.ts",
54
- "import": "./dist/exports/column-types.js"
55
- },
56
- "./operation-types": {
57
- "types": "./dist/exports/operation-types.d.ts",
58
- "import": "./dist/exports/operation-types.js"
59
- }
34
+ "./codec-types": "./dist/codec-types.mjs",
35
+ "./column-types": "./dist/column-types.mjs",
36
+ "./control": "./dist/control.mjs",
37
+ "./operation-types": "./dist/operation-types.mjs",
38
+ "./pack": "./dist/pack.mjs",
39
+ "./runtime": "./dist/runtime.mjs",
40
+ "./package.json": "./package.json"
41
+ },
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "https://github.com/prisma/prisma-next.git",
45
+ "directory": "packages/3-extensions/pgvector"
60
46
  },
61
47
  "scripts": {
62
- "build": "tsup --config tsup.config.ts && tsc --project tsconfig.build.json",
48
+ "build": "tsdown",
63
49
  "test": "vitest run",
64
50
  "test:coverage": "vitest run --coverage",
65
51
  "typecheck": "tsc --project tsconfig.json --noEmit",
@@ -0,0 +1,20 @@
1
+ import type { AuthoringTypeNamespace } from '@prisma-next/framework-components/authoring';
2
+ import { VECTOR_MAX_DIM } from './constants';
3
+
4
+ export const pgvectorAuthoringTypes = {
5
+ pgvector: {
6
+ Vector: {
7
+ kind: 'typeConstructor',
8
+ args: [
9
+ { kind: 'number', name: 'length', integer: true, minimum: 1, maximum: VECTOR_MAX_DIM },
10
+ ],
11
+ output: {
12
+ codecId: 'pg/vector@1',
13
+ nativeType: 'vector',
14
+ typeParams: {
15
+ length: { kind: 'arg', index: 0 },
16
+ },
17
+ },
18
+ },
19
+ },
20
+ } as const satisfies AuthoringTypeNamespace;
@@ -7,9 +7,20 @@
7
7
 
8
8
  import { codec, defineCodecs } from '@prisma-next/sql-relational-core/ast';
9
9
 
10
- const pgVectorCodec = codec<'pg/vector@1', string, number[]>({
10
+ const pgVectorCodec = codec({
11
11
  typeId: 'pg/vector@1',
12
12
  targetTypes: ['vector'],
13
+ traits: ['equality'],
14
+ renderOutputType: (typeParams) => {
15
+ const length = typeParams['length'];
16
+ if (length === undefined) return undefined;
17
+ if (typeof length !== 'number' || !Number.isFinite(length) || !Number.isInteger(length)) {
18
+ throw new Error(
19
+ `renderOutputType: expected positive integer "length" in typeParams for Vector, got ${String(length)}`,
20
+ );
21
+ }
22
+ return `Vector<${length}>`;
23
+ },
13
24
  encode: (value: number[]): string => {
14
25
  // Validate that value is an array of numbers
15
26
  if (!Array.isArray(value)) {
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Codec ID for pgvector's vector type.
3
+ */
4
+ export const VECTOR_CODEC_ID = 'pg/vector@1' as const;
5
+
6
+ /**
7
+ * Maximum dimension for pgvector vectors (VECTOR_MAX_DIM from pgvector).
8
+ */
9
+ export const VECTOR_MAX_DIM = 16000;