@hotmeshio/hotmesh 0.1.16 → 0.2.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.
- package/README.md +12 -12
- package/build/index.d.ts +1 -10
- package/build/index.js +2 -11
- package/build/package.json +1 -1
- package/build/services/meshcall/index.js +7 -4
- package/build/services/meshcall/schemas/factory.js +0 -4
- package/build/types/meshcall.d.ts +9 -5
- package/index.ts +1 -11
- package/package.json +1 -1
- package/types/meshcall.ts +79 -10
package/README.md
CHANGED
|
@@ -12,8 +12,8 @@ You have a Redis instance? Good. You're ready to go.
|
|
|
12
12
|
## SDK Docs
|
|
13
13
|
[Read the Docs](https://hotmeshio.github.io/sdk-typescript/)
|
|
14
14
|
|
|
15
|
-
## MeshCall
|
|
16
|
-
The **MeshCall** module connects
|
|
15
|
+
## MeshCall | Connect Everything
|
|
16
|
+
The **MeshCall** module connects any function with a connection to Redis. Function responses are cacheable and functions can even run as cyclical cron jobs. Make blazing fast interservice calls that return in milliseconds without the overhead of HTTP.
|
|
17
17
|
|
|
18
18
|
<details style="padding: .5em">
|
|
19
19
|
<summary style="font-size:1.25em;">Run an idempotent cron job</summary>
|
|
@@ -21,7 +21,7 @@ The **MeshCall** module connects and exposes your functions as idempotent endpoi
|
|
|
21
21
|
### Run a Cron
|
|
22
22
|
This example demonstrates an *idempotent* cron that runs every day. The `id` makes each cron job unique and ensures that only one instance runs, despite repeated invocations. *The `cron` method fails silently if a workflow is already running with the same `id`.*
|
|
23
23
|
|
|
24
|
-
Optionally set `
|
|
24
|
+
Optionally set a `delay` and/or set `maxCycles` to limit the number of cycles.
|
|
25
25
|
|
|
26
26
|
1. Define the cron function.
|
|
27
27
|
```typescript
|
|
@@ -39,7 +39,7 @@ The **MeshCall** module connects and exposes your functions as idempotent endpoi
|
|
|
39
39
|
callback: async () => {
|
|
40
40
|
//your code here...
|
|
41
41
|
},
|
|
42
|
-
options: { id, interval }
|
|
42
|
+
options: { id, interval, maxCycles: 24 }
|
|
43
43
|
});
|
|
44
44
|
};
|
|
45
45
|
```
|
|
@@ -78,7 +78,7 @@ The **MeshCall** module connects and exposes your functions as idempotent endpoi
|
|
|
78
78
|
<summary style="font-size:1.25em;">Call any function in any service</summary>
|
|
79
79
|
|
|
80
80
|
### Call a Function
|
|
81
|
-
Make blazing fast interservice calls that
|
|
81
|
+
Make blazing fast interservice calls that behave like HTTP but without the setup and performance overhead. This example demonstrates how to connect a function to the mesh and call it from anywhere on the network.
|
|
82
82
|
|
|
83
83
|
1. Call `MeshCall.connect` and provide a `topic` to uniquely identify the function.
|
|
84
84
|
|
|
@@ -167,7 +167,7 @@ The **MeshCall** module connects and exposes your functions as idempotent endpoi
|
|
|
167
167
|
```
|
|
168
168
|
</details>
|
|
169
169
|
|
|
170
|
-
## MeshFlow
|
|
170
|
+
## MeshFlow | Transactional Workflow
|
|
171
171
|
The **MeshFlow** module is a drop-in replacement for [Temporal.io](https://temporal.io). If you need to orchestrate your functions as durable workflows, MeshFlow combines the popular Temporal SDK with Redis' *in-memory execution speed*.
|
|
172
172
|
|
|
173
173
|
<details style="padding: .5em">
|
|
@@ -502,17 +502,17 @@ This example calls an activity and then sleeps for a week. It runs indefinitely
|
|
|
502
502
|
```
|
|
503
503
|
</details>
|
|
504
504
|
|
|
505
|
-
## MeshData
|
|
505
|
+
## MeshData | Transactional Analytics
|
|
506
506
|
The **MeshData** service extends the **MeshFlow** service, combining data record concepts and transactional workflow principles into a single *Operational Data Layer*.
|
|
507
507
|
|
|
508
508
|
Deployments with the Redis `FT.SEARCH` module enabled can use the **MeshData** module to merge [OLTP](https://en.wikipedia.org/wiki/Online_transaction_processing) and [OLAP](https://en.wikipedia.org/wiki/Online_analytical_processing) operations into a hybrid transactional/analytics ([HTAP](https://en.wikipedia.org/wiki/Hybrid_transactional/analytical_processing)) system.
|
|
509
509
|
|
|
510
|
-
|
|
510
|
+
*For those Redis deployments without the `FT.SEARCH` module, it's still useful to define a workflow schema. The MeshData class provides convenience methods for reading and writing hash field data to a workflow record (e.g., `get`, `del`, and `incr`).*
|
|
511
511
|
|
|
512
512
|
<details style="padding: .5em">
|
|
513
513
|
<summary style="font-size:1.25em;">Create a search index</summary>
|
|
514
514
|
|
|
515
|
-
###
|
|
515
|
+
### Workflow Data Indexes
|
|
516
516
|
|
|
517
517
|
This example demonstrates how to define a schema and deploy an index for a 'user' entity type.
|
|
518
518
|
|
|
@@ -552,7 +552,7 @@ This example demonstrates how to define a schema and deploy an index for a 'user
|
|
|
552
552
|
<details style="padding: .5em">
|
|
553
553
|
<summary style="font-size:1.25em;">Create an indexed, searchable record</summary>
|
|
554
554
|
|
|
555
|
-
###
|
|
555
|
+
### Workflow Record Data
|
|
556
556
|
This example demonstrates how to create a 'user' workflow backed by the searchable schema from the prior example.
|
|
557
557
|
|
|
558
558
|
1. Call MeshData `connect` to initialize a 'user' entity *worker*. It references a target worker function which will run the workflow. Data fields that are documented in the schema (like `active`) will be automatically indexed when set on the workflow record.
|
|
@@ -632,7 +632,7 @@ This example demonstrates how to create a 'user' workflow backed by the searchab
|
|
|
632
632
|
<details style="padding: .5em">
|
|
633
633
|
<summary style="font-size:1.25em;">Fetch record data</summary>
|
|
634
634
|
|
|
635
|
-
###
|
|
635
|
+
### Read Record Data
|
|
636
636
|
This example demonstrates how to read data fields directly from a workflow.
|
|
637
637
|
|
|
638
638
|
1. Read data fields directly from the *jimbo123* 'user' record.
|
|
@@ -663,7 +663,7 @@ This example demonstrates how to read data fields directly from a workflow.
|
|
|
663
663
|
<details style="padding: .5em">
|
|
664
664
|
<summary style="font-size:1.25em;">Search record data</summary>
|
|
665
665
|
|
|
666
|
-
###
|
|
666
|
+
### Query Record Data
|
|
667
667
|
This example demonstrates how to search for those workflows where a given condition exists in the data. This one searches for active users. *NOTE: The native Redis FT.SEARCH syntax is supported. The JSON abstraction shown here is a convenience method for straight-forward, one-dimensional queries.*
|
|
668
668
|
|
|
669
669
|
1. Search for active users (where the value of the `active` field is `yes`).
|
package/build/index.d.ts
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
import { MeshCall } from './services/meshcall';
|
|
2
2
|
import { MeshData } from './services/meshdata';
|
|
3
|
+
import { MeshFlow } from './services/meshflow';
|
|
3
4
|
import { HotMesh } from './services/hotmesh';
|
|
4
|
-
import { ClientService } from './services/meshflow/client';
|
|
5
|
-
import { WorkerService } from './services/meshflow/worker';
|
|
6
|
-
import { WorkflowService } from './services/meshflow/workflow';
|
|
7
|
-
import { ConnectionService } from './services/meshflow/connection';
|
|
8
5
|
import { HotMeshConfig } from './types/hotmesh';
|
|
9
|
-
declare const MeshFlow: {
|
|
10
|
-
Client: typeof ClientService;
|
|
11
|
-
Worker: typeof WorkerService;
|
|
12
|
-
workflow: typeof WorkflowService;
|
|
13
|
-
Connection: typeof ConnectionService;
|
|
14
|
-
};
|
|
15
6
|
export { HotMesh, MeshCall, MeshData, MeshFlow, HotMeshConfig, };
|
|
16
7
|
export * as Types from './types';
|
package/build/index.js
CHANGED
|
@@ -28,17 +28,8 @@ const meshcall_1 = require("./services/meshcall");
|
|
|
28
28
|
Object.defineProperty(exports, "MeshCall", { enumerable: true, get: function () { return meshcall_1.MeshCall; } });
|
|
29
29
|
const meshdata_1 = require("./services/meshdata");
|
|
30
30
|
Object.defineProperty(exports, "MeshData", { enumerable: true, get: function () { return meshdata_1.MeshData; } });
|
|
31
|
+
const meshflow_1 = require("./services/meshflow");
|
|
32
|
+
Object.defineProperty(exports, "MeshFlow", { enumerable: true, get: function () { return meshflow_1.MeshFlow; } });
|
|
31
33
|
const hotmesh_1 = require("./services/hotmesh");
|
|
32
34
|
Object.defineProperty(exports, "HotMesh", { enumerable: true, get: function () { return hotmesh_1.HotMesh; } });
|
|
33
|
-
const client_1 = require("./services/meshflow/client");
|
|
34
|
-
const worker_1 = require("./services/meshflow/worker");
|
|
35
|
-
const workflow_1 = require("./services/meshflow/workflow");
|
|
36
|
-
const connection_1 = require("./services/meshflow/connection");
|
|
37
|
-
const MeshFlow = {
|
|
38
|
-
Client: client_1.ClientService,
|
|
39
|
-
Worker: worker_1.WorkerService,
|
|
40
|
-
workflow: workflow_1.WorkflowService,
|
|
41
|
-
Connection: connection_1.ConnectionService,
|
|
42
|
-
};
|
|
43
|
-
exports.MeshFlow = MeshFlow;
|
|
44
35
|
exports.Types = __importStar(require("./types"));
|
package/build/package.json
CHANGED
|
@@ -127,7 +127,7 @@ class MeshCall {
|
|
|
127
127
|
}
|
|
128
128
|
static async flush(params) {
|
|
129
129
|
const hotMeshInstance = await MeshCall.getInstance(params.namespace, params.redis);
|
|
130
|
-
await hotMeshInstance.scrub(params.id);
|
|
130
|
+
await hotMeshInstance.scrub(params.id ?? params?.options?.id);
|
|
131
131
|
}
|
|
132
132
|
static async cron(params) {
|
|
133
133
|
try {
|
|
@@ -140,14 +140,17 @@ class MeshCall {
|
|
|
140
140
|
namespace: params.namespace,
|
|
141
141
|
});
|
|
142
142
|
const TOPIC = `${params.namespace ?? key_1.HMNS}.cron`;
|
|
143
|
+
const interval = (0, ms_1.default)(params.options.interval) / 1000;
|
|
144
|
+
const delay = params.options.delay ? (0, ms_1.default)(params.options.delay) / 1000 : undefined;
|
|
145
|
+
const maxCycles = params.options.maxCycles ?? 1000000;
|
|
143
146
|
const hotMeshInstance = await MeshCall.getInstance(params.namespace, params.redis);
|
|
144
147
|
await hotMeshInstance.pub(TOPIC, {
|
|
145
148
|
id: params.options.id,
|
|
146
149
|
topic: params.topic,
|
|
147
150
|
args: params.args,
|
|
148
|
-
interval
|
|
149
|
-
maxCycles
|
|
150
|
-
|
|
151
|
+
interval,
|
|
152
|
+
maxCycles,
|
|
153
|
+
delay,
|
|
151
154
|
});
|
|
152
155
|
return true;
|
|
153
156
|
}
|
|
@@ -98,10 +98,6 @@ const getWorkflowYAML = (appId = key_1.HMNS, version = exports.VERSION) => {
|
|
|
98
98
|
maxCycles:
|
|
99
99
|
type: number
|
|
100
100
|
description: maximum number of cycles to run before stopping
|
|
101
|
-
maxDuration:
|
|
102
|
-
type: integer
|
|
103
|
-
description: timevalue (GMT) ceiling. If the current time exceeds this value, the cron will stop.
|
|
104
|
-
example: 1630000000000
|
|
105
101
|
|
|
106
102
|
output:
|
|
107
103
|
schema:
|
|
@@ -11,7 +11,7 @@ interface MeshCallConnectParams {
|
|
|
11
11
|
namespace?: string;
|
|
12
12
|
topic: string;
|
|
13
13
|
redis: RedisConfig;
|
|
14
|
-
callback:
|
|
14
|
+
callback: (...args: any[]) => any;
|
|
15
15
|
}
|
|
16
16
|
interface MeshCallExecParams {
|
|
17
17
|
namespace?: string;
|
|
@@ -20,17 +20,21 @@ interface MeshCallExecParams {
|
|
|
20
20
|
redis: RedisConfig;
|
|
21
21
|
options?: MeshCallExecOptions;
|
|
22
22
|
}
|
|
23
|
+
interface MeshCallFlushOptions {
|
|
24
|
+
id: string;
|
|
25
|
+
}
|
|
23
26
|
interface MeshCallFlushParams {
|
|
24
27
|
namespace?: string;
|
|
25
|
-
id
|
|
28
|
+
id?: string;
|
|
26
29
|
topic: string;
|
|
27
30
|
redis: RedisConfig;
|
|
31
|
+
options?: MeshCallFlushOptions;
|
|
28
32
|
}
|
|
29
33
|
interface MeshCallCronOptions {
|
|
30
34
|
id: string;
|
|
31
35
|
interval: string;
|
|
32
36
|
maxCycles?: number;
|
|
33
|
-
|
|
37
|
+
delay?: string;
|
|
34
38
|
}
|
|
35
39
|
interface MeshCallInterruptOptions {
|
|
36
40
|
id: string;
|
|
@@ -42,7 +46,7 @@ interface MeshCallCronParams {
|
|
|
42
46
|
topic: string;
|
|
43
47
|
redis: RedisConfig;
|
|
44
48
|
args: any[];
|
|
45
|
-
callback:
|
|
49
|
+
callback: (...args: any[]) => any;
|
|
46
50
|
options: MeshCallCronOptions;
|
|
47
51
|
}
|
|
48
52
|
interface MeshCallInterruptParams {
|
|
@@ -51,4 +55,4 @@ interface MeshCallInterruptParams {
|
|
|
51
55
|
redis: RedisConfig;
|
|
52
56
|
options: MeshCallInterruptOptions;
|
|
53
57
|
}
|
|
54
|
-
export { MeshCallConnectParams, MeshCallExecParams, MeshCallCronParams, MeshCallExecOptions, MeshCallCronOptions, MeshCallInterruptOptions, MeshCallInterruptParams, MeshCallFlushParams, };
|
|
58
|
+
export { MeshCallConnectParams, MeshCallExecParams, MeshCallCronParams, MeshCallExecOptions, MeshCallCronOptions, MeshCallInterruptOptions, MeshCallInterruptParams, MeshCallFlushOptions, MeshCallFlushParams, };
|
package/index.ts
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
import { MeshCall } from './services/meshcall';
|
|
2
2
|
import { MeshData } from './services/meshdata';
|
|
3
|
+
import { MeshFlow } from './services/meshflow';
|
|
3
4
|
import { HotMesh } from './services/hotmesh';
|
|
4
|
-
import { ClientService } from './services/meshflow/client';
|
|
5
|
-
import { WorkerService } from './services/meshflow/worker';
|
|
6
|
-
import { WorkflowService } from './services/meshflow/workflow';
|
|
7
|
-
import { ConnectionService } from './services/meshflow/connection';
|
|
8
5
|
import { HotMeshConfig } from './types/hotmesh';
|
|
9
6
|
|
|
10
|
-
const MeshFlow = {
|
|
11
|
-
Client: ClientService,
|
|
12
|
-
Worker: WorkerService,
|
|
13
|
-
workflow: WorkflowService,
|
|
14
|
-
Connection: ConnectionService,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
7
|
export {
|
|
18
8
|
HotMesh,
|
|
19
9
|
MeshCall,
|
package/package.json
CHANGED
package/types/meshcall.ts
CHANGED
|
@@ -16,29 +16,84 @@ interface MeshCallExecOptions {
|
|
|
16
16
|
flush?: boolean;
|
|
17
17
|
}
|
|
18
18
|
interface MeshCallConnectParams {
|
|
19
|
+
/**
|
|
20
|
+
* Log level for the worker
|
|
21
|
+
*/
|
|
19
22
|
logLevel?: LogLevel;
|
|
20
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Idempotent GUID for the worker and engine
|
|
25
|
+
*/
|
|
26
|
+
guid?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Namespace for grouping common functions
|
|
29
|
+
*/
|
|
21
30
|
namespace?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Unique topic for the worker function
|
|
33
|
+
*/
|
|
22
34
|
topic: string;
|
|
35
|
+
/**
|
|
36
|
+
* Redis configuration for the worker
|
|
37
|
+
*/
|
|
23
38
|
redis: RedisConfig;
|
|
24
|
-
|
|
39
|
+
/**
|
|
40
|
+
* The linked worker function that will be called
|
|
41
|
+
*/
|
|
42
|
+
callback: (...args: any[]) => any;
|
|
25
43
|
}
|
|
26
44
|
|
|
27
45
|
interface MeshCallExecParams {
|
|
46
|
+
/**
|
|
47
|
+
* namespace for grouping common functions
|
|
48
|
+
*/
|
|
28
49
|
namespace?: string;
|
|
50
|
+
/**
|
|
51
|
+
* topic assigned to the worker when it was connected
|
|
52
|
+
*/
|
|
29
53
|
topic: string;
|
|
54
|
+
/**
|
|
55
|
+
* Arguments to pass to the worker function
|
|
56
|
+
*/
|
|
30
57
|
args: any[];
|
|
58
|
+
/**
|
|
59
|
+
* Redis configuration
|
|
60
|
+
*/
|
|
31
61
|
redis: RedisConfig;
|
|
62
|
+
/**
|
|
63
|
+
* Execution options like caching ttl
|
|
64
|
+
*/
|
|
32
65
|
options?: MeshCallExecOptions;
|
|
33
66
|
}
|
|
34
67
|
|
|
68
|
+
interface MeshCallFlushOptions {
|
|
69
|
+
/**
|
|
70
|
+
* Cache id when caching/flushing/retrieving function results.
|
|
71
|
+
*/
|
|
72
|
+
id: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
35
75
|
interface MeshCallFlushParams {
|
|
76
|
+
/**
|
|
77
|
+
* namespace for grouping common functions
|
|
78
|
+
*/
|
|
36
79
|
namespace?: string;
|
|
37
|
-
|
|
80
|
+
/**
|
|
81
|
+
* id for cached response to flush
|
|
82
|
+
*/
|
|
83
|
+
id?: string;
|
|
84
|
+
/**
|
|
85
|
+
* topic assigned to the worker when it was connected
|
|
86
|
+
*/
|
|
38
87
|
topic: string;
|
|
88
|
+
/**
|
|
89
|
+
* Redis configuration
|
|
90
|
+
*/
|
|
39
91
|
redis: RedisConfig;
|
|
92
|
+
/**
|
|
93
|
+
* Options for the flush
|
|
94
|
+
*/
|
|
95
|
+
options?: MeshCallFlushOptions;
|
|
40
96
|
}
|
|
41
|
-
|
|
42
97
|
interface MeshCallCronOptions {
|
|
43
98
|
/**
|
|
44
99
|
* Idempotent GUID for the function
|
|
@@ -50,14 +105,15 @@ interface MeshCallCronOptions {
|
|
|
50
105
|
*/
|
|
51
106
|
interval: string;
|
|
52
107
|
/**
|
|
53
|
-
* Maximum number of cycles to run before
|
|
108
|
+
* Maximum number of cycles to run before exiting the cron.
|
|
54
109
|
*/
|
|
55
110
|
maxCycles?: number;
|
|
56
111
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
112
|
+
* Time in seconds to sleep before invoking the first cycle.
|
|
113
|
+
* For example, `1 day`, `1 hour`. Fidelity is generally
|
|
114
|
+
* within 5 seconds. Refer to the syntax for the `ms` NPM package.
|
|
59
115
|
*/
|
|
60
|
-
|
|
116
|
+
delay?: string;
|
|
61
117
|
}
|
|
62
118
|
|
|
63
119
|
interface MeshCallInterruptOptions {
|
|
@@ -95,9 +151,9 @@ interface MeshCallCronParams {
|
|
|
95
151
|
*/
|
|
96
152
|
args: any[];
|
|
97
153
|
/**
|
|
98
|
-
*
|
|
154
|
+
* linked worker function to run
|
|
99
155
|
*/
|
|
100
|
-
callback:
|
|
156
|
+
callback: (...args: any[]) => any;
|
|
101
157
|
/**
|
|
102
158
|
* Options for the cron job
|
|
103
159
|
*/
|
|
@@ -105,9 +161,21 @@ interface MeshCallCronParams {
|
|
|
105
161
|
}
|
|
106
162
|
|
|
107
163
|
interface MeshCallInterruptParams {
|
|
164
|
+
/**
|
|
165
|
+
* namespace for grouping common functions
|
|
166
|
+
*/
|
|
108
167
|
namespace?: string;
|
|
168
|
+
/**
|
|
169
|
+
* topic assigned to the cron worker when it was connected
|
|
170
|
+
*/
|
|
109
171
|
topic: string;
|
|
172
|
+
/**
|
|
173
|
+
* Redis configuration
|
|
174
|
+
*/
|
|
110
175
|
redis: RedisConfig;
|
|
176
|
+
/**
|
|
177
|
+
* Options for interrupting the cron
|
|
178
|
+
*/
|
|
111
179
|
options: MeshCallInterruptOptions;
|
|
112
180
|
}
|
|
113
181
|
|
|
@@ -119,5 +187,6 @@ export {
|
|
|
119
187
|
MeshCallCronOptions,
|
|
120
188
|
MeshCallInterruptOptions,
|
|
121
189
|
MeshCallInterruptParams,
|
|
190
|
+
MeshCallFlushOptions,
|
|
122
191
|
MeshCallFlushParams,
|
|
123
192
|
};
|