@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.
Files changed (252) hide show
  1. package/package.json +40 -15
  2. package/src/caching/cache-manager.ts +102 -0
  3. package/src/caching/cache.decorator.ts +56 -0
  4. package/src/caching/cache.ts +11 -0
  5. package/{es6/src/caching/index.js → src/caching/index.ts} +1 -1
  6. package/src/caching/invalidate-cache.decorator.ts +81 -0
  7. package/src/caching/memoize.decorator.ts +34 -0
  8. package/src/caching/node-cache-memoize.adapter.ts +47 -0
  9. package/src/cli/action.ts +77 -0
  10. package/src/cli/command.ts +173 -0
  11. package/src/cli/index.ts +30 -0
  12. package/src/cli/module.type.ts +48 -0
  13. package/src/cli/options.ts +81 -0
  14. package/src/collections/find-duplicates.ts +16 -0
  15. package/src/collections/merge-arrays.ts +9 -0
  16. package/src/collections/sum.ts +71 -0
  17. package/src/collections/unique-objects.ts +23 -0
  18. package/src/composition/index.ts +48 -0
  19. package/src/configuration/configuration.types.ts +13 -0
  20. package/src/diagnostics/index.ts +1 -0
  21. package/src/diagnostics/trace.ts +97 -0
  22. package/{es6/src/extensibility/decorator-factory-base.js → src/extensibility/decorator-factory-base.ts} +17 -9
  23. package/src/extensibility/decorator-factory.ts +44 -0
  24. package/src/extensibility/extension.ts +34 -0
  25. package/src/extensibility/mixwith.ts +42 -0
  26. package/src/extensibility/pipeline.ts +60 -0
  27. package/{types/src/extensibility/step.d.ts → src/extensibility/step.ts} +6 -4
  28. package/src/interop/docker/docker.ts +57 -0
  29. package/src/interop/errors/interop.error.ts +1 -0
  30. package/src/interop/git/git.ts +98 -0
  31. package/src/interop/git/git.types.ts +17 -0
  32. package/src/interop/index.ts +22 -0
  33. package/src/interop/node/index.ts +1 -0
  34. package/src/interop/node/node.ts +38 -0
  35. package/src/interop/npm/npm.ts +168 -0
  36. package/src/interop/npm/npm.types.ts +28 -0
  37. package/src/interop/pnpm/pnpm.ts +22 -0
  38. package/src/interop/pnpm/pnpm.types.ts +3 -0
  39. package/src/interop/shell/shell.argv.ts +31 -0
  40. package/src/interop/shell/shell.ts +100 -0
  41. package/src/interop/shell/shell.types.ts +9 -0
  42. package/src/interop/types/detect-package-manager.ts +45 -0
  43. package/src/interop/types/package-manager.ts +7 -0
  44. package/src/interop/yarn/yarn.ts +28 -0
  45. package/src/interop/yarn/yarn.types.ts +3 -0
  46. package/src/io/copy-file.ts +13 -0
  47. package/src/io/delete-file.ts +4 -0
  48. package/src/io/directory-exists.ts +9 -0
  49. package/src/io/file-exists.ts +10 -0
  50. package/src/io/find-directories.ts +13 -0
  51. package/src/io/find-file.ts +37 -0
  52. package/{es6/src/io/io.js → src/io/io.ts} +3 -0
  53. package/src/io/read-file.ts +25 -0
  54. package/src/io/remove-dir.ts +11 -0
  55. package/src/io/types/directory.type.ts +4 -0
  56. package/src/io/types/file.ts +34 -0
  57. package/src/io/url-to-path.ts +17 -0
  58. package/src/io/watch.ts +290 -0
  59. package/src/io/write-file.ts +21 -0
  60. package/src/objects/deep-merge.ts +131 -0
  61. package/{es6/src/reflection/index.js → src/reflection/index.ts} +1 -0
  62. package/src/reflection/types/reflection.types.ts +28 -0
  63. package/src/reflection/utilities.ts +92 -0
  64. package/src/semver/index.ts +1 -0
  65. package/src/semver/semver.ts +96 -0
  66. package/src/system/camel-case.ts +3 -0
  67. package/src/system/debounce.ts +13 -0
  68. package/src/system/decorator.ts +41 -0
  69. package/src/system/environment.ts +6 -0
  70. package/{types/src/system/function.types.d.ts → src/system/function.types.ts} +10 -2
  71. package/src/system/retry.decorator.ts +43 -0
  72. package/src/system/sleep.ts +6 -0
  73. package/src/system/type.utils.ts +5 -0
  74. package/src/testing/flush-promises.ts +7 -0
  75. package/src/testing/glob-with-memfs.ts +25 -0
  76. package/src/testing/index.ts +5 -0
  77. package/src/testing/memfs.ts +28 -0
  78. package/src/testing/mock-logger.ts +42 -0
  79. package/src/testing/spy-on-constructor.ts +33 -0
  80. package/tests/caching/cache-manager.spec.ts +147 -0
  81. package/tests/caching/cache-test-class.ts +91 -0
  82. package/tests/caching/cache.decorator.spec.ts +259 -0
  83. package/tests/caching/invalidate-cache-test-class.ts +52 -0
  84. package/tests/caching/invalidate-cache.decorator.spec.ts +120 -0
  85. package/tests/caching/memoize-test-class.ts +99 -0
  86. package/tests/caching/memoize.decorator.spec.ts +203 -0
  87. package/tests/cli/command.model.spec.ts +91 -0
  88. package/tests/collections/merge-arrays.spec.ts +50 -0
  89. package/tests/collections/sum.spec.ts +86 -0
  90. package/tests/collections/unique-objects.spec.ts +233 -0
  91. package/tests/extensibility/extension.spec.ts +29 -0
  92. package/tests/extensibility/pipeline.spec.ts +379 -0
  93. package/tests/interop/detect-package-manager.spec.ts +70 -0
  94. package/tests/interop/npm.spec.ts +129 -0
  95. package/tests/interop/pnpm.spec.ts +30 -0
  96. package/tests/interop/shell.spec.ts +47 -0
  97. package/tests/interop/yarn.spec.ts +18 -0
  98. package/tests/io/find-file.spec.ts +188 -0
  99. package/tests/io/watch.real-fs.spec.ts +76 -0
  100. package/tests/io/watch.spec.ts +291 -0
  101. package/tests/mock-prototype.ts +12 -0
  102. package/tests/semver/semver.spec.ts +51 -0
  103. package/tests/system/decorator.spec.ts +250 -0
  104. package/tests/system/retry.decorator.spec.ts +57 -0
  105. package/LICENSE +0 -15
  106. package/commonjs/src/caching/cache-manager.js +0 -98
  107. package/commonjs/src/caching/cache.decorator.js +0 -69
  108. package/commonjs/src/caching/cache.js +0 -6
  109. package/commonjs/src/caching/index.js +0 -23
  110. package/commonjs/src/caching/invalidate-cache.decorator.js +0 -92
  111. package/commonjs/src/caching/map-cache.js +0 -39
  112. package/commonjs/src/caching/memoize.decorator.js +0 -36
  113. package/commonjs/src/collections/collections.js +0 -21
  114. package/commonjs/src/collections/find-duplicates.js +0 -35
  115. package/commonjs/src/collections/index.js +0 -52
  116. package/commonjs/src/collections/merge-arrays.js +0 -34
  117. package/commonjs/src/collections/sum.js +0 -63
  118. package/commonjs/src/collections/unique-objects.js +0 -39
  119. package/commonjs/src/composition/index.js +0 -4
  120. package/commonjs/src/configuration/configuration.types.js +0 -11
  121. package/commonjs/src/configuration/index.js +0 -18
  122. package/commonjs/src/extensibility/decorator-factory-base.js +0 -22
  123. package/commonjs/src/extensibility/decorator-factory.js +0 -31
  124. package/commonjs/src/extensibility/extension.js +0 -37
  125. package/commonjs/src/extensibility/index.js +0 -23
  126. package/commonjs/src/extensibility/mixwith.js +0 -36
  127. package/commonjs/src/extensibility/pipeline.js +0 -56
  128. package/commonjs/src/extensibility/step.js +0 -18
  129. package/commonjs/src/io/copy-file.js +0 -25
  130. package/commonjs/src/io/delete-file.js +0 -21
  131. package/commonjs/src/io/directory-exists.js +0 -24
  132. package/commonjs/src/io/file-exists.js +0 -19
  133. package/commonjs/src/io/index.js +0 -66
  134. package/commonjs/src/io/io.js +0 -25
  135. package/commonjs/src/io/read-file.js +0 -39
  136. package/commonjs/src/io/remove-dir.js +0 -22
  137. package/commonjs/src/io/types/directory.type.js +0 -4
  138. package/commonjs/src/io/types/file.js +0 -28
  139. package/commonjs/src/io/types/index.js +0 -19
  140. package/commonjs/src/io/url-to-path.js +0 -33
  141. package/commonjs/src/io/write-file.js +0 -30
  142. package/commonjs/src/objects/deep-merge.js +0 -67
  143. package/commonjs/src/objects/index.js +0 -11
  144. package/commonjs/src/reflection/index.js +0 -20
  145. package/commonjs/src/reflection/types/index.js +0 -18
  146. package/commonjs/src/reflection/types/reflection.types.js +0 -26
  147. package/commonjs/src/reflection/utilities.js +0 -118
  148. package/commonjs/src/system/camel-case.js +0 -13
  149. package/commonjs/src/system/debounce.js +0 -19
  150. package/commonjs/src/system/decorator.js +0 -46
  151. package/commonjs/src/system/environment.js +0 -23
  152. package/commonjs/src/system/function.types.js +0 -18
  153. package/commonjs/src/system/index.js +0 -24
  154. package/commonjs/src/system/retry.decorator.js +0 -40
  155. package/commonjs/src/system/sleep.js +0 -13
  156. package/commonjs/src/system/type.utils.js +0 -4
  157. package/es6/src/caching/cache-manager.js +0 -82
  158. package/es6/src/caching/cache.decorator.js +0 -51
  159. package/es6/src/caching/cache.js +0 -3
  160. package/es6/src/caching/invalidate-cache.decorator.js +0 -71
  161. package/es6/src/caching/map-cache.js +0 -35
  162. package/es6/src/caching/memoize.decorator.js +0 -27
  163. package/es6/src/collections/find-duplicates.js +0 -17
  164. package/es6/src/collections/merge-arrays.js +0 -16
  165. package/es6/src/collections/sum.js +0 -45
  166. package/es6/src/collections/unique-objects.js +0 -21
  167. package/es6/src/composition/index.js +0 -1
  168. package/es6/src/configuration/configuration.types.js +0 -1
  169. package/es6/src/extensibility/decorator-factory.js +0 -21
  170. package/es6/src/extensibility/extension.js +0 -27
  171. package/es6/src/extensibility/mixwith.js +0 -26
  172. package/es6/src/extensibility/pipeline.js +0 -46
  173. package/es6/src/extensibility/step.js +0 -16
  174. package/es6/src/io/copy-file.js +0 -10
  175. package/es6/src/io/delete-file.js +0 -6
  176. package/es6/src/io/directory-exists.js +0 -9
  177. package/es6/src/io/file-exists.js +0 -9
  178. package/es6/src/io/read-file.js +0 -13
  179. package/es6/src/io/remove-dir.js +0 -7
  180. package/es6/src/io/types/directory.type.js +0 -1
  181. package/es6/src/io/types/file.js +0 -18
  182. package/es6/src/io/url-to-path.js +0 -15
  183. package/es6/src/io/write-file.js +0 -15
  184. package/es6/src/objects/deep-merge.js +0 -57
  185. package/es6/src/reflection/types/reflection.types.js +0 -8
  186. package/es6/src/reflection/utilities.js +0 -74
  187. package/es6/src/system/camel-case.js +0 -3
  188. package/es6/src/system/debounce.js +0 -9
  189. package/es6/src/system/decorator.js +0 -30
  190. package/es6/src/system/environment.js +0 -5
  191. package/es6/src/system/function.types.js +0 -26
  192. package/es6/src/system/retry.decorator.js +0 -30
  193. package/es6/src/system/sleep.js +0 -3
  194. package/es6/src/system/type.utils.js +0 -1
  195. package/types/src/caching/cache-manager.d.ts +0 -59
  196. package/types/src/caching/cache.d.ts +0 -11
  197. package/types/src/caching/cache.decorator.d.ts +0 -18
  198. package/types/src/caching/index.d.ts +0 -6
  199. package/types/src/caching/invalidate-cache.decorator.d.ts +0 -17
  200. package/types/src/caching/map-cache.d.ts +0 -23
  201. package/types/src/caching/memoize.decorator.d.ts +0 -16
  202. package/types/src/collections/collections.d.ts +0 -4
  203. package/types/src/collections/find-duplicates.d.ts +0 -2
  204. package/types/src/collections/index.d.ts +0 -1
  205. package/types/src/collections/merge-arrays.d.ts +0 -2
  206. package/types/src/collections/sum.d.ts +0 -4
  207. package/types/src/collections/unique-objects.d.ts +0 -2
  208. package/types/src/composition/index.d.ts +0 -37
  209. package/types/src/configuration/configuration.types.d.ts +0 -10
  210. package/types/src/configuration/index.d.ts +0 -1
  211. package/types/src/extensibility/decorator-factory-base.d.ts +0 -39
  212. package/types/src/extensibility/decorator-factory.d.ts +0 -19
  213. package/types/src/extensibility/extension.d.ts +0 -9
  214. package/types/src/extensibility/index.d.ts +0 -6
  215. package/types/src/extensibility/mixwith.d.ts +0 -6
  216. package/types/src/extensibility/pipeline.d.ts +0 -12
  217. package/types/src/io/copy-file.d.ts +0 -4
  218. package/types/src/io/delete-file.d.ts +0 -1
  219. package/types/src/io/directory-exists.d.ts +0 -1
  220. package/types/src/io/file-exists.d.ts +0 -1
  221. package/types/src/io/index.d.ts +0 -2
  222. package/types/src/io/io.d.ts +0 -8
  223. package/types/src/io/read-file.d.ts +0 -4
  224. package/types/src/io/remove-dir.d.ts +0 -5
  225. package/types/src/io/types/directory.type.d.ts +0 -4
  226. package/types/src/io/types/file.d.ts +0 -20
  227. package/types/src/io/types/index.d.ts +0 -2
  228. package/types/src/io/url-to-path.d.ts +0 -2
  229. package/types/src/io/write-file.d.ts +0 -5
  230. package/types/src/objects/deep-merge.d.ts +0 -41
  231. package/types/src/objects/index.d.ts +0 -1
  232. package/types/src/reflection/index.d.ts +0 -3
  233. package/types/src/reflection/types/index.d.ts +0 -1
  234. package/types/src/reflection/types/reflection.types.d.ts +0 -21
  235. package/types/src/reflection/utilities.d.ts +0 -27
  236. package/types/src/system/camel-case.d.ts +0 -1
  237. package/types/src/system/debounce.d.ts +0 -1
  238. package/types/src/system/decorator.d.ts +0 -15
  239. package/types/src/system/environment.d.ts +0 -6
  240. package/types/src/system/index.d.ts +0 -7
  241. package/types/src/system/retry.decorator.d.ts +0 -6
  242. package/types/src/system/sleep.d.ts +0 -1
  243. package/types/src/system/type.utils.d.ts +0 -1
  244. /package/{es6/src/collections/collections.js → src/collections/collections.ts} +0 -0
  245. /package/{es6/src/collections/index.js → src/collections/index.ts} +0 -0
  246. /package/{es6/src/configuration/index.js → src/configuration/index.ts} +0 -0
  247. /package/{es6/src/extensibility/index.js → src/extensibility/index.ts} +0 -0
  248. /package/{es6/src/io/index.js → src/io/index.ts} +0 -0
  249. /package/{es6/src/io/types/index.js → src/io/types/index.ts} +0 -0
  250. /package/{es6/src/objects/index.js → src/objects/index.ts} +0 -0
  251. /package/{es6/src/reflection/types/index.js → src/reflection/types/index.ts} +0 -0
  252. /package/{es6/src/system/index.js → src/system/index.ts} +0 -0
@@ -1,57 +0,0 @@
1
- // Source https://github.com/voodoocreation/ts-deepmerge/blob/master/package.json
2
- // istanbul ignore next
3
- const isObject = (obj)=>{
4
- if (typeof obj === "object" && obj !== null) {
5
- if (typeof Object.getPrototypeOf === "function") {
6
- const prototype = Object.getPrototypeOf(obj);
7
- return prototype === Object.prototype || prototype === null;
8
- }
9
- return Object.prototype.toString.call(obj) === "[object Object]";
10
- }
11
- return false;
12
- };
13
- export const merge = (...objects)=>objects.reduce((result, current)=>{
14
- if (current === undefined) {
15
- return result;
16
- }
17
- if (Array.isArray(current)) {
18
- throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");
19
- }
20
- Object.keys(current).forEach((key)=>{
21
- if ([
22
- "__proto__",
23
- "constructor",
24
- "prototype"
25
- ].includes(key)) {
26
- return;
27
- }
28
- if (Array.isArray(result[key]) && Array.isArray(current[key])) {
29
- result[key] = merge.options.mergeArrays ? merge.options.uniqueArrayItems ? Array.from(new Set(result[key].concat(current[key]))) : [
30
- ...result[key],
31
- ...current[key]
32
- ] : current[key];
33
- } else if (isObject(result[key]) && isObject(current[key])) {
34
- result[key] = merge(result[key], current[key]);
35
- } else if (!isObject(result[key]) && isObject(current[key])) {
36
- result[key] = merge(current[key], undefined);
37
- } else {
38
- result[key] = current[key] === undefined ? merge.options.allowUndefinedOverrides ? current[key] : result[key] : current[key];
39
- }
40
- });
41
- return result;
42
- }, {});
43
- const defaultOptions = {
44
- allowUndefinedOverrides: true,
45
- mergeArrays: true,
46
- uniqueArrayItems: true
47
- };
48
- merge.options = defaultOptions;
49
- merge.withOptions = (options, ...objects)=>{
50
- merge.options = {
51
- ...defaultOptions,
52
- ...options
53
- };
54
- const result = merge(...objects);
55
- merge.options = defaultOptions;
56
- return result;
57
- };
@@ -1,8 +0,0 @@
1
- export const MetaDataOwners = {
2
- Hearth: "hearth",
3
- Reflect: "design"
4
- };
5
- export const ReflectionMeta = {
6
- paramtypes: `${MetaDataOwners.Reflect}:paramtypes`,
7
- type: `${MetaDataOwners.Reflect}:type`
8
- };
@@ -1,74 +0,0 @@
1
- import { ReflectionMeta } from "./types/reflection.types.js";
2
- const Primitives = [
3
- "string",
4
- "number",
5
- "bigint",
6
- "boolean",
7
- "undefined",
8
- "symbol",
9
- "null"
10
- ];
11
- export const isPrimitiveOrDateType = (type)=>{
12
- return Primitives.includes(type.name.toLocaleLowerCase()) || isDateType(type);
13
- };
14
- export const isDateType = (type)=>{
15
- return type?.prototype === Date.prototype;
16
- };
17
- export function isConstructable(type) {
18
- const proto = type?.prototype;
19
- const isConstructable = typeof type === "function" && typeof proto === "object";
20
- return isConstructable;
21
- }
22
- export const isArrayType = (type)=>{
23
- return type?.prototype === Array.prototype;
24
- };
25
- export function getMeta(key, target, propertyKey) {
26
- const meta = Reflect.getMetadata(key, target, propertyKey);
27
- return meta;
28
- }
29
- export function getFunctions(object) {
30
- const functions = Object.entries(Object.getOwnPropertyDescriptors(object.prototype)).filter(([key])=>key !== "constructor").map(([, value])=>value);
31
- return functions;
32
- }
33
- export function getFunction(object, functionName) {
34
- const [, value] = Object.entries(Object.getOwnPropertyDescriptors(object.prototype)).find(([k])=>k !== "constructor" && k === functionName);
35
- return value;
36
- }
37
- export function getFunctionMetadata(key, target, func) {
38
- const meta = Reflect.getMetadata(key, target, func.name);
39
- return meta;
40
- }
41
- export function getFunctionArgs(target, func) {
42
- const meta = getFunctionMetadata(ReflectionMeta.paramtypes, target, func);
43
- return meta;
44
- }
45
- /**
46
- * @description Gets the fields from an object
47
- * @param object
48
- * @returns
49
- */ export function getFields(object) {
50
- const fields = Object.entries(Object.getOwnPropertyDescriptors(object)).filter(([, val])=>typeof val.value !== "function").map(([key, propertyDescriptor])=>({
51
- key,
52
- propertyDescriptor
53
- }));
54
- return fields;
55
- }
56
- export function getFieldType(target, fieldName) {
57
- return Reflect.getMetadata(ReflectionMeta.type, target, fieldName);
58
- }
59
- export function getArgumentMeta(key, target, argIndex) {
60
- const meta = Reflect.getMetadata(key, target, argIndex.toString());
61
- return meta;
62
- }
63
- export function defineMeta(key, value, target) {
64
- Reflect.defineMetadata(key, value, target);
65
- }
66
- /**
67
- * @description Facade function to define metadata for a function argument
68
- * @param key
69
- * @param value
70
- * @param func
71
- * @param argIndex
72
- */ export function defineArgumentMeta(key, value, func, argIndex) {
73
- Reflect.defineMetadata(key, value, func, argIndex.toString());
74
- }
@@ -1,3 +0,0 @@
1
- export function lowerCamelCase(val) {
2
- return String(val).charAt(0).toLowerCase() + String(val).slice(1);
3
- }
@@ -1,9 +0,0 @@
1
- export function debounce(callback, delay) {
2
- let timeoutTimer;
3
- return (...args)=>{
4
- clearTimeout(timeoutTimer);
5
- timeoutTimer = setTimeout(async ()=>{
6
- await callback(...args);
7
- }, delay);
8
- };
9
- }
@@ -1,30 +0,0 @@
1
- export class FunctionDecorator {
2
- options;
3
- constructor(){
4
- this.decoratorFactory = this.decoratorFactory.bind(this);
5
- }
6
- decoratorFactory(options) {
7
- this.options = options;
8
- return this.decorator.bind(this);
9
- }
10
- }
11
- /**
12
- * Skips the decorated method decorator if any of the named environment variables equal "true".
13
- * Useful for disabling decorators like @cache() during unit tests or via feature flags.
14
- *
15
- * @example @ignoreIf("TEST", "DISABLE_CACHE")
16
- */ export function ignoreIf(...envVars) {
17
- return (_, __, descriptor)=>{
18
- const originalFunction = descriptor.value;
19
- descriptor.value = function(target, key, descriptor) {
20
- if (envVars.some((v)=>process.env[v] === "true")) {
21
- return descriptor;
22
- }
23
- return originalFunction.bind(this)(target, key, descriptor);
24
- };
25
- return descriptor;
26
- };
27
- }
28
- /** @deprecated Use ignoreIf("TEST") instead */ export function ignoreDuringUnitTest() {
29
- return ignoreIf("TEST");
30
- }
@@ -1,5 +0,0 @@
1
- export const Environments = {
2
- production: "production",
3
- development: "development"
4
- };
5
- export const DefaultEnvironment = Environments.development;
@@ -1,26 +0,0 @@
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
- */ /**
16
- * Action function type that returns void.
17
- *
18
- * @example
19
- * ```typescript
20
- * // Instead of: (event: Event) => void
21
- * type EventHandler = Action<[Event]>;
22
- *
23
- * // Instead of: () => void
24
- * type Callback = Action<[]>;
25
- * ```
26
- */ export { };
@@ -1,30 +0,0 @@
1
- import { FunctionDecorator } from "./decorator.js";
2
- import { sleep } from "./sleep.js";
3
- class RetryDecorator extends FunctionDecorator {
4
- decorator(_target, _propertyKey, descriptor) {
5
- const originalMethod = descriptor.value;
6
- const attempts = Math.max(1, this.options?.attempts ?? 3);
7
- const delayMs = Math.max(0, this.options?.delayMs ?? 0);
8
- const shouldRetry = this.options?.shouldRetry ?? (()=>true);
9
- descriptor.value = async function(...args) {
10
- let lastError;
11
- for(let attempt = 1; attempt <= attempts; attempt++){
12
- try {
13
- return await Promise.resolve(originalMethod.apply(this, args));
14
- } catch (error) {
15
- lastError = error;
16
- const shouldAttemptAgain = attempt < attempts && shouldRetry(error);
17
- if (!shouldAttemptAgain) {
18
- throw error;
19
- }
20
- if (delayMs > 0) {
21
- await sleep(delayMs);
22
- }
23
- }
24
- }
25
- throw lastError;
26
- };
27
- return descriptor;
28
- }
29
- }
30
- export const retry = new RetryDecorator().decoratorFactory;
@@ -1,3 +0,0 @@
1
- export const sleep = (ms)=>new Promise((resolve)=>setTimeout(()=>{
2
- resolve(null);
3
- }, ms));
@@ -1 +0,0 @@
1
- export { };
@@ -1,59 +0,0 @@
1
- import type { ICache } from "./cache.js";
2
- export declare const Caches: {
3
- readonly default: "DEFAULT";
4
- readonly memoize: "MEMOIZE_CACHE";
5
- };
6
- /**
7
- * Central cache manager for managing named cache instances
8
- */
9
- declare class CacheManager {
10
- private caches;
11
- private readonly defaultCacheName;
12
- /**
13
- * Set a cache instance with the given name
14
- * @param name - The name of the cache
15
- * @param cache - The cache instance
16
- */
17
- setCache(name: string, cache: ICache): void;
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
- */
23
- getCache(name?: string, memoize?: boolean): ICache;
24
- /**
25
- * Clear a cache by name. If no name is provided, clears the default cache.
26
- * Note: This only works if the cache implements a clear() method.
27
- * @param name - The name of the cache to clear
28
- */
29
- flush(name?: string): void;
30
- flushAllCaches(): void;
31
- /**
32
- * Remove a cache instance by name
33
- * @param name - The name of the cache to remove
34
- */
35
- removeCache(name: string): void;
36
- /**
37
- * Check if a cache with the given name exists
38
- * @param name - The name of the cache
39
- * @returns True if the cache exists, false otherwise
40
- */
41
- hasCache(name: string): boolean;
42
- private readonly instanceIds;
43
- private instanceIdCounter;
44
- /**
45
- * Generate a cache key for a given instance, function name, and arguments.
46
- * Each instance receives a stable numeric ID so cache entries are never
47
- * shared across instances of the same class.
48
- * @param instance - The class instance (`this` at call time)
49
- * @param functionName - The name of the decorated method
50
- * @param args - The method arguments
51
- * @returns A unique cache key string
52
- */
53
- generateCacheKey(instance: object, functionName: string, args: unknown[]): string;
54
- }
55
- /**
56
- * Singleton instance of the cache manager
57
- */
58
- export declare const Caching: CacheManager;
59
- export {};
@@ -1,11 +0,0 @@
1
- /**
2
- * Interface for cache implementations used by the @cache() decorator
3
- */
4
- export interface ICache {
5
- get(key: string): unknown;
6
- set(key: string, value: unknown): void;
7
- has(key: string): boolean;
8
- del(key: string): void;
9
- flushAll(): any;
10
- get isMemoize(): boolean;
11
- }
@@ -1,18 +0,0 @@
1
- import { FunctionDecorator } from "../system/decorator.js";
2
- import type { ICache } from "./cache.js";
3
- /**
4
- * Options for configuring the @cache() decorator
5
- */
6
- export interface CacheOptions {
7
- cache?: ICache;
8
- name?: string;
9
- /**
10
- * Custom key function. When provided, replaces the default instance-scoped key
11
- * with a caller-defined key, enabling cross-instance cache sharing.
12
- */
13
- keyFn?: (...args: unknown[]) => string;
14
- }
15
- export declare class CacheDecorator extends FunctionDecorator<CacheOptions> {
16
- decorator(_target: object, propertyKey: string, descriptor: PropertyDescriptor): void;
17
- }
18
- export declare const cache: (options?: CacheOptions) => any;
@@ -1,6 +0,0 @@
1
- export * from "./cache.decorator.js";
2
- export * from "./cache.js";
3
- export * from "./cache-manager.js";
4
- export * from "./invalidate-cache.decorator.js";
5
- export * from "./memoize.decorator.js";
6
- export * from "./map-cache.js";
@@ -1,17 +0,0 @@
1
- import { FunctionDecorator } from "../system/decorator.js";
2
- import type { CacheOptions } from "./cache.decorator.js";
3
- type InvalidateCacheOptions = CacheOptions & {
4
- getKey: (instance: object, args: unknown[]) => string;
5
- };
6
- export declare class InvalidateCacheDecorator extends FunctionDecorator<InvalidateCacheOptions> {
7
- decorator(_target: object, _propertyKey: string, descriptor: PropertyDescriptor): void;
8
- }
9
- export declare const invalidateCache: {
10
- (method: string | ((...args: never[]) => unknown), options?: CacheOptions): any;
11
- evict(instance: object, method: (...args: never[]) => unknown, args?: unknown[]): void;
12
- };
13
- export declare const invalidateMemoize: {
14
- (method: string | ((...args: never[]) => unknown), options?: CacheOptions): any;
15
- evict(instance: object, method: (...args: never[]) => unknown, args?: unknown[]): void;
16
- };
17
- export {};
@@ -1,23 +0,0 @@
1
- import type { ICache } from "./cache.js";
2
- type MapCacheOptions = {
3
- /** Hand out the stored reference instead of a copy (what `@memoize` needs). */
4
- memoize?: boolean;
5
- };
6
- /**
7
- * The built-in cache: a plain `Map`, no expiry.
8
- *
9
- * By default `get` returns a `structuredClone` of an object, so a caller that changes what it
10
- * got back can't change the cached value. With `memoize` it returns the stored reference.
11
- * Scalars, `null` and `undefined` are returned as they are.
12
- */
13
- export declare class MapCache implements ICache {
14
- #private;
15
- constructor(options?: MapCacheOptions);
16
- get isMemoize(): boolean;
17
- get(key: string): unknown;
18
- set(key: string, value: unknown): void;
19
- has(key: string): boolean;
20
- del(key: string): void;
21
- flushAll(): void;
22
- }
23
- export {};
@@ -1,16 +0,0 @@
1
- import { CacheDecorator } from "./cache.decorator.js";
2
- /**
3
- * Memoize decorator class that extends CacheDecorator with memoization support
4
- * Automatically uses a memoization-capable cache (a MapCache that hands out references)
5
- */
6
- export declare class MemoizeDecorator extends CacheDecorator {
7
- decorator(target: object, propertyKey: string, descriptor: PropertyDescriptor): void;
8
- }
9
- /**
10
- * Memoize decorator factory
11
- * Provides true memoization by storing object references instead of clones
12
- *
13
- * @param options - Optional configuration for the memoize decorator
14
- * @returns Decorator function
15
- */
16
- export declare const memoize: (options?: import("./cache.decorator.js").CacheOptions) => any;
@@ -1,4 +0,0 @@
1
- export * from "./find-duplicates.js";
2
- export * from "./merge-arrays.js";
3
- export * from "./sum.js";
4
- export * from "./unique-objects.js";
@@ -1,2 +0,0 @@
1
- export declare function findDuplicatesByKey<T>(items: T[], key: keyof T): [string, T[]][];
2
- export declare function findDuplicatesBy<T>(items: T[], selector: (item: T) => string): [string, T[]][];
@@ -1 +0,0 @@
1
- export * as collections from "./collections.js";
@@ -1,2 +0,0 @@
1
- export declare function mergeByKey<T>(first: T[], second: T[], key: keyof T): T[];
2
- export declare function mergeBy<T>(first: T[], second: T[], selector: (item: T) => string): T[];
@@ -1,4 +0,0 @@
1
- export declare function sumByKey<T>(objects: T[], key: keyof T): number;
2
- export declare function sumByKey<T>(objects: T[], key: keyof T): bigint;
3
- export declare function sumBy<T>(objects: T[], key: (obj: T) => number): number;
4
- export declare function sumBy<T>(objects: T[], key: (obj: T) => bigint): bigint;
@@ -1,2 +0,0 @@
1
- export declare function uniqueObjectsByKey<T>(objects: T[], key: keyof T): T[];
2
- export declare function uniqueObjectsBy<T>(objects: T[], key: (obj: T) => string): T[];
@@ -1,37 +0,0 @@
1
- import type { Constructable } from "../reflection/index.js";
2
- export type ResolveRequest<T extends object = object> = string | symbol | Constructable<T>;
3
- export type Scope = "single-instance" | "request" | "transient";
4
- export interface ServiceProvider {
5
- /**
6
- * @param key
7
- * @throws {ServiceNotFoundException}
8
- */
9
- resolve<T extends object>(key: ResolveRequest<T>): T;
10
- resolveMany<T extends object = object>(resolveRequest: ResolveRequest<T>): T[];
11
- }
12
- export interface LifetimeScope extends ServiceProvider {
13
- /** A name must be unique among open scopes; omit it for per-request scopes. */
14
- beginScope(name?: string): LifetimeScope;
15
- [Symbol.dispose](): void;
16
- [Symbol.asyncDispose](): Promise<void>;
17
- }
18
- export interface IContainer extends LifetimeScope {
19
- }
20
- export interface ContainerRegistrar {
21
- registerTransient(key: string | symbol, type: Constructable): unknown;
22
- registerTransient(type: Constructable): unknown;
23
- registerRequestScoped<T>(type: () => T): unknown;
24
- registerRequestScoped<T>(key: string | symbol, type: () => T): unknown;
25
- registerRequestScoped(key: string | symbol, type: Constructable): unknown;
26
- registerRequestScoped(type: Constructable): unknown;
27
- registerSingleton(key: string | symbol | Constructable, instance: object): unknown;
28
- registerSingleton(key: string | symbol, type: Constructable): unknown;
29
- registerSingleton(type: Constructable): unknown;
30
- registerType(type: Constructable, scope?: Scope): unknown;
31
- registerTypes(...types: Constructable[]): unknown[];
32
- registerTypes(scope: Scope, ...types: Constructable[]): unknown[];
33
- }
34
- export interface ContainerBuilder extends ContainerRegistrar {
35
- readonly override: ContainerRegistrar;
36
- build(): IContainer;
37
- }
@@ -1,10 +0,0 @@
1
- import type { Constructable } from "../reflection/index.js";
2
- export declare const ConfigurationServiceToken: unique symbol;
3
- export interface IConfigurationService {
4
- readonly dataSources: readonly IConfigurationDataSource[];
5
- get<T extends object>(typeOrString: Constructable<T> | string): Promise<T>;
6
- }
7
- export interface IConfigurationDataSource {
8
- readonly name: string;
9
- getData(): Promise<Record<string, unknown>>;
10
- }
@@ -1 +0,0 @@
1
- export * from "./configuration.types.js";
@@ -1,39 +0,0 @@
1
- import type { FunctionDecorator } from "./decorator-factory.js";
2
- /**
3
- * Base class for creating decorator factory instances with methods that can be
4
- * conditionally disabled during unit testing.
5
- *
6
- * Example usage:
7
- * ```typescript
8
- * class MyDecoratorFactory extends DecoratorFactory {
9
- * @ignoreInUnitTest
10
- * cache(options?: CacheOptions) {
11
- * return cache(options);
12
- * }
13
- *
14
- * @ignoreInUnitTest
15
- * logger(options?: LoggerOptions) {
16
- * return logger(options);
17
- * }
18
- * }
19
- *
20
- * const decorators = new MyDecoratorFactory();
21
- *
22
- * class TestClass {
23
- * @decorators.cache({ ttl: 1000 })
24
- * async getData() {
25
- * // This decorator will be disabled when TEST=true
26
- * }
27
- * }
28
- * ```
29
- */
30
- export declare abstract class DecoratorFactoryBase {
31
- /**
32
- * Utility method to check if we're currently in a test environment
33
- */
34
- protected isTestEnvironment(): boolean;
35
- /**
36
- * Creates a no-op decorator that returns the original function unchanged
37
- */
38
- protected createNoOpDecorator(): FunctionDecorator;
39
- }
@@ -1,19 +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
- /**
8
- * Decorator that disables the decorated decorator method when TEST environment variable is true.
9
- * If TEST=true, it returns a no-op decorator that simply returns the original function unchanged.
10
- */
11
- export declare function ignoreInUnitTest(_target: object, _propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor;
12
- /**
13
- * Type definition for a function decorator
14
- */
15
- export type FunctionDecorator = (target: object, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor | undefined;
16
- /**
17
- * Type definition for a decorator factory function (returns a decorator)
18
- */
19
- export type DecoratorFactory<TOptions = unknown> = (options?: TOptions) => FunctionDecorator;
@@ -1,9 +0,0 @@
1
- import type { Type } from "../reflection/types/reflection.types.js";
2
- export type ExtensionOptions = {
3
- /**
4
- * Also install the method on the constructor. Use for singleton facades
5
- * (`scribe.withPinoPretty()`) whose instance lives at `ctor.instance`.
6
- */
7
- static?: boolean;
8
- };
9
- export declare function extension(ctor: Type, options?: ExtensionOptions): (_target: object, propertyKey: string, descriptor: PropertyDescriptor) => void;
@@ -1,6 +0,0 @@
1
- export * from "./decorator-factory.js";
2
- export * from "./decorator-factory-base.js";
3
- export * from "./extension.js";
4
- export * from "./mixwith.js";
5
- export * from "./pipeline.js";
6
- export * from "./step.js";
@@ -1,6 +0,0 @@
1
- type Constructor<T = object> = abstract new (...args: unknown[]) => T;
2
- type UnionToIntersection<T> = (T extends unknown ? (arg: T) => void : never) extends (arg: infer TResult) => void ? TResult : never;
3
- type MixedInstance<TMixins extends readonly Constructor[]> = UnionToIntersection<InstanceType<TMixins[number]>>;
4
- type MixedClass<TMixins extends readonly Constructor[]> = abstract new (...args: unknown[]) => MixedInstance<TMixins>;
5
- export declare function mixwith<TMixins extends readonly Constructor[]>(...mixins: TMixins): MixedClass<TMixins>;
6
- export {};
@@ -1,12 +0,0 @@
1
- export interface PipelineStep<TContext extends Record<string, unknown> = Record<string, unknown>> {
2
- run(ctx: TContext, next: Next): Promise<void> | void;
3
- }
4
- export type Next = () => Promise<void> | void;
5
- export declare class Pipeline<T extends Record<string, unknown>> {
6
- private readonly stack;
7
- private readonly logger;
8
- private currentStep;
9
- constructor(...steps: [string, PipelineStep<T>, ((ctx: T) => boolean)?][]);
10
- [Symbol.dispose](): void;
11
- start(context: T): Promise<void>;
12
- }
@@ -1,4 +0,0 @@
1
- export type CopyFileOptions = {
2
- mkdir?: boolean;
3
- };
4
- export declare function copyFile(src: string, dest: string, options?: CopyFileOptions): Promise<void>;
@@ -1 +0,0 @@
1
- export declare function deleteFile(filePath: string): Promise<void>;
@@ -1 +0,0 @@
1
- export declare function directoryExists(path: string): Promise<boolean>;
@@ -1 +0,0 @@
1
- export declare function fileExists(path: string): Promise<boolean>;
@@ -1,2 +0,0 @@
1
- export * as io from "./io.js";
2
- export * from "./types/index.js";
@@ -1,8 +0,0 @@
1
- export * from "./copy-file.js";
2
- export * from "./delete-file.js";
3
- export * from "./directory-exists.js";
4
- export * from "./file-exists.js";
5
- export * from "./read-file.js";
6
- export * from "./remove-dir.js";
7
- export * from "./url-to-path.js";
8
- export * from "./write-file.js";
@@ -1,4 +0,0 @@
1
- import type { File } from "./types/file.js";
2
- export declare function readFiles(filePaths: File[], encoding?: BufferEncoding): Promise<string[]>;
3
- export declare function readFile(filePath: string, encoding?: BufferEncoding): Promise<string>;
4
- export declare function readJsonFile<T>(filePath: string, encoding?: BufferEncoding): Promise<T>;
@@ -1,5 +0,0 @@
1
- export type RemoveDirOptions = {
2
- force: boolean;
3
- recursive: boolean;
4
- };
5
- export declare function removeDir(path: string, options?: RemoveDirOptions): Promise<void>;