@getstrata/bootstrap 0.2.9 → 0.2.10

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,4 +1,7 @@
1
1
  // @bun
2
+ // ../../src/bootstrap/queue/defaultJobs.ts
3
+ import { resolveApplicationCache } from "@getstrata/core";
4
+
2
5
  // ../../src/core/jobs/dispatchWebhookJob.ts
3
6
  import { createHmac } from "crypto";
4
7
 
@@ -19,9 +22,22 @@ function getBoundDatabaseConnection() {
19
22
  return boundConnectionHolder.connection;
20
23
  }
21
24
 
22
- // ../../src/core/database/connectionContext.ts
25
+ // ../../src/core/runtime/asyncContextStore.ts
23
26
  import { AsyncLocalStorage } from "async_hooks";
24
- var activeConnection = new AsyncLocalStorage;
27
+ function createAsyncContextStore(key) {
28
+ const symbol = Symbol.for(key);
29
+ const globalRecord = globalThis;
30
+ const existing = globalRecord[symbol];
31
+ if (existing) {
32
+ return existing;
33
+ }
34
+ const store = new AsyncLocalStorage;
35
+ globalRecord[symbol] = store;
36
+ return store;
37
+ }
38
+
39
+ // ../../src/core/database/connectionContext.ts
40
+ var activeConnection = createAsyncContextStore("@getstrata/databaseConnectionContext");
25
41
  function getActiveDatabaseConnection(fallback) {
26
42
  return activeConnection.getStore() ?? fallback;
27
43
  }
@@ -362,181 +378,6 @@ class JobRegistry {
362
378
  }
363
379
  var jobRegistry = new JobRegistry;
364
380
 
365
- // ../../src/core/logging/logger.ts
366
- class Logger {
367
- channel;
368
- constructor(channel = "app") {
369
- this.channel = channel;
370
- }
371
- write(level, message, context = {}) {
372
- const entry = {
373
- level,
374
- channel: this.channel,
375
- message,
376
- timestamp: new Date().toISOString(),
377
- ...context
378
- };
379
- const line = JSON.stringify(entry);
380
- if (level === "error") {
381
- console.error(line);
382
- return;
383
- }
384
- console.log(line);
385
- }
386
- debug(message, context) {
387
- this.write("debug", message, context);
388
- }
389
- info(message, context) {
390
- this.write("info", message, context);
391
- }
392
- warn(message, context) {
393
- this.write("warn", message, context);
394
- }
395
- error(message, context) {
396
- this.write("error", message, context);
397
- }
398
- }
399
- var appLogger = new Logger("app");
400
-
401
- // ../../src/bootstrap/config.ts
402
- var APP_PORT_CONFIG_KEY = "app.port";
403
- var CACHE_TTL_MS_CONFIG_KEY = "cache.ttlMs";
404
- var CACHE_MAX_ENTRIES_CONFIG_KEY = "cache.maxEntries";
405
- var CACHE_DRIVER_CONFIG_KEY = "cache.driver";
406
- var REDIS_URL_CONFIG_KEY = "cache.redisUrl";
407
- var DATABASE_URL_CONFIG_KEY = "database.url";
408
- var CORE_CONFIG_TOKEN = "core.config";
409
- var CORE_CACHE_TOKEN = "core.cache";
410
- var CORE_QUEUE_TOKEN = "core.queue";
411
- var CORE_POLICY_GATE_TOKEN = "core.policyGate";
412
- var CORE_AUTH_TOKEN = "core.auth";
413
- var CORE_TOKEN_SERVICE_TOKEN = "core.tokenService";
414
- var AUTH_DEV_HEADERS_CONFIG_KEY = "auth.allowDevHeaders";
415
- var DEFAULT_APP_PORT = 3000;
416
- var DEFAULT_CACHE_TTL_MS = 3600000;
417
- var DEFAULT_CACHE_MAX_ENTRIES = 100;
418
- var DEFAULT_CACHE_DRIVER = "array";
419
- var DEFAULT_API_TOKEN = "";
420
- var DEFAULT_QUEUE_DRIVER = "sync";
421
-
422
- // ../../src/bootstrap/contracts.ts
423
- class ServiceContainer {
424
- services = new Map;
425
- singletonFactories = new Map;
426
- bindings = new Map;
427
- set(key, value) {
428
- this.singletonFactories.delete(key);
429
- this.bindings.delete(key);
430
- this.services.set(key, value);
431
- return value;
432
- }
433
- singleton(key, factory) {
434
- this.bindings.delete(key);
435
- this.services.delete(key);
436
- this.singletonFactories.set(key, factory);
437
- }
438
- bind(key, factory) {
439
- this.singletonFactories.delete(key);
440
- this.services.delete(key);
441
- this.bindings.set(key, factory);
442
- }
443
- get(key) {
444
- if (this.services.has(key)) {
445
- return this.services.get(key);
446
- }
447
- const singletonFactory = this.singletonFactories.get(key);
448
- if (singletonFactory) {
449
- const value = singletonFactory(this);
450
- this.services.set(key, value);
451
- return value;
452
- }
453
- const binding = this.bindings.get(key);
454
- if (binding) {
455
- return binding(this);
456
- }
457
- throw new Error(`Service "${key}" is not registered.`);
458
- }
459
- resolve(key) {
460
- return this.get(key);
461
- }
462
- has(key) {
463
- return this.services.has(key) || this.singletonFactories.has(key) || this.bindings.has(key);
464
- }
465
- }
466
-
467
- class ConfigStore {
468
- values = new Map;
469
- set(key, value) {
470
- this.values.set(key, value);
471
- return value;
472
- }
473
- get(key) {
474
- return this.values.get(key);
475
- }
476
- require(key) {
477
- if (!this.values.has(key)) {
478
- throw new Error(`Config key "${key}" is not defined.`);
479
- }
480
- return this.values.get(key);
481
- }
482
- has(key) {
483
- return this.values.has(key);
484
- }
485
- }
486
- var requiredDependencyKeys = [
487
- "container",
488
- "cache",
489
- "storage"
490
- ];
491
- function getRequiredDependency(dependencies, key) {
492
- const dependency = dependencies[key];
493
- if (dependency === undefined) {
494
- throw new Error(`Required dependency "${key}" is not registered.`);
495
- }
496
- return dependency;
497
- }
498
- function assertAppDependenciesComplete(dependencies) {
499
- for (const key of requiredDependencyKeys) {
500
- getRequiredDependency(dependencies, key);
501
- }
502
- }
503
- function resolveService(dependencies, token) {
504
- return dependencies.container.resolve(token);
505
- }
506
-
507
- // ../../src/bootstrap/applicationRegistry.ts
508
- var activeContext;
509
- function setActiveApplicationContext(context) {
510
- activeContext = context;
511
- }
512
- function requireActiveApplicationContext() {
513
- if (!activeContext) {
514
- throw new Error("The application context has not been bootstrapped.");
515
- }
516
- return activeContext;
517
- }
518
- function resolveApplicationCache() {
519
- return getRequiredDependency(requireActiveApplicationContext().dependencies, "cache");
520
- }
521
- function resolveApplicationQueue() {
522
- return requireActiveApplicationContext().container.resolve(CORE_QUEUE_TOKEN);
523
- }
524
- function resolveApplicationAuth() {
525
- return requireActiveApplicationContext().container.resolve(CORE_AUTH_TOKEN);
526
- }
527
- function resolveApplicationPolicyGate() {
528
- return requireActiveApplicationContext().container.resolve(CORE_POLICY_GATE_TOKEN);
529
- }
530
- function resolveApplicationConfig() {
531
- return requireActiveApplicationContext().config;
532
- }
533
- function resolveApplicationLogger() {
534
- return appLogger;
535
- }
536
- function resolveApplicationDependencies() {
537
- return requireActiveApplicationContext().dependencies;
538
- }
539
-
540
381
  // ../../src/bootstrap/queue/defaultJobs.ts
541
382
  function registerDefaultJobs() {
542
383
  jobRegistry.register("cache.invalidate-tags", () => {
package/dist/index.js CHANGED
@@ -1,4 +1,16 @@
1
1
  // @bun
2
+ // ../../src/bootstrap/public-api.ts
3
+ import {
4
+ resolveApplicationAuth as resolveApplicationAuth2,
5
+ resolveApplicationCache as resolveApplicationCache3,
6
+ resolveApplicationConfig,
7
+ resolveApplicationDependencies as resolveApplicationDependencies2,
8
+ resolveApplicationLogger,
9
+ resolveApplicationPolicyGate as resolveApplicationPolicyGate2,
10
+ resolveApplicationQueue as resolveApplicationQueue2,
11
+ setActiveApplicationContext as setActiveApplicationContext2
12
+ } from "@getstrata/core";
13
+
2
14
  // ../../src/core/scheduler/schedule.ts
3
15
  class Schedule {
4
16
  tasks = [];
@@ -70,9 +82,22 @@ function getBoundDatabaseConnection() {
70
82
  return boundConnectionHolder.connection;
71
83
  }
72
84
 
73
- // ../../src/core/database/connectionContext.ts
85
+ // ../../src/core/runtime/asyncContextStore.ts
74
86
  import { AsyncLocalStorage } from "async_hooks";
75
- var activeConnection = new AsyncLocalStorage;
87
+ function createAsyncContextStore(key) {
88
+ const symbol = Symbol.for(key);
89
+ const globalRecord = globalThis;
90
+ const existing = globalRecord[symbol];
91
+ if (existing) {
92
+ return existing;
93
+ }
94
+ const store = new AsyncLocalStorage;
95
+ globalRecord[symbol] = store;
96
+ return store;
97
+ }
98
+
99
+ // ../../src/core/database/connectionContext.ts
100
+ var activeConnection = createAsyncContextStore("@getstrata/databaseConnectionContext");
76
101
  function getActiveDatabaseConnection(fallback) {
77
102
  return activeConnection.getStore() ?? fallback;
78
103
  }
@@ -509,6 +534,8 @@ var DEFAULT_CACHE_MAX_ENTRIES = 100;
509
534
  var DEFAULT_CACHE_DRIVER = "array";
510
535
  var DEFAULT_API_TOKEN = "";
511
536
  var DEFAULT_QUEUE_DRIVER = "sync";
537
+ // ../../src/bootstrap/context.ts
538
+ import { setActiveApplicationContext } from "@getstrata/core";
512
539
 
513
540
  // ../../src/bootstrap/contracts.ts
514
541
  class ServiceContainer {
@@ -595,41 +622,6 @@ function resolveService(dependencies, token) {
595
622
  return dependencies.container.resolve(token);
596
623
  }
597
624
 
598
- // ../../src/bootstrap/applicationRegistry.ts
599
- var activeContext;
600
- function setActiveApplicationContext(context) {
601
- activeContext = context;
602
- }
603
- function requireActiveApplicationContext() {
604
- if (!activeContext) {
605
- throw new Error("The application context has not been bootstrapped.");
606
- }
607
- return activeContext;
608
- }
609
- function resolveApplicationCache() {
610
- return getRequiredDependency(requireActiveApplicationContext().dependencies, "cache");
611
- }
612
- function resolveApplicationQueue() {
613
- return requireActiveApplicationContext().container.resolve(CORE_QUEUE_TOKEN);
614
- }
615
- function resolveApplicationAuth() {
616
- return requireActiveApplicationContext().container.resolve(CORE_AUTH_TOKEN);
617
- }
618
- function resolveApplicationPolicyGate() {
619
- return requireActiveApplicationContext().container.resolve(CORE_POLICY_GATE_TOKEN);
620
- }
621
- function resolveApplicationConfig() {
622
- return requireActiveApplicationContext().config;
623
- }
624
- function resolveApplicationLogger() {
625
- return appLogger;
626
- }
627
- function resolveApplicationDependencies() {
628
- return requireActiveApplicationContext().dependencies;
629
- }
630
- // ../../src/bootstrap/context.ts
631
- import { setActiveApplicationContext as setActiveApplicationContext2 } from "@getstrata/core";
632
-
633
625
  // ../../src/bootstrap/discoverModules.ts
634
626
  import { readdirSync } from "fs";
635
627
  import { join } from "path";
@@ -942,8 +934,7 @@ import { resolveDefaultTokenExpiryDays as resolveDefaultTokenExpiryDays2 } from
942
934
  var tokenServiceToken = CORE_TOKEN_SERVICE_TOKEN;
943
935
 
944
936
  // ../../src/core/auth/authContext.ts
945
- import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
946
- var authContext = new AsyncLocalStorage2;
937
+ var authContext = createAsyncContextStore("@getstrata/authContext");
947
938
  function currentAuthUser() {
948
939
  return authContext.getStore() ?? null;
949
940
  }
@@ -1808,6 +1799,9 @@ function discoverListeners() {
1808
1799
  return appListeners;
1809
1800
  }
1810
1801
 
1802
+ // ../../src/bootstrap/listeners/invalidateCacheOnModelWrite.ts
1803
+ import { resolveApplicationCache as resolveApplicationCache2, resolveApplicationQueue } from "@getstrata/core";
1804
+
1811
1805
  // ../../src/core/cache/modelCacheTags.ts
1812
1806
  function cacheTagsForModelWrite(tableName, action) {
1813
1807
  const module = appModules.find((entry) => entry.tableName === tableName);
@@ -3709,6 +3703,9 @@ function createProductionQueue(driver, options = {}) {
3709
3703
  return new ResilientQueue(failedJobs, driver === "async");
3710
3704
  }
3711
3705
 
3706
+ // ../../src/bootstrap/queue/defaultJobs.ts
3707
+ import { resolveApplicationCache } from "@getstrata/core";
3708
+
3712
3709
  // ../../src/core/jobs/dispatchWebhookJob.ts
3713
3710
  import { createHmac as createHmac2 } from "crypto";
3714
3711
  class DispatchWebhookJob extends Job {
@@ -3801,7 +3798,7 @@ function registerInvalidateCacheOnModelWriteListeners(bus = eventBus) {
3801
3798
  let cache;
3802
3799
  let queue;
3803
3800
  try {
3804
- cache = resolveApplicationCache();
3801
+ cache = resolveApplicationCache2();
3805
3802
  queue = resolveApplicationQueue();
3806
3803
  } catch {
3807
3804
  return;
@@ -4035,8 +4032,7 @@ function isViewsEnabled() {
4035
4032
  }
4036
4033
 
4037
4034
  // ../../src/core/http/requestMetaContext.ts
4038
- import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
4039
- var requestMetaContext = new AsyncLocalStorage3;
4035
+ var requestMetaContext = createAsyncContextStore("@getstrata/requestMetaContext");
4040
4036
  function currentRequestMeta() {
4041
4037
  return requestMetaContext.getStore() ?? {
4042
4038
  ipAddress: null,
@@ -4369,7 +4365,7 @@ function createAppContext() {
4369
4365
  config,
4370
4366
  dependencies
4371
4367
  };
4372
- setActiveApplicationContext2(appContext);
4368
+ setActiveApplicationContext(appContext);
4373
4369
  return appContext;
4374
4370
  }
4375
4371
  // ../../src/bootstrap/createWebRoutes.ts
@@ -4725,6 +4721,9 @@ function mergeWebRoutes(dependencies, routes) {
4725
4721
  ...routes
4726
4722
  };
4727
4723
  }
4724
+ // ../../src/bootstrap/http/securedRouteModelBinding.ts
4725
+ import { resolveApplicationAuth, resolveApplicationPolicyGate } from "@getstrata/core";
4726
+
4728
4727
  // ../../src/core/crypto/nonCryptographicHash.ts
4729
4728
  function nonCryptographicDigest(input) {
4730
4729
  return Bun.hash(input).toString(16);
@@ -4817,8 +4816,7 @@ function applyConditionalGet(request, response, etag) {
4817
4816
  }
4818
4817
 
4819
4818
  // ../../src/core/tenant/tenantContext.ts
4820
- import { AsyncLocalStorage as AsyncLocalStorage4 } from "async_hooks";
4821
- var tenantContext = new AsyncLocalStorage4;
4819
+ var tenantContext = createAsyncContextStore("@getstrata/tenantContext");
4822
4820
 
4823
4821
  // ../../src/core/http/validation.ts
4824
4822
  function parsePositiveIntParam(value, name = "id") {
@@ -4876,6 +4874,9 @@ function securedBindRouteModelByKey(param, resolver, authorization, handler) {
4876
4874
  return response;
4877
4875
  };
4878
4876
  }
4877
+ // ../../src/bootstrap/membershipService.ts
4878
+ import { resolveApplicationDependencies } from "@getstrata/core";
4879
+
4879
4880
  // ../../src/core/auth/accessControl.ts
4880
4881
  var ROLE_RANK = {
4881
4882
  member: 1,
@@ -4899,9 +4900,6 @@ function resolveUserId(user) {
4899
4900
  return userId;
4900
4901
  }
4901
4902
 
4902
- // ../../src/core/auth/membershipContext.ts
4903
- import { AsyncLocalStorage as AsyncLocalStorage5 } from "async_hooks";
4904
-
4905
4903
  // ../../src/modules/organization/memberRepository.ts
4906
4904
  class OrganizationMemberRepository {
4907
4905
  constructor() {}
@@ -4954,7 +4952,7 @@ class OrganizationMemberRepository {
4954
4952
  var memberRepository_default = OrganizationMemberRepository;
4955
4953
 
4956
4954
  // ../../src/core/auth/membershipContext.ts
4957
- var membershipContext = new AsyncLocalStorage5;
4955
+ var membershipContext = createAsyncContextStore("@getstrata/membershipContext");
4958
4956
  var membershipRepository = new memberRepository_default;
4959
4957
 
4960
4958
  // ../../src/core/auth/membershipService.ts
@@ -5254,7 +5252,7 @@ export {
5254
5252
  wrapSecuredRouteModelByKey,
5255
5253
  toRouteRequest,
5256
5254
  slugify,
5257
- setActiveApplicationContext,
5255
+ setActiveApplicationContext2 as setActiveApplicationContext,
5258
5256
  securedBindRouteModelByKey,
5259
5257
  securedBindRouteModel,
5260
5258
  scheduleRunCommand,
@@ -5263,13 +5261,13 @@ export {
5263
5261
  routeParams,
5264
5262
  resolveService,
5265
5263
  resolveMembershipService,
5266
- resolveApplicationQueue,
5267
- resolveApplicationPolicyGate,
5264
+ resolveApplicationQueue2 as resolveApplicationQueue,
5265
+ resolveApplicationPolicyGate2 as resolveApplicationPolicyGate,
5268
5266
  resolveApplicationLogger,
5269
- resolveApplicationDependencies,
5267
+ resolveApplicationDependencies2 as resolveApplicationDependencies,
5270
5268
  resolveApplicationConfig,
5271
- resolveApplicationCache,
5272
- resolveApplicationAuth,
5269
+ resolveApplicationCache3 as resolveApplicationCache,
5270
+ resolveApplicationAuth2 as resolveApplicationAuth,
5273
5271
  registerDefaultJobs,
5274
5272
  prefixRouteMap,
5275
5273
  parseFormBody,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getstrata/bootstrap",
3
- "version": "0.2.9",
3
+ "version": "0.2.10",
4
4
  "description": "Strata application bootstrap — HttpKernel, DI, web session helpers",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -89,7 +89,7 @@
89
89
  "access": "public"
90
90
  },
91
91
  "peerDependencies": {
92
- "@getstrata/core": "^0.5.17",
92
+ "@getstrata/core": "^0.5.18",
93
93
  "typescript": "^5.9.0"
94
94
  }
95
95
  }