@hey-api/shared 0.2.2 → 0.2.4

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
@@ -1,5 +1,4 @@
1
1
  import { PathLike } from "node:fs";
2
- import ts from "typescript";
3
2
  import * as semver from "semver";
4
3
  import { RangeOptions, SemVer } from "semver";
5
4
  import { getResolvedInput } from "@hey-api/json-schema-ref-parser";
@@ -7,6 +6,10 @@ import { IProject, Logger, NameConflictResolver, Node, Project, Ref, RenderConte
7
6
  import { AnyString, MaybeArray, MaybeFunc, MaybePromise } from "@hey-api/types";
8
7
 
9
8
  //#region src/cli.d.ts
9
+ /**
10
+ * Checks the current environment based on the HEYAPI_CODEGEN_ENV environment variable.
11
+ */
12
+ declare function isEnvironment(value: 'development'): boolean;
10
13
  declare function printCliIntro(initialDir: string, showLogo?: boolean): void;
11
14
  //#endregion
12
15
  //#region src/config/engine.d.ts
@@ -2938,7 +2941,7 @@ interface IRSchemaObject extends Pick<JsonSchemaDraft2020_12, '$ref' | 'const' |
2938
2941
  type?: 'array' | 'boolean' | 'enum' | 'integer' | 'never' | 'null' | 'number' | 'object' | 'string' | 'tuple' | 'undefined' | 'unknown' | 'void';
2939
2942
  }
2940
2943
  type IRSecurityObject = SecuritySchemeObject$2;
2941
- type IRServerObject = ServerObject$1;
2944
+ interface IRServerObject extends ServerObject$1 {}
2942
2945
  type IRWebhookObject = IRPathItemObject;
2943
2946
  interface IRModel {
2944
2947
  components?: IRComponentsObject;
@@ -2993,10 +2996,10 @@ interface SchemaProcessorContext {
2993
2996
  schema: IR.SchemaObject;
2994
2997
  tags?: ReadonlyArray<string>;
2995
2998
  }
2996
- interface SchemaProcessorResult<Context$1 extends SchemaProcessorContext = SchemaProcessorContext> {
2997
- process: (ctx: Context$1) => void;
2999
+ interface SchemaProcessorResult<Context extends SchemaProcessorContext = SchemaProcessorContext> {
3000
+ process: (ctx: Context) => void;
2998
3001
  }
2999
- type SchemaExtractor<Context$1 extends SchemaProcessorContext = SchemaProcessorContext> = (ctx: Context$1) => IR.SchemaObject;
3002
+ type SchemaExtractor<Context extends SchemaProcessorContext = SchemaProcessorContext> = (ctx: Context) => IR.SchemaObject;
3000
3003
  declare function createSchemaProcessor(): SchemaProcessor;
3001
3004
  //#endregion
3002
3005
  //#region src/openApi/shared/utils/graph.d.ts
@@ -3074,17 +3077,11 @@ type Graph = {
3074
3077
  * @property tags - The set of tags for this node, if any. Optional.
3075
3078
  */
3076
3079
  type NodeInfo = {
3077
- /** Whether the node is deprecated. Optional. */
3078
- deprecated?: boolean;
3079
- /** The property name or array index in the parent, or null for root. */
3080
- key: string | number | null;
3081
- /** The actual object at this pointer in the spec. */
3082
- node: unknown;
3083
- /** The JSON Pointer of the parent node, or null for root. */
3084
- parentPointer: string | null;
3085
- /** The set of access scopes for this node, if any. Optional. */
3086
- scopes?: Set<Scope>;
3087
- /** The set of tags for this node, if any. Optional. */
3080
+ /** Whether the node is deprecated. Optional. */deprecated?: boolean; /** The property name or array index in the parent, or null for root. */
3081
+ key: string | number | null; /** The actual object at this pointer in the spec. */
3082
+ node: unknown; /** The JSON Pointer of the parent node, or null for root. */
3083
+ parentPointer: string | null; /** The set of access scopes for this node, if any. Optional. */
3084
+ scopes?: Set<Scope>; /** The set of tags for this node, if any. Optional. */
3088
3085
  tags?: Set<string>;
3089
3086
  };
3090
3087
  //#endregion
@@ -3258,18 +3255,15 @@ type WalkEvents = BaseEvent & ({
3258
3255
  path: string;
3259
3256
  type: Extract<IrTopLevelKind, 'operation'>;
3260
3257
  } | {
3261
- /** Name of the parameter (e.g., "id" for a parameter defined as "#/components/parameters/id"). */
3262
- name: string;
3258
+ /** Name of the parameter (e.g., "id" for a parameter defined as "#/components/parameters/id"). */name: string;
3263
3259
  parameter: IR.ParameterObject;
3264
3260
  type: Extract<IrTopLevelKind, 'parameter'>;
3265
3261
  } | {
3266
- /** Name of the request body (e.g., "CreateUserRequest" for a request body defined as "#/components/requestBodies/CreateUserRequest"). */
3267
- name: string;
3262
+ /** Name of the request body (e.g., "CreateUserRequest" for a request body defined as "#/components/requestBodies/CreateUserRequest"). */name: string;
3268
3263
  requestBody: IR.RequestBodyObject;
3269
3264
  type: Extract<IrTopLevelKind, 'requestBody'>;
3270
3265
  } | {
3271
- /** Name of the schema (e.g., "User" for a schema defined as "#/components/schemas/User"). */
3272
- name: string;
3266
+ /** Name of the schema (e.g., "User" for a schema defined as "#/components/schemas/User"). */name: string;
3273
3267
  schema: IR.SchemaObject;
3274
3268
  type: Extract<IrTopLevelKind, 'schema'>;
3275
3269
  } | {
@@ -3382,7 +3376,7 @@ declare class PluginInstance<T extends Plugin.Types = Plugin.Types> {
3382
3376
  querySymbol(filter: SymbolMeta): Symbol<ResolvedNode> | undefined;
3383
3377
  referenceSymbol(meta: SymbolMeta): Symbol<ResolvedNode>;
3384
3378
  /**
3385
- * @deprecated use `plugin.symbol()` instead
3379
+ * Alias for `symbol()` method with single argument.
3386
3380
  */
3387
3381
  registerSymbol(symbol: SymbolIn): Symbol<ResolvedNode>;
3388
3382
  /**
@@ -3402,6 +3396,43 @@ declare class PluginInstance<T extends Plugin.Types = Plugin.Types> {
3402
3396
  private isOperationKind;
3403
3397
  }
3404
3398
  //#endregion
3399
+ //#region src/utils/naming/types.d.ts
3400
+ /**
3401
+ * Available casing strategies.
3402
+ */
3403
+ type Casing = 'camelCase' | 'PascalCase' | 'preserve' | 'snake_case' | 'SCREAMING_SNAKE_CASE';
3404
+ /**
3405
+ * Name transformer: template string or function.
3406
+ *
3407
+ * Template supports `{{name}}` variable.
3408
+ */
3409
+ type NameTransformer = MaybeFunc<(name: string) => string>;
3410
+ /**
3411
+ * Full naming configuration.
3412
+ */
3413
+ interface NamingConfig {
3414
+ /**
3415
+ * Casing strategy applied after transformation.
3416
+ *
3417
+ * @deprecated Use `casing` instead.
3418
+ */
3419
+ case?: Casing;
3420
+ /**
3421
+ * Casing strategy applied after transformation.
3422
+ */
3423
+ casing?: Casing;
3424
+ /**
3425
+ * Name template or transformer function.
3426
+ *
3427
+ * Applied before `casing` transformation.
3428
+ */
3429
+ name?: NameTransformer;
3430
+ }
3431
+ /**
3432
+ * Name customization: shorthand or full configuration.
3433
+ */
3434
+ type NamingRule = NameTransformer | NamingConfig;
3435
+ //#endregion
3405
3436
  //#region src/parser/hooks.d.ts
3406
3437
  type Hooks = {
3407
3438
  /**
@@ -3417,9 +3448,7 @@ type Hooks = {
3417
3448
  * @returns void
3418
3449
  */
3419
3450
  'node:set:after'?: (args: {
3420
- /** The node added or updated. */
3421
- node: Node | null;
3422
- /** Plugin that added or updated the node. */
3451
+ /** The node added or updated. */node: Node | null; /** Plugin that added or updated the node. */
3423
3452
  plugin: PluginInstance;
3424
3453
  }) => void;
3425
3454
  /**
@@ -3431,9 +3460,7 @@ type Hooks = {
3431
3460
  * @returns void
3432
3461
  */
3433
3462
  'node:set:before'?: (args: {
3434
- /** The node to be added or updated. */
3435
- node: Node | null;
3436
- /** Plugin adding or updating the node. */
3463
+ /** The node to be added or updated. */node: Node | null; /** Plugin adding or updating the node. */
3437
3464
  plugin: PluginInstance;
3438
3465
  }) => void;
3439
3466
  /**
@@ -3443,8 +3470,7 @@ type Hooks = {
3443
3470
  * @returns void
3444
3471
  */
3445
3472
  'plugin:handler:after'?: (args: {
3446
- /** Plugin that just executed. */
3447
- plugin: PluginInstance;
3473
+ /** Plugin that just executed. */plugin: PluginInstance;
3448
3474
  }) => void;
3449
3475
  /**
3450
3476
  * Triggered before executing a plugin handler.
@@ -3453,8 +3479,7 @@ type Hooks = {
3453
3479
  * @returns void
3454
3480
  */
3455
3481
  'plugin:handler:before'?: (args: {
3456
- /** Plugin about to execute. */
3457
- plugin: PluginInstance;
3482
+ /** Plugin about to execute. */plugin: PluginInstance;
3458
3483
  }) => void;
3459
3484
  /**
3460
3485
  * Triggered after registering a symbol.
@@ -3465,9 +3490,7 @@ type Hooks = {
3465
3490
  * @returns void
3466
3491
  */
3467
3492
  'symbol:register:after'?: (args: {
3468
- /** Plugin that registered the symbol. */
3469
- plugin: PluginInstance;
3470
- /** The registered symbol. */
3493
+ /** Plugin that registered the symbol. */plugin: PluginInstance; /** The registered symbol. */
3471
3494
  symbol: Symbol;
3472
3495
  }) => void;
3473
3496
  /**
@@ -3479,9 +3502,7 @@ type Hooks = {
3479
3502
  * @returns void
3480
3503
  */
3481
3504
  'symbol:register:before'?: (args: {
3482
- /** Plugin registering the symbol. */
3483
- plugin: PluginInstance;
3484
- /** Symbol to register. */
3505
+ /** Plugin registering the symbol. */plugin: PluginInstance; /** Symbol to register. */
3485
3506
  symbol: SymbolIn;
3486
3507
  }) => void;
3487
3508
  };
@@ -3609,8 +3630,28 @@ type Hooks = {
3609
3630
  * @returns The file path to output the symbol to, or undefined to fallback to default behavior.
3610
3631
  */
3611
3632
  getFilePath?: (symbol: Symbol) => string | undefined;
3633
+ /**
3634
+ * Optional output strategy to override default plugin behavior.
3635
+ *
3636
+ * Use this to customize symbol names.
3637
+ *
3638
+ * @returns The name to register the symbol with, or undefined to fallback to default behavior.
3639
+ */
3640
+ getName?: (ctx: GetNameContext) => MaybeFunc<(ctx: GetNameContext) => string | undefined>;
3612
3641
  };
3613
3642
  };
3643
+ interface GetNameContext {
3644
+ /** Arbitrary metadata about the symbol. */
3645
+ meta: SymbolMeta;
3646
+ /** The proposed name for the symbol. */
3647
+ name: string;
3648
+ /** The naming configuration for the symbol. */
3649
+ naming?: NamingConfig;
3650
+ /** The operation object associated with the symbol. */
3651
+ operation?: IROperationObject;
3652
+ /** The schema object associated with the symbol. */
3653
+ schema?: IRSchemaObject;
3654
+ }
3614
3655
  //#endregion
3615
3656
  //#region src/plugins/types.d.ts
3616
3657
  interface PluginConfigMap {}
@@ -3705,51 +3746,15 @@ type DefinePlugin<Config extends PluginBaseConfig = PluginBaseConfig, ResolvedCo
3705
3746
  Config: Plugin.Config<Plugin.Types<Config, ResolvedConfig, Api>>;
3706
3747
  Handler: (args: {
3707
3748
  plugin: PluginInstance<Plugin.Types<Config, ResolvedConfig, Api>>;
3708
- }) => void;
3709
- /** The plugin instance. */
3749
+ }) => void; /** The plugin instance. */
3710
3750
  Instance: PluginInstance<Plugin.Types<Config, ResolvedConfig, Api>>;
3711
3751
  Types: Plugin.Types<Config, ResolvedConfig, Api>;
3712
3752
  };
3713
3753
  //#endregion
3714
- //#region src/utils/naming/types.d.ts
3715
- /**
3716
- * Available casing strategies.
3717
- */
3718
- type Casing = 'camelCase' | 'PascalCase' | 'preserve' | 'snake_case' | 'SCREAMING_SNAKE_CASE';
3719
- /**
3720
- * Name transformer: template string or function.
3721
- *
3722
- * Template supports `{{name}}` variable.
3723
- */
3724
- type NameTransformer = MaybeFunc<(name: string) => string>;
3725
- /**
3726
- * Full naming configuration.
3727
- */
3728
- interface NamingConfig {
3729
- /**
3730
- * Casing strategy applied after transformation.
3731
- *
3732
- * @deprecated Use `casing` instead.
3733
- */
3734
- case?: Casing;
3735
- /**
3736
- * Casing strategy applied after transformation.
3737
- */
3738
- casing?: Casing;
3739
- /**
3740
- * Name template or transformer function.
3741
- *
3742
- * Applied before `casing` transformation.
3743
- */
3744
- name?: NameTransformer;
3745
- }
3746
- /**
3747
- * Name customization: shorthand or full configuration.
3748
- */
3749
- type NamingRule = NameTransformer | NamingConfig;
3750
- //#endregion
3751
3754
  //#region src/config/output/types.d.ts
3752
- type OutputHeader = MaybeFunc<(ctx: Omit<RenderContext, 'file'> & Pick<Partial<RenderContext>, 'file'>) => MaybeArray<string> | null | undefined>;
3755
+ type OutputHeader = MaybeFunc<(ctx: Pick<RenderContext, 'meta' | 'project'> & Pick<Partial<RenderContext>, 'file'> & {
3756
+ /** The default header value. */defaultValue: ReadonlyArray<string>;
3757
+ }) => MaybeArray<string> | null | undefined>;
3753
3758
  //#endregion
3754
3759
  //#region src/config/parser/filters.d.ts
3755
3760
  type Filters = {
@@ -8052,8 +8057,7 @@ interface SchemaVisitor<TResult, TPlugin = unknown> {
8052
8057
  * Apply modifiers to a result.
8053
8058
  */
8054
8059
  applyModifiers(result: TResult, ctx: SchemaVisitorContext<TPlugin>, context?: {
8055
- /** Is this property optional? */
8056
- optional?: boolean;
8060
+ /** Is this property optional? */optional?: boolean;
8057
8061
  }): unknown;
8058
8062
  array(schema: SchemaWithType<'array'>, ctx: SchemaVisitorContext<TPlugin>, walk: Walker<TResult, TPlugin>): TResult;
8059
8063
  boolean(schema: SchemaWithType<'boolean'>, ctx: SchemaVisitorContext<TPlugin>): TResult;
@@ -8312,6 +8316,24 @@ declare const mappers: {
8312
8316
  };
8313
8317
  };
8314
8318
  //#endregion
8319
+ //#region src/plugins/symbol.d.ts
8320
+ /**
8321
+ * Helper function to build the input for symbol registration, applying naming hooks if provided.
8322
+ */
8323
+ declare function buildSymbolIn({
8324
+ plugin,
8325
+ ...ctx
8326
+ }: GetNameContext & {
8327
+ plugin: {
8328
+ config: Pick<PluginInstance['config'], '~hooks'>;
8329
+ context: {
8330
+ config: {
8331
+ parser: Pick<PluginInstance['context']['config']['parser'], 'hooks'>;
8332
+ };
8333
+ };
8334
+ };
8335
+ }): SymbolIn;
8336
+ //#endregion
8315
8337
  //#region src/tsConfig.d.ts
8316
8338
  declare function findPackageJson(initialDir: string): unknown | undefined;
8317
8339
  type PackageJson = {
@@ -8323,7 +8345,6 @@ type PackageJson = {
8323
8345
  };
8324
8346
  declare function loadPackageJson(initialDir: string): PackageJson | undefined;
8325
8347
  declare function findTsConfigPath(baseDir: string, tsConfigPath?: AnyString | null): string | null;
8326
- declare function loadTsConfig(configPath: string | null): ts.ParsedCommandLine | null;
8327
8348
  //#endregion
8328
8349
  //#region src/utils/escape.d.ts
8329
8350
  declare function escapeComment(value: string): string;
@@ -8386,7 +8407,11 @@ declare const utils: {
8386
8407
  /**
8387
8408
  * Converts an {@link OutputHeader} value to a string prefix for file content.
8388
8409
  */
8389
- declare function outputHeaderToPrefix(header: OutputHeader, project: IProject): string;
8410
+ declare function outputHeaderToPrefix(ctx: {
8411
+ defaultValue: ReadonlyArray<string>;
8412
+ header: OutputHeader;
8413
+ project: IProject;
8414
+ }): string;
8390
8415
  //#endregion
8391
8416
  //#region src/utils/input/index.d.ts
8392
8417
  declare function inputToApiRegistry(input: Input & {
@@ -8514,5 +8539,5 @@ interface Url {
8514
8539
  }
8515
8540
  declare function parseUrl(value: string): Url;
8516
8541
  //#endregion
8517
- 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 SchemaVisitor, type SchemaVisitorContext, type SchemaWithType, type SourceConfig, type UserCommentsOption, type UserIndexExportOption, type UserInput, type UserParser, type UserPostProcessor, type UserSourceConfig, type UserWatch, type ValueToObject, type Walker, type Watch, type WatchValues, 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, 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 };
8542
+ 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, type GetNameContext, HeyApiError, type Hooks, type IR, type IRModel, type IROperationObject, type IRParameterObject, type IRParametersObject, type IRSchemaObject, type IRServerObject, 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 SchemaVisitor, type SchemaVisitorContext, type SchemaWithType, type SourceConfig, type UserCommentsOption, type UserIndexExportOption, type UserInput, type UserParser, type UserPostProcessor, type UserSourceConfig, type UserWatch, type ValueToObject, type Walker, type Watch, type WatchValues, 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, 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 };
8518
8543
  //# sourceMappingURL=index.d.mts.map