@uploadista/core 0.2.0 → 1.0.0-beta.2
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/{checksum-BjP9nb5b.mjs → checksum-BRjFmTRk.mjs} +2 -2
- package/dist/{checksum-BjP9nb5b.mjs.map → checksum-BRjFmTRk.mjs.map} +1 -1
- package/dist/{checksum-B7RDiO7V.cjs → checksum-BrjQ8GJL.cjs} +1 -1
- package/dist/errors/index.cjs +1 -1
- package/dist/errors/index.d.cts +1 -1
- package/dist/errors/index.d.mts +1 -1
- package/dist/errors/index.mjs +1 -1
- package/dist/flow/index.cjs +1 -1
- package/dist/flow/index.d.cts +3 -2
- package/dist/flow/index.d.mts +8 -5
- package/dist/flow/index.mjs +1 -1
- package/dist/generate-id-BAMRQzMr.d.cts +34 -0
- package/dist/generate-id-BAMRQzMr.d.cts.map +1 -0
- package/dist/generate-id-DuZwLm4m.d.mts +34 -0
- package/dist/generate-id-DuZwLm4m.d.mts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +8 -5
- package/dist/index.d.mts +8 -5
- package/dist/index.mjs +1 -1
- package/dist/middleware-BlrOGKrp.d.cts +4129 -0
- package/dist/middleware-BlrOGKrp.d.cts.map +1 -0
- package/dist/middleware-BmRmwme_.d.mts +4129 -0
- package/dist/middleware-BmRmwme_.d.mts.map +1 -0
- package/dist/resolve-upload-metadata-B2C5e1y1.d.cts +4533 -0
- package/dist/resolve-upload-metadata-B2C5e1y1.d.cts.map +1 -0
- package/dist/resolve-upload-metadata-DbkBzxm8.d.mts +4533 -0
- package/dist/resolve-upload-metadata-DbkBzxm8.d.mts.map +1 -0
- package/dist/run-args-C4no7Ny4.cjs +1 -0
- package/dist/run-args-CIqI4Zc7.mjs +2 -0
- package/dist/run-args-CIqI4Zc7.mjs.map +1 -0
- package/dist/{stream-limiter-BCFULdAM.d.cts → stream-limiter-7wkBVLWT.d.mts} +2 -2
- package/dist/{stream-limiter-BCFULdAM.d.cts.map → stream-limiter-7wkBVLWT.d.mts.map} +1 -1
- package/dist/{stream-limiter-DZ22uIqf.cjs → stream-limiter-B-Y0DTgA.cjs} +1 -1
- package/dist/{stream-limiter-CTJPEJqE.mjs → stream-limiter-CvDuNIyd.mjs} +2 -2
- package/dist/{stream-limiter-CTJPEJqE.mjs.map → stream-limiter-CvDuNIyd.mjs.map} +1 -1
- package/dist/{stream-limiter-Bi7OTbRp.d.mts → stream-limiter-D1KC-6pK.d.cts} +2 -2
- package/dist/{stream-limiter-Bi7OTbRp.d.mts.map → stream-limiter-D1KC-6pK.d.cts.map} +1 -1
- package/dist/streams/index.cjs +1 -1
- package/dist/streams/index.d.cts +1 -1
- package/dist/streams/index.d.mts +2 -2
- package/dist/streams/index.mjs +1 -1
- package/dist/testing/index.cjs +1 -1
- package/dist/testing/index.d.cts +2 -1
- package/dist/testing/index.d.cts.map +1 -1
- package/dist/testing/index.d.mts +7 -4
- package/dist/testing/index.d.mts.map +1 -1
- package/dist/testing/index.mjs +1 -1
- package/dist/{throttle-Da0OA8JT.d.cts → throttle-3FRcr7MU.d.mts} +4 -34
- package/dist/throttle-3FRcr7MU.d.mts.map +1 -0
- package/dist/{throttle-ibiT6E4U.d.mts → throttle-BlH27EGu.d.cts} +4 -34
- package/dist/throttle-BlH27EGu.d.cts.map +1 -0
- package/dist/{throttle-KnkRgZPi.cjs → throttle-Dp59f37i.cjs} +1 -1
- package/dist/{throttle-CnDa3v1k.mjs → throttle-TFY-V41R.mjs} +2 -2
- package/dist/{throttle-CnDa3v1k.mjs.map → throttle-TFY-V41R.mjs.map} +1 -1
- package/dist/types/index.cjs +1 -1
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.mts +3 -5
- package/dist/types/index.mjs +1 -1
- package/dist/upload/index.cjs +1 -1
- package/dist/upload/index.d.cts +1 -1
- package/dist/upload/index.d.mts +4 -4
- package/dist/upload/index.mjs +1 -1
- package/dist/{upload-strategy-negotiator-DfiQ0Fy0.cjs → upload-strategy-negotiator-5da9ZySO.cjs} +1 -1
- package/dist/{upload-strategy-negotiator-BuxPf1sa.mjs → upload-strategy-negotiator-ChKvppnA.mjs} +2 -2
- package/dist/{upload-strategy-negotiator-BuxPf1sa.mjs.map → upload-strategy-negotiator-ChKvppnA.mjs.map} +1 -1
- package/dist/upload-strategy-negotiator-EmOrc2bn.d.cts +455 -0
- package/dist/upload-strategy-negotiator-EmOrc2bn.d.cts.map +1 -0
- package/dist/upload-strategy-negotiator-a2O28qPf.d.mts +455 -0
- package/dist/upload-strategy-negotiator-a2O28qPf.d.mts.map +1 -0
- package/dist/{uploadista-error-B-geDgi8.cjs → uploadista-error-CZx1JU_L.cjs} +3 -1
- package/dist/{uploadista-error-Fsfvr2Bb.mjs → uploadista-error-DQ7V1FlX.mjs} +3 -1
- package/dist/uploadista-error-DQ7V1FlX.mjs.map +1 -0
- package/dist/{uploadista-error-BragVhIs.d.mts → uploadista-error-LtiZn-R_.d.mts} +2 -2
- package/dist/{uploadista-error-BragVhIs.d.mts.map → uploadista-error-LtiZn-R_.d.mts.map} +1 -1
- package/dist/{uploadista-error-Cj_pAFck.d.cts → uploadista-error-eZtG4iyf.d.cts} +2 -2
- package/dist/{uploadista-error-Cj_pAFck.d.cts.map → uploadista-error-eZtG4iyf.d.cts.map} +1 -1
- package/dist/utils/index.cjs +1 -1
- package/dist/utils/index.d.cts +2 -1
- package/dist/utils/index.d.mts +3 -2
- package/dist/utils/index.mjs +1 -1
- package/dist/websocket-Br0ijEZA.cjs +1 -0
- package/dist/websocket-DftnHFfN.mjs +2 -0
- package/dist/websocket-DftnHFfN.mjs.map +1 -0
- package/package.json +3 -3
- package/src/errors/uploadista-error.ts +11 -1
- package/src/flow/README.md +115 -0
- package/src/flow/flow-engine.ts +34 -2
- package/src/flow/flow-queue-store.ts +155 -0
- package/src/flow/flow-queue.ts +640 -0
- package/src/flow/index.ts +4 -0
- package/src/flow/types/flow-queue-item.ts +154 -0
- package/src/types/kv-store.ts +31 -1
- package/tests/flow-queue-store.test.ts +150 -0
- package/tests/flow-queue.test.ts +308 -0
- package/dist/resolve-upload-metadata-BUVl1LoS.d.cts +0 -8723
- package/dist/resolve-upload-metadata-BUVl1LoS.d.cts.map +0 -1
- package/dist/resolve-upload-metadata-MPDmDfOZ.d.mts +0 -8723
- package/dist/resolve-upload-metadata-MPDmDfOZ.d.mts.map +0 -1
- package/dist/run-args-WD1otVrz.mjs +0 -2
- package/dist/run-args-WD1otVrz.mjs.map +0 -1
- package/dist/run-args-g74p8pEZ.cjs +0 -1
- package/dist/throttle-Da0OA8JT.d.cts.map +0 -1
- package/dist/throttle-ibiT6E4U.d.mts.map +0 -1
- package/dist/uploadista-error-Fsfvr2Bb.mjs.map +0 -1
- package/dist/websocket-Avz4T8YB.cjs +0 -1
- package/dist/websocket-CdgVhVJs.mjs +0 -2
- package/dist/websocket-CdgVhVJs.mjs.map +0 -1
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
import { n as UploadistaError } from "./uploadista-error-eZtG4iyf.cjs";
|
|
2
|
+
import { B as DataStoreCapabilities, G as StreamingConfig, O as WebSocketConnection, Y as UploadStrategy, at as UploadFileKVStore, j as UploadEvent, jn as UploadFile, o as InputFile, q as UploadFileDataStores, rt as KvStore, t as Middleware, w as UploadEventEmitter, x as EventEmitter, z as DataStore } from "./middleware-BlrOGKrp.cjs";
|
|
3
|
+
import { a as GenerateIdShape, t as GenerateId } from "./generate-id-BAMRQzMr.cjs";
|
|
4
|
+
import { Context, Effect, Layer, Stream } from "effect";
|
|
5
|
+
|
|
6
|
+
//#region src/upload/mime.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Detect MIME type from buffer using magic bytes (file signatures).
|
|
9
|
+
* Supports a wide range of common file types including images, videos, audio, documents, and archives.
|
|
10
|
+
*
|
|
11
|
+
* @param buffer - File content as Uint8Array
|
|
12
|
+
* @param filename - Optional filename for extension-based fallback
|
|
13
|
+
* @returns Detected MIME type or "application/octet-stream" if unknown
|
|
14
|
+
*/
|
|
15
|
+
declare const detectMimeType: (buffer: Uint8Array, filename?: string) => string;
|
|
16
|
+
/**
|
|
17
|
+
* Compare two MIME types with lenient matching.
|
|
18
|
+
* Matches on major type (e.g., "image/*") to allow for minor variations.
|
|
19
|
+
*
|
|
20
|
+
* @param declared - MIME type provided by client
|
|
21
|
+
* @param detected - MIME type detected from file content
|
|
22
|
+
* @returns true if MIME types are compatible
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* compareMimeTypes("image/png", "image/apng") // true
|
|
26
|
+
* compareMimeTypes("image/jpeg", "image/png") // true (both images)
|
|
27
|
+
* compareMimeTypes("image/png", "application/pdf") // false
|
|
28
|
+
*/
|
|
29
|
+
declare function compareMimeTypes(declared: string, detected: string): boolean;
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/upload/upload-engine.d.ts
|
|
32
|
+
/**
|
|
33
|
+
* Legacy configuration options for UploadEngine.
|
|
34
|
+
*
|
|
35
|
+
* @deprecated Use Effect Layers instead of this configuration object.
|
|
36
|
+
* This type is kept for backward compatibility.
|
|
37
|
+
*
|
|
38
|
+
* @property dataStore - DataStore instance or factory function
|
|
39
|
+
* @property kvStore - KV store for upload metadata
|
|
40
|
+
* @property eventEmitter - Event emitter for upload progress
|
|
41
|
+
* @property generateId - Optional ID generator (defaults to UUID)
|
|
42
|
+
* @property middlewares - Optional request middlewares
|
|
43
|
+
* @property withTracing - Enable Effect tracing for debugging
|
|
44
|
+
*/
|
|
45
|
+
type UploadEngineOptions = {
|
|
46
|
+
dataStore: ((storageId: string) => Promise<DataStore<UploadFile>>) | DataStore<UploadFile>;
|
|
47
|
+
kvStore: KvStore<UploadFile>;
|
|
48
|
+
eventEmitter: EventEmitter<UploadEvent>;
|
|
49
|
+
generateId?: GenerateIdShape;
|
|
50
|
+
middlewares?: Middleware[];
|
|
51
|
+
withTracing?: boolean;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* UploadEngine service interface.
|
|
55
|
+
*
|
|
56
|
+
* This is the core upload handling service that provides all file upload operations.
|
|
57
|
+
* It manages upload lifecycle, resumable uploads, progress tracking, and storage integration.
|
|
58
|
+
*
|
|
59
|
+
* All operations return Effect types for composable, type-safe error handling.
|
|
60
|
+
*
|
|
61
|
+
* @property createUpload - Initiates a new upload and returns metadata
|
|
62
|
+
* @property uploadChunk - Uploads a chunk of data for an existing upload
|
|
63
|
+
* @property getCapabilities - Returns storage backend capabilities
|
|
64
|
+
* @property upload - Complete upload in one operation (create + upload data)
|
|
65
|
+
* @property uploadFromUrl - Uploads a file from a remote URL
|
|
66
|
+
* @property getUpload - Retrieves upload metadata by ID
|
|
67
|
+
* @property read - Reads the complete uploaded file data
|
|
68
|
+
* @property delete - Deletes an upload and its data
|
|
69
|
+
* @property subscribeToUploadEvents - Subscribes WebSocket to upload progress events
|
|
70
|
+
* @property unsubscribeFromUploadEvents - Unsubscribes from upload events
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* // Basic upload flow
|
|
75
|
+
* const program = Effect.gen(function* () {
|
|
76
|
+
* const server = yield* UploadEngine;
|
|
77
|
+
*
|
|
78
|
+
* // 1. Create upload
|
|
79
|
+
* const inputFile: InputFile = {
|
|
80
|
+
* storageId: "s3-production",
|
|
81
|
+
* size: 1024000,
|
|
82
|
+
* type: "image/jpeg",
|
|
83
|
+
* fileName: "photo.jpg"
|
|
84
|
+
* };
|
|
85
|
+
* const upload = yield* server.createUpload(inputFile, "client123");
|
|
86
|
+
*
|
|
87
|
+
* // 2. Upload chunks
|
|
88
|
+
* const chunk = new ReadableStream(...);
|
|
89
|
+
* const updated = yield* server.uploadChunk(upload.id, "client123", chunk);
|
|
90
|
+
*
|
|
91
|
+
* // 3. Read the uploaded file
|
|
92
|
+
* const data = yield* server.read(upload.id, "client123");
|
|
93
|
+
*
|
|
94
|
+
* return upload;
|
|
95
|
+
* });
|
|
96
|
+
*
|
|
97
|
+
* // Upload with WebSocket progress tracking
|
|
98
|
+
* const uploadWithProgress = Effect.gen(function* () {
|
|
99
|
+
* const server = yield* UploadEngine;
|
|
100
|
+
*
|
|
101
|
+
* // Subscribe to progress events
|
|
102
|
+
* yield* server.subscribeToUploadEvents(uploadId, websocket);
|
|
103
|
+
*
|
|
104
|
+
* // Upload (events will be emitted automatically)
|
|
105
|
+
* const result = yield* server.upload(inputFile, clientId, stream);
|
|
106
|
+
*
|
|
107
|
+
* // Unsubscribe when done
|
|
108
|
+
* yield* server.unsubscribeFromUploadEvents(uploadId);
|
|
109
|
+
*
|
|
110
|
+
* return result;
|
|
111
|
+
* });
|
|
112
|
+
*
|
|
113
|
+
* // Upload from URL
|
|
114
|
+
* const urlUpload = Effect.gen(function* () {
|
|
115
|
+
* const server = yield* UploadEngine;
|
|
116
|
+
*
|
|
117
|
+
* const inputFile: InputFile = {
|
|
118
|
+
* storageId: "s3-production",
|
|
119
|
+
* size: 0, // Unknown initially
|
|
120
|
+
* type: "image/png",
|
|
121
|
+
* fileName: "remote-image.png"
|
|
122
|
+
* };
|
|
123
|
+
*
|
|
124
|
+
* const upload = yield* server.uploadFromUrl(
|
|
125
|
+
* inputFile,
|
|
126
|
+
* "client123",
|
|
127
|
+
* "https://example.com/image.png"
|
|
128
|
+
* );
|
|
129
|
+
*
|
|
130
|
+
* return upload;
|
|
131
|
+
* });
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
type UploadEngineShape = {
|
|
135
|
+
createUpload: (inputFile: InputFile, clientId: string | null) => Effect.Effect<UploadFile, UploadistaError>;
|
|
136
|
+
uploadChunk: (uploadId: string, clientId: string | null, chunk: ReadableStream) => Effect.Effect<UploadFile, UploadistaError>;
|
|
137
|
+
getCapabilities: (storageId: string, clientId: string | null) => Effect.Effect<DataStoreCapabilities, UploadistaError>;
|
|
138
|
+
upload: (file: InputFile, clientId: string | null, stream: ReadableStream) => Effect.Effect<UploadFile, UploadistaError>;
|
|
139
|
+
uploadFromUrl: (inputFile: InputFile, clientId: string | null, url: string) => Effect.Effect<UploadFile, UploadistaError>;
|
|
140
|
+
getUpload: (uploadId: string) => Effect.Effect<UploadFile, UploadistaError>;
|
|
141
|
+
/**
|
|
142
|
+
* Reads the complete uploaded file data as bytes (buffered mode).
|
|
143
|
+
* For large files, consider using readStream() for memory efficiency.
|
|
144
|
+
*/
|
|
145
|
+
read: (uploadId: string, clientId: string | null) => Effect.Effect<Uint8Array, UploadistaError>;
|
|
146
|
+
/**
|
|
147
|
+
* Reads file content as a stream of chunks for memory-efficient processing.
|
|
148
|
+
* Falls back to buffered read if the underlying DataStore doesn't support streaming.
|
|
149
|
+
*
|
|
150
|
+
* @param uploadId - The unique identifier of the upload to read
|
|
151
|
+
* @param clientId - Client identifier for multi-tenant routing
|
|
152
|
+
* @param config - Optional streaming configuration (chunk size)
|
|
153
|
+
* @returns An Effect that resolves to a Stream of byte chunks
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* const server = yield* UploadEngine;
|
|
158
|
+
* const stream = yield* server.readStream(uploadId, clientId, { chunkSize: 65536 });
|
|
159
|
+
* // Process stream chunk by chunk with bounded memory
|
|
160
|
+
* yield* Stream.runForEach(stream, (chunk) => processChunk(chunk));
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
readStream: (uploadId: string, clientId: string | null, config?: StreamingConfig) => Effect.Effect<Stream.Stream<Uint8Array, UploadistaError>, UploadistaError>;
|
|
164
|
+
/**
|
|
165
|
+
* Uploads file content from a stream with unknown final size.
|
|
166
|
+
* Creates upload with deferred length, streams content to storage,
|
|
167
|
+
* and updates the upload record with final size when complete.
|
|
168
|
+
*
|
|
169
|
+
* Falls back to buffered upload if the underlying DataStore
|
|
170
|
+
* doesn't support streaming writes.
|
|
171
|
+
*
|
|
172
|
+
* @param file - Input file configuration (size is optional)
|
|
173
|
+
* @param clientId - Client identifier for multi-tenant routing
|
|
174
|
+
* @param stream - Effect Stream of byte chunks to upload
|
|
175
|
+
* @returns The completed UploadFile with final size
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* const server = yield* UploadEngine;
|
|
180
|
+
* const result = yield* server.uploadStream(
|
|
181
|
+
* {
|
|
182
|
+
* storageId: "s3-production",
|
|
183
|
+
* type: "image/webp",
|
|
184
|
+
* uploadLengthDeferred: true,
|
|
185
|
+
* fileName: "optimized.webp",
|
|
186
|
+
* },
|
|
187
|
+
* clientId,
|
|
188
|
+
* transformedStream,
|
|
189
|
+
* );
|
|
190
|
+
* console.log(`Uploaded ${result.size} bytes`);
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
uploadStream: (file: Omit<InputFile, "size"> & {
|
|
194
|
+
size?: number;
|
|
195
|
+
sizeHint?: number;
|
|
196
|
+
}, clientId: string | null, stream: Stream.Stream<Uint8Array, UploadistaError>) => Effect.Effect<UploadFile, UploadistaError>;
|
|
197
|
+
delete: (uploadId: string, clientId: string | null) => Effect.Effect<void, UploadistaError>;
|
|
198
|
+
subscribeToUploadEvents: (uploadId: string, connection: WebSocketConnection) => Effect.Effect<void, UploadistaError>;
|
|
199
|
+
unsubscribeFromUploadEvents: (uploadId: string) => Effect.Effect<void, UploadistaError>;
|
|
200
|
+
};
|
|
201
|
+
declare const UploadEngine_base: Context.TagClass<UploadEngine, "UploadEngine", UploadEngineShape>;
|
|
202
|
+
/**
|
|
203
|
+
* Effect-TS context tag for the UploadEngine service.
|
|
204
|
+
*
|
|
205
|
+
* Use this tag to access the UploadEngine in an Effect context.
|
|
206
|
+
* The server must be provided via a Layer or dependency injection.
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```typescript
|
|
210
|
+
* // Access UploadEngine in an Effect
|
|
211
|
+
* const uploadEffect = Effect.gen(function* () {
|
|
212
|
+
* const server = yield* UploadEngine;
|
|
213
|
+
* const upload = yield* server.createUpload(inputFile, clientId);
|
|
214
|
+
* return upload;
|
|
215
|
+
* });
|
|
216
|
+
*
|
|
217
|
+
* // Provide UploadEngine layer
|
|
218
|
+
* const program = uploadEffect.pipe(
|
|
219
|
+
* Effect.provide(uploadEngine),
|
|
220
|
+
* Effect.provide(uploadFileKvStore),
|
|
221
|
+
* Effect.provide(dataStoreLayer),
|
|
222
|
+
* Effect.provide(eventEmitterLayer)
|
|
223
|
+
* );
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
declare class UploadEngine extends UploadEngine_base {}
|
|
227
|
+
/**
|
|
228
|
+
* Creates the UploadEngine implementation.
|
|
229
|
+
*
|
|
230
|
+
* This function constructs the UploadEngine service by composing all required
|
|
231
|
+
* dependencies (KV store, data stores, event emitter, ID generator). It implements
|
|
232
|
+
* all upload operations defined in UploadEngineShape.
|
|
233
|
+
*
|
|
234
|
+
* The server automatically handles:
|
|
235
|
+
* - Upload lifecycle management (create, resume, complete)
|
|
236
|
+
* - Progress tracking and event emission
|
|
237
|
+
* - Storage backend routing based on storageId
|
|
238
|
+
* - Error handling with proper UploadistaError types
|
|
239
|
+
*
|
|
240
|
+
* @returns An Effect that yields the UploadEngineShape implementation
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* // Create a custom UploadEngine layer
|
|
245
|
+
* const myUploadEngine = Layer.effect(
|
|
246
|
+
* UploadEngine,
|
|
247
|
+
* createUploadEngine()
|
|
248
|
+
* );
|
|
249
|
+
*
|
|
250
|
+
* // Use in a program
|
|
251
|
+
* const program = Effect.gen(function* () {
|
|
252
|
+
* const server = yield* UploadEngine;
|
|
253
|
+
* // Use server operations...
|
|
254
|
+
* }).pipe(Effect.provide(myUploadEngine));
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
declare function createUploadEngine(): Effect.Effect<{
|
|
258
|
+
upload: (inputFile: InputFile, clientId: string | null, stream: ReadableStream) => Effect.Effect<UploadFile, UploadistaError, never>;
|
|
259
|
+
uploadFromUrl: (inputFile: InputFile, clientId: string | null, url: string) => Effect.Effect<UploadFile, UploadistaError, never>;
|
|
260
|
+
createUpload: (inputFile: InputFile, clientId: string | null) => Effect.Effect<UploadFile, UploadistaError, never>;
|
|
261
|
+
uploadChunk: (uploadId: string, clientId: string | null, chunk: ReadableStream) => Effect.Effect<UploadFile, UploadistaError, never>;
|
|
262
|
+
getUpload: (uploadId: string) => Effect.Effect<UploadFile, UploadistaError, never>;
|
|
263
|
+
read: (uploadId: string, clientId: string | null) => Effect.Effect<Uint8Array<ArrayBufferLike>, UploadistaError, never>;
|
|
264
|
+
readStream: (uploadId: string, clientId: string | null, config?: StreamingConfig) => Effect.Effect<Stream.Stream<Uint8Array<ArrayBufferLike>, UploadistaError, never>, UploadistaError, never>;
|
|
265
|
+
uploadStream: (file: Omit<InputFile, "size"> & {
|
|
266
|
+
size?: number;
|
|
267
|
+
sizeHint?: number;
|
|
268
|
+
}, clientId: string | null, stream: Stream.Stream<Uint8Array, UploadistaError>) => Effect.Effect<UploadFile, UploadistaError, never>;
|
|
269
|
+
delete: (uploadId: string, clientId: string | null) => Effect.Effect<void, UploadistaError, never>;
|
|
270
|
+
getCapabilities: (storageId: string, clientId: string | null) => Effect.Effect<DataStoreCapabilities, UploadistaError, never>;
|
|
271
|
+
subscribeToUploadEvents: (uploadId: string, connection: WebSocketConnection) => Effect.Effect<void, UploadistaError, never>;
|
|
272
|
+
unsubscribeFromUploadEvents: (uploadId: string) => Effect.Effect<void, UploadistaError, never>;
|
|
273
|
+
}, never, GenerateId | UploadFileDataStores | UploadFileKVStore | UploadEventEmitter>;
|
|
274
|
+
/**
|
|
275
|
+
* Pre-built UploadEngine Effect Layer.
|
|
276
|
+
*
|
|
277
|
+
* This layer provides a ready-to-use UploadEngine implementation that can be
|
|
278
|
+
* composed with other layers to build a complete upload system.
|
|
279
|
+
*
|
|
280
|
+
* Required dependencies:
|
|
281
|
+
* - UploadFileKVStore: For storing upload metadata
|
|
282
|
+
* - UploadFileDataStores: For routing to storage backends
|
|
283
|
+
* - UploadEventEmitter: For progress events
|
|
284
|
+
* - GenerateId: For creating upload IDs
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* ```typescript
|
|
288
|
+
* // Compose a complete upload system
|
|
289
|
+
* const fullUploadSystem = Layer.mergeAll(
|
|
290
|
+
* uploadEngine,
|
|
291
|
+
* uploadFileKvStore,
|
|
292
|
+
* dataStoreLayer,
|
|
293
|
+
* uploadEventEmitter,
|
|
294
|
+
* generateIdLayer
|
|
295
|
+
* );
|
|
296
|
+
*
|
|
297
|
+
* // Use in application
|
|
298
|
+
* const app = Effect.gen(function* () {
|
|
299
|
+
* const server = yield* UploadEngine;
|
|
300
|
+
* // Perform uploads...
|
|
301
|
+
* }).pipe(Effect.provide(fullUploadSystem));
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
declare const uploadEngine: Layer.Layer<UploadEngine, never, GenerateId | UploadFileDataStores | UploadFileKVStore | UploadEventEmitter>;
|
|
305
|
+
//#endregion
|
|
306
|
+
//#region src/upload/upload-strategy-negotiator.d.ts
|
|
307
|
+
/**
|
|
308
|
+
* Configuration options for upload strategy negotiation.
|
|
309
|
+
*
|
|
310
|
+
* @property fileSize - Size of the file to be uploaded in bytes
|
|
311
|
+
* @property preferredStrategy - Preferred upload strategy (single, parallel, resumable)
|
|
312
|
+
* @property preferredChunkSize - Preferred chunk size in bytes
|
|
313
|
+
* @property parallelUploads - Number of parallel upload connections
|
|
314
|
+
* @property minChunkSizeForParallel - Minimum file size to consider parallel uploads
|
|
315
|
+
*/
|
|
316
|
+
type UploadStrategyOptions = {
|
|
317
|
+
fileSize: number;
|
|
318
|
+
preferredStrategy?: UploadStrategy;
|
|
319
|
+
preferredChunkSize?: number;
|
|
320
|
+
parallelUploads?: number;
|
|
321
|
+
minChunkSizeForParallel?: number;
|
|
322
|
+
};
|
|
323
|
+
/**
|
|
324
|
+
* Result of upload strategy negotiation.
|
|
325
|
+
*
|
|
326
|
+
* @property strategy - The negotiated upload strategy
|
|
327
|
+
* @property chunkSize - The negotiated chunk size in bytes
|
|
328
|
+
* @property parallelUploads - The negotiated number of parallel uploads
|
|
329
|
+
* @property reasoning - Array of reasoning strings explaining the decisions
|
|
330
|
+
* @property warnings - Array of warning messages about adjustments made
|
|
331
|
+
*/
|
|
332
|
+
type NegotiatedStrategy = {
|
|
333
|
+
strategy: UploadStrategy;
|
|
334
|
+
chunkSize: number;
|
|
335
|
+
parallelUploads: number;
|
|
336
|
+
reasoning: string[];
|
|
337
|
+
warnings: string[];
|
|
338
|
+
};
|
|
339
|
+
/**
|
|
340
|
+
* Negotiates the optimal upload strategy based on data store capabilities and file characteristics.
|
|
341
|
+
*
|
|
342
|
+
* This class analyzes data store capabilities, file size, and user preferences to determine
|
|
343
|
+
* the best upload strategy (single, parallel, resumable) and optimal parameters like chunk size
|
|
344
|
+
* and parallel connection count.
|
|
345
|
+
*
|
|
346
|
+
* The negotiator considers:
|
|
347
|
+
* - Data store capabilities (parallel uploads, resumable uploads, concatenation)
|
|
348
|
+
* - File size and chunk size constraints
|
|
349
|
+
* - User preferences and requirements
|
|
350
|
+
* - Performance optimization opportunities
|
|
351
|
+
*
|
|
352
|
+
* @example
|
|
353
|
+
* ```typescript
|
|
354
|
+
* // Create negotiator for S3 data store
|
|
355
|
+
* const negotiator = new UploadStrategyNegotiator(
|
|
356
|
+
* s3Capabilities,
|
|
357
|
+
* (strategy) => s3Capabilities.supportsStrategy(strategy)
|
|
358
|
+
* );
|
|
359
|
+
*
|
|
360
|
+
* // Negotiate strategy for large file
|
|
361
|
+
* const result = negotiator.negotiateStrategy({
|
|
362
|
+
* fileSize: 100_000_000, // 100MB
|
|
363
|
+
* preferredStrategy: "parallel",
|
|
364
|
+
* preferredChunkSize: 5_000_000, // 5MB chunks
|
|
365
|
+
* parallelUploads: 4
|
|
366
|
+
* });
|
|
367
|
+
*
|
|
368
|
+
* console.log(result.strategy); // "parallel"
|
|
369
|
+
* console.log(result.chunkSize); // 5_000_000
|
|
370
|
+
* console.log(result.reasoning); // ["Using preferred strategy: parallel", ...]
|
|
371
|
+
* ```
|
|
372
|
+
*/
|
|
373
|
+
declare class UploadStrategyNegotiator {
|
|
374
|
+
private capabilities;
|
|
375
|
+
private validateUploadStrategy;
|
|
376
|
+
/**
|
|
377
|
+
* Creates a new upload strategy negotiator.
|
|
378
|
+
*
|
|
379
|
+
* @param capabilities - Data store capabilities and constraints
|
|
380
|
+
* @param validateUploadStrategy - Function to validate if a strategy is supported
|
|
381
|
+
*/
|
|
382
|
+
constructor(capabilities: DataStoreCapabilities, validateUploadStrategy: (strategy: UploadStrategy) => boolean);
|
|
383
|
+
/**
|
|
384
|
+
* Negotiates the optimal upload strategy based on options and data store capabilities.
|
|
385
|
+
*
|
|
386
|
+
* This method analyzes the provided options and data store capabilities to determine
|
|
387
|
+
* the best upload strategy, chunk size, and parallel upload settings. It considers
|
|
388
|
+
* user preferences, file size, and data store constraints to make optimal decisions.
|
|
389
|
+
*
|
|
390
|
+
* The negotiation process:
|
|
391
|
+
* 1. Validates preferred strategy against data store capabilities
|
|
392
|
+
* 2. Automatically selects strategy based on file size and capabilities
|
|
393
|
+
* 3. Adjusts chunk size to fit within data store constraints
|
|
394
|
+
* 4. Validates parallel upload settings
|
|
395
|
+
* 5. Ensures final strategy is supported by the data store
|
|
396
|
+
*
|
|
397
|
+
* @param options - Upload strategy options including file size and preferences
|
|
398
|
+
* @returns Negotiated strategy with reasoning and warnings
|
|
399
|
+
*
|
|
400
|
+
* @example
|
|
401
|
+
* ```typescript
|
|
402
|
+
* const result = negotiator.negotiateStrategy({
|
|
403
|
+
* fileSize: 50_000_000, // 50MB
|
|
404
|
+
* preferredStrategy: "parallel",
|
|
405
|
+
* preferredChunkSize: 5_000_000, // 5MB
|
|
406
|
+
* parallelUploads: 3
|
|
407
|
+
* });
|
|
408
|
+
*
|
|
409
|
+
* console.log(result.strategy); // "parallel"
|
|
410
|
+
* console.log(result.chunkSize); // 5_000_000
|
|
411
|
+
* console.log(result.parallelUploads); // 3
|
|
412
|
+
* console.log(result.reasoning); // ["Using preferred strategy: parallel", ...]
|
|
413
|
+
* console.log(result.warnings); // [] (no warnings)
|
|
414
|
+
* ```
|
|
415
|
+
*/
|
|
416
|
+
negotiateStrategy(options: UploadStrategyOptions): NegotiatedStrategy;
|
|
417
|
+
/**
|
|
418
|
+
* Gets the data store capabilities used by this negotiator.
|
|
419
|
+
*
|
|
420
|
+
* @returns The data store capabilities and constraints
|
|
421
|
+
*/
|
|
422
|
+
getDataStoreCapabilities(): DataStoreCapabilities;
|
|
423
|
+
/**
|
|
424
|
+
* Validates upload strategy configuration against data store capabilities.
|
|
425
|
+
*
|
|
426
|
+
* This method checks if the provided configuration is valid for the current
|
|
427
|
+
* data store capabilities without performing the actual negotiation. It's
|
|
428
|
+
* useful for pre-validation before attempting to negotiate a strategy.
|
|
429
|
+
*
|
|
430
|
+
* @param options - Upload strategy options to validate
|
|
431
|
+
* @returns Validation result with validity flag and error messages
|
|
432
|
+
*
|
|
433
|
+
* @example
|
|
434
|
+
* ```typescript
|
|
435
|
+
* const validation = negotiator.validateConfiguration({
|
|
436
|
+
* fileSize: 10_000_000,
|
|
437
|
+
* preferredStrategy: "parallel",
|
|
438
|
+
* preferredChunkSize: 1_000_000,
|
|
439
|
+
* parallelUploads: 5
|
|
440
|
+
* });
|
|
441
|
+
*
|
|
442
|
+
* if (!validation.valid) {
|
|
443
|
+
* console.log("Configuration errors:", validation.errors);
|
|
444
|
+
* // Handle validation errors
|
|
445
|
+
* }
|
|
446
|
+
* ```
|
|
447
|
+
*/
|
|
448
|
+
validateConfiguration(options: UploadStrategyOptions): {
|
|
449
|
+
valid: boolean;
|
|
450
|
+
errors: string[];
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
//#endregion
|
|
454
|
+
export { UploadEngineOptions as a, uploadEngine as c, UploadEngine as i, compareMimeTypes as l, UploadStrategyNegotiator as n, UploadEngineShape as o, UploadStrategyOptions as r, createUploadEngine as s, NegotiatedStrategy as t, detectMimeType as u };
|
|
455
|
+
//# sourceMappingURL=upload-strategy-negotiator-EmOrc2bn.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload-strategy-negotiator-EmOrc2bn.d.cts","names":[],"sources":["../src/upload/mime.ts","../src/upload/upload-engine.ts","../src/upload/upload-strategy-negotiator.ts"],"mappings":";;;;;;;;;;;;AA+BA;;cAAa,cAAA,GACX,MAAA,EAAQ,UAAA,EACR,QAAA;;;;;;;AAqYF;;;;;;;iBAAgB,gBAAA,CAAiB,QAAA,UAAkB,QAAA;;;;AAvYnD;;;;;;;;;AAuYA;;;KChYY,mBAAA;EACV,SAAA,IACM,SAAA,aAAsB,OAAA,CAAQ,SAAA,CAAU,UAAA,MAC1C,SAAA,CAAU,UAAA;EACd,OAAA,EAAS,OAAA,CAAQ,UAAA;EACjB,YAAA,EAAc,YAAA,CAAa,WAAA;EAC3B,UAAA,GAAa,eAAA;EACb,WAAA,GAAc,UAAA;EACd,WAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoFF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAAY,iBAAA;EACV,YAAA,GACE,SAAA,EAAW,SAAA,EACX,QAAA,oBACG,MAAA,CAAO,MAAA,CAAO,UAAA,EAAY,eAAA;EAC/B,WAAA,GACE,QAAA,UACA,QAAA,iBACA,KAAA,EAAO,cAAA,KACJ,MAAA,CAAO,MAAA,CAAO,UAAA,EAAY,eAAA;EAC/B,eAAA,GACE,SAAA,UACA,QAAA,oBACG,MAAA,CAAO,MAAA,CAAO,qBAAA,EAAuB,eAAA;EAC1C,MAAA,GACE,IAAA,EAAM,SAAA,EACN,QAAA,iBACA,MAAA,EAAQ,cAAA,KACL,MAAA,CAAO,MAAA,CAAO,UAAA,EAAY,eAAA;EAC/B,aAAA,GACE,SAAA,EAAW,SAAA,EACX,QAAA,iBACA,GAAA,aACG,MAAA,CAAO,MAAA,CAAO,UAAA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