@ferricstore/ferricstore 0.11.9 → 0.11.11
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 +29 -9
- package/dist/index.cjs +494 -159
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +483 -148
- package/dist/index.js.map +1 -1
- package/docs/api/classes/HTTPAdapter.html +7 -7
- package/docs/api/classes/KeyValueStore.html +4 -4
- package/docs/api/functions/httpCommandDisposition.html +1 -1
- package/docs/api/index.html +25 -9
- package/docs/api/interfaces/HTTPAdapterOptions.html +19 -15
- package/docs/api/types/HTTPCommandDisposition.html +1 -1
- package/docs/api/variables/FERRICSTORE_SDK_VERSION.html +1 -1
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -1556,6 +1556,7 @@ var neverAutoBatchCommandPrefixes = /* @__PURE__ */ new Set([
|
|
|
1556
1556
|
"BLPOP",
|
|
1557
1557
|
"BRPOP",
|
|
1558
1558
|
"BRPOPLPUSH",
|
|
1559
|
+
"BZMPOP",
|
|
1559
1560
|
"BZPOPMAX",
|
|
1560
1561
|
"BZPOPMIN",
|
|
1561
1562
|
"CLIENT",
|
|
@@ -1667,6 +1668,9 @@ var connectionBlockingCommands = /* @__PURE__ */ new Set([
|
|
|
1667
1668
|
"BLPOP",
|
|
1668
1669
|
"BRPOP",
|
|
1669
1670
|
"BRPOPLPUSH",
|
|
1671
|
+
"BZMPOP",
|
|
1672
|
+
"BZPOPMAX",
|
|
1673
|
+
"BZPOPMIN",
|
|
1670
1674
|
"XREAD",
|
|
1671
1675
|
"XREADGROUP"
|
|
1672
1676
|
]);
|
|
@@ -2535,8 +2539,10 @@ function serverBlockMetadata(args) {
|
|
|
2535
2539
|
serverBlockMs = blockDurationMs(args[3], 1e3);
|
|
2536
2540
|
} else if (command === "BLMOVE" && args.length >= 6) {
|
|
2537
2541
|
serverBlockMs = blockDurationMs(args[args.length - 1], 1e3);
|
|
2538
|
-
} else if (command === "BLMPOP" && args.length >= 2) {
|
|
2542
|
+
} else if ((command === "BLMPOP" || command === "BZMPOP") && args.length >= 2) {
|
|
2539
2543
|
serverBlockMs = blockDurationMs(args[1], 1e3);
|
|
2544
|
+
} else if ((command === "BZPOPMAX" || command === "BZPOPMIN") && args.length >= 3) {
|
|
2545
|
+
serverBlockMs = blockDurationMs(args[args.length - 1], 1e3);
|
|
2540
2546
|
} else if (command === "XREAD" || command === "XREADGROUP") {
|
|
2541
2547
|
serverBlockMs = optionBlockDurationMs(args, ["BLOCK"], "STREAMS");
|
|
2542
2548
|
} else if (command === "WAIT" && args.length === 3) {
|
|
@@ -7596,6 +7602,24 @@ async function executeIndividually(host, commands, laneId, options) {
|
|
|
7596
7602
|
}, commands, options);
|
|
7597
7603
|
}
|
|
7598
7604
|
|
|
7605
|
+
// src/server-response-timeout.ts
|
|
7606
|
+
function serverResponseTimeoutMs(requestTimeoutMs, serverBlockMs) {
|
|
7607
|
+
if (serverBlockMs == null) return requestTimeoutMs;
|
|
7608
|
+
if (serverBlockMs === 0) return void 0;
|
|
7609
|
+
return saturatingAdd(requestTimeoutMs, serverBlockMs);
|
|
7610
|
+
}
|
|
7611
|
+
function combinedServerBlockMs(values) {
|
|
7612
|
+
let total;
|
|
7613
|
+
for (const value of values) {
|
|
7614
|
+
if (value === 0) return 0;
|
|
7615
|
+
if (value != null) total = saturatingAdd(total ?? 0, value);
|
|
7616
|
+
}
|
|
7617
|
+
return total;
|
|
7618
|
+
}
|
|
7619
|
+
function saturatingAdd(left, right) {
|
|
7620
|
+
return Math.min(Number.MAX_SAFE_INTEGER, left + right);
|
|
7621
|
+
}
|
|
7622
|
+
|
|
7599
7623
|
// src/native-pending-timeout.ts
|
|
7600
7624
|
function timeoutNativePendingRequest(operations, requestId, timeoutMs) {
|
|
7601
7625
|
const pending = operations.getPending(requestId);
|
|
@@ -7624,10 +7648,7 @@ function timeoutNativePendingRequest(operations, requestId, timeoutMs) {
|
|
|
7624
7648
|
pending.reject(new RequestTimeoutError(timeoutMs, "possibly_sent"));
|
|
7625
7649
|
}
|
|
7626
7650
|
function nativeResponseTimeoutMs(command, requestTimeoutMs) {
|
|
7627
|
-
|
|
7628
|
-
if (blockMs == null) return requestTimeoutMs;
|
|
7629
|
-
if (blockMs === 0) return void 0;
|
|
7630
|
-
return Math.min(Number.MAX_SAFE_INTEGER, requestTimeoutMs + blockMs);
|
|
7651
|
+
return serverResponseTimeoutMs(requestTimeoutMs, command.serverBlockMs);
|
|
7631
7652
|
}
|
|
7632
7653
|
|
|
7633
7654
|
// src/native-chunk-assembler.ts
|
|
@@ -8655,12 +8676,14 @@ var NativeAdapter = class _NativeAdapter {
|
|
|
8655
8676
|
};
|
|
8656
8677
|
|
|
8657
8678
|
// src/http-command-policy.ts
|
|
8679
|
+
var import_node_buffer33 = require("buffer");
|
|
8658
8680
|
var nativeOnlyCommands = /* @__PURE__ */ new Set([
|
|
8659
8681
|
"AUTH",
|
|
8660
8682
|
"BACKPRESSURE",
|
|
8661
8683
|
"CLIENT",
|
|
8662
8684
|
"CLIENT.INFO",
|
|
8663
8685
|
"CLIENT.SETNAME",
|
|
8686
|
+
"COMMAND_EXEC",
|
|
8664
8687
|
"EVENT",
|
|
8665
8688
|
"GOAWAY",
|
|
8666
8689
|
"HELLO",
|
|
@@ -8676,84 +8699,139 @@ var nativeOnlyCommands = /* @__PURE__ */ new Set([
|
|
|
8676
8699
|
"WINDOW_UPDATE"
|
|
8677
8700
|
]);
|
|
8678
8701
|
var sessionOnlyCommands = /* @__PURE__ */ new Set([
|
|
8702
|
+
"ASKING",
|
|
8679
8703
|
"AUTH",
|
|
8680
|
-
"BLMOVE",
|
|
8681
|
-
"BLMPOP",
|
|
8682
|
-
"BLPOP",
|
|
8683
|
-
"BRPOP",
|
|
8684
8704
|
"CLIENT",
|
|
8685
8705
|
"DISCARD",
|
|
8686
8706
|
"EXEC",
|
|
8707
|
+
"FETCH_OR_COMPUTE",
|
|
8708
|
+
"FETCH_OR_COMPUTE_ERROR",
|
|
8709
|
+
"FETCH_OR_COMPUTE_RESULT",
|
|
8687
8710
|
"HELLO",
|
|
8711
|
+
"MONITOR",
|
|
8688
8712
|
"MULTI",
|
|
8689
8713
|
"PSUBSCRIBE",
|
|
8714
|
+
"PSYNC",
|
|
8690
8715
|
"PUNSUBSCRIBE",
|
|
8691
8716
|
"QUIT",
|
|
8717
|
+
"READONLY",
|
|
8718
|
+
"READWRITE",
|
|
8719
|
+
"REPLCONF",
|
|
8720
|
+
"RESET",
|
|
8721
|
+
"SANDBOX",
|
|
8692
8722
|
"SELECT",
|
|
8723
|
+
"SSUBSCRIBE",
|
|
8693
8724
|
"SUBSCRIBE",
|
|
8725
|
+
"SUNSUBSCRIBE",
|
|
8726
|
+
"SYNC",
|
|
8694
8727
|
"UNSUBSCRIBE",
|
|
8695
8728
|
"UNWATCH",
|
|
8696
|
-
"WATCH"
|
|
8697
|
-
"XREAD",
|
|
8698
|
-
"XREADGROUP"
|
|
8729
|
+
"WATCH"
|
|
8699
8730
|
]);
|
|
8700
8731
|
function httpCommandDisposition(name) {
|
|
8701
8732
|
const normalized = name.toUpperCase();
|
|
8702
8733
|
return nativeOnlyCommands.has(normalized) || sessionOnlyCommands.has(normalized) ? "native_only" : "supported";
|
|
8703
8734
|
}
|
|
8704
8735
|
function assertHTTPCommandSupported(name) {
|
|
8705
|
-
|
|
8706
|
-
if (
|
|
8707
|
-
|
|
8736
|
+
const normalized = normalizedCommandName(name);
|
|
8737
|
+
if (normalized == null || normalized === "") throw new TypeError("HTTP command must have a name");
|
|
8738
|
+
if (sessionOnlyCommands.has(normalized)) {
|
|
8739
|
+
throw new InvalidCommandError(`${normalized} requires a persistent native TCP session`);
|
|
8740
|
+
}
|
|
8741
|
+
if (nativeOnlyCommands.has(normalized)) {
|
|
8742
|
+
throw new InvalidCommandError(`${normalized} is a native TCP transport control command`);
|
|
8743
|
+
}
|
|
8744
|
+
}
|
|
8745
|
+
function normalizedCommandName(value) {
|
|
8746
|
+
if (typeof value === "string") return value.toUpperCase();
|
|
8747
|
+
if (import_node_buffer33.Buffer.isBuffer(value) || value instanceof Uint8Array) {
|
|
8748
|
+
return import_node_buffer33.Buffer.from(value).toString("utf8").toUpperCase();
|
|
8708
8749
|
}
|
|
8750
|
+
return void 0;
|
|
8709
8751
|
}
|
|
8710
8752
|
|
|
8711
8753
|
// src/http-envelope.ts
|
|
8712
|
-
var
|
|
8754
|
+
var import_node_buffer34 = require("buffer");
|
|
8713
8755
|
var encoding = "ferricstore-json-v1";
|
|
8714
8756
|
var bytesMarker = "$ferricstore_bytes";
|
|
8715
8757
|
var mapMarker = "$ferricstore_map";
|
|
8716
8758
|
var maxDepth = 64;
|
|
8717
|
-
|
|
8718
|
-
|
|
8759
|
+
var integerJSON = /^-?(?:0|[1-9][0-9]*)$/u;
|
|
8760
|
+
var bytesMarkerBaseBytes = import_node_buffer34.Buffer.byteLength(bytesMarker) + 7;
|
|
8761
|
+
var mapMarkerBaseBytes = import_node_buffer34.Buffer.byteLength(mapMarker) + 7;
|
|
8762
|
+
function encodeHTTPCommands(commands, maxBytes = Number.MAX_SAFE_INTEGER) {
|
|
8763
|
+
const budget = { remaining: maxBytes };
|
|
8764
|
+
return import_node_buffer34.Buffer.from(JSON.stringify({
|
|
8719
8765
|
encoding,
|
|
8720
|
-
commands: commands.map((command) => encodeValue(command, 0))
|
|
8766
|
+
commands: commands.map((command) => encodeValue(command, 0, budget))
|
|
8721
8767
|
}));
|
|
8722
8768
|
}
|
|
8723
8769
|
function decodeHTTPEnvelope(source) {
|
|
8724
8770
|
let parsed;
|
|
8725
8771
|
try {
|
|
8726
|
-
parsed = JSON.parse(source.toString("utf8"));
|
|
8772
|
+
parsed = JSON.parse(source.toString("utf8"), preserveIntegerPrecision);
|
|
8727
8773
|
} catch (error) {
|
|
8728
8774
|
throw new TypeError("invalid HTTP command response JSON", { cause: error });
|
|
8729
8775
|
}
|
|
8730
8776
|
if (!isRecord(parsed)) throw new TypeError("HTTP command response must be an object");
|
|
8731
8777
|
return decodePlainRecord(parsed, 0);
|
|
8732
8778
|
}
|
|
8733
|
-
function
|
|
8779
|
+
function preserveIntegerPrecision(_key, value, context) {
|
|
8780
|
+
if (typeof value !== "number" || Number.isSafeInteger(value) || !Number.isInteger(value)) {
|
|
8781
|
+
return value;
|
|
8782
|
+
}
|
|
8783
|
+
const literal = context?.source;
|
|
8784
|
+
return literal != null && integerJSON.test(literal) ? BigInt(literal) : value;
|
|
8785
|
+
}
|
|
8786
|
+
function encodeValue(value, depth, budget) {
|
|
8734
8787
|
if (depth > maxDepth) throw new TypeError("HTTP command value exceeds maximum depth");
|
|
8735
|
-
if (value == null
|
|
8736
|
-
|
|
8737
|
-
return
|
|
8788
|
+
if (value == null) {
|
|
8789
|
+
consumeBudget(budget, 1);
|
|
8790
|
+
return value;
|
|
8791
|
+
}
|
|
8792
|
+
if (typeof value === "string") {
|
|
8793
|
+
consumeBudget(budget, import_node_buffer34.Buffer.byteLength(value) + 2);
|
|
8794
|
+
return value;
|
|
8795
|
+
}
|
|
8796
|
+
if (typeof value === "boolean") {
|
|
8797
|
+
consumeBudget(budget, 1);
|
|
8798
|
+
return value;
|
|
8799
|
+
}
|
|
8800
|
+
if (import_node_buffer34.Buffer.isBuffer(value) || value instanceof Uint8Array) {
|
|
8801
|
+
consumeBudget(budget, bytesMarkerBaseBytes + 4 * Math.ceil(value.byteLength / 3));
|
|
8802
|
+
return { [bytesMarker]: import_node_buffer34.Buffer.from(value).toString("base64") };
|
|
8738
8803
|
}
|
|
8739
8804
|
if (typeof value === "number") {
|
|
8740
8805
|
if (!Number.isFinite(value)) throw new TypeError("HTTP command numbers must be finite");
|
|
8806
|
+
consumeBudget(budget, 1);
|
|
8741
8807
|
return value;
|
|
8742
8808
|
}
|
|
8743
8809
|
if (typeof value === "bigint") {
|
|
8744
|
-
|
|
8810
|
+
const encoded = value >= BigInt(Number.MIN_SAFE_INTEGER) && value <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(value) : value.toString();
|
|
8811
|
+
consumeBudget(budget, typeof encoded === "number" ? 1 : import_node_buffer34.Buffer.byteLength(encoded) + 2);
|
|
8812
|
+
return encoded;
|
|
8813
|
+
}
|
|
8814
|
+
if (Array.isArray(value)) {
|
|
8815
|
+
consumeBudget(budget, 2 + Math.max(0, value.length - 1));
|
|
8816
|
+
return denseArray(value, depth + 1, (item, itemDepth) => encodeValue(item, itemDepth, budget));
|
|
8745
8817
|
}
|
|
8746
|
-
if (Array.isArray(value)) return denseArray(value, depth + 1, encodeValue);
|
|
8747
8818
|
if (value instanceof Map) {
|
|
8748
|
-
|
|
8749
|
-
|
|
8750
|
-
|
|
8751
|
-
|
|
8819
|
+
consumeBudget(budget, mapMarkerBaseBytes + value.size);
|
|
8820
|
+
const pairs = [];
|
|
8821
|
+
for (const [key, item] of value.entries()) {
|
|
8822
|
+
pairs.push([
|
|
8823
|
+
encodeValue(key, depth + 1, budget),
|
|
8824
|
+
encodeValue(item, depth + 1, budget)
|
|
8825
|
+
]);
|
|
8826
|
+
}
|
|
8827
|
+
return { [mapMarker]: pairs };
|
|
8752
8828
|
}
|
|
8753
8829
|
if (isRecord(value)) {
|
|
8754
|
-
|
|
8755
|
-
|
|
8756
|
-
|
|
8830
|
+
const keys = Object.keys(value);
|
|
8831
|
+
consumeBudget(budget, mapMarkerBaseBytes + keys.length);
|
|
8832
|
+
return { [mapMarker]: keys.map((key) => [
|
|
8833
|
+
encodeValue(key, depth + 1, budget),
|
|
8834
|
+
encodeValue(value[key], depth + 1, budget)
|
|
8757
8835
|
]) };
|
|
8758
8836
|
}
|
|
8759
8837
|
throw new TypeError(`unsupported HTTP command value: ${typeof value}`);
|
|
@@ -8779,15 +8857,28 @@ function decodeBase64(value) {
|
|
|
8779
8857
|
if (value.length % 4 !== 0 || !/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value)) {
|
|
8780
8858
|
throw new TypeError("invalid HTTP bytes marker");
|
|
8781
8859
|
}
|
|
8782
|
-
const decoded =
|
|
8860
|
+
const decoded = import_node_buffer34.Buffer.from(value, "base64");
|
|
8783
8861
|
if (decoded.toString("base64") !== value) throw new TypeError("invalid HTTP bytes marker");
|
|
8784
8862
|
return decoded;
|
|
8785
8863
|
}
|
|
8786
8864
|
function decodePlainRecord(value, depth) {
|
|
8787
8865
|
const result = {};
|
|
8788
|
-
for (const [key, item] of Object.entries(value))
|
|
8866
|
+
for (const [key, item] of Object.entries(value)) {
|
|
8867
|
+
Object.defineProperty(result, key, {
|
|
8868
|
+
configurable: true,
|
|
8869
|
+
enumerable: true,
|
|
8870
|
+
value: decodeValue2(item, depth),
|
|
8871
|
+
writable: true
|
|
8872
|
+
});
|
|
8873
|
+
}
|
|
8789
8874
|
return result;
|
|
8790
8875
|
}
|
|
8876
|
+
function consumeBudget(budget, amount) {
|
|
8877
|
+
if (amount > budget.remaining) {
|
|
8878
|
+
throw new HTTPTransportError("HTTP command request exceeds maxRequestBytes");
|
|
8879
|
+
}
|
|
8880
|
+
budget.remaining -= amount;
|
|
8881
|
+
}
|
|
8791
8882
|
function denseArray(values, depth, transform) {
|
|
8792
8883
|
const result = new Array(values.length);
|
|
8793
8884
|
for (let index = 0; index < values.length; index += 1) {
|
|
@@ -8797,10 +8888,12 @@ function denseArray(values, depth, transform) {
|
|
|
8797
8888
|
return result;
|
|
8798
8889
|
}
|
|
8799
8890
|
function isRecord(value) {
|
|
8800
|
-
return typeof value === "object" && value != null && !Array.isArray(value) && !
|
|
8891
|
+
return typeof value === "object" && value != null && !Array.isArray(value) && !import_node_buffer34.Buffer.isBuffer(value);
|
|
8801
8892
|
}
|
|
8802
8893
|
|
|
8803
8894
|
// src/http-options.ts
|
|
8895
|
+
var import_node_buffer35 = require("buffer");
|
|
8896
|
+
var import_node_http = require("http");
|
|
8804
8897
|
function normalizeHTTPOptions(value, options) {
|
|
8805
8898
|
const url = new URL(value);
|
|
8806
8899
|
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
@@ -8826,10 +8919,10 @@ function normalizeHTTPOptions(value, options) {
|
|
|
8826
8919
|
});
|
|
8827
8920
|
}
|
|
8828
8921
|
function normalizedHeaders(source) {
|
|
8829
|
-
const headers =
|
|
8922
|
+
const headers = /* @__PURE__ */ Object.create(null);
|
|
8830
8923
|
for (const [rawName, value] of Object.entries(source)) {
|
|
8831
8924
|
const name = rawName.toLowerCase();
|
|
8832
|
-
if (
|
|
8925
|
+
if (typeof value !== "string" || !validHeader(name, value)) {
|
|
8833
8926
|
throw new TypeError(`invalid HTTP header: ${rawName}`);
|
|
8834
8927
|
}
|
|
8835
8928
|
headers[name] = value;
|
|
@@ -8841,7 +8934,9 @@ function authorizationHeader(url, options, custom) {
|
|
|
8841
8934
|
const count = Number(custom != null) + Number(options.bearerToken != null) + Number(basic);
|
|
8842
8935
|
if (count > 1) throw new TypeError("HTTP credentials are mutually exclusive");
|
|
8843
8936
|
if (options.bearerToken != null) {
|
|
8844
|
-
if (
|
|
8937
|
+
if (options.bearerToken === "" || !validHeader("authorization", `Bearer ${options.bearerToken}`)) {
|
|
8938
|
+
throw new TypeError("invalid bearer token");
|
|
8939
|
+
}
|
|
8845
8940
|
return `Bearer ${options.bearerToken}`;
|
|
8846
8941
|
}
|
|
8847
8942
|
if (!basic) return custom;
|
|
@@ -8851,7 +8946,7 @@ function authorizationHeader(url, options, custom) {
|
|
|
8851
8946
|
if (username === "" || username.includes(":") || !safeHeader(username) || !safeHeader(options.password)) {
|
|
8852
8947
|
throw new TypeError("invalid Basic authentication credentials");
|
|
8853
8948
|
}
|
|
8854
|
-
return `Basic ${Buffer.from(`${username}:${options.password}`).toString("base64")}`;
|
|
8949
|
+
return `Basic ${import_node_buffer35.Buffer.from(`${username}:${options.password}`).toString("base64")}`;
|
|
8855
8950
|
}
|
|
8856
8951
|
function positiveInteger(value, fallback, name) {
|
|
8857
8952
|
const result = value ?? fallback;
|
|
@@ -8871,36 +8966,167 @@ function booleanOption(value, fallback, name) {
|
|
|
8871
8966
|
function safeHeader(value) {
|
|
8872
8967
|
return !value.includes("\r") && !value.includes("\n");
|
|
8873
8968
|
}
|
|
8969
|
+
function validHeader(name, value) {
|
|
8970
|
+
try {
|
|
8971
|
+
(0, import_node_http.validateHeaderName)(name);
|
|
8972
|
+
(0, import_node_http.validateHeaderValue)(name, value);
|
|
8973
|
+
return true;
|
|
8974
|
+
} catch {
|
|
8975
|
+
return false;
|
|
8976
|
+
}
|
|
8977
|
+
}
|
|
8874
8978
|
|
|
8875
8979
|
// src/http-transport.ts
|
|
8876
|
-
var
|
|
8877
|
-
var
|
|
8980
|
+
var import_node_http2 = __toESM(require("http"), 1);
|
|
8981
|
+
var import_node_http22 = __toESM(require("http2"), 1);
|
|
8878
8982
|
var import_node_https = __toESM(require("https"), 1);
|
|
8879
|
-
var
|
|
8983
|
+
var import_node_buffer36 = require("buffer");
|
|
8984
|
+
|
|
8985
|
+
// src/http2-slot-pool.ts
|
|
8986
|
+
var HTTP2SessionRetiredError = class extends Error {
|
|
8987
|
+
constructor(message, cause) {
|
|
8988
|
+
super(message, { cause });
|
|
8989
|
+
this.name = "HTTP2SessionRetiredError";
|
|
8990
|
+
}
|
|
8991
|
+
};
|
|
8992
|
+
var HTTP2SlotPool = class {
|
|
8993
|
+
active = 0;
|
|
8994
|
+
idleCallback;
|
|
8995
|
+
limit;
|
|
8996
|
+
retiredError;
|
|
8997
|
+
waiterHead;
|
|
8998
|
+
waiterTail;
|
|
8999
|
+
acquire(signal) {
|
|
9000
|
+
if (signal.aborted) return Promise.reject(signalAbortError(signal));
|
|
9001
|
+
if (this.retiredError != null) return Promise.reject(this.retiredError);
|
|
9002
|
+
if (this.limit != null && this.active < this.limit) {
|
|
9003
|
+
this.active += 1;
|
|
9004
|
+
return Promise.resolve(this.releaseOnce());
|
|
9005
|
+
}
|
|
9006
|
+
return new Promise((resolve, reject) => {
|
|
9007
|
+
const waiter = {
|
|
9008
|
+
abort: () => {
|
|
9009
|
+
if (waiter.settled) return;
|
|
9010
|
+
waiter.settled = true;
|
|
9011
|
+
this.removeWaiter(waiter);
|
|
9012
|
+
reject(signalAbortError(signal));
|
|
9013
|
+
},
|
|
9014
|
+
queued: true,
|
|
9015
|
+
reject,
|
|
9016
|
+
resolve,
|
|
9017
|
+
settled: false,
|
|
9018
|
+
signal
|
|
9019
|
+
};
|
|
9020
|
+
this.enqueueWaiter(waiter);
|
|
9021
|
+
signal.addEventListener("abort", waiter.abort, { once: true });
|
|
9022
|
+
});
|
|
9023
|
+
}
|
|
9024
|
+
updateLimit(limit) {
|
|
9025
|
+
if (this.retiredError != null) return;
|
|
9026
|
+
this.limit = limit;
|
|
9027
|
+
this.drain();
|
|
9028
|
+
}
|
|
9029
|
+
retire(error) {
|
|
9030
|
+
if (this.retiredError != null) return;
|
|
9031
|
+
this.retiredError = error;
|
|
9032
|
+
while (this.waiterHead != null) {
|
|
9033
|
+
const waiter = this.waiterHead;
|
|
9034
|
+
this.removeWaiter(waiter);
|
|
9035
|
+
if (waiter.settled) continue;
|
|
9036
|
+
waiter.settled = true;
|
|
9037
|
+
waiter.signal.removeEventListener("abort", waiter.abort);
|
|
9038
|
+
waiter.reject(error);
|
|
9039
|
+
}
|
|
9040
|
+
}
|
|
9041
|
+
whenIdle(callback) {
|
|
9042
|
+
if (this.active === 0) callback();
|
|
9043
|
+
else this.idleCallback = callback;
|
|
9044
|
+
}
|
|
9045
|
+
drain() {
|
|
9046
|
+
while (this.retiredError == null && this.limit != null && this.active < this.limit) {
|
|
9047
|
+
const waiter = this.waiterHead;
|
|
9048
|
+
if (waiter == null) return;
|
|
9049
|
+
this.removeWaiter(waiter);
|
|
9050
|
+
if (waiter.settled) continue;
|
|
9051
|
+
waiter.settled = true;
|
|
9052
|
+
waiter.signal.removeEventListener("abort", waiter.abort);
|
|
9053
|
+
this.active += 1;
|
|
9054
|
+
waiter.resolve(this.releaseOnce());
|
|
9055
|
+
}
|
|
9056
|
+
}
|
|
9057
|
+
enqueueWaiter(waiter) {
|
|
9058
|
+
waiter.previous = this.waiterTail;
|
|
9059
|
+
if (this.waiterTail == null) this.waiterHead = waiter;
|
|
9060
|
+
else this.waiterTail.next = waiter;
|
|
9061
|
+
this.waiterTail = waiter;
|
|
9062
|
+
}
|
|
9063
|
+
removeWaiter(waiter) {
|
|
9064
|
+
if (!waiter.queued) return;
|
|
9065
|
+
if (waiter.previous == null) this.waiterHead = waiter.next;
|
|
9066
|
+
else waiter.previous.next = waiter.next;
|
|
9067
|
+
if (waiter.next == null) this.waiterTail = waiter.previous;
|
|
9068
|
+
else waiter.next.previous = waiter.previous;
|
|
9069
|
+
waiter.next = void 0;
|
|
9070
|
+
waiter.previous = void 0;
|
|
9071
|
+
waiter.queued = false;
|
|
9072
|
+
}
|
|
9073
|
+
releaseOnce() {
|
|
9074
|
+
let released = false;
|
|
9075
|
+
return () => {
|
|
9076
|
+
if (released) return;
|
|
9077
|
+
released = true;
|
|
9078
|
+
this.active -= 1;
|
|
9079
|
+
this.drain();
|
|
9080
|
+
if (this.active === 0) {
|
|
9081
|
+
const callback = this.idleCallback;
|
|
9082
|
+
this.idleCallback = void 0;
|
|
9083
|
+
callback?.();
|
|
9084
|
+
}
|
|
9085
|
+
};
|
|
9086
|
+
}
|
|
9087
|
+
};
|
|
9088
|
+
function signalAbortError(signal) {
|
|
9089
|
+
return signal.reason instanceof Error ? signal.reason : new HTTPTransportError("HTTP request was aborted", { raw: signal.reason });
|
|
9090
|
+
}
|
|
9091
|
+
|
|
9092
|
+
// src/http-transport.ts
|
|
8880
9093
|
var HTTPTransport = class {
|
|
8881
9094
|
constructor(config) {
|
|
8882
9095
|
this.config = config;
|
|
8883
|
-
this.#httpAgent = new
|
|
9096
|
+
this.#httpAgent = new import_node_http2.default.Agent({
|
|
9097
|
+
keepAlive: true,
|
|
9098
|
+
maxFreeSockets: config.maxConnections,
|
|
9099
|
+
maxSockets: config.maxConnections,
|
|
9100
|
+
maxTotalSockets: config.maxConnections
|
|
9101
|
+
});
|
|
8884
9102
|
this.#httpsAgent = new import_node_https.default.Agent({
|
|
8885
9103
|
...config.tlsOptions,
|
|
8886
9104
|
keepAlive: true,
|
|
8887
|
-
|
|
9105
|
+
maxFreeSockets: config.maxConnections,
|
|
9106
|
+
maxSockets: config.maxConnections,
|
|
9107
|
+
maxTotalSockets: config.maxConnections
|
|
8888
9108
|
});
|
|
8889
9109
|
}
|
|
8890
9110
|
config;
|
|
8891
9111
|
#httpAgent;
|
|
8892
9112
|
#httpsAgent;
|
|
9113
|
+
#allSessions = /* @__PURE__ */ new Set();
|
|
8893
9114
|
#sessions = /* @__PURE__ */ new Map();
|
|
9115
|
+
#sessionSlots = /* @__PURE__ */ new WeakMap();
|
|
9116
|
+
#requests = /* @__PURE__ */ new Set();
|
|
8894
9117
|
#closed = false;
|
|
8895
|
-
async post(body) {
|
|
9118
|
+
async post(body, timeoutMs) {
|
|
8896
9119
|
if (this.#closed) throw new HTTPTransportError("HTTP transport is closed");
|
|
8897
9120
|
const controller = new AbortController();
|
|
8898
|
-
|
|
9121
|
+
this.#requests.add(controller);
|
|
9122
|
+
const timer = timeoutMs == null ? void 0 : setLongTimeout(() => controller.abort(requestTimeoutReason), timeoutMs);
|
|
9123
|
+
timer?.unref();
|
|
8899
9124
|
try {
|
|
8900
9125
|
return await this.request(this.config.commandUrl, "POST", body, 0, controller.signal);
|
|
8901
9126
|
} catch (error) {
|
|
8902
9127
|
if (controller.signal.aborted) {
|
|
8903
|
-
|
|
9128
|
+
if (controller.signal.reason instanceof HTTPTransportError) throw controller.signal.reason;
|
|
9129
|
+
throw new RequestTimeoutError(timeoutMs ?? this.config.timeoutMs, "possibly_sent", {
|
|
8904
9130
|
cause: error,
|
|
8905
9131
|
raw: { retryable: true, safe_to_retry: false }
|
|
8906
9132
|
});
|
|
@@ -8912,15 +9138,19 @@ var HTTPTransport = class {
|
|
|
8912
9138
|
safeToRetry: false
|
|
8913
9139
|
});
|
|
8914
9140
|
} finally {
|
|
8915
|
-
|
|
9141
|
+
timer?.cancel();
|
|
9142
|
+
this.#requests.delete(controller);
|
|
8916
9143
|
}
|
|
8917
9144
|
}
|
|
8918
9145
|
async close() {
|
|
8919
9146
|
if (this.#closed) return;
|
|
8920
9147
|
this.#closed = true;
|
|
9148
|
+
const error = new HTTPTransportError("HTTP transport is closed");
|
|
9149
|
+
for (const controller of this.#requests) controller.abort(error);
|
|
8921
9150
|
this.#httpAgent.destroy();
|
|
8922
9151
|
this.#httpsAgent.destroy();
|
|
8923
|
-
for (const session of this.#
|
|
9152
|
+
for (const session of this.#allSessions) session.destroy();
|
|
9153
|
+
this.#allSessions.clear();
|
|
8924
9154
|
this.#sessions.clear();
|
|
8925
9155
|
}
|
|
8926
9156
|
async request(url, method, body, redirects, signal) {
|
|
@@ -8943,7 +9173,7 @@ var HTTPTransport = class {
|
|
|
8943
9173
|
);
|
|
8944
9174
|
}
|
|
8945
9175
|
async http1Request(url, method, body, signal) {
|
|
8946
|
-
const request = url.protocol === "https:" ? import_node_https.default.request :
|
|
9176
|
+
const request = url.protocol === "https:" ? import_node_https.default.request : import_node_http2.default.request;
|
|
8947
9177
|
const agent = url.protocol === "https:" ? this.#httpsAgent : this.#httpAgent;
|
|
8948
9178
|
const headers = this.requestHeaders(body);
|
|
8949
9179
|
return await new Promise((resolve, reject) => {
|
|
@@ -8968,7 +9198,6 @@ var HTTPTransport = class {
|
|
|
8968
9198
|
);
|
|
8969
9199
|
}
|
|
8970
9200
|
async http2Request(url, method, body, signal) {
|
|
8971
|
-
const session = this.session(url);
|
|
8972
9201
|
const headers = {
|
|
8973
9202
|
...this.requestHeaders(body),
|
|
8974
9203
|
":authority": url.host,
|
|
@@ -8976,10 +9205,43 @@ var HTTPTransport = class {
|
|
|
8976
9205
|
":path": `${url.pathname}${url.search}`,
|
|
8977
9206
|
":scheme": url.protocol.slice(0, -1)
|
|
8978
9207
|
};
|
|
9208
|
+
if (signal.aborted) throw signalAbortError(signal);
|
|
9209
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
9210
|
+
const session = this.session(url);
|
|
9211
|
+
let release;
|
|
9212
|
+
try {
|
|
9213
|
+
release = await this.slotPool(session).acquire(signal);
|
|
9214
|
+
} catch (error) {
|
|
9215
|
+
if (attempt === 0 && error instanceof HTTP2SessionRetiredError && !signal.aborted) continue;
|
|
9216
|
+
throw error;
|
|
9217
|
+
}
|
|
9218
|
+
try {
|
|
9219
|
+
let stream;
|
|
9220
|
+
try {
|
|
9221
|
+
stream = session.request(headers);
|
|
9222
|
+
} catch (error) {
|
|
9223
|
+
if (attempt === 0 && retryableSessionOpenError(error) && !signal.aborted) {
|
|
9224
|
+
this.retireSession(url.origin, session, true, error);
|
|
9225
|
+
continue;
|
|
9226
|
+
}
|
|
9227
|
+
throw error;
|
|
9228
|
+
}
|
|
9229
|
+
try {
|
|
9230
|
+
return await this.collectHttp2(stream, body, signal);
|
|
9231
|
+
} catch (error) {
|
|
9232
|
+
if (attempt === 0 && refusedStreamError(error) && !signal.aborted) continue;
|
|
9233
|
+
throw error;
|
|
9234
|
+
}
|
|
9235
|
+
} finally {
|
|
9236
|
+
release();
|
|
9237
|
+
}
|
|
9238
|
+
}
|
|
9239
|
+
throw new HTTPTransportError("HTTP/2 session could not accept the request");
|
|
9240
|
+
}
|
|
9241
|
+
async collectHttp2(stream, body, signal) {
|
|
8979
9242
|
return await new Promise((resolve, reject) => {
|
|
8980
|
-
const stream = session.request(headers);
|
|
8981
9243
|
let responseHeaders = {};
|
|
8982
|
-
const abort = () => stream.close(
|
|
9244
|
+
const abort = () => stream.close(import_node_http22.default.constants.NGHTTP2_CANCEL);
|
|
8983
9245
|
signal.addEventListener("abort", abort, { once: true });
|
|
8984
9246
|
stream.once("response", (value) => responseHeaders = value);
|
|
8985
9247
|
stream.once("error", reject);
|
|
@@ -8987,19 +9249,60 @@ var HTTPTransport = class {
|
|
|
8987
9249
|
const status = Number(responseHeaders[":status"] ?? 0);
|
|
8988
9250
|
resolve({ body: response.body, headers: normalizeHeaders(responseHeaders), status });
|
|
8989
9251
|
}, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
8990
|
-
|
|
9252
|
+
if (signal.aborted) abort();
|
|
9253
|
+
else stream.end(body);
|
|
8991
9254
|
});
|
|
8992
9255
|
}
|
|
8993
9256
|
session(url) {
|
|
8994
9257
|
const origin = url.origin;
|
|
8995
9258
|
const current = this.#sessions.get(origin);
|
|
8996
9259
|
if (current != null && !current.closed && !current.destroyed) return current;
|
|
8997
|
-
const session =
|
|
8998
|
-
|
|
8999
|
-
|
|
9260
|
+
const session = import_node_http22.default.connect(origin, {
|
|
9261
|
+
...this.config.tlsOptions,
|
|
9262
|
+
settings: { enablePush: false }
|
|
9263
|
+
});
|
|
9264
|
+
const slots = new HTTP2SlotPool();
|
|
9265
|
+
this.#allSessions.add(session);
|
|
9266
|
+
this.#sessionSlots.set(session, slots);
|
|
9267
|
+
session.on("remoteSettings", (settings) => {
|
|
9268
|
+
const remoteLimit = settings.maxConcurrentStreams;
|
|
9269
|
+
const limit = typeof remoteLimit === "number" && Number.isFinite(remoteLimit) ? Math.max(0, Math.floor(remoteLimit)) : this.config.maxConnections;
|
|
9270
|
+
slots.updateLimit(Math.min(this.config.maxConnections, limit));
|
|
9271
|
+
});
|
|
9272
|
+
session.on("error", (error) => this.retireSession(origin, session, true, error));
|
|
9273
|
+
session.once("goaway", () => {
|
|
9274
|
+
this.retireSession(
|
|
9275
|
+
origin,
|
|
9276
|
+
session,
|
|
9277
|
+
"when_idle",
|
|
9278
|
+
new HTTP2SessionRetiredError("HTTP/2 session received GOAWAY")
|
|
9279
|
+
);
|
|
9280
|
+
});
|
|
9281
|
+
session.once("close", () => {
|
|
9282
|
+
if (session.destroyed) this.#allSessions.delete(session);
|
|
9283
|
+
this.retireSession(origin, session);
|
|
9284
|
+
});
|
|
9000
9285
|
this.#sessions.set(origin, session);
|
|
9001
9286
|
return session;
|
|
9002
9287
|
}
|
|
9288
|
+
retireSession(origin, session, destroy = false, cause) {
|
|
9289
|
+
if (this.#sessions.get(origin) === session) this.#sessions.delete(origin);
|
|
9290
|
+
const slots = this.#sessionSlots.get(session);
|
|
9291
|
+
slots?.retire(
|
|
9292
|
+
cause instanceof HTTP2SessionRetiredError ? cause : new HTTP2SessionRetiredError("HTTP/2 session is unavailable", cause)
|
|
9293
|
+
);
|
|
9294
|
+
if (destroy === true && !session.destroyed) session.destroy();
|
|
9295
|
+
else if (destroy === "when_idle") {
|
|
9296
|
+
slots?.whenIdle(() => {
|
|
9297
|
+
if (!session.destroyed) session.destroy();
|
|
9298
|
+
});
|
|
9299
|
+
}
|
|
9300
|
+
}
|
|
9301
|
+
slotPool(session) {
|
|
9302
|
+
const slots = this.#sessionSlots.get(session);
|
|
9303
|
+
if (slots == null) throw new HTTP2SessionRetiredError("HTTP/2 session is unavailable");
|
|
9304
|
+
return slots;
|
|
9305
|
+
}
|
|
9003
9306
|
requestHeaders(body) {
|
|
9004
9307
|
const headers = { ...this.config.headers };
|
|
9005
9308
|
delete headers["content-length"];
|
|
@@ -9011,11 +9314,21 @@ var HTTPTransport = class {
|
|
|
9011
9314
|
};
|
|
9012
9315
|
}
|
|
9013
9316
|
};
|
|
9317
|
+
var requestTimeoutReason = /* @__PURE__ */ Symbol("ferricstore-http-request-timeout");
|
|
9318
|
+
function retryableSessionOpenError(error) {
|
|
9319
|
+
if (typeof error !== "object" || error == null || !("code" in error)) return false;
|
|
9320
|
+
const code = error.code;
|
|
9321
|
+
return code === "ERR_HTTP2_GOAWAY_SESSION" || code === "ERR_HTTP2_INVALID_SESSION";
|
|
9322
|
+
}
|
|
9323
|
+
function refusedStreamError(error) {
|
|
9324
|
+
if (!(error instanceof Error)) return false;
|
|
9325
|
+
return error.code === "ERR_HTTP2_STREAM_ERROR" && error.message.includes("NGHTTP2_REFUSED_STREAM");
|
|
9326
|
+
}
|
|
9014
9327
|
async function collectBody(source, status, headers, maximum) {
|
|
9015
9328
|
const chunks = [];
|
|
9016
9329
|
let size = 0;
|
|
9017
9330
|
for await (const chunk of source) {
|
|
9018
|
-
const bytes2 =
|
|
9331
|
+
const bytes2 = import_node_buffer36.Buffer.from(chunk);
|
|
9019
9332
|
size += bytes2.byteLength;
|
|
9020
9333
|
if (size > maximum) {
|
|
9021
9334
|
const destroy = source.destroy;
|
|
@@ -9024,10 +9337,10 @@ async function collectBody(source, status, headers, maximum) {
|
|
|
9024
9337
|
}
|
|
9025
9338
|
chunks.push(bytes2);
|
|
9026
9339
|
}
|
|
9027
|
-
return { body:
|
|
9340
|
+
return { body: import_node_buffer36.Buffer.concat(chunks, size), headers, status };
|
|
9028
9341
|
}
|
|
9029
9342
|
function normalizeHeaders(headers) {
|
|
9030
|
-
const result =
|
|
9343
|
+
const result = /* @__PURE__ */ Object.create(null);
|
|
9031
9344
|
for (const [name, raw] of Object.entries(headers)) {
|
|
9032
9345
|
const value = headerValue(raw);
|
|
9033
9346
|
if (value != null) result[name.toLowerCase()] = value;
|
|
@@ -9079,11 +9392,16 @@ var HTTPAdapter = class _HTTPAdapter {
|
|
|
9079
9392
|
throw new HTTPTransportError("HTTP command batch exceeds maxBatchItems");
|
|
9080
9393
|
}
|
|
9081
9394
|
for (const command of commands) assertHTTPCommandSupported(command[0]);
|
|
9082
|
-
const
|
|
9395
|
+
const prepared = commands.map((command) => prepareHTTPCommand(command, this.#config.maxRequestBytes));
|
|
9396
|
+
const body = encodeHTTPCommands(prepared.map((command) => command.encoded), this.#config.maxRequestBytes);
|
|
9083
9397
|
if (body.byteLength > this.#config.maxRequestBytes) {
|
|
9084
9398
|
throw new HTTPTransportError("HTTP command request exceeds maxRequestBytes");
|
|
9085
9399
|
}
|
|
9086
|
-
const
|
|
9400
|
+
const serverBlockMs = combinedServerBlockMs(prepared.map((command) => command.serverBlockMs));
|
|
9401
|
+
const response = await this.#transport.post(
|
|
9402
|
+
body,
|
|
9403
|
+
serverResponseTimeoutMs(this.#config.timeoutMs, serverBlockMs)
|
|
9404
|
+
);
|
|
9087
9405
|
let envelope = {};
|
|
9088
9406
|
try {
|
|
9089
9407
|
if (response.body.byteLength > 0) envelope = decodeHTTPEnvelope(response.body);
|
|
@@ -9107,12 +9425,17 @@ var HTTPAdapter = class _HTTPAdapter {
|
|
|
9107
9425
|
var commandNamesByOpcode = new Map(
|
|
9108
9426
|
Object.entries(COMMAND_OPCODES).map(([name, opcode]) => [opcode, name])
|
|
9109
9427
|
);
|
|
9110
|
-
function
|
|
9428
|
+
function prepareHTTPCommand(command, maxRequestBytes) {
|
|
9111
9429
|
const protocol = buildProtocolCommand(command, maxRequestBytes, false);
|
|
9112
|
-
if (protocol.opcode === OPCODES.commandExec)
|
|
9430
|
+
if (protocol.opcode === OPCODES.commandExec) {
|
|
9431
|
+
return { encoded: command, serverBlockMs: protocol.serverBlockMs };
|
|
9432
|
+
}
|
|
9113
9433
|
const name = commandNamesByOpcode.get(protocol.opcode);
|
|
9114
9434
|
if (name == null) throw new HTTPTransportError(`HTTP command has unknown opcode ${protocol.opcode}`);
|
|
9115
|
-
return {
|
|
9435
|
+
return {
|
|
9436
|
+
encoded: { command: name, opcode: protocol.opcode, payload: protocol.payload ?? {} },
|
|
9437
|
+
serverBlockMs: protocol.serverBlockMs
|
|
9438
|
+
};
|
|
9116
9439
|
}
|
|
9117
9440
|
function validatedResult(value) {
|
|
9118
9441
|
if (!isRecord2(value)) throw new HTTPTransportError("HTTP response has an invalid result item");
|
|
@@ -9132,7 +9455,7 @@ function commandError(value) {
|
|
|
9132
9455
|
function topLevelError(status, envelope, retryAfter) {
|
|
9133
9456
|
const details = isRecord2(envelope.error) ? envelope.error : {};
|
|
9134
9457
|
const message = typeof details.message === "string" ? details.message : `HTTP command request failed with status ${status}`;
|
|
9135
|
-
const retryAfterMs2 =
|
|
9458
|
+
const retryAfterMs2 = retryAfterMilliseconds(retryAfter);
|
|
9136
9459
|
return new HTTPTransportError(message, {
|
|
9137
9460
|
raw: details,
|
|
9138
9461
|
retryable: status === 408 || status === 425 || status === 429 || status >= 500,
|
|
@@ -9141,6 +9464,18 @@ function topLevelError(status, envelope, retryAfter) {
|
|
|
9141
9464
|
statusCode: status
|
|
9142
9465
|
});
|
|
9143
9466
|
}
|
|
9467
|
+
function retryAfterMilliseconds(value) {
|
|
9468
|
+
if (value == null) return void 0;
|
|
9469
|
+
if (/^\d+$/u.test(value)) {
|
|
9470
|
+
const seconds = Number.parseInt(value, 10);
|
|
9471
|
+
const milliseconds2 = seconds * 1e3;
|
|
9472
|
+
return Number.isSafeInteger(milliseconds2) ? milliseconds2 : void 0;
|
|
9473
|
+
}
|
|
9474
|
+
const deadline = Date.parse(value);
|
|
9475
|
+
if (!Number.isFinite(deadline)) return void 0;
|
|
9476
|
+
const milliseconds = Math.max(0, deadline - Date.now());
|
|
9477
|
+
return Number.isSafeInteger(milliseconds) ? milliseconds : void 0;
|
|
9478
|
+
}
|
|
9144
9479
|
function isRecord2(value) {
|
|
9145
9480
|
return typeof value === "object" && value != null && !Array.isArray(value);
|
|
9146
9481
|
}
|
|
@@ -9153,10 +9488,10 @@ function executeCommandArgs(executor, args) {
|
|
|
9153
9488
|
}
|
|
9154
9489
|
|
|
9155
9490
|
// src/reconnecting-executor.ts
|
|
9156
|
-
var
|
|
9491
|
+
var import_node_buffer38 = require("buffer");
|
|
9157
9492
|
|
|
9158
9493
|
// src/command-retry-policy.ts
|
|
9159
|
-
var
|
|
9494
|
+
var import_node_buffer37 = require("buffer");
|
|
9160
9495
|
function isCasMutation(args) {
|
|
9161
9496
|
const offset = commandName2(args[0]) === "COMMAND_EXEC" ? 1 : 0;
|
|
9162
9497
|
const name = commandName2(args[offset]);
|
|
@@ -9170,8 +9505,8 @@ function isCasMutation(args) {
|
|
|
9170
9505
|
}
|
|
9171
9506
|
function commandName2(value) {
|
|
9172
9507
|
if (typeof value === "string") return value.toUpperCase();
|
|
9173
|
-
if (
|
|
9174
|
-
return
|
|
9508
|
+
if (import_node_buffer37.Buffer.isBuffer(value) || value instanceof Uint8Array) {
|
|
9509
|
+
return import_node_buffer37.Buffer.from(value).toString("utf8").toUpperCase();
|
|
9175
9510
|
}
|
|
9176
9511
|
return void 0;
|
|
9177
9512
|
}
|
|
@@ -9383,15 +9718,15 @@ function normalizeNonNegativeInteger2(value, fallback) {
|
|
|
9383
9718
|
}
|
|
9384
9719
|
|
|
9385
9720
|
// src/topology.ts
|
|
9386
|
-
var
|
|
9721
|
+
var import_node_buffer41 = require("buffer");
|
|
9387
9722
|
|
|
9388
9723
|
// src/topology-routing.ts
|
|
9389
|
-
var
|
|
9724
|
+
var import_node_buffer40 = require("buffer");
|
|
9390
9725
|
|
|
9391
9726
|
// src/flow-partition-route-cache.ts
|
|
9392
|
-
var
|
|
9727
|
+
var import_node_buffer39 = require("buffer");
|
|
9393
9728
|
var import_node_crypto = require("crypto");
|
|
9394
|
-
var AUTO_PREFIX =
|
|
9729
|
+
var AUTO_PREFIX = import_node_buffer39.Buffer.from("__flow_auto__:", "ascii");
|
|
9395
9730
|
var MAX_CACHEABLE_PARTITION_BYTES = 4 * 1024;
|
|
9396
9731
|
var MAX_CACHE_BYTES = 1 * 1024 * 1024;
|
|
9397
9732
|
var MAX_CACHE_ENTRIES = 1024;
|
|
@@ -9401,10 +9736,10 @@ var cacheBytes = 0;
|
|
|
9401
9736
|
var cacheHits = 0;
|
|
9402
9737
|
var cacheMisses = 0;
|
|
9403
9738
|
function flowLogicalPartitionRoutingKey(value) {
|
|
9404
|
-
if (typeof value !== "string" && !
|
|
9739
|
+
if (typeof value !== "string" && !import_node_buffer39.Buffer.isBuffer(value)) return void 0;
|
|
9405
9740
|
const autoBucket = flowAutoBucket(value);
|
|
9406
9741
|
if (autoBucket != null) return `{fa:${autoBucket}}`;
|
|
9407
|
-
const bytes2 =
|
|
9742
|
+
const bytes2 = import_node_buffer39.Buffer.isBuffer(value) ? value : import_node_buffer39.Buffer.from(value);
|
|
9408
9743
|
if (bytes2.byteLength > MAX_CACHEABLE_PARTITION_BYTES) return hashRoute(bytes2);
|
|
9409
9744
|
const cacheKey = bytes2.toString("base64");
|
|
9410
9745
|
const cached = routeCache.get(cacheKey);
|
|
@@ -9478,7 +9813,7 @@ function routingKeyFromProtocolPayload(name, command) {
|
|
|
9478
9813
|
"scope"
|
|
9479
9814
|
]) {
|
|
9480
9815
|
const value = getField(command.payload, field3);
|
|
9481
|
-
if (typeof value === "string" ||
|
|
9816
|
+
if (typeof value === "string" || import_node_buffer40.Buffer.isBuffer(value)) {
|
|
9482
9817
|
return value;
|
|
9483
9818
|
}
|
|
9484
9819
|
}
|
|
@@ -9526,7 +9861,7 @@ function flowRoutingData(name, args) {
|
|
|
9526
9861
|
if (typeof partition === "string" && partition.toUpperCase() !== "AUTO" && partition.toUpperCase() !== "MIXED") {
|
|
9527
9862
|
return flowRoutingResult(flowLogicalPartitionRoutingKey(partition));
|
|
9528
9863
|
}
|
|
9529
|
-
if (
|
|
9864
|
+
if (import_node_buffer40.Buffer.isBuffer(partition)) {
|
|
9530
9865
|
const text3 = partition.toString("utf8").toUpperCase();
|
|
9531
9866
|
if (text3 !== "AUTO" && text3 !== "MIXED") {
|
|
9532
9867
|
return flowRoutingResult(flowLogicalPartitionRoutingKey(partition));
|
|
@@ -9617,17 +9952,17 @@ function flowPartitionRoutingKeyFromCommand(command, claim) {
|
|
|
9617
9952
|
return { handled: false };
|
|
9618
9953
|
}
|
|
9619
9954
|
function isRoutingKey(value) {
|
|
9620
|
-
return typeof value === "string" ||
|
|
9955
|
+
return typeof value === "string" || import_node_buffer40.Buffer.isBuffer(value);
|
|
9621
9956
|
}
|
|
9622
9957
|
function flowAutoIdRoutingKey(value) {
|
|
9623
|
-
if (typeof value !== "string" && !
|
|
9958
|
+
if (typeof value !== "string" && !import_node_buffer40.Buffer.isBuffer(value)) {
|
|
9624
9959
|
return void 0;
|
|
9625
9960
|
}
|
|
9626
|
-
const bucket = (
|
|
9961
|
+
const bucket = (import_node_buffer40.Buffer.isBuffer(value) ? crc32(value) : crc32Utf8(value)) & 255;
|
|
9627
9962
|
return `{fa:${bucket}}`;
|
|
9628
9963
|
}
|
|
9629
9964
|
function flowClaimLogicalPartitionRoutingKey(value) {
|
|
9630
|
-
if (typeof value !== "string" && !
|
|
9965
|
+
if (typeof value !== "string" && !import_node_buffer40.Buffer.isBuffer(value)) return void 0;
|
|
9631
9966
|
const selector = commandPart(value);
|
|
9632
9967
|
if (selector === "AUTO" || selector === "ANY") return void 0;
|
|
9633
9968
|
if (selector === "GLOBAL") return "{f}";
|
|
@@ -9642,7 +9977,7 @@ function singleShardFlowClaimPartitionKey(values) {
|
|
|
9642
9977
|
return keys.some((key) => key == null) ? void 0 : singleShardKey(keys);
|
|
9643
9978
|
}
|
|
9644
9979
|
function singleShardKey(keys) {
|
|
9645
|
-
if (keys.length === 0 || keys.some((key) => typeof key !== "string" && !
|
|
9980
|
+
if (keys.length === 0 || keys.some((key) => typeof key !== "string" && !import_node_buffer40.Buffer.isBuffer(key))) {
|
|
9646
9981
|
return void 0;
|
|
9647
9982
|
}
|
|
9648
9983
|
const usable = keys;
|
|
@@ -9675,7 +10010,7 @@ function routedKeyGroups(keys, routeKey) {
|
|
|
9675
10010
|
const groups = /* @__PURE__ */ new Map();
|
|
9676
10011
|
for (let index = 0; index < keys.length; index += 1) {
|
|
9677
10012
|
const key = keys[index];
|
|
9678
|
-
if (typeof key !== "string" && !
|
|
10013
|
+
if (typeof key !== "string" && !import_node_buffer40.Buffer.isBuffer(key)) return void 0;
|
|
9679
10014
|
const route = routeKey(key);
|
|
9680
10015
|
const groupKey = `${route.endpointKey}\0${route.laneId}`;
|
|
9681
10016
|
const group = groups.get(groupKey);
|
|
@@ -10764,7 +11099,7 @@ var TopologyNativeAdapterPool = class _TopologyNativeAdapterPool {
|
|
|
10764
11099
|
};
|
|
10765
11100
|
|
|
10766
11101
|
// src/response-map-preservation.ts
|
|
10767
|
-
var
|
|
11102
|
+
var import_node_buffer42 = require("buffer");
|
|
10768
11103
|
function toStringKeyMapPreservingValues(value) {
|
|
10769
11104
|
if (value == null) return void 0;
|
|
10770
11105
|
const result = {};
|
|
@@ -10774,7 +11109,7 @@ function toStringKeyMapPreservingValues(value) {
|
|
|
10774
11109
|
}
|
|
10775
11110
|
return result;
|
|
10776
11111
|
}
|
|
10777
|
-
if (typeof value === "object" && !Array.isArray(value) && !
|
|
11112
|
+
if (typeof value === "object" && !Array.isArray(value) && !import_node_buffer42.Buffer.isBuffer(value) && !(value instanceof Uint8Array)) {
|
|
10778
11113
|
for (const [key, item] of Object.entries(value)) {
|
|
10779
11114
|
setOwnValue(result, text(key), normalizeMapStructurePreservingBytes(item));
|
|
10780
11115
|
}
|
|
@@ -10783,7 +11118,7 @@ function toStringKeyMapPreservingValues(value) {
|
|
|
10783
11118
|
return void 0;
|
|
10784
11119
|
}
|
|
10785
11120
|
function normalizeMapStructurePreservingBytes(value) {
|
|
10786
|
-
if (
|
|
11121
|
+
if (import_node_buffer42.Buffer.isBuffer(value) || value instanceof Uint8Array) return value;
|
|
10787
11122
|
if (value instanceof Map) {
|
|
10788
11123
|
const result = {};
|
|
10789
11124
|
for (const [key, item] of value.entries()) {
|
|
@@ -10805,7 +11140,7 @@ function normalizeMapStructurePreservingBytes(value) {
|
|
|
10805
11140
|
}
|
|
10806
11141
|
|
|
10807
11142
|
// src/native-kv-responses.ts
|
|
10808
|
-
var
|
|
11143
|
+
var import_node_buffer43 = require("buffer");
|
|
10809
11144
|
function rateLimitResultFromResp(value) {
|
|
10810
11145
|
if (!Array.isArray(value) || value.length !== 4) {
|
|
10811
11146
|
throw new TypeError("RATELIMIT.ADD returned an unexpected response");
|
|
@@ -10862,13 +11197,13 @@ function fetchOrComputeResultFromResp(value, codec) {
|
|
|
10862
11197
|
}
|
|
10863
11198
|
function decodePayload(codec, value) {
|
|
10864
11199
|
if (value == null) return null;
|
|
10865
|
-
if (
|
|
10866
|
-
if (value instanceof Uint8Array) return codec.decode(
|
|
10867
|
-
if (typeof value === "string") return codec.decode(
|
|
11200
|
+
if (import_node_buffer43.Buffer.isBuffer(value)) return codec.decode(value);
|
|
11201
|
+
if (value instanceof Uint8Array) return codec.decode(import_node_buffer43.Buffer.from(value));
|
|
11202
|
+
if (typeof value === "string") return codec.decode(import_node_buffer43.Buffer.from(value));
|
|
10868
11203
|
return normalizeRefMeta(value);
|
|
10869
11204
|
}
|
|
10870
11205
|
function requiredResponseString(value, context) {
|
|
10871
|
-
if (typeof value !== "string" && !
|
|
11206
|
+
if (typeof value !== "string" && !import_node_buffer43.Buffer.isBuffer(value) && !(value instanceof Uint8Array)) {
|
|
10872
11207
|
throw new TypeError(`${context} returned an unexpected response`);
|
|
10873
11208
|
}
|
|
10874
11209
|
const result = text(value);
|
|
@@ -10885,7 +11220,7 @@ function requiredNonNegativeInteger(value, context) {
|
|
|
10885
11220
|
return result;
|
|
10886
11221
|
}
|
|
10887
11222
|
function responseBytes(value, context) {
|
|
10888
|
-
if (typeof value !== "string" && !
|
|
11223
|
+
if (typeof value !== "string" && !import_node_buffer43.Buffer.isBuffer(value) && !(value instanceof Uint8Array)) {
|
|
10889
11224
|
throw new TypeError(`${context} returned an unexpected response`);
|
|
10890
11225
|
}
|
|
10891
11226
|
return bytes(value);
|
|
@@ -11568,7 +11903,7 @@ function groupAutoPartitionItems(items) {
|
|
|
11568
11903
|
}
|
|
11569
11904
|
|
|
11570
11905
|
// src/client-values.ts
|
|
11571
|
-
var
|
|
11906
|
+
var import_node_buffer44 = require("buffer");
|
|
11572
11907
|
async function valueMGetEntries(client, refs, options = {}) {
|
|
11573
11908
|
const refCount = refs.length;
|
|
11574
11909
|
if (refCount === 0) {
|
|
@@ -11603,12 +11938,12 @@ async function valueMGetEntries(client, refs, options = {}) {
|
|
|
11603
11938
|
const item = response[index];
|
|
11604
11939
|
if (item == null) {
|
|
11605
11940
|
entries[index] = { found: false };
|
|
11606
|
-
} else if (
|
|
11941
|
+
} else if (import_node_buffer44.Buffer.isBuffer(item)) {
|
|
11607
11942
|
entries[index] = { found: true, value: client.codec.decode(item) };
|
|
11608
11943
|
} else if (item instanceof Uint8Array) {
|
|
11609
|
-
entries[index] = { found: true, value: client.codec.decode(
|
|
11944
|
+
entries[index] = { found: true, value: client.codec.decode(import_node_buffer44.Buffer.from(item)) };
|
|
11610
11945
|
} else if (typeof item === "string") {
|
|
11611
|
-
entries[index] = { found: true, value: client.codec.decode(
|
|
11946
|
+
entries[index] = { found: true, value: client.codec.decode(import_node_buffer44.Buffer.from(item)) };
|
|
11612
11947
|
} else {
|
|
11613
11948
|
entries[index] = { found: true, value: item };
|
|
11614
11949
|
}
|
|
@@ -11617,10 +11952,10 @@ async function valueMGetEntries(client, refs, options = {}) {
|
|
|
11617
11952
|
}
|
|
11618
11953
|
|
|
11619
11954
|
// src/auto-batch.ts
|
|
11620
|
-
var
|
|
11955
|
+
var import_node_buffer46 = require("buffer");
|
|
11621
11956
|
|
|
11622
11957
|
// src/auto-batch-ordering.ts
|
|
11623
|
-
var
|
|
11958
|
+
var import_node_buffer45 = require("buffer");
|
|
11624
11959
|
function autoBatchOrderingPlan(batch) {
|
|
11625
11960
|
const accesses = /* @__PURE__ */ new Map();
|
|
11626
11961
|
const fallbackDependencies = [];
|
|
@@ -11735,13 +12070,13 @@ function flowManyAutoBatchIds(command, name) {
|
|
|
11735
12070
|
return fixedFlowItemIds(
|
|
11736
12071
|
command,
|
|
11737
12072
|
mixed ? 4 : 3,
|
|
11738
|
-
(itemIndex) => isAutoBatchResourceValue(command[itemIndex]) && (!mixed || isAutoBatchResourceValue(command[itemIndex + 1])) && isFencingToken(command[itemIndex + (mixed ? 2 : 1)]) &&
|
|
12073
|
+
(itemIndex) => isAutoBatchResourceValue(command[itemIndex]) && (!mixed || isAutoBatchResourceValue(command[itemIndex + 1])) && isFencingToken(command[itemIndex + (mixed ? 2 : 1)]) && import_node_buffer45.Buffer.isBuffer(command[itemIndex + (mixed ? 3 : 2)])
|
|
11739
12074
|
);
|
|
11740
12075
|
}
|
|
11741
12076
|
return fixedFlowItemIds(
|
|
11742
12077
|
command,
|
|
11743
12078
|
mixed ? 4 : 3,
|
|
11744
|
-
(itemIndex) => isAutoBatchResourceValue(command[itemIndex]) && (!mixed || isAutoBatchResourceValue(command[itemIndex + 1])) &&
|
|
12079
|
+
(itemIndex) => isAutoBatchResourceValue(command[itemIndex]) && (!mixed || isAutoBatchResourceValue(command[itemIndex + 1])) && import_node_buffer45.Buffer.isBuffer(command[itemIndex + (mixed ? 2 : 1)]) && isFencingToken(command[itemIndex + (mixed ? 3 : 2)])
|
|
11745
12080
|
);
|
|
11746
12081
|
}
|
|
11747
12082
|
function createManyAutoBatchIds(command) {
|
|
@@ -11754,7 +12089,7 @@ function createManyAutoBatchIds(command) {
|
|
|
11754
12089
|
const ids = fixedFlowItemIds(
|
|
11755
12090
|
command,
|
|
11756
12091
|
width,
|
|
11757
|
-
(itemIndex) => isAutoBatchResourceValue(command[itemIndex]) && (!mixed || isAutoBatchResourceValue(command[itemIndex + 1])) &&
|
|
12092
|
+
(itemIndex) => isAutoBatchResourceValue(command[itemIndex]) && (!mixed || isAutoBatchResourceValue(command[itemIndex + 1])) && import_node_buffer45.Buffer.isBuffer(command[itemIndex + width - 1]),
|
|
11758
12093
|
markerIndex
|
|
11759
12094
|
);
|
|
11760
12095
|
if (ids != null) return ids;
|
|
@@ -11772,7 +12107,7 @@ function extendedCreateManyAutoBatchIds(command, markerIndex) {
|
|
|
11772
12107
|
let cursor = markerIndex + 2;
|
|
11773
12108
|
for (let itemIndex = 0; itemIndex < itemCount; itemIndex += 1) {
|
|
11774
12109
|
const id = command[cursor];
|
|
11775
|
-
if (!isAutoBatchResourceValue(id) || !isAutoBatchResourceValue(command[cursor + 1]) || !
|
|
12110
|
+
if (!isAutoBatchResourceValue(id) || !isAutoBatchResourceValue(command[cursor + 1]) || !import_node_buffer45.Buffer.isBuffer(command[cursor + 2])) return void 0;
|
|
11776
12111
|
ids.push(id);
|
|
11777
12112
|
cursor += 3;
|
|
11778
12113
|
const afterValues = skipExtendedNamedItems(command, cursor, true);
|
|
@@ -11791,7 +12126,7 @@ function skipExtendedNamedItems(command, countIndex, encodedValues) {
|
|
|
11791
12126
|
for (let index = 0; index < count; index += 1) {
|
|
11792
12127
|
const name = command[firstItem + index * 2];
|
|
11793
12128
|
const value = command[firstItem + index * 2 + 1];
|
|
11794
|
-
if (!isAutoBatchResourceValue(name) || (encodedValues ? !
|
|
12129
|
+
if (!isAutoBatchResourceValue(name) || (encodedValues ? !import_node_buffer45.Buffer.isBuffer(value) : !isAutoBatchResourceValue(value))) return void 0;
|
|
11795
12130
|
}
|
|
11796
12131
|
return firstItem + count * 2;
|
|
11797
12132
|
}
|
|
@@ -11806,7 +12141,7 @@ function runStepsManyAutoBatchIds(command) {
|
|
|
11806
12141
|
ids.push(item);
|
|
11807
12142
|
continue;
|
|
11808
12143
|
}
|
|
11809
|
-
if (typeof item !== "object" || item == null || Array.isArray(item) ||
|
|
12144
|
+
if (typeof item !== "object" || item == null || Array.isArray(item) || import_node_buffer45.Buffer.isBuffer(item)) return void 0;
|
|
11810
12145
|
const id = item.id;
|
|
11811
12146
|
if (!isAutoBatchResourceValue(id)) return void 0;
|
|
11812
12147
|
ids.push(id);
|
|
@@ -11847,7 +12182,7 @@ function flowValuePutOwner(command, start) {
|
|
|
11847
12182
|
}
|
|
11848
12183
|
var flowValuePutOptionTokens = /* @__PURE__ */ new Set(["NAME", "NOW", "OVERRIDE", "OWNER_FLOW_ID", "PARTITION", "TTL", "TTL_MS"]);
|
|
11849
12184
|
function isAutoBatchResourceValue(value) {
|
|
11850
|
-
return typeof value === "string" ||
|
|
12185
|
+
return typeof value === "string" || import_node_buffer45.Buffer.isBuffer(value);
|
|
11851
12186
|
}
|
|
11852
12187
|
function isFencingToken(value) {
|
|
11853
12188
|
return typeof value === "number" && Number.isSafeInteger(value) || typeof value === "bigint";
|
|
@@ -11856,7 +12191,7 @@ function nonNegativeItemCount(value) {
|
|
|
11856
12191
|
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : void 0;
|
|
11857
12192
|
}
|
|
11858
12193
|
function autoBatchResourceKey(namespace, value) {
|
|
11859
|
-
return `${namespace}:${
|
|
12194
|
+
return `${namespace}:${import_node_buffer45.Buffer.from(value).toString("base64")}`;
|
|
11860
12195
|
}
|
|
11861
12196
|
function autoBatchCommandName(command) {
|
|
11862
12197
|
return commandView(command).name ?? null;
|
|
@@ -12265,13 +12600,13 @@ function claimFailure(error) {
|
|
|
12265
12600
|
}
|
|
12266
12601
|
|
|
12267
12602
|
// src/client-flow-support.ts
|
|
12268
|
-
var
|
|
12603
|
+
var import_node_buffer59 = require("buffer");
|
|
12269
12604
|
|
|
12270
12605
|
// src/flow-query-builder.ts
|
|
12271
|
-
var
|
|
12606
|
+
var import_node_buffer48 = require("buffer");
|
|
12272
12607
|
|
|
12273
12608
|
// src/flow-query-metadata.ts
|
|
12274
|
-
var
|
|
12609
|
+
var import_node_buffer47 = require("buffer");
|
|
12275
12610
|
var MAX_FLOW_QUERY_METADATA_KEY_BYTES = 64;
|
|
12276
12611
|
function normalizeStateMeta(value, state) {
|
|
12277
12612
|
if (value == null) return {};
|
|
@@ -12296,7 +12631,7 @@ function normalizeStateMeta(value, state) {
|
|
|
12296
12631
|
function metadataEntries(value, context) {
|
|
12297
12632
|
const entries = objectEntries(value ?? {}, context).map(([rawName, item]) => {
|
|
12298
12633
|
const name = rawName.trim();
|
|
12299
|
-
const size =
|
|
12634
|
+
const size = import_node_buffer47.Buffer.byteLength(name, "utf8");
|
|
12300
12635
|
if (size === 0 || size > MAX_FLOW_QUERY_METADATA_KEY_BYTES || name.startsWith("__")) {
|
|
12301
12636
|
throw new TypeError(`${context} key is invalid or reserved`);
|
|
12302
12637
|
}
|
|
@@ -12320,7 +12655,7 @@ function objectEntries(value, context) {
|
|
|
12320
12655
|
return keys.map((key) => [key, value[key]]);
|
|
12321
12656
|
}
|
|
12322
12657
|
function isPlainRecord(value) {
|
|
12323
|
-
if (typeof value !== "object" || value == null || Array.isArray(value) ||
|
|
12658
|
+
if (typeof value !== "object" || value == null || Array.isArray(value) || import_node_buffer47.Buffer.isBuffer(value)) {
|
|
12324
12659
|
return false;
|
|
12325
12660
|
}
|
|
12326
12661
|
const prototype = Object.getPrototypeOf(value);
|
|
@@ -12390,7 +12725,7 @@ var FlowCollectionQuery = class {
|
|
|
12390
12725
|
const states = /* @__PURE__ */ new Set();
|
|
12391
12726
|
for (const [rawState, metadata] of objectEntries(values, "stateMeta")) {
|
|
12392
12727
|
const state = requiredText(rawState, "stateMeta state").trim();
|
|
12393
|
-
const stateBytes =
|
|
12728
|
+
const stateBytes = import_node_buffer48.Buffer.byteLength(state, "utf8");
|
|
12394
12729
|
if (stateBytes === 0 || stateBytes > MAX_FLOW_QUERY_STATE_BYTES) {
|
|
12395
12730
|
throw new TypeError(
|
|
12396
12731
|
`stateMeta state names must be 1..${MAX_FLOW_QUERY_STATE_BYTES} bytes`
|
|
@@ -12569,7 +12904,7 @@ function requiredPartition(value) {
|
|
|
12569
12904
|
"FLOW.QUERY convenience methods require a partition key"
|
|
12570
12905
|
);
|
|
12571
12906
|
}
|
|
12572
|
-
const size =
|
|
12907
|
+
const size = import_node_buffer48.Buffer.byteLength(value, "utf8");
|
|
12573
12908
|
if (size === 0 || size > MAX_FLOW_QUERY_PARTITION_BYTES) {
|
|
12574
12909
|
throw new TypeError(
|
|
12575
12910
|
`FLOW.QUERY partition key must be 1..${MAX_FLOW_QUERY_PARTITION_BYTES} bytes`
|
|
@@ -12617,23 +12952,23 @@ function requiredText(value, context) {
|
|
|
12617
12952
|
return value;
|
|
12618
12953
|
}
|
|
12619
12954
|
function queryParameter(value, context) {
|
|
12620
|
-
if (typeof value === "string" || typeof value === "boolean" || typeof value === "bigint" || typeof value === "number" ||
|
|
12955
|
+
if (typeof value === "string" || typeof value === "boolean" || typeof value === "bigint" || typeof value === "number" || import_node_buffer48.Buffer.isBuffer(value)) {
|
|
12621
12956
|
return value;
|
|
12622
12957
|
}
|
|
12623
12958
|
throw new TypeError(`${context} must be a scalar FLOW.QUERY parameter`);
|
|
12624
12959
|
}
|
|
12625
12960
|
|
|
12626
12961
|
// src/flow-query-response.ts
|
|
12627
|
-
var
|
|
12962
|
+
var import_node_buffer52 = require("buffer");
|
|
12628
12963
|
|
|
12629
12964
|
// src/flow-query-diagnostic-response.ts
|
|
12630
|
-
var
|
|
12965
|
+
var import_node_buffer50 = require("buffer");
|
|
12631
12966
|
|
|
12632
12967
|
// src/flow-query-response-validation.ts
|
|
12633
|
-
var
|
|
12968
|
+
var import_node_buffer49 = require("buffer");
|
|
12634
12969
|
function requiredMap2(value, context) {
|
|
12635
12970
|
if (value instanceof Map) return value;
|
|
12636
|
-
if (typeof value !== "object" || value == null || Array.isArray(value) ||
|
|
12971
|
+
if (typeof value !== "object" || value == null || Array.isArray(value) || import_node_buffer49.Buffer.isBuffer(value) || value instanceof Uint8Array) {
|
|
12637
12972
|
throw decodeError(`${context} must be a map`, value);
|
|
12638
12973
|
}
|
|
12639
12974
|
return value;
|
|
@@ -12690,7 +13025,7 @@ function normalizeMetadataValue(value, context, budget, ancestors, depth) {
|
|
|
12690
13025
|
if (!value.isWellFormed()) throw decodeError(`${context} contains invalid text`, value);
|
|
12691
13026
|
return value;
|
|
12692
13027
|
}
|
|
12693
|
-
if (
|
|
13028
|
+
if (import_node_buffer49.Buffer.isBuffer(value) || value instanceof Uint8Array) {
|
|
12694
13029
|
const decoded = strictText2(value);
|
|
12695
13030
|
if (decoded == null) throw decodeError(`${context} contains invalid UTF-8`, value);
|
|
12696
13031
|
return decoded;
|
|
@@ -12769,7 +13104,7 @@ function optionalText2(mapping2, name, context) {
|
|
|
12769
13104
|
}
|
|
12770
13105
|
function requiredBoundedText2(mapping2, name, context, maximumBytes) {
|
|
12771
13106
|
const value = requiredText2(mapping2, name, context);
|
|
12772
|
-
if (
|
|
13107
|
+
if (import_node_buffer49.Buffer.byteLength(value, "utf8") > maximumBytes) {
|
|
12773
13108
|
throw decodeError(
|
|
12774
13109
|
`${context} ${name} exceeds ${maximumBytes} bytes`,
|
|
12775
13110
|
mapping2
|
|
@@ -12782,7 +13117,7 @@ function boundedText(value, context, maximumBytes) {
|
|
|
12782
13117
|
if (decoded == null || decoded.length === 0) {
|
|
12783
13118
|
throw decodeError(`${context} must be non-empty text`, value);
|
|
12784
13119
|
}
|
|
12785
|
-
if (
|
|
13120
|
+
if (import_node_buffer49.Buffer.byteLength(decoded, "utf8") > maximumBytes) {
|
|
12786
13121
|
throw decodeError(`${context} exceeds ${maximumBytes} bytes`, value);
|
|
12787
13122
|
}
|
|
12788
13123
|
return decoded;
|
|
@@ -12836,10 +13171,10 @@ function positiveBoundedInteger(value, maximum, context) {
|
|
|
12836
13171
|
function hasKey(mapping2, name) {
|
|
12837
13172
|
if (!(mapping2 instanceof Map)) return Object.hasOwn(mapping2, name);
|
|
12838
13173
|
if (mapping2.has(name)) return true;
|
|
12839
|
-
const binaryName =
|
|
13174
|
+
const binaryName = import_node_buffer49.Buffer.from(name);
|
|
12840
13175
|
for (const key of mapping2.keys()) {
|
|
12841
|
-
if (
|
|
12842
|
-
if (key instanceof Uint8Array &&
|
|
13176
|
+
if (import_node_buffer49.Buffer.isBuffer(key) && key.equals(binaryName)) return true;
|
|
13177
|
+
if (key instanceof Uint8Array && import_node_buffer49.Buffer.from(key).equals(binaryName))
|
|
12843
13178
|
return true;
|
|
12844
13179
|
}
|
|
12845
13180
|
return false;
|
|
@@ -12850,7 +13185,7 @@ function decodeError(message, raw) {
|
|
|
12850
13185
|
function strictText2(value) {
|
|
12851
13186
|
if (typeof value === "string")
|
|
12852
13187
|
return value.isWellFormed() ? value : void 0;
|
|
12853
|
-
if (
|
|
13188
|
+
if (import_node_buffer49.Buffer.isBuffer(value) || value instanceof Uint8Array) {
|
|
12854
13189
|
try {
|
|
12855
13190
|
return new TextDecoder("utf-8", { fatal: true }).decode(value);
|
|
12856
13191
|
} catch {
|
|
@@ -12930,7 +13265,7 @@ function tryDecodeFlowQueryError(value, cause) {
|
|
|
12930
13265
|
}
|
|
12931
13266
|
function optionalDiagnosticText(mapping2, name) {
|
|
12932
13267
|
const value = optionalText2(mapping2, name, "FLOW.QUERY diagnostic");
|
|
12933
|
-
if (value != null &&
|
|
13268
|
+
if (value != null && import_node_buffer50.Buffer.byteLength(value, "utf8") > DIAGNOSTIC_TEXT_BYTES) {
|
|
12934
13269
|
throw decodeError(
|
|
12935
13270
|
`FLOW.QUERY diagnostic ${name} exceeds ${DIAGNOSTIC_TEXT_BYTES} bytes`,
|
|
12936
13271
|
mapping2
|
|
@@ -12965,7 +13300,7 @@ function validateDiagnosticContextValue(value, depth, budget) {
|
|
|
12965
13300
|
}
|
|
12966
13301
|
const text3 = diagnosticContextText(value);
|
|
12967
13302
|
if (text3 != null) {
|
|
12968
|
-
if (
|
|
13303
|
+
if (import_node_buffer50.Buffer.byteLength(text3, "utf8") <= DIAGNOSTIC_TEXT_BYTES) return;
|
|
12969
13304
|
throw decodeError("FLOW.QUERY diagnostic context contains oversized text", value);
|
|
12970
13305
|
}
|
|
12971
13306
|
if (depth <= 0) {
|
|
@@ -12991,7 +13326,7 @@ function validateDiagnosticContextValue(value, depth, budget) {
|
|
|
12991
13326
|
}
|
|
12992
13327
|
for (const [rawKey, item] of entries) {
|
|
12993
13328
|
const key = diagnosticContextText(rawKey);
|
|
12994
|
-
if (key == null || key.length === 0 ||
|
|
13329
|
+
if (key == null || key.length === 0 || import_node_buffer50.Buffer.byteLength(key, "utf8") > DIAGNOSTIC_CONTEXT_KEY_BYTES) {
|
|
12995
13330
|
throw decodeError("FLOW.QUERY diagnostic context contains an invalid key", value);
|
|
12996
13331
|
}
|
|
12997
13332
|
validateDiagnosticContextValue(item, depth - 1, budget);
|
|
@@ -13008,7 +13343,7 @@ function consumeDiagnosticContextNode(value, budget) {
|
|
|
13008
13343
|
}
|
|
13009
13344
|
function diagnosticContextText(value) {
|
|
13010
13345
|
if (typeof value === "string") return value.isWellFormed() ? value : void 0;
|
|
13011
|
-
if (!
|
|
13346
|
+
if (!import_node_buffer50.Buffer.isBuffer(value) && !(value instanceof Uint8Array)) return void 0;
|
|
13012
13347
|
try {
|
|
13013
13348
|
return new TextDecoder("utf-8", { fatal: true }).decode(value);
|
|
13014
13349
|
} catch {
|
|
@@ -13034,7 +13369,7 @@ function decodePosition(value) {
|
|
|
13034
13369
|
}
|
|
13035
13370
|
|
|
13036
13371
|
// src/flow-query-index-contract.ts
|
|
13037
|
-
var
|
|
13372
|
+
var import_node_buffer51 = require("buffer");
|
|
13038
13373
|
var FLOW_QUERY_BUILD_PHASES = ["pending", "snapshot", "backfill", "done"];
|
|
13039
13374
|
var FLOW_QUERY_VALIDATION_PHASES = [
|
|
13040
13375
|
"pending",
|
|
@@ -13280,10 +13615,10 @@ function fieldKind(name) {
|
|
|
13280
13615
|
return void 0;
|
|
13281
13616
|
}
|
|
13282
13617
|
function validUnquoted(value) {
|
|
13283
|
-
return !value.startsWith("__") && UNQUOTED_METADATA.test(value) &&
|
|
13618
|
+
return !value.startsWith("__") && UNQUOTED_METADATA.test(value) && import_node_buffer51.Buffer.byteLength(value, "ascii") <= 64;
|
|
13284
13619
|
}
|
|
13285
13620
|
function validMetadata(value, rejectReserved) {
|
|
13286
|
-
return value.length > 0 &&
|
|
13621
|
+
return value.length > 0 && import_node_buffer51.Buffer.byteLength(value, "utf8") <= 64 && (!rejectReserved || !value.startsWith("__"));
|
|
13287
13622
|
}
|
|
13288
13623
|
function externalSelector(root, ...segments) {
|
|
13289
13624
|
return segments.every(validUnquoted) ? [root, ...segments].join(".") : root + segments.map((segment) => `['${segment.replaceAll("'", "''")}']`).join("");
|
|
@@ -14190,7 +14525,7 @@ function decodePage(value) {
|
|
|
14190
14525
|
const mapping2 = requiredMap2(value, "FLOW.QUERY page");
|
|
14191
14526
|
const hasMore = requiredBoolean(mapping2, "has_more", "FLOW.QUERY page");
|
|
14192
14527
|
const cursor = optionalText2(mapping2, "cursor", "FLOW.QUERY page");
|
|
14193
|
-
if (cursor != null && (!cursor.startsWith("fqc1_") ||
|
|
14528
|
+
if (cursor != null && (!cursor.startsWith("fqc1_") || import_node_buffer52.Buffer.byteLength(cursor) < 16 || import_node_buffer52.Buffer.byteLength(cursor) > 4096)) {
|
|
14194
14529
|
throw decodeError("FLOW.QUERY page cursor is invalid", value);
|
|
14195
14530
|
}
|
|
14196
14531
|
if (hasMore !== (cursor != null)) {
|
|
@@ -14200,12 +14535,12 @@ function decodePage(value) {
|
|
|
14200
14535
|
}
|
|
14201
14536
|
|
|
14202
14537
|
// src/client-core.ts
|
|
14203
|
-
var
|
|
14538
|
+
var import_node_buffer57 = require("buffer");
|
|
14204
14539
|
|
|
14205
14540
|
// src/client-core-helpers.ts
|
|
14206
|
-
var
|
|
14541
|
+
var import_node_buffer53 = require("buffer");
|
|
14207
14542
|
function bgsaveResponse(response) {
|
|
14208
|
-
if ((typeof response === "string" ||
|
|
14543
|
+
if ((typeof response === "string" || import_node_buffer53.Buffer.isBuffer(response) || response instanceof Uint8Array) && text(response) === "Background saving started") {
|
|
14209
14544
|
return true;
|
|
14210
14545
|
}
|
|
14211
14546
|
return okResponse(response);
|
|
@@ -14219,7 +14554,7 @@ function fetchOrComputeCompletionToken(options) {
|
|
|
14219
14554
|
"fetch-or-compute completion requires computeToken"
|
|
14220
14555
|
);
|
|
14221
14556
|
}
|
|
14222
|
-
if (!
|
|
14557
|
+
if (!import_node_buffer53.Buffer.isBuffer(options.computeToken)) {
|
|
14223
14558
|
throw new TypeError("fetch-or-compute computeToken must be a Buffer");
|
|
14224
14559
|
}
|
|
14225
14560
|
return options.computeToken;
|
|
@@ -14242,10 +14577,10 @@ function unsupportedClientCaching() {
|
|
|
14242
14577
|
}
|
|
14243
14578
|
|
|
14244
14579
|
// src/client-base.ts
|
|
14245
|
-
var
|
|
14580
|
+
var import_node_buffer55 = require("buffer");
|
|
14246
14581
|
|
|
14247
14582
|
// src/client-executor.ts
|
|
14248
|
-
var
|
|
14583
|
+
var import_node_buffer54 = require("buffer");
|
|
14249
14584
|
var ErrorMappingExecutor = class {
|
|
14250
14585
|
constructor(executor) {
|
|
14251
14586
|
this.executor = executor;
|
|
@@ -14586,14 +14921,14 @@ var FerricStoreAdministrationClient = class extends FerricStoreClientBase {
|
|
|
14586
14921
|
};
|
|
14587
14922
|
|
|
14588
14923
|
// src/store-utilities.ts
|
|
14589
|
-
var
|
|
14924
|
+
var import_node_buffer56 = require("buffer");
|
|
14590
14925
|
function encode(codec, value) {
|
|
14591
14926
|
return codec.encode(value);
|
|
14592
14927
|
}
|
|
14593
14928
|
function decode(codec, value) {
|
|
14594
14929
|
if (value == null) return null;
|
|
14595
|
-
if (
|
|
14596
|
-
if (value instanceof Uint8Array) return codec.decode(
|
|
14930
|
+
if (import_node_buffer56.Buffer.isBuffer(value)) return codec.decode(value);
|
|
14931
|
+
if (value instanceof Uint8Array) return codec.decode(import_node_buffer56.Buffer.from(value));
|
|
14597
14932
|
return value;
|
|
14598
14933
|
}
|
|
14599
14934
|
function number(value) {
|
|
@@ -17449,7 +17784,7 @@ function throwIfClosed(signal) {
|
|
|
17449
17784
|
}
|
|
17450
17785
|
|
|
17451
17786
|
// src/flow-policy.ts
|
|
17452
|
-
var
|
|
17787
|
+
var import_node_buffer58 = require("buffer");
|
|
17453
17788
|
var MAX_FLOW_POLICY_GENERATION = Number.MAX_SAFE_INTEGER;
|
|
17454
17789
|
function assertFlowPolicyGeneration(value) {
|
|
17455
17790
|
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
|
|
@@ -17539,7 +17874,7 @@ function requiredRecord(value, context) {
|
|
|
17539
17874
|
}
|
|
17540
17875
|
return result;
|
|
17541
17876
|
}
|
|
17542
|
-
if (typeof value === "object" && value != null && !Array.isArray(value) && !
|
|
17877
|
+
if (typeof value === "object" && value != null && !Array.isArray(value) && !import_node_buffer58.Buffer.isBuffer(value) && !(value instanceof Uint8Array)) return value;
|
|
17543
17878
|
throw new TypeError(`${context} returned an unexpected response`);
|
|
17544
17879
|
}
|
|
17545
17880
|
function optionalRecord(value, context) {
|
|
@@ -17560,8 +17895,8 @@ function stringArray(value, context) {
|
|
|
17560
17895
|
}
|
|
17561
17896
|
function requiredText4(value, context) {
|
|
17562
17897
|
if (typeof value === "string") return value;
|
|
17563
|
-
if (
|
|
17564
|
-
return
|
|
17898
|
+
if (import_node_buffer58.Buffer.isBuffer(value) || value instanceof Uint8Array) {
|
|
17899
|
+
return import_node_buffer58.Buffer.from(value).toString("utf8");
|
|
17565
17900
|
}
|
|
17566
17901
|
throw new TypeError(`FLOW policy ${context} returned an unexpected response`);
|
|
17567
17902
|
}
|
|
@@ -17817,7 +18152,7 @@ var FerricStoreFlowSupportClient = class extends FerricStoreFlowQueryClient {
|
|
|
17817
18152
|
};
|
|
17818
18153
|
|
|
17819
18154
|
// src/flow-many-snapshot.ts
|
|
17820
|
-
var
|
|
18155
|
+
var import_node_buffer60 = require("buffer");
|
|
17821
18156
|
var encodedOptionFields = ["error", "payload", "reason", "result"];
|
|
17822
18157
|
function snapshotCreateItem(item, codec) {
|
|
17823
18158
|
const snapshot = {
|
|
@@ -17857,7 +18192,7 @@ function snapshotFlowManyOptions(options, codec) {
|
|
|
17857
18192
|
}
|
|
17858
18193
|
function snapshotClaimedItem(item) {
|
|
17859
18194
|
const wire = item[CLAIMED_ITEM_WIRE];
|
|
17860
|
-
const leaseToken =
|
|
18195
|
+
const leaseToken = import_node_buffer60.Buffer.from(wire?.leaseToken ?? item.leaseToken);
|
|
17861
18196
|
const snapshot = {
|
|
17862
18197
|
...item,
|
|
17863
18198
|
fencingToken: wire?.fencingToken ?? item.fencingToken,
|
|
@@ -17874,15 +18209,15 @@ function snapshotClaimedItem(item) {
|
|
|
17874
18209
|
function snapshotFencedItem(item) {
|
|
17875
18210
|
return Object.freeze({
|
|
17876
18211
|
...item,
|
|
17877
|
-
...item.leaseToken == null ? {} : { leaseToken:
|
|
18212
|
+
...item.leaseToken == null ? {} : { leaseToken: import_node_buffer60.Buffer.from(item.leaseToken) }
|
|
17878
18213
|
});
|
|
17879
18214
|
}
|
|
17880
18215
|
function snapshotClaimedItemWire(wire, leaseToken) {
|
|
17881
18216
|
return Object.freeze({
|
|
17882
18217
|
fencingToken: wire.fencingToken,
|
|
17883
|
-
id:
|
|
18218
|
+
id: import_node_buffer60.Buffer.from(wire.id),
|
|
17884
18219
|
leaseToken,
|
|
17885
|
-
partitionKey: wire.partitionKey == null ? wire.partitionKey :
|
|
18220
|
+
partitionKey: wire.partitionKey == null ? wire.partitionKey : import_node_buffer60.Buffer.from(wire.partitionKey)
|
|
17886
18221
|
});
|
|
17887
18222
|
}
|
|
17888
18223
|
function snapshotArray(values) {
|
|
@@ -17893,7 +18228,7 @@ function snapshotArray(values) {
|
|
|
17893
18228
|
return Object.freeze(snapshot);
|
|
17894
18229
|
}
|
|
17895
18230
|
function snapshotStateMeta(stateMeta) {
|
|
17896
|
-
return snapshotRecord(stateMeta, (value) =>
|
|
18231
|
+
return snapshotRecord(stateMeta, (value) => import_node_buffer60.Buffer.isBuffer(value) ? import_node_buffer60.Buffer.from(value) : value);
|
|
17897
18232
|
}
|
|
17898
18233
|
function snapshotCommandRecord(values) {
|
|
17899
18234
|
const seen = /* @__PURE__ */ new WeakMap();
|
|
@@ -17911,7 +18246,7 @@ function snapshotRecord(values, capture) {
|
|
|
17911
18246
|
}
|
|
17912
18247
|
function snapshotCommandArgument(value, seen) {
|
|
17913
18248
|
if (typeof value !== "object" || value == null) return value;
|
|
17914
|
-
if (
|
|
18249
|
+
if (import_node_buffer60.Buffer.isBuffer(value) || value instanceof Uint8Array) return import_node_buffer60.Buffer.from(value);
|
|
17915
18250
|
const objectValue = value;
|
|
17916
18251
|
const existing = seen.get(objectValue);
|
|
17917
18252
|
if (existing != null) return existing;
|
|
@@ -18907,7 +19242,7 @@ function nativeOptionsForBootstrap(options, signal) {
|
|
|
18907
19242
|
}
|
|
18908
19243
|
|
|
18909
19244
|
// src/flow-query-projection.ts
|
|
18910
|
-
var
|
|
19245
|
+
var import_node_buffer61 = require("buffer");
|
|
18911
19246
|
var MAX_PROJECTION_FIELDS = 32;
|
|
18912
19247
|
var MAX_DYNAMIC_NAME_BYTES = 64;
|
|
18913
19248
|
var FIELD_BRAND = /* @__PURE__ */ Symbol("FerricStoreFlowProjectionField");
|
|
@@ -18977,7 +19312,7 @@ function projectFlowQuery(query, shape, ...fields) {
|
|
|
18977
19312
|
}
|
|
18978
19313
|
const base = stripOptionalTerminator(query);
|
|
18979
19314
|
const result = `${base} RETURN ${shape.toUpperCase()} (${selectors.join(", ")})`;
|
|
18980
|
-
if (
|
|
19315
|
+
if (import_node_buffer61.Buffer.byteLength(result, "utf8") > FLOW_QUERY_MAX_BYTES) {
|
|
18981
19316
|
throw new TypeError(`FLOW.QUERY query exceeds ${FLOW_QUERY_MAX_BYTES} bytes`);
|
|
18982
19317
|
}
|
|
18983
19318
|
return result;
|
|
@@ -19037,7 +19372,7 @@ function quoteName(value, allowPrivate) {
|
|
|
19037
19372
|
throw new TypeError("Flow query projection metadata name must be text");
|
|
19038
19373
|
}
|
|
19039
19374
|
validateUnicodeScalarText2(value);
|
|
19040
|
-
const size =
|
|
19375
|
+
const size = import_node_buffer61.Buffer.byteLength(value, "utf8");
|
|
19041
19376
|
if (size === 0 || size > MAX_DYNAMIC_NAME_BYTES || !allowPrivate && value.startsWith("__")) {
|
|
19042
19377
|
throw new TypeError(
|
|
19043
19378
|
`Flow query projection metadata names must be 1..${MAX_DYNAMIC_NAME_BYTES} UTF-8 bytes`
|
|
@@ -21043,7 +21378,7 @@ var WorkflowWorker = class {
|
|
|
21043
21378
|
};
|
|
21044
21379
|
|
|
21045
21380
|
// src/version.ts
|
|
21046
|
-
var FERRICSTORE_SDK_VERSION = "0.11.
|
|
21381
|
+
var FERRICSTORE_SDK_VERSION = "0.11.11";
|
|
21047
21382
|
var FERRICSTORE_MINIMUM_SERVER_VERSION = "0.11.4";
|
|
21048
21383
|
var FERRICSTORE_NATIVE_PROTOCOL_VERSION = 1;
|
|
21049
21384
|
// Annotate the CommonJS export names for ESM import in node:
|