@uploadista/flow-images-nodes 0.0.11 → 0.0.12
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 +70 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +70 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +1 -0
- package/src/transform-image-node.ts +80 -0
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
let e=require(`@uploadista/core/errors`),t=require(`@uploadista/core/flow`),n=require(`@uploadista/core/types`),r=require(`effect`),i=require(`@uploadista/core/upload`);function a(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 o(i,{credentialId:o}={}){return r.Effect.gen(function*(){let s=yield*t.ImageAiPlugin;return yield*(0,t.createFlowNode)({id:i,name:`Describe Image`,description:`Describes the image using AI`,type:t.NodeType.process,inputSchema:n.uploadFileSchema,outputSchema:n.uploadFileSchema,run:({data:n,flowId:c,jobId:l,clientId:u})=>r.Effect.gen(function*(){let d={flowId:c,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*a(f);let p={clientId:u,credentialId:o},{description:m}=yield*s.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()}))),{metadata:h}=(0,t.resolveUploadMetadata)(n.metadata),g={...n.metadata,...h,description:m};return yield*r.Effect.logInfo(`Successfully described image for file ${n.id}`),(0,t.completeNodeExecution)(g?{...n,metadata:g,flow:d}:n)})})})}const s={jpeg:`image/jpeg`,webp:`image/webp`,png:`image/png`,avif:`image/avif`},c={jpeg:`jpg`,webp:`webp`,png:`png`,avif:`avif`};function l(e,{quality:n,format:i}){return r.Effect.gen(function*(){let a=yield*t.ImagePlugin;return yield*(0,t.createTransformNode)({id:e,name:`Optimize`,description:`Optimizes an image for web delivery`,transform:(e,t)=>r.Effect.map(a.optimize(e,{quality:n,format:i}),e=>{let n=s[i],r=c[i],a=t.metadata?.fileName;return{bytes:e,type:n,fileName:a&&typeof a==`string`?a.replace(/\.[^.]+$/,`.${r}`):void 0}})})})}function u(o,{credentialId:s}={}){return r.Effect.gen(function*(){let c=yield*t.ImageAiPlugin,l=yield*i.UploadServer;return yield*(0,t.createFlowNode)({id:o,name:`Remove Background`,description:`Removes the background from an image`,type:t.NodeType.process,inputSchema:n.uploadFileSchema,outputSchema:n.uploadFileSchema,run:({data:n,flowId:i,jobId:u,storageId:d,clientId:f})=>r.Effect.gen(function*(){let p={flowId:i,nodeId:o,jobId:u},m=n.url;if(!m)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*a(m);let h={clientId:f,credentialId:s},{outputUrl:g}=yield*c.removeBackground(m,h).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:_,fileName:v,metadata:y,metadataJson:b}=(0,t.resolveUploadMetadata)(n.metadata);yield*r.Effect.logInfo(`Uploading processed file to storage`);let x=yield*l.uploadFromUrl({storageId:d,size:0,type:_,fileName:v,lastModified:0,metadata:b,flow:p},f,g).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()})));return yield*r.Effect.logInfo(`Successfully removed background for file ${n.id}`),(0,t.completeNodeExecution)(y?{...x,metadata:y}:x)})})})}function d(e,{width:n,height:i,fit:a}){return r.Effect.gen(function*(){let r=yield*t.ImagePlugin;return yield*(0,t.createTransformNode)({id:e,name:`Resize`,description:`Resizes an image to the specified dimensions`,transform:e=>r.resize(e,{height:i,width:n,fit:a})})})}exports.createDescribeImageNode=o,exports.createOptimizeNode=l,exports.createRemoveBackgroundNode=u,exports.createResizeNode=d,exports.waitForUrlAvailability=a;
|
|
1
|
+
let e=require(`@uploadista/core/errors`),t=require(`@uploadista/core/flow`),n=require(`@uploadista/core/types`),r=require(`effect`),i=require(`@uploadista/core/upload`);function a(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 o(i,{credentialId:o}={}){return r.Effect.gen(function*(){let s=yield*t.ImageAiPlugin;return yield*(0,t.createFlowNode)({id:i,name:`Describe Image`,description:`Describes the image using AI`,type:t.NodeType.process,inputSchema:n.uploadFileSchema,outputSchema:n.uploadFileSchema,run:({data:n,flowId:c,jobId:l,clientId:u})=>r.Effect.gen(function*(){let d={flowId:c,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*a(f);let p={clientId:u,credentialId:o},{description:m}=yield*s.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()}))),{metadata:h}=(0,t.resolveUploadMetadata)(n.metadata),g={...n.metadata,...h,description:m};return yield*r.Effect.logInfo(`Successfully described image for file ${n.id}`),(0,t.completeNodeExecution)(g?{...n,metadata:g,flow:d}:n)})})})}const s={jpeg:`image/jpeg`,webp:`image/webp`,png:`image/png`,avif:`image/avif`},c={jpeg:`jpg`,webp:`webp`,png:`png`,avif:`avif`};function l(e,{quality:n,format:i}){return r.Effect.gen(function*(){let a=yield*t.ImagePlugin;return yield*(0,t.createTransformNode)({id:e,name:`Optimize`,description:`Optimizes an image for web delivery`,transform:(e,t)=>r.Effect.map(a.optimize(e,{quality:n,format:i}),e=>{let n=s[i],r=c[i],a=t.metadata?.fileName;return{bytes:e,type:n,fileName:a&&typeof a==`string`?a.replace(/\.[^.]+$/,`.${r}`):void 0}})})})}function u(o,{credentialId:s}={}){return r.Effect.gen(function*(){let c=yield*t.ImageAiPlugin,l=yield*i.UploadServer;return yield*(0,t.createFlowNode)({id:o,name:`Remove Background`,description:`Removes the background from an image`,type:t.NodeType.process,inputSchema:n.uploadFileSchema,outputSchema:n.uploadFileSchema,run:({data:n,flowId:i,jobId:u,storageId:d,clientId:f})=>r.Effect.gen(function*(){let p={flowId:i,nodeId:o,jobId:u},m=n.url;if(!m)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*a(m);let h={clientId:f,credentialId:s},{outputUrl:g}=yield*c.removeBackground(m,h).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:_,fileName:v,metadata:y,metadataJson:b}=(0,t.resolveUploadMetadata)(n.metadata);yield*r.Effect.logInfo(`Uploading processed file to storage`);let x=yield*l.uploadFromUrl({storageId:d,size:0,type:_,fileName:v,lastModified:0,metadata:b,flow:p},f,g).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()})));return yield*r.Effect.logInfo(`Successfully removed background for file ${n.id}`),(0,t.completeNodeExecution)(y?{...x,metadata:y}:x)})})})}function d(e,{width:n,height:i,fit:a}){return r.Effect.gen(function*(){let r=yield*t.ImagePlugin;return yield*(0,t.createTransformNode)({id:e,name:`Resize`,description:`Resizes an image to the specified dimensions`,transform:e=>r.resize(e,{height:i,width:n,fit:a})})})}function f(e,t,n){return r.Effect.reduce(n,t,(t,n)=>e.transform(t,n))}function p(e,{transformations:n}){return r.Effect.gen(function*(){let r=yield*t.ImagePlugin;return yield*(0,t.createTransformNode)({id:e,name:`Transform Image`,description:`Apply ${n.length} transformation${n.length===1?``:`s`} to the image`,transform:e=>f(r,e,n)})})}exports.createDescribeImageNode=o,exports.createOptimizeNode=l,exports.createRemoveBackgroundNode=u,exports.createResizeNode=d,exports.createTransformImageNode=p,exports.waitForUrlAvailability=a;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _uploadista_core_flow0 from "@uploadista/core/flow";
|
|
2
|
-
import { ImageAiPlugin, ImagePlugin, OptimizeParams, ResizeParams } from "@uploadista/core/flow";
|
|
2
|
+
import { ImageAiPlugin, ImagePlugin, OptimizeParams, ResizeParams, TransformImageParams } from "@uploadista/core/flow";
|
|
3
3
|
import * as _uploadista_core_errors0 from "@uploadista/core/errors";
|
|
4
4
|
import { UploadistaError } from "@uploadista/core/errors";
|
|
5
5
|
import { Effect } from "effect";
|
|
@@ -198,6 +198,74 @@ declare function createResizeNode(id: string, {
|
|
|
198
198
|
} | undefined;
|
|
199
199
|
}, _uploadista_core_types0.UploadFile, _uploadista_core_errors0.UploadistaError>, never, ImagePlugin | _uploadista_core_upload0.UploadServer>;
|
|
200
200
|
//#endregion
|
|
201
|
+
//#region src/transform-image-node.d.ts
|
|
202
|
+
/**
|
|
203
|
+
* Creates a transform image node that applies multiple transformations sequentially.
|
|
204
|
+
*
|
|
205
|
+
* This node enables complex image processing workflows by chaining multiple transformations
|
|
206
|
+
* together. Each transformation is applied to the output of the previous transformation,
|
|
207
|
+
* allowing for powerful image manipulation pipelines.
|
|
208
|
+
*
|
|
209
|
+
* Supported transformations include:
|
|
210
|
+
* - Basic: resize, blur, rotate, flip
|
|
211
|
+
* - Filters: grayscale, sepia, brightness, contrast
|
|
212
|
+
* - Effects: sharpen
|
|
213
|
+
* - Advanced: watermark, logo, text
|
|
214
|
+
*
|
|
215
|
+
* Note: Watermark and logo transformations require imagePath to be a valid URL.
|
|
216
|
+
* Images will be fetched from the provided URL during transformation.
|
|
217
|
+
*
|
|
218
|
+
* @param id - Unique identifier for this node
|
|
219
|
+
* @param params - Parameters including the transformations array
|
|
220
|
+
* @returns Effect that resolves to a transform node
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```typescript
|
|
224
|
+
* const node = createTransformImageNode("transform-1", {
|
|
225
|
+
* transformations: [
|
|
226
|
+
* { type: 'resize', width: 800, height: 600, fit: 'cover' },
|
|
227
|
+
* { type: 'brightness', value: 20 },
|
|
228
|
+
* {
|
|
229
|
+
* type: 'watermark',
|
|
230
|
+
* imagePath: 'https://cdn.example.com/watermark.png',
|
|
231
|
+
* position: 'bottom-right',
|
|
232
|
+
* opacity: 0.5
|
|
233
|
+
* }
|
|
234
|
+
* ]
|
|
235
|
+
* });
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
declare function createTransformImageNode(id: string, {
|
|
239
|
+
transformations
|
|
240
|
+
}: TransformImageParams): Effect.Effect<_uploadista_core_flow0.FlowNode<{
|
|
241
|
+
id: string;
|
|
242
|
+
offset: number;
|
|
243
|
+
storage: {
|
|
244
|
+
id: string;
|
|
245
|
+
type: string;
|
|
246
|
+
path?: string | undefined;
|
|
247
|
+
uploadId?: string | undefined;
|
|
248
|
+
bucket?: string | undefined;
|
|
249
|
+
parts?: {
|
|
250
|
+
partNumber: number;
|
|
251
|
+
etag: string;
|
|
252
|
+
size: number;
|
|
253
|
+
}[] | undefined;
|
|
254
|
+
};
|
|
255
|
+
size?: number | undefined;
|
|
256
|
+
metadata?: Record<string, string | number | boolean> | undefined;
|
|
257
|
+
creationDate?: string | undefined;
|
|
258
|
+
url?: string | undefined;
|
|
259
|
+
sizeIsDeferred?: boolean | undefined;
|
|
260
|
+
checksum?: string | undefined;
|
|
261
|
+
checksumAlgorithm?: string | undefined;
|
|
262
|
+
flow?: {
|
|
263
|
+
flowId: string;
|
|
264
|
+
nodeId: string;
|
|
265
|
+
jobId: string;
|
|
266
|
+
} | undefined;
|
|
267
|
+
}, _uploadista_core_types0.UploadFile, _uploadista_core_errors0.UploadistaError>, never, ImagePlugin | _uploadista_core_upload0.UploadServer>;
|
|
268
|
+
//#endregion
|
|
201
269
|
//#region src/wait-for-url.d.ts
|
|
202
270
|
/**
|
|
203
271
|
* Waits for a URL to become available by periodically checking its accessibility.
|
|
@@ -215,5 +283,5 @@ declare function waitForUrlAvailability(url: string, options?: {
|
|
|
215
283
|
retryDelay?: number;
|
|
216
284
|
}): Effect.Effect<void, UploadistaError>;
|
|
217
285
|
//#endregion
|
|
218
|
-
export { createDescribeImageNode, createOptimizeNode, createRemoveBackgroundNode, createResizeNode, waitForUrlAvailability };
|
|
286
|
+
export { createDescribeImageNode, createOptimizeNode, createRemoveBackgroundNode, createResizeNode, createTransformImageNode, waitForUrlAvailability };
|
|
219
287
|
//# 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/wait-for-url.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;iBAagB,uBAAA;;;;IAEkC,MAAA,CAAA,8BAAA;;;;;IAFlC,IAAA,EAAA,MAAA;IAEZ,IAAA,CAAA,EAAA,MAAA,GAAA,SAAA;;;;kBAA8C,MAAA;;MAAA,IAAA,EAAA,MAAA;IAAA,CAAA,EAAA,GAAA,SAAA;;;;ECQlC,YAAA,CAAA,EAAA,MAAkB,GAAA,SAAA;EAE9B,GAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EAAS,cAAA,CAAA,EAAA,OAAA,GAAA,SAAA;EAAU,QAAA,CAAA,EAAA,MAAA,GAAA,SAAA;;;;;;;CAAc,EAAA;EAAA,EAAA,EAAA,MAAA;;;;ICZrB,IAAA,EAAA,MAAA;IAEZ,IAAA,CAAA,EAAA,MAAA,GAAA,SAAA;;;;kBAA8C,MAAA;;;IAAA,CAAA,EAAA,GAAA,SAAA;EAAA,CAAA;;;;ECRlC,GAAA,CAAA,EAAA,MAAA,GAAA,SAAgB;EAE5B,cAAA,CAAA,EAAA,OAAA,GAAA,SAAA;EAAO,QAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EAAQ,iBAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EAAO,IAAA,CAAA,EAAA;;;;;;;IAAY,WAAA,EAAA,MAAA;EAAA,CAAA;;;;
|
|
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"],"sourcesContent":[],"mappings":";;;;;;;;;;iBAagB,uBAAA;;;;IAEkC,MAAA,CAAA,8BAAA;;;;;IAFlC,IAAA,EAAA,MAAA;IAEZ,IAAA,CAAA,EAAA,MAAA,GAAA,SAAA;;;;kBAA8C,MAAA;;MAAA,IAAA,EAAA,MAAA;IAAA,CAAA,EAAA,GAAA,SAAA;;;;ECQlC,YAAA,CAAA,EAAA,MAAkB,GAAA,SAAA;EAE9B,GAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EAAS,cAAA,CAAA,EAAA,OAAA,GAAA,SAAA;EAAU,QAAA,CAAA,EAAA,MAAA,GAAA,SAAA;;;;;;;CAAc,EAAA;EAAA,EAAA,EAAA,MAAA;;;;ICZrB,IAAA,EAAA,MAAA;IAEZ,IAAA,CAAA,EAAA,MAAA,GAAA,SAAA;;;;kBAA8C,MAAA;;;IAAA,CAAA,EAAA,GAAA,SAAA;EAAA,CAAA;;;;ECRlC,GAAA,CAAA,EAAA,MAAA,GAAA,SAAgB;EAE5B,cAAA,CAAA,EAAA,OAAA,GAAA,SAAA;EAAO,QAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EAAQ,iBAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EAAO,IAAA,CAAA,EAAA;;;;;;;IAAY,WAAA,EAAA,MAAA;EAAA,CAAA;;;;ICuDtB,KAAA,EAAA,MAAA;EAEZ,CAAA;EAAmB,EAAA,EAAA,MAAA;;;;;;;IAAoB,MAAA,CAAA,EAAA,MAAA,GAAA,SAAA;IAAA,KAAA,CAAA,EAAA;;;;ICpD3B,CAAA,EAAA,GAAA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AA,GAAA,SAAkB;EAE9B,iBAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EAAS,IAAA,CAAA,EAAA;IAAU,MAAA,EAAA,MAAA;;;;gFAAc,EAAA,KAAA,aAAA,wCAAA,CAAA;;;;;;;;;;;ADZrC;;;;;;;;;;;;ACUA;;;;;;;;;;;;;;;ACVA;AAEI,iBEiDY,wBAAA,CFjDZ,EAAA,EAAA,MAAA,EAAA;EAAA;AAAA,CAAA,EEmDmB,oBFnDnB,CAAA,EEmDuC,MAAA,CAAA,MFnDvC,wBEmDuC,QFnDvC,CAAA;;;;;;;IAA8C,QAAA,CAAA,EAAA,MAAA,GAAA,SAAA;IAAA,MAAA,CAAA,EAAA,MAAA,GAAA,SAAA;;;;MCRlC,IAAA,EAAA,MAAgB;IAE5B,CAAA,EAAA,GAAA,SAAA;EAAO,CAAA;EAAQ,IAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EAAO,QAAA,CAAA,QAAA,CAAA,MAAA,EAAA,MAAA,GAAA,MAAA,GAAA,OAAA,CAAA,GAAA,SAAA;;;;sBAAY,SAAA;;;IAAA,MAAA,EAAA,MAAA;IAAA,MAAA,EAAA,MAAA;;;;;;;;;;;;;;AHItC;;;iBKCgB,sBAAA;;;IAMb,MAAA,CAAO,aAAa"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _uploadista_core_errors0 from "@uploadista/core/errors";
|
|
2
2
|
import { UploadistaError } from "@uploadista/core/errors";
|
|
3
3
|
import * as _uploadista_core_flow0 from "@uploadista/core/flow";
|
|
4
|
-
import { ImageAiPlugin, ImagePlugin, OptimizeParams, ResizeParams } from "@uploadista/core/flow";
|
|
4
|
+
import { ImageAiPlugin, ImagePlugin, OptimizeParams, ResizeParams, TransformImageParams } from "@uploadista/core/flow";
|
|
5
5
|
import * as _uploadista_core_types0 from "@uploadista/core/types";
|
|
6
6
|
import { Effect } from "effect";
|
|
7
7
|
import * as _uploadista_core_upload0 from "@uploadista/core/upload";
|
|
@@ -198,6 +198,74 @@ declare function createResizeNode(id: string, {
|
|
|
198
198
|
} | undefined;
|
|
199
199
|
}, _uploadista_core_types0.UploadFile, _uploadista_core_errors0.UploadistaError>, never, ImagePlugin | _uploadista_core_upload0.UploadServer>;
|
|
200
200
|
//#endregion
|
|
201
|
+
//#region src/transform-image-node.d.ts
|
|
202
|
+
/**
|
|
203
|
+
* Creates a transform image node that applies multiple transformations sequentially.
|
|
204
|
+
*
|
|
205
|
+
* This node enables complex image processing workflows by chaining multiple transformations
|
|
206
|
+
* together. Each transformation is applied to the output of the previous transformation,
|
|
207
|
+
* allowing for powerful image manipulation pipelines.
|
|
208
|
+
*
|
|
209
|
+
* Supported transformations include:
|
|
210
|
+
* - Basic: resize, blur, rotate, flip
|
|
211
|
+
* - Filters: grayscale, sepia, brightness, contrast
|
|
212
|
+
* - Effects: sharpen
|
|
213
|
+
* - Advanced: watermark, logo, text
|
|
214
|
+
*
|
|
215
|
+
* Note: Watermark and logo transformations require imagePath to be a valid URL.
|
|
216
|
+
* Images will be fetched from the provided URL during transformation.
|
|
217
|
+
*
|
|
218
|
+
* @param id - Unique identifier for this node
|
|
219
|
+
* @param params - Parameters including the transformations array
|
|
220
|
+
* @returns Effect that resolves to a transform node
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```typescript
|
|
224
|
+
* const node = createTransformImageNode("transform-1", {
|
|
225
|
+
* transformations: [
|
|
226
|
+
* { type: 'resize', width: 800, height: 600, fit: 'cover' },
|
|
227
|
+
* { type: 'brightness', value: 20 },
|
|
228
|
+
* {
|
|
229
|
+
* type: 'watermark',
|
|
230
|
+
* imagePath: 'https://cdn.example.com/watermark.png',
|
|
231
|
+
* position: 'bottom-right',
|
|
232
|
+
* opacity: 0.5
|
|
233
|
+
* }
|
|
234
|
+
* ]
|
|
235
|
+
* });
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
declare function createTransformImageNode(id: string, {
|
|
239
|
+
transformations
|
|
240
|
+
}: TransformImageParams): Effect.Effect<_uploadista_core_flow0.FlowNode<{
|
|
241
|
+
id: string;
|
|
242
|
+
offset: number;
|
|
243
|
+
storage: {
|
|
244
|
+
id: string;
|
|
245
|
+
type: string;
|
|
246
|
+
path?: string | undefined;
|
|
247
|
+
uploadId?: string | undefined;
|
|
248
|
+
bucket?: string | undefined;
|
|
249
|
+
parts?: {
|
|
250
|
+
partNumber: number;
|
|
251
|
+
etag: string;
|
|
252
|
+
size: number;
|
|
253
|
+
}[] | undefined;
|
|
254
|
+
};
|
|
255
|
+
size?: number | undefined;
|
|
256
|
+
metadata?: Record<string, string | number | boolean> | undefined;
|
|
257
|
+
creationDate?: string | undefined;
|
|
258
|
+
url?: string | undefined;
|
|
259
|
+
sizeIsDeferred?: boolean | undefined;
|
|
260
|
+
checksum?: string | undefined;
|
|
261
|
+
checksumAlgorithm?: string | undefined;
|
|
262
|
+
flow?: {
|
|
263
|
+
flowId: string;
|
|
264
|
+
nodeId: string;
|
|
265
|
+
jobId: string;
|
|
266
|
+
} | undefined;
|
|
267
|
+
}, _uploadista_core_types0.UploadFile, _uploadista_core_errors0.UploadistaError>, never, ImagePlugin | _uploadista_core_upload0.UploadServer>;
|
|
268
|
+
//#endregion
|
|
201
269
|
//#region src/wait-for-url.d.ts
|
|
202
270
|
/**
|
|
203
271
|
* Waits for a URL to become available by periodically checking its accessibility.
|
|
@@ -215,5 +283,5 @@ declare function waitForUrlAvailability(url: string, options?: {
|
|
|
215
283
|
retryDelay?: number;
|
|
216
284
|
}): Effect.Effect<void, UploadistaError>;
|
|
217
285
|
//#endregion
|
|
218
|
-
export { createDescribeImageNode, createOptimizeNode, createRemoveBackgroundNode, createResizeNode, waitForUrlAvailability };
|
|
286
|
+
export { createDescribeImageNode, createOptimizeNode, createRemoveBackgroundNode, createResizeNode, createTransformImageNode, waitForUrlAvailability };
|
|
219
287
|
//# sourceMappingURL=index.d.mts.map
|
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/wait-for-url.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;iBAagB,uBAAA;;;;IAEkC,MAAA,CAAA,8BAAA;;;;;IAFlC,IAAA,EAAA,MAAA;IAEZ,IAAA,CAAA,EAAA,MAAA,GAAA,SAAA;;;;kBAA8C,MAAA;;MAAA,IAAA,EAAA,MAAA;IAAA,CAAA,EAAA,GAAA,SAAA;;;;ECQlC,YAAA,CAAA,EAAA,MAAkB,GAAA,SAAA;EAE9B,GAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EAAS,cAAA,CAAA,EAAA,OAAA,GAAA,SAAA;EAAU,QAAA,CAAA,EAAA,MAAA,GAAA,SAAA;;;;;;;CAAc,EAAA;EAAA,EAAA,EAAA,MAAA;;;;ICZrB,IAAA,EAAA,MAAA;IAEZ,IAAA,CAAA,EAAA,MAAA,GAAA,SAAA;;;;kBAA8C,MAAA;;;IAAA,CAAA,EAAA,GAAA,SAAA;EAAA,CAAA;;;;ECRlC,GAAA,CAAA,EAAA,MAAA,GAAA,SAAgB;EAE5B,cAAA,CAAA,EAAA,OAAA,GAAA,SAAA;EAAO,QAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EAAQ,iBAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EAAO,IAAA,CAAA,EAAA;;;;;;;IAAY,WAAA,EAAA,MAAA;EAAA,CAAA;;;;
|
|
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"],"sourcesContent":[],"mappings":";;;;;;;;;;iBAagB,uBAAA;;;;IAEkC,MAAA,CAAA,8BAAA;;;;;IAFlC,IAAA,EAAA,MAAA;IAEZ,IAAA,CAAA,EAAA,MAAA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C,QAAA,CAAA,EAAA,MAAA,GAAA,SAAA;IAAA,MAAA,CAAA,EAAA,MAAA,GAAA,SAAA;;;;MCRlC,IAAA,EAAA,MAAgB;IAE5B,CAAA,EAAA,GAAA,SAAA;EAAO,CAAA;EAAQ,IAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EAAO,QAAA,CAAA,QAAA,CAAA,MAAA,EAAA,MAAA,GAAA,MAAA,GAAA,OAAA,CAAA,GAAA,SAAA;;;;sBAAY,SAAA;;;IAAA,MAAA,EAAA,MAAA;IAAA,MAAA,EAAA,MAAA;;;;;;;;;;;;;;AHItC;;;iBKCgB,sBAAA;;;IAMb,MAAA,CAAO,aAAa"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{UploadistaError as e}from"@uploadista/core/errors";import{ImageAiPlugin as t,ImagePlugin as n,NodeType as r,completeNodeExecution as i,createFlowNode as a,createTransformNode as o,resolveUploadMetadata as s}from"@uploadista/core/flow";import{uploadFileSchema as c}from"@uploadista/core/types";import{Effect as l}from"effect";import{UploadServer as u}from"@uploadista/core/upload";function d(t,n={}){let{maxWaitTime:r=1e4,retryDelay:i=500}=n;return l.gen(function*(){let n=Date.now();for(;Date.now()-n<r;){let e=yield*l.tryPromise(()=>fetch(t,{method:`HEAD`})).pipe(l.catchAll(()=>l.succeed(null)));if(e?.ok){yield*l.logInfo(`URL ${t} is now available`);return}e?yield*l.logDebug(`URL not ready yet (${e.status}), retrying...`):yield*l.logDebug(`URL check failed, retrying...`),yield*l.sleep(i)}return yield*e.fromCode(`FLOW_NODE_ERROR`,{cause:`URL ${t} not available after ${r}ms`}).toEffect()})}function f(n,{credentialId:o}={}){return l.gen(function*(){let u=yield*t;return yield*a({id:n,name:`Describe Image`,description:`Describes the image using AI`,type:r.process,inputSchema:c,outputSchema:c,run:({data:t,flowId:r,jobId:a,clientId:c})=>l.gen(function*(){let f={flowId:r,nodeId:n,jobId:a},p=t.url;if(!p)return yield*e.fromCode(`FLOW_NODE_ERROR`,{cause:`URL is required for describe image operation`}).toEffect();yield*l.logInfo(`Describing image for file ${t.id} at URL: ${p}`),yield*d(p);let m={clientId:c,credentialId:o},{description:h}=yield*u.describeImage(p,m).pipe(l.catchAll(t=>l.gen(function*(){return yield*l.logError(`Failed to describe image`,t),yield*e.fromCode(`FLOW_NODE_ERROR`,{cause:t instanceof Error?t.message:`Failed to describe image`}).toEffect()}))),{metadata:g}=s(t.metadata),_={...t.metadata,...g,description:h};return yield*l.logInfo(`Successfully described image for file ${t.id}`),i(_?{...t,metadata:_,flow:f}:t)})})})}const p={jpeg:`image/jpeg`,webp:`image/webp`,png:`image/png`,avif:`image/avif`},m={jpeg:`jpg`,webp:`webp`,png:`png`,avif:`avif`};function h(e,{quality:t,format:r}){return l.gen(function*(){let i=yield*n;return yield*o({id:e,name:`Optimize`,description:`Optimizes an image for web delivery`,transform:(e,n)=>l.map(i.optimize(e,{quality:t,format:r}),e=>{let t=p[r],i=m[r],a=n.metadata?.fileName;return{bytes:e,type:t,fileName:a&&typeof a==`string`?a.replace(/\.[^.]+$/,`.${i}`):void 0}})})})}function g(n,{credentialId:o}={}){return l.gen(function*(){let f=yield*t,p=yield*u;return yield*a({id:n,name:`Remove Background`,description:`Removes the background from an image`,type:r.process,inputSchema:c,outputSchema:c,run:({data:t,flowId:r,jobId:a,storageId:c,clientId:u})=>l.gen(function*(){let m={flowId:r,nodeId:n,jobId:a},h=t.url;if(!h)return yield*e.fromCode(`FLOW_NODE_ERROR`,{cause:`URL is required for remove background operation`}).toEffect();yield*l.logInfo(`Removing background for file ${t.id} at URL: ${t.url}`),yield*d(h);let g={clientId:u,credentialId:o},{outputUrl:_}=yield*f.removeBackground(h,g).pipe(l.catchAll(t=>l.gen(function*(){return yield*l.logError(`Failed to remove background`,t),yield*e.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}=s(t.metadata);yield*l.logInfo(`Uploading processed file to storage`);let S=yield*p.uploadFromUrl({storageId:c,size:0,type:v,fileName:y,lastModified:0,metadata:x,flow:m},u,_).pipe(l.catchAll(t=>l.gen(function*(){return yield*l.logError(`Failed to upload processed file`,t),yield*e.fromCode(`FLOW_NODE_ERROR`,{cause:t instanceof Error?t.message:`Failed to upload processed file`}).toEffect()})));return yield*l.logInfo(`Successfully removed background for file ${t.id}`),i(b?{...S,metadata:b}:S)})})})}function _(e,{width:t,height:r,fit:i}){return l.gen(function*(){let a=yield*n;return yield*o({id:e,name:`Resize`,description:`Resizes an image to the specified dimensions`,transform:e=>a.resize(e,{height:r,width:t,fit:i})})})}export{f as createDescribeImageNode,h as createOptimizeNode,g as createRemoveBackgroundNode,_ as createResizeNode,d as waitForUrlAvailability};
|
|
1
|
+
import{UploadistaError as e}from"@uploadista/core/errors";import{ImageAiPlugin as t,ImagePlugin as n,NodeType as r,completeNodeExecution as i,createFlowNode as a,createTransformNode as o,resolveUploadMetadata as s}from"@uploadista/core/flow";import{uploadFileSchema as c}from"@uploadista/core/types";import{Effect as l}from"effect";import{UploadServer as u}from"@uploadista/core/upload";function d(t,n={}){let{maxWaitTime:r=1e4,retryDelay:i=500}=n;return l.gen(function*(){let n=Date.now();for(;Date.now()-n<r;){let e=yield*l.tryPromise(()=>fetch(t,{method:`HEAD`})).pipe(l.catchAll(()=>l.succeed(null)));if(e?.ok){yield*l.logInfo(`URL ${t} is now available`);return}e?yield*l.logDebug(`URL not ready yet (${e.status}), retrying...`):yield*l.logDebug(`URL check failed, retrying...`),yield*l.sleep(i)}return yield*e.fromCode(`FLOW_NODE_ERROR`,{cause:`URL ${t} not available after ${r}ms`}).toEffect()})}function f(n,{credentialId:o}={}){return l.gen(function*(){let u=yield*t;return yield*a({id:n,name:`Describe Image`,description:`Describes the image using AI`,type:r.process,inputSchema:c,outputSchema:c,run:({data:t,flowId:r,jobId:a,clientId:c})=>l.gen(function*(){let f={flowId:r,nodeId:n,jobId:a},p=t.url;if(!p)return yield*e.fromCode(`FLOW_NODE_ERROR`,{cause:`URL is required for describe image operation`}).toEffect();yield*l.logInfo(`Describing image for file ${t.id} at URL: ${p}`),yield*d(p);let m={clientId:c,credentialId:o},{description:h}=yield*u.describeImage(p,m).pipe(l.catchAll(t=>l.gen(function*(){return yield*l.logError(`Failed to describe image`,t),yield*e.fromCode(`FLOW_NODE_ERROR`,{cause:t instanceof Error?t.message:`Failed to describe image`}).toEffect()}))),{metadata:g}=s(t.metadata),_={...t.metadata,...g,description:h};return yield*l.logInfo(`Successfully described image for file ${t.id}`),i(_?{...t,metadata:_,flow:f}:t)})})})}const p={jpeg:`image/jpeg`,webp:`image/webp`,png:`image/png`,avif:`image/avif`},m={jpeg:`jpg`,webp:`webp`,png:`png`,avif:`avif`};function h(e,{quality:t,format:r}){return l.gen(function*(){let i=yield*n;return yield*o({id:e,name:`Optimize`,description:`Optimizes an image for web delivery`,transform:(e,n)=>l.map(i.optimize(e,{quality:t,format:r}),e=>{let t=p[r],i=m[r],a=n.metadata?.fileName;return{bytes:e,type:t,fileName:a&&typeof a==`string`?a.replace(/\.[^.]+$/,`.${i}`):void 0}})})})}function g(n,{credentialId:o}={}){return l.gen(function*(){let f=yield*t,p=yield*u;return yield*a({id:n,name:`Remove Background`,description:`Removes the background from an image`,type:r.process,inputSchema:c,outputSchema:c,run:({data:t,flowId:r,jobId:a,storageId:c,clientId:u})=>l.gen(function*(){let m={flowId:r,nodeId:n,jobId:a},h=t.url;if(!h)return yield*e.fromCode(`FLOW_NODE_ERROR`,{cause:`URL is required for remove background operation`}).toEffect();yield*l.logInfo(`Removing background for file ${t.id} at URL: ${t.url}`),yield*d(h);let g={clientId:u,credentialId:o},{outputUrl:_}=yield*f.removeBackground(h,g).pipe(l.catchAll(t=>l.gen(function*(){return yield*l.logError(`Failed to remove background`,t),yield*e.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}=s(t.metadata);yield*l.logInfo(`Uploading processed file to storage`);let S=yield*p.uploadFromUrl({storageId:c,size:0,type:v,fileName:y,lastModified:0,metadata:x,flow:m},u,_).pipe(l.catchAll(t=>l.gen(function*(){return yield*l.logError(`Failed to upload processed file`,t),yield*e.fromCode(`FLOW_NODE_ERROR`,{cause:t instanceof Error?t.message:`Failed to upload processed file`}).toEffect()})));return yield*l.logInfo(`Successfully removed background for file ${t.id}`),i(b?{...S,metadata:b}:S)})})})}function _(e,{width:t,height:r,fit:i}){return l.gen(function*(){let a=yield*n;return yield*o({id:e,name:`Resize`,description:`Resizes an image to the specified dimensions`,transform:e=>a.resize(e,{height:r,width:t,fit:i})})})}function v(e,t,n){return l.reduce(n,t,(t,n)=>e.transform(t,n))}function y(e,{transformations:t}){return l.gen(function*(){let r=yield*n;return yield*o({id:e,name:`Transform Image`,description:`Apply ${t.length} transformation${t.length===1?``:`s`} to the image`,transform:e=>v(r,e,t)})})}export{f as createDescribeImageNode,h as createOptimizeNode,g as createRemoveBackgroundNode,_ as createResizeNode,y as createTransformImageNode,d as waitForUrlAvailability};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["formatToMimeType: Record<OptimizeParams[\"format\"], string>","formatToExtension: Record<OptimizeParams[\"format\"], string>"],"sources":["../src/wait-for-url.ts","../src/describe-image-node.ts","../src/optimize-node.ts","../src/remove-background-node.ts","../src/resize-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 ImageAiPlugin,\n NodeType,\n resolveUploadMetadata,\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 { credentialId }: { credentialId?: string } = {},\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 inputSchema: uploadFileSchema,\n outputSchema: uploadFileSchema,\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 { description } = 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 const { metadata } = resolveUploadMetadata(file.metadata);\n\n // add description to metadata\n const newMetadata = {\n ...file.metadata,\n ...metadata,\n description,\n };\n\n yield* Effect.logInfo(\n `Successfully described image for file ${file.id}`,\n );\n\n return completeNodeExecution(\n newMetadata\n ? {\n ...file,\n metadata: newMetadata,\n flow,\n }\n : file,\n );\n });\n },\n });\n });\n}\n","import {\n createTransformNode,\n ImagePlugin,\n type OptimizeParams,\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\nexport function createOptimizeNode(\n id: string,\n { quality, format }: OptimizeParams,\n) {\n return Effect.gen(function* () {\n const imageService = yield* ImagePlugin;\n\n return yield* createTransformNode({\n id,\n name: \"Optimize\",\n description: \"Optimizes an image for web delivery\",\n transform: (inputBytes, file) =>\n Effect.map(\n imageService.optimize(inputBytes, { quality, format }),\n (optimizedBytes) => {\n // Return bytes with updated metadata if format changes\n const newType = formatToMimeType[format];\n const newExtension = formatToExtension[format];\n\n // Update file extension if format changed\n const fileName = file.metadata?.fileName;\n const newFileName =\n fileName && typeof fileName === \"string\"\n ? fileName.replace(/\\.[^.]+$/, `.${newExtension}`)\n : undefined;\n\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 });\n });\n}\n","import { UploadistaError } from \"@uploadista/core/errors\";\nimport {\n completeNodeExecution,\n createFlowNode,\n ImageAiPlugin,\n NodeType,\n resolveUploadMetadata,\n} from \"@uploadista/core/flow\";\nimport { uploadFileSchema } from \"@uploadista/core/types\";\nimport { UploadServer } from \"@uploadista/core/upload\";\nimport { Effect } from \"effect\";\nimport { waitForUrlAvailability } from \"./wait-for-url\";\n\nexport function createRemoveBackgroundNode(\n id: string,\n { credentialId }: { credentialId?: string } = {},\n) {\n return Effect.gen(function* () {\n const imageAiService = yield* ImageAiPlugin;\n const uploadServer = yield* UploadServer;\n\n return yield* createFlowNode({\n id,\n name: \"Remove Background\",\n description: \"Removes the background from an image\",\n type: NodeType.process,\n inputSchema: uploadFileSchema,\n outputSchema: uploadFileSchema,\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 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* uploadServer\n .uploadFromUrl(\n {\n storageId,\n size: 0,\n type,\n fileName,\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 return completeNodeExecution(\n metadata\n ? {\n ...result,\n metadata,\n }\n : result,\n );\n });\n },\n });\n });\n}\n","import {\n createTransformNode,\n ImagePlugin,\n type ResizeParams,\n} from \"@uploadista/core/flow\";\nimport { Effect } from \"effect\";\n\nexport function createResizeNode(\n id: string,\n { width, height, fit }: ResizeParams,\n) {\n return Effect.gen(function* () {\n const imageService = yield* ImagePlugin;\n\n return yield* createTransformNode({\n id,\n name: \"Resize\",\n description: \"Resizes an image to the specified dimensions\",\n transform: (inputBytes) =>\n imageService.resize(inputBytes, { height, width, fit }),\n });\n });\n}\n"],"mappings":"mYAcA,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,C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,MACzD,CAGD,MAAO,EAAuB,EAAQ,CAGtC,IAAM,EAAU,CACd,WACA,eACD,CAmBK,CAAE,aAhBwB,MAAO,EACpC,iBAAiB,EAAS,EAAQ,CAClC,KACC,EAAO,SAAU,GACf,EAAO,IAAI,WAAa,CAEtB,OADA,MAAO,EAAO,SAAS,8BAA+B,EAAM,CACrD,MAAO,EAAgB,SAAS,kBAAmB,CACxD,MACE,aAAiB,MACb,EAAM,QACN,yCACP,CAAC,CAAC,UAAU,EACb,CACH,CACF,CAGG,CAAE,OAAM,WAAU,WAAU,gBAChC,EAAsB,EAAK,SAAS,CAEtC,MAAO,EAAO,QAAQ,sCAAsC,CAG5D,IAAM,EAAS,MAAO,EACnB,cACC,CACE,YACA,KAAM,EACN,OACA,WACA,aAAc,EACd,SAAU,EACV,OACD,CACD,EACA,EACD,CACA,KACC,EAAO,SAAU,GACf,EAAO,IAAI,WAAa,CAKtB,OAJA,MAAO,EAAO,SACZ,kCACA,EACD,CACM,MAAO,EAAgB,SAAS,kBAAmB,CACxD,MACE,aAAiB,MACb,EAAM,QACN,kCACP,CAAC,CAAC,UAAU,EACb,CACH,CACF,CAMH,OAJA,MAAO,EAAO,QACZ,4CAA4C,EAAK,KAClD,CAEM,EACL,EACI,CACE,GAAG,EACH,WACD,CACD,EACL,EACD,CAEL,CAAC,EACF,CCzHJ,SAAgB,EACd,EACA,CAAE,QAAO,SAAQ,OACjB,CACA,OAAO,EAAO,IAAI,WAAa,CAC7B,IAAM,EAAe,MAAO,EAE5B,OAAO,MAAO,EAAoB,CAChC,KACA,KAAM,SACN,YAAa,+CACb,UAAY,GACV,EAAa,OAAO,EAAY,CAAE,SAAQ,QAAO,MAAK,CAAC,CAC1D,CAAC,EACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["formatToMimeType: Record<OptimizeParams[\"format\"], string>","formatToExtension: Record<OptimizeParams[\"format\"], string>"],"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 ImageAiPlugin,\n NodeType,\n resolveUploadMetadata,\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 { credentialId }: { credentialId?: string } = {},\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 inputSchema: uploadFileSchema,\n outputSchema: uploadFileSchema,\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 { description } = 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 const { metadata } = resolveUploadMetadata(file.metadata);\n\n // add description to metadata\n const newMetadata = {\n ...file.metadata,\n ...metadata,\n description,\n };\n\n yield* Effect.logInfo(\n `Successfully described image for file ${file.id}`,\n );\n\n return completeNodeExecution(\n newMetadata\n ? {\n ...file,\n metadata: newMetadata,\n flow,\n }\n : file,\n );\n });\n },\n });\n });\n}\n","import {\n createTransformNode,\n ImagePlugin,\n type OptimizeParams,\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\nexport function createOptimizeNode(\n id: string,\n { quality, format }: OptimizeParams,\n) {\n return Effect.gen(function* () {\n const imageService = yield* ImagePlugin;\n\n return yield* createTransformNode({\n id,\n name: \"Optimize\",\n description: \"Optimizes an image for web delivery\",\n transform: (inputBytes, file) =>\n Effect.map(\n imageService.optimize(inputBytes, { quality, format }),\n (optimizedBytes) => {\n // Return bytes with updated metadata if format changes\n const newType = formatToMimeType[format];\n const newExtension = formatToExtension[format];\n\n // Update file extension if format changed\n const fileName = file.metadata?.fileName;\n const newFileName =\n fileName && typeof fileName === \"string\"\n ? fileName.replace(/\\.[^.]+$/, `.${newExtension}`)\n : undefined;\n\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 });\n });\n}\n","import { UploadistaError } from \"@uploadista/core/errors\";\nimport {\n completeNodeExecution,\n createFlowNode,\n ImageAiPlugin,\n NodeType,\n resolveUploadMetadata,\n} from \"@uploadista/core/flow\";\nimport { uploadFileSchema } from \"@uploadista/core/types\";\nimport { UploadServer } from \"@uploadista/core/upload\";\nimport { Effect } from \"effect\";\nimport { waitForUrlAvailability } from \"./wait-for-url\";\n\nexport function createRemoveBackgroundNode(\n id: string,\n { credentialId }: { credentialId?: string } = {},\n) {\n return Effect.gen(function* () {\n const imageAiService = yield* ImageAiPlugin;\n const uploadServer = yield* UploadServer;\n\n return yield* createFlowNode({\n id,\n name: \"Remove Background\",\n description: \"Removes the background from an image\",\n type: NodeType.process,\n inputSchema: uploadFileSchema,\n outputSchema: uploadFileSchema,\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 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* uploadServer\n .uploadFromUrl(\n {\n storageId,\n size: 0,\n type,\n fileName,\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 return completeNodeExecution(\n metadata\n ? {\n ...result,\n metadata,\n }\n : result,\n );\n });\n },\n });\n });\n}\n","import {\n createTransformNode,\n ImagePlugin,\n type ResizeParams,\n} from \"@uploadista/core/flow\";\nimport { Effect } from \"effect\";\n\nexport function createResizeNode(\n id: string,\n { width, height, fit }: ResizeParams,\n) {\n return Effect.gen(function* () {\n const imageService = yield* ImagePlugin;\n\n return yield* createTransformNode({\n id,\n name: \"Resize\",\n description: \"Resizes an image to the specified dimensions\",\n transform: (inputBytes) =>\n imageService.resize(inputBytes, { height, width, fit }),\n });\n });\n}\n","import {\n createTransformNode,\n ImagePlugin,\n type TransformImageParams,\n} from \"@uploadista/core/flow\";\nimport { Effect } 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(\n transformations,\n inputBytes,\n (bytes, transformation) => imageService.transform(bytes, transformation),\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 * Supported transformations include:\n * - Basic: resize, blur, rotate, flip\n * - Filters: grayscale, sepia, brightness, contrast\n * - Effects: sharpen\n * - Advanced: watermark, logo, text\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 *\n * @param id - Unique identifier for this node\n * @param params - Parameters including the transformations array\n * @returns Effect that resolves to a transform node\n *\n * @example\n * ```typescript\n * const node = createTransformImageNode(\"transform-1\", {\n * transformations: [\n * { type: 'resize', width: 800, height: 600, fit: 'cover' },\n * { type: 'brightness', value: 20 },\n * {\n * type: 'watermark',\n * imagePath: 'https://cdn.example.com/watermark.png',\n * position: 'bottom-right',\n * opacity: 0.5\n * }\n * ]\n * });\n * ```\n */\nexport function createTransformImageNode(\n id: string,\n { transformations }: TransformImageParams,\n) {\n return Effect.gen(function* () {\n const imageService = yield* ImagePlugin;\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 transform: (inputBytes) =>\n applyT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7B,IAAM,EAAe,MAAO,EAE5B,OAAO,MAAO,EAAoB,CAChC,KACA,KAAM,SACN,YAAa,+CACb,UAAY,GACV,EAAa,OAAO,EAAY,CAAE,SAAQ,QAAO,MAAK,CAAC,CAC1D,CAAC,EACF,CCLJ,SAAS,EACP,EACA,EACA,EACA,CACA,OAAO,EAAO,OACZ,EACA,GACC,EAAO,IAAmB,EAAa,UAAU,EAAO,EAAe,CACzE,CAuCH,SAAgB,EACd,EACA,CAAE,mBACF,CACA,OAAO,EAAO,IAAI,WAAa,CAC7B,IAAM,EAAe,MAAO,EAE5B,OAAO,MAAO,EAAoB,CAChC,KACA,KAAM,kBACN,YAAa,SAAS,EAAgB,OAAO,iBAAiB,EAAgB,SAAW,EAAI,GAAK,IAAI,eACtG,UAAY,GACV,EAAyB,EAAc,EAAY,EAAgB,CACtE,CAAC,EACF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uploadista/flow-images-nodes",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.12",
|
|
5
5
|
"description": "Image processing nodes for Uploadista Flow",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "Uploadista",
|
|
@@ -14,14 +14,14 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"effect": "3.19.
|
|
17
|
+
"effect": "3.19.1",
|
|
18
18
|
"zod": "4.1.12",
|
|
19
|
-
"@uploadista/core": "0.0.
|
|
19
|
+
"@uploadista/core": "0.0.12"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/node": "24.10.0",
|
|
23
23
|
"tsdown": "0.16.0",
|
|
24
|
-
"@uploadista/typescript-config": "0.0.
|
|
24
|
+
"@uploadista/typescript-config": "0.0.12"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
27
|
"build": "tsdown",
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createTransformNode,
|
|
3
|
+
ImagePlugin,
|
|
4
|
+
type TransformImageParams,
|
|
5
|
+
} from "@uploadista/core/flow";
|
|
6
|
+
import { Effect } from "effect";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Apply a chain of transformations to an image by reducing over the transformations array.
|
|
10
|
+
* Each transformation receives the output of the previous transformation as input.
|
|
11
|
+
*
|
|
12
|
+
* @param imageService - The image plugin service to use for transformations
|
|
13
|
+
* @param inputBytes - The input image bytes
|
|
14
|
+
* @param transformations - Array of transformations to apply in sequence
|
|
15
|
+
* @returns Effect that resolves to the final transformed image bytes
|
|
16
|
+
*/
|
|
17
|
+
function applyTransformationChain(
|
|
18
|
+
imageService: ReturnType<typeof ImagePlugin.of>,
|
|
19
|
+
inputBytes: Uint8Array,
|
|
20
|
+
transformations: TransformImageParams["transformations"],
|
|
21
|
+
) {
|
|
22
|
+
return Effect.reduce(
|
|
23
|
+
transformations,
|
|
24
|
+
inputBytes,
|
|
25
|
+
(bytes, transformation) => imageService.transform(bytes, transformation),
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Creates a transform image node that applies multiple transformations sequentially.
|
|
31
|
+
*
|
|
32
|
+
* This node enables complex image processing workflows by chaining multiple transformations
|
|
33
|
+
* together. Each transformation is applied to the output of the previous transformation,
|
|
34
|
+
* allowing for powerful image manipulation pipelines.
|
|
35
|
+
*
|
|
36
|
+
* Supported transformations include:
|
|
37
|
+
* - Basic: resize, blur, rotate, flip
|
|
38
|
+
* - Filters: grayscale, sepia, brightness, contrast
|
|
39
|
+
* - Effects: sharpen
|
|
40
|
+
* - Advanced: watermark, logo, text
|
|
41
|
+
*
|
|
42
|
+
* Note: Watermark and logo transformations require imagePath to be a valid URL.
|
|
43
|
+
* Images will be fetched from the provided URL during transformation.
|
|
44
|
+
*
|
|
45
|
+
* @param id - Unique identifier for this node
|
|
46
|
+
* @param params - Parameters including the transformations array
|
|
47
|
+
* @returns Effect that resolves to a transform node
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const node = createTransformImageNode("transform-1", {
|
|
52
|
+
* transformations: [
|
|
53
|
+
* { type: 'resize', width: 800, height: 600, fit: 'cover' },
|
|
54
|
+
* { type: 'brightness', value: 20 },
|
|
55
|
+
* {
|
|
56
|
+
* type: 'watermark',
|
|
57
|
+
* imagePath: 'https://cdn.example.com/watermark.png',
|
|
58
|
+
* position: 'bottom-right',
|
|
59
|
+
* opacity: 0.5
|
|
60
|
+
* }
|
|
61
|
+
* ]
|
|
62
|
+
* });
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export function createTransformImageNode(
|
|
66
|
+
id: string,
|
|
67
|
+
{ transformations }: TransformImageParams,
|
|
68
|
+
) {
|
|
69
|
+
return Effect.gen(function* () {
|
|
70
|
+
const imageService = yield* ImagePlugin;
|
|
71
|
+
|
|
72
|
+
return yield* createTransformNode({
|
|
73
|
+
id,
|
|
74
|
+
name: "Transform Image",
|
|
75
|
+
description: `Apply ${transformations.length} transformation${transformations.length === 1 ? "" : "s"} to the image`,
|
|
76
|
+
transform: (inputBytes) =>
|
|
77
|
+
applyTransformationChain(imageService, inputBytes, transformations),
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|