@decohere/core 0.0.1-dev.116
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/commonjs/src/caching/cache-manager.js +98 -0
- package/commonjs/src/caching/cache.decorator.js +69 -0
- package/commonjs/src/caching/cache.js +6 -0
- package/commonjs/src/caching/index.js +23 -0
- package/commonjs/src/caching/invalidate-cache.decorator.js +92 -0
- package/commonjs/src/caching/memoize.decorator.js +36 -0
- package/commonjs/src/caching/node-cache-memoize.adapter.js +49 -0
- package/commonjs/src/cli/action.js +65 -0
- package/commonjs/src/cli/command.js +127 -0
- package/commonjs/src/cli/index.js +61 -0
- package/commonjs/src/cli/module.type.js +18 -0
- package/commonjs/src/cli/options.js +115 -0
- package/commonjs/src/collections/collections.js +21 -0
- package/commonjs/src/collections/find-duplicates.js +35 -0
- package/commonjs/src/collections/index.js +52 -0
- package/commonjs/src/collections/merge-arrays.js +34 -0
- package/commonjs/src/collections/sum.js +63 -0
- package/commonjs/src/collections/unique-objects.js +39 -0
- package/commonjs/src/composition/index.js +4 -0
- package/commonjs/src/configuration/configuration.types.js +11 -0
- package/commonjs/src/configuration/index.js +18 -0
- package/commonjs/src/diagnostics/index.js +22 -0
- package/commonjs/src/diagnostics/trace.js +86 -0
- package/commonjs/src/extensibility/decorator-factory-base.js +22 -0
- package/commonjs/src/extensibility/decorator-factory.js +31 -0
- package/commonjs/src/extensibility/extension.js +37 -0
- package/commonjs/src/extensibility/index.js +23 -0
- package/commonjs/src/extensibility/mixwith.js +36 -0
- package/commonjs/src/extensibility/pipeline.js +56 -0
- package/commonjs/src/extensibility/step.js +18 -0
- package/commonjs/src/interop/docker/docker.js +54 -0
- package/commonjs/src/interop/errors/interop.error.js +12 -0
- package/commonjs/src/interop/git/git.js +134 -0
- package/commonjs/src/interop/git/git.types.js +4 -0
- package/commonjs/src/interop/index.js +97 -0
- package/commonjs/src/interop/node/index.js +18 -0
- package/commonjs/src/interop/node/node.js +45 -0
- package/commonjs/src/interop/npm/npm.js +231 -0
- package/commonjs/src/interop/npm/npm.types.js +16 -0
- package/commonjs/src/interop/pnpm/pnpm.js +34 -0
- package/commonjs/src/interop/pnpm/pnpm.types.js +4 -0
- package/commonjs/src/interop/shell/shell.argv.js +45 -0
- package/commonjs/src/interop/shell/shell.js +105 -0
- package/commonjs/src/interop/shell/shell.types.js +4 -0
- package/commonjs/src/interop/types/detect-package-manager.js +71 -0
- package/commonjs/src/interop/types/package-manager.js +4 -0
- package/commonjs/src/interop/yarn/yarn.js +34 -0
- package/commonjs/src/interop/yarn/yarn.types.js +4 -0
- package/commonjs/src/io/copy-file.js +25 -0
- package/commonjs/src/io/delete-file.js +21 -0
- package/commonjs/src/io/directory-exists.js +24 -0
- package/commonjs/src/io/file-exists.js +19 -0
- package/commonjs/src/io/find-directories.js +21 -0
- package/commonjs/src/io/find-file.js +45 -0
- package/commonjs/src/io/index.js +66 -0
- package/commonjs/src/io/io.js +28 -0
- package/commonjs/src/io/read-file.js +39 -0
- package/commonjs/src/io/remove-dir.js +22 -0
- package/commonjs/src/io/types/directory.type.js +4 -0
- package/commonjs/src/io/types/file.js +28 -0
- package/commonjs/src/io/types/index.js +19 -0
- package/commonjs/src/io/url-to-path.js +33 -0
- package/commonjs/src/io/watch.js +261 -0
- package/commonjs/src/io/write-file.js +30 -0
- package/commonjs/src/objects/deep-merge.js +67 -0
- package/commonjs/src/objects/index.js +11 -0
- package/commonjs/src/reflection/index.js +20 -0
- package/commonjs/src/reflection/types/index.js +18 -0
- package/commonjs/src/reflection/types/reflection.types.js +26 -0
- package/commonjs/src/reflection/utilities.js +118 -0
- package/commonjs/src/semver/index.js +18 -0
- package/commonjs/src/semver/semver.js +92 -0
- package/commonjs/src/system/camel-case.js +13 -0
- package/commonjs/src/system/debounce.js +19 -0
- package/commonjs/src/system/decorator.js +46 -0
- package/commonjs/src/system/environment.js +23 -0
- package/commonjs/src/system/function.types.js +18 -0
- package/commonjs/src/system/index.js +24 -0
- package/commonjs/src/system/retry.decorator.js +40 -0
- package/commonjs/src/system/sleep.js +13 -0
- package/commonjs/src/system/type.utils.js +4 -0
- package/commonjs/src/testing/flush-promises.js +16 -0
- package/commonjs/src/testing/glob-with-memfs.js +22 -0
- package/commonjs/src/testing/index.js +22 -0
- package/commonjs/src/testing/memfs.js +52 -0
- package/commonjs/src/testing/mock-logger.js +36 -0
- package/commonjs/src/testing/spy-on-constructor.js +27 -0
- package/es6/src/caching/cache-manager.js +82 -0
- package/es6/src/caching/cache.decorator.js +51 -0
- package/es6/src/caching/cache.js +3 -0
- package/es6/src/caching/index.js +6 -0
- package/es6/src/caching/invalidate-cache.decorator.js +71 -0
- package/es6/src/caching/memoize.decorator.js +27 -0
- package/es6/src/caching/node-cache-memoize.adapter.js +37 -0
- package/es6/src/cli/action.js +47 -0
- package/es6/src/cli/command.js +106 -0
- package/es6/src/cli/index.js +4 -0
- package/es6/src/cli/module.type.js +11 -0
- package/es6/src/cli/options.js +76 -0
- package/es6/src/collections/collections.js +4 -0
- package/es6/src/collections/find-duplicates.js +17 -0
- package/es6/src/collections/index.js +1 -0
- package/es6/src/collections/merge-arrays.js +16 -0
- package/es6/src/collections/sum.js +45 -0
- package/es6/src/collections/unique-objects.js +21 -0
- package/es6/src/composition/index.js +1 -0
- package/es6/src/configuration/configuration.types.js +1 -0
- package/es6/src/configuration/index.js +1 -0
- package/es6/src/diagnostics/index.js +1 -0
- package/es6/src/diagnostics/trace.js +68 -0
- package/es6/src/extensibility/decorator-factory-base.js +39 -0
- package/es6/src/extensibility/decorator-factory.js +21 -0
- package/es6/src/extensibility/extension.js +27 -0
- package/es6/src/extensibility/index.js +6 -0
- package/es6/src/extensibility/mixwith.js +26 -0
- package/es6/src/extensibility/pipeline.js +46 -0
- package/es6/src/extensibility/step.js +16 -0
- package/es6/src/interop/docker/docker.js +44 -0
- package/es6/src/interop/errors/interop.error.js +2 -0
- package/es6/src/interop/git/git.js +124 -0
- package/es6/src/interop/git/git.types.js +1 -0
- package/es6/src/interop/index.js +21 -0
- package/es6/src/interop/node/index.js +1 -0
- package/es6/src/interop/node/node.js +35 -0
- package/es6/src/interop/npm/npm.js +180 -0
- package/es6/src/interop/npm/npm.types.js +6 -0
- package/es6/src/interop/pnpm/pnpm.js +24 -0
- package/es6/src/interop/pnpm/pnpm.types.js +1 -0
- package/es6/src/interop/shell/shell.argv.js +35 -0
- package/es6/src/interop/shell/shell.js +95 -0
- package/es6/src/interop/shell/shell.types.js +1 -0
- package/es6/src/interop/types/detect-package-manager.js +50 -0
- package/es6/src/interop/types/package-manager.js +1 -0
- package/es6/src/interop/yarn/yarn.js +24 -0
- package/es6/src/interop/yarn/yarn.types.js +1 -0
- package/es6/src/io/copy-file.js +10 -0
- package/es6/src/io/delete-file.js +6 -0
- package/es6/src/io/directory-exists.js +9 -0
- package/es6/src/io/file-exists.js +9 -0
- package/es6/src/io/find-directories.js +11 -0
- package/es6/src/io/find-file.js +27 -0
- package/es6/src/io/index.js +2 -0
- package/es6/src/io/io.js +11 -0
- package/es6/src/io/read-file.js +13 -0
- package/es6/src/io/remove-dir.js +7 -0
- package/es6/src/io/types/directory.type.js +1 -0
- package/es6/src/io/types/file.js +18 -0
- package/es6/src/io/types/index.js +2 -0
- package/es6/src/io/url-to-path.js +15 -0
- package/es6/src/io/watch.js +238 -0
- package/es6/src/io/write-file.js +15 -0
- package/es6/src/objects/deep-merge.js +57 -0
- package/es6/src/objects/index.js +1 -0
- package/es6/src/reflection/index.js +3 -0
- package/es6/src/reflection/types/index.js +1 -0
- package/es6/src/reflection/types/reflection.types.js +8 -0
- package/es6/src/reflection/utilities.js +74 -0
- package/es6/src/semver/index.js +1 -0
- package/es6/src/semver/semver.js +71 -0
- package/es6/src/system/camel-case.js +3 -0
- package/es6/src/system/debounce.js +9 -0
- package/es6/src/system/decorator.js +30 -0
- package/es6/src/system/environment.js +5 -0
- package/es6/src/system/function.types.js +26 -0
- package/es6/src/system/index.js +7 -0
- package/es6/src/system/retry.decorator.js +30 -0
- package/es6/src/system/sleep.js +3 -0
- package/es6/src/system/type.utils.js +1 -0
- package/es6/src/testing/flush-promises.js +6 -0
- package/es6/src/testing/glob-with-memfs.js +20 -0
- package/es6/src/testing/index.js +5 -0
- package/es6/src/testing/memfs.js +25 -0
- package/es6/src/testing/mock-logger.js +26 -0
- package/es6/src/testing/spy-on-constructor.js +31 -0
- package/package.json +106 -0
- package/types/src/caching/cache-manager.d.ts +59 -0
- package/types/src/caching/cache.d.ts +11 -0
- package/types/src/caching/cache.decorator.d.ts +18 -0
- package/types/src/caching/index.d.ts +6 -0
- package/types/src/caching/invalidate-cache.decorator.d.ts +17 -0
- package/types/src/caching/memoize.decorator.d.ts +16 -0
- package/types/src/caching/node-cache-memoize.adapter.d.ts +22 -0
- package/types/src/cli/action.d.ts +36 -0
- package/types/src/cli/command.d.ts +34 -0
- package/types/src/cli/index.d.ts +7 -0
- package/types/src/cli/module.type.d.ts +36 -0
- package/types/src/cli/options.d.ts +28 -0
- package/types/src/collections/collections.d.ts +4 -0
- package/types/src/collections/find-duplicates.d.ts +2 -0
- package/types/src/collections/index.d.ts +1 -0
- package/types/src/collections/merge-arrays.d.ts +2 -0
- package/types/src/collections/sum.d.ts +4 -0
- package/types/src/collections/unique-objects.d.ts +2 -0
- package/types/src/composition/index.d.ts +37 -0
- package/types/src/configuration/configuration.types.d.ts +10 -0
- package/types/src/configuration/index.d.ts +1 -0
- package/types/src/diagnostics/index.d.ts +1 -0
- package/types/src/diagnostics/trace.d.ts +10 -0
- package/types/src/extensibility/decorator-factory-base.d.ts +39 -0
- package/types/src/extensibility/decorator-factory.d.ts +19 -0
- package/types/src/extensibility/extension.d.ts +9 -0
- package/types/src/extensibility/index.d.ts +6 -0
- package/types/src/extensibility/mixwith.d.ts +6 -0
- package/types/src/extensibility/pipeline.d.ts +12 -0
- package/types/src/extensibility/step.d.ts +16 -0
- package/types/src/interop/docker/docker.d.ts +19 -0
- package/types/src/interop/errors/interop.error.d.ts +2 -0
- package/types/src/interop/git/git.d.ts +16 -0
- package/types/src/interop/git/git.types.d.ts +14 -0
- package/types/src/interop/index.d.ts +14 -0
- package/types/src/interop/node/index.d.ts +1 -0
- package/types/src/interop/node/node.d.ts +5 -0
- package/types/src/interop/npm/npm.d.ts +29 -0
- package/types/src/interop/npm/npm.types.d.ts +24 -0
- package/types/src/interop/pnpm/pnpm.d.ts +9 -0
- package/types/src/interop/pnpm/pnpm.types.d.ts +3 -0
- package/types/src/interop/shell/shell.argv.d.ts +5 -0
- package/types/src/interop/shell/shell.d.ts +6 -0
- package/types/src/interop/shell/shell.types.d.ts +9 -0
- package/types/src/interop/types/detect-package-manager.d.ts +4 -0
- package/types/src/interop/types/package-manager.d.ts +10 -0
- package/types/src/interop/yarn/yarn.d.ts +9 -0
- package/types/src/interop/yarn/yarn.types.d.ts +3 -0
- package/types/src/io/copy-file.d.ts +4 -0
- package/types/src/io/delete-file.d.ts +1 -0
- package/types/src/io/directory-exists.d.ts +1 -0
- package/types/src/io/file-exists.d.ts +1 -0
- package/types/src/io/find-directories.d.ts +2 -0
- package/types/src/io/find-file.d.ts +9 -0
- package/types/src/io/index.d.ts +2 -0
- package/types/src/io/io.d.ts +11 -0
- package/types/src/io/read-file.d.ts +4 -0
- package/types/src/io/remove-dir.d.ts +5 -0
- package/types/src/io/types/directory.type.d.ts +4 -0
- package/types/src/io/types/file.d.ts +20 -0
- package/types/src/io/types/index.d.ts +2 -0
- package/types/src/io/url-to-path.d.ts +2 -0
- package/types/src/io/watch.d.ts +16 -0
- package/types/src/io/write-file.d.ts +5 -0
- package/types/src/objects/deep-merge.d.ts +41 -0
- package/types/src/objects/index.d.ts +1 -0
- package/types/src/reflection/index.d.ts +3 -0
- package/types/src/reflection/types/index.d.ts +1 -0
- package/types/src/reflection/types/reflection.types.d.ts +21 -0
- package/types/src/reflection/utilities.d.ts +27 -0
- package/types/src/semver/index.d.ts +1 -0
- package/types/src/semver/semver.d.ts +18 -0
- package/types/src/system/camel-case.d.ts +1 -0
- package/types/src/system/debounce.d.ts +1 -0
- package/types/src/system/decorator.d.ts +15 -0
- package/types/src/system/environment.d.ts +6 -0
- package/types/src/system/function.types.d.ts +55 -0
- package/types/src/system/index.d.ts +7 -0
- package/types/src/system/retry.decorator.d.ts +6 -0
- package/types/src/system/sleep.d.ts +1 -0
- package/types/src/system/type.utils.d.ts +1 -0
- package/types/src/testing/flush-promises.d.ts +1 -0
- package/types/src/testing/glob-with-memfs.d.ts +3 -0
- package/types/src/testing/index.d.ts +5 -0
- package/types/src/testing/memfs.d.ts +5 -0
- package/types/src/testing/mock-logger.d.ts +13 -0
- package/types/src/testing/spy-on-constructor.d.ts +21 -0
|
@@ -0,0 +1,92 @@
|
|
|
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 Semver () {
|
|
13
|
+
return Semver;
|
|
14
|
+
},
|
|
15
|
+
get SemverError () {
|
|
16
|
+
return SemverError;
|
|
17
|
+
},
|
|
18
|
+
get VersionTypes () {
|
|
19
|
+
return VersionTypes;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const VersionTypes = {
|
|
23
|
+
major: "major",
|
|
24
|
+
minor: "minor",
|
|
25
|
+
patch: "patch",
|
|
26
|
+
prerelease: "prerelease"
|
|
27
|
+
};
|
|
28
|
+
class SemverError extends Error {
|
|
29
|
+
constructor(message){
|
|
30
|
+
super(message);
|
|
31
|
+
this.name = SemverError.name;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const SEMVER_REGEX = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/;
|
|
35
|
+
class Semver {
|
|
36
|
+
version;
|
|
37
|
+
constructor(version){
|
|
38
|
+
this.ensureValid(version);
|
|
39
|
+
this.version = version;
|
|
40
|
+
}
|
|
41
|
+
increment(versionType, preid = "pre") {
|
|
42
|
+
const { major, minor, patch, prerelease } = this.parse(this.version);
|
|
43
|
+
if (versionType === "major") {
|
|
44
|
+
this.version = `${major + 1}.0.0`;
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
if (versionType === "minor") {
|
|
48
|
+
this.version = `${major}.${minor + 1}.0`;
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
if (versionType === "patch") {
|
|
52
|
+
this.version = `${major}.${minor}.${patch + 1}`;
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
if (prerelease == null) {
|
|
56
|
+
this.version = `${major}.${minor}.${patch + 1}-${preid}.0`;
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
const [identifier, ...rest] = prerelease.split(".");
|
|
60
|
+
const maybeCounter = rest.at(-1);
|
|
61
|
+
const counter = maybeCounter != null ? Number.parseInt(maybeCounter, 10) : Number.NaN;
|
|
62
|
+
if (identifier === preid && Number.isFinite(counter)) {
|
|
63
|
+
const nextCounter = counter + 1;
|
|
64
|
+
const prefix = rest.length > 1 ? `${rest.slice(0, -1).join(".")}.` : "";
|
|
65
|
+
this.version = `${major}.${minor}.${patch}-${preid}.${prefix}${nextCounter}`;
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
this.version = `${major}.${minor}.${patch}-${preid}.0`;
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
toString() {
|
|
72
|
+
return this.version;
|
|
73
|
+
}
|
|
74
|
+
ensureValid(version) {
|
|
75
|
+
if (SEMVER_REGEX.test(version)) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
throw new SemverError(`Invalid semantic version: ${version}`);
|
|
79
|
+
}
|
|
80
|
+
parse(version) {
|
|
81
|
+
const match = version.match(SEMVER_REGEX);
|
|
82
|
+
if (match == null) {
|
|
83
|
+
throw new SemverError(`Invalid semantic version: ${version}`);
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
major: Number.parseInt(match[1], 10),
|
|
87
|
+
minor: Number.parseInt(match[2], 10),
|
|
88
|
+
patch: Number.parseInt(match[3], 10),
|
|
89
|
+
prerelease: match[4]
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "lowerCamelCase", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return lowerCamelCase;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
function lowerCamelCase(val) {
|
|
12
|
+
return String(val).charAt(0).toLowerCase() + String(val).slice(1);
|
|
13
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "debounce", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return debounce;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
function debounce(callback, delay) {
|
|
12
|
+
let timeoutTimer;
|
|
13
|
+
return (...args)=>{
|
|
14
|
+
clearTimeout(timeoutTimer);
|
|
15
|
+
timeoutTimer = setTimeout(async ()=>{
|
|
16
|
+
await callback(...args);
|
|
17
|
+
}, delay);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
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 FunctionDecorator () {
|
|
13
|
+
return FunctionDecorator;
|
|
14
|
+
},
|
|
15
|
+
get ignoreDuringUnitTest () {
|
|
16
|
+
return ignoreDuringUnitTest;
|
|
17
|
+
},
|
|
18
|
+
get ignoreIf () {
|
|
19
|
+
return ignoreIf;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
class FunctionDecorator {
|
|
23
|
+
options;
|
|
24
|
+
constructor(){
|
|
25
|
+
this.decoratorFactory = this.decoratorFactory.bind(this);
|
|
26
|
+
}
|
|
27
|
+
decoratorFactory(options) {
|
|
28
|
+
this.options = options;
|
|
29
|
+
return this.decorator.bind(this);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function ignoreIf(...envVars) {
|
|
33
|
+
return (_, __, descriptor)=>{
|
|
34
|
+
const originalFunction = descriptor.value;
|
|
35
|
+
descriptor.value = function(target, key, descriptor) {
|
|
36
|
+
if (envVars.some((v)=>process.env[v] === "true")) {
|
|
37
|
+
return descriptor;
|
|
38
|
+
}
|
|
39
|
+
return originalFunction.bind(this)(target, key, descriptor);
|
|
40
|
+
};
|
|
41
|
+
return descriptor;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function ignoreDuringUnitTest() {
|
|
45
|
+
return ignoreIf("TEST");
|
|
46
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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 DefaultEnvironment () {
|
|
13
|
+
return DefaultEnvironment;
|
|
14
|
+
},
|
|
15
|
+
get Environments () {
|
|
16
|
+
return Environments;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const Environments = {
|
|
20
|
+
production: "production",
|
|
21
|
+
development: "development"
|
|
22
|
+
};
|
|
23
|
+
const DefaultEnvironment = Environments.development;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic function type that can replace arrow function signatures.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* // Instead of: (arg1: string, arg2: number) => boolean
|
|
7
|
+
* type MyCallback = Func<[string, number], boolean>;
|
|
8
|
+
*
|
|
9
|
+
* // Instead of: (data: any) => void
|
|
10
|
+
* type MyHandler = Func<[any], void>;
|
|
11
|
+
*
|
|
12
|
+
* // Instead of: () => Promise<string>
|
|
13
|
+
* type MyAsyncFunc = Func<[], Promise<string>>;
|
|
14
|
+
* ```
|
|
15
|
+
*/ "use strict";
|
|
16
|
+
Object.defineProperty(exports, "__esModule", {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./camel-case.js"), exports);
|
|
6
|
+
_export_star(require("./debounce.js"), exports);
|
|
7
|
+
_export_star(require("./decorator.js"), exports);
|
|
8
|
+
_export_star(require("./environment.js"), exports);
|
|
9
|
+
_export_star(require("./function.types.js"), exports);
|
|
10
|
+
_export_star(require("./retry.decorator.js"), exports);
|
|
11
|
+
_export_star(require("./type.utils.js"), exports);
|
|
12
|
+
function _export_star(from, to) {
|
|
13
|
+
Object.keys(from).forEach(function(k) {
|
|
14
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
15
|
+
Object.defineProperty(to, k, {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function() {
|
|
18
|
+
return from[k];
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return from;
|
|
24
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "retry", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return retry;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _decorator = require("./decorator.js");
|
|
12
|
+
const _sleep = require("./sleep.js");
|
|
13
|
+
class RetryDecorator extends _decorator.FunctionDecorator {
|
|
14
|
+
decorator(_target, _propertyKey, descriptor) {
|
|
15
|
+
const originalMethod = descriptor.value;
|
|
16
|
+
const attempts = Math.max(1, this.options?.attempts ?? 3);
|
|
17
|
+
const delayMs = Math.max(0, this.options?.delayMs ?? 0);
|
|
18
|
+
const shouldRetry = this.options?.shouldRetry ?? (()=>true);
|
|
19
|
+
descriptor.value = async function(...args) {
|
|
20
|
+
let lastError;
|
|
21
|
+
for(let attempt = 1; attempt <= attempts; attempt++){
|
|
22
|
+
try {
|
|
23
|
+
return await Promise.resolve(originalMethod.apply(this, args));
|
|
24
|
+
} catch (error) {
|
|
25
|
+
lastError = error;
|
|
26
|
+
const shouldAttemptAgain = attempt < attempts && shouldRetry(error);
|
|
27
|
+
if (!shouldAttemptAgain) {
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
if (delayMs > 0) {
|
|
31
|
+
await (0, _sleep.sleep)(delayMs);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
throw lastError;
|
|
36
|
+
};
|
|
37
|
+
return descriptor;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const retry = new RetryDecorator().decoratorFactory;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "sleep", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return sleep;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const sleep = (ms)=>new Promise((resolve)=>setTimeout(()=>{
|
|
12
|
+
resolve(null);
|
|
13
|
+
}, ms));
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "flushPromises", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return flushPromises;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
var scheduler = typeof setImmediate === "function" ? setImmediate : setTimeout;
|
|
12
|
+
function flushPromises() {
|
|
13
|
+
return new Promise((resolve)=>{
|
|
14
|
+
scheduler(resolve);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "withMemfsFsForGlob", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return withMemfsFsForGlob;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _memfs = require("memfs");
|
|
12
|
+
function withMemfsFsForGlob(actual) {
|
|
13
|
+
// Preserve all module exports, overriding only `glob` to force `{ fs: memfs }`.
|
|
14
|
+
const glob = (pattern, options)=>actual.glob(pattern, {
|
|
15
|
+
...options,
|
|
16
|
+
fs: _memfs.fs
|
|
17
|
+
});
|
|
18
|
+
return {
|
|
19
|
+
...actual,
|
|
20
|
+
glob
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./flush-promises.js"), exports);
|
|
6
|
+
_export_star(require("./glob-with-memfs.js"), exports);
|
|
7
|
+
_export_star(require("./memfs.js"), exports);
|
|
8
|
+
_export_star(require("./mock-logger.js"), exports);
|
|
9
|
+
_export_star(require("./spy-on-constructor.js"), exports);
|
|
10
|
+
function _export_star(from, to) {
|
|
11
|
+
Object.keys(from).forEach(function(k) {
|
|
12
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
13
|
+
Object.defineProperty(to, k, {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function() {
|
|
16
|
+
return from[k];
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return from;
|
|
22
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
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 createTestFile () {
|
|
13
|
+
return createTestFile;
|
|
14
|
+
},
|
|
15
|
+
get fileExists () {
|
|
16
|
+
return fileExists;
|
|
17
|
+
},
|
|
18
|
+
get readFile () {
|
|
19
|
+
return readFile;
|
|
20
|
+
},
|
|
21
|
+
get resetMemfs () {
|
|
22
|
+
return resetMemfs;
|
|
23
|
+
},
|
|
24
|
+
get seedMemfs () {
|
|
25
|
+
return seedMemfs;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const _memfs = require("memfs");
|
|
29
|
+
function resetMemfs() {
|
|
30
|
+
_memfs.vol.reset();
|
|
31
|
+
}
|
|
32
|
+
function seedMemfs(files) {
|
|
33
|
+
_memfs.vol.fromJSON(files);
|
|
34
|
+
}
|
|
35
|
+
function createTestFile(filePath, content) {
|
|
36
|
+
_memfs.fs.mkdirSync(filePath.substring(0, filePath.lastIndexOf("/")), {
|
|
37
|
+
recursive: true
|
|
38
|
+
});
|
|
39
|
+
_memfs.fs.writeFileSync(filePath, content);
|
|
40
|
+
}
|
|
41
|
+
async function readFile(filePath) {
|
|
42
|
+
const response = await _memfs.fs.promises.readFile(filePath, "utf8");
|
|
43
|
+
return response;
|
|
44
|
+
}
|
|
45
|
+
function fileExists(filePath) {
|
|
46
|
+
try {
|
|
47
|
+
_memfs.vol.statSync(filePath);
|
|
48
|
+
return true;
|
|
49
|
+
} catch {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "createMockLogger", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return createMockLogger;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _vitest = require("vitest");
|
|
12
|
+
const DefaultLogLevels = {
|
|
13
|
+
fatal: 60,
|
|
14
|
+
error: 50,
|
|
15
|
+
warn: 40,
|
|
16
|
+
info: 30,
|
|
17
|
+
debug: 20,
|
|
18
|
+
trace: 10
|
|
19
|
+
};
|
|
20
|
+
function createMockLogger() {
|
|
21
|
+
return {
|
|
22
|
+
error: _vitest.vi.fn(),
|
|
23
|
+
info: _vitest.vi.fn(),
|
|
24
|
+
warn: _vitest.vi.fn(),
|
|
25
|
+
debug: _vitest.vi.fn(),
|
|
26
|
+
trace: _vitest.vi.fn(),
|
|
27
|
+
fatal: _vitest.vi.fn(),
|
|
28
|
+
isLevelEnabled: _vitest.vi.fn().mockReturnValue(true),
|
|
29
|
+
get currentLevel () {
|
|
30
|
+
return "info";
|
|
31
|
+
},
|
|
32
|
+
get logLevels () {
|
|
33
|
+
return DefaultLogLevels;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "spyOnConstructor", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return spyOnConstructor;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _vitest = require("vitest");
|
|
12
|
+
function spyOnConstructor(Target) {
|
|
13
|
+
const spy = _vitest.vi.fn();
|
|
14
|
+
const ProxiedTarget = new Proxy(Target, {
|
|
15
|
+
construct (Ctor, args) {
|
|
16
|
+
spy(...args);
|
|
17
|
+
return Reflect.construct(Ctor, args);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
for (const key of Reflect.getMetadataKeys(Target)){
|
|
21
|
+
Reflect.defineMetadata(key, Reflect.getMetadata(key, Target), ProxiedTarget);
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
spy,
|
|
25
|
+
Proxy: ProxiedTarget
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { NodeCacheAdapter } from "./node-cache-memoize.adapter.js";
|
|
2
|
+
export const Caches = {
|
|
3
|
+
default: "DEFAULT",
|
|
4
|
+
memoize: "MEMOIZE_CACHE"
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Central cache manager for managing named cache instances
|
|
8
|
+
*/ class CacheManager {
|
|
9
|
+
caches = new Map();
|
|
10
|
+
defaultCacheName = Caches.default;
|
|
11
|
+
/**
|
|
12
|
+
* Set a cache instance with the given name
|
|
13
|
+
* @param name - The name of the cache
|
|
14
|
+
* @param cache - The cache instance
|
|
15
|
+
*/ setCache(name, cache) {
|
|
16
|
+
this.caches.set(name, cache);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get a cache instance by name
|
|
20
|
+
* @param name - The name of the cache, defaults to "DEFAULT"
|
|
21
|
+
* @returns The cache instance
|
|
22
|
+
*/ getCache(name, memoize = false) {
|
|
23
|
+
const cacheName = name ?? this.defaultCacheName;
|
|
24
|
+
if (!this.caches.has(cacheName)) {
|
|
25
|
+
const cache = NodeCacheAdapter.create({
|
|
26
|
+
enableMemoization: memoize
|
|
27
|
+
});
|
|
28
|
+
this.caches.set(cacheName, cache);
|
|
29
|
+
}
|
|
30
|
+
return this.caches.get(cacheName);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Clear a cache by name. If no name is provided, clears the default cache.
|
|
34
|
+
* Note: This only works if the cache implements a clear() method.
|
|
35
|
+
* @param name - The name of the cache to clear
|
|
36
|
+
*/ flush(name) {
|
|
37
|
+
const cacheName = name ?? this.defaultCacheName;
|
|
38
|
+
const cache = this.caches.get(cacheName);
|
|
39
|
+
cache.flushAll();
|
|
40
|
+
}
|
|
41
|
+
flushAllCaches() {
|
|
42
|
+
for (const [, cache] of this.caches){
|
|
43
|
+
cache.flushAll();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Remove a cache instance by name
|
|
48
|
+
* @param name - The name of the cache to remove
|
|
49
|
+
*/ removeCache(name) {
|
|
50
|
+
this.caches.delete(name);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Check if a cache with the given name exists
|
|
54
|
+
* @param name - The name of the cache
|
|
55
|
+
* @returns True if the cache exists, false otherwise
|
|
56
|
+
*/ hasCache(name) {
|
|
57
|
+
return this.caches.has(name);
|
|
58
|
+
}
|
|
59
|
+
instanceIds = new WeakMap();
|
|
60
|
+
instanceIdCounter = 0;
|
|
61
|
+
/**
|
|
62
|
+
* Generate a cache key for a given instance, function name, and arguments.
|
|
63
|
+
* Each instance receives a stable numeric ID so cache entries are never
|
|
64
|
+
* shared across instances of the same class.
|
|
65
|
+
* @param instance - The class instance (`this` at call time)
|
|
66
|
+
* @param functionName - The name of the decorated method
|
|
67
|
+
* @param args - The method arguments
|
|
68
|
+
* @returns A unique cache key string
|
|
69
|
+
*/ generateCacheKey(instance, functionName, args) {
|
|
70
|
+
if (!this.instanceIds.has(instance)) {
|
|
71
|
+
this.instanceIds.set(instance, ++this.instanceIdCounter);
|
|
72
|
+
}
|
|
73
|
+
const instanceId = this.instanceIds.get(instance);
|
|
74
|
+
const argsStr = JSON.stringify({
|
|
75
|
+
args
|
|
76
|
+
}, (_key, val)=>typeof val === "function" ? `[Function:${val.name}]` : val);
|
|
77
|
+
return `${instance.constructor.name}#${instanceId}|${functionName}|${argsStr}`;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Singleton instance of the cache manager
|
|
82
|
+
*/ export const Caching = new CacheManager();
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
}
|
|
7
|
+
function _ts_metadata(k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
}
|
|
10
|
+
import { isPromise } from "node:util/types";
|
|
11
|
+
import { FunctionDecorator, ignoreIf } from "../system/decorator.js";
|
|
12
|
+
import { Caching } from "./cache-manager.js";
|
|
13
|
+
export class CacheDecorator extends FunctionDecorator {
|
|
14
|
+
decorator(_target, propertyKey, descriptor) {
|
|
15
|
+
const cacheInstance = this.options?.cache ?? Caching.getCache(this.options?.name);
|
|
16
|
+
const keyFn = this.options?.keyFn;
|
|
17
|
+
const originalMethod = descriptor.value;
|
|
18
|
+
const wrapped = function(...args) {
|
|
19
|
+
const cacheKey = keyFn ? keyFn(...args) : Caching.generateCacheKey(this, propertyKey, args);
|
|
20
|
+
if (cacheInstance.has(cacheKey)) {
|
|
21
|
+
const val = cacheInstance.get(cacheKey);
|
|
22
|
+
return val;
|
|
23
|
+
}
|
|
24
|
+
const resultOrPromise = originalMethod.apply(this, args);
|
|
25
|
+
if (isPromise(resultOrPromise)) {
|
|
26
|
+
resultOrPromise.then((result)=>{
|
|
27
|
+
cacheInstance.set(cacheKey, result);
|
|
28
|
+
}, ()=>{
|
|
29
|
+
/* rejection propagates via the returned promise */ });
|
|
30
|
+
} else {
|
|
31
|
+
cacheInstance.set(cacheKey, resultOrPromise);
|
|
32
|
+
}
|
|
33
|
+
return resultOrPromise;
|
|
34
|
+
};
|
|
35
|
+
Object.defineProperty(wrapped, "name", {
|
|
36
|
+
value: propertyKey
|
|
37
|
+
});
|
|
38
|
+
descriptor.value = wrapped;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
_ts_decorate([
|
|
42
|
+
ignoreIf("FORGE_DISABLE_CACHE"),
|
|
43
|
+
_ts_metadata("design:type", Function),
|
|
44
|
+
_ts_metadata("design:paramtypes", [
|
|
45
|
+
Object,
|
|
46
|
+
String,
|
|
47
|
+
typeof PropertyDescriptor === "undefined" ? Object : PropertyDescriptor
|
|
48
|
+
]),
|
|
49
|
+
_ts_metadata("design:returntype", void 0)
|
|
50
|
+
], CacheDecorator.prototype, "decorator", null);
|
|
51
|
+
export const cache = new CacheDecorator().decoratorFactory;
|