New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@remote-ui/rpc

Package Overview
Dependencies
Maintainers
3
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@remote-ui/rpc - npm Package Compare versions

Comparing version

to
1.4.1

60

build/cjs/encoding/basic.js

@@ -51,31 +51,41 @@ 'use strict';

function encode(value) {
if (typeof value === 'object') {
if (value == null) {
return [value];
}
function encode(value, seen = new Map()) {
if (value == null) {
return [value];
}
if (value instanceof ArrayBuffer) {
return [value];
}
const seenValue = seen.get(value);
const transferables = [];
if (seenValue) {
return seenValue;
}
if (typeof value === 'object') {
if (Array.isArray(value)) {
seen.set(value, [undefined]);
const transferables = [];
const result = value.map(item => {
const [result, nestedTransferables = []] = encode(item);
const [result, nestedTransferables = []] = encode(item, seen);
transferables.push(...nestedTransferables);
return result;
});
return [result, transferables];
const fullResult = [result, transferables];
seen.set(value, fullResult);
return fullResult;
}
const result = Object.keys(value).reduce((object, key) => {
const [result, nestedTransferables = []] = encode(value[key]);
transferables.push(...nestedTransferables);
return { ...object,
[key]: result
};
}, {});
return [result, transferables];
if (memory.isBasicObject(value)) {
seen.set(value, [undefined]);
const transferables = [];
const result = Object.keys(value).reduce((object, key) => {
const [result, nestedTransferables = []] = encode(value[key], seen);
transferables.push(...nestedTransferables);
return { ...object,
[key]: result
};
}, {});
const fullResult = [result, transferables];
seen.set(value, fullResult);
return fullResult;
}
}

@@ -86,5 +96,7 @@

const id = functionsToId.get(value);
return [{
const result = [{
[FUNCTION]: id
}];
seen.set(value, result);
return result;
}

@@ -95,8 +107,12 @@

idsToFunction.set(id, value);
return [{
const result = [{
[FUNCTION]: id
}];
seen.set(value, result);
return result;
}
return [value];
const result = [value];
seen.set(value, result);
return result;
}

@@ -103,0 +119,0 @@

@@ -18,2 +18,4 @@ 'use strict';

exports.StackFrame = memory.StackFrame;
exports.isBasicObject = memory.isBasicObject;
exports.isMemoryManageable = memory.isMemoryManageable;
exports.release = memory.release;

@@ -20,0 +22,0 @@ exports.retain = memory.retain;

@@ -34,2 +34,8 @@ 'use strict';

} = {}) {
return retainInternal(value, deep, new Map());
}
function retainInternal(value, deep, seen) {
const seenValue = seen.get(value);
if (seenValue != null) return seenValue;
const canRetain = isMemoryManageable(value);

@@ -41,19 +47,30 @@

seen.set(value, canRetain);
if (deep) {
if (Array.isArray(value)) {
return value.reduce((canRetain, item) => retain(item, {
deep
}) || canRetain, canRetain);
} else if (typeof value === 'object' && value != null) {
return Object.keys(value).reduce((canRetain, key) => retain(value[key], {
deep
}) || canRetain, canRetain);
const nestedCanRetain = value.reduce((canRetain, item) => retainInternal(item, deep, seen) || canRetain, canRetain);
seen.set(value, nestedCanRetain);
return nestedCanRetain;
}
if (isBasicObject(value)) {
const nestedCanRetain = Object.keys(value).reduce((canRetain, key) => retainInternal(value[key], deep, seen) || canRetain, canRetain);
seen.set(value, nestedCanRetain);
return nestedCanRetain;
}
}
seen.set(value, canRetain);
return canRetain;
}
function release(value, {
deep = true
} = {}) {
return releaseInternal(value, deep, new Map());
}
function releaseInternal(value, deep, seen) {
const seenValue = seen.get(value);
if (seenValue != null) return seenValue;
const canRelease = isMemoryManageable(value);

@@ -65,12 +82,16 @@

seen.set(value, canRelease);
if (deep) {
if (Array.isArray(value)) {
return value.reduce((canRelease, item) => release(item, {
deep
}) || canRelease, canRelease);
} else if (typeof value === 'object' && value != null) {
return Object.keys(value).reduce((canRelease, key) => release(value[key], {
deep
}) || canRelease, canRelease);
const nestedCanRelease = value.reduce((canRelease, item) => releaseInternal(item, deep, seen) || canRelease, canRelease);
seen.set(value, nestedCanRelease);
return nestedCanRelease;
}
if (isBasicObject(value)) {
const nestedCanRelease = Object.keys(value).reduce((canRelease, key) => releaseInternal(value[key], deep, seen) || canRelease, canRelease);
seen.set(value, nestedCanRelease);
return nestedCanRelease;
}
}

@@ -80,2 +101,7 @@

}
function isBasicObject(value) {
if (value == null || typeof value !== 'object') return false;
const prototype = Object.getPrototypeOf(value);
return prototype == null || prototype === Object.prototype;
}

@@ -86,4 +112,6 @@ exports.RELEASE_METHOD = types.RELEASE_METHOD;

exports.StackFrame = StackFrame;
exports.isBasicObject = isBasicObject;
exports.isMemoryManageable = isMemoryManageable;
exports.release = release;
exports.releaseInternal = releaseInternal;
exports.retain = retain;

@@ -5,5 +5,5 @@ export { createEndpoint } from './endpoint';

export { fromMessagePort, fromWebWorker, fromIframe, fromInsideIframe, } from './adaptors';
export { retain, release, StackFrame, RELEASE_METHOD, RETAIN_METHOD, RETAINED_BY, } from './memory';
export { retain, release, StackFrame, isBasicObject, isMemoryManageable, RELEASE_METHOD, RETAIN_METHOD, RETAINED_BY, } from './memory';
export type { Retainer, MemoryManageable } from './memory';
export type { EncodingStrategy, EncodingStrategyApi, RemoteCallable, SafeRpcArgument, MessageEndpoint, MaybePromise, } from './types';
//# sourceMappingURL=index.d.ts.map

@@ -17,2 +17,4 @@ import { RETAINED_BY, RETAIN_METHOD, RELEASE_METHOD } from './types';

}): boolean;
export declare function releaseInternal(value: any, deep: boolean, seen: Map<any, boolean>): boolean;
export declare function isBasicObject(value: unknown): value is object;
//# sourceMappingURL=memory.d.ts.map
# Changelog
## 1.4.1
### Patch Changes
- [#187](https://github.com/Shopify/remote-ui/pull/187) [`d8e7bae`](https://github.com/Shopify/remote-ui/commit/d8e7baed50d5743a55f86b88005f411fba0c7cd5) Thanks [@lemonmade](https://github.com/lemonmade)! - Fix infinite loops with self-referencing structures
## 1.4.0

@@ -4,0 +10,0 @@

{
"name": "@remote-ui/rpc",
"description": "An RPC library with strong support for simulating the transfer of functions via postMessage",
"version": "1.4.0",
"version": "1.4.1",
"publishConfig": {

@@ -6,0 +6,0 @@ "access": "public"

@@ -9,3 +9,3 @@ import {

import type {Retainer} from '../memory';
import {StackFrame, isMemoryManageable} from '../memory';
import {StackFrame, isBasicObject, isMemoryManageable} from '../memory';

@@ -61,17 +61,25 @@ type AnyFunction = (...args: any[]) => any;

function encode(value: unknown): [any, Transferable[]?] {
if (typeof value === 'object') {
if (value == null) {
return [value];
}
type EncodeResult = [any, Transferable[]?];
if (value instanceof ArrayBuffer) {
return [value];
}
function encode(
value: unknown,
seen = new Map<any, EncodeResult>(),
): EncodeResult {
if (value == null) {
return [value];
}
const transferables: Transferable[] = [];
const seenValue = seen.get(value);
if (seenValue) {
return seenValue;
}
if (typeof value === 'object') {
if (Array.isArray(value)) {
seen.set(value, [undefined]);
const transferables: Transferable[] = [];
const result = value.map((item) => {
const [result, nestedTransferables = []] = encode(item);
const [result, nestedTransferables = []] = encode(item, seen);
transferables.push(...nestedTransferables);

@@ -81,12 +89,28 @@ return result;

return [result, transferables];
const fullResult: EncodeResult = [result, transferables];
seen.set(value, fullResult);
return fullResult;
}
const result = Object.keys(value).reduce((object, key) => {
const [result, nestedTransferables = []] = encode((value as any)[key]);
transferables.push(...nestedTransferables);
return {...object, [key]: result};
}, {});
if (isBasicObject(value)) {
seen.set(value, [undefined]);
return [result, transferables];
const transferables: Transferable[] = [];
const result = Object.keys(value).reduce((object, key) => {
const [result, nestedTransferables = []] = encode(
(value as any)[key],
seen,
);
transferables.push(...nestedTransferables);
return {...object, [key]: result};
}, {});
const fullResult: EncodeResult = [result, transferables];
seen.set(value, fullResult);
return fullResult;
}
}

@@ -97,3 +121,6 @@

const id = functionsToId.get(value as AnyFunction)!;
return [{[FUNCTION]: id}];
const result: EncodeResult = [{[FUNCTION]: id}];
seen.set(value, result);
return result;
}

@@ -106,6 +133,12 @@

return [{[FUNCTION]: id}];
const result: EncodeResult = [{[FUNCTION]: id}];
seen.set(value, result);
return result;
}
return [value];
const result: EncodeResult = [value];
seen.set(value, result);
return result;
}

@@ -112,0 +145,0 @@

@@ -14,2 +14,4 @@ export {createEndpoint} from './endpoint';

StackFrame,
isBasicObject,
isMemoryManageable,
RELEASE_METHOD,

@@ -16,0 +18,0 @@ RETAIN_METHOD,

@@ -33,2 +33,13 @@ import {RETAINED_BY, RETAIN_METHOD, RELEASE_METHOD} from './types';

export function retain(value: any, {deep = true} = {}): boolean {
return retainInternal(value, deep, new Map());
}
function retainInternal(
value: unknown,
deep: boolean,
seen: Map<any, boolean>,
): boolean {
const seenValue = seen.get(value);
if (seenValue != null) return seenValue;
const canRetain = isMemoryManageable(value);

@@ -40,16 +51,31 @@

seen.set(value, canRetain);
if (deep) {
if (Array.isArray(value)) {
return value.reduce(
(canRetain, item) => retain(item, {deep}) || canRetain,
const nestedCanRetain = value.reduce(
(canRetain, item) => retainInternal(item, deep, seen) || canRetain,
canRetain,
);
} else if (typeof value === 'object' && value != null) {
return Object.keys(value).reduce(
(canRetain, key) => retain(value[key], {deep}) || canRetain,
seen.set(value, nestedCanRetain);
return nestedCanRetain;
}
if (isBasicObject(value)) {
const nestedCanRetain = Object.keys(value).reduce<boolean>(
(canRetain, key) =>
retainInternal((value as any)[key], deep, seen) || canRetain,
canRetain,
);
seen.set(value, nestedCanRetain);
return nestedCanRetain;
}
}
seen.set(value, canRetain);
return canRetain;

@@ -59,2 +85,13 @@ }

export function release(value: any, {deep = true} = {}): boolean {
return releaseInternal(value, deep, new Map());
}
export function releaseInternal(
value: any,
deep: boolean,
seen: Map<any, boolean>,
): boolean {
const seenValue = seen.get(value);
if (seenValue != null) return seenValue;
const canRelease = isMemoryManageable(value);

@@ -66,13 +103,26 @@

seen.set(value, canRelease);
if (deep) {
if (Array.isArray(value)) {
return value.reduce(
(canRelease, item) => release(item, {deep}) || canRelease,
const nestedCanRelease = value.reduce(
(canRelease, item) => releaseInternal(item, deep, seen) || canRelease,
canRelease,
);
} else if (typeof value === 'object' && value != null) {
return Object.keys(value).reduce(
(canRelease, key) => release(value[key], {deep}) || canRelease,
seen.set(value, nestedCanRelease);
return nestedCanRelease;
}
if (isBasicObject(value)) {
const nestedCanRelease = Object.keys(value).reduce<boolean>(
(canRelease, key) =>
releaseInternal((value as any)[key], deep, seen) || canRelease,
canRelease,
);
seen.set(value, nestedCanRelease);
return nestedCanRelease;
}

@@ -83,1 +133,8 @@ }

}
export function isBasicObject(value: unknown): value is object {
if (value == null || typeof value !== 'object') return false;
const prototype = Object.getPrototypeOf(value);
return prototype == null || prototype === Object.prototype;
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet