@hotmeshio/hotmesh 0.4.0 → 0.4.2

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.
Files changed (284) hide show
  1. package/README.md +39 -14
  2. package/build/modules/enums.d.ts +110 -0
  3. package/build/modules/enums.js +134 -0
  4. package/build/modules/errors.d.ts +124 -0
  5. package/build/modules/errors.js +191 -0
  6. package/build/modules/key.d.ts +66 -0
  7. package/build/modules/key.js +190 -0
  8. package/build/modules/storage.d.ts +3 -0
  9. package/build/modules/storage.js +5 -0
  10. package/build/modules/utils.d.ts +119 -0
  11. package/build/modules/utils.js +374 -0
  12. package/build/package.json +1 -1
  13. package/build/services/activities/activity.d.ts +104 -0
  14. package/build/services/activities/activity.js +549 -0
  15. package/build/services/activities/await.d.ts +12 -0
  16. package/build/services/activities/await.js +114 -0
  17. package/build/services/activities/cycle.d.ts +19 -0
  18. package/build/services/activities/cycle.js +112 -0
  19. package/build/services/activities/hook.d.ts +27 -0
  20. package/build/services/activities/hook.js +168 -0
  21. package/build/services/activities/index.d.ts +19 -0
  22. package/build/services/activities/index.js +20 -0
  23. package/build/services/activities/interrupt.d.ts +16 -0
  24. package/build/services/activities/interrupt.js +158 -0
  25. package/build/services/activities/signal.d.ts +20 -0
  26. package/build/services/activities/signal.js +134 -0
  27. package/build/services/activities/trigger.d.ts +37 -0
  28. package/build/services/activities/trigger.js +246 -0
  29. package/build/services/activities/worker.d.ts +12 -0
  30. package/build/services/activities/worker.js +106 -0
  31. package/build/services/collator/index.d.ts +111 -0
  32. package/build/services/collator/index.js +293 -0
  33. package/build/services/compiler/deployer.d.ts +40 -0
  34. package/build/services/compiler/deployer.js +488 -0
  35. package/build/services/compiler/index.d.ts +32 -0
  36. package/build/services/compiler/index.js +112 -0
  37. package/build/services/compiler/validator.d.ts +34 -0
  38. package/build/services/compiler/validator.js +147 -0
  39. package/build/services/connector/factory.d.ts +22 -0
  40. package/build/services/connector/factory.js +99 -0
  41. package/build/services/connector/index.d.ts +30 -0
  42. package/build/services/connector/index.js +54 -0
  43. package/build/services/connector/providers/ioredis.d.ts +9 -0
  44. package/build/services/connector/providers/ioredis.js +26 -0
  45. package/build/services/connector/providers/nats.d.ts +9 -0
  46. package/build/services/connector/providers/nats.js +34 -0
  47. package/build/services/connector/providers/postgres.d.ts +20 -0
  48. package/build/services/connector/providers/postgres.js +102 -0
  49. package/build/services/connector/providers/redis.d.ts +9 -0
  50. package/build/services/connector/providers/redis.js +38 -0
  51. package/build/services/engine/index.d.ts +264 -0
  52. package/build/services/engine/index.js +761 -0
  53. package/build/services/exporter/index.d.ts +44 -0
  54. package/build/services/exporter/index.js +126 -0
  55. package/build/services/hotmesh/index.d.ts +483 -0
  56. package/build/services/hotmesh/index.js +622 -0
  57. package/build/services/logger/index.d.ts +16 -0
  58. package/build/services/logger/index.js +54 -0
  59. package/build/services/mapper/index.d.ts +28 -0
  60. package/build/services/mapper/index.js +81 -0
  61. package/build/services/memflow/client.d.ts +108 -0
  62. package/build/services/memflow/client.js +372 -0
  63. package/build/services/memflow/connection.d.ts +23 -0
  64. package/build/services/memflow/connection.js +33 -0
  65. package/build/services/memflow/context.d.ts +143 -0
  66. package/build/services/memflow/context.js +299 -0
  67. package/build/services/memflow/exporter.d.ts +51 -0
  68. package/build/services/memflow/exporter.js +215 -0
  69. package/build/services/memflow/handle.d.ts +90 -0
  70. package/build/services/memflow/handle.js +176 -0
  71. package/build/services/memflow/index.d.ts +116 -0
  72. package/build/services/memflow/index.js +122 -0
  73. package/build/services/memflow/schemas/factory.d.ts +29 -0
  74. package/build/services/memflow/schemas/factory.js +2492 -0
  75. package/build/services/memflow/search.d.ts +142 -0
  76. package/build/services/memflow/search.js +320 -0
  77. package/build/services/memflow/worker.d.ts +124 -0
  78. package/build/services/memflow/worker.js +514 -0
  79. package/build/services/memflow/workflow/all.d.ts +7 -0
  80. package/build/services/memflow/workflow/all.js +15 -0
  81. package/build/services/memflow/workflow/common.d.ts +20 -0
  82. package/build/services/memflow/workflow/common.js +47 -0
  83. package/build/services/memflow/workflow/context.d.ts +6 -0
  84. package/build/services/memflow/workflow/context.js +45 -0
  85. package/build/services/memflow/workflow/contextMethods.d.ts +14 -0
  86. package/build/services/memflow/workflow/contextMethods.js +33 -0
  87. package/build/services/memflow/workflow/didRun.d.ts +7 -0
  88. package/build/services/memflow/workflow/didRun.js +22 -0
  89. package/build/services/memflow/workflow/emit.d.ts +11 -0
  90. package/build/services/memflow/workflow/emit.js +29 -0
  91. package/build/services/memflow/workflow/enrich.d.ts +9 -0
  92. package/build/services/memflow/workflow/enrich.js +17 -0
  93. package/build/services/memflow/workflow/execChild.d.ts +18 -0
  94. package/build/services/memflow/workflow/execChild.js +102 -0
  95. package/build/services/memflow/workflow/execHook.d.ts +65 -0
  96. package/build/services/memflow/workflow/execHook.js +73 -0
  97. package/build/services/memflow/workflow/hook.d.ts +9 -0
  98. package/build/services/memflow/workflow/hook.js +56 -0
  99. package/build/services/memflow/workflow/index.d.ts +74 -0
  100. package/build/services/memflow/workflow/index.js +87 -0
  101. package/build/services/memflow/workflow/interrupt.d.ts +9 -0
  102. package/build/services/memflow/workflow/interrupt.js +24 -0
  103. package/build/services/memflow/workflow/isSideEffectAllowed.d.ts +10 -0
  104. package/build/services/memflow/workflow/isSideEffectAllowed.js +33 -0
  105. package/build/services/memflow/workflow/proxyActivities.d.ts +20 -0
  106. package/build/services/memflow/workflow/proxyActivities.js +97 -0
  107. package/build/services/memflow/workflow/random.d.ts +6 -0
  108. package/build/services/memflow/workflow/random.js +16 -0
  109. package/build/services/memflow/workflow/searchMethods.d.ts +6 -0
  110. package/build/services/memflow/workflow/searchMethods.js +25 -0
  111. package/build/services/memflow/workflow/signal.d.ts +29 -0
  112. package/build/services/memflow/workflow/signal.js +50 -0
  113. package/build/services/memflow/workflow/sleepFor.d.ts +24 -0
  114. package/build/services/memflow/workflow/sleepFor.js +51 -0
  115. package/build/services/memflow/workflow/trace.d.ts +14 -0
  116. package/build/services/memflow/workflow/trace.js +33 -0
  117. package/build/services/memflow/workflow/waitFor.d.ts +29 -0
  118. package/build/services/memflow/workflow/waitFor.js +56 -0
  119. package/build/services/meshcall/index.d.ts +194 -0
  120. package/build/services/meshcall/index.js +452 -0
  121. package/build/services/meshcall/schemas/factory.d.ts +9 -0
  122. package/build/services/meshcall/schemas/factory.js +189 -0
  123. package/build/services/meshdata/index.d.ts +795 -0
  124. package/build/services/meshdata/index.js +1235 -0
  125. package/build/services/meshos/index.d.ts +293 -0
  126. package/build/services/meshos/index.js +547 -0
  127. package/build/services/pipe/functions/array.d.ts +17 -0
  128. package/build/services/pipe/functions/array.js +74 -0
  129. package/build/services/pipe/functions/bitwise.d.ts +9 -0
  130. package/build/services/pipe/functions/bitwise.js +24 -0
  131. package/build/services/pipe/functions/conditional.d.ts +13 -0
  132. package/build/services/pipe/functions/conditional.js +36 -0
  133. package/build/services/pipe/functions/cron.d.ts +12 -0
  134. package/build/services/pipe/functions/cron.js +40 -0
  135. package/build/services/pipe/functions/date.d.ts +58 -0
  136. package/build/services/pipe/functions/date.js +171 -0
  137. package/build/services/pipe/functions/index.d.ts +29 -0
  138. package/build/services/pipe/functions/index.js +30 -0
  139. package/build/services/pipe/functions/json.d.ts +5 -0
  140. package/build/services/pipe/functions/json.js +12 -0
  141. package/build/services/pipe/functions/logical.d.ts +5 -0
  142. package/build/services/pipe/functions/logical.js +12 -0
  143. package/build/services/pipe/functions/math.d.ts +42 -0
  144. package/build/services/pipe/functions/math.js +184 -0
  145. package/build/services/pipe/functions/number.d.ts +21 -0
  146. package/build/services/pipe/functions/number.js +60 -0
  147. package/build/services/pipe/functions/object.d.ts +25 -0
  148. package/build/services/pipe/functions/object.js +81 -0
  149. package/build/services/pipe/functions/string.d.ts +23 -0
  150. package/build/services/pipe/functions/string.js +69 -0
  151. package/build/services/pipe/functions/symbol.d.ts +12 -0
  152. package/build/services/pipe/functions/symbol.js +33 -0
  153. package/build/services/pipe/functions/unary.d.ts +7 -0
  154. package/build/services/pipe/functions/unary.js +18 -0
  155. package/build/services/pipe/index.d.ts +48 -0
  156. package/build/services/pipe/index.js +242 -0
  157. package/build/services/quorum/index.d.ts +90 -0
  158. package/build/services/quorum/index.js +263 -0
  159. package/build/services/reporter/index.d.ts +50 -0
  160. package/build/services/reporter/index.js +348 -0
  161. package/build/services/router/config/index.d.ts +11 -0
  162. package/build/services/router/config/index.js +36 -0
  163. package/build/services/router/consumption/index.d.ts +34 -0
  164. package/build/services/router/consumption/index.js +395 -0
  165. package/build/services/router/error-handling/index.d.ts +8 -0
  166. package/build/services/router/error-handling/index.js +98 -0
  167. package/build/services/router/index.d.ts +57 -0
  168. package/build/services/router/index.js +121 -0
  169. package/build/services/router/lifecycle/index.d.ts +27 -0
  170. package/build/services/router/lifecycle/index.js +80 -0
  171. package/build/services/router/telemetry/index.d.ts +11 -0
  172. package/build/services/router/telemetry/index.js +32 -0
  173. package/build/services/router/throttling/index.d.ts +23 -0
  174. package/build/services/router/throttling/index.js +76 -0
  175. package/build/services/search/factory.d.ts +7 -0
  176. package/build/services/search/factory.js +24 -0
  177. package/build/services/search/index.d.ts +23 -0
  178. package/build/services/search/index.js +10 -0
  179. package/build/services/search/providers/postgres/postgres.d.ts +25 -0
  180. package/build/services/search/providers/postgres/postgres.js +149 -0
  181. package/build/services/search/providers/redis/ioredis.d.ts +19 -0
  182. package/build/services/search/providers/redis/ioredis.js +121 -0
  183. package/build/services/search/providers/redis/redis.d.ts +19 -0
  184. package/build/services/search/providers/redis/redis.js +134 -0
  185. package/build/services/serializer/index.d.ts +42 -0
  186. package/build/services/serializer/index.js +282 -0
  187. package/build/services/store/cache.d.ts +67 -0
  188. package/build/services/store/cache.js +128 -0
  189. package/build/services/store/factory.d.ts +8 -0
  190. package/build/services/store/factory.js +24 -0
  191. package/build/services/store/index.d.ts +89 -0
  192. package/build/services/store/index.js +9 -0
  193. package/build/services/store/providers/postgres/kvsql.d.ts +168 -0
  194. package/build/services/store/providers/postgres/kvsql.js +198 -0
  195. package/build/services/store/providers/postgres/kvtables.d.ts +20 -0
  196. package/build/services/store/providers/postgres/kvtables.js +441 -0
  197. package/build/services/store/providers/postgres/kvtransaction.d.ts +36 -0
  198. package/build/services/store/providers/postgres/kvtransaction.js +248 -0
  199. package/build/services/store/providers/postgres/kvtypes/hash.d.ts +60 -0
  200. package/build/services/store/providers/postgres/kvtypes/hash.js +1287 -0
  201. package/build/services/store/providers/postgres/kvtypes/list.d.ts +33 -0
  202. package/build/services/store/providers/postgres/kvtypes/list.js +194 -0
  203. package/build/services/store/providers/postgres/kvtypes/string.d.ts +20 -0
  204. package/build/services/store/providers/postgres/kvtypes/string.js +115 -0
  205. package/build/services/store/providers/postgres/kvtypes/zset.d.ts +41 -0
  206. package/build/services/store/providers/postgres/kvtypes/zset.js +214 -0
  207. package/build/services/store/providers/postgres/postgres.d.ts +178 -0
  208. package/build/services/store/providers/postgres/postgres.js +1244 -0
  209. package/build/services/store/providers/redis/_base.d.ts +137 -0
  210. package/build/services/store/providers/redis/_base.js +980 -0
  211. package/build/services/store/providers/redis/ioredis.d.ts +20 -0
  212. package/build/services/store/providers/redis/ioredis.js +180 -0
  213. package/build/services/store/providers/redis/redis.d.ts +18 -0
  214. package/build/services/store/providers/redis/redis.js +199 -0
  215. package/build/services/store/providers/store-initializable.d.ts +5 -0
  216. package/build/services/store/providers/store-initializable.js +2 -0
  217. package/build/services/stream/factory.d.ts +8 -0
  218. package/build/services/stream/factory.js +37 -0
  219. package/build/services/stream/index.d.ts +69 -0
  220. package/build/services/stream/index.js +11 -0
  221. package/build/services/stream/providers/nats/nats.d.ts +60 -0
  222. package/build/services/stream/providers/nats/nats.js +225 -0
  223. package/build/services/stream/providers/postgres/kvtables.d.ts +3 -0
  224. package/build/services/stream/providers/postgres/kvtables.js +146 -0
  225. package/build/services/stream/providers/postgres/postgres.d.ts +107 -0
  226. package/build/services/stream/providers/postgres/postgres.js +519 -0
  227. package/build/services/stream/providers/redis/ioredis.d.ts +61 -0
  228. package/build/services/stream/providers/redis/ioredis.js +272 -0
  229. package/build/services/stream/providers/redis/redis.d.ts +61 -0
  230. package/build/services/stream/providers/redis/redis.js +305 -0
  231. package/build/services/stream/providers/stream-initializable.d.ts +4 -0
  232. package/build/services/stream/providers/stream-initializable.js +2 -0
  233. package/build/services/sub/factory.d.ts +7 -0
  234. package/build/services/sub/factory.js +29 -0
  235. package/build/services/sub/index.d.ts +22 -0
  236. package/build/services/sub/index.js +10 -0
  237. package/build/services/sub/providers/nats/nats.d.ts +19 -0
  238. package/build/services/sub/providers/nats/nats.js +105 -0
  239. package/build/services/sub/providers/postgres/postgres.d.ts +19 -0
  240. package/build/services/sub/providers/postgres/postgres.js +92 -0
  241. package/build/services/sub/providers/redis/ioredis.d.ts +17 -0
  242. package/build/services/sub/providers/redis/ioredis.js +81 -0
  243. package/build/services/sub/providers/redis/redis.d.ts +17 -0
  244. package/build/services/sub/providers/redis/redis.js +72 -0
  245. package/build/services/task/index.d.ts +48 -0
  246. package/build/services/task/index.js +253 -0
  247. package/build/services/telemetry/index.d.ts +52 -0
  248. package/build/services/telemetry/index.js +306 -0
  249. package/build/services/worker/index.d.ts +77 -0
  250. package/build/services/worker/index.js +197 -0
  251. package/package.json +1 -1
  252. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  253. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  254. package/typedoc.json +0 -47
  255. package/types/activity.ts +0 -268
  256. package/types/app.ts +0 -20
  257. package/types/async.ts +0 -6
  258. package/types/cache.ts +0 -1
  259. package/types/collator.ts +0 -9
  260. package/types/error.ts +0 -56
  261. package/types/exporter.ts +0 -102
  262. package/types/hook.ts +0 -44
  263. package/types/hotmesh.ts +0 -314
  264. package/types/index.ts +0 -306
  265. package/types/job.ts +0 -233
  266. package/types/logger.ts +0 -8
  267. package/types/manifest.ts +0 -70
  268. package/types/map.ts +0 -5
  269. package/types/memflow.ts +0 -645
  270. package/types/meshcall.ts +0 -235
  271. package/types/meshdata.ts +0 -278
  272. package/types/ms.d.ts +0 -7
  273. package/types/nats.ts +0 -270
  274. package/types/pipe.ts +0 -90
  275. package/types/postgres.ts +0 -114
  276. package/types/provider.ts +0 -161
  277. package/types/quorum.ts +0 -167
  278. package/types/redis.ts +0 -404
  279. package/types/serializer.ts +0 -40
  280. package/types/stats.ts +0 -117
  281. package/types/stream.ts +0 -231
  282. package/types/task.ts +0 -7
  283. package/types/telemetry.ts +0 -16
  284. package/types/transition.ts +0 -20
@@ -0,0 +1,89 @@
1
+ import { KeyStoreParams, KeyType } from '../../modules/key';
2
+ import { ILogger } from '../logger';
3
+ import { SerializerService as Serializer } from '../serializer';
4
+ import { Consumes } from '../../types/activity';
5
+ import { AppVID } from '../../types/app';
6
+ import { HookRule, HookSignal } from '../../types/hook';
7
+ import { HotMeshApps, HotMeshSettings } from '../../types/hotmesh';
8
+ import { ProviderClient, ProviderTransaction } from '../../types/provider';
9
+ import { ThrottleOptions } from '../../types/quorum';
10
+ import { StringAnyType, Symbols, StringStringType, SymbolSets } from '../../types/serializer';
11
+ import { IdsData, JobStatsRange, StatsType } from '../../types/stats';
12
+ import { WorkListTaskType } from '../../types/task';
13
+ import { Cache } from './cache';
14
+ declare abstract class StoreService<Provider extends ProviderClient, TransactionProvider extends ProviderTransaction> {
15
+ storeClient: Provider;
16
+ namespace: string;
17
+ appId: string;
18
+ logger: ILogger;
19
+ cache: Cache;
20
+ serializer: Serializer;
21
+ constructor(client: Provider);
22
+ abstract transact(): TransactionProvider;
23
+ abstract init(namespace: string, appId: string, logger: ILogger): Promise<HotMeshApps>;
24
+ abstract mintKey(type: KeyType, params: KeyStoreParams): string;
25
+ abstract getSettings(bCreate?: boolean): Promise<HotMeshSettings>;
26
+ abstract setSettings(manifest: HotMeshSettings): Promise<any>;
27
+ abstract getApp(id: string, refresh?: boolean): Promise<any>;
28
+ abstract setApp(id: string, version: string): Promise<any>;
29
+ abstract activateAppVersion(id: string, version: string): Promise<boolean>;
30
+ abstract reserveScoutRole(scoutType: 'time' | 'signal' | 'activate', delay?: number): Promise<boolean>;
31
+ abstract releaseScoutRole(scoutType: 'time' | 'signal' | 'activate'): Promise<boolean>;
32
+ abstract reserveSymbolRange(target: string, size: number, type: 'JOB' | 'ACTIVITY', tryCount?: number): Promise<[number, number, Symbols]>;
33
+ abstract getSymbols(activityId: string): Promise<Symbols>;
34
+ abstract addSymbols(activityId: string, symbols: Symbols): Promise<boolean>;
35
+ abstract getSymbolValues(): Promise<Symbols>;
36
+ abstract addSymbolValues(symvals: Symbols): Promise<boolean>;
37
+ abstract getSymbolKeys(symbolNames: string[]): Promise<SymbolSets>;
38
+ abstract setStats(jobKey: string, jobId: string, dateTime: string, stats: StatsType, appVersion: AppVID, transaction?: TransactionProvider): Promise<any>;
39
+ abstract getJobStats(jobKeys: string[]): Promise<JobStatsRange>;
40
+ abstract getJobIds(indexKeys: string[], idRange: [number, number]): Promise<IdsData>;
41
+ abstract setStatus(collationKeyStatus: number, jobId: string, appId: string, transaction?: TransactionProvider): Promise<any>;
42
+ abstract getStatus(jobId: string, appId: string): Promise<number>;
43
+ abstract setStateNX(jobId: string, appId: string, status?: number): Promise<boolean>;
44
+ abstract setState(state: StringAnyType, status: number | null, jobId: string, symbolNames: string[], dIds: StringStringType, transaction?: TransactionProvider): Promise<string>;
45
+ abstract getQueryState(jobId: string, fields: string[]): Promise<StringAnyType>;
46
+ abstract getState(jobId: string, consumes: Consumes, dIds: StringStringType): Promise<[StringAnyType, number] | undefined>;
47
+ abstract getRaw(jobId: string): Promise<StringStringType>;
48
+ abstract collate(jobId: string, activityId: string, amount: number, dIds: StringStringType, transaction?: TransactionProvider): Promise<number>;
49
+ abstract collateSynthetic(jobId: string, guid: string, amount: number, transaction?: TransactionProvider): Promise<number>;
50
+ abstract getSchema(activityId: string, appVersion: AppVID): Promise<any>;
51
+ abstract getSchemas(appVersion: AppVID): Promise<Record<string, any>>;
52
+ abstract setSchemas(schemas: Record<string, any>, appVersion: AppVID): Promise<any>;
53
+ abstract setSubscriptions(subscriptions: Record<string, any>, appVersion: AppVID): Promise<boolean>;
54
+ abstract getSubscriptions(appVersion: AppVID): Promise<Record<string, any>>;
55
+ abstract getSubscription(topic: string, appVersion: AppVID): Promise<string | undefined>;
56
+ abstract setTransitions(transitions: Record<string, any>, appVersion: AppVID): Promise<any>;
57
+ abstract getTransitions(appVersion: AppVID): Promise<any>;
58
+ abstract setHookRules(hookRules: Record<string, HookRule[]>): Promise<any>;
59
+ abstract getHookRules(): Promise<Record<string, HookRule[]>>;
60
+ abstract getAllSymbols(): Promise<Symbols>;
61
+ abstract setHookSignal(hook: HookSignal, transaction?: TransactionProvider): Promise<any>;
62
+ abstract getHookSignal(topic: string, resolved: string): Promise<string | undefined>;
63
+ abstract deleteHookSignal(topic: string, resolved: string): Promise<number | undefined>;
64
+ abstract addTaskQueues(keys: string[]): Promise<void>;
65
+ abstract getActiveTaskQueue(): Promise<string | null>;
66
+ abstract deleteProcessedTaskQueue(workItemKey: string, key: string, processedKey: string, scrub?: boolean): Promise<void>;
67
+ abstract processTaskQueue(sourceKey: string, destinationKey: string): Promise<any>;
68
+ abstract expireJob(jobId: string, inSeconds: number, redisMulti?: TransactionProvider): Promise<void>;
69
+ abstract getDependencies(jobId: string): Promise<string[]>;
70
+ abstract delistSignalKey(key: string, target: string): Promise<void>;
71
+ abstract registerTimeHook(jobId: string, gId: string, activityId: string, type: WorkListTaskType, deletionTime: number, dad: string, transaction?: TransactionProvider): Promise<void>;
72
+ abstract getNextTask(listKey?: string): Promise<[
73
+ listKey: string,
74
+ jobId: string,
75
+ gId: string,
76
+ activityId: string,
77
+ type: WorkListTaskType
78
+ ] | boolean>;
79
+ abstract interrupt(topic: string, jobId: string, options: {
80
+ [key: string]: any;
81
+ }): Promise<void>;
82
+ abstract scrub(jobId: string): Promise<void>;
83
+ abstract findJobs(queryString?: string, limit?: number, batchSize?: number, cursor?: string): Promise<[string, string[]]>;
84
+ abstract findJobFields(jobId: string, fieldMatchPattern?: string, limit?: number, batchSize?: number, cursor?: string): Promise<[string, StringStringType]>;
85
+ abstract setThrottleRate(options: ThrottleOptions): Promise<void>;
86
+ abstract getThrottleRates(): Promise<StringStringType>;
87
+ abstract getThrottleRate(topic: string): Promise<number>;
88
+ }
89
+ export { StoreService };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StoreService = void 0;
4
+ class StoreService {
5
+ constructor(client) {
6
+ this.storeClient = client;
7
+ }
8
+ }
9
+ exports.StoreService = StoreService;
@@ -0,0 +1,168 @@
1
+ import { KeyStoreParams } from '../../../../types/hotmesh';
2
+ import { PostgresClientType } from '../../../../types/postgres';
3
+ import { ProviderTransaction } from '../../../../types/provider';
4
+ import { stringModule } from './kvtypes/string';
5
+ import { hashModule } from './kvtypes/hash';
6
+ import { listModule } from './kvtypes/list';
7
+ import { zsetModule } from './kvtypes/zset';
8
+ /**
9
+ * KVSQL is a class that provides a set of methods to interact with a Postgres database.
10
+ * It is used to interact with the database in a key-value manner.
11
+ */
12
+ export declare class KVSQL {
13
+ pgClient: PostgresClientType;
14
+ namespace: string;
15
+ appId: string;
16
+ string: ReturnType<typeof stringModule>;
17
+ hash: ReturnType<typeof hashModule>;
18
+ list: ReturnType<typeof listModule>;
19
+ zset: ReturnType<typeof zsetModule>;
20
+ constructor(pgClient: PostgresClientType, namespace: string, appId: string);
21
+ isStatusOnly(fields: string[]): boolean;
22
+ appendExpiryClause(baseQuery: string, tableAlias: string): string;
23
+ appendJobExpiryClause(baseQuery: string, tableAlias: string): string;
24
+ getMulti(): ProviderTransaction;
25
+ transact(): ProviderTransaction;
26
+ exec(...args: any[]): Promise<Array<any>>;
27
+ mintKey(type: KeyType, params: KeyStoreParams): string;
28
+ /**
29
+ * Resolves the table name when provided a key
30
+ */
31
+ tableForKey(key: string, stats_type?: 'hash' | 'sorted_set' | 'list'): string;
32
+ safeName(input: string, prefix?: string): string;
33
+ set: (key: string, value: string, options?: import("../../../../types/provider").SetOptions, multi?: ProviderTransaction) => Promise<boolean>;
34
+ _set: (key: string, value: string, options?: import("../../../../types/provider").SetOptions) => {
35
+ sql: string;
36
+ params: any[];
37
+ };
38
+ get: (key: string, multi?: ProviderTransaction) => Promise<string>;
39
+ _get: (key: string) => {
40
+ sql: string;
41
+ params: any[];
42
+ };
43
+ del: (key: string, multi?: ProviderTransaction) => Promise<number>;
44
+ _del: (key: string) => {
45
+ sql: string;
46
+ params: any[];
47
+ };
48
+ setnx: (key: string, value: string, multi?: ProviderTransaction) => Promise<boolean>;
49
+ setnxex: (key: string, value: string, delay: number, multi?: ProviderTransaction) => Promise<boolean>;
50
+ hset: (key: string, fields: Record<string, string>, options?: import("../../../../types/provider").HSetOptions, multi?: ProviderTransaction) => Promise<any>;
51
+ _hset: (key: string, fields: Record<string, string>, options?: import("../../../../types/provider").HSetOptions) => {
52
+ sql: string;
53
+ params: any[];
54
+ };
55
+ hsetnx: (key: string, field: string, value: string, multi?: ProviderTransaction) => Promise<number>;
56
+ hget: (key: string, field: string, multi?: ProviderTransaction) => Promise<string>;
57
+ _hget: (key: string, field: string) => {
58
+ sql: string;
59
+ params: any[];
60
+ };
61
+ hdel: (key: string, fields: string[], multi?: unknown) => Promise<number>;
62
+ _hdel: (key: string, fields: string[]) => {
63
+ sql: string;
64
+ params: any[];
65
+ };
66
+ hmget: (key: string, fields: string[], multi?: ProviderTransaction) => Promise<string[]>;
67
+ _hmget: (key: string, fields: string[]) => {
68
+ sql: string;
69
+ params: any[];
70
+ };
71
+ hgetall: (key: string, multi?: ProviderTransaction) => Promise<Record<string, string>>;
72
+ hincrbyfloat: (key: string, field: string, increment: number, multi?: ProviderTransaction) => Promise<number>;
73
+ _hincrbyfloat: (key: string, field: string, increment: number) => {
74
+ sql: string;
75
+ params: any[];
76
+ };
77
+ hscan: (key: string, cursor: string, count?: number, pattern?: string, multi?: ProviderTransaction) => Promise<import("../../../../types/provider").HScanResult>;
78
+ _hscan: (key: string, cursor: string, count: number, pattern?: string) => {
79
+ sql: string;
80
+ params: any[];
81
+ };
82
+ expire: (key: string, seconds: number, multi?: ProviderTransaction) => Promise<boolean>;
83
+ _expire: (key: string, seconds: number) => {
84
+ sql: string;
85
+ params: any[];
86
+ };
87
+ scan: (cursor: number, count?: number, pattern?: string, multi?: ProviderTransaction) => Promise<{
88
+ cursor: number;
89
+ keys: string[];
90
+ }>;
91
+ _scan: (cursor: number, count: number, pattern?: string) => {
92
+ sql: string;
93
+ params: any[];
94
+ };
95
+ lrange: (key: string, start: number, end: number, multi?: ProviderTransaction) => Promise<string[]>;
96
+ _lrange: (key: string, start: number, end: number) => {
97
+ sql: string;
98
+ params: any[];
99
+ };
100
+ rpush: (key: string, value: string | string[], multi?: ProviderTransaction) => Promise<number>;
101
+ _rpush: (key: string, value: string | string[]) => {
102
+ sql: string;
103
+ params: any[];
104
+ };
105
+ lpush: (key: string, value: string | string[], multi?: ProviderTransaction) => Promise<number>;
106
+ _lpush: (key: string, value: string | string[]) => {
107
+ sql: string;
108
+ params: any[];
109
+ };
110
+ lpop: (key: string, multi?: ProviderTransaction) => Promise<string>;
111
+ _lpop: (key: string) => {
112
+ sql: string;
113
+ params: any[];
114
+ };
115
+ lmove: (source: string, destination: string, srcPosition: "LEFT" | "RIGHT", destPosition: "LEFT" | "RIGHT", multi?: ProviderTransaction) => Promise<string>;
116
+ _lmove: (source: string, destination: string, srcPosition: "LEFT" | "RIGHT", destPosition: "LEFT" | "RIGHT") => {
117
+ sql: string;
118
+ params: any[];
119
+ };
120
+ rename: (oldKey: string, newKey: string, multi?: ProviderTransaction) => Promise<void>;
121
+ _rename: (oldKey: string, newKey: string) => {
122
+ sql: string;
123
+ params: any[];
124
+ };
125
+ zadd: (key: string, score: number, member: string, options?: import("../../../../types/provider").ZAddOptions, multi?: ProviderTransaction) => Promise<number>;
126
+ _zadd: (key: string, score: number, member: string, options?: import("../../../../types/provider").ZAddOptions) => {
127
+ sql: string;
128
+ params: any[];
129
+ };
130
+ zrange: (key: string, start: number, stop: number, facet?: "WITHSCORES", multi?: ProviderTransaction) => Promise<string[]>;
131
+ _zrange: (key: string, start: number, stop: number, facet?: "WITHSCORES") => {
132
+ sql: string;
133
+ params: any[];
134
+ };
135
+ zrangebyscore: (key: string, min: number, max: number, multi?: ProviderTransaction) => Promise<string[]>;
136
+ _zrangebyscore: (key: string, min: number, max: number) => {
137
+ sql: string;
138
+ params: any[];
139
+ };
140
+ zrangebyscore_withscores: (key: string, min: number, max: number, multi?: ProviderTransaction) => Promise<{
141
+ member: string;
142
+ score: number;
143
+ }[]>;
144
+ _zrangebyscore_withscores: (key: string, min: number, max: number) => {
145
+ sql: string;
146
+ params: any[];
147
+ };
148
+ zrem: (key: string, member: string, multi?: ProviderTransaction) => Promise<number>;
149
+ _zrem: (key: string, member: string) => {
150
+ sql: string;
151
+ params: any[];
152
+ };
153
+ zrank: (key: string, member: string, multi?: ProviderTransaction) => Promise<number>;
154
+ _zrank: (key: string, member: string) => {
155
+ sql: string;
156
+ params: any[];
157
+ };
158
+ zscore: (key: string, member: string, multi?: ProviderTransaction) => Promise<number>;
159
+ _zscore: (key: string, member: string) => {
160
+ sql: string;
161
+ params: any[];
162
+ };
163
+ exists(key: string): Promise<string | 0>;
164
+ _exists(key: string): {
165
+ sql: string;
166
+ params: any[];
167
+ };
168
+ }
@@ -0,0 +1,198 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KVSQL = void 0;
4
+ const key_1 = require("../../../../modules/key");
5
+ const kvtransaction_1 = require("./kvtransaction");
6
+ const string_1 = require("./kvtypes/string");
7
+ const hash_1 = require("./kvtypes/hash");
8
+ const list_1 = require("./kvtypes/list");
9
+ const zset_1 = require("./kvtypes/zset");
10
+ /**
11
+ * KVSQL is a class that provides a set of methods to interact with a Postgres database.
12
+ * It is used to interact with the database in a key-value manner.
13
+ */
14
+ class KVSQL {
15
+ constructor(pgClient, namespace, appId) {
16
+ // String Commands
17
+ this.set = (...args) => this.string.set(...args);
18
+ this._set = (...args) => this.string._set(...args);
19
+ this.get = (...args) => this.string.get(...args);
20
+ this._get = (...args) => this.string._get(...args);
21
+ this.del = (...args) => this.string.del(...args);
22
+ this._del = (...args) => this.string._del(...args);
23
+ this.setnx = (...args) => this.string.setnx(...args);
24
+ this.setnxex = (...args) => this.string.setnxex(...args);
25
+ // Hash Commands
26
+ this.hset = (...args) => this.hash.hset(...args);
27
+ this._hset = (...args) => this.hash._hset(...args);
28
+ this.hsetnx = (...args) => this.hash.hsetnx(...args);
29
+ this.hget = (...args) => this.hash.hget(...args);
30
+ this._hget = (...args) => this.hash._hget(...args);
31
+ this.hdel = (...args) => this.hash.hdel(...args);
32
+ this._hdel = (...args) => this.hash._hdel(...args);
33
+ this.hmget = (...args) => this.hash.hmget(...args);
34
+ this._hmget = (...args) => this.hash._hmget(...args);
35
+ this.hgetall = (...args) => this.hash.hgetall(...args);
36
+ this.hincrbyfloat = (...args) => this.hash.hincrbyfloat(...args);
37
+ this._hincrbyfloat = (...args) => this.hash._hincrbyfloat(...args);
38
+ this.hscan = (...args) => this.hash.hscan(...args);
39
+ this._hscan = (...args) => this.hash._hscan(...args);
40
+ this.expire = (...args) => this.hash.expire(...args);
41
+ this._expire = (...args) => this.hash._expire(...args);
42
+ this.scan = (...args) => this.hash.scan(...args);
43
+ this._scan = (...args) => this.hash._scan(...args);
44
+ // List Commands
45
+ this.lrange = (...args) => this.list.lrange(...args);
46
+ this._lrange = (...args) => this.list._lrange(...args);
47
+ this.rpush = (...args) => this.list.rpush(...args);
48
+ this._rpush = (...args) => this.list._rpush(...args);
49
+ this.lpush = (...args) => this.list.lpush(...args);
50
+ this._lpush = (...args) => this.list._lpush(...args);
51
+ this.lpop = (...args) => this.list.lpop(...args);
52
+ this._lpop = (...args) => this.list._lpop(...args);
53
+ this.lmove = (...args) => this.list.lmove(...args);
54
+ this._lmove = (...args) => this.list._lmove(...args);
55
+ this.rename = (...args) => this.list.rename(...args);
56
+ this._rename = (...args) => this.list._rename(...args);
57
+ // Sorted Set Commands
58
+ this.zadd = (...args) => this.zset.zadd(...args);
59
+ this._zadd = (...args) => this.zset._zadd(...args);
60
+ this.zrange = (...args) => this.zset.zrange(...args);
61
+ this._zrange = (...args) => this.zset._zrange(...args);
62
+ this.zrangebyscore = (...args) => this.zset.zrangebyscore(...args);
63
+ this._zrangebyscore = (...args) => this.zset._zrangebyscore(...args);
64
+ this.zrangebyscore_withscores = (...args) => this.zset.zrangebyscore_withscores(...args);
65
+ this._zrangebyscore_withscores = (...args) => this.zset._zrangebyscore_withscores(...args);
66
+ this.zrem = (...args) => this.zset.zrem(...args);
67
+ this._zrem = (...args) => this.zset._zrem(...args);
68
+ this.zrank = (...args) => this.zset.zrank(...args);
69
+ this._zrank = (...args) => this.zset._zrank(...args);
70
+ this.zscore = (...args) => this.zset.zscore(...args);
71
+ this._zscore = (...args) => this.zset._zscore(...args);
72
+ this.pgClient = pgClient;
73
+ this.namespace = namespace;
74
+ this.appId = appId;
75
+ this.hash = (0, hash_1.hashModule)(this);
76
+ this.list = (0, list_1.listModule)(this);
77
+ this.zset = (0, zset_1.zsetModule)(this);
78
+ this.string = (0, string_1.stringModule)(this);
79
+ }
80
+ isStatusOnly(fields) {
81
+ return fields.length === 1 && fields[0] === ':';
82
+ }
83
+ appendExpiryClause(baseQuery, tableAlias) {
84
+ return `
85
+ ${baseQuery}
86
+ AND (${tableAlias}.expiry IS NULL OR ${tableAlias}.expiry > NOW())
87
+ `;
88
+ }
89
+ appendJobExpiryClause(baseQuery, tableAlias) {
90
+ return `
91
+ ${baseQuery}
92
+ AND (${tableAlias}.expired_at IS NULL OR ${tableAlias}.expired_at > NOW())
93
+ `;
94
+ }
95
+ getMulti() {
96
+ return new kvtransaction_1.KVTransaction(this);
97
+ }
98
+ transact() {
99
+ return new kvtransaction_1.KVTransaction(this);
100
+ }
101
+ exec(...args) {
102
+ return Promise.resolve([]);
103
+ }
104
+ mintKey(type, params) {
105
+ //no-op
106
+ return '';
107
+ }
108
+ /**
109
+ * Resolves the table name when provided a key
110
+ */
111
+ tableForKey(key, stats_type) {
112
+ if (key === key_1.HMNS) {
113
+ return 'public.hotmesh_connections';
114
+ }
115
+ const [_, appName, abbrev, ...rest] = key.split(':');
116
+ if (appName === 'a') {
117
+ return 'public.hotmesh_applications';
118
+ }
119
+ const id = rest?.length ? rest.join(':') : '';
120
+ const entity = key_1.KeyService.resolveEntityType(abbrev, id);
121
+ if (this.safeName(this.appId) !== this.safeName(appName)) {
122
+ throw new Error(`App ID mismatch: ${this.appId} !== ${appName}`);
123
+ }
124
+ const schemaName = this.safeName(appName);
125
+ if (entity === 'stats') {
126
+ let tableName;
127
+ if (stats_type === 'sorted_set') {
128
+ tableName = 'stats_ordered';
129
+ }
130
+ else if (stats_type === 'list' || key.endsWith(':processed')) {
131
+ tableName = 'stats_indexed';
132
+ }
133
+ else if (stats_type === 'hash' || /:\d$/.test(key)) {
134
+ tableName = 'stats_counted';
135
+ }
136
+ else {
137
+ throw new Error(`Unknown stats type [${stats_type}] for key [${key}]`);
138
+ }
139
+ return `${schemaName}.${tableName}`;
140
+ }
141
+ if (entity === 'unknown_entity') {
142
+ throw new Error(`Unknown entity type abbreviation: ${abbrev}`);
143
+ }
144
+ else if (entity === 'applications') {
145
+ return 'public.hotmesh_applications';
146
+ }
147
+ else {
148
+ return `${schemaName}.${entity}`;
149
+ }
150
+ }
151
+ safeName(input, prefix = '') {
152
+ if (!input) {
153
+ return 'connections';
154
+ }
155
+ let tableName = input.trim().toLowerCase();
156
+ tableName = tableName.replace(/[^a-z0-9]+/g, '_');
157
+ if (prefix) {
158
+ tableName = `${prefix}_${tableName}`;
159
+ }
160
+ if (tableName.length > 63) {
161
+ tableName = tableName.slice(0, 63);
162
+ }
163
+ tableName = tableName.replace(/_+$/g, '');
164
+ if (!tableName) {
165
+ tableName = 'connections';
166
+ }
167
+ return tableName;
168
+ }
169
+ async exists(key) {
170
+ const { sql, params } = this._exists(key);
171
+ const res = await this.pgClient.query(sql, params);
172
+ return res.rows.length ? res.rows[0].table_name : 0;
173
+ }
174
+ _exists(key) {
175
+ const tableName = this.tableForKey(key);
176
+ const isJobsTable = tableName.endsWith('jobs');
177
+ let sql;
178
+ if (isJobsTable) {
179
+ sql = `
180
+ SELECT FROM ${tableName}
181
+ WHERE id = $1
182
+ AND (expired_at IS NULL OR expired_at > NOW())
183
+ LIMIT 1;
184
+ `;
185
+ }
186
+ else {
187
+ sql = `
188
+ SELECT FROM ${tableName}
189
+ WHERE key = $1
190
+ AND (expiry IS NULL OR expiry > NOW())
191
+ LIMIT 1;
192
+ `;
193
+ }
194
+ const params = [key];
195
+ return { sql, params };
196
+ }
197
+ }
198
+ exports.KVSQL = KVSQL;
@@ -0,0 +1,20 @@
1
+ import { PostgresClientType, PostgresPoolClientType } from '../../../../types/postgres';
2
+ import type { PostgresStoreService } from './postgres';
3
+ export declare const KVTables: (context: PostgresStoreService) => {
4
+ /**
5
+ * Deploys the necessary tables with the specified naming strategy.
6
+ * @param appName - The name of the application.
7
+ */
8
+ deploy(appName: string): Promise<void>;
9
+ getAdvisoryLockId(appName: string): number;
10
+ hashStringToInt(str: string): number;
11
+ waitForTablesCreation(lockId: number, appName: string): Promise<void>;
12
+ checkIfTablesExist(client: PostgresClientType, appName: string): Promise<boolean>;
13
+ createTables(client: PostgresClientType | PostgresPoolClientType, appName: string): Promise<void>;
14
+ getTableNames(appName: string): string[];
15
+ getTableDefinitions(appName: string): Array<{
16
+ schema: string;
17
+ name: string;
18
+ type: string;
19
+ }>;
20
+ };