@snyxex/pipex 0.0.0-stage → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/LICENSE +21 -0
- package/README.md +319 -2
- package/dist/compression-2mm0MhWY.mjs +1 -0
- package/dist/compression-CtrHxa9G.d.mts +38 -0
- package/dist/compression-DnVFu8TM.d.cts +38 -0
- package/dist/compression-DrgzribA.cjs +1 -0
- package/dist/compression.cjs +1 -0
- package/dist/compression.d.cts +2 -0
- package/dist/compression.d.mts +2 -0
- package/dist/compression.mjs +1 -0
- package/dist/core-BOdvxKBq.mjs +2 -0
- package/dist/core-B_z1gN5W.cjs +2 -0
- package/dist/dataEngine-4m6GTOLe.mjs +1 -0
- package/dist/dataEngine-Bvl6amzP.cjs +1 -0
- package/dist/dataEngine-D-fIXgE7.d.cts +232 -0
- package/dist/dataEngine-DUEmWp7a.d.mts +232 -0
- package/dist/encryption-BmmNECIc.d.cts +44 -0
- package/dist/encryption-CnSL1BEY.d.mts +44 -0
- package/dist/encryption-CqxtoqAD.mjs +1 -0
- package/dist/encryption-DdP1zFYl.cjs +1 -0
- package/dist/encryption.cjs +1 -0
- package/dist/encryption.d.cts +2 -0
- package/dist/encryption.d.mts +2 -0
- package/dist/encryption.mjs +1 -0
- package/dist/hashing-B6xGcbQR.d.mts +33 -0
- package/dist/hashing-ChrADfcH.mjs +1 -0
- package/dist/hashing-JtOHPybU.cjs +1 -0
- package/dist/hashing-LY-8x66g.d.cts +33 -0
- package/dist/hashing.cjs +1 -0
- package/dist/hashing.d.cts +2 -0
- package/dist/hashing.d.mts +2 -0
- package/dist/hashing.mjs +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +302 -0
- package/dist/index.d.mts +302 -0
- package/dist/index.mjs +1 -0
- package/dist/kms.cjs +1 -0
- package/dist/kms.d.cts +3 -0
- package/dist/kms.d.mts +3 -0
- package/dist/kms.mjs +1 -0
- package/dist/kms_encryption-Da-KqjKI.d.mts +33 -0
- package/dist/kms_encryption-Dh1LEHhk.d.cts +33 -0
- package/dist/kms_encryption-R9auKGW4.mjs +1 -0
- package/dist/kms_encryption-xyWi65rZ.cjs +1 -0
- package/dist/native.cjs +1 -0
- package/dist/native.d.cts +2 -0
- package/dist/native.d.mts +2 -0
- package/dist/native.mjs +1 -0
- package/dist/parallel.cjs +1 -0
- package/dist/parallel.d.cts +2 -0
- package/dist/parallel.d.mts +2 -0
- package/dist/parallel.mjs +1 -0
- package/dist/plugin-C9Kd9coY.d.cts +16 -0
- package/dist/plugin-CE94-p8P.d.mts +16 -0
- package/dist/resourceLimits-C1HHDwXQ.mjs +1 -0
- package/dist/resourceLimits-CI0Qrqdf.cjs +1 -0
- package/dist/types-Bytga6zd.d.mts +155 -0
- package/dist/types-ia4x-Dvp.d.cts +155 -0
- package/dist/validation-CqmhNHdW.d.cts +32 -0
- package/dist/validation-D17IkoHy.d.mts +32 -0
- package/dist/validation-P5WRSAUK.mjs +1 -0
- package/dist/validation-pEeJmCad.cjs +1 -0
- package/dist/validation.cjs +1 -0
- package/dist/validation.d.cts +2 -0
- package/dist/validation.d.mts +2 -0
- package/dist/validation.mjs +1 -0
- package/dist/worker-CbuCpSNc.d.cts +37 -0
- package/dist/worker-CgCC-BWG.d.mts +37 -0
- package/dist/worker-I_kqxWeK.cjs +1 -0
- package/dist/worker-c0_VZ9c7.mjs +1 -0
- package/package.json +188 -4
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { Duplex, Writable } from "node:stream";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/core/types.d.ts
|
|
5
|
+
interface Logger {
|
|
6
|
+
info(message: string, context?: Record<string, unknown>): void;
|
|
7
|
+
warn(message: string, context?: Record<string, unknown>): void;
|
|
8
|
+
error(message: string, context?: Record<string, unknown>): void;
|
|
9
|
+
debug(message: string, context?: Record<string, unknown>): void;
|
|
10
|
+
}
|
|
11
|
+
interface Span {
|
|
12
|
+
setAttribute(key: string, value: unknown): this;
|
|
13
|
+
addEvent(name: string, attributes?: Record<string, unknown>): this;
|
|
14
|
+
end(): void;
|
|
15
|
+
}
|
|
16
|
+
interface Tracer {
|
|
17
|
+
startSpan(name: string, context?: ProcessorContext): Span;
|
|
18
|
+
}
|
|
19
|
+
interface RetryOptions {
|
|
20
|
+
attempts: number;
|
|
21
|
+
backoff: 'exponential' | 'fixed';
|
|
22
|
+
delayMs: number;
|
|
23
|
+
}
|
|
24
|
+
interface EngineLimits {
|
|
25
|
+
maxInputBytes: number;
|
|
26
|
+
maxOutputBytes: number;
|
|
27
|
+
maxFrameBytes: number;
|
|
28
|
+
maxFrames: number;
|
|
29
|
+
maxConcurrentOperations: number;
|
|
30
|
+
operationTimeoutMs: number;
|
|
31
|
+
maxRetryAttempts: number;
|
|
32
|
+
maxRetryDelayMs: number;
|
|
33
|
+
/** Maximum provider-wrapped data-key bytes accepted in a KMS envelope. */
|
|
34
|
+
maxKmsEncryptedKeyBytes: number;
|
|
35
|
+
/** Maximum UTF-8 bytes accepted for a provider key identifier. */
|
|
36
|
+
maxKmsKeyIdBytes: number;
|
|
37
|
+
}
|
|
38
|
+
interface OperationOptions {
|
|
39
|
+
signal?: AbortSignal;
|
|
40
|
+
timeoutMs?: number;
|
|
41
|
+
}
|
|
42
|
+
/** expectedType must come from trusted application configuration, never the received result. */
|
|
43
|
+
interface BinaryUndoOptions extends OperationOptions {
|
|
44
|
+
expectedType?: string;
|
|
45
|
+
}
|
|
46
|
+
interface StreamPluginContext {
|
|
47
|
+
/** Engine-owned accounting for work that continues after cancellation. */
|
|
48
|
+
readonly track?: (pending: Promise<unknown>) => void;
|
|
49
|
+
readonly requestId: string;
|
|
50
|
+
readonly signal: AbortSignal;
|
|
51
|
+
readonly limits: Readonly<EngineLimits>;
|
|
52
|
+
readonly logger?: Logger;
|
|
53
|
+
readonly tracer?: Tracer;
|
|
54
|
+
}
|
|
55
|
+
interface AuditRecord {
|
|
56
|
+
requestId: string;
|
|
57
|
+
operation: 'pack' | 'unpack' | 'process' | 'reverse';
|
|
58
|
+
pluginChain: string[];
|
|
59
|
+
timestamp: number;
|
|
60
|
+
metadata: Record<string, unknown>;
|
|
61
|
+
}
|
|
62
|
+
interface AuditLogger {
|
|
63
|
+
log(record: AuditRecord): void | Promise<void>;
|
|
64
|
+
}
|
|
65
|
+
type KmsOperation = 'encrypt' | 'decrypt' | 'generateDataKey';
|
|
66
|
+
interface KmsProviderCapabilities {
|
|
67
|
+
readonly encrypt: boolean;
|
|
68
|
+
readonly decrypt: boolean;
|
|
69
|
+
readonly generateDataKey: boolean;
|
|
70
|
+
}
|
|
71
|
+
interface KmsProvider {
|
|
72
|
+
/** Explicit false disables an operation even when a compatibility stub exists. */
|
|
73
|
+
readonly capabilities?: Partial<KmsProviderCapabilities>;
|
|
74
|
+
encrypt?(data: Buffer, keyId: string, options?: KmsRequestOptions): Promise<Buffer>;
|
|
75
|
+
decrypt?(data: Buffer, keyId: string, options?: KmsRequestOptions): Promise<Buffer>;
|
|
76
|
+
generateDataKey?(keyId: string, options?: KmsRequestOptions): Promise<{
|
|
77
|
+
plaintext: Buffer;
|
|
78
|
+
ciphertext: Buffer;
|
|
79
|
+
}>;
|
|
80
|
+
}
|
|
81
|
+
interface KmsRequestOptions {
|
|
82
|
+
signal?: AbortSignal;
|
|
83
|
+
}
|
|
84
|
+
interface SchemaRegistry {
|
|
85
|
+
getSchema(subject: string, version?: number): Promise<z.ZodType<any>>;
|
|
86
|
+
}
|
|
87
|
+
interface EngineConfig {
|
|
88
|
+
plugins?: {
|
|
89
|
+
name: string;
|
|
90
|
+
options?: unknown;
|
|
91
|
+
}[];
|
|
92
|
+
limits?: Partial<EngineLimits>;
|
|
93
|
+
logger?: Logger;
|
|
94
|
+
tracer?: Tracer;
|
|
95
|
+
auditLogger?: AuditLogger;
|
|
96
|
+
/** Optional caller-owned failure sink; `dlq` is retained for compatibility. */
|
|
97
|
+
dlq?: Writable;
|
|
98
|
+
schema?: z.ZodType<any>;
|
|
99
|
+
schemaRegistry?: SchemaRegistry;
|
|
100
|
+
}
|
|
101
|
+
interface ProcessorContext {
|
|
102
|
+
readonly requestId: string;
|
|
103
|
+
readonly timestamp: number;
|
|
104
|
+
readonly signal?: AbortSignal;
|
|
105
|
+
readonly limits?: Readonly<EngineLimits>;
|
|
106
|
+
metadata: Record<string, unknown>;
|
|
107
|
+
logger?: Logger;
|
|
108
|
+
span?: Span;
|
|
109
|
+
}
|
|
110
|
+
interface ProcessorPlugin {
|
|
111
|
+
readonly name: string;
|
|
112
|
+
readonly version: string;
|
|
113
|
+
readonly reversible?: boolean;
|
|
114
|
+
readonly streaming?: boolean;
|
|
115
|
+
process(data: Buffer, ctx: ProcessorContext): Promise<Buffer> | Buffer;
|
|
116
|
+
reverse?(data: Buffer, ctx: ProcessorContext): Promise<Buffer> | Buffer;
|
|
117
|
+
createStream?(mode: 'compress' | 'decompress', context?: StreamPluginContext): Duplex;
|
|
118
|
+
retryOptions?: RetryOptions;
|
|
119
|
+
}
|
|
120
|
+
type PluginOperation = 'process' | 'reverse' | 'stream';
|
|
121
|
+
/** Normalized, runtime-validated operations exposed by a plugin. */
|
|
122
|
+
interface PluginCapabilities {
|
|
123
|
+
readonly process: true;
|
|
124
|
+
readonly reverse: boolean;
|
|
125
|
+
readonly streaming: boolean;
|
|
126
|
+
readonly streamMode: 'native' | 'fallback' | 'none';
|
|
127
|
+
}
|
|
128
|
+
/** Capability view for a plugin registered with a DataEngine. */
|
|
129
|
+
interface RegisteredPluginCapabilities extends PluginCapabilities {
|
|
130
|
+
readonly plugin: string;
|
|
131
|
+
}
|
|
132
|
+
interface EngineResult {
|
|
133
|
+
readonly data: Buffer;
|
|
134
|
+
readonly originalType: string;
|
|
135
|
+
readonly pipeline: string[];
|
|
136
|
+
readonly metrics: {
|
|
137
|
+
durationMs: number;
|
|
138
|
+
steps: Record<string, number>;
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
interface PipeXManifest {
|
|
142
|
+
readonly __pipex_v: 1;
|
|
143
|
+
readonly plugins: string[];
|
|
144
|
+
readonly ts: number;
|
|
145
|
+
}
|
|
146
|
+
declare function isManifest(value: unknown): value is PipeXManifest;
|
|
147
|
+
interface EngineEvents {
|
|
148
|
+
start: [requestId: string];
|
|
149
|
+
'plugin:after': [name: string, durationMs: number];
|
|
150
|
+
progress: [bytes: number, requestId: string];
|
|
151
|
+
error: [err: Error, requestId: string];
|
|
152
|
+
end: [requestId: string, durationMs: number];
|
|
153
|
+
}
|
|
154
|
+
//#endregion
|
|
155
|
+
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,155 @@
|
|
|
1
|
+
import { Duplex, Writable } from "node:stream";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/core/types.d.ts
|
|
5
|
+
interface Logger {
|
|
6
|
+
info(message: string, context?: Record<string, unknown>): void;
|
|
7
|
+
warn(message: string, context?: Record<string, unknown>): void;
|
|
8
|
+
error(message: string, context?: Record<string, unknown>): void;
|
|
9
|
+
debug(message: string, context?: Record<string, unknown>): void;
|
|
10
|
+
}
|
|
11
|
+
interface Span {
|
|
12
|
+
setAttribute(key: string, value: unknown): this;
|
|
13
|
+
addEvent(name: string, attributes?: Record<string, unknown>): this;
|
|
14
|
+
end(): void;
|
|
15
|
+
}
|
|
16
|
+
interface Tracer {
|
|
17
|
+
startSpan(name: string, context?: ProcessorContext): Span;
|
|
18
|
+
}
|
|
19
|
+
interface RetryOptions {
|
|
20
|
+
attempts: number;
|
|
21
|
+
backoff: 'exponential' | 'fixed';
|
|
22
|
+
delayMs: number;
|
|
23
|
+
}
|
|
24
|
+
interface EngineLimits {
|
|
25
|
+
maxInputBytes: number;
|
|
26
|
+
maxOutputBytes: number;
|
|
27
|
+
maxFrameBytes: number;
|
|
28
|
+
maxFrames: number;
|
|
29
|
+
maxConcurrentOperations: number;
|
|
30
|
+
operationTimeoutMs: number;
|
|
31
|
+
maxRetryAttempts: number;
|
|
32
|
+
maxRetryDelayMs: number;
|
|
33
|
+
/** Maximum provider-wrapped data-key bytes accepted in a KMS envelope. */
|
|
34
|
+
maxKmsEncryptedKeyBytes: number;
|
|
35
|
+
/** Maximum UTF-8 bytes accepted for a provider key identifier. */
|
|
36
|
+
maxKmsKeyIdBytes: number;
|
|
37
|
+
}
|
|
38
|
+
interface OperationOptions {
|
|
39
|
+
signal?: AbortSignal;
|
|
40
|
+
timeoutMs?: number;
|
|
41
|
+
}
|
|
42
|
+
/** expectedType must come from trusted application configuration, never the received result. */
|
|
43
|
+
interface BinaryUndoOptions extends OperationOptions {
|
|
44
|
+
expectedType?: string;
|
|
45
|
+
}
|
|
46
|
+
interface StreamPluginContext {
|
|
47
|
+
/** Engine-owned accounting for work that continues after cancellation. */
|
|
48
|
+
readonly track?: (pending: Promise<unknown>) => void;
|
|
49
|
+
readonly requestId: string;
|
|
50
|
+
readonly signal: AbortSignal;
|
|
51
|
+
readonly limits: Readonly<EngineLimits>;
|
|
52
|
+
readonly logger?: Logger;
|
|
53
|
+
readonly tracer?: Tracer;
|
|
54
|
+
}
|
|
55
|
+
interface AuditRecord {
|
|
56
|
+
requestId: string;
|
|
57
|
+
operation: 'pack' | 'unpack' | 'process' | 'reverse';
|
|
58
|
+
pluginChain: string[];
|
|
59
|
+
timestamp: number;
|
|
60
|
+
metadata: Record<string, unknown>;
|
|
61
|
+
}
|
|
62
|
+
interface AuditLogger {
|
|
63
|
+
log(record: AuditRecord): void | Promise<void>;
|
|
64
|
+
}
|
|
65
|
+
type KmsOperation = 'encrypt' | 'decrypt' | 'generateDataKey';
|
|
66
|
+
interface KmsProviderCapabilities {
|
|
67
|
+
readonly encrypt: boolean;
|
|
68
|
+
readonly decrypt: boolean;
|
|
69
|
+
readonly generateDataKey: boolean;
|
|
70
|
+
}
|
|
71
|
+
interface KmsProvider {
|
|
72
|
+
/** Explicit false disables an operation even when a compatibility stub exists. */
|
|
73
|
+
readonly capabilities?: Partial<KmsProviderCapabilities>;
|
|
74
|
+
encrypt?(data: Buffer, keyId: string, options?: KmsRequestOptions): Promise<Buffer>;
|
|
75
|
+
decrypt?(data: Buffer, keyId: string, options?: KmsRequestOptions): Promise<Buffer>;
|
|
76
|
+
generateDataKey?(keyId: string, options?: KmsRequestOptions): Promise<{
|
|
77
|
+
plaintext: Buffer;
|
|
78
|
+
ciphertext: Buffer;
|
|
79
|
+
}>;
|
|
80
|
+
}
|
|
81
|
+
interface KmsRequestOptions {
|
|
82
|
+
signal?: AbortSignal;
|
|
83
|
+
}
|
|
84
|
+
interface SchemaRegistry {
|
|
85
|
+
getSchema(subject: string, version?: number): Promise<z.ZodType<any>>;
|
|
86
|
+
}
|
|
87
|
+
interface EngineConfig {
|
|
88
|
+
plugins?: {
|
|
89
|
+
name: string;
|
|
90
|
+
options?: unknown;
|
|
91
|
+
}[];
|
|
92
|
+
limits?: Partial<EngineLimits>;
|
|
93
|
+
logger?: Logger;
|
|
94
|
+
tracer?: Tracer;
|
|
95
|
+
auditLogger?: AuditLogger;
|
|
96
|
+
/** Optional caller-owned failure sink; `dlq` is retained for compatibility. */
|
|
97
|
+
dlq?: Writable;
|
|
98
|
+
schema?: z.ZodType<any>;
|
|
99
|
+
schemaRegistry?: SchemaRegistry;
|
|
100
|
+
}
|
|
101
|
+
interface ProcessorContext {
|
|
102
|
+
readonly requestId: string;
|
|
103
|
+
readonly timestamp: number;
|
|
104
|
+
readonly signal?: AbortSignal;
|
|
105
|
+
readonly limits?: Readonly<EngineLimits>;
|
|
106
|
+
metadata: Record<string, unknown>;
|
|
107
|
+
logger?: Logger;
|
|
108
|
+
span?: Span;
|
|
109
|
+
}
|
|
110
|
+
interface ProcessorPlugin {
|
|
111
|
+
readonly name: string;
|
|
112
|
+
readonly version: string;
|
|
113
|
+
readonly reversible?: boolean;
|
|
114
|
+
readonly streaming?: boolean;
|
|
115
|
+
process(data: Buffer, ctx: ProcessorContext): Promise<Buffer> | Buffer;
|
|
116
|
+
reverse?(data: Buffer, ctx: ProcessorContext): Promise<Buffer> | Buffer;
|
|
117
|
+
createStream?(mode: 'compress' | 'decompress', context?: StreamPluginContext): Duplex;
|
|
118
|
+
retryOptions?: RetryOptions;
|
|
119
|
+
}
|
|
120
|
+
type PluginOperation = 'process' | 'reverse' | 'stream';
|
|
121
|
+
/** Normalized, runtime-validated operations exposed by a plugin. */
|
|
122
|
+
interface PluginCapabilities {
|
|
123
|
+
readonly process: true;
|
|
124
|
+
readonly reverse: boolean;
|
|
125
|
+
readonly streaming: boolean;
|
|
126
|
+
readonly streamMode: 'native' | 'fallback' | 'none';
|
|
127
|
+
}
|
|
128
|
+
/** Capability view for a plugin registered with a DataEngine. */
|
|
129
|
+
interface RegisteredPluginCapabilities extends PluginCapabilities {
|
|
130
|
+
readonly plugin: string;
|
|
131
|
+
}
|
|
132
|
+
interface EngineResult {
|
|
133
|
+
readonly data: Buffer;
|
|
134
|
+
readonly originalType: string;
|
|
135
|
+
readonly pipeline: string[];
|
|
136
|
+
readonly metrics: {
|
|
137
|
+
durationMs: number;
|
|
138
|
+
steps: Record<string, number>;
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
interface PipeXManifest {
|
|
142
|
+
readonly __pipex_v: 1;
|
|
143
|
+
readonly plugins: string[];
|
|
144
|
+
readonly ts: number;
|
|
145
|
+
}
|
|
146
|
+
declare function isManifest(value: unknown): value is PipeXManifest;
|
|
147
|
+
interface EngineEvents {
|
|
148
|
+
start: [requestId: string];
|
|
149
|
+
'plugin:after': [name: string, durationMs: number];
|
|
150
|
+
progress: [bytes: number, requestId: string];
|
|
151
|
+
error: [err: Error, requestId: string];
|
|
152
|
+
end: [requestId: string, durationMs: number];
|
|
153
|
+
}
|
|
154
|
+
//#endregion
|
|
155
|
+
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,32 @@
|
|
|
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
|
+
import { z } from "zod";
|
|
5
|
+
|
|
6
|
+
//#region src/core/validation.d.ts
|
|
7
|
+
interface ValidationOptions {
|
|
8
|
+
schema: z.ZodType<any>;
|
|
9
|
+
/**
|
|
10
|
+
* Whether to validate during the reverse (decompress) phase.
|
|
11
|
+
* Useful if you want to ensure the restored data still matches the schema.
|
|
12
|
+
*/
|
|
13
|
+
validateOnReverse?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* ValidationPlugin — Core plugin for schema-based data validation.
|
|
17
|
+
* Uses Zod to verify the structure of the data passing through the engine.
|
|
18
|
+
*
|
|
19
|
+
* Note: This plugin assumes the data is MsgPack-encoded (default PipeX behavior).
|
|
20
|
+
*/
|
|
21
|
+
declare class ValidationPlugin extends BasePlugin {
|
|
22
|
+
protected options: ValidationOptions;
|
|
23
|
+
readonly name = "validation";
|
|
24
|
+
readonly version = "1.0.0";
|
|
25
|
+
constructor(options: ValidationOptions);
|
|
26
|
+
process(data: Buffer, ctx: ProcessorContext): Promise<Buffer>;
|
|
27
|
+
reverse(data: Buffer, ctx: ProcessorContext): Promise<Buffer>;
|
|
28
|
+
private validate;
|
|
29
|
+
createStream(mode?: 'compress' | 'decompress', context?: StreamPluginContext): Transform;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { ValidationPlugin as n, ValidationOptions as t };
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
import { z } from "zod";
|
|
5
|
+
|
|
6
|
+
//#region src/core/validation.d.ts
|
|
7
|
+
interface ValidationOptions {
|
|
8
|
+
schema: z.ZodType<any>;
|
|
9
|
+
/**
|
|
10
|
+
* Whether to validate during the reverse (decompress) phase.
|
|
11
|
+
* Useful if you want to ensure the restored data still matches the schema.
|
|
12
|
+
*/
|
|
13
|
+
validateOnReverse?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* ValidationPlugin — Core plugin for schema-based data validation.
|
|
17
|
+
* Uses Zod to verify the structure of the data passing through the engine.
|
|
18
|
+
*
|
|
19
|
+
* Note: This plugin assumes the data is MsgPack-encoded (default PipeX behavior).
|
|
20
|
+
*/
|
|
21
|
+
declare class ValidationPlugin extends BasePlugin {
|
|
22
|
+
protected options: ValidationOptions;
|
|
23
|
+
readonly name = "validation";
|
|
24
|
+
readonly version = "1.0.0";
|
|
25
|
+
constructor(options: ValidationOptions);
|
|
26
|
+
process(data: Buffer, ctx: ProcessorContext): Promise<Buffer>;
|
|
27
|
+
reverse(data: Buffer, ctx: ProcessorContext): Promise<Buffer>;
|
|
28
|
+
private validate;
|
|
29
|
+
createStream(mode?: 'compress' | 'decompress', context?: StreamPluginContext): Transform;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { ValidationPlugin as n, ValidationOptions as t };
|
|
@@ -0,0 +1 @@
|
|
|
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};
|
|
@@ -0,0 +1 @@
|
|
|
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}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./validation-pEeJmCad.cjs`);exports.ValidationPlugin=e.t;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./validation-P5WRSAUK.mjs";export{e as ValidationPlugin};
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
|
|
5
|
+
//#region src/plugin/worker.d.ts
|
|
6
|
+
interface WorkerPoolOptions {
|
|
7
|
+
/** Absolute path or file URL to a caller-owned ESM/CJS worker module. */
|
|
8
|
+
filename: string | URL;
|
|
9
|
+
/** Export used for forward processing. Omit to use the worker's default export. */
|
|
10
|
+
processName?: string;
|
|
11
|
+
/** Export used for reverse processing. When omitted, reverse is unsupported. */
|
|
12
|
+
reverseName?: string;
|
|
13
|
+
maxThreads?: number;
|
|
14
|
+
/** Maximum queued tasks. Defaults to 64. */
|
|
15
|
+
maxQueue?: number;
|
|
16
|
+
/** Per-task timeout in milliseconds. Zero disables the plugin-level timeout. */
|
|
17
|
+
taskTimeoutMs?: number;
|
|
18
|
+
/** Grace period used by Piscina when closing the pool. Defaults to 30 seconds. */
|
|
19
|
+
closeTimeoutMs?: number;
|
|
20
|
+
}
|
|
21
|
+
/** Runs caller-owned CPU transforms in a bounded, persistent Piscina pool. */
|
|
22
|
+
declare class WorkerPoolPlugin extends BasePlugin {
|
|
23
|
+
#private;
|
|
24
|
+
readonly name = "worker-pool";
|
|
25
|
+
readonly version = "5.0.0";
|
|
26
|
+
constructor(options: WorkerPoolOptions);
|
|
27
|
+
get reversible(): boolean;
|
|
28
|
+
process(data: Buffer, ctx: ProcessorContext): Promise<Buffer>;
|
|
29
|
+
reverse(data: Buffer, ctx: ProcessorContext): Promise<Buffer>;
|
|
30
|
+
createStream(mode: 'compress' | 'decompress', context?: StreamPluginContext): Transform;
|
|
31
|
+
/** Rejects new tasks and waits for queued/running work unless force is true. */
|
|
32
|
+
close(options?: {
|
|
33
|
+
force?: boolean;
|
|
34
|
+
}): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { WorkerPoolPlugin as n, WorkerPoolOptions as t };
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
|
|
5
|
+
//#region src/plugin/worker.d.ts
|
|
6
|
+
interface WorkerPoolOptions {
|
|
7
|
+
/** Absolute path or file URL to a caller-owned ESM/CJS worker module. */
|
|
8
|
+
filename: string | URL;
|
|
9
|
+
/** Export used for forward processing. Omit to use the worker's default export. */
|
|
10
|
+
processName?: string;
|
|
11
|
+
/** Export used for reverse processing. When omitted, reverse is unsupported. */
|
|
12
|
+
reverseName?: string;
|
|
13
|
+
maxThreads?: number;
|
|
14
|
+
/** Maximum queued tasks. Defaults to 64. */
|
|
15
|
+
maxQueue?: number;
|
|
16
|
+
/** Per-task timeout in milliseconds. Zero disables the plugin-level timeout. */
|
|
17
|
+
taskTimeoutMs?: number;
|
|
18
|
+
/** Grace period used by Piscina when closing the pool. Defaults to 30 seconds. */
|
|
19
|
+
closeTimeoutMs?: number;
|
|
20
|
+
}
|
|
21
|
+
/** Runs caller-owned CPU transforms in a bounded, persistent Piscina pool. */
|
|
22
|
+
declare class WorkerPoolPlugin extends BasePlugin {
|
|
23
|
+
#private;
|
|
24
|
+
readonly name = "worker-pool";
|
|
25
|
+
readonly version = "5.0.0";
|
|
26
|
+
constructor(options: WorkerPoolOptions);
|
|
27
|
+
get reversible(): boolean;
|
|
28
|
+
process(data: Buffer, ctx: ProcessorContext): Promise<Buffer>;
|
|
29
|
+
reverse(data: Buffer, ctx: ProcessorContext): Promise<Buffer>;
|
|
30
|
+
createStream(mode: 'compress' | 'decompress', context?: StreamPluginContext): Transform;
|
|
31
|
+
/** Rejects new tasks and waits for queued/running work unless force is true. */
|
|
32
|
+
close(options?: {
|
|
33
|
+
force?: boolean;
|
|
34
|
+
}): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { WorkerPoolPlugin as n, WorkerPoolOptions as t };
|
|
@@ -0,0 +1 @@
|
|
|
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}});
|
|
@@ -0,0 +1 @@
|
|
|
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};
|