@getstrata/bootstrap 0.2.10 → 0.2.12
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/dist/bootstrap/cache/modelCacheTags.d.ts +3 -0
- package/dist/bootstrap/discoverModules.d.ts +3 -2
- package/dist/bootstrap/modules.d.ts +1 -1
- package/dist/bootstrap/preloadModules.d.ts +1 -0
- package/dist/bootstrap/public-api.d.ts +2 -1
- package/dist/bootstrap/routeRegistry.d.ts +1 -5
- package/dist/bootstrap/server.d.ts +1 -1
- package/dist/core/auth/guard.d.ts +2 -2
- package/dist/core/auth/sessionGuard.d.ts +2 -2
- package/dist/core/cache/modelCacheTags.d.ts +1 -3
- package/dist/core/contracts/serviceContainer.d.ts +5 -0
- package/dist/core/openapi/registeredRoute.d.ts +6 -0
- package/dist/core/view/webLayoutData.d.ts +2 -2
- package/dist/entries/cache/modelCacheTags.js +22 -0
- package/dist/entries/context.js +133 -78
- package/dist/entries/createWebRoutes.js +5 -23
- package/dist/entries/http/securedRouteModelBinding.js +188 -3
- package/dist/entries/membershipService.js +188 -3
- package/dist/entries/providers.js +195 -51
- package/dist/entries/queue/defaultJobs.js +188 -3
- package/dist/framework/public-api.d.ts +1 -0
- package/dist/index.js +86 -83
- package/package.json +8 -3
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
// ../../src/bootstrap/http/securedRouteModelBinding.ts
|
|
3
|
-
import { resolveApplicationAuth, resolveApplicationPolicyGate } from "@getstrata/core";
|
|
4
|
-
|
|
5
2
|
// ../../src/core/runtime/asyncContextStore.ts
|
|
6
3
|
import { AsyncLocalStorage } from "async_hooks";
|
|
7
4
|
function createAsyncContextStore(key) {
|
|
@@ -170,6 +167,194 @@ function parsePositiveIntParam(value, name = "id") {
|
|
|
170
167
|
return parsed;
|
|
171
168
|
}
|
|
172
169
|
|
|
170
|
+
// ../../src/core/logging/logger.ts
|
|
171
|
+
class Logger {
|
|
172
|
+
channel;
|
|
173
|
+
constructor(channel = "app") {
|
|
174
|
+
this.channel = channel;
|
|
175
|
+
}
|
|
176
|
+
write(level, message, context = {}) {
|
|
177
|
+
const entry = {
|
|
178
|
+
level,
|
|
179
|
+
channel: this.channel,
|
|
180
|
+
message,
|
|
181
|
+
timestamp: new Date().toISOString(),
|
|
182
|
+
...context
|
|
183
|
+
};
|
|
184
|
+
const line = JSON.stringify(entry);
|
|
185
|
+
if (level === "error") {
|
|
186
|
+
console.error(line);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
console.log(line);
|
|
190
|
+
}
|
|
191
|
+
debug(message, context) {
|
|
192
|
+
this.write("debug", message, context);
|
|
193
|
+
}
|
|
194
|
+
info(message, context) {
|
|
195
|
+
this.write("info", message, context);
|
|
196
|
+
}
|
|
197
|
+
warn(message, context) {
|
|
198
|
+
this.write("warn", message, context);
|
|
199
|
+
}
|
|
200
|
+
error(message, context) {
|
|
201
|
+
this.write("error", message, context);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
var appLogger = new Logger("app");
|
|
205
|
+
|
|
206
|
+
// ../../src/bootstrap/config.ts
|
|
207
|
+
var APP_PORT_CONFIG_KEY = "app.port";
|
|
208
|
+
var CACHE_TTL_MS_CONFIG_KEY = "cache.ttlMs";
|
|
209
|
+
var CACHE_MAX_ENTRIES_CONFIG_KEY = "cache.maxEntries";
|
|
210
|
+
var CACHE_DRIVER_CONFIG_KEY = "cache.driver";
|
|
211
|
+
var REDIS_URL_CONFIG_KEY = "cache.redisUrl";
|
|
212
|
+
var DATABASE_URL_CONFIG_KEY = "database.url";
|
|
213
|
+
var CORE_CONFIG_TOKEN = "core.config";
|
|
214
|
+
var CORE_CACHE_TOKEN = "core.cache";
|
|
215
|
+
var CORE_QUEUE_TOKEN = "core.queue";
|
|
216
|
+
var CORE_POLICY_GATE_TOKEN = "core.policyGate";
|
|
217
|
+
var CORE_AUTH_TOKEN = "core.auth";
|
|
218
|
+
var CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
|
|
219
|
+
var AUTH_DEV_HEADERS_CONFIG_KEY = "auth.allowDevHeaders";
|
|
220
|
+
var DEFAULT_APP_PORT = 3000;
|
|
221
|
+
var DEFAULT_CACHE_TTL_MS = 3600000;
|
|
222
|
+
var DEFAULT_CACHE_MAX_ENTRIES = 100;
|
|
223
|
+
var DEFAULT_CACHE_DRIVER = "array";
|
|
224
|
+
var DEFAULT_API_TOKEN = "";
|
|
225
|
+
var DEFAULT_QUEUE_DRIVER = "sync";
|
|
226
|
+
|
|
227
|
+
// ../../src/bootstrap/contracts.ts
|
|
228
|
+
class ServiceContainer {
|
|
229
|
+
services = new Map;
|
|
230
|
+
singletonFactories = new Map;
|
|
231
|
+
bindings = new Map;
|
|
232
|
+
set(key, value) {
|
|
233
|
+
this.singletonFactories.delete(key);
|
|
234
|
+
this.bindings.delete(key);
|
|
235
|
+
this.services.set(key, value);
|
|
236
|
+
return value;
|
|
237
|
+
}
|
|
238
|
+
singleton(key, factory) {
|
|
239
|
+
this.bindings.delete(key);
|
|
240
|
+
this.services.delete(key);
|
|
241
|
+
this.singletonFactories.set(key, factory);
|
|
242
|
+
}
|
|
243
|
+
bind(key, factory) {
|
|
244
|
+
this.singletonFactories.delete(key);
|
|
245
|
+
this.services.delete(key);
|
|
246
|
+
this.bindings.set(key, factory);
|
|
247
|
+
}
|
|
248
|
+
get(key) {
|
|
249
|
+
if (this.services.has(key)) {
|
|
250
|
+
return this.services.get(key);
|
|
251
|
+
}
|
|
252
|
+
const singletonFactory = this.singletonFactories.get(key);
|
|
253
|
+
if (singletonFactory) {
|
|
254
|
+
const value = singletonFactory(this);
|
|
255
|
+
this.services.set(key, value);
|
|
256
|
+
return value;
|
|
257
|
+
}
|
|
258
|
+
const binding = this.bindings.get(key);
|
|
259
|
+
if (binding) {
|
|
260
|
+
return binding(this);
|
|
261
|
+
}
|
|
262
|
+
throw new Error(`Service "${key}" is not registered.`);
|
|
263
|
+
}
|
|
264
|
+
resolve(key) {
|
|
265
|
+
return this.get(key);
|
|
266
|
+
}
|
|
267
|
+
has(key) {
|
|
268
|
+
return this.services.has(key) || this.singletonFactories.has(key) || this.bindings.has(key);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
class ConfigStore {
|
|
273
|
+
values = new Map;
|
|
274
|
+
set(key, value) {
|
|
275
|
+
this.values.set(key, value);
|
|
276
|
+
return value;
|
|
277
|
+
}
|
|
278
|
+
get(key) {
|
|
279
|
+
return this.values.get(key);
|
|
280
|
+
}
|
|
281
|
+
require(key) {
|
|
282
|
+
if (!this.values.has(key)) {
|
|
283
|
+
throw new Error(`Config key "${key}" is not defined.`);
|
|
284
|
+
}
|
|
285
|
+
return this.values.get(key);
|
|
286
|
+
}
|
|
287
|
+
has(key) {
|
|
288
|
+
return this.values.has(key);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
var requiredDependencyKeys = [
|
|
292
|
+
"container",
|
|
293
|
+
"cache",
|
|
294
|
+
"storage"
|
|
295
|
+
];
|
|
296
|
+
function getRequiredDependency(dependencies, key) {
|
|
297
|
+
const dependency = dependencies[key];
|
|
298
|
+
if (dependency === undefined) {
|
|
299
|
+
throw new Error(`Required dependency "${key}" is not registered.`);
|
|
300
|
+
}
|
|
301
|
+
return dependency;
|
|
302
|
+
}
|
|
303
|
+
function assertAppDependenciesComplete(dependencies) {
|
|
304
|
+
for (const key of requiredDependencyKeys) {
|
|
305
|
+
getRequiredDependency(dependencies, key);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function resolveService(dependencies, token) {
|
|
309
|
+
return dependencies.container.resolve(token);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// ../../src/bootstrap/applicationRegistry.ts
|
|
313
|
+
var APPLICATION_CONTEXT_KEY = Symbol.for("@getstrata/applicationContext");
|
|
314
|
+
var activeContext;
|
|
315
|
+
function readStoredApplicationContext() {
|
|
316
|
+
if (activeContext) {
|
|
317
|
+
return activeContext;
|
|
318
|
+
}
|
|
319
|
+
const globalContext = globalThis[APPLICATION_CONTEXT_KEY];
|
|
320
|
+
if (globalContext) {
|
|
321
|
+
activeContext = globalContext;
|
|
322
|
+
}
|
|
323
|
+
return activeContext;
|
|
324
|
+
}
|
|
325
|
+
function setActiveApplicationContext(context) {
|
|
326
|
+
activeContext = context;
|
|
327
|
+
globalThis[APPLICATION_CONTEXT_KEY] = context;
|
|
328
|
+
}
|
|
329
|
+
function requireActiveApplicationContext() {
|
|
330
|
+
const context = readStoredApplicationContext();
|
|
331
|
+
if (!context) {
|
|
332
|
+
throw new Error("The application context has not been bootstrapped.");
|
|
333
|
+
}
|
|
334
|
+
return context;
|
|
335
|
+
}
|
|
336
|
+
function resolveApplicationCache() {
|
|
337
|
+
return getRequiredDependency(requireActiveApplicationContext().dependencies, "cache");
|
|
338
|
+
}
|
|
339
|
+
function resolveApplicationQueue() {
|
|
340
|
+
return requireActiveApplicationContext().container.resolve(CORE_QUEUE_TOKEN);
|
|
341
|
+
}
|
|
342
|
+
function resolveApplicationAuth() {
|
|
343
|
+
return requireActiveApplicationContext().container.resolve(CORE_AUTH_TOKEN);
|
|
344
|
+
}
|
|
345
|
+
function resolveApplicationPolicyGate() {
|
|
346
|
+
return requireActiveApplicationContext().container.resolve(CORE_POLICY_GATE_TOKEN);
|
|
347
|
+
}
|
|
348
|
+
function resolveApplicationConfig() {
|
|
349
|
+
return requireActiveApplicationContext().config;
|
|
350
|
+
}
|
|
351
|
+
function resolveApplicationLogger() {
|
|
352
|
+
return appLogger;
|
|
353
|
+
}
|
|
354
|
+
function resolveApplicationDependencies() {
|
|
355
|
+
return requireActiveApplicationContext().dependencies;
|
|
356
|
+
}
|
|
357
|
+
|
|
173
358
|
// ../../src/bootstrap/http/securedRouteModelBinding.ts
|
|
174
359
|
function isMutatingPolicyAction(action) {
|
|
175
360
|
return action === "update" || action === "delete";
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
// ../../src/bootstrap/membershipService.ts
|
|
3
|
-
import { resolveApplicationDependencies } from "@getstrata/core";
|
|
4
|
-
|
|
5
2
|
// ../../src/core/errors/http.ts
|
|
6
3
|
class HttpError extends Error {
|
|
7
4
|
status;
|
|
@@ -304,6 +301,194 @@ class MembershipService {
|
|
|
304
301
|
}
|
|
305
302
|
var membershipService_default = MembershipService;
|
|
306
303
|
|
|
304
|
+
// ../../src/core/logging/logger.ts
|
|
305
|
+
class Logger {
|
|
306
|
+
channel;
|
|
307
|
+
constructor(channel = "app") {
|
|
308
|
+
this.channel = channel;
|
|
309
|
+
}
|
|
310
|
+
write(level, message, context = {}) {
|
|
311
|
+
const entry = {
|
|
312
|
+
level,
|
|
313
|
+
channel: this.channel,
|
|
314
|
+
message,
|
|
315
|
+
timestamp: new Date().toISOString(),
|
|
316
|
+
...context
|
|
317
|
+
};
|
|
318
|
+
const line = JSON.stringify(entry);
|
|
319
|
+
if (level === "error") {
|
|
320
|
+
console.error(line);
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
console.log(line);
|
|
324
|
+
}
|
|
325
|
+
debug(message, context) {
|
|
326
|
+
this.write("debug", message, context);
|
|
327
|
+
}
|
|
328
|
+
info(message, context) {
|
|
329
|
+
this.write("info", message, context);
|
|
330
|
+
}
|
|
331
|
+
warn(message, context) {
|
|
332
|
+
this.write("warn", message, context);
|
|
333
|
+
}
|
|
334
|
+
error(message, context) {
|
|
335
|
+
this.write("error", message, context);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
var appLogger = new Logger("app");
|
|
339
|
+
|
|
340
|
+
// ../../src/bootstrap/config.ts
|
|
341
|
+
var APP_PORT_CONFIG_KEY = "app.port";
|
|
342
|
+
var CACHE_TTL_MS_CONFIG_KEY = "cache.ttlMs";
|
|
343
|
+
var CACHE_MAX_ENTRIES_CONFIG_KEY = "cache.maxEntries";
|
|
344
|
+
var CACHE_DRIVER_CONFIG_KEY = "cache.driver";
|
|
345
|
+
var REDIS_URL_CONFIG_KEY = "cache.redisUrl";
|
|
346
|
+
var DATABASE_URL_CONFIG_KEY = "database.url";
|
|
347
|
+
var CORE_CONFIG_TOKEN = "core.config";
|
|
348
|
+
var CORE_CACHE_TOKEN = "core.cache";
|
|
349
|
+
var CORE_QUEUE_TOKEN = "core.queue";
|
|
350
|
+
var CORE_POLICY_GATE_TOKEN = "core.policyGate";
|
|
351
|
+
var CORE_AUTH_TOKEN = "core.auth";
|
|
352
|
+
var CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
|
|
353
|
+
var AUTH_DEV_HEADERS_CONFIG_KEY = "auth.allowDevHeaders";
|
|
354
|
+
var DEFAULT_APP_PORT = 3000;
|
|
355
|
+
var DEFAULT_CACHE_TTL_MS = 3600000;
|
|
356
|
+
var DEFAULT_CACHE_MAX_ENTRIES = 100;
|
|
357
|
+
var DEFAULT_CACHE_DRIVER = "array";
|
|
358
|
+
var DEFAULT_API_TOKEN = "";
|
|
359
|
+
var DEFAULT_QUEUE_DRIVER = "sync";
|
|
360
|
+
|
|
361
|
+
// ../../src/bootstrap/contracts.ts
|
|
362
|
+
class ServiceContainer {
|
|
363
|
+
services = new Map;
|
|
364
|
+
singletonFactories = new Map;
|
|
365
|
+
bindings = new Map;
|
|
366
|
+
set(key, value) {
|
|
367
|
+
this.singletonFactories.delete(key);
|
|
368
|
+
this.bindings.delete(key);
|
|
369
|
+
this.services.set(key, value);
|
|
370
|
+
return value;
|
|
371
|
+
}
|
|
372
|
+
singleton(key, factory) {
|
|
373
|
+
this.bindings.delete(key);
|
|
374
|
+
this.services.delete(key);
|
|
375
|
+
this.singletonFactories.set(key, factory);
|
|
376
|
+
}
|
|
377
|
+
bind(key, factory) {
|
|
378
|
+
this.singletonFactories.delete(key);
|
|
379
|
+
this.services.delete(key);
|
|
380
|
+
this.bindings.set(key, factory);
|
|
381
|
+
}
|
|
382
|
+
get(key) {
|
|
383
|
+
if (this.services.has(key)) {
|
|
384
|
+
return this.services.get(key);
|
|
385
|
+
}
|
|
386
|
+
const singletonFactory = this.singletonFactories.get(key);
|
|
387
|
+
if (singletonFactory) {
|
|
388
|
+
const value = singletonFactory(this);
|
|
389
|
+
this.services.set(key, value);
|
|
390
|
+
return value;
|
|
391
|
+
}
|
|
392
|
+
const binding = this.bindings.get(key);
|
|
393
|
+
if (binding) {
|
|
394
|
+
return binding(this);
|
|
395
|
+
}
|
|
396
|
+
throw new Error(`Service "${key}" is not registered.`);
|
|
397
|
+
}
|
|
398
|
+
resolve(key) {
|
|
399
|
+
return this.get(key);
|
|
400
|
+
}
|
|
401
|
+
has(key) {
|
|
402
|
+
return this.services.has(key) || this.singletonFactories.has(key) || this.bindings.has(key);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
class ConfigStore {
|
|
407
|
+
values = new Map;
|
|
408
|
+
set(key, value) {
|
|
409
|
+
this.values.set(key, value);
|
|
410
|
+
return value;
|
|
411
|
+
}
|
|
412
|
+
get(key) {
|
|
413
|
+
return this.values.get(key);
|
|
414
|
+
}
|
|
415
|
+
require(key) {
|
|
416
|
+
if (!this.values.has(key)) {
|
|
417
|
+
throw new Error(`Config key "${key}" is not defined.`);
|
|
418
|
+
}
|
|
419
|
+
return this.values.get(key);
|
|
420
|
+
}
|
|
421
|
+
has(key) {
|
|
422
|
+
return this.values.has(key);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
var requiredDependencyKeys = [
|
|
426
|
+
"container",
|
|
427
|
+
"cache",
|
|
428
|
+
"storage"
|
|
429
|
+
];
|
|
430
|
+
function getRequiredDependency(dependencies, key) {
|
|
431
|
+
const dependency = dependencies[key];
|
|
432
|
+
if (dependency === undefined) {
|
|
433
|
+
throw new Error(`Required dependency "${key}" is not registered.`);
|
|
434
|
+
}
|
|
435
|
+
return dependency;
|
|
436
|
+
}
|
|
437
|
+
function assertAppDependenciesComplete(dependencies) {
|
|
438
|
+
for (const key of requiredDependencyKeys) {
|
|
439
|
+
getRequiredDependency(dependencies, key);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
function resolveService(dependencies, token) {
|
|
443
|
+
return dependencies.container.resolve(token);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
// ../../src/bootstrap/applicationRegistry.ts
|
|
447
|
+
var APPLICATION_CONTEXT_KEY = Symbol.for("@getstrata/applicationContext");
|
|
448
|
+
var activeContext;
|
|
449
|
+
function readStoredApplicationContext() {
|
|
450
|
+
if (activeContext) {
|
|
451
|
+
return activeContext;
|
|
452
|
+
}
|
|
453
|
+
const globalContext = globalThis[APPLICATION_CONTEXT_KEY];
|
|
454
|
+
if (globalContext) {
|
|
455
|
+
activeContext = globalContext;
|
|
456
|
+
}
|
|
457
|
+
return activeContext;
|
|
458
|
+
}
|
|
459
|
+
function setActiveApplicationContext(context) {
|
|
460
|
+
activeContext = context;
|
|
461
|
+
globalThis[APPLICATION_CONTEXT_KEY] = context;
|
|
462
|
+
}
|
|
463
|
+
function requireActiveApplicationContext() {
|
|
464
|
+
const context = readStoredApplicationContext();
|
|
465
|
+
if (!context) {
|
|
466
|
+
throw new Error("The application context has not been bootstrapped.");
|
|
467
|
+
}
|
|
468
|
+
return context;
|
|
469
|
+
}
|
|
470
|
+
function resolveApplicationCache() {
|
|
471
|
+
return getRequiredDependency(requireActiveApplicationContext().dependencies, "cache");
|
|
472
|
+
}
|
|
473
|
+
function resolveApplicationQueue() {
|
|
474
|
+
return requireActiveApplicationContext().container.resolve(CORE_QUEUE_TOKEN);
|
|
475
|
+
}
|
|
476
|
+
function resolveApplicationAuth() {
|
|
477
|
+
return requireActiveApplicationContext().container.resolve(CORE_AUTH_TOKEN);
|
|
478
|
+
}
|
|
479
|
+
function resolveApplicationPolicyGate() {
|
|
480
|
+
return requireActiveApplicationContext().container.resolve(CORE_POLICY_GATE_TOKEN);
|
|
481
|
+
}
|
|
482
|
+
function resolveApplicationConfig() {
|
|
483
|
+
return requireActiveApplicationContext().config;
|
|
484
|
+
}
|
|
485
|
+
function resolveApplicationLogger() {
|
|
486
|
+
return appLogger;
|
|
487
|
+
}
|
|
488
|
+
function resolveApplicationDependencies() {
|
|
489
|
+
return requireActiveApplicationContext().dependencies;
|
|
490
|
+
}
|
|
491
|
+
|
|
307
492
|
// ../../src/bootstrap/membershipService.ts
|
|
308
493
|
function resolveMembershipService() {
|
|
309
494
|
const dependencies = resolveApplicationDependencies();
|