@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
|
@@ -1311,44 +1311,6 @@ function discoverListeners() {
|
|
|
1311
1311
|
return appListeners;
|
|
1312
1312
|
}
|
|
1313
1313
|
|
|
1314
|
-
// ../../src/bootstrap/listeners/invalidateCacheOnModelWrite.ts
|
|
1315
|
-
import { resolveApplicationCache as resolveApplicationCache2, resolveApplicationQueue } from "@getstrata/core";
|
|
1316
|
-
|
|
1317
|
-
// ../../src/bootstrap/discoverModules.ts
|
|
1318
|
-
import { readdirSync as readdirSync2 } from "fs";
|
|
1319
|
-
import { join as join2 } from "path";
|
|
1320
|
-
import { pathToFileURL as pathToFileURL2 } from "url";
|
|
1321
|
-
async function loadDiscoveredModules() {
|
|
1322
|
-
const modulesDirectory = join2(import.meta.dir, "../modules");
|
|
1323
|
-
let moduleNames;
|
|
1324
|
-
try {
|
|
1325
|
-
moduleNames = readdirSync2(modulesDirectory, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
|
|
1326
|
-
} catch (error) {
|
|
1327
|
-
if (error.code === "ENOENT") {
|
|
1328
|
-
return [];
|
|
1329
|
-
}
|
|
1330
|
-
throw error;
|
|
1331
|
-
}
|
|
1332
|
-
const modules = await Promise.all(moduleNames.map(async (moduleName) => {
|
|
1333
|
-
const moduleUrl = pathToFileURL2(join2(modulesDirectory, moduleName, "index.ts")).href;
|
|
1334
|
-
const loaded = await import(moduleUrl);
|
|
1335
|
-
return loaded.default;
|
|
1336
|
-
}));
|
|
1337
|
-
return modules.filter((module) => module?.name !== undefined).sort((left, right) => (left.order ?? 100) - (right.order ?? 100));
|
|
1338
|
-
}
|
|
1339
|
-
var appModules = await loadDiscoveredModules();
|
|
1340
|
-
// ../../src/core/cache/modelCacheTags.ts
|
|
1341
|
-
function cacheTagsForModelWrite(tableName, action) {
|
|
1342
|
-
const module = appModules.find((entry) => entry.tableName === tableName);
|
|
1343
|
-
const baseTags = module?.cacheTags ?? [`${tableName}s`];
|
|
1344
|
-
const isDelete = action === "deleted" || action === "force-deleted";
|
|
1345
|
-
const extraTags = isDelete ? module?.cacheDeleteExtraTags ?? [] : [];
|
|
1346
|
-
return [...new Set([...baseTags, ...extraTags])];
|
|
1347
|
-
}
|
|
1348
|
-
function discoverModelTableNames() {
|
|
1349
|
-
return appModules.map((module) => module.tableName).filter((tableName) => tableName !== undefined);
|
|
1350
|
-
}
|
|
1351
|
-
|
|
1352
1314
|
// ../../src/core/queue/index.ts
|
|
1353
1315
|
class Job {
|
|
1354
1316
|
maxAttempts;
|
|
@@ -1659,10 +1621,10 @@ function buildHavingClause(tableName, having, params) {
|
|
|
1659
1621
|
return body.length > 0 ? ` HAVING ${body}` : "";
|
|
1660
1622
|
}
|
|
1661
1623
|
function buildJoinClause(joins = []) {
|
|
1662
|
-
return joins.map((
|
|
1663
|
-
const joinType =
|
|
1664
|
-
const onClause =
|
|
1665
|
-
return ` ${joinType} ${quoteIdentifier(
|
|
1624
|
+
return joins.map((join2) => {
|
|
1625
|
+
const joinType = join2.type === "left" ? "LEFT JOIN" : "INNER JOIN";
|
|
1626
|
+
const onClause = join2.on.map(({ left, right }) => `${qualifyColumn(left.table, left.column)} = ${qualifyColumn(right.table, right.column)}`).join(" AND ");
|
|
1627
|
+
return ` ${joinType} ${quoteIdentifier(join2.table)} ON ${onClause}`;
|
|
1666
1628
|
}).join("");
|
|
1667
1629
|
}
|
|
1668
1630
|
function buildLimitClause(limit) {
|
|
@@ -2098,7 +2060,7 @@ class RepositoryQuery {
|
|
|
2098
2060
|
const rightRef = parseQualifiedColumn(right);
|
|
2099
2061
|
const table = type === "inner" ? rightRef.table : rightRef.table;
|
|
2100
2062
|
const joins = this.queryOptions.joins ?? [];
|
|
2101
|
-
const existing = joins.find((
|
|
2063
|
+
const existing = joins.find((join2) => join2.table === table && join2.type === type);
|
|
2102
2064
|
if (existing) {
|
|
2103
2065
|
existing.on.push({ left: leftRef, right: rightRef });
|
|
2104
2066
|
return this;
|
|
@@ -3261,9 +3223,6 @@ function createProductionQueue(driver, options = {}) {
|
|
|
3261
3223
|
return new ResilientQueue(failedJobs, driver === "async");
|
|
3262
3224
|
}
|
|
3263
3225
|
|
|
3264
|
-
// ../../src/bootstrap/queue/defaultJobs.ts
|
|
3265
|
-
import { resolveApplicationCache } from "@getstrata/core";
|
|
3266
|
-
|
|
3267
3226
|
// ../../src/core/jobs/dispatchWebhookJob.ts
|
|
3268
3227
|
import { createHmac as createHmac2 } from "crypto";
|
|
3269
3228
|
|
|
@@ -3451,6 +3410,173 @@ class DispatchWebhookJob extends Job {
|
|
|
3451
3410
|
}
|
|
3452
3411
|
var dispatchWebhookJob_default = DispatchWebhookJob;
|
|
3453
3412
|
|
|
3413
|
+
// ../../src/core/logging/logger.ts
|
|
3414
|
+
class Logger {
|
|
3415
|
+
channel;
|
|
3416
|
+
constructor(channel = "app") {
|
|
3417
|
+
this.channel = channel;
|
|
3418
|
+
}
|
|
3419
|
+
write(level, message, context = {}) {
|
|
3420
|
+
const entry = {
|
|
3421
|
+
level,
|
|
3422
|
+
channel: this.channel,
|
|
3423
|
+
message,
|
|
3424
|
+
timestamp: new Date().toISOString(),
|
|
3425
|
+
...context
|
|
3426
|
+
};
|
|
3427
|
+
const line = JSON.stringify(entry);
|
|
3428
|
+
if (level === "error") {
|
|
3429
|
+
console.error(line);
|
|
3430
|
+
return;
|
|
3431
|
+
}
|
|
3432
|
+
console.log(line);
|
|
3433
|
+
}
|
|
3434
|
+
debug(message, context) {
|
|
3435
|
+
this.write("debug", message, context);
|
|
3436
|
+
}
|
|
3437
|
+
info(message, context) {
|
|
3438
|
+
this.write("info", message, context);
|
|
3439
|
+
}
|
|
3440
|
+
warn(message, context) {
|
|
3441
|
+
this.write("warn", message, context);
|
|
3442
|
+
}
|
|
3443
|
+
error(message, context) {
|
|
3444
|
+
this.write("error", message, context);
|
|
3445
|
+
}
|
|
3446
|
+
}
|
|
3447
|
+
var appLogger = new Logger("app");
|
|
3448
|
+
|
|
3449
|
+
// ../../src/bootstrap/contracts.ts
|
|
3450
|
+
class ServiceContainer {
|
|
3451
|
+
services = new Map;
|
|
3452
|
+
singletonFactories = new Map;
|
|
3453
|
+
bindings = new Map;
|
|
3454
|
+
set(key, value) {
|
|
3455
|
+
this.singletonFactories.delete(key);
|
|
3456
|
+
this.bindings.delete(key);
|
|
3457
|
+
this.services.set(key, value);
|
|
3458
|
+
return value;
|
|
3459
|
+
}
|
|
3460
|
+
singleton(key, factory) {
|
|
3461
|
+
this.bindings.delete(key);
|
|
3462
|
+
this.services.delete(key);
|
|
3463
|
+
this.singletonFactories.set(key, factory);
|
|
3464
|
+
}
|
|
3465
|
+
bind(key, factory) {
|
|
3466
|
+
this.singletonFactories.delete(key);
|
|
3467
|
+
this.services.delete(key);
|
|
3468
|
+
this.bindings.set(key, factory);
|
|
3469
|
+
}
|
|
3470
|
+
get(key) {
|
|
3471
|
+
if (this.services.has(key)) {
|
|
3472
|
+
return this.services.get(key);
|
|
3473
|
+
}
|
|
3474
|
+
const singletonFactory = this.singletonFactories.get(key);
|
|
3475
|
+
if (singletonFactory) {
|
|
3476
|
+
const value = singletonFactory(this);
|
|
3477
|
+
this.services.set(key, value);
|
|
3478
|
+
return value;
|
|
3479
|
+
}
|
|
3480
|
+
const binding = this.bindings.get(key);
|
|
3481
|
+
if (binding) {
|
|
3482
|
+
return binding(this);
|
|
3483
|
+
}
|
|
3484
|
+
throw new Error(`Service "${key}" is not registered.`);
|
|
3485
|
+
}
|
|
3486
|
+
resolve(key) {
|
|
3487
|
+
return this.get(key);
|
|
3488
|
+
}
|
|
3489
|
+
has(key) {
|
|
3490
|
+
return this.services.has(key) || this.singletonFactories.has(key) || this.bindings.has(key);
|
|
3491
|
+
}
|
|
3492
|
+
}
|
|
3493
|
+
|
|
3494
|
+
class ConfigStore {
|
|
3495
|
+
values = new Map;
|
|
3496
|
+
set(key, value) {
|
|
3497
|
+
this.values.set(key, value);
|
|
3498
|
+
return value;
|
|
3499
|
+
}
|
|
3500
|
+
get(key) {
|
|
3501
|
+
return this.values.get(key);
|
|
3502
|
+
}
|
|
3503
|
+
require(key) {
|
|
3504
|
+
if (!this.values.has(key)) {
|
|
3505
|
+
throw new Error(`Config key "${key}" is not defined.`);
|
|
3506
|
+
}
|
|
3507
|
+
return this.values.get(key);
|
|
3508
|
+
}
|
|
3509
|
+
has(key) {
|
|
3510
|
+
return this.values.has(key);
|
|
3511
|
+
}
|
|
3512
|
+
}
|
|
3513
|
+
var requiredDependencyKeys = [
|
|
3514
|
+
"container",
|
|
3515
|
+
"cache",
|
|
3516
|
+
"storage"
|
|
3517
|
+
];
|
|
3518
|
+
function getRequiredDependency(dependencies, key) {
|
|
3519
|
+
const dependency = dependencies[key];
|
|
3520
|
+
if (dependency === undefined) {
|
|
3521
|
+
throw new Error(`Required dependency "${key}" is not registered.`);
|
|
3522
|
+
}
|
|
3523
|
+
return dependency;
|
|
3524
|
+
}
|
|
3525
|
+
function assertAppDependenciesComplete(dependencies) {
|
|
3526
|
+
for (const key of requiredDependencyKeys) {
|
|
3527
|
+
getRequiredDependency(dependencies, key);
|
|
3528
|
+
}
|
|
3529
|
+
}
|
|
3530
|
+
function resolveService(dependencies, token) {
|
|
3531
|
+
return dependencies.container.resolve(token);
|
|
3532
|
+
}
|
|
3533
|
+
|
|
3534
|
+
// ../../src/bootstrap/applicationRegistry.ts
|
|
3535
|
+
var APPLICATION_CONTEXT_KEY = Symbol.for("@getstrata/applicationContext");
|
|
3536
|
+
var activeContext;
|
|
3537
|
+
function readStoredApplicationContext() {
|
|
3538
|
+
if (activeContext) {
|
|
3539
|
+
return activeContext;
|
|
3540
|
+
}
|
|
3541
|
+
const globalContext = globalThis[APPLICATION_CONTEXT_KEY];
|
|
3542
|
+
if (globalContext) {
|
|
3543
|
+
activeContext = globalContext;
|
|
3544
|
+
}
|
|
3545
|
+
return activeContext;
|
|
3546
|
+
}
|
|
3547
|
+
function setActiveApplicationContext(context) {
|
|
3548
|
+
activeContext = context;
|
|
3549
|
+
globalThis[APPLICATION_CONTEXT_KEY] = context;
|
|
3550
|
+
}
|
|
3551
|
+
function requireActiveApplicationContext() {
|
|
3552
|
+
const context = readStoredApplicationContext();
|
|
3553
|
+
if (!context) {
|
|
3554
|
+
throw new Error("The application context has not been bootstrapped.");
|
|
3555
|
+
}
|
|
3556
|
+
return context;
|
|
3557
|
+
}
|
|
3558
|
+
function resolveApplicationCache() {
|
|
3559
|
+
return getRequiredDependency(requireActiveApplicationContext().dependencies, "cache");
|
|
3560
|
+
}
|
|
3561
|
+
function resolveApplicationQueue() {
|
|
3562
|
+
return requireActiveApplicationContext().container.resolve(CORE_QUEUE_TOKEN);
|
|
3563
|
+
}
|
|
3564
|
+
function resolveApplicationAuth() {
|
|
3565
|
+
return requireActiveApplicationContext().container.resolve(CORE_AUTH_TOKEN);
|
|
3566
|
+
}
|
|
3567
|
+
function resolveApplicationPolicyGate() {
|
|
3568
|
+
return requireActiveApplicationContext().container.resolve(CORE_POLICY_GATE_TOKEN);
|
|
3569
|
+
}
|
|
3570
|
+
function resolveApplicationConfig() {
|
|
3571
|
+
return requireActiveApplicationContext().config;
|
|
3572
|
+
}
|
|
3573
|
+
function resolveApplicationLogger() {
|
|
3574
|
+
return appLogger;
|
|
3575
|
+
}
|
|
3576
|
+
function resolveApplicationDependencies() {
|
|
3577
|
+
return requireActiveApplicationContext().dependencies;
|
|
3578
|
+
}
|
|
3579
|
+
|
|
3454
3580
|
// ../../src/bootstrap/queue/defaultJobs.ts
|
|
3455
3581
|
function registerDefaultJobs() {
|
|
3456
3582
|
jobRegistry.register("cache.invalidate-tags", () => {
|
|
@@ -3469,6 +3595,24 @@ function createAppQueue(driver, redisUrl, failedJobs = createFailedJobService(),
|
|
|
3469
3595
|
});
|
|
3470
3596
|
}
|
|
3471
3597
|
|
|
3598
|
+
// ../../src/bootstrap/discoverModules.ts
|
|
3599
|
+
var appModules = [];
|
|
3600
|
+
function discoverModules() {
|
|
3601
|
+
return appModules;
|
|
3602
|
+
}
|
|
3603
|
+
|
|
3604
|
+
// ../../src/bootstrap/cache/modelCacheTags.ts
|
|
3605
|
+
function cacheTagsForModelWrite(tableName, action) {
|
|
3606
|
+
const module = discoverModules().find((entry) => entry.tableName === tableName);
|
|
3607
|
+
const baseTags = module?.cacheTags ?? [`${tableName}s`];
|
|
3608
|
+
const isDelete = action === "deleted" || action === "force-deleted";
|
|
3609
|
+
const extraTags = isDelete ? module?.cacheDeleteExtraTags ?? [] : [];
|
|
3610
|
+
return [...new Set([...baseTags, ...extraTags])];
|
|
3611
|
+
}
|
|
3612
|
+
function discoverModelTableNames() {
|
|
3613
|
+
return discoverModules().map((module) => module.tableName).filter((tableName) => tableName !== undefined);
|
|
3614
|
+
}
|
|
3615
|
+
|
|
3472
3616
|
// ../../src/bootstrap/listeners/invalidateCacheOnModelWrite.ts
|
|
3473
3617
|
var MODEL_WRITE_ACTIONS = ["created", "updated", "deleted", "restored", "force-deleted"];
|
|
3474
3618
|
function registerInvalidateCacheOnModelWriteListeners(bus = eventBus) {
|
|
@@ -3482,7 +3626,7 @@ function registerInvalidateCacheOnModelWriteListeners(bus = eventBus) {
|
|
|
3482
3626
|
let cache;
|
|
3483
3627
|
let queue;
|
|
3484
3628
|
try {
|
|
3485
|
-
cache =
|
|
3629
|
+
cache = resolveApplicationCache();
|
|
3486
3630
|
queue = resolveApplicationQueue();
|
|
3487
3631
|
} catch {
|
|
3488
3632
|
return;
|
|
@@ -3580,7 +3724,7 @@ var queue_default = queueProvider;
|
|
|
3580
3724
|
|
|
3581
3725
|
// ../../src/core/storage/storage.ts
|
|
3582
3726
|
import { mkdir, readFile, unlink, writeFile } from "fs/promises";
|
|
3583
|
-
import { dirname, join as
|
|
3727
|
+
import { dirname, join as join2 } from "path";
|
|
3584
3728
|
var {S3Client } = globalThis.Bun;
|
|
3585
3729
|
|
|
3586
3730
|
class LocalStorageDriver {
|
|
@@ -3592,7 +3736,7 @@ class LocalStorageDriver {
|
|
|
3592
3736
|
return this.rootDirectory ?? process.env.STORAGE_PATH ?? "storage";
|
|
3593
3737
|
}
|
|
3594
3738
|
resolvePath(path) {
|
|
3595
|
-
return
|
|
3739
|
+
return join2(this.resolveRootDirectory(), path.replace(/^\/+/, ""));
|
|
3596
3740
|
}
|
|
3597
3741
|
async put(path, contents) {
|
|
3598
3742
|
const absolutePath = this.resolvePath(path);
|
|
@@ -3725,9 +3869,9 @@ function currentRequestMeta() {
|
|
|
3725
3869
|
}
|
|
3726
3870
|
|
|
3727
3871
|
// ../../src/core/view/etaViewEngine.ts
|
|
3728
|
-
import { join as
|
|
3872
|
+
import { join as join3 } from "path";
|
|
3729
3873
|
import { Eta } from "eta";
|
|
3730
|
-
var DEFAULT_VIEWS_DIRECTORY =
|
|
3874
|
+
var DEFAULT_VIEWS_DIRECTORY = join3(process.cwd(), "resources/views");
|
|
3731
3875
|
var DEFAULT_LAYOUT = "layouts/app.eta";
|
|
3732
3876
|
|
|
3733
3877
|
class EtaViewEngine {
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
// ../../src/bootstrap/queue/defaultJobs.ts
|
|
3
|
-
import { resolveApplicationCache } from "@getstrata/core";
|
|
4
|
-
|
|
5
2
|
// ../../src/core/jobs/dispatchWebhookJob.ts
|
|
6
3
|
import { createHmac } from "crypto";
|
|
7
4
|
|
|
@@ -378,6 +375,194 @@ class JobRegistry {
|
|
|
378
375
|
}
|
|
379
376
|
var jobRegistry = new JobRegistry;
|
|
380
377
|
|
|
378
|
+
// ../../src/core/logging/logger.ts
|
|
379
|
+
class Logger {
|
|
380
|
+
channel;
|
|
381
|
+
constructor(channel = "app") {
|
|
382
|
+
this.channel = channel;
|
|
383
|
+
}
|
|
384
|
+
write(level, message, context = {}) {
|
|
385
|
+
const entry = {
|
|
386
|
+
level,
|
|
387
|
+
channel: this.channel,
|
|
388
|
+
message,
|
|
389
|
+
timestamp: new Date().toISOString(),
|
|
390
|
+
...context
|
|
391
|
+
};
|
|
392
|
+
const line = JSON.stringify(entry);
|
|
393
|
+
if (level === "error") {
|
|
394
|
+
console.error(line);
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
console.log(line);
|
|
398
|
+
}
|
|
399
|
+
debug(message, context) {
|
|
400
|
+
this.write("debug", message, context);
|
|
401
|
+
}
|
|
402
|
+
info(message, context) {
|
|
403
|
+
this.write("info", message, context);
|
|
404
|
+
}
|
|
405
|
+
warn(message, context) {
|
|
406
|
+
this.write("warn", message, context);
|
|
407
|
+
}
|
|
408
|
+
error(message, context) {
|
|
409
|
+
this.write("error", message, context);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
var appLogger = new Logger("app");
|
|
413
|
+
|
|
414
|
+
// ../../src/bootstrap/config.ts
|
|
415
|
+
var APP_PORT_CONFIG_KEY = "app.port";
|
|
416
|
+
var CACHE_TTL_MS_CONFIG_KEY = "cache.ttlMs";
|
|
417
|
+
var CACHE_MAX_ENTRIES_CONFIG_KEY = "cache.maxEntries";
|
|
418
|
+
var CACHE_DRIVER_CONFIG_KEY = "cache.driver";
|
|
419
|
+
var REDIS_URL_CONFIG_KEY = "cache.redisUrl";
|
|
420
|
+
var DATABASE_URL_CONFIG_KEY = "database.url";
|
|
421
|
+
var CORE_CONFIG_TOKEN = "core.config";
|
|
422
|
+
var CORE_CACHE_TOKEN = "core.cache";
|
|
423
|
+
var CORE_QUEUE_TOKEN = "core.queue";
|
|
424
|
+
var CORE_POLICY_GATE_TOKEN = "core.policyGate";
|
|
425
|
+
var CORE_AUTH_TOKEN = "core.auth";
|
|
426
|
+
var CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
|
|
427
|
+
var AUTH_DEV_HEADERS_CONFIG_KEY = "auth.allowDevHeaders";
|
|
428
|
+
var DEFAULT_APP_PORT = 3000;
|
|
429
|
+
var DEFAULT_CACHE_TTL_MS = 3600000;
|
|
430
|
+
var DEFAULT_CACHE_MAX_ENTRIES = 100;
|
|
431
|
+
var DEFAULT_CACHE_DRIVER = "array";
|
|
432
|
+
var DEFAULT_API_TOKEN = "";
|
|
433
|
+
var DEFAULT_QUEUE_DRIVER = "sync";
|
|
434
|
+
|
|
435
|
+
// ../../src/bootstrap/contracts.ts
|
|
436
|
+
class ServiceContainer {
|
|
437
|
+
services = new Map;
|
|
438
|
+
singletonFactories = new Map;
|
|
439
|
+
bindings = new Map;
|
|
440
|
+
set(key, value) {
|
|
441
|
+
this.singletonFactories.delete(key);
|
|
442
|
+
this.bindings.delete(key);
|
|
443
|
+
this.services.set(key, value);
|
|
444
|
+
return value;
|
|
445
|
+
}
|
|
446
|
+
singleton(key, factory) {
|
|
447
|
+
this.bindings.delete(key);
|
|
448
|
+
this.services.delete(key);
|
|
449
|
+
this.singletonFactories.set(key, factory);
|
|
450
|
+
}
|
|
451
|
+
bind(key, factory) {
|
|
452
|
+
this.singletonFactories.delete(key);
|
|
453
|
+
this.services.delete(key);
|
|
454
|
+
this.bindings.set(key, factory);
|
|
455
|
+
}
|
|
456
|
+
get(key) {
|
|
457
|
+
if (this.services.has(key)) {
|
|
458
|
+
return this.services.get(key);
|
|
459
|
+
}
|
|
460
|
+
const singletonFactory = this.singletonFactories.get(key);
|
|
461
|
+
if (singletonFactory) {
|
|
462
|
+
const value = singletonFactory(this);
|
|
463
|
+
this.services.set(key, value);
|
|
464
|
+
return value;
|
|
465
|
+
}
|
|
466
|
+
const binding = this.bindings.get(key);
|
|
467
|
+
if (binding) {
|
|
468
|
+
return binding(this);
|
|
469
|
+
}
|
|
470
|
+
throw new Error(`Service "${key}" is not registered.`);
|
|
471
|
+
}
|
|
472
|
+
resolve(key) {
|
|
473
|
+
return this.get(key);
|
|
474
|
+
}
|
|
475
|
+
has(key) {
|
|
476
|
+
return this.services.has(key) || this.singletonFactories.has(key) || this.bindings.has(key);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
class ConfigStore {
|
|
481
|
+
values = new Map;
|
|
482
|
+
set(key, value) {
|
|
483
|
+
this.values.set(key, value);
|
|
484
|
+
return value;
|
|
485
|
+
}
|
|
486
|
+
get(key) {
|
|
487
|
+
return this.values.get(key);
|
|
488
|
+
}
|
|
489
|
+
require(key) {
|
|
490
|
+
if (!this.values.has(key)) {
|
|
491
|
+
throw new Error(`Config key "${key}" is not defined.`);
|
|
492
|
+
}
|
|
493
|
+
return this.values.get(key);
|
|
494
|
+
}
|
|
495
|
+
has(key) {
|
|
496
|
+
return this.values.has(key);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
var requiredDependencyKeys = [
|
|
500
|
+
"container",
|
|
501
|
+
"cache",
|
|
502
|
+
"storage"
|
|
503
|
+
];
|
|
504
|
+
function getRequiredDependency(dependencies, key) {
|
|
505
|
+
const dependency = dependencies[key];
|
|
506
|
+
if (dependency === undefined) {
|
|
507
|
+
throw new Error(`Required dependency "${key}" is not registered.`);
|
|
508
|
+
}
|
|
509
|
+
return dependency;
|
|
510
|
+
}
|
|
511
|
+
function assertAppDependenciesComplete(dependencies) {
|
|
512
|
+
for (const key of requiredDependencyKeys) {
|
|
513
|
+
getRequiredDependency(dependencies, key);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
function resolveService(dependencies, token) {
|
|
517
|
+
return dependencies.container.resolve(token);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
// ../../src/bootstrap/applicationRegistry.ts
|
|
521
|
+
var APPLICATION_CONTEXT_KEY = Symbol.for("@getstrata/applicationContext");
|
|
522
|
+
var activeContext;
|
|
523
|
+
function readStoredApplicationContext() {
|
|
524
|
+
if (activeContext) {
|
|
525
|
+
return activeContext;
|
|
526
|
+
}
|
|
527
|
+
const globalContext = globalThis[APPLICATION_CONTEXT_KEY];
|
|
528
|
+
if (globalContext) {
|
|
529
|
+
activeContext = globalContext;
|
|
530
|
+
}
|
|
531
|
+
return activeContext;
|
|
532
|
+
}
|
|
533
|
+
function setActiveApplicationContext(context) {
|
|
534
|
+
activeContext = context;
|
|
535
|
+
globalThis[APPLICATION_CONTEXT_KEY] = context;
|
|
536
|
+
}
|
|
537
|
+
function requireActiveApplicationContext() {
|
|
538
|
+
const context = readStoredApplicationContext();
|
|
539
|
+
if (!context) {
|
|
540
|
+
throw new Error("The application context has not been bootstrapped.");
|
|
541
|
+
}
|
|
542
|
+
return context;
|
|
543
|
+
}
|
|
544
|
+
function resolveApplicationCache() {
|
|
545
|
+
return getRequiredDependency(requireActiveApplicationContext().dependencies, "cache");
|
|
546
|
+
}
|
|
547
|
+
function resolveApplicationQueue() {
|
|
548
|
+
return requireActiveApplicationContext().container.resolve(CORE_QUEUE_TOKEN);
|
|
549
|
+
}
|
|
550
|
+
function resolveApplicationAuth() {
|
|
551
|
+
return requireActiveApplicationContext().container.resolve(CORE_AUTH_TOKEN);
|
|
552
|
+
}
|
|
553
|
+
function resolveApplicationPolicyGate() {
|
|
554
|
+
return requireActiveApplicationContext().container.resolve(CORE_POLICY_GATE_TOKEN);
|
|
555
|
+
}
|
|
556
|
+
function resolveApplicationConfig() {
|
|
557
|
+
return requireActiveApplicationContext().config;
|
|
558
|
+
}
|
|
559
|
+
function resolveApplicationLogger() {
|
|
560
|
+
return appLogger;
|
|
561
|
+
}
|
|
562
|
+
function resolveApplicationDependencies() {
|
|
563
|
+
return requireActiveApplicationContext().dependencies;
|
|
564
|
+
}
|
|
565
|
+
|
|
381
566
|
// ../../src/bootstrap/queue/defaultJobs.ts
|
|
382
567
|
function registerDefaultJobs() {
|
|
383
568
|
jobRegistry.register("cache.invalidate-tags", () => {
|
|
@@ -20,6 +20,7 @@ export { default as MembershipService, resolveMembershipService, } from "../core
|
|
|
20
20
|
export { Policy, PolicyGate } from "../core/auth/policy.ts";
|
|
21
21
|
export { createScimAuthMiddleware } from "../core/auth/scimAuthMiddleware.ts";
|
|
22
22
|
export { type CacheDriver, type CreateCacheStoreOptions, createCacheStore, } from "../core/cache/createCacheStore.ts";
|
|
23
|
+
export { cacheTagsForModelWrite, discoverModelTableNames } from "../core/cache/modelCacheTags.ts";
|
|
23
24
|
export { default as CacheRepository } from "../core/cache/repository.ts";
|
|
24
25
|
export { CACHE_TAGS } from "../core/cache/tags.ts";
|
|
25
26
|
export type { DatabaseConnection } from "../core/database/baseRepository.ts";
|