@getstrata/bootstrap 0.2.10 → 0.2.12

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/index.js CHANGED
@@ -1,16 +1,4 @@
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
-
14
2
  // ../../src/core/scheduler/schedule.ts
15
3
  class Schedule {
16
4
  tasks = [];
@@ -534,8 +522,6 @@ var DEFAULT_CACHE_MAX_ENTRIES = 100;
534
522
  var DEFAULT_CACHE_DRIVER = "array";
535
523
  var DEFAULT_API_TOKEN = "";
536
524
  var DEFAULT_QUEUE_DRIVER = "sync";
537
- // ../../src/bootstrap/context.ts
538
- import { setActiveApplicationContext } from "@getstrata/core";
539
525
 
540
526
  // ../../src/bootstrap/contracts.ts
541
527
  class ServiceContainer {
@@ -622,29 +608,68 @@ function resolveService(dependencies, token) {
622
608
  return dependencies.container.resolve(token);
623
609
  }
624
610
 
625
- // ../../src/bootstrap/discoverModules.ts
626
- import { readdirSync } from "fs";
627
- import { join } from "path";
628
- import { pathToFileURL } from "url";
629
- async function loadDiscoveredModules() {
630
- const modulesDirectory = join(import.meta.dir, "../modules");
631
- let moduleNames;
632
- try {
633
- moduleNames = readdirSync(modulesDirectory, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
634
- } catch (error) {
635
- if (error.code === "ENOENT") {
636
- return [];
637
- }
638
- throw error;
611
+ // ../../src/bootstrap/applicationRegistry.ts
612
+ var APPLICATION_CONTEXT_KEY = Symbol.for("@getstrata/applicationContext");
613
+ var activeContext;
614
+ function readStoredApplicationContext() {
615
+ if (activeContext) {
616
+ return activeContext;
639
617
  }
640
- const modules = await Promise.all(moduleNames.map(async (moduleName) => {
641
- const moduleUrl = pathToFileURL(join(modulesDirectory, moduleName, "index.ts")).href;
642
- const loaded = await import(moduleUrl);
643
- return loaded.default;
644
- }));
645
- return modules.filter((module) => module?.name !== undefined).sort((left, right) => (left.order ?? 100) - (right.order ?? 100));
618
+ const globalContext = globalThis[APPLICATION_CONTEXT_KEY];
619
+ if (globalContext) {
620
+ activeContext = globalContext;
621
+ }
622
+ return activeContext;
623
+ }
624
+ function setActiveApplicationContext(context) {
625
+ activeContext = context;
626
+ globalThis[APPLICATION_CONTEXT_KEY] = context;
627
+ }
628
+ function requireActiveApplicationContext() {
629
+ const context = readStoredApplicationContext();
630
+ if (!context) {
631
+ throw new Error("The application context has not been bootstrapped.");
632
+ }
633
+ return context;
634
+ }
635
+ function resolveApplicationCache() {
636
+ return getRequiredDependency(requireActiveApplicationContext().dependencies, "cache");
637
+ }
638
+ function resolveApplicationQueue() {
639
+ return requireActiveApplicationContext().container.resolve(CORE_QUEUE_TOKEN);
640
+ }
641
+ function resolveApplicationAuth() {
642
+ return requireActiveApplicationContext().container.resolve(CORE_AUTH_TOKEN);
643
+ }
644
+ function resolveApplicationPolicyGate() {
645
+ return requireActiveApplicationContext().container.resolve(CORE_POLICY_GATE_TOKEN);
646
+ }
647
+ function resolveApplicationConfig() {
648
+ return requireActiveApplicationContext().config;
649
+ }
650
+ function resolveApplicationLogger() {
651
+ return appLogger;
652
+ }
653
+ function resolveApplicationDependencies() {
654
+ return requireActiveApplicationContext().dependencies;
655
+ }
656
+ // ../../src/bootstrap/discoverModules.ts
657
+ var appModules = [];
658
+ function discoverModules() {
659
+ return appModules;
660
+ }
661
+
662
+ // ../../src/bootstrap/cache/modelCacheTags.ts
663
+ function cacheTagsForModelWrite(tableName, action) {
664
+ const module = discoverModules().find((entry) => entry.tableName === tableName);
665
+ const baseTags = module?.cacheTags ?? [`${tableName}s`];
666
+ const isDelete = action === "deleted" || action === "force-deleted";
667
+ const extraTags = isDelete ? module?.cacheDeleteExtraTags ?? [] : [];
668
+ return [...new Set([...baseTags, ...extraTags])];
669
+ }
670
+ function discoverModelTableNames() {
671
+ return discoverModules().map((module) => module.tableName).filter((tableName) => tableName !== undefined);
646
672
  }
647
- var appModules = await loadDiscoveredModules();
648
673
  // ../../src/config/auth.ts
649
674
  var authConfig = {
650
675
  allowDevHeaders: (process.env.AUTH_DEV_HEADERS ?? "true") !== "false",
@@ -1773,14 +1798,14 @@ var eventsProvider = {
1773
1798
  var events_default = eventsProvider;
1774
1799
 
1775
1800
  // ../../src/bootstrap/discoverListeners.ts
1776
- import { readdirSync as readdirSync2 } from "fs";
1777
- import { join as join2 } from "path";
1778
- import { pathToFileURL as pathToFileURL2 } from "url";
1801
+ import { readdirSync } from "fs";
1802
+ import { join } from "path";
1803
+ import { pathToFileURL } from "url";
1779
1804
  async function loadDiscoveredListeners() {
1780
- const listenersDirectory = join2(import.meta.dir, "../listeners");
1805
+ const listenersDirectory = join(import.meta.dir, "../listeners");
1781
1806
  let entries;
1782
1807
  try {
1783
- entries = readdirSync2(listenersDirectory, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".ts")).map((entry) => entry.name);
1808
+ entries = readdirSync(listenersDirectory, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".ts")).map((entry) => entry.name);
1784
1809
  } catch (error) {
1785
1810
  if (error instanceof Error && "code" in error && error.code === "ENOENT") {
1786
1811
  return [];
@@ -1788,7 +1813,7 @@ async function loadDiscoveredListeners() {
1788
1813
  throw error;
1789
1814
  }
1790
1815
  const listeners = await Promise.all(entries.map(async (fileName) => {
1791
- const moduleUrl = pathToFileURL2(join2(listenersDirectory, fileName)).href;
1816
+ const moduleUrl = pathToFileURL(join(listenersDirectory, fileName)).href;
1792
1817
  const loaded = await import(moduleUrl);
1793
1818
  return loaded.default;
1794
1819
  }));
@@ -1799,21 +1824,6 @@ function discoverListeners() {
1799
1824
  return appListeners;
1800
1825
  }
1801
1826
 
1802
- // ../../src/bootstrap/listeners/invalidateCacheOnModelWrite.ts
1803
- import { resolveApplicationCache as resolveApplicationCache2, resolveApplicationQueue } from "@getstrata/core";
1804
-
1805
- // ../../src/core/cache/modelCacheTags.ts
1806
- function cacheTagsForModelWrite(tableName, action) {
1807
- const module = appModules.find((entry) => entry.tableName === tableName);
1808
- const baseTags = module?.cacheTags ?? [`${tableName}s`];
1809
- const isDelete = action === "deleted" || action === "force-deleted";
1810
- const extraTags = isDelete ? module?.cacheDeleteExtraTags ?? [] : [];
1811
- return [...new Set([...baseTags, ...extraTags])];
1812
- }
1813
- function discoverModelTableNames() {
1814
- return appModules.map((module) => module.tableName).filter((tableName) => tableName !== undefined);
1815
- }
1816
-
1817
1827
  // ../../src/core/queue/index.ts
1818
1828
  class Job {
1819
1829
  maxAttempts;
@@ -2124,10 +2134,10 @@ function buildHavingClause(tableName, having, params) {
2124
2134
  return body.length > 0 ? ` HAVING ${body}` : "";
2125
2135
  }
2126
2136
  function buildJoinClause(joins = []) {
2127
- return joins.map((join3) => {
2128
- const joinType = join3.type === "left" ? "LEFT JOIN" : "INNER JOIN";
2129
- const onClause = join3.on.map(({ left, right }) => `${qualifyColumn(left.table, left.column)} = ${qualifyColumn(right.table, right.column)}`).join(" AND ");
2130
- return ` ${joinType} ${quoteIdentifier(join3.table)} ON ${onClause}`;
2137
+ return joins.map((join2) => {
2138
+ const joinType = join2.type === "left" ? "LEFT JOIN" : "INNER JOIN";
2139
+ const onClause = join2.on.map(({ left, right }) => `${qualifyColumn(left.table, left.column)} = ${qualifyColumn(right.table, right.column)}`).join(" AND ");
2140
+ return ` ${joinType} ${quoteIdentifier(join2.table)} ON ${onClause}`;
2131
2141
  }).join("");
2132
2142
  }
2133
2143
  function buildLimitClause(limit) {
@@ -2540,7 +2550,7 @@ class RepositoryQuery {
2540
2550
  const rightRef = parseQualifiedColumn(right);
2541
2551
  const table = type === "inner" ? rightRef.table : rightRef.table;
2542
2552
  const joins = this.queryOptions.joins ?? [];
2543
- const existing = joins.find((join3) => join3.table === table && join3.type === type);
2553
+ const existing = joins.find((join2) => join2.table === table && join2.type === type);
2544
2554
  if (existing) {
2545
2555
  existing.on.push({ left: leftRef, right: rightRef });
2546
2556
  return this;
@@ -3703,9 +3713,6 @@ function createProductionQueue(driver, options = {}) {
3703
3713
  return new ResilientQueue(failedJobs, driver === "async");
3704
3714
  }
3705
3715
 
3706
- // ../../src/bootstrap/queue/defaultJobs.ts
3707
- import { resolveApplicationCache } from "@getstrata/core";
3708
-
3709
3716
  // ../../src/core/jobs/dispatchWebhookJob.ts
3710
3717
  import { createHmac as createHmac2 } from "crypto";
3711
3718
  class DispatchWebhookJob extends Job {
@@ -3798,7 +3805,7 @@ function registerInvalidateCacheOnModelWriteListeners(bus = eventBus) {
3798
3805
  let cache;
3799
3806
  let queue;
3800
3807
  try {
3801
- cache = resolveApplicationCache2();
3808
+ cache = resolveApplicationCache();
3802
3809
  queue = resolveApplicationQueue();
3803
3810
  } catch {
3804
3811
  return;
@@ -3896,7 +3903,7 @@ var queue_default = queueProvider;
3896
3903
 
3897
3904
  // ../../src/core/storage/storage.ts
3898
3905
  import { mkdir, readFile, unlink, writeFile } from "fs/promises";
3899
- import { dirname, join as join3 } from "path";
3906
+ import { dirname, join as join2 } from "path";
3900
3907
  var {S3Client } = globalThis.Bun;
3901
3908
 
3902
3909
  class LocalStorageDriver {
@@ -3908,7 +3915,7 @@ class LocalStorageDriver {
3908
3915
  return this.rootDirectory ?? process.env.STORAGE_PATH ?? "storage";
3909
3916
  }
3910
3917
  resolvePath(path) {
3911
- return join3(this.resolveRootDirectory(), path.replace(/^\/+/, ""));
3918
+ return join2(this.resolveRootDirectory(), path.replace(/^\/+/, ""));
3912
3919
  }
3913
3920
  async put(path, contents) {
3914
3921
  const absolutePath = this.resolvePath(path);
@@ -4041,9 +4048,9 @@ function currentRequestMeta() {
4041
4048
  }
4042
4049
 
4043
4050
  // ../../src/core/view/etaViewEngine.ts
4044
- import { join as join4 } from "path";
4051
+ import { join as join3 } from "path";
4045
4052
  import { Eta } from "eta";
4046
- var DEFAULT_VIEWS_DIRECTORY = join4(process.cwd(), "resources/views");
4053
+ var DEFAULT_VIEWS_DIRECTORY = join3(process.cwd(), "resources/views");
4047
4054
  var DEFAULT_LAYOUT = "layouts/app.eta";
4048
4055
 
4049
4056
  class EtaViewEngine {
@@ -4369,7 +4376,7 @@ function createAppContext() {
4369
4376
  return appContext;
4370
4377
  }
4371
4378
  // ../../src/bootstrap/createWebRoutes.ts
4372
- import { join as join5 } from "path";
4379
+ import { join as join4 } from "path";
4373
4380
 
4374
4381
  // ../../src/core/http/middleware.ts
4375
4382
  function isRouteHandler(value) {
@@ -4703,7 +4710,7 @@ function createWebRoutes(dependencies) {
4703
4710
  registerRoute("GET", "/assets/*", ["global", "web"]);
4704
4711
  const pathname = new URL(request.url).pathname;
4705
4712
  const relativePath = pathname.replace(/^\//, "");
4706
- const file = Bun.file(join5(process.cwd(), "public", relativePath));
4713
+ const file = Bun.file(join4(process.cwd(), "public", relativePath));
4707
4714
  if (!await file.exists()) {
4708
4715
  return htmlResponse("Not Found", { status: 404 });
4709
4716
  }
@@ -4721,9 +4728,6 @@ function mergeWebRoutes(dependencies, routes) {
4721
4728
  ...routes
4722
4729
  };
4723
4730
  }
4724
- // ../../src/bootstrap/http/securedRouteModelBinding.ts
4725
- import { resolveApplicationAuth, resolveApplicationPolicyGate } from "@getstrata/core";
4726
-
4727
4731
  // ../../src/core/crypto/nonCryptographicHash.ts
4728
4732
  function nonCryptographicDigest(input) {
4729
4733
  return Bun.hash(input).toString(16);
@@ -4874,9 +4878,6 @@ function securedBindRouteModelByKey(param, resolver, authorization, handler) {
4874
4878
  return response;
4875
4879
  };
4876
4880
  }
4877
- // ../../src/bootstrap/membershipService.ts
4878
- import { resolveApplicationDependencies } from "@getstrata/core";
4879
-
4880
4881
  // ../../src/core/auth/accessControl.ts
4881
4882
  var ROLE_RANK = {
4882
4883
  member: 1,
@@ -5252,7 +5253,7 @@ export {
5252
5253
  wrapSecuredRouteModelByKey,
5253
5254
  toRouteRequest,
5254
5255
  slugify,
5255
- setActiveApplicationContext2 as setActiveApplicationContext,
5256
+ setActiveApplicationContext,
5256
5257
  securedBindRouteModelByKey,
5257
5258
  securedBindRouteModel,
5258
5259
  scheduleRunCommand,
@@ -5261,18 +5262,19 @@ export {
5261
5262
  routeParams,
5262
5263
  resolveService,
5263
5264
  resolveMembershipService,
5264
- resolveApplicationQueue2 as resolveApplicationQueue,
5265
- resolveApplicationPolicyGate2 as resolveApplicationPolicyGate,
5265
+ resolveApplicationQueue,
5266
+ resolveApplicationPolicyGate,
5266
5267
  resolveApplicationLogger,
5267
- resolveApplicationDependencies2 as resolveApplicationDependencies,
5268
+ resolveApplicationDependencies,
5268
5269
  resolveApplicationConfig,
5269
- resolveApplicationCache3 as resolveApplicationCache,
5270
- resolveApplicationAuth2 as resolveApplicationAuth,
5270
+ resolveApplicationCache,
5271
+ resolveApplicationAuth,
5271
5272
  registerDefaultJobs,
5272
5273
  prefixRouteMap,
5273
5274
  parseFormBody,
5274
5275
  mergeWebRoutes,
5275
5276
  getRequiredDependency,
5277
+ discoverModelTableNames,
5276
5278
  createWebServer,
5277
5279
  createWebRoutes,
5278
5280
  createRouteKernel,
@@ -5281,6 +5283,7 @@ export {
5281
5283
  createAppContext,
5282
5284
  coreProviders,
5283
5285
  collectProviders,
5286
+ cacheTagsForModelWrite,
5284
5287
  assertAppDependenciesComplete,
5285
5288
  appSchedule,
5286
5289
  ServiceContainer,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getstrata/bootstrap",
3
- "version": "0.2.10",
3
+ "version": "0.2.12",
4
4
  "description": "Strata application bootstrap — HttpKernel, DI, web session helpers",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -15,6 +15,11 @@
15
15
  "import": "./dist/index.js",
16
16
  "default": "./dist/index.js"
17
17
  },
18
+ "./cache/modelCacheTags": {
19
+ "types": "./dist/bootstrap/cache/modelCacheTags.d.ts",
20
+ "import": "./dist/entries/cache/modelCacheTags.js",
21
+ "default": "./dist/entries/cache/modelCacheTags.js"
22
+ },
18
23
  "./applicationRegistry": {
19
24
  "types": "./dist/bootstrap/applicationRegistry.d.ts",
20
25
  "import": "./dist/entries/applicationRegistry.js",
@@ -82,14 +87,14 @@
82
87
  "build:bundle": "bun build index.ts --outdir dist --target bun --external bun --external eta --external @getstrata/core",
83
88
  "build:types": "tsc -p tsconfig.types.json",
84
89
  "prepublishOnly": "bun run build",
85
- "build:subpaths": "bun build entries/applicationRegistry.ts entries/config.ts entries/context.ts entries/contracts.ts entries/createWebRoutes.ts entries/http/securedRouteModelBinding.ts entries/httpKernel.ts entries/membershipService.ts entries/queue/defaultJobs.ts entries/providers.ts entries/providers/view.ts --outdir dist --root . --target bun --external bun --external eta --external @getstrata/core",
90
+ "build:subpaths": "bun build entries/applicationRegistry.ts entries/cache/modelCacheTags.ts entries/config.ts entries/context.ts entries/contracts.ts entries/createWebRoutes.ts entries/http/securedRouteModelBinding.ts entries/httpKernel.ts entries/membershipService.ts entries/queue/defaultJobs.ts entries/providers.ts entries/providers/view.ts --outdir dist --root . --target bun --external bun --external eta --external @getstrata/core",
86
91
  "build:shims": "true"
87
92
  },
88
93
  "publishConfig": {
89
94
  "access": "public"
90
95
  },
91
96
  "peerDependencies": {
92
- "@getstrata/core": "^0.5.18",
97
+ "@getstrata/core": "^0.5.20",
93
98
  "typescript": "^5.9.0"
94
99
  }
95
100
  }