@prisma-next/cli 0.10.0-dev.6 → 0.10.0-dev.8
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/dist/cli.mjs +153 -9
- package/dist/cli.mjs.map +1 -1
- package/dist/{command-helpers-D3vL5yi8.mjs → command-helpers-Dvgul7UA.mjs} +3 -3
- package/dist/command-helpers-Dvgul7UA.mjs.map +1 -0
- package/dist/commands/contract-emit.mjs +1 -1
- package/dist/commands/contract-infer.mjs +1 -1
- package/dist/commands/db-init.mjs +4 -4
- package/dist/commands/db-schema.mjs +4 -4
- package/dist/commands/db-sign.mjs +3 -3
- package/dist/commands/db-update.mjs +4 -4
- package/dist/commands/db-verify.mjs +1 -1
- package/dist/commands/migrate.mjs +3 -3
- package/dist/commands/migration-check.mjs +1 -1
- package/dist/commands/migration-graph.mjs +2 -2
- package/dist/commands/migration-list.mjs +2 -2
- package/dist/commands/migration-log.mjs +2 -2
- package/dist/commands/migration-new.mjs +2 -2
- package/dist/commands/migration-plan.mjs +1 -1
- package/dist/commands/migration-show.mjs +3 -3
- package/dist/commands/migration-status.mjs +3 -3
- package/dist/commands/ref.mjs +2 -2
- package/dist/{contract-emit-C3STUIBg.mjs → contract-emit-BDBzHlaC.mjs} +4 -4
- package/dist/{contract-emit-C3STUIBg.mjs.map → contract-emit-BDBzHlaC.mjs.map} +1 -1
- package/dist/{contract-infer-Cnj8G1E2.mjs → contract-infer-Dm8pBZMR.mjs} +4 -4
- package/dist/{contract-infer-Cnj8G1E2.mjs.map → contract-infer-Dm8pBZMR.mjs.map} +1 -1
- package/dist/{db-verify-D7cyH_zz.mjs → db-verify-CW8DR5Ei.mjs} +4 -4
- package/dist/{db-verify-D7cyH_zz.mjs.map → db-verify-CW8DR5Ei.mjs.map} +1 -1
- package/dist/{errors-Cw6kyTyV.mjs → errors-BYAXmyRJ.mjs} +2 -2
- package/dist/{errors-Cw6kyTyV.mjs.map → errors-BYAXmyRJ.mjs.map} +1 -1
- package/dist/exports/index.mjs +2 -2
- package/dist/global-flags-DGmw6Kqg.d.mts.map +1 -1
- package/dist/{init-BHbEOgNr.mjs → init-CxS9eqbQ.mjs} +57 -3
- package/dist/init-CxS9eqbQ.mjs.map +1 -0
- package/dist/{inspect-live-schema-CWLK_lgs.mjs → inspect-live-schema-iETRZ_59.mjs} +2 -2
- package/dist/{inspect-live-schema-CWLK_lgs.mjs.map → inspect-live-schema-iETRZ_59.mjs.map} +1 -1
- package/dist/is-ci-YyvQBBke.mjs +44 -0
- package/dist/is-ci-YyvQBBke.mjs.map +1 -0
- package/dist/{migration-command-scaffold-CmXXC1UZ.mjs → migration-command-scaffold-BlgVj_Pn.mjs} +2 -2
- package/dist/{migration-command-scaffold-CmXXC1UZ.mjs.map → migration-command-scaffold-BlgVj_Pn.mjs.map} +1 -1
- package/dist/{migration-plan-CHyUlBV0.mjs → migration-plan-BSzcWsvm.mjs} +3 -3
- package/dist/{migration-plan-CHyUlBV0.mjs.map → migration-plan-BSzcWsvm.mjs.map} +1 -1
- package/dist/{migrations-DyUf5lTt.mjs → migrations-CgANWI0w.mjs} +2 -2
- package/dist/{migrations-DyUf5lTt.mjs.map → migrations-CgANWI0w.mjs.map} +1 -1
- package/dist/{result-handler-Bm_6dDYg.mjs → result-handler-CG3vVoKf.mjs} +2 -2
- package/dist/{result-handler-Bm_6dDYg.mjs.map → result-handler-CG3vVoKf.mjs.map} +1 -1
- package/dist/{verify-D7ypCCe6.mjs → verify-nlzO0uIY.mjs} +2 -2
- package/dist/{verify-D7ypCCe6.mjs.map → verify-nlzO0uIY.mjs.map} +1 -1
- package/package.json +19 -17
- package/src/cli.ts +15 -0
- package/src/commands/init/index.ts +10 -2
- package/src/commands/init/init.ts +14 -1
- package/src/commands/init/inputs.ts +75 -0
- package/src/utils/global-flags.ts +6 -2
- package/src/utils/is-ci.ts +18 -0
- package/src/utils/telemetry.ts +166 -0
- package/dist/command-helpers-D3vL5yi8.mjs.map +0 -1
- package/dist/helpers-eqdN8tH6.mjs +0 -25
- package/dist/helpers-eqdN8tH6.mjs.map +0 -1
- package/dist/init-BHbEOgNr.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify-D7ypCCe6.mjs","names":[],"sources":["../src/utils/formatters/verify.ts"],"sourcesContent":["import type {\n CoreSchemaView,\n IntrospectSchemaResult,\n SchemaTreeNode,\n SchemaVerificationNode,\n SignDatabaseResult,\n VerifyDatabaseResult,\n VerifyDatabaseSchemaResult,\n} from '@prisma-next/framework-components/control';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { bold, cyan, dim, green, magenta, red, yellow } from 'colorette';\nimport type { GlobalFlags } from '../global-flags';\nimport { createColorFormatter, formatDim, isVerbose } from './helpers';\n\n// ============================================================================\n// Verify Output Formatters\n// ============================================================================\n\nexport interface DbVerifyCommandSuccessResult {\n readonly ok: true;\n readonly mode: 'full' | 'marker-only';\n readonly summary: string;\n readonly contract: VerifyDatabaseResult['contract'];\n readonly marker?: VerifyDatabaseResult['marker'];\n readonly target: VerifyDatabaseResult['target'];\n readonly missingCodecs?: VerifyDatabaseResult['missingCodecs'];\n readonly codecCoverageSkipped?: VerifyDatabaseResult['codecCoverageSkipped'];\n readonly schema?: {\n readonly summary: string;\n readonly counts: VerifyDatabaseSchemaResult['schema']['counts'];\n readonly strict: boolean;\n };\n readonly warning?: string;\n readonly meta?:\n | (NonNullable<VerifyDatabaseResult['meta']> & {\n readonly schemaVerification: 'performed' | 'skipped';\n })\n | {\n readonly schemaVerification: 'performed' | 'skipped';\n };\n readonly timings: {\n readonly total: number;\n };\n}\n\n/**\n * Formats human-readable output for database verify.\n */\nexport function formatVerifyOutput(\n result: DbVerifyCommandSuccessResult,\n flags: GlobalFlags,\n): string {\n if (flags.quiet) {\n return '';\n }\n\n const lines: string[] = [];\n\n const useColor = flags.color !== false;\n const formatGreen = createColorFormatter(useColor, green);\n const formatYellow = createColorFormatter(useColor, yellow);\n const formatDimText = (text: string) => formatDim(useColor, text);\n const verificationMode =\n result.mode === 'full'\n ? `marker + schema${result.schema?.strict ? ' (strict)' : ' (tolerant)'}`\n : 'marker only (--marker-only)';\n\n lines.push(`${formatGreen('✔')} ${result.summary}`);\n lines.push(`${formatDimText(` verification: ${verificationMode}`)}`);\n lines.push(`${formatDimText(` storageHash: ${result.contract.storageHash}`)}`);\n if (result.contract.profileHash) {\n lines.push(`${formatDimText(` profileHash: ${result.contract.profileHash}`)}`);\n }\n if (result.mode === 'full' && result.schema && isVerbose(flags, 1)) {\n lines.push(\n `${formatDimText(` schema: pass=${result.schema.counts.pass} warn=${result.schema.counts.warn} fail=${result.schema.counts.fail}`)}`,\n );\n }\n if (result.warning) {\n lines.push('');\n lines.push(`${formatYellow('⚠')} ${result.warning}`);\n }\n\n if (isVerbose(flags, 1)) {\n if (result.codecCoverageSkipped) {\n lines.push(\n `${formatDimText(' Codec coverage check skipped (helper returned no supported types)')}`,\n );\n }\n lines.push(`${formatDimText(` Total time: ${result.timings.total}ms`)}`);\n }\n\n return lines.join('\\n');\n}\n\n/**\n * Formats JSON output for database verify.\n */\nexport function formatVerifyJson(result: DbVerifyCommandSuccessResult): string {\n const output = {\n ok: result.ok,\n summary: result.summary,\n mode: result.mode,\n contract: result.contract,\n ...ifDefined('marker', result.marker),\n target: result.target,\n ...ifDefined('missingCodecs', result.missingCodecs),\n ...ifDefined('codecCoverageSkipped', result.codecCoverageSkipped),\n ...ifDefined('schema', result.schema),\n ...ifDefined('warning', result.warning),\n ...ifDefined('meta', result.meta),\n timings: result.timings,\n };\n\n return JSON.stringify(output, null, 2);\n}\n\n/**\n * Formats JSON output for database introspection.\n */\nexport function formatIntrospectJson(result: IntrospectSchemaResult<unknown>): string {\n return JSON.stringify(result, null, 2);\n}\n\n/**\n * Renders a schema tree structure from CoreSchemaView.\n * Matches the style of renderSchemaVerificationTree for consistency.\n */\nfunction renderSchemaTree(\n node: SchemaTreeNode,\n flags: GlobalFlags,\n options: {\n readonly isLast: boolean;\n readonly prefix: string;\n readonly useColor: boolean;\n readonly formatDimText: (text: string) => string;\n readonly isRoot?: boolean;\n },\n): string[] {\n const { isLast, prefix, useColor, formatDimText, isRoot = false } = options;\n const lines: string[] = [];\n\n // Format node label with color based on kind (matching schema-verify style)\n let formattedLabel: string = node.label;\n\n if (useColor) {\n switch (node.kind) {\n case 'root':\n formattedLabel = bold(node.label);\n break;\n case 'entity': {\n // Parse \"table tableName\" format - color \"table\" dim, tableName cyan\n const tableMatch = node.label.match(/^table\\s+(.+)$/);\n if (tableMatch?.[1]) {\n const tableName = tableMatch[1];\n formattedLabel = `${dim('table')} ${cyan(tableName)}`;\n } else {\n // Fallback: color entire label with cyan\n formattedLabel = cyan(node.label);\n }\n break;\n }\n case 'collection': {\n // \"columns\" grouping node - dim the label\n formattedLabel = dim(node.label);\n break;\n }\n case 'field': {\n // Parse column name format: \"columnName: typeDisplay (nullability)\"\n // Color code: column name (cyan), type (default), nullability (dim)\n const columnMatch = node.label.match(/^([^:]+):\\s*(.+)$/);\n if (columnMatch?.[1] && columnMatch[2]) {\n const columnName = columnMatch[1];\n const rest = columnMatch[2];\n // Parse rest: \"typeDisplay (nullability)\"\n const typeMatch = rest.match(/^([^\\s(]+)\\s*(\\([^)]+\\))$/);\n if (typeMatch?.[1] && typeMatch[2]) {\n const typeDisplay = typeMatch[1];\n const nullability = typeMatch[2];\n formattedLabel = `${cyan(columnName)}: ${typeDisplay} ${dim(nullability)}`;\n } else {\n // Fallback if format doesn't match\n formattedLabel = `${cyan(columnName)}: ${rest}`;\n }\n } else {\n formattedLabel = node.label;\n }\n break;\n }\n case 'index': {\n // Parse index/unique constraint/primary key formats\n // \"primary key: columnName\" -> dim \"primary key\", cyan columnName\n const pkMatch = node.label.match(/^primary key:\\s*(.+)$/);\n if (pkMatch?.[1]) {\n const columnNames = pkMatch[1];\n formattedLabel = `${dim('primary key')}: ${cyan(columnNames)}`;\n } else {\n // \"unique name\" -> dim \"unique\", cyan \"name\"\n const uniqueMatch = node.label.match(/^unique\\s+(.+)$/);\n if (uniqueMatch?.[1]) {\n const name = uniqueMatch[1];\n formattedLabel = `${dim('unique')} ${cyan(name)}`;\n } else {\n // \"index name\" or \"unique index name\" -> dim label prefix, cyan name\n const indexMatch = node.label.match(/^(unique\\s+)?index\\s+(.+)$/);\n if (indexMatch?.[2]) {\n const indexPrefix = indexMatch[1] ? `${dim('unique')} ` : '';\n const name = indexMatch[2];\n formattedLabel = `${indexPrefix}${dim('index')} ${cyan(name)}`;\n } else {\n formattedLabel = dim(node.label);\n }\n }\n }\n break;\n }\n case 'dependency': {\n // Parse extension message formats similar to schema-verify\n // \"extensionName extension is enabled\" -> cyan extensionName, dim rest\n const extMatch = node.label.match(/^([^\\s]+)\\s+(extension is enabled)$/);\n if (extMatch?.[1] && extMatch[2]) {\n const extName = extMatch[1];\n const rest = extMatch[2];\n formattedLabel = `${cyan(extName)} ${dim(rest)}`;\n } else {\n // Fallback: color entire label with magenta\n formattedLabel = magenta(node.label);\n }\n break;\n }\n default:\n formattedLabel = node.label;\n break;\n }\n }\n\n // Root node renders without tree characters or prefix\n if (isRoot) {\n lines.push(formattedLabel);\n } else {\n const treeChar = isLast ? '└' : '├';\n const treePrefix = `${formatDimText(treeChar)}─ `;\n lines.push(`${prefix}${treePrefix}${formattedLabel}`);\n }\n\n // Render children if present\n if (node.children && node.children.length > 0) {\n const childPrefix = isRoot ? '' : `${prefix}${isLast ? ' ' : `${formatDimText('│')} `}`;\n for (let i = 0; i < node.children.length; i++) {\n const child = node.children[i];\n if (!child) continue;\n const isLastChild = i === node.children.length - 1;\n const childLines = renderSchemaTree(child, flags, {\n isLast: isLastChild,\n prefix: childPrefix,\n useColor,\n formatDimText,\n isRoot: false,\n });\n lines.push(...childLines);\n }\n }\n\n return lines;\n}\n\n/**\n * Formats human-readable output for database introspection.\n */\nexport function formatIntrospectOutput(\n result: IntrospectSchemaResult<unknown>,\n schemaView: CoreSchemaView | undefined,\n flags: GlobalFlags,\n): string {\n if (flags.quiet) {\n return '';\n }\n\n const lines: string[] = [];\n\n const useColor = flags.color !== false;\n const formatDimText = (text: string) => formatDim(useColor, text);\n\n if (schemaView) {\n // Render tree structure - root node is special (no tree characters)\n const treeLines = renderSchemaTree(schemaView.root, flags, {\n isLast: true,\n prefix: '',\n useColor,\n formatDimText,\n isRoot: true,\n });\n lines.push(...treeLines);\n } else {\n // Fallback: print summary when toSchemaView is not available\n lines.push(`✔ ${result.summary}`);\n if (isVerbose(flags, 1)) {\n lines.push(` Target: ${result.target.familyId}/${result.target.id}`);\n if (result.meta?.dbUrl) {\n lines.push(` Database: ${result.meta.dbUrl}`);\n }\n }\n }\n\n // Add timings in verbose mode\n if (isVerbose(flags, 1)) {\n lines.push(`${formatDimText(` Total time: ${result.timings.total}ms`)}`);\n }\n\n return lines.join('\\n');\n}\n\n/**\n * Renders a schema verification tree structure from SchemaVerificationNode.\n * Similar to renderSchemaTree but for verification nodes with status-based colors and glyphs.\n */\nfunction renderSchemaVerificationTree(\n node: SchemaVerificationNode,\n flags: GlobalFlags,\n options: {\n readonly isLast: boolean;\n readonly prefix: string;\n readonly useColor: boolean;\n readonly formatDimText: (text: string) => string;\n readonly isRoot?: boolean;\n },\n): string[] {\n const { isLast, prefix, useColor, formatDimText, isRoot = false } = options;\n const lines: string[] = [];\n\n // Format status glyph and color based on status\n let statusGlyph = '';\n let statusColor: (text: string) => string = (text) => text;\n if (useColor) {\n switch (node.status) {\n case 'pass':\n statusGlyph = '✔';\n statusColor = green;\n break;\n case 'warn':\n statusGlyph = '⚠';\n statusColor = (text) => (useColor ? yellow(text) : text);\n break;\n case 'fail':\n statusGlyph = '✖';\n statusColor = red;\n break;\n }\n } else {\n switch (node.status) {\n case 'pass':\n statusGlyph = '✔';\n break;\n case 'warn':\n statusGlyph = '⚠';\n break;\n case 'fail':\n statusGlyph = '✖';\n break;\n }\n }\n\n // Format node label with color based on kind\n // For column nodes, we need to parse the name to color code different parts\n let labelColor: (text: string) => string = (text) => text;\n let formattedLabel: string = node.name;\n\n if (useColor) {\n switch (node.kind) {\n case 'contract':\n case 'schema':\n labelColor = bold;\n formattedLabel = labelColor(node.name);\n break;\n case 'table': {\n // Parse \"table tableName\" format - color \"table\" dim, tableName cyan\n const tableMatch = node.name.match(/^table\\s+(.+)$/);\n if (tableMatch?.[1]) {\n const tableName = tableMatch[1];\n formattedLabel = `${dim('table')} ${cyan(tableName)}`;\n } else {\n formattedLabel = dim(node.name);\n }\n break;\n }\n case 'columns':\n labelColor = dim;\n formattedLabel = labelColor(node.name);\n break;\n case 'column': {\n // Parse column name format: \"columnName: contractType -> nativeType (nullability)\"\n // Color code: column name (cyan), contract type (default), native type (dim), nullability (dim)\n const columnMatch = node.name.match(/^([^:]+):\\s*(.+)$/);\n if (columnMatch?.[1] && columnMatch[2]) {\n const columnName = columnMatch[1];\n const rest = columnMatch[2];\n // Parse rest: \"contractType -> nativeType (nullability)\"\n // Match contract type (can contain /, @, etc.), arrow, native type, then nullability in parentheses\n const typeMatch = rest.match(/^([^\\s→]+)\\s*→\\s*([^\\s(]+)\\s*(\\([^)]+\\))$/);\n if (typeMatch?.[1] && typeMatch[2] && typeMatch[3]) {\n const contractType = typeMatch[1];\n const nativeType = typeMatch[2];\n const nullability = typeMatch[3];\n formattedLabel = `${cyan(columnName)}: ${contractType} → ${dim(nativeType)} ${dim(nullability)}`;\n } else {\n // Fallback if format doesn't match (e.g., no native type or no nullability)\n formattedLabel = `${cyan(columnName)}: ${rest}`;\n }\n } else {\n formattedLabel = node.name;\n }\n break;\n }\n case 'type':\n case 'nullability':\n labelColor = (text) => text; // Default color\n formattedLabel = labelColor(node.name);\n break;\n case 'primaryKey': {\n // Parse \"primary key: columnName\" format - color \"primary key\" dim, columnName cyan\n const pkMatch = node.name.match(/^primary key:\\s*(.+)$/);\n if (pkMatch?.[1]) {\n const columnNames = pkMatch[1];\n formattedLabel = `${dim('primary key')}: ${cyan(columnNames)}`;\n } else {\n formattedLabel = dim(node.name);\n }\n break;\n }\n case 'foreignKey':\n case 'unique':\n case 'index':\n labelColor = dim;\n formattedLabel = labelColor(node.name);\n break;\n case 'dependency': {\n // Parse specific extension message formats\n // \"database is postgres\" -> dim \"database is\", cyan \"postgres\"\n const dbMatch = node.name.match(/^database is\\s+(.+)$/);\n if (dbMatch?.[1]) {\n const dbName = dbMatch[1];\n formattedLabel = `${dim('database is')} ${cyan(dbName)}`;\n } else {\n // \"vector extension is enabled\" -> dim everything except extension name\n // Match pattern: \"extensionName extension is enabled\"\n const extMatch = node.name.match(/^([^\\s]+)\\s+(extension is enabled)$/);\n if (extMatch?.[1] && extMatch[2]) {\n const extName = extMatch[1];\n const rest = extMatch[2];\n formattedLabel = `${cyan(extName)} ${dim(rest)}`;\n } else {\n // Fallback: color entire name with magenta\n labelColor = magenta;\n formattedLabel = labelColor(node.name);\n }\n }\n break;\n }\n default:\n formattedLabel = node.name;\n break;\n }\n } else {\n formattedLabel = node.name;\n }\n\n const statusGlyphColored = statusColor(statusGlyph);\n\n // Build the label with optional message for failure/warn nodes\n let nodeLabel = formattedLabel;\n if (\n (node.status === 'fail' || node.status === 'warn') &&\n node.message &&\n node.message.length > 0\n ) {\n // Always show message for failure/warn nodes - it provides crucial context\n // For parent nodes, the message summarizes child failures\n // For leaf nodes, the message explains the specific issue\n const messageText = formatDimText(`(${node.message})`);\n nodeLabel = `${formattedLabel} ${messageText}`;\n }\n\n // Root node renders without tree characters or | prefix\n // Root node renders without tree characters or prefix\n if (isRoot) {\n lines.push(`${statusGlyphColored} ${nodeLabel}`);\n } else {\n const treeChar = isLast ? '└' : '├';\n const treePrefix = `${formatDimText(treeChar)}─ `;\n lines.push(`${prefix}${treePrefix}${statusGlyphColored} ${nodeLabel}`);\n }\n\n // Render children if present\n if (node.children && node.children.length > 0) {\n const childPrefix = isRoot ? '' : `${prefix}${isLast ? ' ' : `${formatDimText('│')} `}`;\n for (let i = 0; i < node.children.length; i++) {\n const child = node.children[i];\n if (!child) continue;\n const isLastChild = i === node.children.length - 1;\n const childLines = renderSchemaVerificationTree(child, flags, {\n isLast: isLastChild,\n prefix: childPrefix,\n useColor,\n formatDimText,\n isRoot: false,\n });\n lines.push(...childLines);\n }\n }\n\n return lines;\n}\n\n/**\n * Formats human-readable output for database schema verification.\n */\nexport function formatSchemaVerifyOutput(\n result: VerifyDatabaseSchemaResult,\n flags: GlobalFlags,\n): string {\n if (flags.quiet) {\n return '';\n }\n\n const lines: string[] = [];\n\n const useColor = flags.color !== false;\n const formatGreen = createColorFormatter(useColor, green);\n const formatRed = createColorFormatter(useColor, red);\n const formatDimText = (text: string) => formatDim(useColor, text);\n\n // Render verification tree first\n const treeLines = renderSchemaVerificationTree(result.schema.root, flags, {\n isLast: true,\n prefix: '',\n useColor,\n formatDimText,\n isRoot: true,\n });\n lines.push(...treeLines);\n\n // Add counts and timings in verbose mode\n if (isVerbose(flags, 1)) {\n lines.push(`${formatDimText(` Total time: ${result.timings.total}ms`)}`);\n lines.push(\n `${formatDimText(` pass=${result.schema.counts.pass} warn=${result.schema.counts.warn} fail=${result.schema.counts.fail}`)}`,\n );\n }\n\n // Blank line before summary\n lines.push('');\n\n // Summary line at the end: summary with status glyph\n if (result.ok) {\n lines.push(`${formatGreen('✔')} ${result.summary}`);\n } else {\n const codeText = result.code ? ` (${result.code})` : '';\n lines.push(`${formatRed('✖')} ${result.summary}${codeText}`);\n }\n\n return lines.join('\\n');\n}\n\n/**\n * Formats JSON output for database schema verification.\n */\nexport function formatSchemaVerifyJson(result: VerifyDatabaseSchemaResult): string {\n return JSON.stringify(result, null, 2);\n}\n\n// ============================================================================\n// Sign Output Formatters\n// ============================================================================\n\n/**\n * Formats human-readable output for database sign.\n */\nexport function formatSignOutput(result: SignDatabaseResult, flags: GlobalFlags): string {\n if (flags.quiet) {\n return '';\n }\n\n const lines: string[] = [];\n\n const useColor = flags.color !== false;\n const formatGreen = createColorFormatter(useColor, green);\n const formatDimText = (text: string) => formatDim(useColor, text);\n\n if (result.ok) {\n // Main success message in white (not dimmed)\n lines.push(`${formatGreen('✔')} Database signed`);\n\n // Show from -> to hashes with clear labels\n const previousHash = result.marker.previous?.storageHash ?? 'none';\n const currentHash = result.contract.storageHash;\n\n lines.push(`${formatDimText(` from: ${previousHash}`)}`);\n lines.push(`${formatDimText(` to: ${currentHash}`)}`);\n\n if (isVerbose(flags, 1)) {\n if (result.contract.profileHash) {\n lines.push(`${formatDimText(` profileHash: ${result.contract.profileHash}`)}`);\n }\n if (result.marker.previous?.profileHash) {\n lines.push(\n `${formatDimText(` previous profileHash: ${result.marker.previous.profileHash}`)}`,\n );\n }\n lines.push(`${formatDimText(` Total time: ${result.timings.total}ms`)}`);\n }\n }\n\n return lines.join('\\n');\n}\n\n/**\n * Formats JSON output for database sign.\n */\nexport function formatSignJson(result: SignDatabaseResult): string {\n return JSON.stringify(result, null, 2);\n}\n"],"mappings":";;;;;;;AAgDA,SAAgB,mBACd,QACA,OACQ;CACR,IAAI,MAAM,OACR,OAAO;CAGT,MAAM,QAAkB,EAAE;CAE1B,MAAM,WAAW,MAAM,UAAU;CACjC,MAAM,cAAc,qBAAqB,UAAU,MAAM;CACzD,MAAM,eAAe,qBAAqB,UAAU,OAAO;CAC3D,MAAM,iBAAiB,SAAiB,UAAU,UAAU,KAAK;CACjE,MAAM,mBACJ,OAAO,SAAS,SACZ,kBAAkB,OAAO,QAAQ,SAAS,cAAc,kBACxD;CAEN,MAAM,KAAK,GAAG,YAAY,IAAI,CAAC,GAAG,OAAO,UAAU;CACnD,MAAM,KAAK,GAAG,cAAc,mBAAmB,mBAAmB,GAAG;CACrE,MAAM,KAAK,GAAG,cAAc,kBAAkB,OAAO,SAAS,cAAc,GAAG;CAC/E,IAAI,OAAO,SAAS,aAClB,MAAM,KAAK,GAAG,cAAc,kBAAkB,OAAO,SAAS,cAAc,GAAG;CAEjF,IAAI,OAAO,SAAS,UAAU,OAAO,UAAU,UAAU,OAAO,EAAE,EAChE,MAAM,KACJ,GAAG,cAAc,kBAAkB,OAAO,OAAO,OAAO,KAA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I,GAAG;;;CAI7E,OAAO,MAAM,KAAK,KAAK;;;;;AAMzB,SAAgB,eAAe,QAAoC;CACjE,OAAO,KAAK,UAAU,QAAQ,MAAM,EAAE"}
|
|
1
|
+
{"version":3,"file":"verify-nlzO0uIY.mjs","names":[],"sources":["../src/utils/formatters/verify.ts"],"sourcesContent":["import type {\n CoreSchemaView,\n IntrospectSchemaResult,\n SchemaTreeNode,\n SchemaVerificationNode,\n SignDatabaseResult,\n VerifyDatabaseResult,\n VerifyDatabaseSchemaResult,\n} from '@prisma-next/framework-components/control';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { bold, cyan, dim, green, magenta, red, yellow } from 'colorette';\nimport type { GlobalFlags } from '../global-flags';\nimport { createColorFormatter, formatDim, isVerbose } from './helpers';\n\n// ============================================================================\n// Verify Output Formatters\n// ============================================================================\n\nexport interface DbVerifyCommandSuccessResult {\n readonly ok: true;\n readonly mode: 'full' | 'marker-only';\n readonly summary: string;\n readonly contract: VerifyDatabaseResult['contract'];\n readonly marker?: VerifyDatabaseResult['marker'];\n readonly target: VerifyDatabaseResult['target'];\n readonly missingCodecs?: VerifyDatabaseResult['missingCodecs'];\n readonly codecCoverageSkipped?: VerifyDatabaseResult['codecCoverageSkipped'];\n readonly schema?: {\n readonly summary: string;\n readonly counts: VerifyDatabaseSchemaResult['schema']['counts'];\n readonly strict: boolean;\n };\n readonly warning?: string;\n readonly meta?:\n | (NonNullable<VerifyDatabaseResult['meta']> & {\n readonly schemaVerification: 'performed' | 'skipped';\n })\n | {\n readonly schemaVerification: 'performed' | 'skipped';\n };\n readonly timings: {\n readonly total: number;\n };\n}\n\n/**\n * Formats human-readable output for database verify.\n */\nexport function formatVerifyOutput(\n result: DbVerifyCommandSuccessResult,\n flags: GlobalFlags,\n): string {\n if (flags.quiet) {\n return '';\n }\n\n const lines: string[] = [];\n\n const useColor = flags.color !== false;\n const formatGreen = createColorFormatter(useColor, green);\n const formatYellow = createColorFormatter(useColor, yellow);\n const formatDimText = (text: string) => formatDim(useColor, text);\n const verificationMode =\n result.mode === 'full'\n ? `marker + schema${result.schema?.strict ? ' (strict)' : ' (tolerant)'}`\n : 'marker only (--marker-only)';\n\n lines.push(`${formatGreen('✔')} ${result.summary}`);\n lines.push(`${formatDimText(` verification: ${verificationMode}`)}`);\n lines.push(`${formatDimText(` storageHash: ${result.contract.storageHash}`)}`);\n if (result.contract.profileHash) {\n lines.push(`${formatDimText(` profileHash: ${result.contract.profileHash}`)}`);\n }\n if (result.mode === 'full' && result.schema && isVerbose(flags, 1)) {\n lines.push(\n `${formatDimText(` schema: pass=${result.schema.counts.pass} warn=${result.schema.counts.warn} fail=${result.schema.counts.fail}`)}`,\n );\n }\n if (result.warning) {\n lines.push('');\n lines.push(`${formatYellow('⚠')} ${result.warning}`);\n }\n\n if (isVerbose(flags, 1)) {\n if (result.codecCoverageSkipped) {\n lines.push(\n `${formatDimText(' Codec coverage check skipped (helper returned no supported types)')}`,\n );\n }\n lines.push(`${formatDimText(` Total time: ${result.timings.total}ms`)}`);\n }\n\n return lines.join('\\n');\n}\n\n/**\n * Formats JSON output for database verify.\n */\nexport function formatVerifyJson(result: DbVerifyCommandSuccessResult): string {\n const output = {\n ok: result.ok,\n summary: result.summary,\n mode: result.mode,\n contract: result.contract,\n ...ifDefined('marker', result.marker),\n target: result.target,\n ...ifDefined('missingCodecs', result.missingCodecs),\n ...ifDefined('codecCoverageSkipped', result.codecCoverageSkipped),\n ...ifDefined('schema', result.schema),\n ...ifDefined('warning', result.warning),\n ...ifDefined('meta', result.meta),\n timings: result.timings,\n };\n\n return JSON.stringify(output, null, 2);\n}\n\n/**\n * Formats JSON output for database introspection.\n */\nexport function formatIntrospectJson(result: IntrospectSchemaResult<unknown>): string {\n return JSON.stringify(result, null, 2);\n}\n\n/**\n * Renders a schema tree structure from CoreSchemaView.\n * Matches the style of renderSchemaVerificationTree for consistency.\n */\nfunction renderSchemaTree(\n node: SchemaTreeNode,\n flags: GlobalFlags,\n options: {\n readonly isLast: boolean;\n readonly prefix: string;\n readonly useColor: boolean;\n readonly formatDimText: (text: string) => string;\n readonly isRoot?: boolean;\n },\n): string[] {\n const { isLast, prefix, useColor, formatDimText, isRoot = false } = options;\n const lines: string[] = [];\n\n // Format node label with color based on kind (matching schema-verify style)\n let formattedLabel: string = node.label;\n\n if (useColor) {\n switch (node.kind) {\n case 'root':\n formattedLabel = bold(node.label);\n break;\n case 'entity': {\n // Parse \"table tableName\" format - color \"table\" dim, tableName cyan\n const tableMatch = node.label.match(/^table\\s+(.+)$/);\n if (tableMatch?.[1]) {\n const tableName = tableMatch[1];\n formattedLabel = `${dim('table')} ${cyan(tableName)}`;\n } else {\n // Fallback: color entire label with cyan\n formattedLabel = cyan(node.label);\n }\n break;\n }\n case 'collection': {\n // \"columns\" grouping node - dim the label\n formattedLabel = dim(node.label);\n break;\n }\n case 'field': {\n // Parse column name format: \"columnName: typeDisplay (nullability)\"\n // Color code: column name (cyan), type (default), nullability (dim)\n const columnMatch = node.label.match(/^([^:]+):\\s*(.+)$/);\n if (columnMatch?.[1] && columnMatch[2]) {\n const columnName = columnMatch[1];\n const rest = columnMatch[2];\n // Parse rest: \"typeDisplay (nullability)\"\n const typeMatch = rest.match(/^([^\\s(]+)\\s*(\\([^)]+\\))$/);\n if (typeMatch?.[1] && typeMatch[2]) {\n const typeDisplay = typeMatch[1];\n const nullability = typeMatch[2];\n formattedLabel = `${cyan(columnName)}: ${typeDisplay} ${dim(nullability)}`;\n } else {\n // Fallback if format doesn't match\n formattedLabel = `${cyan(columnName)}: ${rest}`;\n }\n } else {\n formattedLabel = node.label;\n }\n break;\n }\n case 'index': {\n // Parse index/unique constraint/primary key formats\n // \"primary key: columnName\" -> dim \"primary key\", cyan columnName\n const pkMatch = node.label.match(/^primary key:\\s*(.+)$/);\n if (pkMatch?.[1]) {\n const columnNames = pkMatch[1];\n formattedLabel = `${dim('primary key')}: ${cyan(columnNames)}`;\n } else {\n // \"unique name\" -> dim \"unique\", cyan \"name\"\n const uniqueMatch = node.label.match(/^unique\\s+(.+)$/);\n if (uniqueMatch?.[1]) {\n const name = uniqueMatch[1];\n formattedLabel = `${dim('unique')} ${cyan(name)}`;\n } else {\n // \"index name\" or \"unique index name\" -> dim label prefix, cyan name\n const indexMatch = node.label.match(/^(unique\\s+)?index\\s+(.+)$/);\n if (indexMatch?.[2]) {\n const indexPrefix = indexMatch[1] ? `${dim('unique')} ` : '';\n const name = indexMatch[2];\n formattedLabel = `${indexPrefix}${dim('index')} ${cyan(name)}`;\n } else {\n formattedLabel = dim(node.label);\n }\n }\n }\n break;\n }\n case 'dependency': {\n // Parse extension message formats similar to schema-verify\n // \"extensionName extension is enabled\" -> cyan extensionName, dim rest\n const extMatch = node.label.match(/^([^\\s]+)\\s+(extension is enabled)$/);\n if (extMatch?.[1] && extMatch[2]) {\n const extName = extMatch[1];\n const rest = extMatch[2];\n formattedLabel = `${cyan(extName)} ${dim(rest)}`;\n } else {\n // Fallback: color entire label with magenta\n formattedLabel = magenta(node.label);\n }\n break;\n }\n default:\n formattedLabel = node.label;\n break;\n }\n }\n\n // Root node renders without tree characters or prefix\n if (isRoot) {\n lines.push(formattedLabel);\n } else {\n const treeChar = isLast ? '└' : '├';\n const treePrefix = `${formatDimText(treeChar)}─ `;\n lines.push(`${prefix}${treePrefix}${formattedLabel}`);\n }\n\n // Render children if present\n if (node.children && node.children.length > 0) {\n const childPrefix = isRoot ? '' : `${prefix}${isLast ? ' ' : `${formatDimText('│')} `}`;\n for (let i = 0; i < node.children.length; i++) {\n const child = node.children[i];\n if (!child) continue;\n const isLastChild = i === node.children.length - 1;\n const childLines = renderSchemaTree(child, flags, {\n isLast: isLastChild,\n prefix: childPrefix,\n useColor,\n formatDimText,\n isRoot: false,\n });\n lines.push(...childLines);\n }\n }\n\n return lines;\n}\n\n/**\n * Formats human-readable output for database introspection.\n */\nexport function formatIntrospectOutput(\n result: IntrospectSchemaResult<unknown>,\n schemaView: CoreSchemaView | undefined,\n flags: GlobalFlags,\n): string {\n if (flags.quiet) {\n return '';\n }\n\n const lines: string[] = [];\n\n const useColor = flags.color !== false;\n const formatDimText = (text: string) => formatDim(useColor, text);\n\n if (schemaView) {\n // Render tree structure - root node is special (no tree characters)\n const treeLines = renderSchemaTree(schemaView.root, flags, {\n isLast: true,\n prefix: '',\n useColor,\n formatDimText,\n isRoot: true,\n });\n lines.push(...treeLines);\n } else {\n // Fallback: print summary when toSchemaView is not available\n lines.push(`✔ ${result.summary}`);\n if (isVerbose(flags, 1)) {\n lines.push(` Target: ${result.target.familyId}/${result.target.id}`);\n if (result.meta?.dbUrl) {\n lines.push(` Database: ${result.meta.dbUrl}`);\n }\n }\n }\n\n // Add timings in verbose mode\n if (isVerbose(flags, 1)) {\n lines.push(`${formatDimText(` Total time: ${result.timings.total}ms`)}`);\n }\n\n return lines.join('\\n');\n}\n\n/**\n * Renders a schema verification tree structure from SchemaVerificationNode.\n * Similar to renderSchemaTree but for verification nodes with status-based colors and glyphs.\n */\nfunction renderSchemaVerificationTree(\n node: SchemaVerificationNode,\n flags: GlobalFlags,\n options: {\n readonly isLast: boolean;\n readonly prefix: string;\n readonly useColor: boolean;\n readonly formatDimText: (text: string) => string;\n readonly isRoot?: boolean;\n },\n): string[] {\n const { isLast, prefix, useColor, formatDimText, isRoot = false } = options;\n const lines: string[] = [];\n\n // Format status glyph and color based on status\n let statusGlyph = '';\n let statusColor: (text: string) => string = (text) => text;\n if (useColor) {\n switch (node.status) {\n case 'pass':\n statusGlyph = '✔';\n statusColor = green;\n break;\n case 'warn':\n statusGlyph = '⚠';\n statusColor = (text) => (useColor ? yellow(text) : text);\n break;\n case 'fail':\n statusGlyph = '✖';\n statusColor = red;\n break;\n }\n } else {\n switch (node.status) {\n case 'pass':\n statusGlyph = '✔';\n break;\n case 'warn':\n statusGlyph = '⚠';\n break;\n case 'fail':\n statusGlyph = '✖';\n break;\n }\n }\n\n // Format node label with color based on kind\n // For column nodes, we need to parse the name to color code different parts\n let labelColor: (text: string) => string = (text) => text;\n let formattedLabel: string = node.name;\n\n if (useColor) {\n switch (node.kind) {\n case 'contract':\n case 'schema':\n labelColor = bold;\n formattedLabel = labelColor(node.name);\n break;\n case 'table': {\n // Parse \"table tableName\" format - color \"table\" dim, tableName cyan\n const tableMatch = node.name.match(/^table\\s+(.+)$/);\n if (tableMatch?.[1]) {\n const tableName = tableMatch[1];\n formattedLabel = `${dim('table')} ${cyan(tableName)}`;\n } else {\n formattedLabel = dim(node.name);\n }\n break;\n }\n case 'columns':\n labelColor = dim;\n formattedLabel = labelColor(node.name);\n break;\n case 'column': {\n // Parse column name format: \"columnName: contractType -> nativeType (nullability)\"\n // Color code: column name (cyan), contract type (default), native type (dim), nullability (dim)\n const columnMatch = node.name.match(/^([^:]+):\\s*(.+)$/);\n if (columnMatch?.[1] && columnMatch[2]) {\n const columnName = columnMatch[1];\n const rest = columnMatch[2];\n // Parse rest: \"contractType -> nativeType (nullability)\"\n // Match contract type (can contain /, @, etc.), arrow, native type, then nullability in parentheses\n const typeMatch = rest.match(/^([^\\s→]+)\\s*→\\s*([^\\s(]+)\\s*(\\([^)]+\\))$/);\n if (typeMatch?.[1] && typeMatch[2] && typeMatch[3]) {\n const contractType = typeMatch[1];\n const nativeType = typeMatch[2];\n const nullability = typeMatch[3];\n formattedLabel = `${cyan(columnName)}: ${contractType} → ${dim(nativeType)} ${dim(nullability)}`;\n } else {\n // Fallback if format doesn't match (e.g., no native type or no nullability)\n formattedLabel = `${cyan(columnName)}: ${rest}`;\n }\n } else {\n formattedLabel = node.name;\n }\n break;\n }\n case 'type':\n case 'nullability':\n labelColor = (text) => text; // Default color\n formattedLabel = labelColor(node.name);\n break;\n case 'primaryKey': {\n // Parse \"primary key: columnName\" format - color \"primary key\" dim, columnName cyan\n const pkMatch = node.name.match(/^primary key:\\s*(.+)$/);\n if (pkMatch?.[1]) {\n const columnNames = pkMatch[1];\n formattedLabel = `${dim('primary key')}: ${cyan(columnNames)}`;\n } else {\n formattedLabel = dim(node.name);\n }\n break;\n }\n case 'foreignKey':\n case 'unique':\n case 'index':\n labelColor = dim;\n formattedLabel = labelColor(node.name);\n break;\n case 'dependency': {\n // Parse specific extension message formats\n // \"database is postgres\" -> dim \"database is\", cyan \"postgres\"\n const dbMatch = node.name.match(/^database is\\s+(.+)$/);\n if (dbMatch?.[1]) {\n const dbName = dbMatch[1];\n formattedLabel = `${dim('database is')} ${cyan(dbName)}`;\n } else {\n // \"vector extension is enabled\" -> dim everything except extension name\n // Match pattern: \"extensionName extension is enabled\"\n const extMatch = node.name.match(/^([^\\s]+)\\s+(extension is enabled)$/);\n if (extMatch?.[1] && extMatch[2]) {\n const extName = extMatch[1];\n const rest = extMatch[2];\n formattedLabel = `${cyan(extName)} ${dim(rest)}`;\n } else {\n // Fallback: color entire name with magenta\n labelColor = magenta;\n formattedLabel = labelColor(node.name);\n }\n }\n break;\n }\n default:\n formattedLabel = node.name;\n break;\n }\n } else {\n formattedLabel = node.name;\n }\n\n const statusGlyphColored = statusColor(statusGlyph);\n\n // Build the label with optional message for failure/warn nodes\n let nodeLabel = formattedLabel;\n if (\n (node.status === 'fail' || node.status === 'warn') &&\n node.message &&\n node.message.length > 0\n ) {\n // Always show message for failure/warn nodes - it provides crucial context\n // For parent nodes, the message summarizes child failures\n // For leaf nodes, the message explains the specific issue\n const messageText = formatDimText(`(${node.message})`);\n nodeLabel = `${formattedLabel} ${messageText}`;\n }\n\n // Root node renders without tree characters or | prefix\n // Root node renders without tree characters or prefix\n if (isRoot) {\n lines.push(`${statusGlyphColored} ${nodeLabel}`);\n } else {\n const treeChar = isLast ? '└' : '├';\n const treePrefix = `${formatDimText(treeChar)}─ `;\n lines.push(`${prefix}${treePrefix}${statusGlyphColored} ${nodeLabel}`);\n }\n\n // Render children if present\n if (node.children && node.children.length > 0) {\n const childPrefix = isRoot ? '' : `${prefix}${isLast ? ' ' : `${formatDimText('│')} `}`;\n for (let i = 0; i < node.children.length; i++) {\n const child = node.children[i];\n if (!child) continue;\n const isLastChild = i === node.children.length - 1;\n const childLines = renderSchemaVerificationTree(child, flags, {\n isLast: isLastChild,\n prefix: childPrefix,\n useColor,\n formatDimText,\n isRoot: false,\n });\n lines.push(...childLines);\n }\n }\n\n return lines;\n}\n\n/**\n * Formats human-readable output for database schema verification.\n */\nexport function formatSchemaVerifyOutput(\n result: VerifyDatabaseSchemaResult,\n flags: GlobalFlags,\n): string {\n if (flags.quiet) {\n return '';\n }\n\n const lines: string[] = [];\n\n const useColor = flags.color !== false;\n const formatGreen = createColorFormatter(useColor, green);\n const formatRed = createColorFormatter(useColor, red);\n const formatDimText = (text: string) => formatDim(useColor, text);\n\n // Render verification tree first\n const treeLines = renderSchemaVerificationTree(result.schema.root, flags, {\n isLast: true,\n prefix: '',\n useColor,\n formatDimText,\n isRoot: true,\n });\n lines.push(...treeLines);\n\n // Add counts and timings in verbose mode\n if (isVerbose(flags, 1)) {\n lines.push(`${formatDimText(` Total time: ${result.timings.total}ms`)}`);\n lines.push(\n `${formatDimText(` pass=${result.schema.counts.pass} warn=${result.schema.counts.warn} fail=${result.schema.counts.fail}`)}`,\n );\n }\n\n // Blank line before summary\n lines.push('');\n\n // Summary line at the end: summary with status glyph\n if (result.ok) {\n lines.push(`${formatGreen('✔')} ${result.summary}`);\n } else {\n const codeText = result.code ? ` (${result.code})` : '';\n lines.push(`${formatRed('✖')} ${result.summary}${codeText}`);\n }\n\n return lines.join('\\n');\n}\n\n/**\n * Formats JSON output for database schema verification.\n */\nexport function formatSchemaVerifyJson(result: VerifyDatabaseSchemaResult): string {\n return JSON.stringify(result, null, 2);\n}\n\n// ============================================================================\n// Sign Output Formatters\n// ============================================================================\n\n/**\n * Formats human-readable output for database sign.\n */\nexport function formatSignOutput(result: SignDatabaseResult, flags: GlobalFlags): string {\n if (flags.quiet) {\n return '';\n }\n\n const lines: string[] = [];\n\n const useColor = flags.color !== false;\n const formatGreen = createColorFormatter(useColor, green);\n const formatDimText = (text: string) => formatDim(useColor, text);\n\n if (result.ok) {\n // Main success message in white (not dimmed)\n lines.push(`${formatGreen('✔')} Database signed`);\n\n // Show from -> to hashes with clear labels\n const previousHash = result.marker.previous?.storageHash ?? 'none';\n const currentHash = result.contract.storageHash;\n\n lines.push(`${formatDimText(` from: ${previousHash}`)}`);\n lines.push(`${formatDimText(` to: ${currentHash}`)}`);\n\n if (isVerbose(flags, 1)) {\n if (result.contract.profileHash) {\n lines.push(`${formatDimText(` profileHash: ${result.contract.profileHash}`)}`);\n }\n if (result.marker.previous?.profileHash) {\n lines.push(\n `${formatDimText(` previous profileHash: ${result.marker.previous.profileHash}`)}`,\n );\n }\n lines.push(`${formatDimText(` Total time: ${result.timings.total}ms`)}`);\n }\n }\n\n return lines.join('\\n');\n}\n\n/**\n * Formats JSON output for database sign.\n */\nexport function formatSignJson(result: SignDatabaseResult): string {\n return JSON.stringify(result, null, 2);\n}\n"],"mappings":";;;;;;;AAgDA,SAAgB,mBACd,QACA,OACQ;CACR,IAAI,MAAM,OACR,OAAO;CAGT,MAAM,QAAkB,EAAE;CAE1B,MAAM,WAAW,MAAM,UAAU;CACjC,MAAM,cAAc,qBAAqB,UAAU,MAAM;CACzD,MAAM,eAAe,qBAAqB,UAAU,OAAO;CAC3D,MAAM,iBAAiB,SAAiB,UAAU,UAAU,KAAK;CACjE,MAAM,mBACJ,OAAO,SAAS,SACZ,kBAAkB,OAAO,QAAQ,SAAS,cAAc,kBACxD;CAEN,MAAM,KAAK,GAAG,YAAY,IAAI,CAAC,GAAG,OAAO,UAAU;CACnD,MAAM,KAAK,GAAG,cAAc,mBAAmB,mBAAmB,GAAG;CACrE,MAAM,KAAK,GAAG,cAAc,kBAAkB,OAAO,SAAS,cAAc,GAAG;CAC/E,IAAI,OAAO,SAAS,aAClB,MAAM,KAAK,GAAG,cAAc,kBAAkB,OAAO,SAAS,cAAc,GAAG;CAEjF,IAAI,OAAO,SAAS,UAAU,OAAO,UAAU,UAAU,OAAO,EAAE,EAChE,MAAM,KACJ,GAAG,cAAc,kBAAkB,OAAO,OAAO,OAA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M,IAAI,GAAG;;;CAI7E,OAAO,MAAM,KAAK,KAAK;;;;;AAMzB,SAAgB,eAAe,QAAoC;CACjE,OAAO,KAAK,UAAU,QAAQ,MAAM,EAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/cli",
|
|
3
|
-
"version": "0.10.0-dev.
|
|
3
|
+
"version": "0.10.0-dev.8",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -14,16 +14,18 @@
|
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@clack/prompts": "^1.3.0",
|
|
16
16
|
"@dagrejs/dagre": "^3.0.0",
|
|
17
|
-
"@prisma-next/config": "0.10.0-dev.
|
|
18
|
-
"@prisma-next/contract": "0.10.0-dev.
|
|
19
|
-
"@prisma-next/emitter": "0.10.0-dev.
|
|
20
|
-
"@prisma-next/errors": "0.10.0-dev.
|
|
21
|
-
"@prisma-next/framework-components": "0.10.0-dev.
|
|
22
|
-
"@prisma-next/migration-tools": "0.10.0-dev.
|
|
23
|
-
"@prisma-next/psl-printer": "0.10.0-dev.
|
|
24
|
-
"@prisma-next/
|
|
17
|
+
"@prisma-next/config": "0.10.0-dev.8",
|
|
18
|
+
"@prisma-next/contract": "0.10.0-dev.8",
|
|
19
|
+
"@prisma-next/emitter": "0.10.0-dev.8",
|
|
20
|
+
"@prisma-next/errors": "0.10.0-dev.8",
|
|
21
|
+
"@prisma-next/framework-components": "0.10.0-dev.8",
|
|
22
|
+
"@prisma-next/migration-tools": "0.10.0-dev.8",
|
|
23
|
+
"@prisma-next/psl-printer": "0.10.0-dev.8",
|
|
24
|
+
"@prisma-next/cli-telemetry": "0.10.0-dev.8",
|
|
25
|
+
"@prisma-next/utils": "0.10.0-dev.8",
|
|
25
26
|
"arktype": "^2.2.0",
|
|
26
27
|
"c12": "^3.3.4",
|
|
28
|
+
"ci-info": "^4.3.1",
|
|
27
29
|
"clipanion": "4.0.0-rc.4",
|
|
28
30
|
"closest-match": "^1.3.3",
|
|
29
31
|
"colorette": "^2.0.20",
|
|
@@ -37,14 +39,14 @@
|
|
|
37
39
|
"wrap-ansi": "^10.0.0"
|
|
38
40
|
},
|
|
39
41
|
"devDependencies": {
|
|
40
|
-
"@prisma-next/sql-contract": "0.10.0-dev.
|
|
41
|
-
"@prisma-next/sql-contract-emitter": "0.10.0-dev.
|
|
42
|
-
"@prisma-next/sql-contract-ts": "0.10.0-dev.
|
|
43
|
-
"@prisma-next/sql-operations": "0.10.0-dev.
|
|
44
|
-
"@prisma-next/sql-runtime": "0.10.0-dev.
|
|
45
|
-
"@prisma-next/test-utils": "0.10.0-dev.
|
|
46
|
-
"@prisma-next/tsconfig": "0.10.0-dev.
|
|
47
|
-
"@prisma-next/tsdown": "0.10.0-dev.
|
|
42
|
+
"@prisma-next/sql-contract": "0.10.0-dev.8",
|
|
43
|
+
"@prisma-next/sql-contract-emitter": "0.10.0-dev.8",
|
|
44
|
+
"@prisma-next/sql-contract-ts": "0.10.0-dev.8",
|
|
45
|
+
"@prisma-next/sql-operations": "0.10.0-dev.8",
|
|
46
|
+
"@prisma-next/sql-runtime": "0.10.0-dev.8",
|
|
47
|
+
"@prisma-next/test-utils": "0.10.0-dev.8",
|
|
48
|
+
"@prisma-next/tsconfig": "0.10.0-dev.8",
|
|
49
|
+
"@prisma-next/tsdown": "0.10.0-dev.8",
|
|
48
50
|
"@types/node": "24.10.4",
|
|
49
51
|
"tsdown": "0.22.0",
|
|
50
52
|
"typescript": "5.9.3",
|
package/src/cli.ts
CHANGED
|
@@ -27,6 +27,7 @@ import { setCommandDescriptions } from './utils/command-helpers';
|
|
|
27
27
|
import { formatCommandHelp, formatRootHelp } from './utils/formatters/help';
|
|
28
28
|
import { parseGlobalFlags } from './utils/global-flags';
|
|
29
29
|
import { suggestCommands } from './utils/suggest-command';
|
|
30
|
+
import { fireTelemetryFromPreAction } from './utils/telemetry';
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
33
|
* Lookup table mapping removed subcommands to their replacement verbs.
|
|
@@ -68,6 +69,20 @@ const program = new Command();
|
|
|
68
69
|
|
|
69
70
|
program.name('prisma-next').description('Prisma Next CLI').version(packageJson.version);
|
|
70
71
|
|
|
72
|
+
// Telemetry hook — fires at command start, before the action body
|
|
73
|
+
// runs. Every failure mode is swallowed inside `runTelemetry`; the
|
|
74
|
+
// hook never throws and never blocks long enough to be perceptible.
|
|
75
|
+
//
|
|
76
|
+
// Fire-and-forget: `fireTelemetryFromPreAction` `await`s a c12 config
|
|
77
|
+
// load before forking the sender, so awaiting it here would block the
|
|
78
|
+
// command's action body behind telemetry. Use `void` to dispatch in
|
|
79
|
+
// parallel; the existing `.catch(() => {})` keeps errors swallowed.
|
|
80
|
+
program.hook('preAction', (_thisCommand, actionCommand) => {
|
|
81
|
+
void fireTelemetryFromPreAction(actionCommand).catch(() => {
|
|
82
|
+
// defence-in-depth — runTelemetry already swallows internally.
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
71
86
|
// Override version option description to match capitalization style
|
|
72
87
|
const versionOption = program.options.find((opt) => opt.flags.includes('--version'));
|
|
73
88
|
if (versionOption) {
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
setCommandExamples,
|
|
6
6
|
} from '../../utils/command-helpers';
|
|
7
7
|
import { type CommonCommandOptions, parseGlobalFlags } from '../../utils/global-flags';
|
|
8
|
+
import { fireTelemetryAfterInitConsent } from '../../utils/telemetry';
|
|
8
9
|
import {
|
|
9
10
|
INIT_EXIT_EMIT_FAILED,
|
|
10
11
|
INIT_EXIT_INSTALL_FAILED,
|
|
@@ -91,7 +92,7 @@ export function createInitCommand(): Command {
|
|
|
91
92
|
'--no-skill',
|
|
92
93
|
'Skip Prisma Next skills install (air-gapped CI, restricted registries, etc.)',
|
|
93
94
|
)
|
|
94
|
-
.action(async (options: InitCommandOptions) => {
|
|
95
|
+
.action(async (options: InitCommandOptions, actionCommand: Command) => {
|
|
95
96
|
const { runInit } = await import('./init');
|
|
96
97
|
const flags = parseGlobalFlags(options);
|
|
97
98
|
const canPrompt = deriveCanPrompt({
|
|
@@ -99,7 +100,14 @@ export function createInitCommand(): Command {
|
|
|
99
100
|
optionInteractive: options.interactive,
|
|
100
101
|
stdinIsTTY: Boolean(process.stdin.isTTY),
|
|
101
102
|
});
|
|
102
|
-
const exitCode = await runInit(process.cwd(), {
|
|
103
|
+
const exitCode = await runInit(process.cwd(), {
|
|
104
|
+
options,
|
|
105
|
+
flags,
|
|
106
|
+
canPrompt,
|
|
107
|
+
afterFirstTelemetryConsent: (inputs) => {
|
|
108
|
+
fireTelemetryAfterInitConsent(actionCommand, { databaseTarget: inputs.target });
|
|
109
|
+
},
|
|
110
|
+
});
|
|
103
111
|
process.exit(exitCode);
|
|
104
112
|
});
|
|
105
113
|
}
|
|
@@ -113,6 +113,11 @@ export async function runInit(
|
|
|
113
113
|
* mode) — see [Style Guide § Interactivity](../../../../../../../docs/CLI%20Style%20Guide.md#interactivity).
|
|
114
114
|
*/
|
|
115
115
|
readonly canPrompt: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Called once after the first affirmative telemetry consent is persisted.
|
|
118
|
+
* Failures are swallowed by the caller; init success must not depend on telemetry.
|
|
119
|
+
*/
|
|
120
|
+
readonly afterFirstTelemetryConsent?: (inputs: ResolvedInitInputs) => void | Promise<void>;
|
|
116
121
|
/**
|
|
117
122
|
* FR8.3 — test-only seam for the optional database version probe.
|
|
118
123
|
* Production callers omit this; tests inject stub `probePostgres` /
|
|
@@ -124,7 +129,7 @@ export async function runInit(
|
|
|
124
129
|
readonly probeOverrides?: ProbeOverrides;
|
|
125
130
|
},
|
|
126
131
|
): Promise<number> {
|
|
127
|
-
const { options, flags, canPrompt, probeOverrides } = runOptions;
|
|
132
|
+
const { options, flags, canPrompt, probeOverrides, afterFirstTelemetryConsent } = runOptions;
|
|
128
133
|
const ui = new TerminalUI({ color: flags.color, interactive: flags.interactive });
|
|
129
134
|
const warnings: string[] = [];
|
|
130
135
|
const filesWritten: string[] = [];
|
|
@@ -144,6 +149,14 @@ export async function runInit(
|
|
|
144
149
|
throw error;
|
|
145
150
|
}
|
|
146
151
|
|
|
152
|
+
if (inputs.enableTelemetry === true && afterFirstTelemetryConsent !== undefined) {
|
|
153
|
+
try {
|
|
154
|
+
await afterFirstTelemetryConsent(inputs);
|
|
155
|
+
} catch {
|
|
156
|
+
// telemetry is best-effort and must never affect init
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
147
160
|
const pm = await detectPackageManager(baseDir);
|
|
148
161
|
const pkgRun = formatRunCommand(pm, 'prisma-next', '').trimEnd();
|
|
149
162
|
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import * as clack from '@clack/prompts';
|
|
3
|
+
import { readUserConfig, resolveGating, writeUserConfig } from '@prisma-next/cli-telemetry';
|
|
3
4
|
import { extname, join, normalize } from 'pathe';
|
|
4
5
|
import type { GlobalFlags } from '../../utils/global-flags';
|
|
6
|
+
import { isCI } from '../../utils/is-ci';
|
|
5
7
|
import {
|
|
6
8
|
errorInitInvalidFlagValue,
|
|
7
9
|
errorInitMissingFlags,
|
|
@@ -68,6 +70,18 @@ export interface ResolvedInitInputs {
|
|
|
68
70
|
* is added separately via the install step.
|
|
69
71
|
*/
|
|
70
72
|
readonly removePreviousFacade: string | null;
|
|
73
|
+
/**
|
|
74
|
+
* Telemetry consent answer recorded during this `init` run, or `null`
|
|
75
|
+
* when no prompt was shown. The prompt fires only on the
|
|
76
|
+
* canPrompt + !autoAcceptPrompts + no env/CI opt-out +
|
|
77
|
+
* `enableTelemetry === undefined` intersection; outside that window
|
|
78
|
+
* the field is `null` and the stored preference (if any) stays
|
|
79
|
+
* unchanged. The answer has already been persisted to
|
|
80
|
+
* `$XDG_CONFIG_HOME/prisma-next/config.json` by
|
|
81
|
+
* the time `runInit` sees this value — it's surfaced here purely so
|
|
82
|
+
* the post-init summary can mention what the user chose.
|
|
83
|
+
*/
|
|
84
|
+
readonly enableTelemetry: boolean | null;
|
|
71
85
|
/**
|
|
72
86
|
* Whether to run `npx skills add prisma/prisma-next#v<version>` at the
|
|
73
87
|
* project level after install + emit. True by default; `--no-skill`
|
|
@@ -91,6 +105,12 @@ const AUTHORING_VALUES: ReadonlyMap<string, AuthoringId> = new Map([
|
|
|
91
105
|
['ts', 'typescript'],
|
|
92
106
|
]);
|
|
93
107
|
|
|
108
|
+
export const TELEMETRY_CONSENT_MESSAGE = [
|
|
109
|
+
'Help us prioritize features by sharing anonymous CLI usage data?',
|
|
110
|
+
'The telemetry implementation is open source and fully transparent.',
|
|
111
|
+
'(packages/1-framework/3-tooling/cli-telemetry and apps/telemetry-backend).',
|
|
112
|
+
].join(' ');
|
|
113
|
+
|
|
94
114
|
/**
|
|
95
115
|
* Resolves every required input for `runInit`. In interactive mode, missing
|
|
96
116
|
* inputs are prompted via clack; in non-interactive mode, missing required
|
|
@@ -176,6 +196,11 @@ export async function resolveInitInputs(ctx: {
|
|
|
176
196
|
autoAcceptPrompts,
|
|
177
197
|
});
|
|
178
198
|
|
|
199
|
+
const enableTelemetry = await resolveTelemetryConsent({
|
|
200
|
+
canPrompt,
|
|
201
|
+
autoAcceptPrompts,
|
|
202
|
+
});
|
|
203
|
+
|
|
179
204
|
// Skill-install gating. `--no-skill` (commander parses
|
|
180
205
|
// `options.skill === false`) is the only escape hatch; otherwise
|
|
181
206
|
// project-level install is unconditional. The skill is always
|
|
@@ -193,10 +218,60 @@ export async function resolveInitInputs(ctx: {
|
|
|
193
218
|
strictProbe: Boolean(options.strictProbe),
|
|
194
219
|
reinit,
|
|
195
220
|
removePreviousFacade,
|
|
221
|
+
enableTelemetry,
|
|
196
222
|
installProjectSkill,
|
|
197
223
|
};
|
|
198
224
|
}
|
|
199
225
|
|
|
226
|
+
/**
|
|
227
|
+
* The interactive telemetry consent prompt. Shown as the last
|
|
228
|
+
* question of the `init` sequence iff:
|
|
229
|
+
* 1. `canPrompt === true` (interactive stdin / stdout combo),
|
|
230
|
+
* 2. `autoAcceptPrompts === false` (the user did not pass `--yes`),
|
|
231
|
+
* 3. neither telemetry env opt-out is active,
|
|
232
|
+
* 4. the process is not running in CI,
|
|
233
|
+
* 5. the stored `enableTelemetry` value is `undefined` (the user
|
|
234
|
+
* has never been asked, or skipped the prompt previously).
|
|
235
|
+
*
|
|
236
|
+
* Outside that intersection the function returns `null` and leaves the
|
|
237
|
+
* stored preference untouched. Inside it, the user's answer is
|
|
238
|
+
* persisted via `writeUserConfig({ enableTelemetry })` before this
|
|
239
|
+
* function returns; on an affirmative answer `writeUserConfig`
|
|
240
|
+
* generates and stores the v4 `installationId` in the same write.
|
|
241
|
+
*
|
|
242
|
+
* The wording names CLI usage data and points to the open-source
|
|
243
|
+
* client/backend paths. Default value is `true` to match precedent
|
|
244
|
+
* and to make the consent answer a single keystroke once it's been
|
|
245
|
+
* disclosed.
|
|
246
|
+
*/
|
|
247
|
+
async function resolveTelemetryConsent(opts: {
|
|
248
|
+
readonly canPrompt: boolean;
|
|
249
|
+
readonly autoAcceptPrompts: boolean;
|
|
250
|
+
}): Promise<boolean | null> {
|
|
251
|
+
if (!opts.canPrompt || opts.autoAcceptPrompts || isCI()) {
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
const config = readUserConfig();
|
|
255
|
+
const gating = resolveGating({ env: process.env, config });
|
|
256
|
+
if (!gating.enabled && gating.reason === 'env-override') {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
const stored = config.enableTelemetry;
|
|
260
|
+
if (stored !== undefined) {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
const result = await clack.confirm({
|
|
264
|
+
message: TELEMETRY_CONSENT_MESSAGE,
|
|
265
|
+
initialValue: true,
|
|
266
|
+
output: process.stderr,
|
|
267
|
+
});
|
|
268
|
+
if (clack.isCancel(result)) {
|
|
269
|
+
throw errorInitUserAborted();
|
|
270
|
+
}
|
|
271
|
+
writeUserConfig({ enableTelemetry: Boolean(result) });
|
|
272
|
+
return Boolean(result);
|
|
273
|
+
}
|
|
274
|
+
|
|
200
275
|
async function resolveWriteEnv(opts: {
|
|
201
276
|
readonly flag: boolean | undefined;
|
|
202
277
|
readonly canPrompt: boolean;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isCI } from './is-ci';
|
|
2
|
+
|
|
1
3
|
export interface GlobalFlags {
|
|
2
4
|
readonly json?: boolean;
|
|
3
5
|
readonly quiet?: boolean;
|
|
@@ -70,8 +72,10 @@ export function parseGlobalFlags(options: CommonCommandOptions): GlobalFlags {
|
|
|
70
72
|
} else if (options.color !== undefined) {
|
|
71
73
|
flags.color = options.color;
|
|
72
74
|
} else {
|
|
73
|
-
// Default: enable color if TTY
|
|
74
|
-
|
|
75
|
+
// Default: enable color if TTY and not in CI. Uses the consolidated
|
|
76
|
+
// `isCI()` helper (`./is-ci.ts`) — the single source of truth shared
|
|
77
|
+
// with telemetry-skip detection.
|
|
78
|
+
flags.color = process.stdout.isTTY && !isCI();
|
|
75
79
|
}
|
|
76
80
|
|
|
77
81
|
// Interactivity: --interactive/--no-interactive
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isCI as ciInfoIsCI } from 'ci-info';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns true when the process is running in any CI environment recognised
|
|
5
|
+
* by the `ci-info` package. The single source of truth for CI detection
|
|
6
|
+
* across this CLI — colour-output suppression and telemetry-skip both call
|
|
7
|
+
* this helper, so neither path drifts from the other when a new CI provider
|
|
8
|
+
* is added upstream.
|
|
9
|
+
*
|
|
10
|
+
* `ci-info` checks the standard `CI=true` marker plus dozens of
|
|
11
|
+
* provider-specific environment variables (Buildkite, Jenkins, Drone,
|
|
12
|
+
* Bitbucket Pipelines, Azure Pipelines, AWS CodeBuild, …) that the raw
|
|
13
|
+
* `process.env.CI` read misses.
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
export function isCI(): boolean {
|
|
17
|
+
return ciInfoIsCI;
|
|
18
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import {
|
|
3
|
+
type CommanderOptionShape,
|
|
4
|
+
type CommanderResultShape,
|
|
5
|
+
readUserConfig,
|
|
6
|
+
resolveGating,
|
|
7
|
+
runTelemetry,
|
|
8
|
+
type TelemetryRunOutcome,
|
|
9
|
+
type UserConfig,
|
|
10
|
+
} from '@prisma-next/cli-telemetry';
|
|
11
|
+
import type { Command } from 'commander';
|
|
12
|
+
import { version as CLI_VERSION } from '../../package.json' with { type: 'json' };
|
|
13
|
+
import { loadConfig } from '../config-loader';
|
|
14
|
+
import { isCI } from './is-ci';
|
|
15
|
+
|
|
16
|
+
interface TelemetryFields {
|
|
17
|
+
readonly databaseTarget: string | null;
|
|
18
|
+
readonly extensions: readonly string[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type TelemetryGate =
|
|
22
|
+
| { readonly enabled: true; readonly userConfig: UserConfig }
|
|
23
|
+
| { readonly enabled: false; readonly outcome: TelemetryRunOutcome };
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Resolve the commander command path from a leaf `Command`, walking up
|
|
27
|
+
* the parent chain. Result is rooted at the program name and ends at
|
|
28
|
+
* the leaf — `['prisma-next', 'migration', 'new']` for
|
|
29
|
+
* `prisma-next migration new …`.
|
|
30
|
+
*/
|
|
31
|
+
function commandPathFor(actionCommand: Command): string[] {
|
|
32
|
+
const path: string[] = [];
|
|
33
|
+
let cursor: Command | null = actionCommand;
|
|
34
|
+
while (cursor !== null) {
|
|
35
|
+
path.unshift(cursor.name());
|
|
36
|
+
cursor = cursor.parent;
|
|
37
|
+
}
|
|
38
|
+
return path;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function commanderOptionSnapshots(actionCommand: Command): CommanderOptionShape[] {
|
|
42
|
+
return actionCommand.options.map((option) => {
|
|
43
|
+
const attributeName = option.attributeName();
|
|
44
|
+
return {
|
|
45
|
+
attributeName,
|
|
46
|
+
longName: option.long ?? null,
|
|
47
|
+
source: actionCommand.getOptionValueSource(attributeName) ?? null,
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Project commander's leaf `Command` into the wire-shape snapshot the
|
|
54
|
+
* telemetry sanitiser consumes. Pure projection — no env, no I/O.
|
|
55
|
+
*/
|
|
56
|
+
export function commanderSnapshotForTelemetry(actionCommand: Command): CommanderResultShape {
|
|
57
|
+
return {
|
|
58
|
+
commandPath: commandPathFor(actionCommand),
|
|
59
|
+
positionalArgs: actionCommand.args,
|
|
60
|
+
options: commanderOptionSnapshots(actionCommand),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function resolveTelemetryGate(): TelemetryGate {
|
|
65
|
+
if (isCI()) {
|
|
66
|
+
return { enabled: false, outcome: { spawned: false, reason: 'ci' } };
|
|
67
|
+
}
|
|
68
|
+
const userConfig = readUserConfig();
|
|
69
|
+
const gating = resolveGating({ env: process.env, config: userConfig });
|
|
70
|
+
if (!gating.enabled) {
|
|
71
|
+
return { enabled: false, outcome: { spawned: false, reason: 'gated-off' } };
|
|
72
|
+
}
|
|
73
|
+
return { enabled: true, userConfig };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Best-effort extraction of `databaseTarget` and `extensions` from the
|
|
78
|
+
* project config. Loads via the same `c12`-backed loader the action
|
|
79
|
+
* handlers use so we honour the same lookup rules. Every failure mode
|
|
80
|
+
* (no config file, malformed config, async load reject) collapses to
|
|
81
|
+
* `(null, [])` because telemetry is non-blocking and may fire for
|
|
82
|
+
* commands that legitimately don't have a config (e.g. `init`).
|
|
83
|
+
*/
|
|
84
|
+
async function loadConfigForTelemetry(): Promise<TelemetryFields> {
|
|
85
|
+
try {
|
|
86
|
+
const config = await loadConfig();
|
|
87
|
+
const target = config.target as { readonly targetId?: unknown } | undefined;
|
|
88
|
+
const databaseTarget =
|
|
89
|
+
target !== undefined && typeof target.targetId === 'string' ? target.targetId : null;
|
|
90
|
+
const extensionPacks = (config.extensionPacks ?? []) as ReadonlyArray<{
|
|
91
|
+
readonly id?: unknown;
|
|
92
|
+
}>;
|
|
93
|
+
const extensions = extensionPacks
|
|
94
|
+
.map((pack) => pack.id)
|
|
95
|
+
.filter((id): id is string => typeof id === 'string');
|
|
96
|
+
return { databaseTarget, extensions };
|
|
97
|
+
} catch {
|
|
98
|
+
return { databaseTarget: null, extensions: [] };
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Path to the compiled sender script inside `@prisma-next/cli-telemetry`'s
|
|
104
|
+
* `dist/`. Resolved off this module's `import.meta.url` via the package
|
|
105
|
+
* specifier `@prisma-next/cli-telemetry/sender`, so the consumer pays
|
|
106
|
+
* no attention to internal package layout.
|
|
107
|
+
*/
|
|
108
|
+
function senderPath(): string {
|
|
109
|
+
return fileURLToPath(new URL(import.meta.resolve('@prisma-next/cli-telemetry/sender')));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function fireTelemetryWithFields(
|
|
113
|
+
actionCommand: Command,
|
|
114
|
+
fields: TelemetryFields,
|
|
115
|
+
userConfig: UserConfig,
|
|
116
|
+
): TelemetryRunOutcome {
|
|
117
|
+
return runTelemetry({
|
|
118
|
+
command: commanderSnapshotForTelemetry(actionCommand),
|
|
119
|
+
version: CLI_VERSION,
|
|
120
|
+
databaseTarget: fields.databaseTarget,
|
|
121
|
+
extensions: fields.extensions,
|
|
122
|
+
projectRoot: process.cwd(),
|
|
123
|
+
senderPath: senderPath(),
|
|
124
|
+
isCI: isCI(),
|
|
125
|
+
env: process.env,
|
|
126
|
+
userConfig,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* preAction-stage entry point: resolve env/CI/user-consent gates first,
|
|
132
|
+
* then (only when enabled) load project config for database target and
|
|
133
|
+
* extension metadata, then fork the detached sender. The early gate is
|
|
134
|
+
* privacy- and UX-critical: config loading can execute user code and
|
|
135
|
+
* must never happen before opt-out/default-off checks have resolved.
|
|
136
|
+
*/
|
|
137
|
+
export async function fireTelemetryFromPreAction(
|
|
138
|
+
actionCommand: Command,
|
|
139
|
+
): Promise<TelemetryRunOutcome> {
|
|
140
|
+
const gate = resolveTelemetryGate();
|
|
141
|
+
if (!gate.enabled) {
|
|
142
|
+
return gate.outcome;
|
|
143
|
+
}
|
|
144
|
+
const fields = await loadConfigForTelemetry();
|
|
145
|
+
return fireTelemetryWithFields(actionCommand, fields, gate.userConfig);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Manual one-shot telemetry path for the first `init` run where the user
|
|
150
|
+
* explicitly answers Yes to the consent prompt. The preAction hook for
|
|
151
|
+
* that same run has already resolved before consent existed, so it is
|
|
152
|
+
* default-off. After consent is persisted, `runInit` calls this helper
|
|
153
|
+
* exactly for that first affirmative answer; subsequent init runs skip
|
|
154
|
+
* it because the prompt is not shown again.
|
|
155
|
+
*/
|
|
156
|
+
export function fireTelemetryAfterInitConsent(
|
|
157
|
+
actionCommand: Command,
|
|
158
|
+
inputs: { readonly databaseTarget: string },
|
|
159
|
+
): TelemetryRunOutcome {
|
|
160
|
+
const userConfig = readUserConfig();
|
|
161
|
+
return fireTelemetryWithFields(
|
|
162
|
+
actionCommand,
|
|
163
|
+
{ databaseTarget: inputs.databaseTarget, extensions: [] },
|
|
164
|
+
userConfig,
|
|
165
|
+
);
|
|
166
|
+
}
|