@decohere/core 0.0.1-dev.126 → 0.0.1-dev.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/package.json +40 -15
- package/src/caching/cache-manager.ts +102 -0
- package/src/caching/cache.decorator.ts +56 -0
- package/src/caching/cache.ts +11 -0
- package/{es6/src/caching/index.js → src/caching/index.ts} +1 -1
- package/src/caching/invalidate-cache.decorator.ts +81 -0
- package/src/caching/memoize.decorator.ts +34 -0
- package/src/caching/node-cache-memoize.adapter.ts +47 -0
- package/src/cli/action.ts +77 -0
- package/src/cli/command.ts +173 -0
- package/src/cli/index.ts +30 -0
- package/src/cli/module.type.ts +48 -0
- package/src/cli/options.ts +81 -0
- package/src/collections/find-duplicates.ts +16 -0
- package/src/collections/merge-arrays.ts +9 -0
- package/src/collections/sum.ts +71 -0
- package/src/collections/unique-objects.ts +23 -0
- package/src/composition/index.ts +48 -0
- package/src/configuration/configuration.types.ts +13 -0
- package/src/diagnostics/index.ts +1 -0
- package/src/diagnostics/trace.ts +97 -0
- package/{es6/src/extensibility/decorator-factory-base.js → src/extensibility/decorator-factory-base.ts} +17 -9
- package/src/extensibility/decorator-factory.ts +44 -0
- package/src/extensibility/extension.ts +34 -0
- package/src/extensibility/mixwith.ts +42 -0
- package/src/extensibility/pipeline.ts +60 -0
- package/{types/src/extensibility/step.d.ts → src/extensibility/step.ts} +6 -4
- package/src/interop/docker/docker.ts +57 -0
- package/src/interop/errors/interop.error.ts +1 -0
- package/src/interop/git/git.ts +98 -0
- package/src/interop/git/git.types.ts +17 -0
- package/src/interop/index.ts +22 -0
- package/src/interop/node/index.ts +1 -0
- package/src/interop/node/node.ts +38 -0
- package/src/interop/npm/npm.ts +168 -0
- package/src/interop/npm/npm.types.ts +28 -0
- package/src/interop/pnpm/pnpm.ts +22 -0
- package/src/interop/pnpm/pnpm.types.ts +3 -0
- package/src/interop/shell/shell.argv.ts +31 -0
- package/src/interop/shell/shell.ts +100 -0
- package/src/interop/shell/shell.types.ts +9 -0
- package/src/interop/types/detect-package-manager.ts +45 -0
- package/src/interop/types/package-manager.ts +7 -0
- package/src/interop/yarn/yarn.ts +28 -0
- package/src/interop/yarn/yarn.types.ts +3 -0
- package/src/io/copy-file.ts +13 -0
- package/src/io/delete-file.ts +4 -0
- package/src/io/directory-exists.ts +9 -0
- package/src/io/file-exists.ts +10 -0
- package/src/io/find-directories.ts +13 -0
- package/src/io/find-file.ts +37 -0
- package/{es6/src/io/io.js → src/io/io.ts} +3 -0
- package/src/io/read-file.ts +25 -0
- package/src/io/remove-dir.ts +11 -0
- package/src/io/types/directory.type.ts +4 -0
- package/src/io/types/file.ts +34 -0
- package/src/io/url-to-path.ts +17 -0
- package/src/io/watch.ts +290 -0
- package/src/io/write-file.ts +21 -0
- package/src/objects/deep-merge.ts +131 -0
- package/{es6/src/reflection/index.js → src/reflection/index.ts} +1 -0
- package/src/reflection/types/reflection.types.ts +28 -0
- package/src/reflection/utilities.ts +92 -0
- package/src/semver/index.ts +1 -0
- package/src/semver/semver.ts +96 -0
- package/src/system/camel-case.ts +3 -0
- package/src/system/debounce.ts +13 -0
- package/src/system/decorator.ts +41 -0
- package/src/system/environment.ts +6 -0
- package/{types/src/system/function.types.d.ts → src/system/function.types.ts} +10 -2
- package/src/system/retry.decorator.ts +43 -0
- package/src/system/sleep.ts +6 -0
- package/src/system/type.utils.ts +5 -0
- package/src/testing/flush-promises.ts +7 -0
- package/src/testing/glob-with-memfs.ts +25 -0
- package/src/testing/index.ts +5 -0
- package/src/testing/memfs.ts +28 -0
- package/src/testing/mock-logger.ts +42 -0
- package/src/testing/spy-on-constructor.ts +33 -0
- package/tests/caching/cache-manager.spec.ts +147 -0
- package/tests/caching/cache-test-class.ts +91 -0
- package/tests/caching/cache.decorator.spec.ts +259 -0
- package/tests/caching/invalidate-cache-test-class.ts +52 -0
- package/tests/caching/invalidate-cache.decorator.spec.ts +120 -0
- package/tests/caching/memoize-test-class.ts +99 -0
- package/tests/caching/memoize.decorator.spec.ts +203 -0
- package/tests/cli/command.model.spec.ts +91 -0
- package/tests/collections/merge-arrays.spec.ts +50 -0
- package/tests/collections/sum.spec.ts +86 -0
- package/tests/collections/unique-objects.spec.ts +233 -0
- package/tests/extensibility/extension.spec.ts +29 -0
- package/tests/extensibility/pipeline.spec.ts +379 -0
- package/tests/interop/detect-package-manager.spec.ts +70 -0
- package/tests/interop/npm.spec.ts +129 -0
- package/tests/interop/pnpm.spec.ts +30 -0
- package/tests/interop/shell.spec.ts +47 -0
- package/tests/interop/yarn.spec.ts +18 -0
- package/tests/io/find-file.spec.ts +188 -0
- package/tests/io/watch.real-fs.spec.ts +76 -0
- package/tests/io/watch.spec.ts +291 -0
- package/tests/mock-prototype.ts +12 -0
- package/tests/semver/semver.spec.ts +51 -0
- package/tests/system/decorator.spec.ts +250 -0
- package/tests/system/retry.decorator.spec.ts +57 -0
- package/LICENSE +0 -15
- package/commonjs/src/caching/cache-manager.js +0 -98
- package/commonjs/src/caching/cache.decorator.js +0 -69
- package/commonjs/src/caching/cache.js +0 -6
- package/commonjs/src/caching/index.js +0 -23
- package/commonjs/src/caching/invalidate-cache.decorator.js +0 -92
- package/commonjs/src/caching/map-cache.js +0 -39
- package/commonjs/src/caching/memoize.decorator.js +0 -36
- package/commonjs/src/collections/collections.js +0 -21
- package/commonjs/src/collections/find-duplicates.js +0 -35
- package/commonjs/src/collections/index.js +0 -52
- package/commonjs/src/collections/merge-arrays.js +0 -34
- package/commonjs/src/collections/sum.js +0 -63
- package/commonjs/src/collections/unique-objects.js +0 -39
- package/commonjs/src/composition/index.js +0 -4
- package/commonjs/src/configuration/configuration.types.js +0 -11
- package/commonjs/src/configuration/index.js +0 -18
- package/commonjs/src/extensibility/decorator-factory-base.js +0 -22
- package/commonjs/src/extensibility/decorator-factory.js +0 -31
- package/commonjs/src/extensibility/extension.js +0 -37
- package/commonjs/src/extensibility/index.js +0 -23
- package/commonjs/src/extensibility/mixwith.js +0 -36
- package/commonjs/src/extensibility/pipeline.js +0 -56
- package/commonjs/src/extensibility/step.js +0 -18
- package/commonjs/src/io/copy-file.js +0 -25
- package/commonjs/src/io/delete-file.js +0 -21
- package/commonjs/src/io/directory-exists.js +0 -24
- package/commonjs/src/io/file-exists.js +0 -19
- package/commonjs/src/io/index.js +0 -66
- package/commonjs/src/io/io.js +0 -25
- package/commonjs/src/io/read-file.js +0 -39
- package/commonjs/src/io/remove-dir.js +0 -22
- package/commonjs/src/io/types/directory.type.js +0 -4
- package/commonjs/src/io/types/file.js +0 -28
- package/commonjs/src/io/types/index.js +0 -19
- package/commonjs/src/io/url-to-path.js +0 -33
- package/commonjs/src/io/write-file.js +0 -30
- package/commonjs/src/objects/deep-merge.js +0 -67
- package/commonjs/src/objects/index.js +0 -11
- package/commonjs/src/reflection/index.js +0 -20
- package/commonjs/src/reflection/types/index.js +0 -18
- package/commonjs/src/reflection/types/reflection.types.js +0 -26
- package/commonjs/src/reflection/utilities.js +0 -118
- package/commonjs/src/system/camel-case.js +0 -13
- package/commonjs/src/system/debounce.js +0 -19
- package/commonjs/src/system/decorator.js +0 -46
- package/commonjs/src/system/environment.js +0 -23
- package/commonjs/src/system/function.types.js +0 -18
- package/commonjs/src/system/index.js +0 -24
- package/commonjs/src/system/retry.decorator.js +0 -40
- package/commonjs/src/system/sleep.js +0 -13
- package/commonjs/src/system/type.utils.js +0 -4
- package/es6/src/caching/cache-manager.js +0 -82
- package/es6/src/caching/cache.decorator.js +0 -51
- package/es6/src/caching/cache.js +0 -3
- package/es6/src/caching/invalidate-cache.decorator.js +0 -71
- package/es6/src/caching/map-cache.js +0 -35
- package/es6/src/caching/memoize.decorator.js +0 -27
- package/es6/src/collections/find-duplicates.js +0 -17
- package/es6/src/collections/merge-arrays.js +0 -16
- package/es6/src/collections/sum.js +0 -45
- package/es6/src/collections/unique-objects.js +0 -21
- package/es6/src/composition/index.js +0 -1
- package/es6/src/configuration/configuration.types.js +0 -1
- package/es6/src/extensibility/decorator-factory.js +0 -21
- package/es6/src/extensibility/extension.js +0 -27
- package/es6/src/extensibility/mixwith.js +0 -26
- package/es6/src/extensibility/pipeline.js +0 -46
- package/es6/src/extensibility/step.js +0 -16
- package/es6/src/io/copy-file.js +0 -10
- package/es6/src/io/delete-file.js +0 -6
- package/es6/src/io/directory-exists.js +0 -9
- package/es6/src/io/file-exists.js +0 -9
- package/es6/src/io/read-file.js +0 -13
- package/es6/src/io/remove-dir.js +0 -7
- package/es6/src/io/types/directory.type.js +0 -1
- package/es6/src/io/types/file.js +0 -18
- package/es6/src/io/url-to-path.js +0 -15
- package/es6/src/io/write-file.js +0 -15
- package/es6/src/objects/deep-merge.js +0 -57
- package/es6/src/reflection/types/reflection.types.js +0 -8
- package/es6/src/reflection/utilities.js +0 -74
- package/es6/src/system/camel-case.js +0 -3
- package/es6/src/system/debounce.js +0 -9
- package/es6/src/system/decorator.js +0 -30
- package/es6/src/system/environment.js +0 -5
- package/es6/src/system/function.types.js +0 -26
- package/es6/src/system/retry.decorator.js +0 -30
- package/es6/src/system/sleep.js +0 -3
- package/es6/src/system/type.utils.js +0 -1
- package/types/src/caching/cache-manager.d.ts +0 -59
- package/types/src/caching/cache.d.ts +0 -11
- package/types/src/caching/cache.decorator.d.ts +0 -18
- package/types/src/caching/index.d.ts +0 -6
- package/types/src/caching/invalidate-cache.decorator.d.ts +0 -17
- package/types/src/caching/map-cache.d.ts +0 -23
- package/types/src/caching/memoize.decorator.d.ts +0 -16
- package/types/src/collections/collections.d.ts +0 -4
- package/types/src/collections/find-duplicates.d.ts +0 -2
- package/types/src/collections/index.d.ts +0 -1
- package/types/src/collections/merge-arrays.d.ts +0 -2
- package/types/src/collections/sum.d.ts +0 -4
- package/types/src/collections/unique-objects.d.ts +0 -2
- package/types/src/composition/index.d.ts +0 -37
- package/types/src/configuration/configuration.types.d.ts +0 -10
- package/types/src/configuration/index.d.ts +0 -1
- package/types/src/extensibility/decorator-factory-base.d.ts +0 -39
- package/types/src/extensibility/decorator-factory.d.ts +0 -19
- package/types/src/extensibility/extension.d.ts +0 -9
- package/types/src/extensibility/index.d.ts +0 -6
- package/types/src/extensibility/mixwith.d.ts +0 -6
- package/types/src/extensibility/pipeline.d.ts +0 -12
- package/types/src/io/copy-file.d.ts +0 -4
- package/types/src/io/delete-file.d.ts +0 -1
- package/types/src/io/directory-exists.d.ts +0 -1
- package/types/src/io/file-exists.d.ts +0 -1
- package/types/src/io/index.d.ts +0 -2
- package/types/src/io/io.d.ts +0 -8
- package/types/src/io/read-file.d.ts +0 -4
- package/types/src/io/remove-dir.d.ts +0 -5
- package/types/src/io/types/directory.type.d.ts +0 -4
- package/types/src/io/types/file.d.ts +0 -20
- package/types/src/io/types/index.d.ts +0 -2
- package/types/src/io/url-to-path.d.ts +0 -2
- package/types/src/io/write-file.d.ts +0 -5
- package/types/src/objects/deep-merge.d.ts +0 -41
- package/types/src/objects/index.d.ts +0 -1
- package/types/src/reflection/index.d.ts +0 -3
- package/types/src/reflection/types/index.d.ts +0 -1
- package/types/src/reflection/types/reflection.types.d.ts +0 -21
- package/types/src/reflection/utilities.d.ts +0 -27
- package/types/src/system/camel-case.d.ts +0 -1
- package/types/src/system/debounce.d.ts +0 -1
- package/types/src/system/decorator.d.ts +0 -15
- package/types/src/system/environment.d.ts +0 -6
- package/types/src/system/index.d.ts +0 -7
- package/types/src/system/retry.decorator.d.ts +0 -6
- package/types/src/system/sleep.d.ts +0 -1
- package/types/src/system/type.utils.d.ts +0 -1
- /package/{es6/src/collections/collections.js → src/collections/collections.ts} +0 -0
- /package/{es6/src/collections/index.js → src/collections/index.ts} +0 -0
- /package/{es6/src/configuration/index.js → src/configuration/index.ts} +0 -0
- /package/{es6/src/extensibility/index.js → src/extensibility/index.ts} +0 -0
- /package/{es6/src/io/index.js → src/io/index.ts} +0 -0
- /package/{es6/src/io/types/index.js → src/io/types/index.ts} +0 -0
- /package/{es6/src/objects/index.js → src/objects/index.ts} +0 -0
- /package/{es6/src/reflection/types/index.js → src/reflection/types/index.ts} +0 -0
- /package/{es6/src/system/index.js → src/system/index.ts} +0 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { FunctionDecorator, ignoreDuringUnitTest } from "../../src/system/decorator.js";
|
|
3
|
+
|
|
4
|
+
// Test decorator class
|
|
5
|
+
class TestDecorator extends FunctionDecorator {
|
|
6
|
+
@ignoreDuringUnitTest()
|
|
7
|
+
public decorator(
|
|
8
|
+
_target: object,
|
|
9
|
+
_propertyKey: string,
|
|
10
|
+
descriptor: PropertyDescriptor,
|
|
11
|
+
): PropertyDescriptor {
|
|
12
|
+
const originalMethod = descriptor.value;
|
|
13
|
+
descriptor.value = function (...args: unknown[]) {
|
|
14
|
+
// Add "decorated-" prefix to show decorator was applied
|
|
15
|
+
const result = originalMethod.apply(this, args);
|
|
16
|
+
return `decorated-${result}`;
|
|
17
|
+
};
|
|
18
|
+
return descriptor;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Another test decorator without @ignoreInUnitTest
|
|
23
|
+
class AlwaysActiveDecorator extends FunctionDecorator {
|
|
24
|
+
public decorator(_target: object, _propertyKey: string, descriptor: PropertyDescriptor) {
|
|
25
|
+
const originalMethod = descriptor.value;
|
|
26
|
+
descriptor.value = function (...args: unknown[]) {
|
|
27
|
+
const result = originalMethod.apply(this, args);
|
|
28
|
+
return `always-${result}`;
|
|
29
|
+
};
|
|
30
|
+
return descriptor;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const createTestDecorator = new TestDecorator().decoratorFactory;
|
|
35
|
+
const createAlwaysActiveDecorator = new AlwaysActiveDecorator().decoratorFactory;
|
|
36
|
+
|
|
37
|
+
describe("ignoreInUnitTest decorator", () => {
|
|
38
|
+
let originalTestEnv: string | undefined;
|
|
39
|
+
|
|
40
|
+
beforeEach(() => {
|
|
41
|
+
originalTestEnv = process.env.TEST;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
afterEach(() => {
|
|
45
|
+
if (originalTestEnv !== undefined) {
|
|
46
|
+
process.env.TEST = originalTestEnv;
|
|
47
|
+
} else {
|
|
48
|
+
delete process.env.TEST;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe("when TEST environment variable is not set", () => {
|
|
53
|
+
beforeEach(() => {
|
|
54
|
+
delete process.env.TEST;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("should apply decorator normally", () => {
|
|
58
|
+
class TestClass {
|
|
59
|
+
@createTestDecorator()
|
|
60
|
+
public getValue(): string {
|
|
61
|
+
return "original";
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const instance = new TestClass();
|
|
66
|
+
const result = instance.getValue();
|
|
67
|
+
|
|
68
|
+
expect(result).toBe("decorated-original");
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe("when TEST=false", () => {
|
|
73
|
+
beforeEach(() => {
|
|
74
|
+
process.env.TEST = "false";
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("should apply decorator normally", () => {
|
|
78
|
+
class TestClass {
|
|
79
|
+
@createTestDecorator()
|
|
80
|
+
public getValue(): string {
|
|
81
|
+
return "original";
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const instance = new TestClass();
|
|
86
|
+
const result = instance.getValue();
|
|
87
|
+
|
|
88
|
+
expect(result).toBe("decorated-original");
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe("when TEST=true", () => {
|
|
93
|
+
beforeEach(() => {
|
|
94
|
+
process.env.TEST = "true";
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("should disable decorator and return original function", () => {
|
|
98
|
+
class TestClass {
|
|
99
|
+
@createTestDecorator()
|
|
100
|
+
public getValue(): string {
|
|
101
|
+
return "original";
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const instance = new TestClass();
|
|
106
|
+
const result = instance.getValue();
|
|
107
|
+
|
|
108
|
+
expect(result).toBe("original"); // No decoration applied
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("should still apply decorators that are not marked with @ignoreInUnitTest", () => {
|
|
112
|
+
class TestClass {
|
|
113
|
+
@createAlwaysActiveDecorator()
|
|
114
|
+
public getValue(): string {
|
|
115
|
+
return "original";
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const instance = new TestClass();
|
|
120
|
+
const result = instance.getValue();
|
|
121
|
+
|
|
122
|
+
expect(result).toBe("always-original"); // Decoration still applied
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe("multiple decorators", () => {
|
|
127
|
+
it("should disable decorator when marked with @ignoreInUnitTest when TEST=true", () => {
|
|
128
|
+
process.env.TEST = "true";
|
|
129
|
+
|
|
130
|
+
class TestClass {
|
|
131
|
+
@createTestDecorator() // This will be disabled and return original function
|
|
132
|
+
public getValue(): string {
|
|
133
|
+
return "original";
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const instance = new TestClass();
|
|
138
|
+
const result = instance.getValue();
|
|
139
|
+
|
|
140
|
+
// When a decorator with @ignoreInUnitTest is disabled, it returns the original function
|
|
141
|
+
expect(result).toBe("original");
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("should work with multiple decorators where some have @ignoreInUnitTest", () => {
|
|
145
|
+
process.env.TEST = "true";
|
|
146
|
+
|
|
147
|
+
// Test with the non-ignored decorator applied first
|
|
148
|
+
class TestClass1 {
|
|
149
|
+
@createAlwaysActiveDecorator() // This will be active
|
|
150
|
+
public getValue(): string {
|
|
151
|
+
return "original";
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Test with the ignored decorator applied first
|
|
156
|
+
class TestClass2 {
|
|
157
|
+
@createTestDecorator() // This will be disabled
|
|
158
|
+
public getValue(): string {
|
|
159
|
+
return "original";
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const instance1 = new TestClass1();
|
|
164
|
+
const instance2 = new TestClass2();
|
|
165
|
+
|
|
166
|
+
expect(instance1.getValue()).toBe("always-original");
|
|
167
|
+
expect(instance2.getValue()).toBe("original");
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("should apply all decorators when TEST is not true", () => {
|
|
171
|
+
delete process.env.TEST;
|
|
172
|
+
|
|
173
|
+
class TestClass {
|
|
174
|
+
@createTestDecorator() // This will be active
|
|
175
|
+
@createAlwaysActiveDecorator() // This will be active
|
|
176
|
+
public getValue(): string {
|
|
177
|
+
return "original";
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const instance = new TestClass();
|
|
182
|
+
const result = instance.getValue();
|
|
183
|
+
|
|
184
|
+
// Both decorators should be applied (decorators apply bottom-to-top)
|
|
185
|
+
expect(result).toBe("decorated-always-original");
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
describe("FunctionDecorator base class", () => {
|
|
190
|
+
it("should bind decoratorFactory method correctly", () => {
|
|
191
|
+
const decorator = new TestDecorator();
|
|
192
|
+
const factory = decorator.decoratorFactory;
|
|
193
|
+
|
|
194
|
+
expect(typeof factory).toBe("function");
|
|
195
|
+
expect(factory).toBe(decorator.decoratorFactory);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("should return the decorator method from decoratorFactory", () => {
|
|
199
|
+
const decorator = new TestDecorator();
|
|
200
|
+
const factory = decorator.decoratorFactory();
|
|
201
|
+
|
|
202
|
+
expect(typeof factory).toBe("function");
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
describe("ignoreDuringUnitTest function behavior", () => {
|
|
207
|
+
it("should wrap decorator methods to respect TEST environment variable", () => {
|
|
208
|
+
// Create a mock decorator method
|
|
209
|
+
const originalDecoratorMethod = vi.fn((_target, _key, descriptor) => {
|
|
210
|
+
const originalMethod = descriptor.value;
|
|
211
|
+
descriptor.value = function (...args: unknown[]) {
|
|
212
|
+
return `decorated-${originalMethod.apply(this, args)}`;
|
|
213
|
+
};
|
|
214
|
+
return descriptor;
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
const mockDescriptor = {
|
|
218
|
+
value: originalDecoratorMethod,
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
// Apply @ignoreDuringUnitTest to the decorator method
|
|
222
|
+
ignoreDuringUnitTest()({}, "testMethod", mockDescriptor);
|
|
223
|
+
|
|
224
|
+
// Create a test target and method to decorate
|
|
225
|
+
const testTarget = {};
|
|
226
|
+
const testPropertyKey = "testMethod";
|
|
227
|
+
const testMethodDescriptor = {
|
|
228
|
+
value: () => "original",
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
// When TEST is not set, should call original decorator method
|
|
232
|
+
delete process.env.TEST;
|
|
233
|
+
const result1 = mockDescriptor.value(testTarget, testPropertyKey, testMethodDescriptor);
|
|
234
|
+
expect(originalDecoratorMethod).toHaveBeenCalledWith(
|
|
235
|
+
testTarget,
|
|
236
|
+
testPropertyKey,
|
|
237
|
+
testMethodDescriptor,
|
|
238
|
+
);
|
|
239
|
+
expect(result1).toBe(testMethodDescriptor); // Original decorator modifies descriptor in place
|
|
240
|
+
|
|
241
|
+
// When TEST=true, should return descriptor unchanged (no-op behavior)
|
|
242
|
+
process.env.TEST = "true";
|
|
243
|
+
originalDecoratorMethod.mockClear();
|
|
244
|
+
const originalDescriptor = { value: () => "untouched" };
|
|
245
|
+
const result2 = mockDescriptor.value(testTarget, testPropertyKey, originalDescriptor);
|
|
246
|
+
expect(originalDecoratorMethod).not.toHaveBeenCalled();
|
|
247
|
+
expect(result2).toBe(originalDescriptor); // Should return descriptor unchanged
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { retry } from "../../src/system/retry.decorator.js";
|
|
3
|
+
|
|
4
|
+
describe("retry decorator", () => {
|
|
5
|
+
it("retries until success within attempt limit", async () => {
|
|
6
|
+
class TestClass {
|
|
7
|
+
private attempts = 0;
|
|
8
|
+
|
|
9
|
+
@retry({ attempts: 3 })
|
|
10
|
+
public async unstableOperation() {
|
|
11
|
+
this.attempts++;
|
|
12
|
+
if (this.attempts < 3) {
|
|
13
|
+
throw new Error("transient");
|
|
14
|
+
}
|
|
15
|
+
return "ok";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const instance = new TestClass();
|
|
20
|
+
await expect(instance.unstableOperation()).resolves.toBe("ok");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("throws after max attempts", async () => {
|
|
24
|
+
class TestClass {
|
|
25
|
+
@retry({ attempts: 2 })
|
|
26
|
+
public async alwaysFails() {
|
|
27
|
+
throw new Error("persistent");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const instance = new TestClass();
|
|
32
|
+
await expect(instance.alwaysFails()).rejects.toThrow("persistent");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("respects shouldRetry predicate", async () => {
|
|
36
|
+
const shouldRetry = vi.fn((error: unknown) => {
|
|
37
|
+
return (error as Error).message !== "fatal";
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
class TestClass {
|
|
41
|
+
private attempts = 0;
|
|
42
|
+
|
|
43
|
+
@retry({ attempts: 5, shouldRetry })
|
|
44
|
+
public async operation() {
|
|
45
|
+
this.attempts++;
|
|
46
|
+
if (this.attempts === 1) {
|
|
47
|
+
throw new Error("fatal");
|
|
48
|
+
}
|
|
49
|
+
return "ok";
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const instance = new TestClass();
|
|
54
|
+
await expect(instance.operation()).rejects.toThrow("fatal");
|
|
55
|
+
expect(shouldRetry).toHaveBeenCalledTimes(1);
|
|
56
|
+
});
|
|
57
|
+
});
|
package/LICENSE
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
ISC License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025-2026 Typesmiths
|
|
4
|
-
|
|
5
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
-
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
-
copyright notice and this permission notice appear in all copies.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
-
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
-
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
-
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
-
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
-
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
-
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
get Caches () {
|
|
13
|
-
return Caches;
|
|
14
|
-
},
|
|
15
|
-
get Caching () {
|
|
16
|
-
return Caching;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _mapcache = require("./map-cache.js");
|
|
20
|
-
const Caches = {
|
|
21
|
-
default: "DEFAULT",
|
|
22
|
-
memoize: "MEMOIZE_CACHE"
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Central cache manager for managing named cache instances
|
|
26
|
-
*/ class CacheManager {
|
|
27
|
-
caches = new Map();
|
|
28
|
-
defaultCacheName = Caches.default;
|
|
29
|
-
/**
|
|
30
|
-
* Set a cache instance with the given name
|
|
31
|
-
* @param name - The name of the cache
|
|
32
|
-
* @param cache - The cache instance
|
|
33
|
-
*/ setCache(name, cache) {
|
|
34
|
-
this.caches.set(name, cache);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Get a cache instance by name
|
|
38
|
-
* @param name - The name of the cache, defaults to "DEFAULT"
|
|
39
|
-
* @returns The cache instance
|
|
40
|
-
*/ getCache(name, memoize = false) {
|
|
41
|
-
const cacheName = name ?? this.defaultCacheName;
|
|
42
|
-
if (!this.caches.has(cacheName)) {
|
|
43
|
-
const cache = new _mapcache.MapCache({
|
|
44
|
-
memoize
|
|
45
|
-
});
|
|
46
|
-
this.caches.set(cacheName, cache);
|
|
47
|
-
}
|
|
48
|
-
return this.caches.get(cacheName);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Clear a cache by name. If no name is provided, clears the default cache.
|
|
52
|
-
* Note: This only works if the cache implements a clear() method.
|
|
53
|
-
* @param name - The name of the cache to clear
|
|
54
|
-
*/ flush(name) {
|
|
55
|
-
const cacheName = name ?? this.defaultCacheName;
|
|
56
|
-
const cache = this.caches.get(cacheName);
|
|
57
|
-
cache.flushAll();
|
|
58
|
-
}
|
|
59
|
-
flushAllCaches() {
|
|
60
|
-
for (const [, cache] of this.caches){
|
|
61
|
-
cache.flushAll();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Remove a cache instance by name
|
|
66
|
-
* @param name - The name of the cache to remove
|
|
67
|
-
*/ removeCache(name) {
|
|
68
|
-
this.caches.delete(name);
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Check if a cache with the given name exists
|
|
72
|
-
* @param name - The name of the cache
|
|
73
|
-
* @returns True if the cache exists, false otherwise
|
|
74
|
-
*/ hasCache(name) {
|
|
75
|
-
return this.caches.has(name);
|
|
76
|
-
}
|
|
77
|
-
instanceIds = new WeakMap();
|
|
78
|
-
instanceIdCounter = 0;
|
|
79
|
-
/**
|
|
80
|
-
* Generate a cache key for a given instance, function name, and arguments.
|
|
81
|
-
* Each instance receives a stable numeric ID so cache entries are never
|
|
82
|
-
* shared across instances of the same class.
|
|
83
|
-
* @param instance - The class instance (`this` at call time)
|
|
84
|
-
* @param functionName - The name of the decorated method
|
|
85
|
-
* @param args - The method arguments
|
|
86
|
-
* @returns A unique cache key string
|
|
87
|
-
*/ generateCacheKey(instance, functionName, args) {
|
|
88
|
-
if (!this.instanceIds.has(instance)) {
|
|
89
|
-
this.instanceIds.set(instance, ++this.instanceIdCounter);
|
|
90
|
-
}
|
|
91
|
-
const instanceId = this.instanceIds.get(instance);
|
|
92
|
-
const argsStr = JSON.stringify({
|
|
93
|
-
args
|
|
94
|
-
}, (_key, val)=>typeof val === "function" ? `[Function:${val.name}]` : val);
|
|
95
|
-
return `${instance.constructor.name}#${instanceId}|${functionName}|${argsStr}`;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
const Caching = new CacheManager();
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
get CacheDecorator () {
|
|
13
|
-
return CacheDecorator;
|
|
14
|
-
},
|
|
15
|
-
get cache () {
|
|
16
|
-
return cache;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _types = require("node:util/types");
|
|
20
|
-
const _decorator = require("../system/decorator.js");
|
|
21
|
-
const _cachemanager = require("./cache-manager.js");
|
|
22
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
23
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
24
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
25
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
26
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
27
|
-
}
|
|
28
|
-
function _ts_metadata(k, v) {
|
|
29
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
30
|
-
}
|
|
31
|
-
class CacheDecorator extends _decorator.FunctionDecorator {
|
|
32
|
-
decorator(_target, propertyKey, descriptor) {
|
|
33
|
-
const cacheInstance = this.options?.cache ?? _cachemanager.Caching.getCache(this.options?.name);
|
|
34
|
-
const keyFn = this.options?.keyFn;
|
|
35
|
-
const originalMethod = descriptor.value;
|
|
36
|
-
const wrapped = function(...args) {
|
|
37
|
-
const cacheKey = keyFn ? keyFn(...args) : _cachemanager.Caching.generateCacheKey(this, propertyKey, args);
|
|
38
|
-
if (cacheInstance.has(cacheKey)) {
|
|
39
|
-
const val = cacheInstance.get(cacheKey);
|
|
40
|
-
return val;
|
|
41
|
-
}
|
|
42
|
-
const resultOrPromise = originalMethod.apply(this, args);
|
|
43
|
-
if ((0, _types.isPromise)(resultOrPromise)) {
|
|
44
|
-
resultOrPromise.then((result)=>{
|
|
45
|
-
cacheInstance.set(cacheKey, result);
|
|
46
|
-
}, ()=>{
|
|
47
|
-
/* rejection propagates via the returned promise */ });
|
|
48
|
-
} else {
|
|
49
|
-
cacheInstance.set(cacheKey, resultOrPromise);
|
|
50
|
-
}
|
|
51
|
-
return resultOrPromise;
|
|
52
|
-
};
|
|
53
|
-
Object.defineProperty(wrapped, "name", {
|
|
54
|
-
value: propertyKey
|
|
55
|
-
});
|
|
56
|
-
descriptor.value = wrapped;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
_ts_decorate([
|
|
60
|
-
(0, _decorator.ignoreIf)("FORGE_DISABLE_CACHE"),
|
|
61
|
-
_ts_metadata("design:type", Function),
|
|
62
|
-
_ts_metadata("design:paramtypes", [
|
|
63
|
-
Object,
|
|
64
|
-
String,
|
|
65
|
-
typeof PropertyDescriptor === "undefined" ? Object : PropertyDescriptor
|
|
66
|
-
]),
|
|
67
|
-
_ts_metadata("design:returntype", void 0)
|
|
68
|
-
], CacheDecorator.prototype, "decorator", null);
|
|
69
|
-
const cache = new CacheDecorator().decoratorFactory;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
_export_star(require("./cache.decorator.js"), exports);
|
|
6
|
-
_export_star(require("./cache.js"), exports);
|
|
7
|
-
_export_star(require("./cache-manager.js"), exports);
|
|
8
|
-
_export_star(require("./invalidate-cache.decorator.js"), exports);
|
|
9
|
-
_export_star(require("./memoize.decorator.js"), exports);
|
|
10
|
-
_export_star(require("./map-cache.js"), exports);
|
|
11
|
-
function _export_star(from, to) {
|
|
12
|
-
Object.keys(from).forEach(function(k) {
|
|
13
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
14
|
-
Object.defineProperty(to, k, {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: function() {
|
|
17
|
-
return from[k];
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
return from;
|
|
23
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
get InvalidateCacheDecorator () {
|
|
13
|
-
return InvalidateCacheDecorator;
|
|
14
|
-
},
|
|
15
|
-
get invalidateCache () {
|
|
16
|
-
return invalidateCache;
|
|
17
|
-
},
|
|
18
|
-
get invalidateMemoize () {
|
|
19
|
-
return invalidateMemoize;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
const _types = require("node:util/types");
|
|
23
|
-
const _decorator = require("../system/decorator.js");
|
|
24
|
-
const _cachemanager = require("./cache-manager.js");
|
|
25
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
26
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
27
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
28
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
29
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
30
|
-
}
|
|
31
|
-
function _ts_metadata(k, v) {
|
|
32
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
33
|
-
}
|
|
34
|
-
class InvalidateCacheDecorator extends _decorator.FunctionDecorator {
|
|
35
|
-
decorator(_target, _propertyKey, descriptor) {
|
|
36
|
-
const { getKey, cache, name } = this.options;
|
|
37
|
-
const cacheInstance = cache ?? _cachemanager.Caching.getCache(name);
|
|
38
|
-
const originalMethod = descriptor.value;
|
|
39
|
-
descriptor.value = function(...args) {
|
|
40
|
-
const resultOrPromise = originalMethod.apply(this, args);
|
|
41
|
-
const evict = ()=>{
|
|
42
|
-
const key = getKey(this, args);
|
|
43
|
-
cacheInstance.del(key);
|
|
44
|
-
};
|
|
45
|
-
if ((0, _types.isPromise)(resultOrPromise)) {
|
|
46
|
-
resultOrPromise.then(evict);
|
|
47
|
-
} else {
|
|
48
|
-
evict();
|
|
49
|
-
}
|
|
50
|
-
return resultOrPromise;
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
_ts_decorate([
|
|
55
|
-
(0, _decorator.ignoreIf)("FORGE_DISABLE_CACHE"),
|
|
56
|
-
_ts_metadata("design:type", Function),
|
|
57
|
-
_ts_metadata("design:paramtypes", [
|
|
58
|
-
Object,
|
|
59
|
-
String,
|
|
60
|
-
typeof PropertyDescriptor === "undefined" ? Object : PropertyDescriptor
|
|
61
|
-
]),
|
|
62
|
-
_ts_metadata("design:returntype", void 0)
|
|
63
|
-
], InvalidateCacheDecorator.prototype, "decorator", null);
|
|
64
|
-
const buildGetKey = (method, keyFn)=>{
|
|
65
|
-
if (typeof method === "string") return ()=>method;
|
|
66
|
-
if (keyFn) return (_instance, args)=>keyFn(...args);
|
|
67
|
-
return (instance, args)=>_cachemanager.Caching.generateCacheKey(instance, method.name, args);
|
|
68
|
-
};
|
|
69
|
-
const invalidateCache = (method, options)=>{
|
|
70
|
-
const cache = options?.cache ?? _cachemanager.Caching.getCache(options?.name);
|
|
71
|
-
return new InvalidateCacheDecorator().decoratorFactory({
|
|
72
|
-
getKey: buildGetKey(method, options?.keyFn),
|
|
73
|
-
...options,
|
|
74
|
-
cache
|
|
75
|
-
});
|
|
76
|
-
};
|
|
77
|
-
invalidateCache.evict = (instance, method, args = [])=>{
|
|
78
|
-
const key = _cachemanager.Caching.generateCacheKey(instance, method.name, args);
|
|
79
|
-
_cachemanager.Caching.getCache().del(key);
|
|
80
|
-
};
|
|
81
|
-
const invalidateMemoize = (method, options)=>{
|
|
82
|
-
const cache = options?.cache ?? _cachemanager.Caching.getCache(options?.name ?? _cachemanager.Caches.memoize, true);
|
|
83
|
-
return new InvalidateCacheDecorator().decoratorFactory({
|
|
84
|
-
getKey: buildGetKey(method),
|
|
85
|
-
...options,
|
|
86
|
-
cache
|
|
87
|
-
});
|
|
88
|
-
};
|
|
89
|
-
invalidateMemoize.evict = (instance, method, args = [])=>{
|
|
90
|
-
const key = _cachemanager.Caching.generateCacheKey(instance, method.name, args);
|
|
91
|
-
_cachemanager.Caching.getCache(_cachemanager.Caches.memoize, true).del(key);
|
|
92
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "MapCache", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return MapCache;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
class MapCache {
|
|
12
|
-
#entries = new Map();
|
|
13
|
-
#memoize;
|
|
14
|
-
constructor(options = {}){
|
|
15
|
-
this.#memoize = options.memoize ?? false;
|
|
16
|
-
}
|
|
17
|
-
get isMemoize() {
|
|
18
|
-
return this.#memoize;
|
|
19
|
-
}
|
|
20
|
-
get(key) {
|
|
21
|
-
const value = this.#entries.get(key);
|
|
22
|
-
if (this.#memoize || value === null || typeof value !== "object") {
|
|
23
|
-
return value;
|
|
24
|
-
}
|
|
25
|
-
return structuredClone(value);
|
|
26
|
-
}
|
|
27
|
-
set(key, value) {
|
|
28
|
-
this.#entries.set(key, value);
|
|
29
|
-
}
|
|
30
|
-
has(key) {
|
|
31
|
-
return this.#entries.has(key);
|
|
32
|
-
}
|
|
33
|
-
del(key) {
|
|
34
|
-
this.#entries.delete(key);
|
|
35
|
-
}
|
|
36
|
-
flushAll() {
|
|
37
|
-
this.#entries.clear();
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
get MemoizeDecorator () {
|
|
13
|
-
return MemoizeDecorator;
|
|
14
|
-
},
|
|
15
|
-
get memoize () {
|
|
16
|
-
return memoize;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _cachedecorator = require("./cache.decorator.js");
|
|
20
|
-
const _cachemanager = require("./cache-manager.js");
|
|
21
|
-
class MemoizeDecorator extends _cachedecorator.CacheDecorator {
|
|
22
|
-
decorator(target, propertyKey, descriptor) {
|
|
23
|
-
const cache = this.options?.cache ?? _cachemanager.Caching.getCache(this.options?.name ?? _cachemanager.Caches.memoize, true);
|
|
24
|
-
if (!cache.isMemoize) {
|
|
25
|
-
throw new Error("Memoize decorator requires a cache that supports memoization (stores references, not clones)");
|
|
26
|
-
}
|
|
27
|
-
// Pass the resolved cache to the base class by updating options
|
|
28
|
-
// This ensures the base class uses CacheNames.memoize when no cache was provided
|
|
29
|
-
this.options = {
|
|
30
|
-
...this.options,
|
|
31
|
-
cache
|
|
32
|
-
};
|
|
33
|
-
return super.decorator(target, propertyKey, descriptor);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
const memoize = new MemoizeDecorator().decoratorFactory;
|