@getstrata/core 0.7.3 → 0.7.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @getstrata/core changelog
2
2
 
3
+ ## 0.7.4
4
+
5
+ - Default database pool and query handles live on `globalThis`, so the published `@getstrata/core` bundle and `src/core` share one pool in the same process.
6
+
3
7
  ## 0.7.3
4
8
 
5
9
  - `JsonResource.whenLoaded` returns `null` when a relation is loaded but empty. It does not call the transform, so `new PositionResource(value).toArray()` cannot crash on a missing belongsTo.
package/README.md CHANGED
@@ -65,7 +65,7 @@ import type { Migration } from "@getstrata/core/database/migrations/types";
65
65
  Package name: **`@getstrata/core`** (npm org [`@getstrata`](https://www.npmjs.com/org/getstrata)).
66
66
 
67
67
  1. Add `NPM_TOKEN` to GitHub repository secrets.
68
- 2. Tag a release: `git tag v0.7.3 && git push origin v0.7.3`
68
+ 2. Tag a release: `git tag v0.7.4 && git push origin v0.7.4`
69
69
  3. [Release workflow](../../.github/workflows/release.yml) builds and runs `npm publish --access public`.
70
70
 
71
71
  See [docs/PACKAGING.md](../../docs/PACKAGING.md).
package/dist/index.js CHANGED
@@ -1008,17 +1008,25 @@ class PolicyGate {
1008
1008
  }
1009
1009
  }
1010
1010
  // ../../src/core/database/boundConnection.ts
1011
- var boundConnectionHolder = {
1012
- connection: null
1013
- };
1011
+ var BOUND_CONNECTION_KEY = Symbol.for("@getstrata/boundDatabaseConnection");
1012
+ function boundConnectionState() {
1013
+ const globalRecord = globalThis;
1014
+ const existing = globalRecord[BOUND_CONNECTION_KEY];
1015
+ if (existing) {
1016
+ return existing;
1017
+ }
1018
+ const created = { connection: null };
1019
+ globalRecord[BOUND_CONNECTION_KEY] = created;
1020
+ return created;
1021
+ }
1014
1022
  function bindDatabaseConnection(connection) {
1015
- boundConnectionHolder.connection = connection;
1023
+ boundConnectionState().connection = connection;
1016
1024
  }
1017
1025
  function getBoundDatabaseConnection() {
1018
- return boundConnectionHolder.connection;
1026
+ return boundConnectionState().connection;
1019
1027
  }
1020
1028
  function resetBoundDatabaseConnection() {
1021
- boundConnectionHolder.connection = null;
1029
+ boundConnectionState().connection = null;
1022
1030
  }
1023
1031
  // ../../src/core/database/connectionContext.ts
1024
1032
  var activeConnection = createAsyncContextStore("@getstrata/databaseConnectionContext");
@@ -1057,27 +1065,35 @@ function createDatabaseQueryProxy(pool) {
1057
1065
  }
1058
1066
 
1059
1067
  // ../../src/core/database/defaultConnection.ts
1060
- var defaultPool = {
1061
- connection: null
1062
- };
1063
- var defaultQuery = {
1064
- connection: null
1065
- };
1068
+ var DEFAULT_CONNECTION_KEY = Symbol.for("@getstrata/defaultDatabaseConnection");
1069
+ function defaultConnectionState() {
1070
+ const globalRecord = globalThis;
1071
+ const existing = globalRecord[DEFAULT_CONNECTION_KEY];
1072
+ if (existing) {
1073
+ return existing;
1074
+ }
1075
+ const created = { pool: null, query: null };
1076
+ globalRecord[DEFAULT_CONNECTION_KEY] = created;
1077
+ return created;
1078
+ }
1066
1079
  function registerDefaultDatabasePool(connection) {
1067
- defaultPool.connection = connection;
1068
- defaultQuery.connection = createDatabaseQueryProxy(connection);
1080
+ const holder = defaultConnectionState();
1081
+ holder.pool = connection;
1082
+ holder.query = createDatabaseQueryProxy(connection);
1069
1083
  }
1070
1084
  function getDefaultDatabasePool() {
1071
- if (!defaultPool.connection) {
1085
+ const pool = defaultConnectionState().pool;
1086
+ if (!pool) {
1072
1087
  throw new Error("Default database pool is not registered. Call registerDefaultDatabasePool() during app bootstrap.");
1073
1088
  }
1074
- return defaultPool.connection;
1089
+ return pool;
1075
1090
  }
1076
1091
  function getDefaultDatabaseQuery() {
1077
- if (!defaultQuery.connection) {
1092
+ const query = defaultConnectionState().query;
1093
+ if (!query) {
1078
1094
  throw new Error("Default database query handle is not registered. Call registerDefaultDatabasePool() during app bootstrap.");
1079
1095
  }
1080
- return defaultQuery.connection;
1096
+ return query;
1081
1097
  }
1082
1098
 
1083
1099
  // ../../src/core/security/timingSafeCompare.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getstrata/core",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "description": "Strata Bun framework public API",
5
5
  "type": "module",
6
6
  "license": "MIT",