@hiliosai/sdk 0.1.21 → 0.1.22
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.d.ts +3 -17
- package/dist/index.js +16 -6
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -239,6 +239,8 @@ declare class PrismaDatasource<TPrismaClient extends PrismaClientLike = PrismaCl
|
|
|
239
239
|
protected applyExtensions(client: TPrismaClient): TPrismaClient;
|
|
240
240
|
/**
|
|
241
241
|
* Get extended client with all applied extensions
|
|
242
|
+
* Note: Since extensions are already applied in initializePrismaClient,
|
|
243
|
+
* this just returns the client directly to avoid double-applying extensions
|
|
242
244
|
*/
|
|
243
245
|
get extendedClient(): TPrismaClient;
|
|
244
246
|
/**
|
|
@@ -248,6 +250,7 @@ declare class PrismaDatasource<TPrismaClient extends PrismaClientLike = PrismaCl
|
|
|
248
250
|
/**
|
|
249
251
|
* Called automatically when context is injected
|
|
250
252
|
* Sets tenant context from service context if available
|
|
253
|
+
* Skips update if currently in bypass mode to avoid overriding admin operations
|
|
251
254
|
*/
|
|
252
255
|
private updateTenantFromContext;
|
|
253
256
|
/**
|
|
@@ -325,23 +328,6 @@ declare const softDeleteExtension: {
|
|
|
325
328
|
};
|
|
326
329
|
};
|
|
327
330
|
|
|
328
|
-
/**
|
|
329
|
-
* Multi-Tenant Extension for Prisma
|
|
330
|
-
* Automatically filters queries by tenant context for multi-tenant applications
|
|
331
|
-
*
|
|
332
|
-
* Usage:
|
|
333
|
-
* ```typescript
|
|
334
|
-
* import { createTenantExtension } from './extensions/tenant.extension';
|
|
335
|
-
*
|
|
336
|
-
* class MyPrismaDS extends PrismaDatasource<PrismaClient> {
|
|
337
|
-
* protected applyExtensions(client: PrismaClient) {
|
|
338
|
-
* return client.$extends(createTenantExtension());
|
|
339
|
-
* }
|
|
340
|
-
* }
|
|
341
|
-
* ```
|
|
342
|
-
*
|
|
343
|
-
* Requires models to have `tenantId String` field
|
|
344
|
-
*/
|
|
345
331
|
declare function createTenantExtension(): {
|
|
346
332
|
name: string;
|
|
347
333
|
client: {
|
package/dist/index.js
CHANGED
|
@@ -1417,12 +1417,16 @@ var AbstractDatasource = class {
|
|
|
1417
1417
|
};
|
|
1418
1418
|
|
|
1419
1419
|
// src/datasources/extensions/tenant.extension.ts
|
|
1420
|
+
var globalTenantContext = {
|
|
1421
|
+
currentTenantId: null,
|
|
1422
|
+
bypassMode: false,
|
|
1423
|
+
strictMode: false
|
|
1424
|
+
};
|
|
1425
|
+
function isInBypassMode() {
|
|
1426
|
+
return globalTenantContext.bypassMode;
|
|
1427
|
+
}
|
|
1420
1428
|
function createTenantExtension() {
|
|
1421
|
-
const tenantContext =
|
|
1422
|
-
currentTenantId: null,
|
|
1423
|
-
bypassMode: false,
|
|
1424
|
-
strictMode: false
|
|
1425
|
-
};
|
|
1429
|
+
const tenantContext = globalTenantContext;
|
|
1426
1430
|
return {
|
|
1427
1431
|
name: "Tenant",
|
|
1428
1432
|
client: {
|
|
@@ -1621,9 +1625,11 @@ var PrismaDatasource = class extends AbstractDatasource {
|
|
|
1621
1625
|
}
|
|
1622
1626
|
/**
|
|
1623
1627
|
* Get extended client with all applied extensions
|
|
1628
|
+
* Note: Since extensions are already applied in initializePrismaClient,
|
|
1629
|
+
* this just returns the client directly to avoid double-applying extensions
|
|
1624
1630
|
*/
|
|
1625
1631
|
get extendedClient() {
|
|
1626
|
-
return this.
|
|
1632
|
+
return this.client;
|
|
1627
1633
|
}
|
|
1628
1634
|
/**
|
|
1629
1635
|
* Initialize datasource - called after broker injection
|
|
@@ -1634,8 +1640,12 @@ var PrismaDatasource = class extends AbstractDatasource {
|
|
|
1634
1640
|
/**
|
|
1635
1641
|
* Called automatically when context is injected
|
|
1636
1642
|
* Sets tenant context from service context if available
|
|
1643
|
+
* Skips update if currently in bypass mode to avoid overriding admin operations
|
|
1637
1644
|
*/
|
|
1638
1645
|
updateTenantFromContext() {
|
|
1646
|
+
if (isInBypassMode()) {
|
|
1647
|
+
return;
|
|
1648
|
+
}
|
|
1639
1649
|
const tenantId = this.context?.meta?.tenantId;
|
|
1640
1650
|
if (tenantId && typeof tenantId === "string") {
|
|
1641
1651
|
this.setTenantContext(tenantId);
|