@nyariv/sandboxjs 0.8.22 → 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.
- package/.github/workflows/npm-publish.yml +2 -2
- package/build/Sandbox.d.ts +5 -4
- package/build/Sandbox.js +1 -1
- package/build/executor.d.ts +46 -24
- package/build/executor.js +627 -624
- package/build/parser.d.ts +321 -52
- package/build/parser.js +217 -157
- package/dist/Sandbox.d.ts +5 -4
- package/dist/Sandbox.js +1 -1
- package/dist/Sandbox.js.map +1 -1
- package/dist/executor.d.ts +46 -24
- package/dist/node/Sandbox.d.ts +5 -4
- package/dist/node/Sandbox.js +842 -782
- package/dist/node/executor.d.ts +46 -24
- package/dist/node/parser.d.ts +321 -52
- package/dist/parser.d.ts +321 -52
- package/package.json +14 -14
- package/rollup.config.mjs +33 -0
- package/dist/Sandbox.min.js +0 -2
- package/dist/Sandbox.min.js.map +0 -1
|
@@ -14,7 +14,7 @@ jobs:
|
|
|
14
14
|
- uses: actions/checkout@v2
|
|
15
15
|
- uses: actions/setup-node@v1
|
|
16
16
|
with:
|
|
17
|
-
node-version:
|
|
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:
|
|
28
|
+
node-version: 18
|
|
29
29
|
registry-url: https://registry.npmjs.org/
|
|
30
30
|
- run: npm ci
|
|
31
31
|
- run: npm publish
|
package/build/Sandbox.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { IGlobals,
|
|
2
|
-
import { IExecutionTree, expectTypes, setLispType, LispItem,
|
|
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:
|
|
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:
|
|
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
package/build/executor.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { LispItem, Lisp,
|
|
1
|
+
import { LispItem, Lisp, LispType, LispFamily, ExtractLispOp } from "./parser.js";
|
|
2
2
|
import { IExecContext, Ticks } from "./Sandbox.js";
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
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<
|
|
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]:
|
|
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
|
|
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):
|
|
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]:
|
|
109
|
+
[key: string]: unknown;
|
|
111
110
|
} & Object;
|
|
112
|
-
functionThis?:
|
|
113
|
-
constructor(parent: Scope, vars?: {}, functionThis?:
|
|
111
|
+
functionThis?: unknown;
|
|
112
|
+
constructor(parent: Scope, vars?: {}, functionThis?: unknown);
|
|
114
113
|
get(key: string, functionScope?: boolean): Prop;
|
|
115
|
-
set(key: string, val:
|
|
116
|
-
declare(key: string, type?: VarType, value?:
|
|
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:
|
|
129
|
-
export declare function createFunctionAsync(argNames: string[], parsed:
|
|
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
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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:
|
|
152
|
-
export declare function executeTreeAsync<T>(ticks: Ticks, context: IExecContext, executionTree:
|
|
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 {};
|