@pydantic/monty 0.0.3 → 0.0.4

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 (4) hide show
  1. package/index.js +52 -52
  2. package/package.json +6 -6
  3. package/wrapper.d.ts +225 -0
  4. package/wrapper.js +423 -0
package/index.js CHANGED
@@ -81,8 +81,8 @@ function requireNative() {
81
81
  try {
82
82
  const binding = require('@pydantic/monty-android-arm64')
83
83
  const bindingPackageVersion = require('@pydantic/monty-android-arm64/package.json').version
84
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
85
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
84
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
85
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
86
86
  }
87
87
  return binding
88
88
  } catch (e) {
@@ -97,8 +97,8 @@ function requireNative() {
97
97
  try {
98
98
  const binding = require('@pydantic/monty-android-arm-eabi')
99
99
  const bindingPackageVersion = require('@pydantic/monty-android-arm-eabi/package.json').version
100
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
101
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
100
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
101
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
102
102
  }
103
103
  return binding
104
104
  } catch (e) {
@@ -118,8 +118,8 @@ function requireNative() {
118
118
  try {
119
119
  const binding = require('@pydantic/monty-win32-x64-gnu')
120
120
  const bindingPackageVersion = require('@pydantic/monty-win32-x64-gnu/package.json').version
121
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
122
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
121
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
122
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
123
123
  }
124
124
  return binding
125
125
  } catch (e) {
@@ -134,8 +134,8 @@ function requireNative() {
134
134
  try {
135
135
  const binding = require('@pydantic/monty-win32-x64-msvc')
136
136
  const bindingPackageVersion = require('@pydantic/monty-win32-x64-msvc/package.json').version
137
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
138
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
137
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
138
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
139
139
  }
140
140
  return binding
141
141
  } catch (e) {
@@ -151,8 +151,8 @@ function requireNative() {
151
151
  try {
152
152
  const binding = require('@pydantic/monty-win32-ia32-msvc')
153
153
  const bindingPackageVersion = require('@pydantic/monty-win32-ia32-msvc/package.json').version
154
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
155
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
154
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
155
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
156
156
  }
157
157
  return binding
158
158
  } catch (e) {
@@ -167,8 +167,8 @@ function requireNative() {
167
167
  try {
168
168
  const binding = require('@pydantic/monty-win32-arm64-msvc')
169
169
  const bindingPackageVersion = require('@pydantic/monty-win32-arm64-msvc/package.json').version
170
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
171
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
170
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
171
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
172
172
  }
173
173
  return binding
174
174
  } catch (e) {
@@ -186,8 +186,8 @@ function requireNative() {
186
186
  try {
187
187
  const binding = require('@pydantic/monty-darwin-universal')
188
188
  const bindingPackageVersion = require('@pydantic/monty-darwin-universal/package.json').version
189
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
190
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
189
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
190
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
191
191
  }
192
192
  return binding
193
193
  } catch (e) {
@@ -202,8 +202,8 @@ function requireNative() {
202
202
  try {
203
203
  const binding = require('@pydantic/monty-darwin-x64')
204
204
  const bindingPackageVersion = require('@pydantic/monty-darwin-x64/package.json').version
205
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
206
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
205
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
206
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
207
207
  }
208
208
  return binding
209
209
  } catch (e) {
@@ -218,8 +218,8 @@ function requireNative() {
218
218
  try {
219
219
  const binding = require('@pydantic/monty-darwin-arm64')
220
220
  const bindingPackageVersion = require('@pydantic/monty-darwin-arm64/package.json').version
221
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
222
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
221
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
222
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
223
223
  }
224
224
  return binding
225
225
  } catch (e) {
@@ -238,8 +238,8 @@ function requireNative() {
238
238
  try {
239
239
  const binding = require('@pydantic/monty-freebsd-x64')
240
240
  const bindingPackageVersion = require('@pydantic/monty-freebsd-x64/package.json').version
241
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
242
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
241
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
242
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
243
243
  }
244
244
  return binding
245
245
  } catch (e) {
@@ -254,8 +254,8 @@ function requireNative() {
254
254
  try {
255
255
  const binding = require('@pydantic/monty-freebsd-arm64')
256
256
  const bindingPackageVersion = require('@pydantic/monty-freebsd-arm64/package.json').version
257
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
258
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
257
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
258
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
259
259
  }
260
260
  return binding
261
261
  } catch (e) {
@@ -275,8 +275,8 @@ function requireNative() {
275
275
  try {
276
276
  const binding = require('@pydantic/monty-linux-x64-musl')
277
277
  const bindingPackageVersion = require('@pydantic/monty-linux-x64-musl/package.json').version
278
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
279
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
278
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
279
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
280
280
  }
281
281
  return binding
282
282
  } catch (e) {
@@ -291,8 +291,8 @@ function requireNative() {
291
291
  try {
292
292
  const binding = require('@pydantic/monty-linux-x64-gnu')
293
293
  const bindingPackageVersion = require('@pydantic/monty-linux-x64-gnu/package.json').version
294
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
295
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
294
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
295
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
296
296
  }
297
297
  return binding
298
298
  } catch (e) {
@@ -309,8 +309,8 @@ function requireNative() {
309
309
  try {
310
310
  const binding = require('@pydantic/monty-linux-arm64-musl')
311
311
  const bindingPackageVersion = require('@pydantic/monty-linux-arm64-musl/package.json').version
312
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
313
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
312
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
313
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
314
314
  }
315
315
  return binding
316
316
  } catch (e) {
@@ -325,8 +325,8 @@ function requireNative() {
325
325
  try {
326
326
  const binding = require('@pydantic/monty-linux-arm64-gnu')
327
327
  const bindingPackageVersion = require('@pydantic/monty-linux-arm64-gnu/package.json').version
328
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
329
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
328
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
329
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
330
330
  }
331
331
  return binding
332
332
  } catch (e) {
@@ -343,8 +343,8 @@ function requireNative() {
343
343
  try {
344
344
  const binding = require('@pydantic/monty-linux-arm-musleabihf')
345
345
  const bindingPackageVersion = require('@pydantic/monty-linux-arm-musleabihf/package.json').version
346
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
347
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
346
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
347
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
348
348
  }
349
349
  return binding
350
350
  } catch (e) {
@@ -359,8 +359,8 @@ function requireNative() {
359
359
  try {
360
360
  const binding = require('@pydantic/monty-linux-arm-gnueabihf')
361
361
  const bindingPackageVersion = require('@pydantic/monty-linux-arm-gnueabihf/package.json').version
362
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
363
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
362
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
363
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
364
364
  }
365
365
  return binding
366
366
  } catch (e) {
@@ -377,8 +377,8 @@ function requireNative() {
377
377
  try {
378
378
  const binding = require('@pydantic/monty-linux-loong64-musl')
379
379
  const bindingPackageVersion = require('@pydantic/monty-linux-loong64-musl/package.json').version
380
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
381
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
380
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
381
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
382
382
  }
383
383
  return binding
384
384
  } catch (e) {
@@ -393,8 +393,8 @@ function requireNative() {
393
393
  try {
394
394
  const binding = require('@pydantic/monty-linux-loong64-gnu')
395
395
  const bindingPackageVersion = require('@pydantic/monty-linux-loong64-gnu/package.json').version
396
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
397
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
396
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
397
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
398
398
  }
399
399
  return binding
400
400
  } catch (e) {
@@ -411,8 +411,8 @@ function requireNative() {
411
411
  try {
412
412
  const binding = require('@pydantic/monty-linux-riscv64-musl')
413
413
  const bindingPackageVersion = require('@pydantic/monty-linux-riscv64-musl/package.json').version
414
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
415
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
414
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
415
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
416
416
  }
417
417
  return binding
418
418
  } catch (e) {
@@ -427,8 +427,8 @@ function requireNative() {
427
427
  try {
428
428
  const binding = require('@pydantic/monty-linux-riscv64-gnu')
429
429
  const bindingPackageVersion = require('@pydantic/monty-linux-riscv64-gnu/package.json').version
430
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
431
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
430
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
431
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
432
432
  }
433
433
  return binding
434
434
  } catch (e) {
@@ -444,8 +444,8 @@ function requireNative() {
444
444
  try {
445
445
  const binding = require('@pydantic/monty-linux-ppc64-gnu')
446
446
  const bindingPackageVersion = require('@pydantic/monty-linux-ppc64-gnu/package.json').version
447
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
448
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
447
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
448
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
449
449
  }
450
450
  return binding
451
451
  } catch (e) {
@@ -460,8 +460,8 @@ function requireNative() {
460
460
  try {
461
461
  const binding = require('@pydantic/monty-linux-s390x-gnu')
462
462
  const bindingPackageVersion = require('@pydantic/monty-linux-s390x-gnu/package.json').version
463
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
464
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
463
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
464
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
465
465
  }
466
466
  return binding
467
467
  } catch (e) {
@@ -480,8 +480,8 @@ function requireNative() {
480
480
  try {
481
481
  const binding = require('@pydantic/monty-openharmony-arm64')
482
482
  const bindingPackageVersion = require('@pydantic/monty-openharmony-arm64/package.json').version
483
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
484
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
483
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
484
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
485
485
  }
486
486
  return binding
487
487
  } catch (e) {
@@ -496,8 +496,8 @@ function requireNative() {
496
496
  try {
497
497
  const binding = require('@pydantic/monty-openharmony-x64')
498
498
  const bindingPackageVersion = require('@pydantic/monty-openharmony-x64/package.json').version
499
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
500
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
499
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
500
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
501
501
  }
502
502
  return binding
503
503
  } catch (e) {
@@ -512,8 +512,8 @@ function requireNative() {
512
512
  try {
513
513
  const binding = require('@pydantic/monty-openharmony-arm')
514
514
  const bindingPackageVersion = require('@pydantic/monty-openharmony-arm/package.json').version
515
- if (bindingPackageVersion !== '0.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
516
- throw new Error(`Native binding package version mismatch, expected 0.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
515
+ if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
516
+ throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
517
517
  }
518
518
  return binding
519
519
  } catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pydantic/monty",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
5
  "description": "Sandboxed Python interpreter for JavaScript/TypeScript",
6
6
  "main": "wrapper.js",
@@ -97,10 +97,10 @@
97
97
  "arrowParens": "always"
98
98
  },
99
99
  "optionalDependencies": {
100
- "@pydantic/monty-win32-x64-msvc": "0.0.3",
101
- "@pydantic/monty-darwin-x64": "0.0.3",
102
- "@pydantic/monty-linux-x64-gnu": "0.0.3",
103
- "@pydantic/monty-darwin-arm64": "0.0.3",
104
- "@pydantic/monty-wasm32-wasi": "0.0.3"
100
+ "@pydantic/monty-win32-x64-msvc": "0.0.4",
101
+ "@pydantic/monty-darwin-x64": "0.0.4",
102
+ "@pydantic/monty-linux-x64-gnu": "0.0.4",
103
+ "@pydantic/monty-darwin-arm64": "0.0.4",
104
+ "@pydantic/monty-wasm32-wasi": "0.0.4"
105
105
  }
106
106
  }
package/wrapper.d.ts ADDED
@@ -0,0 +1,225 @@
1
+ import type { MontyOptions, RunOptions, ResourceLimits, Frame, ExceptionInfo, StartOptions, ResumeOptions, ExceptionInput, SnapshotLoadOptions, JsMontyObject } from './index.js';
2
+ import { MontySnapshot as NativeMontySnapshot, MontyComplete as NativeMontyComplete, MontyException as NativeMontyException, MontyTypingError as NativeMontyTypingError } from './index.js';
3
+ export type { MontyOptions, RunOptions, ResourceLimits, Frame, ExceptionInfo, StartOptions, ResumeOptions, ExceptionInput, SnapshotLoadOptions, JsMontyObject, };
4
+ /**
5
+ * Alias for ResourceLimits (deprecated name).
6
+ */
7
+ export type JsResourceLimits = ResourceLimits;
8
+ /**
9
+ * Base class for all Monty interpreter errors.
10
+ *
11
+ * This is the parent class for `MontySyntaxError`, `MontyRuntimeError`, and `MontyTypingError`.
12
+ * Catching `MontyError` will catch any exception raised by Monty.
13
+ */
14
+ export declare class MontyError extends Error {
15
+ protected _typeName: string;
16
+ protected _message: string;
17
+ constructor(typeName: string, message: string);
18
+ /**
19
+ * Returns information about the inner Python exception.
20
+ */
21
+ get exception(): ExceptionInfo;
22
+ /**
23
+ * Returns formatted exception string.
24
+ * @param format - 'type-msg' for 'ExceptionType: message', 'msg' for just the message
25
+ */
26
+ display(format?: 'type-msg' | 'msg'): string;
27
+ }
28
+ /**
29
+ * Raised when Python code has syntax errors or cannot be parsed by Monty.
30
+ *
31
+ * The inner exception is always a `SyntaxError`. Use `display()` to get
32
+ * formatted error output.
33
+ */
34
+ export declare class MontySyntaxError extends MontyError {
35
+ private _native;
36
+ constructor(messageOrNative: string | NativeMontyException);
37
+ /**
38
+ * Returns formatted exception string.
39
+ * @param format - 'type-msg' for 'SyntaxError: message', 'msg' for just the message
40
+ */
41
+ display(format?: 'type-msg' | 'msg'): string;
42
+ }
43
+ /**
44
+ * Raised when Monty code fails during execution.
45
+ *
46
+ * Provides access to the traceback frames where the error occurred via `traceback()`,
47
+ * and formatted output via `display()`.
48
+ */
49
+ export declare class MontyRuntimeError extends MontyError {
50
+ private _native;
51
+ private _tracebackString;
52
+ private _frames;
53
+ constructor(nativeOrTypeName: NativeMontyException | string, message?: string, tracebackString?: string, frames?: Frame[]);
54
+ /**
55
+ * Returns the Monty traceback as an array of Frame objects.
56
+ */
57
+ traceback(): Frame[];
58
+ /**
59
+ * Returns formatted exception string.
60
+ * @param format - 'traceback' for full traceback, 'type-msg' for 'ExceptionType: message', 'msg' for just the message
61
+ */
62
+ display(format?: 'traceback' | 'type-msg' | 'msg'): string;
63
+ }
64
+ export type TypingDisplayFormat = 'full' | 'concise' | 'azure' | 'json' | 'jsonlines' | 'rdjson' | 'pylint' | 'gitlab' | 'github';
65
+ /**
66
+ * Raised when type checking finds errors in the code.
67
+ *
68
+ * This exception is raised when static type analysis detects type errors.
69
+ * Use `displayDiagnostics()` to render rich diagnostics in various formats for tooling integration.
70
+ * Use `display()` (inherited) for simple 'type-msg' or 'msg' formats.
71
+ */
72
+ export declare class MontyTypingError extends MontyError {
73
+ private _native;
74
+ constructor(messageOrNative: string | NativeMontyTypingError, nativeError?: NativeMontyTypingError | null);
75
+ /**
76
+ * Renders rich type error diagnostics for tooling integration.
77
+ *
78
+ * @param format - Output format (default: 'full')
79
+ * @param color - Include ANSI color codes (default: false)
80
+ */
81
+ displayDiagnostics(format?: TypingDisplayFormat, color?: boolean): string;
82
+ }
83
+ /**
84
+ * Wrapped Monty class that throws proper Error subclasses.
85
+ */
86
+ export declare class Monty {
87
+ private _native;
88
+ /**
89
+ * Creates a new Monty interpreter by parsing the given code.
90
+ *
91
+ * @param code - Python code to execute
92
+ * @param options - Configuration options
93
+ * @throws {MontySyntaxError} If the code has syntax errors
94
+ * @throws {MontyTypingError} If type checking is enabled and finds errors
95
+ */
96
+ constructor(code: string, options?: MontyOptions);
97
+ /**
98
+ * Performs static type checking on the code.
99
+ *
100
+ * @param prefixCode - Optional code to prepend before type checking
101
+ * @throws {MontyTypingError} If type checking finds errors
102
+ */
103
+ typeCheck(prefixCode?: string): void;
104
+ /**
105
+ * Executes the code and returns the result.
106
+ *
107
+ * @param options - Execution options (inputs, limits)
108
+ * @returns The result of the last expression
109
+ * @throws {MontyRuntimeError} If the code raises an exception
110
+ */
111
+ run(options?: RunOptions): JsMontyObject;
112
+ /**
113
+ * Starts execution and returns either a snapshot (paused at external call) or completion.
114
+ *
115
+ * @param options - Execution options (inputs, limits)
116
+ * @returns MontySnapshot if an external function call is pending, MontyComplete if done
117
+ * @throws {MontyRuntimeError} If the code raises an exception
118
+ */
119
+ start(options?: StartOptions): MontySnapshot | MontyComplete;
120
+ /**
121
+ * Serializes the Monty instance to a binary format.
122
+ */
123
+ dump(): Buffer;
124
+ /**
125
+ * Deserializes a Monty instance from binary format.
126
+ */
127
+ static load(data: Buffer): Monty;
128
+ /** Returns the script name. */
129
+ get scriptName(): string;
130
+ /** Returns the input variable names. */
131
+ get inputs(): string[];
132
+ /** Returns the external function names. */
133
+ get externalFunctions(): string[];
134
+ /** Returns a string representation of the Monty instance. */
135
+ repr(): string;
136
+ }
137
+ /**
138
+ * Represents paused execution waiting for an external function call return value.
139
+ *
140
+ * Contains information about the pending external function call and allows
141
+ * resuming execution with the return value or an exception.
142
+ */
143
+ export declare class MontySnapshot {
144
+ private _native;
145
+ constructor(nativeSnapshot: NativeMontySnapshot);
146
+ /** Returns the name of the script being executed. */
147
+ get scriptName(): string;
148
+ /** Returns the name of the external function being called. */
149
+ get functionName(): string;
150
+ /** Returns the positional arguments passed to the external function. */
151
+ get args(): JsMontyObject[];
152
+ /** Returns the keyword arguments passed to the external function as an object. */
153
+ get kwargs(): Record<string, JsMontyObject>;
154
+ /**
155
+ * Resumes execution with either a return value or an exception.
156
+ *
157
+ * @param options - Object with either `returnValue` or `exception`
158
+ * @returns MontySnapshot if another external call is pending, MontyComplete if done
159
+ * @throws {MontyRuntimeError} If the code raises an exception
160
+ */
161
+ resume(options: ResumeOptions): MontySnapshot | MontyComplete;
162
+ /**
163
+ * Serializes the MontySnapshot to a binary format.
164
+ */
165
+ dump(): Buffer;
166
+ /**
167
+ * Deserializes a MontySnapshot from binary format.
168
+ */
169
+ static load(data: Buffer, options?: SnapshotLoadOptions): MontySnapshot;
170
+ /** Returns a string representation of the MontySnapshot. */
171
+ repr(): string;
172
+ }
173
+ /**
174
+ * Represents completed execution with a final output value.
175
+ */
176
+ export declare class MontyComplete {
177
+ private _native;
178
+ constructor(nativeComplete: NativeMontyComplete);
179
+ /** Returns the final output value from the executed code. */
180
+ get output(): JsMontyObject;
181
+ /** Returns a string representation of the MontyComplete. */
182
+ repr(): string;
183
+ }
184
+ /**
185
+ * Options for `runMontyAsync`.
186
+ */
187
+ export interface RunMontyAsyncOptions {
188
+ /** Input values for the script. */
189
+ inputs?: Record<string, JsMontyObject>;
190
+ /** External function implementations (sync or async). */
191
+ externalFunctions?: Record<string, (...args: unknown[]) => unknown>;
192
+ /** Resource limits. */
193
+ limits?: ResourceLimits;
194
+ }
195
+ /**
196
+ * Runs a Monty script with async external function support.
197
+ *
198
+ * This function handles both synchronous and asynchronous external functions.
199
+ * When an external function returns a Promise, it will be awaited before
200
+ * resuming execution.
201
+ *
202
+ * @param montyRunner - The Monty runner instance to execute
203
+ * @param options - Execution options
204
+ * @returns The output of the Monty script
205
+ * @throws {MontyRuntimeError} If the code raises an exception
206
+ * @throws {MontySyntaxError} If the code has syntax errors
207
+ *
208
+ * @example
209
+ * const m = new Monty('result = await fetch_data(url)', {
210
+ * inputs: ['url'],
211
+ * externalFunctions: ['fetch_data']
212
+ * });
213
+ *
214
+ * const result = await runMontyAsync(m, {
215
+ * inputs: { url: 'https://example.com' },
216
+ * externalFunctions: {
217
+ * fetch_data: async (url) => {
218
+ * const response = await fetch(url);
219
+ * return response.text();
220
+ * }
221
+ * }
222
+ * });
223
+ */
224
+ export declare function runMontyAsync(montyRunner: Monty, options?: RunMontyAsyncOptions): Promise<JsMontyObject>;
225
+ //# sourceMappingURL=wrapper.d.ts.map
package/wrapper.js ADDED
@@ -0,0 +1,423 @@
1
+ // Custom error classes that extend Error for proper JavaScript error handling.
2
+ // These wrap the native Rust classes to provide instanceof support.
3
+ import { Monty as NativeMonty, MontySnapshot as NativeMontySnapshot, MontyComplete as NativeMontyComplete, MontyException as NativeMontyException, MontyTypingError as NativeMontyTypingError, } from './index.js';
4
+ /**
5
+ * Base class for all Monty interpreter errors.
6
+ *
7
+ * This is the parent class for `MontySyntaxError`, `MontyRuntimeError`, and `MontyTypingError`.
8
+ * Catching `MontyError` will catch any exception raised by Monty.
9
+ */
10
+ export class MontyError extends Error {
11
+ constructor(typeName, message) {
12
+ super(message ? `${typeName}: ${message}` : typeName);
13
+ this.name = 'MontyError';
14
+ this._typeName = typeName;
15
+ this._message = message;
16
+ // Maintains proper stack trace for where our error was thrown (only available on V8)
17
+ if (Error.captureStackTrace) {
18
+ Error.captureStackTrace(this, MontyError);
19
+ }
20
+ }
21
+ /**
22
+ * Returns information about the inner Python exception.
23
+ */
24
+ get exception() {
25
+ return {
26
+ typeName: this._typeName,
27
+ message: this._message,
28
+ };
29
+ }
30
+ /**
31
+ * Returns formatted exception string.
32
+ * @param format - 'type-msg' for 'ExceptionType: message', 'msg' for just the message
33
+ */
34
+ display(format = 'msg') {
35
+ switch (format) {
36
+ case 'msg':
37
+ return this._message;
38
+ case 'type-msg':
39
+ return this._message ? `${this._typeName}: ${this._message}` : this._typeName;
40
+ default:
41
+ throw new Error(`Invalid display format: '${format}'. Expected 'type-msg' or 'msg'`);
42
+ }
43
+ }
44
+ }
45
+ /**
46
+ * Raised when Python code has syntax errors or cannot be parsed by Monty.
47
+ *
48
+ * The inner exception is always a `SyntaxError`. Use `display()` to get
49
+ * formatted error output.
50
+ */
51
+ export class MontySyntaxError extends MontyError {
52
+ constructor(messageOrNative) {
53
+ if (typeof messageOrNative === 'string') {
54
+ super('SyntaxError', messageOrNative);
55
+ this._native = null;
56
+ }
57
+ else {
58
+ const exc = messageOrNative.exception;
59
+ super('SyntaxError', exc.message);
60
+ this._native = messageOrNative;
61
+ }
62
+ this.name = 'MontySyntaxError';
63
+ if (Error.captureStackTrace) {
64
+ Error.captureStackTrace(this, MontySyntaxError);
65
+ }
66
+ }
67
+ /**
68
+ * Returns formatted exception string.
69
+ * @param format - 'type-msg' for 'SyntaxError: message', 'msg' for just the message
70
+ */
71
+ display(format = 'msg') {
72
+ if (this._native && typeof this._native.display === 'function') {
73
+ return this._native.display(format);
74
+ }
75
+ return super.display(format);
76
+ }
77
+ }
78
+ /**
79
+ * Raised when Monty code fails during execution.
80
+ *
81
+ * Provides access to the traceback frames where the error occurred via `traceback()`,
82
+ * and formatted output via `display()`.
83
+ */
84
+ export class MontyRuntimeError extends MontyError {
85
+ constructor(nativeOrTypeName, message, tracebackString, frames) {
86
+ if (typeof nativeOrTypeName === 'string') {
87
+ // Legacy constructor: (typeName, message, tracebackString, frames)
88
+ super(nativeOrTypeName, message);
89
+ this._native = null;
90
+ this._tracebackString = tracebackString ?? null;
91
+ this._frames = frames ?? null;
92
+ }
93
+ else {
94
+ // New constructor: (nativeException)
95
+ const exc = nativeOrTypeName.exception;
96
+ super(exc.typeName, exc.message);
97
+ this._native = nativeOrTypeName;
98
+ this._tracebackString = null;
99
+ this._frames = null;
100
+ }
101
+ this.name = 'MontyRuntimeError';
102
+ if (Error.captureStackTrace) {
103
+ Error.captureStackTrace(this, MontyRuntimeError);
104
+ }
105
+ }
106
+ /**
107
+ * Returns the Monty traceback as an array of Frame objects.
108
+ */
109
+ traceback() {
110
+ if (this._native) {
111
+ return this._native.traceback();
112
+ }
113
+ return this._frames || [];
114
+ }
115
+ /**
116
+ * Returns formatted exception string.
117
+ * @param format - 'traceback' for full traceback, 'type-msg' for 'ExceptionType: message', 'msg' for just the message
118
+ */
119
+ display(format = 'traceback') {
120
+ if (this._native && typeof this._native.display === 'function') {
121
+ return this._native.display(format);
122
+ }
123
+ // Fallback for legacy constructor
124
+ switch (format) {
125
+ case 'traceback':
126
+ return this._tracebackString || this.message;
127
+ case 'type-msg':
128
+ return this._message ? `${this._typeName}: ${this._message}` : this._typeName;
129
+ case 'msg':
130
+ return this._message;
131
+ default:
132
+ throw new Error(`Invalid display format: '${format}'. Expected 'traceback', 'type-msg', or 'msg'`);
133
+ }
134
+ }
135
+ }
136
+ /**
137
+ * Raised when type checking finds errors in the code.
138
+ *
139
+ * This exception is raised when static type analysis detects type errors.
140
+ * Use `displayDiagnostics()` to render rich diagnostics in various formats for tooling integration.
141
+ * Use `display()` (inherited) for simple 'type-msg' or 'msg' formats.
142
+ */
143
+ export class MontyTypingError extends MontyError {
144
+ constructor(messageOrNative, nativeError = null) {
145
+ if (typeof messageOrNative === 'string') {
146
+ super('TypeError', messageOrNative);
147
+ this._native = nativeError;
148
+ }
149
+ else {
150
+ const exc = messageOrNative.exception;
151
+ super('TypeError', exc.message);
152
+ this._native = messageOrNative;
153
+ }
154
+ this.name = 'MontyTypingError';
155
+ if (Error.captureStackTrace) {
156
+ Error.captureStackTrace(this, MontyTypingError);
157
+ }
158
+ }
159
+ /**
160
+ * Renders rich type error diagnostics for tooling integration.
161
+ *
162
+ * @param format - Output format (default: 'full')
163
+ * @param color - Include ANSI color codes (default: false)
164
+ */
165
+ displayDiagnostics(format = 'full', color = false) {
166
+ if (this._native && typeof this._native.display === 'function') {
167
+ return this._native.display(format, color);
168
+ }
169
+ return this._message;
170
+ }
171
+ }
172
+ /**
173
+ * Wrapped Monty class that throws proper Error subclasses.
174
+ */
175
+ export class Monty {
176
+ /**
177
+ * Creates a new Monty interpreter by parsing the given code.
178
+ *
179
+ * @param code - Python code to execute
180
+ * @param options - Configuration options
181
+ * @throws {MontySyntaxError} If the code has syntax errors
182
+ * @throws {MontyTypingError} If type checking is enabled and finds errors
183
+ */
184
+ constructor(code, options) {
185
+ const result = NativeMonty.create(code, options);
186
+ if (result instanceof NativeMontyException) {
187
+ // Check typeName to distinguish syntax errors from other exceptions
188
+ if (result.exception.typeName === 'SyntaxError') {
189
+ throw new MontySyntaxError(result);
190
+ }
191
+ throw new MontyRuntimeError(result);
192
+ }
193
+ if (result instanceof NativeMontyTypingError) {
194
+ throw new MontyTypingError(result);
195
+ }
196
+ this._native = result;
197
+ }
198
+ /**
199
+ * Performs static type checking on the code.
200
+ *
201
+ * @param prefixCode - Optional code to prepend before type checking
202
+ * @throws {MontyTypingError} If type checking finds errors
203
+ */
204
+ typeCheck(prefixCode) {
205
+ const result = this._native.typeCheck(prefixCode);
206
+ if (result instanceof NativeMontyTypingError) {
207
+ throw new MontyTypingError(result);
208
+ }
209
+ }
210
+ /**
211
+ * Executes the code and returns the result.
212
+ *
213
+ * @param options - Execution options (inputs, limits)
214
+ * @returns The result of the last expression
215
+ * @throws {MontyRuntimeError} If the code raises an exception
216
+ */
217
+ run(options) {
218
+ const result = this._native.run(options);
219
+ if (result instanceof NativeMontyException) {
220
+ throw new MontyRuntimeError(result);
221
+ }
222
+ return result;
223
+ }
224
+ /**
225
+ * Starts execution and returns either a snapshot (paused at external call) or completion.
226
+ *
227
+ * @param options - Execution options (inputs, limits)
228
+ * @returns MontySnapshot if an external function call is pending, MontyComplete if done
229
+ * @throws {MontyRuntimeError} If the code raises an exception
230
+ */
231
+ start(options) {
232
+ const result = this._native.start(options);
233
+ return wrapStartResult(result);
234
+ }
235
+ /**
236
+ * Serializes the Monty instance to a binary format.
237
+ */
238
+ dump() {
239
+ return this._native.dump();
240
+ }
241
+ /**
242
+ * Deserializes a Monty instance from binary format.
243
+ */
244
+ static load(data) {
245
+ const instance = Object.create(Monty.prototype);
246
+ instance._native = NativeMonty.load(data);
247
+ return instance;
248
+ }
249
+ /** Returns the script name. */
250
+ get scriptName() {
251
+ return this._native.scriptName;
252
+ }
253
+ /** Returns the input variable names. */
254
+ get inputs() {
255
+ return this._native.inputs;
256
+ }
257
+ /** Returns the external function names. */
258
+ get externalFunctions() {
259
+ return this._native.externalFunctions;
260
+ }
261
+ /** Returns a string representation of the Monty instance. */
262
+ repr() {
263
+ return this._native.repr();
264
+ }
265
+ }
266
+ /**
267
+ * Helper to wrap native start/resume results, throwing errors as needed.
268
+ */
269
+ function wrapStartResult(result) {
270
+ if (result instanceof NativeMontyException) {
271
+ throw new MontyRuntimeError(result);
272
+ }
273
+ if (result instanceof NativeMontySnapshot) {
274
+ return new MontySnapshot(result);
275
+ }
276
+ if (result instanceof NativeMontyComplete) {
277
+ return new MontyComplete(result);
278
+ }
279
+ throw new Error(`Unexpected result type from native binding: ${result}`);
280
+ }
281
+ /**
282
+ * Represents paused execution waiting for an external function call return value.
283
+ *
284
+ * Contains information about the pending external function call and allows
285
+ * resuming execution with the return value or an exception.
286
+ */
287
+ export class MontySnapshot {
288
+ constructor(nativeSnapshot) {
289
+ this._native = nativeSnapshot;
290
+ }
291
+ /** Returns the name of the script being executed. */
292
+ get scriptName() {
293
+ return this._native.scriptName;
294
+ }
295
+ /** Returns the name of the external function being called. */
296
+ get functionName() {
297
+ return this._native.functionName;
298
+ }
299
+ /** Returns the positional arguments passed to the external function. */
300
+ get args() {
301
+ return this._native.args;
302
+ }
303
+ /** Returns the keyword arguments passed to the external function as an object. */
304
+ get kwargs() {
305
+ return this._native.kwargs;
306
+ }
307
+ /**
308
+ * Resumes execution with either a return value or an exception.
309
+ *
310
+ * @param options - Object with either `returnValue` or `exception`
311
+ * @returns MontySnapshot if another external call is pending, MontyComplete if done
312
+ * @throws {MontyRuntimeError} If the code raises an exception
313
+ */
314
+ resume(options) {
315
+ const result = this._native.resume(options);
316
+ return wrapStartResult(result);
317
+ }
318
+ /**
319
+ * Serializes the MontySnapshot to a binary format.
320
+ */
321
+ dump() {
322
+ return this._native.dump();
323
+ }
324
+ /**
325
+ * Deserializes a MontySnapshot from binary format.
326
+ */
327
+ static load(data, options) {
328
+ const nativeSnapshot = NativeMontySnapshot.load(data, options);
329
+ return new MontySnapshot(nativeSnapshot);
330
+ }
331
+ /** Returns a string representation of the MontySnapshot. */
332
+ repr() {
333
+ return this._native.repr();
334
+ }
335
+ }
336
+ /**
337
+ * Represents completed execution with a final output value.
338
+ */
339
+ export class MontyComplete {
340
+ constructor(nativeComplete) {
341
+ this._native = nativeComplete;
342
+ }
343
+ /** Returns the final output value from the executed code. */
344
+ get output() {
345
+ return this._native.output;
346
+ }
347
+ /** Returns a string representation of the MontyComplete. */
348
+ repr() {
349
+ return this._native.repr();
350
+ }
351
+ }
352
+ /**
353
+ * Runs a Monty script with async external function support.
354
+ *
355
+ * This function handles both synchronous and asynchronous external functions.
356
+ * When an external function returns a Promise, it will be awaited before
357
+ * resuming execution.
358
+ *
359
+ * @param montyRunner - The Monty runner instance to execute
360
+ * @param options - Execution options
361
+ * @returns The output of the Monty script
362
+ * @throws {MontyRuntimeError} If the code raises an exception
363
+ * @throws {MontySyntaxError} If the code has syntax errors
364
+ *
365
+ * @example
366
+ * const m = new Monty('result = await fetch_data(url)', {
367
+ * inputs: ['url'],
368
+ * externalFunctions: ['fetch_data']
369
+ * });
370
+ *
371
+ * const result = await runMontyAsync(m, {
372
+ * inputs: { url: 'https://example.com' },
373
+ * externalFunctions: {
374
+ * fetch_data: async (url) => {
375
+ * const response = await fetch(url);
376
+ * return response.text();
377
+ * }
378
+ * }
379
+ * });
380
+ */
381
+ export async function runMontyAsync(montyRunner, options = {}) {
382
+ const { inputs, externalFunctions = {}, limits } = options;
383
+ let progress = montyRunner.start({ inputs, limits });
384
+ while (progress instanceof MontySnapshot) {
385
+ const snapshot = progress;
386
+ const funcName = snapshot.functionName;
387
+ const extFunction = externalFunctions[funcName];
388
+ if (!extFunction) {
389
+ // Function not found - resume with a KeyError exception
390
+ progress = snapshot.resume({
391
+ exception: {
392
+ type: 'KeyError',
393
+ message: `"External function '${funcName}' not found"`,
394
+ },
395
+ });
396
+ continue;
397
+ }
398
+ try {
399
+ // Call the external function
400
+ let result = extFunction(...snapshot.args, snapshot.kwargs);
401
+ // If the result is a Promise, await it
402
+ if (result && typeof result.then === 'function') {
403
+ result = await result;
404
+ }
405
+ // Resume with the return value
406
+ progress = snapshot.resume({ returnValue: result });
407
+ }
408
+ catch (error) {
409
+ // External function threw an exception - convert to Monty exception
410
+ const err = error;
411
+ const excType = err.name || 'RuntimeError';
412
+ const excMessage = err.message || String(error);
413
+ progress = snapshot.resume({
414
+ exception: {
415
+ type: excType,
416
+ message: excMessage,
417
+ },
418
+ });
419
+ }
420
+ }
421
+ return progress.output;
422
+ }
423
+ //# sourceMappingURL=wrapper.js.map