@snyxex/pipex 1.0.3 → 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.
Files changed (87) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/{compression-CtrHxa9G.d.mts → compression-B0xKUa-N.d.mts} +2 -5
  3. package/dist/{compression-DnVFu8TM.d.cts → compression-C1nLQVur.d.cts} +2 -5
  4. package/dist/compression-ChJlMVwP.mjs +1 -0
  5. package/dist/compression-ZHOsKTJC.cjs +1 -0
  6. package/dist/compression.cjs +1 -1
  7. package/dist/compression.d.cts +1 -1
  8. package/dist/compression.d.mts +1 -1
  9. package/dist/compression.mjs +1 -1
  10. package/dist/core-DNchiRD5.mjs +2 -0
  11. package/dist/core-DSIwvTqu.cjs +2 -0
  12. package/dist/dataEngine-6R3J-WtS.cjs +1 -0
  13. package/dist/{dataEngine-D-fIXgE7.d.cts → dataEngine-C-xYat2f.d.cts} +2 -11
  14. package/dist/{dataEngine-DUEmWp7a.d.mts → dataEngine-Zap1RwAJ.d.mts} +2 -11
  15. package/dist/dataEngine-raQdutX5.mjs +1 -0
  16. package/dist/{encryption-BmmNECIc.d.cts → encryption-CCPoyX4q.d.cts} +2 -7
  17. package/dist/{encryption-CqxtoqAD.mjs → encryption-CHvy--rb.mjs} +1 -1
  18. package/dist/{encryption-CnSL1BEY.d.mts → encryption-D4eC9ubl.d.mts} +2 -7
  19. package/dist/encryption-DwdO7Y4J.cjs +1 -0
  20. package/dist/encryption.cjs +1 -1
  21. package/dist/encryption.d.cts +1 -1
  22. package/dist/encryption.d.mts +1 -1
  23. package/dist/encryption.mjs +1 -1
  24. package/dist/{hashing-B6xGcbQR.d.mts → hashing-C6TkcsUE.d.cts} +2 -5
  25. package/dist/{hashing-LY-8x66g.d.cts → hashing-CEwtXh2V.d.mts} +2 -5
  26. package/dist/hashing-DF_guuZf.cjs +1 -0
  27. package/dist/hashing-DU3rmGMP.mjs +1 -0
  28. package/dist/hashing.cjs +1 -1
  29. package/dist/hashing.d.cts +1 -1
  30. package/dist/hashing.d.mts +1 -1
  31. package/dist/hashing.mjs +1 -1
  32. package/dist/index.cjs +1 -1
  33. package/dist/index.d.cts +77 -94
  34. package/dist/index.d.mts +77 -94
  35. package/dist/index.mjs +1 -1
  36. package/dist/kms.cjs +1 -1
  37. package/dist/kms.d.cts +2 -2
  38. package/dist/kms.d.mts +2 -2
  39. package/dist/kms.mjs +1 -1
  40. package/dist/kms_encryption-1G54Lcuo.mjs +1 -0
  41. package/dist/kms_encryption-B07lunjB.cjs +1 -0
  42. package/dist/{kms_encryption-Da-KqjKI.d.mts → kms_encryption-BBIHGi_O.d.cts} +2 -5
  43. package/dist/{kms_encryption-Dh1LEHhk.d.cts → kms_encryption-BbtS7rXa.d.mts} +2 -5
  44. package/dist/native.cjs +1 -1
  45. package/dist/native.d.cts +1 -1
  46. package/dist/native.d.mts +1 -1
  47. package/dist/native.mjs +1 -1
  48. package/dist/parallel.cjs +1 -1
  49. package/dist/parallel.d.cts +1 -1
  50. package/dist/parallel.d.mts +1 -1
  51. package/dist/parallel.mjs +1 -1
  52. package/dist/{plugin-C9Kd9coY.d.cts → plugin-D85NMNiy.d.mts} +1 -4
  53. package/dist/{plugin-CE94-p8P.d.mts → plugin-c_iSNY86.d.cts} +1 -4
  54. package/dist/resourceLimits-CpDWwraK.mjs +1 -0
  55. package/dist/resourceLimits-lJrEhDE5.cjs +1 -0
  56. package/dist/{types-ia4x-Dvp.d.cts → types-B50Urzn2.d.cts} +0 -3
  57. package/dist/{types-Bytga6zd.d.mts → types-B50Urzn2.d.mts} +0 -3
  58. package/dist/validation-BgdV4KdW.cjs +1 -0
  59. package/dist/validation-BkJxOs7q.mjs +1 -0
  60. package/dist/{validation-CqmhNHdW.d.cts → validation-hcvcixaS.d.cts} +3 -6
  61. package/dist/{validation-D17IkoHy.d.mts → validation-xIBvnsSH.d.mts} +3 -6
  62. package/dist/validation.cjs +1 -1
  63. package/dist/validation.d.cts +1 -1
  64. package/dist/validation.d.mts +1 -1
  65. package/dist/validation.mjs +1 -1
  66. package/dist/worker-1Q2hRcRB.cjs +1 -0
  67. package/dist/{worker-CbuCpSNc.d.cts → worker-DT7RYWwo.d.cts} +2 -5
  68. package/dist/{worker-CgCC-BWG.d.mts → worker-iSO3KhfN.d.mts} +2 -5
  69. package/dist/worker-ul8lQ0SH.mjs +1 -0
  70. package/package.json +9 -9
  71. package/dist/compression-2mm0MhWY.mjs +0 -1
  72. package/dist/compression-DrgzribA.cjs +0 -1
  73. package/dist/core-BOdvxKBq.mjs +0 -2
  74. package/dist/core-B_z1gN5W.cjs +0 -2
  75. package/dist/dataEngine-4m6GTOLe.mjs +0 -1
  76. package/dist/dataEngine-Bvl6amzP.cjs +0 -1
  77. package/dist/encryption-DdP1zFYl.cjs +0 -1
  78. package/dist/hashing-ChrADfcH.mjs +0 -1
  79. package/dist/hashing-JtOHPybU.cjs +0 -1
  80. package/dist/kms_encryption-R9auKGW4.mjs +0 -1
  81. package/dist/kms_encryption-xyWi65rZ.cjs +0 -1
  82. package/dist/resourceLimits-C1HHDwXQ.mjs +0 -1
  83. package/dist/resourceLimits-CI0Qrqdf.cjs +0 -1
  84. package/dist/validation-P5WRSAUK.mjs +0 -1
  85. package/dist/validation-pEeJmCad.cjs +0 -1
  86. package/dist/worker-I_kqxWeK.cjs +0 -1
  87. package/dist/worker-c0_VZ9c7.mjs +0 -1
@@ -1,7 +1,5 @@
1
1
  import { Duplex, Writable } from "node:stream";
2
2
  import { z } from "zod";
3
-
4
- //#region src/core/types.d.ts
5
3
  interface Logger {
6
4
  info(message: string, context?: Record<string, unknown>): void;
7
5
  warn(message: string, context?: Record<string, unknown>): void;
@@ -151,5 +149,4 @@ interface EngineEvents {
151
149
  error: [err: Error, requestId: string];
152
150
  end: [requestId: string, durationMs: number];
153
151
  }
154
- //#endregion
155
152
  export { StreamPluginContext as C, Span as S, isManifest as T, ProcessorContext as _, EngineEvents as a, RetryOptions as b, KmsOperation as c, KmsRequestOptions as d, Logger as f, PluginOperation as g, PluginCapabilities as h, EngineConfig as i, KmsProvider as l, PipeXManifest as m, AuditRecord as n, EngineLimits as o, OperationOptions as p, BinaryUndoOptions as r, EngineResult as s, AuditLogger as t, KmsProviderCapabilities as u, ProcessorPlugin as v, Tracer as w, SchemaRegistry as x, RegisteredPluginCapabilities as y };
@@ -0,0 +1 @@
1
+ require("zod");const e=require("./resourceLimits-lJrEhDE5.cjs"),t=require("./core-DSIwvTqu.cjs");let n=require("node:stream");var r=class extends e.i{options;name=`validation`;version=`1.0.0`;constructor(e){super(e),this.options=e}async process(t,n){return this.validate(t,Math.min(e.n(n),e.r(n)),n.limits?.maxFrameBytes),t}async reverse(t,n){let r=Math.min(e.n(n),e.r(n));if(t.length>r)throw new e.w({transformName:`validation`});return this.options.validateOnReverse&&this.validate(t,r,n.limits?.maxFrameBytes),t}validate(n,r,i=e.t.maxFrameBytes){if(n.length>r)throw new e.w({transformName:`validation`});t.V(n,i,1);let a;try{a=t.s.unpack(n)}catch{throw new e.w({transformName:`validation`})}if(!this.options.schema.safeParse(a).success)throw new e.w({transformName:`validation`})}createStream(t=`compress`,r){let i=[],a=0,o=Math.min(e.n(r),e.r(r));return new n.Transform({transform(t,n,r){if(t.length>o-a)return r(new e.w({transformName:`validation`}));a+=t.length,i.push(t),r()},flush:e=>{try{let n=Buffer.concat(i,a);(t!==`decompress`||this.options.validateOnReverse)&&this.validate(n,o,r?.limits?.maxFrameBytes),e(null,n)}catch(t){e(t)}}})}};Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return r}});
@@ -0,0 +1 @@
1
+ import"zod";import{i as e,n as t,r as n,t as r,w as i}from"./resourceLimits-CpDWwraK.mjs";import{V as a,s as o}from"./core-DNchiRD5.mjs";import{Transform as s}from"node:stream";var c=class extends e{options;name=`validation`;version=`1.0.0`;constructor(e){super(e),this.options=e}async process(e,r){return this.validate(e,Math.min(t(r),n(r)),r.limits?.maxFrameBytes),e}async reverse(e,r){let a=Math.min(t(r),n(r));if(e.length>a)throw new i({transformName:`validation`});return this.options.validateOnReverse&&this.validate(e,a,r.limits?.maxFrameBytes),e}validate(e,t,n=r.maxFrameBytes){if(e.length>t)throw new i({transformName:`validation`});a(e,n,1);let s;try{s=o.unpack(e)}catch{throw new i({transformName:`validation`})}if(!this.options.schema.safeParse(s).success)throw new i({transformName:`validation`})}createStream(e=`compress`,r){let a=[],o=0,c=Math.min(t(r),n(r));return new s({transform(e,t,n){if(e.length>c-o)return n(new i({transformName:`validation`}));o+=e.length,a.push(e),n()},flush:t=>{try{let n=Buffer.concat(a,o);(e!==`decompress`||this.options.validateOnReverse)&&this.validate(n,c,r?.limits?.maxFrameBytes),t(null,n)}catch(e){t(e)}}})}};export{c as t};
@@ -1,9 +1,7 @@
1
- import { C as StreamPluginContext, _ as ProcessorContext } from "./types-ia4x-Dvp.cjs";
2
- import { t as BasePlugin } from "./plugin-C9Kd9coY.cjs";
3
- import { Transform } from "node:stream";
4
1
  import { z } from "zod";
5
-
6
- //#region src/core/validation.d.ts
2
+ import { t as BasePlugin } from "./plugin-c_iSNY86.cjs";
3
+ import { C as StreamPluginContext, _ as ProcessorContext } from "./types-B50Urzn2.cjs";
4
+ import { Transform } from "node:stream";
7
5
  interface ValidationOptions {
8
6
  schema: z.ZodType<any>;
9
7
  /**
@@ -28,5 +26,4 @@ declare class ValidationPlugin extends BasePlugin {
28
26
  private validate;
29
27
  createStream(mode?: 'compress' | 'decompress', context?: StreamPluginContext): Transform;
30
28
  }
31
- //#endregion
32
29
  export { ValidationPlugin as n, ValidationOptions as t };
@@ -1,9 +1,7 @@
1
- import { C as StreamPluginContext, _ as ProcessorContext } from "./types-Bytga6zd.mjs";
2
- import { t as BasePlugin } from "./plugin-CE94-p8P.mjs";
3
- import { Transform } from "node:stream";
4
1
  import { z } from "zod";
5
-
6
- //#region src/core/validation.d.ts
2
+ import { t as BasePlugin } from "./plugin-D85NMNiy.mjs";
3
+ import { C as StreamPluginContext, _ as ProcessorContext } from "./types-B50Urzn2.mjs";
4
+ import { Transform } from "node:stream";
7
5
  interface ValidationOptions {
8
6
  schema: z.ZodType<any>;
9
7
  /**
@@ -28,5 +26,4 @@ declare class ValidationPlugin extends BasePlugin {
28
26
  private validate;
29
27
  createStream(mode?: 'compress' | 'decompress', context?: StreamPluginContext): Transform;
30
28
  }
31
- //#endregion
32
29
  export { ValidationPlugin as n, ValidationOptions as t };
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./validation-pEeJmCad.cjs`);exports.ValidationPlugin=e.t;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./validation-BgdV4KdW.cjs");exports.ValidationPlugin=e.t;
@@ -1,2 +1,2 @@
1
- import { n as ValidationPlugin, t as ValidationOptions } from "./validation-CqmhNHdW.cjs";
1
+ import { n as ValidationPlugin, t as ValidationOptions } from "./validation-hcvcixaS.cjs";
2
2
  export { type ValidationOptions, ValidationPlugin };
@@ -1,2 +1,2 @@
1
- import { n as ValidationPlugin, t as ValidationOptions } from "./validation-D17IkoHy.mjs";
1
+ import { n as ValidationPlugin, t as ValidationOptions } from "./validation-xIBvnsSH.mjs";
2
2
  export { type ValidationOptions, ValidationPlugin };
@@ -1 +1 @@
1
- import{t as e}from"./validation-P5WRSAUK.mjs";export{e as ValidationPlugin};
1
+ export{t as ValidationPlugin}from"./validation-BkJxOs7q.mjs";
@@ -0,0 +1 @@
1
+ let e=require("node:url"),t=require("node:os"),n=require("node:stream"),r=require("piscina");const i=require("./resourceLimits-lJrEhDE5.cjs"),a=0x7fffffff,o=1e5,s=Math.max(1,Math.min(4,(0,t.availableParallelism)()));function c(e,t,n=!1){if(e!==void 0&&(!Number.isSafeInteger(e)||e<+!n))throw Error(`[PipeX] Worker pool ${t} must be ${n?`a non-negative`:`a positive`} integer`)}function l(e,t){let n=t??e.limits?.operationTimeoutMs??i.t.operationTimeoutMs;if(!Number.isSafeInteger(n)||n<0||n>a)throw Error(`[PipeX] Invalid worker task timeout`);if(n===0)return{signal:e.signal,cleanup(){}};let r=new AbortController,o=setTimeout(()=>{r.abort(new DOMException(`Worker task timed out`,`TimeoutError`))},n);return o.unref(),{signal:e.signal?AbortSignal.any([e.signal,r.signal]):r.signal,cleanup(){clearTimeout(o)}}}function u(e){return e.reason instanceof Error&&e.reason.name===`TimeoutError`?new i._({cause:e.reason}):new i.g({cause:e.reason})}var d=class extends i.i{name=`worker-pool`;version=`5.0.0`;#e;#t;#n;#r;#i;#a;#o;#s;#c;#l=!0;#u=0;#d;#f;#p=/* @__PURE__ */ new Set;#m;constructor(t){if(super(t),!t||!(typeof t.filename==`string`||t.filename instanceof URL))throw Error(`[PipeX] Worker pool requires a worker filename`);if(c(t.maxThreads,`maxThreads`),c(t.maxQueue,`maxQueue`),c(t.taskTimeoutMs,`taskTimeoutMs`,!0),c(t.closeTimeoutMs,`closeTimeoutMs`,!0),t.maxThreads!==void 0&&t.maxThreads>128)throw Error(`[PipeX] Worker pool maxThreads cannot exceed 128`);if(t.maxQueue!==void 0&&t.maxQueue>o)throw Error(`[PipeX] Worker pool maxQueue cannot exceed ${o}`);if(t.taskTimeoutMs!==void 0&&t.taskTimeoutMs>a)throw Error(`[PipeX] Worker pool taskTimeoutMs exceeds the supported timer range`);if(t.closeTimeoutMs!==void 0&&t.closeTimeoutMs>a)throw Error(`[PipeX] Worker pool closeTimeoutMs exceeds the supported timer range`);for(let[e,n]of[[`processName`,t.processName],[`reverseName`,t.reverseName]])if(n!==void 0&&(typeof n!=`string`||n.length===0||n.length>128))throw Error(`[PipeX] Worker pool ${e} must be a non-empty export name`);let n=t.filename instanceof URL?(0,e.fileURLToPath)(t.filename):t.filename;this.#t=t.processName,this.#n=t.reverseName,this.#r=t.taskTimeoutMs,this.#i=t.maxThreads??s,this.#a=t.maxQueue??64,this.#o=this.#i+this.#a,this.#s=t.closeTimeoutMs??3e4,this.#c=!!t.reverseName,this.#e=new r.Piscina({filename:n,minThreads:0,maxThreads:this.#i,maxQueue:this.#a,closeTimeout:this.#s}),this.#m=e=>{this.#f||(this.#f=new i.O(`worker-thread`,{cause:e}),this.#l=!1,this.#e.destroy().catch(()=>void 0))},this.#e.on(`error`,this.#m)}get reversible(){return this.#c}async#h(e,t,n){if(this.#f)throw this.#f;if(!this.#l)throw new i.E;let r=i.n(t);if(e.length>r)throw Error(`[PipeX] Worker input exceeds ${r} bytes`);if(this.#u>=this.#o)throw new i.D(this.#a);let a=l(t,this.#r);this.#u++;try{a.signal?.throwIfAborted();let r=e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength),o=await this.#e.run(r,{transferList:[r],signal:a.signal,name:n});if(!(o instanceof ArrayBuffer)&&!ArrayBuffer.isView(o))throw Error(`worker returned a non-binary value`);let s=o instanceof ArrayBuffer?Buffer.from(o):Buffer.from(o.buffer,o.byteOffset,o.byteLength),c=i.r(t);if(s.length>c)throw Error(`[PipeX] Worker output exceeds ${c} bytes`);return s}catch(e){throw a.signal?.aborted?u(a.signal):e instanceof i.E||e instanceof i.D?e:e instanceof Error&&(e.message===`Task queue is at limit`||e.message===`No task queue available and all Workers are busy`)?new i.D(this.#a):new i.O(n??`default`,{cause:e})}finally{if(a.cleanup(),this.#u--,this.#u===0){for(let e of this.#p)e();this.#p.clear()}}}process(e,t){return this.#h(e,t,this.#t)}reverse(e,t){if(!this.#n)throw new i.S(`${this.name}@${this.version}`);return this.#h(e,t,this.#n)}createStream(e,t){if(e===`decompress`&&!this.#n)throw new i.S(this.name);let r=new AbortController,a=t?.signal?AbortSignal.any([t.signal,r.signal]):r.signal,o=t?.limits??i.t,s=Math.min(o.maxFrameBytes,0xfffffffe),c=Buffer.from([80,88,87,75,1]),l=Buffer.from([255,255,255,255]),u=0,d=0,f=0,p=!1,m=!1,h=Buffer.alloc(c.length),g=0,_,v=0,y=this,b=(e,t)=>{if(t.length>o.maxOutputBytes-d)throw Error(`[PipeX] Worker stream output exceeds configured limit`);d+=t.length,e.push(t)},x=async n=>{if(++f>o.maxFrames)throw Error(`[PipeX] Worker frame count exceeds configured limit`);let r={requestId:t?.requestId??`worker-stream`,timestamp:Date.now(),signal:a,limits:o,logger:t?.logger,metadata:{}},i=e===`decompress`?y.reverse(n,r):y.process(n,r);t?.track?.(i);let c=await i;if(a.throwIfAborted(),c.length>s)throw Error(`[PipeX] Worker frame exceeds configured limit`);return c};return new n.Transform({transform(n,r,o){let l=this;(async()=>{if(a.throwIfAborted(),n.length>i.n(t)-u)throw Error(`[PipeX] Worker stream input exceeds configured limit`);if(u+=n.length,e===`compress`){p||=(b(l,c),!0);for(let e=0;e<n.length;e+=s){let t=await x(n.subarray(e,e+s)),r=Buffer.alloc(4);r.writeUInt32BE(t.length),b(l,r),b(l,t)}return}let r=0;for(;r<n.length;){if(m)throw Error(`[PipeX] Worker stream has trailing bytes`);if(!_){let e=Math.min(h.length-g,n.length-r);if(n.copy(h,g,r,r+e),g+=e,r+=e,g!==h.length)continue;if(!p){if(!h.equals(c))throw Error(`[PipeX] Invalid worker stream format`);p=!0,h=Buffer.alloc(4),g=0;continue}let t=h.readUInt32BE();if(g=0,t===0xffffffff){m=!0;continue}if(t>s)throw Error(`[PipeX] Worker frame exceeds configured limit`);_=Buffer.alloc(t),v=0}let e=Math.min(_.length-v,n.length-r);n.copy(_,v,r,r+e),v+=e,r+=e,v===_.length&&(b(l,await x(_)),_=void 0,v=0)}})().then(()=>o(),e=>o(e))},flush(t){try{if(a.throwIfAborted(),e===`compress`)p||b(this,c),b(this,l);else if(!m||_||g)throw Error(`[PipeX] Incomplete worker stream`);t()}catch(e){t(e)}},destroy(e,t){a.aborted||r.abort(e??new DOMException(`Worker stream destroyed`,`AbortError`)),_=void 0,t(e)}})}async close(e={}){if(!e||e.force!==void 0&&typeof e.force!=`boolean`)throw TypeError(`[PipeX] Worker pool close force must be a boolean`);return this.#d||=(this.#l=!1,(async()=>{try{if(this.#f)await this.#e.destroy();else if(e.force)await this.#e.destroy();else if(this.#u>0&&await new Promise((e,t)=>{let n=()=>{clearTimeout(r),e()},r=setTimeout(()=>{this.#p.delete(n),t(new i.T)},this.#s);this.#p.add(n)}),await this.#e.close({force:!1}),this.#f)throw this.#f}catch(e){throw await this.#e.destroy().catch(()=>void 0),e instanceof i.T?e:new i.T({cause:e})}finally{this.#e.removeListener(`error`,this.#m)}})()),this.#d}};Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return d}});
@@ -1,8 +1,6 @@
1
- import { C as StreamPluginContext, _ as ProcessorContext } from "./types-ia4x-Dvp.cjs";
2
- import { t as BasePlugin } from "./plugin-C9Kd9coY.cjs";
3
1
  import { Transform } from "node:stream";
4
-
5
- //#region src/plugin/worker.d.ts
2
+ import { t as BasePlugin } from "./plugin-c_iSNY86.cjs";
3
+ import { C as StreamPluginContext, _ as ProcessorContext } from "./types-B50Urzn2.cjs";
6
4
  interface WorkerPoolOptions {
7
5
  /** Absolute path or file URL to a caller-owned ESM/CJS worker module. */
8
6
  filename: string | URL;
@@ -33,5 +31,4 @@ declare class WorkerPoolPlugin extends BasePlugin {
33
31
  force?: boolean;
34
32
  }): Promise<void>;
35
33
  }
36
- //#endregion
37
34
  export { WorkerPoolPlugin as n, WorkerPoolOptions as t };
@@ -1,8 +1,6 @@
1
- import { C as StreamPluginContext, _ as ProcessorContext } from "./types-Bytga6zd.mjs";
2
- import { t as BasePlugin } from "./plugin-CE94-p8P.mjs";
3
1
  import { Transform } from "node:stream";
4
-
5
- //#region src/plugin/worker.d.ts
2
+ import { t as BasePlugin } from "./plugin-D85NMNiy.mjs";
3
+ import { C as StreamPluginContext, _ as ProcessorContext } from "./types-B50Urzn2.mjs";
6
4
  interface WorkerPoolOptions {
7
5
  /** Absolute path or file URL to a caller-owned ESM/CJS worker module. */
8
6
  filename: string | URL;
@@ -33,5 +31,4 @@ declare class WorkerPoolPlugin extends BasePlugin {
33
31
  force?: boolean;
34
32
  }): Promise<void>;
35
33
  }
36
- //#endregion
37
34
  export { WorkerPoolPlugin as n, WorkerPoolOptions as t };
@@ -0,0 +1 @@
1
+ import{fileURLToPath as e}from"node:url";import{availableParallelism as t}from"node:os";import{Transform as n}from"node:stream";import{Piscina as r}from"piscina";import{D as i,E as a,O as o,S as s,T as c,_ as l,g as u,i as d,n as f,r as p,t as m}from"./resourceLimits-CpDWwraK.mjs";const h=0x7fffffff,g=1e5,_=Math.max(1,Math.min(4,t()));function v(e,t,n=!1){if(e!==void 0&&(!Number.isSafeInteger(e)||e<+!n))throw Error(`[PipeX] Worker pool ${t} must be ${n?`a non-negative`:`a positive`} integer`)}function y(e,t){let n=t??e.limits?.operationTimeoutMs??m.operationTimeoutMs;if(!Number.isSafeInteger(n)||n<0||n>h)throw Error(`[PipeX] Invalid worker task timeout`);if(n===0)return{signal:e.signal,cleanup(){}};let r=new AbortController,i=setTimeout(()=>{r.abort(new DOMException(`Worker task timed out`,`TimeoutError`))},n);return i.unref(),{signal:e.signal?AbortSignal.any([e.signal,r.signal]):r.signal,cleanup(){clearTimeout(i)}}}function b(e){return e.reason instanceof Error&&e.reason.name===`TimeoutError`?new l({cause:e.reason}):new u({cause:e.reason})}var x=class extends d{name=`worker-pool`;version=`5.0.0`;#e;#t;#n;#r;#i;#a;#o;#s;#c;#l=!0;#u=0;#d;#f;#p=/* @__PURE__ */ new Set;#m;constructor(t){if(super(t),!t||!(typeof t.filename==`string`||t.filename instanceof URL))throw Error(`[PipeX] Worker pool requires a worker filename`);if(v(t.maxThreads,`maxThreads`),v(t.maxQueue,`maxQueue`),v(t.taskTimeoutMs,`taskTimeoutMs`,!0),v(t.closeTimeoutMs,`closeTimeoutMs`,!0),t.maxThreads!==void 0&&t.maxThreads>128)throw Error(`[PipeX] Worker pool maxThreads cannot exceed 128`);if(t.maxQueue!==void 0&&t.maxQueue>g)throw Error(`[PipeX] Worker pool maxQueue cannot exceed ${g}`);if(t.taskTimeoutMs!==void 0&&t.taskTimeoutMs>h)throw Error(`[PipeX] Worker pool taskTimeoutMs exceeds the supported timer range`);if(t.closeTimeoutMs!==void 0&&t.closeTimeoutMs>h)throw Error(`[PipeX] Worker pool closeTimeoutMs exceeds the supported timer range`);for(let[e,n]of[[`processName`,t.processName],[`reverseName`,t.reverseName]])if(n!==void 0&&(typeof n!=`string`||n.length===0||n.length>128))throw Error(`[PipeX] Worker pool ${e} must be a non-empty export name`);let n=t.filename instanceof URL?e(t.filename):t.filename;this.#t=t.processName,this.#n=t.reverseName,this.#r=t.taskTimeoutMs,this.#i=t.maxThreads??_,this.#a=t.maxQueue??64,this.#o=this.#i+this.#a,this.#s=t.closeTimeoutMs??3e4,this.#c=!!t.reverseName,this.#e=new r({filename:n,minThreads:0,maxThreads:this.#i,maxQueue:this.#a,closeTimeout:this.#s}),this.#m=e=>{this.#f||(this.#f=new o(`worker-thread`,{cause:e}),this.#l=!1,this.#e.destroy().catch(()=>void 0))},this.#e.on(`error`,this.#m)}get reversible(){return this.#c}async#h(e,t,n){if(this.#f)throw this.#f;if(!this.#l)throw new a;let r=f(t);if(e.length>r)throw Error(`[PipeX] Worker input exceeds ${r} bytes`);if(this.#u>=this.#o)throw new i(this.#a);let s=y(t,this.#r);this.#u++;try{s.signal?.throwIfAborted();let r=e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength),i=await this.#e.run(r,{transferList:[r],signal:s.signal,name:n});if(!(i instanceof ArrayBuffer)&&!ArrayBuffer.isView(i))throw Error(`worker returned a non-binary value`);let a=i instanceof ArrayBuffer?Buffer.from(i):Buffer.from(i.buffer,i.byteOffset,i.byteLength),o=p(t);if(a.length>o)throw Error(`[PipeX] Worker output exceeds ${o} bytes`);return a}catch(e){throw s.signal?.aborted?b(s.signal):e instanceof a||e instanceof i?e:e instanceof Error&&(e.message===`Task queue is at limit`||e.message===`No task queue available and all Workers are busy`)?new i(this.#a):new o(n??`default`,{cause:e})}finally{if(s.cleanup(),this.#u--,this.#u===0){for(let e of this.#p)e();this.#p.clear()}}}process(e,t){return this.#h(e,t,this.#t)}reverse(e,t){if(!this.#n)throw new s(`${this.name}@${this.version}`);return this.#h(e,t,this.#n)}createStream(e,t){if(e===`decompress`&&!this.#n)throw new s(this.name);let r=new AbortController,i=t?.signal?AbortSignal.any([t.signal,r.signal]):r.signal,a=t?.limits??m,o=Math.min(a.maxFrameBytes,0xfffffffe),c=Buffer.from([80,88,87,75,1]),l=Buffer.from([255,255,255,255]),u=0,d=0,p=0,h=!1,g=!1,_=Buffer.alloc(c.length),v=0,y,b=0,x=this,S=(e,t)=>{if(t.length>a.maxOutputBytes-d)throw Error(`[PipeX] Worker stream output exceeds configured limit`);d+=t.length,e.push(t)},C=async n=>{if(++p>a.maxFrames)throw Error(`[PipeX] Worker frame count exceeds configured limit`);let r={requestId:t?.requestId??`worker-stream`,timestamp:Date.now(),signal:i,limits:a,logger:t?.logger,metadata:{}},s=e===`decompress`?x.reverse(n,r):x.process(n,r);t?.track?.(s);let c=await s;if(i.throwIfAborted(),c.length>o)throw Error(`[PipeX] Worker frame exceeds configured limit`);return c};return new n({transform(n,r,a){let s=this;(async()=>{if(i.throwIfAborted(),n.length>f(t)-u)throw Error(`[PipeX] Worker stream input exceeds configured limit`);if(u+=n.length,e===`compress`){h||=(S(s,c),!0);for(let e=0;e<n.length;e+=o){let t=await C(n.subarray(e,e+o)),r=Buffer.alloc(4);r.writeUInt32BE(t.length),S(s,r),S(s,t)}return}let r=0;for(;r<n.length;){if(g)throw Error(`[PipeX] Worker stream has trailing bytes`);if(!y){let e=Math.min(_.length-v,n.length-r);if(n.copy(_,v,r,r+e),v+=e,r+=e,v!==_.length)continue;if(!h){if(!_.equals(c))throw Error(`[PipeX] Invalid worker stream format`);h=!0,_=Buffer.alloc(4),v=0;continue}let t=_.readUInt32BE();if(v=0,t===0xffffffff){g=!0;continue}if(t>o)throw Error(`[PipeX] Worker frame exceeds configured limit`);y=Buffer.alloc(t),b=0}let e=Math.min(y.length-b,n.length-r);n.copy(y,b,r,r+e),b+=e,r+=e,b===y.length&&(S(s,await C(y)),y=void 0,b=0)}})().then(()=>a(),e=>a(e))},flush(t){try{if(i.throwIfAborted(),e===`compress`)h||S(this,c),S(this,l);else if(!g||y||v)throw Error(`[PipeX] Incomplete worker stream`);t()}catch(e){t(e)}},destroy(e,t){i.aborted||r.abort(e??new DOMException(`Worker stream destroyed`,`AbortError`)),y=void 0,t(e)}})}async close(e={}){if(!e||e.force!==void 0&&typeof e.force!=`boolean`)throw TypeError(`[PipeX] Worker pool close force must be a boolean`);return this.#d||=(this.#l=!1,(async()=>{try{if(this.#f)await this.#e.destroy();else if(e.force)await this.#e.destroy();else if(this.#u>0&&await new Promise((e,t)=>{let n=()=>{clearTimeout(r),e()},r=setTimeout(()=>{this.#p.delete(n),t(new c)},this.#s);this.#p.add(n)}),await this.#e.close({force:!1}),this.#f)throw this.#f}catch(e){throw await this.#e.destroy().catch(()=>void 0),e instanceof c?e:new c({cause:e})}finally{this.#e.removeListener(`error`,this.#m)}})()),this.#d}};export{x as t};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snyxex/pipex",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Composable compression, authenticated encryption, and HMAC transformation pipelines for Node.js buffers, files, and streams.",
5
5
  "main": "./dist/index.cjs",
6
6
  "types": "./dist/index.d.mts",
@@ -57,19 +57,19 @@
57
57
  ],
58
58
  "author": "Snyxex",
59
59
  "license": "MIT",
60
- "packageManager": "npm@11.16.0",
60
+ "packageManager": "npm@12.2.3",
61
61
  "engines": {
62
62
  "node": ">=22"
63
63
  },
64
64
  "devDependencies": {
65
- "@types/node": "^25.6.0",
66
- "tsdown": "^0.21.10",
67
- "typescript": "^6.0.2"
65
+ "@types/node": "^26.6.11",
66
+ "tsdown": "^0.23.7",
67
+ "typescript": "^7.0.2"
68
68
  },
69
69
  "dependencies": {
70
- "koffi": "3.3.2",
71
- "msgpackr": "^1.11.9",
72
- "piscina": "^5.2.0",
70
+ "koffi": "3.3.8",
71
+ "msgpackr": "^2.1.4",
72
+ "piscina": "^5.3.2",
73
73
  "zod": "^4.6.7"
74
74
  },
75
75
  "exports": {
@@ -172,7 +172,7 @@
172
172
  "CHANGELOG.md"
173
173
  ],
174
174
  "allowScripts": {
175
- "msgpackr-extract@3.0.4": true
175
+ "msgpackr-extract@3.0.7": true
176
176
  },
177
177
  "repository": {
178
178
  "type": "git",
@@ -1 +0,0 @@
1
- import{p as e}from"./core-BOdvxKBq.mjs";import{b as t,i as n,n as r,o as i,r as a}from"./resourceLimits-C1HHDwXQ.mjs";import{Duplex as o,PassThrough as s,Readable as c,Transform as l,compose as u}from"node:stream";import{brotliCompress as d,brotliDecompress as f,constants as p,createBrotliCompress as m,createBrotliDecompress as h,createGunzip as g,createGzip as _,gunzip as v,gzip as y}from"node:zlib";import{promisify as b}from"node:util";const x={none:0,gzip:1,brotli:2},S={0:`none`,1:`gzip`,2:`brotli`},C=b(y),w=b(v),T=b(d),E=b(f);var D=class extends n{name=`compression`;version=`3.0.0`;constructor(e){if(super(e),this.options=e,!(e.type in x))throw new t({transformName:`compression`,stage:`configuration`});if(e.level!==void 0&&!Number.isInteger(e.level)||e.type===`gzip`&&e.level!==void 0&&(e.level<0||e.level>9)||e.type===`brotli`&&e.level!==void 0&&(e.level<0||e.level>11)||e.type===`none`&&e.level!==void 0)throw new i({transformName:`compression`})}async process(e,t){let n=r(t),o=a(t);if(e.length>n)throw new i({transformName:`compression`,stage:`input`});let{type:s,level:c}=this.options,l=Buffer.from([x[s]]);if(e.length>o-l.length&&s===`none`||o<=l.length&&s!==`none`)throw new i({transformName:`compression`,stage:`output`});let u;return u=s===`gzip`?await C(e,{level:c??6,maxOutputLength:o-l.length}):s===`brotli`?await T(e,{params:{[p.BROTLI_PARAM_QUALITY]:c??11},maxOutputLength:o-l.length}):e,Buffer.concat([l,u])}async reverse(e,n){let o=r(n),s=a(n);if(e.length>o)throw new i({transformName:`compression`,stage:`input`});if(e.length<1)throw new i({transformName:`compression`});let c=S[e.readUInt8(0)],l=e.subarray(1);if(c===`gzip`)return await w(l,{maxOutputLength:s});if(c===`brotli`)return await E(l,{maxOutputLength:s});if(c!==`none`)throw new t({transformName:`compression`,stage:`configuration`});if(l.length>s)throw new i({transformName:`compression`,stage:`output`});return l}createStream(n,d){let{type:f,level:v}=this.options,y=r(d),b=a(d);if(n===`compress`){let t=f===`gzip`?_({level:v??6}):f===`brotli`?m({params:{[p.BROTLI_PARAM_QUALITY]:v??11}}):new s,n=!1,r=new l({transform(e,t,r){n||(n=!0,this.push(Buffer.from([x[f]]))),r(null,e)},flush(e){n||this.push(Buffer.from([x[f]])),e()}});return u(e(y,`compression input`),t,r,e(b,`compression output`))}return o.from(async function*(e){let n=e[Symbol.asyncIterator](),r,a=0,o=0;for(;!r;){let e=await n.next();if(e.done)throw new i({transformName:`compression`});let t=Buffer.isBuffer(e.value)?e.value:Buffer.from(e.value);if(t.length>y-a)throw new i({transformName:`compression`,stage:`input`});a+=t.length,t.length>0&&(r=t)}let l=S[r.readUInt8(0)];if(!l)throw new t({transformName:`compression`,stage:`decompress`});let d=l===`gzip`?g():l===`brotli`?h():new s;async function*f(){let e=r.subarray(1);for(e.length>0&&(yield e);;){let e=await n.next();if(e.done)return;let t=Buffer.isBuffer(e.value)?e.value:Buffer.from(e.value);if(t.length>y-a)throw new i({transformName:`compression`,stage:`input`});a+=t.length,t.length>0&&(yield t)}}try{for await(let e of u(c.from(f()),d)){let t=Buffer.isBuffer(e)?e:Buffer.from(e);if(t.length>b-o)throw new i({transformName:`compression`,stage:`output`});o+=t.length,yield t}}finally{d.destroy();try{await n.return?.()}catch{}}})}};export{D as t};
@@ -1 +0,0 @@
1
- const e=require(`./core-B_z1gN5W.cjs`),t=require(`./resourceLimits-CI0Qrqdf.cjs`);let n=require(`node:stream`),r=require(`node:zlib`),i=require(`node:util`);const a={none:0,gzip:1,brotli:2},o={0:`none`,1:`gzip`,2:`brotli`},s=(0,i.promisify)(r.gzip),c=(0,i.promisify)(r.gunzip),l=(0,i.promisify)(r.brotliCompress),u=(0,i.promisify)(r.brotliDecompress);var d=class extends t.i{name=`compression`;version=`3.0.0`;constructor(e){if(super(e),this.options=e,!(e.type in a))throw new t.b({transformName:`compression`,stage:`configuration`});if(e.level!==void 0&&!Number.isInteger(e.level)||e.type===`gzip`&&e.level!==void 0&&(e.level<0||e.level>9)||e.type===`brotli`&&e.level!==void 0&&(e.level<0||e.level>11)||e.type===`none`&&e.level!==void 0)throw new t.o({transformName:`compression`})}async process(e,n){let i=t.n(n),o=t.r(n);if(e.length>i)throw new t.o({transformName:`compression`,stage:`input`});let{type:c,level:u}=this.options,d=Buffer.from([a[c]]);if(e.length>o-d.length&&c===`none`||o<=d.length&&c!==`none`)throw new t.o({transformName:`compression`,stage:`output`});let f;return f=c===`gzip`?await s(e,{level:u??6,maxOutputLength:o-d.length}):c===`brotli`?await l(e,{params:{[r.constants.BROTLI_PARAM_QUALITY]:u??11},maxOutputLength:o-d.length}):e,Buffer.concat([d,f])}async reverse(e,n){let r=t.n(n),i=t.r(n);if(e.length>r)throw new t.o({transformName:`compression`,stage:`input`});if(e.length<1)throw new t.o({transformName:`compression`});let a=o[e.readUInt8(0)],s=e.subarray(1);if(a===`gzip`)return await c(s,{maxOutputLength:i});if(a===`brotli`)return await u(s,{maxOutputLength:i});if(a!==`none`)throw new t.b({transformName:`compression`,stage:`configuration`});if(s.length>i)throw new t.o({transformName:`compression`,stage:`output`});return s}createStream(i,s){let{type:c,level:l}=this.options,u=t.n(s),d=t.r(s);if(i===`compress`){let t=c===`gzip`?(0,r.createGzip)({level:l??6}):c===`brotli`?(0,r.createBrotliCompress)({params:{[r.constants.BROTLI_PARAM_QUALITY]:l??11}}):new n.PassThrough,i=!1,o=new n.Transform({transform(e,t,n){i||(i=!0,this.push(Buffer.from([a[c]]))),n(null,e)},flush(e){i||this.push(Buffer.from([a[c]])),e()}});return(0,n.compose)(e.p(u,`compression input`),t,o,e.p(d,`compression output`))}return n.Duplex.from(async function*(e){let i=e[Symbol.asyncIterator](),a,s=0,c=0;for(;!a;){let e=await i.next();if(e.done)throw new t.o({transformName:`compression`});let n=Buffer.isBuffer(e.value)?e.value:Buffer.from(e.value);if(n.length>u-s)throw new t.o({transformName:`compression`,stage:`input`});s+=n.length,n.length>0&&(a=n)}let l=o[a.readUInt8(0)];if(!l)throw new t.b({transformName:`compression`,stage:`decompress`});let f=l===`gzip`?(0,r.createGunzip)():l===`brotli`?(0,r.createBrotliDecompress)():new n.PassThrough;async function*p(){let e=a.subarray(1);for(e.length>0&&(yield e);;){let e=await i.next();if(e.done)return;let n=Buffer.isBuffer(e.value)?e.value:Buffer.from(e.value);if(n.length>u-s)throw new t.o({transformName:`compression`,stage:`input`});s+=n.length,n.length>0&&(yield n)}}try{for await(let e of(0,n.compose)(n.Readable.from(p()),f)){let n=Buffer.isBuffer(e)?e:Buffer.from(e);if(n.length>d-c)throw new t.o({transformName:`compression`,stage:`output`});c+=n.length,yield n}}finally{f.destroy();try{await i.return?.()}catch{}}})}};Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return d}});
@@ -1,2 +0,0 @@
1
- import{C as e,S as t,_ as n,d as r,g as i,i as a,t as o}from"./resourceLimits-C1HHDwXQ.mjs";import{randomUUID as s}from"node:crypto";import{pipeline as c}from"node:stream/promises";import{Transform as l}from"node:stream";import{Packr as u,PackrStream as d,Unpackr as f,UnpackrStream as p}from"msgpackr";import"zod";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();return}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 n=new v(e,t),r=[],i=0;return new l({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 b=new WeakMap;function x(e,t){t>0&&b.set(e,Date.now()+t)}function S(e){return e.reason instanceof n||e.reason instanceof i?e.reason:e.reason instanceof Error&&e.reason.name===`TimeoutError`?new n:new i}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 n}async function w(e,t,r){let i=Promise.resolve(e);return r?.(i),t?new Promise((e,r)=>{let a=!1,o,s=()=>{t.removeEventListener(`abort`,l),o&&clearTimeout(o)},c=e=>{a||(a=!0,s(),r(e))},l=()=>c(S(t));t.addEventListener(`abort`,l,{once:!0});let u=b.get(t);u!==void 0&&(o=setTimeout(()=>c(new n),Math.max(0,u-Date.now()))),i.then(n=>{if(!a){try{C(t)}catch(e){c(e);return}a=!0,s(),e(n)}},c);try{C(t)}catch(e){c(e)}}):i}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??Error(`[PipeX] Operation aborted`))};r?.signal?.addEventListener(`abort`,o,{once:!0}),r?.signal?.aborted&&o()})}}}throw l}const k=`__pipex_v`,A=new u({useRecords:!1,moreTypes:!0,structuredClone:!1,bundleStrings:!1}),j=new f({useRecords:!1,structuredClone:!1}),te=256*1024*1024,M=64*1024;function N(e){return typeof e.createStream==`function`}function P(e){let t=`${e.name}@${e.version}`,n=e.reversible,i=e.streaming,o=e.reverse,s=e.createStream,c=typeof o==`function`&&o!==a.prototype.reverse;if(n!==void 0&&typeof n!=`boolean`)throw new r(t,`reversible`,`MUST_BE_BOOLEAN`);if(i!==void 0&&typeof i!=`boolean`)throw new r(t,`streaming`,`MUST_BE_BOOLEAN`);if(n===!0&&!c)throw new r(t,`reversible`,`MISSING_IMPLEMENTATION`);if(i===!1&&typeof s==`function`)throw new r(t,`streaming`,`CONFLICTING_IMPLEMENTATION`);let l=n!==!1&&c,u=i!==!1;return Object.freeze({process:!0,reverse:l,streaming:u,streamMode:u?typeof s==`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 n=e.find(e=>!I(e));if(n)throw new t(`${n.name}@${n.version}`)}function R(t){let n=t.find(e=>!F(e,`stream`));if(n)throw new e(`${n.name}@${n.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=o.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,n=Buffer.from(A.pack(e));return new l({transform(e,r,i){t||(t=!0,this.push(n)),i(null,e)},flush(e){t||this.push(n),e()}})}function K(e){let t=!1;return new l({writableObjectMode:!0,readableObjectMode:!0,transform(n,r,i){if(!t&&(t=!0,_(n))){try{e(n),i()}catch(e){i(e)}return}i(null,n)}})}var q=class extends p{#e=0;#t;constructor(e={},t=o.maxInputBytes){super(e),this.#t=t}_transform(e,t,n){if(e.length>this.#t-this.#e){n(Error(`[PipeX] Serialized input exceeds ${this.#t} bytes`));return}this.#e+=e.length,super._transform(e,t,e=>{n(e?Error(`[PipeX] Invalid MessagePack input`):void 0)})}};function J(){return new d({useRecords:!1,moreTypes:!0,structuredClone:!1,bundleStrings:!1})}function Y(e=o.maxInputBytes){return new q({useRecords:!1,structuredClone:!1},e)}function X(e,t){let n=0;return new l({transform(r,i,a){if(r.length>e-n){a(Error(`[PipeX] ${t} exceeds ${e} bytes`));return}n+=r.length,a(null,r)}})}function re(e){let t=0;return new l({writableObjectMode:!0,readableObjectMode:!0,transform(n,r,i){if(t>=e){i(Error(`[PipeX] Application frame count exceeds ${e}`));return}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 l({writableObjectMode:!0,readableObjectMode:!0,transform(n,r,i){try{Z(n,e,t),i(null,n)}catch(e){i(e)}}})}function Q(e,n,r,i,a,c,u){i=E(i),a=D(a);let d=u?.requestId??`stream-${s()}`;return new l({async transform(s,l,f){let p=a?.startSpan(`plugin:${e.name}`,{requestId:d});p?.setAttribute(`plugin.version`,e.version),p?.setAttribute(`mode`,n?`reverse`:`process`);try{u?.signal.throwIfAborted();let a=U(d,{},i,p,u?.signal,u?.limits);if(n&&!I(e))throw new t(`${e.name}@${e.version}`);let c=n?e.reverse.bind(e):e.process.bind(e),l=await O(()=>c(s,a),e.retryOptions,i,{signal:u?.signal,limits:u?.limits,track:u?.track}),m=u?.limits.maxOutputBytes??o.maxOutputBytes;if(!Buffer.isBuffer(l)||l.length>m)throw Error(`[PipeX] Plugin output exceeds ${m} bytes`);r?.(l.length),p?.addEvent(`processed`,{bytes:l.length}),f(null,l)}catch(t){let n=t instanceof Error?t:Error(String(t));if(i?.error(`[PipeX] Plugin ${e.name} failed after retries`,{requestId:d,error:n.message}),p?.setAttribute(`error`,!0),p?.addEvent(`error`,{message:n.message}),c&&c.writable){i?.warn(`[PipeX] Diverting failed chunk to DLQ`,{requestId:d,plugin:e.name});try{c.write(s)||await new Promise((e,t)=>{let n=()=>{o(),e()},r=e=>{o(),t(e)},i=()=>{o(),t(u?.signal.reason instanceof Error?u.signal.reason:Error(`[PipeX] Operation aborted`))},a=()=>{o(),t(Error(`[PipeX] Stream closed while writing to DLQ`))},o=()=>{c.off(`drain`,n),c.off(`error`,r),u?.signal.removeEventListener(`abort`,i),this.off(`close`,a)};c.once(`drain`,n),c.once(`error`,r),this.once(`close`,a),u?.signal.aborted?i():u?.signal.addEventListener(`abort`,i,{once:!0})}),f(n)}catch(e){f(e)}}else f(n)}finally{p?.end()}}})}function ae(){return new l({writableObjectMode:!0,readableObjectMode:!1,transform(e,t,n){try{n(null,JSON.stringify(e)+`
2
- `)}catch(e){n(Error(`[PipeX] NDJSON: ${e.message}`))}}})}function oe(e,t,n=!1,r,i,a,s,c){return i=E(i),a=D(a),R(e),n&&L(e),(n?[...e].reverse():e).flatMap((e,u)=>{let d=N(e)?e.createStream(t,c):Q(e,n,r,i,a,s,c),f=X(c?.limits.maxOutputBytes??o.maxOutputBytes,`output after plugin ${e.name}#${u}`);if(!N(e))return[d,f];let p=a?.startSpan(`plugin:${e.name}`,{requestId:c?.requestId??`stream`}),m=!1,h=e=>{m||(m=!0,e&&p?.setAttribute(`error`,!0),p?.end())};return[d,new l({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)}}),f]})}async function se(e,t,n,r){await c(e,...t,n,r??{})}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};
@@ -1,2 +0,0 @@
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(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));const c=require(`./resourceLimits-CI0Qrqdf.cjs`);let l=require(`node:crypto`),u=require(`node:stream/promises`),d=require(`node:stream`),f=require(`msgpackr`);require(`zod`);let p=require(`node:path`);p=s(p,1);let m=require(`node:fs`);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();return}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 d.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=new WeakMap;function b(e,t){t>0&&y.set(e,Date.now()+t)}function x(e){return e.reason instanceof c._||e.reason instanceof c.g?e.reason:e.reason instanceof Error&&e.reason.name===`TimeoutError`?new c._:new c.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 c._}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`,l),a&&clearTimeout(a)},s=e=>{i||(i=!0,o(),n(e))},l=()=>s(x(t));t.addEventListener(`abort`,l,{once:!0});let u=y.get(t);u!==void 0&&(a=setTimeout(()=>s(new c._),Math.max(0,u-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??Error(`[PipeX] Operation aborted`))};r?.signal?.addEventListener(`abort`,o,{once:!0}),r?.signal?.aborted&&o()})}}}throw l}const O=new f.Packr({useRecords:!1,moreTypes:!0,structuredClone:!1,bundleStrings:!1}),k=new f.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!==c.i.prototype.reverse;if(n!==void 0&&typeof n!=`boolean`)throw new c.d(t,`reversible`,`MUST_BE_BOOLEAN`);if(r!==void 0&&typeof r!=`boolean`)throw new c.d(t,`streaming`,`MUST_BE_BOOLEAN`);if(n===!0&&!o)throw new c.d(t,`reversible`,`MISSING_IMPLEMENTATION`);if(r===!1&&typeof a==`function`)throw new c.d(t,`streaming`,`CONFLICTING_IMPLEMENTATION`);let s=n!==!1&&o,l=r!==!1;return Object.freeze({process:!0,reverse:s,streaming:l,streamMode:l?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 c.S(`${t.name}@${t.version}`)}function F(e){let t=e.find(e=>!M(e,`stream`));if(t)throw new c.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=c.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 d.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 d.Transform({writableObjectMode:!0,readableObjectMode:!0,transform(n,r,i){if(!t&&(t=!0,h(n))){try{e(n),i()}catch(e){i(e)}return}i(null,n)}})}var W=class extends f.UnpackrStream{#e=0;#t;constructor(e={},t=c.t.maxInputBytes){super(e),this.#t=t}_transform(e,t,n){if(e.length>this.#t-this.#e){n(Error(`[PipeX] Serialized input exceeds ${this.#t} bytes`));return}this.#e+=e.length,super._transform(e,t,e=>{n(e?Error(`[PipeX] Invalid MessagePack input`):void 0)})}};function G(){return new f.PackrStream({useRecords:!1,moreTypes:!0,structuredClone:!1,bundleStrings:!1})}function K(e=c.t.maxInputBytes){return new W({useRecords:!1,structuredClone:!1},e)}function q(e,t){let n=0;return new d.Transform({transform(r,i,a){if(r.length>e-n){a(Error(`[PipeX] ${t} exceeds ${e} bytes`));return}n+=r.length,a(null,r)}})}function J(e){let t=0;return new d.Transform({writableObjectMode:!0,readableObjectMode:!0,transform(n,r,i){if(t>=e){i(Error(`[PipeX] Application frame count exceeds ${e}`));return}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 d.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,l.randomUUID)()}`;return new d.Transform({async transform(l,u,d){let f=i?.startSpan(`plugin:${e.name}`,{requestId:s});f?.setAttribute(`plugin.version`,e.version),f?.setAttribute(`mode`,t?`reverse`:`process`);try{o?.signal.throwIfAborted();let i=V(s,{},r,f,o?.signal,o?.limits);if(t&&!N(e))throw new c.S(`${e.name}@${e.version}`);let a=t?e.reverse.bind(e):e.process.bind(e),u=await D(()=>a(l,i),e.retryOptions,r,{signal:o?.signal,limits:o?.limits,track:o?.track}),p=o?.limits.maxOutputBytes??c.t.maxOutputBytes;if(!Buffer.isBuffer(u)||u.length>p)throw Error(`[PipeX] Plugin output exceeds ${p} bytes`);n?.(u.length),f?.addEvent(`processed`,{bytes:u.length}),d(null,u)}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}),f?.setAttribute(`error`,!0),f?.addEvent(`error`,{message:n.message}),a&&a.writable){r?.warn(`[PipeX] Diverting failed chunk to DLQ`,{requestId:s,plugin:e.name});try{a.write(l)||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:Error(`[PipeX] Operation aborted`))},s=()=>{c(),t(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})}),d(n)}catch(e){d(e)}}else d(n)}finally{f?.end()}}})}function Q(){return new d.Transform({writableObjectMode:!0,readableObjectMode:!1,transform(e,t,n){try{n(null,JSON.stringify(e)+`
2
- `)}catch(e){n(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,l)=>{let u=A(e)?e.createStream(t,s):Z(e,n,r,i,a,o,s),f=q(s?.limits.maxOutputBytes??c.t.maxOutputBytes,`output after plugin ${e.name}#${l}`);if(!A(e))return[u,f];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[u,new d.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)}}),f]})}async function ne(e,t,n,r){await(0,u.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}});
@@ -1 +0,0 @@
1
- import{A as e,B as t,C as n,E as r,F as i,H as a,I as o,L as s,N as c,O as l,P as u,R as d,S as f,T as p,U as m,V as h,_ as g,a as _,b as v,c as y,d as b,g as x,h as S,k as C,l as w,p as T,s as E,t as D,u as O,v as k,w as A,x as j,y as ee,z as M}from"./core-BOdvxKBq.mjs";import{t as N,w as P}from"./resourceLimits-C1HHDwXQ.mjs";import{createRequire as te}from"node:module";import{randomUUID as F}from"node:crypto";import{Duplex as I,PassThrough as L,Readable as R,Transform as z,Writable as B}from"node:stream";import"zod";import V from"node:path";import{closeSync as H,constants as U,fstatSync as W,openSync as G,realpathSync as K}from"node:fs";import{EventEmitter as q}from"node:events";let J;const Y=()=>J??=te(import.meta.url)(`koffi`),X=e=>{throw Error(`[PipeX] Secure file `+e+` failed`)},Z=e=>{let t=V.parse(e).root;return e.slice(t.length).split(V.sep).filter(Boolean)};function ne(e,t,n){let r=K.native(V.resolve(n??process.cwd())),i=y(e,r),a=C(t,r);if(i===a)throw Error(`[PipeX] Input and output must be different files`);return process.platform===`win32`?ae(i,a,r):Q(i,a)}let re;function ie(){let e=Y(),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 ae(e,t,n){let r=re??=ie(),i=[],a=new Map,o=new Set,s=!1,c=!1,l,u,d=e=>{let t=Buffer.alloc(52);return r.info(e,t)||X(`handle inspection`),t},f=(e,t,n,a,o)=>{let s=r.open(e,t,n,null,a,2097152|(o?33554432:128),null);BigInt(s)===-1n&&X(`open`),i.push(s);let c=d(s).readUInt32LE(0);return(c&1024||!!(c&16)!==o||r.type(s)!==1)&&X(`file type validation`),s},p=(e,t,n,a,o,s=!1)=>{(!t||t===`.`||t===`..`||/[\\/:]/.test(t))&&X(`relative name validation`);let c=[0],l=r.relativeOpen(c,(n|1048576)>>>0,{Length:r.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,o?3:1,a?2:1,2097184|(o?1:64),null,0);if(l<0){if(s&&l>>>0==3221225524)return;X(`relative open`)}let f=c[0];i.push(f),a&&(u=f);let p=d(f).readUInt32LE(0);return(p&1024||!!(p&16)!==o||r.type(f)!==1)&&X(`relative type validation`),f},m=(e,t)=>{let r=``,i=t;for(let t of Z(V.relative(n,V.dirname(e)))){r=V.join(r,t);let e=a.get(r.toLowerCase());e===void 0?(i=p(i,t,2147483648,!1,!0),a.set(r.toLowerCase(),i)):i=e}return i},h,g=()=>{for(let e of i.reverse())r.close(e);i.length=0};try{let a=f(n,2147483648,3,3,!0),o=Buffer.alloc(65536),s=r.finalPath(a,o,o.length/2,0);(!s||s>=o.length/2)&&X(`root identity validation`),V.normalize((e=>e.startsWith(`\\\\?\\UNC\\`)?`\\\\`+e.slice(8):e.startsWith(`\\\\?\\`)?e.slice(4):e)(o.subarray(0,s*2).toString(`utf16le`))).toLowerCase()!==V.normalize(n).toLowerCase()&&X(`root identity validation`);let c=m(e,a);h=m(t,a),l=p(c,V.basename(e),2147483648,!1,!1);let g=p(h,V.basename(t),2147483648,!1,!1,!0);if(g!==void 0)try{let e=d(l),t=d(g);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&&X(`output reparse validation`)}finally{r.close(g),i.pop()}let _=`.pipex-`+F()+`.tmp`;u=p(h,_,1073807488,!0,!1)}catch(e){throw u!==void 0&&r.setInfo(u,4,Buffer.from([1]),1),g(),e}let _=(e,t)=>{let n=[0],i=new Promise((i,a)=>{(e?r.write:r.read).async(e?u:l,t,t.length,n,null,(t,r)=>{t||!r?a(Error(`[PipeX] Secure file `+(e?`write`:`read`)+` failed`)):i(n[0])})});return o.add(i),i.then(()=>o.delete(i),()=>o.delete(i)),i},v=!1,y=new R({highWaterMark:D,read(){if(v)return;v=!0;let e=Buffer.allocUnsafe(D);_(!1,e).then(t=>{v=!1,this.destroyed||this.push(t?e.subarray(0,t):null)},e=>{v=!1,this.destroy(e)})}}),b=new B({highWaterMark:D,write(e,t,n){let r=(async()=>{let t=0;for(;t<e.length;){c&&X(`write after disposal`);let n=await _(!0,e.subarray(t));n||X(`write progress`),t+=n}})();o.add(r),r.then(()=>{o.delete(r),n()},e=>{o.delete(r),n(e)})}});return{source:y,destination:b,commit(){(c||s)&&X(`commit state`);let e=r.pointerBytes,n=e===8?8:4,i=n+e,a=i+4,o=Buffer.from(V.basename(t)+`\0`,`utf16le`),l=Buffer.alloc(a+o.length);l[0]=1,e===8?l.writeBigUInt64LE(BigInt(h),n):l.writeUInt32LE(Number(h),n),l.writeUInt32LE(o.length-2,i),o.copy(l,a);let d=r.setRelativeInfo(u,{},l,l.length,10);d<0&&X(`atomic rename status `+(d>>>0).toString(16)),s=!0},async dispose(){c||(c=!0,y.destroy(),b.destroy(),await Promise.allSettled([...o]),s||r.setInfo(u,4,Buffer.from([1]),1),g())}}}let oe;function se(){let e=Y().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 Q(e,t){let n=oe??=se(),r=[],i=U.O_NOFOLLOW,a=U.O_DIRECTORY;(!i||!a)&&X(`platform support`);let o=()=>{for(let e of r.reverse())try{H(e)}catch{}r.length=0},s=(e,t,a,o=0)=>{let s=n.openat(e,t,a|i,o);return s<0&&X(`relative open`),r.push(s),n.fcntl(s,2,1)<0&&X(`descriptor inheritance protection`),s},c=e=>{let t=G(V.parse(e).root,U.O_RDONLY|a);r.push(t);for(let n of Z(V.dirname(e)))t=s(t,n,U.O_RDONLY|a);return t},l=`.pipex-`+F(),u,d,f,p,m=!1,h=!1,g=!1,_=new Set,v=process.platform===`linux`?512:process.platform===`darwin`?128:process.platform===`openbsd`?8:2048,y=()=>{d!==void 0&&!m&&n.unlinkat(d,`data`,0),u!==void 0&&g&&n.unlinkat(u,l,v),o()};try{let r=c(e);u=c(t),f=s(r,V.basename(e),U.O_RDONLY|U.O_NONBLOCK);let o=W(f,{bigint:!0});o.isFile()||X(`input type validation`);let m=n.openat(u,V.basename(t),U.O_RDONLY|i|U.O_NONBLOCK,0);if(m>=0)try{let e=W(m,{bigint:!0});if(o.dev===e.dev&&o.ino===e.ino)throw Error(`[PipeX] Input and output must be different files`)}finally{H(m)}n.mkdirat(u,l,448)!==0&&X(`temporary directory creation`),g=!0,d=s(u,l,U.O_RDONLY|a);let h=W(d);(h.mode&63||h.uid!==process.geteuid?.())&&X(`temporary directory permissions`),p=s(d,`data`,U.O_WRONLY|U.O_CREAT|U.O_EXCL,384)}catch(e){throw y(),e}let b=(e,t)=>{let r=new Promise((r,i)=>{(e?n.write:n.read).async(e?p:f,t,t.length,(e,t)=>{e||t<0?i(Error(`[PipeX] Secure relative file I/O failed`)):r(Number(t))})});return _.add(r),r.then(()=>_.delete(r),()=>_.delete(r)),r},x=!1,S=new R({highWaterMark:D,read(){if(x)return;x=!0;let e=Buffer.allocUnsafe(D);b(!1,e).then(t=>{x=!1,this.destroyed||this.push(t?e.subarray(0,t):null)},e=>{x=!1,this.destroy(e)})}}),C=new B({highWaterMark:D,write(e,t,n){let r=(async()=>{let t=0;for(;t<e.length;){h&&X(`write after disposal`);let n=await b(!0,e.subarray(t));n||X(`relative write progress`),t+=n}})();_.add(r),r.then(()=>{_.delete(r),n()},e=>{_.delete(r),n(e)})}});return{source:S,destination:C,commit(){(h||m)&&X(`commit state`),n.renameat(d,`data`,u,V.basename(t))!==0&&X(`atomic relative rename`),m=!0},async dispose(){h||(h=!0,S.destroy(),C.destroy(),await Promise.allSettled([..._]),y())}}}var ce=class{#e;constructor(e){this.#e=e}async#t(e,n,r,i,a){let o=ne(e,n,r);try{await a(o.source,o.destination),t(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(n,r,i,a={}){let o=this.#e.createOperationSignal(a);t(o);let s=this.#e.startRequest();try{if(this.#e.schema)throw Error(`[PipeX] Global object schemas cannot validate raw file streams`);await this.#t(n,r,i,o,async(t,n)=>{let r=this.#n(s,o);await e(t,[T(this.#e.limits.maxInputBytes,`input`),...j(this.#e.plugins,`compress`,!1,e=>this.#e.emitProgress(e,s),this.#e.logger,this.#e.tracer,this.#e.dlq,r),T(this.#e.limits.maxOutputBytes,`output`)],n,{signal:o})}),await d(this.#e.emitAudit({requestId:s,operation:`process`,metadata:{controller:`file`}}),o,e=>this.#e.trackWork(s,e)),t(o),this.#e.endRequest(s)}catch(e){throw this.#e.emitError(e,s),e}}async reverse(n,r,i,a={}){let o=this.#e.createOperationSignal(a);t(o);let s=this.#e.startRequest();try{if(this.#e.schema)throw Error(`[PipeX] Global object schemas cannot validate raw file streams`);await this.#t(n,r,i,o,async(t,n)=>{let r=this.#n(s,o);await e(t,[T(this.#e.limits.maxInputBytes,`input`),...j(this.#e.plugins,`decompress`,!0,e=>this.#e.emitProgress(e,s),this.#e.logger,this.#e.tracer,this.#e.dlq,r),T(this.#e.limits.maxOutputBytes,`output`)],n,{signal:o})}),await d(this.#e.emitAudit({requestId:s,operation:`reverse`,metadata:{controller:`file`}}),o,e=>this.#e.trackWork(s,e)),t(o),this.#e.endRequest(s)}catch(e){throw this.#e.emitError(e,s),e}}async pack(n,r,i,o={}){let s=this.#e.createOperationSignal(o);t(s);let c=this.#e.startRequest();try{await this.#t(n,r,i,s,async(t,n)=>{await e(t,[T(this.#e.limits.maxInputBytes,`input`),v(this.#e.limits.maxFrames),S(this.#e.limits.maxFrameBytes,`MessagePack frame`),f(),k(x([])),a(this.#e.limits.maxFrameBytes,Math.min(2**53-1,this.#e.limits.maxFrames+1)),T(this.#e.limits.maxOutputBytes,`output`)],n,{signal:s})}),await d(this.#e.emitAudit({requestId:c,operation:`pack`,metadata:{controller:`file`}}),s,e=>this.#e.trackWork(c,e)),t(s),this.#e.endRequest(c)}catch(e){throw this.#e.emitError(e,c),e}}async unpack(r,i,o,s={}){let c=this.#e.createOperationSignal(s);t(c);let l=this.#e.startRequest();try{await this.#t(r,i,o,c,async(t,r)=>{let i=n(this.#e.limits.maxInputBytes),o=g(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,l)}),s=ee(),u=new z({writableObjectMode:!0,readableObjectMode:!0,transform:(e,t,n)=>{try{this.#e.validate(e),n(null,e)}catch(e){n(e)}}});await e(t,[T(this.#e.limits.maxInputBytes,`input`),a(this.#e.limits.maxFrameBytes,Math.min(2**53-1,this.#e.limits.maxFrames+1)),i,o,v(this.#e.limits.maxFrames),u,s,T(this.#e.limits.maxOutputBytes,`output`)],r,{signal:c})}),await d(this.#e.emitAudit({requestId:l,operation:`unpack`,metadata:{controller:`file`}}),c,e=>this.#e.trackWork(l,e)),t(c),this.#e.endRequest(l)}catch(e){throw this.#e.emitError(e,l),e}}},le=class{#e;constructor(e){this.#e=e}pack(e){try{w(e,Math.min(this.#e.limits.maxInputBytes,this.#e.limits.maxFrameBytes),`Serialization input`);let t=_.pack(e);if(t.length>this.#e.limits.maxInputBytes)throw Error(`[PipeX] Packed input exceeds configured limit`);if(h(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 P({stage:`pack`})}}unpack(e){try{if(e.byteLength>this.#e.limits.maxInputBytes)throw Error(`[PipeX] Serialized input exceeds configured limit`);return h(e,this.#e.limits.maxFrameBytes,1),E.unpack(e)}catch(e){throw e instanceof Error&&e.message.startsWith(`[PipeX]`)?e:new P({stage:`unpack`})}}#t=new WeakMap;async run(e,n={}){let r=this.#e.createOperationSignal(n);t(r);let i=A(e);O(i);let a=this.#e.plugins,o=[...this.#e.pipeline],s=this.#e.limits,f=this.#e.startRequest({operation:`run`}),p=Date.now(),m=this.#e.tracer?.startSpan(`binary:run`,{requestId:f});try{m?.setAttribute(`input.type`,i),this.#e.validate(e),w(e,s.maxInputBytes,`Input`);let n=c(e);if(n.length>s.maxInputBytes)throw Error(`[PipeX] Input exceeds configured limit`);(i===`object`||i===`array`)&&h(n,s.maxFrameBytes,1);let g=Object.create(null);for(let e of a){let t=Date.now(),a=this.#e.tracer?.startSpan(`plugin:${e.name}`,{requestId:f});try{a?.setAttribute(`mode`,`process`);let t=l(f,{originalType:i},this.#e.logger,a,r,s);if(n=await u(()=>e.process(n,t),e.retryOptions,this.#e.logger,{signal:r,limits:s,track:e=>this.#e.trackWork(f,e)}),!Buffer.isBuffer(n)||n.length>s.maxOutputBytes)throw Error(`[PipeX] Plugin output exceeds configured limit`)}catch(e){throw a?.setAttribute(`error`,!0),e}finally{a?.end()}g[e.name]=Date.now()-t,this.#e.emit(`plugin:after`,e.name,g[e.name])}if(n.length>s.maxOutputBytes)throw Error(`[PipeX] Output exceeds configured limit`);t(r);let _=Date.now()-p;await d(this.#e.emitAudit({requestId:f,operation:`process`,metadata:{inputType:i,durationMs:_}}),r,e=>this.#e.trackWork(f,e)),t(r),this.#t.set(n,i);let v={data:n,originalType:i,pipeline:o,metrics:{durationMs:_,steps:g}};return m?.setAttribute(`duration_ms`,_),this.#e.endRequest(f,_),v}catch(e){throw m?.setAttribute(`error`,!0),this.#e.emitError(e,f),e}finally{m?.end(),this.#e.releaseRequest(f)}}async undo(e,n,r={}){let i=Buffer.isBuffer(e),a,o,s;if(i)O(n),a=e,o=n,s=r;else{let t=e;if(!t||typeof t!=`object`||!Buffer.isBuffer(t.data)||!Array.isArray(t.pipeline)||t.pipeline.length>256||!t.pipeline.every(e=>typeof e==`string`&&e.length<=512)||!t.metrics||!Number.isFinite(t.metrics.durationMs)||t.metrics.durationMs<0||!t.metrics.steps||typeof t.metrics.steps!=`object`||Array.isArray(t.metrics.steps)||!Object.values(t.metrics.steps).every(e=>typeof e==`number`&&Number.isFinite(e)&&e>=0))throw Error(`[PipeX] Invalid EngineResult`);if(O(t.originalType),n!==void 0&&(typeof n!=`object`||!n))throw Error(`[PipeX] Invalid undo options`);let r=n,i=r?.expectedType??this.#t.get(t.data);if(i===void 0)throw Error(`[PipeX] Transported EngineResult requires a trusted expectedType`);if(O(i),i!==t.originalType)throw Error(`[PipeX] Result type does not match the expected type`);a=t.data,o=i,s=r??{}}let f=this.#e.createOperationSignal(s);t(f);let m=this.#e.plugins;b(m);let h=this.#e.limits;if(a.length>h.maxInputBytes)throw Error(`[PipeX] Undo input exceeds configured limit`);let g=this.#e.startRequest({operation:`undo`,originalType:o}),_=this.#e.tracer?.startSpan(`binary:undo`,{requestId:g});try{if(i&&m.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(A(e.data)!==o)throw Error(`[PipeX] Manifest data does not match the expected type`);a=c(e.data)}}for(let e of[...m].reverse()){let t=this.#e.tracer?.startSpan(`plugin:${e.name}`,{requestId:g});try{t?.setAttribute(`mode`,`reverse`);let n=l(g,{originalType:o},this.#e.logger,t,f,h);if(a=await u(()=>e.reverse(a,n),e.retryOptions,this.#e.logger,{signal:f,limits:h,track:e=>this.#e.trackWork(g,e)}),!Buffer.isBuffer(a)||a.length>h.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>h.maxOutputBytes)throw Error(`[PipeX] Output exceeds configured limit`);t(f);let e=p(a,o,h.maxFrameBytes);return this.#e.validate(e),t(f),await d(this.#e.emitAudit({requestId:g,operation:`reverse`,metadata:{originalType:o}}),f,e=>this.#e.trackWork(g,e)),t(f),this.#e.endRequest(g),e}catch(e){throw _?.setAttribute(`error`,!0),this.#e.emitError(e,g),e}finally{_?.end(),this.#e.releaseRequest(g)}}packWithManifest(e){if(this.#e.plugins.length>0)throw Error(`[PipeX] packWithManifest is serialization-only; use binary.run for plugin transforms`);let t=x([]);w(e,Math.min(this.#e.limits.maxInputBytes,this.#e.limits.maxFrameBytes),`Serialization input`);let n=_.pack(t),r=_.pack(e);if(h(n,this.#e.limits.maxFrameBytes,1),h(r,this.#e.limits.maxFrameBytes,1),n.length+r.length>Math.min(this.#e.limits.maxInputBytes,this.#e.limits.maxOutputBytes))throw Error(`[PipeX] Serialized input exceeds configured limit`);return Buffer.concat([n,r])}unpackWithManifest(e){if(e.length>this.#e.limits.maxInputBytes)throw Error(`[PipeX] Serialized input exceeds configured limit`);h(e,this.#e.limits.maxFrameBytes,2);let t=[];try{E.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(!m(t[0]))throw Error(`[PipeX] binary.unpackWithManifest: first frame is not a PipeXManifest`);return{manifest:t[0],data:t[1]}}},ue=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 I.from({writable:e,readable:t})}#r(n,r,i){let a=this.#e.createOperationSignal(i);if(t(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=r?`decompress`:`compress`,l;try{l=j(this.#e.plugins,c,r,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 L,f,p=new B({write(e,t,r){if(u.destroyed){let e=n.errored??u.errored;r(e instanceof Error?e:Error(`[PipeX] Stream pipeline is closed`));return}u.write(e,t,r)},final(e){f=e,u.end()},destroy(e,t){f=void 0,u.destroyed||u.destroy(e??void 0),t(e)}}),m=e=>{let t=f;f=void 0,t?t(e):e&&!p.destroyed&&p.destroy(e)};return e(u,[T(this.#e.limits.maxInputBytes,`input`),...l,T(this.#e.limits.maxOutputBytes,`output`)],n,{signal:a}).then(async()=>{await d(this.#e.emitAudit({requestId:o,operation:r?`reverse`:`process`,metadata:{controller:`stream`}}),a,e=>this.#e.trackWork(o,e)),t(a),this.#e.endRequest(o),m()}).catch(e=>{let t=e instanceof Error?e:Error(String(e));this.#e.emitError(t,o),m(t)}),p}into(e,t={}){return this.#r(e,!1,t)}reverseInto(e,t={}){return this.#r(e,!0,t)}pack(n={}){let r=this.#e.createOperationSignal(n);t(r);let i=this.#e.startRequest({operation:`pack`}),o=new L({objectMode:!0}),s=new L,c=[v(this.#e.limits.maxFrames),S(this.#e.limits.maxFrameBytes,`MessagePack frame`),f(),k(x([])),a(this.#e.limits.maxFrameBytes,Math.min(2**53-1,this.#e.limits.maxFrames+1)),T(this.#e.limits.maxOutputBytes,`output`)],l=this.#n(o,s);return e(o,c,s,{signal:r}).then(async()=>{await d(this.#e.emitAudit({requestId:i,operation:`pack`,metadata:{controller:`stream`}}),r,e=>this.#e.trackWork(i,e)),t(r),this.#e.endRequest(i)}).catch(e=>{this.#e.emitError(e,i),l.destroy(e instanceof Error?e:Error(String(e)))}),l}unpack(r={}){let i=this.#e.createOperationSignal(r);t(i);let o=this.#e.startRequest({operation:`unpack`}),s=new L,c=new L({objectMode:!0}),l=n(this.#e.limits.maxInputBytes),u=g(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,o)}),f=new z({writableObjectMode:!0,readableObjectMode:!0,transform:(e,t,n)=>{try{this.#e.validate(e),n(null,e)}catch(e){n(e)}}}),p=[T(this.#e.limits.maxInputBytes,`input`),a(this.#e.limits.maxFrameBytes,Math.min(2**53-1,this.#e.limits.maxFrames+1)),l,u,v(this.#e.limits.maxFrames),f],m=this.#n(s,c);return e(s,p,c,{signal:i}).then(async()=>{await d(this.#e.emitAudit({requestId:o,operation:`unpack`,metadata:{controller:`stream`}}),i,e=>this.#e.trackWork(o,e)),t(i),this.#e.endRequest(o)}).catch(e=>{this.#e.emitError(e,o),m.destroy(e instanceof Error?e:Error(String(e)))}),m}async pipe(n,r,i=!1,a={}){let o=this.#e.createOperationSignal(a);if(t(o),this.#e.schema)throw Error(`[PipeX] Global object schemas cannot validate raw byte streams`);let s=this.#e.startRequest(),c=i?`decompress`:`compress`,l=this.#t(s,o);try{let a=j(this.#e.plugins,c,i,e=>this.#e.emitProgress(e,s),this.#e.logger,this.#e.tracer,this.#e.dlq,l);await e(n,[T(this.#e.limits.maxInputBytes,`input`),...a,T(this.#e.limits.maxOutputBytes,`output`)],r,{signal:o}),await d(this.#e.emitAudit({requestId:s,operation:i?`reverse`:`process`,metadata:{controller:`stream`}}),o,e=>this.#e.trackWork(s,e)),t(o),this.#e.endRequest(s)}catch(e){throw this.#e.emitError(e,s),e}}};const $=2147483647;var de=class e extends q{static pluginRegistry=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(t){if(!t||typeof t!=`object`)throw Error(`[PipeX] Configuration must be an object`);let n=new e(t.limits);if(t.logger&&n.setLogger(t.logger),t.tracer&&n.setTracer(t.tracer),t.auditLogger&&n.setAuditLogger(t.auditLogger),t.dlq&&n.setDlq(t.dlq),t.schemaRegistry&&n.setSchemaRegistry(t.schemaRegistry),t.schema&&n.setSchema(t.schema),t.plugins){if(!Array.isArray(t.plugins))throw Error(`[PipeX] Configuration plugins must be an array`);for(let e of t.plugins){let t=this.pluginRegistry.get(e.name);if(!t)throw Error(`[PipeX] Unknown plugin in config: ${e.name}`);try{n.use(t(e.options))}catch(t){let n=t instanceof Error?t.message:String(t);throw Error(`[PipeX] Failed to initialize plugin "${e.name}": ${n}`,{cause:t})}}}return n}#e=[];#t=Object.freeze([]);#n;#r;#i;#a;#o;#s;#c;#l=new Set;#u=new Map;#d=new Set;#f=new Map;file;binary;stream;constructor(e={}){super(),this.#c=Object.freeze({...N,...e}),this.#p(this.#c),this.file=new ce(this),this.binary=new le(this),this.stream=new ue(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>$||e.maxKmsEncryptedKeyBytes>4294967295)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>$)throw Error(`[PipeX] Invalid operation timeout`);let n=e.signal?[e.signal]:[];t>0&&n.push(AbortSignal.timeout(t));let r=n.length===0?new AbortController().signal:AbortSignal.any(n);return M(r,t),r}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=o(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=s(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(r(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}`,...r(e)})))}startRequest(e={}){if(this.#l.size>=this.#c.maxConcurrentOperations)throw Error(`[PipeX] Maximum concurrent operations exceeded`);let t=F();this.#l.add(t),this.#f.set(t,this.pipeline);try{this.#i?.info(`[PipeX] Request started`,{requestId:t,...e})}catch{}return this.emit(`start`,t),t}trackWork(e,t){let n=this.#u.get(e);n||this.#u.set(e,n=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){if(this.#u.get(e)?.size){this.#d.add(e);return}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 n=this.rawListeners(e);for(let e of n)i(()=>Reflect.apply(e,this,t));return n.length>0}on(e,t){return super.on(e,t)}once(e,t){return super.once(e,t)}};export{de as t};
@@ -1 +0,0 @@
1
- const e=require(`./core-B_z1gN5W.cjs`),t=require(`./resourceLimits-CI0Qrqdf.cjs`);let n=require(`node:crypto`),r=require(`node:stream`);require(`zod`);let i=require(`node:path`);i=e.W(i,1);let a=require(`node:fs`),o=require(`node:events`),s=require(`node:module`),c;const l=()=>c??=(0,s.createRequire)(require(`url`).pathToFileURL(__filename).href)(`koffi`),u=e=>{throw Error(`[PipeX] Secure file `+e+` failed`)},d=e=>{let t=i.default.parse(e).root;return e.slice(t.length).split(i.default.sep).filter(Boolean)};function f(t,n,r){let o=a.realpathSync.native(i.default.resolve(r??process.cwd())),s=e.c(t,o),c=e.k(n,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(t,a,o){let s=p??=m(),c=[],l=new Map,f=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==3221225524)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(i.default.relative(o,i.default.dirname(e)))){n=i.default.join(n,t);let e=l.get(n.toLowerCase());e===void 0?(r=x(r,t,2147483648,!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 e=b(o,2147483648,3,3,!0),r=Buffer.alloc(65536),l=s.finalPath(e,r,r.length/2,0);(!l||l>=r.length/2)&&u(`root identity validation`),i.default.normalize((e=>e.startsWith(`\\\\?\\UNC\\`)?`\\\\`+e.slice(8):e.startsWith(`\\\\?\\`)?e.slice(4):e)(r.subarray(0,l*2).toString(`utf16le`))).toLowerCase()!==i.default.normalize(o).toLowerCase()&&u(`root identity validation`);let d=S(t,e);C=S(a,e),_=x(d,i.default.basename(t),2147483648,!1,!1);let f=x(C,i.default.basename(a),2147483648,!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,n.randomUUID)()+`.tmp`;v=x(C,p,1073807488,!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(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:e.t,read(){if(E)return;E=!0;let t=Buffer.allocUnsafe(e.t);T(!1,t).then(e=>{E=!1,this.destroyed||this.push(e?t.subarray(0,e):null)},e=>{E=!1,this.destroy(e)})}}),O=new r.Writable({highWaterMark:e.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(i.default.basename(a)+`\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(t,o){let s=g??=_(),c=[],l=a.constants.O_NOFOLLOW,f=a.constants.O_DIRECTORY;(!l||!f)&&u(`platform support`);let p=()=>{for(let e of c.reverse())try{(0,a.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,a.openSync)(i.default.parse(e).root,a.constants.O_RDONLY|f);c.push(t);for(let n of d(i.default.dirname(e)))t=m(t,n,a.constants.O_RDONLY|f);return t},v=`.pipex-`+(0,n.randomUUID)(),y,b,x,S,C=!1,w=!1,T=!1,E=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 e=h(t);y=h(o),x=m(e,i.default.basename(t),a.constants.O_RDONLY|a.constants.O_NONBLOCK);let n=(0,a.fstatSync)(x,{bigint:!0});n.isFile()||u(`input type validation`);let r=s.openat(y,i.default.basename(o),a.constants.O_RDONLY|l|a.constants.O_NONBLOCK,0);if(r>=0)try{let e=(0,a.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,a.closeSync)(r)}s.mkdirat(y,v,448)!==0&&u(`temporary directory creation`),T=!0,b=m(y,v,a.constants.O_RDONLY|f);let c=(0,a.fstatSync)(b);(c.mode&63||c.uid!==process.geteuid?.())&&u(`temporary directory permissions`),S=m(b,`data`,a.constants.O_WRONLY|a.constants.O_CREAT|a.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(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:e.t,read(){if(A)return;A=!0;let t=Buffer.allocUnsafe(e.t);k(!1,t).then(e=>{A=!1,this.destroyed||this.push(e?t.subarray(0,e):null)},e=>{A=!1,this.destroy(e)})}}),M=new r.Writable({highWaterMark:e.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,i.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(t,n,r,i,a){let o=f(t,n,r);try{await a(o.source,o.destination),e.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(t,n,r,i={}){let a=this.#e.createOperationSignal(i);e.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(t,n,r,a,async(t,n)=>{let r=this.#n(o,a);await e.A(t,[e.p(this.#e.limits.maxInputBytes,`input`),...e.x(this.#e.plugins,`compress`,!1,e=>this.#e.emitProgress(e,o),this.#e.logger,this.#e.tracer,this.#e.dlq,r),e.p(this.#e.limits.maxOutputBytes,`output`)],n,{signal:a})}),await e.R(this.#e.emitAudit({requestId:o,operation:`process`,metadata:{controller:`file`}}),a,e=>this.#e.trackWork(o,e)),e.B(a),this.#e.endRequest(o)}catch(e){throw this.#e.emitError(e,o),e}}async reverse(t,n,r,i={}){let a=this.#e.createOperationSignal(i);e.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(t,n,r,a,async(t,n)=>{let r=this.#n(o,a);await e.A(t,[e.p(this.#e.limits.maxInputBytes,`input`),...e.x(this.#e.plugins,`decompress`,!0,e=>this.#e.emitProgress(e,o),this.#e.logger,this.#e.tracer,this.#e.dlq,r),e.p(this.#e.limits.maxOutputBytes,`output`)],n,{signal:a})}),await e.R(this.#e.emitAudit({requestId:o,operation:`reverse`,metadata:{controller:`file`}}),a,e=>this.#e.trackWork(o,e)),e.B(a),this.#e.endRequest(o)}catch(e){throw this.#e.emitError(e,o),e}}async pack(t,n,r,i={}){let a=this.#e.createOperationSignal(i);e.B(a);let o=this.#e.startRequest();try{await this.#t(t,n,r,a,async(t,n)=>{await e.A(t,[e.p(this.#e.limits.maxInputBytes,`input`),e.b(this.#e.limits.maxFrames),e.h(this.#e.limits.maxFrameBytes,`MessagePack frame`),e.S(),e.v(e.g([])),e.H(this.#e.limits.maxFrameBytes,Math.min(2**53-1,this.#e.limits.maxFrames+1)),e.p(this.#e.limits.maxOutputBytes,`output`)],n,{signal:a})}),await e.R(this.#e.emitAudit({requestId:o,operation:`pack`,metadata:{controller:`file`}}),a,e=>this.#e.trackWork(o,e)),e.B(a),this.#e.endRequest(o)}catch(e){throw this.#e.emitError(e,o),e}}async unpack(t,n,i,a={}){let o=this.#e.createOperationSignal(a);e.B(o);let s=this.#e.startRequest();try{await this.#t(t,n,i,o,async(t,n)=>{let i=e.C(this.#e.limits.maxInputBytes),a=e._(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=e.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 e.A(t,[e.p(this.#e.limits.maxInputBytes,`input`),e.H(this.#e.limits.maxFrameBytes,Math.min(2**53-1,this.#e.limits.maxFrames+1)),i,a,e.b(this.#e.limits.maxFrames),l,c,e.p(this.#e.limits.maxOutputBytes,`output`)],n,{signal:o})}),await e.R(this.#e.emitAudit({requestId:s,operation:`unpack`,metadata:{controller:`file`}}),o,e=>this.#e.trackWork(s,e)),e.B(o),this.#e.endRequest(s)}catch(e){throw this.#e.emitError(e,s),e}}},b=class{#e;constructor(e){this.#e=e}pack(n){try{e.l(n,Math.min(this.#e.limits.maxInputBytes,this.#e.limits.maxFrameBytes),`Serialization input`);let t=e.a.pack(n);if(t.length>this.#e.limits.maxInputBytes)throw Error(`[PipeX] Packed input exceeds configured limit`);if(e.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 t.w({stage:`pack`})}}unpack(n){try{if(n.byteLength>this.#e.limits.maxInputBytes)throw Error(`[PipeX] Serialized input exceeds configured limit`);return e.V(n,this.#e.limits.maxFrameBytes,1),e.s.unpack(n)}catch(e){throw e instanceof Error&&e.message.startsWith(`[PipeX]`)?e:new t.w({stage:`unpack`})}}#t=new WeakMap;async run(t,n={}){let r=this.#e.createOperationSignal(n);e.B(r);let i=e.w(t);e.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(t),e.l(t,s.maxInputBytes,`Input`);let n=e.N(t);if(n.length>s.maxInputBytes)throw Error(`[PipeX] Input exceeds configured limit`);(i===`object`||i===`array`)&&e.V(n,s.maxFrameBytes,1);let d=Object.create(null);for(let t of a){let a=Date.now(),o=this.#e.tracer?.startSpan(`plugin:${t.name}`,{requestId:c});try{o?.setAttribute(`mode`,`process`);let a=e.O(c,{originalType:i},this.#e.logger,o,r,s);if(n=await e.P(()=>t.process(n,a),t.retryOptions,this.#e.logger,{signal:r,limits:s,track:e=>this.#e.trackWork(c,e)}),!Buffer.isBuffer(n)||n.length>s.maxOutputBytes)throw Error(`[PipeX] Plugin output exceeds configured limit`)}catch(e){throw o?.setAttribute(`error`,!0),e}finally{o?.end()}d[t.name]=Date.now()-a,this.#e.emit(`plugin:after`,t.name,d[t.name])}if(n.length>s.maxOutputBytes)throw Error(`[PipeX] Output exceeds configured limit`);e.B(r);let f=Date.now()-l;await e.R(this.#e.emitAudit({requestId:c,operation:`process`,metadata:{inputType:i,durationMs:f}}),r,e=>this.#e.trackWork(c,e)),e.B(r),this.#t.set(n,i);let p={data:n,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(t,n,r={}){let i=Buffer.isBuffer(t),a,o,s;if(i)e.u(n),a=t,o=n,s=r;else{let r=t;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(e.u(r.originalType),n!==void 0&&(typeof n!=`object`||!n))throw Error(`[PipeX] Invalid undo options`);let i=n,c=i?.expectedType??this.#t.get(r.data);if(c===void 0)throw Error(`[PipeX] Transported EngineResult requires a trusted expectedType`);if(e.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);e.B(c);let l=this.#e.plugins;e.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 t;try{t=this.unpackWithManifest(a)}catch{}if(t){if(t.manifest.plugins.length!==0)throw Error(`[PipeX] Manifest plugin chain does not match the configured engine`);if(e.w(t.data)!==o)throw Error(`[PipeX] Manifest data does not match the expected type`);a=e.N(t.data)}}for(let t of[...l].reverse()){let n=this.#e.tracer?.startSpan(`plugin:${t.name}`,{requestId:d});try{n?.setAttribute(`mode`,`reverse`);let r=e.O(d,{originalType:o},this.#e.logger,n,c,u);if(a=await e.P(()=>t.reverse(a,r),t.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 n?.setAttribute(`error`,!0),e}finally{n?.end()}this.#e.emit(`plugin:after`,t.name,0)}if(a.length>u.maxOutputBytes)throw Error(`[PipeX] Output exceeds configured limit`);e.B(c);let t=e.T(a,o,u.maxFrameBytes);return this.#e.validate(t),e.B(c),await e.R(this.#e.emitAudit({requestId:d,operation:`reverse`,metadata:{originalType:o}}),c,e=>this.#e.trackWork(d,e)),e.B(c),this.#e.endRequest(d),t}catch(e){throw f?.setAttribute(`error`,!0),this.#e.emitError(e,d),e}finally{f?.end(),this.#e.releaseRequest(d)}}packWithManifest(t){if(this.#e.plugins.length>0)throw Error(`[PipeX] packWithManifest is serialization-only; use binary.run for plugin transforms`);let n=e.g([]);e.l(t,Math.min(this.#e.limits.maxInputBytes,this.#e.limits.maxFrameBytes),`Serialization input`);let r=e.a.pack(n),i=e.a.pack(t);if(e.V(r,this.#e.limits.maxFrameBytes,1),e.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(t){if(t.length>this.#e.limits.maxInputBytes)throw Error(`[PipeX] Serialized input exceeds configured limit`);e.V(t,this.#e.limits.maxFrameBytes,2);let n=[];try{e.s.unpackMultiple(t,e=>{if(n.length>=2)throw Error(`[PipeX] Frame count exceeds configured limit`);n.push(e)})}catch(e){throw e instanceof Error&&e.message.startsWith(`[PipeX]`)?e:Error(`[PipeX] binary.unpackWithManifest: invalid MessagePack input`)}if(n.length<2)throw Error(`[PipeX] binary.unpackWithManifest: buffer contains fewer than 2 frames`);if(!e.U(n[0]))throw Error(`[PipeX] binary.unpackWithManifest: first frame is not a PipeXManifest`);return{manifest:n[0],data:n[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(t,n,i){let a=this.#e.createOperationSignal(i);if(e.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=n?`decompress`:`compress`,l;try{l=e.x(this.#e.plugins,c,n,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(e,n,r){if(u.destroyed){let e=t.errored??u.errored;r(e instanceof Error?e:Error(`[PipeX] Stream pipeline is closed`));return}u.write(e,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 e.A(u,[e.p(this.#e.limits.maxInputBytes,`input`),...l,e.p(this.#e.limits.maxOutputBytes,`output`)],t,{signal:a}).then(async()=>{await e.R(this.#e.emitAudit({requestId:o,operation:n?`reverse`:`process`,metadata:{controller:`stream`}}),a,e=>this.#e.trackWork(o,e)),e.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(t={}){let n=this.#e.createOperationSignal(t);e.B(n);let i=this.#e.startRequest({operation:`pack`}),a=new r.PassThrough({objectMode:!0}),o=new r.PassThrough,s=[e.b(this.#e.limits.maxFrames),e.h(this.#e.limits.maxFrameBytes,`MessagePack frame`),e.S(),e.v(e.g([])),e.H(this.#e.limits.maxFrameBytes,Math.min(2**53-1,this.#e.limits.maxFrames+1)),e.p(this.#e.limits.maxOutputBytes,`output`)],c=this.#n(a,o);return e.A(a,s,o,{signal:n}).then(async()=>{await e.R(this.#e.emitAudit({requestId:i,operation:`pack`,metadata:{controller:`stream`}}),n,e=>this.#e.trackWork(i,e)),e.B(n),this.#e.endRequest(i)}).catch(e=>{this.#e.emitError(e,i),c.destroy(e instanceof Error?e:Error(String(e)))}),c}unpack(t={}){let n=this.#e.createOperationSignal(t);e.B(n);let i=this.#e.startRequest({operation:`unpack`}),a=new r.PassThrough,o=new r.PassThrough({objectMode:!0}),s=e.C(this.#e.limits.maxInputBytes),c=e._(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=[e.p(this.#e.limits.maxInputBytes,`input`),e.H(this.#e.limits.maxFrameBytes,Math.min(2**53-1,this.#e.limits.maxFrames+1)),s,c,e.b(this.#e.limits.maxFrames),l],d=this.#n(a,o);return e.A(a,u,o,{signal:n}).then(async()=>{await e.R(this.#e.emitAudit({requestId:i,operation:`unpack`,metadata:{controller:`stream`}}),n,e=>this.#e.trackWork(i,e)),e.B(n),this.#e.endRequest(i)}).catch(e=>{this.#e.emitError(e,i),d.destroy(e instanceof Error?e:Error(String(e)))}),d}async pipe(t,n,r=!1,i={}){let a=this.#e.createOperationSignal(i);if(e.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=e.x(this.#e.plugins,s,r,e=>this.#e.emitProgress(e,o),this.#e.logger,this.#e.tracer,this.#e.dlq,c);await e.A(t,[e.p(this.#e.limits.maxInputBytes,`input`),...i,e.p(this.#e.limits.maxOutputBytes,`output`)],n,{signal:a}),await e.R(this.#e.emitAudit({requestId:o,operation:r?`reverse`:`process`,metadata:{controller:`stream`}}),a,e=>this.#e.trackWork(o,e)),e.B(a),this.#e.endRequest(o)}catch(e){throw this.#e.emitError(e,o),e}}};const S=2147483647;var C=class r extends o.EventEmitter{static pluginRegistry=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=new Set;#u=new Map;#d=new Set;#f=new Map;file;binary;stream;constructor(e={}){super(),this.#c=Object.freeze({...t.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>4294967295)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(t={}){let n=t.timeoutMs??this.#c.operationTimeoutMs;if(!Number.isSafeInteger(n)||n<0||n>S)throw Error(`[PipeX] Invalid operation timeout`);let r=t.signal?[t.signal]:[];n>0&&r.push(AbortSignal.timeout(n));let i=r.length===0?new AbortController().signal:AbortSignal.any(r);return e.z(i,n),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(t){if(!t||![`info`,`warn`,`error`,`debug`].every(e=>typeof t[e]==`function`))throw Error(`[PipeX] Logger must implement info, warn, error, and debug`);return this.#i=e.I(t),this}get logger(){return this.#i}setTracer(t){if(!t||typeof t.startSpan!=`function`)throw Error(`[PipeX] Tracer must implement startSpan`);return this.#a=e.L(t),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(t){if(!t||typeof t.name!=`string`||t.name.length===0||t.name.length>128||typeof t.version!=`string`||t.version.length===0||typeof t.process!=`function`)throw Error(`[PipeX] Invalid processor plugin`);if(e.E(t),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(t),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(t=>Object.freeze({plugin:`${t.name}@${t.version}`,...e.E(t)})))}startRequest(e={}){if(this.#l.size>=this.#c.maxConcurrentOperations)throw Error(`[PipeX] Maximum concurrent operations exceeded`);let t=(0,n.randomUUID)();this.#l.add(t),this.#f.set(t,this.pipeline);try{this.#i?.info(`[PipeX] Request started`,{requestId:t,...e})}catch{}return this.emit(`start`,t),t}trackWork(e,t){let n=this.#u.get(e);n||this.#u.set(e,n=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){if(this.#u.get(e)?.size){this.#d.add(e);return}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(t,...n){let r=this.rawListeners(t);for(let t of r)e.F(()=>Reflect.apply(t,this,n));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}});
@@ -1 +0,0 @@
1
- require(`./core-B_z1gN5W.cjs`);const e=require(`./resourceLimits-CI0Qrqdf.cjs`);let t=require(`node:crypto`),n=require(`node:stream`);const r=Buffer.from(`PXAE`),i={"aes-256-gcm":1,"chacha20-poly1305":2},a={1:`aes-256-gcm`,2:`chacha20-poly1305`};function o(t){if(!Buffer.isBuffer(t)||t.length!==32)throw new e.l}function s(t){return{maxInputBytes:e.n(t),maxOutputBytes:e.r(t),maxFrameBytes:t?.limits?.maxFrameBytes??e.t.maxFrameBytes,maxFrames:t?.limits?.maxFrames??e.t.maxFrames}}function c(e,t){let n=t.maxFrameBytes-29;if(n<1||t.maxFrameBytes<28)throw Error(`[PipeX] Encryption frame limit ${t.maxFrameBytes} bytes is too small`);let r=e.frameSizeBytes??Math.min(65536,n);if(!Number.isSafeInteger(r)||r<1||r>4294967295)throw Error(`[PipeX] Encryption frameSizeBytes must be a positive 32-bit integer`);if(r>n)throw Error(`[PipeX] Encryption frameSizeBytes exceeds the ${t.maxFrameBytes}-byte frame limit`);return r}function l(e,t){let n=e===0?0:Math.ceil(e/t);return 28+e+(n+1)*29}function u(e,t){return e===0?0:Math.ceil(e/t)}function d(e,n,a=(0,t.randomBytes)(16)){let o=Buffer.alloc(28);return r.copy(o,0),o.writeUInt8(1,4),o.writeUInt8(i[e],5),o.writeUInt16BE(0,6),o.writeUInt32BE(n,8),a.copy(o,12),o}function f(e,t){if(e.length!==28||!e.subarray(0,4).equals(r))throw Error(`[PipeX] Decryption failed: invalid framed header`);if(e.readUInt8(4)!==1)throw Error(`[PipeX] Decryption failed: unsupported format version`);let n=a[e.readUInt8(5)];if(!n||e.readUInt16BE(6)!==0)throw Error(`[PipeX] Decryption failed: invalid framed header`);let i=e.readUInt32BE(8);if(i<1||i>t.maxFrameBytes-29)throw Error(`[PipeX] Decryption failed: invalid frame size`);return{bytes:e,algorithm:n,frameSizeBytes:i,salt:e.subarray(12,28)}}function p(e,n){let r=Buffer.from(`PipeX AEAD framed v1:${n.algorithm}`,`utf8`);return Buffer.from((0,t.hkdfSync)(`sha256`,e,n.salt,r,32))}function m(e){if(e<0n||e>18446744073709551615n)throw Error(`[PipeX] Encryption frame sequence exhausted`);let t=Buffer.alloc(12);return t.writeBigUInt64BE(e,4),t}function h(e,t,n){let r=Buffer.alloc(13);return r.writeUInt8(e,0),r.writeBigUInt64BE(t,1),r.writeUInt32BE(n,9),r}function g(e,n,r,i,a,o){let s=h(n,r,e.length),c=m(r);try{let n=(0,t.createCipheriv)(i,a,c,{authTagLength:16});n.setAAD(Buffer.concat([o,s]));let r=Buffer.concat([n.update(e),n.final()]);return Buffer.concat([s,r,n.getAuthTag()],29+r.length)}finally{c.fill(0)}}function _(n,r,i,a,o,s,c){let l=m(a),u=(0,t.createDecipheriv)(o,s,l,{authTagLength:16});if(u.setAAD(Buffer.concat([c,i])),r.length!==16)throw new e.a;u.setAuthTag(r);let d=u.update(n);try{let e=u.final();return e.length===0?d:Buffer.concat([d,e])}catch{throw d.fill(0),new e.a}finally{l.fill(0)}}function v(e,n,r){if(e.length<29)throw Error(`[PipeX] Decryption failed: packet too short`);if(e.length-29>r.maxOutputBytes)throw Error(`[PipeX] Decryption output exceeds ${r.maxOutputBytes} bytes`);let i=a[e.readUInt8(0)];if(!i)throw Error(`[PipeX] Decryption failed: unknown legacy algorithm`);let o=(0,t.createDecipheriv)(i,n,e.subarray(1,13),{authTagLength:16});o.setAuthTag(e.subarray(13,29));let s=o.update(e.subarray(29));try{let e=o.final();return e.length===0?s:Buffer.concat([s,e])}catch{throw s.fill(0),Error(`[PipeX] Decryption failed: authentication failed`)}}function y(e){return e.length>=r.length&&e.subarray(0,r.length).equals(r)}function b(e,t,n){o(t.key);let r=s(n);if(e.length>r.maxInputBytes)throw Error(`[PipeX] Encryption input exceeds ${r.maxInputBytes} bytes`);let i=c(t,r);if(u(e.length,i)>r.maxFrames)throw Error(`[PipeX] Encryption frame count exceeds ${r.maxFrames}`);let a=l(e.length,i);if(a>r.maxOutputBytes)throw Error(`[PipeX] Encryption output exceeds ${r.maxOutputBytes} bytes`);let m=d(t.algorithm,i),h=f(m,r),_=p(t.key,h),v=[m],y=0n;try{for(let n=0;n<e.length;n+=i)v.push(g(e.subarray(n,Math.min(e.length,n+i)),1,y++,t.algorithm,_,m));return v.push(g(Buffer.alloc(0),2,y,t.algorithm,_,m)),Buffer.concat(v,a)}finally{_.fill(0)}}function x(e,t,n){o(t.key);let i=s(n);if(e.length>i.maxInputBytes)throw Error(`[PipeX] Decryption input exceeds ${i.maxInputBytes} bytes`);if(e.length===0||!y(e)&&e.readUInt8(0)!==r.readUInt8(0)){if(t.allowLegacyDecrypt!==!0)throw Error(`[PipeX] Decryption failed: legacy format disabled`);return v(e,t.key,i)}if(e.length<28)throw Error(`[PipeX] Decryption failed: incomplete framed header`);let a=f(e.subarray(0,28),i),c=p(t.key,a),l=[],u=0,d=28,m=0n,h=0,g=!1;try{for(;d<e.length;){if(g||e.length-d<13)throw Error(`[PipeX] Decryption failed: incomplete or trailing frame`);let t=e.subarray(d,d+13);d+=13;let n=t.readUInt8(0),r=t.readBigUInt64BE(1),o=t.readUInt32BE(9);if(r!==m)throw Error(`[PipeX] Decryption failed: invalid frame sequence`);if(n!==1&&n!==2)throw Error(`[PipeX] Decryption failed: invalid frame type`);if(n===2&&o!==0)throw Error(`[PipeX] Decryption failed: invalid final frame`);if(o>a.frameSizeBytes||o>i.maxFrameBytes-29)throw Error(`[PipeX] Decryption failed: frame length exceeds configured limit`);if(n===1&&h>=i.maxFrames)throw Error(`[PipeX] Encryption frame count exceeds ${i.maxFrames}`);if(n===1&&o>i.maxOutputBytes-u)throw Error(`[PipeX] Decryption output exceeds ${i.maxOutputBytes} bytes`);if(e.length-d<o+16)throw Error(`[PipeX] Decryption failed: incomplete frame`);let s=e.subarray(d,d+o);d+=o;let f=e.subarray(d,d+16);d+=16;let p=_(s,f,t,r,a.algorithm,c,a.bytes);n===2?(p.fill(0),g=!0):(h++,u+=p.length,l.push(p)),m++}if(!g)throw Error(`[PipeX] Decryption failed: missing authenticated final frame`);let t=Buffer.concat(l,u);for(let e of l)e.fill(0);return t}catch(e){for(let e of l)e.fill(0);throw e}finally{c.fill(0)}}function S(e,t){o(e.key);let r=s(t),i=c(e,r);if(l(0,i)>r.maxOutputBytes)throw Error(`[PipeX] Encryption output exceeds ${r.maxOutputBytes} bytes`);let a=d(e.algorithm,i),m=f(a,r),h=p(e.key,m),_=Buffer.alloc(i),v=0,y=0,b=0,x=0n,S=!1,C=()=>{_.fill(0),h.fill(0)};return new n.Transform({transform(t,n,o){try{let n=Buffer.isBuffer(t)?t:Buffer.from(t);if(n.length>r.maxInputBytes-y)throw Error(`[PipeX] Encryption input exceeds ${r.maxInputBytes} bytes`);let s=y+n.length;if(u(s,i)>r.maxFrames)throw Error(`[PipeX] Encryption frame count exceeds ${r.maxFrames}`);if(l(s,i)>r.maxOutputBytes)throw Error(`[PipeX] Encryption output exceeds ${r.maxOutputBytes} bytes`);y=s,S||=(this.push(a),!0);let c=0;for(;c<n.length;){let t=Math.min(i-v,n.length-c);if(n.copy(_,v,c,c+t),v+=t,c+=t,v===i){if(++b>r.maxFrames)throw Error(`[PipeX] Encryption frame count exceeds ${r.maxFrames}`);this.push(g(_,1,x++,e.algorithm,h,a)),_.fill(0),v=0}}o()}catch(e){C(),o(e)}},flush(t){try{if(S||=(this.push(a),!0),v>0){if(++b>r.maxFrames)throw Error(`[PipeX] Encryption frame count exceeds ${r.maxFrames}`);this.push(g(_.subarray(0,v),1,x++,e.algorithm,h,a))}this.push(g(Buffer.alloc(0),2,x,e.algorithm,h,a)),C(),t()}catch(e){C(),t(e)}},destroy(e,t){C(),t(e)}})}function C(e,t){o(e.key);let i=s(t),a=`unknown`,c=0,l=0,u=Buffer.alloc(28),d=0,m,h,g=Buffer.alloc(13),y=0,b,x=0,S=0n,C=0,w=!1,T=[],E=()=>{h?.fill(0),b?.fill(0),u.fill(0),g.fill(0),T=[]},D=(t,n)=>{let r=0;for(;r<t.length;){if(w)throw Error(`[PipeX] Decryption failed: trailing data after final frame`);if(!m){let n=Math.min(28-d,t.length-r);t.copy(u,d,r,r+n),d+=n,r+=n,d===28&&(m=f(u,i),h=p(e.key,m));continue}if(y<13){let e=Math.min(13-y,t.length-r);if(t.copy(g,y,r,r+e),y+=e,r+=e,y<13)continue;let n=g.readUInt8(0),a=g.readBigUInt64BE(1),o=g.readUInt32BE(9);if(a!==S)throw Error(`[PipeX] Decryption failed: invalid frame sequence`);if(n!==1&&n!==2)throw Error(`[PipeX] Decryption failed: invalid frame type`);if(n===2&&o!==0)throw Error(`[PipeX] Decryption failed: invalid final frame`);if(o>m.frameSizeBytes||o>i.maxFrameBytes-29)throw Error(`[PipeX] Decryption failed: frame length exceeds configured limit`);if(n===1&&C>=i.maxFrames)throw Error(`[PipeX] Encryption frame count exceeds ${i.maxFrames}`);if(n===1&&o>i.maxOutputBytes-l)throw Error(`[PipeX] Decryption output exceeds ${i.maxOutputBytes} bytes`);b=Buffer.alloc(o+16),x=0}let a=Math.min(b.length-x,t.length-r);if(t.copy(b,x,r,r+a),x+=a,r+=a,x<b.length)continue;let o=g.readUInt8(0),s=g.readBigUInt64BE(1),c=g.readUInt32BE(9),v=_(b.subarray(0,c),b.subarray(c),g,s,m.algorithm,h,m.bytes);o===2?(v.fill(0),w=!0):(C++,l+=v.length,n.push(v)),S++,b.fill(0),b=void 0,x=0,g.fill(0),y=0}};return new n.Transform({transform(t,n,o){try{let n=Buffer.isBuffer(t)?t:Buffer.from(t);if(n.length>i.maxInputBytes-c)throw Error(`[PipeX] Decryption input exceeds ${i.maxInputBytes} bytes`);if(c+=n.length,n.length===0)return o();if(a===`unknown`&&(a=n.readUInt8(0)===r.readUInt8(0)?`framed`:`legacy`,a===`legacy`&&e.allowLegacyDecrypt===!1))throw Error(`[PipeX] Decryption failed: legacy format disabled`);a===`legacy`?T.push(n):D(n,this),o()}catch(e){E(),o(e)}},flush(t){try{if(a===`legacy`){let n=v(Buffer.concat(T,c),e.key,i);return this.push(n),E(),t()}if(a!==`framed`||!m||y!==0||b)throw Error(`[PipeX] Decryption failed: incomplete encrypted stream`);if(!w)throw Error(`[PipeX] Decryption failed: missing authenticated final frame`);E(),t()}catch(e){E(),t(e)}},destroy(e,t){E(),t(e)}})}var w=class extends e.i{name=`encryption`;version=`4.0.0`;constructor(t){if(super(t),this.options=t,!t||!Buffer.isBuffer(t.key)||t.key.length!==32)throw new e.l;if(![`aes-256-gcm`,`chacha20-poly1305`].includes(t.algorithm))throw new e.b({transformName:`encryption`,stage:`configuration`});if(t.frameSizeBytes!==void 0&&(!Number.isSafeInteger(t.frameSizeBytes)||t.frameSizeBytes<1||t.frameSizeBytes>4294967295))throw new e.s(`[PipeX] Invalid encryption frame size`);if(t.allowLegacyDecrypt!==void 0&&typeof t.allowLegacyDecrypt!=`boolean`)throw new e.s(`[PipeX] Invalid legacy decryption setting`)}async process(e,t){return b(e,this.options,t)}async reverse(e,t){return x(e,this.options,t)}createStream(e,t){return e===`compress`?S(this.options,t):C(this.options,t)}};Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return w}});
@@ -1 +0,0 @@
1
- import{b as e,c as t,i as n,n as r,r as i}from"./resourceLimits-C1HHDwXQ.mjs";import{createHmac as a,timingSafeEqual as o}from"node:crypto";import{Transform as s}from"node:stream";const c={sha256:32,sha512:64};var l=class extends n{name=`hashing`;version=`3.0.0`;constructor(n){if(super(n),this.options=n,!(n.algorithm in c))throw new e({transformName:`hashing`,stage:`configuration`});if(!n.secret||n.secret.length<16)throw new t({transformName:`hashing`})}async process(e,n){let o=r(n),s=i(n),l=c[this.options.algorithm];if(e.length>o)throw new t({transformName:`hashing`,stage:`input`});if(e.length>s-l)throw new t({transformName:`hashing`,stage:`output`});n.metadata??={};let u=a(this.options.algorithm,this.options.secret).update(e).digest();return n.metadata.hmac=u.toString(`hex`),Buffer.concat([e,u])}async reverse(e,n){let s=c[this.options.algorithm],l=r(n),u=i(n);if(e.length>l)throw new t({transformName:`hashing`,stage:`input`});if(e.length<s)throw new t({transformName:`hashing`});if(e.length-s>u)throw new t({transformName:`hashing`,stage:`output`});let d=e.subarray(0,e.length-s),f=e.subarray(e.length-s),p=a(this.options.algorithm,this.options.secret).update(d).digest();try{if(!o(f,p))throw new t({transformName:`hashing`});return n.metadata??={},n.metadata.verified_hmac=f.toString(`hex`),d}finally{p.fill(0)}}createStream(e,n){let{algorithm:l,secret:u}=this.options,d=a(l,u),f=c[l],p=r(n),m=i(n);if(e===`compress`){let e=0;return new s({construct(e){e(m<f?new t({transformName:`hashing`,stage:`output`}):void 0)},transform(n,r,i){if(n.length>p-e)return i(new t({transformName:`hashing`,stage:`input`}));if(n.length>m-f-e)return i(new t({transformName:`hashing`,stage:`output`}));e+=n.length,d.update(n),this.push(n),i()},flush(e){this.push(d.digest()),e()}})}else{let e=[],n=0;return new s({transform(r,i,a){if(r.length>p-n)return a(new t({transformName:`hashing`,stage:`input`}));n+=r.length,e.push(r),a()},flush(r){let i=Buffer.concat(e,n);e=[];let a;try{if(i.length<f)throw new t({transformName:`hashing`});let e=i.subarray(0,i.length-f);if(e.length>m)throw new t({transformName:`hashing`,stage:`output`});let n=i.subarray(i.length-f);if(d.update(e),a=d.digest(),!o(n,a))throw new t({transformName:`hashing`});let s=Buffer.from(e);i.fill(0),this.push(s),r()}catch(e){i.fill(0),r(e)}finally{a?.fill(0)}},destroy(t,n){e=[],n(t)}})}}};export{l as t};
@@ -1 +0,0 @@
1
- require(`./core-B_z1gN5W.cjs`);const e=require(`./resourceLimits-CI0Qrqdf.cjs`);let t=require(`node:crypto`),n=require(`node:stream`);const r={sha256:32,sha512:64};var i=class extends e.i{name=`hashing`;version=`3.0.0`;constructor(t){if(super(t),this.options=t,!(t.algorithm in r))throw new e.b({transformName:`hashing`,stage:`configuration`});if(!t.secret||t.secret.length<16)throw new e.c({transformName:`hashing`})}async process(n,i){let a=e.n(i),o=e.r(i),s=r[this.options.algorithm];if(n.length>a)throw new e.c({transformName:`hashing`,stage:`input`});if(n.length>o-s)throw new e.c({transformName:`hashing`,stage:`output`});i.metadata??={};let c=(0,t.createHmac)(this.options.algorithm,this.options.secret).update(n).digest();return i.metadata.hmac=c.toString(`hex`),Buffer.concat([n,c])}async reverse(n,i){let a=r[this.options.algorithm],o=e.n(i),s=e.r(i);if(n.length>o)throw new e.c({transformName:`hashing`,stage:`input`});if(n.length<a)throw new e.c({transformName:`hashing`});if(n.length-a>s)throw new e.c({transformName:`hashing`,stage:`output`});let c=n.subarray(0,n.length-a),l=n.subarray(n.length-a),u=(0,t.createHmac)(this.options.algorithm,this.options.secret).update(c).digest();try{if(!(0,t.timingSafeEqual)(l,u))throw new e.c({transformName:`hashing`});return i.metadata??={},i.metadata.verified_hmac=l.toString(`hex`),c}finally{u.fill(0)}}createStream(i,a){let{algorithm:o,secret:s}=this.options,c=(0,t.createHmac)(o,s),l=r[o],u=e.n(a),d=e.r(a);if(i===`compress`){let t=0;return new n.Transform({construct(t){t(d<l?new e.c({transformName:`hashing`,stage:`output`}):void 0)},transform(n,r,i){if(n.length>u-t)return i(new e.c({transformName:`hashing`,stage:`input`}));if(n.length>d-l-t)return i(new e.c({transformName:`hashing`,stage:`output`}));t+=n.length,c.update(n),this.push(n),i()},flush(e){this.push(c.digest()),e()}})}else{let r=[],i=0;return new n.Transform({transform(t,n,a){if(t.length>u-i)return a(new e.c({transformName:`hashing`,stage:`input`}));i+=t.length,r.push(t),a()},flush(n){let a=Buffer.concat(r,i);r=[];let o;try{if(a.length<l)throw new e.c({transformName:`hashing`});let r=a.subarray(0,a.length-l);if(r.length>d)throw new e.c({transformName:`hashing`,stage:`output`});let i=a.subarray(a.length-l);if(c.update(r),o=c.digest(),!(0,t.timingSafeEqual)(i,o))throw new e.c({transformName:`hashing`});let s=Buffer.from(r);a.fill(0),this.push(s),n()}catch(e){a.fill(0),n(e)}finally{o?.fill(0)}},destroy(e,t){r=[],t(e)}})}}};Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return i}});
@@ -1 +0,0 @@
1
- import{_ as e,f as t,g as n,h as r,i,m as a,n as o,p as s,r as c,t as l,u,x as d}from"./resourceLimits-C1HHDwXQ.mjs";import{createCipheriv as f,createDecipheriv as p,randomBytes as m}from"node:crypto";const h=[`encrypt`,`decrypt`,`generateDataKey`];function g(e){if(!e||typeof e!=`object`)throw TypeError(`[PipeX] Invalid KMS provider`);if(e.capabilities!==void 0&&(!e.capabilities||typeof e.capabilities!=`object`))throw TypeError(`[PipeX] Invalid KMS provider capabilities`);let t={};for(let n of h){let r=e.capabilities?.[n],i=typeof e[n]==`function`;if(r!==void 0&&typeof r!=`boolean`)throw new u(n,`MUST_BE_BOOLEAN`);if(r===!0&&!i)throw new u(n,`MISSING_IMPLEMENTATION`);t[n]=r??i}return Object.freeze(t)}function _(e,t){if(!h.includes(t))throw TypeError(`[PipeX] Unknown KMS operation`);return g(e)[t]}function v(e,t){if(!_(e,t))throw new d(t)}const y=Buffer.from(`PXKM`);function b(t){let r={cause:t.reason};return t.reason instanceof Error&&t.reason.name===`TimeoutError`?new e(r):new n(r)}async function x(e,t,n){if(!t)return e;if(t.aborted)throw e.then(e=>{try{n?.(e)}catch{}},()=>void 0),b(t);return new Promise((r,i)=>{let a=!1,o=()=>{a=!0,i(b(t))};t.addEventListener(`abort`,o,{once:!0}),e.then(e=>{if(t.removeEventListener(`abort`,o),a)try{n?.(e)}catch{}else r(e)},e=>{t.removeEventListener(`abort`,o),a||i(e)})})}function S(e){let t=e.limits?.operationTimeoutMs??l.operationTimeoutMs;if(!Number.isSafeInteger(t)||t<0||t>2147483647)throw Error(`[PipeX] Invalid KMS provider timeout`);if(t===0)return{signal:e.signal,cleanup(){}};let n=new AbortController,r=setTimeout(()=>{n.abort(new DOMException(`KMS provider operation timed out`,`TimeoutError`))},t);return{signal:e.signal?AbortSignal.any([e.signal,n.signal]):n.signal,cleanup(){clearTimeout(r)}}}function C(t,i){return i instanceof n||i instanceof e?i:i instanceof s?new s(t):i instanceof r?new r(t):new a(t)}async function w(e,t,n,r,i){v(e,t);let a=S(n);try{if(a.signal?.aborted)throw b(a.signal);return await x(r(a.signal),a.signal,i)}catch(e){throw a.signal?.aborted?b(a.signal):C(t,e)}finally{a.cleanup()}}var T=class extends i{name=`kms-encryption`;version=`2.1.0`;streaming=!1;get providerCapabilities(){return g(this.options.kms)}get reversible(){return this.providerCapabilities.decrypt}constructor(e){if(super(e),this.options=e,!e||!e.kms||typeof e.keyId!=`string`||e.keyId.length===0)throw Error(`[PipeX] KMS Encryption: invalid provider or keyId`);if(e.allowLegacyDecrypt!==void 0&&typeof e.allowLegacyDecrypt!=`boolean`)throw Error(`[PipeX] KMS Encryption allowLegacyDecrypt must be a boolean`);g(e.kms),v(e.kms,`generateDataKey`)}async process(e,t){let n=o(t),r=c(t),i=t.limits?.maxKmsEncryptedKeyBytes??l.maxKmsEncryptedKeyBytes,a=t.limits?.maxKmsKeyIdBytes??l.maxKmsKeyIdBytes;if(Buffer.byteLength(this.options.keyId)>a)throw Error(`[PipeX] KMS key identifier exceeds the configured limit`);if(e.length>n)throw Error(`[PipeX] KMS encryption input exceeds ${n} bytes`);if(e.length>4294967295)throw Error(`[PipeX] KMS encryption input exceeds the format limit`);if(e.length>r-45)throw Error(`[PipeX] KMS encryption output exceeds ${r} bytes`);let{kms:s,keyId:u}=this.options,d=await w(s,`generateDataKey`,t,e=>s.generateDataKey(u,{signal:e}),e=>{Buffer.isBuffer(e?.plaintext)&&e.plaintext.fill(0)}),p=d?.plaintext;try{let t=d?.ciphertext;if(!Buffer.isBuffer(p)||p.length!==32)throw Error(`[PipeX] KMS generated an invalid data key`);if(!Buffer.isBuffer(t)||t.length<1||t.length>i)throw Error(`[PipeX] KMS generated an invalid encrypted key`);let n=28+t.length+16;if(e.length>r-n)throw Error(`[PipeX] KMS encryption output exceeds ${r} bytes`);let a=n+e.length,o=m(12),s=f(`aes-256-gcm`,p,o,{authTagLength:16}),c=Buffer.alloc(28);y.copy(c,0),c.writeUInt8(1,4),c.writeUInt8(1,5),c.writeUInt16BE(0,6),c.writeUInt32BE(t.length,8),c.writeUInt32BE(e.length,12),o.copy(c,16),s.setAAD(Buffer.concat([c,t]));let l=Buffer.concat([s.update(e),s.final()]),u=s.getAuthTag();return Buffer.concat([c,t,l,u],a)}finally{Buffer.isBuffer(p)&&p.fill(0)}}async reverse(e,n){let{kms:r,keyId:i}=this.options;v(r,`decrypt`);let a=o(n),s=c(n),u=n.limits?.maxKmsEncryptedKeyBytes??l.maxKmsEncryptedKeyBytes,d=n.limits?.maxKmsKeyIdBytes??l.maxKmsKeyIdBytes;if(Buffer.byteLength(i)>d)throw Error(`[PipeX] KMS key identifier exceeds the configured limit`);if(e.length>a)throw Error(`[PipeX] KMS decryption input exceeds ${a} bytes`);if(e.length===0)throw Error(`[PipeX] KMS Decryption: Packet too short`);let f=e.length>=y.length&&e.subarray(0,y.length).equals(y);if(!f&&e.readUInt8(0)===y.readUInt8(0))throw Error(`[PipeX] KMS Decryption: incomplete framed header`);if(!f&&this.options.allowLegacyDecrypt!==!0)throw Error(`[PipeX] KMS Decryption: legacy format disabled`);let m,h,g,_,b;if(f){if(e.length<45)throw Error(`[PipeX] KMS Decryption: incomplete framed envelope`);if(e.readUInt8(4)!==1)throw Error(`[PipeX] KMS Decryption: unsupported format version`);if(e.readUInt8(5)!==1||e.readUInt16BE(6)!==0)throw Error(`[PipeX] KMS Decryption: invalid framed envelope`);let t=e.readUInt32BE(8),n=e.readUInt32BE(12);if(t<1||t>u)throw Error(`[PipeX] KMS Decryption: invalid key envelope`);if(28+t+n+16!==e.length)throw Error(`[PipeX] KMS Decryption: invalid envelope length`);if(n>s)throw Error(`[PipeX] KMS decryption output exceeds ${s} bytes`);h=e.subarray(16,28),m=e.subarray(28,28+t),_=e.subarray(28+t,e.length-16),g=e.subarray(e.length-16),b=e.subarray(0,28+t)}else{if(e.length<4)throw Error(`[PipeX] KMS Decryption: Packet too short`);let t=e.readUInt32BE(0);if(t<1||t>u||e.length<4+t+12+16)throw Error(`[PipeX] KMS Decryption: invalid key envelope`);m=e.subarray(4,4+t),h=e.subarray(4+t,4+t+12),g=e.subarray(4+t+12,4+t+12+16),_=e.subarray(4+t+12+16)}if(_.length>s)throw Error(`[PipeX] KMS decryption output exceeds ${s} bytes`);let x=await w(r,`decrypt`,n,e=>r.decrypt(m,i,{signal:e}),e=>{Buffer.isBuffer(e)&&e.fill(0)});try{if(!Buffer.isBuffer(x)||x.length!==32)throw Error(`[PipeX] KMS Decryption: invalid data key length`);let e=p(`aes-256-gcm`,x,h,{authTagLength:16});b&&e.setAAD(b),e.setAuthTag(g);let n=e.update(_);try{let t=e.final();return t.length===0?n:Buffer.concat([n,t])}catch{throw n.fill(0),new t}}finally{Buffer.isBuffer(x)&&x.fill(0)}}};export{g as n,_ as r,T as t};
@@ -1 +0,0 @@
1
- require(`./core-B_z1gN5W.cjs`);const e=require(`./resourceLimits-CI0Qrqdf.cjs`);let t=require(`node:crypto`);const n=[`encrypt`,`decrypt`,`generateDataKey`];function r(t){if(!t||typeof t!=`object`)throw TypeError(`[PipeX] Invalid KMS provider`);if(t.capabilities!==void 0&&(!t.capabilities||typeof t.capabilities!=`object`))throw TypeError(`[PipeX] Invalid KMS provider capabilities`);let r={};for(let i of n){let n=t.capabilities?.[i],a=typeof t[i]==`function`;if(n!==void 0&&typeof n!=`boolean`)throw new e.u(i,`MUST_BE_BOOLEAN`);if(n===!0&&!a)throw new e.u(i,`MISSING_IMPLEMENTATION`);r[i]=n??a}return Object.freeze(r)}function i(e,t){if(!n.includes(t))throw TypeError(`[PipeX] Unknown KMS operation`);return r(e)[t]}function a(t,n){if(!i(t,n))throw new e.x(n)}const o=Buffer.from(`PXKM`);function s(t){let n={cause:t.reason};return t.reason instanceof Error&&t.reason.name===`TimeoutError`?new e._(n):new e.g(n)}async function c(e,t,n){if(!t)return e;if(t.aborted)throw e.then(e=>{try{n?.(e)}catch{}},()=>void 0),s(t);return new Promise((r,i)=>{let a=!1,o=()=>{a=!0,i(s(t))};t.addEventListener(`abort`,o,{once:!0}),e.then(e=>{if(t.removeEventListener(`abort`,o),a)try{n?.(e)}catch{}else r(e)},e=>{t.removeEventListener(`abort`,o),a||i(e)})})}function l(t){let n=t.limits?.operationTimeoutMs??e.t.operationTimeoutMs;if(!Number.isSafeInteger(n)||n<0||n>2147483647)throw Error(`[PipeX] Invalid KMS provider timeout`);if(n===0)return{signal:t.signal,cleanup(){}};let r=new AbortController,i=setTimeout(()=>{r.abort(new DOMException(`KMS provider operation timed out`,`TimeoutError`))},n);return{signal:t.signal?AbortSignal.any([t.signal,r.signal]):r.signal,cleanup(){clearTimeout(i)}}}function u(t,n){return n instanceof e.g||n instanceof e._?n:n instanceof e.p?new e.p(t):n instanceof e.h?new e.h(t):new e.m(t)}async function d(e,t,n,r,i){a(e,t);let o=l(n);try{if(o.signal?.aborted)throw s(o.signal);return await c(r(o.signal),o.signal,i)}catch(e){throw o.signal?.aborted?s(o.signal):u(t,e)}finally{o.cleanup()}}var f=class extends e.i{name=`kms-encryption`;version=`2.1.0`;streaming=!1;get providerCapabilities(){return r(this.options.kms)}get reversible(){return this.providerCapabilities.decrypt}constructor(e){if(super(e),this.options=e,!e||!e.kms||typeof e.keyId!=`string`||e.keyId.length===0)throw Error(`[PipeX] KMS Encryption: invalid provider or keyId`);if(e.allowLegacyDecrypt!==void 0&&typeof e.allowLegacyDecrypt!=`boolean`)throw Error(`[PipeX] KMS Encryption allowLegacyDecrypt must be a boolean`);r(e.kms),a(e.kms,`generateDataKey`)}async process(n,r){let i=e.n(r),a=e.r(r),s=r.limits?.maxKmsEncryptedKeyBytes??e.t.maxKmsEncryptedKeyBytes,c=r.limits?.maxKmsKeyIdBytes??e.t.maxKmsKeyIdBytes;if(Buffer.byteLength(this.options.keyId)>c)throw Error(`[PipeX] KMS key identifier exceeds the configured limit`);if(n.length>i)throw Error(`[PipeX] KMS encryption input exceeds ${i} bytes`);if(n.length>4294967295)throw Error(`[PipeX] KMS encryption input exceeds the format limit`);if(n.length>a-45)throw Error(`[PipeX] KMS encryption output exceeds ${a} bytes`);let{kms:l,keyId:u}=this.options,f=await d(l,`generateDataKey`,r,e=>l.generateDataKey(u,{signal:e}),e=>{Buffer.isBuffer(e?.plaintext)&&e.plaintext.fill(0)}),p=f?.plaintext;try{let e=f?.ciphertext;if(!Buffer.isBuffer(p)||p.length!==32)throw Error(`[PipeX] KMS generated an invalid data key`);if(!Buffer.isBuffer(e)||e.length<1||e.length>s)throw Error(`[PipeX] KMS generated an invalid encrypted key`);let r=28+e.length+16;if(n.length>a-r)throw Error(`[PipeX] KMS encryption output exceeds ${a} bytes`);let i=r+n.length,c=(0,t.randomBytes)(12),l=(0,t.createCipheriv)(`aes-256-gcm`,p,c,{authTagLength:16}),u=Buffer.alloc(28);o.copy(u,0),u.writeUInt8(1,4),u.writeUInt8(1,5),u.writeUInt16BE(0,6),u.writeUInt32BE(e.length,8),u.writeUInt32BE(n.length,12),c.copy(u,16),l.setAAD(Buffer.concat([u,e]));let d=Buffer.concat([l.update(n),l.final()]),m=l.getAuthTag();return Buffer.concat([u,e,d,m],i)}finally{Buffer.isBuffer(p)&&p.fill(0)}}async reverse(n,r){let{kms:i,keyId:s}=this.options;a(i,`decrypt`);let c=e.n(r),l=e.r(r),u=r.limits?.maxKmsEncryptedKeyBytes??e.t.maxKmsEncryptedKeyBytes,f=r.limits?.maxKmsKeyIdBytes??e.t.maxKmsKeyIdBytes;if(Buffer.byteLength(s)>f)throw Error(`[PipeX] KMS key identifier exceeds the configured limit`);if(n.length>c)throw Error(`[PipeX] KMS decryption input exceeds ${c} bytes`);if(n.length===0)throw Error(`[PipeX] KMS Decryption: Packet too short`);let p=n.length>=o.length&&n.subarray(0,o.length).equals(o);if(!p&&n.readUInt8(0)===o.readUInt8(0))throw Error(`[PipeX] KMS Decryption: incomplete framed header`);if(!p&&this.options.allowLegacyDecrypt!==!0)throw Error(`[PipeX] KMS Decryption: legacy format disabled`);let m,h,g,_,v;if(p){if(n.length<45)throw Error(`[PipeX] KMS Decryption: incomplete framed envelope`);if(n.readUInt8(4)!==1)throw Error(`[PipeX] KMS Decryption: unsupported format version`);if(n.readUInt8(5)!==1||n.readUInt16BE(6)!==0)throw Error(`[PipeX] KMS Decryption: invalid framed envelope`);let e=n.readUInt32BE(8),t=n.readUInt32BE(12);if(e<1||e>u)throw Error(`[PipeX] KMS Decryption: invalid key envelope`);if(28+e+t+16!==n.length)throw Error(`[PipeX] KMS Decryption: invalid envelope length`);if(t>l)throw Error(`[PipeX] KMS decryption output exceeds ${l} bytes`);h=n.subarray(16,28),m=n.subarray(28,28+e),_=n.subarray(28+e,n.length-16),g=n.subarray(n.length-16),v=n.subarray(0,28+e)}else{if(n.length<4)throw Error(`[PipeX] KMS Decryption: Packet too short`);let e=n.readUInt32BE(0);if(e<1||e>u||n.length<4+e+12+16)throw Error(`[PipeX] KMS Decryption: invalid key envelope`);m=n.subarray(4,4+e),h=n.subarray(4+e,4+e+12),g=n.subarray(4+e+12,4+e+12+16),_=n.subarray(4+e+12+16)}if(_.length>l)throw Error(`[PipeX] KMS decryption output exceeds ${l} bytes`);let y=await d(i,`decrypt`,r,e=>i.decrypt(m,s,{signal:e}),e=>{Buffer.isBuffer(e)&&e.fill(0)});try{if(!Buffer.isBuffer(y)||y.length!==32)throw Error(`[PipeX] KMS Decryption: invalid data key length`);let n=(0,t.createDecipheriv)(`aes-256-gcm`,y,h,{authTagLength:16});v&&n.setAAD(v),n.setAuthTag(g);let r=n.update(_);try{let e=n.final();return e.length===0?r:Buffer.concat([r,e])}catch{throw r.fill(0),new e.f}}finally{Buffer.isBuffer(y)&&y.fill(0)}}};Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return f}});
@@ -1 +0,0 @@
1
- var e=class extends Error{name=`PipeXError`;transformName;stage;constructor(e,t,n){super(t,n),this.code=e,this.transformName=n?.transformName,this.stage=n?.stage}},t=class extends e{name=`ValidationError`;constructor(e){super(`VALIDATION_FAILED`,`[PipeX] Validation failed`,e)}},n=class extends e{name=`CompressionError`;constructor(e){super(`COMPRESSION_FAILED`,`[PipeX] Compression failed`,e)}},r=class extends e{name=`HashingError`;constructor(e){super(`HASHING_FAILED`,`[PipeX] Hashing failed`,e)}},i=class extends e{name=`UnsupportedAlgorithmError`;constructor(e){super(`UNSUPPORTED_ALGORITHM`,`[PipeX] Unsupported algorithm`,e)}},a=class extends e{name=`PipelineAbortedError`;constructor(e){super(`OPERATION_ABORTED`,`[PipeX] Operation aborted`,e)}},o=class extends e{name=`UnsupportedReverseError`;constructor(e){super(`UNSUPPORTED_REVERSE`,`[PipeX] Plugin ${e} does not support reverse operations`),this.plugin=e}},s=class extends e{name=`UnsupportedStreamingError`;constructor(e){super(`UNSUPPORTED_STREAMING`,`[PipeX] Plugin ${e} does not support stream operations`),this.plugin=e}},c=class extends e{name=`InvalidPluginCapabilityError`;constructor(e,t,n){super(`INVALID_PLUGIN_CAPABILITY`,`[PipeX] Plugin ${e} has an invalid ${t} capability: ${n===`MUST_BE_BOOLEAN`?`must be a boolean when declared`:n===`MISSING_IMPLEMENTATION`?`is declared but its implementation is missing`:`is disabled but its implementation is present`}`),this.plugin=e,this.capability=t,this.issue=n}},l=class extends a{name=`OperationAbortedError`;constructor(e){super(e)}},u=class extends e{name=`OperationTimeoutError`;constructor(e){super(`OPERATION_TIMEOUT`,`[PipeX] Operation timed out`,e)}},d=class extends e{name=`KmsProviderError`;constructor(e,t){super(`KMS_PROVIDER_FAILURE`,`[PipeX] KMS ${e} failed`,t),this.operation=e}},f=class extends e{name=`KmsAuthenticationError`;constructor(){super(`KMS_AUTHENTICATION_FAILED`,`[PipeX] KMS envelope authentication failed`)}},p=class extends e{name=`KmsProviderAuthenticationError`;constructor(e){super(`KMS_PROVIDER_AUTHENTICATION_FAILED`,`[PipeX] KMS ${e} authentication failed`),this.operation=e}},m=class extends e{name=`KmsProviderUnavailableError`;constructor(e){super(`KMS_PROVIDER_UNAVAILABLE`,`[PipeX] KMS ${e} provider unavailable`),this.operation=e}},h=class extends e{name=`UnsupportedKmsOperationError`;constructor(e){super(`UNSUPPORTED_KMS_OPERATION`,`[PipeX] KMS provider does not support ${e}`),this.operation=e}},g=class extends e{name=`InvalidKmsProviderCapabilityError`;constructor(e,t){super(`INVALID_KMS_PROVIDER_CAPABILITY`,`[PipeX] Invalid KMS ${e} capability: ${t===`MUST_BE_BOOLEAN`?`must be a boolean when declared`:`is declared but its implementation is missing`}`),this.operation=e,this.issue=t}},_=class extends e{name=`WorkerPoolClosedError`;constructor(){super(`WORKER_POOL_CLOSED`,`[PipeX] Worker pool is closed`)}},v=class extends e{name=`WorkerQueueFullError`;constructor(e){super(`WORKER_QUEUE_FULL`,`[PipeX] Worker queue is full (maximum ${e} waiting tasks)`),this.maxQueue=e}},y=class extends e{name=`WorkerPoolCloseError`;constructor(e){super(`WORKER_POOL_CLOSE_FAILURE`,`[PipeX] Worker pool failed to close cleanly`,e)}},b=class extends e{name=`WorkerTaskError`;constructor(e,t){super(`WORKER_TASK_FAILURE`,`[PipeX] Worker task ${e} failed`,t),this.taskName=e}},x=class extends e{name=`EncryptionError`;constructor(e=`[PipeX] Encryption operation failed`){super(`ENCRYPTION_ERROR`,e)}},S=class extends e{name=`InvalidKeyError`;constructor(){super(`INVALID_ENCRYPTION_KEY`,`[PipeX] Encryption key must be a 32-byte Buffer`)}},C=class extends e{name=`AuthenticationError`;constructor(){super(`ENCRYPTION_AUTHENTICATION_FAILED`,`[PipeX] Encrypted data authentication failed`)}},w=class e{retryOptions;get reversible(){return this.reverse!==e.prototype.reverse}constructor(e={}){this.options=e}reverse(e,t){throw new o(`${this.name}@${this.version}`)}};const T=Object.freeze({maxInputBytes:64*1024*1024,maxOutputBytes:256*1024*1024,maxFrameBytes:8*1024*1024,maxFrames:1e5,maxConcurrentOperations:32,operationTimeoutMs:5*6e4,maxRetryAttempts:5,maxRetryDelayMs:3e4,maxKmsEncryptedKeyBytes:64*1024,maxKmsKeyIdBytes:512});function E(e){let t=e?.limits??T;return Math.max(t.maxInputBytes,t.maxOutputBytes)}function D(e){return e?.limits?.maxOutputBytes??T.maxOutputBytes}export{s as C,v as D,_ as E,b as O,o as S,y as T,u as _,C as a,i as b,r as c,c as d,f,l as g,m as h,w as i,S as l,d as m,E as n,n as o,p,D as r,x as s,T as t,g as u,e as v,t as w,h as x,a as y};
@@ -1 +0,0 @@
1
- var e=class extends Error{name=`PipeXError`;transformName;stage;constructor(e,t,n){super(t,n),this.code=e,this.transformName=n?.transformName,this.stage=n?.stage}},t=class extends e{name=`ValidationError`;constructor(e){super(`VALIDATION_FAILED`,`[PipeX] Validation failed`,e)}},n=class extends e{name=`CompressionError`;constructor(e){super(`COMPRESSION_FAILED`,`[PipeX] Compression failed`,e)}},r=class extends e{name=`HashingError`;constructor(e){super(`HASHING_FAILED`,`[PipeX] Hashing failed`,e)}},i=class extends e{name=`UnsupportedAlgorithmError`;constructor(e){super(`UNSUPPORTED_ALGORITHM`,`[PipeX] Unsupported algorithm`,e)}},a=class extends e{name=`PipelineAbortedError`;constructor(e){super(`OPERATION_ABORTED`,`[PipeX] Operation aborted`,e)}},o=class extends e{name=`UnsupportedReverseError`;constructor(e){super(`UNSUPPORTED_REVERSE`,`[PipeX] Plugin ${e} does not support reverse operations`),this.plugin=e}},s=class extends e{name=`UnsupportedStreamingError`;constructor(e){super(`UNSUPPORTED_STREAMING`,`[PipeX] Plugin ${e} does not support stream operations`),this.plugin=e}},c=class extends e{name=`InvalidPluginCapabilityError`;constructor(e,t,n){super(`INVALID_PLUGIN_CAPABILITY`,`[PipeX] Plugin ${e} has an invalid ${t} capability: ${n===`MUST_BE_BOOLEAN`?`must be a boolean when declared`:n===`MISSING_IMPLEMENTATION`?`is declared but its implementation is missing`:`is disabled but its implementation is present`}`),this.plugin=e,this.capability=t,this.issue=n}},l=class extends a{name=`OperationAbortedError`;constructor(e){super(e)}},u=class extends e{name=`OperationTimeoutError`;constructor(e){super(`OPERATION_TIMEOUT`,`[PipeX] Operation timed out`,e)}},d=class extends e{name=`KmsProviderError`;constructor(e,t){super(`KMS_PROVIDER_FAILURE`,`[PipeX] KMS ${e} failed`,t),this.operation=e}},f=class extends e{name=`KmsAuthenticationError`;constructor(){super(`KMS_AUTHENTICATION_FAILED`,`[PipeX] KMS envelope authentication failed`)}},p=class extends e{name=`KmsProviderAuthenticationError`;constructor(e){super(`KMS_PROVIDER_AUTHENTICATION_FAILED`,`[PipeX] KMS ${e} authentication failed`),this.operation=e}},m=class extends e{name=`KmsProviderUnavailableError`;constructor(e){super(`KMS_PROVIDER_UNAVAILABLE`,`[PipeX] KMS ${e} provider unavailable`),this.operation=e}},h=class extends e{name=`UnsupportedKmsOperationError`;constructor(e){super(`UNSUPPORTED_KMS_OPERATION`,`[PipeX] KMS provider does not support ${e}`),this.operation=e}},g=class extends e{name=`InvalidKmsProviderCapabilityError`;constructor(e,t){super(`INVALID_KMS_PROVIDER_CAPABILITY`,`[PipeX] Invalid KMS ${e} capability: ${t===`MUST_BE_BOOLEAN`?`must be a boolean when declared`:`is declared but its implementation is missing`}`),this.operation=e,this.issue=t}},_=class extends e{name=`WorkerPoolClosedError`;constructor(){super(`WORKER_POOL_CLOSED`,`[PipeX] Worker pool is closed`)}},v=class extends e{name=`WorkerQueueFullError`;constructor(e){super(`WORKER_QUEUE_FULL`,`[PipeX] Worker queue is full (maximum ${e} waiting tasks)`),this.maxQueue=e}},y=class extends e{name=`WorkerPoolCloseError`;constructor(e){super(`WORKER_POOL_CLOSE_FAILURE`,`[PipeX] Worker pool failed to close cleanly`,e)}},b=class extends e{name=`WorkerTaskError`;constructor(e,t){super(`WORKER_TASK_FAILURE`,`[PipeX] Worker task ${e} failed`,t),this.taskName=e}},x=class extends e{name=`EncryptionError`;constructor(e=`[PipeX] Encryption operation failed`){super(`ENCRYPTION_ERROR`,e)}},S=class extends e{name=`InvalidKeyError`;constructor(){super(`INVALID_ENCRYPTION_KEY`,`[PipeX] Encryption key must be a 32-byte Buffer`)}},C=class extends e{name=`AuthenticationError`;constructor(){super(`ENCRYPTION_AUTHENTICATION_FAILED`,`[PipeX] Encrypted data authentication failed`)}},w=class e{retryOptions;get reversible(){return this.reverse!==e.prototype.reverse}constructor(e={}){this.options=e}reverse(e,t){throw new o(`${this.name}@${this.version}`)}};const T=Object.freeze({maxInputBytes:64*1024*1024,maxOutputBytes:256*1024*1024,maxFrameBytes:8*1024*1024,maxFrames:1e5,maxConcurrentOperations:32,operationTimeoutMs:5*6e4,maxRetryAttempts:5,maxRetryDelayMs:3e4,maxKmsEncryptedKeyBytes:64*1024,maxKmsKeyIdBytes:512});function E(e){let t=e?.limits??T;return Math.max(t.maxInputBytes,t.maxOutputBytes)}function D(e){return e?.limits?.maxOutputBytes??T.maxOutputBytes}Object.defineProperty(exports,`C`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`D`,{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,`E`,{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,`O`,{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,`S`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`T`,{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,`_`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,`b`,{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`g`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,`v`,{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,`w`,{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,`x`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`y`,{enumerable:!0,get:function(){return a}});
@@ -1 +0,0 @@
1
- import{V as e,s as t}from"./core-BOdvxKBq.mjs";import{i as n,n as r,r as i,t as a,w as o}from"./resourceLimits-C1HHDwXQ.mjs";import{Transform as s}from"node:stream";import"zod";var c=class extends n{name=`validation`;version=`1.0.0`;constructor(e){super(e),this.options=e}async process(e,t){return this.validate(e,Math.min(r(t),i(t)),t.limits?.maxFrameBytes),e}async reverse(e,t){let n=Math.min(r(t),i(t));if(e.length>n)throw new o({transformName:`validation`});return this.options.validateOnReverse&&this.validate(e,n,t.limits?.maxFrameBytes),e}validate(n,r,i=a.maxFrameBytes){if(n.length>r)throw new o({transformName:`validation`});e(n,i,1);let s;try{s=t.unpack(n)}catch{throw new o({transformName:`validation`})}if(!this.options.schema.safeParse(s).success)throw new o({transformName:`validation`})}createStream(e=`compress`,t){let n=[],a=0,c=Math.min(r(t),i(t));return new s({transform(e,t,r){if(e.length>c-a)return r(new o({transformName:`validation`}));a+=e.length,n.push(e),r()},flush:r=>{try{let i=Buffer.concat(n,a);(e!==`decompress`||this.options.validateOnReverse)&&this.validate(i,c,t?.limits?.maxFrameBytes),r(null,i)}catch(e){r(e)}}})}};export{c as t};
@@ -1 +0,0 @@
1
- const e=require(`./core-B_z1gN5W.cjs`),t=require(`./resourceLimits-CI0Qrqdf.cjs`);let n=require(`node:stream`);require(`zod`);var r=class extends t.i{name=`validation`;version=`1.0.0`;constructor(e){super(e),this.options=e}async process(e,n){return this.validate(e,Math.min(t.n(n),t.r(n)),n.limits?.maxFrameBytes),e}async reverse(e,n){let r=Math.min(t.n(n),t.r(n));if(e.length>r)throw new t.w({transformName:`validation`});return this.options.validateOnReverse&&this.validate(e,r,n.limits?.maxFrameBytes),e}validate(n,r,i=t.t.maxFrameBytes){if(n.length>r)throw new t.w({transformName:`validation`});e.V(n,i,1);let a;try{a=e.s.unpack(n)}catch{throw new t.w({transformName:`validation`})}if(!this.options.schema.safeParse(a).success)throw new t.w({transformName:`validation`})}createStream(e=`compress`,r){let i=[],a=0,o=Math.min(t.n(r),t.r(r));return new n.Transform({transform(e,n,r){if(e.length>o-a)return r(new t.w({transformName:`validation`}));a+=e.length,i.push(e),r()},flush:t=>{try{let n=Buffer.concat(i,a);(e!==`decompress`||this.options.validateOnReverse)&&this.validate(n,o,r?.limits?.maxFrameBytes),t(null,n)}catch(e){t(e)}}})}};Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return r}});
@@ -1 +0,0 @@
1
- require(`./core-B_z1gN5W.cjs`);const e=require(`./resourceLimits-CI0Qrqdf.cjs`);let t=require(`node:stream`),n=require(`node:url`),r=require(`node:os`),i=require(`piscina`);const a=2147483647,o=1e5,s=Math.max(1,Math.min(4,(0,r.availableParallelism)()));function c(e,t,n=!1){if(e!==void 0&&(!Number.isSafeInteger(e)||e<+!n))throw Error(`[PipeX] Worker pool ${t} must be ${n?`a non-negative`:`a positive`} integer`)}function l(t,n){let r=n??t.limits?.operationTimeoutMs??e.t.operationTimeoutMs;if(!Number.isSafeInteger(r)||r<0||r>a)throw Error(`[PipeX] Invalid worker task timeout`);if(r===0)return{signal:t.signal,cleanup(){}};let i=new AbortController,o=setTimeout(()=>{i.abort(new DOMException(`Worker task timed out`,`TimeoutError`))},r);return o.unref(),{signal:t.signal?AbortSignal.any([t.signal,i.signal]):i.signal,cleanup(){clearTimeout(o)}}}function u(t){return t.reason instanceof Error&&t.reason.name===`TimeoutError`?new e._({cause:t.reason}):new e.g({cause:t.reason})}var d=class extends e.i{name=`worker-pool`;version=`5.0.0`;#e;#t;#n;#r;#i;#a;#o;#s;#c;#l=!0;#u=0;#d;#f;#p=new Set;#m;constructor(t){if(super(t),!t||!(typeof t.filename==`string`||t.filename instanceof URL))throw Error(`[PipeX] Worker pool requires a worker filename`);if(c(t.maxThreads,`maxThreads`),c(t.maxQueue,`maxQueue`),c(t.taskTimeoutMs,`taskTimeoutMs`,!0),c(t.closeTimeoutMs,`closeTimeoutMs`,!0),t.maxThreads!==void 0&&t.maxThreads>128)throw Error(`[PipeX] Worker pool maxThreads cannot exceed 128`);if(t.maxQueue!==void 0&&t.maxQueue>o)throw Error(`[PipeX] Worker pool maxQueue cannot exceed ${o}`);if(t.taskTimeoutMs!==void 0&&t.taskTimeoutMs>a)throw Error(`[PipeX] Worker pool taskTimeoutMs exceeds the supported timer range`);if(t.closeTimeoutMs!==void 0&&t.closeTimeoutMs>a)throw Error(`[PipeX] Worker pool closeTimeoutMs exceeds the supported timer range`);for(let[e,n]of[[`processName`,t.processName],[`reverseName`,t.reverseName]])if(n!==void 0&&(typeof n!=`string`||n.length===0||n.length>128))throw Error(`[PipeX] Worker pool ${e} must be a non-empty export name`);let r=t.filename instanceof URL?(0,n.fileURLToPath)(t.filename):t.filename;this.#t=t.processName,this.#n=t.reverseName,this.#r=t.taskTimeoutMs,this.#i=t.maxThreads??s,this.#a=t.maxQueue??64,this.#o=this.#i+this.#a,this.#s=t.closeTimeoutMs??3e4,this.#c=!!t.reverseName,this.#e=new i.Piscina({filename:r,minThreads:0,maxThreads:this.#i,maxQueue:this.#a,closeTimeout:this.#s}),this.#m=t=>{this.#f||(this.#f=new e.O(`worker-thread`,{cause:t}),this.#l=!1,this.#e.destroy().catch(()=>void 0))},this.#e.on(`error`,this.#m)}get reversible(){return this.#c}async#h(t,n,r){if(this.#f)throw this.#f;if(!this.#l)throw new e.E;let i=e.n(n);if(t.length>i)throw Error(`[PipeX] Worker input exceeds ${i} bytes`);if(this.#u>=this.#o)throw new e.D(this.#a);let a=l(n,this.#r);this.#u++;try{a.signal?.throwIfAborted();let i=t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength),o=await this.#e.run(i,{transferList:[i],signal:a.signal,name:r});if(!(o instanceof ArrayBuffer)&&!ArrayBuffer.isView(o))throw Error(`worker returned a non-binary value`);let s=o instanceof ArrayBuffer?Buffer.from(o):Buffer.from(o.buffer,o.byteOffset,o.byteLength),c=e.r(n);if(s.length>c)throw Error(`[PipeX] Worker output exceeds ${c} bytes`);return s}catch(t){throw a.signal?.aborted?u(a.signal):t instanceof e.E||t instanceof e.D?t:t instanceof Error&&(t.message===`Task queue is at limit`||t.message===`No task queue available and all Workers are busy`)?new e.D(this.#a):new e.O(r??`default`,{cause:t})}finally{if(a.cleanup(),this.#u--,this.#u===0){for(let e of this.#p)e();this.#p.clear()}}}process(e,t){return this.#h(e,t,this.#t)}reverse(t,n){if(!this.#n)throw new e.S(`${this.name}@${this.version}`);return this.#h(t,n,this.#n)}createStream(n,r){if(n===`decompress`&&!this.#n)throw new e.S(this.name);let i=new AbortController,a=r?.signal?AbortSignal.any([r.signal,i.signal]):i.signal,o=r?.limits??e.t,s=Math.min(o.maxFrameBytes,4294967294),c=Buffer.from([80,88,87,75,1]),l=Buffer.from([255,255,255,255]),u=0,d=0,f=0,p=!1,m=!1,h=Buffer.alloc(c.length),g=0,_,v=0,y=this,b=(e,t)=>{if(t.length>o.maxOutputBytes-d)throw Error(`[PipeX] Worker stream output exceeds configured limit`);d+=t.length,e.push(t)},x=async e=>{if(++f>o.maxFrames)throw Error(`[PipeX] Worker frame count exceeds configured limit`);let t={requestId:r?.requestId??`worker-stream`,timestamp:Date.now(),signal:a,limits:o,logger:r?.logger,metadata:{}},i=n===`decompress`?y.reverse(e,t):y.process(e,t);r?.track?.(i);let c=await i;if(a.throwIfAborted(),c.length>s)throw Error(`[PipeX] Worker frame exceeds configured limit`);return c};return new t.Transform({transform(t,i,o){let l=this;(async()=>{if(a.throwIfAborted(),t.length>e.n(r)-u)throw Error(`[PipeX] Worker stream input exceeds configured limit`);if(u+=t.length,n===`compress`){p||=(b(l,c),!0);for(let e=0;e<t.length;e+=s){let n=await x(t.subarray(e,e+s)),r=Buffer.alloc(4);r.writeUInt32BE(n.length),b(l,r),b(l,n)}return}let i=0;for(;i<t.length;){if(m)throw Error(`[PipeX] Worker stream has trailing bytes`);if(!_){let e=Math.min(h.length-g,t.length-i);if(t.copy(h,g,i,i+e),g+=e,i+=e,g!==h.length)continue;if(!p){if(!h.equals(c))throw Error(`[PipeX] Invalid worker stream format`);p=!0,h=Buffer.alloc(4),g=0;continue}let n=h.readUInt32BE();if(g=0,n===4294967295){m=!0;continue}if(n>s)throw Error(`[PipeX] Worker frame exceeds configured limit`);_=Buffer.alloc(n),v=0}let e=Math.min(_.length-v,t.length-i);t.copy(_,v,i,i+e),v+=e,i+=e,v===_.length&&(b(l,await x(_)),_=void 0,v=0)}})().then(()=>o(),e=>o(e))},flush(e){try{if(a.throwIfAborted(),n===`compress`)p||b(this,c),b(this,l);else if(!m||_||g)throw Error(`[PipeX] Incomplete worker stream`);e()}catch(t){e(t)}},destroy(e,t){a.aborted||i.abort(e??new DOMException(`Worker stream destroyed`,`AbortError`)),_=void 0,t(e)}})}async close(t={}){if(!t||t.force!==void 0&&typeof t.force!=`boolean`)throw TypeError(`[PipeX] Worker pool close force must be a boolean`);return this.#d?this.#d:(this.#l=!1,this.#d=(async()=>{try{if(this.#f)await this.#e.destroy();else if(t.force)await this.#e.destroy();else if(this.#u>0&&await new Promise((t,n)=>{let r=()=>{clearTimeout(i),t()},i=setTimeout(()=>{this.#p.delete(r),n(new e.T)},this.#s);this.#p.add(r)}),await this.#e.close({force:!1}),this.#f)throw this.#f}catch(t){throw await this.#e.destroy().catch(()=>void 0),t instanceof e.T?t:new e.T({cause:t})}finally{this.#e.removeListener(`error`,this.#m)}})(),this.#d)}};Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return d}});
@@ -1 +0,0 @@
1
- import{D as e,E as t,O as n,S as r,T as i,_ as a,g as o,i as s,n as c,r as l,t as u}from"./resourceLimits-C1HHDwXQ.mjs";import{Transform as d}from"node:stream";import{fileURLToPath as f}from"node:url";import{availableParallelism as p}from"node:os";import{Piscina as m}from"piscina";const h=2147483647,g=1e5,_=Math.max(1,Math.min(4,p()));function v(e,t,n=!1){if(e!==void 0&&(!Number.isSafeInteger(e)||e<+!n))throw Error(`[PipeX] Worker pool ${t} must be ${n?`a non-negative`:`a positive`} integer`)}function y(e,t){let n=t??e.limits?.operationTimeoutMs??u.operationTimeoutMs;if(!Number.isSafeInteger(n)||n<0||n>h)throw Error(`[PipeX] Invalid worker task timeout`);if(n===0)return{signal:e.signal,cleanup(){}};let r=new AbortController,i=setTimeout(()=>{r.abort(new DOMException(`Worker task timed out`,`TimeoutError`))},n);return i.unref(),{signal:e.signal?AbortSignal.any([e.signal,r.signal]):r.signal,cleanup(){clearTimeout(i)}}}function b(e){return e.reason instanceof Error&&e.reason.name===`TimeoutError`?new a({cause:e.reason}):new o({cause:e.reason})}var x=class extends s{name=`worker-pool`;version=`5.0.0`;#e;#t;#n;#r;#i;#a;#o;#s;#c;#l=!0;#u=0;#d;#f;#p=new Set;#m;constructor(e){if(super(e),!e||!(typeof e.filename==`string`||e.filename instanceof URL))throw Error(`[PipeX] Worker pool requires a worker filename`);if(v(e.maxThreads,`maxThreads`),v(e.maxQueue,`maxQueue`),v(e.taskTimeoutMs,`taskTimeoutMs`,!0),v(e.closeTimeoutMs,`closeTimeoutMs`,!0),e.maxThreads!==void 0&&e.maxThreads>128)throw Error(`[PipeX] Worker pool maxThreads cannot exceed 128`);if(e.maxQueue!==void 0&&e.maxQueue>g)throw Error(`[PipeX] Worker pool maxQueue cannot exceed ${g}`);if(e.taskTimeoutMs!==void 0&&e.taskTimeoutMs>h)throw Error(`[PipeX] Worker pool taskTimeoutMs exceeds the supported timer range`);if(e.closeTimeoutMs!==void 0&&e.closeTimeoutMs>h)throw Error(`[PipeX] Worker pool closeTimeoutMs exceeds the supported timer range`);for(let[t,n]of[[`processName`,e.processName],[`reverseName`,e.reverseName]])if(n!==void 0&&(typeof n!=`string`||n.length===0||n.length>128))throw Error(`[PipeX] Worker pool ${t} must be a non-empty export name`);let t=e.filename instanceof URL?f(e.filename):e.filename;this.#t=e.processName,this.#n=e.reverseName,this.#r=e.taskTimeoutMs,this.#i=e.maxThreads??_,this.#a=e.maxQueue??64,this.#o=this.#i+this.#a,this.#s=e.closeTimeoutMs??3e4,this.#c=!!e.reverseName,this.#e=new m({filename:t,minThreads:0,maxThreads:this.#i,maxQueue:this.#a,closeTimeout:this.#s}),this.#m=e=>{this.#f||(this.#f=new n(`worker-thread`,{cause:e}),this.#l=!1,this.#e.destroy().catch(()=>void 0))},this.#e.on(`error`,this.#m)}get reversible(){return this.#c}async#h(r,i,a){if(this.#f)throw this.#f;if(!this.#l)throw new t;let o=c(i);if(r.length>o)throw Error(`[PipeX] Worker input exceeds ${o} bytes`);if(this.#u>=this.#o)throw new e(this.#a);let s=y(i,this.#r);this.#u++;try{s.signal?.throwIfAborted();let e=r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength),t=await this.#e.run(e,{transferList:[e],signal:s.signal,name:a});if(!(t instanceof ArrayBuffer)&&!ArrayBuffer.isView(t))throw Error(`worker returned a non-binary value`);let n=t instanceof ArrayBuffer?Buffer.from(t):Buffer.from(t.buffer,t.byteOffset,t.byteLength),o=l(i);if(n.length>o)throw Error(`[PipeX] Worker output exceeds ${o} bytes`);return n}catch(r){throw s.signal?.aborted?b(s.signal):r instanceof t||r instanceof e?r:r instanceof Error&&(r.message===`Task queue is at limit`||r.message===`No task queue available and all Workers are busy`)?new e(this.#a):new n(a??`default`,{cause:r})}finally{if(s.cleanup(),this.#u--,this.#u===0){for(let e of this.#p)e();this.#p.clear()}}}process(e,t){return this.#h(e,t,this.#t)}reverse(e,t){if(!this.#n)throw new r(`${this.name}@${this.version}`);return this.#h(e,t,this.#n)}createStream(e,t){if(e===`decompress`&&!this.#n)throw new r(this.name);let n=new AbortController,i=t?.signal?AbortSignal.any([t.signal,n.signal]):n.signal,a=t?.limits??u,o=Math.min(a.maxFrameBytes,4294967294),s=Buffer.from([80,88,87,75,1]),l=Buffer.from([255,255,255,255]),f=0,p=0,m=0,h=!1,g=!1,_=Buffer.alloc(s.length),v=0,y,b=0,x=this,S=(e,t)=>{if(t.length>a.maxOutputBytes-p)throw Error(`[PipeX] Worker stream output exceeds configured limit`);p+=t.length,e.push(t)},C=async n=>{if(++m>a.maxFrames)throw Error(`[PipeX] Worker frame count exceeds configured limit`);let r={requestId:t?.requestId??`worker-stream`,timestamp:Date.now(),signal:i,limits:a,logger:t?.logger,metadata:{}},s=e===`decompress`?x.reverse(n,r):x.process(n,r);t?.track?.(s);let c=await s;if(i.throwIfAborted(),c.length>o)throw Error(`[PipeX] Worker frame exceeds configured limit`);return c};return new d({transform(n,r,a){let l=this;(async()=>{if(i.throwIfAborted(),n.length>c(t)-f)throw Error(`[PipeX] Worker stream input exceeds configured limit`);if(f+=n.length,e===`compress`){h||=(S(l,s),!0);for(let e=0;e<n.length;e+=o){let t=await C(n.subarray(e,e+o)),r=Buffer.alloc(4);r.writeUInt32BE(t.length),S(l,r),S(l,t)}return}let r=0;for(;r<n.length;){if(g)throw Error(`[PipeX] Worker stream has trailing bytes`);if(!y){let e=Math.min(_.length-v,n.length-r);if(n.copy(_,v,r,r+e),v+=e,r+=e,v!==_.length)continue;if(!h){if(!_.equals(s))throw Error(`[PipeX] Invalid worker stream format`);h=!0,_=Buffer.alloc(4),v=0;continue}let t=_.readUInt32BE();if(v=0,t===4294967295){g=!0;continue}if(t>o)throw Error(`[PipeX] Worker frame exceeds configured limit`);y=Buffer.alloc(t),b=0}let e=Math.min(y.length-b,n.length-r);n.copy(y,b,r,r+e),b+=e,r+=e,b===y.length&&(S(l,await C(y)),y=void 0,b=0)}})().then(()=>a(),e=>a(e))},flush(t){try{if(i.throwIfAborted(),e===`compress`)h||S(this,s),S(this,l);else if(!g||y||v)throw Error(`[PipeX] Incomplete worker stream`);t()}catch(e){t(e)}},destroy(e,t){i.aborted||n.abort(e??new DOMException(`Worker stream destroyed`,`AbortError`)),y=void 0,t(e)}})}async close(e={}){if(!e||e.force!==void 0&&typeof e.force!=`boolean`)throw TypeError(`[PipeX] Worker pool close force must be a boolean`);return this.#d?this.#d:(this.#l=!1,this.#d=(async()=>{try{if(this.#f)await this.#e.destroy();else if(e.force)await this.#e.destroy();else if(this.#u>0&&await new Promise((e,t)=>{let n=()=>{clearTimeout(r),e()},r=setTimeout(()=>{this.#p.delete(n),t(new i)},this.#s);this.#p.add(n)}),await this.#e.close({force:!1}),this.#f)throw this.#f}catch(e){throw await this.#e.destroy().catch(()=>void 0),e instanceof i?e:new i({cause:e})}finally{this.#e.removeListener(`error`,this.#m)}})(),this.#d)}};export{x as t};