@requence/service 1.0.0-alpha.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/CHANGELOG.md +16 -0
- package/README.md +191 -0
- package/build/chunk-2exhyr7n.js +234 -0
- package/build/chunk-2exhyr7n.js.map +14 -0
- package/build/cli.js +46 -0
- package/build/cli.js.map +10 -0
- package/build/index.js +1111 -0
- package/build/index.js.map +22 -0
- package/build/types/helpers/src/clone.d.ts +3 -0
- package/build/types/helpers/src/clone.d.ts.map +1 -0
- package/build/types/helpers/src/createObjectProxy.d.ts +2 -0
- package/build/types/helpers/src/createObjectProxy.d.ts.map +1 -0
- package/build/types/helpers/src/index.d.ts +7 -0
- package/build/types/helpers/src/index.d.ts.map +1 -0
- package/build/types/helpers/src/obfuscate.d.ts +4 -0
- package/build/types/helpers/src/obfuscate.d.ts.map +1 -0
- package/build/types/helpers/src/service.d.ts +156 -0
- package/build/types/helpers/src/service.d.ts.map +1 -0
- package/build/types/helpers/src/task.d.ts +49 -0
- package/build/types/helpers/src/task.d.ts.map +1 -0
- package/build/types/helpers/src/utils.d.ts +7 -0
- package/build/types/helpers/src/utils.d.ts.map +1 -0
- package/build/types/service/src/connections/createAmqpConnection.d.ts +42 -0
- package/build/types/service/src/connections/createAmqpConnection.d.ts.map +1 -0
- package/build/types/service/src/helpers.d.ts +121 -0
- package/build/types/service/src/helpers.d.ts.map +1 -0
- package/build/types/service/src/index.d.ts +12 -0
- package/build/types/service/src/index.d.ts.map +1 -0
- package/package.json +31 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
# 1.0.0-alpha.0 (2024-11-18)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* nodes rewrite ([80928db](https://github.com/regrapes/requence/commit/80928db9fe0bb360fae7608c85ae750d7ee86ea2))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### BREAKING CHANGES
|
|
15
|
+
|
|
16
|
+
* Rewrite form XState to custom node based implementation w/ UI
|
package/README.md
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# @requence/consumer
|
|
2
|
+
|
|
3
|
+
This package connects a JavaScript runtime (e.g. Node.js / Bun) to the operator bus. It manages the retrieval and responses of messages.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import createConsumer from '@requence/consumer'
|
|
9
|
+
|
|
10
|
+
createConsumer((ctx) => {
|
|
11
|
+
return 'this is my response'
|
|
12
|
+
})
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Every consumer instance needs a `url` parameter to connect to the operator and a `version`. In the basic example, those parameters get automatically retrieved from environment variables `REQUENCE_URL` and `VERSION`.
|
|
16
|
+
To be more explicit about those configurations, you can pass an object as the first parameter:
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
createConsumer(
|
|
20
|
+
{
|
|
21
|
+
url: 'your operator connection url string',
|
|
22
|
+
version: 'your version in format major.minor.patch',
|
|
23
|
+
},
|
|
24
|
+
(ctx) => {
|
|
25
|
+
return 'this is my response'
|
|
26
|
+
},
|
|
27
|
+
)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Additional configuration
|
|
31
|
+
|
|
32
|
+
By default, the consumer retrieves one message from the operator, processes it and passes the response back to the operator. If your service is capable of processing multiple messages in parallel, you can define a higher `prefetch`.
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
createConsumer(
|
|
36
|
+
{
|
|
37
|
+
prefetch: 10, // this will process max. 10 messages at once when available
|
|
38
|
+
},
|
|
39
|
+
async (ctx) => {
|
|
40
|
+
return 'this is my response'
|
|
41
|
+
},
|
|
42
|
+
)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Unsubscribing service
|
|
46
|
+
|
|
47
|
+
Should you ever need to unsubscribe your service from the operator programmatically, `createConsumer` returns a promise with an unsubscribe function.
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
const unsubscribe = await createConsumer(...)
|
|
51
|
+
|
|
52
|
+
// later
|
|
53
|
+
unsubscribe()
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
To resubscribe, you have to call `createConsumer` again
|
|
57
|
+
|
|
58
|
+
## Processing messages
|
|
59
|
+
|
|
60
|
+
The message handler callback provides one argument: the message context.
|
|
61
|
+
The context provides helper methods to access previous operator results and also methods to abort the processing early.
|
|
62
|
+
|
|
63
|
+
### context api data retrieval
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
ctx.getInput()
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The input that was defined when the task started
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
ctx.getMeta()
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The additional meta information added to the task
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
ctx.getConfiguration(): unknown
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
The optional configuration of the current service
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
ctx.getServiceMeta(serviceIdentifier): {
|
|
85
|
+
executionDate: Date | null, // null when the service was not yet executed
|
|
86
|
+
id: string, // service id used for internal routing
|
|
87
|
+
alias?: string, // service alias (see service Identifier)
|
|
88
|
+
name: string,
|
|
89
|
+
configuration?: unknown,
|
|
90
|
+
version: string
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The meta parameters of a service, usually not needed
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
ctx.getServiceData(serviceIdentifier): unknown
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The response of a previously executed service
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
ctx.getLastServiceData(serviceIdentifier): unknown
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Same as `ctx.getServiceData` but only returns the last data when a service is used multiple times
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
ctx.getServiceError(serviceIdentifier): string | null
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
The error message of a previously executed service or null when said service was not yet executed or did process without error.
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
ctx.getLastServiceError(serviceIdentifier): string | null
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Same as `ctx.getServiceError` but only returns the last error when a service is used multiple times
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
ctx.getResults(): Array<{
|
|
122
|
+
executionDate: Date | null, // null when the service was not yet executed
|
|
123
|
+
id: string, // service id used for internal routing
|
|
124
|
+
alias?: string, // service alias (see service Identifier)
|
|
125
|
+
name: string,
|
|
126
|
+
configuration?: unknown,
|
|
127
|
+
version: string
|
|
128
|
+
error?: string
|
|
129
|
+
data?: unknown | null
|
|
130
|
+
}>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
get results of all configured services in this task. When a service did run prior to the current service, `executionDate` and `error` or `data` will be available.
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
ctx.getTenantName(): String
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
The name of the tenant that initiated the task
|
|
140
|
+
|
|
141
|
+
### context api processing control
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
ctx.retry(delay?: number): never
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Instructs the operator to retry the service after an optional delay in milliseconds (minimum is 100ms). No code gets executed after this line.
|
|
148
|
+
**Currently, it is your responsibility to prevent infinite loops.**
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
ctx.abort(reason?: string): never
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Instructs the operator to abort the processing of this service immediately.
|
|
155
|
+
If the service is not configured with a fail over, the complete task will fail.
|
|
156
|
+
|
|
157
|
+
### service identifier
|
|
158
|
+
|
|
159
|
+
Most context methods require a service identifier as parameter. This identifier can either be a service name or a service alias. The latter is useful for situations where a service is used multiple times in a task and needs the data from one specific execution.
|
|
160
|
+
|
|
161
|
+
## Full example
|
|
162
|
+
|
|
163
|
+
Pseudo implementation of a database service
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
import createConsumer from '@requence/consumer'
|
|
167
|
+
import db from './database.js' // pseudo code
|
|
168
|
+
createConsumer(
|
|
169
|
+
{
|
|
170
|
+
url: 'amqp://username:password@host',
|
|
171
|
+
version: '1.2.3',
|
|
172
|
+
prefetch: 2, // we can process 2 messages in parallel
|
|
173
|
+
},
|
|
174
|
+
async (ctx) => {
|
|
175
|
+
const ocrData = ctx.getServiceData('ocr')
|
|
176
|
+
|
|
177
|
+
if (!ocrData) {
|
|
178
|
+
ctx.abort('Ocr service is mandatory for this AI service')
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (!db.isConnected) {
|
|
182
|
+
// lets wait 2s for the db to recover
|
|
183
|
+
ctx.retry(2000)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const response = await db.getDataBasedOnOcr(ocrData)
|
|
187
|
+
|
|
188
|
+
return response
|
|
189
|
+
},
|
|
190
|
+
)
|
|
191
|
+
```
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
// ../helpers/src/obfuscate.ts
|
|
2
|
+
function obfuscate(...parts) {
|
|
3
|
+
const str = parts.join(separator);
|
|
4
|
+
let binaryString = "";
|
|
5
|
+
for (let i = 0;i < str.length; i++) {
|
|
6
|
+
const charCode = str.charCodeAt(i);
|
|
7
|
+
binaryString += charCode.toString(2).padStart(16, "0");
|
|
8
|
+
}
|
|
9
|
+
let encodedString = "";
|
|
10
|
+
const chunkSize = 6;
|
|
11
|
+
let paddingCount = 0;
|
|
12
|
+
for (let i = 0;i < binaryString.length; i += chunkSize) {
|
|
13
|
+
let chunk = binaryString.substring(i, i + chunkSize);
|
|
14
|
+
if (chunk.length < chunkSize) {
|
|
15
|
+
paddingCount = chunkSize - chunk.length;
|
|
16
|
+
chunk = chunk.padEnd(chunkSize, "0");
|
|
17
|
+
}
|
|
18
|
+
const decimalValue = parseInt(chunk, 2);
|
|
19
|
+
encodedString += base65Chars[decimalValue];
|
|
20
|
+
}
|
|
21
|
+
return encodedString + paddingCount.toString();
|
|
22
|
+
}
|
|
23
|
+
function deobfuscate(str) {
|
|
24
|
+
const paddingCount = parseInt(str.slice(-1), 10);
|
|
25
|
+
str = str.slice(0, -1);
|
|
26
|
+
let binaryString = "";
|
|
27
|
+
for (let i = 0;i < str.length; i++) {
|
|
28
|
+
const decimalValue = base65CharToIndex[str[i]];
|
|
29
|
+
const binaryChunk = decimalValue.toString(2).padStart(6, "0");
|
|
30
|
+
binaryString += binaryChunk;
|
|
31
|
+
}
|
|
32
|
+
if (paddingCount > 0) {
|
|
33
|
+
binaryString = binaryString.slice(0, -paddingCount);
|
|
34
|
+
}
|
|
35
|
+
let decodedString = "";
|
|
36
|
+
const charSize = 16;
|
|
37
|
+
for (let i = 0;i < binaryString.length; i += charSize) {
|
|
38
|
+
const byte = binaryString.substring(i, i + charSize);
|
|
39
|
+
if (byte.length === 16) {
|
|
40
|
+
const charCode = parseInt(byte, 2);
|
|
41
|
+
decodedString += String.fromCharCode(charCode);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return decodedString.split(separator);
|
|
45
|
+
}
|
|
46
|
+
var separator = "\uF6EE";
|
|
47
|
+
var base65Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$";
|
|
48
|
+
var base65CharToIndex = {};
|
|
49
|
+
for (let i = 0;i < base65Chars.length; i++) {
|
|
50
|
+
base65CharToIndex[base65Chars[i]] = i;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ../helpers/src/service.ts
|
|
54
|
+
import {z} from "zod";
|
|
55
|
+
var uuidSchema = z.string().uuid();
|
|
56
|
+
var serviceSchema = z.lazy(() => z.union([
|
|
57
|
+
singleServiceSchema,
|
|
58
|
+
sequenceServiceSchema,
|
|
59
|
+
conditionSchema,
|
|
60
|
+
parallelServiceSchema
|
|
61
|
+
]));
|
|
62
|
+
var singleServiceSchema = z.object({
|
|
63
|
+
id: uuidSchema,
|
|
64
|
+
type: z.literal("service"),
|
|
65
|
+
name: z.string(),
|
|
66
|
+
version: z.string(),
|
|
67
|
+
configuration: z.any().optional(),
|
|
68
|
+
messageTTL: z.number().int().min(1).optional(),
|
|
69
|
+
alias: z.string().optional(),
|
|
70
|
+
retry: z.number().int().optional(),
|
|
71
|
+
retryDelay: z.number().int().optional(),
|
|
72
|
+
onFail: z.union([z.literal("skip"), serviceSchema.optional()])
|
|
73
|
+
});
|
|
74
|
+
var serviceListSchema = z.array(singleServiceSchema.pick({
|
|
75
|
+
id: true,
|
|
76
|
+
alias: true
|
|
77
|
+
}).merge(singleServiceSchema.pick({
|
|
78
|
+
name: true,
|
|
79
|
+
version: true,
|
|
80
|
+
configuration: true
|
|
81
|
+
}).partial()));
|
|
82
|
+
var parallelServiceSchema = z.object({
|
|
83
|
+
type: z.literal("parallel"),
|
|
84
|
+
name: z.string().optional(),
|
|
85
|
+
services: z.array(serviceSchema).min(1)
|
|
86
|
+
});
|
|
87
|
+
var sequenceServiceSchema = z.object({
|
|
88
|
+
type: z.literal("sequence"),
|
|
89
|
+
name: z.string().optional(),
|
|
90
|
+
services: z.array(serviceSchema).min(1)
|
|
91
|
+
});
|
|
92
|
+
var expressionSchema = z.union([
|
|
93
|
+
z.object({
|
|
94
|
+
property: z.union([z.boolean(), z.string(), z.number(), z.date()]),
|
|
95
|
+
operator: z.enum(["==", "==="]),
|
|
96
|
+
operant: z.union([z.boolean(), z.string(), z.number(), z.date()])
|
|
97
|
+
}),
|
|
98
|
+
z.object({
|
|
99
|
+
property: z.union([z.number(), z.date(), z.string()]),
|
|
100
|
+
operator: z.enum([">", "<", ">=", "<="]),
|
|
101
|
+
operant: z.union([z.number(), z.date()])
|
|
102
|
+
}),
|
|
103
|
+
z.object({
|
|
104
|
+
property: z.union([z.number(), z.date(), z.boolean(), z.string()]),
|
|
105
|
+
operator: z.enum(["IN", "NOT_IN"]),
|
|
106
|
+
operant: z.array(z.union([z.string(), z.number()]))
|
|
107
|
+
}),
|
|
108
|
+
z.object({
|
|
109
|
+
property: z.string(),
|
|
110
|
+
operator: z.literal("MATCHES"),
|
|
111
|
+
operant: z.string()
|
|
112
|
+
}),
|
|
113
|
+
z.object({
|
|
114
|
+
property: z.string(),
|
|
115
|
+
operator: z.enum(["EXISTS", "NOT_EXISTS"])
|
|
116
|
+
})
|
|
117
|
+
]);
|
|
118
|
+
var conditionSchema = z.object({
|
|
119
|
+
id: uuidSchema,
|
|
120
|
+
type: z.literal("condition"),
|
|
121
|
+
name: z.string().optional(),
|
|
122
|
+
expression: expressionSchema,
|
|
123
|
+
then: serviceSchema,
|
|
124
|
+
else: serviceSchema.optional()
|
|
125
|
+
});
|
|
126
|
+
// ../helpers/src/task.ts
|
|
127
|
+
import {z as z2} from "zod";
|
|
128
|
+
function uniqueServices(task, ctx) {
|
|
129
|
+
const serviceIds = new Set;
|
|
130
|
+
const aliases = new Set;
|
|
131
|
+
const addServiceId = (id) => {
|
|
132
|
+
if (serviceIds.has(id)) {
|
|
133
|
+
ctx.addIssue({
|
|
134
|
+
code: z2.ZodIssueCode.custom,
|
|
135
|
+
message: "serviceId is not unique",
|
|
136
|
+
params: {
|
|
137
|
+
id
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
serviceIds.add(id);
|
|
142
|
+
};
|
|
143
|
+
const addAlias = (alias) => {
|
|
144
|
+
if (aliases.has(alias)) {
|
|
145
|
+
ctx.addIssue({
|
|
146
|
+
code: z2.ZodIssueCode.custom,
|
|
147
|
+
message: "alias is not unique",
|
|
148
|
+
params: {
|
|
149
|
+
alias
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
aliases.add(alias);
|
|
154
|
+
};
|
|
155
|
+
const visitService = (service2) => {
|
|
156
|
+
switch (service2.type) {
|
|
157
|
+
case "service": {
|
|
158
|
+
addServiceId(service2.id);
|
|
159
|
+
if (service2.alias) {
|
|
160
|
+
addAlias(service2.alias);
|
|
161
|
+
}
|
|
162
|
+
if (service2.onFail && service2.onFail !== "skip") {
|
|
163
|
+
visitService(service2.onFail);
|
|
164
|
+
}
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
case "parallel":
|
|
168
|
+
case "sequence": {
|
|
169
|
+
service2.services.forEach(visitService);
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
case "condition": {
|
|
173
|
+
addServiceId(service2.id);
|
|
174
|
+
visitService(service2.then);
|
|
175
|
+
if (service2.else) {
|
|
176
|
+
visitService(service2.else);
|
|
177
|
+
}
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
visitService(task.pipeline);
|
|
183
|
+
}
|
|
184
|
+
var baseTaskSchema = z2.object({
|
|
185
|
+
id: uuidSchema,
|
|
186
|
+
input: z2.any(),
|
|
187
|
+
meta: z2.any(),
|
|
188
|
+
pipeline: serviceSchema
|
|
189
|
+
});
|
|
190
|
+
var taskSchema = baseTaskSchema.superRefine(uniqueServices);
|
|
191
|
+
// ../helpers/src/clone.ts
|
|
192
|
+
var CLONE_SYMBOL = Symbol("original");
|
|
193
|
+
function clone(data) {
|
|
194
|
+
if (typeof data !== "object" || data === null) {
|
|
195
|
+
return data;
|
|
196
|
+
}
|
|
197
|
+
const target = data[CLONE_SYMBOL];
|
|
198
|
+
if (target) {
|
|
199
|
+
return clone(target);
|
|
200
|
+
}
|
|
201
|
+
if (Array.isArray(data)) {
|
|
202
|
+
return data.map(clone);
|
|
203
|
+
}
|
|
204
|
+
return Object.fromEntries(Object.entries(data).map(([key, value]) => [key, clone(value)]));
|
|
205
|
+
}
|
|
206
|
+
// ../helpers/src/createObjectProxy.ts
|
|
207
|
+
function createObjectProxy(obj, onChange) {
|
|
208
|
+
return new Proxy(obj, {
|
|
209
|
+
set(target, property, newValue) {
|
|
210
|
+
const result = Reflect.set(target, property, newValue);
|
|
211
|
+
onChange(target);
|
|
212
|
+
return result;
|
|
213
|
+
},
|
|
214
|
+
deleteProperty(target, property) {
|
|
215
|
+
const result = Reflect.deleteProperty(target, property);
|
|
216
|
+
onChange(target);
|
|
217
|
+
return result;
|
|
218
|
+
},
|
|
219
|
+
get(target, property, receiver) {
|
|
220
|
+
if (property === CLONE_SYMBOL) {
|
|
221
|
+
return target;
|
|
222
|
+
}
|
|
223
|
+
const result = Reflect.get(target, property, receiver);
|
|
224
|
+
if (typeof result === "object" && result !== null) {
|
|
225
|
+
return createObjectProxy(result, () => onChange(target));
|
|
226
|
+
}
|
|
227
|
+
return result;
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
export { obfuscate, deobfuscate, clone, createObjectProxy };
|
|
232
|
+
|
|
233
|
+
//# debugId=BEBA23696243BAE964756E2164756E21
|
|
234
|
+
//# sourceMappingURL=chunk-2exhyr7n.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../helpers/src/obfuscate.ts", "../../helpers/src/service.ts", "../../helpers/src/task.ts", "../../helpers/src/clone.ts", "../../helpers/src/createObjectProxy.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"const separator = '\\u{f6ee}'\n\nconst base65Chars =\n 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$'\n\nconst base65CharToIndex: Record<string, number> = {}\nfor (let i = 0; i < base65Chars.length; i++) {\n base65CharToIndex[base65Chars[i]] = i\n}\n\nexport function obfuscate(...parts: Array<string>) {\n const str = parts.join(separator)\n let binaryString = ''\n\n for (let i = 0; i < str.length; i++) {\n const charCode = str.charCodeAt(i)\n binaryString += charCode.toString(2).padStart(16, '0')\n }\n\n let encodedString = ''\n const chunkSize = 6\n let paddingCount = 0\n\n for (let i = 0; i < binaryString.length; i += chunkSize) {\n let chunk = binaryString.substring(i, i + chunkSize)\n\n if (chunk.length < chunkSize) {\n paddingCount = chunkSize - chunk.length\n chunk = chunk.padEnd(chunkSize, '0')\n }\n\n const decimalValue = parseInt(chunk, 2)\n encodedString += base65Chars[decimalValue]\n }\n\n return encodedString + paddingCount.toString()\n}\n\nexport function randomString(length: number) {\n const randomValues = new Uint8Array(length)\n crypto.getRandomValues(randomValues)\n\n let randomString = ''\n for (let i = 0; i < length; i++) {\n randomString += base65Chars[randomValues[i] % base65Chars.length]\n }\n\n return randomString\n}\n\nexport function deobfuscate(str: string) {\n const paddingCount = parseInt(str.slice(-1), 10)\n str = str.slice(0, -1)\n\n let binaryString = ''\n\n for (let i = 0; i < str.length; i++) {\n const decimalValue = base65CharToIndex[str[i]]\n const binaryChunk = decimalValue.toString(2).padStart(6, '0')\n binaryString += binaryChunk\n }\n\n if (paddingCount > 0) {\n binaryString = binaryString.slice(0, -paddingCount)\n }\n\n let decodedString = ''\n const charSize = 16\n\n for (let i = 0; i < binaryString.length; i += charSize) {\n const byte = binaryString.substring(i, i + charSize)\n if (byte.length === 16) {\n const charCode = parseInt(byte, 2)\n decodedString += String.fromCharCode(charCode)\n }\n }\n\n return decodedString.split(separator)\n}\n",
|
|
6
|
+
"import { z } from 'zod'\n\nexport type ServiceList = Array<\n Pick<SingleService, 'id' | 'alias'> &\n Partial<Pick<SingleService, 'name' | 'version' | 'configuration'>>\n>\n\nexport type SingleService = {\n id: string\n type: 'service'\n name: string\n version: string\n configuration?: any\n messageTTL?: number\n retry?: number\n retryDelay?: number\n alias?: string\n onFail?: Service | 'skip'\n}\n\nexport type ParallelService = {\n type: 'parallel'\n name?: string\n services: Array<Service>\n}\n\nexport type SequenceService = {\n type: 'sequence'\n name?: string\n services: Array<Service>\n}\n\nexport type Condition = {\n type: 'condition'\n id: string\n name?: string\n expression: z.infer<typeof expressionSchema>\n then: Service\n else?: Service\n}\n\nexport type Service =\n | SingleService\n | ParallelService\n | SequenceService\n | Condition\n\nexport const uuidSchema = z.string().uuid()\n\nexport const serviceSchema: z.ZodType<Service> = z.lazy(() =>\n z.union([\n singleServiceSchema,\n sequenceServiceSchema,\n conditionSchema,\n parallelServiceSchema,\n ]),\n)\n\nexport const singleServiceSchema = z.object({\n id: uuidSchema,\n type: z.literal('service'),\n name: z.string(),\n version: z.string(),\n configuration: z.any().optional(),\n messageTTL: z.number().int().min(1).optional(),\n alias: z.string().optional(),\n retry: z.number().int().optional(),\n retryDelay: z.number().int().optional(),\n onFail: z.union([z.literal('skip'), serviceSchema.optional()]),\n})\n\nexport const serviceListSchema = z.array(\n singleServiceSchema\n .pick({\n id: true,\n alias: true,\n })\n .merge(\n singleServiceSchema\n .pick({\n name: true,\n version: true,\n configuration: true,\n })\n .partial(),\n ),\n)\n\nconst parallelServiceSchema: z.ZodType<ParallelService> = z.object({\n type: z.literal('parallel'),\n name: z.string().optional(),\n services: z.array(serviceSchema).min(1),\n})\n\nconst sequenceServiceSchema: z.ZodType<SequenceService> = z.object({\n type: z.literal('sequence'),\n name: z.string().optional(),\n services: z.array(serviceSchema).min(1),\n})\n\nexport const expressionSchema = z.union([\n z.object({\n property: z.union([z.boolean(), z.string(), z.number(), z.date()]),\n operator: z.enum(['==', '==='] as const),\n operant: z.union([z.boolean(), z.string(), z.number(), z.date()]),\n }),\n z.object({\n property: z.union([z.number(), z.date(), z.string()]),\n operator: z.enum(['>', '<', '>=', '<='] as const),\n operant: z.union([z.number(), z.date()]),\n }),\n z.object({\n property: z.union([z.number(), z.date(), z.boolean(), z.string()]),\n operator: z.enum(['IN', 'NOT_IN'] as const),\n operant: z.array(z.union([z.string(), z.number()])),\n }),\n z.object({\n property: z.string(),\n operator: z.literal('MATCHES'),\n operant: z.string(),\n }),\n z.object({\n property: z.string(),\n operator: z.enum(['EXISTS', 'NOT_EXISTS'] as const),\n }),\n])\n\nconst conditionSchema: z.ZodType<Condition> = z.object({\n id: uuidSchema,\n type: z.literal('condition'),\n name: z.string().optional(),\n expression: expressionSchema,\n then: serviceSchema,\n else: serviceSchema.optional(),\n})\n",
|
|
7
|
+
"import { z } from 'zod'\n\nimport { type Service, serviceSchema, uuidSchema } from './service.js'\n\nexport function uniqueServices(\n task: { pipeline: Service },\n ctx: z.RefinementCtx,\n) {\n const serviceIds = new Set<string>()\n const aliases = new Set<string>()\n\n const addServiceId = (id: string) => {\n if (serviceIds.has(id)) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: 'serviceId is not unique',\n params: {\n id,\n },\n })\n }\n serviceIds.add(id)\n }\n\n const addAlias = (alias: string) => {\n if (aliases.has(alias)) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: 'alias is not unique',\n params: {\n alias,\n },\n })\n }\n aliases.add(alias)\n }\n\n const visitService = (service: Service) => {\n switch (service.type) {\n case 'service': {\n addServiceId(service.id)\n if (service.alias) {\n addAlias(service.alias)\n }\n if (service.onFail && service.onFail !== 'skip') {\n visitService(service.onFail)\n }\n break\n }\n case 'parallel':\n case 'sequence': {\n service.services.forEach(visitService)\n break\n }\n case 'condition': {\n addServiceId(service.id)\n visitService(service.then)\n if (service.else) {\n visitService(service.else)\n }\n break\n }\n }\n }\n\n visitService(task.pipeline)\n}\n\nexport const baseTaskSchema = z.object({\n id: uuidSchema,\n input: z.any(),\n meta: z.any(),\n pipeline: serviceSchema,\n})\n\nexport const taskSchema = baseTaskSchema.superRefine(uniqueServices)\n\nexport type Task = z.infer<typeof baseTaskSchema>\n",
|
|
8
|
+
"export const CLONE_SYMBOL = Symbol('original')\n\nexport default function clone(data: any): any {\n if (typeof data !== 'object' || data === null) {\n return data\n }\n\n const target = (data as any)[CLONE_SYMBOL]\n if (target) {\n return clone(target)\n }\n\n if (Array.isArray(data)) {\n return data.map(clone)\n }\n\n return Object.fromEntries(\n Object.entries(data).map(([key, value]) => [key, clone(value)]),\n )\n}\n",
|
|
9
|
+
"import { CLONE_SYMBOL } from './clone.js'\n\nexport default function createObjectProxy(\n obj: Record<string, unknown>,\n onChange: (newObj: Record<string, unknown>) => void,\n) {\n return new Proxy(obj, {\n set(target, property, newValue) {\n const result = Reflect.set(target, property, newValue)\n onChange(target)\n return result\n },\n deleteProperty(target, property) {\n const result = Reflect.deleteProperty(target, property)\n onChange(target)\n return result\n },\n get(target, property, receiver) {\n if (property === CLONE_SYMBOL) {\n return target\n }\n\n const result = Reflect.get(target, property, receiver)\n\n if (typeof result === 'object' && result !== null) {\n return createObjectProxy(result, () => onChange(target))\n }\n\n return result\n },\n })\n}\n"
|
|
10
|
+
],
|
|
11
|
+
"mappings": ";AAUO,SAAS,SAAS,IAAI,OAAsB;AACjD,QAAM,MAAM,MAAM,KAAK,SAAS;AAChC,MAAI,eAAe;AAEnB,WAAS,IAAI,EAAG,IAAI,IAAI,QAAQ,KAAK;AACnC,UAAM,WAAW,IAAI,WAAW,CAAC;AACjC,oBAAgB,SAAS,SAAS,CAAC,EAAE,SAAS,IAAI,GAAG;AAAA,EACvD;AAEA,MAAI,gBAAgB;AACpB,QAAM,YAAY;AAClB,MAAI,eAAe;AAEnB,WAAS,IAAI,EAAG,IAAI,aAAa,QAAQ,KAAK,WAAW;AACvD,QAAI,QAAQ,aAAa,UAAU,GAAG,IAAI,SAAS;AAEnD,QAAI,MAAM,SAAS,WAAW;AAC5B,qBAAe,YAAY,MAAM;AACjC,cAAQ,MAAM,OAAO,WAAW,GAAG;AAAA,IACrC;AAEA,UAAM,eAAe,SAAS,OAAO,CAAC;AACtC,qBAAiB,YAAY;AAAA,EAC/B;AAEA,SAAO,gBAAgB,aAAa,SAAS;AAAA;AAexC,SAAS,WAAW,CAAC,KAAa;AACvC,QAAM,eAAe,SAAS,IAAI,MAAM,EAAE,GAAG,EAAE;AAC/C,QAAM,IAA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K,IAAI,KAAK;AAAA,EACvB;AAEA,SAAO,OAAO,YACZ,OAAO,QAAQ,IAAI,EAAE,IAAI,EAAE,KAAK,WAAW,CAAC,KAAK,MAAM,KAAK,CAAC,CAAC,CAChE;AAAA;;AChBF,SAAwB,iBAAiB,CACvC,KACA,UACA;AACA,SAAO,IAAI,MAAM,KAAK;AAAA,IACpB,GAAG,CAAC,QAAQ,UAAU,UAAU;AAC9B,YAAM,SAAS,QAAQ,IAAI,QAAQ,UAAU,QAAQ;AACrD,eAAS,MAAM;AACf,aAAO;AAAA;AAAA,IAET,cAAc,CAAC,QAAQ,UAAU;AAC/B,YAAM,SAAS,QAAQ,eAAe,QAAQ,QAAQ;AACtD,eAAS,MAAM;AACf,aAAO;AAAA;AAAA,IAET,GAAG,CAAC,QAAQ,UAAU,UAAU;AAC9B,UAAI,aAAa,cAAc;AAC7B,eAAO;AAAA,MACT;AAEA,YAAM,SAAS,QAAQ,IAAI,QAAQ,UAAU,QAAQ;AAErD,iBAAW,WAAW,YAAY,WAAW,MAAM;AACjD,eAAO,kBAAkB,QAAQ,MAAM,SAAS,MAAM,CAAC;AAAA,MACzD;AAEA,aAAO;AAAA;AAAA,EAEX,CAAC;AAAA;",
|
|
12
|
+
"debugId": "BEBA23696243BAE964756E2164756E21",
|
|
13
|
+
"names": []
|
|
14
|
+
}
|
package/build/cli.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
deobfuscate
|
|
4
|
+
} from "./chunk-2exhyr7n.js";
|
|
5
|
+
|
|
6
|
+
// src/cli.ts
|
|
7
|
+
import {mkdirSync, readFileSync, writeFileSync} from "node:fs";
|
|
8
|
+
import chalk from "chalk";
|
|
9
|
+
import yargs from "yargs";
|
|
10
|
+
import {hideBin} from "yargs/helpers";
|
|
11
|
+
function errorExit(msg) {
|
|
12
|
+
console.error(chalk.red.bold(msg + "\n"));
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
var y = yargs(hideBin(process.argv));
|
|
16
|
+
y.command("generate-types", "generates typescript types", (yargs2) => yargs2.option("service-key", {
|
|
17
|
+
describe: "service key"
|
|
18
|
+
}), async (argv) => {
|
|
19
|
+
const key = argv.serviceKey ?? process.env.REQUENCE_SERVICE_KEY ?? JSON.parse(readFileSync("package.json", "utf-8")).requence?.serviceKey;
|
|
20
|
+
console.log();
|
|
21
|
+
if (!key) {
|
|
22
|
+
errorExit("No service key found");
|
|
23
|
+
}
|
|
24
|
+
const parts = deobfuscate(key);
|
|
25
|
+
if (parts.length !== 3 || parts[0] !== "service") {
|
|
26
|
+
errorExit("Invalid service key");
|
|
27
|
+
}
|
|
28
|
+
const [, connectionString, serverUrl] = parts;
|
|
29
|
+
const response = await fetch(serverUrl + "/service/typescript", {
|
|
30
|
+
method: "GET",
|
|
31
|
+
headers: {
|
|
32
|
+
Authorization: `Bearer ${connectionString}`
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
if (!response.ok) {
|
|
36
|
+
const error = await response.text();
|
|
37
|
+
errorExit(error);
|
|
38
|
+
}
|
|
39
|
+
const data = await response.text();
|
|
40
|
+
mkdirSync(".requence/types", { recursive: true });
|
|
41
|
+
writeFileSync(".requence/types/versions.d.ts", data);
|
|
42
|
+
console.info(chalk.green("types saved to", chalk.bold(".requence")));
|
|
43
|
+
}).scriptName("requence-service").help("h").demandCommand(1, 1).strict().parse();
|
|
44
|
+
|
|
45
|
+
//# debugId=F212890998E26AF664756E2164756E21
|
|
46
|
+
//# sourceMappingURL=cli.js.map
|
package/build/cli.js.map
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/cli.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"#!/usr/bin/env node\n\nimport { mkdirSync, readFileSync, writeFileSync } from 'node:fs'\n\nimport { deobfuscate } from '@requence/helpers'\nimport chalk from 'chalk'\nimport yargs from 'yargs'\nimport { hideBin } from 'yargs/helpers'\n\nconst y = yargs(hideBin(process.argv))\n\nfunction errorExit(msg: string): never {\n console.error(chalk.red.bold(msg + '\\n'))\n process.exit(1)\n}\n\ny.command(\n 'generate-types',\n 'generates typescript types',\n (yargs) =>\n yargs.option('service-key', {\n describe: 'service key',\n }),\n async (argv) => {\n const key =\n argv.serviceKey ??\n process.env.REQUENCE_SERVICE_KEY ??\n JSON.parse(readFileSync('package.json', 'utf-8')).requence?.serviceKey\n console.log() // newline\n if (!key) {\n errorExit('No service key found')\n }\n\n const parts = deobfuscate(key)\n if (parts.length !== 3 || parts[0] !== 'service') {\n errorExit('Invalid service key')\n }\n\n const [, connectionString, serverUrl] = parts\n\n const response = await fetch(serverUrl + '/service/typescript', {\n method: 'GET',\n headers: {\n Authorization: `Bearer ${connectionString}`,\n },\n })\n\n if (!response.ok) {\n const error = await response.text()\n errorExit(error)\n }\n\n const data = await response.text()\n\n mkdirSync('.requence/types', { recursive: true })\n writeFileSync('.requence/types/versions.d.ts', data)\n\n console.info(chalk.green('types saved to', chalk.bold('.requence')))\n },\n)\n .scriptName('requence-service')\n .help('h')\n .demandCommand(1, 1)\n .strict()\n .parse()\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;AAEA;AAGA;AACA;AACA;AAIA,SAAS,SAAS,CAAC,KAAoB;AACrC,UAAQ,MAAM,MAAM,IAAI,KAAK,MAAM,IAAI,CAAC;AACxC,UAAQ,KAAK,CAAC;AAAA;AAJhB,IAAM,IAAI,MAAM,QAAQ,QAAQ,IAAI,CAAC;AAOrC,EAAE,QACA,kBACA,8BACA,CAAC,WACC,OAAM,OAAO,eAAe;AAAA,EAC1B,UAAU;AACZ,CAAC,GACH,OAAO,SAAS;AACd,QAAM,MACJ,KAAK,cACL,QAAQ,IAAI,wBACZ,KAAK,MAAM,aAAa,gBAAgB,OAAO,CAAC,EAAE,UAAU;AAC9D,UAAQ,IAAI;AACZ,OAAK,KAAK;AACR,c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