@tinycloud/cli 1.1.0-beta.20 → 1.1.0-beta.21

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.
@@ -7740,6 +7740,18 @@ var MAX_KV_BATCH_READ_ITEMS = 100;
7740
7740
  function isJsonObject(value) {
7741
7741
  return typeof value === "object" && value !== null && !Array.isArray(value);
7742
7742
  }
7743
+ var pathByteEncoder = new TextEncoder();
7744
+ function comparePathsByBytes(a, b) {
7745
+ const left = pathByteEncoder.encode(a);
7746
+ const right = pathByteEncoder.encode(b);
7747
+ const length4 = Math.min(left.length, right.length);
7748
+ for (let index = 0; index < length4; index++) {
7749
+ if (left[index] !== right[index]) {
7750
+ return left[index] - right[index];
7751
+ }
7752
+ }
7753
+ return left.length - right.length;
7754
+ }
7743
7755
  var REVOKED_BODY = /^(?:Invalid invocation: )?delegation-(?:(revoked): [A-Za-z0-9]+|(ancestor-revoked): ancestor=[A-Za-z0-9]+ invoked=[A-Za-z0-9]+)$/;
7744
7756
  function revocationCodeOf(body) {
7745
7757
  const match = REVOKED_BODY.exec(body.trim());
@@ -7973,15 +7985,25 @@ var KVService = class extends BaseService {
7973
7985
  )?.[1];
7974
7986
  return contentType?.includes("application/json") ? JSON.parse(text) : text;
7975
7987
  }
7988
+ /**
7989
+ * Validate a batch read response and return its items in the caller's
7990
+ * request order. The node flattens invocation abilities from a `BTreeMap`,
7991
+ * so results arrive sorted by UTF-8 byte order of the path, not in request
7992
+ * order. Items that carry their path in `key` are matched by path; if no
7993
+ * item carries a key, items are assumed to be in the node's byte-sorted
7994
+ * order and the request is aligned the same way. Any mix of keyed and
7995
+ * keyless items, a missing requested path, an unrequested path, or a
7996
+ * malformed item fails closed (returns undefined).
7997
+ */
7976
7998
  normalizeBatchReadResponse(data, paths, requireData) {
7977
7999
  if (!data || typeof data !== "object") return void 0;
7978
8000
  const response = data;
7979
- if (!Array.isArray(response.results) || response.results.length !== paths.length) {
8001
+ const items = response.results;
8002
+ if (!Array.isArray(items) || items.length !== paths.length) {
7980
8003
  return void 0;
7981
8004
  }
7982
- for (let index = 0; index < response.results.length; index++) {
7983
- const item = response.results[index];
7984
- if (!item || typeof item !== "object" || item.key !== paths[index] || typeof item.ok !== "boolean") {
8005
+ for (const item of items) {
8006
+ if (!item || typeof item !== "object" || typeof item.ok !== "boolean") {
7985
8007
  return void 0;
7986
8008
  }
7987
8009
  if (item.ok && (!item.headers || typeof item.headers !== "object" || Object.values(item.headers).some((value) => typeof value !== "string") || requireData && typeof item.dataBase64 !== "string")) {
@@ -7991,7 +8013,24 @@ var KVService = class extends BaseService {
7991
8013
  return void 0;
7992
8014
  }
7993
8015
  }
7994
- return response;
8016
+ if (items.every((item) => typeof item.key === "string")) {
8017
+ const byPath = new Map(items.map((item) => [item.key, item]));
8018
+ if (byPath.size !== items.length) return void 0;
8019
+ const aligned2 = [];
8020
+ for (const path of paths) {
8021
+ const item = byPath.get(path);
8022
+ if (!item) return void 0;
8023
+ aligned2.push(item);
8024
+ }
8025
+ return aligned2;
8026
+ }
8027
+ if (items.some((item) => item.key !== void 0)) return void 0;
8028
+ const requestOrder = paths.map((_, index) => index).sort((a, b) => comparePathsByBytes(paths[a], paths[b]));
8029
+ const aligned = new Array(items.length);
8030
+ for (let position = 0; position < requestOrder.length; position++) {
8031
+ aligned[requestOrder[position]] = items[position];
8032
+ }
8033
+ return aligned;
7995
8034
  }
7996
8035
  async batchRead(keys, action, options) {
7997
8036
  if (!this.requireAuth()) return err(authRequiredError("kv"));
@@ -8084,19 +8123,19 @@ var KVService = class extends BaseService {
8084
8123
  { meta: { status: response.status, statusText: response.statusText } }
8085
8124
  ));
8086
8125
  }
8087
- const payload = this.normalizeBatchReadResponse(
8126
+ const items = this.normalizeBatchReadResponse(
8088
8127
  await response.json(),
8089
8128
  paths,
8090
8129
  action === KVAction.GET
8091
8130
  );
8092
- if (!payload) {
8131
+ if (!items) {
8093
8132
  return err(serviceError(
8094
8133
  ErrorCodes.NETWORK_ERROR,
8095
8134
  "KV batch read response did not match the requested keys",
8096
8135
  "kv"
8097
8136
  ));
8098
8137
  }
8099
- const results = payload.results.map((item, index) => {
8138
+ const results = items.map((item, index) => {
8100
8139
  if (!item.ok) {
8101
8140
  return {
8102
8141
  key: keys[index],