@prisma-next/sql-relational-core 0.3.0-dev.14 → 0.3.0-dev.147

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 (163) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +19 -5
  3. package/dist/codec-types-DcEITed4.d.mts +144 -0
  4. package/dist/codec-types-DcEITed4.d.mts.map +1 -0
  5. package/dist/errors-Cs52upp3.d.mts +8 -0
  6. package/dist/errors-Cs52upp3.d.mts.map +1 -0
  7. package/dist/errors-D3xmG4h-.mjs +35 -0
  8. package/dist/errors-D3xmG4h-.mjs.map +1 -0
  9. package/dist/exports/ast.d.mts +158 -0
  10. package/dist/exports/ast.d.mts.map +1 -0
  11. package/dist/exports/ast.mjs +1358 -0
  12. package/dist/exports/ast.mjs.map +1 -0
  13. package/dist/exports/errors.d.mts +5 -0
  14. package/dist/exports/errors.mjs +3 -0
  15. package/dist/exports/plan.d.mts +2 -0
  16. package/dist/exports/plan.mjs +17 -0
  17. package/dist/exports/plan.mjs.map +1 -0
  18. package/dist/exports/query-lane-context.d.mts +3 -0
  19. package/dist/exports/query-lane-context.mjs +1 -0
  20. package/dist/exports/types.d.mts +4 -0
  21. package/dist/exports/types.mjs +1 -0
  22. package/dist/index.d.mts +11 -0
  23. package/dist/index.mjs +7 -0
  24. package/dist/plan-5qUWdlJM.d.mts +28 -0
  25. package/dist/plan-5qUWdlJM.d.mts.map +1 -0
  26. package/dist/query-lane-context-UlR8vOkd.d.mts +89 -0
  27. package/dist/query-lane-context-UlR8vOkd.d.mts.map +1 -0
  28. package/dist/types-CLCtwVWx.d.mts +485 -0
  29. package/dist/types-CLCtwVWx.d.mts.map +1 -0
  30. package/dist/types-V1qiC5DO.d.mts +200 -0
  31. package/dist/types-V1qiC5DO.d.mts.map +1 -0
  32. package/package.json +32 -54
  33. package/src/ast/adapter-types.ts +11 -0
  34. package/src/ast/codec-types.ts +101 -53
  35. package/src/ast/driver-types.ts +20 -3
  36. package/src/ast/sql-codecs.ts +142 -0
  37. package/src/ast/types.ts +1681 -77
  38. package/src/errors.ts +47 -1
  39. package/src/exports/ast.ts +1 -8
  40. package/src/index.ts +0 -3
  41. package/src/plan.ts +4 -4
  42. package/src/query-lane-context.ts +81 -6
  43. package/src/types.ts +102 -354
  44. package/dist/ast/adapter-types.d.ts +0 -28
  45. package/dist/ast/adapter-types.d.ts.map +0 -1
  46. package/dist/ast/codec-types.d.ts +0 -141
  47. package/dist/ast/codec-types.d.ts.map +0 -1
  48. package/dist/ast/common.d.ts +0 -7
  49. package/dist/ast/common.d.ts.map +0 -1
  50. package/dist/ast/delete.d.ts +0 -8
  51. package/dist/ast/delete.d.ts.map +0 -1
  52. package/dist/ast/driver-types.d.ts +0 -20
  53. package/dist/ast/driver-types.d.ts.map +0 -1
  54. package/dist/ast/insert.d.ts +0 -8
  55. package/dist/ast/insert.d.ts.map +0 -1
  56. package/dist/ast/join.d.ts +0 -6
  57. package/dist/ast/join.d.ts.map +0 -1
  58. package/dist/ast/order.d.ts +0 -6
  59. package/dist/ast/order.d.ts.map +0 -1
  60. package/dist/ast/predicate.d.ts +0 -4
  61. package/dist/ast/predicate.d.ts.map +0 -1
  62. package/dist/ast/select.d.ts +0 -18
  63. package/dist/ast/select.d.ts.map +0 -1
  64. package/dist/ast/types.d.ts +0 -118
  65. package/dist/ast/types.d.ts.map +0 -1
  66. package/dist/ast/update.d.ts +0 -9
  67. package/dist/ast/update.d.ts.map +0 -1
  68. package/dist/ast/util.d.ts +0 -2
  69. package/dist/ast/util.d.ts.map +0 -1
  70. package/dist/chunk-2F7DSEOU.js +0 -8
  71. package/dist/chunk-2F7DSEOU.js.map +0 -1
  72. package/dist/chunk-36WJWNHT.js +0 -1
  73. package/dist/chunk-36WJWNHT.js.map +0 -1
  74. package/dist/chunk-5N34PNVZ.js +0 -62
  75. package/dist/chunk-5N34PNVZ.js.map +0 -1
  76. package/dist/chunk-7I3EMQID.js +0 -16
  77. package/dist/chunk-7I3EMQID.js.map +0 -1
  78. package/dist/chunk-D4JLPIWO.js +0 -13
  79. package/dist/chunk-D4JLPIWO.js.map +0 -1
  80. package/dist/chunk-G52ENULI.js +0 -1
  81. package/dist/chunk-G52ENULI.js.map +0 -1
  82. package/dist/chunk-J6O2HVBM.js +0 -320
  83. package/dist/chunk-J6O2HVBM.js.map +0 -1
  84. package/dist/chunk-KYSP7L5C.js +0 -16
  85. package/dist/chunk-KYSP7L5C.js.map +0 -1
  86. package/dist/chunk-M23L3JHG.js +0 -159
  87. package/dist/chunk-M23L3JHG.js.map +0 -1
  88. package/dist/chunk-U7AXAUJA.js +0 -1
  89. package/dist/chunk-U7AXAUJA.js.map +0 -1
  90. package/dist/chunk-U7IAFPVU.js +0 -152
  91. package/dist/chunk-U7IAFPVU.js.map +0 -1
  92. package/dist/errors.d.ts +0 -2
  93. package/dist/errors.d.ts.map +0 -1
  94. package/dist/exports/ast.d.ts +0 -14
  95. package/dist/exports/ast.d.ts.map +0 -1
  96. package/dist/exports/ast.js +0 -46
  97. package/dist/exports/ast.js.map +0 -1
  98. package/dist/exports/errors.d.ts +0 -2
  99. package/dist/exports/errors.d.ts.map +0 -1
  100. package/dist/exports/errors.js +0 -9
  101. package/dist/exports/errors.js.map +0 -1
  102. package/dist/exports/guards.d.ts +0 -2
  103. package/dist/exports/guards.d.ts.map +0 -1
  104. package/dist/exports/guards.js +0 -21
  105. package/dist/exports/guards.js.map +0 -1
  106. package/dist/exports/operations-registry.d.ts +0 -2
  107. package/dist/exports/operations-registry.d.ts.map +0 -1
  108. package/dist/exports/operations-registry.js +0 -9
  109. package/dist/exports/operations-registry.js.map +0 -1
  110. package/dist/exports/param.d.ts +0 -3
  111. package/dist/exports/param.d.ts.map +0 -1
  112. package/dist/exports/param.js +0 -7
  113. package/dist/exports/param.js.map +0 -1
  114. package/dist/exports/plan.d.ts +0 -2
  115. package/dist/exports/plan.d.ts.map +0 -1
  116. package/dist/exports/plan.js +0 -7
  117. package/dist/exports/plan.js.map +0 -1
  118. package/dist/exports/query-lane-context.d.ts +0 -2
  119. package/dist/exports/query-lane-context.d.ts.map +0 -1
  120. package/dist/exports/query-lane-context.js +0 -2
  121. package/dist/exports/query-lane-context.js.map +0 -1
  122. package/dist/exports/schema.d.ts +0 -3
  123. package/dist/exports/schema.d.ts.map +0 -1
  124. package/dist/exports/schema.js +0 -14
  125. package/dist/exports/schema.js.map +0 -1
  126. package/dist/exports/types.d.ts +0 -2
  127. package/dist/exports/types.d.ts.map +0 -1
  128. package/dist/exports/types.js +0 -10
  129. package/dist/exports/types.js.map +0 -1
  130. package/dist/index.d.ts +0 -9
  131. package/dist/index.d.ts.map +0 -1
  132. package/dist/index.js +0 -81
  133. package/dist/index.js.map +0 -1
  134. package/dist/operations-registry.d.ts +0 -5
  135. package/dist/operations-registry.d.ts.map +0 -1
  136. package/dist/param.d.ts +0 -4
  137. package/dist/param.d.ts.map +0 -1
  138. package/dist/plan.d.ts +0 -23
  139. package/dist/plan.d.ts.map +0 -1
  140. package/dist/query-lane-context.d.ts +0 -16
  141. package/dist/query-lane-context.d.ts.map +0 -1
  142. package/dist/schema.d.ts +0 -63
  143. package/dist/schema.d.ts.map +0 -1
  144. package/dist/types.d.ts +0 -332
  145. package/dist/types.d.ts.map +0 -1
  146. package/dist/utils/guards.d.ts +0 -55
  147. package/dist/utils/guards.d.ts.map +0 -1
  148. package/src/ast/common.ts +0 -36
  149. package/src/ast/delete.ts +0 -17
  150. package/src/ast/insert.ts +0 -17
  151. package/src/ast/join.ts +0 -54
  152. package/src/ast/order.ts +0 -11
  153. package/src/ast/predicate.ts +0 -30
  154. package/src/ast/select.ts +0 -39
  155. package/src/ast/update.ts +0 -19
  156. package/src/exports/guards.ts +0 -10
  157. package/src/exports/operations-registry.ts +0 -1
  158. package/src/exports/param.ts +0 -2
  159. package/src/exports/schema.ts +0 -6
  160. package/src/operations-registry.ts +0 -237
  161. package/src/param.ts +0 -15
  162. package/src/schema.ts +0 -373
  163. package/src/utils/guards.ts +0 -123
@@ -0,0 +1,142 @@
1
+ import { type as arktype } from 'arktype';
2
+ import { codec, defineCodecs } from './codec-types';
3
+
4
+ export const SQL_CHAR_CODEC_ID = 'sql/char@1' as const;
5
+ export const SQL_VARCHAR_CODEC_ID = 'sql/varchar@1' as const;
6
+ export const SQL_INT_CODEC_ID = 'sql/int@1' as const;
7
+ export const SQL_FLOAT_CODEC_ID = 'sql/float@1' as const;
8
+ export const SQL_TEXT_CODEC_ID = 'sql/text@1' as const;
9
+ export const SQL_TIMESTAMP_CODEC_ID = 'sql/timestamp@1' as const;
10
+
11
+ const lengthParamsSchema = arktype({
12
+ length: 'number.integer > 0',
13
+ });
14
+
15
+ const precisionParamsSchema = arktype({
16
+ 'precision?': 'number.integer >= 0 & number.integer <= 6',
17
+ });
18
+
19
+ type LengthTypeHelper = {
20
+ readonly kind: 'fixed' | 'variable';
21
+ readonly maxLength: number;
22
+ };
23
+
24
+ function createLengthTypeHelper(
25
+ kind: LengthTypeHelper['kind'],
26
+ ): (params: Record<string, unknown>) => LengthTypeHelper {
27
+ return (params) => ({
28
+ kind,
29
+ maxLength: params['length'] as number,
30
+ });
31
+ }
32
+
33
+ const sqlCharCodec = codec<
34
+ typeof SQL_CHAR_CODEC_ID,
35
+ readonly ['equality', 'order', 'textual'],
36
+ string,
37
+ string
38
+ >({
39
+ typeId: SQL_CHAR_CODEC_ID,
40
+ targetTypes: ['char'],
41
+ traits: ['equality', 'order', 'textual'],
42
+ encode: (value: string): string => value,
43
+ decode: (wire: string): string => wire.trimEnd(),
44
+ paramsSchema: lengthParamsSchema,
45
+ init: createLengthTypeHelper('fixed'),
46
+ renderOutputType: (typeParams) => {
47
+ const length = typeParams['length'];
48
+ if (length === undefined) return undefined;
49
+ if (typeof length !== 'number' || !Number.isFinite(length) || !Number.isInteger(length)) {
50
+ throw new Error(
51
+ `renderOutputType: expected integer "length" in typeParams for Char, got ${String(length)}`,
52
+ );
53
+ }
54
+ return `Char<${length}>`;
55
+ },
56
+ });
57
+
58
+ const sqlVarcharCodec = codec<
59
+ typeof SQL_VARCHAR_CODEC_ID,
60
+ readonly ['equality', 'order', 'textual'],
61
+ string,
62
+ string
63
+ >({
64
+ typeId: SQL_VARCHAR_CODEC_ID,
65
+ targetTypes: ['varchar'],
66
+ traits: ['equality', 'order', 'textual'],
67
+ encode: (value: string): string => value,
68
+ decode: (wire: string): string => wire,
69
+ paramsSchema: lengthParamsSchema,
70
+ init: createLengthTypeHelper('variable'),
71
+ renderOutputType: (typeParams) => {
72
+ const length = typeParams['length'];
73
+ if (length === undefined) return undefined;
74
+ if (typeof length !== 'number' || !Number.isFinite(length) || !Number.isInteger(length)) {
75
+ throw new Error(
76
+ `renderOutputType: expected integer "length" in typeParams for Varchar, got ${String(length)}`,
77
+ );
78
+ }
79
+ return `Varchar<${length}>`;
80
+ },
81
+ });
82
+
83
+ const sqlIntCodec = codec({
84
+ typeId: SQL_INT_CODEC_ID,
85
+ targetTypes: ['int'],
86
+ traits: ['equality', 'order', 'numeric'],
87
+ encode: (value: number): number => value,
88
+ decode: (wire: number): number => wire,
89
+ });
90
+
91
+ const sqlFloatCodec = codec({
92
+ typeId: SQL_FLOAT_CODEC_ID,
93
+ targetTypes: ['float'],
94
+ traits: ['equality', 'order', 'numeric'],
95
+ encode: (value: number): number => value,
96
+ decode: (wire: number): number => wire,
97
+ });
98
+
99
+ const sqlTextCodec = codec({
100
+ typeId: SQL_TEXT_CODEC_ID,
101
+ targetTypes: ['text'],
102
+ traits: ['equality', 'order', 'textual'],
103
+ encode: (value: string): string => value,
104
+ decode: (wire: string): string => wire,
105
+ });
106
+
107
+ const sqlTimestampCodec = codec({
108
+ typeId: SQL_TIMESTAMP_CODEC_ID,
109
+ targetTypes: ['timestamp'],
110
+ traits: ['equality', 'order'],
111
+ encode: (value: string | Date): string => (value instanceof Date ? value.toISOString() : value),
112
+ decode: (wire: string | Date): string => (wire instanceof Date ? wire.toISOString() : wire),
113
+ paramsSchema: precisionParamsSchema,
114
+ renderOutputType: (typeParams) => {
115
+ const precision = typeParams['precision'];
116
+ if (precision === undefined) {
117
+ return 'Timestamp';
118
+ }
119
+ if (
120
+ typeof precision !== 'number' ||
121
+ !Number.isFinite(precision) ||
122
+ !Number.isInteger(precision)
123
+ ) {
124
+ throw new Error(
125
+ `renderOutputType: expected integer "precision" in typeParams for Timestamp, got ${String(precision)}`,
126
+ );
127
+ }
128
+ return `Timestamp<${precision}>`;
129
+ },
130
+ });
131
+
132
+ const codecs = defineCodecs()
133
+ .add('char', sqlCharCodec)
134
+ .add('varchar', sqlVarcharCodec)
135
+ .add('int', sqlIntCodec)
136
+ .add('float', sqlFloatCodec)
137
+ .add('text', sqlTextCodec)
138
+ .add('timestamp', sqlTimestampCodec);
139
+
140
+ export const sqlCodecDefinitions = codecs.codecDefinitions;
141
+ export const sqlDataTypes = codecs.dataTypes;
142
+ export type SqlCodecTypes = typeof codecs.CodecTypes;