@prisma-next/family-sql 0.3.0-dev.4 → 0.3.0-dev.41

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 (74) hide show
  1. package/README.md +11 -6
  2. package/dist/assembly-BVS641kd.mjs +106 -0
  3. package/dist/assembly-BVS641kd.mjs.map +1 -0
  4. package/dist/control-adapter.d.mts +60 -0
  5. package/dist/control-adapter.d.mts.map +1 -0
  6. package/dist/control-adapter.mjs +1 -0
  7. package/dist/control-instance-CWKSpACr.d.mts +292 -0
  8. package/dist/control-instance-CWKSpACr.d.mts.map +1 -0
  9. package/dist/control.d.mts +64 -0
  10. package/dist/control.d.mts.map +1 -0
  11. package/dist/control.mjs +534 -0
  12. package/dist/control.mjs.map +1 -0
  13. package/dist/runtime.d.mts +27 -0
  14. package/dist/runtime.d.mts.map +1 -0
  15. package/dist/runtime.mjs +38 -0
  16. package/dist/runtime.mjs.map +1 -0
  17. package/dist/schema-verify.d.mts +48 -0
  18. package/dist/schema-verify.d.mts.map +1 -0
  19. package/dist/schema-verify.mjs +4 -0
  20. package/dist/test-utils.d.mts +2 -0
  21. package/dist/test-utils.mjs +3 -0
  22. package/dist/verify-BfMETJcM.mjs +108 -0
  23. package/dist/verify-BfMETJcM.mjs.map +1 -0
  24. package/dist/verify-sql-schema-DMG0mz1g.mjs +997 -0
  25. package/dist/verify-sql-schema-DMG0mz1g.mjs.map +1 -0
  26. package/dist/verify-sql-schema-DhHnkpPa.d.mts +67 -0
  27. package/dist/verify-sql-schema-DhHnkpPa.d.mts.map +1 -0
  28. package/dist/{exports/verify.d.ts → verify.d.mts} +8 -5
  29. package/dist/verify.d.mts.map +1 -0
  30. package/dist/verify.mjs +3 -0
  31. package/package.json +38 -48
  32. package/src/core/assembly.ts +216 -0
  33. package/src/core/control-adapter.ts +67 -0
  34. package/src/core/control-descriptor.ts +37 -0
  35. package/src/core/control-instance.ts +750 -0
  36. package/src/core/migrations/plan-helpers.ts +164 -0
  37. package/src/core/migrations/policies.ts +8 -0
  38. package/src/core/migrations/types.ts +279 -0
  39. package/src/core/runtime-descriptor.ts +23 -0
  40. package/src/core/runtime-instance.ts +22 -0
  41. package/src/core/schema-verify/verify-helpers.ts +532 -0
  42. package/src/core/schema-verify/verify-sql-schema.ts +1102 -0
  43. package/src/core/verify.ts +168 -0
  44. package/src/exports/control-adapter.ts +1 -0
  45. package/src/exports/control.ts +59 -0
  46. package/src/exports/runtime.ts +3 -0
  47. package/src/exports/schema-verify.ts +19 -0
  48. package/src/exports/test-utils.ts +10 -0
  49. package/src/exports/verify.ts +1 -0
  50. package/dist/exports/chunk-6P44BVZ4.js +0 -580
  51. package/dist/exports/chunk-6P44BVZ4.js.map +0 -1
  52. package/dist/exports/chunk-C3GKWCKA.js +0 -96
  53. package/dist/exports/chunk-C3GKWCKA.js.map +0 -1
  54. package/dist/exports/chunk-F252JMEU.js +0 -772
  55. package/dist/exports/chunk-F252JMEU.js.map +0 -1
  56. package/dist/exports/control-adapter.d.ts +0 -44
  57. package/dist/exports/control-adapter.js +0 -1
  58. package/dist/exports/control-adapter.js.map +0 -1
  59. package/dist/exports/control.d.ts +0 -75
  60. package/dist/exports/control.js +0 -149
  61. package/dist/exports/control.js.map +0 -1
  62. package/dist/exports/instance-DiZi2k_2.d.ts +0 -127
  63. package/dist/exports/runtime.d.ts +0 -66
  64. package/dist/exports/runtime.js +0 -64
  65. package/dist/exports/runtime.js.map +0 -1
  66. package/dist/exports/schema-verify.d.ts +0 -75
  67. package/dist/exports/schema-verify.js +0 -11
  68. package/dist/exports/schema-verify.js.map +0 -1
  69. package/dist/exports/test-utils.d.ts +0 -33
  70. package/dist/exports/test-utils.js +0 -17
  71. package/dist/exports/test-utils.js.map +0 -1
  72. package/dist/exports/types-Bh7ftf0Q.d.ts +0 -275
  73. package/dist/exports/verify.js +0 -11
  74. package/dist/exports/verify.js.map +0 -1
@@ -0,0 +1,168 @@
1
+ import type { ContractMarkerRecord } from '@prisma-next/contract/types';
2
+ import type { ControlDriverInstance } from '@prisma-next/core-control-plane/types';
3
+ import { type } from 'arktype';
4
+
5
+ const MetaSchema = type({ '[string]': 'unknown' });
6
+
7
+ function parseMeta(meta: unknown): Record<string, unknown> {
8
+ if (meta === null || meta === undefined) {
9
+ return {};
10
+ }
11
+
12
+ let parsed: unknown;
13
+ if (typeof meta === 'string') {
14
+ try {
15
+ parsed = JSON.parse(meta);
16
+ } catch {
17
+ return {};
18
+ }
19
+ } else {
20
+ parsed = meta;
21
+ }
22
+
23
+ const result = MetaSchema(parsed);
24
+ if (result instanceof type.errors) {
25
+ return {};
26
+ }
27
+
28
+ return result as Record<string, unknown>;
29
+ }
30
+
31
+ const ContractMarkerRowSchema = type({
32
+ core_hash: 'string',
33
+ profile_hash: 'string',
34
+ 'contract_json?': 'unknown | null',
35
+ 'canonical_version?': 'number | null',
36
+ 'updated_at?': 'Date | string',
37
+ 'app_tag?': 'string | null',
38
+ 'meta?': 'unknown | null',
39
+ });
40
+
41
+ /**
42
+ * Parses a contract marker row from database query result.
43
+ * This is SQL-specific parsing logic (handles SQL row structure with snake_case columns).
44
+ */
45
+ export function parseContractMarkerRow(row: unknown): ContractMarkerRecord {
46
+ const result = ContractMarkerRowSchema(row);
47
+ if (result instanceof type.errors) {
48
+ const messages = result.map((p: { message: string }) => p.message).join('; ');
49
+ throw new Error(`Invalid contract marker row: ${messages}`);
50
+ }
51
+
52
+ const validatedRow = result as {
53
+ core_hash: string;
54
+ profile_hash: string;
55
+ contract_json?: unknown | null;
56
+ canonical_version?: number | null;
57
+ updated_at?: Date | string;
58
+ app_tag?: string | null;
59
+ meta?: unknown | null;
60
+ };
61
+
62
+ const updatedAt = validatedRow.updated_at
63
+ ? validatedRow.updated_at instanceof Date
64
+ ? validatedRow.updated_at
65
+ : new Date(validatedRow.updated_at)
66
+ : new Date();
67
+
68
+ return {
69
+ storageHash: validatedRow.core_hash,
70
+ profileHash: validatedRow.profile_hash,
71
+ contractJson: validatedRow.contract_json ?? null,
72
+ canonicalVersion: validatedRow.canonical_version ?? null,
73
+ updatedAt,
74
+ appTag: validatedRow.app_tag ?? null,
75
+ meta: parseMeta(validatedRow.meta),
76
+ };
77
+ }
78
+
79
+ /**
80
+ * Returns the SQL statement to read the contract marker.
81
+ * This is a migration-plane helper (no runtime imports).
82
+ * @internal - Used internally by readMarker(). Prefer readMarker() for Control Plane usage.
83
+ */
84
+ export function readMarkerSql(): { readonly sql: string; readonly params: readonly unknown[] } {
85
+ return {
86
+ sql: `select
87
+ core_hash,
88
+ profile_hash,
89
+ contract_json,
90
+ canonical_version,
91
+ updated_at,
92
+ app_tag,
93
+ meta
94
+ from prisma_contract.marker
95
+ where id = $1`,
96
+ params: [1],
97
+ };
98
+ }
99
+
100
+ /**
101
+ * Reads the contract marker from the database using the provided driver.
102
+ * Returns the parsed marker record or null if no marker is found.
103
+ * This abstracts SQL-specific details from the Control Plane.
104
+ *
105
+ * @param driver - ControlDriverInstance instance for executing queries
106
+ * @returns Promise resolving to ContractMarkerRecord or null if marker not found
107
+ */
108
+ export async function readMarker(
109
+ driver: ControlDriverInstance<'sql', string>,
110
+ ): Promise<ContractMarkerRecord | null> {
111
+ const markerStatement = readMarkerSql();
112
+
113
+ try {
114
+ const queryResult = await driver.query<{
115
+ core_hash: string;
116
+ profile_hash: string;
117
+ contract_json: unknown | null;
118
+ canonical_version: number | null;
119
+ updated_at: Date | string;
120
+ app_tag: string | null;
121
+ meta: unknown | null;
122
+ }>(markerStatement.sql, markerStatement.params);
123
+
124
+ if (queryResult.rows.length === 0) {
125
+ return null;
126
+ }
127
+
128
+ const markerRow = queryResult.rows[0];
129
+ if (!markerRow) {
130
+ // If rows array has length > 0 but first element is undefined, this is an unexpected result structure
131
+ throw new Error('Database query returned unexpected result structure');
132
+ }
133
+
134
+ return parseContractMarkerRow(markerRow);
135
+ } catch (error) {
136
+ // Handle case where marker table doesn't exist yet (empty database)
137
+ // PostgreSQL error code 42P01 = undefined_table
138
+ if (
139
+ error instanceof Error &&
140
+ (error.message.includes('does not exist') || (error as { code?: string }).code === '42P01')
141
+ ) {
142
+ return null;
143
+ }
144
+ throw error;
145
+ }
146
+ }
147
+
148
+ /**
149
+ * Collects supported codec type IDs from adapter and extension manifests.
150
+ * Returns a sorted, unique array of type IDs that are declared in the manifests.
151
+ * This enables coverage checks by comparing contract column types against supported types.
152
+ *
153
+ * Note: This extracts type IDs from manifest type imports, not from runtime codec registries.
154
+ * The manifests declare which codec types are available, but the actual type IDs
155
+ * are defined in the codec-types TypeScript modules that are imported.
156
+ *
157
+ * For MVP, we return an empty array since extracting type IDs from TypeScript modules
158
+ * would require runtime evaluation or static analysis. This can be enhanced later.
159
+ */
160
+ export function collectSupportedCodecTypeIds(
161
+ descriptors: ReadonlyArray<{ readonly id: string }>,
162
+ ): readonly string[] {
163
+ // For MVP, return empty array
164
+ // Future enhancement: Extract type IDs from codec-types modules via static analysis
165
+ // or require manifests to explicitly list supported type IDs
166
+ void descriptors;
167
+ return [];
168
+ }
@@ -0,0 +1 @@
1
+ export type { SqlControlAdapter, SqlControlAdapterDescriptor } from '../core/control-adapter';
@@ -0,0 +1,59 @@
1
+ import { SqlFamilyDescriptor } from '../core/control-descriptor';
2
+
3
+ // Re-export core types from canonical source
4
+ export type {
5
+ MigrationOperationClass,
6
+ MigrationOperationPolicy,
7
+ MigrationPlan,
8
+ MigrationPlanner,
9
+ MigrationPlannerConflict,
10
+ MigrationPlannerResult,
11
+ MigrationPlanOperation,
12
+ TargetMigrationsCapability,
13
+ } from '@prisma-next/core-control-plane/types';
14
+ export type { SqlControlDescriptorWithContributions } from '../core/assembly';
15
+ export { extractCodecControlHooks } from '../core/assembly';
16
+ export type { SchemaVerifyOptions, SqlControlFamilyInstance } from '../core/control-instance';
17
+ export {
18
+ createMigrationPlan,
19
+ plannerFailure,
20
+ plannerSuccess,
21
+ runnerFailure,
22
+ runnerSuccess,
23
+ } from '../core/migrations/plan-helpers';
24
+ export { INIT_ADDITIVE_POLICY } from '../core/migrations/policies';
25
+ // SQL-specific types
26
+ export type {
27
+ CodecControlHooks,
28
+ ComponentDatabaseDependencies,
29
+ ComponentDatabaseDependency,
30
+ CreateSqlMigrationPlanOptions,
31
+ ExpandNativeTypeInput,
32
+ SqlControlAdapterDescriptor,
33
+ SqlControlExtensionDescriptor,
34
+ SqlControlStaticContributions,
35
+ SqlControlTargetDescriptor,
36
+ SqlMigrationPlan,
37
+ SqlMigrationPlanContractInfo,
38
+ SqlMigrationPlanner,
39
+ SqlMigrationPlannerPlanOptions,
40
+ SqlMigrationPlanOperation,
41
+ SqlMigrationPlanOperationStep,
42
+ SqlMigrationPlanOperationTarget,
43
+ SqlMigrationRunner,
44
+ SqlMigrationRunnerErrorCode,
45
+ SqlMigrationRunnerExecuteCallbacks,
46
+ SqlMigrationRunnerExecuteOptions,
47
+ SqlMigrationRunnerFailure,
48
+ SqlMigrationRunnerResult,
49
+ SqlMigrationRunnerSuccessValue,
50
+ SqlPlannerConflict,
51
+ SqlPlannerConflictKind,
52
+ SqlPlannerConflictLocation,
53
+ SqlPlannerFailureResult,
54
+ SqlPlannerResult,
55
+ SqlPlannerSuccessResult,
56
+ StorageTypePlanResult,
57
+ } from '../core/migrations/types';
58
+
59
+ export default new SqlFamilyDescriptor();
@@ -0,0 +1,3 @@
1
+ import { sqlRuntimeFamilyDescriptor } from '../core/runtime-descriptor';
2
+
3
+ export default sqlRuntimeFamilyDescriptor;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Pure schema verification exports.
3
+ *
4
+ * This module exports the pure schema verification function that can be used
5
+ * without a database connection. It's suitable for migration planning and
6
+ * other tools that need to compare schema states.
7
+ */
8
+
9
+ export {
10
+ arraysEqual,
11
+ isIndexSatisfied,
12
+ isUniqueConstraintSatisfied,
13
+ verifyDatabaseDependencies,
14
+ } from '../core/schema-verify/verify-helpers';
15
+ export type {
16
+ NativeTypeNormalizer,
17
+ VerifySqlSchemaOptions,
18
+ } from '../core/schema-verify/verify-sql-schema';
19
+ export { verifySqlSchema } from '../core/schema-verify/verify-sql-schema';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Test utilities for working with component descriptors.
3
+ * These functions operate on descriptors directly, used in tests and integration tests.
4
+ */
5
+ export {
6
+ assembleOperationRegistry,
7
+ extractCodecTypeImports,
8
+ extractExtensionIds,
9
+ extractOperationTypeImports,
10
+ } from '../core/assembly';
@@ -0,0 +1 @@
1
+ export { parseContractMarkerRow, readMarker, readMarkerSql } from '../core/verify';