@swagger-api/apidom-core 0.99.1 → 1.0.0-alpha.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/CHANGELOG.md +14 -0
- package/cjs/identity/index.cjs +35 -44
- package/cjs/refractor/plugins/element-identity.cjs +1 -1
- package/cjs/refractor/plugins/semantic-element-identity.cjs +1 -1
- package/dist/apidom-core.browser.js +3005 -3453
- package/dist/apidom-core.browser.min.js +1 -1
- package/es/identity/index.mjs +34 -44
- package/es/refractor/plugins/element-identity.mjs +1 -1
- package/es/refractor/plugins/semantic-element-identity.mjs +1 -1
- package/package.json +7 -7
- package/types/dist.d.ts +10 -10
package/es/identity/index.mjs
CHANGED
|
@@ -1,59 +1,49 @@
|
|
|
1
1
|
import { StringElement } from 'minim';
|
|
2
|
-
import stampit from 'stampit';
|
|
3
2
|
import ShortUniqueId from 'short-unique-id';
|
|
4
3
|
import ElementIdentityError from "./errors/ElementIdentityError.mjs";
|
|
5
4
|
import { isElement, isStringElement } from "../predicates/index.mjs";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
length: null,
|
|
11
|
-
identityMap: null
|
|
12
|
-
},
|
|
13
|
-
init({
|
|
5
|
+
export class IdentityManager {
|
|
6
|
+
uuid;
|
|
7
|
+
identityMap;
|
|
8
|
+
constructor({
|
|
14
9
|
length = 6
|
|
15
10
|
} = {}) {
|
|
16
|
-
this.length = 6;
|
|
17
11
|
this.uuid = new ShortUniqueId({
|
|
18
12
|
length
|
|
19
13
|
});
|
|
20
14
|
this.identityMap = new WeakMap();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
15
|
+
}
|
|
16
|
+
identify(element) {
|
|
17
|
+
if (!isElement(element)) {
|
|
18
|
+
throw new ElementIdentityError('Cannot not identify the element. `element` is neither structurally compatible nor a subclass of an Element class.', {
|
|
19
|
+
value: element
|
|
20
|
+
});
|
|
21
|
+
}
|
|
29
22
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
// use already assigned identity
|
|
24
|
+
if (element.meta.hasKey('id') && isStringElement(element.meta.get('id')) && !element.meta.get('id').equals('')) {
|
|
25
|
+
return element.id;
|
|
26
|
+
}
|
|
34
27
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
28
|
+
// assign identity in immutable way
|
|
29
|
+
if (this.identityMap.has(element)) {
|
|
30
|
+
return this.identityMap.get(element);
|
|
31
|
+
}
|
|
39
32
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
return false;
|
|
51
|
-
},
|
|
52
|
-
generateId() {
|
|
53
|
-
return this.uuid.randomUUID();
|
|
33
|
+
// return element identity
|
|
34
|
+
const id = new StringElement(this.generateId());
|
|
35
|
+
this.identityMap.set(element, id);
|
|
36
|
+
return id;
|
|
37
|
+
}
|
|
38
|
+
forget(element) {
|
|
39
|
+
if (this.identityMap.has(element)) {
|
|
40
|
+
this.identityMap.delete(element);
|
|
41
|
+
return true;
|
|
54
42
|
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
generateId() {
|
|
46
|
+
return this.uuid.randomUUID();
|
|
55
47
|
}
|
|
56
|
-
}
|
|
57
|
-
export const defaultIdentityManager = IdentityManager(
|
|
58
|
-
length: 6
|
|
59
|
-
});
|
|
48
|
+
}
|
|
49
|
+
export const defaultIdentityManager = new IdentityManager();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swagger-api/apidom-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-alpha.0",
|
|
4
4
|
"description": "Tools for manipulating ApiDOM structures.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -42,14 +42,14 @@
|
|
|
42
42
|
"license": "Apache-2.0",
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@babel/runtime-corejs3": "^7.20.7",
|
|
45
|
-
"@swagger-api/apidom-ast": "^0.
|
|
45
|
+
"@swagger-api/apidom-ast": "^1.0.0-alpha.0",
|
|
46
46
|
"@swagger-api/apidom-error": "^0.99.0",
|
|
47
|
-
"@types/ramda": "~0.
|
|
47
|
+
"@types/ramda": "~0.30.0",
|
|
48
48
|
"minim": "~0.23.8",
|
|
49
|
-
"ramda": "~0.
|
|
50
|
-
"ramda-adjunct": "^
|
|
49
|
+
"ramda": "~0.30.0",
|
|
50
|
+
"ramda-adjunct": "^5.0.0",
|
|
51
51
|
"short-unique-id": "^5.0.2",
|
|
52
|
-
"
|
|
52
|
+
"ts-mixer": "^6.0.3"
|
|
53
53
|
},
|
|
54
54
|
"files": [
|
|
55
55
|
"cjs/",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"README.md",
|
|
63
63
|
"CHANGELOG.md"
|
|
64
64
|
],
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "b126995cc9e0f0c986c581aaa8b3fd1c35dfbdf7"
|
|
66
66
|
}
|
package/types/dist.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import * as minim from 'minim';
|
|
|
3
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
|
-
import stampit from 'stampit';
|
|
7
6
|
import ShortUniqueId from 'short-unique-id';
|
|
8
7
|
export { BREAK, mergeAllVisitors } from '@swagger-api/apidom-ast';
|
|
9
8
|
|
|
@@ -287,16 +286,17 @@ declare class DeepCloneError extends CloneError {
|
|
|
287
286
|
declare class ShallowCloneError extends CloneError {
|
|
288
287
|
}
|
|
289
288
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
289
|
+
declare class IdentityManager {
|
|
290
|
+
protected readonly uuid: ShortUniqueId;
|
|
291
|
+
protected readonly identityMap: WeakMap<Element, StringElement>;
|
|
292
|
+
constructor({ length }?: {
|
|
293
|
+
length?: number | undefined;
|
|
294
|
+
});
|
|
295
|
+
identify<T extends Element>(this: IdentityManager, element: T): StringElement;
|
|
296
|
+
forget<T extends Element>(element: T): boolean;
|
|
297
|
+
generateId(): string;
|
|
297
298
|
}
|
|
298
|
-
declare const
|
|
299
|
-
declare const defaultIdentityManager: IdentityManager<Element>;
|
|
299
|
+
declare const defaultIdentityManager: IdentityManager;
|
|
300
300
|
|
|
301
301
|
interface ElementIdentityErrorOptions extends ApiDOMErrorOptions {
|
|
302
302
|
readonly value: unknown;
|