ocel 0.0.1-alpha.0 → 0.0.1
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/LICENSE +202 -0
- package/NOTICE +2 -0
- package/README.md +98 -0
- package/dist/binding/binding.d.ts +22 -0
- package/dist/binding/binding.js +60 -0
- package/dist/binding/unprovisioned.d.ts +17 -0
- package/dist/binding/unprovisioned.js +25 -0
- package/dist/bucket/bucket-client.d.ts +4 -0
- package/dist/bucket/bucket-client.js +5 -0
- package/dist/bucket/bucket-context.d.ts +8 -0
- package/dist/bucket/bucket-context.js +10 -0
- package/dist/bucket/bucket.d.ts +60 -0
- package/dist/bucket/bucket.js +91 -0
- package/dist/bucket/client.d.ts +49 -0
- package/dist/bucket/client.js +95 -0
- package/dist/bucket/errors.d.ts +12 -0
- package/dist/bucket/errors.js +20 -0
- package/dist/bucket/express.d.ts +10 -0
- package/dist/bucket/express.js +24 -0
- package/dist/bucket/hono.d.ts +18 -0
- package/dist/bucket/hono.js +13 -0
- package/dist/bucket/index.d.ts +8 -0
- package/dist/bucket/index.js +6 -0
- package/dist/bucket/keys.d.ts +5 -0
- package/dist/bucket/keys.js +24 -0
- package/dist/bucket/metadata.d.ts +6 -0
- package/dist/bucket/metadata.js +6 -0
- package/dist/bucket/next.d.ts +15 -0
- package/dist/bucket/next.js +11 -0
- package/dist/bucket/objects.d.ts +130 -0
- package/dist/bucket/objects.js +350 -0
- package/dist/bucket/route.d.ts +13 -0
- package/dist/bucket/route.js +247 -0
- package/dist/bucket/server-only.js +5 -0
- package/dist/bucket/types.d.ts +63 -0
- package/dist/bucket/uploader.d.ts +3 -0
- package/dist/bucket/uploader.js +6 -0
- package/dist/build-env.d.ts +17 -0
- package/dist/build-env.js +41 -0
- package/dist/config.d.ts +30 -0
- package/dist/config.js +9 -0
- package/dist/declaration/callsite.d.ts +15 -0
- package/dist/declaration/callsite.js +43 -0
- package/dist/declaration/component.d.ts +4 -0
- package/dist/declaration/component.js +1 -0
- package/dist/declaration/defer.d.ts +5 -0
- package/dist/declaration/defer.js +9 -0
- package/dist/delivery/duration.d.ts +13 -0
- package/dist/delivery/duration.js +36 -0
- package/dist/delivery/lane.d.ts +4 -0
- package/dist/delivery/lane.js +15 -0
- package/dist/delivery/payload.d.ts +6 -0
- package/dist/delivery/payload.js +14 -0
- package/dist/delivery/retry.d.ts +16 -0
- package/dist/delivery/retry.js +10 -0
- package/dist/delivery/schema.d.ts +10 -0
- package/dist/delivery/schema.js +20 -0
- package/dist/dns.d.ts +11 -0
- package/dist/dns.js +4 -0
- package/dist/edge.d.ts +4 -0
- package/dist/edge.js +4 -0
- package/dist/env/access.d.ts +22 -0
- package/dist/env/access.js +49 -0
- package/dist/env/client.d.ts +5 -0
- package/dist/env/client.js +10 -0
- package/dist/env/declare.d.ts +2 -0
- package/dist/env/declare.js +83 -0
- package/dist/env/definition.d.ts +46 -0
- package/dist/env/definition.js +164 -0
- package/dist/env/deployment.d.ts +23 -0
- package/dist/env/deployment.js +13 -0
- package/dist/env/edge.d.ts +10 -0
- package/dist/env/edge.js +30 -0
- package/dist/env/errors.d.ts +9 -0
- package/dist/env/errors.js +9 -0
- package/dist/env/file.d.ts +1 -0
- package/dist/env/file.js +27 -0
- package/dist/env/index.d.ts +10 -0
- package/dist/env/index.js +63 -0
- package/dist/env/live.d.ts +3 -0
- package/dist/env/live.js +12 -0
- package/dist/env/schema.d.ts +27 -0
- package/dist/env/schema.js +43 -0
- package/dist/env/scope.d.ts +7 -0
- package/dist/env/scope.js +45 -0
- package/dist/env/standard.d.ts +10 -0
- package/dist/env/standard.js +21 -0
- package/dist/env/value.d.ts +5 -0
- package/dist/env/value.js +26 -0
- package/dist/env-source.d.ts +17 -0
- package/dist/env-source.js +16 -0
- package/dist/gen/proto/app/bucket/v1/bucket_pb.d.ts +911 -0
- package/dist/gen/proto/app/bucket/v1/bucket_pb.js +253 -0
- package/dist/gen/proto/app/realtime/v1/realtime_pb.d.ts +50 -0
- package/dist/gen/proto/app/realtime/v1/realtime_pb.js +23 -0
- package/dist/gen/proto/app/resources/v1/resources_pb.d.ts +554 -0
- package/dist/gen/proto/app/resources/v1/resources_pb.js +214 -0
- package/dist/gen/proto/app/resources/v1/variables_pb.d.ts +231 -0
- package/dist/gen/proto/app/resources/v1/variables_pb.js +101 -0
- package/dist/gen/proto/app/task/v1/task_pb.d.ts +498 -0
- package/dist/gen/proto/app/task/v1/task_pb.js +151 -0
- package/dist/gen/proto/app/topic/v1/topic_pb.d.ts +456 -0
- package/dist/gen/proto/app/topic/v1/topic_pb.js +125 -0
- package/dist/gen/proto/buf/validate/validate_pb.d.ts +4833 -0
- package/dist/gen/proto/buf/validate/validate_pb.js +356 -0
- package/dist/gen/proto/common/bindings/v1/bindings_pb.d.ts +378 -0
- package/dist/gen/proto/common/bindings/v1/bindings_pb.js +140 -0
- package/dist/generated/config.d.ts +428 -0
- package/dist/generated/config.js +2 -0
- package/dist/kv/entries.d.ts +193 -0
- package/dist/kv/entries.js +325 -0
- package/dist/kv/errors.d.ts +12 -0
- package/dist/kv/errors.js +14 -0
- package/dist/kv/index.d.ts +6 -0
- package/dist/kv/index.js +3 -0
- package/dist/kv/ioredis.d.ts +2 -0
- package/dist/kv/ioredis.js +20 -0
- package/dist/kv/kv.d.ts +84 -0
- package/dist/kv/kv.js +177 -0
- package/dist/kv/pattern.d.ts +27 -0
- package/dist/kv/pattern.js +73 -0
- package/dist/kv/ttl.d.ts +22 -0
- package/dist/kv/ttl.js +21 -0
- package/dist/postgres/index.d.ts +21 -2
- package/dist/postgres/index.js +73 -2
- package/dist/postgres/pg.d.ts +5 -4
- package/dist/postgres/pg.js +16 -12
- package/dist/providers/aws/dns.d.ts +11 -0
- package/dist/providers/aws/dns.js +4 -0
- package/dist/providers/aws/edge.d.ts +6 -0
- package/dist/providers/aws/edge.js +8 -0
- package/dist/providers/aws/index.d.ts +4 -0
- package/dist/providers/aws/index.js +4 -0
- package/dist/providers/gcp/edge.d.ts +14 -0
- package/dist/providers/gcp/edge.js +14 -0
- package/dist/providers/gcp/index.d.ts +9 -0
- package/dist/providers/gcp/index.js +9 -0
- package/dist/providers/vps/index.d.ts +4 -0
- package/dist/providers/vps/index.js +4 -0
- package/dist/realtime/client-error.d.ts +30 -0
- package/dist/realtime/client-error.js +17 -0
- package/dist/realtime/client-event-socket.d.ts +8 -0
- package/dist/realtime/client-event-socket.js +169 -0
- package/dist/realtime/client-transport.d.ts +29 -0
- package/dist/realtime/client-transport.js +13 -0
- package/dist/realtime/client.d.ts +150 -0
- package/dist/realtime/client.js +345 -0
- package/dist/realtime/express.d.ts +18 -0
- package/dist/realtime/express.js +83 -0
- package/dist/realtime/handler.d.ts +56 -0
- package/dist/realtime/handler.js +287 -0
- package/dist/realtime/hono.d.ts +19 -0
- package/dist/realtime/hono.js +24 -0
- package/dist/realtime/index.d.ts +2 -0
- package/dist/realtime/index.js +2 -0
- package/dist/realtime/next.d.ts +26 -0
- package/dist/realtime/next.js +16 -0
- package/dist/realtime/realtime.d.ts +181 -0
- package/dist/realtime/realtime.js +205 -0
- package/dist/realtime/token.d.ts +20 -0
- package/dist/realtime/token.js +45 -0
- package/dist/realtime/transport.d.ts +11 -0
- package/dist/realtime/transport.js +15 -0
- package/dist/realtime/wire.d.ts +30 -0
- package/dist/realtime/wire.js +104 -0
- package/dist/runtime/dev-server.d.ts +8 -0
- package/dist/runtime/dev-server.js +8 -0
- package/dist/runtime/rpc.d.ts +23 -0
- package/dist/runtime/rpc.js +24 -0
- package/dist/runtime/transport.d.ts +11 -0
- package/dist/runtime/transport.js +35 -0
- package/dist/task/errors.d.ts +7 -0
- package/dist/task/errors.js +7 -0
- package/dist/task/hooks.d.ts +57 -0
- package/dist/task/hooks.js +1 -0
- package/dist/task/index.d.ts +9 -0
- package/dist/task/index.js +4 -0
- package/dist/task/runs.d.ts +74 -0
- package/dist/task/runs.js +82 -0
- package/dist/task/task.d.ts +117 -0
- package/dist/task/task.js +109 -0
- package/dist/topic/dead-letters.d.ts +53 -0
- package/dist/topic/dead-letters.js +62 -0
- package/dist/topic/index.d.ts +8 -0
- package/dist/topic/index.js +4 -0
- package/dist/topic/topic.d.ts +85 -0
- package/dist/topic/topic.js +117 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +2 -0
- package/dist/worker/context.d.ts +36 -0
- package/dist/worker/context.js +1 -0
- package/dist/worker/deliver.d.ts +13 -0
- package/dist/worker/deliver.js +258 -0
- package/dist/worker/index.d.ts +4 -0
- package/dist/worker/index.js +2 -0
- package/dist/worker/registry.d.ts +28 -0
- package/dist/worker/registry.js +22 -0
- package/dist/worker/semaphore.d.ts +7 -0
- package/dist/worker/semaphore.js +36 -0
- package/dist/worker/worker.d.ts +21 -0
- package/dist/worker/worker.js +32 -0
- package/package.json +158 -57
- package/bin/run.js +0 -39
- package/dist/blob/bucket.d.ts +0 -55
- package/dist/blob/bucket.js +0 -65
- package/dist/blob/index.d.ts +0 -8
- package/dist/blob/index.js +0 -13
- package/dist/blob/integrations/client.d.ts +0 -25
- package/dist/blob/integrations/client.js +0 -71
- package/dist/blob/integrations/hono.d.ts +0 -31
- package/dist/blob/integrations/hono.js +0 -11
- package/dist/blob/mime-types.d.ts +0 -1
- package/dist/blob/parse.d.ts +0 -16
- package/dist/blob/parse.js +0 -69
- package/dist/blob/s3-listener.d.ts +0 -7
- package/dist/blob/s3-listener.js +0 -35
- package/dist/blob/types.d.ts +0 -128
- package/dist/blob/types.js +0 -1
- package/dist/blob/upload-error.d.ts +0 -35
- package/dist/blob/upload-error.js +0 -54
- package/dist/blob/uploader.d.ts +0 -67
- package/dist/blob/uploader.js +0 -323
- package/dist/internal/db/index.d.ts +0 -68
- package/dist/internal/db/index.js +0 -73
- package/dist/lambda/index.d.ts +0 -2
- package/dist/lambda/index.js +0 -4
- package/dist/lambda/integrations/express.d.ts +0 -3
- package/dist/lambda/integrations/express.js +0 -13
- package/dist/lambda/integrations/hono.d.ts +0 -3
- package/dist/lambda/integrations/hono.js +0 -13
- package/dist/lambda/lambda.d.ts +0 -43
- package/dist/lambda/lambda.js +0 -30
- package/dist/utils/component.d.ts +0 -3
- package/dist/utils/constants.d.ts +0 -2
- package/dist/utils/constants.js +0 -2
- package/dist/utils/nanoid.d.ts +0 -1
- package/dist/utils/nanoid.js +0 -6
- package/dist/utils/rpc.d.ts +0 -11
- package/dist/utils/rpc.js +0 -17
- package/dist/utils/stack.d.ts +0 -4
- package/dist/utils/stack.js +0 -23
- package/dist/workflow/index.d.ts +0 -3
- package/dist/workflow/index.js +0 -4
- package/dist/workflow/workflow.d.ts +0 -34
- package/dist/workflow/workflow.js +0 -146
- package/src/blob/bucket.ts +0 -92
- package/src/blob/index.ts +0 -34
- package/src/blob/integrations/client.ts +0 -127
- package/src/blob/integrations/hono.ts +0 -16
- package/src/blob/mime-types.ts +0 -68
- package/src/blob/parse.ts +0 -93
- package/src/blob/s3-listener.ts +0 -48
- package/src/blob/types.ts +0 -142
- package/src/blob/upload-error.ts +0 -67
- package/src/blob/uploader.ts +0 -426
- package/src/internal/db/index.ts +0 -78
- package/src/lambda/index.ts +0 -8
- package/src/lambda/integrations/express.ts +0 -25
- package/src/lambda/integrations/hono.ts +0 -25
- package/src/lambda/lambda.ts +0 -94
- package/src/postgres/index.ts +0 -5
- package/src/postgres/pg.ts +0 -33
- package/src/utils/component.ts +0 -3
- package/src/utils/constants.ts +0 -2
- package/src/utils/nanoid.ts +0 -9
- package/src/utils/rpc.ts +0 -28
- package/src/utils/stack.ts +0 -26
- package/src/workflow/index.ts +0 -9
- package/src/workflow/workflow.ts +0 -235
- /package/dist/{blob/mime-types.js → bucket/server-only.d.ts} +0 -0
- /package/dist/{utils/component.js → bucket/types.js} +0 -0
package/dist/blob/parse.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { UploadError } from "./upload-error";
|
|
2
|
-
export function parseReq(req) {
|
|
3
|
-
if (req instanceof Request) {
|
|
4
|
-
const headers = {};
|
|
5
|
-
req.headers.forEach((value, key) => {
|
|
6
|
-
headers[key] = value;
|
|
7
|
-
});
|
|
8
|
-
return {
|
|
9
|
-
headers,
|
|
10
|
-
method: req.method,
|
|
11
|
-
url: req.url,
|
|
12
|
-
path: new URL(req.url).pathname,
|
|
13
|
-
query: new URL(req.url).searchParams,
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
const headers = {};
|
|
17
|
-
for (const [key, value] of Object.entries(req.headers)) {
|
|
18
|
-
if (typeof value === "string") {
|
|
19
|
-
headers[key] = value;
|
|
20
|
-
}
|
|
21
|
-
else if (Array.isArray(value)) {
|
|
22
|
-
headers[key] = value.join(", ");
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
const url = new URL(req.url || "", "http://localhost");
|
|
26
|
-
return {
|
|
27
|
-
headers,
|
|
28
|
-
method: req.method || "GET",
|
|
29
|
-
url: req.url || "",
|
|
30
|
-
path: url.pathname,
|
|
31
|
-
query: url.searchParams,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Converts a human-readable file size string (e.g., "10MB", "2.5GB") into bytes.
|
|
36
|
-
* Throws an error for invalid input formats.
|
|
37
|
-
* * @param size The file size represented as a number (bytes) or a string with units (KB, MB, GB, B).
|
|
38
|
-
* @returns The size in bytes (number).
|
|
39
|
-
*/
|
|
40
|
-
export function parseFileSize(size) {
|
|
41
|
-
if (typeof size === "number") {
|
|
42
|
-
if (size < 0) {
|
|
43
|
-
throw UploadError.badRequest("File size cannot be negative.");
|
|
44
|
-
}
|
|
45
|
-
return size;
|
|
46
|
-
}
|
|
47
|
-
// Convert the input to uppercase to handle 'mb', 'MB', 'Mb' uniformly
|
|
48
|
-
const cleanSize = size.toUpperCase().trim();
|
|
49
|
-
// Regular expression to extract the numeric value and the unit
|
|
50
|
-
// Captures: (1) The number part, (2) The unit part (B, KB, MB, GB)
|
|
51
|
-
const match = cleanSize.match(/^(\d+(\.\d+)?)([A-Z]+)$/);
|
|
52
|
-
if (!match) {
|
|
53
|
-
throw UploadError.badRequest(`Invalid file size format: "${size}". Expected formats: "10MB", "2GB", "512KB", or raw bytes.`);
|
|
54
|
-
}
|
|
55
|
-
const numericValue = Number.parseFloat(match[1] ?? "0");
|
|
56
|
-
const unit = match[3] ?? "";
|
|
57
|
-
const byteConversionMap = {
|
|
58
|
-
B: 1,
|
|
59
|
-
KB: 1024,
|
|
60
|
-
MB: 1024 ** 2, // 1,048,576
|
|
61
|
-
GB: 1024 ** 3, // 1,073,741,824
|
|
62
|
-
};
|
|
63
|
-
const multiplier = byteConversionMap[unit];
|
|
64
|
-
if (!multiplier) {
|
|
65
|
-
throw new Error(`Invalid file size unit: "${unit}". Must be B, KB, MB, or GB.`);
|
|
66
|
-
}
|
|
67
|
-
// Return the size rounded to the nearest integer byte
|
|
68
|
-
return Math.round(numericValue * multiplier);
|
|
69
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* S3 event listener Lambda for ocel/blob.
|
|
3
|
-
* Receives ObjectCreated events, reads x-ocel-session-id from object metadata,
|
|
4
|
-
* and updates the UploadSession in DynamoDB to SUCCESS.
|
|
5
|
-
*/
|
|
6
|
-
import type { S3Handler } from "aws-lambda";
|
|
7
|
-
export declare const handler: S3Handler;
|
package/dist/blob/s3-listener.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { HeadObjectCommand, S3Client } from "@aws-sdk/client-s3";
|
|
2
|
-
import { UpdateItemCommand, DynamoDBClient } from "@aws-sdk/client-dynamodb";
|
|
3
|
-
const s3 = new S3Client({});
|
|
4
|
-
const dynamo = new DynamoDBClient({});
|
|
5
|
-
const TABLE_NAME = process.env.OCEL_TABLE_NAME || "OcelTable";
|
|
6
|
-
export const handler = async (event) => {
|
|
7
|
-
for (const record of event.Records) {
|
|
8
|
-
const bucket = record.s3.bucket.name;
|
|
9
|
-
const key = decodeURIComponent(record.s3.object.key.replace(/\+/g, " "));
|
|
10
|
-
try {
|
|
11
|
-
const head = await s3.send(new HeadObjectCommand({ Bucket: bucket, Key: key }));
|
|
12
|
-
const sessionId = head.Metadata?.["x-ocel-session-id"];
|
|
13
|
-
if (!sessionId)
|
|
14
|
-
continue;
|
|
15
|
-
const pk = `SESSION#${sessionId}`.toLowerCase();
|
|
16
|
-
const sk = `FILE#${bucket}#${key}`.toLowerCase();
|
|
17
|
-
await dynamo.send(new UpdateItemCommand({
|
|
18
|
-
TableName: TABLE_NAME,
|
|
19
|
-
Key: {
|
|
20
|
-
pk: { S: pk },
|
|
21
|
-
sk: { S: sk },
|
|
22
|
-
},
|
|
23
|
-
UpdateExpression: "SET #status = :status, updatedAt = :now",
|
|
24
|
-
ExpressionAttributeNames: { "#status": "status" },
|
|
25
|
-
ExpressionAttributeValues: {
|
|
26
|
-
":status": { S: "SUCCESS" },
|
|
27
|
-
":now": { S: new Date().toISOString() },
|
|
28
|
-
},
|
|
29
|
-
}));
|
|
30
|
-
}
|
|
31
|
-
catch (err) {
|
|
32
|
-
console.error(`Failed to update session for ${bucket}/${key}:`, err);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
};
|
package/dist/blob/types.d.ts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import type { IncomingMessage } from "node:http";
|
|
2
|
-
import z, { type ZodType } from "zod";
|
|
3
|
-
import type { KnownMimeType } from "./mime-types";
|
|
4
|
-
import type { UploadError } from "./upload-error";
|
|
5
|
-
type SuggestedSize = "1KB" | "100KB" | "1MB" | "10MB" | "100MB" | "1GB";
|
|
6
|
-
export type FileSizeUnit = "B" | "KB" | "MB" | "GB";
|
|
7
|
-
export type UnitAutocomplete<TUnit extends string> = `${number}${TUnit}`;
|
|
8
|
-
export type FileSize = SuggestedSize | UnitAutocomplete<FileSizeUnit> | number | (string & {});
|
|
9
|
-
export type StringWithAutocomplete<T extends string> = T | (string & {});
|
|
10
|
-
export type HandleUploadBody = PresignUploadBody | CallbackBody<any>;
|
|
11
|
-
export type HandleUploadResult = PresignUploadResponse;
|
|
12
|
-
export type PresignUploadBody = {
|
|
13
|
-
files: {
|
|
14
|
-
name: string;
|
|
15
|
-
size: number;
|
|
16
|
-
mimeType: string;
|
|
17
|
-
lastModified: number;
|
|
18
|
-
}[];
|
|
19
|
-
input?: Record<string, any>;
|
|
20
|
-
};
|
|
21
|
-
export type PresignUploadResponse = {
|
|
22
|
-
files: {
|
|
23
|
-
url: string;
|
|
24
|
-
key: string;
|
|
25
|
-
name: string;
|
|
26
|
-
}[];
|
|
27
|
-
sessionId: string;
|
|
28
|
-
};
|
|
29
|
-
export type CallbackBody<TMeta> = {
|
|
30
|
-
metadata: TMeta;
|
|
31
|
-
file: {
|
|
32
|
-
path: string;
|
|
33
|
-
contentDisposition: string;
|
|
34
|
-
contentType: string;
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
export type UploadFileBody = {
|
|
38
|
-
key: string;
|
|
39
|
-
name: string;
|
|
40
|
-
size: number;
|
|
41
|
-
mimeType: string;
|
|
42
|
-
disposition: string;
|
|
43
|
-
lastModified: number;
|
|
44
|
-
metadata?: Record<string, string>;
|
|
45
|
-
};
|
|
46
|
-
export type PathConfig = {
|
|
47
|
-
prefix?: string;
|
|
48
|
-
suffix?: string;
|
|
49
|
-
randomSuffix?: boolean;
|
|
50
|
-
};
|
|
51
|
-
export type PathContext<TMeta> = [TMeta] extends [never] ? {
|
|
52
|
-
/**
|
|
53
|
-
* File extension including the dot (e.g., .jpg, .png)
|
|
54
|
-
*/
|
|
55
|
-
ext: string;
|
|
56
|
-
/**
|
|
57
|
-
* File name without extension
|
|
58
|
-
*/
|
|
59
|
-
fileNameWithoutExt: string;
|
|
60
|
-
/**
|
|
61
|
-
* Original file name as uploaded by user
|
|
62
|
-
*/
|
|
63
|
-
fileNameWithExt: string;
|
|
64
|
-
} : {
|
|
65
|
-
/**
|
|
66
|
-
* File extension including the dot (e.g., .jpg, .png)
|
|
67
|
-
*/
|
|
68
|
-
ext: string;
|
|
69
|
-
/**
|
|
70
|
-
* File name without extension
|
|
71
|
-
*/
|
|
72
|
-
fileNameWithoutExt: string;
|
|
73
|
-
/**
|
|
74
|
-
* Original file name as uploaded by user
|
|
75
|
-
*/
|
|
76
|
-
fileNameWithExt: string;
|
|
77
|
-
/**
|
|
78
|
-
* Any metadata returned by middleware function
|
|
79
|
-
*/
|
|
80
|
-
metadata: TMeta;
|
|
81
|
-
};
|
|
82
|
-
export type PathGenerator<TMeta> = (ctx: PathContext<TMeta>) => string;
|
|
83
|
-
export type PathInput<TMeta> = PathConfig | PathGenerator<TMeta>;
|
|
84
|
-
export type TUploaderConfig<TInput extends ZodType = never, TMeta = never, TReturn = unknown> = {
|
|
85
|
-
path?: PathInput<TMeta>;
|
|
86
|
-
input?: TInput;
|
|
87
|
-
accept?: StringWithAutocomplete<KnownMimeType>[];
|
|
88
|
-
limits?: {
|
|
89
|
-
maxFileSize?: FileSize | ((ctx: {
|
|
90
|
-
metadata?: TMeta;
|
|
91
|
-
}) => FileSize);
|
|
92
|
-
maxFileCount?: number | ((ctx: {
|
|
93
|
-
metadata?: TMeta;
|
|
94
|
-
}) => number);
|
|
95
|
-
minFileCount?: number | ((ctx: {
|
|
96
|
-
metadata?: TMeta;
|
|
97
|
-
}) => number);
|
|
98
|
-
};
|
|
99
|
-
contentDisposition?: "inline" | "attachment";
|
|
100
|
-
onBeforeUpload: (opts: [TInput] extends [never] ? {
|
|
101
|
-
files: PresignUploadBody["files"];
|
|
102
|
-
req: Request | IncomingMessage;
|
|
103
|
-
} : {
|
|
104
|
-
files: PresignUploadBody["files"];
|
|
105
|
-
input: z.infer<TInput>;
|
|
106
|
-
req: Request | IncomingMessage;
|
|
107
|
-
}) => TMeta | Promise<TMeta>;
|
|
108
|
-
onUploadError?: (args: {
|
|
109
|
-
error: UploadError;
|
|
110
|
-
}) => void | Promise<void>;
|
|
111
|
-
onUploadComplete?: (args: {
|
|
112
|
-
metadata: TMeta;
|
|
113
|
-
file: {
|
|
114
|
-
path: string;
|
|
115
|
-
contentDisposition: string;
|
|
116
|
-
contentType: string;
|
|
117
|
-
};
|
|
118
|
-
}) => TReturn | Promise<TReturn>;
|
|
119
|
-
_def: {
|
|
120
|
-
meta: TMeta;
|
|
121
|
-
input: TInput;
|
|
122
|
-
output: TReturn;
|
|
123
|
-
};
|
|
124
|
-
};
|
|
125
|
-
export type TBucketConfig<TUploaderShape> = {
|
|
126
|
-
uploaders: TUploaderShape;
|
|
127
|
-
};
|
|
128
|
-
export {};
|
package/dist/blob/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import z, {} from "zod";
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export declare class UploadError extends Error {
|
|
2
|
-
readonly statusCode: number;
|
|
3
|
-
readonly code: string;
|
|
4
|
-
constructor(message: string, statusCode?: number, code?: string);
|
|
5
|
-
/**
|
|
6
|
-
* 400 Bad Request
|
|
7
|
-
* Use when the input is invalid (e.g. file too big, wrong extension)
|
|
8
|
-
*/
|
|
9
|
-
static badRequest(message?: string): UploadError;
|
|
10
|
-
/**
|
|
11
|
-
* 401 Unauthorized
|
|
12
|
-
* Use when the user is not logged in or missing headers
|
|
13
|
-
*/
|
|
14
|
-
static unauthorized(message?: string): UploadError;
|
|
15
|
-
/**
|
|
16
|
-
* 403 Forbidden
|
|
17
|
-
* Use when the user is logged in but doesn't have permission (e.g. wrong plan)
|
|
18
|
-
*/
|
|
19
|
-
static forbidden(message?: string): UploadError;
|
|
20
|
-
/**
|
|
21
|
-
* 404 Not Found
|
|
22
|
-
* Use when a resource required for the upload is missing
|
|
23
|
-
*/
|
|
24
|
-
static notFound(message?: string): UploadError;
|
|
25
|
-
/**
|
|
26
|
-
* 429 Too Many Requests
|
|
27
|
-
* Use for rate limiting logic
|
|
28
|
-
*/
|
|
29
|
-
static tooManyRequests(message?: string): UploadError;
|
|
30
|
-
/**
|
|
31
|
-
* 500 Internal Server Error
|
|
32
|
-
* Use for unexpected crashes or database failures
|
|
33
|
-
*/
|
|
34
|
-
static internal(message?: string): UploadError;
|
|
35
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
export class UploadError extends Error {
|
|
2
|
-
statusCode;
|
|
3
|
-
code;
|
|
4
|
-
constructor(message, statusCode = 500, code = "INTERNAL_SERVER_ERROR") {
|
|
5
|
-
super(message);
|
|
6
|
-
this.statusCode = statusCode;
|
|
7
|
-
this.code = code;
|
|
8
|
-
// Essential for 'instanceof' to work correctly when extending built-in classes in TypeScript
|
|
9
|
-
Object.setPrototypeOf(this, UploadError.prototype);
|
|
10
|
-
}
|
|
11
|
-
// --- Static Factory Helpers (The DX Magic) ---
|
|
12
|
-
/**
|
|
13
|
-
* 400 Bad Request
|
|
14
|
-
* Use when the input is invalid (e.g. file too big, wrong extension)
|
|
15
|
-
*/
|
|
16
|
-
static badRequest(message = "Bad Request") {
|
|
17
|
-
return new UploadError(message, 400, "BAD_REQUEST");
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* 401 Unauthorized
|
|
21
|
-
* Use when the user is not logged in or missing headers
|
|
22
|
-
*/
|
|
23
|
-
static unauthorized(message = "Unauthorized") {
|
|
24
|
-
return new UploadError(message, 401, "UNAUTHORIZED");
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* 403 Forbidden
|
|
28
|
-
* Use when the user is logged in but doesn't have permission (e.g. wrong plan)
|
|
29
|
-
*/
|
|
30
|
-
static forbidden(message = "Forbidden") {
|
|
31
|
-
return new UploadError(message, 403, "FORBIDDEN");
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* 404 Not Found
|
|
35
|
-
* Use when a resource required for the upload is missing
|
|
36
|
-
*/
|
|
37
|
-
static notFound(message = "Not Found") {
|
|
38
|
-
return new UploadError(message, 404, "NOT_FOUND");
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* 429 Too Many Requests
|
|
42
|
-
* Use for rate limiting logic
|
|
43
|
-
*/
|
|
44
|
-
static tooManyRequests(message = "Too many requests") {
|
|
45
|
-
return new UploadError(message, 429, "TOO_MANY_REQUESTS");
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* 500 Internal Server Error
|
|
49
|
-
* Use for unexpected crashes or database failures
|
|
50
|
-
*/
|
|
51
|
-
static internal(message = "Internal Server Error") {
|
|
52
|
-
return new UploadError(message, 500, "INTERNAL_SERVER_ERROR");
|
|
53
|
-
}
|
|
54
|
-
}
|
package/dist/blob/uploader.d.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import type { HandleUploadBody, PathConfig, PathGenerator, TUploaderConfig, UploadFileBody } from "./types";
|
|
2
|
-
import type { IncomingMessage } from "node:http";
|
|
3
|
-
import type { Bucket } from "./bucket";
|
|
4
|
-
export declare class Uploader<TMeta = unknown> {
|
|
5
|
-
private bucket;
|
|
6
|
-
private name;
|
|
7
|
-
private config;
|
|
8
|
-
private pathGenerator;
|
|
9
|
-
constructor(bucket: Bucket<any>, name: string, config: TUploaderConfig<any, TMeta>);
|
|
10
|
-
handleUpload({ action, body, request, sessionId, }: {
|
|
11
|
-
request: Request | IncomingMessage;
|
|
12
|
-
body: HandleUploadBody;
|
|
13
|
-
action: "presign" | "callback" | "poll";
|
|
14
|
-
sessionId?: string;
|
|
15
|
-
}): Promise<{
|
|
16
|
-
files: {
|
|
17
|
-
url: string;
|
|
18
|
-
key: string;
|
|
19
|
-
name: string;
|
|
20
|
-
}[];
|
|
21
|
-
sessionId: string;
|
|
22
|
-
} | {
|
|
23
|
-
files: {
|
|
24
|
-
fileKey: string;
|
|
25
|
-
status: "PENDING" | "SUCCESS" | "FAILED";
|
|
26
|
-
file: {
|
|
27
|
-
path: string;
|
|
28
|
-
contentDisposition: string;
|
|
29
|
-
contentType: string;
|
|
30
|
-
} | undefined;
|
|
31
|
-
metadata: TMeta;
|
|
32
|
-
}[];
|
|
33
|
-
completed: boolean;
|
|
34
|
-
type?: undefined;
|
|
35
|
-
response?: undefined;
|
|
36
|
-
error?: undefined;
|
|
37
|
-
} | {
|
|
38
|
-
type: "UPLOAD_COMPLETED";
|
|
39
|
-
response: "ok";
|
|
40
|
-
files?: undefined;
|
|
41
|
-
completed?: undefined;
|
|
42
|
-
error?: undefined;
|
|
43
|
-
} | {
|
|
44
|
-
error: {
|
|
45
|
-
message: string;
|
|
46
|
-
code: string;
|
|
47
|
-
status: number;
|
|
48
|
-
};
|
|
49
|
-
files?: undefined;
|
|
50
|
-
completed?: undefined;
|
|
51
|
-
type?: undefined;
|
|
52
|
-
response?: undefined;
|
|
53
|
-
}>;
|
|
54
|
-
private startPolling;
|
|
55
|
-
getProvider(): {
|
|
56
|
-
presign: (files: UploadFileBody[]) => Promise<{
|
|
57
|
-
files: {
|
|
58
|
-
url: string;
|
|
59
|
-
key: string;
|
|
60
|
-
name: string;
|
|
61
|
-
}[];
|
|
62
|
-
sessionId: string;
|
|
63
|
-
}>;
|
|
64
|
-
};
|
|
65
|
-
createConfigBasedGenerator(config: PathConfig): PathGenerator<any>;
|
|
66
|
-
private validateFiles;
|
|
67
|
-
}
|