@getstrata/core 0.5.47 → 0.5.49

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,129 +1 @@
1
- // @bun
2
- // ../../src/core/database/connection.ts
3
- function createDatabaseConnection(source) {
4
- return {
5
- async unsafe(query, params = []) {
6
- return await source.unsafe(query, params);
7
- }
8
- };
9
- }
10
-
11
- // ../../src/core/database/boundConnection.ts
12
- var boundConnectionHolder = {
13
- connection: null
14
- };
15
- function bindDatabaseConnection(connection) {
16
- boundConnectionHolder.connection = connection;
17
- }
18
- function getBoundDatabaseConnection() {
19
- return boundConnectionHolder.connection;
20
- }
21
- function resetBoundDatabaseConnection() {
22
- boundConnectionHolder.connection = null;
23
- }
24
-
25
- // ../../src/core/runtime/asyncContextStore.ts
26
- import { AsyncLocalStorage } from "async_hooks";
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");
41
- function runWithDatabaseConnection(connection, callback) {
42
- return activeConnection.run(connection, callback);
43
- }
44
- function getActiveDatabaseConnection(fallback) {
45
- return activeConnection.getStore() ?? fallback;
46
- }
47
- function hasActiveDatabaseConnection() {
48
- return activeConnection.getStore() !== undefined;
49
- }
50
-
51
- // ../../src/core/database/queryProxy.ts
52
- var POOL_CONNECTION_METHODS = new Set(["begin", "close", "connect"]);
53
- function createDatabaseQueryProxy(pool) {
54
- function resolveDatabase() {
55
- return getActiveDatabaseConnection(pool);
56
- }
57
- function resolveDatabaseForProperty(property) {
58
- if (typeof property === "string" && POOL_CONNECTION_METHODS.has(property)) {
59
- return pool;
60
- }
61
- return resolveDatabase();
62
- }
63
- return new Proxy(function database() {}, {
64
- apply(_target, _thisArg, args) {
65
- return resolveDatabase()(...args);
66
- },
67
- get(_target, property) {
68
- const connection = resolveDatabaseForProperty(property);
69
- const value = connection[property];
70
- return typeof value === "function" ? value.bind(connection) : value;
71
- }
72
- });
73
- }
74
-
75
- // ../../src/core/database/defaultConnection.ts
76
- var defaultPool = {
77
- connection: null
78
- };
79
- var defaultQuery = {
80
- connection: null
81
- };
82
- function registerDefaultDatabasePool(connection) {
83
- defaultPool.connection = connection;
84
- defaultQuery.connection = createDatabaseQueryProxy(connection);
85
- }
86
- function getDefaultDatabasePool() {
87
- if (!defaultPool.connection) {
88
- throw new Error("Default database pool is not registered. Call registerDefaultDatabasePool() during app bootstrap.");
89
- }
90
- return defaultPool.connection;
91
- }
92
- function getDefaultDatabaseQuery() {
93
- if (!defaultQuery.connection) {
94
- throw new Error("Default database query handle is not registered. Call registerDefaultDatabasePool() during app bootstrap.");
95
- }
96
- return defaultQuery.connection;
97
- }
98
-
99
- // ../../src/core/database/repositoryConnection.ts
100
- function resolveRepositoryConnection() {
101
- return getBoundDatabaseConnection() ?? getDefaultDatabaseQuery();
102
- }
103
- var repositoryConnection = new Proxy(function repositoryConnection2() {}, {
104
- apply(_target, _thisArg, args) {
105
- return resolveRepositoryConnection()(...args);
106
- },
107
- get(_target, property) {
108
- const connection = resolveRepositoryConnection();
109
- const value = connection[property];
110
- return typeof value === "function" ? value.bind(connection) : value;
111
- }
112
- });
113
-
114
- // ../../src/core/database/transaction.ts
115
- function supportsTransactions(connection) {
116
- return typeof connection.begin === "function";
117
- }
118
- async function runInTransaction(operation) {
119
- const pool = resolveRepositoryConnection();
120
- if (!supportsTransactions(pool)) {
121
- throw new Error("Active database connection does not support transactions. Bind a client with begin() via bindDatabaseConnection.");
122
- }
123
- return await pool.begin(async (transaction) => {
124
- return await operation(createDatabaseConnection(transaction));
125
- });
126
- }
127
- export {
128
- runInTransaction
129
- };
1
+ export * from "../../index.js";
@@ -96,9 +96,6 @@ function runWithTenant(tenant, callback) {
96
96
  function currentTenant() {
97
97
  return tenantContext.getStore() ?? null;
98
98
  }
99
- function currentTenantId() {
100
- return currentTenant()?.id ?? 1;
101
- }
102
99
  function rateLimitMultiplierForPlan(plan) {
103
100
  switch (plan) {
104
101
  case "enterprise":
@@ -107,9 +107,6 @@ function runWithTenant(tenant, callback) {
107
107
  function currentTenant() {
108
108
  return tenantContext.getStore() ?? null;
109
109
  }
110
- function currentTenantId() {
111
- return currentTenant()?.id ?? 1;
112
- }
113
110
  function rateLimitMultiplierForPlan(plan) {
114
111
  switch (plan) {
115
112
  case "enterprise":
@@ -96,9 +96,6 @@ function runWithTenant(tenant, callback) {
96
96
  function currentTenant() {
97
97
  return tenantContext.getStore() ?? null;
98
98
  }
99
- function currentTenantId() {
100
- return currentTenant()?.id ?? 1;
101
- }
102
99
  function rateLimitMultiplierForPlan(plan) {
103
100
  switch (plan) {
104
101
  case "enterprise":
@@ -285,9 +285,6 @@ function runWithTenant(tenant, callback) {
285
285
  function currentTenant() {
286
286
  return tenantContext.getStore() ?? null;
287
287
  }
288
- function currentTenantId() {
289
- return currentTenant()?.id ?? 1;
290
- }
291
288
  function rateLimitMultiplierForPlan(plan) {
292
289
  switch (plan) {
293
290
  case "enterprise":
@@ -33,9 +33,6 @@ function runWithTenant(tenant, callback) {
33
33
  function currentTenant() {
34
34
  return tenantContext.getStore() ?? null;
35
35
  }
36
- function currentTenantId() {
37
- return currentTenant()?.id ?? 1;
38
- }
39
36
  function rateLimitMultiplierForPlan(plan) {
40
37
  switch (plan) {
41
38
  case "enterprise":