@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.
@@ -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
- // @TODO(oliwia.rogala@smartbear.com): transforming this stamp to class will break backward compatibility
7
- export const IdentityManager = stampit({
8
- props: {
9
- uuid: null,
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
- methods: {
23
- identify(element) {
24
- if (!isElement(element)) {
25
- throw new ElementIdentityError('Cannot not identify the element. `element` is neither structurally compatible nor a subclass of an Element class.', {
26
- value: element
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
- // use already assigned identity
31
- if (element.meta.hasKey('id') && isStringElement(element.meta.get('id')) && !element.meta.get('id').equals('')) {
32
- return element.id;
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
- // assign identity in immutable way
36
- if (this.identityMap.has(element)) {
37
- return this.identityMap.get(element);
38
- }
28
+ // assign identity in immutable way
29
+ if (this.identityMap.has(element)) {
30
+ return this.identityMap.get(element);
31
+ }
39
32
 
40
- // return element identity
41
- const id = new StringElement(this.generateId());
42
- this.identityMap.set(element, id);
43
- return id;
44
- },
45
- forget(element) {
46
- if (this.identityMap.has(element)) {
47
- this.identityMap.delete(element);
48
- return true;
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();
@@ -8,7 +8,7 @@ const plugin = ({
8
8
  let identityManager;
9
9
  return {
10
10
  pre() {
11
- identityManager = IdentityManager({
11
+ identityManager = new IdentityManager({
12
12
  length
13
13
  });
14
14
  },
@@ -10,7 +10,7 @@ const plugin = ({
10
10
  let identityManager;
11
11
  return {
12
12
  pre() {
13
- identityManager = IdentityManager({
13
+ identityManager = new IdentityManager({
14
14
  length
15
15
  });
16
16
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swagger-api/apidom-core",
3
- "version": "0.99.1",
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.99.1",
45
+ "@swagger-api/apidom-ast": "^1.0.0-alpha.0",
46
46
  "@swagger-api/apidom-error": "^0.99.0",
47
- "@types/ramda": "~0.29.6",
47
+ "@types/ramda": "~0.30.0",
48
48
  "minim": "~0.23.8",
49
- "ramda": "~0.29.1",
50
- "ramda-adjunct": "^4.1.1",
49
+ "ramda": "~0.30.0",
50
+ "ramda-adjunct": "^5.0.0",
51
51
  "short-unique-id": "^5.0.2",
52
- "stampit": "^4.3.2"
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": "ad1f5d3aff83a179309673da13801a882cd3df6a"
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
- interface IdentityManager<T extends Element = Element> {
291
- length: number;
292
- uuid: ShortUniqueId;
293
- identityMap: WeakMap<T, StringElement>;
294
- identify(this: IdentityManager<T>, element: T): StringElement;
295
- forget(this: IdentityManager<T>, element: T): boolean;
296
- generateId(this: IdentityManager<T>): string;
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 IdentityManager: stampit.Stamp<IdentityManager>;
299
- declare const defaultIdentityManager: IdentityManager<Element>;
299
+ declare const defaultIdentityManager: IdentityManager;
300
300
 
301
301
  interface ElementIdentityErrorOptions extends ApiDOMErrorOptions {
302
302
  readonly value: unknown;