@prisma-next/family-sql 0.3.0-dev.1 → 0.3.0-dev.11

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 (69) hide show
  1. package/dist/{exports/chunk-F252JMEU.js → chunk-BHEGVBY7.js} +1 -1
  2. package/dist/chunk-BHEGVBY7.js.map +1 -0
  3. package/dist/{exports/chunk-6P44BVZ4.js → chunk-SQ2VWYDV.js} +12 -3
  4. package/dist/chunk-SQ2VWYDV.js.map +1 -0
  5. package/dist/{exports/chunk-C3GKWCKA.js → chunk-SU7LN2UH.js} +1 -1
  6. package/dist/chunk-SU7LN2UH.js.map +1 -0
  7. package/dist/core/assembly.d.ts +25 -0
  8. package/dist/core/assembly.d.ts.map +1 -0
  9. package/dist/core/control-adapter.d.ts +42 -0
  10. package/dist/core/control-adapter.d.ts.map +1 -0
  11. package/dist/core/descriptor.d.ts +24 -0
  12. package/dist/core/descriptor.d.ts.map +1 -0
  13. package/dist/{exports/instance-DiZi2k_2.d.ts → core/instance.d.ts} +28 -15
  14. package/dist/core/instance.d.ts.map +1 -0
  15. package/dist/core/migrations/plan-helpers.d.ts +20 -0
  16. package/dist/core/migrations/plan-helpers.d.ts.map +1 -0
  17. package/dist/core/migrations/policies.d.ts +6 -0
  18. package/dist/core/migrations/policies.d.ts.map +1 -0
  19. package/dist/{exports/types-Bh7ftf0Q.d.ts → core/migrations/types.d.ts} +41 -36
  20. package/dist/core/migrations/types.d.ts.map +1 -0
  21. package/dist/core/runtime-descriptor.d.ts +19 -0
  22. package/dist/core/runtime-descriptor.d.ts.map +1 -0
  23. package/dist/core/runtime-instance.d.ts +54 -0
  24. package/dist/core/runtime-instance.d.ts.map +1 -0
  25. package/dist/core/schema-verify/verify-helpers.d.ts +50 -0
  26. package/dist/core/schema-verify/verify-helpers.d.ts.map +1 -0
  27. package/dist/core/schema-verify/verify-sql-schema.d.ts +45 -0
  28. package/dist/core/schema-verify/verify-sql-schema.d.ts.map +1 -0
  29. package/dist/core/verify.d.ts +39 -0
  30. package/dist/core/verify.d.ts.map +1 -0
  31. package/dist/exports/control-adapter.d.ts +2 -44
  32. package/dist/exports/control-adapter.d.ts.map +1 -0
  33. package/dist/exports/control.d.ts +8 -160
  34. package/dist/exports/control.d.ts.map +1 -0
  35. package/dist/exports/control.js +7 -7
  36. package/dist/exports/control.js.map +1 -1
  37. package/dist/exports/runtime.d.ts +3 -61
  38. package/dist/exports/runtime.d.ts.map +1 -0
  39. package/dist/exports/schema-verify.d.ts +8 -72
  40. package/dist/exports/schema-verify.d.ts.map +1 -0
  41. package/dist/exports/schema-verify.js +1 -1
  42. package/dist/exports/test-utils.d.ts +5 -31
  43. package/dist/exports/test-utils.d.ts.map +1 -0
  44. package/dist/exports/test-utils.js +3 -3
  45. package/dist/exports/verify.d.ts +2 -28
  46. package/dist/exports/verify.d.ts.map +1 -0
  47. package/dist/exports/verify.js +1 -1
  48. package/package.json +23 -23
  49. package/src/core/assembly.ts +117 -0
  50. package/src/core/control-adapter.ts +52 -0
  51. package/src/core/descriptor.ts +33 -0
  52. package/src/core/instance.ts +903 -0
  53. package/src/core/migrations/plan-helpers.ts +164 -0
  54. package/src/core/migrations/policies.ts +8 -0
  55. package/src/core/migrations/types.ts +380 -0
  56. package/src/core/runtime-descriptor.ts +45 -0
  57. package/src/core/runtime-instance.ts +144 -0
  58. package/src/core/schema-verify/verify-helpers.ts +514 -0
  59. package/src/core/schema-verify/verify-sql-schema.ts +584 -0
  60. package/src/core/verify.ts +177 -0
  61. package/src/exports/control-adapter.ts +1 -0
  62. package/src/exports/control.ts +56 -0
  63. package/src/exports/runtime.ts +7 -0
  64. package/src/exports/schema-verify.ts +11 -0
  65. package/src/exports/test-utils.ts +11 -0
  66. package/src/exports/verify.ts +1 -0
  67. package/dist/exports/chunk-6P44BVZ4.js.map +0 -1
  68. package/dist/exports/chunk-C3GKWCKA.js.map +0 -1
  69. package/dist/exports/chunk-F252JMEU.js.map +0 -1
@@ -0,0 +1,117 @@
1
+ import type { OperationManifest } from '@prisma-next/contract/pack-manifest-types';
2
+ import type { TypesImportSpec } from '@prisma-next/contract/types';
3
+ import type {
4
+ ControlAdapterDescriptor,
5
+ ControlExtensionDescriptor,
6
+ ControlTargetDescriptor,
7
+ } from '@prisma-next/core-control-plane/types';
8
+ import type { OperationRegistry, OperationSignature } from '@prisma-next/operations';
9
+ import { createOperationRegistry } from '@prisma-next/operations';
10
+
11
+ /**
12
+ * Assembles an operation registry from descriptors (adapter, target, extensions).
13
+ * Loops over descriptors, extracts operations, converts them using the provided
14
+ * conversion function, and registers them in a new registry.
15
+ */
16
+ export function assembleOperationRegistry(
17
+ descriptors: ReadonlyArray<
18
+ | ControlTargetDescriptor<'sql', string>
19
+ | ControlAdapterDescriptor<'sql', string>
20
+ | ControlExtensionDescriptor<'sql', string>
21
+ >,
22
+ convertOperationManifest: (manifest: OperationManifest) => OperationSignature,
23
+ ): OperationRegistry {
24
+ const registry = createOperationRegistry();
25
+
26
+ for (const descriptor of descriptors) {
27
+ const operations = descriptor.operations ?? [];
28
+ for (const operationManifest of operations as ReadonlyArray<OperationManifest>) {
29
+ const signature = convertOperationManifest(operationManifest);
30
+ registry.register(signature);
31
+ }
32
+ }
33
+
34
+ return registry;
35
+ }
36
+
37
+ /**
38
+ * Extracts codec type imports from descriptors for contract.d.ts generation.
39
+ */
40
+ export function extractCodecTypeImports(
41
+ descriptors: ReadonlyArray<
42
+ | ControlTargetDescriptor<'sql', string>
43
+ | ControlAdapterDescriptor<'sql', string>
44
+ | ControlExtensionDescriptor<'sql', string>
45
+ >,
46
+ ): ReadonlyArray<TypesImportSpec> {
47
+ const imports: TypesImportSpec[] = [];
48
+
49
+ for (const descriptor of descriptors) {
50
+ const types = descriptor.types;
51
+ const codecTypes = types?.codecTypes;
52
+ if (codecTypes?.import) {
53
+ imports.push(codecTypes.import);
54
+ }
55
+ }
56
+
57
+ return imports;
58
+ }
59
+
60
+ /**
61
+ * Extracts operation type imports from descriptors for contract.d.ts generation.
62
+ */
63
+ export function extractOperationTypeImports(
64
+ descriptors: ReadonlyArray<
65
+ | ControlTargetDescriptor<'sql', string>
66
+ | ControlAdapterDescriptor<'sql', string>
67
+ | ControlExtensionDescriptor<'sql', string>
68
+ >,
69
+ ): ReadonlyArray<TypesImportSpec> {
70
+ const imports: TypesImportSpec[] = [];
71
+
72
+ for (const descriptor of descriptors) {
73
+ const types = descriptor.types;
74
+ const operationTypes = types?.operationTypes;
75
+ if (operationTypes?.import) {
76
+ imports.push(operationTypes.import);
77
+ }
78
+ }
79
+
80
+ return imports;
81
+ }
82
+
83
+ /**
84
+ * Extracts extension IDs from descriptors in deterministic order:
85
+ * [adapter.id, target.id, ...extensions.map(e => e.id)]
86
+ * Deduplicates while preserving stable order.
87
+ */
88
+ export function extractExtensionIds(
89
+ adapter: ControlAdapterDescriptor<'sql', string>,
90
+ target: ControlTargetDescriptor<'sql', string>,
91
+ extensions: ReadonlyArray<ControlExtensionDescriptor<'sql', string>>,
92
+ ): ReadonlyArray<string> {
93
+ const ids: string[] = [];
94
+ const seen = new Set<string>();
95
+
96
+ // Add adapter first
97
+ if (!seen.has(adapter.id)) {
98
+ ids.push(adapter.id);
99
+ seen.add(adapter.id);
100
+ }
101
+
102
+ // Add target second
103
+ if (!seen.has(target.id)) {
104
+ ids.push(target.id);
105
+ seen.add(target.id);
106
+ }
107
+
108
+ // Add extensions in order
109
+ for (const ext of extensions) {
110
+ if (!seen.has(ext.id)) {
111
+ ids.push(ext.id);
112
+ seen.add(ext.id);
113
+ }
114
+ }
115
+
116
+ return ids;
117
+ }
@@ -0,0 +1,52 @@
1
+ import type {
2
+ ControlAdapterInstance,
3
+ ControlDriverInstance,
4
+ } from '@prisma-next/core-control-plane/types';
5
+ import type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';
6
+
7
+ /**
8
+ * SQL control adapter interface for control-plane operations.
9
+ * Implemented by target-specific adapters (e.g., Postgres, MySQL).
10
+ *
11
+ * @template TTarget - The target ID (e.g., 'postgres', 'mysql')
12
+ */
13
+ export interface SqlControlAdapter<TTarget extends string = string>
14
+ extends ControlAdapterInstance<'sql', TTarget> {
15
+ /**
16
+ * The target ID this adapter implements.
17
+ * Used for type tracking and runtime validation.
18
+ * @deprecated Use targetId from ControlAdapterInstance instead
19
+ */
20
+ readonly target: TTarget;
21
+
22
+ /**
23
+ * Introspects a database schema and returns a raw SqlSchemaIR.
24
+ *
25
+ * This is a pure schema discovery operation that queries the database catalog
26
+ * and returns the schema structure without type mapping or contract enrichment.
27
+ * Type mapping and enrichment are handled separately by enrichment helpers.
28
+ *
29
+ * @param driver - ControlDriverInstance instance for executing queries (target-specific)
30
+ * @param contractIR - Optional contract IR for contract-guided introspection (filtering, optimization)
31
+ * @param schema - Schema name to introspect (defaults to 'public')
32
+ * @returns Promise resolving to SqlSchemaIR representing the live database schema
33
+ */
34
+ introspect(
35
+ driver: ControlDriverInstance<'sql', TTarget>,
36
+ contractIR?: unknown,
37
+ schema?: string,
38
+ ): Promise<SqlSchemaIR>;
39
+ }
40
+
41
+ /**
42
+ * SQL control adapter descriptor interface.
43
+ * Provides a factory method to create control adapter instances.
44
+ *
45
+ * @template TTarget - The target ID (e.g., 'postgres', 'mysql')
46
+ */
47
+ export interface SqlControlAdapterDescriptor<TTarget extends string = string> {
48
+ /**
49
+ * Creates a SQL control adapter instance for control-plane operations.
50
+ */
51
+ create(): SqlControlAdapter<TTarget>;
52
+ }
@@ -0,0 +1,33 @@
1
+ import type {
2
+ ControlFamilyDescriptor,
3
+ ControlPlaneStack,
4
+ } from '@prisma-next/core-control-plane/types';
5
+ import { sqlTargetFamilyHook } from '@prisma-next/sql-contract-emitter';
6
+ import { createSqlFamilyInstance, type SqlControlFamilyInstance } from './instance';
7
+
8
+ /**
9
+ * SQL family descriptor implementation.
10
+ * Provides the SQL family hook and factory method.
11
+ */
12
+ export class SqlFamilyDescriptor
13
+ implements ControlFamilyDescriptor<'sql', SqlControlFamilyInstance>
14
+ {
15
+ readonly kind = 'family' as const;
16
+ readonly id = 'sql';
17
+ readonly familyId = 'sql' as const;
18
+ readonly version = '0.0.1';
19
+ readonly hook = sqlTargetFamilyHook;
20
+
21
+ create<TTargetId extends string>(
22
+ stack: ControlPlaneStack<'sql', TTargetId>,
23
+ ): SqlControlFamilyInstance {
24
+ // Note: driver is not passed here because SqlFamilyInstance operations
25
+ // (validate, emit, etc.) don't require DB connectivity. Commands that
26
+ // need the driver (verify, introspect) get it directly from the stack.
27
+ return createSqlFamilyInstance({
28
+ target: stack.target,
29
+ adapter: stack.adapter,
30
+ extensionPacks: stack.extensionPacks,
31
+ });
32
+ }
33
+ }