@getstrata/bootstrap 0.2.12 → 0.2.16

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.
@@ -1,16 +1 @@
1
- import type { AuthManager } from "../core/auth/guard";
2
- import type { PolicyGate } from "../core/auth/policy";
3
- import { type Logger } from "../core/logging/logger";
4
- import type { Queue } from "../core/queue";
5
- import type { CacheLike } from "../types/services";
6
- import type { AppContext } from "./contracts";
7
- import { type ConfigStore } from "./contracts";
8
- declare function setActiveApplicationContext(context: AppContext): void;
9
- declare function resolveApplicationCache(): CacheLike;
10
- declare function resolveApplicationQueue(): Queue;
11
- declare function resolveApplicationAuth(): AuthManager;
12
- declare function resolveApplicationPolicyGate(): PolicyGate;
13
- declare function resolveApplicationConfig(): ConfigStore;
14
- declare function resolveApplicationLogger(): Logger;
15
- declare function resolveApplicationDependencies(): import("./contracts").AppDependencies;
16
- export { resolveApplicationAuth, resolveApplicationCache, resolveApplicationConfig, resolveApplicationDependencies, resolveApplicationLogger, resolveApplicationPolicyGate, resolveApplicationQueue, setActiveApplicationContext, };
1
+ export { resolveApplicationAuth, resolveApplicationCache, resolveApplicationConfig, resolveApplicationDependencies, resolveApplicationLogger, resolveApplicationPolicyGate, resolveApplicationQueue, setActiveApplicationContext, } from "../core/runtime/applicationRegistry.ts";
@@ -4,12 +4,7 @@ declare const CACHE_MAX_ENTRIES_CONFIG_KEY = "cache.maxEntries";
4
4
  declare const CACHE_DRIVER_CONFIG_KEY = "cache.driver";
5
5
  declare const REDIS_URL_CONFIG_KEY = "cache.redisUrl";
6
6
  declare const DATABASE_URL_CONFIG_KEY = "database.url";
7
- declare const CORE_CONFIG_TOKEN = "core.config";
8
- declare const CORE_CACHE_TOKEN = "core.cache";
9
- declare const CORE_QUEUE_TOKEN = "core.queue";
10
- declare const CORE_POLICY_GATE_TOKEN = "core.policyGate";
11
- declare const CORE_AUTH_TOKEN = "core.auth";
12
- declare const CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
7
+ export { CORE_AUTH_TOKEN, CORE_CACHE_TOKEN, CORE_CONFIG_TOKEN, CORE_POLICY_GATE_TOKEN, CORE_QUEUE_TOKEN, CORE_TOKEN_SERVICE_TOKEN, } from "../core/contracts/serviceTokens.ts";
13
8
  declare const AUTH_DEV_HEADERS_CONFIG_KEY = "auth.allowDevHeaders";
14
9
  declare const DEFAULT_APP_PORT = 3000;
15
10
  declare const DEFAULT_CACHE_TTL_MS = 3600000;
@@ -17,4 +12,4 @@ declare const DEFAULT_CACHE_MAX_ENTRIES = 100;
17
12
  declare const DEFAULT_CACHE_DRIVER = "array";
18
13
  declare const DEFAULT_API_TOKEN = "";
19
14
  declare const DEFAULT_QUEUE_DRIVER = "sync";
20
- export { APP_PORT_CONFIG_KEY, AUTH_DEV_HEADERS_CONFIG_KEY, CACHE_DRIVER_CONFIG_KEY, CACHE_MAX_ENTRIES_CONFIG_KEY, CACHE_TTL_MS_CONFIG_KEY, CORE_AUTH_TOKEN, CORE_CACHE_TOKEN, CORE_CONFIG_TOKEN, CORE_POLICY_GATE_TOKEN, CORE_QUEUE_TOKEN, CORE_TOKEN_SERVICE_TOKEN, DATABASE_URL_CONFIG_KEY, DEFAULT_API_TOKEN, DEFAULT_APP_PORT, DEFAULT_CACHE_DRIVER, DEFAULT_CACHE_MAX_ENTRIES, DEFAULT_CACHE_TTL_MS, DEFAULT_QUEUE_DRIVER, REDIS_URL_CONFIG_KEY, };
15
+ export { APP_PORT_CONFIG_KEY, AUTH_DEV_HEADERS_CONFIG_KEY, CACHE_DRIVER_CONFIG_KEY, CACHE_MAX_ENTRIES_CONFIG_KEY, CACHE_TTL_MS_CONFIG_KEY, DATABASE_URL_CONFIG_KEY, DEFAULT_API_TOKEN, DEFAULT_APP_PORT, DEFAULT_CACHE_DRIVER, DEFAULT_CACHE_MAX_ENTRIES, DEFAULT_CACHE_TTL_MS, DEFAULT_QUEUE_DRIVER, REDIS_URL_CONFIG_KEY, };
@@ -1,11 +1,2 @@
1
- import type { Policy } from "../../core/auth/policy";
2
- import type { RouteRequest } from "../../core/http/route";
3
- interface RouteModelAuthorization {
4
- resource: string;
5
- action: keyof Policy;
6
- requireIfMatch?: boolean;
7
- }
8
- declare function securedBindRouteModel<TParams extends Record<string, string>, TModel, TParam extends keyof TParams & string>(param: TParam, resolver: (id: number, request: RouteRequest<TParams>) => Promise<TModel>, authorization: RouteModelAuthorization, handler: (request: RouteRequest<TParams>, model: TModel) => Response | Promise<Response>): (request: RouteRequest<TParams>) => Promise<Response>;
9
- declare function securedBindRouteModelByKey<TParams extends Record<string, string>, TModel, TParam extends keyof TParams & string>(param: TParam, resolver: (key: string, request: RouteRequest<TParams>) => Promise<TModel>, authorization: RouteModelAuthorization, handler: (request: RouteRequest<TParams>, model: TModel) => Response | Promise<Response>): (request: RouteRequest<TParams>) => Promise<Response>;
10
- export type { RouteModelAuthorization };
11
- export { securedBindRouteModel, securedBindRouteModelByKey };
1
+ export type { RouteModelAuthorization } from "../../core/http/securedRouteModelBinding.ts";
2
+ export { securedBindRouteModel, securedBindRouteModelByKey, } from "../../core/http/securedRouteModelBinding.ts";
@@ -1,3 +1 @@
1
- import MembershipService from "../core/auth/membershipService";
2
- declare function resolveMembershipService(): MembershipService;
3
- export { resolveMembershipService };
1
+ export { resolveMembershipService } from "../core/auth/resolveMembershipService.ts";
@@ -20,4 +20,4 @@ declare class MembershipService {
20
20
  }
21
21
  export type { MembershipRepositoryLike };
22
22
  export default MembershipService;
23
- export { resolveMembershipService } from "../../bootstrap/membershipService.ts";
23
+ export { resolveMembershipService } from "./resolveMembershipService.ts";
@@ -0,0 +1,3 @@
1
+ import MembershipService from "./membershipService";
2
+ declare function resolveMembershipService(): MembershipService;
3
+ export { resolveMembershipService };
@@ -0,0 +1,18 @@
1
+ import type { CacheLike } from "../../types/services";
2
+ import type { ServiceContainerLike } from "./serviceContainer";
3
+ interface ConfigStoreLike {
4
+ get<T>(key: string): T | undefined;
5
+ }
6
+ interface ApplicationDependenciesLike {
7
+ container: ServiceContainerLike;
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 };
@@ -0,0 +1,7 @@
1
+ declare const CORE_CONFIG_TOKEN = "core.config";
2
+ declare const CORE_CACHE_TOKEN = "core.cache";
3
+ declare const CORE_QUEUE_TOKEN = "core.queue";
4
+ declare const CORE_POLICY_GATE_TOKEN = "core.policyGate";
5
+ declare const CORE_AUTH_TOKEN = "core.auth";
6
+ declare const CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
7
+ export { CORE_AUTH_TOKEN, CORE_CACHE_TOKEN, CORE_CONFIG_TOKEN, CORE_POLICY_GATE_TOKEN, CORE_QUEUE_TOKEN, CORE_TOKEN_SERVICE_TOKEN, };
@@ -1,2 +1,11 @@
1
- export type { RouteModelAuthorization } from "../../bootstrap/http/securedRouteModelBinding.ts";
2
- export { securedBindRouteModel, securedBindRouteModelByKey, } from "../../bootstrap/http/securedRouteModelBinding.ts";
1
+ import type { Policy } from "../auth/policy";
2
+ import type { RouteRequest } from "./route";
3
+ interface RouteModelAuthorization {
4
+ resource: string;
5
+ action: keyof Policy;
6
+ requireIfMatch?: boolean;
7
+ }
8
+ declare function securedBindRouteModel<TParams extends Record<string, string>, TModel, TParam extends keyof TParams & string>(param: TParam, resolver: (id: number, request: RouteRequest<TParams>) => Promise<TModel>, authorization: RouteModelAuthorization, handler: (request: RouteRequest<TParams>, model: TModel) => Response | Promise<Response>): (request: RouteRequest<TParams>) => Promise<Response>;
9
+ declare function securedBindRouteModelByKey<TParams extends Record<string, string>, TModel, TParam extends keyof TParams & string>(param: TParam, resolver: (key: string, request: RouteRequest<TParams>) => Promise<TModel>, authorization: RouteModelAuthorization, handler: (request: RouteRequest<TParams>, model: TModel) => Response | Promise<Response>): (request: RouteRequest<TParams>) => Promise<Response>;
10
+ export type { RouteModelAuthorization };
11
+ export { securedBindRouteModel, securedBindRouteModelByKey };
@@ -2,5 +2,4 @@ import type { Queue } from "./index";
2
2
  import { createFailedJobService, createQueueWorker, createTrackedJob, type FailedJobService } from "./publicQueue";
3
3
  declare const FAILED_JOB_SERVICE_TOKEN = "core.failedJobs";
4
4
  declare function createAppQueue(driver: "sync" | "async" | "redis", redisUrl?: string, failedJobs?: FailedJobService, registerJobs?: () => void): Queue;
5
- export { registerDefaultJobs } from "../../bootstrap/queue/defaultJobs.ts";
6
5
  export { createAppQueue, createFailedJobService, createQueueWorker, createTrackedJob, FAILED_JOB_SERVICE_TOKEN, };
@@ -1,7 +1,6 @@
1
1
  import type { Job } from "./index";
2
2
  type JobFactory = () => Job;
3
3
  declare class JobRegistry {
4
- constructor();
5
4
  private readonly factories;
6
5
  private readonly instances;
7
6
  register(name: string, factory: JobFactory): void;
@@ -0,0 +1,15 @@
1
+ import type { CacheLike } from "../../types/services";
2
+ import type { AuthManager } from "../auth/guard";
3
+ import type { PolicyGate } from "../auth/policy";
4
+ import type { ApplicationContext } from "../contracts/applicationContext";
5
+ import { type Logger } from "../logging/logger";
6
+ import type { Queue } from "../queue";
7
+ declare function setActiveApplicationContext(context: ApplicationContext): void;
8
+ declare function resolveApplicationCache(): CacheLike;
9
+ declare function resolveApplicationQueue(): Queue;
10
+ declare function resolveApplicationAuth(): AuthManager;
11
+ declare function resolveApplicationPolicyGate(): PolicyGate;
12
+ declare function resolveApplicationConfig(): import("../contracts/applicationContext").ConfigStoreLike;
13
+ declare function resolveApplicationLogger(): Logger;
14
+ declare function resolveApplicationDependencies(): import("../contracts/applicationContext").ApplicationDependenciesLike;
15
+ export { resolveApplicationAuth, resolveApplicationCache, resolveApplicationConfig, resolveApplicationDependencies, resolveApplicationLogger, resolveApplicationPolicyGate, resolveApplicationQueue, setActiveApplicationContext, };
@@ -1,4 +1,21 @@
1
1
  // @bun
2
+ // ../../src/core/contracts/applicationContext.ts
3
+ function getRequiredDependency(dependencies, key) {
4
+ const dependency = dependencies[key];
5
+ if (dependency === undefined) {
6
+ throw new Error(`Required dependency "${String(key)}" is not registered.`);
7
+ }
8
+ return dependency;
9
+ }
10
+
11
+ // ../../src/core/contracts/serviceTokens.ts
12
+ var CORE_CONFIG_TOKEN = "core.config";
13
+ var CORE_CACHE_TOKEN = "core.cache";
14
+ var CORE_QUEUE_TOKEN = "core.queue";
15
+ var CORE_POLICY_GATE_TOKEN = "core.policyGate";
16
+ var CORE_AUTH_TOKEN = "core.auth";
17
+ var CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
18
+
2
19
  // ../../src/core/logging/logger.ts
3
20
  class Logger {
4
21
  channel;
@@ -35,113 +52,7 @@ class Logger {
35
52
  }
36
53
  var appLogger = new Logger("app");
37
54
 
38
- // ../../src/bootstrap/config.ts
39
- var APP_PORT_CONFIG_KEY = "app.port";
40
- var CACHE_TTL_MS_CONFIG_KEY = "cache.ttlMs";
41
- var CACHE_MAX_ENTRIES_CONFIG_KEY = "cache.maxEntries";
42
- var CACHE_DRIVER_CONFIG_KEY = "cache.driver";
43
- var REDIS_URL_CONFIG_KEY = "cache.redisUrl";
44
- var DATABASE_URL_CONFIG_KEY = "database.url";
45
- var CORE_CONFIG_TOKEN = "core.config";
46
- var CORE_CACHE_TOKEN = "core.cache";
47
- var CORE_QUEUE_TOKEN = "core.queue";
48
- var CORE_POLICY_GATE_TOKEN = "core.policyGate";
49
- var CORE_AUTH_TOKEN = "core.auth";
50
- var CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
51
- var AUTH_DEV_HEADERS_CONFIG_KEY = "auth.allowDevHeaders";
52
- var DEFAULT_APP_PORT = 3000;
53
- var DEFAULT_CACHE_TTL_MS = 3600000;
54
- var DEFAULT_CACHE_MAX_ENTRIES = 100;
55
- var DEFAULT_CACHE_DRIVER = "array";
56
- var DEFAULT_API_TOKEN = "";
57
- var DEFAULT_QUEUE_DRIVER = "sync";
58
-
59
- // ../../src/bootstrap/contracts.ts
60
- class ServiceContainer {
61
- services = new Map;
62
- singletonFactories = new Map;
63
- bindings = new Map;
64
- set(key, value) {
65
- this.singletonFactories.delete(key);
66
- this.bindings.delete(key);
67
- this.services.set(key, value);
68
- return value;
69
- }
70
- singleton(key, factory) {
71
- this.bindings.delete(key);
72
- this.services.delete(key);
73
- this.singletonFactories.set(key, factory);
74
- }
75
- bind(key, factory) {
76
- this.singletonFactories.delete(key);
77
- this.services.delete(key);
78
- this.bindings.set(key, factory);
79
- }
80
- get(key) {
81
- if (this.services.has(key)) {
82
- return this.services.get(key);
83
- }
84
- const singletonFactory = this.singletonFactories.get(key);
85
- if (singletonFactory) {
86
- const value = singletonFactory(this);
87
- this.services.set(key, value);
88
- return value;
89
- }
90
- const binding = this.bindings.get(key);
91
- if (binding) {
92
- return binding(this);
93
- }
94
- throw new Error(`Service "${key}" is not registered.`);
95
- }
96
- resolve(key) {
97
- return this.get(key);
98
- }
99
- has(key) {
100
- return this.services.has(key) || this.singletonFactories.has(key) || this.bindings.has(key);
101
- }
102
- }
103
-
104
- class ConfigStore {
105
- values = new Map;
106
- set(key, value) {
107
- this.values.set(key, value);
108
- return value;
109
- }
110
- get(key) {
111
- return this.values.get(key);
112
- }
113
- require(key) {
114
- if (!this.values.has(key)) {
115
- throw new Error(`Config key "${key}" is not defined.`);
116
- }
117
- return this.values.get(key);
118
- }
119
- has(key) {
120
- return this.values.has(key);
121
- }
122
- }
123
- var requiredDependencyKeys = [
124
- "container",
125
- "cache",
126
- "storage"
127
- ];
128
- function getRequiredDependency(dependencies, key) {
129
- const dependency = dependencies[key];
130
- if (dependency === undefined) {
131
- throw new Error(`Required dependency "${key}" is not registered.`);
132
- }
133
- return dependency;
134
- }
135
- function assertAppDependenciesComplete(dependencies) {
136
- for (const key of requiredDependencyKeys) {
137
- getRequiredDependency(dependencies, key);
138
- }
139
- }
140
- function resolveService(dependencies, token) {
141
- return dependencies.container.resolve(token);
142
- }
143
-
144
- // ../../src/bootstrap/applicationRegistry.ts
55
+ // ../../src/core/runtime/applicationRegistry.ts
145
56
  var APPLICATION_CONTEXT_KEY = Symbol.for("@getstrata/applicationContext");
146
57
  var activeContext;
147
58
  function readStoredApplicationContext() {
@@ -1,4 +1,12 @@
1
1
  // @bun
2
+ // ../../src/core/contracts/serviceTokens.ts
3
+ var CORE_CONFIG_TOKEN = "core.config";
4
+ var CORE_CACHE_TOKEN = "core.cache";
5
+ var CORE_QUEUE_TOKEN = "core.queue";
6
+ var CORE_POLICY_GATE_TOKEN = "core.policyGate";
7
+ var CORE_AUTH_TOKEN = "core.auth";
8
+ var CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
9
+
2
10
  // ../../src/bootstrap/config.ts
3
11
  var APP_PORT_CONFIG_KEY = "app.port";
4
12
  var CACHE_TTL_MS_CONFIG_KEY = "cache.ttlMs";
@@ -6,12 +14,6 @@ var CACHE_MAX_ENTRIES_CONFIG_KEY = "cache.maxEntries";
6
14
  var CACHE_DRIVER_CONFIG_KEY = "cache.driver";
7
15
  var REDIS_URL_CONFIG_KEY = "cache.redisUrl";
8
16
  var DATABASE_URL_CONFIG_KEY = "database.url";
9
- var CORE_CONFIG_TOKEN = "core.config";
10
- var CORE_CACHE_TOKEN = "core.cache";
11
- var CORE_QUEUE_TOKEN = "core.queue";
12
- var CORE_POLICY_GATE_TOKEN = "core.policyGate";
13
- var CORE_AUTH_TOKEN = "core.auth";
14
- var CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
15
17
  var AUTH_DEV_HEADERS_CONFIG_KEY = "auth.allowDevHeaders";
16
18
  var DEFAULT_APP_PORT = 3000;
17
19
  var DEFAULT_CACHE_TTL_MS = 3600000;