@hiliosai/sdk 0.1.18 → 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 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
@@ -1812,4 +1837,4 @@ var retryExtension = {
1812
1837
  }
1813
1838
  };
1814
1839
 
1815
- 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hiliosai/sdk",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "type": "module",
5
5
  "license": "UNLICENSED",
6
6
  "main": "./dist/index.js",
@@ -31,4 +31,4 @@
31
31
  "bun-types": "latest"
32
32
  },
33
33
  "prettier": "@hiliosai/prettier"
34
- }
34
+ }