UNPKG

@strapi/data-transfer

Version:

Data transfer capabilities for Strapi

24 lines 1.53 kB
/** * Shared `JSON.stringify` replacer for data-transfer WebSocket frames (push and pull). * * Default `JSON.stringify` uses `Buffer.toJSON()` → `{ type: 'Buffer', data: [n,n,...] }`, which * allocates a large array on the peer during `JSON.parse`. Encode binary values as compact base64 strings instead. * * Note: Node runs `Buffer.prototype.toJSON` before the replacer sees a `Buffer` property, so the * replacer receives `{ type: 'Buffer', data: [...] }` unless the value is already a string (see * `createTransferAssetStreamChunk` in `transfer-asset-chunk.ts`). */ export declare const replacerForTransferWebSocket: (_key: string, value: unknown) => unknown; /** * `JSON.stringify` invokes an own enumerable `toJSON` on the root value before replacers run. If that * method returns `undefined`, the whole `JSON.stringify` result is `undefined`, and `ws.send(undefined)` * throws ("The first argument must be of type string or an instance of Buffer... Received undefined"). * Spreading transfer messages (`{ ...message, uuid }`) can copy an enumerable `toJSON` from user / ORM * objects onto the wire payload — strip it on the root object we control. */ export declare function stripRootToJSONMethod(payload: Record<string, unknown>): void; /** * Serialize a transfer WebSocket envelope. Never returns `undefined` (unlike raw `JSON.stringify`). */ export declare function stringifyTransferWebSocketPayload(payload: Record<string, unknown>): string; //# sourceMappingURL=transfer-websocket-json.d.ts.map