@prisma-next/ids 0.3.0-dev.99 → 0.3.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/README.md CHANGED
@@ -31,14 +31,24 @@ flowchart LR
31
31
  ## Usage
32
32
 
33
33
  ```ts
34
- import { defineContract } from '@prisma-next/sql-contract-ts/contract-builder';
34
+ import { textColumn } from '@prisma-next/adapter-postgres/column-types';
35
+ import sqlFamily from '@prisma-next/family-sql/pack';
35
36
  import { uuidv4 } from '@prisma-next/ids';
36
-
37
- export const contract = defineContract()
38
- .table('user', (t) =>
39
- t.generated('id', uuidv4()).column('email', { type: { codecId: 'pg/text@1', nativeType: 'text' } }),
40
- )
41
- .build();
37
+ import { defineContract, field, model } from '@prisma-next/sql-contract-ts/contract-builder';
38
+ import postgresPack from '@prisma-next/target-postgres/pack';
39
+
40
+ export const contract = defineContract({
41
+ family: sqlFamily,
42
+ target: postgresPack,
43
+ models: {
44
+ User: model('User', {
45
+ fields: {
46
+ id: field.generated(uuidv4()).id(),
47
+ email: field.column(textColumn),
48
+ },
49
+ }).sql({ table: 'user' }),
50
+ },
51
+ });
42
52
  ```
43
53
 
44
54
  Pass generator options directly (for helpers whose `uniku` implementation supports them):
package/dist/index.d.mts CHANGED
@@ -35,18 +35,18 @@ declare function resolveBuiltinGeneratedColumnDescriptor(input: {
35
35
  readonly id: BuiltinGeneratorId;
36
36
  readonly params?: Record<string, unknown>;
37
37
  }): GeneratedColumnDescriptor;
38
- type GeneratedColumnSpec = {
39
- readonly type: ColumnTypeDescriptor;
38
+ type GeneratedColumnSpec<TCodecId extends string = string> = {
39
+ readonly type: ColumnTypeDescriptor<TCodecId>;
40
40
  readonly nullable?: false;
41
41
  readonly typeParams?: Record<string, unknown>;
42
42
  readonly generated: ExecutionMutationDefaultValue;
43
43
  };
44
- declare const ulid: (options?: IdGeneratorOptionsById["ulid"]) => GeneratedColumnSpec;
45
- declare const nanoid: (options?: IdGeneratorOptionsById["nanoid"]) => GeneratedColumnSpec;
46
- declare const uuidv7: (options?: IdGeneratorOptionsById["uuidv7"]) => GeneratedColumnSpec;
47
- declare const uuidv4: (options?: IdGeneratorOptionsById["uuidv4"]) => GeneratedColumnSpec;
48
- declare const cuid2: (options?: IdGeneratorOptionsById["cuid2"]) => GeneratedColumnSpec;
49
- declare const ksuid: (options?: IdGeneratorOptionsById["ksuid"]) => GeneratedColumnSpec;
44
+ declare const ulid: (options?: IdGeneratorOptionsById["ulid"]) => GeneratedColumnSpec<"sql/char@1">;
45
+ declare const nanoid: (options?: IdGeneratorOptionsById["nanoid"]) => GeneratedColumnSpec<"sql/char@1">;
46
+ declare const uuidv7: (options?: IdGeneratorOptionsById["uuidv7"]) => GeneratedColumnSpec<"sql/char@1">;
47
+ declare const uuidv4: (options?: IdGeneratorOptionsById["uuidv4"]) => GeneratedColumnSpec<"sql/char@1">;
48
+ declare const cuid2: (options?: IdGeneratorOptionsById["cuid2"]) => GeneratedColumnSpec<"sql/char@1">;
49
+ declare const ksuid: (options?: IdGeneratorOptionsById["ksuid"]) => GeneratedColumnSpec<"sql/char@1">;
50
50
  //#endregion
51
51
  export { GeneratedColumnDescriptor, GeneratedColumnSpec, builtinGeneratorIds, builtinGeneratorRegistryMetadata, cuid2, ksuid, nanoid, resolveBuiltinGeneratedColumnDescriptor, ulid, uuidv4, uuidv7 };
52
52
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/generator-ids.ts","../src/generators.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;cAAa;KASD,kBAAA,WAA6B;;;KCDpC,sBAAsB,uFAGrB;KAGM,sBAAA;iBACK,gBAAgB;mBACd,gBAAgB;EDhBtB,SAAA,MAAA,ECiBM,QDVT,CAAA,OCUyB,QDVzB,CAAA;EAEE,SAAA,MAAA,ECSO,QDTW,CAAA,OCSK,QDTM,CAAA;kBCUvB,gBAAgB;kBAChB,gBAAgB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;AACgB,cC8HrB,KD9HqB,EAAA,CAAA,OAAA,CAAA,EC8HF,sBD9HE,CAAA,OAAA,CAAA,EAAA,GC8H6B,mBD9H7B,CAAA,YAAA,CAAA;AAAhB,cCgIL,KDhIK,EAAA,CAAA,OAAA,CAAA,ECgIc,sBDhId,CAAA,OAAA,CAAA,EAAA,GCgI6C,mBDhI7C,CAAA,YAAA,CAAA"}
package/dist/index.mjs CHANGED
@@ -99,8 +99,7 @@ const builtinGeneratorRegistryMetadata = builtinGeneratorIds.map((id) => ({
99
99
  }));
100
100
  function resolveBuiltinGeneratedColumnDescriptor(input) {
101
101
  const metadata = builtinGeneratorMetadataById[input.id];
102
- const resolver = metadata.resolveGeneratedColumnDescriptor;
103
- if (resolver) return resolver(input.params);
102
+ if (metadata.resolveGeneratedColumnDescriptor) return metadata.resolveGeneratedColumnDescriptor(input.params);
104
103
  return metadata.generatedColumnDescriptor;
105
104
  }
106
105
  function createGeneratedSpec(id, options) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["builtinGeneratorMetadataById: Record<BuiltinGeneratorId, BuiltinGeneratorMetadata>","builtinGeneratorRegistryMetadata: ReadonlyArray<{\n readonly id: BuiltinGeneratorId;\n readonly applicableCodecIds: readonly string[];\n}>"],"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/contract-authoring';\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: Record<BuiltinGeneratorId, BuiltinGeneratorMetadata> = {\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'],\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'],\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};\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 = builtinGeneratorMetadataById[input.id];\n const resolver = metadata.resolveGeneratedColumnDescriptor;\n if (resolver) {\n return resolver(input.params);\n }\n return metadata.generatedColumnDescriptor;\n}\n\nexport type GeneratedColumnSpec = {\n readonly type: ColumnTypeDescriptor;\n readonly nullable?: false;\n readonly typeParams?: Record<string, unknown>;\n readonly generated: ExecutionMutationDefaultValue;\n};\n\nfunction createGeneratedSpec<TId extends BuiltinGeneratorId>(\n id: TId,\n options?: IdGeneratorOptionsById[TId],\n): GeneratedColumnSpec {\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 };\n}\n\nexport const ulid = (options?: IdGeneratorOptionsById['ulid']): GeneratedColumnSpec =>\n createGeneratedSpec('ulid', options);\nexport const nanoid = (options?: IdGeneratorOptionsById['nanoid']): GeneratedColumnSpec =>\n createGeneratedSpec('nanoid', options);\nexport const uuidv7 = (options?: IdGeneratorOptionsById['uuidv7']): GeneratedColumnSpec =>\n createGeneratedSpec('uuidv7', options);\nexport const uuidv4 = (options?: IdGeneratorOptionsById['uuidv4']): GeneratedColumnSpec =>\n createGeneratedSpec('uuidv4', options);\nexport const cuid2 = (options?: IdGeneratorOptionsById['cuid2']): GeneratedColumnSpec =>\n createGeneratedSpec('cuid2', options);\nexport const ksuid = (options?: IdGeneratorOptionsById['ksuid']): GeneratedColumnSpec =>\n createGeneratedSpec('ksuid', options);\n"],"mappings":";;;AAAA,MAAa,sBAAsB;CACjC;CACA;CACA;CACA;CACA;CACA;CACD;;;;ACcD,SAAS,8BACP,QAC2B;CAC3B,MAAM,UAAU,SAAS;AACzB,KAAI,YAAY,OACd,QAAO;EACL,MAAM;GAAE,SAAS;GAAc,YAAY;GAAa;EACxD,YAAY,EAAE,QAAQ,IAAI;EAC3B;AAGH,KAAI,OAAO,YAAY,YAAY,CAAC,OAAO,UAAU,QAAQ,IAAI,UAAU,KAAK,UAAU,IACxF,OAAM,IAAI,MAAM,mDAAmD;AAGrE,QAAO;EACL,MAAM;GAAE,SAAS;GAAc,YAAY;GAAa;EACxD,YAAY,EAAE,QAAQ,SAAS;EAChC;;AAGH,MAAMA,+BAAqF;CACzF,MAAM;EACJ,oBAAoB,CAAC,aAAa,aAAa;EAC/C,2BAA2B;GACzB,MAAM;IAAE,SAAS;IAAc,YAAY;IAAa;GACxD,YAAY,EAAE,QAAQ,IAAI;GAC3B;EACF;CACD,QAAQ;EACN,oBAAoB,CAAC,aAAa,aAAa;EAC/C,2BAA2B;GACzB,MAAM;IAAE,SAAS;IAAc,YAAY;IAAa;GACxD,YAAY,EAAE,QAAQ,IAAI;GAC3B;EACD,kCAAkC;EACnC;CACD,QAAQ;EACN,oBAAoB,CAAC,aAAa,aAAa;EAC/C,2BAA2B;GACzB,MAAM;IAAE,SAAS;IAAc,YAAY;IAAa;GACxD,YAAY,EAAE,QAAQ,IAAI;GAC3B;EACF;CACD,QAAQ;EACN,oBAAoB,CAAC,aAAa,aAAa;EAC/C,2BAA2B;GACzB,MAAM;IAAE,SAAS;IAAc,YAAY;IAAa;GACxD,YAAY,EAAE,QAAQ,IAAI;GAC3B;EACF;CACD,OAAO;EACL,oBAAoB,CAAC,aAAa,aAAa;EAC/C,2BAA2B;GACzB,MAAM;IAAE,SAAS;IAAc,YAAY;IAAa;GACxD,YAAY,EAAE,QAAQ,IAAI;GAC3B;EACF;CACD,OAAO;EACL,oBAAoB,CAAC,aAAa,aAAa;EAC/C,2BAA2B;GACzB,MAAM;IAAE,SAAS;IAAc,YAAY;IAAa;GACxD,YAAY,EAAE,QAAQ,IAAI;GAC3B;EACF;CACF;AAED,MAAaC,mCAGR,oBAAoB,KAAK,QAAQ;CACpC;CACA,oBAAoB,6BAA6B,IAAI;CACtD,EAAE;AAEH,SAAgB,wCAAwC,OAG1B;CAC5B,MAAM,WAAW,6BAA6B,MAAM;CACpD,MAAM,WAAW,SAAS;AAC1B,KAAI,SACF,QAAO,SAAS,MAAM,OAAO;AAE/B,QAAO,SAAS;;AAUlB,SAAS,oBACP,IACA,SACqB;CACrB,MAAM,SAAS;CACf,MAAM,qBAAqB,wCAAwC;EACjE;EACA,GAAG,UAAU,UAAU,OAAO;EAC/B,CAAC;AACF,QAAO;EACL,MAAM,mBAAmB;EACzB,UAAU;EACV,GAAG,UAAU,cAAc,mBAAmB,WAAW;EACzD,WAAW;GACT,MAAM;GACN;GACA,GAAG,UAAU,UAAU,OAAO;GAC/B;EACF;;AAGH,MAAa,QAAQ,YACnB,oBAAoB,QAAQ,QAAQ;AACtC,MAAa,UAAU,YACrB,oBAAoB,UAAU,QAAQ;AACxC,MAAa,UAAU,YACrB,oBAAoB,UAAU,QAAQ;AACxC,MAAa,UAAU,YACrB,oBAAoB,UAAU,QAAQ;AACxC,MAAa,SAAS,YACpB,oBAAoB,SAAS,QAAQ;AACvC,MAAa,SAAS,YACpB,oBAAoB,SAAS,QAAQ"}
1
+ {"version":3,"file":"index.mjs","names":["builtinGeneratorRegistryMetadata: ReadonlyArray<{\n readonly id: BuiltinGeneratorId;\n readonly applicableCodecIds: readonly string[];\n}>","metadata: BuiltinGeneratorMetadata"],"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/contract-authoring';\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'],\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'],\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;CACD;;;;ACcD,SAAS,8BACP,QAC2B;CAC3B,MAAM,UAAU,SAAS;AACzB,KAAI,YAAY,OACd,QAAO;EACL,MAAM;GAAE,SAAS;GAAc,YAAY;GAAa;EACxD,YAAY,EAAE,QAAQ,IAAI;EAC3B;AAGH,KAAI,OAAO,YAAY,YAAY,CAAC,OAAO,UAAU,QAAQ,IAAI,UAAU,KAAK,UAAU,IACxF,OAAM,IAAI,MAAM,mDAAmD;AAGrE,QAAO;EACL,MAAM;GAAE,SAAS;GAAc,YAAY;GAAa;EACxD,YAAY,EAAE,QAAQ,SAAS;EAChC;;AAGH,MAAM,+BAA+B;CACnC,MAAM;EACJ,oBAAoB,CAAC,aAAa,aAAa;E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AU;EACV,GAAG,UAAU,cAAc,mBAAmB,WAAW;EACzD,WAAW;GACT,MAAM;GACN;GACA,GAAG,UAAU,UAAU,OAAO;GAC/B;EACF;;AAGH,MAAa,QAAQ,YACnB,oBAAoB,QAAQ,QAAQ;AACtC,MAAa,UAAU,YACrB,oBAAoB,UAAU,QAAQ;AACxC,MAAa,UAAU,YACrB,oBAAoB,UAAU,QAAQ;AACxC,MAAa,UAAU,YACrB,oBAAoB,UAAU,QAAQ;AACxC,MAAa,SAAS,YACpB,oBAAoB,SAAS,QAAQ;AACvC,MAAa,SAAS,YACpB,oBAAoB,SAAS,QAAQ"}
package/package.json CHANGED
@@ -1,21 +1,21 @@
1
1
  {
2
2
  "name": "@prisma-next/ids",
3
- "version": "0.3.0-dev.99",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "ID generator helpers for Prisma Next contracts",
7
7
  "dependencies": {
8
8
  "uniku": "^0.0.12",
9
- "@prisma-next/contract": "0.3.0-dev.99",
10
- "@prisma-next/utils": "0.3.0-dev.99",
11
- "@prisma-next/contract-authoring": "0.3.0-dev.99"
9
+ "@prisma-next/contract": "0.3.0",
10
+ "@prisma-next/contract-authoring": "0.3.0",
11
+ "@prisma-next/utils": "0.3.0"
12
12
  },
13
13
  "devDependencies": {
14
14
  "tsdown": "0.18.4",
15
15
  "typescript": "5.9.3",
16
16
  "vitest": "4.0.17",
17
- "@prisma-next/tsconfig": "0.0.0",
18
- "@prisma-next/tsdown": "0.0.0"
17
+ "@prisma-next/tsdown": "0.0.0",
18
+ "@prisma-next/tsconfig": "0.0.0"
19
19
  },
20
20
  "files": [
21
21
  "dist",
package/src/index.ts CHANGED
@@ -40,7 +40,7 @@ function resolveNanoidColumnDescriptor(
40
40
  };
41
41
  }
42
42
 
43
- const builtinGeneratorMetadataById: Record<BuiltinGeneratorId, BuiltinGeneratorMetadata> = {
43
+ const builtinGeneratorMetadataById = {
44
44
  ulid: {
45
45
  applicableCodecIds: ['pg/text@1', 'sql/char@1'],
46
46
  generatedColumnDescriptor: {
@@ -84,7 +84,7 @@ const builtinGeneratorMetadataById: Record<BuiltinGeneratorId, BuiltinGeneratorM
84
84
  typeParams: { length: 27 },
85
85
  },
86
86
  },
87
- };
87
+ } as const satisfies Record<BuiltinGeneratorId, BuiltinGeneratorMetadata>;
88
88
 
89
89
  export const builtinGeneratorRegistryMetadata: ReadonlyArray<{
90
90
  readonly id: BuiltinGeneratorId;
@@ -98,25 +98,27 @@ export function resolveBuiltinGeneratedColumnDescriptor(input: {
98
98
  readonly id: BuiltinGeneratorId;
99
99
  readonly params?: Record<string, unknown>;
100
100
  }): GeneratedColumnDescriptor {
101
- const metadata = builtinGeneratorMetadataById[input.id];
102
- const resolver = metadata.resolveGeneratedColumnDescriptor;
103
- if (resolver) {
104
- return resolver(input.params);
101
+ const metadata: BuiltinGeneratorMetadata = builtinGeneratorMetadataById[input.id];
102
+ if (metadata.resolveGeneratedColumnDescriptor) {
103
+ return metadata.resolveGeneratedColumnDescriptor(input.params);
105
104
  }
106
105
  return metadata.generatedColumnDescriptor;
107
106
  }
108
107
 
109
- export type GeneratedColumnSpec = {
110
- readonly type: ColumnTypeDescriptor;
108
+ export type GeneratedColumnSpec<TCodecId extends string = string> = {
109
+ readonly type: ColumnTypeDescriptor<TCodecId>;
111
110
  readonly nullable?: false;
112
111
  readonly typeParams?: Record<string, unknown>;
113
112
  readonly generated: ExecutionMutationDefaultValue;
114
113
  };
115
114
 
115
+ type GeneratorCodecId<TId extends BuiltinGeneratorId> =
116
+ (typeof builtinGeneratorMetadataById)[TId]['generatedColumnDescriptor']['type']['codecId'];
117
+
116
118
  function createGeneratedSpec<TId extends BuiltinGeneratorId>(
117
119
  id: TId,
118
120
  options?: IdGeneratorOptionsById[TId],
119
- ): GeneratedColumnSpec {
121
+ ): GeneratedColumnSpec<GeneratorCodecId<TId>> {
120
122
  const params = options as Record<string, unknown> | undefined;
121
123
  const resolvedDescriptor = resolveBuiltinGeneratedColumnDescriptor({
122
124
  id,
@@ -131,18 +133,18 @@ function createGeneratedSpec<TId extends BuiltinGeneratorId>(
131
133
  id,
132
134
  ...ifDefined('params', params),
133
135
  },
134
- };
136
+ } as GeneratedColumnSpec<GeneratorCodecId<TId>>;
135
137
  }
136
138
 
137
- export const ulid = (options?: IdGeneratorOptionsById['ulid']): GeneratedColumnSpec =>
139
+ export const ulid = (options?: IdGeneratorOptionsById['ulid']) =>
138
140
  createGeneratedSpec('ulid', options);
139
- export const nanoid = (options?: IdGeneratorOptionsById['nanoid']): GeneratedColumnSpec =>
141
+ export const nanoid = (options?: IdGeneratorOptionsById['nanoid']) =>
140
142
  createGeneratedSpec('nanoid', options);
141
- export const uuidv7 = (options?: IdGeneratorOptionsById['uuidv7']): GeneratedColumnSpec =>
143
+ export const uuidv7 = (options?: IdGeneratorOptionsById['uuidv7']) =>
142
144
  createGeneratedSpec('uuidv7', options);
143
- export const uuidv4 = (options?: IdGeneratorOptionsById['uuidv4']): GeneratedColumnSpec =>
145
+ export const uuidv4 = (options?: IdGeneratorOptionsById['uuidv4']) =>
144
146
  createGeneratedSpec('uuidv4', options);
145
- export const cuid2 = (options?: IdGeneratorOptionsById['cuid2']): GeneratedColumnSpec =>
147
+ export const cuid2 = (options?: IdGeneratorOptionsById['cuid2']) =>
146
148
  createGeneratedSpec('cuid2', options);
147
- export const ksuid = (options?: IdGeneratorOptionsById['ksuid']): GeneratedColumnSpec =>
149
+ export const ksuid = (options?: IdGeneratorOptionsById['ksuid']) =>
148
150
  createGeneratedSpec('ksuid', options);