@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,91 @@
1
+ import { varchar, jsonb, timestamp, bigint, boolean, doublePrecision, integer, time, date, inet, uuid } from "drizzle-orm/pg-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 { DrizzleTypesPostgres, DEFAULT_VARCHAR_LENGTH, DEFAULT_LENGTH_BUFFER } from "../types/common.types.js";
6
+ import { getMaxLengthFromParams, getLengthFromParams, 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 pgPrimitiveDefaults = {
14
+ [ReflectionKind.string]: __assignType((p) => ({
15
+ builder: varchar(p, { length: DEFAULT_VARCHAR_LENGTH }),
16
+ drizzleType: DrizzleTypesPostgres.varchar
17
+ }), ["p", "", 'P"2!"/"']),
18
+ [ReflectionKind.number]: __assignType((p) => ({ builder: doublePrecision(p), drizzleType: DrizzleTypesPostgres.doublePrecision }), ["p", "", 'P"2!"/"']),
19
+ [ReflectionKind.boolean]: __assignType((p) => ({ builder: boolean(p), drizzleType: DrizzleTypesPostgres.boolean }), ["p", "", 'P"2!"/"']),
20
+ [ReflectionKind.bigint]: __assignType((p) => ({ builder: bigint(p, { mode: "bigint" }), drizzleType: DrizzleTypesPostgres.bigint }), ["p", "", 'P"2!"/"'])
21
+ };
22
+ const pgFormatDefaults = {
23
+ [FormatNames.uuid]: __assignType((p) => ({ builder: uuid(p), drizzleType: DrizzleTypesPostgres.uuid }), ["p", "", 'P"2!"/"']),
24
+ [FormatNames.email]: __assignType((p, params) => {
25
+ const maxLength = getMaxLengthFromParams(params) || 254;
26
+ return { builder: varchar(p, { length: maxLength }), drizzleType: DrizzleTypesPostgres.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: DrizzleTypesPostgres.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: DrizzleTypesPostgres.varchar };
35
+ }, ["p", "params", "", 'P"2!"2""/#']),
36
+ [FormatNames.ip]: __assignType((p) => ({ builder: inet(p), drizzleType: DrizzleTypesPostgres.inet }), ["p", "", 'P"2!"/"']),
37
+ [FormatNames.dateTime]: __assignType((p) => ({ builder: timestamp(p), drizzleType: DrizzleTypesPostgres.timestamp }), ["p", "", 'P"2!"/"']),
38
+ [FormatNames.date]: __assignType((p) => ({ builder: date(p), drizzleType: DrizzleTypesPostgres.date }), ["p", "", 'P"2!"/"']),
39
+ [FormatNames.time]: __assignType((p) => ({ builder: time(p), drizzleType: DrizzleTypesPostgres.time }), ["p", "", 'P"2!"/"']),
40
+ [FormatNames.bigintFormat]: __assignType((p) => ({ builder: bigint(p, { mode: "bigint" }), drizzleType: DrizzleTypesPostgres.bigint }), ["p", "", 'P"2!"/"']),
41
+ [FormatNames.numberFormat]: __assignType((p, params) => {
42
+ if (isIntegerFormat(params))
43
+ return { builder: integer(p), drizzleType: DrizzleTypesPostgres.integer };
44
+ return { builder: doublePrecision(p), drizzleType: DrizzleTypesPostgres.doublePrecision };
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
+ const exactLength = getLengthFromParams(params);
50
+ if (exactLength)
51
+ return { builder: varchar(p, { length: exactLength }), drizzleType: DrizzleTypesPostgres.varchar };
52
+ if (maxLength)
53
+ return { builder: varchar(p, { length: Math.ceil(maxLength * buf) }), drizzleType: DrizzleTypesPostgres.varchar };
54
+ return { builder: varchar(p, { length: DEFAULT_VARCHAR_LENGTH }), drizzleType: DrizzleTypesPostgres.varchar };
55
+ }, ["p", "params", "config", "", 'P"2!"2""2#"/$'])
56
+ };
57
+ class PGColumnMapper extends BaseColumnMapper {
58
+ constructor(config) {
59
+ super(config);
60
+ }
61
+ mapPrimitive(kind, propName) {
62
+ const factory = pgPrimitiveDefaults[kind];
63
+ if (!factory) {
64
+ throw new TypedError({
65
+ type: "drizzle-column-mapping-failed",
66
+ message: `Cannot map property "${propName}" to PostgreSQL column. TypeScript primitive type "${ReflectionKind[kind]}" has no corresponding drizzle column type.`
67
+ });
68
+ }
69
+ return factory(propName);
70
+ }
71
+ mapFormat(formatName, formatParams, propName) {
72
+ const factory = pgFormatDefaults[formatName];
73
+ if (!factory)
74
+ return { builder: varchar(propName, { length: DEFAULT_VARCHAR_LENGTH }), drizzleType: DrizzleTypesPostgres.varchar };
75
+ return factory(propName, formatParams, { lengthBuffer: this.lengthBuffer });
76
+ }
77
+ mapArray(propName) {
78
+ return { builder: jsonb(propName), drizzleType: DrizzleTypesPostgres.jsonb };
79
+ }
80
+ mapObject(propName) {
81
+ return { builder: jsonb(propName), drizzleType: DrizzleTypesPostgres.jsonb };
82
+ }
83
+ mapDate(propName) {
84
+ return { builder: timestamp(propName), drizzleType: DrizzleTypesPostgres.timestamp };
85
+ }
86
+ static __type = [() => BaseColumnMapper, "DrizzleMapperConfig", "config", "constructor", () => ___ReflectionKind, "kind", "propName", "ColumnMapping", "mapPrimitive", () => ___FormatName, "formatName", () => __ΩRecord, "formatParams", "mapFormat", "mapArray", "mapObject", "mapDate", "PGColumnMapper", `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`];
87
+ }
88
+ export {
89
+ PGColumnMapper
90
+ };
91
+ //# sourceMappingURL=pg.mapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pg.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 SQLiteColumnMapper 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,70 @@
1
+ import { text, integer, blob, real } from "drizzle-orm/sqlite-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 { DrizzleTypesSQLite } from "../types/common.types.js";
6
+ import { 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 sqlitePrimitiveDefaults = {
14
+ [ReflectionKind.string]: __assignType((p) => ({ builder: text(p), drizzleType: DrizzleTypesSQLite.text }), ["p", "", 'P"2!"/"']),
15
+ [ReflectionKind.number]: __assignType((p) => ({ builder: real(p), drizzleType: DrizzleTypesSQLite.real }), ["p", "", 'P"2!"/"']),
16
+ [ReflectionKind.boolean]: __assignType((p) => ({ builder: integer(p, { mode: "boolean" }), drizzleType: DrizzleTypesSQLite.integer }), ["p", "", 'P"2!"/"']),
17
+ [ReflectionKind.bigint]: __assignType((p) => ({ builder: blob(p, { mode: "bigint" }), drizzleType: DrizzleTypesSQLite.blob }), ["p", "", 'P"2!"/"'])
18
+ };
19
+ const sqliteFormatDefaults = {
20
+ [FormatNames.uuid]: __assignType((p) => ({ builder: text(p), drizzleType: DrizzleTypesSQLite.text }), ["p", "", 'P"2!"/"']),
21
+ [FormatNames.email]: __assignType((p) => ({ builder: text(p), drizzleType: DrizzleTypesSQLite.text }), ["p", "", 'P"2!"/"']),
22
+ [FormatNames.url]: __assignType((p) => ({ builder: text(p), drizzleType: DrizzleTypesSQLite.text }), ["p", "", 'P"2!"/"']),
23
+ [FormatNames.domain]: __assignType((p) => ({ builder: text(p), drizzleType: DrizzleTypesSQLite.text }), ["p", "", 'P"2!"/"']),
24
+ [FormatNames.ip]: __assignType((p) => ({ builder: text(p), drizzleType: DrizzleTypesSQLite.text }), ["p", "", 'P"2!"/"']),
25
+ [FormatNames.dateTime]: __assignType((p) => ({ builder: text(p), drizzleType: DrizzleTypesSQLite.text }), ["p", "", 'P"2!"/"']),
26
+ [FormatNames.date]: __assignType((p) => ({ builder: text(p), drizzleType: DrizzleTypesSQLite.text }), ["p", "", 'P"2!"/"']),
27
+ [FormatNames.time]: __assignType((p) => ({ builder: text(p), drizzleType: DrizzleTypesSQLite.text }), ["p", "", 'P"2!"/"']),
28
+ [FormatNames.stringFormat]: __assignType((p) => ({ builder: text(p), drizzleType: DrizzleTypesSQLite.text }), ["p", "", 'P"2!"/"']),
29
+ [FormatNames.bigintFormat]: __assignType((p) => ({ builder: blob(p, { mode: "bigint" }), drizzleType: DrizzleTypesSQLite.blob }), ["p", "", 'P"2!"/"']),
30
+ [FormatNames.numberFormat]: __assignType((p, params) => {
31
+ if (isIntegerFormat(params))
32
+ return { builder: integer(p), drizzleType: DrizzleTypesSQLite.integer };
33
+ return { builder: real(p), drizzleType: DrizzleTypesSQLite.real };
34
+ }, ["p", "params", "", 'P"2!"2""/#'])
35
+ };
36
+ class SQLiteColumnMapper extends BaseColumnMapper {
37
+ constructor(config) {
38
+ super(config);
39
+ }
40
+ mapPrimitive(kind, propName) {
41
+ const factory = sqlitePrimitiveDefaults[kind];
42
+ if (!factory) {
43
+ throw new TypedError({
44
+ type: "drizzle-column-mapping-failed",
45
+ message: `Cannot map property "${propName}" to SQLite column. TypeScript primitive type "${ReflectionKind[kind]}" has no corresponding drizzle column type.`
46
+ });
47
+ }
48
+ return factory(propName);
49
+ }
50
+ mapFormat(formatName, formatParams, propName) {
51
+ const factory = sqliteFormatDefaults[formatName];
52
+ if (!factory)
53
+ return { builder: text(propName), drizzleType: DrizzleTypesSQLite.text };
54
+ return factory(propName, formatParams, { lengthBuffer: this.lengthBuffer });
55
+ }
56
+ mapArray(propName) {
57
+ return { builder: text(propName, { mode: "json" }), drizzleType: DrizzleTypesSQLite.text };
58
+ }
59
+ mapObject(propName) {
60
+ return { builder: text(propName, { mode: "json" }), drizzleType: DrizzleTypesSQLite.text };
61
+ }
62
+ mapDate(propName) {
63
+ return { builder: integer(propName, { mode: "timestamp" }), drizzleType: DrizzleTypesSQLite.integer };
64
+ }
65
+ static __type = [() => BaseColumnMapper, "DrizzleMapperConfig", "config", "constructor", () => ___ReflectionKind, "kind", "propName", "ColumnMapping", "mapPrimitive", () => ___FormatName, "formatName", () => __ΩRecord, "formatParams", "mapFormat", "mapArray", "mapObject", "mapDate", "SQLiteColumnMapper", `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`];
66
+ }
67
+ export {
68
+ SQLiteColumnMapper
69
+ };
70
+ //# sourceMappingURL=sqlite.mapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite.mapper.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,15 @@
1
+ import { MySqlTableWithColumns, MySqlColumnBuilderBase } from 'drizzle-orm/mysql-core';
2
+ import { BuildColumns } from 'drizzle-orm/column-builder';
3
+ import { ReceiveType } from '@deepkit/type';
4
+ import { MySqlTableConfig, MySqlColumnType } from './types/mysql.types.ts';
5
+ import { DrizzleMapperConfig, Nullable } from './types/common.types.ts';
6
+ type MergedMySqlColumns<T, TConfig> = {
7
+ [K in keyof T as K extends string ? K : never]-?: K extends keyof TConfig ? TConfig[K] extends MySqlColumnBuilderBase ? TConfig[K] : Nullable<T, K, MySqlColumnType<K & string, NonNullable<T[K]>>> : Nullable<T, K, MySqlColumnType<K & string, NonNullable<T[K]>>>;
8
+ };
9
+ export declare function toDrizzleMySqlTable<T, TN extends string = string, TConfig extends MySqlTableConfig<T> = {}>(tableName: TN, tableConfig?: TConfig, mapperConfig?: DrizzleMapperConfig, type?: ReceiveType<T>): MySqlTableWithColumns<{
10
+ name: TN;
11
+ schema: undefined;
12
+ columns: BuildColumns<TN, MergedMySqlColumns<T, TConfig>, 'mysql'>;
13
+ dialect: 'mysql';
14
+ }>;
15
+ export {};
@@ -0,0 +1,49 @@
1
+ import { mysqlTable } from "drizzle-orm/mysql-core";
2
+ import { TypedError } from "@mionjs/core";
3
+ import { extractTypeInfo } from "./core/typeTraverser.js";
4
+ import { validateConfig } from "./core/validator.js";
5
+ import { MySQLColumnMapper } from "./mappers/mysql.mapper.js";
6
+ const __ΩMergedMySqlColumns = ["T", "TConfig", "Nullable", "MergedMySqlColumns", `lre*"e&!fR"w#RPe)"e%!f!qk#+QR"w#RPe#!e'"gqk/>QRe$!R!RPe#!&qkPTQRPPde$!pBPde$!pVGRb!b"Pde"!gta#w$y`];
7
+ const DEFAULT_CONFIG = {};
8
+ function toDrizzleMySqlTable(tableName, tableConfig, mapperConfig = DEFAULT_CONFIG, type = toDrizzleMySqlTable.Ω?.[0]) {
9
+ toDrizzleMySqlTable.Ω = void 0;
10
+ if (!type) {
11
+ throw new TypedError({
12
+ type: "drizzle-table-missing-type",
13
+ message: "toDrizzleMySqlTable requires a type parameter. Usage: toDrizzleMySqlTable<YourType>(tableName) or toDrizzleMySqlTable<YourType>(tableName, tableConfig)"
14
+ });
15
+ }
16
+ const typeInfo = (extractTypeInfo.Ω = [[type, "n!"]], extractTypeInfo(type));
17
+ if (tableConfig) {
18
+ const validation = validateConfig(typeInfo, tableConfig);
19
+ if (!validation.valid) {
20
+ throw new TypedError({
21
+ type: "drizzle-table-config-invalid",
22
+ message: `Cannot create MySQL table "${tableName}". The provided tableConfig does not match type "${typeInfo.typeName}":
23
+ ${validation.errors.join("\n")}`
24
+ });
25
+ }
26
+ if (validation.warnings.length > 0) {
27
+ console.warn(`toDrizzleMySqlTable warnings:
28
+ ${validation.warnings.join("\n")}`);
29
+ }
30
+ }
31
+ const mapper = new MySQLColumnMapper(mapperConfig);
32
+ const __ΩMerged = [() => __ΩMergedMySqlColumns, type, () => tableConfig, "Merged", 'n"Pdi#h!!qe!!!jo!#w$y'];
33
+ const columns = {};
34
+ for (const prop of typeInfo.properties) {
35
+ const configKey = prop.name;
36
+ if (tableConfig && configKey in tableConfig) {
37
+ columns[prop.name] = tableConfig[configKey];
38
+ } else {
39
+ const mapping = mapper.mapProperty(prop);
40
+ columns[prop.name] = mapping.builder;
41
+ }
42
+ }
43
+ return mysqlTable.Ω = [[() => tableName, "Pdi!h!!qe!!!j"], [() => __ΩMerged, "n!"]], mysqlTable(tableName, columns);
44
+ }
45
+ toDrizzleMySqlTable.__type = ["tableName", "tableConfig", "DrizzleMapperConfig", "mapperConfig", () => DEFAULT_CONFIG, "ReceiveType", "type", "toDrizzleMySqlTable", `P"2!"2"8"w#2$>%"w&2'8!/(`];
46
+ export {
47
+ toDrizzleMySqlTable
48
+ };
49
+ //# sourceMappingURL=mysql.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mysql.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,15 @@
1
+ import { PgTableWithColumns, PgColumnBuilderBase } from 'drizzle-orm/pg-core';
2
+ import { BuildColumns } from 'drizzle-orm/column-builder';
3
+ import { ReceiveType } from '@deepkit/type';
4
+ import { PgTableConfig, PgColumnType } from './types/postgres.types.ts';
5
+ import { DrizzleMapperConfig, Nullable } from './types/common.types.ts';
6
+ type MergedPgColumns<T, TConfig> = {
7
+ [K in keyof T as K extends string ? K : never]-?: K extends keyof TConfig ? TConfig[K] extends PgColumnBuilderBase ? TConfig[K] : Nullable<T, K, PgColumnType<K & string, NonNullable<T[K]>>> : Nullable<T, K, PgColumnType<K & string, NonNullable<T[K]>>>;
8
+ };
9
+ export declare function toDrizzlePGTable<T, TN extends string = string, TConfig extends PgTableConfig<T> = {}>(tableName: TN, tableConfig?: TConfig, mapperConfig?: DrizzleMapperConfig, type?: ReceiveType<T>): PgTableWithColumns<{
10
+ name: TN;
11
+ schema: undefined;
12
+ columns: BuildColumns<TN, MergedPgColumns<T, TConfig>, 'pg'>;
13
+ dialect: 'pg';
14
+ }>;
15
+ export {};
@@ -0,0 +1,49 @@
1
+ import { pgTable } from "drizzle-orm/pg-core";
2
+ import { TypedError } from "@mionjs/core";
3
+ import { extractTypeInfo } from "./core/typeTraverser.js";
4
+ import { validateConfig } from "./core/validator.js";
5
+ import { PGColumnMapper } from "./mappers/pg.mapper.js";
6
+ const __ΩMergedPgColumns = ["T", "TConfig", "Nullable", "MergedPgColumns", `lre*"e&!fR"w#RPe)"e%!f!qk#+QR"w#RPe#!e'"gqk/>QRe$!R!RPe#!&qkPTQRPPde$!pBPde$!pVGRb!b"Pde"!gta#w$y`];
7
+ const DEFAULT_CONFIG = {};
8
+ function toDrizzlePGTable(tableName, tableConfig, mapperConfig = DEFAULT_CONFIG, type = toDrizzlePGTable.Ω?.[0]) {
9
+ toDrizzlePGTable.Ω = void 0;
10
+ if (!type) {
11
+ throw new TypedError({
12
+ type: "drizzle-table-missing-type",
13
+ message: "toDrizzlePGTable requires a type parameter. Usage: toDrizzlePGTable<YourType>(tableName) or toDrizzlePGTable<YourType>(tableName, tableConfig)"
14
+ });
15
+ }
16
+ const typeInfo = (extractTypeInfo.Ω = [[type, "n!"]], extractTypeInfo(type));
17
+ if (tableConfig) {
18
+ const validation = validateConfig(typeInfo, tableConfig);
19
+ if (!validation.valid) {
20
+ throw new TypedError({
21
+ type: "drizzle-table-config-invalid",
22
+ message: `Cannot create PostgreSQL table "${tableName}". The provided tableConfig does not match type "${typeInfo.typeName}":
23
+ ${validation.errors.join("\n")}`
24
+ });
25
+ }
26
+ if (validation.warnings.length > 0) {
27
+ console.warn(`toDrizzlePGTable warnings:
28
+ ${validation.warnings.join("\n")}`);
29
+ }
30
+ }
31
+ const mapper = new PGColumnMapper(mapperConfig);
32
+ const __ΩMerged = [() => __ΩMergedPgColumns, type, () => tableConfig, "Merged", 'n"Pdi#h!!qe!!!jo!#w$y'];
33
+ const columns = {};
34
+ for (const prop of typeInfo.properties) {
35
+ const configKey = prop.name;
36
+ if (tableConfig && configKey in tableConfig) {
37
+ columns[prop.name] = tableConfig[configKey];
38
+ } else {
39
+ const mapping = mapper.mapProperty(prop);
40
+ columns[prop.name] = mapping.builder;
41
+ }
42
+ }
43
+ return pgTable.Ω = [[() => tableName, "Pdi!h!!qe!!!j"], [() => __ΩMerged, "n!"]], pgTable(tableName, columns);
44
+ }
45
+ toDrizzlePGTable.__type = ["tableName", "tableConfig", "DrizzleMapperConfig", "mapperConfig", () => DEFAULT_CONFIG, "ReceiveType", "type", "toDrizzlePGTable", `P"2!"2"8"w#2$>%"w&2'8!/(`];
46
+ export {
47
+ toDrizzlePGTable
48
+ };
49
+ //# sourceMappingURL=postgres.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,15 @@
1
+ import { SQLiteTableWithColumns, SQLiteColumnBuilderBase } from 'drizzle-orm/sqlite-core';
2
+ import { BuildColumns } from 'drizzle-orm/column-builder';
3
+ import { ReceiveType } from '@deepkit/type';
4
+ import { SqliteTableConfig, SqliteColumnType } from './types/sqlite.types.ts';
5
+ import { DrizzleMapperConfig, Nullable } from './types/common.types.ts';
6
+ type MergedSqliteColumns<T, TConfig> = {
7
+ [K in keyof T as K extends string ? K : never]-?: K extends keyof TConfig ? TConfig[K] extends SQLiteColumnBuilderBase ? TConfig[K] : Nullable<T, K, SqliteColumnType<K & string, NonNullable<T[K]>>> : Nullable<T, K, SqliteColumnType<K & string, NonNullable<T[K]>>>;
8
+ };
9
+ export declare function toDrizzleSqliteTable<T, TN extends string = string, TConfig extends SqliteTableConfig<T> = {}>(tableName: TN, tableConfig?: TConfig, mapperConfig?: DrizzleMapperConfig, type?: ReceiveType<T>): SQLiteTableWithColumns<{
10
+ name: TN;
11
+ schema: undefined;
12
+ columns: BuildColumns<TN, MergedSqliteColumns<T, TConfig>, 'sqlite'>;
13
+ dialect: 'sqlite';
14
+ }>;
15
+ export {};
@@ -0,0 +1,49 @@
1
+ import { sqliteTable } from "drizzle-orm/sqlite-core";
2
+ import { TypedError } from "@mionjs/core";
3
+ import { extractTypeInfo } from "./core/typeTraverser.js";
4
+ import { validateConfig } from "./core/validator.js";
5
+ import { SQLiteColumnMapper } from "./mappers/sqlite.mapper.js";
6
+ const __ΩMergedSqliteColumns = ["T", "TConfig", "Nullable", "MergedSqliteColumns", `lre*"e&!fR"w#RPe)"e%!f!qk#+QR"w#RPe#!e'"gqk/>QRe$!R!RPe#!&qkPTQRPPde$!pBPde$!pVGRb!b"Pde"!gta#w$y`];
7
+ const DEFAULT_CONFIG = {};
8
+ function toDrizzleSqliteTable(tableName, tableConfig, mapperConfig = DEFAULT_CONFIG, type = toDrizzleSqliteTable.Ω?.[0]) {
9
+ toDrizzleSqliteTable.Ω = void 0;
10
+ if (!type) {
11
+ throw new TypedError({
12
+ type: "drizzle-table-missing-type",
13
+ message: "toDrizzleSqliteTable requires a type parameter. Usage: toDrizzleSqliteTable<YourType>(tableName) or toDrizzleSqliteTable<YourType>(tableName, tableConfig)"
14
+ });
15
+ }
16
+ const typeInfo = (extractTypeInfo.Ω = [[type, "n!"]], extractTypeInfo(type));
17
+ if (tableConfig) {
18
+ const validation = validateConfig(typeInfo, tableConfig);
19
+ if (!validation.valid) {
20
+ throw new TypedError({
21
+ type: "drizzle-table-config-invalid",
22
+ message: `Cannot create SQLite table "${tableName}". The provided tableConfig does not match type "${typeInfo.typeName}":
23
+ ${validation.errors.join("\n")}`
24
+ });
25
+ }
26
+ if (validation.warnings.length > 0) {
27
+ console.warn(`toDrizzleSqliteTable warnings:
28
+ ${validation.warnings.join("\n")}`);
29
+ }
30
+ }
31
+ const mapper = new SQLiteColumnMapper(mapperConfig);
32
+ const __ΩMerged = [() => __ΩMergedSqliteColumns, type, () => tableConfig, "Merged", 'n"Pdi#h!!qe!!!jo!#w$y'];
33
+ const columns = {};
34
+ for (const prop of typeInfo.properties) {
35
+ const configKey = prop.name;
36
+ if (tableConfig && configKey in tableConfig) {
37
+ columns[prop.name] = tableConfig[configKey];
38
+ } else {
39
+ const mapping = mapper.mapProperty(prop);
40
+ columns[prop.name] = mapping.builder;
41
+ }
42
+ }
43
+ return sqliteTable.Ω = [[() => tableName, "Pdi!h!!qe!!!j"], [() => __ΩMerged, "n!"]], sqliteTable(tableName, columns);
44
+ }
45
+ toDrizzleSqliteTable.__type = ["tableName", "tableConfig", "DrizzleMapperConfig", "mapperConfig", () => DEFAULT_CONFIG, "ReceiveType", "type", "toDrizzleSqliteTable", `P"2!"2"8"w#2$>%"w&2'8!/(`];
46
+ export {
47
+ toDrizzleSqliteTable
48
+ };
49
+ //# sourceMappingURL=sqlite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,28 @@
1
+ import { FormatUUIDv7, FormatEmail } from '@mionjs/type-formats/StringFormats';
2
+ import { FormatInteger, FormatPositiveInt } from '@mionjs/type-formats/NumberFormats';
3
+ export interface User {
4
+ id: FormatUUIDv7;
5
+ email: FormatEmail;
6
+ name: string;
7
+ age: FormatInteger;
8
+ score: FormatPositiveInt;
9
+ tags: string[];
10
+ profile: {
11
+ avatar: string;
12
+ theme: string;
13
+ };
14
+ }
15
+ export interface Post {
16
+ id: FormatUUIDv7;
17
+ authorId: FormatUUIDv7;
18
+ title: string;
19
+ views: FormatPositiveInt;
20
+ }
21
+ export interface UserWithOptional {
22
+ id: FormatUUIDv7;
23
+ name: string;
24
+ bio?: string;
25
+ }
26
+ export declare type __ΩUser = any[];
27
+ export declare type __ΩPost = any[];
28
+ export declare type __ΩUserWithOptional = any[];
@@ -0,0 +1,11 @@
1
+ import { __ΩFormatUUIDv7 as ___FormatUUIDv7, __ΩFormatEmail as ___FormatEmail } from "@mionjs/type-formats/StringFormats";
2
+ import { __ΩFormatPositiveInt as ___FormatPositiveInt, __ΩFormatInteger as ___FormatInteger } from "@mionjs/type-formats/NumberFormats";
3
+ const __ΩUser = [() => ___FormatUUIDv7, "id", () => ___FormatEmail, "email", "name", () => ___FormatInteger, "age", () => ___FormatPositiveInt, "score", "tags", "avatar", "theme", "profile", "User", `Pn!4"n#4$&4%n&4'n(4)&F4*P&4+&4,M4-Mw.y`];
4
+ const __ΩPost = [() => ___FormatUUIDv7, "id", () => ___FormatUUIDv7, "authorId", "title", () => ___FormatPositiveInt, "views", "Post", `Pn!4"n#4$&4%n&4'Mw(y`];
5
+ const __ΩUserWithOptional = [() => ___FormatUUIDv7, "id", "name", "bio", "UserWithOptional", 'Pn!4"&4#&4$8Mw%y'];
6
+ export {
7
+ __ΩPost,
8
+ __ΩUser,
9
+ __ΩUserWithOptional
10
+ };
11
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
@@ -0,0 +1,8 @@
1
+ import "drizzle-orm";
2
+ import { toDrizzleMySqlTable } from "../mysql.js";
3
+ import "@mionjs/type-formats/StringFormats";
4
+ import { __ΩPost as ___Post, __ΩUserWithOptional as ___UserWithOptional, __ΩUser as ___User } from "./common.js";
5
+ toDrizzleMySqlTable.Ω = [[() => ___User, "n!"]], toDrizzleMySqlTable("users");
6
+ toDrizzleMySqlTable.Ω = [[() => ___Post, "n!"]], toDrizzleMySqlTable("posts");
7
+ toDrizzleMySqlTable.Ω = [[() => ___UserWithOptional, "n!"]], toDrizzleMySqlTable("optional_users");
8
+ //# sourceMappingURL=mysql.stub.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mysql.stub.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
@@ -0,0 +1,8 @@
1
+ import "drizzle-orm";
2
+ import { toDrizzlePGTable } from "../postgres.js";
3
+ import "@mionjs/type-formats/StringFormats";
4
+ import { __ΩPost as ___Post, __ΩUserWithOptional as ___UserWithOptional, __ΩUser as ___User } from "./common.js";
5
+ toDrizzlePGTable.Ω = [[() => ___User, "n!"]], toDrizzlePGTable("users");
6
+ toDrizzlePGTable.Ω = [[() => ___Post, "n!"]], toDrizzlePGTable("posts");
7
+ toDrizzlePGTable.Ω = [[() => ___UserWithOptional, "n!"]], toDrizzlePGTable("optional_users");
8
+ //# sourceMappingURL=postgres.stub.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres.stub.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
@@ -0,0 +1,8 @@
1
+ import "drizzle-orm";
2
+ import { toDrizzleSqliteTable } from "../sqlite.js";
3
+ import "@mionjs/type-formats/StringFormats";
4
+ import { __ΩPost as ___Post, __ΩUserWithOptional as ___UserWithOptional, __ΩUser as ___User } from "./common.js";
5
+ toDrizzleSqliteTable.Ω = [[() => ___User, "n!"]], toDrizzleSqliteTable("users");
6
+ toDrizzleSqliteTable.Ω = [[() => ___Post, "n!"]], toDrizzleSqliteTable("posts");
7
+ toDrizzleSqliteTable.Ω = [[() => ___UserWithOptional, "n!"]], toDrizzleSqliteTable("optional_users");
8
+ //# sourceMappingURL=sqlite.stub.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite.stub.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
@@ -0,0 +1,118 @@
1
+ import { BaseRunType } from '@mionjs/run-types';
2
+ import { ReflectionKind } from '@deepkit/type';
3
+ import { BrandEmail, BrandUUID, BrandUrl, BrandDomain, BrandIP, BrandDate, BrandTime, BrandDateTime, BrandInteger, BrandFloat, BrandPositive, BrandNegative, BrandPositiveInt, BrandNegativeInt, BrandInt8, BrandInt16, BrandInt32, BrandUInt8, BrandUInt16, BrandUInt32 } from '@mionjs/core';
4
+ export type DatabaseType = 'postgres' | 'mysql' | 'sqlite';
5
+ type ExtractBrandName<T> = T extends {
6
+ brand: infer B extends string;
7
+ } ? B : never;
8
+ export type AllBrandNames = ExtractBrandName<BrandEmail> | ExtractBrandName<BrandUUID> | ExtractBrandName<BrandUrl> | ExtractBrandName<BrandDomain> | ExtractBrandName<BrandIP> | ExtractBrandName<BrandDate> | ExtractBrandName<BrandTime> | ExtractBrandName<BrandDateTime> | ExtractBrandName<BrandInteger> | ExtractBrandName<BrandFloat> | ExtractBrandName<BrandPositive> | ExtractBrandName<BrandNegative> | ExtractBrandName<BrandPositiveInt> | ExtractBrandName<BrandNegativeInt> | ExtractBrandName<BrandInt8> | ExtractBrandName<BrandInt16> | ExtractBrandName<BrandInt32> | ExtractBrandName<BrandUInt8> | ExtractBrandName<BrandUInt16> | ExtractBrandName<BrandUInt32>;
9
+ export declare const DrizzleTypesPostgres: {
10
+ readonly text: "text";
11
+ readonly boolean: "boolean";
12
+ readonly bigint: "bigint";
13
+ readonly varchar: "varchar";
14
+ readonly date: "date";
15
+ readonly time: "time";
16
+ readonly timestamp: "timestamp";
17
+ readonly integer: "integer";
18
+ readonly doublePrecision: "doublePrecision";
19
+ readonly uuid: "uuid";
20
+ readonly inet: "inet";
21
+ readonly char: "char";
22
+ readonly jsonb: "jsonb";
23
+ };
24
+ export declare const DrizzleTypesMySQL: {
25
+ readonly text: "text";
26
+ readonly boolean: "boolean";
27
+ readonly bigint: "bigint";
28
+ readonly varchar: "varchar";
29
+ readonly date: "date";
30
+ readonly time: "time";
31
+ readonly timestamp: "timestamp";
32
+ readonly json: "json";
33
+ readonly double: "double";
34
+ readonly int: "int";
35
+ readonly datetime: "datetime";
36
+ };
37
+ export declare const DrizzleTypesSQLite: {
38
+ readonly text: "text";
39
+ readonly integer: "integer";
40
+ readonly real: "real";
41
+ readonly blob: "blob";
42
+ };
43
+ export declare const DrizzleTypes: {
44
+ readonly text: "text";
45
+ readonly integer: "integer";
46
+ readonly real: "real";
47
+ readonly blob: "blob";
48
+ readonly boolean: "boolean";
49
+ readonly bigint: "bigint";
50
+ readonly varchar: "varchar";
51
+ readonly date: "date";
52
+ readonly time: "time";
53
+ readonly timestamp: "timestamp";
54
+ readonly json: "json";
55
+ readonly double: "double";
56
+ readonly int: "int";
57
+ readonly datetime: "datetime";
58
+ readonly doublePrecision: "doublePrecision";
59
+ readonly uuid: "uuid";
60
+ readonly inet: "inet";
61
+ readonly char: "char";
62
+ readonly jsonb: "jsonb";
63
+ };
64
+ export type DrizzleTypePostgres = (typeof DrizzleTypesPostgres)[keyof typeof DrizzleTypesPostgres];
65
+ export type DrizzleTypeMySQL = (typeof DrizzleTypesMySQL)[keyof typeof DrizzleTypesMySQL];
66
+ export type DrizzleTypeSQLite = (typeof DrizzleTypesSQLite)[keyof typeof DrizzleTypesSQLite];
67
+ export type DrizzleType = (typeof DrizzleTypes)[keyof typeof DrizzleTypes];
68
+ export interface ColumnMapping {
69
+ builder: any;
70
+ drizzleType: DrizzleType;
71
+ }
72
+ export type PrimitiveColumnFactory = (propName: string) => ColumnMapping;
73
+ export type FormatColumnFactory = (propName: string, formatParams?: Record<string, any>, config?: DrizzleMapperConfig) => ColumnMapping;
74
+ export interface PropertyInfo {
75
+ name: string;
76
+ runType: BaseRunType;
77
+ isOptional: boolean;
78
+ isNestedObject: boolean;
79
+ isArray: boolean;
80
+ isDate: boolean;
81
+ formatName?: string;
82
+ formatParams?: Record<string, any>;
83
+ primitiveKind?: ReflectionKind;
84
+ }
85
+ export interface TypeInfo {
86
+ typeName: string;
87
+ properties: PropertyInfo[];
88
+ }
89
+ export interface ValidationResult {
90
+ valid: boolean;
91
+ errors: string[];
92
+ warnings: string[];
93
+ }
94
+ export declare const DEFAULT_VARCHAR_LENGTH = 255;
95
+ export declare const DEFAULT_LENGTH_BUFFER = 1.5;
96
+ export interface DrizzleMapperConfig {
97
+ lengthBuffer?: number;
98
+ }
99
+ export type Nullable<T, K extends keyof T, Col> = {} extends Pick<T, K> ? Col : Col & {
100
+ _: {
101
+ notNull: true;
102
+ };
103
+ };
104
+ export {};
105
+ export declare type __ΩDatabaseType = any[];
106
+ export declare type __ΩAllBrandNames = any[];
107
+ export declare type __ΩDrizzleTypePostgres = any[];
108
+ export declare type __ΩDrizzleTypeMySQL = any[];
109
+ export declare type __ΩDrizzleTypeSQLite = any[];
110
+ export declare type __ΩDrizzleType = any[];
111
+ export declare type __ΩColumnMapping = any[];
112
+ export declare type __ΩPrimitiveColumnFactory = any[];
113
+ export declare type __ΩFormatColumnFactory = any[];
114
+ export declare type __ΩPropertyInfo = any[];
115
+ export declare type __ΩTypeInfo = any[];
116
+ export declare type __ΩValidationResult = any[];
117
+ export declare type __ΩDrizzleMapperConfig = any[];
118
+ export declare type __ΩNullable = any[];