@getstrata/bootstrap 0.2.9 → 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 +1 -0
- package/dist/bootstrap/routeRegistry.d.ts +1 -5
- package/dist/bootstrap/server.d.ts +1 -1
- package/dist/core/auth/authContext.d.ts +1 -2
- package/dist/core/auth/guard.d.ts +2 -2
- package/dist/core/auth/membershipContext.d.ts +1 -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/http/requestMetaContext.d.ts +1 -2
- package/dist/core/openapi/registeredRoute.d.ts +6 -0
- package/dist/core/runtime/asyncContextStore.d.ts +3 -0
- package/dist/core/tenant/tenantContext.d.ts +1 -2
- package/dist/core/tracing/traceContext.d.ts +1 -2
- package/dist/core/view/webLayoutData.d.ts +2 -2
- package/dist/entries/applicationRegistry.js +15 -2
- package/dist/entries/cache/modelCacheTags.js +22 -0
- package/dist/entries/context.js +150 -147
- package/dist/entries/createWebRoutes.js +22 -29
- package/dist/entries/http/securedRouteModelBinding.js +31 -6
- package/dist/entries/membershipService.js +32 -10
- package/dist/entries/providers/view.js +17 -6
- package/dist/entries/providers.js +59 -52
- package/dist/entries/queue/defaultJobs.js +30 -4
- package/dist/framework/public-api.d.ts +1 -0
- package/dist/index.js +69 -68
- package/package.json +8 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// ../../src/bootstrap/createWebRoutes.ts
|
|
3
|
-
import { join as
|
|
3
|
+
import { join as join2 } from "path";
|
|
4
4
|
|
|
5
5
|
// ../../src/config/frontend.ts
|
|
6
6
|
function readFrontendMode() {
|
|
@@ -173,9 +173,22 @@ var databaseConfig = {
|
|
|
173
173
|
connectionTimeoutSeconds: readInteger("DB_CONNECTION_TIMEOUT", 10)
|
|
174
174
|
};
|
|
175
175
|
|
|
176
|
-
// ../../src/core/
|
|
176
|
+
// ../../src/core/runtime/asyncContextStore.ts
|
|
177
177
|
import { AsyncLocalStorage } from "async_hooks";
|
|
178
|
-
|
|
178
|
+
function createAsyncContextStore(key) {
|
|
179
|
+
const symbol = Symbol.for(key);
|
|
180
|
+
const globalRecord = globalThis;
|
|
181
|
+
const existing = globalRecord[symbol];
|
|
182
|
+
if (existing) {
|
|
183
|
+
return existing;
|
|
184
|
+
}
|
|
185
|
+
const store = new AsyncLocalStorage;
|
|
186
|
+
globalRecord[symbol] = store;
|
|
187
|
+
return store;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// ../../src/core/database/connectionContext.ts
|
|
191
|
+
var activeConnection = createAsyncContextStore("@getstrata/databaseConnectionContext");
|
|
179
192
|
function getActiveDatabaseConnection(fallback) {
|
|
180
193
|
return activeConnection.getStore() ?? fallback;
|
|
181
194
|
}
|
|
@@ -486,8 +499,7 @@ import { resolveDefaultTokenExpiryDays as resolveDefaultTokenExpiryDays2 } from
|
|
|
486
499
|
var tokenServiceToken = CORE_TOKEN_SERVICE_TOKEN;
|
|
487
500
|
|
|
488
501
|
// ../../src/core/auth/authContext.ts
|
|
489
|
-
|
|
490
|
-
var authContext = new AsyncLocalStorage2;
|
|
502
|
+
var authContext = createAsyncContextStore("@getstrata/authContext");
|
|
491
503
|
function currentAuthUser() {
|
|
492
504
|
return authContext.getStore() ?? null;
|
|
493
505
|
}
|
|
@@ -518,8 +530,7 @@ function readRequestCookie(request, name) {
|
|
|
518
530
|
}
|
|
519
531
|
|
|
520
532
|
// ../../src/core/http/requestMetaContext.ts
|
|
521
|
-
|
|
522
|
-
var requestMetaContext = new AsyncLocalStorage3;
|
|
533
|
+
var requestMetaContext = createAsyncContextStore("@getstrata/requestMetaContext");
|
|
523
534
|
function currentRequestMeta() {
|
|
524
535
|
return requestMetaContext.getStore() ?? {
|
|
525
536
|
ipAddress: null,
|
|
@@ -894,28 +905,10 @@ function createHttpKernel(dependencies) {
|
|
|
894
905
|
}
|
|
895
906
|
|
|
896
907
|
// ../../src/bootstrap/discoverModules.ts
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
async function loadDiscoveredModules() {
|
|
901
|
-
const modulesDirectory = join2(import.meta.dir, "../modules");
|
|
902
|
-
let moduleNames;
|
|
903
|
-
try {
|
|
904
|
-
moduleNames = readdirSync(modulesDirectory, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
|
|
905
|
-
} catch (error) {
|
|
906
|
-
if (error.code === "ENOENT") {
|
|
907
|
-
return [];
|
|
908
|
-
}
|
|
909
|
-
throw error;
|
|
910
|
-
}
|
|
911
|
-
const modules = await Promise.all(moduleNames.map(async (moduleName) => {
|
|
912
|
-
const moduleUrl = pathToFileURL(join2(modulesDirectory, moduleName, "index.ts")).href;
|
|
913
|
-
const loaded = await import(moduleUrl);
|
|
914
|
-
return loaded.default;
|
|
915
|
-
}));
|
|
916
|
-
return modules.filter((module) => module?.name !== undefined).sort((left, right) => (left.order ?? 100) - (right.order ?? 100));
|
|
908
|
+
var appModules = [];
|
|
909
|
+
function discoverModules() {
|
|
910
|
+
return appModules;
|
|
917
911
|
}
|
|
918
|
-
var appModules = await loadDiscoveredModules();
|
|
919
912
|
// ../../src/bootstrap/routeRegistry.ts
|
|
920
913
|
class RouteRegistry {
|
|
921
914
|
routes = [];
|
|
@@ -973,7 +966,7 @@ function createWebRoutes(dependencies) {
|
|
|
973
966
|
registerRoute("GET", "/assets/*", ["global", "web"]);
|
|
974
967
|
const pathname = new URL(request.url).pathname;
|
|
975
968
|
const relativePath = pathname.replace(/^\//, "");
|
|
976
|
-
const file = Bun.file(
|
|
969
|
+
const file = Bun.file(join2(process.cwd(), "public", relativePath));
|
|
977
970
|
if (!await file.exists()) {
|
|
978
971
|
return htmlResponse("Not Found", { status: 404 });
|
|
979
972
|
}
|
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
// ../../src/core/
|
|
2
|
+
// ../../src/core/runtime/asyncContextStore.ts
|
|
3
3
|
import { AsyncLocalStorage } from "async_hooks";
|
|
4
|
-
|
|
4
|
+
function createAsyncContextStore(key) {
|
|
5
|
+
const symbol = Symbol.for(key);
|
|
6
|
+
const globalRecord = globalThis;
|
|
7
|
+
const existing = globalRecord[symbol];
|
|
8
|
+
if (existing) {
|
|
9
|
+
return existing;
|
|
10
|
+
}
|
|
11
|
+
const store = new AsyncLocalStorage;
|
|
12
|
+
globalRecord[symbol] = store;
|
|
13
|
+
return store;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// ../../src/core/auth/authContext.ts
|
|
17
|
+
var authContext = createAsyncContextStore("@getstrata/authContext");
|
|
5
18
|
function currentAuthUser() {
|
|
6
19
|
return authContext.getStore() ?? null;
|
|
7
20
|
}
|
|
@@ -143,8 +156,7 @@ function applyConditionalGet(request, response, etag) {
|
|
|
143
156
|
}
|
|
144
157
|
|
|
145
158
|
// ../../src/core/tenant/tenantContext.ts
|
|
146
|
-
|
|
147
|
-
var tenantContext = new AsyncLocalStorage2;
|
|
159
|
+
var tenantContext = createAsyncContextStore("@getstrata/tenantContext");
|
|
148
160
|
|
|
149
161
|
// ../../src/core/http/validation.ts
|
|
150
162
|
function parsePositiveIntParam(value, name = "id") {
|
|
@@ -298,15 +310,28 @@ function resolveService(dependencies, token) {
|
|
|
298
310
|
}
|
|
299
311
|
|
|
300
312
|
// ../../src/bootstrap/applicationRegistry.ts
|
|
313
|
+
var APPLICATION_CONTEXT_KEY = Symbol.for("@getstrata/applicationContext");
|
|
301
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
|
+
}
|
|
302
325
|
function setActiveApplicationContext(context) {
|
|
303
326
|
activeContext = context;
|
|
327
|
+
globalThis[APPLICATION_CONTEXT_KEY] = context;
|
|
304
328
|
}
|
|
305
329
|
function requireActiveApplicationContext() {
|
|
306
|
-
|
|
330
|
+
const context = readStoredApplicationContext();
|
|
331
|
+
if (!context) {
|
|
307
332
|
throw new Error("The application context has not been bootstrapped.");
|
|
308
333
|
}
|
|
309
|
-
return
|
|
334
|
+
return context;
|
|
310
335
|
}
|
|
311
336
|
function resolveApplicationCache() {
|
|
312
337
|
return getRequiredDependency(requireActiveApplicationContext().dependencies, "cache");
|
|
@@ -44,9 +44,22 @@ class PreconditionFailedError extends HttpError {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
// ../../src/core/
|
|
47
|
+
// ../../src/core/runtime/asyncContextStore.ts
|
|
48
48
|
import { AsyncLocalStorage } from "async_hooks";
|
|
49
|
-
|
|
49
|
+
function createAsyncContextStore(key) {
|
|
50
|
+
const symbol = Symbol.for(key);
|
|
51
|
+
const globalRecord = globalThis;
|
|
52
|
+
const existing = globalRecord[symbol];
|
|
53
|
+
if (existing) {
|
|
54
|
+
return existing;
|
|
55
|
+
}
|
|
56
|
+
const store = new AsyncLocalStorage;
|
|
57
|
+
globalRecord[symbol] = store;
|
|
58
|
+
return store;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// ../../src/core/auth/authContext.ts
|
|
62
|
+
var authContext = createAsyncContextStore("@getstrata/authContext");
|
|
50
63
|
function currentAuthUser() {
|
|
51
64
|
return authContext.getStore() ?? null;
|
|
52
65
|
}
|
|
@@ -74,9 +87,6 @@ function resolveUserId(user) {
|
|
|
74
87
|
return userId;
|
|
75
88
|
}
|
|
76
89
|
|
|
77
|
-
// ../../src/core/auth/membershipContext.ts
|
|
78
|
-
import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
|
|
79
|
-
|
|
80
90
|
// ../../src/config/database.ts
|
|
81
91
|
function readInteger(name, fallback) {
|
|
82
92
|
const parsed = Number.parseInt(process.env[name] ?? String(fallback), 10);
|
|
@@ -91,8 +101,7 @@ var databaseConfig = {
|
|
|
91
101
|
};
|
|
92
102
|
|
|
93
103
|
// ../../src/core/database/connectionContext.ts
|
|
94
|
-
|
|
95
|
-
var activeConnection = new AsyncLocalStorage2;
|
|
104
|
+
var activeConnection = createAsyncContextStore("@getstrata/databaseConnectionContext");
|
|
96
105
|
function getActiveDatabaseConnection(fallback) {
|
|
97
106
|
return activeConnection.getStore() ?? fallback;
|
|
98
107
|
}
|
|
@@ -233,7 +242,7 @@ class OrganizationMemberRepository {
|
|
|
233
242
|
var memberRepository_default = OrganizationMemberRepository;
|
|
234
243
|
|
|
235
244
|
// ../../src/core/auth/membershipContext.ts
|
|
236
|
-
var membershipContext =
|
|
245
|
+
var membershipContext = createAsyncContextStore("@getstrata/membershipContext");
|
|
237
246
|
var membershipRepository = new memberRepository_default;
|
|
238
247
|
|
|
239
248
|
// ../../src/core/auth/membershipService.ts
|
|
@@ -435,15 +444,28 @@ function resolveService(dependencies, token) {
|
|
|
435
444
|
}
|
|
436
445
|
|
|
437
446
|
// ../../src/bootstrap/applicationRegistry.ts
|
|
447
|
+
var APPLICATION_CONTEXT_KEY = Symbol.for("@getstrata/applicationContext");
|
|
438
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
|
+
}
|
|
439
459
|
function setActiveApplicationContext(context) {
|
|
440
460
|
activeContext = context;
|
|
461
|
+
globalThis[APPLICATION_CONTEXT_KEY] = context;
|
|
441
462
|
}
|
|
442
463
|
function requireActiveApplicationContext() {
|
|
443
|
-
|
|
464
|
+
const context = readStoredApplicationContext();
|
|
465
|
+
if (!context) {
|
|
444
466
|
throw new Error("The application context has not been bootstrapped.");
|
|
445
467
|
}
|
|
446
|
-
return
|
|
468
|
+
return context;
|
|
447
469
|
}
|
|
448
470
|
function resolveApplicationCache() {
|
|
449
471
|
return getRequiredDependency(requireActiveApplicationContext().dependencies, "cache");
|
|
@@ -14,9 +14,22 @@ function isViewsEnabled() {
|
|
|
14
14
|
return readFrontendMode() === "server-htmx";
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
// ../../src/core/
|
|
17
|
+
// ../../src/core/runtime/asyncContextStore.ts
|
|
18
18
|
import { AsyncLocalStorage } from "async_hooks";
|
|
19
|
-
|
|
19
|
+
function createAsyncContextStore(key) {
|
|
20
|
+
const symbol = Symbol.for(key);
|
|
21
|
+
const globalRecord = globalThis;
|
|
22
|
+
const existing = globalRecord[symbol];
|
|
23
|
+
if (existing) {
|
|
24
|
+
return existing;
|
|
25
|
+
}
|
|
26
|
+
const store = new AsyncLocalStorage;
|
|
27
|
+
globalRecord[symbol] = store;
|
|
28
|
+
return store;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// ../../src/core/http/requestMetaContext.ts
|
|
32
|
+
var requestMetaContext = createAsyncContextStore("@getstrata/requestMetaContext");
|
|
20
33
|
function currentRequestMeta() {
|
|
21
34
|
return requestMetaContext.getStore() ?? {
|
|
22
35
|
ipAddress: null,
|
|
@@ -130,8 +143,7 @@ var databaseConfig = {
|
|
|
130
143
|
};
|
|
131
144
|
|
|
132
145
|
// ../../src/core/database/connectionContext.ts
|
|
133
|
-
|
|
134
|
-
var activeConnection = new AsyncLocalStorage2;
|
|
146
|
+
var activeConnection = createAsyncContextStore("@getstrata/databaseConnectionContext");
|
|
135
147
|
function getActiveDatabaseConnection(fallback) {
|
|
136
148
|
return activeConnection.getStore() ?? fallback;
|
|
137
149
|
}
|
|
@@ -442,8 +454,7 @@ import { resolveDefaultTokenExpiryDays as resolveDefaultTokenExpiryDays2 } from
|
|
|
442
454
|
var tokenServiceToken = CORE_TOKEN_SERVICE_TOKEN;
|
|
443
455
|
|
|
444
456
|
// ../../src/core/auth/authContext.ts
|
|
445
|
-
|
|
446
|
-
var authContext = new AsyncLocalStorage3;
|
|
457
|
+
var authContext = createAsyncContextStore("@getstrata/authContext");
|
|
447
458
|
function currentAuthUser() {
|
|
448
459
|
return authContext.getStore() ?? null;
|
|
449
460
|
}
|
|
@@ -106,9 +106,22 @@ var databaseConfig = {
|
|
|
106
106
|
connectionTimeoutSeconds: readInteger("DB_CONNECTION_TIMEOUT", 10)
|
|
107
107
|
};
|
|
108
108
|
|
|
109
|
-
// ../../src/core/
|
|
109
|
+
// ../../src/core/runtime/asyncContextStore.ts
|
|
110
110
|
import { AsyncLocalStorage } from "async_hooks";
|
|
111
|
-
|
|
111
|
+
function createAsyncContextStore(key) {
|
|
112
|
+
const symbol = Symbol.for(key);
|
|
113
|
+
const globalRecord = globalThis;
|
|
114
|
+
const existing = globalRecord[symbol];
|
|
115
|
+
if (existing) {
|
|
116
|
+
return existing;
|
|
117
|
+
}
|
|
118
|
+
const store = new AsyncLocalStorage;
|
|
119
|
+
globalRecord[symbol] = store;
|
|
120
|
+
return store;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// ../../src/core/database/connectionContext.ts
|
|
124
|
+
var activeConnection = createAsyncContextStore("@getstrata/databaseConnectionContext");
|
|
112
125
|
function getActiveDatabaseConnection(fallback) {
|
|
113
126
|
return activeConnection.getStore() ?? fallback;
|
|
114
127
|
}
|
|
@@ -424,8 +437,7 @@ class PreconditionFailedError extends HttpError {
|
|
|
424
437
|
}
|
|
425
438
|
|
|
426
439
|
// ../../src/core/auth/authContext.ts
|
|
427
|
-
|
|
428
|
-
var authContext = new AsyncLocalStorage2;
|
|
440
|
+
var authContext = createAsyncContextStore("@getstrata/authContext");
|
|
429
441
|
function currentAuthUser() {
|
|
430
442
|
return authContext.getStore() ?? null;
|
|
431
443
|
}
|
|
@@ -1299,41 +1311,6 @@ function discoverListeners() {
|
|
|
1299
1311
|
return appListeners;
|
|
1300
1312
|
}
|
|
1301
1313
|
|
|
1302
|
-
// ../../src/bootstrap/discoverModules.ts
|
|
1303
|
-
import { readdirSync as readdirSync2 } from "fs";
|
|
1304
|
-
import { join as join2 } from "path";
|
|
1305
|
-
import { pathToFileURL as pathToFileURL2 } from "url";
|
|
1306
|
-
async function loadDiscoveredModules() {
|
|
1307
|
-
const modulesDirectory = join2(import.meta.dir, "../modules");
|
|
1308
|
-
let moduleNames;
|
|
1309
|
-
try {
|
|
1310
|
-
moduleNames = readdirSync2(modulesDirectory, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
|
|
1311
|
-
} catch (error) {
|
|
1312
|
-
if (error.code === "ENOENT") {
|
|
1313
|
-
return [];
|
|
1314
|
-
}
|
|
1315
|
-
throw error;
|
|
1316
|
-
}
|
|
1317
|
-
const modules = await Promise.all(moduleNames.map(async (moduleName) => {
|
|
1318
|
-
const moduleUrl = pathToFileURL2(join2(modulesDirectory, moduleName, "index.ts")).href;
|
|
1319
|
-
const loaded = await import(moduleUrl);
|
|
1320
|
-
return loaded.default;
|
|
1321
|
-
}));
|
|
1322
|
-
return modules.filter((module) => module?.name !== undefined).sort((left, right) => (left.order ?? 100) - (right.order ?? 100));
|
|
1323
|
-
}
|
|
1324
|
-
var appModules = await loadDiscoveredModules();
|
|
1325
|
-
// ../../src/core/cache/modelCacheTags.ts
|
|
1326
|
-
function cacheTagsForModelWrite(tableName, action) {
|
|
1327
|
-
const module = appModules.find((entry) => entry.tableName === tableName);
|
|
1328
|
-
const baseTags = module?.cacheTags ?? [`${tableName}s`];
|
|
1329
|
-
const isDelete = action === "deleted" || action === "force-deleted";
|
|
1330
|
-
const extraTags = isDelete ? module?.cacheDeleteExtraTags ?? [] : [];
|
|
1331
|
-
return [...new Set([...baseTags, ...extraTags])];
|
|
1332
|
-
}
|
|
1333
|
-
function discoverModelTableNames() {
|
|
1334
|
-
return appModules.map((module) => module.tableName).filter((tableName) => tableName !== undefined);
|
|
1335
|
-
}
|
|
1336
|
-
|
|
1337
1314
|
// ../../src/core/queue/index.ts
|
|
1338
1315
|
class Job {
|
|
1339
1316
|
maxAttempts;
|
|
@@ -1644,10 +1621,10 @@ function buildHavingClause(tableName, having, params) {
|
|
|
1644
1621
|
return body.length > 0 ? ` HAVING ${body}` : "";
|
|
1645
1622
|
}
|
|
1646
1623
|
function buildJoinClause(joins = []) {
|
|
1647
|
-
return joins.map((
|
|
1648
|
-
const joinType =
|
|
1649
|
-
const onClause =
|
|
1650
|
-
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}`;
|
|
1651
1628
|
}).join("");
|
|
1652
1629
|
}
|
|
1653
1630
|
function buildLimitClause(limit) {
|
|
@@ -2083,7 +2060,7 @@ class RepositoryQuery {
|
|
|
2083
2060
|
const rightRef = parseQualifiedColumn(right);
|
|
2084
2061
|
const table = type === "inner" ? rightRef.table : rightRef.table;
|
|
2085
2062
|
const joins = this.queryOptions.joins ?? [];
|
|
2086
|
-
const existing = joins.find((
|
|
2063
|
+
const existing = joins.find((join2) => join2.table === table && join2.type === type);
|
|
2087
2064
|
if (existing) {
|
|
2088
2065
|
existing.on.push({ left: leftRef, right: rightRef });
|
|
2089
2066
|
return this;
|
|
@@ -3555,15 +3532,28 @@ function resolveService(dependencies, token) {
|
|
|
3555
3532
|
}
|
|
3556
3533
|
|
|
3557
3534
|
// ../../src/bootstrap/applicationRegistry.ts
|
|
3535
|
+
var APPLICATION_CONTEXT_KEY = Symbol.for("@getstrata/applicationContext");
|
|
3558
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
|
+
}
|
|
3559
3547
|
function setActiveApplicationContext(context) {
|
|
3560
3548
|
activeContext = context;
|
|
3549
|
+
globalThis[APPLICATION_CONTEXT_KEY] = context;
|
|
3561
3550
|
}
|
|
3562
3551
|
function requireActiveApplicationContext() {
|
|
3563
|
-
|
|
3552
|
+
const context = readStoredApplicationContext();
|
|
3553
|
+
if (!context) {
|
|
3564
3554
|
throw new Error("The application context has not been bootstrapped.");
|
|
3565
3555
|
}
|
|
3566
|
-
return
|
|
3556
|
+
return context;
|
|
3567
3557
|
}
|
|
3568
3558
|
function resolveApplicationCache() {
|
|
3569
3559
|
return getRequiredDependency(requireActiveApplicationContext().dependencies, "cache");
|
|
@@ -3605,6 +3595,24 @@ function createAppQueue(driver, redisUrl, failedJobs = createFailedJobService(),
|
|
|
3605
3595
|
});
|
|
3606
3596
|
}
|
|
3607
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
|
+
|
|
3608
3616
|
// ../../src/bootstrap/listeners/invalidateCacheOnModelWrite.ts
|
|
3609
3617
|
var MODEL_WRITE_ACTIONS = ["created", "updated", "deleted", "restored", "force-deleted"];
|
|
3610
3618
|
function registerInvalidateCacheOnModelWriteListeners(bus = eventBus) {
|
|
@@ -3716,7 +3724,7 @@ var queue_default = queueProvider;
|
|
|
3716
3724
|
|
|
3717
3725
|
// ../../src/core/storage/storage.ts
|
|
3718
3726
|
import { mkdir, readFile, unlink, writeFile } from "fs/promises";
|
|
3719
|
-
import { dirname, join as
|
|
3727
|
+
import { dirname, join as join2 } from "path";
|
|
3720
3728
|
var {S3Client } = globalThis.Bun;
|
|
3721
3729
|
|
|
3722
3730
|
class LocalStorageDriver {
|
|
@@ -3728,7 +3736,7 @@ class LocalStorageDriver {
|
|
|
3728
3736
|
return this.rootDirectory ?? process.env.STORAGE_PATH ?? "storage";
|
|
3729
3737
|
}
|
|
3730
3738
|
resolvePath(path) {
|
|
3731
|
-
return
|
|
3739
|
+
return join2(this.resolveRootDirectory(), path.replace(/^\/+/, ""));
|
|
3732
3740
|
}
|
|
3733
3741
|
async put(path, contents) {
|
|
3734
3742
|
const absolutePath = this.resolvePath(path);
|
|
@@ -3852,8 +3860,7 @@ function isViewsEnabled() {
|
|
|
3852
3860
|
}
|
|
3853
3861
|
|
|
3854
3862
|
// ../../src/core/http/requestMetaContext.ts
|
|
3855
|
-
|
|
3856
|
-
var requestMetaContext = new AsyncLocalStorage3;
|
|
3863
|
+
var requestMetaContext = createAsyncContextStore("@getstrata/requestMetaContext");
|
|
3857
3864
|
function currentRequestMeta() {
|
|
3858
3865
|
return requestMetaContext.getStore() ?? {
|
|
3859
3866
|
ipAddress: null,
|
|
@@ -3862,9 +3869,9 @@ function currentRequestMeta() {
|
|
|
3862
3869
|
}
|
|
3863
3870
|
|
|
3864
3871
|
// ../../src/core/view/etaViewEngine.ts
|
|
3865
|
-
import { join as
|
|
3872
|
+
import { join as join3 } from "path";
|
|
3866
3873
|
import { Eta } from "eta";
|
|
3867
|
-
var DEFAULT_VIEWS_DIRECTORY =
|
|
3874
|
+
var DEFAULT_VIEWS_DIRECTORY = join3(process.cwd(), "resources/views");
|
|
3868
3875
|
var DEFAULT_LAYOUT = "layouts/app.eta";
|
|
3869
3876
|
|
|
3870
3877
|
class EtaViewEngine {
|
|
@@ -19,9 +19,22 @@ function getBoundDatabaseConnection() {
|
|
|
19
19
|
return boundConnectionHolder.connection;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
// ../../src/core/
|
|
22
|
+
// ../../src/core/runtime/asyncContextStore.ts
|
|
23
23
|
import { AsyncLocalStorage } from "async_hooks";
|
|
24
|
-
|
|
24
|
+
function createAsyncContextStore(key) {
|
|
25
|
+
const symbol = Symbol.for(key);
|
|
26
|
+
const globalRecord = globalThis;
|
|
27
|
+
const existing = globalRecord[symbol];
|
|
28
|
+
if (existing) {
|
|
29
|
+
return existing;
|
|
30
|
+
}
|
|
31
|
+
const store = new AsyncLocalStorage;
|
|
32
|
+
globalRecord[symbol] = store;
|
|
33
|
+
return store;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// ../../src/core/database/connectionContext.ts
|
|
37
|
+
var activeConnection = createAsyncContextStore("@getstrata/databaseConnectionContext");
|
|
25
38
|
function getActiveDatabaseConnection(fallback) {
|
|
26
39
|
return activeConnection.getStore() ?? fallback;
|
|
27
40
|
}
|
|
@@ -505,15 +518,28 @@ function resolveService(dependencies, token) {
|
|
|
505
518
|
}
|
|
506
519
|
|
|
507
520
|
// ../../src/bootstrap/applicationRegistry.ts
|
|
521
|
+
var APPLICATION_CONTEXT_KEY = Symbol.for("@getstrata/applicationContext");
|
|
508
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
|
+
}
|
|
509
533
|
function setActiveApplicationContext(context) {
|
|
510
534
|
activeContext = context;
|
|
535
|
+
globalThis[APPLICATION_CONTEXT_KEY] = context;
|
|
511
536
|
}
|
|
512
537
|
function requireActiveApplicationContext() {
|
|
513
|
-
|
|
538
|
+
const context = readStoredApplicationContext();
|
|
539
|
+
if (!context) {
|
|
514
540
|
throw new Error("The application context has not been bootstrapped.");
|
|
515
541
|
}
|
|
516
|
-
return
|
|
542
|
+
return context;
|
|
517
543
|
}
|
|
518
544
|
function resolveApplicationCache() {
|
|
519
545
|
return getRequiredDependency(requireActiveApplicationContext().dependencies, "cache");
|
|
@@ -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";
|