@getstrata/bootstrap 0.2.16 → 0.2.18
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/contracts.d.ts +6 -50
- package/dist/core/contracts/applicationContext.d.ts +7 -18
- package/dist/core/contracts/container.d.ts +30 -0
- package/dist/core/contracts/di.d.ts +31 -0
- package/dist/core/contracts/serviceContainer.d.ts +1 -5
- package/dist/core/runtime/applicationRegistry.d.ts +2 -2
- package/dist/entries/applicationRegistry.js +15 -3
- package/dist/entries/cache/modelCacheTags.js +22 -0
- package/dist/entries/context.js +16 -25
- package/dist/entries/contracts.js +2 -1
- package/dist/entries/http/securedRouteModelBinding.js +15 -3
- package/dist/entries/membershipService.js +15 -3
- package/dist/entries/providers.js +15 -3
- package/dist/entries/queue/defaultJobs.js +15 -3
- package/dist/entries/web/forms.js +53 -0
- package/dist/entries/web/routing.js +636 -0
- package/dist/entries/web/server.js +57 -0
- package/dist/entries/web/session.js +99 -0
- package/dist/entries/web/slug.js +8 -0
- package/dist/framework/public-api.d.ts +3 -2
- package/dist/index.js +17 -25
- package/package.json +33 -3
|
@@ -1,48 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type
|
|
5
|
-
type
|
|
6
|
-
declare class ServiceContainer {
|
|
7
|
-
private readonly services;
|
|
8
|
-
private readonly singletonFactories;
|
|
9
|
-
private readonly bindings;
|
|
10
|
-
set<T>(key: string, value: T): T;
|
|
11
|
-
singleton<T>(key: string, factory: ServiceFactory<T>): void;
|
|
12
|
-
bind<T>(key: string, factory: ServiceFactory<T>): void;
|
|
13
|
-
get<T>(key: string): T;
|
|
14
|
-
resolve<T>(key: string): T;
|
|
15
|
-
has(key: string): boolean;
|
|
16
|
-
}
|
|
17
|
-
declare class ConfigStore {
|
|
18
|
-
private readonly values;
|
|
19
|
-
set<T>(key: string, value: T): T;
|
|
20
|
-
get<T>(key: string): T | undefined;
|
|
21
|
-
require<T>(key: string): T;
|
|
22
|
-
has(key: string): boolean;
|
|
23
|
-
}
|
|
24
|
-
interface AppDependencies {
|
|
25
|
-
container: ServiceContainer;
|
|
26
|
-
cache: CacheLike;
|
|
27
|
-
storage: StorageManager;
|
|
28
|
-
}
|
|
29
|
-
type MutableAppDependencies = Partial<Omit<AppDependencies, "container">> & Pick<AppDependencies, "container">;
|
|
30
|
-
interface ProviderContext {
|
|
31
|
-
container: ServiceContainer;
|
|
32
|
-
config: ConfigStore;
|
|
33
|
-
dependencies: MutableAppDependencies;
|
|
34
|
-
}
|
|
35
|
-
import type { HttpKernel } from "./httpKernel";
|
|
1
|
+
export { ConfigStore, type ConfigStoreLike, ServiceContainer, type ServiceContainerLike, } from "../core/contracts/container.ts";
|
|
2
|
+
export type { AppContext, AppDependencies, AppRouteMap, CachedJson, MutableAppDependencies, ProviderContext, ServiceFactory, ServiceProvider, } from "../core/contracts/di.ts";
|
|
3
|
+
export { assertAppDependenciesComplete, getRequiredDependency, resolveService, } from "../core/contracts/di.ts";
|
|
4
|
+
import type { AppDependencies, AppRouteMap, CachedJson, ServiceProvider } from "../core/contracts/di.ts";
|
|
5
|
+
import type { HttpKernel } from "./httpKernel.ts";
|
|
36
6
|
interface ModuleRouteContext {
|
|
37
7
|
dependencies: AppDependencies;
|
|
38
8
|
cachedJson: CachedJson;
|
|
39
9
|
kernel: HttpKernel;
|
|
40
10
|
}
|
|
41
|
-
interface ServiceProvider {
|
|
42
|
-
name: string;
|
|
43
|
-
register?(context: ProviderContext): void;
|
|
44
|
-
boot?(context: ProviderContext): void;
|
|
45
|
-
}
|
|
46
11
|
interface AppModule {
|
|
47
12
|
name: string;
|
|
48
13
|
order?: number;
|
|
@@ -53,13 +18,4 @@ interface AppModule {
|
|
|
53
18
|
routes?(context: ModuleRouteContext): AppRouteMap;
|
|
54
19
|
webRoutes?(context: ModuleRouteContext): AppRouteMap;
|
|
55
20
|
}
|
|
56
|
-
|
|
57
|
-
container: ServiceContainer;
|
|
58
|
-
config: ConfigStore;
|
|
59
|
-
dependencies: AppDependencies;
|
|
60
|
-
}
|
|
61
|
-
declare function getRequiredDependency<K extends keyof AppDependencies>(dependencies: Partial<AppDependencies>, key: K): AppDependencies[K];
|
|
62
|
-
declare function assertAppDependenciesComplete(dependencies: MutableAppDependencies): asserts dependencies is AppDependencies;
|
|
63
|
-
declare function resolveService<T>(dependencies: AppDependencies, token: string): T;
|
|
64
|
-
export type { AppContext, AppDependencies, AppModule, AppRouteMap, CachedJson, ModuleRouteContext, MutableAppDependencies, ProviderContext, ServiceFactory, ServiceProvider, };
|
|
65
|
-
export { assertAppDependenciesComplete, ConfigStore, getRequiredDependency, resolveService, ServiceContainer, };
|
|
21
|
+
export type { AppModule, ModuleRouteContext };
|
|
@@ -1,18 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
cache: CacheLike;
|
|
9
|
-
storage?: unknown;
|
|
10
|
-
}
|
|
11
|
-
interface ApplicationContext {
|
|
12
|
-
container: ServiceContainerLike;
|
|
13
|
-
config: ConfigStoreLike;
|
|
14
|
-
dependencies: ApplicationDependenciesLike;
|
|
15
|
-
}
|
|
16
|
-
declare function getRequiredDependency<K extends keyof ApplicationDependenciesLike>(dependencies: Partial<ApplicationDependenciesLike>, key: K): ApplicationDependenciesLike[K];
|
|
17
|
-
export type { ApplicationContext, ApplicationDependenciesLike, ConfigStoreLike };
|
|
18
|
-
export { getRequiredDependency };
|
|
1
|
+
import type { AppContext, AppDependencies } from "./di";
|
|
2
|
+
/** @deprecated Use AppContext from @getstrata/core/contracts/di */
|
|
3
|
+
type ApplicationContext = AppContext;
|
|
4
|
+
/** @deprecated Use AppDependencies from @getstrata/core/contracts/di */
|
|
5
|
+
type ApplicationDependenciesLike = AppDependencies;
|
|
6
|
+
export { getRequiredDependency } from "./di";
|
|
7
|
+
export type { ApplicationContext, ApplicationDependenciesLike };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
type ServiceFactory<T> = (container: ServiceContainer) => T;
|
|
2
|
+
interface ServiceContainerLike {
|
|
3
|
+
has(key: string): boolean;
|
|
4
|
+
resolve<T>(key: string): T;
|
|
5
|
+
}
|
|
6
|
+
declare class ServiceContainer implements ServiceContainerLike {
|
|
7
|
+
private readonly services;
|
|
8
|
+
private readonly singletonFactories;
|
|
9
|
+
private readonly bindings;
|
|
10
|
+
set<T>(key: string, value: T): T;
|
|
11
|
+
singleton<T>(key: string, factory: ServiceFactory<T>): void;
|
|
12
|
+
bind<T>(key: string, factory: ServiceFactory<T>): void;
|
|
13
|
+
get<T>(key: string): T;
|
|
14
|
+
resolve<T>(key: string): T;
|
|
15
|
+
has(key: string): boolean;
|
|
16
|
+
}
|
|
17
|
+
interface ConfigStoreLike {
|
|
18
|
+
get<T>(key: string): T | undefined;
|
|
19
|
+
require<T>(key: string): T;
|
|
20
|
+
has(key: string): boolean;
|
|
21
|
+
}
|
|
22
|
+
declare class ConfigStore implements ConfigStoreLike {
|
|
23
|
+
private readonly values;
|
|
24
|
+
set<T>(key: string, value: T): T;
|
|
25
|
+
get<T>(key: string): T | undefined;
|
|
26
|
+
require<T>(key: string): T;
|
|
27
|
+
has(key: string): boolean;
|
|
28
|
+
}
|
|
29
|
+
export type { ConfigStoreLike, ServiceContainerLike, ServiceFactory };
|
|
30
|
+
export { ConfigStore, ServiceContainer };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { CacheLike } from "../../types/services";
|
|
2
|
+
import type { StorageManager } from "../storage/storage";
|
|
3
|
+
import type { ConfigStore, ConfigStoreLike, ServiceContainer, ServiceFactory } from "./container";
|
|
4
|
+
type AppRouteMap = Record<string, any>;
|
|
5
|
+
type CachedJson = <T>(cacheKey: string, loader: () => Promise<T>, tags?: string[], request?: Request) => Promise<Response>;
|
|
6
|
+
interface AppDependencies {
|
|
7
|
+
container: ServiceContainer;
|
|
8
|
+
cache: CacheLike;
|
|
9
|
+
storage: StorageManager;
|
|
10
|
+
}
|
|
11
|
+
type MutableAppDependencies = Partial<Omit<AppDependencies, "container">> & Pick<AppDependencies, "container">;
|
|
12
|
+
interface ProviderContext {
|
|
13
|
+
container: ServiceContainer;
|
|
14
|
+
config: ConfigStore;
|
|
15
|
+
dependencies: MutableAppDependencies;
|
|
16
|
+
}
|
|
17
|
+
interface ServiceProvider {
|
|
18
|
+
name: string;
|
|
19
|
+
register?(context: ProviderContext): void;
|
|
20
|
+
boot?(context: ProviderContext): void;
|
|
21
|
+
}
|
|
22
|
+
interface AppContext {
|
|
23
|
+
container: ServiceContainer;
|
|
24
|
+
config: ConfigStoreLike;
|
|
25
|
+
dependencies: AppDependencies;
|
|
26
|
+
}
|
|
27
|
+
declare function getRequiredDependency<K extends keyof AppDependencies>(dependencies: Partial<AppDependencies>, key: K): AppDependencies[K];
|
|
28
|
+
declare function assertAppDependenciesComplete(dependencies: MutableAppDependencies): asserts dependencies is AppDependencies;
|
|
29
|
+
declare function resolveService<T>(dependencies: AppDependencies, token: string): T;
|
|
30
|
+
export type { AppContext, AppDependencies, AppRouteMap, CachedJson, MutableAppDependencies, ProviderContext, ServiceFactory, ServiceProvider, };
|
|
31
|
+
export { assertAppDependenciesComplete, getRequiredDependency, resolveService };
|
|
@@ -9,7 +9,7 @@ declare function resolveApplicationCache(): CacheLike;
|
|
|
9
9
|
declare function resolveApplicationQueue(): Queue;
|
|
10
10
|
declare function resolveApplicationAuth(): AuthManager;
|
|
11
11
|
declare function resolveApplicationPolicyGate(): PolicyGate;
|
|
12
|
-
declare function resolveApplicationConfig(): import("../contracts/
|
|
12
|
+
declare function resolveApplicationConfig(): import("../contracts/container").ConfigStoreLike;
|
|
13
13
|
declare function resolveApplicationLogger(): Logger;
|
|
14
|
-
declare function resolveApplicationDependencies(): import("../contracts/
|
|
14
|
+
declare function resolveApplicationDependencies(): import("../contracts/di").AppDependencies;
|
|
15
15
|
export { resolveApplicationAuth, resolveApplicationCache, resolveApplicationConfig, resolveApplicationDependencies, resolveApplicationLogger, resolveApplicationPolicyGate, resolveApplicationQueue, setActiveApplicationContext, };
|
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
// ../../src/core/contracts/
|
|
2
|
+
// ../../src/core/contracts/di.ts
|
|
3
|
+
var requiredDependencyKeys = [
|
|
4
|
+
"container",
|
|
5
|
+
"cache",
|
|
6
|
+
"storage"
|
|
7
|
+
];
|
|
3
8
|
function getRequiredDependency(dependencies, key) {
|
|
4
9
|
const dependency = dependencies[key];
|
|
5
10
|
if (dependency === undefined) {
|
|
6
|
-
throw new Error(`Required dependency "${
|
|
11
|
+
throw new Error(`Required dependency "${key}" is not registered.`);
|
|
7
12
|
}
|
|
8
13
|
return dependency;
|
|
9
14
|
}
|
|
10
|
-
|
|
15
|
+
function assertAppDependenciesComplete(dependencies) {
|
|
16
|
+
for (const key of requiredDependencyKeys) {
|
|
17
|
+
getRequiredDependency(dependencies, key);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function resolveService(dependencies, token) {
|
|
21
|
+
return dependencies.container.resolve(token);
|
|
22
|
+
}
|
|
11
23
|
// ../../src/core/contracts/serviceTokens.ts
|
|
12
24
|
var CORE_CONFIG_TOKEN = "core.config";
|
|
13
25
|
var CORE_CACHE_TOKEN = "core.cache";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// ../../src/bootstrap/discoverModules.ts
|
|
3
|
+
var appModules = [];
|
|
4
|
+
function discoverModules() {
|
|
5
|
+
return appModules;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// ../../src/bootstrap/cache/modelCacheTags.ts
|
|
9
|
+
function cacheTagsForModelWrite(tableName, action) {
|
|
10
|
+
const module = discoverModules().find((entry) => entry.tableName === tableName);
|
|
11
|
+
const baseTags = module?.cacheTags ?? [`${tableName}s`];
|
|
12
|
+
const isDelete = action === "deleted" || action === "force-deleted";
|
|
13
|
+
const extraTags = isDelete ? module?.cacheDeleteExtraTags ?? [] : [];
|
|
14
|
+
return [...new Set([...baseTags, ...extraTags])];
|
|
15
|
+
}
|
|
16
|
+
function discoverModelTableNames() {
|
|
17
|
+
return discoverModules().map((module) => module.tableName).filter((tableName) => tableName !== undefined);
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
discoverModelTableNames,
|
|
21
|
+
cacheTagsForModelWrite
|
|
22
|
+
};
|
package/dist/entries/context.js
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
// ../../src/core/contracts/
|
|
2
|
+
// ../../src/core/contracts/di.ts
|
|
3
|
+
var requiredDependencyKeys = [
|
|
4
|
+
"container",
|
|
5
|
+
"cache",
|
|
6
|
+
"storage"
|
|
7
|
+
];
|
|
3
8
|
function getRequiredDependency(dependencies, key) {
|
|
4
9
|
const dependency = dependencies[key];
|
|
5
10
|
if (dependency === undefined) {
|
|
6
|
-
throw new Error(`Required dependency "${
|
|
11
|
+
throw new Error(`Required dependency "${key}" is not registered.`);
|
|
7
12
|
}
|
|
8
13
|
return dependency;
|
|
9
14
|
}
|
|
10
|
-
|
|
15
|
+
function assertAppDependenciesComplete(dependencies) {
|
|
16
|
+
for (const key of requiredDependencyKeys) {
|
|
17
|
+
getRequiredDependency(dependencies, key);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function resolveService(dependencies, token) {
|
|
21
|
+
return dependencies.container.resolve(token);
|
|
22
|
+
}
|
|
11
23
|
// ../../src/core/contracts/serviceTokens.ts
|
|
12
24
|
var CORE_CONFIG_TOKEN = "core.config";
|
|
13
25
|
var CORE_CACHE_TOKEN = "core.cache";
|
|
@@ -97,7 +109,7 @@ function resolveApplicationLogger() {
|
|
|
97
109
|
function resolveApplicationDependencies() {
|
|
98
110
|
return requireActiveApplicationContext().dependencies;
|
|
99
111
|
}
|
|
100
|
-
// ../../src/
|
|
112
|
+
// ../../src/core/contracts/container.ts
|
|
101
113
|
class ServiceContainer {
|
|
102
114
|
services = new Map;
|
|
103
115
|
singletonFactories = new Map;
|
|
@@ -161,27 +173,6 @@ class ConfigStore {
|
|
|
161
173
|
return this.values.has(key);
|
|
162
174
|
}
|
|
163
175
|
}
|
|
164
|
-
var requiredDependencyKeys = [
|
|
165
|
-
"container",
|
|
166
|
-
"cache",
|
|
167
|
-
"storage"
|
|
168
|
-
];
|
|
169
|
-
function getRequiredDependency2(dependencies, key) {
|
|
170
|
-
const dependency = dependencies[key];
|
|
171
|
-
if (dependency === undefined) {
|
|
172
|
-
throw new Error(`Required dependency "${key}" is not registered.`);
|
|
173
|
-
}
|
|
174
|
-
return dependency;
|
|
175
|
-
}
|
|
176
|
-
function assertAppDependenciesComplete(dependencies) {
|
|
177
|
-
for (const key of requiredDependencyKeys) {
|
|
178
|
-
getRequiredDependency2(dependencies, key);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
function resolveService(dependencies, token) {
|
|
182
|
-
return dependencies.container.resolve(token);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
176
|
// ../../src/bootstrap/discoverModules.ts
|
|
186
177
|
var appModules = [];
|
|
187
178
|
function discoverModules() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
// ../../src/
|
|
2
|
+
// ../../src/core/contracts/container.ts
|
|
3
3
|
class ServiceContainer {
|
|
4
4
|
services = new Map;
|
|
5
5
|
singletonFactories = new Map;
|
|
@@ -63,6 +63,7 @@ class ConfigStore {
|
|
|
63
63
|
return this.values.has(key);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
+
// ../../src/core/contracts/di.ts
|
|
66
67
|
var requiredDependencyKeys = [
|
|
67
68
|
"container",
|
|
68
69
|
"cache",
|
|
@@ -64,15 +64,27 @@ class PreconditionFailedError extends HttpError {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
// ../../src/core/contracts/
|
|
67
|
+
// ../../src/core/contracts/di.ts
|
|
68
|
+
var requiredDependencyKeys = [
|
|
69
|
+
"container",
|
|
70
|
+
"cache",
|
|
71
|
+
"storage"
|
|
72
|
+
];
|
|
68
73
|
function getRequiredDependency(dependencies, key) {
|
|
69
74
|
const dependency = dependencies[key];
|
|
70
75
|
if (dependency === undefined) {
|
|
71
|
-
throw new Error(`Required dependency "${
|
|
76
|
+
throw new Error(`Required dependency "${key}" is not registered.`);
|
|
72
77
|
}
|
|
73
78
|
return dependency;
|
|
74
79
|
}
|
|
75
|
-
|
|
80
|
+
function assertAppDependenciesComplete(dependencies) {
|
|
81
|
+
for (const key of requiredDependencyKeys) {
|
|
82
|
+
getRequiredDependency(dependencies, key);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function resolveService(dependencies, token) {
|
|
86
|
+
return dependencies.container.resolve(token);
|
|
87
|
+
}
|
|
76
88
|
// ../../src/core/contracts/serviceTokens.ts
|
|
77
89
|
var CORE_CONFIG_TOKEN = "core.config";
|
|
78
90
|
var CORE_CACHE_TOKEN = "core.cache";
|
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
// ../../src/core/contracts/
|
|
2
|
+
// ../../src/core/contracts/di.ts
|
|
3
|
+
var requiredDependencyKeys = [
|
|
4
|
+
"container",
|
|
5
|
+
"cache",
|
|
6
|
+
"storage"
|
|
7
|
+
];
|
|
3
8
|
function getRequiredDependency(dependencies, key) {
|
|
4
9
|
const dependency = dependencies[key];
|
|
5
10
|
if (dependency === undefined) {
|
|
6
|
-
throw new Error(`Required dependency "${
|
|
11
|
+
throw new Error(`Required dependency "${key}" is not registered.`);
|
|
7
12
|
}
|
|
8
13
|
return dependency;
|
|
9
14
|
}
|
|
10
|
-
|
|
15
|
+
function assertAppDependenciesComplete(dependencies) {
|
|
16
|
+
for (const key of requiredDependencyKeys) {
|
|
17
|
+
getRequiredDependency(dependencies, key);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function resolveService(dependencies, token) {
|
|
21
|
+
return dependencies.container.resolve(token);
|
|
22
|
+
}
|
|
11
23
|
// ../../src/core/contracts/serviceTokens.ts
|
|
12
24
|
var CORE_CONFIG_TOKEN = "core.config";
|
|
13
25
|
var CORE_CACHE_TOKEN = "core.cache";
|
|
@@ -3244,15 +3244,27 @@ function createAppQueue(driver, redisUrl, failedJobs = createFailedJobService(),
|
|
|
3244
3244
|
});
|
|
3245
3245
|
}
|
|
3246
3246
|
|
|
3247
|
-
// ../../src/core/contracts/
|
|
3247
|
+
// ../../src/core/contracts/di.ts
|
|
3248
|
+
var requiredDependencyKeys = [
|
|
3249
|
+
"container",
|
|
3250
|
+
"cache",
|
|
3251
|
+
"storage"
|
|
3252
|
+
];
|
|
3248
3253
|
function getRequiredDependency(dependencies, key) {
|
|
3249
3254
|
const dependency = dependencies[key];
|
|
3250
3255
|
if (dependency === undefined) {
|
|
3251
|
-
throw new Error(`Required dependency "${
|
|
3256
|
+
throw new Error(`Required dependency "${key}" is not registered.`);
|
|
3252
3257
|
}
|
|
3253
3258
|
return dependency;
|
|
3254
3259
|
}
|
|
3255
|
-
|
|
3260
|
+
function assertAppDependenciesComplete(dependencies) {
|
|
3261
|
+
for (const key of requiredDependencyKeys) {
|
|
3262
|
+
getRequiredDependency(dependencies, key);
|
|
3263
|
+
}
|
|
3264
|
+
}
|
|
3265
|
+
function resolveService(dependencies, token) {
|
|
3266
|
+
return dependencies.container.resolve(token);
|
|
3267
|
+
}
|
|
3256
3268
|
// ../../src/core/logging/logger.ts
|
|
3257
3269
|
class Logger {
|
|
3258
3270
|
channel;
|
|
@@ -384,15 +384,27 @@ function readSharedJobRegistry() {
|
|
|
384
384
|
}
|
|
385
385
|
var jobRegistry = readSharedJobRegistry();
|
|
386
386
|
|
|
387
|
-
// ../../src/core/contracts/
|
|
387
|
+
// ../../src/core/contracts/di.ts
|
|
388
|
+
var requiredDependencyKeys = [
|
|
389
|
+
"container",
|
|
390
|
+
"cache",
|
|
391
|
+
"storage"
|
|
392
|
+
];
|
|
388
393
|
function getRequiredDependency(dependencies, key) {
|
|
389
394
|
const dependency = dependencies[key];
|
|
390
395
|
if (dependency === undefined) {
|
|
391
|
-
throw new Error(`Required dependency "${
|
|
396
|
+
throw new Error(`Required dependency "${key}" is not registered.`);
|
|
392
397
|
}
|
|
393
398
|
return dependency;
|
|
394
399
|
}
|
|
395
|
-
|
|
400
|
+
function assertAppDependenciesComplete(dependencies) {
|
|
401
|
+
for (const key of requiredDependencyKeys) {
|
|
402
|
+
getRequiredDependency(dependencies, key);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
function resolveService(dependencies, token) {
|
|
406
|
+
return dependencies.container.resolve(token);
|
|
407
|
+
}
|
|
396
408
|
// ../../src/core/contracts/serviceTokens.ts
|
|
397
409
|
var CORE_CONFIG_TOKEN = "core.config";
|
|
398
410
|
var CORE_CACHE_TOKEN = "core.cache";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// ../../src/core/http/csrfProtection.ts
|
|
3
|
+
var DEFAULT_CSRF_TTL_MS = 60 * 60 * 1000;
|
|
4
|
+
function createCsrfProtection(secret, options = {}) {
|
|
5
|
+
const expiresIn = options.expiresIn ?? DEFAULT_CSRF_TTL_MS;
|
|
6
|
+
const maxAge = options.maxAge ?? expiresIn;
|
|
7
|
+
return {
|
|
8
|
+
generate(_sessionKey) {
|
|
9
|
+
return Bun.CSRF.generate(secret, { expiresIn });
|
|
10
|
+
},
|
|
11
|
+
verify(token, _sessionKey) {
|
|
12
|
+
if (!token) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
return Bun.CSRF.verify(token, { secret, maxAge });
|
|
16
|
+
},
|
|
17
|
+
secret
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// ../../src/bootstrap/web/forms.ts
|
|
22
|
+
async function parseFormBody(request) {
|
|
23
|
+
const contentType = request.headers.get("content-type") ?? "";
|
|
24
|
+
const fields = {};
|
|
25
|
+
const files = {};
|
|
26
|
+
if (contentType.includes("application/x-www-form-urlencoded")) {
|
|
27
|
+
const text = await request.text();
|
|
28
|
+
for (const pair of text.split("&")) {
|
|
29
|
+
const idx = pair.indexOf("=");
|
|
30
|
+
if (idx === -1)
|
|
31
|
+
continue;
|
|
32
|
+
const key = decodeURIComponent(pair.slice(0, idx).replace(/\+/g, " "));
|
|
33
|
+
const value = decodeURIComponent(pair.slice(idx + 1).replace(/\+/g, " "));
|
|
34
|
+
fields[key] = value;
|
|
35
|
+
}
|
|
36
|
+
return { fields, files };
|
|
37
|
+
}
|
|
38
|
+
if (contentType.includes("multipart/form-data")) {
|
|
39
|
+
const form = await request.formData();
|
|
40
|
+
for (const [key, value] of form.entries()) {
|
|
41
|
+
if (value instanceof File) {
|
|
42
|
+
files[key] = value;
|
|
43
|
+
} else {
|
|
44
|
+
fields[key] = String(value);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return { fields, files };
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
parseFormBody,
|
|
52
|
+
createCsrfProtection
|
|
53
|
+
};
|