@snyxex/pipex 1.0.2 → 1.0.4
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/CHANGELOG.md +6 -0
- package/LICENSE +1 -1
- package/README.md +238 -139
- package/dist/compression-B0xKUa-N.d.mts +35 -0
- package/dist/compression-C1nLQVur.d.cts +35 -0
- package/dist/compression-ChJlMVwP.mjs +1 -0
- package/dist/compression-ZHOsKTJC.cjs +1 -0
- package/dist/compression.cjs +1 -0
- package/dist/compression.d.cts +2 -0
- package/dist/compression.d.mts +2 -0
- package/dist/compression.mjs +1 -0
- package/dist/core-DNchiRD5.mjs +2 -0
- package/dist/core-DSIwvTqu.cjs +2 -0
- package/dist/dataEngine-6R3J-WtS.cjs +1 -0
- package/dist/dataEngine-C-xYat2f.d.cts +223 -0
- package/dist/dataEngine-Zap1RwAJ.d.mts +223 -0
- package/dist/dataEngine-raQdutX5.mjs +1 -0
- package/dist/encryption-CCPoyX4q.d.cts +39 -0
- package/dist/encryption-CHvy--rb.mjs +1 -0
- package/dist/encryption-D4eC9ubl.d.mts +39 -0
- package/dist/encryption-DwdO7Y4J.cjs +1 -0
- package/dist/encryption.cjs +1 -0
- package/dist/encryption.d.cts +2 -0
- package/dist/encryption.d.mts +2 -0
- package/dist/encryption.mjs +1 -0
- package/dist/hashing-C6TkcsUE.d.cts +30 -0
- package/dist/hashing-CEwtXh2V.d.mts +30 -0
- package/dist/hashing-DF_guuZf.cjs +1 -0
- package/dist/hashing-DU3rmGMP.mjs +1 -0
- package/dist/hashing.cjs +1 -0
- package/dist/hashing.d.cts +2 -0
- package/dist/hashing.d.mts +2 -0
- package/dist/hashing.mjs +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +285 -0
- package/dist/index.d.mts +143 -623
- package/dist/index.mjs +1 -3
- package/dist/kms.cjs +1 -0
- package/dist/kms.d.cts +3 -0
- package/dist/kms.d.mts +3 -0
- package/dist/kms.mjs +1 -0
- package/dist/kms_encryption-1G54Lcuo.mjs +1 -0
- package/dist/kms_encryption-B07lunjB.cjs +1 -0
- package/dist/kms_encryption-BBIHGi_O.d.cts +30 -0
- package/dist/kms_encryption-BbtS7rXa.d.mts +30 -0
- package/dist/native.cjs +1 -0
- package/dist/native.d.cts +2 -0
- package/dist/native.d.mts +2 -0
- package/dist/native.mjs +1 -0
- package/dist/parallel.cjs +1 -0
- package/dist/parallel.d.cts +2 -0
- package/dist/parallel.d.mts +2 -0
- package/dist/parallel.mjs +1 -0
- package/dist/plugin-D85NMNiy.d.mts +13 -0
- package/dist/plugin-c_iSNY86.d.cts +13 -0
- package/dist/resourceLimits-CpDWwraK.mjs +1 -0
- package/dist/resourceLimits-lJrEhDE5.cjs +1 -0
- package/dist/types-B50Urzn2.d.cts +152 -0
- package/dist/types-B50Urzn2.d.mts +152 -0
- package/dist/validation-BgdV4KdW.cjs +1 -0
- package/dist/validation-BkJxOs7q.mjs +1 -0
- package/dist/validation-hcvcixaS.d.cts +29 -0
- package/dist/validation-xIBvnsSH.d.mts +29 -0
- package/dist/validation.cjs +1 -0
- package/dist/validation.d.cts +2 -0
- package/dist/validation.d.mts +2 -0
- package/dist/validation.mjs +1 -0
- package/dist/worker-1Q2hRcRB.cjs +1 -0
- package/dist/worker-DT7RYWwo.d.cts +34 -0
- package/dist/worker-iSO3KhfN.d.mts +34 -0
- package/dist/worker-ul8lQ0SH.mjs +1 -0
- package/package.json +128 -31
- package/SECURITY.md +0 -41
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/docs/architecture.md +0 -124
- package/docs/encryption-v4-migration.md +0 -45
- package/docs/enterprise.md +0 -280
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{randomUUID as e}from"node:crypto";import{pipeline as t}from"node:stream/promises";import{Transform as n}from"node:stream";import{Packr as r,PackrStream as i,Unpackr as a,UnpackrStream as o}from"msgpackr";import"zod";import{C as s,S as c,_ as l,d as u,g as d,i as f,t as p}from"./resourceLimits-CpDWwraK.mjs";import m from"node:path";import{existsSync as h,realpathSync as g}from"node:fs";function _(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.__pipex_v===1&&Array.isArray(t.plugins)&&t.plugins.length<=256&&t.plugins.every(e=>typeof e==`string`&&e.length<=256)&&typeof t.ts==`number`&&Number.isSafeInteger(t.ts)&&t.ts>=0}var v=class{#e;#t;#n=0;#r=1;#i=0;#a=!1;#o;#s=0;constructor(e,t){this.#e=e,this.#t=t}scan(e){let t=[],n=0;for(;n<e.length;){if(this.#i>0){if(this.#a){this.#c(1);let r=e[n];n++,this.#i--,this.#a=!1,r===101||r===115||r===120?(this.#u(1),this.#l(this.#i)):r!==0&&r!==66&&r!==116&&r!==255&&this.#v(),this.#i===0&&this.#g(n,t);continue}let r=Math.min(this.#i,e.length-n);this.#c(r),this.#i-=r,n+=r,this.#i>0&&this.#n===this.#e&&this.#_(),this.#i===0&&this.#g(n,t);continue}if(this.#o){let r=this.#o;if(this.#c(1),r.value=r.value*256+e[n],n++,r.read++,r.read===r.bytes){let{kind:e,value:i}=r;this.#o=void 0,this.#m(e,i),this.#g(n,t)}continue}this.#c(1);let r=e[n];n++,this.#r--,this.#r<0&&this.#v(),this.#h(r),this.#g(n,t)}return t}finish(){if(this.#n!==0||this.#o||this.#i!==0)throw Error(`[PipeX] Invalid MessagePack input: incomplete frame`)}#c(e){e>this.#e-this.#n&&this.#_(),this.#n+=e}#l(e=0){let t=this.#e-this.#n;(e>t||this.#r>t-e)&&this.#_()}#u(e){(!Number.isSafeInteger(e)||e<0||e>2**53-1-this.#r)&&this.#v(),this.#r+=e,this.#l()}#d(e){(!Number.isSafeInteger(e)||e<0)&&this.#v(),this.#l(e),this.#i=e}#f(e){this.#d(e+1),this.#a=!0}#p(e,t){this.#o={kind:e,bytes:t,read:0,value:0}}#m(e,t){e===`array`?this.#u(t):e===`map`?this.#u(t*2):(this.#d(t+ +(e===`extension`)),this.#a=e===`extension`)}#h(e){if(e<=127||e>=224||e>=192&&e<=195)e===193&&this.#v();else{if(e>=128&&e<=143)return this.#u((e&15)*2);if(e>=144&&e<=159)return this.#u(e&15);if(e>=160&&e<=191)return this.#d(e&31);switch(e){case 196:return this.#p(`payload`,1);case 197:return this.#p(`payload`,2);case 198:return this.#p(`payload`,4);case 199:return this.#p(`extension`,1);case 200:return this.#p(`extension`,2);case 201:return this.#p(`extension`,4);case 202:return this.#d(4);case 203:return this.#d(8);case 204:case 208:return this.#d(1);case 205:case 209:return this.#d(2);case 206:case 210:return this.#d(4);case 207:case 211:return this.#d(8);case 212:return this.#f(1);case 213:return this.#f(2);case 214:return this.#f(4);case 215:return this.#f(8);case 216:return this.#f(16);case 217:return this.#p(`payload`,1);case 218:return this.#p(`payload`,2);case 219:return this.#p(`payload`,4);case 220:return this.#p(`array`,2);case 221:return this.#p(`array`,4);case 222:return this.#p(`map`,2);case 223:return this.#p(`map`,4);default:return this.#v()}}}#g(e,t){if(!(this.#o||this.#i>0||this.#r!==0)){if(this.#s++,this.#s>this.#t)throw Error(`[PipeX] Frame count exceeds ${this.#t}`);t.push(e),this.#n=0,this.#r=1,this.#a=!1}}#_(){throw Error(`[PipeX] MessagePack frame exceeds ${this.#e} bytes`)}#v(){throw Error(`[PipeX] Invalid MessagePack input`)}};function y(e,t,n=2**53-1){let r=new v(t,n),i=r.scan(Buffer.isBuffer(e)?e:Buffer.from(e.buffer,e.byteOffset,e.byteLength));return r.finish(),i.length}function ee(e,t){let r=new v(e,t),i=[],a=0;return new n({transform(e,t,n){try{let t=Buffer.isBuffer(e)?e:Buffer.from(e),o=r.scan(t),s=0;for(let e of o){let n=t.subarray(s,e);n.length>0&&(i.push(n),a+=n.length),this.push(i.length===1?i[0]:Buffer.concat(i,a)),i=[],a=0,s=e}if(s<t.length){let e=t.subarray(s);i.push(e),a+=e.length}n()}catch(e){n(e)}},flush(e){try{r.finish(),e()}catch(t){e(t)}}})}const b=/* @__PURE__ */ new WeakMap;function x(e,t){t>0&&b.set(e,Date.now()+t)}function S(e){return e.reason instanceof l||e.reason instanceof d?e.reason:e.reason instanceof Error&&e.reason.name===`TimeoutError`?new l:new d}function C(e){if(!e)return;if(e.aborted)throw S(e);let t=b.get(e);if(t!==void 0&&Date.now()>=t)throw new l}async function w(e,t,n){let r=Promise.resolve(e);return n?.(r),t?new Promise((e,n)=>{let i=!1,a,o=()=>{t.removeEventListener(`abort`,c),a&&clearTimeout(a)},s=e=>{i||(i=!0,o(),n(e))},c=()=>s(S(t));t.addEventListener(`abort`,c,{once:!0});let u=b.get(t);u!==void 0&&(a=setTimeout(()=>s(new l),Math.max(0,u-Date.now()))),r.then(n=>{if(!i){try{C(t)}catch(e){s(e);return}i=!0,o(),e(n)}},s);try{C(t)}catch(e){s(e)}}):r}function T(e){try{Promise.resolve(e()).catch(()=>void 0)}catch{}}function E(e){if(e)return{info:(t,n)=>T(()=>e.info(t,n)),warn:(t,n)=>T(()=>e.warn(t,n)),error:(t,n)=>T(()=>e.error(t,n)),debug:(t,n)=>T(()=>e.debug(t,n))}}function D(e){if(e)return{startSpan(t,n){let r;try{let i=e.startSpan(t,n);i&&typeof i.then==`function`?T(()=>i):r=i}catch{}let i=!1,a={setAttribute(e,t){return T(()=>r?.setAttribute(e,t)),a},addEvent(e,t){return T(()=>r?.addEvent(e,t)),a},end(){i||(i=!0,T(()=>r?.end()))}};return a}}}async function O(e,t,n,r){n=E(n);let{attempts:i=1,backoff:a=`fixed`,delayMs:o=0}=t??{},s=r?.limits?.maxRetryAttempts??5,c=r?.limits?.maxRetryDelayMs??3e4;if(!Number.isSafeInteger(i)||i<1||i>s)throw Error(`[PipeX] Invalid retry attempts: ${i}`);if(!Number.isSafeInteger(o)||o<0||o>c)throw Error(`[PipeX] Invalid retry delay: ${o}`);let l;for(let t=0;t<i;t++){C(r?.signal);try{return await w(e(),r?.signal,r?.track)}catch(e){if(C(r?.signal),l=e instanceof Error?e:Error(String(e)),t<i-1){let e=a===`exponential`?o*2**t:o;n?.debug(`[PipeX] Retry ${t+1}/${i} after ${e}ms`,{error:l.message}),e>0&&await new Promise((t,n)=>{let i=()=>r?.signal?.removeEventListener(`abort`,o),a=setTimeout(()=>{i(),t()},Math.min(e,c)),o=()=>{clearTimeout(a),i(),n(r?.signal?.reason??/* @__PURE__ */ Error(`[PipeX] Operation aborted`))};r?.signal?.addEventListener(`abort`,o,{once:!0}),r?.signal?.aborted&&o()})}}}throw l}const k=`__pipex_v`,A=new r({useRecords:!1,moreTypes:!0,structuredClone:!1,bundleStrings:!1}),j=new a({useRecords:!1,structuredClone:!1}),te=268435456,M=65536;function N(e){return typeof e.createStream==`function`}function P(e){let t=`${e.name}@${e.version}`,n=e.reversible,r=e.streaming,i=e.reverse,a=e.createStream,o=typeof i==`function`&&i!==f.prototype.reverse;if(n!==void 0&&typeof n!=`boolean`)throw new u(t,`reversible`,`MUST_BE_BOOLEAN`);if(r!==void 0&&typeof r!=`boolean`)throw new u(t,`streaming`,`MUST_BE_BOOLEAN`);if(n===!0&&!o)throw new u(t,`reversible`,`MISSING_IMPLEMENTATION`);if(r===!1&&typeof a==`function`)throw new u(t,`streaming`,`CONFLICTING_IMPLEMENTATION`);let s=n!==!1&&o,c=r!==!1;return Object.freeze({process:!0,reverse:s,streaming:c,streamMode:c?typeof a==`function`?`native`:`fallback`:`none`})}function F(e,t){let n=P(e);switch(t){case`process`:return n.process;case`reverse`:return n.reverse;case`stream`:return n.streaming;default:throw TypeError(`[PipeX] Unknown plugin operation`)}}function I(e){return F(e,`reverse`)}function L(e){let t=e.find(e=>!I(e));if(t)throw new c(`${t.name}@${t.version}`)}function R(e){let t=e.find(e=>!F(e,`stream`));if(t)throw new s(`${t.name}@${t.version}`)}function z(e){return e===null?`null`:Buffer.isBuffer(e)?`buffer`:Array.isArray(e)?`array`:typeof e==`object`?`object`:typeof e}function ne(e){return Buffer.isBuffer(e)?e:e instanceof ArrayBuffer?Buffer.from(e):typeof e==`object`&&e?A.pack(e):typeof e==`number`||typeof e==`boolean`?Buffer.from(String(e)):Buffer.from(String(e??``),`utf-8`)}const B=Object.freeze([`buffer`,`object`,`array`,`string`,`number`,`boolean`,`null`,`undefined`,`bigint`,`json`]);function V(e){if(typeof e!=`string`||!B.includes(e))throw Error(`[PipeX] Unsupported original type`)}function H(e,t,n=p.maxFrameBytes){if(V(t),!Buffer.isBuffer(e))throw Error(`[PipeX] Invalid binary payload`);switch(t){case`array`:case`object`:{y(e,n,1);let r;try{r=j.unpack(e)}catch{throw Error(`[PipeX] fromBuffer: invalid MessagePack input`)}if(t===`array`?!Array.isArray(r):typeof r!=`object`||!r||Array.isArray(r))throw Error(`[PipeX] Decoded value does not match the expected type`);return r}case`json`:try{return JSON.parse(e.toString(`utf-8`))}catch{throw Error(`[PipeX] fromBuffer: invalid JSON input`)}case`number`:{let t=Number(e.toString(`utf-8`));if(Number.isNaN(t))throw Error(`[PipeX] fromBuffer: invalid number`);return t}case`bigint`:try{return BigInt(e.toString(`utf-8`))}catch{throw Error(`[PipeX] fromBuffer: invalid bigint`)}case`boolean`:{let t=e.toString(`utf-8`);if(t!==`true`&&t!==`false`)throw Error(`[PipeX] fromBuffer: invalid boolean`);return t===`true`}case`string`:return e.toString(`utf-8`);case`null`:case`undefined`:if(e.length!==0)throw Error(`[PipeX] Payload does not match the expected empty type`);return t===`null`?null:void 0;default:return e}}function U(e,t={},n,r,i,a){return{requestId:e,timestamp:Date.now(),metadata:t,logger:n,span:r,signal:i,limits:a}}function W(e){return{__pipex_v:1,plugins:e.map(e=>`${e.name}@${e.version}`),ts:Date.now()}}function G(e){let t=!1,r=Buffer.from(A.pack(e));return new n({transform(e,n,i){t||(t=!0,this.push(r)),i(null,e)},flush(e){t||this.push(r),e()}})}function K(e){let t=!1;return new n({writableObjectMode:!0,readableObjectMode:!0,transform(n,r,i){if(!t&&(t=!0,_(n)))try{e(n),i()}catch(e){i(e)}else i(null,n)}})}var q=class extends o{#e=0;#t;constructor(e={},t=p.maxInputBytes){super(e),this.#t=t}_transform(e,t,n){e.length>this.#t-this.#e?n(/* @__PURE__ */ Error(`[PipeX] Serialized input exceeds ${this.#t} bytes`)):(this.#e+=e.length,super._transform(e,t,e=>{n(e?/* @__PURE__ */ Error(`[PipeX] Invalid MessagePack input`):void 0)}))}};function J(){return new i({useRecords:!1,moreTypes:!0,structuredClone:!1,bundleStrings:!1})}function Y(e=p.maxInputBytes){return new q({useRecords:!1,structuredClone:!1},e)}function X(e,t){let r=0;return new n({transform(n,i,a){n.length>e-r?a(/* @__PURE__ */ Error(`[PipeX] ${t} exceeds ${e} bytes`)):(r+=n.length,a(null,n))}})}function re(e){let t=0;return new n({writableObjectMode:!0,readableObjectMode:!0,transform(n,r,i){t>=e?i(/* @__PURE__ */ Error(`[PipeX] Application frame count exceeds ${e}`)):(t++,i(null,n))}})}function Z(e,t,n){let r=typeof e==`string`?Buffer.byteLength(e):Buffer.isBuffer(e)||ArrayBuffer.isView(e)||e instanceof ArrayBuffer?e.byteLength:void 0;if(r!==void 0&&r>t)throw Error(`[PipeX] ${n} exceeds ${t} bytes`)}function ie(e,t){return new n({writableObjectMode:!0,readableObjectMode:!0,transform(n,r,i){try{Z(n,e,t),i(null,n)}catch(e){i(e)}}})}function Q(t,r,i,a,o,s,l){a=E(a),o=D(o);let u=l?.requestId??`stream-${e()}`;return new n({async transform(e,n,d){let f=o?.startSpan(`plugin:${t.name}`,{requestId:u});f?.setAttribute(`plugin.version`,t.version),f?.setAttribute(`mode`,r?`reverse`:`process`);try{l?.signal.throwIfAborted();let n=U(u,{},a,f,l?.signal,l?.limits);if(r&&!I(t))throw new c(`${t.name}@${t.version}`);let o=r?t.reverse.bind(t):t.process.bind(t),s=await O(()=>o(e,n),t.retryOptions,a,{signal:l?.signal,limits:l?.limits,track:l?.track}),m=l?.limits.maxOutputBytes??p.maxOutputBytes;if(!Buffer.isBuffer(s)||s.length>m)throw Error(`[PipeX] Plugin output exceeds ${m} bytes`);i?.(s.length),f?.addEvent(`processed`,{bytes:s.length}),d(null,s)}catch(n){let r=n instanceof Error?n:Error(String(n));if(a?.error(`[PipeX] Plugin ${t.name} failed after retries`,{requestId:u,error:r.message}),f?.setAttribute(`error`,!0),f?.addEvent(`error`,{message:r.message}),s&&s.writable){a?.warn(`[PipeX] Diverting failed chunk to DLQ`,{requestId:u,plugin:t.name});try{s.write(e)||await new Promise((e,t)=>{let n=()=>{o(),e()},r=e=>{o(),t(e)},i=()=>{o(),t(l?.signal.reason instanceof Error?l.signal.reason:/* @__PURE__ */ Error(`[PipeX] Operation aborted`))},a=()=>{o(),t(/* @__PURE__ */ Error(`[PipeX] Stream closed while writing to DLQ`))},o=()=>{s.off(`drain`,n),s.off(`error`,r),l?.signal.removeEventListener(`abort`,i),this.off(`close`,a)};s.once(`drain`,n),s.once(`error`,r),this.once(`close`,a),l?.signal.aborted?i():l?.signal.addEventListener(`abort`,i,{once:!0})}),d(r)}catch(e){d(e)}}else d(r)}finally{f?.end()}}})}function ae(){return new n({writableObjectMode:!0,readableObjectMode:!1,transform(e,t,n){try{n(null,JSON.stringify(e)+`
|
|
2
|
+
`)}catch(e){n(/* @__PURE__ */ Error(`[PipeX] NDJSON: ${e.message}`))}}})}function oe(e,t,r=!1,i,a,o,s,c){return a=E(a),o=D(o),R(e),r&&L(e),(r?[...e].reverse():e).flatMap((e,l)=>{let u=N(e)?e.createStream(t,c):Q(e,r,i,a,o,s,c),d=X(c?.limits.maxOutputBytes??p.maxOutputBytes,`output after plugin ${e.name}#${l}`);if(!N(e))return[u,d];let f=o?.startSpan(`plugin:${e.name}`,{requestId:c?.requestId??`stream`}),m=!1,h=e=>{m||(m=!0,e&&f?.setAttribute(`error`,!0),f?.end())};return[u,new n({transform(e,t,n){i?.(e.length),f?.addEvent(`processed`,{bytes:e.length}),n(null,e)},final(e){h(),e()},destroy(e,t){h(e),t(e)}}),d]})}async function se(e,n,r,i){await t(e,...n,r,i??{})}function $(e,t){let n=m.relative(t,e);if(n===`..`||n.startsWith(`..${m.sep}`)||m.isAbsolute(n))throw Error(`[PipeX] Path is outside the allowed root`)}function ce(e,t){let n=m.resolve(e);if(!h(n))throw Error(`[PipeX] File not found: ${n}`);let r=g.native(m.resolve(t??process.cwd())),i=g.native(n);return $(i,r),i}function le(e,t){let n=g.native(m.resolve(t??process.cwd())),r=m.resolve(e),i=g.native(m.dirname(r));$(i,n);let a=m.join(i,m.basename(r));return h(a)&&$(g.native(a),n),a}export{se as A,C as B,Y as C,N as D,P as E,T as F,ee as H,E as I,D as L,I as M,ne as N,U as O,O as P,w as R,J as S,H as T,_ as U,y as V,K as _,A as a,re as b,ce as c,L as d,R as f,W as g,ie as h,B as i,F as j,le as k,Z as l,Q as m,q as n,k as o,X as p,te as r,j as s,M as t,V as u,G as v,z as w,oe as x,ae as y,x as z};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(let c of r(i))!a.call(e,c)&&c!==o&&(s=n(i,c),t(e,c,{get:s&&s.get&&!s.configurable?s.get:()=>i[c],enumerable:!s||s.enumerable}));return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));let c=require("node:crypto"),l=require("node:stream/promises"),u=require("node:stream"),d=require("msgpackr");require("zod");const f=require("./resourceLimits-lJrEhDE5.cjs");let p=require("node:path"),m=require("node:fs");p=s(p,1);function h(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.__pipex_v===1&&Array.isArray(t.plugins)&&t.plugins.length<=256&&t.plugins.every(e=>typeof e==`string`&&e.length<=256)&&typeof t.ts==`number`&&Number.isSafeInteger(t.ts)&&t.ts>=0}var g=class{#e;#t;#n=0;#r=1;#i=0;#a=!1;#o;#s=0;constructor(e,t){this.#e=e,this.#t=t}scan(e){let t=[],n=0;for(;n<e.length;){if(this.#i>0){if(this.#a){this.#c(1);let r=e[n];n++,this.#i--,this.#a=!1,r===101||r===115||r===120?(this.#u(1),this.#l(this.#i)):r!==0&&r!==66&&r!==116&&r!==255&&this.#v(),this.#i===0&&this.#g(n,t);continue}let r=Math.min(this.#i,e.length-n);this.#c(r),this.#i-=r,n+=r,this.#i>0&&this.#n===this.#e&&this.#_(),this.#i===0&&this.#g(n,t);continue}if(this.#o){let r=this.#o;if(this.#c(1),r.value=r.value*256+e[n],n++,r.read++,r.read===r.bytes){let{kind:e,value:i}=r;this.#o=void 0,this.#m(e,i),this.#g(n,t)}continue}this.#c(1);let r=e[n];n++,this.#r--,this.#r<0&&this.#v(),this.#h(r),this.#g(n,t)}return t}finish(){if(this.#n!==0||this.#o||this.#i!==0)throw Error(`[PipeX] Invalid MessagePack input: incomplete frame`)}#c(e){e>this.#e-this.#n&&this.#_(),this.#n+=e}#l(e=0){let t=this.#e-this.#n;(e>t||this.#r>t-e)&&this.#_()}#u(e){(!Number.isSafeInteger(e)||e<0||e>2**53-1-this.#r)&&this.#v(),this.#r+=e,this.#l()}#d(e){(!Number.isSafeInteger(e)||e<0)&&this.#v(),this.#l(e),this.#i=e}#f(e){this.#d(e+1),this.#a=!0}#p(e,t){this.#o={kind:e,bytes:t,read:0,value:0}}#m(e,t){e===`array`?this.#u(t):e===`map`?this.#u(t*2):(this.#d(t+ +(e===`extension`)),this.#a=e===`extension`)}#h(e){if(e<=127||e>=224||e>=192&&e<=195)e===193&&this.#v();else{if(e>=128&&e<=143)return this.#u((e&15)*2);if(e>=144&&e<=159)return this.#u(e&15);if(e>=160&&e<=191)return this.#d(e&31);switch(e){case 196:return this.#p(`payload`,1);case 197:return this.#p(`payload`,2);case 198:return this.#p(`payload`,4);case 199:return this.#p(`extension`,1);case 200:return this.#p(`extension`,2);case 201:return this.#p(`extension`,4);case 202:return this.#d(4);case 203:return this.#d(8);case 204:case 208:return this.#d(1);case 205:case 209:return this.#d(2);case 206:case 210:return this.#d(4);case 207:case 211:return this.#d(8);case 212:return this.#f(1);case 213:return this.#f(2);case 214:return this.#f(4);case 215:return this.#f(8);case 216:return this.#f(16);case 217:return this.#p(`payload`,1);case 218:return this.#p(`payload`,2);case 219:return this.#p(`payload`,4);case 220:return this.#p(`array`,2);case 221:return this.#p(`array`,4);case 222:return this.#p(`map`,2);case 223:return this.#p(`map`,4);default:return this.#v()}}}#g(e,t){if(!(this.#o||this.#i>0||this.#r!==0)){if(this.#s++,this.#s>this.#t)throw Error(`[PipeX] Frame count exceeds ${this.#t}`);t.push(e),this.#n=0,this.#r=1,this.#a=!1}}#_(){throw Error(`[PipeX] MessagePack frame exceeds ${this.#e} bytes`)}#v(){throw Error(`[PipeX] Invalid MessagePack input`)}};function _(e,t,n=2**53-1){let r=new g(t,n),i=r.scan(Buffer.isBuffer(e)?e:Buffer.from(e.buffer,e.byteOffset,e.byteLength));return r.finish(),i.length}function v(e,t){let n=new g(e,t),r=[],i=0;return new u.Transform({transform(e,t,a){try{let t=Buffer.isBuffer(e)?e:Buffer.from(e),o=n.scan(t),s=0;for(let e of o){let n=t.subarray(s,e);n.length>0&&(r.push(n),i+=n.length),this.push(r.length===1?r[0]:Buffer.concat(r,i)),r=[],i=0,s=e}if(s<t.length){let e=t.subarray(s);r.push(e),i+=e.length}a()}catch(e){a(e)}},flush(e){try{n.finish(),e()}catch(t){e(t)}}})}const y=/* @__PURE__ */ new WeakMap;function b(e,t){t>0&&y.set(e,Date.now()+t)}function x(e){return e.reason instanceof f._||e.reason instanceof f.g?e.reason:e.reason instanceof Error&&e.reason.name===`TimeoutError`?new f._:new f.g}function S(e){if(!e)return;if(e.aborted)throw x(e);let t=y.get(e);if(t!==void 0&&Date.now()>=t)throw new f._}async function C(e,t,n){let r=Promise.resolve(e);return n?.(r),t?new Promise((e,n)=>{let i=!1,a,o=()=>{t.removeEventListener(`abort`,c),a&&clearTimeout(a)},s=e=>{i||(i=!0,o(),n(e))},c=()=>s(x(t));t.addEventListener(`abort`,c,{once:!0});let l=y.get(t);l!==void 0&&(a=setTimeout(()=>s(new f._),Math.max(0,l-Date.now()))),r.then(n=>{if(!i){try{S(t)}catch(e){s(e);return}i=!0,o(),e(n)}},s);try{S(t)}catch(e){s(e)}}):r}function w(e){try{Promise.resolve(e()).catch(()=>void 0)}catch{}}function T(e){if(e)return{info:(t,n)=>w(()=>e.info(t,n)),warn:(t,n)=>w(()=>e.warn(t,n)),error:(t,n)=>w(()=>e.error(t,n)),debug:(t,n)=>w(()=>e.debug(t,n))}}function E(e){if(e)return{startSpan(t,n){let r;try{let i=e.startSpan(t,n);i&&typeof i.then==`function`?w(()=>i):r=i}catch{}let i=!1,a={setAttribute(e,t){return w(()=>r?.setAttribute(e,t)),a},addEvent(e,t){return w(()=>r?.addEvent(e,t)),a},end(){i||(i=!0,w(()=>r?.end()))}};return a}}}async function D(e,t,n,r){n=T(n);let{attempts:i=1,backoff:a=`fixed`,delayMs:o=0}=t??{},s=r?.limits?.maxRetryAttempts??5,c=r?.limits?.maxRetryDelayMs??3e4;if(!Number.isSafeInteger(i)||i<1||i>s)throw Error(`[PipeX] Invalid retry attempts: ${i}`);if(!Number.isSafeInteger(o)||o<0||o>c)throw Error(`[PipeX] Invalid retry delay: ${o}`);let l;for(let t=0;t<i;t++){S(r?.signal);try{return await C(e(),r?.signal,r?.track)}catch(e){if(S(r?.signal),l=e instanceof Error?e:Error(String(e)),t<i-1){let e=a===`exponential`?o*2**t:o;n?.debug(`[PipeX] Retry ${t+1}/${i} after ${e}ms`,{error:l.message}),e>0&&await new Promise((t,n)=>{let i=()=>r?.signal?.removeEventListener(`abort`,o),a=setTimeout(()=>{i(),t()},Math.min(e,c)),o=()=>{clearTimeout(a),i(),n(r?.signal?.reason??/* @__PURE__ */ Error(`[PipeX] Operation aborted`))};r?.signal?.addEventListener(`abort`,o,{once:!0}),r?.signal?.aborted&&o()})}}}throw l}const O=new d.Packr({useRecords:!1,moreTypes:!0,structuredClone:!1,bundleStrings:!1}),k=new d.Unpackr({useRecords:!1,structuredClone:!1});function A(e){return typeof e.createStream==`function`}function j(e){let t=`${e.name}@${e.version}`,n=e.reversible,r=e.streaming,i=e.reverse,a=e.createStream,o=typeof i==`function`&&i!==f.i.prototype.reverse;if(n!==void 0&&typeof n!=`boolean`)throw new f.d(t,`reversible`,`MUST_BE_BOOLEAN`);if(r!==void 0&&typeof r!=`boolean`)throw new f.d(t,`streaming`,`MUST_BE_BOOLEAN`);if(n===!0&&!o)throw new f.d(t,`reversible`,`MISSING_IMPLEMENTATION`);if(r===!1&&typeof a==`function`)throw new f.d(t,`streaming`,`CONFLICTING_IMPLEMENTATION`);let s=n!==!1&&o,c=r!==!1;return Object.freeze({process:!0,reverse:s,streaming:c,streamMode:c?typeof a==`function`?`native`:`fallback`:`none`})}function M(e,t){let n=j(e);switch(t){case`process`:return n.process;case`reverse`:return n.reverse;case`stream`:return n.streaming;default:throw TypeError(`[PipeX] Unknown plugin operation`)}}function N(e){return M(e,`reverse`)}function P(e){let t=e.find(e=>!N(e));if(t)throw new f.S(`${t.name}@${t.version}`)}function F(e){let t=e.find(e=>!M(e,`stream`));if(t)throw new f.C(`${t.name}@${t.version}`)}function I(e){return e===null?`null`:Buffer.isBuffer(e)?`buffer`:Array.isArray(e)?`array`:typeof e==`object`?`object`:typeof e}function L(e){return Buffer.isBuffer(e)?e:e instanceof ArrayBuffer?Buffer.from(e):typeof e==`object`&&e?O.pack(e):typeof e==`number`||typeof e==`boolean`?Buffer.from(String(e)):Buffer.from(String(e??``),`utf-8`)}const R=Object.freeze([`buffer`,`object`,`array`,`string`,`number`,`boolean`,`null`,`undefined`,`bigint`,`json`]);function z(e){if(typeof e!=`string`||!R.includes(e))throw Error(`[PipeX] Unsupported original type`)}function B(e,t,n=f.t.maxFrameBytes){if(z(t),!Buffer.isBuffer(e))throw Error(`[PipeX] Invalid binary payload`);switch(t){case`array`:case`object`:{_(e,n,1);let r;try{r=k.unpack(e)}catch{throw Error(`[PipeX] fromBuffer: invalid MessagePack input`)}if(t===`array`?!Array.isArray(r):typeof r!=`object`||!r||Array.isArray(r))throw Error(`[PipeX] Decoded value does not match the expected type`);return r}case`json`:try{return JSON.parse(e.toString(`utf-8`))}catch{throw Error(`[PipeX] fromBuffer: invalid JSON input`)}case`number`:{let t=Number(e.toString(`utf-8`));if(Number.isNaN(t))throw Error(`[PipeX] fromBuffer: invalid number`);return t}case`bigint`:try{return BigInt(e.toString(`utf-8`))}catch{throw Error(`[PipeX] fromBuffer: invalid bigint`)}case`boolean`:{let t=e.toString(`utf-8`);if(t!==`true`&&t!==`false`)throw Error(`[PipeX] fromBuffer: invalid boolean`);return t===`true`}case`string`:return e.toString(`utf-8`);case`null`:case`undefined`:if(e.length!==0)throw Error(`[PipeX] Payload does not match the expected empty type`);return t===`null`?null:void 0;default:return e}}function V(e,t={},n,r,i,a){return{requestId:e,timestamp:Date.now(),metadata:t,logger:n,span:r,signal:i,limits:a}}function ee(e){return{__pipex_v:1,plugins:e.map(e=>`${e.name}@${e.version}`),ts:Date.now()}}function H(e){let t=!1,n=Buffer.from(O.pack(e));return new u.Transform({transform(e,r,i){t||(t=!0,this.push(n)),i(null,e)},flush(e){t||this.push(n),e()}})}function U(e){let t=!1;return new u.Transform({writableObjectMode:!0,readableObjectMode:!0,transform(n,r,i){if(!t&&(t=!0,h(n)))try{e(n),i()}catch(e){i(e)}else i(null,n)}})}var W=class extends d.UnpackrStream{#e=0;#t;constructor(e={},t=f.t.maxInputBytes){super(e),this.#t=t}_transform(e,t,n){e.length>this.#t-this.#e?n(/* @__PURE__ */ Error(`[PipeX] Serialized input exceeds ${this.#t} bytes`)):(this.#e+=e.length,super._transform(e,t,e=>{n(e?/* @__PURE__ */ Error(`[PipeX] Invalid MessagePack input`):void 0)}))}};function G(){return new d.PackrStream({useRecords:!1,moreTypes:!0,structuredClone:!1,bundleStrings:!1})}function K(e=f.t.maxInputBytes){return new W({useRecords:!1,structuredClone:!1},e)}function q(e,t){let n=0;return new u.Transform({transform(r,i,a){r.length>e-n?a(/* @__PURE__ */ Error(`[PipeX] ${t} exceeds ${e} bytes`)):(n+=r.length,a(null,r))}})}function J(e){let t=0;return new u.Transform({writableObjectMode:!0,readableObjectMode:!0,transform(n,r,i){t>=e?i(/* @__PURE__ */ Error(`[PipeX] Application frame count exceeds ${e}`)):(t++,i(null,n))}})}function Y(e,t,n){let r=typeof e==`string`?Buffer.byteLength(e):Buffer.isBuffer(e)||ArrayBuffer.isView(e)||e instanceof ArrayBuffer?e.byteLength:void 0;if(r!==void 0&&r>t)throw Error(`[PipeX] ${n} exceeds ${t} bytes`)}function X(e,t){return new u.Transform({writableObjectMode:!0,readableObjectMode:!0,transform(n,r,i){try{Y(n,e,t),i(null,n)}catch(e){i(e)}}})}function Z(e,t,n,r,i,a,o){r=T(r),i=E(i);let s=o?.requestId??`stream-${(0,c.randomUUID)()}`;return new u.Transform({async transform(c,l,u){let d=i?.startSpan(`plugin:${e.name}`,{requestId:s});d?.setAttribute(`plugin.version`,e.version),d?.setAttribute(`mode`,t?`reverse`:`process`);try{o?.signal.throwIfAborted();let i=V(s,{},r,d,o?.signal,o?.limits);if(t&&!N(e))throw new f.S(`${e.name}@${e.version}`);let a=t?e.reverse.bind(e):e.process.bind(e),l=await D(()=>a(c,i),e.retryOptions,r,{signal:o?.signal,limits:o?.limits,track:o?.track}),p=o?.limits.maxOutputBytes??f.t.maxOutputBytes;if(!Buffer.isBuffer(l)||l.length>p)throw Error(`[PipeX] Plugin output exceeds ${p} bytes`);n?.(l.length),d?.addEvent(`processed`,{bytes:l.length}),u(null,l)}catch(t){let n=t instanceof Error?t:Error(String(t));if(r?.error(`[PipeX] Plugin ${e.name} failed after retries`,{requestId:s,error:n.message}),d?.setAttribute(`error`,!0),d?.addEvent(`error`,{message:n.message}),a&&a.writable){r?.warn(`[PipeX] Diverting failed chunk to DLQ`,{requestId:s,plugin:e.name});try{a.write(c)||await new Promise((e,t)=>{let n=()=>{c(),e()},r=e=>{c(),t(e)},i=()=>{c(),t(o?.signal.reason instanceof Error?o.signal.reason:/* @__PURE__ */ Error(`[PipeX] Operation aborted`))},s=()=>{c(),t(/* @__PURE__ */ Error(`[PipeX] Stream closed while writing to DLQ`))},c=()=>{a.off(`drain`,n),a.off(`error`,r),o?.signal.removeEventListener(`abort`,i),this.off(`close`,s)};a.once(`drain`,n),a.once(`error`,r),this.once(`close`,s),o?.signal.aborted?i():o?.signal.addEventListener(`abort`,i,{once:!0})}),u(n)}catch(e){u(e)}}else u(n)}finally{d?.end()}}})}function Q(){return new u.Transform({writableObjectMode:!0,readableObjectMode:!1,transform(e,t,n){try{n(null,JSON.stringify(e)+`
|
|
2
|
+
`)}catch(e){n(/* @__PURE__ */ Error(`[PipeX] NDJSON: ${e.message}`))}}})}function te(e,t,n=!1,r,i,a,o,s){return i=T(i),a=E(a),F(e),n&&P(e),(n?[...e].reverse():e).flatMap((e,c)=>{let l=A(e)?e.createStream(t,s):Z(e,n,r,i,a,o,s),d=q(s?.limits.maxOutputBytes??f.t.maxOutputBytes,`output after plugin ${e.name}#${c}`);if(!A(e))return[l,d];let p=a?.startSpan(`plugin:${e.name}`,{requestId:s?.requestId??`stream`}),m=!1,h=e=>{m||(m=!0,e&&p?.setAttribute(`error`,!0),p?.end())};return[l,new u.Transform({transform(e,t,n){r?.(e.length),p?.addEvent(`processed`,{bytes:e.length}),n(null,e)},final(e){h(),e()},destroy(e,t){h(e),t(e)}}),d]})}async function ne(e,t,n,r){await(0,l.pipeline)(e,...t,n,r??{})}function $(e,t){let n=p.default.relative(t,e);if(n===`..`||n.startsWith(`..${p.default.sep}`)||p.default.isAbsolute(n))throw Error(`[PipeX] Path is outside the allowed root`)}function re(e,t){let n=p.default.resolve(e);if(!(0,m.existsSync)(n))throw Error(`[PipeX] File not found: ${n}`);let r=m.realpathSync.native(p.default.resolve(t??process.cwd())),i=m.realpathSync.native(n);return $(i,r),i}function ie(e,t){let n=m.realpathSync.native(p.default.resolve(t??process.cwd())),r=p.default.resolve(e),i=m.realpathSync.native(p.default.dirname(r));$(i,n);let a=p.default.join(i,p.default.basename(r));return(0,m.existsSync)(a)&&$(m.realpathSync.native(a),n),a}Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(exports,"B",{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return K}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,"F",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"H",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"I",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"L",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"M",{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,"N",{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return V}}),Object.defineProperty(exports,"P",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"R",{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return G}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"U",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"V",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"W",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return U}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return J}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return re}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return ee}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return X}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"j",{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return Z}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return`__pipex_v`}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return q}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return 268435456}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return 65536}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return H}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return te}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(exports,"z",{enumerable:!0,get:function(){return b}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let e=require("node:events"),t=require("node:crypto");require("zod");const n=require("./core-DSIwvTqu.cjs");let r=require("node:stream"),i=require("node:fs"),a=require("node:path"),o=require("node:module");const s=require("./resourceLimits-lJrEhDE5.cjs");a=n.W(a,1);let c;const l=()=>c??=(0,o.createRequire)(require("url").pathToFileURL(__filename).href)(`koffi`),u=e=>{throw Error(`[PipeX] Secure file `+e+` failed`)},d=e=>{let t=a.default.parse(e).root;return e.slice(t.length).split(a.default.sep).filter(Boolean)};function f(e,t,r){let o=i.realpathSync.native(a.default.resolve(r??process.cwd())),s=n.c(e,o),c=n.k(t,o);if(s===c)throw Error(`[PipeX] Input and output must be different files`);return process.platform===`win32`?h(s,c,o):v(s,c)}let p;function m(){let e=l(),t=e.load(`kernel32.dll`),n=e.load(`ntdll.dll`),r=e.struct({Length:`uint16_t`,MaximumLength:`uint16_t`,Buffer:`str16`}),i=e.struct({Length:`uint32_t`,RootDirectory:`intptr_t`,ObjectName:e.pointer(r),Attributes:`uint32_t`,SecurityDescriptor:`void *`,SecurityQualityOfService:`void *`}),a=e.struct({Status:`intptr_t`,Information:`uintptr_t`});return{setRelativeInfo:n.func(`__stdcall`,`NtSetInformationFile`,`int32_t`,[`intptr_t`,e.out(e.pointer(a)),`void *`,`uint32_t`,`int`]),relativeOpen:n.func(`__stdcall`,`NtCreateFile`,`int32_t`,[`_Out_ intptr_t *`,`uint32_t`,e.pointer(i),e.out(e.pointer(a)),`void *`,`uint32_t`,`uint32_t`,`uint32_t`,`uint32_t`,`void *`,`uint32_t`]),attributesSize:e.sizeof(i),pointerBytes:e.sizeof(`void *`),finalPath:t.func(`__stdcall`,`GetFinalPathNameByHandleW`,`uint32_t`,[`intptr_t`,`_Out_ void *`,`uint32_t`,`uint32_t`]),open:t.func(`__stdcall`,`CreateFileW`,`intptr_t`,[`str16`,`uint32_t`,`uint32_t`,`void *`,`uint32_t`,`uint32_t`,`void *`]),info:t.func(`__stdcall`,`GetFileInformationByHandle`,`int`,[`intptr_t`,`_Out_ void *`]),type:t.func(`__stdcall`,`GetFileType`,`uint32_t`,[`intptr_t`]),read:t.func(`__stdcall`,`ReadFile`,`int`,[`intptr_t`,`_Out_ void *`,`uint32_t`,`_Out_ uint32_t *`,`void *`]),write:t.func(`__stdcall`,`WriteFile`,`int`,[`intptr_t`,`void *`,`uint32_t`,`_Out_ uint32_t *`,`void *`]),setInfo:t.func(`__stdcall`,`SetFileInformationByHandle`,`int`,[`intptr_t`,`int`,`void *`,`uint32_t`]),close:t.func(`__stdcall`,`CloseHandle`,`int`,[`intptr_t`])}}function h(e,i,o){let s=p??=m(),c=[],l=/* @__PURE__ */ new Map,f=/* @__PURE__ */ new Set,h=!1,g=!1,_,v,y=e=>{let t=Buffer.alloc(52);return s.info(e,t)||u(`handle inspection`),t},b=(e,t,n,r,i)=>{let a=s.open(e,t,n,null,r,2097152|(i?33554432:128),null);BigInt(a)===-1n&&u(`open`),c.push(a);let o=y(a).readUInt32LE(0);return(o&1024||!!(o&16)!==i||s.type(a)!==1)&&u(`file type validation`),a},x=(e,t,n,r,i,a=!1)=>{(!t||t===`.`||t===`..`||/[\\/:]/.test(t))&&u(`relative name validation`);let o=[0],l=s.relativeOpen(o,(n|1048576)>>>0,{Length:s.attributesSize,RootDirectory:e,ObjectName:{Length:Buffer.byteLength(t,`utf16le`),MaximumLength:Buffer.byteLength(t,`utf16le`)+2,Buffer:t},Attributes:64,SecurityDescriptor:null,SecurityQualityOfService:null},{},null,128,i?3:1,r?2:1,2097184|(i?1:64),null,0);if(l<0){if(a&&l>>>0==0xc0000034)return;u(`relative open`)}let d=o[0];c.push(d),r&&(v=d);let f=y(d).readUInt32LE(0);return(f&1024||!!(f&16)!==i||s.type(d)!==1)&&u(`relative type validation`),d},S=(e,t)=>{let n=``,r=t;for(let t of d(a.default.relative(o,a.default.dirname(e)))){n=a.default.join(n,t);let e=l.get(n.toLowerCase());e===void 0?(r=x(r,t,0x80000000,!1,!0),l.set(n.toLowerCase(),r)):r=e}return r},C,w=()=>{for(let e of c.reverse())s.close(e);c.length=0};try{let n=b(o,0x80000000,3,3,!0),r=Buffer.alloc(65536),l=s.finalPath(n,r,r.length/2,0);(!l||l>=r.length/2)&&u(`root identity validation`),a.default.normalize((e=>e.startsWith(`\\\\?\\UNC\\`)?`\\\\`+e.slice(8):e.startsWith(`\\\\?\\`)?e.slice(4):e)(r.subarray(0,l*2).toString(`utf16le`))).toLowerCase()!==a.default.normalize(o).toLowerCase()&&u(`root identity validation`);let d=S(e,n);C=S(i,n),_=x(d,a.default.basename(e),0x80000000,!1,!1);let f=x(C,a.default.basename(i),0x80000000,!1,!1,!0);if(f!==void 0)try{let e=y(_),t=y(f);if(e.readUInt32LE(28)===t.readUInt32LE(28)&&e.subarray(44,52).equals(t.subarray(44,52)))throw Error(`[PipeX] Input and output must be different files`);t.readUInt32LE(0)&1024&&u(`output reparse validation`)}finally{s.close(f),c.pop()}let p=`.pipex-`+(0,t.randomUUID)()+`.tmp`;v=x(C,p,0x40010080,!0,!1)}catch(e){throw v!==void 0&&s.setInfo(v,4,Buffer.from([1]),1),w(),e}let T=(e,t)=>{let n=[0],r=new Promise((r,i)=>{(e?s.write:s.read).async(e?v:_,t,t.length,n,null,(t,a)=>{t||!a?i(/* @__PURE__ */ Error(`[PipeX] Secure file `+(e?`write`:`read`)+` failed`)):r(n[0])})});return f.add(r),r.then(()=>f.delete(r),()=>f.delete(r)),r},E=!1,D=new r.Readable({highWaterMark:n.t,read(){if(E)return;E=!0;let e=Buffer.allocUnsafe(n.t);T(!1,e).then(t=>{E=!1,this.destroyed||this.push(t?e.subarray(0,t):null)},e=>{E=!1,this.destroy(e)})}}),O=new r.Writable({highWaterMark:n.t,write(e,t,n){let r=(async()=>{let t=0;for(;t<e.length;){g&&u(`write after disposal`);let n=await T(!0,e.subarray(t));n||u(`write progress`),t+=n}})();f.add(r),r.then(()=>{f.delete(r),n()},e=>{f.delete(r),n(e)})}});return{source:D,destination:O,commit(){(g||h)&&u(`commit state`);let e=s.pointerBytes,t=e===8?8:4,n=t+e,r=n+4,o=Buffer.from(a.default.basename(i)+`\0`,`utf16le`),c=Buffer.alloc(r+o.length);c[0]=1,e===8?c.writeBigUInt64LE(BigInt(C),t):c.writeUInt32LE(Number(C),t),c.writeUInt32LE(o.length-2,n),o.copy(c,r);let l=s.setRelativeInfo(v,{},c,c.length,10);l<0&&u(`atomic rename status `+(l>>>0).toString(16)),h=!0},async dispose(){g||(g=!0,D.destroy(),O.destroy(),await Promise.allSettled([...f]),h||s.setInfo(v,4,Buffer.from([1]),1),w())}}}let g;function _(){let e=l().load(null);return{read:e.func(`intptr_t read(int fd, _Out_ void *buffer, size_t count)`),write:e.func(`intptr_t write(int fd, const void *buffer, size_t count)`),fcntl:e.func(`int fcntl(int fd, int command, int argument)`),openat:e.func(`int openat(int dirfd, const char *path, int flags, unsigned int mode)`),mkdirat:e.func(`int mkdirat(int dirfd, const char *path, unsigned int mode)`),renameat:e.func(`int renameat(int oldfd, const char *oldname, int newfd, const char *newname)`),unlinkat:e.func(`int unlinkat(int dirfd, const char *path, int flags)`)}}function v(e,o){let s=g??=_(),c=[],l=i.constants.O_NOFOLLOW,f=i.constants.O_DIRECTORY;l&&f||u(`platform support`);let p=()=>{for(let e of c.reverse())try{(0,i.closeSync)(e)}catch{}c.length=0},m=(e,t,n,r=0)=>{let i=s.openat(e,t,n|l,r);return i<0&&u(`relative open`),c.push(i),s.fcntl(i,2,1)<0&&u(`descriptor inheritance protection`),i},h=e=>{let t=(0,i.openSync)(a.default.parse(e).root,i.constants.O_RDONLY|f);c.push(t);for(let n of d(a.default.dirname(e)))t=m(t,n,i.constants.O_RDONLY|f);return t},v=`.pipex-`+(0,t.randomUUID)(),y,b,x,S,C=!1,w=!1,T=!1,E=/* @__PURE__ */ new Set,D=process.platform===`linux`?512:process.platform===`darwin`?128:process.platform===`openbsd`?8:2048,O=()=>{b!==void 0&&!C&&s.unlinkat(b,`data`,0),y!==void 0&&T&&s.unlinkat(y,v,D),p()};try{let t=h(e);y=h(o),x=m(t,a.default.basename(e),i.constants.O_RDONLY|i.constants.O_NONBLOCK);let n=(0,i.fstatSync)(x,{bigint:!0});n.isFile()||u(`input type validation`);let r=s.openat(y,a.default.basename(o),i.constants.O_RDONLY|l|i.constants.O_NONBLOCK,0);if(r>=0)try{let e=(0,i.fstatSync)(r,{bigint:!0});if(n.dev===e.dev&&n.ino===e.ino)throw Error(`[PipeX] Input and output must be different files`)}finally{(0,i.closeSync)(r)}s.mkdirat(y,v,448)!==0&&u(`temporary directory creation`),T=!0,b=m(y,v,i.constants.O_RDONLY|f);let c=(0,i.fstatSync)(b);(c.mode&63||c.uid!==process.geteuid?.())&&u(`temporary directory permissions`),S=m(b,`data`,i.constants.O_WRONLY|i.constants.O_CREAT|i.constants.O_EXCL,384)}catch(e){throw O(),e}let k=(e,t)=>{let n=new Promise((n,r)=>{(e?s.write:s.read).async(e?S:x,t,t.length,(e,t)=>{e||t<0?r(/* @__PURE__ */ Error(`[PipeX] Secure relative file I/O failed`)):n(Number(t))})});return E.add(n),n.then(()=>E.delete(n),()=>E.delete(n)),n},A=!1,j=new r.Readable({highWaterMark:n.t,read(){if(A)return;A=!0;let e=Buffer.allocUnsafe(n.t);k(!1,e).then(t=>{A=!1,this.destroyed||this.push(t?e.subarray(0,t):null)},e=>{A=!1,this.destroy(e)})}}),M=new r.Writable({highWaterMark:n.t,write(e,t,n){let r=(async()=>{let t=0;for(;t<e.length;){w&&u(`write after disposal`);let n=await k(!0,e.subarray(t));n||u(`relative write progress`),t+=n}})();E.add(r),r.then(()=>{E.delete(r),n()},e=>{E.delete(r),n(e)})}});return{source:j,destination:M,commit(){(w||C)&&u(`commit state`),s.renameat(b,`data`,y,a.default.basename(o))!==0&&u(`atomic relative rename`),C=!0},async dispose(){w||(w=!0,j.destroy(),M.destroy(),await Promise.allSettled([...E]),O())}}}var y=class{#e;constructor(e){this.#e=e}async#t(e,t,r,i,a){let o=f(e,t,r);try{await a(o.source,o.destination),n.B(i),o.commit()}finally{await o.dispose()}}#n(e,t){return{requestId:e,signal:t,track:t=>this.#e.trackWork(e,t),limits:this.#e.limits,logger:this.#e.logger,tracer:this.#e.tracer}}async process(e,t,r,i={}){let a=this.#e.createOperationSignal(i);n.B(a);let o=this.#e.startRequest();try{if(this.#e.schema)throw Error(`[PipeX] Global object schemas cannot validate raw file streams`);await this.#t(e,t,r,a,async(e,t)=>{let r=this.#n(o,a),i=[n.p(this.#e.limits.maxInputBytes,`input`),...n.x(this.#e.plugins,`compress`,!1,e=>this.#e.emitProgress(e,o),this.#e.logger,this.#e.tracer,this.#e.dlq,r),n.p(this.#e.limits.maxOutputBytes,`output`)];await n.A(e,i,t,{signal:a})}),await n.R(this.#e.emitAudit({requestId:o,operation:`process`,metadata:{controller:`file`}}),a,e=>this.#e.trackWork(o,e)),n.B(a),this.#e.endRequest(o)}catch(e){throw this.#e.emitError(e,o),e}}async reverse(e,t,r,i={}){let a=this.#e.createOperationSignal(i);n.B(a);let o=this.#e.startRequest();try{if(this.#e.schema)throw Error(`[PipeX] Global object schemas cannot validate raw file streams`);await this.#t(e,t,r,a,async(e,t)=>{let r=this.#n(o,a),i=[n.p(this.#e.limits.maxInputBytes,`input`),...n.x(this.#e.plugins,`decompress`,!0,e=>this.#e.emitProgress(e,o),this.#e.logger,this.#e.tracer,this.#e.dlq,r),n.p(this.#e.limits.maxOutputBytes,`output`)];await n.A(e,i,t,{signal:a})}),await n.R(this.#e.emitAudit({requestId:o,operation:`reverse`,metadata:{controller:`file`}}),a,e=>this.#e.trackWork(o,e)),n.B(a),this.#e.endRequest(o)}catch(e){throw this.#e.emitError(e,o),e}}async pack(e,t,r,i={}){let a=this.#e.createOperationSignal(i);n.B(a);let o=this.#e.startRequest();try{await this.#t(e,t,r,a,async(e,t)=>{let r=[n.p(this.#e.limits.maxInputBytes,`input`),n.b(this.#e.limits.maxFrames),n.h(this.#e.limits.maxFrameBytes,`MessagePack frame`),n.S(),n.v(n.g([])),n.H(this.#e.limits.maxFrameBytes,Math.min(2**53-1,this.#e.limits.maxFrames+1)),n.p(this.#e.limits.maxOutputBytes,`output`)];await n.A(e,r,t,{signal:a})}),await n.R(this.#e.emitAudit({requestId:o,operation:`pack`,metadata:{controller:`file`}}),a,e=>this.#e.trackWork(o,e)),n.B(a),this.#e.endRequest(o)}catch(e){throw this.#e.emitError(e,o),e}}async unpack(e,t,i,a={}){let o=this.#e.createOperationSignal(a);n.B(o);let s=this.#e.startRequest();try{await this.#t(e,t,i,o,async(e,t)=>{let i=n.C(this.#e.limits.maxInputBytes),a=n._(e=>{let t=[];if(e.plugins.length!==t.length||e.plugins.some((e,n)=>e!==t[n]))throw Error(`[PipeX] Manifest plugin chain does not match the configured engine`);this.#e.emit(`manifest`,e,s)}),c=n.y(),l=new r.Transform({writableObjectMode:!0,readableObjectMode:!0,transform:(e,t,n)=>{try{this.#e.validate(e),n(null,e)}catch(e){n(e)}}});await n.A(e,[n.p(this.#e.limits.maxInputBytes,`input`),n.H(this.#e.limits.maxFrameBytes,Math.min(2**53-1,this.#e.limits.maxFrames+1)),i,a,n.b(this.#e.limits.maxFrames),l,c,n.p(this.#e.limits.maxOutputBytes,`output`)],t,{signal:o})}),await n.R(this.#e.emitAudit({requestId:s,operation:`unpack`,metadata:{controller:`file`}}),o,e=>this.#e.trackWork(s,e)),n.B(o),this.#e.endRequest(s)}catch(e){throw this.#e.emitError(e,s),e}}},b=class{#e;constructor(e){this.#e=e}pack(e){try{n.l(e,Math.min(this.#e.limits.maxInputBytes,this.#e.limits.maxFrameBytes),`Serialization input`);let t=n.a.pack(e);if(t.length>this.#e.limits.maxInputBytes)throw Error(`[PipeX] Packed input exceeds configured limit`);if(n.V(t,this.#e.limits.maxFrameBytes,1),t.length>this.#e.limits.maxOutputBytes)throw Error(`[PipeX] Packed output exceeds configured limit`);return t}catch(e){throw e instanceof Error&&e.message.startsWith(`[PipeX]`)?e:new s.w({stage:`pack`})}}unpack(e){try{if(e.byteLength>this.#e.limits.maxInputBytes)throw Error(`[PipeX] Serialized input exceeds configured limit`);return n.V(e,this.#e.limits.maxFrameBytes,1),n.s.unpack(e)}catch(e){throw e instanceof Error&&e.message.startsWith(`[PipeX]`)?e:new s.w({stage:`unpack`})}}#t=/* @__PURE__ */ new WeakMap;async run(e,t={}){let r=this.#e.createOperationSignal(t);n.B(r);let i=n.w(e);n.u(i);let a=this.#e.plugins,o=[...this.#e.pipeline],s=this.#e.limits,c=this.#e.startRequest({operation:`run`}),l=Date.now(),u=this.#e.tracer?.startSpan(`binary:run`,{requestId:c});try{u?.setAttribute(`input.type`,i),this.#e.validate(e),n.l(e,s.maxInputBytes,`Input`);let t=n.N(e);if(t.length>s.maxInputBytes)throw Error(`[PipeX] Input exceeds configured limit`);(i===`object`||i===`array`)&&n.V(t,s.maxFrameBytes,1);let d=Object.create(null);for(let e of a){let a=Date.now(),o=this.#e.tracer?.startSpan(`plugin:${e.name}`,{requestId:c});try{o?.setAttribute(`mode`,`process`);let a=n.O(c,{originalType:i},this.#e.logger,o,r,s);if(t=await n.P(()=>e.process(t,a),e.retryOptions,this.#e.logger,{signal:r,limits:s,track:e=>this.#e.trackWork(c,e)}),!Buffer.isBuffer(t)||t.length>s.maxOutputBytes)throw Error(`[PipeX] Plugin output exceeds configured limit`)}catch(e){throw o?.setAttribute(`error`,!0),e}finally{o?.end()}d[e.name]=Date.now()-a,this.#e.emit(`plugin:after`,e.name,d[e.name])}if(t.length>s.maxOutputBytes)throw Error(`[PipeX] Output exceeds configured limit`);n.B(r);let f=Date.now()-l;await n.R(this.#e.emitAudit({requestId:c,operation:`process`,metadata:{inputType:i,durationMs:f}}),r,e=>this.#e.trackWork(c,e)),n.B(r),this.#t.set(t,i);let p={data:t,originalType:i,pipeline:o,metrics:{durationMs:f,steps:d}};return u?.setAttribute(`duration_ms`,f),this.#e.endRequest(c,f),p}catch(e){throw u?.setAttribute(`error`,!0),this.#e.emitError(e,c),e}finally{u?.end(),this.#e.releaseRequest(c)}}async undo(e,t,r={}){let i=Buffer.isBuffer(e),a,o,s;if(i)n.u(t),a=e,o=t,s=r;else{let r=e;if(!r||typeof r!=`object`||!Buffer.isBuffer(r.data)||!Array.isArray(r.pipeline)||r.pipeline.length>256||!r.pipeline.every(e=>typeof e==`string`&&e.length<=512)||!r.metrics||!Number.isFinite(r.metrics.durationMs)||r.metrics.durationMs<0||!r.metrics.steps||typeof r.metrics.steps!=`object`||Array.isArray(r.metrics.steps)||!Object.values(r.metrics.steps).every(e=>typeof e==`number`&&Number.isFinite(e)&&e>=0))throw Error(`[PipeX] Invalid EngineResult`);if(n.u(r.originalType),t!==void 0&&(typeof t!=`object`||!t))throw Error(`[PipeX] Invalid undo options`);let i=t,c=i?.expectedType??this.#t.get(r.data);if(c===void 0)throw Error(`[PipeX] Transported EngineResult requires a trusted expectedType`);if(n.u(c),c!==r.originalType)throw Error(`[PipeX] Result type does not match the expected type`);a=r.data,o=c,s=i??{}}let c=this.#e.createOperationSignal(s);n.B(c);let l=this.#e.plugins;n.d(l);let u=this.#e.limits;if(a.length>u.maxInputBytes)throw Error(`[PipeX] Undo input exceeds configured limit`);let d=this.#e.startRequest({operation:`undo`,originalType:o}),f=this.#e.tracer?.startSpan(`binary:undo`,{requestId:d});try{if(i&&l.length===0&&a.length>0){let e;try{e=this.unpackWithManifest(a)}catch{}if(e){if(e.manifest.plugins.length!==0)throw Error(`[PipeX] Manifest plugin chain does not match the configured engine`);if(n.w(e.data)!==o)throw Error(`[PipeX] Manifest data does not match the expected type`);a=n.N(e.data)}}for(let e of[...l].reverse()){let t=this.#e.tracer?.startSpan(`plugin:${e.name}`,{requestId:d});try{t?.setAttribute(`mode`,`reverse`);let r=n.O(d,{originalType:o},this.#e.logger,t,c,u);if(a=await n.P(()=>e.reverse(a,r),e.retryOptions,this.#e.logger,{signal:c,limits:u,track:e=>this.#e.trackWork(d,e)}),!Buffer.isBuffer(a)||a.length>u.maxOutputBytes)throw Error(`[PipeX] Plugin output exceeds configured limit`)}catch(e){throw t?.setAttribute(`error`,!0),e}finally{t?.end()}this.#e.emit(`plugin:after`,e.name,0)}if(a.length>u.maxOutputBytes)throw Error(`[PipeX] Output exceeds configured limit`);n.B(c);let e=n.T(a,o,u.maxFrameBytes);return this.#e.validate(e),n.B(c),await n.R(this.#e.emitAudit({requestId:d,operation:`reverse`,metadata:{originalType:o}}),c,e=>this.#e.trackWork(d,e)),n.B(c),this.#e.endRequest(d),e}catch(e){throw f?.setAttribute(`error`,!0),this.#e.emitError(e,d),e}finally{f?.end(),this.#e.releaseRequest(d)}}packWithManifest(e){if(this.#e.plugins.length>0)throw Error(`[PipeX] packWithManifest is serialization-only; use binary.run for plugin transforms`);let t=n.g([]);n.l(e,Math.min(this.#e.limits.maxInputBytes,this.#e.limits.maxFrameBytes),`Serialization input`);let r=n.a.pack(t),i=n.a.pack(e);if(n.V(r,this.#e.limits.maxFrameBytes,1),n.V(i,this.#e.limits.maxFrameBytes,1),r.length+i.length>Math.min(this.#e.limits.maxInputBytes,this.#e.limits.maxOutputBytes))throw Error(`[PipeX] Serialized input exceeds configured limit`);return Buffer.concat([r,i])}unpackWithManifest(e){if(e.length>this.#e.limits.maxInputBytes)throw Error(`[PipeX] Serialized input exceeds configured limit`);n.V(e,this.#e.limits.maxFrameBytes,2);let t=[];try{n.s.unpackMultiple(e,e=>{if(t.length>=2)throw Error(`[PipeX] Frame count exceeds configured limit`);t.push(e)})}catch(e){throw e instanceof Error&&e.message.startsWith(`[PipeX]`)?e:Error(`[PipeX] binary.unpackWithManifest: invalid MessagePack input`)}if(t.length<2)throw Error(`[PipeX] binary.unpackWithManifest: buffer contains fewer than 2 frames`);if(!n.U(t[0]))throw Error(`[PipeX] binary.unpackWithManifest: first frame is not a PipeXManifest`);return{manifest:t[0],data:t[1]}}},x=class{#e;constructor(e){this.#e=e}#t(e,t){return{requestId:e,signal:t,track:t=>this.#e.trackWork(e,t),limits:this.#e.limits,logger:this.#e.logger,tracer:this.#e.tracer}}#n(e,t){return r.Duplex.from({writable:e,readable:t})}#r(e,t,i){let a=this.#e.createOperationSignal(i);if(n.B(a),this.#e.schema)throw Error(`[PipeX] Global object schemas cannot validate raw byte streams`);let o=this.#e.startRequest(),s=this.#t(o,a),c=t?`decompress`:`compress`,l;try{l=n.x(this.#e.plugins,c,t,e=>this.#e.emitProgress(e,o),this.#e.logger,this.#e.tracer,this.#e.dlq,s)}catch(e){throw this.#e.emitError(e,o),e}let u=new r.PassThrough,d,f=new r.Writable({write(t,n,r){if(u.destroyed){let t=e.errored??u.errored;r(t instanceof Error?t:/* @__PURE__ */ Error(`[PipeX] Stream pipeline is closed`))}else u.write(t,n,r)},final(e){d=e,u.end()},destroy(e,t){d=void 0,u.destroyed||u.destroy(e??void 0),t(e)}}),p=e=>{let t=d;d=void 0,t?t(e):e&&!f.destroyed&&f.destroy(e)};return n.A(u,[n.p(this.#e.limits.maxInputBytes,`input`),...l,n.p(this.#e.limits.maxOutputBytes,`output`)],e,{signal:a}).then(async()=>{await n.R(this.#e.emitAudit({requestId:o,operation:t?`reverse`:`process`,metadata:{controller:`stream`}}),a,e=>this.#e.trackWork(o,e)),n.B(a),this.#e.endRequest(o),p()}).catch(e=>{let t=e instanceof Error?e:Error(String(e));this.#e.emitError(t,o),p(t)}),f}into(e,t={}){return this.#r(e,!1,t)}reverseInto(e,t={}){return this.#r(e,!0,t)}pack(e={}){let t=this.#e.createOperationSignal(e);n.B(t);let i=this.#e.startRequest({operation:`pack`}),a=new r.PassThrough({objectMode:!0}),o=new r.PassThrough,s=[n.b(this.#e.limits.maxFrames),n.h(this.#e.limits.maxFrameBytes,`MessagePack frame`),n.S(),n.v(n.g([])),n.H(this.#e.limits.maxFrameBytes,Math.min(2**53-1,this.#e.limits.maxFrames+1)),n.p(this.#e.limits.maxOutputBytes,`output`)],c=this.#n(a,o);return n.A(a,s,o,{signal:t}).then(async()=>{await n.R(this.#e.emitAudit({requestId:i,operation:`pack`,metadata:{controller:`stream`}}),t,e=>this.#e.trackWork(i,e)),n.B(t),this.#e.endRequest(i)}).catch(e=>{this.#e.emitError(e,i),c.destroy(e instanceof Error?e:Error(String(e)))}),c}unpack(e={}){let t=this.#e.createOperationSignal(e);n.B(t);let i=this.#e.startRequest({operation:`unpack`}),a=new r.PassThrough,o=new r.PassThrough({objectMode:!0}),s=n.C(this.#e.limits.maxInputBytes),c=n._(e=>{let t=[];if(e.plugins.length!==t.length||e.plugins.some((e,n)=>e!==t[n]))throw Error(`[PipeX] Manifest plugin chain does not match the configured engine`);this.#e.emit(`manifest`,e,i)}),l=new r.Transform({writableObjectMode:!0,readableObjectMode:!0,transform:(e,t,n)=>{try{this.#e.validate(e),n(null,e)}catch(e){n(e)}}}),u=[n.p(this.#e.limits.maxInputBytes,`input`),n.H(this.#e.limits.maxFrameBytes,Math.min(2**53-1,this.#e.limits.maxFrames+1)),s,c,n.b(this.#e.limits.maxFrames),l],d=this.#n(a,o);return n.A(a,u,o,{signal:t}).then(async()=>{await n.R(this.#e.emitAudit({requestId:i,operation:`unpack`,metadata:{controller:`stream`}}),t,e=>this.#e.trackWork(i,e)),n.B(t),this.#e.endRequest(i)}).catch(e=>{this.#e.emitError(e,i),d.destroy(e instanceof Error?e:Error(String(e)))}),d}async pipe(e,t,r=!1,i={}){let a=this.#e.createOperationSignal(i);if(n.B(a),this.#e.schema)throw Error(`[PipeX] Global object schemas cannot validate raw byte streams`);let o=this.#e.startRequest(),s=r?`decompress`:`compress`,c=this.#t(o,a);try{let i=n.x(this.#e.plugins,s,r,e=>this.#e.emitProgress(e,o),this.#e.logger,this.#e.tracer,this.#e.dlq,c);await n.A(e,[n.p(this.#e.limits.maxInputBytes,`input`),...i,n.p(this.#e.limits.maxOutputBytes,`output`)],t,{signal:a}),await n.R(this.#e.emitAudit({requestId:o,operation:r?`reverse`:`process`,metadata:{controller:`stream`}}),a,e=>this.#e.trackWork(o,e)),n.B(a),this.#e.endRequest(o)}catch(e){throw this.#e.emitError(e,o),e}}};const S=0x7fffffff;var C=class r extends e.EventEmitter{static pluginRegistry=/* @__PURE__ */ new Map;static registerPlugin(e,t){if(!/^[a-z0-9][a-z0-9-]{0,63}$/i.test(e)||typeof t!=`function`)throw Error(`[PipeX] Invalid plugin registration`);this.pluginRegistry.set(e,e=>new t(e))}static async fromConfig(e){if(!e||typeof e!=`object`)throw Error(`[PipeX] Configuration must be an object`);let t=new r(e.limits);if(e.logger&&t.setLogger(e.logger),e.tracer&&t.setTracer(e.tracer),e.auditLogger&&t.setAuditLogger(e.auditLogger),e.dlq&&t.setDlq(e.dlq),e.schemaRegistry&&t.setSchemaRegistry(e.schemaRegistry),e.schema&&t.setSchema(e.schema),e.plugins){if(!Array.isArray(e.plugins))throw Error(`[PipeX] Configuration plugins must be an array`);for(let n of e.plugins){let e=this.pluginRegistry.get(n.name);if(!e)throw Error(`[PipeX] Unknown plugin in config: ${n.name}`);try{t.use(e(n.options))}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`[PipeX] Failed to initialize plugin "${n.name}": ${t}`,{cause:e})}}}return t}#e=[];#t=Object.freeze([]);#n;#r;#i;#a;#o;#s;#c;#l=/* @__PURE__ */ new Set;#u=/* @__PURE__ */ new Map;#d=/* @__PURE__ */ new Set;#f=/* @__PURE__ */ new Map;file;binary;stream;constructor(e={}){super(),this.#c=Object.freeze({...s.t,...e}),this.#p(this.#c),this.file=new y(this),this.binary=new b(this),this.stream=new x(this)}#p(e){for(let[t,n]of Object.entries(e))if(!Number.isSafeInteger(n)||n<0)throw Error(`[PipeX] Invalid engine limit ${t}`);if(e.maxInputBytes<1||e.maxOutputBytes<1||e.maxFrameBytes<1||e.maxFrames<1||e.maxConcurrentOperations<1||e.maxRetryAttempts<1||e.maxKmsEncryptedKeyBytes<1||e.maxKmsKeyIdBytes<1)throw Error(`[PipeX] Engine limits must be positive`);if(e.operationTimeoutMs>S||e.maxKmsEncryptedKeyBytes>0xffffffff)throw Error(`[PipeX] Engine limit exceeds its supported protocol or timer range`)}get limits(){return this.#c}setLimits(e){if(this.#l.size>0)throw Error(`[PipeX] Cannot modify engine limits while operations are active`);let t={...this.#c,...e};return this.#p(t),this.#c=Object.freeze(t),this}createOperationSignal(e={}){let t=e.timeoutMs??this.#c.operationTimeoutMs;if(!Number.isSafeInteger(t)||t<0||t>S)throw Error(`[PipeX] Invalid operation timeout`);let r=e.signal?[e.signal]:[];t>0&&r.push(AbortSignal.timeout(t));let i=r.length===0?new AbortController().signal:AbortSignal.any(r);return n.z(i,t),i}setDlq(e){if(!e||typeof e.write!=`function`)throw Error(`[PipeX] DLQ must be a writable stream`);return this.#o=e,this}get dlq(){return this.#o}setLogger(e){if(!e||![`info`,`warn`,`error`,`debug`].every(t=>typeof e[t]==`function`))throw Error(`[PipeX] Logger must implement info, warn, error, and debug`);return this.#i=n.I(e),this}get logger(){return this.#i}setTracer(e){if(!e||typeof e.startSpan!=`function`)throw Error(`[PipeX] Tracer must implement startSpan`);return this.#a=n.L(e),this}get tracer(){return this.#a}setAuditLogger(e){if(!e||typeof e.log!=`function`)throw Error(`[PipeX] Audit logger must implement log`);return this.#s=e,this}async emitAudit(e){this.#s&&await this.#s.log({...e,pluginChain:e.operation===`pack`||e.operation===`unpack`?[]:[...this.#f.get(e.requestId)??this.pipeline],timestamp:Date.now()})}setSchemaRegistry(e){if(!e||typeof e.getSchema!=`function`)throw Error(`[PipeX] Schema registry must implement getSchema`);return this.#r=e,this}async loadSchema(e,t){if(!this.#r)throw Error(`[PipeX] No Schema Registry configured`);let n=await this.#r.getSchema(e,t);this.setSchema(n)}setSchema(e){if(!e||typeof e.safeParse!=`function`)throw Error(`[PipeX] Schema must implement safeParse`);return this.#n=e,this}get schema(){return this.#n}validate(e){if(this.#n&&!this.#n.safeParse(e).success)throw Error(`[PipeX] Core Validation failed`)}use(e){if(!e||typeof e.name!=`string`||e.name.length===0||e.name.length>128||typeof e.version!=`string`||e.version.length===0||typeof e.process!=`function`)throw Error(`[PipeX] Invalid processor plugin`);if(n.E(e),this.#l.size>0)throw Error(`[PipeX] Cannot modify the plugin pipeline while operations are active`);if(this.#e.length>=256)throw Error(`[PipeX] Maximum plugin count exceeded`);return this.#e.push(e),this.#t=Object.freeze([...this.#e]),this}get plugins(){return this.#t}get pipeline(){return Object.freeze(this.#t.map(e=>`${e.name}@${e.version}`))}get pluginCapabilities(){return Object.freeze(this.#t.map(e=>Object.freeze({plugin:`${e.name}@${e.version}`,...n.E(e)})))}startRequest(e={}){if(this.#l.size>=this.#c.maxConcurrentOperations)throw Error(`[PipeX] Maximum concurrent operations exceeded`);let n=(0,t.randomUUID)();this.#l.add(n),this.#f.set(n,this.pipeline);try{this.#i?.info(`[PipeX] Request started`,{requestId:n,...e})}catch{}return this.emit(`start`,n),n}trackWork(e,t){let n=this.#u.get(e);n||this.#u.set(e,n=/* @__PURE__ */ new Set),n.add(t);let r=()=>{n.delete(t),n.size===0&&(this.#u.delete(e),this.#d.has(e)&&this.releaseRequest(e))};t.then(r,r)}releaseRequest(e){this.#u.get(e)?.size?this.#d.add(e):(this.#l.delete(e),this.#d.delete(e),this.#f.delete(e))}endRequest(e,t){this.releaseRequest(e);try{this.#i?.info(`[PipeX] Request ended`,{requestId:e,durationMs:t})}catch{}this.emit(`end`,e,t)}emitProgress(e,t){this.emit(`progress`,e,t)}emitError(e,t){let n=e instanceof Error?e:Error(String(e));this.releaseRequest(t);try{this.#i?.error(`[PipeX] Request failed`,{requestId:t,error:n.message})}catch{}this.listenerCount(`error`)>0&&this.emit(`error`,n,t)}emit(e,...t){let r=this.rawListeners(e);for(let e of r)n.F(()=>Reflect.apply(e,this,t));return r.length>0}on(e,t){return super.on(e,t)}once(e,t){return super.once(e,t)}};Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return C}});
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import { Duplex, Readable, Writable } from "node:stream";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { f as Logger, i as EngineConfig, m as PipeXManifest, n as AuditRecord, o as EngineLimits, p as OperationOptions, r as BinaryUndoOptions, s as EngineResult, t as AuditLogger, v as ProcessorPlugin, w as Tracer, x as SchemaRegistry, y as RegisteredPluginCapabilities } from "./types-B50Urzn2.cjs";
|
|
5
|
+
declare class FileController {
|
|
6
|
+
#private;
|
|
7
|
+
constructor(engine: DataEngine);
|
|
8
|
+
/**
|
|
9
|
+
* Source file → Plugin pipeline (compress) → Destination file.
|
|
10
|
+
*/
|
|
11
|
+
process(inputPath: string, outputPath: string, allowedRoot?: string, options?: OperationOptions): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Source file → Plugin pipeline (decompress, reversed) → Destination file.
|
|
14
|
+
*/
|
|
15
|
+
reverse(inputPath: string, outputPath: string, allowedRoot?: string, options?: OperationOptions): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Source file → PackrStream → manifest header → Destination msgpack file.
|
|
18
|
+
*
|
|
19
|
+
* Output format: [ PipeXManifest frame ][ ...data frames ]
|
|
20
|
+
* The serialization-only manifest declares an empty plugin chain.
|
|
21
|
+
*/
|
|
22
|
+
pack(inputPath: string, outputPath: string, allowedRoot?: string, options?: OperationOptions): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Source msgpack file → UnpackrStream → manifest extraction → NDJSON → Destination file.
|
|
25
|
+
*
|
|
26
|
+
* Fires 'manifest' event with the recovered PipeXManifest before streaming data.
|
|
27
|
+
*/
|
|
28
|
+
unpack(inputPath: string, outputPath: string, allowedRoot?: string, options?: OperationOptions): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
declare class BinaryController {
|
|
31
|
+
#private;
|
|
32
|
+
constructor(engine: DataEngine);
|
|
33
|
+
/**
|
|
34
|
+
* Serialise a supported JS value to a msgpack Buffer (synchronous).
|
|
35
|
+
* For streaming large datasets use engine.stream or engine.file.pack instead.
|
|
36
|
+
*/
|
|
37
|
+
pack(data: unknown): Buffer;
|
|
38
|
+
/**
|
|
39
|
+
* Deserialise a msgpack Buffer back to T (synchronous).
|
|
40
|
+
*/
|
|
41
|
+
unpack<T = unknown>(input: Buffer | Uint8Array): T;
|
|
42
|
+
run(input: unknown, options?: OperationOptions): Promise<EngineResult>;
|
|
43
|
+
undo<T = unknown>(result: EngineResult, options?: BinaryUndoOptions): Promise<T>;
|
|
44
|
+
undo<T = unknown>(input: Buffer, forceType: string, options?: OperationOptions): Promise<T>;
|
|
45
|
+
/**
|
|
46
|
+
* Pack data AND embed a manifest header as the first msgpack frame.
|
|
47
|
+
* Mirrors what file.pack writes to disk — useful for in-memory transport.
|
|
48
|
+
*/
|
|
49
|
+
packWithManifest(data: unknown): Buffer;
|
|
50
|
+
/**
|
|
51
|
+
* Unpack a buffer that begins with a PipeXManifest frame.
|
|
52
|
+
* Returns { manifest, data } — callers can inspect the manifest to verify
|
|
53
|
+
* the pipeline that produced the buffer before consuming data.
|
|
54
|
+
*/
|
|
55
|
+
unpackWithManifest<T = unknown>(input: Buffer): {
|
|
56
|
+
manifest: PipeXManifest;
|
|
57
|
+
data: T;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
declare class StreamController {
|
|
61
|
+
#private;
|
|
62
|
+
constructor(engine: DataEngine);
|
|
63
|
+
/**
|
|
64
|
+
* Returns a Writable that pumps incoming bytes through the plugin pipeline
|
|
65
|
+
* (compress direction) and forwards them to `destination`.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* await pipeline(readableSource, engine.stream.into(createWriteStream('out')));
|
|
69
|
+
*/
|
|
70
|
+
into(destination: Writable, options?: OperationOptions): Writable;
|
|
71
|
+
/**
|
|
72
|
+
* Returns a Writable that pumps bytes through the reversed plugin pipeline
|
|
73
|
+
* (decompress direction) and forwards to `destination`.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* await pipeline(readableSource, engine.stream.reverseInto(createWriteStream('restored')));
|
|
77
|
+
*/
|
|
78
|
+
reverseInto(destination: Writable, options?: OperationOptions): Writable;
|
|
79
|
+
/**
|
|
80
|
+
* Returns a PackrStream: write JS objects, read msgpack bytes.
|
|
81
|
+
* A manifest header frame is prepended automatically.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* await pipeline(objectSource, engine.stream.pack(), tcpSocket);
|
|
85
|
+
*/
|
|
86
|
+
pack(options?: OperationOptions): Duplex;
|
|
87
|
+
/**
|
|
88
|
+
* Returns a GuardedUnpackrStream: write msgpack bytes, read JS objects.
|
|
89
|
+
* Fires the engine's 'manifest' event when the header frame is detected.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* await pipeline(tcpSocket, engine.stream.unpack(), objectDestination);
|
|
93
|
+
*/
|
|
94
|
+
unpack(options?: OperationOptions): Duplex;
|
|
95
|
+
/**
|
|
96
|
+
* Orchestrate a complete pipeline: Readable → plugin chain → Writable.
|
|
97
|
+
* This is the primary low-level entry point — file/binary controllers
|
|
98
|
+
* build on top of this.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* await engine.stream.pipe(
|
|
102
|
+
* createReadStream('input.bin'),
|
|
103
|
+
* createWriteStream('output.bin'),
|
|
104
|
+
* );
|
|
105
|
+
*/
|
|
106
|
+
pipe(source: Readable, destination: Writable, reverse?: boolean, options?: OperationOptions): Promise<void>;
|
|
107
|
+
}
|
|
108
|
+
interface PipeXEventMap {
|
|
109
|
+
start: [requestId: string];
|
|
110
|
+
'plugin:after': [name: string, durationMs: number];
|
|
111
|
+
progress: [bytes: number, requestId: string];
|
|
112
|
+
error: [err: Error, requestId: string];
|
|
113
|
+
end: [requestId: string, durationMs?: number];
|
|
114
|
+
manifest: [manifest: unknown, requestId?: string];
|
|
115
|
+
}
|
|
116
|
+
type PluginConstructor<TOptions = unknown> = new (options: TOptions) => ProcessorPlugin;
|
|
117
|
+
declare class DataEngine extends EventEmitter {
|
|
118
|
+
#private;
|
|
119
|
+
/** Built-in plugin registry for config-driven bootstrap. */
|
|
120
|
+
private static readonly pluginRegistry;
|
|
121
|
+
/** Register a plugin class for use in fromConfig(). */
|
|
122
|
+
static registerPlugin<TOptions>(name: string, pluginClass: PluginConstructor<TOptions>): void;
|
|
123
|
+
/**
|
|
124
|
+
* Bootstrap a DataEngine from a configuration object.
|
|
125
|
+
*/
|
|
126
|
+
static fromConfig(config: EngineConfig): Promise<DataEngine>;
|
|
127
|
+
readonly file: FileController;
|
|
128
|
+
readonly binary: BinaryController;
|
|
129
|
+
readonly stream: StreamController;
|
|
130
|
+
constructor(limits?: Partial<EngineLimits>);
|
|
131
|
+
get limits(): Readonly<EngineLimits>;
|
|
132
|
+
setLimits(limits: Partial<EngineLimits>): this;
|
|
133
|
+
createOperationSignal(options?: OperationOptions): AbortSignal;
|
|
134
|
+
/**
|
|
135
|
+
* Set the optional, caller-owned failure sink (legacy DLQ terminology).
|
|
136
|
+
* A failed fallback-transform chunk is written after retries are exhausted;
|
|
137
|
+
* the operation still rejects. PipeX does not persist, replay, end, or own
|
|
138
|
+
* the supplied Writable.
|
|
139
|
+
*
|
|
140
|
+
* @param stream The caller-provided Writable used as a failure sink.
|
|
141
|
+
*/
|
|
142
|
+
setDlq(stream: Writable): this;
|
|
143
|
+
/** The current caller-provided failure sink, if any. */
|
|
144
|
+
get dlq(): Writable | undefined;
|
|
145
|
+
/**
|
|
146
|
+
* Set the engine's logger for structured observability.
|
|
147
|
+
* Compatible with Pino, Winston, or any logger implementing the Logger interface.
|
|
148
|
+
*
|
|
149
|
+
* @param logger The logger instance.
|
|
150
|
+
*/
|
|
151
|
+
setLogger(logger: Logger): this;
|
|
152
|
+
/** The current logger instance. */
|
|
153
|
+
get logger(): Logger | undefined;
|
|
154
|
+
/**
|
|
155
|
+
* Set the engine's tracer for OpenTelemetry-compatible tracing.
|
|
156
|
+
*
|
|
157
|
+
* @param tracer The tracer instance.
|
|
158
|
+
*/
|
|
159
|
+
setTracer(tracer: Tracer): this;
|
|
160
|
+
/** The current tracer instance. */
|
|
161
|
+
get tracer(): Tracer | undefined;
|
|
162
|
+
/**
|
|
163
|
+
* Set the engine's audit logger for compliance and security auditing.
|
|
164
|
+
*
|
|
165
|
+
* @param logger The audit logger instance.
|
|
166
|
+
*/
|
|
167
|
+
setAuditLogger(logger: AuditLogger): this;
|
|
168
|
+
/**
|
|
169
|
+
* Emits an audit record if an audit logger is configured.
|
|
170
|
+
* This is called automatically by controllers.
|
|
171
|
+
*
|
|
172
|
+
* @param record The audit record metadata.
|
|
173
|
+
*/
|
|
174
|
+
emitAudit(record: Omit<AuditRecord, 'pluginChain' | 'timestamp'>): Promise<void>;
|
|
175
|
+
/**
|
|
176
|
+
* Set a Schema Registry to fetch schemas dynamically.
|
|
177
|
+
*
|
|
178
|
+
* @param registry The schema registry provider.
|
|
179
|
+
*/
|
|
180
|
+
setSchemaRegistry(registry: SchemaRegistry): this;
|
|
181
|
+
/**
|
|
182
|
+
* Fetch a schema from the registry and set it as the engine's active schema.
|
|
183
|
+
*
|
|
184
|
+
* @param subject The name of the schema to fetch.
|
|
185
|
+
* @param version Optional version of the schema.
|
|
186
|
+
*/
|
|
187
|
+
loadSchema(subject: string, version?: number): Promise<void>;
|
|
188
|
+
/**
|
|
189
|
+
* Set a global Zod schema for input/output validation.
|
|
190
|
+
* When set, controllers will automatically validate data against this schema.
|
|
191
|
+
*/
|
|
192
|
+
setSchema(schema: z.ZodType<any>): this;
|
|
193
|
+
get schema(): z.ZodType<any> | undefined;
|
|
194
|
+
/** Validates data against the registered schema (if any). Throws on failure. */
|
|
195
|
+
validate(data: unknown): void;
|
|
196
|
+
/** Register a plugin and return this for fluent chaining. */
|
|
197
|
+
use(plugin: ProcessorPlugin): this;
|
|
198
|
+
/**
|
|
199
|
+
* Read-only view of the registered plugins.
|
|
200
|
+
* Exposed so controllers can iterate without mutating the list.
|
|
201
|
+
*/
|
|
202
|
+
get plugins(): readonly ProcessorPlugin[];
|
|
203
|
+
/** Human-readable plugin identifiers in execution order. */
|
|
204
|
+
get pipeline(): readonly string[];
|
|
205
|
+
/** Runtime-validated capabilities in pipeline order. */
|
|
206
|
+
get pluginCapabilities(): readonly Readonly<RegisteredPluginCapabilities>[];
|
|
207
|
+
/** Generates a requestId, emits 'start', returns the id. */
|
|
208
|
+
startRequest(metadata?: Record<string, unknown>): string;
|
|
209
|
+
/** Keep capacity reserved for accepted non-cooperative work after caller cancellation. */
|
|
210
|
+
trackWork(requestId: string, pending: Promise<unknown>): void;
|
|
211
|
+
/** Idempotent cleanup, including error paths that fail before transformation starts. */
|
|
212
|
+
releaseRequest(requestId: string): void;
|
|
213
|
+
/** Emits 'end' with optional duration. */
|
|
214
|
+
endRequest(requestId: string, durationMs?: number): void;
|
|
215
|
+
/** Emits 'progress'. */
|
|
216
|
+
emitProgress(bytes: number, requestId: string): void;
|
|
217
|
+
/** Normalises unknown throws → Error and emits 'error'. */
|
|
218
|
+
emitError(err: unknown, requestId: string): void;
|
|
219
|
+
emit<K extends keyof PipeXEventMap>(event: K, ...args: PipeXEventMap[K]): boolean;
|
|
220
|
+
on<K extends keyof PipeXEventMap>(event: K, listener: (...args: PipeXEventMap[K]) => void): this;
|
|
221
|
+
once<K extends keyof PipeXEventMap>(event: K, listener: (...args: PipeXEventMap[K]) => void): this;
|
|
222
|
+
}
|
|
223
|
+
export { PluginConstructor as n, DataEngine as t };
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import { Duplex, Readable, Writable } from "node:stream";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { f as Logger, i as EngineConfig, m as PipeXManifest, n as AuditRecord, o as EngineLimits, p as OperationOptions, r as BinaryUndoOptions, s as EngineResult, t as AuditLogger, v as ProcessorPlugin, w as Tracer, x as SchemaRegistry, y as RegisteredPluginCapabilities } from "./types-B50Urzn2.mjs";
|
|
5
|
+
declare class FileController {
|
|
6
|
+
#private;
|
|
7
|
+
constructor(engine: DataEngine);
|
|
8
|
+
/**
|
|
9
|
+
* Source file → Plugin pipeline (compress) → Destination file.
|
|
10
|
+
*/
|
|
11
|
+
process(inputPath: string, outputPath: string, allowedRoot?: string, options?: OperationOptions): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Source file → Plugin pipeline (decompress, reversed) → Destination file.
|
|
14
|
+
*/
|
|
15
|
+
reverse(inputPath: string, outputPath: string, allowedRoot?: string, options?: OperationOptions): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Source file → PackrStream → manifest header → Destination msgpack file.
|
|
18
|
+
*
|
|
19
|
+
* Output format: [ PipeXManifest frame ][ ...data frames ]
|
|
20
|
+
* The serialization-only manifest declares an empty plugin chain.
|
|
21
|
+
*/
|
|
22
|
+
pack(inputPath: string, outputPath: string, allowedRoot?: string, options?: OperationOptions): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Source msgpack file → UnpackrStream → manifest extraction → NDJSON → Destination file.
|
|
25
|
+
*
|
|
26
|
+
* Fires 'manifest' event with the recovered PipeXManifest before streaming data.
|
|
27
|
+
*/
|
|
28
|
+
unpack(inputPath: string, outputPath: string, allowedRoot?: string, options?: OperationOptions): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
declare class BinaryController {
|
|
31
|
+
#private;
|
|
32
|
+
constructor(engine: DataEngine);
|
|
33
|
+
/**
|
|
34
|
+
* Serialise a supported JS value to a msgpack Buffer (synchronous).
|
|
35
|
+
* For streaming large datasets use engine.stream or engine.file.pack instead.
|
|
36
|
+
*/
|
|
37
|
+
pack(data: unknown): Buffer;
|
|
38
|
+
/**
|
|
39
|
+
* Deserialise a msgpack Buffer back to T (synchronous).
|
|
40
|
+
*/
|
|
41
|
+
unpack<T = unknown>(input: Buffer | Uint8Array): T;
|
|
42
|
+
run(input: unknown, options?: OperationOptions): Promise<EngineResult>;
|
|
43
|
+
undo<T = unknown>(result: EngineResult, options?: BinaryUndoOptions): Promise<T>;
|
|
44
|
+
undo<T = unknown>(input: Buffer, forceType: string, options?: OperationOptions): Promise<T>;
|
|
45
|
+
/**
|
|
46
|
+
* Pack data AND embed a manifest header as the first msgpack frame.
|
|
47
|
+
* Mirrors what file.pack writes to disk — useful for in-memory transport.
|
|
48
|
+
*/
|
|
49
|
+
packWithManifest(data: unknown): Buffer;
|
|
50
|
+
/**
|
|
51
|
+
* Unpack a buffer that begins with a PipeXManifest frame.
|
|
52
|
+
* Returns { manifest, data } — callers can inspect the manifest to verify
|
|
53
|
+
* the pipeline that produced the buffer before consuming data.
|
|
54
|
+
*/
|
|
55
|
+
unpackWithManifest<T = unknown>(input: Buffer): {
|
|
56
|
+
manifest: PipeXManifest;
|
|
57
|
+
data: T;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
declare class StreamController {
|
|
61
|
+
#private;
|
|
62
|
+
constructor(engine: DataEngine);
|
|
63
|
+
/**
|
|
64
|
+
* Returns a Writable that pumps incoming bytes through the plugin pipeline
|
|
65
|
+
* (compress direction) and forwards them to `destination`.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* await pipeline(readableSource, engine.stream.into(createWriteStream('out')));
|
|
69
|
+
*/
|
|
70
|
+
into(destination: Writable, options?: OperationOptions): Writable;
|
|
71
|
+
/**
|
|
72
|
+
* Returns a Writable that pumps bytes through the reversed plugin pipeline
|
|
73
|
+
* (decompress direction) and forwards to `destination`.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* await pipeline(readableSource, engine.stream.reverseInto(createWriteStream('restored')));
|
|
77
|
+
*/
|
|
78
|
+
reverseInto(destination: Writable, options?: OperationOptions): Writable;
|
|
79
|
+
/**
|
|
80
|
+
* Returns a PackrStream: write JS objects, read msgpack bytes.
|
|
81
|
+
* A manifest header frame is prepended automatically.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* await pipeline(objectSource, engine.stream.pack(), tcpSocket);
|
|
85
|
+
*/
|
|
86
|
+
pack(options?: OperationOptions): Duplex;
|
|
87
|
+
/**
|
|
88
|
+
* Returns a GuardedUnpackrStream: write msgpack bytes, read JS objects.
|
|
89
|
+
* Fires the engine's 'manifest' event when the header frame is detected.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* await pipeline(tcpSocket, engine.stream.unpack(), objectDestination);
|
|
93
|
+
*/
|
|
94
|
+
unpack(options?: OperationOptions): Duplex;
|
|
95
|
+
/**
|
|
96
|
+
* Orchestrate a complete pipeline: Readable → plugin chain → Writable.
|
|
97
|
+
* This is the primary low-level entry point — file/binary controllers
|
|
98
|
+
* build on top of this.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* await engine.stream.pipe(
|
|
102
|
+
* createReadStream('input.bin'),
|
|
103
|
+
* createWriteStream('output.bin'),
|
|
104
|
+
* );
|
|
105
|
+
*/
|
|
106
|
+
pipe(source: Readable, destination: Writable, reverse?: boolean, options?: OperationOptions): Promise<void>;
|
|
107
|
+
}
|
|
108
|
+
interface PipeXEventMap {
|
|
109
|
+
start: [requestId: string];
|
|
110
|
+
'plugin:after': [name: string, durationMs: number];
|
|
111
|
+
progress: [bytes: number, requestId: string];
|
|
112
|
+
error: [err: Error, requestId: string];
|
|
113
|
+
end: [requestId: string, durationMs?: number];
|
|
114
|
+
manifest: [manifest: unknown, requestId?: string];
|
|
115
|
+
}
|
|
116
|
+
type PluginConstructor<TOptions = unknown> = new (options: TOptions) => ProcessorPlugin;
|
|
117
|
+
declare class DataEngine extends EventEmitter {
|
|
118
|
+
#private;
|
|
119
|
+
/** Built-in plugin registry for config-driven bootstrap. */
|
|
120
|
+
private static readonly pluginRegistry;
|
|
121
|
+
/** Register a plugin class for use in fromConfig(). */
|
|
122
|
+
static registerPlugin<TOptions>(name: string, pluginClass: PluginConstructor<TOptions>): void;
|
|
123
|
+
/**
|
|
124
|
+
* Bootstrap a DataEngine from a configuration object.
|
|
125
|
+
*/
|
|
126
|
+
static fromConfig(config: EngineConfig): Promise<DataEngine>;
|
|
127
|
+
readonly file: FileController;
|
|
128
|
+
readonly binary: BinaryController;
|
|
129
|
+
readonly stream: StreamController;
|
|
130
|
+
constructor(limits?: Partial<EngineLimits>);
|
|
131
|
+
get limits(): Readonly<EngineLimits>;
|
|
132
|
+
setLimits(limits: Partial<EngineLimits>): this;
|
|
133
|
+
createOperationSignal(options?: OperationOptions): AbortSignal;
|
|
134
|
+
/**
|
|
135
|
+
* Set the optional, caller-owned failure sink (legacy DLQ terminology).
|
|
136
|
+
* A failed fallback-transform chunk is written after retries are exhausted;
|
|
137
|
+
* the operation still rejects. PipeX does not persist, replay, end, or own
|
|
138
|
+
* the supplied Writable.
|
|
139
|
+
*
|
|
140
|
+
* @param stream The caller-provided Writable used as a failure sink.
|
|
141
|
+
*/
|
|
142
|
+
setDlq(stream: Writable): this;
|
|
143
|
+
/** The current caller-provided failure sink, if any. */
|
|
144
|
+
get dlq(): Writable | undefined;
|
|
145
|
+
/**
|
|
146
|
+
* Set the engine's logger for structured observability.
|
|
147
|
+
* Compatible with Pino, Winston, or any logger implementing the Logger interface.
|
|
148
|
+
*
|
|
149
|
+
* @param logger The logger instance.
|
|
150
|
+
*/
|
|
151
|
+
setLogger(logger: Logger): this;
|
|
152
|
+
/** The current logger instance. */
|
|
153
|
+
get logger(): Logger | undefined;
|
|
154
|
+
/**
|
|
155
|
+
* Set the engine's tracer for OpenTelemetry-compatible tracing.
|
|
156
|
+
*
|
|
157
|
+
* @param tracer The tracer instance.
|
|
158
|
+
*/
|
|
159
|
+
setTracer(tracer: Tracer): this;
|
|
160
|
+
/** The current tracer instance. */
|
|
161
|
+
get tracer(): Tracer | undefined;
|
|
162
|
+
/**
|
|
163
|
+
* Set the engine's audit logger for compliance and security auditing.
|
|
164
|
+
*
|
|
165
|
+
* @param logger The audit logger instance.
|
|
166
|
+
*/
|
|
167
|
+
setAuditLogger(logger: AuditLogger): this;
|
|
168
|
+
/**
|
|
169
|
+
* Emits an audit record if an audit logger is configured.
|
|
170
|
+
* This is called automatically by controllers.
|
|
171
|
+
*
|
|
172
|
+
* @param record The audit record metadata.
|
|
173
|
+
*/
|
|
174
|
+
emitAudit(record: Omit<AuditRecord, 'pluginChain' | 'timestamp'>): Promise<void>;
|
|
175
|
+
/**
|
|
176
|
+
* Set a Schema Registry to fetch schemas dynamically.
|
|
177
|
+
*
|
|
178
|
+
* @param registry The schema registry provider.
|
|
179
|
+
*/
|
|
180
|
+
setSchemaRegistry(registry: SchemaRegistry): this;
|
|
181
|
+
/**
|
|
182
|
+
* Fetch a schema from the registry and set it as the engine's active schema.
|
|
183
|
+
*
|
|
184
|
+
* @param subject The name of the schema to fetch.
|
|
185
|
+
* @param version Optional version of the schema.
|
|
186
|
+
*/
|
|
187
|
+
loadSchema(subject: string, version?: number): Promise<void>;
|
|
188
|
+
/**
|
|
189
|
+
* Set a global Zod schema for input/output validation.
|
|
190
|
+
* When set, controllers will automatically validate data against this schema.
|
|
191
|
+
*/
|
|
192
|
+
setSchema(schema: z.ZodType<any>): this;
|
|
193
|
+
get schema(): z.ZodType<any> | undefined;
|
|
194
|
+
/** Validates data against the registered schema (if any). Throws on failure. */
|
|
195
|
+
validate(data: unknown): void;
|
|
196
|
+
/** Register a plugin and return this for fluent chaining. */
|
|
197
|
+
use(plugin: ProcessorPlugin): this;
|
|
198
|
+
/**
|
|
199
|
+
* Read-only view of the registered plugins.
|
|
200
|
+
* Exposed so controllers can iterate without mutating the list.
|
|
201
|
+
*/
|
|
202
|
+
get plugins(): readonly ProcessorPlugin[];
|
|
203
|
+
/** Human-readable plugin identifiers in execution order. */
|
|
204
|
+
get pipeline(): readonly string[];
|
|
205
|
+
/** Runtime-validated capabilities in pipeline order. */
|
|
206
|
+
get pluginCapabilities(): readonly Readonly<RegisteredPluginCapabilities>[];
|
|
207
|
+
/** Generates a requestId, emits 'start', returns the id. */
|
|
208
|
+
startRequest(metadata?: Record<string, unknown>): string;
|
|
209
|
+
/** Keep capacity reserved for accepted non-cooperative work after caller cancellation. */
|
|
210
|
+
trackWork(requestId: string, pending: Promise<unknown>): void;
|
|
211
|
+
/** Idempotent cleanup, including error paths that fail before transformation starts. */
|
|
212
|
+
releaseRequest(requestId: string): void;
|
|
213
|
+
/** Emits 'end' with optional duration. */
|
|
214
|
+
endRequest(requestId: string, durationMs?: number): void;
|
|
215
|
+
/** Emits 'progress'. */
|
|
216
|
+
emitProgress(bytes: number, requestId: string): void;
|
|
217
|
+
/** Normalises unknown throws → Error and emits 'error'. */
|
|
218
|
+
emitError(err: unknown, requestId: string): void;
|
|
219
|
+
emit<K extends keyof PipeXEventMap>(event: K, ...args: PipeXEventMap[K]): boolean;
|
|
220
|
+
on<K extends keyof PipeXEventMap>(event: K, listener: (...args: PipeXEventMap[K]) => void): this;
|
|
221
|
+
once<K extends keyof PipeXEventMap>(event: K, listener: (...args: PipeXEventMap[K]) => void): this;
|
|
222
|
+
}
|
|
223
|
+
export { PluginConstructor as n, DataEngine as t };
|