test1 addSignalListener function addSignalListener() {} removeSignalListener function removeSignalListener() {} args build [object Object] noColor false version [object Object] mainModule file:///src/main.ts ChildProcess class ChildProcess { get pid() { throw new TypeError("Not implemented"); } get stdin() { throw new TypeError("Not implemented"); } get stdout() { throw new TypeError("Not implemented"); } get stderr() { throw new TypeError("Not implemented"); } constructor() { throw new TypeError("Illegal constructor."); } get status() { throw new TypeError("Not implemented"); } // deno-lint-ignore require-await async output() { throw new TypeError("Not implemented"); } kill() { throw new TypeError("Not implemented"); } ref() { throw new TypeError("Not implemented"); } unref() { throw new TypeError("Not implemented"); } } Command class Command { constructor(_command, _options) { } // deno-lint-ignore require-await async output() { throw new PermissionDenied( "Spawning subprocesses is not allowed on Deno Deploy.", ); } outputSync() { throw new PermissionDenied( "Spawning subprocesses is not allowed on Deno Deploy.", ); } spawn() { throw new PermissionDenied( "Spawning subprocesses is not allowed on Deno Deploy.", ); } } kill function kill() { throw new PermissionDenied( "'Deno.kill' is not allowed in this context.", ); } connect async function connect(args) { switch (args.transport ?? "tcp") { case "tcp": { let cancelRid; let abortHandler; if (args?.signal) { args.signal.throwIfAborted(); cancelRid = createCancelHandle(); abortHandler = () => core.tryClose(cancelRid); args.signal[abortSignal.add](abortHandler); } const port = validatePort(args.port); try { const { 0: rid, 1: localAddr, 2: remoteAddr } = await op_net_connect_tcp( { hostname: args.hostname ?? "127.0.0.1", port, }, undefined, cancelRid, ); localAddr.transport = "tcp"; remoteAddr.transport = "tcp"; return new TcpConn(rid, remoteAddr, localAddr); } finally { if (args?.signal) { args.signal[abortSignal.remove](abortHandler); args.signal.throwIfAborted(); } } } case "unix": { const { 0: rid, 1: localAddr, 2: remoteAddr } = await op_net_connect_unix( args.path, ); return new UnixConn( rid, { transport: "unix", path: remoteAddr }, { transport: "unix", path: localAddr }, ); } case "vsock": { const { 0: rid, 1: localAddr, 2: remoteAddr } = await op_net_connect_vsock(args.cid, args.port); return new VsockConn( rid, { transport: "vsock", cid: remoteAddr[0], port: remoteAddr[1] }, { transport: "vsock", cid: localAddr[0], port: localAddr[1] }, ); } default: throw new TypeError(`Unsupported transport: '${transport}'`); } } listen function wrappedListen(args) { // Ignore the port number specified by the caller and use port 80 always. // This is needed to maintain compabitility; `Deno.listen({})` has been // working on Deploy, but since deno_net 0.158.0 it requires a port number // like `Deno.listen({ port: 80 })`. On Deploy, we open port 80 anyway, so // we simply accept any, possibly invalid, port number and use 80. return net.listen({ ...args, port: 80, }); } resolveDns async function resolveDns(query, recordType, options) { let cancelRid; let abortHandler; if (options?.signal) { options.signal.throwIfAborted(); cancelRid = createCancelHandle(); abortHandler = () => core.tryClose(cancelRid); options.signal[abortSignal.add](abortHandler); } try { const res = await op_dns_resolve({ cancelRid, query, recordType, options, }); return ArrayPrototypeMap(res, (recordWithTtl) => recordWithTtl.data); } finally { if (options?.signal) { options.signal[abortSignal.remove](abortHandler); // always throw the abort error when aborted options.signal.throwIfAborted(); } } } connectTls async function connectTls({ port, hostname = "127.0.0.1", transport = "tcp", caCerts = [], alpnProtocols = undefined, keyFormat = undefined, cert = undefined, key = undefined, }) { if (transport !== "tcp") { throw new TypeError(`Unsupported transport: '${transport}'`); } const keyPair = loadTlsKeyPair("Deno.connectTls", { keyFormat, cert, key, }); // TODO(mmastrac): We only expose this feature via symbol for now. This should actually be a feature // in Deno.connectTls, however. const serverName = arguments[0][serverNameSymbol] ?? null; const { 0: rid, 1: localAddr, 2: remoteAddr } = await op_net_connect_tls( { hostname, port }, { caCerts, alpnProtocols, serverName }, keyPair, ); localAddr.transport = "tcp"; remoteAddr.transport = "tcp"; return new TlsConn(rid, remoteAddr, localAddr); } startTls async function startTls( conn, { hostname = "127.0.0.1", caCerts = [], alpnProtocols = undefined, } = { __proto__: null }, ) { const { 0: rid, 1: localAddr, 2: remoteAddr } = op_tls_start({ rid: conn[internalRidSymbol], hostname, caCerts, alpnProtocols, }); return new TlsConn(rid, remoteAddr, localAddr); } consoleSize function consoleSize() { return { columns: 80, rows: 24 }; } isatty function isatty() { return false; } inspect function inspect( value, inspectOptions = { __proto__: null }, ) { // Default options const ctx = { ...getDefaultInspectOptions(), ...inspectOptions, }; if (inspectOptions.iterableLimit !== undefined) { ctx.maxArrayLength = inspectOptions.iterableLimit; } if (inspectOptions.strAbbreviateSize !== undefined) { ctx.maxStringLength = inspectOptions.strAbbreviateSize; } if (ctx.colors) ctx.stylize = createStylizeWithColor(styles, colors); if (ctx.maxArrayLength === null) ctx.maxArrayLength = Infinity; if (ctx.maxStringLength === null) ctx.maxStringLength = Infinity; return formatValue(ctx, value, 0); } env [object Object] execPath function execPath() { // TODO(@AaronO): consider a different path that is unambiguously fake ? return "/bin/deno"; } exit function exit() { throw new PermissionDenied( "'Deno.exit' is not allowed in this context.", ); } gid function gid() { return 1000; } hostname function hostname() { return "localhost"; } loadavg function loadavg() { // returns fake data return [0, 0, 0]; } memoryUsage function memoryUsage() { // returns fake data return { rss: 0, heapTotal: 0, heapUsed: 0, external: 0, }; } networkInterfaces function networkInterfaces() { // returns fake data return [ { family: "IPv4", name: "lo", address: "127.0.0.1", netmask: "255.0.0.0", scopeid: null, cidr: "127.0.0.1/8", mac: "00:00:00:00:00:00", }, { family: "IPv4", name: "eth0", address: "10.0.0.10", netmask: "255.255.255.0", scopeid: null, cidr: "10.0.0.10/24", mac: "00:00:00:00:00:01", }, ]; } osRelease function osRelease() { return "0.0.0-00000000-generic"; } osUptime function osUptime() { return Math.floor(performance.now() / 1000); } systemMemoryInfo function systemMemoryInfo() { // returns fake data return { total: 0, free: 0, available: 0, buffers: 0, cached: 0, swapTotal: 0, swapFree: 0, }; } uid function uid() { return 1000; } permissions [object Object] Permissions class Permissions { constructor(key = null) { if (key != illegalConstructorKey) { throw new TypeError("Illegal constructor."); } } query(desc) { if (!isValidDescriptor(desc)) { return PromiseReject( new TypeError( `The provided value "${desc.name}" is not a valid permission name.`, ), ); } // TODO(@AaronO): handle dynamic net permissions specified in subhosting switch (desc.name) { case "env": case "net": case "read": case "sys": return PromiseResolve( new PermissionStatus({ state: "granted" }, illegalConstructorKey), ); default: return PromiseResolve( new PermissionStatus({ state: "denied" }, illegalConstructorKey), ); } } request(desc) { return this.query(desc); } revoke(_desc) { return PromiseReject( new PermissionDenied( "'Deno.permission.revoke' is not allowed in this context.", ), ); } } PermissionStatus class PermissionStatus extends EventTarget { /** @type {{ state: Deno.PermissionState }} */ #state; /** @type {((this: PermissionStatus, event: Event) => any) | null} */ onchange = null; /** @returns {Deno.PermissionState} */ get state() { return this.#state.state; } /** * @param {{ state: Deno.PermissionState }} state * @param {unknown} key */ constructor(state = null, key = null) { if (key != illegalConstructorKey) { throw new TypeError("Illegal constructor."); } super(); this.#state = state; } /** * @param {Event} event * @returns {boolean} */ dispatchEvent(event) { let dispatched = super.dispatchEvent(event); if (dispatched && this.onchange) { FunctionPrototypeCall(this.onchange, this, event); dispatched = !event.defaultPrevented; } return dispatched; } [SymbolFor("Deno.privateCustomInspect")](inspect) { return `${this.constructor.name} ${ inspect({ state: this.state, onchange: this.onchange }) }`; } } refTimer function refTimer(id) { core.refTimer(id); } unrefTimer function unrefTimer(id) { core.unrefTimer(id); } serve function wrappedServe(arg1, arg2) { // Ignore the port number if specified by the caller and use port 80 always. // // This is needed to maintain compabitility; the following examples have been // working on Deploy: // // ```ts // Deno.serve({ port: NaN }, () => new Response("ok")); // ``` // // ```ts // Deno.serve({ port: "INVALID" }, () => new Response("ok")); // ``` // // ```ts // Deno.serve({ port: 12.34, handler: () => new Response("ok") }); // ``` // // However, since deno_http 0.163.0, it performs a port number validation and // these examples are flagged as invalid. To ensure these will keep working, // we simply accept any, possibly invalid, port number and use 80. if (typeof arg1 !== "function") { arg1.port = 80; } return serve.serve(arg1, arg2); } serveHttp function serveHttp(conn) { const rid = core.ops.op_http_start(conn[core.internalRidSymbol]); return new HttpConn(rid, conn.remoteAddr, conn.localAddr); } upgradeWebSocket function upgradeWebSocket(request, options = { __proto__: null }) { const inner = toInnerRequest(request); const upgrade = request.headers.get("upgrade"); const upgradeHasWebSocketOption = upgrade !== null && websocketCvf(upgrade); if (!upgradeHasWebSocketOption) { throw new TypeError("Invalid Header: 'upgrade' header must contain 'websocket'"); } const connection = request.headers.get("connection"); const connectionHasUpgradeOption = connection !== null && upgradeCvf(connection); if (!connectionHasUpgradeOption) { throw new TypeError("Invalid Header: 'connection' header must contain 'Upgrade'"); } const websocketKey = request.headers.get("sec-websocket-key"); if (websocketKey === null) { throw new TypeError("Invalid Header: 'sec-websocket-key' header must be set"); } const accept = op_http_websocket_accept_header(websocketKey); const r = newInnerResponse(101); r.headerList = [ [ "upgrade", "websocket" ], [ "connection", "Upgrade" ], [ "sec-websocket-accept", accept ] ]; const protocolsStr = request.headers.get("sec-websocket-protocol") || ""; const protocols = StringPrototypeSplit(protocolsStr, ", "); if (protocols && options.protocol) { if (ArrayPrototypeIncludes(protocols, options.protocol)) { ArrayPrototypePush(r.headerList, [ "sec-websocket-protocol", options.protocol ]); } else { throw new TypeError(`Protocol '${options.protocol}' not in the request's protocol list (non negotiable)`); } } const socket = createWebSocketBranded(WebSocket); setEventTargetData(socket); socket[_server] = true; // Nginx timeout is 60s, so default to a lower number: https://github.com/denoland/deno/pull/23985 socket[_idleTimeoutDuration] = options.idleTimeout ?? 30; socket[_idleTimeoutTimeout] = null; if (inner._wantsUpgrade) { return inner._wantsUpgrade("upgradeWebSocket", r, socket); } const response = fromInnerResponse(r, "immutable"); response[_ws] = socket; return { response, socket }; } stderr [object Object] stdin [object Object] stdout [object Object] AtomicOperation class AtomicOperation { #rid; #checks = []; #mutations = []; #enqueues = []; constructor(rid){ this.#rid = rid; } check(...checks) { for(let i = 0; i < checks.length; ++i){ const check = checks[i]; ArrayPrototypePush(this.#checks, [ check.key, check.versionstamp ]); } return this; } mutate(...mutations) { for(let i = 0; i < mutations.length; ++i){ const mutation = mutations[i]; const key = mutation.key; let type; let value; let expireIn = undefined; switch(mutation.type){ case "delete": type = "delete"; if (mutation.value) { throw new TypeError("Invalid mutation 'delete' with value"); } break; case "set": if (typeof mutation.expireIn === "number") { expireIn = mutation.expireIn; } /* falls through */ case "sum": case "min": case "max": type = mutation.type; if (!ObjectHasOwn(mutation, "value")) { throw new TypeError(`Invalid mutation '${type}' without value`); } value = serializeValue(mutation.value); break; default: throw new TypeError("Invalid mutation type"); } ArrayPrototypePush(this.#mutations, [ key, type, value, expireIn ]); } return this; } sum(key, n) { ArrayPrototypePush(this.#mutations, [ key, "sum", serializeValue(new KvU64(n)), undefined ]); return this; } min(key, n) { ArrayPrototypePush(this.#mutations, [ key, "min", serializeValue(new KvU64(n)), undefined ]); return this; } max(key, n) { ArrayPrototypePush(this.#mutations, [ key, "max", serializeValue(new KvU64(n)), undefined ]); return this; } set(key, value, options) { ArrayPrototypePush(this.#mutations, [ key, "set", serializeValue(value), options?.expireIn ]); return this; } delete(key) { ArrayPrototypePush(this.#mutations, [ key, "delete", null, undefined ]); return this; } enqueue(message, opts) { if (opts?.delay !== undefined) { validateQueueDelay(opts?.delay); } if (opts?.backoffSchedule !== undefined) { validateBackoffSchedule(opts?.backoffSchedule); } ArrayPrototypePush(this.#enqueues, [ core.serialize(message, { forStorage: true }), opts?.delay ?? 0, opts?.keysIfUndelivered ?? [], opts?.backoffSchedule ?? null ]); return this; } async commit() { const versionstamp = await doAtomicWriteInPlace(this.#rid, this.#checks, this.#mutations, this.#enqueues); if (versionstamp === null) return { ok: false }; return { ok: true, versionstamp }; } then() { throw new TypeError("'Deno.AtomicOperation' is not a promise: did you forget to call 'commit()'"); } } openKv async function openKv(path) { const rid = await op_kv_database_open(path); return new Kv(rid, kvSymbol); } Kv class Kv { #rid; #isClosed; constructor(rid = undefined, symbol = undefined){ if (kvSymbol !== symbol) { throw new TypeError("Deno.Kv can not be constructed: use Deno.openKv instead"); } this.#rid = rid; this.#isClosed = false; } atomic() { return new AtomicOperation(this.#rid); } commitVersionstamp() { return commitVersionstampSymbol; } async get(key, opts) { const { 0: entries } = await op_kv_snapshot_read(this.#rid, [ [ null, key, null, 1, false, null ] ], opts?.consistency ?? "strong"); if (!entries.length) { return { key, value: null, versionstamp: null }; } return deserializeValue(entries[0]); } async getMany(keys, opts) { const ranges = await op_kv_snapshot_read(this.#rid, ArrayPrototypeMap(keys, (key)=>[ null, key, null, 1, false, null ]), opts?.consistency ?? "strong"); return ArrayPrototypeMap(ranges, (entries, i)=>{ if (!entries.length) { return { key: keys[i], value: null, versionstamp: null }; } return deserializeValue(entries[0]); }); } async set(key, value, options) { const versionstamp = await doAtomicWriteInPlace(this.#rid, [], [ [ key, "set", serializeValue(value), options?.expireIn ] ], []); if (versionstamp === null) throw new TypeError("Failed to set value"); return { ok: true, versionstamp }; } async delete(key) { const result = await doAtomicWriteInPlace(this.#rid, [], [ [ key, "delete", null, undefined ] ], []); if (!result) throw new TypeError("Failed to set value"); } list(selector, options = { __proto__: null }) { if (options.limit !== undefined && options.limit <= 0) { throw new Error(`Limit must be positive: received ${options.limit}`); } let batchSize = options.batchSize ?? options.limit ?? 100; if (batchSize <= 0) throw new Error("batchSize must be positive"); if (options.batchSize === undefined && batchSize > 500) batchSize = 500; return new KvListIterator({ limit: options.limit, selector, cursor: options.cursor, reverse: options.reverse ?? false, consistency: options.consistency ?? "strong", batchSize, pullBatch: this.#pullBatch(batchSize) }); } #pullBatch(batchSize) { return async (selector, cursor, reverse, consistency)=>{ const { 0: entries } = await op_kv_snapshot_read(this.#rid, [ [ ObjectHasOwn(selector, "prefix") ? selector.prefix : null, ObjectHasOwn(selector, "start") ? selector.start : null, ObjectHasOwn(selector, "end") ? selector.end : null, batchSize, reverse, cursor ] ], consistency); return ArrayPrototypeMap(entries, deserializeValue); }; } async enqueue(message, opts) { if (opts?.delay !== undefined) { validateQueueDelay(opts?.delay); } if (opts?.backoffSchedule !== undefined) { validateBackoffSchedule(opts?.backoffSchedule); } const versionstamp = await doAtomicWriteInPlace(this.#rid, [], [], [ [ core.serialize(message, { forStorage: true }), opts?.delay ?? 0, opts?.keysIfUndelivered ?? [], opts?.backoffSchedule ?? null ] ]); if (versionstamp === null) throw new TypeError("Failed to enqueue value"); return { ok: true, versionstamp }; } async listenQueue(handler) { if (this.#isClosed) { throw new Error("Queue already closed"); } const finishMessageOps = new SafeMap(); while(true){ // Wait for the next message. const next = await op_kv_dequeue_next_message(this.#rid); if (next === null) { break; } // Deserialize the payload. const { 0: payload, 1: handleId } = next; const deserializedPayload = core.deserialize(payload, { forStorage: true }); // Dispatch the payload. (async ()=>{ let success = false; try { const result = handler(deserializedPayload); const _res = isPromise(result) ? await result : result; success = true; } catch (error) { import.meta.log("error", "Exception in queue handler", error); } finally{ const promise = op_kv_finish_dequeued_message(handleId, success); finishMessageOps.set(handleId, promise); try { await promise; } finally{ finishMessageOps.delete(handleId); } } })(); } for (const { 1: promise } of new SafeMapIterator(finishMessageOps)){ await promise; } finishMessageOps.clear(); } watch(keys, options = { __proto__: null }) { const raw = options.raw ?? false; const rid = op_kv_watch(this.#rid, keys); const lastEntries = ArrayFrom({ length: keys.length }); return new ReadableStream({ async pull (controller) { while(true){ let updates; try { updates = await op_kv_watch_next(rid); } catch (err) { core.tryClose(rid); controller.error(err); return; } if (updates === null) { core.tryClose(rid); controller.close(); return; } let changed = false; for(let i = 0; i < keys.length; i++){ if (updates[i] === "unchanged") { if (lastEntries[i] === undefined) { throw new Error("'watch': invalid unchanged update (internal error)"); } continue; } if (lastEntries[i] !== undefined && (updates[i]?.versionstamp ?? null) === lastEntries[i]?.versionstamp) { continue; } changed = true; if (updates[i] === null) { lastEntries[i] = { key: ArrayPrototypeSlice(keys[i]), value: null, versionstamp: null }; } else { lastEntries[i] = updates[i]; } } if (!changed && !raw) continue; // no change const entries = ArrayPrototypeMap(lastEntries, (entry)=>entry.versionstamp === null ? { ...entry } : deserializeValue(entry)); controller.enqueue(entries); return; } }, cancel () { core.tryClose(rid); } }); } close() { core.close(this.#rid); this.#isClosed = true; } [SymbolDispose]() { core.tryClose(this.#rid); } } KvU64 class KvU64 { value; constructor(value){ if (typeof value !== "bigint") { throw new TypeError(`Value must be a bigint: received ${typeof value}`); } if (value < MIN_U64) { throw new RangeError(`Value must be a positive bigint: received ${value}`); } if (value > MAX_U64) { throw new RangeError("Value must fit in a 64-bit unsigned integer"); } this.value = value; ObjectFreeze(this); } valueOf() { return this.value; } toString() { return BigIntPrototypeToString(this.value); } get [SymbolToStringTag]() { return "Deno.KvU64"; } [SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) { return StringPrototypeReplace(inspect(Object(this.value), inspectOptions), "BigInt", "Deno.KvU64"); } } KvListIterator class KvListIterator extends AsyncIterator { #selector; #entries = null; #cursorGen = null; #done = false; #lastBatch = false; #pullBatch; #limit; #count = 0; #reverse; #batchSize; #consistency; constructor({ limit, selector, cursor, reverse, consistency, batchSize, pullBatch }){ super(); let prefix; let start; let end; if (ObjectHasOwn(selector, "prefix") && selector.prefix !== undefined) { prefix = ObjectFreeze(ArrayPrototypeSlice(selector.prefix)); } if (ObjectHasOwn(selector, "start") && selector.start !== undefined) { start = ObjectFreeze(ArrayPrototypeSlice(selector.start)); } if (ObjectHasOwn(selector, "end") && selector.end !== undefined) { end = ObjectFreeze(ArrayPrototypeSlice(selector.end)); } if (prefix) { if (start && end) { throw new TypeError("Selector can not specify both 'start' and 'end' key when specifying 'prefix'"); } if (start) { this.#selector = { prefix, start }; } else if (end) { this.#selector = { prefix, end }; } else { this.#selector = { prefix }; } } else { if (start && end) { this.#selector = { start, end }; } else { throw new TypeError("Selector must specify either 'prefix' or both 'start' and 'end' key"); } } ObjectFreeze(this.#selector); this.#pullBatch = pullBatch; this.#limit = limit; this.#reverse = reverse; this.#consistency = consistency; this.#batchSize = batchSize; this.#cursorGen = cursor ? ()=>cursor : null; } get cursor() { if (this.#cursorGen === null) { throw new Error("Cannot get cursor before first iteration"); } return this.#cursorGen(); } async next() { // Fused or limit exceeded if (this.#done || this.#limit !== undefined && this.#count >= this.#limit) { return { done: true, value: undefined }; } // Attempt to fill the buffer if (!this.#entries?.length && !this.#lastBatch) { const batch = await this.#pullBatch(this.#selector, this.#cursorGen ? this.#cursorGen() : undefined, this.#reverse, this.#consistency); // Reverse the batch so we can pop from the end ArrayPrototypeReverse(batch); this.#entries = batch; // Last batch, do not attempt to pull more if (batch.length < this.#batchSize) { this.#lastBatch = true; } } const entry = this.#entries?.pop(); if (!entry) { this.#done = true; this.#cursorGen = ()=>""; return { done: true, value: undefined }; } this.#cursorGen = ()=>{ const selector = this.#selector; return encodeCursor([ ObjectHasOwn(selector, "prefix") ? selector.prefix : null, ObjectHasOwn(selector, "start") ? selector.start : null, ObjectHasOwn(selector, "end") ? selector.end : null ], entry.key); }; this.#count++; return { done: false, value: entry }; } [SymbolAsyncIterator]() { return this; } } SeekMode [object Object] chdir function chdir(directory) { op_fs_chdir(pathFromURL(directory)); } chmod async function chmod(path, mode) { await op_fs_chmod_async(pathFromURL(path), mode); } chmodSync function chmodSync(path, mode) { op_fs_chmod_sync(pathFromURL(path), mode); } chown async function chown( path, uid, gid, ) { await op_fs_chown_async( pathFromURL(path), uid, gid, ); } chownSync function chownSync( path, uid, gid, ) { op_fs_chown_sync(pathFromURL(path), uid, gid); } copyFile async function copyFile( fromPath, toPath, ) { await op_fs_copy_file_async( pathFromURL(fromPath), pathFromURL(toPath), ); } copyFileSync function copyFileSync( fromPath, toPath, ) { op_fs_copy_file_sync( pathFromURL(fromPath), pathFromURL(toPath), ); } create function create(path) { return open(path, { read: true, write: true, truncate: true, create: true, }); } createSync function createSync(path) { return openSync(path, { read: true, write: true, truncate: true, create: true, }); } cwd function cwd() { return op_fs_cwd(); } File class FsFile { #rid = 0; #readable; #writable; constructor(rid, symbol) { ObjectDefineProperty(this, internalRidSymbol, { __proto__: null, enumerable: false, value: rid, }); this.#rid = rid; if (!symbol || symbol !== SymbolFor("Deno.internal.FsFile")) { throw new TypeError( "'Deno.FsFile' cannot be constructed, use 'Deno.open()' or 'Deno.openSync()' instead", ); } } write(p) { return write(this.#rid, p); } writeSync(p) { return writeSync(this.#rid, p); } truncate(len) { return op_fs_file_truncate_async(this.#rid, coerceLen(len)); } truncateSync(len) { return op_fs_ftruncate_sync(this.#rid, coerceLen(len)); } read(p) { return read(this.#rid, p); } readSync(p) { return readSync(this.#rid, p); } seek(offset, whence) { return op_fs_seek_async(this.#rid, offset, whence); } seekSync(offset, whence) { return op_fs_seek_sync(this.#rid, offset, whence); } async stat() { return parseFileInfo(await op_fs_file_stat_async(this.#rid)); } statSync() { op_fs_file_stat_sync(this.#rid, statBuf); return statStruct(statBuf); } async syncData() { await op_fs_file_sync_data_async(this.#rid); } syncDataSync() { op_fs_file_sync_data_sync(this.#rid); } close() { core.close(this.#rid); } get readable() { if (this.#readable === undefined) { this.#readable = readableStreamForRid(this.#rid); } return this.#readable; } get writable() { if (this.#writable === undefined) { this.#writable = writableStreamForRid(this.#rid); } return this.#writable; } async sync() { await op_fs_file_sync_async(this.#rid); } syncSync() { op_fs_file_sync_sync(this.#rid); } async utime(atime, mtime) { const { 0: atimeSec, 1: atimeNsec } = toUnixTimeFromEpoch(atime); const { 0: mtimeSec, 1: mtimeNsec } = toUnixTimeFromEpoch(mtime); await op_fs_futime_async( this.#rid, atimeSec, atimeNsec, mtimeSec, mtimeNsec, ); } utimeSync(atime, mtime) { const { 0: atimeSec, 1: atimeNsec } = toUnixTimeFromEpoch(atime); const { 0: mtimeSec, 1: mtimeNsec } = toUnixTimeFromEpoch(mtime); op_fs_futime_sync(this.#rid, atimeSec, atimeNsec, mtimeSec, mtimeNsec); } isTerminal() { return core.isTerminal(this.#rid); } setRaw(mode, options = { __proto__: null }) { const cbreak = !!(options.cbreak ?? false); op_set_raw(this.#rid, mode, cbreak); } lockSync(exclusive = false) { op_fs_flock_sync(this.#rid, exclusive); } async lock(exclusive = false) { await op_fs_flock_async(this.#rid, exclusive); } unlockSync() { op_fs_funlock_sync(this.#rid); } async unlock() { await op_fs_funlock_async(this.#rid); } [SymbolDispose]() { core.tryClose(this.#rid); } } FsFile class FsFile { #rid = 0; #readable; #writable; constructor(rid, symbol) { ObjectDefineProperty(this, internalRidSymbol, { __proto__: null, enumerable: false, value: rid, }); this.#rid = rid; if (!symbol || symbol !== SymbolFor("Deno.internal.FsFile")) { throw new TypeError( "'Deno.FsFile' cannot be constructed, use 'Deno.open()' or 'Deno.openSync()' instead", ); } } write(p) { return write(this.#rid, p); } writeSync(p) { return writeSync(this.#rid, p); } truncate(len) { return op_fs_file_truncate_async(this.#rid, coerceLen(len)); } truncateSync(len) { return op_fs_ftruncate_sync(this.#rid, coerceLen(len)); } read(p) { return read(this.#rid, p); } readSync(p) { return readSync(this.#rid, p); } seek(offset, whence) { return op_fs_seek_async(this.#rid, offset, whence); } seekSync(offset, whence) { return op_fs_seek_sync(this.#rid, offset, whence); } async stat() { return parseFileInfo(await op_fs_file_stat_async(this.#rid)); } statSync() { op_fs_file_stat_sync(this.#rid, statBuf); return statStruct(statBuf); } async syncData() { await op_fs_file_sync_data_async(this.#rid); } syncDataSync() { op_fs_file_sync_data_sync(this.#rid); } close() { core.close(this.#rid); } get readable() { if (this.#readable === undefined) { this.#readable = readableStreamForRid(this.#rid); } return this.#readable; } get writable() { if (this.#writable === undefined) { this.#writable = writableStreamForRid(this.#rid); } return this.#writable; } async sync() { await op_fs_file_sync_async(this.#rid); } syncSync() { op_fs_file_sync_sync(this.#rid); } async utime(atime, mtime) { const { 0: atimeSec, 1: atimeNsec } = toUnixTimeFromEpoch(atime); const { 0: mtimeSec, 1: mtimeNsec } = toUnixTimeFromEpoch(mtime); await op_fs_futime_async( this.#rid, atimeSec, atimeNsec, mtimeSec, mtimeNsec, ); } utimeSync(atime, mtime) { const { 0: atimeSec, 1: atimeNsec } = toUnixTimeFromEpoch(atime); const { 0: mtimeSec, 1: mtimeNsec } = toUnixTimeFromEpoch(mtime); op_fs_futime_sync(this.#rid, atimeSec, atimeNsec, mtimeSec, mtimeNsec); } isTerminal() { return core.isTerminal(this.#rid); } setRaw(mode, options = { __proto__: null }) { const cbreak = !!(options.cbreak ?? false); op_set_raw(this.#rid, mode, cbreak); } lockSync(exclusive = false) { op_fs_flock_sync(this.#rid, exclusive); } async lock(exclusive = false) { await op_fs_flock_async(this.#rid, exclusive); } unlockSync() { op_fs_funlock_sync(this.#rid); } async unlock() { await op_fs_funlock_async(this.#rid); } [SymbolDispose]() { core.tryClose(this.#rid); } } link async function link(oldpath, newpath) { await op_fs_link_async(oldpath, newpath); } linkSync function linkSync(oldpath, newpath) { op_fs_link_sync(oldpath, newpath); } lstat async function lstat(path) { const res = await op_fs_lstat_async(pathFromURL(path)); return parseFileInfo(res); } makeTempDir function makeTempDir(options = { __proto__: null }) { return op_fs_make_temp_dir_async( options.dir, options.prefix, options.suffix, ); } makeTempDirSync function makeTempDirSync(options = { __proto__: null }) { return op_fs_make_temp_dir_sync( options.dir, options.prefix, options.suffix, ); } makeTempFile function makeTempFile(options = { __proto__: null }) { return op_fs_make_temp_file_async( options.dir, options.prefix, options.suffix, ); } makeTempFileSync function makeTempFileSync(options = { __proto__: null }) { return op_fs_make_temp_file_sync( options.dir, options.prefix, options.suffix, ); } mkdir async function mkdir(path, options) { await op_fs_mkdir_async( pathFromURL(path), options?.recursive ?? false, options?.mode, ); } mkdirSync function mkdirSync(path, options) { op_fs_mkdir_sync( pathFromURL(path), options?.recursive ?? false, options?.mode, ); } open async function open( path, options, ) { if (options) checkOpenOptions(options); const rid = await op_fs_open_async( pathFromURL(path), options, ); return new FsFile(rid, SymbolFor("Deno.internal.FsFile")); } readDir function readDir(path) { const array = op_fs_read_dir_async( pathFromURL(path), ); return { async *[SymbolAsyncIterator]() { const dir = await array; for (let i = 0; i < dir.length; ++i) { yield dir[i]; } }, }; } readFile async function readFile(path, options) { let cancelRid; let abortHandler; if (options?.signal) { options.signal.throwIfAborted(); cancelRid = createCancelHandle(); abortHandler = () => core.tryClose(cancelRid); options.signal[abortSignal.add](abortHandler); } try { const read = await op_fs_read_file_async( pathFromURL(path), cancelRid, ); return read; } finally { if (options?.signal) { options.signal[abortSignal.remove](abortHandler); // always throw the abort error when aborted options.signal.throwIfAborted(); } } } readLink function readLink(path) { return op_fs_read_link_async(pathFromURL(path)); } readTextFile async function readTextFile(path, options) { let cancelRid; let abortHandler; if (options?.signal) { options.signal.throwIfAborted(); cancelRid = createCancelHandle(); abortHandler = () => core.tryClose(cancelRid); options.signal[abortSignal.add](abortHandler); } try { const read = await op_fs_read_file_text_async( pathFromURL(path), cancelRid, ); return read; } finally { if (options?.signal) { options.signal[abortSignal.remove](abortHandler); // always throw the abort error when aborted options.signal.throwIfAborted(); } } } realPath function realPath(path) { return op_fs_realpath_async(pathFromURL(path)); } remove async function remove( path, options = { __proto__: null }, ) { await op_fs_remove_async( pathFromURL(path), !!options.recursive, ); } removeSync function removeSync( path, options = { __proto__: null }, ) { op_fs_remove_sync( pathFromURL(path), !!options.recursive, ); } rename async function rename(oldpath, newpath) { await op_fs_rename_async( pathFromURL(oldpath), pathFromURL(newpath), ); } renameSync function renameSync(oldpath, newpath) { op_fs_rename_sync( pathFromURL(oldpath), pathFromURL(newpath), ); } stat async function stat(path) { const res = await op_fs_stat_async(pathFromURL(path)); return parseFileInfo(res); } symlink async function symlink( oldpath, newpath, options, ) { await op_fs_symlink_async( pathFromURL(oldpath), pathFromURL(newpath), options?.type, ); } symlinkSync function symlinkSync( oldpath, newpath, options, ) { op_fs_symlink_sync( pathFromURL(oldpath), pathFromURL(newpath), options?.type, ); } truncate async function truncate(path, len) { await op_fs_truncate_async(path, coerceLen(len)); } truncateSync function truncateSync(path, len) { op_fs_truncate_sync(path, coerceLen(len)); } utime async function utime( path, atime, mtime, ) { const { 0: atimeSec, 1: atimeNsec } = toUnixTimeFromEpoch(atime); const { 0: mtimeSec, 1: mtimeNsec } = toUnixTimeFromEpoch(mtime); await op_fs_utime_async( pathFromURL(path), atimeSec, atimeNsec, mtimeSec, mtimeNsec, ); } utimeSync function utimeSync( path, atime, mtime, ) { const { 0: atimeSec, 1: atimeNsec } = toUnixTimeFromEpoch(atime); const { 0: mtimeSec, 1: mtimeNsec } = toUnixTimeFromEpoch(mtime); op_fs_utime_sync( pathFromURL(path), atimeSec, atimeNsec, mtimeSec, mtimeNsec, ); } watchFs function watchFs() { return new FsWatcher(); } writeFile async function writeFile( path, data, options = { __proto__: null }, ) { let cancelRid; let abortHandler; if (options.signal) { options.signal.throwIfAborted(); cancelRid = createCancelHandle(); abortHandler = () => core.tryClose(cancelRid); options.signal[abortSignal.add](abortHandler); } try { if (ObjectPrototypeIsPrototypeOf(ReadableStreamPrototype, data)) { const file = await open(path, { mode: options.mode, append: options.append ?? false, create: options.create ?? true, createNew: options.createNew ?? false, truncate: !(options.append ?? false), write: true, }); await data.pipeTo(file.writable, { signal: options.signal, }); } else { await op_fs_write_file_async( pathFromURL(path), options.mode, options.append ?? false, options.create ?? true, options.createNew ?? false, data, cancelRid, ); } } finally { if (options.signal) { options.signal[abortSignal.remove](abortHandler); // always throw the abort error when aborted options.signal.throwIfAborted(); } } } writeFileSync function writeFileSync( path, data, options = { __proto__: null }, ) { options.signal?.throwIfAborted(); op_fs_write_file_sync( pathFromURL(path), options.mode, options.append ?? false, options.create ?? true, options.createNew ?? false, data, ); } writeTextFile function writeTextFile( path, data, options = { __proto__: null }, ) { if (ObjectPrototypeIsPrototypeOf(ReadableStreamPrototype, data)) { return writeFile( path, data.pipeThrough(new TextEncoderStream()), options, ); } else { const encoder = new TextEncoder(); return writeFile(path, encoder.encode(data), options); } } writeTextFileSync function writeTextFileSync( path, data, options = { __proto__: null }, ) { const encoder = new TextEncoder(); return writeFileSync(path, encoder.encode(data), options); } lstatSync function lstatSync(path) { op_fs_lstat_sync(pathFromURL(path), statBuf); return statStruct(statBuf); } openSync function openSync( path, options, ) { if (options) checkOpenOptions(options); const rid = op_fs_open_sync( pathFromURL(path), options, ); return new FsFile(rid, SymbolFor("Deno.internal.FsFile")); } readDirSync function readDirSync(path) { return op_fs_read_dir_sync(pathFromURL(path))[ SymbolIterator ](); } readFileSync function readFileSync(path) { return op_fs_read_file_sync(pathFromURL(path)); } readLinkSync function readLinkSync(path) { return op_fs_read_link_sync(pathFromURL(path)); } readTextFileSync function readTextFileSync(path) { return op_fs_read_file_text_sync(pathFromURL(path)); } realPathSync function realPathSync(path) { return op_fs_realpath_sync(pathFromURL(path)); } statSync function statSync(path) { op_fs_stat_sync(pathFromURL(path), statBuf); return statStruct(statBuf); } cron function cron(name, schedule, handlerOrOptions1, handler2) { if (name === undefined) { throw new TypeError("Cannot create cron job, a unique name is required: received 'undefined'"); } if (schedule === undefined) { throw new TypeError("Cannot create cron job, a schedule is required: received 'undefined'"); } schedule = parseScheduleToString(schedule); let handler; let options = undefined; if (typeof handlerOrOptions1 === "function") { handler = handlerOrOptions1; if (handler2 !== undefined) { throw new TypeError("Cannot create cron job, a single handler is required: two handlers were specified"); } } else if (typeof handler2 === "function") { handler = handler2; options = handlerOrOptions1; } else { throw new TypeError("Cannot create cron job: a handler is required"); } const rid = op_cron_create(name, schedule, options?.backoffSchedule); if (options?.signal) { const signal = options?.signal; signal.addEventListener("abort", ()=>{ core.close(rid); }, { once: true }); } return (async ()=>{ let success = true; while(true){ const r = await op_cron_next(rid, success); if (r === false) { break; } try { const result = handler(); const _res = isPromise(result) ? await result : result; success = true; } catch (error) { import.meta.log("error", `Exception in cron handler ${name}`, error); success = false; } } })(); } bench bench() {} test test() {} metrics metrics() { return {}; } resources resources() { return {}; } pid 2 ppid 1