@contractkit/prettier-plugin 0.12.0 → 0.12.2
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/.turbo/turbo-build$colon$ci.log +5 -5
- package/.turbo/turbo-test$colon$ci.log +9 -9
- package/CHANGELOG.md +15 -0
- package/dist/index.js +22 -7
- package/dist/index.js.map +1 -1
- package/dist/print-ck.d.ts +1 -0
- package/dist/print-ck.d.ts.map +1 -1
- package/dist/print-contract.d.ts +7 -0
- package/dist/print-contract.d.ts.map +1 -1
- package/dist/print-operation.d.ts +9 -0
- package/dist/print-operation.d.ts.map +1 -1
- package/dist/print-type.d.ts +3 -1
- package/dist/print-type.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/print-ck.ts +18 -7
- package/src/print-contract.ts +10 -0
- package/src/print-operation.ts +14 -0
- package/src/print-type.ts +8 -2
- package/tests/print-ck.test.ts +239 -0
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -87
- package/coverage/clover.xml +0 -358
- package/coverage/coverage-final.json +0 -6
- package/coverage/favicon.png +0 -0
- package/coverage/indent.ts.html +0 -88
- package/coverage/index.html +0 -176
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/print-ck.ts.html +0 -424
- package/coverage/print-contract.ts.html +0 -292
- package/coverage/print-operation.ts.html +0 -1078
- package/coverage/print-type.ts.html +0 -532
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -210
|
@@ -5,9 +5,9 @@ $ tsup src/index.ts --format esm --sourcemap --dts && tsc --emitDeclarationOnly
|
|
|
5
5
|
[34mCLI[39m tsup v8.5.1
|
|
6
6
|
[34mCLI[39m Target: esnext
|
|
7
7
|
[34mESM[39m Build start
|
|
8
|
-
[32mESM[39m [1mdist/index.js [22m[
|
|
9
|
-
[32mESM[39m [1mdist/index.js.map [22m[
|
|
10
|
-
[32mESM[39m ⚡️ Build success in
|
|
8
|
+
[32mESM[39m [1mdist/index.js [22m[32m21.38 KB[39m
|
|
9
|
+
[32mESM[39m [1mdist/index.js.map [22m[32m52.77 KB[39m
|
|
10
|
+
[32mESM[39m ⚡️ Build success in 206ms
|
|
11
11
|
[34mDTS[39m Build start
|
|
12
|
-
[32mDTS[39m ⚡️ Build success in
|
|
13
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
12
|
+
[32mDTS[39m ⚡️ Build success in 5108ms
|
|
13
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m726.00 B[39m
|
|
@@ -3,21 +3,21 @@ $ vitest run --coverage
|
|
|
3
3
|
[1m[30m[46m RUN [49m[39m[22m [36mv4.1.5 [39m[90m/home/runner/work/ContractKit/ContractKit/apps/prettier-plugin[39m
|
|
4
4
|
[2mCoverage enabled with [22m[33mv8[39m
|
|
5
5
|
|
|
6
|
-
[32m✓[39m tests/print-ck.test.ts [2m([22m[
|
|
6
|
+
[32m✓[39m tests/print-ck.test.ts [2m([22m[2m75 tests[22m[2m)[22m[33m 570[2mms[22m[39m
|
|
7
7
|
|
|
8
8
|
[2m Test Files [22m [1m[32m1 passed[39m[22m[90m (1)[39m
|
|
9
|
-
[2m Tests [22m [1m[
|
|
10
|
-
[2m Start at [22m
|
|
11
|
-
[2m Duration [22m
|
|
9
|
+
[2m Tests [22m [1m[32m75 passed[39m[22m[90m (75)[39m
|
|
10
|
+
[2m Start at [22m 17:06:39
|
|
11
|
+
[2m Duration [22m 6.62s[2m (transform 2.00s, setup 0ms, import 4.69s, tests 570ms, environment 0ms)[22m
|
|
12
12
|
|
|
13
13
|
[34m % [39m[2mCoverage report from [22m[33mv8[39m
|
|
14
14
|
-------------------|---------|----------|---------|---------|-------------------
|
|
15
15
|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
|
|
16
16
|
-------------------|---------|----------|---------|---------|-------------------
|
|
17
|
-
All files |
|
|
17
|
+
All files | 71.2 | 63.72 | 81.25 | 77.8 |
|
|
18
18
|
indent.ts | 100 | 100 | 100 | 100 |
|
|
19
|
-
print-ck.ts | 89.
|
|
20
|
-
print-contract.ts |
|
|
21
|
-
...t-operation.ts | 73.
|
|
22
|
-
print-type.ts |
|
|
19
|
+
print-ck.ts | 89.18 | 83.8 | 100 | 98.14 | 70
|
|
20
|
+
print-contract.ts | 45.71 | 37.5 | 50 | 46.66 | 17,47-78
|
|
21
|
+
...t-operation.ts | 73.98 | 65.04 | 92.85 | 83.95 | ...88,296-307,339
|
|
22
|
+
print-type.ts | 58.69 | 56.73 | 63.63 | 60 | ...02-103,148-151
|
|
23
23
|
-------------------|---------|----------|---------|---------|-------------------
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @contractkit/prettier-plugin-contractkit
|
|
2
2
|
|
|
3
|
+
## 0.12.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2bf01f1: Preserve trailing comments instead of dropping them on format: a comment as the last line of a contract/model body, an operation/route body, an inline object type, or an options `keys`/`services` block now round-trips.
|
|
8
|
+
- Updated dependencies [2bf01f1]
|
|
9
|
+
- @contractkit/core@0.23.0
|
|
10
|
+
|
|
11
|
+
## 0.12.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [0d3b8e2]
|
|
16
|
+
- @contractkit/core@0.22.0
|
|
17
|
+
|
|
3
18
|
## 0.12.0
|
|
4
19
|
|
|
5
20
|
### Minor Changes
|
package/dist/index.js
CHANGED
|
@@ -106,7 +106,11 @@ function printField(field, indent, printWidth = 80) {
|
|
|
106
106
|
}
|
|
107
107
|
__name(printField, "printField");
|
|
108
108
|
function printInlineObjectExpanded(obj, indent, printWidth = 80) {
|
|
109
|
-
|
|
109
|
+
const lines = obj.fields.map((f) => printField(f, indent, printWidth));
|
|
110
|
+
for (const comment of obj.trailingComments ?? []) {
|
|
111
|
+
lines.push(`${indent}# ${comment}`);
|
|
112
|
+
}
|
|
113
|
+
return lines;
|
|
110
114
|
}
|
|
111
115
|
__name(printInlineObjectExpanded, "printInlineObjectExpanded");
|
|
112
116
|
function formatEnumValue(v) {
|
|
@@ -164,6 +168,9 @@ function printModelDecl(model, printWidth = 80) {
|
|
|
164
168
|
for (const field of model.fields) {
|
|
165
169
|
lines.push(printField(field, INDENT, printWidth));
|
|
166
170
|
}
|
|
171
|
+
for (const comment of model.trailingComments ?? []) {
|
|
172
|
+
lines.push(`${INDENT}# ${comment}`);
|
|
173
|
+
}
|
|
167
174
|
lines.push("}");
|
|
168
175
|
return lines.join("\n");
|
|
169
176
|
}
|
|
@@ -228,6 +235,9 @@ function printRoute(route, blocks, idx, nextRouteStart) {
|
|
|
228
235
|
lines.push(...printOperation(op));
|
|
229
236
|
}
|
|
230
237
|
flushBlocks(lines, blocks, idx, nextRouteStart, I1);
|
|
238
|
+
for (const comment of route.trailingComments ?? []) {
|
|
239
|
+
lines.push(`${I1}# ${comment}`);
|
|
240
|
+
}
|
|
231
241
|
lines.push("}");
|
|
232
242
|
return lines.join("\n");
|
|
233
243
|
}
|
|
@@ -483,6 +493,15 @@ function quoteOptionsValue(value) {
|
|
|
483
493
|
return /^[a-zA-Z_$][a-zA-Z0-9_$\-.]*$/.test(value) ? value : `"${value}"`;
|
|
484
494
|
}
|
|
485
495
|
__name(quoteOptionsValue, "quoteOptionsValue");
|
|
496
|
+
function emitOptionsEntries(lines, entries, comments) {
|
|
497
|
+
const I22 = INDENT + INDENT;
|
|
498
|
+
for (const [key, value] of Object.entries(entries)) {
|
|
499
|
+
for (const c of comments?.leading?.[key] ?? []) lines.push(`${I22}# ${c}`);
|
|
500
|
+
lines.push(`${I22}${key}: ${quoteOptionsValue(value)}`);
|
|
501
|
+
}
|
|
502
|
+
for (const c of comments?.trailing ?? []) lines.push(`${I22}# ${c}`);
|
|
503
|
+
}
|
|
504
|
+
__name(emitOptionsEntries, "emitOptionsEntries");
|
|
486
505
|
function printOptionsBlock(ast) {
|
|
487
506
|
const hasMeta = Object.keys(ast.meta).length > 0;
|
|
488
507
|
const hasServices = Object.keys(ast.services).length > 0;
|
|
@@ -495,16 +514,12 @@ function printOptionsBlock(ast) {
|
|
|
495
514
|
];
|
|
496
515
|
if (hasMeta) {
|
|
497
516
|
lines.push(`${INDENT}keys: {`);
|
|
498
|
-
|
|
499
|
-
lines.push(`${INDENT}${INDENT}${key}: ${quoteOptionsValue(value)}`);
|
|
500
|
-
}
|
|
517
|
+
emitOptionsEntries(lines, ast.meta, ast.optionsComments?.keys);
|
|
501
518
|
lines.push(`${INDENT}}`);
|
|
502
519
|
}
|
|
503
520
|
if (hasServices) {
|
|
504
521
|
lines.push(`${INDENT}services: {`);
|
|
505
|
-
|
|
506
|
-
lines.push(`${INDENT}${INDENT}${key}: ${quoteOptionsValue(value)}`);
|
|
507
|
-
}
|
|
522
|
+
emitOptionsEntries(lines, ast.services, ast.optionsComments?.services);
|
|
508
523
|
lines.push(`${INDENT}}`);
|
|
509
524
|
}
|
|
510
525
|
if (hasRequestHeaders) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/indent.ts","../src/print-type.ts","../src/print-contract.ts","../src/print-operation.ts","../src/print-ck.ts"],"sourcesContent":["import type { Plugin } from 'prettier';\nimport { builders } from 'prettier/doc';\nimport { parseCk, DiagnosticCollector } from '@contractkit/core';\nimport type { CkRootNode } from '@contractkit/core';\nimport { printCk } from './print-ck.js';\n\nconst { hardline, join } = builders;\n\nfunction toDoc(text: string) {\n const lines = text.trimEnd().split('\\n');\n return join(hardline, lines);\n}\n\nconst plugin: Plugin<CkRootNode> = {\n languages: [\n {\n name: 'ContractDSL',\n parsers: ['contract-ck'],\n extensions: ['.ck'],\n vscodeLanguageIds: ['contract-ck'],\n },\n ],\n\n parsers: {\n 'contract-ck': {\n parse(text, _options) {\n const diag = new DiagnosticCollector();\n return parseCk(text, '<stdin>', diag);\n },\n astFormat: 'contract-ck',\n locStart: () => 0,\n locEnd: _node => 0,\n },\n },\n\n printers: {\n 'contract-ck': {\n print(path, options) {\n const node = path.node as CkRootNode;\n return toDoc(printCk(node, options.printWidth));\n },\n },\n },\n};\n\nexport default plugin;\nexport { printCk, DEFAULT_PRINT_WIDTH } from './print-ck.js';\n","export const INDENT = ' ';\n","import type { ContractTypeNode, FieldNode, InlineObjectTypeNode } from '@contractkit/core';\nimport { INDENT } from './indent.js';\n\n// ─── Type expression printer ────────────────────────────────────────────────\n\n/** Render a `ContractTypeNode` back to its `.ck` source string. */\nexport function printType(type: ContractTypeNode): string {\n switch (type.kind) {\n case 'scalar': {\n const constraints: string[] = [];\n if (type.format !== undefined) {\n // Print unquoted when format contains only safe chars; quote otherwise\n const fmt = type.format;\n constraints.push(/^[a-zA-Z0-9\\-.:/]+$/.test(fmt) ? fmt : `\"${fmt}\"`);\n }\n if (type.min !== undefined) constraints.push(`min=${type.min}`);\n if (type.max !== undefined) constraints.push(`max=${type.max}`);\n if (type.len !== undefined) constraints.push(`len=${type.len}`);\n if (type.regex !== undefined) constraints.push(`regex=/${type.regex}/`);\n return constraints.length > 0 ? `${type.name}(${constraints.join(', ')})` : type.name;\n }\n case 'array': {\n const args: string[] = [printType(type.item)];\n if (type.min !== undefined) args.push(`min=${type.min}`);\n if (type.max !== undefined) args.push(`max=${type.max}`);\n return `array(${args.join(', ')})`;\n }\n case 'tuple':\n return `tuple(${type.items.map(printType).join(', ')})`;\n case 'record':\n return `record(${printType(type.key)}, ${printType(type.value)})`;\n case 'enum':\n return `enum(${type.values.map(formatEnumValue).join(', ')})`;\n case 'literal':\n return typeof type.value === 'string' ? `literal(\"${type.value}\")` : `literal(${type.value})`;\n case 'union':\n return type.members.map(printType).join(' | ');\n case 'discriminatedUnion':\n return `discriminated(by=${type.discriminator}, ${type.members.map(printType).join(' | ')})`;\n case 'intersection':\n return type.members.map(printType).join(' & ');\n case 'ref':\n return type.name;\n case 'inlineObject':\n return printInlineObjectCompact(type);\n case 'lazy':\n return `lazy(${printType(type.inner)})`;\n }\n}\n\n/** Compact single-line form — used when inline object appears nested inside another type. */\nfunction printInlineObjectCompact(obj: InlineObjectTypeNode): string {\n const prefix = obj.mode ? `mode(${obj.mode}) ` : '';\n if (obj.fields.length === 0) return `${prefix}{}`;\n const parts = obj.fields.map(f => {\n const opt = f.optional ? '?' : '';\n let t = printType(f.type);\n if (f.nullable) t += ' | null';\n return `${f.name}${opt}: ${t}`;\n });\n return `${prefix}{ ${parts.join(', ')} }`;\n}\n\n/** Multi-line enum form — one value per line, used when single-line would exceed print width. */\nexport function printEnumExpanded(values: string[], indent: string): string {\n const innerIndent = indent + INDENT;\n return `enum(\\n${values.map(v => `${innerIndent}${formatEnumValue(v)}`).join(',\\n')}\\n${indent})`;\n}\n\n// ─── Field printer ──────────────────────────────────────────────────────────\n\n/** Print a full field declaration, including visibility, default, and inline comment.\n * Modifier order is canonical: override → deprecated → readonly|writeonly → type. */\nexport function printField(field: FieldNode, indent: string, printWidth: number = 80): string {\n const opt = field.optional ? '?' : '';\n const ovr = field.override ? 'override ' : '';\n const dep = field.deprecated ? 'deprecated ' : '';\n const vis = field.visibility !== 'normal' ? `${field.visibility} ` : '';\n const mods = `${ovr}${dep}${vis}`;\n const def = field.default !== undefined ? ` = ${formatDefault(field.default)}` : '';\n const comment = field.description ? ` # ${field.description}` : '';\n const innerIndent = indent + INDENT;\n\n // Expand inline object types to multi-line — same rule as type aliases.\n // Only when there's no default and no nullable union (those can't split cleanly).\n if (!field.nullable && field.default === undefined) {\n const trailing = extractTrailingInlineObject(field.type);\n if (trailing) {\n const { prefix, inlineObj } = trailing;\n const modePart = inlineObj.mode ? `mode(${inlineObj.mode}) ` : '';\n const header = prefix\n ? `${indent}${field.name}${opt}: ${mods}${prefix} & ${modePart}{${comment}`\n : `${indent}${field.name}${opt}: ${mods}${modePart}{${comment}`;\n return [header, ...printInlineObjectExpanded(inlineObj, innerIndent, printWidth), `${indent}}`].join('\\n');\n }\n }\n\n let typeStr = printType(field.type);\n if (field.nullable) typeStr += ' | null';\n const fullLine = `${indent}${field.name}${opt}: ${mods}${typeStr}${def}${comment}`;\n if (field.type.kind === 'enum' && !field.nullable && field.default === undefined && fullLine.length > printWidth) {\n const enumStr = printEnumExpanded(field.type.values, indent);\n return `${indent}${field.name}${opt}: ${mods}${enumStr}${comment}`;\n }\n return fullLine;\n}\n\n/** Print inline-object fields expanded (used when an inline brace object trails a type alias). */\nexport function printInlineObjectExpanded(obj: InlineObjectTypeNode, indent: string, printWidth: number = 80): string[] {\n return obj.fields.map(f => printField(f, indent, printWidth));\n}\n\n// ─── Helpers ────────────────────────────────────────────────────────────────\n\n/** Format a single enum value: bare identifier stays bare; anything else gets double-quoted. */\nexport function formatEnumValue(v: string): string {\n if (/^[a-zA-Z_$][a-zA-Z0-9_$\\-.]*$/.test(v)) return v;\n return `\"${v}\"`;\n}\n\n/** Format a default value: quote strings that aren't valid bare identifiers. */\nexport function formatDefault(val: string | number | boolean): string {\n if (typeof val === 'number' || typeof val === 'boolean') return String(val);\n // If it looks like a bare identifier (enum value, unquoted token), keep it bare.\n if (/^[a-zA-Z_$][a-zA-Z0-9_$\\-.]*$/.test(val)) return val;\n return `\"${val}\"`;\n}\n\n/**\n * Detect whether the last member of a type is an inline brace object, and if so\n * return the prefix type string and the inline object for expanded printing.\n * Returns null if the type doesn't end with an inline object.\n */\nexport function extractTrailingInlineObject(type: ContractTypeNode): {\n prefix: string | null;\n inlineObj: InlineObjectTypeNode;\n} | null {\n if (type.kind === 'inlineObject') {\n return { prefix: null, inlineObj: type };\n }\n if (type.kind === 'intersection') {\n const last = type.members[type.members.length - 1];\n if (last?.kind === 'inlineObject') {\n const prefixStr = type.members.slice(0, -1).map(printType).join(' & ');\n return { prefix: prefixStr, inlineObj: last };\n }\n }\n return null;\n}\n","import type { ModelNode } from '@contractkit/core';\nimport { printField, printInlineObjectExpanded, extractTrailingInlineObject, printType, printEnumExpanded } from './print-type.js';\nimport { INDENT } from './indent.js';\n\n// ─── Model declaration ───────────────────────────────────────────────────────\n\nexport function printModelDecl(model: ModelNode, printWidth: number = 80): string {\n // Type alias form: Name : typeExpression\n if (model.type !== undefined) {\n return printTypeAlias(model, printWidth);\n }\n\n // Regular model with fields (possibly inherited)\n const commentSuffix = model.description ? ` # ${model.description}` : '';\n const modifiers = [\n model.deprecated ? 'deprecated' : '',\n model.inputCase || model.outputCase\n ? `format(${[model.inputCase ? `input=${model.inputCase}` : '', model.outputCase ? `output=${model.outputCase}` : ''].filter(Boolean).join(', ')})`\n : '',\n model.mode ? `mode(${model.mode})` : '',\n ]\n .filter(Boolean)\n .join(' ');\n const modePrefix = modifiers ? `${modifiers} ` : '';\n const baseChain = model.bases && model.bases.length > 0 ? `${model.bases.join(' & ')} & ` : '';\n const header = `${modePrefix}${model.name}: ${baseChain}{${commentSuffix}`;\n\n const lines: string[] = [header];\n for (const field of model.fields) {\n lines.push(printField(field, INDENT, printWidth));\n }\n lines.push('}');\n return lines.join('\\n');\n}\n\nfunction printTypeAlias(model: ModelNode, printWidth: number): string {\n const type = model.type!;\n const commentSuffix = model.description ? ` # ${model.description}` : '';\n const modifiers = [\n model.deprecated ? 'deprecated' : '',\n model.inputCase || model.outputCase\n ? `format(${[model.inputCase ? `input=${model.inputCase}` : '', model.outputCase ? `output=${model.outputCase}` : ''].filter(Boolean).join(', ')})`\n : '',\n model.mode ? `mode(${model.mode})` : '',\n ]\n .filter(Boolean)\n .join(' ');\n const modePrefix = modifiers ? `${modifiers} ` : '';\n\n // If the type ends with an inline brace object, expand it as a pseudo-model block.\n const trailing = extractTrailingInlineObject(type);\n if (trailing) {\n const { prefix, inlineObj } = trailing;\n const modePart = inlineObj.mode ? `mode(${inlineObj.mode}) ` : '';\n const header = prefix\n ? `${modePrefix}${model.name}: ${prefix} & ${modePart}{${commentSuffix}`\n : `${modePrefix}${model.name}: ${modePart}{${commentSuffix}`;\n const lines: string[] = [header, ...printInlineObjectExpanded(inlineObj, INDENT, printWidth), '}'];\n return lines.join('\\n');\n }\n\n // Simple type alias — single line, unless it's a long enum.\n // Note: the contract prefix \"contract \" (9 chars) is prepended by the caller.\n const singleLine = `${modePrefix}${model.name}: ${printType(type)}${commentSuffix}`;\n if (type.kind === 'enum' && 'contract '.length + singleLine.length > printWidth) {\n return `${modePrefix}${model.name}: ${printEnumExpanded(type.values, '')}${commentSuffix}`;\n }\n return singleLine;\n}\n","import type {\n OpRouteNode,\n OpOperationNode,\n OpResponseNode,\n ParamSource,\n SecurityNode,\n SecurityFields,\n ContractTypeNode,\n ObjectMode,\n PluginValue,\n} from '@contractkit/core';\nimport { SECURITY_NONE } from '@contractkit/core';\nimport { printType, formatDefault } from './print-type.js';\nimport { INDENT } from './indent.js';\n\nconst I1 = INDENT;\nconst I2 = INDENT.repeat(2);\nconst I3 = INDENT.repeat(3);\nconst I4 = INDENT.repeat(4);\n\n// ─── Orphan comment helpers ──────────────────────────────────────────────────\n\ntype CommentEntry = { line: number; text: string };\nexport type CommentBlock = { startLine: number; lines: string[] };\n\n/** Group sorted orphan comment entries into consecutive-line blocks. */\nexport function groupComments(entries: CommentEntry[]): CommentBlock[] {\n const blocks: CommentBlock[] = [];\n let current: CommentBlock | null = null;\n for (const { line, text } of entries) {\n if (current && line === current.startLine + current.lines.length) {\n current.lines.push(text);\n } else {\n if (current) blocks.push(current);\n current = { startLine: line, lines: [text] };\n }\n }\n if (current) blocks.push(current);\n return blocks;\n}\n\n/**\n * Emit any comment blocks whose startLine is < beforeLine.\n * Lines are emitted verbatim — they already carry their original indentation.\n */\nexport function flushBlocks(out: string[], blocks: CommentBlock[], idx: { value: number }, beforeLine: number, _indent = '') {\n while (idx.value < blocks.length && blocks[idx.value]!.startLine < beforeLine) {\n for (const l of blocks[idx.value]!.lines) out.push(l);\n idx.value++;\n }\n}\n\n// ─── Route ───────────────────────────────────────────────────────────────────\n\nexport function printRoute(route: OpRouteNode, blocks: CommentBlock[], idx: { value: number }, nextRouteStart: number): string {\n const lines: string[] = [];\n const commentSuffix = route.description ? ` # ${route.description}` : '';\n lines.push(`${route.path}: {${commentSuffix}`);\n\n if (route.params !== undefined) {\n lines.push(...printParamsBlock(route.params, I1, route.paramsMode));\n }\n\n if (route.security !== undefined) {\n lines.push(...printSecurity(route.security, I1, I2));\n }\n\n for (const op of route.operations) {\n // Flush comment blocks that appear before this operation (inside the route)\n flushBlocks(lines, blocks, idx, op.loc.line, I1);\n lines.push(...printOperation(op));\n }\n\n // Flush comment blocks between last operation and the next route\n flushBlocks(lines, blocks, idx, nextRouteStart, I1);\n\n lines.push('}');\n return lines.join('\\n');\n}\n\n// ─── Params block ────────────────────────────────────────────────────────────\n\nfunction printParamsBlock(source: ParamSource, indent: string, mode?: ObjectMode): string[] {\n const prefix = mode ? `mode(${mode}) ` : '';\n if (source.kind === 'ref') {\n return [`${indent}${prefix}params: ${source.name}`];\n }\n if (source.kind === 'params') {\n const lines: string[] = [`${indent}${prefix}params: {`];\n const inner = indent + INDENT;\n for (const p of source.nodes) {\n const opt = p.optional ? '?' : '';\n let t = printType(p.type);\n if (p.nullable) t += ' | null';\n const def = p.default !== undefined ? ` = ${formatDefault(p.default)}` : '';\n const comment = p.description ? ` # ${p.description}` : '';\n lines.push(`${inner}${p.name}${opt}: ${t}${def}${comment}`);\n }\n lines.push(`${indent}}`);\n return lines;\n }\n // ContractTypeNode\n return [`${indent}${prefix}params: ${printType(source.node)}`];\n}\n\n// ─── HTTP operation ──────────────────────────────────────────────────────────\n\nfunction printOperation(op: OpOperationNode): string[] {\n const lines: string[] = [];\n const commentSuffix = op.description ? ` # ${op.description}` : '';\n const modPart = op.modifiers?.length ? `(${op.modifiers[0]})` : '';\n lines.push(`${I1}${op.method}${modPart}: {${commentSuffix}`);\n\n if (op.name) lines.push(`${I2}name: ${op.name}`);\n if (op.service) lines.push(`${I2}service: ${op.service}`);\n if (op.sdk) lines.push(`${I2}sdk: ${op.sdk}`);\n if (op.signature) {\n const comment = op.signatureDescription ? ` # ${op.signatureDescription}` : '';\n if (op.signaturePolicy) {\n lines.push(`${I2}signature: {`);\n lines.push(`${I3}options: ${formatSignatureValue(op.signature)}${comment}`);\n lines.push(`${I3}policy: ${op.signaturePolicy}`);\n lines.push(`${I2}}`);\n } else {\n lines.push(`${I2}signature: ${formatSignatureValue(op.signature)}${comment}`);\n }\n }\n if (op.security !== undefined) lines.push(...printSecurity(op.security));\n if (op.plugins && Object.keys(op.plugins).length > 0) {\n lines.push(`${I2}plugins: {`);\n for (const [key, val] of Object.entries(op.plugins)) {\n lines.push(...printPluginEntry(key, val, I3));\n }\n lines.push(`${I2}}`);\n }\n if (op.query !== undefined) lines.push(...printQueryOrHeaders('query', op.query, op.queryMode));\n if (op.requestHeadersOptOut) {\n lines.push(`${I2}headers: none`);\n } else if (op.headers !== undefined) {\n lines.push(...printQueryOrHeaders('headers', op.headers, op.headersMode));\n }\n if (op.request) {\n lines.push(`${I2}request: {`);\n for (const body of op.request.bodies) {\n lines.push(...printContentTypeLine(body.contentType, body.bodyType, I3));\n }\n lines.push(`${I2}}`);\n }\n if (op.responses.length > 0) {\n lines.push(...printResponseBlock(op.responses));\n }\n\n lines.push(`${I1}}`);\n return lines;\n}\n\n// ─── Plugins block ───────────────────────────────────────────────────────────\n\nconst IDENT_RE = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;\n\nfunction escapeString(s: string): string {\n return s.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"');\n}\n\nfunction printPluginEntry(key: string, value: PluginValue, indent: string): string[] {\n const lines: string[] = [];\n const inline = printPluginInline(value);\n if (inline !== null) {\n lines.push(`${indent}${key}: ${inline}`);\n } else {\n const head = `${indent}${key}: `;\n const block = printPluginBlock(value, indent);\n lines.push(`${head}${block[0]!.trimStart()}`);\n for (let i = 1; i < block.length; i++) lines.push(block[i]!);\n }\n return lines;\n}\n\nfunction printPluginInline(value: PluginValue): string | null {\n if (typeof value === 'string') return `\"${escapeString(value)}\"`;\n if (typeof value === 'number' || typeof value === 'boolean') return String(value);\n if (value === null) return 'null';\n if (Array.isArray(value) && value.length === 0) return '[]';\n if (!Array.isArray(value) && typeof value === 'object' && Object.keys(value).length === 0) return '{}';\n return null;\n}\n\nfunction printPluginBlock(value: PluginValue, indent: string): string[] {\n const inner = indent + INDENT;\n const lines: string[] = [];\n if (Array.isArray(value)) {\n lines.push(`${indent}[`);\n for (const item of value) {\n const inline = printPluginInline(item);\n if (inline !== null) {\n lines.push(`${inner}${inline}`);\n } else {\n const block = printPluginBlock(item, inner);\n for (const l of block) lines.push(l);\n }\n }\n lines.push(`${indent}]`);\n return lines;\n }\n if (typeof value === 'object' && value !== null) {\n lines.push(`${indent}{`);\n for (const [k, v] of Object.entries(value)) {\n const fieldKey = IDENT_RE.test(k) ? k : `\"${escapeString(k)}\"`;\n const inline = printPluginInline(v);\n if (inline !== null) {\n lines.push(`${inner}${fieldKey}: ${inline}`);\n } else {\n const block = printPluginBlock(v, inner);\n lines.push(`${inner}${fieldKey}: ${block[0]!.trimStart()}`);\n for (let i = 1; i < block.length; i++) lines.push(block[i]!);\n }\n }\n lines.push(`${indent}}`);\n return lines;\n }\n // Scalars are always inline; printPluginInline already handles them.\n return [`${indent}${printPluginInline(value)}`];\n}\n\n// ─── Security ────────────────────────────────────────────────────────────────\n\n/** Print a signature key: unquoted when it's a plain identifier, quoted otherwise. */\nfunction formatSignatureValue(value: string): string {\n return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(value) ? value : `\"${value}\"`;\n}\n\n/**\n * Print a `security:` declaration. Returns `[\"${indent}security: none\"]` for the public-endpoint\n * sentinel, a multi-line block when `policy` is set, or an empty array when there's nothing\n * meaningful to emit.\n *\n * @param indent indentation for the `security` keyword line\n * @param innerIndent indentation for field lines inside the block\n */\nexport function printSecurity(security: SecurityNode, indent = I2, innerIndent = I3): string[] {\n if (security === SECURITY_NONE) return [`${indent}security: none`];\n const fields = security as SecurityFields;\n if (fields.policy === undefined) return [];\n const lines = [`${indent}security: {`];\n const comment = fields.policyDescription ? ` # ${fields.policyDescription}` : '';\n const value = fields.policy === false ? 'none' : fields.policy;\n lines.push(`${innerIndent}policy: ${value}${comment}`);\n lines.push(`${indent}}`);\n return lines;\n}\n\n// ─── Query / headers ─────────────────────────────────────────────────────────\n\nfunction printQueryOrHeaders(keyword: 'query' | 'headers', source: ParamSource, mode?: ObjectMode): string[] {\n const prefix = mode ? `mode(${mode}) ` : '';\n if (source.kind === 'ref') {\n return [`${I2}${prefix}${keyword}: ${source.name}`];\n }\n if (source.kind === 'params') {\n if (source.nodes.length === 0) return [];\n const lines: string[] = [`${I2}${prefix}${keyword}: {`];\n for (const p of source.nodes) {\n const opt = p.optional ? '?' : '';\n let t = printType(p.type);\n if (p.nullable) t += ' | null';\n const def = p.default !== undefined ? ` = ${formatDefault(p.default)}` : '';\n const comment = p.description ? ` # ${p.description}` : '';\n lines.push(`${I3}${p.name}${opt}: ${t}${def}${comment}`);\n }\n lines.push(`${I2}}`);\n return lines;\n }\n // ContractTypeNode (e.g. intersection)\n return [`${I2}${prefix}${keyword}: ${printType(source.node)}`];\n}\n\n// ─── Content-type line ───────────────────────────────────────────────────────\n\n/** Print a `contentType: bodyType` line, expanding inline brace objects onto separate lines. */\nfunction printContentTypeLine(contentType: string, bodyType: ContractTypeNode, lineIndent: string): string[] {\n if (bodyType.kind === 'inlineObject') {\n const fieldIndent = lineIndent + INDENT;\n const lines: string[] = [`${lineIndent}${contentType}: {`];\n for (const f of bodyType.fields) {\n const opt = f.optional ? '?' : '';\n let t = printType(f.type);\n if (f.nullable) t += ' | null';\n const def = f.default !== undefined ? ` = ${formatDefault(f.default)}` : '';\n const comment = f.description ? ` # ${f.description}` : '';\n lines.push(`${fieldIndent}${f.name}${opt}: ${t}${def}${comment}`);\n }\n lines.push(`${lineIndent}}`);\n return lines;\n }\n return [`${lineIndent}${contentType}: ${printType(bodyType)}`];\n}\n\n// ─── Response block ──────────────────────────────────────────────────────────\n\nfunction printResponseBlock(responses: OpResponseNode[]): string[] {\n const lines: string[] = [`${I2}response: {`];\n\n for (const resp of responses) {\n const hasBody = resp.contentType && resp.bodyType;\n const hasHeaders = resp.headers && resp.headers.length > 0;\n const optOut = resp.headersOptOut;\n if (hasBody || hasHeaders || optOut) {\n lines.push(`${I3}${resp.statusCode}: {`);\n if (hasBody) {\n lines.push(...printContentTypeLine(resp.contentType!, resp.bodyType!, I4));\n }\n if (optOut) {\n lines.push(`${I4}headers: none`);\n } else if (hasHeaders) {\n lines.push(`${I4}headers: {`);\n for (const h of resp.headers!) {\n const opt = h.optional ? '?' : '';\n const trail = h.description ? ` # ${h.description}` : '';\n lines.push(`${I4}${INDENT}${h.name}${opt}: ${printType(h.type)}${trail}`);\n }\n lines.push(`${I4}}`);\n }\n lines.push(`${I3}}`);\n } else {\n lines.push(`${I3}${resp.statusCode}:`);\n }\n }\n\n lines.push(`${I2}}`);\n return lines;\n}\n","import type { CkRootNode, OpResponseHeaderNode } from '@contractkit/core';\nimport { printModelDecl } from './print-contract.js';\nimport { printRoute, printSecurity, type CommentBlock } from './print-operation.js';\nimport { printType } from './print-type.js';\nimport { INDENT } from './indent.js';\n\nexport const DEFAULT_PRINT_WIDTH = 80;\n\n// ─── Options block ──────────────────────────────────────────────────────────\n\n/**\n * Quote an options-block value if it isn't a plain identifier.\n *\n * Plain identifiers (starts with letter/underscore/dollar, rest are\n * alphanumeric/underscore/dollar/hyphen/dot) are left bare. Everything\n * else — paths with slashes, values starting with `#`, values with spaces,\n * etc. — is double-quoted so the round-trip parse is unambiguous.\n */\nfunction quoteOptionsValue(value: string): string {\n return /^[a-zA-Z_$][a-zA-Z0-9_$\\-.]*$/.test(value) ? value : `\"${value}\"`;\n}\n\nfunction printOptionsBlock(ast: CkRootNode): string | null {\n const hasMeta = Object.keys(ast.meta).length > 0;\n const hasServices = Object.keys(ast.services).length > 0;\n const hasSecurity = ast.security !== undefined;\n const hasRequestHeaders = (ast.requestHeaders?.length ?? 0) > 0;\n const hasResponseHeaders = (ast.responseHeaders?.length ?? 0) > 0;\n\n if (!hasMeta && !hasServices && !hasSecurity && !hasRequestHeaders && !hasResponseHeaders) return null;\n\n const lines: string[] = ['options {'];\n\n if (hasMeta) {\n lines.push(`${INDENT}keys: {`);\n for (const [key, value] of Object.entries(ast.meta)) {\n lines.push(`${INDENT}${INDENT}${key}: ${quoteOptionsValue(value)}`);\n }\n lines.push(`${INDENT}}`);\n }\n\n if (hasServices) {\n lines.push(`${INDENT}services: {`);\n for (const [key, value] of Object.entries(ast.services)) {\n lines.push(`${INDENT}${INDENT}${key}: ${quoteOptionsValue(value)}`);\n }\n lines.push(`${INDENT}}`);\n }\n\n if (hasRequestHeaders) {\n lines.push(...printOptionsHeaderScope('request', ast.requestHeaders!));\n }\n\n if (hasResponseHeaders) {\n lines.push(...printOptionsHeaderScope('response', ast.responseHeaders!));\n }\n\n if (hasSecurity) {\n lines.push(...printSecurity(ast.security!, INDENT, INDENT + INDENT));\n }\n\n lines.push('}');\n return lines.join('\\n');\n}\n\nfunction printOptionsHeaderScope(keyword: 'request' | 'response', headers: OpResponseHeaderNode[]): string[] {\n const I2 = INDENT + INDENT;\n const I3 = INDENT + INDENT + INDENT;\n const lines = [`${INDENT}${keyword}: {`, `${I2}headers: {`];\n for (const h of headers) {\n const opt = h.optional ? '?' : '';\n const trail = h.description ? ` # ${h.description}` : '';\n lines.push(`${I3}${h.name}${opt}: ${printType(h.type)}${trail}`);\n }\n lines.push(`${I2}}`);\n lines.push(`${INDENT}}`);\n return lines;\n}\n\n// ─── CK file printer ───────────────────────────────────────────────────────\n\n/**\n * Render a parsed `.ck` AST back to source. Output is byte-identical on\n * round-trip when the input is already canonically formatted: options block\n * first, then contracts, then operations, separated by blank lines.\n *\n * `printWidth` is forwarded to per-model printing for line wrapping inside\n * inline-object types.\n */\nexport function printCk(ast: CkRootNode, printWidth: number = DEFAULT_PRINT_WIDTH): string {\n const parts: string[] = [];\n\n // Options block\n const options = printOptionsBlock(ast);\n if (options) parts.push(options);\n\n // Contracts (models)\n for (const model of ast.models) {\n if (parts.length > 0) parts.push('');\n parts.push(`contract ${printModelDecl(model, printWidth)}`);\n }\n\n // Operations (routes)\n const emptyBlocks: CommentBlock[] = [];\n const emptyIdx = { value: 0 };\n for (const route of ast.routes) {\n if (parts.length > 0) parts.push('');\n const modPart = route.modifiers?.length ? `(${route.modifiers[0]})` : '';\n parts.push(`operation${modPart} ${printRoute(route, emptyBlocks, emptyIdx, Infinity)}`);\n }\n\n return parts.join('\\n') + '\\n';\n}\n"],"mappings":";;;;AACA,SAASA,gBAAgB;AACzB,SAASC,SAASC,2BAA2B;;;ACFtC,IAAMC,SAAS;;;ACMf,SAASC,UAAUC,MAAsB;AAC5C,UAAQA,KAAKC,MAAI;IACb,KAAK,UAAU;AACX,YAAMC,cAAwB,CAAA;AAC9B,UAAIF,KAAKG,WAAWC,QAAW;AAE3B,cAAMC,MAAML,KAAKG;AACjBD,oBAAYI,KAAK,sBAAsBC,KAAKF,GAAAA,IAAOA,MAAM,IAAIA,GAAAA,GAAM;MACvE;AACA,UAAIL,KAAKQ,QAAQJ,OAAWF,aAAYI,KAAK,OAAON,KAAKQ,GAAG,EAAE;AAC9D,UAAIR,KAAKS,QAAQL,OAAWF,aAAYI,KAAK,OAAON,KAAKS,GAAG,EAAE;AAC9D,UAAIT,KAAKU,QAAQN,OAAWF,aAAYI,KAAK,OAAON,KAAKU,GAAG,EAAE;AAC9D,UAAIV,KAAKW,UAAUP,OAAWF,aAAYI,KAAK,UAAUN,KAAKW,KAAK,GAAG;AACtE,aAAOT,YAAYU,SAAS,IAAI,GAAGZ,KAAKa,IAAI,IAAIX,YAAYY,KAAK,IAAA,CAAA,MAAWd,KAAKa;IACrF;IACA,KAAK,SAAS;AACV,YAAME,OAAiB;QAAChB,UAAUC,KAAKgB,IAAI;;AAC3C,UAAIhB,KAAKQ,QAAQJ,OAAWW,MAAKT,KAAK,OAAON,KAAKQ,GAAG,EAAE;AACvD,UAAIR,KAAKS,QAAQL,OAAWW,MAAKT,KAAK,OAAON,KAAKS,GAAG,EAAE;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,eAAe;MACXC,MAAMC,MAAMC,SAAO;AACf,cAAMC,OAAOF,KAAKE;AAClB,eAAOxB,MAAMyB,QAAQD,MAAMD,QAAQG,UAAU,CAAA;MACjD;IACJ;EACJ;AACJ;AAEA,IAAA,gBAAerB;","names":["builders","parseCk","DiagnosticCollector","INDENT","printType","type","kind","constraints","format","undefined","fmt","push","test","min","max","len","regex","length","name","join","args","item","items","map","key","value","values","formatEnumValue","members","discriminator","printInlineObjectCompact","inner","obj","prefix","mode","fields","parts","f","opt","optional","t","nullable","printEnumExpanded","indent","innerIndent","INDENT","v","printField","field","printWidth","ovr","override","dep","deprecated","vis","visibility","mods","def","default","formatDefault","comment","description","trailing","extractTrailingInlineObject","inlineObj","modePart","header","printInlineObjectExpanded","typeStr","fullLine","enumStr","val","String","last","prefixStr","slice","printModelDecl","model","printWidth","type","undefined","printTypeAlias","commentSuffix","description","modifiers","deprecated","inputCase","outputCase","filter","Boolean","join","mode","modePrefix","baseChain","bases","length","header","name","lines","field","fields","push","printField","INDENT","trailing","extractTrailingInlineObject","prefix","inlineObj","modePart","printInlineObjectExpanded","singleLine","printType","kind","printEnumExpanded","values","SECURITY_NONE","I1","INDENT","I2","repeat","I3","I4","flushBlocks","out","blocks","idx","beforeLine","_indent","value","length","startLine","l","lines","push","printRoute","route","nextRouteStart","commentSuffix","description","path","params","undefined","printParamsBlock","I1","paramsMode","security","printSecurity","I2","op","operations","loc","line","printOperation","join","source","indent","mode","prefix","kind","name","inner","INDENT","p","nodes","opt","optional","t","printType","type","nullable","def","default","formatDefault","comment","node","modPart","modifiers","method","service","sdk","signature","signatureDescription","signaturePolicy","I3","formatSignatureValue","plugins","Object","keys","key","val","entries","printPluginEntry","query","printQueryOrHeaders","queryMode","requestHeadersOptOut","headers","headersMode","request","body","bodies","printContentTypeLine","contentType","bodyType","responses","printResponseBlock","IDENT_RE","escapeString","s","replace","inline","printPluginInline","head","block","printPluginBlock","trimStart","i","String","Array","isArray","item","k","v","fieldKey","test","innerIndent","SECURITY_NONE","fields","policy","policyDescription","keyword","lineIndent","fieldIndent","f","resp","hasBody","hasHeaders","optOut","headersOptOut","statusCode","I4","h","trail","DEFAULT_PRINT_WIDTH","quoteOptionsValue","value","test","printOptionsBlock","ast","hasMeta","Object","keys","meta","length","hasServices","services","hasSecurity","security","undefined","hasRequestHeaders","requestHeaders","hasResponseHeaders","responseHeaders","lines","push","INDENT","key","entries","printOptionsHeaderScope","printSecurity","join","keyword","headers","I2","I3","h","opt","optional","trail","description","name","printType","type","printCk","printWidth","parts","options","model","models","printModelDecl","emptyBlocks","emptyIdx","route","routes","modPart","modifiers","printRoute","Infinity","hardline","join","builders","toDoc","text","lines","trimEnd","split","plugin","languages","name","parsers","extensions","vscodeLanguageIds","parse","_options","diag","DiagnosticCollector","parseCk","astFormat","locStart","locEnd","_node","printers","print","path","options","node","printCk","printWidth"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/indent.ts","../src/print-type.ts","../src/print-contract.ts","../src/print-operation.ts","../src/print-ck.ts"],"sourcesContent":["import type { Plugin } from 'prettier';\nimport { builders } from 'prettier/doc';\nimport { parseCk, DiagnosticCollector } from '@contractkit/core';\nimport type { CkRootNode } from '@contractkit/core';\nimport { printCk } from './print-ck.js';\n\nconst { hardline, join } = builders;\n\nfunction toDoc(text: string) {\n const lines = text.trimEnd().split('\\n');\n return join(hardline, lines);\n}\n\nconst plugin: Plugin<CkRootNode> = {\n languages: [\n {\n name: 'ContractDSL',\n parsers: ['contract-ck'],\n extensions: ['.ck'],\n vscodeLanguageIds: ['contract-ck'],\n },\n ],\n\n parsers: {\n 'contract-ck': {\n parse(text, _options) {\n const diag = new DiagnosticCollector();\n return parseCk(text, '<stdin>', diag);\n },\n astFormat: 'contract-ck',\n locStart: () => 0,\n locEnd: _node => 0,\n },\n },\n\n printers: {\n 'contract-ck': {\n print(path, options) {\n const node = path.node as CkRootNode;\n return toDoc(printCk(node, options.printWidth));\n },\n },\n },\n};\n\nexport default plugin;\nexport { printCk, DEFAULT_PRINT_WIDTH } from './print-ck.js';\n","export const INDENT = ' ';\n","import type { ContractTypeNode, FieldNode, InlineObjectTypeNode } from '@contractkit/core';\nimport { INDENT } from './indent.js';\n\n// ─── Type expression printer ────────────────────────────────────────────────\n\n/** Render a `ContractTypeNode` back to its `.ck` source string. */\nexport function printType(type: ContractTypeNode): string {\n switch (type.kind) {\n case 'scalar': {\n const constraints: string[] = [];\n if (type.format !== undefined) {\n // Print unquoted when format contains only safe chars; quote otherwise\n const fmt = type.format;\n constraints.push(/^[a-zA-Z0-9\\-.:/]+$/.test(fmt) ? fmt : `\"${fmt}\"`);\n }\n if (type.min !== undefined) constraints.push(`min=${type.min}`);\n if (type.max !== undefined) constraints.push(`max=${type.max}`);\n if (type.len !== undefined) constraints.push(`len=${type.len}`);\n if (type.regex !== undefined) constraints.push(`regex=/${type.regex}/`);\n return constraints.length > 0 ? `${type.name}(${constraints.join(', ')})` : type.name;\n }\n case 'array': {\n const args: string[] = [printType(type.item)];\n if (type.min !== undefined) args.push(`min=${type.min}`);\n if (type.max !== undefined) args.push(`max=${type.max}`);\n return `array(${args.join(', ')})`;\n }\n case 'tuple':\n return `tuple(${type.items.map(printType).join(', ')})`;\n case 'record':\n return `record(${printType(type.key)}, ${printType(type.value)})`;\n case 'enum':\n return `enum(${type.values.map(formatEnumValue).join(', ')})`;\n case 'literal':\n return typeof type.value === 'string' ? `literal(\"${type.value}\")` : `literal(${type.value})`;\n case 'union':\n return type.members.map(printType).join(' | ');\n case 'discriminatedUnion':\n return `discriminated(by=${type.discriminator}, ${type.members.map(printType).join(' | ')})`;\n case 'intersection':\n return type.members.map(printType).join(' & ');\n case 'ref':\n return type.name;\n case 'inlineObject':\n return printInlineObjectCompact(type);\n case 'lazy':\n return `lazy(${printType(type.inner)})`;\n }\n}\n\n/** Compact single-line form — used when inline object appears nested inside another type. */\nfunction printInlineObjectCompact(obj: InlineObjectTypeNode): string {\n const prefix = obj.mode ? `mode(${obj.mode}) ` : '';\n if (obj.fields.length === 0) return `${prefix}{}`;\n const parts = obj.fields.map(f => {\n const opt = f.optional ? '?' : '';\n let t = printType(f.type);\n if (f.nullable) t += ' | null';\n return `${f.name}${opt}: ${t}`;\n });\n return `${prefix}{ ${parts.join(', ')} }`;\n}\n\n/** Multi-line enum form — one value per line, used when single-line would exceed print width. */\nexport function printEnumExpanded(values: string[], indent: string): string {\n const innerIndent = indent + INDENT;\n return `enum(\\n${values.map(v => `${innerIndent}${formatEnumValue(v)}`).join(',\\n')}\\n${indent})`;\n}\n\n// ─── Field printer ──────────────────────────────────────────────────────────\n\n/** Print a full field declaration, including visibility, default, and inline comment.\n * Modifier order is canonical: override → deprecated → readonly|writeonly → type. */\nexport function printField(field: FieldNode, indent: string, printWidth: number = 80): string {\n const opt = field.optional ? '?' : '';\n const ovr = field.override ? 'override ' : '';\n const dep = field.deprecated ? 'deprecated ' : '';\n const vis = field.visibility !== 'normal' ? `${field.visibility} ` : '';\n const mods = `${ovr}${dep}${vis}`;\n const def = field.default !== undefined ? ` = ${formatDefault(field.default)}` : '';\n const comment = field.description ? ` # ${field.description}` : '';\n const innerIndent = indent + INDENT;\n\n // Expand inline object types to multi-line — same rule as type aliases.\n // Only when there's no default and no nullable union (those can't split cleanly).\n if (!field.nullable && field.default === undefined) {\n const trailing = extractTrailingInlineObject(field.type);\n if (trailing) {\n const { prefix, inlineObj } = trailing;\n const modePart = inlineObj.mode ? `mode(${inlineObj.mode}) ` : '';\n const header = prefix\n ? `${indent}${field.name}${opt}: ${mods}${prefix} & ${modePart}{${comment}`\n : `${indent}${field.name}${opt}: ${mods}${modePart}{${comment}`;\n return [header, ...printInlineObjectExpanded(inlineObj, innerIndent, printWidth), `${indent}}`].join('\\n');\n }\n }\n\n let typeStr = printType(field.type);\n if (field.nullable) typeStr += ' | null';\n const fullLine = `${indent}${field.name}${opt}: ${mods}${typeStr}${def}${comment}`;\n if (field.type.kind === 'enum' && !field.nullable && field.default === undefined && fullLine.length > printWidth) {\n const enumStr = printEnumExpanded(field.type.values, indent);\n return `${indent}${field.name}${opt}: ${mods}${enumStr}${comment}`;\n }\n return fullLine;\n}\n\n/** Print inline-object fields expanded (used when an inline brace object trails a type alias).\n * Any `trailingComments` (comments after the last field, before `}`) are emitted as indented\n * `# text` lines after the fields, matching how model bodies round-trip trailing comments. */\nexport function printInlineObjectExpanded(obj: InlineObjectTypeNode, indent: string, printWidth: number = 80): string[] {\n const lines = obj.fields.map(f => printField(f, indent, printWidth));\n for (const comment of obj.trailingComments ?? []) {\n lines.push(`${indent}# ${comment}`);\n }\n return lines;\n}\n\n// ─── Helpers ────────────────────────────────────────────────────────────────\n\n/** Format a single enum value: bare identifier stays bare; anything else gets double-quoted. */\nexport function formatEnumValue(v: string): string {\n if (/^[a-zA-Z_$][a-zA-Z0-9_$\\-.]*$/.test(v)) return v;\n return `\"${v}\"`;\n}\n\n/** Format a default value: quote strings that aren't valid bare identifiers. */\nexport function formatDefault(val: string | number | boolean): string {\n if (typeof val === 'number' || typeof val === 'boolean') return String(val);\n // If it looks like a bare identifier (enum value, unquoted token), keep it bare.\n if (/^[a-zA-Z_$][a-zA-Z0-9_$\\-.]*$/.test(val)) return val;\n return `\"${val}\"`;\n}\n\n/**\n * Detect whether the last member of a type is an inline brace object, and if so\n * return the prefix type string and the inline object for expanded printing.\n * Returns null if the type doesn't end with an inline object.\n */\nexport function extractTrailingInlineObject(type: ContractTypeNode): {\n prefix: string | null;\n inlineObj: InlineObjectTypeNode;\n} | null {\n if (type.kind === 'inlineObject') {\n return { prefix: null, inlineObj: type };\n }\n if (type.kind === 'intersection') {\n const last = type.members[type.members.length - 1];\n if (last?.kind === 'inlineObject') {\n const prefixStr = type.members.slice(0, -1).map(printType).join(' & ');\n return { prefix: prefixStr, inlineObj: last };\n }\n }\n return null;\n}\n","import type { ModelNode } from '@contractkit/core';\nimport { printField, printInlineObjectExpanded, extractTrailingInlineObject, printType, printEnumExpanded } from './print-type.js';\nimport { INDENT } from './indent.js';\n\n// ─── Model declaration ───────────────────────────────────────────────────────\n\n/**\n * Render a `contract` body from its `Name: ...` onward (the `contract ` keyword is\n * prepended by the caller). Handles both the type-alias form (`Name: <type>`) and the\n * regular field-block form, including modifiers, base chain, and per-field printing.\n * Any `model.trailingComments` (comments after the last field, before `}`) are emitted\n * as indented `# text` lines so they round-trip.\n */\nexport function printModelDecl(model: ModelNode, printWidth: number = 80): string {\n // Type alias form: Name : typeExpression\n if (model.type !== undefined) {\n return printTypeAlias(model, printWidth);\n }\n\n // Regular model with fields (possibly inherited)\n const commentSuffix = model.description ? ` # ${model.description}` : '';\n const modifiers = [\n model.deprecated ? 'deprecated' : '',\n model.inputCase || model.outputCase\n ? `format(${[model.inputCase ? `input=${model.inputCase}` : '', model.outputCase ? `output=${model.outputCase}` : ''].filter(Boolean).join(', ')})`\n : '',\n model.mode ? `mode(${model.mode})` : '',\n ]\n .filter(Boolean)\n .join(' ');\n const modePrefix = modifiers ? `${modifiers} ` : '';\n const baseChain = model.bases && model.bases.length > 0 ? `${model.bases.join(' & ')} & ` : '';\n const header = `${modePrefix}${model.name}: ${baseChain}{${commentSuffix}`;\n\n const lines: string[] = [header];\n for (const field of model.fields) {\n lines.push(printField(field, INDENT, printWidth));\n }\n for (const comment of model.trailingComments ?? []) {\n lines.push(`${INDENT}# ${comment}`);\n }\n lines.push('}');\n return lines.join('\\n');\n}\n\nfunction printTypeAlias(model: ModelNode, printWidth: number): string {\n const type = model.type!;\n const commentSuffix = model.description ? ` # ${model.description}` : '';\n const modifiers = [\n model.deprecated ? 'deprecated' : '',\n model.inputCase || model.outputCase\n ? `format(${[model.inputCase ? `input=${model.inputCase}` : '', model.outputCase ? `output=${model.outputCase}` : ''].filter(Boolean).join(', ')})`\n : '',\n model.mode ? `mode(${model.mode})` : '',\n ]\n .filter(Boolean)\n .join(' ');\n const modePrefix = modifiers ? `${modifiers} ` : '';\n\n // If the type ends with an inline brace object, expand it as a pseudo-model block.\n const trailing = extractTrailingInlineObject(type);\n if (trailing) {\n const { prefix, inlineObj } = trailing;\n const modePart = inlineObj.mode ? `mode(${inlineObj.mode}) ` : '';\n const header = prefix\n ? `${modePrefix}${model.name}: ${prefix} & ${modePart}{${commentSuffix}`\n : `${modePrefix}${model.name}: ${modePart}{${commentSuffix}`;\n const lines: string[] = [header, ...printInlineObjectExpanded(inlineObj, INDENT, printWidth), '}'];\n return lines.join('\\n');\n }\n\n // Simple type alias — single line, unless it's a long enum.\n // Note: the contract prefix \"contract \" (9 chars) is prepended by the caller.\n const singleLine = `${modePrefix}${model.name}: ${printType(type)}${commentSuffix}`;\n if (type.kind === 'enum' && 'contract '.length + singleLine.length > printWidth) {\n return `${modePrefix}${model.name}: ${printEnumExpanded(type.values, '')}${commentSuffix}`;\n }\n return singleLine;\n}\n","import type {\n OpRouteNode,\n OpOperationNode,\n OpResponseNode,\n ParamSource,\n SecurityNode,\n SecurityFields,\n ContractTypeNode,\n ObjectMode,\n PluginValue,\n} from '@contractkit/core';\nimport { SECURITY_NONE } from '@contractkit/core';\nimport { printType, formatDefault } from './print-type.js';\nimport { INDENT } from './indent.js';\n\nconst I1 = INDENT;\nconst I2 = INDENT.repeat(2);\nconst I3 = INDENT.repeat(3);\nconst I4 = INDENT.repeat(4);\n\n// ─── Orphan comment helpers ──────────────────────────────────────────────────\n\ntype CommentEntry = { line: number; text: string };\n/** A run of consecutive-line orphan comments, keyed by the source line it starts on. */\nexport type CommentBlock = { startLine: number; lines: string[] };\n\n/** Group sorted orphan comment entries into consecutive-line blocks. */\nexport function groupComments(entries: CommentEntry[]): CommentBlock[] {\n const blocks: CommentBlock[] = [];\n let current: CommentBlock | null = null;\n for (const { line, text } of entries) {\n if (current && line === current.startLine + current.lines.length) {\n current.lines.push(text);\n } else {\n if (current) blocks.push(current);\n current = { startLine: line, lines: [text] };\n }\n }\n if (current) blocks.push(current);\n return blocks;\n}\n\n/**\n * Emit any comment blocks whose startLine is < beforeLine.\n * Lines are emitted verbatim — they already carry their original indentation.\n */\nexport function flushBlocks(out: string[], blocks: CommentBlock[], idx: { value: number }, beforeLine: number, _indent = '') {\n while (idx.value < blocks.length && blocks[idx.value]!.startLine < beforeLine) {\n for (const l of blocks[idx.value]!.lines) out.push(l);\n idx.value++;\n }\n}\n\n// ─── Route ───────────────────────────────────────────────────────────────────\n\n/**\n * Render an `operation` route body from its `path: {` onward (the `operation` keyword and\n * any modifier are prepended by the caller). Emits the params/security blocks and each HTTP\n * operation, interleaving orphan comment `blocks` at their original source positions — `idx`\n * tracks how far through `blocks` we've consumed, and `nextRouteStart` bounds the flush to\n * comments before the following route. Any `route.trailingComments` (comments after the last\n * operation, before `}`) are emitted before the closing brace so they round-trip.\n */\nexport function printRoute(route: OpRouteNode, blocks: CommentBlock[], idx: { value: number }, nextRouteStart: number): string {\n const lines: string[] = [];\n const commentSuffix = route.description ? ` # ${route.description}` : '';\n lines.push(`${route.path}: {${commentSuffix}`);\n\n if (route.params !== undefined) {\n lines.push(...printParamsBlock(route.params, I1, route.paramsMode));\n }\n\n if (route.security !== undefined) {\n lines.push(...printSecurity(route.security, I1, I2));\n }\n\n for (const op of route.operations) {\n // Flush comment blocks that appear before this operation (inside the route)\n flushBlocks(lines, blocks, idx, op.loc.line, I1);\n lines.push(...printOperation(op));\n }\n\n // Flush comment blocks between last operation and the next route\n flushBlocks(lines, blocks, idx, nextRouteStart, I1);\n\n // Trailing/orphan comments after the last operation, before the closing brace.\n for (const comment of route.trailingComments ?? []) {\n lines.push(`${I1}# ${comment}`);\n }\n\n lines.push('}');\n return lines.join('\\n');\n}\n\n// ─── Params block ────────────────────────────────────────────────────────────\n\nfunction printParamsBlock(source: ParamSource, indent: string, mode?: ObjectMode): string[] {\n const prefix = mode ? `mode(${mode}) ` : '';\n if (source.kind === 'ref') {\n return [`${indent}${prefix}params: ${source.name}`];\n }\n if (source.kind === 'params') {\n const lines: string[] = [`${indent}${prefix}params: {`];\n const inner = indent + INDENT;\n for (const p of source.nodes) {\n const opt = p.optional ? '?' : '';\n let t = printType(p.type);\n if (p.nullable) t += ' | null';\n const def = p.default !== undefined ? ` = ${formatDefault(p.default)}` : '';\n const comment = p.description ? ` # ${p.description}` : '';\n lines.push(`${inner}${p.name}${opt}: ${t}${def}${comment}`);\n }\n lines.push(`${indent}}`);\n return lines;\n }\n // ContractTypeNode\n return [`${indent}${prefix}params: ${printType(source.node)}`];\n}\n\n// ─── HTTP operation ──────────────────────────────────────────────────────────\n\nfunction printOperation(op: OpOperationNode): string[] {\n const lines: string[] = [];\n const commentSuffix = op.description ? ` # ${op.description}` : '';\n const modPart = op.modifiers?.length ? `(${op.modifiers[0]})` : '';\n lines.push(`${I1}${op.method}${modPart}: {${commentSuffix}`);\n\n if (op.name) lines.push(`${I2}name: ${op.name}`);\n if (op.service) lines.push(`${I2}service: ${op.service}`);\n if (op.sdk) lines.push(`${I2}sdk: ${op.sdk}`);\n if (op.signature) {\n const comment = op.signatureDescription ? ` # ${op.signatureDescription}` : '';\n if (op.signaturePolicy) {\n lines.push(`${I2}signature: {`);\n lines.push(`${I3}options: ${formatSignatureValue(op.signature)}${comment}`);\n lines.push(`${I3}policy: ${op.signaturePolicy}`);\n lines.push(`${I2}}`);\n } else {\n lines.push(`${I2}signature: ${formatSignatureValue(op.signature)}${comment}`);\n }\n }\n if (op.security !== undefined) lines.push(...printSecurity(op.security));\n if (op.plugins && Object.keys(op.plugins).length > 0) {\n lines.push(`${I2}plugins: {`);\n for (const [key, val] of Object.entries(op.plugins)) {\n lines.push(...printPluginEntry(key, val, I3));\n }\n lines.push(`${I2}}`);\n }\n if (op.query !== undefined) lines.push(...printQueryOrHeaders('query', op.query, op.queryMode));\n if (op.requestHeadersOptOut) {\n lines.push(`${I2}headers: none`);\n } else if (op.headers !== undefined) {\n lines.push(...printQueryOrHeaders('headers', op.headers, op.headersMode));\n }\n if (op.request) {\n lines.push(`${I2}request: {`);\n for (const body of op.request.bodies) {\n lines.push(...printContentTypeLine(body.contentType, body.bodyType, I3));\n }\n lines.push(`${I2}}`);\n }\n if (op.responses.length > 0) {\n lines.push(...printResponseBlock(op.responses));\n }\n\n lines.push(`${I1}}`);\n return lines;\n}\n\n// ─── Plugins block ───────────────────────────────────────────────────────────\n\nconst IDENT_RE = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;\n\nfunction escapeString(s: string): string {\n return s.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"');\n}\n\nfunction printPluginEntry(key: string, value: PluginValue, indent: string): string[] {\n const lines: string[] = [];\n const inline = printPluginInline(value);\n if (inline !== null) {\n lines.push(`${indent}${key}: ${inline}`);\n } else {\n const head = `${indent}${key}: `;\n const block = printPluginBlock(value, indent);\n lines.push(`${head}${block[0]!.trimStart()}`);\n for (let i = 1; i < block.length; i++) lines.push(block[i]!);\n }\n return lines;\n}\n\nfunction printPluginInline(value: PluginValue): string | null {\n if (typeof value === 'string') return `\"${escapeString(value)}\"`;\n if (typeof value === 'number' || typeof value === 'boolean') return String(value);\n if (value === null) return 'null';\n if (Array.isArray(value) && value.length === 0) return '[]';\n if (!Array.isArray(value) && typeof value === 'object' && Object.keys(value).length === 0) return '{}';\n return null;\n}\n\nfunction printPluginBlock(value: PluginValue, indent: string): string[] {\n const inner = indent + INDENT;\n const lines: string[] = [];\n if (Array.isArray(value)) {\n lines.push(`${indent}[`);\n for (const item of value) {\n const inline = printPluginInline(item);\n if (inline !== null) {\n lines.push(`${inner}${inline}`);\n } else {\n const block = printPluginBlock(item, inner);\n for (const l of block) lines.push(l);\n }\n }\n lines.push(`${indent}]`);\n return lines;\n }\n if (typeof value === 'object' && value !== null) {\n lines.push(`${indent}{`);\n for (const [k, v] of Object.entries(value)) {\n const fieldKey = IDENT_RE.test(k) ? k : `\"${escapeString(k)}\"`;\n const inline = printPluginInline(v);\n if (inline !== null) {\n lines.push(`${inner}${fieldKey}: ${inline}`);\n } else {\n const block = printPluginBlock(v, inner);\n lines.push(`${inner}${fieldKey}: ${block[0]!.trimStart()}`);\n for (let i = 1; i < block.length; i++) lines.push(block[i]!);\n }\n }\n lines.push(`${indent}}`);\n return lines;\n }\n // Scalars are always inline; printPluginInline already handles them.\n return [`${indent}${printPluginInline(value)}`];\n}\n\n// ─── Security ────────────────────────────────────────────────────────────────\n\n/** Print a signature key: unquoted when it's a plain identifier, quoted otherwise. */\nfunction formatSignatureValue(value: string): string {\n return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(value) ? value : `\"${value}\"`;\n}\n\n/**\n * Print a `security:` declaration. Returns `[\"${indent}security: none\"]` for the public-endpoint\n * sentinel, a multi-line block when `policy` is set, or an empty array when there's nothing\n * meaningful to emit.\n *\n * @param indent indentation for the `security` keyword line\n * @param innerIndent indentation for field lines inside the block\n */\nexport function printSecurity(security: SecurityNode, indent = I2, innerIndent = I3): string[] {\n if (security === SECURITY_NONE) return [`${indent}security: none`];\n const fields = security as SecurityFields;\n if (fields.policy === undefined) return [];\n const lines = [`${indent}security: {`];\n const comment = fields.policyDescription ? ` # ${fields.policyDescription}` : '';\n const value = fields.policy === false ? 'none' : fields.policy;\n lines.push(`${innerIndent}policy: ${value}${comment}`);\n lines.push(`${indent}}`);\n return lines;\n}\n\n// ─── Query / headers ─────────────────────────────────────────────────────────\n\nfunction printQueryOrHeaders(keyword: 'query' | 'headers', source: ParamSource, mode?: ObjectMode): string[] {\n const prefix = mode ? `mode(${mode}) ` : '';\n if (source.kind === 'ref') {\n return [`${I2}${prefix}${keyword}: ${source.name}`];\n }\n if (source.kind === 'params') {\n if (source.nodes.length === 0) return [];\n const lines: string[] = [`${I2}${prefix}${keyword}: {`];\n for (const p of source.nodes) {\n const opt = p.optional ? '?' : '';\n let t = printType(p.type);\n if (p.nullable) t += ' | null';\n const def = p.default !== undefined ? ` = ${formatDefault(p.default)}` : '';\n const comment = p.description ? ` # ${p.description}` : '';\n lines.push(`${I3}${p.name}${opt}: ${t}${def}${comment}`);\n }\n lines.push(`${I2}}`);\n return lines;\n }\n // ContractTypeNode (e.g. intersection)\n return [`${I2}${prefix}${keyword}: ${printType(source.node)}`];\n}\n\n// ─── Content-type line ───────────────────────────────────────────────────────\n\n/** Print a `contentType: bodyType` line, expanding inline brace objects onto separate lines. */\nfunction printContentTypeLine(contentType: string, bodyType: ContractTypeNode, lineIndent: string): string[] {\n if (bodyType.kind === 'inlineObject') {\n const fieldIndent = lineIndent + INDENT;\n const lines: string[] = [`${lineIndent}${contentType}: {`];\n for (const f of bodyType.fields) {\n const opt = f.optional ? '?' : '';\n let t = printType(f.type);\n if (f.nullable) t += ' | null';\n const def = f.default !== undefined ? ` = ${formatDefault(f.default)}` : '';\n const comment = f.description ? ` # ${f.description}` : '';\n lines.push(`${fieldIndent}${f.name}${opt}: ${t}${def}${comment}`);\n }\n lines.push(`${lineIndent}}`);\n return lines;\n }\n return [`${lineIndent}${contentType}: ${printType(bodyType)}`];\n}\n\n// ─── Response block ──────────────────────────────────────────────────────────\n\nfunction printResponseBlock(responses: OpResponseNode[]): string[] {\n const lines: string[] = [`${I2}response: {`];\n\n for (const resp of responses) {\n const hasBody = resp.contentType && resp.bodyType;\n const hasHeaders = resp.headers && resp.headers.length > 0;\n const optOut = resp.headersOptOut;\n if (hasBody || hasHeaders || optOut) {\n lines.push(`${I3}${resp.statusCode}: {`);\n if (hasBody) {\n lines.push(...printContentTypeLine(resp.contentType!, resp.bodyType!, I4));\n }\n if (optOut) {\n lines.push(`${I4}headers: none`);\n } else if (hasHeaders) {\n lines.push(`${I4}headers: {`);\n for (const h of resp.headers!) {\n const opt = h.optional ? '?' : '';\n const trail = h.description ? ` # ${h.description}` : '';\n lines.push(`${I4}${INDENT}${h.name}${opt}: ${printType(h.type)}${trail}`);\n }\n lines.push(`${I4}}`);\n }\n lines.push(`${I3}}`);\n } else {\n lines.push(`${I3}${resp.statusCode}:`);\n }\n }\n\n lines.push(`${I2}}`);\n return lines;\n}\n","import type { CkRootNode, OpResponseHeaderNode, OptionsScopeComments } from '@contractkit/core';\nimport { printModelDecl } from './print-contract.js';\nimport { printRoute, printSecurity, type CommentBlock } from './print-operation.js';\nimport { printType } from './print-type.js';\nimport { INDENT } from './indent.js';\n\n/** Default line width used for wrapping inline-object and enum types when none is supplied. */\nexport const DEFAULT_PRINT_WIDTH = 80;\n\n// ─── Options block ──────────────────────────────────────────────────────────\n\n/**\n * Quote an options-block value if it isn't a plain identifier.\n *\n * Plain identifiers (starts with letter/underscore/dollar, rest are\n * alphanumeric/underscore/dollar/hyphen/dot) are left bare. Everything\n * else — paths with slashes, values starting with `#`, values with spaces,\n * etc. — is double-quoted so the round-trip parse is unambiguous.\n */\nfunction quoteOptionsValue(value: string): string {\n return /^[a-zA-Z_$][a-zA-Z0-9_$\\-.]*$/.test(value) ? value : `\"${value}\"`;\n}\n\n/**\n * Emit the `key: value` lines of an options `keys`/`services` sub-block, interleaving any\n * retained comments: leading comments before the entry they precede, and trailing comments\n * after the last entry (before the closing `}`). Keeps comments inside these sub-blocks lossless.\n */\nfunction emitOptionsEntries(lines: string[], entries: Record<string, string>, comments: OptionsScopeComments | undefined): void {\n const I2 = INDENT + INDENT;\n for (const [key, value] of Object.entries(entries)) {\n for (const c of comments?.leading?.[key] ?? []) lines.push(`${I2}# ${c}`);\n lines.push(`${I2}${key}: ${quoteOptionsValue(value)}`);\n }\n for (const c of comments?.trailing ?? []) lines.push(`${I2}# ${c}`);\n}\n\nfunction printOptionsBlock(ast: CkRootNode): string | null {\n const hasMeta = Object.keys(ast.meta).length > 0;\n const hasServices = Object.keys(ast.services).length > 0;\n const hasSecurity = ast.security !== undefined;\n const hasRequestHeaders = (ast.requestHeaders?.length ?? 0) > 0;\n const hasResponseHeaders = (ast.responseHeaders?.length ?? 0) > 0;\n\n if (!hasMeta && !hasServices && !hasSecurity && !hasRequestHeaders && !hasResponseHeaders) return null;\n\n const lines: string[] = ['options {'];\n\n if (hasMeta) {\n lines.push(`${INDENT}keys: {`);\n emitOptionsEntries(lines, ast.meta, ast.optionsComments?.keys);\n lines.push(`${INDENT}}`);\n }\n\n if (hasServices) {\n lines.push(`${INDENT}services: {`);\n emitOptionsEntries(lines, ast.services, ast.optionsComments?.services);\n lines.push(`${INDENT}}`);\n }\n\n if (hasRequestHeaders) {\n lines.push(...printOptionsHeaderScope('request', ast.requestHeaders!));\n }\n\n if (hasResponseHeaders) {\n lines.push(...printOptionsHeaderScope('response', ast.responseHeaders!));\n }\n\n if (hasSecurity) {\n lines.push(...printSecurity(ast.security!, INDENT, INDENT + INDENT));\n }\n\n lines.push('}');\n return lines.join('\\n');\n}\n\nfunction printOptionsHeaderScope(keyword: 'request' | 'response', headers: OpResponseHeaderNode[]): string[] {\n const I2 = INDENT + INDENT;\n const I3 = INDENT + INDENT + INDENT;\n const lines = [`${INDENT}${keyword}: {`, `${I2}headers: {`];\n for (const h of headers) {\n const opt = h.optional ? '?' : '';\n const trail = h.description ? ` # ${h.description}` : '';\n lines.push(`${I3}${h.name}${opt}: ${printType(h.type)}${trail}`);\n }\n lines.push(`${I2}}`);\n lines.push(`${INDENT}}`);\n return lines;\n}\n\n// ─── CK file printer ───────────────────────────────────────────────────────\n\n/**\n * Render a parsed `.ck` AST back to source. Output is byte-identical on\n * round-trip when the input is already canonically formatted: options block\n * first, then contracts, then operations, separated by blank lines.\n *\n * `printWidth` is forwarded to per-model printing for line wrapping inside\n * inline-object types.\n */\nexport function printCk(ast: CkRootNode, printWidth: number = DEFAULT_PRINT_WIDTH): string {\n const parts: string[] = [];\n\n // Options block\n const options = printOptionsBlock(ast);\n if (options) parts.push(options);\n\n // Contracts (models)\n for (const model of ast.models) {\n if (parts.length > 0) parts.push('');\n parts.push(`contract ${printModelDecl(model, printWidth)}`);\n }\n\n // Operations (routes)\n const emptyBlocks: CommentBlock[] = [];\n const emptyIdx = { value: 0 };\n for (const route of ast.routes) {\n if (parts.length > 0) parts.push('');\n const modPart = route.modifiers?.length ? `(${route.modifiers[0]})` : '';\n parts.push(`operation${modPart} ${printRoute(route, emptyBlocks, emptyIdx, Infinity)}`);\n }\n\n return parts.join('\\n') + '\\n';\n}\n"],"mappings":";;;;AACA,S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ACIC,MAAM;MACNC,SAAS;QAAC;;MACVC,YAAY;QAAC;;MACbC,mBAAmB;QAAC;;IACxB;;EAGJF,SAAS;IACL,eAAe;MACXG,MAAMV,MAAMW,UAAQ;AAChB,cAAMC,OAAO,IAAIC,oBAAAA;AACjB,eAAOC,QAAQd,MAAM,WAAWY,IAAAA;MACpC;MACAG,WAAW;MACXC,UAAU,6BAAM,GAAN;MACVC,QAAQC,wBAAAA,UAAS,GAATA;IACZ;EACJ;EAEAC,UAAU;IACN,eAAe;MACXC,MAAMC,MAAMC,SAAO;AACf,cAAMC,OAAOF,KAAKE;AAClB,eAAOxB,MAAMyB,QAAQD,MAAMD,QAAQG,UAAU,CAAA;MACjD;IACJ;EACJ;AACJ;AAEA,IAAA,gBAAerB;","names":["builders","parseCk","DiagnosticCollector","INDENT","printType","type","kind","constraints","format","undefined","fmt","push","test","min","max","len","regex","length","name","join","args","item","items","map","key","value","values","formatEnumValue","members","discriminator","printInlineObjectCompact","inner","obj","prefix","mode","fields","parts","f","opt","optional","t","nullable","printEnumExpanded","indent","innerIndent","INDENT","v","printField","field","printWidth","ovr","override","dep","deprecated","vis","visibility","mods","def","default","formatDefault","comment","description","trailing","extractTrailingInlineObject","inlineObj","modePart","header","printInlineObjectExpanded","typeStr","fullLine","enumStr","lines","trailingComments","val","String","last","prefixStr","slice","printModelDecl","model","printWidth","type","undefined","printTypeAlias","commentSuffix","description","modifiers","deprecated","inputCase","outputCase","filter","Boolean","join","mode","modePrefix","baseChain","bases","length","header","name","lines","field","fields","push","printField","INDENT","comment","trailingComments","trailing","extractTrailingInlineObject","prefix","inlineObj","modePart","printInlineObjectExpanded","singleLine","printType","kind","printEnumExpanded","values","SECURITY_NONE","I1","INDENT","I2","repeat","I3","I4","flushBlocks","out","blocks","idx","beforeLine","_indent","value","length","startLine","l","lines","push","printRoute","route","nextRouteStart","commentSuffix","description","path","params","undefined","printParamsBlock","I1","paramsMode","security","printSecurity","I2","op","operations","loc","line","printOperation","comment","trailingComments","join","source","indent","mode","prefix","kind","name","inner","INDENT","p","nodes","opt","optional","t","printType","type","nullable","def","default","formatDefault","node","modPart","modifiers","method","service","sdk","signature","signatureDescription","signaturePolicy","I3","formatSignatureValue","plugins","Object","keys","key","val","entries","printPluginEntry","query","printQueryOrHeaders","queryMode","requestHeadersOptOut","headers","headersMode","request","body","bodies","printContentTypeLine","contentType","bodyType","responses","printResponseBlock","IDENT_RE","escapeString","s","replace","inline","printPluginInline","head","block","printPluginBlock","trimStart","i","String","Array","isArray","item","k","v","fieldKey","test","innerIndent","SECURITY_NONE","fields","policy","policyDescription","keyword","lineIndent","fieldIndent","f","resp","hasBody","hasHeaders","optOut","headersOptOut","statusCode","I4","h","trail","DEFAULT_PRINT_WIDTH","quoteOptionsValue","value","test","emitOptionsEntries","lines","entries","comments","I2","INDENT","key","Object","c","leading","push","trailing","printOptionsBlock","ast","hasMeta","keys","meta","length","hasServices","services","hasSecurity","security","undefined","hasRequestHeaders","requestHeaders","hasResponseHeaders","responseHeaders","optionsComments","printOptionsHeaderScope","printSecurity","join","keyword","headers","I3","h","opt","optional","trail","description","name","printType","type","printCk","printWidth","parts","options","model","models","printModelDecl","emptyBlocks","emptyIdx","route","routes","modPart","modifiers","printRoute","Infinity","hardline","join","builders","toDoc","text","lines","trimEnd","split","plugin","languages","name","parsers","extensions","vscodeLanguageIds","parse","_options","diag","DiagnosticCollector","parseCk","astFormat","locStart","locEnd","_node","printers","print","path","options","node","printCk","printWidth"]}
|
package/dist/print-ck.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CkRootNode } from '@contractkit/core';
|
|
2
|
+
/** Default line width used for wrapping inline-object and enum types when none is supplied. */
|
|
2
3
|
export declare const DEFAULT_PRINT_WIDTH = 80;
|
|
3
4
|
/**
|
|
4
5
|
* Render a parsed `.ck` AST back to source. Output is byte-identical on
|
package/dist/print-ck.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"print-ck.d.ts","sourceRoot":"","sources":["../src/print-ck.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"print-ck.d.ts","sourceRoot":"","sources":["../src/print-ck.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA8C,MAAM,mBAAmB,CAAC;AAMhG,+FAA+F;AAC/F,eAAO,MAAM,mBAAmB,KAAK,CAAC;AAqFtC;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,UAAU,EAAE,UAAU,GAAE,MAA4B,GAAG,MAAM,CAuBzF"}
|
package/dist/print-contract.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import type { ModelNode } from '@contractkit/core';
|
|
2
|
+
/**
|
|
3
|
+
* Render a `contract` body from its `Name: ...` onward (the `contract ` keyword is
|
|
4
|
+
* prepended by the caller). Handles both the type-alias form (`Name: <type>`) and the
|
|
5
|
+
* regular field-block form, including modifiers, base chain, and per-field printing.
|
|
6
|
+
* Any `model.trailingComments` (comments after the last field, before `}`) are emitted
|
|
7
|
+
* as indented `# text` lines so they round-trip.
|
|
8
|
+
*/
|
|
2
9
|
export declare function printModelDecl(model: ModelNode, printWidth?: number): string;
|
|
3
10
|
//# sourceMappingURL=print-contract.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"print-contract.d.ts","sourceRoot":"","sources":["../src/print-contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAMnD,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,EAAE,UAAU,GAAE,MAAW,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"print-contract.d.ts","sourceRoot":"","sources":["../src/print-contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAMnD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,EAAE,UAAU,GAAE,MAAW,GAAG,MAAM,CA8BhF"}
|
|
@@ -3,6 +3,7 @@ type CommentEntry = {
|
|
|
3
3
|
line: number;
|
|
4
4
|
text: string;
|
|
5
5
|
};
|
|
6
|
+
/** A run of consecutive-line orphan comments, keyed by the source line it starts on. */
|
|
6
7
|
export type CommentBlock = {
|
|
7
8
|
startLine: number;
|
|
8
9
|
lines: string[];
|
|
@@ -16,6 +17,14 @@ export declare function groupComments(entries: CommentEntry[]): CommentBlock[];
|
|
|
16
17
|
export declare function flushBlocks(out: string[], blocks: CommentBlock[], idx: {
|
|
17
18
|
value: number;
|
|
18
19
|
}, beforeLine: number, _indent?: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* Render an `operation` route body from its `path: {` onward (the `operation` keyword and
|
|
22
|
+
* any modifier are prepended by the caller). Emits the params/security blocks and each HTTP
|
|
23
|
+
* operation, interleaving orphan comment `blocks` at their original source positions — `idx`
|
|
24
|
+
* tracks how far through `blocks` we've consumed, and `nextRouteStart` bounds the flush to
|
|
25
|
+
* comments before the following route. Any `route.trailingComments` (comments after the last
|
|
26
|
+
* operation, before `}`) are emitted before the closing brace so they round-trip.
|
|
27
|
+
*/
|
|
19
28
|
export declare function printRoute(route: OpRouteNode, blocks: CommentBlock[], idx: {
|
|
20
29
|
value: number;
|
|
21
30
|
}, nextRouteStart: number): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"print-operation.d.ts","sourceRoot":"","sources":["../src/print-operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,WAAW,EAIX,YAAY,EAKf,MAAM,mBAAmB,CAAC;AAY3B,KAAK,YAAY,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AACnD,MAAM,MAAM,YAAY,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;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AK,EAAE,MAAM,CAAA;CAAE,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CA6B7H;AAyJD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAK,EAAE,WAAW,SAAK,GAAG,MAAM,EAAE,CAU7F"}
|
package/dist/print-type.d.ts
CHANGED
|
@@ -6,7 +6,9 @@ export declare function printEnumExpanded(values: string[], indent: string): str
|
|
|
6
6
|
/** Print a full field declaration, including visibility, default, and inline comment.
|
|
7
7
|
* Modifier order is canonical: override → deprecated → readonly|writeonly → type. */
|
|
8
8
|
export declare function printField(field: FieldNode, indent: string, printWidth?: number): string;
|
|
9
|
-
/** Print inline-object fields expanded (used when an inline brace object trails a type alias).
|
|
9
|
+
/** Print inline-object fields expanded (used when an inline brace object trails a type alias).
|
|
10
|
+
* Any `trailingComments` (comments after the last field, before `}`) are emitted as indented
|
|
11
|
+
* `# text` lines after the fields, matching how model bodies round-trip trailing comments. */
|
|
10
12
|
export declare function printInlineObjectExpanded(obj: InlineObjectTypeNode, indent: string, printWidth?: number): string[];
|
|
11
13
|
/** Format a single enum value: bare identifier stays bare; anything else gets double-quoted. */
|
|
12
14
|
export declare function formatEnumValue(v: string): string;
|
package/dist/print-type.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"print-type.d.ts","sourceRoot":"","sources":["../src/print-type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAK3F,mEAAmE;AACnE,wBAAgB,SAAS,CAAC,IAAI,EAAE,gBAAgB,GAAG,MAAM,CA0CxD;AAeD,iGAAiG;AACjG,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAG1E;AAID;qFACqF;AACrF,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAE,MAAW,GAAG,MAAM,CAgC5F;AAED
|
|
1
|
+
{"version":3,"file":"print-type.d.ts","sourceRoot":"","sources":["../src/print-type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAK3F,mEAAmE;AACnE,wBAAgB,SAAS,CAAC,IAAI,EAAE,gBAAgB,GAAG,MAAM,CA0CxD;AAeD,iGAAiG;AACjG,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAG1E;AAID;qFACqF;AACrF,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAE,MAAW,GAAG,MAAM,CAgC5F;AAED;;8FAE8F;AAC9F,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAE,MAAW,GAAG,MAAM,EAAE,CAMtH;AAID,gGAAgG;AAChG,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAGjD;AAED,gFAAgF;AAChF,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAKpE;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,gBAAgB,GAAG;IACjE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,SAAS,EAAE,oBAAoB,CAAC;CACnC,GAAG,IAAI,CAYP"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contractkit/prettier-plugin",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
4
4
|
"description": "Prettier plugin for ContractKit DSL",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Marooned Software",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"prettier": "^3.0.0"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@contractkit/core": "0.
|
|
32
|
+
"@contractkit/core": "0.23.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"prettier": "^3.8.3",
|
package/src/print-ck.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { CkRootNode, OpResponseHeaderNode } from '@contractkit/core';
|
|
1
|
+
import type { CkRootNode, OpResponseHeaderNode, OptionsScopeComments } from '@contractkit/core';
|
|
2
2
|
import { printModelDecl } from './print-contract.js';
|
|
3
3
|
import { printRoute, printSecurity, type CommentBlock } from './print-operation.js';
|
|
4
4
|
import { printType } from './print-type.js';
|
|
5
5
|
import { INDENT } from './indent.js';
|
|
6
6
|
|
|
7
|
+
/** Default line width used for wrapping inline-object and enum types when none is supplied. */
|
|
7
8
|
export const DEFAULT_PRINT_WIDTH = 80;
|
|
8
9
|
|
|
9
10
|
// ─── Options block ──────────────────────────────────────────────────────────
|
|
@@ -20,6 +21,20 @@ function quoteOptionsValue(value: string): string {
|
|
|
20
21
|
return /^[a-zA-Z_$][a-zA-Z0-9_$\-.]*$/.test(value) ? value : `"${value}"`;
|
|
21
22
|
}
|
|
22
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Emit the `key: value` lines of an options `keys`/`services` sub-block, interleaving any
|
|
26
|
+
* retained comments: leading comments before the entry they precede, and trailing comments
|
|
27
|
+
* after the last entry (before the closing `}`). Keeps comments inside these sub-blocks lossless.
|
|
28
|
+
*/
|
|
29
|
+
function emitOptionsEntries(lines: string[], entries: Record<string, string>, comments: OptionsScopeComments | undefined): void {
|
|
30
|
+
const I2 = INDENT + INDENT;
|
|
31
|
+
for (const [key, value] of Object.entries(entries)) {
|
|
32
|
+
for (const c of comments?.leading?.[key] ?? []) lines.push(`${I2}# ${c}`);
|
|
33
|
+
lines.push(`${I2}${key}: ${quoteOptionsValue(value)}`);
|
|
34
|
+
}
|
|
35
|
+
for (const c of comments?.trailing ?? []) lines.push(`${I2}# ${c}`);
|
|
36
|
+
}
|
|
37
|
+
|
|
23
38
|
function printOptionsBlock(ast: CkRootNode): string | null {
|
|
24
39
|
const hasMeta = Object.keys(ast.meta).length > 0;
|
|
25
40
|
const hasServices = Object.keys(ast.services).length > 0;
|
|
@@ -33,17 +48,13 @@ function printOptionsBlock(ast: CkRootNode): string | null {
|
|
|
33
48
|
|
|
34
49
|
if (hasMeta) {
|
|
35
50
|
lines.push(`${INDENT}keys: {`);
|
|
36
|
-
|
|
37
|
-
lines.push(`${INDENT}${INDENT}${key}: ${quoteOptionsValue(value)}`);
|
|
38
|
-
}
|
|
51
|
+
emitOptionsEntries(lines, ast.meta, ast.optionsComments?.keys);
|
|
39
52
|
lines.push(`${INDENT}}`);
|
|
40
53
|
}
|
|
41
54
|
|
|
42
55
|
if (hasServices) {
|
|
43
56
|
lines.push(`${INDENT}services: {`);
|
|
44
|
-
|
|
45
|
-
lines.push(`${INDENT}${INDENT}${key}: ${quoteOptionsValue(value)}`);
|
|
46
|
-
}
|
|
57
|
+
emitOptionsEntries(lines, ast.services, ast.optionsComments?.services);
|
|
47
58
|
lines.push(`${INDENT}}`);
|
|
48
59
|
}
|
|
49
60
|
|
package/src/print-contract.ts
CHANGED
|
@@ -4,6 +4,13 @@ import { INDENT } from './indent.js';
|
|
|
4
4
|
|
|
5
5
|
// ─── Model declaration ───────────────────────────────────────────────────────
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Render a `contract` body from its `Name: ...` onward (the `contract ` keyword is
|
|
9
|
+
* prepended by the caller). Handles both the type-alias form (`Name: <type>`) and the
|
|
10
|
+
* regular field-block form, including modifiers, base chain, and per-field printing.
|
|
11
|
+
* Any `model.trailingComments` (comments after the last field, before `}`) are emitted
|
|
12
|
+
* as indented `# text` lines so they round-trip.
|
|
13
|
+
*/
|
|
7
14
|
export function printModelDecl(model: ModelNode, printWidth: number = 80): string {
|
|
8
15
|
// Type alias form: Name : typeExpression
|
|
9
16
|
if (model.type !== undefined) {
|
|
@@ -29,6 +36,9 @@ export function printModelDecl(model: ModelNode, printWidth: number = 80): strin
|
|
|
29
36
|
for (const field of model.fields) {
|
|
30
37
|
lines.push(printField(field, INDENT, printWidth));
|
|
31
38
|
}
|
|
39
|
+
for (const comment of model.trailingComments ?? []) {
|
|
40
|
+
lines.push(`${INDENT}# ${comment}`);
|
|
41
|
+
}
|
|
32
42
|
lines.push('}');
|
|
33
43
|
return lines.join('\n');
|
|
34
44
|
}
|