@speclynx/apidom-reference 4.0.3 → 4.0.5
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/CHANGELOG.md +10 -0
- package/dist/apidom-reference.browser.js +43 -19
- package/dist/apidom-reference.browser.min.js +1 -1
- package/package.json +27 -26
- package/src/File.ts +0 -63
- package/src/Reference.ts +0 -38
- package/src/ReferenceSet.ts +0 -73
- package/src/bundle/index.ts +0 -57
- package/src/bundle/strategies/BundleStrategy.ts +0 -27
- package/src/bundle/strategies/openapi-3-1/index.ts +0 -57
- package/src/configuration/empty.ts +0 -1
- package/src/configuration/saturated.ts +0 -72
- package/src/dereference/index.ts +0 -96
- package/src/dereference/strategies/DereferenceStrategy.ts +0 -27
- package/src/dereference/strategies/apidom/index.ts +0 -128
- package/src/dereference/strategies/apidom/selectors/element-id.ts +0 -48
- package/src/dereference/strategies/apidom/visitor.ts +0 -316
- package/src/dereference/strategies/arazzo-1/index.ts +0 -158
- package/src/dereference/strategies/arazzo-1/selectors/$anchor.ts +0 -9
- package/src/dereference/strategies/arazzo-1/selectors/uri.ts +0 -5
- package/src/dereference/strategies/arazzo-1/source-descriptions.ts +0 -317
- package/src/dereference/strategies/arazzo-1/util.ts +0 -33
- package/src/dereference/strategies/arazzo-1/visitor.ts +0 -574
- package/src/dereference/strategies/asyncapi-2/index.ts +0 -133
- package/src/dereference/strategies/asyncapi-2/visitor.ts +0 -589
- package/src/dereference/strategies/openapi-2/index.ts +0 -136
- package/src/dereference/strategies/openapi-2/visitor.ts +0 -745
- package/src/dereference/strategies/openapi-3-0/index.ts +0 -134
- package/src/dereference/strategies/openapi-3-0/visitor.ts +0 -760
- package/src/dereference/strategies/openapi-3-1/index.ts +0 -141
- package/src/dereference/strategies/openapi-3-1/selectors/$anchor.ts +0 -64
- package/src/dereference/strategies/openapi-3-1/selectors/uri.ts +0 -54
- package/src/dereference/strategies/openapi-3-1/util.ts +0 -83
- package/src/dereference/strategies/openapi-3-1/visitor.ts +0 -1053
- package/src/dereference/util.ts +0 -29
- package/src/errors/BundleError.ts +0 -8
- package/src/errors/DereferenceError.ts +0 -8
- package/src/errors/EvaluationElementIdError.ts +0 -8
- package/src/errors/EvaluationJsonSchema$anchorError.ts +0 -8
- package/src/errors/EvaluationJsonSchemaUriError.ts +0 -8
- package/src/errors/InvalidJsonSchema$anchorError.ts +0 -12
- package/src/errors/JsonSchema$anchorError.ts +0 -8
- package/src/errors/JsonSchemaUriError.ts +0 -8
- package/src/errors/MaximumBundleDepthError.ts +0 -8
- package/src/errors/MaximumDereferenceDepthError.ts +0 -8
- package/src/errors/MaximumResolveDepthError.ts +0 -8
- package/src/errors/ParseError.ts +0 -8
- package/src/errors/ParserError.ts +0 -8
- package/src/errors/PluginError.ts +0 -15
- package/src/errors/ResolveError.ts +0 -8
- package/src/errors/ResolverError.ts +0 -8
- package/src/errors/UnmatchedBundleStrategyError.ts +0 -8
- package/src/errors/UnmatchedDereferenceStrategyError.ts +0 -8
- package/src/errors/UnmatchedParserError.ts +0 -8
- package/src/errors/UnmatchedResolveStrategyError.ts +0 -8
- package/src/errors/UnmatchedResolverError.ts +0 -8
- package/src/errors/UnresolvableReferenceError.ts +0 -8
- package/src/index.ts +0 -135
- package/src/options/index.ts +0 -239
- package/src/options/util.ts +0 -22
- package/src/parse/index.ts +0 -67
- package/src/parse/parsers/Parser.ts +0 -80
- package/src/parse/parsers/apidom-json/index.ts +0 -78
- package/src/parse/parsers/arazzo-json-1/index.ts +0 -76
- package/src/parse/parsers/arazzo-json-1/source-descriptions.ts +0 -280
- package/src/parse/parsers/arazzo-yaml-1/index.ts +0 -77
- package/src/parse/parsers/arazzo-yaml-1/source-descriptions.ts +0 -16
- package/src/parse/parsers/asyncapi-json-2/index.ts +0 -58
- package/src/parse/parsers/asyncapi-yaml-2/index.ts +0 -58
- package/src/parse/parsers/binary/index-browser.ts +0 -60
- package/src/parse/parsers/binary/index-node.ts +0 -57
- package/src/parse/parsers/json/index.ts +0 -52
- package/src/parse/parsers/openapi-json-2/index.ts +0 -58
- package/src/parse/parsers/openapi-json-3-0/index.ts +0 -59
- package/src/parse/parsers/openapi-json-3-1/index.ts +0 -59
- package/src/parse/parsers/openapi-yaml-2/index.ts +0 -58
- package/src/parse/parsers/openapi-yaml-3-0/index.ts +0 -59
- package/src/parse/parsers/openapi-yaml-3-1/index.ts +0 -59
- package/src/parse/parsers/yaml-1-2/index.ts +0 -60
- package/src/resolve/index.ts +0 -75
- package/src/resolve/resolvers/HTTPResolver.ts +0 -58
- package/src/resolve/resolvers/Resolver.ts +0 -25
- package/src/resolve/resolvers/file/index-browser.ts +0 -24
- package/src/resolve/resolvers/file/index-node.ts +0 -55
- package/src/resolve/resolvers/http-axios/cache/MemoryCache.ts +0 -46
- package/src/resolve/resolvers/http-axios/index.ts +0 -130
- package/src/resolve/strategies/ResolveStrategy.ts +0 -26
- package/src/resolve/strategies/apidom/index.ts +0 -78
- package/src/resolve/strategies/asyncapi-2/index.ts +0 -78
- package/src/resolve/strategies/openapi-2/index.ts +0 -78
- package/src/resolve/strategies/openapi-3-0/index.ts +0 -78
- package/src/resolve/strategies/openapi-3-1/index.ts +0 -78
- package/src/resolve/util.ts +0 -39
- package/src/util/plugins.ts +0 -37
- package/src/util/url.ts +0 -285
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { propEq } from 'ramda';
|
|
2
|
-
import { Element, cloneDeep } from '@speclynx/apidom-datamodel';
|
|
3
|
-
import { traverseAsync } from '@speclynx/apidom-traverse';
|
|
4
|
-
import { isOpenApi3_1Element, mediaTypes } from '@speclynx/apidom-ns-openapi-3-1';
|
|
5
|
-
|
|
6
|
-
import DereferenceStrategy, { DereferenceStrategyOptions } from '../DereferenceStrategy.ts';
|
|
7
|
-
import File from '../../../File.ts';
|
|
8
|
-
import Reference from '../../../Reference.ts';
|
|
9
|
-
import ReferenceSet from '../../../ReferenceSet.ts';
|
|
10
|
-
import OpenAPI3_1DereferenceVisitor from './visitor.ts';
|
|
11
|
-
import type { ReferenceOptions } from '../../../options/index.ts';
|
|
12
|
-
|
|
13
|
-
export type {
|
|
14
|
-
default as DereferenceStrategy,
|
|
15
|
-
DereferenceStrategyOptions,
|
|
16
|
-
} from '../DereferenceStrategy.ts';
|
|
17
|
-
export type { default as File, FileOptions } from '../../../File.ts';
|
|
18
|
-
export type { default as Reference, ReferenceOptions } from '../../../Reference.ts';
|
|
19
|
-
export type { default as ReferenceSet, ReferenceSetOptions } from '../../../ReferenceSet.ts';
|
|
20
|
-
export type { OpenAPI3_1DereferenceVisitorOptions } from './visitor.ts';
|
|
21
|
-
export type {
|
|
22
|
-
ReferenceOptions as ApiDOMReferenceOptions,
|
|
23
|
-
ReferenceBundleOptions as ApiDOMReferenceBundleOptions,
|
|
24
|
-
ReferenceDereferenceOptions as ApiDOMReferenceDereferenceOptions,
|
|
25
|
-
ReferenceParseOptions as ApiDOMReferenceParseOptions,
|
|
26
|
-
ReferenceResolveOptions as ApiDOMReferenceResolveOptions,
|
|
27
|
-
} from '../../../options/index.ts';
|
|
28
|
-
export type { default as Parser, ParserOptions } from '../../../parse/parsers/Parser.ts';
|
|
29
|
-
export type { default as Resolver, ResolverOptions } from '../../../resolve/resolvers/Resolver.ts';
|
|
30
|
-
export type {
|
|
31
|
-
default as ResolveStrategy,
|
|
32
|
-
ResolveStrategyOptions,
|
|
33
|
-
} from '../../../resolve/strategies/ResolveStrategy.ts';
|
|
34
|
-
export type {
|
|
35
|
-
default as BundleStrategy,
|
|
36
|
-
BundleStrategyOptions,
|
|
37
|
-
} from '../../../bundle/strategies/BundleStrategy.ts';
|
|
38
|
-
export type { AncestorLineage } from '../../util.ts';
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* @public
|
|
42
|
-
*/
|
|
43
|
-
export interface OpenAPI3_1DereferenceStrategyOptions extends Omit<
|
|
44
|
-
DereferenceStrategyOptions,
|
|
45
|
-
'name'
|
|
46
|
-
> {}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* @public
|
|
50
|
-
*/
|
|
51
|
-
class OpenAPI3_1DereferenceStrategy extends DereferenceStrategy {
|
|
52
|
-
constructor(options?: OpenAPI3_1DereferenceStrategyOptions) {
|
|
53
|
-
super({ ...(options ?? {}), name: 'openapi-3-1' });
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
canDereference(file: File): boolean {
|
|
57
|
-
// assert by media type
|
|
58
|
-
if (file.mediaType !== 'text/plain') {
|
|
59
|
-
return mediaTypes.includes(file.mediaType);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// assert by inspecting ApiDOM
|
|
63
|
-
return isOpenApi3_1Element(file.parseResult?.result);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async dereference(file: File, options: ReferenceOptions): Promise<Element> {
|
|
67
|
-
const immutableRefSet = options.dereference.refSet ?? new ReferenceSet();
|
|
68
|
-
const mutableRefSet = new ReferenceSet();
|
|
69
|
-
let refSet = immutableRefSet;
|
|
70
|
-
let reference;
|
|
71
|
-
|
|
72
|
-
if (!immutableRefSet.has(file.uri)) {
|
|
73
|
-
reference = new Reference({ uri: file.uri, value: file.parseResult! });
|
|
74
|
-
immutableRefSet.add(reference);
|
|
75
|
-
} else {
|
|
76
|
-
// pre-computed refSet was provided as configuration option
|
|
77
|
-
reference = immutableRefSet.find(propEq(file.uri, 'uri'));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Clone refSet due the dereferencing process being mutable.
|
|
82
|
-
* We don't want to mutate the original refSet and the references.
|
|
83
|
-
*/
|
|
84
|
-
if (options.dereference.immutable) {
|
|
85
|
-
immutableRefSet.refs
|
|
86
|
-
.map(
|
|
87
|
-
(ref) =>
|
|
88
|
-
new Reference({
|
|
89
|
-
...ref,
|
|
90
|
-
value: cloneDeep(ref.value),
|
|
91
|
-
}),
|
|
92
|
-
)
|
|
93
|
-
.forEach((ref) => mutableRefSet.add(ref));
|
|
94
|
-
reference = mutableRefSet.find((ref) => ref.uri === file.uri);
|
|
95
|
-
refSet = mutableRefSet;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const visitor = new OpenAPI3_1DereferenceVisitor({ reference: reference!, options });
|
|
99
|
-
|
|
100
|
-
const dereferencedElement = await traverseAsync(refSet.rootRef!.value, visitor, {
|
|
101
|
-
mutable: true,
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* If immutable option is set, replay refs from the refSet.
|
|
106
|
-
*/
|
|
107
|
-
if (options.dereference.immutable) {
|
|
108
|
-
mutableRefSet.refs
|
|
109
|
-
.filter((ref) => ref.uri.startsWith('immutable://'))
|
|
110
|
-
.map(
|
|
111
|
-
(ref) =>
|
|
112
|
-
new Reference({
|
|
113
|
-
...ref,
|
|
114
|
-
uri: ref.uri.replace(/^immutable:\/\//, ''),
|
|
115
|
-
}),
|
|
116
|
-
)
|
|
117
|
-
.forEach((ref) => immutableRefSet.add(ref));
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Release all memory if this refSet was not provided as an configuration option.
|
|
122
|
-
* If provided as configuration option, then provider is responsible for cleanup.
|
|
123
|
-
*/
|
|
124
|
-
if (options.dereference.refSet === null) {
|
|
125
|
-
immutableRefSet.clean();
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
mutableRefSet.clean();
|
|
129
|
-
|
|
130
|
-
return dereferencedElement;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export { OpenAPI3_1DereferenceVisitor };
|
|
135
|
-
export {
|
|
136
|
-
resolveSchema$refField,
|
|
137
|
-
resolveSchema$idField,
|
|
138
|
-
maybeRefractToSchemaElement,
|
|
139
|
-
} from './util.ts';
|
|
140
|
-
|
|
141
|
-
export default OpenAPI3_1DereferenceStrategy;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { trimCharsStart, isUndefined } from 'ramda-adjunct';
|
|
2
|
-
import { Element } from '@speclynx/apidom-datamodel';
|
|
3
|
-
import { toValue } from '@speclynx/apidom-core';
|
|
4
|
-
import { find } from '@speclynx/apidom-traverse';
|
|
5
|
-
import { isJSONSchemaElement } from '@speclynx/apidom-ns-json-schema-2020-12';
|
|
6
|
-
|
|
7
|
-
import { getHash } from '../../../../util/url.ts';
|
|
8
|
-
import EvaluationJsonSchema$anchorError from '../../../../errors/EvaluationJsonSchema$anchorError.ts';
|
|
9
|
-
import InvalidJsonSchema$anchorError from '../../../../errors/InvalidJsonSchema$anchorError.ts';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @public
|
|
13
|
-
*/
|
|
14
|
-
export const isAnchor = (uri: string) => {
|
|
15
|
-
/**
|
|
16
|
-
* MUST start with a letter ([A-Za-z]) or underscore ("_"), followed by any number of letters,
|
|
17
|
-
* digits ([0-9]), hyphens ("-"), underscores ("_"), and periods (".").
|
|
18
|
-
*
|
|
19
|
-
* https://json-schema.org/draft/2020-12/json-schema-core.html#rfc.section.8.2.2
|
|
20
|
-
*/
|
|
21
|
-
return /^[A-Za-z_][A-Za-z_0-9.-]*$/.test(uri);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @public
|
|
26
|
-
*/
|
|
27
|
-
export const uriToAnchor = (uri: string): string => {
|
|
28
|
-
const hash = getHash(uri);
|
|
29
|
-
return trimCharsStart('#', hash);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @public
|
|
34
|
-
*/
|
|
35
|
-
export const parse = (anchor: string): string => {
|
|
36
|
-
if (!isAnchor(anchor)) {
|
|
37
|
-
throw new InvalidJsonSchema$anchorError(anchor);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return anchor;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Evaluates JSON Schema $anchor against ApiDOM fragment.
|
|
45
|
-
* @public
|
|
46
|
-
*/
|
|
47
|
-
export const evaluate = <T extends Element>(anchor: string, element: T): Element | undefined => {
|
|
48
|
-
const token = parse(anchor);
|
|
49
|
-
|
|
50
|
-
const resultPath = find(
|
|
51
|
-
element,
|
|
52
|
-
// @ts-ignore
|
|
53
|
-
(path) => isJSONSchemaElement(path.node) && toValue(path.node.$anchor) === token,
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
if (isUndefined(resultPath)) {
|
|
57
|
-
throw new EvaluationJsonSchema$anchorError(`Evaluation failed on token: "${token}"`);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return resultPath.node;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export { EvaluationJsonSchema$anchorError, InvalidJsonSchema$anchorError };
|
|
64
|
-
export { default as JsonSchema$anchorError } from '../../../../errors/JsonSchema$anchorError.ts';
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { isUndefined } from 'ramda-adjunct';
|
|
2
|
-
import { Element } from '@speclynx/apidom-datamodel';
|
|
3
|
-
import { filter, type Path } from '@speclynx/apidom-traverse';
|
|
4
|
-
import { isJSONSchemaElement, JSONSchemaElement } from '@speclynx/apidom-ns-json-schema-2020-12';
|
|
5
|
-
import {
|
|
6
|
-
URIFragmentIdentifier,
|
|
7
|
-
evaluate as jsonPointerEvaluate,
|
|
8
|
-
} from '@speclynx/apidom-json-pointer';
|
|
9
|
-
|
|
10
|
-
import * as url from '../../../../util/url.ts';
|
|
11
|
-
import EvaluationJsonSchemaUriError from '../../../../errors/EvaluationJsonSchemaUriError.ts';
|
|
12
|
-
import { isAnchor, uriToAnchor, evaluate as $anchorEvaluate } from './$anchor.ts';
|
|
13
|
-
import { resolveSchema$idField } from '../util.ts';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Evaluates JSON Schema $ref containing unknown URI against ApiDOM fragment.
|
|
17
|
-
* @public
|
|
18
|
-
*/
|
|
19
|
-
export const evaluate = <T extends Element>(uri: string, element: T): Element | undefined => {
|
|
20
|
-
const { cache } = evaluate;
|
|
21
|
-
const uriStrippedHash = url.stripHash(uri);
|
|
22
|
-
const isJSONSchemaElementWith$id = (path: Path<Element>) =>
|
|
23
|
-
isJSONSchemaElement(path.node) && typeof (path.node as any).$id !== 'undefined';
|
|
24
|
-
|
|
25
|
-
// warm the cache
|
|
26
|
-
if (!cache.has(element)) {
|
|
27
|
-
const schemaObjectPaths = filter(element, isJSONSchemaElementWith$id);
|
|
28
|
-
cache.set(
|
|
29
|
-
element,
|
|
30
|
-
schemaObjectPaths.map((path) => path.node),
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// search for the matching schema
|
|
35
|
-
const result = cache.get(element).find((e: JSONSchemaElement) => {
|
|
36
|
-
const $idBaseURI = resolveSchema$idField(uriStrippedHash, e);
|
|
37
|
-
return $idBaseURI === uriStrippedHash;
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
if (isUndefined(result)) {
|
|
41
|
-
throw new EvaluationJsonSchemaUriError(`Evaluation failed on URI: "${uri}"`);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (isAnchor(uriToAnchor(uri))) {
|
|
45
|
-
// we're dealing with JSON Schema $anchor here
|
|
46
|
-
return $anchorEvaluate(uriToAnchor(uri), result);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return jsonPointerEvaluate(result, URIFragmentIdentifier.fromURIReference(uri));
|
|
50
|
-
};
|
|
51
|
-
evaluate.cache = new WeakMap();
|
|
52
|
-
|
|
53
|
-
export { EvaluationJsonSchemaUriError };
|
|
54
|
-
export { default as JsonSchemaUriError } from '../../../../errors/JsonSchemaUriError.ts';
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { reduce } from 'ramda';
|
|
2
|
-
import { Element, isPrimitiveElement } from '@speclynx/apidom-datamodel';
|
|
3
|
-
import { toValue } from '@speclynx/apidom-core';
|
|
4
|
-
import { JSONSchemaElement } from '@speclynx/apidom-ns-json-schema-2020-12';
|
|
5
|
-
import { refractSchema } from '@speclynx/apidom-ns-openapi-3-1';
|
|
6
|
-
|
|
7
|
-
import * as url from '../../../util/url.ts';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @public
|
|
11
|
-
*/
|
|
12
|
-
export const resolveSchema$refField = (retrievalURI: string, schemaElement: JSONSchemaElement) => {
|
|
13
|
-
if (typeof schemaElement.$ref === 'undefined') {
|
|
14
|
-
return undefined;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const hash = url.getHash(toValue(schemaElement.$ref) as string);
|
|
18
|
-
const ancestorsSchemaIdentifiers = schemaElement.meta.get(
|
|
19
|
-
'ancestorsSchemaIdentifiers',
|
|
20
|
-
) as string[];
|
|
21
|
-
const $refBaseURI = reduce(
|
|
22
|
-
(acc: string, uri: string): string => {
|
|
23
|
-
return url.resolve(acc, url.sanitize(url.stripHash(uri)));
|
|
24
|
-
},
|
|
25
|
-
retrievalURI,
|
|
26
|
-
[...ancestorsSchemaIdentifiers, toValue(schemaElement.$ref) as string],
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
return `${$refBaseURI}${hash === '#' ? '' : hash}`;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @public
|
|
34
|
-
*/
|
|
35
|
-
export const resolveSchema$idField = (
|
|
36
|
-
retrievalURI: string,
|
|
37
|
-
schemaElement: JSONSchemaElement,
|
|
38
|
-
): string | undefined => {
|
|
39
|
-
if (typeof schemaElement.$id === 'undefined') {
|
|
40
|
-
return undefined;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const ancestorsSchemaIdentifiers = schemaElement.meta.get(
|
|
44
|
-
'ancestorsSchemaIdentifiers',
|
|
45
|
-
) as string[];
|
|
46
|
-
|
|
47
|
-
return reduce(
|
|
48
|
-
(acc: string, $id: string): string => {
|
|
49
|
-
return url.resolve(acc, url.sanitize(url.stripHash($id)));
|
|
50
|
-
},
|
|
51
|
-
retrievalURI,
|
|
52
|
-
ancestorsSchemaIdentifiers,
|
|
53
|
-
);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Cached version of SchemaElement.refract.
|
|
58
|
-
*/
|
|
59
|
-
export const refractToSchemaElement = <T extends Element>(element: T) => {
|
|
60
|
-
if (refractToSchemaElement.cache.has(element)) {
|
|
61
|
-
return refractToSchemaElement.cache.get(element);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const refracted = refractSchema(element);
|
|
65
|
-
refractToSchemaElement.cache.set(element, refracted);
|
|
66
|
-
return refracted;
|
|
67
|
-
};
|
|
68
|
-
refractToSchemaElement.cache = new WeakMap();
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* @public
|
|
72
|
-
*/
|
|
73
|
-
export const maybeRefractToSchemaElement = <T extends Element>(element: T) => {
|
|
74
|
-
/**
|
|
75
|
-
* Conditional version of refractToSchemaElement, that acts as an identity
|
|
76
|
-
* function for all non-primitive Element instances.
|
|
77
|
-
*/
|
|
78
|
-
if (isPrimitiveElement(element)) {
|
|
79
|
-
return refractToSchemaElement(element);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return element;
|
|
83
|
-
};
|