@requence/service 0.8.2-edge.1157 → 0.8.2-edge.1160
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 +47 -729
- package/build/index.js +255 -67
- package/build/index.js.map +11 -6
- package/build/types/helpers/src/protocol/command.d.ts +36 -0
- package/build/types/helpers/src/protocol/command.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/index.d.ts +1 -0
- package/build/types/helpers/src/protocol/index.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/logicExecutionTime.d.ts +22 -0
- package/build/types/helpers/src/protocol/logicExecutionTime.d.ts.map +1 -0
- package/build/types/helpers/src/protocol/taskOptions.d.ts +3 -0
- package/build/types/helpers/src/protocol/taskOptions.d.ts.map +1 -1
- package/build/types/service/src/createAmqpConnection.d.ts +0 -1
- package/build/types/service/src/createAmqpConnection.d.ts.map +1 -1
- package/build/types/service/src/helpers.d.ts +20 -1
- package/build/types/service/src/helpers.d.ts.map +1 -1
- package/build/types/service/src/index.d.ts +2 -0
- package/build/types/service/src/index.d.ts.map +1 -1
- package/build/types/service/src/store.d.ts +104 -0
- package/build/types/service/src/store.d.ts.map +1 -0
- package/package.json +2 -1
package/build/index.js
CHANGED
|
@@ -400,7 +400,7 @@ function wireBodyByteLength(value, codec) {
|
|
|
400
400
|
|
|
401
401
|
// src/createAmqpConnection.ts
|
|
402
402
|
import { connect } from "amqp-connection-manager";
|
|
403
|
-
import { z as
|
|
403
|
+
import { z as z10 } from "zod/v4";
|
|
404
404
|
|
|
405
405
|
// ../files/src/errors.ts
|
|
406
406
|
class RequenceStreamTruncatedError extends Error {
|
|
@@ -1527,6 +1527,7 @@ async function createContextHelper(options) {
|
|
|
1527
1527
|
};
|
|
1528
1528
|
},
|
|
1529
1529
|
defer: options.onDefer,
|
|
1530
|
+
store: options.store,
|
|
1530
1531
|
render(ui, props, renderOptions) {
|
|
1531
1532
|
options.onRender({
|
|
1532
1533
|
ui,
|
|
@@ -1564,6 +1565,187 @@ async function createContextHelper(options) {
|
|
|
1564
1565
|
}
|
|
1565
1566
|
var handlerStorage = new AsyncLocalStorage2;
|
|
1566
1567
|
|
|
1568
|
+
// ../store/src/address.ts
|
|
1569
|
+
import { z as z9 } from "zod/v4";
|
|
1570
|
+
// ../store/src/capability.ts
|
|
1571
|
+
function encode(value) {
|
|
1572
|
+
return Buffer.from(JSON.stringify(value), "utf8").toString("base64url");
|
|
1573
|
+
}
|
|
1574
|
+
function composeStoreCapability(signature, context) {
|
|
1575
|
+
return `${signature}.${encode({
|
|
1576
|
+
taskId: context.taskId,
|
|
1577
|
+
nodeId: context.nodeId,
|
|
1578
|
+
...context.configuration ? { configuration: true } : {}
|
|
1579
|
+
})}`;
|
|
1580
|
+
}
|
|
1581
|
+
// ../store/src/errors.ts
|
|
1582
|
+
class StoreError extends Error {
|
|
1583
|
+
constructor(message) {
|
|
1584
|
+
super(message);
|
|
1585
|
+
this.name = "StoreError";
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
class StoreUnavailableError extends StoreError {
|
|
1590
|
+
constructor(message = "the store is unavailable") {
|
|
1591
|
+
super(message);
|
|
1592
|
+
this.name = "StoreUnavailableError";
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
class StoreRequestError extends StoreError {
|
|
1597
|
+
constructor(message = "invalid store request") {
|
|
1598
|
+
super(message);
|
|
1599
|
+
this.name = "StoreRequestError";
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
|
|
1603
|
+
class StoreUnauthorizedError extends StoreError {
|
|
1604
|
+
constructor(message = "the store rejected the capability") {
|
|
1605
|
+
super(message);
|
|
1606
|
+
this.name = "StoreUnauthorizedError";
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
class StoreTaskNotAllowedError extends StoreError {
|
|
1611
|
+
constructor(message = "this task is not allowed to use the store") {
|
|
1612
|
+
super(message);
|
|
1613
|
+
this.name = "StoreTaskNotAllowedError";
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
class StoreAddressFullError extends StoreError {
|
|
1618
|
+
constructor(message = "this node already stores 64 keys") {
|
|
1619
|
+
super(message);
|
|
1620
|
+
this.name = "StoreAddressFullError";
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1624
|
+
class StoreValueTooLargeError extends StoreError {
|
|
1625
|
+
constructor(message = "the value is too large") {
|
|
1626
|
+
super(message);
|
|
1627
|
+
this.name = "StoreValueTooLargeError";
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
class StoreValueNotStorableError extends StoreError {
|
|
1632
|
+
constructor(message = "the value is not storable") {
|
|
1633
|
+
super(message);
|
|
1634
|
+
this.name = "StoreValueNotStorableError";
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
function storeErrorForStatus(status, message) {
|
|
1638
|
+
switch (status) {
|
|
1639
|
+
case 400:
|
|
1640
|
+
return new StoreRequestError(message);
|
|
1641
|
+
case 401:
|
|
1642
|
+
return new StoreUnauthorizedError(message);
|
|
1643
|
+
case 403:
|
|
1644
|
+
return new StoreTaskNotAllowedError(message);
|
|
1645
|
+
case 409:
|
|
1646
|
+
return new StoreAddressFullError(message);
|
|
1647
|
+
case 413:
|
|
1648
|
+
return new StoreValueTooLargeError(message);
|
|
1649
|
+
case 422:
|
|
1650
|
+
return new StoreValueNotStorableError(message);
|
|
1651
|
+
default:
|
|
1652
|
+
return new StoreUnavailableError(message);
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
// ../store/src/client.ts
|
|
1657
|
+
async function refusalMessage(response) {
|
|
1658
|
+
try {
|
|
1659
|
+
const body = await response.json();
|
|
1660
|
+
if (typeof body.error === "string" && body.error.length > 0) {
|
|
1661
|
+
return body.error;
|
|
1662
|
+
}
|
|
1663
|
+
} catch {}
|
|
1664
|
+
return `the store answered ${response.status}`;
|
|
1665
|
+
}
|
|
1666
|
+
function createStoreClient(options) {
|
|
1667
|
+
const doFetch = options.fetch ?? globalThis.fetch;
|
|
1668
|
+
const capability = composeStoreCapability(options.signature, {
|
|
1669
|
+
taskId: options.taskId,
|
|
1670
|
+
nodeId: options.nodeId,
|
|
1671
|
+
configuration: options.configuration
|
|
1672
|
+
});
|
|
1673
|
+
const base = options.url.endsWith("/") ? options.url.slice(0, -1) : options.url;
|
|
1674
|
+
async function call(operation, body) {
|
|
1675
|
+
let response;
|
|
1676
|
+
try {
|
|
1677
|
+
response = await doFetch(`${base}/node/${operation}`, {
|
|
1678
|
+
method: "POST",
|
|
1679
|
+
headers: {
|
|
1680
|
+
"Content-Type": "application/json",
|
|
1681
|
+
Authorization: `Bearer ${capability}`
|
|
1682
|
+
},
|
|
1683
|
+
body: JSON.stringify(body)
|
|
1684
|
+
});
|
|
1685
|
+
} catch (error) {
|
|
1686
|
+
throw new StoreUnavailableError(`the store at ${base} could not be reached: ${error instanceof Error ? error.message : String(error)}`);
|
|
1687
|
+
}
|
|
1688
|
+
if (!response.ok) {
|
|
1689
|
+
throw storeErrorForStatus(response.status, await refusalMessage(response));
|
|
1690
|
+
}
|
|
1691
|
+
return response;
|
|
1692
|
+
}
|
|
1693
|
+
return {
|
|
1694
|
+
async get(ownership, binding, key) {
|
|
1695
|
+
const response = await call("get", { ownership, binding, key });
|
|
1696
|
+
const body = await response.json();
|
|
1697
|
+
return body.value ?? null;
|
|
1698
|
+
},
|
|
1699
|
+
async set(ownership, binding, key, value) {
|
|
1700
|
+
await call("set", { ownership, binding, key, value: value ?? null });
|
|
1701
|
+
},
|
|
1702
|
+
async delete(ownership, binding, key) {
|
|
1703
|
+
await call("delete", { ownership, binding, key });
|
|
1704
|
+
}
|
|
1705
|
+
};
|
|
1706
|
+
}
|
|
1707
|
+
// src/store.ts
|
|
1708
|
+
function createStore(dispatch) {
|
|
1709
|
+
let client;
|
|
1710
|
+
function connect() {
|
|
1711
|
+
if (!client) {
|
|
1712
|
+
if (!dispatch.url || !dispatch.signature || !dispatch.nodeId) {
|
|
1713
|
+
throw new StoreUnavailableError("this dispatch carries no store capability, so the store cannot be reached from this node — the task was started before the store existed, or by a Requence instance that has none");
|
|
1714
|
+
}
|
|
1715
|
+
client = createStoreClient({
|
|
1716
|
+
url: dispatch.url,
|
|
1717
|
+
signature: dispatch.signature,
|
|
1718
|
+
taskId: dispatch.taskId,
|
|
1719
|
+
nodeId: dispatch.nodeId,
|
|
1720
|
+
configuration: dispatch.configuration,
|
|
1721
|
+
fetch: dispatch.fetch
|
|
1722
|
+
});
|
|
1723
|
+
}
|
|
1724
|
+
return client;
|
|
1725
|
+
}
|
|
1726
|
+
function slot(ownership, key, binding) {
|
|
1727
|
+
return {
|
|
1728
|
+
async get() {
|
|
1729
|
+
return connect().get(ownership, binding, key);
|
|
1730
|
+
},
|
|
1731
|
+
async set(value) {
|
|
1732
|
+
await connect().set(ownership, binding, key, value);
|
|
1733
|
+
},
|
|
1734
|
+
async delete() {
|
|
1735
|
+
await connect().delete(ownership, binding, key);
|
|
1736
|
+
}
|
|
1737
|
+
};
|
|
1738
|
+
}
|
|
1739
|
+
return {
|
|
1740
|
+
private(key, binding = "task") {
|
|
1741
|
+
return slot("private", key, binding);
|
|
1742
|
+
},
|
|
1743
|
+
shared(key, binding = "task") {
|
|
1744
|
+
return slot("shared", key, binding);
|
|
1745
|
+
}
|
|
1746
|
+
};
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1567
1749
|
// src/uiWatch.ts
|
|
1568
1750
|
import { createHash } from "node:crypto";
|
|
1569
1751
|
import fs from "node:fs";
|
|
@@ -1662,7 +1844,7 @@ function reload(registration) {
|
|
|
1662
1844
|
function errorText(error) {
|
|
1663
1845
|
return error instanceof Error ? error.message : String(error);
|
|
1664
1846
|
}
|
|
1665
|
-
var messageKeySchema =
|
|
1847
|
+
var messageKeySchema = z10.string().transform((str) => deobfuscate(str)).pipe(z10.tuple([z10.uuid(), z10.uuid()]).rest(z10.string())).transform((arr) => ({
|
|
1666
1848
|
taskId: arr[0],
|
|
1667
1849
|
messageId: arr[1],
|
|
1668
1850
|
uploadUrl: arr[2] || undefined,
|
|
@@ -1671,12 +1853,12 @@ var messageKeySchema = z9.string().transform((str) => deobfuscate(str)).pipe(z9.
|
|
|
1671
1853
|
maxFileSize: arr[5] && Number.isFinite(Number(arr[5])) ? Number(arr[5]) : undefined,
|
|
1672
1854
|
nodeId: arr[6] || undefined
|
|
1673
1855
|
}));
|
|
1674
|
-
var headerSchema =
|
|
1675
|
-
properties:
|
|
1676
|
-
correlationId:
|
|
1677
|
-
headers:
|
|
1678
|
-
taskId:
|
|
1679
|
-
mode:
|
|
1856
|
+
var headerSchema = z10.object({
|
|
1857
|
+
properties: z10.object({
|
|
1858
|
+
correlationId: z10.uuid(),
|
|
1859
|
+
headers: z10.object({
|
|
1860
|
+
taskId: z10.uuid(),
|
|
1861
|
+
mode: z10.enum(["LINEAR", "CONTINUOUS"]).default("LINEAR")
|
|
1680
1862
|
})
|
|
1681
1863
|
})
|
|
1682
1864
|
}).transform((msg) => ({
|
|
@@ -1684,45 +1866,48 @@ var headerSchema = z9.object({
|
|
|
1684
1866
|
taskId: msg.properties.headers.taskId,
|
|
1685
1867
|
mode: msg.properties.headers.mode
|
|
1686
1868
|
}));
|
|
1687
|
-
var payloadSchema =
|
|
1688
|
-
content:
|
|
1689
|
-
properties:
|
|
1690
|
-
}).transform((msg) => decodeWireBody(msg.content, msg.properties.contentType)).pipe(
|
|
1691
|
-
input:
|
|
1692
|
-
configuration:
|
|
1693
|
-
nodeId:
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1869
|
+
var payloadSchema = z10.object({
|
|
1870
|
+
content: z10.instanceof(Buffer),
|
|
1871
|
+
properties: z10.object({ contentType: z10.string().optional() })
|
|
1872
|
+
}).transform((msg) => decodeWireBody(msg.content, msg.properties.contentType)).pipe(z10.object({
|
|
1873
|
+
input: z10.unknown().optional(),
|
|
1874
|
+
configuration: z10.unknown().optional(),
|
|
1875
|
+
nodeId: z10.string().optional(),
|
|
1876
|
+
configurationEval: z10.boolean().optional(),
|
|
1877
|
+
options: z10.object({
|
|
1878
|
+
uploadUrl: z10.url().optional(),
|
|
1879
|
+
streamUrl: z10.url().optional(),
|
|
1880
|
+
maxPayloadSize: z10.number().optional(),
|
|
1881
|
+
maxFileSize: z10.number().optional(),
|
|
1882
|
+
storeUrl: z10.string().optional(),
|
|
1883
|
+
storeSignature: z10.string().optional()
|
|
1699
1884
|
})
|
|
1700
1885
|
}));
|
|
1701
|
-
var backchannelMessageSchema =
|
|
1702
|
-
content:
|
|
1703
|
-
properties:
|
|
1704
|
-
correlationId:
|
|
1705
|
-
contentType:
|
|
1706
|
-
headers:
|
|
1886
|
+
var backchannelMessageSchema = z10.object({
|
|
1887
|
+
content: z10.instanceof(Buffer),
|
|
1888
|
+
properties: z10.object({
|
|
1889
|
+
correlationId: z10.string(),
|
|
1890
|
+
contentType: z10.string().optional(),
|
|
1891
|
+
headers: z10.object({ taskId: z10.uuid().optional() }).optional().catch(undefined)
|
|
1707
1892
|
})
|
|
1708
1893
|
}).transform((message) => ({
|
|
1709
1894
|
...message,
|
|
1710
1895
|
content: decodeWireBody(message.content, message.properties.contentType)
|
|
1711
|
-
})).pipe(
|
|
1712
|
-
content:
|
|
1713
|
-
|
|
1714
|
-
type:
|
|
1896
|
+
})).pipe(z10.object({
|
|
1897
|
+
content: z10.discriminatedUnion("type", [
|
|
1898
|
+
z10.object({
|
|
1899
|
+
type: z10.literal("stop")
|
|
1715
1900
|
}),
|
|
1716
|
-
|
|
1717
|
-
type:
|
|
1718
|
-
callbackId:
|
|
1719
|
-
arg:
|
|
1720
|
-
surface:
|
|
1901
|
+
z10.object({
|
|
1902
|
+
type: z10.literal("callback"),
|
|
1903
|
+
callbackId: z10.uuid(),
|
|
1904
|
+
arg: z10.any().optional(),
|
|
1905
|
+
surface: z10.uuid().optional()
|
|
1721
1906
|
})
|
|
1722
1907
|
]),
|
|
1723
|
-
properties:
|
|
1724
|
-
correlationId:
|
|
1725
|
-
headers:
|
|
1908
|
+
properties: z10.object({
|
|
1909
|
+
correlationId: z10.string(),
|
|
1910
|
+
headers: z10.object({ taskId: z10.uuid().optional() }).optional().catch(undefined)
|
|
1726
1911
|
})
|
|
1727
1912
|
})).transform((message) => ({
|
|
1728
1913
|
payload: message.content,
|
|
@@ -1730,21 +1915,21 @@ var backchannelMessageSchema = z9.object({
|
|
|
1730
1915
|
taskId: message.properties.headers?.taskId
|
|
1731
1916
|
}));
|
|
1732
1917
|
var abortSymbol = Symbol();
|
|
1733
|
-
var connectionOptionsSchema =
|
|
1734
|
-
url:
|
|
1735
|
-
|
|
1736
|
-
|
|
1918
|
+
var connectionOptionsSchema = z10.object({
|
|
1919
|
+
url: z10.union([
|
|
1920
|
+
z10.string().regex(/^amqps?:\/\/(.+):(.+)@(.+)$/).transform((str) => new URL(str)),
|
|
1921
|
+
z10.instanceof(URL).refine((url) => url.protocol.match(/^amqps?:/), "Wrong protocol")
|
|
1737
1922
|
]),
|
|
1738
|
-
version:
|
|
1739
|
-
name:
|
|
1740
|
-
devOverlay:
|
|
1741
|
-
silent:
|
|
1742
|
-
prefetch:
|
|
1743
|
-
connectionTimeout:
|
|
1744
|
-
heartbeatInterval:
|
|
1745
|
-
connectionOptions:
|
|
1746
|
-
maxMessageSize:
|
|
1747
|
-
passthroughByteReferences:
|
|
1923
|
+
version: z10.string(),
|
|
1924
|
+
name: z10.string().optional(),
|
|
1925
|
+
devOverlay: z10.string().optional(),
|
|
1926
|
+
silent: z10.boolean().optional(),
|
|
1927
|
+
prefetch: z10.number().int().optional(),
|
|
1928
|
+
connectionTimeout: z10.number().positive().default(3000),
|
|
1929
|
+
heartbeatInterval: z10.number().int().positive().optional(),
|
|
1930
|
+
connectionOptions: z10.any().optional(),
|
|
1931
|
+
maxMessageSize: z10.number().int().positive().default(128 * 1024 * 1024),
|
|
1932
|
+
passthroughByteReferences: z10.boolean().optional()
|
|
1748
1933
|
});
|
|
1749
1934
|
function isMessageHandlerGenerator(handler) {
|
|
1750
1935
|
return handler.constructor.name === "GeneratorFunction" || handler.constructor.name === "AsyncGeneratorFunction";
|
|
@@ -1806,7 +1991,7 @@ function createConnection({
|
|
|
1806
1991
|
clientProperties: {
|
|
1807
1992
|
...connectionOptions?.clientProperties,
|
|
1808
1993
|
...buildServiceClientProperties({
|
|
1809
|
-
libVersion: "javascript@0.8.2-edge.
|
|
1994
|
+
libVersion: "javascript@0.8.2-edge.1160",
|
|
1810
1995
|
serviceVersion: version,
|
|
1811
1996
|
name,
|
|
1812
1997
|
devOverlay: Boolean(devOverlay)
|
|
@@ -2122,18 +2307,6 @@ function createConnection({
|
|
|
2122
2307
|
...options?.overwrite ? { overwrite: true } : {},
|
|
2123
2308
|
...base
|
|
2124
2309
|
}));
|
|
2125
|
-
},
|
|
2126
|
-
async sendState(state) {
|
|
2127
|
-
await deps.gate?.();
|
|
2128
|
-
deps.outbound.track(publish({
|
|
2129
|
-
index: 0,
|
|
2130
|
-
version,
|
|
2131
|
-
messageId: deps.messageId,
|
|
2132
|
-
taskId: deps.taskId,
|
|
2133
|
-
data: await deps.outbound.send(state, { outputName: null }),
|
|
2134
|
-
state: true,
|
|
2135
|
-
...base
|
|
2136
|
-
}));
|
|
2137
2310
|
}
|
|
2138
2311
|
};
|
|
2139
2312
|
};
|
|
@@ -2293,6 +2466,13 @@ function createConnection({
|
|
|
2293
2466
|
configuration: payload.configuration,
|
|
2294
2467
|
abortController,
|
|
2295
2468
|
passthroughByteReferences,
|
|
2469
|
+
store: createStore({
|
|
2470
|
+
url: payload.options.storeUrl,
|
|
2471
|
+
signature: payload.options.storeSignature,
|
|
2472
|
+
taskId,
|
|
2473
|
+
nodeId: payload.nodeId,
|
|
2474
|
+
configuration: payload.configurationEval
|
|
2475
|
+
}),
|
|
2296
2476
|
sends: {
|
|
2297
2477
|
...buildSendApi(publishDeps),
|
|
2298
2478
|
invokeCallback: (ref, arg) => dispatchInvocation({ ...ref, arg }),
|
|
@@ -2333,7 +2513,7 @@ function createConnection({
|
|
|
2333
2513
|
begin: true,
|
|
2334
2514
|
epoch,
|
|
2335
2515
|
...buildServiceIdentityHeaders({
|
|
2336
|
-
libVersion: "javascript@0.8.2-edge.
|
|
2516
|
+
libVersion: "javascript@0.8.2-edge.1160",
|
|
2337
2517
|
name
|
|
2338
2518
|
})
|
|
2339
2519
|
});
|
|
@@ -2887,6 +3067,14 @@ export {
|
|
|
2887
3067
|
assertReachable,
|
|
2888
3068
|
UnsupportedCapabilityError,
|
|
2889
3069
|
UITooLargeError,
|
|
3070
|
+
StoreValueTooLargeError,
|
|
3071
|
+
StoreValueNotStorableError,
|
|
3072
|
+
StoreUnavailableError,
|
|
3073
|
+
StoreUnauthorizedError,
|
|
3074
|
+
StoreTaskNotAllowedError,
|
|
3075
|
+
StoreRequestError,
|
|
3076
|
+
StoreError,
|
|
3077
|
+
StoreAddressFullError,
|
|
2890
3078
|
RequenceUnreachableError,
|
|
2891
3079
|
RequenceStream,
|
|
2892
3080
|
RequenceFile,
|
|
@@ -2894,5 +3082,5 @@ export {
|
|
|
2894
3082
|
PayloadTooLargeError
|
|
2895
3083
|
};
|
|
2896
3084
|
|
|
2897
|
-
//# debugId=
|
|
3085
|
+
//# debugId=2EE6F97FF9F3150464756E2164756E21
|
|
2898
3086
|
//# sourceMappingURL=index.js.map
|