@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.
Files changed (262) hide show
  1. package/commonjs/src/caching/cache-manager.js +98 -0
  2. package/commonjs/src/caching/cache.decorator.js +69 -0
  3. package/commonjs/src/caching/cache.js +6 -0
  4. package/commonjs/src/caching/index.js +23 -0
  5. package/commonjs/src/caching/invalidate-cache.decorator.js +92 -0
  6. package/commonjs/src/caching/memoize.decorator.js +36 -0
  7. package/commonjs/src/caching/node-cache-memoize.adapter.js +49 -0
  8. package/commonjs/src/cli/action.js +65 -0
  9. package/commonjs/src/cli/command.js +127 -0
  10. package/commonjs/src/cli/index.js +61 -0
  11. package/commonjs/src/cli/module.type.js +18 -0
  12. package/commonjs/src/cli/options.js +115 -0
  13. package/commonjs/src/collections/collections.js +21 -0
  14. package/commonjs/src/collections/find-duplicates.js +35 -0
  15. package/commonjs/src/collections/index.js +52 -0
  16. package/commonjs/src/collections/merge-arrays.js +34 -0
  17. package/commonjs/src/collections/sum.js +63 -0
  18. package/commonjs/src/collections/unique-objects.js +39 -0
  19. package/commonjs/src/composition/index.js +4 -0
  20. package/commonjs/src/configuration/configuration.types.js +11 -0
  21. package/commonjs/src/configuration/index.js +18 -0
  22. package/commonjs/src/diagnostics/index.js +22 -0
  23. package/commonjs/src/diagnostics/trace.js +86 -0
  24. package/commonjs/src/extensibility/decorator-factory-base.js +22 -0
  25. package/commonjs/src/extensibility/decorator-factory.js +31 -0
  26. package/commonjs/src/extensibility/extension.js +37 -0
  27. package/commonjs/src/extensibility/index.js +23 -0
  28. package/commonjs/src/extensibility/mixwith.js +36 -0
  29. package/commonjs/src/extensibility/pipeline.js +56 -0
  30. package/commonjs/src/extensibility/step.js +18 -0
  31. package/commonjs/src/interop/docker/docker.js +54 -0
  32. package/commonjs/src/interop/errors/interop.error.js +12 -0
  33. package/commonjs/src/interop/git/git.js +134 -0
  34. package/commonjs/src/interop/git/git.types.js +4 -0
  35. package/commonjs/src/interop/index.js +97 -0
  36. package/commonjs/src/interop/node/index.js +18 -0
  37. package/commonjs/src/interop/node/node.js +45 -0
  38. package/commonjs/src/interop/npm/npm.js +231 -0
  39. package/commonjs/src/interop/npm/npm.types.js +16 -0
  40. package/commonjs/src/interop/pnpm/pnpm.js +34 -0
  41. package/commonjs/src/interop/pnpm/pnpm.types.js +4 -0
  42. package/commonjs/src/interop/shell/shell.argv.js +45 -0
  43. package/commonjs/src/interop/shell/shell.js +105 -0
  44. package/commonjs/src/interop/shell/shell.types.js +4 -0
  45. package/commonjs/src/interop/types/detect-package-manager.js +71 -0
  46. package/commonjs/src/interop/types/package-manager.js +4 -0
  47. package/commonjs/src/interop/yarn/yarn.js +34 -0
  48. package/commonjs/src/interop/yarn/yarn.types.js +4 -0
  49. package/commonjs/src/io/copy-file.js +25 -0
  50. package/commonjs/src/io/delete-file.js +21 -0
  51. package/commonjs/src/io/directory-exists.js +24 -0
  52. package/commonjs/src/io/file-exists.js +19 -0
  53. package/commonjs/src/io/find-directories.js +21 -0
  54. package/commonjs/src/io/find-file.js +45 -0
  55. package/commonjs/src/io/index.js +66 -0
  56. package/commonjs/src/io/io.js +28 -0
  57. package/commonjs/src/io/read-file.js +39 -0
  58. package/commonjs/src/io/remove-dir.js +22 -0
  59. package/commonjs/src/io/types/directory.type.js +4 -0
  60. package/commonjs/src/io/types/file.js +28 -0
  61. package/commonjs/src/io/types/index.js +19 -0
  62. package/commonjs/src/io/url-to-path.js +33 -0
  63. package/commonjs/src/io/watch.js +261 -0
  64. package/commonjs/src/io/write-file.js +30 -0
  65. package/commonjs/src/objects/deep-merge.js +67 -0
  66. package/commonjs/src/objects/index.js +11 -0
  67. package/commonjs/src/reflection/index.js +20 -0
  68. package/commonjs/src/reflection/types/index.js +18 -0
  69. package/commonjs/src/reflection/types/reflection.types.js +26 -0
  70. package/commonjs/src/reflection/utilities.js +118 -0
  71. package/commonjs/src/semver/index.js +18 -0
  72. package/commonjs/src/semver/semver.js +92 -0
  73. package/commonjs/src/system/camel-case.js +13 -0
  74. package/commonjs/src/system/debounce.js +19 -0
  75. package/commonjs/src/system/decorator.js +46 -0
  76. package/commonjs/src/system/environment.js +23 -0
  77. package/commonjs/src/system/function.types.js +18 -0
  78. package/commonjs/src/system/index.js +24 -0
  79. package/commonjs/src/system/retry.decorator.js +40 -0
  80. package/commonjs/src/system/sleep.js +13 -0
  81. package/commonjs/src/system/type.utils.js +4 -0
  82. package/commonjs/src/testing/flush-promises.js +16 -0
  83. package/commonjs/src/testing/glob-with-memfs.js +22 -0
  84. package/commonjs/src/testing/index.js +22 -0
  85. package/commonjs/src/testing/memfs.js +52 -0
  86. package/commonjs/src/testing/mock-logger.js +36 -0
  87. package/commonjs/src/testing/spy-on-constructor.js +27 -0
  88. package/es6/src/caching/cache-manager.js +82 -0
  89. package/es6/src/caching/cache.decorator.js +51 -0
  90. package/es6/src/caching/cache.js +3 -0
  91. package/es6/src/caching/index.js +6 -0
  92. package/es6/src/caching/invalidate-cache.decorator.js +71 -0
  93. package/es6/src/caching/memoize.decorator.js +27 -0
  94. package/es6/src/caching/node-cache-memoize.adapter.js +37 -0
  95. package/es6/src/cli/action.js +47 -0
  96. package/es6/src/cli/command.js +106 -0
  97. package/es6/src/cli/index.js +4 -0
  98. package/es6/src/cli/module.type.js +11 -0
  99. package/es6/src/cli/options.js +76 -0
  100. package/es6/src/collections/collections.js +4 -0
  101. package/es6/src/collections/find-duplicates.js +17 -0
  102. package/es6/src/collections/index.js +1 -0
  103. package/es6/src/collections/merge-arrays.js +16 -0
  104. package/es6/src/collections/sum.js +45 -0
  105. package/es6/src/collections/unique-objects.js +21 -0
  106. package/es6/src/composition/index.js +1 -0
  107. package/es6/src/configuration/configuration.types.js +1 -0
  108. package/es6/src/configuration/index.js +1 -0
  109. package/es6/src/diagnostics/index.js +1 -0
  110. package/es6/src/diagnostics/trace.js +68 -0
  111. package/es6/src/extensibility/decorator-factory-base.js +39 -0
  112. package/es6/src/extensibility/decorator-factory.js +21 -0
  113. package/es6/src/extensibility/extension.js +27 -0
  114. package/es6/src/extensibility/index.js +6 -0
  115. package/es6/src/extensibility/mixwith.js +26 -0
  116. package/es6/src/extensibility/pipeline.js +46 -0
  117. package/es6/src/extensibility/step.js +16 -0
  118. package/es6/src/interop/docker/docker.js +44 -0
  119. package/es6/src/interop/errors/interop.error.js +2 -0
  120. package/es6/src/interop/git/git.js +124 -0
  121. package/es6/src/interop/git/git.types.js +1 -0
  122. package/es6/src/interop/index.js +21 -0
  123. package/es6/src/interop/node/index.js +1 -0
  124. package/es6/src/interop/node/node.js +35 -0
  125. package/es6/src/interop/npm/npm.js +180 -0
  126. package/es6/src/interop/npm/npm.types.js +6 -0
  127. package/es6/src/interop/pnpm/pnpm.js +24 -0
  128. package/es6/src/interop/pnpm/pnpm.types.js +1 -0
  129. package/es6/src/interop/shell/shell.argv.js +35 -0
  130. package/es6/src/interop/shell/shell.js +95 -0
  131. package/es6/src/interop/shell/shell.types.js +1 -0
  132. package/es6/src/interop/types/detect-package-manager.js +50 -0
  133. package/es6/src/interop/types/package-manager.js +1 -0
  134. package/es6/src/interop/yarn/yarn.js +24 -0
  135. package/es6/src/interop/yarn/yarn.types.js +1 -0
  136. package/es6/src/io/copy-file.js +10 -0
  137. package/es6/src/io/delete-file.js +6 -0
  138. package/es6/src/io/directory-exists.js +9 -0
  139. package/es6/src/io/file-exists.js +9 -0
  140. package/es6/src/io/find-directories.js +11 -0
  141. package/es6/src/io/find-file.js +27 -0
  142. package/es6/src/io/index.js +2 -0
  143. package/es6/src/io/io.js +11 -0
  144. package/es6/src/io/read-file.js +13 -0
  145. package/es6/src/io/remove-dir.js +7 -0
  146. package/es6/src/io/types/directory.type.js +1 -0
  147. package/es6/src/io/types/file.js +18 -0
  148. package/es6/src/io/types/index.js +2 -0
  149. package/es6/src/io/url-to-path.js +15 -0
  150. package/es6/src/io/watch.js +238 -0
  151. package/es6/src/io/write-file.js +15 -0
  152. package/es6/src/objects/deep-merge.js +57 -0
  153. package/es6/src/objects/index.js +1 -0
  154. package/es6/src/reflection/index.js +3 -0
  155. package/es6/src/reflection/types/index.js +1 -0
  156. package/es6/src/reflection/types/reflection.types.js +8 -0
  157. package/es6/src/reflection/utilities.js +74 -0
  158. package/es6/src/semver/index.js +1 -0
  159. package/es6/src/semver/semver.js +71 -0
  160. package/es6/src/system/camel-case.js +3 -0
  161. package/es6/src/system/debounce.js +9 -0
  162. package/es6/src/system/decorator.js +30 -0
  163. package/es6/src/system/environment.js +5 -0
  164. package/es6/src/system/function.types.js +26 -0
  165. package/es6/src/system/index.js +7 -0
  166. package/es6/src/system/retry.decorator.js +30 -0
  167. package/es6/src/system/sleep.js +3 -0
  168. package/es6/src/system/type.utils.js +1 -0
  169. package/es6/src/testing/flush-promises.js +6 -0
  170. package/es6/src/testing/glob-with-memfs.js +20 -0
  171. package/es6/src/testing/index.js +5 -0
  172. package/es6/src/testing/memfs.js +25 -0
  173. package/es6/src/testing/mock-logger.js +26 -0
  174. package/es6/src/testing/spy-on-constructor.js +31 -0
  175. package/package.json +106 -0
  176. package/types/src/caching/cache-manager.d.ts +59 -0
  177. package/types/src/caching/cache.d.ts +11 -0
  178. package/types/src/caching/cache.decorator.d.ts +18 -0
  179. package/types/src/caching/index.d.ts +6 -0
  180. package/types/src/caching/invalidate-cache.decorator.d.ts +17 -0
  181. package/types/src/caching/memoize.decorator.d.ts +16 -0
  182. package/types/src/caching/node-cache-memoize.adapter.d.ts +22 -0
  183. package/types/src/cli/action.d.ts +36 -0
  184. package/types/src/cli/command.d.ts +34 -0
  185. package/types/src/cli/index.d.ts +7 -0
  186. package/types/src/cli/module.type.d.ts +36 -0
  187. package/types/src/cli/options.d.ts +28 -0
  188. package/types/src/collections/collections.d.ts +4 -0
  189. package/types/src/collections/find-duplicates.d.ts +2 -0
  190. package/types/src/collections/index.d.ts +1 -0
  191. package/types/src/collections/merge-arrays.d.ts +2 -0
  192. package/types/src/collections/sum.d.ts +4 -0
  193. package/types/src/collections/unique-objects.d.ts +2 -0
  194. package/types/src/composition/index.d.ts +37 -0
  195. package/types/src/configuration/configuration.types.d.ts +10 -0
  196. package/types/src/configuration/index.d.ts +1 -0
  197. package/types/src/diagnostics/index.d.ts +1 -0
  198. package/types/src/diagnostics/trace.d.ts +10 -0
  199. package/types/src/extensibility/decorator-factory-base.d.ts +39 -0
  200. package/types/src/extensibility/decorator-factory.d.ts +19 -0
  201. package/types/src/extensibility/extension.d.ts +9 -0
  202. package/types/src/extensibility/index.d.ts +6 -0
  203. package/types/src/extensibility/mixwith.d.ts +6 -0
  204. package/types/src/extensibility/pipeline.d.ts +12 -0
  205. package/types/src/extensibility/step.d.ts +16 -0
  206. package/types/src/interop/docker/docker.d.ts +19 -0
  207. package/types/src/interop/errors/interop.error.d.ts +2 -0
  208. package/types/src/interop/git/git.d.ts +16 -0
  209. package/types/src/interop/git/git.types.d.ts +14 -0
  210. package/types/src/interop/index.d.ts +14 -0
  211. package/types/src/interop/node/index.d.ts +1 -0
  212. package/types/src/interop/node/node.d.ts +5 -0
  213. package/types/src/interop/npm/npm.d.ts +29 -0
  214. package/types/src/interop/npm/npm.types.d.ts +24 -0
  215. package/types/src/interop/pnpm/pnpm.d.ts +9 -0
  216. package/types/src/interop/pnpm/pnpm.types.d.ts +3 -0
  217. package/types/src/interop/shell/shell.argv.d.ts +5 -0
  218. package/types/src/interop/shell/shell.d.ts +6 -0
  219. package/types/src/interop/shell/shell.types.d.ts +9 -0
  220. package/types/src/interop/types/detect-package-manager.d.ts +4 -0
  221. package/types/src/interop/types/package-manager.d.ts +10 -0
  222. package/types/src/interop/yarn/yarn.d.ts +9 -0
  223. package/types/src/interop/yarn/yarn.types.d.ts +3 -0
  224. package/types/src/io/copy-file.d.ts +4 -0
  225. package/types/src/io/delete-file.d.ts +1 -0
  226. package/types/src/io/directory-exists.d.ts +1 -0
  227. package/types/src/io/file-exists.d.ts +1 -0
  228. package/types/src/io/find-directories.d.ts +2 -0
  229. package/types/src/io/find-file.d.ts +9 -0
  230. package/types/src/io/index.d.ts +2 -0
  231. package/types/src/io/io.d.ts +11 -0
  232. package/types/src/io/read-file.d.ts +4 -0
  233. package/types/src/io/remove-dir.d.ts +5 -0
  234. package/types/src/io/types/directory.type.d.ts +4 -0
  235. package/types/src/io/types/file.d.ts +20 -0
  236. package/types/src/io/types/index.d.ts +2 -0
  237. package/types/src/io/url-to-path.d.ts +2 -0
  238. package/types/src/io/watch.d.ts +16 -0
  239. package/types/src/io/write-file.d.ts +5 -0
  240. package/types/src/objects/deep-merge.d.ts +41 -0
  241. package/types/src/objects/index.d.ts +1 -0
  242. package/types/src/reflection/index.d.ts +3 -0
  243. package/types/src/reflection/types/index.d.ts +1 -0
  244. package/types/src/reflection/types/reflection.types.d.ts +21 -0
  245. package/types/src/reflection/utilities.d.ts +27 -0
  246. package/types/src/semver/index.d.ts +1 -0
  247. package/types/src/semver/semver.d.ts +18 -0
  248. package/types/src/system/camel-case.d.ts +1 -0
  249. package/types/src/system/debounce.d.ts +1 -0
  250. package/types/src/system/decorator.d.ts +15 -0
  251. package/types/src/system/environment.d.ts +6 -0
  252. package/types/src/system/function.types.d.ts +55 -0
  253. package/types/src/system/index.d.ts +7 -0
  254. package/types/src/system/retry.decorator.d.ts +6 -0
  255. package/types/src/system/sleep.d.ts +1 -0
  256. package/types/src/system/type.utils.d.ts +1 -0
  257. package/types/src/testing/flush-promises.d.ts +1 -0
  258. package/types/src/testing/glob-with-memfs.d.ts +3 -0
  259. package/types/src/testing/index.d.ts +5 -0
  260. package/types/src/testing/memfs.d.ts +5 -0
  261. package/types/src/testing/mock-logger.d.ts +13 -0
  262. package/types/src/testing/spy-on-constructor.d.ts +21 -0
@@ -0,0 +1,98 @@
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 _nodecachememoizeadapter = require("./node-cache-memoize.adapter.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 = _nodecachememoizeadapter.NodeCacheAdapter.create({
44
+ enableMemoization: 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();
@@ -0,0 +1,69 @@
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;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Interface for cache implementations used by the @cache() decorator
3
+ */ "use strict";
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
@@ -0,0 +1,23 @@
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("./node-cache-memoize.adapter.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
+ }
@@ -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 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
+ };
@@ -0,0 +1,36 @@
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;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "NodeCacheAdapter", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return NodeCacheAdapter;
9
+ }
10
+ });
11
+ const _nodecache = /*#__PURE__*/ _interop_require_default(require("@cacheable/node-cache"));
12
+ function _interop_require_default(obj) {
13
+ return obj && obj.__esModule ? obj : {
14
+ default: obj
15
+ };
16
+ }
17
+ class NodeCacheAdapter {
18
+ static create(options = {
19
+ enableMemoization: false
20
+ }) {
21
+ const nodeCache = new _nodecache.default({
22
+ useClones: !options.enableMemoization
23
+ });
24
+ return new NodeCacheAdapter(nodeCache);
25
+ }
26
+ supportsMemoization = true;
27
+ cache;
28
+ constructor(inst = new _nodecache.default()){
29
+ this.cache = inst;
30
+ }
31
+ get isMemoize() {
32
+ return !this.cache.options.useClones;
33
+ }
34
+ get(key) {
35
+ return this.cache.get(key);
36
+ }
37
+ set(key, value) {
38
+ this.cache.set(key, value);
39
+ }
40
+ has(key) {
41
+ return this.cache.has(key);
42
+ }
43
+ del(key) {
44
+ this.cache.del(key);
45
+ }
46
+ flushAll() {
47
+ this.cache.flushAll();
48
+ }
49
+ }
@@ -0,0 +1,65 @@
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 ActionMap () {
13
+ return ActionMap;
14
+ },
15
+ get ActionResponse () {
16
+ return ActionResponse;
17
+ }
18
+ });
19
+ const ActionMap = Symbol("ActionMap");
20
+ class ActionResponse {
21
+ static Success(name, data) {
22
+ return new ActionResponse({
23
+ name,
24
+ data,
25
+ succeeded: true
26
+ });
27
+ }
28
+ static Skipped(name) {
29
+ return new ActionResponse({
30
+ name,
31
+ skipped: true
32
+ });
33
+ }
34
+ static Blocking(name) {
35
+ return new ActionResponse({
36
+ name,
37
+ succeeded: true,
38
+ blocking: true
39
+ });
40
+ }
41
+ static Error(name, messageOrData, data) {
42
+ if (Array.isArray(messageOrData)) {
43
+ const message = messageOrData.filter((r)=>!r.succeeded).map((r)=>r.error ?? "Unknown error").join("\n");
44
+ return new ActionResponse({
45
+ name,
46
+ message,
47
+ data: messageOrData
48
+ });
49
+ }
50
+ return new ActionResponse({
51
+ name,
52
+ message: messageOrData,
53
+ data
54
+ });
55
+ }
56
+ constructor(data){
57
+ Object.assign(this, data);
58
+ }
59
+ name;
60
+ succeeded = false;
61
+ skipped = false;
62
+ blocking = false;
63
+ message;
64
+ data;
65
+ }
@@ -0,0 +1,127 @@
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 CommandError () {
13
+ return CommandError;
14
+ },
15
+ get CommandResponse () {
16
+ return CommandResponse;
17
+ },
18
+ get DecohereCommand () {
19
+ return DecohereCommand;
20
+ }
21
+ });
22
+ const _commander = require("commander");
23
+ const CommandResponse = {
24
+ success (_ctx, responses) {
25
+ return responses;
26
+ },
27
+ help () {
28
+ return {};
29
+ },
30
+ fromAction (name, response) {
31
+ return {
32
+ [name]: response
33
+ };
34
+ }
35
+ };
36
+ class CommandError extends Error {
37
+ }
38
+ class DecohereCommand extends _commander.Command {
39
+ get actions() {
40
+ return [];
41
+ }
42
+ constructor(name, handler){
43
+ super();
44
+ if (typeof name === "string" || typeof name === "function") {
45
+ this.name(this.parseCommandName(name));
46
+ } else {
47
+ this.name(this.parseCommandName(this.constructor));
48
+ if (name) {
49
+ this.registerSubcommand(name, handler);
50
+ }
51
+ }
52
+ if (handler && !this.commands.length) {
53
+ this.action(handler);
54
+ }
55
+ this.exitOverride();
56
+ }
57
+ /**
58
+ * Whether the command, with these options, runs until it is stopped (`flux serve`,
59
+ * `forge build --watch`). The CLI then listens for SIGINT and SIGTERM from the moment it
60
+ * starts, so a stop during start-up still shuts down cleanly; other commands keep Node's
61
+ * default, where Ctrl+C ends them at once.
62
+ */ runsUntilStopped(_options) {
63
+ return false;
64
+ }
65
+ async run(actions, options) {
66
+ const responses = await this.runActions(actions, options);
67
+ this.throwOnErrors(responses);
68
+ return CommandResponse.success(options, responses);
69
+ }
70
+ registerSubcommand(commands, onAction) {
71
+ if (typeof commands === "function") {
72
+ const instance = new commands(commands, onAction);
73
+ this.addCommand(instance);
74
+ if (onAction && !instance.commands.length) {
75
+ instance.action(onAction);
76
+ }
77
+ return;
78
+ }
79
+ for (const [key, command] of Object.entries(commands)){
80
+ const instance = command instanceof DecohereCommand ? command : new command(key, onAction);
81
+ this.addCommand(instance);
82
+ if (onAction && !instance.commands.length) {
83
+ instance.action(onAction);
84
+ }
85
+ }
86
+ }
87
+ async runActions(actions, options) {
88
+ const selectedActions = this.getSelectedActions(actions);
89
+ const responses = {};
90
+ for (const [actionKey, action] of selectedActions){
91
+ responses[actionKey] = await action.run(options);
92
+ }
93
+ return responses;
94
+ }
95
+ getSelectedActions(actions) {
96
+ if (!this.actions.length) {
97
+ return [];
98
+ }
99
+ const actionEntries = Object.entries(actions);
100
+ return this.actions.map((ActionClass)=>{
101
+ const selectedAction = actionEntries.find(([, action])=>action instanceof ActionClass);
102
+ if (!selectedAction) {
103
+ throw new CommandError(`${this.name()} command missing action instance for ${ActionClass.name}`);
104
+ }
105
+ return selectedAction;
106
+ });
107
+ }
108
+ throwOnErrors(responses) {
109
+ const failures = Object.entries(responses).filter(([, response])=>{
110
+ if (!response) {
111
+ return false;
112
+ }
113
+ return !response.succeeded && !response.skipped;
114
+ });
115
+ if (!failures.length) {
116
+ return;
117
+ }
118
+ throw new CommandError(`${this.name()} command failed. ${failures.map(([actionName, response])=>`${actionName}: ${response?.message ?? "Unknown error"}`).join("\n")}`);
119
+ }
120
+ parseCommandName(stringLike) {
121
+ const command = typeof stringLike === "string" ? stringLike : stringLike.name?.toLowerCase().replace("command", "") ?? "";
122
+ if (command === "") {
123
+ throw new CommandError(`Could not parse command name from ${stringLike.toString()}`);
124
+ }
125
+ return command;
126
+ }
127
+ }
@@ -0,0 +1,61 @@
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 ActionMap () {
13
+ return _action.ActionMap;
14
+ },
15
+ get ActionResponse () {
16
+ return _action.ActionResponse;
17
+ },
18
+ get CommandError () {
19
+ return _command.CommandError;
20
+ },
21
+ get CommandResponse () {
22
+ return _command.CommandResponse;
23
+ },
24
+ get ConfigFileOption () {
25
+ return _options.ConfigFileOption;
26
+ },
27
+ get ConfigurationOption () {
28
+ return _options.ConfigurationOption;
29
+ },
30
+ get DecohereCommand () {
31
+ return _command.DecohereCommand;
32
+ },
33
+ get DryRunOption () {
34
+ return _options.DryRunOption;
35
+ },
36
+ get EnvFileIfExistsOption () {
37
+ return _options.EnvFileIfExistsOption;
38
+ },
39
+ get EnvFileOption () {
40
+ return _options.EnvFileOption;
41
+ },
42
+ get LogLevelOption () {
43
+ return _options.LogLevelOption;
44
+ },
45
+ get ModuleManifest () {
46
+ return _moduletype.ModuleManifest;
47
+ },
48
+ get NoBuildOptions () {
49
+ return _options.NoBuildOptions;
50
+ },
51
+ get NoCleanOptions () {
52
+ return _options.NoCleanOptions;
53
+ },
54
+ get ProjectOption () {
55
+ return _options.ProjectOption;
56
+ }
57
+ });
58
+ const _action = require("./action.js");
59
+ const _command = require("./command.js");
60
+ const _moduletype = require("./module.type.js");
61
+ const _options = require("./options.js");
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "ModuleManifest", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return ModuleManifest;
9
+ }
10
+ });
11
+ class ModuleManifest {
12
+ /** Sub-command classes this module contributes. */ commands = {};
13
+ /** Action classes this module contributes. */ actions = {};
14
+ /** Register infrastructure services into the DI container. */ registerServices(_builder) {}
15
+ /** Lazily create a workspace instance. Return null if this module does not use a workspace. */ createWorkspace(_options) {
16
+ return Promise.resolve(null);
17
+ }
18
+ }