@hey-api/shared 0.1.1 → 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.d.mts CHANGED
@@ -2965,6 +2965,40 @@ declare namespace IR {
2965
2965
  type WebhookObject = IRWebhookObject;
2966
2966
  }
2967
2967
  //#endregion
2968
+ //#region src/plugins/schema-processor.d.ts
2969
+ interface SchemaProcessor {
2970
+ /** Current inherited context (set by withContext) */
2971
+ readonly context: {
2972
+ readonly anchor: string | undefined;
2973
+ readonly tags: ReadonlyArray<string> | undefined;
2974
+ };
2975
+ /** Check if pointer was already emitted */
2976
+ hasEmitted: (path: ReadonlyArray<string | number>) => boolean;
2977
+ /** Mark pointer as emitted. Returns false if already emitted. */
2978
+ markEmitted: (path: ReadonlyArray<string | number>) => boolean;
2979
+ /** Execute with inherited context for nested extractions */
2980
+ withContext: <T>(ctx: {
2981
+ anchor?: string;
2982
+ tags?: ReadonlyArray<string>;
2983
+ }, fn: () => T) => T;
2984
+ }
2985
+ interface SchemaProcessorContext {
2986
+ meta: {
2987
+ resource: string;
2988
+ resourceId: string;
2989
+ role?: string;
2990
+ };
2991
+ namingAnchor?: string;
2992
+ path: ReadonlyArray<string | number>;
2993
+ schema: IR.SchemaObject;
2994
+ tags?: ReadonlyArray<string>;
2995
+ }
2996
+ interface SchemaProcessorResult<Context$1 extends SchemaProcessorContext = SchemaProcessorContext> {
2997
+ process: (ctx: Context$1) => void;
2998
+ }
2999
+ type SchemaExtractor<Context$1 extends SchemaProcessorContext = SchemaProcessorContext> = (ctx: Context$1) => IR.SchemaObject;
3000
+ declare function createSchemaProcessor(): SchemaProcessor;
3001
+ //#endregion
2968
3002
  //#region src/openApi/shared/utils/graph.d.ts
2969
3003
  /**
2970
3004
  * Represents the possible access scopes for OpenAPI nodes.
@@ -3224,14 +3258,17 @@ type WalkEvents = BaseEvent & ({
3224
3258
  path: string;
3225
3259
  type: Extract<IrTopLevelKind, 'operation'>;
3226
3260
  } | {
3261
+ /** Name of the parameter (e.g., "id" for a parameter defined as "#/components/parameters/id"). */
3227
3262
  name: string;
3228
3263
  parameter: IR.ParameterObject;
3229
3264
  type: Extract<IrTopLevelKind, 'parameter'>;
3230
3265
  } | {
3266
+ /** Name of the request body (e.g., "CreateUserRequest" for a request body defined as "#/components/requestBodies/CreateUserRequest"). */
3231
3267
  name: string;
3232
3268
  requestBody: IR.RequestBodyObject;
3233
3269
  type: Extract<IrTopLevelKind, 'requestBody'>;
3234
3270
  } | {
3271
+ /** Name of the schema (e.g., "User" for a schema defined as "#/components/schemas/User"). */
3235
3272
  name: string;
3236
3273
  schema: IR.SchemaObject;
3237
3274
  type: Extract<IrTopLevelKind, 'schema'>;
@@ -3360,6 +3397,7 @@ declare class PluginInstance<T extends Plugin.Types = Plugin.Types> {
3360
3397
  symbolOnce(name: SymbolIn['name'], symbol?: Omit<SymbolIn, 'name'>): Symbol;
3361
3398
  private buildEventHooks;
3362
3399
  private forEachError;
3400
+ private getSymbolExportFromFilePath;
3363
3401
  private getSymbolFilePath;
3364
3402
  private isOperationKind;
3365
3403
  }
@@ -3527,6 +3565,28 @@ type Hooks = {
3527
3565
  */
3528
3566
  isQuery?: (operation: IROperationObject) => boolean | undefined;
3529
3567
  };
3568
+ schemas?: {
3569
+ /**
3570
+ * Whether to extract the given schema into a separate symbol.
3571
+ *
3572
+ * This affects how schemas are processed and output.
3573
+ *
3574
+ * **Default behavior:** No schemas are extracted.
3575
+ *
3576
+ * @param ctx - The processing context for the schema.
3577
+ * @returns true to extract the schema, false to keep it inline, or undefined to fallback to default behavior.
3578
+ * @example
3579
+ * ```ts
3580
+ * shouldExtract: (ctx) => {
3581
+ * if (ctx.meta.resource === 'requestBody') {
3582
+ * return true;
3583
+ * }
3584
+ * return; // fallback to default behavior
3585
+ * }
3586
+ * ```
3587
+ */
3588
+ shouldExtract?: (ctx: SchemaProcessorContext) => boolean;
3589
+ };
3530
3590
  /**
3531
3591
  * Hooks specifically for overriding symbols behavior.
3532
3592
  *
@@ -3536,7 +3596,15 @@ type Hooks = {
3536
3596
  /**
3537
3597
  * Optional output strategy to override default plugin behavior.
3538
3598
  *
3539
- * Use this to route generated symbols to specific files.
3599
+ * Use this to re-export symbols from specific files.
3600
+ *
3601
+ * @returns The file path(s) that re-export this symbol, or undefined to fallback to default behavior.
3602
+ */
3603
+ getExportFromFilePath?: (symbol: Symbol) => ReadonlyArray<string> | undefined;
3604
+ /**
3605
+ * Optional output strategy to override default plugin behavior.
3606
+ *
3607
+ * Use this to route symbols to specific files.
3540
3608
  *
3541
3609
  * @returns The file path to output the symbol to, or undefined to fallback to default behavior.
3542
3610
  */
@@ -3558,11 +3626,7 @@ type PluginContext = {
3558
3626
  valueToObject: ValueToObject;
3559
3627
  };
3560
3628
  type BaseApi = Record<string, unknown>;
3561
- type BaseConfig$1 = {
3562
- /**
3563
- * Whether exports should be re-exported in the index file.
3564
- */
3565
- exportFromIndex?: boolean;
3629
+ type PluginBaseConfig = UserIndexExportOption & {
3566
3630
  name: AnyPluginName;
3567
3631
  /**
3568
3632
  * Optional hooks to override default plugin behavior.
@@ -3601,10 +3665,14 @@ declare namespace Plugin {
3601
3665
  */
3602
3666
  tags?: ReadonlyArray<PluginTag>;
3603
3667
  };
3668
+ type Comments = CommentsOption;
3669
+ type UserComments = UserCommentsOption;
3670
+ type Exports = IndexExportOption;
3671
+ type UserExports = UserIndexExportOption;
3604
3672
  /**
3605
3673
  * Generic wrapper for plugin hooks.
3606
3674
  */
3607
- type Hooks = Pick<BaseConfig$1, '~hooks'>;
3675
+ type Hooks = Pick<PluginBaseConfig, '~hooks'>;
3608
3676
  interface Name<Name extends PluginNames> {
3609
3677
  name: Name;
3610
3678
  }
@@ -3624,7 +3692,7 @@ declare namespace Plugin {
3624
3692
  */
3625
3693
  '~resolvers'?: T;
3626
3694
  };
3627
- type Types<Config extends BaseConfig$1 = BaseConfig$1, ResolvedConfig extends BaseConfig$1 = Config, Api extends BaseApi = never> = ([Api] extends [never] ? {
3695
+ type Types<Config extends PluginBaseConfig = PluginBaseConfig, ResolvedConfig extends PluginBaseConfig = Config, Api extends BaseApi = never> = ([Api] extends [never] ? {
3628
3696
  api?: BaseApi;
3629
3697
  } : {
3630
3698
  api: Api;
@@ -3633,7 +3701,7 @@ declare namespace Plugin {
3633
3701
  resolvedConfig: ResolvedConfig;
3634
3702
  };
3635
3703
  }
3636
- type DefinePlugin<Config extends BaseConfig$1 = BaseConfig$1, ResolvedConfig extends BaseConfig$1 = Config, Api extends BaseApi = never> = {
3704
+ type DefinePlugin<Config extends PluginBaseConfig = PluginBaseConfig, ResolvedConfig extends PluginBaseConfig = Config, Api extends BaseApi = never> = {
3637
3705
  Config: Plugin.Config<Plugin.Types<Config, ResolvedConfig, Api>>;
3638
3706
  Handler: (args: {
3639
3707
  plugin: PluginInstance<Plugin.Types<Config, ResolvedConfig, Api>>;
@@ -7200,11 +7268,54 @@ type FeatureToggle = {
7200
7268
  */
7201
7269
  enabled: boolean;
7202
7270
  };
7271
+ type UserIndexExportOption = {
7272
+ /**
7273
+ * Whether exports should be re-exported from the entry file.
7274
+ *
7275
+ * - `true` — include all exports
7276
+ * - `false` — exclude all exports
7277
+ * - `(symbol) => boolean` — include exports matching the predicate
7278
+ *
7279
+ * @default false
7280
+ * @deprecated use `includeInEntry` instead
7281
+ */
7282
+ exportFromIndex?: boolean | ((symbol: Symbol) => boolean);
7283
+ /**
7284
+ * Whether exports should be re-exported from the entry file.
7285
+ *
7286
+ * - `true` — include all exports
7287
+ * - `false` — exclude all exports
7288
+ * - `(symbol) => boolean` — include exports matching the predicate
7289
+ *
7290
+ * @default false
7291
+ */
7292
+ includeInEntry?: boolean | ((symbol: Symbol) => boolean);
7293
+ };
7203
7294
  type IndexExportOption = {
7204
7295
  /**
7205
- * Whether exports should be re-exported in the index file.
7296
+ * Whether exports should be re-exported from the entry file.
7297
+ *
7298
+ * @deprecated use `includeInEntry` instead
7299
+ */
7300
+ exportFromIndex: boolean | ((symbol: Symbol) => boolean);
7301
+ /**
7302
+ * Whether exports should be re-exported from the entry file.
7303
+ */
7304
+ includeInEntry: boolean | ((symbol: Symbol) => boolean);
7305
+ };
7306
+ type UserCommentsOption = {
7307
+ /**
7308
+ * Whether to add comments to the generated code.
7309
+ *
7310
+ * @default true
7311
+ */
7312
+ comments?: boolean;
7313
+ };
7314
+ type CommentsOption = {
7315
+ /**
7316
+ * Whether to add comments to the generated code.
7206
7317
  */
7207
- exportFromIndex: boolean;
7318
+ comments: boolean;
7208
7319
  };
7209
7320
  type NamingOptions = {
7210
7321
  /**
@@ -7236,6 +7347,14 @@ interface BaseUserOutput {
7236
7347
  * @default true
7237
7348
  */
7238
7349
  clean?: boolean;
7350
+ /**
7351
+ * Whether to generate an entry file that re-exports symbols for convenient imports.
7352
+ *
7353
+ * Plugins control their inclusion via `includeInEntry`.
7354
+ *
7355
+ * @default true
7356
+ */
7357
+ entryFile?: boolean;
7239
7358
  /**
7240
7359
  * Optional function to transform file names before they are used.
7241
7360
  *
@@ -7274,11 +7393,12 @@ interface BaseUserOutput {
7274
7393
  */
7275
7394
  header?: OutputHeader;
7276
7395
  /**
7277
- * Should the exports from plugin files be re-exported in the index
7278
- * barrel file? By default, this is enabled and only default plugins
7279
- * are re-exported.
7396
+ * Whether to generate an entry file that re-exports symbols for convenient imports.
7397
+ *
7398
+ * Plugins control their inclusion via `includeInEntry`.
7280
7399
  *
7281
7400
  * @default true
7401
+ * @deprecated use `entryFile` instead
7282
7402
  */
7283
7403
  indexFile?: boolean;
7284
7404
  /**
@@ -7323,6 +7443,10 @@ interface BaseOutput {
7323
7443
  * input, or package version changes.
7324
7444
  */
7325
7445
  clean: boolean;
7446
+ /**
7447
+ * Whether to generate an entry file that re-exports symbols for convenient imports.
7448
+ */
7449
+ entryFile: boolean;
7326
7450
  /**
7327
7451
  * Optional function to transform file names before they are used.
7328
7452
  *
@@ -7347,9 +7471,9 @@ interface BaseOutput {
7347
7471
  */
7348
7472
  header: OutputHeader;
7349
7473
  /**
7350
- * Should the exports from plugin files be re-exported in the index
7351
- * barrel file? By default, this is enabled and only default plugins
7352
- * are re-exported.
7474
+ * Whether to generate an entry file that re-exports symbols for convenient imports.
7475
+ *
7476
+ * @deprecated use `entryFile` instead
7353
7477
  */
7354
7478
  indexFile: boolean;
7355
7479
  /**
@@ -7780,6 +7904,23 @@ declare function deduplicateSchema<T extends IR.SchemaObject>({
7780
7904
  schema: T;
7781
7905
  }): T;
7782
7906
  //#endregion
7907
+ //#region src/ir/utils.d.ts
7908
+ /**
7909
+ * Simply adds `items` to the schema. Also handles setting the logical operator
7910
+ * and avoids setting it for a single item or tuples.
7911
+ */
7912
+ declare function addItemsToSchema({
7913
+ items,
7914
+ logicalOperator,
7915
+ mutateSchemaOneItem,
7916
+ schema
7917
+ }: {
7918
+ items: Array<IR.SchemaObject>;
7919
+ logicalOperator?: IR.SchemaObject['logicalOperator'];
7920
+ mutateSchemaOneItem?: boolean;
7921
+ schema: IR.SchemaObject;
7922
+ }): IR.SchemaObject;
7923
+ //#endregion
7783
7924
  //#region src/openApi/index.d.ts
7784
7925
  /**
7785
7926
  * @internal
@@ -8066,6 +8207,32 @@ declare class MinHeap {
8066
8207
  private sinkDown;
8067
8208
  }
8068
8209
  //#endregion
8210
+ //#region src/utils/path.d.ts
8211
+ interface PathToNameOptions {
8212
+ /**
8213
+ * When provided, replaces the root semantic segments with this anchor.
8214
+ * Structural suffixes are still derived from path.
8215
+ */
8216
+ anchor?: string;
8217
+ }
8218
+ /**
8219
+ * Derives a composite name from a path.
8220
+ *
8221
+ * Examples:
8222
+ * .../User → 'User'
8223
+ * .../User/properties/address → 'UserAddress'
8224
+ * .../User/properties/properties → 'UserProperties'
8225
+ * .../User/properties/address/properties/city → 'UserAddressCity'
8226
+ * .../Pet/additionalProperties → 'PetValue'
8227
+ * .../Order/properties/items/items/0 → 'OrderItems'
8228
+ * paths//event/get/properties/query → 'EventGetQuery'
8229
+ *
8230
+ * With anchor:
8231
+ * paths//event/get/properties/query, { anchor: 'event.subscribe' }
8232
+ * → 'event.subscribe-Query'
8233
+ */
8234
+ declare function pathToName(path: ReadonlyArray<string | number>, options?: PathToNameOptions): string;
8235
+ //#endregion
8069
8236
  //#region src/utils/ref.d.ts
8070
8237
  /**
8071
8238
  * Returns the reusable component name from `$ref`.
@@ -8116,7 +8283,7 @@ declare function normalizeJsonPointer(pointer: string): string;
8116
8283
  */
8117
8284
  declare function pathToJsonPointer(path: ReadonlyArray<string | number>): string;
8118
8285
  /**
8119
- * Checks if a $ref points to a top-level component (not a deep path reference).
8286
+ * Checks if a $ref or path points to a top-level component (not a deep path reference).
8120
8287
  *
8121
8288
  * Top-level component references:
8122
8289
  * - OpenAPI 3.x: #/components/{type}/{name} (3 segments)
@@ -8125,10 +8292,10 @@ declare function pathToJsonPointer(path: ReadonlyArray<string | number>): string
8125
8292
  * Deep path references (4+ segments for 3.x, 3+ for 2.0) should be inlined
8126
8293
  * because they don't have corresponding registered symbols.
8127
8294
  *
8128
- * @param $ref - The $ref string to check
8295
+ * @param refOrPath - The $ref string or path array to check
8129
8296
  * @returns true if the ref points to a top-level component, false otherwise
8130
8297
  */
8131
- declare function isTopLevelComponentRef($ref: string): boolean;
8298
+ declare function isTopLevelComponent(refOrPath: string | ReadonlyArray<string | number>): boolean;
8132
8299
  declare function resolveRef<T>({
8133
8300
  $ref,
8134
8301
  spec
@@ -8146,5 +8313,5 @@ interface Url {
8146
8313
  }
8147
8314
  declare function parseUrl(value: string): Url;
8148
8315
  //#endregion
8149
- export { type AnyConfig, type AnyPluginName, type BaseConfig, type BaseOutput, type BaseUserConfig, type BaseUserOutput, type Casing, type CodeSampleObject, ConfigError, ConfigValidationError, Context, type DefinePlugin, type Dependency, type EnumExtensions, type FeatureToggle, type Filters, HeyApiError, type Hooks, type IR, type IndexExportOption, type Input, IntentContext, JobError, type LinguistLanguages, type Logs, MinHeap, type NameTransformer, type NamingConfig, type NamingOptions, type NamingRule, type OpenApi, type OpenApiMetaObject, type OpenApiOperationObject, type OpenApiParameterObject, type OpenApiRequestBodyObject, type OpenApiResponseObject, type OpenApiSchemaObject, type OpenApiV2_0_X, type OpenApiV2_0_XTypes, type OpenApiV3_0_X, type OpenApiV3_0_XTypes, type OpenApiV3_1_X, type OpenApiV3_1_XTypes, OperationPath, type OperationPathStrategy, OperationStrategy, type OperationStructureStrategy, type OperationsStrategy, type OutputHeader, type Parser, type Patch, type Plugin, type PluginConfigMap, type PluginContext, PluginInstance, type PluginInstanceTypes, type PluginNames, type PostProcessor, type SchemaWithType, type SourceConfig, type UserInput, type UserParser, type UserPostProcessor, type UserSourceConfig, type UserWatch, type ValueToObject, type Watch, type WatchValues, 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 };
8316
+ export { type AnyConfig, type AnyPluginName, type BaseConfig, type BaseOutput, type BaseUserConfig, type BaseUserOutput, type Casing, type CodeSampleObject, type CommentsOption, ConfigError, ConfigValidationError, Context, type DefinePlugin, type Dependency, type EnumExtensions, type FeatureToggle, type Filters, HeyApiError, type Hooks, type IR, type IndexExportOption, type Input, IntentContext, JobError, type LinguistLanguages, type Logs, MinHeap, type NameTransformer, type NamingConfig, type NamingOptions, type NamingRule, type OpenApi, type OpenApiMetaObject, type OpenApiOperationObject, type OpenApiParameterObject, type OpenApiRequestBodyObject, type OpenApiResponseObject, type OpenApiSchemaObject, type OpenApiV2_0_X, type OpenApiV2_0_XTypes, type OpenApiV3_0_X, type OpenApiV3_0_XTypes, type OpenApiV3_1_X, type OpenApiV3_1_XTypes, OperationPath, type OperationPathStrategy, OperationStrategy, type OperationStructureStrategy, type OperationsStrategy, type OutputHeader, type Parser, type Patch, type Plugin, type PluginConfigMap, type PluginContext, PluginInstance, type PluginInstanceTypes, type PluginNames, type PostProcessor, type SchemaExtractor, type SchemaProcessor, type SchemaProcessorContext, type SchemaProcessorResult, type SchemaWithType, type SourceConfig, type UserCommentsOption, type UserIndexExportOption, type UserInput, type UserParser, type UserPostProcessor, type UserSourceConfig, type UserWatch, type ValueToObject, type Watch, type WatchValues, 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 };
8150
8317
  //# sourceMappingURL=index.d.mts.map