From 5a608c43430bda8b781c37b04219b3ff3ae1ac32 Mon Sep 17 00:00:00 2001 From: lostrepo Date: Sun, 5 May 2024 10:56:57 +0300 Subject: [PATCH 1/4] feat: added types to exported api declarations in lib//api.js typedef based on usage only see lib/gen.js to form proper typedef --- lib/@typify/typify.d.ts | 32 +++++++++++++++ lib/@typify/typify.js | 3 ++ lib/ada/api.js | 6 ++- lib/bestlines/api.js | 14 ++++--- lib/boringssl/api.js | 8 ++-- lib/cfzlib/api.js | 8 ++-- lib/core/api.js | 86 +++++++++++++++++++++-------------------- lib/curl/api.js | 8 ++-- lib/duckdb/api.js | 6 ++- lib/encode/api.js | 6 ++- lib/epoll/api.js | 6 ++- lib/fsmount/api.js | 8 ++-- lib/heap/api.js | 6 ++- lib/inflate/api.js | 6 ++- lib/kevents/api.js | 12 +++--- lib/libffi/api.js | 82 ++++++++++++++++++++------------------- lib/libssl/api.js | 10 +++-- lib/lz4/api.js | 6 ++- lib/mach/api.js | 6 ++- lib/mbedtls/api.js | 14 ++++--- lib/net/api.js | 30 +++++++------- lib/pico/api.js | 32 ++++++++------- lib/pthread/api.js | 6 ++- lib/rustls/api.js | 6 ++- lib/seccomp/api.js | 6 ++- lib/sqlite/api.js | 8 ++-- lib/system/api.js | 8 ++-- lib/tcc/api.js | 6 ++- lib/webui/api.js | 6 ++- lib/wireguard/api.js | 6 ++- lib/zlib/api.js | 8 ++-- 31 files changed, 274 insertions(+), 181 deletions(-) create mode 100644 lib/@typify/typify.d.ts create mode 100644 lib/@typify/typify.js diff --git a/lib/@typify/typify.d.ts b/lib/@typify/typify.d.ts new file mode 100644 index 0000000..eddc615 --- /dev/null +++ b/lib/@typify/typify.d.ts @@ -0,0 +1,32 @@ + +type ARCH = 'x64'; +type CType = 'u64' | 'f64' | 'u32' | 'i64' | 'f32' | 'i32' | 'u8' | 'void' | 'char'; +type Pointer = 'pointer' +type Bool = 'bool'; +type String = 'string'; +type Buffer = 'buffer'; +type TypedArray = 'u32array'; + +// lib_api_typed +type LibApiParameter = Pointer | CType | String | Buffer | TypedArray | Bool; +type LibApiResult = Pointer | CType | Bool; +type LibApiPointer = string; // this is sad +type LibApiOverride = { param: number, fastfield: `${string}->${string}`, slowfield: `${string}.${string}()` } | number; +type LibApiItem = { nofast: boolean; declare_only: boolean; } | { + parameters: LibApiParameter[]; + pointers?: (LibApiPointer | void)[]; + result: LibApiResult; + rpointer?: LibApiPointer | [LibApiPointer]; + name?: string; + arch?: ARCH[]; + override?: (LibApiOverride | void)[]; + casts?: (string | void)[]; + jsdoc?: string; + man?: string[]; + nofast?: boolean; + nonblocking?: boolean; +}; +type LibApi = Record; + +// TODO: add lib_exports_typed to get types for lib exports +export const lib_api_typed: (api: LibApi) => LibApi; diff --git a/lib/@typify/typify.js b/lib/@typify/typify.js new file mode 100644 index 0000000..fcf3148 --- /dev/null +++ b/lib/@typify/typify.js @@ -0,0 +1,3 @@ +function passthrough(v){ return v } + +export const lib_api_typed = passthrough diff --git a/lib/ada/api.js b/lib/ada/api.js index 9867cab..67f2afe 100644 --- a/lib/ada/api.js +++ b/lib/ada/api.js @@ -1,4 +1,6 @@ -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ ada_parse: { parameters: ['pointer', 'u32'], pointers: ['const char*'], @@ -30,7 +32,7 @@ const api = { parameters: ['pointer'], result: 'void' } -} +}) const preamble = ` #ifdef __cplusplus diff --git a/lib/bestlines/api.js b/lib/bestlines/api.js index e6df02e..d524173 100644 --- a/lib/bestlines/api.js +++ b/lib/bestlines/api.js @@ -1,6 +1,8 @@ -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ bestline: { - parameters: ['buffer'], + parameters: ['buffer'], pointers: ['const char*'], result: 'pointer' }, @@ -13,16 +15,16 @@ const api = { result: 'i32', name: 'bestlineHistoryAdd' }, save: { - parameters: ['string'], + parameters: ['string'], pointers: ['const char*'], result: 'i32', name: 'bestlineHistorySave' }, load: { - parameters: ['string'], + parameters: ['string'], pointers: ['const char*'], result: 'i32', name: 'bestlineHistoryLoad' - } -} + } +}) const name = 'bestlines' const includes = ['bestline.h'] diff --git a/lib/boringssl/api.js b/lib/boringssl/api.js index b4b0550..6927b2c 100644 --- a/lib/boringssl/api.js +++ b/lib/boringssl/api.js @@ -1,4 +1,6 @@ -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ OpenSSL_version: { parameters: ['i32'], result: 'pointer', @@ -15,7 +17,7 @@ const api = { result: 'i32' }, EVP_PKEY_keygen: { - parameters: ['pointer', 'pointer'], + parameters: ['pointer', 'pointer'], pointers: ['EVP_PKEY_CTX*', 'EVP_PKEY**'], result: 'i32' }, @@ -516,7 +518,7 @@ const api = { pointers: ['SSL*'], result: 'i32' }, -} +}) const constants = { SSL_OP_ALL: 'u64', diff --git a/lib/cfzlib/api.js b/lib/cfzlib/api.js index d5c04bc..b89633c 100644 --- a/lib/cfzlib/api.js +++ b/lib/cfzlib/api.js @@ -1,4 +1,6 @@ -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ deflate: { parameters: ['buffer', 'u32', 'buffer', 'u32'], pointers: ['uint8_t*', ,'uint8_t*'], @@ -11,7 +13,7 @@ const api = { result: 'u32', name: 'zlib_inflate' } -} +}) const includes = ['zlib.h', 'stdint.h', 'stdlib.h'] const preamble = ` #define Z_DEFAULT_MEMLEVEL 8 @@ -52,7 +54,7 @@ uint32_t zlib_inflate (uint8_t* src, uint32_t ssize, uint8_t* dest, uint32_t dsi inflateEnd(stream); free(stream); return written; -} +} ` //const libs = ['z'] const name = 'cfzlib' diff --git a/lib/core/api.js b/lib/core/api.js index 3134cad..03995c9 100644 --- a/lib/core/api.js +++ b/lib/core/api.js @@ -1,5 +1,7 @@ // the bindings definitions. see docs for more detail -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ // dynamic loader // this is just an example of a jsdoc. should we embed jsdoc here or generate it? // we should generate wrappers in JS with the JSdoc in them @@ -7,10 +9,10 @@ const api = { parameters: ['string', 'i32'], pointers: ['const char*'], jsdoc: `/** -* The function dlopen() loads the dynamic shared object (shared library) -* file named by the null-terminated string filename and returns an opaque -* "handle" for the loaded object. This handle is employed with other -* functions in the dlopen API, such as dlsym(3), dladdr(3), dlinfo(3), +* The function dlopen() loads the dynamic shared object (shared library) +* file named by the null-terminated string filename and returns an opaque +* "handle" for the loaded object. This handle is employed with other +* functions in the dlopen API, such as dlsym(3), dladdr(3), dlinfo(3), * and dlclose() * * \`\`\`js @@ -312,11 +314,11 @@ const api = { // isolates isolate_create: { parameters: [ - 'i32', 'u32array', 'string', 'u32', 'string', 'u32', 'buffer', + 'i32', 'u32array', 'string', 'u32', 'string', 'u32', 'buffer', 'i32', 'i32', 'u64', 'string', 'string', 'i32', 'i32', 'pointer' ], pointers: [ - , 'char**', 'const char*', , 'const char*', , 'char*', , , + , 'char**', 'const char*', , 'const char*', , 'char*', , , 'const char*', 'const char*' ], result: 'i32', @@ -326,11 +328,11 @@ const api = { }, isolate_context_create: { parameters: [ - 'i32', 'pointer', 'string', 'u32', 'string', 'u32', 'pointer', + 'i32', 'pointer', 'string', 'u32', 'string', 'u32', 'pointer', 'i32', 'i32', 'u64', 'string', 'string', 'i32', 'i32', 'pointer', 'buffer' ], pointers: [ - , 'char**', 'const char*', , 'const char*', , 'char*', , , + , 'char**', 'const char*', , 'const char*', , 'char*', , , 'const char*', 'const char*', , , , , 'struct isolate_context*' ], result: 'void', @@ -386,9 +388,9 @@ const api = { parameters: [], result: 'void' } -} +}) -// optional preamble of C/C++ code to embed in the generated source file before +// optional preamble of C/C++ code to embed in the generated source file before // compilation const preamble = ` #include @@ -439,47 +441,47 @@ inline uint8_t needsunwrap (lo::FastTypes t) { } v8::CTypeInfo* CTypeFromV8 (uint8_t v8Type) { - if (v8Type == lo::FastTypes::boolean) + if (v8Type == lo::FastTypes::boolean) return new v8::CTypeInfo(v8::CTypeInfo::Type::kBool); - if (v8Type == lo::FastTypes::i8) + if (v8Type == lo::FastTypes::i8) return new v8::CTypeInfo(v8::CTypeInfo::Type::kInt32); - if (v8Type == lo::FastTypes::i16) + if (v8Type == lo::FastTypes::i16) return new v8::CTypeInfo(v8::CTypeInfo::Type::kInt32); - if (v8Type == lo::FastTypes::i32) + if (v8Type == lo::FastTypes::i32) return new v8::CTypeInfo(v8::CTypeInfo::Type::kInt32); - if (v8Type == lo::FastTypes::u8) + if (v8Type == lo::FastTypes::u8) return new v8::CTypeInfo(v8::CTypeInfo::Type::kUint32); - if (v8Type == lo::FastTypes::u16) + if (v8Type == lo::FastTypes::u16) return new v8::CTypeInfo(v8::CTypeInfo::Type::kUint32); - if (v8Type == lo::FastTypes::u32) + if (v8Type == lo::FastTypes::u32) return new v8::CTypeInfo(v8::CTypeInfo::Type::kUint32); - if (v8Type == lo::FastTypes::f32) + if (v8Type == lo::FastTypes::f32) return new v8::CTypeInfo(v8::CTypeInfo::Type::kFloat32); - if (v8Type == lo::FastTypes::f64) + if (v8Type == lo::FastTypes::f64) return new v8::CTypeInfo(v8::CTypeInfo::Type::kFloat64); - if (v8Type == lo::FastTypes::i64) + if (v8Type == lo::FastTypes::i64) return new v8::CTypeInfo(v8::CTypeInfo::Type::kInt64); - if (v8Type == lo::FastTypes::u64) + if (v8Type == lo::FastTypes::u64) return new v8::CTypeInfo(v8::CTypeInfo::Type::kUint64); - if (v8Type == lo::FastTypes::iSize) + if (v8Type == lo::FastTypes::iSize) return new v8::CTypeInfo(v8::CTypeInfo::Type::kInt64); - if (v8Type == lo::FastTypes::uSize) + if (v8Type == lo::FastTypes::uSize) return new v8::CTypeInfo(v8::CTypeInfo::Type::kUint64); - if (v8Type == lo::FastTypes::pointer) + if (v8Type == lo::FastTypes::pointer) return new v8::CTypeInfo(v8::CTypeInfo::Type::kUint64); - if (v8Type == lo::FastTypes::function) + if (v8Type == lo::FastTypes::function) return new v8::CTypeInfo(v8::CTypeInfo::Type::kUint64); - if (v8Type == lo::FastTypes::string) + if (v8Type == lo::FastTypes::string) return new v8::CTypeInfo(v8::CTypeInfo::Type::kSeqOneByteString); if (v8Type == lo::FastTypes::buffer) { - return new v8::CTypeInfo(v8::CTypeInfo::Type::kUint8, + return new v8::CTypeInfo(v8::CTypeInfo::Type::kUint8, v8::CTypeInfo::SequenceType::kIsTypedArray, v8::CTypeInfo::Flags::kNone); } if (v8Type == lo::FastTypes::u32array) { - return new v8::CTypeInfo(v8::CTypeInfo::Type::kUint32, + return new v8::CTypeInfo(v8::CTypeInfo::Type::kUint32, v8::CTypeInfo::SequenceType::kIsTypedArray, v8::CTypeInfo::Flags::kNone); } - return new v8::CTypeInfo(v8::CTypeInfo::Type::kVoid); + return new v8::CTypeInfo(v8::CTypeInfo::Type::kVoid); } void lo_fastcall (struct fastcall* state) { @@ -534,14 +536,14 @@ void SlowCallback(const FunctionCallbackInfo &args) { case FastTypes::buffer: { Local u8 = args[i].As(); - state->args[r++] = (uint64_t)((uint8_t*)u8->Buffer()->Data() + + state->args[r++] = (uint64_t)((uint8_t*)u8->Buffer()->Data() + u8->ByteOffset()); } break; case FastTypes::u32array: { Local u32 = args[i].As(); - state->args[r++] = (uint64_t)((uint8_t*)u32->Buffer()->Data() + + state->args[r++] = (uint64_t)((uint8_t*)u32->Buffer()->Data() + u32->ByteOffset()); } break; @@ -557,7 +559,7 @@ void SlowCallback(const FunctionCallbackInfo &args) { case FastTypes::f64: { //Local u32 = args[i].As(); - //state->args[r++] = (uint64_t)((uint8_t*)u32->Buffer()->Data() + + //state->args[r++] = (uint64_t)((uint8_t*)u32->Buffer()->Data() + // u32->ByteOffset()); double src = (double)args[i].As()->Value(); double* dst = (double*)&state->args[r++]; @@ -638,11 +640,11 @@ void bind_fastcallSlow(const FunctionCallbackInfo &args) { } CFunctionInfo* info = new CFunctionInfo(*rc, fastlen, cargs); CFunction* fastCFunc = new CFunction(state->wrapper, info); - Local funcTemplate = FunctionTemplate::New(isolate, + Local funcTemplate = FunctionTemplate::New(isolate, SlowCallback, data, Local(), 0, ConstructorBehavior::kThrow, SideEffectType::kHasNoSideEffect, fastCFunc ); - Local fun = + Local fun = funcTemplate->GetFunction(context).ToLocalChecked(); args.GetReturnValue().Set(fun); } @@ -656,11 +658,11 @@ void bind_slowcallSlow(const FunctionCallbackInfo &args) { tpl->SetInternalFieldCount(2); Local data = tpl->NewInstance(context).ToLocalChecked(); data->SetAlignedPointerInInternalField(1, state); - Local funcTemplate = FunctionTemplate::New(isolate, + Local funcTemplate = FunctionTemplate::New(isolate, SlowCallback, data, Local(), 0, ConstructorBehavior::kThrow, SideEffectType::kHasNoSideEffect, 0 ); - Local fun = + Local fun = funcTemplate->GetFunction(context).ToLocalChecked(); args.GetReturnValue().Set(fun); } @@ -702,14 +704,14 @@ pid_t vfexecve (int fd, char* const argv[], char* const envp[]) { // that system constant will be set in the binding at compile time // todo: we need to define platform for constants too const constants = { - S_IFBLK: 'i32', S_IFCHR: 'i32', S_IFIFO: 'i32', + S_IFBLK: 'i32', S_IFCHR: 'i32', S_IFIFO: 'i32', S_IRUSR: 'i32', S_IWUSR: 'i32', S_IRGRP: 'i32', S_IWGRP: 'i32', S_IROTH: 'i32', S_IWOTH: 'i32', O_RDONLY: 'i32', O_WRONLY: 'i32', O_CREAT: 'i32', S_IRWXU: 'i32', S_IRWXG: 'i32', S_IXOTH: 'i32', O_TRUNC: 'i32', STDIN: 0, STDOUT: 1, STDERR: 2, O_CLOEXEC: 'i32', RUSAGE_SELF: 'i32', SEEK_SET: 'i32', SEEK_CUR: 'i32', SEEK_END: 'i32', S_IRWXO: 'i32', F_OK: 'i32', S_IFMT: 'i32', S_IFDIR: 'i32', - S_IFREG: 'i32', NAME_MAX: 'u32', O_RDWR: 'i32', O_SYNC: 'i32', + S_IFREG: 'i32', NAME_MAX: 'u32', O_RDWR: 'i32', O_SYNC: 'i32', O_DIRECTORY: 'i32', F_SETFL: 'i32', O_NONBLOCK: 'i32', EAGAIN: 'i32', WNOHANG: 'i32', SIGTERM: 'i32', @@ -717,11 +719,11 @@ const constants = { MS_ASYNC: 'i32', MS_SYNC: 'i32', MS_INVALIDATE: 'i32', _SC_CLK_TCK: 'i32', F_GETFL: 'i32', - RTLD_NOW: 'i32', RTLD_LAZY: 'i32', RTLD_GLOBAL: 'i32', RTLD_LOCAL: 'i32', + RTLD_NOW: 'i32', RTLD_LAZY: 'i32', RTLD_GLOBAL: 'i32', RTLD_LOCAL: 'i32', RTLD_NODELETE: 'i32', RTLD_NOLOAD: 'i32', RTLD_DEFAULT: 'u64', RTLD_NEXT: 'u64', PROT_READ: 'i32', PROT_WRITE: 'i32', PROT_EXEC: 'i32', - + } const structs = ['clock_t'] @@ -733,7 +735,7 @@ const includes = [ 'string.h', 'termios.h' ] -// i think this is cleanest way to do this for now. would be nice to come up +// i think this is cleanest way to do this for now. would be nice to come up // with a matrix of all syscalls for all environments and generate them automatically const mac = { constants: { diff --git a/lib/curl/api.js b/lib/curl/api.js index c6836cb..7478ec2 100644 --- a/lib/curl/api.js +++ b/lib/curl/api.js @@ -1,4 +1,6 @@ -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ fopen: { parameters: ['string', 'string'], result: 'pointer' @@ -86,12 +88,12 @@ const api = { pointers: ['CURL*'], name: 'curl_easy_getinfo' }, -} +}) const includes = ['curl/curl.h', 'stdint.h'] const constants = { CURLINFO_OFF_T: 'i32', CURL_GLOBAL_DEFAULT: 'i32', CURLOPT_URL: 'i32', - CURLOPT_BUFFERSIZE: 'i32', CURLOPT_HTTP_VERSION: 'i32', + CURLOPT_BUFFERSIZE: 'i32', CURLOPT_HTTP_VERSION: 'i32', CURL_HTTP_VERSION_1_1: 'i32', CURLOPT_FOLLOWLOCATION: 'i32', CURLINFO_SIZE_DOWNLOAD_T: 'i32', CURLOPT_WRITEFUNCTION: 'i32', CURLOPT_WRITEDATA: 'i32', CURLINFO_RESPONSE_CODE: 'i32', CURLOPT_FAILONERROR: 'i32', diff --git a/lib/duckdb/api.js b/lib/duckdb/api.js index 7235720..1f4b573 100644 --- a/lib/duckdb/api.js +++ b/lib/duckdb/api.js @@ -1,4 +1,6 @@ -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ create_config: { parameters: ['pointer'], pointers: ['duckdb_config*'], @@ -138,7 +140,7 @@ const api = { rpointer: 'const char*', name: 'duckdb_library_version' } -} +}) const name = 'duckdb' diff --git a/lib/encode/api.js b/lib/encode/api.js index 1ef2e74..6a465d8 100644 --- a/lib/encode/api.js +++ b/lib/encode/api.js @@ -1,4 +1,6 @@ -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ hex_encode: { parameters: ['buffer', 'u32', 'buffer', 'u32'], pointers: ['const char*', , 'char*'], @@ -31,7 +33,7 @@ const api = { result: 'u32', name: 'base64_decode' }, -} +}) // todo: add licensese for this code or replace/rewrite it diff --git a/lib/epoll/api.js b/lib/epoll/api.js index 476fa83..842d3cd 100644 --- a/lib/epoll/api.js +++ b/lib/epoll/api.js @@ -1,4 +1,6 @@ -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ create: { parameters: ['i32'], result: 'i32', @@ -21,7 +23,7 @@ const api = { result: 'i32', name: 'close' } -} +}) const constants = { EPOLLIN: 'i32', diff --git a/lib/fsmount/api.js b/lib/fsmount/api.js index ab5eb93..1b58ea0 100644 --- a/lib/fsmount/api.js +++ b/lib/fsmount/api.js @@ -1,4 +1,6 @@ -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ // dynamic loader mount: { parameters: ['string', 'string', 'string', 'u32', 'pointer'], @@ -12,7 +14,7 @@ const api = { parameters: ['string', 'i32'], result: 'i32' } -} +}) const includes = [ 'sys/mount.h' @@ -24,7 +26,7 @@ const constants = { MNT_FORCE: 'i32', MNT_DETACH: 'i32', MNT_EXPIRE: 'i32', UMOUNT_NOFOLLOW: 'i32', // mount flags MS_DIRSYNC: 'u32', MS_LAZYTIME: 'u32', MS_MANDLOCK: 'u32', MS_NOATIME: 'u32', - MS_NODEV: 'u32', MS_NODIRATIME: 'u32', MS_NOEXEC: 'u32', MS_NOSUID: 'u32', + MS_NODEV: 'u32', MS_NODIRATIME: 'u32', MS_NOEXEC: 'u32', MS_NOSUID: 'u32', MS_RDONLY: 'u32', MS_REC: 'u32', MS_RELATIME: 'u32', MS_SILENT: 'u32', MS_STRICTATIME: 'u32', MS_SYNCHRONOUS: 'u32', MS_NOSYMFOLLOW: 'u32' } diff --git a/lib/heap/api.js b/lib/heap/api.js index 79ffaf5..a047342 100644 --- a/lib/heap/api.js +++ b/lib/heap/api.js @@ -42,12 +42,14 @@ void snapshotSlow(const FunctionCallbackInfo &args) { ` -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ snapshot: { declare_only: true, nofast: true } -} +}) const includes = ['v8-profiler.h'] const name = 'heap' diff --git a/lib/inflate/api.js b/lib/inflate/api.js index bb0ca2f..730c8dd 100644 --- a/lib/inflate/api.js +++ b/lib/inflate/api.js @@ -1,4 +1,6 @@ -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ inflate: { parameters: ['buffer', 'u32', 'buffer', 'u32'], pointers: ['unsigned char*', , 'unsigned char*'], @@ -11,7 +13,7 @@ const api = { result: 'i32', name: 'em_inflate' } -} +}) const name = 'inflate' const includes = ['em_inflate.h'] diff --git a/lib/kevents/api.js b/lib/kevents/api.js index b79b8dd..6efb949 100644 --- a/lib/kevents/api.js +++ b/lib/kevents/api.js @@ -1,4 +1,6 @@ -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ kqueue: { parameters: [], result: 'i32' @@ -13,12 +15,12 @@ const api = { pointers: [, 'const struct kevent64_s *', , 'struct kevent64_s *', , , 'const struct timespec *'], result: 'i32' } -} +}) const name = 'kevents' const constants = { - EVFILT_READ: 'i32', + EVFILT_READ: 'i32', EVFILT_EXCEPT: 'i32', EVFILT_WRITE: 'i32', EVFILT_VNODE: 'i32', @@ -26,8 +28,8 @@ const constants = { EVFILT_SIGNAL: 'i32', EVFILT_MACHPORT: 'i32', EVFILT_TIMER: 'i32', - EV_ADD: 'i32', - EV_ENABLE: 'i32', + EV_ADD: 'i32', + EV_ENABLE: 'i32', EV_DISABLE: 'i32', EV_DELETE: 'i32', EV_RECEIPT: 'i32', diff --git a/lib/libffi/api.js b/lib/libffi/api.js index a6891b7..dcad74e 100644 --- a/lib/libffi/api.js +++ b/lib/libffi/api.js @@ -1,4 +1,6 @@ -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ ffi_prep_cif: { parameters: ['buffer', 'u32', 'u32', 'buffer', 'buffer'], pointers: ['ffi_cif*', , , 'ffi_type*', 'ffi_type**'], @@ -20,7 +22,7 @@ const api = { nofast: true, name: 'bindSlowApi' } -} +}) const preamble = ` typedef void (*callback)(); @@ -47,87 +49,87 @@ inline uint8_t needsunwrap (lo::FastTypes t) { } v8::CTypeInfo* CTypeFromV8 (uint8_t v8Type) { - if (v8Type == lo::FastTypes::boolean) + if (v8Type == lo::FastTypes::boolean) return new v8::CTypeInfo(v8::CTypeInfo::Type::kBool); - if (v8Type == lo::FastTypes::i8) + if (v8Type == lo::FastTypes::i8) return new v8::CTypeInfo(v8::CTypeInfo::Type::kInt32); - if (v8Type == lo::FastTypes::i16) + if (v8Type == lo::FastTypes::i16) return new v8::CTypeInfo(v8::CTypeInfo::Type::kInt32); - if (v8Type == lo::FastTypes::i32) + if (v8Type == lo::FastTypes::i32) return new v8::CTypeInfo(v8::CTypeInfo::Type::kInt32); - if (v8Type == lo::FastTypes::u8) + if (v8Type == lo::FastTypes::u8) return new v8::CTypeInfo(v8::CTypeInfo::Type::kUint32); - if (v8Type == lo::FastTypes::u16) + if (v8Type == lo::FastTypes::u16) return new v8::CTypeInfo(v8::CTypeInfo::Type::kUint32); - if (v8Type == lo::FastTypes::u32) + if (v8Type == lo::FastTypes::u32) return new v8::CTypeInfo(v8::CTypeInfo::Type::kUint32); - if (v8Type == lo::FastTypes::f32) + if (v8Type == lo::FastTypes::f32) return new v8::CTypeInfo(v8::CTypeInfo::Type::kFloat32); - if (v8Type == lo::FastTypes::f64) + if (v8Type == lo::FastTypes::f64) return new v8::CTypeInfo(v8::CTypeInfo::Type::kFloat64); - if (v8Type == lo::FastTypes::i64) + if (v8Type == lo::FastTypes::i64) return new v8::CTypeInfo(v8::CTypeInfo::Type::kInt64); - if (v8Type == lo::FastTypes::u64) + if (v8Type == lo::FastTypes::u64) return new v8::CTypeInfo(v8::CTypeInfo::Type::kUint64); - if (v8Type == lo::FastTypes::iSize) + if (v8Type == lo::FastTypes::iSize) return new v8::CTypeInfo(v8::CTypeInfo::Type::kInt64); - if (v8Type == lo::FastTypes::uSize) + if (v8Type == lo::FastTypes::uSize) return new v8::CTypeInfo(v8::CTypeInfo::Type::kUint64); - if (v8Type == lo::FastTypes::pointer) + if (v8Type == lo::FastTypes::pointer) return new v8::CTypeInfo(v8::CTypeInfo::Type::kUint64); - if (v8Type == lo::FastTypes::function) + if (v8Type == lo::FastTypes::function) return new v8::CTypeInfo(v8::CTypeInfo::Type::kUint64); - if (v8Type == lo::FastTypes::string) + if (v8Type == lo::FastTypes::string) return new v8::CTypeInfo(v8::CTypeInfo::Type::kSeqOneByteString); if (v8Type == lo::FastTypes::buffer) { - return new v8::CTypeInfo(v8::CTypeInfo::Type::kUint8, + return new v8::CTypeInfo(v8::CTypeInfo::Type::kUint8, v8::CTypeInfo::SequenceType::kIsTypedArray, v8::CTypeInfo::Flags::kNone); } if (v8Type == lo::FastTypes::u32array) { - return new v8::CTypeInfo(v8::CTypeInfo::Type::kUint32, + return new v8::CTypeInfo(v8::CTypeInfo::Type::kUint32, v8::CTypeInfo::SequenceType::kIsTypedArray, v8::CTypeInfo::Flags::kNone); } - return new v8::CTypeInfo(v8::CTypeInfo::Type::kVoid); + return new v8::CTypeInfo(v8::CTypeInfo::Type::kVoid); } ffi_type* FFITypeFromV8 (uint8_t v8Type) { - if (v8Type == lo::FastTypes::boolean) + if (v8Type == lo::FastTypes::boolean) return &ffi_type_uint8; - if (v8Type == lo::FastTypes::i8) + if (v8Type == lo::FastTypes::i8) return &ffi_type_sint8; - if (v8Type == lo::FastTypes::i16) + if (v8Type == lo::FastTypes::i16) return &ffi_type_sint16; - if (v8Type == lo::FastTypes::i32) + if (v8Type == lo::FastTypes::i32) return &ffi_type_sint32; - if (v8Type == lo::FastTypes::u8) + if (v8Type == lo::FastTypes::u8) return &ffi_type_uint8; - if (v8Type == lo::FastTypes::u16) + if (v8Type == lo::FastTypes::u16) return &ffi_type_uint16; - if (v8Type == lo::FastTypes::u32) + if (v8Type == lo::FastTypes::u32) return &ffi_type_uint32; - if (v8Type == lo::FastTypes::f32) + if (v8Type == lo::FastTypes::f32) return &ffi_type_float; - if (v8Type == lo::FastTypes::f64) + if (v8Type == lo::FastTypes::f64) return &ffi_type_double; - if (v8Type == lo::FastTypes::i64) + if (v8Type == lo::FastTypes::i64) return &ffi_type_sint64; - if (v8Type == lo::FastTypes::u64) + if (v8Type == lo::FastTypes::u64) return &ffi_type_uint64; - if (v8Type == lo::FastTypes::iSize) + if (v8Type == lo::FastTypes::iSize) return &ffi_type_sint64; - if (v8Type == lo::FastTypes::uSize) + if (v8Type == lo::FastTypes::uSize) return &ffi_type_uint64; - if (v8Type == lo::FastTypes::pointer) + if (v8Type == lo::FastTypes::pointer) return &ffi_type_pointer; - if (v8Type == lo::FastTypes::function) + if (v8Type == lo::FastTypes::function) return &ffi_type_pointer; - if (v8Type == lo::FastTypes::string) + if (v8Type == lo::FastTypes::string) return &ffi_type_pointer; if (v8Type == lo::FastTypes::buffer) return &ffi_type_pointer; if (v8Type == lo::FastTypes::u32array) return &ffi_type_pointer; - return &ffi_type_void; + return &ffi_type_void; } // 10 ns if this fn does nothing @@ -306,7 +308,7 @@ void bindSlowApiSlow(const FunctionCallbackInfo &args) { SideEffectType::kHasNoSideEffect, NULL ); - Local fun = + Local fun = funcTemplate->GetFunction(context).ToLocalChecked(); args.GetReturnValue().Set(fun); } @@ -418,7 +420,7 @@ void bindFastApiSlow(const FunctionCallbackInfo &args) { ); // TODO: figure out how to handle side-effect flag: // https://github.com/nodejs/node/pull/46619 - Local fun = + Local fun = funcTemplate->GetFunction(context).ToLocalChecked(); args.GetReturnValue().Set(fun); } diff --git a/lib/libssl/api.js b/lib/libssl/api.js index 7b0f219..2b04237 100644 --- a/lib/libssl/api.js +++ b/lib/libssl/api.js @@ -1,4 +1,6 @@ -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ OpenSSL_version: { parameters: ['i32'], result: 'pointer', @@ -15,7 +17,7 @@ const api = { result: 'i32' }, EVP_PKEY_keygen: { - parameters: ['pointer', 'pointer'], + parameters: ['pointer', 'pointer'], pointers: ['EVP_PKEY_CTX*', 'EVP_PKEY**'], result: 'i32' }, @@ -459,7 +461,7 @@ const api = { result: 'u64' }, RSA_pkey_ctx_ctrl: { - parameters: ['pointer', 'i32', 'i32', 'i32', 'pointer'], + parameters: ['pointer', 'i32', 'i32', 'i32', 'pointer'], pointers: ['EVP_PKEY_CTX*'], result: 'i32' }, @@ -543,7 +545,7 @@ const api = { pointers: ['SSL_CTX*'], result: 'i32' } -} +}) const constants = { SSL_OP_ALL: 'u64', diff --git a/lib/lz4/api.js b/lib/lz4/api.js index 5663a79..761fb92 100644 --- a/lib/lz4/api.js +++ b/lib/lz4/api.js @@ -1,4 +1,6 @@ -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ compress_default: { parameters: ['pointer', 'pointer', 'i32', 'i32'], pointers: ['const char*', 'char*'], @@ -17,7 +19,7 @@ const api = { result: 'i32', name: 'LZ4_decompress_safe' } -} +}) const name = 'lz4' const includes = ['lz4.h', 'lz4hc.h'] diff --git a/lib/mach/api.js b/lib/mach/api.js index fbbc5cc..42910b9 100644 --- a/lib/mach/api.js +++ b/lib/mach/api.js @@ -1,4 +1,6 @@ -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ task_info: { parameters: ['u32', 'i32', 'pointer', 'pointer'], pointers: [, , 'task_info_t', 'mach_msg_type_number_t*'], @@ -15,7 +17,7 @@ const api = { result: 'i32', name: '_NSGetExecutablePath' } -} +}) const preamble = '' diff --git a/lib/mbedtls/api.js b/lib/mbedtls/api.js index 23dbe43..afd21ed 100644 --- a/lib/mbedtls/api.js +++ b/lib/mbedtls/api.js @@ -1,4 +1,6 @@ -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ x509_crt_init: { parameters: ['pointer'], pointers: ['mbedtls_x509_crt*'], @@ -316,11 +318,11 @@ const api = { result: 'void', name: 'mbedtls_sha256_finish' }, -} +}) const includes = [ - 'mbedtls/x509.h', 'mbedtls/entropy.h', 'mbedtls/ssl.h', - 'mbedtls/net_sockets.h', + 'mbedtls/x509.h', 'mbedtls/entropy.h', 'mbedtls/ssl.h', + 'mbedtls/net_sockets.h', 'mbedtls/ctr_drbg.h', 'mbedtls/debug.h', 'mbedtls/platform.h' ] @@ -328,11 +330,11 @@ const include_paths = ['./deps/mbedtls/include'] const name = 'mbedtls' const libs = [] const obj = [ - 'deps/mbedtls/library/libmbedx509.a', 'deps/mbedtls/library/libmbedcrypto.a', + 'deps/mbedtls/library/libmbedx509.a', 'deps/mbedtls/library/libmbedcrypto.a', 'deps/mbedtls/library/libmbedtls.a' ] const structs = [ - 'mbedtls_net_context', 'mbedtls_x509_crt', 'mbedtls_entropy_context', + 'mbedtls_net_context', 'mbedtls_x509_crt', 'mbedtls_entropy_context', 'mbedtls_ssl_context', 'mbedtls_ssl_config', 'mbedtls_ctr_drbg_context', 'mbedtls_dhm_context', 'mbedtls_md5_context', 'mbedtls_sha256_context' ] diff --git a/lib/net/api.js b/lib/net/api.js index 144517a..e057750 100644 --- a/lib/net/api.js +++ b/lib/net/api.js @@ -1,4 +1,6 @@ -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ socket: { parameters: ['i32', 'i32', 'i32'], result: 'i32' @@ -98,24 +100,24 @@ const api = { parameters: ['i32', 'i32'], result: 'i32' }, -} +}) const constants = { - EINPROGRESS: 'i32', + EINPROGRESS: 'i32', EAGAIN: 'i32', - AF_INET: 'i32', + AF_INET: 'i32', AF_UNIX: 'i32', - SOCK_STREAM: 'i32', - SOL_SOCKET: 'i32', + SOCK_STREAM: 'i32', + SOL_SOCKET: 'i32', SO_REUSEPORT: 'i32', - SOMAXCONN: 'i32', - MSG_NOSIGNAL: 'i32', - SOCK_DGRAM: 'i32', - SOCK_RAW: 'i32', - SIOCGIFADDR: 'i32', - IPPROTO_RAW: 'i32', - SIOCSIFFLAGS: 'i32', - SIOCSIFADDR: 'i32', + SOMAXCONN: 'i32', + MSG_NOSIGNAL: 'i32', + SOCK_DGRAM: 'i32', + SOCK_RAW: 'i32', + SIOCGIFADDR: 'i32', + IPPROTO_RAW: 'i32', + SIOCSIFFLAGS: 'i32', + SIOCSIFADDR: 'i32', SIOCSIFNETMASK: 'i32', SOCKADDR_LEN: 16, TCP_NODELAY: 'i32', diff --git a/lib/pico/api.js b/lib/pico/api.js index 1510743..4bb7673 100644 --- a/lib/pico/api.js +++ b/lib/pico/api.js @@ -1,4 +1,6 @@ -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ parseRequest: { parameters: ['buffer', 'u32', 'buffer'], pointers: ['char*', ,'httpRequest*'], @@ -24,17 +26,17 @@ const api = { name: 'parse_response' }, /* -int phr_parse_request(const char *buf, size_t len, const char **method, - size_t *method_len, const char **path, size_t *path_len, int *minor_version, +int phr_parse_request(const char *buf, size_t len, const char **method, + size_t *method_len, const char **path, size_t *path_len, int *minor_version, struct phr_header *headers, size_t *num_headers, size_t last_len); -int phr_parse_response(const char *_buf, size_t len, int *minor_version, - int *status, const char **msg, size_t *msg_len, struct phr_header *headers, +int phr_parse_response(const char *_buf, size_t len, int *minor_version, + int *status, const char **msg, size_t *msg_len, struct phr_header *headers, size_t *num_headers, size_t last_len); */ parse_request: { parameters: [ - 'pointer', 'u32', 'pointer', 'pointer', 'pointer', 'pointer', + 'pointer', 'u32', 'pointer', 'pointer', 'pointer', 'pointer', 'pointer', 'pointer', 'pointer', 'u64' ], pointers: [ @@ -46,7 +48,7 @@ int phr_parse_response(const char *_buf, size_t len, int *minor_version, }, parse_response: { parameters: [ - 'pointer', 'u32', 'pointer', 'pointer', 'pointer', 'pointer', + 'pointer', 'u32', 'pointer', 'pointer', 'pointer', 'pointer', 'pointer', 'pointer', 'u32' ], pointers: [ @@ -62,7 +64,7 @@ int phr_parse_response(const char *_buf, size_t len, int *minor_version, result: 'i32', name: 'phr_decode_chunked' } -} +}) const name = 'pico' const includes = ['picohttpparser.h'] @@ -118,10 +120,10 @@ int parse_request(char* next, ssize_t bytes, httpRequest* req) { const char* path; struct phr_header headers[JUST_MAX_HEADERS]; req->num_headers = JUST_MAX_HEADERS; - int nread = phr_parse_request(next, bytes, - (const char **)&method, - &req->method_len, (const char **)&path, - &req->path_len, &req->minor_version, headers, + int nread = phr_parse_request(next, bytes, + (const char **)&method, + &req->method_len, (const char **)&path, + &req->path_len, &req->minor_version, headers, &req->num_headers, 0); for (uint32_t i = 0; i < req->num_headers; i++) { req->headers[i].name_start = (uint64_t)headers[i].name - (uint64_t)next; @@ -137,9 +139,9 @@ int parse_response(char* next, ssize_t bytes, httpResponse* res) { struct phr_header headers[JUST_MAX_HEADERS]; res->num_headers = JUST_MAX_HEADERS; int nread = phr_parse_response(next, bytes, - &res->minor_version, &res->status_code, - (const char **)&status_message, - &res->status_message_len, headers, + &res->minor_version, &res->status_code, + (const char **)&status_message, + &res->status_message_len, headers, &res->num_headers, 0); for (uint32_t i = 0; i < res->num_headers; i++) { res->headers[i].name_start = (uint64_t)headers[i].name - (uint64_t)next; diff --git a/lib/pthread/api.js b/lib/pthread/api.js index fb91dbb..4641c6c 100644 --- a/lib/pthread/api.js +++ b/lib/pthread/api.js @@ -1,4 +1,6 @@ -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ create: { parameters: ['u32array', 'pointer', 'pointer', 'buffer'], pointers: ['pthread_t*', 'const pthread_attr_t*', 'start_routine'], @@ -30,7 +32,7 @@ const api = { result: 'void', name: 'pthread_exit' }, -} +}) const constants = { EBUSY: 'i32' diff --git a/lib/rustls/api.js b/lib/rustls/api.js index 57669d4..b0e78a1 100644 --- a/lib/rustls/api.js +++ b/lib/rustls/api.js @@ -1,4 +1,6 @@ -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ version: { parameters: [], result: 'pointer', @@ -163,7 +165,7 @@ const api = { result: 'void', name: 'rustls_connection_free' } -} +}) const name = 'rustls' diff --git a/lib/seccomp/api.js b/lib/seccomp/api.js index decca4a..3207e09 100644 --- a/lib/seccomp/api.js +++ b/lib/seccomp/api.js @@ -1,4 +1,6 @@ -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ seccomp_syscall_resolve_num_arch: { parameters: ['i32', 'i32'], result: 'pointer', @@ -29,7 +31,7 @@ const api = { pointers: ['const char*'], result: 'i32' } -} +}) const name = 'seccomp' const includes = ['seccomp.h'] diff --git a/lib/sqlite/api.js b/lib/sqlite/api.js index 90bb3dd..f09d839 100644 --- a/lib/sqlite/api.js +++ b/lib/sqlite/api.js @@ -1,4 +1,6 @@ -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ version: { parameters: [], pointers: [], @@ -208,7 +210,7 @@ const api = { pointers: ['sqlite3*', , 'unsigned char*'], result: 'i32' } -} +}) /* sqlite3_bind_null @@ -245,7 +247,7 @@ const preamble = `typedef int (*callback)(void*,int,char**,char**);\n` const libs = [] const obj = ['deps/sqlite/.libs/libsqlite3.a'] const constants = { - SQLITE_OPEN_READWRITE: 'i32', SQLITE_OPEN_PRIVATECACHE: 'i32', + SQLITE_OPEN_READWRITE: 'i32', SQLITE_OPEN_PRIVATECACHE: 'i32', SQLITE_ROW: 'i32', SQLITE_OPEN_NOMUTEX: 'i32', SQLITE_OPEN_CREATE: 'i32', SQLITE_OK: 'i32', SQLITE_OPEN_READONLY: 'i32' } diff --git a/lib/system/api.js b/lib/system/api.js index d1836f2..e967e0f 100644 --- a/lib/system/api.js +++ b/lib/system/api.js @@ -1,4 +1,6 @@ -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ mmap: { parameters: ['pointer', 'u32', 'i32', 'i32', 'i32', 'u32'], result: 'pointer' @@ -107,7 +109,7 @@ const api = { parameters: ['pointer'], result: 'void' }, -} +}) const constants = { _SC_CLK_TCK: 'i32', @@ -186,7 +188,7 @@ const linux = { extern "C" { #endif - extern + extern int __xpg_strerror_r(int errcode,char* buffer,size_t length); #define strerror_r __xpg_strerror_r #ifdef __cplusplus diff --git a/lib/tcc/api.js b/lib/tcc/api.js index d0d6bde..900dca4 100644 --- a/lib/tcc/api.js +++ b/lib/tcc/api.js @@ -1,4 +1,6 @@ -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ tcc_new: { parameters: [], result: 'pointer' @@ -63,7 +65,7 @@ const api = { pointers: ['TCCState*', 'const char*'], result: 'i32' } -} +}) const name = 'tcc' const includes = ['libtcc.h'] diff --git a/lib/webui/api.js b/lib/webui/api.js index fccfe4e..54f5c6b 100644 --- a/lib/webui/api.js +++ b/lib/webui/api.js @@ -1,4 +1,6 @@ -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ webui_wait: { // void webui_wait(void) parameters: [], @@ -220,7 +222,7 @@ const api = { parameters: ["u32", "u32"], result: "void", } -} +}) const include_paths = ['./deps/webui/include'] //const includes = ['webui.h'] diff --git a/lib/wireguard/api.js b/lib/wireguard/api.js index 3166038..8c5b61c 100644 --- a/lib/wireguard/api.js +++ b/lib/wireguard/api.js @@ -1,4 +1,6 @@ -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ set: { parameters: ['pointer'], pointers: ['wg_device*'], @@ -70,7 +72,7 @@ const api = { result: 'void', name: 'wg_generate_preshared_key' } -} +}) const includes = ['wireguard.h'] const name = 'wireguard' diff --git a/lib/zlib/api.js b/lib/zlib/api.js index 3fc84fa..6518c54 100644 --- a/lib/zlib/api.js +++ b/lib/zlib/api.js @@ -1,4 +1,6 @@ -const api = { +import { lib_api_typed } from 'lib/@typify/typify.js'; + +const api = lib_api_typed({ deflate: { parameters: ['buffer', 'u32', 'buffer', 'u32'], pointers: ['uint8_t*', ,'uint8_t*'], @@ -11,7 +13,7 @@ const api = { result: 'u32', name: 'zlib_inflate' } -} +}) const includes = ['zlib.h', 'stdint.h', 'stdlib.h'] const preamble = ` #define Z_DEFAULT_MEMLEVEL 8 @@ -52,7 +54,7 @@ uint32_t zlib_inflate (uint8_t* src, uint32_t ssize, uint8_t* dest, uint32_t dsi inflateEnd(stream); free(stream); return written; -} +} ` //const libs = ['z'] const name = 'zlib' From 1e744ac93f0b86fc318a4acadf60e5b6662b66ee Mon Sep 17 00:00:00 2001 From: lostrepo Date: Sun, 5 May 2024 13:32:59 +0300 Subject: [PATCH 2/4] feat: lo typedefs with type check setup (partially typed lo.core) missing lib/.d.ts typedefs --- globals.d.ts | 449 +++++++++++++++++++++++++++++++++++++++++++++----- jsconfig.json | 8 - tsconfig.json | 21 +++ 3 files changed, 428 insertions(+), 50 deletions(-) delete mode 100644 jsconfig.json create mode 100644 tsconfig.json diff --git a/globals.d.ts b/globals.d.ts index b164955..cbbdd44 100644 --- a/globals.d.ts +++ b/globals.d.ts @@ -1,9 +1,150 @@ -declare class TextEncoder { +/// +/// +// TODO: autogenerate everything below, extend from lib//api.js +// TODO: add other libs to be used as built-in with lo.library +// use global interface? module? import autogenerated interface from lib/@types/lib.d.ts? + +// generic typedef helper for classes: +// interface IClassX { ... } +// declare var ClassX: Constructor +// TODO: find solution to class declaration issues (TS class declaration !== JS class declaration) +interface Constructor { + readonly prototype: T; + new (): T; +} +type TextEncoderConstructor = Constructor; +type TextDecoderConstructor = Constructor; + +// override types for globally available names +declare var global: GlobalThis; +declare var onUnhandledRejection: OnUnhandledRejection; +declare var require: Require; +declare var TextEncoder: TextEncoderConstructor; +declare var TextDecoder: TextDecoderConstructor; +declare var lo: Runtime; +declare var console: Console; +declare class CString extends Uint8Array { + ptr: number; + size: number; +} + +interface GlobalThis extends GlobalThisBase { + globalThis: GlobalThis; + global: GlobalThis; + onUnhandledRejection: OnUnhandledRejection; + require: Require; + TextEncoder: TextEncoderConstructor; + TextDecoder: TextDecoderConstructor; + lo: Runtime; + console: Console; + CString: CString; +} + +// keep only things that we have, no need to confuse people +// TODO: in codegen replace with `type GlobalThisBase = typeof globalThis` +interface GlobalThisBase + extends Omit, + // we define those manually: + | 'global' + | 'globalThis' + | 'lo' + | 'onUnhandledRejection' + | 'require' + | 'TextDecoder' + | 'TextEncoder' + | 'console' + > {} + +type OnUnhandledRejection = (error: Error) => void; + +type Require = >( + file_path: string +) => T | undefined; + +interface Console { + log: (str: unknown) => number; + error: (str: unknown) => number; +} + +interface ITextEncoder { /** * The encoding supported by the `TextEncoder` instance. Always set to `'utf-8'`. */ - readonly encoding: "utf-8"; - constructor(encoding?: "utf-8"); + readonly encoding: string; /** * UTF-8 encodes the `input` string and returns a `Uint8Array` containing the * encoded bytes. @@ -23,20 +164,78 @@ declare class TextEncoder { * @param src The text to encode. * @param dest The array to hold the encode result. */ - encodeInto(src?: string, dest?: BufferSource): EncodeIntoResult; + encodeInto(src?: string, dest?: Uint8Array): number; } +interface ITextDecoder { + /** + * The encoding supported by the `TextEncoder` instance. Always set to `'utf-8'`. + */ + readonly encoding: string; + /** + * UTF-8 decodes the `Uint8Array` and returns an `input` string. + */ + decode(ptr_source?: typeof CString | Uint8Array): string; +} + +type ZeroOrMinusOne = 0 | -1; +type OS = 'mac' | 'win' | 'linux'; +type ARCH = 'x64' | 'arm64'; +type TypedArray = + | Uint8Array + | Int8Array + | Uint16Array + | Int16Array + | Uint32Array + | Int32Array + | Float32Array + | Float64Array + | BigUint64Array + | BigInt64Array + | ArrayBuffer; + +type Ptr = T & { + ptr: number; + size: number; +}; + +// TODO: find better way to type imports +type UnknownLib = Record< + T | string | number | symbol, + unknown +>; +type SetLibTypeIfNameMatches< + T extends string | number, + Name, + LibType, + FallbackType +> = Name extends T + ? T extends Name + ? Record + : FallbackType + : FallbackType; +type Library = + SetLibTypeIfNameMatches> + & { + handle?: number; + fileName?: string; + internal?: boolean; +}; + interface RuntimeVersion { - lo: string, - v8: string + lo: string; + v8: string; } +// TODO: autogenerate interface Core { - O_RDONLY: number; - open(path: string, flags: number, mode: number); + name: 'core', + // TODO: add missing declarations + // validate with list from: lo eval 'console.log(`"${Object.getOwnPropertyNames(lo.core).join(`":unknown;"`)}":unknown;`)' + open(path: string, flags: number, mode?: number): number; dlsym(handle: number, name: string): number; dlopen(path: string, flags: number): number; - strnlen(str: string, size: number); + strnlen(str: string | number, size: number): number; /** * Reads a file from the given path into a Uint8Array and returns it. * @param [path] The path to the file. @@ -49,28 +248,134 @@ interface Core { * @param {TypedArray}[buffer] The data write to the file. * @returns {number} Number of bytes written */ - write_file(path: string, buffer: Uint8Array, flags?: number, mode?: number): number; -} + write_file( + path: string, + buffer: Uint8Array, + flags?: number, + mode?: number + ): number; + os: OS; + arch: ARCH; + little_endian: boolean; + homedir: string; + defaultWriteFlags: number; + defaultWriteMode: number; + isatty(fd: number): 0 | 1; + mmap( + ptr: number, + length: number, + prot: number, + flags: number, + fd: number, + offset: number, + buf: Uint32Array + ): void; + fork(): number; + sysconf(num: number): number; + times(buf: TypedArray): number; + pread(num: number, buf: TypedArray, num2: number, num3: number): number; + waitpid(num: number, buf: TypedArray, num2: number): number; + execve(str: string, buf: TypedArray, buf2: TypedArray): number; + execvp(str: string, buf: TypedArray): number; + readlink(path: string, buf: TypedArray, num: number): number; + getcwd(ptr: number, num: number, buf: Uint32Array): void; + getenv(name: string, buf: Uint32Array): void; + setenv(name: string, value: string, overwrite?: number): ZeroOrMinusOne; + write_string(num: number, str: string): number; + fstat(fd: number, buf: TypedArray): number; + read(fd: number, buf: TypedArray, count: number): ZeroOrMinusOne; + write(fd: number, buf: TypedArray, count: number): number; + close(fd: number): ZeroOrMinusOne; + readFile(path: string, flags?: number, size?: number): Uint8Array; + writeFile( + path: string, + u8: Uint8Array, + flags?: number, + mode?: number + ): number; -declare class CString extends Uint8Array { - ptr: number; - size: number; + isFile(path: string): boolean; + // conditionally defined props + loader?: (specifier: string, resource: string) => string; + sync_loader?: (specifier: string, resource: string) => string; + binding_loader?: (name: T) => Library; + + // constants + S_IFBLK: number; + S_IFCHR: number; + S_IFIFO: number; + S_IRUSR: number; + S_IWUSR: number; + S_IRGRP: number; + S_IWGRP: number; + S_IROTH: number; + S_IWOTH: number; + O_RDONLY: number; + O_WRONLY: number; + O_CREAT: number; + S_IRWXU: number; + S_IRWXG: number; + S_IXOTH: number; + O_TRUNC: number; + STDIN: 0; + STDOUT: 1; + STDERR: 2; + O_CLOEXEC: number; + RUSAGE_SELF: number; + SEEK_SET: number; + SEEK_CUR: number; + SEEK_END: number; + S_IRWXO: number; + F_OK: number; + S_IFMT: number; + S_IFDIR: number; + S_IFREG: number; + NAME_MAX: number; + O_RDWR: number; + O_SYNC: number; + O_DIRECTORY: number; + F_SETFL: number; + O_NONBLOCK: number; + EAGAIN: number; + WNOHANG: number; + SIGTERM: number; + MAP_SHARED: number; + MAP_ANONYMOUS: number; + MAP_PRIVATE: number; + MS_ASYNC: number; + MS_SYNC: number; + MS_INVALIDATE: number; + _SC_CLK_TCK: number; + F_GETFL: number; + RTLD_NOW: number; + RTLD_LAZY: number; + RTLD_GLOBAL: number; + RTLD_LOCAL: number; + RTLD_NODELETE: number; + RTLD_NOLOAD: number; + RTLD_DEFAULT: number; + RTLD_NEXT: number; + PROT_READ: number; + PROT_WRITE: number; + PROT_EXEC: number; } +// TODO: autogenerate interface Runtime { - moduleCache: Map; - libCache: Map; - requireCache: Map; + // validate with list from: lo eval 'console.log(`"${Object.getOwnPropertyNames(lo).join(`":unknown;"`)}":unknown;`)' + moduleCache: Map>; + libCache: Map; + requireCache: Map; start: number; errno: number; - colors: any; + colors: Record, string>; core: Core; - libraries(): Array; - builtins(): Array; + libraries(): string[]; + builtins(): string[]; assert(expression: any, message?: string | Function): any; cstr(str: string): CString; load(name: string): any; - library(name: string): any; + library(name: T): Library; /** * Prints a string to the console * @param [str='a string'] The text to print. @@ -79,37 +384,97 @@ interface Runtime { exit(status: number): void; runMicroTasks(): void; hrtime(): number; - nextTick(callback: function): void; + nextTick(callback: Function): void; getAddress(buf: TypedArray): number; utf8Length(str: string): number; utf8EncodeInto(str: string, buf: TypedArray): number; utf8EncodeIntoAtOffset(str: string, buf: TypedArray, off: number): number; utf8_decode(address: number, len?: number): string; latin1Decode(address: number, len?: number): string; - utf8Encode(str: sring): TypedArray; - wrap(handle: TypedArray, fn: Function, plen: number): function; + utf8Encode(str: string): Uint8Array; + utf8Decode: Runtime['utf8_decode']; + wrap< + Handle extends TypedArray, + WrappedFnArgs extends unknown[], + >( + handle: Handle, + fn: (...args: [...WrappedFnArgs, Handle]) => unknown, + plen: number + ): (...args: WrappedFnArgs) => number; addr(handle: TypedArray): number; version: RuntimeVersion; - args: Array; + args: string[]; + argv: number; + argc: number; workerSource: string; builtin(path: string): string; - os(): string; - arch(): string; - getenv(string): string; - async evaluateModule(identifier: string): Promise; - loadModule(src: string, specifier: string): any; + os(): OS; + arch(): ARCH; + getenv(str: string): string; + evaluateModule(identifier: number): Promise; + loadModule( + source: string, + specifier: string + ): { + requests: string; + isSourceTextModule: boolean; + status: number; + specifier: string; + src: string; + identity: number; + scriptId: number; + // js land extensions on returned value + resource?: string; + evaluated?: boolean; + namespace?: object; // module namespace object + }; readMemory(dest: TypedArray, start: number, len: number): void; - wrapMemory(start: number, size: number, free?: number); - unwrapMemory(buffer: ArrayBuffer); - ptr(u8: TypedArray): TypedArray; - register_callback(ptr: number, fn: Function); - setModuleCallbacks(on_module_load: Function, - on_module_instantiate: Function); -} + wrapMemory(start: number, size: number, free?: number): ArrayBuffer; + unwrapMemory(buffer: ArrayBuffer): void; + ptr(u8: T): Ptr; + register_callback(ptr: number, fn: Function): void; + registerCallback: Runtime['register_callback']; + setModuleCallbacks( + on_module_load: Function, + on_module_instantiate: Function + ): void; -declare var lo: Runtime & typeof globalThis; + utf8EncodeIntoPtr(str: string, ptr: number): number; + runScript(source: string, path: string /* resource name */): void; + pumpMessageLoop(): void; + readMemoryAtOffset( + u8: TypedArray, + start: number, + size: number, + offset: number + ): void; + setFlags(str: string): void; + getMeta: unknown; -declare var TextEncoder: { - prototype: TextEncoder; - new(): TextEncoder; -} & typeof globalThis; + setenv: Core['setenv']; + getcwd(): string; + run_script: Runtime['runScript']; + bindings: Runtime['libraries']; + evaluate_module: Runtime['evaluateModule']; + get_address: Runtime['getAddress']; + get_meta: Runtime['getMeta']; + latin1_decode: Runtime['latin1Decode']; + lib_cache: Runtime['libCache']; + load_module: Runtime['loadModule']; + module_cache: Runtime['moduleCache']; + next_tick: Runtime['nextTick']; + pump_message_loop: Runtime['pumpMessageLoop']; + read_memory: Runtime['readMemory']; + read_memory_at_offset: Runtime['readMemoryAtOffset']; + require_cache: Runtime['requireCache']; + run_microtasks: Runtime['runMicroTasks']; + set_flags: Runtime['setFlags']; + set_module_callbacks: Runtime['setModuleCallbacks']; + unwrap_memory: Runtime['unwrapMemory']; + utf8_encode: Runtime['utf8Encode']; + utf8_encode_into: Runtime['utf8EncodeInto']; + utf8_encode_into_ptr: Runtime['utf8EncodeIntoPtr']; + utf8_encode_into_at_offset: Runtime['utf8EncodeIntoAtOffset']; + utf8_length: Runtime['utf8Length']; + wrap_memory: Runtime['wrapMemory']; +} diff --git a/jsconfig.json b/jsconfig.json deleted file mode 100644 index fd0705c..0000000 --- a/jsconfig.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "compilerOptions": { - "checkJs": true, - "module": "ES2022", - "target": "ES2022" - }, - "exclude": ["scratch", "v8", ".vscode", ".git", ".github"] -} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..bd4f0bb --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,21 @@ +{ + "files": ["main.js"], + "compilerOptions": { + "paths": { + "lib": ["./lib"] + }, + "types": [], + "target": "es2022", + "lib": ["es2023"], + "outDir": "dist", + "allowJs": true, + "checkJs": true, + "strict": true, + "noImplicitAny": false, + "isolatedModules": true, + "noEmit": false, + "module": "es2022" + }, + "exclude": ["scratch", "v8", ".vscode", ".git", ".github"], + "include": ["globals.d.ts", "lib"] +} From c7afb6785c7596dc7839ea0a78bb009e80e9cdf6 Mon Sep 17 00:00:00 2001 From: lostrepo Date: Sun, 5 May 2024 13:47:05 +0300 Subject: [PATCH 3/4] feat: lo init pick up typedefs and readme --- lib/build.js | 102 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 64 insertions(+), 38 deletions(-) diff --git a/lib/build.js b/lib/build.js index 6a2565d..42de8ab 100644 --- a/lib/build.js +++ b/lib/build.js @@ -2,7 +2,7 @@ import { is_file, is_dir, mkdir_all_safe } from 'lib/fs.js' import { inflate } from 'lib/inflate.js' import { fetch } from 'lib/curl.js' import { untar } from 'lib/untar.js' -import { +import { bindings, linkerScript, headerFile, config, linkArgs, libPaths } from 'lib/gen.js' import { exec } from 'lib/proc.js' @@ -11,7 +11,7 @@ import { fileName, extName, join, baseName } from 'lib/path.js' const { core, getenv, getcwd, assert, colors } = lo const { AM, AY, AG, AD } = colors const { - write_file, chdir, mkdir, read_file, unlink, rename, + write_file, chdir, mkdir, read_file, unlink, rename, S_IXOTH, S_IRWXU, S_IRWXG, S_IROTH, defaultWriteFlags } = core @@ -71,8 +71,8 @@ async function create_lo_home () { assert(chdir(LO_HOME) === 0) const file_name = `libv8_monolith-${os}-${arch}.a.gz` console.log(`${AY}download v8 static lib for version ${AD}${v8}`) - const size = - fetch(`${v8_url_prefix}/${v8}/libv8_monolith-${os}-${arch}.a.gz`, + const size = + fetch(`${v8_url_prefix}/${v8}/libv8_monolith-${os}-${arch}.a.gz`, file_name) assert(size > 0) console.log(`${AY}downloaded${AD} ${file_name} ${AG}size${AY} ${size}`) @@ -85,7 +85,7 @@ async function create_lo_home () { assert(is_file(v8_lib)) assert(chdir(cwd) === 0) } -} +} // todo: change these methods to accept objects, not filenames async function compile_bindings (lib, verbose = false, opt = OPT, shared = true) { @@ -146,14 +146,14 @@ async function compile_bindings (lib, verbose = false, opt = OPT, shared = true) } console.log(`${AY}compile${AD} ${def.name}.cc ${AY}with${AG} ${CXX}${AD}`) unlink(`${def.name}.o`) - exec2([...CXX.split(' '), ...CFLAGS, ...opt.split(' '), `-I${LO_HOME}`, `-I${LO_HOME}/v8`, + exec2([...CXX.split(' '), ...CFLAGS, ...opt.split(' '), `-I${LO_HOME}`, `-I${LO_HOME}/v8`, ...include_paths.map(p => `-I${p}`), '-I.', `-I${LO_HOME}/v8/include`, `-I${lib_dir}`, ...WARN, '-o', `${def.name}.o`, `${def.name}.cc`], verbose) console.log(`${AY}static lib ${AD} ${def.name}.a`) unlink(`${def.name}.a`) if (obj && obj.length) { - exec2(['ar', 'crsT', `${def.name}.a`, `${def.name}.o`, + exec2(['ar', 'crsT', `${def.name}.a`, `${def.name}.o`, ...obj.filter(f => extName(f) === 'o')], verbose) } else { exec2(['ar', 'crsT', `${def.name}.a`, `${def.name}.o`], verbose) @@ -162,17 +162,17 @@ async function compile_bindings (lib, verbose = false, opt = OPT, shared = true) console.log(`${AY}shared lib ${AD} ${def.name}.so ${AY}with${AG} ${CXX}${AD}`) unlink(`${def.name}.so`) if (os === 'mac') { - exec2([...LINK.split(' '), '-bundle_loader', LO_PATH, ...LARGS, ...opt.split(' '), '-bundle', ...WARN, '-o', - `${def.name}.so`, `${def.name}.o`, - ...(obj || []), - ...(libs || []).map(l => `-l${l}`), + exec2([...LINK.split(' '), '-bundle_loader', LO_PATH, ...LARGS, ...opt.split(' '), '-bundle', ...WARN, '-o', + `${def.name}.so`, `${def.name}.o`, + ...(obj || []), + ...(libs || []).map(l => `-l${l}`), ...(lib_paths || []).map(l => `-L${l}`)], verbose) } else if (os === 'linux') { - exec2([...LINK.split(' '), ...LARGS, ...opt.split(' '), '-shared', ...WARN, '-o', + exec2([...LINK.split(' '), ...LARGS, ...opt.split(' '), '-shared', ...WARN, '-o', `${def.name}.so`, `${def.name}.o`, ...(obj || []), - ...(libs || []).map(l => `-l${l}`), + ...(libs || []).map(l => `-l${l}`), ...(lib_paths || []).map(l => `-L${l}`)], verbose) } @@ -198,10 +198,10 @@ function create_builtins (libs = [], main = 'main.js', os) { return linkerScript(path) } config.os = 'linux' - write_file(`${LO_HOME}/builtins_linux.S`, + write_file(`${LO_HOME}/builtins_linux.S`, encoder.encode(`${Array.from(new Set([main, ...libs])).map(verify_path).join('')}.section .note.GNU-stack,"",@progbits`)) config.os = 'mac' - write_file(`${LO_HOME}/builtins.S`, + write_file(`${LO_HOME}/builtins.S`, encoder.encode(Array.from(new Set([main, ...libs])).map(verify_path).join(''))) config.os = os } @@ -288,8 +288,8 @@ function check_compilers () { } -async function build_runtime ({ libs = lo.builtins(), bindings = lo.libraries(), - embeds = [], target, link_type = LINK_TYPE, opt = OPT, +async function build_runtime ({ libs = lo.builtins(), bindings = lo.libraries(), + embeds = [], target, link_type = LINK_TYPE, opt = OPT, v8_opts = {}, index = '', main = 'main.js' }, verbose = false) { const cwd = getcwd() if (index) embeds.push(index) @@ -317,14 +317,14 @@ async function build_runtime ({ libs = lo.builtins(), bindings = lo.libraries(), exec2([...CC.split(' '), '-c', 'builtins.S', '-o', 'builtins.o'], verbose) } console.log(`${AY}compile${AD} main.cc`) - exec2([...CXX.split(' '), `-DRUNTIME="${RUNTIME}"`, `-DVERSION="${VERSION}"`, - ...CFLAGS, ...opt.split(' '), `-I${LO_HOME}`, `-I${LO_HOME}/v8`, - '-I.', `-I${LO_HOME}/v8/include`, ...WARN, '-o', 'main.o', 'main.cc'], + exec2([...CXX.split(' '), `-DRUNTIME="${RUNTIME}"`, `-DVERSION="${VERSION}"`, + ...CFLAGS, ...opt.split(' '), `-I${LO_HOME}`, `-I${LO_HOME}/v8`, + '-I.', `-I${LO_HOME}/v8/include`, ...WARN, '-o', 'main.o', 'main.cc'], verbose) console.log(`${AY}compile${AD} lo.cc`) - exec2([...CXX.split(' '), `-DRUNTIME="${RUNTIME}"`, `-DVERSION="${VERSION}"`, - ...CFLAGS, ...opt.split(' '), `-I${LO_HOME}`, `-I${LO_HOME}/v8`, - '-I.', `-I${LO_HOME}/v8/include`, ...WARN, '-o', `${target}.o`, `lo.cc`], + exec2([...CXX.split(' '), `-DRUNTIME="${RUNTIME}"`, `-DVERSION="${VERSION}"`, + ...CFLAGS, ...opt.split(' '), `-I${LO_HOME}`, `-I${LO_HOME}/v8`, + '-I.', `-I${LO_HOME}/v8/include`, ...WARN, '-o', `${target}.o`, `lo.cc`], verbose) console.log(`${AY}link runtime ${AD}`) assert(chdir(cwd) === 0) @@ -337,7 +337,7 @@ async function build_runtime ({ libs = lo.builtins(), bindings = lo.libraries(), return join(cwd, f) } return f - }) + }) assert(chdir(LO_HOME) === 0) let dynamic_libs = await linkArgs(platform_bindings.map(n => `lib/${n}/api.js`)) if (link_type.split(' ').includes('-static')) { @@ -347,9 +347,9 @@ async function build_runtime ({ libs = lo.builtins(), bindings = lo.libraries(), let lib_paths = await libPaths(platform_bindings.map(n => `lib/${n}/api.js`), { prefix: PREFIX }) let bin = target if (cwd !== LO_HOME) bin = `${join(cwd, target)}` - exec2([...LINK.split(' '), ...LARGS, ...opt.split(' '), ...link_type.split(' '), ...WARN, '-o', - `${bin}`, `${target}.o`, 'main.o', 'builtins.o', 'v8/libv8_monolith.a', - ...static_libs, ...dynamic_libs, ...lib_paths].filter(v => v).flat(), verbose) + exec2([...LINK.split(' '), ...LARGS, ...opt.split(' '), ...link_type.split(' '), ...WARN, '-o', + `${bin}`, `${target}.o`, 'main.o', 'builtins.o', 'v8/libv8_monolith.a', + ...static_libs, ...dynamic_libs, ...lib_paths].filter(v => v).flat(), verbose) assert(chdir(cwd) === 0) } @@ -373,7 +373,7 @@ const constants = {} // put comments in here export { name, api, constants, preamble } -` +` } function generate_config (config) { @@ -497,17 +497,43 @@ lib/**/*.a lib/**/*.so lib/**/deps globals.d.ts -jsconfig.json +tsconfig.json ${app_name} -`)) - write_file(`jsconfig.json`, encoder.encode(`{ +`)); + + write_file(`tsconfig.json`, encoder.encode(`{ + "files": ["${config.default.index}"], "compilerOptions": { + "paths": { + "lib": ["${LO_HOME}/lib"] + }, + "types": [], + "target": "es2022", + "lib": ["es2023"], + "outDir": "dist", + "allowJs": true, "checkJs": true, - "module": "ES2022", - "target": "ES2022" + "strict": true, + "noImplicitAny": false, + "isolatedModules": true, + "noEmit": false, + "module": "es2022" }, - "exclude": ["scratch", "v8", ".vscode", ".git", ".github"] -}`)) + "exclude": ["scratch", "v8", ".vscode", ".git", ".github"], + "include": ["globals.d.ts", "lib"] +}`)); + + write_file(`README.md`, encoder.encode(` +# Build +\`\`\`sh +lo build runtime ${cwd}/${app_name} +\`\`\` +# Run +\`\`\`sh +./${app_name} +\`\`\` + `)); + if (!is_file(`${app_name}.js`)) { write_file(`${app_name}.js`, encoder.encode(`console.log('hello')`)) } @@ -528,7 +554,7 @@ const RUNTIME = getenv('LO_RUNTIME') || 'lo' const TARGET = getenv('LO_TARGET') const LINK_TYPE = getenv('LO_LINK_TYPE') || '-rdynamic' const OPT = getenv('LO_OPT') || '-O3 -march=native -mtune=native' -const WARN = (getenv('LO_WARN') || +const WARN = (getenv('LO_WARN') || '-Werror -Wpedantic -Wall -Wextra -Wno-unused-parameter').split(' ') const cwd = getcwd() const LO_HOME = getenv('LO_HOME') || join(cwd, '.lo') @@ -539,7 +565,7 @@ const url_prefix = getenv('LO_URL_PREFIX') || `https://github.com/${org}` const v8_path = getenv('LO_V8_PATH') || 'v8/releases/download' const v8_url_prefix = `${url_prefix}/${v8_path}` // todo: way to override these - usse env? -// todo: only set this if memory is > 16 GB on x86_64 +// todo: only set this if memory is > 16 GB on x86_64 // --huge-max-old-generation-size let defaultOpts = { v8_cleanup: 0, v8_threads: 2, on_exit: 0, @@ -602,7 +628,7 @@ if (os === 'mac') { LO_PATH = lo.latin1Decode(path_name.ptr, len) } -export { +export { build, build_runtime, create_binding, compile_bindings, create_lo_home, install, upgrade, uninstall, init, config From 2d089da385f2b450481fa58d54df9c49519da482 Mon Sep 17 00:00:00 2001 From: lostrepo Date: Sun, 5 May 2024 18:41:30 +0300 Subject: [PATCH 4/4] feat: mark api shape as generic const type downside - marked as readonly const object --- lib/@typify/typify.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/@typify/typify.d.ts b/lib/@typify/typify.d.ts index eddc615..d93a381 100644 --- a/lib/@typify/typify.d.ts +++ b/lib/@typify/typify.d.ts @@ -29,4 +29,4 @@ type LibApiItem = { nofast: boolean; declare_only: boolean; } | { type LibApi = Record; // TODO: add lib_exports_typed to get types for lib exports -export const lib_api_typed: (api: LibApi) => LibApi; +export const lib_api_typed: (api: T) => T;