@getstrata/bootstrap 2.2.59 → 3.0.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/CHANGELOG.md +28 -0
- package/dist/bootstrap/app.d.ts +18 -7
- package/dist/bootstrap/buildModuleRoutes.d.ts +3 -5
- package/dist/bootstrap/buildWebModuleRoutes.d.ts +2 -3
- package/dist/bootstrap/cache/modelCacheTags.d.ts +3 -2
- package/dist/bootstrap/cachedJson.d.ts +7 -2
- package/dist/bootstrap/config.d.ts +1 -1
- package/dist/bootstrap/context.d.ts +25 -7
- package/dist/bootstrap/contracts.d.ts +1 -0
- package/dist/bootstrap/createWebRoutes.d.ts +2 -1
- package/dist/bootstrap/databaseReadiness.d.ts +3 -0
- package/dist/bootstrap/dependencies.d.ts +3 -2
- package/dist/bootstrap/discoverJobs.d.ts +3 -2
- package/dist/bootstrap/discoverListeners.d.ts +10 -7
- package/dist/bootstrap/discoverModels.d.ts +3 -2
- package/dist/bootstrap/discoverModules.d.ts +7 -6
- package/dist/bootstrap/health.d.ts +3 -2
- package/dist/bootstrap/http/securedRouteModelBinding.d.ts +1 -1
- package/dist/bootstrap/httpKernel.d.ts +43 -22
- package/dist/bootstrap/httpPersistence.d.ts +4 -0
- package/dist/bootstrap/inProcessCron.d.ts +5 -5
- package/dist/bootstrap/listeners/invalidateCacheOnModelWrite.d.ts +13 -12
- package/dist/bootstrap/metricsRoutes.d.ts +6 -1
- package/dist/bootstrap/moduleRouteMiddleware.d.ts +4 -4
- package/dist/bootstrap/modules.d.ts +1 -1
- package/dist/bootstrap/ownedHttpRoute.d.ts +23 -0
- package/dist/bootstrap/persistenceContracts.d.ts +70 -0
- package/dist/bootstrap/persistenceInvocation.d.ts +4 -0
- package/dist/bootstrap/providers/auth.d.ts +21 -0
- package/dist/bootstrap/providers/cache.d.ts +9 -3
- package/dist/bootstrap/providers/cacheProvider.d.ts +3 -0
- package/dist/bootstrap/providers/config.d.ts +6 -3
- package/dist/bootstrap/providers/events.d.ts +5 -2
- package/dist/bootstrap/providers/index.d.ts +3 -2
- package/dist/bootstrap/providers/listeners.d.ts +3 -3
- package/dist/bootstrap/providers/mail.d.ts +15 -0
- package/dist/bootstrap/providers/queue.d.ts +3 -2
- package/dist/bootstrap/providers/storage.d.ts +11 -2
- package/dist/bootstrap/providers/tracing.d.ts +4 -2
- package/dist/bootstrap/providers/view.d.ts +8 -5
- package/dist/bootstrap/public-api.d.ts +10 -7
- package/dist/bootstrap/queue/defaultJobs.d.ts +4 -2
- package/dist/bootstrap/rateLimit.d.ts +13 -3
- package/dist/bootstrap/routeCompiler.d.ts +20 -0
- package/dist/bootstrap/routeMetadata.d.ts +3 -3
- package/dist/bootstrap/routePlan.d.ts +11 -0
- package/dist/bootstrap/schedule.d.ts +11 -2
- package/dist/bootstrap/secretsGuard.d.ts +2 -3
- package/dist/bootstrap/web/routing.d.ts +6 -3
- package/dist/bootstrap/web/server.d.ts +14 -4
- package/dist/bootstrap/web/session.d.ts +23 -16
- package/dist/entries/buildModuleRoutes.js +602 -384
- package/dist/entries/buildWebModuleRoutes.js +596 -347
- package/dist/entries/cache/modelCacheTags.js +8 -186
- package/dist/entries/cachedJson.js +22 -0
- package/dist/entries/config.js +1 -3
- package/dist/entries/context.js +665 -700
- package/dist/entries/createSpaRoutes.js +194 -5
- package/dist/entries/createWebRoutes.js +618 -367
- package/dist/entries/databaseReadiness.js +267 -0
- package/dist/entries/dependencies.js +666 -701
- package/dist/entries/discoverJobs.js +18 -16
- package/dist/entries/discoverListeners.js +27 -38
- package/dist/entries/discoverModels.js +4 -3
- package/dist/entries/discoverModules.js +29 -67
- package/dist/entries/health.js +14 -34
- package/dist/entries/httpKernel.js +405 -89
- package/dist/entries/listeners/invalidateCacheOnModelWrite.js +43 -289
- package/dist/entries/metricsRoutes.js +9 -5
- package/dist/entries/persistenceContracts.js +1 -0
- package/dist/entries/persistenceInvocation.js +17 -0
- package/dist/entries/providers/auth.js +114 -0
- package/dist/entries/providers/cache.js +35 -0
- package/dist/entries/providers/events.js +55 -0
- package/dist/entries/providers/view.js +34 -44
- package/dist/entries/providers.js +392 -561
- package/dist/entries/queue/defaultJobs.js +9 -6
- package/dist/entries/routePlan.js +200 -0
- package/dist/entries/schedule.js +37 -37
- package/dist/entries/secretsGuard.js +10 -13
- package/dist/entries/web/routing.js +412 -96
- package/dist/entries/web/server.js +461 -29
- package/dist/entries/web/session.js +61 -73
- package/dist/index.js +1520 -1085
- package/dist/internal/ownedHttpRoute.js +66 -0
- package/package.json +52 -15
- package/dist/bootstrap/applicationRegistry.d.ts +0 -1
- package/dist/bootstrap/routeRegistry.d.ts +0 -10
- package/dist/entries/applicationRegistry.js +0 -24
- package/dist/entries/routeRegistry.js +0 -29
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
// ../../src/bootstrap/discoverJobs.ts
|
|
3
3
|
import { join as join2, resolve } from "path";
|
|
4
4
|
import { Job } from "@getstrata/core/queue";
|
|
5
|
-
import { jobRegistry } from "@getstrata/core/queue/jobRegistry";
|
|
6
5
|
|
|
7
6
|
// ../../src/bootstrap/infrastructureDiscovery.ts
|
|
8
7
|
import { readdir } from "fs/promises";
|
|
@@ -54,17 +53,20 @@ async function importInfrastructure(file) {
|
|
|
54
53
|
}
|
|
55
54
|
|
|
56
55
|
// ../../src/bootstrap/discoverJobs.ts
|
|
57
|
-
var
|
|
58
|
-
function state() {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
var states = new WeakMap;
|
|
57
|
+
function state(registry) {
|
|
58
|
+
let value = states.get(registry);
|
|
59
|
+
if (!value) {
|
|
60
|
+
value = { loads: new Map, registered: new Map };
|
|
61
|
+
states.set(registry, value);
|
|
62
|
+
}
|
|
63
|
+
return value;
|
|
62
64
|
}
|
|
63
65
|
function validateClass(value, location) {
|
|
64
66
|
if (typeof value !== "function" || typeof value.jobName !== "string" || !value.jobName.trim() || !(value.prototype instanceof Job) && typeof value.prototype?.handle !== "function")
|
|
65
67
|
throw new TypeError(`Invalid job at ${location}: expected a class with nonempty static jobName and handle().`);
|
|
66
68
|
}
|
|
67
|
-
async function load(options, current) {
|
|
69
|
+
async function load(registry, options, current) {
|
|
68
70
|
const jobs = new Map;
|
|
69
71
|
const add = (name, identity, create, location) => {
|
|
70
72
|
const previous = jobs.get(name);
|
|
@@ -109,23 +111,23 @@ async function load(options, current) {
|
|
|
109
111
|
}
|
|
110
112
|
if (!current())
|
|
111
113
|
return [...jobs.keys()];
|
|
112
|
-
const registered = state().registered;
|
|
114
|
+
const registered = state(registry).registered;
|
|
113
115
|
for (const [name, entry] of jobs) {
|
|
114
116
|
const previous = registered.get(name);
|
|
115
117
|
if (previous && previous.identity !== entry.identity)
|
|
116
118
|
throw new Error(`Duplicate discovered job "${name}" at ${entry.location}; first declared at ${previous.location}.`);
|
|
117
119
|
}
|
|
118
|
-
const existing = new Set(
|
|
120
|
+
const existing = new Set(registry.names());
|
|
119
121
|
for (const [name, entry] of jobs) {
|
|
120
122
|
if (!existing.has(name)) {
|
|
121
|
-
|
|
123
|
+
registry.register(name, entry.create);
|
|
122
124
|
registered.set(name, entry);
|
|
123
125
|
}
|
|
124
126
|
}
|
|
125
127
|
return [...jobs.keys()];
|
|
126
128
|
}
|
|
127
|
-
function discoverJobs(options = {}) {
|
|
128
|
-
const cache = state().loads;
|
|
129
|
+
function discoverJobs(registry, options = {}) {
|
|
130
|
+
const cache = state(registry).loads;
|
|
129
131
|
const key = options.manifest ?? JSON.stringify([
|
|
130
132
|
resolve(options.directory ?? join2(process.cwd(), "src", "jobs")),
|
|
131
133
|
[...options.exclude ?? []].sort()
|
|
@@ -133,7 +135,7 @@ function discoverJobs(options = {}) {
|
|
|
133
135
|
const existing = cache.get(key);
|
|
134
136
|
if (existing)
|
|
135
137
|
return existing;
|
|
136
|
-
const pending = load(options, () => state().loads === cache).catch((error) => {
|
|
138
|
+
const pending = load(registry, options, () => state(registry).loads === cache).catch((error) => {
|
|
137
139
|
if (cache.get(key) === pending)
|
|
138
140
|
cache.delete(key);
|
|
139
141
|
throw error;
|
|
@@ -141,9 +143,9 @@ function discoverJobs(options = {}) {
|
|
|
141
143
|
cache.set(key, pending);
|
|
142
144
|
return pending;
|
|
143
145
|
}
|
|
144
|
-
function resetDiscoverJobsForTests() {
|
|
145
|
-
state().loads = new Map;
|
|
146
|
-
state().registered = new Map;
|
|
146
|
+
function resetDiscoverJobsForTests(registry) {
|
|
147
|
+
state(registry).loads = new Map;
|
|
148
|
+
state(registry).registered = new Map;
|
|
147
149
|
}
|
|
148
150
|
export {
|
|
149
151
|
discoverJobs,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// ../../src/bootstrap/discoverListeners.ts
|
|
3
|
-
import { join as join2
|
|
3
|
+
import { join as join2 } from "path";
|
|
4
4
|
|
|
5
5
|
// ../../src/bootstrap/infrastructureDiscovery.ts
|
|
6
6
|
import { readdir } from "fs/promises";
|
|
@@ -52,51 +52,40 @@ async function importInfrastructure(file) {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
// ../../src/bootstrap/discoverListeners.ts
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
function snapshot(value, location) {
|
|
56
|
+
if (!value || typeof value !== "object")
|
|
57
|
+
throw new TypeError(`Invalid listener declarations at ${location}.`);
|
|
58
|
+
const fields = Object.getOwnPropertyDescriptors(value);
|
|
59
|
+
const services = fields.services?.value, effects = fields.repositoryEffects?.value;
|
|
60
|
+
if (!fields.services || !("value" in fields.services) || !Array.isArray(services) || !fields.repositoryEffects || !("value" in fields.repositoryEffects) || !Array.isArray(effects))
|
|
61
|
+
throw new TypeError(`Listener ${location} must export services and repositoryEffects declarations; registrar callbacks are no longer supported.`);
|
|
62
|
+
return Object.freeze({
|
|
63
|
+
services: Object.freeze([...services]),
|
|
64
|
+
repositoryEffects: Object.freeze([...effects])
|
|
65
|
+
});
|
|
60
66
|
}
|
|
61
|
-
async function
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
async function discoverListeners(options = {}) {
|
|
68
|
+
const result = [];
|
|
69
|
+
const seen = new Set;
|
|
70
|
+
const add = (input, location) => {
|
|
71
|
+
const value = input && typeof input === "object" && Object.getOwnPropertyDescriptor(input, "default")?.value ? Object.getOwnPropertyDescriptor(input, "default")?.value : input;
|
|
72
|
+
if (value && typeof value === "object") {
|
|
73
|
+
if (seen.has(value))
|
|
74
|
+
return;
|
|
75
|
+
seen.add(value);
|
|
76
|
+
}
|
|
77
|
+
result.push(snapshot(value, location));
|
|
67
78
|
};
|
|
68
79
|
if (options.manifest)
|
|
69
80
|
for (const [index, value] of options.manifest.entries())
|
|
70
|
-
add(value, `
|
|
81
|
+
add(value, `manifest[${index}]`);
|
|
71
82
|
else
|
|
72
83
|
for (const file of await infrastructureFiles(options.directory ?? join2(process.cwd(), "src", "listeners"), options.exclude)) {
|
|
73
84
|
const exports = await importInfrastructure(file);
|
|
74
|
-
|
|
75
|
-
add(value && typeof value === "object" && "default" in value ? value.default : value, file);
|
|
85
|
+
add(exports.default, file);
|
|
76
86
|
}
|
|
77
|
-
return
|
|
78
|
-
}
|
|
79
|
-
function discoverListeners(options = {}) {
|
|
80
|
-
const cache = state().loads;
|
|
81
|
-
const key = options.manifest ?? JSON.stringify([
|
|
82
|
-
resolve(options.directory ?? join2(process.cwd(), "src", "listeners")),
|
|
83
|
-
[...options.exclude ?? []].sort()
|
|
84
|
-
]);
|
|
85
|
-
const existing = cache.get(key);
|
|
86
|
-
if (existing)
|
|
87
|
-
return existing;
|
|
88
|
-
const pending = load(options).catch((error) => {
|
|
89
|
-
if (cache.get(key) === pending)
|
|
90
|
-
cache.delete(key);
|
|
91
|
-
throw error;
|
|
92
|
-
});
|
|
93
|
-
cache.set(key, pending);
|
|
94
|
-
return pending;
|
|
95
|
-
}
|
|
96
|
-
function resetDiscoverListenersForTests() {
|
|
97
|
-
state().loads = new Map;
|
|
87
|
+
return Object.freeze(result);
|
|
98
88
|
}
|
|
99
89
|
export {
|
|
100
|
-
discoverListeners
|
|
101
|
-
resetDiscoverListenersForTests
|
|
90
|
+
discoverListeners
|
|
102
91
|
};
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { readdir } from "fs/promises";
|
|
4
4
|
import { join } from "path";
|
|
5
5
|
import { pathToFileURL } from "url";
|
|
6
|
-
import {
|
|
6
|
+
import { assertDefinition } from "@getstrata/core/database/definitions";
|
|
7
7
|
async function discoverModels(directory = join(process.cwd(), "src", "models"), options = {}) {
|
|
8
8
|
const excluded = new Set([
|
|
9
9
|
"register.ts",
|
|
@@ -23,15 +23,16 @@ async function discoverModels(directory = join(process.cwd(), "src", "models"),
|
|
|
23
23
|
else if (!excluded.has(entry.name) && entry.isFile() && /\.(ts|js|mts|mjs)$/.test(entry.name) && !/\.d\.[cm]?ts$/.test(entry.name)) {
|
|
24
24
|
const exports = await import(pathToFileURL(file).href);
|
|
25
25
|
for (const value of Object.values(exports)) {
|
|
26
|
-
if (typeof value === "
|
|
26
|
+
if (value && typeof value === "object" && Object.getOwnPropertyDescriptor(value, "kind")?.value === "model") {
|
|
27
|
+
assertDefinition(value, "model");
|
|
27
28
|
models.add(value);
|
|
29
|
+
}
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
33
|
}
|
|
32
34
|
await visit(directory);
|
|
33
35
|
const result = [...models];
|
|
34
|
-
bootModels(result);
|
|
35
36
|
return result;
|
|
36
37
|
}
|
|
37
38
|
export {
|
|
@@ -53,32 +53,6 @@ async function importInfrastructure(file) {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
// ../../src/bootstrap/discoverModules.ts
|
|
56
|
-
var KEY = Symbol.for("@getstrata/discoverModulesState");
|
|
57
|
-
function state() {
|
|
58
|
-
const globals = globalThis;
|
|
59
|
-
globals[KEY] ??= { appModules: [] };
|
|
60
|
-
return globals[KEY];
|
|
61
|
-
}
|
|
62
|
-
function configureModulesDirectory(modulesDir) {
|
|
63
|
-
const current = state();
|
|
64
|
-
const directory = resolve(modulesDir);
|
|
65
|
-
if (current.configuredModulesDir !== directory || current.configuredManifest) {
|
|
66
|
-
current.appModules.length = 0;
|
|
67
|
-
current.modulesReady = undefined;
|
|
68
|
-
current.source = undefined;
|
|
69
|
-
}
|
|
70
|
-
current.configuredManifest = undefined;
|
|
71
|
-
current.configuredModulesDir = directory;
|
|
72
|
-
}
|
|
73
|
-
function configureModulesManifest(manifest) {
|
|
74
|
-
const current = state();
|
|
75
|
-
if (current.configuredManifest !== manifest) {
|
|
76
|
-
current.appModules.length = 0;
|
|
77
|
-
current.modulesReady = undefined;
|
|
78
|
-
current.source = undefined;
|
|
79
|
-
}
|
|
80
|
-
current.configuredManifest = manifest;
|
|
81
|
-
}
|
|
82
56
|
function validateModule(value, location) {
|
|
83
57
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
84
58
|
throw new TypeError(`Invalid application module at ${location}.`);
|
|
@@ -100,21 +74,21 @@ function validateModule(value, location) {
|
|
|
100
74
|
}
|
|
101
75
|
}
|
|
102
76
|
async function load(options) {
|
|
103
|
-
const manifest = options.manifest
|
|
77
|
+
const manifest = options.manifest;
|
|
104
78
|
const entries = [];
|
|
105
79
|
if (manifest)
|
|
106
80
|
for (const [index, value] of manifest.entries())
|
|
107
81
|
entries.push({ value, location: `module manifest[${index}]` });
|
|
108
82
|
else {
|
|
109
|
-
const directory = options.modulesDir
|
|
83
|
+
const directory = options.modulesDir;
|
|
110
84
|
if (!directory)
|
|
111
|
-
throw new Error("
|
|
85
|
+
throw new Error("An explicit modulesDir or manifest is required to discover modules.");
|
|
112
86
|
let folders;
|
|
113
87
|
try {
|
|
114
88
|
folders = await readdir2(directory, { withFileTypes: true });
|
|
115
89
|
} catch (error) {
|
|
116
90
|
if (error.code === "ENOENT")
|
|
117
|
-
return [];
|
|
91
|
+
return Object.freeze([]);
|
|
118
92
|
throw error;
|
|
119
93
|
}
|
|
120
94
|
const excluded = new Set(options.exclude ?? []);
|
|
@@ -139,46 +113,34 @@ async function load(options) {
|
|
|
139
113
|
names.set(value.name, location);
|
|
140
114
|
modules.push(value);
|
|
141
115
|
}
|
|
142
|
-
return modules.sort((left, right) => (left.order ?? 100) - (right.order ?? 100));
|
|
116
|
+
return Object.freeze(modules.sort((left, right) => (left.order ?? 100) - (right.order ?? 100)));
|
|
143
117
|
}
|
|
144
|
-
function
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
options.modulesDir ? resolve(options.modulesDir)
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
118
|
+
function createModuleDiscovery(options) {
|
|
119
|
+
const source = Object.freeze({
|
|
120
|
+
...options,
|
|
121
|
+
modulesDir: options.modulesDir === undefined ? undefined : resolve(options.modulesDir),
|
|
122
|
+
manifest: options.manifest === undefined ? undefined : Object.freeze([...options.manifest]),
|
|
123
|
+
exclude: options.exclude === undefined ? undefined : Object.freeze([...options.exclude])
|
|
124
|
+
});
|
|
125
|
+
let pending;
|
|
126
|
+
return Object.freeze({
|
|
127
|
+
load() {
|
|
128
|
+
if (pending)
|
|
129
|
+
return pending;
|
|
130
|
+
const result = load(source).catch((error) => {
|
|
131
|
+
if (pending === result)
|
|
132
|
+
pending = undefined;
|
|
133
|
+
throw error;
|
|
134
|
+
});
|
|
135
|
+
pending = result;
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
163
138
|
});
|
|
164
|
-
current.modulesReady = pending;
|
|
165
|
-
return pending;
|
|
166
|
-
}
|
|
167
|
-
function discoverModules() {
|
|
168
|
-
return state().appModules;
|
|
169
139
|
}
|
|
170
|
-
function
|
|
171
|
-
|
|
172
|
-
current.configuredModulesDir = undefined;
|
|
173
|
-
current.configuredManifest = undefined;
|
|
174
|
-
current.appModules.length = 0;
|
|
175
|
-
current.modulesReady = undefined;
|
|
176
|
-
current.source = undefined;
|
|
140
|
+
function ensureModulesLoaded(options) {
|
|
141
|
+
return createModuleDiscovery(options).load();
|
|
177
142
|
}
|
|
178
143
|
export {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
discoverModules,
|
|
182
|
-
ensureModulesLoaded,
|
|
183
|
-
resetDiscoverModulesForTests
|
|
144
|
+
createModuleDiscovery,
|
|
145
|
+
ensureModulesLoaded
|
|
184
146
|
};
|
package/dist/entries/health.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// ../../src/bootstrap/health.ts
|
|
3
|
-
import { getBoundDatabaseConnection } from "@getstrata/core/database/boundConnection";
|
|
4
|
-
import { getDefaultDatabasePool } from "@getstrata/core/database/defaultConnection";
|
|
5
3
|
import { jsonResponse } from "@getstrata/core/http/response";
|
|
6
4
|
import { envFlagEnabled } from "@getstrata/core/runtime/appEnv";
|
|
7
5
|
var {RedisClient } = globalThis.Bun;
|
|
@@ -19,8 +17,7 @@ import {
|
|
|
19
17
|
CORE_PUBLIC_TENANCY_TOKEN,
|
|
20
18
|
CORE_QUEUE_TOKEN,
|
|
21
19
|
CORE_TENANT_RESOLVER_TOKEN,
|
|
22
|
-
CORE_THROTTLE_QUOTA_POLICY_TOKEN
|
|
23
|
-
CORE_TOKEN_SERVICE_TOKEN
|
|
20
|
+
CORE_THROTTLE_QUOTA_POLICY_TOKEN
|
|
24
21
|
} from "@getstrata/core/contracts/serviceTokens";
|
|
25
22
|
var APP_PORT_CONFIG_KEY = "app.port";
|
|
26
23
|
var CACHE_TTL_MS_CONFIG_KEY = "cache.ttlMs";
|
|
@@ -46,35 +43,16 @@ function resolveRedisUrl(dependencies) {
|
|
|
46
43
|
const redisUrl = config.get(REDIS_URL_CONFIG_KEY)?.trim();
|
|
47
44
|
return redisUrl || undefined;
|
|
48
45
|
}
|
|
49
|
-
function
|
|
50
|
-
const bound = getBoundDatabaseConnection();
|
|
51
|
-
if (bound) {
|
|
52
|
-
return bound;
|
|
53
|
-
}
|
|
54
|
-
try {
|
|
55
|
-
return getDefaultDatabasePool();
|
|
56
|
-
} catch {
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
async function pingDatabaseClient(connection) {
|
|
46
|
+
async function pingDatabase(invoke) {
|
|
61
47
|
try {
|
|
62
|
-
await
|
|
63
|
-
|
|
48
|
+
return await invoke({ kind: "request", actor: { kind: "system", policy: "http.health" } }, async ({ database }) => {
|
|
49
|
+
await database.execute({ text: "SELECT 1", params: [] });
|
|
50
|
+
return true;
|
|
51
|
+
});
|
|
64
52
|
} catch {
|
|
65
53
|
return false;
|
|
66
54
|
}
|
|
67
55
|
}
|
|
68
|
-
async function checkDatabase() {
|
|
69
|
-
const connection = resolveHealthDatabase();
|
|
70
|
-
if (!connection) {
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
return await pingDatabaseClient(connection);
|
|
74
|
-
}
|
|
75
|
-
async function pingDatabase() {
|
|
76
|
-
return await checkDatabase();
|
|
77
|
-
}
|
|
78
56
|
async function checkRedis(redisUrl) {
|
|
79
57
|
let client;
|
|
80
58
|
try {
|
|
@@ -97,11 +75,10 @@ async function resolveExtraFields(extra) {
|
|
|
97
75
|
}
|
|
98
76
|
return typeof extra === "function" ? await extra() : extra;
|
|
99
77
|
}
|
|
100
|
-
async function collectDependencyChecks(dependencies) {
|
|
78
|
+
async function collectDependencyChecks(dependencies, redisUrl) {
|
|
101
79
|
const checks = {
|
|
102
|
-
database: await
|
|
80
|
+
database: await pingDatabase(dependencies.invoke) ? "ok" : "error"
|
|
103
81
|
};
|
|
104
|
-
const redisUrl = resolveRedisUrl(dependencies);
|
|
105
82
|
if (redisUrl) {
|
|
106
83
|
checks.redis = await checkRedis(redisUrl) ? "ok" : "error";
|
|
107
84
|
} else {
|
|
@@ -111,6 +88,9 @@ async function collectDependencyChecks(dependencies) {
|
|
|
111
88
|
return { checks, ready };
|
|
112
89
|
}
|
|
113
90
|
function createHealthRoutes(dependencies, options = {}) {
|
|
91
|
+
const redisUrl = resolveRedisUrl(dependencies);
|
|
92
|
+
const config = dependencies.container.has(CORE_CONFIG_TOKEN) ? dependencies.container.resolve(CORE_CONFIG_TOKEN) : undefined;
|
|
93
|
+
const debug = config ? config.get("app.debug") === true : envFlagEnabled(process.env.APP_DEBUG);
|
|
114
94
|
return {
|
|
115
95
|
"/health": async (request) => {
|
|
116
96
|
if (request && request.method !== "GET" && request.method !== "HEAD") {
|
|
@@ -123,7 +103,7 @@ function createHealthRoutes(dependencies, options = {}) {
|
|
|
123
103
|
headers: { ...headers, "content-type": "text/plain; charset=utf-8" }
|
|
124
104
|
}) : jsonResponse({ status: "ok", ...extra }, { headers });
|
|
125
105
|
}
|
|
126
|
-
const { checks, ready: dependenciesReady } = await collectDependencyChecks(dependencies);
|
|
106
|
+
const { checks, ready: dependenciesReady } = await collectDependencyChecks(dependencies, redisUrl);
|
|
127
107
|
let schemaReady = true;
|
|
128
108
|
if (options.schemaCheck) {
|
|
129
109
|
try {
|
|
@@ -149,8 +129,7 @@ function createHealthRoutes(dependencies, options = {}) {
|
|
|
149
129
|
},
|
|
150
130
|
"/ready": async () => {
|
|
151
131
|
const extra = await resolveExtraFields(options.extra);
|
|
152
|
-
const { checks, ready } = await collectDependencyChecks(dependencies);
|
|
153
|
-
const debug = envFlagEnabled(process.env.APP_DEBUG);
|
|
132
|
+
const { checks, ready } = await collectDependencyChecks(dependencies, redisUrl);
|
|
154
133
|
return jsonResponse({
|
|
155
134
|
status: ready ? "ready" : "not_ready",
|
|
156
135
|
...debug ? { checks, ...extra } : {}
|
|
@@ -158,6 +137,7 @@ function createHealthRoutes(dependencies, options = {}) {
|
|
|
158
137
|
}
|
|
159
138
|
};
|
|
160
139
|
}
|
|
140
|
+
var checkDatabase = pingDatabase;
|
|
161
141
|
export {
|
|
162
142
|
checkDatabase,
|
|
163
143
|
checkRedis,
|