@contractkit/plugin-typescript 0.25.4 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -25,6 +25,15 @@ export interface SdkConfig {
25
25
  clients?: string;
26
26
  };
27
27
  includeInternal?: boolean;
28
+ /**
29
+ * Emit a starter `package.json` and `tsconfig.json` at the SDK `baseDir` so the
30
+ * generated output is a buildable, publishable package on its own. Opt-in and
31
+ * write-once: the files are created only when absent and are never overwritten or
32
+ * cleaned up on later builds, so any edits you make to them are preserved.
33
+ * Dependency ranges are derived from the contracts (always `zod` when `zod: true`;
34
+ * `luxon` when any covered model uses a date/time/datetime/interval scalar).
35
+ */
36
+ scaffold?: boolean;
28
37
  }
29
38
  export interface ZodConfig {
30
39
  baseDir?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACR,iBAAiB,EAQpB,MAAM,mBAAmB,CAAC;AA0C3B,MAAM,WAAW,YAAY;IACzB,wFAAwF;IACxF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6HAA6H;IAC7H,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE;QACL,8EAA8E;QAC9E,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,+EAA+E;QAC/E,KAAK,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,wDAAwD;IACxD,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,wEAAwE;IACxE,eAAe,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,MAAM,WAAW,SAAS;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE;QACL,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,KAA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,MAAM,WAAW,SAAS;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE;QACL,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,SAAS;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,WAAW;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,sBAAsB;IACnC,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB,KAAK,CAAC,EAAE,WAAW,CAAC;CACvB;AAID,yGAAyG;AACzG,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAO9C,QAAA,MAAM,MAAM,EAAE,iBAMb,CAAC;AAEF,eAAe,MAAM,CAAC;AAEtB,2GAA2G;AAC3G,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM,GAAG,iBAAiB,CAOzG"}
package/dist/index.js CHANGED
@@ -1273,7 +1273,8 @@ function generateHandler(route, op, root, options) {
1273
1273
  middlewares.push(`bodyParserMiddleware([${tokensExpr}])`);
1274
1274
  }
1275
1275
  if (op.signature) {
1276
- middlewares.push(`requireSignature('${op.signature}')`);
1276
+ const sigArgs = op.signaturePolicy ? `'${op.signature}', { policy: '${op.signaturePolicy}' }` : `'${op.signature}'`;
1277
+ middlewares.push(`requireSignature(${sigArgs})`);
1277
1278
  }
1278
1279
  const middlewareStr = middlewares.length > 0 ? `, ${middlewares.join(", ")},` : ",";
1279
1280
  lines.push(`${deriveRouterName(file)}.${method}('${path}'${middlewareStr} async (ctx, next) => {`);
@@ -2589,6 +2590,71 @@ function generateSdkOptions() {
2589
2590
  ].join("\n");
2590
2591
  }
2591
2592
  __name(generateSdkOptions, "generateSdkOptions");
2593
+ var SCAFFOLD_DEP_VERSIONS = {
2594
+ zod: "^4.3.6",
2595
+ luxon: "^3.5.0",
2596
+ typesLuxon: "^3.4.2",
2597
+ typescript: "^6.0.3"
2598
+ };
2599
+ function generateSdkPackageJson(input) {
2600
+ const dependencies = {};
2601
+ if (input.deps.zod) dependencies.zod = SCAFFOLD_DEP_VERSIONS.zod;
2602
+ if (input.deps.luxon) dependencies.luxon = SCAFFOLD_DEP_VERSIONS.luxon;
2603
+ const devDependencies = {
2604
+ typescript: SCAFFOLD_DEP_VERSIONS.typescript
2605
+ };
2606
+ if (input.deps.luxon) devDependencies["@types/luxon"] = SCAFFOLD_DEP_VERSIONS.typesLuxon;
2607
+ const pkg = {
2608
+ name: input.name,
2609
+ version: "0.0.0",
2610
+ type: "module",
2611
+ main: "./dist/index.js",
2612
+ types: "./dist/index.d.ts",
2613
+ exports: {
2614
+ ".": {
2615
+ types: "./dist/index.d.ts",
2616
+ import: "./dist/index.js"
2617
+ }
2618
+ },
2619
+ files: [
2620
+ "dist"
2621
+ ],
2622
+ scripts: {
2623
+ build: "tsc -p tsconfig.json"
2624
+ },
2625
+ ...Object.keys(dependencies).length > 0 ? {
2626
+ dependencies
2627
+ } : {},
2628
+ devDependencies
2629
+ };
2630
+ return JSON.stringify(pkg, null, 4) + "\n";
2631
+ }
2632
+ __name(generateSdkPackageJson, "generateSdkPackageJson");
2633
+ function generateSdkTsconfig() {
2634
+ const tsconfig = {
2635
+ compilerOptions: {
2636
+ target: "ES2022",
2637
+ module: "NodeNext",
2638
+ moduleResolution: "NodeNext",
2639
+ declaration: true,
2640
+ outDir: "./dist",
2641
+ rootDir: "./src",
2642
+ strict: true,
2643
+ esModuleInterop: true,
2644
+ skipLibCheck: true,
2645
+ forceConsistentCasingInFileNames: true
2646
+ },
2647
+ include: [
2648
+ "src"
2649
+ ],
2650
+ exclude: [
2651
+ "dist",
2652
+ "node_modules"
2653
+ ]
2654
+ };
2655
+ return JSON.stringify(tsconfig, null, 4) + "\n";
2656
+ }
2657
+ __name(generateSdkTsconfig, "generateSdkTsconfig");
2592
2658
  function generateAreaClient(input) {
2593
2659
  const { area, outPath, inlineFiles, subareaClients, sdkOptionsPath } = input;
2594
2660
  const className = deriveAreaClientClassName(area);
@@ -3192,8 +3258,10 @@ async function runTypescriptCodegen(inputs, ctx, config, rootDir) {
3192
3258
  fileExists: existsSync
3193
3259
  });
3194
3260
  deleteStalePaths(result.deletedPaths);
3195
- for (const { relativePath, content } of result.filesToWrite) {
3196
- ctx.emitFile(relativePath, content);
3261
+ for (const { relativePath, content, ifAbsent } of result.filesToWrite) {
3262
+ ctx.emitFile(relativePath, content, ifAbsent ? {
3263
+ ifAbsent: true
3264
+ } : void 0);
3197
3265
  }
3198
3266
  writeManifest(manifestPath, result.manifest);
3199
3267
  }
@@ -3718,6 +3786,26 @@ function collectSdkOutput(config, rootDir, inputs, units, globalFiles) {
3718
3786
  ${rootExports.sort().join("\n")}
3719
3787
  `
3720
3788
  });
3789
+ if (config.scaffold) {
3790
+ const coveredRoots = sdkContractEntries.map((e) => e.ast);
3791
+ const deps = {
3792
+ zod: !!config.zod,
3793
+ luxon: coveredRoots.some((r) => rootNeedsScalar(r, "datetime") || rootNeedsScalar(r, "date") || rootNeedsScalar(r, "time") || rootNeedsScalar(r, "interval"))
3794
+ };
3795
+ globalFiles.push({
3796
+ relativePath: join2(sdkBase, "package.json"),
3797
+ content: generateSdkPackageJson({
3798
+ name: sdkName ?? "sdk",
3799
+ deps
3800
+ }),
3801
+ ifAbsent: true
3802
+ });
3803
+ globalFiles.push({
3804
+ relativePath: join2(sdkBase, "tsconfig.json"),
3805
+ content: generateSdkTsconfig(),
3806
+ ifAbsent: true
3807
+ });
3808
+ }
3721
3809
  }
3722
3810
  __name(collectSdkOutput, "collectSdkOutput");
3723
3811
  function collectZodOutput(config, rootDir, inputs, units) {