xmemory 3.8.0 → 3.8.1
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/dist/cjs/instance.js +27 -3
- package/dist/esm/instance.js +27 -3
- package/package.json +1 -1
package/dist/cjs/instance.js
CHANGED
|
@@ -197,8 +197,21 @@ function buildJsonSchemaProps(params) {
|
|
|
197
197
|
* exactly the deployments that have no link — the case the comparison exists for.
|
|
198
198
|
* Same treatment `read` already gives `reader_results`.
|
|
199
199
|
*/
|
|
200
|
+
/**
|
|
201
|
+
* An *own* property of a decoded response, or `undefined`.
|
|
202
|
+
*
|
|
203
|
+
* A response is JSON, so a field the server omitted is answered by
|
|
204
|
+
* `Object.prototype` — and normalizing with `result.field ?? default` then writes
|
|
205
|
+
* that inherited value back as an own property, where nothing downstream can tell
|
|
206
|
+
* it apart from something the server actually sent. Prototype pollution anywhere in
|
|
207
|
+
* the process could fabricate sub-answers or a trace id this way.
|
|
208
|
+
*/
|
|
209
|
+
function own(result, key) {
|
|
210
|
+
return Object.hasOwn(result, key) ? result[key] : undefined;
|
|
211
|
+
}
|
|
200
212
|
function withConsoleUrl(result) {
|
|
201
|
-
|
|
213
|
+
const url = own(result, "console_url");
|
|
214
|
+
return { ...result, console_url: typeof url === "string" ? url : null };
|
|
202
215
|
}
|
|
203
216
|
class InstanceHandle {
|
|
204
217
|
id;
|
|
@@ -230,7 +243,17 @@ class InstanceHandle {
|
|
|
230
243
|
body,
|
|
231
244
|
timeoutMs: options?.timeoutMs,
|
|
232
245
|
});
|
|
233
|
-
|
|
246
|
+
// Every documented field set explicitly, so each one is an *own* property of
|
|
247
|
+
// what callers get back. Spreading alone leaves an omitted field to be answered
|
|
248
|
+
// by `Object.prototype` when the caller reads it.
|
|
249
|
+
const readerResults = own(result, "reader_results");
|
|
250
|
+
const traceId = own(result, "trace_id");
|
|
251
|
+
return withConsoleUrl({
|
|
252
|
+
...result,
|
|
253
|
+
reader_result: own(result, "reader_result") ?? null,
|
|
254
|
+
reader_results: Array.isArray(readerResults) ? readerResults : [],
|
|
255
|
+
trace_id: typeof traceId === "string" ? traceId : null,
|
|
256
|
+
});
|
|
234
257
|
}
|
|
235
258
|
async write(input, options) {
|
|
236
259
|
return withConsoleUrl(await this._requestOne("POST", `/instances/${this.id}/write`, { body: buildWriteBody(input, options), timeoutMs: options?.timeoutMs }));
|
|
@@ -242,7 +265,8 @@ class InstanceHandle {
|
|
|
242
265
|
});
|
|
243
266
|
// `trace_id` is normalized here as well because this result declares it for the
|
|
244
267
|
// first time, and the wire omits it exactly as it omits the console link.
|
|
245
|
-
|
|
268
|
+
const traceId = own(result, "trace_id");
|
|
269
|
+
return withConsoleUrl({ ...result, trace_id: typeof traceId === "string" ? traceId : null });
|
|
246
270
|
}
|
|
247
271
|
async writeStatus(writeId, options) {
|
|
248
272
|
return withConsoleUrl(await this._requestOne("POST", `/instances/${this.id}/write_status`, { body: { write_id: writeId }, timeoutMs: options?.timeoutMs }));
|
package/dist/esm/instance.js
CHANGED
|
@@ -193,8 +193,21 @@ function buildJsonSchemaProps(params) {
|
|
|
193
193
|
* exactly the deployments that have no link — the case the comparison exists for.
|
|
194
194
|
* Same treatment `read` already gives `reader_results`.
|
|
195
195
|
*/
|
|
196
|
+
/**
|
|
197
|
+
* An *own* property of a decoded response, or `undefined`.
|
|
198
|
+
*
|
|
199
|
+
* A response is JSON, so a field the server omitted is answered by
|
|
200
|
+
* `Object.prototype` — and normalizing with `result.field ?? default` then writes
|
|
201
|
+
* that inherited value back as an own property, where nothing downstream can tell
|
|
202
|
+
* it apart from something the server actually sent. Prototype pollution anywhere in
|
|
203
|
+
* the process could fabricate sub-answers or a trace id this way.
|
|
204
|
+
*/
|
|
205
|
+
function own(result, key) {
|
|
206
|
+
return Object.hasOwn(result, key) ? result[key] : undefined;
|
|
207
|
+
}
|
|
196
208
|
function withConsoleUrl(result) {
|
|
197
|
-
|
|
209
|
+
const url = own(result, "console_url");
|
|
210
|
+
return { ...result, console_url: typeof url === "string" ? url : null };
|
|
198
211
|
}
|
|
199
212
|
export class InstanceHandle {
|
|
200
213
|
id;
|
|
@@ -226,7 +239,17 @@ export class InstanceHandle {
|
|
|
226
239
|
body,
|
|
227
240
|
timeoutMs: options?.timeoutMs,
|
|
228
241
|
});
|
|
229
|
-
|
|
242
|
+
// Every documented field set explicitly, so each one is an *own* property of
|
|
243
|
+
// what callers get back. Spreading alone leaves an omitted field to be answered
|
|
244
|
+
// by `Object.prototype` when the caller reads it.
|
|
245
|
+
const readerResults = own(result, "reader_results");
|
|
246
|
+
const traceId = own(result, "trace_id");
|
|
247
|
+
return withConsoleUrl({
|
|
248
|
+
...result,
|
|
249
|
+
reader_result: own(result, "reader_result") ?? null,
|
|
250
|
+
reader_results: Array.isArray(readerResults) ? readerResults : [],
|
|
251
|
+
trace_id: typeof traceId === "string" ? traceId : null,
|
|
252
|
+
});
|
|
230
253
|
}
|
|
231
254
|
async write(input, options) {
|
|
232
255
|
return withConsoleUrl(await this._requestOne("POST", `/instances/${this.id}/write`, { body: buildWriteBody(input, options), timeoutMs: options?.timeoutMs }));
|
|
@@ -238,7 +261,8 @@ export class InstanceHandle {
|
|
|
238
261
|
});
|
|
239
262
|
// `trace_id` is normalized here as well because this result declares it for the
|
|
240
263
|
// first time, and the wire omits it exactly as it omits the console link.
|
|
241
|
-
|
|
264
|
+
const traceId = own(result, "trace_id");
|
|
265
|
+
return withConsoleUrl({ ...result, trace_id: typeof traceId === "string" ? traceId : null });
|
|
242
266
|
}
|
|
243
267
|
async writeStatus(writeId, options) {
|
|
244
268
|
return withConsoleUrl(await this._requestOne("POST", `/instances/${this.id}/write_status`, { body: { write_id: writeId }, timeoutMs: options?.timeoutMs }));
|