@jutsustack/api-codegen 0.1.0 → 0.2.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.
Files changed (199) hide show
  1. package/README.md +574 -141
  2. package/dist/cache/manifest.d.ts +0 -1
  3. package/dist/cache/manifest.d.ts.map +1 -1
  4. package/dist/cache/manifest.js +1 -1
  5. package/dist/cache/manifest.js.map +1 -1
  6. package/dist/cjs/cache/manifest.d.ts +34 -0
  7. package/dist/cjs/cache/manifest.js +45 -0
  8. package/dist/cjs/cli.d.ts +8 -0
  9. package/dist/cjs/cli.js +245 -0
  10. package/dist/cjs/codegen/emit-api.d.ts +6 -0
  11. package/dist/cjs/codegen/emit-api.js +108 -0
  12. package/dist/cjs/codegen/emit-bindings.d.ts +8 -0
  13. package/dist/cjs/codegen/emit-bindings.js +115 -0
  14. package/dist/cjs/codegen/emit-types.d.ts +10 -0
  15. package/dist/cjs/codegen/emit-types.js +232 -0
  16. package/dist/cjs/codegen/emit.d.ts +28 -0
  17. package/dist/cjs/codegen/emit.js +180 -0
  18. package/dist/cjs/codegen/files.d.ts +14 -0
  19. package/dist/cjs/codegen/files.js +66 -0
  20. package/dist/cjs/codegen/plan.d.ts +32 -0
  21. package/dist/cjs/codegen/plan.js +84 -0
  22. package/dist/cjs/codegen/print.d.ts +10 -0
  23. package/dist/cjs/codegen/print.js +65 -0
  24. package/dist/cjs/codegen/templates/bindings.d.ts +13 -0
  25. package/dist/cjs/codegen/templates/bindings.js +707 -0
  26. package/dist/cjs/codegen/templates/runtime.d.ts +2 -0
  27. package/dist/cjs/codegen/templates/runtime.js +1401 -0
  28. package/dist/cjs/codegen/templates/transports.d.ts +1 -0
  29. package/dist/cjs/codegen/templates/transports.js +272 -0
  30. package/dist/cjs/codegen/tsType.d.ts +15 -0
  31. package/dist/cjs/codegen/tsType.js +114 -0
  32. package/dist/cjs/collect/collect.d.ts +16 -0
  33. package/dist/cjs/collect/collect.js +472 -0
  34. package/dist/cjs/collect/naming.d.ts +25 -0
  35. package/dist/cjs/collect/naming.js +149 -0
  36. package/dist/cjs/collect/path.d.ts +10 -0
  37. package/dist/cjs/collect/path.js +67 -0
  38. package/dist/cjs/config/init.d.ts +37 -0
  39. package/dist/cjs/config/init.js +143 -0
  40. package/dist/cjs/config/load.d.ts +11 -0
  41. package/dist/cjs/config/load.js +121 -0
  42. package/dist/cjs/config/types.d.ts +88 -0
  43. package/dist/cjs/config/types.js +2 -0
  44. package/dist/cjs/config/validate.d.ts +8 -0
  45. package/dist/cjs/config/validate.js +200 -0
  46. package/dist/cjs/generate.d.ts +55 -0
  47. package/dist/cjs/generate.js +263 -0
  48. package/dist/cjs/index.d.ts +23 -0
  49. package/dist/cjs/index.js +48 -0
  50. package/dist/cjs/model/collection.d.ts +83 -0
  51. package/dist/cjs/model/collection.js +16 -0
  52. package/dist/cjs/model/infer.d.ts +7 -0
  53. package/dist/cjs/model/infer.js +95 -0
  54. package/dist/cjs/model/merge.d.ts +3 -0
  55. package/dist/cjs/model/merge.js +131 -0
  56. package/dist/cjs/model/reserved.d.ts +2 -0
  57. package/dist/cjs/model/reserved.js +128 -0
  58. package/dist/cjs/model/schema.d.ts +54 -0
  59. package/dist/cjs/model/schema.js +2 -0
  60. package/dist/cjs/package.json +1 -0
  61. package/dist/cjs/parsers/openapi-schema.d.ts +30 -0
  62. package/dist/cjs/parsers/openapi-schema.js +241 -0
  63. package/dist/cjs/parsers/openapi.d.ts +8 -0
  64. package/dist/cjs/parsers/openapi.js +435 -0
  65. package/dist/cjs/parsers/postman.d.ts +20 -0
  66. package/dist/cjs/parsers/postman.js +493 -0
  67. package/dist/cjs/parsers/types.d.ts +52 -0
  68. package/dist/cjs/parsers/types.js +2 -0
  69. package/dist/cjs/sources/load.d.ts +25 -0
  70. package/dist/cjs/sources/load.js +296 -0
  71. package/dist/cjs/sources/parse.d.ts +4 -0
  72. package/dist/cjs/sources/parse.js +50 -0
  73. package/dist/cjs/util/errors.d.ts +9 -0
  74. package/dist/cjs/util/errors.js +23 -0
  75. package/dist/cjs/util/fs.d.ts +7 -0
  76. package/dist/cjs/util/fs.js +44 -0
  77. package/dist/cjs/util/hash.d.ts +3 -0
  78. package/dist/cjs/util/hash.js +26 -0
  79. package/dist/cjs/util/json.d.ts +10 -0
  80. package/dist/cjs/util/json.js +31 -0
  81. package/dist/cjs/util/log.d.ts +22 -0
  82. package/dist/cjs/util/log.js +45 -0
  83. package/dist/cjs/version.d.ts +2 -0
  84. package/dist/cjs/version.js +6 -0
  85. package/dist/cli.d.ts +3 -1
  86. package/dist/cli.d.ts.map +1 -1
  87. package/dist/cli.js +42 -12
  88. package/dist/cli.js.map +1 -1
  89. package/dist/codegen/emit-api.d.ts +3 -1
  90. package/dist/codegen/emit-api.d.ts.map +1 -1
  91. package/dist/codegen/emit-api.js +32 -7
  92. package/dist/codegen/emit-api.js.map +1 -1
  93. package/dist/codegen/emit-bindings.d.ts +9 -0
  94. package/dist/codegen/emit-bindings.d.ts.map +1 -0
  95. package/dist/codegen/emit-bindings.js +112 -0
  96. package/dist/codegen/emit-bindings.js.map +1 -0
  97. package/dist/codegen/emit-types.d.ts +8 -1
  98. package/dist/codegen/emit-types.d.ts.map +1 -1
  99. package/dist/codegen/emit-types.js +10 -8
  100. package/dist/codegen/emit-types.js.map +1 -1
  101. package/dist/codegen/emit.d.ts +10 -1
  102. package/dist/codegen/emit.d.ts.map +1 -1
  103. package/dist/codegen/emit.js +142 -37
  104. package/dist/codegen/emit.js.map +1 -1
  105. package/dist/codegen/files.d.ts +3 -12
  106. package/dist/codegen/files.d.ts.map +1 -1
  107. package/dist/codegen/files.js +3 -12
  108. package/dist/codegen/files.js.map +1 -1
  109. package/dist/codegen/print.d.ts +1 -4
  110. package/dist/codegen/print.d.ts.map +1 -1
  111. package/dist/codegen/print.js +1 -4
  112. package/dist/codegen/print.js.map +1 -1
  113. package/dist/codegen/templates/bindings.d.ts +14 -0
  114. package/dist/codegen/templates/bindings.d.ts.map +1 -0
  115. package/dist/codegen/templates/bindings.js +705 -0
  116. package/dist/codegen/templates/bindings.js.map +1 -0
  117. package/dist/codegen/templates/runtime.d.ts +2 -1
  118. package/dist/codegen/templates/runtime.d.ts.map +1 -1
  119. package/dist/codegen/templates/runtime.js +1192 -279
  120. package/dist/codegen/templates/runtime.js.map +1 -1
  121. package/dist/codegen/templates/transports.d.ts +2 -0
  122. package/dist/codegen/templates/transports.d.ts.map +1 -0
  123. package/dist/codegen/templates/transports.js +270 -0
  124. package/dist/codegen/templates/transports.js.map +1 -0
  125. package/dist/collect/collect.d.ts +1 -11
  126. package/dist/collect/collect.d.ts.map +1 -1
  127. package/dist/collect/collect.js +21 -28
  128. package/dist/collect/collect.js.map +1 -1
  129. package/dist/collect/naming.d.ts +1 -4
  130. package/dist/collect/naming.d.ts.map +1 -1
  131. package/dist/collect/naming.js +1 -4
  132. package/dist/collect/naming.js.map +1 -1
  133. package/dist/collect/path.d.ts +2 -9
  134. package/dist/collect/path.d.ts.map +1 -1
  135. package/dist/collect/path.js +2 -9
  136. package/dist/collect/path.js.map +1 -1
  137. package/dist/config/init.d.ts +11 -2
  138. package/dist/config/init.d.ts.map +1 -1
  139. package/dist/config/init.js +55 -7
  140. package/dist/config/init.js.map +1 -1
  141. package/dist/config/load.d.ts.map +1 -1
  142. package/dist/config/load.js +26 -1
  143. package/dist/config/load.js.map +1 -1
  144. package/dist/config/types.d.ts +13 -5
  145. package/dist/config/types.d.ts.map +1 -1
  146. package/dist/config/validate.d.ts +2 -6
  147. package/dist/config/validate.d.ts.map +1 -1
  148. package/dist/config/validate.js +18 -7
  149. package/dist/config/validate.js.map +1 -1
  150. package/dist/generate.d.ts +2 -8
  151. package/dist/generate.d.ts.map +1 -1
  152. package/dist/generate.js +13 -12
  153. package/dist/generate.js.map +1 -1
  154. package/dist/index.d.ts +4 -4
  155. package/dist/index.d.ts.map +1 -1
  156. package/dist/index.js +4 -4
  157. package/dist/index.js.map +1 -1
  158. package/dist/model/infer.d.ts +2 -9
  159. package/dist/model/infer.d.ts.map +1 -1
  160. package/dist/model/infer.js +2 -9
  161. package/dist/model/infer.js.map +1 -1
  162. package/dist/model/merge.d.ts +1 -5
  163. package/dist/model/merge.d.ts.map +1 -1
  164. package/dist/model/merge.js +1 -5
  165. package/dist/model/merge.js.map +1 -1
  166. package/dist/model/reserved.d.ts +1 -4
  167. package/dist/model/reserved.d.ts.map +1 -1
  168. package/dist/model/reserved.js +63 -4
  169. package/dist/model/reserved.js.map +1 -1
  170. package/dist/model/schema.d.ts +1 -4
  171. package/dist/model/schema.d.ts.map +1 -1
  172. package/dist/parsers/openapi-schema.d.ts +1 -5
  173. package/dist/parsers/openapi-schema.d.ts.map +1 -1
  174. package/dist/parsers/openapi-schema.js +2 -5
  175. package/dist/parsers/openapi-schema.js.map +1 -1
  176. package/dist/parsers/postman.d.ts +0 -3
  177. package/dist/parsers/postman.d.ts.map +1 -1
  178. package/dist/parsers/postman.js +2 -5
  179. package/dist/parsers/postman.js.map +1 -1
  180. package/dist/sources/load.d.ts +0 -6
  181. package/dist/sources/load.d.ts.map +1 -1
  182. package/dist/sources/load.js +4 -7
  183. package/dist/sources/load.js.map +1 -1
  184. package/dist/sources/parse.d.ts +0 -2
  185. package/dist/sources/parse.d.ts.map +1 -1
  186. package/dist/sources/parse.js +1 -1
  187. package/dist/sources/parse.js.map +1 -1
  188. package/dist/version.d.ts +1 -1
  189. package/dist/version.js +1 -1
  190. package/package.json +40 -12
  191. package/schema/config.schema.json +58 -12
  192. package/dist/codegen/emit-hooks.d.ts +0 -5
  193. package/dist/codegen/emit-hooks.d.ts.map +0 -1
  194. package/dist/codegen/emit-hooks.js +0 -67
  195. package/dist/codegen/emit-hooks.js.map +0 -1
  196. package/dist/codegen/templates/hooks.d.ts +0 -11
  197. package/dist/codegen/templates/hooks.d.ts.map +0 -1
  198. package/dist/codegen/templates/hooks.js +0 -272
  199. package/dist/codegen/templates/hooks.js.map +0 -1
@@ -24,7 +24,6 @@ export interface Manifest {
24
24
  /** output path (relative to the config dir, `/`-separated) → sha256 of its content */
25
25
  outputs: Record<string, string>;
26
26
  }
27
- export declare function manifestPath(cacheDir: string): string;
28
27
  export declare function snapshotPath(cacheDir: string, sourceId: string): string;
29
28
  export declare function readManifest(cacheDir: string): Promise<Manifest | undefined>;
30
29
  export declare function writeManifest(cacheDir: string, manifest: Manifest): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/cache/manifest.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,4EAA4E;IAC5E,MAAM,EAAE,MAAM,CAAC;IACf,0EAA0E;IAC1E,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8BAA8B;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mCAAmC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,oFAAoF;AACpF,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,CAAC,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,yDAAyD;IACzD,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,sFAAsF;IACtF,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEvE;AAED,wBAAsB,YAAY,CAChC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAY/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jC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,IAAI,CAAC,CAKf;AAED,qEAAqE;AACrE,wBAAgB,eAAe,CAC7B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,GACtC,MAAM,CAQR"}
@@ -2,7 +2,7 @@ import path from 'node:path';
2
2
  import { readTextIfExists, writeFileAtomic } from '../util/fs.js';
3
3
  import { sha256, stableStringify } from '../util/hash.js';
4
4
  import { PACKAGE_NAME, VERSION } from '../version.js';
5
- export function manifestPath(cacheDir) {
5
+ function manifestPath(cacheDir) {
6
6
  return path.join(cacheDir, 'manifest.json');
7
7
  }
8
8
  export function snapshotPath(cacheDir, sourceId) {
@@ -1 +1 @@
1
- {"version":3,"file":"manifest.js","sourceRoot":"","sources":["../../src/cache/manifest.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AA8BtD,MAAM,UAAU,YAAY,CAAC,QAAgB;IAC3C,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;AAC9C,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,QAAgB,EAAE,QAAgB;IAC7D,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,EAAE,GAAG,QAAQ,MAAM,CAAC,CAAC;AAC3D,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,QAAgB;IAEhB,MAAM,IAAI,GAAG,MAAM,gBAAgB,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC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E,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;KAC5C,CAAC,CACH,CAAC;AACJ,CAAC"}
@@ -0,0 +1,34 @@
1
+ export interface ManifestSource {
2
+ id: string;
3
+ /** file path (relative to the config) or URL; never contains credentials */
4
+ origin: string;
5
+ /** sha256 of the source content (plus its Postman environment, if any) */
6
+ hash: string;
7
+ etag?: string;
8
+ lastModified?: string;
9
+ /** Postman API `updatedAt` */
10
+ updatedAt?: string;
11
+ /** local file modification time */
12
+ mtime?: string;
13
+ fetchedAt: string;
14
+ }
15
+ /** `.jutsu-api/<project>/manifest.json`: what the last generation was made from. */
16
+ export interface Manifest {
17
+ version: 1;
18
+ generator: string;
19
+ generatedAt: string;
20
+ /** hash of generator version + config + source hashes */
21
+ inputKey: string;
22
+ configHash: string;
23
+ sources: ManifestSource[];
24
+ /** output path (relative to the config dir, `/`-separated) → sha256 of its content */
25
+ outputs: Record<string, string>;
26
+ }
27
+ export declare function snapshotPath(cacheDir: string, sourceId: string): string;
28
+ export declare function readManifest(cacheDir: string): Promise<Manifest | undefined>;
29
+ export declare function writeManifest(cacheDir: string, manifest: Manifest): Promise<void>;
30
+ /** Same inputs → same key → the previous output is still correct. */
31
+ export declare function computeInputKey(configHash: string, sources: {
32
+ id: string;
33
+ hash: string;
34
+ }[]): string;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.snapshotPath = snapshotPath;
7
+ exports.readManifest = readManifest;
8
+ exports.writeManifest = writeManifest;
9
+ exports.computeInputKey = computeInputKey;
10
+ const node_path_1 = __importDefault(require("node:path"));
11
+ const fs_js_1 = require("../util/fs.js");
12
+ const hash_js_1 = require("../util/hash.js");
13
+ const version_js_1 = require("../version.js");
14
+ function manifestPath(cacheDir) {
15
+ return node_path_1.default.join(cacheDir, 'manifest.json');
16
+ }
17
+ function snapshotPath(cacheDir, sourceId) {
18
+ return node_path_1.default.join(cacheDir, 'sources', `${sourceId}.txt`);
19
+ }
20
+ async function readManifest(cacheDir) {
21
+ const text = await (0, fs_js_1.readTextIfExists)(manifestPath(cacheDir));
22
+ if (text === undefined)
23
+ return undefined;
24
+ try {
25
+ const value = JSON.parse(text);
26
+ // an unreadable or foreign manifest just means "no cache"
27
+ return value && value.version === 1 && typeof value.inputKey === 'string'
28
+ ? value
29
+ : undefined;
30
+ }
31
+ catch {
32
+ return undefined;
33
+ }
34
+ }
35
+ async function writeManifest(cacheDir, manifest) {
36
+ await (0, fs_js_1.writeFileAtomic)(manifestPath(cacheDir), JSON.stringify(manifest, null, 2) + '\n');
37
+ }
38
+ /** Same inputs → same key → the previous output is still correct. */
39
+ function computeInputKey(configHash, sources) {
40
+ return (0, hash_js_1.sha256)((0, hash_js_1.stableStringify)({
41
+ generator: `${version_js_1.PACKAGE_NAME}@${version_js_1.VERSION}`,
42
+ config: configHash,
43
+ sources: sources.map((s) => [s.id, s.hash]),
44
+ }));
45
+ }
@@ -0,0 +1,8 @@
1
+ import type { Logger } from './util/log.js';
2
+ export declare const HELP: string;
3
+ /** Run the CLI; resolves the process exit code. */
4
+ export declare function main(argv: string[], io?: {
5
+ logger?: Logger;
6
+ }): Promise<number>;
7
+ /** How to run the CLI with the package manager that started it (npm, pnpm, yarn or bun). */
8
+ export declare function runner(env?: NodeJS.ProcessEnv): string;
@@ -0,0 +1,245 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.HELP = void 0;
7
+ exports.main = main;
8
+ exports.runner = runner;
9
+ const node_path_1 = __importDefault(require("node:path"));
10
+ const node_util_1 = require("node:util");
11
+ const emit_js_1 = require("./codegen/emit.js");
12
+ const init_js_1 = require("./config/init.js");
13
+ const generate_js_1 = require("./generate.js");
14
+ const errors_js_1 = require("./util/errors.js");
15
+ const log_js_1 = require("./util/log.js");
16
+ const version_js_1 = require("./version.js");
17
+ exports.HELP = `${version_js_1.PACKAGE_NAME} ${version_js_1.VERSION}
18
+ Generate a typed API layer from Postman, Swagger and OpenAPI collections, for
19
+ React, React Native, Next.js, Vue, Angular, Svelte, SolidJS or plain TypeScript,
20
+ on fetch, axios, react-native-fetch, Angular HttpClient or your own HTTP client.
21
+
22
+ Usage
23
+ jutsu-api [command] [options]
24
+
25
+ Commands
26
+ generate Build api-collection.json and the typed client (default)
27
+ check Exit 1 when generated files are out of date (CI)
28
+ collect Only build api-collection.json
29
+ init Create <project>-api.config.json
30
+
31
+ Options
32
+ -c, --config <file> Config file (default: the *-api.config.json in the cwd)
33
+ --cwd <dir> Run as if started in <dir>
34
+ -f, --force Regenerate even if nothing changed; overwrite edited files
35
+ --offline Use cached copies of remote sources, never the network
36
+ --dry-run Show what would change without writing
37
+ -q, --quiet Only print warnings and errors
38
+ -v, --verbose Print debug details
39
+ -h, --help Show this help
40
+ -V, --version Show the version
41
+
42
+ init options
43
+ --name <project> Project name (default: package.json name)
44
+ --framework <f> ${emit_js_1.FRAMEWORKS.join(' | ')}
45
+ (default: detected from package.json)
46
+ --http-client <c> ${emit_js_1.HTTP_CLIENTS.join(' | ')}
47
+ (default: detected, else fetch)
48
+ --source <s> Path or URL of the first collection / spec
49
+ --output <dir> Output folder (default: src/api; lib/api for Next.js,
50
+ src/app/api for Angular, src/lib/api for Svelte)
51
+
52
+ Exit codes
53
+ 0 success / up to date 1 failure or stale (check) 2 usage or config error
54
+
55
+ Environment
56
+ POSTMAN_API_KEY Key for "postman": { "collectionId" } sources
57
+ NO_COLOR Disable colours
58
+ `;
59
+ const COMMANDS = ['generate', 'check', 'collect', 'init', 'help'];
60
+ const OPTIONS = {
61
+ 'config': { type: 'string', short: 'c' },
62
+ 'cwd': { type: 'string' },
63
+ 'force': { type: 'boolean', short: 'f' },
64
+ 'offline': { type: 'boolean' },
65
+ 'dry-run': { type: 'boolean' },
66
+ 'quiet': { type: 'boolean', short: 'q' },
67
+ 'verbose': { type: 'boolean', short: 'v' },
68
+ 'help': { type: 'boolean', short: 'h' },
69
+ 'version': { type: 'boolean', short: 'V' },
70
+ 'name': { type: 'string' },
71
+ 'framework': { type: 'string' },
72
+ 'http-client': { type: 'string' },
73
+ 'target': { type: 'string' },
74
+ 'source': { type: 'string' },
75
+ 'output': { type: 'string' },
76
+ };
77
+ const parse = (argv) => (0, node_util_1.parseArgs)({
78
+ args: argv,
79
+ allowPositionals: true,
80
+ strict: true,
81
+ options: OPTIONS,
82
+ });
83
+ /** Config and usage mistakes exit with 2; everything else that fails exits with 1. */
84
+ const USAGE_ERRORS = new Set([
85
+ 'CONFIG_INVALID',
86
+ 'CONFIG_NOT_FOUND',
87
+ 'CONFIG_AMBIGUOUS',
88
+ 'CONFIG_EXISTS',
89
+ 'USAGE',
90
+ 'OUTPUT_UNSAFE',
91
+ ]);
92
+ /** Run the CLI; resolves the process exit code. */
93
+ async function main(argv, io = {}) {
94
+ let parsed;
95
+ try {
96
+ parsed = parse(argv);
97
+ }
98
+ catch (error) {
99
+ process.stderr.write(`${(0, errors_js_1.errorMessage)(error)}\n\nRun jutsu-api --help for usage.\n`);
100
+ return 2;
101
+ }
102
+ const { values, positionals } = parsed;
103
+ const logger = io.logger ??
104
+ (0, log_js_1.createLogger)({
105
+ quiet: values.quiet ?? false,
106
+ verbose: values.verbose ?? false,
107
+ color: Boolean(process.stdout.isTTY) && !process.env.NO_COLOR,
108
+ });
109
+ if (values.version) {
110
+ logger.info(version_js_1.VERSION);
111
+ return 0;
112
+ }
113
+ const command = (positionals[0] ?? 'generate');
114
+ if (values.help || command === 'help') {
115
+ logger.info(exports.HELP);
116
+ return 0;
117
+ }
118
+ if (!COMMANDS.includes(command)) {
119
+ logger.error(`Unknown command "${command}". Run jutsu-api --help.`);
120
+ return 2;
121
+ }
122
+ if (positionals.length > 1) {
123
+ logger.error(`Unexpected argument "${positionals[1]}".`);
124
+ return 2;
125
+ }
126
+ const run = {
127
+ cwd: node_path_1.default.resolve(values.cwd ?? process.cwd()),
128
+ logger,
129
+ force: values.force ?? false,
130
+ offline: values.offline ?? false,
131
+ dryRun: values['dry-run'] ?? false,
132
+ };
133
+ if (values.config)
134
+ run.configPath = values.config;
135
+ try {
136
+ if (command === 'init')
137
+ return await runInit(values, run, logger);
138
+ if (command === 'collect')
139
+ return await runCollect(run, logger);
140
+ if (command === 'check')
141
+ return await runCheck(run, logger);
142
+ report(await (0, generate_js_1.generate)(run), logger);
143
+ return 0;
144
+ }
145
+ catch (error) {
146
+ if (!(0, errors_js_1.isCodegenError)(error))
147
+ throw error;
148
+ logger.error(error.message);
149
+ for (const line of error.details)
150
+ logger.info(` • ${line}`);
151
+ return USAGE_ERRORS.has(error.code) ? 2 : 1;
152
+ }
153
+ }
154
+ async function runInit(values, run, logger) {
155
+ if (values.target !== undefined) {
156
+ if (values.framework !== undefined) {
157
+ throw new errors_js_1.CodegenError('USAGE', '--target is replaced by --framework; pass only --framework');
158
+ }
159
+ logger.warn('--target is deprecated; use --framework');
160
+ }
161
+ const framework = values.framework ?? values.target;
162
+ if (framework !== undefined && !emit_js_1.FRAMEWORKS.includes(framework)) {
163
+ throw new errors_js_1.CodegenError('USAGE', `--framework must be one of ${emit_js_1.FRAMEWORKS.join(', ')} (got "${framework}")`);
164
+ }
165
+ const httpClient = values['http-client'];
166
+ if (httpClient !== undefined &&
167
+ !emit_js_1.HTTP_CLIENTS.includes(httpClient)) {
168
+ throw new errors_js_1.CodegenError('USAGE', `--http-client must be one of ${emit_js_1.HTTP_CLIENTS.join(', ')} (got "${httpClient}")`);
169
+ }
170
+ await (0, init_js_1.init)({
171
+ cwd: run.cwd,
172
+ logger,
173
+ force: run.force ?? false,
174
+ ...(values.name ? { name: values.name } : {}),
175
+ ...(framework ? { framework: framework } : {}),
176
+ ...(httpClient ? { httpClient: httpClient } : {}),
177
+ ...(values.source ? { source: values.source } : {}),
178
+ ...(values.output ? { output: values.output } : {}),
179
+ });
180
+ logger.info(`Next: point "sources" at your Postman / Swagger / OpenAPI file, then run \`${runner(run.env)} generate\`.`);
181
+ return 0;
182
+ }
183
+ async function runCollect(run, logger) {
184
+ const result = await (0, generate_js_1.collect)(run);
185
+ const file = node_path_1.default.relative(run.cwd, result.path) || result.path;
186
+ logger.success(`${run.dryRun ? 'Would write' : 'Wrote'} ${file} (${countEndpoints(result.collection)} endpoints)`);
187
+ printWarnings(result.collection.warnings, logger);
188
+ return 0;
189
+ }
190
+ async function runCheck(run, logger) {
191
+ const result = await (0, generate_js_1.check)(run);
192
+ printWarnings(result.warnings, logger);
193
+ if (result.fresh) {
194
+ logger.success('Generated API is up to date');
195
+ return 0;
196
+ }
197
+ logger.error(`Generated API is out of date (${result.stale.length} file(s)). Run \`${runner(run.env)} generate\`.`);
198
+ for (const file of result.stale)
199
+ logger.info(` ${file.path}`);
200
+ return 1;
201
+ }
202
+ function report(result, logger) {
203
+ if (result.status === 'up-to-date') {
204
+ const ids = result.sources.map((s) => s.id).join(', ');
205
+ logger.success(`Up to date: sources (${ids}), config and generator unchanged. Use --force to regenerate.`);
206
+ return;
207
+ }
208
+ const dryRun = result.status === 'dry-run';
209
+ for (const change of result.changes) {
210
+ if (change.action === 'write')
211
+ logger.info(` ${dryRun ? '~' : '✎'} ${change.path}`);
212
+ else if (change.action === 'remove')
213
+ logger.info(` - ${change.path}`);
214
+ else
215
+ logger.debug(` = ${change.path} (${change.action})`);
216
+ }
217
+ const collection = result.collection;
218
+ const touched = result.changes.filter((c) => c.action === 'write' || c.action === 'remove').length;
219
+ const merged = collection.groups
220
+ .flatMap((g) => g.operations)
221
+ .filter((o) => o.origins.length > 1).length;
222
+ logger.success(`${dryRun ? 'Would update' : 'Updated'} ${touched} file(s) in ${node_path_1.default.relative(result.config.configDir, result.config.outputDir)}: ` +
223
+ `${countEndpoints(collection)} endpoints in ${collection.groups.length} group(s)` +
224
+ (merged ? `, ${merged} merged from duplicate requests` : '') +
225
+ ` [${result.config.framework} + ${result.config.httpClient}]`);
226
+ printWarnings(result.warnings, logger);
227
+ }
228
+ /** How to run the CLI with the package manager that started it (npm, pnpm, yarn or bun). */
229
+ function runner(env = process.env) {
230
+ const agent = env.npm_config_user_agent ?? '';
231
+ if (agent.startsWith('pnpm'))
232
+ return 'pnpm exec jutsu-api';
233
+ if (agent.startsWith('yarn'))
234
+ return 'yarn jutsu-api';
235
+ if (agent.startsWith('bun'))
236
+ return 'bunx jutsu-api';
237
+ return 'npx jutsu-api';
238
+ }
239
+ function countEndpoints(collection) {
240
+ return collection.groups.reduce((n, g) => n + g.operations.length, 0);
241
+ }
242
+ function printWarnings(warnings, logger) {
243
+ for (const warning of warnings)
244
+ logger.warn(warning);
245
+ }
@@ -0,0 +1,6 @@
1
+ import type { ApiCollection } from '../model/collection.js';
2
+ import type { OpPlan, PlannedGroup } from './plan.js';
3
+ /** api.ts: `createApi(client)` returning `{ group: { endpoint } }`. */
4
+ export declare function emitApi(collection: ApiCollection, groups: PlannedGroup[], ext: string): string;
5
+ /** `group.name`: the key in `ApiOptions.endpoints`, logs and metrics. */
6
+ export declare function endpointId(plan: OpPlan): string;
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.emitApi = emitApi;
4
+ exports.endpointId = endpointId;
5
+ const plan_js_1 = require("./plan.js");
6
+ const print_js_1 = require("./print.js");
7
+ /** api.ts: `createApi(client)` returning `{ group: { endpoint } }`. */
8
+ function emitApi(collection, groups, ext) {
9
+ const plans = groups.flatMap((g) => g.plans);
10
+ const first = plans[0];
11
+ let out = first
12
+ ? `import { endpoint } from './runtime${ext}';\nimport type { ApiRequester, EndpointOptions } from './runtime${ext}';\nimport type * as T from './types${ext}';\n`
13
+ : `import type { ApiRequester, EndpointOptions } from './runtime${ext}';\n`;
14
+ out += '\n';
15
+ out += (0, print_js_1.jsDoc)(['Every endpoint by id, with its args and response types.']);
16
+ out += 'export interface Endpoints {\n';
17
+ for (const plan of plans) {
18
+ out += ` ${(0, print_js_1.tsString)(endpointId(plan))}: { args: T.${plan.args}; response: T.${plan.response} };\n`;
19
+ }
20
+ out += '}\n\n';
21
+ out += 'export type EndpointId = keyof Endpoints;\n\n';
22
+ out += (0, print_js_1.jsDoc)([`Options of {@link createApi}.`]);
23
+ out +=
24
+ 'export interface ApiOptions {\n' +
25
+ " /** defaults per endpoint: messages, retry, fallback, timeoutMs, headers, … (e.g. { 'auth.login': { messages: { 401: 'Wrong password' } } }) */\n" +
26
+ " endpoints?: { [K in EndpointId]?: EndpointOptions<Endpoints[K]['response']> };\n" +
27
+ '}\n\n';
28
+ out += (0, print_js_1.jsDoc)([
29
+ `Typed API of ${(0, print_js_1.code)(collection.project)}.`,
30
+ '',
31
+ '@example',
32
+ 'const api = createApi(client);',
33
+ ...(first ? [exampleCall(first)] : []),
34
+ ]);
35
+ out += first
36
+ ? 'export function createApi(client: ApiRequester, options: ApiOptions = {}) {\n const e = options.endpoints ?? {};\n return {\n'
37
+ : 'export function createApi(_client: ApiRequester, _options: ApiOptions = {}) {\n return {\n';
38
+ for (const { group, plans } of groups) {
39
+ out += (0, print_js_1.jsDoc)([group.name], ' ') + ` ${(0, print_js_1.propKey)(group.key)}: {\n`;
40
+ for (const plan of plans)
41
+ out += endpointEntry(plan);
42
+ out += ' },\n';
43
+ }
44
+ out += ' };\n}\n\n';
45
+ out +=
46
+ '/** The object returned by {@link createApi}. */\nexport type Api = ReturnType<typeof createApi>;\n';
47
+ return out;
48
+ }
49
+ function endpointEntry(plan) {
50
+ const { op } = plan;
51
+ const generics = [`T.${plan.args}`, `T.${plan.response}`];
52
+ if (plan.errors || plan.defaultError)
53
+ generics.push(plan.errors ? `T.${plan.errors}` : '{}');
54
+ if (plan.defaultError)
55
+ generics.push(`T.${plan.defaultError}`);
56
+ const id = (0, print_js_1.tsString)(endpointId(plan));
57
+ const spec = [
58
+ `id: ${id}`,
59
+ `method: '${op.method}'`,
60
+ `path: ${(0, print_js_1.tsString)(op.path)}`,
61
+ ];
62
+ if (plan.defaults.length)
63
+ spec.push(`defaults: { ${plan.defaults.join(', ')} }`);
64
+ if (plan.errorStatuses.length)
65
+ spec.push(`errors: [${plan.errorStatuses.join(', ')}]`);
66
+ if (plan.errorRanges.length)
67
+ spec.push(`errorRanges: [${plan.errorRanges.join(', ')}]`);
68
+ if (plan.hasDefault)
69
+ spec.push('defaultError: true');
70
+ return ((0, print_js_1.jsDoc)(endpointDocs(op), ' ') +
71
+ ` ${(0, print_js_1.propKey)(op.name)}: endpoint<${generics.join(', ')}>(client, {\n` +
72
+ spec.map((s) => ` ${s},\n`).join('') +
73
+ ` }, e[${id}]),\n`);
74
+ }
75
+ /** `group.name`: the key in `ApiOptions.endpoints`, logs and metrics. */
76
+ function endpointId(plan) {
77
+ return `${plan.groupKey}.${plan.op.name}`;
78
+ }
79
+ function endpointDocs(op) {
80
+ const lines = [];
81
+ if (op.summary)
82
+ lines.push(op.summary);
83
+ if (op.description && op.description !== op.summary)
84
+ lines.push('', op.description);
85
+ lines.push('', (0, print_js_1.code)(`${op.method} ${op.path}`));
86
+ const errors = op.responses.filter((r) => r.status === 'default' ||
87
+ (typeof r.status === 'number' && r.status >= 400));
88
+ if (errors.length) {
89
+ lines.push(`Errors: ${errors.map(plan_js_1.statusLabel).join(', ')} (typed by ${(0, print_js_1.code)('.errorOf(error)')})`);
90
+ }
91
+ if (op.auth === 'none')
92
+ lines.push('Sent without auth (`skipAuth`).');
93
+ if (op.origins.length > 1)
94
+ lines.push(`Merged from: ${op.origins.join('; ')}`);
95
+ if (op.deprecated)
96
+ lines.push('@deprecated');
97
+ return lines;
98
+ }
99
+ function exampleCall(plan) {
100
+ const args = [];
101
+ if (plan.op.pathParams.length) {
102
+ args.push(`params: { ${plan.op.pathParams.map((p) => `${(0, print_js_1.propKey)(p.name)}: 1`).join(', ')} }`);
103
+ }
104
+ if (plan.op.body?.required)
105
+ args.push('body: { … }');
106
+ const call = args.length ? `{ ${args.join(', ')} }` : '';
107
+ return `const data = await api.${plan.groupKey}.${plan.op.name}(${call});`;
108
+ }
@@ -0,0 +1,8 @@
1
+ import type { OpPlan } from './plan.js';
2
+ import type { UiFramework } from './templates/bindings.js';
3
+ export declare function bindingsFile(framework: UiFramework): string;
4
+ /** The framework bindings: a query wrapper per GET / HEAD / OPTIONS endpoint, a mutation wrapper for the rest. */
5
+ export declare function emitBindings(plans: OpPlan[], framework: UiFramework, options: {
6
+ ext: string;
7
+ useClient: boolean;
8
+ }): string;
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bindingsFile = bindingsFile;
4
+ exports.emitBindings = emitBindings;
5
+ const print_js_1 = require("./print.js");
6
+ const bindings_js_1 = require("./templates/bindings.js");
7
+ const QUERY_METHODS = new Set(['GET', 'HEAD', 'OPTIONS']);
8
+ const FLAVORS = {
9
+ react: {
10
+ file: 'hooks.ts',
11
+ prefix: 'use',
12
+ query: 'useApiQuery',
13
+ mutation: 'useApiMutation',
14
+ queryOptions: 'QueryHookOptions',
15
+ mutationOptions: 'MutationHookOptions',
16
+ args: (t) => t,
17
+ },
18
+ vue: {
19
+ file: 'composables.ts',
20
+ prefix: 'use',
21
+ query: 'useApiQuery',
22
+ mutation: 'useApiMutation',
23
+ queryOptions: 'QueryComposableOptions',
24
+ mutationOptions: 'MutationComposableOptions',
25
+ args: (t) => `MaybeRefOrGetter<${t}>`,
26
+ },
27
+ angular: {
28
+ file: 'angular.ts',
29
+ prefix: 'inject',
30
+ query: 'injectApiQuery',
31
+ mutation: 'injectApiMutation',
32
+ queryOptions: 'QuerySignalOptions',
33
+ mutationOptions: 'MutationSignalOptions',
34
+ args: (t) => `Input<${t}>`,
35
+ },
36
+ svelte: {
37
+ file: 'stores.ts',
38
+ prefix: 'create',
39
+ query: 'createApiQuery',
40
+ mutation: 'createApiMutation',
41
+ queryOptions: 'QueryStoreOptions',
42
+ mutationOptions: 'MutationStoreOptions',
43
+ args: (t) => `StoreInput<${t}>`,
44
+ },
45
+ solid: {
46
+ file: 'primitives.ts',
47
+ prefix: 'create',
48
+ query: 'createApiQuery',
49
+ mutation: 'createApiMutation',
50
+ queryOptions: 'QueryPrimitiveOptions',
51
+ mutationOptions: 'MutationPrimitiveOptions',
52
+ args: (t) => `Input<${t}>`,
53
+ },
54
+ };
55
+ function bindingsFile(framework) {
56
+ return FLAVORS[framework].file;
57
+ }
58
+ /** The framework bindings: a query wrapper per GET / HEAD / OPTIONS endpoint, a mutation wrapper for the rest. */
59
+ function emitBindings(plans, framework, options) {
60
+ const flavor = FLAVORS[framework];
61
+ const isQuery = (p) => QUERY_METHODS.has(p.op.method);
62
+ let out = (0, bindings_js_1.bindingsPrelude)({
63
+ framework,
64
+ useClient: options.useClient,
65
+ hasEndpoints: plans.length > 0,
66
+ hasQueries: plans.some(isQuery),
67
+ ext: options.ext,
68
+ });
69
+ for (const plan of plans) {
70
+ out +=
71
+ '\n' +
72
+ (isQuery(plan)
73
+ ? queryWrapper(plan, flavor)
74
+ : mutationWrapper(plan, flavor));
75
+ }
76
+ return out;
77
+ }
78
+ function queryWrapper(plan, f) {
79
+ const { op } = plan;
80
+ const args = `T.${plan.args}`;
81
+ const param = plan.argsOptional
82
+ ? `args?: ${f.args(`${args} | undefined`)}`
83
+ : `args: ${f.args(args)}`;
84
+ const a = plan.argsOptional ? `${args} | undefined` : args;
85
+ const signal = plan.argsOptional ? 'a?.signal' : 'a.signal';
86
+ return ((0, print_js_1.jsDoc)([
87
+ `${op.summary ?? op.name} — ${(0, print_js_1.code)(`${op.method} ${op.path}`)}.`,
88
+ 'Refetches when params, query, body or headers change.',
89
+ ]) +
90
+ `export function ${f.prefix}${op.typeName}(${param}, options?: ${f.queryOptions}<T.${plan.response}>) {\n` +
91
+ ` return ${f.query}(\n` +
92
+ ` (api, a: ${a}, signal, report) =>\n` +
93
+ ` api.${plan.groupKey}.${op.name}.raw({ ...a, signal: linkSignals(signal, ${signal}) }).then((r) => (report(r), r.data)),\n` +
94
+ ' args,\n' +
95
+ ' options\n' +
96
+ ' );\n}\n');
97
+ }
98
+ function mutationWrapper(plan, f) {
99
+ const { op } = plan;
100
+ // a `void` vars type lets run() be called without arguments
101
+ const vars = plan.argsOptional ? `T.${plan.args} | void` : `T.${plan.args}`;
102
+ const pass = plan.argsOptional
103
+ ? `vars as T.${plan.args} | undefined`
104
+ : 'vars';
105
+ return ((0, print_js_1.jsDoc)([
106
+ `${op.summary ?? op.name} — ${(0, print_js_1.code)(`${op.method} ${op.path}`)}.`,
107
+ 'Call run(args) / runAsync(args).',
108
+ ]) +
109
+ `export function ${f.prefix}${op.typeName}(options?: ${f.mutationOptions}<T.${plan.response}, ${vars}>) {\n` +
110
+ ` return ${f.mutation}(\n` +
111
+ ` (api, vars: ${vars}, report) => api.${plan.groupKey}.${op.name}.raw(${pass}).then((r) => (report(r), r.data)),\n` +
112
+ ' options\n' +
113
+ ' );\n' +
114
+ '}\n');
115
+ }
@@ -0,0 +1,10 @@
1
+ import type { ApiCollection } from '../model/collection.js';
2
+ import type { PlannedGroup } from './plan.js';
3
+ export interface TypesOptions {
4
+ /** file responses are Blob (web) or unknown (React Native) */
5
+ web: boolean;
6
+ importExtension: string;
7
+ /** the transport sends a multipart array field as one JSON string (react-native-fetch) */
8
+ multipartArraysAsJson: boolean;
9
+ }
10
+ export declare function emitTypes(collection: ApiCollection, groups: PlannedGroup[], options: TypesOptions): string;