@hotmeshio/hotmesh 0.4.0 → 0.4.1

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 (283) hide show
  1. package/build/modules/enums.d.ts +110 -0
  2. package/build/modules/enums.js +134 -0
  3. package/build/modules/errors.d.ts +124 -0
  4. package/build/modules/errors.js +191 -0
  5. package/build/modules/key.d.ts +66 -0
  6. package/build/modules/key.js +190 -0
  7. package/build/modules/storage.d.ts +3 -0
  8. package/build/modules/storage.js +5 -0
  9. package/build/modules/utils.d.ts +119 -0
  10. package/build/modules/utils.js +374 -0
  11. package/build/package.json +1 -1
  12. package/build/services/activities/activity.d.ts +104 -0
  13. package/build/services/activities/activity.js +549 -0
  14. package/build/services/activities/await.d.ts +12 -0
  15. package/build/services/activities/await.js +114 -0
  16. package/build/services/activities/cycle.d.ts +19 -0
  17. package/build/services/activities/cycle.js +112 -0
  18. package/build/services/activities/hook.d.ts +27 -0
  19. package/build/services/activities/hook.js +168 -0
  20. package/build/services/activities/index.d.ts +19 -0
  21. package/build/services/activities/index.js +20 -0
  22. package/build/services/activities/interrupt.d.ts +16 -0
  23. package/build/services/activities/interrupt.js +158 -0
  24. package/build/services/activities/signal.d.ts +20 -0
  25. package/build/services/activities/signal.js +134 -0
  26. package/build/services/activities/trigger.d.ts +37 -0
  27. package/build/services/activities/trigger.js +246 -0
  28. package/build/services/activities/worker.d.ts +12 -0
  29. package/build/services/activities/worker.js +106 -0
  30. package/build/services/collator/index.d.ts +111 -0
  31. package/build/services/collator/index.js +293 -0
  32. package/build/services/compiler/deployer.d.ts +40 -0
  33. package/build/services/compiler/deployer.js +488 -0
  34. package/build/services/compiler/index.d.ts +32 -0
  35. package/build/services/compiler/index.js +112 -0
  36. package/build/services/compiler/validator.d.ts +34 -0
  37. package/build/services/compiler/validator.js +147 -0
  38. package/build/services/connector/factory.d.ts +22 -0
  39. package/build/services/connector/factory.js +99 -0
  40. package/build/services/connector/index.d.ts +30 -0
  41. package/build/services/connector/index.js +54 -0
  42. package/build/services/connector/providers/ioredis.d.ts +9 -0
  43. package/build/services/connector/providers/ioredis.js +26 -0
  44. package/build/services/connector/providers/nats.d.ts +9 -0
  45. package/build/services/connector/providers/nats.js +34 -0
  46. package/build/services/connector/providers/postgres.d.ts +20 -0
  47. package/build/services/connector/providers/postgres.js +102 -0
  48. package/build/services/connector/providers/redis.d.ts +9 -0
  49. package/build/services/connector/providers/redis.js +38 -0
  50. package/build/services/engine/index.d.ts +264 -0
  51. package/build/services/engine/index.js +761 -0
  52. package/build/services/exporter/index.d.ts +44 -0
  53. package/build/services/exporter/index.js +126 -0
  54. package/build/services/hotmesh/index.d.ts +483 -0
  55. package/build/services/hotmesh/index.js +622 -0
  56. package/build/services/logger/index.d.ts +16 -0
  57. package/build/services/logger/index.js +54 -0
  58. package/build/services/mapper/index.d.ts +28 -0
  59. package/build/services/mapper/index.js +81 -0
  60. package/build/services/memflow/client.d.ts +108 -0
  61. package/build/services/memflow/client.js +372 -0
  62. package/build/services/memflow/connection.d.ts +23 -0
  63. package/build/services/memflow/connection.js +33 -0
  64. package/build/services/memflow/context.d.ts +143 -0
  65. package/build/services/memflow/context.js +299 -0
  66. package/build/services/memflow/exporter.d.ts +51 -0
  67. package/build/services/memflow/exporter.js +215 -0
  68. package/build/services/memflow/handle.d.ts +90 -0
  69. package/build/services/memflow/handle.js +176 -0
  70. package/build/services/memflow/index.d.ts +116 -0
  71. package/build/services/memflow/index.js +122 -0
  72. package/build/services/memflow/schemas/factory.d.ts +29 -0
  73. package/build/services/memflow/schemas/factory.js +2492 -0
  74. package/build/services/memflow/search.d.ts +142 -0
  75. package/build/services/memflow/search.js +320 -0
  76. package/build/services/memflow/worker.d.ts +124 -0
  77. package/build/services/memflow/worker.js +514 -0
  78. package/build/services/memflow/workflow/all.d.ts +7 -0
  79. package/build/services/memflow/workflow/all.js +15 -0
  80. package/build/services/memflow/workflow/common.d.ts +20 -0
  81. package/build/services/memflow/workflow/common.js +47 -0
  82. package/build/services/memflow/workflow/context.d.ts +6 -0
  83. package/build/services/memflow/workflow/context.js +45 -0
  84. package/build/services/memflow/workflow/contextMethods.d.ts +14 -0
  85. package/build/services/memflow/workflow/contextMethods.js +33 -0
  86. package/build/services/memflow/workflow/didRun.d.ts +7 -0
  87. package/build/services/memflow/workflow/didRun.js +22 -0
  88. package/build/services/memflow/workflow/emit.d.ts +11 -0
  89. package/build/services/memflow/workflow/emit.js +29 -0
  90. package/build/services/memflow/workflow/enrich.d.ts +9 -0
  91. package/build/services/memflow/workflow/enrich.js +17 -0
  92. package/build/services/memflow/workflow/execChild.d.ts +18 -0
  93. package/build/services/memflow/workflow/execChild.js +102 -0
  94. package/build/services/memflow/workflow/execHook.d.ts +65 -0
  95. package/build/services/memflow/workflow/execHook.js +73 -0
  96. package/build/services/memflow/workflow/hook.d.ts +9 -0
  97. package/build/services/memflow/workflow/hook.js +56 -0
  98. package/build/services/memflow/workflow/index.d.ts +74 -0
  99. package/build/services/memflow/workflow/index.js +87 -0
  100. package/build/services/memflow/workflow/interrupt.d.ts +9 -0
  101. package/build/services/memflow/workflow/interrupt.js +24 -0
  102. package/build/services/memflow/workflow/isSideEffectAllowed.d.ts +10 -0
  103. package/build/services/memflow/workflow/isSideEffectAllowed.js +33 -0
  104. package/build/services/memflow/workflow/proxyActivities.d.ts +20 -0
  105. package/build/services/memflow/workflow/proxyActivities.js +97 -0
  106. package/build/services/memflow/workflow/random.d.ts +6 -0
  107. package/build/services/memflow/workflow/random.js +16 -0
  108. package/build/services/memflow/workflow/searchMethods.d.ts +6 -0
  109. package/build/services/memflow/workflow/searchMethods.js +25 -0
  110. package/build/services/memflow/workflow/signal.d.ts +7 -0
  111. package/build/services/memflow/workflow/signal.js +28 -0
  112. package/build/services/memflow/workflow/sleepFor.d.ts +8 -0
  113. package/build/services/memflow/workflow/sleepFor.js +35 -0
  114. package/build/services/memflow/workflow/trace.d.ts +14 -0
  115. package/build/services/memflow/workflow/trace.js +33 -0
  116. package/build/services/memflow/workflow/waitFor.d.ts +8 -0
  117. package/build/services/memflow/workflow/waitFor.js +35 -0
  118. package/build/services/meshcall/index.d.ts +194 -0
  119. package/build/services/meshcall/index.js +452 -0
  120. package/build/services/meshcall/schemas/factory.d.ts +9 -0
  121. package/build/services/meshcall/schemas/factory.js +189 -0
  122. package/build/services/meshdata/index.d.ts +795 -0
  123. package/build/services/meshdata/index.js +1235 -0
  124. package/build/services/meshos/index.d.ts +293 -0
  125. package/build/services/meshos/index.js +547 -0
  126. package/build/services/pipe/functions/array.d.ts +17 -0
  127. package/build/services/pipe/functions/array.js +74 -0
  128. package/build/services/pipe/functions/bitwise.d.ts +9 -0
  129. package/build/services/pipe/functions/bitwise.js +24 -0
  130. package/build/services/pipe/functions/conditional.d.ts +13 -0
  131. package/build/services/pipe/functions/conditional.js +36 -0
  132. package/build/services/pipe/functions/cron.d.ts +12 -0
  133. package/build/services/pipe/functions/cron.js +40 -0
  134. package/build/services/pipe/functions/date.d.ts +58 -0
  135. package/build/services/pipe/functions/date.js +171 -0
  136. package/build/services/pipe/functions/index.d.ts +29 -0
  137. package/build/services/pipe/functions/index.js +30 -0
  138. package/build/services/pipe/functions/json.d.ts +5 -0
  139. package/build/services/pipe/functions/json.js +12 -0
  140. package/build/services/pipe/functions/logical.d.ts +5 -0
  141. package/build/services/pipe/functions/logical.js +12 -0
  142. package/build/services/pipe/functions/math.d.ts +42 -0
  143. package/build/services/pipe/functions/math.js +184 -0
  144. package/build/services/pipe/functions/number.d.ts +21 -0
  145. package/build/services/pipe/functions/number.js +60 -0
  146. package/build/services/pipe/functions/object.d.ts +25 -0
  147. package/build/services/pipe/functions/object.js +81 -0
  148. package/build/services/pipe/functions/string.d.ts +23 -0
  149. package/build/services/pipe/functions/string.js +69 -0
  150. package/build/services/pipe/functions/symbol.d.ts +12 -0
  151. package/build/services/pipe/functions/symbol.js +33 -0
  152. package/build/services/pipe/functions/unary.d.ts +7 -0
  153. package/build/services/pipe/functions/unary.js +18 -0
  154. package/build/services/pipe/index.d.ts +48 -0
  155. package/build/services/pipe/index.js +242 -0
  156. package/build/services/quorum/index.d.ts +90 -0
  157. package/build/services/quorum/index.js +263 -0
  158. package/build/services/reporter/index.d.ts +50 -0
  159. package/build/services/reporter/index.js +348 -0
  160. package/build/services/router/config/index.d.ts +11 -0
  161. package/build/services/router/config/index.js +36 -0
  162. package/build/services/router/consumption/index.d.ts +34 -0
  163. package/build/services/router/consumption/index.js +395 -0
  164. package/build/services/router/error-handling/index.d.ts +8 -0
  165. package/build/services/router/error-handling/index.js +98 -0
  166. package/build/services/router/index.d.ts +57 -0
  167. package/build/services/router/index.js +121 -0
  168. package/build/services/router/lifecycle/index.d.ts +27 -0
  169. package/build/services/router/lifecycle/index.js +80 -0
  170. package/build/services/router/telemetry/index.d.ts +11 -0
  171. package/build/services/router/telemetry/index.js +32 -0
  172. package/build/services/router/throttling/index.d.ts +23 -0
  173. package/build/services/router/throttling/index.js +76 -0
  174. package/build/services/search/factory.d.ts +7 -0
  175. package/build/services/search/factory.js +24 -0
  176. package/build/services/search/index.d.ts +23 -0
  177. package/build/services/search/index.js +10 -0
  178. package/build/services/search/providers/postgres/postgres.d.ts +25 -0
  179. package/build/services/search/providers/postgres/postgres.js +149 -0
  180. package/build/services/search/providers/redis/ioredis.d.ts +19 -0
  181. package/build/services/search/providers/redis/ioredis.js +121 -0
  182. package/build/services/search/providers/redis/redis.d.ts +19 -0
  183. package/build/services/search/providers/redis/redis.js +134 -0
  184. package/build/services/serializer/index.d.ts +42 -0
  185. package/build/services/serializer/index.js +282 -0
  186. package/build/services/store/cache.d.ts +67 -0
  187. package/build/services/store/cache.js +128 -0
  188. package/build/services/store/factory.d.ts +8 -0
  189. package/build/services/store/factory.js +24 -0
  190. package/build/services/store/index.d.ts +89 -0
  191. package/build/services/store/index.js +9 -0
  192. package/build/services/store/providers/postgres/kvsql.d.ts +168 -0
  193. package/build/services/store/providers/postgres/kvsql.js +198 -0
  194. package/build/services/store/providers/postgres/kvtables.d.ts +20 -0
  195. package/build/services/store/providers/postgres/kvtables.js +441 -0
  196. package/build/services/store/providers/postgres/kvtransaction.d.ts +36 -0
  197. package/build/services/store/providers/postgres/kvtransaction.js +248 -0
  198. package/build/services/store/providers/postgres/kvtypes/hash.d.ts +60 -0
  199. package/build/services/store/providers/postgres/kvtypes/hash.js +1287 -0
  200. package/build/services/store/providers/postgres/kvtypes/list.d.ts +33 -0
  201. package/build/services/store/providers/postgres/kvtypes/list.js +194 -0
  202. package/build/services/store/providers/postgres/kvtypes/string.d.ts +20 -0
  203. package/build/services/store/providers/postgres/kvtypes/string.js +115 -0
  204. package/build/services/store/providers/postgres/kvtypes/zset.d.ts +41 -0
  205. package/build/services/store/providers/postgres/kvtypes/zset.js +214 -0
  206. package/build/services/store/providers/postgres/postgres.d.ts +145 -0
  207. package/build/services/store/providers/postgres/postgres.js +1036 -0
  208. package/build/services/store/providers/redis/_base.d.ts +137 -0
  209. package/build/services/store/providers/redis/_base.js +980 -0
  210. package/build/services/store/providers/redis/ioredis.d.ts +20 -0
  211. package/build/services/store/providers/redis/ioredis.js +180 -0
  212. package/build/services/store/providers/redis/redis.d.ts +18 -0
  213. package/build/services/store/providers/redis/redis.js +199 -0
  214. package/build/services/store/providers/store-initializable.d.ts +5 -0
  215. package/build/services/store/providers/store-initializable.js +2 -0
  216. package/build/services/stream/factory.d.ts +8 -0
  217. package/build/services/stream/factory.js +37 -0
  218. package/build/services/stream/index.d.ts +69 -0
  219. package/build/services/stream/index.js +11 -0
  220. package/build/services/stream/providers/nats/nats.d.ts +60 -0
  221. package/build/services/stream/providers/nats/nats.js +225 -0
  222. package/build/services/stream/providers/postgres/kvtables.d.ts +3 -0
  223. package/build/services/stream/providers/postgres/kvtables.js +146 -0
  224. package/build/services/stream/providers/postgres/postgres.d.ts +107 -0
  225. package/build/services/stream/providers/postgres/postgres.js +519 -0
  226. package/build/services/stream/providers/redis/ioredis.d.ts +61 -0
  227. package/build/services/stream/providers/redis/ioredis.js +272 -0
  228. package/build/services/stream/providers/redis/redis.d.ts +61 -0
  229. package/build/services/stream/providers/redis/redis.js +305 -0
  230. package/build/services/stream/providers/stream-initializable.d.ts +4 -0
  231. package/build/services/stream/providers/stream-initializable.js +2 -0
  232. package/build/services/sub/factory.d.ts +7 -0
  233. package/build/services/sub/factory.js +29 -0
  234. package/build/services/sub/index.d.ts +22 -0
  235. package/build/services/sub/index.js +10 -0
  236. package/build/services/sub/providers/nats/nats.d.ts +19 -0
  237. package/build/services/sub/providers/nats/nats.js +105 -0
  238. package/build/services/sub/providers/postgres/postgres.d.ts +19 -0
  239. package/build/services/sub/providers/postgres/postgres.js +92 -0
  240. package/build/services/sub/providers/redis/ioredis.d.ts +17 -0
  241. package/build/services/sub/providers/redis/ioredis.js +81 -0
  242. package/build/services/sub/providers/redis/redis.d.ts +17 -0
  243. package/build/services/sub/providers/redis/redis.js +72 -0
  244. package/build/services/task/index.d.ts +36 -0
  245. package/build/services/task/index.js +206 -0
  246. package/build/services/telemetry/index.d.ts +52 -0
  247. package/build/services/telemetry/index.js +306 -0
  248. package/build/services/worker/index.d.ts +77 -0
  249. package/build/services/worker/index.js +197 -0
  250. package/package.json +1 -1
  251. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  252. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  253. package/typedoc.json +0 -47
  254. package/types/activity.ts +0 -268
  255. package/types/app.ts +0 -20
  256. package/types/async.ts +0 -6
  257. package/types/cache.ts +0 -1
  258. package/types/collator.ts +0 -9
  259. package/types/error.ts +0 -56
  260. package/types/exporter.ts +0 -102
  261. package/types/hook.ts +0 -44
  262. package/types/hotmesh.ts +0 -314
  263. package/types/index.ts +0 -306
  264. package/types/job.ts +0 -233
  265. package/types/logger.ts +0 -8
  266. package/types/manifest.ts +0 -70
  267. package/types/map.ts +0 -5
  268. package/types/memflow.ts +0 -645
  269. package/types/meshcall.ts +0 -235
  270. package/types/meshdata.ts +0 -278
  271. package/types/ms.d.ts +0 -7
  272. package/types/nats.ts +0 -270
  273. package/types/pipe.ts +0 -90
  274. package/types/postgres.ts +0 -114
  275. package/types/provider.ts +0 -161
  276. package/types/quorum.ts +0 -167
  277. package/types/redis.ts +0 -404
  278. package/types/serializer.ts +0 -40
  279. package/types/stats.ts +0 -117
  280. package/types/stream.ts +0 -231
  281. package/types/task.ts +0 -7
  282. package/types/telemetry.ts +0 -16
  283. package/types/transition.ts +0 -20
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RedisSearchService = void 0;
4
+ const index_1 = require("../../index");
5
+ class RedisSearchService extends index_1.SearchService {
6
+ constructor(searchClient, storeClient) {
7
+ super(searchClient, storeClient);
8
+ }
9
+ async init(namespace, appId, logger) {
10
+ this.namespace = namespace;
11
+ this.appId = appId;
12
+ this.logger = logger;
13
+ }
14
+ async createSearchIndex(indexName, prefixes, schema) {
15
+ try {
16
+ await this.searchClient.sendCommand([
17
+ 'FT.CREATE',
18
+ indexName,
19
+ 'ON',
20
+ 'HASH',
21
+ 'PREFIX',
22
+ prefixes.length.toString(),
23
+ ...prefixes,
24
+ 'SCHEMA',
25
+ ...schema,
26
+ ]);
27
+ }
28
+ catch (error) {
29
+ this.logger.info('Error creating search index', { error });
30
+ throw error;
31
+ }
32
+ }
33
+ async listSearchIndexes() {
34
+ try {
35
+ const indexes = await this.searchClient.sendCommand(['FT._LIST']);
36
+ return indexes;
37
+ }
38
+ catch (error) {
39
+ this.logger.info('Error listing search indexes', { error });
40
+ throw error;
41
+ }
42
+ }
43
+ async updateContext(key, fields) {
44
+ //no-op;
45
+ throw new Error('Not implemented');
46
+ }
47
+ async setFields(key, fields) {
48
+ try {
49
+ const result = await this.searchClient.HSET(key, fields);
50
+ return Number(result);
51
+ }
52
+ catch (error) {
53
+ this.logger.error(`Error setting fields for key: ${key}`, { error });
54
+ throw error;
55
+ }
56
+ }
57
+ async getField(key, field) {
58
+ try {
59
+ return await this.searchClient.HGET(key, field);
60
+ }
61
+ catch (error) {
62
+ this.logger.error(`Error getting field ${field} for key: ${key}`, {
63
+ error,
64
+ });
65
+ throw error;
66
+ }
67
+ }
68
+ async getFields(key, fields) {
69
+ try {
70
+ return await this.searchClient.HMGET(key, [...fields]);
71
+ }
72
+ catch (error) {
73
+ this.logger.error(`Error getting fields for key: ${key}`, { error });
74
+ throw error;
75
+ }
76
+ }
77
+ async getAllFields(key) {
78
+ try {
79
+ return await this.searchClient.HGETALL(key);
80
+ }
81
+ catch (error) {
82
+ this.logger.error(`Error getting fields for key: ${key}`, { error });
83
+ throw error;
84
+ }
85
+ }
86
+ async deleteFields(key, fields) {
87
+ try {
88
+ const result = await this.searchClient.HDEL(key, fields);
89
+ return Number(result);
90
+ }
91
+ catch (error) {
92
+ this.logger.error(`Error deleting fields for key: ${key}`, { error });
93
+ throw error;
94
+ }
95
+ }
96
+ async incrementFieldByFloat(key, field, increment) {
97
+ try {
98
+ const result = await this.searchClient.HINCRBYFLOAT(key, field, increment);
99
+ return Number(result);
100
+ }
101
+ catch (error) {
102
+ this.logger.error(`Error incrementing field ${field} for key: ${key}`, {
103
+ error,
104
+ });
105
+ throw error;
106
+ }
107
+ }
108
+ async sendQuery(...query) {
109
+ try {
110
+ return await this.searchClient.sendCommand(query);
111
+ }
112
+ catch (error) {
113
+ this.logger.error('Error executing query', { error });
114
+ throw error;
115
+ }
116
+ }
117
+ async sendIndexedQuery(index, query) {
118
+ try {
119
+ if (query[0]?.startsWith('FT.')) {
120
+ return (await this.searchClient.sendCommand(query));
121
+ }
122
+ return (await this.searchClient.sendCommand([
123
+ 'FT.SEARCH',
124
+ index,
125
+ ...query,
126
+ ]));
127
+ }
128
+ catch (error) {
129
+ this.logger.error('Error executing query', { error });
130
+ throw error;
131
+ }
132
+ }
133
+ }
134
+ exports.RedisSearchService = RedisSearchService;
@@ -0,0 +1,42 @@
1
+ import { Consumes } from '../../types/activity';
2
+ import { StringStringType, StringAnyType, SymbolMap, SymbolMaps, SymbolSets, Symbols } from '../../types/serializer';
3
+ export declare const MDATA_SYMBOLS: {
4
+ SLOTS: number;
5
+ ACTIVITY: {
6
+ KEYS: string[];
7
+ };
8
+ ACTIVITY_UPDATE: {
9
+ KEYS: string[];
10
+ };
11
+ JOB: {
12
+ KEYS: string[];
13
+ };
14
+ JOB_UPDATE: {
15
+ KEYS: string[];
16
+ };
17
+ };
18
+ export declare class SerializerService {
19
+ dIds: StringStringType;
20
+ symKeys: SymbolMaps;
21
+ symReverseKeys: SymbolMaps;
22
+ symValMaps: SymbolMap;
23
+ symValReverseMaps: SymbolMap;
24
+ constructor();
25
+ abbreviate(consumes: Consumes, symbolNames: string[], fields?: string[]): string[];
26
+ resolveDimensionalIndex(path: string): string;
27
+ isJobPath(path: string): boolean;
28
+ resetSymbols(symKeys: SymbolSets, symVals: Symbols, dIds: StringStringType): void;
29
+ getReverseKeyMap(keyMap: SymbolMap, id?: string): SymbolMap;
30
+ getReverseValueMap(valueMap: SymbolMap): SymbolMap;
31
+ static filterSymVals(startIndex: number, maxIndex: number, existingSymbolValues: Symbols, proposedValues: Set<string>): Symbols;
32
+ compress(document: StringStringType, ids: string[]): StringStringType;
33
+ isLiteralKeyType(key: string): boolean;
34
+ decompress(document: StringStringType, ids: string[]): StringStringType;
35
+ stringify(document: Record<string, any>): StringStringType;
36
+ parse(document: StringStringType): any;
37
+ static toString(value: any): string | undefined;
38
+ static fromString(value: string | undefined): any;
39
+ package(multiDimensionalDocument: StringAnyType, ids: string[]): StringStringType;
40
+ unpackage(document: StringStringType, ids: string[]): StringAnyType;
41
+ export(): SymbolSets;
42
+ }
@@ -0,0 +1,282 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SerializerService = exports.MDATA_SYMBOLS = void 0;
4
+ const utils_1 = require("../../modules/utils");
5
+ const dateReg = /^"\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z)?"$/;
6
+ exports.MDATA_SYMBOLS = {
7
+ SLOTS: 26,
8
+ ACTIVITY: {
9
+ KEYS: ['aid', 'dad', 'as', 'atp', 'stp', 'ac', 'au', 'err', 'l1s', 'l2s'],
10
+ },
11
+ ACTIVITY_UPDATE: {
12
+ KEYS: ['au', 'err', 'l2s'],
13
+ },
14
+ JOB: {
15
+ KEYS: [
16
+ 'ngn',
17
+ 'tpc',
18
+ 'pj',
19
+ 'pg',
20
+ 'pd',
21
+ 'px',
22
+ 'pa',
23
+ 'key',
24
+ 'app',
25
+ 'vrs',
26
+ 'jid',
27
+ 'gid',
28
+ 'aid',
29
+ 'ts',
30
+ 'jc',
31
+ 'ju',
32
+ 'js',
33
+ 'err',
34
+ 'trc',
35
+ ],
36
+ },
37
+ JOB_UPDATE: {
38
+ KEYS: ['ju', 'err'],
39
+ },
40
+ };
41
+ class SerializerService {
42
+ constructor() {
43
+ this.resetSymbols({}, {}, {});
44
+ }
45
+ abbreviate(consumes, symbolNames, fields = []) {
46
+ for (const symbolName of symbolNames) {
47
+ const symbolSet = this.symKeys.get(symbolName);
48
+ const symbolPaths = consumes[symbolName];
49
+ for (const symbolPath of symbolPaths) {
50
+ const abbreviation = symbolSet.get(symbolPath);
51
+ if (abbreviation) {
52
+ const dimensionalIndex = this.resolveDimensionalIndex(symbolPath);
53
+ fields.push(`${abbreviation}${dimensionalIndex}`);
54
+ }
55
+ else {
56
+ fields.push(symbolPath);
57
+ }
58
+ }
59
+ }
60
+ return fields;
61
+ }
62
+ resolveDimensionalIndex(path) {
63
+ if (this.isJobPath(path)) {
64
+ return '';
65
+ }
66
+ else {
67
+ const [activityId] = path.split('/');
68
+ if (activityId in this.dIds) {
69
+ return this.dIds[activityId];
70
+ }
71
+ else if ('$ADJACENT' in this.dIds) {
72
+ //else=> pre-authorizing adjacent activity entry
73
+ return this.dIds['$ADJACENT'];
74
+ }
75
+ return ',0';
76
+ }
77
+ }
78
+ isJobPath(path) {
79
+ return path.startsWith('data/') || path.startsWith('metadata/');
80
+ }
81
+ resetSymbols(symKeys, symVals, dIds) {
82
+ this.symKeys = new Map();
83
+ this.symReverseKeys = new Map();
84
+ for (const id in symKeys) {
85
+ this.symKeys.set(id, new Map(Object.entries(symKeys[id])));
86
+ }
87
+ this.symValMaps = new Map(Object.entries(symVals));
88
+ this.symValReverseMaps = this.getReverseValueMap(this.symValMaps);
89
+ this.dIds = dIds;
90
+ }
91
+ getReverseKeyMap(keyMap, id) {
92
+ let map = this.symReverseKeys.get(id);
93
+ if (!map) {
94
+ map = new Map();
95
+ for (const [key, val] of keyMap.entries()) {
96
+ map.set(val, key);
97
+ }
98
+ this.symReverseKeys.set(id, map);
99
+ }
100
+ return map;
101
+ }
102
+ getReverseValueMap(valueMap) {
103
+ const map = new Map();
104
+ for (const [key, val] of valueMap.entries()) {
105
+ map.set(val, key);
106
+ }
107
+ return map;
108
+ }
109
+ static filterSymVals(startIndex, maxIndex, existingSymbolValues, proposedValues) {
110
+ const newSymbolValues = {};
111
+ const currentSymbolValues = { ...existingSymbolValues };
112
+ const currentValuesSet = new Set(Object.values(currentSymbolValues));
113
+ for (const value of proposedValues) {
114
+ if (!currentValuesSet.has(value)) {
115
+ if (startIndex > maxIndex) {
116
+ return newSymbolValues;
117
+ }
118
+ const symbol = (0, utils_1.getSymVal)(startIndex);
119
+ startIndex++;
120
+ newSymbolValues[symbol] = value;
121
+ currentValuesSet.add(value);
122
+ }
123
+ }
124
+ return newSymbolValues;
125
+ }
126
+ compress(document, ids) {
127
+ if (this.symKeys.size === 0) {
128
+ return document;
129
+ }
130
+ const source = { ...document };
131
+ const result = {};
132
+ const compressWithMap = (abbreviationMap, id) => {
133
+ for (const key in source) {
134
+ if (key.startsWith(`${id}/`) ||
135
+ id.startsWith('$') &&
136
+ ['data', 'metadata'].includes(key.split('/')[0])) {
137
+ const dimensionalIndex = this.resolveDimensionalIndex(key);
138
+ const shortKey = abbreviationMap.get(key) || key;
139
+ const shortDimensionalKey = `${shortKey}${dimensionalIndex}`;
140
+ result[shortDimensionalKey] = source[key];
141
+ }
142
+ else if (!(key in result) && this.isLiteralKeyType(key)) {
143
+ //mark (-) and search (_)
144
+ result[key] = source[key];
145
+ }
146
+ }
147
+ };
148
+ for (const id of ids) {
149
+ const abbreviationMap = this.symKeys.get(id);
150
+ if (abbreviationMap) {
151
+ compressWithMap(abbreviationMap, id);
152
+ }
153
+ }
154
+ return result;
155
+ }
156
+ isLiteralKeyType(key) {
157
+ return key.startsWith('-') || key.startsWith('_');
158
+ }
159
+ decompress(document, ids) {
160
+ if (this.symKeys.size === 0) {
161
+ return document;
162
+ }
163
+ const result = { ...document };
164
+ const inflateWithMap = (abbreviationMap, id) => {
165
+ const reversedAbbreviationMap = this.getReverseKeyMap(abbreviationMap, id);
166
+ for (const key in result) {
167
+ //strip dimensional index from key
168
+ const shortKey = key.split(',')[0];
169
+ const longKey = reversedAbbreviationMap.get(shortKey);
170
+ if (longKey) {
171
+ result[longKey] = result[key];
172
+ delete result[key];
173
+ }
174
+ }
175
+ };
176
+ for (const id of ids) {
177
+ const abbreviationMap = this.symKeys.get(id);
178
+ if (abbreviationMap) {
179
+ inflateWithMap(abbreviationMap, id);
180
+ }
181
+ }
182
+ return result;
183
+ }
184
+ //stringify: convert a n-dimensional document to a 2-d hash
185
+ stringify(document) {
186
+ const result = {};
187
+ for (const key in document) {
188
+ const value = SerializerService.toString(document[key]);
189
+ if (value) {
190
+ // if (/^:*[a-zA-Z]{2}$/.test(value)) {
191
+ // value = ':' + value;
192
+ // } else if (this.symValReverseMaps.has(value)) {
193
+ // value = this.symValReverseMaps.get(value);
194
+ // }
195
+ result[key] = value;
196
+ }
197
+ }
198
+ return result;
199
+ }
200
+ //parse: convert a 2-d hash to a n-dimensional document
201
+ parse(document) {
202
+ const result = {};
203
+ for (const [key, value] of Object.entries(document)) {
204
+ if (value === undefined || value === null)
205
+ continue;
206
+ // if (/^:+[a-zA-Z]{2}$/.test(value)) {
207
+ // result[key] = value.slice(1);
208
+ // } else {
209
+ // if (value?.length === 2 && this.symValMaps.has(value)) {
210
+ // value = this.symValMaps.get(value);
211
+ // }
212
+ result[key] = SerializerService.fromString(value);
213
+ // }
214
+ }
215
+ return result;
216
+ }
217
+ static toString(value) {
218
+ switch (typeof value) {
219
+ case 'string':
220
+ break;
221
+ case 'boolean':
222
+ value = value ? '/t' : '/f';
223
+ break;
224
+ case 'number':
225
+ value = '/d' + value.toString();
226
+ break;
227
+ case 'undefined':
228
+ return undefined;
229
+ case 'object':
230
+ if (value === null) {
231
+ value = '/n';
232
+ }
233
+ else {
234
+ value = '/s' + JSON.stringify(value);
235
+ }
236
+ break;
237
+ }
238
+ return value;
239
+ }
240
+ static fromString(value) {
241
+ if (typeof value !== 'string')
242
+ return undefined;
243
+ const prefix = value.slice(0, 2);
244
+ const rest = value.slice(2);
245
+ switch (prefix) {
246
+ case '/t': // boolean true
247
+ return true;
248
+ case '/f': // boolean false
249
+ return false;
250
+ case '/d': // number
251
+ return Number(rest);
252
+ case '/n': // null
253
+ return null;
254
+ case '/s': // object (JSON string)
255
+ if (dateReg.exec(rest)) {
256
+ return new Date(JSON.parse(rest));
257
+ }
258
+ return JSON.parse(rest);
259
+ default: // string
260
+ return value;
261
+ }
262
+ }
263
+ package(multiDimensionalDocument, ids) {
264
+ const flatDocument = this.stringify(multiDimensionalDocument);
265
+ return this.compress(flatDocument, ids);
266
+ }
267
+ unpackage(document, ids) {
268
+ const multiDimensionalDocument = this.decompress(document, ids);
269
+ return this.parse(multiDimensionalDocument);
270
+ }
271
+ export() {
272
+ const obj = {};
273
+ for (const [id, map] of this.symKeys.entries()) {
274
+ obj[id] = {};
275
+ for (const [key, value] of map.entries()) {
276
+ obj[id][key] = value;
277
+ }
278
+ }
279
+ return obj;
280
+ }
281
+ }
282
+ exports.SerializerService = SerializerService;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * The Cache is a key/value store and used to store commonly accessed Redis metadata
3
+ * (mainly the execution rules for the app) to save time accessing them as they
4
+ * are immutable per verison. Rules are only ejected when a new version
5
+ * (a new distributed executable) is deployed to the quorum
6
+ * and the cache is invalidated/cleared of the prior version.
7
+ */
8
+ import { ActivityType } from '../../types/activity';
9
+ import { HookRule } from '../../types/hook';
10
+ import { HotMeshApp, HotMeshSettings } from '../../types/hotmesh';
11
+ import { Symbols } from '../../types/serializer';
12
+ import { Transitions } from '../../types/transition';
13
+ declare class Cache {
14
+ settings: HotMeshSettings;
15
+ appId: string;
16
+ apps: Record<string, HotMeshApp>;
17
+ schemas: Record<string, ActivityType>;
18
+ subscriptions: Record<string, Record<string, string>>;
19
+ symbols: Record<string, Symbols>;
20
+ symvals: Record<string, Symbols>;
21
+ transitions: Record<string, Record<string, unknown>>;
22
+ hookRules: Record<string, Record<string, HookRule[]>>;
23
+ workItems: Record<string, string>;
24
+ /**
25
+ * The cache is ALWAYS initialized with HotMeshSettings. The other parameters are optional.
26
+ * @param settings
27
+ * @param apps
28
+ * @param schemas
29
+ * @param subscriptions
30
+ * @param transitions
31
+ * @param hookRules
32
+ */
33
+ constructor(appId: string, settings: HotMeshSettings, apps?: Record<string, HotMeshApp>, schemas?: Record<string, ActivityType>, subscriptions?: Record<string, Record<string, string>>, symbols?: Record<string, Symbols>, symvals?: Record<string, Symbols>, transitions?: Record<string, Record<string, unknown>>, hookRules?: Record<string, Record<string, HookRule[]>>, workItems?: Record<string, string>);
34
+ /**
35
+ * invalidate the cache; settings are not invalidated!
36
+ */
37
+ invalidate(): void;
38
+ getSettings(): HotMeshSettings;
39
+ setSettings(settings: HotMeshSettings): void;
40
+ getApps(): Record<string, HotMeshApp>;
41
+ getApp(appId: string): HotMeshApp;
42
+ setApps(apps: Record<string, HotMeshApp>): void;
43
+ setApp(appId: string, app: HotMeshApp): void;
44
+ getSchemas(appId: string, version: string): Record<string, ActivityType>;
45
+ getSchema(appId: string, version: string, activityId: string): ActivityType;
46
+ setSchemas(appId: string, version: string, schemas: Record<string, ActivityType>): void;
47
+ setSchema(appId: string, version: string, activityId: string, schema: ActivityType): void;
48
+ getSubscriptions(appId: string, version: string): Record<string, string>;
49
+ getSubscription(appId: string, version: string, topic: string): unknown;
50
+ setSubscriptions(appId: string, version: string, subscriptions: Record<string, string>): void;
51
+ getSymbols(appId: string, targetEntityId: string): Symbols;
52
+ setSymbols(appId: string, targetEntityId: string, symbols: Symbols): void;
53
+ deleteSymbols(appId: string, targetEntityId: string): void;
54
+ getSymbolValues(appId: string): Symbols;
55
+ setSymbolValues(appId: string, symvals: Symbols): void;
56
+ deleteSymbolValues(appId: string): void;
57
+ getTransitions(appId: string, version: string): Transitions;
58
+ setTransitions(appId: string, version: string, transitions: Transitions): void;
59
+ getHookRules(appId: string): Record<string, HookRule[]>;
60
+ setHookRules(appId: string, hookRules: Record<string, HookRule[]>): void;
61
+ getSignals(appId: string, version: string): Record<string, unknown>;
62
+ setSignals(appId: string, version: string): Record<string, unknown>;
63
+ getActiveTaskQueue(appId: string): string;
64
+ setWorkItem(appId: string, workItem: string): void;
65
+ removeWorkItem(appId: string): void;
66
+ }
67
+ export { Cache };
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ /**
3
+ * The Cache is a key/value store and used to store commonly accessed Redis metadata
4
+ * (mainly the execution rules for the app) to save time accessing them as they
5
+ * are immutable per verison. Rules are only ejected when a new version
6
+ * (a new distributed executable) is deployed to the quorum
7
+ * and the cache is invalidated/cleared of the prior version.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.Cache = void 0;
11
+ class Cache {
12
+ /**
13
+ * The cache is ALWAYS initialized with HotMeshSettings. The other parameters are optional.
14
+ * @param settings
15
+ * @param apps
16
+ * @param schemas
17
+ * @param subscriptions
18
+ * @param transitions
19
+ * @param hookRules
20
+ */
21
+ constructor(appId, settings, apps = {}, schemas = {}, subscriptions = {}, symbols = {}, symvals = {}, transitions = {}, hookRules = {}, workItems = {}) {
22
+ this.appId = appId;
23
+ this.settings = settings;
24
+ this.apps = apps;
25
+ this.schemas = schemas;
26
+ this.subscriptions = subscriptions;
27
+ this.symbols = symbols;
28
+ this.symvals = symvals;
29
+ this.transitions = transitions;
30
+ this.hookRules = hookRules;
31
+ this.workItems = workItems;
32
+ }
33
+ /**
34
+ * invalidate the cache; settings are not invalidated!
35
+ */
36
+ invalidate() {
37
+ this.apps = {};
38
+ this.schemas = {};
39
+ this.subscriptions = {};
40
+ this.transitions = {};
41
+ this.hookRules = {};
42
+ }
43
+ getSettings() {
44
+ return this.settings;
45
+ }
46
+ setSettings(settings) {
47
+ this.settings = settings;
48
+ }
49
+ getApps() {
50
+ return this.apps;
51
+ }
52
+ getApp(appId) {
53
+ return this.apps[appId];
54
+ }
55
+ setApps(apps) {
56
+ this.apps = apps;
57
+ }
58
+ setApp(appId, app) {
59
+ this.apps[appId] = app;
60
+ }
61
+ getSchemas(appId, version) {
62
+ return this.schemas[`${appId}/${version}`];
63
+ }
64
+ getSchema(appId, version, activityId) {
65
+ return this.schemas?.[`${appId}/${version}`]?.[activityId];
66
+ }
67
+ setSchemas(appId, version, schemas) {
68
+ this.schemas[`${appId}/${version}`] = schemas;
69
+ }
70
+ setSchema(appId, version, activityId, schema) {
71
+ this.schemas[`${appId}/${version}`][activityId] = schema;
72
+ }
73
+ getSubscriptions(appId, version) {
74
+ return this.subscriptions[`${appId}/${version}`];
75
+ }
76
+ getSubscription(appId, version, topic) {
77
+ return this.subscriptions?.[`${appId}/${version}`]?.[topic];
78
+ }
79
+ setSubscriptions(appId, version, subscriptions) {
80
+ this.subscriptions[`${appId}/${version}`] = subscriptions;
81
+ }
82
+ getSymbols(appId, targetEntityId) {
83
+ return this.symbols[`${appId}/${targetEntityId}`];
84
+ }
85
+ setSymbols(appId, targetEntityId, symbols) {
86
+ this.symbols[`${appId}/${targetEntityId}`] = symbols;
87
+ }
88
+ deleteSymbols(appId, targetEntityId) {
89
+ delete this.symbols[`${appId}/${targetEntityId}`];
90
+ }
91
+ getSymbolValues(appId) {
92
+ return this.symvals[`${appId}`];
93
+ }
94
+ setSymbolValues(appId, symvals) {
95
+ this.symvals[`${appId}`] = symvals;
96
+ }
97
+ deleteSymbolValues(appId) {
98
+ delete this.symvals[`${appId}`];
99
+ }
100
+ getTransitions(appId, version) {
101
+ return this.transitions[`${appId}/${version}`];
102
+ }
103
+ setTransitions(appId, version, transitions) {
104
+ this.transitions[`${appId}/${version}`] = transitions;
105
+ }
106
+ getHookRules(appId) {
107
+ return this.hookRules[`${appId}`];
108
+ }
109
+ setHookRules(appId, hookRules) {
110
+ this.hookRules[`${appId}`] = hookRules;
111
+ }
112
+ getSignals(appId, version) {
113
+ throw new Error('SIGNAL (getHooks) is not supported');
114
+ }
115
+ setSignals(appId, version) {
116
+ throw new Error('SIGNAL (setHook) is not supported');
117
+ }
118
+ getActiveTaskQueue(appId) {
119
+ return this.workItems[appId];
120
+ }
121
+ setWorkItem(appId, workItem) {
122
+ this.workItems[appId] = workItem;
123
+ }
124
+ removeWorkItem(appId) {
125
+ delete this.workItems[appId];
126
+ }
127
+ }
128
+ exports.Cache = Cache;
@@ -0,0 +1,8 @@
1
+ import { ILogger } from '../logger';
2
+ import { ProviderClient, ProviderTransaction } from '../../types/provider';
3
+ import { StoreInitializable } from './providers/store-initializable';
4
+ import { StoreService } from './index';
5
+ declare class StoreServiceFactory {
6
+ static init(providerClient: ProviderClient, namespace: string, appId: string, logger: ILogger): Promise<StoreService<ProviderClient, ProviderTransaction> & StoreInitializable>;
7
+ }
8
+ export { StoreServiceFactory };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StoreServiceFactory = void 0;
4
+ const utils_1 = require("../../modules/utils");
5
+ const ioredis_1 = require("./providers/redis/ioredis");
6
+ const redis_1 = require("./providers/redis/redis");
7
+ const postgres_1 = require("./providers/postgres/postgres");
8
+ class StoreServiceFactory {
9
+ static async init(providerClient, namespace, appId, logger) {
10
+ let service;
11
+ if ((0, utils_1.identifyProvider)(providerClient) === 'redis') {
12
+ service = new redis_1.RedisStoreService(providerClient);
13
+ }
14
+ else if ((0, utils_1.identifyProvider)(providerClient) === 'ioredis') {
15
+ service = new ioredis_1.IORedisStoreService(providerClient);
16
+ }
17
+ else if ((0, utils_1.identifyProvider)(providerClient) === 'postgres') {
18
+ service = new postgres_1.PostgresStoreService(providerClient);
19
+ } //etc
20
+ await service.init(namespace, appId, logger);
21
+ return service;
22
+ }
23
+ }
24
+ exports.StoreServiceFactory = StoreServiceFactory;