@prisma-next/sql-contract-ts 0.12.0-dev.44 → 0.12.0-dev.45

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/package.json CHANGED
@@ -1,27 +1,27 @@
1
1
  {
2
2
  "name": "@prisma-next/sql-contract-ts",
3
- "version": "0.12.0-dev.44",
3
+ "version": "0.12.0-dev.45",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "description": "SQL-specific TypeScript contract authoring surface for Prisma Next",
8
8
  "dependencies": {
9
- "@prisma-next/config": "0.12.0-dev.44",
10
- "@prisma-next/contract": "0.12.0-dev.44",
11
- "@prisma-next/contract-authoring": "0.12.0-dev.44",
12
- "@prisma-next/framework-components": "0.12.0-dev.44",
13
- "@prisma-next/sql-contract": "0.12.0-dev.44",
14
- "@prisma-next/utils": "0.12.0-dev.44",
9
+ "@prisma-next/config": "0.12.0-dev.45",
10
+ "@prisma-next/contract": "0.12.0-dev.45",
11
+ "@prisma-next/contract-authoring": "0.12.0-dev.45",
12
+ "@prisma-next/framework-components": "0.12.0-dev.45",
13
+ "@prisma-next/sql-contract": "0.12.0-dev.45",
14
+ "@prisma-next/utils": "0.12.0-dev.45",
15
15
  "arktype": "^2.2.0",
16
16
  "pathe": "^2.0.3",
17
17
  "ts-toolbelt": "^9.6.0"
18
18
  },
19
19
  "devDependencies": {
20
- "@prisma-next/test-utils": "0.12.0-dev.44",
21
- "@prisma-next/tsconfig": "0.12.0-dev.44",
20
+ "@prisma-next/test-utils": "0.12.0-dev.45",
21
+ "@prisma-next/tsconfig": "0.12.0-dev.45",
22
22
  "@types/pg": "8.20.0",
23
23
  "pg": "8.20.0",
24
- "@prisma-next/tsdown": "0.12.0-dev.44",
24
+ "@prisma-next/tsdown": "0.12.0-dev.45",
25
25
  "tsdown": "0.22.0",
26
26
  "typescript": "5.9.3",
27
27
  "vitest": "4.1.6"
@@ -13,6 +13,7 @@ import type {
13
13
  StorageTypeInstance,
14
14
  } from '@prisma-next/sql-contract/types';
15
15
  import { blindCast } from '@prisma-next/utils/casts';
16
+ import { ifDefined } from '@prisma-next/utils/defined';
16
17
  import { buildSqlContractFromDefinition } from './build-contract';
17
18
  import {
18
19
  type ComposedAuthoringHelpers,
@@ -292,6 +293,130 @@ function buildContractFromDsl<Definition extends ContractInput>(
292
293
  >(buildSqlContractFromDefinition(buildContractDefinition(definition), definition.codecLookup));
293
294
  }
294
295
 
296
+ // Input for buildBoundContract — all fields from ContractInput except family/target
297
+ // (those are injected by the builder, pre-bound at the call site).
298
+ type BoundDefinitionInput<
299
+ Types extends Record<string, StorageTypeInstance | PostgresEnumStorageEntry> = Record<
300
+ never,
301
+ never
302
+ >,
303
+ Models extends Record<string, ModelLike> = Record<never, never>,
304
+ ExtensionPacks extends Record<string, ExtensionPackRef<'sql', string>> | undefined = undefined,
305
+ Naming extends ContractInput['naming'] | undefined = undefined,
306
+ StorageHash extends string | undefined = undefined,
307
+ ForeignKeyDefaults extends ForeignKeyDefaultsState | undefined = undefined,
308
+ Namespaces extends readonly string[] | undefined = undefined,
309
+ > = {
310
+ readonly extensionPacks?: ExtensionPacks;
311
+ readonly naming?: Naming;
312
+ readonly storageHash?: StorageHash;
313
+ readonly foreignKeyDefaults?: ForeignKeyDefaults;
314
+ readonly defaultControlPolicy?: ControlPolicy;
315
+ readonly namespaces?: Namespaces;
316
+ readonly createNamespace?: (input: SqlNamespaceTablesInput) => Namespace;
317
+ readonly types?: Types;
318
+ readonly models?: Models;
319
+ readonly codecLookup?: CodecLookup;
320
+ };
321
+
322
+ // Merges a bound input with the pre-bound family/target to produce a full ContractDefinition.
323
+ type WithFamilyTarget<
324
+ Input,
325
+ F extends FamilyPackRef<string>,
326
+ T extends TargetPackRef<'sql', string>,
327
+ > = Input & { readonly family: F; readonly target: T };
328
+
329
+ /**
330
+ * Shared builder that assembles a SqlContract with pre-bound family and target.
331
+ * Extension wrappers keep their own public overloads and delegate their impl body here;
332
+ * this is a plain overloaded function (not a factory returning an overloaded function)
333
+ * so no overloaded-function-return cast is needed.
334
+ *
335
+ * Overload 1: definition form (no factory).
336
+ */
337
+ export function buildBoundContract<
338
+ const F extends FamilyPackRef<string>,
339
+ const T extends TargetPackRef<'sql', string>,
340
+ const Definition extends BoundDefinitionInput<
341
+ Record<string, StorageTypeInstance | PostgresEnumStorageEntry>,
342
+ Record<string, ModelLike>,
343
+ Record<string, ExtensionPackRef<'sql', string>> | undefined,
344
+ ContractInput['naming'] | undefined,
345
+ string | undefined,
346
+ ForeignKeyDefaultsState | undefined,
347
+ readonly string[] | undefined
348
+ >,
349
+ >(
350
+ family: F,
351
+ target: T,
352
+ definition: Definition,
353
+ factory?: undefined,
354
+ ): SqlContractResult<WithFamilyTarget<Definition, F, T>>;
355
+ /**
356
+ * Overload 2: factory form.
357
+ */
358
+ export function buildBoundContract<
359
+ const F extends FamilyPackRef<string>,
360
+ const T extends TargetPackRef<'sql', string>,
361
+ const Definition extends BoundDefinitionInput<
362
+ Record<string, StorageTypeInstance | PostgresEnumStorageEntry>,
363
+ Record<string, ModelLike>,
364
+ Record<string, ExtensionPackRef<'sql', string>> | undefined,
365
+ ContractInput['naming'] | undefined,
366
+ string | undefined,
367
+ ForeignKeyDefaultsState | undefined,
368
+ readonly string[] | undefined
369
+ >,
370
+ const Built extends {
371
+ readonly types?: Record<string, StorageTypeInstance | PostgresEnumStorageEntry>;
372
+ readonly models?: Record<string, ModelLike>;
373
+ },
374
+ >(
375
+ family: F,
376
+ target: T,
377
+ definition: Definition,
378
+ factory: (
379
+ helpers: ComposedAuthoringHelpers<F, T, NonNullable<Definition['extensionPacks']>>,
380
+ ) => Built,
381
+ ): SqlContractResult<WithFamilyTarget<Definition & Built, F, T>>;
382
+ /** Implementation. */
383
+ export function buildBoundContract(
384
+ family: FamilyPackRef<string>,
385
+ target: TargetPackRef<'sql', string>,
386
+ definition: Omit<ContractInput, 'family' | 'target'>,
387
+ factory?:
388
+ | ((
389
+ helpers: ComposedAuthoringHelpers<
390
+ FamilyPackRef<string>,
391
+ TargetPackRef<'sql', string>,
392
+ Record<string, ExtensionPackRef<'sql', string>> | undefined
393
+ >,
394
+ ) => {
395
+ readonly types?: Record<string, StorageTypeInstance | PostgresEnumStorageEntry>;
396
+ readonly models?: Record<string, ModelLike>;
397
+ })
398
+ | undefined,
399
+ ) {
400
+ const full = { ...definition, family, target };
401
+
402
+ if (factory !== undefined) {
403
+ const built = factory(
404
+ createComposedAuthoringHelpers({
405
+ family,
406
+ target,
407
+ extensionPacks: definition.extensionPacks,
408
+ }),
409
+ );
410
+ return buildContractFromDsl({
411
+ ...full,
412
+ ...ifDefined('types', built.types),
413
+ ...ifDefined('models', built.models),
414
+ });
415
+ }
416
+
417
+ return buildContractFromDsl(full);
418
+ }
419
+
295
420
  export function defineContract<
296
421
  const Family extends FamilyPackRef<string>,
297
422
  const Target extends TargetPackRef<'sql', string>,
@@ -387,22 +512,10 @@ export function defineContract(
387
512
  );
388
513
  }
389
514
 
390
- if (!factory) {
391
- return buildContractFromDsl(definition);
515
+ if (factory !== undefined) {
516
+ return buildBoundContract(definition.family, definition.target, definition, factory);
392
517
  }
393
-
394
- const builtDefinition = {
395
- ...definition,
396
- ...factory(
397
- createComposedAuthoringHelpers({
398
- family: definition.family,
399
- target: definition.target,
400
- extensionPacks: definition.extensionPacks,
401
- }),
402
- ),
403
- };
404
-
405
- return buildContractFromDsl(builtDefinition);
518
+ return buildBoundContract(definition.family, definition.target, definition);
406
519
  }
407
520
 
408
521
  export type {
@@ -6,6 +6,7 @@ export type {
6
6
  ScalarFieldBuilder,
7
7
  } from '../contract-builder';
8
8
  export {
9
+ buildBoundContract,
9
10
  buildSqlContractFromDefinition,
10
11
  defineContract,
11
12
  field,