@digital-alchemy/core 24.8.4 → 24.9.4
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/README.md +17 -27
- package/dist/helpers/async.helper.d.ts +1 -1
- package/dist/helpers/async.helper.js +13 -14
- package/dist/helpers/async.helper.js.map +1 -1
- package/dist/helpers/config-environment-loader.helper.js +16 -20
- package/dist/helpers/config-environment-loader.helper.js.map +1 -1
- package/dist/helpers/config-file-loader.helper.d.ts +5 -3
- package/dist/helpers/config-file-loader.helper.js +45 -52
- package/dist/helpers/config-file-loader.helper.js.map +1 -1
- package/dist/helpers/config.helper.d.ts +24 -3
- package/dist/helpers/config.helper.js +30 -37
- package/dist/helpers/config.helper.js.map +1 -1
- package/dist/helpers/context.helper.js +1 -2
- package/dist/helpers/cron.helper.d.ts +27 -0
- package/dist/helpers/cron.helper.js +4 -7
- package/dist/helpers/cron.helper.js.map +1 -1
- package/dist/helpers/errors.helper.d.ts +0 -12
- package/dist/helpers/errors.helper.js +2 -23
- package/dist/helpers/errors.helper.js.map +1 -1
- package/dist/helpers/events.helper.js +4 -10
- package/dist/helpers/events.helper.js.map +1 -1
- package/dist/helpers/extend.helper.d.ts +2 -0
- package/dist/helpers/extend.helper.js +19 -24
- package/dist/helpers/extend.helper.js.map +1 -1
- package/dist/helpers/index.d.ts +2 -4
- package/dist/helpers/index.js +14 -19
- package/dist/helpers/index.js.map +1 -1
- package/dist/helpers/lifecycle.helper.d.ts +1 -5
- package/dist/helpers/lifecycle.helper.js +1 -4
- package/dist/helpers/lifecycle.helper.js.map +1 -1
- package/dist/{extensions/logger.extension.d.ts → helpers/logger.helper.d.ts} +33 -40
- package/dist/helpers/logger.helper.js +10 -0
- package/dist/helpers/logger.helper.js.map +1 -0
- package/dist/helpers/module.helper.d.ts +74 -0
- package/dist/helpers/module.helper.js +131 -0
- package/dist/helpers/module.helper.js.map +1 -0
- package/dist/helpers/utilities.helper.d.ts +3 -14
- package/dist/helpers/utilities.helper.js +51 -73
- package/dist/helpers/utilities.helper.js.map +1 -1
- package/dist/helpers/wiring.helper.d.ts +77 -23
- package/dist/helpers/wiring.helper.js +45 -47
- package/dist/helpers/wiring.helper.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -5
- package/dist/index.js.map +1 -1
- package/dist/services/als.extension.d.ts +2 -0
- package/dist/services/als.extension.js +17 -0
- package/dist/services/als.extension.js.map +1 -0
- package/dist/services/configuration.extension.d.ts +7 -0
- package/dist/services/configuration.extension.js +117 -0
- package/dist/services/configuration.extension.js.map +1 -0
- package/dist/{extensions → services}/index.d.ts +1 -3
- package/dist/services/index.js +8 -0
- package/dist/services/index.js.map +1 -0
- package/dist/{extensions → services}/internal.extension.d.ts +7 -23
- package/dist/{extensions → services}/internal.extension.js +43 -55
- package/dist/services/internal.extension.js.map +1 -0
- package/dist/{extensions → services}/is.extension.d.ts +5 -0
- package/dist/{extensions → services}/is.extension.js +20 -15
- package/dist/services/is.extension.js.map +1 -0
- package/dist/{extensions → services}/lifecycle.extension.js +17 -19
- package/dist/services/lifecycle.extension.js.map +1 -0
- package/dist/services/logger.extension.d.ts +2 -0
- package/dist/services/logger.extension.js +201 -0
- package/dist/services/logger.extension.js.map +1 -0
- package/dist/services/scheduler.extension.d.ts +2 -0
- package/dist/services/scheduler.extension.js +108 -0
- package/dist/services/scheduler.extension.js.map +1 -0
- package/dist/services/wiring.extension.d.ts +111 -0
- package/dist/services/wiring.extension.js +437 -0
- package/dist/services/wiring.extension.js.map +1 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.js +3 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/mock-logger.d.ts +2 -0
- package/dist/testing/mock-logger.js +11 -0
- package/dist/testing/mock-logger.js.map +1 -0
- package/dist/testing/test-module.d.ts +112 -0
- package/dist/testing/test-module.js +138 -0
- package/dist/testing/test-module.js.map +1 -0
- package/package.json +56 -43
- package/dist/extensions/cache.extension.d.ts +0 -2
- package/dist/extensions/cache.extension.js +0 -90
- package/dist/extensions/cache.extension.js.map +0 -1
- package/dist/extensions/configuration.extension.d.ts +0 -52
- package/dist/extensions/configuration.extension.js +0 -131
- package/dist/extensions/configuration.extension.js.map +0 -1
- package/dist/extensions/fetch.extension.d.ts +0 -17
- package/dist/extensions/fetch.extension.js +0 -133
- package/dist/extensions/fetch.extension.js.map +0 -1
- package/dist/extensions/index.js +0 -13
- package/dist/extensions/index.js.map +0 -1
- package/dist/extensions/internal.extension.js.map +0 -1
- package/dist/extensions/is.extension.js.map +0 -1
- package/dist/extensions/lifecycle.extension.js.map +0 -1
- package/dist/extensions/logger.extension.js +0 -186
- package/dist/extensions/logger.extension.js.map +0 -1
- package/dist/extensions/metrics.extension.d.ts +0 -18
- package/dist/extensions/metrics.extension.js +0 -156
- package/dist/extensions/metrics.extension.js.map +0 -1
- package/dist/extensions/scheduler.extension.d.ts +0 -21
- package/dist/extensions/scheduler.extension.js +0 -133
- package/dist/extensions/scheduler.extension.js.map +0 -1
- package/dist/extensions/wiring.extension.d.ts +0 -50
- package/dist/extensions/wiring.extension.js +0 -374
- package/dist/extensions/wiring.extension.js.map +0 -1
- package/dist/helpers/cache-memory.helper.d.ts +0 -6
- package/dist/helpers/cache-memory.helper.js +0 -68
- package/dist/helpers/cache-memory.helper.js.map +0 -1
- package/dist/helpers/cache-redis.helper.d.ts +0 -6
- package/dist/helpers/cache-redis.helper.js +0 -73
- package/dist/helpers/cache-redis.helper.js.map +0 -1
- package/dist/helpers/cache.helper.d.ts +0 -19
- package/dist/helpers/cache.helper.js +0 -9
- package/dist/helpers/cache.helper.js.map +0 -1
- package/dist/helpers/fetch.helper.d.ts +0 -165
- package/dist/helpers/fetch.helper.js +0 -173
- package/dist/helpers/fetch.helper.js.map +0 -1
- /package/dist/{extensions → services}/lifecycle.extension.d.ts +0 -0
|
@@ -1,29 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
exports.ValidateLibrary = ValidateLibrary;
|
|
6
|
-
exports.WireOrder = WireOrder;
|
|
7
|
-
exports.CreateLibrary = CreateLibrary;
|
|
8
|
-
const __1 = require("..");
|
|
9
|
-
exports.WIRE_PROJECT = Symbol.for("wire-project");
|
|
10
|
-
function BuildSortOrder(app, logger) {
|
|
11
|
-
if (__1.is.empty(app.libraries)) {
|
|
1
|
+
import { BootstrapException, eachSeries, is, LOAD_PROJECT, } from "..";
|
|
2
|
+
export const WIRE_PROJECT = Symbol.for("wire-project");
|
|
3
|
+
export function buildSortOrder(app, logger) {
|
|
4
|
+
if (is.empty(app.libraries)) {
|
|
12
5
|
return [];
|
|
13
6
|
}
|
|
14
|
-
const libraryMap = new Map(app.libraries.map(
|
|
7
|
+
const libraryMap = new Map(app.libraries.map(i => [i.name, i]));
|
|
15
8
|
// Recursive function to check for missing dependencies at any depth
|
|
16
9
|
function checkDependencies(library) {
|
|
17
|
-
const depends = [
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
];
|
|
21
|
-
if (!__1.is.empty(depends)) {
|
|
22
|
-
depends.forEach((item) => {
|
|
10
|
+
const depends = [...(library?.depends ?? []), ...(library?.optionalDepends ?? [])];
|
|
11
|
+
if (!is.empty(depends)) {
|
|
12
|
+
depends.forEach(item => {
|
|
23
13
|
const loaded = libraryMap.get(item.name);
|
|
24
14
|
if (!loaded) {
|
|
25
15
|
if (library.depends.includes(item)) {
|
|
26
|
-
throw new
|
|
16
|
+
throw new BootstrapException(WIRING_CONTEXT, "MISSING_DEPENDENCY", `${item.name} is required by ${library.name}, but was not provided`);
|
|
27
17
|
}
|
|
28
18
|
else {
|
|
29
19
|
logger.info({ library: library.name, name: checkDependencies }, `optional depends [%s] not provided`, item.name);
|
|
@@ -33,70 +23,77 @@ function BuildSortOrder(app, logger) {
|
|
|
33
23
|
// just "are they the same object reference?" as the test
|
|
34
24
|
// you get a warning, and the one the app asks for
|
|
35
25
|
// hopefully there is no breaking changes
|
|
36
|
-
if (loaded !== item) {
|
|
37
|
-
logger.warn({ name:
|
|
26
|
+
if (loaded !== item && !process.env.NODE_ENV.startsWith("test")) {
|
|
27
|
+
logger.warn({ name: buildSortOrder }, "[%s] depends different version {%s}", library.name, item.name);
|
|
38
28
|
}
|
|
39
29
|
});
|
|
40
30
|
}
|
|
41
31
|
return library;
|
|
42
32
|
}
|
|
43
|
-
let starting = app.libraries.map(
|
|
33
|
+
let starting = app.libraries.map(i => checkDependencies(i));
|
|
44
34
|
const out = [];
|
|
45
|
-
while (!
|
|
46
|
-
const next = starting.find(
|
|
35
|
+
while (!is.empty(starting)) {
|
|
36
|
+
const next = starting.find(library => {
|
|
47
37
|
const depends = [
|
|
48
38
|
...(library?.depends ?? []),
|
|
49
|
-
...(library?.optionalDepends?.filter(
|
|
39
|
+
...(library?.optionalDepends?.filter(i => app.libraries.some(index => i.name === index.name)) ?? []),
|
|
50
40
|
];
|
|
51
|
-
if (
|
|
41
|
+
if (is.empty(depends)) {
|
|
52
42
|
return true;
|
|
53
43
|
}
|
|
54
|
-
return depends.every(
|
|
44
|
+
return depends.every(depend => out.some(i => i.name === depend.name));
|
|
55
45
|
});
|
|
56
46
|
if (!next) {
|
|
57
|
-
logger.fatal({ current: out.map(
|
|
58
|
-
throw new
|
|
47
|
+
logger.fatal({ current: out.map(i => i.name), name: buildSortOrder });
|
|
48
|
+
throw new BootstrapException(WIRING_CONTEXT, "BAD_SORT", `Cannot find a next lib to load`);
|
|
59
49
|
}
|
|
60
|
-
starting = starting.filter(
|
|
50
|
+
starting = starting.filter(i => next.name !== i.name);
|
|
61
51
|
out.push(next);
|
|
62
52
|
}
|
|
63
53
|
return out;
|
|
64
54
|
}
|
|
65
|
-
const COERCE_CONTEXT = (context) => context;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
throw new __1.BootstrapException((0, exports.COERCE_CONTEXT)("CreateLibrary"), "MISSING_LIBRARY_NAME", "Library name is required");
|
|
55
|
+
export const COERCE_CONTEXT = (context) => context;
|
|
56
|
+
export const WIRING_CONTEXT = COERCE_CONTEXT("boilerplate:wiring");
|
|
57
|
+
export function validateLibrary(project, serviceList) {
|
|
58
|
+
if (is.empty(project)) {
|
|
59
|
+
throw new BootstrapException(COERCE_CONTEXT("CreateLibrary"), "MISSING_LIBRARY_NAME", "Library name is required");
|
|
71
60
|
}
|
|
72
61
|
const services = Object.entries(serviceList);
|
|
73
62
|
// Find the first invalid service
|
|
74
63
|
const invalidService = services.find(([, definition]) => typeof definition !== "function");
|
|
75
64
|
if (invalidService) {
|
|
76
65
|
const [invalidServiceName, service] = invalidService;
|
|
77
|
-
throw new
|
|
66
|
+
throw new BootstrapException(COERCE_CONTEXT("CreateLibrary"), "INVALID_SERVICE_DEFINITION", `Invalid service definition for '${invalidServiceName}' in library '${project}' (${typeof service}})`);
|
|
78
67
|
}
|
|
79
68
|
}
|
|
80
|
-
function
|
|
69
|
+
export function wireOrder(priority, list) {
|
|
81
70
|
const out = [...(priority || [])];
|
|
82
|
-
if (!
|
|
83
|
-
const check =
|
|
71
|
+
if (!is.empty(priority)) {
|
|
72
|
+
const check = is.unique(priority);
|
|
84
73
|
if (check.length !== out.length) {
|
|
85
|
-
throw new
|
|
74
|
+
throw new BootstrapException(WIRING_CONTEXT, "DOUBLE_PRIORITY", "There are duplicate items in the priority load list");
|
|
86
75
|
}
|
|
87
76
|
}
|
|
88
|
-
|
|
77
|
+
const temporary = [...out, ...list.filter(i => !out.includes(i))];
|
|
78
|
+
return temporary;
|
|
89
79
|
}
|
|
90
|
-
function CreateLibrary({ name: libraryName, configuration = {}, priorityInit, services, depends, optionalDepends, }) {
|
|
91
|
-
|
|
80
|
+
export function CreateLibrary({ name: libraryName, configuration = {}, priorityInit, services, depends, optionalDepends, }) {
|
|
81
|
+
validateLibrary(libraryName, services);
|
|
92
82
|
const serviceApis = {};
|
|
83
|
+
if (!is.empty(priorityInit)) {
|
|
84
|
+
priorityInit.forEach(name => {
|
|
85
|
+
if (!is.function(services[name])) {
|
|
86
|
+
throw new BootstrapException(WIRING_CONTEXT, "MISSING_PRIORITY_SERVICE", `${name} was listed as priority init, but was not found in services`);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
93
90
|
const library = {
|
|
94
|
-
[
|
|
91
|
+
[WIRE_PROJECT]: async (internal, WireService) => {
|
|
95
92
|
// not defined for boilerplate (chicken & egg)
|
|
96
93
|
// manually added inside the bootstrap process
|
|
97
94
|
const config = internal?.boilerplate.configuration;
|
|
98
|
-
config?.[
|
|
99
|
-
await
|
|
95
|
+
config?.[LOAD_PROJECT](libraryName, configuration);
|
|
96
|
+
await eachSeries(wireOrder(priorityInit, Object.keys(services)), async (service) => {
|
|
100
97
|
serviceApis[service] = await WireService(libraryName, service, services[service], internal.boot.lifecycle.events, internal);
|
|
101
98
|
});
|
|
102
99
|
internal.boot.constructComplete.add(libraryName);
|
|
@@ -110,6 +107,7 @@ function CreateLibrary({ name: libraryName, configuration = {}, priorityInit, se
|
|
|
110
107
|
priorityInit,
|
|
111
108
|
serviceApis,
|
|
112
109
|
services,
|
|
110
|
+
type: "library",
|
|
113
111
|
};
|
|
114
112
|
return library;
|
|
115
113
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wiring.helper.js","sourceRoot":"","sources":["../../src/helpers/wiring.helper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wiring.helper.js","sourceRoot":"","sources":["../../src/helpers/wiring.helper.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,kBAAkB,EAGlB,UAAU,EAGV,EAAE,EAEF,YAAY,GAIb,MAAM,IAAI,CAAC;AAsYZ,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;AA0CvD,MAAM,UAAU,cAAc,CAC5B,GAAgC,EAChC,MAAe;IAEf,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;QAC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,EACpC,EAAE;YACF,8CAA8C;YAC9C,8CAA8C;YAC9C,MAAM,MAAM,GAAG,QAAQ,EAAE,WAAW,CAAC,aAA8B,CAAC;YACpE,MAAM,EAAE,CAAC,YAAY,CAAC,CAAC,WAAkC,EAAE,aAAa,CAAC,CAAC;YAC1E,MAAM,UAAU,CAAC,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAC,OAAO,EAAC,EAAE;gBAC/E,WAAW,CAAC,OAAO,CAAC,GAAG,MAAM,WAAW,CACtC,WAAW,EACX,OAAO,EACP,QAAQ,CAAC,OAAO,CAAC,EACjB,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAC9B,QAAQ,CACT,CAAC;YACJ,CAAC,CAAC,CAAC;YACH,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;YACjD,oGAAoG;YACpG,qHAAqH;QACvH,CAAC;QACD,aAAa;QACb,OAAO;QACP,IAAI,EAAE,WAAW;QACjB,eAAe;QACf,YAAY;QACZ,WAAW;QACX,QAAQ;QACR,IAAI,EAAE,SAAS;KACsB,CAAC;IACxC,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
tslib_1.__exportStar(require("./extensions"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./helpers"), exports);
|
|
1
|
+
export * from "./helpers";
|
|
2
|
+
export * from "./services";
|
|
3
|
+
export * from "./testing";
|
|
6
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
2
|
+
import { v4 } from "uuid";
|
|
3
|
+
export function ALS({ config }) {
|
|
4
|
+
const storage = new AsyncLocalStorage();
|
|
5
|
+
return {
|
|
6
|
+
asyncStorage: () => (config.boilerplate.NODE_ENV ? storage : undefined),
|
|
7
|
+
getLogData: () => storage.getStore()?.logs ?? {},
|
|
8
|
+
getStore: () => storage.getStore(),
|
|
9
|
+
init(source, callback) {
|
|
10
|
+
const data = { logs: { id: v4(), ...source } };
|
|
11
|
+
storage.run(data, () => {
|
|
12
|
+
callback();
|
|
13
|
+
});
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=als.extension.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"als.extension.js","sourceRoot":"","sources":["../../src/services/als.extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAI1B,MAAM,UAAU,GAAG,CAAC,EAAE,MAAM,EAAkB;IAC5C,MAAM,OAAO,GAAG,IAAI,iBAAiB,EAAkB,CAAC;IACxD,OAAO;QACL,YAAY,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;QACvE,UAAU,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,IAAI,IAAK,EAAmB;QAClE,QAAQ,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE;QAClC,IAAI,CAAC,MAAc,EAAE,QAA0B;YAC7C,MAAM,IAAI,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,CAAC;YAC/C,OAAO,CAAC,GAAG,CAAC,IAAsB,EAAE,GAAG,EAAE;gBACvC,QAAQ,EAAE,CAAC;YACb,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DigitalAlchemyConfiguration, TServiceParams } from "..";
|
|
2
|
+
export declare const INITIALIZE: unique symbol;
|
|
3
|
+
export declare const LOAD_PROJECT: unique symbol;
|
|
4
|
+
export declare const EVENT_CONFIGURATION_UPDATED = "event_configuration_updated";
|
|
5
|
+
export declare const INJECTED_DEFINITIONS: unique symbol;
|
|
6
|
+
export type ConfigManager = ReturnType<typeof Configuration>;
|
|
7
|
+
export declare function Configuration({ context, event, lifecycle, internal, logger, }: TServiceParams): DigitalAlchemyConfiguration;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { BootstrapException, ConfigLoaderEnvironment, configLoaderFile, deepExtend, eachSeries, } from "..";
|
|
2
|
+
import { is } from ".";
|
|
3
|
+
export const INITIALIZE = Symbol.for("initialize");
|
|
4
|
+
export const LOAD_PROJECT = Symbol.for("load-project");
|
|
5
|
+
export const EVENT_CONFIGURATION_UPDATED = "event_configuration_updated";
|
|
6
|
+
export const INJECTED_DEFINITIONS = Symbol.for("injected-config");
|
|
7
|
+
const DECIMALS = 2;
|
|
8
|
+
export function Configuration({ context, event, lifecycle, internal,
|
|
9
|
+
// ! THIS DOES NOT EXIST BEFORE PRE INIT
|
|
10
|
+
logger, }) {
|
|
11
|
+
// modern problems require modern solutions
|
|
12
|
+
lifecycle.onPreInit(() => (logger = internal.boilerplate.logger.context(context)));
|
|
13
|
+
const configuration = {};
|
|
14
|
+
const configDefinitions = new Map();
|
|
15
|
+
function injectedDefinitions() {
|
|
16
|
+
const out = {};
|
|
17
|
+
return new Proxy(out, {
|
|
18
|
+
get(_, project) {
|
|
19
|
+
return internal.utils.object.get(configuration, project) ?? {};
|
|
20
|
+
},
|
|
21
|
+
has(_, key) {
|
|
22
|
+
Object.keys(configuration).forEach(key => (out[key] ??= {}));
|
|
23
|
+
return Object.keys(configuration).includes(key);
|
|
24
|
+
},
|
|
25
|
+
ownKeys() {
|
|
26
|
+
Object.keys(configuration).forEach(key => (out[key] ??= {}));
|
|
27
|
+
return Object.keys(configuration);
|
|
28
|
+
},
|
|
29
|
+
set() {
|
|
30
|
+
return false;
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function setConfig(project, property, value) {
|
|
35
|
+
internal.utils.object.set(configuration, [project, property].join("."), value);
|
|
36
|
+
// in case anyone needs a hook
|
|
37
|
+
event.emit(EVENT_CONFIGURATION_UPDATED, project, property);
|
|
38
|
+
}
|
|
39
|
+
function validateConfig() {
|
|
40
|
+
// * validate
|
|
41
|
+
// - ensure all required properties have been defined
|
|
42
|
+
configDefinitions.forEach((definitions, project) => {
|
|
43
|
+
Object.keys(definitions).forEach(key => {
|
|
44
|
+
const config = [project, key].join(".");
|
|
45
|
+
if (definitions[key].required &&
|
|
46
|
+
is.undefined(internal.utils.object.get(configuration, config))) {
|
|
47
|
+
// ruh roh
|
|
48
|
+
throw new BootstrapException(context, "REQUIRED_CONFIGURATION_MISSING", `Configuration property ${config} is not defined`);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
// #MARK: Initialize
|
|
54
|
+
async function initialize(application) {
|
|
55
|
+
const configLoaders = internal.boot.application.configurationLoaders ??
|
|
56
|
+
[ConfigLoaderEnvironment, configLoaderFile];
|
|
57
|
+
const start = performance.now();
|
|
58
|
+
// * were configs disabled?
|
|
59
|
+
if (is.empty(configLoaders)) {
|
|
60
|
+
validateConfig();
|
|
61
|
+
if (!configuration.boilerplate.IS_TEST) {
|
|
62
|
+
logger.warn({ name: initialize }, `no config loaders defined`);
|
|
63
|
+
}
|
|
64
|
+
return `${(performance.now() - start).toFixed(DECIMALS)}ms`;
|
|
65
|
+
}
|
|
66
|
+
// * load!
|
|
67
|
+
await eachSeries(configLoaders, async (loader) => {
|
|
68
|
+
const merge = await loader({
|
|
69
|
+
application,
|
|
70
|
+
configs: configDefinitions,
|
|
71
|
+
internal,
|
|
72
|
+
logger,
|
|
73
|
+
});
|
|
74
|
+
deepExtend(configuration, merge);
|
|
75
|
+
});
|
|
76
|
+
validateConfig();
|
|
77
|
+
return `${(performance.now() - start).toFixed(DECIMALS)}ms`;
|
|
78
|
+
}
|
|
79
|
+
function merge(merge) {
|
|
80
|
+
return deepExtend(configuration, merge);
|
|
81
|
+
}
|
|
82
|
+
function loadProject(library, definitions) {
|
|
83
|
+
internal.utils.object.set(configuration, library, {});
|
|
84
|
+
Object.keys(definitions).forEach(key => {
|
|
85
|
+
internal.utils.object.set(configuration, [library, key].join("."), definitions[key].default);
|
|
86
|
+
});
|
|
87
|
+
return configDefinitions.set(library, definitions);
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
[INITIALIZE]: initialize,
|
|
91
|
+
[INJECTED_DEFINITIONS]: injectedDefinitions,
|
|
92
|
+
[LOAD_PROJECT]: loadProject,
|
|
93
|
+
/**
|
|
94
|
+
* retrieve the metadata that was originally used to define the configs
|
|
95
|
+
*/
|
|
96
|
+
getDefinitions: () => configDefinitions,
|
|
97
|
+
/**
|
|
98
|
+
* take a configuration object, and deep merge values
|
|
99
|
+
*
|
|
100
|
+
* intended for initial loading workflows
|
|
101
|
+
*/
|
|
102
|
+
merge: merge,
|
|
103
|
+
onUpdate(callback, project, property) {
|
|
104
|
+
event.on(EVENT_CONFIGURATION_UPDATED, (updatedProject, updatedProperty) => {
|
|
105
|
+
if (!is.empty(project) && project !== updatedProject) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (!is.empty(property) && property !== updatedProperty) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
callback(updatedProject, updatedProperty);
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
set: setConfig,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=configuration.extension.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configuration.extension.js","sourceRoot":"","sources":["../../src/services/configuration.extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EAGlB,uBAAuB,EACvB,gBAAgB,EAChB,UAAU,EAEV,UAAU,GASX,MAAM,IAAI,CAAC;AACZ,OAAO,EAAE,EAAE,EAAE,MAAM,GAAG,CAAC;AAEvB,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AACnD,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;AACvD,MAAM,CAAC,MAAM,2BAA2B,GAAG,6BAA6B,CAAC;AACzE,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;AAGlE,MAAM,QAAQ,GAAG,CAAC,CAAC;AAEnB,MAAM,UAAU,aAAa,CAAC,EAC5B,OAAO,EACP,KAAK,EACL,SAAS,EACT,QAAQ;AACR,wCAAwC;AACxC,MAAM,GACS;IACf,2CAA2C;IAC3C,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,CAAC,MAAM,GAAG,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAEnF,MAAM,aAAa,GAAyB,EAAE,CAAC;IAC/C,MAAM,iBAAiB,GAAiB,IAAI,GAAG,EAAE,CAAC;IAElD,SAAS,mBAAmB;QAC1B,MAAM,GAAG,GAAG,EAA4B,CAAC;QACzC,OAAO,IAAI,KAAK,CAAC,GAAsB,EAAE;YACvC,GAAG,CAAC,CAAC,EAAE,O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AI,OAAO,KAAK,cAAc,EAAE,CAAC;oBACrD,OAAO;gBACT,CAAC;gBACD,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,QAAQ,KAAK,eAAe,EAAE,CAAC;oBACxD,OAAO;gBACT,CAAC;gBACD,QAAQ,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;YAC5C,CAAC,CAAC,CAAC;QACL,CAAC;QAED,GAAG,EAAE,SAAuB;KAC7B,CAAC;AACJ,CAAC"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./als.extension";
|
|
2
2
|
export * from "./configuration.extension";
|
|
3
|
-
export * from "./fetch.extension";
|
|
4
3
|
export * from "./internal.extension";
|
|
5
4
|
export * from "./is.extension";
|
|
6
5
|
export * from "./logger.extension";
|
|
7
|
-
export * from "./metrics.extension";
|
|
8
6
|
export * from "./scheduler.extension";
|
|
9
7
|
export * from "./wiring.extension";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./als.extension";
|
|
2
|
+
export * from "./configuration.extension";
|
|
3
|
+
export * from "./internal.extension";
|
|
4
|
+
export * from "./is.extension";
|
|
5
|
+
export * from "./logger.extension";
|
|
6
|
+
export * from "./scheduler.extension";
|
|
7
|
+
export * from "./wiring.extension";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Dayjs } from "dayjs";
|
|
2
2
|
import { EventEmitter } from "events";
|
|
3
|
-
import { Counter, Summary } from "prom-client";
|
|
4
3
|
import { Get } from "type-fest";
|
|
5
4
|
import { ApplicationDefinition, BootstrapOptions, GetApis, LIB_BOILERPLATE, LifecycleStages, OptionalModuleConfiguration, ServiceMap, TBlackHole, TContext, TModuleMappings, TResolvedModuleMappings } from "..";
|
|
6
5
|
import { CreateLifecycle } from "./lifecycle.extension";
|
|
@@ -12,8 +11,9 @@ export declare class InternalUtils {
|
|
|
12
11
|
* **NOTE:** bootstrapping process will initialize this at boot, and cleanup at teardown.
|
|
13
12
|
* Making listener changes should only be done from within the context of service functions
|
|
14
13
|
*/
|
|
15
|
-
event: EventEmitter
|
|
16
|
-
|
|
14
|
+
event: EventEmitter;
|
|
15
|
+
constructor();
|
|
16
|
+
titleCase(input: string): string;
|
|
17
17
|
relativeDate(pastDate: inputFormats, futureDate?: inputFormats): string;
|
|
18
18
|
object: {
|
|
19
19
|
del<T>(object: T, path: string): void;
|
|
@@ -21,32 +21,16 @@ export declare class InternalUtils {
|
|
|
21
21
|
set<T>(object: T, path: string, value: unknown, doNotReplace?: boolean): void;
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
type SafeExecOptions
|
|
24
|
+
type SafeExecOptions = {
|
|
25
|
+
context?: TContext;
|
|
25
26
|
exec: () => TBlackHole;
|
|
26
|
-
labels: LABELS;
|
|
27
|
-
duration: Summary<Extract<keyof LABELS, string>>;
|
|
28
|
-
executions: Counter<Extract<keyof LABELS, string>>;
|
|
29
|
-
errors: Counter<Extract<keyof LABELS, string>>;
|
|
30
|
-
};
|
|
31
|
-
type BaseLabels = {
|
|
32
|
-
context: TContext;
|
|
33
|
-
/**
|
|
34
|
-
* ! if provided, specific metrics will be kept
|
|
35
|
-
*
|
|
36
|
-
* do not pass label if you do not want metrics to be kept, you may not want / need metrics to be kept on all instances
|
|
37
|
-
*
|
|
38
|
-
* - execution count
|
|
39
|
-
* - error count
|
|
40
|
-
* - summary of execution time
|
|
41
|
-
*/
|
|
42
|
-
label?: string;
|
|
43
27
|
};
|
|
44
28
|
type Phase = "bootstrap" | "teardown" | "running";
|
|
45
29
|
export declare class InternalDefinition {
|
|
46
30
|
/**
|
|
47
31
|
* Utility methods provided by boilerplate
|
|
48
32
|
*/
|
|
49
|
-
boilerplate: Pick<GetApis<typeof LIB_BOILERPLATE>, "configuration" | "
|
|
33
|
+
boilerplate: Pick<GetApis<typeof LIB_BOILERPLATE>, "configuration" | "logger">;
|
|
50
34
|
boot: {
|
|
51
35
|
/**
|
|
52
36
|
* Options that were passed into bootstrap
|
|
@@ -83,6 +67,6 @@ export declare class InternalDefinition {
|
|
|
83
67
|
startup: Date;
|
|
84
68
|
};
|
|
85
69
|
utils: InternalUtils;
|
|
86
|
-
safeExec<
|
|
70
|
+
safeExec<T>(options: (() => TBlackHole) | SafeExecOptions): Promise<T>;
|
|
87
71
|
}
|
|
88
72
|
export {};
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
6
|
-
const events_1 = require("events");
|
|
7
|
-
const __1 = require("..");
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
import { EventEmitter } from "events";
|
|
3
|
+
import { ARRAY_OFFSET, DAY, FIRST, HOUR, is, MINUTE, NONE, SECOND, START, YEAR, } from "..";
|
|
8
4
|
const EVERYTHING_ELSE = 1;
|
|
9
5
|
const MONTHS = 12;
|
|
10
6
|
// TODO: probably should make this configurable
|
|
@@ -13,39 +9,48 @@ const formatter = new Intl.RelativeTimeFormat("en", {
|
|
|
13
9
|
style: "short",
|
|
14
10
|
});
|
|
15
11
|
// #MARK: misc
|
|
16
|
-
class InternalUtils {
|
|
12
|
+
export class InternalUtils {
|
|
17
13
|
/**
|
|
18
14
|
* The global eventemitter. All of `@digital-alchemy` will be wired through this
|
|
19
15
|
*
|
|
20
16
|
* **NOTE:** bootstrapping process will initialize this at boot, and cleanup at teardown.
|
|
21
17
|
* Making listener changes should only be done from within the context of service functions
|
|
22
18
|
*/
|
|
23
|
-
event
|
|
24
|
-
|
|
19
|
+
event;
|
|
20
|
+
constructor() {
|
|
21
|
+
this.event = new EventEmitter();
|
|
22
|
+
this.event.setMaxListeners(NONE);
|
|
23
|
+
}
|
|
24
|
+
titleCase(input) {
|
|
25
25
|
const matches = input.match(new RegExp("[a-z][A-Z]", "g"));
|
|
26
26
|
if (matches) {
|
|
27
|
-
matches.forEach(
|
|
27
|
+
matches.forEach(i => (input = input.replace(i, [...i].join(" "))));
|
|
28
28
|
}
|
|
29
29
|
return input
|
|
30
30
|
.split(new RegExp("[ _-]"))
|
|
31
|
-
.map(
|
|
31
|
+
.map(word => `${word.charAt(FIRST).toUpperCase()}${word.slice(EVERYTHING_ELSE)}`)
|
|
32
32
|
.join(" ");
|
|
33
33
|
}
|
|
34
34
|
relativeDate(pastDate, futureDate = new Date().toISOString()) {
|
|
35
35
|
const UNITS = new Map([
|
|
36
|
-
["year",
|
|
37
|
-
["month",
|
|
38
|
-
["day",
|
|
39
|
-
["hour",
|
|
40
|
-
["minute",
|
|
41
|
-
["second",
|
|
36
|
+
["year", YEAR],
|
|
37
|
+
["month", YEAR / MONTHS],
|
|
38
|
+
["day", DAY],
|
|
39
|
+
["hour", HOUR],
|
|
40
|
+
["minute", MINUTE],
|
|
41
|
+
["second", SECOND],
|
|
42
42
|
]);
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
const past = dayjs(pastDate);
|
|
44
|
+
if (!past.isValid()) {
|
|
45
|
+
throw new Error("invalid past date " + pastDate);
|
|
46
|
+
}
|
|
47
|
+
const future = dayjs(futureDate);
|
|
48
|
+
if (!future.isValid()) {
|
|
49
|
+
throw new Error("invalid future date " + pastDate);
|
|
45
50
|
}
|
|
46
|
-
const elapsed =
|
|
51
|
+
const elapsed = past.diff(future, "ms");
|
|
47
52
|
let out = "";
|
|
48
|
-
[...UNITS.keys()].some(
|
|
53
|
+
[...UNITS.keys()].some(unit => {
|
|
49
54
|
const cutoff = UNITS.get(unit);
|
|
50
55
|
if (Math.abs(elapsed) > cutoff || unit == "second") {
|
|
51
56
|
out = formatter.format(Math.round(elapsed / cutoff), unit);
|
|
@@ -60,7 +65,7 @@ class InternalUtils {
|
|
|
60
65
|
del(object, path) {
|
|
61
66
|
const keys = path.split(".");
|
|
62
67
|
let current = object; // Starting with the object as an unknown type
|
|
63
|
-
for (let i =
|
|
68
|
+
for (let i = START; i < keys.length; i++) {
|
|
64
69
|
const key = keys[i];
|
|
65
70
|
// Check if current is an object and not null
|
|
66
71
|
if (typeof current !== "object" || current === null) {
|
|
@@ -69,13 +74,12 @@ class InternalUtils {
|
|
|
69
74
|
}
|
|
70
75
|
const safeCurrent = current;
|
|
71
76
|
// If we're at the last key, attempt to delete the property
|
|
72
|
-
if (i === keys.length -
|
|
77
|
+
if (i === keys.length - ARRAY_OFFSET) {
|
|
73
78
|
delete safeCurrent[key]; // Delete without checking; non-existent keys are a no-op
|
|
74
79
|
}
|
|
75
80
|
else {
|
|
76
81
|
// For non-last keys, if the next level doesn't exist or isn't an object, stop processing
|
|
77
|
-
if (typeof safeCurrent[key] !== "object" ||
|
|
78
|
-
safeCurrent[key] === null) {
|
|
82
|
+
if (typeof safeCurrent[key] !== "object" || safeCurrent[key] === null) {
|
|
79
83
|
return;
|
|
80
84
|
}
|
|
81
85
|
// Move to the next level in the path
|
|
@@ -87,7 +91,7 @@ class InternalUtils {
|
|
|
87
91
|
const keys = path.split(".");
|
|
88
92
|
let current = object;
|
|
89
93
|
for (const key of keys) {
|
|
90
|
-
if (!
|
|
94
|
+
if (!is.object(current) || current === null || !(key in current)) {
|
|
91
95
|
return undefined;
|
|
92
96
|
}
|
|
93
97
|
current = current[key];
|
|
@@ -106,7 +110,7 @@ class InternalUtils {
|
|
|
106
110
|
// Safely cast current to Record<string, unknown> after the type guard
|
|
107
111
|
const safeCurrent = current;
|
|
108
112
|
// For the last key, attempt to set the value
|
|
109
|
-
if (i === keys.length -
|
|
113
|
+
if (i === keys.length - ARRAY_OFFSET) {
|
|
110
114
|
if (!doNotReplace || !(key in safeCurrent)) {
|
|
111
115
|
safeCurrent[key] = value;
|
|
112
116
|
}
|
|
@@ -125,9 +129,8 @@ class InternalUtils {
|
|
|
125
129
|
},
|
|
126
130
|
};
|
|
127
131
|
}
|
|
128
|
-
exports.InternalUtils = InternalUtils;
|
|
129
132
|
// #region Base definition
|
|
130
|
-
class InternalDefinition {
|
|
133
|
+
export class InternalDefinition {
|
|
131
134
|
/**
|
|
132
135
|
* Utility methods provided by boilerplate
|
|
133
136
|
*/
|
|
@@ -136,36 +139,21 @@ class InternalDefinition {
|
|
|
136
139
|
utils = new InternalUtils();
|
|
137
140
|
// #MARK: safeExec
|
|
138
141
|
async safeExec(options) {
|
|
139
|
-
|
|
140
|
-
|
|
142
|
+
const logger = this.boilerplate.logger.systemLogger;
|
|
143
|
+
const context = is.function(options) ? undefined : options?.context;
|
|
144
|
+
const exec = is.function(options) ? options : options?.exec;
|
|
145
|
+
if (!is.function(exec)) {
|
|
146
|
+
logger.error({ context }, `received non-function callback to [safeExec]`);
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
141
149
|
try {
|
|
142
|
-
|
|
143
|
-
await options();
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
const opt = options;
|
|
147
|
-
labels = opt.labels;
|
|
148
|
-
errorMetric = opt.errors;
|
|
149
|
-
const { exec, duration, executions } = opt;
|
|
150
|
-
if (__1.is.empty(labels.label)) {
|
|
151
|
-
await exec();
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
executions?.inc(labels);
|
|
155
|
-
const end = duration?.startTimer();
|
|
156
|
-
await exec();
|
|
157
|
-
if (end) {
|
|
158
|
-
end(labels);
|
|
159
|
-
}
|
|
150
|
+
return (await exec());
|
|
160
151
|
}
|
|
161
152
|
catch (error) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
errorMetric?.inc(labels);
|
|
165
|
-
}
|
|
153
|
+
logger.error({ context, error }, `callback threw error`);
|
|
154
|
+
return undefined;
|
|
166
155
|
}
|
|
167
156
|
}
|
|
168
157
|
}
|
|
169
|
-
exports.InternalDefinition = InternalDefinition;
|
|
170
158
|
// #endregion
|
|
171
159
|
//# sourceMappingURL=internal.extension.js.map
|