swagger-sdk-generator 0.0.0-stage → 3.0.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/README.md +58 -2
- package/dist/cli/commands/generate.d.ts +2 -0
- package/dist/cli/commands/generate.js +196 -0
- package/dist/cli/commands/init.d.ts +2 -0
- package/dist/cli/commands/init.js +130 -0
- package/dist/cli/commands/inspect.d.ts +2 -0
- package/dist/cli/commands/inspect.js +164 -0
- package/dist/cli/commands/templates.d.ts +2 -0
- package/dist/cli/commands/templates.js +126 -0
- package/dist/cli/context.d.ts +16 -0
- package/dist/cli/context.js +85 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +25 -0
- package/dist/config/dotenv.d.ts +2 -0
- package/dist/config/dotenv.js +82 -0
- package/dist/config/interpolate.d.ts +8 -0
- package/dist/config/interpolate.js +85 -0
- package/dist/config/load.d.ts +11 -0
- package/dist/config/load.js +182 -0
- package/dist/config/migrate-v3.d.ts +5 -0
- package/dist/config/migrate-v3.js +6 -0
- package/dist/config/mode-compatibility.d.ts +9 -0
- package/dist/config/mode-compatibility.js +17 -0
- package/dist/config/modes.d.ts +13 -0
- package/dist/config/modes.js +27 -0
- package/dist/config/preset-definitions.d.ts +2 -0
- package/dist/config/preset-definitions.js +4 -0
- package/dist/config/presets.d.ts +25 -0
- package/dist/config/presets.js +36 -0
- package/dist/config/resolve.d.ts +32 -0
- package/dist/config/resolve.js +288 -0
- package/dist/config/schema.d.ts +93 -0
- package/dist/config/schema.js +173 -0
- package/dist/config/types.d.ts +42 -0
- package/dist/config/types.js +2 -0
- package/dist/config/workspace.d.ts +30 -0
- package/dist/config/workspace.js +95 -0
- package/dist/core/case-align.d.ts +5 -0
- package/dist/core/case-align.js +90 -0
- package/dist/core/deep-merge.d.ts +2 -0
- package/dist/core/deep-merge.js +21 -0
- package/dist/core/file-set.d.ts +10 -0
- package/dist/core/file-set.js +31 -0
- package/dist/core/import-module.d.ts +1 -0
- package/dist/core/import-module.js +61 -0
- package/dist/core/log.d.ts +9 -0
- package/dist/core/log.js +24 -0
- package/dist/core/manifest.d.ts +17 -0
- package/dist/core/manifest.js +195 -0
- package/dist/core/overlaps.d.ts +6 -0
- package/dist/core/overlaps.js +67 -0
- package/dist/core/package-version.d.ts +1 -0
- package/dist/core/package-version.js +44 -0
- package/dist/core/pipeline.d.ts +30 -0
- package/dist/core/pipeline.js +335 -0
- package/dist/core/plugin.d.ts +72 -0
- package/dist/core/plugin.js +2 -0
- package/dist/core/targets.d.ts +14 -0
- package/dist/core/targets.js +120 -0
- package/dist/core/unmanaged.d.ts +3 -0
- package/dist/core/unmanaged.js +101 -0
- package/dist/core/writer.d.ts +28 -0
- package/dist/core/writer.js +148 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +37 -0
- package/dist/ir/casing.d.ts +5 -0
- package/dist/ir/casing.js +22 -0
- package/dist/ir/graph.d.ts +8 -0
- package/dist/ir/graph.js +95 -0
- package/dist/ir/operations/grouping.d.ts +17 -0
- package/dist/ir/operations/grouping.js +39 -0
- package/dist/ir/operations/legacy-naming.d.ts +2 -0
- package/dist/ir/operations/legacy-naming.js +8 -0
- package/dist/ir/operations/naming.d.ts +6 -0
- package/dist/ir/operations/naming.js +54 -0
- package/dist/ir/option-errors.d.ts +3 -0
- package/dist/ir/option-errors.js +68 -0
- package/dist/ir/transforms/builtins.d.ts +2 -0
- package/dist/ir/transforms/builtins.js +4 -0
- package/dist/ir/transforms/index.d.ts +10 -0
- package/dist/ir/transforms/index.js +39 -0
- package/dist/ir/transforms/types.d.ts +9 -0
- package/dist/ir/transforms/types.js +2 -0
- package/dist/ir/types.d.ts +140 -0
- package/dist/ir/types.js +2 -0
- package/dist/runtime/axios.d.ts +28 -0
- package/dist/runtime/axios.js +132 -0
- package/dist/runtime/fetch.d.ts +6 -0
- package/dist/runtime/fetch.js +38 -0
- package/dist/runtime/index.d.ts +54 -0
- package/dist/runtime/index.js +167 -0
- package/dist/runtime/rtk.d.ts +35 -0
- package/dist/runtime/rtk.js +36 -0
- package/dist/runtime/transport.d.ts +38 -0
- package/dist/runtime/transport.js +30 -0
- package/dist/runtime/wire.d.ts +27 -0
- package/dist/runtime/wire.js +148 -0
- package/dist/spec/html-entities.d.ts +1 -0
- package/dist/spec/html-entities.js +25 -0
- package/dist/spec/load.d.ts +26 -0
- package/dist/spec/load.js +130 -0
- package/dist/spec/openapi/all-of.d.ts +3 -0
- package/dist/spec/openapi/all-of.js +9 -0
- package/dist/spec/openapi/normalize.d.ts +4 -0
- package/dist/spec/openapi/normalize.js +31 -0
- package/dist/spec/openapi/operations.d.ts +4 -0
- package/dist/spec/openapi/operations.js +173 -0
- package/dist/spec/openapi/schema.d.ts +51 -0
- package/dist/spec/openapi/schema.js +307 -0
- package/dist/targets/declarative/config.d.ts +533 -0
- package/dist/targets/declarative/config.js +280 -0
- package/dist/targets/declarative/extensions.d.ts +45 -0
- package/dist/targets/declarative/extensions.js +123 -0
- package/dist/targets/declarative/files.d.ts +13 -0
- package/dist/targets/declarative/files.js +127 -0
- package/dist/targets/declarative/format.d.ts +4 -0
- package/dist/targets/declarative/format.js +104 -0
- package/dist/targets/declarative/index.d.ts +9 -0
- package/dist/targets/declarative/index.js +170 -0
- package/dist/targets/declarative/liquid.d.ts +8 -0
- package/dist/targets/declarative/liquid.js +57 -0
- package/dist/targets/declarative/naming-case.d.ts +3 -0
- package/dist/targets/declarative/naming-case.js +31 -0
- package/dist/targets/declarative/naming.d.ts +42 -0
- package/dist/targets/declarative/naming.js +174 -0
- package/dist/targets/declarative/scaffold.d.ts +5 -0
- package/dist/targets/declarative/scaffold.js +146 -0
- package/dist/targets/declarative/types.d.ts +52 -0
- package/dist/targets/declarative/types.js +287 -0
- package/dist/targets/declarative/views.d.ts +180 -0
- package/dist/targets/declarative/views.js +447 -0
- package/dist/targets/python/extensions.js +152 -0
- package/dist/targets/python/target.json +549 -0
- package/dist/targets/python/templates/client/client.liquid +114 -0
- package/dist/targets/python/templates/client/httpx_transport.liquid +172 -0
- package/dist/targets/python/templates/client/init.liquid +20 -0
- package/dist/targets/python/templates/client/partials/operation_method.liquid +41 -0
- package/dist/targets/python/templates/client/resource.liquid +28 -0
- package/dist/targets/python/templates/client/runtime.liquid +133 -0
- package/dist/targets/python/templates/client/transport.liquid +62 -0
- package/dist/targets/python/templates/models/module.liquid +48 -0
- package/dist/targets/python/templates/models/partials/docstring.liquid +5 -0
- package/dist/targets/python/templates/models/partials/enum_class.liquid +11 -0
- package/dist/targets/python/templates/models/partials/field_line.liquid +5 -0
- package/dist/targets/python/templates/models/partials/model_class.liquid +17 -0
- package/dist/targets/typescript/compatibility-naming.d.ts +6 -0
- package/dist/targets/typescript/compatibility-naming.js +28 -0
- package/dist/targets/typescript/compatibility-options.d.ts +5 -0
- package/dist/targets/typescript/compatibility-options.js +8 -0
- package/dist/targets/typescript/compatibility-target.d.ts +5 -0
- package/dist/targets/typescript/compatibility-target.js +10 -0
- package/dist/targets/typescript/http-operations.d.ts +34 -0
- package/dist/targets/typescript/http-operations.js +155 -0
- package/dist/targets/typescript/imports.d.ts +43 -0
- package/dist/targets/typescript/imports.js +154 -0
- package/dist/targets/typescript/index.d.ts +7 -0
- package/dist/targets/typescript/index.js +52 -0
- package/dist/targets/typescript/mock-compatibility.d.ts +4 -0
- package/dist/targets/typescript/mock-compatibility.js +6 -0
- package/dist/targets/typescript/mock-hints.d.ts +13 -0
- package/dist/targets/typescript/mock-hints.js +75 -0
- package/dist/targets/typescript/mock-reachability.d.ts +12 -0
- package/dist/targets/typescript/mock-reachability.js +87 -0
- package/dist/targets/typescript/model-compatibility.d.ts +14 -0
- package/dist/targets/typescript/model-compatibility.js +16 -0
- package/dist/targets/typescript/naming.d.ts +13 -0
- package/dist/targets/typescript/naming.js +50 -0
- package/dist/targets/typescript/options.d.ts +124 -0
- package/dist/targets/typescript/options.js +90 -0
- package/dist/targets/typescript/outputs/client.d.ts +67 -0
- package/dist/targets/typescript/outputs/client.js +187 -0
- package/dist/targets/typescript/outputs/mocks.d.ts +32 -0
- package/dist/targets/typescript/outputs/mocks.js +371 -0
- package/dist/targets/typescript/outputs/models.d.ts +85 -0
- package/dist/targets/typescript/outputs/models.js +246 -0
- package/dist/targets/typescript/outputs/rtk-query.d.ts +69 -0
- package/dist/targets/typescript/outputs/rtk-query.js +266 -0
- package/dist/targets/typescript/prettier.d.ts +7 -0
- package/dist/targets/typescript/prettier.js +44 -0
- package/dist/targets/typescript/templates/client/client.liquid +30 -0
- package/dist/targets/typescript/templates/client/partials/api-member.liquid +13 -0
- package/dist/targets/typescript/templates/client/partials/jsdoc.liquid +10 -0
- package/dist/targets/typescript/templates/client/partials/method.liquid +26 -0
- package/dist/targets/typescript/templates/client/partials/query-type.liquid +10 -0
- package/dist/targets/typescript/templates/client/resource.liquid +34 -0
- package/dist/targets/typescript/templates/mocks/mock.liquid +15 -0
- package/dist/targets/typescript/templates/mocks/partials/factory.liquid +12 -0
- package/dist/targets/typescript/templates/mocks/partials/imports.liquid +7 -0
- package/dist/targets/typescript/templates/models/alias.liquid +16 -0
- package/dist/targets/typescript/templates/models/enum.liquid +27 -0
- package/dist/targets/typescript/templates/models/index.liquid +14 -0
- package/dist/targets/typescript/templates/models/model.liquid +25 -0
- package/dist/targets/typescript/templates/models/partials/const.liquid +10 -0
- package/dist/targets/typescript/templates/models/partials/imports.liquid +9 -0
- package/dist/targets/typescript/templates/models/partials/jsdoc.liquid +9 -0
- package/dist/targets/typescript/templates/models/partials/property.liquid +7 -0
- package/dist/targets/typescript/templates/rtk-query/api.liquid +16 -0
- package/dist/targets/typescript/templates/rtk-query/partials/arg-types.liquid +6 -0
- package/dist/targets/typescript/templates/rtk-query/partials/endpoint-mutation.liquid +13 -0
- package/dist/targets/typescript/templates/rtk-query/partials/endpoint-query.liquid +13 -0
- package/dist/targets/typescript/templates/rtk-query/partials/file-warning.liquid +7 -0
- package/dist/targets/typescript/templates/rtk-query/partials/hooks.liquid +9 -0
- package/dist/targets/typescript/templates/rtk-query/partials/imports.liquid +7 -0
- package/dist/targets/typescript/templates/rtk-query/partials/request-config.liquid +9 -0
- package/dist/targets/typescript/templates/rtk-query/resource.liquid +40 -0
- package/dist/targets/typescript/ts-type.d.ts +70 -0
- package/dist/targets/typescript/ts-type.js +62 -0
- package/dist/targets/typescript/type-printer.d.ts +21 -0
- package/dist/targets/typescript/type-printer.js +115 -0
- package/dist/templates/engine.d.ts +20 -0
- package/dist/templates/engine.js +161 -0
- package/dist/templates/inspect.d.ts +27 -0
- package/dist/templates/inspect.js +331 -0
- package/package.json +65 -4
- package/schema/sdk-gen.local.schema.json +75 -0
- package/schema/sdk-gen.schema.json +980 -0
- package/schema/sdk-gen.target.schema.json +1384 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JS_RESERVED = void 0;
|
|
4
|
+
exports.endpointFullPath = endpointFullPath;
|
|
5
|
+
exports.withUndeclaredPathParams = withUndeclaredPathParams;
|
|
6
|
+
exports.pathParamLocals = pathParamLocals;
|
|
7
|
+
exports.safeLocalName = safeLocalName;
|
|
8
|
+
exports.pathTemplateWithLocals = pathTemplateWithLocals;
|
|
9
|
+
exports.headerParamKeys = headerParamKeys;
|
|
10
|
+
exports.renamedHeaderDoc = renamedHeaderDoc;
|
|
11
|
+
exports.pickJsonContent = pickJsonContent;
|
|
12
|
+
exports.pickContent = pickContent;
|
|
13
|
+
exports.requestMedia = requestMedia;
|
|
14
|
+
exports.isBinaryResponse = isBinaryResponse;
|
|
15
|
+
exports.successContent = successContent;
|
|
16
|
+
exports.responseKind = responseKind;
|
|
17
|
+
exports.supportedOperations = supportedOperations;
|
|
18
|
+
exports.docLines = docLines;
|
|
19
|
+
exports.claimUnique = claimUnique;
|
|
20
|
+
exports.modelPeersWithFallback = modelPeersWithFallback;
|
|
21
|
+
const casing_1 = require("../../ir/casing");
|
|
22
|
+
const grouping_1 = require("../../ir/operations/grouping");
|
|
23
|
+
const imports_1 = require("./imports");
|
|
24
|
+
const type_printer_1 = require("./type-printer");
|
|
25
|
+
function endpointFullPath(pathString, options) {
|
|
26
|
+
const cleared = (0, grouping_1.stripPrefix)(pathString, options.stripPrefixes);
|
|
27
|
+
const base = options.basePath.replace(/^\/+|\/+$/g, '');
|
|
28
|
+
return `${base ? `/${base}` : ''}${cleared}`;
|
|
29
|
+
}
|
|
30
|
+
function withUndeclaredPathParams(operation, legacy) {
|
|
31
|
+
const declared = new Set(operation.parameters.filter((param) => param.in === 'path').map((param) => param.name));
|
|
32
|
+
const healed = [];
|
|
33
|
+
for (const match of operation.path.matchAll(/\{([^{}]+)\}/g)) {
|
|
34
|
+
const name = match[1];
|
|
35
|
+
if (declared.has(name))
|
|
36
|
+
continue;
|
|
37
|
+
declared.add(name);
|
|
38
|
+
const schema = { type: legacy ? 'number' : 'string' };
|
|
39
|
+
healed.push({ name, in: 'path', required: true, type: { kind: 'primitive', type: schema.type }, raw: { name, in: 'path', required: true, schema } });
|
|
40
|
+
}
|
|
41
|
+
return healed.length ? Object.assign(Object.assign({}, operation), { parameters: [...operation.parameters, ...healed] }) : operation;
|
|
42
|
+
}
|
|
43
|
+
function pathParamLocals(operation, reserved) {
|
|
44
|
+
const names = new Map();
|
|
45
|
+
const claimed = new Set([...reserved, ...exports.JS_RESERVED]);
|
|
46
|
+
for (const param of operation.parameters.filter((p) => p.in === 'path')) {
|
|
47
|
+
const base = safeLocalName(param.name);
|
|
48
|
+
let candidate = claimed.has(base) ? `${base}Param` : base;
|
|
49
|
+
for (let counter = 2; claimed.has(candidate); counter++)
|
|
50
|
+
candidate = `${base}${counter}`;
|
|
51
|
+
claimed.add(candidate);
|
|
52
|
+
names.set(param.name, candidate);
|
|
53
|
+
}
|
|
54
|
+
return names;
|
|
55
|
+
}
|
|
56
|
+
function safeLocalName(name) {
|
|
57
|
+
const candidate = (0, imports_1.toIdentifier)((0, casing_1.camelCase)(name.replace(/[^A-Za-z0-9_$]+/g, ' ')).replace(/^_+/, '')) || 'param';
|
|
58
|
+
return candidate === '_' ? 'param' : candidate;
|
|
59
|
+
}
|
|
60
|
+
function pathTemplateWithLocals(fullPath, localNames, encode = false) {
|
|
61
|
+
return fullPath
|
|
62
|
+
.split(/(\{[^}]+\})/)
|
|
63
|
+
.map((part) => {
|
|
64
|
+
var _a;
|
|
65
|
+
var _b;
|
|
66
|
+
const param = (_a = /^\{([^}]+)\}$/.exec(part)) === null || _a === void 0 ? void 0 : _a[1];
|
|
67
|
+
if (param !== undefined) {
|
|
68
|
+
const local = (_b = localNames.get(param)) !== null && _b !== void 0 ? _b : safeLocalName(param);
|
|
69
|
+
return '${' + (encode ? `encodeURIComponent(String(${local}))` : local) + '}';
|
|
70
|
+
}
|
|
71
|
+
return part.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\$\{/g, '\\${');
|
|
72
|
+
})
|
|
73
|
+
.join('');
|
|
74
|
+
}
|
|
75
|
+
function headerParamKeys(parameters) {
|
|
76
|
+
const queryNames = new Set(parameters.filter((p) => p.in === 'query').map((p) => p.name));
|
|
77
|
+
const taken = new Set(parameters.filter((p) => p.in === 'query' || p.in === 'header').map((p) => p.name));
|
|
78
|
+
const keys = new Map();
|
|
79
|
+
for (const param of parameters.filter((p) => p.in === 'header')) {
|
|
80
|
+
keys.set(param, queryNames.has(param.name) ? claimUnique(`${param.name}Header`, taken) : param.name);
|
|
81
|
+
}
|
|
82
|
+
return keys;
|
|
83
|
+
}
|
|
84
|
+
function renamedHeaderDoc(param, key) {
|
|
85
|
+
return key !== undefined && key !== param.name ? [`Sent as request header \`${param.name.replace(/\*\//g, '*\\/')}\`.`] : [];
|
|
86
|
+
}
|
|
87
|
+
function pickJsonContent(contents) {
|
|
88
|
+
return contents.find((content) => /(^|[/+])json($|[;\s])/i.test(content.mediaType));
|
|
89
|
+
}
|
|
90
|
+
function pickContent(contents) {
|
|
91
|
+
var _a;
|
|
92
|
+
return (_a = pickJsonContent(contents)) !== null && _a !== void 0 ? _a : contents[0];
|
|
93
|
+
}
|
|
94
|
+
function requestMedia(contents, print) {
|
|
95
|
+
var _a, _b, _c;
|
|
96
|
+
const multipart = contents.find((c) => c.mediaType === 'multipart/form-data');
|
|
97
|
+
const chosen = (_c = (_b = (_a = pickJsonContent(contents)) !== null && _a !== void 0 ? _a : multipart) !== null && _b !== void 0 ? _b : contents.find((c) => c.mediaType === 'application/x-www-form-urlencoded')) !== null && _c !== void 0 ? _c : contents[0];
|
|
98
|
+
if (!chosen)
|
|
99
|
+
return { contentType: 'application/json', type: '' };
|
|
100
|
+
const type = chosen === multipart ? 'FormData' : (0, type_printer_1.printType)(chosen.type, print);
|
|
101
|
+
return { contentType: chosen.mediaType, type };
|
|
102
|
+
}
|
|
103
|
+
function isBinaryResponse(responses) {
|
|
104
|
+
return responses.some((response) => response.status.startsWith('2') &&
|
|
105
|
+
response.contents.some((content) => content.mediaType === 'application/pdf' || content.mediaType === 'application/octet-stream'));
|
|
106
|
+
}
|
|
107
|
+
function successContent(responses) {
|
|
108
|
+
const success = responses.filter((response) => response.status.startsWith('2'));
|
|
109
|
+
return success[0] ? pickContent(success[0].contents) : undefined;
|
|
110
|
+
}
|
|
111
|
+
function responseKind(responses) {
|
|
112
|
+
if (isBinaryResponse(responses))
|
|
113
|
+
return 'blob';
|
|
114
|
+
const content = successContent(responses);
|
|
115
|
+
if (content && !pickJsonContent([content]) && /^text\//i.test(content.mediaType))
|
|
116
|
+
return 'text';
|
|
117
|
+
return 'json';
|
|
118
|
+
}
|
|
119
|
+
function supportedOperations(output, operations, group, warn) {
|
|
120
|
+
return operations.filter((operation) => {
|
|
121
|
+
if (operation.method === 'head' || operation.method === 'options' || operation.method === 'trace') {
|
|
122
|
+
warn(output === 'stores'
|
|
123
|
+
? `stores: skipped ${operation.method.toUpperCase()} ${operation.path} in "${group.key}" because HttpStore has no ${operation.method}() runtime method`
|
|
124
|
+
: `${output}: skipped ${operation.method.toUpperCase()} ${operation.path} in "${group.key}" (the transport contract has no ${operation.method})`);
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
return true;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
function docLines(text) {
|
|
131
|
+
if (!(text === null || text === void 0 ? void 0 : text.trim()))
|
|
132
|
+
return [];
|
|
133
|
+
return text
|
|
134
|
+
.replace(/\*\//g, '*\\/')
|
|
135
|
+
.split('\n')
|
|
136
|
+
.map((line) => line.trimEnd());
|
|
137
|
+
}
|
|
138
|
+
function claimUnique(base, claimed, keyOf = (name) => name) {
|
|
139
|
+
let name = base;
|
|
140
|
+
for (let counter = 2; claimed.has(keyOf(name)); counter++)
|
|
141
|
+
name = `${base}${counter}`;
|
|
142
|
+
claimed.add(keyOf(name));
|
|
143
|
+
return name;
|
|
144
|
+
}
|
|
145
|
+
exports.JS_RESERVED = [
|
|
146
|
+
'await', 'break', 'case', 'catch', 'class', 'const', 'continue', 'debugger', 'default', 'delete', 'do', 'else',
|
|
147
|
+
'enum', 'export', 'extends', 'false', 'finally', 'for', 'function', 'if', 'import', 'in', 'instanceof', 'new',
|
|
148
|
+
'null', 'return', 'super', 'switch', 'this', 'throw', 'true', 'try', 'typeof', 'var', 'void', 'while', 'with', 'yield',
|
|
149
|
+
];
|
|
150
|
+
function modelPeersWithFallback(ctx) {
|
|
151
|
+
const models = ctx.peers.models;
|
|
152
|
+
if ((models === null || models === void 0 ? void 0 : models.enabled) || (models === null || models === void 0 ? void 0 : models.importPath))
|
|
153
|
+
return ctx.peers;
|
|
154
|
+
return Object.assign(Object.assign({}, ctx.peers), { models: Object.assign(Object.assign({}, models), { importPath: '@models/swagger' }) });
|
|
155
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ApiSpec, Model, ModelId } from '../../ir/types';
|
|
2
|
+
import type { PeerOptions } from '../../core/plugin';
|
|
3
|
+
import type { ModelsOptions } from './options';
|
|
4
|
+
export interface ModelLocator {
|
|
5
|
+
model(id: ModelId): Model | undefined;
|
|
6
|
+
typeName(id: ModelId): string;
|
|
7
|
+
modulePath(id: ModelId): string;
|
|
8
|
+
specifier(id: ModelId, fromFile: string): string;
|
|
9
|
+
}
|
|
10
|
+
export interface ModelLocation {
|
|
11
|
+
dir: string;
|
|
12
|
+
layout: ModelsOptions['layout'];
|
|
13
|
+
importPath?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function createModelLocator(api: ApiSpec, location: ModelLocation): ModelLocator;
|
|
16
|
+
export declare function locatorFromPeers(api: ApiSpec, peers: Record<string, PeerOptions>): ModelLocator;
|
|
17
|
+
export declare function relativeSpecifier(fromFile: string, toModule: string): string;
|
|
18
|
+
export declare function toIdentifier(raw: string): string;
|
|
19
|
+
export interface ImportDeclaration {
|
|
20
|
+
specifier: string;
|
|
21
|
+
typeOnly: boolean;
|
|
22
|
+
names: Array<{
|
|
23
|
+
name: string;
|
|
24
|
+
alias?: string;
|
|
25
|
+
}>;
|
|
26
|
+
}
|
|
27
|
+
export declare class ImportCollector {
|
|
28
|
+
readonly fromFile: string;
|
|
29
|
+
private readonly locator?;
|
|
30
|
+
private readonly decls;
|
|
31
|
+
private readonly locals;
|
|
32
|
+
constructor(fromFile: string, locator?: ModelLocator | undefined);
|
|
33
|
+
reserve(...names: string[]): this;
|
|
34
|
+
named(specifier: string, name: string, options?: {
|
|
35
|
+
typeOnly?: boolean;
|
|
36
|
+
}): string;
|
|
37
|
+
model(id: ModelId, options?: {
|
|
38
|
+
typeOnly?: boolean;
|
|
39
|
+
selfId?: ModelId;
|
|
40
|
+
}): string;
|
|
41
|
+
list(): ImportDeclaration[];
|
|
42
|
+
private freeLocal;
|
|
43
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
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.ImportCollector = void 0;
|
|
37
|
+
exports.createModelLocator = createModelLocator;
|
|
38
|
+
exports.locatorFromPeers = locatorFromPeers;
|
|
39
|
+
exports.relativeSpecifier = relativeSpecifier;
|
|
40
|
+
exports.toIdentifier = toIdentifier;
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
function createModelLocator(api, location) {
|
|
43
|
+
const byId = new Map(api.models.map((m) => [m.id, m]));
|
|
44
|
+
const typeName = (id) => {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
const model = byId.get(id);
|
|
47
|
+
if (location.layout === 'flat')
|
|
48
|
+
return toIdentifier(id);
|
|
49
|
+
return toIdentifier((_b = (_a = model === null || model === void 0 ? void 0 : model.name) !== null && _a !== void 0 ? _a : id.split('.').pop()) !== null && _b !== void 0 ? _b : id);
|
|
50
|
+
};
|
|
51
|
+
const modulePath = (id) => {
|
|
52
|
+
if (location.layout === 'flat')
|
|
53
|
+
return toIdentifier(id);
|
|
54
|
+
const model = byId.get(id);
|
|
55
|
+
const segments = model ? [...model.namespace, model.name] : id.split('.');
|
|
56
|
+
return segments.join('/');
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
model: (id) => byId.get(id),
|
|
60
|
+
typeName,
|
|
61
|
+
modulePath,
|
|
62
|
+
specifier(id, fromFile) {
|
|
63
|
+
const target = modulePath(id);
|
|
64
|
+
if (location.importPath)
|
|
65
|
+
return `${location.importPath.replace(/\/+$/, '')}/${target}`;
|
|
66
|
+
return relativeSpecifier(fromFile, path.join(location.dir, ...target.split('/')));
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function locatorFromPeers(api, peers) {
|
|
71
|
+
var _a;
|
|
72
|
+
const models = peers.models;
|
|
73
|
+
if (!models)
|
|
74
|
+
throw new Error('TypeScript target has no "models" output to locate model types');
|
|
75
|
+
return createModelLocator(api, {
|
|
76
|
+
dir: models.dir,
|
|
77
|
+
layout: (_a = models.layout) !== null && _a !== void 0 ? _a : 'namespace',
|
|
78
|
+
importPath: models.importPath,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function relativeSpecifier(fromFile, toModule) {
|
|
82
|
+
const relative = path.relative(path.dirname(fromFile), toModule);
|
|
83
|
+
if (path.isAbsolute(relative)) {
|
|
84
|
+
throw new Error(`Cannot import ${toModule} relatively from ${fromFile} (different drive/root) — set models.importPath`);
|
|
85
|
+
}
|
|
86
|
+
let rel = relative.split(path.sep).join('/');
|
|
87
|
+
if (!rel.startsWith('.'))
|
|
88
|
+
rel = `./${rel}`;
|
|
89
|
+
return rel;
|
|
90
|
+
}
|
|
91
|
+
function toIdentifier(raw) {
|
|
92
|
+
const cleaned = raw.replace(/[^A-Za-z0-9_$]/g, '_');
|
|
93
|
+
return /^[0-9]/.test(cleaned) ? `_${cleaned}` : cleaned;
|
|
94
|
+
}
|
|
95
|
+
class ImportCollector {
|
|
96
|
+
constructor(fromFile, locator) {
|
|
97
|
+
this.fromFile = fromFile;
|
|
98
|
+
this.locator = locator;
|
|
99
|
+
this.decls = new Map();
|
|
100
|
+
this.locals = new Map();
|
|
101
|
+
}
|
|
102
|
+
reserve(...names) {
|
|
103
|
+
for (const n of names)
|
|
104
|
+
this.locals.set(n, `#local#${n}`);
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
named(specifier, name, options = {}) {
|
|
108
|
+
var _a, _b;
|
|
109
|
+
const key = `${specifier}#${name}`;
|
|
110
|
+
let decl = this.decls.get(specifier);
|
|
111
|
+
const existing = decl === null || decl === void 0 ? void 0 : decl.names.find((n) => n.name === name);
|
|
112
|
+
if (existing) {
|
|
113
|
+
if (!options.typeOnly)
|
|
114
|
+
decl.typeOnly = false;
|
|
115
|
+
return (_a = existing.alias) !== null && _a !== void 0 ? _a : existing.name;
|
|
116
|
+
}
|
|
117
|
+
const local = this.freeLocal(name, key, specifier);
|
|
118
|
+
this.locals.set(local, key);
|
|
119
|
+
if (!decl) {
|
|
120
|
+
decl = { specifier, typeOnly: (_b = options.typeOnly) !== null && _b !== void 0 ? _b : false, names: [] };
|
|
121
|
+
this.decls.set(specifier, decl);
|
|
122
|
+
}
|
|
123
|
+
else if (!options.typeOnly) {
|
|
124
|
+
decl.typeOnly = false;
|
|
125
|
+
}
|
|
126
|
+
decl.names.push(local === name ? { name } : { name, alias: local });
|
|
127
|
+
return local;
|
|
128
|
+
}
|
|
129
|
+
model(id, options = {}) {
|
|
130
|
+
var _a;
|
|
131
|
+
if (!this.locator)
|
|
132
|
+
throw new Error('ImportCollector.model() needs a ModelLocator');
|
|
133
|
+
const name = this.locator.typeName(id);
|
|
134
|
+
if (options.selfId === id)
|
|
135
|
+
return name;
|
|
136
|
+
return this.named(this.locator.specifier(id, this.fromFile), name, { typeOnly: (_a = options.typeOnly) !== null && _a !== void 0 ? _a : true });
|
|
137
|
+
}
|
|
138
|
+
list() {
|
|
139
|
+
return Array.from(this.decls.values());
|
|
140
|
+
}
|
|
141
|
+
freeLocal(name, key, specifier) {
|
|
142
|
+
var _a;
|
|
143
|
+
const owner = this.locals.get(name);
|
|
144
|
+
if (owner === undefined || owner === key)
|
|
145
|
+
return name;
|
|
146
|
+
const dir = (_a = specifier.split('/').slice(-2, -1)[0]) !== null && _a !== void 0 ? _a : '';
|
|
147
|
+
const base = `${toIdentifier(dir.charAt(0).toUpperCase() + dir.slice(1))}${name}`;
|
|
148
|
+
let candidate = base;
|
|
149
|
+
for (let i = 2; this.locals.has(candidate); i++)
|
|
150
|
+
candidate = `${base}${i}`;
|
|
151
|
+
return candidate;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
exports.ImportCollector = ImportCollector;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Target } from '../../core/plugin';
|
|
2
|
+
import { type TypeScriptCompatibilityOptions } from './compatibility-target';
|
|
3
|
+
import { type PrettierFormatterOptions } from './prettier';
|
|
4
|
+
export interface TypeScriptTargetOptions extends TypeScriptCompatibilityOptions {
|
|
5
|
+
prettier?: false | PrettierFormatterOptions;
|
|
6
|
+
}
|
|
7
|
+
export declare function createTypeScriptTarget(options?: TypeScriptTargetOptions): Target;
|
|
@@ -0,0 +1,52 @@
|
|
|
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.createTypeScriptTarget = createTypeScriptTarget;
|
|
37
|
+
const path = __importStar(require("path"));
|
|
38
|
+
const client_1 = require("./outputs/client");
|
|
39
|
+
const mocks_1 = require("./outputs/mocks");
|
|
40
|
+
const models_1 = require("./outputs/models");
|
|
41
|
+
const rtk_query_1 = require("./outputs/rtk-query");
|
|
42
|
+
const compatibility_target_1 = require("./compatibility-target");
|
|
43
|
+
const prettier_1 = require("./prettier");
|
|
44
|
+
function createTypeScriptTarget(options = {}) {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
return {
|
|
47
|
+
name: 'typescript',
|
|
48
|
+
templatesDir: path.join(__dirname, 'templates'),
|
|
49
|
+
outputs: [models_1.modelsOutput, client_1.clientOutput, ...compatibility_target_1.compatibilityOutputs, rtk_query_1.rtkQueryOutput, mocks_1.mocksOutput],
|
|
50
|
+
formatter: (_a = (0, compatibility_target_1.compatibilityFormatter)(options)) !== null && _a !== void 0 ? _a : (options.prettier === false ? undefined : (0, prettier_1.createPrettierFormatter)((_b = options.prettier) !== null && _b !== void 0 ? _b : {})),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type ScalarKind = 'string' | 'integer' | 'number';
|
|
2
|
+
export type HintExpressions = Partial<Record<ScalarKind, string>>;
|
|
3
|
+
export interface NameHint extends HintExpressions {
|
|
4
|
+
pattern: RegExp;
|
|
5
|
+
}
|
|
6
|
+
export interface MockHints {
|
|
7
|
+
formats: Record<string, HintExpressions>;
|
|
8
|
+
names: NameHint[];
|
|
9
|
+
defaults: Record<ScalarKind, string>;
|
|
10
|
+
}
|
|
11
|
+
export declare const FIXED_REF_DATE = "2020-01-01T00:00:00.000Z";
|
|
12
|
+
export declare const DEFAULT_MOCK_HINTS: MockHints;
|
|
13
|
+
export declare function scalarMock(kind: ScalarKind, format: string | undefined, name: string | undefined, hints?: MockHints): string;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_MOCK_HINTS = exports.FIXED_REF_DATE = void 0;
|
|
4
|
+
exports.scalarMock = scalarMock;
|
|
5
|
+
exports.FIXED_REF_DATE = '2020-01-01T00:00:00.000Z';
|
|
6
|
+
const DATE_TIME = `faker.date.recent({ refDate: '${exports.FIXED_REF_DATE}' }).toISOString()`;
|
|
7
|
+
const PRICE = {
|
|
8
|
+
number: 'faker.number.float({ min: 1, max: 1000, fractionDigits: 2 })',
|
|
9
|
+
integer: 'faker.number.int({ min: 1, max: 1000 })',
|
|
10
|
+
};
|
|
11
|
+
const COUNT = { integer: 'faker.number.int({ min: 0, max: 100 })' };
|
|
12
|
+
exports.DEFAULT_MOCK_HINTS = {
|
|
13
|
+
formats: {
|
|
14
|
+
'date-time': { string: DATE_TIME },
|
|
15
|
+
date: { string: `${DATE_TIME}.slice(0, 10)` },
|
|
16
|
+
email: { string: 'faker.internet.email()' },
|
|
17
|
+
uri: { string: 'faker.internet.url()' },
|
|
18
|
+
url: { string: 'faker.internet.url()' },
|
|
19
|
+
uuid: { string: 'faker.string.uuid()' },
|
|
20
|
+
hostname: { string: 'faker.internet.domainName()' },
|
|
21
|
+
ipv4: { string: 'faker.internet.ipv4()' },
|
|
22
|
+
ipv6: { string: 'faker.internet.ipv6()' },
|
|
23
|
+
},
|
|
24
|
+
names: [
|
|
25
|
+
{ pattern: /(^|_)(id|ID)$|Id$/, integer: 'faker.number.int({ min: 1, max: 100000 })', string: 'faker.string.uuid()' },
|
|
26
|
+
{ pattern: /e-?mail/i, string: 'faker.internet.email()' },
|
|
27
|
+
{ pattern: /(url|uri|link|website)$/i, string: 'faker.internet.url()' },
|
|
28
|
+
{ pattern: /phone|mobile/i, string: 'faker.phone.number()' },
|
|
29
|
+
{ pattern: /^first_?name$/i, string: 'faker.person.firstName()' },
|
|
30
|
+
{ pattern: /^(last|sur|family)_?name$/i, string: 'faker.person.lastName()' },
|
|
31
|
+
{ pattern: /^user_?name$/i, string: 'faker.internet.username()' },
|
|
32
|
+
{ pattern: /^company(_?name)?$/i, string: 'faker.company.name()' },
|
|
33
|
+
{ pattern: /^(full_?|display_?)?name$/i, string: 'faker.person.fullName()' },
|
|
34
|
+
{ pattern: /city$/i, string: 'faker.location.city()' },
|
|
35
|
+
{ pattern: /country_?code$/i, string: 'faker.location.countryCode()' },
|
|
36
|
+
{ pattern: /^country(_?name)?$/i, string: 'faker.location.country()' },
|
|
37
|
+
{ pattern: /zip|postal|post_?code/i, string: 'faker.location.zipCode()' },
|
|
38
|
+
{ pattern: /^(ip|IP)(_?[aA]ddress)?$|[a-z0-9]I[pP](Address)?$/, string: 'faker.internet.ipv4()' },
|
|
39
|
+
{ pattern: /street|address/i, string: 'faker.location.streetAddress()' },
|
|
40
|
+
{ pattern: /title$/i, string: 'faker.lorem.words(3)' },
|
|
41
|
+
{ pattern: /(description|content|text|message|comment)s?$/i, string: 'faker.lorem.sentence()' },
|
|
42
|
+
{ pattern: /(At|Date|_at|_date)$|^date$/, string: DATE_TIME },
|
|
43
|
+
Object.assign({ pattern: /(price|amount|total|cost)$/i }, PRICE),
|
|
44
|
+
Object.assign({ pattern: /(count|quantity|qty)$/i }, COUNT),
|
|
45
|
+
{ pattern: /^lat(itude)?$/i, number: 'faker.location.latitude()', integer: 'faker.number.int({ min: -90, max: 90 })' },
|
|
46
|
+
{ pattern: /^(lng|lon|long|longitude)$/i, number: 'faker.location.longitude()', integer: 'faker.number.int({ min: -180, max: 180 })' },
|
|
47
|
+
{ pattern: /colou?r$/i, string: 'faker.color.rgb()' },
|
|
48
|
+
{ pattern: /currency(_?code)?$/i, string: 'faker.finance.currencyCode()' },
|
|
49
|
+
{ pattern: /locale$/i, string: "faker.helpers.arrayElement(['en-US', 'de-DE', 'fr-FR', 'es-ES', 'it-IT'])" },
|
|
50
|
+
{ pattern: /token$/i, string: 'faker.string.alphanumeric(32)' },
|
|
51
|
+
{ pattern: /slug$/i, string: 'faker.lorem.slug()' },
|
|
52
|
+
],
|
|
53
|
+
defaults: {
|
|
54
|
+
string: 'faker.word.words()',
|
|
55
|
+
integer: 'faker.number.int()',
|
|
56
|
+
number: 'faker.number.float({ fractionDigits: 2 })',
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
const forKind = (hint, kind) => { var _a; return (_a = hint[kind]) !== null && _a !== void 0 ? _a : (kind === 'number' ? hint.integer : undefined); };
|
|
60
|
+
function scalarMock(kind, format, name, hints = exports.DEFAULT_MOCK_HINTS) {
|
|
61
|
+
const byFormat = format !== undefined ? hints.formats[format] : undefined;
|
|
62
|
+
const fromFormat = byFormat && forKind(byFormat, kind);
|
|
63
|
+
if (fromFormat)
|
|
64
|
+
return fromFormat;
|
|
65
|
+
if (name !== undefined) {
|
|
66
|
+
for (const hint of hints.names) {
|
|
67
|
+
if (!hint.pattern.test(name))
|
|
68
|
+
continue;
|
|
69
|
+
const expr = forKind(hint, kind);
|
|
70
|
+
if (expr)
|
|
71
|
+
return expr;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return hints.defaults[kind];
|
|
75
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ApiSpec, ModelId } from '../../ir/types';
|
|
2
|
+
import type { ModelLocator } from './imports';
|
|
3
|
+
export interface Reachability {
|
|
4
|
+
ids: Set<ModelId>;
|
|
5
|
+
unknown: string[];
|
|
6
|
+
scanned: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function findReachableMocks(api: ApiSpec, locator: ModelLocator, options: {
|
|
9
|
+
roots: string[];
|
|
10
|
+
subdir: string;
|
|
11
|
+
exclude: string[];
|
|
12
|
+
}): Reachability;
|
|
@@ -0,0 +1,87 @@
|
|
|
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.findReachableMocks = findReachableMocks;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const graph_1 = require("../../ir/graph");
|
|
40
|
+
const SOURCE_FILE = /\.(?:[cm]?[jt]sx?)$/;
|
|
41
|
+
const SKIP_DIRS = new Set(['node_modules', '.git', 'dist', 'build', 'coverage']);
|
|
42
|
+
function findReachableMocks(api, locator, options) {
|
|
43
|
+
var _a;
|
|
44
|
+
const byModulePath = new Map(api.models.map((m) => [locator.modulePath(m.id), m.id]));
|
|
45
|
+
const pattern = new RegExp(`${escapeRegExp(options.subdir)}/([^'"\`\\s]+?)\\.mock(?:\\.[cm]?[jt]sx?)?['"\`]`, 'g');
|
|
46
|
+
const direct = new Set();
|
|
47
|
+
const unknown = new Set();
|
|
48
|
+
let scanned = 0;
|
|
49
|
+
const visit = (dir) => {
|
|
50
|
+
if (options.exclude.some((ex) => dir === ex || dir.startsWith(ex + path.sep)))
|
|
51
|
+
return;
|
|
52
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
53
|
+
const abs = path.join(dir, entry.name);
|
|
54
|
+
if (entry.isDirectory()) {
|
|
55
|
+
if (!SKIP_DIRS.has(entry.name))
|
|
56
|
+
visit(abs);
|
|
57
|
+
}
|
|
58
|
+
else if (SOURCE_FILE.test(entry.name)) {
|
|
59
|
+
scanned++;
|
|
60
|
+
for (const match of fs.readFileSync(abs, 'utf8').matchAll(pattern)) {
|
|
61
|
+
const id = byModulePath.get(match[1]);
|
|
62
|
+
if (id)
|
|
63
|
+
direct.add(id);
|
|
64
|
+
else
|
|
65
|
+
unknown.add(match[1]);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
for (const root of options.roots)
|
|
71
|
+
if (fs.existsSync(root))
|
|
72
|
+
visit(root);
|
|
73
|
+
const graph = (0, graph_1.refGraph)(api);
|
|
74
|
+
const ids = new Set();
|
|
75
|
+
const stack = [...direct];
|
|
76
|
+
while (stack.length) {
|
|
77
|
+
const id = stack.pop();
|
|
78
|
+
if (ids.has(id))
|
|
79
|
+
continue;
|
|
80
|
+
ids.add(id);
|
|
81
|
+
stack.push(...((_a = graph.get(id)) !== null && _a !== void 0 ? _a : []));
|
|
82
|
+
}
|
|
83
|
+
return { ids, unknown: [...unknown].sort(), scanned };
|
|
84
|
+
}
|
|
85
|
+
function escapeRegExp(text) {
|
|
86
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
87
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { OutputContext } from '../../core/plugin';
|
|
2
|
+
import type { ModelsOptions } from './options';
|
|
3
|
+
import type { ApiSpec, ModelId, TypeNode } from '../../ir/types';
|
|
4
|
+
import type { ImportCollector, ModelLocator } from './imports';
|
|
5
|
+
export declare function generateCompatibilityModels(_ctx: OutputContext<ModelsOptions>): boolean;
|
|
6
|
+
export declare function doubleSlashLocator(locator: ModelLocator, _importPath?: string): ModelLocator;
|
|
7
|
+
export declare function legacyModelOverrides(_api: ApiSpec): ReadonlyMap<ModelId, {
|
|
8
|
+
type: TypeNode;
|
|
9
|
+
imports: ModelId[];
|
|
10
|
+
}> | undefined;
|
|
11
|
+
export declare function seedLegacyImports(_imports: ImportCollector, _ids: ModelId[], _locator: ModelLocator, _options: {
|
|
12
|
+
importPath?: string;
|
|
13
|
+
typeOnly: boolean;
|
|
14
|
+
}, _self: ModelId): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateCompatibilityModels = generateCompatibilityModels;
|
|
4
|
+
exports.doubleSlashLocator = doubleSlashLocator;
|
|
5
|
+
exports.legacyModelOverrides = legacyModelOverrides;
|
|
6
|
+
exports.seedLegacyImports = seedLegacyImports;
|
|
7
|
+
function generateCompatibilityModels(_ctx) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
function doubleSlashLocator(locator, _importPath) {
|
|
11
|
+
return locator;
|
|
12
|
+
}
|
|
13
|
+
function legacyModelOverrides(_api) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
function seedLegacyImports(_imports, _ids, _locator, _options, _self) { }
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { EnumValue } from '../../ir/types';
|
|
2
|
+
export declare function isIdentifier(name: string): boolean;
|
|
3
|
+
export declare function upperFirst(s: string): string;
|
|
4
|
+
export declare function propertyKey(name: string): string;
|
|
5
|
+
export declare function propertyEnumName(typeName: string, propertyName: string): string;
|
|
6
|
+
export declare function literal(value: EnumValue): string;
|
|
7
|
+
export declare function docLines(description: string | undefined): string[] | null;
|
|
8
|
+
export interface ConstMember {
|
|
9
|
+
key: string;
|
|
10
|
+
value: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function constMembers(values: EnumValue[]): ConstMember[];
|
|
13
|
+
export declare function constEnumValues(values: EnumValue[]): EnumValue[];
|