@prisma-next/adapter-postgres 0.3.0-pr.99.6 → 0.4.0-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +64 -2
  3. package/dist/adapter-7pXt8ej9.mjs +369 -0
  4. package/dist/adapter-7pXt8ej9.mjs.map +1 -0
  5. package/dist/adapter.d.mts +23 -0
  6. package/dist/adapter.d.mts.map +1 -0
  7. package/dist/adapter.mjs +3 -0
  8. package/dist/codec-ids-BwjcIf74.mjs +29 -0
  9. package/dist/codec-ids-BwjcIf74.mjs.map +1 -0
  10. package/dist/codec-types.d.mts +107 -0
  11. package/dist/codec-types.d.mts.map +1 -0
  12. package/dist/codec-types.mjs +3 -0
  13. package/dist/codecs-C3wlpdV7.mjs +385 -0
  14. package/dist/codecs-C3wlpdV7.mjs.map +1 -0
  15. package/dist/column-types.d.mts +122 -0
  16. package/dist/column-types.d.mts.map +1 -0
  17. package/dist/column-types.mjs +180 -0
  18. package/dist/column-types.mjs.map +1 -0
  19. package/dist/control.d.mts +77 -0
  20. package/dist/control.d.mts.map +1 -0
  21. package/dist/control.mjs +776 -0
  22. package/dist/control.mjs.map +1 -0
  23. package/dist/descriptor-meta-DemWrTfB.mjs +768 -0
  24. package/dist/descriptor-meta-DemWrTfB.mjs.map +1 -0
  25. package/dist/runtime.d.mts +19 -0
  26. package/dist/runtime.d.mts.map +1 -0
  27. package/dist/runtime.mjs +98 -0
  28. package/dist/runtime.mjs.map +1 -0
  29. package/dist/sql-utils-CSfAGEwF.mjs +78 -0
  30. package/dist/sql-utils-CSfAGEwF.mjs.map +1 -0
  31. package/dist/types-DxaTd7aP.d.mts +20 -0
  32. package/dist/types-DxaTd7aP.d.mts.map +1 -0
  33. package/dist/types.d.mts +2 -0
  34. package/dist/types.mjs +1 -0
  35. package/package.json +32 -41
  36. package/src/core/adapter.ts +535 -256
  37. package/src/core/codec-ids.ts +30 -0
  38. package/src/core/codecs.ts +487 -36
  39. package/src/core/control-adapter.ts +405 -184
  40. package/src/core/control-mutation-defaults.ts +335 -0
  41. package/src/core/default-normalizer.ts +145 -0
  42. package/src/core/descriptor-meta.ts +227 -9
  43. package/src/core/enum-control-hooks.ts +739 -0
  44. package/src/core/json-schema-type-expression.ts +131 -0
  45. package/src/core/json-schema-validator.ts +53 -0
  46. package/src/core/sql-utils.ts +111 -0
  47. package/src/core/standard-schema.ts +71 -0
  48. package/src/core/types.ts +8 -10
  49. package/src/exports/codec-types.ts +34 -1
  50. package/src/exports/column-types.ts +223 -27
  51. package/src/exports/control.ts +19 -9
  52. package/src/exports/runtime.ts +75 -19
  53. package/dist/chunk-HD5YISNQ.js +0 -47
  54. package/dist/chunk-HD5YISNQ.js.map +0 -1
  55. package/dist/chunk-J3XSOAM2.js +0 -162
  56. package/dist/chunk-J3XSOAM2.js.map +0 -1
  57. package/dist/chunk-T6S3A6VT.js +0 -301
  58. package/dist/chunk-T6S3A6VT.js.map +0 -1
  59. package/dist/core/adapter.d.ts +0 -19
  60. package/dist/core/adapter.d.ts.map +0 -1
  61. package/dist/core/codecs.d.ts +0 -110
  62. package/dist/core/codecs.d.ts.map +0 -1
  63. package/dist/core/control-adapter.d.ts +0 -33
  64. package/dist/core/control-adapter.d.ts.map +0 -1
  65. package/dist/core/descriptor-meta.d.ts +0 -72
  66. package/dist/core/descriptor-meta.d.ts.map +0 -1
  67. package/dist/core/types.d.ts +0 -16
  68. package/dist/core/types.d.ts.map +0 -1
  69. package/dist/exports/adapter.d.ts +0 -2
  70. package/dist/exports/adapter.d.ts.map +0 -1
  71. package/dist/exports/adapter.js +0 -8
  72. package/dist/exports/adapter.js.map +0 -1
  73. package/dist/exports/codec-types.d.ts +0 -11
  74. package/dist/exports/codec-types.d.ts.map +0 -1
  75. package/dist/exports/codec-types.js +0 -7
  76. package/dist/exports/codec-types.js.map +0 -1
  77. package/dist/exports/column-types.d.ts +0 -17
  78. package/dist/exports/column-types.d.ts.map +0 -1
  79. package/dist/exports/column-types.js +0 -49
  80. package/dist/exports/column-types.js.map +0 -1
  81. package/dist/exports/control.d.ts +0 -8
  82. package/dist/exports/control.d.ts.map +0 -1
  83. package/dist/exports/control.js +0 -279
  84. package/dist/exports/control.js.map +0 -1
  85. package/dist/exports/runtime.d.ts +0 -15
  86. package/dist/exports/runtime.d.ts.map +0 -1
  87. package/dist/exports/runtime.js +0 -20
  88. package/dist/exports/runtime.js.map +0 -1
  89. package/dist/exports/types.d.ts +0 -2
  90. package/dist/exports/types.d.ts.map +0 -1
  91. package/dist/exports/types.js +0 -1
  92. package/dist/exports/types.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codecs-C3wlpdV7.mjs","names":["arktype"],"sources":["../src/core/json-schema-type-expression.ts","../src/core/codecs.ts"],"sourcesContent":["type JsonSchemaRecord = Record<string, unknown>;\n\nconst MAX_DEPTH = 32;\n\nfunction isRecord(value: unknown): value is JsonSchemaRecord {\n return typeof value === 'object' && value !== null;\n}\n\nfunction escapeStringLiteral(str: string): string {\n return str\n .replace(/\\\\/g, '\\\\\\\\')\n .replace(/'/g, \"\\\\'\")\n .replace(/\\n/g, '\\\\n')\n .replace(/\\r/g, '\\\\r');\n}\n\nfunction quotePropertyKey(key: string): string {\n return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? key : `'${escapeStringLiteral(key)}'`;\n}\n\nfunction renderLiteral(value: unknown): string {\n if (typeof value === 'string') {\n return `'${escapeStringLiteral(value)}'`;\n }\n if (typeof value === 'number' || typeof value === 'boolean') {\n return String(value);\n }\n if (value === null) {\n return 'null';\n }\n return 'unknown';\n}\n\nfunction renderUnion(items: readonly unknown[], depth: number): string {\n const rendered = items.map((item) => render(item, depth));\n return rendered.join(' | ');\n}\n\nfunction renderObjectType(schema: JsonSchemaRecord, depth: number): string {\n const properties = isRecord(schema['properties']) ? schema['properties'] : {};\n const required = Array.isArray(schema['required'])\n ? new Set(schema['required'].filter((key): key is string => typeof key === 'string'))\n : new Set<string>();\n const keys = Object.keys(properties).sort((left, right) => left.localeCompare(right));\n\n if (keys.length === 0) {\n const additionalProperties = schema['additionalProperties'];\n if (additionalProperties === true || additionalProperties === undefined) {\n return 'Record<string, unknown>';\n }\n return `Record<string, ${render(additionalProperties, depth)}>`;\n }\n\n const renderedProperties = keys.map((key) => {\n const valueSchema = (properties as JsonSchemaRecord)[key];\n const optionalMarker = required.has(key) ? '' : '?';\n return `${quotePropertyKey(key)}${optionalMarker}: ${render(valueSchema, depth)}`;\n });\n\n return `{ ${renderedProperties.join('; ')} }`;\n}\n\nfunction renderArrayType(schema: JsonSchemaRecord, depth: number): string {\n if (Array.isArray(schema['items'])) {\n return `readonly [${schema['items'].map((item) => render(item, depth)).join(', ')}]`;\n }\n\n if (schema['items'] !== undefined) {\n const itemType = render(schema['items'], depth);\n const needsParens = itemType.includes(' | ') || itemType.includes(' & ');\n return needsParens ? `(${itemType})[]` : `${itemType}[]`;\n }\n\n return 'unknown[]';\n}\n\nfunction render(schema: unknown, depth: number): string {\n if (depth > MAX_DEPTH || !isRecord(schema)) {\n return 'JsonValue';\n }\n\n const nextDepth = depth + 1;\n\n if ('const' in schema) {\n return renderLiteral(schema['const']);\n }\n\n if (Array.isArray(schema['enum'])) {\n return schema['enum'].map((value) => renderLiteral(value)).join(' | ');\n }\n\n if (Array.isArray(schema['oneOf'])) {\n return renderUnion(schema['oneOf'], nextDepth);\n }\n\n if (Array.isArray(schema['anyOf'])) {\n return renderUnion(schema['anyOf'], nextDepth);\n }\n\n if (Array.isArray(schema['allOf'])) {\n return schema['allOf'].map((item) => render(item, nextDepth)).join(' & ');\n }\n\n if (Array.isArray(schema['type'])) {\n return schema['type'].map((item) => render({ ...schema, type: item }, nextDepth)).join(' | ');\n }\n\n switch (schema['type']) {\n case 'string':\n return 'string';\n case 'number':\n case 'integer':\n return 'number';\n case 'boolean':\n return 'boolean';\n case 'null':\n return 'null';\n case 'array':\n return renderArrayType(schema, nextDepth);\n case 'object':\n return renderObjectType(schema, nextDepth);\n default:\n break;\n }\n\n return 'JsonValue';\n}\n\nexport function renderTypeScriptTypeFromJsonSchema(schema: unknown): string {\n return render(schema, 0);\n}\n","/**\n * Unified codec definitions for Postgres adapter.\n *\n * This file contains a single source of truth for all codec information:\n * - Scalar names\n * - Type IDs\n * - Codec implementations (runtime)\n * - Type information (compile-time)\n *\n * This structure is used both at runtime (to populate the registry) and\n * at compile time (to derive CodecTypes).\n */\n\nimport type { JsonValue } from '@prisma-next/contract/types';\nimport type { Codec, CodecMeta, CodecTrait } from '@prisma-next/sql-relational-core/ast';\nimport { codec, defineCodecs, sqlCodecDefinitions } from '@prisma-next/sql-relational-core/ast';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { type as arktype } from 'arktype';\nimport {\n PG_BIT_CODEC_ID,\n PG_BOOL_CODEC_ID,\n PG_CHAR_CODEC_ID,\n PG_ENUM_CODEC_ID,\n PG_FLOAT_CODEC_ID,\n PG_FLOAT4_CODEC_ID,\n PG_FLOAT8_CODEC_ID,\n PG_INT_CODEC_ID,\n PG_INT2_CODEC_ID,\n PG_INT4_CODEC_ID,\n PG_INT8_CODEC_ID,\n PG_INTERVAL_CODEC_ID,\n PG_JSON_CODEC_ID,\n PG_JSONB_CODEC_ID,\n PG_NUMERIC_CODEC_ID,\n PG_TEXT_CODEC_ID,\n PG_TIME_CODEC_ID,\n PG_TIMESTAMP_CODEC_ID,\n PG_TIMESTAMPTZ_CODEC_ID,\n PG_TIMETZ_CODEC_ID,\n PG_VARBIT_CODEC_ID,\n PG_VARCHAR_CODEC_ID,\n} from './codec-ids';\nimport { renderTypeScriptTypeFromJsonSchema } from './json-schema-type-expression';\n\nconst lengthParamsSchema = arktype({\n length: 'number.integer > 0',\n});\n\nconst numericParamsSchema = arktype({\n precision: 'number.integer > 0 & number.integer <= 1000',\n 'scale?': 'number.integer >= 0',\n});\n\nconst precisionParamsSchema = arktype({\n 'precision?': 'number.integer >= 0 & number.integer <= 6',\n});\n\nfunction renderLength(typeName: string, typeParams: Record<string, unknown>): string | undefined {\n const length = typeParams['length'];\n if (length === undefined) {\n return undefined;\n }\n if (typeof length !== 'number' || !Number.isFinite(length) || !Number.isInteger(length)) {\n throw new Error(\n `renderOutputType: expected integer \"length\" in typeParams for ${typeName}, got ${String(length)}`,\n );\n }\n return `${typeName}<${length}>`;\n}\n\nfunction renderPrecision(typeName: string, typeParams: Record<string, unknown>): string {\n const precision = typeParams['precision'];\n if (precision === undefined) {\n return typeName;\n }\n if (\n typeof precision !== 'number' ||\n !Number.isFinite(precision) ||\n !Number.isInteger(precision)\n ) {\n throw new Error(\n `renderOutputType: expected integer \"precision\" in typeParams for ${typeName}, got ${String(precision)}`,\n );\n }\n return `${typeName}<${precision}>`;\n}\n\nfunction renderJsonOutputType(typeParams: Record<string, unknown>): string {\n const typeName = typeParams['type'];\n if (typeof typeName === 'string' && typeName.trim().length > 0) {\n return typeName.trim();\n }\n const schema = typeParams['schemaJson'];\n if (schema && typeof schema === 'object') {\n return renderTypeScriptTypeFromJsonSchema(schema);\n }\n throw new Error(\n `renderOutputType: JSON codec typeParams must contain \"type\" (string) or \"schemaJson\" (object), got keys: ${Object.keys(typeParams).join(', ')}`,\n );\n}\n\nfunction aliasCodec<\n Id extends string,\n TTraits extends readonly CodecTrait[],\n TWire,\n TJs,\n TParams,\n THelper,\n>(\n base: Codec<string, TTraits, TWire, TJs, TParams, THelper>,\n options: {\n readonly typeId: Id;\n readonly targetTypes: readonly string[];\n readonly meta?: CodecMeta;\n },\n): Codec<Id, TTraits, TWire, TJs, TParams, THelper> {\n return {\n id: options.typeId,\n targetTypes: options.targetTypes,\n ...ifDefined('meta', options.meta),\n ...ifDefined('paramsSchema', base.paramsSchema),\n ...ifDefined('init', base.init),\n ...ifDefined('encode', base.encode),\n ...ifDefined('traits', base.traits),\n ...ifDefined('renderOutputType', base.renderOutputType),\n decode: base.decode,\n encodeJson: base.encodeJson,\n decodeJson: base.decodeJson,\n } as Codec<Id, TTraits, TWire, TJs, TParams, THelper>;\n}\n\nconst sqlCharCodec = sqlCodecDefinitions.char.codec;\nconst sqlVarcharCodec = sqlCodecDefinitions.varchar.codec;\nconst sqlIntCodec = sqlCodecDefinitions.int.codec;\nconst sqlFloatCodec = sqlCodecDefinitions.float.codec;\nconst sqlTextCodec = sqlCodecDefinitions.text.codec;\nconst sqlTimestampCodec = sqlCodecDefinitions.timestamp.codec;\n\n// Create individual codec instances\nconst pgTextCodec = codec({\n typeId: PG_TEXT_CODEC_ID,\n targetTypes: ['text'],\n traits: ['equality', 'order', 'textual'],\n encode: (value: string): string => value,\n decode: (wire: string): string => wire,\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'text',\n },\n },\n },\n },\n});\n\nconst pgCharCodec = aliasCodec(sqlCharCodec, {\n typeId: PG_CHAR_CODEC_ID,\n targetTypes: ['character'],\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'character',\n },\n },\n },\n },\n});\n\nconst pgVarcharCodec = aliasCodec(sqlVarcharCodec, {\n typeId: PG_VARCHAR_CODEC_ID,\n targetTypes: ['character varying'],\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'character varying',\n },\n },\n },\n },\n});\n\nconst pgIntCodec = aliasCodec(sqlIntCodec, {\n typeId: PG_INT_CODEC_ID,\n targetTypes: ['int4'],\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'integer',\n },\n },\n },\n },\n});\n\nconst pgFloatCodec = aliasCodec(sqlFloatCodec, {\n typeId: PG_FLOAT_CODEC_ID,\n targetTypes: ['float8'],\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'double precision',\n },\n },\n },\n },\n});\n\nconst pgInt4Codec = codec({\n typeId: PG_INT4_CODEC_ID,\n targetTypes: ['int4'],\n traits: ['equality', 'order', 'numeric'],\n encode: (value: number): number => value,\n decode: (wire: number): number => wire,\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'integer',\n },\n },\n },\n },\n});\n\nconst pgNumericCodec = codec<\n typeof PG_NUMERIC_CODEC_ID,\n readonly ['equality', 'order', 'numeric'],\n string,\n string\n>({\n typeId: PG_NUMERIC_CODEC_ID,\n targetTypes: ['numeric', 'decimal'],\n traits: ['equality', 'order', 'numeric'],\n encode: (value: string): string => value,\n decode: (wire: string | number): string => {\n if (typeof wire === 'number') return String(wire);\n return wire;\n },\n paramsSchema: numericParamsSchema,\n renderOutputType: (typeParams) => {\n const precision = typeParams['precision'];\n if (precision === undefined) return undefined;\n if (\n typeof precision !== 'number' ||\n !Number.isFinite(precision) ||\n !Number.isInteger(precision)\n ) {\n throw new Error(\n `renderOutputType: expected integer \"precision\" in typeParams for Numeric, got ${String(precision)}`,\n );\n }\n const scale = typeParams['scale'];\n return typeof scale === 'number' ? `Numeric<${precision}, ${scale}>` : `Numeric<${precision}>`;\n },\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'numeric',\n },\n },\n },\n },\n});\n\nconst pgInt2Codec = codec({\n typeId: PG_INT2_CODEC_ID,\n targetTypes: ['int2'],\n traits: ['equality', 'order', 'numeric'],\n encode: (value: number): number => value,\n decode: (wire: number): number => wire,\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'smallint',\n },\n },\n },\n },\n});\n\nconst pgInt8Codec = codec({\n typeId: PG_INT8_CODEC_ID,\n targetTypes: ['int8'],\n traits: ['equality', 'order', 'numeric'],\n encode: (value: number): number => value,\n decode: (wire: number): number => wire,\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'bigint',\n },\n },\n },\n },\n});\n\nconst pgFloat4Codec = codec({\n typeId: PG_FLOAT4_CODEC_ID,\n targetTypes: ['float4'],\n traits: ['equality', 'order', 'numeric'],\n encode: (value: number): number => value,\n decode: (wire: number): number => wire,\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'real',\n },\n },\n },\n },\n});\n\nconst pgFloat8Codec = codec({\n typeId: PG_FLOAT8_CODEC_ID,\n targetTypes: ['float8'],\n traits: ['equality', 'order', 'numeric'],\n encode: (value: number): number => value,\n decode: (wire: number): number => wire,\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'double precision',\n },\n },\n },\n },\n});\n\nconst pgTimestampCodec = codec<\n typeof PG_TIMESTAMP_CODEC_ID,\n readonly ['equality', 'order'],\n string | Date,\n string | Date\n>({\n typeId: PG_TIMESTAMP_CODEC_ID,\n targetTypes: ['timestamp'],\n traits: ['equality', 'order'],\n encode: (value: string | Date): string => {\n if (value instanceof Date) return value.toISOString();\n if (typeof value === 'string') return value;\n return String(value);\n },\n decode: (wire: string | Date): string => {\n if (wire instanceof Date) return wire.toISOString();\n return wire;\n },\n encodeJson: (value: string | Date) => (value instanceof Date ? value.toISOString() : value),\n decodeJson: (json) => {\n if (typeof json !== 'string') {\n throw new Error(`Expected ISO date string for pg/timestamp@1, got ${typeof json}`);\n }\n const date = new Date(json);\n if (Number.isNaN(date.getTime())) {\n throw new Error(`Invalid ISO date string for pg/timestamp@1: ${json}`);\n }\n return date;\n },\n paramsSchema: precisionParamsSchema,\n renderOutputType: (typeParams) => renderPrecision('Timestamp', typeParams),\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'timestamp without time zone',\n },\n },\n },\n },\n});\n\nconst pgTimestamptzCodec = codec<\n typeof PG_TIMESTAMPTZ_CODEC_ID,\n readonly ['equality', 'order'],\n string | Date,\n string | Date\n>({\n typeId: PG_TIMESTAMPTZ_CODEC_ID,\n targetTypes: ['timestamptz'],\n traits: ['equality', 'order'],\n encode: (value: string | Date): string => {\n if (value instanceof Date) return value.toISOString();\n if (typeof value === 'string') return value;\n return String(value);\n },\n decode: (wire: string | Date): string => {\n if (wire instanceof Date) return wire.toISOString();\n return wire;\n },\n encodeJson: (value: string | Date) => (value instanceof Date ? value.toISOString() : value),\n decodeJson: (json) => {\n if (typeof json !== 'string') {\n throw new Error(`Expected ISO date string for pg/timestamptz@1, got ${typeof json}`);\n }\n const date = new Date(json);\n if (Number.isNaN(date.getTime())) {\n throw new Error(`Invalid ISO date string for pg/timestamptz@1: ${json}`);\n }\n return date;\n },\n paramsSchema: precisionParamsSchema,\n renderOutputType: (typeParams) => renderPrecision('Timestamptz', typeParams),\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'timestamp with time zone',\n },\n },\n },\n },\n});\n\nconst pgTimeCodec = codec<typeof PG_TIME_CODEC_ID, readonly ['equality', 'order'], string, string>({\n typeId: PG_TIME_CODEC_ID,\n targetTypes: ['time'],\n traits: ['equality', 'order'],\n encode: (value: string): string => value,\n decode: (wire: string): string => wire,\n paramsSchema: precisionParamsSchema,\n renderOutputType: (typeParams) => renderPrecision('Time', typeParams),\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'time',\n },\n },\n },\n },\n});\n\nconst pgTimetzCodec = codec<\n typeof PG_TIMETZ_CODEC_ID,\n readonly ['equality', 'order'],\n string,\n string\n>({\n typeId: PG_TIMETZ_CODEC_ID,\n targetTypes: ['timetz'],\n traits: ['equality', 'order'],\n encode: (value: string): string => value,\n decode: (wire: string): string => wire,\n paramsSchema: precisionParamsSchema,\n renderOutputType: (typeParams) => renderPrecision('Timetz', typeParams),\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'timetz',\n },\n },\n },\n },\n});\n\nconst pgBoolCodec = codec({\n typeId: PG_BOOL_CODEC_ID,\n targetTypes: ['bool'],\n traits: ['equality', 'boolean'],\n encode: (value: boolean): boolean => value,\n decode: (wire: boolean): boolean => wire,\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'boolean',\n },\n },\n },\n },\n});\n\nconst pgBitCodec = codec<typeof PG_BIT_CODEC_ID, readonly ['equality', 'order'], string, string>({\n typeId: PG_BIT_CODEC_ID,\n targetTypes: ['bit'],\n traits: ['equality', 'order'],\n encode: (value: string): string => value,\n decode: (wire: string): string => wire,\n paramsSchema: lengthParamsSchema,\n renderOutputType: (typeParams) => renderLength('Bit', typeParams),\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'bit',\n },\n },\n },\n },\n});\n\nconst pgVarbitCodec = codec<\n typeof PG_VARBIT_CODEC_ID,\n readonly ['equality', 'order'],\n string,\n string\n>({\n typeId: PG_VARBIT_CODEC_ID,\n targetTypes: ['bit varying'],\n traits: ['equality', 'order'],\n encode: (value: string): string => value,\n decode: (wire: string): string => wire,\n paramsSchema: lengthParamsSchema,\n renderOutputType: (typeParams) => renderLength('VarBit', typeParams),\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'bit varying',\n },\n },\n },\n },\n});\n\nconst pgEnumCodec = codec({\n typeId: PG_ENUM_CODEC_ID,\n targetTypes: ['enum'],\n traits: ['equality', 'order'],\n encode: (value: string): string => value,\n decode: (wire: string): string => wire,\n renderOutputType: (typeParams) => {\n const values = typeParams['values'];\n if (!Array.isArray(values)) {\n throw new Error(\n `renderOutputType: expected array \"values\" in typeParams for enum, got ${typeof values}`,\n );\n }\n return values\n .map((value) => `'${String(value).replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")}'`)\n .join(' | ');\n },\n});\n\nconst pgIntervalCodec = codec<\n typeof PG_INTERVAL_CODEC_ID,\n readonly ['equality', 'order'],\n string | Record<string, unknown>,\n string\n>({\n typeId: PG_INTERVAL_CODEC_ID,\n targetTypes: ['interval'],\n traits: ['equality', 'order'],\n encode: (value: string): string => value,\n decode: (wire: string | Record<string, unknown>): string => {\n if (typeof wire === 'string') return wire;\n return JSON.stringify(wire);\n },\n paramsSchema: precisionParamsSchema,\n renderOutputType: (typeParams) => renderPrecision('Interval', typeParams),\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'interval',\n },\n },\n },\n },\n});\n\nconst pgJsonCodec = codec({\n typeId: PG_JSON_CODEC_ID,\n targetTypes: ['json'],\n traits: [],\n encode: (value: string | JsonValue): string => JSON.stringify(value),\n decode: (wire: string | JsonValue): JsonValue =>\n typeof wire === 'string' ? JSON.parse(wire) : wire,\n renderOutputType: renderJsonOutputType,\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'json',\n },\n },\n },\n },\n});\n\nconst pgJsonbCodec = codec({\n typeId: PG_JSONB_CODEC_ID,\n targetTypes: ['jsonb'],\n traits: ['equality'],\n encode: (value: string | JsonValue): string => JSON.stringify(value),\n decode: (wire: string | JsonValue): JsonValue =>\n typeof wire === 'string' ? JSON.parse(wire) : wire,\n renderOutputType: renderJsonOutputType,\n meta: {\n db: {\n sql: {\n postgres: {\n nativeType: 'jsonb',\n },\n },\n },\n },\n});\n\n// Build codec definitions using the builder DSL\nconst codecs = defineCodecs()\n .add('char', sqlCharCodec)\n .add('varchar', sqlVarcharCodec)\n .add('int', sqlIntCodec)\n .add('float', sqlFloatCodec)\n .add('sql-text', sqlTextCodec)\n .add('sql-timestamp', sqlTimestampCodec)\n .add('text', pgTextCodec)\n .add('character', pgCharCodec)\n .add('character varying', pgVarcharCodec)\n .add('integer', pgIntCodec)\n .add('double precision', pgFloatCodec)\n .add('int4', pgInt4Codec)\n .add('int2', pgInt2Codec)\n .add('int8', pgInt8Codec)\n .add('float4', pgFloat4Codec)\n .add('float8', pgFloat8Codec)\n .add('numeric', pgNumericCodec)\n .add('timestamp', pgTimestampCodec)\n .add('timestamptz', pgTimestamptzCodec)\n .add('time', pgTimeCodec)\n .add('timetz', pgTimetzCodec)\n .add('bool', pgBoolCodec)\n .add('bit', pgBitCodec)\n .add('bit varying', pgVarbitCodec)\n .add('interval', pgIntervalCodec)\n .add('enum', pgEnumCodec)\n .add('json', pgJsonCodec)\n .add('jsonb', pgJsonbCodec);\n\n// Export derived structures directly from codecs builder\nexport const codecDefinitions = codecs.codecDefinitions;\nexport const dataTypes = codecs.dataTypes;\n\nexport type CodecTypes = typeof codecs.CodecTypes;\n"],"mappings":";;;;;;AAEA,MAAM,YAAY;AAElB,SAAS,SAAS,OAA2C;AAC3D,QAAO,OAAO,UAAU,YAAY,UAAU;;AAGhD,SAAS,oBAAoB,KAAqB;AAChD,QAAO,IACJ,QAAQ,OAAO,OAAO,CACtB,QAAQ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AAY,CACxB,IAAI,UAAU,cAAc,CAC5B,IAAI,UAAU,cAAc,CAC5B,IAAI,WAAW,eAAe,CAC9B,IAAI,aAAa,iBAAiB,CAClC,IAAI,eAAe,mBAAmB,CACtC,IAAI,QAAQ,YAAY,CACxB,IAAI,UAAU,cAAc,CAC5B,IAAI,QAAQ,YAAY,CACxB,IAAI,OAAO,WAAW,CACtB,IAAI,eAAe,cAAc,CACjC,IAAI,YAAY,gBAAgB,CAChC,IAAI,QAAQ,YAAY,CACxB,IAAI,QAAQ,YAAY,CACxB,IAAI,SAAS,aAAa;AAG7B,MAAa,mBAAmB,OAAO;AACvC,MAAa,YAAY,OAAO"}
@@ -0,0 +1,122 @@
1
+ import { StorageTypeInstance } from "@prisma-next/sql-contract/types";
2
+ import { ColumnTypeDescriptor } from "@prisma-next/contract-authoring";
3
+
4
+ //#region src/core/standard-schema.d.ts
5
+ type StandardSchemaJsonSchemaField = {
6
+ readonly output?: unknown;
7
+ };
8
+ /**
9
+ * Runtime view of the Standard Schema protocol.
10
+ * Reads `~standard.jsonSchema.output` for the serializable JSON Schema representation,
11
+ * and `.expression` for an optional TypeScript type expression string (Arktype-specific).
12
+ *
13
+ * This differs from the compile-time `StandardSchemaLike` in `codec-types.ts`, which reads
14
+ * `~standard.types.output` for TypeScript type narrowing in contract.d.ts.
15
+ */
16
+ type StandardSchemaLike = {
17
+ readonly '~standard'?: {
18
+ readonly version?: number;
19
+ readonly jsonSchema?: StandardSchemaJsonSchemaField;
20
+ };
21
+ readonly expression?: unknown;
22
+ };
23
+ //#endregion
24
+ //#region src/exports/column-types.d.ts
25
+ declare const textColumn: {
26
+ readonly codecId: "pg/text@1";
27
+ readonly nativeType: "text";
28
+ };
29
+ declare function charColumn(length: number): ColumnTypeDescriptor & {
30
+ readonly typeParams: {
31
+ readonly length: number;
32
+ };
33
+ };
34
+ declare function varcharColumn(length: number): ColumnTypeDescriptor & {
35
+ readonly typeParams: {
36
+ readonly length: number;
37
+ };
38
+ };
39
+ declare const int4Column: {
40
+ readonly codecId: "pg/int4@1";
41
+ readonly nativeType: "int4";
42
+ };
43
+ declare const int2Column: {
44
+ readonly codecId: "pg/int2@1";
45
+ readonly nativeType: "int2";
46
+ };
47
+ declare const int8Column: {
48
+ readonly codecId: "pg/int8@1";
49
+ readonly nativeType: "int8";
50
+ };
51
+ declare const float4Column: {
52
+ readonly codecId: "pg/float4@1";
53
+ readonly nativeType: "float4";
54
+ };
55
+ declare const float8Column: {
56
+ readonly codecId: "pg/float8@1";
57
+ readonly nativeType: "float8";
58
+ };
59
+ declare function numericColumn(precision: number, scale?: number): ColumnTypeDescriptor & {
60
+ readonly typeParams: {
61
+ readonly precision: number;
62
+ readonly scale?: number;
63
+ };
64
+ };
65
+ declare const timestampColumn: {
66
+ readonly codecId: "pg/timestamp@1";
67
+ readonly nativeType: "timestamp";
68
+ };
69
+ declare const timestamptzColumn: {
70
+ readonly codecId: "pg/timestamptz@1";
71
+ readonly nativeType: "timestamptz";
72
+ };
73
+ declare function timeColumn(precision?: number): ColumnTypeDescriptor & {
74
+ readonly typeParams?: {
75
+ readonly precision: number;
76
+ };
77
+ };
78
+ declare function timetzColumn(precision?: number): ColumnTypeDescriptor & {
79
+ readonly typeParams?: {
80
+ readonly precision: number;
81
+ };
82
+ };
83
+ declare const boolColumn: {
84
+ readonly codecId: "pg/bool@1";
85
+ readonly nativeType: "bool";
86
+ };
87
+ declare function bitColumn(length: number): ColumnTypeDescriptor & {
88
+ readonly typeParams: {
89
+ readonly length: number;
90
+ };
91
+ };
92
+ declare function varbitColumn(length: number): ColumnTypeDescriptor & {
93
+ readonly typeParams: {
94
+ readonly length: number;
95
+ };
96
+ };
97
+ declare function intervalColumn(precision?: number): ColumnTypeDescriptor & {
98
+ readonly typeParams?: {
99
+ readonly precision: number;
100
+ };
101
+ };
102
+ declare const jsonColumn: {
103
+ readonly codecId: "pg/json@1";
104
+ readonly nativeType: "json";
105
+ };
106
+ declare const jsonbColumn: {
107
+ readonly codecId: "pg/jsonb@1";
108
+ readonly nativeType: "jsonb";
109
+ };
110
+ declare function json(schema?: StandardSchemaLike): ColumnTypeDescriptor;
111
+ declare function jsonb(schema?: StandardSchemaLike): ColumnTypeDescriptor;
112
+ declare function enumType<const Values extends readonly string[]>(name: string, values: Values): StorageTypeInstance & {
113
+ readonly typeParams: {
114
+ readonly values: Values;
115
+ };
116
+ };
117
+ declare function enumColumn<TypeName extends string>(typeName: TypeName, nativeType: string): ColumnTypeDescriptor & {
118
+ readonly typeRef: TypeName;
119
+ };
120
+ //#endregion
121
+ export { bitColumn, boolColumn, charColumn, enumColumn, enumType, float4Column, float8Column, int2Column, int4Column, int8Column, intervalColumn, json, jsonColumn, jsonb, jsonbColumn, numericColumn, textColumn, timeColumn, timestampColumn, timestamptzColumn, timetzColumn, varbitColumn, varcharColumn };
122
+ //# sourceMappingURL=column-types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"column-types.d.mts","names":[],"sources":["../src/core/standard-schema.ts","../src/exports/column-types.ts"],"sourcesContent":[],"mappings":";;;;KAEK,6BAAA;;;AAFsB;AAc3B;;;;ACwBA;AAKA;AAUA;AAUa,KDjDD,kBAAA,GCoD6B;EAE5B,SAAA,WAG4B,CAAA,EAAA;IAE5B,SAG4B,OAAA,CAAA,EAAA,MAAA;IAE5B,SAAA,UAG4B,CAAA,EDhEf,6BCgEe;EAE5B,CAAA;EAKG,SAAA,UAAa,CAAA,EAAA,OAG1B;AAUH,CAAA;;;AA/Da,cAAA,UAG4B,EAAA;EAEzB,SAAA,OAAU,EAAA,WAAkB;EAU5B,SAAA,UAAa,EAAA,MAAkB;AAU/C,CAAA;AAKa,iBAzBG,UAAA,CA4ByB,MAAA,EAAA,MAAA,CAAA,EA5BG,oBA4BH,GAAA;EAE5B,SAAA,UAG4B,EAAA;IAE5B,SAAA,MAG4B,EAAA,MAAA;EAE5B,CAAA;AAKb,CAAA;AAaa,iBAhDG,aAAA,CAmDyB,MAAA,EAAA,MAAA,CAAA,EAn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C_ID, t as PG_BIT_CODEC_ID, u as PG_INT8_CODEC_ID, v as PG_TIMESTAMP_CODEC_ID, x as PG_VARBIT_CODEC_ID, y as PG_TIMETZ_CODEC_ID } from "./codec-ids-BwjcIf74.mjs";
2
+
3
+ //#region src/core/standard-schema.ts
4
+ function isObjectLike(value) {
5
+ return (typeof value === "object" || typeof value === "function") && value !== null;
6
+ }
7
+ function resolveOutputJsonSchemaField(schema) {
8
+ const jsonSchema = schema["~standard"]?.jsonSchema;
9
+ if (!jsonSchema) return;
10
+ if (typeof jsonSchema.output === "function") return jsonSchema.output({ target: "draft-07" });
11
+ return jsonSchema.output;
12
+ }
13
+ function extractStandardSchemaOutputJsonSchema(schema) {
14
+ const outputSchema = resolveOutputJsonSchemaField(schema);
15
+ if (!isObjectLike(outputSchema)) return;
16
+ return outputSchema;
17
+ }
18
+ function extractStandardSchemaTypeExpression(schema) {
19
+ const expression = schema.expression;
20
+ if (typeof expression !== "string") return;
21
+ const trimmedExpression = expression.trim();
22
+ if (trimmedExpression.length === 0) return;
23
+ return trimmedExpression;
24
+ }
25
+ function isStandardSchemaLike(value) {
26
+ return isObjectLike(value) && isObjectLike(value["~standard"]);
27
+ }
28
+
29
+ //#endregion
30
+ //#region src/exports/column-types.ts
31
+ const textColumn = {
32
+ codecId: PG_TEXT_CODEC_ID,
33
+ nativeType: "text"
34
+ };
35
+ function charColumn(length) {
36
+ return {
37
+ codecId: SQL_CHAR_CODEC_ID,
38
+ nativeType: "character",
39
+ typeParams: { length }
40
+ };
41
+ }
42
+ function varcharColumn(length) {
43
+ return {
44
+ codecId: SQL_VARCHAR_CODEC_ID,
45
+ nativeType: "character varying",
46
+ typeParams: { length }
47
+ };
48
+ }
49
+ const int4Column = {
50
+ codecId: PG_INT4_CODEC_ID,
51
+ nativeType: "int4"
52
+ };
53
+ const int2Column = {
54
+ codecId: PG_INT2_CODEC_ID,
55
+ nativeType: "int2"
56
+ };
57
+ const int8Column = {
58
+ codecId: PG_INT8_CODEC_ID,
59
+ nativeType: "int8"
60
+ };
61
+ const float4Column = {
62
+ codecId: PG_FLOAT4_CODEC_ID,
63
+ nativeType: "float4"
64
+ };
65
+ const float8Column = {
66
+ codecId: PG_FLOAT8_CODEC_ID,
67
+ nativeType: "float8"
68
+ };
69
+ function numericColumn(precision, scale) {
70
+ return {
71
+ codecId: PG_NUMERIC_CODEC_ID,
72
+ nativeType: "numeric",
73
+ typeParams: scale === void 0 ? { precision } : {
74
+ precision,
75
+ scale
76
+ }
77
+ };
78
+ }
79
+ const timestampColumn = {
80
+ codecId: PG_TIMESTAMP_CODEC_ID,
81
+ nativeType: "timestamp"
82
+ };
83
+ const timestamptzColumn = {
84
+ codecId: PG_TIMESTAMPTZ_CODEC_ID,
85
+ nativeType: "timestamptz"
86
+ };
87
+ function timeColumn(precision) {
88
+ return {
89
+ codecId: PG_TIME_CODEC_ID,
90
+ nativeType: "time",
91
+ ...precision === void 0 ? {} : { typeParams: { precision } }
92
+ };
93
+ }
94
+ function timetzColumn(precision) {
95
+ return {
96
+ codecId: PG_TIMETZ_CODEC_ID,
97
+ nativeType: "timetz",
98
+ ...precision === void 0 ? {} : { typeParams: { precision } }
99
+ };
100
+ }
101
+ const boolColumn = {
102
+ codecId: PG_BOOL_CODEC_ID,
103
+ nativeType: "bool"
104
+ };
105
+ function bitColumn(length) {
106
+ return {
107
+ codecId: PG_BIT_CODEC_ID,
108
+ nativeType: "bit",
109
+ typeParams: { length }
110
+ };
111
+ }
112
+ function varbitColumn(length) {
113
+ return {
114
+ codecId: PG_VARBIT_CODEC_ID,
115
+ nativeType: "bit varying",
116
+ typeParams: { length }
117
+ };
118
+ }
119
+ function intervalColumn(precision) {
120
+ return {
121
+ codecId: PG_INTERVAL_CODEC_ID,
122
+ nativeType: "interval",
123
+ ...precision === void 0 ? {} : { typeParams: { precision } }
124
+ };
125
+ }
126
+ const jsonColumn = {
127
+ codecId: PG_JSON_CODEC_ID,
128
+ nativeType: "json"
129
+ };
130
+ const jsonbColumn = {
131
+ codecId: PG_JSONB_CODEC_ID,
132
+ nativeType: "jsonb"
133
+ };
134
+ function createJsonTypeParams(schema) {
135
+ const outputSchema = extractStandardSchemaOutputJsonSchema(schema);
136
+ if (!outputSchema) throw new Error("JSON schema must expose ~standard.jsonSchema.output()");
137
+ const expression = extractStandardSchemaTypeExpression(schema);
138
+ if (expression) return {
139
+ schemaJson: outputSchema,
140
+ type: expression
141
+ };
142
+ return { schemaJson: outputSchema };
143
+ }
144
+ function createJsonColumnFactory(codecId, nativeType, staticDescriptor) {
145
+ return (schema) => {
146
+ if (!schema) return staticDescriptor;
147
+ if (!isStandardSchemaLike(schema)) throw new Error(`${nativeType}(schema) expects a Standard Schema value`);
148
+ return {
149
+ codecId,
150
+ nativeType,
151
+ typeParams: createJsonTypeParams(schema)
152
+ };
153
+ };
154
+ }
155
+ const _json = createJsonColumnFactory(PG_JSON_CODEC_ID, "json", jsonColumn);
156
+ const _jsonb = createJsonColumnFactory(PG_JSONB_CODEC_ID, "jsonb", jsonbColumn);
157
+ function json(schema) {
158
+ return _json(schema);
159
+ }
160
+ function jsonb(schema) {
161
+ return _jsonb(schema);
162
+ }
163
+ function enumType(name, values) {
164
+ return {
165
+ codecId: PG_ENUM_CODEC_ID,
166
+ nativeType: name,
167
+ typeParams: { values }
168
+ };
169
+ }
170
+ function enumColumn(typeName, nativeType) {
171
+ return {
172
+ codecId: PG_ENUM_CODEC_ID,
173
+ nativeType,
174
+ typeRef: typeName
175
+ };
176
+ }
177
+
178
+ //#endregion
179
+ export { bitColumn, boolColumn, charColumn, enumColumn, enumType, float4Column, float8Column, int2Column, int4Column, int8Column, intervalColumn, json, jsonColumn, jsonb, jsonbColumn, numericColumn, textColumn, timeColumn, timestampColumn, timestamptzColumn, timetzColumn, varbitColumn, varcharColumn };
180
+ //# sourceMappingURL=column-types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"column-types.mjs","names":[],"sources":["../src/core/standard-schema.ts","../src/exports/column-types.ts"],"sourcesContent":["type UnknownRecord = Record<string, unknown>;\n\ntype StandardSchemaJsonSchemaField = {\n readonly output?: unknown;\n};\n\n/**\n * Runtime view of the Standard Schema protocol.\n * Reads `~standard.jsonSchema.output` for the serializable JSON Schema representation,\n * and `.expression` for an optional TypeScript type expression string (Arktype-specific).\n *\n * This differs from the compile-time `StandardSchemaLike` in `codec-types.ts`, which reads\n * `~standard.types.output` for TypeScript type narrowing in contract.d.ts.\n */\nexport type StandardSchemaLike = {\n readonly '~standard'?: {\n readonly version?: number;\n readonly jsonSchema?: StandardSchemaJsonSchemaField;\n };\n readonly expression?: unknown;\n};\n\nfunction isObjectLike(value: unknown): value is UnknownRecord {\n return (typeof value === 'object' || typeof value === 'function') && value !== null;\n}\n\nfunction resolveOutputJsonSchemaField(schema: StandardSchemaLike): unknown {\n const jsonSchema = schema['~standard']?.jsonSchema;\n if (!jsonSchema) {\n return undefined;\n }\n\n if (typeof jsonSchema.output === 'function') {\n return jsonSchema.output({\n target: 'draft-07',\n });\n }\n\n return jsonSchema.output;\n}\n\nexport function extractStandardSchemaOutputJsonSchema(\n schema: StandardSchemaLike,\n): UnknownRecord | undefined {\n const outputSchema = resolveOutputJsonSchemaField(schema);\n if (!isObjectLike(outputSchema)) {\n return undefined;\n }\n\n return outputSchema;\n}\n\nexport function extractStandardSchemaTypeExpression(\n schema: StandardSchemaLike,\n): string | undefined {\n const expression = schema.expression;\n if (typeof expression !== 'string') {\n return undefined;\n }\n\n const trimmedExpression = expression.trim();\n if (trimmedExpression.length === 0) {\n return undefined;\n }\n\n return trimmedExpression;\n}\n\nexport function isStandardSchemaLike(value: unknown): value is StandardSchemaLike {\n return isObjectLike(value) && isObjectLike((value as StandardSchemaLike)['~standard']);\n}\n","/**\n * Column type descriptors for Postgres adapter.\n *\n * These descriptors provide both codecId and nativeType for use in contract authoring.\n * They are derived from the same source of truth as codec definitions and manifests.\n */\n\nimport type { ColumnTypeDescriptor } from '@prisma-next/contract-authoring';\nimport type { StorageTypeInstance } from '@prisma-next/sql-contract/types';\nimport {\n PG_BIT_CODEC_ID,\n PG_BOOL_CODEC_ID,\n PG_ENUM_CODEC_ID,\n PG_FLOAT4_CODEC_ID,\n PG_FLOAT8_CODEC_ID,\n PG_INT2_CODEC_ID,\n PG_INT4_CODEC_ID,\n PG_INT8_CODEC_ID,\n PG_INTERVAL_CODEC_ID,\n PG_JSON_CODEC_ID,\n PG_JSONB_CODEC_ID,\n PG_NUMERIC_CODEC_ID,\n PG_TEXT_CODEC_ID,\n PG_TIME_CODEC_ID,\n PG_TIMESTAMP_CODEC_ID,\n PG_TIMESTAMPTZ_CODEC_ID,\n PG_TIMETZ_CODEC_ID,\n PG_VARBIT_CODEC_ID,\n SQL_CHAR_CODEC_ID,\n SQL_VARCHAR_CODEC_ID,\n} from '../core/codec-ids';\nimport {\n extractStandardSchemaOutputJsonSchema,\n extractStandardSchemaTypeExpression,\n isStandardSchemaLike,\n type StandardSchemaLike,\n} from '../core/standard-schema';\n\nexport const textColumn = {\n codecId: PG_TEXT_CODEC_ID,\n nativeType: 'text',\n} as const satisfies ColumnTypeDescriptor;\n\nexport function charColumn(length: number): ColumnTypeDescriptor & {\n readonly typeParams: { readonly length: number };\n} {\n return {\n codecId: SQL_CHAR_CODEC_ID,\n nativeType: 'character',\n typeParams: { length },\n } as const;\n}\n\nexport function varcharColumn(length: number): ColumnTypeDescriptor & {\n readonly typeParams: { readonly length: number };\n} {\n return {\n codecId: SQL_VARCHAR_CODEC_ID,\n nativeType: 'character varying',\n typeParams: { length },\n } as const;\n}\n\nexport const int4Column = {\n codecId: PG_INT4_CODEC_ID,\n nativeType: 'int4',\n} as const satisfies ColumnTypeDescriptor;\n\nexport const int2Column = {\n codecId: PG_INT2_CODEC_ID,\n nativeType: 'int2',\n} as const satisfies ColumnTypeDescriptor;\n\nexport const int8Column = {\n codecId: PG_INT8_CODEC_ID,\n nativeType: 'int8',\n} as const satisfies ColumnTypeDescriptor;\n\nexport const float4Column = {\n codecId: PG_FLOAT4_CODEC_ID,\n nativeType: 'float4',\n} as const satisfies ColumnTypeDescriptor;\n\nexport const float8Column = {\n codecId: PG_FLOAT8_CODEC_ID,\n nativeType: 'float8',\n} as const satisfies ColumnTypeDescriptor;\n\nexport function numericColumn(\n precision: number,\n scale?: number,\n): ColumnTypeDescriptor & {\n readonly typeParams: { readonly precision: number; readonly scale?: number };\n} {\n return {\n codecId: PG_NUMERIC_CODEC_ID,\n nativeType: 'numeric',\n typeParams: scale === undefined ? { precision } : { precision, scale },\n } as const;\n}\n\nexport const timestampColumn = {\n codecId: PG_TIMESTAMP_CODEC_ID,\n nativeType: 'timestamp',\n} as const satisfies ColumnTypeDescriptor;\n\nexport const timestamptzColumn = {\n codecId: PG_TIMESTAMPTZ_CODEC_ID,\n nativeType: 'timestamptz',\n} as const satisfies ColumnTypeDescriptor;\n\nexport function timeColumn(precision?: number): ColumnTypeDescriptor & {\n readonly typeParams?: { readonly precision: number };\n} {\n return {\n codecId: PG_TIME_CODEC_ID,\n nativeType: 'time',\n ...(precision === undefined ? {} : { typeParams: { precision } }),\n } as const;\n}\n\nexport function timetzColumn(precision?: number): ColumnTypeDescriptor & {\n readonly typeParams?: { readonly precision: number };\n} {\n return {\n codecId: PG_TIMETZ_CODEC_ID,\n nativeType: 'timetz',\n ...(precision === undefined ? {} : { typeParams: { precision } }),\n } as const;\n}\n\nexport const boolColumn = {\n codecId: PG_BOOL_CODEC_ID,\n nativeType: 'bool',\n} as const satisfies ColumnTypeDescriptor;\n\nexport function bitColumn(length: number): ColumnTypeDescriptor & {\n readonly typeParams: { readonly length: number };\n} {\n return {\n codecId: PG_BIT_CODEC_ID,\n nativeType: 'bit',\n typeParams: { length },\n } as const;\n}\n\nexport function varbitColumn(length: number): ColumnTypeDescriptor & {\n readonly typeParams: { readonly length: number };\n} {\n return {\n codecId: PG_VARBIT_CODEC_ID,\n nativeType: 'bit varying',\n typeParams: { length },\n } as const;\n}\n\nexport function intervalColumn(precision?: number): ColumnTypeDescriptor & {\n readonly typeParams?: { readonly precision: number };\n} {\n return {\n codecId: PG_INTERVAL_CODEC_ID,\n nativeType: 'interval',\n ...(precision === undefined ? {} : { typeParams: { precision } }),\n } as const;\n}\n\nexport const jsonColumn = {\n codecId: PG_JSON_CODEC_ID,\n nativeType: 'json',\n} as const satisfies ColumnTypeDescriptor;\n\nexport const jsonbColumn = {\n codecId: PG_JSONB_CODEC_ID,\n nativeType: 'jsonb',\n} as const satisfies ColumnTypeDescriptor;\n\ntype JsonSchemaTypeParams = {\n readonly schemaJson: Record<string, unknown>;\n readonly type?: string;\n};\n\nfunction createJsonTypeParams(schema: StandardSchemaLike): JsonSchemaTypeParams {\n const outputSchema = extractStandardSchemaOutputJsonSchema(schema);\n if (!outputSchema) {\n throw new Error('JSON schema must expose ~standard.jsonSchema.output()');\n }\n\n const expression = extractStandardSchemaTypeExpression(schema);\n if (expression) {\n return { schemaJson: outputSchema, type: expression };\n }\n\n return { schemaJson: outputSchema };\n}\n\nfunction createJsonColumnFactory(\n codecId: string,\n nativeType: string,\n staticDescriptor: ColumnTypeDescriptor,\n) {\n return (schema?: StandardSchemaLike): ColumnTypeDescriptor => {\n if (!schema) {\n return staticDescriptor;\n }\n\n if (!isStandardSchemaLike(schema)) {\n throw new Error(`${nativeType}(schema) expects a Standard Schema value`);\n }\n\n return {\n codecId,\n nativeType,\n typeParams: createJsonTypeParams(schema),\n };\n };\n}\n\nconst _json = createJsonColumnFactory(PG_JSON_CODEC_ID, 'json', jsonColumn);\nconst _jsonb = createJsonColumnFactory(PG_JSONB_CODEC_ID, 'jsonb', jsonbColumn);\n\nexport function json(schema?: StandardSchemaLike): ColumnTypeDescriptor {\n return _json(schema);\n}\n\nexport function jsonb(schema?: StandardSchemaLike): ColumnTypeDescriptor {\n return _jsonb(schema);\n}\n\nexport function enumType<const Values extends readonly string[]>(\n name: string,\n values: Values,\n): StorageTypeInstance & { readonly typeParams: { readonly values: Values } } {\n return {\n codecId: PG_ENUM_CODEC_ID,\n nativeType: name,\n typeParams: { values },\n } as const;\n}\n\nexport function enumColumn<TypeName extends string>(\n typeName: TypeName,\n nativeType: string,\n): ColumnTypeDescriptor & { readonly typeRef: TypeName } {\n return {\n codecId: PG_ENUM_CODEC_ID,\n nativeType,\n typeRef: typeName,\n };\n}\n"],"mappings":";;;AAsBA,SAAS,aAAa,OAAwC;AAC5D,SAAQ,OAAO,UAAU,YAAY,OAAO,UAAU,eAAe,UAAU;;AAGjF,SAAS,6BAA6B,QAAqC;CACzE,MAAM,aAAa,OAAO,cAAc;AACxC,KAAI,CAAC,WACH;AAGF,KAAI,OAAO,WAAW,WAAW,WAC/B,QAAO,WAAW,OAAO,EACvB,QAAQ,YACT,CAAC;AAGJ,QAAO,WAAW;;AAGpB,SAAgB,sCACd,QAC2B;CAC3B,MAAM,eAAe,6BAA6B,OAAO;AACzD,KAAI,CAAC,aAAa,aAAa,CAC7B;AAGF,QAAO;;AAGT,SAAgB,oCACd,QACoB;CACpB,MAAM,aAAa,OAAO;AAC1B,KAAI,OAAO,eAAe,SACxB;CAGF,MAAM,oBAAoB,WAAW,MAAM;AAC3C,KAAI,kBAAkB,WAAW,EAC/B;AAGF,QAAO;;AAGT,SAAgB,qBAAqB,OAA6C;AAChF,QAAO,aAAa,MAAM,IAAI,aAAc,MAA6B,aAAa;;;;;AC/BxF,MAAa,aAAa;CACxB,SAAS;CACT,YAAY;CACb;AAED,SAAgB,WAAW,QAEzB;AACA,QAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,EAAE,QAAQ;EACvB;;AAGH,SAAgB,cAAc,QAE5B;AACA,QAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,EAAE,QAAQ;EACvB;;AAGH,MAAa,aAAa;CACxB,SAAS;CACT,YAAY;CACb;AAED,MAAa,aAAa;CACxB,SAAS;CACT,YAAY;CACb;AAED,MAAa,aAAa;CACxB,SAAS;CACT,YAAY;CACb;AAED,MAAa,eAAe;CAC1B,SAAS;CACT,YAAY;CACb;AAED,MAAa,eAAe;CAC1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SAAQ,WAAsD;AAC5D,MAAI,CAAC,OACH,QAAO;AAGT,MAAI,CAAC,qBAAqB,OAAO,CAC/B,OAAM,IAAI,MAAM,GAAG,WAAW,0CAA0C;AAG1E,SAAO;GACL;GACA;GACA,YAAY,qBAAqB,OAAO;GACzC;;;AAIL,MAAM,QAAQ,wBAAwB,kBAAkB,QAAQ,WAAW;AAC3E,MAAM,SAAS,wBAAwB,mBAAmB,SAAS,YAAY;AAE/E,SAAgB,KAAK,QAAmD;AACtE,QAAO,MAAM,OAAO;;AAGtB,SAAgB,MAAM,QAAmD;AACvE,QAAO,OAAO,OAAO;;AAGvB,SAAgB,SACd,MACA,QAC4E;AAC5E,QAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,EAAE,QAAQ;EACvB;;AAGH,SAAgB,WACd,UACA,YACuD;AACvD,QAAO;EACL,SAAS;EACT;EACA,SAAS;EACV"}
@@ -0,0 +1,77 @@
1
+ import { ColumnDefault } from "@prisma-next/contract/types";
2
+ import { SqlControlAdapterDescriptor } from "@prisma-next/family-sql/control";
3
+
4
+ //#region src/core/sql-utils.d.ts
5
+
6
+ /**
7
+ * Shared SQL utility functions for the Postgres adapter.
8
+ *
9
+ * These functions handle safe SQL identifier and literal escaping
10
+ * with security validations to prevent injection and encoding issues.
11
+ */
12
+ /**
13
+ * Error thrown when an invalid SQL identifier or literal is detected.
14
+ * Boundary layers map this to structured envelopes.
15
+ */
16
+ declare class SqlEscapeError extends Error {
17
+ readonly value: string;
18
+ readonly kind: 'identifier' | 'literal';
19
+ constructor(message: string, value: string, kind: 'identifier' | 'literal');
20
+ }
21
+ /**
22
+ * Validates and quotes a PostgreSQL identifier (table, column, type, schema names).
23
+ *
24
+ * Security validations:
25
+ * - Rejects null bytes which could cause truncation or unexpected behavior
26
+ * - Rejects empty identifiers
27
+ * - Warns on identifiers exceeding PostgreSQL's 63-character limit
28
+ *
29
+ * @throws {SqlEscapeError} If the identifier contains null bytes or is empty
30
+ */
31
+ declare function quoteIdentifier(identifier: string): string;
32
+ /**
33
+ * Escapes a string literal for safe use in SQL statements.
34
+ *
35
+ * Security validations:
36
+ * - Rejects null bytes which could cause truncation or unexpected behavior
37
+ *
38
+ * Note: This assumes PostgreSQL's `standard_conforming_strings` is ON (default since PG 9.1).
39
+ * Backslashes are treated as literal characters, not escape sequences.
40
+ *
41
+ * @throws {SqlEscapeError} If the value contains null bytes
42
+ */
43
+ declare function escapeLiteral(value: string): string;
44
+ /**
45
+ * Builds a qualified name (schema.object) with proper quoting.
46
+ */
47
+ declare function qualifyName(schemaName: string, objectName: string): string;
48
+ //#endregion
49
+ //#region src/core/default-normalizer.d.ts
50
+ /**
51
+ * Parses a raw Postgres column default expression into a normalized ColumnDefault.
52
+ * This enables semantic comparison between contract defaults and introspected schema defaults.
53
+ *
54
+ * Used by the migration diff layer to normalize raw database defaults during comparison,
55
+ * keeping the introspection layer focused on faithful data capture.
56
+ *
57
+ * @param rawDefault - Raw default expression from information_schema.columns.column_default
58
+ * @param nativeType - Native column type, used for type-aware parsing (bigint tagging, JSON detection)
59
+ * @returns Normalized ColumnDefault or undefined if the expression cannot be parsed
60
+ */
61
+ declare function parsePostgresDefault(rawDefault: string, nativeType?: string): ColumnDefault | undefined;
62
+ //#endregion
63
+ //#region src/core/control-adapter.d.ts
64
+
65
+ /**
66
+ * Normalizes a Postgres schema native type to its canonical form for comparison.
67
+ *
68
+ * Uses a pre-computed lookup map for simple prefix replacements (O(1))
69
+ * and handles complex temporal type normalization separately.
70
+ */
71
+ declare function normalizeSchemaNativeType(nativeType: string): string;
72
+ //#endregion
73
+ //#region src/exports/control.d.ts
74
+ declare const postgresAdapterDescriptor: SqlControlAdapterDescriptor<'postgres'>;
75
+ //#endregion
76
+ export { SqlEscapeError, postgresAdapterDescriptor as default, escapeLiteral, normalizeSchemaNativeType, parsePostgresDefault, qualifyName, quoteIdentifier };
77
+ //# sourceMappingURL=control.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/sql-utils.ts","../src/core/default-normalizer.ts","../src/core/control-adapter.ts","../src/exports/control.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAWA;AA0BA;AAiCA;AAcA;;;cAzEa,cAAA,SAAuB,KAAA;ECuDpB,SAAA,KAAA,EAAA,MAAA;;;;ACsZhB;;;;AC/cgG;;;;;;iBH4BhF,eAAA;;;;;;;;;;;;iBAiCA,aAAA;;;;iBAcA,WAAA;;;;;;AAzEhB;AA0BA;AAiCA;AAcA;;;;AClBA;iBAAgB,oBAAA,2CAGb;;;;;;;;;;iBCmZa,yBAAA;;;cC7cV,2BAA2B"}