@hotmeshio/hotmesh 0.3.32 → 0.4.0

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 (254) hide show
  1. package/README.md +128 -823
  2. package/build/index.d.ts +9 -9
  3. package/build/index.js +10 -10
  4. package/build/package.json +22 -21
  5. package/build/types/error.d.ts +5 -5
  6. package/build/types/exporter.d.ts +1 -1
  7. package/build/types/index.d.ts +3 -3
  8. package/build/types/manifest.d.ts +2 -2
  9. package/build/types/{meshflow.d.ts → memflow.d.ts} +15 -15
  10. package/build/types/meshdata.d.ts +3 -3
  11. package/build/types/postgres.d.ts +7 -0
  12. package/build/types/stream.d.ts +3 -0
  13. package/index.ts +11 -11
  14. package/package.json +22 -21
  15. package/typedoc.json +8 -7
  16. package/types/error.ts +5 -5
  17. package/types/exporter.ts +1 -1
  18. package/types/index.ts +7 -7
  19. package/types/manifest.ts +2 -2
  20. package/types/{meshflow.ts → memflow.ts} +15 -15
  21. package/types/meshdata.ts +3 -3
  22. package/types/postgres.ts +9 -0
  23. package/types/stream.ts +4 -0
  24. package/build/modules/enums.d.ts +0 -110
  25. package/build/modules/enums.js +0 -134
  26. package/build/modules/errors.d.ts +0 -124
  27. package/build/modules/errors.js +0 -191
  28. package/build/modules/key.d.ts +0 -66
  29. package/build/modules/key.js +0 -1
  30. package/build/modules/storage.d.ts +0 -3
  31. package/build/modules/storage.js +0 -5
  32. package/build/modules/utils.d.ts +0 -119
  33. package/build/modules/utils.js +0 -1
  34. package/build/services/activities/activity.d.ts +0 -104
  35. package/build/services/activities/activity.js +0 -1
  36. package/build/services/activities/await.d.ts +0 -12
  37. package/build/services/activities/await.js +0 -1
  38. package/build/services/activities/cycle.d.ts +0 -19
  39. package/build/services/activities/cycle.js +0 -1
  40. package/build/services/activities/hook.d.ts +0 -27
  41. package/build/services/activities/hook.js +0 -1
  42. package/build/services/activities/index.d.ts +0 -19
  43. package/build/services/activities/index.js +0 -1
  44. package/build/services/activities/interrupt.d.ts +0 -16
  45. package/build/services/activities/interrupt.js +0 -1
  46. package/build/services/activities/signal.d.ts +0 -20
  47. package/build/services/activities/signal.js +0 -1
  48. package/build/services/activities/trigger.d.ts +0 -37
  49. package/build/services/activities/trigger.js +0 -1
  50. package/build/services/activities/worker.d.ts +0 -12
  51. package/build/services/activities/worker.js +0 -1
  52. package/build/services/collator/index.d.ts +0 -111
  53. package/build/services/collator/index.js +0 -1
  54. package/build/services/compiler/deployer.d.ts +0 -40
  55. package/build/services/compiler/deployer.js +0 -1
  56. package/build/services/compiler/index.d.ts +0 -32
  57. package/build/services/compiler/index.js +0 -1
  58. package/build/services/compiler/validator.d.ts +0 -34
  59. package/build/services/compiler/validator.js +0 -1
  60. package/build/services/connector/factory.d.ts +0 -22
  61. package/build/services/connector/factory.js +0 -99
  62. package/build/services/connector/index.d.ts +0 -30
  63. package/build/services/connector/index.js +0 -54
  64. package/build/services/connector/providers/ioredis.d.ts +0 -9
  65. package/build/services/connector/providers/ioredis.js +0 -26
  66. package/build/services/connector/providers/nats.d.ts +0 -9
  67. package/build/services/connector/providers/nats.js +0 -34
  68. package/build/services/connector/providers/postgres.d.ts +0 -20
  69. package/build/services/connector/providers/postgres.js +0 -102
  70. package/build/services/connector/providers/redis.d.ts +0 -9
  71. package/build/services/connector/providers/redis.js +0 -38
  72. package/build/services/engine/index.d.ts +0 -264
  73. package/build/services/engine/index.js +0 -1
  74. package/build/services/exporter/index.d.ts +0 -44
  75. package/build/services/exporter/index.js +0 -1
  76. package/build/services/hotmesh/index.d.ts +0 -340
  77. package/build/services/hotmesh/index.js +0 -479
  78. package/build/services/logger/index.d.ts +0 -16
  79. package/build/services/logger/index.js +0 -54
  80. package/build/services/mapper/index.d.ts +0 -28
  81. package/build/services/mapper/index.js +0 -1
  82. package/build/services/meshcall/index.d.ts +0 -194
  83. package/build/services/meshcall/index.js +0 -452
  84. package/build/services/meshcall/schemas/factory.d.ts +0 -9
  85. package/build/services/meshcall/schemas/factory.js +0 -189
  86. package/build/services/meshdata/index.d.ts +0 -795
  87. package/build/services/meshdata/index.js +0 -1235
  88. package/build/services/meshflow/client.d.ts +0 -108
  89. package/build/services/meshflow/client.js +0 -371
  90. package/build/services/meshflow/connection.d.ts +0 -23
  91. package/build/services/meshflow/connection.js +0 -33
  92. package/build/services/meshflow/exporter.d.ts +0 -51
  93. package/build/services/meshflow/exporter.js +0 -1
  94. package/build/services/meshflow/handle.d.ts +0 -90
  95. package/build/services/meshflow/handle.js +0 -176
  96. package/build/services/meshflow/index.d.ts +0 -111
  97. package/build/services/meshflow/index.js +0 -117
  98. package/build/services/meshflow/schemas/factory.d.ts +0 -29
  99. package/build/services/meshflow/schemas/factory.js +0 -2492
  100. package/build/services/meshflow/search.d.ts +0 -142
  101. package/build/services/meshflow/search.js +0 -320
  102. package/build/services/meshflow/worker.d.ts +0 -124
  103. package/build/services/meshflow/worker.js +0 -514
  104. package/build/services/meshflow/workflow/all.d.ts +0 -7
  105. package/build/services/meshflow/workflow/all.js +0 -15
  106. package/build/services/meshflow/workflow/common.d.ts +0 -18
  107. package/build/services/meshflow/workflow/common.js +0 -45
  108. package/build/services/meshflow/workflow/context.d.ts +0 -6
  109. package/build/services/meshflow/workflow/context.js +0 -45
  110. package/build/services/meshflow/workflow/didRun.d.ts +0 -7
  111. package/build/services/meshflow/workflow/didRun.js +0 -22
  112. package/build/services/meshflow/workflow/emit.d.ts +0 -11
  113. package/build/services/meshflow/workflow/emit.js +0 -29
  114. package/build/services/meshflow/workflow/enrich.d.ts +0 -9
  115. package/build/services/meshflow/workflow/enrich.js +0 -17
  116. package/build/services/meshflow/workflow/execChild.d.ts +0 -18
  117. package/build/services/meshflow/workflow/execChild.js +0 -102
  118. package/build/services/meshflow/workflow/hook.d.ts +0 -9
  119. package/build/services/meshflow/workflow/hook.js +0 -40
  120. package/build/services/meshflow/workflow/index.d.ts +0 -70
  121. package/build/services/meshflow/workflow/index.js +0 -83
  122. package/build/services/meshflow/workflow/interrupt.d.ts +0 -9
  123. package/build/services/meshflow/workflow/interrupt.js +0 -24
  124. package/build/services/meshflow/workflow/isSideEffectAllowed.d.ts +0 -10
  125. package/build/services/meshflow/workflow/isSideEffectAllowed.js +0 -33
  126. package/build/services/meshflow/workflow/proxyActivities.d.ts +0 -20
  127. package/build/services/meshflow/workflow/proxyActivities.js +0 -97
  128. package/build/services/meshflow/workflow/random.d.ts +0 -6
  129. package/build/services/meshflow/workflow/random.js +0 -16
  130. package/build/services/meshflow/workflow/searchMethods.d.ts +0 -6
  131. package/build/services/meshflow/workflow/searchMethods.js +0 -25
  132. package/build/services/meshflow/workflow/signal.d.ts +0 -7
  133. package/build/services/meshflow/workflow/signal.js +0 -28
  134. package/build/services/meshflow/workflow/sleepFor.d.ts +0 -8
  135. package/build/services/meshflow/workflow/sleepFor.js +0 -35
  136. package/build/services/meshflow/workflow/trace.d.ts +0 -14
  137. package/build/services/meshflow/workflow/trace.js +0 -33
  138. package/build/services/meshflow/workflow/waitFor.d.ts +0 -8
  139. package/build/services/meshflow/workflow/waitFor.js +0 -35
  140. package/build/services/meshos/index.d.ts +0 -293
  141. package/build/services/meshos/index.js +0 -547
  142. package/build/services/pipe/functions/array.d.ts +0 -17
  143. package/build/services/pipe/functions/array.js +0 -1
  144. package/build/services/pipe/functions/bitwise.d.ts +0 -9
  145. package/build/services/pipe/functions/bitwise.js +0 -1
  146. package/build/services/pipe/functions/conditional.d.ts +0 -13
  147. package/build/services/pipe/functions/conditional.js +0 -1
  148. package/build/services/pipe/functions/cron.d.ts +0 -12
  149. package/build/services/pipe/functions/cron.js +0 -1
  150. package/build/services/pipe/functions/date.d.ts +0 -58
  151. package/build/services/pipe/functions/date.js +0 -1
  152. package/build/services/pipe/functions/index.d.ts +0 -29
  153. package/build/services/pipe/functions/index.js +0 -1
  154. package/build/services/pipe/functions/json.d.ts +0 -5
  155. package/build/services/pipe/functions/json.js +0 -1
  156. package/build/services/pipe/functions/logical.d.ts +0 -5
  157. package/build/services/pipe/functions/logical.js +0 -1
  158. package/build/services/pipe/functions/math.d.ts +0 -42
  159. package/build/services/pipe/functions/math.js +0 -1
  160. package/build/services/pipe/functions/number.d.ts +0 -21
  161. package/build/services/pipe/functions/number.js +0 -1
  162. package/build/services/pipe/functions/object.d.ts +0 -25
  163. package/build/services/pipe/functions/object.js +0 -1
  164. package/build/services/pipe/functions/string.d.ts +0 -23
  165. package/build/services/pipe/functions/string.js +0 -1
  166. package/build/services/pipe/functions/symbol.d.ts +0 -12
  167. package/build/services/pipe/functions/symbol.js +0 -1
  168. package/build/services/pipe/functions/unary.d.ts +0 -7
  169. package/build/services/pipe/functions/unary.js +0 -1
  170. package/build/services/pipe/index.d.ts +0 -48
  171. package/build/services/pipe/index.js +0 -1
  172. package/build/services/quorum/index.d.ts +0 -90
  173. package/build/services/quorum/index.js +0 -1
  174. package/build/services/reporter/index.d.ts +0 -50
  175. package/build/services/reporter/index.js +0 -1
  176. package/build/services/router/index.d.ts +0 -60
  177. package/build/services/router/index.js +0 -1
  178. package/build/services/search/factory.d.ts +0 -7
  179. package/build/services/search/factory.js +0 -24
  180. package/build/services/search/index.d.ts +0 -22
  181. package/build/services/search/index.js +0 -10
  182. package/build/services/search/providers/postgres/postgres.d.ts +0 -24
  183. package/build/services/search/providers/postgres/postgres.js +0 -1
  184. package/build/services/search/providers/redis/ioredis.d.ts +0 -18
  185. package/build/services/search/providers/redis/ioredis.js +0 -1
  186. package/build/services/search/providers/redis/redis.d.ts +0 -18
  187. package/build/services/search/providers/redis/redis.js +0 -1
  188. package/build/services/serializer/index.d.ts +0 -42
  189. package/build/services/serializer/index.js +0 -1
  190. package/build/services/store/cache.d.ts +0 -67
  191. package/build/services/store/cache.js +0 -128
  192. package/build/services/store/factory.d.ts +0 -8
  193. package/build/services/store/factory.js +0 -24
  194. package/build/services/store/index.d.ts +0 -89
  195. package/build/services/store/index.js +0 -9
  196. package/build/services/store/providers/postgres/kvsql.d.ts +0 -168
  197. package/build/services/store/providers/postgres/kvsql.js +0 -1
  198. package/build/services/store/providers/postgres/kvtables.d.ts +0 -20
  199. package/build/services/store/providers/postgres/kvtables.js +0 -1
  200. package/build/services/store/providers/postgres/kvtransaction.d.ts +0 -36
  201. package/build/services/store/providers/postgres/kvtransaction.js +0 -1
  202. package/build/services/store/providers/postgres/kvtypes/hash.d.ts +0 -60
  203. package/build/services/store/providers/postgres/kvtypes/hash.js +0 -1
  204. package/build/services/store/providers/postgres/kvtypes/list.d.ts +0 -33
  205. package/build/services/store/providers/postgres/kvtypes/list.js +0 -1
  206. package/build/services/store/providers/postgres/kvtypes/string.d.ts +0 -20
  207. package/build/services/store/providers/postgres/kvtypes/string.js +0 -1
  208. package/build/services/store/providers/postgres/kvtypes/zset.d.ts +0 -41
  209. package/build/services/store/providers/postgres/kvtypes/zset.js +0 -1
  210. package/build/services/store/providers/postgres/postgres.d.ts +0 -145
  211. package/build/services/store/providers/postgres/postgres.js +0 -1
  212. package/build/services/store/providers/redis/_base.d.ts +0 -137
  213. package/build/services/store/providers/redis/_base.js +0 -1
  214. package/build/services/store/providers/redis/ioredis.d.ts +0 -20
  215. package/build/services/store/providers/redis/ioredis.js +0 -1
  216. package/build/services/store/providers/redis/redis.d.ts +0 -18
  217. package/build/services/store/providers/redis/redis.js +0 -1
  218. package/build/services/store/providers/store-initializable.d.ts +0 -5
  219. package/build/services/store/providers/store-initializable.js +0 -1
  220. package/build/services/stream/factory.d.ts +0 -8
  221. package/build/services/stream/factory.js +0 -37
  222. package/build/services/stream/index.d.ts +0 -64
  223. package/build/services/stream/index.js +0 -11
  224. package/build/services/stream/providers/nats/nats.d.ts +0 -59
  225. package/build/services/stream/providers/nats/nats.js +0 -1
  226. package/build/services/stream/providers/postgres/kvtables.d.ts +0 -2
  227. package/build/services/stream/providers/postgres/kvtables.js +0 -1
  228. package/build/services/stream/providers/postgres/postgres.d.ts +0 -88
  229. package/build/services/stream/providers/postgres/postgres.js +0 -1
  230. package/build/services/stream/providers/redis/ioredis.d.ts +0 -60
  231. package/build/services/stream/providers/redis/ioredis.js +0 -1
  232. package/build/services/stream/providers/redis/redis.d.ts +0 -60
  233. package/build/services/stream/providers/redis/redis.js +0 -1
  234. package/build/services/stream/providers/stream-initializable.d.ts +0 -4
  235. package/build/services/stream/providers/stream-initializable.js +0 -1
  236. package/build/services/sub/factory.d.ts +0 -7
  237. package/build/services/sub/factory.js +0 -29
  238. package/build/services/sub/index.d.ts +0 -22
  239. package/build/services/sub/index.js +0 -10
  240. package/build/services/sub/providers/nats/nats.d.ts +0 -19
  241. package/build/services/sub/providers/nats/nats.js +0 -1
  242. package/build/services/sub/providers/postgres/postgres.d.ts +0 -19
  243. package/build/services/sub/providers/postgres/postgres.js +0 -1
  244. package/build/services/sub/providers/redis/ioredis.d.ts +0 -17
  245. package/build/services/sub/providers/redis/ioredis.js +0 -1
  246. package/build/services/sub/providers/redis/redis.d.ts +0 -17
  247. package/build/services/sub/providers/redis/redis.js +0 -1
  248. package/build/services/task/index.d.ts +0 -36
  249. package/build/services/task/index.js +0 -1
  250. package/build/services/telemetry/index.d.ts +0 -52
  251. package/build/services/telemetry/index.js +0 -1
  252. package/build/services/worker/index.d.ts +0 -77
  253. package/build/services/worker/index.js +0 -1
  254. /package/build/types/{meshflow.js → memflow.js} +0 -0
@@ -1,142 +0,0 @@
1
- import { HotMesh } from '../hotmesh';
2
- import { SearchService } from '../search';
3
- import { WorkflowSearchOptions } from '../../types/meshflow';
4
- /**
5
- * The Search module provides methods for reading and
6
- * writing record data to a workflow. The instance
7
- * methods exposed by this class are available
8
- * for use from within a running workflow. The following example
9
- * uses search to set a `name` field and increment a
10
- * `counter` field. The workflow returns the incremented value.
11
- *
12
- * @example
13
- * ```typescript
14
- * //searchWorkflow.ts
15
- * import { workflow } from '@hotmeshio/hotmesh';
16
-
17
- * export async function searchExample(name: string): Promise<{counter: number}> {
18
- * const search = await workflow.search();
19
- * await search.set({ name });
20
- * const newCounterValue = await search.incr('counter', 1);
21
- * return { counter: newCounterValue };
22
- * }
23
- * ```
24
- */
25
- export declare class Search {
26
- /**
27
- * @private
28
- */
29
- jobId: string;
30
- /**
31
- * @private
32
- */
33
- searchSessionId: string;
34
- /**
35
- * @private
36
- */
37
- searchSessionIndex: number;
38
- /**
39
- * @private
40
- */
41
- hotMeshClient: HotMesh;
42
- /**
43
- * @private
44
- */
45
- search: SearchService<any> | null;
46
- /**
47
- * @private
48
- */
49
- cachedFields: Record<string, string>;
50
- /**
51
- * @private
52
- */
53
- constructor(workflowId: string, hotMeshClient: HotMesh, searchSessionId: string);
54
- /**
55
- * Prefixes the key with an underscore to keep separate from the
56
- * activity and job history (and searchable via HKEYS)
57
- *
58
- * @private
59
- */
60
- safeKey(key: string): string;
61
- /**
62
- * For those deployments with search configured, this method
63
- * will configure the search index with the provided schema.
64
- *
65
- * @private
66
- * @example
67
- * const search = {
68
- * index: 'my_search_index',
69
- * prefix: ['my_workflow_prefix'],
70
- * schema: {
71
- * field1: { type: 'TEXT', sortable: true },
72
- * field2: { type: 'NUMERIC', sortable: true }
73
- * }
74
- * }
75
- * await Search.configureSearchIndex(hotMeshClient, search);
76
- */
77
- static configureSearchIndex(hotMeshClient: HotMesh, search?: WorkflowSearchOptions): Promise<void>;
78
- /**
79
- * Returns an array of search indexes ids
80
- *
81
- * @example
82
- * const searchIndexes = await Search.listSearchIndexes(hotMeshClient);
83
- */
84
- static listSearchIndexes(hotMeshClient: HotMesh): Promise<string[]>;
85
- /**
86
- * increments the index to return a unique search session guid when
87
- * calling any method that produces side effects (changes the value)
88
- * @private
89
- */
90
- getSearchSessionGuid(): string;
91
- /**
92
- * Sets the fields listed in args. Returns the
93
- * count of new fields that were set (does not
94
- * count fields that were updated)
95
- *
96
- * @example
97
- * const search = await workflow.search();
98
- * const count = await search.set({ field1: 'value1', field2: 'value2' });
99
- */
100
- set(...args: any[]): Promise<number>;
101
- /**
102
- * Returns the value of the record data field, given a field id
103
- *
104
- * @example
105
- * const search = await workflow.search();
106
- * const value = await search.get('field1');
107
- */
108
- get(id: string): Promise<string>;
109
- /**
110
- * Returns the values of all specified fields in the HASH stored at key.
111
- */
112
- mget(...args: string[]): Promise<string[]>;
113
- /**
114
- * Deletes the fields provided as args. Returns the
115
- * count of fields that were deleted.
116
- *
117
- * @example
118
- * const search = await workflow.search();
119
- * const count = await search.del('field1', 'field2', 'field3');
120
- */
121
- del(...args: string[]): Promise<number | void>;
122
- /**
123
- * Increments the value of a float field by the given amount. Returns the
124
- * new value of the field after the increment. Pass a negative
125
- * number to decrement the value.
126
- *
127
- * @example
128
- * const search = await workflow.search();
129
- * const count = await search.incr('field1', 1.5);
130
- */
131
- incr(key: string, val: number): Promise<number>;
132
- /**
133
- * Multiplies the value of a field by the given amount. Returns the
134
- * new value of the field after the multiplication. NOTE:
135
- * this is exponential multiplication.
136
- *
137
- * @example
138
- * const search = await workflow.search();
139
- * const product = await search.mult('field1', 1.5);
140
- */
141
- mult(key: string, val: number): Promise<number>;
142
- }
@@ -1,320 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Search = void 0;
4
- const key_1 = require("../../modules/key");
5
- const storage_1 = require("../../modules/storage");
6
- /**
7
- * The Search module provides methods for reading and
8
- * writing record data to a workflow. The instance
9
- * methods exposed by this class are available
10
- * for use from within a running workflow. The following example
11
- * uses search to set a `name` field and increment a
12
- * `counter` field. The workflow returns the incremented value.
13
- *
14
- * @example
15
- * ```typescript
16
- * //searchWorkflow.ts
17
- * import { workflow } from '@hotmeshio/hotmesh';
18
-
19
- * export async function searchExample(name: string): Promise<{counter: number}> {
20
- * const search = await workflow.search();
21
- * await search.set({ name });
22
- * const newCounterValue = await search.incr('counter', 1);
23
- * return { counter: newCounterValue };
24
- * }
25
- * ```
26
- */
27
- class Search {
28
- /**
29
- * @private
30
- */
31
- constructor(workflowId, hotMeshClient, searchSessionId) {
32
- /**
33
- * @private
34
- */
35
- this.searchSessionIndex = 0;
36
- /**
37
- * @private
38
- */
39
- this.cachedFields = {};
40
- const keyParams = {
41
- appId: hotMeshClient.appId,
42
- jobId: workflowId,
43
- };
44
- this.jobId = key_1.KeyService.mintKey(hotMeshClient.namespace, key_1.KeyType.JOB_STATE, keyParams);
45
- this.searchSessionId = searchSessionId;
46
- this.hotMeshClient = hotMeshClient;
47
- this.search = hotMeshClient.engine.search;
48
- }
49
- /**
50
- * Prefixes the key with an underscore to keep separate from the
51
- * activity and job history (and searchable via HKEYS)
52
- *
53
- * @private
54
- */
55
- safeKey(key) {
56
- if (key.startsWith('"')) {
57
- return key.slice(1, -1);
58
- }
59
- return `_${key}`;
60
- }
61
- /**
62
- * For those deployments with search configured, this method
63
- * will configure the search index with the provided schema.
64
- *
65
- * @private
66
- * @example
67
- * const search = {
68
- * index: 'my_search_index',
69
- * prefix: ['my_workflow_prefix'],
70
- * schema: {
71
- * field1: { type: 'TEXT', sortable: true },
72
- * field2: { type: 'NUMERIC', sortable: true }
73
- * }
74
- * }
75
- * await Search.configureSearchIndex(hotMeshClient, search);
76
- */
77
- static async configureSearchIndex(hotMeshClient, search) {
78
- if (search?.schema) {
79
- const searchService = hotMeshClient.engine.search;
80
- const schema = [];
81
- for (const [key, value] of Object.entries(search.schema)) {
82
- if (value.indexed !== false) {
83
- schema.push(value.fieldName ? `${value.fieldName.toString()}` : `_${key}`);
84
- schema.push(value.type ? value.type : 'TEXT');
85
- if (value.noindex) {
86
- schema.push('NOINDEX');
87
- }
88
- else {
89
- if (value.nostem && value.type === 'TEXT') {
90
- schema.push('NOSTEM');
91
- }
92
- if (value.sortable) {
93
- schema.push('SORTABLE');
94
- }
95
- }
96
- }
97
- }
98
- try {
99
- const keyParams = {
100
- appId: hotMeshClient.appId,
101
- jobId: '',
102
- };
103
- const hotMeshPrefix = key_1.KeyService.mintKey(hotMeshClient.namespace, key_1.KeyType.JOB_STATE, keyParams);
104
- const prefixes = search.prefix.map((prefix) => `${hotMeshPrefix}${prefix}`);
105
- await searchService.createSearchIndex(`${search.index}`, prefixes, schema);
106
- }
107
- catch (error) {
108
- hotMeshClient.engine.logger.info('meshflow-client-search-err', {
109
- error,
110
- });
111
- }
112
- }
113
- }
114
- /**
115
- * Returns an array of search indexes ids
116
- *
117
- * @example
118
- * const searchIndexes = await Search.listSearchIndexes(hotMeshClient);
119
- */
120
- static async listSearchIndexes(hotMeshClient) {
121
- try {
122
- const searchService = hotMeshClient.engine.search;
123
- return await searchService.listSearchIndexes();
124
- }
125
- catch (error) {
126
- hotMeshClient.engine.logger.info('meshflow-client-search-list-err', {
127
- error,
128
- });
129
- return [];
130
- }
131
- }
132
- /**
133
- * increments the index to return a unique search session guid when
134
- * calling any method that produces side effects (changes the value)
135
- * @private
136
- */
137
- getSearchSessionGuid() {
138
- return `${this.searchSessionId}-${this.searchSessionIndex++}-`;
139
- }
140
- /**
141
- * Sets the fields listed in args. Returns the
142
- * count of new fields that were set (does not
143
- * count fields that were updated)
144
- *
145
- * @example
146
- * const search = await workflow.search();
147
- * const count = await search.set({ field1: 'value1', field2: 'value2' });
148
- */
149
- async set(...args) {
150
- const ssGuid = this.getSearchSessionGuid();
151
- const store = storage_1.asyncLocalStorage.getStore();
152
- const replay = store?.get('replay') ?? {};
153
- if (ssGuid in replay) {
154
- return Number(replay[ssGuid]);
155
- }
156
- const fields = {};
157
- if (typeof args[0] === 'object') {
158
- for (const [key, value] of Object.entries(args[0])) {
159
- delete this.cachedFields[key];
160
- fields[this.safeKey(key)] = value.toString();
161
- }
162
- }
163
- else {
164
- for (let i = 0; i < args.length; i += 2) {
165
- const keyName = args[i];
166
- delete this.cachedFields[keyName];
167
- const key = this.safeKey(keyName);
168
- const value = args[i + 1].toString();
169
- fields[key] = value;
170
- }
171
- }
172
- const fieldCount = await this.search.setFields(this.jobId, fields);
173
- await this.search.setFields(this.jobId, {
174
- [ssGuid]: fieldCount.toString(),
175
- });
176
- return fieldCount;
177
- }
178
- /**
179
- * Returns the value of the record data field, given a field id
180
- *
181
- * @example
182
- * const search = await workflow.search();
183
- * const value = await search.get('field1');
184
- */
185
- async get(id) {
186
- try {
187
- if (id in this.cachedFields) {
188
- return this.cachedFields[id];
189
- }
190
- const value = await this.search.getField(this.jobId, this.safeKey(id));
191
- this.cachedFields[id] = value;
192
- return value;
193
- }
194
- catch (error) {
195
- this.hotMeshClient.logger.error('meshflow-search-get-error', {
196
- error,
197
- });
198
- return '';
199
- }
200
- }
201
- /**
202
- * Returns the values of all specified fields in the HASH stored at key.
203
- */
204
- async mget(...args) {
205
- let isCached = true;
206
- const values = [];
207
- const safeArgs = [];
208
- for (let i = 0; i < args.length; i++) {
209
- if (isCached && args[i] in this.cachedFields) {
210
- values.push(this.cachedFields[args[i]]);
211
- }
212
- else {
213
- isCached = false;
214
- }
215
- safeArgs.push(this.safeKey(args[i]));
216
- }
217
- try {
218
- if (isCached) {
219
- return values;
220
- }
221
- const returnValues = await this.search.getFields(this.jobId, safeArgs);
222
- returnValues.forEach((value, index) => {
223
- if (value !== null) {
224
- this.cachedFields[args[index]] = value;
225
- }
226
- });
227
- return returnValues;
228
- }
229
- catch (error) {
230
- this.hotMeshClient.logger.error('meshflow-search-mget-error', {
231
- error,
232
- });
233
- return [];
234
- }
235
- }
236
- /**
237
- * Deletes the fields provided as args. Returns the
238
- * count of fields that were deleted.
239
- *
240
- * @example
241
- * const search = await workflow.search();
242
- * const count = await search.del('field1', 'field2', 'field3');
243
- */
244
- async del(...args) {
245
- const ssGuid = this.getSearchSessionGuid();
246
- const store = storage_1.asyncLocalStorage.getStore();
247
- const replay = store?.get('replay') ?? {};
248
- const safeArgs = [];
249
- for (let i = 0; i < args.length; i++) {
250
- const keyName = args[i];
251
- delete this.cachedFields[keyName];
252
- safeArgs.push(this.safeKey(keyName));
253
- }
254
- if (ssGuid in replay) {
255
- return Number(replay[ssGuid]);
256
- }
257
- const response = await this.search.deleteFields(this.jobId, safeArgs);
258
- const formattedResponse = isNaN(response)
259
- ? 0
260
- : Number(response);
261
- await this.search.setFields(this.jobId, {
262
- [ssGuid]: formattedResponse.toString(),
263
- });
264
- return formattedResponse;
265
- }
266
- /**
267
- * Increments the value of a float field by the given amount. Returns the
268
- * new value of the field after the increment. Pass a negative
269
- * number to decrement the value.
270
- *
271
- * @example
272
- * const search = await workflow.search();
273
- * const count = await search.incr('field1', 1.5);
274
- */
275
- async incr(key, val) {
276
- delete this.cachedFields[key];
277
- const ssGuid = this.getSearchSessionGuid();
278
- const store = storage_1.asyncLocalStorage.getStore();
279
- const replay = store?.get('replay') ?? {};
280
- if (ssGuid in replay) {
281
- return Number(replay[ssGuid]);
282
- }
283
- const num = await this.search.incrementFieldByFloat(this.jobId, this.safeKey(key), val);
284
- await this.search.setFields(this.jobId, { [ssGuid]: num.toString() });
285
- return num;
286
- }
287
- /**
288
- * Multiplies the value of a field by the given amount. Returns the
289
- * new value of the field after the multiplication. NOTE:
290
- * this is exponential multiplication.
291
- *
292
- * @example
293
- * const search = await workflow.search();
294
- * const product = await search.mult('field1', 1.5);
295
- */
296
- async mult(key, val) {
297
- delete this.cachedFields[key];
298
- const ssGuid = this.getSearchSessionGuid();
299
- const store = storage_1.asyncLocalStorage.getStore();
300
- const replay = store?.get('replay') ?? {};
301
- if (ssGuid in replay) {
302
- return Math.exp(Number(replay[ssGuid]));
303
- }
304
- const ssGuidValue = await this.search.incrementFieldByFloat(this.jobId, ssGuid, 1);
305
- if (ssGuidValue === 1) {
306
- const log = Math.log(val);
307
- const logTotal = await this.search.incrementFieldByFloat(this.jobId, this.safeKey(key), log);
308
- await this.search.setFields(this.jobId, {
309
- [ssGuid]: logTotal.toString(),
310
- });
311
- return Math.exp(logTotal);
312
- }
313
- else {
314
- const logTotalStr = await this.search.getField(this.jobId, ssGuid);
315
- const logTotal = Number(logTotalStr);
316
- return Math.exp(logTotal);
317
- }
318
- }
319
- }
320
- exports.Search = Search;
@@ -1,124 +0,0 @@
1
- import { HotMesh } from '../hotmesh';
2
- import { Connection, Registry, WorkerConfig, WorkerOptions } from '../../types/meshflow';
3
- /**
4
- * The *Worker* service Registers worker functions and connects them to the mesh,
5
- * using the target backend provider/s (Redis, Postgres, NATS, etc).
6
- *
7
- * @example
8
- * ```typescript
9
- * import { MeshFlow } from '@hotmeshio/hotmesh';
10
- * import { Client as Postgres } from 'pg';
11
- * import * as workflows from './workflows';
12
- *
13
- * async function run() {
14
- * const worker = await MeshFlow.Worker.create({
15
- * connection: {
16
- * class: Postgres,
17
- * options: { connectionString: 'postgres://user:password@localhost:5432/db' }
18
- * },
19
- * taskQueue: 'default',
20
- * workflow: workflows.example,
21
- * });
22
- *
23
- * await worker.run();
24
- * }
25
- * ```
26
- */
27
- export declare class WorkerService {
28
- /**
29
- * @private
30
- */
31
- static activityRegistry: Registry;
32
- /**
33
- * @private
34
- */
35
- static instances: Map<string, HotMesh | Promise<HotMesh>>;
36
- /**
37
- * @private
38
- */
39
- workflowRunner: HotMesh;
40
- /**
41
- * @private
42
- */
43
- activityRunner: HotMesh;
44
- /**
45
- * @private
46
- */
47
- static getHotMesh: (workflowTopic: string, config?: Partial<WorkerConfig>, options?: WorkerOptions) => Promise<HotMesh>;
48
- static hashOptions(connection: Connection): string;
49
- /**
50
- * @private
51
- */
52
- constructor();
53
- /**
54
- * @private
55
- */
56
- static activateWorkflow(hotMesh: HotMesh): Promise<void>;
57
- /**
58
- * @private
59
- */
60
- static registerActivities<ACT>(activities: ACT): Registry;
61
- /**
62
- * Connects a worker to the mesh.
63
- *
64
- * @example
65
- * ```typescript
66
- * import { MeshFlow } from '@hotmeshio/hotmesh';
67
- * import { Client as Postgres } from 'pg';
68
- * import * as workflows from './workflows';
69
- *
70
- * async function run() {
71
- * const worker = await MeshFlow.Worker.create({
72
- * connection: {
73
- * class: Postgres,
74
- * options: {
75
- * connectionString: 'postgres://user:password@localhost:5432/db'
76
- * },
77
- * },
78
- * taskQueue: 'default',
79
- * workflow: workflows.example,
80
- * });
81
- *
82
- * await worker.run();
83
- * }
84
- * ```
85
- */
86
- static create(config: WorkerConfig): Promise<WorkerService>;
87
- /**
88
- * @private
89
- */
90
- static resolveWorkflowTarget(workflow: object | Function, name?: string): [string, Function];
91
- /**
92
- * Run the connected worker; no-op (unnecessary to call)
93
- */
94
- run(): Promise<void>;
95
- /**
96
- * @private
97
- */
98
- initActivityWorker(config: WorkerConfig, activityTopic: string): Promise<HotMesh>;
99
- /**
100
- * @private
101
- */
102
- wrapActivityFunctions(): Function;
103
- /**
104
- * @private
105
- */
106
- initWorkflowWorker(config: WorkerConfig, workflowTopic: string, workflowFunction: Function): Promise<HotMesh>;
107
- /**
108
- * @private
109
- */
110
- static Context: {
111
- info: () => {
112
- workflowId: string;
113
- workflowTopic: string;
114
- };
115
- };
116
- /**
117
- * @private
118
- */
119
- wrapWorkflowFunction(workflowFunction: Function, workflowTopic: string, config: WorkerConfig): Function;
120
- /**
121
- * @private
122
- */
123
- static shutdown(): Promise<void>;
124
- }