Skip to content

Commit c6aada2

Browse files
committed
chore: changes after review
1 parent eb06535 commit c6aada2

File tree

13 files changed

+47
-159
lines changed

13 files changed

+47
-159
lines changed

packages/core/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
"types": "./lib/config/index.d.ts"
1717
},
1818
"./lib/bundle": {
19-
"import": "./lib/bundle.js",
20-
"require": "./lib/bundle.js",
21-
"types": "./lib/bundle.d.ts"
19+
"import": "./lib/bundle/bundle.js",
20+
"require": "./lib/bundle/bundle.js",
21+
"types": "./lib/bundle/bundle.d.ts"
2222
},
2323
"./lib/bundle-oas": {
24-
"import": "./lib/bundle-oas.js",
25-
"require": "./lib/bundle-oas.js",
26-
"types": "./lib/bundle-oas.d.ts"
24+
"import": "./lib/bundle/bundle-oas.js",
25+
"require": "./lib/bundle/bundle-oas.js",
26+
"types": "./lib/bundle/bundle-oas.d.ts"
2727
}
2828
},
2929
"engines": {

packages/core/src/__tests__/bundle-oas.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import outdent from 'outdent';
22
import * as path from 'node:path';
33
import { fileURLToPath } from 'node:url';
4-
import { bundleOas, loadConfig } from '../bundle-oas.js';
4+
import { bundleOas, loadConfig } from '../bundle/bundle-oas.js';
55
import { parseYamlToDocument, yamlSerializer } from '../../__tests__/utils.js';
66
import { createConfig } from '../config/index.js';
77
import { BaseResolver } from '../resolve.js';

packages/core/src/__tests__/bundle.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import outdent from 'outdent';
22
import * as path from 'node:path';
33
import { fileURLToPath } from 'node:url';
44
import { bundleDocument } from '../bundle/bundle-document.js';
5-
import { bundle, bundleFromString } from '../bundle.js';
5+
import { bundle, bundleFromString } from '../bundle/bundle.js';
66
import { parseYamlToDocument, yamlSerializer } from '../../__tests__/utils.js';
77
import { createConfig, loadConfig } from '../config/index.js';
88
import { BaseResolver } from '../resolve.js';
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// Specialized OAS only bundle export for vite bundle
2-
import { BaseResolver } from './resolve.js';
3-
import { detectSpec } from './detect-spec.js';
4-
import { bundleDocument } from './bundle/bundle-document.js';
5-
import { Oas2Types } from './types/oas2.js';
6-
import { Oas3Types } from './types/oas3.js';
7-
import { Oas3_1Types } from './types/oas3_1.js';
8-
import { Oas3_2Types } from './types/oas3_2.js';
9-
import { Config } from './config/config.js';
2+
import { BaseResolver } from '../resolve.js';
3+
import { detectSpec } from '../detect-spec.js';
4+
import { bundleDocument } from './bundle-document.js';
5+
import { Oas2Types } from '../types/oas2.js';
6+
import { Oas3Types } from '../types/oas3.js';
7+
import { Oas3_1Types } from '../types/oas3_1.js';
8+
import { Oas3_2Types } from '../types/oas3_2.js';
9+
import { Config } from '../config/config.js';
1010

11-
import type { NodeType } from './types/index.js';
12-
import type { Document } from './resolve.js';
13-
import type { CollectFn } from './types.js';
11+
import type { NodeType } from '../types/index.js';
12+
import type { Document } from '../resolve.js';
13+
import type { CollectFn } from '../utils/types.js';
1414

1515
export type CoreBundleOptions = {
1616
externalRefResolver?: BaseResolver;
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import { BaseResolver, makeDocumentFromString } from './resolve.js';
2-
import { walkDocument } from './walk.js';
3-
import { detectSpec } from './detect-spec.js';
4-
import { getTypes } from './oas-types.js';
5-
import { NormalizedConfigTypes } from './types/redocly-yaml.js';
6-
import { type Config } from './config/config.js';
7-
import { configBundlerVisitor, pluginsCollectorVisitor } from './config/visitors.js';
8-
import { CONFIG_BUNDLER_VISITOR_ID, PLUGINS_COLLECTOR_VISITOR_ID } from './config/constants.js';
9-
import { bundleDocument } from './bundle/bundle-document.js';
10-
11-
import type { ConfigBundlerVisitorData, PluginsCollectorVisitorData } from './config/visitors.js';
12-
import type { Plugin, ResolvedConfig } from './config/types.js';
13-
import type { NormalizedNodeType } from './types/index.js';
14-
import type { WalkContext, NormalizedProblem } from './walk.js';
15-
import type { Document, ResolvedRefMap } from './resolve.js';
16-
import type { CollectFn } from './types.js';
1+
import { BaseResolver, makeDocumentFromString } from '../resolve.js';
2+
import { walkDocument } from '../walk.js';
3+
import { detectSpec } from '../detect-spec.js';
4+
import { getTypes } from '../oas-types.js';
5+
import { NormalizedConfigTypes } from '../types/redocly-yaml.js';
6+
import { type Config } from '../config/config.js';
7+
import { configBundlerVisitor, pluginsCollectorVisitor } from '../config/visitors.js';
8+
import { CONFIG_BUNDLER_VISITOR_ID, PLUGINS_COLLECTOR_VISITOR_ID } from '../config/constants.js';
9+
import { bundleDocument } from './bundle-document.js';
10+
11+
import type { ConfigBundlerVisitorData, PluginsCollectorVisitorData } from '../config/visitors.js';
12+
import type { Plugin, ResolvedConfig } from '../config/types.js';
13+
import type { NormalizedNodeType } from '../types/index.js';
14+
import type { WalkContext, NormalizedProblem } from '../walk.js';
15+
import type { Document, ResolvedRefMap } from '../resolve.js';
16+
import type { CollectFn } from '../utils/types.js';
1717

1818
export type CoreBundleOptions = {
1919
externalRefResolver?: BaseResolver;

packages/core/src/config/config-resolvers.ts

Lines changed: 2 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,33 @@ import * as fs from 'node:fs';
44
import module from 'node:module';
55
import { isAbsoluteUrl } from '../ref-utils.js';
66
import { isNotString } from '../utils/is-not-string.js';
7-
import { keysOf } from '../utils/keys-of.js';
87
import { isString } from '../utils/is-string.js';
98
import { isPlainObject } from '../utils/is-plain-object.js';
109
import { isDefined } from '../utils/is-defined.js';
1110
import { resolveDocument, BaseResolver, Source } from '../resolve.js';
1211
import { defaultPlugin } from './builtIn.js';
1312
import {
1413
deepCloneMapWithJSON,
15-
getResolveConfig,
1614
isCommonJsPlugin,
1715
isDeprecatedPluginFormat,
1816
mergeExtends,
1917
parsePresetName,
2018
prefixRules,
2119
} from './utils.js';
20+
import { getResolveConfig } from './get-resolve-config.js';
2221
import { isBrowser } from '../env.js';
2322
import { colorize, logger } from '../logger.js';
24-
import { asserts, buildAssertCustomFunction } from '../rules/common/assertions/asserts.js';
2523
import { NormalizedConfigTypes } from '../types/redocly-yaml.js';
26-
import { bundleConfig, collectConfigPlugins } from '../bundle.js';
24+
import { bundleConfig, collectConfigPlugins } from '../bundle/bundle.js';
2725
import { CONFIG_FILE_NAME, DEFAULT_CONFIG, DEFAULT_PROJECT_PLUGIN_PATHS } from './constants.js';
2826

2927
import type {
3028
Plugin,
3129
RawUniversalConfig,
3230
ResolvedConfig,
3331
RawGovernanceConfig,
34-
RuleConfig,
3532
ImportedPlugin,
3633
} from './types.js';
37-
import type {
38-
Assertion,
39-
AssertionDefinition,
40-
RawAssertion,
41-
} from '../rules/common/assertions/index.js';
42-
import type { Asserts, AssertionFn } from '../rules/common/assertions/asserts.js';
4334
import type { Document, ResolvedRefMap } from '../resolve.js';
4435

4536
// Cache instantiated plugins during a single execution
@@ -476,70 +467,3 @@ export function resolvePreset(presetName: string, plugins: Plugin[]): RawGoverna
476467
}
477468
return preset;
478469
}
479-
480-
export function groupAssertionRules(
481-
config: RawGovernanceConfig,
482-
plugins: Plugin[]
483-
): Record<string, RuleConfig> {
484-
if (!config.rules) {
485-
return {};
486-
}
487-
488-
// Create a new record to avoid mutating original
489-
const transformedRules: Record<string, RuleConfig> = {};
490-
491-
// Collect assertion rules
492-
const assertions: Assertion[] = [];
493-
for (const [ruleKey, rule] of Object.entries(config.rules)) {
494-
if (ruleKey.startsWith('rule/') && typeof rule === 'object' && rule !== null) {
495-
const assertion = rule as RawAssertion;
496-
497-
if (plugins) {
498-
registerCustomAssertions(plugins, assertion);
499-
500-
// We may have custom assertion inside where block
501-
for (const context of assertion.where || []) {
502-
registerCustomAssertions(plugins, context);
503-
}
504-
}
505-
assertions.push({
506-
...assertion,
507-
assertionId: ruleKey,
508-
});
509-
} else {
510-
// If it's not an assertion, keep it as is
511-
transformedRules[ruleKey] = rule;
512-
}
513-
}
514-
if (assertions.length > 0) {
515-
transformedRules.assertions = assertions;
516-
}
517-
518-
return transformedRules;
519-
}
520-
521-
function registerCustomAssertions(plugins: Plugin[], assertion: AssertionDefinition) {
522-
for (const field of keysOf(assertion.assertions)) {
523-
const [pluginId, fn] = field.split('/');
524-
525-
if (!pluginId || !fn) continue;
526-
527-
const plugin = plugins.find((plugin) => plugin.id === pluginId);
528-
529-
if (!plugin) {
530-
throw Error(colorize.red(`Plugin ${colorize.blue(pluginId)} isn't found.`));
531-
}
532-
533-
if (!plugin.assertions || !plugin.assertions[fn]) {
534-
throw Error(
535-
`Plugin ${colorize.red(
536-
pluginId
537-
)} doesn't export assertions function with name ${colorize.red(fn)}.`
538-
);
539-
}
540-
541-
(asserts as Asserts & { [name: string]: AssertionFn })[field] = buildAssertCustomFunction(
542-
plugin.assertions[fn]
543-
);
544-
}
545-
}

packages/core/src/config/utils.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
import { assignOnlyExistingConfig, assignConfig } from '../utils/assign-config.js';
22
import { isPlainObject } from '../utils/is-plain-object.js';
33

4-
import type {
5-
ImportedPlugin,
6-
RawResolveConfig,
7-
ResolveConfig,
8-
ResolvedGovernanceConfig,
9-
Plugin,
10-
PluginCreator,
11-
} from './types.js';
4+
import type { ImportedPlugin, ResolvedGovernanceConfig, Plugin, PluginCreator } from './types.js';
125
import type {
136
Oas3RuleSet,
147
Oas2RuleSet,
@@ -144,15 +137,6 @@ export function mergeExtends(rulesConfList: ResolvedGovernanceConfig[]) {
144137
return result;
145138
}
146139

147-
export function getResolveConfig(resolve?: RawResolveConfig): ResolveConfig {
148-
return {
149-
http: {
150-
headers: resolve?.http?.headers ?? [],
151-
customFetch: undefined,
152-
},
153-
};
154-
}
155-
156140
export class ConfigValidationError extends Error {}
157141

158142
export function deepCloneMapWithJSON<K, V>(originalMap: Map<K, V>): Map<K, V> {

packages/core/src/decorators/oas2/__tests__/remove-unused-components.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as path from 'node:path';
22
import { outdent } from 'outdent';
33
import { parseYamlToDocument } from '../../../../__tests__/utils.js';
44
import { bundleDocument } from '../../../bundle/bundle-document.js';
5-
import { bundle } from '../../../bundle.js';
5+
import { bundle } from '../../../bundle/bundle.js';
66
import { BaseResolver } from '../../../resolve.js';
77
import { createConfig } from '../../../config/index.js';
88
import { Oas2Types } from '../../../index.js';

packages/core/src/decorators/oas3/__tests__/remove-unused-components.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as path from 'node:path';
22
import { outdent } from 'outdent';
33
import { parseYamlToDocument } from '../../../../__tests__/utils.js';
44
import { bundleDocument } from '../../../bundle/bundle-document.js';
5-
import { bundle } from '../../../bundle.js';
5+
import { bundle } from '../../../bundle/bundle.js';
66
import { BaseResolver } from '../../../resolve.js';
77
import { createConfig } from '../../../config/index.js';
88
import { Oas3Types } from '../../../index.js';

packages/core/src/index.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,8 @@ export {
5757
type Location,
5858
} from './ref-utils.js';
5959
export { detectSpec } from './detect-spec.js';
60-
export {
61-
getMajorSpecVersion,
62-
getTypes,
63-
type SpecVersion,
64-
type SpecMajorVersion,
65-
} from './oas-types.js';
60+
export { getTypes, type SpecVersion, type SpecMajorVersion } from './oas-types.js';
61+
export { getMajorSpecVersion } from './detect-spec.js';
6662
export {
6763
normalizeVisitors,
6864
type Oas3Visitor,
@@ -103,15 +99,15 @@ export {
10399
export { getAstNodeByPointer, getLineColLocation, getCodeframe } from './format/codeframes.js';
104100
export { formatProblems, getTotals, type OutputFormat, type Totals } from './format/format.js';
105101
export { lint, lint as validate, lintDocument, lintFromString, lintConfig } from './lint.js';
106-
export { bundle, bundleFromString, type BundleResult } from './bundle.js';
102+
export { bundle, bundleFromString, type BundleResult } from './bundle/bundle.js';
107103
export { bundleDocument } from './bundle/bundle-document.js';
108104
export { mapTypeToComponent } from './bundle/bundle-visitor.js';
109105
export { type Assertions, type Assertion } from './rules/common/assertions/index.js';
110106
export { logger, type LoggerInterface } from './logger.js';
111107
export { HandledError } from './utils/error.js';
112108
export { isBrowser } from './env.js';
113109

114-
export type { CollectFn, Exact } from './types.js';
110+
export type { CollectFn, Exact } from './utils/types.js';
115111
export type {
116112
Oas3Definition,
117113
Oas3_1Definition,

0 commit comments

Comments
 (0)