@prisma-next/sql-relational-core 0.3.0-pr.99.6 → 0.4.0-dev.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.
- package/LICENSE +201 -0
- package/README.md +20 -6
- package/dist/codec-types-DcEITed4.d.mts +144 -0
- package/dist/codec-types-DcEITed4.d.mts.map +1 -0
- package/dist/errors-Cs52upp3.d.mts +8 -0
- package/dist/errors-Cs52upp3.d.mts.map +1 -0
- package/dist/errors-D3xmG4h-.mjs +35 -0
- package/dist/errors-D3xmG4h-.mjs.map +1 -0
- package/dist/exports/ast.d.mts +158 -0
- package/dist/exports/ast.d.mts.map +1 -0
- package/dist/exports/ast.mjs +1358 -0
- package/dist/exports/ast.mjs.map +1 -0
- package/dist/exports/errors.d.mts +5 -0
- package/dist/exports/errors.mjs +3 -0
- package/dist/exports/plan.d.mts +2 -0
- package/dist/exports/plan.mjs +17 -0
- package/dist/exports/plan.mjs.map +1 -0
- package/dist/exports/query-lane-context.d.mts +3 -0
- package/dist/exports/query-lane-context.mjs +1 -0
- package/dist/exports/types.d.mts +4 -0
- package/dist/exports/types.mjs +1 -0
- package/dist/index.d.mts +11 -0
- package/dist/index.mjs +7 -0
- package/dist/plan-5qUWdlJM.d.mts +28 -0
- package/dist/plan-5qUWdlJM.d.mts.map +1 -0
- package/dist/query-lane-context-UlR8vOkd.d.mts +89 -0
- package/dist/query-lane-context-UlR8vOkd.d.mts.map +1 -0
- package/dist/types-CLCtwVWx.d.mts +485 -0
- package/dist/types-CLCtwVWx.d.mts.map +1 -0
- package/dist/types-V1qiC5DO.d.mts +200 -0
- package/dist/types-V1qiC5DO.d.mts.map +1 -0
- package/package.json +30 -52
- package/src/ast/adapter-types.ts +11 -0
- package/src/ast/codec-types.ts +101 -53
- package/src/ast/driver-types.ts +20 -3
- package/src/ast/sql-codecs.ts +142 -0
- package/src/ast/types.ts +1678 -88
- package/src/errors.ts +47 -1
- package/src/exports/ast.ts +1 -8
- package/src/index.ts +0 -3
- package/src/plan.ts +4 -4
- package/src/query-lane-context.ts +74 -11
- package/src/types.ts +102 -404
- package/dist/ast/adapter-types.d.ts +0 -28
- package/dist/ast/adapter-types.d.ts.map +0 -1
- package/dist/ast/codec-types.d.ts +0 -141
- package/dist/ast/codec-types.d.ts.map +0 -1
- package/dist/ast/common.d.ts +0 -7
- package/dist/ast/common.d.ts.map +0 -1
- package/dist/ast/delete.d.ts +0 -8
- package/dist/ast/delete.d.ts.map +0 -1
- package/dist/ast/driver-types.d.ts +0 -20
- package/dist/ast/driver-types.d.ts.map +0 -1
- package/dist/ast/insert.d.ts +0 -8
- package/dist/ast/insert.d.ts.map +0 -1
- package/dist/ast/join.d.ts +0 -6
- package/dist/ast/join.d.ts.map +0 -1
- package/dist/ast/order.d.ts +0 -6
- package/dist/ast/order.d.ts.map +0 -1
- package/dist/ast/predicate.d.ts +0 -4
- package/dist/ast/predicate.d.ts.map +0 -1
- package/dist/ast/select.d.ts +0 -18
- package/dist/ast/select.d.ts.map +0 -1
- package/dist/ast/types.d.ts +0 -130
- package/dist/ast/types.d.ts.map +0 -1
- package/dist/ast/update.d.ts +0 -9
- package/dist/ast/update.d.ts.map +0 -1
- package/dist/ast/util.d.ts +0 -2
- package/dist/ast/util.d.ts.map +0 -1
- package/dist/chunk-2BWK6XEY.js +0 -13
- package/dist/chunk-2BWK6XEY.js.map +0 -1
- package/dist/chunk-2F7DSEOU.js +0 -8
- package/dist/chunk-2F7DSEOU.js.map +0 -1
- package/dist/chunk-2MAKNVCP.js +0 -86
- package/dist/chunk-2MAKNVCP.js.map +0 -1
- package/dist/chunk-36WJWNHT.js +0 -1
- package/dist/chunk-36WJWNHT.js.map +0 -1
- package/dist/chunk-3F4RFQIB.js +0 -169
- package/dist/chunk-3F4RFQIB.js.map +0 -1
- package/dist/chunk-7I3EMQID.js +0 -16
- package/dist/chunk-7I3EMQID.js.map +0 -1
- package/dist/chunk-G52ENULI.js +0 -1
- package/dist/chunk-G52ENULI.js.map +0 -1
- package/dist/chunk-HV334QHG.js +0 -320
- package/dist/chunk-HV334QHG.js.map +0 -1
- package/dist/chunk-KYSP7L5C.js +0 -16
- package/dist/chunk-KYSP7L5C.js.map +0 -1
- package/dist/chunk-U7AXAUJA.js +0 -1
- package/dist/chunk-U7AXAUJA.js.map +0 -1
- package/dist/chunk-YXD25S5I.js +0 -171
- package/dist/chunk-YXD25S5I.js.map +0 -1
- package/dist/errors.d.ts +0 -2
- package/dist/errors.d.ts.map +0 -1
- package/dist/exports/ast.d.ts +0 -14
- package/dist/exports/ast.d.ts.map +0 -1
- package/dist/exports/ast.js +0 -46
- package/dist/exports/ast.js.map +0 -1
- package/dist/exports/errors.d.ts +0 -2
- package/dist/exports/errors.d.ts.map +0 -1
- package/dist/exports/errors.js +0 -9
- package/dist/exports/errors.js.map +0 -1
- package/dist/exports/guards.d.ts +0 -2
- package/dist/exports/guards.d.ts.map +0 -1
- package/dist/exports/guards.js +0 -31
- package/dist/exports/guards.js.map +0 -1
- package/dist/exports/operations-registry.d.ts +0 -2
- package/dist/exports/operations-registry.d.ts.map +0 -1
- package/dist/exports/operations-registry.js +0 -9
- package/dist/exports/operations-registry.js.map +0 -1
- package/dist/exports/param.d.ts +0 -3
- package/dist/exports/param.d.ts.map +0 -1
- package/dist/exports/param.js +0 -7
- package/dist/exports/param.js.map +0 -1
- package/dist/exports/plan.d.ts +0 -2
- package/dist/exports/plan.d.ts.map +0 -1
- package/dist/exports/plan.js +0 -7
- package/dist/exports/plan.js.map +0 -1
- package/dist/exports/query-lane-context.d.ts +0 -2
- package/dist/exports/query-lane-context.d.ts.map +0 -1
- package/dist/exports/query-lane-context.js +0 -2
- package/dist/exports/query-lane-context.js.map +0 -1
- package/dist/exports/schema.d.ts +0 -3
- package/dist/exports/schema.d.ts.map +0 -1
- package/dist/exports/schema.js +0 -13
- package/dist/exports/schema.js.map +0 -1
- package/dist/exports/types.d.ts +0 -2
- package/dist/exports/types.d.ts.map +0 -1
- package/dist/exports/types.js +0 -10
- package/dist/exports/types.js.map +0 -1
- package/dist/index.d.ts +0 -9
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -81
- package/dist/index.js.map +0 -1
- package/dist/operations-registry.d.ts +0 -5
- package/dist/operations-registry.d.ts.map +0 -1
- package/dist/param.d.ts +0 -4
- package/dist/param.d.ts.map +0 -1
- package/dist/plan.d.ts +0 -23
- package/dist/plan.d.ts.map +0 -1
- package/dist/query-lane-context.d.ts +0 -27
- package/dist/query-lane-context.d.ts.map +0 -1
- package/dist/schema.d.ts +0 -83
- package/dist/schema.d.ts.map +0 -1
- package/dist/types.d.ts +0 -371
- package/dist/types.d.ts.map +0 -1
- package/dist/utils/guards.d.ts +0 -82
- package/dist/utils/guards.d.ts.map +0 -1
- package/src/ast/common.ts +0 -36
- package/src/ast/delete.ts +0 -17
- package/src/ast/insert.ts +0 -17
- package/src/ast/join.ts +0 -54
- package/src/ast/order.ts +0 -11
- package/src/ast/predicate.ts +0 -22
- package/src/ast/select.ts +0 -39
- package/src/ast/update.ts +0 -19
- package/src/exports/guards.ts +0 -15
- package/src/exports/operations-registry.ts +0 -1
- package/src/exports/param.ts +0 -2
- package/src/exports/schema.ts +0 -6
- package/src/operations-registry.ts +0 -276
- package/src/param.ts +0 -15
- package/src/schema.ts +0 -406
- package/src/utils/guards.ts +0 -193
|
@@ -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;
|