Update app and tooling

This commit is contained in:
Lawrence Chen 2026-01-29 17:36:26 -08:00
parent 3046531bdd
commit e620ec7349
4950 changed files with 2975120 additions and 10 deletions

1
node_modules/edge-runtime/dist/cli/eval.d.ts generated vendored Normal file
View file

@ -0,0 +1 @@
export declare const inlineEval: (script: string) => Promise<any>;

11
node_modules/edge-runtime/dist/cli/eval.js generated vendored Normal file
View file

@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.inlineEval = void 0;
const edge_runtime_1 = require("../edge-runtime");
const inlineEval = async (script) => {
const runtime = new edge_runtime_1.EdgeRuntime();
const result = await runtime.evaluate(script);
return result;
};
exports.inlineEval = inlineEval;
//# sourceMappingURL=eval.js.map

1
node_modules/edge-runtime/dist/cli/eval.js.map generated vendored Normal file
View file

@ -0,0 +1 @@
{"version":3,"file":"eval.js","sourceRoot":"","sources":["../../src/cli/eval.ts"],"names":[],"mappings":";;;AAAA,kDAA6C;AAEtC,MAAM,UAAU,GAAG,KAAK,EAAE,MAAc,EAAE,EAAE;IACjD,MAAM,OAAO,GAAG,IAAI,0BAAW,EAAE,CAAA;IACjC,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IAC7C,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAJY,QAAA,UAAU,cAItB","sourcesContent":["import { EdgeRuntime } from '../edge-runtime'\n\nexport const inlineEval = async (script: string) => {\n const runtime = new EdgeRuntime()\n const result = await runtime.evaluate(script)\n return result\n}\n"]}

1
node_modules/edge-runtime/dist/cli/help.d.ts generated vendored Normal file
View file

@ -0,0 +1 @@
export declare const help: () => string;

31
node_modules/edge-runtime/dist/cli/help.js generated vendored Normal file
View file

@ -0,0 +1,31 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.help = void 0;
const picocolors_1 = require("picocolors");
const flags = {
eval: 'Evaluate an input script',
help: 'Display this message.',
listen: 'Run as HTTP server.',
port: 'Specify a port to use.',
repl: 'Start an interactive session.',
};
const help = () => `
edge-runtime ${(0, picocolors_1.dim)('[<flags>] [input]')}
${(0, picocolors_1.dim)('Flags:')}
${getSectionSummary(flags)}
`;
exports.help = help;
function getPadLength(options) {
const lengths = Object.keys(options).map((key) => key.length);
return Math.max.apply(null, lengths) + 1;
}
function getSectionSummary(options) {
const summaryPadLength = getPadLength(options);
const summary = Object.entries(options)
.map(([key, description]) => ` --${key.padEnd(summaryPadLength)} ${(0, picocolors_1.dim)(description)}`)
.join('\n');
return `${summary}`;
}
//# sourceMappingURL=help.js.map

1
node_modules/edge-runtime/dist/cli/help.js.map generated vendored Normal file
View file

@ -0,0 +1 @@
{"version":3,"file":"help.js","sourceRoot":"","sources":["../../src/cli/help.ts"],"names":[],"mappings":";;;AAAA,2CAAuC;AAGvC,MAAM,KAAK,GAAgB;IACzB,IAAI,EAAE,0BAA0B;IAChC,IAAI,EAAE,uBAAuB;IAC7B,MAAM,EAAE,qBAAqB;IAC7B,IAAI,EAAE,wBAAwB;IAC9B,IAAI,EAAE,+BAA+B;CACtC,CAAA;AAEM,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC;iBACT,IAAA,gBAAG,EAAC,mBAAmB,CAAC;;IAErC,IAAA,gBAAG,EAAC,QAAQ,CAAC;;EAEf,iBAAiB,CAAC,KAAK,CAAC;CACzB,CAAA;AANY,QAAA,IAAI,QAMhB;AAED,SAAS,YAAY,CAAC,OAAoB;IACxC,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IAC7D,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;AAC1C,CAAC;AAED,SAAS,iBAAiB,CAAC,OAAoB;IAC7C,MAAM,gBAAgB,GAAG,YAAY,CAAC,OAAO,CAAC,CAAA;IAE9C,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;SACpC,GAAG,CACF,CAAC,CAAC,GAAG,EAAE,WAAW,CAAC,EAAE,EAAE,CACrB,SAAS,GAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,IAAI,IAAA,gBAAG,EAAC,WAAW,CAAC,EAAE,CAC9D;SACA,IAAI,CAAC,IAAI,CAAC,CAAA;IAEb,OAAO,GAAG,OAAO,EAAE,CAAA;AACrB,CAAC","sourcesContent":["import { dim, white } from 'picocolors'\ninterface HelpOptions extends Record<string, string> {}\n\nconst flags: HelpOptions = {\n eval: 'Evaluate an input script',\n help: 'Display this message.',\n listen: 'Run as HTTP server.',\n port: 'Specify a port to use.',\n repl: 'Start an interactive session.',\n}\n\nexport const help = () => `\n edge-runtime ${dim('[<flags>] [input]')}\n\n ${dim('Flags:')}\n\n${getSectionSummary(flags)}\n`\n\nfunction getPadLength(options: HelpOptions) {\n const lengths = Object.keys(options).map((key) => key.length)\n return Math.max.apply(null, lengths) + 1\n}\n\nfunction getSectionSummary(options: HelpOptions) {\n const summaryPadLength = getPadLength(options)\n\n const summary = Object.entries(options)\n .map(\n ([key, description]) =>\n ` --${key.padEnd(summaryPadLength)} ${dim(description)}`,\n )\n .join('\\n')\n\n return `${summary}`\n}\n"]}

2
node_modules/edge-runtime/dist/cli/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,2 @@
#!/usr/bin/env node
export {};

113
node_modules/edge-runtime/dist/cli/index.js generated vendored Executable file
View file

@ -0,0 +1,113 @@
#!/usr/bin/env node
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const edge_runtime_1 = require("../edge-runtime");
const util_1 = require("util");
const fs_1 = require("fs");
const server_1 = require("../server");
const child_process_1 = __importDefault(require("child_process"));
const signal_exit_1 = require("signal-exit");
const mri_1 = __importDefault(require("mri"));
const path_1 = __importDefault(require("path"));
const { _: input, ...flags } = (0, mri_1.default)(process.argv.slice(2), {
alias: {
e: 'eval',
h: 'host',
l: 'listen',
p: 'port',
},
default: {
cwd: process.cwd(),
eval: false,
help: false,
host: '127.0.0.1',
listen: false,
port: 3000,
repl: false,
},
});
async function main() {
if (flags.help) {
const { help } = await Promise.resolve().then(() => __importStar(require('./help')));
console.log(help());
return;
}
if (flags.eval) {
const { inlineEval } = await Promise.resolve().then(() => __importStar(require('./eval')));
console.log(await inlineEval(input[0]));
return;
}
/**
* If there is no script path to run a server, the CLI will start a REPL.
*/
const [scriptPath] = input;
if (!scriptPath) {
const replPath = path_1.default.resolve(__dirname, 'repl.js');
return (0, util_1.promisify)(child_process_1.default.spawn).call(null, 'node', [replPath], {
stdio: 'inherit',
});
}
const initialCode = (0, fs_1.readFileSync)(path_1.default.resolve(process.cwd(), scriptPath), 'utf-8');
const runtime = new edge_runtime_1.EdgeRuntime({ initialCode });
if (!flags.listen)
return runtime.evaluate('');
const logger = await Promise.resolve().then(() => __importStar(require('./logger'))).then(({ createLogger }) => createLogger());
logger.debug(`v${String(require('../../package.json').version)} at Node.js ${process.version}`);
/**
* Start a server with the script provided in the file path.
*/
let server;
let port = flags.port;
while (server === undefined) {
try {
server = await (0, server_1.runServer)({
host: flags.host,
logger: logger,
port,
runtime,
});
}
catch (error) {
if ((error === null || error === void 0 ? void 0 : error.code) === 'EADDRINUSE') {
logger.warn(`Port \`${port}\` already in use`);
++port;
}
else
throw error;
}
}
(0, signal_exit_1.onExit)(() => server === null || server === void 0 ? void 0 : server.close());
logger(`Waiting incoming requests at ${logger.quotes(server.url)}`);
}
main().catch((error) => {
if (!(error instanceof Error))
error = new Error(error);
process.exit(1);
});
//# sourceMappingURL=index.js.map

1
node_modules/edge-runtime/dist/cli/index.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

7
node_modules/edge-runtime/dist/cli/logger.d.ts generated vendored Normal file
View file

@ -0,0 +1,7 @@
import type { Logger } from '../types';
export declare const format: (...args: unknown[]) => string;
/**
* Creates basic logger with colors that can be used from the CLI and the
* server logs.
*/
export declare function createLogger(): Logger;

37
node_modules/edge-runtime/dist/cli/logger.js generated vendored Normal file
View file

@ -0,0 +1,37 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createLogger = exports.format = void 0;
const format_1 = require("@edge-runtime/format");
const picocolors_1 = __importDefault(require("picocolors"));
const isEnabled = process.env.EDGE_RUNTIME_LOGGING !== undefined
? Boolean(process.env.EDGE_RUNTIME_LOGGING)
: true;
exports.format = (0, format_1.createFormat)();
/**
* Creates basic logger with colors that can be used from the CLI and the
* server logs.
*/
function createLogger() {
const logger = function (message, opts) {
print(message, opts);
};
logger.info = logger;
logger.error = (message, opts) => print(message, { color: 'red', ...opts });
logger.debug = (message, opts) => print(message, { color: 'dim', ...opts });
logger.warn = (message, opts) => print(message, { color: 'yellow', ...opts });
logger.quotes = (str) => `\`${str}\``;
return logger;
}
exports.createLogger = createLogger;
function print(message, { color = 'white', withHeader = true, withBreakline = false, } = {}) {
if (!isEnabled)
return;
const colorize = picocolors_1.default[color];
const header = withHeader ? `${colorize('ƒ')} ` : '';
const separator = withBreakline ? '\n' : '';
console.log(`${header}${separator}${colorize(message)}`);
}
//# sourceMappingURL=logger.js.map

1
node_modules/edge-runtime/dist/cli/logger.js.map generated vendored Normal file
View file

@ -0,0 +1 @@
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/cli/logger.ts"],"names":[],"mappings":";;;;;;AAAA,iDAAmD;AAGnD,4DAA6B;AAE7B,MAAM,SAAS,GACb,OAAO,CAAC,GAAG,CAAC,oBAAoB,KAAK,SAAS;IAC5C,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC;IAC3C,CAAC,CAAC,IAAI,CAAA;AAEG,QAAA,MAAM,GAAG,IAAA,qBAAY,GAAE,CAAA;AAEpC;;;GAGG;AACH,SAAgB,YAAY;IAC1B,MAAM,MAAM,GAAG,UAAU,OAAe,EAAE,IAAoB;QAC5D,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;IACtB,CAAW,CAAA;IAEX,MAAM,CAAC,IAAI,GAAG,MAAM,CAAA;IACpB,MAAM,CAAC,KAAK,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,CAAC,CAAA;IAC3E,MAAM,CAAC,KAAK,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,CAAC,CAAA;IAC3E,MAAM,CAAC,IAAI,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,CAAC,CAAA;IAC7E,MAAM,CAAC,MAAM,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,KAAK,GAAG,IAAI,CAAA;IAC7C,OAAO,MAAM,CAAA;AACf,CAAC;AAXD,oCAWC;AAED,SAAS,KAAK,CACZ,OAAe,EACf,EACE,KAAK,GAAG,OAAO,EACf,UAAU,GAAG,IAAI,EACjB,aAAa,GAAG,KAAK,MACJ,EAAE;IAErB,IAAI,CAAC,SAAS;QAAE,OAAM;IACtB,MAAM,QAAQ,GAAG,oBAAI,CAAC,KAAK,CAAc,CAAA;IACzC,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAA;IACpD,MAAM,SAAS,GAAG,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAA;IAC3C,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;AAC1D,CAAC","sourcesContent":["import { createFormat } from '@edge-runtime/format'\nimport type { Logger, LoggerOptions } from '../types'\nimport type { Formatter } from 'picocolors/types'\nimport pico from 'picocolors'\n\nconst isEnabled =\n process.env.EDGE_RUNTIME_LOGGING !== undefined\n ? Boolean(process.env.EDGE_RUNTIME_LOGGING)\n : true\n\nexport const format = createFormat()\n\n/**\n * Creates basic logger with colors that can be used from the CLI and the\n * server logs.\n */\nexport function createLogger() {\n const logger = function (message: string, opts?: LoggerOptions) {\n print(message, opts)\n } as Logger\n\n logger.info = logger\n logger.error = (message, opts) => print(message, { color: 'red', ...opts })\n logger.debug = (message, opts) => print(message, { color: 'dim', ...opts })\n logger.warn = (message, opts) => print(message, { color: 'yellow', ...opts })\n logger.quotes = (str: string) => `\\`${str}\\``\n return logger\n}\n\nfunction print(\n message: string,\n {\n color = 'white',\n withHeader = true,\n withBreakline = false,\n }: LoggerOptions = {},\n) {\n if (!isEnabled) return\n const colorize = pico[color] as Formatter\n const header = withHeader ? `${colorize('ƒ')} ` : ''\n const separator = withBreakline ? '\\n' : ''\n console.log(`${header}${separator}${colorize(message)}`)\n}\n"]}

4
node_modules/edge-runtime/dist/cli/repl.d.ts generated vendored Normal file
View file

@ -0,0 +1,4 @@
/// <reference types="node" />
import createRepl from 'repl';
declare const repl: createRepl.REPLServer;
export { repl };

30
node_modules/edge-runtime/dist/cli/repl.js generated vendored Normal file
View file

@ -0,0 +1,30 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.repl = void 0;
const format_1 = require("@edge-runtime/format");
const repl_1 = __importDefault(require("repl"));
const os_1 = require("os");
const path_1 = require("path");
const edge_runtime_1 = require("../edge-runtime");
const format = (0, format_1.createFormat)();
const writer = (output) => {
return typeof output === 'function' ? output.toString() : format(output);
};
const repl = repl_1.default.start({ prompt: 'ƒ => ', writer });
exports.repl = repl;
repl.setupHistory((0, path_1.join)((0, os_1.homedir)(), '.edge_runtime_repl_history'), () => { });
Object.getOwnPropertyNames(repl.context).forEach((mod) => delete repl.context[mod]);
const runtime = new edge_runtime_1.EdgeRuntime();
Object.getOwnPropertyNames(runtime.context)
.filter((key) => !key.startsWith('__'))
.forEach((key) => Object.assign(repl.context, { [key]: runtime.context[key] }));
Object.defineProperty(repl.context, 'EdgeRuntime', {
configurable: false,
enumerable: false,
writable: false,
value: runtime.context.EdgeRuntime,
});
//# sourceMappingURL=repl.js.map

1
node_modules/edge-runtime/dist/cli/repl.js.map generated vendored Normal file
View file

@ -0,0 +1 @@
{"version":3,"file":"repl.js","sourceRoot":"","sources":["../../src/cli/repl.ts"],"names":[],"mappings":";;;;;;AAAA,iDAAmD;AACnD,gDAA6B;AAC7B,2BAA4B;AAC5B,+BAA2B;AAE3B,kDAA6C;AAE7C,MAAM,MAAM,GAAG,IAAA,qBAAY,GAAE,CAAA;AAE7B,MAAM,MAAM,GAA0B,CAAC,MAAM,EAAE,EAAE;IAC/C,OAAO,OAAO,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;AAC1E,CAAC,CAAA;AAED,MAAM,IAAI,GAAG,cAAU,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAA;AAsBjD,oBAAI;AArBb,IAAI,CAAC,YAAY,CAAC,IAAA,WAAI,EAAC,IAAA,YAAO,GAAE,EAAE,4BAA4B,CAAC,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;AAE1E,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,CAC9C,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAClC,CAAA;AAED,MAAM,OAAO,GAAG,IAAI,0BAAW,EAAE,CAAA;AAEjC,MAAM,CAAC,mBAAmB,CAAC,OAAO,CAAC,OAAO,CAAC;KACxC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;KACtC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CACf,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAC7D,CAAA;AAEH,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE,aAAa,EAAE;IACjD,YAAY,EAAE,KAAK;IACnB,UAAU,EAAE,KAAK;IACjB,QAAQ,EAAE,KAAK;IACf,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,WAAW;CACnC,CAAC,CAAA","sourcesContent":["import { createFormat } from '@edge-runtime/format'\nimport createRepl from 'repl'\nimport { homedir } from 'os'\nimport { join } from 'path'\n\nimport { EdgeRuntime } from '../edge-runtime'\n\nconst format = createFormat()\n\nconst writer: createRepl.REPLWriter = (output) => {\n return typeof output === 'function' ? output.toString() : format(output)\n}\n\nconst repl = createRepl.start({ prompt: 'ƒ => ', writer })\nrepl.setupHistory(join(homedir(), '.edge_runtime_repl_history'), () => {})\n\nObject.getOwnPropertyNames(repl.context).forEach(\n (mod) => delete repl.context[mod],\n)\n\nconst runtime = new EdgeRuntime()\n\nObject.getOwnPropertyNames(runtime.context)\n .filter((key) => !key.startsWith('__'))\n .forEach((key) =>\n Object.assign(repl.context, { [key]: runtime.context[key] }),\n )\n\nObject.defineProperty(repl.context, 'EdgeRuntime', {\n configurable: false,\n enumerable: false,\n writable: false,\n value: runtime.context.EdgeRuntime,\n})\n\nexport { repl }\n"]}

1
node_modules/edge-runtime/dist/edge-runtime.d.ts generated vendored Normal file
View file

@ -0,0 +1 @@
export { EdgeVM as EdgeRuntime } from '@edge-runtime/vm';

6
node_modules/edge-runtime/dist/edge-runtime.js generated vendored Normal file
View file

@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EdgeRuntime = void 0;
var vm_1 = require("@edge-runtime/vm");
Object.defineProperty(exports, "EdgeRuntime", { enumerable: true, get: function () { return vm_1.EdgeVM; } });
//# sourceMappingURL=edge-runtime.js.map

1
node_modules/edge-runtime/dist/edge-runtime.js.map generated vendored Normal file
View file

@ -0,0 +1 @@
{"version":3,"file":"edge-runtime.js","sourceRoot":"","sources":["../src/edge-runtime.ts"],"names":[],"mappings":";;;AAAA,uCAAwD;AAA/C,iGAAA,MAAM,OAAe","sourcesContent":["export { EdgeVM as EdgeRuntime } from '@edge-runtime/vm'\n"]}

2
node_modules/edge-runtime/dist/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,2 @@
export { consumeUint8ArrayReadableStream, pipeBodyStreamToResponse, createHandler, runServer, } from './server';
export { EdgeRuntime } from './edge-runtime';

11
node_modules/edge-runtime/dist/index.js generated vendored Normal file
View file

@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EdgeRuntime = exports.runServer = exports.createHandler = exports.pipeBodyStreamToResponse = exports.consumeUint8ArrayReadableStream = void 0;
var server_1 = require("./server");
Object.defineProperty(exports, "consumeUint8ArrayReadableStream", { enumerable: true, get: function () { return server_1.consumeUint8ArrayReadableStream; } });
Object.defineProperty(exports, "pipeBodyStreamToResponse", { enumerable: true, get: function () { return server_1.pipeBodyStreamToResponse; } });
Object.defineProperty(exports, "createHandler", { enumerable: true, get: function () { return server_1.createHandler; } });
Object.defineProperty(exports, "runServer", { enumerable: true, get: function () { return server_1.runServer; } });
var edge_runtime_1 = require("./edge-runtime");
Object.defineProperty(exports, "EdgeRuntime", { enumerable: true, get: function () { return edge_runtime_1.EdgeRuntime; } });
//# sourceMappingURL=index.js.map

1
node_modules/edge-runtime/dist/index.js.map generated vendored Normal file
View file

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAKiB;AAJf,yHAAA,+BAA+B,OAAA;AAC/B,kHAAA,wBAAwB,OAAA;AACxB,uGAAA,aAAa,OAAA;AACb,mGAAA,SAAS,OAAA;AAGX,+CAA4C;AAAnC,2GAAA,WAAW,OAAA","sourcesContent":["export {\n consumeUint8ArrayReadableStream,\n pipeBodyStreamToResponse,\n createHandler,\n runServer,\n} from './server'\n\nexport { EdgeRuntime } from './edge-runtime'\n"]}

View file

@ -0,0 +1,35 @@
/// <reference types="node" />
/// <reference types="node" />
import type { IncomingMessage } from 'http';
import type { Writable } from 'stream';
type BodyStream = ReadableStream<Uint8Array>;
/**
* An interface that encapsulates body stream cloning
* of an incoming request.
*/
export declare function getClonableBodyStream<T extends IncomingMessage>(incomingMessage: T, KUint8Array: typeof Uint8Array, KTransformStream: typeof TransformStream): {
/**
* Replaces the original request body if necessary.
* This is done because once we read the body from the original request,
* we can't read it again.
*/
finalize(): void;
/**
* Clones the body stream
* to pass into a middleware
*/
cloneBodyStream(): BodyStream;
};
/**
* Creates an async iterator from a ReadableStream that ensures that every
* emitted chunk is a `Uint8Array`. If there is some invalid chunk it will
* throw.
*/
export declare function consumeUint8ArrayReadableStream(body?: ReadableStream): AsyncGenerator<Uint8Array, void, unknown>;
/**
* Pipes the chunks of a BodyStream into a Response. This optimizes for
* laziness, pauses reading if we experience back-pressure, and handles early
* disconnects by the client on the other end of the server response.
*/
export declare function pipeBodyStreamToResponse(body: BodyStream | null, res: Writable): Promise<void>;
export {};

161
node_modules/edge-runtime/dist/server/body-streams.js generated vendored Normal file
View file

@ -0,0 +1,161 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.pipeBodyStreamToResponse = exports.consumeUint8ArrayReadableStream = exports.getClonableBodyStream = void 0;
const stream_1 = require("stream");
/**
* An interface that encapsulates body stream cloning
* of an incoming request.
*/
function getClonableBodyStream(incomingMessage, KUint8Array, KTransformStream) {
let bufferedBodyStream = null;
return {
/**
* Replaces the original request body if necessary.
* This is done because once we read the body from the original request,
* we can't read it again.
*/
finalize() {
if (bufferedBodyStream) {
replaceRequestBody(incomingMessage, bodyStreamToNodeStream(bufferedBodyStream));
}
},
/**
* Clones the body stream
* to pass into a middleware
*/
cloneBodyStream() {
const originalStream = bufferedBodyStream !== null && bufferedBodyStream !== void 0 ? bufferedBodyStream : requestToBodyStream(incomingMessage, KUint8Array, KTransformStream);
const [stream1, stream2] = originalStream.tee();
bufferedBodyStream = stream1;
return stream2;
},
};
}
exports.getClonableBodyStream = getClonableBodyStream;
/**
* Creates a ReadableStream from a Node.js HTTP request
*/
function requestToBodyStream(request, KUint8Array, KTransformStream) {
const transform = new KTransformStream({
start(controller) {
request.on('data', (chunk) => controller.enqueue(new KUint8Array([...new Uint8Array(chunk)])));
request.on('end', () => controller.terminate());
request.on('error', (err) => controller.error(err));
},
});
return transform.readable;
}
function bodyStreamToNodeStream(bodyStream) {
const reader = bodyStream.getReader();
return stream_1.Readable.from((async function* () {
while (true) {
const { done, value } = await reader.read();
if (done) {
return;
}
yield value;
}
})());
}
function replaceRequestBody(base, stream) {
for (const key in stream) {
let v = stream[key];
if (typeof v === 'function') {
v = v.bind(stream);
}
base[key] = v;
}
return base;
}
function isUint8ArrayChunk(value) {
var _a;
return ((_a = value === null || value === void 0 ? void 0 : value.constructor) === null || _a === void 0 ? void 0 : _a.name) == 'Uint8Array';
}
/**
* Creates an async iterator from a ReadableStream that ensures that every
* emitted chunk is a `Uint8Array`. If there is some invalid chunk it will
* throw.
*/
async function* consumeUint8ArrayReadableStream(body) {
const reader = body === null || body === void 0 ? void 0 : body.getReader();
if (reader) {
let error;
try {
while (true) {
const { done, value } = await reader.read();
if (done) {
return;
}
if (!isUint8ArrayChunk(value)) {
error = new TypeError('This ReadableStream did not return bytes.');
break;
}
yield value;
}
}
finally {
if (error) {
reader.cancel(error);
throw error;
}
else {
reader.cancel();
}
}
}
}
exports.consumeUint8ArrayReadableStream = consumeUint8ArrayReadableStream;
/**
* Pipes the chunks of a BodyStream into a Response. This optimizes for
* laziness, pauses reading if we experience back-pressure, and handles early
* disconnects by the client on the other end of the server response.
*/
async function pipeBodyStreamToResponse(body, res) {
if (!body)
return;
// If the client has already disconnected, then we don't need to pipe anything.
if (res.destroyed)
return body.cancel();
// When the server pushes more data than the client reads, then we need to
// wait for the client to catch up before writing more data. We register this
// generic handler once so that we don't incur constant register/unregister
// calls.
let drainResolve;
res.on('drain', () => drainResolve === null || drainResolve === void 0 ? void 0 : drainResolve());
// If the user aborts, then we'll receive a close event before the
// body closes. In that case, we want to end the streaming.
let open = true;
res.on('close', () => {
open = false;
drainResolve === null || drainResolve === void 0 ? void 0 : drainResolve();
});
const reader = body.getReader();
while (open) {
const { done, value } = await reader.read();
if (done)
break;
if (!isUint8ArrayChunk(value)) {
const error = new TypeError('This ReadableStream did not return bytes.');
reader.cancel(error);
throw error;
}
if (open) {
const bufferSpaceAvailable = res.write(value);
// If there's no more space in the buffer, then we need to wait on the
// client to read data before pushing again.
if (!bufferSpaceAvailable) {
await new Promise((res) => {
drainResolve = res;
});
}
}
// If the client disconnected early, then we need to cleanup the stream.
// This cannot be joined with the above if-statement, because the client may
// have disconnected while waiting for a drain signal.
if (!open) {
return reader.cancel();
}
}
}
exports.pipeBodyStreamToResponse = pipeBodyStreamToResponse;
//# sourceMappingURL=body-streams.js.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,26 @@
/// <reference types="node" />
import type { EdgeRuntime } from '../edge-runtime';
import type { IncomingMessage, ServerResponse } from 'http';
import type { Logger } from '../types';
import type { EdgeContext } from '@edge-runtime/vm';
export interface Options<T extends EdgeContext> {
/**
* A logger interface. If none is provided there will be no logs.
*/
logger?: Logger;
/**
* The runtime where the FetchEvent will be triggered whenever the server
* receives a request.
*/
runtime: EdgeRuntime<T>;
}
/**
* Creates an HHTP handler that can be used to create a Node.js HTTP server.
* Whenever a request is handled it will transform it into a `dispatchFetch`
* call for the given `EdgeRuntime`. Then it will transform the response
* into an HTTP response.
*/
export declare function createHandler<T extends EdgeContext>(options: Options<T>): {
handler: (req: IncomingMessage, res: ServerResponse) => Promise<void>;
waitUntil: () => Promise<unknown[]>;
};

View file

@ -0,0 +1,94 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createHandler = void 0;
const body_streams_1 = require("./body-streams");
const pretty_ms_1 = __importDefault(require("pretty-ms"));
const time_span_1 = __importDefault(require("time-span"));
const http_1 = require("http");
/**
* Creates an HHTP handler that can be used to create a Node.js HTTP server.
* Whenever a request is handled it will transform it into a `dispatchFetch`
* call for the given `EdgeRuntime`. Then it will transform the response
* into an HTTP response.
*/
function createHandler(options) {
const awaiting = new Set();
return {
handler: async (req, res) => {
var _a, _b;
try {
const start = (0, time_span_1.default)();
const body = req.method !== 'GET' && req.method !== 'HEAD'
? (0, body_streams_1.getClonableBodyStream)(req, options.runtime.evaluate('Uint8Array'), options.runtime.context.TransformStream)
: undefined;
const response = await options.runtime.dispatchFetch(String(getURL(req)), {
headers: toRequestInitHeaders(req),
method: req.method,
body: body === null || body === void 0 ? void 0 : body.cloneBodyStream(),
});
const waitUntil = response.waitUntil();
awaiting.add(waitUntil);
waitUntil.finally(() => awaiting.delete(waitUntil));
res.statusCode = response.status;
res.statusMessage = response.statusText;
for (const [key, value] of Object.entries(toNodeHeaders(response.headers))) {
if (value !== undefined) {
res.setHeader(key, value);
}
}
await (0, body_streams_1.pipeBodyStreamToResponse)(response.body, res);
const subject = `${req.socket.remoteAddress} ${req.method} ${req.url}`;
const time = `${(_a = (0, pretty_ms_1.default)(start())
.match(/[a-zA-Z]+|[0-9]+/g)) === null || _a === void 0 ? void 0 : _a.join(' ')}`;
const code = `${res.statusCode} ${http_1.STATUS_CODES[res.statusCode]}`;
(_b = options.logger) === null || _b === void 0 ? void 0 : _b.debug(`${subject}${code} in ${time}`);
res.end();
}
finally {
if (!res.writableEnded) {
res.end();
}
}
},
waitUntil: () => Promise.all(awaiting),
};
}
exports.createHandler = createHandler;
/**
* Builds a full URL from the provided incoming message. Note this function
* is not safe as one can set has a host anything based on headers. It is
* useful to build the fetch request full URL.
*/
function getURL(req) {
var _a;
const proto = ((_a = req.socket) === null || _a === void 0 ? void 0 : _a.encrypted) ? 'https' : 'http';
return new URL(String(req.url), `${proto}://${String(req.headers.host)}`);
}
/**
* Takes headers from IncomingMessage and transforms them into the signature
* accepted by fetch. It simply folds headers into a single value when they
* hold an array. For others it just copies the value.
*/
function toRequestInitHeaders(req) {
return Object.keys(req.headers).map((key) => {
const value = req.headers[key];
return [key, Array.isArray(value) ? value.join(', ') : value !== null && value !== void 0 ? value : ''];
});
}
/**
* Transforms WHATWG Headers into a Node Headers shape. Copies all items but
* does a special case for Set-Cookie using the [`getSetCookie`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/getSetCookie) method.
*/
function toNodeHeaders(headers) {
const result = {};
if (headers) {
for (const [key, value] of headers.entries()) {
result[key] = key === 'set-cookie' ? headers.getSetCookie() : value;
}
}
return result;
}
//# sourceMappingURL=create-handler.js.map

File diff suppressed because one or more lines are too long

3
node_modules/edge-runtime/dist/server/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,3 @@
export { consumeUint8ArrayReadableStream, pipeBodyStreamToResponse, } from './body-streams';
export { createHandler } from './create-handler';
export { runServer, EdgeRuntimeServer } from './run-server';

11
node_modules/edge-runtime/dist/server/index.js generated vendored Normal file
View file

@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.runServer = exports.createHandler = exports.pipeBodyStreamToResponse = exports.consumeUint8ArrayReadableStream = void 0;
var body_streams_1 = require("./body-streams");
Object.defineProperty(exports, "consumeUint8ArrayReadableStream", { enumerable: true, get: function () { return body_streams_1.consumeUint8ArrayReadableStream; } });
Object.defineProperty(exports, "pipeBodyStreamToResponse", { enumerable: true, get: function () { return body_streams_1.pipeBodyStreamToResponse; } });
var create_handler_1 = require("./create-handler");
Object.defineProperty(exports, "createHandler", { enumerable: true, get: function () { return create_handler_1.createHandler; } });
var run_server_1 = require("./run-server");
Object.defineProperty(exports, "runServer", { enumerable: true, get: function () { return run_server_1.runServer; } });
//# sourceMappingURL=index.js.map

1
node_modules/edge-runtime/dist/server/index.js.map generated vendored Normal file
View file

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":";;;AAAA,+CAGuB;AAFrB,+HAAA,+BAA+B,OAAA;AAC/B,wHAAA,wBAAwB,OAAA;AAE1B,mDAAgD;AAAvC,+GAAA,aAAa,OAAA;AACtB,2CAA2D;AAAlD,uGAAA,SAAS,OAAA","sourcesContent":["export {\n consumeUint8ArrayReadableStream,\n pipeBodyStreamToResponse,\n} from './body-streams'\nexport { createHandler } from './create-handler'\nexport { runServer, EdgeRuntimeServer } from './run-server'\n"]}

27
node_modules/edge-runtime/dist/server/run-server.d.ts generated vendored Normal file
View file

@ -0,0 +1,27 @@
/// <reference types="node" />
import { Options } from './create-handler';
import type { EdgeContext } from '@edge-runtime/vm';
import type { ListenOptions } from 'net';
interface ServerOptions<T extends EdgeContext> extends Options<T> {
}
export interface EdgeRuntimeServer {
/**
* The server URL.
*/
url: string;
/**
* Waits for all the current effects and closes the server.
*/
close: () => Promise<void>;
/**
* Waits for all current effects returning their result.
*/
waitUntil: () => Promise<any[]>;
}
/**
* This helper will create a handler based on the given options and then
* immediately run a server on the provided port. If there is no port, the
* server will use a random one.
*/
export declare function runServer<T extends EdgeContext>(options: ListenOptions & ServerOptions<T>): Promise<EdgeRuntimeServer>;
export {};

37
node_modules/edge-runtime/dist/server/run-server.js generated vendored Normal file
View file

@ -0,0 +1,37 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.runServer = void 0;
const create_handler_1 = require("./create-handler");
const async_listen_1 = __importDefault(require("async-listen"));
const http_1 = __importDefault(require("http"));
/**
* This helper will create a handler based on the given options and then
* immediately run a server on the provided port. If there is no port, the
* server will use a random one.
*/
async function runServer(options) {
if (options.port === undefined)
options.port = 0;
const { handler, waitUntil } = (0, create_handler_1.createHandler)(options);
const server = http_1.default.createServer(handler);
const url = await (0, async_listen_1.default)(server, options);
return {
url: String(url),
close: async () => {
await waitUntil();
await new Promise((resolve, reject) => {
return server.close((err) => {
if (err)
reject(err);
resolve();
});
});
},
waitUntil,
};
}
exports.runServer = runServer;
//# sourceMappingURL=run-server.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"run-server.js","sourceRoot":"","sources":["../../src/server/run-server.ts"],"names":[],"mappings":";;;;;;AAAA,qDAAyD;AAEzD,gEAAiC;AACjC,gDAAuB;AAoBvB;;;;GAIG;AACI,KAAK,UAAU,SAAS,CAC7B,OAAyC;IAEzC,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS;QAAE,OAAO,CAAC,IAAI,GAAG,CAAC,CAAA;IAChD,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,IAAA,8BAAa,EAAC,OAAO,CAAC,CAAA;IACrD,MAAM,MAAM,GAAG,cAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAA;IACzC,MAAM,GAAG,GAAG,MAAM,IAAA,sBAAM,EAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAEzC,OAAO;QACL,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC;QAChB,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,MAAM,SAAS,EAAE,CAAA;YACjB,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBAC1C,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;oBAC1B,IAAI,GAAG;wBAAE,MAAM,CAAC,GAAG,CAAC,CAAA;oBACpB,OAAO,EAAE,CAAA;gBACX,CAAC,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;QACJ,CAAC;QACD,SAAS;KACV,CAAA;AACH,CAAC;AArBD,8BAqBC","sourcesContent":["import { createHandler, Options } from './create-handler'\nimport type { EdgeContext } from '@edge-runtime/vm'\nimport listen from 'async-listen'\nimport http from 'http'\nimport type { ListenOptions } from 'net'\n\ninterface ServerOptions<T extends EdgeContext> extends Options<T> {}\n\nexport interface EdgeRuntimeServer {\n /**\n * The server URL.\n */\n url: string\n /**\n * Waits for all the current effects and closes the server.\n */\n close: () => Promise<void>\n /**\n * Waits for all current effects returning their result.\n */\n waitUntil: () => Promise<any[]>\n}\n\n/**\n * This helper will create a handler based on the given options and then\n * immediately run a server on the provided port. If there is no port, the\n * server will use a random one.\n */\nexport async function runServer<T extends EdgeContext>(\n options: ListenOptions & ServerOptions<T>,\n): Promise<EdgeRuntimeServer> {\n if (options.port === undefined) options.port = 0\n const { handler, waitUntil } = createHandler(options)\n const server = http.createServer(handler)\n const url = await listen(server, options)\n\n return {\n url: String(url),\n close: async () => {\n await waitUntil()\n await new Promise<void>((resolve, reject) => {\n return server.close((err) => {\n if (err) reject(err)\n resolve()\n })\n })\n },\n waitUntil,\n }\n}\n"]}

17
node_modules/edge-runtime/dist/types.d.ts generated vendored Normal file
View file

@ -0,0 +1,17 @@
import type { Colors } from 'picocolors/types';
export interface LoggerOptions {
color?: keyof Colors;
withHeader?: boolean;
withBreakline?: boolean;
}
export interface Logger {
(message: string, opts?: LoggerOptions): void;
warn(message: string, opts?: LoggerOptions): void;
debug(message: string, opts?: LoggerOptions): void;
error(message: string, opts?: LoggerOptions): void;
info(message: string, opts?: LoggerOptions): void;
quotes(str: string): string;
}
export interface NodeHeaders {
[header: string]: string | string[] | undefined;
}

3
node_modules/edge-runtime/dist/types.js generated vendored Normal file
View file

@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map

1
node_modules/edge-runtime/dist/types.js.map generated vendored Normal file
View file

@ -0,0 +1 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Colors } from 'picocolors/types'\n\nexport interface LoggerOptions {\n color?: keyof Colors\n withHeader?: boolean\n withBreakline?: boolean\n}\n\nexport interface Logger {\n (message: string, opts?: LoggerOptions): void\n warn(message: string, opts?: LoggerOptions): void\n debug(message: string, opts?: LoggerOptions): void\n error(message: string, opts?: LoggerOptions): void\n info(message: string, opts?: LoggerOptions): void\n quotes(str: string): string\n}\n\nexport interface NodeHeaders {\n [header: string]: string | string[] | undefined\n}\n"]}