@uploadista/flow-images-nodes 1.0.0-beta.3 → 1.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +49 -52
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +43 -46
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
- package/tsconfig.json +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@uploadista/core/errors"),t=require("@uploadista/core/flow"),n=require("@uploadista/core/types"),r=require("effect"),i=require("@uploadista/core"),a=require("@uploadista/core/upload");function o(t,n={}){let{maxWaitTime:i=1e4,retryDelay:a=500}=n;return r.Effect.gen(function*(){let n=Date.now();for(;Date.now()-n<i;){let e=yield*r.Effect.tryPromise(()=>fetch(t,{method:`HEAD`})).pipe(r.Effect.catchAll(()=>r.Effect.succeed(null)));if(e?.ok){yield*r.Effect.logInfo(`URL ${t} is now available`);return}e?yield*r.Effect.logDebug(`URL not ready yet (${e.status}), retrying...`):yield*r.Effect.logDebug(`URL check failed, retrying...`),yield*r.Effect.sleep(a)}return yield*e.UploadistaError.fromCode(`FLOW_NODE_ERROR`,{cause:`URL ${t} not available after ${i}ms`}).toEffect()})}function s(i,{credentialId:a,keepOutput:s}={}){return r.Effect.gen(function*(){let c=yield*t.ImageAiPlugin;return yield*(0,t.createFlowNode)({id:i,name:`Describe Image`,description:`Describes the image using AI`,type:t.NodeType.process,nodeTypeId:`describe-image`,outputTypeId:t.IMAGE_DESCRIPTION_OUTPUT_TYPE_ID,keepOutput:s,inputSchema:n.uploadFileSchema,outputSchema:t.imageDescriptionOutputSchema,circuitBreaker:{enabled:!0,failureThreshold:5,resetTimeout:6e4,fallback:{type:`fail`}},run:({data:n,flowId:s,jobId:l,clientId:u})=>r.Effect.gen(function*(){let d={flowId:s,nodeId:i,jobId:l},f=n.url;if(!f)return yield*e.UploadistaError.fromCode(`FLOW_NODE_ERROR`,{cause:`URL is required for describe image operation`}).toEffect();yield*r.Effect.logInfo(`Describing image for file ${n.id} at URL: ${f}`),yield*o(f);let p={clientId:u,credentialId:a},m=yield*c.describeImage(f,p).pipe(r.Effect.catchAll(t=>r.Effect.gen(function*(){return yield*r.Effect.logError(`Failed to describe image`,t),yield*e.UploadistaError.fromCode(`FLOW_NODE_ERROR`,{cause:t instanceof Error?t.message:`Failed to describe image`}).toEffect()})));return yield*r.Effect.logInfo(`Successfully described image for file ${n.id}`),(0,t.completeNodeExecution)({description:m.description,flow:d})})})})}const c={jpeg:`image/jpeg`,webp:`image/webp`,png:`image/png`,avif:`image/avif`},l={jpeg:`jpg`,webp:`webp`,png:`png`,avif:`avif`};function u(e,{quality:n,format:a},o){return r.Effect.gen(function*(){let s=yield*t.ImagePlugin,u=s.supportsStreaming??!1,d=o?.mode??`buffered`,f=d===`buffered`?`buffered`:u?d:`buffered`,p=r=>{let i=c[a],s=l[a],u=r.metadata?.fileName,d;if(u&&typeof u==`string`)if(o?.naming){let i={...o.naming,autoSuffix:o.naming.autoSuffix??(e=>e.format??a)};d=`${(0,t.getBaseName)((0,t.applyFileNaming)(r,(0,t.buildNamingContext)(r,{flowId:r.flow?.flowId??``,jobId:r.flow?.jobId??``,nodeId:e,nodeType:`optimize`},{format:a,quality:n}),i))}.${s}`}else d=u.replace(/\.[^.]+$/,`.${s}`);return{newType:i,newFileName:d}};return yield*(0,t.createTransformNode)({id:e,name:`Optimize`,description:`Optimizes an image for web delivery`,nodeTypeId:`optimize-image`,outputTypeId:t.STORAGE_OUTPUT_TYPE_ID,keepOutput:o?.keepOutput,nodeType:`optimize`,namingVars:{format:a,quality:n},mode:f,streamingConfig:o?.streamingConfig,transform:(e,t)=>r.Effect.map(s.optimize(e,{quality:n,format:a}),e=>{let{newType:n,newFileName:r}=p(t);return{bytes:e,type:n,fileName:r}}),streamingTransform:s.optimizeStream?(e,t)=>{let o=s.optimizeStream;if(!o)throw i.UploadistaError.fromCode(`UNKNOWN_ERROR`);return r.Effect.gen(function*(){let r=yield*o(e,{quality:n,format:a}),{newType:i,newFileName:s}=p(t);return{stream:r,type:i,fileName:s}})}:void 0})})}function d(i,{credentialId:s,keepOutput:c,naming:l}={}){return r.Effect.gen(function*(){let u=yield*t.ImageAiPlugin,d=yield*a.UploadEngine;return yield*(0,t.createFlowNode)({id:i,name:`Remove Background`,description:`Removes the background from an image`,type:t.NodeType.process,nodeTypeId:`remove-background`,outputTypeId:t.STORAGE_OUTPUT_TYPE_ID,keepOutput:c,inputSchema:n.uploadFileSchema,outputSchema:n.uploadFileSchema,circuitBreaker:{enabled:!0,failureThreshold:5,resetTimeout:6e4,fallback:{type:`skip`,passThrough:!0}},run:({data:n,flowId:a,jobId:c,storageId:f,clientId:p})=>r.Effect.gen(function*(){let m={flowId:a,nodeId:i,jobId:c},h=n.url;if(!h)return yield*e.UploadistaError.fromCode(`FLOW_NODE_ERROR`,{cause:`URL is required for remove background operation`}).toEffect();yield*r.Effect.logInfo(`Removing background for file ${n.id} at URL: ${n.url}`),yield*o(h);let g={clientId:p,credentialId:s},{outputUrl:_}=yield*u.removeBackground(h,g).pipe(r.Effect.catchAll(t=>r.Effect.gen(function*(){return yield*r.Effect.logError(`Failed to remove background`,t),yield*e.UploadistaError.fromCode(`FLOW_NODE_ERROR`,{cause:t instanceof Error?t.message:`Failed to remove background from image`}).toEffect()}))),{type:v,fileName:y,metadata:b,metadataJson:x}=(0,t.resolveUploadMetadata)(n.metadata),S=y;if(l){let e={...l,autoSuffix:l.autoSuffix??(()=>`nobg`)};S=(0,t.applyFileNaming)(n,(0,t.buildNamingContext)(n,{flowId:a,jobId:c,nodeId:i,nodeType:`remove-background`}),e)}yield*r.Effect.logInfo(`Uploading processed file to storage`);let C=yield*d.uploadFromUrl({storageId:f,size:0,type:v,fileName:S,lastModified:0,metadata:x,flow:m},p,_).pipe(r.Effect.catchAll(t=>r.Effect.gen(function*(){return yield*r.Effect.logError(`Failed to upload processed file`,t),yield*e.UploadistaError.fromCode(`FLOW_NODE_ERROR`,{cause:t instanceof Error?t.message:`Failed to upload processed file`}).toEffect()})));yield*r.Effect.logInfo(`Successfully removed background for file ${n.id}`);let w=b?{...b,...S!==y&&{fileName:S,originalName:S,name:S,extension:S.split(`.`).pop()||b.extension}}:C.metadata;return(0,t.completeNodeExecution)(w?{...C,metadata:w}:C)})})})}function f(e,{width:n,height:i,fit:a},o){return r.Effect.gen(function*(){let s=yield*t.ImagePlugin,c=s.supportsStreaming??!1,l=o?.mode??`auto`,u=l===`buffered`?`buffered`:c?l:`buffered`,d=o?.naming?{...o.naming,autoSuffix:o.naming.autoSuffix??(e=>`${e.width??n}x${e.height??i}`)}:void 0;return yield*(0,t.createTransformNode)({id:e,name:`Resize`,description:`Resizes an image to the specified dimensions`,nodeTypeId:`resize-image`,outputTypeId:t.STORAGE_OUTPUT_TYPE_ID,keepOutput:o?.keepOutput,naming:d,nodeType:`resize`,namingVars:{width:n,height:i},mode:u,streamingConfig:o?.streamingConfig,transform:e=>s.resize(e,{height:i,width:n,fit:a}),streamingTransform:s.resizeStream?e=>r.Effect.gen(function*(){let t=s.resizeStream;if(!t)throw Error(`resizeStream not available`);return{stream:yield*t(e,{width:n,height:i,fit:a})}}):void 0})})}function p(e,t,n){return r.Effect.reduce(n,t,(t,n)=>e.transform(t,n))}function m(e,t,n){let i=e.transformStream;return i?r.Effect.reduce(n,t,(e,t)=>r.Effect.flatMap(i(e,t),e=>r.Effect.succeed(e))):r.Effect.gen(function*(){let i=[];yield*r.Stream.runForEach(t,e=>r.Effect.sync(()=>{i.push(e)}));let a=i.reduce((e,t)=>e+t.byteLength,0),o=new Uint8Array(a),s=0;for(let e of i)o.set(e,s),s+=e.byteLength;let c=yield*p(e,o,n);return r.Stream.make(c)})}function h(e,{transformations:n},i){return r.Effect.gen(function*(){let a=yield*t.ImagePlugin,o=a.supportsStreaming??!1,s=i?.mode??`auto`,c=n.some(e=>e.type===`watermark`||e.type===`logo`||e.type===`text`),l=s===`buffered`?`buffered`:o&&!c?s:`buffered`,u=i?.naming?{...i.naming,autoSuffix:i.naming.autoSuffix??(()=>`transformed`)}:void 0;return yield*(0,t.createTransformNode)({id:e,name:`Transform Image`,description:`Apply ${n.length} transformation${n.length===1?``:`s`} to the image`,nodeTypeId:`transform-image`,outputTypeId:t.STORAGE_OUTPUT_TYPE_ID,keepOutput:i?.keepOutput,naming:u,nodeType:`transform-image`,mode:l,streamingConfig:i?.streamingConfig,transform:e=>p(a,e,n),streamingTransform:o&&!c?e=>r.Effect.gen(function*(){return{stream:yield*m(a,e,n)}}):void 0})})}exports.createDescribeImageNode=s,exports.createOptimizeNode=u,exports.createRemoveBackgroundNode=d,exports.createResizeNode=f,exports.createTransformImageNode=h,exports.waitForUrlAvailability=o;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { UploadistaError } from "@uploadista/core";
|
|
3
|
-
import * as zod_v4_core0 from "zod/v4/core";
|
|
4
|
-
import * as zod from "zod";
|
|
5
|
-
import { UploadistaError as UploadistaError$1 } from "@uploadista/core/errors";
|
|
1
|
+
import { UploadistaError } from "@uploadista/core/errors";
|
|
6
2
|
import { FileNamingConfig, ImageAiPlugin, ImagePlugin, NodeType, OptimizeParams, ResizeParams, StreamingConfig, TransformImageParams, TransformMode } from "@uploadista/core/flow";
|
|
7
3
|
import { Effect } from "effect";
|
|
4
|
+
import { UploadistaError as UploadistaError$1 } from "@uploadista/core";
|
|
8
5
|
import { UploadEngine } from "@uploadista/core/upload";
|
|
9
6
|
|
|
10
7
|
//#region src/describe-image-node.d.ts
|
|
@@ -14,8 +11,8 @@ declare function createDescribeImageNode(id: string, {
|
|
|
14
11
|
}?: {
|
|
15
12
|
credentialId?: string;
|
|
16
13
|
keepOutput?: boolean;
|
|
17
|
-
}): Effect.Effect<
|
|
18
|
-
inputSchema: zod.ZodType<{
|
|
14
|
+
}): Effect.Effect<import("@uploadista/core").FlowNodeData & {
|
|
15
|
+
inputSchema: import("zod").ZodType<{
|
|
19
16
|
id: string;
|
|
20
17
|
offset: number;
|
|
21
18
|
storage: {
|
|
@@ -31,7 +28,7 @@ declare function createDescribeImageNode(id: string, {
|
|
|
31
28
|
}[] | undefined;
|
|
32
29
|
};
|
|
33
30
|
size?: number | undefined;
|
|
34
|
-
metadata?: Record<string,
|
|
31
|
+
metadata?: Record<string, import("@uploadista/core").JsonValue> | undefined;
|
|
35
32
|
creationDate?: string | undefined;
|
|
36
33
|
url?: string | undefined;
|
|
37
34
|
sizeIsDeferred?: boolean | undefined;
|
|
@@ -47,7 +44,7 @@ declare function createDescribeImageNode(id: string, {
|
|
|
47
44
|
spanId: string;
|
|
48
45
|
traceFlags: number;
|
|
49
46
|
} | undefined;
|
|
50
|
-
}, unknown,
|
|
47
|
+
}, unknown, import("zod/v4/core").$ZodTypeInternals<{
|
|
51
48
|
id: string;
|
|
52
49
|
offset: number;
|
|
53
50
|
storage: {
|
|
@@ -63,7 +60,7 @@ declare function createDescribeImageNode(id: string, {
|
|
|
63
60
|
}[] | undefined;
|
|
64
61
|
};
|
|
65
62
|
size?: number | undefined;
|
|
66
|
-
metadata?: Record<string,
|
|
63
|
+
metadata?: Record<string, import("@uploadista/core").JsonValue> | undefined;
|
|
67
64
|
creationDate?: string | undefined;
|
|
68
65
|
url?: string | undefined;
|
|
69
66
|
sizeIsDeferred?: boolean | undefined;
|
|
@@ -80,11 +77,11 @@ declare function createDescribeImageNode(id: string, {
|
|
|
80
77
|
traceFlags: number;
|
|
81
78
|
} | undefined;
|
|
82
79
|
}, unknown>>;
|
|
83
|
-
outputSchema: zod.ZodType<{
|
|
80
|
+
outputSchema: import("zod").ZodType<{
|
|
84
81
|
description: string;
|
|
85
82
|
confidence?: number | undefined;
|
|
86
83
|
metadata?: Record<string, unknown> | undefined;
|
|
87
|
-
}, unknown,
|
|
84
|
+
}, unknown, import("zod/v4/core").$ZodTypeInternals<{
|
|
88
85
|
description: string;
|
|
89
86
|
confidence?: number | undefined;
|
|
90
87
|
metadata?: Record<string, unknown> | undefined;
|
|
@@ -106,7 +103,7 @@ declare function createDescribeImageNode(id: string, {
|
|
|
106
103
|
}[] | undefined;
|
|
107
104
|
};
|
|
108
105
|
size?: number | undefined;
|
|
109
|
-
metadata?: Record<string,
|
|
106
|
+
metadata?: Record<string, import("@uploadista/core").JsonValue> | undefined;
|
|
110
107
|
creationDate?: string | undefined;
|
|
111
108
|
url?: string | undefined;
|
|
112
109
|
sizeIsDeferred?: boolean | undefined;
|
|
@@ -128,11 +125,11 @@ declare function createDescribeImageNode(id: string, {
|
|
|
128
125
|
flowId: string;
|
|
129
126
|
inputs?: Record<string, unknown>;
|
|
130
127
|
clientId: string | null;
|
|
131
|
-
}) => Effect.Effect<
|
|
128
|
+
}) => Effect.Effect<import("@uploadista/core").NodeExecutionResult<{
|
|
132
129
|
description: string;
|
|
133
130
|
confidence?: number | undefined;
|
|
134
131
|
metadata?: Record<string, unknown> | undefined;
|
|
135
|
-
}>, UploadistaError
|
|
132
|
+
}>, UploadistaError, never>;
|
|
136
133
|
condition?: {
|
|
137
134
|
field: string;
|
|
138
135
|
operator: string;
|
|
@@ -146,10 +143,10 @@ declare function createDescribeImageNode(id: string, {
|
|
|
146
143
|
retryDelay?: number;
|
|
147
144
|
exponentialBackoff?: boolean;
|
|
148
145
|
};
|
|
149
|
-
circuitBreaker?:
|
|
146
|
+
circuitBreaker?: import("@uploadista/core").FlowCircuitBreakerConfig;
|
|
150
147
|
} & {
|
|
151
148
|
type: NodeType.process;
|
|
152
|
-
}, UploadistaError
|
|
149
|
+
}, UploadistaError, ImageAiPlugin>;
|
|
153
150
|
//#endregion
|
|
154
151
|
//#region src/optimize-node.d.ts
|
|
155
152
|
/**
|
|
@@ -196,17 +193,17 @@ declare function createOptimizeNode(id: string, {
|
|
|
196
193
|
naming?: FileNamingConfig;
|
|
197
194
|
mode?: TransformMode;
|
|
198
195
|
streamingConfig?: StreamingConfig;
|
|
199
|
-
}): Effect.Effect<
|
|
200
|
-
inputSchema: zod.ZodType<
|
|
201
|
-
outputSchema: zod.ZodType<
|
|
196
|
+
}): Effect.Effect<import("@uploadista/core").FlowNodeData & {
|
|
197
|
+
inputSchema: import("zod").ZodType<import("@uploadista/core").UploadFile, unknown, import("zod/v4/core").$ZodTypeInternals<import("@uploadista/core").UploadFile, unknown>>;
|
|
198
|
+
outputSchema: import("zod").ZodType<import("@uploadista/core").UploadFile, unknown, import("zod/v4/core").$ZodTypeInternals<import("@uploadista/core").UploadFile, unknown>>;
|
|
202
199
|
run: (args: {
|
|
203
|
-
data:
|
|
200
|
+
data: import("@uploadista/core").UploadFile;
|
|
204
201
|
jobId: string;
|
|
205
202
|
storageId: string;
|
|
206
203
|
flowId: string;
|
|
207
204
|
inputs?: Record<string, unknown>;
|
|
208
205
|
clientId: string | null;
|
|
209
|
-
}) => Effect.Effect<
|
|
206
|
+
}) => Effect.Effect<import("@uploadista/core").NodeExecutionResult<import("@uploadista/core").UploadFile>, UploadistaError$1, never>;
|
|
210
207
|
condition?: {
|
|
211
208
|
field: string;
|
|
212
209
|
operator: string;
|
|
@@ -220,10 +217,10 @@ declare function createOptimizeNode(id: string, {
|
|
|
220
217
|
retryDelay?: number;
|
|
221
218
|
exponentialBackoff?: boolean;
|
|
222
219
|
};
|
|
223
|
-
circuitBreaker?:
|
|
220
|
+
circuitBreaker?: import("@uploadista/core").FlowCircuitBreakerConfig;
|
|
224
221
|
} & {
|
|
225
|
-
type:
|
|
226
|
-
}, UploadistaError, ImagePlugin |
|
|
222
|
+
type: import("@uploadista/core").NodeType;
|
|
223
|
+
}, UploadistaError$1, ImagePlugin | import("@uploadista/core").UploadEngine>;
|
|
227
224
|
//#endregion
|
|
228
225
|
//#region src/remove-background-node.d.ts
|
|
229
226
|
/**
|
|
@@ -251,8 +248,8 @@ declare function createRemoveBackgroundNode(id: string, {
|
|
|
251
248
|
credentialId?: string;
|
|
252
249
|
keepOutput?: boolean;
|
|
253
250
|
naming?: FileNamingConfig;
|
|
254
|
-
}): Effect.Effect<
|
|
255
|
-
inputSchema: zod.ZodType<{
|
|
251
|
+
}): Effect.Effect<import("@uploadista/core").FlowNodeData & {
|
|
252
|
+
inputSchema: import("zod").ZodType<{
|
|
256
253
|
id: string;
|
|
257
254
|
offset: number;
|
|
258
255
|
storage: {
|
|
@@ -268,7 +265,7 @@ declare function createRemoveBackgroundNode(id: string, {
|
|
|
268
265
|
}[] | undefined;
|
|
269
266
|
};
|
|
270
267
|
size?: number | undefined;
|
|
271
|
-
metadata?: Record<string,
|
|
268
|
+
metadata?: Record<string, import("@uploadista/core").JsonValue> | undefined;
|
|
272
269
|
creationDate?: string | undefined;
|
|
273
270
|
url?: string | undefined;
|
|
274
271
|
sizeIsDeferred?: boolean | undefined;
|
|
@@ -284,7 +281,7 @@ declare function createRemoveBackgroundNode(id: string, {
|
|
|
284
281
|
spanId: string;
|
|
285
282
|
traceFlags: number;
|
|
286
283
|
} | undefined;
|
|
287
|
-
}, unknown,
|
|
284
|
+
}, unknown, import("zod/v4/core").$ZodTypeInternals<{
|
|
288
285
|
id: string;
|
|
289
286
|
offset: number;
|
|
290
287
|
storage: {
|
|
@@ -300,7 +297,7 @@ declare function createRemoveBackgroundNode(id: string, {
|
|
|
300
297
|
}[] | undefined;
|
|
301
298
|
};
|
|
302
299
|
size?: number | undefined;
|
|
303
|
-
metadata?: Record<string,
|
|
300
|
+
metadata?: Record<string, import("@uploadista/core").JsonValue> | undefined;
|
|
304
301
|
creationDate?: string | undefined;
|
|
305
302
|
url?: string | undefined;
|
|
306
303
|
sizeIsDeferred?: boolean | undefined;
|
|
@@ -317,7 +314,7 @@ declare function createRemoveBackgroundNode(id: string, {
|
|
|
317
314
|
traceFlags: number;
|
|
318
315
|
} | undefined;
|
|
319
316
|
}, unknown>>;
|
|
320
|
-
outputSchema: zod.ZodType<
|
|
317
|
+
outputSchema: import("zod").ZodType<import("@uploadista/core").UploadFile, unknown, import("zod/v4/core").$ZodTypeInternals<import("@uploadista/core").UploadFile, unknown>>;
|
|
321
318
|
run: (args: {
|
|
322
319
|
data: {
|
|
323
320
|
id: string;
|
|
@@ -335,7 +332,7 @@ declare function createRemoveBackgroundNode(id: string, {
|
|
|
335
332
|
}[] | undefined;
|
|
336
333
|
};
|
|
337
334
|
size?: number | undefined;
|
|
338
|
-
metadata?: Record<string,
|
|
335
|
+
metadata?: Record<string, import("@uploadista/core").JsonValue> | undefined;
|
|
339
336
|
creationDate?: string | undefined;
|
|
340
337
|
url?: string | undefined;
|
|
341
338
|
sizeIsDeferred?: boolean | undefined;
|
|
@@ -357,7 +354,7 @@ declare function createRemoveBackgroundNode(id: string, {
|
|
|
357
354
|
flowId: string;
|
|
358
355
|
inputs?: Record<string, unknown>;
|
|
359
356
|
clientId: string | null;
|
|
360
|
-
}) => Effect.Effect<
|
|
357
|
+
}) => Effect.Effect<import("@uploadista/core").NodeExecutionResult<import("@uploadista/core").UploadFile>, UploadistaError, never>;
|
|
361
358
|
condition?: {
|
|
362
359
|
field: string;
|
|
363
360
|
operator: string;
|
|
@@ -371,10 +368,10 @@ declare function createRemoveBackgroundNode(id: string, {
|
|
|
371
368
|
retryDelay?: number;
|
|
372
369
|
exponentialBackoff?: boolean;
|
|
373
370
|
};
|
|
374
|
-
circuitBreaker?:
|
|
371
|
+
circuitBreaker?: import("@uploadista/core").FlowCircuitBreakerConfig;
|
|
375
372
|
} & {
|
|
376
373
|
type: NodeType.process;
|
|
377
|
-
}, UploadistaError
|
|
374
|
+
}, UploadistaError, ImageAiPlugin | UploadEngine>;
|
|
378
375
|
//#endregion
|
|
379
376
|
//#region src/resize-node.d.ts
|
|
380
377
|
/**
|
|
@@ -421,17 +418,17 @@ declare function createResizeNode(id: string, {
|
|
|
421
418
|
naming?: FileNamingConfig;
|
|
422
419
|
mode?: TransformMode;
|
|
423
420
|
streamingConfig?: StreamingConfig;
|
|
424
|
-
}): Effect.Effect<
|
|
425
|
-
inputSchema: zod.ZodType<
|
|
426
|
-
outputSchema: zod.ZodType<
|
|
421
|
+
}): Effect.Effect<import("@uploadista/core").FlowNodeData & {
|
|
422
|
+
inputSchema: import("zod").ZodType<import("@uploadista/core").UploadFile, unknown, import("zod/v4/core").$ZodTypeInternals<import("@uploadista/core").UploadFile, unknown>>;
|
|
423
|
+
outputSchema: import("zod").ZodType<import("@uploadista/core").UploadFile, unknown, import("zod/v4/core").$ZodTypeInternals<import("@uploadista/core").UploadFile, unknown>>;
|
|
427
424
|
run: (args: {
|
|
428
|
-
data:
|
|
425
|
+
data: import("@uploadista/core").UploadFile;
|
|
429
426
|
jobId: string;
|
|
430
427
|
storageId: string;
|
|
431
428
|
flowId: string;
|
|
432
429
|
inputs?: Record<string, unknown>;
|
|
433
430
|
clientId: string | null;
|
|
434
|
-
}) => Effect.Effect<
|
|
431
|
+
}) => Effect.Effect<import("@uploadista/core").NodeExecutionResult<import("@uploadista/core").UploadFile>, import("@uploadista/core").UploadistaError, never>;
|
|
435
432
|
condition?: {
|
|
436
433
|
field: string;
|
|
437
434
|
operator: string;
|
|
@@ -445,10 +442,10 @@ declare function createResizeNode(id: string, {
|
|
|
445
442
|
retryDelay?: number;
|
|
446
443
|
exponentialBackoff?: boolean;
|
|
447
444
|
};
|
|
448
|
-
circuitBreaker?:
|
|
445
|
+
circuitBreaker?: import("@uploadista/core").FlowCircuitBreakerConfig;
|
|
449
446
|
} & {
|
|
450
|
-
type:
|
|
451
|
-
},
|
|
447
|
+
type: import("@uploadista/core").NodeType;
|
|
448
|
+
}, import("@uploadista/core").UploadistaError, ImagePlugin | import("@uploadista/core").UploadEngine>;
|
|
452
449
|
//#endregion
|
|
453
450
|
//#region src/transform-image-node.d.ts
|
|
454
451
|
/**
|
|
@@ -520,17 +517,17 @@ declare function createTransformImageNode(id: string, {
|
|
|
520
517
|
naming?: FileNamingConfig;
|
|
521
518
|
mode?: TransformMode;
|
|
522
519
|
streamingConfig?: StreamingConfig;
|
|
523
|
-
}): Effect.Effect<
|
|
524
|
-
inputSchema: zod.ZodType<
|
|
525
|
-
outputSchema: zod.ZodType<
|
|
520
|
+
}): Effect.Effect<import("@uploadista/core").FlowNodeData & {
|
|
521
|
+
inputSchema: import("zod").ZodType<import("@uploadista/core").UploadFile, unknown, import("zod/v4/core").$ZodTypeInternals<import("@uploadista/core").UploadFile, unknown>>;
|
|
522
|
+
outputSchema: import("zod").ZodType<import("@uploadista/core").UploadFile, unknown, import("zod/v4/core").$ZodTypeInternals<import("@uploadista/core").UploadFile, unknown>>;
|
|
526
523
|
run: (args: {
|
|
527
|
-
data:
|
|
524
|
+
data: import("@uploadista/core").UploadFile;
|
|
528
525
|
jobId: string;
|
|
529
526
|
storageId: string;
|
|
530
527
|
flowId: string;
|
|
531
528
|
inputs?: Record<string, unknown>;
|
|
532
529
|
clientId: string | null;
|
|
533
|
-
}) => Effect.Effect<
|
|
530
|
+
}) => Effect.Effect<import("@uploadista/core").NodeExecutionResult<import("@uploadista/core").UploadFile>, UploadistaError, never>;
|
|
534
531
|
condition?: {
|
|
535
532
|
field: string;
|
|
536
533
|
operator: string;
|
|
@@ -544,10 +541,10 @@ declare function createTransformImageNode(id: string, {
|
|
|
544
541
|
retryDelay?: number;
|
|
545
542
|
exponentialBackoff?: boolean;
|
|
546
543
|
};
|
|
547
|
-
circuitBreaker?:
|
|
544
|
+
circuitBreaker?: import("@uploadista/core").FlowCircuitBreakerConfig;
|
|
548
545
|
} & {
|
|
549
|
-
type:
|
|
550
|
-
}, UploadistaError
|
|
546
|
+
type: import("@uploadista/core").NodeType;
|
|
547
|
+
}, UploadistaError, ImagePlugin | import("@uploadista/core").UploadEngine>;
|
|
551
548
|
//#endregion
|
|
552
549
|
//#region src/wait-for-url.d.ts
|
|
553
550
|
/**
|
|
@@ -564,7 +561,7 @@ declare function createTransformImageNode(id: string, {
|
|
|
564
561
|
declare function waitForUrlAvailability(url: string, options?: {
|
|
565
562
|
maxWaitTime?: number;
|
|
566
563
|
retryDelay?: number;
|
|
567
|
-
}): Effect.Effect<void, UploadistaError
|
|
564
|
+
}): Effect.Effect<void, UploadistaError>;
|
|
568
565
|
//#endregion
|
|
569
566
|
export { createDescribeImageNode, createOptimizeNode, createRemoveBackgroundNode, createResizeNode, createTransformImageNode, waitForUrlAvailability };
|
|
570
567
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/describe-image-node.ts","../src/optimize-node.ts","../src/remove-background-node.ts","../src/resize-node.ts","../src/transform-image-node.ts","../src/wait-for-url.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/describe-image-node.ts","../src/optimize-node.ts","../src/remove-background-node.ts","../src/resize-node.ts","../src/transform-image-node.ts","../src/wait-for-url.ts"],"mappings":";;;;;;;iBAcgB,uBAAA,CACd,EAAA;EAEE,YAAA;EACA;AAAA;EACG,YAAA;EAAuB,UAAA;AAAA,IAA2B,MAAA,CAAA,MAAA,4BAAA,YAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCqDgB,kBAAA,CACd,EAAA;EACE,OAAA;EAAS;AAAA,GAAU,cAAA,EACrB,OAAA;EACE,UAAA;EACA,MAAA,GAAS,gBAAA;EACT,IAAA,GAAO,aAAA;EACP,eAAA,GAAkB,eAAA;AAAA,IACnB,MAAA,CAAA,MAAA,4BAAA,YAAA;;;;;;;;aAsH2vjE,MAAA;;;;;;;;;;;;;;;;;;;;;;;;;ADnL9vjE;;;;;;;;;;;;;;iBEoBgB,0BAAA,CACd,EAAA;EAEE,YAAA;EACA,UAAA;EACA;AAAA;EAEA,YAAA;EACA,UAAA;EACA,MAAA,GAAS,gBAAA;AAAA,IACL,MAAA,CAAA,MAAA,4BAAA,YAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AF9BR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBGgCgB,gBAAA,CACd,EAAA;EACE,KAAA;EAAO,MAAA;EAAQ;AAAA,GAAO,YAAA,EACxB,OAAA;EACE,UAAA;EACA,MAAA,GAAS,gBAAA;EACT,IAAA,GAAO,aAAA;EACP,eAAA,GAAkB,eAAA;AAAA,IACnB,MAAA,CAAA,MAAA,4BAAA,YAAA;;;;;;;;aA8D4ooE,MAAA;;;;;;;;;;;;;;;;;;;;;;;;;;AHtG/ooE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBIuIgB,wBAAA,CACd,EAAA;EACE;AAAA,GAAmB,oBAAA,EACrB,OAAA;EACE,UAAA;EACA,MAAA,GAAS,gBAAA;EACT,IAAA,GAAO,aAAA;EACP,eAAA,GAAkB,eAAA;AAAA,IACnB,MAAA,CAAA,MAAA,4BAAA,YAAA;;;;;;;;aA4D6wgE,MAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;AJ3MhxgE;;;;;;iBKAgB,sBAAA,CACd,GAAA,UACA,OAAA;EACE,WAAA;EACA,UAAA;AAAA,IAED,MAAA,CAAO,MAAM,OAAO,eAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { UploadistaError } from "@uploadista/core/errors";
|
|
2
2
|
import { FileNamingConfig, ImageAiPlugin, ImagePlugin, NodeType, OptimizeParams, ResizeParams, StreamingConfig, TransformImageParams, TransformMode } from "@uploadista/core/flow";
|
|
3
3
|
import { Effect } from "effect";
|
|
4
|
-
import * as _uploadista_core0 from "@uploadista/core";
|
|
5
4
|
import { UploadistaError as UploadistaError$1 } from "@uploadista/core";
|
|
6
5
|
import { UploadEngine } from "@uploadista/core/upload";
|
|
7
|
-
import * as zod_v4_core0 from "zod/v4/core";
|
|
8
|
-
import * as zod from "zod";
|
|
9
6
|
|
|
10
7
|
//#region src/describe-image-node.d.ts
|
|
11
8
|
declare function createDescribeImageNode(id: string, {
|
|
@@ -14,8 +11,8 @@ declare function createDescribeImageNode(id: string, {
|
|
|
14
11
|
}?: {
|
|
15
12
|
credentialId?: string;
|
|
16
13
|
keepOutput?: boolean;
|
|
17
|
-
}): Effect.Effect<
|
|
18
|
-
inputSchema: zod.ZodType<{
|
|
14
|
+
}): Effect.Effect<import("@uploadista/core").FlowNodeData & {
|
|
15
|
+
inputSchema: import("zod").ZodType<{
|
|
19
16
|
id: string;
|
|
20
17
|
offset: number;
|
|
21
18
|
storage: {
|
|
@@ -31,7 +28,7 @@ declare function createDescribeImageNode(id: string, {
|
|
|
31
28
|
}[] | undefined;
|
|
32
29
|
};
|
|
33
30
|
size?: number | undefined;
|
|
34
|
-
metadata?: Record<string,
|
|
31
|
+
metadata?: Record<string, import("@uploadista/core").JsonValue> | undefined;
|
|
35
32
|
creationDate?: string | undefined;
|
|
36
33
|
url?: string | undefined;
|
|
37
34
|
sizeIsDeferred?: boolean | undefined;
|
|
@@ -47,7 +44,7 @@ declare function createDescribeImageNode(id: string, {
|
|
|
47
44
|
spanId: string;
|
|
48
45
|
traceFlags: number;
|
|
49
46
|
} | undefined;
|
|
50
|
-
}, unknown,
|
|
47
|
+
}, unknown, import("zod/v4/core").$ZodTypeInternals<{
|
|
51
48
|
id: string;
|
|
52
49
|
offset: number;
|
|
53
50
|
storage: {
|
|
@@ -63,7 +60,7 @@ declare function createDescribeImageNode(id: string, {
|
|
|
63
60
|
}[] | undefined;
|
|
64
61
|
};
|
|
65
62
|
size?: number | undefined;
|
|
66
|
-
metadata?: Record<string,
|
|
63
|
+
metadata?: Record<string, import("@uploadista/core").JsonValue> | undefined;
|
|
67
64
|
creationDate?: string | undefined;
|
|
68
65
|
url?: string | undefined;
|
|
69
66
|
sizeIsDeferred?: boolean | undefined;
|
|
@@ -80,11 +77,11 @@ declare function createDescribeImageNode(id: string, {
|
|
|
80
77
|
traceFlags: number;
|
|
81
78
|
} | undefined;
|
|
82
79
|
}, unknown>>;
|
|
83
|
-
outputSchema: zod.ZodType<{
|
|
80
|
+
outputSchema: import("zod").ZodType<{
|
|
84
81
|
description: string;
|
|
85
82
|
confidence?: number | undefined;
|
|
86
83
|
metadata?: Record<string, unknown> | undefined;
|
|
87
|
-
}, unknown,
|
|
84
|
+
}, unknown, import("zod/v4/core").$ZodTypeInternals<{
|
|
88
85
|
description: string;
|
|
89
86
|
confidence?: number | undefined;
|
|
90
87
|
metadata?: Record<string, unknown> | undefined;
|
|
@@ -106,7 +103,7 @@ declare function createDescribeImageNode(id: string, {
|
|
|
106
103
|
}[] | undefined;
|
|
107
104
|
};
|
|
108
105
|
size?: number | undefined;
|
|
109
|
-
metadata?: Record<string,
|
|
106
|
+
metadata?: Record<string, import("@uploadista/core").JsonValue> | undefined;
|
|
110
107
|
creationDate?: string | undefined;
|
|
111
108
|
url?: string | undefined;
|
|
112
109
|
sizeIsDeferred?: boolean | undefined;
|
|
@@ -128,7 +125,7 @@ declare function createDescribeImageNode(id: string, {
|
|
|
128
125
|
flowId: string;
|
|
129
126
|
inputs?: Record<string, unknown>;
|
|
130
127
|
clientId: string | null;
|
|
131
|
-
}) => Effect.Effect<
|
|
128
|
+
}) => Effect.Effect<import("@uploadista/core").NodeExecutionResult<{
|
|
132
129
|
description: string;
|
|
133
130
|
confidence?: number | undefined;
|
|
134
131
|
metadata?: Record<string, unknown> | undefined;
|
|
@@ -146,7 +143,7 @@ declare function createDescribeImageNode(id: string, {
|
|
|
146
143
|
retryDelay?: number;
|
|
147
144
|
exponentialBackoff?: boolean;
|
|
148
145
|
};
|
|
149
|
-
circuitBreaker?:
|
|
146
|
+
circuitBreaker?: import("@uploadista/core").FlowCircuitBreakerConfig;
|
|
150
147
|
} & {
|
|
151
148
|
type: NodeType.process;
|
|
152
149
|
}, UploadistaError, ImageAiPlugin>;
|
|
@@ -196,17 +193,17 @@ declare function createOptimizeNode(id: string, {
|
|
|
196
193
|
naming?: FileNamingConfig;
|
|
197
194
|
mode?: TransformMode;
|
|
198
195
|
streamingConfig?: StreamingConfig;
|
|
199
|
-
}): Effect.Effect<
|
|
200
|
-
inputSchema: zod.ZodType<
|
|
201
|
-
outputSchema: zod.ZodType<
|
|
196
|
+
}): Effect.Effect<import("@uploadista/core").FlowNodeData & {
|
|
197
|
+
inputSchema: import("zod").ZodType<import("@uploadista/core").UploadFile, unknown, import("zod/v4/core").$ZodTypeInternals<import("@uploadista/core").UploadFile, unknown>>;
|
|
198
|
+
outputSchema: import("zod").ZodType<import("@uploadista/core").UploadFile, unknown, import("zod/v4/core").$ZodTypeInternals<import("@uploadista/core").UploadFile, unknown>>;
|
|
202
199
|
run: (args: {
|
|
203
|
-
data:
|
|
200
|
+
data: import("@uploadista/core").UploadFile;
|
|
204
201
|
jobId: string;
|
|
205
202
|
storageId: string;
|
|
206
203
|
flowId: string;
|
|
207
204
|
inputs?: Record<string, unknown>;
|
|
208
205
|
clientId: string | null;
|
|
209
|
-
}) => Effect.Effect<
|
|
206
|
+
}) => Effect.Effect<import("@uploadista/core").NodeExecutionResult<import("@uploadista/core").UploadFile>, UploadistaError$1, never>;
|
|
210
207
|
condition?: {
|
|
211
208
|
field: string;
|
|
212
209
|
operator: string;
|
|
@@ -220,10 +217,10 @@ declare function createOptimizeNode(id: string, {
|
|
|
220
217
|
retryDelay?: number;
|
|
221
218
|
exponentialBackoff?: boolean;
|
|
222
219
|
};
|
|
223
|
-
circuitBreaker?:
|
|
220
|
+
circuitBreaker?: import("@uploadista/core").FlowCircuitBreakerConfig;
|
|
224
221
|
} & {
|
|
225
|
-
type:
|
|
226
|
-
}, UploadistaError$1, ImagePlugin |
|
|
222
|
+
type: import("@uploadista/core").NodeType;
|
|
223
|
+
}, UploadistaError$1, ImagePlugin | import("@uploadista/core").UploadEngine>;
|
|
227
224
|
//#endregion
|
|
228
225
|
//#region src/remove-background-node.d.ts
|
|
229
226
|
/**
|
|
@@ -251,8 +248,8 @@ declare function createRemoveBackgroundNode(id: string, {
|
|
|
251
248
|
credentialId?: string;
|
|
252
249
|
keepOutput?: boolean;
|
|
253
250
|
naming?: FileNamingConfig;
|
|
254
|
-
}): Effect.Effect<
|
|
255
|
-
inputSchema: zod.ZodType<{
|
|
251
|
+
}): Effect.Effect<import("@uploadista/core").FlowNodeData & {
|
|
252
|
+
inputSchema: import("zod").ZodType<{
|
|
256
253
|
id: string;
|
|
257
254
|
offset: number;
|
|
258
255
|
storage: {
|
|
@@ -268,7 +265,7 @@ declare function createRemoveBackgroundNode(id: string, {
|
|
|
268
265
|
}[] | undefined;
|
|
269
266
|
};
|
|
270
267
|
size?: number | undefined;
|
|
271
|
-
metadata?: Record<string,
|
|
268
|
+
metadata?: Record<string, import("@uploadista/core").JsonValue> | undefined;
|
|
272
269
|
creationDate?: string | undefined;
|
|
273
270
|
url?: string | undefined;
|
|
274
271
|
sizeIsDeferred?: boolean | undefined;
|
|
@@ -284,7 +281,7 @@ declare function createRemoveBackgroundNode(id: string, {
|
|
|
284
281
|
spanId: string;
|
|
285
282
|
traceFlags: number;
|
|
286
283
|
} | undefined;
|
|
287
|
-
}, unknown,
|
|
284
|
+
}, unknown, import("zod/v4/core").$ZodTypeInternals<{
|
|
288
285
|
id: string;
|
|
289
286
|
offset: number;
|
|
290
287
|
storage: {
|
|
@@ -300,7 +297,7 @@ declare function createRemoveBackgroundNode(id: string, {
|
|
|
300
297
|
}[] | undefined;
|
|
301
298
|
};
|
|
302
299
|
size?: number | undefined;
|
|
303
|
-
metadata?: Record<string,
|
|
300
|
+
metadata?: Record<string, import("@uploadista/core").JsonValue> | undefined;
|
|
304
301
|
creationDate?: string | undefined;
|
|
305
302
|
url?: string | undefined;
|
|
306
303
|
sizeIsDeferred?: boolean | undefined;
|
|
@@ -317,7 +314,7 @@ declare function createRemoveBackgroundNode(id: string, {
|
|
|
317
314
|
traceFlags: number;
|
|
318
315
|
} | undefined;
|
|
319
316
|
}, unknown>>;
|
|
320
|
-
outputSchema: zod.ZodType<
|
|
317
|
+
outputSchema: import("zod").ZodType<import("@uploadista/core").UploadFile, unknown, import("zod/v4/core").$ZodTypeInternals<import("@uploadista/core").UploadFile, unknown>>;
|
|
321
318
|
run: (args: {
|
|
322
319
|
data: {
|
|
323
320
|
id: string;
|
|
@@ -335,7 +332,7 @@ declare function createRemoveBackgroundNode(id: string, {
|
|
|
335
332
|
}[] | undefined;
|
|
336
333
|
};
|
|
337
334
|
size?: number | undefined;
|
|
338
|
-
metadata?: Record<string,
|
|
335
|
+
metadata?: Record<string, import("@uploadista/core").JsonValue> | undefined;
|
|
339
336
|
creationDate?: string | undefined;
|
|
340
337
|
url?: string | undefined;
|
|
341
338
|
sizeIsDeferred?: boolean | undefined;
|
|
@@ -357,7 +354,7 @@ declare function createRemoveBackgroundNode(id: string, {
|
|
|
357
354
|
flowId: string;
|
|
358
355
|
inputs?: Record<string, unknown>;
|
|
359
356
|
clientId: string | null;
|
|
360
|
-
}) => Effect.Effect<
|
|
357
|
+
}) => Effect.Effect<import("@uploadista/core").NodeExecutionResult<import("@uploadista/core").UploadFile>, UploadistaError, never>;
|
|
361
358
|
condition?: {
|
|
362
359
|
field: string;
|
|
363
360
|
operator: string;
|
|
@@ -371,7 +368,7 @@ declare function createRemoveBackgroundNode(id: string, {
|
|
|
371
368
|
retryDelay?: number;
|
|
372
369
|
exponentialBackoff?: boolean;
|
|
373
370
|
};
|
|
374
|
-
circuitBreaker?:
|
|
371
|
+
circuitBreaker?: import("@uploadista/core").FlowCircuitBreakerConfig;
|
|
375
372
|
} & {
|
|
376
373
|
type: NodeType.process;
|
|
377
374
|
}, UploadistaError, ImageAiPlugin | UploadEngine>;
|
|
@@ -421,17 +418,17 @@ declare function createResizeNode(id: string, {
|
|
|
421
418
|
naming?: FileNamingConfig;
|
|
422
419
|
mode?: TransformMode;
|
|
423
420
|
streamingConfig?: StreamingConfig;
|
|
424
|
-
}): Effect.Effect<
|
|
425
|
-
inputSchema: zod.ZodType<
|
|
426
|
-
outputSchema: zod.ZodType<
|
|
421
|
+
}): Effect.Effect<import("@uploadista/core").FlowNodeData & {
|
|
422
|
+
inputSchema: import("zod").ZodType<import("@uploadista/core").UploadFile, unknown, import("zod/v4/core").$ZodTypeInternals<import("@uploadista/core").UploadFile, unknown>>;
|
|
423
|
+
outputSchema: import("zod").ZodType<import("@uploadista/core").UploadFile, unknown, import("zod/v4/core").$ZodTypeInternals<import("@uploadista/core").UploadFile, unknown>>;
|
|
427
424
|
run: (args: {
|
|
428
|
-
data:
|
|
425
|
+
data: import("@uploadista/core").UploadFile;
|
|
429
426
|
jobId: string;
|
|
430
427
|
storageId: string;
|
|
431
428
|
flowId: string;
|
|
432
429
|
inputs?: Record<string, unknown>;
|
|
433
430
|
clientId: string | null;
|
|
434
|
-
}) => Effect.Effect<
|
|
431
|
+
}) => Effect.Effect<import("@uploadista/core").NodeExecutionResult<import("@uploadista/core").UploadFile>, import("@uploadista/core").UploadistaError, never>;
|
|
435
432
|
condition?: {
|
|
436
433
|
field: string;
|
|
437
434
|
operator: string;
|
|
@@ -445,10 +442,10 @@ declare function createResizeNode(id: string, {
|
|
|
445
442
|
retryDelay?: number;
|
|
446
443
|
exponentialBackoff?: boolean;
|
|
447
444
|
};
|
|
448
|
-
circuitBreaker?:
|
|
445
|
+
circuitBreaker?: import("@uploadista/core").FlowCircuitBreakerConfig;
|
|
449
446
|
} & {
|
|
450
|
-
type:
|
|
451
|
-
},
|
|
447
|
+
type: import("@uploadista/core").NodeType;
|
|
448
|
+
}, import("@uploadista/core").UploadistaError, ImagePlugin | import("@uploadista/core").UploadEngine>;
|
|
452
449
|
//#endregion
|
|
453
450
|
//#region src/transform-image-node.d.ts
|
|
454
451
|
/**
|
|
@@ -520,17 +517,17 @@ declare function createTransformImageNode(id: string, {
|
|
|
520
517
|
naming?: FileNamingConfig;
|
|
521
518
|
mode?: TransformMode;
|
|
522
519
|
streamingConfig?: StreamingConfig;
|
|
523
|
-
}): Effect.Effect<
|
|
524
|
-
inputSchema: zod.ZodType<
|
|
525
|
-
outputSchema: zod.ZodType<
|
|
520
|
+
}): Effect.Effect<import("@uploadista/core").FlowNodeData & {
|
|
521
|
+
inputSchema: import("zod").ZodType<import("@uploadista/core").UploadFile, unknown, import("zod/v4/core").$ZodTypeInternals<import("@uploadista/core").UploadFile, unknown>>;
|
|
522
|
+
outputSchema: import("zod").ZodType<import("@uploadista/core").UploadFile, unknown, import("zod/v4/core").$ZodTypeInternals<import("@uploadista/core").UploadFile, unknown>>;
|
|
526
523
|
run: (args: {
|
|
527
|
-
data:
|
|
524
|
+
data: import("@uploadista/core").UploadFile;
|
|
528
525
|
jobId: string;
|
|
529
526
|
storageId: string;
|
|
530
527
|
flowId: string;
|
|
531
528
|
inputs?: Record<string, unknown>;
|
|
532
529
|
clientId: string | null;
|
|
533
|
-
}) => Effect.Effect<
|
|
530
|
+
}) => Effect.Effect<import("@uploadista/core").NodeExecutionResult<import("@uploadista/core").UploadFile>, UploadistaError, never>;
|
|
534
531
|
condition?: {
|
|
535
532
|
field: string;
|
|
536
533
|
operator: string;
|
|
@@ -544,10 +541,10 @@ declare function createTransformImageNode(id: string, {
|
|
|
544
541
|
retryDelay?: number;
|
|
545
542
|
exponentialBackoff?: boolean;
|
|
546
543
|
};
|
|
547
|
-
circuitBreaker?:
|
|
544
|
+
circuitBreaker?: import("@uploadista/core").FlowCircuitBreakerConfig;
|
|
548
545
|
} & {
|
|
549
|
-
type:
|
|
550
|
-
}, UploadistaError, ImagePlugin |
|
|
546
|
+
type: import("@uploadista/core").NodeType;
|
|
547
|
+
}, UploadistaError, ImagePlugin | import("@uploadista/core").UploadEngine>;
|
|
551
548
|
//#endregion
|
|
552
549
|
//#region src/wait-for-url.d.ts
|
|
553
550
|
/**
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/describe-image-node.ts","../src/optimize-node.ts","../src/remove-background-node.ts","../src/resize-node.ts","../src/transform-image-node.ts","../src/wait-for-url.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/describe-image-node.ts","../src/optimize-node.ts","../src/remove-background-node.ts","../src/resize-node.ts","../src/transform-image-node.ts","../src/wait-for-url.ts"],"mappings":";;;;;;;iBAcgB,uBAAA,CACd,EAAA;EAEE,YAAA;EACA;AAAA;EACG,YAAA;EAAuB,UAAA;AAAA,IAA2B,MAAA,CAAA,MAAA,4BAAA,YAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCqDgB,kBAAA,CACd,EAAA;EACE,OAAA;EAAS;AAAA,GAAU,cAAA,EACrB,OAAA;EACE,UAAA;EACA,MAAA,GAAS,gBAAA;EACT,IAAA,GAAO,aAAA;EACP,eAAA,GAAkB,eAAA;AAAA,IACnB,MAAA,CAAA,MAAA,4BAAA,YAAA;;;;;;;;aAsH2vjE,MAAA;;;;;;;;;;;;;;;;;;;;;;;;;ADnL9vjE;;;;;;;;;;;;;;iBEoBgB,0BAAA,CACd,EAAA;EAEE,YAAA;EACA,UAAA;EACA;AAAA;EAEA,YAAA;EACA,UAAA;EACA,MAAA,GAAS,gBAAA;AAAA,IACL,MAAA,CAAA,MAAA,4BAAA,YAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AF9BR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBGgCgB,gBAAA,CACd,EAAA;EACE,KAAA;EAAO,MAAA;EAAQ;AAAA,GAAO,YAAA,EACxB,OAAA;EACE,UAAA;EACA,MAAA,GAAS,gBAAA;EACT,IAAA,GAAO,aAAA;EACP,eAAA,GAAkB,eAAA;AAAA,IACnB,MAAA,CAAA,MAAA,4BAAA,YAAA;;;;;;;;aA8D4ooE,MAAA;;;;;;;;;;;;;;;;;;;;;;;;;;AHtG/ooE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBIuIgB,wBAAA,CACd,EAAA;EACE;AAAA,GAAmB,oBAAA,EACrB,OAAA;EACE,UAAA;EACA,MAAA,GAAS,gBAAA;EACT,IAAA,GAAO,aAAA;EACP,eAAA,GAAkB,eAAA;AAAA,IACnB,MAAA,CAAA,MAAA,4BAAA,YAAA;;;;;;;;aA4D6wgE,MAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;AJ3MhxgE;;;;;;iBKAgB,sBAAA,CACd,GAAA,UACA,OAAA;EACE,WAAA;EACA,UAAA;AAAA,IAED,MAAA,CAAO,MAAM,OAAO,eAAA"}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["UploadistaError"],"sources":["../src/wait-for-url.ts","../src/describe-image-node.ts","../src/optimize-node.ts","../src/remove-background-node.ts","../src/resize-node.ts","../src/transform-image-node.ts"],"sourcesContent":["import { UploadistaError } from \"@uploadista/core/errors\";\nimport { Effect } from \"effect\";\n\n/**\n * Waits for a URL to become available by periodically checking its accessibility.\n * This is useful when a file has just been uploaded and may not be immediately\n * accessible due to CDN propagation or storage consistency delays.\n *\n * @param url - The URL to check for availability\n * @param options - Configuration options\n * @param options.maxWaitTime - Maximum time to wait in milliseconds (default: 10000)\n * @param options.retryDelay - Delay between retries in milliseconds (default: 500)\n * @returns Effect that succeeds when URL is available or fails with UploadistaError\n */\nexport function waitForUrlAvailability(\n url: string,\n options: {\n maxWaitTime?: number;\n retryDelay?: number;\n } = {},\n): Effect.Effect<void, UploadistaError> {\n const { maxWaitTime = 10000, retryDelay = 500 } = options;\n\n return Effect.gen(function* () {\n const startTime = Date.now();\n\n while (Date.now() - startTime < maxWaitTime) {\n const response = yield* Effect.tryPromise(() =>\n fetch(url, { method: \"HEAD\" }),\n ).pipe(Effect.catchAll(() => Effect.succeed(null)));\n\n if (response?.ok) {\n yield* Effect.logInfo(`URL ${url} is now available`);\n return;\n }\n\n if (response) {\n yield* Effect.logDebug(\n `URL not ready yet (${response.status}), retrying...`,\n );\n } else {\n yield* Effect.logDebug(`URL check failed, retrying...`);\n }\n\n yield* Effect.sleep(retryDelay);\n }\n\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause: `URL ${url} not available after ${maxWaitTime}ms`,\n }).toEffect();\n });\n}\n","import { UploadistaError } from \"@uploadista/core/errors\";\nimport {\n completeNodeExecution,\n createFlowNode,\n IMAGE_DESCRIPTION_OUTPUT_TYPE_ID,\n ImageAiPlugin,\n imageDescriptionOutputSchema,\n NodeType,\n} from \"@uploadista/core/flow\";\nimport { uploadFileSchema } from \"@uploadista/core/types\";\n\nimport { Effect } from \"effect\";\nimport { waitForUrlAvailability } from \"./wait-for-url\";\n\nexport function createDescribeImageNode(\n id: string,\n {\n credentialId,\n keepOutput,\n }: { credentialId?: string; keepOutput?: boolean } = {},\n) {\n return Effect.gen(function* () {\n const imageAiService = yield* ImageAiPlugin;\n\n return yield* createFlowNode({\n id,\n name: \"Describe Image\",\n description: \"Describes the image using AI\",\n type: NodeType.process,\n nodeTypeId: \"describe-image\",\n outputTypeId: IMAGE_DESCRIPTION_OUTPUT_TYPE_ID,\n keepOutput,\n inputSchema: uploadFileSchema,\n outputSchema: imageDescriptionOutputSchema,\n // AI service - enable circuit breaker\n // Note: skip fallback cannot be used here because the input schema (UploadFile)\n // differs from the output schema (ImageDescription). Using \"fail\" instead.\n circuitBreaker: {\n enabled: true,\n failureThreshold: 5,\n resetTimeout: 60000,\n fallback: { type: \"fail\" },\n },\n run: ({ data: file, flowId, jobId, clientId }) => {\n return Effect.gen(function* () {\n const flow = {\n flowId,\n nodeId: id,\n jobId,\n };\n\n const fileUrl = file.url;\n\n // Validate input\n if (!fileUrl) {\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause: \"URL is required for describe image operation\",\n }).toEffect();\n }\n\n yield* Effect.logInfo(\n `Describing image for file ${file.id} at URL: ${fileUrl}`,\n );\n\n // Wait for URL to be available with retry mechanism\n yield* waitForUrlAvailability(fileUrl);\n\n // Build context for ImageAI plugin\n const context = {\n clientId,\n credentialId,\n };\n\n // Describe image with error handling\n const result = yield* imageAiService\n .describeImage(fileUrl, context)\n .pipe(\n Effect.catchAll((error) =>\n Effect.gen(function* () {\n yield* Effect.logError(\"Failed to describe image\", error);\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause:\n error instanceof Error\n ? error.message\n : \"Failed to describe image\",\n }).toEffect();\n }),\n ),\n );\n\n yield* Effect.logInfo(\n `Successfully described image for file ${file.id}`,\n );\n\n // Return structured image description output (not UploadFile)\n return completeNodeExecution({\n description: result.description,\n flow,\n });\n });\n },\n });\n });\n}\n","import { UploadistaError } from \"@uploadista/core\";\nimport {\n applyFileNaming,\n buildNamingContext,\n createTransformNode,\n type FileNamingConfig,\n getBaseName,\n ImagePlugin,\n type OptimizeParams,\n STORAGE_OUTPUT_TYPE_ID,\n type StreamingConfig,\n type TransformMode,\n} from \"@uploadista/core/flow\";\nimport { Effect } from \"effect\";\n\n// Map image format to MIME type\nconst formatToMimeType: Record<OptimizeParams[\"format\"], string> = {\n jpeg: \"image/jpeg\",\n webp: \"image/webp\",\n png: \"image/png\",\n avif: \"image/avif\",\n};\n\n// Map image format to file extension\nconst formatToExtension: Record<OptimizeParams[\"format\"], string> = {\n jpeg: \"jpg\",\n webp: \"webp\",\n png: \"png\",\n avif: \"avif\",\n};\n\n/**\n * Creates an optimize node that optimizes images for web delivery.\n *\n * Supports both buffered and streaming modes for memory-efficient processing\n * of large images. In streaming mode, the image is read and processed\n * incrementally, reducing peak memory usage.\n *\n * @param id - Unique node identifier\n * @param params - Optimize parameters (quality, format)\n * @param options - Optional configuration\n * @param options.keepOutput - Whether to keep output in flow results\n * @param options.naming - File naming configuration (auto suffix: `${format}`)\n * @param options.mode - Transform mode: \"buffered\" (default), \"streaming\", or \"auto\"\n * @param options.streamingConfig - Streaming configuration (file size threshold, chunk size)\n *\n * @example\n * ```typescript\n * // Buffered mode (default) - \"photo.jpg\" -> \"photo-webp.webp\"\n * const optimize = yield* createOptimizeNode(\"opt-1\", { quality: 80, format: \"webp\" }, {\n * naming: { mode: \"auto\" }\n * });\n *\n * // Streaming mode for large files\n * const optimizeStreaming = yield* createOptimizeNode(\"opt-2\", { quality: 80, format: \"webp\" }, {\n * mode: \"streaming\",\n * naming: { mode: \"auto\" }\n * });\n *\n * // Auto mode - uses streaming for files > 1MB\n * const optimizeAuto = yield* createOptimizeNode(\"opt-3\", { quality: 80, format: \"webp\" }, {\n * mode: \"auto\",\n * streamingConfig: { fileSizeThreshold: 1_048_576 },\n * naming: { mode: \"auto\" }\n * });\n * ```\n */\nexport function createOptimizeNode(\n id: string,\n { quality, format }: OptimizeParams,\n options?: {\n keepOutput?: boolean;\n naming?: FileNamingConfig;\n mode?: TransformMode;\n streamingConfig?: StreamingConfig;\n },\n) {\n return Effect.gen(function* () {\n const imageService = yield* ImagePlugin;\n\n // Determine if streaming is available and requested\n const supportsStreaming = imageService.supportsStreaming ?? false;\n const requestedMode = options?.mode ?? \"buffered\";\n\n // If streaming requested but not supported, fall back to buffered\n const effectiveMode: TransformMode =\n requestedMode === \"buffered\"\n ? \"buffered\"\n : supportsStreaming\n ? requestedMode\n : \"buffered\";\n\n // Helper to build output metadata from optimized result\n const buildOutputMetadata = (file: {\n metadata?: Record<string, unknown>;\n flow?: { flowId?: string; jobId?: string };\n }) => {\n const newType = formatToMimeType[format];\n const newExtension = formatToExtension[format];\n\n // Get original fileName\n const fileName = file.metadata?.fileName;\n let newFileName: string | undefined;\n\n if (fileName && typeof fileName === \"string\") {\n // Apply naming if configured\n if (options?.naming) {\n const namingConfig: FileNamingConfig = {\n ...options.naming,\n autoSuffix:\n options.naming.autoSuffix ?? ((ctx) => ctx.format ?? format),\n };\n const namingContext = buildNamingContext(\n file as Parameters<typeof buildNamingContext>[0],\n {\n flowId: file.flow?.flowId ?? \"\",\n jobId: file.flow?.jobId ?? \"\",\n nodeId: id,\n nodeType: \"optimize\",\n },\n { format, quality },\n );\n // Apply naming to get base name with suffix\n const namedFile = applyFileNaming(\n file as Parameters<typeof applyFileNaming>[0],\n namingContext,\n namingConfig,\n );\n // Replace extension with new format extension\n newFileName = `${getBaseName(namedFile)}.${newExtension}`;\n } else {\n // No naming config, just update extension\n newFileName = fileName.replace(/\\.[^.]+$/, `.${newExtension}`);\n }\n }\n\n return { newType, newFileName };\n };\n\n return yield* createTransformNode({\n id,\n name: \"Optimize\",\n description: \"Optimizes an image for web delivery\",\n nodeTypeId: \"optimize-image\",\n outputTypeId: STORAGE_OUTPUT_TYPE_ID,\n keepOutput: options?.keepOutput,\n // Note: naming is handled in transform since format changes extension\n nodeType: \"optimize\",\n namingVars: { format, quality },\n mode: effectiveMode,\n streamingConfig: options?.streamingConfig,\n // Buffered transform (used when mode is \"buffered\" or \"auto\" selects buffered)\n transform: (inputBytes, file) =>\n Effect.map(\n imageService.optimize(inputBytes, { quality, format }),\n (optimizedBytes) => {\n const { newType, newFileName } = buildOutputMetadata(file);\n return {\n bytes: optimizedBytes,\n type: newType,\n fileName: newFileName,\n } as\n | Uint8Array\n | { bytes: Uint8Array; type: string; fileName?: string };\n },\n ),\n // Streaming transform (used when mode is \"streaming\" or \"auto\" selects streaming)\n streamingTransform: imageService.optimizeStream\n ? (inputStream, file) => {\n const optimizeStreamFn = imageService.optimizeStream;\n if (!optimizeStreamFn) {\n throw UploadistaError.fromCode(\"UNKNOWN_ERROR\");\n }\n return Effect.gen(function* () {\n // Use the streaming optimization\n const outputStream = yield* optimizeStreamFn(inputStream, {\n quality,\n format,\n });\n\n const { newType, newFileName } = buildOutputMetadata(file);\n\n return {\n stream: outputStream,\n type: newType,\n fileName: newFileName,\n };\n });\n }\n : undefined,\n });\n });\n}\n","import { UploadistaError } from \"@uploadista/core/errors\";\nimport {\n applyFileNaming,\n buildNamingContext,\n completeNodeExecution,\n createFlowNode,\n type FileNamingConfig,\n ImageAiPlugin,\n NodeType,\n resolveUploadMetadata,\n STORAGE_OUTPUT_TYPE_ID,\n} from \"@uploadista/core/flow\";\nimport { uploadFileSchema } from \"@uploadista/core/types\";\nimport { UploadEngine } from \"@uploadista/core/upload\";\nimport { Effect } from \"effect\";\nimport { waitForUrlAvailability } from \"./wait-for-url\";\n\n/**\n * Creates a remove-background node that removes backgrounds from images using AI.\n *\n * @param id - Unique node identifier\n * @param options - Optional configuration\n * @param options.credentialId - Optional credential ID for AI service\n * @param options.keepOutput - Whether to keep output in flow results\n * @param options.naming - File naming configuration (auto suffix: `nobg`)\n *\n * @example\n * ```typescript\n * // With auto-naming: \"photo.jpg\" -> \"photo-nobg.jpg\"\n * const node = yield* createRemoveBackgroundNode(\"remove-bg-1\", {\n * naming: { mode: \"auto\" }\n * });\n * ```\n */\nexport function createRemoveBackgroundNode(\n id: string,\n {\n credentialId,\n keepOutput,\n naming,\n }: {\n credentialId?: string;\n keepOutput?: boolean;\n naming?: FileNamingConfig;\n } = {},\n) {\n return Effect.gen(function* () {\n const imageAiService = yield* ImageAiPlugin;\n const uploadEngine = yield* UploadEngine;\n\n return yield* createFlowNode({\n id,\n name: \"Remove Background\",\n description: \"Removes the background from an image\",\n type: NodeType.process,\n nodeTypeId: \"remove-background\",\n outputTypeId: STORAGE_OUTPUT_TYPE_ID,\n keepOutput,\n inputSchema: uploadFileSchema,\n outputSchema: uploadFileSchema,\n // AI service - enable circuit breaker with skip fallback\n circuitBreaker: {\n enabled: true,\n failureThreshold: 5,\n resetTimeout: 60000,\n fallback: { type: \"skip\", passThrough: true },\n },\n run: ({ data: file, flowId, jobId, storageId, clientId }) => {\n return Effect.gen(function* () {\n const flow = {\n flowId,\n nodeId: id,\n jobId,\n };\n\n const fileUrl = file.url;\n\n // Validate input\n if (!fileUrl) {\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause: \"URL is required for remove background operation\",\n }).toEffect();\n }\n\n yield* Effect.logInfo(\n `Removing background for file ${file.id} at URL: ${file.url}`,\n );\n\n // Wait for URL to be available with retry mechanism\n yield* waitForUrlAvailability(fileUrl);\n\n // Build context for ImageAI plugin\n const context = {\n clientId,\n credentialId,\n };\n\n // Remove background with error handling\n const backgroundRemovalResult = yield* imageAiService\n .removeBackground(fileUrl, context)\n .pipe(\n Effect.catchAll((error) =>\n Effect.gen(function* () {\n yield* Effect.logError(\"Failed to remove background\", error);\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause:\n error instanceof Error\n ? error.message\n : \"Failed to remove background from image\",\n }).toEffect();\n }),\n ),\n );\n\n const { outputUrl } = backgroundRemovalResult;\n const { type, fileName, metadata, metadataJson } =\n resolveUploadMetadata(file.metadata);\n\n // Apply file naming if configured\n let outputFileName = fileName;\n if (naming) {\n const namingConfig: FileNamingConfig = {\n ...naming,\n autoSuffix: naming.autoSuffix ?? (() => \"nobg\"),\n };\n const namingContext = buildNamingContext(file, {\n flowId,\n jobId,\n nodeId: id,\n nodeType: \"remove-background\",\n });\n outputFileName = applyFileNaming(file, namingContext, namingConfig);\n }\n\n yield* Effect.logInfo(`Uploading processed file to storage`);\n\n // Upload the transformed bytes back to the upload server with error handling\n const result = yield* uploadEngine\n .uploadFromUrl(\n {\n storageId,\n size: 0,\n type,\n fileName: outputFileName,\n lastModified: 0,\n metadata: metadataJson,\n flow,\n },\n clientId,\n outputUrl,\n )\n .pipe(\n Effect.catchAll((error) =>\n Effect.gen(function* () {\n yield* Effect.logError(\n \"Failed to upload processed file\",\n error,\n );\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause:\n error instanceof Error\n ? error.message\n : \"Failed to upload processed file\",\n }).toEffect();\n }),\n ),\n );\n\n yield* Effect.logInfo(\n `Successfully removed background for file ${file.id}`,\n );\n\n // Update metadata with new filename if naming was applied\n const updatedMetadata = metadata\n ? {\n ...metadata,\n ...(outputFileName !== fileName && {\n fileName: outputFileName,\n originalName: outputFileName,\n name: outputFileName,\n extension:\n outputFileName.split(\".\").pop() || metadata.extension,\n }),\n }\n : result.metadata;\n\n return completeNodeExecution(\n updatedMetadata\n ? {\n ...result,\n metadata: updatedMetadata,\n }\n : result,\n );\n });\n },\n });\n });\n}\n","import {\n createTransformNode,\n type FileNamingConfig,\n ImagePlugin,\n type ResizeParams,\n STORAGE_OUTPUT_TYPE_ID,\n type StreamingConfig,\n type TransformMode,\n} from \"@uploadista/core/flow\";\nimport { Effect } from \"effect\";\n\n/**\n * Creates a resize node that resizes images to specified dimensions.\n *\n * Supports both buffered and streaming modes for memory-efficient processing\n * of large images. In streaming mode, the image is read and processed\n * incrementally, reducing peak memory usage.\n *\n * @param id - Unique node identifier\n * @param params - Resize parameters (width, height, fit)\n * @param options - Optional configuration\n * @param options.keepOutput - Whether to keep output in flow results\n * @param options.naming - File naming configuration (auto suffix: `${width}x${height}`)\n * @param options.mode - Transform mode: \"buffered\", \"streaming\", or \"auto\" (default)\n * @param options.streamingConfig - Streaming configuration (file size threshold, chunk size)\n *\n * @example\n * ```typescript\n * // Auto mode (default) - uses streaming for files > 1MB, otherwise buffered\n * const resize = yield* createResizeNode(\"resize-1\", { width: 800, height: 600 }, {\n * naming: { mode: \"auto\" }\n * });\n *\n * // Force buffered mode for small files\n * const resizeBuffered = yield* createResizeNode(\"resize-2\", { width: 800, height: 600 }, {\n * mode: \"buffered\",\n * naming: { mode: \"auto\" }\n * });\n *\n * // Force streaming mode for memory efficiency\n * const resizeStreaming = yield* createResizeNode(\"resize-3\", { width: 800, height: 600 }, {\n * mode: \"streaming\",\n * naming: { mode: \"auto\" }\n * });\n * ```\n */\nexport function createResizeNode(\n id: string,\n { width, height, fit }: ResizeParams,\n options?: {\n keepOutput?: boolean;\n naming?: FileNamingConfig;\n mode?: TransformMode;\n streamingConfig?: StreamingConfig;\n },\n) {\n return Effect.gen(function* () {\n const imageService = yield* ImagePlugin;\n\n // Determine if streaming is available and requested\n const supportsStreaming = imageService.supportsStreaming ?? false;\n const requestedMode = options?.mode ?? \"auto\";\n\n // If streaming requested but not supported, fall back to buffered\n const effectiveMode: TransformMode =\n requestedMode === \"buffered\"\n ? \"buffered\"\n : supportsStreaming\n ? requestedMode\n : \"buffered\";\n\n // Build naming config with auto suffix for resize\n const namingConfig: FileNamingConfig | undefined = options?.naming\n ? {\n ...options.naming,\n // Provide default auto suffix generator for resize nodes\n autoSuffix:\n options.naming.autoSuffix ??\n ((ctx) => `${ctx.width ?? width}x${ctx.height ?? height}`),\n }\n : undefined;\n\n return yield* createTransformNode({\n id,\n name: \"Resize\",\n description: \"Resizes an image to the specified dimensions\",\n nodeTypeId: \"resize-image\",\n outputTypeId: STORAGE_OUTPUT_TYPE_ID,\n keepOutput: options?.keepOutput,\n naming: namingConfig,\n nodeType: \"resize\",\n namingVars: { width, height },\n mode: effectiveMode,\n streamingConfig: options?.streamingConfig,\n // Buffered transform (used when mode is \"buffered\" or \"auto\" selects buffered)\n transform: (inputBytes) =>\n imageService.resize(inputBytes, { height, width, fit }),\n // Streaming transform (used when mode is \"streaming\" or \"auto\" selects streaming)\n streamingTransform: imageService.resizeStream\n ? (inputStream) =>\n Effect.gen(function* () {\n const resizeStreamFn = imageService.resizeStream;\n if (!resizeStreamFn) {\n throw new Error(\"resizeStream not available\");\n }\n const outputStream = yield* resizeStreamFn(inputStream, {\n width,\n height,\n fit,\n });\n return { stream: outputStream };\n })\n : undefined,\n });\n });\n}\n","import type { UploadistaError } from \"@uploadista/core/errors\";\nimport {\n createTransformNode,\n type FileNamingConfig,\n ImagePlugin,\n STORAGE_OUTPUT_TYPE_ID,\n type StreamingConfig,\n type TransformImageParams,\n type TransformMode,\n} from \"@uploadista/core/flow\";\nimport { Effect, Stream } from \"effect\";\n\n/**\n * Apply a chain of transformations to an image by reducing over the transformations array.\n * Each transformation receives the output of the previous transformation as input.\n *\n * @param imageService - The image plugin service to use for transformations\n * @param inputBytes - The input image bytes\n * @param transformations - Array of transformations to apply in sequence\n * @returns Effect that resolves to the final transformed image bytes\n */\nfunction applyTransformationChain(\n imageService: ReturnType<typeof ImagePlugin.of>,\n inputBytes: Uint8Array,\n transformations: TransformImageParams[\"transformations\"],\n) {\n return Effect.reduce(transformations, inputBytes, (bytes, transformation) =>\n imageService.transform(bytes, transformation),\n );\n}\n\n/**\n * Apply a chain of transformations using streaming where possible.\n * Falls back to buffered processing for transformations that don't support streaming.\n *\n * @param imageService - The image plugin service to use for transformations\n * @param inputStream - The input image as a stream\n * @param transformations - Array of transformations to apply in sequence\n * @returns Effect that resolves to the final transformed image stream\n */\nfunction applyStreamingTransformationChain(\n imageService: ReturnType<typeof ImagePlugin.of>,\n inputStream: Stream.Stream<Uint8Array, UploadistaError>,\n transformations: TransformImageParams[\"transformations\"],\n): Effect.Effect<Stream.Stream<Uint8Array, UploadistaError>, UploadistaError> {\n const transformStreamFn = imageService.transformStream;\n\n if (!transformStreamFn) {\n // If streaming not supported, collect to buffer and use buffered chain\n return Effect.gen(function* () {\n // Collect stream to buffer\n const chunks: Uint8Array[] = [];\n yield* Stream.runForEach(inputStream, (chunk) =>\n Effect.sync(() => {\n chunks.push(chunk);\n }),\n );\n const totalLength = chunks.reduce((sum, c) => sum + c.byteLength, 0);\n const inputBuffer = new Uint8Array(totalLength);\n let offset = 0;\n for (const chunk of chunks) {\n inputBuffer.set(chunk, offset);\n offset += chunk.byteLength;\n }\n\n // Apply transformations\n const result = yield* applyTransformationChain(\n imageService,\n inputBuffer,\n transformations,\n );\n return Stream.make(result);\n });\n }\n\n // Apply each transformation in sequence using streaming\n return Effect.reduce(\n transformations,\n inputStream,\n (currentStream, transformation) =>\n Effect.flatMap(\n transformStreamFn(currentStream, transformation),\n (outputStream) => Effect.succeed(outputStream),\n ),\n );\n}\n\n/**\n * Creates a transform image node that applies multiple transformations sequentially.\n *\n * This node enables complex image processing workflows by chaining multiple transformations\n * together. Each transformation is applied to the output of the previous transformation,\n * allowing for powerful image manipulation pipelines.\n *\n * Supports both buffered and streaming modes for memory-efficient processing\n * of large images. In streaming mode, each transformation is applied in sequence\n * using streaming where supported.\n *\n * Supported transformations include:\n * - Basic: resize, blur, rotate, flip\n * - Filters: grayscale, sepia, brightness, contrast\n * - Effects: sharpen\n * - Advanced: watermark, logo, text (streaming not supported for these)\n *\n * Note: Watermark and logo transformations require imagePath to be a valid URL.\n * Images will be fetched from the provided URL during transformation.\n * Streaming mode is not supported for watermark, logo, and text transformations;\n * these will cause fallback to buffered mode.\n *\n * @param id - Unique identifier for this node\n * @param params - Parameters including the transformations array\n * @param options - Optional configuration\n * @param options.keepOutput - Whether to keep output in flow results\n * @param options.naming - File naming configuration (auto suffix: `transformed`)\n * @param options.mode - Transform mode: \"buffered\", \"streaming\", or \"auto\" (default)\n * @param options.streamingConfig - Streaming configuration (file size threshold, chunk size)\n *\n * @example\n * ```typescript\n * // Auto mode (default) - uses streaming for files > 1MB, otherwise buffered\n * const node = yield* createTransformImageNode(\"transform-1\", {\n * transformations: [\n * { type: 'resize', width: 800, height: 600, fit: 'cover' },\n * { type: 'brightness', value: 20 }\n * ]\n * }, {\n * naming: { mode: \"auto\" }\n * });\n *\n * // Force buffered mode for small files\n * const nodeBuffered = yield* createTransformImageNode(\"transform-2\", {\n * transformations: [\n * { type: 'resize', width: 800, height: 600, fit: 'cover' },\n * { type: 'blur', sigma: 5 }\n * ]\n * }, {\n * mode: \"buffered\",\n * naming: { mode: \"auto\" }\n * });\n *\n * // Force streaming mode for memory efficiency\n * const nodeStreaming = yield* createTransformImageNode(\"transform-3\", {\n * transformations: [{ type: 'grayscale' }]\n * }, {\n * mode: \"streaming\",\n * naming: { mode: \"auto\" }\n * });\n * ```\n */\nexport function createTransformImageNode(\n id: string,\n { transformations }: TransformImageParams,\n options?: {\n keepOutput?: boolean;\n naming?: FileNamingConfig;\n mode?: TransformMode;\n streamingConfig?: StreamingConfig;\n },\n) {\n return Effect.gen(function* () {\n const imageService = yield* ImagePlugin;\n\n // Determine if streaming is available and requested\n const supportsStreaming = imageService.supportsStreaming ?? false;\n const requestedMode = options?.mode ?? \"auto\";\n\n // Check if any transformations don't support streaming\n const hasUnsupportedTransformations = transformations.some(\n (t) => t.type === \"watermark\" || t.type === \"logo\" || t.type === \"text\",\n );\n\n // If streaming requested but not supported or unsupported transformations, fall back to buffered\n const effectiveMode: TransformMode =\n requestedMode === \"buffered\"\n ? \"buffered\"\n : supportsStreaming && !hasUnsupportedTransformations\n ? requestedMode\n : \"buffered\";\n\n // Build naming config with auto suffix for transform-image\n const namingConfig: FileNamingConfig | undefined = options?.naming\n ? {\n ...options.naming,\n autoSuffix: options.naming.autoSuffix ?? (() => \"transformed\"),\n }\n : undefined;\n\n return yield* createTransformNode({\n id,\n name: \"Transform Image\",\n description: `Apply ${transformations.length} transformation${transformations.length === 1 ? \"\" : \"s\"} to the image`,\n nodeTypeId: \"transform-image\",\n outputTypeId: STORAGE_OUTPUT_TYPE_ID,\n keepOutput: options?.keepOutput,\n naming: namingConfig,\n nodeType: \"transform-image\",\n mode: effectiveMode,\n streamingConfig: options?.streamingConfig,\n // Buffered transform (used when mode is \"buffered\" or \"auto\" selects buffered)\n transform: (inputBytes) =>\n applyTransformationChain(imageService, inputBytes, transformations),\n // Streaming transform (used when mode is \"streaming\" or \"auto\" selects streaming)\n streamingTransform:\n supportsStreaming && !hasUnsupportedTransformations\n ? (inputStream) =>\n Effect.gen(function* () {\n const outputStream = yield* applyStreamingTransformationChain(\n imageService,\n inputStream,\n transformations,\n );\n return { stream: outputStream };\n })\n : undefined,\n });\n });\n}\n"],"mappings":"omBAcA,SAAgB,EACd,EACA,EAGI,EAAE,CACgC,CACtC,GAAM,CAAE,cAAc,IAAO,aAAa,KAAQ,EAElD,OAAO,EAAO,IAAI,WAAa,CAC7B,IAAM,EAAY,KAAK,KAAK,CAE5B,KAAO,KAAK,KAAK,CAAG,EAAY,GAAa,CAC3C,IAAM,EAAW,MAAO,EAAO,eAC7B,MAAM,EAAK,CAAE,OAAQ,OAAQ,CAAC,CAC/B,CAAC,KAAK,EAAO,aAAe,EAAO,QAAQ,KAAK,CAAC,CAAC,CAEnD,GAAI,GAAU,GAAI,CAChB,MAAO,EAAO,QAAQ,OAAO,EAAI,mBAAmB,CACpD,OAGE,EACF,MAAO,EAAO,SACZ,sBAAsB,EAAS,OAAO,gBACvC,CAED,MAAO,EAAO,SAAS,gCAAgC,CAGzD,MAAO,EAAO,MAAM,EAAW,CAGjC,OAAO,MAAO,EAAgB,SAAS,kBAAmB,CACxD,MAAO,OAAO,EAAI,uBAAuB,EAAY,IACtD,CAAC,CAAC,UAAU,EACb,CCpCJ,SAAgB,EACd,EACA,CACE,eACA,cACmD,EAAE,CACvD,CACA,OAAO,EAAO,IAAI,WAAa,CAC7B,IAAM,EAAiB,MAAO,EAE9B,OAAO,MAAO,EAAe,CAC3B,KACA,KAAM,iBACN,YAAa,+BACb,KAAM,EAAS,QACf,WAAY,iBACZ,aAAc,EACd,aACA,YAAa,EACb,aAAc,EAId,eAAgB,CACd,QAAS,GACT,iBAAkB,EAClB,aAAc,IACd,SAAU,CAAE,KAAM,OAAQ,CAC3B,CACD,KAAM,CAAE,KAAM,EAAM,SAAQ,QAAO,cAC1B,EAAO,IAAI,WAAa,CAC7B,IAAM,EAAO,CACX,SACA,OAAQ,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,EAAgB,CAErE,mBACE,GAAqB,CAAC,EACjB,GACC,EAAO,IAAI,WAAa,CAMtB,MAAO,CAAE,OALY,MAAO,EAC1B,EACA,EACA,EACD,CAC8B,EAC/B,CACJ,IAAA,GACP,CAAC,EACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["UploadistaError"],"sources":["../src/wait-for-url.ts","../src/describe-image-node.ts","../src/optimize-node.ts","../src/remove-background-node.ts","../src/resize-node.ts","../src/transform-image-node.ts"],"sourcesContent":["import { UploadistaError } from \"@uploadista/core/errors\";\nimport { Effect } from \"effect\";\n\n/**\n * Waits for a URL to become available by periodically checking its accessibility.\n * This is useful when a file has just been uploaded and may not be immediately\n * accessible due to CDN propagation or storage consistency delays.\n *\n * @param url - The URL to check for availability\n * @param options - Configuration options\n * @param options.maxWaitTime - Maximum time to wait in milliseconds (default: 10000)\n * @param options.retryDelay - Delay between retries in milliseconds (default: 500)\n * @returns Effect that succeeds when URL is available or fails with UploadistaError\n */\nexport function waitForUrlAvailability(\n url: string,\n options: {\n maxWaitTime?: number;\n retryDelay?: number;\n } = {},\n): Effect.Effect<void, UploadistaError> {\n const { maxWaitTime = 10000, retryDelay = 500 } = options;\n\n return Effect.gen(function* () {\n const startTime = Date.now();\n\n while (Date.now() - startTime < maxWaitTime) {\n const response = yield* Effect.tryPromise(() =>\n fetch(url, { method: \"HEAD\" }),\n ).pipe(Effect.catchAll(() => Effect.succeed(null)));\n\n if (response?.ok) {\n yield* Effect.logInfo(`URL ${url} is now available`);\n return;\n }\n\n if (response) {\n yield* Effect.logDebug(\n `URL not ready yet (${response.status}), retrying...`,\n );\n } else {\n yield* Effect.logDebug(`URL check failed, retrying...`);\n }\n\n yield* Effect.sleep(retryDelay);\n }\n\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause: `URL ${url} not available after ${maxWaitTime}ms`,\n }).toEffect();\n });\n}\n","import { UploadistaError } from \"@uploadista/core/errors\";\nimport {\n completeNodeExecution,\n createFlowNode,\n IMAGE_DESCRIPTION_OUTPUT_TYPE_ID,\n ImageAiPlugin,\n imageDescriptionOutputSchema,\n NodeType,\n} from \"@uploadista/core/flow\";\nimport { uploadFileSchema } from \"@uploadista/core/types\";\n\nimport { Effect } from \"effect\";\nimport { waitForUrlAvailability } from \"./wait-for-url\";\n\nexport function createDescribeImageNode(\n id: string,\n {\n credentialId,\n keepOutput,\n }: { credentialId?: string; keepOutput?: boolean } = {},\n) {\n return Effect.gen(function* () {\n const imageAiService = yield* ImageAiPlugin;\n\n return yield* createFlowNode({\n id,\n name: \"Describe Image\",\n description: \"Describes the image using AI\",\n type: NodeType.process,\n nodeTypeId: \"describe-image\",\n outputTypeId: IMAGE_DESCRIPTION_OUTPUT_TYPE_ID,\n keepOutput,\n inputSchema: uploadFileSchema,\n outputSchema: imageDescriptionOutputSchema,\n // AI service - enable circuit breaker\n // Note: skip fallback cannot be used here because the input schema (UploadFile)\n // differs from the output schema (ImageDescription). Using \"fail\" instead.\n circuitBreaker: {\n enabled: true,\n failureThreshold: 5,\n resetTimeout: 60000,\n fallback: { type: \"fail\" },\n },\n run: ({ data: file, flowId, jobId, clientId }) => {\n return Effect.gen(function* () {\n const flow = {\n flowId,\n nodeId: id,\n jobId,\n };\n\n const fileUrl = file.url;\n\n // Validate input\n if (!fileUrl) {\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause: \"URL is required for describe image operation\",\n }).toEffect();\n }\n\n yield* Effect.logInfo(\n `Describing image for file ${file.id} at URL: ${fileUrl}`,\n );\n\n // Wait for URL to be available with retry mechanism\n yield* waitForUrlAvailability(fileUrl);\n\n // Build context for ImageAI plugin\n const context = {\n clientId,\n credentialId,\n };\n\n // Describe image with error handling\n const result = yield* imageAiService\n .describeImage(fileUrl, context)\n .pipe(\n Effect.catchAll((error) =>\n Effect.gen(function* () {\n yield* Effect.logError(\"Failed to describe image\", error);\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause:\n error instanceof Error\n ? error.message\n : \"Failed to describe image\",\n }).toEffect();\n }),\n ),\n );\n\n yield* Effect.logInfo(\n `Successfully described image for file ${file.id}`,\n );\n\n // Return structured image description output (not UploadFile)\n return completeNodeExecution({\n description: result.description,\n flow,\n });\n });\n },\n });\n });\n}\n","import { UploadistaError } from \"@uploadista/core\";\nimport {\n applyFileNaming,\n buildNamingContext,\n createTransformNode,\n type FileNamingConfig,\n getBaseName,\n ImagePlugin,\n type OptimizeParams,\n STORAGE_OUTPUT_TYPE_ID,\n type StreamingConfig,\n type TransformMode,\n} from \"@uploadista/core/flow\";\nimport { Effect } from \"effect\";\n\n// Map image format to MIME type\nconst formatToMimeType: Record<OptimizeParams[\"format\"], string> = {\n jpeg: \"image/jpeg\",\n webp: \"image/webp\",\n png: \"image/png\",\n avif: \"image/avif\",\n};\n\n// Map image format to file extension\nconst formatToExtension: Record<OptimizeParams[\"format\"], string> = {\n jpeg: \"jpg\",\n webp: \"webp\",\n png: \"png\",\n avif: \"avif\",\n};\n\n/**\n * Creates an optimize node that optimizes images for web delivery.\n *\n * Supports both buffered and streaming modes for memory-efficient processing\n * of large images. In streaming mode, the image is read and processed\n * incrementally, reducing peak memory usage.\n *\n * @param id - Unique node identifier\n * @param params - Optimize parameters (quality, format)\n * @param options - Optional configuration\n * @param options.keepOutput - Whether to keep output in flow results\n * @param options.naming - File naming configuration (auto suffix: `${format}`)\n * @param options.mode - Transform mode: \"buffered\" (default), \"streaming\", or \"auto\"\n * @param options.streamingConfig - Streaming configuration (file size threshold, chunk size)\n *\n * @example\n * ```typescript\n * // Buffered mode (default) - \"photo.jpg\" -> \"photo-webp.webp\"\n * const optimize = yield* createOptimizeNode(\"opt-1\", { quality: 80, format: \"webp\" }, {\n * naming: { mode: \"auto\" }\n * });\n *\n * // Streaming mode for large files\n * const optimizeStreaming = yield* createOptimizeNode(\"opt-2\", { quality: 80, format: \"webp\" }, {\n * mode: \"streaming\",\n * naming: { mode: \"auto\" }\n * });\n *\n * // Auto mode - uses streaming for files > 1MB\n * const optimizeAuto = yield* createOptimizeNode(\"opt-3\", { quality: 80, format: \"webp\" }, {\n * mode: \"auto\",\n * streamingConfig: { fileSizeThreshold: 1_048_576 },\n * naming: { mode: \"auto\" }\n * });\n * ```\n */\nexport function createOptimizeNode(\n id: string,\n { quality, format }: OptimizeParams,\n options?: {\n keepOutput?: boolean;\n naming?: FileNamingConfig;\n mode?: TransformMode;\n streamingConfig?: StreamingConfig;\n },\n) {\n return Effect.gen(function* () {\n const imageService = yield* ImagePlugin;\n\n // Determine if streaming is available and requested\n const supportsStreaming = imageService.supportsStreaming ?? false;\n const requestedMode = options?.mode ?? \"buffered\";\n\n // If streaming requested but not supported, fall back to buffered\n const effectiveMode: TransformMode =\n requestedMode === \"buffered\"\n ? \"buffered\"\n : supportsStreaming\n ? requestedMode\n : \"buffered\";\n\n // Helper to build output metadata from optimized result\n const buildOutputMetadata = (file: {\n metadata?: Record<string, unknown>;\n flow?: { flowId?: string; jobId?: string };\n }) => {\n const newType = formatToMimeType[format];\n const newExtension = formatToExtension[format];\n\n // Get original fileName\n const fileName = file.metadata?.fileName;\n let newFileName: string | undefined;\n\n if (fileName && typeof fileName === \"string\") {\n // Apply naming if configured\n if (options?.naming) {\n const namingConfig: FileNamingConfig = {\n ...options.naming,\n autoSuffix:\n options.naming.autoSuffix ?? ((ctx) => ctx.format ?? format),\n };\n const namingContext = buildNamingContext(\n file as Parameters<typeof buildNamingContext>[0],\n {\n flowId: file.flow?.flowId ?? \"\",\n jobId: file.flow?.jobId ?? \"\",\n nodeId: id,\n nodeType: \"optimize\",\n },\n { format, quality },\n );\n // Apply naming to get base name with suffix\n const namedFile = applyFileNaming(\n file as Parameters<typeof applyFileNaming>[0],\n namingContext,\n namingConfig,\n );\n // Replace extension with new format extension\n newFileName = `${getBaseName(namedFile)}.${newExtension}`;\n } else {\n // No naming config, just update extension\n newFileName = fileName.replace(/\\.[^.]+$/, `.${newExtension}`);\n }\n }\n\n return { newType, newFileName };\n };\n\n return yield* createTransformNode({\n id,\n name: \"Optimize\",\n description: \"Optimizes an image for web delivery\",\n nodeTypeId: \"optimize-image\",\n outputTypeId: STORAGE_OUTPUT_TYPE_ID,\n keepOutput: options?.keepOutput,\n // Note: naming is handled in transform since format changes extension\n nodeType: \"optimize\",\n namingVars: { format, quality },\n mode: effectiveMode,\n streamingConfig: options?.streamingConfig,\n // Buffered transform (used when mode is \"buffered\" or \"auto\" selects buffered)\n transform: (inputBytes, file) =>\n Effect.map(\n imageService.optimize(inputBytes, { quality, format }),\n (optimizedBytes) => {\n const { newType, newFileName } = buildOutputMetadata(file);\n return {\n bytes: optimizedBytes,\n type: newType,\n fileName: newFileName,\n } as\n | Uint8Array\n | { bytes: Uint8Array; type: string; fileName?: string };\n },\n ),\n // Streaming transform (used when mode is \"streaming\" or \"auto\" selects streaming)\n streamingTransform: imageService.optimizeStream\n ? (inputStream, file) => {\n const optimizeStreamFn = imageService.optimizeStream;\n if (!optimizeStreamFn) {\n throw UploadistaError.fromCode(\"UNKNOWN_ERROR\");\n }\n return Effect.gen(function* () {\n // Use the streaming optimization\n const outputStream = yield* optimizeStreamFn(inputStream, {\n quality,\n format,\n });\n\n const { newType, newFileName } = buildOutputMetadata(file);\n\n return {\n stream: outputStream,\n type: newType,\n fileName: newFileName,\n };\n });\n }\n : undefined,\n });\n });\n}\n","import { UploadistaError } from \"@uploadista/core/errors\";\nimport {\n applyFileNaming,\n buildNamingContext,\n completeNodeExecution,\n createFlowNode,\n type FileNamingConfig,\n ImageAiPlugin,\n NodeType,\n resolveUploadMetadata,\n STORAGE_OUTPUT_TYPE_ID,\n} from \"@uploadista/core/flow\";\nimport { uploadFileSchema } from \"@uploadista/core/types\";\nimport { UploadEngine } from \"@uploadista/core/upload\";\nimport { Effect } from \"effect\";\nimport { waitForUrlAvailability } from \"./wait-for-url\";\n\n/**\n * Creates a remove-background node that removes backgrounds from images using AI.\n *\n * @param id - Unique node identifier\n * @param options - Optional configuration\n * @param options.credentialId - Optional credential ID for AI service\n * @param options.keepOutput - Whether to keep output in flow results\n * @param options.naming - File naming configuration (auto suffix: `nobg`)\n *\n * @example\n * ```typescript\n * // With auto-naming: \"photo.jpg\" -> \"photo-nobg.jpg\"\n * const node = yield* createRemoveBackgroundNode(\"remove-bg-1\", {\n * naming: { mode: \"auto\" }\n * });\n * ```\n */\nexport function createRemoveBackgroundNode(\n id: string,\n {\n credentialId,\n keepOutput,\n naming,\n }: {\n credentialId?: string;\n keepOutput?: boolean;\n naming?: FileNamingConfig;\n } = {},\n) {\n return Effect.gen(function* () {\n const imageAiService = yield* ImageAiPlugin;\n const uploadEngine = yield* UploadEngine;\n\n return yield* createFlowNode({\n id,\n name: \"Remove Background\",\n description: \"Removes the background from an image\",\n type: NodeType.process,\n nodeTypeId: \"remove-background\",\n outputTypeId: STORAGE_OUTPUT_TYPE_ID,\n keepOutput,\n inputSchema: uploadFileSchema,\n outputSchema: uploadFileSchema,\n // AI service - enable circuit breaker with skip fallback\n circuitBreaker: {\n enabled: true,\n failureThreshold: 5,\n resetTimeout: 60000,\n fallback: { type: \"skip\", passThrough: true },\n },\n run: ({ data: file, flowId, jobId, storageId, clientId }) => {\n return Effect.gen(function* () {\n const flow = {\n flowId,\n nodeId: id,\n jobId,\n };\n\n const fileUrl = file.url;\n\n // Validate input\n if (!fileUrl) {\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause: \"URL is required for remove background operation\",\n }).toEffect();\n }\n\n yield* Effect.logInfo(\n `Removing background for file ${file.id} at URL: ${file.url}`,\n );\n\n // Wait for URL to be available with retry mechanism\n yield* waitForUrlAvailability(fileUrl);\n\n // Build context for ImageAI plugin\n const context = {\n clientId,\n credentialId,\n };\n\n // Remove background with error handling\n const backgroundRemovalResult = yield* imageAiService\n .removeBackground(fileUrl, context)\n .pipe(\n Effect.catchAll((error) =>\n Effect.gen(function* () {\n yield* Effect.logError(\"Failed to remove background\", error);\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause:\n error instanceof Error\n ? error.message\n : \"Failed to remove background from image\",\n }).toEffect();\n }),\n ),\n );\n\n const { outputUrl } = backgroundRemovalResult;\n const { type, fileName, metadata, metadataJson } =\n resolveUploadMetadata(file.metadata);\n\n // Apply file naming if configured\n let outputFileName = fileName;\n if (naming) {\n const namingConfig: FileNamingConfig = {\n ...naming,\n autoSuffix: naming.autoSuffix ?? (() => \"nobg\"),\n };\n const namingContext = buildNamingContext(file, {\n flowId,\n jobId,\n nodeId: id,\n nodeType: \"remove-background\",\n });\n outputFileName = applyFileNaming(file, namingContext, namingConfig);\n }\n\n yield* Effect.logInfo(`Uploading processed file to storage`);\n\n // Upload the transformed bytes back to the upload server with error handling\n const result = yield* uploadEngine\n .uploadFromUrl(\n {\n storageId,\n size: 0,\n type,\n fileName: outputFileName,\n lastModified: 0,\n metadata: metadataJson,\n flow,\n },\n clientId,\n outputUrl,\n )\n .pipe(\n Effect.catchAll((error) =>\n Effect.gen(function* () {\n yield* Effect.logError(\n \"Failed to upload processed file\",\n error,\n );\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause:\n error instanceof Error\n ? error.message\n : \"Failed to upload processed file\",\n }).toEffect();\n }),\n ),\n );\n\n yield* Effect.logInfo(\n `Successfully removed background for file ${file.id}`,\n );\n\n // Update metadata with new filename if naming was applied\n const updatedMetadata = metadata\n ? {\n ...metadata,\n ...(outputFileName !== fileName && {\n fileName: outputFileName,\n originalName: outputFileName,\n name: outputFileName,\n extension:\n outputFileName.split(\".\").pop() || metadata.extension,\n }),\n }\n : result.metadata;\n\n return completeNodeExecution(\n updatedMetadata\n ? {\n ...result,\n metadata: updatedMetadata,\n }\n : result,\n );\n });\n },\n });\n });\n}\n","import {\n createTransformNode,\n type FileNamingConfig,\n ImagePlugin,\n type ResizeParams,\n STORAGE_OUTPUT_TYPE_ID,\n type StreamingConfig,\n type TransformMode,\n} from \"@uploadista/core/flow\";\nimport { Effect } from \"effect\";\n\n/**\n * Creates a resize node that resizes images to specified dimensions.\n *\n * Supports both buffered and streaming modes for memory-efficient processing\n * of large images. In streaming mode, the image is read and processed\n * incrementally, reducing peak memory usage.\n *\n * @param id - Unique node identifier\n * @param params - Resize parameters (width, height, fit)\n * @param options - Optional configuration\n * @param options.keepOutput - Whether to keep output in flow results\n * @param options.naming - File naming configuration (auto suffix: `${width}x${height}`)\n * @param options.mode - Transform mode: \"buffered\", \"streaming\", or \"auto\" (default)\n * @param options.streamingConfig - Streaming configuration (file size threshold, chunk size)\n *\n * @example\n * ```typescript\n * // Auto mode (default) - uses streaming for files > 1MB, otherwise buffered\n * const resize = yield* createResizeNode(\"resize-1\", { width: 800, height: 600 }, {\n * naming: { mode: \"auto\" }\n * });\n *\n * // Force buffered mode for small files\n * const resizeBuffered = yield* createResizeNode(\"resize-2\", { width: 800, height: 600 }, {\n * mode: \"buffered\",\n * naming: { mode: \"auto\" }\n * });\n *\n * // Force streaming mode for memory efficiency\n * const resizeStreaming = yield* createResizeNode(\"resize-3\", { width: 800, height: 600 }, {\n * mode: \"streaming\",\n * naming: { mode: \"auto\" }\n * });\n * ```\n */\nexport function createResizeNode(\n id: string,\n { width, height, fit }: ResizeParams,\n options?: {\n keepOutput?: boolean;\n naming?: FileNamingConfig;\n mode?: TransformMode;\n streamingConfig?: StreamingConfig;\n },\n) {\n return Effect.gen(function* () {\n const imageService = yield* ImagePlugin;\n\n // Determine if streaming is available and requested\n const supportsStreaming = imageService.supportsStreaming ?? false;\n const requestedMode = options?.mode ?? \"auto\";\n\n // If streaming requested but not supported, fall back to buffered\n const effectiveMode: TransformMode =\n requestedMode === \"buffered\"\n ? \"buffered\"\n : supportsStreaming\n ? requestedMode\n : \"buffered\";\n\n // Build naming config with auto suffix for resize\n const namingConfig: FileNamingConfig | undefined = options?.naming\n ? {\n ...options.naming,\n // Provide default auto suffix generator for resize nodes\n autoSuffix:\n options.naming.autoSuffix ??\n ((ctx) => `${ctx.width ?? width}x${ctx.height ?? height}`),\n }\n : undefined;\n\n return yield* createTransformNode({\n id,\n name: \"Resize\",\n description: \"Resizes an image to the specified dimensions\",\n nodeTypeId: \"resize-image\",\n outputTypeId: STORAGE_OUTPUT_TYPE_ID,\n keepOutput: options?.keepOutput,\n naming: namingConfig,\n nodeType: \"resize\",\n namingVars: { width, height },\n mode: effectiveMode,\n streamingConfig: options?.streamingConfig,\n // Buffered transform (used when mode is \"buffered\" or \"auto\" selects buffered)\n transform: (inputBytes) =>\n imageService.resize(inputBytes, { height, width, fit }),\n // Streaming transform (used when mode is \"streaming\" or \"auto\" selects streaming)\n streamingTransform: imageService.resizeStream\n ? (inputStream) =>\n Effect.gen(function* () {\n const resizeStreamFn = imageService.resizeStream;\n if (!resizeStreamFn) {\n throw new Error(\"resizeStream not available\");\n }\n const outputStream = yield* resizeStreamFn(inputStream, {\n width,\n height,\n fit,\n });\n return { stream: outputStream };\n })\n : undefined,\n });\n });\n}\n","import type { UploadistaError } from \"@uploadista/core/errors\";\nimport {\n createTransformNode,\n type FileNamingConfig,\n ImagePlugin,\n STORAGE_OUTPUT_TYPE_ID,\n type StreamingConfig,\n type TransformImageParams,\n type TransformMode,\n} from \"@uploadista/core/flow\";\nimport { Effect, Stream } from \"effect\";\n\n/**\n * Apply a chain of transformations to an image by reducing over the transformations array.\n * Each transformation receives the output of the previous transformation as input.\n *\n * @param imageService - The image plugin service to use for transformations\n * @param inputBytes - The input image bytes\n * @param transformations - Array of transformations to apply in sequence\n * @returns Effect that resolves to the final transformed image bytes\n */\nfunction applyTransformationChain(\n imageService: ReturnType<typeof ImagePlugin.of>,\n inputBytes: Uint8Array,\n transformations: TransformImageParams[\"transformations\"],\n) {\n return Effect.reduce(transformations, inputBytes, (bytes, transformation) =>\n imageService.transform(bytes, transformation),\n );\n}\n\n/**\n * Apply a chain of transformations using streaming where possible.\n * Falls back to buffered processing for transformations that don't support streaming.\n *\n * @param imageService - The image plugin service to use for transformations\n * @param inputStream - The input image as a stream\n * @param transformations - Array of transformations to apply in sequence\n * @returns Effect that resolves to the final transformed image stream\n */\nfunction applyStreamingTransformationChain(\n imageService: ReturnType<typeof ImagePlugin.of>,\n inputStream: Stream.Stream<Uint8Array, UploadistaError>,\n transformations: TransformImageParams[\"transformations\"],\n): Effect.Effect<Stream.Stream<Uint8Array, UploadistaError>, UploadistaError> {\n const transformStreamFn = imageService.transformStream;\n\n if (!transformStreamFn) {\n // If streaming not supported, collect to buffer and use buffered chain\n return Effect.gen(function* () {\n // Collect stream to buffer\n const chunks: Uint8Array[] = [];\n yield* Stream.runForEach(inputStream, (chunk) =>\n Effect.sync(() => {\n chunks.push(chunk);\n }),\n );\n const totalLength = chunks.reduce((sum, c) => sum + c.byteLength, 0);\n const inputBuffer = new Uint8Array(totalLength);\n let offset = 0;\n for (const chunk of chunks) {\n inputBuffer.set(chunk, offset);\n offset += chunk.byteLength;\n }\n\n // Apply transformations\n const result = yield* applyTransformationChain(\n imageService,\n inputBuffer,\n transformations,\n );\n return Stream.make(result);\n });\n }\n\n // Apply each transformation in sequence using streaming\n return Effect.reduce(\n transformations,\n inputStream,\n (currentStream, transformation) =>\n Effect.flatMap(\n transformStreamFn(currentStream, transformation),\n (outputStream) => Effect.succeed(outputStream),\n ),\n );\n}\n\n/**\n * Creates a transform image node that applies multiple transformations sequentially.\n *\n * This node enables complex image processing workflows by chaining multiple transformations\n * together. Each transformation is applied to the output of the previous transformation,\n * allowing for powerful image manipulation pipelines.\n *\n * Supports both buffered and streaming modes for memory-efficient processing\n * of large images. In streaming mode, each transformation is applied in sequence\n * using streaming where supported.\n *\n * Supported transformations include:\n * - Basic: resize, blur, rotate, flip\n * - Filters: grayscale, sepia, brightness, contrast\n * - Effects: sharpen\n * - Advanced: watermark, logo, text (streaming not supported for these)\n *\n * Note: Watermark and logo transformations require imagePath to be a valid URL.\n * Images will be fetched from the provided URL during transformation.\n * Streaming mode is not supported for watermark, logo, and text transformations;\n * these will cause fallback to buffered mode.\n *\n * @param id - Unique identifier for this node\n * @param params - Parameters including the transformations array\n * @param options - Optional configuration\n * @param options.keepOutput - Whether to keep output in flow results\n * @param options.naming - File naming configuration (auto suffix: `transformed`)\n * @param options.mode - Transform mode: \"buffered\", \"streaming\", or \"auto\" (default)\n * @param options.streamingConfig - Streaming configuration (file size threshold, chunk size)\n *\n * @example\n * ```typescript\n * // Auto mode (default) - uses streaming for files > 1MB, otherwise buffered\n * const node = yield* createTransformImageNode(\"transform-1\", {\n * transformations: [\n * { type: 'resize', width: 800, height: 600, fit: 'cover' },\n * { type: 'brightness', value: 20 }\n * ]\n * }, {\n * naming: { mode: \"auto\" }\n * });\n *\n * // Force buffered mode for small files\n * const nodeBuffered = yield* createTransformImageNode(\"transform-2\", {\n * transformations: [\n * { type: 'resize', width: 800, height: 600, fit: 'cover' },\n * { type: 'blur', sigma: 5 }\n * ]\n * }, {\n * mode: \"buffered\",\n * naming: { mode: \"auto\" }\n * });\n *\n * // Force streaming mode for memory efficiency\n * const nodeStreaming = yield* createTransformImageNode(\"transform-3\", {\n * transformations: [{ type: 'grayscale' }]\n * }, {\n * mode: \"streaming\",\n * naming: { mode: \"auto\" }\n * });\n * ```\n */\nexport function createTransformImageNode(\n id: string,\n { transformations }: TransformImageParams,\n options?: {\n keepOutput?: boolean;\n naming?: FileNamingConfig;\n mode?: TransformMode;\n streamingConfig?: StreamingConfig;\n },\n) {\n return Effect.gen(function* () {\n const imageService = yield* ImagePlugin;\n\n // Determine if streaming is available and requested\n const supportsStreaming = imageService.supportsStreaming ?? false;\n const requestedMode = options?.mode ?? \"auto\";\n\n // Check if any transformations don't support streaming\n const hasUnsupportedTransformations = transformations.some(\n (t) => t.type === \"watermark\" || t.type === \"logo\" || t.type === \"text\",\n );\n\n // If streaming requested but not supported or unsupported transformations, fall back to buffered\n const effectiveMode: TransformMode =\n requestedMode === \"buffered\"\n ? \"buffered\"\n : supportsStreaming && !hasUnsupportedTransformations\n ? requestedMode\n : \"buffered\";\n\n // Build naming config with auto suffix for transform-image\n const namingConfig: FileNamingConfig | undefined = options?.naming\n ? {\n ...options.naming,\n autoSuffix: options.naming.autoSuffix ?? (() => \"transformed\"),\n }\n : undefined;\n\n return yield* createTransformNode({\n id,\n name: \"Transform Image\",\n description: `Apply ${transformations.length} transformation${transformations.length === 1 ? \"\" : \"s\"} to the image`,\n nodeTypeId: \"transform-image\",\n outputTypeId: STORAGE_OUTPUT_TYPE_ID,\n keepOutput: options?.keepOutput,\n naming: namingConfig,\n nodeType: \"transform-image\",\n mode: effectiveMode,\n streamingConfig: options?.streamingConfig,\n // Buffered transform (used when mode is \"buffered\" or \"auto\" selects buffered)\n transform: (inputBytes) =>\n applyTransformationChain(imageService, inputBytes, transformations),\n // Streaming transform (used when mode is \"streaming\" or \"auto\" selects streaming)\n streamingTransform:\n supportsStreaming && !hasUnsupportedTransformations\n ? (inputStream) =>\n Effect.gen(function* () {\n const outputStream = yield* applyStreamingTransformationChain(\n imageService,\n inputStream,\n transformations,\n );\n return { stream: outputStream };\n })\n : undefined,\n });\n });\n}\n"],"mappings":"omBAcA,SAAgB,EACd,EACA,EAGI,CAAC,EACiC,CACtC,GAAM,CAAE,cAAc,IAAO,aAAa,KAAQ,EAElD,OAAO,EAAO,IAAI,WAAa,CAC7B,IAAM,EAAY,KAAK,IAAI,EAE3B,KAAO,KAAK,IAAI,EAAI,EAAY,GAAa,CAC3C,IAAM,EAAW,MAAO,EAAO,eAC7B,MAAM,EAAK,CAAE,OAAQ,MAAO,CAAC,CAC/B,CAAC,CAAC,KAAK,EAAO,aAAe,EAAO,QAAQ,IAAI,CAAC,CAAC,EAElD,GAAI,GAAU,GAAI,CAChB,MAAO,EAAO,QAAQ,OAAO,EAAI,kBAAkB,EACnD,MACF,CAEI,EACF,MAAO,EAAO,SACZ,sBAAsB,EAAS,OAAO,eACxC,EAEA,MAAO,EAAO,SAAS,+BAA+B,EAGxD,MAAO,EAAO,MAAM,CAAU,CAChC,CAEA,OAAO,MAAO,EAAgB,SAAS,kBAAmB,CACxD,MAAO,OAAO,EAAI,uBAAuB,EAAY,G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AaL,CAgEA,SAAgB,EACd,EACA,CAAE,mBACF,EAMA,CACA,OAAO,EAAO,IAAI,WAAa,CAC7B,IAAM,EAAe,MAAO,EAGtB,EAAoB,EAAa,mBAAqB,GACtD,EAAgB,GAAS,MAAQ,OAGjC,EAAgC,EAAgB,KACnD,GAAM,EAAE,OAAS,aAAe,EAAE,OAAS,QAAU,EAAE,OAAS,MACnE,EAGM,EACJ,IAAkB,WACd,WACA,GAAqB,CAAC,EACpB,EACA,WAGF,EAA6C,GAAS,OACxD,CACE,GAAG,EAAQ,OACX,WAAY,EAAQ,OAAO,iBAAqB,cAClD,EACA,IAAA,GAEJ,OAAO,MAAO,EAAoB,CAChC,KACA,KAAM,kBACN,YAAa,SAAS,EAAgB,OAAO,iBAAiB,EAAgB,SAAW,EAAI,GAAK,IAAI,eACtG,WAAY,kBACZ,aAAc,EACd,WAAY,GAAS,WACrB,OAAQ,EACR,SAAU,kBACV,KAAM,EACN,gBAAiB,GAAS,gBAE1B,UAAY,GACV,EAAyB,EAAc,EAAY,CAAe,EAEpE,mBACE,GAAqB,CAAC,EACjB,GACC,EAAO,IAAI,WAAa,CAMtB,MAAO,CAAE,OAAQ,MALW,EAC1B,EACA,EACA,CACF,CAC8B,CAChC,CAAC,EACH,IAAA,EACR,CAAC,CACH,CAAC,CACH"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uploadista/flow-images-nodes",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.0-beta.
|
|
4
|
+
"version": "1.0.0-beta.4",
|
|
5
5
|
"description": "Image processing nodes for Uploadista Flow",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "Uploadista",
|
|
@@ -14,20 +14,20 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@uploadista/core": "1.0.0-beta.
|
|
17
|
+
"@uploadista/core": "1.0.0-beta.4"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"effect": "^3.0.0",
|
|
21
21
|
"zod": "^4.0.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@effect/vitest": "0.
|
|
24
|
+
"@effect/vitest": "0.29.0",
|
|
25
25
|
"@types/node": "24.10.9",
|
|
26
|
-
"effect": "3.
|
|
27
|
-
"tsdown": "0.
|
|
26
|
+
"effect": "3.21.4",
|
|
27
|
+
"tsdown": "0.22.3",
|
|
28
28
|
"vitest": "4.0.18",
|
|
29
|
-
"zod": "4.3
|
|
30
|
-
"@uploadista/typescript-config": "1.0.0-beta.
|
|
29
|
+
"zod": "4.4.3",
|
|
30
|
+
"@uploadista/typescript-config": "1.0.0-beta.4"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "tsc --noEmit && tsdown",
|