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

@wixc3/engine-core

Package Overview
Dependencies
Maintainers
0
Versions
348
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wixc3/engine-core - npm Package Compare versions

Comparing version 50.1.0 to 50.2.0

2

dist/com/communication-errors.js

@@ -21,3 +21,3 @@ import { redactArguments } from './helpers.js';

constructor(api, method) {
super(`Cannot add listener to un-configured method ${api} ${method}.`);
super(`Cannot add listener to un-configured method ${api} ${method}. use "declareComEmitter" to configure it.`);
}

@@ -24,0 +24,0 @@ }

@@ -135,3 +135,3 @@ import type { ContextualEnvironment, Environment, EnvironmentMode } from '../entities/env.js';

private handleCallback;
private createDispatcher;
private getDispatcher;
private isListenCall;

@@ -138,0 +138,0 @@ private handleEvent;

@@ -30,3 +30,3 @@ import { isDisposable, SetMultiMap } from '@wixc3/patterns';

handlers = new Map();
eventDispatchers = {};
eventDispatchers = new Map();
apis = {};

@@ -181,7 +181,6 @@ apisOverrides = {};

return new Promise((res, rej) => {
const callbackId = !serviceComConfig[method]?.emitOnly
? this.idsCounter.next(this.messageIdPrefix)
: undefined;
if (this.isListenCall(args) || serviceComConfig[method]?.removeAllListeners) {
this.addOrRemoveListener(envId, api, method, callbackId, origin, serviceComConfig, args[0], res, rej);
const methodConfig = serviceComConfig[method];
const callbackId = !methodConfig?.emitOnly ? this.idsCounter.next(this.messageIdPrefix) : undefined;
if (this.isListenCall(args) || methodConfig?.removeAllListeners) {
this.addOrRemoveListener(envId, api, method, callbackId, origin, methodConfig, args[0], res, rej);
}

@@ -302,3 +301,3 @@ else {

}, {}),
eventDispatchers: Object.keys(this.eventDispatchers),
eventDispatchers: Array.from(this.eventDispatchers.keys()),
apis: Object.keys(this.apis),

@@ -454,2 +453,10 @@ readyEnvs: Array.from(this.readyEnvs),

delete this.environments[instanceId];
for (const [dispatcherKey, { message, dispatcher }] of this.eventDispatchers) {
if (dispatcherKey.endsWith(instanceId)) {
this.eventDispatchers.delete(dispatcherKey);
if (message.removeListener) {
this.apiCall(message.origin, message.data.api, message.removeListener, [dispatcher]);
}
}
}
for (const callbackRecord of this.pendingCallbacks.values()) {

@@ -502,5 +509,5 @@ if (callbackRecord.message.to === instanceId) {

}
addOrRemoveListener(envId, api, method, callbackId, origin, serviceComConfig, fn, res, rej) {
const removeListenerRef = serviceComConfig[method]?.removeAllListeners || serviceComConfig[method]?.removeListener;
if (removeListenerRef) {
addOrRemoveListener(envId, api, method, callbackId, origin, methodConfig, fn, res, rej) {
const removeListenerRef = methodConfig?.removeAllListeners || methodConfig?.removeListener;
if (removeListenerRef && !methodConfig?.listener) {
const listenerHandlerId = this.getHandlerId(envId, api, removeListenerRef);

@@ -512,3 +519,3 @@ const listenerHandlersBucket = this.handlers.get(listenerHandlerId);

}
if (serviceComConfig[method]?.removeListener) {
if (methodConfig?.removeListener) {
listenerHandlersBucket.delete(fn);

@@ -541,3 +548,3 @@ }

else {
if (serviceComConfig[method]?.listener) {
if (methodConfig?.listener) {
const handlersBucket = this.handlers.get(this.getHandlerId(envId, api, method));

@@ -561,2 +568,3 @@ if (handlersBucket && handlersBucket.size !== 0) {

},
removeListener: methodConfig.removeListener,
handlerId: this.createHandlerRecord(envId, api, method, fn),

@@ -651,5 +659,5 @@ callbackId,

const namespacedHandlerId = message.handlerId + message.origin;
const dispatcher = this.eventDispatchers[namespacedHandlerId];
const dispatcher = this.eventDispatchers.get(namespacedHandlerId)?.dispatcher;
if (dispatcher) {
delete this.eventDispatchers[namespacedHandlerId];
this.eventDispatchers.delete(namespacedHandlerId);
const data = await this.apiCall(message.origin, message.data.api, message.data.method, [dispatcher]);

@@ -670,4 +678,3 @@ if (message.callbackId) {

try {
const namespacedHandlerId = message.handlerId + message.origin;
const dispatcher = this.eventDispatchers[namespacedHandlerId] || this.createDispatcher(message.from, message);
const dispatcher = this.getDispatcher(message.from, message);
const data = await this.apiCall(message.origin, message.data.api, message.data.method, [dispatcher]);

@@ -746,14 +753,21 @@ if (message.callbackId) {

}
createDispatcher(envId, message) {
getDispatcher(envId, message) {
const namespacedHandlerId = message.handlerId + message.origin;
return (this.eventDispatchers[namespacedHandlerId] = (...args) => {
this.sendTo(envId, {
to: envId,
from: this.rootEnvId,
type: 'event',
data: args,
handlerId: message.handlerId,
origin: this.rootEnvId,
});
});
if (this.eventDispatchers.has(namespacedHandlerId)) {
return this.eventDispatchers.get(namespacedHandlerId).dispatcher;
}
else {
const dispatcher = (...args) => {
this.sendTo(envId, {
to: envId,
from: this.rootEnvId,
type: 'event',
data: args,
handlerId: message.handlerId,
origin: this.rootEnvId,
});
};
this.eventDispatchers.set(namespacedHandlerId, { dispatcher, message });
return dispatcher;
}
}

@@ -827,4 +841,7 @@ isListenCall(args) {

}
if (typeof offMethod !== 'string') {
throw new Error('offMethod ref must be a string');
}
return {
[onMethod]: { listener: true },
[onMethod]: { listener: true, removeListener: offMethod },
[offMethod]: { removeListener: onMethod },

@@ -831,0 +848,0 @@ ...(removeAll ? { [removeAll]: { removeAllListeners: onMethod } } : undefined),

@@ -32,2 +32,3 @@ import type { SerializableArguments } from './types.js';

handlerId: string;
removeListener?: string;
}

@@ -34,0 +35,0 @@ export interface UnListenMessage extends BaseMessage {

{
"name": "@wixc3/engine-core",
"version": "50.1.0",
"version": "50.2.0",
"type": "module",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -26,3 +26,3 @@ import type { Message } from './message-types.js';

constructor(api: string, method: string) {
super(`Cannot add listener to un-configured method ${api} ${method}.`);
super(`Cannot add listener to un-configured method ${api} ${method}. use "declareComEmitter" to configure it.`);
}

@@ -29,0 +29,0 @@ }

@@ -84,3 +84,3 @@ import { isDisposable, SetMultiMap } from '@wixc3/patterns';

private handlers = new Map<string, Set<UnknownFunction>>();
private eventDispatchers: { [dispatcherId: string]: SerializableMethod } = {};
private eventDispatchers = new Map<string, { dispatcher: SerializableMethod; message: ListenMessage }>();
private apis: RemoteAPIServicesMapping = {};

@@ -269,7 +269,7 @@ private apisOverrides: RemoteAPIServicesMapping = {};

return new Promise<unknown>((res, rej) => {
const callbackId = !serviceComConfig[method]?.emitOnly
? this.idsCounter.next(this.messageIdPrefix)
: undefined;
const methodConfig = serviceComConfig[method];
if (this.isListenCall(args) || serviceComConfig[method]?.removeAllListeners) {
const callbackId = !methodConfig?.emitOnly ? this.idsCounter.next(this.messageIdPrefix) : undefined;
if (this.isListenCall(args) || methodConfig?.removeAllListeners) {
this.addOrRemoveListener(

@@ -281,3 +281,3 @@ envId,

origin,
serviceComConfig,
methodConfig,
args[0] as UnknownFunction,

@@ -410,3 +410,3 @@ res,

}, {}),
eventDispatchers: Object.keys(this.eventDispatchers),
eventDispatchers: Array.from(this.eventDispatchers.keys()),
apis: Object.keys(this.apis),

@@ -578,2 +578,10 @@ readyEnvs: Array.from(this.readyEnvs),

delete this.environments[instanceId];
for (const [dispatcherKey, { message, dispatcher }] of this.eventDispatchers) {
if (dispatcherKey.endsWith(instanceId)) {
this.eventDispatchers.delete(dispatcherKey);
if (message.removeListener) {
this.apiCall(message.origin, message.data.api, message.removeListener, [dispatcher]);
}
}
}
for (const callbackRecord of this.pendingCallbacks.values()) {

@@ -637,3 +645,3 @@ if (callbackRecord.message.to === instanceId) {

origin: string,
serviceComConfig: Record<string, AnyServiceMethodOptions>,
methodConfig: AnyServiceMethodOptions | undefined,
fn: UnknownFunction,

@@ -643,6 +651,5 @@ res: (value?: any) => void,

) {
const removeListenerRef =
serviceComConfig[method]?.removeAllListeners || serviceComConfig[method]?.removeListener;
const removeListenerRef = methodConfig?.removeAllListeners || methodConfig?.removeListener;
if (removeListenerRef) {
if (removeListenerRef && !methodConfig?.listener) {
const listenerHandlerId = this.getHandlerId(envId, api, removeListenerRef);

@@ -654,3 +661,3 @@ const listenerHandlersBucket = this.handlers.get(listenerHandlerId);

}
if (serviceComConfig[method]?.removeListener) {
if (methodConfig?.removeListener) {
listenerHandlersBucket.delete(fn);

@@ -680,3 +687,3 @@ } else {

} else {
if (serviceComConfig[method]?.listener) {
if (methodConfig?.listener) {
const handlersBucket = this.handlers.get(this.getHandlerId(envId, api, method));

@@ -700,2 +707,3 @@

},
removeListener: methodConfig.removeListener,
handlerId: this.createHandlerRecord(envId, api, method, fn),

@@ -800,5 +808,5 @@ callbackId,

const namespacedHandlerId = message.handlerId + message.origin;
const dispatcher = this.eventDispatchers[namespacedHandlerId];
const dispatcher = this.eventDispatchers.get(namespacedHandlerId)?.dispatcher;
if (dispatcher) {
delete this.eventDispatchers[namespacedHandlerId];
this.eventDispatchers.delete(namespacedHandlerId);
const data = await this.apiCall(message.origin, message.data.api, message.data.method, [dispatcher]);

@@ -820,6 +828,4 @@ if (message.callbackId) {

try {
const namespacedHandlerId = message.handlerId + message.origin;
const dispatcher = this.getDispatcher(message.from, message);
const dispatcher =
this.eventDispatchers[namespacedHandlerId] || this.createDispatcher(message.from, message);
const data = await this.apiCall(message.origin, message.data.api, message.data.method, [dispatcher]);

@@ -899,15 +905,20 @@

private createDispatcher(envId: string, message: ListenMessage): SerializableMethod {
private getDispatcher(envId: string, message: ListenMessage): SerializableMethod {
const namespacedHandlerId = message.handlerId + message.origin;
return (this.eventDispatchers[namespacedHandlerId] = (...args: SerializableArguments) => {
this.sendTo(envId, {
to: envId,
from: this.rootEnvId,
type: 'event',
data: args,
handlerId: message.handlerId,
origin: this.rootEnvId,
});
});
if (this.eventDispatchers.has(namespacedHandlerId)) {
return this.eventDispatchers.get(namespacedHandlerId)!.dispatcher;
} else {
const dispatcher = (...args: SerializableArguments) => {
this.sendTo(envId, {
to: envId,
from: this.rootEnvId,
type: 'event',
data: args,
handlerId: message.handlerId,
origin: this.rootEnvId,
});
};
this.eventDispatchers.set(namespacedHandlerId, { dispatcher, message });
return dispatcher;
}
}

@@ -994,4 +1005,7 @@

}
if (typeof offMethod !== 'string') {
throw new Error('offMethod ref must be a string');
}
return {
[onMethod]: { listener: true },
[onMethod]: { listener: true, removeListener: offMethod },
[offMethod]: { removeListener: onMethod },

@@ -998,0 +1012,0 @@ ...(removeAll ? { [removeAll]: { removeAllListeners: onMethod } } : undefined),

@@ -33,2 +33,3 @@ import type { SerializableArguments } from './types.js';

handlerId: string;
removeListener?: string;
}

@@ -35,0 +36,0 @@

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc