@getstrata/core 0.5.18 → 0.5.21
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/applicationRegistry.d.ts +1 -16
- package/dist/bootstrap/cache/modelCacheTags.d.ts +3 -0
- package/dist/bootstrap/config.d.ts +2 -7
- package/dist/bootstrap/discoverModules.d.ts +3 -2
- 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/applicationContext.d.ts +18 -0
- package/dist/core/contracts/serviceContainer.d.ts +5 -0
- package/dist/core/contracts/serviceTokens.d.ts +7 -0
- package/dist/core/openapi/generator.d.ts +1 -1
- package/dist/core/openapi/registeredRoute.d.ts +6 -0
- package/dist/core/runtime/applicationRegistry.d.ts +15 -0
- package/dist/core/view/webLayoutData.d.ts +2 -2
- package/dist/entries/http/webErrorResponse.js +2 -2
- package/dist/entries/queue/createAppQueue.js +234 -2655
- package/dist/entries/queue/jobRunner.js +2 -1
- package/dist/entries/queue/publicQueue.js +2 -1
- package/dist/entries/queue/queueMetrics.js +236 -2606
- package/dist/entries/runtime/applicationRegistry.js +1 -0
- package/dist/entries/view.js +2 -2
- package/dist/framework/public-api.d.ts +2 -1
- package/dist/index.js +117 -96
- package/package.json +6 -1
- package/dist/bootstrap/modules.d.ts +0 -1
- package/dist/bootstrap/routeRegistry.d.ts +0 -14
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../../index.js";
|
package/dist/entries/view.js
CHANGED
|
@@ -44,8 +44,9 @@ function htmlResponse(html, init = {}) {
|
|
|
44
44
|
function isHtmxRequest(request) {
|
|
45
45
|
return request.headers.get("HX-Request") === "true";
|
|
46
46
|
}
|
|
47
|
-
// ../../src/
|
|
47
|
+
// ../../src/core/contracts/serviceTokens.ts
|
|
48
48
|
var CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
|
|
49
|
+
// ../../src/bootstrap/config.ts
|
|
49
50
|
var DEFAULT_QUEUE_DRIVER = "sync";
|
|
50
51
|
|
|
51
52
|
// ../../src/core/auth/oauth/oidcProvider.ts
|
|
@@ -2108,7 +2109,6 @@ var db = new Proxy(function database() {}, {
|
|
|
2108
2109
|
return typeof value === "function" ? value.bind(connection) : value;
|
|
2109
2110
|
}
|
|
2110
2111
|
});
|
|
2111
|
-
var connection_default = db;
|
|
2112
2112
|
|
|
2113
2113
|
// ../../src/modules/user/apiTokenTable.ts
|
|
2114
2114
|
var apiTokenTable = defineTable({
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* Stable framework surface for application modules and future package extraction.
|
|
3
3
|
* Import from `@getstrata/core` (workspace) or `src/framework/public-api`.
|
|
4
4
|
*/
|
|
5
|
-
export { resolveApplicationAuth, resolveApplicationCache, resolveApplicationConfig, resolveApplicationDependencies, resolveApplicationLogger, resolveApplicationPolicyGate, resolveApplicationQueue, setActiveApplicationContext, } from "../bootstrap/applicationRegistry.ts";
|
|
6
5
|
export type { ServiceProvider } from "../bootstrap/contracts.ts";
|
|
7
6
|
export { ConfigStore, resolveService, ServiceContainer, } from "../bootstrap/contracts.ts";
|
|
8
7
|
export type { AdminColumn, AdminColumnType, AdminResource, AdminResourceDefinition, AdminResourceHandlers, } from "../core/admin/index.ts";
|
|
@@ -20,6 +19,7 @@ export { default as MembershipService, resolveMembershipService, } from "../core
|
|
|
20
19
|
export { Policy, PolicyGate } from "../core/auth/policy.ts";
|
|
21
20
|
export { createScimAuthMiddleware } from "../core/auth/scimAuthMiddleware.ts";
|
|
22
21
|
export { type CacheDriver, type CreateCacheStoreOptions, createCacheStore, } from "../core/cache/createCacheStore.ts";
|
|
22
|
+
export { cacheTagsForModelWrite, discoverModelTableNames } from "../core/cache/modelCacheTags.ts";
|
|
23
23
|
export { default as CacheRepository } from "../core/cache/repository.ts";
|
|
24
24
|
export { CACHE_TAGS } from "../core/cache/tags.ts";
|
|
25
25
|
export type { DatabaseConnection } from "../core/database/baseRepository.ts";
|
|
@@ -95,6 +95,7 @@ export { AsyncQueue, createQueue, Job, SyncQueue } from "../core/queue/index.ts"
|
|
|
95
95
|
export { createFailedJobService, createProductionQueue, createQueueWorker, createTrackedJob, FailedJobRepository, FailedJobService, jobRegistry, QueueWorker, RedisQueue, ResilientQueue, runQueueJob, } from "../core/queue/publicQueue.ts";
|
|
96
96
|
export type { QueueMetricsSnapshot } from "../core/queue/queueMetrics.ts";
|
|
97
97
|
export { collectQueueMetrics } from "../core/queue/queueMetrics.ts";
|
|
98
|
+
export { resolveApplicationAuth, resolveApplicationCache, resolveApplicationConfig, resolveApplicationDependencies, resolveApplicationLogger, resolveApplicationPolicyGate, resolveApplicationQueue, setActiveApplicationContext, } from "../core/runtime/applicationRegistry.ts";
|
|
98
99
|
export type { ScheduledTask } from "../core/scheduler/schedule.ts";
|
|
99
100
|
export { appSchedule, runDueScheduledTasks, Schedule } from "../core/scheduler/schedule.ts";
|
|
100
101
|
export { guestCanViewResource, isPublicReadsEnabled } from "../core/security/publicReads.ts";
|
package/dist/index.js
CHANGED
|
@@ -1,47 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
// ../../src/core/logging/logger.ts
|
|
3
|
-
class Logger {
|
|
4
|
-
channel;
|
|
5
|
-
constructor(channel = "app") {
|
|
6
|
-
this.channel = channel;
|
|
7
|
-
}
|
|
8
|
-
write(level, message, context = {}) {
|
|
9
|
-
const entry = {
|
|
10
|
-
level,
|
|
11
|
-
channel: this.channel,
|
|
12
|
-
message,
|
|
13
|
-
timestamp: new Date().toISOString(),
|
|
14
|
-
...context
|
|
15
|
-
};
|
|
16
|
-
const line = JSON.stringify(entry);
|
|
17
|
-
if (level === "error") {
|
|
18
|
-
console.error(line);
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
console.log(line);
|
|
22
|
-
}
|
|
23
|
-
debug(message, context) {
|
|
24
|
-
this.write("debug", message, context);
|
|
25
|
-
}
|
|
26
|
-
info(message, context) {
|
|
27
|
-
this.write("info", message, context);
|
|
28
|
-
}
|
|
29
|
-
warn(message, context) {
|
|
30
|
-
this.write("warn", message, context);
|
|
31
|
-
}
|
|
32
|
-
error(message, context) {
|
|
33
|
-
this.write("error", message, context);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
var appLogger = new Logger("app");
|
|
37
|
-
|
|
38
|
-
// ../../src/bootstrap/config.ts
|
|
39
|
-
var CORE_QUEUE_TOKEN = "core.queue";
|
|
40
|
-
var CORE_POLICY_GATE_TOKEN = "core.policyGate";
|
|
41
|
-
var CORE_AUTH_TOKEN = "core.auth";
|
|
42
|
-
var CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
|
|
43
|
-
var DEFAULT_QUEUE_DRIVER = "sync";
|
|
44
|
-
|
|
45
2
|
// ../../src/bootstrap/contracts.ts
|
|
46
3
|
class ServiceContainer {
|
|
47
4
|
services = new Map;
|
|
@@ -106,62 +63,9 @@ class ConfigStore {
|
|
|
106
63
|
return this.values.has(key);
|
|
107
64
|
}
|
|
108
65
|
}
|
|
109
|
-
function getRequiredDependency(dependencies, key) {
|
|
110
|
-
const dependency = dependencies[key];
|
|
111
|
-
if (dependency === undefined) {
|
|
112
|
-
throw new Error(`Required dependency "${key}" is not registered.`);
|
|
113
|
-
}
|
|
114
|
-
return dependency;
|
|
115
|
-
}
|
|
116
66
|
function resolveService(dependencies, token) {
|
|
117
67
|
return dependencies.container.resolve(token);
|
|
118
68
|
}
|
|
119
|
-
|
|
120
|
-
// ../../src/bootstrap/applicationRegistry.ts
|
|
121
|
-
var APPLICATION_CONTEXT_KEY = Symbol.for("@getstrata/applicationContext");
|
|
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
|
-
}
|
|
133
|
-
function setActiveApplicationContext(context) {
|
|
134
|
-
activeContext = context;
|
|
135
|
-
globalThis[APPLICATION_CONTEXT_KEY] = context;
|
|
136
|
-
}
|
|
137
|
-
function requireActiveApplicationContext() {
|
|
138
|
-
const context = readStoredApplicationContext();
|
|
139
|
-
if (!context) {
|
|
140
|
-
throw new Error("The application context has not been bootstrapped.");
|
|
141
|
-
}
|
|
142
|
-
return context;
|
|
143
|
-
}
|
|
144
|
-
function resolveApplicationCache() {
|
|
145
|
-
return getRequiredDependency(requireActiveApplicationContext().dependencies, "cache");
|
|
146
|
-
}
|
|
147
|
-
function resolveApplicationQueue() {
|
|
148
|
-
return requireActiveApplicationContext().container.resolve(CORE_QUEUE_TOKEN);
|
|
149
|
-
}
|
|
150
|
-
function resolveApplicationAuth() {
|
|
151
|
-
return requireActiveApplicationContext().container.resolve(CORE_AUTH_TOKEN);
|
|
152
|
-
}
|
|
153
|
-
function resolveApplicationPolicyGate() {
|
|
154
|
-
return requireActiveApplicationContext().container.resolve(CORE_POLICY_GATE_TOKEN);
|
|
155
|
-
}
|
|
156
|
-
function resolveApplicationConfig() {
|
|
157
|
-
return requireActiveApplicationContext().config;
|
|
158
|
-
}
|
|
159
|
-
function resolveApplicationLogger() {
|
|
160
|
-
return appLogger;
|
|
161
|
-
}
|
|
162
|
-
function resolveApplicationDependencies() {
|
|
163
|
-
return requireActiveApplicationContext().dependencies;
|
|
164
|
-
}
|
|
165
69
|
// ../../src/core/admin/formatValue.ts
|
|
166
70
|
function formatAdminValue(value, type = "text") {
|
|
167
71
|
if (value === null || value === undefined) {
|
|
@@ -367,6 +271,14 @@ function resolveAbilitiesForRole(role) {
|
|
|
367
271
|
return [...MEMBER_ABILITIES];
|
|
368
272
|
}
|
|
369
273
|
|
|
274
|
+
// ../../src/core/contracts/serviceTokens.ts
|
|
275
|
+
var CORE_QUEUE_TOKEN = "core.queue";
|
|
276
|
+
var CORE_POLICY_GATE_TOKEN = "core.policyGate";
|
|
277
|
+
var CORE_AUTH_TOKEN = "core.auth";
|
|
278
|
+
var CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
|
|
279
|
+
// ../../src/bootstrap/config.ts
|
|
280
|
+
var DEFAULT_QUEUE_DRIVER = "sync";
|
|
281
|
+
|
|
370
282
|
// ../../src/config/features.ts
|
|
371
283
|
function readFeatureFlags() {
|
|
372
284
|
return {
|
|
@@ -3309,6 +3221,96 @@ function assertOrganizationReadable(organizationId) {
|
|
|
3309
3221
|
throw new NotFoundError(`Organization ${organizationId} not found.`);
|
|
3310
3222
|
}
|
|
3311
3223
|
}
|
|
3224
|
+
// ../../src/core/contracts/applicationContext.ts
|
|
3225
|
+
function getRequiredDependency(dependencies, key) {
|
|
3226
|
+
const dependency = dependencies[key];
|
|
3227
|
+
if (dependency === undefined) {
|
|
3228
|
+
throw new Error(`Required dependency "${String(key)}" is not registered.`);
|
|
3229
|
+
}
|
|
3230
|
+
return dependency;
|
|
3231
|
+
}
|
|
3232
|
+
|
|
3233
|
+
// ../../src/core/logging/logger.ts
|
|
3234
|
+
class Logger {
|
|
3235
|
+
channel;
|
|
3236
|
+
constructor(channel = "app") {
|
|
3237
|
+
this.channel = channel;
|
|
3238
|
+
}
|
|
3239
|
+
write(level, message, context = {}) {
|
|
3240
|
+
const entry = {
|
|
3241
|
+
level,
|
|
3242
|
+
channel: this.channel,
|
|
3243
|
+
message,
|
|
3244
|
+
timestamp: new Date().toISOString(),
|
|
3245
|
+
...context
|
|
3246
|
+
};
|
|
3247
|
+
const line = JSON.stringify(entry);
|
|
3248
|
+
if (level === "error") {
|
|
3249
|
+
console.error(line);
|
|
3250
|
+
return;
|
|
3251
|
+
}
|
|
3252
|
+
console.log(line);
|
|
3253
|
+
}
|
|
3254
|
+
debug(message, context) {
|
|
3255
|
+
this.write("debug", message, context);
|
|
3256
|
+
}
|
|
3257
|
+
info(message, context) {
|
|
3258
|
+
this.write("info", message, context);
|
|
3259
|
+
}
|
|
3260
|
+
warn(message, context) {
|
|
3261
|
+
this.write("warn", message, context);
|
|
3262
|
+
}
|
|
3263
|
+
error(message, context) {
|
|
3264
|
+
this.write("error", message, context);
|
|
3265
|
+
}
|
|
3266
|
+
}
|
|
3267
|
+
var appLogger = new Logger("app");
|
|
3268
|
+
|
|
3269
|
+
// ../../src/core/runtime/applicationRegistry.ts
|
|
3270
|
+
var APPLICATION_CONTEXT_KEY = Symbol.for("@getstrata/applicationContext");
|
|
3271
|
+
var activeContext;
|
|
3272
|
+
function readStoredApplicationContext() {
|
|
3273
|
+
if (activeContext) {
|
|
3274
|
+
return activeContext;
|
|
3275
|
+
}
|
|
3276
|
+
const globalContext = globalThis[APPLICATION_CONTEXT_KEY];
|
|
3277
|
+
if (globalContext) {
|
|
3278
|
+
activeContext = globalContext;
|
|
3279
|
+
}
|
|
3280
|
+
return activeContext;
|
|
3281
|
+
}
|
|
3282
|
+
function setActiveApplicationContext(context) {
|
|
3283
|
+
activeContext = context;
|
|
3284
|
+
globalThis[APPLICATION_CONTEXT_KEY] = context;
|
|
3285
|
+
}
|
|
3286
|
+
function requireActiveApplicationContext() {
|
|
3287
|
+
const context = readStoredApplicationContext();
|
|
3288
|
+
if (!context) {
|
|
3289
|
+
throw new Error("The application context has not been bootstrapped.");
|
|
3290
|
+
}
|
|
3291
|
+
return context;
|
|
3292
|
+
}
|
|
3293
|
+
function resolveApplicationCache() {
|
|
3294
|
+
return getRequiredDependency(requireActiveApplicationContext().dependencies, "cache");
|
|
3295
|
+
}
|
|
3296
|
+
function resolveApplicationQueue() {
|
|
3297
|
+
return requireActiveApplicationContext().container.resolve(CORE_QUEUE_TOKEN);
|
|
3298
|
+
}
|
|
3299
|
+
function resolveApplicationAuth() {
|
|
3300
|
+
return requireActiveApplicationContext().container.resolve(CORE_AUTH_TOKEN);
|
|
3301
|
+
}
|
|
3302
|
+
function resolveApplicationPolicyGate() {
|
|
3303
|
+
return requireActiveApplicationContext().container.resolve(CORE_POLICY_GATE_TOKEN);
|
|
3304
|
+
}
|
|
3305
|
+
function resolveApplicationConfig() {
|
|
3306
|
+
return requireActiveApplicationContext().config;
|
|
3307
|
+
}
|
|
3308
|
+
function resolveApplicationLogger() {
|
|
3309
|
+
return appLogger;
|
|
3310
|
+
}
|
|
3311
|
+
function resolveApplicationDependencies() {
|
|
3312
|
+
return requireActiveApplicationContext().dependencies;
|
|
3313
|
+
}
|
|
3312
3314
|
// ../../src/bootstrap/membershipService.ts
|
|
3313
3315
|
function resolveMembershipService() {
|
|
3314
3316
|
const dependencies = resolveApplicationDependencies();
|
|
@@ -3920,6 +3922,23 @@ function createCacheStore(options) {
|
|
|
3920
3922
|
}
|
|
3921
3923
|
return new simpleCacheStore_default(new simpleCache_default(options.ttlMs, options.maxEntries));
|
|
3922
3924
|
}
|
|
3925
|
+
// ../../src/bootstrap/discoverModules.ts
|
|
3926
|
+
var appModules = [];
|
|
3927
|
+
function discoverModules() {
|
|
3928
|
+
return appModules;
|
|
3929
|
+
}
|
|
3930
|
+
|
|
3931
|
+
// ../../src/bootstrap/cache/modelCacheTags.ts
|
|
3932
|
+
function cacheTagsForModelWrite(tableName, action) {
|
|
3933
|
+
const module = discoverModules().find((entry) => entry.tableName === tableName);
|
|
3934
|
+
const baseTags = module?.cacheTags ?? [`${tableName}s`];
|
|
3935
|
+
const isDelete = action === "deleted" || action === "force-deleted";
|
|
3936
|
+
const extraTags = isDelete ? module?.cacheDeleteExtraTags ?? [] : [];
|
|
3937
|
+
return [...new Set([...baseTags, ...extraTags])];
|
|
3938
|
+
}
|
|
3939
|
+
function discoverModelTableNames() {
|
|
3940
|
+
return discoverModules().map((module) => module.tableName).filter((tableName) => tableName !== undefined);
|
|
3941
|
+
}
|
|
3923
3942
|
// ../../src/core/cache/taggedCache.ts
|
|
3924
3943
|
class TaggedCache {
|
|
3925
3944
|
store;
|
|
@@ -6804,6 +6823,7 @@ export {
|
|
|
6804
6823
|
etagFromResource,
|
|
6805
6824
|
emptyPaginateResult,
|
|
6806
6825
|
emailRule,
|
|
6826
|
+
discoverModelTableNames,
|
|
6807
6827
|
dehydrateValue,
|
|
6808
6828
|
defineTable,
|
|
6809
6829
|
currentTraceId,
|
|
@@ -6853,6 +6873,7 @@ export {
|
|
|
6853
6873
|
composeMiddleware,
|
|
6854
6874
|
compileBlueprint,
|
|
6855
6875
|
collectQueueMetrics,
|
|
6876
|
+
cacheTagsForModelWrite,
|
|
6856
6877
|
cache,
|
|
6857
6878
|
buildSmtpPayload,
|
|
6858
6879
|
buildRequestCacheKey,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getstrata/core",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.21",
|
|
4
4
|
"description": "Strata — Laravel-inspired Bun framework public API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -240,6 +240,11 @@
|
|
|
240
240
|
"import": "./dist/entries/queue/types.js",
|
|
241
241
|
"default": "./dist/entries/queue/types.js"
|
|
242
242
|
},
|
|
243
|
+
"./runtime/applicationRegistry": {
|
|
244
|
+
"types": "./dist/core/runtime/applicationRegistry.d.ts",
|
|
245
|
+
"import": "./dist/entries/runtime/applicationRegistry.js",
|
|
246
|
+
"default": "./dist/entries/runtime/applicationRegistry.js"
|
|
247
|
+
},
|
|
243
248
|
"./security/oauthState": {
|
|
244
249
|
"types": "./dist/core/security/oauthState.d.ts",
|
|
245
250
|
"import": "./dist/entries/security/oauthState.js",
|
|
@@ -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 };
|