@decohere/core 0.0.1-dev.125 → 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
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { MapCache } from "./map-cache.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 = new MapCache({
|
|
26
|
-
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();
|
|
@@ -1,51 +0,0 @@
|
|
|
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;
|
package/es6/src/caching/cache.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
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 { Caches, Caching } from "./cache-manager.js";
|
|
13
|
-
export class InvalidateCacheDecorator extends FunctionDecorator {
|
|
14
|
-
decorator(_target, _propertyKey, descriptor) {
|
|
15
|
-
const { getKey, cache, name } = this.options;
|
|
16
|
-
const cacheInstance = cache ?? Caching.getCache(name);
|
|
17
|
-
const originalMethod = descriptor.value;
|
|
18
|
-
descriptor.value = function(...args) {
|
|
19
|
-
const resultOrPromise = originalMethod.apply(this, args);
|
|
20
|
-
const evict = ()=>{
|
|
21
|
-
const key = getKey(this, args);
|
|
22
|
-
cacheInstance.del(key);
|
|
23
|
-
};
|
|
24
|
-
if (isPromise(resultOrPromise)) {
|
|
25
|
-
resultOrPromise.then(evict);
|
|
26
|
-
} else {
|
|
27
|
-
evict();
|
|
28
|
-
}
|
|
29
|
-
return resultOrPromise;
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
_ts_decorate([
|
|
34
|
-
ignoreIf("FORGE_DISABLE_CACHE"),
|
|
35
|
-
_ts_metadata("design:type", Function),
|
|
36
|
-
_ts_metadata("design:paramtypes", [
|
|
37
|
-
Object,
|
|
38
|
-
String,
|
|
39
|
-
typeof PropertyDescriptor === "undefined" ? Object : PropertyDescriptor
|
|
40
|
-
]),
|
|
41
|
-
_ts_metadata("design:returntype", void 0)
|
|
42
|
-
], InvalidateCacheDecorator.prototype, "decorator", null);
|
|
43
|
-
const buildGetKey = (method, keyFn)=>{
|
|
44
|
-
if (typeof method === "string") return ()=>method;
|
|
45
|
-
if (keyFn) return (_instance, args)=>keyFn(...args);
|
|
46
|
-
return (instance, args)=>Caching.generateCacheKey(instance, method.name, args);
|
|
47
|
-
};
|
|
48
|
-
export const invalidateCache = (method, options)=>{
|
|
49
|
-
const cache = options?.cache ?? Caching.getCache(options?.name);
|
|
50
|
-
return new InvalidateCacheDecorator().decoratorFactory({
|
|
51
|
-
getKey: buildGetKey(method, options?.keyFn),
|
|
52
|
-
...options,
|
|
53
|
-
cache
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
invalidateCache.evict = (instance, method, args = [])=>{
|
|
57
|
-
const key = Caching.generateCacheKey(instance, method.name, args);
|
|
58
|
-
Caching.getCache().del(key);
|
|
59
|
-
};
|
|
60
|
-
export const invalidateMemoize = (method, options)=>{
|
|
61
|
-
const cache = options?.cache ?? Caching.getCache(options?.name ?? Caches.memoize, true);
|
|
62
|
-
return new InvalidateCacheDecorator().decoratorFactory({
|
|
63
|
-
getKey: buildGetKey(method),
|
|
64
|
-
...options,
|
|
65
|
-
cache
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
invalidateMemoize.evict = (instance, method, args = [])=>{
|
|
69
|
-
const key = Caching.generateCacheKey(instance, method.name, args);
|
|
70
|
-
Caching.getCache(Caches.memoize, true).del(key);
|
|
71
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The built-in cache: a plain `Map`, no expiry.
|
|
3
|
-
*
|
|
4
|
-
* By default `get` returns a `structuredClone` of an object, so a caller that changes what it
|
|
5
|
-
* got back can't change the cached value. With `memoize` it returns the stored reference.
|
|
6
|
-
* Scalars, `null` and `undefined` are returned as they are.
|
|
7
|
-
*/ export class MapCache {
|
|
8
|
-
#entries = new Map();
|
|
9
|
-
#memoize;
|
|
10
|
-
constructor(options = {}){
|
|
11
|
-
this.#memoize = options.memoize ?? false;
|
|
12
|
-
}
|
|
13
|
-
get isMemoize() {
|
|
14
|
-
return this.#memoize;
|
|
15
|
-
}
|
|
16
|
-
get(key) {
|
|
17
|
-
const value = this.#entries.get(key);
|
|
18
|
-
if (this.#memoize || value === null || typeof value !== "object") {
|
|
19
|
-
return value;
|
|
20
|
-
}
|
|
21
|
-
return structuredClone(value);
|
|
22
|
-
}
|
|
23
|
-
set(key, value) {
|
|
24
|
-
this.#entries.set(key, value);
|
|
25
|
-
}
|
|
26
|
-
has(key) {
|
|
27
|
-
return this.#entries.has(key);
|
|
28
|
-
}
|
|
29
|
-
del(key) {
|
|
30
|
-
this.#entries.delete(key);
|
|
31
|
-
}
|
|
32
|
-
flushAll() {
|
|
33
|
-
this.#entries.clear();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { CacheDecorator } from "./cache.decorator.js";
|
|
2
|
-
import { Caches, Caching } from "./cache-manager.js";
|
|
3
|
-
/**
|
|
4
|
-
* Memoize decorator class that extends CacheDecorator with memoization support
|
|
5
|
-
* Automatically uses a memoization-capable cache (a MapCache that hands out references)
|
|
6
|
-
*/ export class MemoizeDecorator extends CacheDecorator {
|
|
7
|
-
decorator(target, propertyKey, descriptor) {
|
|
8
|
-
const cache = this.options?.cache ?? Caching.getCache(this.options?.name ?? Caches.memoize, true);
|
|
9
|
-
if (!cache.isMemoize) {
|
|
10
|
-
throw new Error("Memoize decorator requires a cache that supports memoization (stores references, not clones)");
|
|
11
|
-
}
|
|
12
|
-
// Pass the resolved cache to the base class by updating options
|
|
13
|
-
// This ensures the base class uses CacheNames.memoize when no cache was provided
|
|
14
|
-
this.options = {
|
|
15
|
-
...this.options,
|
|
16
|
-
cache
|
|
17
|
-
};
|
|
18
|
-
return super.decorator(target, propertyKey, descriptor);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Memoize decorator factory
|
|
23
|
-
* Provides true memoization by storing object references instead of clones
|
|
24
|
-
*
|
|
25
|
-
* @param options - Optional configuration for the memoize decorator
|
|
26
|
-
* @returns Decorator function
|
|
27
|
-
*/ export const memoize = new MemoizeDecorator().decoratorFactory;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export function findDuplicatesByKey(items, key) {
|
|
2
|
-
return findDuplicatesBy(items, (item)=>String(item[key]));
|
|
3
|
-
}
|
|
4
|
-
export function findDuplicatesBy(items, selector) {
|
|
5
|
-
const groups = new Map();
|
|
6
|
-
for (const item of items){
|
|
7
|
-
const k = selector(item);
|
|
8
|
-
const existing = groups.get(k) ?? [];
|
|
9
|
-
groups.set(k, [
|
|
10
|
-
...existing,
|
|
11
|
-
item
|
|
12
|
-
]);
|
|
13
|
-
}
|
|
14
|
-
return [
|
|
15
|
-
...groups.entries()
|
|
16
|
-
].filter(([, group])=>group.length > 1);
|
|
17
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export function mergeByKey(first, second, key) {
|
|
2
|
-
return mergeBy(first, second, (item)=>String(item[key]));
|
|
3
|
-
}
|
|
4
|
-
export function mergeBy(first, second, selector) {
|
|
5
|
-
// Second collection values win when keys collide.
|
|
6
|
-
const merged = [
|
|
7
|
-
...first,
|
|
8
|
-
...second
|
|
9
|
-
];
|
|
10
|
-
return [
|
|
11
|
-
...new Map(merged.map((item)=>[
|
|
12
|
-
selector(item),
|
|
13
|
-
item
|
|
14
|
-
])).values()
|
|
15
|
-
];
|
|
16
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
export function sumByKey(objects, key) {
|
|
2
|
-
return sum(objects, key);
|
|
3
|
-
}
|
|
4
|
-
export function sumBy(objects, key) {
|
|
5
|
-
return sum(objects, key);
|
|
6
|
-
}
|
|
7
|
-
function extractValueFromItem(item, key) {
|
|
8
|
-
if (typeof key === "function") {
|
|
9
|
-
const result = key(item);
|
|
10
|
-
return isNumericValue(result) ? result : 0;
|
|
11
|
-
}
|
|
12
|
-
const value = item?.[key];
|
|
13
|
-
return isNumericValue(value) ? value : 0;
|
|
14
|
-
}
|
|
15
|
-
function isNumericValue(value) {
|
|
16
|
-
return typeof value === "number" || typeof value === "bigint";
|
|
17
|
-
}
|
|
18
|
-
function determineSumType(firstValue) {
|
|
19
|
-
return typeof firstValue === "bigint" ? "bigint" : "number";
|
|
20
|
-
}
|
|
21
|
-
function getInitialSumValue(sumType) {
|
|
22
|
-
return sumType === "bigint" ? 0n : 0;
|
|
23
|
-
}
|
|
24
|
-
function addValues(total, value, sumType) {
|
|
25
|
-
if (sumType === "bigint") {
|
|
26
|
-
const totalBigInt = total;
|
|
27
|
-
const valueBigInt = typeof value === "bigint" ? value : BigInt(value);
|
|
28
|
-
return totalBigInt + valueBigInt;
|
|
29
|
-
}
|
|
30
|
-
const totalNumber = total;
|
|
31
|
-
const valueNumber = typeof value === "number" ? value : Number(value);
|
|
32
|
-
return totalNumber + valueNumber;
|
|
33
|
-
}
|
|
34
|
-
function sum(objects, key) {
|
|
35
|
-
if (objects.length === 0) {
|
|
36
|
-
return 0;
|
|
37
|
-
}
|
|
38
|
-
const firstValue = extractValueFromItem(objects[0], key);
|
|
39
|
-
const sumType = determineSumType(firstValue);
|
|
40
|
-
const initialValue = getInitialSumValue(sumType);
|
|
41
|
-
return objects.reduce((total, item)=>{
|
|
42
|
-
const value = extractValueFromItem(item, key);
|
|
43
|
-
return addValues(total, value, sumType);
|
|
44
|
-
}, initialValue);
|
|
45
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export function uniqueObjectsByKey(objects, key) {
|
|
2
|
-
return uniqueObjects(objects, key);
|
|
3
|
-
}
|
|
4
|
-
export function uniqueObjectsBy(objects, key) {
|
|
5
|
-
return uniqueObjects(objects, key);
|
|
6
|
-
}
|
|
7
|
-
function uniqueObjects(objects, key) {
|
|
8
|
-
const getKey = (key, item)=>{
|
|
9
|
-
if (typeof key === "function") {
|
|
10
|
-
return key(item);
|
|
11
|
-
}
|
|
12
|
-
return item != null ? item[key] : null;
|
|
13
|
-
};
|
|
14
|
-
const arrayUniqueByKey = [
|
|
15
|
-
...new Map(objects.map((item)=>[
|
|
16
|
-
getKey(key, item),
|
|
17
|
-
item
|
|
18
|
-
])).values()
|
|
19
|
-
];
|
|
20
|
-
return arrayUniqueByKey;
|
|
21
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const ConfigurationServiceToken = Symbol("IConfigurationService");
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Decorator factory class that provides decorator methods which can be conditionally
|
|
3
|
-
* disabled during unit testing using the @ignoreInUnitTest decorator.
|
|
4
|
-
*
|
|
5
|
-
* Inspired by: https://jasonharper.blog/2018/03/13/decorate-the-decorator-to-exclude-in-unit-testing/
|
|
6
|
-
*/ /**
|
|
7
|
-
* Decorator that disables the decorated decorator method when TEST environment variable is true.
|
|
8
|
-
* If TEST=true, it returns a no-op decorator that simply returns the original function unchanged.
|
|
9
|
-
*/ export function ignoreInUnitTest(_target, _propertyKey, descriptor) {
|
|
10
|
-
const originalMethod = descriptor.value;
|
|
11
|
-
descriptor.value = function(...args) {
|
|
12
|
-
// Check if we're in a test environment
|
|
13
|
-
if (process.env.TEST === "true") {
|
|
14
|
-
// Return a no-op decorator that just returns the original function
|
|
15
|
-
return (originalFunction)=>originalFunction;
|
|
16
|
-
}
|
|
17
|
-
// Otherwise, apply the original decorator method
|
|
18
|
-
return originalMethod.apply(this, args);
|
|
19
|
-
};
|
|
20
|
-
return descriptor;
|
|
21
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export function extension(ctor, options) {
|
|
2
|
-
return (_target, propertyKey, descriptor)=>{
|
|
3
|
-
const originalFunction = descriptor.value;
|
|
4
|
-
ctor.prototype[propertyKey] = function(...args) {
|
|
5
|
-
return originalFunction.apply(this, [
|
|
6
|
-
this,
|
|
7
|
-
...args
|
|
8
|
-
]);
|
|
9
|
-
};
|
|
10
|
-
if (options?.static) {
|
|
11
|
-
Object.defineProperty(ctor, propertyKey, {
|
|
12
|
-
configurable: true,
|
|
13
|
-
writable: true,
|
|
14
|
-
value (...args) {
|
|
15
|
-
const receiver = singletonOf(ctor) ?? this;
|
|
16
|
-
return originalFunction.apply(receiver, [
|
|
17
|
-
receiver,
|
|
18
|
-
...args
|
|
19
|
-
]);
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
function singletonOf(ctor) {
|
|
26
|
-
return ctor.instance;
|
|
27
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const BLOCKED_PROTOTYPE_KEYS = new Set([
|
|
2
|
-
"constructor",
|
|
3
|
-
"prototype",
|
|
4
|
-
"name",
|
|
5
|
-
"length"
|
|
6
|
-
]);
|
|
7
|
-
function copyPrototypeProperties(target, source) {
|
|
8
|
-
for (const key of Reflect.ownKeys(source)){
|
|
9
|
-
if (typeof key === "string" && BLOCKED_PROTOTYPE_KEYS.has(key)) {
|
|
10
|
-
continue;
|
|
11
|
-
}
|
|
12
|
-
const descriptor = Object.getOwnPropertyDescriptor(source, key);
|
|
13
|
-
if (descriptor == null) {
|
|
14
|
-
continue;
|
|
15
|
-
}
|
|
16
|
-
Object.defineProperty(target, key, descriptor);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
export function mixwith(...mixins) {
|
|
20
|
-
class Mixed {
|
|
21
|
-
}
|
|
22
|
-
for (const mixin of mixins){
|
|
23
|
-
copyPrototypeProperties(Mixed.prototype, mixin.prototype);
|
|
24
|
-
}
|
|
25
|
-
return Mixed;
|
|
26
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { scribe } from "@decohere/scribe";
|
|
2
|
-
export class Pipeline {
|
|
3
|
-
stack;
|
|
4
|
-
logger = scribe.logger(Pipeline.name);
|
|
5
|
-
currentStep;
|
|
6
|
-
constructor(...steps){
|
|
7
|
-
this.stack = steps;
|
|
8
|
-
}
|
|
9
|
-
[Symbol.dispose]() {
|
|
10
|
-
for (const [, step] of this.stack){
|
|
11
|
-
if (Symbol.dispose in step) {
|
|
12
|
-
step[Symbol.dispose]();
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
async start(context) {
|
|
17
|
-
const runStep = async (index)=>{
|
|
18
|
-
const [key, middleware, when] = this.stack[index] ?? [];
|
|
19
|
-
if (middleware == null) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (when != null && !when(context)) {
|
|
23
|
-
this.logger.info(`Skipping step ${key}`);
|
|
24
|
-
return await runStep(index + 1);
|
|
25
|
-
}
|
|
26
|
-
this.currentStep = key;
|
|
27
|
-
this.logger.info(`Running step ${key}`);
|
|
28
|
-
await middleware.run(context, async ()=>{
|
|
29
|
-
await runStep(index + 1);
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
try {
|
|
33
|
-
await runStep(0);
|
|
34
|
-
} catch (error) {
|
|
35
|
-
const step = this.currentStep ?? "unknown";
|
|
36
|
-
if (error instanceof Error) {
|
|
37
|
-
throw new Error(`Pipeline step '${step}' failed: ${error.message}`, {
|
|
38
|
-
cause: error
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
throw new Error(`Pipeline step '${step}' failed with non-Error value`, {
|
|
42
|
-
cause: error
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Wraps a pipeline step with an optional `when` predicate.
|
|
3
|
-
* When `when` is provided, the step only runs if `when(ctx)` returns `true`.
|
|
4
|
-
* If `when` returns `false`, the pipeline logs `"Skipping step <name>"` and
|
|
5
|
-
* advances to the next step without invoking `run()`.
|
|
6
|
-
*
|
|
7
|
-
* Predicates are declared in the command constructor via `addDisableStepOption`,
|
|
8
|
-
* keeping skip conditions co-located with the option that controls them.
|
|
9
|
-
*/ export class Step {
|
|
10
|
-
type;
|
|
11
|
-
when;
|
|
12
|
-
constructor(type, when){
|
|
13
|
-
this.type = type;
|
|
14
|
-
this.when = when;
|
|
15
|
-
}
|
|
16
|
-
}
|
package/es6/src/io/copy-file.js
DELETED
package/es6/src/io/read-file.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
export async function readFiles(filePaths, encoding = "utf8") {
|
|
3
|
-
const data = await Promise.all(filePaths.map((file)=>readFile(file.fullPath, encoding)));
|
|
4
|
-
return data;
|
|
5
|
-
}
|
|
6
|
-
export async function readFile(filePath, encoding = "utf8") {
|
|
7
|
-
const data = await fs.readFile(filePath, encoding);
|
|
8
|
-
return data;
|
|
9
|
-
}
|
|
10
|
-
export async function readJsonFile(filePath, encoding = "utf8") {
|
|
11
|
-
const data = await readFile(filePath, encoding);
|
|
12
|
-
return JSON.parse(data);
|
|
13
|
-
}
|
package/es6/src/io/remove-dir.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
package/es6/src/io/types/file.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { readFile } from "../read-file.js";
|
|
2
|
-
export class FileEx {
|
|
3
|
-
constructor(data){
|
|
4
|
-
this.fullPath = data.fullPath;
|
|
5
|
-
this.relativePath = data.relativePath ?? data.fullPath;
|
|
6
|
-
this.#content = data.content;
|
|
7
|
-
}
|
|
8
|
-
#content;
|
|
9
|
-
fullPath;
|
|
10
|
-
relativePath;
|
|
11
|
-
toString() {
|
|
12
|
-
return this.relativePath;
|
|
13
|
-
}
|
|
14
|
-
async getContent() {
|
|
15
|
-
if (this.#content != null) return this.#content;
|
|
16
|
-
return readFile(this.fullPath);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
2
|
-
export const fileUrlToPath = (url)=>{
|
|
3
|
-
try {
|
|
4
|
-
return fileURLToPath(url);
|
|
5
|
-
} catch {
|
|
6
|
-
return url;
|
|
7
|
-
}
|
|
8
|
-
};
|
|
9
|
-
export const pathToFileUrl = (path)=>{
|
|
10
|
-
try {
|
|
11
|
-
return pathToFileURL(path).toString();
|
|
12
|
-
} catch {
|
|
13
|
-
return path;
|
|
14
|
-
}
|
|
15
|
-
};
|
package/es6/src/io/write-file.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
export async function writeFile(filePath, content, options = {
|
|
4
|
-
encoding: "utf8",
|
|
5
|
-
mkdir: false
|
|
6
|
-
}) {
|
|
7
|
-
const { encoding, mkdir } = options;
|
|
8
|
-
if (mkdir) {
|
|
9
|
-
const directory = path.dirname(filePath);
|
|
10
|
-
await fs.mkdir(directory, {
|
|
11
|
-
recursive: true
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
await fs.writeFile(filePath, content, encoding);
|
|
15
|
-
}
|