@semcore/core 17.0.0-prerelease.17 → 17.0.0-prerelease.19

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  CHANGELOG.md standards are inspired by [keepachangelog.com](https://keepachangelog.com/en/1.0.0/).
4
4
 
5
- ## [17.0.0] - 2026-02-18
5
+ ## [17.0.0] - 2026-02-19
6
6
 
7
7
  ### BREAK
8
8
 
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ function propsObserver(propsToWatch) {
10
+ return function (Class) {
11
+ return class extends Class {
12
+ constructor(...args) {
13
+ super(...args);
14
+ (0, _defineProperty2.default)(this, "__observableProps", {});
15
+ if (!this.props) return;
16
+ const observablePropKeys = propsToWatch.length === 0 ? Object.keys(this.props) : [...propsToWatch];
17
+ observablePropKeys.forEach(key => {
18
+ this.__observableProps[key] = this.props[key];
19
+ });
20
+ }
21
+ onPropsChange(_) {
22
+ let shouldEmitChanges = false;
23
+ const changedProps = {};
24
+ Object.entries(this.__observableProps).forEach(([key, value]) => {
25
+ const arePropsEqual = Object.is(value, this.props[key]);
26
+ if (!arePropsEqual) {
27
+ this.__observableProps[key] = this.props[key];
28
+ changedProps[key] = this.props[key];
29
+ shouldEmitChanges = true;
30
+ }
31
+ });
32
+ if (!shouldEmitChanges) return;
33
+ super.onPropsChange(changedProps);
34
+ }
35
+ componentWillUnmount() {
36
+ super.componentWillUnmount?.();
37
+ Object.keys(this.__observableProps).forEach(key => {
38
+ this.__observableProps[key] = undefined;
39
+ });
40
+ }
41
+ render() {
42
+ this.onPropsChange();
43
+ return super.render();
44
+ }
45
+ };
46
+ };
47
+ }
48
+ var _default = exports.default = propsObserver;
49
+ //# sourceMappingURL=propsObserver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"propsObserver.js","names":["propsObserver","propsToWatch","Class","constructor","args","_defineProperty2","default","props","observablePropKeys","length","Object","keys","forEach","key","__observableProps","onPropsChange","_","shouldEmitChanges","changedProps","entries","value","arePropsEqual","is","componentWillUnmount","undefined","render","_default","exports"],"sources":["../../src/decorators/propsObserver.ts"],"sourcesContent":["type WatchedProps<Props> = { [key in keyof Props]?: unknown };\n\ntype Constructor<Props> = new (...args: any[]) => {\n props: Props;\n onPropsChange(changedProps: WatchedProps<Props>): void;\n render(): React.ReactNode;\n componentWillUnmount?(): void;\n};\n\nfunction propsObserver<\n P extends Record<string, any>,\n C extends Constructor<P>,\n>(propsToWatch: Array<keyof P>) {\n return function (Class: C): C & Constructor<P> {\n return class extends Class {\n __observableProps: WatchedProps<P> = {};\n\n constructor(...args: any[]) {\n super(...args);\n\n if (!this.props) return;\n\n const observablePropKeys = propsToWatch.length === 0 ? Object.keys(this.props) : [...propsToWatch];\n\n observablePropKeys.forEach((key) => {\n this.__observableProps[key] = this.props[key];\n });\n }\n\n onPropsChange(_?: WatchedProps<P>) {\n let shouldEmitChanges = false;\n const changedProps: WatchedProps<P> = {};\n\n Object.entries(this.__observableProps).forEach(([key, value]: [key: keyof P, value: unknown]) => {\n const arePropsEqual = Object.is(value, this.props[key]);\n\n if (!arePropsEqual) {\n this.__observableProps[key] = this.props[key];\n changedProps[key] = this.props[key];\n\n shouldEmitChanges = true;\n }\n });\n\n if (!shouldEmitChanges) return;\n\n super.onPropsChange(changedProps);\n }\n\n componentWillUnmount() {\n super.componentWillUnmount?.();\n\n Object.keys(this.__observableProps).forEach((key: keyof P) => {\n this.__observableProps[key] = undefined;\n });\n }\n\n render() {\n this.onPropsChange();\n\n return super.render();\n }\n };\n };\n}\n\nexport default propsObserver;\n"],"mappings":";;;;;;;;AASA,SAASA,aAAaA,CAGpBC,YA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BAAoBA,CAAA,EAAG;QACrB,KAAK,CAACA,oBAAoB,GAAG,CAAC;QAE9Bb,MAAM,CAACC,IAAI,CAAC,IAAI,CAACG,iBAAiB,CAAC,CAACF,OAAO,CAAEC,GAAY,IAAK;UAC5D,IAAI,CAACC,iBAAiB,CAACD,GAAG,CAAC,GAAGW,SAAS;QACzC,CAAC,CAAC;MACJ;MAEAC,MAAMA,CAAA,EAAG;QACP,IAAI,CAACV,aAAa,CAAC,CAAC;QAEpB,OAAO,KAAK,CAACU,MAAM,CAAC,CAAC;MACvB;IACF,CAAC;EACH,CAAC;AACH;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAArB,OAAA,GAEcN,aAAa","ignoreList":[]}
@@ -0,0 +1,42 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ function propsObserver(propsToWatch) {
3
+ return function (Class) {
4
+ return class extends Class {
5
+ constructor(...args) {
6
+ super(...args);
7
+ _defineProperty(this, "__observableProps", {});
8
+ if (!this.props) return;
9
+ const observablePropKeys = propsToWatch.length === 0 ? Object.keys(this.props) : [...propsToWatch];
10
+ observablePropKeys.forEach(key => {
11
+ this.__observableProps[key] = this.props[key];
12
+ });
13
+ }
14
+ onPropsChange(_) {
15
+ let shouldEmitChanges = false;
16
+ const changedProps = {};
17
+ Object.entries(this.__observableProps).forEach(([key, value]) => {
18
+ const arePropsEqual = Object.is(value, this.props[key]);
19
+ if (!arePropsEqual) {
20
+ this.__observableProps[key] = this.props[key];
21
+ changedProps[key] = this.props[key];
22
+ shouldEmitChanges = true;
23
+ }
24
+ });
25
+ if (!shouldEmitChanges) return;
26
+ super.onPropsChange(changedProps);
27
+ }
28
+ componentWillUnmount() {
29
+ super.componentWillUnmount?.();
30
+ Object.keys(this.__observableProps).forEach(key => {
31
+ this.__observableProps[key] = undefined;
32
+ });
33
+ }
34
+ render() {
35
+ this.onPropsChange();
36
+ return super.render();
37
+ }
38
+ };
39
+ };
40
+ }
41
+ export default propsObserver;
42
+ //# sourceMappingURL=propsObserver.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"propsObserver.mjs","names":["propsObserver","propsToWatch","Class","constructor","args","_defineProperty","props","observablePropKeys","length","Object","keys","forEach","key","__observableProps","onPropsChange","_","shouldEmitChanges","changedProps","entries","value","arePropsEqual","is","componentWillUnmount","undefined","render"],"sources":["../../src/decorators/propsObserver.ts"],"sourcesContent":["type WatchedProps<Props> = { [key in keyof Props]?: unknown };\n\ntype Constructor<Props> = new (...args: any[]) => {\n props: Props;\n onPropsChange(changedProps: WatchedProps<Props>): void;\n render(): React.ReactNode;\n componentWillUnmount?(): void;\n};\n\nfunction propsObserver<\n P extends Record<string, any>,\n C extends Constructor<P>,\n>(propsToWatch: Array<keyof P>) {\n return function (Class: C): C & Constructor<P> {\n return class extends Class {\n __observableProps: WatchedProps<P> = {};\n\n constructor(...args: any[]) {\n super(...args);\n\n if (!this.props) return;\n\n const observablePropKeys = propsToWatch.length === 0 ? Object.keys(this.props) : [...propsToWatch];\n\n observablePropKeys.forEach((key) => {\n this.__observableProps[key] = this.props[key];\n });\n }\n\n onPropsChange(_?: WatchedProps<P>) {\n let shouldEmitChanges = false;\n const changedProps: WatchedProps<P> = {};\n\n Object.entries(this.__observableProps).forEach(([key, value]: [key: keyof P, value: unknown]) => {\n const arePropsEqual = Object.is(value, this.props[key]);\n\n if (!arePropsEqual) {\n this.__observableProps[key] = this.props[key];\n changedProps[key] = this.props[key];\n\n shouldEmitChanges = true;\n }\n });\n\n if (!shouldEmitChanges) return;\n\n super.onPropsChange(changedProps);\n }\n\n componentWillUnmount() {\n super.componentWillUnmount?.();\n\n Object.keys(this.__observableProps).forEach((key: keyof P) => {\n this.__observableProps[key] = undefined;\n });\n }\n\n render() {\n this.onPropsChange();\n\n return super.render();\n }\n };\n };\n}\n\nexport default propsObserver;\n"],"mappings":";AASA,SAASA,aAAaA,CAGpBC,YAA4B,EAAE;EAC9B,OAAO,UAAUC,KAAQ,EAAsB;IAC7C,O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ACC,IAAI,CAAC,IAAI,CAACG,iBAAiB,CAAC,CAACF,OAAO,CAAEC,GAAY,IAAK;UAC5D,IAAI,CAACC,iBAAiB,CAACD,GAAG,CAAC,GAAGW,SAAS;QACzC,CAAC,CAAC;MACJ;MAEAC,MAAMA,CAAA,EAAG;QACP,IAAI,CAACV,aAAa,CAAC,CAAC;QAEpB,OAAO,KAAK,CAACU,MAAM,CAAC,CAAC;MACvB;IACF,CAAC;EACH,CAAC;AACH;AAEA,eAAexB,aAAa","ignoreList":[]}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ const isPrimitiveValue = value => value !== Object(value);
8
+ function reactive(watchedFieldsOrCb, cb) {
9
+ return function (_, ctx) {
10
+ const {
11
+ addInitializer,
12
+ name
13
+ } = ctx;
14
+ addInitializer(function () {
15
+ const thisRoot = this;
16
+ const isPrimitive = isPrimitiveValue(this[name]);
17
+ const callback = typeof watchedFieldsOrCb === 'function' ? watchedFieldsOrCb : cb;
18
+ const fields = Array.isArray(watchedFieldsOrCb) ? watchedFieldsOrCb : null;
19
+ if (isPrimitive) {
20
+ let value = this[name];
21
+ Object.defineProperty(this, name, {
22
+ get() {
23
+ return value;
24
+ },
25
+ set(newValue) {
26
+ const oldValue = value;
27
+ value = newValue;
28
+ if (oldValue !== newValue) {
29
+ callback.call(thisRoot, name, newValue);
30
+ }
31
+ },
32
+ enumerable: true,
33
+ configurable: true
34
+ });
35
+ } else {
36
+ // @ts-ignore
37
+ this[name] = new Proxy(this[name], {
38
+ set(target, p, newValue) {
39
+ target[p] = newValue;
40
+ if (fields?.length === 0 || fields?.includes(p)) {
41
+ callback.call(thisRoot, p, newValue);
42
+ }
43
+ return true;
44
+ }
45
+ });
46
+ }
47
+ });
48
+ };
49
+ }
50
+ var _default = exports.default = reactive;
51
+ //# sourceMappingURL=reactive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactive.js","names":["isPrimitiveValue","value","Object","reactive","watchedFieldsOrCb","cb","_","ctx","addInitializer","name","thisRoot","isPrimitive","callback","fields","Array","isArray","defineProperty","get","set","newValue","oldValue","call","enumerable","configurable","Proxy","target","p","length","includes","_default","exports","default"],"sources":["../../src/decorators/reactive.ts"],"sourcesContent":["type Primitive = string | number | boolean | symbol | bigint | null | undefined;\ntype IsReadonly<This, Property extends keyof This> =\n (<F>() => F extends { [P in Property]: This[Property] } ? 1 : 2) extends\n (<F>() => F extends { -readonly [P in Property]: This[Property] } ? 1 : 2)\n ? false\n : true;\ntype Callback<This> = (this: This, field: string | symbol, newValue: unknown) => void;\ntype ReturnType<\n This,\n Property extends keyof This = keyof This,\n> = IsReadonly<This, Property> extends true\n ? (_: undefined, ctx: ClassFieldDecoratorContext<This, This[Property]>) => void\n : This[Property] extends Primitive\n ? (_: undefined, ctx: ClassFieldDecoratorContext<This, This[Property]>) => void\n : never;\n\nconst isPrimitiveValue = (value: unknown) => value !== Object(value);\n\nfunction reactive<\n This,\n Property extends keyof This,\n Value = This[Property],\n>(cb: Value extends Primitive ? Callback<This> : never): ReturnType<This>;\nfunction reactive<\n This,\n Property extends keyof This,\n Value = This[Property],\n>(watchedFields: Value extends Primitive ? never : Array<keyof Value>, cb: Callback<This>): ReturnType<This>;\n\nfunction reactive<\n This,\n Property extends keyof This,\n>(watchedFieldsOrCb: Array<keyof This[Property]> | Callback<This>, cb?: Callback<This>) {\n return function (_: undefined, ctx: ClassFieldDecoratorContext<This, This[Property]>) {\n const { addInitializer, name } = ctx;\n\n addInitializer(function (this: This) {\n const thisRoot = this;\n\n const isPrimitive = isPrimitiveValue(this[name as Property]);\n\n const callback = typeof watchedFieldsOrCb === 'function' ? watchedFieldsOrCb : cb!;\n const fields = Array.isArray(watchedFieldsOrCb) ? watchedFieldsOrCb : null;\n\n if (isPrimitive) {\n let value = this[name as Property];\n\n Object.defineProperty(this, name, {\n get() {\n return value;\n },\n set(newValue) {\n const oldValue = value;\n\n value = newValue;\n\n if (oldValue !== newValue) {\n callback.call(thisRoot, name, newValue);\n }\n },\n enumerable: true,\n configurable: true,\n });\n } else {\n // @ts-ignore\n this[name] = new Proxy(this[name], {\n set(target, p, newValue) {\n target[p] = newValue;\n\n if (fields?.length === 0 || fields?.includes(p as keyof This[Property])) {\n callback.call(thisRoot, p, newValue);\n }\n\n return true;\n },\n });\n }\n });\n };\n}\n\nexport default reactive;\n"],"mappings":";;;;;;AAgBA,MAAMA,gBAAgB,GAAIC,KAAc,IAAKA,KAAK,KAAKC,MAAM,CAACD,KAAK,CAAC;AAapE,SAASE,QAAQA,CAGfC,iBAA+D,EAAEC,EAAmB,EAAE;EACtF,OAAO,UAAUC,CAAY,EAAEC,GAAqD,EAAE;IACpF,MAAM;MAAEC,cAAc;MAAEC;IAAK,CAAC,GAAGF,GAAG;IAEpCC,cAAc,CAAC,YAAsB;MACnC,MAAME,QAAQ,GAAG,IAAI;MAErB,MAAMC,WAAW,GAAGX,gBAAgB,CAAC,IAAI,CAACS,IAAI,CAAa,CAAC;MAE5D,MAAMG,QAAQ,GAAG,OAAOR,iBAAiB,KAAK,UAAU,GAAGA,iBAAiB,GAAGC,EAAG;MAClF,MAAMQ,MAAM,GAAGC,KAAK,CAACC,OAAO,CAACX,iBAAiB,CAAC,GAAGA,iBAAiB,GAAG,IAAI;MAE1E,IAAIO,WAAW,EAAE;QACf,IAAIV,KAAK,GAAG,IAAI,CAACQ,IAAI,CAAa;QAElCP,MAAM,CAACc,cAAc,CAAC,IAAI,EAAEP,IAAI,EAAE;UAChCQ,GAAGA,CAAA,EAAG;YACJ,OAAOhB,KAAK;UACd,CAAC;UACDiB,GAAGA,CAACC,QAAQ,EAAE;YACZ,MAAMC,QAAQ,GAAGnB,KAAK;YAEtBA,KAAK,GAAGkB,QAAQ;YAEhB,IAAIC,QAAQ,KAAKD,QAAQ,EAAE;cACzBP,QAAQ,CAACS,IAAI,CAACX,QAAQ,EAAED,IAAI,EAAEU,QAAQ,CAAC;YACzC;UACF,CAAC;UACDG,UAAU,EAAE,IAAI;UAChBC,YAAY,EAAE;QAChB,CAAC,CAAC;MACJ,CAAC,MAAM;QACL;QACA,IAAI,CAACd,IAAI,CAAC,GAAG,IAAIe,KAAK,CAAC,IAAI,CAACf,IAAI,CAAC,EAAE;UACjCS,GAAGA,CAACO,MAAM,EAAEC,CAAC,EAAEP,QAAQ,EAAE;YACvBM,MAAM,CAACC,CAAC,CAAC,GAAGP,QAAQ;YAEpB,IAAIN,MAAM,EAAEc,MAAM,KAAK,CAAC,IAAId,MAAM,EAAEe,QAAQ,CAACF,CAAyB,CAAC,EAAE;cACvEd,QAAQ,CAACS,IAAI,CAACX,QAAQ,EAAEgB,CAAC,EAAEP,QAAQ,CAAC;YACtC;YAEA,OAAO,IAAI;UACb;QACF,CAAC,CAAC;MACJ;IACF,CAAC,CAAC;EACJ,CAAC;AACH;AAAC,IAAAU,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEc5B,QAAQ","ignoreList":[]}
@@ -0,0 +1,45 @@
1
+ const isPrimitiveValue = value => value !== Object(value);
2
+ function reactive(watchedFieldsOrCb, cb) {
3
+ return function (_, ctx) {
4
+ const {
5
+ addInitializer,
6
+ name
7
+ } = ctx;
8
+ addInitializer(function () {
9
+ const thisRoot = this;
10
+ const isPrimitive = isPrimitiveValue(this[name]);
11
+ const callback = typeof watchedFieldsOrCb === 'function' ? watchedFieldsOrCb : cb;
12
+ const fields = Array.isArray(watchedFieldsOrCb) ? watchedFieldsOrCb : null;
13
+ if (isPrimitive) {
14
+ let value = this[name];
15
+ Object.defineProperty(this, name, {
16
+ get() {
17
+ return value;
18
+ },
19
+ set(newValue) {
20
+ const oldValue = value;
21
+ value = newValue;
22
+ if (oldValue !== newValue) {
23
+ callback.call(thisRoot, name, newValue);
24
+ }
25
+ },
26
+ enumerable: true,
27
+ configurable: true
28
+ });
29
+ } else {
30
+ // @ts-ignore
31
+ this[name] = new Proxy(this[name], {
32
+ set(target, p, newValue) {
33
+ target[p] = newValue;
34
+ if (fields?.length === 0 || fields?.includes(p)) {
35
+ callback.call(thisRoot, p, newValue);
36
+ }
37
+ return true;
38
+ }
39
+ });
40
+ }
41
+ });
42
+ };
43
+ }
44
+ export default reactive;
45
+ //# sourceMappingURL=reactive.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactive.mjs","names":["isPrimitiveValue","value","Object","reactive","watchedFieldsOrCb","cb","_","ctx","addInitializer","name","thisRoot","isPrimitive","callback","fields","Array","isArray","defineProperty","get","set","newValue","oldValue","call","enumerable","configurable","Proxy","target","p","length","includes"],"sources":["../../src/decorators/reactive.ts"],"sourcesContent":["type Primitive = string | number | boolean | symbol | bigint | null | undefined;\ntype IsReadonly<This, Property extends keyof This> =\n (<F>() => F extends { [P in Property]: This[Property] } ? 1 : 2) extends\n (<F>() => F extends { -readonly [P in Property]: This[Property] } ? 1 : 2)\n ? false\n : true;\ntype Callback<This> = (this: This, field: string | symbol, newValue: unknown) => void;\ntype ReturnType<\n This,\n Property extends keyof This = keyof This,\n> = IsReadonly<This, Property> extends true\n ? (_: undefined, ctx: ClassFieldDecoratorContext<This, This[Property]>) => void\n : This[Property] extends Primitive\n ? (_: undefined, ctx: ClassFieldDecoratorContext<This, This[Property]>) => void\n : never;\n\nconst isPrimitiveValue = (value: unknown) => value !== Object(value);\n\nfunction reactive<\n This,\n Property extends keyof This,\n Value = This[Property],\n>(cb: Value extends Primitive ? Callback<This> : never): ReturnType<This>;\nfunction reactive<\n This,\n Property extends keyof This,\n Value = This[Property],\n>(watchedFields: Value extends Primitive ? never : Array<keyof Value>, cb: Callback<This>): ReturnType<This>;\n\nfunction reactive<\n This,\n Property extends keyof This,\n>(watchedFieldsOrCb: Array<keyof This[Property]> | Callback<This>, cb?: Callback<This>) {\n return function (_: undefined, ctx: ClassFieldDecoratorContext<This, This[Property]>) {\n const { addInitializer, name } = ctx;\n\n addInitializer(function (this: This) {\n const thisRoot = this;\n\n const isPrimitive = isPrimitiveValue(this[name as Property]);\n\n const callback = typeof watchedFieldsOrCb === 'function' ? watchedFieldsOrCb : cb!;\n const fields = Array.isArray(watchedFieldsOrCb) ? watchedFieldsOrCb : null;\n\n if (isPrimitive) {\n let value = this[name as Property];\n\n Object.defineProperty(this, name, {\n get() {\n return value;\n },\n set(newValue) {\n const oldValue = value;\n\n value = newValue;\n\n if (oldValue !== newValue) {\n callback.call(thisRoot, name, newValue);\n }\n },\n enumerable: true,\n configurable: true,\n });\n } else {\n // @ts-ignore\n this[name] = new Proxy(this[name], {\n set(target, p, newValue) {\n target[p] = newValue;\n\n if (fields?.length === 0 || fields?.includes(p as keyof This[Property])) {\n callback.call(thisRoot, p, newValue);\n }\n\n return true;\n },\n });\n }\n });\n };\n}\n\nexport default reactive;\n"],"mappings":"AAgBA,MAAMA,gBAAgB,GAAIC,KAAc,IAAKA,KAAK,KAAKC,MAAM,CAACD,KAAK,CAAC;AAapE,SAASE,QAAQA,CAGfC,iBAA+D,EAAEC,EAAmB,EAAE;EACtF,OAAO,UAAUC,CAAY,EAAEC,GAAqD,EAAE;IACpF,MAAM;MAAEC,cAAc;MAAEC;IAAK,CAAC,GAAGF,GAAG;IAEpCC,cAAc,CAAC,YAAsB;MACnC,MAAME,QAAQ,GAAG,IAAI;MAErB,MAAMC,WAAW,GAAGX,gBAAgB,CAAC,IAAI,CAACS,IAAI,CAAa,CAAC;MAE5D,MAAMG,QAAQ,GAAG,OAAOR,iBAAiB,KAAK,UAAU,GAAGA,iBAAiB,GAAGC,EAAG;MAClF,MAAMQ,MAAM,GAAGC,KAAK,CAACC,OAAO,CAACX,iBAAiB,CAAC,GAAGA,iBAAiB,GAAG,IAAI;MAE1E,IAAIO,WAAW,EAAE;QACf,IAAIV,KAAK,GAAG,IAAI,CAACQ,IAAI,CAAa;QAElCP,MAAM,CAACc,cAAc,CAAC,IAAI,EAAEP,IAAI,EAAE;UAChCQ,GAAGA,CAAA,EAAG;YACJ,OAAOhB,KAAK;UACd,CAAC;UACDiB,GAAGA,CAACC,QAAQ,EAAE;YACZ,MAAMC,QAAQ,GAAGnB,KAAK;YAEtBA,KAAK,GAAGkB,QAAQ;YAEhB,IAAIC,QAAQ,KAAKD,QAAQ,EAAE;cACzBP,QAAQ,CAACS,IAAI,CAACX,QAAQ,EAAED,IAAI,EAAEU,QAAQ,CAAC;YACzC;UACF,CAAC;UACDG,UAAU,EAAE,IAAI;UAChBC,YAAY,EAAE;QAChB,CAAC,CAAC;MACJ,CAAC,MAAM;QACL;QACA,IAAI,CAACd,IAAI,CAAC,GAAG,IAAIe,KAAK,CAAC,IAAI,CAACf,IAAI,CAAC,EAAE;UACjCS,GAAGA,CAACO,MAAM,EAAEC,CAAC,EAAEP,QAAQ,EAAE;YACvBM,MAAM,CAACC,CAAC,CAAC,GAAGP,QAAQ;YAEpB,IAAIN,MAAM,EAAEc,MAAM,KAAK,CAAC,IAAId,MAAM,EAAEe,QAAQ,CAACF,CAAyB,CAAC,EAAE;cACvEd,QAAQ,CAACS,IAAI,CAACX,QAAQ,EAAEgB,CAAC,EAAEP,QAAQ,CAAC;YACtC;YAEA,OAAO,IAAI;UACb;QACF,CAAC,CAAC;MACJ;IACF,CAAC,CAAC;EACJ,CAAC;AACH;AAEA,eAAehB,QAAQ","ignoreList":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@semcore/core",
3
3
  "description": "Semrush Core Component",
4
- "version": "17.0.0-prerelease.17",
4
+ "version": "17.0.0-prerelease.19",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.mjs",
7
7
  "typings": "lib/index.d.ts",
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "extends": "../../tsconfig.json",
3
- "include": ["src/utils"]
3
+ "include": ["src/utils", "src/decorators"]
4
4
  }