├── .cargo └── config ├── .gitattributes ├── .gitignore ├── .gitmodules ├── Cargo.lock ├── Cargo.toml ├── README.md ├── doc ├── benchmark.md ├── devtools.md └── images │ ├── breakpoint1.jpg │ ├── cpuprofile1.jpg │ ├── image1.jpg │ └── memory.jpg ├── src ├── 01_inspector.js ├── 01_skynet.js ├── 01_tls.js ├── interface.rs ├── lib.rs ├── loader.rs ├── mod_inspector.rs ├── mod_skynet.rs └── mod_tls.rs └── ts ├── dts ├── README.md ├── lib.d.ts ├── lib.deno.d.ts ├── lib.deno.ns.d.ts ├── lib.deno.shared_globals.d.ts ├── lib.deno.unstable.d.ts ├── lib.deno.window.d.ts ├── lib.deno.worker.d.ts ├── lib.dom.asynciterable.d.ts ├── lib.dom.d.ts ├── lib.dom.iterable.d.ts ├── lib.es2015.collection.d.ts ├── lib.es2015.core.d.ts ├── lib.es2015.d.ts ├── lib.es2015.generator.d.ts ├── lib.es2015.iterable.d.ts ├── lib.es2015.promise.d.ts ├── lib.es2015.proxy.d.ts ├── lib.es2015.reflect.d.ts ├── lib.es2015.symbol.d.ts ├── lib.es2015.symbol.wellknown.d.ts ├── lib.es2016.array.include.d.ts ├── lib.es2016.d.ts ├── lib.es2016.full.d.ts ├── lib.es2017.d.ts ├── lib.es2017.full.d.ts ├── lib.es2017.intl.d.ts ├── lib.es2017.object.d.ts ├── lib.es2017.sharedmemory.d.ts ├── lib.es2017.string.d.ts ├── lib.es2017.typedarrays.d.ts ├── lib.es2018.asyncgenerator.d.ts ├── lib.es2018.asynciterable.d.ts ├── lib.es2018.d.ts ├── lib.es2018.full.d.ts ├── lib.es2018.intl.d.ts ├── lib.es2018.promise.d.ts ├── lib.es2018.regexp.d.ts ├── lib.es2019.array.d.ts ├── lib.es2019.d.ts ├── lib.es2019.full.d.ts ├── lib.es2019.object.d.ts ├── lib.es2019.string.d.ts ├── lib.es2019.symbol.d.ts ├── lib.es2020.bigint.d.ts ├── lib.es2020.d.ts ├── lib.es2020.full.d.ts ├── lib.es2020.intl.d.ts ├── lib.es2020.promise.d.ts ├── lib.es2020.sharedmemory.d.ts ├── lib.es2020.string.d.ts ├── lib.es2020.symbol.wellknown.d.ts ├── lib.es5.d.ts ├── lib.es6.d.ts ├── lib.esnext.d.ts ├── lib.esnext.full.d.ts ├── lib.esnext.intl.d.ts ├── lib.esnext.promise.d.ts ├── lib.esnext.string.d.ts ├── lib.esnext.weakref.d.ts ├── lib.scripthost.d.ts ├── lib.webworker.d.ts ├── lib.webworker.importscripts.d.ts ├── lib.webworker.iterable.d.ts └── typescript.d.ts ├── lib ├── jsSHA │ ├── common.ts │ ├── converters.ts │ ├── custom_types.ts │ ├── license_header.es3.txt │ ├── license_header.es6.txt │ ├── primitives_32.ts │ ├── primitives_64.ts │ ├── sha.ts │ ├── sha1.ts │ ├── sha256.ts │ ├── sha3.ts │ └── sha512.ts ├── loader.ts ├── protobufjs │ ├── index.d.ts │ └── protobuf.js ├── skynet │ ├── crypt │ │ ├── index.ts │ │ └── md5.ts │ ├── http │ │ ├── helper.ts │ │ ├── httpc.ts │ │ ├── httpd.ts │ │ ├── internal.ts │ │ ├── types.ts │ │ └── websocket.ts │ ├── lua_seri.ts │ ├── pack.ts │ ├── skynet │ │ ├── db │ │ │ ├── mongo │ │ │ │ ├── bson.ts │ │ │ │ └── index.ts │ │ │ └── mysql.ts │ │ ├── debug.ts │ │ ├── dns.ts │ │ ├── index.ts │ │ ├── log.ts │ │ └── socket │ │ │ ├── channel.ts │ │ │ └── index.ts │ └── utf8.ts ├── std │ ├── _util │ │ ├── assert.ts │ │ ├── assert_test.ts │ │ ├── deep_assign.ts │ │ ├── deep_assign_test.ts │ │ ├── has_own_property.ts │ │ └── os.ts │ ├── archive │ │ ├── README.md │ │ ├── tar.ts │ │ ├── tar_test.ts │ │ └── testdata │ │ │ ├── deno.tar │ │ │ └── example.txt │ ├── async │ │ ├── README.md │ │ ├── deferred.ts │ │ ├── deferred_test.ts │ │ ├── delay.ts │ │ ├── delay_test.ts │ │ ├── mod.ts │ │ ├── mux_async_iterator.ts │ │ ├── mux_async_iterator_test.ts │ │ ├── pool.ts │ │ ├── pool_test.ts │ │ └── test.ts │ ├── bytes │ │ ├── README.md │ │ ├── bytes_list.ts │ │ ├── bytes_list_test.ts │ │ ├── mod.ts │ │ └── test.ts │ ├── datetime │ │ ├── README.md │ │ ├── formatter.ts │ │ ├── mod.ts │ │ ├── test.ts │ │ └── tokenizer.ts │ ├── encoding │ │ ├── README.md │ │ ├── _yaml │ │ │ ├── dumper │ │ │ │ ├── dumper.ts │ │ │ │ └── dumper_state.ts │ │ │ ├── error.ts │ │ │ ├── example │ │ │ │ ├── dump.ts │ │ │ │ ├── inout.ts │ │ │ │ ├── parse.ts │ │ │ │ ├── sample_document.ts │ │ │ │ └── sample_document.yml │ │ │ ├── loader │ │ │ │ ├── loader.ts │ │ │ │ └── loader_state.ts │ │ │ ├── mark.ts │ │ │ ├── parse.ts │ │ │ ├── parse_test.ts │ │ │ ├── schema.ts │ │ │ ├── schema │ │ │ │ ├── core.ts │ │ │ │ ├── default.ts │ │ │ │ ├── extended.ts │ │ │ │ ├── failsafe.ts │ │ │ │ ├── json.ts │ │ │ │ └── mod.ts │ │ │ ├── state.ts │ │ │ ├── stringify.ts │ │ │ ├── stringify_test.ts │ │ │ ├── type.ts │ │ │ ├── type │ │ │ │ ├── binary.ts │ │ │ │ ├── bool.ts │ │ │ │ ├── float.ts │ │ │ │ ├── function.ts │ │ │ │ ├── int.ts │ │ │ │ ├── map.ts │ │ │ │ ├── merge.ts │ │ │ │ ├── mod.ts │ │ │ │ ├── nil.ts │ │ │ │ ├── omap.ts │ │ │ │ ├── pairs.ts │ │ │ │ ├── regexp.ts │ │ │ │ ├── seq.ts │ │ │ │ ├── set.ts │ │ │ │ ├── str.ts │ │ │ │ ├── timestamp.ts │ │ │ │ └── undefined.ts │ │ │ └── utils.ts │ │ ├── ascii85.ts │ │ ├── ascii85_test.ts │ │ ├── base32.ts │ │ ├── base32_test.ts │ │ ├── base64.ts │ │ ├── base64_test.ts │ │ ├── base64url.ts │ │ ├── base64url_test.ts │ │ ├── binary.ts │ │ ├── binary_test.ts │ │ ├── csv.ts │ │ ├── csv_stringify.ts │ │ ├── csv_stringify_test.ts │ │ ├── csv_test.ts │ │ ├── hex.ts │ │ ├── hex_test.ts │ │ ├── testdata │ │ │ ├── CRLF.toml │ │ │ ├── arrayTable.toml │ │ │ ├── arrays.toml │ │ │ ├── boolean.toml │ │ │ ├── cargo.toml │ │ │ ├── cargoTest.toml │ │ │ ├── comment.toml │ │ │ ├── datetime.toml │ │ │ ├── float.toml │ │ │ ├── inlineArrayOfInlineTable.toml │ │ │ ├── inlineTable.toml │ │ │ ├── integer.toml │ │ │ ├── simple.toml │ │ │ ├── string.toml │ │ │ └── table.toml │ │ ├── toml.ts │ │ ├── toml_test.ts │ │ ├── yaml.ts │ │ └── yaml_test.ts │ ├── flags │ │ ├── README.md │ │ ├── mod.ts │ │ └── test.ts │ ├── fmt │ │ ├── README.md │ │ ├── TODO │ │ ├── colors.ts │ │ ├── colors_test.ts │ │ ├── printf.ts │ │ └── printf_test.ts │ ├── fs │ │ ├── README.md │ │ ├── _util.ts │ │ ├── _util_test.ts │ │ ├── copy.ts │ │ ├── copy_test.ts │ │ ├── empty_dir.ts │ │ ├── empty_dir_test.ts │ │ ├── ensure_dir.ts │ │ ├── ensure_dir_test.ts │ │ ├── ensure_file.ts │ │ ├── ensure_file_test.ts │ │ ├── ensure_link.ts │ │ ├── ensure_link_test.ts │ │ ├── ensure_symlink.ts │ │ ├── ensure_symlink_test.ts │ │ ├── eol.ts │ │ ├── eol_test.ts │ │ ├── exists.ts │ │ ├── exists_test.ts │ │ ├── expand_glob.ts │ │ ├── expand_glob_test.ts │ │ ├── mod.ts │ │ ├── move.ts │ │ ├── move_test.ts │ │ ├── test.ts │ │ ├── testdata │ │ │ ├── 0-link │ │ │ ├── 0.ts │ │ │ ├── copy_dir │ │ │ │ ├── 0.txt │ │ │ │ └── nest │ │ │ │ │ └── 0.txt │ │ │ ├── copy_dir_link_file │ │ │ │ └── 0.txt │ │ │ ├── copy_file.txt │ │ │ ├── empty_dir.ts │ │ │ ├── empty_dir_sync.ts │ │ │ ├── exists.ts │ │ │ ├── exists_sync.ts │ │ │ ├── expand_wildcard.js │ │ │ └── glob │ │ │ │ ├── abc │ │ │ │ ├── abcdef │ │ │ │ ├── abcdefghi │ │ │ │ └── subdir │ │ │ │ └── abc │ │ ├── walk.ts │ │ └── walk_test.ts │ ├── hash │ │ ├── README.md │ │ ├── _fnv │ │ │ ├── fnv32.ts │ │ │ ├── fnv64.ts │ │ │ ├── util.ts │ │ │ └── util_test.ts │ │ ├── _sha3 │ │ │ ├── keccak.ts │ │ │ ├── keccakf.ts │ │ │ ├── sha3.ts │ │ │ ├── shake.ts │ │ │ └── sponge.ts │ │ ├── _wasm │ │ │ ├── Cargo.lock │ │ │ ├── Cargo.toml │ │ │ ├── README.md │ │ │ ├── build.ts │ │ │ ├── hash.ts │ │ │ ├── src │ │ │ │ └── lib.rs │ │ │ └── wasm.js │ │ ├── fnv.ts │ │ ├── fnv_test.ts │ │ ├── hasher.ts │ │ ├── md5.ts │ │ ├── md5_test.ts │ │ ├── mod.ts │ │ ├── sha1.ts │ │ ├── sha1_test.ts │ │ ├── sha256.ts │ │ ├── sha256_test.ts │ │ ├── sha3.ts │ │ ├── sha3_test.ts │ │ ├── sha512.ts │ │ ├── sha512_test.ts │ │ ├── test.ts │ │ └── testdata │ │ │ └── hashtest │ ├── http │ │ ├── README.md │ │ ├── _io.ts │ │ ├── _io_test.ts │ │ ├── _mock_conn.ts │ │ ├── cookie.ts │ │ ├── cookie_test.ts │ │ ├── file_server.ts │ │ ├── file_server_test.ts │ │ ├── http_status.ts │ │ ├── mod.ts │ │ ├── racing_server_test.ts │ │ ├── server.ts │ │ ├── server_test.ts │ │ └── test.ts │ ├── io │ │ ├── README.md │ │ ├── _iotest.ts │ │ ├── buffer.ts │ │ ├── buffer_test.ts │ │ ├── bufio.ts │ │ ├── bufio_test.ts │ │ ├── ioutil.ts │ │ ├── ioutil_test.ts │ │ ├── mod.ts │ │ ├── readers.ts │ │ ├── readers_test.ts │ │ ├── streams.ts │ │ ├── test.ts │ │ ├── testdata │ │ │ └── iso-8859-15.txt │ │ ├── types.d.ts │ │ ├── util.ts │ │ ├── util_test.ts │ │ ├── writers.ts │ │ └── writers_test.ts │ ├── log │ │ ├── README.md │ │ ├── handlers.ts │ │ ├── handlers_test.ts │ │ ├── levels.ts │ │ ├── logger.ts │ │ ├── logger_test.ts │ │ ├── mod.ts │ │ ├── mod_test.ts │ │ └── test.ts │ ├── mime │ │ ├── mod.ts │ │ ├── multipart.ts │ │ ├── multipart_test.ts │ │ ├── test.ts │ │ └── testdata │ │ │ └── sample.txt │ ├── node │ │ ├── README.md │ │ ├── _crypto │ │ │ ├── constants.ts │ │ │ ├── pbkdf2.ts │ │ │ ├── pbkdf2_test.ts │ │ │ ├── randomBytes.ts │ │ │ ├── randomBytes_test.ts │ │ │ └── types.ts │ │ ├── _errors.ts │ │ ├── _fs │ │ │ ├── _fs_access.ts │ │ │ ├── _fs_appendFile.ts │ │ │ ├── _fs_appendFile_test.ts │ │ │ ├── _fs_chmod.ts │ │ │ ├── _fs_chmod_test.ts │ │ │ ├── _fs_chown.ts │ │ │ ├── _fs_chown_test.ts │ │ │ ├── _fs_close.ts │ │ │ ├── _fs_close_test.ts │ │ │ ├── _fs_common.ts │ │ │ ├── _fs_constants.ts │ │ │ ├── _fs_copy.ts │ │ │ ├── _fs_copy_test.ts │ │ │ ├── _fs_dir.ts │ │ │ ├── _fs_dir_test.ts │ │ │ ├── _fs_dirent.ts │ │ │ ├── _fs_dirent_test.ts │ │ │ ├── _fs_exists.ts │ │ │ ├── _fs_exists_test.ts │ │ │ ├── _fs_fdatasync.ts │ │ │ ├── _fs_fdatasync_test.ts │ │ │ ├── _fs_fstat.ts │ │ │ ├── _fs_fstat_test.ts │ │ │ ├── _fs_fsync.ts │ │ │ ├── _fs_fsync_test.ts │ │ │ ├── _fs_ftruncate.ts │ │ │ ├── _fs_ftruncate_test.ts │ │ │ ├── _fs_futimes.ts │ │ │ ├── _fs_futimes_test.ts │ │ │ ├── _fs_link.ts │ │ │ ├── _fs_link_test.ts │ │ │ ├── _fs_lstat.ts │ │ │ ├── _fs_lstat_test.ts │ │ │ ├── _fs_mkdir.ts │ │ │ ├── _fs_mkdir_test.ts │ │ │ ├── _fs_mkdtemp.ts │ │ │ ├── _fs_mkdtemp_test.ts │ │ │ ├── _fs_open.ts │ │ │ ├── _fs_open_test.ts │ │ │ ├── _fs_readFile.ts │ │ │ ├── _fs_readFile_test.ts │ │ │ ├── _fs_readdir.ts │ │ │ ├── _fs_readdir_test.ts │ │ │ ├── _fs_readlink.ts │ │ │ ├── _fs_readlink_test.ts │ │ │ ├── _fs_realpath.ts │ │ │ ├── _fs_realpath_test.ts │ │ │ ├── _fs_rename.ts │ │ │ ├── _fs_rename_test.ts │ │ │ ├── _fs_rmdir.ts │ │ │ ├── _fs_rmdir_test.ts │ │ │ ├── _fs_stat.ts │ │ │ ├── _fs_stat_test.ts │ │ │ ├── _fs_symlink.ts │ │ │ ├── _fs_symlink_test.ts │ │ │ ├── _fs_truncate.ts │ │ │ ├── _fs_truncate_test.ts │ │ │ ├── _fs_unlink.ts │ │ │ ├── _fs_unlink_test.ts │ │ │ ├── _fs_utimes.ts │ │ │ ├── _fs_utimes_test.ts │ │ │ ├── _fs_watch.ts │ │ │ ├── _fs_watch_test.ts │ │ │ ├── _fs_writeFile.ts │ │ │ ├── _fs_writeFile_test.ts │ │ │ ├── promises │ │ │ │ ├── _fs_readFile.ts │ │ │ │ ├── _fs_readFile_test.ts │ │ │ │ ├── _fs_writeFile.ts │ │ │ │ ├── _fs_writeFile_test.ts │ │ │ │ └── mod.ts │ │ │ └── testdata │ │ │ │ └── hello.txt │ │ ├── _module │ │ │ ├── cjs │ │ │ │ ├── cjs_a.js │ │ │ │ ├── cjs_b.js │ │ │ │ ├── cjs_builtin.js │ │ │ │ ├── cjs_conditional_exports.js │ │ │ │ ├── cjs_cycle_a.js │ │ │ │ ├── cjs_cycle_b.js │ │ │ │ ├── cjs_throw.js │ │ │ │ ├── dir │ │ │ │ ├── index.js │ │ │ │ └── subdir │ │ │ │ │ ├── cjs_c.js │ │ │ │ │ └── dir │ │ │ │ │ └── index.js │ │ │ ├── example.js │ │ │ ├── node_modules │ │ │ │ ├── colorette │ │ │ │ │ ├── index.cjs │ │ │ │ │ ├── index.js │ │ │ │ │ └── package.json │ │ │ │ └── left-pad │ │ │ │ │ ├── README.md │ │ │ │ │ ├── index.js │ │ │ │ │ └── package.json │ │ │ └── package.json │ │ ├── _stream │ │ │ ├── async_iterator.ts │ │ │ ├── async_iterator_test.ts │ │ │ ├── buffer_list.ts │ │ │ ├── destroy.ts │ │ │ ├── duplex.ts │ │ │ ├── duplex_internal.ts │ │ │ ├── duplex_test.ts │ │ │ ├── end_of_stream.ts │ │ │ ├── end_of_stream_test.ts │ │ │ ├── from.ts │ │ │ ├── passthrough.ts │ │ │ ├── pipeline.ts │ │ │ ├── pipeline_test.ts │ │ │ ├── promises.ts │ │ │ ├── promises_test.ts │ │ │ ├── readable.ts │ │ │ ├── readable_internal.ts │ │ │ ├── readable_test.ts │ │ │ ├── stream.ts │ │ │ ├── symbols.ts │ │ │ ├── transform.ts │ │ │ ├── transform_test.ts │ │ │ ├── writable.ts │ │ │ ├── writable_internal.ts │ │ │ └── writable_test.ts │ │ ├── _tools │ │ │ ├── .gitignore │ │ │ ├── common.ts │ │ │ ├── config.json │ │ │ ├── require.ts │ │ │ └── suites │ │ │ │ ├── common │ │ │ │ └── index.js │ │ │ │ └── parallel │ │ │ │ ├── test-assert-async.js │ │ │ │ ├── test-assert-fail.js │ │ │ │ ├── test-assert.js │ │ │ │ ├── test-event-emitter-invalid-listener.js │ │ │ │ └── test-event-emitter-listener-count.js │ │ ├── _util │ │ │ ├── _util_callbackify.ts │ │ │ ├── _util_promisify.ts │ │ │ ├── _util_promisify_test.ts │ │ │ ├── _util_types.ts │ │ │ └── _util_types_test.ts │ │ ├── _utils.ts │ │ ├── assert.ts │ │ ├── assertion_error.ts │ │ ├── assertion_error_test.ts │ │ ├── buffer.ts │ │ ├── buffer_test.ts │ │ ├── child_process.ts │ │ ├── child_process_test.ts │ │ ├── cli.ts │ │ ├── cli_test.ts │ │ ├── console.ts │ │ ├── constants.ts │ │ ├── crypto.ts │ │ ├── crypto_test.ts │ │ ├── events.ts │ │ ├── events_test.ts │ │ ├── fs.ts │ │ ├── global.d.ts │ │ ├── global.ts │ │ ├── global_test.ts │ │ ├── module.ts │ │ ├── module_test.ts │ │ ├── os.ts │ │ ├── os_test.ts │ │ ├── path.ts │ │ ├── process.ts │ │ ├── process_test.ts │ │ ├── querystring.ts │ │ ├── querystring_test.ts │ │ ├── stream.ts │ │ ├── stream_test.ts │ │ ├── string_decoder.ts │ │ ├── string_decoder_test.ts │ │ ├── testdata │ │ │ ├── process_exit.ts │ │ │ └── shebang.js │ │ ├── timers.ts │ │ ├── tty.ts │ │ ├── tty_test.ts │ │ ├── url.ts │ │ ├── url_test.ts │ │ ├── util.ts │ │ └── util_test.ts │ ├── path │ │ ├── README.md │ │ ├── _constants.ts │ │ ├── _interface.ts │ │ ├── _util.ts │ │ ├── basename_test.ts │ │ ├── common.ts │ │ ├── common_test.ts │ │ ├── dirname_test.ts │ │ ├── extname_test.ts │ │ ├── from_file_url_test.ts │ │ ├── glob.ts │ │ ├── glob_test.ts │ │ ├── isabsolute_test.ts │ │ ├── join_test.ts │ │ ├── mod.ts │ │ ├── parse_format_test.ts │ │ ├── posix.ts │ │ ├── relative_test.ts │ │ ├── resolve_test.ts │ │ ├── separator.ts │ │ ├── test.ts │ │ ├── to_file_url_test.ts │ │ ├── win32.ts │ │ └── zero_length_strings_test.ts │ ├── permissions │ │ ├── mod.ts │ │ └── test.ts │ ├── signal │ │ ├── README.md │ │ ├── mod.ts │ │ └── test.ts │ ├── testing │ │ ├── README.md │ │ ├── _diff.ts │ │ ├── _diff_test.ts │ │ ├── asserts.ts │ │ ├── asserts_test.ts │ │ ├── bench.ts │ │ ├── bench_example.ts │ │ └── bench_test.ts │ ├── textproto │ │ ├── mod.ts │ │ └── test.ts │ ├── uuid │ │ ├── README.md │ │ ├── _common.ts │ │ ├── mod.ts │ │ ├── test.ts │ │ ├── v1.ts │ │ ├── v1_test.ts │ │ ├── v4.ts │ │ ├── v4_test.ts │ │ ├── v5.ts │ │ └── v5_test.ts │ ├── version.ts │ ├── wasi │ │ ├── README.md │ │ ├── snapshot_preview1.ts │ │ ├── snapshot_preview1_test.ts │ │ └── snapshot_preview1_test_runner.ts │ └── ws │ │ ├── README.md │ │ ├── example_test.ts │ │ ├── mod.ts │ │ └── test.ts └── x │ ├── grpc_basic │ ├── client.ts │ ├── error.ts │ ├── http2 │ │ ├── conn.ts │ │ ├── flow.ts │ │ ├── frames.ts │ │ ├── hpack.ts │ │ ├── stream.ts │ │ └── util.ts │ ├── proto.ts │ └── server.ts │ └── router │ └── mod.ts ├── service ├── log_service.ts └── v8_inspector.ts └── tsconfig.json /.cargo/config: -------------------------------------------------------------------------------- 1 | [target.x86_64-pc-windows-msvc] 2 | rustflags = ["-C", "target-feature=+crt-static"] 3 | 4 | [target.x86_64-apple-darwin] 5 | rustflags = ["-Clink-args=-undefined dynamic_lookup"] 6 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.rs text eol=crlf 3 | *.ts text eol=crlf 4 | *.js text eol=crlf 5 | 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | js 3 | skynet.lib 4 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "rusty_v8"] 2 | path = rusty_v8 3 | url = https://github.com/lsg2020/rusty_v8 4 | [submodule "deno"] 5 | path = deno 6 | url = https://github.com/lsg2020/deno 7 | [submodule "serde_v8"] 8 | path = serde_v8 9 | url = https://github.com/lsg2020/serde_v8 10 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "skynet_deno" 3 | version = "0.1.0" 4 | authors = ["lsg2020 <2468180623@qq.com>"] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [lib] 10 | name = "sndeno" 11 | crate-type = ["cdylib"] 12 | path = "./src/lib.rs" 13 | 14 | [dependencies] 15 | futures = "0.3.5" 16 | lazy_static = "1.4.0" 17 | libc = "0.2.93" 18 | log = "0.4.14" 19 | tokio = { version = "1.6.1", features = ["full"] } 20 | tokio-util = { version = "0.6", features = ["io"] } 21 | tokio-rustls = "0.22.0" 22 | async-task = "1.3.0" 23 | async-std = "0.99.5" 24 | backtrace = "0.3" 25 | url = { version = "2.2.1", features = ["serde"] } 26 | serde = { version = "1.0.125", features = ["derive"] } 27 | serde_json = { version = "1.0.64", features = ["preserve_order"] } 28 | byteorder = "1.4.2" 29 | smallvec = "1.4.0" 30 | openssl-sys = "0.9.59" 31 | ureq = "2.0.0" 32 | tungstenite = "0.11.1" 33 | 34 | rusty_v8 = {version = "0.26.0", path = "./rusty_v8"} 35 | deno_core = {path = "./deno/core", version = "0.97.0"} 36 | deno_runtime = {path = "./deno/runtime", version = "0.23.0"} 37 | -------------------------------------------------------------------------------- /doc/devtools.md: -------------------------------------------------------------------------------- 1 | ## 使用 `chrome devtools` 调试 skynet.snjs 服务 2 | * `config`配置增加 `js_inspector = true` 3 | * 启动入口页服务: `skynet.call(".launcher", "lua" , "LAUNCH", "snjs", "v8_inspector", "0.0.0.0", 9527)` 通过页面`http://127.0.0.1:9527`查看已开启调试的服务信息. 4 | * 服务开启调试支持:`snjs`服务执行 5 | ``` 6 | import * as debug from "skynet/debug"; 7 | debug.v8inspector.enable(service_name); 8 | ``` 9 | * service_name: 展示服务名 10 | * 进入入口页`http://127.0.0.1:9527`获取服务连接信息 11 | ![image1](https://github.com/lsg2020/skynet_ts/blob/master/doc/images/image1.jpg) 12 | * 在chrome 浏览器进入调试地址 例如: `devtools://devtools/bundled/inspector.html?v8only=true&ws=192.168.163.128:9527/ws/12` 13 | * 配置chrome, `Customize and control DevTools` -> `More Tools` -> `JavaScript Profiler` 14 | 15 | ## 展示 16 | ![breakpoint](https://github.com/lsg2020/skynet_ts/blob/master/doc/images/breakpoint1.jpg) 17 | ![memory](https://github.com/lsg2020/skynet_ts/blob/master/doc/images/memory.jpg) 18 | ![cpuprofile](https://github.com/lsg2020/skynet_ts/blob/master/doc/images/cpuprofile1.jpg) 19 | 20 | -------------------------------------------------------------------------------- /doc/images/breakpoint1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsg2020/skynet_ts/66c9e09805138ab2801faa2c808ace13473a9c2e/doc/images/breakpoint1.jpg -------------------------------------------------------------------------------- /doc/images/cpuprofile1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsg2020/skynet_ts/66c9e09805138ab2801faa2c808ace13473a9c2e/doc/images/cpuprofile1.jpg -------------------------------------------------------------------------------- /doc/images/image1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsg2020/skynet_ts/66c9e09805138ab2801faa2c808ace13473a9c2e/doc/images/image1.jpg -------------------------------------------------------------------------------- /doc/images/memory.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsg2020/skynet_ts/66c9e09805138ab2801faa2c808ace13473a9c2e/doc/images/memory.jpg -------------------------------------------------------------------------------- /src/01_inspector.js: -------------------------------------------------------------------------------- 1 | ((window) => { 2 | const core = window.Deno.core; 3 | 4 | function v8inspector_connect(proxy_addr, proto_ptype, pause_addr, resume_addr) { 5 | return core.opRawSync("op_v8inspector_connect", proxy_addr, proto_ptype, pause_addr, resume_addr); 6 | } 7 | 8 | function v8inspector_disconnect(session_id) { 9 | core.opRawSync("op_v8inspector_disconnect", session_id); 10 | } 11 | 12 | function v8inspector_message(session_id, msg) { 13 | core.opRawSync("op_v8inspector_message", session_id, msg) 14 | } 15 | 16 | let V8Inspector = { 17 | v8inspector_connect, 18 | v8inspector_disconnect, 19 | v8inspector_message, 20 | } 21 | window.V8Inspector = V8Inspector; 22 | window.__bootstrap.V8Inspector = V8Inspector; 23 | })(this); 24 | -------------------------------------------------------------------------------- /src/01_tls.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | ((window) => { 4 | const core = window.Deno.core; 5 | 6 | function new_ctx() { 7 | return core.opRawSync("op_tls_new_ctx"); 8 | } 9 | 10 | function free_ctx(ctx) { 11 | core.opRawSync("op_tls_free_ctx", ctx); 12 | } 13 | 14 | function set_cert(ctx, certfile, keyfile) { 15 | core.opRawSync("op_tls_set_cert", ctx, certfile, keyfile); 16 | } 17 | 18 | function new_tls(ctx, method) { 19 | return core.opRawSync("op_tls_new_tls", ctx, method); 20 | } 21 | 22 | function free_tls(ctx) { 23 | core.opRawSync("op_tls_free_tls", ctx); 24 | } 25 | 26 | function finished(ctx) { 27 | return core.opRawSync("op_tls_finished", ctx); 28 | } 29 | 30 | function handshake(ctx) { 31 | return core.opRawSync("op_tls_handshake", ctx); 32 | } 33 | 34 | function bio_write(ctx, ...buffer) { 35 | return core.opRawSync("op_tls_bio_write", ctx, ...buffer); 36 | } 37 | 38 | function bio_read(ctx, buffer, offset) { 39 | return core.opRawSync("op_tls_bio_read", ctx, buffer, offset); 40 | } 41 | 42 | function ssl_write(ctx, ...buffer) { 43 | return core.opRawSync("op_tls_ssl_write", ctx, ...buffer); 44 | } 45 | 46 | function ssl_read(ctx, buffer, offset, sz) { 47 | return core.opRawSync("op_tls_ssl_read", ctx, buffer, offset, sz); 48 | } 49 | 50 | let tls = { 51 | new_ctx, 52 | free_ctx, 53 | set_cert, 54 | new_tls, 55 | free_tls, 56 | finished, 57 | handshake, 58 | bio_write, 59 | bio_read, 60 | ssl_write, 61 | ssl_read, 62 | }; 63 | window.SkynetTls = tls; 64 | window.__bootstrap.SkynetTls = tls; 65 | })(this); 66 | -------------------------------------------------------------------------------- /ts/dts/README.md: -------------------------------------------------------------------------------- 1 | # How to upgrade TypeScript. 2 | 3 | The files in this directory are mostly from the TypeScript repository. We 4 | currently (unfortunately) have a rather manual process for upgrading TypeScript. 5 | It works like this currently: 6 | 7 | 1. Checkout typescript repo in a separate directory. 8 | 2. Copy typescript.js into Deno repo. 9 | 3. Copy d.ts files into dts directory. 10 | 11 | So that might look something like this: 12 | 13 | ``` 14 | git clone https://github.com/microsoft/TypeScript.git 15 | cd typescript 16 | git checkout v3.9.7 17 | rsync lib/typescript.js ~/src/deno/cli/tsc/00_typescript.js 18 | rsync --exclude=protocol.d.ts --exclude=tsserverlibrary.d.ts --exclude=typescriptServices.d.ts lib/*.d.ts ~/src/deno/cli/dts/ 19 | ``` 20 | -------------------------------------------------------------------------------- /ts/dts/lib.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | 17 | 18 | /// 19 | 20 | 21 | /// 22 | /// 23 | /// 24 | /// 25 | -------------------------------------------------------------------------------- /ts/dts/lib.deno.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace Deno { 2 | function v8MemoryInfo(): any; 3 | } 4 | declare const JS_INIT_ARGS: string; 5 | declare const Skynet: any; 6 | declare const SkynetTls: any; 7 | declare const V8Inspector: any; 8 | -------------------------------------------------------------------------------- /ts/dts/lib.dom.asynciterable.d.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | 3 | /// 4 | 5 | interface ReadableStream { 6 | [Symbol.asyncIterator](options?: { 7 | preventCancel?: boolean; 8 | }): AsyncIterableIterator; 9 | } 10 | -------------------------------------------------------------------------------- /ts/dts/lib.es2015.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | 17 | 18 | /// 19 | 20 | 21 | /// 22 | /// 23 | /// 24 | /// 25 | /// 26 | /// 27 | /// 28 | /// 29 | /// 30 | /// 31 | -------------------------------------------------------------------------------- /ts/dts/lib.es2016.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | 17 | 18 | /// 19 | 20 | 21 | /// 22 | /// -------------------------------------------------------------------------------- /ts/dts/lib.es2016.full.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | 17 | 18 | /// 19 | 20 | 21 | /// 22 | /// 23 | /// 24 | /// 25 | /// -------------------------------------------------------------------------------- /ts/dts/lib.es2017.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | 17 | 18 | /// 19 | 20 | 21 | /// 22 | /// 23 | /// 24 | /// 25 | /// 26 | /// 27 | -------------------------------------------------------------------------------- /ts/dts/lib.es2017.full.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | 17 | 18 | /// 19 | 20 | 21 | /// 22 | /// 23 | /// 24 | /// 25 | /// -------------------------------------------------------------------------------- /ts/dts/lib.es2017.intl.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | 17 | 18 | /// 19 | 20 | 21 | declare namespace Intl { 22 | type DateTimeFormatPartTypes = "day" | "dayPeriod" | "era" | "hour" | "literal" | "minute" | "month" | "second" | "timeZoneName" | "weekday" | "year"; 23 | 24 | interface DateTimeFormatPart { 25 | type: DateTimeFormatPartTypes; 26 | value: string; 27 | } 28 | 29 | interface DateTimeFormat { 30 | formatToParts(date?: Date | number): DateTimeFormatPart[]; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /ts/dts/lib.es2017.typedarrays.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | 17 | 18 | /// 19 | 20 | 21 | interface Int8ArrayConstructor { 22 | new (): Int8Array; 23 | } 24 | 25 | interface Uint8ArrayConstructor { 26 | new (): Uint8Array; 27 | } 28 | 29 | interface Uint8ClampedArrayConstructor { 30 | new (): Uint8ClampedArray; 31 | } 32 | 33 | interface Int16ArrayConstructor { 34 | new (): Int16Array; 35 | } 36 | 37 | interface Uint16ArrayConstructor { 38 | new (): Uint16Array; 39 | } 40 | 41 | interface Int32ArrayConstructor { 42 | new (): Int32Array; 43 | } 44 | 45 | interface Uint32ArrayConstructor { 46 | new (): Uint32Array; 47 | } 48 | 49 | interface Float32ArrayConstructor { 50 | new (): Float32Array; 51 | } 52 | 53 | interface Float64ArrayConstructor { 54 | new (): Float64Array; 55 | } 56 | -------------------------------------------------------------------------------- /ts/dts/lib.es2018.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | 17 | 18 | /// 19 | 20 | 21 | /// 22 | /// 23 | /// 24 | /// 25 | /// 26 | /// 27 | -------------------------------------------------------------------------------- /ts/dts/lib.es2018.full.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | 17 | 18 | /// 19 | 20 | 21 | /// 22 | /// 23 | /// 24 | /// 25 | /// -------------------------------------------------------------------------------- /ts/dts/lib.es2018.promise.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | 17 | 18 | /// 19 | 20 | 21 | /** 22 | * Represents the completion of an asynchronous operation 23 | */ 24 | interface Promise { 25 | /** 26 | * Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The 27 | * resolved value cannot be modified from the callback. 28 | * @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected). 29 | * @returns A Promise for the completion of the callback. 30 | */ 31 | finally(onfinally?: (() => void) | undefined | null): Promise 32 | } 33 | -------------------------------------------------------------------------------- /ts/dts/lib.es2018.regexp.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | 17 | 18 | /// 19 | 20 | 21 | interface RegExpMatchArray { 22 | groups?: { 23 | [key: string]: string 24 | } 25 | } 26 | 27 | interface RegExpExecArray { 28 | groups?: { 29 | [key: string]: string 30 | } 31 | } 32 | 33 | interface RegExp { 34 | /** 35 | * Returns a Boolean value indicating the state of the dotAll flag (s) used with a regular expression. 36 | * Default is false. Read-only. 37 | */ 38 | readonly dotAll: boolean; 39 | } -------------------------------------------------------------------------------- /ts/dts/lib.es2019.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | 17 | 18 | /// 19 | 20 | 21 | /// 22 | /// 23 | /// 24 | /// 25 | /// 26 | -------------------------------------------------------------------------------- /ts/dts/lib.es2019.full.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | 17 | 18 | /// 19 | 20 | 21 | /// 22 | /// 23 | /// 24 | /// 25 | /// 26 | -------------------------------------------------------------------------------- /ts/dts/lib.es2019.object.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | 17 | 18 | /// 19 | 20 | 21 | /// 22 | 23 | interface ObjectConstructor { 24 | /** 25 | * Returns an object created by key-value entries for properties and methods 26 | * @param entries An iterable object that contains key-value entries for properties and methods. 27 | */ 28 | fromEntries(entries: Iterable): { [k: string]: T }; 29 | 30 | /** 31 | * Returns an object created by key-value entries for properties and methods 32 | * @param entries An iterable object that contains key-value entries for properties and methods. 33 | */ 34 | fromEntries(entries: Iterable): any; 35 | } 36 | -------------------------------------------------------------------------------- /ts/dts/lib.es2019.string.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | 17 | 18 | /// 19 | 20 | 21 | interface String { 22 | /** Removes the trailing white space and line terminator characters from a string. */ 23 | trimEnd(): string; 24 | 25 | /** Removes the leading white space and line terminator characters from a string. */ 26 | trimStart(): string; 27 | 28 | /** Removes the leading white space and line terminator characters from a string. */ 29 | trimLeft(): string; 30 | 31 | /** Removes the trailing white space and line terminator characters from a string. */ 32 | trimRight(): string; 33 | } 34 | -------------------------------------------------------------------------------- /ts/dts/lib.es2019.symbol.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | 17 | 18 | /// 19 | 20 | 21 | interface Symbol { 22 | /** 23 | * Expose the [[Description]] internal slot of a symbol directly. 24 | */ 25 | readonly description: string | undefined; 26 | } 27 | -------------------------------------------------------------------------------- /ts/dts/lib.es2020.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | 17 | 18 | /// 19 | 20 | 21 | /// 22 | /// 23 | /// 24 | /// 25 | /// 26 | /// 27 | /// 28 | -------------------------------------------------------------------------------- /ts/dts/lib.es2020.full.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | 17 | 18 | /// 19 | 20 | 21 | /// 22 | /// 23 | /// 24 | /// 25 | /// 26 | -------------------------------------------------------------------------------- /ts/dts/lib.es2020.string.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | 17 | 18 | /// 19 | 20 | 21 | /// 22 | 23 | interface String { 24 | /** 25 | * Matches a string with a regular expression, and returns an iterable of matches 26 | * containing the results of that search. 27 | * @param regexp A variable name or string literal containing the regular expression pattern and flags. 28 | */ 29 | matchAll(regexp: RegExp): IterableIterator; 30 | } 31 | -------------------------------------------------------------------------------- /ts/dts/lib.es2020.symbol.wellknown.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | 17 | 18 | /// 19 | 20 | 21 | /// 22 | /// 23 | 24 | interface SymbolConstructor { 25 | /** 26 | * A regular expression method that matches the regular expression against a string. Called 27 | * by the String.prototype.matchAll method. 28 | */ 29 | readonly matchAll: symbol; 30 | } 31 | 32 | interface RegExp { 33 | /** 34 | * Matches a string with this regular expression, and returns an iterable of matches 35 | * containing the results of that search. 36 | * @param string A string to search within. 37 | */ 38 | [Symbol.matchAll](str: string): IterableIterator; 39 | } 40 | -------------------------------------------------------------------------------- /ts/dts/lib.es6.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | 17 | 18 | /// 19 | 20 | 21 | /// 22 | /// 23 | /// 24 | /// 25 | /// 26 | -------------------------------------------------------------------------------- /ts/dts/lib.esnext.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | 17 | 18 | /// 19 | 20 | 21 | /// 22 | /// 23 | /// 24 | /// 25 | /// 26 | -------------------------------------------------------------------------------- /ts/dts/lib.esnext.full.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | 17 | 18 | /// 19 | 20 | 21 | /// 22 | /// 23 | /// 24 | /// 25 | /// -------------------------------------------------------------------------------- /ts/dts/lib.esnext.intl.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | 17 | 18 | /// 19 | 20 | 21 | declare namespace Intl { 22 | type NumberFormatPartTypes = "compact" | "currency" | "decimal" | "exponentInteger" | "exponentMinusSign" | "exponentSeparator" | "fraction" | "group" | "infinity" | "integer" | "literal" | "minusSign" | "nan" | "plusSign" | "percentSign" | "unit" | "unknown"; 23 | 24 | interface NumberFormatPart { 25 | type: NumberFormatPartTypes; 26 | value: string; 27 | } 28 | 29 | interface NumberFormat { 30 | formatToParts(number?: number): NumberFormatPart[]; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /ts/dts/lib.esnext.string.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | 17 | 18 | /// 19 | 20 | 21 | interface String { 22 | /** 23 | * Replace all instances of a substring in a string, using a regular expression or search string. 24 | * @param searchValue A string to search for. 25 | * @param replaceValue A string containing the text to replace for every successful match of searchValue in this string. 26 | */ 27 | replaceAll(searchValue: string | RegExp, replaceValue: string): string; 28 | 29 | /** 30 | * Replace all instances of a substring in a string, using a regular expression or search string. 31 | * @param searchValue A string to search for. 32 | * @param replacer A function that returns the replacement text. 33 | */ 34 | replaceAll(searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; 35 | } 36 | -------------------------------------------------------------------------------- /ts/dts/lib.webworker.importscripts.d.ts: -------------------------------------------------------------------------------- 1 | /*! ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | 17 | 18 | /// 19 | 20 | 21 | 22 | ///////////////////////////// 23 | /// WorkerGlobalScope APIs 24 | ///////////////////////////// 25 | // These are only available in a Web Worker 26 | declare function importScripts(...urls: string[]): void; 27 | -------------------------------------------------------------------------------- /ts/lib/jsSHA/license_header.es3.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * A JavaScript implementation of the SHA family of hashes - defined in FIPS PUB 180-4, FIPS PUB 202, 3 | * and SP 800-185 - as well as the corresponding HMAC implementation as defined in FIPS PUB 198-1. 4 | * 5 | * Copyright 2008-2020 Brian Turek, 1998-2009 Paul Johnston & Contributors 6 | * Distributed under the BSD License 7 | * See http://caligatio.github.com/jsSHA/ for more information 8 | * 9 | * Two ECMAScript polyfill functions carry the following license: 10 | * 11 | * Copyright (c) Microsoft Corporation. All rights reserved. 12 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 13 | * the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, 16 | * INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 17 | * MERCHANTABLITY OR NON-INFRINGEMENT. 18 | * 19 | * See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. 20 | */ 21 | -------------------------------------------------------------------------------- /ts/lib/jsSHA/license_header.es6.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * A JavaScript implementation of the SHA family of hashes - defined in FIPS PUB 180-4, FIPS PUB 202, 3 | * and SP 800-185 - as well as the corresponding HMAC implementation as defined in FIPS PUB 198-1. 4 | * 5 | * Copyright 2008-2020 Brian Turek, 1998-2009 Paul Johnston & Contributors 6 | * Distributed under the BSD License 7 | * See http://caligatio.github.com/jsSHA/ for more information 8 | */ 9 | -------------------------------------------------------------------------------- /ts/lib/loader.ts: -------------------------------------------------------------------------------- 1 | let args = JS_INIT_ARGS.split(" "); 2 | var SERVICE_NAME = args[0]; 3 | let skynet = Skynet; 4 | 5 | function exists_file(path: string): boolean { 6 | try { 7 | Deno.lstatSync(path); 8 | return true; 9 | } catch (err) { 10 | return false; 11 | } 12 | } 13 | 14 | let js_lib_paths = skynet.get_env("jslib", "js/lib/?.js;js/lib/?/index.js;js/lib/skynet/?.js;js/lib/skynet/?/index.js"); 15 | let js_service_paths = skynet.get_env("jsservice", "js/service/?.js;js/service/?/main.js"); 16 | js_service_paths = js_service_paths.split(";"); 17 | let search_paths = []; 18 | let main_service_path; 19 | let main_pattern; 20 | for (let service_path of js_service_paths) { 21 | let target_path = `${Deno.cwd()}/${service_path.replace("?", SERVICE_NAME)}`; 22 | if (exists_file(target_path)) { 23 | main_service_path = target_path; 24 | main_pattern = service_path; 25 | break; 26 | } 27 | search_paths.push(target_path); 28 | } 29 | 30 | if (!main_service_path) { 31 | throw new Error(`not found: ${search_paths.join("\n")}`); 32 | } 33 | 34 | let base_service_path = main_pattern.match(/(.*\/)/)[0]; 35 | var SERVICE_PATH = base_service_path.replace("?", SERVICE_NAME); 36 | skynet.set_jslib_paths(`${SERVICE_PATH}/?.js;${SERVICE_PATH}/?/index.js;` + js_lib_paths); 37 | 38 | if (main_service_path[0] != "/") { 39 | main_service_path = "file:///" + main_service_path; 40 | } 41 | await import(main_service_path); 42 | export {}; -------------------------------------------------------------------------------- /ts/lib/skynet/http/types.ts: -------------------------------------------------------------------------------- 1 | 2 | export type HEADER_VALUE = number | string | string[]; 3 | export type HEADER_MAP = Map; 4 | 5 | export type READ_FUNC = (sz?: number, buffer?: Uint8Array, offset?: number) => Promise<[Uint8Array, number]>; 6 | export type SOCKET_INTERFACE = { 7 | init?: () => void, 8 | close?: () => void, 9 | read: READ_FUNC, 10 | readall: (buffer?: Uint8Array, offset?: number) => Promise<[Uint8Array, number]>, 11 | write: (content: string|Uint8Array|Uint8Array[]) => void, 12 | websocket?: boolean, 13 | } 14 | 15 | export type REQUEST_OPTIONS = { 16 | method: string, 17 | host: string, 18 | url: string, 19 | header?: HEADER_MAP, 20 | content?: string, 21 | timeout?: number, 22 | } 23 | 24 | export enum INTERFACE_TYPE { 25 | CLIENT = "client", 26 | SERVER = "server", 27 | } -------------------------------------------------------------------------------- /ts/lib/std/_util/assert.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | 3 | export class DenoStdInternalError extends Error { 4 | constructor(message: string) { 5 | super(message); 6 | this.name = "DenoStdInternalError"; 7 | } 8 | } 9 | 10 | /** Make an assertion, if not `true`, then throw. */ 11 | export function assert(expr: unknown, msg = ""): asserts expr { 12 | if (!expr) { 13 | throw new DenoStdInternalError(msg); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ts/lib/std/_util/assert_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import { assert, DenoStdInternalError } from "./assert"; 3 | import { assertThrows } from "../testing/asserts"; 4 | 5 | Deno.test({ 6 | name: "assert valid scenario", 7 | fn(): void { 8 | assert(true); 9 | }, 10 | }); 11 | 12 | Deno.test({ 13 | name: "assert invalid scenario, no message", 14 | fn(): void { 15 | assertThrows(() => { 16 | assert(false); 17 | }, DenoStdInternalError); 18 | }, 19 | }); 20 | Deno.test({ 21 | name: "assert invalid scenario, with message", 22 | fn(): void { 23 | assertThrows( 24 | () => { 25 | assert(false, "Oops! Should be true"); 26 | }, 27 | DenoStdInternalError, 28 | "Oops! Should be true", 29 | ); 30 | }, 31 | }); 32 | -------------------------------------------------------------------------------- /ts/lib/std/_util/deep_assign.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import { assert } from "./assert"; 3 | 4 | export function deepAssign(target: T, source: U): T & U; 5 | export function deepAssign( 6 | target: T, 7 | source1: U, 8 | source2: V, 9 | ): T & U & V; 10 | export function deepAssign( 11 | target: T, 12 | source1: U, 13 | source2: V, 14 | source3: W, 15 | ): T & U & V & W; 16 | export function deepAssign( 17 | // deno-lint-ignore no-explicit-any 18 | target: Record, 19 | // deno-lint-ignore no-explicit-any 20 | ...sources: any[] 21 | ): // deno-lint-ignore ban-types 22 | object | undefined { 23 | for (let i = 0; i < sources.length; i++) { 24 | const source = sources[i]; 25 | if (!source || typeof source !== `object`) { 26 | return; 27 | } 28 | Object.entries(source).forEach(([key, value]): void => { 29 | if (value instanceof Date) { 30 | target[key] = new Date(value); 31 | return; 32 | } 33 | if (!value || typeof value !== `object`) { 34 | target[key] = value; 35 | return; 36 | } 37 | if (Array.isArray(value)) { 38 | target[key] = []; 39 | } 40 | // value is an Object 41 | if (typeof target[key] !== `object` || !target[key]) { 42 | target[key] = {}; 43 | } 44 | assert(value); 45 | deepAssign(target[key] as Record, value); 46 | }); 47 | } 48 | return target; 49 | } 50 | -------------------------------------------------------------------------------- /ts/lib/std/_util/deep_assign_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import { assert, assertEquals } from "../testing/asserts"; 3 | import { deepAssign } from "./deep_assign"; 4 | 5 | Deno.test("deepAssignTest", function (): void { 6 | const date = new Date("1979-05-27T07:32:00Z"); 7 | const reg = RegExp(/DENOWOWO/); 8 | const obj1 = { deno: { bar: { deno: ["is", "not", "node"] } } }; 9 | const obj2 = { foo: { deno: date } }; 10 | const obj3 = { foo: { bar: "deno" }, reg: reg }; 11 | const actual = deepAssign(obj1, obj2, obj3); 12 | const expected = { 13 | foo: { 14 | deno: new Date("1979-05-27T07:32:00Z"), 15 | bar: "deno", 16 | }, 17 | deno: { bar: { deno: ["is", "not", "node"] } }, 18 | reg: RegExp(/DENOWOWO/), 19 | }; 20 | assert(date !== expected.foo.deno); 21 | assert(reg !== expected.reg); 22 | assertEquals(actual, expected); 23 | }); 24 | -------------------------------------------------------------------------------- /ts/lib/std/_util/has_own_property.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | 3 | /** 4 | * Determines whether an object has a property with the specified name. 5 | * Avoid calling prototype builtin `hasOwnProperty` for two reasons: 6 | * 7 | * 1. `hasOwnProperty` is defined on the object as something else: 8 | * 9 | * const options = { 10 | * ending: 'utf8', 11 | * hasOwnProperty: 'foo' 12 | * }; 13 | * options.hasOwnProperty('ending') // throws a TypeError 14 | * 15 | * 2. The object doesn't inherit from `Object.prototype`: 16 | * 17 | * const options = Object.create(null); 18 | * options.ending = 'utf8'; 19 | * options.hasOwnProperty('ending'); // throws a TypeError 20 | * 21 | * @param obj A Object. 22 | * @param v A property name. 23 | * @see https://eslint.org/docs/rules/no-prototype-builtins 24 | */ 25 | export function hasOwnProperty(obj: T, v: PropertyKey): boolean { 26 | if (obj == null) { 27 | return false; 28 | } 29 | return Object.prototype.hasOwnProperty.call(obj, v); 30 | } 31 | -------------------------------------------------------------------------------- /ts/lib/std/_util/os.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | // This module is browser compatible. 3 | 4 | export const osType = (() => { 5 | if (globalThis.Deno != null) { 6 | return Deno.build.os; 7 | } 8 | 9 | // deno-lint-ignore no-explicit-any 10 | const navigator = (globalThis as any).navigator; 11 | if (navigator?.appVersion?.includes?.("Win") ?? false) { 12 | return "windows"; 13 | } 14 | 15 | return "linux"; 16 | })(); 17 | 18 | export const isWindows = osType === "windows"; 19 | -------------------------------------------------------------------------------- /ts/lib/std/archive/README.md: -------------------------------------------------------------------------------- 1 | # Usage 2 | 3 | ## Tar 4 | 5 | ```ts 6 | import { Tar } from "https://deno.land/std@$STD_VERSION/archive/tar"; 7 | import { Buffer } from "https://deno.land/std@$STD_VERSION/io/buffer"; 8 | 9 | const tar = new Tar(); 10 | const content = new TextEncoder().encode("Deno.land"); 11 | await tar.append("deno.txt", { 12 | reader: new Buffer(content), 13 | contentSize: content.byteLength, 14 | }); 15 | 16 | // Or specifying a filePath. 17 | await tar.append("land.txt", { 18 | filePath: "./land.txt", 19 | }); 20 | 21 | // use tar.getReader() to read the contents. 22 | 23 | const writer = await Deno.open("./out.tar", { write: true, create: true }); 24 | await Deno.copy(tar.getReader(), writer); 25 | writer.close(); 26 | ``` 27 | 28 | ## Untar 29 | 30 | ```ts 31 | import { Untar } from "https://deno.land/std@$STD_VERSION/archive/tar"; 32 | import { ensureFile } from "https://deno.land/std@$STD_VERSION/fs/ensure_file"; 33 | import { ensureDir } from "https://deno.land/std@$STD_VERSION/fs/ensure_dir"; 34 | 35 | const reader = await Deno.open("./out.tar", { read: true }); 36 | const untar = new Untar(reader); 37 | 38 | for await (const entry of untar) { 39 | console.log(entry); // metadata 40 | /* 41 | fileName: "archive/deno.txt", 42 | fileMode: 33204, 43 | mtime: 1591657305, 44 | uid: 0, 45 | gid: 0, 46 | size: 24400, 47 | type: 'file' 48 | */ 49 | 50 | if (entry.type === "directory") { 51 | await ensureDir(entry.fileName); 52 | continue; 53 | } 54 | 55 | await ensureFile(entry.fileName); 56 | const file = await Deno.open(entry.fileName, { write: true }); 57 | // is a reader. 58 | await Deno.copy(entry, file); 59 | } 60 | reader.close(); 61 | ``` 62 | -------------------------------------------------------------------------------- /ts/lib/std/archive/testdata/example.txt: -------------------------------------------------------------------------------- 1 | hello world! 2 | -------------------------------------------------------------------------------- /ts/lib/std/async/deferred.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | // TODO(ry) It'd be better to make Deferred a class that inherits from 3 | // Promise, rather than an interface. This is possible in ES2016, however 4 | // typescript produces broken code when targeting ES5 code. 5 | // See https://github.com/Microsoft/TypeScript/issues/15202 6 | // At the time of writing, the github issue is closed but the problem remains. 7 | export interface Deferred extends Promise { 8 | resolve(value?: T | PromiseLike): void; 9 | // deno-lint-ignore no-explicit-any 10 | reject(reason?: any): void; 11 | } 12 | 13 | /** Creates a Promise with the `reject` and `resolve` functions 14 | * placed as methods on the promise object itself. It allows you to do: 15 | * 16 | * const p = deferred(); 17 | * // ... 18 | * p.resolve(42); 19 | */ 20 | export function deferred(): Deferred { 21 | let methods; 22 | const promise = new Promise((resolve, reject): void => { 23 | methods = { resolve, reject }; 24 | }); 25 | return Object.assign(promise, methods) as Deferred; 26 | } 27 | -------------------------------------------------------------------------------- /ts/lib/std/async/deferred_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import { assertEquals, assertThrowsAsync } from "../testing/asserts"; 3 | import { deferred } from "./deferred"; 4 | 5 | Deno.test("[async] deferred: resolve", async function () { 6 | const d = deferred(); 7 | d.resolve("🦕"); 8 | assertEquals(await d, "🦕"); 9 | }); 10 | 11 | Deno.test("[async] deferred: reject", async function () { 12 | const d = deferred(); 13 | d.reject(new Error("A deno error 🦕")); 14 | await assertThrowsAsync(async () => { 15 | await d; 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /ts/lib/std/async/delay.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | /* Resolves after the given number of milliseconds. */ 3 | export function delay(ms: number): Promise { 4 | return new Promise((res): number => 5 | setTimeout((): void => { 6 | res(); 7 | }, ms) 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /ts/lib/std/async/delay_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import { delay } from "./delay"; 3 | import { assert } from "../testing/asserts"; 4 | 5 | Deno.test("[async] delay", async function () { 6 | const start = new Date(); 7 | const delayedPromise = delay(100); 8 | const result = await delayedPromise; 9 | const diff = new Date().getTime() - start.getTime(); 10 | assert(result === undefined); 11 | assert(diff >= 100); 12 | }); 13 | -------------------------------------------------------------------------------- /ts/lib/std/async/mod.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | export * from "./deferred"; 3 | export * from "./delay"; 4 | export * from "./mux_async_iterator"; 5 | export * from "./pool"; 6 | -------------------------------------------------------------------------------- /ts/lib/std/async/mux_async_iterator_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import { assertEquals, assertThrowsAsync } from "../testing/asserts"; 3 | import { MuxAsyncIterator } from "./mux_async_iterator"; 4 | 5 | async function* gen123(): AsyncIterableIterator { 6 | yield 1; 7 | yield 2; 8 | yield 3; 9 | } 10 | 11 | async function* gen456(): AsyncIterableIterator { 12 | yield 4; 13 | yield 5; 14 | yield 6; 15 | } 16 | 17 | async function* genThrows(): AsyncIterableIterator { 18 | yield 7; 19 | throw new Error("something went wrong"); 20 | } 21 | 22 | Deno.test("[async] MuxAsyncIterator", async function () { 23 | const mux = new MuxAsyncIterator(); 24 | mux.add(gen123()); 25 | mux.add(gen456()); 26 | const results = new Set(); 27 | for await (const value of mux) { 28 | results.add(value); 29 | } 30 | assertEquals(results.size, 6); 31 | }); 32 | 33 | Deno.test({ 34 | name: "[async] MuxAsyncIterator throws", 35 | async fn() { 36 | const mux = new MuxAsyncIterator(); 37 | mux.add(gen123()); 38 | mux.add(genThrows()); 39 | const results = new Set(); 40 | await assertThrowsAsync( 41 | async () => { 42 | for await (const value of mux) { 43 | results.add(value); 44 | } 45 | }, 46 | Error, 47 | "something went wrong", 48 | ); 49 | }, 50 | }); 51 | -------------------------------------------------------------------------------- /ts/lib/std/async/pool_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import { delay } from "./delay"; 3 | import { pooledMap } from "./pool"; 4 | import { 5 | assert, 6 | assertEquals, 7 | assertStringIncludes, 8 | assertThrowsAsync, 9 | } from "../testing/asserts"; 10 | 11 | Deno.test("[async] pooledMap", async function () { 12 | const start = new Date(); 13 | const results = pooledMap( 14 | 2, 15 | [1, 2, 3], 16 | (i) => new Promise((r) => setTimeout(() => r(i), 1000)), 17 | ); 18 | for await (const value of results) { 19 | console.log(value); 20 | } 21 | const diff = new Date().getTime() - start.getTime(); 22 | assert(diff >= 2000); 23 | assert(diff < 3000); 24 | }); 25 | 26 | Deno.test("[async] pooledMap errors", async function () { 27 | async function mapNumber(n: number): Promise { 28 | if (n <= 2) { 29 | throw new Error(`Bad number: ${n}`); 30 | } 31 | await delay(100); 32 | return n; 33 | } 34 | const mappedNumbers: number[] = []; 35 | const error = await assertThrowsAsync(async () => { 36 | for await (const m of pooledMap(3, [1, 2, 3, 4], mapNumber)) { 37 | mappedNumbers.push(m); 38 | } 39 | }, AggregateError) as AggregateError; 40 | assertEquals(mappedNumbers, [3]); 41 | assertEquals(error.errors.length, 2); 42 | assertStringIncludes(error.errors[0].stack, "Error: Bad number: 1"); 43 | assertStringIncludes(error.errors[1].stack, "Error: Bad number: 2"); 44 | }); 45 | -------------------------------------------------------------------------------- /ts/lib/std/async/test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import "./mod"; 3 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/_yaml/error.ts: -------------------------------------------------------------------------------- 1 | // Ported from js-yaml v3.13.1: 2 | // https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da 3 | // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license. 4 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 5 | 6 | import type { Mark } from "./mark"; 7 | 8 | export class YAMLError extends Error { 9 | constructor( 10 | message = "(unknown reason)", 11 | protected mark: Mark | string = "", 12 | ) { 13 | super(`${message} ${mark}`); 14 | this.name = this.constructor.name; 15 | } 16 | 17 | public toString(_compact: boolean): string { 18 | return `${this.name}: ${this.message} ${this.mark}`; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/_yaml/example/dump.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | 3 | import { stringify } from "../../yaml"; 4 | 5 | console.log( 6 | stringify({ 7 | foo: { 8 | bar: true, 9 | test: [ 10 | "a", 11 | "b", 12 | { 13 | a: false, 14 | }, 15 | { 16 | a: false, 17 | }, 18 | ], 19 | }, 20 | test: "foobar", 21 | }), 22 | ); 23 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/_yaml/example/inout.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | 3 | import { parse, stringify } from "../../yaml"; 4 | 5 | const test = { 6 | foo: { 7 | bar: true, 8 | test: [ 9 | "a", 10 | "b", 11 | { 12 | a: false, 13 | }, 14 | { 15 | a: false, 16 | }, 17 | ], 18 | }, 19 | test: "foobar", 20 | }; 21 | 22 | const string = stringify(test); 23 | if (Deno.inspect(test) === Deno.inspect(parse(string))) { 24 | console.log("In-Out as expected."); 25 | } else { 26 | console.log("Something went wrong."); 27 | } 28 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/_yaml/example/parse.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | 3 | import { parse } from "../../yaml"; 4 | 5 | const result = parse(` 6 | test: toto 7 | foo: 8 | bar: True 9 | baz: 1 10 | qux: ~ 11 | `); 12 | console.log(result); 13 | 14 | const expected = '{ test: "toto", foo: { bar: true, baz: 1, qux: null } }'; 15 | if (Deno.inspect(result) === expected) { 16 | console.log("Output is as expected."); 17 | } else { 18 | console.error("Error during parse. Output is not as expect.", expected); 19 | } 20 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/_yaml/example/sample_document.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | 3 | import { parse } from "../../yaml"; 4 | 5 | (() => { 6 | const yml = Deno.readFileSync(`${Deno.cwd()}/example/sample_document.yml`); 7 | 8 | const document = new TextDecoder().decode(yml); 9 | // deno-lint-ignore no-explicit-any 10 | const obj = parse(document) as Record; 11 | console.log(obj); 12 | 13 | let i = 0; 14 | for (const o of Object.values(obj)) { 15 | console.log(`======${i}`); 16 | for (const [key, value] of Object.entries(o)) { 17 | console.log(key, value); 18 | } 19 | i++; 20 | } 21 | })(); 22 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/_yaml/parse.ts: -------------------------------------------------------------------------------- 1 | // Ported from js-yaml v3.13.1: 2 | // https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da 3 | // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license. 4 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 5 | 6 | import { CbFunction, load, loadAll } from "./loader/loader"; 7 | import type { LoaderStateOptions } from "./loader/loader_state"; 8 | 9 | export type ParseOptions = LoaderStateOptions; 10 | 11 | /** 12 | * Parses `content` as single YAML document. 13 | * 14 | * Returns a JavaScript object or throws `YAMLException` on error. 15 | * By default, does not support regexps, functions and undefined. This method is safe for untrusted data. 16 | * 17 | */ 18 | export function parse(content: string, options?: ParseOptions): unknown { 19 | return load(content, options); 20 | } 21 | 22 | /** 23 | * Same as `parse()`, but understands multi-document sources. 24 | * Applies iterator to each document if specified, or returns array of documents. 25 | */ 26 | export function parseAll( 27 | content: string, 28 | iterator?: CbFunction, 29 | options?: ParseOptions, 30 | ): unknown { 31 | return loadAll(content, iterator, options); 32 | } 33 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/_yaml/schema/core.ts: -------------------------------------------------------------------------------- 1 | // Ported from js-yaml v3.13.1: 2 | // https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da 3 | // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license. 4 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 5 | 6 | import { Schema } from "../schema"; 7 | import { json } from "./json"; 8 | 9 | // Standard YAML's Core schema. 10 | // http://www.yaml.org/spec/1.2/spec.html#id2804923 11 | export const core = new Schema({ 12 | include: [json], 13 | }); 14 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/_yaml/schema/default.ts: -------------------------------------------------------------------------------- 1 | // Ported from js-yaml v3.13.1: 2 | // https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da 3 | // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license. 4 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 5 | 6 | import { Schema } from "../schema"; 7 | import { binary, merge, omap, pairs, set, timestamp } from "../type/mod"; 8 | import { core } from "./core"; 9 | 10 | // JS-YAML's default schema for `safeLoad` function. 11 | // It is not described in the YAML specification. 12 | export const def = new Schema({ 13 | explicit: [binary, omap, pairs, set], 14 | implicit: [timestamp, merge], 15 | include: [core], 16 | }); 17 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/_yaml/schema/extended.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | 3 | import { Schema } from "../schema"; 4 | import { func, regexp, undefinedType } from "../type/mod"; 5 | import { def } from "./default"; 6 | 7 | // Extends JS-YAML default schema with additional JavaScript types 8 | // It is not described in the YAML specification. 9 | export const extended = new Schema({ 10 | explicit: [func, regexp, undefinedType], 11 | include: [def], 12 | }); 13 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/_yaml/schema/failsafe.ts: -------------------------------------------------------------------------------- 1 | // Ported from js-yaml v3.13.1: 2 | // https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da 3 | // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license. 4 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 5 | 6 | import { Schema } from "../schema"; 7 | import { map, seq, str } from "../type/mod"; 8 | 9 | // Standard YAML's Failsafe schema. 10 | // http://www.yaml.org/spec/1.2/spec.html#id2802346 11 | export const failsafe = new Schema({ 12 | explicit: [str, seq, map], 13 | }); 14 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/_yaml/schema/json.ts: -------------------------------------------------------------------------------- 1 | // Ported from js-yaml v3.13.1: 2 | // https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da 3 | // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license. 4 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 5 | 6 | import { Schema } from "../schema"; 7 | import { bool, float, int, nil } from "../type/mod"; 8 | import { failsafe } from "./failsafe"; 9 | 10 | // Standard YAML's JSON schema. 11 | // http://www.yaml.org/spec/1.2/spec.html#id2803231 12 | export const json = new Schema({ 13 | implicit: [nil, bool, int, float], 14 | include: [failsafe], 15 | }); 16 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/_yaml/schema/mod.ts: -------------------------------------------------------------------------------- 1 | // Ported from js-yaml v3.13.1: 2 | // https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da 3 | // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license. 4 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 5 | 6 | export { core as CORE_SCHEMA } from "./core"; 7 | export { def as DEFAULT_SCHEMA } from "./default"; 8 | export { extended as EXTENDED_SCHEMA } from "./extended"; 9 | export { failsafe as FAILSAFE_SCHEMA } from "./failsafe"; 10 | export { json as JSON_SCHEMA } from "./json"; 11 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/_yaml/state.ts: -------------------------------------------------------------------------------- 1 | // Ported from js-yaml v3.13.1: 2 | // https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da 3 | // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license. 4 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 5 | 6 | import type { SchemaDefinition } from "./schema"; 7 | import { DEFAULT_SCHEMA } from "./schema/mod"; 8 | 9 | export abstract class State { 10 | constructor(public schema: SchemaDefinition = DEFAULT_SCHEMA) {} 11 | } 12 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/_yaml/stringify.ts: -------------------------------------------------------------------------------- 1 | // Ported from js-yaml v3.13.1: 2 | // https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da 3 | // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license. 4 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 5 | 6 | import { dump } from "./dumper/dumper"; 7 | import type { DumperStateOptions } from "./dumper/dumper_state"; 8 | 9 | export type DumpOptions = DumperStateOptions; 10 | 11 | /** 12 | * Serializes `object` as a YAML document. 13 | * 14 | * You can disable exceptions by setting the skipInvalid option to true. 15 | */ 16 | export function stringify( 17 | obj: Record, 18 | options?: DumpOptions, 19 | ): string { 20 | return dump(obj, options); 21 | } 22 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/_yaml/type/bool.ts: -------------------------------------------------------------------------------- 1 | // Ported from js-yaml v3.13.1: 2 | // https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da 3 | // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license. 4 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 5 | 6 | import { Type } from "../type"; 7 | import { isBoolean } from "../utils"; 8 | 9 | function resolveYamlBoolean(data: string): boolean { 10 | const max = data.length; 11 | 12 | return ( 13 | (max === 4 && (data === "true" || data === "True" || data === "TRUE")) || 14 | (max === 5 && (data === "false" || data === "False" || data === "FALSE")) 15 | ); 16 | } 17 | 18 | function constructYamlBoolean(data: string): boolean { 19 | return data === "true" || data === "True" || data === "TRUE"; 20 | } 21 | 22 | export const bool = new Type("tag:yaml.org,2002:bool", { 23 | construct: constructYamlBoolean, 24 | defaultStyle: "lowercase", 25 | kind: "scalar", 26 | predicate: isBoolean, 27 | represent: { 28 | lowercase(object: boolean): string { 29 | return object ? "true" : "false"; 30 | }, 31 | uppercase(object: boolean): string { 32 | return object ? "TRUE" : "FALSE"; 33 | }, 34 | camelcase(object: boolean): string { 35 | return object ? "True" : "False"; 36 | }, 37 | }, 38 | resolve: resolveYamlBoolean, 39 | }); 40 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/_yaml/type/function.ts: -------------------------------------------------------------------------------- 1 | // Ported and adapted from js-yaml-js-types v1.0.0: 2 | // https://github.com/nodeca/js-yaml-js-types/tree/ac537e7bbdd3c2cbbd9882ca3919c520c2dc022b 3 | // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license. 4 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 5 | 6 | import { Type } from "../type"; 7 | import type { Any } from "../utils"; 8 | 9 | // Note: original implementation used Esprima to handle functions 10 | // To avoid dependencies, we'll just try to check if we can construct a function from given string 11 | function reconstructFunction(code: string) { 12 | const func = new Function(`return ${code}`)(); 13 | if (!(func instanceof Function)) { 14 | throw new TypeError(`Expected function but got ${typeof func}: ${code}`); 15 | } 16 | return func; 17 | } 18 | 19 | export const func = new Type("tag:yaml.org,2002:js/function", { 20 | kind: "scalar", 21 | resolve(data: Any) { 22 | if (data === null) { 23 | return false; 24 | } 25 | try { 26 | reconstructFunction(`${data}`); 27 | return true; 28 | } catch (_err) { 29 | return false; 30 | } 31 | }, 32 | construct(data: string) { 33 | return reconstructFunction(data); 34 | }, 35 | predicate(object: unknown) { 36 | return object instanceof Function; 37 | }, 38 | represent(object: (...args: Any[]) => Any) { 39 | return object.toString(); 40 | }, 41 | }); 42 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/_yaml/type/map.ts: -------------------------------------------------------------------------------- 1 | // Ported from js-yaml v3.13.1: 2 | // https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da 3 | // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license. 4 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 5 | 6 | import { Type } from "../type"; 7 | import type { Any } from "../utils"; 8 | 9 | export const map = new Type("tag:yaml.org,2002:map", { 10 | construct(data): Any { 11 | return data !== null ? data : {}; 12 | }, 13 | kind: "mapping", 14 | }); 15 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/_yaml/type/merge.ts: -------------------------------------------------------------------------------- 1 | // Ported from js-yaml v3.13.1: 2 | // https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da 3 | // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license. 4 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 5 | 6 | import { Type } from "../type"; 7 | 8 | function resolveYamlMerge(data: string): boolean { 9 | return data === "<<" || data === null; 10 | } 11 | 12 | export const merge = new Type("tag:yaml.org,2002:merge", { 13 | kind: "scalar", 14 | resolve: resolveYamlMerge, 15 | }); 16 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/_yaml/type/mod.ts: -------------------------------------------------------------------------------- 1 | // Ported from js-yaml v3.13.1: 2 | // https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da 3 | // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license. 4 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 5 | 6 | export { binary } from "./binary"; 7 | export { bool } from "./bool"; 8 | export { float } from "./float"; 9 | export { func } from "./function"; 10 | export { int } from "./int"; 11 | export { map } from "./map"; 12 | export { merge } from "./merge"; 13 | export { nil } from "./nil"; 14 | export { omap } from "./omap"; 15 | export { pairs } from "./pairs"; 16 | export { regexp } from "./regexp"; 17 | export { seq } from "./seq"; 18 | export { set } from "./set"; 19 | export { str } from "./str"; 20 | export { timestamp } from "./timestamp"; 21 | export { undefinedType } from "./undefined"; 22 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/_yaml/type/nil.ts: -------------------------------------------------------------------------------- 1 | // Ported from js-yaml v3.13.1: 2 | // https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da 3 | // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license. 4 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 5 | 6 | import { Type } from "../type"; 7 | 8 | function resolveYamlNull(data: string): boolean { 9 | const max = data.length; 10 | 11 | return ( 12 | (max === 1 && data === "~") || 13 | (max === 4 && (data === "null" || data === "Null" || data === "NULL")) 14 | ); 15 | } 16 | 17 | function constructYamlNull(): null { 18 | return null; 19 | } 20 | 21 | function isNull(object: unknown): object is null { 22 | return object === null; 23 | } 24 | 25 | export const nil = new Type("tag:yaml.org,2002:null", { 26 | construct: constructYamlNull, 27 | defaultStyle: "lowercase", 28 | kind: "scalar", 29 | predicate: isNull, 30 | represent: { 31 | canonical(): string { 32 | return "~"; 33 | }, 34 | lowercase(): string { 35 | return "null"; 36 | }, 37 | uppercase(): string { 38 | return "NULL"; 39 | }, 40 | camelcase(): string { 41 | return "Null"; 42 | }, 43 | }, 44 | resolve: resolveYamlNull, 45 | }); 46 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/_yaml/type/omap.ts: -------------------------------------------------------------------------------- 1 | // Ported from js-yaml v3.13.1: 2 | // https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da 3 | // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license. 4 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 5 | 6 | import { Type } from "../type"; 7 | import type { Any } from "../utils"; 8 | 9 | const _hasOwnProperty = Object.prototype.hasOwnProperty; 10 | const _toString = Object.prototype.toString; 11 | 12 | function resolveYamlOmap(data: Any): boolean { 13 | const objectKeys: string[] = []; 14 | let pairKey = ""; 15 | let pairHasKey = false; 16 | 17 | for (const pair of data) { 18 | pairHasKey = false; 19 | 20 | if (_toString.call(pair) !== "[object Object]") return false; 21 | 22 | for (pairKey in pair) { 23 | if (_hasOwnProperty.call(pair, pairKey)) { 24 | if (!pairHasKey) pairHasKey = true; 25 | else return false; 26 | } 27 | } 28 | 29 | if (!pairHasKey) return false; 30 | 31 | if (objectKeys.indexOf(pairKey) === -1) objectKeys.push(pairKey); 32 | else return false; 33 | } 34 | 35 | return true; 36 | } 37 | 38 | function constructYamlOmap(data: Any): Any { 39 | return data !== null ? data : []; 40 | } 41 | 42 | export const omap = new Type("tag:yaml.org,2002:omap", { 43 | construct: constructYamlOmap, 44 | kind: "sequence", 45 | resolve: resolveYamlOmap, 46 | }); 47 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/_yaml/type/pairs.ts: -------------------------------------------------------------------------------- 1 | // Ported from js-yaml v3.13.1: 2 | // https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da 3 | // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license. 4 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 5 | 6 | import { Type } from "../type"; 7 | import type { Any } from "../utils"; 8 | 9 | const _toString = Object.prototype.toString; 10 | 11 | function resolveYamlPairs(data: Any[][]): boolean { 12 | const result = new Array(data.length); 13 | 14 | for (let index = 0; index < data.length; index++) { 15 | const pair = data[index]; 16 | 17 | if (_toString.call(pair) !== "[object Object]") return false; 18 | 19 | const keys = Object.keys(pair); 20 | 21 | if (keys.length !== 1) return false; 22 | 23 | result[index] = [keys[0], pair[keys[0] as Any]]; 24 | } 25 | 26 | return true; 27 | } 28 | 29 | function constructYamlPairs(data: string): Any[] { 30 | if (data === null) return []; 31 | 32 | const result = new Array(data.length); 33 | 34 | for (let index = 0; index < data.length; index += 1) { 35 | const pair = data[index]; 36 | 37 | const keys = Object.keys(pair); 38 | 39 | result[index] = [keys[0], pair[keys[0] as Any]]; 40 | } 41 | 42 | return result; 43 | } 44 | 45 | export const pairs = new Type("tag:yaml.org,2002:pairs", { 46 | construct: constructYamlPairs, 47 | kind: "sequence", 48 | resolve: resolveYamlPairs, 49 | }); 50 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/_yaml/type/regexp.ts: -------------------------------------------------------------------------------- 1 | // Ported and adapted from js-yaml-js-types v1.0.0: 2 | // https://github.com/nodeca/js-yaml-js-types/tree/ac537e7bbdd3c2cbbd9882ca3919c520c2dc022b 3 | // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license. 4 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 5 | 6 | import { Type } from "../type"; 7 | import type { Any } from "../utils"; 8 | 9 | const REGEXP = /^\/(?[\s\S]+)\/(?[gismuy]*)$/; 10 | 11 | export const regexp = new Type("tag:yaml.org,2002:js/regexp", { 12 | kind: "scalar", 13 | resolve(data: Any) { 14 | if ((data === null) || (!data.length)) { 15 | return false; 16 | } 17 | 18 | const regexp = `${data}`; 19 | if (regexp.charAt(0) === "/") { 20 | // Ensure regex is properly terminated 21 | if (!REGEXP.test(data)) { 22 | return false; 23 | } 24 | // Check no duplicate modifiers 25 | const modifiers = [...(regexp.match(REGEXP)?.groups?.modifiers ?? "")]; 26 | if (new Set(modifiers).size < modifiers.length) { 27 | return false; 28 | } 29 | } 30 | 31 | return true; 32 | }, 33 | construct(data: string) { 34 | const { regexp = `${data}`, modifiers = "" } = 35 | `${data}`.match(REGEXP)?.groups ?? {}; 36 | return new RegExp(regexp, modifiers); 37 | }, 38 | predicate(object: unknown) { 39 | return object instanceof RegExp; 40 | }, 41 | represent(object: RegExp) { 42 | return object.toString(); 43 | }, 44 | }); 45 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/_yaml/type/seq.ts: -------------------------------------------------------------------------------- 1 | // Ported from js-yaml v3.13.1: 2 | // https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da 3 | // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license. 4 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 5 | 6 | import { Type } from "../type"; 7 | import type { Any } from "../utils"; 8 | 9 | export const seq = new Type("tag:yaml.org,2002:seq", { 10 | construct(data): Any { 11 | return data !== null ? data : []; 12 | }, 13 | kind: "sequence", 14 | }); 15 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/_yaml/type/set.ts: -------------------------------------------------------------------------------- 1 | // Ported from js-yaml v3.13.1: 2 | // https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da 3 | // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license. 4 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 5 | 6 | import { Type } from "../type"; 7 | import type { Any } from "../utils"; 8 | 9 | const _hasOwnProperty = Object.prototype.hasOwnProperty; 10 | 11 | function resolveYamlSet(data: Any): boolean { 12 | if (data === null) return true; 13 | 14 | for (const key in data) { 15 | if (_hasOwnProperty.call(data, key)) { 16 | if (data[key] !== null) return false; 17 | } 18 | } 19 | 20 | return true; 21 | } 22 | 23 | function constructYamlSet(data: string): Any { 24 | return data !== null ? data : {}; 25 | } 26 | 27 | export const set = new Type("tag:yaml.org,2002:set", { 28 | construct: constructYamlSet, 29 | kind: "mapping", 30 | resolve: resolveYamlSet, 31 | }); 32 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/_yaml/type/str.ts: -------------------------------------------------------------------------------- 1 | // Ported from js-yaml v3.13.1: 2 | // https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da 3 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 4 | 5 | import { Type } from "../type"; 6 | 7 | export const str = new Type("tag:yaml.org,2002:str", { 8 | construct(data): string { 9 | return data !== null ? data : ""; 10 | }, 11 | kind: "scalar", 12 | }); 13 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/_yaml/type/undefined.ts: -------------------------------------------------------------------------------- 1 | // Ported and adapted from js-yaml-js-types v1.0.0: 2 | // https://github.com/nodeca/js-yaml-js-types/tree/ac537e7bbdd3c2cbbd9882ca3919c520c2dc022b 3 | // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license. 4 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 5 | 6 | import { Type } from "../type"; 7 | 8 | export const undefinedType = new Type("tag:yaml.org,2002:js/undefined", { 9 | kind: "scalar", 10 | resolve() { 11 | return true; 12 | }, 13 | construct() { 14 | return undefined; 15 | }, 16 | predicate(object) { 17 | return typeof object === "undefined"; 18 | }, 19 | represent() { 20 | return ""; 21 | }, 22 | }); 23 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/base64_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | 3 | import { assertEquals } from "../testing/asserts"; 4 | import { decode, encode } from "./base64"; 5 | 6 | const testsetString = [ 7 | ["", ""], 8 | ["ß", "w58="], 9 | ["f", "Zg=="], 10 | ["fo", "Zm8="], 11 | ["foo", "Zm9v"], 12 | ["foob", "Zm9vYg=="], 13 | ["fooba", "Zm9vYmE="], 14 | ["foobar", "Zm9vYmFy"], 15 | ]; 16 | 17 | const testsetBinary = testsetString.map(([str, b64]) => [ 18 | new TextEncoder().encode(str), 19 | b64, 20 | ]) as Array<[Uint8Array, string]>; 21 | 22 | Deno.test("[encoding/base64] testBase64EncodeString", () => { 23 | for (const [input, output] of testsetString) { 24 | assertEquals(encode(input), output); 25 | } 26 | }); 27 | 28 | Deno.test("[encoding/base64] testBase64EncodeBinary", () => { 29 | for (const [input, output] of testsetBinary) { 30 | assertEquals(encode(input), output); 31 | } 32 | }); 33 | 34 | Deno.test("[encoding/base64] testBase64EncodeBinaryBuffer", () => { 35 | for (const [input, output] of testsetBinary) { 36 | assertEquals(encode(input.buffer), output); 37 | } 38 | }); 39 | 40 | Deno.test("[encoding/base64] testBase64DecodeBinary", () => { 41 | for (const [input, output] of testsetBinary) { 42 | const outputBinary = decode(output); 43 | assertEquals(outputBinary, input); 44 | } 45 | }); 46 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/base64url.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | 3 | import * as base64 from "./base64"; 4 | 5 | /* 6 | * Some variants allow or require omitting the padding '=' signs: 7 | * https://en.wikipedia.org/wiki/Base64#URL_applications 8 | * @param base64url 9 | */ 10 | export function addPaddingToBase64url(base64url: string): string { 11 | if (base64url.length % 4 === 2) return base64url + "=="; 12 | if (base64url.length % 4 === 3) return base64url + "="; 13 | if (base64url.length % 4 === 1) { 14 | throw new TypeError("Illegal base64url string!"); 15 | } 16 | return base64url; 17 | } 18 | 19 | function convertBase64urlToBase64(b64url: string): string { 20 | return addPaddingToBase64url(b64url).replace(/\-/g, "+").replace(/_/g, "/"); 21 | } 22 | 23 | function convertBase64ToBase64url(b64: string): string { 24 | return b64.replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_"); 25 | } 26 | 27 | /** 28 | * Encodes a given Uint8Array into a base64url representation 29 | * @param uint8 30 | */ 31 | export function encode(uint8: Uint8Array): string { 32 | return convertBase64ToBase64url(base64.encode(uint8)); 33 | } 34 | 35 | /** 36 | * Converts given base64url encoded data back to original 37 | * @param b64url 38 | */ 39 | export function decode(b64url: string): Uint8Array { 40 | return base64.decode(convertBase64urlToBase64(b64url)); 41 | } 42 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/base64url_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | 3 | import { assertEquals } from "../testing/asserts"; 4 | import { decode, encode } from "./base64url"; 5 | 6 | const testsetString = [ 7 | ["", ""], 8 | ["ß", "w58"], 9 | ["f", "Zg"], 10 | ["fo", "Zm8"], 11 | ["foo", "Zm9v"], 12 | ["foob", "Zm9vYg"], 13 | ["fooba", "Zm9vYmE"], 14 | ["foobar", "Zm9vYmFy"], 15 | [">?>d?ß", "Pj8-ZD_Dnw"], 16 | ]; 17 | 18 | const testsetBinary = testsetString.map(([str, b64]) => [ 19 | new TextEncoder().encode(str), 20 | b64, 21 | ]) as Array<[Uint8Array, string]>; 22 | 23 | Deno.test("[encoding/base64url] testBase64urlEncodeBinary", () => { 24 | for (const [input, output] of testsetBinary) { 25 | assertEquals(encode(input), output); 26 | } 27 | }); 28 | 29 | Deno.test("[decoding/base64url] testBase64urlDecodeBinary", () => { 30 | for (const [input, output] of testsetBinary) { 31 | assertEquals(decode(output), input); 32 | } 33 | }); 34 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/testdata/CRLF.toml: -------------------------------------------------------------------------------- 1 | [boolean] 2 | bool1 = true 3 | bool2 = false -------------------------------------------------------------------------------- /ts/lib/std/encoding/testdata/arrayTable.toml: -------------------------------------------------------------------------------- 1 | 2 | [[bin]] 3 | name = "deno" 4 | path = "cli/main.rs" 5 | 6 | [[bin]] 7 | name = "deno_core" 8 | path = "src/foo.rs" 9 | 10 | [[nib]] 11 | name = "node" 12 | path = "not_found" -------------------------------------------------------------------------------- /ts/lib/std/encoding/testdata/arrays.toml: -------------------------------------------------------------------------------- 1 | [arrays] 2 | data = [ ["gamma", "delta"], [1, 2] ] # comment after an array caused issue #7072 3 | 4 | # Line breaks are OK when inside arrays 5 | hosts = [ 6 | "alpha", 7 | "omega" 8 | ] # comment -------------------------------------------------------------------------------- /ts/lib/std/encoding/testdata/boolean.toml: -------------------------------------------------------------------------------- 1 | [boolean] # i hate comments 2 | bool1 = true 3 | bool2 = false 4 | bool3 = true # I love comments -------------------------------------------------------------------------------- /ts/lib/std/encoding/testdata/cargo.toml: -------------------------------------------------------------------------------- 1 | # Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | # Dummy package info required by `cargo fetch`. 3 | 4 | [workspace] 5 | members = [ 6 | "./", 7 | "core", 8 | ] 9 | 10 | [[bin]] 11 | name = "deno" 12 | path = "cli/main.rs" 13 | 14 | [package] 15 | name = "deno" 16 | version = "0.3.4" 17 | edition = "2018" 18 | 19 | [dependencies] 20 | deno_core = { path = "./core" } 21 | 22 | atty = "0.2.11" 23 | dirs = "1.0.5" 24 | flatbuffers = "0.5.0" 25 | futures = "0.1.25" 26 | getopts = "0.2.18" 27 | http = "0.1.16" 28 | hyper = "0.12.24" 29 | hyper-rustls = "0.16.0" 30 | integer-atomics = "1.0.2" 31 | lazy_static = "1.3.0" 32 | libc = "0.2.49" 33 | log = "0.4.6" 34 | rand = "0.6.5" 35 | regex = "1.1.0" 36 | remove_dir_all = "0.5.2" 37 | ring = "0.14.6" 38 | rustyline = "3.0.0" 39 | serde_json = "1.0.38" 40 | source-map-mappings = "0.5.0" 41 | tempfile = "3.0.7" 42 | tokio = "0.1.15" 43 | tokio-executor = "0.1.6" 44 | tokio-fs = "0.1.5" 45 | tokio-io = "0.1.11" 46 | tokio-process = "0.2.3" 47 | tokio-threadpool = "0.1.11" 48 | url = "1.7.2" 49 | 50 | [target.'cfg(windows)'.dependencies] 51 | winapi = "0.3.6" 52 | 53 | [target."cfg(linux)".dependencies] 54 | winapi = "0.3.9" 55 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/testdata/comment.toml: -------------------------------------------------------------------------------- 1 | # This is a full-line comment 2 | str0 = 'value' # This is a comment at the end of a line 3 | str1 = "# This is not a comment" # but this is 4 | str2 = """ # this is not a comment! 5 | A multiline string with a # 6 | # this is also not a comment 7 | """ # this is definitely a comment 8 | 9 | str3 = ''' 10 | "# not a comment" 11 | # this is a real tab on purpose 12 | # not a comment 13 | ''' # comment 14 | 15 | point0 = { x = 1, y = 2, str0 = "#not a comment", z = 3 } # comment 16 | point1 = { x = 7, y = 8, z = 9, str0 = "#not a comment"} # comment 17 | 18 | [deno] # this comment is fine 19 | features = ["#secure by default", "supports typescript # not a comment"] # Comment caused Issue #7072 20 | url = "https://deno.land/" # comment 21 | is_not_node = true # comment 22 | 23 | [toml] # Comment caused Issue #7072 (case 2) 24 | name = "Tom's Obvious, Minimal Language" 25 | objectives = [ # Comment 26 | "easy to read", # Comment 27 | "minimal config file", 28 | "#not a comment" # comment 29 | ] # comment 30 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/testdata/datetime.toml: -------------------------------------------------------------------------------- 1 | [datetime] 2 | odt1 = 1979-05-27T07:32:00Z # Comment 3 | odt2 = 1979-05-27T00:32:00-07:00 # Comment 4 | odt3 = 1979-05-27T00:32:00.999999-07:00 # Comment 5 | odt4 = 1979-05-27 07:32:00Z # Comment 6 | ld1 = 1979-05-27 # Comment 7 | lt1 = 07:32:00 # Comment 8 | lt2 = 00:32:00.999999 # Comment 9 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/testdata/float.toml: -------------------------------------------------------------------------------- 1 | [float] 2 | # fractional 3 | flt1 = +1.0 # Comment 4 | flt2 = 3.1415 # Comment 5 | flt3 = -0.01 # Comment 6 | 7 | # exponent 8 | flt4 = 5e+22 # Comment 9 | flt5 = 1e6 # Comment 10 | flt6 = -2E-2 # Comment 11 | 12 | # both 13 | flt7 = 6.626e-34 # Comment 14 | flt8 = 224_617.445_991_228 # Comment 15 | # infinity 16 | sf1 = inf # positive infinity 17 | sf2 = +inf # positive infinity 18 | sf3 = -inf # negative infinity 19 | 20 | # not a number 21 | sf4 = nan # actual sNaN/qNaN encoding is implementation specific 22 | sf5 = +nan # same as `nan` 23 | sf6 = -nan # valid, actual encoding is implementation specific -------------------------------------------------------------------------------- /ts/lib/std/encoding/testdata/inlineArrayOfInlineTable.toml: -------------------------------------------------------------------------------- 1 | [inlineArray] 2 | string = [ {var = "a string"} ] 3 | 4 | my_points = [ { x = 1, y = 2, z = 3 }, { x = 7, y = 8, z = 9 }, { x = 2, y = 4, z = 8 } ] 5 | 6 | points = [ { x = 1, y = 2, z = 3 }, 7 | { x = 7, y = 8, z = 9 }, 8 | { x = 2, y = 4, z = 8 } ] -------------------------------------------------------------------------------- /ts/lib/std/encoding/testdata/inlineTable.toml: -------------------------------------------------------------------------------- 1 | [inlinetable] 2 | name = { first = "Tom", last = "Preston-Werner" } 3 | point = { x = 1, y = 2 } 4 | dog = { type = { name = "pug" } } 5 | animal.as.leaders = "tosin" 6 | "tosin.abasi" = "guitarist" 7 | nile = { derek.roddy = "drummer", also = { malevolant.creation = { drum.kit = "Tama" } } } -------------------------------------------------------------------------------- /ts/lib/std/encoding/testdata/integer.toml: -------------------------------------------------------------------------------- 1 | [integer] 2 | int1 = +99 3 | int2 = 42 4 | int3 = 0 5 | int4 = -17 6 | int5 = 1_000 7 | int6 = 5_349_221 8 | int7 = 1_2_3_4_5 # VALID but discouraged 9 | 10 | # hexadecimal with prefix `0x` 11 | hex1 = 0xDEADBEEF 12 | hex2 = 0xdeadbeef 13 | hex3 = 0xdead_beef 14 | 15 | # octal with prefix `0o` 16 | oct1 = 0o01234567 17 | oct2 = 0o755 # useful for Unix file permissions 18 | 19 | # binary with prefix `0b` 20 | bin1 = 0b11010110 -------------------------------------------------------------------------------- /ts/lib/std/encoding/testdata/simple.toml: -------------------------------------------------------------------------------- 1 | deno = "is" 2 | not = "[node]" 3 | regex = '<\i\c*\s*>' 4 | NANI = '何?!' 5 | comment = "Comment inside # the comment" # Comment 6 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/testdata/string.toml: -------------------------------------------------------------------------------- 1 | [strings] 2 | str0 = "deno" 3 | str1 = """ 4 | Roses are not Deno 5 | Violets are not Deno either""" 6 | # On a Unix system, the above multi-line string will most likely be the same as: 7 | str2 = "Roses are not Deno\nViolets are not Deno either" 8 | 9 | # On a Windows system, it will most likely be equivalent to: 10 | str3 = "Roses are not Deno\r\nViolets are not Deno either" 11 | str4 = "this is a \"quote\"" 12 | 13 | str5 = """ 14 | The quick brown \ 15 | 16 | 17 | fox jumps over \ 18 | the lazy dog.""" 19 | 20 | str6 = """\ 21 | The quick brown \ 22 | fox jumps over \ 23 | the lazy dog.\ 24 | """ 25 | lines = ''' 26 | The first newline is 27 | trimmed in raw strings. 28 | All other whitespace 29 | is preserved. 30 | ''' 31 | 32 | withApostrophe = "What if it's not?" 33 | withSemicolon = "const message = 'hello world';" 34 | withHexNumberLiteral = "Prevent bug from stripping string here ->0xabcdef" 35 | withUnicodeChar1 = "\u3042" 36 | withUnicodeChar2 = "Deno\U01F995" 37 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/testdata/table.toml: -------------------------------------------------------------------------------- 1 | [deeply.nested.object.in.the.toml] 2 | name = "Tom Preston-Werner" 3 | 4 | [servers] 5 | 6 | # Indentation (tabs and/or spaces) is allowed but not required 7 | [servers.alpha] 8 | ip = "10.0.0.1" 9 | dc = "eqdc10" 10 | 11 | [servers.beta] 12 | ip = "10.0.0.2" 13 | dc = "eqdc20" -------------------------------------------------------------------------------- /ts/lib/std/encoding/yaml.ts: -------------------------------------------------------------------------------- 1 | // Ported from js-yaml v3.13.1: 2 | // https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da 3 | // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license. 4 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 5 | 6 | export type { ParseOptions } from "./_yaml/parse"; 7 | export { parse, parseAll } from "./_yaml/parse"; 8 | export type { DumpOptions as StringifyOptions } from "./_yaml/stringify"; 9 | export { stringify } from "./_yaml/stringify"; 10 | export type { SchemaDefinition } from "./_yaml/schema"; 11 | export type { StyleVariant, Type } from "./_yaml/type"; 12 | export { 13 | CORE_SCHEMA, 14 | DEFAULT_SCHEMA, 15 | EXTENDED_SCHEMA, 16 | FAILSAFE_SCHEMA, 17 | JSON_SCHEMA, 18 | } from "./_yaml/schema/mod"; 19 | -------------------------------------------------------------------------------- /ts/lib/std/encoding/yaml_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | 3 | import "./_yaml/parse_test"; 4 | import "./_yaml/stringify_test"; 5 | 6 | // Type check. 7 | import "./yaml"; 8 | -------------------------------------------------------------------------------- /ts/lib/std/fmt/TODO: -------------------------------------------------------------------------------- 1 | 2 | * "native" formatting, json, arrays, object/structs, functions ... 3 | * %q %U 4 | * Java has a %n flag to print the platform native newline... in POSIX 5 | that means "number of chars printed so far", though. 6 | * Use of Writer and Buffer internally in order to make fprintf, printf, etc. 7 | easier and more elegant. 8 | 9 | * See "Discussion" in README 10 | 11 | * scanf, pack, unpack, annotated hex 12 | * Consistent error handling. 13 | * Rewrite (probably), now that I know how it's done. 14 | -------------------------------------------------------------------------------- /ts/lib/std/fs/_util.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import * as path from "../path/mod"; 3 | 4 | /** 5 | * Test whether or not `dest` is a sub-directory of `src` 6 | * @param src src file path 7 | * @param dest dest file path 8 | * @param sep path separator 9 | */ 10 | export function isSubdir( 11 | src: string, 12 | dest: string, 13 | sep: string = path.sep, 14 | ): boolean { 15 | if (src === dest) { 16 | return false; 17 | } 18 | const srcArray = src.split(sep); 19 | const destArray = dest.split(sep); 20 | return srcArray.every((current, i) => destArray[i] === current); 21 | } 22 | 23 | export type PathType = "file" | "dir" | "symlink"; 24 | 25 | /** 26 | * Get a human readable file type string. 27 | * 28 | * @param fileInfo A FileInfo describes a file and is returned by `stat`, 29 | * `lstat` 30 | */ 31 | export function getFileInfoType(fileInfo: Deno.FileInfo): PathType | undefined { 32 | return fileInfo.isFile 33 | ? "file" 34 | : fileInfo.isDirectory 35 | ? "dir" 36 | : fileInfo.isSymlink 37 | ? "symlink" 38 | : undefined; 39 | } 40 | -------------------------------------------------------------------------------- /ts/lib/std/fs/ensure_dir.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import { getFileInfoType } from "./_util"; 3 | 4 | /** 5 | * Ensures that the directory exists. 6 | * If the directory structure does not exist, it is created. Like mkdir -p. 7 | * Requires the `--allow-read` and `--allow-write` flag. 8 | */ 9 | export async function ensureDir(dir: string) { 10 | try { 11 | const fileInfo = await Deno.lstat(dir); 12 | if (!fileInfo.isDirectory) { 13 | throw new Error( 14 | `Ensure path exists, expected 'dir', got '${ 15 | getFileInfoType(fileInfo) 16 | }'`, 17 | ); 18 | } 19 | } catch (err) { 20 | if (err instanceof Deno.errors.NotFound) { 21 | // if dir not exists. then create it. 22 | await Deno.mkdir(dir, { recursive: true }); 23 | return; 24 | } 25 | throw err; 26 | } 27 | } 28 | 29 | /** 30 | * Ensures that the directory exists. 31 | * If the directory structure does not exist, it is created. Like mkdir -p. 32 | * Requires the `--allow-read` and `--allow-write` flag. 33 | */ 34 | export function ensureDirSync(dir: string): void { 35 | try { 36 | const fileInfo = Deno.lstatSync(dir); 37 | if (!fileInfo.isDirectory) { 38 | throw new Error( 39 | `Ensure path exists, expected 'dir', got '${ 40 | getFileInfoType(fileInfo) 41 | }'`, 42 | ); 43 | } 44 | } catch (err) { 45 | if (err instanceof Deno.errors.NotFound) { 46 | // if dir not exists. then create it. 47 | Deno.mkdirSync(dir, { recursive: true }); 48 | return; 49 | } 50 | throw err; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /ts/lib/std/fs/eol.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | 3 | /** EndOfLine character enum */ 4 | export enum EOL { 5 | LF = "\n", 6 | CRLF = "\r\n", 7 | } 8 | 9 | const regDetect = /(?:\r?\n)/g; 10 | 11 | /** 12 | * Detect the EOL character for string input. 13 | * returns null if no newline 14 | */ 15 | export function detect(content: string): EOL | null { 16 | const d = content.match(regDetect); 17 | if (!d || d.length === 0) { 18 | return null; 19 | } 20 | const hasCRLF = d.some((x: string): boolean => x === EOL.CRLF); 21 | 22 | return hasCRLF ? EOL.CRLF : EOL.LF; 23 | } 24 | 25 | /** Format the file to the targeted EOL */ 26 | export function format(content: string, eol: EOL): string { 27 | return content.replace(regDetect, eol); 28 | } 29 | -------------------------------------------------------------------------------- /ts/lib/std/fs/eol_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import { assertEquals } from "../testing/asserts"; 3 | import { detect, EOL, format } from "./eol"; 4 | 5 | const CRLFinput = "deno\r\nis not\r\nnode"; 6 | const Mixedinput = "deno\nis not\r\nnode"; 7 | const Mixedinput2 = "deno\r\nis not\nnode"; 8 | const LFinput = "deno\nis not\nnode"; 9 | const NoNLinput = "deno is not node"; 10 | 11 | Deno.test({ 12 | name: "[EOL] Detect CR LF", 13 | fn(): void { 14 | assertEquals(detect(CRLFinput), EOL.CRLF); 15 | }, 16 | }); 17 | 18 | Deno.test({ 19 | name: "[EOL] Detect LF", 20 | fn(): void { 21 | assertEquals(detect(LFinput), EOL.LF); 22 | }, 23 | }); 24 | 25 | Deno.test({ 26 | name: "[EOL] Detect No New Line", 27 | fn(): void { 28 | assertEquals(detect(NoNLinput), null); 29 | }, 30 | }); 31 | 32 | Deno.test({ 33 | name: "[EOL] Detect Mixed", 34 | fn(): void { 35 | assertEquals(detect(Mixedinput), EOL.CRLF); 36 | assertEquals(detect(Mixedinput2), EOL.CRLF); 37 | }, 38 | }); 39 | 40 | Deno.test({ 41 | name: "[EOL] Format", 42 | fn(): void { 43 | assertEquals(format(CRLFinput, EOL.LF), LFinput); 44 | assertEquals(format(LFinput, EOL.LF), LFinput); 45 | assertEquals(format(LFinput, EOL.CRLF), CRLFinput); 46 | assertEquals(format(CRLFinput, EOL.CRLF), CRLFinput); 47 | assertEquals(format(CRLFinput, EOL.CRLF), CRLFinput); 48 | assertEquals(format(NoNLinput, EOL.CRLF), NoNLinput); 49 | assertEquals(format(Mixedinput, EOL.CRLF), CRLFinput); 50 | assertEquals(format(Mixedinput, EOL.LF), LFinput); 51 | assertEquals(format(Mixedinput2, EOL.CRLF), CRLFinput); 52 | assertEquals(format(Mixedinput2, EOL.LF), LFinput); 53 | }, 54 | }); 55 | -------------------------------------------------------------------------------- /ts/lib/std/fs/exists.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | /** 3 | * Test whether or not the given path exists by checking with the file system 4 | */ 5 | export async function exists(filePath: string): Promise { 6 | try { 7 | await Deno.lstat(filePath); 8 | return true; 9 | } catch (err) { 10 | if (err instanceof Deno.errors.NotFound) { 11 | return false; 12 | } 13 | 14 | throw err; 15 | } 16 | } 17 | 18 | /** 19 | * Test whether or not the given path exists by checking with the file system 20 | */ 21 | export function existsSync(filePath: string): boolean { 22 | try { 23 | Deno.lstatSync(filePath); 24 | return true; 25 | } catch (err) { 26 | if (err instanceof Deno.errors.NotFound) { 27 | return false; 28 | } 29 | throw err; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /ts/lib/std/fs/mod.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | export * from "./empty_dir"; 3 | export * from "./ensure_dir"; 4 | export * from "./ensure_file"; 5 | export * from "./ensure_link"; 6 | export * from "./ensure_symlink"; 7 | export * from "./exists"; 8 | export * from "./expand_glob"; 9 | export * from "./move"; 10 | export * from "./copy"; 11 | export * from "./walk"; 12 | export * from "./eol"; 13 | -------------------------------------------------------------------------------- /ts/lib/std/fs/move.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import { exists, existsSync } from "./exists"; 3 | import { isSubdir } from "./_util"; 4 | 5 | interface MoveOptions { 6 | overwrite?: boolean; 7 | } 8 | 9 | /** Moves a file or directory */ 10 | export async function move( 11 | src: string, 12 | dest: string, 13 | { overwrite = false }: MoveOptions = {}, 14 | ) { 15 | const srcStat = await Deno.stat(src); 16 | 17 | if (srcStat.isDirectory && isSubdir(src, dest)) { 18 | throw new Error( 19 | `Cannot move '${src}' to a subdirectory of itself, '${dest}'.`, 20 | ); 21 | } 22 | 23 | if (overwrite) { 24 | if (await exists(dest)) { 25 | await Deno.remove(dest, { recursive: true }); 26 | } 27 | } else { 28 | if (await exists(dest)) { 29 | throw new Error("dest already exists."); 30 | } 31 | } 32 | 33 | await Deno.rename(src, dest); 34 | 35 | return; 36 | } 37 | 38 | /** Moves a file or directory synchronously */ 39 | export function moveSync( 40 | src: string, 41 | dest: string, 42 | { overwrite = false }: MoveOptions = {}, 43 | ): void { 44 | const srcStat = Deno.statSync(src); 45 | 46 | if (srcStat.isDirectory && isSubdir(src, dest)) { 47 | throw new Error( 48 | `Cannot move '${src}' to a subdirectory of itself, '${dest}'.`, 49 | ); 50 | } 51 | 52 | if (overwrite) { 53 | if (existsSync(dest)) { 54 | Deno.removeSync(dest, { recursive: true }); 55 | } 56 | } else { 57 | if (existsSync(dest)) { 58 | throw new Error("dest already exists."); 59 | } 60 | } 61 | 62 | Deno.renameSync(src, dest); 63 | } 64 | -------------------------------------------------------------------------------- /ts/lib/std/fs/test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import "./mod"; 3 | -------------------------------------------------------------------------------- /ts/lib/std/fs/testdata/0-link: -------------------------------------------------------------------------------- 1 | 0.ts -------------------------------------------------------------------------------- /ts/lib/std/fs/testdata/0.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsg2020/skynet_ts/66c9e09805138ab2801faa2c808ace13473a9c2e/ts/lib/std/fs/testdata/0.ts -------------------------------------------------------------------------------- /ts/lib/std/fs/testdata/copy_dir/0.txt: -------------------------------------------------------------------------------- 1 | text -------------------------------------------------------------------------------- /ts/lib/std/fs/testdata/copy_dir/nest/0.txt: -------------------------------------------------------------------------------- 1 | nest -------------------------------------------------------------------------------- /ts/lib/std/fs/testdata/copy_dir_link_file/0.txt: -------------------------------------------------------------------------------- 1 | ./fs/testdata/copy_dir/0.txt -------------------------------------------------------------------------------- /ts/lib/std/fs/testdata/copy_file.txt: -------------------------------------------------------------------------------- 1 | txt -------------------------------------------------------------------------------- /ts/lib/std/fs/testdata/empty_dir.ts: -------------------------------------------------------------------------------- 1 | import { emptyDir } from "../empty_dir"; 2 | 3 | emptyDir(Deno.args[0]) 4 | .then(() => { 5 | Deno.stdout.write(new TextEncoder().encode("success")); 6 | }) 7 | .catch((err) => { 8 | Deno.stdout.write(new TextEncoder().encode(err.message)); 9 | }); 10 | -------------------------------------------------------------------------------- /ts/lib/std/fs/testdata/empty_dir_sync.ts: -------------------------------------------------------------------------------- 1 | import { emptyDirSync } from "../empty_dir"; 2 | 3 | try { 4 | emptyDirSync(Deno.args[0]); 5 | Deno.stdout.write(new TextEncoder().encode("success")); 6 | } catch (err) { 7 | Deno.stdout.write(new TextEncoder().encode(err.message)); 8 | } 9 | -------------------------------------------------------------------------------- /ts/lib/std/fs/testdata/exists.ts: -------------------------------------------------------------------------------- 1 | import { exists } from "../exists"; 2 | 3 | exists(Deno.args[0]) 4 | .then((isExist) => { 5 | Deno.stdout.write( 6 | new TextEncoder().encode(isExist ? "exist" : "not exist"), 7 | ); 8 | }) 9 | .catch((err) => { 10 | Deno.stdout.write(new TextEncoder().encode(err.message)); 11 | }); 12 | -------------------------------------------------------------------------------- /ts/lib/std/fs/testdata/exists_sync.ts: -------------------------------------------------------------------------------- 1 | import { existsSync } from "../exists"; 2 | 3 | try { 4 | const isExist = existsSync(Deno.args[0]); 5 | Deno.stdout.write(new TextEncoder().encode(isExist ? "exist" : "not exist")); 6 | } catch (err) { 7 | Deno.stdout.write(new TextEncoder().encode(err.message)); 8 | } 9 | -------------------------------------------------------------------------------- /ts/lib/std/fs/testdata/expand_wildcard.js: -------------------------------------------------------------------------------- 1 | import { expandGlob } from "../expand_glob"; 2 | 3 | const glob = new URL("*", import.meta.url).pathname; 4 | for await (const { filename } of expandGlob(glob)) { 5 | console.log(filename); 6 | } 7 | -------------------------------------------------------------------------------- /ts/lib/std/fs/testdata/glob/abc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsg2020/skynet_ts/66c9e09805138ab2801faa2c808ace13473a9c2e/ts/lib/std/fs/testdata/glob/abc -------------------------------------------------------------------------------- /ts/lib/std/fs/testdata/glob/abcdef: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsg2020/skynet_ts/66c9e09805138ab2801faa2c808ace13473a9c2e/ts/lib/std/fs/testdata/glob/abcdef -------------------------------------------------------------------------------- /ts/lib/std/fs/testdata/glob/abcdefghi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsg2020/skynet_ts/66c9e09805138ab2801faa2c808ace13473a9c2e/ts/lib/std/fs/testdata/glob/abcdefghi -------------------------------------------------------------------------------- /ts/lib/std/fs/testdata/glob/subdir/abc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsg2020/skynet_ts/66c9e09805138ab2801faa2c808ace13473a9c2e/ts/lib/std/fs/testdata/glob/subdir/abc -------------------------------------------------------------------------------- /ts/lib/std/hash/_fnv/util.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | 3 | function n16(n: number): number { 4 | return n & 0xffff; 5 | } 6 | 7 | function n32(n: number): number { 8 | return n >>> 0; 9 | } 10 | 11 | function add32WithCarry(a: number, b: number): [number, number] { 12 | const added = n32(a) + n32(b); 13 | return [n32(added), added > 0xffffffff ? 1 : 0]; 14 | } 15 | 16 | function mul32WithCarry(a: number, b: number): [number, number] { 17 | const al = n16(a); 18 | const ah = n16(a >>> 16); 19 | const bl = n16(b); 20 | const bh = n16(b >>> 16); 21 | 22 | const [t, tc] = add32WithCarry(al * bh, ah * bl); 23 | const [n, nc] = add32WithCarry(al * bl, n32(t << 16)); 24 | const carry = nc + (tc << 16) + n16(t >>> 16) + ah * bh; 25 | 26 | return [n, carry]; 27 | } 28 | 29 | /** 30 | * mul32 performs 32-bit multiplication, a * b 31 | * @param a 32 | * @param b 33 | */ 34 | export function mul32(a: number, b: number): number { 35 | // https://stackoverflow.com/a/28151933 36 | const al = n16(a); 37 | const ah = a - al; 38 | return n32(n32(ah * b) + al * b); 39 | } 40 | 41 | /** 42 | * mul64 performs 64-bit multiplication with two 32-bit words 43 | * @param [ah, al] 44 | * @param [bh, bl] 45 | */ 46 | export function mul64( 47 | [ah, al]: [number, number], 48 | [bh, bl]: [number, number], 49 | ): [number, number] { 50 | const [n, c] = mul32WithCarry(al, bl); 51 | return [n32(mul32(al, bh) + mul32(ah, bl) + c), n]; 52 | } 53 | -------------------------------------------------------------------------------- /ts/lib/std/hash/_sha3/keccak.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | 3 | import { Sponge } from "./sponge"; 4 | import { keccakf } from "./keccakf"; 5 | 6 | /** Keccak-224 hash */ 7 | export class Keccak224 extends Sponge { 8 | constructor() { 9 | super({ 10 | bitsize: 224, 11 | rate: 144, 12 | dsbyte: 1, 13 | permutator: keccakf, 14 | }); 15 | } 16 | } 17 | 18 | /** Keccak-256 hash */ 19 | export class Keccak256 extends Sponge { 20 | constructor() { 21 | super({ 22 | bitsize: 256, 23 | rate: 136, 24 | dsbyte: 1, 25 | permutator: keccakf, 26 | }); 27 | } 28 | } 29 | 30 | /** Keccak-384 hash */ 31 | export class Keccak384 extends Sponge { 32 | constructor() { 33 | super({ 34 | bitsize: 384, 35 | rate: 104, 36 | dsbyte: 1, 37 | permutator: keccakf, 38 | }); 39 | } 40 | } 41 | 42 | /** Keccak-512 hash */ 43 | export class Keccak512 extends Sponge { 44 | constructor() { 45 | super({ 46 | bitsize: 512, 47 | rate: 72, 48 | dsbyte: 1, 49 | permutator: keccakf, 50 | }); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /ts/lib/std/hash/_sha3/sha3.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | 3 | import { Sponge } from "./sponge"; 4 | import { keccakf } from "./keccakf"; 5 | 6 | /** Sha3-224 hash */ 7 | // deno-lint-ignore camelcase 8 | export class Sha3_224 extends Sponge { 9 | constructor() { 10 | super({ 11 | bitsize: 224, 12 | rate: 144, 13 | dsbyte: 6, 14 | permutator: keccakf, 15 | }); 16 | } 17 | } 18 | 19 | /** Sha3-256 hash */ 20 | // deno-lint-ignore camelcase 21 | export class Sha3_256 extends Sponge { 22 | constructor() { 23 | super({ 24 | bitsize: 256, 25 | rate: 136, 26 | dsbyte: 6, 27 | permutator: keccakf, 28 | }); 29 | } 30 | } 31 | 32 | /** Sha3-384 hash */ 33 | // deno-lint-ignore camelcase 34 | export class Sha3_384 extends Sponge { 35 | constructor() { 36 | super({ 37 | bitsize: 384, 38 | rate: 104, 39 | dsbyte: 6, 40 | permutator: keccakf, 41 | }); 42 | } 43 | } 44 | 45 | /** Sha3-512 hash */ 46 | // deno-lint-ignore camelcase 47 | export class Sha3_512 extends Sponge { 48 | constructor() { 49 | super({ 50 | bitsize: 512, 51 | rate: 72, 52 | dsbyte: 6, 53 | permutator: keccakf, 54 | }); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /ts/lib/std/hash/_sha3/shake.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | 3 | import { Sponge } from "./sponge"; 4 | import { keccakf } from "./keccakf"; 5 | 6 | /** Shake128 hash */ 7 | export class Shake128 extends Sponge { 8 | /** 9 | * Instantiates a new Shake128 hash 10 | * @param bitsize length of hash in bits 11 | */ 12 | constructor(bitsize: number) { 13 | if (bitsize < 8) { 14 | throw new Error("shake128: `bitsize` too small"); 15 | } 16 | 17 | if (bitsize % 8 !== 0) { 18 | throw new Error("shake128: `bitsize` must be multiple of 8"); 19 | } 20 | 21 | super({ 22 | bitsize: bitsize, 23 | rate: 168, 24 | dsbyte: 0x1f, 25 | permutator: keccakf, 26 | }); 27 | } 28 | } 29 | 30 | /** 31 | * Instantiates a new Shake256 hash 32 | * @param bitsize length of hash in bits 33 | */ 34 | export class Shake256 extends Sponge { 35 | constructor(bitsize: number) { 36 | if (bitsize < 8) { 37 | throw new Error("shake256: `bitsize` too small"); 38 | } 39 | 40 | if (bitsize % 8 !== 0) { 41 | throw new Error("shake256: `bitsize` must be multiple of 8"); 42 | } 43 | 44 | super({ 45 | bitsize: bitsize, 46 | rate: 136, 47 | dsbyte: 0x1f, 48 | permutator: keccakf, 49 | }); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /ts/lib/std/hash/_wasm/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "deno-hash" 3 | version = "0.1.0" 4 | authors = ["the Deno authors"] 5 | edition = "2018" 6 | license = "MIT" 7 | repository = "https://github.com/denoland/deno" 8 | 9 | [lib] 10 | crate-type = ["cdylib"] 11 | 12 | [dependencies] 13 | digest = "0.9.0" 14 | md2 = "0.9.0" 15 | md4 = "0.9.0" 16 | md-5 = "0.9.1" 17 | ripemd160 = "0.9.1" 18 | ripemd320 = "0.9.0" 19 | sha-1 = "0.9.1" 20 | sha2 = "0.9.1" 21 | sha3 = "0.9.1" 22 | wasm-bindgen = "0.2.68" 23 | 24 | [profile.release] 25 | lto = true 26 | opt-level = 3 27 | 28 | [package.metadata.wasm-pack.profile.release] 29 | wasm-opt = ["-O", "--enable-mutable-globals"] 30 | -------------------------------------------------------------------------------- /ts/lib/std/hash/_wasm/README.md: -------------------------------------------------------------------------------- 1 | # How to build 2 | 3 | ## Prerequisite 4 | 5 | `wasm-pack` is required. 6 | 7 | ```sh 8 | cargo install wasm-pack 9 | ``` 10 | 11 | ## Build 12 | 13 | ```sh 14 | deno run --allow-read --allow-write --allow-run ./build.ts 15 | ``` 16 | 17 | `wasm.js` will be generated. 18 | -------------------------------------------------------------------------------- /ts/lib/std/hash/_wasm/build.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | 3 | import { encode as base64Encode } from "../../encoding/base64"; 4 | 5 | // 1. build wasm 6 | async function buildWasm(path: string) { 7 | const cmd = [ 8 | "wasm-pack", 9 | "build", 10 | "--target", 11 | "web", 12 | "--release", 13 | "-d", 14 | path, 15 | ]; 16 | const builder = Deno.run({ cmd }); 17 | const status = await builder.status(); 18 | 19 | if (!status.success) { 20 | console.error(`Failed to build wasm: ${status.code}`); 21 | Deno.exit(1); 22 | } 23 | } 24 | 25 | // 2. encode wasm 26 | async function encodeWasm(wasmPath: string): Promise { 27 | const wasm = await Deno.readFile(`${wasmPath}/deno_hash_bg.wasm`); 28 | return base64Encode(wasm); 29 | } 30 | 31 | // 3. generate script 32 | async function generate(wasm: string, output: string) { 33 | const initScript = await Deno.readTextFile(`${output}/deno_hash.js`); 34 | const denoHashScript = "// deno-lint-ignore-file\n" + 35 | "//deno-fmt-ignore-file\n" + 36 | "//deno-lint-ignore-file\n" + 37 | `import * as base64 from "../../encoding/base64";` + 38 | `export const source = base64.decode("${wasm}");` + 39 | initScript; 40 | 41 | await Deno.writeFile("wasm.js", new TextEncoder().encode(denoHashScript)); 42 | } 43 | 44 | const OUTPUT_DIR = "./out"; 45 | 46 | await buildWasm(OUTPUT_DIR); 47 | const wasm = await encodeWasm(OUTPUT_DIR); 48 | await generate(wasm, OUTPUT_DIR); 49 | -------------------------------------------------------------------------------- /ts/lib/std/hash/fnv.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | 3 | export { Fnv32, Fnv32a } from "./_fnv/fnv32"; 4 | export { Fnv64, Fnv64a } from "./_fnv/fnv64"; 5 | -------------------------------------------------------------------------------- /ts/lib/std/hash/hasher.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | 3 | export type Message = string | ArrayBuffer; 4 | export type OutputFormat = "hex" | "base64"; 5 | 6 | export interface Hasher { 7 | update(data: Message): this; 8 | digest(): ArrayBuffer; 9 | toString(format?: OutputFormat): string; 10 | } 11 | -------------------------------------------------------------------------------- /ts/lib/std/hash/mod.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | 3 | import { Hash } from "./_wasm/hash"; 4 | import type { Hasher } from "./hasher"; 5 | 6 | export type { Hasher } from "./hasher"; 7 | export const supportedAlgorithms = [ 8 | "md2", 9 | "md4", 10 | "md5", 11 | "ripemd160", 12 | "ripemd320", 13 | "sha1", 14 | "sha224", 15 | "sha256", 16 | "sha384", 17 | "sha512", 18 | "sha3-224", 19 | "sha3-256", 20 | "sha3-384", 21 | "sha3-512", 22 | "keccak224", 23 | "keccak256", 24 | "keccak384", 25 | "keccak512", 26 | ] as const; 27 | export type SupportedAlgorithm = typeof supportedAlgorithms[number]; 28 | /** 29 | * Creates a new `Hash` instance. 30 | * 31 | * @param algorithm name of hash algorithm to use 32 | */ 33 | export function createHash(algorithm: SupportedAlgorithm): Hasher { 34 | return new Hash(algorithm as string); 35 | } 36 | -------------------------------------------------------------------------------- /ts/lib/std/hash/sha3.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | 3 | export { Sha3_224, Sha3_256, Sha3_384, Sha3_512 } from "./_sha3/sha3"; 4 | export { Keccak224, Keccak256, Keccak384, Keccak512 } from "./_sha3/keccak"; 5 | export { Shake128, Shake256 } from "./_sha3/shake"; 6 | -------------------------------------------------------------------------------- /ts/lib/std/hash/testdata/hashtest: -------------------------------------------------------------------------------- 1 | test -------------------------------------------------------------------------------- /ts/lib/std/http/_mock_conn.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | 3 | /** Create dummy Deno.Conn object with given base properties */ 4 | export function mockConn(base: Partial = {}): Deno.Conn { 5 | return { 6 | localAddr: { 7 | transport: "tcp", 8 | hostname: "", 9 | port: 0, 10 | }, 11 | remoteAddr: { 12 | transport: "tcp", 13 | hostname: "", 14 | port: 0, 15 | }, 16 | rid: -1, 17 | closeWrite: () => { 18 | return Promise.resolve(); 19 | }, 20 | read: (): Promise => { 21 | return Promise.resolve(0); 22 | }, 23 | write: (): Promise => { 24 | return Promise.resolve(-1); 25 | }, 26 | close: (): void => {}, 27 | ...base, 28 | }; 29 | } 30 | -------------------------------------------------------------------------------- /ts/lib/std/http/mod.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | export * from "./cookie"; 3 | export * from "./http_status"; 4 | export * from "./server"; 5 | -------------------------------------------------------------------------------- /ts/lib/std/http/test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import "./mod"; 3 | -------------------------------------------------------------------------------- /ts/lib/std/io/mod.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | export * from "./buffer"; 3 | export * from "./bufio"; 4 | export * from "./ioutil"; 5 | export * from "./readers"; 6 | export * from "./streams"; 7 | export * from "./util"; 8 | export * from "./writers"; 9 | -------------------------------------------------------------------------------- /ts/lib/std/io/test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import "./mod"; 3 | -------------------------------------------------------------------------------- /ts/lib/std/io/testdata/iso-8859-15.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsg2020/skynet_ts/66c9e09805138ab2801faa2c808ace13473a9c2e/ts/lib/std/io/testdata/iso-8859-15.txt -------------------------------------------------------------------------------- /ts/lib/std/io/writers.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | type Writer = Deno.Writer; 3 | type WriterSync = Deno.WriterSync; 4 | 5 | const decoder = new TextDecoder(); 6 | 7 | /** Writer utility for buffering string chunks */ 8 | export class StringWriter implements Writer, WriterSync { 9 | private chunks: Uint8Array[] = []; 10 | private byteLength = 0; 11 | private cache: string | undefined; 12 | 13 | constructor(private base: string = "") { 14 | const c = new TextEncoder().encode(base); 15 | this.chunks.push(c); 16 | this.byteLength += c.byteLength; 17 | } 18 | 19 | write(p: Uint8Array): Promise { 20 | return Promise.resolve(this.writeSync(p)); 21 | } 22 | 23 | writeSync(p: Uint8Array): number { 24 | this.chunks.push(p); 25 | this.byteLength += p.byteLength; 26 | this.cache = undefined; 27 | return p.byteLength; 28 | } 29 | 30 | toString(): string { 31 | if (this.cache) { 32 | return this.cache; 33 | } 34 | const buf = new Uint8Array(this.byteLength); 35 | let offs = 0; 36 | for (const chunk of this.chunks) { 37 | buf.set(chunk, offs); 38 | offs += chunk.byteLength; 39 | } 40 | this.cache = decoder.decode(buf); 41 | return this.cache; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ts/lib/std/io/writers_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import { assertEquals } from "../testing/asserts"; 3 | import { StringWriter } from "./writers"; 4 | import { StringReader } from "./readers"; 5 | import { copyN } from "./ioutil"; 6 | 7 | Deno.test("ioStringWriter", async function () { 8 | const w = new StringWriter("base"); 9 | const r = new StringReader("0123456789"); 10 | await copyN(r, w, 4); 11 | assertEquals(w.toString(), "base0123"); 12 | await Deno.copy(r, w); 13 | assertEquals(w.toString(), "base0123456789"); 14 | }); 15 | 16 | Deno.test("ioStringWriterSync", function (): void { 17 | const encoder = new TextEncoder(); 18 | const w = new StringWriter(""); 19 | w.writeSync(encoder.encode("deno")); 20 | assertEquals(w.toString(), "deno"); 21 | w.writeSync(encoder.encode("\nland")); 22 | assertEquals(w.toString(), "deno\nland"); 23 | }); 24 | -------------------------------------------------------------------------------- /ts/lib/std/mime/mod.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | export * from "./multipart"; 3 | -------------------------------------------------------------------------------- /ts/lib/std/mime/test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import "./mod"; 3 | -------------------------------------------------------------------------------- /ts/lib/std/mime/testdata/sample.txt: -------------------------------------------------------------------------------- 1 | ----------------------------434049563556637648550474 2 | content-disposition: form-data; name="foo" 3 | content-type: application/octet-stream 4 | 5 | foo 6 | ----------------------------434049563556637648550474 7 | content-disposition: form-data; name="bar" 8 | content-type: application/octet-stream 9 | 10 | bar 11 | ----------------------------434049563556637648550474 12 | content-disposition: form-data; name="file"; filename="tsconfig.json" 13 | content-type: application/octet-stream 14 | 15 | { 16 | "compilerOptions": { 17 | "target": "es2018", 18 | "baseUrl": ".", 19 | "paths": { 20 | "deno": ["./deno.d.ts"], 21 | "https://*": ["../../.deno/deps/https/*"], 22 | "http://*": ["../../.deno/deps/http/*"] 23 | } 24 | } 25 | } 26 | 27 | ----------------------------434049563556637648550474 28 | content-disposition: form-data; name="file2"; filename="中文.json" 29 | content-type: application/octet-stream 30 | 31 | { 32 | "test": "filename" 33 | } 34 | 35 | ----------------------------434049563556637648550474-- 36 | -------------------------------------------------------------------------------- /ts/lib/std/node/_crypto/constants.ts: -------------------------------------------------------------------------------- 1 | export const MAX_ALLOC = Math.pow(2, 30) - 1; 2 | -------------------------------------------------------------------------------- /ts/lib/std/node/_crypto/types.ts: -------------------------------------------------------------------------------- 1 | import { Buffer } from "../buffer"; 2 | 3 | export type HASH_DATA = string | ArrayBufferView | Buffer; 4 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/_fs_access.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import type { CallbackWithError } from "./_fs_common"; 3 | import { notImplemented } from "../_utils"; 4 | 5 | /** Revist once https://github.com/denoland/deno/issues/4017 lands */ 6 | 7 | // TODO(bartlomieju) 'path' can also be a Buffer. Neither of these polyfills 8 | //is available yet. See https://github.com/denoland/deno/issues/3403 9 | export function access( 10 | _path: string | URL, 11 | _modeOrCallback: number | ((...args: unknown[]) => void), 12 | _callback?: CallbackWithError, 13 | ): void { 14 | notImplemented("Not yet available"); 15 | } 16 | 17 | // TODO(bartlomieju) 'path' can also be a Buffer. Neither of these polyfills 18 | // is available yet. See https://github.com/denoland/deno/issues/3403 19 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 20 | export function accessSync(_path: string | URL, _mode?: number): void { 21 | notImplemented("Not yet available"); 22 | } 23 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/_fs_chmod.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import type { CallbackWithError } from "./_fs_common"; 3 | import { fromFileUrl } from "../path"; 4 | 5 | const allowedModes = /^[0-7]{3}/; 6 | 7 | /** 8 | * TODO: Also accept 'path' parameter as a Node polyfill Buffer type once these 9 | * are implemented. See https://github.com/denoland/deno/issues/3403 10 | */ 11 | export function chmod( 12 | path: string | URL, 13 | mode: string | number, 14 | callback: CallbackWithError, 15 | ): void { 16 | path = path instanceof URL ? fromFileUrl(path) : path; 17 | 18 | Deno.chmod(path, getResolvedMode(mode)).then(() => callback(null), callback); 19 | } 20 | 21 | /** 22 | * TODO: Also accept 'path' parameter as a Node polyfill Buffer type once these 23 | * are implemented. See https://github.com/denoland/deno/issues/3403 24 | */ 25 | export function chmodSync(path: string | URL, mode: string | number): void { 26 | path = path instanceof URL ? fromFileUrl(path) : path; 27 | Deno.chmodSync(path, getResolvedMode(mode)); 28 | } 29 | 30 | function getResolvedMode(mode: string | number): number { 31 | if (typeof mode === "number") { 32 | return mode; 33 | } 34 | 35 | if (typeof mode === "string" && !allowedModes.test(mode)) { 36 | throw new Error("Unrecognized mode: " + mode); 37 | } 38 | 39 | return parseInt(mode, 8); 40 | } 41 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/_fs_chown.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import type { CallbackWithError } from "./_fs_common"; 3 | import { fromFileUrl } from "../path"; 4 | 5 | /** 6 | * TODO: Also accept 'path' parameter as a Node polyfill Buffer type once these 7 | * are implemented. See https://github.com/denoland/deno/issues/3403 8 | */ 9 | export function chown( 10 | path: string | URL, 11 | uid: number, 12 | gid: number, 13 | callback: CallbackWithError, 14 | ): void { 15 | path = path instanceof URL ? fromFileUrl(path) : path; 16 | 17 | Deno.chown(path, uid, gid).then(() => callback(null), callback); 18 | } 19 | 20 | /** 21 | * TODO: Also accept 'path' parameter as a Node polyfill Buffer type once these 22 | * are implemented. See https://github.com/denoland/deno/issues/3403 23 | */ 24 | export function chownSync(path: string | URL, uid: number, gid: number): void { 25 | path = path instanceof URL ? fromFileUrl(path) : path; 26 | 27 | Deno.chownSync(path, uid, gid); 28 | } 29 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/_fs_close.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import type { CallbackWithError } from "./_fs_common"; 3 | 4 | export function close(fd: number, callback: CallbackWithError): void { 5 | setTimeout(() => { 6 | let error = null; 7 | try { 8 | Deno.close(fd); 9 | } catch (err) { 10 | error = err; 11 | } 12 | callback(error); 13 | }, 0); 14 | } 15 | 16 | export function closeSync(fd: number): void { 17 | Deno.close(fd); 18 | } 19 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/_fs_constants.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | 3 | //File access constants 4 | export const F_OK = 0; 5 | export const R_OK = 4; 6 | export const W_OK = 2; 7 | export const X_OK = 1; 8 | 9 | //File mode constants 10 | export const S_IRUSR = 0o400; //read by owner 11 | export const S_IWUSR = 0o200; //write by owner 12 | export const S_IXUSR = 0o100; //execute/search by owner 13 | export const S_IRGRP = 0o40; //read by group 14 | export const S_IWGRP = 0o20; //write by group 15 | export const S_IXGRP = 0o10; //execute/search by group 16 | export const S_IROTH = 0o4; //read by others 17 | export const S_IWOTH = 0o2; //write by others 18 | export const S_IXOTH = 0o1; //execute/search by others 19 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/_fs_copy.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import type { CallbackWithError } from "./_fs_common"; 3 | import { fromFileUrl } from "../path"; 4 | 5 | export function copyFile( 6 | source: string | URL, 7 | destination: string, 8 | callback: CallbackWithError, 9 | ): void { 10 | source = source instanceof URL ? fromFileUrl(source) : source; 11 | 12 | Deno.copyFile(source, destination).then(() => callback(null), callback); 13 | } 14 | 15 | export function copyFileSync(source: string | URL, destination: string): void { 16 | source = source instanceof URL ? fromFileUrl(source) : source; 17 | Deno.copyFileSync(source, destination); 18 | } 19 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/_fs_dirent.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import { notImplemented } from "../_utils"; 3 | 4 | export default class Dirent { 5 | constructor(private entry: Deno.DirEntry) {} 6 | 7 | isBlockDevice(): boolean { 8 | notImplemented("Deno does not yet support identification of block devices"); 9 | return false; 10 | } 11 | 12 | isCharacterDevice(): boolean { 13 | notImplemented( 14 | "Deno does not yet support identification of character devices", 15 | ); 16 | return false; 17 | } 18 | 19 | isDirectory(): boolean { 20 | return this.entry.isDirectory; 21 | } 22 | 23 | isFIFO(): boolean { 24 | notImplemented( 25 | "Deno does not yet support identification of FIFO named pipes", 26 | ); 27 | return false; 28 | } 29 | 30 | isFile(): boolean { 31 | return this.entry.isFile; 32 | } 33 | 34 | isSocket(): boolean { 35 | notImplemented("Deno does not yet support identification of sockets"); 36 | return false; 37 | } 38 | 39 | isSymbolicLink(): boolean { 40 | return this.entry.isSymlink; 41 | } 42 | 43 | get name(): string | null { 44 | return this.entry.name; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/_fs_exists.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import { fromFileUrl } from "../path"; 3 | 4 | type ExitsCallback = (exists: boolean) => void; 5 | 6 | /** 7 | * TODO: Also accept 'path' parameter as a Node polyfill Buffer type once these 8 | * are implemented. See https://github.com/denoland/deno/issues/3403 9 | * Deprecated in node api 10 | */ 11 | export function exists(path: string | URL, callback: ExitsCallback): void { 12 | path = path instanceof URL ? fromFileUrl(path) : path; 13 | Deno.lstat(path).then(() => callback(true), () => callback(false)); 14 | } 15 | 16 | /** 17 | * TODO: Also accept 'path' parameter as a Node polyfill Buffer or URL type once these 18 | * are implemented. See https://github.com/denoland/deno/issues/3403 19 | */ 20 | export function existsSync(path: string | URL): boolean { 21 | path = path instanceof URL ? fromFileUrl(path) : path; 22 | try { 23 | Deno.lstatSync(path); 24 | return true; 25 | } catch (err) { 26 | if (err instanceof Deno.errors.NotFound) { 27 | return false; 28 | } 29 | throw err; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/_fs_fdatasync.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import { CallbackWithError } from "./_fs_common"; 3 | 4 | export function fdatasync( 5 | fd: number, 6 | callback: CallbackWithError, 7 | ) { 8 | Deno.fdatasync(fd).then(() => callback(null), callback); 9 | } 10 | 11 | export function fdatasyncSync(fd: number) { 12 | Deno.fdatasyncSync(fd); 13 | } 14 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/_fs_fstat.ts: -------------------------------------------------------------------------------- 1 | import { 2 | BigIntStats, 3 | CFISBIS, 4 | statCallback, 5 | statCallbackBigInt, 6 | statOptions, 7 | Stats, 8 | } from "./_fs_stat"; 9 | 10 | export function fstat(fd: number, callback: statCallback): void; 11 | export function fstat( 12 | fd: number, 13 | options: { bigint: false }, 14 | callback: statCallback, 15 | ): void; 16 | export function fstat( 17 | fd: number, 18 | options: { bigint: true }, 19 | callback: statCallbackBigInt, 20 | ): void; 21 | export function fstat( 22 | fd: number, 23 | optionsOrCallback: statCallback | statCallbackBigInt | statOptions, 24 | maybeCallback?: statCallback | statCallbackBigInt, 25 | ) { 26 | const callback = 27 | (typeof optionsOrCallback === "function" 28 | ? optionsOrCallback 29 | : maybeCallback) as ( 30 | ...args: [Error] | [null, BigIntStats | Stats] 31 | ) => void; 32 | const options = typeof optionsOrCallback === "object" 33 | ? optionsOrCallback 34 | : { bigint: false }; 35 | 36 | if (!callback) throw new Error("No callback function supplied"); 37 | 38 | Deno.fstat(fd).then( 39 | (stat) => callback(null, CFISBIS(stat, options.bigint)), 40 | (err) => callback(err), 41 | ); 42 | } 43 | 44 | export function fstatSync(fd: number): Stats; 45 | export function fstatSync( 46 | fd: number, 47 | options: { bigint: false }, 48 | ): Stats; 49 | export function fstatSync( 50 | fd: number, 51 | options: { bigint: true }, 52 | ): BigIntStats; 53 | export function fstatSync( 54 | fd: number, 55 | options?: statOptions, 56 | ): Stats | BigIntStats { 57 | const origin = Deno.fstatSync(fd); 58 | return CFISBIS(origin, options?.bigint || false); 59 | } 60 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/_fs_fsync.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import { CallbackWithError } from "./_fs_common"; 3 | 4 | export function fsync( 5 | fd: number, 6 | callback: CallbackWithError, 7 | ) { 8 | Deno.fsync(fd).then(() => callback(null), callback); 9 | } 10 | 11 | export function fsyncSync(fd: number) { 12 | Deno.fsyncSync(fd); 13 | } 14 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/_fs_fsync_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import { assertEquals, fail } from "../../testing/asserts"; 3 | import { fsync, fsyncSync } from "./_fs_fsync"; 4 | 5 | Deno.test({ 6 | name: "ASYNC: flush any pending data of the given file stream to disk", 7 | async fn() { 8 | const file: string = await Deno.makeTempFile(); 9 | const { rid } = await Deno.open(file, { 10 | read: true, 11 | write: true, 12 | create: true, 13 | }); 14 | const size = 64; 15 | await Deno.ftruncate(rid, size); 16 | 17 | await new Promise((resolve, reject) => { 18 | fsync(rid, (err: Error | null) => { 19 | if (err !== null) reject(); 20 | else resolve(); 21 | }); 22 | }) 23 | .then( 24 | async () => { 25 | assertEquals((await Deno.stat(file)).size, size); 26 | }, 27 | () => { 28 | fail("No error expected"); 29 | }, 30 | ) 31 | .finally(async () => { 32 | await Deno.remove(file); 33 | Deno.close(rid); 34 | }); 35 | }, 36 | }); 37 | 38 | Deno.test({ 39 | name: "SYNC: flush any pending data the given file stream to disk", 40 | fn() { 41 | const file: string = Deno.makeTempFileSync(); 42 | const { rid } = Deno.openSync(file, { 43 | read: true, 44 | write: true, 45 | create: true, 46 | }); 47 | const size = 64; 48 | Deno.ftruncateSync(rid, size); 49 | 50 | try { 51 | fsyncSync(rid); 52 | assertEquals(Deno.statSync(file).size, size); 53 | } finally { 54 | Deno.removeSync(file); 55 | Deno.close(rid); 56 | } 57 | }, 58 | }); 59 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/_fs_ftruncate.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import { CallbackWithError } from "./_fs_common"; 3 | 4 | export function ftruncate( 5 | fd: number, 6 | lenOrCallback: number | CallbackWithError, 7 | maybeCallback?: CallbackWithError, 8 | ) { 9 | const len: number | undefined = typeof lenOrCallback === "number" 10 | ? lenOrCallback 11 | : undefined; 12 | const callback: CallbackWithError = typeof lenOrCallback === "function" 13 | ? lenOrCallback 14 | : maybeCallback as CallbackWithError; 15 | 16 | if (!callback) throw new Error("No callback function supplied"); 17 | 18 | Deno.ftruncate(fd, len).then(() => callback(null), callback); 19 | } 20 | 21 | export function ftruncateSync(fd: number, len?: number) { 22 | Deno.ftruncateSync(fd, len); 23 | } 24 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/_fs_futimes.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import type { CallbackWithError } from "./_fs_common"; 3 | 4 | function getValidTime( 5 | time: number | string | Date, 6 | name: string, 7 | ): number | Date { 8 | if (typeof time === "string") { 9 | time = Number(time); 10 | } 11 | 12 | if ( 13 | typeof time === "number" && 14 | (Number.isNaN(time) || !Number.isFinite(time)) 15 | ) { 16 | throw new Deno.errors.InvalidData( 17 | `invalid ${name}, must not be infitiny or NaN`, 18 | ); 19 | } 20 | 21 | return time; 22 | } 23 | 24 | export function futimes( 25 | fd: number, 26 | atime: number | string | Date, 27 | mtime: number | string | Date, 28 | callback: CallbackWithError, 29 | ): void { 30 | if (!callback) { 31 | throw new Deno.errors.InvalidData("No callback function supplied"); 32 | } 33 | 34 | atime = getValidTime(atime, "atime"); 35 | mtime = getValidTime(mtime, "mtime"); 36 | 37 | Deno.futime(fd, atime, mtime).then(() => callback(null), callback); 38 | } 39 | 40 | export function futimesSync( 41 | fd: number, 42 | atime: number | string | Date, 43 | mtime: number | string | Date, 44 | ): void { 45 | atime = getValidTime(atime, "atime"); 46 | mtime = getValidTime(mtime, "mtime"); 47 | 48 | Deno.futimeSync(fd, atime, mtime); 49 | } 50 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/_fs_link.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import type { CallbackWithError } from "./_fs_common"; 3 | import { fromFileUrl } from "../path"; 4 | 5 | /** 6 | * TODO: Also accept 'path' parameter as a Node polyfill Buffer type once these 7 | * are implemented. See https://github.com/denoland/deno/issues/3403 8 | */ 9 | export function link( 10 | existingPath: string | URL, 11 | newPath: string | URL, 12 | callback: CallbackWithError, 13 | ): void { 14 | existingPath = existingPath instanceof URL 15 | ? fromFileUrl(existingPath) 16 | : existingPath; 17 | newPath = newPath instanceof URL ? fromFileUrl(newPath) : newPath; 18 | 19 | Deno.link(existingPath, newPath).then(() => callback(null), callback); 20 | } 21 | 22 | /** 23 | * TODO: Also accept 'path' parameter as a Node polyfill Buffer type once these 24 | * are implemented. See https://github.com/denoland/deno/issues/3403 25 | */ 26 | export function linkSync( 27 | existingPath: string | URL, 28 | newPath: string | URL, 29 | ): void { 30 | existingPath = existingPath instanceof URL 31 | ? fromFileUrl(existingPath) 32 | : existingPath; 33 | newPath = newPath instanceof URL ? fromFileUrl(newPath) : newPath; 34 | 35 | Deno.linkSync(existingPath, newPath); 36 | } 37 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/_fs_lstat.ts: -------------------------------------------------------------------------------- 1 | import { 2 | BigIntStats, 3 | CFISBIS, 4 | statCallback, 5 | statCallbackBigInt, 6 | statOptions, 7 | Stats, 8 | } from "./_fs_stat"; 9 | 10 | export function lstat(path: string | URL, callback: statCallback): void; 11 | export function lstat( 12 | path: string | URL, 13 | options: { bigint: false }, 14 | callback: statCallback, 15 | ): void; 16 | export function lstat( 17 | path: string | URL, 18 | options: { bigint: true }, 19 | callback: statCallbackBigInt, 20 | ): void; 21 | export function lstat( 22 | path: string | URL, 23 | optionsOrCallback: statCallback | statCallbackBigInt | statOptions, 24 | maybeCallback?: statCallback | statCallbackBigInt, 25 | ) { 26 | const callback = 27 | (typeof optionsOrCallback === "function" 28 | ? optionsOrCallback 29 | : maybeCallback) as ( 30 | ...args: [Error] | [null, BigIntStats | Stats] 31 | ) => void; 32 | const options = typeof optionsOrCallback === "object" 33 | ? optionsOrCallback 34 | : { bigint: false }; 35 | 36 | if (!callback) throw new Error("No callback function supplied"); 37 | 38 | Deno.lstat(path).then( 39 | (stat) => callback(null, CFISBIS(stat, options.bigint)), 40 | (err) => callback(err), 41 | ); 42 | } 43 | 44 | export function lstatSync(path: string | URL): Stats; 45 | export function lstatSync( 46 | path: string | URL, 47 | options: { bigint: false }, 48 | ): Stats; 49 | export function lstatSync( 50 | path: string | URL, 51 | options: { bigint: true }, 52 | ): BigIntStats; 53 | export function lstatSync( 54 | path: string | URL, 55 | options?: statOptions, 56 | ): Stats | BigIntStats { 57 | const origin = Deno.lstatSync(path); 58 | return CFISBIS(origin, options?.bigint || false); 59 | } 60 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/_fs_mkdir_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import * as path from "../../path/mod"; 3 | import { assert } from "../../testing/asserts"; 4 | import { assertCallbackErrorUncaught } from "../_utils"; 5 | import { mkdir, mkdirSync } from "./_fs_mkdir"; 6 | import { existsSync } from "./_fs_exists"; 7 | 8 | const tmpDir = "./tmpdir"; 9 | 10 | Deno.test({ 11 | name: "[node/fs] mkdir", 12 | fn: async () => { 13 | const result = await new Promise((resolve) => { 14 | mkdir(tmpDir, (err) => { 15 | err && resolve(false); 16 | resolve(existsSync(tmpDir)); 17 | Deno.removeSync(tmpDir); 18 | }); 19 | }); 20 | assert(result); 21 | }, 22 | }); 23 | 24 | Deno.test({ 25 | name: "[node/fs] mkdirSync", 26 | fn: () => { 27 | mkdirSync(tmpDir); 28 | assert(existsSync(tmpDir)); 29 | Deno.removeSync(tmpDir); 30 | }, 31 | }); 32 | 33 | Deno.test("[std/node/fs] mkdir callback isn't called twice if error is thrown", async () => { 34 | const tempDir = await Deno.makeTempDir(); 35 | const subdir = path.join(tempDir, "subdir"); 36 | const importUrl = new URL("./_fs_mkdir.ts", import.meta.url); 37 | await assertCallbackErrorUncaught({ 38 | prelude: `import { mkdir } from ${JSON.stringify(importUrl)}`, 39 | invocation: `mkdir(${JSON.stringify(subdir)}, `, 40 | async cleanup() { 41 | await Deno.remove(tempDir, { recursive: true }); 42 | }, 43 | }); 44 | }); 45 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/_fs_realpath.ts: -------------------------------------------------------------------------------- 1 | type Options = { encoding: string }; 2 | type Callback = (err: Error | null, path?: string) => void; 3 | 4 | export function realpath( 5 | path: string, 6 | options?: Options | Callback, 7 | callback?: Callback, 8 | ) { 9 | if (typeof options === "function") { 10 | callback = options; 11 | } 12 | if (!callback) { 13 | throw new Error("No callback function supplied"); 14 | } 15 | Deno.realPath(path).then( 16 | (path) => callback!(null, path), 17 | (err) => callback!(err), 18 | ); 19 | } 20 | 21 | export function realpathSync(path: string): string { 22 | return Deno.realPathSync(path); 23 | } 24 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/_fs_rename.ts: -------------------------------------------------------------------------------- 1 | import { fromFileUrl } from "../path"; 2 | 3 | export function rename( 4 | oldPath: string | URL, 5 | newPath: string | URL, 6 | callback: (err?: Error) => void, 7 | ) { 8 | oldPath = oldPath instanceof URL ? fromFileUrl(oldPath) : oldPath; 9 | newPath = newPath instanceof URL ? fromFileUrl(newPath) : newPath; 10 | 11 | if (!callback) throw new Error("No callback function supplied"); 12 | 13 | Deno.rename(oldPath, newPath).then((_) => callback(), callback); 14 | } 15 | 16 | export function renameSync(oldPath: string | URL, newPath: string | URL) { 17 | oldPath = oldPath instanceof URL ? fromFileUrl(oldPath) : oldPath; 18 | newPath = newPath instanceof URL ? fromFileUrl(newPath) : newPath; 19 | 20 | Deno.renameSync(oldPath, newPath); 21 | } 22 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/_fs_rmdir.ts: -------------------------------------------------------------------------------- 1 | type rmdirOptions = { 2 | maxRetries?: number; 3 | recursive?: boolean; 4 | retryDelay?: number; 5 | }; 6 | 7 | type rmdirCallback = (err?: Error) => void; 8 | 9 | export function rmdir(path: string | URL, callback: rmdirCallback): void; 10 | export function rmdir( 11 | path: string | URL, 12 | options: rmdirOptions, 13 | callback: rmdirCallback, 14 | ): void; 15 | export function rmdir( 16 | path: string | URL, 17 | optionsOrCallback: rmdirOptions | rmdirCallback, 18 | maybeCallback?: rmdirCallback, 19 | ) { 20 | const callback = typeof optionsOrCallback === "function" 21 | ? optionsOrCallback 22 | : maybeCallback; 23 | const options = typeof optionsOrCallback === "object" 24 | ? optionsOrCallback 25 | : undefined; 26 | 27 | if (!callback) throw new Error("No callback function supplied"); 28 | 29 | Deno.remove(path, { recursive: options?.recursive }) 30 | .then((_) => callback(), callback); 31 | } 32 | 33 | export function rmdirSync(path: string | URL, options?: rmdirOptions) { 34 | Deno.removeSync(path, { recursive: options?.recursive }); 35 | } 36 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/_fs_symlink.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import { CallbackWithError } from "./_fs_common"; 3 | import { fromFileUrl } from "../path"; 4 | 5 | type SymlinkType = "file" | "dir"; 6 | 7 | export function symlink( 8 | target: string | URL, 9 | path: string | URL, 10 | typeOrCallback: SymlinkType | CallbackWithError, 11 | maybeCallback?: CallbackWithError, 12 | ) { 13 | target = target instanceof URL ? fromFileUrl(target) : target; 14 | path = path instanceof URL ? fromFileUrl(path) : path; 15 | 16 | const type: SymlinkType = typeof typeOrCallback === "string" 17 | ? typeOrCallback 18 | : "file"; 19 | 20 | const callback: CallbackWithError = typeof typeOrCallback === "function" 21 | ? typeOrCallback 22 | : (maybeCallback as CallbackWithError); 23 | 24 | if (!callback) throw new Error("No callback function supplied"); 25 | 26 | Deno.symlink(target, path, { type }).then(() => callback(null), callback); 27 | } 28 | 29 | export function symlinkSync( 30 | target: string | URL, 31 | path: string | URL, 32 | type?: SymlinkType, 33 | ) { 34 | target = target instanceof URL ? fromFileUrl(target) : target; 35 | path = path instanceof URL ? fromFileUrl(path) : path; 36 | type = type || "file"; 37 | 38 | Deno.symlinkSync(target, path, { type }); 39 | } 40 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/_fs_truncate.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import { CallbackWithError } from "./_fs_common"; 3 | import { fromFileUrl } from "../path"; 4 | 5 | export function truncate( 6 | path: string | URL, 7 | lenOrCallback: number | CallbackWithError, 8 | maybeCallback?: CallbackWithError, 9 | ) { 10 | path = path instanceof URL ? fromFileUrl(path) : path; 11 | const len: number | undefined = typeof lenOrCallback === "number" 12 | ? lenOrCallback 13 | : undefined; 14 | const callback: CallbackWithError = typeof lenOrCallback === "function" 15 | ? lenOrCallback 16 | : maybeCallback as CallbackWithError; 17 | 18 | if (!callback) throw new Error("No callback function supplied"); 19 | 20 | Deno.truncate(path, len).then(() => callback(null), callback); 21 | } 22 | 23 | export function truncateSync(path: string | URL, len?: number) { 24 | path = path instanceof URL ? fromFileUrl(path) : path; 25 | 26 | Deno.truncateSync(path, len); 27 | } 28 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/_fs_unlink.ts: -------------------------------------------------------------------------------- 1 | export function unlink(path: string | URL, callback: (err?: Error) => void) { 2 | if (!callback) throw new Error("No callback function supplied"); 3 | Deno.remove(path).then((_) => callback(), callback); 4 | } 5 | 6 | export function unlinkSync(path: string | URL) { 7 | Deno.removeSync(path); 8 | } 9 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/_fs_unlink_test.ts: -------------------------------------------------------------------------------- 1 | import { assertEquals, fail } from "../../testing/asserts"; 2 | import { existsSync } from "../../fs/exists"; 3 | import { assertCallbackErrorUncaught } from "../_utils"; 4 | import { unlink, unlinkSync } from "./_fs_unlink"; 5 | 6 | Deno.test({ 7 | name: "ASYNC: deleting a file", 8 | async fn() { 9 | const file = Deno.makeTempFileSync(); 10 | await new Promise((resolve, reject) => { 11 | unlink(file, (err) => { 12 | if (err) reject(err); 13 | resolve(); 14 | }); 15 | }) 16 | .then(() => assertEquals(existsSync(file), false), () => fail()) 17 | .finally(() => { 18 | if (existsSync(file)) Deno.removeSync(file); 19 | }); 20 | }, 21 | }); 22 | 23 | Deno.test({ 24 | name: "SYNC: Test deleting a file", 25 | fn() { 26 | const file = Deno.makeTempFileSync(); 27 | unlinkSync(file); 28 | assertEquals(existsSync(file), false); 29 | }, 30 | }); 31 | 32 | Deno.test("[std/node/fs] unlink callback isn't called twice if error is thrown", async () => { 33 | const tempFile = await Deno.makeTempFile(); 34 | const importUrl = new URL("./_fs_unlink.ts", import.meta.url); 35 | await assertCallbackErrorUncaught({ 36 | prelude: `import { unlink } from ${JSON.stringify(importUrl)}`, 37 | invocation: `unlink(${JSON.stringify(tempFile)}, `, 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/_fs_utimes.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import type { CallbackWithError } from "./_fs_common"; 3 | import { fromFileUrl } from "../path"; 4 | 5 | function getValidTime( 6 | time: number | string | Date, 7 | name: string, 8 | ): number | Date { 9 | if (typeof time === "string") { 10 | time = Number(time); 11 | } 12 | 13 | if ( 14 | typeof time === "number" && 15 | (Number.isNaN(time) || !Number.isFinite(time)) 16 | ) { 17 | throw new Deno.errors.InvalidData( 18 | `invalid ${name}, must not be infitiny or NaN`, 19 | ); 20 | } 21 | 22 | return time; 23 | } 24 | 25 | export function utimes( 26 | path: string | URL, 27 | atime: number | string | Date, 28 | mtime: number | string | Date, 29 | callback: CallbackWithError, 30 | ): void { 31 | path = path instanceof URL ? fromFileUrl(path) : path; 32 | 33 | if (!callback) { 34 | throw new Deno.errors.InvalidData("No callback function supplied"); 35 | } 36 | 37 | atime = getValidTime(atime, "atime"); 38 | mtime = getValidTime(mtime, "mtime"); 39 | 40 | Deno.utime(path, atime, mtime).then(() => callback(null), callback); 41 | } 42 | 43 | export function utimesSync( 44 | path: string | URL, 45 | atime: number | string | Date, 46 | mtime: number | string | Date, 47 | ): void { 48 | path = path instanceof URL ? fromFileUrl(path) : path; 49 | atime = getValidTime(atime, "atime"); 50 | mtime = getValidTime(mtime, "mtime"); 51 | 52 | Deno.utimeSync(path, atime, mtime); 53 | } 54 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/_fs_watch_test.ts: -------------------------------------------------------------------------------- 1 | import { watch } from "./_fs_watch"; 2 | import { assertEquals } from "../../testing/asserts"; 3 | 4 | function wait(time: number) { 5 | return new Promise((resolve) => { 6 | setTimeout(resolve, time); 7 | }); 8 | } 9 | 10 | Deno.test({ 11 | name: "watching a file", 12 | async fn() { 13 | const file = Deno.makeTempFileSync(); 14 | const result: Array<[string, string]> = []; 15 | const watcher = watch( 16 | file, 17 | (eventType, filename) => result.push([eventType, filename]), 18 | ); 19 | await wait(100); 20 | Deno.writeTextFileSync(file, "something"); 21 | await wait(100); 22 | watcher.close(); 23 | await wait(100); 24 | assertEquals(result.length >= 1, true); 25 | }, 26 | }); 27 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/promises/_fs_readFile.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import type { 3 | BinaryOptionsArgument, 4 | FileOptionsArgument, 5 | TextOptionsArgument, 6 | } from "../_fs_common"; 7 | import { readFile as readFileCallback } from "../_fs_readFile"; 8 | 9 | export function readFile( 10 | path: string | URL, 11 | options: TextOptionsArgument, 12 | ): Promise; 13 | export function readFile( 14 | path: string | URL, 15 | options?: BinaryOptionsArgument, 16 | ): Promise; 17 | export function readFile( 18 | path: string | URL, 19 | options?: FileOptionsArgument, 20 | ): Promise { 21 | return new Promise((resolve, reject) => { 22 | readFileCallback(path, options, (err, data): void => { 23 | if (err) return reject(err); 24 | if (data == null) { 25 | return reject(new Error("Invalid state: data missing, but no error")); 26 | } 27 | resolve(data); 28 | }); 29 | }); 30 | } 31 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/promises/_fs_writeFile.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import type { WriteFileOptions } from "../_fs_common"; 3 | import type { Encodings } from "../../_utils"; 4 | 5 | import { writeFile as writeFileCallback } from "../_fs_writeFile"; 6 | 7 | export function writeFile( 8 | pathOrRid: string | number | URL, 9 | data: string | Uint8Array, 10 | options?: Encodings | WriteFileOptions, 11 | ): Promise { 12 | return new Promise((resolve, reject) => { 13 | writeFileCallback(pathOrRid, data, options, (err?: Error | null) => { 14 | if (err) return reject(err); 15 | resolve(); 16 | }); 17 | }); 18 | } 19 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/promises/mod.ts: -------------------------------------------------------------------------------- 1 | export { writeFile } from "./_fs_writeFile"; 2 | export { readFile } from "./_fs_readFile"; 3 | -------------------------------------------------------------------------------- /ts/lib/std/node/_fs/testdata/hello.txt: -------------------------------------------------------------------------------- 1 | hello world -------------------------------------------------------------------------------- /ts/lib/std/node/_module/cjs/cjs_a.js: -------------------------------------------------------------------------------- 1 | // deno-lint-ignore-file no-undef 2 | // deno-lint-ignore-file 3 | const { helloB } = require("./cjs_b.js"); 4 | const C = require("./subdir/cjs_c"); 5 | const leftPad = require("left-pad"); 6 | 7 | function helloA() { 8 | return "A"; 9 | } 10 | 11 | module.exports = { helloA, helloB, C, leftPad }; 12 | -------------------------------------------------------------------------------- /ts/lib/std/node/_module/cjs/cjs_b.js: -------------------------------------------------------------------------------- 1 | function helloB() { 2 | return "B"; 3 | } 4 | 5 | // deno-lint-ignore no-undef 6 | module.exports = { helloB }; 7 | -------------------------------------------------------------------------------- /ts/lib/std/node/_module/cjs/cjs_builtin.js: -------------------------------------------------------------------------------- 1 | // deno-lint-ignore-file no-undef 2 | // deno-lint-ignore-file 3 | const fs = require("fs"); 4 | const util = require("util"); 5 | const path = require("path"); 6 | 7 | module.exports = { 8 | readFileSync: fs.readFileSync, 9 | isNull: util.isNull, 10 | extname: path.extname, 11 | }; 12 | -------------------------------------------------------------------------------- /ts/lib/std/node/_module/cjs/cjs_conditional_exports.js: -------------------------------------------------------------------------------- 1 | // deno-lint-ignore no-undef 2 | module.exports = require("colorette"); 3 | -------------------------------------------------------------------------------- /ts/lib/std/node/_module/cjs/cjs_cycle_a.js: -------------------------------------------------------------------------------- 1 | // deno-lint-ignore-file no-undef 2 | module.exports = false; 3 | require("./cjs_cycle_a"); 4 | module.exports = true; 5 | -------------------------------------------------------------------------------- /ts/lib/std/node/_module/cjs/cjs_cycle_b.js: -------------------------------------------------------------------------------- 1 | // deno-lint-ignore-file no-undef 2 | module.exports = false; 3 | require("./cjs_cycle_b"); 4 | module.exports = true; 5 | -------------------------------------------------------------------------------- /ts/lib/std/node/_module/cjs/cjs_throw.js: -------------------------------------------------------------------------------- 1 | function hello() { 2 | throw new Error("bye"); 3 | } 4 | 5 | // deno-lint-ignore no-undef 6 | module.exports = { hello }; 7 | -------------------------------------------------------------------------------- /ts/lib/std/node/_module/cjs/dir: -------------------------------------------------------------------------------- 1 | ./subdir/dir -------------------------------------------------------------------------------- /ts/lib/std/node/_module/cjs/index.js: -------------------------------------------------------------------------------- 1 | // deno-lint-ignore no-undef 2 | module.exports = { isIndex: true }; 3 | -------------------------------------------------------------------------------- /ts/lib/std/node/_module/cjs/subdir/cjs_c.js: -------------------------------------------------------------------------------- 1 | // deno-lint-ignore no-undef 2 | module.exports = "C"; 3 | -------------------------------------------------------------------------------- /ts/lib/std/node/_module/cjs/subdir/dir/index.js: -------------------------------------------------------------------------------- 1 | // deno-lint-ignore-file no-undef 2 | const C = require("../cjs_c"); 3 | 4 | module.exports = { C }; 5 | -------------------------------------------------------------------------------- /ts/lib/std/node/_module/example.js: -------------------------------------------------------------------------------- 1 | // deno-lint-ignore no-undef 2 | const leftPad = require("left-pad"); 3 | console.log(leftPad("foo", 5)); // => " foo" 4 | -------------------------------------------------------------------------------- /ts/lib/std/node/_module/node_modules/colorette/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": { 3 | "name": "Jorge Bucaran" 4 | }, 5 | "description": "Color your terminal using pure idiomatic JavaScript.", 6 | "exports": { 7 | "./package.json": "./package.json", 8 | ".": { 9 | "require": "./index.cjs", 10 | "import": "./index.js" 11 | } 12 | }, 13 | "license": "MIT", 14 | "main": "index.cjs", 15 | "module": "index.js", 16 | "name": "colorette", 17 | "repository": { 18 | "type": "git", 19 | "url": "git+https://github.com/jorgebucaran/colorette.git" 20 | }, 21 | "type": "module", 22 | "version": "1.2.1" 23 | } 24 | -------------------------------------------------------------------------------- /ts/lib/std/node/_module/node_modules/left-pad/README.md: -------------------------------------------------------------------------------- 1 | ## left-pad 2 | 3 | String left pad 4 | 5 | [![Build Status][travis-image]][travis-url] 6 | 7 | ## Install 8 | 9 | ```bash 10 | $ npm install left-pad 11 | ``` 12 | 13 | ## Usage 14 | 15 | ```js 16 | const leftPad = require("left-pad"); 17 | 18 | leftPad("foo", 5); 19 | // => " foo" 20 | 21 | leftPad("foobar", 6); 22 | // => "foobar" 23 | 24 | leftPad(1, 2, "0"); 25 | // => "01" 26 | 27 | leftPad(17, 5, 0); 28 | // => "00017" 29 | ``` 30 | 31 | **NOTE:** The third argument should be a single `char`. However the module 32 | doesn't throw an error if you supply more than one `char`s. See 33 | [#28](https://github.com/stevemao/left-pad/pull/28). 34 | 35 | **NOTE:** Characters having code points outside of 36 | [BMP plan](https://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_Multilingual_Plane) 37 | are considered a two distinct characters. See 38 | [#58](https://github.com/stevemao/left-pad/issues/58). 39 | 40 | [travis-image]: https://travis-ci.org/stevemao/left-pad.svg?branch=master 41 | [travis-url]: https://travis-ci.org/stevemao/left-pad 42 | -------------------------------------------------------------------------------- /ts/lib/std/node/_module/node_modules/left-pad/index.js: -------------------------------------------------------------------------------- 1 | // deno-lint-ignore-file 2 | 3 | /* This program is free software. It comes without any warranty, to 4 | * the extent permitted by applicable law. You can redistribute it 5 | * and/or modify it under the terms of the Do What The Fuck You Want 6 | * To Public License, Version 2, as published by Sam Hocevar. See 7 | * http://www.wtfpl.net/ for more details. */ 8 | "use strict"; 9 | module.exports = leftPad; 10 | 11 | var cache = [ 12 | "", 13 | " ", 14 | " ", 15 | " ", 16 | " ", 17 | " ", 18 | " ", 19 | " ", 20 | " ", 21 | " ", 22 | ]; 23 | 24 | function leftPad(str, len, ch) { 25 | // convert `str` to a `string` 26 | str = str + ""; 27 | // `len` is the `pad`'s length now 28 | len = len - str.length; 29 | // doesn't need to pad 30 | if (len <= 0) return str; 31 | // `ch` defaults to `' '` 32 | if (!ch && ch !== 0) ch = " "; 33 | // convert `ch` to a `string` cuz it could be a number 34 | ch = ch + ""; 35 | // cache common use cases 36 | if (ch === " " && len < 10) return cache[len] + str; 37 | // `pad` starts with an empty string 38 | var pad = ""; 39 | // loop 40 | while (true) { 41 | // add `ch` to `pad` if `len` is odd 42 | if (len & 1) pad += ch; 43 | // divide `len` by 2, ditch the remainder 44 | len >>= 1; 45 | // "double" the `ch` so this operation count grows logarithmically on `len` 46 | // each time `ch` is "doubled", the `len` would need to be "doubled" too 47 | // similar to finding a value in binary search tree, hence O(log(n)) 48 | if (len) ch += ch; 49 | // `len` is 0, exit the loop 50 | else break; 51 | } 52 | // pad `str`! 53 | return pad + str; 54 | } 55 | -------------------------------------------------------------------------------- /ts/lib/std/node/_module/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "deno_std_node", 3 | "version": "0.0.1", 4 | "description": "", 5 | "main": "index.js", 6 | "dependencies": { 7 | "colorette": "1.2.1", 8 | "left-pad": "1.3.0" 9 | }, 10 | "devDependencies": {}, 11 | "scripts": { 12 | "test": "echo \"Error: no test specified\" && exit 1" 13 | }, 14 | "author": "", 15 | "license": "ISC" 16 | } 17 | -------------------------------------------------------------------------------- /ts/lib/std/node/_stream/destroy.ts: -------------------------------------------------------------------------------- 1 | // Copyright Node.js contributors. All rights reserved. MIT License. 2 | import type Duplex from "./duplex"; 3 | import type Readable from "./readable"; 4 | import type Stream from "./stream"; 5 | import type Writable from "./writable"; 6 | 7 | //This whole module acts as a 'normalizer' 8 | //Idea behind it is you can pass any kind of streams and functions will execute anyways 9 | 10 | //TODO(Soremwar) 11 | //Should be any implementation of stream 12 | //This is a guard to check executed methods exist inside the implementation 13 | type StreamImplementations = Duplex | Readable | Writable; 14 | 15 | // TODO(Soremwar) 16 | // Bring back once requests are implemented 17 | // function isRequest(stream: any) { 18 | // return stream && stream.setHeader && typeof stream.abort === "function"; 19 | // } 20 | 21 | export function destroyer(stream: Stream, err?: Error | null) { 22 | // TODO(Soremwar) 23 | // Bring back once requests are implemented 24 | // if (isRequest(stream)) return stream.abort(); 25 | // if (isRequest(stream.req)) return stream.req.abort(); 26 | if ( 27 | typeof (stream as StreamImplementations).destroy === "function" 28 | ) { 29 | return (stream as StreamImplementations).destroy(err); 30 | } 31 | // A test of async iterator mocks an upcoming implementation of stream 32 | // his is casted to any in the meanwhile 33 | // deno-lint-ignore no-explicit-any 34 | if (typeof (stream as any).close === "function") { 35 | // deno-lint-ignore no-explicit-any 36 | return (stream as any).close(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /ts/lib/std/node/_stream/passthrough.ts: -------------------------------------------------------------------------------- 1 | // Copyright Node.js contributors. All rights reserved. MIT License. 2 | import Transform from "./transform"; 3 | import type { TransformOptions } from "./transform"; 4 | import type { Encodings } from "../_utils"; 5 | 6 | export default class PassThrough extends Transform { 7 | constructor(options?: TransformOptions) { 8 | super(options); 9 | } 10 | 11 | _transform( 12 | // deno-lint-ignore no-explicit-any 13 | chunk: any, 14 | _encoding: Encodings, 15 | // deno-lint-ignore no-explicit-any 16 | cb: (error?: Error | null, data?: any) => void, 17 | ) { 18 | cb(null, chunk); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ts/lib/std/node/_stream/promises.ts: -------------------------------------------------------------------------------- 1 | // Copyright Node.js contributors. All rights reserved. MIT License. 2 | import pl from "./pipeline"; 3 | import type { PipelineArguments } from "./pipeline"; 4 | import eos from "./end_of_stream"; 5 | import type { 6 | FinishedOptions, 7 | StreamImplementations as FinishedStreams, 8 | } from "./end_of_stream"; 9 | 10 | export function pipeline(...streams: PipelineArguments) { 11 | return new Promise((resolve, reject) => { 12 | pl( 13 | ...streams, 14 | (err, value) => { 15 | if (err) { 16 | reject(err); 17 | } else { 18 | resolve(value); 19 | } 20 | }, 21 | ); 22 | }); 23 | } 24 | 25 | export function finished( 26 | stream: FinishedStreams, 27 | opts?: FinishedOptions, 28 | ) { 29 | return new Promise((resolve, reject) => { 30 | eos( 31 | stream, 32 | opts || null, 33 | (err) => { 34 | if (err) { 35 | reject(err); 36 | } else { 37 | resolve(); 38 | } 39 | }, 40 | ); 41 | }); 42 | } 43 | -------------------------------------------------------------------------------- /ts/lib/std/node/_stream/symbols.ts: -------------------------------------------------------------------------------- 1 | // Copyright Node.js contributors. All rights reserved. MIT License. 2 | export const kConstruct = Symbol("kConstruct"); 3 | export const kDestroy = Symbol("kDestroy"); 4 | export const kPaused = Symbol("kPaused"); 5 | -------------------------------------------------------------------------------- /ts/lib/std/node/_tools/.gitignore: -------------------------------------------------------------------------------- 1 | versions -------------------------------------------------------------------------------- /ts/lib/std/node/_tools/common.ts: -------------------------------------------------------------------------------- 1 | import { join } from "../../path/mod"; 2 | 3 | /** 4 | * The test suite matches the folders inside the `test` folder inside the 5 | * node repo 6 | * 7 | * Each test suite contains a list of files (which can be paths 8 | * or a regex to match) that will be pulled from the node repo 9 | */ 10 | type TestSuites = Record; 11 | 12 | interface Config { 13 | nodeVersion: string; 14 | /** Ignored files won't regenerated by the update script */ 15 | ignore: TestSuites; 16 | /** 17 | * The files that will be run by the test suite 18 | * 19 | * The files to be generated with the update script must be listed here as well, 20 | * but they won't be regenerated if they are listed in the `ignore` configuration 21 | * */ 22 | tests: TestSuites; 23 | suitesFolder: string; 24 | versionsFolder: string; 25 | } 26 | 27 | export const config: Config = JSON.parse( 28 | await Deno.readTextFile(new URL("./config.json", import.meta.url)), 29 | ); 30 | 31 | export const ignoreList = Object.entries(config.ignore).reduce( 32 | (total: RegExp[], [suite, paths]) => { 33 | paths.forEach((path) => total.push(new RegExp(join(suite, path)))); 34 | return total; 35 | }, 36 | [], 37 | ); 38 | 39 | export const testList = Object.entries(config.tests).reduce( 40 | (total: RegExp[], [suite, paths]) => { 41 | paths.forEach((path) => total.push(new RegExp(join(suite, path)))); 42 | return total; 43 | }, 44 | [], 45 | ); 46 | -------------------------------------------------------------------------------- /ts/lib/std/node/_tools/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "nodeVersion": "15.5.1", 3 | "ignore": { 4 | "common": [ 5 | "index.js" 6 | ] 7 | }, 8 | "tests": { 9 | "parallel": [ 10 | "test-assert.js", 11 | "test-assert-async.js", 12 | "test-assert-fail.js", 13 | "test-event-emitter-invalid-listener.js", 14 | "test-event-emitter-listener-count.js" 15 | ] 16 | }, 17 | "suitesFolder": "suites", 18 | "versionsFolder": "versions" 19 | } 20 | -------------------------------------------------------------------------------- /ts/lib/std/node/_tools/require.ts: -------------------------------------------------------------------------------- 1 | import { createRequire } from "../module"; 2 | import { isAbsolute } from "../../path/mod"; 3 | 4 | /** 5 | * This module is used as an entry point for each test file 6 | * 7 | * The idea is to emulate a CommonJS environment without having to modify 8 | * the test files in any way 9 | * 10 | * Running with all permissions and unstable is recommended 11 | * 12 | * Usage: `deno run -A --unstable require.ts my_commonjs_file.js` 13 | */ 14 | 15 | const file = Deno.args[0]; 16 | if (!file) { 17 | throw new Error("No file provided"); 18 | } else if (!isAbsolute(file)) { 19 | throw new Error("Path for file must be absolute"); 20 | } 21 | 22 | const require = createRequire(file); 23 | require(file); 24 | -------------------------------------------------------------------------------- /ts/lib/std/node/_tools/suites/parallel/test-assert-fail.js: -------------------------------------------------------------------------------- 1 | // deno-fmt-ignore-file 2 | // deno-lint-ignore-file 3 | 4 | // Copyright Joyent and Node contributors. All rights reserved. MIT license. 5 | // Taken from Node 15.5.1 6 | // This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually 7 | 8 | 'use strict'; 9 | 10 | require('../common'); 11 | const assert = require('assert'); 12 | 13 | // No args 14 | assert.throws( 15 | () => { assert.fail(); }, 16 | { 17 | code: 'ERR_ASSERTION', 18 | name: 'AssertionError', 19 | message: 'Failed', 20 | operator: 'fail', 21 | actual: undefined, 22 | expected: undefined, 23 | generatedMessage: true, 24 | stack: /Failed/ 25 | } 26 | ); 27 | 28 | // One arg = message 29 | assert.throws(() => { 30 | assert.fail('custom message'); 31 | }, { 32 | code: 'ERR_ASSERTION', 33 | name: 'AssertionError', 34 | message: 'custom message', 35 | operator: 'fail', 36 | actual: undefined, 37 | expected: undefined, 38 | generatedMessage: false 39 | }); 40 | 41 | // One arg = Error 42 | assert.throws(() => { 43 | assert.fail(new TypeError('custom message')); 44 | }, { 45 | name: 'TypeError', 46 | message: 'custom message' 47 | }); 48 | -------------------------------------------------------------------------------- /ts/lib/std/node/_tools/suites/parallel/test-event-emitter-invalid-listener.js: -------------------------------------------------------------------------------- 1 | // deno-fmt-ignore-file 2 | // deno-lint-ignore-file 3 | 4 | // Copyright Joyent and Node contributors. All rights reserved. MIT license. 5 | // Taken from Node 15.5.1 6 | // This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually 7 | 8 | 'use strict'; 9 | 10 | require('../common'); 11 | const assert = require('assert'); 12 | const EventEmitter = require('events'); 13 | 14 | const eventsMethods = ['on', 'once', 'removeListener', 'prependOnceListener']; 15 | 16 | // Verify that the listener must be a function for events methods 17 | for (const method of eventsMethods) { 18 | assert.throws(() => { 19 | const ee = new EventEmitter(); 20 | ee[method]('foo', null); 21 | }, { 22 | code: 'ERR_INVALID_ARG_TYPE', 23 | name: 'TypeError', 24 | message: 'The "listener" argument must be of type function. ' + 25 | 'Received null' 26 | }, `event.${method}('foo', null) should throw the proper error`); 27 | } 28 | -------------------------------------------------------------------------------- /ts/lib/std/node/_tools/suites/parallel/test-event-emitter-listener-count.js: -------------------------------------------------------------------------------- 1 | // deno-fmt-ignore-file 2 | // deno-lint-ignore-file 3 | 4 | // Copyright Joyent and Node contributors. All rights reserved. MIT license. 5 | // Taken from Node 15.5.1 6 | // This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually 7 | 8 | 'use strict'; 9 | 10 | require('../common'); 11 | const assert = require('assert'); 12 | const EventEmitter = require('events'); 13 | 14 | const emitter = new EventEmitter(); 15 | emitter.on('foo', () => {}); 16 | emitter.on('foo', () => {}); 17 | emitter.on('baz', () => {}); 18 | // Allow any type 19 | emitter.on(123, () => {}); 20 | 21 | assert.strictEqual(EventEmitter.listenerCount(emitter, 'foo'), 2); 22 | assert.strictEqual(emitter.listenerCount('foo'), 2); 23 | assert.strictEqual(emitter.listenerCount('bar'), 0); 24 | assert.strictEqual(emitter.listenerCount('baz'), 1); 25 | assert.strictEqual(emitter.listenerCount(123), 1); 26 | -------------------------------------------------------------------------------- /ts/lib/std/node/cli_test.ts: -------------------------------------------------------------------------------- 1 | import { assert, assertEquals } from "../testing/asserts"; 2 | import { dirname, fromFileUrl } from "../path/mod"; 3 | 4 | /** The utility for running "node/main.ts" with the given args */ 5 | async function runNodeMain(...args: string[]) { 6 | const p = Deno.run({ 7 | cmd: [ 8 | Deno.execPath(), 9 | "run", 10 | "--allow-read", 11 | "--unstable", 12 | "cli.ts", 13 | ...args, 14 | ], 15 | stdout: "piped", 16 | stderr: "piped", 17 | cwd: dirname(fromFileUrl(new URL(import.meta.url))), 18 | }); 19 | 20 | const [status, output, stderrOutput] = await Promise.all([ 21 | p.status(), 22 | p.output(), 23 | p.stderrOutput(), 24 | ]); 25 | 26 | const decoder = new TextDecoder(); 27 | 28 | p.close(); 29 | 30 | return { 31 | status, 32 | output: decoder.decode(output), 33 | stderrOutput: decoder.decode(stderrOutput), 34 | }; 35 | } 36 | 37 | Deno.test("[node/main] run node.js script", async () => { 38 | const { status, output } = await runNodeMain("_module/example.js"); 39 | assertEquals(status.code, 0); 40 | assertEquals(output, " foo\n"); 41 | }); 42 | 43 | Deno.test("[node/main] --help", async () => { 44 | const { status, output } = await runNodeMain("--help"); 45 | assertEquals(status.code, 0); 46 | assert(output.includes("Usage:")); 47 | }); 48 | 49 | Deno.test("[node/main] exec with no arg", async () => { 50 | const { status, output } = await runNodeMain(); 51 | assertEquals(status.code, 1); // Error 52 | assert(output.includes("Usage:")); // Shows the usage 53 | }); 54 | -------------------------------------------------------------------------------- /ts/lib/std/node/console.ts: -------------------------------------------------------------------------------- 1 | export default console; 2 | 3 | export const { 4 | assert, 5 | clear, 6 | count, 7 | countReset, 8 | debug, 9 | dir, 10 | dirxml, 11 | error, 12 | group, 13 | groupCollapsed, 14 | groupEnd, 15 | info, 16 | log, 17 | table, 18 | time, 19 | timeEnd, 20 | timeLog, 21 | trace, 22 | warn, 23 | } = console; 24 | -------------------------------------------------------------------------------- /ts/lib/std/node/constants.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | 3 | // Based on: https://github.com/nodejs/node/blob/0646eda/lib/constants.js 4 | 5 | import { constants as fsConstants } from "./fs"; 6 | import { constants as osConstants } from "./os"; 7 | 8 | export default { 9 | ...fsConstants, 10 | ...osConstants.dlopen, 11 | ...osConstants.errno, 12 | ...osConstants.signals, 13 | ...osConstants.priority, 14 | }; 15 | -------------------------------------------------------------------------------- /ts/lib/std/node/global.d.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import processModule from "./process"; 3 | import { Buffer as bufferModule } from "./buffer"; 4 | import timers from "./timers"; 5 | 6 | // d.ts files allow us to declare Buffer as a value and as a type 7 | // type something = Buffer | something_else; is quite common 8 | 9 | type GlobalType = { 10 | process: typeof processModule; 11 | Buffer: typeof bufferModule; 12 | setImmediate: typeof timers.setImmediate; 13 | clearImmediate: typeof timers.clearImmediate; 14 | }; 15 | 16 | declare global { 17 | interface Window { 18 | global: GlobalType; 19 | } 20 | 21 | interface globalThis { 22 | global: GlobalType; 23 | } 24 | 25 | var global: GlobalType; 26 | var process: typeof processModule; 27 | var Buffer: typeof bufferModule; 28 | type Buffer = bufferModule; 29 | var setImmediate: typeof timers.setImmediate; 30 | var clearImmediate: typeof timers.clearImmediate; 31 | } 32 | 33 | export {}; 34 | -------------------------------------------------------------------------------- /ts/lib/std/node/global.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | /// 3 | import processModule from "./process"; 4 | import { Buffer as bufferModule } from "./buffer"; 5 | import timers from "./timers"; 6 | 7 | Object.defineProperty(globalThis, "global", { 8 | value: globalThis, 9 | writable: false, 10 | enumerable: false, 11 | configurable: true, 12 | }); 13 | 14 | Object.defineProperty(globalThis, "process", { 15 | value: processModule, 16 | enumerable: false, 17 | writable: true, 18 | configurable: true, 19 | }); 20 | 21 | Object.defineProperty(globalThis, "Buffer", { 22 | value: bufferModule, 23 | enumerable: false, 24 | writable: true, 25 | configurable: true, 26 | }); 27 | 28 | Object.defineProperty(globalThis, "setImmediate", { 29 | value: timers.setImmediate, 30 | enumerable: true, 31 | writable: true, 32 | configurable: true, 33 | }); 34 | 35 | Object.defineProperty(globalThis, "clearImmediate", { 36 | value: timers.clearImmediate, 37 | enumerable: true, 38 | writable: true, 39 | configurable: true, 40 | }); 41 | 42 | export {}; 43 | -------------------------------------------------------------------------------- /ts/lib/std/node/path.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | export * from "../path/mod"; 3 | import * as m from "../path/mod"; 4 | export default { ...m }; 5 | -------------------------------------------------------------------------------- /ts/lib/std/node/querystring_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import { assertEquals } from "../testing/asserts"; 3 | import { parse, stringify } from "./querystring"; 4 | 5 | Deno.test({ 6 | name: "stringify", 7 | fn() { 8 | assertEquals( 9 | stringify({ 10 | a: "hello", 11 | b: 5, 12 | c: true, 13 | d: ["foo", "bar"], 14 | }), 15 | "a=hello&b=5&c=true&d=foo&d=bar", 16 | ); 17 | }, 18 | }); 19 | 20 | Deno.test({ 21 | name: "parse", 22 | fn() { 23 | assertEquals(parse("a=hello&b=5&c=true&d=foo&d=bar"), { 24 | a: "hello", 25 | b: "5", 26 | c: "true", 27 | d: ["foo", "bar"], 28 | }); 29 | }, 30 | }); 31 | -------------------------------------------------------------------------------- /ts/lib/std/node/testdata/process_exit.ts: -------------------------------------------------------------------------------- 1 | import "../global"; 2 | 3 | //deno-lint-ignore no-undef 4 | process.on("exit", () => { 5 | console.log(1); 6 | }); 7 | 8 | function unexpected() { 9 | console.log(null); 10 | } 11 | //deno-lint-ignore no-undef 12 | process.on("exit", unexpected); 13 | //deno-lint-ignore no-undef 14 | process.removeListener("exit", unexpected); 15 | 16 | //deno-lint-ignore no-undef 17 | process.on("exit", () => { 18 | console.log(2); 19 | }); 20 | -------------------------------------------------------------------------------- /ts/lib/std/node/testdata/shebang.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | console.log(42); 3 | -------------------------------------------------------------------------------- /ts/lib/std/node/timers.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | // TODO(bartlomieju): implement the 'NodeJS.Timeout' and 'NodeJS.Immediate' versions of the timers. 3 | // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/1163ead296d84e7a3c80d71e7c81ecbd1a130e9a/types/node/v12/globals.d.ts#L1120-L1131 4 | export const setTimeout = globalThis.setTimeout; 5 | export const clearTimeout = globalThis.clearTimeout; 6 | export const setInterval = globalThis.setInterval; 7 | export const clearInterval = globalThis.clearInterval; 8 | export const setImmediate = ( 9 | // deno-lint-ignore no-explicit-any 10 | cb: (...args: any[]) => void, 11 | // deno-lint-ignore no-explicit-any 12 | ...args: any[] 13 | ): number => globalThis.setTimeout(cb, 0, ...args); 14 | export const clearImmediate = globalThis.clearTimeout; 15 | 16 | export default { 17 | setTimeout, 18 | clearTimeout, 19 | setInterval, 20 | clearInterval, 21 | setImmediate, 22 | clearImmediate, 23 | }; 24 | -------------------------------------------------------------------------------- /ts/lib/std/node/tty.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | 3 | // This module implements 'tty' module of Node.JS API. 4 | // ref: https://nodejs.org/api/tty.html 5 | 6 | // Returns true when the given numeric fd is associated with a TTY and false otherwise. 7 | function isatty(fd: number) { 8 | if (typeof fd !== "number") { 9 | return false; 10 | } 11 | try { 12 | return Deno.isatty(fd); 13 | } catch (_) { 14 | return false; 15 | } 16 | } 17 | 18 | // TODO(kt3k): Implement tty.ReadStream class 19 | // TODO(kt3k): Implement tty.WriteStream class 20 | 21 | export { isatty }; 22 | export default { isatty }; 23 | -------------------------------------------------------------------------------- /ts/lib/std/node/tty_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | // deno-lint-ignore-file no-explicit-any 3 | import { assert } from "../testing/asserts"; 4 | import { isatty } from "./tty"; 5 | 6 | Deno.test("[node/tty isatty] returns true when fd is a tty, false otherwise", () => { 7 | assert(Deno.isatty(Deno.stdin.rid) === isatty(Deno.stdin.rid)); 8 | assert(Deno.isatty(Deno.stdout.rid) === isatty(Deno.stdout.rid)); 9 | assert(Deno.isatty(Deno.stderr.rid) === isatty(Deno.stderr.rid)); 10 | 11 | const file = Deno.openSync("README.md"); 12 | assert(!isatty(file.rid)); 13 | Deno.close(file.rid); 14 | }); 15 | 16 | Deno.test("[node/tty isatty] returns false for irrelevant values", () => { 17 | // invalid numeric fd 18 | assert(!isatty(1234567)); 19 | assert(!isatty(-1)); 20 | 21 | // invalid type fd 22 | assert(!isatty("abc" as any)); 23 | assert(!isatty({} as any)); 24 | assert(!isatty([] as any)); 25 | assert(!isatty(null as any)); 26 | assert(!isatty(undefined as any)); 27 | }); 28 | -------------------------------------------------------------------------------- /ts/lib/std/node/url_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import { assertEquals } from "../testing/asserts"; 3 | import * as url from "./url"; 4 | 5 | Deno.test({ 6 | name: "[url] URL", 7 | fn() { 8 | assertEquals(url.URL, URL); 9 | }, 10 | }); 11 | -------------------------------------------------------------------------------- /ts/lib/std/path/README.md: -------------------------------------------------------------------------------- 1 | # Deno Path Manipulation Libraries 2 | 3 | Usage: 4 | 5 | ```ts 6 | import * as path from "https://deno.land/std@$STD_VERSION/path/mod"; 7 | ``` 8 | 9 | ### globToRegExp 10 | 11 | Generate a regex based on glob pattern and options This was meant to be using 12 | the `fs.walk` function but can be used anywhere else. 13 | 14 | ```ts 15 | import { globToRegExp } from "https://deno.land/std@$STD_VERSION/path/glob"; 16 | 17 | globToRegExp("foo/**/*.json", { 18 | flags: "g", 19 | extended: true, 20 | globstar: true, 21 | caseInsensitive: false, 22 | }); // returns the regex to find all .json files in the folder foo. 23 | ``` 24 | -------------------------------------------------------------------------------- /ts/lib/std/path/_interface.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | // This module is browser compatible. 3 | 4 | /** 5 | * A parsed path object generated by path.parse() or consumed by path.format(). 6 | */ 7 | export interface ParsedPath { 8 | /** 9 | * The root of the path such as '/' or 'c:\' 10 | */ 11 | root: string; 12 | /** 13 | * The full directory path such as '/home/user/dir' or 'c:\path\dir' 14 | */ 15 | dir: string; 16 | /** 17 | * The file name including extension (if any) such as 'index.html' 18 | */ 19 | base: string; 20 | /** 21 | * The file extension (if any) such as '.html' 22 | */ 23 | ext: string; 24 | /** 25 | * The file name without extension (if any) such as 'index' 26 | */ 27 | name: string; 28 | } 29 | 30 | export type FormatInputPathObject = Partial; 31 | -------------------------------------------------------------------------------- /ts/lib/std/path/common.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | // This module is browser compatible. 3 | 4 | import { SEP } from "./separator"; 5 | 6 | /** Determines the common path from a set of paths, using an optional separator, 7 | * which defaults to the OS default separator. 8 | * 9 | * import { common } from "https://deno.land/std/path/mod"; 10 | * const p = common([ 11 | * "./deno/std/path/mod.ts", 12 | * "./deno/std/fs/mod.ts", 13 | * ]); 14 | * console.log(p); // "./deno/std/" 15 | * 16 | */ 17 | export function common(paths: string[], sep = SEP): string { 18 | const [first = "", ...remaining] = paths; 19 | if (first === "" || remaining.length === 0) { 20 | return first.substring(0, first.lastIndexOf(sep) + 1); 21 | } 22 | const parts = first.split(sep); 23 | 24 | let endOfPrefix = parts.length; 25 | for (const path of remaining) { 26 | const compare = path.split(sep); 27 | for (let i = 0; i < endOfPrefix; i++) { 28 | if (compare[i] !== parts[i]) { 29 | endOfPrefix = i; 30 | } 31 | } 32 | 33 | if (endOfPrefix === 0) { 34 | return ""; 35 | } 36 | } 37 | const prefix = parts.slice(0, endOfPrefix).join(sep); 38 | return prefix.endsWith(sep) ? prefix : `${prefix}${sep}`; 39 | } 40 | -------------------------------------------------------------------------------- /ts/lib/std/path/common_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import { assertEquals } from "../testing/asserts"; 3 | import { common } from "./mod"; 4 | 5 | Deno.test({ 6 | name: "path - common - basic usage", 7 | fn() { 8 | const actual = common( 9 | [ 10 | "file://deno/cli/js/deno.ts", 11 | "file://deno/std/path/mod.ts", 12 | "file://deno/cli/js/main.ts", 13 | ], 14 | "/", 15 | ); 16 | assertEquals(actual, "file://deno/"); 17 | }, 18 | }); 19 | 20 | Deno.test({ 21 | name: "path - common - no shared", 22 | fn() { 23 | const actual = common( 24 | ["file://deno/cli/js/deno.ts", "https://deno.land/std/path/mod.ts"], 25 | "/", 26 | ); 27 | assertEquals(actual, ""); 28 | }, 29 | }); 30 | 31 | Deno.test({ 32 | name: "path - common - windows sep", 33 | fn() { 34 | const actual = common( 35 | [ 36 | "c:\\deno\\cli\\js\\deno.ts", 37 | "c:\\deno\\std\\path\\mod.ts", 38 | "c:\\deno\\cli\\js\\main.ts", 39 | ], 40 | "\\", 41 | ); 42 | assertEquals(actual, "c:\\deno\\"); 43 | }, 44 | }); 45 | -------------------------------------------------------------------------------- /ts/lib/std/path/isabsolute_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright the Browserify authors. MIT License. 2 | // Ported from https://github.com/browserify/path-browserify/ 3 | import { assertEquals } from "../testing/asserts"; 4 | import * as path from "./mod"; 5 | 6 | Deno.test("isAbsolute", function () { 7 | assertEquals(path.posix.isAbsolute("/home/foo"), true); 8 | assertEquals(path.posix.isAbsolute("/home/foo/.."), true); 9 | assertEquals(path.posix.isAbsolute("bar/"), false); 10 | assertEquals(path.posix.isAbsolute("./baz"), false); 11 | }); 12 | 13 | Deno.test("isAbsoluteWin32", function () { 14 | assertEquals(path.win32.isAbsolute("/"), true); 15 | assertEquals(path.win32.isAbsolute("//"), true); 16 | assertEquals(path.win32.isAbsolute("//server"), true); 17 | assertEquals(path.win32.isAbsolute("//server/file"), true); 18 | assertEquals(path.win32.isAbsolute("\\\\server\\file"), true); 19 | assertEquals(path.win32.isAbsolute("\\\\server"), true); 20 | assertEquals(path.win32.isAbsolute("\\\\"), true); 21 | assertEquals(path.win32.isAbsolute("c"), false); 22 | assertEquals(path.win32.isAbsolute("c:"), false); 23 | assertEquals(path.win32.isAbsolute("c:\\"), true); 24 | assertEquals(path.win32.isAbsolute("c:/"), true); 25 | assertEquals(path.win32.isAbsolute("c://"), true); 26 | assertEquals(path.win32.isAbsolute("C:/Users/"), true); 27 | assertEquals(path.win32.isAbsolute("C:\\Users\\"), true); 28 | assertEquals(path.win32.isAbsolute("C:cwd/another"), false); 29 | assertEquals(path.win32.isAbsolute("C:cwd\\another"), false); 30 | assertEquals(path.win32.isAbsolute("directory/directory"), false); 31 | assertEquals(path.win32.isAbsolute("directory\\directory"), false); 32 | }); 33 | -------------------------------------------------------------------------------- /ts/lib/std/path/mod.ts: -------------------------------------------------------------------------------- 1 | // Copyright the Browserify authors. MIT License. 2 | // Ported mostly from https://github.com/browserify/path-browserify/ 3 | // This module is browser compatible. 4 | 5 | import { isWindows } from "../_util/os"; 6 | import * as _win32 from "./win32"; 7 | import * as _posix from "./posix"; 8 | 9 | const path = isWindows ? _win32 : _posix; 10 | 11 | export const win32 = _win32; 12 | export const posix = _posix; 13 | export const { 14 | basename, 15 | delimiter, 16 | dirname, 17 | extname, 18 | format, 19 | fromFileUrl, 20 | isAbsolute, 21 | join, 22 | normalize, 23 | parse, 24 | relative, 25 | resolve, 26 | sep, 27 | toFileUrl, 28 | toNamespacedPath, 29 | } = path; 30 | 31 | export * from "./common"; 32 | export { SEP, SEP_PATTERN } from "./separator"; 33 | export * from "./_interface"; 34 | export * from "./glob"; 35 | -------------------------------------------------------------------------------- /ts/lib/std/path/separator.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | // This module is browser compatible. 3 | 4 | import { isWindows } from "../_util/os"; 5 | 6 | export const SEP = isWindows ? "\\" : "/"; 7 | export const SEP_PATTERN = isWindows ? /[\\/]+/ : /\/+/; 8 | -------------------------------------------------------------------------------- /ts/lib/std/path/test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import "./mod"; 3 | -------------------------------------------------------------------------------- /ts/lib/std/permissions/test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import { grant, grantOrThrow } from "./mod"; 3 | import { assert, assertEquals } from "../testing/asserts"; 4 | 5 | Deno.test({ 6 | name: "grant basic", 7 | async fn() { 8 | assertEquals(await grant({ name: "net" }, { name: "env" }), [ 9 | { name: "net" }, 10 | { name: "env" }, 11 | ]); 12 | }, 13 | }); 14 | 15 | Deno.test({ 16 | name: "grant array", 17 | async fn() { 18 | assertEquals(await grant([{ name: "net" }, { name: "env" }]), [ 19 | { name: "net" }, 20 | { name: "env" }, 21 | ]); 22 | }, 23 | }); 24 | 25 | Deno.test({ 26 | name: "grant logic", 27 | async fn() { 28 | assert(await grant({ name: "net" })); 29 | }, 30 | }); 31 | 32 | Deno.test({ 33 | name: "grantOrThrow basic", 34 | async fn() { 35 | await grantOrThrow({ name: "net" }, { name: "env" }); 36 | }, 37 | }); 38 | 39 | Deno.test({ 40 | name: "grantOrThrow array", 41 | async fn() { 42 | await grantOrThrow([{ name: "net" }, { name: "env" }]); 43 | }, 44 | }); 45 | -------------------------------------------------------------------------------- /ts/lib/std/signal/README.md: -------------------------------------------------------------------------------- 1 | # signal 2 | 3 | signal is a module used to capture and monitor OS signals. 4 | 5 | # usage 6 | 7 | The following functions are exposed in `mod.ts`: 8 | 9 | ## signal 10 | 11 | Generates an AsyncIterable which can be awaited on for one or more signals. 12 | `dispose()` can be called when you are finished waiting on the events. 13 | 14 | ```typescript 15 | import { signal } from "https://deno.land/std/signal/mod"; 16 | const sig = signal(Deno.Signal.SIGUSR1, Deno.Signal.SIGINT); 17 | setTimeout(() => {}, 5000); // Prevents exiting immediately. 18 | 19 | for await (const _ of sig) { 20 | // .. 21 | } 22 | 23 | // At some other point in your code when finished listening: 24 | sig.dispose(); 25 | ``` 26 | 27 | ## onSignal 28 | 29 | Registers a callback function to be called on triggering of a signal event. 30 | 31 | ```typescript 32 | import { onSignal } from "https://deno.land/std/signal/mod"; 33 | 34 | const handle = onSignal(Deno.Signal.SIGINT, () => { 35 | // ... 36 | handle.dispose(); // de-register from receiving further events. 37 | }); 38 | ``` 39 | -------------------------------------------------------------------------------- /ts/lib/std/testing/bench_example.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | // https://deno.land/std/testing/bench.ts 3 | import { bench, BenchmarkTimer, runBenchmarks } from "./bench"; 4 | 5 | // Basic 6 | bench(function forIncrementX1e9(b: BenchmarkTimer): void { 7 | b.start(); 8 | for (let i = 0; i < 1e9; i++); 9 | b.stop(); 10 | }); 11 | 12 | // Reporting average measured time for $runs runs of func 13 | bench({ 14 | name: "runs100ForIncrementX1e6", 15 | runs: 100, 16 | func(b): void { 17 | b.start(); 18 | for (let i = 0; i < 1e6; i++); 19 | b.stop(); 20 | }, 21 | }); 22 | 23 | // Itsabug 24 | bench(function throwing(b): void { 25 | b.start(); 26 | // Throws bc the timer's stop method is never called 27 | }); 28 | 29 | // Bench control 30 | if (import.meta.main) { 31 | runBenchmarks({ skip: /throw/ }); 32 | } 33 | -------------------------------------------------------------------------------- /ts/lib/std/uuid/README.md: -------------------------------------------------------------------------------- 1 | # UUID 2 | 3 | Support for version 1, 4, and 5 UUIDs. 4 | 5 | ## Usage 6 | 7 | ```ts 8 | import { v4 } from "https://deno.land/std@$STD_VERSION/uuid/mod"; 9 | 10 | // Generate a v4 uuid. 11 | const myUUID = v4.generate(); 12 | 13 | // Validate a v4 uuid. 14 | const isValid = v4.validate(myUUID); 15 | ``` 16 | -------------------------------------------------------------------------------- /ts/lib/std/uuid/mod.ts: -------------------------------------------------------------------------------- 1 | // Based on https://github.com/kelektiv/node-uuid -> https://www.ietf.org/rfc/rfc4122.txt 2 | // Supporting Support for RFC4122 version 1, 4, and 5 UUIDs 3 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 4 | import * as v1 from "./v1"; 5 | import * as v4 from "./v4"; 6 | import * as v5 from "./v5"; 7 | 8 | export const NIL_UUID = "00000000-0000-0000-0000-000000000000"; 9 | 10 | /** 11 | * Checks if UUID is nil 12 | * @param val UUID value 13 | */ 14 | export function isNil(val: string): boolean { 15 | return val === NIL_UUID; 16 | } 17 | 18 | export { v1, v4, v5 }; 19 | -------------------------------------------------------------------------------- /ts/lib/std/uuid/test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import { assert } from "../testing/asserts"; 3 | import { isNil, NIL_UUID } from "./mod"; 4 | 5 | Deno.test("[UUID] isNil", () => { 6 | const nil = NIL_UUID; 7 | const u = "582cbcff-dad6-4f28-888a-e062ae36bafc"; 8 | assert(isNil(nil)); 9 | assert(!isNil(u)); 10 | }); 11 | -------------------------------------------------------------------------------- /ts/lib/std/uuid/v1_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import { assert, assertEquals } from "../testing/asserts"; 3 | import { generate, validate } from "./v1"; 4 | 5 | Deno.test("[UUID] is_valid_uuid_v1", () => { 6 | const u = generate(); 7 | const t = "63655efa-7ee6-11ea-bc55-0242ac130003"; 8 | const n = "63655efa-7ee6-11eg-bc55-0242ac130003"; 9 | 10 | assert(validate(u as string), `generated ${u} should be valid`); 11 | assert(validate(t), `${t} should be valid`); 12 | assert(!validate(n), `${n} should not be valid`); 13 | }); 14 | 15 | Deno.test("[UUID] test_uuid_v1", () => { 16 | const u = generate(); 17 | assertEquals(typeof u, "string", "returns a string"); 18 | assert(u !== "", "return string is not empty"); 19 | }); 20 | 21 | Deno.test("[UUID] test_uuid_v1_format", () => { 22 | for (let i = 0; i < 10000; i++) { 23 | const u = generate() as string; 24 | assert(validate(u), `${u} is not a valid uuid v1`); 25 | } 26 | }); 27 | 28 | Deno.test("[UUID] test_uuid_v1_static", () => { 29 | const v1options = { 30 | node: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab], 31 | clockseq: 0x1234, 32 | msecs: new Date("2011-11-01").getTime(), 33 | nsecs: 5678, 34 | }; 35 | const u = generate(v1options); 36 | assertEquals(u, "710b962e-041c-11e1-9234-0123456789ab"); 37 | }); 38 | -------------------------------------------------------------------------------- /ts/lib/std/uuid/v4.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import { bytesToUuid } from "./_common"; 3 | 4 | const UUID_RE = 5 | /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; 6 | 7 | /** 8 | * Validates the UUID v4. 9 | * @param id UUID value. 10 | */ 11 | export function validate(id: string): boolean { 12 | return UUID_RE.test(id); 13 | } 14 | 15 | /** Generates a RFC4122 v4 UUID (pseudo-randomly-based) */ 16 | export function generate(): string { 17 | const rnds = crypto.getRandomValues(new Uint8Array(16)); 18 | 19 | rnds[6] = (rnds[6] & 0x0f) | 0x40; // Version 4 20 | rnds[8] = (rnds[8] & 0x3f) | 0x80; // Variant 10 21 | 22 | return bytesToUuid(rnds); 23 | } 24 | -------------------------------------------------------------------------------- /ts/lib/std/uuid/v4_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import { assert, assertEquals } from "../testing/asserts"; 3 | import { generate, validate } from "./v4"; 4 | 5 | Deno.test("[UUID] test_uuid_v4", () => { 6 | const u = generate(); 7 | assertEquals(typeof u, "string", "returns a string"); 8 | assert(u !== "", "return string is not empty"); 9 | }); 10 | 11 | Deno.test("[UUID] test_uuid_v4_format", () => { 12 | for (let i = 0; i < 10000; i++) { 13 | const u = generate() as string; 14 | assert(validate(u), `${u} is not a valid uuid v4`); 15 | } 16 | }); 17 | 18 | Deno.test("[UUID] is_valid_uuid_v4", () => { 19 | const u = generate(); 20 | const t = "84fb7824-b951-490e-8afd-0c13228a8282"; 21 | const n = "84fb7824-b951-490g-8afd-0c13228a8282"; 22 | 23 | assert(validate(u), `generated ${u} should be valid`); 24 | assert(validate(t), `${t} should be valid`); 25 | assert(!validate(n), `${n} should not be valid`); 26 | }); 27 | -------------------------------------------------------------------------------- /ts/lib/std/version.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | /** Version of the Deno standard modules 3 | * 4 | * Deno std is versioned differently than Deno cli because it is still unstable; 5 | * the cli's API is stable. In the future when std becomes stable, likely we 6 | * will match versions with cli as we have in the past. 7 | */ 8 | export const VERSION = "0.97.0"; 9 | -------------------------------------------------------------------------------- /ts/lib/std/wasi/README.md: -------------------------------------------------------------------------------- 1 | # wasi 2 | 3 | This module provides an implementation of the WebAssembly System Interface. 4 | 5 | ## Supported Syscalls 6 | 7 | ### wasi_snapshot_preview1 8 | 9 | - [x] args_get 10 | - [x] args_sizes_get 11 | - [x] environ_get 12 | - [x] environ_sizes_get 13 | - [x] clock_res_get 14 | - [x] clock_time_get 15 | - [ ] fd_advise 16 | - [ ] fd_allocate 17 | - [x] fd_close 18 | - [x] fd_datasync 19 | - [x] fd_fdstat_get 20 | - [ ] fd_fdstat_set_flags 21 | - [ ] fd_fdstat_set_rights 22 | - [x] fd_filestat_get 23 | - [x] fd_filestat_set_size 24 | - [x] fd_filestat_set_times 25 | - [x] fd_pread 26 | - [x] fd_prestat_get 27 | - [x] fd_prestat_dir_name 28 | - [x] fd_pwrite 29 | - [x] fd_read 30 | - [x] fd_readdir 31 | - [x] fd_renumber 32 | - [x] fd_seek 33 | - [x] fd_sync 34 | - [x] fd_tell 35 | - [x] fd_write 36 | - [x] path_create_directory 37 | - [x] path_filestat_get 38 | - [x] path_filestat_set_times 39 | - [x] path_link 40 | - [x] path_open 41 | - [x] path_readlink 42 | - [x] path_remove_directory 43 | - [x] path_rename 44 | - [x] path_symlink 45 | - [x] path_unlink_file 46 | - [x] poll_oneoff 47 | - [x] proc_exit 48 | - [ ] proc_raise 49 | - [x] sched_yield 50 | - [x] random_get 51 | - [ ] sock_recv 52 | - [ ] sock_send 53 | - [ ] sock_shutdown 54 | 55 | ## Usage 56 | 57 | ```typescript 58 | import Context from "https://deno.land/std@$STD_VERSION/wasi/snapshot_preview1"; 59 | 60 | const context = new Context({ 61 | args: Deno.args, 62 | env: Deno.env.toObject(), 63 | }); 64 | 65 | const binary = await Deno.readFile("path/to/your/module.wasm"); 66 | const module = await WebAssembly.compile(binary); 67 | const instance = await WebAssembly.instantiate(module, { 68 | "wasi_snapshot_preview1": context.exports, 69 | }); 70 | 71 | context.start(instance); 72 | ``` 73 | -------------------------------------------------------------------------------- /ts/lib/std/wasi/snapshot_preview1_test_runner.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import Context from "./snapshot_preview1"; 3 | 4 | const options = JSON.parse(Deno.args[0]); 5 | const pathname = Deno.args[1]; 6 | const binary = await Deno.readFile(pathname); 7 | const module = await WebAssembly.compile(binary); 8 | 9 | const context = new Context({ 10 | env: options.env, 11 | args: [pathname].concat(options.args), 12 | preopens: options.preopens, 13 | }); 14 | 15 | const instance = new WebAssembly.Instance(module, { 16 | "wasi_snapshot_preview1": context.exports, 17 | }); 18 | 19 | context.start(instance); 20 | -------------------------------------------------------------------------------- /ts/lib/std/ws/example_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. 2 | import "./example_server"; 3 | -------------------------------------------------------------------------------- /ts/lib/x/grpc_basic/error.ts: -------------------------------------------------------------------------------- 1 | export enum Status { 2 | OK = 0, 3 | CANCELLED, 4 | UNKNOWN, 5 | INVALID_ARGUMENT, 6 | DEADLINE_EXCEEDED, 7 | NOT_FOUND, 8 | ALREADY_EXISTS, 9 | PERMISSION_DENIED, 10 | RESOURCE_EXHAUSTED, 11 | FAILED_PRECONDITION, 12 | ABORTED, 13 | OUT_OF_RANGE, 14 | UNIMPLEMENTED, 15 | INTERNAL, 16 | UNAVAILABLE, 17 | DATA_LOSS, 18 | UNAUTHENTICATED, 19 | } 20 | 21 | export function error(code: Status, message = "") { 22 | const status = Status[code]; 23 | const err = new GrpcError(`${status}: ${message}`); 24 | err.grpcCode = +code; 25 | err.grpcMessage = message; 26 | return err; 27 | } 28 | 29 | export class GrpcError extends Error { 30 | grpcCode = 0; 31 | grpcMessage = ""; 32 | grpcMetadata: Record = {}; 33 | 34 | constructor(message: string) { 35 | super(message); 36 | this.name = this.constructor.name; 37 | if (typeof Error["captureStackTrace"] === "function") { 38 | Error["captureStackTrace"](this, this.constructor); 39 | } else { 40 | this.stack = new Error(message).stack; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ts/lib/x/grpc_basic/http2/util.ts: -------------------------------------------------------------------------------- 1 | export const logData = false; 2 | 3 | export const noop = () => {}; 4 | export const consoleLogger = () => ({ 5 | debug: (...args: any[]) => (logData ? console.log(...args) : noop()), 6 | trace: (...args: any[]) => (logData ? console.log(...args) : noop()), 7 | error: (...args: any[]) => (logData ? console.error(...args) : noop()), 8 | }); 9 | -------------------------------------------------------------------------------- /ts/lib/x/grpc_basic/proto.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | import type { 4 | Root, 5 | Type, 6 | Field, 7 | Service, 8 | Message, 9 | Method, 10 | ReflectionObject 11 | } from "protobufjs/index"; 12 | 13 | import * as protobuf from "protobufjs/protobuf"; 14 | 15 | const lib = protobuf.default.exports as any; 16 | 17 | export { Root, Type, Field, Service, Message, Method, ReflectionObject }; 18 | 19 | export function parse(proto: string): { package: string; root: Root } { 20 | return lib.parse(proto); 21 | } 22 | --------------------------------------------------------------------------------