@getstrata/bootstrap 2.2.60 → 3.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -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
|
@@ -1,191 +1,13 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
// ../../src/bootstrap/discoverModules.ts
|
|
3
|
-
import { readdir as readdir2 } from "fs/promises";
|
|
4
|
-
import { join as join2, resolve } from "path";
|
|
5
|
-
|
|
6
|
-
// ../../src/bootstrap/infrastructureDiscovery.ts
|
|
7
|
-
import { readdir } from "fs/promises";
|
|
8
|
-
import { join, relative } from "path";
|
|
9
|
-
import { pathToFileURL } from "url";
|
|
10
|
-
async function infrastructureFiles(directory, exclude = []) {
|
|
11
|
-
const excluded = new Set([
|
|
12
|
-
"index.ts",
|
|
13
|
-
"index.js",
|
|
14
|
-
"index.mts",
|
|
15
|
-
"index.mjs",
|
|
16
|
-
"register.ts",
|
|
17
|
-
"register.js",
|
|
18
|
-
"register.mts",
|
|
19
|
-
"register.mjs",
|
|
20
|
-
...exclude
|
|
21
|
-
]);
|
|
22
|
-
const files = [];
|
|
23
|
-
async function visit(path) {
|
|
24
|
-
const entries = await readdir(path, { withFileTypes: true });
|
|
25
|
-
entries.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
26
|
-
for (const entry of entries) {
|
|
27
|
-
const file = join(path, entry.name);
|
|
28
|
-
const key = relative(directory, file).replaceAll("\\", "/");
|
|
29
|
-
if (excluded.has(entry.name) || excluded.has(key))
|
|
30
|
-
continue;
|
|
31
|
-
if (entry.isDirectory())
|
|
32
|
-
await visit(file);
|
|
33
|
-
else if (entry.isFile() && /\.(ts|js|mts|mjs)$/.test(entry.name) && !/\.(d|test|spec)\.[cm]?[jt]s$/.test(entry.name))
|
|
34
|
-
files.push(file);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
try {
|
|
38
|
-
await visit(directory);
|
|
39
|
-
} catch (error) {
|
|
40
|
-
if (error.code !== "ENOENT")
|
|
41
|
-
throw error;
|
|
42
|
-
if (error.path !== directory)
|
|
43
|
-
throw error;
|
|
44
|
-
}
|
|
45
|
-
return files;
|
|
46
|
-
}
|
|
47
|
-
async function importInfrastructure(file) {
|
|
48
|
-
try {
|
|
49
|
-
return await import(pathToFileURL(file).href);
|
|
50
|
-
} catch (error) {
|
|
51
|
-
throw new Error(`Cannot load infrastructure module ${file}`, { cause: error });
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
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
|
-
function validateModule(value, location) {
|
|
83
|
-
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
84
|
-
throw new TypeError(`Invalid application module at ${location}.`);
|
|
85
|
-
const module = value;
|
|
86
|
-
if (typeof module.name !== "string" || !module.name.trim())
|
|
87
|
-
throw new TypeError(`Invalid module name at ${location}.`);
|
|
88
|
-
if (module.order !== undefined && (typeof module.order !== "number" || !Number.isFinite(module.order)))
|
|
89
|
-
throw new TypeError(`Invalid module order at ${location}.`);
|
|
90
|
-
for (const hook of ["routes", "webRoutes"])
|
|
91
|
-
if (module[hook] !== undefined && typeof module[hook] !== "function")
|
|
92
|
-
throw new TypeError(`Invalid ${hook} at ${location}.`);
|
|
93
|
-
if (module.providers !== undefined) {
|
|
94
|
-
if (!Array.isArray(module.providers))
|
|
95
|
-
throw new TypeError(`Invalid providers at ${location}.`);
|
|
96
|
-
for (const provider of module.providers) {
|
|
97
|
-
if (!provider || typeof provider.name !== "string" || !provider.name.trim() || provider.register !== undefined && typeof provider.register !== "function" || provider.boot !== undefined && typeof provider.boot !== "function")
|
|
98
|
-
throw new TypeError(`Invalid provider at ${location}.`);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
async function load(options) {
|
|
103
|
-
const manifest = options.manifest ?? (options.modulesDir === undefined ? state().configuredManifest : undefined);
|
|
104
|
-
const entries = [];
|
|
105
|
-
if (manifest)
|
|
106
|
-
for (const [index, value] of manifest.entries())
|
|
107
|
-
entries.push({ value, location: `module manifest[${index}]` });
|
|
108
|
-
else {
|
|
109
|
-
const directory = options.modulesDir ?? state().configuredModulesDir;
|
|
110
|
-
if (!directory)
|
|
111
|
-
throw new Error("configureModulesDirectory() or configureModulesManifest() must be called before discovering modules.");
|
|
112
|
-
let folders;
|
|
113
|
-
try {
|
|
114
|
-
folders = await readdir2(directory, { withFileTypes: true });
|
|
115
|
-
} catch (error) {
|
|
116
|
-
if (error.code === "ENOENT")
|
|
117
|
-
return [];
|
|
118
|
-
throw error;
|
|
119
|
-
}
|
|
120
|
-
const excluded = new Set(options.exclude ?? []);
|
|
121
|
-
for (const folder of folders.filter((entry) => entry.isDirectory() && !excluded.has(entry.name)).sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0)) {
|
|
122
|
-
const path = join2(directory, folder.name);
|
|
123
|
-
const files = await readdir2(path);
|
|
124
|
-
const candidates = files.filter((file) => /^index\.(ts|js|mts|mjs)$/.test(file));
|
|
125
|
-
if (candidates.length !== 1)
|
|
126
|
-
throw new Error(`Expected one module entrypoint at ${path}; found ${candidates.length}.`);
|
|
127
|
-
const file = join2(path, candidates[0]);
|
|
128
|
-
const exports = await importInfrastructure(file);
|
|
129
|
-
entries.push({ value: exports.default, location: file });
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
const names = new Map;
|
|
133
|
-
const modules = [];
|
|
134
|
-
for (const { value, location } of entries) {
|
|
135
|
-
validateModule(value, location);
|
|
136
|
-
const previous = names.get(value.name);
|
|
137
|
-
if (previous)
|
|
138
|
-
throw new Error(`Duplicate module "${value.name}" at ${location}; first declared at ${previous}.`);
|
|
139
|
-
names.set(value.name, location);
|
|
140
|
-
modules.push(value);
|
|
141
|
-
}
|
|
142
|
-
return modules.sort((left, right) => (left.order ?? 100) - (right.order ?? 100));
|
|
143
|
-
}
|
|
144
|
-
function ensureModulesLoaded(options = {}) {
|
|
145
|
-
const current = state();
|
|
146
|
-
const key = options.manifest ?? (options.modulesDir === undefined ? current.configuredManifest : undefined) ?? JSON.stringify([
|
|
147
|
-
options.modulesDir ? resolve(options.modulesDir) : current.configuredModulesDir,
|
|
148
|
-
[...options.exclude ?? []].sort()
|
|
149
|
-
]);
|
|
150
|
-
if (current.modulesReady && current.source === key)
|
|
151
|
-
return current.modulesReady;
|
|
152
|
-
current.appModules.length = 0;
|
|
153
|
-
current.source = key;
|
|
154
|
-
const pending = load(options).then((modules) => {
|
|
155
|
-
if (current.modulesReady !== pending)
|
|
156
|
-
return modules;
|
|
157
|
-
current.appModules.splice(0, current.appModules.length, ...modules);
|
|
158
|
-
return current.appModules;
|
|
159
|
-
}).catch((error) => {
|
|
160
|
-
if (current.modulesReady === pending)
|
|
161
|
-
current.modulesReady = undefined;
|
|
162
|
-
throw error;
|
|
163
|
-
});
|
|
164
|
-
current.modulesReady = pending;
|
|
165
|
-
return pending;
|
|
166
|
-
}
|
|
167
|
-
function discoverModules() {
|
|
168
|
-
return state().appModules;
|
|
169
|
-
}
|
|
170
|
-
function resetDiscoverModulesForTests() {
|
|
171
|
-
const current = state();
|
|
172
|
-
current.configuredModulesDir = undefined;
|
|
173
|
-
current.configuredManifest = undefined;
|
|
174
|
-
current.appModules.length = 0;
|
|
175
|
-
current.modulesReady = undefined;
|
|
176
|
-
current.source = undefined;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
2
|
// ../../src/bootstrap/cache/modelCacheTags.ts
|
|
180
|
-
function cacheTagsForModelWrite(tableName, action) {
|
|
181
|
-
const module =
|
|
182
|
-
const baseTags = module?.cacheTags ?? [`${tableName}s`];
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
return discoverModules().map((module) => module.tableName).filter((tableName) => tableName !== undefined);
|
|
3
|
+
function cacheTagsForModelWrite(tableName, action, modules) {
|
|
4
|
+
const module = modules.find((entry) => entry.tableName === tableName);
|
|
5
|
+
const baseTags = module?.cacheTags ?? [tableName.endsWith("s") ? tableName : `${tableName}s`];
|
|
6
|
+
const extras = action === "deleted" || action === "force-deleted" ? module?.cacheDeleteExtraTags ?? [] : [];
|
|
7
|
+
return [...new Set([...baseTags, ...extras])];
|
|
8
|
+
}
|
|
9
|
+
function discoverModelTableNames(modules) {
|
|
10
|
+
return modules.map((module) => module.tableName).filter((name) => name !== undefined);
|
|
189
11
|
}
|
|
190
12
|
export {
|
|
191
13
|
cacheTagsForModelWrite,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// ../../src/bootstrap/cachedJson.ts
|
|
3
|
+
import { CORE_JSON_RESPONSE_POLICY_TOKEN } from "@getstrata/core/contracts/serviceTokens";
|
|
4
|
+
import {
|
|
5
|
+
conditionalJsonResponse,
|
|
6
|
+
snapshotJsonResponsePolicy
|
|
7
|
+
} from "@getstrata/core/http/conditionalResponse";
|
|
8
|
+
function createCachedJson(cache, policy) {
|
|
9
|
+
const responsePolicy = snapshotJsonResponsePolicy(policy);
|
|
10
|
+
return async (cacheKey, loader, tags = [], request) => {
|
|
11
|
+
const data = tags.length > 0 ? await cache.tags(...tags).remember(cacheKey, loader) : await cache.remember(cacheKey, loader);
|
|
12
|
+
return conditionalJsonResponse(request, data, responsePolicy);
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function createApplicationCachedJson(dependencies) {
|
|
16
|
+
const policy = dependencies.container.has(CORE_JSON_RESPONSE_POLICY_TOKEN) ? dependencies.container.resolve(CORE_JSON_RESPONSE_POLICY_TOKEN) : { etagEnabled: true };
|
|
17
|
+
return createCachedJson(dependencies.cache, policy);
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
createApplicationCachedJson,
|
|
21
|
+
createCachedJson
|
|
22
|
+
};
|
package/dist/entries/config.js
CHANGED
|
@@ -12,8 +12,7 @@ import {
|
|
|
12
12
|
CORE_PUBLIC_TENANCY_TOKEN,
|
|
13
13
|
CORE_QUEUE_TOKEN,
|
|
14
14
|
CORE_TENANT_RESOLVER_TOKEN,
|
|
15
|
-
CORE_THROTTLE_QUOTA_POLICY_TOKEN
|
|
16
|
-
CORE_TOKEN_SERVICE_TOKEN
|
|
15
|
+
CORE_THROTTLE_QUOTA_POLICY_TOKEN
|
|
17
16
|
} from "@getstrata/core/contracts/serviceTokens";
|
|
18
17
|
var APP_PORT_CONFIG_KEY = "app.port";
|
|
19
18
|
var CACHE_TTL_MS_CONFIG_KEY = "cache.ttlMs";
|
|
@@ -47,7 +46,6 @@ export {
|
|
|
47
46
|
CORE_QUEUE_TOKEN,
|
|
48
47
|
CORE_TENANT_RESOLVER_TOKEN,
|
|
49
48
|
CORE_THROTTLE_QUOTA_POLICY_TOKEN,
|
|
50
|
-
CORE_TOKEN_SERVICE_TOKEN,
|
|
51
49
|
CSRF_TARGET_ORIGIN_CONFIG_KEY,
|
|
52
50
|
DATABASE_URL_CONFIG_KEY,
|
|
53
51
|
DEFAULT_API_TOKEN,
|