@hey-api/shared 0.2.1 → 0.2.3
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 +89 -41
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +79 -29
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -91,6 +91,12 @@ const asciiToLines = (ascii, options) => {
|
|
|
91
91
|
maxLineLength
|
|
92
92
|
};
|
|
93
93
|
};
|
|
94
|
+
/**
|
|
95
|
+
* Checks the current environment based on the HEYAPI_CODEGEN_ENV environment variable.
|
|
96
|
+
*/
|
|
97
|
+
function isEnvironment(value) {
|
|
98
|
+
return process.env.HEYAPI_CODEGEN_ENV === value;
|
|
99
|
+
}
|
|
94
100
|
function printCliIntro(initialDir, showLogo = false) {
|
|
95
101
|
const packageJson = loadPackageJson(initialDir);
|
|
96
102
|
if (packageJson) {
|
|
@@ -98,7 +104,8 @@ function printCliIntro(initialDir, showLogo = false) {
|
|
|
98
104
|
const text = asciiToLines(textAscii, { padding: 1 });
|
|
99
105
|
for (const line of text.lines) console.log(colors.cyan(line));
|
|
100
106
|
}
|
|
101
|
-
|
|
107
|
+
const versionString = isEnvironment("development") ? "[DEVELOPMENT]" : `v${packageJson.version}`;
|
|
108
|
+
console.log(colors.gray(`${packageJson.name} ${versionString}`));
|
|
102
109
|
}
|
|
103
110
|
console.log("");
|
|
104
111
|
}
|
|
@@ -1822,6 +1829,7 @@ const defaultGetFilePath = (symbol) => {
|
|
|
1822
1829
|
if (!symbol.meta?.pluginName || typeof symbol.meta.pluginName !== "string") return;
|
|
1823
1830
|
if (symbol.meta.pluginName.startsWith("@hey-api/client-")) return "client";
|
|
1824
1831
|
if (symbol.meta.pluginName === "@hey-api/typescript") return "types";
|
|
1832
|
+
if (symbol.meta.pluginName === "@hey-api/python-sdk") return "sdk";
|
|
1825
1833
|
if (symbol.meta.pluginName.startsWith("@hey-api/")) return symbol.meta.pluginName.split("/")[1];
|
|
1826
1834
|
return symbol.meta.pluginName;
|
|
1827
1835
|
};
|
|
@@ -2027,7 +2035,7 @@ var PluginInstance = class {
|
|
|
2027
2035
|
return this.gen.symbols.reference(meta);
|
|
2028
2036
|
}
|
|
2029
2037
|
/**
|
|
2030
|
-
*
|
|
2038
|
+
* Alias for `symbol()` method with single argument.
|
|
2031
2039
|
*/
|
|
2032
2040
|
registerSymbol(symbol) {
|
|
2033
2041
|
return this.symbol(symbol.name, symbol);
|
|
@@ -5651,7 +5659,6 @@ const parseAllOf$1 = ({ context, schema, state }) => {
|
|
|
5651
5659
|
const schemaType = getSchemaType({ schema });
|
|
5652
5660
|
const compositionSchemas = schema.allOf;
|
|
5653
5661
|
const discriminatorsToAdd = [];
|
|
5654
|
-
const addedDiscriminators = /* @__PURE__ */ new Set();
|
|
5655
5662
|
for (const compositionSchema of compositionSchemas) {
|
|
5656
5663
|
const originalInAllOf = state.inAllOf;
|
|
5657
5664
|
if (!("$ref" in compositionSchema)) state.inAllOf = true;
|
|
@@ -5673,19 +5680,21 @@ const parseAllOf$1 = ({ context, schema, state }) => {
|
|
|
5673
5680
|
schema: ref$1
|
|
5674
5681
|
});
|
|
5675
5682
|
for (const { discriminator, oneOf } of discriminators) {
|
|
5676
|
-
if (addedDiscriminators.has(discriminator.propertyName)) continue;
|
|
5677
5683
|
const values = discriminatorValues(state.$ref, discriminator.mapping, oneOf ? () => oneOf.some((o) => "$ref" in o && o.$ref === state.$ref) : void 0);
|
|
5678
|
-
if (values.length
|
|
5679
|
-
|
|
5680
|
-
|
|
5681
|
-
|
|
5682
|
-
|
|
5683
|
-
|
|
5684
|
-
|
|
5685
|
-
|
|
5686
|
-
|
|
5687
|
-
|
|
5688
|
-
|
|
5684
|
+
if (values.length === 0) continue;
|
|
5685
|
+
const isExplicitMapping = discriminator.mapping !== void 0 && Object.values(discriminator.mapping).includes(state.$ref);
|
|
5686
|
+
const existingIndex = discriminatorsToAdd.findIndex((d) => d.discriminator.propertyName === discriminator.propertyName);
|
|
5687
|
+
if (existingIndex !== -1) if (isExplicitMapping && !discriminatorsToAdd[existingIndex].isExplicitMapping) discriminatorsToAdd.splice(existingIndex, 1);
|
|
5688
|
+
else continue;
|
|
5689
|
+
const isRequired = discriminators.some((d) => d.discriminator.propertyName === discriminator.propertyName && (ref$1.required?.includes(d.discriminator.propertyName) || ref$1.allOf && ref$1.allOf.some((item) => {
|
|
5690
|
+
return ("$ref" in item ? context.resolveRef(item.$ref) : item).required?.includes(d.discriminator.propertyName);
|
|
5691
|
+
})));
|
|
5692
|
+
discriminatorsToAdd.push({
|
|
5693
|
+
discriminator,
|
|
5694
|
+
isExplicitMapping,
|
|
5695
|
+
isRequired,
|
|
5696
|
+
values
|
|
5697
|
+
});
|
|
5689
5698
|
}
|
|
5690
5699
|
}
|
|
5691
5700
|
}
|
|
@@ -7027,7 +7036,6 @@ const parseAllOf = ({ context, schema, state }) => {
|
|
|
7027
7036
|
const schemaTypes = getSchemaTypes({ schema });
|
|
7028
7037
|
const compositionSchemas = schema.allOf;
|
|
7029
7038
|
const discriminatorsToAdd = [];
|
|
7030
|
-
const addedDiscriminators = /* @__PURE__ */ new Set();
|
|
7031
7039
|
for (const compositionSchema of compositionSchemas) {
|
|
7032
7040
|
const originalInAllOf = state.inAllOf;
|
|
7033
7041
|
if (!("$ref" in compositionSchema)) state.inAllOf = true;
|
|
@@ -7049,19 +7057,21 @@ const parseAllOf = ({ context, schema, state }) => {
|
|
|
7049
7057
|
schema: ref$1
|
|
7050
7058
|
});
|
|
7051
7059
|
for (const { discriminator, oneOf } of discriminators) {
|
|
7052
|
-
if (addedDiscriminators.has(discriminator.propertyName)) continue;
|
|
7053
7060
|
const values = discriminatorValues(state.$ref, discriminator.mapping, oneOf ? () => oneOf.some((o) => "$ref" in o && o.$ref === state.$ref) : void 0);
|
|
7054
|
-
if (values.length
|
|
7055
|
-
|
|
7056
|
-
|
|
7057
|
-
|
|
7058
|
-
|
|
7059
|
-
|
|
7060
|
-
|
|
7061
|
-
|
|
7062
|
-
|
|
7063
|
-
|
|
7064
|
-
|
|
7061
|
+
if (values.length === 0) continue;
|
|
7062
|
+
const isExplicitMapping = discriminator.mapping !== void 0 && Object.values(discriminator.mapping).includes(state.$ref);
|
|
7063
|
+
const existingIndex = discriminatorsToAdd.findIndex((d) => d.discriminator.propertyName === discriminator.propertyName);
|
|
7064
|
+
if (existingIndex !== -1) if (isExplicitMapping && !discriminatorsToAdd[existingIndex].isExplicitMapping) discriminatorsToAdd.splice(existingIndex, 1);
|
|
7065
|
+
else continue;
|
|
7066
|
+
const isRequired = discriminators.some((d) => d.discriminator.propertyName === discriminator.propertyName && (ref$1.required?.includes(d.discriminator.propertyName) || ref$1.allOf && ref$1.allOf.some((item) => {
|
|
7067
|
+
return (item.$ref ? context.resolveRef(item.$ref) : item).required?.includes(d.discriminator.propertyName);
|
|
7068
|
+
})));
|
|
7069
|
+
discriminatorsToAdd.push({
|
|
7070
|
+
discriminator,
|
|
7071
|
+
isExplicitMapping,
|
|
7072
|
+
isRequired,
|
|
7073
|
+
values
|
|
7074
|
+
});
|
|
7065
7075
|
}
|
|
7066
7076
|
}
|
|
7067
7077
|
}
|
|
@@ -8492,6 +8502,33 @@ const mappers = {
|
|
|
8492
8502
|
string: (name) => ({ name })
|
|
8493
8503
|
};
|
|
8494
8504
|
|
|
8505
|
+
//#endregion
|
|
8506
|
+
//#region src/plugins/symbol.ts
|
|
8507
|
+
/**
|
|
8508
|
+
* Helper function to build the input for symbol registration, applying naming hooks if provided.
|
|
8509
|
+
*/
|
|
8510
|
+
function buildSymbolIn({ plugin, ...ctx }) {
|
|
8511
|
+
const hooks = [plugin.config["~hooks"]?.symbols?.getName, plugin.context.config.parser.hooks.symbols?.getName];
|
|
8512
|
+
for (const hook of hooks) {
|
|
8513
|
+
if (!hook) continue;
|
|
8514
|
+
const result = hook(ctx);
|
|
8515
|
+
if (typeof result === "function") {
|
|
8516
|
+
const name = result(ctx);
|
|
8517
|
+
if (name) return {
|
|
8518
|
+
meta: ctx.meta,
|
|
8519
|
+
name
|
|
8520
|
+
};
|
|
8521
|
+
} else if (typeof result === "string") return {
|
|
8522
|
+
meta: ctx.meta,
|
|
8523
|
+
name: ctx.naming ? applyNaming(result, ctx.naming) : result
|
|
8524
|
+
};
|
|
8525
|
+
}
|
|
8526
|
+
return {
|
|
8527
|
+
meta: ctx.meta,
|
|
8528
|
+
name: ctx.naming ? applyNaming(ctx.name, ctx.naming) : ctx.name
|
|
8529
|
+
};
|
|
8530
|
+
}
|
|
8531
|
+
|
|
8495
8532
|
//#endregion
|
|
8496
8533
|
//#region src/utils/escape.ts
|
|
8497
8534
|
function escapeComment(value) {
|
|
@@ -8510,6 +8547,19 @@ const utils = {
|
|
|
8510
8547
|
toCase
|
|
8511
8548
|
};
|
|
8512
8549
|
|
|
8550
|
+
//#endregion
|
|
8551
|
+
//#region src/utils/header.ts
|
|
8552
|
+
/**
|
|
8553
|
+
* Converts an {@link OutputHeader} value to a string prefix for file content.
|
|
8554
|
+
*/
|
|
8555
|
+
function outputHeaderToPrefix(header, project) {
|
|
8556
|
+
let lines = typeof header === "function" ? header({ project }) : header;
|
|
8557
|
+
if (lines === null || lines === void 0) return "";
|
|
8558
|
+
lines = typeof lines === "string" ? lines.split(/\r?\n/) : lines.flatMap((line) => line.split(/\r?\n/));
|
|
8559
|
+
const content = lines.join("\n");
|
|
8560
|
+
return content ? `${content}\n\n` : "";
|
|
8561
|
+
}
|
|
8562
|
+
|
|
8513
8563
|
//#endregion
|
|
8514
8564
|
//#region src/utils/path.ts
|
|
8515
8565
|
/**
|
|
@@ -8615,5 +8665,5 @@ function pathToName(path$1, options) {
|
|
|
8615
8665
|
}
|
|
8616
8666
|
|
|
8617
8667
|
//#endregion
|
|
8618
|
-
export { ConfigError, ConfigValidationError, Context, HeyApiError, IntentContext, JobError, MinHeap, OperationPath, OperationStrategy, PluginInstance, addItemsToSchema, applyNaming, buildGraph, checkNodeVersion, childContext, compileInputPath, createOperationKey, createSchemaProcessor, createSchemaWalker, debugTools, deduplicateSchema, defaultPaginationKeywords, definePluginConfig, dependencyFactory, encodeJsonPointerSegment, ensureDirSync, escapeComment, findPackageJson, findTsConfigPath, getInput, getLogs, getParser, getSpec, hasOperationDataRequired, hasParameterGroupObjectRequired, hasParametersObjectRequired, heyApiRegistryBaseUrl, inputToApiRegistry, isTopLevelComponent, jsonPointerToPath, loadPackageJson, loadTsConfig, logCrashReport, logInputPaths, mappers, normalizeJsonPointer, openGitHubIssueWithCrashReport, operationPagination, operationResponsesMap, parameterWithPagination, parseOpenApiSpec, parseUrl, parseV2_0_X, parseV3_0_X, parseV3_1_X, patchOpenApiSpec, pathToJsonPointer, pathToName, postprocessOutput, printCliIntro, printCrashReport, refToName, resolveNaming, resolveRef, resolveSource, satisfies, shouldReportCrash, statusCodeToGroup, toCase, utils, valueToObject };
|
|
8668
|
+
export { ConfigError, ConfigValidationError, Context, HeyApiError, IntentContext, JobError, MinHeap, OperationPath, OperationStrategy, PluginInstance, addItemsToSchema, applyNaming, buildGraph, buildSymbolIn, checkNodeVersion, childContext, compileInputPath, createOperationKey, createSchemaProcessor, createSchemaWalker, debugTools, deduplicateSchema, defaultPaginationKeywords, definePluginConfig, dependencyFactory, encodeJsonPointerSegment, ensureDirSync, escapeComment, findPackageJson, findTsConfigPath, getInput, getLogs, getParser, getSpec, hasOperationDataRequired, hasParameterGroupObjectRequired, hasParametersObjectRequired, heyApiRegistryBaseUrl, inputToApiRegistry, isEnvironment, isTopLevelComponent, jsonPointerToPath, loadPackageJson, loadTsConfig, logCrashReport, logInputPaths, mappers, normalizeJsonPointer, openGitHubIssueWithCrashReport, operationPagination, operationResponsesMap, outputHeaderToPrefix, parameterWithPagination, parseOpenApiSpec, parseUrl, parseV2_0_X, parseV3_0_X, parseV3_1_X, patchOpenApiSpec, pathToJsonPointer, pathToName, postprocessOutput, printCliIntro, printCrashReport, refToName, resolveNaming, resolveRef, resolveSource, satisfies, shouldReportCrash, statusCodeToGroup, toCase, utils, valueToObject };
|
|
8619
8669
|
//# sourceMappingURL=index.mjs.map
|