@burdenoff/be-sdk 2026.510.79
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/README.md +173 -0
- package/configs/eslint/index.js +492 -0
- package/configs/tsconfig/tsconfig.json +53 -0
- package/dist/EventQueueFactory-6NMSGECR.js +8 -0
- package/dist/EventQueueFactory-6NMSGECR.js.map +1 -0
- package/dist/auth/index.d.ts +66 -0
- package/dist/auth/index.js +8 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/cache/index.d.ts +2 -0
- package/dist/cache/index.js +6 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/captcha/index.d.ts +1 -0
- package/dist/captcha/index.js +4 -0
- package/dist/captcha/index.js.map +1 -0
- package/dist/chunk-2HANKZZM.js +245 -0
- package/dist/chunk-2HANKZZM.js.map +1 -0
- package/dist/chunk-2SD5L2F2.js +816 -0
- package/dist/chunk-2SD5L2F2.js.map +1 -0
- package/dist/chunk-3O2RQOPV.js +1068 -0
- package/dist/chunk-3O2RQOPV.js.map +1 -0
- package/dist/chunk-4B43DZIS.js +560 -0
- package/dist/chunk-4B43DZIS.js.map +1 -0
- package/dist/chunk-4XAEES25.js +2444 -0
- package/dist/chunk-4XAEES25.js.map +1 -0
- package/dist/chunk-4XGGWW36.js +1405 -0
- package/dist/chunk-4XGGWW36.js.map +1 -0
- package/dist/chunk-5LXDPGDH.js +245 -0
- package/dist/chunk-5LXDPGDH.js.map +1 -0
- package/dist/chunk-AI7L22ZJ.js +472 -0
- package/dist/chunk-AI7L22ZJ.js.map +1 -0
- package/dist/chunk-CBZNP6RF.js +286 -0
- package/dist/chunk-CBZNP6RF.js.map +1 -0
- package/dist/chunk-ELLX3K54.js +613 -0
- package/dist/chunk-ELLX3K54.js.map +1 -0
- package/dist/chunk-F5XEAGHQ.js +1875 -0
- package/dist/chunk-F5XEAGHQ.js.map +1 -0
- package/dist/chunk-FNZEQOJY.js +628 -0
- package/dist/chunk-FNZEQOJY.js.map +1 -0
- package/dist/chunk-GTEMQXCA.js +516 -0
- package/dist/chunk-GTEMQXCA.js.map +1 -0
- package/dist/chunk-HIWTWIGQ.js +226 -0
- package/dist/chunk-HIWTWIGQ.js.map +1 -0
- package/dist/chunk-IYE2NTRX.js +764 -0
- package/dist/chunk-IYE2NTRX.js.map +1 -0
- package/dist/chunk-J26YGR2U.js +1484 -0
- package/dist/chunk-J26YGR2U.js.map +1 -0
- package/dist/chunk-JG2FTZPI.js +509 -0
- package/dist/chunk-JG2FTZPI.js.map +1 -0
- package/dist/chunk-JVBTNSPG.js +1551 -0
- package/dist/chunk-JVBTNSPG.js.map +1 -0
- package/dist/chunk-L7ZMN2FJ.js +12 -0
- package/dist/chunk-L7ZMN2FJ.js.map +1 -0
- package/dist/chunk-M5IMU3US.js +473 -0
- package/dist/chunk-M5IMU3US.js.map +1 -0
- package/dist/chunk-MLW2HPS5.js +1267 -0
- package/dist/chunk-MLW2HPS5.js.map +1 -0
- package/dist/chunk-MNCGUYLJ.js +269 -0
- package/dist/chunk-MNCGUYLJ.js.map +1 -0
- package/dist/chunk-MOCUBSTW.js +373 -0
- package/dist/chunk-MOCUBSTW.js.map +1 -0
- package/dist/chunk-NGMEI42S.js +103 -0
- package/dist/chunk-NGMEI42S.js.map +1 -0
- package/dist/chunk-NUB5GQTU.js +270 -0
- package/dist/chunk-NUB5GQTU.js.map +1 -0
- package/dist/chunk-OVSYMNCI.js +145 -0
- package/dist/chunk-OVSYMNCI.js.map +1 -0
- package/dist/chunk-QLVKMWFA.js +94 -0
- package/dist/chunk-QLVKMWFA.js.map +1 -0
- package/dist/chunk-SAG6ZYWQ.js +89 -0
- package/dist/chunk-SAG6ZYWQ.js.map +1 -0
- package/dist/chunk-SAK2JCA7.js +198 -0
- package/dist/chunk-SAK2JCA7.js.map +1 -0
- package/dist/chunk-SBS4S2PJ.js +100 -0
- package/dist/chunk-SBS4S2PJ.js.map +1 -0
- package/dist/chunk-SNEOLWXT.js +148 -0
- package/dist/chunk-SNEOLWXT.js.map +1 -0
- package/dist/chunk-TKBD2ONF.js +564 -0
- package/dist/chunk-TKBD2ONF.js.map +1 -0
- package/dist/chunk-UBXFIIAW.js +127 -0
- package/dist/chunk-UBXFIIAW.js.map +1 -0
- package/dist/chunk-VI4VSNTI.js +57 -0
- package/dist/chunk-VI4VSNTI.js.map +1 -0
- package/dist/chunk-VWCN5PMD.js +268 -0
- package/dist/chunk-VWCN5PMD.js.map +1 -0
- package/dist/chunk-XC2YD6CF.js +913 -0
- package/dist/chunk-XC2YD6CF.js.map +1 -0
- package/dist/chunk-XE4OXN2W.js +10 -0
- package/dist/chunk-XE4OXN2W.js.map +1 -0
- package/dist/chunk-YMZEUTD2.js +110 -0
- package/dist/chunk-YMZEUTD2.js.map +1 -0
- package/dist/chunk-Z4IRLBWO.js +758 -0
- package/dist/chunk-Z4IRLBWO.js.map +1 -0
- package/dist/client/internal-client.d.ts +7 -0
- package/dist/client/internal-client.js +5 -0
- package/dist/client/internal-client.js.map +1 -0
- package/dist/client-CSjIrYKS.d.ts +77 -0
- package/dist/config-UKE2E3BW.js +4 -0
- package/dist/config-UKE2E3BW.js.map +1 -0
- package/dist/crypto/index.d.ts +1 -0
- package/dist/crypto/index.js +4 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/database/index.d.ts +117 -0
- package/dist/database/index.js +7 -0
- package/dist/database/index.js.map +1 -0
- package/dist/dataloader/index.d.ts +1 -0
- package/dist/dataloader/index.js +4 -0
- package/dist/dataloader/index.js.map +1 -0
- package/dist/esm-K6H7EIWK.js +1450 -0
- package/dist/esm-K6H7EIWK.js.map +1 -0
- package/dist/event-queue/index.d.ts +6 -0
- package/dist/event-queue/index.js +10 -0
- package/dist/event-queue/index.js.map +1 -0
- package/dist/export/index.d.ts +2 -0
- package/dist/export/index.js +9 -0
- package/dist/export/index.js.map +1 -0
- package/dist/feature-flags/index.d.ts +1 -0
- package/dist/feature-flags/index.js +4 -0
- package/dist/feature-flags/index.js.map +1 -0
- package/dist/gateway/index.d.ts +4 -0
- package/dist/gateway/index.js +8 -0
- package/dist/gateway/index.js.map +1 -0
- package/dist/gateway/security/index.d.ts +2 -0
- package/dist/gateway/security/index.js +5 -0
- package/dist/gateway/security/index.js.map +1 -0
- package/dist/graph/index.d.ts +9 -0
- package/dist/graph/index.js +13 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph-emitter-Bk0FqD53.d.ts +47 -0
- package/dist/graphql/index.d.ts +2 -0
- package/dist/graphql/index.js +7 -0
- package/dist/graphql/index.js.map +1 -0
- package/dist/graphql/services/index.d.ts +24 -0
- package/dist/graphql/services/index.js +5 -0
- package/dist/graphql/services/index.js.map +1 -0
- package/dist/graphql-BAVrUgBF.d.ts +22 -0
- package/dist/i18n/index.d.ts +2 -0
- package/dist/i18n/index.js +5 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/i18n-DA6IPnYy.d.ts +101 -0
- package/dist/index-4gKQKZ2B.d.ts +71 -0
- package/dist/index-B18rrFru.d.ts +42 -0
- package/dist/index-B70b5mYS.d.ts +33 -0
- package/dist/index-BMq3lFjj.d.ts +247 -0
- package/dist/index-BODgvRtL.d.ts +316 -0
- package/dist/index-BS2idbnr.d.ts +874 -0
- package/dist/index-BV3G48cH.d.ts +124 -0
- package/dist/index-CHbVw5M7.d.ts +73 -0
- package/dist/index-Cq_xNjcv.d.ts +602 -0
- package/dist/index-CrQgidpx.d.ts +77 -0
- package/dist/index-CyVEg86m.d.ts +309 -0
- package/dist/index-DOcBnmMe.d.ts +166 -0
- package/dist/index-DSOpj8DI.d.ts +17 -0
- package/dist/index-DW9q22GH.d.ts +75 -0
- package/dist/index-DlFDFyWD.d.ts +55 -0
- package/dist/index-DoK0bjhH.d.ts +607 -0
- package/dist/index-Dtf6FBaD.d.ts +199 -0
- package/dist/index-KVWGHMbS.d.ts +415 -0
- package/dist/index-PaojfSdd.d.ts +71 -0
- package/dist/index-RU_M5c74.d.ts +163 -0
- package/dist/index-UhkH2eaB.d.ts +192 -0
- package/dist/index-e_18DzAg.d.ts +18 -0
- package/dist/index-jOuh_TKn.d.ts +59 -0
- package/dist/index.d.ts +584 -0
- package/dist/index.js +2626 -0
- package/dist/index.js.map +1 -0
- package/dist/init/index.d.ts +2 -0
- package/dist/init/index.js +12 -0
- package/dist/init/index.js.map +1 -0
- package/dist/instrumentation/index.d.ts +3 -0
- package/dist/instrumentation/index.js +5 -0
- package/dist/instrumentation/index.js.map +1 -0
- package/dist/layer/index.d.ts +2 -0
- package/dist/layer/index.js +6 -0
- package/dist/layer/index.js.map +1 -0
- package/dist/layer-DDip18KY.d.ts +67 -0
- package/dist/logger/index.d.ts +2 -0
- package/dist/logger/index.js +4 -0
- package/dist/logger/index.js.map +1 -0
- package/dist/middleware/index.d.ts +3 -0
- package/dist/middleware/index.js +5 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/notifications/index.d.ts +4 -0
- package/dist/notifications/index.js +7 -0
- package/dist/notifications/index.js.map +1 -0
- package/dist/observability/index.d.ts +3 -0
- package/dist/observability/index.js +5 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/pino-logger-RYLGXPHZ.js +5 -0
- package/dist/pino-logger-RYLGXPHZ.js.map +1 -0
- package/dist/prisma/generator/index.d.ts +1 -0
- package/dist/prisma/generator/index.js +228 -0
- package/dist/prisma/generator/index.js.map +1 -0
- package/dist/prisma/index.d.ts +5 -0
- package/dist/prisma/index.js +12 -0
- package/dist/prisma/index.js.map +1 -0
- package/dist/prisma-extension-krXnYnrN.d.ts +30 -0
- package/dist/rbac/index.d.ts +116 -0
- package/dist/rbac/index.js +7 -0
- package/dist/rbac/index.js.map +1 -0
- package/dist/sdk-THO3IWEE.js +136 -0
- package/dist/sdk-THO3IWEE.js.map +1 -0
- package/dist/server/index.d.ts +359 -0
- package/dist/server/index.js +884 -0
- package/dist/server/index.js.map +1 -0
- package/dist/telemetry/index.d.ts +83 -0
- package/dist/telemetry/index.js +209 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/temporal/index.d.ts +148 -0
- package/dist/temporal/index.js +6 -0
- package/dist/temporal/index.js.map +1 -0
- package/dist/tracker/index.d.ts +5 -0
- package/dist/tracker/index.js +9 -0
- package/dist/tracker/index.js.map +1 -0
- package/dist/types-Bo2wkjSP.d.ts +35 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/workspace-guard-LHBNK4TG.js +5 -0
- package/dist/workspace-guard-LHBNK4TG.js.map +1 -0
- package/package.json +241 -0
|
@@ -0,0 +1,816 @@
|
|
|
1
|
+
import { withWorkspaceContextSync, withWorkspaceContext, setWorkspaceContext, injectWhereWorkspaceId, getWorkspaceContext, addWorkspaceExtension } from './chunk-GTEMQXCA.js';
|
|
2
|
+
import { addGraphExtension } from './chunk-TKBD2ONF.js';
|
|
3
|
+
import { getGraphEventEmitter } from './chunk-ELLX3K54.js';
|
|
4
|
+
import { logger } from './chunk-CBZNP6RF.js';
|
|
5
|
+
import { __export, __name } from './chunk-XE4OXN2W.js';
|
|
6
|
+
import { PrismaPg } from '@prisma/adapter-pg';
|
|
7
|
+
import { Pool } from 'pg';
|
|
8
|
+
import { createRequire } from 'module';
|
|
9
|
+
|
|
10
|
+
// src/prisma/index.ts
|
|
11
|
+
var prisma_exports = {};
|
|
12
|
+
__export(prisma_exports, {
|
|
13
|
+
PrismaClientWrapper: () => PrismaClientWrapper,
|
|
14
|
+
addWorkspaceExtension: () => addWorkspaceExtension,
|
|
15
|
+
buildContextWhereClause: () => buildContextWhereClause,
|
|
16
|
+
buildContextWhereConditions: () => buildContextWhereConditions,
|
|
17
|
+
checkDatabaseHealth: () => checkDatabaseHealth,
|
|
18
|
+
configurePrismaLogging: () => configurePrismaLogging,
|
|
19
|
+
contextMatches: () => contextMatches,
|
|
20
|
+
createConnectionPool: () => createConnectionPool,
|
|
21
|
+
createContextFromSDK: () => createContextFromSDK,
|
|
22
|
+
createDatabaseClient: () => createDatabaseClient,
|
|
23
|
+
createDatabaseClientFromEnv: () => createDatabaseClientFromEnv,
|
|
24
|
+
createPrismaAdapter: () => createPrismaAdapter,
|
|
25
|
+
createPrismaClient: () => createPrismaClient,
|
|
26
|
+
extractFieldsFromModel: () => extractFieldsFromModel,
|
|
27
|
+
getAllModelNames: () => getAllModelNames,
|
|
28
|
+
getDatabaseManager: () => getDatabaseManager,
|
|
29
|
+
getDatabaseProductName: () => getDatabaseProductName,
|
|
30
|
+
getDatabaseStats: () => getDatabaseStats,
|
|
31
|
+
getDatabaseVersion: () => getDatabaseVersion,
|
|
32
|
+
getDb: () => getDb,
|
|
33
|
+
getModelFields: () => getModelFields,
|
|
34
|
+
getWorkspaceContext: () => getWorkspaceContext,
|
|
35
|
+
hasModel: () => hasModel,
|
|
36
|
+
initializeDatabase: () => initializeDatabase,
|
|
37
|
+
initializeDatabaseWithConfig: () => initializeDatabaseWithConfig,
|
|
38
|
+
injectWhereWorkspaceId: () => injectWhereWorkspaceId,
|
|
39
|
+
isDatabaseInitialized: () => isDatabaseInitialized,
|
|
40
|
+
loadGeneratedFields: () => loadGeneratedFields,
|
|
41
|
+
mergeContext: () => mergeContext,
|
|
42
|
+
parseContext: () => parseContext,
|
|
43
|
+
resetDatabaseManager: () => resetDatabaseManager,
|
|
44
|
+
setWorkspaceContext: () => setWorkspaceContext,
|
|
45
|
+
testConnection: () => testConnection,
|
|
46
|
+
toContextJson: () => toContextJson,
|
|
47
|
+
withWorkspaceContext: () => withWorkspaceContext,
|
|
48
|
+
withWorkspaceContextSync: () => withWorkspaceContextSync
|
|
49
|
+
});
|
|
50
|
+
function createConnectionPool(config) {
|
|
51
|
+
return new Pool({
|
|
52
|
+
connectionString: config.databaseUrl,
|
|
53
|
+
max: config.maxConnections ?? 20,
|
|
54
|
+
idleTimeoutMillis: config.idleTimeoutMillis ?? 3e4,
|
|
55
|
+
connectionTimeoutMillis: config.connectionTimeoutMillis ?? 1e4
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
__name(createConnectionPool, "createConnectionPool");
|
|
59
|
+
function createPrismaAdapter(pool) {
|
|
60
|
+
return new PrismaPg(pool);
|
|
61
|
+
}
|
|
62
|
+
__name(createPrismaAdapter, "createPrismaAdapter");
|
|
63
|
+
function configurePrismaLogging(client, config) {
|
|
64
|
+
const isDevelopment = process.env["NODE_ENV"] === "development";
|
|
65
|
+
const slowQueryThreshold = config.slowQueryThreshold ?? (isDevelopment ? 100 : 500);
|
|
66
|
+
if (config.enableQueryLogging ?? isDevelopment) {
|
|
67
|
+
client.$on("query", (e) => {
|
|
68
|
+
if ("query" in e && "duration" in e) {
|
|
69
|
+
if (e.duration > slowQueryThreshold) {
|
|
70
|
+
logger.warn("[Prisma] Slow query detected", {
|
|
71
|
+
query: e.query.substring(0, 200) + (e.query.length > 200 ? "..." : ""),
|
|
72
|
+
params: e.params,
|
|
73
|
+
duration: `${e.duration}ms`
|
|
74
|
+
});
|
|
75
|
+
} else {
|
|
76
|
+
logger.debug("[Prisma] Query", {
|
|
77
|
+
query: e.query.substring(0, 100) + (e.query.length > 100 ? "..." : ""),
|
|
78
|
+
duration: `${e.duration}ms`
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
client.$on("error", (e) => {
|
|
85
|
+
if ("message" in e) {
|
|
86
|
+
logger.error("[Prisma] Database error", {
|
|
87
|
+
message: e.message,
|
|
88
|
+
target: e.target
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
client.$on("warn", (e) => {
|
|
93
|
+
if ("message" in e) {
|
|
94
|
+
logger.warn("[Prisma] Database warning", {
|
|
95
|
+
message: e.message,
|
|
96
|
+
target: e.target
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
return client;
|
|
101
|
+
}
|
|
102
|
+
__name(configurePrismaLogging, "configurePrismaLogging");
|
|
103
|
+
var PrismaClientWrapper = class {
|
|
104
|
+
static {
|
|
105
|
+
__name(this, "PrismaClientWrapper");
|
|
106
|
+
}
|
|
107
|
+
client;
|
|
108
|
+
pool;
|
|
109
|
+
connectionState = {
|
|
110
|
+
isConnected: false,
|
|
111
|
+
attempts: 0
|
|
112
|
+
};
|
|
113
|
+
isDisconnecting = false;
|
|
114
|
+
constructor(client, pool, config) {
|
|
115
|
+
this.client = client;
|
|
116
|
+
this.pool = pool;
|
|
117
|
+
configurePrismaLogging(this.client, config);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Get the Prisma client instance
|
|
121
|
+
*/
|
|
122
|
+
getClient() {
|
|
123
|
+
return this.client;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Get the connection pool
|
|
127
|
+
*/
|
|
128
|
+
getPool() {
|
|
129
|
+
return this.pool;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Get connection state
|
|
133
|
+
*/
|
|
134
|
+
getConnectionState() {
|
|
135
|
+
return {
|
|
136
|
+
...this.connectionState
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Connect to database with retry logic
|
|
141
|
+
*/
|
|
142
|
+
async connect(retries = 5, delay = 1e3) {
|
|
143
|
+
if (this.connectionState.isConnected) {
|
|
144
|
+
logger.info("[Prisma] Already connected to database");
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
for (let attempt = 1; attempt <= retries; attempt++) {
|
|
148
|
+
this.connectionState.attempts = attempt;
|
|
149
|
+
try {
|
|
150
|
+
await this.client.$connect();
|
|
151
|
+
this.connectionState.isConnected = true;
|
|
152
|
+
this.connectionState.lastConnectedAt = /* @__PURE__ */ new Date();
|
|
153
|
+
this.connectionState.lastError = void 0;
|
|
154
|
+
logger.info("[Prisma] Successfully connected to database");
|
|
155
|
+
return;
|
|
156
|
+
} catch (error) {
|
|
157
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
158
|
+
this.connectionState.lastError = errorMessage;
|
|
159
|
+
logger.error(`[Prisma] Connection attempt ${attempt}/${retries} failed`, {
|
|
160
|
+
error: errorMessage
|
|
161
|
+
});
|
|
162
|
+
if (attempt === retries) {
|
|
163
|
+
logger.error("[Prisma] Max connection retries reached");
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
166
|
+
const waitTime = delay * Math.pow(2, attempt - 1);
|
|
167
|
+
logger.info(`[Prisma] Retrying in ${waitTime}ms...`);
|
|
168
|
+
await new Promise((resolve) => setTimeout(resolve, waitTime));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Gracefully disconnect from database
|
|
174
|
+
*/
|
|
175
|
+
async disconnect() {
|
|
176
|
+
if (this.isDisconnecting) {
|
|
177
|
+
logger.debug("[Prisma] Disconnect already in progress, skipping");
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (!this.connectionState.isConnected) {
|
|
181
|
+
logger.info("[Prisma] Database already disconnected");
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
this.isDisconnecting = true;
|
|
185
|
+
try {
|
|
186
|
+
await this.client.$disconnect();
|
|
187
|
+
await this.pool.end();
|
|
188
|
+
this.connectionState.isConnected = false;
|
|
189
|
+
logger.info("[Prisma] Successfully disconnected from database");
|
|
190
|
+
} catch (error) {
|
|
191
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
192
|
+
if (errorMessage.includes("Called end on pool more than once")) {
|
|
193
|
+
logger.debug("[Prisma] Pool already ended, ignoring duplicate end call");
|
|
194
|
+
this.connectionState.isConnected = false;
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
logger.error("[Prisma] Error disconnecting from database", {
|
|
198
|
+
error: errorMessage
|
|
199
|
+
});
|
|
200
|
+
throw error;
|
|
201
|
+
} finally {
|
|
202
|
+
this.isDisconnecting = false;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Register graceful shutdown handlers
|
|
207
|
+
*/
|
|
208
|
+
registerShutdownHandlers() {
|
|
209
|
+
const shutdownHandler = /* @__PURE__ */ __name(async (signal) => {
|
|
210
|
+
logger.info(`[Prisma] Received ${signal}, starting graceful shutdown...`);
|
|
211
|
+
try {
|
|
212
|
+
await this.disconnect();
|
|
213
|
+
process.exit(0);
|
|
214
|
+
} catch (error) {
|
|
215
|
+
logger.error("[Prisma] Error during graceful shutdown", {
|
|
216
|
+
error: error instanceof Error ? error.message : String(error)
|
|
217
|
+
});
|
|
218
|
+
process.exit(1);
|
|
219
|
+
}
|
|
220
|
+
}, "shutdownHandler");
|
|
221
|
+
process.on("SIGINT", () => void shutdownHandler("SIGINT"));
|
|
222
|
+
process.on("SIGTERM", () => void shutdownHandler("SIGTERM"));
|
|
223
|
+
process.on("beforeExit", () => void this.disconnect());
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
function createPrismaClient(PrismaClientConstructor, config) {
|
|
227
|
+
const isDevelopment = process.env["NODE_ENV"] === "development";
|
|
228
|
+
const pool = createConnectionPool(config);
|
|
229
|
+
const adapter = createPrismaAdapter(pool);
|
|
230
|
+
const logLevels = config.logLevels ?? (isDevelopment ? [
|
|
231
|
+
{
|
|
232
|
+
emit: "event",
|
|
233
|
+
level: "query"
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
emit: "event",
|
|
237
|
+
level: "info"
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
emit: "event",
|
|
241
|
+
level: "warn"
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
emit: "event",
|
|
245
|
+
level: "error"
|
|
246
|
+
}
|
|
247
|
+
] : [
|
|
248
|
+
{
|
|
249
|
+
emit: "event",
|
|
250
|
+
level: "warn"
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
emit: "event",
|
|
254
|
+
level: "error"
|
|
255
|
+
}
|
|
256
|
+
]);
|
|
257
|
+
const client = new PrismaClientConstructor({
|
|
258
|
+
adapter,
|
|
259
|
+
log: logLevels
|
|
260
|
+
});
|
|
261
|
+
return new PrismaClientWrapper(client, pool, config);
|
|
262
|
+
}
|
|
263
|
+
__name(createPrismaClient, "createPrismaClient");
|
|
264
|
+
|
|
265
|
+
// src/prisma/factory.ts
|
|
266
|
+
function createDatabaseClient(PrismaClientConstructor, config) {
|
|
267
|
+
const { productName, enableGraphExtension = process.env["GRAPH_MIDDLEWARE_ENABLED"] !== "false", graphEventEmitter, enableWorkspaceExtension = process.env["WORKSPACE_EXTENSION_ENABLED"] !== "false", workspaceExtensionConfig, registerShutdownHandlers = true, ...prismaConfig } = config;
|
|
268
|
+
const wrapper = createPrismaClient(PrismaClientConstructor, prismaConfig);
|
|
269
|
+
const baseClient = wrapper.getClient();
|
|
270
|
+
let extendedClient;
|
|
271
|
+
if (enableGraphExtension) {
|
|
272
|
+
const eventEmitter = graphEventEmitter ?? getGraphEventEmitter();
|
|
273
|
+
const graphConfig = {
|
|
274
|
+
enabled: true,
|
|
275
|
+
productName,
|
|
276
|
+
eventEmitter
|
|
277
|
+
};
|
|
278
|
+
extendedClient = addGraphExtension(baseClient, graphConfig);
|
|
279
|
+
logger.info("[Database] Graph extension enabled", {
|
|
280
|
+
productName
|
|
281
|
+
});
|
|
282
|
+
} else {
|
|
283
|
+
extendedClient = baseClient;
|
|
284
|
+
logger.info("[Database] Graph extension disabled");
|
|
285
|
+
}
|
|
286
|
+
if (enableWorkspaceExtension) {
|
|
287
|
+
extendedClient = addWorkspaceExtension(extendedClient, workspaceExtensionConfig);
|
|
288
|
+
logger.info("[Database] Workspace extension enabled", {
|
|
289
|
+
productName
|
|
290
|
+
});
|
|
291
|
+
} else {
|
|
292
|
+
logger.info("[Database] Workspace extension disabled");
|
|
293
|
+
}
|
|
294
|
+
const db = extendedClient;
|
|
295
|
+
db["client"] = db;
|
|
296
|
+
if (registerShutdownHandlers) {
|
|
297
|
+
wrapper.registerShutdownHandlers();
|
|
298
|
+
logger.debug("[Database] Shutdown handlers registered");
|
|
299
|
+
}
|
|
300
|
+
return {
|
|
301
|
+
db,
|
|
302
|
+
wrapper,
|
|
303
|
+
connect: /* @__PURE__ */ __name((retries, delay) => wrapper.connect(retries, delay), "connect"),
|
|
304
|
+
disconnect: /* @__PURE__ */ __name(() => wrapper.disconnect(), "disconnect")
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
__name(createDatabaseClient, "createDatabaseClient");
|
|
308
|
+
function createDatabaseClientFromEnv(PrismaClientConstructor, productName, overrides) {
|
|
309
|
+
const databaseUrl = process.env["DATABASE_URL"];
|
|
310
|
+
if (!databaseUrl) {
|
|
311
|
+
throw new Error("DATABASE_URL environment variable is required");
|
|
312
|
+
}
|
|
313
|
+
const isDevelopment = process.env["NODE_ENV"] === "development";
|
|
314
|
+
const config = {
|
|
315
|
+
productName,
|
|
316
|
+
databaseUrl,
|
|
317
|
+
maxConnections: parseInt(process.env["DATABASE_MAX_CONNECTIONS"] || "20", 10),
|
|
318
|
+
idleTimeoutMillis: parseInt(process.env["DATABASE_IDLE_TIMEOUT"] || "30000", 10),
|
|
319
|
+
connectionTimeoutMillis: parseInt(process.env["DATABASE_CONNECTION_TIMEOUT"] || "10000", 10),
|
|
320
|
+
enableQueryLogging: isDevelopment,
|
|
321
|
+
slowQueryThreshold: isDevelopment ? 100 : 500,
|
|
322
|
+
...overrides
|
|
323
|
+
};
|
|
324
|
+
return createDatabaseClient(PrismaClientConstructor, config);
|
|
325
|
+
}
|
|
326
|
+
__name(createDatabaseClientFromEnv, "createDatabaseClientFromEnv");
|
|
327
|
+
|
|
328
|
+
// src/prisma/manager.ts
|
|
329
|
+
var state = {
|
|
330
|
+
initialized: false,
|
|
331
|
+
productName: null,
|
|
332
|
+
client: null
|
|
333
|
+
};
|
|
334
|
+
function initializeDatabase(PrismaClientConstructor, productName, config) {
|
|
335
|
+
if (state.initialized) {
|
|
336
|
+
if (state.productName !== productName) {
|
|
337
|
+
throw new Error(`Database already initialized for product "${state.productName}". Cannot reinitialize for "${productName}".`);
|
|
338
|
+
}
|
|
339
|
+
logger.debug("[DatabaseManager] Already initialized, returning existing client", {
|
|
340
|
+
productName
|
|
341
|
+
});
|
|
342
|
+
return state.client;
|
|
343
|
+
}
|
|
344
|
+
const client = createDatabaseClientFromEnv(PrismaClientConstructor, productName, config);
|
|
345
|
+
state.initialized = true;
|
|
346
|
+
state.productName = productName;
|
|
347
|
+
state.client = client;
|
|
348
|
+
logger.info("[DatabaseManager] Database initialized", {
|
|
349
|
+
productName
|
|
350
|
+
});
|
|
351
|
+
return client;
|
|
352
|
+
}
|
|
353
|
+
__name(initializeDatabase, "initializeDatabase");
|
|
354
|
+
function initializeDatabaseWithConfig(PrismaClientConstructor, config) {
|
|
355
|
+
const { productName } = config;
|
|
356
|
+
if (state.initialized) {
|
|
357
|
+
if (state.productName !== productName) {
|
|
358
|
+
throw new Error(`Database already initialized for product "${state.productName}". Cannot reinitialize for "${productName}".`);
|
|
359
|
+
}
|
|
360
|
+
logger.debug("[DatabaseManager] Already initialized, returning existing client", {
|
|
361
|
+
productName
|
|
362
|
+
});
|
|
363
|
+
return state.client;
|
|
364
|
+
}
|
|
365
|
+
const client = createDatabaseClient(PrismaClientConstructor, config);
|
|
366
|
+
state.initialized = true;
|
|
367
|
+
state.productName = productName;
|
|
368
|
+
state.client = client;
|
|
369
|
+
logger.info("[DatabaseManager] Database initialized with custom config", {
|
|
370
|
+
productName
|
|
371
|
+
});
|
|
372
|
+
return client;
|
|
373
|
+
}
|
|
374
|
+
__name(initializeDatabaseWithConfig, "initializeDatabaseWithConfig");
|
|
375
|
+
function getDb() {
|
|
376
|
+
if (!state.initialized || !state.client) {
|
|
377
|
+
throw new Error("Database not initialized. Call initializeDatabase() at application startup before using getDb().");
|
|
378
|
+
}
|
|
379
|
+
return state.client.db;
|
|
380
|
+
}
|
|
381
|
+
__name(getDb, "getDb");
|
|
382
|
+
function getDatabaseManager() {
|
|
383
|
+
if (!state.initialized || !state.client) {
|
|
384
|
+
throw new Error("Database not initialized. Call initializeDatabase() at application startup before using getDatabaseManager().");
|
|
385
|
+
}
|
|
386
|
+
return state.client;
|
|
387
|
+
}
|
|
388
|
+
__name(getDatabaseManager, "getDatabaseManager");
|
|
389
|
+
function isDatabaseInitialized() {
|
|
390
|
+
return state.initialized;
|
|
391
|
+
}
|
|
392
|
+
__name(isDatabaseInitialized, "isDatabaseInitialized");
|
|
393
|
+
function getDatabaseProductName() {
|
|
394
|
+
return state.productName;
|
|
395
|
+
}
|
|
396
|
+
__name(getDatabaseProductName, "getDatabaseProductName");
|
|
397
|
+
async function resetDatabaseManager() {
|
|
398
|
+
if (state.client) {
|
|
399
|
+
try {
|
|
400
|
+
await state.client.disconnect();
|
|
401
|
+
} catch (error) {
|
|
402
|
+
logger.warn("[DatabaseManager] Error during disconnect on reset", {
|
|
403
|
+
error
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
state.initialized = false;
|
|
408
|
+
state.productName = null;
|
|
409
|
+
state.client = null;
|
|
410
|
+
logger.debug("[DatabaseManager] Database manager reset");
|
|
411
|
+
}
|
|
412
|
+
__name(resetDatabaseManager, "resetDatabaseManager");
|
|
413
|
+
|
|
414
|
+
// src/prisma/health.ts
|
|
415
|
+
async function checkDatabaseHealth(client) {
|
|
416
|
+
try {
|
|
417
|
+
const start = Date.now();
|
|
418
|
+
await client.$queryRaw`SELECT 1`;
|
|
419
|
+
const latency = Date.now() - start;
|
|
420
|
+
return {
|
|
421
|
+
healthy: true,
|
|
422
|
+
latency
|
|
423
|
+
};
|
|
424
|
+
} catch (error) {
|
|
425
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
426
|
+
logger.error("[Prisma] Health check failed", {
|
|
427
|
+
error: errorMessage
|
|
428
|
+
});
|
|
429
|
+
return {
|
|
430
|
+
healthy: false,
|
|
431
|
+
error: errorMessage
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
__name(checkDatabaseHealth, "checkDatabaseHealth");
|
|
436
|
+
async function testConnection(client) {
|
|
437
|
+
try {
|
|
438
|
+
await client.$queryRaw`SELECT 1`;
|
|
439
|
+
return true;
|
|
440
|
+
} catch (error) {
|
|
441
|
+
logger.error("[Prisma] Connection test failed", {
|
|
442
|
+
error: error instanceof Error ? error.message : String(error)
|
|
443
|
+
});
|
|
444
|
+
return false;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
__name(testConnection, "testConnection");
|
|
448
|
+
async function getDatabaseVersion(client) {
|
|
449
|
+
try {
|
|
450
|
+
const result = await client.$queryRaw`SELECT version()`;
|
|
451
|
+
return result[0]?.version ?? null;
|
|
452
|
+
} catch (error) {
|
|
453
|
+
logger.error("[Prisma] Failed to get database version", {
|
|
454
|
+
error: error instanceof Error ? error.message : String(error)
|
|
455
|
+
});
|
|
456
|
+
return null;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
__name(getDatabaseVersion, "getDatabaseVersion");
|
|
460
|
+
async function getDatabaseStats(client) {
|
|
461
|
+
const [health, version] = await Promise.all([
|
|
462
|
+
checkDatabaseHealth(client),
|
|
463
|
+
getDatabaseVersion(client)
|
|
464
|
+
]);
|
|
465
|
+
return {
|
|
466
|
+
health,
|
|
467
|
+
version,
|
|
468
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
__name(getDatabaseStats, "getDatabaseStats");
|
|
472
|
+
var requireFn = createRequire(import.meta.url);
|
|
473
|
+
function loadGeneratedFields(generatedFieldsPath) {
|
|
474
|
+
try {
|
|
475
|
+
const generated = requireFn(generatedFieldsPath);
|
|
476
|
+
return generated.default || generated;
|
|
477
|
+
} catch (error) {
|
|
478
|
+
logger.error("[Prisma] Failed to load generated fields", {
|
|
479
|
+
error: error instanceof Error ? error.message : String(error),
|
|
480
|
+
path: generatedFieldsPath
|
|
481
|
+
});
|
|
482
|
+
throw new Error(`Failed to load generated fields from ${generatedFieldsPath}`);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
__name(loadGeneratedFields, "loadGeneratedFields");
|
|
486
|
+
function extractFieldsFromModel(modelName, modelFieldsMap, options = {}) {
|
|
487
|
+
const modelFields = modelFieldsMap[modelName];
|
|
488
|
+
if (!modelFields) {
|
|
489
|
+
throw new Error(`Model "${modelName}" not found in generated fields. Available models: ${Object.keys(modelFieldsMap).join(", ")}`);
|
|
490
|
+
}
|
|
491
|
+
const { excludeFields = [], includeRelations = false, customFilter } = options;
|
|
492
|
+
let fields = [
|
|
493
|
+
...modelFields.fields
|
|
494
|
+
];
|
|
495
|
+
if (includeRelations) {
|
|
496
|
+
fields = [
|
|
497
|
+
...fields,
|
|
498
|
+
...modelFields.relations
|
|
499
|
+
];
|
|
500
|
+
}
|
|
501
|
+
const excluded = [];
|
|
502
|
+
if (excludeFields.length > 0) {
|
|
503
|
+
fields = fields.filter((field) => {
|
|
504
|
+
if (excludeFields.includes(field)) {
|
|
505
|
+
excluded.push(field);
|
|
506
|
+
return false;
|
|
507
|
+
}
|
|
508
|
+
return true;
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
if (customFilter) {
|
|
512
|
+
fields = fields.filter((fieldName) => {
|
|
513
|
+
const isRelation = modelFields.relations.includes(fieldName);
|
|
514
|
+
const shouldInclude = customFilter({
|
|
515
|
+
name: fieldName,
|
|
516
|
+
type: "unknown",
|
|
517
|
+
isRelation
|
|
518
|
+
});
|
|
519
|
+
if (!shouldInclude) {
|
|
520
|
+
excluded.push(fieldName);
|
|
521
|
+
}
|
|
522
|
+
return shouldInclude;
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
return {
|
|
526
|
+
fields,
|
|
527
|
+
metadata: {
|
|
528
|
+
totalFields: modelFields.fields.length + modelFields.relations.length,
|
|
529
|
+
excludedCount: excluded.length,
|
|
530
|
+
excludedFields: excluded,
|
|
531
|
+
relationFields: modelFields.relations.length
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
__name(extractFieldsFromModel, "extractFieldsFromModel");
|
|
536
|
+
function getModelFields(modelName, modelFieldsMap, includeRelations = false) {
|
|
537
|
+
const result = extractFieldsFromModel(modelName, modelFieldsMap, {
|
|
538
|
+
includeRelations
|
|
539
|
+
});
|
|
540
|
+
return result.fields;
|
|
541
|
+
}
|
|
542
|
+
__name(getModelFields, "getModelFields");
|
|
543
|
+
function hasModel(modelName, modelFieldsMap) {
|
|
544
|
+
return modelName in modelFieldsMap;
|
|
545
|
+
}
|
|
546
|
+
__name(hasModel, "hasModel");
|
|
547
|
+
function getAllModelNames(modelFieldsMap) {
|
|
548
|
+
return Object.keys(modelFieldsMap);
|
|
549
|
+
}
|
|
550
|
+
__name(getAllModelNames, "getAllModelNames");
|
|
551
|
+
|
|
552
|
+
// src/prisma/context.ts
|
|
553
|
+
function buildContextWhereClause(contextFilter) {
|
|
554
|
+
if (!contextFilter) {
|
|
555
|
+
return void 0;
|
|
556
|
+
}
|
|
557
|
+
const conditions = [];
|
|
558
|
+
if (contextFilter.workspaceId != null) {
|
|
559
|
+
conditions.push({
|
|
560
|
+
path: [
|
|
561
|
+
"workspaceId"
|
|
562
|
+
],
|
|
563
|
+
equals: contextFilter.workspaceId
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
if (contextFilter.userId != null) {
|
|
567
|
+
conditions.push({
|
|
568
|
+
path: [
|
|
569
|
+
"userId"
|
|
570
|
+
],
|
|
571
|
+
equals: contextFilter.userId
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
if (contextFilter.projectId != null) {
|
|
575
|
+
conditions.push({
|
|
576
|
+
path: [
|
|
577
|
+
"projectId"
|
|
578
|
+
],
|
|
579
|
+
equals: contextFilter.projectId
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
if (contextFilter.appId != null) {
|
|
583
|
+
conditions.push({
|
|
584
|
+
path: [
|
|
585
|
+
"appId"
|
|
586
|
+
],
|
|
587
|
+
equals: contextFilter.appId
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
if (contextFilter.productId != null) {
|
|
591
|
+
conditions.push({
|
|
592
|
+
path: [
|
|
593
|
+
"productId"
|
|
594
|
+
],
|
|
595
|
+
equals: contextFilter.productId
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
if (contextFilter.organizationId != null) {
|
|
599
|
+
conditions.push({
|
|
600
|
+
path: [
|
|
601
|
+
"organizationId"
|
|
602
|
+
],
|
|
603
|
+
equals: contextFilter.organizationId
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
if (conditions.length === 0) {
|
|
607
|
+
return void 0;
|
|
608
|
+
}
|
|
609
|
+
if (conditions.length === 1) {
|
|
610
|
+
return conditions[0];
|
|
611
|
+
}
|
|
612
|
+
return conditions[0];
|
|
613
|
+
}
|
|
614
|
+
__name(buildContextWhereClause, "buildContextWhereClause");
|
|
615
|
+
function buildContextWhereConditions(contextFilter) {
|
|
616
|
+
if (!contextFilter) {
|
|
617
|
+
return [];
|
|
618
|
+
}
|
|
619
|
+
const conditions = [];
|
|
620
|
+
if (contextFilter.workspaceId != null) {
|
|
621
|
+
conditions.push({
|
|
622
|
+
context: {
|
|
623
|
+
path: [
|
|
624
|
+
"workspaceId"
|
|
625
|
+
],
|
|
626
|
+
equals: contextFilter.workspaceId
|
|
627
|
+
}
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
if (contextFilter.userId != null) {
|
|
631
|
+
conditions.push({
|
|
632
|
+
context: {
|
|
633
|
+
path: [
|
|
634
|
+
"userId"
|
|
635
|
+
],
|
|
636
|
+
equals: contextFilter.userId
|
|
637
|
+
}
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
if (contextFilter.projectId != null) {
|
|
641
|
+
conditions.push({
|
|
642
|
+
context: {
|
|
643
|
+
path: [
|
|
644
|
+
"projectId"
|
|
645
|
+
],
|
|
646
|
+
equals: contextFilter.projectId
|
|
647
|
+
}
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
if (contextFilter.appId != null) {
|
|
651
|
+
conditions.push({
|
|
652
|
+
context: {
|
|
653
|
+
path: [
|
|
654
|
+
"appId"
|
|
655
|
+
],
|
|
656
|
+
equals: contextFilter.appId
|
|
657
|
+
}
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
if (contextFilter.productId != null) {
|
|
661
|
+
conditions.push({
|
|
662
|
+
context: {
|
|
663
|
+
path: [
|
|
664
|
+
"productId"
|
|
665
|
+
],
|
|
666
|
+
equals: contextFilter.productId
|
|
667
|
+
}
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
if (contextFilter.organizationId != null) {
|
|
671
|
+
conditions.push({
|
|
672
|
+
context: {
|
|
673
|
+
path: [
|
|
674
|
+
"organizationId"
|
|
675
|
+
],
|
|
676
|
+
equals: contextFilter.organizationId
|
|
677
|
+
}
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
return conditions;
|
|
681
|
+
}
|
|
682
|
+
__name(buildContextWhereConditions, "buildContextWhereConditions");
|
|
683
|
+
function toContextJson(contextInput) {
|
|
684
|
+
if (!contextInput) {
|
|
685
|
+
return void 0;
|
|
686
|
+
}
|
|
687
|
+
const context = {};
|
|
688
|
+
if (contextInput.workspaceId != null) {
|
|
689
|
+
context["workspaceId"] = contextInput.workspaceId;
|
|
690
|
+
}
|
|
691
|
+
if (contextInput.userId != null) {
|
|
692
|
+
context["userId"] = contextInput.userId;
|
|
693
|
+
}
|
|
694
|
+
if (contextInput.projectId != null) {
|
|
695
|
+
context["projectId"] = contextInput.projectId;
|
|
696
|
+
}
|
|
697
|
+
if (contextInput.appId != null) {
|
|
698
|
+
context["appId"] = contextInput.appId;
|
|
699
|
+
}
|
|
700
|
+
if (contextInput.productId != null) {
|
|
701
|
+
context["productId"] = contextInput.productId;
|
|
702
|
+
}
|
|
703
|
+
if (contextInput.organizationId != null) {
|
|
704
|
+
context["organizationId"] = contextInput.organizationId;
|
|
705
|
+
}
|
|
706
|
+
if (contextInput.custom != null) {
|
|
707
|
+
context["custom"] = contextInput.custom;
|
|
708
|
+
}
|
|
709
|
+
if (Object.keys(context).length === 0) {
|
|
710
|
+
return void 0;
|
|
711
|
+
}
|
|
712
|
+
return context;
|
|
713
|
+
}
|
|
714
|
+
__name(toContextJson, "toContextJson");
|
|
715
|
+
function filterNullValues(obj) {
|
|
716
|
+
const filtered = {};
|
|
717
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
718
|
+
if (value !== null) {
|
|
719
|
+
filtered[key] = value;
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
return filtered;
|
|
723
|
+
}
|
|
724
|
+
__name(filterNullValues, "filterNullValues");
|
|
725
|
+
function mergeContextField(merged, fieldName, fieldValue) {
|
|
726
|
+
if (fieldValue === void 0) {
|
|
727
|
+
return;
|
|
728
|
+
}
|
|
729
|
+
if (fieldValue === null) {
|
|
730
|
+
delete merged[fieldName];
|
|
731
|
+
} else {
|
|
732
|
+
merged[fieldName] = fieldValue;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
__name(mergeContextField, "mergeContextField");
|
|
736
|
+
function mergeContext(existingContext, newContext) {
|
|
737
|
+
if (!newContext) {
|
|
738
|
+
if (!existingContext) {
|
|
739
|
+
return void 0;
|
|
740
|
+
}
|
|
741
|
+
if (typeof existingContext === "object" && !Array.isArray(existingContext)) {
|
|
742
|
+
const filtered = filterNullValues(existingContext);
|
|
743
|
+
return Object.keys(filtered).length > 0 ? filtered : void 0;
|
|
744
|
+
}
|
|
745
|
+
return existingContext;
|
|
746
|
+
}
|
|
747
|
+
if (!existingContext || typeof existingContext !== "object" || Array.isArray(existingContext)) {
|
|
748
|
+
return toContextJson(newContext);
|
|
749
|
+
}
|
|
750
|
+
const merged = filterNullValues(existingContext);
|
|
751
|
+
mergeContextField(merged, "workspaceId", newContext.workspaceId);
|
|
752
|
+
mergeContextField(merged, "userId", newContext.userId);
|
|
753
|
+
mergeContextField(merged, "projectId", newContext.projectId);
|
|
754
|
+
mergeContextField(merged, "appId", newContext.appId);
|
|
755
|
+
mergeContextField(merged, "productId", newContext.productId);
|
|
756
|
+
mergeContextField(merged, "organizationId", newContext.organizationId);
|
|
757
|
+
mergeContextField(merged, "custom", newContext.custom);
|
|
758
|
+
return Object.keys(merged).length > 0 ? merged : void 0;
|
|
759
|
+
}
|
|
760
|
+
__name(mergeContext, "mergeContext");
|
|
761
|
+
function parseContext(contextJson) {
|
|
762
|
+
if (!contextJson || typeof contextJson !== "object" || Array.isArray(contextJson)) {
|
|
763
|
+
return null;
|
|
764
|
+
}
|
|
765
|
+
const ctx = contextJson;
|
|
766
|
+
return {
|
|
767
|
+
workspaceId: typeof ctx["workspaceId"] === "string" ? ctx["workspaceId"] : null,
|
|
768
|
+
userId: typeof ctx["userId"] === "string" ? ctx["userId"] : null,
|
|
769
|
+
projectId: typeof ctx["projectId"] === "string" ? ctx["projectId"] : null,
|
|
770
|
+
appId: typeof ctx["appId"] === "string" ? ctx["appId"] : null,
|
|
771
|
+
productId: typeof ctx["productId"] === "string" ? ctx["productId"] : null,
|
|
772
|
+
organizationId: typeof ctx["organizationId"] === "string" ? ctx["organizationId"] : null,
|
|
773
|
+
custom: typeof ctx["custom"] === "object" ? ctx["custom"] : null
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
__name(parseContext, "parseContext");
|
|
777
|
+
function contextMatches(context, filter) {
|
|
778
|
+
if (!context) {
|
|
779
|
+
return false;
|
|
780
|
+
}
|
|
781
|
+
if (filter.workspaceId != null && context.workspaceId !== filter.workspaceId) {
|
|
782
|
+
return false;
|
|
783
|
+
}
|
|
784
|
+
if (filter.userId != null && context.userId !== filter.userId) {
|
|
785
|
+
return false;
|
|
786
|
+
}
|
|
787
|
+
if (filter.projectId != null && context.projectId !== filter.projectId) {
|
|
788
|
+
return false;
|
|
789
|
+
}
|
|
790
|
+
if (filter.appId != null && context.appId !== filter.appId) {
|
|
791
|
+
return false;
|
|
792
|
+
}
|
|
793
|
+
if (filter.productId != null && context.productId !== filter.productId) {
|
|
794
|
+
return false;
|
|
795
|
+
}
|
|
796
|
+
if (filter.organizationId != null && context.organizationId !== filter.organizationId) {
|
|
797
|
+
return false;
|
|
798
|
+
}
|
|
799
|
+
return true;
|
|
800
|
+
}
|
|
801
|
+
__name(contextMatches, "contextMatches");
|
|
802
|
+
function createContextFromSDK(sdkContext) {
|
|
803
|
+
return {
|
|
804
|
+
workspaceId: sdkContext.workspaceId ?? null,
|
|
805
|
+
userId: sdkContext.userId ?? null,
|
|
806
|
+
projectId: sdkContext.projectId ?? null,
|
|
807
|
+
appId: sdkContext.appId ?? null,
|
|
808
|
+
productId: sdkContext.productId ?? null,
|
|
809
|
+
organizationId: sdkContext.organizationId ?? null
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
__name(createContextFromSDK, "createContextFromSDK");
|
|
813
|
+
|
|
814
|
+
export { PrismaClientWrapper, buildContextWhereClause, buildContextWhereConditions, checkDatabaseHealth, configurePrismaLogging, contextMatches, createConnectionPool, createContextFromSDK, createDatabaseClient, createDatabaseClientFromEnv, createPrismaAdapter, createPrismaClient, extractFieldsFromModel, getAllModelNames, getDatabaseManager, getDatabaseProductName, getDatabaseStats, getDatabaseVersion, getDb, getModelFields, hasModel, initializeDatabase, initializeDatabaseWithConfig, isDatabaseInitialized, loadGeneratedFields, mergeContext, parseContext, prisma_exports, resetDatabaseManager, testConnection, toContextJson };
|
|
815
|
+
//# sourceMappingURL=chunk-2SD5L2F2.js.map
|
|
816
|
+
//# sourceMappingURL=chunk-2SD5L2F2.js.map
|