@hey-api/shared 0.1.2 → 0.2.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.mjs CHANGED
@@ -1782,7 +1782,7 @@ function pathToJsonPointer(path$1) {
1782
1782
  return "#" + (segments ? `/${segments}` : "");
1783
1783
  }
1784
1784
  /**
1785
- * Checks if a $ref points to a top-level component (not a deep path reference).
1785
+ * Checks if a $ref or path points to a top-level component (not a deep path reference).
1786
1786
  *
1787
1787
  * Top-level component references:
1788
1788
  * - OpenAPI 3.x: #/components/{type}/{name} (3 segments)
@@ -1791,11 +1791,11 @@ function pathToJsonPointer(path$1) {
1791
1791
  * Deep path references (4+ segments for 3.x, 3+ for 2.0) should be inlined
1792
1792
  * because they don't have corresponding registered symbols.
1793
1793
  *
1794
- * @param $ref - The $ref string to check
1794
+ * @param refOrPath - The $ref string or path array to check
1795
1795
  * @returns true if the ref points to a top-level component, false otherwise
1796
1796
  */
1797
- function isTopLevelComponentRef($ref) {
1798
- const path$1 = jsonPointerToPath($ref);
1797
+ function isTopLevelComponent(refOrPath) {
1798
+ const path$1 = refOrPath instanceof Array ? refOrPath : jsonPointerToPath(refOrPath);
1799
1799
  if (path$1[0] === "components") return path$1.length === 3;
1800
1800
  if (path$1[0] === "definitions") return path$1.length === 2;
1801
1801
  return false;
@@ -4364,7 +4364,7 @@ const parseEnum$2 = ({ context, schema, state }) => {
4364
4364
  };
4365
4365
  const parseRef$2 = ({ context, schema, state }) => {
4366
4366
  const irSchema = {};
4367
- if (!isTopLevelComponentRef(schema.$ref)) {
4367
+ if (!isTopLevelComponent(schema.$ref)) {
4368
4368
  if (!state.circularReferenceTracker.has(schema.$ref)) {
4369
4369
  const refSchema = context.resolveRef(schema.$ref);
4370
4370
  const originalRef = state.$ref;
@@ -5690,7 +5690,7 @@ const parseOneOf$1 = ({ context, schema, state }) => {
5690
5690
  return irSchema;
5691
5691
  };
5692
5692
  const parseRef$1 = ({ context, schema, state }) => {
5693
- if (!isTopLevelComponentRef(schema.$ref)) {
5693
+ if (!isTopLevelComponent(schema.$ref)) {
5694
5694
  if (!state.circularReferenceTracker.has(schema.$ref)) {
5695
5695
  const refSchema = context.resolveRef(schema.$ref);
5696
5696
  const originalRef = state.$ref;
@@ -7038,7 +7038,7 @@ const parseOneOf = ({ context, schema, state }) => {
7038
7038
  return irSchema;
7039
7039
  };
7040
7040
  const parseRef = ({ context, schema, state }) => {
7041
- if (!isTopLevelComponentRef(schema.$ref)) {
7041
+ if (!isTopLevelComponent(schema.$ref)) {
7042
7042
  if (!state.circularReferenceTracker.has(schema.$ref)) {
7043
7043
  const refSchema = context.resolveRef(schema.$ref);
7044
7044
  const originalRef = state.$ref;
@@ -8144,6 +8144,43 @@ function patchOpenApiSpec({ patchOptions, spec: _spec }) {
8144
8144
  }
8145
8145
  }
8146
8146
 
8147
+ //#endregion
8148
+ //#region src/plugins/schema-processor.ts
8149
+ function createSchemaProcessor() {
8150
+ const emitted = /* @__PURE__ */ new Set();
8151
+ let contextTags;
8152
+ let contextAnchor;
8153
+ return {
8154
+ get context() {
8155
+ return {
8156
+ anchor: contextAnchor,
8157
+ tags: contextTags
8158
+ };
8159
+ },
8160
+ hasEmitted(path$1) {
8161
+ return emitted.has(pathToJsonPointer(path$1));
8162
+ },
8163
+ markEmitted(path$1) {
8164
+ const pointer = pathToJsonPointer(path$1);
8165
+ if (emitted.has(pointer)) return false;
8166
+ emitted.add(pointer);
8167
+ return true;
8168
+ },
8169
+ withContext(ctx, fn) {
8170
+ const prevTags = contextTags;
8171
+ const prevAnchor = contextAnchor;
8172
+ contextTags = ctx.tags;
8173
+ contextAnchor = ctx.anchor;
8174
+ try {
8175
+ return fn();
8176
+ } finally {
8177
+ contextTags = prevTags;
8178
+ contextAnchor = prevAnchor;
8179
+ }
8180
+ }
8181
+ };
8182
+ }
8183
+
8147
8184
  //#endregion
8148
8185
  //#region src/plugins/shared/utils/config.ts
8149
8186
  const definePluginConfig = (defaultConfig) => (userConfig) => ({
@@ -8181,5 +8218,109 @@ const utils = {
8181
8218
  };
8182
8219
 
8183
8220
  //#endregion
8184
- export { ConfigError, ConfigValidationError, Context, HeyApiError, IntentContext, JobError, MinHeap, OperationPath, OperationStrategy, PluginInstance, applyNaming, buildGraph, checkNodeVersion, compileInputPath, createOperationKey, debugTools, deduplicateSchema, defaultPaginationKeywords, definePluginConfig, dependencyFactory, encodeJsonPointerSegment, ensureDirSync, escapeComment, findPackageJson, findTsConfigPath, getInput, getLogs, getParser, getSpec, hasOperationDataRequired, hasParameterGroupObjectRequired, hasParametersObjectRequired, heyApiRegistryBaseUrl, inputToApiRegistry, isTopLevelComponentRef, jsonPointerToPath, loadPackageJson, loadTsConfig, logCrashReport, logInputPaths, mappers, normalizeJsonPointer, openGitHubIssueWithCrashReport, operationPagination, operationResponsesMap, parameterWithPagination, parseOpenApiSpec, parseUrl, parseV2_0_X, parseV3_0_X, parseV3_1_X, patchOpenApiSpec, pathToJsonPointer, postprocessOutput, printCliIntro, printCrashReport, refToName, resolveNaming, resolveRef, resolveSource, satisfies, shouldReportCrash, statusCodeToGroup, toCase, utils, valueToObject };
8221
+ //#region src/utils/path.ts
8222
+ /**
8223
+ * After these structural segments, the next segment has a known role.
8224
+ * This is what makes a property literally named "properties" safe —
8225
+ * it occupies the name position, never the structural position.
8226
+ */
8227
+ const STRUCTURAL_ROLE = {
8228
+ items: "index",
8229
+ patternProperties: "name",
8230
+ properties: "name"
8231
+ };
8232
+ /**
8233
+ * These structural segments have no following name/index —
8234
+ * they are the terminal structural node. Append a suffix
8235
+ * to disambiguate from the parent.
8236
+ */
8237
+ const STRUCTURAL_SUFFIX = { additionalProperties: "Value" };
8238
+ /**
8239
+ * Root context configuration.
8240
+ */
8241
+ const ROOT_CONTEXT = {
8242
+ components: {
8243
+ names: 1,
8244
+ skip: 2
8245
+ },
8246
+ definitions: {
8247
+ names: 1,
8248
+ skip: 1
8249
+ },
8250
+ paths: {
8251
+ names: 2,
8252
+ skip: 1
8253
+ },
8254
+ webhooks: {
8255
+ names: 2,
8256
+ skip: 1
8257
+ }
8258
+ };
8259
+ /**
8260
+ * Sanitizes a path segment for use in a derived name.
8261
+ *
8262
+ * Handles API path segments like `/api/v1/users/{id}` → `ApiV1UsersId`.
8263
+ */
8264
+ function sanitizeSegment(segment) {
8265
+ const str = String(segment);
8266
+ if (str.startsWith("/")) return str.split("/").filter(Boolean).map((part) => {
8267
+ const clean = part.replace(/[{}]/g, "");
8268
+ return clean.charAt(0).toUpperCase() + clean.slice(1);
8269
+ }).join("");
8270
+ return str;
8271
+ }
8272
+ /**
8273
+ * Derives a composite name from a path.
8274
+ *
8275
+ * Examples:
8276
+ * .../User → 'User'
8277
+ * .../User/properties/address → 'UserAddress'
8278
+ * .../User/properties/properties → 'UserProperties'
8279
+ * .../User/properties/address/properties/city → 'UserAddressCity'
8280
+ * .../Pet/additionalProperties → 'PetValue'
8281
+ * .../Order/properties/items/items/0 → 'OrderItems'
8282
+ * paths//event/get/properties/query → 'EventGetQuery'
8283
+ *
8284
+ * With anchor:
8285
+ * paths//event/get/properties/query, { anchor: 'event.subscribe' }
8286
+ * → 'event.subscribe-Query'
8287
+ */
8288
+ function pathToName(path$1, options) {
8289
+ const names = [];
8290
+ let index = 0;
8291
+ const rootContext = ROOT_CONTEXT[path$1[0]];
8292
+ if (rootContext) {
8293
+ index = rootContext.skip;
8294
+ if (options?.anchor) {
8295
+ names.push(options.anchor);
8296
+ index += rootContext.names;
8297
+ } else for (let n = 0; n < rootContext.names && index < path$1.length; n++) {
8298
+ names.push(sanitizeSegment(path$1[index]));
8299
+ index++;
8300
+ }
8301
+ } else if (options?.anchor) {
8302
+ names.push(options.anchor);
8303
+ index++;
8304
+ } else if (index < path$1.length) {
8305
+ names.push(sanitizeSegment(path$1[index]));
8306
+ index++;
8307
+ }
8308
+ while (index < path$1.length) {
8309
+ const segment = String(path$1[index]);
8310
+ const role = STRUCTURAL_ROLE[segment];
8311
+ if (role === "name") {
8312
+ index++;
8313
+ if (index < path$1.length) names.push(sanitizeSegment(path$1[index]));
8314
+ } else if (role === "index") {
8315
+ index++;
8316
+ if (index < path$1.length && typeof path$1[index] === "number") index++;
8317
+ continue;
8318
+ } else if (STRUCTURAL_SUFFIX[segment]) names.push(STRUCTURAL_SUFFIX[segment]);
8319
+ index++;
8320
+ }
8321
+ return decodeURI(names.join("-"));
8322
+ }
8323
+
8324
+ //#endregion
8325
+ export { ConfigError, ConfigValidationError, Context, HeyApiError, IntentContext, JobError, MinHeap, OperationPath, OperationStrategy, PluginInstance, addItemsToSchema, applyNaming, buildGraph, checkNodeVersion, compileInputPath, createOperationKey, createSchemaProcessor, 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 };
8185
8326
  //# sourceMappingURL=index.mjs.map