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.
Files changed (271) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +2 -0
  3. package/README.md +98 -0
  4. package/dist/binding/binding.d.ts +22 -0
  5. package/dist/binding/binding.js +60 -0
  6. package/dist/binding/unprovisioned.d.ts +17 -0
  7. package/dist/binding/unprovisioned.js +25 -0
  8. package/dist/bucket/bucket-client.d.ts +4 -0
  9. package/dist/bucket/bucket-client.js +5 -0
  10. package/dist/bucket/bucket-context.d.ts +8 -0
  11. package/dist/bucket/bucket-context.js +10 -0
  12. package/dist/bucket/bucket.d.ts +60 -0
  13. package/dist/bucket/bucket.js +91 -0
  14. package/dist/bucket/client.d.ts +49 -0
  15. package/dist/bucket/client.js +95 -0
  16. package/dist/bucket/errors.d.ts +12 -0
  17. package/dist/bucket/errors.js +20 -0
  18. package/dist/bucket/express.d.ts +10 -0
  19. package/dist/bucket/express.js +24 -0
  20. package/dist/bucket/hono.d.ts +18 -0
  21. package/dist/bucket/hono.js +13 -0
  22. package/dist/bucket/index.d.ts +8 -0
  23. package/dist/bucket/index.js +6 -0
  24. package/dist/bucket/keys.d.ts +5 -0
  25. package/dist/bucket/keys.js +24 -0
  26. package/dist/bucket/metadata.d.ts +6 -0
  27. package/dist/bucket/metadata.js +6 -0
  28. package/dist/bucket/next.d.ts +15 -0
  29. package/dist/bucket/next.js +11 -0
  30. package/dist/bucket/objects.d.ts +130 -0
  31. package/dist/bucket/objects.js +350 -0
  32. package/dist/bucket/route.d.ts +13 -0
  33. package/dist/bucket/route.js +247 -0
  34. package/dist/bucket/server-only.js +5 -0
  35. package/dist/bucket/types.d.ts +63 -0
  36. package/dist/bucket/uploader.d.ts +3 -0
  37. package/dist/bucket/uploader.js +6 -0
  38. package/dist/build-env.d.ts +17 -0
  39. package/dist/build-env.js +41 -0
  40. package/dist/config.d.ts +30 -0
  41. package/dist/config.js +9 -0
  42. package/dist/declaration/callsite.d.ts +15 -0
  43. package/dist/declaration/callsite.js +43 -0
  44. package/dist/declaration/component.d.ts +4 -0
  45. package/dist/declaration/component.js +1 -0
  46. package/dist/declaration/defer.d.ts +5 -0
  47. package/dist/declaration/defer.js +9 -0
  48. package/dist/delivery/duration.d.ts +13 -0
  49. package/dist/delivery/duration.js +36 -0
  50. package/dist/delivery/lane.d.ts +4 -0
  51. package/dist/delivery/lane.js +15 -0
  52. package/dist/delivery/payload.d.ts +6 -0
  53. package/dist/delivery/payload.js +14 -0
  54. package/dist/delivery/retry.d.ts +16 -0
  55. package/dist/delivery/retry.js +10 -0
  56. package/dist/delivery/schema.d.ts +10 -0
  57. package/dist/delivery/schema.js +20 -0
  58. package/dist/dns.d.ts +11 -0
  59. package/dist/dns.js +4 -0
  60. package/dist/edge.d.ts +4 -0
  61. package/dist/edge.js +4 -0
  62. package/dist/env/access.d.ts +22 -0
  63. package/dist/env/access.js +49 -0
  64. package/dist/env/client.d.ts +5 -0
  65. package/dist/env/client.js +10 -0
  66. package/dist/env/declare.d.ts +2 -0
  67. package/dist/env/declare.js +83 -0
  68. package/dist/env/definition.d.ts +46 -0
  69. package/dist/env/definition.js +164 -0
  70. package/dist/env/deployment.d.ts +23 -0
  71. package/dist/env/deployment.js +13 -0
  72. package/dist/env/edge.d.ts +10 -0
  73. package/dist/env/edge.js +30 -0
  74. package/dist/env/errors.d.ts +9 -0
  75. package/dist/env/errors.js +9 -0
  76. package/dist/env/file.d.ts +1 -0
  77. package/dist/env/file.js +27 -0
  78. package/dist/env/index.d.ts +10 -0
  79. package/dist/env/index.js +63 -0
  80. package/dist/env/live.d.ts +3 -0
  81. package/dist/env/live.js +12 -0
  82. package/dist/env/schema.d.ts +27 -0
  83. package/dist/env/schema.js +43 -0
  84. package/dist/env/scope.d.ts +7 -0
  85. package/dist/env/scope.js +45 -0
  86. package/dist/env/standard.d.ts +10 -0
  87. package/dist/env/standard.js +21 -0
  88. package/dist/env/value.d.ts +5 -0
  89. package/dist/env/value.js +26 -0
  90. package/dist/env-source.d.ts +17 -0
  91. package/dist/env-source.js +16 -0
  92. package/dist/gen/proto/app/bucket/v1/bucket_pb.d.ts +911 -0
  93. package/dist/gen/proto/app/bucket/v1/bucket_pb.js +253 -0
  94. package/dist/gen/proto/app/realtime/v1/realtime_pb.d.ts +50 -0
  95. package/dist/gen/proto/app/realtime/v1/realtime_pb.js +23 -0
  96. package/dist/gen/proto/app/resources/v1/resources_pb.d.ts +554 -0
  97. package/dist/gen/proto/app/resources/v1/resources_pb.js +214 -0
  98. package/dist/gen/proto/app/resources/v1/variables_pb.d.ts +231 -0
  99. package/dist/gen/proto/app/resources/v1/variables_pb.js +101 -0
  100. package/dist/gen/proto/app/task/v1/task_pb.d.ts +498 -0
  101. package/dist/gen/proto/app/task/v1/task_pb.js +151 -0
  102. package/dist/gen/proto/app/topic/v1/topic_pb.d.ts +456 -0
  103. package/dist/gen/proto/app/topic/v1/topic_pb.js +125 -0
  104. package/dist/gen/proto/buf/validate/validate_pb.d.ts +4833 -0
  105. package/dist/gen/proto/buf/validate/validate_pb.js +356 -0
  106. package/dist/gen/proto/common/bindings/v1/bindings_pb.d.ts +378 -0
  107. package/dist/gen/proto/common/bindings/v1/bindings_pb.js +140 -0
  108. package/dist/generated/config.d.ts +428 -0
  109. package/dist/generated/config.js +2 -0
  110. package/dist/kv/entries.d.ts +193 -0
  111. package/dist/kv/entries.js +325 -0
  112. package/dist/kv/errors.d.ts +12 -0
  113. package/dist/kv/errors.js +14 -0
  114. package/dist/kv/index.d.ts +6 -0
  115. package/dist/kv/index.js +3 -0
  116. package/dist/kv/ioredis.d.ts +2 -0
  117. package/dist/kv/ioredis.js +20 -0
  118. package/dist/kv/kv.d.ts +84 -0
  119. package/dist/kv/kv.js +177 -0
  120. package/dist/kv/pattern.d.ts +27 -0
  121. package/dist/kv/pattern.js +73 -0
  122. package/dist/kv/ttl.d.ts +22 -0
  123. package/dist/kv/ttl.js +21 -0
  124. package/dist/postgres/index.d.ts +21 -2
  125. package/dist/postgres/index.js +73 -2
  126. package/dist/postgres/pg.d.ts +5 -4
  127. package/dist/postgres/pg.js +16 -12
  128. package/dist/providers/aws/dns.d.ts +11 -0
  129. package/dist/providers/aws/dns.js +4 -0
  130. package/dist/providers/aws/edge.d.ts +6 -0
  131. package/dist/providers/aws/edge.js +8 -0
  132. package/dist/providers/aws/index.d.ts +4 -0
  133. package/dist/providers/aws/index.js +4 -0
  134. package/dist/providers/gcp/edge.d.ts +14 -0
  135. package/dist/providers/gcp/edge.js +14 -0
  136. package/dist/providers/gcp/index.d.ts +9 -0
  137. package/dist/providers/gcp/index.js +9 -0
  138. package/dist/providers/vps/index.d.ts +4 -0
  139. package/dist/providers/vps/index.js +4 -0
  140. package/dist/realtime/client-error.d.ts +30 -0
  141. package/dist/realtime/client-error.js +17 -0
  142. package/dist/realtime/client-event-socket.d.ts +8 -0
  143. package/dist/realtime/client-event-socket.js +169 -0
  144. package/dist/realtime/client-transport.d.ts +29 -0
  145. package/dist/realtime/client-transport.js +13 -0
  146. package/dist/realtime/client.d.ts +150 -0
  147. package/dist/realtime/client.js +345 -0
  148. package/dist/realtime/express.d.ts +18 -0
  149. package/dist/realtime/express.js +83 -0
  150. package/dist/realtime/handler.d.ts +56 -0
  151. package/dist/realtime/handler.js +287 -0
  152. package/dist/realtime/hono.d.ts +19 -0
  153. package/dist/realtime/hono.js +24 -0
  154. package/dist/realtime/index.d.ts +2 -0
  155. package/dist/realtime/index.js +2 -0
  156. package/dist/realtime/next.d.ts +26 -0
  157. package/dist/realtime/next.js +16 -0
  158. package/dist/realtime/realtime.d.ts +181 -0
  159. package/dist/realtime/realtime.js +205 -0
  160. package/dist/realtime/token.d.ts +20 -0
  161. package/dist/realtime/token.js +45 -0
  162. package/dist/realtime/transport.d.ts +11 -0
  163. package/dist/realtime/transport.js +15 -0
  164. package/dist/realtime/wire.d.ts +30 -0
  165. package/dist/realtime/wire.js +104 -0
  166. package/dist/runtime/dev-server.d.ts +8 -0
  167. package/dist/runtime/dev-server.js +8 -0
  168. package/dist/runtime/rpc.d.ts +23 -0
  169. package/dist/runtime/rpc.js +24 -0
  170. package/dist/runtime/transport.d.ts +11 -0
  171. package/dist/runtime/transport.js +35 -0
  172. package/dist/task/errors.d.ts +7 -0
  173. package/dist/task/errors.js +7 -0
  174. package/dist/task/hooks.d.ts +57 -0
  175. package/dist/task/hooks.js +1 -0
  176. package/dist/task/index.d.ts +9 -0
  177. package/dist/task/index.js +4 -0
  178. package/dist/task/runs.d.ts +74 -0
  179. package/dist/task/runs.js +82 -0
  180. package/dist/task/task.d.ts +117 -0
  181. package/dist/task/task.js +109 -0
  182. package/dist/topic/dead-letters.d.ts +53 -0
  183. package/dist/topic/dead-letters.js +62 -0
  184. package/dist/topic/index.d.ts +8 -0
  185. package/dist/topic/index.js +4 -0
  186. package/dist/topic/topic.d.ts +85 -0
  187. package/dist/topic/topic.js +117 -0
  188. package/dist/version.d.ts +2 -0
  189. package/dist/version.js +2 -0
  190. package/dist/worker/context.d.ts +36 -0
  191. package/dist/worker/context.js +1 -0
  192. package/dist/worker/deliver.d.ts +13 -0
  193. package/dist/worker/deliver.js +258 -0
  194. package/dist/worker/index.d.ts +4 -0
  195. package/dist/worker/index.js +2 -0
  196. package/dist/worker/registry.d.ts +28 -0
  197. package/dist/worker/registry.js +22 -0
  198. package/dist/worker/semaphore.d.ts +7 -0
  199. package/dist/worker/semaphore.js +36 -0
  200. package/dist/worker/worker.d.ts +21 -0
  201. package/dist/worker/worker.js +32 -0
  202. package/package.json +158 -57
  203. package/bin/run.js +0 -39
  204. package/dist/blob/bucket.d.ts +0 -55
  205. package/dist/blob/bucket.js +0 -65
  206. package/dist/blob/index.d.ts +0 -8
  207. package/dist/blob/index.js +0 -13
  208. package/dist/blob/integrations/client.d.ts +0 -25
  209. package/dist/blob/integrations/client.js +0 -71
  210. package/dist/blob/integrations/hono.d.ts +0 -31
  211. package/dist/blob/integrations/hono.js +0 -11
  212. package/dist/blob/mime-types.d.ts +0 -1
  213. package/dist/blob/parse.d.ts +0 -16
  214. package/dist/blob/parse.js +0 -69
  215. package/dist/blob/s3-listener.d.ts +0 -7
  216. package/dist/blob/s3-listener.js +0 -35
  217. package/dist/blob/types.d.ts +0 -128
  218. package/dist/blob/types.js +0 -1
  219. package/dist/blob/upload-error.d.ts +0 -35
  220. package/dist/blob/upload-error.js +0 -54
  221. package/dist/blob/uploader.d.ts +0 -67
  222. package/dist/blob/uploader.js +0 -323
  223. package/dist/internal/db/index.d.ts +0 -68
  224. package/dist/internal/db/index.js +0 -73
  225. package/dist/lambda/index.d.ts +0 -2
  226. package/dist/lambda/index.js +0 -4
  227. package/dist/lambda/integrations/express.d.ts +0 -3
  228. package/dist/lambda/integrations/express.js +0 -13
  229. package/dist/lambda/integrations/hono.d.ts +0 -3
  230. package/dist/lambda/integrations/hono.js +0 -13
  231. package/dist/lambda/lambda.d.ts +0 -43
  232. package/dist/lambda/lambda.js +0 -30
  233. package/dist/utils/component.d.ts +0 -3
  234. package/dist/utils/constants.d.ts +0 -2
  235. package/dist/utils/constants.js +0 -2
  236. package/dist/utils/nanoid.d.ts +0 -1
  237. package/dist/utils/nanoid.js +0 -6
  238. package/dist/utils/rpc.d.ts +0 -11
  239. package/dist/utils/rpc.js +0 -17
  240. package/dist/utils/stack.d.ts +0 -4
  241. package/dist/utils/stack.js +0 -23
  242. package/dist/workflow/index.d.ts +0 -3
  243. package/dist/workflow/index.js +0 -4
  244. package/dist/workflow/workflow.d.ts +0 -34
  245. package/dist/workflow/workflow.js +0 -146
  246. package/src/blob/bucket.ts +0 -92
  247. package/src/blob/index.ts +0 -34
  248. package/src/blob/integrations/client.ts +0 -127
  249. package/src/blob/integrations/hono.ts +0 -16
  250. package/src/blob/mime-types.ts +0 -68
  251. package/src/blob/parse.ts +0 -93
  252. package/src/blob/s3-listener.ts +0 -48
  253. package/src/blob/types.ts +0 -142
  254. package/src/blob/upload-error.ts +0 -67
  255. package/src/blob/uploader.ts +0 -426
  256. package/src/internal/db/index.ts +0 -78
  257. package/src/lambda/index.ts +0 -8
  258. package/src/lambda/integrations/express.ts +0 -25
  259. package/src/lambda/integrations/hono.ts +0 -25
  260. package/src/lambda/lambda.ts +0 -94
  261. package/src/postgres/index.ts +0 -5
  262. package/src/postgres/pg.ts +0 -33
  263. package/src/utils/component.ts +0 -3
  264. package/src/utils/constants.ts +0 -2
  265. package/src/utils/nanoid.ts +0 -9
  266. package/src/utils/rpc.ts +0 -28
  267. package/src/utils/stack.ts +0 -26
  268. package/src/workflow/index.ts +0 -9
  269. package/src/workflow/workflow.ts +0 -235
  270. /package/dist/{blob/mime-types.js → bucket/server-only.d.ts} +0 -0
  271. /package/dist/{utils/component.js → bucket/types.js} +0 -0
@@ -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;
@@ -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
- };
@@ -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 {};
@@ -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
- }
@@ -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
- }