@hiliosai/sdk 0.1.17 → 0.1.19
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 +5 -1
- package/dist/index.js +35 -4
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -151,6 +151,9 @@ declare abstract class AbstractDatasource<TContext = AppContext> implements Base
|
|
|
151
151
|
* Override to implement clearing logic
|
|
152
152
|
*/
|
|
153
153
|
clear(): Promise<void>;
|
|
154
|
+
memoize<P = unknown, R = unknown>(name: string, params: P, fn: () => Promise<R>, options?: {
|
|
155
|
+
ttl?: number;
|
|
156
|
+
}): Promise<R>;
|
|
154
157
|
}
|
|
155
158
|
|
|
156
159
|
interface PrismaClientLike {
|
|
@@ -865,6 +868,7 @@ declare const isDev: boolean;
|
|
|
865
868
|
declare const isTest: boolean;
|
|
866
869
|
declare const isProd: boolean;
|
|
867
870
|
declare const REDIS_URL: string | undefined;
|
|
871
|
+
declare const DEFAULT_DATASOURCE_CACHE_TTL: number;
|
|
868
872
|
|
|
869
873
|
type Env = typeof env;
|
|
870
874
|
|
|
@@ -897,4 +901,4 @@ declare function DatasourceMixin(datasourceConstructors?: DatasourceConstructorR
|
|
|
897
901
|
|
|
898
902
|
declare function omit<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
|
|
899
903
|
|
|
900
|
-
export { AbstractDatasource, type ActionHandler, type ActionSchemaWithContext, type ActionWithPermissions, type AppContext, type AppMeta, type AuditTrailExtension, type BaseDatasource, type BaseSpec, CHANNELS, type CarouselItem, type ChannelSendOptions, ContextHelpersMiddleware, CreateHealthCheckMiddleware, type DatasourceConstructorRegistry, type DatasourceContext, type DatasourceInstanceRegistry, type DatasourceInstanceTypes, DatasourceMixin, type Env, HEALTH_CHECK_DEFAULTS, INTEGRATION_CHANNELS, IntegrationCapability, type IntegrationChannelName, type IntegrationConfig, type IntegrationMessageFailedPayload, type IntegrationMessageReceivedPayload, type IntegrationMessageSentPayload, IntegrationPlatform, type IntegrationRegisteredPayload, type IntegrationServiceConfig, type IntegrationServiceSchema, IntegrationStatus, type IntegrationUnregisteredPayload, MemoizeMixin, type MemoizeMixinOptions, type Message, type MessageAttachment, type MessageButton, type MessageContent, MessageContentType, type MessageDirection, type MessageParticipant, type MessageStatus, type MessageType, NAMESPACE, PERMISSIONS, type Permission, type PermissionHelpers, PermissionsMiddleware, type PlatformMessage, PrismaDatasource, REDIS_URL, ROLE_PERMISSIONS, type SendResult, type SendToChannelMethod, type ServiceActionsSchema, type ServiceConfig, type ServiceSchema, type ServiceWithDatasources, type SoftDeleteExtension, type Tenant, type TenantExtension, type User, UserRole, type WebhookEvent, createDatasourceMiddleware, createTenantExtension, defineIntegration, defineService, isDev, isProd, isTest, configs as moleculer, nodeEnv, omit, retryExtension, softDeleteExtension };
|
|
904
|
+
export { AbstractDatasource, type ActionHandler, type ActionSchemaWithContext, type ActionWithPermissions, type AppContext, type AppMeta, type AuditTrailExtension, type BaseDatasource, type BaseSpec, CHANNELS, type CarouselItem, type ChannelSendOptions, ContextHelpersMiddleware, CreateHealthCheckMiddleware, DEFAULT_DATASOURCE_CACHE_TTL, type DatasourceConstructorRegistry, type DatasourceContext, type DatasourceInstanceRegistry, type DatasourceInstanceTypes, DatasourceMixin, type Env, HEALTH_CHECK_DEFAULTS, INTEGRATION_CHANNELS, IntegrationCapability, type IntegrationChannelName, type IntegrationConfig, type IntegrationMessageFailedPayload, type IntegrationMessageReceivedPayload, type IntegrationMessageSentPayload, IntegrationPlatform, type IntegrationRegisteredPayload, type IntegrationServiceConfig, type IntegrationServiceSchema, IntegrationStatus, type IntegrationUnregisteredPayload, MemoizeMixin, type MemoizeMixinOptions, type Message, type MessageAttachment, type MessageButton, type MessageContent, MessageContentType, type MessageDirection, type MessageParticipant, type MessageStatus, type MessageType, NAMESPACE, PERMISSIONS, type Permission, type PermissionHelpers, PermissionsMiddleware, type PlatformMessage, PrismaDatasource, REDIS_URL, ROLE_PERMISSIONS, type SendResult, type SendToChannelMethod, type ServiceActionsSchema, type ServiceConfig, type ServiceSchema, type ServiceWithDatasources, type SoftDeleteExtension, type Tenant, type TenantExtension, type User, UserRole, type WebhookEvent, createDatasourceMiddleware, createTenantExtension, defineIntegration, defineService, isDev, isProd, isTest, configs as moleculer, nodeEnv, omit, retryExtension, softDeleteExtension };
|
package/dist/index.js
CHANGED
|
@@ -249,6 +249,11 @@ var isDev = nodeEnv === "development";
|
|
|
249
249
|
var isTest = nodeEnv === "test";
|
|
250
250
|
var isProd = nodeEnv === "production";
|
|
251
251
|
var REDIS_URL = env4.string("REDIS_URL");
|
|
252
|
+
var DEFAULT_DATASOURCE_CACHE_TTL = env4.number(
|
|
253
|
+
"DEFAULT_DATASOURCE_CACHE_TTL",
|
|
254
|
+
60
|
|
255
|
+
// 60 seconds
|
|
256
|
+
);
|
|
252
257
|
var env_default = env4;
|
|
253
258
|
|
|
254
259
|
// src/errors/permission.error.ts
|
|
@@ -1389,6 +1394,26 @@ var AbstractDatasource = class {
|
|
|
1389
1394
|
*/
|
|
1390
1395
|
async clear() {
|
|
1391
1396
|
}
|
|
1397
|
+
// memoize
|
|
1398
|
+
async memoize(name, params, fn, options) {
|
|
1399
|
+
let res;
|
|
1400
|
+
if (!this.broker.cacher) return fn();
|
|
1401
|
+
const key = this.broker.cacher.defaultKeygen(
|
|
1402
|
+
`${this.name}:ds-${name}`,
|
|
1403
|
+
params ?? {},
|
|
1404
|
+
{},
|
|
1405
|
+
[]
|
|
1406
|
+
);
|
|
1407
|
+
res = await this.broker.cacher.get(key);
|
|
1408
|
+
if (res) return res;
|
|
1409
|
+
res = await fn();
|
|
1410
|
+
this.broker.cacher.set(
|
|
1411
|
+
key,
|
|
1412
|
+
res,
|
|
1413
|
+
options?.ttl ?? DEFAULT_DATASOURCE_CACHE_TTL
|
|
1414
|
+
);
|
|
1415
|
+
return res;
|
|
1416
|
+
}
|
|
1392
1417
|
};
|
|
1393
1418
|
|
|
1394
1419
|
// src/datasources/prisma.datasource.ts
|
|
@@ -1482,7 +1507,9 @@ var PrismaDatasource = class extends AbstractDatasource {
|
|
|
1482
1507
|
async disconnect() {
|
|
1483
1508
|
try {
|
|
1484
1509
|
this.broker.logger.info("Disconnecting from database");
|
|
1485
|
-
|
|
1510
|
+
if (this._client) {
|
|
1511
|
+
await this._client.$disconnect();
|
|
1512
|
+
}
|
|
1486
1513
|
this.broker.logger.info("Successfully disconnected from database");
|
|
1487
1514
|
} catch (error) {
|
|
1488
1515
|
this.broker.logger.error("Error disconnecting from database:", error);
|
|
@@ -1549,7 +1576,8 @@ var PrismaDatasource = class extends AbstractDatasource {
|
|
|
1549
1576
|
* Requires tenant extension to be applied
|
|
1550
1577
|
*/
|
|
1551
1578
|
setTenantContext(tenantId) {
|
|
1552
|
-
|
|
1579
|
+
this._client ?? (this._client = this.initializePrismaClient());
|
|
1580
|
+
const tenantClient = this._client;
|
|
1553
1581
|
if (tenantClient.$setTenant) {
|
|
1554
1582
|
tenantClient.$setTenant(tenantId);
|
|
1555
1583
|
this.broker.logger.debug("Tenant context set:", { tenantId });
|
|
@@ -1563,7 +1591,10 @@ var PrismaDatasource = class extends AbstractDatasource {
|
|
|
1563
1591
|
* Get current tenant context
|
|
1564
1592
|
*/
|
|
1565
1593
|
getCurrentTenant() {
|
|
1566
|
-
|
|
1594
|
+
if (!this._client) {
|
|
1595
|
+
return null;
|
|
1596
|
+
}
|
|
1597
|
+
const tenantClient = this._client;
|
|
1567
1598
|
if (tenantClient.$getCurrentTenant) {
|
|
1568
1599
|
return tenantClient.$getCurrentTenant();
|
|
1569
1600
|
}
|
|
@@ -1806,4 +1837,4 @@ var retryExtension = {
|
|
|
1806
1837
|
}
|
|
1807
1838
|
};
|
|
1808
1839
|
|
|
1809
|
-
export { AbstractDatasource, CHANNELS, ContextHelpersMiddleware, CreateHealthCheckMiddleware, DatasourceMixin, HEALTH_CHECK_DEFAULTS, INTEGRATION_CHANNELS, IntegrationCapability, IntegrationPlatform, IntegrationStatus, MemoizeMixin, MessageContentType, NAMESPACE, PERMISSIONS, PermissionsMiddleware, PrismaDatasource, REDIS_URL, ROLE_PERMISSIONS, UserRole, createDatasourceMiddleware, createTenantExtension, defineIntegration, defineService, env_default as env, isDev, isProd, isTest, moleculer_default as moleculer, nodeEnv, omit, retryExtension, softDeleteExtension };
|
|
1840
|
+
export { AbstractDatasource, CHANNELS, ContextHelpersMiddleware, CreateHealthCheckMiddleware, DEFAULT_DATASOURCE_CACHE_TTL, DatasourceMixin, HEALTH_CHECK_DEFAULTS, INTEGRATION_CHANNELS, IntegrationCapability, IntegrationPlatform, IntegrationStatus, MemoizeMixin, MessageContentType, NAMESPACE, PERMISSIONS, PermissionsMiddleware, PrismaDatasource, REDIS_URL, ROLE_PERMISSIONS, UserRole, createDatasourceMiddleware, createTenantExtension, defineIntegration, defineService, env_default as env, isDev, isProd, isTest, moleculer_default as moleculer, nodeEnv, omit, retryExtension, softDeleteExtension };
|
package/package.json
CHANGED