wrekenfile-converter 2.0.6 → 2.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 (52) hide show
  1. package/README.md +45 -26
  2. package/dist/example-usage.d.ts +1 -1
  3. package/dist/index.d.ts +6 -5
  4. package/dist/index.js +53 -20
  5. package/dist/v1/index.d.ts +3 -0
  6. package/dist/v1/index.js +21 -0
  7. package/dist/{postman-to-wrekenfile.js → v1/postman-to-wrekenfile.js} +7 -19
  8. package/dist/{wrekenfile-validator.js → v1/wrekenfile-validator.js} +30 -8
  9. package/dist/v2/cli/cli-mini-wrekenfile-generator.d.ts +2 -0
  10. package/dist/v2/cli/cli-mini-wrekenfile-generator.js +107 -0
  11. package/dist/v2/cli/cli-openapi-to-wrekenfile.d.ts +2 -0
  12. package/dist/v2/cli/cli-openapi-to-wrekenfile.js +115 -0
  13. package/dist/v2/cli/cli-openapi-v2-to-wrekenfile.d.ts +2 -0
  14. package/dist/v2/cli/cli-openapi-v2-to-wrekenfile.js +115 -0
  15. package/dist/v2/cli/cli-postman-to-wrekenfile.d.ts +2 -0
  16. package/dist/v2/cli/cli-postman-to-wrekenfile.js +54 -0
  17. package/dist/v2/index.d.ts +4 -0
  18. package/dist/v2/index.js +25 -0
  19. package/dist/v2/mini-wrekenfile-generator.d.ts +13 -0
  20. package/dist/v2/mini-wrekenfile-generator.js +289 -0
  21. package/dist/v2/openapi-to-wreken.d.ts +2 -0
  22. package/dist/v2/openapi-to-wreken.js +829 -0
  23. package/dist/v2/openapi-v2-to-wrekenfile.d.ts +2 -0
  24. package/dist/v2/openapi-v2-to-wrekenfile.js +806 -0
  25. package/dist/v2/postman-to-wrekenfile.d.ts +11 -0
  26. package/dist/v2/postman-to-wrekenfile.js +742 -0
  27. package/dist/v2/utils/constants.d.ts +80 -0
  28. package/dist/v2/utils/constants.js +104 -0
  29. package/dist/v2/utils/response-utils.d.ts +11 -0
  30. package/dist/v2/utils/response-utils.js +39 -0
  31. package/dist/v2/utils/yaml-utils.d.ts +4 -0
  32. package/dist/v2/utils/yaml-utils.js +96 -0
  33. package/dist/versions.d.ts +9 -0
  34. package/dist/versions.js +12 -0
  35. package/package.json +12 -14
  36. package/dist/openapi-to-wrekenfile.d.ts +0 -0
  37. package/dist/openapi-to-wrekenfile.js +0 -10
  38. package/wrekenfile.md +0 -726
  39. /package/dist/{cli → v1/cli}/cli-mini-wrekenfile-generator.d.ts +0 -0
  40. /package/dist/{cli → v1/cli}/cli-mini-wrekenfile-generator.js +0 -0
  41. /package/dist/{cli → v1/cli}/cli-openapi-to-wrekenfile.d.ts +0 -0
  42. /package/dist/{cli → v1/cli}/cli-openapi-to-wrekenfile.js +0 -0
  43. /package/dist/{cli → v1/cli}/cli-postman-to-wrekenfile.d.ts +0 -0
  44. /package/dist/{cli → v1/cli}/cli-postman-to-wrekenfile.js +0 -0
  45. /package/dist/{mini-wrekenfile-generator.d.ts → v1/mini-wrekenfile-generator.d.ts} +0 -0
  46. /package/dist/{mini-wrekenfile-generator.js → v1/mini-wrekenfile-generator.js} +0 -0
  47. /package/dist/{openapi-to-wreken.d.ts → v1/openapi-to-wreken.d.ts} +0 -0
  48. /package/dist/{openapi-to-wreken.js → v1/openapi-to-wreken.js} +0 -0
  49. /package/dist/{openapi-v2-to-wrekenfile.d.ts → v1/openapi-v2-to-wrekenfile.d.ts} +0 -0
  50. /package/dist/{openapi-v2-to-wrekenfile.js → v1/openapi-v2-to-wrekenfile.js} +0 -0
  51. /package/dist/{postman-to-wrekenfile.d.ts → v1/postman-to-wrekenfile.d.ts} +0 -0
  52. /package/dist/{wrekenfile-validator.d.ts → v1/wrekenfile-validator.d.ts} +0 -0
@@ -0,0 +1,115 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
37
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
+ return new (P || (P = Promise))(function (resolve, reject) {
39
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
40
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
41
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
42
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
43
+ });
44
+ };
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ const fs = __importStar(require("fs"));
47
+ const path = __importStar(require("path"));
48
+ const js_yaml_1 = require("js-yaml");
49
+ const openapi_v2_to_wrekenfile_1 = require("../openapi-v2-to-wrekenfile");
50
+ function printUsage() {
51
+ console.log(`Usage: npx ts-node src/cli/rest/cli-openapi-v2-to-wrekenfile.ts --input <swagger.yaml|json> [--output <wrekenfile.yaml>] [--cwd <dir>]`);
52
+ }
53
+ function parseArgs() {
54
+ const args = process.argv.slice(2);
55
+ const opts = {};
56
+ for (let i = 0; i < args.length; i++) {
57
+ if (args[i] === '--input' || args[i] === '-i') {
58
+ opts.input = args[++i];
59
+ }
60
+ else if (args[i] === '--output' || args[i] === '-o') {
61
+ opts.output = args[++i];
62
+ }
63
+ else if (args[i] === '--cwd') {
64
+ opts.cwd = args[++i];
65
+ }
66
+ }
67
+ return opts;
68
+ }
69
+ function main() {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ const opts = parseArgs();
72
+ if (!opts.input) {
73
+ printUsage();
74
+ process.exit(1);
75
+ }
76
+ const inputPath = path.resolve(opts.input);
77
+ const outputPath = path.resolve(opts.output || 'output_wrekenfile.yaml');
78
+ const baseDir = opts.cwd ? path.resolve(opts.cwd) : path.dirname(inputPath);
79
+ if (!fs.existsSync(inputPath)) {
80
+ console.error(`Input file not found: ${inputPath}`);
81
+ process.exit(1);
82
+ }
83
+ let swaggerSpec;
84
+ try {
85
+ const raw = fs.readFileSync(inputPath, 'utf8');
86
+ if (inputPath.endsWith('.json')) {
87
+ swaggerSpec = JSON.parse(raw);
88
+ }
89
+ else {
90
+ swaggerSpec = (0, js_yaml_1.load)(raw);
91
+ }
92
+ }
93
+ catch (err) {
94
+ console.error('Failed to load Swagger/OpenAPI v2 file:', err);
95
+ process.exit(1);
96
+ }
97
+ let wrekenfileYaml;
98
+ try {
99
+ wrekenfileYaml = (0, openapi_v2_to_wrekenfile_1.generateWrekenfile)(swaggerSpec, baseDir);
100
+ }
101
+ catch (err) {
102
+ console.error('Failed to generate Wrekenfile:', err);
103
+ process.exit(1);
104
+ }
105
+ try {
106
+ fs.writeFileSync(outputPath, wrekenfileYaml, 'utf8');
107
+ console.log(`✅ Wrekenfile v2.0.1 written to ${outputPath}`);
108
+ }
109
+ catch (err) {
110
+ console.error('Failed to write output file:', err);
111
+ process.exit(1);
112
+ }
113
+ });
114
+ }
115
+ main();
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ var __importDefault = (this && this.__importDefault) || function (mod) {
13
+ return (mod && mod.__esModule) ? mod : { "default": mod };
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ const fs_1 = __importDefault(require("fs"));
17
+ const postman_to_wrekenfile_1 = require("../postman-to-wrekenfile");
18
+ function printUsage() {
19
+ console.log('Usage: npx ts-node src/cli/rest/cli-postman-to-wrekenfile.ts <postman_collection.json> <output_wrekenfile.yaml> [postman_environment.json]');
20
+ process.exit(1);
21
+ }
22
+ function main() {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const args = process.argv.slice(2);
25
+ if (args.length < 2) {
26
+ printUsage();
27
+ }
28
+ const [inputFile, outputFile, envFile] = args;
29
+ if (!fs_1.default.existsSync(inputFile)) {
30
+ console.error(`❌ Input file not found: ${inputFile}`);
31
+ process.exit(1);
32
+ }
33
+ let variables = {};
34
+ if (envFile) {
35
+ if (!fs_1.default.existsSync(envFile)) {
36
+ console.error(`❌ Environment file not found: ${envFile}`);
37
+ process.exit(1);
38
+ }
39
+ variables = (0, postman_to_wrekenfile_1.loadEnvironmentFile)(envFile);
40
+ }
41
+ try {
42
+ const postmanContent = fs_1.default.readFileSync(inputFile, 'utf8');
43
+ const postmanCollection = JSON.parse(postmanContent);
44
+ const wrekenfileYaml = (0, postman_to_wrekenfile_1.generateWrekenfile)(postmanCollection, variables);
45
+ fs_1.default.writeFileSync(outputFile, wrekenfileYaml);
46
+ console.log(`✅ Wrekenfile v2.0.1 generated: ${outputFile}`);
47
+ }
48
+ catch (error) {
49
+ console.error(`❌ Error generating Wrekenfile: ${error.message}`);
50
+ process.exit(1);
51
+ }
52
+ });
53
+ }
54
+ main();
@@ -0,0 +1,4 @@
1
+ export { generateWrekenfile } from './openapi-to-wreken';
2
+ export { generateWrekenfile as generateWrekenfileV2 } from './openapi-v2-to-wrekenfile';
3
+ export { generateWrekenfile as generateWrekenfileFromPostman, extractStructs, extractOperations, mapType, parseJsonExample, extractFieldsFromObject, loadEnvironmentFile, extractCollectionVariables, resolveVariables } from './postman-to-wrekenfile';
4
+ export { generateMiniWrekenfiles, saveMiniWrekenfiles, MiniWrekenfile } from './mini-wrekenfile-generator';
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ // v2 entry point - Wrekenfile spec version 2.1.0
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.saveMiniWrekenfiles = exports.generateMiniWrekenfiles = exports.resolveVariables = exports.extractCollectionVariables = exports.loadEnvironmentFile = exports.extractFieldsFromObject = exports.parseJsonExample = exports.mapType = exports.extractOperations = exports.extractStructs = exports.generateWrekenfileFromPostman = exports.generateWrekenfileV2 = exports.generateWrekenfile = void 0;
5
+ // Export OpenAPI v3 converter
6
+ var openapi_to_wreken_1 = require("./openapi-to-wreken");
7
+ Object.defineProperty(exports, "generateWrekenfile", { enumerable: true, get: function () { return openapi_to_wreken_1.generateWrekenfile; } });
8
+ // Export OpenAPI v2 (Swagger) converter
9
+ var openapi_v2_to_wrekenfile_1 = require("./openapi-v2-to-wrekenfile");
10
+ Object.defineProperty(exports, "generateWrekenfileV2", { enumerable: true, get: function () { return openapi_v2_to_wrekenfile_1.generateWrekenfile; } });
11
+ // Export Postman converter
12
+ var postman_to_wrekenfile_1 = require("./postman-to-wrekenfile");
13
+ Object.defineProperty(exports, "generateWrekenfileFromPostman", { enumerable: true, get: function () { return postman_to_wrekenfile_1.generateWrekenfile; } });
14
+ Object.defineProperty(exports, "extractStructs", { enumerable: true, get: function () { return postman_to_wrekenfile_1.extractStructs; } });
15
+ Object.defineProperty(exports, "extractOperations", { enumerable: true, get: function () { return postman_to_wrekenfile_1.extractOperations; } });
16
+ Object.defineProperty(exports, "mapType", { enumerable: true, get: function () { return postman_to_wrekenfile_1.mapType; } });
17
+ Object.defineProperty(exports, "parseJsonExample", { enumerable: true, get: function () { return postman_to_wrekenfile_1.parseJsonExample; } });
18
+ Object.defineProperty(exports, "extractFieldsFromObject", { enumerable: true, get: function () { return postman_to_wrekenfile_1.extractFieldsFromObject; } });
19
+ Object.defineProperty(exports, "loadEnvironmentFile", { enumerable: true, get: function () { return postman_to_wrekenfile_1.loadEnvironmentFile; } });
20
+ Object.defineProperty(exports, "extractCollectionVariables", { enumerable: true, get: function () { return postman_to_wrekenfile_1.extractCollectionVariables; } });
21
+ Object.defineProperty(exports, "resolveVariables", { enumerable: true, get: function () { return postman_to_wrekenfile_1.resolveVariables; } });
22
+ // Export mini Wrekenfile generator
23
+ var mini_wrekenfile_generator_1 = require("./mini-wrekenfile-generator");
24
+ Object.defineProperty(exports, "generateMiniWrekenfiles", { enumerable: true, get: function () { return mini_wrekenfile_generator_1.generateMiniWrekenfiles; } });
25
+ Object.defineProperty(exports, "saveMiniWrekenfiles", { enumerable: true, get: function () { return mini_wrekenfile_generator_1.saveMiniWrekenfiles; } });
@@ -0,0 +1,13 @@
1
+ export interface MiniWrekenfile {
2
+ content: string;
3
+ metadata: {
4
+ endpoint?: string;
5
+ interface?: string;
6
+ source?: string;
7
+ methods: string[];
8
+ structs: string[];
9
+ filename: string;
10
+ };
11
+ }
12
+ export declare function generateMiniWrekenfiles(wrekenfileContent: string): MiniWrekenfile[];
13
+ export declare function saveMiniWrekenfiles(miniWrekenfiles: MiniWrekenfile[], outputDir?: string): void;
@@ -0,0 +1,289 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.generateMiniWrekenfiles = generateMiniWrekenfiles;
37
+ exports.saveMiniWrekenfiles = saveMiniWrekenfiles;
38
+ const yaml = __importStar(require("js-yaml"));
39
+ const fs = __importStar(require("fs"));
40
+ const constants_1 = require("./utils/constants");
41
+ function generateMiniWrekenfiles(wrekenfileContent) {
42
+ if (!wrekenfileContent || typeof wrekenfileContent !== 'string') {
43
+ throw new Error("Argument 'wrekenfileContent' is required and must be a string");
44
+ }
45
+ const data = yaml.load(wrekenfileContent);
46
+ if (!data.METHODS) {
47
+ throw new Error('No METHODS section found in Wrekenfile');
48
+ }
49
+ const methodGroups = groupMethods(data.METHODS);
50
+ const miniWrekenfiles = [];
51
+ for (const [groupKey, groupInfo] of Object.entries(methodGroups)) {
52
+ miniWrekenfiles.push(createMiniWrekenfile(data, groupKey, groupInfo));
53
+ }
54
+ return miniWrekenfiles;
55
+ }
56
+ const BACKTICK = '`';
57
+ const SLASH = '/';
58
+ function normalizeEndpoint(endpoint) {
59
+ endpoint = endpoint.trim();
60
+ if (endpoint.startsWith(BACKTICK) && endpoint.endsWith(BACKTICK)) {
61
+ endpoint = endpoint.slice(1, -1).trim();
62
+ }
63
+ if (endpoint.startsWith(SLASH)) {
64
+ endpoint = endpoint.substring(1);
65
+ }
66
+ return endpoint;
67
+ }
68
+ function groupMethods(methods) {
69
+ var _a, _b;
70
+ const groups = {};
71
+ for (const [methodName, methodData] of Object.entries(methods)) {
72
+ if ((_a = methodData.HTTP) === null || _a === void 0 ? void 0 : _a.ENDPOINT) {
73
+ const endpoint = normalizeEndpoint(methodData.HTTP.ENDPOINT);
74
+ const groupKey = `${constants_1.GROUP_PREFIX_HTTP}${endpoint}`;
75
+ if (!groups[groupKey]) {
76
+ groups[groupKey] = {
77
+ methods: {},
78
+ type: 'http',
79
+ endpoint: endpoint
80
+ };
81
+ }
82
+ groups[groupKey].methods[methodName] = methodData;
83
+ }
84
+ else if ((_b = methodData.INTERFACE) === null || _b === void 0 ? void 0 : _b.NAME) {
85
+ const interfaceName = methodData.INTERFACE.NAME;
86
+ const source = methodData.SOURCE;
87
+ const groupKey = source ? `${constants_1.GROUP_PREFIX_SDK}${source}:${interfaceName}` : `${constants_1.GROUP_PREFIX_SDK}${interfaceName}`;
88
+ if (!groups[groupKey]) {
89
+ groups[groupKey] = {
90
+ methods: {},
91
+ type: 'sdk',
92
+ interface: interfaceName,
93
+ source: source
94
+ };
95
+ }
96
+ groups[groupKey].methods[methodName] = methodData;
97
+ }
98
+ else if (methodData.SOURCE) {
99
+ // SDK methods with SOURCE but no INTERFACE.NAME - group by SOURCE
100
+ const source = methodData.SOURCE;
101
+ const groupKey = `${constants_1.GROUP_PREFIX_SDK}${source}`;
102
+ if (!groups[groupKey]) {
103
+ groups[groupKey] = {
104
+ methods: {},
105
+ type: 'sdk',
106
+ source: source
107
+ };
108
+ }
109
+ groups[groupKey].methods[methodName] = methodData;
110
+ }
111
+ else {
112
+ const groupKey = `${constants_1.GROUP_PREFIX_OTHER}${methodName}`;
113
+ groups[groupKey] = {
114
+ methods: { [methodName]: methodData },
115
+ type: 'other'
116
+ };
117
+ }
118
+ }
119
+ return groups;
120
+ }
121
+ function createMiniWrekenfile(data, groupKey, groupInfo) {
122
+ var _a;
123
+ const { methods, type, endpoint, interface: interfaceName, source } = groupInfo;
124
+ const requiredStructs = collectRequiredStructs(methods, data.STRUCTS || {});
125
+ const miniData = {
126
+ VERSION: data.VERSION,
127
+ METHODS: methods,
128
+ };
129
+ if (type === 'sdk' && source && ((_a = data.SOURCES) === null || _a === void 0 ? void 0 : _a[source])) {
130
+ miniData.SOURCES = { [source]: data.SOURCES[source] };
131
+ }
132
+ if (data.DEFAULTS && Object.keys(data.DEFAULTS).length > 0) {
133
+ miniData.DEFAULTS = data.DEFAULTS;
134
+ }
135
+ if (Object.keys(requiredStructs).length > 0) {
136
+ miniData.STRUCTS = requiredStructs;
137
+ }
138
+ const content = yaml.dump(miniData, {
139
+ indent: 2,
140
+ lineWidth: -1,
141
+ noRefs: true
142
+ });
143
+ const methodList = Object.values(methods).map((method) => {
144
+ var _a, _b;
145
+ return ((_a = method.HTTP) === null || _a === void 0 ? void 0 : _a.METHOD) || ((_b = method.INTERFACE) === null || _b === void 0 ? void 0 : _b.NAME) || Object.keys(methods)[0];
146
+ }).filter(Boolean);
147
+ const metadata = {
148
+ methods: methodList,
149
+ structs: Object.keys(requiredStructs),
150
+ filename: generateFilename(groupKey, type, endpoint, interfaceName, source)
151
+ };
152
+ if (endpoint)
153
+ metadata.endpoint = `/${endpoint}`;
154
+ if (interfaceName)
155
+ metadata.interface = interfaceName;
156
+ if (source)
157
+ metadata.source = source;
158
+ return { content, metadata };
159
+ }
160
+ function extractTypeFromInput(value) {
161
+ if (typeof value === 'string')
162
+ return value;
163
+ if (value && typeof value === 'object' && 'TYPE' in value)
164
+ return value.TYPE;
165
+ return null;
166
+ }
167
+ function collectStructRefsFromType(type, structRefs) {
168
+ const structNames = extractAllStructNames(type);
169
+ for (const structName of structNames) {
170
+ if (structName)
171
+ structRefs.add(structName);
172
+ }
173
+ }
174
+ function collectRequiredStructs(methods, allStructs) {
175
+ var _a, _b;
176
+ const requiredStructs = {};
177
+ const processedStructs = new Set();
178
+ const structRefs = new Set();
179
+ for (const methodData of Object.values(methods)) {
180
+ if (methodData.INPUTS) {
181
+ for (const input of methodData.INPUTS) {
182
+ for (const value of Object.values(input)) {
183
+ const type = extractTypeFromInput(value);
184
+ if (type)
185
+ collectStructRefsFromType(type, structRefs);
186
+ }
187
+ }
188
+ }
189
+ if (methodData.RETURNS) {
190
+ for (const ret of methodData.RETURNS) {
191
+ if (ret.RETURNTYPE)
192
+ collectStructRefsFromType(ret.RETURNTYPE, structRefs);
193
+ }
194
+ }
195
+ if (methodData.ERRORS) {
196
+ for (const error of methodData.ERRORS) {
197
+ if (error.TYPE)
198
+ collectStructRefsFromType(error.TYPE, structRefs);
199
+ }
200
+ }
201
+ if ((_b = (_a = methodData.ASYNC) === null || _a === void 0 ? void 0 : _a.RESULT) === null || _b === void 0 ? void 0 : _b.TYPE) {
202
+ collectStructRefsFromType(methodData.ASYNC.RESULT.TYPE, structRefs);
203
+ }
204
+ }
205
+ for (const structName of structRefs) {
206
+ collectStructRecursively(structName, allStructs, requiredStructs, processedStructs);
207
+ }
208
+ return requiredStructs;
209
+ }
210
+ function collectStructRecursively(structName, allStructs, requiredStructs, processedStructs) {
211
+ if (processedStructs.has(structName) || !allStructs[structName]) {
212
+ return;
213
+ }
214
+ processedStructs.add(structName);
215
+ requiredStructs[structName] = allStructs[structName];
216
+ const structFields = allStructs[structName];
217
+ if (Array.isArray(structFields)) {
218
+ for (const field of structFields) {
219
+ if (field.type) {
220
+ const nestedStructNames = extractAllStructNames(field.type);
221
+ for (const nestedStructName of nestedStructNames) {
222
+ if (nestedStructName) {
223
+ collectStructRecursively(nestedStructName, allStructs, requiredStructs, processedStructs);
224
+ }
225
+ }
226
+ }
227
+ }
228
+ }
229
+ }
230
+ const STRUCT_REGEX = /^STRUCT\(([^)]+)\)/;
231
+ const ARRAY_STRUCT_REGEX = /^\[\]STRUCT\(([^)]+)\)/;
232
+ const MAP_STRUCT_REGEX = /map\[[^\]]+\]STRUCT\(([^)]+)\)/;
233
+ function extractAllStructNames(typeString) {
234
+ const matches = [];
235
+ const match1 = typeString.match(STRUCT_REGEX);
236
+ const match2 = typeString.match(ARRAY_STRUCT_REGEX);
237
+ const match3 = typeString.match(MAP_STRUCT_REGEX);
238
+ if (match1)
239
+ matches.push(match1[1]);
240
+ if (match2)
241
+ matches.push(match2[1]);
242
+ if (match3)
243
+ matches.push(match3[1]);
244
+ return matches;
245
+ }
246
+ function sanitizeFilename(name) {
247
+ return name
248
+ .replace(constants_1.FILENAME_LEADING_SLASHES, '')
249
+ .replace(constants_1.FILENAME_TRAILING_SLASHES, '')
250
+ .replace(constants_1.FILENAME_INVALID_CHARS, '-')
251
+ .replace(constants_1.FILENAME_MULTIPLE_HYPHENS, '-')
252
+ .replace(constants_1.FILENAME_LEADING_TRAILING_HYPHENS, '');
253
+ }
254
+ function generateFilename(groupKey, type, endpoint, interfaceName, source) {
255
+ let cleanName;
256
+ if (type === 'http' && endpoint) {
257
+ cleanName = sanitizeFilename(endpoint);
258
+ }
259
+ else if (type === 'sdk') {
260
+ if (interfaceName) {
261
+ cleanName = sanitizeFilename(interfaceName);
262
+ if (source) {
263
+ const cleanSource = sanitizeFilename(source);
264
+ cleanName = `${cleanSource}-${cleanName}`;
265
+ }
266
+ }
267
+ else if (source) {
268
+ // SDK methods grouped by SOURCE only (no interface name)
269
+ cleanName = sanitizeFilename(source);
270
+ }
271
+ else {
272
+ // Fallback: use method name from groupKey
273
+ cleanName = sanitizeFilename(groupKey.replace(constants_1.GROUP_PREFIX_SDK, ''));
274
+ }
275
+ }
276
+ else {
277
+ cleanName = sanitizeFilename(groupKey.replace(constants_1.GROUP_PREFIX_OTHER, ''));
278
+ }
279
+ return `${constants_1.MINI_FILENAME_PREFIX}${cleanName}${constants_1.YAML_EXTENSION}`;
280
+ }
281
+ function saveMiniWrekenfiles(miniWrekenfiles, outputDir = constants_1.DEFAULT_MINI_OUTPUT_DIR) {
282
+ if (!fs.existsSync(outputDir)) {
283
+ fs.mkdirSync(outputDir, { recursive: true });
284
+ }
285
+ for (const miniFile of miniWrekenfiles) {
286
+ const filePath = `${outputDir}/${miniFile.metadata.filename}`;
287
+ fs.writeFileSync(filePath, miniFile.content);
288
+ }
289
+ }
@@ -0,0 +1,2 @@
1
+ declare function generateWrekenfile(spec: any, baseDir: string): string;
2
+ export { generateWrekenfile };