@fireemu/darwin-arm64 0.63.0 → 0.65.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @fireemu/darwin-arm64
2
2
 
3
3
  The [fireemu](https://www.npmjs.com/package/fireemu) daemon built for `darwin-arm64`
4
- (Rust target `aarch64-apple-darwin`), version 0.63.0.
4
+ (Rust target `aarch64-apple-darwin`), version 0.65.0.
5
5
 
6
6
  macOS 13 or newer on Apple silicon.
7
7
 
package/bin/fireemu CHANGED
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/bin/fireemu
3
- size: 37924320 bytes
4
- sha256: 3e31bb151687f6c079f2c912b44c3b44a69b69beae83107585297b9afa05b917
3
+ size: 38337888 bytes
4
+ sha256: ef00c8e0faab3391a1754b245d51f3a46bc266e1a488a799d3a0b94f6ea64037
@@ -1159,14 +1159,16 @@ const STORAGE_OBJECT_MEMBERS = [
1159
1159
  "timeCreated", "updated", "timeDeleted", "storageClass", "timeStorageClassUpdated", "size", "md5Hash",
1160
1160
  "mediaLink", "metadata", "crc32c", "etag",
1161
1161
  ];
1162
+ const STORAGE_OBJECT_KEYS = new Set(STORAGE_OBJECT_MEMBERS);
1163
+
1162
1164
  function storageObjectInRecordedOrder(data) {
1163
1165
  if (data === null || typeof data !== "object" || Array.isArray(data)) return data;
1164
1166
  const ordered = {};
1165
1167
  for (const key of STORAGE_OBJECT_MEMBERS) {
1166
1168
  if (Object.hasOwn(data, key)) ordered[key] = data[key];
1167
1169
  }
1168
- for (const key of Object.keys(data).sort()) {
1169
- if (!Object.hasOwn(ordered, key)) ordered[key] = data[key];
1170
+ for (const key of Object.keys(data).filter(key => !STORAGE_OBJECT_KEYS.has(key)).sort()) {
1171
+ ordered[key] = data[key];
1170
1172
  }
1171
1173
  return ordered;
1172
1174
  }
@@ -30,8 +30,7 @@ export function boundLogMessage(value, maxBytes = MAX_LOG_MESSAGE_BYTES) {
30
30
  const bytes = Buffer.from(String(value), "utf8");
31
31
  // A UTF-8 round trip replaces lone UTF-16 surrogates while preserving valid pairs. Without
32
32
  // this, JSON.stringify emits an escape that serde_json correctly refuses on the protocol side.
33
- const message = bytes.toString("utf8");
34
- if (bytes.length <= maxBytes) return message;
33
+ if (bytes.length <= maxBytes) return bytes.toString("utf8");
35
34
  const marker = Buffer.from(TRUNCATION_MARKER, "utf8");
36
35
  if (maxBytes <= marker.length) return marker.subarray(0, maxBytes).toString("utf8");
37
36
  let end = maxBytes - marker.length;
@@ -70,6 +69,9 @@ function isSafeStructuredValue(root) {
70
69
  }
71
70
 
72
71
  function structuredEntry(message, fallbackLevel) {
72
+ if (message[0] !== "{" && !/^[ \t\r\n]*\{/.test(message)) {
73
+ return { level: fallbackLevel, message };
74
+ }
73
75
  try {
74
76
  const parsed = JSON.parse(message);
75
77
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
@@ -144,12 +144,10 @@ export class FrameDecoder {
144
144
  }
145
145
  }
146
146
  this.#check();
147
+ let payload;
147
148
  if (this.#body === null) {
148
149
  const byte = chunk[at++];
149
- if (byte === 10) {
150
- if (this.#digits === 0) throw new ProtocolError('empty length');
151
- this.#body = Buffer.allocUnsafe(this.#length);
152
- } else {
150
+ if (byte !== 10) {
153
151
  if (byte < 48 || byte > 57 || (this.#digits === 0 && byte === 48)) {
154
152
  throw new ProtocolError('decimal length');
155
153
  }
@@ -158,27 +156,39 @@ export class FrameDecoder {
158
156
  if (this.#digits > MAX_HEADER_BYTES || this.#length > MAX_FRAME_BYTES) {
159
157
  throw new ProtocolError('frame too large');
160
158
  }
159
+ continue;
160
+ }
161
+ if (this.#digits === 0) throw new ProtocolError('empty length');
162
+ if (chunk.length - at < this.#length) {
163
+ this.#body = Buffer.allocUnsafe(this.#length);
164
+ continue;
161
165
  }
166
+ // Complete bodies are decoded synchronously while the input chunk is still owned by the caller.
167
+ this.#check();
168
+ const end = at + this.#length;
169
+ payload = chunk.subarray(at, end);
170
+ at = end;
162
171
  } else {
163
172
  const count = Math.min(chunk.length - at, this.#length - this.#offset);
164
173
  chunk.copy(this.#body, this.#offset, at, at + count);
165
174
  at += count;
166
175
  this.#offset += count;
167
176
  if (this.#offset !== this.#length) continue;
168
- const message = decodeMessage(this.#body);
169
- // Timers can run late. Check after decoding, before any user callback,
170
- // so a late final chunk cannot race the timer into successful dispatch.
171
- this.#check();
172
- const payloadBytes = this.#length;
173
- this.#body = null;
174
- this.#offset = 0;
175
- this.#length = 0;
176
- this.#digits = 0;
177
- this.#deadline = null;
178
- // Byte accounting is the actual received payload length, not a
179
- // caller-supplied field or a second JSON serialization.
180
- if (this.#onFrame(message, payloadBytes) === false) this.#ended = true;
177
+ payload = this.#body;
181
178
  }
179
+ const message = decodeMessage(payload);
180
+ // Timers can run late. Check after decoding, before any user callback,
181
+ // so a late final chunk cannot race the timer into successful dispatch.
182
+ this.#check();
183
+ const payloadBytes = this.#length;
184
+ this.#body = null;
185
+ this.#offset = 0;
186
+ this.#length = 0;
187
+ this.#digits = 0;
188
+ this.#deadline = null;
189
+ // Byte accounting is the actual received payload length, not a
190
+ // caller-supplied field or a second JSON serialization.
191
+ if (this.#onFrame(message, payloadBytes) === false) this.#ended = true;
182
192
  }
183
193
  } catch (error) { this.#fail(error); }
184
194
  }
@@ -79,18 +79,19 @@ _GCS_OBJECT_ORDER = (
79
79
  )
80
80
 
81
81
 
82
- def _sorted_deep(value):
83
- if isinstance(value, dict):
84
- return {k: _sorted_deep(v) for k, v in sorted(value.items())}
85
- if isinstance(value, list):
86
- return [_sorted_deep(v) for v in value]
87
- return value
88
-
89
-
90
82
  def storage_layout(value) -> str:
91
83
  """The object resource in the API's member order, indented by two spaces, and a newline (recorded for the known members)."""
92
- if isinstance(value, dict):
93
- known = [(k, _sorted_deep(value[k])) for k in _GCS_OBJECT_ORDER if k in value]
94
- rest = [(k, _sorted_deep(v)) for k, v in sorted(value.items()) if k not in _GCS_OBJECT_ORDER]
95
- value = dict(known + rest)
96
- return write(value, indent=2) + "\n"
84
+ if not isinstance(value, dict):
85
+ return write(value, indent=2) + "\n"
86
+ known = [(key, value[key]) for key in _GCS_OBJECT_ORDER if key in value]
87
+ rest = [(key, item) for key, item in sorted(value.items()) if key not in _GCS_OBJECT_ORDER]
88
+ members = known + rest
89
+ if not members:
90
+ return "{}\n"
91
+ # The root has a resource-specific order. The normal writer sorts its descendants
92
+ # during serialization, so no reordered copy of the tree is needed.
93
+ parts = [
94
+ json.dumps(str(key), ensure_ascii=False) + ": " + write(item, sort_keys=True, indent=2, level=1)
95
+ for key, item in members
96
+ ]
97
+ return _join("{", parts, "}", 2, 0) + "\n"
@@ -7,7 +7,9 @@ a JSON parser error can quote the payload.
7
7
  """
8
8
 
9
9
  import json
10
+ import re
10
11
  import threading
12
+ from collections.abc import Callable
11
13
 
12
14
  MAX_FRAME_BYTES = 16 * 1024 * 1024
13
15
  _MAX_HEADER_DIGITS = len(str(MAX_FRAME_BYTES))
@@ -29,6 +31,7 @@ def encode_frame(message: dict) -> bytes:
29
31
 
30
32
  _DECODER = json.JSONDecoder()
31
33
  _WHITESPACE = " \t\n\r"
34
+ _FLAT_ARRAY = re.compile(r'\[[^"{}\[\]]*\]')
32
35
  # The trigger types whose request body is the event's JSON data as the daemon framed it.
33
36
  _RAW_DATA_TRIGGERS = frozenset(("eventarc", "pubsub", "storage", "database"))
34
37
 
@@ -39,13 +42,34 @@ def _after_whitespace(text: str, index: int) -> int:
39
42
  return index
40
43
 
41
44
 
45
+ def _decoded_value_end(text: str, start: int) -> int:
46
+ return _DECODER.raw_decode(text, start)[1]
47
+
48
+
49
+ def _validated_value_end(text: str, start: int) -> int:
50
+ # JSON validation has already run. These spans need no intermediate Python value.
51
+ if text[start] == '"':
52
+ end = text.find('"', start + 1)
53
+ if end >= 0 and text.find("\\", start + 1, end) < 0:
54
+ return end + 1
55
+ elif text[start] == "[":
56
+ matched = _FLAT_ARRAY.match(text, start)
57
+ if matched is not None:
58
+ return matched.end()
59
+ return _decoded_value_end(text, start)
60
+
61
+
42
62
  def raw_event_data(text: str) -> str | None:
43
63
  """The text of `event.data` exactly as it stands in a frame, or None when the frame has none or is malformed.
44
64
 
45
65
  The decoder turns the data into Python values and forgets its spelling (`1e-7`, `\\u00e9`, member order, white space).
46
66
  For a custom Eventarc event in the strict profile the daemon frames the publisher's own JSON text, and that text is the
47
- request body production delivered, so it is read here from the frame text, member by member, without parsing the data.
67
+ request body production delivered, so it is read here from the frame text, member by member.
48
68
  """
69
+ return _raw_event_data(text, _decoded_value_end)
70
+
71
+
72
+ def _raw_event_data(text: str, value_end: Callable[[str, int], int]) -> str | None:
49
73
  try:
50
74
  index = _after_whitespace(text, 0)
51
75
  for wanted in ("event", "data"):
@@ -61,11 +85,11 @@ def raw_event_data(text: str) -> str | None:
61
85
  index = _after_whitespace(text, index + 1)
62
86
  if key == wanted:
63
87
  break
64
- index = _after_whitespace(text, _DECODER.raw_decode(text, index)[1])
88
+ index = _after_whitespace(text, value_end(text, index))
65
89
  if text[index] == ",":
66
90
  index += 1
67
91
  start = index
68
- end = _DECODER.raw_decode(text, start)[1]
92
+ end = value_end(text, start)
69
93
  # A value must be followed by what ends it, or the frame is cut short.
70
94
  return text[start:end] if text[_after_whitespace(text, end)] in ",}" else None
71
95
  except (IndexError, ValueError):
@@ -96,7 +120,7 @@ def _decode_message(payload: bytes) -> dict:
96
120
  ):
97
121
  raise ProtocolError("message fields")
98
122
  if message["trigger"] in _RAW_DATA_TRIGGERS and "data" in message["event"]:
99
- raw = raw_event_data(text)
123
+ raw = _raw_event_data(text, _validated_value_end)
100
124
  if raw is not None:
101
125
  message["rawEventData"] = raw
102
126
  return message
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fireemu/darwin-arm64",
3
- "version": "0.63.0",
3
+ "version": "0.65.0",
4
4
  "description": "The fireemu daemon for darwin-arm64",
5
5
  "homepage": "https://fireemu.github.io/fireemu/",
6
6
  "repository": {