@prisma-next/sql-contract-ts 0.14.0-dev.9 → 0.14.0-dev.90

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.
@@ -13,9 +13,6 @@ import type {
13
13
  } from '@prisma-next/framework-components/authoring';
14
14
  import {
15
15
  assertNoCrossRegistryCollisions,
16
- isAuthoringEntityTypeDescriptor,
17
- isAuthoringFieldPresetDescriptor,
18
- isAuthoringTypeConstructorDescriptor,
19
16
  mergeAuthoringNamespaces,
20
17
  } from '@prisma-next/framework-components/authoring';
21
18
  import type {
@@ -183,7 +180,7 @@ function composeTypeNamespace(components: readonly AuthoringComponent[]): Author
183
180
  for (const component of components) {
184
181
  const ns = extractTypeNamespace(component);
185
182
  if (Object.keys(ns).length > 0) {
186
- mergeAuthoringNamespaces(merged, ns, [], isAuthoringTypeConstructorDescriptor, 'type');
183
+ mergeAuthoringNamespaces(merged, ns, [], 'typeConstructor', 'type');
187
184
  }
188
185
  }
189
186
  return merged as AuthoringTypeNamespace;
@@ -194,7 +191,7 @@ function composeFieldNamespace(components: readonly AuthoringComponent[]): Autho
194
191
  for (const component of components) {
195
192
  const ns = extractFieldNamespace(component);
196
193
  if (Object.keys(ns).length > 0) {
197
- mergeAuthoringNamespaces(merged, ns, [], isAuthoringFieldPresetDescriptor, 'field');
194
+ mergeAuthoringNamespaces(merged, ns, [], 'fieldPreset', 'field');
198
195
  }
199
196
  }
200
197
  return merged as AuthoringFieldNamespace;
@@ -207,7 +204,7 @@ function composeEntityNamespace(
207
204
  for (const component of components) {
208
205
  const ns = extractEntitiesNamespace(component);
209
206
  if (Object.keys(ns).length > 0) {
210
- mergeAuthoringNamespaces(merged, ns, [], isAuthoringEntityTypeDescriptor, 'entity');
207
+ mergeAuthoringNamespaces(merged, ns, [], 'entity', 'entity');
211
208
  }
212
209
  }
213
210
  return merged as AuthoringEntityTypeNamespace;
@@ -3,6 +3,7 @@ import type { ContractConfig } from '@prisma-next/config/config-types';
3
3
  import { applySpecifierDefaultControlPolicy } from '@prisma-next/contract/apply-specifier-default-control-policy';
4
4
  import type { Contract, ControlPolicy } from '@prisma-next/contract/types';
5
5
  import type { TargetPackRef } from '@prisma-next/framework-components/components';
6
+ import type { SqlNamespaceBase, SqlNamespaceInput } from '@prisma-next/sql-contract/types';
6
7
  import { ifDefined } from '@prisma-next/utils/defined';
7
8
  import { ok } from '@prisma-next/utils/result';
8
9
  import { extname } from 'pathe';
@@ -27,13 +28,18 @@ export interface TypeScriptContractSpecifierOptions {
27
28
  export function emptyContract(options: {
28
29
  readonly output?: string;
29
30
  readonly target: TargetPackRef<'sql', string>;
31
+ readonly createNamespace: (input: SqlNamespaceInput) => SqlNamespaceBase;
30
32
  readonly defaultControlPolicy?: ControlPolicy;
31
33
  }): ContractConfig {
32
34
  return {
33
35
  source: {
34
36
  sourceFormat: 'typescript',
35
37
  load: async () => {
36
- const built = buildSqlContractFromDefinition({ target: options.target, models: [] });
38
+ const built = buildSqlContractFromDefinition({
39
+ target: options.target,
40
+ createNamespace: options.createNamespace,
41
+ models: [],
42
+ });
37
43
  return ok(applySpecifierDefaultControlPolicy(built, options.defaultControlPolicy));
38
44
  },
39
45
  },
@@ -6,8 +6,12 @@ import type {
6
6
  FamilyPackRef,
7
7
  TargetPackRef,
8
8
  } from '@prisma-next/framework-components/components';
9
- import type { Namespace } from '@prisma-next/framework-components/ir';
10
- import type { SqlNamespaceTablesInput, StorageTypeInstance } from '@prisma-next/sql-contract/types';
9
+ import type { PackEntityHandle } from '@prisma-next/sql-contract/entity-handle-lowering-hook';
10
+ import type {
11
+ SqlNamespaceBase,
12
+ SqlNamespaceInput,
13
+ StorageTypeInstance,
14
+ } from '@prisma-next/sql-contract/types';
11
15
  import { blindCast } from '@prisma-next/utils/casts';
12
16
  import { ifDefined } from '@prisma-next/utils/defined';
13
17
  import { buildSqlContractFromDefinition } from './build-contract';
@@ -68,11 +72,12 @@ type ContractDefinition<
68
72
  readonly foreignKeyDefaults?: ForeignKeyDefaults;
69
73
  readonly defaultControlPolicy?: ControlPolicy;
70
74
  readonly namespaces?: Namespaces;
71
- readonly createNamespace?: (input: SqlNamespaceTablesInput) => Namespace;
75
+ readonly createNamespace: (input: SqlNamespaceInput) => SqlNamespaceBase;
72
76
  readonly types?: Types;
73
77
  readonly models?: Models;
74
78
  readonly codecLookup?: CodecLookup;
75
79
  readonly enums?: Enums;
80
+ readonly entities?: readonly PackEntityHandle[];
76
81
  };
77
82
 
78
83
  type ContractScaffold<
@@ -93,11 +98,12 @@ type ContractScaffold<
93
98
  readonly foreignKeyDefaults?: ForeignKeyDefaults;
94
99
  readonly defaultControlPolicy?: ControlPolicy;
95
100
  readonly namespaces?: Namespaces;
96
- readonly createNamespace?: (input: SqlNamespaceTablesInput) => Namespace;
101
+ readonly createNamespace: (input: SqlNamespaceInput) => SqlNamespaceBase;
97
102
  readonly types?: never;
98
103
  readonly models?: never;
99
104
  readonly codecLookup?: CodecLookup;
100
105
  readonly enums?: Enums;
106
+ readonly entities?: readonly PackEntityHandle[];
101
107
  };
102
108
 
103
109
  type ContractFactory<
@@ -111,6 +117,7 @@ type ContractFactory<
111
117
  readonly types?: Types;
112
118
  readonly models?: Models;
113
119
  readonly enums?: Enums;
120
+ readonly entities?: readonly PackEntityHandle[];
114
121
  };
115
122
 
116
123
  function validateTargetPackRef(
@@ -314,11 +321,12 @@ type BoundDefinitionInput<
314
321
  readonly foreignKeyDefaults?: ForeignKeyDefaults;
315
322
  readonly defaultControlPolicy?: ControlPolicy;
316
323
  readonly namespaces?: Namespaces;
317
- readonly createNamespace?: (input: SqlNamespaceTablesInput) => Namespace;
324
+ readonly createNamespace: (input: SqlNamespaceInput) => SqlNamespaceBase;
318
325
  readonly types?: Types;
319
326
  readonly models?: Models;
320
327
  readonly codecLookup?: CodecLookup;
321
328
  readonly enums?: Record<string, EnumTypeHandle>;
329
+ readonly entities?: readonly PackEntityHandle[];
322
330
  };
323
331
 
324
332
  // A bare `Record<string, EnumTypeHandle>` (no literal keys) is the widened
@@ -387,6 +395,7 @@ export function buildBoundContract<
387
395
  readonly types?: Record<string, StorageTypeInstance>;
388
396
  readonly models?: Record<string, ModelLike>;
389
397
  readonly enums?: Record<string, EnumTypeHandle>;
398
+ readonly entities?: readonly PackEntityHandle[];
390
399
  },
391
400
  >(
392
401
  family: F,
@@ -412,6 +421,7 @@ export function buildBoundContract(
412
421
  readonly types?: Record<string, StorageTypeInstance>;
413
422
  readonly models?: Record<string, ModelLike>;
414
423
  readonly enums?: Record<string, EnumTypeHandle>;
424
+ readonly entities?: readonly PackEntityHandle[];
415
425
  })
416
426
  | undefined,
417
427
  ) {
@@ -426,11 +436,13 @@ export function buildBoundContract(
426
436
  }),
427
437
  );
428
438
  const mergedEnums = { ...(definition.enums ?? {}), ...built.enums };
439
+ const mergedEntities = [...(definition.entities ?? []), ...(built.entities ?? [])];
429
440
  return buildContractFromDsl({
430
441
  ...full,
431
442
  ...ifDefined('types', built.types),
432
443
  ...ifDefined('models', built.models),
433
444
  ...ifDefined('enums', Object.keys(mergedEnums).length > 0 ? mergedEnums : undefined),
445
+ ...ifDefined('entities', mergedEntities.length > 0 ? mergedEntities : undefined),
434
446
  });
435
447
  }
436
448
 
@@ -6,16 +6,33 @@ import type {
6
6
  import type { ForeignKeyDefaultsState } from '@prisma-next/contract-authoring';
7
7
  import type { ColumnTypeDescriptor } from '@prisma-next/framework-components/codec';
8
8
  import type { ExtensionPackRef, TargetPackRef } from '@prisma-next/framework-components/components';
9
- import type { Namespace } from '@prisma-next/framework-components/ir';
10
9
  import type {
11
10
  ReferentialAction,
12
- SqlNamespaceTablesInput,
11
+ SqlNamespaceBase,
12
+ SqlNamespaceInput,
13
13
  StorageTypeInstance,
14
14
  } from '@prisma-next/sql-contract/types';
15
15
  import type { EnumTypeHandle } from './enum-type';
16
16
 
17
17
  export type { ExecutionMutationDefaultPhases };
18
18
 
19
+ /**
20
+ * Namespace-scoped pack-entity attachments, the internal build IR carrying
21
+ * the lowered `entities` handle list: namespace id → entity kind (the
22
+ * discriminator the target/extension pack registered its
23
+ * `AuthoringContributions.entityTypes` descriptor under, e.g. `native_enum`)
24
+ * → entity name → the lowered entity instance. Generic on purpose — neither
25
+ * the framework nor `contract-ts` names a specific entity kind here; the
26
+ * shape mirrors `SqlNamespaceInput.entries` (`entries.<kind>[name]`), just
27
+ * namespace-nested so an attachment can target any declared namespace
28
+ * (default or named), not only the contract's default namespace. Produced by
29
+ * the generic entity-handle walk in `buildContractDefinition`; never an
30
+ * author-facing input.
31
+ */
32
+ export type AttachedEntities = Readonly<
33
+ Record<string, Readonly<Record<string, Readonly<Record<string, unknown>>>>>
34
+ >;
35
+
19
36
  export interface FieldNode {
20
37
  readonly fieldName: string;
21
38
  readonly columnName: string;
@@ -175,8 +192,8 @@ export interface ContractDefinition {
175
192
  * `SqlStorage.namespaces` together with `createNamespace`.
176
193
  */
177
194
  readonly namespaces?: readonly string[];
178
- /** Target-supplied factory that materialises a `Namespace` concretion for a declared namespace coordinate. */
179
- readonly createNamespace?: (input: SqlNamespaceTablesInput) => Namespace;
195
+ /** Target-supplied factory that materialises a `SqlNamespaceBase` concretion for a declared namespace coordinate. */
196
+ readonly createNamespace: (input: SqlNamespaceInput) => SqlNamespaceBase;
180
197
  readonly models: readonly ModelNode[];
181
198
  readonly valueObjects?: readonly ValueObjectNode[];
182
199
  /**
@@ -185,4 +202,15 @@ export interface ContractDefinition {
185
202
  * default namespace.
186
203
  */
187
204
  readonly enums?: Record<string, EnumTypeHandle>;
205
+ /**
206
+ * Pack-entity attachments lowered from the `entities` handle list, keyed by
207
+ * namespace then entity kind then name. Each entity lands in
208
+ * `storage.namespaces[ns].entries.<kind>`; when the registered entity-type
209
+ * descriptor's factory output implements the
210
+ * `SqlValueSetDerivingEntityTypeOutput.deriveValueSet` hook, the derived
211
+ * value-set also folds into `entries.valueSet`, mirroring how `enums` flows
212
+ * there. Internal build IR — populated by `buildContractDefinition`, not an
213
+ * author input.
214
+ */
215
+ readonly attachedEntities?: AttachedEntities;
188
216
  }