@swagger-api/apidom-core 0.97.0 → 0.99.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/es/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { dispatchPlugins as dispatchRefractorPlugins } from "./refractor/plugins/utils/index.mjs";
1
+ export { dispatchPluginsSync as dispatchRefractorPlugins } from "./refractor/plugins/dispatcher/index.mjs";
2
2
  export { default as refractorPluginElementIdentity } from "./refractor/plugins/element-identity.mjs";
3
3
  export { default as refractorPluginSemanticElementIdentity } from "./refractor/plugins/semantic-element-identity.mjs";
4
4
  export { default as MediaTypes } from "./media-types.mjs";
@@ -1,4 +1,4 @@
1
- import { dispatchPlugins } from "./plugins/utils/index.mjs";
1
+ import { dispatchPluginsSync } from "./plugins/dispatcher/index.mjs";
2
2
  import { getNodeType } from "../traversal/visitor.mjs";
3
3
  import { cloneDeep } from "../clone/index.mjs";
4
4
  import { isElement } from "../predicates/index.mjs";
@@ -26,7 +26,7 @@ const refract = (value, {
26
26
  * Run plugins only when necessary.
27
27
  * Running plugins visitors means extra single traversal === performance hit.
28
28
  */
29
- return dispatchPlugins(element, plugins, {
29
+ return dispatchPluginsSync(element, plugins, {
30
30
  toolboxCreator: createToolbox,
31
31
  visitorOptions: {
32
32
  nodeTypeGetter: getNodeType
@@ -0,0 +1,48 @@
1
+ import { mergeDeepRight, propOr } from 'ramda';
2
+ import { invokeArgs } from 'ramda-adjunct';
3
+ import createToolbox from "../../toolbox.mjs";
4
+ import { getNodeType, mergeAllVisitors, visit } from "../../../traversal/visitor.mjs";
5
+ const defaultDispatchPluginsOptions = {
6
+ toolboxCreator: createToolbox,
7
+ visitorOptions: {
8
+ nodeTypeGetter: getNodeType,
9
+ exposeEdits: true
10
+ }
11
+ };
12
+ export const dispatchPluginsSync = (element, plugins, options = {}) => {
13
+ if (plugins.length === 0) return element;
14
+ const mergedOptions = mergeDeepRight(defaultDispatchPluginsOptions, options);
15
+ const {
16
+ toolboxCreator,
17
+ visitorOptions
18
+ } = mergedOptions;
19
+ const toolbox = toolboxCreator();
20
+ const pluginsSpecs = plugins.map(plugin => plugin(toolbox));
21
+ const mergedPluginsVisitor = mergeAllVisitors(pluginsSpecs.map(propOr({}, 'visitor')), {
22
+ ...visitorOptions
23
+ });
24
+ pluginsSpecs.forEach(invokeArgs(['pre'], []));
25
+ const newElement = visit(element, mergedPluginsVisitor, visitorOptions);
26
+ pluginsSpecs.forEach(invokeArgs(['post'], []));
27
+ return newElement;
28
+ };
29
+ export const dispatchPluginsAsync = async (element, plugins, options = {}) => {
30
+ if (plugins.length === 0) return element;
31
+ const mergedOptions = mergeDeepRight(defaultDispatchPluginsOptions, options);
32
+ const {
33
+ toolboxCreator,
34
+ visitorOptions
35
+ } = mergedOptions;
36
+ const toolbox = toolboxCreator();
37
+ const pluginsSpecs = plugins.map(plugin => plugin(toolbox));
38
+ const mergeAllVisitorsAsync = mergeAllVisitors[Symbol.for('nodejs.util.promisify.custom')];
39
+ const visitAsync = visit[Symbol.for('nodejs.util.promisify.custom')];
40
+ const mergedPluginsVisitor = mergeAllVisitorsAsync(pluginsSpecs.map(propOr({}, 'visitor')), {
41
+ ...visitorOptions
42
+ });
43
+ await Promise.allSettled(pluginsSpecs.map(invokeArgs(['pre'], [])));
44
+ const newElement = await visitAsync(element, mergedPluginsVisitor, visitorOptions);
45
+ await Promise.allSettled(pluginsSpecs.map(invokeArgs(['post'], [])));
46
+ return newElement;
47
+ };
48
+ dispatchPluginsSync[Symbol.for('nodejs.util.promisify.custom')] = dispatchPluginsAsync;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swagger-api/apidom-core",
3
- "version": "0.97.0",
3
+ "version": "0.99.0",
4
4
  "description": "Tools for manipulating ApiDOM structures.",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -42,8 +42,8 @@
42
42
  "license": "Apache-2.0",
43
43
  "dependencies": {
44
44
  "@babel/runtime-corejs3": "^7.20.7",
45
- "@swagger-api/apidom-ast": "^0.97.0",
46
- "@swagger-api/apidom-error": "^0.97.0",
45
+ "@swagger-api/apidom-ast": "^0.99.0",
46
+ "@swagger-api/apidom-error": "^0.99.0",
47
47
  "@types/ramda": "~0.29.6",
48
48
  "minim": "~0.23.8",
49
49
  "ramda": "~0.29.1",
@@ -62,5 +62,5 @@
62
62
  "README.md",
63
63
  "CHANGELOG.md"
64
64
  ],
65
- "gitHead": "b616e76738c48401d651a272daef174f6c1a6510"
65
+ "gitHead": "e3c5ac3e738d561a0eb6d9d0f729e0d6bf20b00f"
66
66
  }
package/types/dist.d.ts CHANGED
@@ -1,26 +1,17 @@
1
1
  /// <reference path="./minim.d.ts" />
2
2
  import * as minim from 'minim';
3
- import { Element, StringElement, Meta, Attributes, ArrayElement, ArraySlice, NumberElement, NullElement, BooleanElement, ObjectElement, MemberElement, LinkElement, RefElement, Namespace as Namespace$1, NamespacePlugin, KeyValuePair, ObjectSlice } from 'minim';
3
+ import { Namespace as Namespace$1, NamespacePlugin, StringElement, Meta, Attributes, ArrayElement, Element, ArraySlice, NumberElement, NullElement, BooleanElement, ObjectElement, MemberElement, LinkElement, RefElement, KeyValuePair, ObjectSlice } from 'minim';
4
4
  export { ArrayElement, ArraySlice, Attributes, BooleanElement, Element, KeyValuePair, LinkElement, MemberElement, Meta, NamespacePluginOptions, NullElement, NumberElement, ObjectElement, ObjectSlice, RefElement, StringElement, refract } from 'minim';
5
5
  import { ApiDOMStructuredError, ApiDOMErrorOptions } from '@swagger-api/apidom-error';
6
6
  import stampit from 'stampit';
7
7
  import ShortUniqueId from 'short-unique-id';
8
8
  export { BREAK, mergeAllVisitors } from '@swagger-api/apidom-ast';
9
9
 
10
- declare const dispatchPlugins: <T extends Element>(element: T, plugins: ((toolbox: any) => object)[], options?: {}) => T;
11
-
12
- /**
13
- * Plugin for decorating every element in ApiDOM tree with UUID.
14
- */
15
- declare const plugin$1: ({ length }?: {
16
- length?: number | undefined;
17
- }) => () => {
18
- pre(): void;
19
- visitor: {
20
- enter<T extends Element>(element: T): void;
21
- };
22
- post(): void;
23
- };
10
+ declare class Namespace extends Namespace$1 {
11
+ constructor();
12
+ }
13
+ declare const namespace: Namespace;
14
+ declare const createNamespace: (namespacePlugin?: NamespacePlugin) => Namespace;
24
15
 
25
16
  declare class Annotation extends StringElement {
26
17
  constructor(content?: string, meta?: Meta, attributes?: Attributes);
@@ -60,6 +51,94 @@ declare class SourceMap extends ArrayElement {
60
51
  set position(position: PositionRange | undefined);
61
52
  }
62
53
 
54
+ declare const createToolbox: () => {
55
+ predicates: {
56
+ isElement: ElementPredicate<minim.Element>;
57
+ isStringElement: ElementPredicate<minim.StringElement>;
58
+ isNumberElement: ElementPredicate<minim.NumberElement>;
59
+ isNullElement: ElementPredicate<minim.NullElement>;
60
+ isBooleanElement: ElementPredicate<minim.BooleanElement>;
61
+ isObjectElement: ElementPredicate<minim.ObjectElement>;
62
+ isArrayElement: ElementPredicate<minim.ArrayElement>;
63
+ isMemberElement: ElementPredicate<minim.MemberElement>;
64
+ isLinkElement: ElementPredicate<minim.LinkElement>;
65
+ isRefElement: ElementPredicate<minim.RefElement>;
66
+ isAnnotationElement: ElementPredicate<Annotation>;
67
+ isCommentElement: ElementPredicate<Comment>;
68
+ isParseResultElement: ElementPredicate<ParseResult>;
69
+ isSourceMapElement: ElementPredicate<SourceMap>;
70
+ isPrimitiveElement: ElementPredicate<minim.StringElement | minim.ObjectElement | minim.ArrayElement | minim.NumberElement | minim.NullElement | minim.BooleanElement | minim.MemberElement>;
71
+ hasElementSourceMap: <T extends minim.Element>(element: T) => boolean;
72
+ includesSymbols: <T_1 extends minim.Element>(symbols: string[], element: T_1) => boolean;
73
+ includesClasses: <T_2 extends minim.Element>(classes: string[], element: T_2) => boolean;
74
+ };
75
+ namespace: Namespace;
76
+ };
77
+
78
+ declare const getNodeType: <T extends Element>(element: T) => string | undefined;
79
+ declare const cloneNode: <T>(node: T) => T;
80
+ declare const keyMapDefault: {
81
+ ObjectElement: string[];
82
+ ArrayElement: string[];
83
+ MemberElement: string[];
84
+ StringElement: never[];
85
+ BooleanElement: never[];
86
+ NumberElement: never[];
87
+ NullElement: never[];
88
+ RefElement: never[];
89
+ LinkElement: never[];
90
+ Annotation: never[];
91
+ Comment: never[];
92
+ ParseResultElement: string[];
93
+ SourceMap: string[];
94
+ };
95
+ declare const visit: (root: Element, visitor: any, { keyMap, ...rest }?: {
96
+ keyMap?: {
97
+ ObjectElement: string[];
98
+ ArrayElement: string[];
99
+ MemberElement: string[];
100
+ StringElement: never[];
101
+ BooleanElement: never[];
102
+ NumberElement: never[];
103
+ NullElement: never[];
104
+ RefElement: never[];
105
+ LinkElement: never[];
106
+ Annotation: never[];
107
+ Comment: never[];
108
+ ParseResultElement: string[];
109
+ SourceMap: string[];
110
+ } | undefined;
111
+ }) => Element;
112
+
113
+ interface DispatchPluginsOptions {
114
+ toolboxCreator: typeof createToolbox;
115
+ visitorOptions: {
116
+ nodeTypeGetter: typeof getNodeType;
117
+ exposeEdits: boolean;
118
+ };
119
+ }
120
+ interface DispatchPluginsSync {
121
+ <T extends Element, U extends Element = Element>(element: T, plugins: ((toolbox: any) => object)[], options?: Record<string, unknown>): U;
122
+ [key: symbol]: DispatchPluginsAsync;
123
+ }
124
+ interface DispatchPluginsAsync {
125
+ <T extends Element, U extends Element = Element>(element: T, plugins: ((toolbox: any) => object)[], options?: Record<string, unknown>): Promise<U>;
126
+ }
127
+ declare const dispatchPluginsSync: DispatchPluginsSync;
128
+
129
+ /**
130
+ * Plugin for decorating every element in ApiDOM tree with UUID.
131
+ */
132
+ declare const plugin$1: ({ length }?: {
133
+ length?: number | undefined;
134
+ }) => () => {
135
+ pre(): void;
136
+ visitor: {
137
+ enter<T extends Element>(element: T): void;
138
+ };
139
+ post(): void;
140
+ };
141
+
63
142
  interface PredicateHelpers {
64
143
  hasMethod: typeof hasMethod;
65
144
  hasBasicElementProps: typeof hasBasicElementProps;
@@ -133,12 +212,6 @@ declare class MediaTypes<T> extends Array<T> {
133
212
  latest(): void;
134
213
  }
135
214
 
136
- declare class Namespace extends Namespace$1 {
137
- constructor();
138
- }
139
- declare const namespace: Namespace;
140
- declare const createNamespace: (namespacePlugin?: NamespacePlugin) => Namespace;
141
-
142
215
  declare const filter: <T extends Element>(predicate: (element: any) => boolean, element: T) => ArraySlice;
143
216
 
144
217
  declare const find: <T extends Element>(predicate: (element: any) => boolean, element: T) => T | undefined;
@@ -153,41 +226,6 @@ declare const reject: <T extends Element>(predicate: (element: any) => boolean,
153
226
 
154
227
  declare const some: <T extends Element>(predicate: (element: any) => boolean, element: T) => boolean;
155
228
 
156
- declare const getNodeType: <T extends Element>(element: T) => string | undefined;
157
- declare const cloneNode: <T>(node: T) => T;
158
- declare const keyMapDefault: {
159
- ObjectElement: string[];
160
- ArrayElement: string[];
161
- MemberElement: string[];
162
- StringElement: never[];
163
- BooleanElement: never[];
164
- NumberElement: never[];
165
- NullElement: never[];
166
- RefElement: never[];
167
- LinkElement: never[];
168
- Annotation: never[];
169
- Comment: never[];
170
- ParseResultElement: string[];
171
- SourceMap: string[];
172
- };
173
- declare const visit: (root: Element, visitor: any, { keyMap, ...rest }?: {
174
- keyMap?: {
175
- ObjectElement: string[];
176
- ArrayElement: string[];
177
- MemberElement: string[];
178
- StringElement: never[];
179
- BooleanElement: never[];
180
- NumberElement: never[];
181
- NullElement: never[];
182
- RefElement: never[];
183
- LinkElement: never[];
184
- Annotation: never[];
185
- Comment: never[];
186
- ParseResultElement: string[];
187
- SourceMap: string[];
188
- } | undefined;
189
- }) => Element;
190
-
191
229
  type Callback = <T extends Element>(element: T) => void;
192
230
  interface TraverseOptions {
193
231
  callback?: Callback;
@@ -342,4 +380,4 @@ declare const mergeLeft: {
342
380
  all(list: ObjectOrArrayElement[], options?: MergeRightOptions | undefined): any;
343
381
  };
344
382
 
345
- export { Annotation as AnnotationElement, CloneError, Comment as CommentElement, DeepCloneError, type DeepMergeUserOptions, ElementIdentityError, type ElementPredicate, IdentityManager, MediaTypes, type MergeRightOptions as MergeLeftOptions, type MergeRightOptions, Namespace, type ObjectOrArrayElement, ParseResult as ParseResultElement, type Position, type PositionRange, ShallowCloneError, SourceMap as SourceMapElement, Transcluder, cloneDeep, cloneNode, cloneShallow, createNamespace, createPredicate, deepmerge, defaultIdentityManager, dehydrate, dereference, dispatchPlugins as dispatchRefractorPlugins, filter, find, findAtOffset, fromFn as from, getNodeType, hasElementSourceMap, includesClasses, includesSymbols, isAnnotationElement, isArrayElement, isBooleanElement, isElement, isLinkElement, isMemberElement, isNullElement, isNumberElement, isObjectElement, isParseResultElement, isPrimitiveElement, isRefElement, isSourceMapElement, isStringElement, keyMapDefault as keyMap, mergeLeft, mergeRight, namespace, parents, plugin$1 as refractorPluginElementIdentity, plugin as refractorPluginSemanticElementIdentity, reject, sexprs, some, serializer$1 as toJSON, toString, serializer$2 as toValue, serializer as toYAML, transclude, traverse, visit };
383
+ export { Annotation as AnnotationElement, CloneError, Comment as CommentElement, DeepCloneError, type DeepMergeUserOptions, type DispatchPluginsAsync, type DispatchPluginsOptions, type DispatchPluginsSync, ElementIdentityError, type ElementPredicate, IdentityManager, MediaTypes, type MergeRightOptions as MergeLeftOptions, type MergeRightOptions, Namespace, type ObjectOrArrayElement, ParseResult as ParseResultElement, type Position, type PositionRange, ShallowCloneError, SourceMap as SourceMapElement, Transcluder, cloneDeep, cloneNode, cloneShallow, createNamespace, createPredicate, deepmerge, defaultIdentityManager, dehydrate, dereference, dispatchPluginsSync as dispatchRefractorPlugins, filter, find, findAtOffset, fromFn as from, getNodeType, hasElementSourceMap, includesClasses, includesSymbols, isAnnotationElement, isArrayElement, isBooleanElement, isElement, isLinkElement, isMemberElement, isNullElement, isNumberElement, isObjectElement, isParseResultElement, isPrimitiveElement, isRefElement, isSourceMapElement, isStringElement, keyMapDefault as keyMap, mergeLeft, mergeRight, namespace, parents, plugin$1 as refractorPluginElementIdentity, plugin as refractorPluginSemanticElementIdentity, reject, sexprs, some, serializer$1 as toJSON, toString, serializer$2 as toValue, serializer as toYAML, transclude, traverse, visit };
@@ -1,36 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
- exports.__esModule = true;
5
- exports.dispatchPlugins = void 0;
6
- var _ramda = require("ramda");
7
- var _ramdaAdjunct = require("ramda-adjunct");
8
- var _toolbox = _interopRequireDefault(require("../../toolbox.cjs"));
9
- var _visitor = require("../../../traversal/visitor.cjs");
10
- const defaultDispatchPluginsOptions = {
11
- toolboxCreator: _toolbox.default,
12
- visitorOptions: {
13
- nodeTypeGetter: _visitor.getNodeType,
14
- exposeEdits: true
15
- }
16
- };
17
-
18
- // eslint-disable-next-line import/prefer-default-export
19
- const dispatchPlugins = (element, plugins, options = {}) => {
20
- if (plugins.length === 0) return element;
21
- const mergedOptions = (0, _ramda.mergeDeepRight)(defaultDispatchPluginsOptions, options);
22
- const {
23
- toolboxCreator,
24
- visitorOptions
25
- } = mergedOptions;
26
- const toolbox = toolboxCreator();
27
- const pluginsSpecs = plugins.map(plugin => plugin(toolbox));
28
- const mergedPluginsVisitor = (0, _visitor.mergeAllVisitors)(pluginsSpecs.map((0, _ramda.propOr)({}, 'visitor')), {
29
- ...visitorOptions
30
- });
31
- pluginsSpecs.forEach((0, _ramdaAdjunct.invokeArgs)(['pre'], []));
32
- const newElement = (0, _visitor.visit)(element, mergedPluginsVisitor, visitorOptions);
33
- pluginsSpecs.forEach((0, _ramdaAdjunct.invokeArgs)(['post'], []));
34
- return newElement;
35
- };
36
- exports.dispatchPlugins = dispatchPlugins;
@@ -1,30 +0,0 @@
1
- import { mergeDeepRight, propOr } from 'ramda';
2
- import { invokeArgs } from 'ramda-adjunct';
3
- import createToolbox from "../../toolbox.mjs";
4
- import { getNodeType, mergeAllVisitors, visit } from "../../../traversal/visitor.mjs";
5
- const defaultDispatchPluginsOptions = {
6
- toolboxCreator: createToolbox,
7
- visitorOptions: {
8
- nodeTypeGetter: getNodeType,
9
- exposeEdits: true
10
- }
11
- };
12
-
13
- // eslint-disable-next-line import/prefer-default-export
14
- export const dispatchPlugins = (element, plugins, options = {}) => {
15
- if (plugins.length === 0) return element;
16
- const mergedOptions = mergeDeepRight(defaultDispatchPluginsOptions, options);
17
- const {
18
- toolboxCreator,
19
- visitorOptions
20
- } = mergedOptions;
21
- const toolbox = toolboxCreator();
22
- const pluginsSpecs = plugins.map(plugin => plugin(toolbox));
23
- const mergedPluginsVisitor = mergeAllVisitors(pluginsSpecs.map(propOr({}, 'visitor')), {
24
- ...visitorOptions
25
- });
26
- pluginsSpecs.forEach(invokeArgs(['pre'], []));
27
- const newElement = visit(element, mergedPluginsVisitor, visitorOptions);
28
- pluginsSpecs.forEach(invokeArgs(['post'], []));
29
- return newElement;
30
- };