@mionjs/drizzle 0.8.0-alpha.0 → 0.8.4-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.
- package/.dist/esm/src/core/typeTraverser.js.map +1 -1
- package/.dist/esm/src/core/utils.js.map +1 -1
- package/.dist/esm/src/core/validator.js.map +1 -1
- package/.dist/esm/src/mappers/base.mapper.js.map +1 -1
- package/.dist/esm/src/mappers/mysql.mapper.js.map +1 -1
- package/.dist/esm/src/mappers/pg.mapper.js.map +1 -1
- package/.dist/esm/src/mappers/sqlite.mapper.js.map +1 -1
- package/.dist/esm/src/mysql.js.map +1 -1
- package/.dist/esm/src/postgres.js.map +1 -1
- package/.dist/esm/src/sqlite.js.map +1 -1
- package/.dist/esm/src/stubs-formats-mappings/mysql.stub.js.map +1 -1
- package/.dist/esm/src/stubs-formats-mappings/postgres.stub.js.map +1 -1
- package/.dist/esm/src/stubs-formats-mappings/sqlite.stub.js.map +1 -1
- package/.dist/esm/src/types/common.types.js.map +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeTraverser.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"typeTraverser.js","sources":["../../../../src/core/typeTraverser.ts"],"sourcesContent":["/* ########\n * 2025 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {runType, getRunTypeFormat, isInterfaceRunType, isPropertyRunType, isPropertySignatureRunType} from '@mionjs/run-types';\nimport type {BaseRunType, InterfaceRunType, PropertyRunType} from '@mionjs/run-types';\nimport {ReflectionKind, type ReceiveType} from '@deepkit/type';\nimport {TypedError} from '@mionjs/core';\nimport type {PropertyInfo, TypeInfo} from '../types/common.types.ts';\n\n/** Extracts property information from a TypeScript type using mion's RunType system */\nexport function extractTypeInfo<T>(type?: ReceiveType<T>): TypeInfo {\n const rt = runType(type) as BaseRunType;\n\n // Must be an interface/object type\n if (!isInterfaceRunType(rt)) {\n throw new TypedError({\n type: 'drizzle-table-invalid-source-type',\n message: `Cannot create drizzle table from type \"${rt.getKindName()}\". Expected an interface or object type with properties to map to table columns.`,\n });\n }\n\n const interfaceRt = rt as InterfaceRunType;\n const properties: PropertyInfo[] = [];\n\n // Get all property children\n const children = interfaceRt.getChildRunTypes();\n\n for (const child of children) {\n if (isPropertyRunType(child) || isPropertySignatureRunType(child)) {\n const propRt = child as PropertyRunType;\n const memberType = propRt.getMemberType() as BaseRunType;\n const propInfo = extractPropertyInfo(propRt, memberType);\n properties.push(propInfo);\n }\n }\n\n return {\n typeName: rt.getTypeName(),\n properties,\n };\n}\n\n/** Extracts information about a single property */\nfunction extractPropertyInfo(propRt: PropertyRunType, memberType: BaseRunType): PropertyInfo {\n const kind = memberType.src.kind;\n const formatInfo = getFormatInfo(memberType);\n const isDate = checkIsDateType(memberType);\n\n return {\n name: propRt.getPropertyName() as string,\n runType: memberType,\n isOptional: propRt.isOptional(),\n isNestedObject: isNestedObjectType(kind) && !isDate,\n isArray: kind === ReflectionKind.array,\n isDate,\n formatName: formatInfo?.name,\n formatParams: formatInfo?.params,\n primitiveKind: isPrimitiveKind(kind) ? kind : undefined,\n };\n}\n\n/** Checks if a ReflectionKind represents a nested object type */\nfunction isNestedObjectType(kind: ReflectionKind): boolean {\n return kind === ReflectionKind.objectLiteral || kind === ReflectionKind.class;\n}\n\n/** Checks if a ReflectionKind represents a primitive type */\nfunction isPrimitiveKind(kind: ReflectionKind): boolean {\n return (\n kind === ReflectionKind.string ||\n kind === ReflectionKind.number ||\n kind === ReflectionKind.boolean ||\n kind === ReflectionKind.bigint\n );\n}\n\n/** Gets format information from a RunType if it has a format annotation */\nfunction getFormatInfo(rt: BaseRunType): {name: string; params: Record<string, any>} | undefined {\n const format = getRunTypeFormat(rt);\n if (!format) return undefined;\n\n return {\n name: format.name,\n params: format.getParams(rt),\n };\n}\n\n/** Checks if a type is a Date type by examining the class name */\nfunction checkIsDateType(rt: BaseRunType): boolean {\n if (rt.src.kind !== ReflectionKind.class) return false;\n // Check if the class is Date by looking at the type name or classType\n const src = rt.src as any;\n if (src.classType === Date) return true;\n // Also check the type name\n const typeName = rt.getTypeName();\n return typeName === 'Date';\n}\n\n/** Checks if a type is a Date type */\nexport function isDateType(kind: ReflectionKind): boolean {\n return kind === ReflectionKind.class; // Date is a class type\n}\n\n/** Gets the underlying type kind, unwrapping unions with null/undefined */\nexport function getUnderlyingKind(rt: BaseRunType): ReflectionKind {\n const kind = rt.src.kind;\n\n // Handle union types (e.g., string | null)\n if (kind === ReflectionKind.union) {\n const children = (rt as any).getChildRunTypes?.() || [];\n for (const child of children) {\n const childKind = (child as BaseRunType).src.kind;\n // Skip null and undefined\n if (childKind !== ReflectionKind.null && childKind !== ReflectionKind.undefined) {\n return childKind;\n }\n }\n }\n\n return kind;\n}\n"],"names":[],"mappings":";;;;AAcM,SAAU,gBAAmB,OAAnB,gBAAe,IAAA,CAAA,GAAyB;AAAxC,kBAAe,IAAA;AAC3B,QAAM,KAAK,QAAQ,IAAI;AAGvB,MAAI,CAAC,mBAAmB,EAAE,GAAG;AACzB,UAAM,IAAI,WAAW;AAAA,MACjB,MAAM;AAAA,MACN,SAAS,0CAA0C,GAAG,YAAA,CAAa;AAAA,IAAA,CACtE;AAAA,EACL;AAEA,QAAM,cAAc;AACpB,QAAM,aAA6B,CAAA;AAGnC,QAAM,WAAW,YAAY,iBAAA;AAE7B,aAAW,SAAS,UAAU;AAC1B,QAAI,kBAAkB,KAAK,KAAK,2BAA2B,KAAK,GAAG;AAC/D,YAAM,SAAS;AACf,YAAM,aAAa,OAAO,cAAA;AAC1B,YAAM,WAAW,oBAAoB,QAAQ,UAAU;AACvD,iBAAW,KAAK,QAAQ;AAAA,IAC5B;AAAA,EACJ;AAEA,SAAO;AAAA,IACH,UAAU,GAAG,YAAA;AAAA,IACb;AAAA,EAAA;AAEP;;AAGD,SAAS,oBAAoB,QAAyB,YAAuB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AQ,cAAc,eAAe,WAAW;AAC7E,eAAO;AAAA,MACX;AAAA,IACJ;AAAA,EACJ;AAEA,SAAO;AACX;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../src/core/utils.ts"],"sourcesContent":["/* ########\n * 2025 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {ReflectionKind} from '@deepkit/type';\nimport type {PropertyInfo} from '../types/common.types.ts';\n\n/** Converts a camelCase property name to snake_case for database column names */\nexport function toSnakeCase(str: string): string {\n return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);\n}\n\n/** Checks if a property should be stored as JSON (nested object or array) */\nexport function shouldBeJson(prop: PropertyInfo): boolean {\n return prop.isNestedObject || prop.isArray;\n}\n\n/** Gets the format param value, handling both simple values and objects with val property */\nexport function getParamValue<T>(param: T | {val: T}): T {\n if (param && typeof param === 'object' && 'val' in param) {\n return param.val;\n }\n return param as T;\n}\n\n/** Checks if a type is a Date class */\nexport function isDateClass(kind: ReflectionKind, typeName?: string): boolean {\n return kind === ReflectionKind.class && typeName === 'Date';\n}\n\n/** Gets the max length from format params if available */\nexport function getMaxLengthFromParams(formatParams?: Record<string, any>): number | undefined {\n if (!formatParams) return undefined;\n const maxLength = formatParams.maxLength;\n return maxLength ? getParamValue(maxLength) : undefined;\n}\n\n/** Gets the exact length from format params if available */\nexport function getLengthFromParams(formatParams?: Record<string, any>): number | undefined {\n if (!formatParams) return undefined;\n const length = formatParams.length;\n return length ? getParamValue(length) : undefined;\n}\n\n/** Checks if a number format specifies integer constraint */\nexport function isIntegerFormat(formatParams?: Record<string, any>): boolean {\n if (!formatParams) return false;\n return !!getParamValue(formatParams.integer);\n}\n\n/** Checks if a number format specifies float constraint */\nexport function isFloatFormat(formatParams?: Record<string, any>): boolean {\n if (!formatParams) return false;\n return !!getParamValue(formatParams.float);\n}\n"],"names":[],"mappings":";;;;;;AAWM,SAAU,YAAY,KAAW;AACnC,SAAO,IAAI,QAAQ,UAAQ,aAAE,CAAC,WAAW,IAAI,OAAO,YAAA,CAAa;AACrE;;AAGM,SAAU,aAAa,MAAkB;AAC3C,SAAO,KAAK,kBAAkB,KAAK;AACvC;;AAGM,SAAU,cAAiB,OAAmB;AAChD,MAAI,SAAS,OAAO,UAAU,YAAY,SAAS,OAAO;AACtD,WAAO,MAAM;AAAA,EACjB;AACA,SAAO;AACX;;AAGM,SAAU,YAAY,MAAsB,UAAiB;AAC/D,SAAO,SAAS,eAAe,SAAS,aAAa;AACzD;;AAGM,SAAU,uBAAuB,cAAkC;AACrE,MAAI,CAAC;AAAc,WAAO;AAC1B,QAAM,YAAY,aAAa;AAC/B,SAAO,YAAY,cAAc,SAAS,IAAI;AAClD;;AAGM,SAAU,oBAAoB,cAAkC;AAClE,MAAI,CAAC;AAAc,WAAO;AAC1B,QAAM,SAAS,aAAa;AAC5B,SAAO,SAAS,cAAc,MAAM,IAAI;AAC5C;;AAGM,SAAU,gBAAgB,cAAkC;AAC9D,MAAI,CAAC;AAAc,WAAO;AAC1B,SAAO,CAAC,CAAC,cAAc,aAAa,OAAO;AAC/C;;AAGM,SAAU,cAAc,cAAkC;AAC5D,MAAI,CAAC;AAAc,WAAO;AAC1B,SAAO,CAAC,CAAC,cAAc,aAAa,KAAK;AAC7C;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"validator.js","sources":["../../../../src/core/validator.ts"],"sourcesContent":["/* ########\n * 2025 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {ReflectionKind} from '@deepkit/type';\nimport type {PropertyInfo, TypeInfo, ValidationResult} from '../types/common.types.ts';\n\n/** Validates that provided table config matches the TypeScript type */\nexport function validateConfig(typeInfo: TypeInfo, tableConfig: Record<string, any>): ValidationResult {\n const errors: string[] = [];\n const warnings: string[] = [];\n for (const prop of typeInfo.properties) {\n const configColumn = tableConfig[prop.name];\n // Column not in config - will be auto-generated\n if (!configColumn) continue;\n // Validate type compatibility\n const typeError = validateTypeCompatibility(prop, configColumn);\n if (typeError) errors.push(typeError);\n // Validate nullability\n const nullError = validateNullability(prop, configColumn);\n if (nullError) errors.push(nullError);\n // Validate format constraints\n const formatWarning = validateFormatConstraints(prop, configColumn);\n if (formatWarning) warnings.push(formatWarning);\n }\n // Check for extra columns in config that don't exist in type\n for (const configKey of Object.keys(tableConfig)) {\n const exists = typeInfo.properties.some((p) => p.name === configKey);\n if (!exists) errors.push(`Column \"${configKey}\" exists in tableConfig but not in type \"${typeInfo.typeName}\"`);\n }\n return {valid: errors.length === 0, errors, warnings};\n}\n\n/** Validates that the drizzle column type is compatible with the TypeScript type */\nfunction validateTypeCompatibility(prop: PropertyInfo, column: any): string | null {\n const columnType = getColumnType(column);\n const expectedTypes = getExpectedColumnTypes(prop);\n if (expectedTypes.length > 0 && !expectedTypes.includes(columnType)) {\n return `Type mismatch for property \"${prop.name}\": TypeScript type expects ${expectedTypes.join(' or ')}, but drizzle column is \"${columnType}\"`;\n }\n return null;\n}\n\n/** Validates that nullability constraints match */\nfunction validateNullability(prop: PropertyInfo, column: any): string | null {\n const isColumnNotNull = hasNotNullConstraint(column);\n if (prop.isOptional && isColumnNotNull)\n return `Property \"${prop.name}\" is optional in type but column has .notNull() constraint`;\n return null;\n}\n\n/** Validates format constraints (warnings only) */\nfunction validateFormatConstraints(prop: PropertyInfo, column: any): string | null {\n if (!prop.formatParams) return null;\n // Check maxLength constraint\n if (prop.formatParams.maxLength) {\n const columnLength = getColumnLength(column);\n if (columnLength && columnLength < prop.formatParams.maxLength) {\n return `Column \"${prop.name}\" has length ${columnLength} but type format requires maxLength ${prop.formatParams.maxLength}`;\n }\n }\n return null;\n}\n\n/** Gets the drizzle column type from a column builder */\nfunction getColumnType(column: any): string {\n // Drizzle columns have internal type info\n // Try different properties that might contain the type\n if (column.dataType) return column.dataType;\n if (column.columnType) return column.columnType;\n if (column._ && column._.dataType) return column._.dataType;\n // Check config object (used by column builders)\n if (column.config && column.config.dataType) return column.config.dataType;\n if (column.config && column.config.columnType) return column.config.columnType;\n // Check constructor name for column builders\n if (column.constructor && column.constructor.name) {\n const name = column.constructor.name;\n // Map constructor names to data types\n if (name.includes('UUID')) return 'string';\n if (name.includes('Text')) return 'string';\n if (name.includes('Varchar')) return 'string';\n if (name.includes('Char')) return 'string';\n if (name.includes('Integer') || name.includes('Int')) return 'number';\n if (name.includes('Boolean')) return 'boolean';\n if (name.includes('Timestamp') || name.includes('Date')) return 'date';\n if (name.includes('Json')) return 'json';\n if (name.includes('Double') || name.includes('Real') || name.includes('Float')) return 'number';\n if (name.includes('BigInt')) return 'bigint';\n }\n return 'unknown';\n}\n\n/** Checks if a column has a notNull constraint */\nfunction hasNotNullConstraint(column: any): boolean {\n if (column.notNull === true) return true;\n if (column._ && column._.notNull === true) return true;\n return false;\n}\n\n/** Gets the length constraint from a column if it has one */\nfunction getColumnLength(column: any): number | null {\n if (column.length) return column.length;\n if (column._ && column._.length) return column._.length;\n return null;\n}\n\n/** Gets the expected drizzle column types for a TypeScript property */\nfunction getExpectedColumnTypes(prop: PropertyInfo): string[] {\n // If it's a nested object or array, expect JSON types\n if (prop.isNestedObject || prop.isArray) return ['json', 'jsonb', 'text'];\n // Check format-specific types\n if (prop.formatName) return getExpectedTypesForFormat(prop.formatName);\n // Check primitive types\n if (prop.primitiveKind !== undefined) return getExpectedTypesForPrimitive(prop.primitiveKind);\n // Check for Date type\n const kind = prop.runType.src.kind;\n if (kind === ReflectionKind.class) {\n // Could be Date or other class\n const typeName = prop.runType.getTypeName();\n if (typeName === 'Date') return ['timestamp', 'date', 'datetime', 'integer', 'text'];\n }\n\n return [];\n}\n\n/** Gets expected column types for a format name */\nfunction getExpectedTypesForFormat(formatName: string): string[] {\n switch (formatName) {\n case 'uuid':\n return ['uuid', 'varchar', 'text'];\n case 'email':\n return ['text', 'varchar'];\n case 'url':\n return ['text', 'varchar'];\n case 'ip':\n return ['inet', 'varchar', 'text'];\n case 'date':\n return ['date', 'text'];\n case 'time':\n return ['time', 'text'];\n case 'dateTime':\n return ['timestamp', 'datetime', 'text'];\n case 'numberFormat':\n return ['integer', 'int', 'smallint', 'bigint', 'real', 'double', 'doublePrecision', 'numeric', 'decimal'];\n case 'bigIntFormat':\n return ['bigint', 'blob'];\n default:\n return [];\n }\n}\n\n/** Gets expected column types for a primitive kind */\nfunction getExpectedTypesForPrimitive(kind: ReflectionKind): string[] {\n switch (kind) {\n case ReflectionKind.string:\n // 'string' is the dataType returned by drizzle for text-based columns\n return ['text', 'varchar', 'char', 'uuid', 'inet', 'string'];\n case ReflectionKind.number:\n // 'number' is the dataType returned by drizzle for numeric columns\n return ['integer', 'int', 'smallint', 'real', 'double', 'doublePrecision', 'numeric', 'decimal', 'number'];\n case ReflectionKind.boolean:\n return ['boolean', 'integer'];\n case ReflectionKind.bigint:\n return ['bigint', 'blob'];\n default:\n return [];\n }\n}\n"],"names":[],"mappings":";;;;;;AAWM,SAAU,eAAe,UAAoB,aAAgC;AAC/E,QAAM,SAAmB,CAAA;AACzB,QAAM,WAAqB,CAAA;AAC3B,aAAW,QAAQ,SAAS,YAAY;AACpC,UAAM,eAAe,YAAY,KAAK,IAAI;AAE1C,QAAI,CAAC;AAAc;AAEnB,UAAM,YAAY,0BAA0B,MAAM,YAAY;AAC9D,QAAI;AAAW,aAAO,KAAK,SAAS;AAEpC,UAAM,YAAY,oBAAo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}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.mapper.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base.mapper.js","sources":["../../../../src/mappers/base.mapper.ts"],"sourcesContent":["/* ########\n * 2025 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {ReflectionKind} from '@deepkit/type';\nimport type {ColumnMapping, PropertyInfo, DrizzleMapperConfig} from '../types/common.types.ts';\nimport {DEFAULT_LENGTH_BUFFER} from '../types/common.types.ts';\nimport {shouldBeJson} from '../core/utils.ts';\nimport {FormatName} from '@mionjs/type-formats/constants';\n\n/** Base class for database-specific column mappers */\nexport abstract class BaseColumnMapper {\n protected lengthBuffer: number;\n\n constructor(config?: DrizzleMapperConfig) {\n this.lengthBuffer = config?.lengthBuffer ?? DEFAULT_LENGTH_BUFFER;\n }\n\n /** Applies length buffer to a maxLength value */\n protected applyLengthBuffer(maxLength: number): number {\n return Math.ceil(maxLength * this.lengthBuffer);\n }\n\n /** Maps a primitive TypeScript type to a drizzle column */\n abstract mapPrimitive(kind: ReflectionKind, propName: string): ColumnMapping;\n /** Maps a format type to a drizzle column */\n abstract mapFormat(formatName: FormatName, formatParams: Record<string, any> | undefined, propName: string): ColumnMapping;\n /** Maps an array type to a JSON column */\n abstract mapArray(propName: string): ColumnMapping;\n /** Maps a nested object type to a JSON column */\n abstract mapObject(propName: string): ColumnMapping;\n /** Maps a Date type to a timestamp column */\n abstract mapDate(propName: string): ColumnMapping;\n\n /** Maps a property to a drizzle column based on its type information */\n mapProperty(prop: PropertyInfo): ColumnMapping {\n const {name, isOptional, formatName, formatParams} = prop;\n let mapping: ColumnMapping;\n // Check for Date type first (before JSON check since Date is a class)\n if (prop.isDate) mapping = this.mapDate(name);\n // Check for JSON types (arrays and nested objects)\n else if (shouldBeJson(prop)) {\n if (prop.isArray) mapping = this.mapArray(name);\n else mapping = this.mapObject(name);\n }\n // Check for format annotation\n else if (formatName) mapping = this.mapFormat(formatName, formatParams, name);\n // Primitive type\n else if (prop.primitiveKind !== undefined) mapping = this.mapPrimitive(prop.primitiveKind, name);\n // Fallback to text for unknown types\n else mapping = this.mapPrimitive(ReflectionKind.string, name);\n // Apply notNull for required properties\n if (!isOptional && mapping.builder.notNull) mapping.builder = mapping.builder.notNull();\n return mapping;\n }\n}\n"],"names":[],"mappings":";;;;;MAcsB,iBAAgB;AAAA,EACxB;AAAA,EAEV,YAAY,QAA4B;AACpC,SAAK,eAAe,QAAQ,gBAAgB;AAAA,EAChD;AAAA;AAAA,EAGU,kBAAkB,WAAiB;AACzC,WAAO,KAAK,KAAK,YAAY,KAAK,YAAY;AAAA,EAClD;AAAA;AAAA,EAcA,YAAY,MAAkB;AAC1B,UAAM,EAAC,MAAM,YAAY,YAAY,iBAAgB;AACrD,QAAI;AAEJ,QAAI,KAAK;AAAQ,gBAAU,KAAK,QAAQ,IAAI;AAAA,aAEnC,aAAa,IAAI,GAAG;AACzB,UAAI,KAAK;AAAS,kBAAU,KAAK,SAAS,IAAI;AAAA;AACzC,kBAAU,KAAK,UAAU,IAAI;AAAA,IACtC,WAES;AAAY,gBAAU,KAAK,UAAU,YAAY,cAAc,IAAI;AAAA,aAEnE,KAAK,kBAAkB;AAAW,gBAAU,KAAK,aAAa,KAAK,eAAe,IAAI;AAAA;AAE1F,gBAAU,KAAK,aAAa,eAAe,QAAQ,IAAI;AAE5D,QAAI,CAAC,cAAc,QAAQ,QAAQ;AAAS,cAAQ,UAAU,QAAQ,QAAQ,QAAA;AAC9E,WAAO;AAAA,EACX;AAAA;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mysql.mapper.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mysql.mapper.js","sources":["../../../../src/mappers/mysql.mapper.ts"],"sourcesContent":["/* ########\n * 2025 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {int, boolean, double, bigint, timestamp, date, time, varchar, json, datetime} from 'drizzle-orm/mysql-core';\nimport {ReflectionKind} from '@deepkit/type';\nimport {TypedError} from '@mionjs/core';\nimport {BaseColumnMapper} from './base.mapper.ts';\nimport type {ColumnMapping, DrizzleMapperConfig, PrimitiveColumnFactory, FormatColumnFactory} from '../types/common.types.ts';\nimport {DrizzleTypesMySQL, DEFAULT_VARCHAR_LENGTH, DEFAULT_LENGTH_BUFFER} from '../types/common.types.ts';\nimport {getMaxLengthFromParams, isIntegerFormat} from '../core/utils.ts';\nimport {FormatName, FormatNames} from '@mionjs/type-formats/constants';\n\n// ============================================================================\n// Default Mapping Objects\n// ============================================================================\n\n/** Default primitive-to-column mapping for MySQL, keyed by ReflectionKind */\nconst mysqlPrimitiveDefaults: Record<number, PrimitiveColumnFactory> = {\n [ReflectionKind.string]: (p) => ({\n builder: varchar(p, {length: DEFAULT_VARCHAR_LENGTH}),\n drizzleType: DrizzleTypesMySQL.varchar,\n }),\n [ReflectionKind.number]: (p) => ({builder: double(p), drizzleType: DrizzleTypesMySQL.double}),\n [ReflectionKind.boolean]: (p) => ({builder: boolean(p), drizzleType: DrizzleTypesMySQL.boolean}),\n [ReflectionKind.bigint]: (p) => ({builder: bigint(p, {mode: 'bigint'}), drizzleType: DrizzleTypesMySQL.bigint}),\n};\n\n/** Default format-to-column mapping for MySQL, keyed by FormatName */\nconst mysqlFormatDefaults: Record<string, FormatColumnFactory> = {\n [FormatNames.uuid]: (p) => ({builder: varchar(p, {length: 36}), drizzleType: DrizzleTypesMySQL.varchar}),\n [FormatNames.email]: (p, params) => {\n const maxLength = getMaxLengthFromParams(params) || 254;\n return {builder: varchar(p, {length: maxLength}), drizzleType: DrizzleTypesMySQL.varchar};\n },\n [FormatNames.url]: (p, params) => {\n const maxLength = getMaxLengthFromParams(params) || 2048;\n return {builder: varchar(p, {length: maxLength}), drizzleType: DrizzleTypesMySQL.varchar};\n },\n [FormatNames.domain]: (p, params) => {\n const maxLength = getMaxLengthFromParams(params) || 253;\n return {builder: varchar(p, {length: maxLength}), drizzleType: DrizzleTypesMySQL.varchar};\n },\n [FormatNames.ip]: (p) => ({builder: varchar(p, {length: 45}), drizzleType: DrizzleTypesMySQL.varchar}),\n [FormatNames.dateTime]: (p) => ({builder: datetime(p), drizzleType: DrizzleTypesMySQL.datetime}),\n [FormatNames.date]: (p) => ({builder: date(p), drizzleType: DrizzleTypesMySQL.date}),\n [FormatNames.time]: (p) => ({builder: time(p), drizzleType: DrizzleTypesMySQL.time}),\n [FormatNames.bigintFormat]: (p) => ({builder: bigint(p, {mode: 'bigint'}), drizzleType: DrizzleTypesMySQL.bigint}),\n [FormatNames.numberFormat]: (p, params) => {\n if (isIntegerFormat(params)) return {builder: int(p), drizzleType: DrizzleTypesMySQL.int};\n return {builder: double(p), drizzleType: DrizzleTypesMySQL.double};\n },\n [FormatNames.stringFormat]: (p, params, config) => {\n const buf = config?.lengthBuffer ?? DEFAULT_LENGTH_BUFFER;\n const maxLength = getMaxLengthFromParams(params);\n if (maxLength) return {builder: varchar(p, {length: Math.ceil(maxLength * buf)}), drizzleType: DrizzleTypesMySQL.varchar};\n return {builder: varchar(p, {length: DEFAULT_VARCHAR_LENGTH}), drizzleType: DrizzleTypesMySQL.varchar};\n },\n};\n\n// ============================================================================\n// Mapper Class\n// ============================================================================\n\n/** MySQL-specific column mapper */\nexport class MySQLColumnMapper extends BaseColumnMapper {\n constructor(config?: DrizzleMapperConfig) {\n super(config);\n }\n\n mapPrimitive(kind: ReflectionKind, propName: string): ColumnMapping {\n const factory = mysqlPrimitiveDefaults[kind];\n if (!factory) {\n throw new TypedError({\n type: 'drizzle-column-mapping-failed',\n message: `Cannot map property \"${propName}\" to MySQL column. TypeScript primitive type \"${ReflectionKind[kind]}\" has no corresponding drizzle column type.`,\n });\n }\n return factory(propName);\n }\n\n mapFormat(formatName: FormatName, formatParams: Record<string, any> | undefined, propName: string): ColumnMapping {\n const factory = mysqlFormatDefaults[formatName];\n if (!factory)\n return {builder: varchar(propName, {length: DEFAULT_VARCHAR_LENGTH}), drizzleType: DrizzleTypesMySQL.varchar};\n return factory(propName, formatParams, {lengthBuffer: this.lengthBuffer});\n }\n\n mapArray(propName: string): ColumnMapping {\n return {builder: json(propName), drizzleType: DrizzleTypesMySQL.json};\n }\n\n mapObject(propName: string): ColumnMapping {\n return {builder: json(propName), drizzleType: DrizzleTypesMySQL.json};\n }\n\n mapDate(propName: string): ColumnMapping {\n return {builder: timestamp(propName), drizzleType: DrizzleTypesMySQL.timestamp};\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAqBA,MAAM,yBAAiE;AAAA,EACnE,CAAC,eAAe,MAAM,GAAC,aAAE,CAAC,OAAO;AAAA,IAC7B,SAAS,QAAQ,GAAG,EAAC,QAAQ,wBAAuB;AAAA,IACpD,aAAa,kBAAkB;AAAA,EAAA,IACjC,CAAA,KAAA,IAAA,SAAA,CAAA;AAAA,EACF,CAAC,eAAe,MAAM,GAAC,aAAE,CAAC,OAAO,EAAC,SAAS,OAAO,CAAC,GAAG,aAAa,kBAAkB,OAAA,IAAQ,CAAA,KAAA,IAAA,SAAA,CAAA;AAAA,EAC7F,CAAC,eAAe,OAAO,GAAC,aAAE,CAAC,OAAO,EAAC,SAAS,QAAQ,CAAC,GAAG,aAAa,kBAAkB,QAAA,IAAS,CAAA,KAAA,IAAA,SAAA,CAAA;AAAA,EAChG,CAAC,eAAe,MAAM,gBAAG,CAAC,OAAO,EAAC,SAAS,OAAO,GAAG,EAAC,MAAM,UAAS,GAAG,aAAa,kBAAkB,OAAA,IAAQ,CAAA,KAAA,IAAA,SAAA,CAAA;;AAInH,MAAM,sBAA2D;AAAA,EAC7D,CAAC,YAAY,IAAI,gBAAG,CAAC,OAAO,EAAC,SAAS,QAAQ,GAAG,EAAC,QAAQ,IAAG,GAAG,aAAa,kBAAkB,QAAA,IAAS,CAAA,KAAA,IAAA,SAAA,CAAA;AAAA,E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AA,EAC3B;AAAA,EAEA,UAAU,YAAwB,cAA+C,UAAgB;AAC7F,UAAM,UAAU,oBAAoB,UAAU;AAC9C,QAAI,CAAC;AACD,aAAO,EAAC,SAAS,QAAQ,UAAU,EAAC,QAAQ,uBAAA,CAAuB,GAAG,aAAa,kBAAkB,QAAA;AACzG,WAAO,QAAQ,UAAU,cAAc,EAAC,cAAc,KAAK,cAAa;AAAA,EAC5E;AAAA,EAEA,SAAS,UAAgB;AACrB,WAAO,EAAC,SAAS,KAAK,QAAQ,GAAG,aAAa,kBAAkB,KAAA;AAAA,EACpE;AAAA,EAEA,UAAU,UAAgB;AACtB,WAAO,EAAC,SAAS,KAAK,QAAQ,GAAG,aAAa,kBAAkB,KAAA;AAAA,EACpE;AAAA,EAEA,QAAQ,UAAgB;AACpB,WAAO,EAAC,SAAS,UAAU,QAAQ,GAAG,aAAa,kBAAkB,UAAA;AAAA,EACzE;AAAA;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pg.mapper.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pg.mapper.js","sources":["../../../../src/mappers/pg.mapper.ts"],"sourcesContent":["/* ########\n * 2025 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {integer, boolean, doublePrecision, bigint, timestamp, date, time, uuid, jsonb, inet, varchar} from 'drizzle-orm/pg-core';\nimport {ReflectionKind} from '@deepkit/type';\nimport {TypedError} from '@mionjs/core';\nimport {BaseColumnMapper} from './base.mapper.ts';\nimport type {ColumnMapping, DrizzleMapperConfig, PrimitiveColumnFactory, FormatColumnFactory} from '../types/common.types.ts';\nimport {DrizzleTypesPostgres, DEFAULT_VARCHAR_LENGTH, DEFAULT_LENGTH_BUFFER} from '../types/common.types.ts';\nimport {getMaxLengthFromParams, getLengthFromParams, isIntegerFormat} from '../core/utils.ts';\nimport {FormatName, FormatNames} from '@mionjs/type-formats/constants';\n\n// ============================================================================\n// Default Mapping Objects\n// ============================================================================\n\n/** Default primitive-to-column mapping for PostgreSQL, keyed by ReflectionKind */\nconst pgPrimitiveDefaults: Record<number, PrimitiveColumnFactory> = {\n [ReflectionKind.string]: (p) => ({\n builder: varchar(p, {length: DEFAULT_VARCHAR_LENGTH}),\n drizzleType: DrizzleTypesPostgres.varchar,\n }),\n [ReflectionKind.number]: (p) => ({builder: doublePrecision(p), drizzleType: DrizzleTypesPostgres.doublePrecision}),\n [ReflectionKind.boolean]: (p) => ({builder: boolean(p), drizzleType: DrizzleTypesPostgres.boolean}),\n [ReflectionKind.bigint]: (p) => ({builder: bigint(p, {mode: 'bigint'}), drizzleType: DrizzleTypesPostgres.bigint}),\n};\n\n/** Default format-to-column mapping for PostgreSQL, keyed by FormatName */\nconst pgFormatDefaults: Record<string, FormatColumnFactory> = {\n [FormatNames.uuid]: (p) => ({builder: uuid(p), drizzleType: DrizzleTypesPostgres.uuid}),\n [FormatNames.email]: (p, params) => {\n const maxLength = getMaxLengthFromParams(params) || 254;\n return {builder: varchar(p, {length: maxLength}), drizzleType: DrizzleTypesPostgres.varchar};\n },\n [FormatNames.url]: (p, params) => {\n const maxLength = getMaxLengthFromParams(params) || 2048;\n return {builder: varchar(p, {length: maxLength}), drizzleType: DrizzleTypesPostgres.varchar};\n },\n [FormatNames.domain]: (p, params) => {\n const maxLength = getMaxLengthFromParams(params) || 253;\n return {builder: varchar(p, {length: maxLength}), drizzleType: DrizzleTypesPostgres.varchar};\n },\n [FormatNames.ip]: (p) => ({builder: inet(p), drizzleType: DrizzleTypesPostgres.inet}),\n [FormatNames.dateTime]: (p) => ({builder: timestamp(p), drizzleType: DrizzleTypesPostgres.timestamp}),\n [FormatNames.date]: (p) => ({builder: date(p), drizzleType: DrizzleTypesPostgres.date}),\n [FormatNames.time]: (p) => ({builder: time(p), drizzleType: DrizzleTypesPostgres.time}),\n [FormatNames.bigintFormat]: (p) => ({builder: bigint(p, {mode: 'bigint'}), drizzleType: DrizzleTypesPostgres.bigint}),\n [FormatNames.numberFormat]: (p, params) => {\n if (isIntegerFormat(params)) return {builder: integer(p), drizzleType: DrizzleTypesPostgres.integer};\n return {builder: doublePrecision(p), drizzleType: DrizzleTypesPostgres.doublePrecision};\n },\n [FormatNames.stringFormat]: (p, params, config) => {\n const buf = config?.lengthBuffer ?? DEFAULT_LENGTH_BUFFER;\n const maxLength = getMaxLengthFromParams(params);\n const exactLength = getLengthFromParams(params);\n if (exactLength) return {builder: varchar(p, {length: exactLength}), drizzleType: DrizzleTypesPostgres.varchar};\n if (maxLength)\n return {builder: varchar(p, {length: Math.ceil(maxLength * buf)}), drizzleType: DrizzleTypesPostgres.varchar};\n return {builder: varchar(p, {length: DEFAULT_VARCHAR_LENGTH}), drizzleType: DrizzleTypesPostgres.varchar};\n },\n};\n\n// ============================================================================\n// Mapper Class\n// ============================================================================\n\n/** PostgreSQL-specific column mapper */\nexport class PGColumnMapper extends BaseColumnMapper {\n constructor(config?: DrizzleMapperConfig) {\n super(config);\n }\n\n mapPrimitive(kind: ReflectionKind, propName: string): ColumnMapping {\n const factory = pgPrimitiveDefaults[kind];\n if (!factory) {\n throw new TypedError({\n type: 'drizzle-column-mapping-failed',\n message: `Cannot map property \"${propName}\" to PostgreSQL column. TypeScript primitive type \"${ReflectionKind[kind]}\" has no corresponding drizzle column type.`,\n });\n }\n return factory(propName);\n }\n\n mapFormat(formatName: FormatName, formatParams: Record<string, any> | undefined, propName: string): ColumnMapping {\n const factory = pgFormatDefaults[formatName];\n if (!factory)\n return {builder: varchar(propName, {length: DEFAULT_VARCHAR_LENGTH}), drizzleType: DrizzleTypesPostgres.varchar};\n return factory(propName, formatParams, {lengthBuffer: this.lengthBuffer});\n }\n\n mapArray(propName: string): ColumnMapping {\n return {builder: jsonb(propName), drizzleType: DrizzleTypesPostgres.jsonb};\n }\n\n mapObject(propName: string): ColumnMapping {\n return {builder: jsonb(propName), drizzleType: DrizzleTypesPostgres.jsonb};\n }\n\n mapDate(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A;AAC5G,WAAO,QAAQ,UAAU,cAAc,EAAC,cAAc,KAAK,cAAa;AAAA,EAC5E;AAAA,EAEA,SAAS,UAAgB;AACrB,WAAO,EAAC,SAAS,MAAM,QAAQ,GAAG,aAAa,qBAAqB,MAAA;AAAA,EACxE;AAAA,EAEA,UAAU,UAAgB;AACtB,WAAO,EAAC,SAAS,MAAM,QAAQ,GAAG,aAAa,qBAAqB,MAAA;AAAA,EACxE;AAAA,EAEA,QAAQ,UAAgB;AACpB,WAAO,EAAC,SAAS,UAAU,QAAQ,GAAG,aAAa,qBAAqB,UAAA;AAAA,EAC5E;AAAA;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite.mapper.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sqlite.mapper.js","sources":["../../../../src/mappers/sqlite.mapper.ts"],"sourcesContent":["/* ########\n * 2025 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {text, integer, real, blob} from 'drizzle-orm/sqlite-core';\nimport {ReflectionKind} from '@deepkit/type';\nimport {TypedError} from '@mionjs/core';\nimport {BaseColumnMapper} from './base.mapper.ts';\nimport type {ColumnMapping, DrizzleMapperConfig, PrimitiveColumnFactory, FormatColumnFactory} from '../types/common.types.ts';\nimport {DrizzleTypesSQLite} from '../types/common.types.ts';\nimport {isIntegerFormat} from '../core/utils.ts';\nimport {FormatName, FormatNames} from '@mionjs/type-formats/constants';\n\n// ============================================================================\n// Default Mapping Objects\n// ============================================================================\n\n/** Default primitive-to-column mapping for SQLite, keyed by ReflectionKind */\nconst sqlitePrimitiveDefaults: Record<number, PrimitiveColumnFactory> = {\n [ReflectionKind.string]: (p) => ({builder: text(p), drizzleType: DrizzleTypesSQLite.text}),\n [ReflectionKind.number]: (p) => ({builder: real(p), drizzleType: DrizzleTypesSQLite.real}),\n [ReflectionKind.boolean]: (p) => ({builder: integer(p, {mode: 'boolean'}), drizzleType: DrizzleTypesSQLite.integer}),\n [ReflectionKind.bigint]: (p) => ({builder: blob(p, {mode: 'bigint'}), drizzleType: DrizzleTypesSQLite.blob}),\n};\n\n/** Default format-to-column mapping for SQLite, keyed by FormatName */\nconst sqliteFormatDefaults: Record<string, FormatColumnFactory> = {\n [FormatNames.uuid]: (p) => ({builder: text(p), drizzleType: DrizzleTypesSQLite.text}),\n [FormatNames.email]: (p) => ({builder: text(p), drizzleType: DrizzleTypesSQLite.text}),\n [FormatNames.url]: (p) => ({builder: text(p), drizzleType: DrizzleTypesSQLite.text}),\n [FormatNames.domain]: (p) => ({builder: text(p), drizzleType: DrizzleTypesSQLite.text}),\n [FormatNames.ip]: (p) => ({builder: text(p), drizzleType: DrizzleTypesSQLite.text}),\n [FormatNames.dateTime]: (p) => ({builder: text(p), drizzleType: DrizzleTypesSQLite.text}),\n [FormatNames.date]: (p) => ({builder: text(p), drizzleType: DrizzleTypesSQLite.text}),\n [FormatNames.time]: (p) => ({builder: text(p), drizzleType: DrizzleTypesSQLite.text}),\n [FormatNames.stringFormat]: (p) => ({builder: text(p), drizzleType: DrizzleTypesSQLite.text}),\n [FormatNames.bigintFormat]: (p) => ({builder: blob(p, {mode: 'bigint'}), drizzleType: DrizzleTypesSQLite.blob}),\n [FormatNames.numberFormat]: (p, params) => {\n if (isIntegerFormat(params)) return {builder: integer(p), drizzleType: DrizzleTypesSQLite.integer};\n return {builder: real(p), drizzleType: DrizzleTypesSQLite.real};\n },\n};\n\n// ============================================================================\n// Mapper Class\n// ============================================================================\n\n/** SQLite-specific column mapper */\nexport class SQLiteColumnMapper extends BaseColumnMapper {\n constructor(config?: DrizzleMapperConfig) {\n super(config);\n }\n\n mapPrimitive(kind: ReflectionKind, propName: string): ColumnMapping {\n const factory = sqlitePrimitiveDefaults[kind];\n if (!factory) {\n throw new TypedError({\n type: 'drizzle-column-mapping-failed',\n message: `Cannot map property \"${propName}\" to SQLite column. TypeScript primitive type \"${ReflectionKind[kind]}\" has no corresponding drizzle column type.`,\n });\n }\n return factory(propName);\n }\n\n mapFormat(formatName: FormatName, formatParams: Record<string, any> | undefined, propName: string): ColumnMapping {\n const factory = sqliteFormatDefaults[formatName];\n if (!factory) return {builder: text(propName), drizzleType: DrizzleTypesSQLite.text};\n return factory(propName, formatParams, {lengthBuffer: this.lengthBuffer});\n }\n\n mapArray(propName: string): ColumnMapping {\n return {builder: text(propName, {mode: 'json'}), drizzleType: DrizzleTypesSQLite.text};\n }\n\n mapObject(propName: string): ColumnMapping {\n return {builder: text(propName, {mode: 'json'}), drizzleType: DrizzleTypesSQLite.text};\n }\n\n mapDate(propName: string): ColumnMapping {\n return {builder: integer(propName, {mode: 'timestamp'}), drizzleType: DrizzleTypesSQLite.integer};\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAqBA,MAAM,0BAAkE;AAAA,EACpE,CAAC,eAAe,MAAM,GAAC,aAAE,CAAC,OAAO,EAAC,SAAS,KAAK,CAAC,GAAG,aAAa,mBAAmB,KAAA,IAAM,CAAA,KAAA,IAAA,SAAA,CAAA;AAAA,EAC1F,CAAC,eAAe,MAAM,GAAC,aAAE,CAAC,OAAO,EAAC,SAAS,KAAK,CAAC,GAAG,aAAa,mBAAmB,KAAA,IAAM,CAAA,KAAA,IAAA,SAAA,CAAA;AAAA,EAC1F,CAAC,eAAe,OAAO,gBAAG,CAAC,OAAO,EAAC,SAAS,QAAQ,GAAG,EAAC,MAAM,WAAU,GAAG,aAAa,mBAAmB,QAAA,IAAS,CAAA,KAAA,IAAA,SAAA,CAAA;AAAA,EACpH,CAAC,eAAe,MAAM,gBAAG,CAAC,OAAO,EAAC,SAAS,KAAK,GAAG,EAAC,MAAM,UAAS,GAAG,aAAa,mBAAmB,KAAA,IAAM,CAAA,KAAA,IAAA,SAAA,CAAA;;AAIhH,MAAM,uBAA4D;AAAA,EAC9D,CAAC,YAAY,IAAI,GAAC,aAAE,CAAC,OAAO,EAAC,SAAS,KAAK,CAAC,GAAG,aAAa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AC,SAAS,QAAQ,UAAU,EAAC,MAAM,YAAA,CAAY,GAAG,aAAa,mBAAmB,QAAA;AAAA,EAC7F;AAAA;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mysql.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mysql.js","sources":["../../../src/mysql.ts"],"sourcesContent":["/* ########\n * 2025 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {mysqlTable, type MySqlTableWithColumns, type MySqlColumnBuilderBase} from 'drizzle-orm/mysql-core';\nimport type {BuildColumns} from 'drizzle-orm/column-builder';\nimport type {ReceiveType} from '@deepkit/type';\nimport {TypedError} from '@mionjs/core';\nimport {extractTypeInfo} from './core/typeTraverser.ts';\nimport {validateConfig} from './core/validator.ts';\nimport {MySQLColumnMapper} from './mappers/mysql.mapper.ts';\nimport type {MySqlTableConfig, MySqlColumnType} from './types/mysql.types.ts';\nimport type {DrizzleMapperConfig, Nullable} from './types/common.types.ts';\n\n/**\n * Merges auto-generated columns with config overrides.\n * For each property K in T:\n * - If K exists in TConfig AND TConfig[K] is a column builder, use TConfig[K]\n * - Otherwise, use the auto-generated column type (with notNull for required properties)\n */\ntype MergedMySqlColumns<T, TConfig> = {\n [K in keyof T as K extends string ? K : never]-?: K extends keyof TConfig\n ? TConfig[K] extends MySqlColumnBuilderBase\n ? TConfig[K]\n : Nullable<T, K, MySqlColumnType<K & string, NonNullable<T[K]>>>\n : Nullable<T, K, MySqlColumnType<K & string, NonNullable<T[K]>>>;\n};\n\n/** Default configuration for the mapper */\nconst DEFAULT_CONFIG: DrizzleMapperConfig = {};\n\n/**\n * Creates a MySQL table schema from a TypeScript type.\n * Auto-generates drizzle column definitions based on the type's properties.\n *\n * @example\n * ```typescript\n * interface User {\n * id: FormatUUIDv7;\n * email: FormatEmail;\n * name: string;\n * age: number;\n * createdAt: Date;\n * }\n *\n * // Without overrides - auto-generates all columns\n * const users = toDrizzleMySqlTable<User>('users');\n *\n * // With overrides - customize specific columns\n * const users = toDrizzleMySqlTable<User>('users', {\n * id: varchar('id', { length: 36 }).primaryKey(),\n * });\n *\n * // With custom lengthBuffer for varchar columns\n * const users = toDrizzleMySqlTable<User>('users', undefined, {lengthBuffer: 2.0});\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\nexport function toDrizzleMySqlTable<T, TN extends string = string, TConfig extends MySqlTableConfig<T> = {}>(\n tableName: TN,\n tableConfig?: TConfig,\n mapperConfig: DrizzleMapperConfig = DEFAULT_CONFIG,\n type?: ReceiveType<T>\n): MySqlTableWithColumns<{\n name: TN;\n schema: undefined;\n columns: BuildColumns<TN, MergedMySqlColumns<T, TConfig>, 'mysql'>;\n dialect: 'mysql';\n}> {\n // Validate that a type parameter was provided via type reflection\n if (!type) {\n throw new TypedError({\n type: 'drizzle-table-missing-type',\n message:\n 'toDrizzleMySqlTable requires a type parameter. Usage: toDrizzleMySqlTable<YourType>(tableName) or toDrizzleMySqlTable<YourType>(tableName, tableConfig)',\n });\n }\n\n // Extract type information using mion's RunType system\n const typeInfo = extractTypeInfo<T>(type);\n\n // Validate provided config against type\n if (tableConfig) {\n const validation = validateConfig(typeInfo, tableConfig);\n if (!validation.valid) {\n throw new TypedError({\n type: 'drizzle-table-config-invalid',\n message: `Cannot create MySQL table \"${tableName}\". The provided tableConfig does not match type \"${typeInfo.typeName}\":\\n${validation.errors.join('\\n')}`,\n });\n }\n if (validation.warnings.length > 0) {\n console.warn(`toDrizzleMySqlTable warnings:\\n${validation.warnings.join('\\n')}`);\n }\n }\n // Create column mapper with config\n const mapper = new MySQLColumnMapper(mapperConfig);\n // Build columns object - all properties will be filled (either from config or auto-generated)\n type Merged = MergedMySqlColumns<T, TConfig>;\n const columns: Merged = {} as Merged;\n for (const prop of typeInfo.properties) {\n // Use provided config if available, otherwise auto-generate\n const configKey = prop.name as keyof TConfig;\n if (tableConfig && configKey in tableConfig) {\n (columns as Record<string, unknown>)[prop.name] = tableConfig[configKey];\n } else {\n const mapping = mapper.mapProperty(prop);\n (columns as Record<string, unknown>)[prop.name] = mapping.builder;\n }\n }\n // Create and return the drizzle table\n // Cast is needed because mysqlTable's return type doesn't preserve the TConfig type parameter\n return mysqlTable<TN, Merged>(tableName, columns);\n}\n"],"names":[],"mappings":";;;;;;AAgCA,MAAM,iBAAsC,CAAA;AA6BtC,SAAU,oBACZ,WACA,aACA,eAAoC,gBACpC,OAJY,oBAAmB,IAAA,CAAA,GAIV;AAJT,sBAAmB,IAAA;AAY/B,MAAI,CAAC,MAAM;AACP,UAAM,IAAI,WAAW;AAAA,MACjB,MAAM;AAAA,MACN,SACI;AAAA,IAAA,CACP;AAAA,EACL;AAGA,QAAM,YAAW,gBAAe,IAAA,CAAA,CAAA,MAAA,IAAA,CAAA,GAAf,gBAAmB,IAAI;AAGxC,MAAI,aAAa;AACb,UAAM,aAAa,eAAe,UAAU,WAAW;AACvD,QAAI,CAAC,WAAW,OAAO;AACnB,YAAM,IAAI,WAAW;AAAA,QACjB,MAAM;AAAA,QACN,SAAS,8BAA8B,SAAS,oDAAoD,SAAS,QAAQ;AAAA,EAAO,WAAW,OAAO,KAAK,IAAI,CAAC;AAAA,MAAA,CAC3J;AAAA,IACL;AACA,QAAI,WAAW,SAAS,SAAS,GAAG;AAChC,cAAQ,KAAK;AAAA,EAAkC,WAAW,SAAS,KAAK,IAAI,CAAC,EAAE;AAAA,IACnF;AAAA,EACJ;AAEA,QAAM,SAAS,IAAI,kBAAkB,YAAY;;AAGjD,QAAM,UAAkB,CAAA;AACxB,aAAW,QAAQ,SAAS,YAAY;AAEpC,UAAM,YAAY,KAAK;AACvB,QAAI,eAAe,aAAa,aAAa;AACxC,cAAoC,KAAK,IAAI,IAAI,YAAY,SAAS;AAAA,IAC3E,OAAO;AACH,YAAM,UAAU,OAAO,YAAY,IAAI;AACtC,cAAoC,KAAK,IAAI,IAAI,QAAQ;AAAA,IAC9D;AAAA,EACJ;AAGA,SAAO,8EAAA,WAAuB,WAAW,OAAO;AACnD;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"postgres.js","sources":["../../../src/postgres.ts"],"sourcesContent":["/* ########\n * 2025 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {pgTable, type PgTableWithColumns, type PgColumnBuilderBase} from 'drizzle-orm/pg-core';\nimport type {BuildColumns} from 'drizzle-orm/column-builder';\nimport type {ReceiveType} from '@deepkit/type';\nimport {TypedError} from '@mionjs/core';\nimport {extractTypeInfo} from './core/typeTraverser.ts';\nimport {validateConfig} from './core/validator.ts';\nimport {PGColumnMapper} from './mappers/pg.mapper.ts';\nimport type {PgTableConfig, PgColumnType} from './types/postgres.types.ts';\nimport type {DrizzleMapperConfig, Nullable} from './types/common.types.ts';\n\n/**\n * Merges auto-generated columns with config overrides.\n * For each property K in T:\n * - If K exists in TConfig AND TConfig[K] is a column builder, use TConfig[K]\n * - Otherwise, use the auto-generated column type (with notNull for required properties)\n */\ntype MergedPgColumns<T, TConfig> = {\n [K in keyof T as K extends string ? K : never]-?: K extends keyof TConfig\n ? TConfig[K] extends PgColumnBuilderBase\n ? TConfig[K]\n : Nullable<T, K, PgColumnType<K & string, NonNullable<T[K]>>>\n : Nullable<T, K, PgColumnType<K & string, NonNullable<T[K]>>>;\n};\n\n/** Default configuration for the mapper */\nconst DEFAULT_CONFIG: DrizzleMapperConfig = {};\n\n/**\n * Creates a PostgreSQL table schema from a TypeScript type.\n * Auto-generates drizzle column definitions based on the type's properties.\n *\n * @example\n * ```typescript\n * interface User {\n * id: FormatUUIDv7;\n * email: FormatEmail;\n * name: string;\n * age: number;\n * createdAt: Date;\n * }\n *\n * // Without overrides - auto-generates all columns\n * const users = toDrizzlePGTable<User>('users');\n *\n * // With overrides - customize specific columns\n * const users = toDrizzlePGTable<User>('users', {\n * id: uuid('id').primaryKey(),\n * });\n *\n * // With custom lengthBuffer for varchar columns\n * const users = toDrizzlePGTable<User>('users', undefined, {lengthBuffer: 2.0});\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\nexport function toDrizzlePGTable<T, TN extends string = string, TConfig extends PgTableConfig<T> = {}>(\n tableName: TN,\n tableConfig?: TConfig,\n mapperConfig: DrizzleMapperConfig = DEFAULT_CONFIG,\n type?: ReceiveType<T>\n): PgTableWithColumns<{\n name: TN;\n schema: undefined;\n columns: BuildColumns<TN, MergedPgColumns<T, TConfig>, 'pg'>;\n dialect: 'pg';\n}> {\n // Validate that a type parameter was provided via type reflection\n if (!type) {\n throw new TypedError({\n type: 'drizzle-table-missing-type',\n message:\n 'toDrizzlePGTable requires a type parameter. Usage: toDrizzlePGTable<YourType>(tableName) or toDrizzlePGTable<YourType>(tableName, tableConfig)',\n });\n }\n\n // Extract type information using mion's RunType system\n const typeInfo = extractTypeInfo<T>(type);\n\n // Validate provided config against type\n if (tableConfig) {\n const validation = validateConfig(typeInfo, tableConfig);\n if (!validation.valid) {\n throw new TypedError({\n type: 'drizzle-table-config-invalid',\n message: `Cannot create PostgreSQL table \"${tableName}\". The provided tableConfig does not match type \"${typeInfo.typeName}\":\\n${validation.errors.join('\\n')}`,\n });\n }\n if (validation.warnings.length > 0) {\n console.warn(`toDrizzlePGTable warnings:\\n${validation.warnings.join('\\n')}`);\n }\n }\n // Create column mapper with config\n const mapper = new PGColumnMapper(mapperConfig);\n // Build columns object - all properties will be filled (either from config or auto-generated)\n type Merged = MergedPgColumns<T, TConfig>;\n const columns: Merged = {} as Merged;\n for (const prop of typeInfo.properties) {\n // Use provided config if available, otherwise auto-generate\n const configKey = prop.name as keyof TConfig;\n if (tableConfig && configKey in tableConfig) {\n (columns as Record<string, unknown>)[prop.name] = tableConfig[configKey];\n } else {\n const mapping = mapper.mapProperty(prop);\n (columns as Record<string, unknown>)[prop.name] = mapping.builder;\n }\n }\n // Create and return the drizzle table\n // Cast is needed because pgTable's return type doesn't preserve the TConfig type parameter\n return pgTable<TN, Merged>(tableName, columns);\n}\n"],"names":[],"mappings":";;;;;;AAgCA,MAAM,iBAAsC,CAAA;AA6BtC,SAAU,iBACZ,WACA,aACA,eAAoC,gBACpC,OAJY,iBAAgB,IAAA,CAAA,GAIP;AAJT,mBAAgB,IAAA;AAY5B,MAAI,CAAC,MAAM;AACP,UAAM,IAAI,WAAW;AAAA,MACjB,MAAM;AAAA,MACN,SACI;AAAA,IAAA,CACP;AAAA,EACL;AAGA,QAAM,YAAW,gBAAe,IAAA,CAAA,CAAA,MAAA,IAAA,CAAA,GAAf,gBAAmB,IAAI;AAGxC,MAAI,aAAa;AACb,UAAM,aAAa,eAAe,UAAU,WAAW;AACvD,QAAI,CAAC,WAAW,OAAO;AACnB,YAAM,IAAI,WAAW;AAAA,QACjB,MAAM;AAAA,QACN,SAAS,mCAAmC,SAAS,oDAAoD,SAAS,QAAQ;AAAA,EAAO,WAAW,OAAO,KAAK,IAAI,CAAC;AAAA,MAAA,CAChK;AAAA,IACL;AACA,QAAI,WAAW,SAAS,SAAS,GAAG;AAChC,cAAQ,KAAK;AAAA,EAA+B,WAAW,SAAS,KAAK,IAAI,CAAC,EAAE;AAAA,IAChF;AAAA,EACJ;AAEA,QAAM,SAAS,IAAI,eAAe,YAAY;;AAG9C,QAAM,UAAkB,CAAA;AACxB,aAAW,QAAQ,SAAS,YAAY;AAEpC,UAAM,YAAY,KAAK;AACvB,QAAI,eAAe,aAAa,aAAa;AACxC,cAAoC,KAAK,IAAI,IAAI,YAAY,SAAS;AAAA,IAC3E,OAAO;AACH,YAAM,UAAU,OAAO,YAAY,IAAI;AACtC,cAAoC,KAAK,IAAI,IAAI,QAAQ;AAAA,IAC9D;AAAA,EACJ;AAGA,SAAO,2EAAA,QAAoB,WAAW,OAAO;AAChD;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sqlite.js","sources":["../../../src/sqlite.ts"],"sourcesContent":["/* ########\n * 2025 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {sqliteTable, type SQLiteTableWithColumns, type SQLiteColumnBuilderBase} from 'drizzle-orm/sqlite-core';\nimport type {BuildColumns} from 'drizzle-orm/column-builder';\nimport type {ReceiveType} from '@deepkit/type';\nimport {TypedError} from '@mionjs/core';\nimport {extractTypeInfo} from './core/typeTraverser.ts';\nimport {validateConfig} from './core/validator.ts';\nimport {SQLiteColumnMapper} from './mappers/sqlite.mapper.ts';\nimport type {SqliteTableConfig, SqliteColumnType} from './types/sqlite.types.ts';\nimport type {DrizzleMapperConfig, Nullable} from './types/common.types.ts';\n\n/**\n * Merges auto-generated columns with config overrides.\n * For each property K in T:\n * - If K exists in TConfig AND TConfig[K] is a column builder, use TConfig[K]\n * - Otherwise, use the auto-generated column type (with notNull for required properties)\n */\ntype MergedSqliteColumns<T, TConfig> = {\n [K in keyof T as K extends string ? K : never]-?: K extends keyof TConfig\n ? TConfig[K] extends SQLiteColumnBuilderBase\n ? TConfig[K]\n : Nullable<T, K, SqliteColumnType<K & string, NonNullable<T[K]>>>\n : Nullable<T, K, SqliteColumnType<K & string, NonNullable<T[K]>>>;\n};\n\n/** Default configuration for the mapper */\nconst DEFAULT_CONFIG: DrizzleMapperConfig = {};\n\n/**\n * Creates a SQLite table schema from a TypeScript type.\n * Auto-generates drizzle column definitions based on the type's properties.\n *\n * @example\n * ```typescript\n * interface User {\n * id: FormatUUIDv7;\n * email: FormatEmail;\n * name: string;\n * age: number;\n * createdAt: Date;\n * }\n *\n * // Without overrides - auto-generates all columns\n * const users = toDrizzleSqliteTable<User>('users');\n *\n * // With overrides - customize specific columns\n * const users = toDrizzleSqliteTable<User>('users', {\n * id: text('id').primaryKey(),\n * });\n *\n * // With custom lengthBuffer (not used for SQLite text columns, but for consistency)\n * const users = toDrizzleSqliteTable<User>('users', undefined, {lengthBuffer: 2.0});\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\nexport function toDrizzleSqliteTable<T, TN extends string = string, TConfig extends SqliteTableConfig<T> = {}>(\n tableName: TN,\n tableConfig?: TConfig,\n mapperConfig: DrizzleMapperConfig = DEFAULT_CONFIG,\n type?: ReceiveType<T>\n): SQLiteTableWithColumns<{\n name: TN;\n schema: undefined;\n columns: BuildColumns<TN, MergedSqliteColumns<T, TConfig>, 'sqlite'>;\n dialect: 'sqlite';\n}> {\n // Validate that a type parameter was provided via type reflection\n if (!type) {\n throw new TypedError({\n type: 'drizzle-table-missing-type',\n message:\n 'toDrizzleSqliteTable requires a type parameter. Usage: toDrizzleSqliteTable<YourType>(tableName) or toDrizzleSqliteTable<YourType>(tableName, tableConfig)',\n });\n }\n\n // Extract type information using mion's RunType system\n const typeInfo = extractTypeInfo<T>(type);\n\n // Validate provided config against type\n if (tableConfig) {\n const validation = validateConfig(typeInfo, tableConfig);\n if (!validation.valid) {\n throw new TypedError({\n type: 'drizzle-table-config-invalid',\n message: `Cannot create SQLite table \"${tableName}\". The provided tableConfig does not match type \"${typeInfo.typeName}\":\\n${validation.errors.join('\\n')}`,\n });\n }\n if (validation.warnings.length > 0) {\n console.warn(`toDrizzleSqliteTable warnings:\\n${validation.warnings.join('\\n')}`);\n }\n }\n // Create column mapper with config\n const mapper = new SQLiteColumnMapper(mapperConfig);\n // Build columns object - all properties will be filled (either from config or auto-generated)\n type Merged = MergedSqliteColumns<T, TConfig>;\n const columns: Merged = {} as Merged;\n for (const prop of typeInfo.properties) {\n // Use provided config if available, otherwise auto-generate\n const configKey = prop.name as keyof TConfig;\n if (tableConfig && configKey in tableConfig) {\n (columns as Record<string, unknown>)[prop.name] = tableConfig[configKey];\n } else {\n const mapping = mapper.mapProperty(prop);\n (columns as Record<string, unknown>)[prop.name] = mapping.builder;\n }\n }\n // Create and return the drizzle table\n // Cast is needed because sqliteTable's return type doesn't preserve the TConfig type parameter\n return sqliteTable<TN, Merged>(tableName, columns);\n}\n"],"names":[],"mappings":";;;;;;AAgCA,MAAM,iBAAsC,CAAA;AA6BtC,SAAU,qBACZ,WACA,aACA,eAAoC,gBACpC,OAJY,qBAAoB,IAAA,CAAA,GAIX;AAJT,uBAAoB,IAAA;AAYhC,MAAI,CAAC,MAAM;AACP,UAAM,IAAI,WAAW;AAAA,MACjB,MAAM;AAAA,MACN,SACI;AAAA,IAAA,CACP;AAAA,EACL;AAGA,QAAM,YAAW,gBAAe,IAAA,CAAA,CAAA,MAAA,IAAA,CAAA,GAAf,gBAAmB,IAAI;AAGxC,MAAI,aAAa;AACb,UAAM,aAAa,eAAe,UAAU,WAAW;AACvD,QAAI,CAAC,WAAW,OAAO;AACnB,YAAM,IAAI,WAAW;AAAA,QACjB,MAAM;AAAA,QACN,SAAS,+BAA+B,SAAS,oDAAoD,SAAS,QAAQ;AAAA,EAAO,WAAW,OAAO,KAAK,IAAI,CAAC;AAAA,MAAA,CAC5J;AAAA,IACL;AACA,QAAI,WAAW,SAAS,SAAS,GAAG;AAChC,cAAQ,KAAK;AAAA,EAAmC,WAAW,SAAS,KAAK,IAAI,CAAC,EAAE;AAAA,IACpF;AAAA,EACJ;AAEA,QAAM,SAAS,IAAI,mBAAmB,YAAY;;AAGlD,QAAM,UAAkB,CAAA;AACxB,aAAW,QAAQ,SAAS,YAAY;AAEpC,UAAM,YAAY,KAAK;AACvB,QAAI,eAAe,aAAa,aAAa;AACxC,cAAoC,KAAK,IAAI,IAAI,YAAY,SAAS;AAAA,IAC3E,OAAO;AACH,YAAM,UAAU,OAAO,YAAY,IAAI;AACtC,cAAoC,KAAK,IAAI,IAAI,QAAQ;AAAA,IAC9D;AAAA,EACJ;AAGA,SAAO,+EAAA,YAAwB,WAAW,OAAO;AACpD;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mysql.stub.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mysql.stub.js","sources":["../../../../src/stubs-formats-mappings/mysql.stub.ts"],"sourcesContent":["/* ########\n * 2025 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\n/**\n * TYPE STUB — never executed, only type-checked via tsc --noEmit.\n * Simulates real Drizzle application code with branded mion types.\n */\n\nimport {eq} from 'drizzle-orm';\nimport {MySqlDatabase} from 'drizzle-orm/mysql-core';\nimport {toDrizzleMySqlTable} from '../mysql.ts';\nimport {FormatUUIDv7, FormatEmail} from '@mionjs/type-formats/StringFormats';\nimport {FormatInteger, FormatPositiveInt} from '@mionjs/type-formats/NumberFormats';\nimport {User, Post, UserWithOptional} from './common.ts';\n\n// -- Setup: build tables and declare a db instance (never instantiated) ------\n\nconst users = toDrizzleMySqlTable<User>('users');\nconst posts = toDrizzleMySqlTable<Post>('posts');\nconst optionalUsers = toDrizzleMySqlTable<UserWithOptional>('optional_users');\n\ndeclare const db: MySqlDatabase<any, any>;\n\n// -- 1. Full select → assign row to original type ----------------------------\n\nasync function getUsers(): Promise<User[]> {\n const rows = await db.select().from(users);\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const first: User = rows[0];\n return rows;\n}\n\n// -- 2. Individual branded field access --------------------------------------\n\nasync function getUserFields() {\n const [row] = await db.select().from(users);\n const id: FormatUUIDv7 = row.id;\n const email: FormatEmail = row.email;\n const age: FormatInteger = row.age;\n const score: FormatPositiveInt = row.score;\n const name: string = row.name;\n const tags: string[] = row.tags;\n const profile: {avatar: string; theme: string} = row.profile;\n return {id, email, age, score, name, tags, profile};\n}\n\n// -- 3. Where clause with branded values -------------------------------------\n\nasync function findUserById(userId: FormatUUIDv7): Promise<User | undefined> {\n const rows = await db.select().from(users).where(eq(users.id, userId));\n return rows[0];\n}\n\nasync function findUserByEmail(email: FormatEmail): Promise<User | undefined> {\n const rows = await db.select().from(users).where(eq(users.email, email));\n return rows[0];\n}\n\n// -- 4. Join — both tables preserve branded types ----------------------------\n\nasync function getUsersWithPosts() {\n const rows = await db.select().from(users).innerJoin(posts, eq(users.id, posts.authorId));\n\n const first = rows[0];\n const user: User = first.users;\n const post: Post = first.posts;\n\n const authorId: FormatUUIDv7 = first.users.id;\n const postId: FormatUUIDv7 = first.posts.id;\n const postAuthorId: FormatUUIDv7 = first.posts.authorId;\n const postViews: FormatPositiveInt = first.posts.views;\n\n return {user, post, authorId, postId, postAuthorId, postViews};\n}\n\n// -- 5. Partial select — picked columns preserve brands ----------------------\n\nasync function getPartialUser() {\n const rows = await db.select({id: users.id, email: users.email}).from(users);\n const first = rows[0];\n const id: FormatUUIDv7 = first.id;\n const email: FormatEmail = first.email;\n return {id, email};\n}\n\n// -- 6. Insert with branded values -------------------------------------------\n\nasync function insertUser(user: User) {\n await db.insert(users).values(user);\n}\n\n// -- 7. Optional fields — nullable in select ---------------------------------\n\nasync function getOptionalUser() {\n const [row] = await db.select().from(optionalUsers);\n const id: FormatUUIDv7 = row.id;\n const name: string = row.name;\n const bio: string | null = row.bio;\n return {id, name, bio};\n}\n\n// -- Suppress unused warnings ------------------------------------------------\nvoid getUsers;\nvoid getUserFields;\nvoid findUserById;\nvoid findUserByEmail;\nvoid getUsersWithPosts;\nvoid getPartialUser;\nvoid insertUser;\nvoid getOptionalUser;\n"],"names":["__ΩUser","__ΩPost","__ΩUserWithOptional"],"mappings":";;;;AAqBc,oBAAmB,IAAA,CAAA,CAAA,MAAAA,SAAA,IAAA,CAAA,GAAnB,oBAA0B,OAAO;AACjC,oBAAmB,IAAA,CAAA,CAAA,MAAAC,SAAA,IAAA,CAAA,GAAnB,oBAA0B,OAAO;AACzB,oBAAmB,IAAA,CAAA,CAAA,MAAAC,qBAAA,IAAA,CAAA,GAAnB,oBAAsC,gBAAgB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.stub.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"postgres.stub.js","sources":["../../../../src/stubs-formats-mappings/postgres.stub.ts"],"sourcesContent":["/* ########\n * 2025 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\n/**\n * TYPE STUB — never executed, only type-checked via tsc --noEmit.\n * Simulates real Drizzle application code with branded mion types.\n */\n\nimport {eq} from 'drizzle-orm';\nimport {PgDatabase} from 'drizzle-orm/pg-core';\nimport {toDrizzlePGTable} from '../postgres.ts';\nimport {FormatUUIDv7, FormatEmail} from '@mionjs/type-formats/StringFormats';\nimport {FormatInteger, FormatPositiveInt} from '@mionjs/type-formats/NumberFormats';\nimport {User, Post, UserWithOptional} from './common.ts';\n\n// -- Setup: build tables and declare a db instance (never instantiated) ------\n\nconst users = toDrizzlePGTable<User>('users');\nconst posts = toDrizzlePGTable<Post>('posts');\nconst optionalUsers = toDrizzlePGTable<UserWithOptional>('optional_users');\n\ndeclare const db: PgDatabase<any, any, any>;\n\n// -- 1. Full select → assign row to original type ----------------------------\n\nasync function getUsers(): Promise<User[]> {\n const rows = await db.select().from(users);\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const first: User = rows[0];\n return rows;\n}\n\n// -- 2. Individual branded field access --------------------------------------\n\nasync function getUserFields() {\n const [row] = await db.select().from(users);\n const id: FormatUUIDv7 = row.id;\n const email: FormatEmail = row.email;\n const age: FormatInteger = row.age;\n const score: FormatPositiveInt = row.score;\n const name: string = row.name;\n const tags: string[] = row.tags;\n const profile: {avatar: string; theme: string} = row.profile;\n return {id, email, age, score, name, tags, profile};\n}\n\n// -- 3. Where clause with branded values -------------------------------------\n\nasync function findUserById(userId: FormatUUIDv7): Promise<User | undefined> {\n const rows = await db.select().from(users).where(eq(users.id, userId));\n return rows[0];\n}\n\nasync function findUserByEmail(email: FormatEmail): Promise<User | undefined> {\n const rows = await db.select().from(users).where(eq(users.email, email));\n return rows[0];\n}\n\n// -- 4. Join — both tables preserve branded types ----------------------------\n\nasync function getUsersWithPosts() {\n const rows = await db.select().from(users).innerJoin(posts, eq(users.id, posts.authorId));\n\n const first = rows[0];\n const user: User = first.users;\n const post: Post = first.posts;\n\n // Cross-table branded field access\n const authorId: FormatUUIDv7 = first.users.id;\n const postId: FormatUUIDv7 = first.posts.id;\n const postAuthorId: FormatUUIDv7 = first.posts.authorId;\n const postViews: FormatPositiveInt = first.posts.views;\n\n return {user, post, authorId, postId, postAuthorId, postViews};\n}\n\n// -- 5. Partial select — picked columns preserve brands ----------------------\n\nasync function getPartialUser(): Promise<Pick<User, 'id' | 'email'>> {\n const rows = await db.select({id: users.id, email: users.email}).from(users);\n const first = rows[0];\n const id: FormatUUIDv7 = first.id;\n const email: FormatEmail = first.email;\n return {id, email};\n}\n\n// -- 6. Insert with branded values -------------------------------------------\n\nasync function insertUser(user: User) {\n await db.insert(users).values(user);\n}\n\n// -- 7. Optional fields — nullable in select ---------------------------------\n\nasync function getOptionalUser() {\n const [row] = await db.select().from(optionalUsers);\n // Required fields are NOT nullable\n const id: FormatUUIDv7 = row.id;\n const name: string = row.name;\n // Optional field IS nullable (string | null)\n const bio: string | null = row.bio;\n return {id, name, bio};\n}\n\n// -- Suppress unused warnings ------------------------------------------------\nvoid getUsers;\nvoid getUserFields;\nvoid findUserById;\nvoid findUserByEmail;\nvoid getUsersWithPosts;\nvoid getPartialUser;\nvoid insertUser;\nvoid getOptionalUser;\n"],"names":["__ΩUser","__ΩPost","__ΩUserWithOptional"],"mappings":";;;;AAqBc,iBAAgB,IAAA,CAAA,CAAA,MAAAA,SAAA,IAAA,CAAA,GAAhB,iBAAuB,OAAO;AAC9B,iBAAgB,IAAA,CAAA,CAAA,MAAAC,SAAA,IAAA,CAAA,GAAhB,iBAAuB,OAAO;AACtB,iBAAgB,IAAA,CAAA,CAAA,MAAAC,qBAAA,IAAA,CAAA,GAAhB,iBAAmC,gBAAgB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite.stub.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sqlite.stub.js","sources":["../../../../src/stubs-formats-mappings/sqlite.stub.ts"],"sourcesContent":["/* ########\n * 2025 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\n/**\n * TYPE STUB — never executed, only type-checked via tsc --noEmit.\n * Simulates real Drizzle application code with branded mion types.\n */\n\nimport {eq} from 'drizzle-orm';\nimport {BaseSQLiteDatabase} from 'drizzle-orm/sqlite-core';\nimport {toDrizzleSqliteTable} from '../sqlite.ts';\nimport {FormatUUIDv7, FormatEmail} from '@mionjs/type-formats/StringFormats';\nimport {FormatInteger, FormatPositiveInt} from '@mionjs/type-formats/NumberFormats';\nimport {User, Post, UserWithOptional} from './common.ts';\n\n// -- Setup: build tables and declare a db instance (never instantiated) ------\n\nconst users = toDrizzleSqliteTable<User>('users');\nconst posts = toDrizzleSqliteTable<Post>('posts');\nconst optionalUsers = toDrizzleSqliteTable<UserWithOptional>('optional_users');\n\ndeclare const db: BaseSQLiteDatabase<'async', unknown>;\n\n// -- 1. Full select → assign row to original type ----------------------------\n\nasync function getUsers(): Promise<User[]> {\n const rows = await db.select().from(users);\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const first: User = rows[0];\n return rows;\n}\n\n// -- 2. Individual branded field access --------------------------------------\n\nasync function getUserFields() {\n const [row] = await db.select().from(users);\n const id: FormatUUIDv7 = row.id;\n const email: FormatEmail = row.email;\n const age: FormatInteger = row.age;\n const score: FormatPositiveInt = row.score;\n const name: string = row.name;\n const tags: string[] = row.tags;\n const profile: {avatar: string; theme: string} = row.profile;\n return {id, email, age, score, name, tags, profile};\n}\n\n// -- 3. Where clause with branded values -------------------------------------\n\nasync function findUserById(userId: FormatUUIDv7): Promise<User | undefined> {\n const rows = await db.select().from(users).where(eq(users.id, userId));\n return rows[0];\n}\n\nasync function findUserByEmail(email: FormatEmail): Promise<User | undefined> {\n const rows = await db.select().from(users).where(eq(users.email, email));\n return rows[0];\n}\n\n// -- 4. Join — both tables preserve branded types ----------------------------\n\nasync function getUsersWithPosts() {\n const rows = await db.select().from(users).innerJoin(posts, eq(users.id, posts.authorId));\n\n const first = rows[0];\n const user: User = first.users;\n const post: Post = first.posts;\n\n // Cross-table branded field access\n const authorId: FormatUUIDv7 = first.users.id;\n const postId: FormatUUIDv7 = first.posts.id;\n const postAuthorId: FormatUUIDv7 = first.posts.authorId;\n const postViews: FormatPositiveInt = first.posts.views;\n\n return {user, post, authorId, postId, postAuthorId, postViews};\n}\n\n// -- 5. Partial select — picked columns preserve brands ----------------------\n\nasync function getPartialUser() {\n const rows = await db.select({id: users.id, email: users.email}).from(users);\n const first = rows[0];\n const id: FormatUUIDv7 = first.id;\n const email: FormatEmail = first.email;\n return {id, email};\n}\n\n// -- 6. Insert with branded values -------------------------------------------\n\nasync function insertUser(user: User) {\n await db.insert(users).values(user);\n}\n\n// -- 7. Optional fields — nullable in select ---------------------------------\n\nasync function getOptionalUser() {\n const [row] = await db.select().from(optionalUsers);\n // Required fields are NOT nullable\n const id: FormatUUIDv7 = row.id;\n const name: string = row.name;\n // Optional field IS nullable (string | null)\n const bio: string | null = row.bio;\n return {id, name, bio};\n}\n\n// -- Suppress unused warnings ------------------------------------------------\nvoid getUsers;\nvoid getUserFields;\nvoid findUserById;\nvoid findUserByEmail;\nvoid getUsersWithPosts;\nvoid getPartialUser;\nvoid insertUser;\nvoid getOptionalUser;\n"],"names":["__ΩUser","__ΩPost","__ΩUserWithOptional"],"mappings":";;;;AAqBc,qBAAoB,IAAA,CAAA,CAAA,MAAAA,SAAA,IAAA,CAAA,GAApB,qBAA2B,OAAO;AAClC,qBAAoB,IAAA,CAAA,CAAA,MAAAC,SAAA,IAAA,CAAA,GAApB,qBAA2B,OAAO;AAC1B,qBAAoB,IAAA,CAAA,CAAA,MAAAC,qBAAA,IAAA,CAAA,GAApB,qBAAuC,gBAAgB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.types.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"common.types.js","sources":["../../../../src/types/common.types.ts"],"sourcesContent":["/* ########\n * 2025 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport type {BaseRunType} from '@mionjs/run-types';\nimport type {ReflectionKind} from '@deepkit/type';\nimport type {\n BrandEmail,\n BrandUUID,\n BrandUrl,\n BrandDomain,\n BrandIP,\n BrandDate,\n BrandTime,\n BrandDateTime,\n BrandInteger,\n BrandFloat,\n BrandPositive,\n BrandNegative,\n BrandPositiveInt,\n BrandNegativeInt,\n BrandInt8,\n BrandInt16,\n BrandInt32,\n BrandUInt8,\n BrandUInt16,\n BrandUInt32,\n} from '@mionjs/core';\n\n/** Supported database types */\nexport type DatabaseType = 'postgres' | 'mysql' | 'sqlite';\n\n// ############### Brand Name Utilities ###############\n\n/** Extracts the brand name string from a Brand type */\ntype ExtractBrandName<T> = T extends {brand: infer B extends string} ? B : never;\n\n/** Union of all brand name strings from formatBrands.types.ts.\n * Used as the shared key set for database-specific BrandColumnMap types.\n * If a new brand is added to @mionjs/core, add it here to trigger compile-time\n * errors in any database map that hasn't been updated. */\nexport type AllBrandNames =\n | ExtractBrandName<BrandEmail>\n | ExtractBrandName<BrandUUID>\n | ExtractBrandName<BrandUrl>\n | ExtractBrandName<BrandDomain>\n | ExtractBrandName<BrandIP>\n | ExtractBrandName<BrandDate>\n | ExtractBrandName<BrandTime>\n | ExtractBrandName<BrandDateTime>\n | ExtractBrandName<BrandInteger>\n | ExtractBrandName<BrandFloat>\n | ExtractBrandName<BrandPositive>\n | ExtractBrandName<BrandNegative>\n | ExtractBrandName<BrandPositiveInt>\n | ExtractBrandName<BrandNegativeInt>\n | ExtractBrandName<BrandInt8>\n | ExtractBrandName<BrandInt16>\n | ExtractBrandName<BrandInt32>\n | ExtractBrandName<BrandUInt8>\n | ExtractBrandName<BrandUInt16>\n | ExtractBrandName<BrandUInt32>;\n\n// ############### Drizzle Column Type Constants ###############\n// NOTE: These string values must match the drizzle-orm function names exactly.\n// Run `npm run validate:drizzle-types -w @mionjs/drizzle` to verify.\n\n/** PostgreSQL-specific drizzle column types */\nexport const DrizzleTypesPostgres = {\n text: 'text',\n boolean: 'boolean',\n bigint: 'bigint',\n varchar: 'varchar',\n date: 'date',\n time: 'time',\n timestamp: 'timestamp',\n integer: 'integer',\n doublePrecision: 'doublePrecision',\n uuid: 'uuid',\n inet: 'inet',\n char: 'char',\n jsonb: 'jsonb',\n} as const;\n\n/** MySQL-specific drizzle column types */\nexport const DrizzleTypesMySQL = {\n text: 'text',\n boolean: 'boolean',\n bigint: 'bigint',\n varchar: 'varchar',\n date: 'date',\n time: 'time',\n timestamp: 'timestamp',\n json: 'json',\n double: 'double',\n int: 'int',\n datetime: 'datetime',\n} as const;\n\n/** SQLite-specific drizzle column types */\nexport const DrizzleTypesSQLite = {\n text: 'text',\n integer: 'integer',\n real: 'real',\n blob: 'blob',\n} as const;\n\n/** Combined drizzle column types for backward compatibility */\nexport const DrizzleTypes = {\n ...DrizzleTypesPostgres,\n ...DrizzleTypesMySQL,\n ...DrizzleTypesSQLite,\n} as const;\n\nexport type DrizzleTypePostgres = (typeof DrizzleTypesPostgres)[keyof typeof DrizzleTypesPostgres];\nexport type DrizzleTypeMySQL = (typeof DrizzleTypesMySQL)[keyof typeof DrizzleTypesMySQL];\nexport type DrizzleTypeSQLite = (typeof DrizzleTypesSQLite)[keyof typeof DrizzleTypesSQLite];\nexport type DrizzleType = (typeof DrizzleTypes)[keyof typeof DrizzleTypes];\n\n/** Column mapping result from mapper */\nexport interface ColumnMapping {\n builder: any;\n drizzleType: DrizzleType;\n}\n\n/** Factory that creates a ColumnMapping for a primitive type */\nexport type PrimitiveColumnFactory = (propName: string) => ColumnMapping;\n\n/** Factory that creates a ColumnMapping for a format type (may use params and config) */\nexport type FormatColumnFactory = (\n propName: string,\n formatParams?: Record<string, any>,\n config?: DrizzleMapperConfig\n) => ColumnMapping;\n\n/** Information about a property extracted from TypeScript type */\nexport interface PropertyInfo {\n /** Property name */\n name: string;\n /** The RunType for this property's type */\n runType: BaseRunType;\n /** Whether the property is optional (?) */\n isOptional: boolean;\n /** Whether the type is a nested object (will become JSON column) */\n isNestedObject: boolean;\n /** Whether the type is an array (will become JSON column) */\n isArray: boolean;\n /** Whether the type is a Date */\n isDate: boolean;\n /** Format name if the type has a format annotation (e.g., 'uuid', 'email') */\n formatName?: string;\n /** Format parameters if the type has a format annotation */\n formatParams?: Record<string, any>;\n /** The primitive kind if this is a primitive type */\n primitiveKind?: ReflectionKind;\n}\n\n/** Information about a TypeScript type */\nexport interface TypeInfo {\n /** The type name (interface/class name) */\n typeName: string;\n /** All properties of the type */\n properties: PropertyInfo[];\n}\n\n/** Validation result from config validator */\nexport interface ValidationResult {\n /** Whether the validation passed */\n valid: boolean;\n /** List of validation errors */\n errors: string[];\n /** List of validation warnings */\n warnings: string[];\n}\n\n/** Default varchar length when no maxLength is specified in format params */\nexport const DEFAULT_VARCHAR_LENGTH = 255;\n\n/** Default length buffer multiplier for varchar columns */\nexport const DEFAULT_LENGTH_BUFFER = 1.5;\n\n/** Configuration options for drizzle table mapping */\nexport interface DrizzleMapperConfig {\n /** Multiplier for maxLength in string formats (default: 1.5). Applied to varchar column lengths. */\n lengthBuffer?: number;\n}\n\n/** Applies notNull inline when the property is required in T */\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\nexport type Nullable<T, K extends keyof T, Col> = {} extends Pick<T, K> ? Col : Col & {_: {notNull: true}};\n"],"names":[],"mappings":";;;;;AAuEO,MAAM,uBAAuB;AAAA,EAChC,MAAM;AAAA,EACN,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,WAAW;AAAA,EACX,SAAS;AAAA,EACT,iBAAiB;AAAA,EACjB,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;;AAIJ,MAAM,oBAAoB;AAAA,EAC7B,MAAM;AAAA,EACN,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,WAAW;AAAA,EACX,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,KAAK;AAAA,EACL,UAAU;;AAIP,MAAM,qBAAqB;AAAA,EAC9B,MAAM;AAAA,EACN,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;;AAIH,MAAM,eAAe;AAAA,EACxB,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;;;;;;;;;;;;AAiEA,MAAM,yBAAyB;AAG/B,MAAM,wBAAwB;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mionjs/drizzle",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4-alpha.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "drizzle extension for mion run-types",
|
|
6
6
|
"keywords": [
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
"url": "https://github.com/MionKit/mion/issues"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@mionjs/core": "^0.8.
|
|
57
|
-
"@mionjs/run-types": "^0.8.
|
|
58
|
-
"@mionjs/type-formats": "^0.8.
|
|
56
|
+
"@mionjs/core": "^0.8.4-alpha.0",
|
|
57
|
+
"@mionjs/run-types": "^0.8.4-alpha.0",
|
|
58
|
+
"@mionjs/type-formats": "^0.8.4-alpha.0",
|
|
59
59
|
"drizzle-orm": "^0.38.0"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "26f07a965e43529d4255e6f2ac8a633513026314"
|
|
62
62
|
}
|