@gjsify/utils 0.3.21 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/_virtual/_rolldown/runtime.js +1 -0
- package/lib/esm/base64.js +1 -1
- package/lib/esm/byte-array.js +1 -1
- package/lib/esm/callable.js +1 -1
- package/lib/esm/cli.js +1 -1
- package/lib/esm/defer.js +1 -1
- package/lib/esm/encoding.js +1 -1
- package/lib/esm/error.js +1 -1
- package/lib/esm/file.js +1 -1
- package/lib/esm/fs.js +1 -1
- package/lib/esm/gio-errors.js +1 -1
- package/lib/esm/gio.js +1 -1
- package/lib/esm/globals.js +1 -1
- package/lib/esm/main-loop.js +1 -1
- package/lib/esm/message.js +1 -1
- package/lib/esm/microtask.js +1 -1
- package/lib/esm/next-tick.js +1 -1
- package/lib/esm/path.js +1 -1
- package/lib/esm/structured-clone.js +1 -1
- package/lib/types/callable.d.ts +25 -8
- package/lib/types/structured-clone.d.ts +12 -4
- package/package.json +44 -41
- package/src/base64.ts +0 -78
- package/src/byte-array.ts +0 -12
- package/src/callable.ts +0 -37
- package/src/cli.ts +0 -10
- package/src/defer.ts +0 -11
- package/src/encoding.ts +0 -36
- package/src/error.ts +0 -38
- package/src/file.ts +0 -12
- package/src/fs.ts +0 -24
- package/src/gio-errors.ts +0 -156
- package/src/gio.ts +0 -67
- package/src/globals.ts +0 -13
- package/src/index.ts +0 -18
- package/src/log.spec.ts +0 -32
- package/src/main-loop.ts +0 -62
- package/src/message.ts +0 -11
- package/src/microtask.ts +0 -4
- package/src/next-tick.spec.ts +0 -116
- package/src/next-tick.ts +0 -112
- package/src/path.ts +0 -52
- package/src/structured-clone.ts +0 -242
- package/src/test.ts +0 -5
- package/tsconfig.json +0 -38
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Object.defineProperty,__name=(t,n)=>e(t,`name`,{value:n,configurable:!0});export{__name};
|
package/lib/esm/base64.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,t=new Uint8Array(256);for(let n=0;n<64;n++)t[e.charCodeAt(n)]=n;function atobPolyfill(e){if(typeof globalThis.atob==`function`)return globalThis.atob(e);let n=e.replace(/[=\s]/g,``),r=``,i=0,a=0;for(let e=0;e<n.length;e++)i=i<<6|t[n.charCodeAt(e)],a+=6,a>=8&&(a-=8,r+=String.fromCharCode(i>>a&255));return r}function btoaPolyfill(t){if(typeof globalThis.btoa==`function`)return globalThis.btoa(t);let n=``,r=0;for(;r+2<t.length;r+=3){let i=t.charCodeAt(r)<<16|t.charCodeAt(r+1)<<8|t.charCodeAt(r+2);n+=e[i>>18&63]+e[i>>12&63]+e[i>>6&63]+e[i&63]}if(r+1===t.length){let i=t.charCodeAt(r)<<16;n+=e[i>>18&63]+e[i>>12&63]+`==`}else if(r+2===t.length){let i=t.charCodeAt(r)<<16|t.charCodeAt(r+1)<<8;n+=e[i>>18&63]+e[i>>12&63]+e[i>>6&63]+`=`}return n}function base64Decode(e){let n=e.replace(/[=\s]/g,``),r=new Uint8Array(n.length*3>>2),i=0,a=0,o=0;for(let e=0;e<n.length;e++)i=i<<6|t[n.charCodeAt(e)],a+=6,a>=8&&(a-=8,r[o++]=i>>a&255);return r.subarray(0,o)}function base64Encode(t){let n=``,r=t.length;for(let i=0;i<r;i+=3){let a=t[i],o=i+1<r?t[i+1]:0,s=i+2<r?t[i+2]:0;n+=e[a>>2],n+=e[(a&3)<<4|o>>4],n+=i+1<r?e[(o&15)<<2|s>>6]:`=`,n+=i+2<r?e[s&63]:`=`}return n}export{atobPolyfill,base64Decode,base64Encode,btoaPolyfill};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";const e=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,t=new Uint8Array(256);for(let n=0;n<64;n++)t[e.charCodeAt(n)]=n;function atobPolyfill(e){if(typeof globalThis.atob==`function`)return globalThis.atob(e);let n=e.replace(/[=\s]/g,``),r=``,i=0,a=0;for(let e=0;e<n.length;e++)i=i<<6|t[n.charCodeAt(e)],a+=6,a>=8&&(a-=8,r+=String.fromCharCode(i>>a&255));return r}function btoaPolyfill(t){if(typeof globalThis.btoa==`function`)return globalThis.btoa(t);let n=``,r=0;for(;r+2<t.length;r+=3){let i=t.charCodeAt(r)<<16|t.charCodeAt(r+1)<<8|t.charCodeAt(r+2);n+=e[i>>18&63]+e[i>>12&63]+e[i>>6&63]+e[i&63]}if(r+1===t.length){let i=t.charCodeAt(r)<<16;n+=e[i>>18&63]+e[i>>12&63]+`==`}else if(r+2===t.length){let i=t.charCodeAt(r)<<16|t.charCodeAt(r+1)<<8;n+=e[i>>18&63]+e[i>>12&63]+e[i>>6&63]+`=`}return n}function base64Decode(e){let n=e.replace(/[=\s]/g,``),r=new Uint8Array(n.length*3>>2),i=0,a=0,o=0;for(let e=0;e<n.length;e++)i=i<<6|t[n.charCodeAt(e)],a+=6,a>=8&&(a-=8,r[o++]=i>>a&255);return r.subarray(0,o)}function base64Encode(t){let n=``,r=t.length;for(let i=0;i<r;i+=3){let a=t[i],o=i+1<r?t[i+1]:0,s=i+2<r?t[i+2]:0;n+=e[a>>2],n+=e[(a&3)<<4|o>>4],n+=i+1<r?e[(o&15)<<2|s>>6]:`=`,n+=i+2<r?e[s&63]:`=`}return n}export{atobPolyfill,base64Decode,base64Encode,btoaPolyfill};
|
package/lib/esm/byte-array.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function gbytesToUint8Array(e){return imports.byteArray.fromGBytes(e)}export{gbytesToUint8Array};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";function gbytesToUint8Array(e){return imports.byteArray.fromGBytes(e)}export{gbytesToUint8Array};
|
package/lib/esm/callable.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function makeCallable(e){return new Proxy(e,{apply(e,t,n){let r=Reflect.construct(e,n,e);for(let e of Reflect.ownKeys(r)){let n=Object.getOwnPropertyDescriptor(r,e);n&&Object.defineProperty(t,e,n)}return t}})}export{makeCallable};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";function makeCallable(e){return new Proxy(e,{apply(e,t,n){if(t==null||t===globalThis)return Reflect.construct(e,n,e);let r=Reflect.construct(e,n,e);for(let e of Reflect.ownKeys(r)){let n=Object.getOwnPropertyDescriptor(r,e);n&&Object.defineProperty(t,e,n)}return t}})}export{makeCallable};
|
package/lib/esm/cli.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"@girs/glib-2.0";const t=imports.byteArray,cli=n=>{let[r,i,a,o]=e.spawn_command_line_sync(n);if(a.byteLength)throw Error(t.toString(a));return t.toString(i)};export{cli};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import e from"@girs/glib-2.0";const t=imports.byteArray,cli=n=>{let[r,i,a,o]=e.spawn_command_line_sync(n);if(a.byteLength)throw Error(t.toString(a));return t.toString(i)};export{cli};
|
package/lib/esm/defer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function deferEmit(e,t,...n){setTimeout(()=>e.emit(t,...n),0)}export{deferEmit};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";function deferEmit(e,t,...n){setTimeout(()=>e.emit(t,...n),0)}export{deferEmit};
|
package/lib/esm/encoding.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=[`utf8`,`ascii`,`latin1`,`binary`,`base64`,`base64url`,`hex`,`ucs2`,`utf16le`];function normalizeEncoding(e){if(!e||e===`utf8`||e===`utf-8`)return`utf8`;switch((``+e).toLowerCase().replace(/-/g,``)){case`utf8`:return`utf8`;case`ascii`:return`ascii`;case`latin1`:case`binary`:return`latin1`;case`base64`:return`base64`;case`base64url`:return`base64url`;case`hex`:return`hex`;case`ucs2`:case`utf16le`:return`utf16le`;default:return`utf8`}}function checkEncoding(t){let n=(``+t).toLowerCase().replace(/-/g,``);if(!e.includes(n))throw TypeError(`Unknown encoding: ${t}`)}export{checkEncoding,normalizeEncoding};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";const e=[`utf8`,`ascii`,`latin1`,`binary`,`base64`,`base64url`,`hex`,`ucs2`,`utf16le`];function normalizeEncoding(e){if(!e||e===`utf8`||e===`utf-8`)return`utf8`;switch((``+e).toLowerCase().replace(/-/g,``)){case`utf8`:return`utf8`;case`ascii`:return`ascii`;case`latin1`:case`binary`:return`latin1`;case`base64`:return`base64`;case`base64url`:return`base64url`;case`hex`:return`hex`;case`ucs2`:case`utf16le`:return`utf16le`;default:return`utf8`}}function checkEncoding(t){let n=(``+t).toLowerCase().replace(/-/g,``);if(!e.includes(n))throw TypeError(`Unknown encoding: ${t}`)}export{checkEncoding,normalizeEncoding};
|
package/lib/esm/error.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const initErrorV8Methods=e=>{Error.captureStackTrace||(Error.captureStackTrace=function(e,t){let n=Error();Object.defineProperty(t||e,`stack`,{configurable:!0,get:function(){var e=n.stack;return Object.defineProperty(this,`stack`,{value:e}),e}})})};export{initErrorV8Methods};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";const initErrorV8Methods=e=>{Error.captureStackTrace||(Error.captureStackTrace=function(e,t){let n=Error();Object.defineProperty(t||e,`stack`,{configurable:!0,get:function getStack(){var e=n.stack;return Object.defineProperty(this,`stack`,{value:e}),e}})})};export{initErrorV8Methods};
|
package/lib/esm/file.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"@girs/glib-2.0";const t=imports.byteArray,readJSON=n=>{let[r,i]=e.file_get_contents(n);if(r)return JSON.parse(t.toString(i));throw Error(`Error on require "${n}"`)};export{readJSON};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import e from"@girs/glib-2.0";const t=imports.byteArray,readJSON=n=>{let[r,i]=e.file_get_contents(n);if(r)return JSON.parse(t.toString(i));throw Error(`Error on require "${n}"`)};export{readJSON};
|
package/lib/esm/fs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"@girs/gio-2.0";import t from"@girs/giounix-2.0";const existsFD=e=>{try{return t.InputStream.new(e,!1).close(null),!0}catch{return!1}};function existsSync(t){return typeof t!=`string`||t===``?!1:e.File.new_for_path(t).query_exists(null)}export{existsFD,existsSync};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import e from"@girs/gio-2.0";import t from"@girs/giounix-2.0";const existsFD=e=>{try{return t.InputStream.new(e,!1).close(null),!0}catch{return!1}};function existsSync(t){return typeof t!=`string`||t===``?!1:e.File.new_for_path(t).query_exists(null)}export{existsFD,existsSync};
|
package/lib/esm/gio-errors.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e={0:`EIO`,1:`ENOENT`,2:`EEXIST`,3:`EISDIR`,4:`ENOTDIR`,5:`ENOTEMPTY`,6:`ENOENT`,7:`ENFILE`,9:`EACCES`,10:`ENFILE`,11:`EINVAL`,12:`ELOOP`,13:`ENOSPC`,14:`EACCES`,17:`ELOOP`,19:`ENOSPC`,20:`ENOTSUP`,22:`EMFILE`,24:`EROFS`,25:`ECANCELED`,26:`EBUSY`,27:`ETIMEDOUT`,28:`EHOSTUNREACH`,30:`EHOSTUNREACH`,31:`ENETUNREACH`,32:`ECONNREFUSED`,33:`EADDRINUSE`,34:`ECONNRESET`,36:`EPIPE`,38:`ENETUNREACH`,39:`ECONNREFUSED`,40:`ECONNREFUSED`,41:`EACCES`,44:`ECONNRESET`,46:`EMSGSIZE`};function createNodeError(t,n,r){let i=t,a=e[i?.code??-1]||`EIO`,o=`${a}: ${i?.message||`unknown error`}, ${n}`;r?.path&&(o+=` '${r.path}'`),r?.dest&&(o+=` -> '${r.dest}'`),r?.address&&(o+=` ${r.address}`),r?.port!=null&&(o+=`:${r.port}`);let s=Error(o);return s.code=a,s.syscall=n,s.errno=-(i?.code||0),r?.path&&(s.path=r.path),r?.address&&(s.address=r.address),r?.port!=null&&(s.port=r.port),s}function isNotFoundError(e){let t=e;return t?.code===1||t?.code===`ENOENT`}const t={0:`EEXIST`,1:`EISDIR`,2:`EACCES`,3:`ENAMETOOLONG`,4:`ENOENT`,5:`ENOTDIR`,6:`ENXIO`,7:`ENODEV`,8:`EROFS`,11:`ELOOP`,12:`ENOSPC`,13:`ENOMEM`,14:`EMFILE`,15:`ENFILE`,16:`EBADF`,17:`EINVAL`,18:`EPIPE`,21:`EIO`,22:`EPERM`,24:`EIO`};function createGLibFileError(e,n,r){let i=e,a=t[i?.code??-1]??`EIO`,o=`${a}: ${i?.message||`unknown error`}, ${n}`;r?.path&&(o+=` '${r.path}'`),r?.dest&&(o+=` -> '${r.dest}'`);let s=Error(o);return s.code=a,s.syscall=n,s.errno=-(i?.code||0),r?.path&&(s.path=r.path),s}export{e as GIO_ERROR_TO_NODE,t as GLIB_FILE_ERROR_TO_NODE,createGLibFileError,createNodeError,isNotFoundError};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";const e={0:`EIO`,1:`ENOENT`,2:`EEXIST`,3:`EISDIR`,4:`ENOTDIR`,5:`ENOTEMPTY`,6:`ENOENT`,7:`ENFILE`,9:`EACCES`,10:`ENFILE`,11:`EINVAL`,12:`ELOOP`,13:`ENOSPC`,14:`EACCES`,17:`ELOOP`,19:`ENOSPC`,20:`ENOTSUP`,22:`EMFILE`,24:`EROFS`,25:`ECANCELED`,26:`EBUSY`,27:`ETIMEDOUT`,28:`EHOSTUNREACH`,30:`EHOSTUNREACH`,31:`ENETUNREACH`,32:`ECONNREFUSED`,33:`EADDRINUSE`,34:`ECONNRESET`,36:`EPIPE`,38:`ENETUNREACH`,39:`ECONNREFUSED`,40:`ECONNREFUSED`,41:`EACCES`,44:`ECONNRESET`,46:`EMSGSIZE`};function createNodeError(t,n,r){let i=t,a=e[i?.code??-1]||`EIO`,o=`${a}: ${i?.message||`unknown error`}, ${n}`;r?.path&&(o+=` '${r.path}'`),r?.dest&&(o+=` -> '${r.dest}'`),r?.address&&(o+=` ${r.address}`),r?.port!=null&&(o+=`:${r.port}`);let s=Error(o);return s.code=a,s.syscall=n,s.errno=-(i?.code||0),r?.path&&(s.path=r.path),r?.address&&(s.address=r.address),r?.port!=null&&(s.port=r.port),s}function isNotFoundError(e){let t=e;return t?.code===1||t?.code===`ENOENT`}const t={0:`EEXIST`,1:`EISDIR`,2:`EACCES`,3:`ENAMETOOLONG`,4:`ENOENT`,5:`ENOTDIR`,6:`ENXIO`,7:`ENODEV`,8:`EROFS`,11:`ELOOP`,12:`ENOSPC`,13:`ENOMEM`,14:`EMFILE`,15:`ENFILE`,16:`EBADF`,17:`EINVAL`,18:`EPIPE`,21:`EIO`,22:`EPERM`,24:`EIO`};function createGLibFileError(e,n,r){let i=e,a=t[i?.code??-1]??`EIO`,o=`${a}: ${i?.message||`unknown error`}, ${n}`;r?.path&&(o+=` '${r.path}'`),r?.dest&&(o+=` -> '${r.dest}'`);let s=Error(o);return s.code=a,s.syscall=n,s.errno=-(i?.code||0),r?.path&&(s.path=r.path),s}export{e as GIO_ERROR_TO_NODE,t as GLIB_FILE_ERROR_TO_NODE,createGLibFileError,createNodeError,isNotFoundError};
|
package/lib/esm/gio.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"@girs/glib-2.0";const t=imports.byteArray;function gioAsync(e,t,n,...r){return new Promise((i,a)=>{e[t](...r,(t,r)=>{try{i(e[n](r))}catch(e){a(e)}})})}async function readBytesAsync(n,r=4096,i=e.PRIORITY_DEFAULT,a=null){return new Promise((e,o)=>{n.read_bytes_async(r,i,a,(r,i)=>{try{let r=n.read_bytes_finish(i);return r.get_size()===0?e(null):e(t.fromGBytes(r))}catch(e){o(e)}})})}async function*inputStreamAsyncIterator(t,n=4096,r=e.PRIORITY_DEFAULT,i=null){let a;for(;(a=await readBytesAsync(t,n,r,i))!==null;)yield a}export{gioAsync,inputStreamAsyncIterator,readBytesAsync};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import e from"@girs/glib-2.0";const t=imports.byteArray;function gioAsync(e,t,n,...r){return new Promise((i,a)=>{e[t](...r,(t,r)=>{try{i(e[n](r))}catch(e){a(e)}})})}async function readBytesAsync(n,r=4096,i=e.PRIORITY_DEFAULT,a=null){return new Promise((e,o)=>{n.read_bytes_async(r,i,a,(r,i)=>{try{let r=n.read_bytes_finish(i);return r.get_size()===0?e(null):e(t.fromGBytes(r))}catch(e){o(e)}})})}async function*inputStreamAsyncIterator(t,n=4096,r=e.PRIORITY_DEFAULT,i=null){let a;for(;(a=await readBytesAsync(t,n,r,i))!==null;)yield a}export{gioAsync,inputStreamAsyncIterator,readBytesAsync};
|
package/lib/esm/globals.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function registerGlobal(e,t){globalThis[e]===void 0&&(globalThis[e]=t)}export{registerGlobal};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";function registerGlobal(e,t){globalThis[e]===void 0&&(globalThis[e]=t)}export{registerGlobal};
|
package/lib/esm/main-loop.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
let e=!1,t=null;function ensureMainLoop(){let n=globalThis.imports;if(!n)return;if(e)return t;let r=n.gi.GLib;if(t=new r.MainLoop(null,!1),e=!0,r.main_depth()===0)try{t.runAsync()}catch{}return t}function quitMainLoop(){t&&=(t.quit(),e=!1,null)}export{ensureMainLoop,quitMainLoop};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";let e=!1,t=null;function ensureMainLoop(){let n=globalThis.imports;if(!n)return;if(e)return t;let r=n.gi.GLib;if(t=new r.MainLoop(null,!1),e=!0,r.main_depth()===0)try{t.runAsync()}catch{}return t}function quitMainLoop(){t&&=(t.quit(),e=!1,null)}export{ensureMainLoop,quitMainLoop};
|
package/lib/esm/message.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const notImplemented=e=>{let t=e?`Not implemented: ${e}`:`Not implemented`;throw Error(t)},warnNotImplemented=e=>{let t=e?`Not implemented: ${e}`:`Not implemented`;return console.warn(t),t};export{notImplemented,warnNotImplemented};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";const notImplemented=e=>{let t=e?`Not implemented: ${e}`:`Not implemented`;throw Error(t)},warnNotImplemented=e=>{let t=e?`Not implemented: ${e}`:`Not implemented`;return console.warn(t),t};export{notImplemented,warnNotImplemented};
|
package/lib/esm/microtask.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const queueMicrotask=e=>{Promise.resolve().then(e)};export{queueMicrotask};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";const queueMicrotask=e=>{Promise.resolve().then(e)};export{queueMicrotask};
|
package/lib/esm/next-tick.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=[];let t=!1;function drainOnce(n){let r=Math.min(64,e.length);for(let t=0;t<r;t++){let t=e.shift();try{t()}catch(e){try{n.log_default_handler(`gjsify-nextTick`,n.LogLevelFlags.LEVEL_WARNING,String(e?.stack||e),null)}catch{}}}e.length>0?n.timeout_add(n.PRIORITY_DEFAULT,1,()=>(drainOnce(n),!1)):t=!1}function tryGLibTimeout(n){let r=globalThis.imports?.gi?.GLib;return r?.timeout_add?(e.push(n),t||(t=!0,r.timeout_add(r.PRIORITY_DEFAULT,0,()=>(drainOnce(r),!1))),!0):!1}function __resetBurstStateForTests(){e.length=0,t=!1}const nextTick=(e,...t)=>{let n=t.length>0?()=>e(...t):e;if(!tryGLibTimeout(n)){if(typeof globalThis.process?.nextTick==`function`){globalThis.process.nextTick(e,...t);return}if(typeof queueMicrotask==`function`){queueMicrotask(n);return}Promise.resolve().then(n)}};export{__resetBurstStateForTests,nextTick};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";const e=[];let t=!1;function drainOnce(n){let r=Math.min(64,e.length);for(let t=0;t<r;t++){let t=e.shift();try{t()}catch(e){try{n.log_default_handler(`gjsify-nextTick`,n.LogLevelFlags.LEVEL_WARNING,String(e?.stack||e),null)}catch{}}}e.length>0?n.timeout_add(n.PRIORITY_DEFAULT,1,()=>(drainOnce(n),!1)):t=!1}function tryGLibTimeout(n){let r=globalThis.imports?.gi?.GLib;return r?.timeout_add?(e.push(n),t||(t=!0,r.timeout_add(r.PRIORITY_DEFAULT,0,()=>(drainOnce(r),!1))),!0):!1}function __resetBurstStateForTests(){e.length=0,t=!1}const nextTick=(e,...t)=>{let n=t.length>0?()=>e(...t):e;if(!tryGLibTimeout(n)){if(typeof globalThis.process?.nextTick==`function`){globalThis.process.nextTick(e,...t);return}if(typeof queueMicrotask==`function`){queueMicrotask(n);return}Promise.resolve().then(n)}};export{__resetBurstStateForTests,nextTick};
|
package/lib/esm/path.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"@girs/glib-2.0";import t from"@girs/gio-2.0";const{File:n}=t,_getProgramDir=e=>{let n=e.query_info(`standard::`,t.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null);return n.get_is_symlink()?e.get_parent().resolve_relative_path(n.get_symlink_target()).get_parent():e.get_parent()},resolve=(e,...t)=>{let r=n.new_for_path(e);for(let e of t)r=r.resolve_relative_path(e);return r},getProgramExe=()=>{let t=e.get_current_dir();return n.new_for_path(t).resolve_relative_path(imports.system.programInvocationName)},getProgramDir=()=>_getProgramDir(getProgramExe()).get_path(),getPathSeparator=()=>{let t=e.get_current_dir();return/^\//.test(t)?`/`:`\\`},getNodeModulesPath=()=>{let e=n.new_for_path(getProgramDir()),t=!1;do{e=e.resolve_relative_path(`..`);let n=e.resolve_relative_path(`node_modules`);t=n.query_exists(null),t&&(e=n)}while(e.has_parent(null)&&!t);return e};export{getNodeModulesPath,getPathSeparator,getProgramDir,getProgramExe,resolve};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import e from"@girs/glib-2.0";import t from"@girs/gio-2.0";const{File:n}=t,_getProgramDir=e=>{let n=e.query_info(`standard::`,t.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null);return n.get_is_symlink()?e.get_parent().resolve_relative_path(n.get_symlink_target()).get_parent():e.get_parent()},resolve=(e,...t)=>{let r=n.new_for_path(e);for(let e of t)r=r.resolve_relative_path(e);return r},getProgramExe=()=>{let t=e.get_current_dir();return n.new_for_path(t).resolve_relative_path(imports.system.programInvocationName)},getProgramDir=()=>_getProgramDir(getProgramExe()).get_path(),getPathSeparator=()=>{let t=e.get_current_dir();return/^\//.test(t)?`/`:`\\`},getNodeModulesPath=()=>{let e=n.new_for_path(getProgramDir()),t=!1;do{e=e.resolve_relative_path(`..`);let n=e.resolve_relative_path(`node_modules`);t=n.query_exists(null),t&&(e=n)}while(e.has_parent(null)&&!t);return e};export{getNodeModulesPath,getPathSeparator,getProgramDir,getProgramExe,resolve};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const{toString:e}=Object.prototype;function classOf(t){return e.call(t).slice(8,-1)}function throwDataCloneError(e){let t=globalThis.DOMException;if(typeof t==`function`)throw new t(e,`DataCloneError`);let n=Error(e);throw n.name=`DataCloneError`,n}const t={Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError},n=new Set([`Int8Array`,`Uint8Array`,`Uint8ClampedArray`,`Int16Array`,`Uint16Array`,`Int32Array`,`Uint32Array`,`Float32Array`,`Float64Array`,`BigInt64Array`,`BigUint64Array`]);function internalClone(e,r){if(e==null)return e;let
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";const{toString:e}=Object.prototype;function classOf(t){return e.call(t).slice(8,-1)}function throwDataCloneError(e){let t=globalThis.DOMException;if(typeof t==`function`)throw new t(e,`DataCloneError`);let n=Error(e);throw n.name=`DataCloneError`,n}const t={Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError},n=new Set([`Int8Array`,`Uint8Array`,`Uint8ClampedArray`,`Int16Array`,`Uint16Array`,`Int32Array`,`Uint32Array`,`Float32Array`,`Float64Array`,`BigInt64Array`,`BigUint64Array`]);function internalClone(e,r,i){if(e==null)return e;let a=typeof e;if(a===`boolean`||a===`number`||a===`string`||a===`bigint`)return e;a===`symbol`&&throwDataCloneError(`Symbol cannot be cloned`),a===`function`&&throwDataCloneError(`Function cannot be cloned`);let o=e;if(r.has(o))return r.get(o);let s=classOf(o);if(s===`Date`)return new Date(o.getTime());if(s===`RegExp`)return new RegExp(o.source,o.flags);if(s===`Boolean`||s===`Number`||s===`String`)return Object(o.valueOf());if(s===`BigInt`)return Object(BigInt.prototype.valueOf.call(o));if(o instanceof Error){let e=o,n=e.constructor?.name,a=new(n&&t[n]||t[e.name]||Error)(e.message);return a.name=e.name,`cause`in e&&Object.defineProperty(a,`cause`,{value:internalClone(e.cause,r,i),writable:!0,enumerable:!1,configurable:!0}),a}if(s===`DOMException`){let e=globalThis.DOMException;if(typeof e==`function`){let t=o;return new e(t.message,t.name)}}if(s===`ArrayBuffer`){let e=o;if(i&&i.transferred.has(e)){let t=i.transferred.get(e);return r.set(o,t),t}(e.detached===!0||e.byteLength===0&&e.detached)&&throwDataCloneError(`ArrayBuffer is detached and cannot be cloned`);let t=e.slice(0);return r.set(o,t),t}if(s===`SharedArrayBuffer`)return o;if(s===`DataView`){let e=o,t=i?.viewSnapshots.get(o),n=internalClone(e.buffer,r,i),a=t?t.byteOffset:e.byteOffset,s=t?t.byteLength:e.byteLength,c=new DataView(n,a,s);return r.set(o,c),c}if(n.has(s)){let e=o,t=i?.viewSnapshots.get(o),n=internalClone(e.buffer,r,i),a=e.constructor,s=new a(n,t?t.byteOffset:e.byteOffset,t?t.length:e.length);return r.set(o,s),s}if(s===`Map`){let e=new Map;r.set(o,e);for(let[t,n]of o)e.set(internalClone(t,r,i),internalClone(n,r,i));return e}if(s===`Set`){let e=new Set;r.set(o,e);for(let t of o)e.add(internalClone(t,r,i));return e}{let e=globalThis,t=e.Blob,n=e.File;if(typeof n==`function`&&o instanceof n){let e=o;return new n([o],e.name,{type:e.type,lastModified:e.lastModified})}if(typeof t==`function`&&o instanceof t)return new t([o],{type:o.type})}if(o instanceof WeakMap&&throwDataCloneError(`WeakMap cannot be cloned`),o instanceof WeakSet&&throwDataCloneError(`WeakSet cannot be cloned`),o instanceof WeakRef&&throwDataCloneError(`WeakRef cannot be cloned`),typeof globalThis.Promise==`function`&&o instanceof Promise&&throwDataCloneError(`Promise cannot be cloned`),s===`Array`){let e=o,t=[];r.set(o,t);for(let n=0;n<e.length;n++)n in e&&(t[n]=internalClone(e[n],r,i));return t}if(s===`Object`||typeof o==`object`){let e={};r.set(o,e);for(let t of Object.keys(o))e[t]=internalClone(o[t],r,i);return e}throwDataCloneError(`${s} cannot be cloned`)}function structuredClone(e,t){let n=t?.transfer;if(!n||n.length===0)return internalClone(e,new Map);let r=new Set;for(let e of n)if(classOf(e)===`ArrayBuffer`){let t=e;t.detached===!0&&throwDataCloneError(`ArrayBuffer in transfer list is detached`),r.add(t)}let i=new Map;r.size>0&&snapshotViewsBackedByTransferredBuffers(e,r,i,new Set);let a=new Map;for(let e of r){let t=e;typeof t.transfer!=`function`&&throwDataCloneError(`ArrayBuffer.prototype.transfer() not available — runtime is not SM140+`),a.set(e,t.transfer())}return internalClone(e,new Map,{transferred:a,viewSnapshots:i})}function snapshotViewsBackedByTransferredBuffers(e,t,r,i){if(typeof e!=`object`||!e)return;let a=e;if(i.has(a))return;i.add(a);let o=classOf(a);if(o===`DataView`){let e=a;t.has(e.buffer)&&r.set(a,{byteOffset:e.byteOffset,length:0,byteLength:e.byteLength});return}if(n.has(o)){let e=a;t.has(e.buffer)&&r.set(a,{byteOffset:e.byteOffset,length:e.length,byteLength:e.byteLength});return}if(Array.isArray(a)){for(let e=0;e<a.length;e++)e in a&&snapshotViewsBackedByTransferredBuffers(a[e],t,r,i);return}if(o===`Map`){for(let[e,n]of a)snapshotViewsBackedByTransferredBuffers(e,t,r,i),snapshotViewsBackedByTransferredBuffers(n,t,r,i);return}if(o===`Set`){for(let e of a)snapshotViewsBackedByTransferredBuffers(e,t,r,i);return}if(o===`Object`)for(let e of Object.keys(a))snapshotViewsBackedByTransferredBuffers(a[e],t,r,i)}export{structuredClone};
|
package/lib/types/callable.d.ts
CHANGED
|
@@ -1,12 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Wrap an ES6 class so it supports both the modern `new Cls(...)` pattern and
|
|
3
|
-
* the legacy `Cls.call(thisArg, ...)`
|
|
4
|
-
*
|
|
5
|
-
* The `apply` trap
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
3
|
+
* the legacy `Cls.call(thisArg, ...)` / `Cls(...)` (no-`new`) patterns.
|
|
4
|
+
*
|
|
5
|
+
* The `apply` trap has two modes:
|
|
6
|
+
*
|
|
7
|
+
* 1. **`Cls.call(thisArg, ...)`** — a real consumer instance is provided.
|
|
8
|
+
* We materialise a temporary instance via `Reflect.construct` (so field
|
|
9
|
+
* initializers and constructor bodies run normally) and transplant its
|
|
10
|
+
* own property descriptors onto `thisArg`. This is how Node-era CJS
|
|
11
|
+
* consumers + `util.inherits(Sub, Cls)` chains expect to subclass our
|
|
12
|
+
* ES6 classes.
|
|
13
|
+
*
|
|
14
|
+
* 2. **`Cls(...)`** (called as a plain function — `thisArg` is `undefined`
|
|
15
|
+
* in strict mode or `globalThis` in sloppy mode) — we treat the call as
|
|
16
|
+
* a constructor call and return a fresh `new Cls(...)`. Node's stream
|
|
17
|
+
* constructors implement this guard explicitly:
|
|
18
|
+
* `if (!(this instanceof PassThrough)) return new PassThrough(...)`
|
|
19
|
+
* so consumers like `merge2` invoke `Stream.PassThrough(opts)` without
|
|
20
|
+
* `new` and rely on the result being a real instance. Without this
|
|
21
|
+
* branch the apply trap would crash with "undefined is not a non-null
|
|
22
|
+
* object" when it tried to `Object.defineProperty(thisArg, …)`.
|
|
23
|
+
*
|
|
24
|
+
* The default Proxy traps pass `construct`, `get` and `getPrototypeOf`
|
|
25
|
+
* straight through, so `new Wrapped()`, `Wrapped.prototype` (consulted by
|
|
26
|
+
* `util.inherits`) and `instance instanceof Wrapped` all behave identically
|
|
27
|
+
* to the underlying class.
|
|
11
28
|
*/
|
|
12
29
|
export declare function makeCallable<T extends new (...args: any[]) => any>(Cls: T): T;
|
|
@@ -2,14 +2,22 @@
|
|
|
2
2
|
* structuredClone polyfill implementing the HTML structured clone algorithm.
|
|
3
3
|
*
|
|
4
4
|
* Supports: primitives (incl. -0, NaN, Infinity, BigInt), wrapper objects,
|
|
5
|
-
* Date, RegExp, Error types, ArrayBuffer
|
|
6
|
-
* Blob, File, circular/shared references, plain objects
|
|
5
|
+
* Date, RegExp, Error types, ArrayBuffer (with transfer), TypedArrays,
|
|
6
|
+
* DataView, Map, Set, Blob, File, circular/shared references, plain objects
|
|
7
|
+
* and arrays.
|
|
7
8
|
*
|
|
8
9
|
* Throws DataCloneError for: functions, symbols, WeakMap, WeakSet, WeakRef, Promise.
|
|
9
10
|
*
|
|
11
|
+
* Transfer semantics: any `ArrayBuffer` listed in `options.transfer` is
|
|
12
|
+
* transferred to the clone via SM140's `ArrayBuffer.prototype.transfer()`
|
|
13
|
+
* (zero-copy, sender becomes detached). Non-`ArrayBuffer` entries are
|
|
14
|
+
* accepted but ignored — the caller (e.g. `MessagePort.postMessage`) is
|
|
15
|
+
* responsible for handling transferable objects that aren't structured-clone
|
|
16
|
+
* primitives (`MessagePort`, `ReadableStream`, …).
|
|
17
|
+
*
|
|
10
18
|
* @param value The value to clone
|
|
11
|
-
* @param
|
|
19
|
+
* @param options Optional transfer list
|
|
12
20
|
*/
|
|
13
|
-
export declare function structuredClone<T>(value: T,
|
|
21
|
+
export declare function structuredClone<T>(value: T, options?: {
|
|
14
22
|
transfer?: unknown[];
|
|
15
23
|
}): T;
|
package/package.json
CHANGED
|
@@ -1,44 +1,47 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
"name": "@gjsify/utils",
|
|
3
|
+
"version": "0.4.3",
|
|
4
|
+
"description": "Utils module for gjsify",
|
|
5
|
+
"module": "lib/esm/index.js",
|
|
6
|
+
"types": "lib/types/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib"
|
|
9
|
+
],
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./lib/types/index.d.ts",
|
|
14
|
+
"default": "./lib/esm/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./main-loop": {
|
|
17
|
+
"types": "./lib/types/main-loop.d.ts",
|
|
18
|
+
"default": "./lib/esm/main-loop.js"
|
|
19
|
+
}
|
|
12
20
|
},
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
21
|
+
"scripts": {
|
|
22
|
+
"clear": "rm -rf lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo test.gjs.mjs test.node.mjs || exit 0",
|
|
23
|
+
"check": "tsc --noEmit",
|
|
24
|
+
"build": "gjsify run build:gjsify && gjsify run build:types",
|
|
25
|
+
"build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
|
|
26
|
+
"build:types": "tsc",
|
|
27
|
+
"build:test": "gjsify run build:test:gjs",
|
|
28
|
+
"build:test:gjs": "gjsify build src/test.ts --app gjs --outfile test.gjs.js",
|
|
29
|
+
"test": "gjsify run build:gjsify && gjsify run build:test && gjsify run test:gjs",
|
|
30
|
+
"test:gjs": "gjsify run test.gjs.js"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"gjs",
|
|
34
|
+
"node",
|
|
35
|
+
"fs"
|
|
36
|
+
],
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@gjsify/cli": "workspace:^",
|
|
39
|
+
"typescript": "^6.0.3"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@girs/gio-2.0": "2.88.0-4.0.0-rc.15",
|
|
43
|
+
"@girs/giounix-2.0": "2.0.0-4.0.0-rc.15",
|
|
44
|
+
"@girs/gjs": "4.0.0-rc.15",
|
|
45
|
+
"@girs/glib-2.0": "2.88.0-4.0.0-rc.15"
|
|
16
46
|
}
|
|
17
|
-
|
|
18
|
-
"scripts": {
|
|
19
|
-
"clear": "rm -rf lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo test.gjs.mjs test.node.mjs || exit 0",
|
|
20
|
-
"check": "tsc --noEmit",
|
|
21
|
-
"build": "yarn build:gjsify && yarn build:types",
|
|
22
|
-
"build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
|
|
23
|
-
"build:types": "tsc",
|
|
24
|
-
"build:test": "yarn build:test:gjs",
|
|
25
|
-
"build:test:gjs": "gjsify build src/test.ts --app gjs --outfile test.gjs.js",
|
|
26
|
-
"test": "yarn build:gjsify && yarn build:test && yarn test:gjs",
|
|
27
|
-
"test:gjs": "gjsify run test.gjs.js"
|
|
28
|
-
},
|
|
29
|
-
"keywords": [
|
|
30
|
-
"gjs",
|
|
31
|
-
"node",
|
|
32
|
-
"fs"
|
|
33
|
-
],
|
|
34
|
-
"devDependencies": {
|
|
35
|
-
"@gjsify/cli": "^0.3.21",
|
|
36
|
-
"typescript": "^6.0.3"
|
|
37
|
-
},
|
|
38
|
-
"dependencies": {
|
|
39
|
-
"@girs/gio-2.0": "2.88.0-4.0.0-rc.14",
|
|
40
|
-
"@girs/giounix-2.0": "2.0.0-4.0.0-rc.14",
|
|
41
|
-
"@girs/gjs": "4.0.0-rc.14",
|
|
42
|
-
"@girs/glib-2.0": "2.88.0-4.0.0-rc.14"
|
|
43
|
-
}
|
|
44
|
-
}
|
|
47
|
+
}
|
package/src/base64.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
// Base64 encoding/decoding utilities for GJS
|
|
2
|
-
// Shared by @gjsify/buffer and @gjsify/string_decoder
|
|
3
|
-
// Reference: RFC 4648
|
|
4
|
-
|
|
5
|
-
const B64_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
6
|
-
const B64_LOOKUP = new Uint8Array(256);
|
|
7
|
-
for (let i = 0; i < B64_CHARS.length; i++) B64_LOOKUP[B64_CHARS.charCodeAt(i)] = i;
|
|
8
|
-
|
|
9
|
-
/** Decode a base64 string to a binary string. Uses native atob when available. */
|
|
10
|
-
export function atobPolyfill(str: string): string {
|
|
11
|
-
if (typeof globalThis.atob === 'function') return globalThis.atob(str);
|
|
12
|
-
const cleaned = str.replace(/[=\s]/g, '');
|
|
13
|
-
let result = '';
|
|
14
|
-
let bits = 0;
|
|
15
|
-
let collected = 0;
|
|
16
|
-
for (let i = 0; i < cleaned.length; i++) {
|
|
17
|
-
bits = (bits << 6) | B64_LOOKUP[cleaned.charCodeAt(i)];
|
|
18
|
-
collected += 6;
|
|
19
|
-
if (collected >= 8) {
|
|
20
|
-
collected -= 8;
|
|
21
|
-
result += String.fromCharCode((bits >> collected) & 0xff);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return result;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** Encode a binary string to base64. Uses native btoa when available. */
|
|
28
|
-
export function btoaPolyfill(str: string): string {
|
|
29
|
-
if (typeof globalThis.btoa === 'function') return globalThis.btoa(str);
|
|
30
|
-
let result = '';
|
|
31
|
-
let i = 0;
|
|
32
|
-
for (; i + 2 < str.length; i += 3) {
|
|
33
|
-
const n = (str.charCodeAt(i) << 16) | (str.charCodeAt(i + 1) << 8) | str.charCodeAt(i + 2);
|
|
34
|
-
result += B64_CHARS[(n >> 18) & 63] + B64_CHARS[(n >> 12) & 63] + B64_CHARS[(n >> 6) & 63] + B64_CHARS[n & 63];
|
|
35
|
-
}
|
|
36
|
-
if (i + 1 === str.length) {
|
|
37
|
-
const n = str.charCodeAt(i) << 16;
|
|
38
|
-
result += B64_CHARS[(n >> 18) & 63] + B64_CHARS[(n >> 12) & 63] + '==';
|
|
39
|
-
} else if (i + 2 === str.length) {
|
|
40
|
-
const n = (str.charCodeAt(i) << 16) | (str.charCodeAt(i + 1) << 8);
|
|
41
|
-
result += B64_CHARS[(n >> 18) & 63] + B64_CHARS[(n >> 12) & 63] + B64_CHARS[(n >> 6) & 63] + '=';
|
|
42
|
-
}
|
|
43
|
-
return result;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** Decode a base64 string directly to Uint8Array (avoids lossy atob string round-trip). */
|
|
47
|
-
export function base64Decode(str: string): Uint8Array {
|
|
48
|
-
const cleaned = str.replace(/[=\s]/g, '');
|
|
49
|
-
const bytes = new Uint8Array((cleaned.length * 3) >> 2);
|
|
50
|
-
let bits = 0;
|
|
51
|
-
let collected = 0;
|
|
52
|
-
let pos = 0;
|
|
53
|
-
for (let i = 0; i < cleaned.length; i++) {
|
|
54
|
-
bits = (bits << 6) | B64_LOOKUP[cleaned.charCodeAt(i)];
|
|
55
|
-
collected += 6;
|
|
56
|
-
if (collected >= 8) {
|
|
57
|
-
collected -= 8;
|
|
58
|
-
bytes[pos++] = (bits >> collected) & 0xff;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return bytes.subarray(0, pos);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** Encode a Uint8Array to base64 string. */
|
|
65
|
-
export function base64Encode(bytes: Uint8Array): string {
|
|
66
|
-
let result = '';
|
|
67
|
-
const len = bytes.length;
|
|
68
|
-
for (let i = 0; i < len; i += 3) {
|
|
69
|
-
const b0 = bytes[i];
|
|
70
|
-
const b1 = i + 1 < len ? bytes[i + 1] : 0;
|
|
71
|
-
const b2 = i + 2 < len ? bytes[i + 2] : 0;
|
|
72
|
-
result += B64_CHARS[b0 >> 2];
|
|
73
|
-
result += B64_CHARS[((b0 & 3) << 4) | (b1 >> 4)];
|
|
74
|
-
result += i + 1 < len ? B64_CHARS[((b1 & 0xf) << 2) | (b2 >> 6)] : '=';
|
|
75
|
-
result += i + 2 < len ? B64_CHARS[b2 & 0x3f] : '=';
|
|
76
|
-
}
|
|
77
|
-
return result;
|
|
78
|
-
}
|
package/src/byte-array.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type GLib from '@girs/glib-2.0';
|
|
2
|
-
|
|
3
|
-
declare const imports: { byteArray: { fromGBytes(input: GLib.Bytes): Uint8Array } };
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Convert GLib.Bytes to Uint8Array using GJS's byteArray module.
|
|
7
|
-
* This wraps the GJS-specific `imports.byteArray.fromGBytes()` API
|
|
8
|
-
* with proper typing to eliminate `as any` casts throughout the codebase.
|
|
9
|
-
*/
|
|
10
|
-
export function gbytesToUint8Array(bytes: GLib.Bytes): Uint8Array {
|
|
11
|
-
return imports.byteArray.fromGBytes(bytes);
|
|
12
|
-
}
|
package/src/callable.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// Legacy `.call(this)` compatibility shim for ES6 classes.
|
|
2
|
-
//
|
|
3
|
-
// Reference: refs/node/lib/internal/streams/legacy.js (Node core Stream() as a
|
|
4
|
-
// regular function, deliberately callable via .call()).
|
|
5
|
-
// Reference: refs/readable-stream/lib/internal/streams/legacy.js (same pattern).
|
|
6
|
-
// Implements the legacy callable pattern for our class-based hierarchy so
|
|
7
|
-
// pre-ES2015 CJS consumers can do `Cls.call(this)` + `util.inherits(Sub, Cls)`.
|
|
8
|
-
// Without this shim, packages that do `EventEmitter.call(this)` or
|
|
9
|
-
// `Stream.call(this)` crash with:
|
|
10
|
-
// TypeError: Class constructor Foo cannot be invoked without 'new'
|
|
11
|
-
//
|
|
12
|
-
// Copyright (c) Node.js contributors. MIT license.
|
|
13
|
-
// Modifications: implemented as a Proxy wrapper for GJSify's ES6 classes.
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Wrap an ES6 class so it supports both the modern `new Cls(...)` pattern and
|
|
17
|
-
* the legacy `Cls.call(thisArg, ...)` pattern.
|
|
18
|
-
*
|
|
19
|
-
* The `apply` trap materialises a temporary instance via `Reflect.construct`
|
|
20
|
-
* (so field initializers and constructor bodies run normally), then transplants
|
|
21
|
-
* its own property descriptors onto `thisArg`. The default Proxy traps pass
|
|
22
|
-
* `construct`, `get` and `getPrototypeOf` straight through, so `new Wrapped()`,
|
|
23
|
-
* `Wrapped.prototype` (consulted by `util.inherits`) and `instance instanceof
|
|
24
|
-
* Wrapped` all behave identically to the underlying class.
|
|
25
|
-
*/
|
|
26
|
-
export function makeCallable<T extends new (...args: any[]) => any>(Cls: T): T {
|
|
27
|
-
return new Proxy(Cls, {
|
|
28
|
-
apply(target, thisArg: object, args: any[]) {
|
|
29
|
-
const tmp = Reflect.construct(target, args, target);
|
|
30
|
-
for (const key of Reflect.ownKeys(tmp)) {
|
|
31
|
-
const desc = Object.getOwnPropertyDescriptor(tmp, key);
|
|
32
|
-
if (desc) Object.defineProperty(thisArg, key, desc);
|
|
33
|
-
}
|
|
34
|
-
return thisArg;
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
}
|
package/src/cli.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import GLib from '@girs/glib-2.0';
|
|
2
|
-
const byteArray = imports.byteArray;
|
|
3
|
-
|
|
4
|
-
export const cli = (commandLine: string): string => {
|
|
5
|
-
const [res, out, err, status] = GLib.spawn_command_line_sync(commandLine);
|
|
6
|
-
|
|
7
|
-
if(err.byteLength) throw new Error(byteArray.toString(err));
|
|
8
|
-
|
|
9
|
-
return byteArray.toString(out);
|
|
10
|
-
};
|
package/src/defer.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Defer an event emission to the next macrotask, matching Node.js behavior
|
|
3
|
-
* for server 'listening', 'close', and 'error' events.
|
|
4
|
-
*/
|
|
5
|
-
export function deferEmit(
|
|
6
|
-
emitter: { emit(event: string | symbol, ...args: unknown[]): boolean },
|
|
7
|
-
event: string,
|
|
8
|
-
...args: unknown[]
|
|
9
|
-
): void {
|
|
10
|
-
setTimeout(() => emitter.emit(event, ...args), 0);
|
|
11
|
-
}
|
package/src/encoding.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
// Shared encoding normalization utilities.
|
|
2
|
-
// Used by buffer, string_decoder, crypto, and other packages that deal with encodings.
|
|
3
|
-
|
|
4
|
-
/** Canonical encoding names (matches BufferEncoding from @types/node). */
|
|
5
|
-
export type Encoding = 'utf8' | 'ascii' | 'latin1' | 'base64' | 'base64url' | 'hex' | 'utf16le' | 'binary' | 'ucs2' | 'ucs-2' | 'utf-8';
|
|
6
|
-
|
|
7
|
-
const VALID_ENCODINGS = ['utf8', 'ascii', 'latin1', 'binary', 'base64', 'base64url', 'hex', 'ucs2', 'utf16le'];
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Normalize an encoding string to a canonical encoding value.
|
|
11
|
-
* Returns 'utf8' as default for undefined/null/empty input.
|
|
12
|
-
*/
|
|
13
|
-
export function normalizeEncoding(enc?: string): Encoding {
|
|
14
|
-
if (!enc || enc === 'utf8' || enc === 'utf-8') return 'utf8';
|
|
15
|
-
const lower = ('' + enc).toLowerCase().replace(/-/g, '');
|
|
16
|
-
switch (lower) {
|
|
17
|
-
case 'utf8': return 'utf8';
|
|
18
|
-
case 'ascii': return 'ascii';
|
|
19
|
-
case 'latin1': case 'binary': return 'latin1';
|
|
20
|
-
case 'base64': return 'base64';
|
|
21
|
-
case 'base64url': return 'base64url';
|
|
22
|
-
case 'hex': return 'hex';
|
|
23
|
-
case 'ucs2': case 'utf16le': return 'utf16le';
|
|
24
|
-
default: return 'utf8';
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Check that an encoding string is valid. Throws TypeError if not.
|
|
30
|
-
*/
|
|
31
|
-
export function checkEncoding(encoding: string): void {
|
|
32
|
-
const lower = ('' + encoding).toLowerCase().replace(/-/g, '');
|
|
33
|
-
if (!VALID_ENCODINGS.includes(lower)) {
|
|
34
|
-
throw new TypeError(`Unknown encoding: ${encoding}`);
|
|
35
|
-
}
|
|
36
|
-
}
|
package/src/error.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Defines the static Error.captureStackTrace method,
|
|
3
|
-
* this is not present in SpiderMonkey because it comes from V8
|
|
4
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#static_methods
|
|
5
|
-
* @see https://nodejs.org/dist/latest-v18.x/docs/api/errors.html#errorcapturestacktracetargetobject-constructoropt
|
|
6
|
-
*/
|
|
7
|
-
export const initErrorV8Methods = (ErrorConstructor: typeof Error) => {
|
|
8
|
-
// See https://nodejs.org/dist/latest-v18.x/docs/api/errors.html#errorcapturestacktracetargetobject-constructoropt
|
|
9
|
-
if (!(Error as any).captureStackTrace) {
|
|
10
|
-
/**
|
|
11
|
-
* A non-standard V8 function.
|
|
12
|
-
* Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.
|
|
13
|
-
* @param targetObject
|
|
14
|
-
* @param constructorOpt
|
|
15
|
-
*/
|
|
16
|
-
(Error as any).captureStackTrace = function(targetObject: object, constructorOpt?: Function) {
|
|
17
|
-
const container = new Error();
|
|
18
|
-
|
|
19
|
-
const target = constructorOpt || targetObject;
|
|
20
|
-
|
|
21
|
-
Object.defineProperty(target, 'stack', {
|
|
22
|
-
configurable: true,
|
|
23
|
-
get: function getStack() {
|
|
24
|
-
var stack = container.stack;
|
|
25
|
-
|
|
26
|
-
Object.defineProperty(this, 'stack', {
|
|
27
|
-
value: stack
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
return stack;
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// TODO Error.stackTraceLimit()
|
|
37
|
-
// TODO Error.prepareStackTrace()
|
|
38
|
-
}
|
package/src/file.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import GLib from '@girs/glib-2.0';
|
|
2
|
-
|
|
3
|
-
const byteArray = imports.byteArray;
|
|
4
|
-
|
|
5
|
-
export const readJSON = (path: string) => {
|
|
6
|
-
const [ok, contents] = GLib.file_get_contents(path);
|
|
7
|
-
if (ok) {
|
|
8
|
-
const map = JSON.parse(byteArray.toString(contents));
|
|
9
|
-
return map;
|
|
10
|
-
}
|
|
11
|
-
throw new Error(`Error on require "${path}"`);
|
|
12
|
-
}
|
package/src/fs.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import Gio from '@girs/gio-2.0';
|
|
2
|
-
import GioUnix from '@girs/giounix-2.0';
|
|
3
|
-
/** Check if a file descriptor exists */
|
|
4
|
-
export const existsFD = (fd: number) => {
|
|
5
|
-
try {
|
|
6
|
-
let stream = GioUnix.InputStream.new(fd, false);
|
|
7
|
-
stream.close(null);
|
|
8
|
-
// File descriptor 12345 exists
|
|
9
|
-
return true
|
|
10
|
-
} catch (error) {
|
|
11
|
-
// File descriptor 12345 does not exist
|
|
12
|
-
return false
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function existsSync(path: string) {
|
|
17
|
-
// TODO: accept buffer and URL too
|
|
18
|
-
if (typeof path !== 'string' || path === '') {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const file = Gio.File.new_for_path(path);
|
|
23
|
-
return file.query_exists(null);
|
|
24
|
-
}
|