@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,547 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MeshOS = void 0;
4
- const index_1 = require("../meshdata/index");
5
- const utils_1 = require("../../modules/utils");
6
- const logger_1 = require("../logger");
7
- /**
8
- * MeshOS is an abstract base class for schema-driven entity management within the Mesh network.
9
- * It provides a foundation for defining custom entities.
10
- * By subclassing MeshOS, you can create entities with specific schemas and behaviors, enabling
11
- * structured data storage, retrieval, and transactional workflows.
12
- *
13
- * ### Subclassing MeshOS
14
- *
15
- * Standard CRUD methods are included and use your provided schema to
16
- * fields to return in the response: create, retrieve, update, delete.
17
- *
18
- * Search methods are included and use your provided schema to
19
- * fields to return in the response: count, find, aggregate.
20
- *
21
- * Implement other methods as needed for the entity's
22
- * functionality; For example, subclass/override methods like `create`
23
- * to also spawn a transactional workflow
24
- *
25
- * @example
26
- * ```typescript
27
- * import { MeshOS } from '@hotmeshio/hotmesh';
28
- * import { Types } from '@hotmeshio/hotmesh';
29
- * import { schema } from './schema'; // Import your schema
30
- * import * as workflows from './workflows';
31
- *
32
- * class Widget extends MeshOS {
33
- *
34
- * //Subclass the `connect` method to connect workers and
35
- * // hooks (optional) when the container starts
36
- * async connect() {
37
- * await this.meshData.connect({
38
- * entity: this.getEntity(),
39
- * //the `target widget workflow` runs as a transaction
40
- * target: function() {
41
- * return { hello: 'world' };
42
- * },
43
- * options: {
44
- * namespace: this.getNamespace(),
45
- * taskQueue: this.getTaskQueue(),
46
- * },
47
- * });
48
- * }
49
- *
50
- * // subclass the `create` method to start a transactional
51
- * // workflow; use the options/search field to set default
52
- * // record data `{ ...input}` and invoke the `target widget workflow`
53
- * async create(input: Types.StringAnyType): Promise<Types.StringStringType> {
54
- * return await this.meshData.exec<Types.StringStringType>({
55
- * entity: this.getEntity(),
56
- * args: [{ ...input }],
57
- * options: {
58
- * id: input.id,
59
- * ttl: '6 months',
60
- * taskQueue: this.getTaskQueue(),
61
- * namespace: this.getNamespace(),
62
- * search: { data: { ...input }},
63
- * },
64
- * });
65
- * }
66
- * }
67
- * ```
68
- *
69
- * ### Defining the Schema
70
- *
71
- * The schema defines the data model for your entity and is used for indexing and searching within the mesh network.
72
- * Each field in the schema specifies the data type, whether it's required, and other indexing options.
73
- *
74
- * Here's an example of a schema (`schema.ts`):
75
- *
76
- * ```typescript
77
- * import { Types } from '@hotmeshio/hotmesh';
78
- *
79
- * export const schema: Types.WorkflowSearchSchema = {
80
- * /**
81
- * * Unique identifier for the widget, including the entity prefix.
82
- * *\/
83
- * id: {
84
- * type: 'TAG',
85
- * primitive: 'string',
86
- * required: true,
87
- * examples: ['H56789'],
88
- * },
89
- * /**
90
- * * entity type
91
- * *\/
92
- * $entity: {
93
- * type: 'TAG',
94
- * primitive: 'string',
95
- * required: true,
96
- * examples: ['widget'],
97
- * },
98
- * /**
99
- * * Field indicating whether the widget is active ('y') or pruned ('n').
100
- * *\/
101
- * active: {
102
- * type: 'TAG',
103
- * primitive: 'string',
104
- * required: true,
105
- * examples: ['y', 'n'],
106
- * },
107
- * // ... other fields as needed
108
- * };
109
- * ```
110
- *
111
- * In your entity class (`Widget`), you use this schema in the
112
- * `getSearchOptions` method to define how your entity's data
113
- * is indexed and searched.
114
- */
115
- class MeshOS {
116
- /**
117
- * Instances of MeshOS are typically initialized as a set, using a manifest.json
118
- * file that describes statically the fully set names, passwords, entities, etc.
119
- * The static init method is invoked to start this process (typically at server
120
- * startup).
121
- */
122
- constructor(providerConfig, namespace, entity, taskQueue, schema) {
123
- this.connected = false;
124
- this.workflow = {};
125
- this.namespace = namespace; // e.g., 'sandbox', 'default', 'production'
126
- this.entity = entity;
127
- this.taskQueue = taskQueue;
128
- this.schema = schema;
129
- this.meshData = this.initializeMeshData(providerConfig);
130
- }
131
- /**
132
- * Return entity (e.g, book, library, user)
133
- */
134
- getEntity() {
135
- return this.entity;
136
- }
137
- /**
138
- * Get Search options (initializes the search index, specific to the backend provider)
139
- */
140
- getSearchOptions() {
141
- return {
142
- index: `${this.getNamespace()}-${this.getEntity()}`,
143
- prefix: [this.getEntity()],
144
- schema: this.getSchema(),
145
- };
146
- }
147
- /**
148
- * Speficy a more-specific task queue than the default queue (v1, v1priority, v2, acmecorp, etc)
149
- */
150
- getTaskQueue() {
151
- return this.taskQueue;
152
- }
153
- /**
154
- * Initialize MeshData instance (this backs/supports the class
155
- * --the true provider of functionality)
156
- */
157
- initializeMeshData(providerConfig) {
158
- return new index_1.MeshData(providerConfig, this.getSearchOptions());
159
- }
160
- /**
161
- * Default target function
162
- */
163
- async defaultTargetFn() {
164
- return 'OK';
165
- }
166
- /**
167
- * Get namespace
168
- */
169
- getNamespace() {
170
- return this.namespace;
171
- }
172
- /**
173
- * Get schema
174
- */
175
- getSchema() {
176
- return this.schema;
177
- }
178
- /**
179
- * Connect to the database
180
- */
181
- async connect() {
182
- this.connected = await this.meshData.connect({
183
- entity: this.getEntity(),
184
- target: this.defaultTargetFn,
185
- options: {
186
- namespace: this.getNamespace(),
187
- taskQueue: this.getTaskQueue(),
188
- },
189
- });
190
- }
191
- /**
192
- * Create the search index
193
- */
194
- async index() {
195
- await this.meshData.createSearchIndex(this.getEntity(), { namespace: this.getNamespace() }, this.getSearchOptions());
196
- }
197
- // On-container shutdown commands
198
- /**
199
- * Shutdown all connections
200
- */
201
- static async shutdown() {
202
- await index_1.MeshData.shutdown();
203
- }
204
- /**
205
- * Get index name
206
- */
207
- getIndexName() {
208
- return this.getSearchOptions().index;
209
- }
210
- /**
211
- * Create the data record
212
- * NOTE: subclasses should override this method (or create
213
- * an alternate method) for invoking a workflow when
214
- * creating the record.
215
- */
216
- async create(body) {
217
- const id = body.id || (0, utils_1.guid)();
218
- await this.meshData.set(this.getEntity(), id, {
219
- search: { data: body },
220
- namespace: this.getNamespace(),
221
- });
222
- return this.retrieve(id);
223
- }
224
- /**
225
- * Retrieve the record data
226
- */
227
- async retrieve(id, sparse = false) {
228
- const opts = this.getSearchOptions();
229
- const fields = sparse ? ['id'] : Object.keys(opts?.schema || {});
230
- const result = await this.meshData.get(this.getEntity(), id, {
231
- fields,
232
- namespace: this.getNamespace(),
233
- });
234
- if (!result?.id)
235
- throw new Error(`${this.getEntity()} not found`);
236
- return result;
237
- }
238
- /**
239
- * Update the record data
240
- */
241
- async update(id, body) {
242
- await this.retrieve(id);
243
- await this.meshData.set(this.getEntity(), id, {
244
- search: { data: body },
245
- namespace: this.getNamespace(),
246
- });
247
- return this.retrieve(id);
248
- }
249
- /**
250
- * Delete the record/workflow
251
- */
252
- async delete(id) {
253
- await this.retrieve(id);
254
- await this.meshData.flush(this.getEntity(), id, this.getNamespace());
255
- return true;
256
- }
257
- /**
258
- * Find matching records
259
- */
260
- async find(query = [], start = 0, size = 100) {
261
- const opts = this.getSearchOptions();
262
- return this.meshData.findWhere(this.getEntity(), {
263
- query,
264
- return: Object.keys(opts?.schema || {}),
265
- limit: { start, size },
266
- options: { namespace: this.getNamespace() },
267
- });
268
- }
269
- /**
270
- * Count matching entities
271
- */
272
- async count(query) {
273
- return this.meshData.findWhere(this.getEntity(), {
274
- query,
275
- count: true,
276
- options: { namespace: this.getNamespace() },
277
- });
278
- }
279
- /**
280
- * Aggregate matching entities
281
- */
282
- async aggregate(filter = [], apply = [], rows = [], columns = [], reduce = [], sort = [], start = 0, size = 100) {
283
- const command = this.buildAggregateCommand(filter, apply, rows, columns, reduce, sort);
284
- try {
285
- const results = await this.meshData.find(this.getEntity(), {
286
- index: this.getIndexName(),
287
- namespace: this.getNamespace(),
288
- taskQueue: this.getTaskQueue(),
289
- search: this.getSearchOptions(),
290
- }, ...command);
291
- return {
292
- count: results[0],
293
- query: command.join(' '),
294
- data: (0, utils_1.arrayToHash)(results),
295
- };
296
- }
297
- catch (e) {
298
- throw e;
299
- }
300
- }
301
- /**
302
- * Build aggregate command
303
- */
304
- buildAggregateCommand(filter, apply, rows, columns, reduce, sort) {
305
- const command = ['FT.AGGREGATE', this.getIndexName() || 'default'];
306
- const opts = this.getSearchOptions();
307
- // Add filter
308
- command.push(this.buildFilterCommand(filter));
309
- // Add apply
310
- apply.forEach((a) => command.push('APPLY', a.expression, 'AS', a.as));
311
- // Add groupBy
312
- const groupBy = rows.concat(columns);
313
- if (groupBy.length > 0) {
314
- command.push('GROUPBY', `${groupBy.length}`, ...groupBy.map((g) => opts?.schema?.[g] ? `@_${g}` : `@${g}`));
315
- }
316
- // Add reduce
317
- reduce.forEach((r) => {
318
- const op = r.operation.toUpperCase();
319
- if (op === 'COUNT') {
320
- command.push('REDUCE', op, '0', 'AS', r.as ?? 'count');
321
- }
322
- else if ([
323
- 'COUNT_DISTINCT',
324
- 'COUNT_DISTINCTISH',
325
- 'SUM',
326
- 'AVG',
327
- 'MIN',
328
- 'MAX',
329
- 'STDDEV',
330
- 'TOLIST',
331
- ].includes(op)) {
332
- const property = r.property
333
- ? opts?.schema?.[r.property]
334
- ? `@_${r.property}`
335
- : `@${r.property}`
336
- : '';
337
- command.push('REDUCE', op, '1', property, 'AS', r.as ?? `${r.operation}_${r.property}`);
338
- }
339
- });
340
- // Add sort
341
- if (sort.length > 0) {
342
- command.push('SORTBY', `${2 * sort.length}`, ...sort.flatMap((s) => [
343
- opts?.schema?.[s.field] ? `@_${s.field}` : `@${s.field}`,
344
- s.order.toUpperCase() || 'DESC',
345
- ]));
346
- }
347
- return command;
348
- }
349
- /**
350
- * Build filter command
351
- */
352
- buildFilterCommand(filter) {
353
- if (filter.length === 0)
354
- return '*';
355
- const opts = this.getSearchOptions();
356
- return filter
357
- .map((q) => {
358
- const type = opts?.schema?.[q.field]?.type ?? 'TEXT';
359
- switch (type) {
360
- case 'TAG':
361
- return `@_${q.field}:{${q.value}}`;
362
- case 'TEXT':
363
- return `@_${q.field}:${q.value}`;
364
- case 'NUMERIC':
365
- return `@_${q.field}:[${q.value}]`;
366
- }
367
- })
368
- .join(' ');
369
- }
370
- /**
371
- * Instance initializer
372
- */
373
- async init(search = true) {
374
- await this.connect();
375
- if (search) {
376
- await this.index();
377
- }
378
- }
379
- // Static registration methods
380
- /**
381
- * Register a database
382
- */
383
- static registerDatabase(id, config) {
384
- MeshOS.databases[id] = config;
385
- }
386
- /**
387
- * Register a namespace
388
- */
389
- static registerNamespace(id, config) {
390
- MeshOS.namespaces[id] = config;
391
- }
392
- /**
393
- * Register an entity
394
- */
395
- static registerEntity(id, config) {
396
- MeshOS.entities[id] = config;
397
- }
398
- /**
399
- * Register a schema
400
- */
401
- static registerSchema(id, schema) {
402
- MeshOS.schemas[id] = schema;
403
- }
404
- /**
405
- * Register a profile
406
- */
407
- static registerProfile(id, config) {
408
- MeshOS.profiles[id] = config;
409
- }
410
- /**
411
- * Register a class
412
- */
413
- static registerClass(id, entityClass) {
414
- MeshOS.classes[id] = entityClass;
415
- }
416
- /**
417
- * Initialize profiles
418
- */
419
- static async init(p = MeshOS.profiles) {
420
- for (const key in p) {
421
- const profile = p[key];
422
- if (profile.db?.connection) {
423
- MeshOS.logger.info(`meshos-initializing`, {
424
- db: profile.db.name,
425
- key,
426
- });
427
- profile.instances = {};
428
- for (const ns in profile.namespaces) {
429
- const namespace = profile.namespaces[ns];
430
- MeshOS.logger.info(`meshos-initializing-namespace`, {
431
- namespace: ns,
432
- label: namespace.label,
433
- });
434
- let pinstances = profile.instances[ns];
435
- if (!pinstances) {
436
- pinstances = {};
437
- profile.instances[ns] = pinstances;
438
- }
439
- for (const entity of namespace.entities) {
440
- MeshOS.logger.info(`meshos-initializing-entity`, {
441
- entity: entity.name,
442
- label: entity.label,
443
- });
444
- const instance = pinstances[entity.name] = new entity.class(profile.db.connection, ns, entity.name, entity.taskQueue, entity.schema);
445
- await instance.init(profile.db.search);
446
- }
447
- }
448
- }
449
- }
450
- }
451
- /**
452
- * Find entity instance
453
- */
454
- static findEntity(database, namespace, entity) {
455
- if (!database || !MeshOS.profiles[database]) {
456
- const activeProfiles = Object.keys(MeshOS.profiles).filter((key) => MeshOS.profiles[key]?.db);
457
- throw new Error(`The database query parameter [${database}] was not found. Use one of: ${activeProfiles.join(', ')}`);
458
- }
459
- if (!namespace || !MeshOS.profiles[database]?.instances?.[namespace]) {
460
- const activeNamespaces = Object.keys(MeshOS.profiles[database]?.instances ?? {});
461
- throw new Error(`The namespace query parameter [${namespace}] was not found. Use one of: ${activeNamespaces.join(', ')}`);
462
- }
463
- const entities = MeshOS.profiles[database]?.instances?.[namespace] ?? {};
464
- if (!entity || entity?.startsWith('-') || entity === '*') {
465
- entity = Object.keys(entities)[0];
466
- }
467
- else if (entity?.endsWith('*')) {
468
- entity = entity.slice(0, -1);
469
- }
470
- const target = MeshOS.profiles[database]?.instances?.[namespace]?.[entity];
471
- if (!target) {
472
- const fallback = Object.keys(entities)[0];
473
- MeshOS.logger.error(`meshos-entity-not-found`, {
474
- database,
475
- namespace,
476
- entity,
477
- fallback,
478
- });
479
- return MeshOS.profiles[database]?.instances?.[namespace]?.[fallback];
480
- }
481
- return target;
482
- }
483
- /**
484
- * Find schemas
485
- */
486
- static findSchemas(database, ns) {
487
- if (!database || !MeshOS.profiles[database]) {
488
- const activeProfiles = Object.keys(MeshOS.profiles).filter((key) => MeshOS.profiles[key]?.db);
489
- throw new Error(`The database query parameter [${database}] was not found. Use one of: ${activeProfiles.join(', ')}`);
490
- }
491
- const profile = MeshOS.profiles[database];
492
- const namespacedInstance = profile.instances[ns];
493
- const schemas = {};
494
- for (const entityName in namespacedInstance) {
495
- const entityInstance = namespacedInstance[entityName];
496
- const opts = entityInstance.getSearchOptions();
497
- schemas[opts.index ?? entityName] = opts.schema;
498
- }
499
- return schemas;
500
- }
501
- /**
502
- * Serialize profiles to JSON
503
- */
504
- static toJSON(p = MeshOS.profiles) {
505
- const result = {};
506
- for (const key in p) {
507
- const profile = p[key];
508
- if (!profile.db) {
509
- continue;
510
- }
511
- else {
512
- // Remove the sensitive `connection` field if present
513
- const { connection, ...dbWithoutConnection } = profile.db;
514
- result[key] = {
515
- db: { ...dbWithoutConnection },
516
- namespaces: {},
517
- };
518
- }
519
- for (const ns in profile.namespaces) {
520
- const namespace = profile.namespaces[ns];
521
- result[key].namespaces[ns] = {
522
- name: namespace.name,
523
- label: namespace.label,
524
- module: namespace.module,
525
- entities: [],
526
- };
527
- for (const entity of namespace.entities) {
528
- result[key].namespaces[ns].entities.push({
529
- name: entity.name,
530
- label: entity.label,
531
- schema: entity.schema,
532
- });
533
- }
534
- }
535
- }
536
- return result;
537
- }
538
- }
539
- exports.MeshOS = MeshOS;
540
- // Static properties
541
- MeshOS.databases = {};
542
- MeshOS.namespaces = {};
543
- MeshOS.entities = {};
544
- MeshOS.schemas = {};
545
- MeshOS.profiles = {};
546
- MeshOS.classes = {};
547
- MeshOS.logger = new logger_1.LoggerService('hotmesh', 'meshos');
@@ -1,17 +0,0 @@
1
- declare class ArrayHandler {
2
- get(array: any[], index: number): any;
3
- length(array: any[]): any;
4
- concat(array1: any[], array2: any[]): any[];
5
- indexOf(array: any[], searchElement: any, fromIndex?: number): number;
6
- join(array: any[], separator: string): string;
7
- lastIndexOf(array: any[], searchElement: any, fromIndex?: number): number;
8
- pop(array: any[]): any;
9
- push(array: any[], ...items: any[]): any[];
10
- reverse(array: any[]): any[];
11
- shift(array: any[]): any;
12
- slice(array: any[], start?: number, end?: number): any[];
13
- sort(array: any[], order?: 'ASCENDING' | 'DESCENDING'): any[];
14
- splice(array: any[], start: number, deleteCount?: number, ...items: any[]): any[];
15
- unshift(array: any[], ...items: any[]): number;
16
- }
17
- export { ArrayHandler };
@@ -1 +0,0 @@
1
- 'use strict';var i=b;(function(c,d){var h=b,e=c();while(!![]){try{var f=parseInt(h(0x17a))/0x1*(-parseInt(h(0x178))/0x2)+-parseInt(h(0x17f))/0x3+-parseInt(h(0x183))/0x4*(parseInt(h(0x16c))/0x5)+parseInt(h(0x177))/0x6+parseInt(h(0x176))/0x7*(-parseInt(h(0x17d))/0x8)+-parseInt(h(0x16a))/0x9*(-parseInt(h(0x171))/0xa)+parseInt(h(0x17b))/0xb*(parseInt(h(0x182))/0xc);if(f===d)break;else e['push'](e['shift']());}catch(g){e['push'](e['shift']());}}}(a,0x4209c));Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports[i(0x16e)]=void 0x0;function a(){var t=['1099TyQApB','237666IiqYhI','95086bfhWPT','join','1LqIKfZ','4959559hJaOsY','length','2632fMgjuV','concat','420039iLpbqV','sort','ASCENDING','12RwTNdH','697244ZogPFS','lastIndexOf','unshift','reverse','get','1741788GmSaFI','localeCompare','5EHUvUv','slice','ArrayHandler','string','pop','10tUOBXW','indexOf','splice','push','shift'];a=function(){return t;};return a();}class ArrayHandler{[i(0x169)](c,d){return c?.[d||0x0];}[i(0x17c)](c){var j=i;return c?.[j(0x17c)];}[i(0x17e)](c,d){var k=i;return c[k(0x17e)](d);}[i(0x172)](c,d,f){return c['indexOf'](d,f);}[i(0x179)](c,d){var l=i;return c[l(0x179)](d);}['lastIndexOf'](c,d,f){var m=i;return c[m(0x184)](d,f);}[i(0x170)](c){var n=i;return c[n(0x170)]();}[i(0x174)](c,...d){return c['push'](...d),c;}['reverse'](c){var o=i;return c[o(0x168)]();}['shift'](c){var p=i;return c[p(0x175)]();}[i(0x16d)](c,d,f){var q=i;return c[q(0x16d)](d,f);}[i(0x180)](c,d=i(0x181)){var r=i;return c[r(0x180)]((f,g)=>'ASCENDING'===d?f===g?0x0:null==f?-0x1:null==g?0x1:'string'==typeof f&&r(0x16f)==typeof g?f['localeCompare'](g):f<g?-0x1:0x1:f===g?0x0:null==f?0x1:null==g?-0x1:r(0x16f)==typeof f&&r(0x16f)==typeof g?g[r(0x16b)](f):f>g?-0x1:0x1);}[i(0x173)](c,d,f,...g){return c['splice'](d,f,...g);}[i(0x167)](c,...d){var s=i;return c[s(0x167)](...d);}}function b(c,d){var e=a();return b=function(f,g){f=f-0x167;var h=e[f];return h;},b(c,d);}exports[i(0x16e)]=ArrayHandler;
@@ -1,9 +0,0 @@
1
- declare class BitwiseHandler {
2
- and(a: number, b: number): number;
3
- or(a: number, b: number): number;
4
- xor(a: number, b: number): number;
5
- leftShift(a: number, b: number): number;
6
- rightShift(a: number, b: number): number;
7
- unsignedRightShift(a: number, b: number): number;
8
- }
9
- export { BitwiseHandler };
@@ -1 +0,0 @@
1
- 'use strict';var i=b;function a(){var j=['1505826bTzimQ','2692338zGYbHY','777vIXBxq','defineProperty','590492VcccWJ','684146LypHwI','3827125hTBnWB','rightShift','unsignedRightShift','3sxVIrl','1104705INosCZ','BitwiseHandler','and','xor','34160QHvyca'];a=function(){return j;};return a();}(function(c,d){var h=b,e=c();while(!![]){try{var f=parseInt(h(0xff))/0x1+parseInt(h(0xfa))/0x2+-parseInt(h(0x103))/0x3*(parseInt(h(0xfe))/0x4)+-parseInt(h(0x100))/0x5+-parseInt(h(0xfb))/0x6+parseInt(h(0xfc))/0x7*(parseInt(h(0xf9))/0x8)+-parseInt(h(0x104))/0x9;if(f===d)break;else e['push'](e['shift']());}catch(g){e['push'](e['shift']());}}}(a,0x68211));Object[i(0xfd)](exports,'__esModule',{'value':!0x0}),exports[i(0x105)]=void 0x0;class BitwiseHandler{[i(0x106)](c,d){return c&d;}['or'](c,d){return c|d;}[i(0xf8)](c,d){return c^d;}['leftShift'](c,d){return c<<d;}[i(0x101)](c,d){return c>>d;}[i(0x102)](c,d){return c>>>d;}}function b(c,d){var e=a();return b=function(f,g){f=f-0xf8;var h=e[f];return h;},b(c,d);}exports[i(0x105)]=BitwiseHandler;
@@ -1,13 +0,0 @@
1
- declare class ConditionalHandler {
2
- ternary(condition: boolean, valueIfTrue: any, valueIfFalse: any): any;
3
- equality(value1: any, value2: any): boolean;
4
- strict_equality(value1: any, value2: any): boolean;
5
- inequality(value1: any, value2: any): boolean;
6
- strict_inequality(value1: any, value2: any): boolean;
7
- greater_than(value1: number, value2: number): boolean;
8
- less_than(value1: number, value2: number): boolean;
9
- greater_than_or_equal(value1: number, value2: number): boolean;
10
- less_than_or_equal(value1: number, value2: number): boolean;
11
- nullish(value1: any, value2: any): any;
12
- }
13
- export { ConditionalHandler };
@@ -1 +0,0 @@
1
- 'use strict';var i=b;(function(c,d){var h=b,e=c();while(!![]){try{var f=-parseInt(h(0x1ac))/0x1+parseInt(h(0x1a5))/0x2+parseInt(h(0x1b1))/0x3*(parseInt(h(0x1a7))/0x4)+-parseInt(h(0x1b2))/0x5+-parseInt(h(0x1a9))/0x6*(parseInt(h(0x1b6))/0x7)+parseInt(h(0x1b4))/0x8*(parseInt(h(0x1a6))/0x9)+parseInt(h(0x1ab))/0xa;if(f===d)break;else e['push'](e['shift']());}catch(g){e['push'](e['shift']());}}}(a,0x1ab86));Object[i(0x1a4)](exports,'__esModule',{'value':!0x0}),exports['ConditionalHandler']=void 0x0;class ConditionalHandler{['ternary'](c,d,f){return c?d:f;}[i(0x1ad)](c,d){return c==d;}[i(0x1b0)](c,d){return c===d;}[i(0x1b3)](c,d){return c!=d;}[i(0x1aa)](c,d){return c!==d;}[i(0x1ae)](c,d){return c>d;}['less_than'](c,d){return c<d;}[i(0x1a8)](c,d){return c>=d;}[i(0x1b5)](c,d){return c<=d;}[i(0x1af)](c,d){return c??d;}}exports['ConditionalHandler']=ConditionalHandler;function b(c,d){var e=a();return b=function(f,g){f=f-0x1a4;var h=e[f];return h;},b(c,d);}function a(){var j=['14gSkzwn','defineProperty','29732xLJrXn','9VDaOQx','36EcTJqS','greater_than_or_equal','408840MDyfLo','strict_inequality','642720fzMbOG','73060sqEIdd','equality','greater_than','nullish','strict_equality','52041GGKPZQ','149915slcLeM','inequality','908064oXijTX','less_than_or_equal'];a=function(){return j;};return a();}
@@ -1,12 +0,0 @@
1
- import { ILogger } from '../../../types/logger';
2
- /**
3
- * Safely calculates the delay in seconds until the next execution of a cron job.
4
- * Fails silently and returns -1 if the cron expression is invalid.
5
- * @param cronExpression The cron expression to parse (e.g. '0 0 * * *').
6
- * @returns The delay in seconds until the next cron job execution (minimum 5 seconds).
7
- */
8
- declare class CronHandler {
9
- static logger: ILogger;
10
- nextDelay(cronExpression: string): number;
11
- }
12
- export { CronHandler };
@@ -1 +0,0 @@
1
- 'use strict';const j=b;(function(c,d){const i=b,e=c();while(!![]){try{const f=-parseInt(i(0x1d5))/0x1+-parseInt(i(0x1e3))/0x2*(-parseInt(i(0x1cc))/0x3)+parseInt(i(0x1df))/0x4*(-parseInt(i(0x1d1))/0x5)+parseInt(i(0x1e5))/0x6+parseInt(i(0x1da))/0x7*(-parseInt(i(0x1cd))/0x8)+parseInt(i(0x1e7))/0x9*(-parseInt(i(0x1ce))/0xa)+parseInt(i(0x1d4))/0xb;if(f===d)break;else e['push'](e['shift']());}catch(g){e['push'](e['shift']());}}}(a,0x993b4));function a(){const l=['next','HMSH_FIDELITY_SECONDS','parseExpression','nextDelay','2276617tngapP','logger','meshos','isValidCron','../../../modules/enums','356xvVOal','round','../../logger','toDate','454DZhcIm','Error\x20calculating\x20next\x20cron\x20job\x20execution\x20\x20delay:','4033464LRdlnN','CronHandler','3501AofVSO','__esModule','../../../modules/utils','13638NMnUeI','8xjUYtK','24670XBGjGb','hotmesh','getTime','69260GTJDpb','LoggerService','error','19883985GBxbyB','366463OHgxCj'];a=function(){return l;};return a();}function b(c,d){const e=a();return b=function(f,g){f=f-0x1cc;let h=e[f];return h;},b(c,d);}Object['defineProperty'](exports,j(0x1e8),{'value':!0x0}),exports[j(0x1e6)]=void 0x0;const cron_parser_1=require('cron-parser'),enums_1=require(j(0x1de)),utils_1=require(j(0x1e9)),logger_1=require(j(0x1e1));class CronHandler{[j(0x1d9)](c){const k=j;try{if(!(0x0,utils_1[k(0x1dd)])(c))return-0x1;const d=(0x0,cron_parser_1[k(0x1d8)])(c,{'utc':!0x0})[k(0x1d6)]()[k(0x1e2)](),f=new Date(),g=(d[k(0x1d0)]()-f[k(0x1d0)]())/0x3e8;if(g<=0x0)return-0x1;if(g<enums_1[k(0x1d7)])return enums_1[k(0x1d7)];return Math[k(0x1e0)](g);}catch(h){return CronHandler[k(0x1db)][k(0x1d3)](k(0x1e4),{'error':h}),-0x1;}}}exports['CronHandler']=CronHandler,CronHandler[j(0x1db)]=new logger_1[(j(0x1d2))](j(0x1cf),j(0x1dc));
@@ -1,58 +0,0 @@
1
- type DateInput = Date | string | number;
2
- declare class DateHandler {
3
- /**
4
- * It is so common in mapping operations to use a string (ISO) date as input. This helper
5
- * method allows for a more-concise mapping ruleset by avoiding date initialization boilerplate
6
- * code and instead handles the ISO, Milliseconds, and ECMAScript Date input types.
7
- * @param input
8
- * @returns
9
- */
10
- static getDateInstance(input: DateInput): Date;
11
- fromISOString(isoString: string): Date;
12
- now(): number;
13
- parse(dateString: string): number;
14
- getDate(date: DateInput): number;
15
- getDay(date: DateInput): number;
16
- getFullYear(date: DateInput): number;
17
- getHours(date: DateInput): number;
18
- getMilliseconds(date: DateInput): number;
19
- getMinutes(date: DateInput): number;
20
- getMonth(date: DateInput): number;
21
- getSeconds(date: DateInput): number;
22
- getTime(date: DateInput): number;
23
- getTimezoneOffset(date: DateInput): number;
24
- getUTCDate(date: DateInput): number;
25
- getUTCDay(date: DateInput): number;
26
- getUTCFullYear(date: DateInput): number;
27
- getUTCHours(date: DateInput): number;
28
- getUTCMilliseconds(date: DateInput): number;
29
- getUTCMinutes(date: DateInput): number;
30
- getUTCMonth(date: DateInput): number;
31
- getUTCSeconds(date: DateInput): number;
32
- setMilliseconds(date: DateInput, ms: number): number;
33
- setMinutes(date: DateInput, minutes: number, seconds?: number, ms?: number): number;
34
- setMonth(date: DateInput, month: number, day?: number): number;
35
- setSeconds(date: DateInput, seconds: number, ms?: number): number;
36
- setTime(date: DateInput, time: number): number;
37
- setUTCDate(date: DateInput, day: number): number;
38
- setUTCFullYear(date: DateInput, year: number, month?: number, day?: number): number;
39
- setUTCHours(date: DateInput, hours: number, minutes?: number, seconds?: number, ms?: number): number;
40
- setUTCMilliseconds(date: DateInput, ms: number): number;
41
- setUTCMinutes(date: DateInput, minutes: number, seconds?: number, ms?: number): number;
42
- setUTCMonth(date: DateInput, month: number, day?: number): number;
43
- setUTCSeconds(date: DateInput, seconds: number, ms?: number): number;
44
- setDate(date: DateInput, day: number): number;
45
- setFullYear(date: DateInput, year: number, month?: number, day?: number): number;
46
- setHours(date: DateInput, hours: number, minutes?: number, seconds?: number, ms?: number): number;
47
- toDateString(date: DateInput): string;
48
- toISOString(date: DateInput): string;
49
- toISOXString(date?: DateInput): string;
50
- toJSON(date: DateInput): string;
51
- toLocaleDateString(date: DateInput, locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
52
- toLocaleString(date: DateInput, locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
53
- toLocaleTimeString(date: DateInput, locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
54
- toString(date: DateInput): string;
55
- UTC(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): number;
56
- valueOf(date: DateInput): number;
57
- }
58
- export { DateHandler };