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

@casual-simulation/aux-common

Package Overview
Dependencies
Maintainers
2
Versions
473
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@casual-simulation/aux-common - npm Package Compare versions

Comparing version 0.5.4 to 0.6.0

1

aux-format/AuxTreeCalculations.js

@@ -56,3 +56,2 @@ import { precalculatedOp, } from '@casual-simulation/causal-trees';

const filesAdded = stateDiffs.pipe(map(diff => {
// TODO: Work with all domains
return sortBy(diff.addedFiles, f => {

@@ -59,0 +58,0 @@ let tags = tagsOnFile(f);

11

Files/File.d.ts

@@ -11,2 +11,3 @@ export declare type PartialFile = Partial<File>;

['aux.scene.color']?: string;
['aux.version']?: unknown;
['aux.color']?: unknown;

@@ -29,2 +30,4 @@ ['aux.movable']?: unknown;

['aux.shape']?: FileShape;
['aux.image']?: string;
['aux.channel']?: string;
['aux._creator']?: string;

@@ -38,2 +41,3 @@ ['aux._diff']?: boolean;

['aux._userMenuContext']?: string;
['aux._userSimulationsContext']?: string;
['aux._mode']?: UserMode;

@@ -135,1 +139,8 @@ ['aux._editingFile']?: string;

export declare const DEFAULT_SCENE_BACKGROUND_COLOR = "#263238";
/**
* The current file format version for AUX Files.
* This number increments whenever there are any changes between AUX versions.
* As a result, it will allow us to make breaking changes but still upgrade people's files
* in the future.
*/
export declare const AUX_FILE_VERSION: number;

@@ -53,2 +53,9 @@ /**

export const DEFAULT_SCENE_BACKGROUND_COLOR = '#263238';
/**
* The current file format version for AUX Files.
* This number increments whenever there are any changes between AUX versions.
* As a result, it will allow us to make breaking changes but still upgrade people's files
* in the future.
*/
export const AUX_FILE_VERSION = 1;
//# sourceMappingURL=File.js.map

@@ -107,2 +107,12 @@ import { Object, File, Workspace, UserMode, SelectionMode, FileShape, FileTags, FileLabelAnchor } from './File';

}
export declare type SimulationIdParseResult = SimulationIdParseFailure | SimulationIdParseSuccess;
export interface SimulationIdParseFailure {
success: false;
}
export interface SimulationIdParseSuccess {
success: true;
channel?: string;
host?: string;
context?: string;
}
/**

@@ -431,3 +441,3 @@ * Defines an interface that represents the difference between

*/
export declare function createCalculationContext(objects: Object[], lib?: SandboxLibrary, setValueHandlerFactory?: (file: File) => SetValueHandler): FileCalculationContext;
export declare function createCalculationContext(objects: Object[], userId?: string, lib?: SandboxLibrary, setValueHandlerFactory?: (file: File) => SetValueHandler): FileCalculationContext;
/**

@@ -448,2 +458,9 @@ * Gets a list of tags from the given object that match the given event name and arguments.

/**
* Gets the AUX_FILE_VERSION number that the given file was created with.
* If not specified, then undefined is returned.
* @param calc The file calculation context.
* @param file THe file.
*/
export declare function getFileVersion(calc: FileCalculationContext, file: File): number;
/**
* Gets the index that the given file is at in the given context.

@@ -651,2 +668,7 @@ * @param calc The calculation context to use.

/**
* Determines if the given file allows for the file to be place in inventory.
* @param file The file to check.
*/
export declare function isPickupable(calc: FileCalculationContext, file: File): boolean;
/**
* Gets a partial file that can be used to apply the diff that the given file represents.

@@ -657,2 +679,3 @@ * A diff file is any file that has `aux._diff` set to `true` and `aux._diffTags` set to a list of tag names.

export declare function getDiffUpdate(file: File): PartialFile;
export declare function parseSimulationId(id: string): SimulationIdParseSuccess;
/**

@@ -700,2 +723,14 @@ * Parses the given tag filter into its components.

/**
* Determines if the given file is trying to load a simulation.
* @param calc The calculation context.
* @param file The file to check.
*/
export declare function isSimulation(calc: FileCalculationContext, file: Object): boolean;
/**
* Gets the aux.channel tag from the given file.
* @param calc The file calculation context to use.
* @param file The file.
*/
export declare function getFileChannel(calc: FileCalculationContext, file: Object): string;
/**
* Returns wether or not the given file resides in the given context id.

@@ -702,0 +737,0 @@ * @param context The file calculation context to run formulas with.

@@ -7,3 +7,3 @@ import { DEFAULT_WORKSPACE_SCALE, DEFAULT_WORKSPACE_HEIGHT, DEFAULT_WORKSPACE_GRID_SCALE, DEFAULT_USER_MODE, DEFAULT_SELECTION_MODE, DEFAULT_FILE_SHAPE, DEFAULT_WORKSPACE_SIZE, DEFAULT_LABEL_ANCHOR, } from './File';

/// <reference path="../typings/global.d.ts" />
import formulaLib from '../Formulas/formula-lib';
import formulaLib, { setCalculationContext, getCalculationContext, } from '../Formulas/formula-lib';
import { cleanFile, hasValue } from './FilesChannel';

@@ -705,3 +705,3 @@ import { merge, shortUuid } from '../utils';

*/
export function createCalculationContext(objects, lib = formulaLib, setValueHandlerFactory) {
export function createCalculationContext(objects, userId = null, lib = formulaLib, setValueHandlerFactory) {
const context = {

@@ -711,3 +711,3 @@ sandbox: new Sandbox(lib),

};
context.sandbox.interface = new SandboxInterfaceImpl(context, setValueHandlerFactory);
context.sandbox.interface = new SandboxInterfaceImpl(context, userId, setValueHandlerFactory);
return context;

@@ -754,2 +754,11 @@ }

/**
* Gets the AUX_FILE_VERSION number that the given file was created with.
* If not specified, then undefined is returned.
* @param calc The file calculation context.
* @param file THe file.
*/
export function getFileVersion(calc, file) {
return calculateNumericalTagValue(calc, file, 'aux.version', undefined);
}
/**
* Gets the index that the given file is at in the given context.

@@ -900,2 +909,3 @@ * @param calc The calculation context to use.

export function isFileMovable(calc, file) {
// checks if file is movable, but we should also allow it if it is pickupable so we can drag it into inventory if movable is false
return calculateBooleanTagValue(calc, file, 'aux.movable', true);

@@ -1062,2 +1072,9 @@ }

/**
* Determines if the given file allows for the file to be place in inventory.
* @param file The file to check.
*/
export function isPickupable(calc, file) {
return (!!file && calculateBooleanTagValue(calc, file, 'aux.pickupable', true));
}
/**
* Gets a partial file that can be used to apply the diff that the given file represents.

@@ -1090,2 +1107,59 @@ * A diff file is any file that has `aux._diff` set to `true` and `aux._diffTags` set to a list of tag names.

}
export function parseSimulationId(id) {
try {
let uri = new URL(id);
const split = uri.pathname.slice(1).split('/');
if (split.length === 1) {
if (split[0]) {
return {
success: true,
host: uri.host,
channel: split[0],
};
}
else {
return {
success: true,
host: uri.host,
};
}
}
else {
return {
success: true,
host: uri.host,
channel: split[0],
context: split.slice(1).join('/'),
};
}
}
catch (ex) {
const split = id.split('/');
if (split.length === 1) {
return {
success: true,
channel: id,
};
}
else {
const firstSlashIndex = id.indexOf('/');
const firstDotIndex = id.indexOf('.');
if (firstDotIndex >= 0 && firstDotIndex < firstSlashIndex) {
return {
success: true,
host: split[0],
channel: split[1],
context: split.slice(2).join('/'),
};
}
else {
return {
success: true,
channel: split[0],
context: split.slice(1).join('/'),
};
}
}
}
}
/**

@@ -1225,2 +1299,18 @@ * Parses the given tag filter into its components.

/**
* Determines if the given file is trying to load a simulation.
* @param calc The calculation context.
* @param file The file to check.
*/
export function isSimulation(calc, file) {
return !!getFileChannel(calc, file);
}
/**
* Gets the aux.channel tag from the given file.
* @param calc The file calculation context to use.
* @param file The file.
*/
export function getFileChannel(calc, file) {
return calculateFileValue(calc, file, 'aux.channel');
}
/**
* Returns wether or not the given file resides in the given context id.

@@ -1235,3 +1325,7 @@ * @param context The file calculation context to run formulas with.

let result;
const contextValue = calculateFileValue(context, file, contextId);
let contextValue = calculateFileValue(context, file, contextId.valueOf());
if (typeof contextValue === 'object' &&
typeof contextValue.valueOf === 'function') {
contextValue = contextValue.valueOf();
}
if (typeof contextValue === 'string') {

@@ -1405,2 +1499,4 @@ result = contextValue === 'true';

function _calculateFormulaValue(context, object, tag, formula, unwrapProxy = true) {
const prevCalc = getCalculationContext();
setCalculationContext(context);
const result = context.sandbox.run(formula, {

@@ -1411,2 +1507,3 @@ formula,

}, convertToFormulaObject(context, object));
setCalculationContext(prevCalc);
if (unwrapProxy) {

@@ -1448,5 +1545,6 @@ // Unwrap the proxy object

class SandboxInterfaceImpl {
constructor(context, setValueHandlerFactory) {
constructor(context, userId, setValueHandlerFactory) {
this.objects = context.objects;
this.context = context;
this._userId = userId;
this.proxies = new Map();

@@ -1498,2 +1596,5 @@ this.setValueHandlerFactory = setValueHandlerFactory;

}
userId() {
return this._userId;
}
_filterValues(values, filter) {

@@ -1500,0 +1601,0 @@ if (filter) {

@@ -100,3 +100,3 @@ import { File, PartialFile } from './File';

*/
export declare type LocalEvents = ShowToastEvent | TweenToEvent | OpenQRCodeScannerEvent;
export declare type LocalEvents = ShowToastEvent | TweenToEvent | OpenQRCodeScannerEvent | LoadSimulationEvent | UnloadSimulationEvent | SuperShoutEvent;
/**

@@ -131,2 +131,36 @@ * An event that is used to show a toast message to the user.

/**
* An event that is used to load a simulation.
*/
export interface LoadSimulationEvent extends LocalEvent {
name: 'load_simulation';
/**
* The ID of the simulation to load.
*/
id: string;
}
/**
* An event that is used to unload a simulation.
*/
export interface UnloadSimulationEvent extends LocalEvent {
name: 'unload_simulation';
/**
* The ID of the simulation to unload.
*/
id: string;
}
/**
* Defines an event for actions that are shouted to every current loaded simulation.
*/
export interface SuperShoutEvent extends LocalEvent {
name: 'super_shout';
/**
* The name of the event.
*/
eventName: string;
/**
* The argument to pass as the "that" variable to scripts.
*/
argument?: any;
}
/**
* Defines an event for actions.

@@ -205,1 +239,17 @@ * Actions are basically user-defined events.

export declare function openQRCodeScanner(open: boolean): OpenQRCodeScannerEvent;
/**
* Creates a new LoadSimulationEvent.
* @param id The ID of the simulation to load.
*/
export declare function loadSimulation(id: string): LoadSimulationEvent;
/**
* Creates a new UnloadSimulationEvent.
* @param id The ID of the simulation to unload.
*/
export declare function unloadSimulation(id: string): UnloadSimulationEvent;
/**
* Creates a new SuperShoutEvent.
* @param eventName The name of the event.
* @param arg The argument to send as the "that" variable to scripts.
*/
export declare function superShout(eventName: string, arg?: any): SuperShoutEvent;
import { sortBy, flatMap, mapValues } from 'lodash';
import { createCalculationContext, calculateFileValue, convertToFormulaObject, getActiveObjects, filtersMatchingArguments, calculateFormulaValue, isFile, } from './FileCalculations';
import { merge as mergeObj } from '../utils';
import formulaLib, { setActions, getActions, setFileState, setCalculationContext, getCalculationContext, setUserId, getUserId, } from '../Formulas/formula-lib';
import formulaLib, { setActions, getActions, setFileState, setCalculationContext, getCalculationContext, getUserId, } from '../Formulas/formula-lib';
import { isProxy } from './FileProxy';

@@ -28,3 +28,3 @@ /**

};
const context = createCalculationContext(objects, formulaLib, factory);
const context = createCalculationContext(objects, action.userId, formulaLib, factory);
let changes = {};

@@ -37,3 +37,3 @@ objects.forEach(o => {

});
const fileEvents = flatMap(files, f => eventActions(state, files, context, f, action.eventName, factory, action.userId, action.argument));
const fileEvents = flatMap(files, f => eventActions(state, files, context, f, action.eventName, factory, action.argument));
let events = fileEvents;

@@ -115,3 +115,3 @@ const updates = objects.map(o => calculateFileUpdateFromChanges(o.id, changes[o.id]));

}
function eventActions(state, objects, context, file, eventName, setValueHandlerFactory, userId, argument) {
function eventActions(state, objects, context, file, eventName, setValueHandlerFactory, argument) {
const otherObjects = objects.filter(o => o !== file);

@@ -129,3 +129,2 @@ const sortedObjects = sortBy(objects, o => o !== file);

setCalculationContext(context);
setUserId(userId);
let formulaObjects = sortedObjects.map(o => convertToFormulaObject(context, o, setValueHandlerFactory(o)));

@@ -147,3 +146,2 @@ if (typeof argument === 'undefined') {

setCalculationContext(prevContext);
setUserId(prevUserId);
return actions;

@@ -296,2 +294,37 @@ }

}
/**
* Creates a new LoadSimulationEvent.
* @param id The ID of the simulation to load.
*/
export function loadSimulation(id) {
return {
type: 'local',
name: 'load_simulation',
id: id,
};
}
/**
* Creates a new UnloadSimulationEvent.
* @param id The ID of the simulation to unload.
*/
export function unloadSimulation(id) {
return {
type: 'local',
name: 'unload_simulation',
id: id,
};
}
/**
* Creates a new SuperShoutEvent.
* @param eventName The name of the event.
* @param arg The argument to send as the "that" variable to scripts.
*/
export function superShout(eventName, arg) {
return {
type: 'local',
name: 'super_shout',
eventName: eventName,
argument: arg,
};
}
//# sourceMappingURL=FilesChannel.js.map

@@ -12,3 +12,2 @@ import { File, FileTags } from '../Files/File';

export declare function getUserId(): string;
export declare function setUserId(id: string): void;
/**

@@ -119,2 +118,15 @@ * Defines a type that represents a file diff.

/**
* Shouts the given event to every file in every loaded simulation.
* @param eventName The name of the event to shout.
* @param arg The argument to shout. This gets passed as the `that` variable to the other scripts.
*/
export declare function superShout(eventName: string, arg?: any): void;
/**
* Sends the given event to the given file.
* @param file The file to send the event to.
* @param eventName The name of the event to send.
* @param arg The argument to pass.
*/
export declare function whisper(file: File | string, eventName: string, arg?: any): void;
/**
* Redirects the user to a context in the given simulation and context.

@@ -126,3 +138,3 @@ * @param simulationId The ID of the simulation to go to.

/**
* Derermines wather the player is in the given context.
* Derermines whether the player is in the given context.
* @param context The context.

@@ -132,2 +144,7 @@ */

/**
* Determines whether the player has the given file in their inventory.
* @param files The file or files to check.
*/
export declare function hasFileInInventory(files: FileProxy | FileProxy[]): boolean;
/**
* Gets the current user's file.

@@ -229,2 +246,12 @@ */

/**
* Loads the channel with the given ID.
* @param id The ID of the channel to load.
*/
export declare function loadChannel(id: string): void;
/**
* Unloads the channel with the given ID.
* @param id The ID of the channel to unload.
*/
export declare function unloadChannel(id: string): void;
/**
* Defines a set of functions that are able to make File Diffs.

@@ -252,2 +279,5 @@ */

closeQRCodeScanner: typeof closeQRCodeScanner;
loadChannel: typeof loadChannel;
unloadChannel: typeof unloadChannel;
hasFileInInventory: typeof hasFileInInventory;
};

@@ -304,2 +334,5 @@ /**

closeQRCodeScanner: typeof closeQRCodeScanner;
loadChannel: typeof loadChannel;
unloadChannel: typeof unloadChannel;
hasFileInInventory: typeof hasFileInInventory;
};

@@ -313,3 +346,5 @@ applyDiff: typeof applyDiff;

shout: typeof shout;
superShout: typeof superShout;
whisper: typeof whisper;
};
export default _default;

@@ -1,9 +0,10 @@

import { action, calculateActionEvents, fileRemoved, fileAdded, toast as toastMessage, tweenTo as calcTweenTo, openQRCodeScanner as calcOpenQRCodeScanner, } from '../Files/FilesChannel';
import { action, calculateActionEvents, fileRemoved, fileAdded, toast as toastMessage, tweenTo as calcTweenTo, openQRCodeScanner as calcOpenQRCodeScanner, loadSimulation as calcLoadSimulation, unloadSimulation as calcUnloadSimulation, superShout as calcSuperShout, } from '../Files/FilesChannel';
import uuid from 'uuid/v4';
import { every } from 'lodash';
import { isProxy, proxyObject } from '../Files/FileProxy';
import { calculateFormulaValue, COMBINE_ACTION_NAME, addToContextDiff as calcAddToContextDiff, removeFromContextDiff as calcRemoveFromContextDiff, setPositionDiff as calcSetPositionDiff, isFormulaObject, unwrapProxy, CREATE_ACTION_NAME, DESTROY_ACTION_NAME, } from '../Files/FileCalculations';
import { calculateFormulaValue, COMBINE_ACTION_NAME, addToContextDiff as calcAddToContextDiff, removeFromContextDiff as calcRemoveFromContextDiff, setPositionDiff as calcSetPositionDiff, isFormulaObject, unwrapProxy, CREATE_ACTION_NAME, DESTROY_ACTION_NAME, isFileInContext, } from '../Files/FileCalculations';
let actions = [];
let state = null;
let calc = null;
let userFileId = null;
// let userFileId: string = null;
export function setActions(value) {

@@ -28,7 +29,9 @@ actions = value;

export function getUserId() {
return userFileId;
if (calc) {
return calc.sandbox.interface.userId();
}
else {
return null;
}
}
export function setUserId(id) {
userFileId = id;
}
/**

@@ -306,3 +309,3 @@ * Sums the given array of numbers and returns the result.

: null;
let results = calculateActionEvents(state, action(name, ids, userFileId, arg));
let results = calculateActionEvents(state, action(name, ids, getUserId(), arg));
actions.push(...results.events);

@@ -319,2 +322,19 @@ }

/**
* Shouts the given event to every file in every loaded simulation.
* @param eventName The name of the event to shout.
* @param arg The argument to shout. This gets passed as the `that` variable to the other scripts.
*/
export function superShout(eventName, arg) {
actions.push(calcSuperShout(eventName, arg));
}
/**
* Sends the given event to the given file.
* @param file The file to send the event to.
* @param eventName The name of the event to send.
* @param arg The argument to pass.
*/
export function whisper(file, eventName, arg) {
event(eventName, [file], arg);
}
/**
* Redirects the user to a context in the given simulation and context.

@@ -337,3 +357,3 @@ * @param simulationId The ID of the simulation to go to.

/**
* Derermines wather the player is in the given context.
* Derermines whether the player is in the given context.
* @param context The context.

@@ -346,9 +366,19 @@ */

/**
* Determines whether the player has the given file in their inventory.
* @param files The file or files to check.
*/
export function hasFileInInventory(files) {
if (!Array.isArray(files)) {
files = [files];
}
return every(files, f => isFileInContext(getCalculationContext(), f, getUserInventoryContext()));
}
/**
* Gets the current user's file.
*/
export function getUser() {
if (!userFileId) {
if (!getUserId()) {
return null;
}
const user = calc.sandbox.interface.listObjectsWithTag('id', userFileId);
const user = calc.sandbox.interface.listObjectsWithTag('id', getUserId());
if (Array.isArray(user)) {

@@ -524,2 +554,16 @@ if (user.length === 1) {

/**
* Loads the channel with the given ID.
* @param id The ID of the channel to load.
*/
export function loadChannel(id) {
actions.push(calcLoadSimulation(id));
}
/**
* Unloads the channel with the given ID.
* @param id The ID of the channel to unload.
*/
export function unloadChannel(id) {
actions.push(calcUnloadSimulation(id));
}
/**
* Defines a set of functions that are able to make File Diffs.

@@ -547,2 +591,5 @@ */

closeQRCodeScanner,
loadChannel,
unloadChannel,
hasFileInInventory,
};

@@ -582,3 +629,5 @@ /**

shout,
superShout,
whisper,
};
//# sourceMappingURL=formula-lib.js.map

@@ -37,2 +37,6 @@ import { File } from '../Files/File';

addFile(file: File): FileProxy;
/**
* Gets the ID of the current user.
*/
userId(): string;
}
{
"name": "@casual-simulation/aux-common",
"version": "0.5.4",
"version": "0.6.0",
"description": "Common library for AUX projects",

@@ -36,4 +36,4 @@ "main": "index.js",

"dependencies": {
"@casual-simulation/causal-trees": "^0.5.2",
"@casual-simulation/crypto": "^0.5.2",
"@casual-simulation/causal-trees": "^0.6.0",
"@casual-simulation/crypto": "^0.6.0",
"@types/acorn": "^4.0.5",

@@ -57,3 +57,3 @@ "@types/astring": "^1.3.0",

],
"gitHead": "a4366f4f5fa341625c18759f37c8f4e08701e6cb"
"gitHead": "40c9fc188d3ad5889e8f34026a66ac92ed334ffd"
}

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