@hey-api/shared 0.4.7 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +217 -94
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +404 -250
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -10
package/dist/index.mjs
CHANGED
|
@@ -330,6 +330,15 @@ function isPlainObject(value) {
|
|
|
330
330
|
const proto = Object.getPrototypeOf(value);
|
|
331
331
|
return proto === Object.prototype || proto === null;
|
|
332
332
|
}
|
|
333
|
+
function deepMerge(target, source) {
|
|
334
|
+
if (isPlainObject(target) && isPlainObject(source)) {
|
|
335
|
+
const result = { ...target };
|
|
336
|
+
for (const key of Object.keys(source)) if (key in target) result[key] = deepMerge(target[key], source[key]);
|
|
337
|
+
else result[key] = source[key];
|
|
338
|
+
return result;
|
|
339
|
+
}
|
|
340
|
+
return source;
|
|
341
|
+
}
|
|
333
342
|
//#endregion
|
|
334
343
|
//#region src/normalize/opaque.ts
|
|
335
344
|
const OPAQUE = Symbol("opaque");
|
|
@@ -421,15 +430,20 @@ function resolveTable(input, table, { ancestor = {}, context = {}, resolvedCasca
|
|
|
421
430
|
}
|
|
422
431
|
function collectDeps(spec, resolved, deps) {
|
|
423
432
|
const { $dependencies } = spec;
|
|
424
|
-
if ($dependencies) for (const key of $dependencies)
|
|
425
|
-
const value = resolved[key];
|
|
426
|
-
if (value && typeof value === "string") deps.add(value);
|
|
427
|
-
}
|
|
433
|
+
if ($dependencies) for (const key of $dependencies) addDependencyValue(resolved[key], deps);
|
|
428
434
|
for (const [key, specVal] of Object.entries(spec)) {
|
|
429
435
|
if (key.startsWith("$")) continue;
|
|
430
436
|
if (isPlainObject(specVal) && isPlainObject(resolved[key])) collectDeps(specVal, resolved[key], deps);
|
|
431
437
|
}
|
|
432
438
|
}
|
|
439
|
+
function addDependencyValue(value, deps) {
|
|
440
|
+
if (!value) return;
|
|
441
|
+
if (typeof value === "string") {
|
|
442
|
+
deps.add(value);
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
if (Array.isArray(value)) for (const item of value) addDependencyValue(item, deps);
|
|
446
|
+
}
|
|
433
447
|
function resolveField(defaultVal, currentVal, key, { ancestor, context, resolvedCascade, specAncestor }) {
|
|
434
448
|
if (isCoercer(defaultVal)) return defaultVal[COERCER](currentVal, context);
|
|
435
449
|
if (isPlainObject(defaultVal)) {
|
|
@@ -975,26 +989,26 @@ const graph = {
|
|
|
975
989
|
};
|
|
976
990
|
//#endregion
|
|
977
991
|
//#region src/ir/parameter.ts
|
|
978
|
-
|
|
992
|
+
function getPaginationSchema({ context, parameter }) {
|
|
979
993
|
if (!parameter.pagination) return;
|
|
980
994
|
if (parameter.pagination === true) return parameter.schema;
|
|
981
995
|
let schema = parameter.schema;
|
|
982
996
|
if (schema.$ref) schema = context.resolveIrRef(schema.$ref);
|
|
983
997
|
return schema.properties[parameter.pagination];
|
|
984
|
-
}
|
|
985
|
-
|
|
998
|
+
}
|
|
999
|
+
function hasParameterGroupObjectRequired(parameterGroup) {
|
|
986
1000
|
for (const name in parameterGroup) if (parameterGroup[name].required) return true;
|
|
987
1001
|
return false;
|
|
988
|
-
}
|
|
989
|
-
|
|
1002
|
+
}
|
|
1003
|
+
function hasParametersObjectRequired(parameters) {
|
|
990
1004
|
if (!parameters) return false;
|
|
991
1005
|
if (hasParameterGroupObjectRequired(parameters.cookie)) return true;
|
|
992
1006
|
if (hasParameterGroupObjectRequired(parameters.header)) return true;
|
|
993
1007
|
if (hasParameterGroupObjectRequired(parameters.path)) return true;
|
|
994
1008
|
if (hasParameterGroupObjectRequired(parameters.query)) return true;
|
|
995
1009
|
return false;
|
|
996
|
-
}
|
|
997
|
-
|
|
1010
|
+
}
|
|
1011
|
+
function parameterWithPagination({ context, parameters }) {
|
|
998
1012
|
if (!parameters) return;
|
|
999
1013
|
for (const name in parameters.cookie) {
|
|
1000
1014
|
const parameter = parameters.cookie[name];
|
|
@@ -1040,7 +1054,7 @@ const parameterWithPagination = ({ context, parameters }) => {
|
|
|
1040
1054
|
})
|
|
1041
1055
|
};
|
|
1042
1056
|
}
|
|
1043
|
-
}
|
|
1057
|
+
}
|
|
1044
1058
|
//#endregion
|
|
1045
1059
|
//#region src/ir/schema.ts
|
|
1046
1060
|
/**
|
|
@@ -1114,13 +1128,15 @@ function addItemsToSchema({ items, logicalOperator = "or", mutateSchemaOneItem =
|
|
|
1114
1128
|
}
|
|
1115
1129
|
//#endregion
|
|
1116
1130
|
//#region src/ir/operation.ts
|
|
1117
|
-
|
|
1131
|
+
function hasOperationDataRequired(operation) {
|
|
1118
1132
|
if (hasParametersObjectRequired(operation.parameters)) return true;
|
|
1119
1133
|
if (operation.body?.required) return true;
|
|
1120
1134
|
return false;
|
|
1121
|
-
}
|
|
1122
|
-
|
|
1123
|
-
|
|
1135
|
+
}
|
|
1136
|
+
function createOperationKey({ method, path }) {
|
|
1137
|
+
return `${method.toUpperCase()} ${path}`;
|
|
1138
|
+
}
|
|
1139
|
+
function operationPagination({ context, operation }) {
|
|
1124
1140
|
const body = operation.body;
|
|
1125
1141
|
if (!body || !body.pagination) return parameterWithPagination({
|
|
1126
1142
|
context,
|
|
@@ -1143,8 +1159,8 @@ const operationPagination = ({ context, operation }) => {
|
|
|
1143
1159
|
name: body.pagination,
|
|
1144
1160
|
schema: paginationProp
|
|
1145
1161
|
};
|
|
1146
|
-
}
|
|
1147
|
-
|
|
1162
|
+
}
|
|
1163
|
+
function statusCodeToGroup({ statusCode }) {
|
|
1148
1164
|
switch (statusCode) {
|
|
1149
1165
|
case "1XX": return "1XX";
|
|
1150
1166
|
case "2XX": return "2XX";
|
|
@@ -1154,8 +1170,8 @@ const statusCodeToGroup = ({ statusCode }) => {
|
|
|
1154
1170
|
case "default": return "default";
|
|
1155
1171
|
default: return `${statusCode[0]}XX`;
|
|
1156
1172
|
}
|
|
1157
|
-
}
|
|
1158
|
-
|
|
1173
|
+
}
|
|
1174
|
+
function operationResponsesMap(operation) {
|
|
1159
1175
|
const result = {};
|
|
1160
1176
|
if (!operation.responses) return result;
|
|
1161
1177
|
const errors = {
|
|
@@ -1227,7 +1243,7 @@ const operationResponsesMap = (operation) => {
|
|
|
1227
1243
|
if (Object.keys(responseUnion).length && responseUnion.type !== "unknown") result.response = responseUnion;
|
|
1228
1244
|
}
|
|
1229
1245
|
return result;
|
|
1230
|
-
}
|
|
1246
|
+
}
|
|
1231
1247
|
//#endregion
|
|
1232
1248
|
//#region src/utils/naming/naming.ts
|
|
1233
1249
|
const uppercaseRegExp = /[\p{Lu}]/u;
|
|
@@ -1960,15 +1976,84 @@ function resolveRef({ $ref, spec }) {
|
|
|
1960
1976
|
return current;
|
|
1961
1977
|
}
|
|
1962
1978
|
//#endregion
|
|
1963
|
-
//#region src/
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1979
|
+
//#region src/utils/symbols.ts
|
|
1980
|
+
var SymbolFactory = class {
|
|
1981
|
+
eventHooks;
|
|
1982
|
+
project;
|
|
1983
|
+
plugin;
|
|
1984
|
+
constructor(props) {
|
|
1985
|
+
this.eventHooks = props.eventHooks;
|
|
1986
|
+
this.project = props.project;
|
|
1987
|
+
this.plugin = props.plugin;
|
|
1988
|
+
}
|
|
1989
|
+
static buildEventHooks(scopes) {
|
|
1990
|
+
const result = {
|
|
1991
|
+
"node:set:after": [],
|
|
1992
|
+
"node:set:before": [],
|
|
1993
|
+
"plugin:handler:after": [],
|
|
1994
|
+
"plugin:handler:before": [],
|
|
1995
|
+
"symbol:register:after": [],
|
|
1996
|
+
"symbol:register:before": []
|
|
1997
|
+
};
|
|
1998
|
+
for (const scope of scopes) {
|
|
1999
|
+
if (!scope) continue;
|
|
2000
|
+
for (const [key, value] of Object.entries(scope)) if (value) result[key].push(value.bind(scope));
|
|
2001
|
+
}
|
|
2002
|
+
return result;
|
|
2003
|
+
}
|
|
2004
|
+
isRegistered(identifier) {
|
|
2005
|
+
return this.project.symbols.isRegistered(identifier);
|
|
2006
|
+
}
|
|
2007
|
+
query(filter, tags, predicate) {
|
|
2008
|
+
return this.queryAll(filter, tags, predicate)[0];
|
|
2009
|
+
}
|
|
2010
|
+
queryAll(filter, tags, predicate) {
|
|
2011
|
+
const results = this.project.symbols.query(filter);
|
|
2012
|
+
if (!tags?.length && !predicate) return results;
|
|
2013
|
+
const set = tags?.length ? new Set(tags) : null;
|
|
2014
|
+
return results.filter((symbol) => {
|
|
2015
|
+
if (set && !set.has(symbol.node?.["~dsl"] ?? "")) return false;
|
|
2016
|
+
return predicate ? predicate(symbol) : true;
|
|
2017
|
+
});
|
|
2018
|
+
}
|
|
2019
|
+
reference(meta) {
|
|
2020
|
+
return this.project.symbols.reference(meta);
|
|
2021
|
+
}
|
|
2022
|
+
register(name, symbol = {}) {
|
|
2023
|
+
const meta = { ...symbol.meta };
|
|
2024
|
+
if (symbol.external) {
|
|
2025
|
+
if (!meta.category) meta.category = "external";
|
|
2026
|
+
if (!meta.resource) meta.resource = `${symbol.external}.${name}`;
|
|
2027
|
+
const existing = this.queryAll(meta).find((s) => s.name === name);
|
|
2028
|
+
if (existing) return existing;
|
|
2029
|
+
}
|
|
2030
|
+
const symbolIn = {
|
|
2031
|
+
...symbol,
|
|
2032
|
+
meta,
|
|
2033
|
+
name
|
|
2034
|
+
};
|
|
2035
|
+
for (const hook of this.eventHooks["symbol:register:before"]) hook({
|
|
2036
|
+
plugin: this.plugin,
|
|
2037
|
+
symbol: symbolIn
|
|
2038
|
+
});
|
|
2039
|
+
const symbolOut = this.project.symbols.register(symbolIn);
|
|
2040
|
+
for (const hook of this.eventHooks["symbol:register:after"]) hook({
|
|
2041
|
+
plugin: this.plugin,
|
|
2042
|
+
symbol: symbolOut
|
|
2043
|
+
});
|
|
2044
|
+
return symbolOut;
|
|
2045
|
+
}
|
|
1971
2046
|
};
|
|
2047
|
+
//#endregion
|
|
2048
|
+
//#region src/plugins/shared/utils/instance.ts
|
|
2049
|
+
function defaultGetFilePath(symbol) {
|
|
2050
|
+
if (!symbol.meta?.plugin || typeof symbol.meta.plugin !== "string") return;
|
|
2051
|
+
if (symbol.meta.plugin.startsWith("@hey-api/client-")) return "client";
|
|
2052
|
+
if (symbol.meta.plugin === "@hey-api/typescript") return "types";
|
|
2053
|
+
if (symbol.meta.plugin === "@hey-api/python-sdk") return "sdk";
|
|
2054
|
+
if (symbol.meta.plugin.startsWith("@hey-api/")) return symbol.meta.plugin.split("/")[1];
|
|
2055
|
+
return symbol.meta.plugin;
|
|
2056
|
+
}
|
|
1972
2057
|
const defaultGetKind = (operation) => {
|
|
1973
2058
|
switch (operation.method) {
|
|
1974
2059
|
case "delete":
|
|
@@ -1987,6 +2072,8 @@ var PluginInstance = class {
|
|
|
1987
2072
|
eventHooks;
|
|
1988
2073
|
gen;
|
|
1989
2074
|
handler;
|
|
2075
|
+
/** External symbols imported from other modules. */
|
|
2076
|
+
imports;
|
|
1990
2077
|
name;
|
|
1991
2078
|
/**
|
|
1992
2079
|
* The package metadata and utilities for the current context, constructed
|
|
@@ -1995,26 +2082,37 @@ var PluginInstance = class {
|
|
|
1995
2082
|
* code generation.
|
|
1996
2083
|
*/
|
|
1997
2084
|
package;
|
|
1998
|
-
/**
|
|
1999
|
-
|
|
2085
|
+
/** Factory for creating and managing symbols. */
|
|
2086
|
+
symbolFactory;
|
|
2087
|
+
/** Metadata merged into every symbol this plugin creates. */
|
|
2088
|
+
symbolMeta;
|
|
2089
|
+
isSymbolRegistered;
|
|
2090
|
+
querySymbol;
|
|
2091
|
+
referenceSymbol;
|
|
2000
2092
|
constructor(props) {
|
|
2001
2093
|
this.api = props.api ?? {};
|
|
2002
2094
|
this.config = props.config;
|
|
2003
2095
|
this.context = props.context;
|
|
2004
2096
|
this.dependencies = props.dependencies;
|
|
2005
|
-
this.eventHooks = this.buildEventHooks();
|
|
2006
2097
|
this.gen = props.gen;
|
|
2007
2098
|
this.handler = props.handler;
|
|
2008
2099
|
this.name = props.name;
|
|
2009
2100
|
this.package = props.context.package;
|
|
2010
|
-
this.
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2101
|
+
this.symbolMeta = props.symbolMeta;
|
|
2102
|
+
this.eventHooks = SymbolFactory.buildEventHooks([
|
|
2103
|
+
this.config["~hooks"]?.events,
|
|
2104
|
+
this.config.$hooks?.events,
|
|
2105
|
+
this.context.config.parser.hooks.events
|
|
2106
|
+
]);
|
|
2107
|
+
this.symbolFactory = new SymbolFactory({
|
|
2108
|
+
eventHooks: this.eventHooks,
|
|
2109
|
+
plugin: this,
|
|
2110
|
+
project: this.gen
|
|
2017
2111
|
});
|
|
2112
|
+
this.isSymbolRegistered = this.symbolFactory.isRegistered.bind(this.symbolFactory);
|
|
2113
|
+
this.querySymbol = this.symbolFactory.query.bind(this.symbolFactory);
|
|
2114
|
+
this.referenceSymbol = this.symbolFactory.reference.bind(this.symbolFactory);
|
|
2115
|
+
this.imports = props.imports?.(this) ?? {};
|
|
2018
2116
|
}
|
|
2019
2117
|
forEach(...args) {
|
|
2020
2118
|
if (!this.context.graph) throw new Error("No graph available in context");
|
|
@@ -2108,8 +2206,10 @@ var PluginInstance = class {
|
|
|
2108
2206
|
getHooks(selector, ...customHooks) {
|
|
2109
2207
|
const result = [];
|
|
2110
2208
|
for (const hook of customHooks) if (hook) result.push(hook);
|
|
2111
|
-
const local = selector(this.config
|
|
2209
|
+
const local = selector(this.config.$hooks ?? {});
|
|
2112
2210
|
if (local) result.push(local);
|
|
2211
|
+
const localDeprecated = selector(this.config["~hooks"] ?? {});
|
|
2212
|
+
if (localDeprecated) result.push(localDeprecated);
|
|
2113
2213
|
const global = selector(this.context.config.parser.hooks);
|
|
2114
2214
|
if (global) result.push(global);
|
|
2115
2215
|
return result;
|
|
@@ -2151,9 +2251,6 @@ var PluginInstance = class {
|
|
|
2151
2251
|
intent(intent) {
|
|
2152
2252
|
this.context.intents.push(intent);
|
|
2153
2253
|
}
|
|
2154
|
-
isSymbolRegistered(identifier) {
|
|
2155
|
-
return this.gen.symbols.isRegistered(identifier);
|
|
2156
|
-
}
|
|
2157
2254
|
/**
|
|
2158
2255
|
* Sets or adds a node to the project graph.
|
|
2159
2256
|
*
|
|
@@ -2173,27 +2270,6 @@ var PluginInstance = class {
|
|
|
2173
2270
|
});
|
|
2174
2271
|
return result;
|
|
2175
2272
|
}
|
|
2176
|
-
querySymbol(filter, tags, predicate) {
|
|
2177
|
-
return this.querySymbols(filter, tags, predicate)[0];
|
|
2178
|
-
}
|
|
2179
|
-
querySymbols(filter, tags, predicate) {
|
|
2180
|
-
const results = this.gen.symbols.query(filter);
|
|
2181
|
-
if (!tags?.length && !predicate) return results;
|
|
2182
|
-
const set = tags?.length ? new Set(tags) : null;
|
|
2183
|
-
return results.filter((symbol) => {
|
|
2184
|
-
if (set && !set.has(symbol.node?.["~dsl"] ?? "")) return false;
|
|
2185
|
-
return predicate ? predicate(symbol) : true;
|
|
2186
|
-
});
|
|
2187
|
-
}
|
|
2188
|
-
referenceSymbol(meta) {
|
|
2189
|
-
return this.gen.symbols.reference(meta);
|
|
2190
|
-
}
|
|
2191
|
-
/**
|
|
2192
|
-
* Alias for `symbol()` method with single argument.
|
|
2193
|
-
*/
|
|
2194
|
-
registerSymbol(symbol) {
|
|
2195
|
-
return this.symbol(symbol.name, symbol);
|
|
2196
|
-
}
|
|
2197
2273
|
/**
|
|
2198
2274
|
* Executes plugin's handler function.
|
|
2199
2275
|
*/
|
|
@@ -2202,34 +2278,26 @@ var PluginInstance = class {
|
|
|
2202
2278
|
await this.handler({ plugin: this });
|
|
2203
2279
|
for (const hook of this.eventHooks["plugin:handler:after"]) hook({ plugin: this });
|
|
2204
2280
|
}
|
|
2205
|
-
symbol(
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2281
|
+
symbol(nameOrSymbol, symbolArg = {}) {
|
|
2282
|
+
let name;
|
|
2283
|
+
let symbol;
|
|
2284
|
+
if (typeof nameOrSymbol === "object") {
|
|
2285
|
+
const { name: _name, ...rest } = nameOrSymbol;
|
|
2286
|
+
name = _name;
|
|
2287
|
+
symbol = rest;
|
|
2288
|
+
} else {
|
|
2289
|
+
name = nameOrSymbol;
|
|
2290
|
+
symbol = symbolArg;
|
|
2212
2291
|
}
|
|
2213
|
-
const
|
|
2292
|
+
const meta = !symbol.external && this.symbolMeta ? this.symbolMeta(symbol) : {};
|
|
2293
|
+
Object.assign(meta, symbol.meta);
|
|
2294
|
+
if (!symbol.external) meta.plugin = path.isAbsolute(this.name) ? "custom" : this.name;
|
|
2295
|
+
return this.symbolFactory.register(name, {
|
|
2214
2296
|
...symbol,
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
},
|
|
2219
|
-
name
|
|
2220
|
-
};
|
|
2221
|
-
if (symbolIn.getExportFromFilePath === void 0) symbolIn.getExportFromFilePath = this.getSymbolExportFromFilePath.bind(this);
|
|
2222
|
-
if (symbolIn.getFilePath === void 0) symbolIn.getFilePath = this.getSymbolFilePath.bind(this);
|
|
2223
|
-
for (const hook of this.eventHooks["symbol:register:before"]) hook({
|
|
2224
|
-
plugin: this,
|
|
2225
|
-
symbol: symbolIn
|
|
2297
|
+
getExportFromFilePath: symbol.getExportFromFilePath ?? this.getSymbolExportFromFilePath.bind(this),
|
|
2298
|
+
getFilePath: symbol.getFilePath ?? this.getSymbolFilePath.bind(this),
|
|
2299
|
+
meta
|
|
2226
2300
|
});
|
|
2227
|
-
const symbolOut = this.gen.symbols.register(symbolIn);
|
|
2228
|
-
for (const hook of this.eventHooks["symbol:register:after"]) hook({
|
|
2229
|
-
plugin: this,
|
|
2230
|
-
symbol: symbolOut
|
|
2231
|
-
});
|
|
2232
|
-
return symbolOut;
|
|
2233
2301
|
}
|
|
2234
2302
|
/**
|
|
2235
2303
|
* Registers a symbol only if it does not already exist based on the provided
|
|
@@ -2239,30 +2307,11 @@ var PluginInstance = class {
|
|
|
2239
2307
|
symbolOnce(name, symbol = {}) {
|
|
2240
2308
|
if (symbol.external) return this.symbol(name, symbol);
|
|
2241
2309
|
if (symbol.meta) {
|
|
2242
|
-
const existing = this.
|
|
2310
|
+
const existing = this.symbolFactory.queryAll(symbol.meta).find((s) => s.name === name);
|
|
2243
2311
|
if (existing) return existing;
|
|
2244
2312
|
}
|
|
2245
2313
|
return this.symbol(name, symbol);
|
|
2246
2314
|
}
|
|
2247
|
-
buildEventHooks() {
|
|
2248
|
-
const result = {
|
|
2249
|
-
"node:set:after": [],
|
|
2250
|
-
"node:set:before": [],
|
|
2251
|
-
"plugin:handler:after": [],
|
|
2252
|
-
"plugin:handler:before": [],
|
|
2253
|
-
"symbol:register:after": [],
|
|
2254
|
-
"symbol:register:before": []
|
|
2255
|
-
};
|
|
2256
|
-
const scopes = [this.config["~hooks"]?.events, this.context.config.parser.hooks.events];
|
|
2257
|
-
for (const scope of scopes) {
|
|
2258
|
-
if (!scope) continue;
|
|
2259
|
-
for (const [key, value] of Object.entries(scope)) if (value) result[key].push(value.bind(scope));
|
|
2260
|
-
}
|
|
2261
|
-
return result;
|
|
2262
|
-
}
|
|
2263
|
-
buildSymbols(fn) {
|
|
2264
|
-
return fn ? fn(this) : {};
|
|
2265
|
-
}
|
|
2266
2315
|
forEachError(error, event) {
|
|
2267
2316
|
const originalError = error instanceof Error ? error : new Error(String(error));
|
|
2268
2317
|
throw new HeyApiError({
|
|
@@ -2298,6 +2347,8 @@ var PluginInstance = class {
|
|
|
2298
2347
|
isOperationKind(operation, kind) {
|
|
2299
2348
|
const method = kind === "query" ? "isQuery" : "isMutation";
|
|
2300
2349
|
const hooks = [
|
|
2350
|
+
this.config.$hooks?.operations?.[method],
|
|
2351
|
+
this.config.$hooks?.operations?.getKind,
|
|
2301
2352
|
this.config["~hooks"]?.operations?.[method],
|
|
2302
2353
|
this.config["~hooks"]?.operations?.getKind,
|
|
2303
2354
|
this.context.config.parser.hooks.operations?.[method],
|
|
@@ -2319,25 +2370,15 @@ var Context = class {
|
|
|
2319
2370
|
* is a mix of user-provided and default values.
|
|
2320
2371
|
*/
|
|
2321
2372
|
config;
|
|
2322
|
-
/**
|
|
2323
|
-
* The code generation project instance used to manage files, symbols,
|
|
2324
|
-
*/
|
|
2373
|
+
/** The code generation project instance used to manage files, symbols, */
|
|
2325
2374
|
gen;
|
|
2326
|
-
/**
|
|
2327
|
-
* The dependency graph built from the intermediate representation.
|
|
2328
|
-
*/
|
|
2375
|
+
/** The dependency graph built from the intermediate representation. */
|
|
2329
2376
|
graph;
|
|
2330
|
-
/**
|
|
2331
|
-
* Intents declared by plugins.
|
|
2332
|
-
*/
|
|
2377
|
+
/** Intents declared by plugins. */
|
|
2333
2378
|
intents = [];
|
|
2334
|
-
/**
|
|
2335
|
-
* Intermediate representation model obtained from `spec`.
|
|
2336
|
-
*/
|
|
2379
|
+
/** Intermediate representation model obtained from `spec`. */
|
|
2337
2380
|
ir = {};
|
|
2338
|
-
/**
|
|
2339
|
-
* Logger instance.
|
|
2340
|
-
*/
|
|
2381
|
+
/** Logger instance. */
|
|
2341
2382
|
logger;
|
|
2342
2383
|
/**
|
|
2343
2384
|
* The package metadata and utilities for the current context, constructed
|
|
@@ -2352,9 +2393,7 @@ var Context = class {
|
|
|
2352
2393
|
* their configured name from the config.
|
|
2353
2394
|
*/
|
|
2354
2395
|
plugins = {};
|
|
2355
|
-
/**
|
|
2356
|
-
* Resolved specification from `input`.
|
|
2357
|
-
*/
|
|
2396
|
+
/** Resolved specification from `input`. */
|
|
2358
2397
|
spec;
|
|
2359
2398
|
constructor({ config, dependencies, logger, project, spec }) {
|
|
2360
2399
|
this.config = config;
|
|
@@ -2390,8 +2429,9 @@ var Context = class {
|
|
|
2390
2429
|
dependencies: plugin.dependencies ?? /* @__PURE__ */ new Set(),
|
|
2391
2430
|
gen: this.gen,
|
|
2392
2431
|
handler: plugin.handler,
|
|
2432
|
+
imports: plugin.imports,
|
|
2393
2433
|
name: plugin.name,
|
|
2394
|
-
|
|
2434
|
+
symbolMeta: plugin.symbolMeta
|
|
2395
2435
|
});
|
|
2396
2436
|
this.plugins[instance.name] = instance;
|
|
2397
2437
|
return instance;
|
|
@@ -4466,7 +4506,7 @@ function getPaginationKeywordsRegExp(pagination) {
|
|
|
4466
4506
|
* property may be a boolean, number, or integer. This function converts the string
|
|
4467
4507
|
* key to the correct runtime value and IR type.
|
|
4468
4508
|
*/
|
|
4469
|
-
|
|
4509
|
+
function convertDiscriminatorValue(value, propertyType) {
|
|
4470
4510
|
switch (propertyType) {
|
|
4471
4511
|
case "boolean": {
|
|
4472
4512
|
const lowerValue = value.toLowerCase();
|
|
@@ -4515,13 +4555,58 @@ const convertDiscriminatorValue = (value, propertyType) => {
|
|
|
4515
4555
|
type: "string"
|
|
4516
4556
|
};
|
|
4517
4557
|
}
|
|
4518
|
-
}
|
|
4519
|
-
|
|
4558
|
+
}
|
|
4559
|
+
function discriminatorValues($ref, mapping, shouldUseRefAsValue) {
|
|
4520
4560
|
const values = [];
|
|
4521
4561
|
for (const name in mapping) if (mapping[name] === $ref) values.push(name);
|
|
4522
4562
|
if (!values.length && (!shouldUseRefAsValue || shouldUseRefAsValue())) return [refToName($ref)];
|
|
4523
4563
|
return values;
|
|
4524
|
-
}
|
|
4564
|
+
}
|
|
4565
|
+
function buildDiscriminatedUnion({ parentSchema, resolveIrRef, schemas }) {
|
|
4566
|
+
const discriminatorKey = parentSchema.discriminator?.propertyName;
|
|
4567
|
+
if (!discriminatorKey) return null;
|
|
4568
|
+
const members = [];
|
|
4569
|
+
for (const schema of schemas) {
|
|
4570
|
+
if (schema.type === "null" || schema.const === null) continue;
|
|
4571
|
+
const ref = schema.$ref;
|
|
4572
|
+
if (!ref) return null;
|
|
4573
|
+
let resolved;
|
|
4574
|
+
try {
|
|
4575
|
+
resolved = resolveIrRef(ref);
|
|
4576
|
+
} catch {
|
|
4577
|
+
return null;
|
|
4578
|
+
}
|
|
4579
|
+
if (!resolved) return null;
|
|
4580
|
+
let effective = resolved;
|
|
4581
|
+
while (effective.$ref && !effective.type && !effective.properties && !effective.items) try {
|
|
4582
|
+
const next = resolveIrRef(effective.$ref);
|
|
4583
|
+
if (!next) break;
|
|
4584
|
+
effective = next;
|
|
4585
|
+
} catch {
|
|
4586
|
+
break;
|
|
4587
|
+
}
|
|
4588
|
+
const discriminatorProp = effective.properties?.[discriminatorKey];
|
|
4589
|
+
const needsExtend = discriminatorProp?.const === void 0;
|
|
4590
|
+
const isObjectLike = effective.type === "object" || effective.logicalOperator === "and";
|
|
4591
|
+
if (needsExtend && !isObjectLike) return null;
|
|
4592
|
+
const values = discriminatorValues(ref, parentSchema.discriminator.mapping);
|
|
4593
|
+
if (!values.length) return null;
|
|
4594
|
+
const propType = discriminatorProp?.type;
|
|
4595
|
+
for (const value of values) {
|
|
4596
|
+
const discriminatedValue = propType && propType !== "string" ? convertDiscriminatorValue(value, propType).const : value;
|
|
4597
|
+
members.push({
|
|
4598
|
+
discriminatedValue,
|
|
4599
|
+
needsExtend,
|
|
4600
|
+
ref
|
|
4601
|
+
});
|
|
4602
|
+
}
|
|
4603
|
+
}
|
|
4604
|
+
if (!members.length) return null;
|
|
4605
|
+
return {
|
|
4606
|
+
discriminatorKey,
|
|
4607
|
+
members
|
|
4608
|
+
};
|
|
4609
|
+
}
|
|
4525
4610
|
//#endregion
|
|
4526
4611
|
//#region src/openApi/2.0.x/parser/schema.ts
|
|
4527
4612
|
function getSchemaType$1(schema) {
|
|
@@ -5270,6 +5355,31 @@ const parameterToIrParameter$2 = ({ $ref, context, parameter }) => {
|
|
|
5270
5355
|
//#endregion
|
|
5271
5356
|
//#region src/utils/url.ts
|
|
5272
5357
|
const parseUrlRegExp = /^(([^:/?#]+):)?((\/\/)?([^:/?#]*)(:?([^/?#]*)))?([^?#]*)(\?([^#]*))?(#(.*))?/;
|
|
5358
|
+
/**
|
|
5359
|
+
* Resolve the base URL value based on the plugin configuration.
|
|
5360
|
+
*
|
|
5361
|
+
* The `baseUrl` config option can be:
|
|
5362
|
+
* - `false` to disable using the base URL
|
|
5363
|
+
* - a string to use as the base URL
|
|
5364
|
+
* - a number to pick a server from the IR `servers` array
|
|
5365
|
+
*/
|
|
5366
|
+
function resolveBaseUrl(baseUrl, ir) {
|
|
5367
|
+
if (baseUrl === false) return;
|
|
5368
|
+
if (typeof baseUrl === "string") return baseUrl;
|
|
5369
|
+
return (ir.servers ?? [])[typeof baseUrl === "number" ? baseUrl : 0]?.url;
|
|
5370
|
+
}
|
|
5371
|
+
/**
|
|
5372
|
+
* Resolve the base URL string if it's a valid URL or path.
|
|
5373
|
+
*/
|
|
5374
|
+
function getBaseUrl(config, ir) {
|
|
5375
|
+
const baseUrl = resolveBaseUrl(config, ir);
|
|
5376
|
+
if (baseUrl === void 0) return;
|
|
5377
|
+
if (baseUrl.includes("{")) return;
|
|
5378
|
+
const url = parseUrl(baseUrl);
|
|
5379
|
+
if (url.protocol && url.host) return baseUrl;
|
|
5380
|
+
if (baseUrl !== "/" && baseUrl.startsWith("/")) return baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
|
|
5381
|
+
return baseUrl;
|
|
5382
|
+
}
|
|
5273
5383
|
function parseUrl(value) {
|
|
5274
5384
|
const errorResponse = {
|
|
5275
5385
|
host: "",
|
|
@@ -5983,30 +6093,12 @@ function parseAnyOf$1({ context, schema, state }) {
|
|
|
5983
6093
|
const schemaItems = [];
|
|
5984
6094
|
const schemaType = getSchemaType(schema);
|
|
5985
6095
|
const compositionSchemas = schema.anyOf;
|
|
5986
|
-
const discriminatorPropertyType = schema.discriminator ? findDiscriminatorPropertyType$1({
|
|
5987
|
-
context,
|
|
5988
|
-
propertyName: schema.discriminator.propertyName,
|
|
5989
|
-
schemas: compositionSchemas
|
|
5990
|
-
}) : void 0;
|
|
5991
6096
|
for (const compositionSchema of compositionSchemas) {
|
|
5992
|
-
|
|
6097
|
+
const irCompositionSchema = schemaToIrSchema$1({
|
|
5993
6098
|
context,
|
|
5994
6099
|
schema: compositionSchema,
|
|
5995
6100
|
state
|
|
5996
6101
|
});
|
|
5997
|
-
if (schema.discriminator && irCompositionSchema.$ref) {
|
|
5998
|
-
const valueSchemas = discriminatorValues(irCompositionSchema.$ref, schema.discriminator.mapping).map((value) => convertDiscriminatorValue(value, discriminatorPropertyType));
|
|
5999
|
-
irCompositionSchema = {
|
|
6000
|
-
items: [{
|
|
6001
|
-
properties: { [schema.discriminator.propertyName]: valueSchemas.length > 1 ? {
|
|
6002
|
-
items: valueSchemas,
|
|
6003
|
-
logicalOperator: "or"
|
|
6004
|
-
} : valueSchemas[0] },
|
|
6005
|
-
type: "object"
|
|
6006
|
-
}, irCompositionSchema],
|
|
6007
|
-
logicalOperator: "and"
|
|
6008
|
-
};
|
|
6009
|
-
}
|
|
6010
6102
|
schemaItems.push(irCompositionSchema);
|
|
6011
6103
|
}
|
|
6012
6104
|
if (schema.nullable) schemaItems.push({ type: "null" });
|
|
@@ -6029,7 +6121,10 @@ function parseAnyOf$1({ context, schema, state }) {
|
|
|
6029
6121
|
logicalOperator: "and"
|
|
6030
6122
|
};
|
|
6031
6123
|
}
|
|
6032
|
-
if (schema.discriminator && irSchema.logicalOperator === "or") irSchema.discriminator = {
|
|
6124
|
+
if (schema.discriminator && irSchema.logicalOperator === "or") irSchema.discriminator = {
|
|
6125
|
+
...schema.discriminator.mapping && { mapping: schema.discriminator.mapping },
|
|
6126
|
+
propertyName: schema.discriminator.propertyName
|
|
6127
|
+
};
|
|
6033
6128
|
return irSchema;
|
|
6034
6129
|
}
|
|
6035
6130
|
function parseEnum$1({ context, schema, state }) {
|
|
@@ -6078,31 +6173,12 @@ function parseOneOf$1({ context, schema, state }) {
|
|
|
6078
6173
|
let schemaItems = [];
|
|
6079
6174
|
const schemaType = getSchemaType(schema);
|
|
6080
6175
|
const compositionSchemas = schema.oneOf;
|
|
6081
|
-
const discriminatorPropertyType = schema.discriminator ? findDiscriminatorPropertyType$1({
|
|
6082
|
-
context,
|
|
6083
|
-
propertyName: schema.discriminator.propertyName,
|
|
6084
|
-
schemas: compositionSchemas
|
|
6085
|
-
}) : void 0;
|
|
6086
6176
|
for (const compositionSchema of compositionSchemas) {
|
|
6087
|
-
|
|
6177
|
+
const irCompositionSchema = schemaToIrSchema$1({
|
|
6088
6178
|
context,
|
|
6089
6179
|
schema: compositionSchema,
|
|
6090
6180
|
state
|
|
6091
6181
|
});
|
|
6092
|
-
if (schema.discriminator && irCompositionSchema.$ref) {
|
|
6093
|
-
const valueSchemas = discriminatorValues(irCompositionSchema.$ref, schema.discriminator.mapping).map((value) => convertDiscriminatorValue(value, discriminatorPropertyType));
|
|
6094
|
-
irCompositionSchema = {
|
|
6095
|
-
items: [{
|
|
6096
|
-
properties: { [schema.discriminator.propertyName]: valueSchemas.length > 1 ? {
|
|
6097
|
-
items: valueSchemas,
|
|
6098
|
-
logicalOperator: "or"
|
|
6099
|
-
} : valueSchemas[0] },
|
|
6100
|
-
required: [schema.discriminator.propertyName],
|
|
6101
|
-
type: "object"
|
|
6102
|
-
}, irCompositionSchema],
|
|
6103
|
-
logicalOperator: "and"
|
|
6104
|
-
};
|
|
6105
|
-
}
|
|
6106
6182
|
if (irCompositionSchema.logicalOperator === "or" && irCompositionSchema.type !== "array" && irCompositionSchema.items) schemaItems = schemaItems.concat(irCompositionSchema.items);
|
|
6107
6183
|
else schemaItems.push(irCompositionSchema);
|
|
6108
6184
|
}
|
|
@@ -6126,7 +6202,10 @@ function parseOneOf$1({ context, schema, state }) {
|
|
|
6126
6202
|
logicalOperator: "and"
|
|
6127
6203
|
};
|
|
6128
6204
|
}
|
|
6129
|
-
if (schema.discriminator && irSchema.logicalOperator === "or") irSchema.discriminator = {
|
|
6205
|
+
if (schema.discriminator && irSchema.logicalOperator === "or") irSchema.discriminator = {
|
|
6206
|
+
...schema.discriminator.mapping && { mapping: schema.discriminator.mapping },
|
|
6207
|
+
propertyName: schema.discriminator.propertyName
|
|
6208
|
+
};
|
|
6130
6209
|
return irSchema;
|
|
6131
6210
|
}
|
|
6132
6211
|
function parseRef$1({ context, schema, state }) {
|
|
@@ -7399,30 +7478,12 @@ function parseAnyOf({ context, schema, state }) {
|
|
|
7399
7478
|
const schemaItems = [];
|
|
7400
7479
|
const schemaTypes = getSchemaTypes(schema);
|
|
7401
7480
|
const compositionSchemas = schema.anyOf;
|
|
7402
|
-
const discriminatorPropertyType = schema.discriminator ? findDiscriminatorPropertyType({
|
|
7403
|
-
context,
|
|
7404
|
-
propertyName: schema.discriminator.propertyName,
|
|
7405
|
-
schemas: compositionSchemas
|
|
7406
|
-
}) : void 0;
|
|
7407
7481
|
for (const compositionSchema of compositionSchemas) {
|
|
7408
|
-
|
|
7482
|
+
const irCompositionSchema = schemaToIrSchema({
|
|
7409
7483
|
context,
|
|
7410
7484
|
schema: compositionSchema,
|
|
7411
7485
|
state
|
|
7412
7486
|
});
|
|
7413
|
-
if (schema.discriminator && irCompositionSchema.$ref) {
|
|
7414
|
-
const valueSchemas = discriminatorValues(irCompositionSchema.$ref, schema.discriminator.mapping).map((value) => convertDiscriminatorValue(value, discriminatorPropertyType));
|
|
7415
|
-
irCompositionSchema = {
|
|
7416
|
-
items: [{
|
|
7417
|
-
properties: { [schema.discriminator.propertyName]: valueSchemas.length > 1 ? {
|
|
7418
|
-
items: valueSchemas,
|
|
7419
|
-
logicalOperator: "or"
|
|
7420
|
-
} : valueSchemas[0] },
|
|
7421
|
-
type: "object"
|
|
7422
|
-
}, irCompositionSchema],
|
|
7423
|
-
logicalOperator: "and"
|
|
7424
|
-
};
|
|
7425
|
-
}
|
|
7426
7487
|
schemaItems.push(irCompositionSchema);
|
|
7427
7488
|
}
|
|
7428
7489
|
if (schemaTypes.includes("null")) schemaItems.push({ type: "null" });
|
|
@@ -7445,7 +7506,10 @@ function parseAnyOf({ context, schema, state }) {
|
|
|
7445
7506
|
logicalOperator: "and"
|
|
7446
7507
|
};
|
|
7447
7508
|
}
|
|
7448
|
-
if (schema.discriminator && irSchema.logicalOperator === "or") irSchema.discriminator = {
|
|
7509
|
+
if (schema.discriminator && irSchema.logicalOperator === "or") irSchema.discriminator = {
|
|
7510
|
+
...schema.discriminator.mapping && { mapping: schema.discriminator.mapping },
|
|
7511
|
+
propertyName: schema.discriminator.propertyName
|
|
7512
|
+
};
|
|
7449
7513
|
return irSchema;
|
|
7450
7514
|
}
|
|
7451
7515
|
function parseEnum({ context, schema, state }) {
|
|
@@ -7497,31 +7561,12 @@ function parseOneOf({ context, schema, state }) {
|
|
|
7497
7561
|
let schemaItems = [];
|
|
7498
7562
|
const schemaTypes = getSchemaTypes(schema);
|
|
7499
7563
|
const compositionSchemas = schema.oneOf;
|
|
7500
|
-
const discriminatorPropertyType = schema.discriminator ? findDiscriminatorPropertyType({
|
|
7501
|
-
context,
|
|
7502
|
-
propertyName: schema.discriminator.propertyName,
|
|
7503
|
-
schemas: compositionSchemas
|
|
7504
|
-
}) : void 0;
|
|
7505
7564
|
for (const compositionSchema of compositionSchemas) {
|
|
7506
|
-
|
|
7565
|
+
const irCompositionSchema = schemaToIrSchema({
|
|
7507
7566
|
context,
|
|
7508
7567
|
schema: compositionSchema,
|
|
7509
7568
|
state
|
|
7510
7569
|
});
|
|
7511
|
-
if (schema.discriminator && irCompositionSchema.$ref) {
|
|
7512
|
-
const valueSchemas = discriminatorValues(irCompositionSchema.$ref, schema.discriminator.mapping).map((value) => convertDiscriminatorValue(value, discriminatorPropertyType));
|
|
7513
|
-
irCompositionSchema = {
|
|
7514
|
-
items: [{
|
|
7515
|
-
properties: { [schema.discriminator.propertyName]: valueSchemas.length > 1 ? {
|
|
7516
|
-
items: valueSchemas,
|
|
7517
|
-
logicalOperator: "or"
|
|
7518
|
-
} : valueSchemas[0] },
|
|
7519
|
-
required: [schema.discriminator.propertyName],
|
|
7520
|
-
type: "object"
|
|
7521
|
-
}, irCompositionSchema],
|
|
7522
|
-
logicalOperator: "and"
|
|
7523
|
-
};
|
|
7524
|
-
}
|
|
7525
7570
|
if (irCompositionSchema.logicalOperator === "or" && irCompositionSchema.type !== "array" && irCompositionSchema.items) schemaItems = schemaItems.concat(irCompositionSchema.items);
|
|
7526
7571
|
else schemaItems.push(irCompositionSchema);
|
|
7527
7572
|
}
|
|
@@ -7545,7 +7590,10 @@ function parseOneOf({ context, schema, state }) {
|
|
|
7545
7590
|
logicalOperator: "and"
|
|
7546
7591
|
};
|
|
7547
7592
|
}
|
|
7548
|
-
if (schema.discriminator && irSchema.logicalOperator === "or") irSchema.discriminator = {
|
|
7593
|
+
if (schema.discriminator && irSchema.logicalOperator === "or") irSchema.discriminator = {
|
|
7594
|
+
...schema.discriminator.mapping && { mapping: schema.discriminator.mapping },
|
|
7595
|
+
propertyName: schema.discriminator.propertyName
|
|
7596
|
+
};
|
|
7549
7597
|
return irSchema;
|
|
7550
7598
|
}
|
|
7551
7599
|
function parseRef({ context, schema, state }) {
|
|
@@ -8776,37 +8824,7 @@ async function patchOpenApiSpec({ patchOptions, spec: _spec }) {
|
|
|
8776
8824
|
}
|
|
8777
8825
|
}
|
|
8778
8826
|
//#endregion
|
|
8779
|
-
//#region src/plugins/
|
|
8780
|
-
function stableStringify(value) {
|
|
8781
|
-
return JSON.stringify(value, (_, v) => {
|
|
8782
|
-
if (typeof v === "function") return `[function:${v.toString()}]`;
|
|
8783
|
-
if (v && typeof v === "object" && !Array.isArray(v)) return Object.fromEntries(Object.entries(v).sort(([a], [b]) => a.localeCompare(b)));
|
|
8784
|
-
return v;
|
|
8785
|
-
});
|
|
8786
|
-
}
|
|
8787
|
-
function normalizePluginEntry(plugin) {
|
|
8788
|
-
if (typeof plugin === "string") return {
|
|
8789
|
-
name: plugin,
|
|
8790
|
-
serialized: "{}"
|
|
8791
|
-
};
|
|
8792
|
-
const { name, ...config } = plugin;
|
|
8793
|
-
return {
|
|
8794
|
-
name,
|
|
8795
|
-
serialized: stableStringify(config)
|
|
8796
|
-
};
|
|
8797
|
-
}
|
|
8798
|
-
function warnOnConflictingDuplicatePlugins(plugins) {
|
|
8799
|
-
const seen = /* @__PURE__ */ new Map();
|
|
8800
|
-
for (const plugin of plugins) {
|
|
8801
|
-
const { name, serialized } = normalizePluginEntry(plugin);
|
|
8802
|
-
if (!name) continue;
|
|
8803
|
-
const previous = seen.get(name);
|
|
8804
|
-
if (previous !== void 0 && previous !== serialized) log.warn(`Plugin "${name}" is configured multiple times. Only the last instance will take effect.`);
|
|
8805
|
-
seen.set(name, serialized);
|
|
8806
|
-
}
|
|
8807
|
-
}
|
|
8808
|
-
//#endregion
|
|
8809
|
-
//#region src/plugins/shared/utils/config.ts
|
|
8827
|
+
//#region src/plugins/config.ts
|
|
8810
8828
|
function definePluginConfig(pluginConfig) {
|
|
8811
8829
|
return (userConfig) => ({
|
|
8812
8830
|
...pluginConfig,
|
|
@@ -8823,12 +8841,137 @@ function definePluginConfig(pluginConfig) {
|
|
|
8823
8841
|
name: pluginConfig.name
|
|
8824
8842
|
});
|
|
8825
8843
|
}
|
|
8844
|
+
function isPluginClient(plugin) {
|
|
8845
|
+
if (typeof plugin === "string") return plugin.startsWith("@hey-api/client");
|
|
8846
|
+
return plugin.name.startsWith("@hey-api/client") || Array.isArray(plugin.tags) && plugin.tags.includes("client");
|
|
8847
|
+
}
|
|
8848
|
+
function resolvePluginsConfig({ defaultPluginConfigs, dependencies, userPlugins, userPluginsConfig }) {
|
|
8849
|
+
const circularReferenceTracker = /* @__PURE__ */ new Set();
|
|
8850
|
+
const pluginOrder = /* @__PURE__ */ new Set();
|
|
8851
|
+
const plugins = {};
|
|
8852
|
+
const warnedMessages = /* @__PURE__ */ new Set();
|
|
8853
|
+
function dfs(name) {
|
|
8854
|
+
if (circularReferenceTracker.has(name)) throw new Error(`Circular reference detected at '${name}'`);
|
|
8855
|
+
if (pluginOrder.has(name)) return;
|
|
8856
|
+
circularReferenceTracker.add(name);
|
|
8857
|
+
const defaultPlugin = defaultPluginConfigs[name];
|
|
8858
|
+
const userPlugin = userPluginsConfig[name];
|
|
8859
|
+
if (!defaultPlugin && !userPlugin) throw new Error(`unknown plugin "${name}" - do you need to register a custom plugin with this name?`);
|
|
8860
|
+
const configTable = defaultPlugin?.config ?? userPlugin?.config ?? {};
|
|
8861
|
+
const userConfig = defaultPlugin && userPlugin?.config ? userPlugin.config : {};
|
|
8862
|
+
const pluginContext = {
|
|
8863
|
+
package: dependencyFactory(dependencies),
|
|
8864
|
+
resolveTag(tag, options = {}) {
|
|
8865
|
+
const { defaultPlugin, fallback = false, warn: warnMessage } = options;
|
|
8866
|
+
for (const userPlugin of userPlugins) if ((defaultPluginConfigs[userPlugin] || userPluginsConfig[userPlugin])?.tags?.includes(tag) && userPlugin !== name) return userPlugin;
|
|
8867
|
+
if (defaultPlugin) {
|
|
8868
|
+
if ((defaultPluginConfigs[defaultPlugin] || userPluginsConfig[defaultPlugin])?.tags?.includes(tag) && defaultPlugin !== name) return defaultPlugin;
|
|
8869
|
+
}
|
|
8870
|
+
if (warnMessage && !warnedMessages.has(warnMessage)) {
|
|
8871
|
+
warnedMessages.add(warnMessage);
|
|
8872
|
+
log.warn(warnMessage);
|
|
8873
|
+
}
|
|
8874
|
+
return fallback;
|
|
8875
|
+
}
|
|
8876
|
+
};
|
|
8877
|
+
const finalConfig = defineConfig(configTable)(userConfig, pluginContext);
|
|
8878
|
+
const finalDependencies = new Set([...defaultPlugin?.dependencies || [], ...userPlugin?.dependencies || []]);
|
|
8879
|
+
const plugin = {
|
|
8880
|
+
...defaultPlugin,
|
|
8881
|
+
...userPlugin,
|
|
8882
|
+
config: finalConfig,
|
|
8883
|
+
dependencies: finalDependencies
|
|
8884
|
+
};
|
|
8885
|
+
collectDeps(configTable, finalConfig, finalDependencies);
|
|
8886
|
+
for (const dependency of plugin.dependencies) dfs(dependency);
|
|
8887
|
+
circularReferenceTracker.delete(name);
|
|
8888
|
+
pluginOrder.add(name);
|
|
8889
|
+
plugins[name] = plugin;
|
|
8890
|
+
}
|
|
8891
|
+
for (const name of userPlugins) dfs(name);
|
|
8892
|
+
return {
|
|
8893
|
+
pluginOrder: Array.from(pluginOrder),
|
|
8894
|
+
plugins
|
|
8895
|
+
};
|
|
8896
|
+
}
|
|
8897
|
+
function resolvePlugins({ defaultPluginConfigs, defaultPlugins, dependencies, userConfig }) {
|
|
8898
|
+
const userPluginsConfig = {};
|
|
8899
|
+
const rawPresetPlugins = (userConfig.presets ?? []).flatMap((preset) => preset.plugins ?? []);
|
|
8900
|
+
const rawUserPlugins = userConfig.plugins ?? [];
|
|
8901
|
+
const rawPlugins = [...rawPresetPlugins, ...rawUserPlugins.length ? rawUserPlugins : defaultPlugins].filter((plugin) => typeof plugin === "string" && plugin || typeof plugin !== "string" && plugin.name);
|
|
8902
|
+
const mergedPlugins = [];
|
|
8903
|
+
const seenNames = /* @__PURE__ */ new Map();
|
|
8904
|
+
for (const plugin of rawPlugins) {
|
|
8905
|
+
if (typeof plugin === "string") {
|
|
8906
|
+
if (!seenNames.has(plugin)) {
|
|
8907
|
+
seenNames.set(plugin, {
|
|
8908
|
+
index: mergedPlugins.length,
|
|
8909
|
+
value: plugin
|
|
8910
|
+
});
|
|
8911
|
+
mergedPlugins.push(plugin);
|
|
8912
|
+
}
|
|
8913
|
+
continue;
|
|
8914
|
+
}
|
|
8915
|
+
if (!plugin?.name) continue;
|
|
8916
|
+
const name = plugin.name;
|
|
8917
|
+
if (!seenNames.has(name)) {
|
|
8918
|
+
seenNames.set(name, {
|
|
8919
|
+
index: mergedPlugins.length,
|
|
8920
|
+
value: plugin
|
|
8921
|
+
});
|
|
8922
|
+
mergedPlugins.push(plugin);
|
|
8923
|
+
continue;
|
|
8924
|
+
}
|
|
8925
|
+
const prev = seenNames.get(name);
|
|
8926
|
+
if (typeof prev.value === "string") {
|
|
8927
|
+
seenNames.set(name, {
|
|
8928
|
+
index: prev.index,
|
|
8929
|
+
value: { ...plugin }
|
|
8930
|
+
});
|
|
8931
|
+
mergedPlugins[prev.index] = { ...plugin };
|
|
8932
|
+
continue;
|
|
8933
|
+
}
|
|
8934
|
+
const mergedObj = deepMerge(prev.value, plugin);
|
|
8935
|
+
seenNames.set(name, {
|
|
8936
|
+
index: prev.index,
|
|
8937
|
+
value: mergedObj
|
|
8938
|
+
});
|
|
8939
|
+
mergedPlugins[prev.index] = mergedObj;
|
|
8940
|
+
}
|
|
8941
|
+
if (mergedPlugins.length > 0 && mergedPlugins.every((plugin) => isPluginClient(plugin))) {
|
|
8942
|
+
for (const name of [...defaultPlugins].reverse()) if (!seenNames.has(name)) mergedPlugins.unshift(name);
|
|
8943
|
+
}
|
|
8944
|
+
return resolvePluginsConfig({
|
|
8945
|
+
defaultPluginConfigs,
|
|
8946
|
+
dependencies,
|
|
8947
|
+
userPlugins: mergedPlugins.map((plugin) => {
|
|
8948
|
+
if (typeof plugin === "string") return plugin;
|
|
8949
|
+
const pluginName = plugin.name;
|
|
8950
|
+
if (pluginName) if (plugin.handler) userPluginsConfig[pluginName] = plugin;
|
|
8951
|
+
else {
|
|
8952
|
+
userPluginsConfig[pluginName] = { config: { ...plugin } };
|
|
8953
|
+
delete userPluginsConfig[pluginName].config.name;
|
|
8954
|
+
}
|
|
8955
|
+
return pluginName;
|
|
8956
|
+
}).filter(Boolean),
|
|
8957
|
+
userPluginsConfig
|
|
8958
|
+
});
|
|
8959
|
+
}
|
|
8960
|
+
//#endregion
|
|
8961
|
+
//#region src/plugins/helper.ts
|
|
8962
|
+
function pluginHelper(name) {
|
|
8963
|
+
return (config) => ({
|
|
8964
|
+
...config,
|
|
8965
|
+
name
|
|
8966
|
+
});
|
|
8967
|
+
}
|
|
8826
8968
|
//#endregion
|
|
8827
8969
|
//#region src/plugins/symbol.ts
|
|
8828
8970
|
/**
|
|
8829
|
-
*
|
|
8971
|
+
* Function to build the input for symbol registration, applying naming hooks if provided.
|
|
8830
8972
|
*/
|
|
8831
8973
|
function buildSymbolIn({ plugin, ...ctx }) {
|
|
8974
|
+
const priority = defaultPriorityFromPath(ctx.path);
|
|
8832
8975
|
const hooks = plugin.getHooks((hooks) => hooks.symbols?.getName);
|
|
8833
8976
|
for (const hook of hooks) {
|
|
8834
8977
|
const result = hook(ctx);
|
|
@@ -8836,18 +8979,29 @@ function buildSymbolIn({ plugin, ...ctx }) {
|
|
|
8836
8979
|
const name = result(ctx);
|
|
8837
8980
|
if (name) return {
|
|
8838
8981
|
meta: ctx.meta,
|
|
8839
|
-
name
|
|
8982
|
+
name,
|
|
8983
|
+
priority
|
|
8840
8984
|
};
|
|
8841
8985
|
} else if (typeof result === "string") return {
|
|
8842
8986
|
meta: ctx.meta,
|
|
8843
|
-
name: ctx.naming ? applyNaming(result, ctx.naming) : result
|
|
8987
|
+
name: ctx.naming ? applyNaming(result, ctx.naming) : result,
|
|
8988
|
+
priority
|
|
8844
8989
|
};
|
|
8845
8990
|
}
|
|
8846
8991
|
return {
|
|
8847
8992
|
meta: ctx.meta,
|
|
8848
|
-
name: ctx.naming ? applyNaming(ctx.name, ctx.naming) : ctx.name
|
|
8993
|
+
name: ctx.naming ? applyNaming(ctx.name, ctx.naming) : ctx.name,
|
|
8994
|
+
priority
|
|
8849
8995
|
};
|
|
8850
8996
|
}
|
|
8997
|
+
const MAX_PRIORITY_FROM_PATH = 100;
|
|
8998
|
+
/**
|
|
8999
|
+
* Derives naming priority from path depth.
|
|
9000
|
+
*/
|
|
9001
|
+
function defaultPriorityFromPath(path) {
|
|
9002
|
+
if (!path?.length) return;
|
|
9003
|
+
return Math.max(0, MAX_PRIORITY_FROM_PATH - path.length);
|
|
9004
|
+
}
|
|
8851
9005
|
//#endregion
|
|
8852
9006
|
//#region src/plugins/validator.ts
|
|
8853
9007
|
/**
|
|
@@ -9018,6 +9172,6 @@ function pathToName(path, options) {
|
|
|
9018
9172
|
return names.join("-");
|
|
9019
9173
|
}
|
|
9020
9174
|
//#endregion
|
|
9021
|
-
export { COERCER, ConfigError, ConfigValidationError, Context, HeyApiError, InputError, IntentContext, JobError, MinHeap, OperationPath, OperationStrategy, PluginInstance, addItemsToSchema, applyNaming, buildGraph, buildSymbolIn, checkNodeVersion, childContext, coerce, collectDeps, compileInputPath, createOperationKey, createSchemaProcessor, createSchemaWalker, debugTools, deduplicateSchema, defaultPaginationKeywords, defineConfig, definePluginConfig, dependencyFactory, encodeJsonPointerSegment, ensureDirSync, escapeComment, findPackageJson, findTsConfigPath, getInput, getInputError, getLogs, getParser, getSpec, hasOperationDataRequired, hasParameterGroupObjectRequired, hasParametersObjectRequired, heyApiRegistryBaseUrl, inputToApiRegistry, isCoercer, isEnvironment, isPlainObject, isTopLevelComponent, jsonPointerToPath, loadPackageJson, logCrashReport, logInputPaths, normalizeJsonPointer, openGitHubIssueWithCrashReport, operationPagination, operationResponsesMap, outputHeaderToPrefix, parameterWithPagination, parseOpenApiSpec, parseUrl, parseV2_0_X, parseV3_0_X, parseV3_1_X, patchOpenApiSpec, pathToJsonPointer, pathToName, postprocessOutput, printCliIntro, printCrashReport, refToName, requestValidatorLayers, resolveNaming, resolveRef, resolveValidatorLayer, satisfies, shouldReportCrash, sourceConfig, statusCodeToGroup, toCase, utils
|
|
9175
|
+
export { COERCER, ConfigError, ConfigValidationError, Context, HeyApiError, InputError, IntentContext, JobError, MinHeap, OperationPath, OperationStrategy, PluginInstance, SymbolFactory, addItemsToSchema, applyNaming, buildDiscriminatedUnion, buildGraph, buildSymbolIn, checkNodeVersion, childContext, coerce, collectDeps, compileInputPath, convertDiscriminatorValue, createOperationKey, createSchemaProcessor, createSchemaWalker, debugTools, deduplicateSchema, deepMerge, defaultPaginationKeywords, defineConfig, definePluginConfig, dependencyFactory, discriminatorValues, encodeJsonPointerSegment, ensureDirSync, escapeComment, findPackageJson, findTsConfigPath, getBaseUrl, getInput, getInputError, getLogs, getParser, getSpec, hasOperationDataRequired, hasParameterGroupObjectRequired, hasParametersObjectRequired, heyApiRegistryBaseUrl, inputToApiRegistry, isCoercer, isEnvironment, isPlainObject, isTopLevelComponent, jsonPointerToPath, loadPackageJson, logCrashReport, logInputPaths, normalizeJsonPointer, openGitHubIssueWithCrashReport, operationPagination, operationResponsesMap, outputHeaderToPrefix, parameterWithPagination, parseOpenApiSpec, parseUrl, parseV2_0_X, parseV3_0_X, parseV3_1_X, patchOpenApiSpec, pathToJsonPointer, pathToName, pluginHelper, postprocessOutput, printCliIntro, printCrashReport, refToName, requestValidatorLayers, resolveNaming, resolvePlugins, resolveRef, resolveValidatorLayer, satisfies, shouldReportCrash, sourceConfig, statusCodeToGroup, toCase, utils };
|
|
9022
9176
|
|
|
9023
9177
|
//# sourceMappingURL=index.mjs.map
|