Update app and tooling
This commit is contained in:
parent
3046531bdd
commit
e620ec7349
4950 changed files with 2975120 additions and 10 deletions
67
node_modules/@edge-runtime/vm/dist/edge-vm.d.ts
generated
vendored
Normal file
67
node_modules/@edge-runtime/vm/dist/edge-vm.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import type * as EdgePrimitives from '@edge-runtime/primitives';
|
||||
import type { DispatchFetch } from './types';
|
||||
import { VM, type VMContext, type VMOptions } from './vm';
|
||||
export interface EdgeVMOptions<T extends EdgeContext> {
|
||||
/**
|
||||
* Provide code generation options to the Node.js VM.
|
||||
* If you don't provide any option, code generation will be disabled.
|
||||
*/
|
||||
codeGeneration?: VMOptions<T>['codeGeneration'];
|
||||
/**
|
||||
* Allows to extend the VMContext. Note that it must return a contextified
|
||||
* object so ideally it should return the same reference it receives.
|
||||
*/
|
||||
extend?: (context: EdgeContext) => EdgeContext & T;
|
||||
/**
|
||||
* Code to be evaluated as when the Edge Runtime is created. This is handy
|
||||
* to run code directly instead of first creating the runtime and then
|
||||
* evaluating.
|
||||
*/
|
||||
initialCode?: string;
|
||||
}
|
||||
export declare class EdgeVM<T extends EdgeContext = EdgeContext> extends VM<T> {
|
||||
readonly dispatchFetch: DispatchFetch;
|
||||
constructor(options?: EdgeVMOptions<T>);
|
||||
}
|
||||
export type EdgeContext = VMContext & {
|
||||
self: EdgeContext;
|
||||
globalThis: EdgeContext;
|
||||
AbortController: typeof EdgePrimitives.AbortController;
|
||||
AbortSignal: typeof EdgePrimitives.AbortSignal;
|
||||
atob: typeof EdgePrimitives.atob;
|
||||
Blob: typeof EdgePrimitives.Blob;
|
||||
btoa: typeof EdgePrimitives.btoa;
|
||||
console: typeof EdgePrimitives.console;
|
||||
crypto: typeof EdgePrimitives.crypto;
|
||||
Crypto: typeof EdgePrimitives.Crypto;
|
||||
CryptoKey: typeof EdgePrimitives.CryptoKey;
|
||||
DOMException: typeof EdgePrimitives.DOMException;
|
||||
Event: typeof EdgePrimitives.Event;
|
||||
EventTarget: typeof EdgePrimitives.EventTarget;
|
||||
fetch: typeof EdgePrimitives.fetch;
|
||||
FetchEvent: typeof EdgePrimitives.FetchEvent;
|
||||
File: typeof EdgePrimitives.File;
|
||||
FormData: typeof EdgePrimitives.FormData;
|
||||
Headers: typeof EdgePrimitives.Headers;
|
||||
PromiseRejectionEvent: typeof EdgePrimitives.PromiseRejectionEvent;
|
||||
ReadableStream: typeof EdgePrimitives.ReadableStream;
|
||||
ReadableStreamBYOBReader: typeof EdgePrimitives.ReadableStreamBYOBReader;
|
||||
ReadableStreamDefaultReader: typeof EdgePrimitives.ReadableStreamDefaultReader;
|
||||
Request: typeof EdgePrimitives.Request;
|
||||
Response: typeof EdgePrimitives.Response;
|
||||
setTimeout: typeof EdgePrimitives.setTimeout;
|
||||
setInterval: typeof EdgePrimitives.setInterval;
|
||||
structuredClone: typeof EdgePrimitives.structuredClone;
|
||||
SubtleCrypto: typeof EdgePrimitives.SubtleCrypto;
|
||||
TextDecoder: typeof EdgePrimitives.TextDecoder;
|
||||
TextDecoderStream: typeof EdgePrimitives.TextDecoderStream;
|
||||
TextEncoder: typeof EdgePrimitives.TextEncoder;
|
||||
TextEncoderStream: typeof EdgePrimitives.TextEncoderStream;
|
||||
TransformStream: typeof EdgePrimitives.TransformStream;
|
||||
URL: typeof EdgePrimitives.URL;
|
||||
URLPattern: typeof EdgePrimitives.URLPattern;
|
||||
URLSearchParams: typeof EdgePrimitives.URLSearchParams;
|
||||
WritableStream: typeof EdgePrimitives.WritableStream;
|
||||
WritableStreamDefaultWriter: typeof EdgePrimitives.WritableStreamDefaultWriter;
|
||||
EdgeRuntime: string;
|
||||
};
|
||||
338
node_modules/@edge-runtime/vm/dist/edge-vm.js
generated
vendored
Normal file
338
node_modules/@edge-runtime/vm/dist/edge-vm.js
generated
vendored
Normal file
|
|
@ -0,0 +1,338 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.EdgeVM = void 0;
|
||||
const load_1 = require("@edge-runtime/primitives/load");
|
||||
const vm_1 = require("vm");
|
||||
const vm_2 = require("./vm");
|
||||
/**
|
||||
* Store handlers that the user defined from code so that we can invoke them
|
||||
* from the Node.js realm.
|
||||
*/
|
||||
let unhandledRejectionHandlers;
|
||||
let uncaughtExceptionHandlers;
|
||||
class EdgeVM extends vm_2.VM {
|
||||
constructor(options) {
|
||||
super({
|
||||
...options,
|
||||
extend: (context) => {
|
||||
return (options === null || options === void 0 ? void 0 : options.extend)
|
||||
? options.extend(addPrimitives(context))
|
||||
: addPrimitives(context);
|
||||
},
|
||||
});
|
||||
Object.defineProperty(this.context, '__onUnhandledRejectionHandlers', {
|
||||
set: registerUnhandledRejectionHandlers,
|
||||
configurable: false,
|
||||
enumerable: false,
|
||||
});
|
||||
Object.defineProperty(this, '__rejectionHandlers', {
|
||||
get: () => unhandledRejectionHandlers,
|
||||
configurable: false,
|
||||
enumerable: false,
|
||||
});
|
||||
Object.defineProperty(this.context, '__onErrorHandlers', {
|
||||
set: registerUncaughtExceptionHandlers,
|
||||
configurable: false,
|
||||
enumerable: false,
|
||||
});
|
||||
Object.defineProperty(this, '__errorHandlers', {
|
||||
get: () => uncaughtExceptionHandlers,
|
||||
configurable: false,
|
||||
enumerable: false,
|
||||
});
|
||||
this.evaluate(getDefineEventListenersCode());
|
||||
this.dispatchFetch = this.evaluate(getDispatchFetchCode());
|
||||
for (const name of transferableConstructors) {
|
||||
patchInstanceOf(name, this.context);
|
||||
}
|
||||
if (options === null || options === void 0 ? void 0 : options.initialCode) {
|
||||
this.evaluate(options.initialCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.EdgeVM = EdgeVM;
|
||||
/**
|
||||
* Transferable constructors are the constructors that we expect to be
|
||||
* "shared" between the realms.
|
||||
*
|
||||
* When a user creates an instance of one of these constructors, we want
|
||||
* to make sure that the `instanceof` operator works as expected:
|
||||
*
|
||||
* * If the instance was created in the Node.js realm, then `instanceof`
|
||||
* should return true when used in the EdgeVM realm.
|
||||
* * If the instance was created in the EdgeVM realm, then `instanceof`
|
||||
* should return true when used in the EdgeVM realm.
|
||||
*
|
||||
* For example, the return value from `new TextEncoder().encode("hello")` is a
|
||||
* Uint8Array. Since `TextEncoder` implementation is coming from the Node.js realm,
|
||||
* therefore the following will be false, which doesn't fit the expectation of the user:
|
||||
* ```ts
|
||||
* new TextEncoder().encode("hello") instanceof Uint8Array
|
||||
* ```
|
||||
*
|
||||
* This is because the `Uint8Array` in the `vm` context is not the same
|
||||
* as the one in the Node.js realm.
|
||||
*
|
||||
* Patching the constructors in the `vm` is done by the {@link patchInstanceOf}
|
||||
* function, and this is the list of constructors that need to be patched.
|
||||
*
|
||||
* These constructors are also being injected as "globals" when the VM is
|
||||
* constructed, by passing them as arguments to the {@link loadPrimitives}
|
||||
* function.
|
||||
*/
|
||||
const transferableConstructors = [
|
||||
'Object',
|
||||
'Array',
|
||||
'RegExp',
|
||||
'Uint8Array',
|
||||
'ArrayBuffer',
|
||||
'Error',
|
||||
'SyntaxError',
|
||||
'TypeError',
|
||||
];
|
||||
function patchInstanceOf(item, ctx) {
|
||||
// @ts-ignore
|
||||
ctx[Symbol.for(`node:${item}`)] = eval(item);
|
||||
return (0, vm_1.runInContext)(`
|
||||
globalThis.${item} = new Proxy(${item}, {
|
||||
get(target, prop, receiver) {
|
||||
if (prop === Symbol.hasInstance && receiver === globalThis.${item}) {
|
||||
const nodeTarget = globalThis[Symbol.for('node:${item}')];
|
||||
if (nodeTarget) {
|
||||
return function(instance) {
|
||||
return instance instanceof target || instance instanceof nodeTarget;
|
||||
};
|
||||
} else {
|
||||
throw new Error('node target must exist')
|
||||
}
|
||||
}
|
||||
|
||||
return Reflect.get(target, prop, receiver);
|
||||
}
|
||||
})
|
||||
`, ctx);
|
||||
}
|
||||
/**
|
||||
* Register system-level handlers to make sure that we report to the user
|
||||
* whenever there is an unhandled rejection or exception before the process crashes.
|
||||
* Do it on demand so we don't swallow rejections/errors for no reason.
|
||||
*/
|
||||
function registerUnhandledRejectionHandlers(handlers) {
|
||||
if (!unhandledRejectionHandlers) {
|
||||
process.on('unhandledRejection', function invokeRejectionHandlers(reason, promise) {
|
||||
unhandledRejectionHandlers.forEach((handler) => handler({ reason, promise }));
|
||||
});
|
||||
}
|
||||
unhandledRejectionHandlers = handlers;
|
||||
}
|
||||
function registerUncaughtExceptionHandlers(handlers) {
|
||||
if (!uncaughtExceptionHandlers) {
|
||||
process.on('uncaughtException', function invokeErrorHandlers(error) {
|
||||
uncaughtExceptionHandlers.forEach((handler) => handler(error));
|
||||
});
|
||||
}
|
||||
uncaughtExceptionHandlers = handlers;
|
||||
}
|
||||
/**
|
||||
* Generates polyfills for addEventListener and removeEventListener. It keeps
|
||||
* all listeners in hidden property __listeners. It will also call a hook
|
||||
* `__onUnhandledRejectionHandler` and `__onErrorHandler` when unhandled rejection
|
||||
* events are added or removed and prevent from having more than one FetchEvent
|
||||
* handler.
|
||||
*/
|
||||
function getDefineEventListenersCode() {
|
||||
return `
|
||||
Object.defineProperty(self, '__listeners', {
|
||||
configurable: false,
|
||||
enumerable: false,
|
||||
value: {},
|
||||
writable: true,
|
||||
})
|
||||
|
||||
function __conditionallyUpdatesHandlerList(eventType) {
|
||||
if (eventType === 'unhandledrejection') {
|
||||
self.__onUnhandledRejectionHandlers = self.__listeners[eventType];
|
||||
} else if (eventType === 'error') {
|
||||
self.__onErrorHandlers = self.__listeners[eventType];
|
||||
}
|
||||
}
|
||||
|
||||
function addEventListener(type, handler) {
|
||||
const eventType = type.toLowerCase();
|
||||
if (eventType === 'fetch' && self.__listeners.fetch) {
|
||||
throw new TypeError('You can register just one "fetch" event listener');
|
||||
}
|
||||
|
||||
self.__listeners[eventType] = self.__listeners[eventType] || [];
|
||||
self.__listeners[eventType].push(handler);
|
||||
__conditionallyUpdatesHandlerList(eventType);
|
||||
}
|
||||
|
||||
function removeEventListener(type, handler) {
|
||||
const eventType = type.toLowerCase();
|
||||
if (self.__listeners[eventType]) {
|
||||
self.__listeners[eventType] = self.__listeners[eventType].filter(item => {
|
||||
return item !== handler;
|
||||
});
|
||||
|
||||
if (self.__listeners[eventType].length === 0) {
|
||||
delete self.__listeners[eventType];
|
||||
}
|
||||
}
|
||||
__conditionallyUpdatesHandlerList(eventType);
|
||||
}
|
||||
`;
|
||||
}
|
||||
/**
|
||||
* Generates the code to dispatch a FetchEvent invoking the handlers defined
|
||||
* for such events. In case there is no event handler defined it will throw
|
||||
* an error.
|
||||
*/
|
||||
function getDispatchFetchCode() {
|
||||
return `(async function dispatchFetch(input, init) {
|
||||
const request = new Request(input, init);
|
||||
const event = new FetchEvent(request);
|
||||
if (!self.__listeners.fetch) {
|
||||
throw new Error("No fetch event listeners found");
|
||||
}
|
||||
|
||||
const getResponse = ({ response, error }) => {
|
||||
if (error || !response || !(response instanceof Response)) {
|
||||
console.error(error ? error.toString() : 'The event listener did not respond')
|
||||
response = new Response(null, {
|
||||
statusText: 'Internal Server Error',
|
||||
status: 500
|
||||
})
|
||||
}
|
||||
|
||||
response.waitUntil = () => Promise.all(event.awaiting);
|
||||
|
||||
if (response.status < 300 || response.status >= 400 ) {
|
||||
response.headers.delete('content-encoding');
|
||||
response.headers.delete('transform-encoding');
|
||||
response.headers.delete('content-length');
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
try {
|
||||
await self.__listeners.fetch[0].call(event, event)
|
||||
} catch (error) {
|
||||
return getResponse({ error })
|
||||
}
|
||||
|
||||
return Promise.resolve(event.response)
|
||||
.then(response => getResponse({ response }))
|
||||
.catch(error => getResponse({ error }))
|
||||
})`;
|
||||
}
|
||||
function addPrimitives(context) {
|
||||
defineProperty(context, 'self', { enumerable: true, value: context });
|
||||
defineProperty(context, 'globalThis', { value: context });
|
||||
defineProperty(context, 'Symbol', { value: Symbol });
|
||||
defineProperty(context, 'clearInterval', { value: clearInterval });
|
||||
defineProperty(context, 'clearTimeout', { value: clearTimeout });
|
||||
defineProperty(context, 'queueMicrotask', { value: queueMicrotask });
|
||||
defineProperty(context, 'EdgeRuntime', { value: 'edge-runtime' });
|
||||
const transferables = getTransferablePrimitivesFromContext(context);
|
||||
defineProperties(context, {
|
||||
exports: (0, load_1.load)({
|
||||
...transferables,
|
||||
WeakRef: (0, vm_1.runInContext)(`WeakRef`, context),
|
||||
}),
|
||||
enumerable: ['crypto'],
|
||||
nonenumerable: [
|
||||
// Crypto
|
||||
'Crypto',
|
||||
'CryptoKey',
|
||||
'SubtleCrypto',
|
||||
// Fetch APIs
|
||||
'fetch',
|
||||
'File',
|
||||
'FormData',
|
||||
'Headers',
|
||||
'Request',
|
||||
'Response',
|
||||
'WebSocket',
|
||||
// Structured Clone
|
||||
'structuredClone',
|
||||
// Blob
|
||||
'Blob',
|
||||
// URL
|
||||
'URL',
|
||||
'URLSearchParams',
|
||||
'URLPattern',
|
||||
// AbortController
|
||||
'AbortController',
|
||||
'AbortSignal',
|
||||
'DOMException',
|
||||
// Streams
|
||||
'ReadableStream',
|
||||
'ReadableStreamBYOBReader',
|
||||
'ReadableStreamDefaultReader',
|
||||
'TextDecoderStream',
|
||||
'TextEncoderStream',
|
||||
'TransformStream',
|
||||
'WritableStream',
|
||||
'WritableStreamDefaultWriter',
|
||||
// Encoding
|
||||
'atob',
|
||||
'btoa',
|
||||
'TextEncoder',
|
||||
'TextDecoder',
|
||||
// Events
|
||||
'Event',
|
||||
'EventTarget',
|
||||
'FetchEvent',
|
||||
'PromiseRejectionEvent',
|
||||
// Console
|
||||
'console',
|
||||
// Performance
|
||||
'performance',
|
||||
// Timers
|
||||
'setTimeout',
|
||||
'setInterval',
|
||||
],
|
||||
});
|
||||
return context;
|
||||
}
|
||||
function defineProperty(obj, prop, attrs) {
|
||||
var _a, _b, _c;
|
||||
Object.defineProperty(obj, prop, {
|
||||
configurable: (_a = attrs.configurable) !== null && _a !== void 0 ? _a : false,
|
||||
enumerable: (_b = attrs.enumerable) !== null && _b !== void 0 ? _b : false,
|
||||
value: attrs.value,
|
||||
writable: (_c = attrs.writable) !== null && _c !== void 0 ? _c : true,
|
||||
});
|
||||
}
|
||||
function defineProperties(context, options) {
|
||||
var _a, _b;
|
||||
for (const property of (_a = options.enumerable) !== null && _a !== void 0 ? _a : []) {
|
||||
if (!options.exports[property]) {
|
||||
throw new Error(`Attempt to export a nullable value for "${property}"`);
|
||||
}
|
||||
defineProperty(context, property, {
|
||||
enumerable: true,
|
||||
value: options.exports[property],
|
||||
});
|
||||
}
|
||||
for (const property of (_b = options.nonenumerable) !== null && _b !== void 0 ? _b : []) {
|
||||
if (!options.exports[property]) {
|
||||
throw new Error(`Attempt to export a nullable value for "${property}"`);
|
||||
}
|
||||
defineProperty(context, property, {
|
||||
value: options.exports[property],
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Create an object that contains all the {@link transferableConstructors}
|
||||
* implemented in the provided context.
|
||||
*/
|
||||
function getTransferablePrimitivesFromContext(context) {
|
||||
const keys = transferableConstructors.join(',');
|
||||
const stringifedObject = `({${keys}})`;
|
||||
return (0, vm_1.runInContext)(stringifedObject, context);
|
||||
}
|
||||
//# sourceMappingURL=edge-vm.js.map
|
||||
1
node_modules/@edge-runtime/vm/dist/edge-vm.js.map
generated
vendored
Normal file
1
node_modules/@edge-runtime/vm/dist/edge-vm.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
4
node_modules/@edge-runtime/vm/dist/index.d.ts
generated
vendored
Normal file
4
node_modules/@edge-runtime/vm/dist/index.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
export type { EdgeVMOptions, EdgeContext } from './edge-vm';
|
||||
export type { VMOptions, VMContext } from './vm';
|
||||
export { EdgeVM } from './edge-vm';
|
||||
export { VM } from './vm';
|
||||
8
node_modules/@edge-runtime/vm/dist/index.js
generated
vendored
Normal file
8
node_modules/@edge-runtime/vm/dist/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.VM = exports.EdgeVM = void 0;
|
||||
var edge_vm_1 = require("./edge-vm");
|
||||
Object.defineProperty(exports, "EdgeVM", { enumerable: true, get: function () { return edge_vm_1.EdgeVM; } });
|
||||
var vm_1 = require("./vm");
|
||||
Object.defineProperty(exports, "VM", { enumerable: true, get: function () { return vm_1.VM; } });
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/@edge-runtime/vm/dist/index.js.map
generated
vendored
Normal file
1
node_modules/@edge-runtime/vm/dist/index.js.map
generated
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAEA,qCAAkC;AAAzB,iGAAA,MAAM,OAAA;AACf,2BAAyB;AAAhB,wFAAA,EAAE,OAAA","sourcesContent":["export type { EdgeVMOptions, EdgeContext } from './edge-vm'\nexport type { VMOptions, VMContext } from './vm'\nexport { EdgeVM } from './edge-vm'\nexport { VM } from './vm'\n"]}
|
||||
11
node_modules/@edge-runtime/vm/dist/types.d.ts
generated
vendored
Normal file
11
node_modules/@edge-runtime/vm/dist/types.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
export interface DispatchFetch {
|
||||
(input: string, init?: RequestInit): Promise<Response & {
|
||||
waitUntil: () => Promise<any>;
|
||||
}>;
|
||||
}
|
||||
export interface RejectionHandler {
|
||||
(reason?: {} | null, promise?: Promise<any>): void;
|
||||
}
|
||||
export interface ErrorHandler {
|
||||
(error?: {} | null): void;
|
||||
}
|
||||
3
node_modules/@edge-runtime/vm/dist/types.js
generated
vendored
Normal file
3
node_modules/@edge-runtime/vm/dist/types.js
generated
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=types.js.map
|
||||
1
node_modules/@edge-runtime/vm/dist/types.js.map
generated
vendored
Normal file
1
node_modules/@edge-runtime/vm/dist/types.js.map
generated
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["export interface DispatchFetch {\n (\n input: string,\n init?: RequestInit,\n ): Promise<\n Response & {\n waitUntil: () => Promise<any>\n }\n >\n}\n\nexport interface RejectionHandler {\n (reason?: {} | null, promise?: Promise<any>): void\n}\n\nexport interface ErrorHandler {\n (error?: {} | null): void\n}\n"]}
|
||||
82
node_modules/@edge-runtime/vm/dist/vm.d.ts
generated
vendored
Normal file
82
node_modules/@edge-runtime/vm/dist/vm.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
/// <reference types="node" />
|
||||
import type { CreateContextOptions } from 'vm';
|
||||
export interface VMOptions<T> {
|
||||
/**
|
||||
* Provide code generation options to the Node.js VM.
|
||||
* If you don't provide any option, code generation will be disabled.
|
||||
*/
|
||||
codeGeneration?: CreateContextOptions['codeGeneration'];
|
||||
/**
|
||||
* Allows to extend the VMContext. Note that it must return a contextified
|
||||
* object so ideally it should return the same reference it receives.
|
||||
*/
|
||||
extend?: (context: VMContext) => VMContext & T;
|
||||
}
|
||||
/**
|
||||
* A raw VM with a context that can be extended on instantiation. Implements
|
||||
* a realm-like interface where one can evaluate code or require CommonJS
|
||||
* modules in multiple ways.
|
||||
*/
|
||||
export declare class VM<T extends Record<string | number, any>> {
|
||||
readonly context: VMContext & T;
|
||||
constructor(options?: VMOptions<T>);
|
||||
/**
|
||||
* Allows to run arbitrary code within the VM.
|
||||
*/
|
||||
evaluate<T = any>(code: string): T;
|
||||
}
|
||||
export interface VMContext {
|
||||
Array: typeof Array;
|
||||
ArrayBuffer: typeof ArrayBuffer;
|
||||
Atomics: typeof Atomics;
|
||||
BigInt: typeof BigInt;
|
||||
BigInt64Array: typeof BigInt64Array;
|
||||
BigUint64Array: typeof BigUint64Array;
|
||||
Boolean: typeof Boolean;
|
||||
DataView: typeof DataView;
|
||||
Date: typeof Date;
|
||||
decodeURI: typeof decodeURI;
|
||||
decodeURIComponent: typeof decodeURIComponent;
|
||||
encodeURI: typeof encodeURI;
|
||||
encodeURIComponent: typeof encodeURIComponent;
|
||||
Error: typeof Error;
|
||||
EvalError: typeof EvalError;
|
||||
Float32Array: typeof Float32Array;
|
||||
Float64Array: typeof Float64Array;
|
||||
Function: typeof Function;
|
||||
Infinity: typeof Infinity;
|
||||
Int8Array: typeof Int8Array;
|
||||
Int16Array: typeof Int16Array;
|
||||
Int32Array: typeof Int32Array;
|
||||
Intl: typeof Intl;
|
||||
isFinite: typeof isFinite;
|
||||
isNaN: typeof isNaN;
|
||||
JSON: typeof JSON;
|
||||
Map: typeof Map;
|
||||
Math: typeof Math;
|
||||
Number: typeof Number;
|
||||
Object: typeof Object;
|
||||
parseFloat: typeof parseFloat;
|
||||
parseInt: typeof parseInt;
|
||||
Promise: typeof Promise;
|
||||
Proxy: typeof Proxy;
|
||||
RangeError: typeof RangeError;
|
||||
ReferenceError: typeof ReferenceError;
|
||||
Reflect: typeof Reflect;
|
||||
RegExp: typeof RegExp;
|
||||
Set: typeof Set;
|
||||
SharedArrayBuffer: typeof SharedArrayBuffer;
|
||||
String: typeof String;
|
||||
Symbol: typeof Symbol;
|
||||
SyntaxError: typeof SyntaxError;
|
||||
TypeError: typeof TypeError;
|
||||
Uint8Array: typeof Uint8Array;
|
||||
Uint8ClampedArray: typeof Uint8ClampedArray;
|
||||
Uint16Array: typeof Uint16Array;
|
||||
Uint32Array: typeof Uint32Array;
|
||||
URIError: typeof URIError;
|
||||
WeakMap: typeof WeakMap;
|
||||
WeakSet: typeof WeakSet;
|
||||
WebAssembly: typeof WebAssembly;
|
||||
[key: string | number]: any;
|
||||
}
|
||||
30
node_modules/@edge-runtime/vm/dist/vm.js
generated
vendored
Normal file
30
node_modules/@edge-runtime/vm/dist/vm.js
generated
vendored
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.VM = void 0;
|
||||
const vm_1 = require("vm");
|
||||
/**
|
||||
* A raw VM with a context that can be extended on instantiation. Implements
|
||||
* a realm-like interface where one can evaluate code or require CommonJS
|
||||
* modules in multiple ways.
|
||||
*/
|
||||
class VM {
|
||||
constructor(options = {}) {
|
||||
var _a, _b, _c;
|
||||
const context = (0, vm_1.createContext)({}, {
|
||||
name: 'Edge Runtime',
|
||||
codeGeneration: (_a = options.codeGeneration) !== null && _a !== void 0 ? _a : {
|
||||
strings: false,
|
||||
wasm: true,
|
||||
},
|
||||
});
|
||||
this.context = (_c = (_b = options.extend) === null || _b === void 0 ? void 0 : _b.call(options, context)) !== null && _c !== void 0 ? _c : context;
|
||||
}
|
||||
/**
|
||||
* Allows to run arbitrary code within the VM.
|
||||
*/
|
||||
evaluate(code) {
|
||||
return (0, vm_1.runInContext)(code, this.context);
|
||||
}
|
||||
}
|
||||
exports.VM = VM;
|
||||
//# sourceMappingURL=vm.js.map
|
||||
1
node_modules/@edge-runtime/vm/dist/vm.js.map
generated
vendored
Normal file
1
node_modules/@edge-runtime/vm/dist/vm.js.map
generated
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"vm.js","sourceRoot":"","sources":["../src/vm.ts"],"names":[],"mappings":";;;AACA,2BAAgD;AAehD;;;;GAIG;AACH,MAAa,EAAE;IAGb,YAAY,UAAwB,EAAE;;QACpC,MAAM,OAAO,GAAG,IAAA,kBAAa,EAC3B,EAAE,EACF;YACE,IAAI,EAAE,cAAc;YACpB,cAAc,EAAE,MAAA,OAAO,CAAC,cAAc,mCAAI;gBACxC,OAAO,EAAE,KAAK;gBACd,IAAI,EAAE,IAAI;aACX;SACF,CACW,CAAA;QAEd,IAAI,CAAC,OAAO,GAAG,MAAA,MAAA,OAAO,CAAC,MAAM,wDAAG,OAAO,CAAC,mCAAK,OAAyB,CAAA;IACxE,CAAC;IAED;;OAEG;IACH,QAAQ,CAAU,IAAY;QAC5B,OAAO,IAAA,iBAAY,EAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;IACzC,CAAC;CACF;AAxBD,gBAwBC","sourcesContent":["import type { CreateContextOptions } from 'vm'\nimport { createContext, runInContext } from 'vm'\n\nexport interface VMOptions<T> {\n /**\n * Provide code generation options to the Node.js VM.\n * If you don't provide any option, code generation will be disabled.\n */\n codeGeneration?: CreateContextOptions['codeGeneration']\n /**\n * Allows to extend the VMContext. Note that it must return a contextified\n * object so ideally it should return the same reference it receives.\n */\n extend?: (context: VMContext) => VMContext & T\n}\n\n/**\n * A raw VM with a context that can be extended on instantiation. Implements\n * a realm-like interface where one can evaluate code or require CommonJS\n * modules in multiple ways.\n */\nexport class VM<T extends Record<string | number, any>> {\n public readonly context: VMContext & T\n\n constructor(options: VMOptions<T> = {}) {\n const context = createContext(\n {},\n {\n name: 'Edge Runtime',\n codeGeneration: options.codeGeneration ?? {\n strings: false,\n wasm: true,\n },\n },\n ) as VMContext\n\n this.context = options.extend?.(context) ?? (context as VMContext & T)\n }\n\n /**\n * Allows to run arbitrary code within the VM.\n */\n evaluate<T = any>(code: string): T {\n return runInContext(code, this.context)\n }\n}\n\nexport interface VMContext {\n Array: typeof Array\n ArrayBuffer: typeof ArrayBuffer\n Atomics: typeof Atomics\n BigInt: typeof BigInt\n BigInt64Array: typeof BigInt64Array\n BigUint64Array: typeof BigUint64Array\n Boolean: typeof Boolean\n DataView: typeof DataView\n Date: typeof Date\n decodeURI: typeof decodeURI\n decodeURIComponent: typeof decodeURIComponent\n encodeURI: typeof encodeURI\n encodeURIComponent: typeof encodeURIComponent\n Error: typeof Error\n EvalError: typeof EvalError\n Float32Array: typeof Float32Array\n Float64Array: typeof Float64Array\n Function: typeof Function\n Infinity: typeof Infinity\n Int8Array: typeof Int8Array\n Int16Array: typeof Int16Array\n Int32Array: typeof Int32Array\n Intl: typeof Intl\n isFinite: typeof isFinite\n isNaN: typeof isNaN\n JSON: typeof JSON\n Map: typeof Map\n Math: typeof Math\n Number: typeof Number\n Object: typeof Object\n parseFloat: typeof parseFloat\n parseInt: typeof parseInt\n Promise: typeof Promise\n Proxy: typeof Proxy\n RangeError: typeof RangeError\n ReferenceError: typeof ReferenceError\n Reflect: typeof Reflect\n RegExp: typeof RegExp\n Set: typeof Set\n SharedArrayBuffer: typeof SharedArrayBuffer\n String: typeof String\n Symbol: typeof Symbol\n SyntaxError: typeof SyntaxError\n TypeError: typeof TypeError\n Uint8Array: typeof Uint8Array\n Uint8ClampedArray: typeof Uint8ClampedArray\n Uint16Array: typeof Uint16Array\n Uint32Array: typeof Uint32Array\n URIError: typeof URIError\n WeakMap: typeof WeakMap\n WeakSet: typeof WeakSet\n WebAssembly: typeof WebAssembly\n [key: string | number]: any\n}\n"]}
|
||||
Loading…
Add table
Add a link
Reference in a new issue