@uplift-io/uplift 1.0.0 → 1.1.0
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 +21 -21
- package/README.md +102 -85
- package/dist/client.cjs +23 -2
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +23 -2
- package/dist/client.js.map +1 -1
- package/dist/index.cjs +32 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -7
- package/dist/index.d.ts +10 -7
- package/dist/index.js +32 -2
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +23 -2
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +23 -2
- package/dist/react.js.map +1 -1
- package/dist/server.cjs +75 -3
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +75 -3
- package/dist/server.js.map +1 -1
- package/dist/{types-BdcszAj8.d.cts → types-Cw4fuNs_.d.cts} +36 -2
- package/dist/{types-BdcszAj8.d.ts → types-Cw4fuNs_.d.ts} +36 -2
- package/package.json +1 -1
|
@@ -15,7 +15,13 @@ type UploadedFile = {
|
|
|
15
15
|
size: number;
|
|
16
16
|
extension?: string | undefined;
|
|
17
17
|
provider: string;
|
|
18
|
+
outputs?: Record<string, UploadedFile> | undefined;
|
|
18
19
|
};
|
|
20
|
+
type ClientUploadedFile<TOutputNames extends string = never> = UploadedFile & ([
|
|
21
|
+
TOutputNames
|
|
22
|
+
] extends [never] ? object : {
|
|
23
|
+
output<TName extends TOutputNames>(name: TName): UploadedFile;
|
|
24
|
+
});
|
|
19
25
|
type UploadErrorCode = "FILE_TOO_LARGE" | "FILE_TOO_SMALL" | "INVALID_TYPE" | "AUTH_FAILED" | "VALIDATION_FAILED" | "UPLOAD_FAILED" | "UNKNOWN";
|
|
20
26
|
declare class UploadError extends Error {
|
|
21
27
|
readonly code: UploadErrorCode;
|
|
@@ -53,11 +59,34 @@ type StoragePutInput = {
|
|
|
53
59
|
type StorageAdapter = {
|
|
54
60
|
provider: string;
|
|
55
61
|
put(input: StoragePutInput): Promise<UploadedFile>;
|
|
62
|
+
delete?(key: string): Promise<void>;
|
|
56
63
|
};
|
|
57
64
|
type Middleware<TUser = unknown> = (ctx: {
|
|
58
65
|
req: Request;
|
|
59
66
|
}) => TUser | Promise<TUser>;
|
|
60
67
|
type UploadKind = "any" | "image" | "pdf" | "video" | "audio" | "text" | "json" | "csv" | "custom";
|
|
68
|
+
type PreparedUploadFile = {
|
|
69
|
+
file: UploadInputFile;
|
|
70
|
+
body: File;
|
|
71
|
+
};
|
|
72
|
+
type TransformContext = PreparedUploadFile;
|
|
73
|
+
type UploadTransform<TKind extends UploadKind = UploadKind> = {
|
|
74
|
+
readonly __kind?: TKind | undefined;
|
|
75
|
+
transform(ctx: TransformContext): File | PreparedUploadFile | Promise<File | PreparedUploadFile>;
|
|
76
|
+
};
|
|
77
|
+
type UploadTransformFunction<TKind extends UploadKind = UploadKind> = ((ctx: TransformContext) => File | PreparedUploadFile | Promise<File | PreparedUploadFile>) & {
|
|
78
|
+
readonly __kind?: TKind | undefined;
|
|
79
|
+
};
|
|
80
|
+
type CompatibleTransform<TKind extends UploadKind> = TKind extends "any" | "custom" ? UploadTransform<UploadKind> | UploadTransformFunction<UploadKind> : UploadTransform<TKind> | UploadTransform<"any"> | UploadTransformFunction<TKind> | UploadTransformFunction<"any">;
|
|
81
|
+
type OutputContext = PreparedUploadFile & {
|
|
82
|
+
primary: UploadedFile;
|
|
83
|
+
};
|
|
84
|
+
type UploadOutput<TKind extends UploadKind = UploadKind, TName extends string = string> = {
|
|
85
|
+
readonly __kind?: TKind | undefined;
|
|
86
|
+
name: TName;
|
|
87
|
+
produce(ctx: OutputContext): File | PreparedUploadFile | Promise<File | PreparedUploadFile>;
|
|
88
|
+
};
|
|
89
|
+
type CompatibleOutput<TKind extends UploadKind, TName extends string = string> = TKind extends "any" | "custom" ? UploadOutput<UploadKind, TName> : UploadOutput<TKind, TName> | UploadOutput<"any", TName>;
|
|
61
90
|
type UploadRouteDefinition = {
|
|
62
91
|
kind: UploadKind;
|
|
63
92
|
maxBytes?: number;
|
|
@@ -102,6 +131,8 @@ type UploadRouteDefinition = {
|
|
|
102
131
|
min?: DurationValue;
|
|
103
132
|
max?: DurationValue;
|
|
104
133
|
};
|
|
134
|
+
transforms?: Array<UploadTransform | UploadTransformFunction>;
|
|
135
|
+
outputs?: Array<UploadOutput>;
|
|
105
136
|
};
|
|
106
137
|
type UploadRoutes = Record<string, {
|
|
107
138
|
_def: UploadRouteDefinition;
|
|
@@ -119,10 +150,13 @@ type UpliftApp<TRoutes extends UploadRoutes = UploadRoutes> = {
|
|
|
119
150
|
type IsMultiple<TRoute> = TRoute extends {
|
|
120
151
|
__multiple?: infer TMultiple;
|
|
121
152
|
} ? TMultiple extends true ? true : false : false;
|
|
153
|
+
type OutputNames<TRoute> = TRoute extends {
|
|
154
|
+
__outputs?: infer TOutputNames;
|
|
155
|
+
} ? TOutputNames extends string ? TOutputNames : never : never;
|
|
122
156
|
type ClientInput<TRoute> = IsMultiple<TRoute> extends true ? File[] | FileList : File;
|
|
123
|
-
type ClientOutput<TRoute> = IsMultiple<TRoute> extends true ?
|
|
157
|
+
type ClientOutput<TRoute> = IsMultiple<TRoute> extends true ? Array<ClientUploadedFile<OutputNames<TRoute>>> : ClientUploadedFile<OutputNames<TRoute>>;
|
|
124
158
|
type UploadClient<TApp extends UpliftApp> = {
|
|
125
159
|
[TRouteName in keyof TApp["routes"] & string]: (input: ClientInput<TApp["routes"][TRouteName]>) => Promise<ClientOutput<TApp["routes"][TRouteName]>>;
|
|
126
160
|
};
|
|
127
161
|
|
|
128
|
-
export { type
|
|
162
|
+
export { type CompatibleTransform as C, type DurationValue as D, type KeyContext as K, type Middleware as M, type OutputContext as O, type PreparedUploadFile as P, type SizeValue as S, type TransformContext as T, type UploadKind as U, type UploadRouteDefinition as a, type UploadInputFile as b, type DoneContext as c, type StandardSchema as d, type CompatibleOutput as e, type UploadRoutes as f, type StorageAdapter as g, type UpliftApp as h, type ClientInput as i, type ClientOutput as j, type ClientUploadedFile as k, type OutputNames as l, type StoragePutInput as m, type UploadClient as n, UploadError as o, type UploadErrorCode as p, type UploadOutput as q, type UploadTransform as r, type UploadTransformFunction as s, type UploadedFile as t };
|