mustardscript 0.2.0 → 0.2.1
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/README.md +14 -0
- package/dist/lib/runtime.js +21 -4
- package/index.d.ts +2 -0
- package/mustard.d.ts +2 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -807,6 +807,20 @@ inside the supported language subset, and lowers to an executable compiled
|
|
|
807
807
|
program. It does not prove that a later `run()` or `start()` call will succeed
|
|
808
808
|
with a particular host policy, input set, capability map, or runtime limit.
|
|
809
809
|
|
|
810
|
+
For LLM-generated snippets, hosts can opt into a narrow compile-time
|
|
811
|
+
compatibility mode:
|
|
812
|
+
|
|
813
|
+
```ts
|
|
814
|
+
const program = new Mustard('const value = 41; return value + 1;', {
|
|
815
|
+
lenientMode: true,
|
|
816
|
+
})
|
|
817
|
+
```
|
|
818
|
+
|
|
819
|
+
`lenientMode` only accepts a `return` when it is the final top-level statement;
|
|
820
|
+
that statement is treated like MustardScript's normal final expression result.
|
|
821
|
+
Nested top-level returns, non-final top-level returns, and all forbidden forms
|
|
822
|
+
still fail closed. Strict behavior remains the default.
|
|
823
|
+
|
|
810
824
|
`Progress.load(...)` always requires explicit restore authority: the host must
|
|
811
825
|
pass either a reusable `ExecutionContext` or explicit `capabilities` /
|
|
812
826
|
`console`, explicit `limits` as an object (use `{}` for default runtime
|
package/dist/lib/runtime.js
CHANGED
|
@@ -28,7 +28,24 @@ function createMustardClass({ native, materializeStep, parseStep }) {
|
|
|
28
28
|
})
|
|
29
29
|
: null;
|
|
30
30
|
|
|
31
|
-
function
|
|
31
|
+
function compileOptionsJson(options = {}) {
|
|
32
|
+
if (options === null || typeof options !== 'object' || Array.isArray(options)) {
|
|
33
|
+
throw new TypeError('compile options must be a plain object');
|
|
34
|
+
}
|
|
35
|
+
if (options.lenientMode === undefined || options.lenientMode === false) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
if (options.lenientMode !== true) {
|
|
39
|
+
throw new TypeError('options.lenientMode must be a boolean');
|
|
40
|
+
}
|
|
41
|
+
return '{"lenient_mode":true}';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function compileProgram(code, options = {}) {
|
|
45
|
+
const optionsJson = compileOptionsJson(options);
|
|
46
|
+
if (optionsJson !== null) {
|
|
47
|
+
return callNative(native.compileProgramWithOptions, code, optionsJson);
|
|
48
|
+
}
|
|
32
49
|
return callNative(native.compileProgram, code);
|
|
33
50
|
}
|
|
34
51
|
|
|
@@ -38,15 +55,15 @@ function createMustardClass({ native, materializeStep, parseStep }) {
|
|
|
38
55
|
|
|
39
56
|
return class Mustard {
|
|
40
57
|
constructor(code, options = {}) {
|
|
41
|
-
this._programHandle = compileProgram(code);
|
|
58
|
+
this._programHandle = compileProgram(code, options);
|
|
42
59
|
this._program = null;
|
|
43
60
|
this._inputNames = options.inputs ?? [];
|
|
44
61
|
this._programHandleToken = {};
|
|
45
62
|
programHandleRegistry?.register(this, this._programHandle, this._programHandleToken);
|
|
46
63
|
}
|
|
47
64
|
|
|
48
|
-
static validateProgram(code) {
|
|
49
|
-
const programHandle = compileProgram(code);
|
|
65
|
+
static validateProgram(code, options = {}) {
|
|
66
|
+
const programHandle = compileProgram(code, options);
|
|
50
67
|
releaseProgram(programHandle);
|
|
51
68
|
}
|
|
52
69
|
|
package/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export declare function cancelCancellationToken(tokenId: string): void
|
|
|
4
4
|
|
|
5
5
|
export declare function compileProgram(source: string): string
|
|
6
6
|
|
|
7
|
+
export declare function compileProgramWithOptions(source: string, optionsJson: string): string
|
|
8
|
+
|
|
7
9
|
export declare function createCancellationToken(): string
|
|
8
10
|
|
|
9
11
|
export declare function createExecutionContext(policyJson: string): string
|
package/mustard.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export interface ConsoleCallbacks {
|
|
|
24
24
|
|
|
25
25
|
export interface CompileOptions {
|
|
26
26
|
inputs?: string[];
|
|
27
|
+
lenientMode?: boolean;
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
export type SnapshotKey = string | Buffer | Uint8Array;
|
|
@@ -203,7 +204,7 @@ export class Mustard {
|
|
|
203
204
|
start(options?: ExecutionOptions): StructuredValue | Progress;
|
|
204
205
|
dump(): Buffer;
|
|
205
206
|
|
|
206
|
-
static validateProgram(code: string): void;
|
|
207
|
+
static validateProgram(code: string, options?: CompileOptions): void;
|
|
207
208
|
static load(buffer: Buffer): Mustard;
|
|
208
209
|
}
|
|
209
210
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mustardscript",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Sandboxed, subset JavaScript runtime for Node services.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "mustard.d.ts",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
]
|
|
29
29
|
},
|
|
30
30
|
"optionalDependencies": {
|
|
31
|
-
"@mustardscript/binding-darwin-arm64": "0.2.
|
|
32
|
-
"@mustardscript/binding-darwin-x64": "0.2.
|
|
33
|
-
"@mustardscript/binding-linux-x64-gnu": "0.2.
|
|
34
|
-
"@mustardscript/binding-win32-x64-msvc": "0.2.
|
|
31
|
+
"@mustardscript/binding-darwin-arm64": "0.2.1",
|
|
32
|
+
"@mustardscript/binding-darwin-x64": "0.2.1",
|
|
33
|
+
"@mustardscript/binding-linux-x64-gnu": "0.2.1",
|
|
34
|
+
"@mustardscript/binding-win32-x64-msvc": "0.2.1"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"prepack": "node scripts/build-ts-dist.ts",
|