@mionjs/drizzle 0.8.0-alpha.0

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 (60) hide show
  1. package/.dist/esm/index.d.ts +3 -0
  2. package/.dist/esm/index.js +9 -0
  3. package/.dist/esm/index.js.map +1 -0
  4. package/.dist/esm/src/core/typeTraverser.d.ts +6 -0
  5. package/.dist/esm/src/core/typeTraverser.js +99 -0
  6. package/.dist/esm/src/core/typeTraverser.js.map +1 -0
  7. package/.dist/esm/src/core/utils.d.ts +12 -0
  8. package/.dist/esm/src/core/utils.js +62 -0
  9. package/.dist/esm/src/core/utils.js.map +1 -0
  10. package/.dist/esm/src/core/validator.d.ts +2 -0
  11. package/.dist/esm/src/core/validator.js +172 -0
  12. package/.dist/esm/src/core/validator.js.map +1 -0
  13. package/.dist/esm/src/mappers/base.mapper.d.ts +14 -0
  14. package/.dist/esm/src/mappers/base.mapper.js +41 -0
  15. package/.dist/esm/src/mappers/base.mapper.js.map +1 -0
  16. package/.dist/esm/src/mappers/mysql.mapper.d.ts +12 -0
  17. package/.dist/esm/src/mappers/mysql.mapper.js +88 -0
  18. package/.dist/esm/src/mappers/mysql.mapper.js.map +1 -0
  19. package/.dist/esm/src/mappers/pg.mapper.d.ts +12 -0
  20. package/.dist/esm/src/mappers/pg.mapper.js +91 -0
  21. package/.dist/esm/src/mappers/pg.mapper.js.map +1 -0
  22. package/.dist/esm/src/mappers/sqlite.mapper.d.ts +12 -0
  23. package/.dist/esm/src/mappers/sqlite.mapper.js +70 -0
  24. package/.dist/esm/src/mappers/sqlite.mapper.js.map +1 -0
  25. package/.dist/esm/src/mysql.d.ts +15 -0
  26. package/.dist/esm/src/mysql.js +49 -0
  27. package/.dist/esm/src/mysql.js.map +1 -0
  28. package/.dist/esm/src/postgres.d.ts +15 -0
  29. package/.dist/esm/src/postgres.js +49 -0
  30. package/.dist/esm/src/postgres.js.map +1 -0
  31. package/.dist/esm/src/sqlite.d.ts +15 -0
  32. package/.dist/esm/src/sqlite.js +49 -0
  33. package/.dist/esm/src/sqlite.js.map +1 -0
  34. package/.dist/esm/src/stubs-formats-mappings/common.d.ts +28 -0
  35. package/.dist/esm/src/stubs-formats-mappings/common.js +11 -0
  36. package/.dist/esm/src/stubs-formats-mappings/common.js.map +1 -0
  37. package/.dist/esm/src/stubs-formats-mappings/mysql.stub.d.ts +1 -0
  38. package/.dist/esm/src/stubs-formats-mappings/mysql.stub.js +8 -0
  39. package/.dist/esm/src/stubs-formats-mappings/mysql.stub.js.map +1 -0
  40. package/.dist/esm/src/stubs-formats-mappings/postgres.stub.d.ts +1 -0
  41. package/.dist/esm/src/stubs-formats-mappings/postgres.stub.js +8 -0
  42. package/.dist/esm/src/stubs-formats-mappings/postgres.stub.js.map +1 -0
  43. package/.dist/esm/src/stubs-formats-mappings/sqlite.stub.d.ts +1 -0
  44. package/.dist/esm/src/stubs-formats-mappings/sqlite.stub.js +8 -0
  45. package/.dist/esm/src/stubs-formats-mappings/sqlite.stub.js.map +1 -0
  46. package/.dist/esm/src/types/common.types.d.ts +118 -0
  47. package/.dist/esm/src/types/common.types.js +81 -0
  48. package/.dist/esm/src/types/common.types.js.map +1 -0
  49. package/.dist/esm/src/types/mysql.types.d.ts +66 -0
  50. package/.dist/esm/src/types/mysql.types.js +26 -0
  51. package/.dist/esm/src/types/mysql.types.js.map +1 -0
  52. package/.dist/esm/src/types/postgres.types.d.ts +62 -0
  53. package/.dist/esm/src/types/postgres.types.js +28 -0
  54. package/.dist/esm/src/types/postgres.types.js.map +1 -0
  55. package/.dist/esm/src/types/sqlite.types.d.ts +62 -0
  56. package/.dist/esm/src/types/sqlite.types.js +22 -0
  57. package/.dist/esm/src/types/sqlite.types.js.map +1 -0
  58. package/LICENSE +21 -0
  59. package/README.md +28 -0
  60. package/package.json +62 -0
@@ -0,0 +1,3 @@
1
+ export * from './src/mysql.ts';
2
+ export * from './src/postgres.ts';
3
+ export * from './src/sqlite.ts';
@@ -0,0 +1,9 @@
1
+ import { toDrizzleMySqlTable } from "./src/mysql.js";
2
+ import { toDrizzlePGTable } from "./src/postgres.js";
3
+ import { toDrizzleSqliteTable } from "./src/sqlite.js";
4
+ export {
5
+ toDrizzleMySqlTable,
6
+ toDrizzlePGTable,
7
+ toDrizzleSqliteTable
8
+ };
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
@@ -0,0 +1,6 @@
1
+ import { BaseRunType } from '@mionjs/run-types';
2
+ import { ReflectionKind, ReceiveType } from '@deepkit/type';
3
+ import { TypeInfo } from '../types/common.types.ts';
4
+ export declare function extractTypeInfo<T>(type?: ReceiveType<T>): TypeInfo;
5
+ export declare function isDateType(kind: ReflectionKind): boolean;
6
+ export declare function getUnderlyingKind(rt: BaseRunType): ReflectionKind;
@@ -0,0 +1,99 @@
1
+ import { runType, isInterfaceRunType, isPropertyRunType, isPropertySignatureRunType, getRunTypeFormat } from "@mionjs/run-types";
2
+ import { ReflectionKind, __ΩReflectionKind as ___ReflectionKind } from "@deepkit/type";
3
+ import { TypedError } from "@mionjs/core";
4
+ const __ΩRecord = ["K", "T", "Record", `l'e#"Rb!b"Pde"!N#!w#y`];
5
+ function extractTypeInfo(type = extractTypeInfo.Ω?.[0]) {
6
+ extractTypeInfo.Ω = void 0;
7
+ const rt = runType(type);
8
+ if (!isInterfaceRunType(rt)) {
9
+ throw new TypedError({
10
+ type: "drizzle-table-invalid-source-type",
11
+ message: `Cannot create drizzle table from type "${rt.getKindName()}". Expected an interface or object type with properties to map to table columns.`
12
+ });
13
+ }
14
+ const interfaceRt = rt;
15
+ const properties = [];
16
+ const children = interfaceRt.getChildRunTypes();
17
+ for (const child of children) {
18
+ if (isPropertyRunType(child) || isPropertySignatureRunType(child)) {
19
+ const propRt = child;
20
+ const memberType = propRt.getMemberType();
21
+ const propInfo = extractPropertyInfo(propRt, memberType);
22
+ properties.push(propInfo);
23
+ }
24
+ }
25
+ return {
26
+ typeName: rt.getTypeName(),
27
+ properties
28
+ };
29
+ }
30
+ extractTypeInfo.__type = ["ReceiveType", "type", "TypeInfo", "extractTypeInfo", 'P"w!2"8"w#/$'];
31
+ function extractPropertyInfo(propRt, memberType) {
32
+ const kind = memberType.src.kind;
33
+ const formatInfo = getFormatInfo(memberType);
34
+ const isDate = checkIsDateType(memberType);
35
+ return {
36
+ name: propRt.getPropertyName(),
37
+ runType: memberType,
38
+ isOptional: propRt.isOptional(),
39
+ isNestedObject: isNestedObjectType(kind) && !isDate,
40
+ isArray: kind === ReflectionKind.array,
41
+ isDate,
42
+ formatName: formatInfo?.name,
43
+ formatParams: formatInfo?.params,
44
+ primitiveKind: isPrimitiveKind(kind) ? kind : void 0
45
+ };
46
+ }
47
+ extractPropertyInfo.__type = ["PropertyRunType", "propRt", "BaseRunType", "memberType", "PropertyInfo", "extractPropertyInfo", 'P"w!2""w#2$"w%/&'];
48
+ function isNestedObjectType(kind) {
49
+ return kind === ReflectionKind.objectLiteral || kind === ReflectionKind.class;
50
+ }
51
+ isNestedObjectType.__type = [() => ___ReflectionKind, "kind", "isNestedObjectType", 'Pn!2")/#'];
52
+ function isPrimitiveKind(kind) {
53
+ return kind === ReflectionKind.string || kind === ReflectionKind.number || kind === ReflectionKind.boolean || kind === ReflectionKind.bigint;
54
+ }
55
+ isPrimitiveKind.__type = [() => ___ReflectionKind, "kind", "isPrimitiveKind", 'Pn!2")/#'];
56
+ function getFormatInfo(rt) {
57
+ const format = getRunTypeFormat(rt);
58
+ if (!format)
59
+ return void 0;
60
+ return {
61
+ name: format.name,
62
+ params: format.getParams(rt)
63
+ };
64
+ }
65
+ getFormatInfo.__type = ["BaseRunType", "rt", "name", () => __ΩRecord, "params", "getFormatInfo", 'P"w!2"PP&4#&"o$#4%M-J/&'];
66
+ function checkIsDateType(rt) {
67
+ if (rt.src.kind !== ReflectionKind.class)
68
+ return false;
69
+ const src = rt.src;
70
+ if (src.classType === Date)
71
+ return true;
72
+ const typeName = rt.getTypeName();
73
+ return typeName === "Date";
74
+ }
75
+ checkIsDateType.__type = ["BaseRunType", "rt", "checkIsDateType", 'P"w!2")/#'];
76
+ function isDateType(kind) {
77
+ return kind === ReflectionKind.class;
78
+ }
79
+ isDateType.__type = [() => ___ReflectionKind, "kind", "isDateType", 'Pn!2")/#'];
80
+ function getUnderlyingKind(rt) {
81
+ const kind = rt.src.kind;
82
+ if (kind === ReflectionKind.union) {
83
+ const children = rt.getChildRunTypes?.() || [];
84
+ for (const child of children) {
85
+ const childKind = child.src.kind;
86
+ if (childKind !== ReflectionKind.null && childKind !== ReflectionKind.undefined) {
87
+ return childKind;
88
+ }
89
+ }
90
+ }
91
+ return kind;
92
+ }
93
+ getUnderlyingKind.__type = ["BaseRunType", "rt", () => ___ReflectionKind, "getUnderlyingKind", 'P"w!2"n#/$'];
94
+ export {
95
+ extractTypeInfo,
96
+ getUnderlyingKind,
97
+ isDateType
98
+ };
99
+ //# sourceMappingURL=typeTraverser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeTraverser.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,12 @@
1
+ import { ReflectionKind } from '@deepkit/type';
2
+ import { PropertyInfo } from '../types/common.types.ts';
3
+ export declare function toSnakeCase(str: string): string;
4
+ export declare function shouldBeJson(prop: PropertyInfo): boolean;
5
+ export declare function getParamValue<T>(param: T | {
6
+ val: T;
7
+ }): T;
8
+ export declare function isDateClass(kind: ReflectionKind, typeName?: string): boolean;
9
+ export declare function getMaxLengthFromParams(formatParams?: Record<string, any>): number | undefined;
10
+ export declare function getLengthFromParams(formatParams?: Record<string, any>): number | undefined;
11
+ export declare function isIntegerFormat(formatParams?: Record<string, any>): boolean;
12
+ export declare function isFloatFormat(formatParams?: Record<string, any>): boolean;
@@ -0,0 +1,62 @@
1
+ import { ReflectionKind, __ΩReflectionKind as ___ReflectionKind } from "@deepkit/type";
2
+ const __ΩRecord = ["K", "T", "Record", `l'e#"Rb!b"Pde"!N#!w#y`];
3
+ function __assignType(fn, args) {
4
+ fn.__type = args;
5
+ return fn;
6
+ }
7
+ function toSnakeCase(str) {
8
+ return str.replace(/[A-Z]/g, __assignType((letter) => `_${letter.toLowerCase()}`, ["letter", "", 'P"2!"/"']));
9
+ }
10
+ toSnakeCase.__type = ["str", "toSnakeCase", 'P&2!&/"'];
11
+ function shouldBeJson(prop) {
12
+ return prop.isNestedObject || prop.isArray;
13
+ }
14
+ shouldBeJson.__type = ["PropertyInfo", "prop", "shouldBeJson", 'P"w!2")/#'];
15
+ function getParamValue(param) {
16
+ if (param && typeof param === "object" && "val" in param) {
17
+ return param.val;
18
+ }
19
+ return param;
20
+ }
21
+ getParamValue.__type = ["val", "param", "getParamValue", 'PP"P"4!MJ2""/#'];
22
+ function isDateClass(kind, typeName) {
23
+ return kind === ReflectionKind.class && typeName === "Date";
24
+ }
25
+ isDateClass.__type = [() => ___ReflectionKind, "kind", "typeName", "isDateClass", 'Pn!2"&2#8)/$'];
26
+ function getMaxLengthFromParams(formatParams) {
27
+ if (!formatParams)
28
+ return void 0;
29
+ const maxLength = formatParams.maxLength;
30
+ return maxLength ? getParamValue(maxLength) : void 0;
31
+ }
32
+ getMaxLengthFromParams.__type = [() => __ΩRecord, "formatParams", "getMaxLengthFromParams", `P&"o!#2"8P'-J/#`];
33
+ function getLengthFromParams(formatParams) {
34
+ if (!formatParams)
35
+ return void 0;
36
+ const length = formatParams.length;
37
+ return length ? getParamValue(length) : void 0;
38
+ }
39
+ getLengthFromParams.__type = [() => __ΩRecord, "formatParams", "getLengthFromParams", `P&"o!#2"8P'-J/#`];
40
+ function isIntegerFormat(formatParams) {
41
+ if (!formatParams)
42
+ return false;
43
+ return !!getParamValue(formatParams.integer);
44
+ }
45
+ isIntegerFormat.__type = [() => __ΩRecord, "formatParams", "isIntegerFormat", 'P&"o!#2"8)/#'];
46
+ function isFloatFormat(formatParams) {
47
+ if (!formatParams)
48
+ return false;
49
+ return !!getParamValue(formatParams.float);
50
+ }
51
+ isFloatFormat.__type = [() => __ΩRecord, "formatParams", "isFloatFormat", 'P&"o!#2"8)/#'];
52
+ export {
53
+ getLengthFromParams,
54
+ getMaxLengthFromParams,
55
+ getParamValue,
56
+ isDateClass,
57
+ isFloatFormat,
58
+ isIntegerFormat,
59
+ shouldBeJson,
60
+ toSnakeCase
61
+ };
62
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,2 @@
1
+ import { TypeInfo, ValidationResult } from '../types/common.types.ts';
2
+ export declare function validateConfig(typeInfo: TypeInfo, tableConfig: Record<string, any>): ValidationResult;
@@ -0,0 +1,172 @@
1
+ import { ReflectionKind, __ΩReflectionKind as ___ReflectionKind } from "@deepkit/type";
2
+ const __ΩRecord = ["K", "T", "Record", `l'e#"Rb!b"Pde"!N#!w#y`];
3
+ function __assignType(fn, args) {
4
+ fn.__type = args;
5
+ return fn;
6
+ }
7
+ function validateConfig(typeInfo, tableConfig) {
8
+ const errors = [];
9
+ const warnings = [];
10
+ for (const prop of typeInfo.properties) {
11
+ const configColumn = tableConfig[prop.name];
12
+ if (!configColumn)
13
+ continue;
14
+ const typeError = validateTypeCompatibility(prop, configColumn);
15
+ if (typeError)
16
+ errors.push(typeError);
17
+ const nullError = validateNullability(prop, configColumn);
18
+ if (nullError)
19
+ errors.push(nullError);
20
+ const formatWarning = validateFormatConstraints(prop, configColumn);
21
+ if (formatWarning)
22
+ warnings.push(formatWarning);
23
+ }
24
+ for (const configKey of Object.keys(tableConfig)) {
25
+ const exists = typeInfo.properties.some(__assignType((p) => p.name === configKey, ["p", "", 'P"2!"/"']));
26
+ if (!exists)
27
+ errors.push(`Column "${configKey}" exists in tableConfig but not in type "${typeInfo.typeName}"`);
28
+ }
29
+ return { valid: errors.length === 0, errors, warnings };
30
+ }
31
+ validateConfig.__type = ["TypeInfo", "typeInfo", () => __ΩRecord, "tableConfig", "ValidationResult", "validateConfig", 'P"w!2"&"o##2$"w%/&'];
32
+ function validateTypeCompatibility(prop, column) {
33
+ const columnType = getColumnType(column);
34
+ const expectedTypes = getExpectedColumnTypes(prop);
35
+ if (expectedTypes.length > 0 && !expectedTypes.includes(columnType)) {
36
+ return `Type mismatch for property "${prop.name}": TypeScript type expects ${expectedTypes.join(" or ")}, but drizzle column is "${columnType}"`;
37
+ }
38
+ return null;
39
+ }
40
+ validateTypeCompatibility.__type = ["PropertyInfo", "prop", "column", "validateTypeCompatibility", 'P"w!2""2#P&,J/$'];
41
+ function validateNullability(prop, column) {
42
+ const isColumnNotNull = hasNotNullConstraint(column);
43
+ if (prop.isOptional && isColumnNotNull)
44
+ return `Property "${prop.name}" is optional in type but column has .notNull() constraint`;
45
+ return null;
46
+ }
47
+ validateNullability.__type = ["PropertyInfo", "prop", "column", "validateNullability", 'P"w!2""2#P&,J/$'];
48
+ function validateFormatConstraints(prop, column) {
49
+ if (!prop.formatParams)
50
+ return null;
51
+ if (prop.formatParams.maxLength) {
52
+ const columnLength = getColumnLength(column);
53
+ if (columnLength && columnLength < prop.formatParams.maxLength) {
54
+ return `Column "${prop.name}" has length ${columnLength} but type format requires maxLength ${prop.formatParams.maxLength}`;
55
+ }
56
+ }
57
+ return null;
58
+ }
59
+ validateFormatConstraints.__type = ["PropertyInfo", "prop", "column", "validateFormatConstraints", 'P"w!2""2#P&,J/$'];
60
+ function getColumnType(column) {
61
+ if (column.dataType)
62
+ return column.dataType;
63
+ if (column.columnType)
64
+ return column.columnType;
65
+ if (column._ && column._.dataType)
66
+ return column._.dataType;
67
+ if (column.config && column.config.dataType)
68
+ return column.config.dataType;
69
+ if (column.config && column.config.columnType)
70
+ return column.config.columnType;
71
+ if (column.constructor && column.constructor.name) {
72
+ const name = column.constructor.name;
73
+ if (name.includes("UUID"))
74
+ return "string";
75
+ if (name.includes("Text"))
76
+ return "string";
77
+ if (name.includes("Varchar"))
78
+ return "string";
79
+ if (name.includes("Char"))
80
+ return "string";
81
+ if (name.includes("Integer") || name.includes("Int"))
82
+ return "number";
83
+ if (name.includes("Boolean"))
84
+ return "boolean";
85
+ if (name.includes("Timestamp") || name.includes("Date"))
86
+ return "date";
87
+ if (name.includes("Json"))
88
+ return "json";
89
+ if (name.includes("Double") || name.includes("Real") || name.includes("Float"))
90
+ return "number";
91
+ if (name.includes("BigInt"))
92
+ return "bigint";
93
+ }
94
+ return "unknown";
95
+ }
96
+ getColumnType.__type = ["column", "getColumnType", 'P"2!&/"'];
97
+ function hasNotNullConstraint(column) {
98
+ if (column.notNull === true)
99
+ return true;
100
+ if (column._ && column._.notNull === true)
101
+ return true;
102
+ return false;
103
+ }
104
+ hasNotNullConstraint.__type = ["column", "hasNotNullConstraint", 'P"2!)/"'];
105
+ function getColumnLength(column) {
106
+ if (column.length)
107
+ return column.length;
108
+ if (column._ && column._.length)
109
+ return column._.length;
110
+ return null;
111
+ }
112
+ getColumnLength.__type = ["column", "getColumnLength", `P"2!P',J/"`];
113
+ function getExpectedColumnTypes(prop) {
114
+ if (prop.isNestedObject || prop.isArray)
115
+ return ["json", "jsonb", "text"];
116
+ if (prop.formatName)
117
+ return getExpectedTypesForFormat(prop.formatName);
118
+ if (prop.primitiveKind !== void 0)
119
+ return getExpectedTypesForPrimitive(prop.primitiveKind);
120
+ const kind = prop.runType.src.kind;
121
+ if (kind === ReflectionKind.class) {
122
+ const typeName = prop.runType.getTypeName();
123
+ if (typeName === "Date")
124
+ return ["timestamp", "date", "datetime", "integer", "text"];
125
+ }
126
+ return [];
127
+ }
128
+ getExpectedColumnTypes.__type = ["PropertyInfo", "prop", "getExpectedColumnTypes", 'P"w!2"&F/#'];
129
+ function getExpectedTypesForFormat(formatName) {
130
+ switch (formatName) {
131
+ case "uuid":
132
+ return ["uuid", "varchar", "text"];
133
+ case "email":
134
+ return ["text", "varchar"];
135
+ case "url":
136
+ return ["text", "varchar"];
137
+ case "ip":
138
+ return ["inet", "varchar", "text"];
139
+ case "date":
140
+ return ["date", "text"];
141
+ case "time":
142
+ return ["time", "text"];
143
+ case "dateTime":
144
+ return ["timestamp", "datetime", "text"];
145
+ case "numberFormat":
146
+ return ["integer", "int", "smallint", "bigint", "real", "double", "doublePrecision", "numeric", "decimal"];
147
+ case "bigIntFormat":
148
+ return ["bigint", "blob"];
149
+ default:
150
+ return [];
151
+ }
152
+ }
153
+ getExpectedTypesForFormat.__type = ["formatName", "getExpectedTypesForFormat", 'P&2!&F/"'];
154
+ function getExpectedTypesForPrimitive(kind) {
155
+ switch (kind) {
156
+ case ReflectionKind.string:
157
+ return ["text", "varchar", "char", "uuid", "inet", "string"];
158
+ case ReflectionKind.number:
159
+ return ["integer", "int", "smallint", "real", "double", "doublePrecision", "numeric", "decimal", "number"];
160
+ case ReflectionKind.boolean:
161
+ return ["boolean", "integer"];
162
+ case ReflectionKind.bigint:
163
+ return ["bigint", "blob"];
164
+ default:
165
+ return [];
166
+ }
167
+ }
168
+ getExpectedTypesForPrimitive.__type = [() => ___ReflectionKind, "kind", "getExpectedTypesForPrimitive", 'Pn!2"&F/#'];
169
+ export {
170
+ validateConfig
171
+ };
172
+ //# sourceMappingURL=validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,14 @@
1
+ import { ReflectionKind } from '@deepkit/type';
2
+ import { ColumnMapping, PropertyInfo, DrizzleMapperConfig } from '../types/common.types.ts';
3
+ import { FormatName } from '@mionjs/type-formats/constants';
4
+ export declare abstract class BaseColumnMapper {
5
+ protected lengthBuffer: number;
6
+ constructor(config?: DrizzleMapperConfig);
7
+ protected applyLengthBuffer(maxLength: number): number;
8
+ abstract mapPrimitive(kind: ReflectionKind, propName: string): ColumnMapping;
9
+ abstract mapFormat(formatName: FormatName, formatParams: Record<string, any> | undefined, propName: string): ColumnMapping;
10
+ abstract mapArray(propName: string): ColumnMapping;
11
+ abstract mapObject(propName: string): ColumnMapping;
12
+ abstract mapDate(propName: string): ColumnMapping;
13
+ mapProperty(prop: PropertyInfo): ColumnMapping;
14
+ }
@@ -0,0 +1,41 @@
1
+ import { ReflectionKind, __ΩReflectionKind as ___ReflectionKind } from "@deepkit/type";
2
+ import { DEFAULT_LENGTH_BUFFER } from "../types/common.types.js";
3
+ import { shouldBeJson } from "../core/utils.js";
4
+ import { __ΩFormatName as ___FormatName } from "@mionjs/type-formats/constants";
5
+ const __ΩRecord = ["K", "T", "Record", `l'e#"Rb!b"Pde"!N#!w#y`];
6
+ class BaseColumnMapper {
7
+ lengthBuffer;
8
+ constructor(config) {
9
+ this.lengthBuffer = config?.lengthBuffer ?? DEFAULT_LENGTH_BUFFER;
10
+ }
11
+ /** Applies length buffer to a maxLength value */
12
+ applyLengthBuffer(maxLength) {
13
+ return Math.ceil(maxLength * this.lengthBuffer);
14
+ }
15
+ /** Maps a property to a drizzle column based on its type information */
16
+ mapProperty(prop) {
17
+ const { name, isOptional, formatName, formatParams } = prop;
18
+ let mapping;
19
+ if (prop.isDate)
20
+ mapping = this.mapDate(name);
21
+ else if (shouldBeJson(prop)) {
22
+ if (prop.isArray)
23
+ mapping = this.mapArray(name);
24
+ else
25
+ mapping = this.mapObject(name);
26
+ } else if (formatName)
27
+ mapping = this.mapFormat(formatName, formatParams, name);
28
+ else if (prop.primitiveKind !== void 0)
29
+ mapping = this.mapPrimitive(prop.primitiveKind, name);
30
+ else
31
+ mapping = this.mapPrimitive(ReflectionKind.string, name);
32
+ if (!isOptional && mapping.builder.notNull)
33
+ mapping.builder = mapping.builder.notNull();
34
+ return mapping;
35
+ }
36
+ static __type = ["lengthBuffer", "DrizzleMapperConfig", "config", "constructor", "maxLength", "applyLengthBuffer", () => ___ReflectionKind, "kind", "propName", "ColumnMapping", "mapPrimitive", () => ___FormatName, "formatName", () => __ΩRecord, "formatParams", "mapFormat", "mapArray", "mapObject", "mapDate", "PropertyInfo", "prop", "mapProperty", "BaseColumnMapper", `'3!<P"w"2#8"0$P'2%'0&<Pn'2(&2)"w*0+=Pn,2-P&"o.#-J2/&2)"w*00=P&2)"w*01=P&2)"w*02=P&2)"w*03=P"w425"w*065w7`];
37
+ }
38
+ export {
39
+ BaseColumnMapper
40
+ };
41
+ //# sourceMappingURL=base.mapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.mapper.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,12 @@
1
+ import { ReflectionKind } from '@deepkit/type';
2
+ import { BaseColumnMapper } from './base.mapper.ts';
3
+ import { ColumnMapping, DrizzleMapperConfig } from '../types/common.types.ts';
4
+ import { FormatName } from '@mionjs/type-formats/constants';
5
+ export declare class MySQLColumnMapper extends BaseColumnMapper {
6
+ constructor(config?: DrizzleMapperConfig);
7
+ mapPrimitive(kind: ReflectionKind, propName: string): ColumnMapping;
8
+ mapFormat(formatName: FormatName, formatParams: Record<string, any> | undefined, propName: string): ColumnMapping;
9
+ mapArray(propName: string): ColumnMapping;
10
+ mapObject(propName: string): ColumnMapping;
11
+ mapDate(propName: string): ColumnMapping;
12
+ }
@@ -0,0 +1,88 @@
1
+ import { varchar, json, timestamp, bigint, boolean, double, int, time, date, datetime } from "drizzle-orm/mysql-core";
2
+ import { ReflectionKind, __ΩReflectionKind as ___ReflectionKind } from "@deepkit/type";
3
+ import { TypedError } from "@mionjs/core";
4
+ import { BaseColumnMapper } from "./base.mapper.js";
5
+ import { DrizzleTypesMySQL, DEFAULT_VARCHAR_LENGTH, DEFAULT_LENGTH_BUFFER } from "../types/common.types.js";
6
+ import { getMaxLengthFromParams, isIntegerFormat } from "../core/utils.js";
7
+ import { FormatNames, __ΩFormatName as ___FormatName } from "@mionjs/type-formats/constants";
8
+ const __ΩRecord = ["K", "T", "Record", `l'e#"Rb!b"Pde"!N#!w#y`];
9
+ function __assignType(fn, args) {
10
+ fn.__type = args;
11
+ return fn;
12
+ }
13
+ const mysqlPrimitiveDefaults = {
14
+ [ReflectionKind.string]: __assignType((p) => ({
15
+ builder: varchar(p, { length: DEFAULT_VARCHAR_LENGTH }),
16
+ drizzleType: DrizzleTypesMySQL.varchar
17
+ }), ["p", "", 'P"2!"/"']),
18
+ [ReflectionKind.number]: __assignType((p) => ({ builder: double(p), drizzleType: DrizzleTypesMySQL.double }), ["p", "", 'P"2!"/"']),
19
+ [ReflectionKind.boolean]: __assignType((p) => ({ builder: boolean(p), drizzleType: DrizzleTypesMySQL.boolean }), ["p", "", 'P"2!"/"']),
20
+ [ReflectionKind.bigint]: __assignType((p) => ({ builder: bigint(p, { mode: "bigint" }), drizzleType: DrizzleTypesMySQL.bigint }), ["p", "", 'P"2!"/"'])
21
+ };
22
+ const mysqlFormatDefaults = {
23
+ [FormatNames.uuid]: __assignType((p) => ({ builder: varchar(p, { length: 36 }), drizzleType: DrizzleTypesMySQL.varchar }), ["p", "", 'P"2!"/"']),
24
+ [FormatNames.email]: __assignType((p, params) => {
25
+ const maxLength = getMaxLengthFromParams(params) || 254;
26
+ return { builder: varchar(p, { length: maxLength }), drizzleType: DrizzleTypesMySQL.varchar };
27
+ }, ["p", "params", "", 'P"2!"2""/#']),
28
+ [FormatNames.url]: __assignType((p, params) => {
29
+ const maxLength = getMaxLengthFromParams(params) || 2048;
30
+ return { builder: varchar(p, { length: maxLength }), drizzleType: DrizzleTypesMySQL.varchar };
31
+ }, ["p", "params", "", 'P"2!"2""/#']),
32
+ [FormatNames.domain]: __assignType((p, params) => {
33
+ const maxLength = getMaxLengthFromParams(params) || 253;
34
+ return { builder: varchar(p, { length: maxLength }), drizzleType: DrizzleTypesMySQL.varchar };
35
+ }, ["p", "params", "", 'P"2!"2""/#']),
36
+ [FormatNames.ip]: __assignType((p) => ({ builder: varchar(p, { length: 45 }), drizzleType: DrizzleTypesMySQL.varchar }), ["p", "", 'P"2!"/"']),
37
+ [FormatNames.dateTime]: __assignType((p) => ({ builder: datetime(p), drizzleType: DrizzleTypesMySQL.datetime }), ["p", "", 'P"2!"/"']),
38
+ [FormatNames.date]: __assignType((p) => ({ builder: date(p), drizzleType: DrizzleTypesMySQL.date }), ["p", "", 'P"2!"/"']),
39
+ [FormatNames.time]: __assignType((p) => ({ builder: time(p), drizzleType: DrizzleTypesMySQL.time }), ["p", "", 'P"2!"/"']),
40
+ [FormatNames.bigintFormat]: __assignType((p) => ({ builder: bigint(p, { mode: "bigint" }), drizzleType: DrizzleTypesMySQL.bigint }), ["p", "", 'P"2!"/"']),
41
+ [FormatNames.numberFormat]: __assignType((p, params) => {
42
+ if (isIntegerFormat(params))
43
+ return { builder: int(p), drizzleType: DrizzleTypesMySQL.int };
44
+ return { builder: double(p), drizzleType: DrizzleTypesMySQL.double };
45
+ }, ["p", "params", "", 'P"2!"2""/#']),
46
+ [FormatNames.stringFormat]: __assignType((p, params, config) => {
47
+ const buf = config?.lengthBuffer ?? DEFAULT_LENGTH_BUFFER;
48
+ const maxLength = getMaxLengthFromParams(params);
49
+ if (maxLength)
50
+ return { builder: varchar(p, { length: Math.ceil(maxLength * buf) }), drizzleType: DrizzleTypesMySQL.varchar };
51
+ return { builder: varchar(p, { length: DEFAULT_VARCHAR_LENGTH }), drizzleType: DrizzleTypesMySQL.varchar };
52
+ }, ["p", "params", "config", "", 'P"2!"2""2#"/$'])
53
+ };
54
+ class MySQLColumnMapper extends BaseColumnMapper {
55
+ constructor(config) {
56
+ super(config);
57
+ }
58
+ mapPrimitive(kind, propName) {
59
+ const factory = mysqlPrimitiveDefaults[kind];
60
+ if (!factory) {
61
+ throw new TypedError({
62
+ type: "drizzle-column-mapping-failed",
63
+ message: `Cannot map property "${propName}" to MySQL column. TypeScript primitive type "${ReflectionKind[kind]}" has no corresponding drizzle column type.`
64
+ });
65
+ }
66
+ return factory(propName);
67
+ }
68
+ mapFormat(formatName, formatParams, propName) {
69
+ const factory = mysqlFormatDefaults[formatName];
70
+ if (!factory)
71
+ return { builder: varchar(propName, { length: DEFAULT_VARCHAR_LENGTH }), drizzleType: DrizzleTypesMySQL.varchar };
72
+ return factory(propName, formatParams, { lengthBuffer: this.lengthBuffer });
73
+ }
74
+ mapArray(propName) {
75
+ return { builder: json(propName), drizzleType: DrizzleTypesMySQL.json };
76
+ }
77
+ mapObject(propName) {
78
+ return { builder: json(propName), drizzleType: DrizzleTypesMySQL.json };
79
+ }
80
+ mapDate(propName) {
81
+ return { builder: timestamp(propName), drizzleType: DrizzleTypesMySQL.timestamp };
82
+ }
83
+ static __type = [() => BaseColumnMapper, "DrizzleMapperConfig", "config", "constructor", () => ___ReflectionKind, "kind", "propName", "ColumnMapping", "mapPrimitive", () => ___FormatName, "formatName", () => __ΩRecord, "formatParams", "mapFormat", "mapArray", "mapObject", "mapDate", "MySQLColumnMapper", `P7!P"w"2#8"0$Pn%2&&2'"w(0)Pn*2+P&"o,#-J2-&2'"w(0.P&2'"w(0/P&2'"w(00P&2'"w(015w2`];
84
+ }
85
+ export {
86
+ MySQLColumnMapper
87
+ };
88
+ //# sourceMappingURL=mysql.mapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mysql.mapper.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,12 @@
1
+ import { ReflectionKind } from '@deepkit/type';
2
+ import { BaseColumnMapper } from './base.mapper.ts';
3
+ import { ColumnMapping, DrizzleMapperConfig } from '../types/common.types.ts';
4
+ import { FormatName } from '@mionjs/type-formats/constants';
5
+ export declare class PGColumnMapper extends BaseColumnMapper {
6
+ constructor(config?: DrizzleMapperConfig);
7
+ mapPrimitive(kind: ReflectionKind, propName: string): ColumnMapping;
8
+ mapFormat(formatName: FormatName, formatParams: Record<string, any> | undefined, propName: string): ColumnMapping;
9
+ mapArray(propName: string): ColumnMapping;
10
+ mapObject(propName: string): ColumnMapping;
11
+ mapDate(propName: string): ColumnMapping;
12
+ }