@getstrata/core 0.5.17 → 0.5.20
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/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/generator.d.ts +1 -1
- 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/http/csrfToken.js +15 -2
- package/dist/entries/http/webErrorResponse.js +18 -8
- package/dist/entries/http/webFormRequest.js +16 -4
- package/dist/entries/jobs/dispatchWebhookJob.js +15 -2
- package/dist/entries/queue/createAppQueue.js +29 -4
- package/dist/entries/queue/publicQueue.js +15 -2
- package/dist/entries/queue/queueMetrics.js +29 -4
- package/dist/entries/view.js +18 -8
- package/dist/framework/public-api.d.ts +1 -0
- package/dist/index.js +54 -16
- package/package.json +1 -1
- package/dist/bootstrap/modules.d.ts +0 -1
- package/dist/bootstrap/routeRegistry.d.ts +0 -14
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AppModule } from "./contracts";
|
|
2
|
-
declare
|
|
2
|
+
declare let appModules: AppModule[];
|
|
3
|
+
declare function ensureModulesLoaded(): Promise<AppModule[]>;
|
|
3
4
|
declare function discoverModules(): AppModule[];
|
|
4
|
-
export { appModules, discoverModules };
|
|
5
|
+
export { appModules, discoverModules, ensureModulesLoaded };
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
1
|
type AuthUser = {
|
|
3
2
|
id: number | string;
|
|
4
3
|
role?: string;
|
|
5
4
|
abilities?: string[];
|
|
6
5
|
tokenId?: number;
|
|
7
6
|
};
|
|
8
|
-
declare const authContext: AsyncLocalStorage<AuthUser | null>;
|
|
7
|
+
declare const authContext: import("node:async_hooks").AsyncLocalStorage<AuthUser | null>;
|
|
9
8
|
declare function runWithAuthUser<T>(user: AuthUser | null, callback: () => T | Promise<T>): T | Promise<T>;
|
|
10
9
|
declare function currentAuthUser(): AuthUser | null;
|
|
11
10
|
export type { AuthUser };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ServiceContainerLike } from "../contracts/serviceContainer";
|
|
2
2
|
import type { AuthUser } from "./authContext";
|
|
3
3
|
interface AuthGuard {
|
|
4
4
|
resolve(request: Request): AuthUser | null | Promise<AuthUser | null>;
|
|
@@ -16,7 +16,7 @@ declare class ApiTokenGuard implements AuthGuard {
|
|
|
16
16
|
}
|
|
17
17
|
declare class DatabaseTokenGuard implements AuthGuard {
|
|
18
18
|
private readonly container;
|
|
19
|
-
constructor(container:
|
|
19
|
+
constructor(container: ServiceContainerLike);
|
|
20
20
|
resolve(request: Request): Promise<AuthUser | null>;
|
|
21
21
|
}
|
|
22
22
|
declare class CompositeGuard implements AuthGuard {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
1
|
import OrganizationMemberRepository from "../../modules/organization/memberRepository";
|
|
3
2
|
import type { OrganizationMemberRole } from "../../modules/organization/memberTypes";
|
|
4
3
|
type MembershipContext = {
|
|
5
4
|
organizationIds: number[];
|
|
6
5
|
rolesByOrganizationId: Map<number, OrganizationMemberRole>;
|
|
7
6
|
};
|
|
8
|
-
declare const membershipContext: AsyncLocalStorage<MembershipContext>;
|
|
7
|
+
declare const membershipContext: import("node:async_hooks").AsyncLocalStorage<MembershipContext>;
|
|
9
8
|
declare const membershipRepository: OrganizationMemberRepository;
|
|
10
9
|
declare function runWithMembershipContext<T>(callback: () => T | Promise<T>): Promise<T | Promise<T>>;
|
|
11
10
|
declare function currentOrgRole(organizationId: number): OrganizationMemberRole | null;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ServiceContainerLike } from "../contracts/serviceContainer";
|
|
2
2
|
import type { AuthUser } from "./authContext";
|
|
3
3
|
import type { AuthGuard } from "./guard";
|
|
4
4
|
declare class SessionGuard implements AuthGuard {
|
|
5
5
|
private readonly container;
|
|
6
|
-
constructor(container:
|
|
6
|
+
constructor(container: ServiceContainerLike);
|
|
7
7
|
resolve(request: Request): Promise<AuthUser | null>;
|
|
8
8
|
}
|
|
9
9
|
export { SessionGuard };
|
|
@@ -1,3 +1 @@
|
|
|
1
|
-
|
|
2
|
-
declare function discoverModelTableNames(): string[];
|
|
3
|
-
export { cacheTagsForModelWrite, discoverModelTableNames };
|
|
1
|
+
export { cacheTagsForModelWrite, discoverModelTableNames, } from "../../bootstrap/cache/modelCacheTags.ts";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
1
|
type RequestMeta = {
|
|
3
2
|
ipAddress: string | null;
|
|
4
3
|
userAgent: string | null;
|
|
@@ -9,7 +8,7 @@ type RequestMeta = {
|
|
|
9
8
|
} | null;
|
|
10
9
|
csrfToken?: string;
|
|
11
10
|
};
|
|
12
|
-
declare const requestMetaContext: AsyncLocalStorage<RequestMeta>;
|
|
11
|
+
declare const requestMetaContext: import("node:async_hooks").AsyncLocalStorage<RequestMeta>;
|
|
13
12
|
declare function runWithRequestMeta<T>(meta: RequestMeta, callback: () => T | Promise<T>): T | Promise<T>;
|
|
14
13
|
declare function currentRequestMeta(): RequestMeta;
|
|
15
14
|
export type { RequestMeta };
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
1
|
type TenantContext = {
|
|
3
2
|
id: number;
|
|
4
3
|
slug: string;
|
|
5
4
|
plan: "free" | "pro" | "enterprise";
|
|
6
5
|
region: "eu" | "us" | "apac";
|
|
7
6
|
};
|
|
8
|
-
declare const tenantContext: AsyncLocalStorage<TenantContext>;
|
|
7
|
+
declare const tenantContext: import("node:async_hooks").AsyncLocalStorage<TenantContext>;
|
|
9
8
|
declare function runWithTenant<T>(tenant: TenantContext, callback: () => T | Promise<T>): T | Promise<T>;
|
|
10
9
|
declare function currentTenant(): TenantContext | null;
|
|
11
10
|
declare function currentTenantId(): number;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
1
|
type TraceContext = {
|
|
3
2
|
traceId: string;
|
|
4
3
|
spanId: string;
|
|
5
4
|
};
|
|
6
|
-
declare const traceContextStorage: AsyncLocalStorage<TraceContext>;
|
|
5
|
+
declare const traceContextStorage: import("node:async_hooks").AsyncLocalStorage<TraceContext>;
|
|
7
6
|
declare function runWithTraceContext<T>(context: TraceContext, callback: () => T | Promise<T>): T | Promise<T>;
|
|
8
7
|
declare function currentTraceId(): string | null;
|
|
9
8
|
export type { TraceContext };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ServiceContainerLike } from "../contracts/serviceContainer";
|
|
2
2
|
interface WebLayoutAuthUser {
|
|
3
3
|
id: number;
|
|
4
4
|
email: string;
|
|
@@ -12,6 +12,6 @@ interface WebLayoutData {
|
|
|
12
12
|
message: string;
|
|
13
13
|
} | null;
|
|
14
14
|
}
|
|
15
|
-
declare function resolveWebLayoutData(container:
|
|
15
|
+
declare function resolveWebLayoutData(container: ServiceContainerLike, request?: Request): Promise<Record<string, unknown>>;
|
|
16
16
|
export type { WebLayoutAuthUser, WebLayoutData };
|
|
17
17
|
export { resolveWebLayoutData };
|
|
@@ -27,9 +27,22 @@ function readRequestCookie(request, name) {
|
|
|
27
27
|
return null;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
// ../../src/core/
|
|
30
|
+
// ../../src/core/runtime/asyncContextStore.ts
|
|
31
31
|
import { AsyncLocalStorage } from "async_hooks";
|
|
32
|
-
|
|
32
|
+
function createAsyncContextStore(key) {
|
|
33
|
+
const symbol = Symbol.for(key);
|
|
34
|
+
const globalRecord = globalThis;
|
|
35
|
+
const existing = globalRecord[symbol];
|
|
36
|
+
if (existing) {
|
|
37
|
+
return existing;
|
|
38
|
+
}
|
|
39
|
+
const store = new AsyncLocalStorage;
|
|
40
|
+
globalRecord[symbol] = store;
|
|
41
|
+
return store;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// ../../src/core/http/requestMetaContext.ts
|
|
45
|
+
var requestMetaContext = createAsyncContextStore("@getstrata/requestMetaContext");
|
|
33
46
|
function currentRequestMeta() {
|
|
34
47
|
return requestMetaContext.getStore() ?? {
|
|
35
48
|
ipAddress: null,
|
|
@@ -865,9 +865,22 @@ function getBoundDatabaseConnection() {
|
|
|
865
865
|
return boundConnectionHolder.connection;
|
|
866
866
|
}
|
|
867
867
|
|
|
868
|
-
// ../../src/core/
|
|
868
|
+
// ../../src/core/runtime/asyncContextStore.ts
|
|
869
869
|
import { AsyncLocalStorage } from "async_hooks";
|
|
870
|
-
|
|
870
|
+
function createAsyncContextStore(key) {
|
|
871
|
+
const symbol = Symbol.for(key);
|
|
872
|
+
const globalRecord = globalThis;
|
|
873
|
+
const existing = globalRecord[symbol];
|
|
874
|
+
if (existing) {
|
|
875
|
+
return existing;
|
|
876
|
+
}
|
|
877
|
+
const store = new AsyncLocalStorage;
|
|
878
|
+
globalRecord[symbol] = store;
|
|
879
|
+
return store;
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
// ../../src/core/database/connectionContext.ts
|
|
883
|
+
var activeConnection = createAsyncContextStore("@getstrata/databaseConnectionContext");
|
|
871
884
|
function getActiveDatabaseConnection(fallback) {
|
|
872
885
|
return activeConnection.getStore() ?? fallback;
|
|
873
886
|
}
|
|
@@ -2241,15 +2254,13 @@ function revealMfaSecret(stored) {
|
|
|
2241
2254
|
}
|
|
2242
2255
|
|
|
2243
2256
|
// ../../src/core/auth/authContext.ts
|
|
2244
|
-
|
|
2245
|
-
var authContext = new AsyncLocalStorage2;
|
|
2257
|
+
var authContext = createAsyncContextStore("@getstrata/authContext");
|
|
2246
2258
|
function currentAuthUser() {
|
|
2247
2259
|
return authContext.getStore() ?? null;
|
|
2248
2260
|
}
|
|
2249
2261
|
|
|
2250
2262
|
// ../../src/core/http/requestMetaContext.ts
|
|
2251
|
-
|
|
2252
|
-
var requestMetaContext = new AsyncLocalStorage3;
|
|
2263
|
+
var requestMetaContext = createAsyncContextStore("@getstrata/requestMetaContext");
|
|
2253
2264
|
function currentRequestMeta() {
|
|
2254
2265
|
return requestMetaContext.getStore() ?? {
|
|
2255
2266
|
ipAddress: null,
|
|
@@ -2333,8 +2344,7 @@ function verifyTotp(secret, token, window = 1) {
|
|
|
2333
2344
|
}
|
|
2334
2345
|
|
|
2335
2346
|
// ../../src/core/tenant/tenantContext.ts
|
|
2336
|
-
|
|
2337
|
-
var tenantContext = new AsyncLocalStorage4;
|
|
2347
|
+
var tenantContext = createAsyncContextStore("@getstrata/tenantContext");
|
|
2338
2348
|
function currentTenant() {
|
|
2339
2349
|
return tenantContext.getStore() ?? null;
|
|
2340
2350
|
}
|
|
@@ -106,16 +106,28 @@ function formDataToRecord(formData) {
|
|
|
106
106
|
return values;
|
|
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/auth/authContext.ts
|
|
124
|
+
var authContext = createAsyncContextStore("@getstrata/authContext");
|
|
112
125
|
function currentAuthUser() {
|
|
113
126
|
return authContext.getStore() ?? null;
|
|
114
127
|
}
|
|
115
128
|
|
|
116
129
|
// ../../src/core/tenant/tenantContext.ts
|
|
117
|
-
|
|
118
|
-
var tenantContext = new AsyncLocalStorage2;
|
|
130
|
+
var tenantContext = createAsyncContextStore("@getstrata/tenantContext");
|
|
119
131
|
function currentTenant() {
|
|
120
132
|
return tenantContext.getStore() ?? null;
|
|
121
133
|
}
|
|
@@ -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
|
}
|
|
@@ -644,9 +644,22 @@ function getBoundDatabaseConnection() {
|
|
|
644
644
|
return boundConnectionHolder.connection;
|
|
645
645
|
}
|
|
646
646
|
|
|
647
|
-
// ../../src/core/
|
|
647
|
+
// ../../src/core/runtime/asyncContextStore.ts
|
|
648
648
|
import { AsyncLocalStorage } from "async_hooks";
|
|
649
|
-
|
|
649
|
+
function createAsyncContextStore(key) {
|
|
650
|
+
const symbol = Symbol.for(key);
|
|
651
|
+
const globalRecord = globalThis;
|
|
652
|
+
const existing = globalRecord[symbol];
|
|
653
|
+
if (existing) {
|
|
654
|
+
return existing;
|
|
655
|
+
}
|
|
656
|
+
const store = new AsyncLocalStorage;
|
|
657
|
+
globalRecord[symbol] = store;
|
|
658
|
+
return store;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// ../../src/core/database/connectionContext.ts
|
|
662
|
+
var activeConnection = createAsyncContextStore("@getstrata/databaseConnectionContext");
|
|
650
663
|
function getActiveDatabaseConnection(fallback) {
|
|
651
664
|
return activeConnection.getStore() ?? fallback;
|
|
652
665
|
}
|
|
@@ -2471,12 +2484,24 @@ function getRequiredDependency(dependencies, key) {
|
|
|
2471
2484
|
}
|
|
2472
2485
|
|
|
2473
2486
|
// ../../src/bootstrap/applicationRegistry.ts
|
|
2487
|
+
var APPLICATION_CONTEXT_KEY = Symbol.for("@getstrata/applicationContext");
|
|
2474
2488
|
var activeContext;
|
|
2489
|
+
function readStoredApplicationContext() {
|
|
2490
|
+
if (activeContext) {
|
|
2491
|
+
return activeContext;
|
|
2492
|
+
}
|
|
2493
|
+
const globalContext = globalThis[APPLICATION_CONTEXT_KEY];
|
|
2494
|
+
if (globalContext) {
|
|
2495
|
+
activeContext = globalContext;
|
|
2496
|
+
}
|
|
2497
|
+
return activeContext;
|
|
2498
|
+
}
|
|
2475
2499
|
function requireActiveApplicationContext() {
|
|
2476
|
-
|
|
2500
|
+
const context = readStoredApplicationContext();
|
|
2501
|
+
if (!context) {
|
|
2477
2502
|
throw new Error("The application context has not been bootstrapped.");
|
|
2478
2503
|
}
|
|
2479
|
-
return
|
|
2504
|
+
return context;
|
|
2480
2505
|
}
|
|
2481
2506
|
function resolveApplicationCache() {
|
|
2482
2507
|
return getRequiredDependency(requireActiveApplicationContext().dependencies, "cache");
|
|
@@ -644,9 +644,22 @@ function getBoundDatabaseConnection() {
|
|
|
644
644
|
return boundConnectionHolder.connection;
|
|
645
645
|
}
|
|
646
646
|
|
|
647
|
-
// ../../src/core/
|
|
647
|
+
// ../../src/core/runtime/asyncContextStore.ts
|
|
648
648
|
import { AsyncLocalStorage } from "async_hooks";
|
|
649
|
-
|
|
649
|
+
function createAsyncContextStore(key) {
|
|
650
|
+
const symbol = Symbol.for(key);
|
|
651
|
+
const globalRecord = globalThis;
|
|
652
|
+
const existing = globalRecord[symbol];
|
|
653
|
+
if (existing) {
|
|
654
|
+
return existing;
|
|
655
|
+
}
|
|
656
|
+
const store = new AsyncLocalStorage;
|
|
657
|
+
globalRecord[symbol] = store;
|
|
658
|
+
return store;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// ../../src/core/database/connectionContext.ts
|
|
662
|
+
var activeConnection = createAsyncContextStore("@getstrata/databaseConnectionContext");
|
|
650
663
|
function getActiveDatabaseConnection(fallback) {
|
|
651
664
|
return activeConnection.getStore() ?? fallback;
|
|
652
665
|
}
|
|
@@ -658,9 +658,22 @@ function getBoundDatabaseConnection() {
|
|
|
658
658
|
return boundConnectionHolder.connection;
|
|
659
659
|
}
|
|
660
660
|
|
|
661
|
-
// ../../src/core/
|
|
661
|
+
// ../../src/core/runtime/asyncContextStore.ts
|
|
662
662
|
import { AsyncLocalStorage } from "async_hooks";
|
|
663
|
-
|
|
663
|
+
function createAsyncContextStore(key) {
|
|
664
|
+
const symbol = Symbol.for(key);
|
|
665
|
+
const globalRecord = globalThis;
|
|
666
|
+
const existing = globalRecord[symbol];
|
|
667
|
+
if (existing) {
|
|
668
|
+
return existing;
|
|
669
|
+
}
|
|
670
|
+
const store = new AsyncLocalStorage;
|
|
671
|
+
globalRecord[symbol] = store;
|
|
672
|
+
return store;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// ../../src/core/database/connectionContext.ts
|
|
676
|
+
var activeConnection = createAsyncContextStore("@getstrata/databaseConnectionContext");
|
|
664
677
|
function getActiveDatabaseConnection(fallback) {
|
|
665
678
|
return activeConnection.getStore() ?? fallback;
|
|
666
679
|
}
|
|
@@ -2474,12 +2487,24 @@ function getRequiredDependency(dependencies, key) {
|
|
|
2474
2487
|
}
|
|
2475
2488
|
|
|
2476
2489
|
// ../../src/bootstrap/applicationRegistry.ts
|
|
2490
|
+
var APPLICATION_CONTEXT_KEY = Symbol.for("@getstrata/applicationContext");
|
|
2477
2491
|
var activeContext;
|
|
2492
|
+
function readStoredApplicationContext() {
|
|
2493
|
+
if (activeContext) {
|
|
2494
|
+
return activeContext;
|
|
2495
|
+
}
|
|
2496
|
+
const globalContext = globalThis[APPLICATION_CONTEXT_KEY];
|
|
2497
|
+
if (globalContext) {
|
|
2498
|
+
activeContext = globalContext;
|
|
2499
|
+
}
|
|
2500
|
+
return activeContext;
|
|
2501
|
+
}
|
|
2478
2502
|
function requireActiveApplicationContext() {
|
|
2479
|
-
|
|
2503
|
+
const context = readStoredApplicationContext();
|
|
2504
|
+
if (!context) {
|
|
2480
2505
|
throw new Error("The application context has not been bootstrapped.");
|
|
2481
2506
|
}
|
|
2482
|
-
return
|
|
2507
|
+
return context;
|
|
2483
2508
|
}
|
|
2484
2509
|
function resolveApplicationCache() {
|
|
2485
2510
|
return getRequiredDependency(requireActiveApplicationContext().dependencies, "cache");
|
package/dist/entries/view.js
CHANGED
|
@@ -850,9 +850,22 @@ function getBoundDatabaseConnection() {
|
|
|
850
850
|
return boundConnectionHolder.connection;
|
|
851
851
|
}
|
|
852
852
|
|
|
853
|
-
// ../../src/core/
|
|
853
|
+
// ../../src/core/runtime/asyncContextStore.ts
|
|
854
854
|
import { AsyncLocalStorage } from "async_hooks";
|
|
855
|
-
|
|
855
|
+
function createAsyncContextStore(key) {
|
|
856
|
+
const symbol = Symbol.for(key);
|
|
857
|
+
const globalRecord = globalThis;
|
|
858
|
+
const existing = globalRecord[symbol];
|
|
859
|
+
if (existing) {
|
|
860
|
+
return existing;
|
|
861
|
+
}
|
|
862
|
+
const store = new AsyncLocalStorage;
|
|
863
|
+
globalRecord[symbol] = store;
|
|
864
|
+
return store;
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
// ../../src/core/database/connectionContext.ts
|
|
868
|
+
var activeConnection = createAsyncContextStore("@getstrata/databaseConnectionContext");
|
|
856
869
|
function getActiveDatabaseConnection(fallback) {
|
|
857
870
|
return activeConnection.getStore() ?? fallback;
|
|
858
871
|
}
|
|
@@ -2226,15 +2239,13 @@ function revealMfaSecret(stored) {
|
|
|
2226
2239
|
}
|
|
2227
2240
|
|
|
2228
2241
|
// ../../src/core/auth/authContext.ts
|
|
2229
|
-
|
|
2230
|
-
var authContext = new AsyncLocalStorage2;
|
|
2242
|
+
var authContext = createAsyncContextStore("@getstrata/authContext");
|
|
2231
2243
|
function currentAuthUser() {
|
|
2232
2244
|
return authContext.getStore() ?? null;
|
|
2233
2245
|
}
|
|
2234
2246
|
|
|
2235
2247
|
// ../../src/core/http/requestMetaContext.ts
|
|
2236
|
-
|
|
2237
|
-
var requestMetaContext = new AsyncLocalStorage3;
|
|
2248
|
+
var requestMetaContext = createAsyncContextStore("@getstrata/requestMetaContext");
|
|
2238
2249
|
function currentRequestMeta() {
|
|
2239
2250
|
return requestMetaContext.getStore() ?? {
|
|
2240
2251
|
ipAddress: null,
|
|
@@ -2318,8 +2329,7 @@ function verifyTotp(secret, token, window = 1) {
|
|
|
2318
2329
|
}
|
|
2319
2330
|
|
|
2320
2331
|
// ../../src/core/tenant/tenantContext.ts
|
|
2321
|
-
|
|
2322
|
-
var tenantContext = new AsyncLocalStorage4;
|
|
2332
|
+
var tenantContext = createAsyncContextStore("@getstrata/tenantContext");
|
|
2323
2333
|
function currentTenant() {
|
|
2324
2334
|
return tenantContext.getStore() ?? null;
|
|
2325
2335
|
}
|
|
@@ -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";
|
package/dist/index.js
CHANGED
|
@@ -118,15 +118,28 @@ function resolveService(dependencies, token) {
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
// ../../src/bootstrap/applicationRegistry.ts
|
|
121
|
+
var APPLICATION_CONTEXT_KEY = Symbol.for("@getstrata/applicationContext");
|
|
121
122
|
var activeContext;
|
|
123
|
+
function readStoredApplicationContext() {
|
|
124
|
+
if (activeContext) {
|
|
125
|
+
return activeContext;
|
|
126
|
+
}
|
|
127
|
+
const globalContext = globalThis[APPLICATION_CONTEXT_KEY];
|
|
128
|
+
if (globalContext) {
|
|
129
|
+
activeContext = globalContext;
|
|
130
|
+
}
|
|
131
|
+
return activeContext;
|
|
132
|
+
}
|
|
122
133
|
function setActiveApplicationContext(context) {
|
|
123
134
|
activeContext = context;
|
|
135
|
+
globalThis[APPLICATION_CONTEXT_KEY] = context;
|
|
124
136
|
}
|
|
125
137
|
function requireActiveApplicationContext() {
|
|
126
|
-
|
|
138
|
+
const context = readStoredApplicationContext();
|
|
139
|
+
if (!context) {
|
|
127
140
|
throw new Error("The application context has not been bootstrapped.");
|
|
128
141
|
}
|
|
129
|
-
return
|
|
142
|
+
return context;
|
|
130
143
|
}
|
|
131
144
|
function resolveApplicationCache() {
|
|
132
145
|
return getRequiredDependency(requireActiveApplicationContext().dependencies, "cache");
|
|
@@ -271,9 +284,22 @@ class PreconditionFailedError extends HttpError {
|
|
|
271
284
|
}
|
|
272
285
|
}
|
|
273
286
|
|
|
274
|
-
// ../../src/core/
|
|
287
|
+
// ../../src/core/runtime/asyncContextStore.ts
|
|
275
288
|
import { AsyncLocalStorage } from "async_hooks";
|
|
276
|
-
|
|
289
|
+
function createAsyncContextStore(key) {
|
|
290
|
+
const symbol = Symbol.for(key);
|
|
291
|
+
const globalRecord = globalThis;
|
|
292
|
+
const existing = globalRecord[symbol];
|
|
293
|
+
if (existing) {
|
|
294
|
+
return existing;
|
|
295
|
+
}
|
|
296
|
+
const store = new AsyncLocalStorage;
|
|
297
|
+
globalRecord[symbol] = store;
|
|
298
|
+
return store;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// ../../src/core/auth/authContext.ts
|
|
302
|
+
var authContext = createAsyncContextStore("@getstrata/authContext");
|
|
277
303
|
function runWithAuthUser(user, callback) {
|
|
278
304
|
return authContext.run(user, callback);
|
|
279
305
|
}
|
|
@@ -1029,8 +1055,7 @@ function resetBoundDatabaseConnection() {
|
|
|
1029
1055
|
}
|
|
1030
1056
|
|
|
1031
1057
|
// ../../src/core/database/connectionContext.ts
|
|
1032
|
-
|
|
1033
|
-
var activeConnection = new AsyncLocalStorage2;
|
|
1058
|
+
var activeConnection = createAsyncContextStore("@getstrata/databaseConnectionContext");
|
|
1034
1059
|
function runWithDatabaseConnection(connection, callback) {
|
|
1035
1060
|
return activeConnection.run(connection, callback);
|
|
1036
1061
|
}
|
|
@@ -2752,8 +2777,7 @@ function revealMfaSecret(stored) {
|
|
|
2752
2777
|
}
|
|
2753
2778
|
|
|
2754
2779
|
// ../../src/core/http/requestMetaContext.ts
|
|
2755
|
-
|
|
2756
|
-
var requestMetaContext = new AsyncLocalStorage3;
|
|
2780
|
+
var requestMetaContext = createAsyncContextStore("@getstrata/requestMetaContext");
|
|
2757
2781
|
function runWithRequestMeta(meta, callback) {
|
|
2758
2782
|
return requestMetaContext.run(meta, callback);
|
|
2759
2783
|
}
|
|
@@ -2840,8 +2864,7 @@ function verifyTotp(secret, token, window = 1) {
|
|
|
2840
2864
|
}
|
|
2841
2865
|
|
|
2842
2866
|
// ../../src/core/tenant/tenantContext.ts
|
|
2843
|
-
|
|
2844
|
-
var tenantContext = new AsyncLocalStorage4;
|
|
2867
|
+
var tenantContext = createAsyncContextStore("@getstrata/tenantContext");
|
|
2845
2868
|
function runWithTenant(tenant, callback) {
|
|
2846
2869
|
return tenantContext.run(tenant, callback);
|
|
2847
2870
|
}
|
|
@@ -3098,9 +3121,6 @@ class AuthManager {
|
|
|
3098
3121
|
return user;
|
|
3099
3122
|
}
|
|
3100
3123
|
}
|
|
3101
|
-
// ../../src/core/auth/membershipContext.ts
|
|
3102
|
-
import { AsyncLocalStorage as AsyncLocalStorage5 } from "async_hooks";
|
|
3103
|
-
|
|
3104
3124
|
// ../../src/modules/organization/memberRepository.ts
|
|
3105
3125
|
class OrganizationMemberRepository {
|
|
3106
3126
|
constructor() {}
|
|
@@ -3153,7 +3173,7 @@ class OrganizationMemberRepository {
|
|
|
3153
3173
|
var memberRepository_default = OrganizationMemberRepository;
|
|
3154
3174
|
|
|
3155
3175
|
// ../../src/core/auth/membershipContext.ts
|
|
3156
|
-
var membershipContext =
|
|
3176
|
+
var membershipContext = createAsyncContextStore("@getstrata/membershipContext");
|
|
3157
3177
|
var membershipRepository = new memberRepository_default;
|
|
3158
3178
|
async function runWithMembershipContext(callback) {
|
|
3159
3179
|
const user = currentAuthUser();
|
|
@@ -3900,6 +3920,23 @@ function createCacheStore(options) {
|
|
|
3900
3920
|
}
|
|
3901
3921
|
return new simpleCacheStore_default(new simpleCache_default(options.ttlMs, options.maxEntries));
|
|
3902
3922
|
}
|
|
3923
|
+
// ../../src/bootstrap/discoverModules.ts
|
|
3924
|
+
var appModules = [];
|
|
3925
|
+
function discoverModules() {
|
|
3926
|
+
return appModules;
|
|
3927
|
+
}
|
|
3928
|
+
|
|
3929
|
+
// ../../src/bootstrap/cache/modelCacheTags.ts
|
|
3930
|
+
function cacheTagsForModelWrite(tableName, action) {
|
|
3931
|
+
const module = discoverModules().find((entry) => entry.tableName === tableName);
|
|
3932
|
+
const baseTags = module?.cacheTags ?? [`${tableName}s`];
|
|
3933
|
+
const isDelete = action === "deleted" || action === "force-deleted";
|
|
3934
|
+
const extraTags = isDelete ? module?.cacheDeleteExtraTags ?? [] : [];
|
|
3935
|
+
return [...new Set([...baseTags, ...extraTags])];
|
|
3936
|
+
}
|
|
3937
|
+
function discoverModelTableNames() {
|
|
3938
|
+
return discoverModules().map((module) => module.tableName).filter((tableName) => tableName !== undefined);
|
|
3939
|
+
}
|
|
3903
3940
|
// ../../src/core/cache/taggedCache.ts
|
|
3904
3941
|
class TaggedCache {
|
|
3905
3942
|
store;
|
|
@@ -6504,8 +6541,7 @@ function createTenantMiddleware() {
|
|
|
6504
6541
|
};
|
|
6505
6542
|
}
|
|
6506
6543
|
// ../../src/core/tracing/traceContext.ts
|
|
6507
|
-
|
|
6508
|
-
var traceContextStorage = new AsyncLocalStorage6;
|
|
6544
|
+
var traceContextStorage = createAsyncContextStore("@getstrata/traceContext");
|
|
6509
6545
|
function runWithTraceContext(context, callback) {
|
|
6510
6546
|
return traceContextStorage.run(context, callback);
|
|
6511
6547
|
}
|
|
@@ -6785,6 +6821,7 @@ export {
|
|
|
6785
6821
|
etagFromResource,
|
|
6786
6822
|
emptyPaginateResult,
|
|
6787
6823
|
emailRule,
|
|
6824
|
+
discoverModelTableNames,
|
|
6788
6825
|
dehydrateValue,
|
|
6789
6826
|
defineTable,
|
|
6790
6827
|
currentTraceId,
|
|
@@ -6834,6 +6871,7 @@ export {
|
|
|
6834
6871
|
composeMiddleware,
|
|
6835
6872
|
compileBlueprint,
|
|
6836
6873
|
collectQueueMetrics,
|
|
6874
|
+
cacheTagsForModelWrite,
|
|
6837
6875
|
cache,
|
|
6838
6876
|
buildSmtpPayload,
|
|
6839
6877
|
buildRequestCacheKey,
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { appModules, discoverModules } from "./discoverModules";
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
interface RegisteredRoute {
|
|
2
|
-
method: string;
|
|
3
|
-
path: string;
|
|
4
|
-
middleware: string[];
|
|
5
|
-
}
|
|
6
|
-
declare class RouteRegistry {
|
|
7
|
-
private readonly routes;
|
|
8
|
-
register(route: RegisteredRoute): void;
|
|
9
|
-
clear(): void;
|
|
10
|
-
list(): RegisteredRoute[];
|
|
11
|
-
}
|
|
12
|
-
declare const routeRegistry: RouteRegistry;
|
|
13
|
-
export type { RegisteredRoute };
|
|
14
|
-
export { RouteRegistry, routeRegistry };
|