@prisma-next/core-control-plane 0.0.1
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 +118 -0
- package/dist/chunk-DZPZSLCM.js +178 -0
- package/dist/chunk-DZPZSLCM.js.map +1 -0
- package/dist/exports/config-types.d.ts +69 -0
- package/dist/exports/config-types.js +53 -0
- package/dist/exports/config-types.js.map +1 -0
- package/dist/exports/config-validation.d.ts +17 -0
- package/dist/exports/config-validation.js +252 -0
- package/dist/exports/config-validation.js.map +1 -0
- package/dist/exports/emission.d.ts +42 -0
- package/dist/exports/emission.js +313 -0
- package/dist/exports/emission.js.map +1 -0
- package/dist/exports/errors.d.ts +146 -0
- package/dist/exports/errors.js +35 -0
- package/dist/exports/errors.js.map +1 -0
- package/dist/exports/schema-view.d.ts +87 -0
- package/dist/exports/schema-view.js +1 -0
- package/dist/exports/schema-view.js.map +1 -0
- package/dist/exports/types.d.ts +371 -0
- package/dist/exports/types.js +1 -0
- package/dist/exports/types.js.map +1 -0
- package/package.json +56 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/emission/canonicalization.ts","../../src/emission/emit.ts","../../src/emission/hashing.ts"],"sourcesContent":["import type { ContractIR } from '@prisma-next/contract/ir';\n\ntype NormalizedContract = {\n schemaVersion: string;\n targetFamily: string;\n target: string;\n coreHash?: string;\n profileHash?: string;\n models: Record<string, unknown>;\n relations: Record<string, unknown>;\n storage: Record<string, unknown>;\n extensions: Record<string, unknown>;\n capabilities: Record<string, Record<string, boolean>>;\n meta: Record<string, unknown>;\n sources: Record<string, unknown>;\n};\n\nconst TOP_LEVEL_ORDER = [\n 'schemaVersion',\n 'canonicalVersion',\n 'targetFamily',\n 'target',\n 'coreHash',\n 'profileHash',\n 'models',\n 'storage',\n 'capabilities',\n 'extensions',\n 'meta',\n 'sources',\n] as const;\n\nfunction isDefaultValue(value: unknown): boolean {\n if (value === false) return true;\n if (value === null) return false;\n if (Array.isArray(value) && value.length === 0) return true;\n if (typeof value === 'object' && value !== null) {\n const keys = Object.keys(value);\n return keys.length === 0;\n }\n return false;\n}\n\nfunction omitDefaults(obj: unknown, path: readonly string[]): unknown {\n if (obj === null || typeof obj !== 'object') {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map((item) => omitDefaults(item, path));\n }\n\n const result: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n const currentPath = [...path, key];\n\n // Exclude metadata fields from canonicalization\n if (key === '_generated') {\n continue;\n }\n\n if (key === 'nullable' && value === false) {\n continue;\n }\n\n if (key === 'generated' && value === false) {\n continue;\n }\n\n if (isDefaultValue(value)) {\n const isRequiredModels = currentPath.length === 1 && currentPath[0] === 'models';\n const isRequiredTables =\n currentPath.length === 2 && currentPath[0] === 'storage' && currentPath[1] === 'tables';\n const isRequiredRelations = currentPath.length === 1 && currentPath[0] === 'relations';\n const isRequiredExtensions = currentPath.length === 1 && currentPath[0] === 'extensions';\n const isRequiredCapabilities = currentPath.length === 1 && currentPath[0] === 'capabilities';\n const isRequiredMeta = currentPath.length === 1 && currentPath[0] === 'meta';\n const isRequiredSources = currentPath.length === 1 && currentPath[0] === 'sources';\n const isExtensionNamespace = currentPath.length === 2 && currentPath[0] === 'extensions';\n const isModelRelations =\n currentPath.length === 3 && currentPath[0] === 'models' && currentPath[2] === 'relations';\n const isTableUniques =\n currentPath.length === 4 &&\n currentPath[0] === 'storage' &&\n currentPath[1] === 'tables' &&\n currentPath[3] === 'uniques';\n const isTableIndexes =\n currentPath.length === 4 &&\n currentPath[0] === 'storage' &&\n currentPath[1] === 'tables' &&\n currentPath[3] === 'indexes';\n const isTableForeignKeys =\n currentPath.length === 4 &&\n currentPath[0] === 'storage' &&\n currentPath[1] === 'tables' &&\n currentPath[3] === 'foreignKeys';\n\n if (\n !isRequiredModels &&\n !isRequiredTables &&\n !isRequiredRelations &&\n !isRequiredExtensions &&\n !isRequiredCapabilities &&\n !isRequiredMeta &&\n !isRequiredSources &&\n !isExtensionNamespace &&\n !isModelRelations &&\n !isTableUniques &&\n !isTableIndexes &&\n !isTableForeignKeys\n ) {\n continue;\n }\n }\n\n result[key] = omitDefaults(value, currentPath);\n }\n\n return result;\n}\n\nfunction sortObjectKeys(obj: unknown): unknown {\n if (obj === null || typeof obj !== 'object') {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map((item) => sortObjectKeys(item));\n }\n\n const sorted: Record<string, unknown> = {};\n const keys = Object.keys(obj).sort();\n for (const key of keys) {\n sorted[key] = sortObjectKeys((obj as Record<string, unknown>)[key]);\n }\n\n return sorted;\n}\n\ntype StorageObject = {\n tables?: Record<string, unknown>;\n [key: string]: unknown;\n};\n\ntype TableObject = {\n indexes?: unknown[];\n uniques?: unknown[];\n [key: string]: unknown;\n};\n\nfunction sortIndexesAndUniques(storage: unknown): unknown {\n if (!storage || typeof storage !== 'object') {\n return storage;\n }\n\n const storageObj = storage as StorageObject;\n if (!storageObj.tables || typeof storageObj.tables !== 'object') {\n return storage;\n }\n\n const tables = storageObj.tables;\n const result: StorageObject = { ...storageObj };\n\n result.tables = {};\n // Sort table names to ensure deterministic ordering\n const sortedTableNames = Object.keys(tables).sort();\n for (const tableName of sortedTableNames) {\n const table = tables[tableName];\n if (!table || typeof table !== 'object') {\n result.tables[tableName] = table;\n continue;\n }\n\n const tableObj = table as TableObject;\n const sortedTable: TableObject = { ...tableObj };\n\n if (Array.isArray(tableObj.indexes)) {\n sortedTable.indexes = [...tableObj.indexes].sort((a, b) => {\n const nameA = (a as { name?: string })?.name || '';\n const nameB = (b as { name?: string })?.name || '';\n return nameA.localeCompare(nameB);\n });\n }\n\n if (Array.isArray(tableObj.uniques)) {\n sortedTable.uniques = [...tableObj.uniques].sort((a, b) => {\n const nameA = (a as { name?: string })?.name || '';\n const nameB = (b as { name?: string })?.name || '';\n return nameA.localeCompare(nameB);\n });\n }\n\n result.tables[tableName] = sortedTable;\n }\n\n return result;\n}\n\nfunction orderTopLevel(obj: Record<string, unknown>): Record<string, unknown> {\n const ordered: Record<string, unknown> = {};\n const remaining = new Set(Object.keys(obj));\n\n for (const key of TOP_LEVEL_ORDER) {\n if (remaining.has(key)) {\n ordered[key] = obj[key];\n remaining.delete(key);\n }\n }\n\n for (const key of Array.from(remaining).sort()) {\n ordered[key] = obj[key];\n }\n\n return ordered;\n}\n\nexport function canonicalizeContract(\n ir: ContractIR & { coreHash?: string; profileHash?: string },\n): string {\n const normalized: NormalizedContract = {\n schemaVersion: ir.schemaVersion,\n targetFamily: ir.targetFamily,\n target: ir.target,\n models: ir.models,\n relations: ir.relations,\n storage: ir.storage,\n extensions: ir.extensions,\n capabilities: ir.capabilities,\n meta: ir.meta,\n sources: ir.sources,\n };\n\n if (ir.coreHash !== undefined) {\n normalized.coreHash = ir.coreHash;\n }\n\n if (ir.profileHash !== undefined) {\n normalized.profileHash = ir.profileHash;\n }\n\n const withDefaultsOmitted = omitDefaults(normalized, []) as NormalizedContract;\n const withSortedIndexes = sortIndexesAndUniques(withDefaultsOmitted.storage);\n const withSortedStorage = { ...withDefaultsOmitted, storage: withSortedIndexes };\n const withSortedKeys = sortObjectKeys(withSortedStorage) as Record<string, unknown>;\n const withOrderedTopLevel = orderTopLevel(withSortedKeys);\n\n return JSON.stringify(withOrderedTopLevel, null, 2);\n}\n","import type { ContractIR } from '@prisma-next/contract/ir';\nimport type { TargetFamilyHook, ValidationContext } from '@prisma-next/contract/types';\nimport { format } from 'prettier';\nimport { canonicalizeContract } from './canonicalization';\nimport { computeCoreHash, computeProfileHash } from './hashing';\nimport type { EmitOptions, EmitResult } from './types';\n\nfunction validateCoreStructure(ir: ContractIR): void {\n if (!ir.targetFamily) {\n throw new Error('ContractIR must have targetFamily');\n }\n if (!ir.target) {\n throw new Error('ContractIR must have target');\n }\n if (!ir.schemaVersion) {\n throw new Error('ContractIR must have schemaVersion');\n }\n if (!ir.models || typeof ir.models !== 'object') {\n throw new Error('ContractIR must have models');\n }\n if (!ir.storage || typeof ir.storage !== 'object') {\n throw new Error('ContractIR must have storage');\n }\n if (!ir.relations || typeof ir.relations !== 'object') {\n throw new Error('ContractIR must have relations');\n }\n if (!ir.extensions || typeof ir.extensions !== 'object') {\n throw new Error('ContractIR must have extensions');\n }\n if (!ir.capabilities || typeof ir.capabilities !== 'object') {\n throw new Error('ContractIR must have capabilities');\n }\n if (!ir.meta || typeof ir.meta !== 'object') {\n throw new Error('ContractIR must have meta');\n }\n if (!ir.sources || typeof ir.sources !== 'object') {\n throw new Error('ContractIR must have sources');\n }\n}\n\nfunction validateExtensions(ir: ContractIR, extensionIds: ReadonlyArray<string>): void {\n const extensions = ir.extensions as Record<string, unknown>;\n for (const extensionId of extensionIds) {\n if (!extensions[extensionId]) {\n throw new Error(\n `Extension \"${extensionId}\" must appear in contract.extensions.${extensionId}`,\n );\n }\n }\n}\n\nexport async function emit(\n ir: ContractIR,\n options: EmitOptions,\n targetFamily: TargetFamilyHook,\n): Promise<EmitResult> {\n const { operationRegistry, codecTypeImports, operationTypeImports, extensionIds } = options;\n\n validateCoreStructure(ir);\n\n const ctx: ValidationContext = {\n ...(operationRegistry ? { operationRegistry } : {}),\n ...(codecTypeImports ? { codecTypeImports } : {}),\n ...(operationTypeImports ? { operationTypeImports } : {}),\n ...(extensionIds ? { extensionIds } : {}),\n };\n targetFamily.validateTypes(ir, ctx);\n\n targetFamily.validateStructure(ir);\n\n if (extensionIds) {\n validateExtensions(ir, extensionIds);\n }\n\n const contractJson = {\n schemaVersion: ir.schemaVersion,\n targetFamily: ir.targetFamily,\n target: ir.target,\n models: ir.models,\n relations: ir.relations,\n storage: ir.storage,\n extensions: ir.extensions,\n capabilities: ir.capabilities,\n meta: ir.meta,\n sources: ir.sources,\n } as const;\n\n const coreHash = computeCoreHash(contractJson);\n const profileHash = computeProfileHash(contractJson);\n\n const contractWithHashes: ContractIR & { coreHash?: string; profileHash?: string } = {\n ...ir,\n schemaVersion: contractJson.schemaVersion,\n coreHash,\n profileHash,\n };\n\n // Add _generated metadata to indicate this is a generated artifact\n // This ensures consistency between CLI emit and programmatic emit\n // Always add/update _generated with standard content for consistency\n const contractJsonObj = JSON.parse(canonicalizeContract(contractWithHashes)) as Record<\n string,\n unknown\n >;\n const contractJsonWithMeta = {\n ...contractJsonObj,\n _generated: {\n warning: '⚠️ GENERATED FILE - DO NOT EDIT',\n message: 'This file is automatically generated by \"prisma-next emit\".',\n regenerate: 'To regenerate, run: prisma-next emit',\n },\n };\n const contractJsonString = JSON.stringify(contractJsonWithMeta, null, 2);\n\n const contractDtsRaw = targetFamily.generateContractTypes(\n ir,\n codecTypeImports ?? [],\n operationTypeImports ?? [],\n );\n const contractDts = await format(contractDtsRaw, {\n parser: 'typescript',\n singleQuote: true,\n semi: true,\n printWidth: 100,\n });\n\n return {\n contractJson: contractJsonString,\n contractDts,\n coreHash,\n profileHash,\n };\n}\n","import { createHash } from 'node:crypto';\nimport type { ContractIR } from '@prisma-next/contract/ir';\nimport { canonicalizeContract } from './canonicalization';\n\ntype ContractInput = {\n schemaVersion: string;\n targetFamily: string;\n target: string;\n models: Record<string, unknown>;\n relations: Record<string, unknown>;\n storage: Record<string, unknown>;\n extensions: Record<string, unknown>;\n sources: Record<string, unknown>;\n capabilities: Record<string, Record<string, boolean>>;\n meta: Record<string, unknown>;\n [key: string]: unknown;\n};\n\nfunction computeHash(content: string): string {\n const hash = createHash('sha256');\n hash.update(content);\n return `sha256:${hash.digest('hex')}`;\n}\n\nexport function computeCoreHash(contract: ContractInput): string {\n const coreContract: ContractIR = {\n schemaVersion: contract.schemaVersion,\n targetFamily: contract.targetFamily,\n target: contract.target,\n models: contract.models,\n relations: contract.relations,\n storage: contract.storage,\n extensions: contract.extensions,\n sources: contract.sources,\n capabilities: contract.capabilities,\n meta: contract.meta,\n };\n const canonical = canonicalizeContract(coreContract);\n return computeHash(canonical);\n}\n\nexport function computeProfileHash(contract: ContractInput): string {\n const profileContract: ContractIR = {\n schemaVersion: contract.schemaVersion,\n targetFamily: contract.targetFamily,\n target: contract.target,\n models: {},\n relations: {},\n storage: {},\n extensions: {},\n capabilities: contract.capabilities,\n meta: {},\n sources: {},\n };\n const canonical = canonicalizeContract(profileContract);\n return computeHash(canonical);\n}\n"],"mappings":";AAiBA,IAAM,kBAAkB;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,SAAS,eAAe,OAAyB;AAC/C,MAAI,UAAU,MAAO,QAAO;AAC5B,MAAI,UAAU,KAAM,QAAO;AAC3B,MAAI,MAAM,QAAQ,KAAK,KAAK,MAAM,WAAW,EAAG,QAAO;AACvD,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,UAAM,OAAO,OAAO,KAAK,KAAK;AAC9B,WAAO,KAAK,WAAW;AAAA,EACzB;AACA,SAAO;AACT;AAEA,SAAS,aAAa,KAAc,MAAkC;AACpE,MAAI,QAAQ,QAAQ,OAAO,QAAQ,UAAU;AAC3C,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,QAAQ,GAAG,GAAG;AACtB,WAAO,IAAI,IAAI,CAAC,SAAS,aAAa,MAAM,IAAI,CAAC;AAAA,EACnD;AAEA,QAAM,SAAkC,CAAC;AAEzC,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,UAAM,cAAc,CAAC,GAAG,MAAM,GAAG;AAGjC,QAAI,QAAQ,cAAc;AACxB;AAAA,IACF;AAEA,QAAI,QAAQ,cAAc,UAAU,OAAO;AACzC;AAAA,IACF;AAEA,QAAI,QAAQ,eAAe,UAAU,OAAO;AAC1C;AAAA,IACF;AAEA,QAAI,eAAe,KAAK,GAAG;AACzB,YAAM,mBAAmB,YAAY,WAAW,KAAK,YAAY,CAAC,MAAM;AACxE,YAAM,mBACJ,YAAY,WAAW,KAAK,YAAY,CAAC,MAAM,aAAa,YAAY,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,IACX,QAAQ,GAAG;AAAA,IACX,WAAW,GAAG;AAAA,IACd,SAAS,GAAG;AAAA,IACZ,YAAY,GAAG;AAAA,IACf,cAAc,GAAG;AAAA,IACjB,MAAM,GAAG;AAAA,IACT,SAAS,GAAG;AAAA,EACd;AAEA,QAAM,WAAW,gBAAgB,YAAY;AAC7C,QAAM,cAAc,mBAAmB,YAAY;AAEnD,QAAM,qBAA+E;AAAA,IACnF,GAAG;AAAA,IACH,eAAe,aAAa;AAAA,IAC5B;AAAA,IACA;AAAA,EACF;AAKA,QAAM,kBAAkB,KAAK,MAAM,qBAAqB,kBAAkB,CAAC;AAI3E,QAAM,uBAAuB;AAAA,IAC3B,GAAG;AAAA,IACH,YAAY;AAAA,MACV,SAAS;AAAA,MACT,SAAS;AAAA,MACT,YAAY;AAAA,IACd;AAAA,EACF;AACA,QAAM,qBAAqB,KAAK,UAAU,sBAAsB,MAAM,CAAC;AAEvE,QAAM,iBAAiB,aAAa;AAAA,IAClC;AAAA,IACA,oBAAoB,CAAC;AAAA,IACrB,wBAAwB,CAAC;AAAA,EAC3B;AACA,QAAM,cAAc,MAAM,OAAO,gBAAgB;AAAA,IAC/C,QAAQ;AAAA,IACR,aAAa;AAAA,IACb,MAAM;AAAA,IACN,YAAY;AAAA,EACd,CAAC;AAED,SAAO;AAAA,IACL,cAAc;AAAA,IACd;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI error envelope for output formatting.
|
|
3
|
+
* This is the serialized form of a CliStructuredError.
|
|
4
|
+
*/
|
|
5
|
+
interface CliErrorEnvelope {
|
|
6
|
+
readonly code: string;
|
|
7
|
+
readonly domain: string;
|
|
8
|
+
readonly severity: 'error' | 'warn' | 'info';
|
|
9
|
+
readonly summary: string;
|
|
10
|
+
readonly why: string | undefined;
|
|
11
|
+
readonly fix: string | undefined;
|
|
12
|
+
readonly where: {
|
|
13
|
+
readonly path: string | undefined;
|
|
14
|
+
readonly line: number | undefined;
|
|
15
|
+
} | undefined;
|
|
16
|
+
readonly meta: Record<string, unknown> | undefined;
|
|
17
|
+
readonly docsUrl: string | undefined;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Structured CLI error that contains all information needed for error envelopes.
|
|
21
|
+
* Call sites throw these errors with full context.
|
|
22
|
+
*/
|
|
23
|
+
declare class CliStructuredError extends Error {
|
|
24
|
+
readonly code: string;
|
|
25
|
+
readonly domain: 'CLI' | 'RTM';
|
|
26
|
+
readonly severity: 'error' | 'warn' | 'info';
|
|
27
|
+
readonly why: string | undefined;
|
|
28
|
+
readonly fix: string | undefined;
|
|
29
|
+
readonly where: {
|
|
30
|
+
readonly path: string | undefined;
|
|
31
|
+
readonly line: number | undefined;
|
|
32
|
+
} | undefined;
|
|
33
|
+
readonly meta: Record<string, unknown> | undefined;
|
|
34
|
+
readonly docsUrl: string | undefined;
|
|
35
|
+
constructor(code: string, summary: string, options?: {
|
|
36
|
+
readonly domain?: 'CLI' | 'RTM';
|
|
37
|
+
readonly severity?: 'error' | 'warn' | 'info';
|
|
38
|
+
readonly why?: string;
|
|
39
|
+
readonly fix?: string;
|
|
40
|
+
readonly where?: {
|
|
41
|
+
readonly path?: string;
|
|
42
|
+
readonly line?: number;
|
|
43
|
+
};
|
|
44
|
+
readonly meta?: Record<string, unknown>;
|
|
45
|
+
readonly docsUrl?: string;
|
|
46
|
+
});
|
|
47
|
+
/**
|
|
48
|
+
* Converts this error to a CLI error envelope for output formatting.
|
|
49
|
+
*/
|
|
50
|
+
toEnvelope(): CliErrorEnvelope;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Config file not found or missing.
|
|
54
|
+
*/
|
|
55
|
+
declare function errorConfigFileNotFound(configPath?: string, options?: {
|
|
56
|
+
readonly why?: string;
|
|
57
|
+
}): CliStructuredError;
|
|
58
|
+
/**
|
|
59
|
+
* Contract configuration missing from config.
|
|
60
|
+
*/
|
|
61
|
+
declare function errorContractConfigMissing(options?: {
|
|
62
|
+
readonly why?: string;
|
|
63
|
+
}): CliStructuredError;
|
|
64
|
+
/**
|
|
65
|
+
* Contract validation failed.
|
|
66
|
+
*/
|
|
67
|
+
declare function errorContractValidationFailed(reason: string, options?: {
|
|
68
|
+
readonly where?: {
|
|
69
|
+
readonly path?: string;
|
|
70
|
+
readonly line?: number;
|
|
71
|
+
};
|
|
72
|
+
}): CliStructuredError;
|
|
73
|
+
/**
|
|
74
|
+
* File not found.
|
|
75
|
+
*/
|
|
76
|
+
declare function errorFileNotFound(filePath: string, options?: {
|
|
77
|
+
readonly why?: string;
|
|
78
|
+
}): CliStructuredError;
|
|
79
|
+
/**
|
|
80
|
+
* Database URL is required but not provided.
|
|
81
|
+
*/
|
|
82
|
+
declare function errorDatabaseUrlRequired(options?: {
|
|
83
|
+
readonly why?: string;
|
|
84
|
+
}): CliStructuredError;
|
|
85
|
+
/**
|
|
86
|
+
* Query runner factory is required but not provided in config.
|
|
87
|
+
*/
|
|
88
|
+
declare function errorQueryRunnerFactoryRequired(options?: {
|
|
89
|
+
readonly why?: string;
|
|
90
|
+
}): CliStructuredError;
|
|
91
|
+
/**
|
|
92
|
+
* Family verify.readMarker is required but not provided.
|
|
93
|
+
*/
|
|
94
|
+
declare function errorFamilyReadMarkerSqlRequired(options?: {
|
|
95
|
+
readonly why?: string;
|
|
96
|
+
}): CliStructuredError;
|
|
97
|
+
/**
|
|
98
|
+
* Driver is required for DB-connected commands but not provided.
|
|
99
|
+
*/
|
|
100
|
+
declare function errorDriverRequired(options?: {
|
|
101
|
+
readonly why?: string;
|
|
102
|
+
}): CliStructuredError;
|
|
103
|
+
/**
|
|
104
|
+
* Config validation error (missing required fields).
|
|
105
|
+
*/
|
|
106
|
+
declare function errorConfigValidation(field: string, options?: {
|
|
107
|
+
readonly why?: string;
|
|
108
|
+
}): CliStructuredError;
|
|
109
|
+
/**
|
|
110
|
+
* Contract marker not found in database.
|
|
111
|
+
*/
|
|
112
|
+
declare function errorMarkerMissing(options?: {
|
|
113
|
+
readonly why?: string;
|
|
114
|
+
readonly dbUrl?: string;
|
|
115
|
+
}): CliStructuredError;
|
|
116
|
+
/**
|
|
117
|
+
* Contract hash does not match database marker.
|
|
118
|
+
*/
|
|
119
|
+
declare function errorHashMismatch(options?: {
|
|
120
|
+
readonly why?: string;
|
|
121
|
+
readonly expected?: string;
|
|
122
|
+
readonly actual?: string;
|
|
123
|
+
}): CliStructuredError;
|
|
124
|
+
/**
|
|
125
|
+
* Contract target does not match config target.
|
|
126
|
+
*/
|
|
127
|
+
declare function errorTargetMismatch(expected: string, actual: string, options?: {
|
|
128
|
+
readonly why?: string;
|
|
129
|
+
}): CliStructuredError;
|
|
130
|
+
/**
|
|
131
|
+
* Generic runtime error.
|
|
132
|
+
*/
|
|
133
|
+
declare function errorRuntime(summary: string, options?: {
|
|
134
|
+
readonly why?: string;
|
|
135
|
+
readonly fix?: string;
|
|
136
|
+
readonly meta?: Record<string, unknown>;
|
|
137
|
+
}): CliStructuredError;
|
|
138
|
+
/**
|
|
139
|
+
* Generic unexpected error.
|
|
140
|
+
*/
|
|
141
|
+
declare function errorUnexpected(message: string, options?: {
|
|
142
|
+
readonly why?: string;
|
|
143
|
+
readonly fix?: string;
|
|
144
|
+
}): CliStructuredError;
|
|
145
|
+
|
|
146
|
+
export { type CliErrorEnvelope, CliStructuredError, errorConfigFileNotFound, errorConfigValidation, errorContractConfigMissing, errorContractValidationFailed, errorDatabaseUrlRequired, errorDriverRequired, errorFamilyReadMarkerSqlRequired, errorFileNotFound, errorHashMismatch, errorMarkerMissing, errorQueryRunnerFactoryRequired, errorRuntime, errorTargetMismatch, errorUnexpected };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CliStructuredError,
|
|
3
|
+
errorConfigFileNotFound,
|
|
4
|
+
errorConfigValidation,
|
|
5
|
+
errorContractConfigMissing,
|
|
6
|
+
errorContractValidationFailed,
|
|
7
|
+
errorDatabaseUrlRequired,
|
|
8
|
+
errorDriverRequired,
|
|
9
|
+
errorFamilyReadMarkerSqlRequired,
|
|
10
|
+
errorFileNotFound,
|
|
11
|
+
errorHashMismatch,
|
|
12
|
+
errorMarkerMissing,
|
|
13
|
+
errorQueryRunnerFactoryRequired,
|
|
14
|
+
errorRuntime,
|
|
15
|
+
errorTargetMismatch,
|
|
16
|
+
errorUnexpected
|
|
17
|
+
} from "../chunk-DZPZSLCM.js";
|
|
18
|
+
export {
|
|
19
|
+
CliStructuredError,
|
|
20
|
+
errorConfigFileNotFound,
|
|
21
|
+
errorConfigValidation,
|
|
22
|
+
errorContractConfigMissing,
|
|
23
|
+
errorContractValidationFailed,
|
|
24
|
+
errorDatabaseUrlRequired,
|
|
25
|
+
errorDriverRequired,
|
|
26
|
+
errorFamilyReadMarkerSqlRequired,
|
|
27
|
+
errorFileNotFound,
|
|
28
|
+
errorHashMismatch,
|
|
29
|
+
errorMarkerMissing,
|
|
30
|
+
errorQueryRunnerFactoryRequired,
|
|
31
|
+
errorRuntime,
|
|
32
|
+
errorTargetMismatch,
|
|
33
|
+
errorUnexpected
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core schema view types for family-agnostic schema visualization.
|
|
3
|
+
*
|
|
4
|
+
* These types provide a minimal, generic, tree-shaped representation of schemas
|
|
5
|
+
* across families, designed for CLI visualization and lightweight tooling.
|
|
6
|
+
*
|
|
7
|
+
* Families can optionally project their family-specific Schema IR into this
|
|
8
|
+
* core view via the `toSchemaView` method on `FamilyInstance`.
|
|
9
|
+
*
|
|
10
|
+
* ## Example: SQL Family Mapping
|
|
11
|
+
*
|
|
12
|
+
* For the SQL family, `SqlSchemaIR` can be mapped to `CoreSchemaView` as follows:
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* // SqlSchemaIR structure:
|
|
16
|
+
* // {
|
|
17
|
+
* // tables: { user: { columns: {...}, primaryKey: {...}, ... }, ... },
|
|
18
|
+
* // extensions: ['pgvector'],
|
|
19
|
+
* // annotations: {...}
|
|
20
|
+
* // }
|
|
21
|
+
*
|
|
22
|
+
* // CoreSchemaView mapping:
|
|
23
|
+
* // {
|
|
24
|
+
* // root: {
|
|
25
|
+
* // kind: 'root',
|
|
26
|
+
* // id: 'sql-schema',
|
|
27
|
+
* // label: 'sql schema (tables: 2)',
|
|
28
|
+
* // children: [
|
|
29
|
+
* // {
|
|
30
|
+
* // kind: 'entity',
|
|
31
|
+
* // id: 'table-user',
|
|
32
|
+
* // label: 'table user',
|
|
33
|
+
* // meta: { primaryKey: ['id'], ... },
|
|
34
|
+
* // children: [
|
|
35
|
+
* // {
|
|
36
|
+
* // kind: 'field',
|
|
37
|
+
* // id: 'column-id',
|
|
38
|
+
* // label: 'id: pg/int4@1 (not null)',
|
|
39
|
+
* // meta: { typeId: 'pg/int4@1', nullable: false, ... }
|
|
40
|
+
* // },
|
|
41
|
+
* // {
|
|
42
|
+
* // kind: 'index',
|
|
43
|
+
* // id: 'index-user-email',
|
|
44
|
+
* // label: 'index user_email_unique',
|
|
45
|
+
* // meta: { columns: ['email'], unique: true, ... }
|
|
46
|
+
* // }
|
|
47
|
+
* // ]
|
|
48
|
+
* // },
|
|
49
|
+
* // {
|
|
50
|
+
* // kind: 'extension',
|
|
51
|
+
* // id: 'extension-pgvector',
|
|
52
|
+
* // label: 'extension pgvector',
|
|
53
|
+
* // meta: { ... }
|
|
54
|
+
* // }
|
|
55
|
+
* // ]
|
|
56
|
+
* // }
|
|
57
|
+
* // }
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* This mapping demonstrates that the core view types are expressive enough
|
|
61
|
+
* to represent SQL schemas without being SQL-specific.
|
|
62
|
+
*/
|
|
63
|
+
/**
|
|
64
|
+
* Node kinds for schema tree nodes.
|
|
65
|
+
* Designed to be generic enough for SQL, document, KV, and future families.
|
|
66
|
+
*/
|
|
67
|
+
type SchemaNodeKind = 'root' | 'namespace' | 'collection' | 'entity' | 'field' | 'index' | 'extension';
|
|
68
|
+
/**
|
|
69
|
+
* A node in the schema tree.
|
|
70
|
+
* Tree-shaped structure good for Command Tree-style CLI output.
|
|
71
|
+
*/
|
|
72
|
+
interface SchemaTreeNode {
|
|
73
|
+
readonly kind: SchemaNodeKind;
|
|
74
|
+
readonly id: string;
|
|
75
|
+
readonly label: string;
|
|
76
|
+
readonly meta?: Record<string, unknown>;
|
|
77
|
+
readonly children?: readonly SchemaTreeNode[];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Core schema view providing a family-agnostic tree representation of a schema.
|
|
81
|
+
* Used by CLI and cross-family tooling for visualization.
|
|
82
|
+
*/
|
|
83
|
+
interface CoreSchemaView {
|
|
84
|
+
readonly root: SchemaTreeNode;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export type { CoreSchemaView, SchemaNodeKind, SchemaTreeNode };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=schema-view.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|