@requence/service 0.8.6-edge.1238 → 0.8.7-edge.1242
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 +13 -0
- package/README.md +3 -3
- package/build/index.js +76 -12
- package/build/index.js.map +12 -11
- package/build/types/helpers/src/jsonschema/types.d.ts +1 -0
- package/build/types/helpers/src/jsonschema/types.d.ts.map +1 -1
- package/build/types/helpers/src/jsonschema/validate.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/treeNodes.d.ts.map +1 -1
- package/build/types/helpers/src/utils/variableRef.d.ts +56 -0
- package/build/types/helpers/src/utils/variableRef.d.ts.map +1 -1
- package/build/types/service/src/createAmqpConnection.d.ts +1 -1
- package/build/types/service/src/createAmqpConnection.d.ts.map +1 -1
- package/build/types/service/src/devSession.d.ts +13 -0
- package/build/types/service/src/devSession.d.ts.map +1 -0
- package/build/types/service/src/durableCallback.d.ts +7 -7
- package/build/types/service/src/helpers.d.ts +4 -4
- package/build/types/service/src/index.d.ts +11 -3
- package/build/types/service/src/index.d.ts.map +1 -1
- package/build/types/service/src/store.d.ts +5 -0
- package/build/types/service/src/store.d.ts.map +1 -1
- package/build/types/service/src/ui.d.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @requence/service
|
|
2
2
|
|
|
3
|
+
## 0.8.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 58a3e40: `prefetch` now limits the main queue consumer.
|
|
8
|
+
|
|
9
|
+
The channel's setups run in parallel, so `basic.consume` on the main queue
|
|
10
|
+
reached the broker before `basic.qos`. RabbitMQ applies `basic.qos` only to
|
|
11
|
+
consumers that start after it, so the consumer had no limit. On each start and
|
|
12
|
+
reconnect the broker pushed the whole queue at once: a service with
|
|
13
|
+
`prefetch: 1` and a backlog of 1000 messages started 51 handlers in 78 ms. The
|
|
14
|
+
consumer now sets `prefetch` on its channel before it consumes.
|
|
15
|
+
|
|
3
16
|
## 0.8.5
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ REQUENCE_SERVICE_ACCESS_TOKEN=your-token bun run index.ts
|
|
|
31
31
|
## Your first service
|
|
32
32
|
|
|
33
33
|
Create the service in the Requence UI first — its input schema, configuration schema and
|
|
34
|
-
outputs. Then implement the
|
|
34
|
+
outputs. Then implement the variant:
|
|
35
35
|
|
|
36
36
|
```typescript
|
|
37
37
|
import { createService } from '@requence/service'
|
|
@@ -41,7 +41,7 @@ createService('1.0.0', (ctx) => {
|
|
|
41
41
|
})
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
The
|
|
44
|
+
The first argument to `createService` is the **variant** of the service definition you are
|
|
45
45
|
implementing. When Requence dispatches a message, the handler runs and the return value is sent
|
|
46
46
|
back as the result.
|
|
47
47
|
|
|
@@ -62,7 +62,7 @@ npx requence-service generate-types
|
|
|
62
62
|
| `service.open()`, `service.close()` | [Starting & Stopping][lifecycle] |
|
|
63
63
|
| Generator handlers and `ctx.terminated` | [Continuous Mode][continuous] |
|
|
64
64
|
| `ctx.store` — what a node remembers past this message | [The Store][store] · [`ctx.store`][context-store] |
|
|
65
|
-
| `createDurableCallback`, `.for(…)`, the per-
|
|
65
|
+
| `createDurableCallback`, `.for(…)`, the per-variant queue | [Callbacks][callbacks] |
|
|
66
66
|
| `createUI`, `ctx.render`, handler props | [Surfaces][surfaces] |
|
|
67
67
|
| `ctx.defer()` → `service.act()` | [Deferred Delivery][deferred] |
|
|
68
68
|
| `wrapIterable`, `asyncEventEmitter` | [Utility Helpers][utilities] |
|
package/build/index.js
CHANGED
|
@@ -1942,7 +1942,8 @@ var backchannelMessageSchema = z11.object({
|
|
|
1942
1942
|
})).pipe(z11.object({
|
|
1943
1943
|
content: z11.discriminatedUnion("type", [
|
|
1944
1944
|
z11.object({
|
|
1945
|
-
type: z11.literal("stop")
|
|
1945
|
+
type: z11.literal("stop"),
|
|
1946
|
+
epoch: z11.string().optional()
|
|
1946
1947
|
}),
|
|
1947
1948
|
z11.object({
|
|
1948
1949
|
type: z11.literal("callback"),
|
|
@@ -2039,7 +2040,7 @@ function createConnection({
|
|
|
2039
2040
|
clientProperties: {
|
|
2040
2041
|
...connectionOptions?.clientProperties,
|
|
2041
2042
|
...buildServiceClientProperties({
|
|
2042
|
-
libVersion: "javascript@0.8.
|
|
2043
|
+
libVersion: "javascript@0.8.7-edge.1242",
|
|
2043
2044
|
serviceVersion: version,
|
|
2044
2045
|
connectionId,
|
|
2045
2046
|
prefetch,
|
|
@@ -2124,7 +2125,10 @@ function createConnection({
|
|
|
2124
2125
|
const backchannelMessage = result.data;
|
|
2125
2126
|
switch (backchannelMessage.payload.type) {
|
|
2126
2127
|
case "stop": {
|
|
2127
|
-
generatorTerminators.get(backchannelMessage.messageId)
|
|
2128
|
+
const attempts = generatorTerminators.get(backchannelMessage.messageId);
|
|
2129
|
+
const { epoch } = backchannelMessage.payload;
|
|
2130
|
+
const terminators = epoch === undefined ? [...attempts?.values() ?? []] : [attempts?.get(epoch)];
|
|
2131
|
+
terminators.forEach((terminate) => terminate?.("task stopped"));
|
|
2128
2132
|
break;
|
|
2129
2133
|
}
|
|
2130
2134
|
case "callback": {
|
|
@@ -2601,7 +2605,7 @@ function createConnection({
|
|
|
2601
2605
|
begin: true,
|
|
2602
2606
|
epoch,
|
|
2603
2607
|
...buildServiceIdentityHeaders({
|
|
2604
|
-
libVersion: "javascript@0.8.
|
|
2608
|
+
libVersion: "javascript@0.8.7-edge.1242",
|
|
2605
2609
|
name,
|
|
2606
2610
|
holdsSlot: !(isGeneratorHandler && mode === "CONTINUOUS")
|
|
2607
2611
|
})
|
|
@@ -2613,7 +2617,12 @@ function createConnection({
|
|
|
2613
2617
|
}
|
|
2614
2618
|
const generator = messageHandler(extendedContext);
|
|
2615
2619
|
const terminationPromise = Promise.withResolvers();
|
|
2616
|
-
generatorTerminators.
|
|
2620
|
+
let attempts = generatorTerminators.get(messageId);
|
|
2621
|
+
if (!attempts) {
|
|
2622
|
+
attempts = new Map;
|
|
2623
|
+
generatorTerminators.set(messageId, attempts);
|
|
2624
|
+
}
|
|
2625
|
+
attempts.set(epoch, (reason) => {
|
|
2617
2626
|
terminated = true;
|
|
2618
2627
|
generator.return().catch((error) => {
|
|
2619
2628
|
if (terminated && error instanceof Error && error.name === "AbortError" && !(error instanceof AbortError)) {
|
|
@@ -2814,7 +2823,11 @@ function createConnection({
|
|
|
2814
2823
|
}
|
|
2815
2824
|
} finally {
|
|
2816
2825
|
if (messageIdForCleanup) {
|
|
2817
|
-
generatorTerminators.
|
|
2826
|
+
const attempts = generatorTerminators.get(messageIdForCleanup);
|
|
2827
|
+
attempts?.delete(epoch);
|
|
2828
|
+
if (attempts?.size === 0) {
|
|
2829
|
+
generatorTerminators.delete(messageIdForCleanup);
|
|
2830
|
+
}
|
|
2818
2831
|
messageCodecs.delete(messageIdForCleanup);
|
|
2819
2832
|
}
|
|
2820
2833
|
registeredCallbackIds.forEach((id) => callbacks.delete(id));
|
|
@@ -2948,6 +2961,33 @@ function createConnection({
|
|
|
2948
2961
|
};
|
|
2949
2962
|
return api;
|
|
2950
2963
|
}
|
|
2964
|
+
|
|
2965
|
+
// src/devSession.ts
|
|
2966
|
+
class DevSessionError extends Error {
|
|
2967
|
+
constructor(message) {
|
|
2968
|
+
super(message);
|
|
2969
|
+
this.name = "DevSessionError";
|
|
2970
|
+
}
|
|
2971
|
+
}
|
|
2972
|
+
async function assertDevSession(params, fetchImpl = fetch) {
|
|
2973
|
+
const url = `${params.serverUrl}/service/dev-session`;
|
|
2974
|
+
let response;
|
|
2975
|
+
try {
|
|
2976
|
+
response = await fetchImpl(url, {
|
|
2977
|
+
headers: {
|
|
2978
|
+
Authorization: `Bearer ${params.connectionString}`,
|
|
2979
|
+
"x-dev-authorization": params.devKey
|
|
2980
|
+
}
|
|
2981
|
+
});
|
|
2982
|
+
} catch (error) {
|
|
2983
|
+
throw new DevSessionError(`Requence: the dev token cannot be checked — ${url} is not reachable (${error instanceof Error ? error.message : String(error)}). A dev overlay needs the Requence API.`);
|
|
2984
|
+
}
|
|
2985
|
+
if (response.ok) {
|
|
2986
|
+
return await response.json();
|
|
2987
|
+
}
|
|
2988
|
+
const reason = (await response.text().catch(() => "")).trim();
|
|
2989
|
+
throw new DevSessionError(`Requence: the dev token was refused by ${params.serverUrl} (${response.status})${reason ? `: ${reason}` : ""}`);
|
|
2990
|
+
}
|
|
2951
2991
|
// src/ui.ts
|
|
2952
2992
|
import { createHash as createHash3 } from "node:crypto";
|
|
2953
2993
|
import fs2 from "node:fs";
|
|
@@ -3090,18 +3130,25 @@ function loadPkgJson() {
|
|
|
3090
3130
|
return pkgJson;
|
|
3091
3131
|
}
|
|
3092
3132
|
var didWarnDevToken = false;
|
|
3093
|
-
function createService(
|
|
3133
|
+
function createService(optionsOrVariant, optionalMessageHandler) {
|
|
3094
3134
|
let options;
|
|
3095
3135
|
let messageHandler;
|
|
3096
|
-
if (typeof
|
|
3136
|
+
if (typeof optionsOrVariant === "string") {
|
|
3097
3137
|
options = {
|
|
3098
|
-
|
|
3138
|
+
variant: optionsOrVariant
|
|
3099
3139
|
};
|
|
3100
3140
|
messageHandler = optionalMessageHandler;
|
|
3101
3141
|
} else {
|
|
3102
|
-
options =
|
|
3142
|
+
options = optionsOrVariant;
|
|
3103
3143
|
messageHandler = optionalMessageHandler;
|
|
3104
3144
|
}
|
|
3145
|
+
if (options.variant !== undefined && options.version !== undefined && options.variant !== options.version) {
|
|
3146
|
+
throw new Error("conflicting service options: give `variant` only (`version` is its deprecated name)");
|
|
3147
|
+
}
|
|
3148
|
+
const variant = options.variant ?? options.version;
|
|
3149
|
+
if (typeof variant !== "string") {
|
|
3150
|
+
throw new Error("no service variant provided");
|
|
3151
|
+
}
|
|
3105
3152
|
let token = options.accessToken ?? process.env.REQUENCE_SERVICE_ACCESS_TOKEN ?? process.env.REQUENCE_ACCESS_TOKEN;
|
|
3106
3153
|
if (!token) {
|
|
3107
3154
|
try {
|
|
@@ -3125,6 +3172,7 @@ function createService(optionsOrVersion, optionalMessageHandler) {
|
|
|
3125
3172
|
}
|
|
3126
3173
|
const url = parts[1];
|
|
3127
3174
|
let devOverlay;
|
|
3175
|
+
let devSessionCheck;
|
|
3128
3176
|
if (devToken) {
|
|
3129
3177
|
const devParts = deobfuscate(devToken);
|
|
3130
3178
|
if (devParts[0] !== "api") {
|
|
@@ -3134,15 +3182,24 @@ function createService(optionsOrVersion, optionalMessageHandler) {
|
|
|
3134
3182
|
throw new Error("invalid dev token: access token and dev token belong to different requence instances");
|
|
3135
3183
|
}
|
|
3136
3184
|
devOverlay = devParts[1];
|
|
3185
|
+
if (!parts[2]) {
|
|
3186
|
+
throw new Error("invalid access token: it names no Requence API, so the dev token cannot be checked");
|
|
3187
|
+
}
|
|
3188
|
+
devSessionCheck = {
|
|
3189
|
+
serverUrl: parts[2],
|
|
3190
|
+
connectionString: parts[1],
|
|
3191
|
+
devKey: devParts[1]
|
|
3192
|
+
};
|
|
3137
3193
|
if (!didWarnDevToken) {
|
|
3138
3194
|
didWarnDevToken = true;
|
|
3139
3195
|
simple_default.warn("Requence: started with a |dev token| — this worker consumes a personal dev-overlay queue instead of the deployed version, and that queue is deleted shortly after the process stops. Do not deploy with one: unset |REQUENCE_DEV_TOKEN| / |REQUENCE_SERVICE_DEV_TOKEN|, or remove |requence.devToken| from package.json.");
|
|
3140
3196
|
}
|
|
3141
3197
|
}
|
|
3142
3198
|
const envMaxMessageSize = process.env.REQUENCE_MAX_MESSAGE_SIZE ? Number(process.env.REQUENCE_MAX_MESSAGE_SIZE) : undefined;
|
|
3143
|
-
|
|
3199
|
+
const api = createConnection({
|
|
3144
3200
|
...connectionOptionsSchema.parse({
|
|
3145
3201
|
...options,
|
|
3202
|
+
version: variant,
|
|
3146
3203
|
connectionOptions: resolveConnectionOptions(options.connectionOptions),
|
|
3147
3204
|
maxMessageSize: options.maxMessageSize ?? envMaxMessageSize,
|
|
3148
3205
|
url,
|
|
@@ -3150,6 +3207,13 @@ function createService(optionsOrVersion, optionalMessageHandler) {
|
|
|
3150
3207
|
}),
|
|
3151
3208
|
onConnectionStateChange: options.onConnectionStateChange
|
|
3152
3209
|
}, messageHandler);
|
|
3210
|
+
if (devSessionCheck) {
|
|
3211
|
+
assertDevSession(devSessionCheck).catch((error) => {
|
|
3212
|
+
simple_default.error(error instanceof Error ? error.message : String(error));
|
|
3213
|
+
process.exit(1);
|
|
3214
|
+
});
|
|
3215
|
+
}
|
|
3216
|
+
return api;
|
|
3153
3217
|
}
|
|
3154
3218
|
export {
|
|
3155
3219
|
PayloadTooLargeError2 as PayloadTooLargeError,
|
|
@@ -3178,5 +3242,5 @@ export {
|
|
|
3178
3242
|
wrapIterable
|
|
3179
3243
|
};
|
|
3180
3244
|
|
|
3181
|
-
//# debugId=
|
|
3245
|
+
//# debugId=5DA179C7CDCE0CD264756E2164756E21
|
|
3182
3246
|
//# sourceMappingURL=index.js.map
|