@pikku/openapi-parser 0.12.21 → 0.12.22
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/CHANGELOG.md +12 -0
- package/dist/codegen.js +32 -21
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @pikku/openapi-parser
|
|
2
2
|
|
|
3
|
+
## 0.12.22
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 17d8746: An addon generated with `pikku new addon --openapi` never built. Every function file declared its zod schemas next to an import of `#pikku/function`, and `pikku all` loads the file that declares a schema to convert it. At runtime `#pikku` resolves through the addon's `imports` into `dist/`, which the first build has not written yet, so every schema failed with `Could not convert Zod schema … Cannot find module …/dist/.pikku/function/index.js` and the build stopped there. Each operation's schemas now go in a sibling `<operation>.schemas.ts` that imports only zod, and the function file imports them from it.
|
|
8
|
+
|
|
9
|
+
The generated imports also named the wrong tree. An addon's generated code lives under `.pikku/addon/`, so `#pikku/function` and `#pikku/variables/…` pointed at leaves that do not exist, and `tsc` failed even once codegen had run. They are now `#pikku/addon/function` and `#pikku/addon/variables/…`, as the hand-written addon scaffold already had them.
|
|
10
|
+
|
|
11
|
+
`pikku validate` now reports an installed Pikku package that resolves a different copy of a type-identity package (`zod`, `kysely`, `@pikku/core`, `better-auth`) than the project as an error, `skewed-type-identity-…`, and the codegen preflight warns about it as `PKU719`. Under bun's isolated layout `@pikku/cli` can carry its own `zod` beside it in the store. Codegen then reads the app's schemas with a different zod than wrote them, and correct schemas fail to convert. The existing check only looked at dependencies linked from outside the project, so it never saw this case.
|
|
12
|
+
|
|
13
|
+
The `pikku-build` skill now recognises an OpenAPI spec or an n8n export handed over with the request, says so, converts it first, then carries on building the app. `pikku-addon` gains an OpenAPI reference and corrects its addon import paths and build steps. `pikku-n8n-import` joins the `core` install group.
|
|
14
|
+
|
|
3
15
|
## 0.12.21
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/codegen.js
CHANGED
|
@@ -281,8 +281,11 @@ export function generateAddonFromOpenAPI(spec, vars, flags) {
|
|
|
281
281
|
camelCase: flags.camelCase,
|
|
282
282
|
});
|
|
283
283
|
const inlineSchemas = singleSchemasPerOp.get(i) ?? new Set();
|
|
284
|
-
const
|
|
285
|
-
files[`src/functions/${named.functionName}.function.ts`] =
|
|
284
|
+
const { functionFile, schemasFile } = generateFunctionFile(named, parsed, vars, funcCtx, spec, flags, inlineSchemas, sharedWithDeps, schemaIdentityMap);
|
|
285
|
+
files[`src/functions/${named.functionName}.function.ts`] = functionFile;
|
|
286
|
+
if (schemasFile) {
|
|
287
|
+
files[`src/functions/${named.functionName}.schemas.ts`] = schemasFile;
|
|
288
|
+
}
|
|
286
289
|
functionExports.push(named.functionName);
|
|
287
290
|
}
|
|
288
291
|
// Delegated login: emit the upstream authenticate() implementation
|
|
@@ -516,14 +519,19 @@ function generateFunctionFile(named, parsed, vars, ctx, spec, flags, inlineSchem
|
|
|
516
519
|
}
|
|
517
520
|
// Determine error imports needed
|
|
518
521
|
const errorClasses = getErrorClassesForResponses(parsed.errorResponses);
|
|
519
|
-
const
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
lines.push("import { pikkuSessionlessFunc } from '#pikku/function'");
|
|
522
|
+
const schemaExports = [
|
|
523
|
+
...(hasInput && inputCode ? [inputName] : []),
|
|
524
|
+
...(parsed.responseSchema && outputCode ? [outputName] : []),
|
|
525
|
+
];
|
|
526
|
+
lines.push("import { pikkuSessionlessFunc } from '#pikku/addon/function'");
|
|
524
527
|
if (errorClasses.length > 0) {
|
|
525
528
|
lines.push(`import { ${errorClasses.join(', ')} } from '@pikku/core/errors'`);
|
|
526
529
|
}
|
|
530
|
+
if (schemaExports.length > 0) {
|
|
531
|
+
lines.push(`import { ${schemaExports.join(', ')} } from './${named.functionName}.schemas.js'`);
|
|
532
|
+
}
|
|
533
|
+
lines.push('');
|
|
534
|
+
const schemaLines = ["import { z } from 'zod'"];
|
|
527
535
|
// Import referenced component schemas from the types file.
|
|
528
536
|
// Only import schemas that are in the shared set (not inlined ones).
|
|
529
537
|
// In addition to the refs tracked through usedRefs, scan the generated Zod
|
|
@@ -543,10 +551,10 @@ function generateFunctionFile(named, parsed, vars, ctx, spec, flags, inlineSchem
|
|
|
543
551
|
.filter(Boolean)),
|
|
544
552
|
].sort();
|
|
545
553
|
if (schemaImports.length > 0) {
|
|
546
|
-
|
|
554
|
+
schemaLines.push(`import { ${schemaImports.join(', ')} } from '../${name}.types.js'`);
|
|
547
555
|
}
|
|
548
556
|
}
|
|
549
|
-
|
|
557
|
+
schemaLines.push('');
|
|
550
558
|
// Emit inline (single-use) schema definitions before input/output
|
|
551
559
|
if (inlineSchemas.size > 0) {
|
|
552
560
|
// Build a mini component schemas map for just the inline schemas
|
|
@@ -607,7 +615,7 @@ function generateFunctionFile(named, parsed, vars, ctx, spec, flags, inlineSchem
|
|
|
607
615
|
const emittedTypeNames = new Set();
|
|
608
616
|
// Forward declarations for cycles and forward references within inline schemas
|
|
609
617
|
if (forwardRefs.size > 0) {
|
|
610
|
-
|
|
618
|
+
schemaLines.push('// Forward declarations for circular references');
|
|
611
619
|
for (const sName of forwardRefs) {
|
|
612
620
|
if (!inlineSchemas.has(sName))
|
|
613
621
|
continue;
|
|
@@ -615,8 +623,8 @@ function generateFunctionFile(named, parsed, vars, ctx, spec, flags, inlineSchem
|
|
|
615
623
|
const typeN = sanitizeTypeName(sName);
|
|
616
624
|
emittedVarNames.add(varN);
|
|
617
625
|
emittedTypeNames.add(typeN);
|
|
618
|
-
|
|
619
|
-
|
|
626
|
+
schemaLines.push(`const ${varN}: z.ZodType<any> = z.lazy(() => _${varN})`);
|
|
627
|
+
schemaLines.push('');
|
|
620
628
|
}
|
|
621
629
|
}
|
|
622
630
|
for (const sName of inlineSorted) {
|
|
@@ -624,24 +632,24 @@ function generateFunctionFile(named, parsed, vars, ctx, spec, flags, inlineSchem
|
|
|
624
632
|
emittedVarNames.add(varN);
|
|
625
633
|
const zodCode = generatedCode.get(sName);
|
|
626
634
|
if (forwardRefs.has(sName)) {
|
|
627
|
-
|
|
635
|
+
schemaLines.push(`const _${varN} = ${zodCode}`);
|
|
628
636
|
}
|
|
629
637
|
else {
|
|
630
|
-
|
|
638
|
+
schemaLines.push(`const ${varN} = ${zodCode}`);
|
|
631
639
|
}
|
|
632
|
-
|
|
640
|
+
schemaLines.push('');
|
|
633
641
|
}
|
|
634
642
|
}
|
|
635
643
|
}
|
|
636
644
|
// Build Input schema (exported for pikku schema discovery)
|
|
637
645
|
if (hasInput && inputCode) {
|
|
638
|
-
|
|
639
|
-
|
|
646
|
+
schemaLines.push(`export const ${inputName} = ${inputCode}`);
|
|
647
|
+
schemaLines.push('');
|
|
640
648
|
}
|
|
641
649
|
// Build Output schema (exported for pikku schema discovery)
|
|
642
650
|
if (parsed.responseSchema && outputCode) {
|
|
643
|
-
|
|
644
|
-
|
|
651
|
+
schemaLines.push(`export const ${outputName} = ${outputCode}`);
|
|
652
|
+
schemaLines.push('');
|
|
645
653
|
}
|
|
646
654
|
const description = humanDescription(parsed);
|
|
647
655
|
const method = parsed.method.toUpperCase();
|
|
@@ -671,7 +679,10 @@ function generateFunctionFile(named, parsed, vars, ctx, spec, flags, inlineSchem
|
|
|
671
679
|
lines.push(funcConfig.join('\n'));
|
|
672
680
|
lines.push('})');
|
|
673
681
|
lines.push('');
|
|
674
|
-
return
|
|
682
|
+
return {
|
|
683
|
+
functionFile: lines.join('\n'),
|
|
684
|
+
schemasFile: schemaExports.length > 0 ? schemaLines.join('\n') : undefined,
|
|
685
|
+
};
|
|
675
686
|
}
|
|
676
687
|
function buildInputSchema(parsed, ctx) {
|
|
677
688
|
const props = [];
|
|
@@ -950,7 +961,7 @@ function generateServiceFile(spec, opPairs, vars, flags) {
|
|
|
950
961
|
if (allErrorClasses.size > 0) {
|
|
951
962
|
lines.push(`import { ${[...allErrorClasses].sort().join(', ')} } from '@pikku/core/errors'`);
|
|
952
963
|
}
|
|
953
|
-
lines.push(`import type { TypedVariablesService } from '#pikku/variables/pikku-variables.gen.js'`);
|
|
964
|
+
lines.push(`import type { TypedVariablesService } from '#pikku/addon/variables/pikku-variables.gen.js'`);
|
|
954
965
|
lines.push('');
|
|
955
966
|
// Generate route map from parsed operations
|
|
956
967
|
const routes = {};
|