@prisma-next/ids
Advanced tools
| import type { StructuredError, StructuredErrorOptions } from '@prisma-next/utils/structured-error'; | ||
| import { structuredError } from '@prisma-next/utils/structured-error'; | ||
| export type ContractCode = `CONTRACT.${ContractSubcode}`; | ||
| type ContractSubcode = 'ARGUMENT_INVALID'; | ||
| export function contractError( | ||
| code: ContractCode, | ||
| message: string, | ||
| options?: StructuredErrorOptions, | ||
| ): StructuredError { | ||
| return structuredError(code, message, options); | ||
| } |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.mts","names":[],"sources":["../src/generator-ids.ts","../src/generators.ts","../src/index.ts"],"mappings":";;;;;;;;;cAAa;KASD,6BAA6B;;;KCDpC,SAAS,aAAa,uBAAsB,YAAY,qBACzD,+BAEE;KAGM;WACD,MAAM,gBAAgB;WACtB,QAAQ,gBAAgB;WACxB,QAAQ,gBAAgB;WACxB,QAAQ,gBAAgB;WACxB,OAAO,gBAAgB;WACvB,OAAO,gBAAgB;;;;KCZtB;WACD,MAAM;WACN,aAAa;;cA8EX,kCAAkC;WACpC,IAAI;WACJ;;iBAMK,wCAAwC;WAC7C,IAAI;WACJ,SAAS;IAChB;KAQQ,oBAAoB;WACrB,MAAM,qBAAqB;WAC3B;WACA,aAAa;WACb,WAAW;;cA2BT,OAAQ,UAAU,mCAA8B;cAEhD,SAAU,UAAU,qCAAgC;cAEpD,SAAU,UAAU,qCAAgC;cAEpD,SAAU,UAAU,qCAAgC;cAEpD,QAAS,UAAU,oCAA+B;cAElD,QAAS,UAAU,oCAA+B"} | ||
| {"version":3,"file":"index.d.mts","names":[],"sources":["../src/generator-ids.ts","../src/generators.ts","../src/index.ts"],"mappings":";;;;;;;;;cAAa;KASD,6BAA6B;;;KCDpC,SAAS,aAAa,uBAAsB,YAAY,qBACzD,+BAEE;KAGM;WACD,MAAM,gBAAgB;WACtB,QAAQ,gBAAgB;WACxB,QAAQ,gBAAgB;WACxB,QAAQ,gBAAgB;WACxB,OAAO,gBAAgB;WACvB,OAAO,gBAAgB;;;;KCXtB;WACD,MAAM;WACN,aAAa;;cAkFX,kCAAkC;WACpC,IAAI;WACJ;;iBAMK,wCAAwC;WAC7C,IAAI;WACJ,SAAS;IAChB;KAQQ,oBAAoB;WACrB,MAAM,qBAAqB;WAC3B;WACA,aAAa;WACb,WAAW;;cA2BT,OAAQ,UAAU,mCAA8B;cAEhD,SAAU,UAAU,qCAAgC;cAEpD,SAAU,UAAU,qCAAgC;cAEpD,SAAU,UAAU,qCAAgC;cAEpD,QAAS,UAAU,oCAA+B;cAElD,QAAS,UAAU,oCAA+B"} |
+11
-1
| import { ifDefined } from "@prisma-next/utils/defined"; | ||
| import { structuredError } from "@prisma-next/utils/structured-error"; | ||
| //#region src/contract-errors.ts | ||
| function contractError(code, message, options) { | ||
| return structuredError(code, message, options); | ||
| } | ||
| //#endregion | ||
| //#region src/generator-ids.ts | ||
@@ -22,3 +28,7 @@ const builtinGeneratorIds = [ | ||
| }; | ||
| if (typeof rawSize !== "number" || !Number.isInteger(rawSize) || rawSize < 2 || rawSize > 255) throw new Error("nanoid size must be an integer between 2 and 255"); | ||
| if (typeof rawSize !== "number" || !Number.isInteger(rawSize) || rawSize < 2 || rawSize > 255) throw contractError("CONTRACT.ARGUMENT_INVALID", "nanoid size must be an integer between 2 and 255", { meta: { | ||
| helperPath: "nanoid", | ||
| paramName: "size", | ||
| received: rawSize | ||
| } }); | ||
| return { | ||
@@ -25,0 +35,0 @@ type: { |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.mjs","names":[],"sources":["../src/generator-ids.ts","../src/index.ts"],"sourcesContent":["export const builtinGeneratorIds = [\n 'ulid',\n 'nanoid',\n 'uuidv7',\n 'uuidv4',\n 'cuid2',\n 'ksuid',\n] as const;\n\nexport type BuiltinGeneratorId = (typeof builtinGeneratorIds)[number];\n","import type { ExecutionMutationDefaultValue } from '@prisma-next/contract/types';\nimport type { ColumnTypeDescriptor } from '@prisma-next/framework-components/codec';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { type BuiltinGeneratorId, builtinGeneratorIds } from './generator-ids';\nimport type { IdGeneratorOptionsById } from './generators';\n\nexport { builtinGeneratorIds };\n\nexport type GeneratedColumnDescriptor = {\n readonly type: ColumnTypeDescriptor;\n readonly typeParams?: Record<string, unknown>;\n};\n\ntype BuiltinGeneratorMetadata = {\n readonly applicableCodecIds: readonly string[];\n readonly generatedColumnDescriptor: GeneratedColumnDescriptor;\n readonly resolveGeneratedColumnDescriptor?: (\n params?: Record<string, unknown>,\n ) => GeneratedColumnDescriptor;\n};\n\nfunction resolveNanoidColumnDescriptor(\n params?: Record<string, unknown>,\n): GeneratedColumnDescriptor {\n const rawSize = params?.['size'];\n if (rawSize === undefined) {\n return {\n type: { codecId: 'sql/char@1', nativeType: 'character' },\n typeParams: { length: 21 },\n };\n }\n\n if (typeof rawSize !== 'number' || !Number.isInteger(rawSize) || rawSize < 2 || rawSize > 255) {\n throw new Error('nanoid size must be an integer between 2 and 255');\n }\n\n return {\n type: { codecId: 'sql/char@1', nativeType: 'character' },\n typeParams: { length: rawSize },\n };\n}\n\nconst builtinGeneratorMetadataById = {\n ulid: {\n applicableCodecIds: ['pg/text@1', 'sql/char@1'],\n generatedColumnDescriptor: {\n type: { codecId: 'sql/char@1', nativeType: 'character' },\n typeParams: { length: 26 },\n },\n },\n nanoid: {\n applicableCodecIds: ['pg/text@1', 'sql/char@1'],\n generatedColumnDescriptor: {\n type: { codecId: 'sql/char@1', nativeType: 'character' },\n typeParams: { length: 21 },\n },\n resolveGeneratedColumnDescriptor: resolveNanoidColumnDescriptor,\n },\n uuidv7: {\n applicableCodecIds: ['pg/text@1', 'sql/char@1', 'pg/uuid@1'],\n generatedColumnDescriptor: {\n type: { codecId: 'sql/char@1', nativeType: 'character' },\n typeParams: { length: 36 },\n },\n },\n uuidv4: {\n applicableCodecIds: ['pg/text@1', 'sql/char@1', 'pg/uuid@1'],\n generatedColumnDescriptor: {\n type: { codecId: 'sql/char@1', nativeType: 'character' },\n typeParams: { length: 36 },\n },\n },\n cuid2: {\n applicableCodecIds: ['pg/text@1', 'sql/char@1'],\n generatedColumnDescriptor: {\n type: { codecId: 'sql/char@1', nativeType: 'character' },\n typeParams: { length: 24 },\n },\n },\n ksuid: {\n applicableCodecIds: ['pg/text@1', 'sql/char@1'],\n generatedColumnDescriptor: {\n type: { codecId: 'sql/char@1', nativeType: 'character' },\n typeParams: { length: 27 },\n },\n },\n} as const satisfies Record<BuiltinGeneratorId, BuiltinGeneratorMetadata>;\n\nexport const builtinGeneratorRegistryMetadata: ReadonlyArray<{\n readonly id: BuiltinGeneratorId;\n readonly applicableCodecIds: readonly string[];\n}> = builtinGeneratorIds.map((id) => ({\n id,\n applicableCodecIds: builtinGeneratorMetadataById[id].applicableCodecIds,\n}));\n\nexport function resolveBuiltinGeneratedColumnDescriptor(input: {\n readonly id: BuiltinGeneratorId;\n readonly params?: Record<string, unknown>;\n}): GeneratedColumnDescriptor {\n const metadata: BuiltinGeneratorMetadata = builtinGeneratorMetadataById[input.id];\n if (metadata.resolveGeneratedColumnDescriptor) {\n return metadata.resolveGeneratedColumnDescriptor(input.params);\n }\n return metadata.generatedColumnDescriptor;\n}\n\nexport type GeneratedColumnSpec<TCodecId extends string = string> = {\n readonly type: ColumnTypeDescriptor<TCodecId>;\n readonly nullable?: false;\n readonly typeParams?: Record<string, unknown>;\n readonly generated: ExecutionMutationDefaultValue;\n};\n\ntype GeneratorCodecId<TId extends BuiltinGeneratorId> =\n (typeof builtinGeneratorMetadataById)[TId]['generatedColumnDescriptor']['type']['codecId'];\n\nfunction createGeneratedSpec<TId extends BuiltinGeneratorId>(\n id: TId,\n options?: IdGeneratorOptionsById[TId],\n): GeneratedColumnSpec<GeneratorCodecId<TId>> {\n const params = options as Record<string, unknown> | undefined;\n const resolvedDescriptor = resolveBuiltinGeneratedColumnDescriptor({\n id,\n ...ifDefined('params', params),\n });\n return {\n type: resolvedDescriptor.type,\n nullable: false,\n ...ifDefined('typeParams', resolvedDescriptor.typeParams),\n generated: {\n kind: 'generator',\n id,\n ...ifDefined('params', params),\n },\n } as GeneratedColumnSpec<GeneratorCodecId<TId>>;\n}\n\nexport const ulid = (options?: IdGeneratorOptionsById['ulid']) =>\n createGeneratedSpec('ulid', options);\nexport const nanoid = (options?: IdGeneratorOptionsById['nanoid']) =>\n createGeneratedSpec('nanoid', options);\nexport const uuidv7 = (options?: IdGeneratorOptionsById['uuidv7']) =>\n createGeneratedSpec('uuidv7', options);\nexport const uuidv4 = (options?: IdGeneratorOptionsById['uuidv4']) =>\n createGeneratedSpec('uuidv4', options);\nexport const cuid2 = (options?: IdGeneratorOptionsById['cuid2']) =>\n createGeneratedSpec('cuid2', options);\nexport const ksuid = (options?: IdGeneratorOptionsById['ksuid']) =>\n createGeneratedSpec('ksuid', options);\n"],"mappings":";;AAAA,MAAa,sBAAsB;CACjC;CACA;CACA;CACA;CACA;CACA;AACF;;;ACcA,SAAS,8BACP,QAC2B;CAC3B,MAAM,UAAU,SAAS;CACzB,IAAI,YAAY,KAAA,GACd,OAAO;EACL,MAAM;GAAE,SAAS;GAAc,YAAY;EAAY;EACvD,YAAY,EAAE,QAAQ,GAAG;CAC3B;CAGF,IAAI,OAAO,YAAY,YAAY,CAAC,OAAO,UAAU,OAAO,KAAK,UAAU,KAAK,UAAU,KACxF,MAAM,IAAI,MAAM,kDAAkD;CAGpE,OAAO;EACL,MAAM;GAAE,SAAS;GAAc,YAAY;EAAY;EACvD,YAAY,EAAE,QAAQ,QAAQ;CAChC;AACF;AAEA,MAAM,+BAA+B;CACnC,MAAM;EACJ,oBAAoB,CAAC,aAAa,YAAY;EAC9C,2BAA2B;GACzB,MAAM;IAAE,SAAS;IAAc,YAAY;GAAY;GACvD,YAAY,EAAE,QAAQ,GAAG;EAC3B;CACF;CACA,QAAQ;EACN,oBAAoB,CAAC,aAAa,YAAY;EAC9C,2BAA2B;GACzB,MAAM;IAAE,SAAS;IAAc,YAAY;GAAY;GACvD,YAAY,EAAE,QAAQ,GAAG;EA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AAa,UAAU,YACrB,oBAAoB,UAAU,OAAO;AACvC,MAAa,UAAU,YACrB,oBAAoB,UAAU,OAAO;AACvC,MAAa,SAAS,YACpB,oBAAoB,SAAS,OAAO;AACtC,MAAa,SAAS,YACpB,oBAAoB,SAAS,OAAO"} | ||
| {"version":3,"file":"index.mjs","names":[],"sources":["../src/contract-errors.ts","../src/generator-ids.ts","../src/index.ts"],"sourcesContent":["import type { StructuredError, StructuredErrorOptions } from '@prisma-next/utils/structured-error';\nimport { structuredError } from '@prisma-next/utils/structured-error';\n\nexport type ContractCode = `CONTRACT.${ContractSubcode}`;\n\ntype ContractSubcode = 'ARGUMENT_INVALID';\n\nexport function contractError(\n code: ContractCode,\n message: string,\n options?: StructuredErrorOptions,\n): StructuredError {\n return structuredError(code, message, options);\n}\n","export const builtinGeneratorIds = [\n 'ulid',\n 'nanoid',\n 'uuidv7',\n 'uuidv4',\n 'cuid2',\n 'ksuid',\n] as const;\n\nexport type BuiltinGeneratorId = (typeof builtinGeneratorIds)[number];\n","import type { ExecutionMutationDefaultValue } from '@prisma-next/contract/types';\nimport type { ColumnTypeDescriptor } from '@prisma-next/framework-components/codec';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { contractError } from './contract-errors';\nimport { type BuiltinGeneratorId, builtinGeneratorIds } from './generator-ids';\nimport type { IdGeneratorOptionsById } from './generators';\n\nexport { builtinGeneratorIds };\n\nexport type GeneratedColumnDescriptor = {\n readonly type: ColumnTypeDescriptor;\n readonly typeParams?: Record<string, unknown>;\n};\n\ntype BuiltinGeneratorMetadata = {\n readonly applicableCodecIds: readonly string[];\n readonly generatedColumnDescriptor: GeneratedColumnDescriptor;\n readonly resolveGeneratedColumnDescriptor?: (\n params?: Record<string, unknown>,\n ) => GeneratedColumnDescriptor;\n};\n\nfunction resolveNanoidColumnDescriptor(\n params?: Record<string, unknown>,\n): GeneratedColumnDescriptor {\n const rawSize = params?.['size'];\n if (rawSize === undefined) {\n return {\n type: { codecId: 'sql/char@1', nativeType: 'character' },\n typeParams: { length: 21 },\n };\n }\n\n if (typeof rawSize !== 'number' || !Number.isInteger(rawSize) || rawSize < 2 || rawSize > 255) {\n throw contractError(\n 'CONTRACT.ARGUMENT_INVALID',\n 'nanoid size must be an integer between 2 and 255',\n { meta: { helperPath: 'nanoid', paramName: 'size', received: rawSize } },\n );\n }\n\n return {\n type: { codecId: 'sql/char@1', nativeType: 'character' },\n typeParams: { length: rawSize },\n };\n}\n\nconst builtinGeneratorMetadataById = {\n ulid: {\n applicableCodecIds: ['pg/text@1', 'sql/char@1'],\n generatedColumnDescriptor: {\n type: { codecId: 'sql/char@1', nativeType: 'character' },\n typeParams: { length: 26 },\n },\n },\n nanoid: {\n applicableCodecIds: ['pg/text@1', 'sql/char@1'],\n generatedColumnDescriptor: {\n type: { codecId: 'sql/char@1', nativeType: 'character' },\n typeParams: { length: 21 },\n },\n resolveGeneratedColumnDescriptor: resolveNanoidColumnDescriptor,\n },\n uuidv7: {\n applicableCodecIds: ['pg/text@1', 'sql/char@1', 'pg/uuid@1'],\n generatedColumnDescriptor: {\n type: { codecId: 'sql/char@1', nativeType: 'character' },\n typeParams: { length: 36 },\n },\n },\n uuidv4: {\n applicableCodecIds: ['pg/text@1', 'sql/char@1', 'pg/uuid@1'],\n generatedColumnDescriptor: {\n type: { codecId: 'sql/char@1', nativeType: 'character' },\n typeParams: { length: 36 },\n },\n },\n cuid2: {\n applicableCodecIds: ['pg/text@1', 'sql/char@1'],\n generatedColumnDescriptor: {\n type: { codecId: 'sql/char@1', nativeType: 'character' },\n typeParams: { length: 24 },\n },\n },\n ksuid: {\n applicableCodecIds: ['pg/text@1', 'sql/char@1'],\n generatedColumnDescriptor: {\n type: { codecId: 'sql/char@1', nativeType: 'character' },\n typeParams: { length: 27 },\n },\n },\n} as const satisfies Record<BuiltinGeneratorId, BuiltinGeneratorMetadata>;\n\nexport const builtinGeneratorRegistryMetadata: ReadonlyArray<{\n readonly id: BuiltinGeneratorId;\n readonly applicableCodecIds: readonly string[];\n}> = builtinGeneratorIds.map((id) => ({\n id,\n applicableCodecIds: builtinGeneratorMetadataById[id].applicableCodecIds,\n}));\n\nexport function resolveBuiltinGeneratedColumnDescriptor(input: {\n readonly id: BuiltinGeneratorId;\n readonly params?: Record<string, unknown>;\n}): GeneratedColumnDescriptor {\n const metadata: BuiltinGeneratorMetadata = builtinGeneratorMetadataById[input.id];\n if (metadata.resolveGeneratedColumnDescriptor) {\n return metadata.resolveGeneratedColumnDescriptor(input.params);\n }\n return metadata.generatedColumnDescriptor;\n}\n\nexport type GeneratedColumnSpec<TCodecId extends string = string> = {\n readonly type: ColumnTypeDescriptor<TCodecId>;\n readonly nullable?: false;\n readonly typeParams?: Record<string, unknown>;\n readonly generated: ExecutionMutationDefaultValue;\n};\n\ntype GeneratorCodecId<TId extends BuiltinGeneratorId> =\n (typeof builtinGeneratorMetadataById)[TId]['generatedColumnDescriptor']['type']['codecId'];\n\nfunction createGeneratedSpec<TId extends BuiltinGeneratorId>(\n id: TId,\n options?: IdGeneratorOptionsById[TId],\n): GeneratedColumnSpec<GeneratorCodecId<TId>> {\n const params = options as Record<string, unknown> | undefined;\n const resolvedDescriptor = resolveBuiltinGeneratedColumnDescriptor({\n id,\n ...ifDefined('params', params),\n });\n return {\n type: resolvedDescriptor.type,\n nullable: false,\n ...ifDefined('typeParams', resolvedDescriptor.typeParams),\n generated: {\n kind: 'generator',\n id,\n ...ifDefined('params', params),\n },\n } as GeneratedColumnSpec<GeneratorCodecId<TId>>;\n}\n\nexport const ulid = (options?: IdGeneratorOptionsById['ulid']) =>\n createGeneratedSpec('ulid', options);\nexport const nanoid = (options?: IdGeneratorOptionsById['nanoid']) =>\n createGeneratedSpec('nanoid', options);\nexport const uuidv7 = (options?: IdGeneratorOptionsById['uuidv7']) =>\n createGeneratedSpec('uuidv7', options);\nexport const uuidv4 = (options?: IdGeneratorOptionsById['uuidv4']) =>\n createGeneratedSpec('uuidv4', options);\nexport const cuid2 = (options?: IdGeneratorOptionsById['cuid2']) =>\n createGeneratedSpec('cuid2', options);\nexport const ksuid = (options?: IdGeneratorOptionsById['ksuid']) =>\n createGeneratedSpec('ksuid', options);\n"],"mappings":";;;AAOA,SAAgB,cACd,MACA,SACA,SACiB;CACjB,OAAO,gBAAgB,MAAM,SAAS,OAAO;AAC/C;;;ACbA,MAAa,sBAAsB;CACjC;CACA;CACA;CACA;CACA;CACA;AACF;;;ACeA,SAAS,8BACP,QAC2B;CAC3B,MAAM,UAAU,SAAS;CACzB,IAAI,YAAY,KAAA,GACd,OAAO;EACL,MAAM;GAAE,SAAS;GAAc,YAAY;EAAY;EACvD,YAAY,EAAE,QAAQ,GAAG;CAC3B;CAGF,IAAI,OAAO,YAAY,YAAY,CAAC,OAAO,UAAU,OAAO,KAAK,UAAU,KAAK,UAAU,KACxF,MAAM,cACJ,6BACA,oDACA,EAAE,MAAM;EAAE,YAAY;EAAU,WAAW;EAAQ,UAAU;CAAQ,EAAE,CACzE;CAGF,OAAO;EACL,MAAM;GAAE,SAAS;GAAc,YAAY;EAAY;EACvD,YAAY,EAAE,QAAQ,QAAQ;CAChC;AACF;AAEA,MAAM,+BAA+B;CACnC,MAAM;EACJ,oBAAoB,CAAC,aAAa,YAAY;EAC9C,2BAA2B;GACzB,MAAM;IAAE,SAAS;IAAc,YAAY;GAAY;GACvD,YAAY,EAAE,QAAQ,GAAG;EAC3B;CACF;CACA,QAAQ;EACN,oBAAoB,CAAC,aAAa,YAAY;EAC9C,2BAA2B;GACzB,MAAM;IAAE,SAAS;IAAc,YAAY;GAAY;GACvD,YAAY,EAAE,QAAQ,GAAG;EAC3B;EACA,kCAAkC;CACpC;CACA,QAAQ;EACN,oBAAoB;GAAC;GAAa;GAAc;EAAW;EAC3D,2BAA2B;GACzB,MAAM;IAAE,SAAS;IAAc,YAAY;GAAY;GACvD,YAAY,EAAE,QAAQ,GAAG;EAC3B;CACF;CACA,QAAQ;EACN,oBAAoB;GAAC;GAAa;GAAc;EAAW;EAC3D,2BAA2B;G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.ts"],"mappings":";;iBAQgB,WAAW,MAAM"} | ||
| {"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/runtime.ts"],"mappings":";;iBASgB,WAAW,MAAM"} |
+2
-1
@@ -0,1 +1,2 @@ | ||
| import { InternalError } from "@prisma-next/utils/internal-error"; | ||
| import { cuid2 } from "uniku/cuid2"; | ||
@@ -26,3 +27,3 @@ import { ksuid } from "uniku/ksuid"; | ||
| function generateId(spec) { | ||
| if (!isBuiltinGeneratorId(spec.id)) throw new Error(`Unknown built-in ID generator "${spec.id}".`); | ||
| if (!isBuiltinGeneratorId(spec.id)) throw new InternalError(`Unknown built-in ID generator "${spec.id}".`); | ||
| return idGenerators[spec.id](spec.params); | ||
@@ -29,0 +30,0 @@ } |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"runtime.mjs","names":["ulidGenerator","nanoidGenerator","uuidv7Generator","uuidv4Generator","cuid2Generator","ksuidGenerator"],"sources":["../src/generators.ts","../src/runtime.ts"],"sourcesContent":["import { cuid2 as cuid2Generator } from 'uniku/cuid2';\nimport { ksuid as ksuidGenerator } from 'uniku/ksuid';\nimport { nanoid as nanoidGenerator } from 'uniku/nanoid';\nimport { ulid as ulidGenerator } from 'uniku/ulid';\nimport { uuidv4 as uuidv4Generator } from 'uniku/uuid/v4';\nimport { uuidv7 as uuidv7Generator } from 'uniku/uuid/v7';\nimport type { BuiltinGeneratorId } from './generator-ids';\n\ntype FirstArg<TFunction> = TFunction extends (...args: infer TArgs) => unknown\n ? TArgs extends []\n ? undefined\n : TArgs[0]\n : never;\n\nexport type IdGeneratorOptionsById = {\n readonly ulid: FirstArg<typeof ulidGenerator>;\n readonly nanoid: FirstArg<typeof nanoidGenerator>;\n readonly uuidv7: FirstArg<typeof uuidv7Generator>;\n readonly uuidv4: FirstArg<typeof uuidv4Generator>;\n readonly cuid2: FirstArg<typeof cuid2Generator>;\n readonly ksuid: FirstArg<typeof ksuidGenerator>;\n};\n\ntype IdGenerator = (params?: Record<string, unknown>) => string;\n\nfunction invokeGenerator<TOptions>(\n generator: (options?: TOptions) => string,\n params?: Record<string, unknown>,\n): string {\n if (params === undefined) {\n return generator();\n }\n return generator(params as TOptions);\n}\n\nexport const idGenerators = {\n ulid: (params?: Record<string, unknown>) => invokeGenerator(ulidGenerator, params),\n nanoid: (params?: Record<string, unknown>) => invokeGenerator(nanoidGenerator, params),\n uuidv7: (params?: Record<string, unknown>) => invokeGenerator(uuidv7Generator, params),\n uuidv4: (params?: Record<string, unknown>) => invokeGenerator(uuidv4Generator, params),\n cuid2: (params?: Record<string, unknown>) => invokeGenerator(cuid2Generator, params),\n ksuid: (params?: Record<string, unknown>) => invokeGenerator(ksuidGenerator, params),\n} as const satisfies Record<BuiltinGeneratorId, IdGenerator>;\n","import type { GeneratedValueSpec } from '@prisma-next/contract/types';\nimport type { BuiltinGeneratorId } from './generator-ids';\nimport { idGenerators } from './generators';\n\nfunction isBuiltinGeneratorId(id: string): id is BuiltinGeneratorId {\n return Object.hasOwn(idGenerators, id);\n}\n\nexport function generateId(spec: GeneratedValueSpec): string {\n if (!isBuiltinGeneratorId(spec.id)) {\n throw new Error(`Unknown built-in ID generator \"${spec.id}\".`);\n }\n return idGenerators[spec.id](spec.params);\n}\n"],"mappings":";;;;;;;AAyBA,SAAS,gBACP,WACA,QACQ;CACR,IAAI,WAAW,KAAA,GACb,OAAO,UAAU;CAEnB,OAAO,UAAU,MAAkB;AACrC;AAEA,MAAa,eAAe;CAC1B,OAAO,WAAqC,gBAAgBA,MAAe,MAAM;CACjF,SAAS,WAAqC,gBAAgBC,QAAiB,MAAM;CACrF,SAAS,WAAqC,gBAAgBC,QAAiB,MAAM;CACrF,SAAS,WAAqC,gBAAgBC,QAAiB,MAAM;CACrF,QAAQ,WAAqC,gBAAgBC,OAAgB,MAAM;CACnF,QAAQ,WAAqC,gBAAgBC,OAAgB,MAAM;AACrF;;;ACtCA,SAAS,qBAAqB,IAAsC;CAClE,OAAO,OAAO,OAAO,cAAc,EAAE;AACvC;AAEA,SAAgB,WAAW,MAAkC;CAC3D,IAAI,CAAC,qBAAqB,KAAK,EAAE,GAC/B,MAAM,IAAI,MAAM,kCAAkC,KAAK,GAAG,GAAG;CAE/D,OAAO,aAAa,KAAK,GAAG,CAAC,KAAK,MAAM;AAC1C"} | ||
| {"version":3,"file":"runtime.mjs","names":["ulidGenerator","nanoidGenerator","uuidv7Generator","uuidv4Generator","cuid2Generator","ksuidGenerator"],"sources":["../src/generators.ts","../src/runtime.ts"],"sourcesContent":["import { cuid2 as cuid2Generator } from 'uniku/cuid2';\nimport { ksuid as ksuidGenerator } from 'uniku/ksuid';\nimport { nanoid as nanoidGenerator } from 'uniku/nanoid';\nimport { ulid as ulidGenerator } from 'uniku/ulid';\nimport { uuidv4 as uuidv4Generator } from 'uniku/uuid/v4';\nimport { uuidv7 as uuidv7Generator } from 'uniku/uuid/v7';\nimport type { BuiltinGeneratorId } from './generator-ids';\n\ntype FirstArg<TFunction> = TFunction extends (...args: infer TArgs) => unknown\n ? TArgs extends []\n ? undefined\n : TArgs[0]\n : never;\n\nexport type IdGeneratorOptionsById = {\n readonly ulid: FirstArg<typeof ulidGenerator>;\n readonly nanoid: FirstArg<typeof nanoidGenerator>;\n readonly uuidv7: FirstArg<typeof uuidv7Generator>;\n readonly uuidv4: FirstArg<typeof uuidv4Generator>;\n readonly cuid2: FirstArg<typeof cuid2Generator>;\n readonly ksuid: FirstArg<typeof ksuidGenerator>;\n};\n\ntype IdGenerator = (params?: Record<string, unknown>) => string;\n\nfunction invokeGenerator<TOptions>(\n generator: (options?: TOptions) => string,\n params?: Record<string, unknown>,\n): string {\n if (params === undefined) {\n return generator();\n }\n return generator(params as TOptions);\n}\n\nexport const idGenerators = {\n ulid: (params?: Record<string, unknown>) => invokeGenerator(ulidGenerator, params),\n nanoid: (params?: Record<string, unknown>) => invokeGenerator(nanoidGenerator, params),\n uuidv7: (params?: Record<string, unknown>) => invokeGenerator(uuidv7Generator, params),\n uuidv4: (params?: Record<string, unknown>) => invokeGenerator(uuidv4Generator, params),\n cuid2: (params?: Record<string, unknown>) => invokeGenerator(cuid2Generator, params),\n ksuid: (params?: Record<string, unknown>) => invokeGenerator(ksuidGenerator, params),\n} as const satisfies Record<BuiltinGeneratorId, IdGenerator>;\n","import type { GeneratedValueSpec } from '@prisma-next/contract/types';\nimport { InternalError } from '@prisma-next/utils/internal-error';\nimport type { BuiltinGeneratorId } from './generator-ids';\nimport { idGenerators } from './generators';\n\nfunction isBuiltinGeneratorId(id: string): id is BuiltinGeneratorId {\n return Object.hasOwn(idGenerators, id);\n}\n\nexport function generateId(spec: GeneratedValueSpec): string {\n if (!isBuiltinGeneratorId(spec.id)) {\n throw new InternalError(`Unknown built-in ID generator \"${spec.id}\".`);\n }\n return idGenerators[spec.id](spec.params);\n}\n"],"mappings":";;;;;;;;AAyBA,SAAS,gBACP,WACA,QACQ;CACR,IAAI,WAAW,KAAA,GACb,OAAO,UAAU;CAEnB,OAAO,UAAU,MAAkB;AACrC;AAEA,MAAa,eAAe;CAC1B,OAAO,WAAqC,gBAAgBA,MAAe,MAAM;CACjF,SAAS,WAAqC,gBAAgBC,QAAiB,MAAM;CACrF,SAAS,WAAqC,gBAAgBC,QAAiB,MAAM;CACrF,SAAS,WAAqC,gBAAgBC,QAAiB,MAAM;CACrF,QAAQ,WAAqC,gBAAgBC,OAAgB,MAAM;CACnF,QAAQ,WAAqC,gBAAgBC,OAAgB,MAAM;AACrF;;;ACrCA,SAAS,qBAAqB,IAAsC;CAClE,OAAO,OAAO,OAAO,cAAc,EAAE;AACvC;AAEA,SAAgB,WAAW,MAAkC;CAC3D,IAAI,CAAC,qBAAqB,KAAK,EAAE,GAC/B,MAAM,IAAI,cAAc,kCAAkC,KAAK,GAAG,GAAG;CAEvE,OAAO,aAAa,KAAK,GAAG,CAAC,KAAK,MAAM;AAC1C"} |
+6
-6
| { | ||
| "name": "@prisma-next/ids", | ||
| "version": "0.16.0-dev.6", | ||
| "version": "0.16.0-dev.9", | ||
| "license": "Apache-2.0", | ||
@@ -9,10 +9,10 @@ "type": "module", | ||
| "dependencies": { | ||
| "@prisma-next/contract": "0.16.0-dev.6", | ||
| "@prisma-next/framework-components": "0.16.0-dev.6", | ||
| "@prisma-next/utils": "0.16.0-dev.6", | ||
| "@prisma-next/contract": "0.16.0-dev.9", | ||
| "@prisma-next/framework-components": "0.16.0-dev.9", | ||
| "@prisma-next/utils": "0.16.0-dev.9", | ||
| "uniku": "^0.3.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@prisma-next/tsconfig": "0.16.0-dev.6", | ||
| "@prisma-next/tsdown": "0.16.0-dev.6", | ||
| "@prisma-next/tsconfig": "0.16.0-dev.9", | ||
| "@prisma-next/tsdown": "0.16.0-dev.9", | ||
| "tsdown": "0.22.8", | ||
@@ -19,0 +19,0 @@ "typescript": "5.9.3", |
+6
-1
| import type { ExecutionMutationDefaultValue } from '@prisma-next/contract/types'; | ||
| import type { ColumnTypeDescriptor } from '@prisma-next/framework-components/codec'; | ||
| import { ifDefined } from '@prisma-next/utils/defined'; | ||
| import { contractError } from './contract-errors'; | ||
| import { type BuiltinGeneratorId, builtinGeneratorIds } from './generator-ids'; | ||
@@ -34,3 +35,7 @@ import type { IdGeneratorOptionsById } from './generators'; | ||
| if (typeof rawSize !== 'number' || !Number.isInteger(rawSize) || rawSize < 2 || rawSize > 255) { | ||
| throw new Error('nanoid size must be an integer between 2 and 255'); | ||
| throw contractError( | ||
| 'CONTRACT.ARGUMENT_INVALID', | ||
| 'nanoid size must be an integer between 2 and 255', | ||
| { meta: { helperPath: 'nanoid', paramName: 'size', received: rawSize } }, | ||
| ); | ||
| } | ||
@@ -37,0 +42,0 @@ |
+2
-1
| import type { GeneratedValueSpec } from '@prisma-next/contract/types'; | ||
| import { InternalError } from '@prisma-next/utils/internal-error'; | ||
| import type { BuiltinGeneratorId } from './generator-ids'; | ||
@@ -11,5 +12,5 @@ import { idGenerators } from './generators'; | ||
| if (!isBuiltinGeneratorId(spec.id)) { | ||
| throw new Error(`Unknown built-in ID generator "${spec.id}".`); | ||
| throw new InternalError(`Unknown built-in ID generator "${spec.id}".`); | ||
| } | ||
| return idGenerators[spec.id](spec.params); | ||
| } |
44288
4.77%16
6.67%389
7.76%+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed