@ir-kit/asyncapi-typescript 0.1.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 (145) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +124 -0
  3. package/dist/ast/raw-text-node.d.ts +21 -0
  4. package/dist/ast/raw-text-node.d.ts.map +1 -0
  5. package/dist/ast/raw-text-node.js +37 -0
  6. package/dist/ast/raw-text-node.js.map +1 -0
  7. package/dist/ast/ts-build.d.ts +42 -0
  8. package/dist/ast/ts-build.d.ts.map +1 -0
  9. package/dist/ast/ts-build.js +93 -0
  10. package/dist/ast/ts-build.js.map +1 -0
  11. package/dist/ast/ts-node.d.ts +25 -0
  12. package/dist/ast/ts-node.d.ts.map +1 -0
  13. package/dist/ast/ts-node.js +41 -0
  14. package/dist/ast/ts-node.js.map +1 -0
  15. package/dist/ast/ts-renderer.d.ts +21 -0
  16. package/dist/ast/ts-renderer.d.ts.map +1 -0
  17. package/dist/ast/ts-renderer.js +79 -0
  18. package/dist/ast/ts-renderer.js.map +1 -0
  19. package/dist/index.d.ts +15 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +9 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/orchestrator.d.ts +13 -0
  24. package/dist/orchestrator.d.ts.map +1 -0
  25. package/dist/orchestrator.js +63 -0
  26. package/dist/orchestrator.js.map +1 -0
  27. package/dist/plugin.d.ts +149 -0
  28. package/dist/plugin.d.ts.map +1 -0
  29. package/dist/plugin.js +51 -0
  30. package/dist/plugin.js.map +1 -0
  31. package/dist/plugins/amqplib/bundle/amqp.gen.ts +99 -0
  32. package/dist/plugins/amqplib/config.d.ts +3 -0
  33. package/dist/plugins/amqplib/config.d.ts.map +1 -0
  34. package/dist/plugins/amqplib/config.js +2 -0
  35. package/dist/plugins/amqplib/config.js.map +1 -0
  36. package/dist/plugins/amqplib/index.d.ts +3 -0
  37. package/dist/plugins/amqplib/index.d.ts.map +1 -0
  38. package/dist/plugins/amqplib/index.js +2 -0
  39. package/dist/plugins/amqplib/index.js.map +1 -0
  40. package/dist/plugins/amqplib/plugin.d.ts +4 -0
  41. package/dist/plugins/amqplib/plugin.d.ts.map +1 -0
  42. package/dist/plugins/amqplib/plugin.js +18 -0
  43. package/dist/plugins/amqplib/plugin.js.map +1 -0
  44. package/dist/plugins/amqplib/types.d.ts +5 -0
  45. package/dist/plugins/amqplib/types.d.ts.map +1 -0
  46. package/dist/plugins/amqplib/types.js +2 -0
  47. package/dist/plugins/amqplib/types.js.map +1 -0
  48. package/dist/plugins/dispatch/bundle/dispatch.gen.ts +188 -0
  49. package/dist/plugins/dispatch/config.d.ts +3 -0
  50. package/dist/plugins/dispatch/config.d.ts.map +1 -0
  51. package/dist/plugins/dispatch/config.js +2 -0
  52. package/dist/plugins/dispatch/config.js.map +1 -0
  53. package/dist/plugins/dispatch/index.d.ts +3 -0
  54. package/dist/plugins/dispatch/index.d.ts.map +1 -0
  55. package/dist/plugins/dispatch/index.js +2 -0
  56. package/dist/plugins/dispatch/index.js.map +1 -0
  57. package/dist/plugins/dispatch/plugin.d.ts +12 -0
  58. package/dist/plugins/dispatch/plugin.d.ts.map +1 -0
  59. package/dist/plugins/dispatch/plugin.js +54 -0
  60. package/dist/plugins/dispatch/plugin.js.map +1 -0
  61. package/dist/plugins/dispatch/types.d.ts +6 -0
  62. package/dist/plugins/dispatch/types.d.ts.map +1 -0
  63. package/dist/plugins/dispatch/types.js +2 -0
  64. package/dist/plugins/dispatch/types.js.map +1 -0
  65. package/dist/plugins/event-map/config.d.ts +3 -0
  66. package/dist/plugins/event-map/config.d.ts.map +1 -0
  67. package/dist/plugins/event-map/config.js +4 -0
  68. package/dist/plugins/event-map/config.js.map +1 -0
  69. package/dist/plugins/event-map/index.d.ts +3 -0
  70. package/dist/plugins/event-map/index.d.ts.map +1 -0
  71. package/dist/plugins/event-map/index.js +2 -0
  72. package/dist/plugins/event-map/index.js.map +1 -0
  73. package/dist/plugins/event-map/plugin.d.ts +3 -0
  74. package/dist/plugins/event-map/plugin.d.ts.map +1 -0
  75. package/dist/plugins/event-map/plugin.js +62 -0
  76. package/dist/plugins/event-map/plugin.js.map +1 -0
  77. package/dist/plugins/event-map/types.d.ts +8 -0
  78. package/dist/plugins/event-map/types.d.ts.map +1 -0
  79. package/dist/plugins/event-map/types.js +2 -0
  80. package/dist/plugins/event-map/types.js.map +1 -0
  81. package/dist/plugins/events/config.d.ts +3 -0
  82. package/dist/plugins/events/config.d.ts.map +1 -0
  83. package/dist/plugins/events/config.js +4 -0
  84. package/dist/plugins/events/config.js.map +1 -0
  85. package/dist/plugins/events/index.d.ts +3 -0
  86. package/dist/plugins/events/index.d.ts.map +1 -0
  87. package/dist/plugins/events/index.js +2 -0
  88. package/dist/plugins/events/index.js.map +1 -0
  89. package/dist/plugins/events/plugin.d.ts +3 -0
  90. package/dist/plugins/events/plugin.d.ts.map +1 -0
  91. package/dist/plugins/events/plugin.js +48 -0
  92. package/dist/plugins/events/plugin.js.map +1 -0
  93. package/dist/plugins/events/types.d.ts +8 -0
  94. package/dist/plugins/events/types.d.ts.map +1 -0
  95. package/dist/plugins/events/types.js +2 -0
  96. package/dist/plugins/events/types.js.map +1 -0
  97. package/dist/plugins/index-barrel/config.d.ts +3 -0
  98. package/dist/plugins/index-barrel/config.d.ts.map +1 -0
  99. package/dist/plugins/index-barrel/config.js +2 -0
  100. package/dist/plugins/index-barrel/config.js.map +1 -0
  101. package/dist/plugins/index-barrel/index.d.ts +3 -0
  102. package/dist/plugins/index-barrel/index.d.ts.map +1 -0
  103. package/dist/plugins/index-barrel/index.js +2 -0
  104. package/dist/plugins/index-barrel/index.js.map +1 -0
  105. package/dist/plugins/index-barrel/plugin.d.ts +9 -0
  106. package/dist/plugins/index-barrel/plugin.d.ts.map +1 -0
  107. package/dist/plugins/index-barrel/plugin.js +47 -0
  108. package/dist/plugins/index-barrel/plugin.js.map +1 -0
  109. package/dist/plugins/index-barrel/types.d.ts +5 -0
  110. package/dist/plugins/index-barrel/types.d.ts.map +1 -0
  111. package/dist/plugins/index-barrel/types.js +2 -0
  112. package/dist/plugins/index-barrel/types.js.map +1 -0
  113. package/dist/plugins/typescript/config.d.ts +3 -0
  114. package/dist/plugins/typescript/config.d.ts.map +1 -0
  115. package/dist/plugins/typescript/config.js +4 -0
  116. package/dist/plugins/typescript/config.js.map +1 -0
  117. package/dist/plugins/typescript/index.d.ts +3 -0
  118. package/dist/plugins/typescript/index.d.ts.map +1 -0
  119. package/dist/plugins/typescript/index.js +2 -0
  120. package/dist/plugins/typescript/index.js.map +1 -0
  121. package/dist/plugins/typescript/plugin.d.ts +13 -0
  122. package/dist/plugins/typescript/plugin.d.ts.map +1 -0
  123. package/dist/plugins/typescript/plugin.js +67 -0
  124. package/dist/plugins/typescript/plugin.js.map +1 -0
  125. package/dist/plugins/typescript/types.d.ts +8 -0
  126. package/dist/plugins/typescript/types.d.ts.map +1 -0
  127. package/dist/plugins/typescript/types.js +2 -0
  128. package/dist/plugins/typescript/types.js.map +1 -0
  129. package/dist/runtime/copy-bundle.d.ts +16 -0
  130. package/dist/runtime/copy-bundle.d.ts.map +1 -0
  131. package/dist/runtime/copy-bundle.js +38 -0
  132. package/dist/runtime/copy-bundle.js.map +1 -0
  133. package/dist/runtime/load-document.d.ts +8 -0
  134. package/dist/runtime/load-document.d.ts.map +1 -0
  135. package/dist/runtime/load-document.js +21 -0
  136. package/dist/runtime/load-document.js.map +1 -0
  137. package/dist/runtime/order-plugins.d.ts +8 -0
  138. package/dist/runtime/order-plugins.d.ts.map +1 -0
  139. package/dist/runtime/order-plugins.js +31 -0
  140. package/dist/runtime/order-plugins.js.map +1 -0
  141. package/dist/runtime/plugin-instance.d.ts +18 -0
  142. package/dist/runtime/plugin-instance.d.ts.map +1 -0
  143. package/dist/runtime/plugin-instance.js +72 -0
  144. package/dist/runtime/plugin-instance.js.map +1 -0
  145. package/package.json +84 -0
@@ -0,0 +1,67 @@
1
+ import { TypeScriptGenerator } from "@asyncapi/modelina";
2
+ import { definePluginConfig } from "../../plugin.js";
3
+ import { defaultConfig } from "./config.js";
4
+ const HEADER = [
5
+ "// AUTO-GENERATED by @ir-kit/asyncapi-typescript — do not hand-edit.",
6
+ "",
7
+ "",
8
+ ].join("\n");
9
+ /**
10
+ * Emit one TS interface per message payload schema declared in the spec.
11
+ *
12
+ * Each message's payload is fed to Modelina as a standalone JSON Schema
13
+ * with `title = "<MessageId><suffix>"` injected so the top-level
14
+ * interface is named after the spec's message id. Inner objects
15
+ * referenced via $ref take their name from `components.schemas` (we
16
+ * inject titles there too — parser dereferences $refs by the time we
17
+ * read `payload.json()`, so the title is the only handle Modelina has).
18
+ */
19
+ export const typescript = definePluginConfig({
20
+ name: "typescript",
21
+ defaultConfig,
22
+ async handler(plugin) {
23
+ const generator = new TypeScriptGenerator({
24
+ modelType: "interface",
25
+ processorOptions: {
26
+ interpreter: { ignoreAdditionalProperties: true },
27
+ },
28
+ rawPropertyNames: true,
29
+ });
30
+ for (const schema of plugin.document.components()?.schemas()?.all() ?? []) {
31
+ const id = schema.id();
32
+ const raw = schema.json();
33
+ if (id && typeof raw === "object" && raw !== null && !("title" in raw)) {
34
+ raw.title = id;
35
+ }
36
+ }
37
+ const seen = new Map();
38
+ for (const ev of plugin.forEach("message")) {
39
+ if (ev.type !== "message")
40
+ continue;
41
+ const payload = ev.message.payload();
42
+ if (!payload)
43
+ continue;
44
+ const schema = JSON.parse(JSON.stringify(payload.json()));
45
+ schema.title = `${ev.message.id()}${plugin.config.messageSuffix}`;
46
+ schema.$schema = "http://json-schema.org/draft-07/schema#";
47
+ const models = await generator.generate(schema);
48
+ for (const model of models) {
49
+ if (!seen.has(model.modelName)) {
50
+ seen.set(model.modelName, model.result);
51
+ }
52
+ }
53
+ }
54
+ const blocks = Array.from(seen.values())
55
+ .filter((b) => b.trim().length > 0)
56
+ .map(prefixExports);
57
+ plugin.emit({
58
+ path: "types.gen.ts",
59
+ content: HEADER + blocks.join("\n\n") + "\n",
60
+ });
61
+ },
62
+ });
63
+ /** Modelina emits unexported decls; add `export` to top-level interface/type/enum. */
64
+ function prefixExports(block) {
65
+ return block.replace(/^(\s*)(interface|type|enum)\s/gm, (_, indent, kw) => `${indent}export ${kw} `);
66
+ }
67
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/plugins/typescript/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAM5C,MAAM,MAAM,GAAG;IACb,sEAAsE;IACtE,EAAE;IACF,EAAE;CACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,kBAAkB,CAK1C;IACA,IAAI,EAAE,YAAY;IAClB,aAAa;IACb,KAAK,CAAC,OAAO,CAAC,MAAM;QAClB,MAAM,SAAS,GAAG,IAAI,mBAAmB,CAAC;YACxC,SAAS,EAAE,WAAW;YACtB,gBAAgB,EAAE;gBAChB,WAAW,EAAE,EAAE,0BAA0B,EAAE,IAAI,EAAE;aAClD;YACD,gBAAgB,EAAE,IAAI;SACvB,CAAC,CAAC;QAEH,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC;YAC1E,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,EAAE,CAAC;YACvB,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;YAC1B,IAAI,EAAE,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,IAAI,CAAC,CAAC,OAAO,IAAI,GAAG,CAAC,EAAE,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cAAc;YACpB,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI;SAC7C,CAAC,CAAC;IACL,CAAC;CACF,CAAC,CAAC;AAEH,sFAAsF;AACtF,SAAS,aAAa,CAAC,KAAa;IAClC,OAAO,KAAK,CAAC,OAAO,CAClB,iCAAiC,EACjC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,CAAC,GAAG,MAAM,UAAU,EAAE,GAAG,CAC5C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,8 @@
1
+ export interface TypescriptPluginConfig {
2
+ /** Suffix appended to message ids for the message-level interface name. Default: `"Message"`. */
3
+ messageSuffix?: string;
4
+ }
5
+ export interface TypescriptResolvedConfig {
6
+ messageSuffix: string;
7
+ }
8
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/plugins/typescript/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sBAAsB;IACrC,iGAAiG;IACjG,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,wBAAwB;IACvC,aAAa,EAAE,MAAM,CAAC;CACvB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/plugins/typescript/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,16 @@
1
+ import type { GeneratedFile } from "../plugin.js";
2
+ /**
3
+ * Recursively walk a `bundle/` directory and return the files it contains
4
+ * as a flat array of `GeneratedFile`s, ready for plugins to emit.
5
+ *
6
+ * Mirrors the shape of `@hey-api/openapi-ts`'s `generateClientBundle` —
7
+ * static runtime source lives next to the plugin, gets copied to the
8
+ * caller's output verbatim. Filenames in the bundle become file names
9
+ * in the output (file at `<bundleDir>/foo/bar.gen.ts` → output path
10
+ * `foo/bar.gen.ts`).
11
+ *
12
+ * Files are read as utf8; this helper is for TypeScript source / JSON
13
+ * configs / other text. Binary bundle files would need a different path.
14
+ */
15
+ export declare function readBundle(bundleDir: string): Promise<ReadonlyArray<GeneratedFile>>;
16
+ //# sourceMappingURL=copy-bundle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copy-bundle.d.ts","sourceRoot":"","sources":["../../src/runtime/copy-bundle.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD;;;;;;;;;;;;GAYG;AACH,wBAAsB,UAAU,CAC9B,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC,CAIvC"}
@@ -0,0 +1,38 @@
1
+ import { readdir, readFile, stat } from "node:fs/promises";
2
+ import { join, posix, relative } from "node:path";
3
+ /**
4
+ * Recursively walk a `bundle/` directory and return the files it contains
5
+ * as a flat array of `GeneratedFile`s, ready for plugins to emit.
6
+ *
7
+ * Mirrors the shape of `@hey-api/openapi-ts`'s `generateClientBundle` —
8
+ * static runtime source lives next to the plugin, gets copied to the
9
+ * caller's output verbatim. Filenames in the bundle become file names
10
+ * in the output (file at `<bundleDir>/foo/bar.gen.ts` → output path
11
+ * `foo/bar.gen.ts`).
12
+ *
13
+ * Files are read as utf8; this helper is for TypeScript source / JSON
14
+ * configs / other text. Binary bundle files would need a different path.
15
+ */
16
+ export async function readBundle(bundleDir) {
17
+ const out = [];
18
+ await walk(bundleDir, bundleDir, out);
19
+ return out;
20
+ }
21
+ async function walk(bundleRoot, current, out) {
22
+ const entries = await readdir(current);
23
+ for (const entry of entries) {
24
+ const fullPath = join(current, entry);
25
+ const s = await stat(fullPath);
26
+ if (s.isDirectory()) {
27
+ await walk(bundleRoot, fullPath, out);
28
+ }
29
+ else {
30
+ const relativePath = relative(bundleRoot, fullPath)
31
+ .split(/\\|\//)
32
+ .join(posix.sep);
33
+ const content = await readFile(fullPath, "utf8");
34
+ out.push({ path: relativePath, content });
35
+ }
36
+ }
37
+ }
38
+ //# sourceMappingURL=copy-bundle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copy-bundle.js","sourceRoot":"","sources":["../../src/runtime/copy-bundle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAIlD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,SAAiB;IAEjB,MAAM,GAAG,GAAoB,EAAE,CAAC;IAChC,MAAM,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC;IACtC,OAAO,GAAG,CAAC;AACb,CAAC;AAED,KAAK,UAAU,IAAI,CACjB,UAAkB,EAClB,OAAe,EACf,GAAoB;IAEpB,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACvC,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACtC,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC/B,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;YACpB,MAAM,IAAI,CAAC,UAAU,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;QACxC,CAAC;aAAM,CAAC;YACN,MAAM,YAAY,GAAG,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC;iBAChD,KAAK,CAAC,OAAO,CAAC;iBACd,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACnB,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YACjD,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { AsyncAPIDocumentInterface } from "@asyncapi/parser";
2
+ /**
3
+ * Resolve a `GenerateOptions['input']` to a parsed AsyncAPI document.
4
+ * Strings are dispatched as URL or filesystem path; pre-parsed documents
5
+ * are returned as-is.
6
+ */
7
+ export declare function loadDocument(input: string | AsyncAPIDocumentInterface): Promise<AsyncAPIDocumentInterface>;
8
+ //# sourceMappingURL=load-document.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-document.d.ts","sourceRoot":"","sources":["../../src/runtime/load-document.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAGlE;;;;GAIG;AACH,wBAAsB,YAAY,CAChC,KAAK,EAAE,MAAM,GAAG,yBAAyB,GACxC,OAAO,CAAC,yBAAyB,CAAC,CAcpC"}
@@ -0,0 +1,21 @@
1
+ import { parseSpec } from "@ir-kit/asyncapi-core";
2
+ /**
3
+ * Resolve a `GenerateOptions['input']` to a parsed AsyncAPI document.
4
+ * Strings are dispatched as URL or filesystem path; pre-parsed documents
5
+ * are returned as-is.
6
+ */
7
+ export async function loadDocument(input) {
8
+ if (typeof input !== "string")
9
+ return input;
10
+ const looksLikeUrl = /^https?:\/\//i.test(input);
11
+ const result = await parseSpec(looksLikeUrl ? { kind: "url", url: input } : { kind: "file", path: input });
12
+ if (!result.document) {
13
+ const errors = result.diagnostics
14
+ .filter((d) => d.severity === 0)
15
+ .map((d) => ` - ${d.message}`)
16
+ .join("\n");
17
+ throw new Error(`AsyncAPI spec failed validation:\n${errors}`);
18
+ }
19
+ return result.document;
20
+ }
21
+ //# sourceMappingURL=load-document.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-document.js","sourceRoot":"","sources":["../../src/runtime/load-document.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,KAAyC;IAEzC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5C,MAAM,YAAY,GAAG,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACjD,MAAM,MAAM,GAAG,MAAM,SAAS,CAC5B,YAAY,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAC3E,CAAC;IACF,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QACrB,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW;aAC9B,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC;aAC/B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC;aAC9B,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,qCAAqC,MAAM,EAAE,CAAC,CAAC;IACjE,CAAC;IACD,OAAO,MAAM,CAAC,QAAQ,CAAC;AACzB,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { AnyRegisteredPlugin } from "../plugin.js";
2
+ /**
3
+ * Topological sort by `dependsOn`. Cycles throw. Missing dependencies
4
+ * are skipped silently — the dependent plugin runs anyway and is
5
+ * responsible for tolerating the absence.
6
+ */
7
+ export declare function orderPlugins(plugins: ReadonlyArray<AnyRegisteredPlugin>): ReadonlyArray<AnyRegisteredPlugin>;
8
+ //# sourceMappingURL=order-plugins.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order-plugins.d.ts","sourceRoot":"","sources":["../../src/runtime/order-plugins.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAExD;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,aAAa,CAAC,mBAAmB,CAAC,GAC1C,aAAa,CAAC,mBAAmB,CAAC,CAyBpC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Topological sort by `dependsOn`. Cycles throw. Missing dependencies
3
+ * are skipped silently — the dependent plugin runs anyway and is
4
+ * responsible for tolerating the absence.
5
+ */
6
+ export function orderPlugins(plugins) {
7
+ const byName = new Map(plugins.map((p) => [p.name, p]));
8
+ const visited = new Set();
9
+ const visiting = new Set();
10
+ const result = [];
11
+ function visit(plugin) {
12
+ if (visited.has(plugin.name))
13
+ return;
14
+ if (visiting.has(plugin.name)) {
15
+ throw new Error(`asyncapi-typescript: plugin dependency cycle at "${plugin.name}"`);
16
+ }
17
+ visiting.add(plugin.name);
18
+ for (const depName of plugin.__definition.dependsOn ?? []) {
19
+ const dep = byName.get(depName);
20
+ if (dep)
21
+ visit(dep);
22
+ }
23
+ visiting.delete(plugin.name);
24
+ visited.add(plugin.name);
25
+ result.push(plugin);
26
+ }
27
+ for (const plugin of plugins)
28
+ visit(plugin);
29
+ return result;
30
+ }
31
+ //# sourceMappingURL=order-plugins.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order-plugins.js","sourceRoot":"","sources":["../../src/runtime/order-plugins.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAC1B,OAA2C;IAE3C,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACxD,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;IACnC,MAAM,MAAM,GAA0B,EAAE,CAAC;IAEzC,SAAS,KAAK,CAAC,MAA2B;QACxC,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;YAAE,OAAO;QACrC,IAAI,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CACb,oDAAoD,MAAM,CAAC,IAAI,GAAG,CACnE,CAAC;QACJ,CAAC;QACD,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC1B,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,YAAY,CAAC,SAAS,IAAI,EAAE,EAAE,CAAC;YAC1D,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAChC,IAAI,GAAG;gBAAE,KAAK,CAAC,GAAG,CAAC,CAAC;QACtB,CAAC;QACD,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC7B,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACzB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACtB,CAAC;IAED,KAAK,MAAM,MAAM,IAAI,OAAO;QAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5C,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { AsyncAPIDocumentInterface } from "@asyncapi/parser";
2
+ import type { Project } from "@hey-api/codegen-core";
3
+ import { type GeneratedFile, type PluginInstance } from "../plugin.js";
4
+ interface BuildOptions {
5
+ document: AsyncAPIDocumentInterface;
6
+ project: Project;
7
+ files: GeneratedFile[];
8
+ apiRegistry: Map<string, unknown>;
9
+ headers: Map<string, string>;
10
+ }
11
+ /**
12
+ * Build a `PluginInstance` for one plugin run. `emit` registers a file
13
+ * with raw text; `emitTs` registers a file with `ts.Statement`s the
14
+ * `TsStatementRenderer` prints at `project.render()` time.
15
+ */
16
+ export declare function createPluginInstance(pluginName: string, pluginConfig: unknown, pluginApi: unknown, options: BuildOptions): PluginInstance;
17
+ export {};
18
+ //# sourceMappingURL=plugin-instance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-instance.d.ts","sourceRoot":"","sources":["../../src/runtime/plugin-instance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAIrD,OAAO,EAGL,KAAK,aAAa,EAElB,KAAK,cAAc,EACpB,MAAM,cAAc,CAAC;AAEtB,UAAU,YAAY;IACpB,QAAQ,EAAE,yBAAyB,CAAC;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,aAAa,EAAE,CAAC;IACvB,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,OAAO,EACrB,SAAS,EAAE,OAAO,EAClB,OAAO,EAAE,YAAY,GACpB,cAAc,CAgEhB"}
@@ -0,0 +1,72 @@
1
+ import { RawTextNode } from "../ast/raw-text-node.js";
2
+ import { TsStatementNode } from "../ast/ts-node.js";
3
+ import { iterateDocument, } from "../plugin.js";
4
+ /**
5
+ * Build a `PluginInstance` for one plugin run. `emit` registers a file
6
+ * with raw text; `emitTs` registers a file with `ts.Statement`s the
7
+ * `TsStatementRenderer` prints at `project.render()` time.
8
+ */
9
+ export function createPluginInstance(pluginName, pluginConfig, pluginApi, options) {
10
+ const { document, project, files, apiRegistry, headers } = options;
11
+ return {
12
+ name: pluginName,
13
+ config: pluginConfig,
14
+ api: pluginApi,
15
+ document,
16
+ files,
17
+ emit(file) {
18
+ files.push(file);
19
+ const projectFile = project.files.register({
20
+ logicalFilePath: stripTsExtension(file.path),
21
+ language: "typescript",
22
+ });
23
+ projectFile.addNode(new RawTextNode(file.content, { name: "content" }));
24
+ },
25
+ emitTs(path, statements, opts = {}) {
26
+ // `plugin.files` exposes paths (index-barrel reads them); content
27
+ // is rendered later by TsStatementRenderer.
28
+ files.push({ path, content: "" });
29
+ const projectFile = project.files.register({
30
+ logicalFilePath: stripTsExtension(path),
31
+ language: "typescript",
32
+ });
33
+ for (const group of opts.imports ?? []) {
34
+ const sourceFile = project.files.get({
35
+ logicalFilePath: group.from,
36
+ language: "typescript",
37
+ });
38
+ if (!sourceFile) {
39
+ throw new Error(`${pluginName}: emitTs(${path}) imports from "${group.from}", but no file with that logical path is registered yet. Add a dependsOn on the plugin that emits it.`);
40
+ }
41
+ projectFile.addImport({
42
+ from: sourceFile,
43
+ kind: "named",
44
+ isTypeOnly: group.isType ?? false,
45
+ imports: group.names.map((n) => ({
46
+ sourceName: n.name,
47
+ localName: n.name,
48
+ isTypeOnly: n.isType ?? false,
49
+ })),
50
+ });
51
+ }
52
+ if (opts.header) {
53
+ headers.set(stripTsExtension(path), opts.header);
54
+ }
55
+ for (const [i, stmt] of statements.entries()) {
56
+ projectFile.addNode(new TsStatementNode(stmt, {
57
+ name: `${pluginName}-${i}`,
58
+ }));
59
+ }
60
+ },
61
+ getApi(name) {
62
+ return apiRegistry.get(name);
63
+ },
64
+ forEach(...kinds) {
65
+ return iterateDocument(document, kinds);
66
+ },
67
+ };
68
+ }
69
+ function stripTsExtension(filePath) {
70
+ return filePath.replace(/\.tsx?$/, "");
71
+ }
72
+ //# sourceMappingURL=plugin-instance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-instance.js","sourceRoot":"","sources":["../../src/runtime/plugin-instance.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO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O,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;AACzC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,84 @@
1
+ {
2
+ "name": "@ir-kit/asyncapi-typescript",
3
+ "version": "0.1.0",
4
+ "description": "AsyncAPI 3.0 → TypeScript generator. Plugin-compose architecture: a small core orchestrates parser → IR → registered plugins, each emitting one slice of generated code (types, Events const, dispatch helpers, AMQP helpers, framework adapters). Parser via @asyncapi/parser, JSON Schema → TS via @asyncapi/modelina, file orchestration via @hey-api/codegen-core.",
5
+ "keywords": [
6
+ "asyncapi",
7
+ "typescript",
8
+ "codegen",
9
+ "events",
10
+ "amqp",
11
+ "rabbitmq"
12
+ ],
13
+ "homepage": "https://github.com/ir-kit/ir-kit/tree/main/packages/asyncapi/typescript",
14
+ "bugs": {
15
+ "url": "https://github.com/ir-kit/ir-kit/issues"
16
+ },
17
+ "license": "MIT",
18
+ "author": {
19
+ "name": "Ahmed Rowaihi",
20
+ "email": "ahmedrowaihi@gmail.com"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/ir-kit/ir-kit.git",
25
+ "directory": "packages/asyncapi/typescript"
26
+ },
27
+ "type": "module",
28
+ "sideEffects": false,
29
+ "main": "./dist/index.js",
30
+ "types": "./dist/index.d.ts",
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/index.d.ts",
34
+ "import": "./dist/index.js"
35
+ },
36
+ "./package.json": "./package.json"
37
+ },
38
+ "files": [
39
+ "dist",
40
+ "LICENSE.md"
41
+ ],
42
+ "publishConfig": {
43
+ "access": "public",
44
+ "provenance": true
45
+ },
46
+ "peerDependencies": {
47
+ "@asyncapi/modelina": ">=5.0.0",
48
+ "@asyncapi/parser": ">=3.0.0",
49
+ "@hey-api/codegen-core": ">=0.8.0",
50
+ "@ir-kit/asyncapi-core": ">=0.1.0",
51
+ "@ir-kit/codegen-core": ">=0.1.0",
52
+ "amqplib": ">=0.10.0",
53
+ "typescript": ">=5.0.0"
54
+ },
55
+ "peerDependenciesMeta": {
56
+ "amqplib": {
57
+ "optional": true
58
+ }
59
+ },
60
+ "devDependencies": {
61
+ "@asyncapi/modelina": "^5.0.0",
62
+ "@asyncapi/parser": "^3.6.0",
63
+ "@hey-api/codegen-core": "^0.8.1",
64
+ "@testcontainers/rabbitmq": "^11.14.0",
65
+ "@types/amqplib": "^0.10.5",
66
+ "@types/node": "^22",
67
+ "amqplib": "^0.10.4",
68
+ "testcontainers": "^11.14.0",
69
+ "typescript": "5.9.3",
70
+ "vitest": "^4.0.0",
71
+ "@ir-kit/asyncapi-core": "0.1.0",
72
+ "@ir-kit/codegen-core": "0.1.0",
73
+ "@ir-kit/tsconfig": "0.0.0"
74
+ },
75
+ "engines": {
76
+ "node": ">=20.19.0"
77
+ },
78
+ "scripts": {
79
+ "build": "tsc -p tsconfig.build.json && node scripts/copy-bundles.mjs",
80
+ "dev": "tsc -p tsconfig.build.json --watch",
81
+ "typecheck": "tsc --noEmit",
82
+ "test": "vitest run --passWithNoTests"
83
+ }
84
+ }