@prisma-next/sql-relational-core 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +123 -0
  2. package/dist/chunk-2F7DSEOU.js +8 -0
  3. package/dist/chunk-2F7DSEOU.js.map +1 -0
  4. package/dist/chunk-7FMQVMSM.js +128 -0
  5. package/dist/chunk-7FMQVMSM.js.map +1 -0
  6. package/dist/chunk-7I3EMQID.js +16 -0
  7. package/dist/chunk-7I3EMQID.js.map +1 -0
  8. package/dist/chunk-ENOLRQZS.js +320 -0
  9. package/dist/chunk-ENOLRQZS.js.map +1 -0
  10. package/dist/chunk-FMVAOBWJ.js +151 -0
  11. package/dist/chunk-FMVAOBWJ.js.map +1 -0
  12. package/dist/chunk-G52ENULI.js +1 -0
  13. package/dist/chunk-G52ENULI.js.map +1 -0
  14. package/dist/chunk-ILC64YWE.js +9 -0
  15. package/dist/chunk-ILC64YWE.js.map +1 -0
  16. package/dist/chunk-U7AXAUJA.js +1 -0
  17. package/dist/chunk-U7AXAUJA.js.map +1 -0
  18. package/dist/chunk-UVFWELV2.js +1 -0
  19. package/dist/chunk-UVFWELV2.js.map +1 -0
  20. package/dist/exports/ast.d.ts +119 -0
  21. package/dist/exports/ast.js +46 -0
  22. package/dist/exports/ast.js.map +1 -0
  23. package/dist/exports/errors.d.ts +1 -0
  24. package/dist/exports/errors.js +9 -0
  25. package/dist/exports/errors.js.map +1 -0
  26. package/dist/exports/operations-registry.d.ts +13 -0
  27. package/dist/exports/operations-registry.js +8 -0
  28. package/dist/exports/operations-registry.js.map +1 -0
  29. package/dist/exports/param.d.ts +14 -0
  30. package/dist/exports/param.js +7 -0
  31. package/dist/exports/param.js.map +1 -0
  32. package/dist/exports/plan.d.ts +4 -0
  33. package/dist/exports/plan.js +2 -0
  34. package/dist/exports/plan.js.map +1 -0
  35. package/dist/exports/query-lane-context.d.ts +4 -0
  36. package/dist/exports/query-lane-context.js +2 -0
  37. package/dist/exports/query-lane-context.js.map +1 -0
  38. package/dist/exports/schema.d.ts +63 -0
  39. package/dist/exports/schema.js +12 -0
  40. package/dist/exports/schema.js.map +1 -0
  41. package/dist/exports/types.d.ts +306 -0
  42. package/dist/exports/types.js +7 -0
  43. package/dist/exports/types.js.map +1 -0
  44. package/dist/index.d.ts +13 -0
  45. package/dist/index.js +74 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/plan-D6dOf1wQ.d.ts +135 -0
  48. package/dist/query-lane-context-BhOMmb_K.d.ts +158 -0
  49. package/package.json +72 -0
@@ -0,0 +1,158 @@
1
+ import { OperationRegistry } from '@prisma-next/operations';
2
+ import { SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';
3
+ import { O } from 'ts-toolbelt';
4
+
5
+ /**
6
+ * Codec metadata for database-specific type information.
7
+ * Used for schema introspection and verification.
8
+ */
9
+ interface CodecMeta {
10
+ readonly db?: {
11
+ readonly sql?: {
12
+ readonly postgres?: {
13
+ readonly nativeType: string;
14
+ };
15
+ };
16
+ };
17
+ }
18
+ /**
19
+ * Codec interface for encoding/decoding values between wire format and JavaScript types.
20
+ *
21
+ * Codecs are pure, synchronous functions with no side effects or IO.
22
+ * They provide deterministic conversion between database wire types and JS values.
23
+ */
24
+ interface Codec<Id extends string = string, TWire = unknown, TJs = unknown> {
25
+ /**
26
+ * Namespaced codec identifier in format 'namespace/name@version'
27
+ * Examples: 'pg/text@1', 'pg/uuid@1', 'pg/timestamptz@1'
28
+ */
29
+ readonly id: Id;
30
+ /**
31
+ * Contract scalar type IDs that this codec can handle.
32
+ * Examples: ['text'], ['int4', 'float8'], ['timestamp', 'timestamptz']
33
+ */
34
+ readonly targetTypes: readonly string[];
35
+ /**
36
+ * Optional metadata for database-specific type information.
37
+ * Used for schema introspection and verification.
38
+ */
39
+ readonly meta?: CodecMeta;
40
+ /**
41
+ * Decode a wire value (from database) to JavaScript type.
42
+ * Must be synchronous and pure (no side effects).
43
+ */
44
+ decode(wire: TWire): TJs;
45
+ /**
46
+ * Encode a JavaScript value to wire format (for database).
47
+ * Optional - if not provided, values pass through unchanged.
48
+ * Must be synchronous and pure (no side effects).
49
+ */
50
+ encode?(value: TJs): TWire;
51
+ }
52
+ /**
53
+ * Registry interface for codecs organized by ID and by contract scalar type.
54
+ *
55
+ * The registry allows looking up codecs by their namespaced ID or by the
56
+ * contract scalar types they handle. Multiple codecs may handle the same
57
+ * scalar type; ordering in byScalar reflects preference (adapter first,
58
+ * then packs, then app overrides).
59
+ */
60
+ interface CodecRegistry {
61
+ get(id: string): Codec<string> | undefined;
62
+ has(id: string): boolean;
63
+ getByScalar(scalar: string): readonly Codec<string>[];
64
+ getDefaultCodec(scalar: string): Codec<string> | undefined;
65
+ register(codec: Codec<string>): void;
66
+ [Symbol.iterator](): Iterator<Codec<string>>;
67
+ values(): IterableIterator<Codec<string>>;
68
+ }
69
+ /**
70
+ * Codec factory - creates a codec with typeId and encode/decode functions.
71
+ */
72
+ declare function codec<Id extends string, TWire, TJs>(config: {
73
+ typeId: Id;
74
+ targetTypes: readonly string[];
75
+ encode: (value: TJs) => TWire;
76
+ decode: (wire: TWire) => TJs;
77
+ meta?: CodecMeta;
78
+ }): Codec<Id, TWire, TJs>;
79
+ /**
80
+ * Type helpers to extract codec types.
81
+ */
82
+ type CodecId<T> = T extends Codec<infer Id, unknown, unknown> ? Id : T extends {
83
+ readonly id: infer Id;
84
+ } ? Id : never;
85
+ type CodecInput<T> = T extends Codec<string, unknown, infer JsT> ? JsT : never;
86
+ type CodecOutput<T> = T extends Codec<string, unknown, infer JsT> ? JsT : never;
87
+ /**
88
+ * Type helper to extract codec types from builder instance.
89
+ */
90
+ type ExtractCodecTypes<ScalarNames extends {
91
+ readonly [K in keyof ScalarNames]: Codec<string>;
92
+ } = Record<never, never>> = {
93
+ readonly [K in keyof ScalarNames as ScalarNames[K] extends Codec<infer Id, unknown, unknown> ? Id : never]: {
94
+ readonly input: CodecInput<ScalarNames[K]>;
95
+ readonly output: CodecOutput<ScalarNames[K]>;
96
+ };
97
+ };
98
+ /**
99
+ * Type helper to extract data type IDs from builder instance.
100
+ * Uses ExtractCodecTypes which preserves literal types as keys.
101
+ * Since ExtractCodecTypes<Record<K, ScalarNames[K]>> has exactly one key (the Id),
102
+ * we extract it by creating a mapped type that uses the Id as both key and value,
103
+ * then extract the value type. This preserves literal types.
104
+ */
105
+ type ExtractDataTypes<ScalarNames extends {
106
+ readonly [K in keyof ScalarNames]: Codec<string>;
107
+ }> = {
108
+ readonly [K in keyof ScalarNames]: {
109
+ readonly [Id in keyof ExtractCodecTypes<Record<K, ScalarNames[K]>>]: Id;
110
+ }[keyof ExtractCodecTypes<Record<K, ScalarNames[K]>>];
111
+ };
112
+ /**
113
+ * Builder interface for declaring codecs.
114
+ */
115
+ interface CodecDefBuilder<ScalarNames extends {
116
+ readonly [K in keyof ScalarNames]: Codec<string>;
117
+ } = Record<never, never>> {
118
+ readonly CodecTypes: ExtractCodecTypes<ScalarNames>;
119
+ add<ScalarName extends string, CodecImpl extends Codec<string>>(scalarName: ScalarName, codecImpl: CodecImpl): CodecDefBuilder<O.Overwrite<ScalarNames, Record<ScalarName, CodecImpl>> & Record<ScalarName, CodecImpl>>;
120
+ readonly codecDefinitions: {
121
+ readonly [K in keyof ScalarNames]: {
122
+ readonly typeId: ScalarNames[K] extends Codec<infer Id extends string, unknown, unknown> ? Id : never;
123
+ readonly scalar: K;
124
+ readonly codec: ScalarNames[K];
125
+ readonly input: CodecInput<ScalarNames[K]>;
126
+ readonly output: CodecOutput<ScalarNames[K]>;
127
+ readonly jsType: CodecOutput<ScalarNames[K]>;
128
+ };
129
+ };
130
+ readonly dataTypes: {
131
+ readonly [K in keyof ScalarNames]: {
132
+ readonly [Id in keyof ExtractCodecTypes<Record<K, ScalarNames[K]>>]: Id;
133
+ }[keyof ExtractCodecTypes<Record<K, ScalarNames[K]>>];
134
+ };
135
+ }
136
+ /**
137
+ * Create a new codec registry.
138
+ */
139
+ declare function createCodecRegistry(): CodecRegistry;
140
+ /**
141
+ * Create a new codec definition builder.
142
+ */
143
+ declare function defineCodecs(): CodecDefBuilder<Record<never, never>>;
144
+
145
+ /**
146
+ * Minimal context interface for SQL query lanes.
147
+ *
148
+ * Lanes only need contract, operations, and codecs to build typed ASTs and attach
149
+ * operation builders. This interface explicitly excludes runtime concerns like
150
+ * adapters, connection management, and transaction state.
151
+ */
152
+ interface QueryLaneContext<TContract extends SqlContract<SqlStorage> = SqlContract<SqlStorage>> {
153
+ readonly contract: TContract;
154
+ readonly operations: OperationRegistry;
155
+ readonly codecs: CodecRegistry;
156
+ }
157
+
158
+ export { type CodecMeta as C, type ExtractCodecTypes as E, type QueryLaneContext as Q, type Codec as a, type CodecRegistry as b, codec as c, type CodecId as d, type CodecInput as e, type CodecOutput as f, type ExtractDataTypes as g, type CodecDefBuilder as h, createCodecRegistry as i, defineCodecs as j };
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@prisma-next/sql-relational-core",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "sideEffects": false,
6
+ "description": "Schema and column builders, operation attachment, and AST types for Prisma Next",
7
+ "dependencies": {
8
+ "ts-toolbelt": "^9.6.0",
9
+ "@prisma-next/contract": "0.0.1",
10
+ "@prisma-next/plan": "0.0.1",
11
+ "@prisma-next/operations": "0.0.1",
12
+ "@prisma-next/sql-operations": "0.0.1",
13
+ "@prisma-next/sql-contract": "0.0.1"
14
+ },
15
+ "devDependencies": {
16
+ "tsup": "^8.3.0",
17
+ "typescript": "^5.9.3",
18
+ "vite-tsconfig-paths": "^5.1.4",
19
+ "vitest": "^2.1.1",
20
+ "@prisma-next/sql-contract-ts": "0.0.1",
21
+ "@prisma-next/test-utils": "0.0.1"
22
+ },
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "import": "./dist/index.js"
30
+ },
31
+ "./schema": {
32
+ "types": "./dist/exports/schema.d.ts",
33
+ "import": "./dist/exports/schema.js"
34
+ },
35
+ "./param": {
36
+ "types": "./dist/exports/param.d.ts",
37
+ "import": "./dist/exports/param.js"
38
+ },
39
+ "./types": {
40
+ "types": "./dist/exports/types.d.ts",
41
+ "import": "./dist/exports/types.js"
42
+ },
43
+ "./operations-registry": {
44
+ "types": "./dist/exports/operations-registry.d.ts",
45
+ "import": "./dist/exports/operations-registry.js"
46
+ },
47
+ "./errors": {
48
+ "types": "./dist/exports/errors.d.ts",
49
+ "import": "./dist/exports/errors.js"
50
+ },
51
+ "./ast": {
52
+ "types": "./dist/exports/ast.d.ts",
53
+ "import": "./dist/exports/ast.js"
54
+ },
55
+ "./plan": {
56
+ "types": "./dist/exports/plan.d.ts",
57
+ "import": "./dist/exports/plan.js"
58
+ },
59
+ "./query-lane-context": {
60
+ "types": "./dist/exports/query-lane-context.d.ts",
61
+ "import": "./dist/exports/query-lane-context.js"
62
+ }
63
+ },
64
+ "scripts": {
65
+ "build": "tsup --config tsup.config.ts",
66
+ "test": "vitest run",
67
+ "test:coverage": "vitest run --coverage",
68
+ "typecheck": "tsc --project tsconfig.json --noEmit",
69
+ "lint": "biome check . --config-path ../../../../biome.json --error-on-warnings",
70
+ "clean": "node ../../../../scripts/clean.mjs"
71
+ }
72
+ }