mustardscript 0.1.0

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.
Files changed (99) hide show
  1. package/Cargo.lock +1579 -0
  2. package/Cargo.toml +40 -0
  3. package/LICENSE +201 -0
  4. package/README.md +828 -0
  5. package/SECURITY.md +34 -0
  6. package/crates/mustard/Cargo.toml +31 -0
  7. package/crates/mustard/src/cancellation.rs +28 -0
  8. package/crates/mustard/src/diagnostic.rs +145 -0
  9. package/crates/mustard/src/ir.rs +435 -0
  10. package/crates/mustard/src/lib.rs +21 -0
  11. package/crates/mustard/src/limits.rs +22 -0
  12. package/crates/mustard/src/parser/expressions.rs +723 -0
  13. package/crates/mustard/src/parser/mod.rs +115 -0
  14. package/crates/mustard/src/parser/operators.rs +105 -0
  15. package/crates/mustard/src/parser/patterns.rs +123 -0
  16. package/crates/mustard/src/parser/scope.rs +107 -0
  17. package/crates/mustard/src/parser/statements.rs +298 -0
  18. package/crates/mustard/src/parser/tests/acceptance.rs +339 -0
  19. package/crates/mustard/src/parser/tests/mod.rs +2 -0
  20. package/crates/mustard/src/parser/tests/rejections.rs +107 -0
  21. package/crates/mustard/src/runtime/accounting.rs +613 -0
  22. package/crates/mustard/src/runtime/api.rs +192 -0
  23. package/crates/mustard/src/runtime/async_runtime/mod.rs +5 -0
  24. package/crates/mustard/src/runtime/async_runtime/promises.rs +246 -0
  25. package/crates/mustard/src/runtime/async_runtime/reactions.rs +400 -0
  26. package/crates/mustard/src/runtime/async_runtime/scheduler.rs +224 -0
  27. package/crates/mustard/src/runtime/builtins/arrays.rs +1205 -0
  28. package/crates/mustard/src/runtime/builtins/collections.rs +573 -0
  29. package/crates/mustard/src/runtime/builtins/install.rs +501 -0
  30. package/crates/mustard/src/runtime/builtins/intl.rs +553 -0
  31. package/crates/mustard/src/runtime/builtins/mod.rs +25 -0
  32. package/crates/mustard/src/runtime/builtins/objects.rs +405 -0
  33. package/crates/mustard/src/runtime/builtins/primitives.rs +859 -0
  34. package/crates/mustard/src/runtime/builtins/promises.rs +335 -0
  35. package/crates/mustard/src/runtime/builtins/regexp.rs +356 -0
  36. package/crates/mustard/src/runtime/builtins/strings.rs +803 -0
  37. package/crates/mustard/src/runtime/builtins/support.rs +561 -0
  38. package/crates/mustard/src/runtime/bytecode.rs +123 -0
  39. package/crates/mustard/src/runtime/compiler/assignments.rs +690 -0
  40. package/crates/mustard/src/runtime/compiler/bindings.rs +92 -0
  41. package/crates/mustard/src/runtime/compiler/context.rs +46 -0
  42. package/crates/mustard/src/runtime/compiler/control.rs +342 -0
  43. package/crates/mustard/src/runtime/compiler/expressions.rs +372 -0
  44. package/crates/mustard/src/runtime/compiler/mod.rs +173 -0
  45. package/crates/mustard/src/runtime/compiler/statements.rs +459 -0
  46. package/crates/mustard/src/runtime/conversions/boundary.rs +293 -0
  47. package/crates/mustard/src/runtime/conversions/coercions.rs +217 -0
  48. package/crates/mustard/src/runtime/conversions/errors.rs +118 -0
  49. package/crates/mustard/src/runtime/conversions/mod.rs +14 -0
  50. package/crates/mustard/src/runtime/conversions/operators.rs +334 -0
  51. package/crates/mustard/src/runtime/env.rs +355 -0
  52. package/crates/mustard/src/runtime/exceptions.rs +377 -0
  53. package/crates/mustard/src/runtime/gc.rs +595 -0
  54. package/crates/mustard/src/runtime/mod.rs +318 -0
  55. package/crates/mustard/src/runtime/properties.rs +1762 -0
  56. package/crates/mustard/src/runtime/serialization.rs +127 -0
  57. package/crates/mustard/src/runtime/shared.rs +108 -0
  58. package/crates/mustard/src/runtime/snapshot_validation_tests.rs +93 -0
  59. package/crates/mustard/src/runtime/state.rs +652 -0
  60. package/crates/mustard/src/runtime/tests/async_host.rs +104 -0
  61. package/crates/mustard/src/runtime/tests/collections.rs +50 -0
  62. package/crates/mustard/src/runtime/tests/diagnostics.rs +36 -0
  63. package/crates/mustard/src/runtime/tests/exceptions.rs +122 -0
  64. package/crates/mustard/src/runtime/tests/execution.rs +553 -0
  65. package/crates/mustard/src/runtime/tests/gc.rs +533 -0
  66. package/crates/mustard/src/runtime/tests/mod.rs +56 -0
  67. package/crates/mustard/src/runtime/tests/serialization.rs +170 -0
  68. package/crates/mustard/src/runtime/validation/bytecode.rs +484 -0
  69. package/crates/mustard/src/runtime/validation/mod.rs +14 -0
  70. package/crates/mustard/src/runtime/validation/policy.rs +94 -0
  71. package/crates/mustard/src/runtime/validation/snapshot.rs +406 -0
  72. package/crates/mustard/src/runtime/validation/walk.rs +206 -0
  73. package/crates/mustard/src/runtime/vm.rs +1016 -0
  74. package/crates/mustard/src/span.rs +22 -0
  75. package/crates/mustard/src/structured.rs +107 -0
  76. package/crates/mustard-bridge/Cargo.toml +17 -0
  77. package/crates/mustard-bridge/src/codec.rs +46 -0
  78. package/crates/mustard-bridge/src/dto.rs +99 -0
  79. package/crates/mustard-bridge/src/lib.rs +12 -0
  80. package/crates/mustard-bridge/src/operations.rs +142 -0
  81. package/crates/mustard-node/Cargo.toml +24 -0
  82. package/crates/mustard-node/build.rs +3 -0
  83. package/crates/mustard-node/src/lib.rs +236 -0
  84. package/crates/mustard-sidecar/Cargo.toml +21 -0
  85. package/crates/mustard-sidecar/src/lib.rs +134 -0
  86. package/crates/mustard-sidecar/src/main.rs +36 -0
  87. package/dist/index.js +20 -0
  88. package/dist/install.js +117 -0
  89. package/dist/lib/cancellation.js +124 -0
  90. package/dist/lib/errors.js +46 -0
  91. package/dist/lib/executor.js +555 -0
  92. package/dist/lib/policy.js +292 -0
  93. package/dist/lib/progress.js +356 -0
  94. package/dist/lib/runtime.js +109 -0
  95. package/dist/lib/structured.js +286 -0
  96. package/dist/native-loader.js +227 -0
  97. package/index.d.ts +23 -0
  98. package/mustard.d.ts +220 -0
  99. package/package.json +97 -0
package/mustard.d.ts ADDED
@@ -0,0 +1,220 @@
1
+ export type StructuredValue =
2
+ | undefined
3
+ | null
4
+ | boolean
5
+ | number
6
+ | string
7
+ | StructuredValue[]
8
+ | { [key: string]: StructuredValue };
9
+
10
+ export interface CapabilityError extends Error {
11
+ code?: string;
12
+ details?: StructuredValue;
13
+ }
14
+
15
+ export type Capability = (
16
+ ...args: StructuredValue[]
17
+ ) => StructuredValue | Promise<StructuredValue>;
18
+
19
+ export interface ConsoleCallbacks {
20
+ log?: Capability;
21
+ warn?: Capability;
22
+ error?: Capability;
23
+ }
24
+
25
+ export interface CompileOptions {
26
+ inputs?: string[];
27
+ }
28
+
29
+ export type SnapshotKey = string | Buffer | Uint8Array;
30
+
31
+ export interface ExecutionOptions {
32
+ inputs?: Record<string, StructuredValue>;
33
+ capabilities?: Record<string, Capability>;
34
+ console?: ConsoleCallbacks;
35
+ limits?: RuntimeLimits;
36
+ signal?: AbortSignal;
37
+ snapshotKey?: SnapshotKey;
38
+ }
39
+
40
+ export interface ResumeOptions {
41
+ signal?: AbortSignal;
42
+ }
43
+
44
+ export interface ProgressLoadOptionsBase {
45
+ limits: RuntimeLimits;
46
+ snapshotKey: SnapshotKey;
47
+ }
48
+
49
+ export type ProgressLoadOptions =
50
+ | (ProgressLoadOptionsBase & {
51
+ capabilities: Record<string, Capability>;
52
+ console?: ConsoleCallbacks;
53
+ })
54
+ | (ProgressLoadOptionsBase & {
55
+ capabilities?: Record<string, Capability>;
56
+ console: ConsoleCallbacks;
57
+ });
58
+
59
+ export interface RuntimeLimits {
60
+ instructionBudget?: number;
61
+ heapLimitBytes?: number;
62
+ allocationBudget?: number;
63
+ callDepthLimit?: number;
64
+ maxOutstandingHostCalls?: number;
65
+ }
66
+
67
+ export type MustardJobId = string;
68
+
69
+ export type MustardJobState =
70
+ | 'queued'
71
+ | 'running'
72
+ | 'waiting'
73
+ | 'completed'
74
+ | 'failed'
75
+ | 'cancelled';
76
+
77
+ export interface MustardJobError {
78
+ name: string;
79
+ message: string;
80
+ code?: string;
81
+ details?: StructuredValue;
82
+ }
83
+
84
+ export interface MustardJobRecord<
85
+ TInput extends Record<string, StructuredValue> = Record<string, StructuredValue>,
86
+ TResult extends StructuredValue = StructuredValue,
87
+ > {
88
+ jobId: MustardJobId;
89
+ state: MustardJobState;
90
+ input: TInput;
91
+ capability?: string;
92
+ args?: StructuredValue[];
93
+ result?: TResult;
94
+ error?: MustardJobError;
95
+ attempts: number;
96
+ createdAt: number;
97
+ updatedAt: number;
98
+ }
99
+
100
+ export interface PersistedProgress extends SerializedProgress {}
101
+
102
+ export interface MustardExecutorStore<
103
+ TInput extends Record<string, StructuredValue> = Record<string, StructuredValue>,
104
+ TResult extends StructuredValue = StructuredValue,
105
+ > {
106
+ enqueue(record: MustardJobRecord<TInput, TResult>): Promise<{
107
+ jobId: MustardJobId;
108
+ inserted: boolean;
109
+ }>;
110
+ get(jobId: MustardJobId): Promise<MustardJobRecord<TInput, TResult> | null>;
111
+ claimRunnable(limit: number, workerId: string, now: number): Promise<MustardJobId[]>;
112
+ releaseClaim(jobId: MustardJobId, workerId: string): Promise<void>;
113
+ update(
114
+ jobId: MustardJobId,
115
+ patch: Partial<MustardJobRecord<TInput, TResult>>,
116
+ ): Promise<void>;
117
+ saveProgress(jobId: MustardJobId, progress: PersistedProgress): Promise<void>;
118
+ loadProgress(jobId: MustardJobId): Promise<PersistedProgress | null>;
119
+ deleteProgress(jobId: MustardJobId): Promise<void>;
120
+ requestCancel(jobId: MustardJobId): Promise<'cancelled' | 'requested' | 'ignored'>;
121
+ consumeCancel(jobId: MustardJobId): Promise<boolean>;
122
+ }
123
+
124
+ export interface MustardExecutorOptions<
125
+ TInput extends Record<string, StructuredValue> = Record<string, StructuredValue>,
126
+ TResult extends StructuredValue = StructuredValue,
127
+ > {
128
+ program: Mustard;
129
+ capabilities: Record<string, Capability>;
130
+ snapshotKey?: SnapshotKey;
131
+ store: MustardExecutorStore<TInput, TResult>;
132
+ limits?: RuntimeLimits;
133
+ }
134
+
135
+ export interface MustardExecutorRunWorkerOptions {
136
+ maxConcurrentJobs?: number;
137
+ signal?: AbortSignal;
138
+ drain?: boolean;
139
+ }
140
+
141
+ export type MustardErrorKind =
142
+ | 'Parse'
143
+ | 'Validation'
144
+ | 'Runtime'
145
+ | 'Limit'
146
+ | 'Serialization';
147
+
148
+ export class MustardError extends Error {
149
+ constructor(kind: MustardErrorKind, message: string, cause?: unknown);
150
+
151
+ readonly kind: MustardErrorKind;
152
+ readonly cause?: unknown;
153
+ }
154
+
155
+ export interface SerializedProgress {
156
+ capability: string;
157
+ args: StructuredValue[];
158
+ snapshot: Buffer;
159
+ snapshot_id: string;
160
+ snapshot_key_digest: string;
161
+ token: string;
162
+ }
163
+
164
+ export class Progress {
165
+ readonly capability: string;
166
+ readonly args: StructuredValue[];
167
+ readonly snapshot: Buffer;
168
+
169
+ dump(): SerializedProgress;
170
+ resume(value: StructuredValue, options?: ResumeOptions): StructuredValue | Progress;
171
+ resumeError(error: unknown, options?: ResumeOptions): StructuredValue | Progress;
172
+ cancel(): StructuredValue | Progress;
173
+
174
+ static load(state: SerializedProgress, options: ProgressLoadOptions): Progress;
175
+ }
176
+
177
+ export class Mustard {
178
+ constructor(code: string, options?: CompileOptions);
179
+
180
+ run(options?: ExecutionOptions): Promise<StructuredValue>;
181
+ start(options?: ExecutionOptions): StructuredValue | Progress;
182
+ dump(): Buffer;
183
+
184
+ static validateProgram(code: string): void;
185
+ static load(buffer: Buffer): Mustard;
186
+ }
187
+
188
+ export class InMemoryMustardExecutorStore<
189
+ TInput extends Record<string, StructuredValue> = Record<string, StructuredValue>,
190
+ TResult extends StructuredValue = StructuredValue,
191
+ > implements MustardExecutorStore<TInput, TResult> {
192
+ enqueue(record: MustardJobRecord<TInput, TResult>): Promise<{
193
+ jobId: MustardJobId;
194
+ inserted: boolean;
195
+ }>;
196
+ get(jobId: MustardJobId): Promise<MustardJobRecord<TInput, TResult> | null>;
197
+ claimRunnable(limit: number, workerId: string, now: number): Promise<MustardJobId[]>;
198
+ releaseClaim(jobId: MustardJobId, workerId: string): Promise<void>;
199
+ update(
200
+ jobId: MustardJobId,
201
+ patch: Partial<MustardJobRecord<TInput, TResult>>,
202
+ ): Promise<void>;
203
+ saveProgress(jobId: MustardJobId, progress: PersistedProgress): Promise<void>;
204
+ loadProgress(jobId: MustardJobId): Promise<PersistedProgress | null>;
205
+ deleteProgress(jobId: MustardJobId): Promise<void>;
206
+ requestCancel(jobId: MustardJobId): Promise<'cancelled' | 'requested' | 'ignored'>;
207
+ consumeCancel(jobId: MustardJobId): Promise<boolean>;
208
+ }
209
+
210
+ export class MustardExecutor<
211
+ TInput extends Record<string, StructuredValue> = Record<string, StructuredValue>,
212
+ TResult extends StructuredValue = StructuredValue,
213
+ > {
214
+ constructor(options: MustardExecutorOptions<TInput, TResult>);
215
+
216
+ enqueue(input: TInput, options?: { jobId?: MustardJobId }): Promise<MustardJobId>;
217
+ get(jobId: MustardJobId): Promise<MustardJobRecord<TInput, TResult> | null>;
218
+ cancel(jobId: MustardJobId): Promise<void>;
219
+ runWorker(options?: MustardExecutorRunWorkerOptions): Promise<void>;
220
+ }
package/package.json ADDED
@@ -0,0 +1,97 @@
1
+ {
2
+ "name": "mustardscript",
3
+ "version": "0.1.0",
4
+ "description": "Sandboxed, subset JavaScript runtime for Node services.",
5
+ "main": "dist/index.js",
6
+ "types": "mustard.d.ts",
7
+ "files": [
8
+ "Cargo.lock",
9
+ "Cargo.toml",
10
+ "LICENSE",
11
+ "SECURITY.md",
12
+ "dist",
13
+ "index.d.ts",
14
+ "mustard.d.ts",
15
+ "crates/mustard/Cargo.toml",
16
+ "crates/mustard/src/**",
17
+ "crates/mustard-bridge/Cargo.toml",
18
+ "crates/mustard-bridge/src/**",
19
+ "crates/mustard-node/Cargo.toml",
20
+ "crates/mustard-node/build.rs",
21
+ "crates/mustard-node/src/**",
22
+ "crates/mustard-sidecar/Cargo.toml",
23
+ "crates/mustard-sidecar/src/**"
24
+ ],
25
+ "directories": {
26
+ "doc": "docs",
27
+ "example": "examples",
28
+ "test": "tests"
29
+ },
30
+ "napi": {
31
+ "binaryName": "index",
32
+ "packageName": "mustardscript",
33
+ "targets": [
34
+ "x86_64-pc-windows-msvc",
35
+ "x86_64-apple-darwin",
36
+ "aarch64-apple-darwin",
37
+ "x86_64-unknown-linux-gnu"
38
+ ]
39
+ },
40
+ "optionalDependencies": {
41
+ "mustardscript-darwin-arm64": "0.1.0",
42
+ "mustardscript-darwin-x64": "0.1.0",
43
+ "mustardscript-linux-x64-gnu": "0.1.0",
44
+ "mustardscript-win32-x64-msvc": "0.1.0"
45
+ },
46
+ "scripts": {
47
+ "install": "node -e \"const fs=require('node:fs'); const cp=require('node:child_process'); if (!fs.existsSync('dist/install.js')) { cp.execFileSync(process.execPath, ['scripts/build-ts-dist.ts'], { stdio: 'inherit' }); } cp.execFileSync(process.execPath, ['dist/install.js'], { stdio: 'inherit' });\"",
48
+ "prepack": "node scripts/build-ts-dist.ts",
49
+ "build": "node scripts/build-ts-dist.ts && napi build --platform --manifest-path crates/mustard-node/Cargo.toml --js-package-name mustardscript --output-dir . --no-js",
50
+ "ralph-loop": "node scripts/ralph-loop.ts",
51
+ "test": "npm run build && node --test tests/node/**/*.test.js && npm run test:types && npm run test:package-smoke",
52
+ "test:conformance": "npm run test:differential && npm run test:test262",
53
+ "test:differential": "node --test tests/node/differential.test.js tests/node/ast-conformance.test.js tests/node/property-differential.test.js tests/node/coverage-audit.test.js",
54
+ "test:node": "node --test tests/node/**/*.test.js",
55
+ "test:use-cases": "node scripts/audit-use-cases.ts",
56
+ "test:package-smoke": "node --test tests/package-smoke.test.js",
57
+ "test:test262": "node --test tests/test262/**/*.test.js",
58
+ "test:types": "tsc --noEmit -p tsconfig.typecheck.json",
59
+ "test:rust": "cargo test --workspace",
60
+ "test:hardening": "scripts/run-hardening.sh",
61
+ "test:mutation-guards": "npm run build && node --test tests/hardening/**/*.test.js",
62
+ "seed:fuzz-corpus": "node scripts/seed-fuzz-corpus.ts",
63
+ "bench:smoke": "npm run build && node --expose-gc benchmarks/smoke.ts",
64
+ "prebuilt:dirs": "napi create-npm-dirs",
65
+ "prebuilt:artifacts": "napi artifacts --output-dir artifacts",
66
+ "verify:prebuilt": "node scripts/verify-prebuilt.ts",
67
+ "verify:release": "node scripts/release-verify.ts",
68
+ "lint": "cargo fmt --all --check && cargo clippy --workspace --all-targets -- -D warnings"
69
+ },
70
+ "repository": {
71
+ "type": "git",
72
+ "url": "git+https://github.com/keppoai/mustardscript.git"
73
+ },
74
+ "keywords": [
75
+ "javascript",
76
+ "runtime",
77
+ "sandbox",
78
+ "napi",
79
+ "vm"
80
+ ],
81
+ "author": "",
82
+ "license": "Apache-2.0",
83
+ "type": "commonjs",
84
+ "devDependencies": {
85
+ "@napi-rs/cli": "^3.3.0",
86
+ "@types/node": "^25.6.0",
87
+ "fast-check": "^4.6.0",
88
+ "typescript": "^6.0.2"
89
+ },
90
+ "bugs": {
91
+ "url": "https://github.com/keppoai/mustardscript/issues"
92
+ },
93
+ "homepage": "https://github.com/keppoai/mustardscript#readme",
94
+ "publishConfig": {
95
+ "access": "public"
96
+ }
97
+ }