@nyariv/sandboxjs 0.8.21 → 0.8.23

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.
@@ -14,7 +14,7 @@ jobs:
14
14
  - uses: actions/checkout@v2
15
15
  - uses: actions/setup-node@v1
16
16
  with:
17
- node-version: 12
17
+ node-version: 18
18
18
  - run: npm ci
19
19
  - run: npm test
20
20
 
@@ -25,7 +25,7 @@ jobs:
25
25
  - uses: actions/checkout@v2
26
26
  - uses: actions/setup-node@v1
27
27
  with:
28
- node-version: 12
28
+ node-version: 18
29
29
  registry-url: https://registry.npmjs.org/
30
30
  - run: npm ci
31
31
  - run: npm publish
@@ -1,5 +1,6 @@
1
- import { IGlobals, replacementCallback, IAuditReport, Change, ExecReturn, executeTree, executeTreeAsync, ops, assignCheck, execMany, execAsync, execSync, asyncDone, Scope, IScope, FunctionScope, LocalScope, syncDone } from "./executor.js";
2
- import { IExecutionTree, expectTypes, setLispType, LispItem, LispArray, IConstants } from "./parser.js";
1
+ import { IGlobals, IAuditReport, Change, ExecReturn, executeTree, executeTreeAsync, ops, assignCheck, execMany, execAsync, execSync, asyncDone, Scope, IScope, FunctionScope, LocalScope, syncDone } from "./executor.js";
2
+ import { IExecutionTree, expectTypes, setLispType, LispItem, IConstants, Lisp } from "./parser.js";
3
+ type replacementCallback = (obj: any, isStaticAccess: boolean) => any;
3
4
  export { expectTypes, setLispType, ops as executionOps, assignCheck, execMany, execAsync, execSync, asyncDone, syncDone, executeTree, executeTreeAsync, FunctionScope, LocalScope, };
4
5
  export interface IOptions {
5
6
  audit?: boolean;
@@ -39,7 +40,7 @@ export declare class SandboxGlobal {
39
40
  export declare class ExecContext implements IExecContext {
40
41
  ctx: IContext;
41
42
  constants: IConstants;
42
- tree: LispArray;
43
+ tree: Lisp[];
43
44
  getSubscriptions: Set<(obj: object, name: string) => void>;
44
45
  setSubscriptions: WeakMap<object, Map<string, Set<(modification: Change) => void>>>;
45
46
  changeSubscriptions: WeakMap<object, Set<(modification: Change) => void>>;
@@ -47,7 +48,7 @@ export declare class ExecContext implements IExecContext {
47
48
  changeSubscriptionsGlobal: WeakMap<object, Set<(modification: Change) => void>>;
48
49
  evals: Map<any, any>;
49
50
  registerSandboxFunction: (fn: (...args: any[]) => any) => void;
50
- constructor(ctx: IContext, constants: IConstants, tree: LispArray, getSubscriptions: Set<(obj: object, name: string) => void>, setSubscriptions: WeakMap<object, Map<string, Set<(modification: Change) => void>>>, changeSubscriptions: WeakMap<object, Set<(modification: Change) => void>>, setSubscriptionsGlobal: WeakMap<object, Map<string, Set<(modification: Change) => void>>>, changeSubscriptionsGlobal: WeakMap<object, Set<(modification: Change) => void>>, evals: Map<any, any>, registerSandboxFunction: (fn: (...args: any[]) => any) => void);
51
+ constructor(ctx: IContext, constants: IConstants, tree: Lisp[], getSubscriptions: Set<(obj: object, name: string) => void>, setSubscriptions: WeakMap<object, Map<string, Set<(modification: Change) => void>>>, changeSubscriptions: WeakMap<object, Set<(modification: Change) => void>>, setSubscriptionsGlobal: WeakMap<object, Map<string, Set<(modification: Change) => void>>>, changeSubscriptionsGlobal: WeakMap<object, Set<(modification: Change) => void>>, evals: Map<any, any>, registerSandboxFunction: (fn: (...args: any[]) => any) => void);
51
52
  }
52
53
  export default class Sandbox {
53
54
  context: IContext;
package/build/Sandbox.js CHANGED
@@ -39,7 +39,7 @@ function subscribeSet(obj, name, callback, context) {
39
39
  return {
40
40
  unsubscribe: () => {
41
41
  callbacks.delete(callback);
42
- changeCbs === null || changeCbs === void 0 ? void 0 : changeCbs.delete(callback);
42
+ changeCbs?.delete(callback);
43
43
  }
44
44
  };
45
45
  }
@@ -232,7 +232,7 @@ export default class Sandbox {
232
232
  const parsed = parse(code, optimize);
233
233
  const exec = (...scopes) => {
234
234
  const context = this.createContext(this.context, parsed);
235
- return { context, run: async () => (await this.executeTreeAsync(context, [...scopes])).result };
235
+ return { context, run: () => this.executeTreeAsync(context, [...scopes]).then((ret) => ret.result) };
236
236
  };
237
237
  return exec;
238
238
  }
@@ -249,7 +249,7 @@ export default class Sandbox {
249
249
  const parsed = parse(code, optimize, true);
250
250
  const exec = (...scopes) => {
251
251
  const context = this.createContext(this.context, parsed);
252
- return { context, run: async () => (await this.executeTreeAsync(context, [...scopes])).result };
252
+ return { context, run: () => this.executeTreeAsync(context, [...scopes]).then((ret) => ret.result) };
253
253
  };
254
254
  return exec;
255
255
  }
@@ -1,10 +1,10 @@
1
- import { LispItem, Lisp, LispArray } from "./parser.js";
1
+ import { LispItem, Lisp, LispType, LispFamily, ExtractLispOp } from "./parser.js";
2
2
  import { IExecContext, Ticks } from "./Sandbox.js";
3
- export declare type SandboxFunction = (code: string, ...args: any[]) => () => any;
4
- export declare type sandboxedEval = (code: string) => any;
5
- export declare type sandboxSetTimeout = (handler: TimerHandler, timeout?: any, ...args: any[]) => any;
6
- export declare type sandboxSetInterval = (handler: TimerHandler, timeout?: any, ...args: any[]) => any;
7
- export declare type Done = (err?: any, res?: any) => void;
3
+ export type SandboxFunction = (code: string, ...args: unknown[]) => () => unknown;
4
+ export type sandboxedEval = (code: string) => unknown;
5
+ export type sandboxSetTimeout = (handler: TimerHandler, timeout?: number, ...args: unknown[]) => any;
6
+ export type sandboxSetInterval = (handler: TimerHandler, timeout?: number, ...args: unknown[]) => any;
7
+ export type Done = (err?: unknown, res?: unknown) => void;
8
8
  export declare class ExecReturn<T> {
9
9
  auditReport: IAuditReport;
10
10
  result: T;
@@ -14,13 +14,13 @@ export declare class ExecReturn<T> {
14
14
  constructor(auditReport: IAuditReport, result: T, returned: boolean, breakLoop?: boolean, continueLoop?: boolean);
15
15
  }
16
16
  export interface IAuditReport {
17
- globalsAccess: Set<any>;
17
+ globalsAccess: Set<unknown>;
18
18
  prototypeAccess: {
19
19
  [name: string]: Set<string>;
20
20
  };
21
21
  }
22
22
  export interface IGlobals {
23
- [key: string]: any;
23
+ [key: string]: unknown;
24
24
  }
25
25
  export interface IChange {
26
26
  type: string;
@@ -72,8 +72,7 @@ export interface ICopyWithin extends IChange {
72
72
  added: unknown[];
73
73
  removed: unknown[];
74
74
  }
75
- export declare type Change = ICreate | IReplace | IDelete | IReverse | ISort | IPush | IPop | IUnShift | IShift | ISplice | ICopyWithin;
76
- export declare type replacementCallback = (obj: any, isStaticAccess: boolean) => any;
75
+ export type Change = ICreate | IReplace | IDelete | IReverse | ISort | IPush | IPop | IUnShift | IShift | ISplice | ICopyWithin;
77
76
  export declare class Prop {
78
77
  context: {
79
78
  [key: string]: any;
@@ -85,7 +84,7 @@ export declare class Prop {
85
84
  constructor(context: {
86
85
  [key: string]: any;
87
86
  }, prop: string, isConst?: boolean, isGlobal?: boolean, isVariable?: boolean);
88
- get(context: IExecContext): any;
87
+ get<T = unknown>(context: IExecContext): T;
89
88
  }
90
89
  declare enum VarType {
91
90
  let = "let",
@@ -107,13 +106,13 @@ export declare class Scope {
107
106
  [key: string]: true;
108
107
  };
109
108
  allVars: {
110
- [key: string]: any;
109
+ [key: string]: unknown;
111
110
  } & Object;
112
- functionThis?: any;
113
- constructor(parent: Scope, vars?: {}, functionThis?: any);
111
+ functionThis?: unknown;
112
+ constructor(parent: Scope, vars?: {}, functionThis?: unknown);
114
113
  get(key: string, functionScope?: boolean): Prop;
115
- set(key: string, val: any): Prop;
116
- declare(key: string, type?: VarType, value?: any, isGlobal?: boolean): any;
114
+ set(key: string, val: unknown): Prop;
115
+ declare(key: string, type?: VarType, value?: unknown, isGlobal?: boolean): Prop;
117
116
  }
118
117
  export interface IScope {
119
118
  [key: string]: any;
@@ -125,16 +124,39 @@ export declare class LocalScope implements IScope {
125
124
  export declare class SandboxError extends Error {
126
125
  }
127
126
  export declare function sandboxFunction(context: IExecContext, ticks?: Ticks): SandboxFunction;
128
- export declare function createFunction(argNames: string[], parsed: LispItem, ticks: Ticks, context: IExecContext, scope?: Scope, name?: string): any;
129
- export declare function createFunctionAsync(argNames: string[], parsed: LispItem, ticks: Ticks, context: IExecContext, scope?: Scope, name?: string): any;
127
+ export declare function createFunction(argNames: string[], parsed: Lisp[], ticks: Ticks, context: IExecContext, scope?: Scope, name?: string): any;
128
+ export declare function createFunctionAsync(argNames: string[], parsed: Lisp[], ticks: Ticks, context: IExecContext, scope?: Scope, name?: string): any;
130
129
  export declare function sandboxedEval(func: SandboxFunction): sandboxedEval;
131
130
  export declare function sandboxedSetTimeout(func: SandboxFunction): sandboxSetTimeout;
132
131
  export declare function sandboxedSetInterval(func: SandboxFunction): sandboxSetInterval;
133
132
  export declare function assignCheck(obj: Prop, context: IExecContext, op?: string): void;
134
- declare type OpCallback = (exec: Execution, done: Done, ticks: Ticks, a: LispItem | string[], b: LispItem | Lisp[], obj: Prop | any | undefined, context: IExecContext, scope: Scope, bobj?: Prop | any | undefined, inLoopOrSwitch?: string) => void;
135
- export declare let ops: Map<string, OpCallback>;
136
- export declare function execMany(ticks: Ticks, exec: Execution, tree: LispArray, done: Done, scope: Scope, context: IExecContext, inLoopOrSwitch?: string): void;
137
- declare type Execution = (ticks: Ticks, tree: LispItem, scope: Scope, context: IExecContext, done: Done, inLoopOrSwitch?: string) => void;
133
+ export declare class KeyVal {
134
+ key: string | SpreadObject;
135
+ val: unknown;
136
+ constructor(key: string | SpreadObject, val: unknown);
137
+ }
138
+ export declare class SpreadObject {
139
+ item: {
140
+ [key: string]: unknown;
141
+ };
142
+ constructor(item: {
143
+ [key: string]: unknown;
144
+ });
145
+ }
146
+ export declare class SpreadArray {
147
+ item: unknown[];
148
+ constructor(item: unknown[]);
149
+ }
150
+ export declare class If {
151
+ t: Lisp;
152
+ f: Lisp;
153
+ constructor(t: Lisp, f: Lisp);
154
+ }
155
+ type OpCallback = (exec: Execution, done: Done, ticks: Ticks, a: any, b: any, obj: any, context: IExecContext, scope: Scope, bobj?: any, inLoopOrSwitch?: string) => void;
156
+ export declare const ops: Map<LispType, OpCallback>;
157
+ export declare function addOps<Type extends LispFamily>(type: ExtractLispOp<Type>, cb: OpCallback): void;
158
+ export declare function execMany(ticks: Ticks, exec: Execution, tree: Lisp[], done: Done, scope: Scope, context: IExecContext, inLoopOrSwitch?: string): void;
159
+ type Execution = (ticks: Ticks, tree: LispItem, scope: Scope, context: IExecContext, done: Done, inLoopOrSwitch?: string) => void;
138
160
  export interface AsyncDoneRet {
139
161
  isInstant: boolean;
140
162
  instant: any;
@@ -148,6 +170,6 @@ export declare function syncDone(callback: (done: Done) => void): {
148
170
  };
149
171
  export declare function execAsync(ticks: Ticks, tree: LispItem, scope: Scope, context: IExecContext, doneOriginal: Done, inLoopOrSwitch?: string): Promise<void>;
150
172
  export declare function execSync(ticks: Ticks, tree: LispItem, scope: Scope, context: IExecContext, done: Done, inLoopOrSwitch?: string): void;
151
- export declare function executeTree<T>(ticks: Ticks, context: IExecContext, executionTree: LispItem, scopes?: (IScope)[], inLoopOrSwitch?: string): ExecReturn<T>;
152
- export declare function executeTreeAsync<T>(ticks: Ticks, context: IExecContext, executionTree: LispItem, scopes?: (IScope)[], inLoopOrSwitch?: string): Promise<ExecReturn<T>>;
173
+ export declare function executeTree<T>(ticks: Ticks, context: IExecContext, executionTree: Lisp[], scopes?: (IScope)[], inLoopOrSwitch?: string): ExecReturn<T>;
174
+ export declare function executeTreeAsync<T>(ticks: Ticks, context: IExecContext, executionTree: Lisp[], scopes?: (IScope)[], inLoopOrSwitch?: string): Promise<ExecReturn<T>>;
153
175
  export {};