@edgestore/shared 0.1.5-alpha.14 → 0.1.5-alpha.15
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/errors/EdgeStoreError.d.ts +47 -0
- package/dist/errors/EdgeStoreError.d.ts.map +1 -0
- package/dist/errors/index.d.ts +9 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +268 -0
- package/dist/index.mjs +262 -0
- package/dist/internals/bucketBuilder.d.ts +270 -0
- package/dist/internals/bucketBuilder.d.ts.map +1 -0
- package/dist/internals/createPathParamProxy.d.ts +21 -0
- package/dist/internals/createPathParamProxy.d.ts.map +1 -0
- package/dist/internals/providerTypes.d.ts +114 -0
- package/dist/internals/providerTypes.d.ts.map +1 -0
- package/dist/internals/sharedFuncTypes.d.ts +18 -0
- package/dist/internals/sharedFuncTypes.d.ts.map +1 -0
- package/dist/internals/types.d.ts +30 -0
- package/dist/internals/types.d.ts.map +1 -0
- package/dist/types.d.ts +94 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +11 -4
- package/src/errors/EdgeStoreError.ts +90 -0
- package/src/errors/index.ts +14 -0
- package/src/index.ts +6 -1
- package/src/internals/bucketBuilder.ts +553 -0
- package/src/internals/createPathParamProxy.ts +40 -0
- package/src/internals/providerTypes.ts +140 -0
- package/src/internals/sharedFuncTypes.ts +24 -0
- package/src/internals/types.ts +29 -0
- package/src/types.ts +148 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { type MaybePromise } from '../types';
|
|
2
|
+
import {
|
|
3
|
+
type AnyBuilder,
|
|
4
|
+
type AnyMetadata,
|
|
5
|
+
type EdgeStoreRouter,
|
|
6
|
+
} from './bucketBuilder';
|
|
7
|
+
|
|
8
|
+
export type InitParams = {
|
|
9
|
+
ctx: any;
|
|
10
|
+
router: EdgeStoreRouter<any>;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type InitRes = {
|
|
14
|
+
token?: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type GetFileParams = {
|
|
18
|
+
url: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type GetFileRes = {
|
|
22
|
+
url: string;
|
|
23
|
+
size: number;
|
|
24
|
+
uploadedAt: Date;
|
|
25
|
+
path: {
|
|
26
|
+
[key: string]: string;
|
|
27
|
+
};
|
|
28
|
+
metadata: {
|
|
29
|
+
[key: string]: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type RequestUploadParams = {
|
|
34
|
+
multipart?: {
|
|
35
|
+
uploadId?: string;
|
|
36
|
+
parts: number[];
|
|
37
|
+
};
|
|
38
|
+
bucketName: string;
|
|
39
|
+
bucketType: string;
|
|
40
|
+
fileInfo: {
|
|
41
|
+
size: number;
|
|
42
|
+
extension: string;
|
|
43
|
+
isPublic: boolean;
|
|
44
|
+
fileName?: string;
|
|
45
|
+
path: {
|
|
46
|
+
key: string;
|
|
47
|
+
value: string;
|
|
48
|
+
}[];
|
|
49
|
+
metadata: AnyMetadata;
|
|
50
|
+
replaceTargetUrl?: string;
|
|
51
|
+
temporary: boolean;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export type RequestUploadPartsParams = {
|
|
56
|
+
multipart: {
|
|
57
|
+
uploadId: string;
|
|
58
|
+
parts: number[];
|
|
59
|
+
};
|
|
60
|
+
path: string;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type RequestUploadPartsRes = {
|
|
64
|
+
multipart: {
|
|
65
|
+
uploadId: string;
|
|
66
|
+
parts: {
|
|
67
|
+
partNumber: number;
|
|
68
|
+
uploadUrl: string;
|
|
69
|
+
}[];
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export type CompleteMultipartUploadParams = {
|
|
74
|
+
uploadId: string;
|
|
75
|
+
key: string;
|
|
76
|
+
parts: {
|
|
77
|
+
partNumber: number;
|
|
78
|
+
eTag: string;
|
|
79
|
+
}[];
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export type CompleteMultipartUploadRes = {
|
|
83
|
+
success: boolean;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export type RequestUploadRes =
|
|
87
|
+
| {
|
|
88
|
+
uploadUrl: string;
|
|
89
|
+
accessUrl: string;
|
|
90
|
+
thumbnailUrl?: string | null;
|
|
91
|
+
}
|
|
92
|
+
| {
|
|
93
|
+
multipart: {
|
|
94
|
+
key: string;
|
|
95
|
+
uploadId: string;
|
|
96
|
+
partSize: number;
|
|
97
|
+
totalParts: number;
|
|
98
|
+
parts: {
|
|
99
|
+
partNumber: number;
|
|
100
|
+
uploadUrl: string;
|
|
101
|
+
}[];
|
|
102
|
+
};
|
|
103
|
+
accessUrl: string;
|
|
104
|
+
thumbnailUrl?: string | null;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export type ConfirmUpload = {
|
|
108
|
+
bucket: AnyBuilder;
|
|
109
|
+
url: string;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export type ConfirmUploadRes = {
|
|
113
|
+
success: boolean;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export type DeleteFileParams = {
|
|
117
|
+
bucket: AnyBuilder;
|
|
118
|
+
url: string;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export type DeleteFileRes = {
|
|
122
|
+
success: boolean;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export type Provider = {
|
|
126
|
+
init: (params: InitParams) => MaybePromise<InitRes>;
|
|
127
|
+
getBaseUrl: () => MaybePromise<string>;
|
|
128
|
+
getFile: (params: GetFileParams) => MaybePromise<GetFileRes>;
|
|
129
|
+
requestUpload: (
|
|
130
|
+
params: RequestUploadParams,
|
|
131
|
+
) => MaybePromise<RequestUploadRes>;
|
|
132
|
+
requestUploadParts: (
|
|
133
|
+
params: RequestUploadPartsParams,
|
|
134
|
+
) => MaybePromise<RequestUploadPartsRes>;
|
|
135
|
+
completeMultipartUpload: (
|
|
136
|
+
params: CompleteMultipartUploadParams,
|
|
137
|
+
) => MaybePromise<CompleteMultipartUploadRes>;
|
|
138
|
+
confirmUpload: (params: ConfirmUpload) => MaybePromise<ConfirmUploadRes>;
|
|
139
|
+
deleteFile: (params: DeleteFileParams) => MaybePromise<DeleteFileRes>;
|
|
140
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Simplify } from '../types';
|
|
2
|
+
import { type AnyMetadata } from './bucketBuilder';
|
|
3
|
+
import {
|
|
4
|
+
type DeleteFileRes,
|
|
5
|
+
type RequestUploadPartsRes,
|
|
6
|
+
type RequestUploadRes,
|
|
7
|
+
} from './providerTypes';
|
|
8
|
+
|
|
9
|
+
export type SharedInitRes = {
|
|
10
|
+
newCookies: string[];
|
|
11
|
+
token: string | undefined;
|
|
12
|
+
baseUrl: string;
|
|
13
|
+
};
|
|
14
|
+
export type SharedRequestUploadRes = Simplify<
|
|
15
|
+
RequestUploadRes & {
|
|
16
|
+
size: number;
|
|
17
|
+
uploadedAt: string;
|
|
18
|
+
path: Record<string, string>;
|
|
19
|
+
pathOrder: string[];
|
|
20
|
+
metadata: AnyMetadata;
|
|
21
|
+
}
|
|
22
|
+
>;
|
|
23
|
+
export type SharedRequestUploadPartsRes = RequestUploadPartsRes;
|
|
24
|
+
export type SharedDeleteFileRes = DeleteFileRes;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type UploadOptions = {
|
|
2
|
+
/**
|
|
3
|
+
* e.g. 'my-file-name.jpg'
|
|
4
|
+
*
|
|
5
|
+
* By default, a unique file name will be generated for each upload.
|
|
6
|
+
* If you want to use a custom file name, you can use this option.
|
|
7
|
+
* If you use the same file name for multiple uploads, the previous file will be overwritten.
|
|
8
|
+
* But it might take some time for the CDN cache to be cleared.
|
|
9
|
+
* So maybe you will keep seeing the old file for a while.
|
|
10
|
+
*
|
|
11
|
+
* If you want to replace an existing file immediately leave the `manualFileName` option empty and use the `replaceTargetUrl` option.
|
|
12
|
+
*/
|
|
13
|
+
manualFileName?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Use this to replace an existing file.
|
|
16
|
+
* It will automatically delete the existing file when the upload is complete.
|
|
17
|
+
*/
|
|
18
|
+
replaceTargetUrl?: string;
|
|
19
|
+
/**
|
|
20
|
+
* If true, the file needs to be confirmed by using the `confirmUpload` function.
|
|
21
|
+
* If the file is not confirmed within 24 hours, it will be deleted.
|
|
22
|
+
*
|
|
23
|
+
* This is useful for pages where the file is uploaded as soon as it is selected,
|
|
24
|
+
* but the user can leave the page without submitting the form.
|
|
25
|
+
*
|
|
26
|
+
* This avoids unnecessary zombie files in the bucket.
|
|
27
|
+
*/
|
|
28
|
+
temporary?: boolean;
|
|
29
|
+
};
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
*/
|
|
4
|
+
export type identity<TType> = TType;
|
|
5
|
+
|
|
6
|
+
export type InferOptional<TType, TKeys extends keyof TType> = Omit<
|
|
7
|
+
TType,
|
|
8
|
+
TKeys
|
|
9
|
+
> &
|
|
10
|
+
Partial<Pick<TType, TKeys>>;
|
|
11
|
+
|
|
12
|
+
export type UndefinedKeys<TType> = {
|
|
13
|
+
[K in keyof TType]: undefined extends TType[K] ? K : never;
|
|
14
|
+
}[keyof TType];
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export type FlatOverwrite<TType, TWith> = InferOptional<
|
|
20
|
+
{
|
|
21
|
+
[TKey in keyof TType | keyof TWith]: TKey extends keyof TWith
|
|
22
|
+
? TWith[TKey]
|
|
23
|
+
: TKey extends keyof TType
|
|
24
|
+
? TType[TKey]
|
|
25
|
+
: never;
|
|
26
|
+
},
|
|
27
|
+
UndefinedKeys<TType> | UndefinedKeys<TWith>
|
|
28
|
+
>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
export type IntersectionError<TKey extends string> =
|
|
34
|
+
`The property '${TKey}' in your router collides with a built-in method, rename this router or procedure on your backend.`;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
export type ProtectedIntersection<TType, TWith> = keyof TType &
|
|
40
|
+
keyof TWith extends never
|
|
41
|
+
? TType & TWith
|
|
42
|
+
: IntersectionError<string & keyof TType & keyof TWith>;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
export type Maybe<TType> = TType | null | undefined;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
export type ThenArg<TType> = TType extends PromiseLike<infer U>
|
|
53
|
+
? ThenArg<U>
|
|
54
|
+
: TType;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @internal
|
|
58
|
+
* @see https://github.com/ianstormtaylor/superstruct/blob/7973400cd04d8ad92bbdc2b6f35acbfb3c934079/src/utils.ts#L323-L325
|
|
59
|
+
*/
|
|
60
|
+
export type Simplify<TType> = TType extends any[] | Date
|
|
61
|
+
? TType
|
|
62
|
+
: { [K in keyof TType]: TType[K] };
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
export type Prettify<TType> = {
|
|
68
|
+
[K in keyof TType]: TType[K];
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
70
|
+
} & {};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
export type Dict<TType> = Record<string, TType | undefined>;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @public
|
|
79
|
+
*/
|
|
80
|
+
export type MaybePromise<TType> = Promise<TType> | TType;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @internal
|
|
84
|
+
*
|
|
85
|
+
* Creates a "lower-priority" type inference.
|
|
86
|
+
* https://github.com/microsoft/TypeScript/issues/14829#issuecomment-322267089
|
|
87
|
+
*/
|
|
88
|
+
export type InferLast<TType> = TType & {
|
|
89
|
+
[KeyType in keyof TType]: TType[KeyType];
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @public
|
|
94
|
+
*/
|
|
95
|
+
export type inferAsyncReturnType<TFunction extends (...args: any) => any> =
|
|
96
|
+
ThenArg<ReturnType<TFunction>>;
|
|
97
|
+
|
|
98
|
+
export type FilterKeys<TObj extends object, TFilter> = {
|
|
99
|
+
[TKey in keyof TObj]: TObj[TKey] extends TFilter ? TKey : never;
|
|
100
|
+
}[keyof TObj];
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @internal
|
|
104
|
+
*/
|
|
105
|
+
export type Filter<TObj extends object, TFilter> = Pick<
|
|
106
|
+
TObj,
|
|
107
|
+
FilterKeys<TObj, TFilter>
|
|
108
|
+
>;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Unwrap return type if the type is a function (sync or async), else use the type as is
|
|
112
|
+
* @internal
|
|
113
|
+
*/
|
|
114
|
+
export type Unwrap<TType> = TType extends (...args: any[]) => infer R
|
|
115
|
+
? ThenArg<R>
|
|
116
|
+
: TType;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Makes the object recursively optional.
|
|
120
|
+
* @internal
|
|
121
|
+
*/
|
|
122
|
+
export type DeepPartial<TObject> = TObject extends object
|
|
123
|
+
? {
|
|
124
|
+
[P in keyof TObject]?: DeepPartial<TObject[P]>;
|
|
125
|
+
}
|
|
126
|
+
: TObject;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Get the keys of a union type.
|
|
130
|
+
* @internal
|
|
131
|
+
*/
|
|
132
|
+
export type KeysOfUnion<TUnion> = TUnion extends TUnion
|
|
133
|
+
? keyof TUnion extends string
|
|
134
|
+
? keyof TUnion
|
|
135
|
+
: string
|
|
136
|
+
: never;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Unify a union of objects into a single object.
|
|
140
|
+
* @internal
|
|
141
|
+
*/
|
|
142
|
+
export type UnifyUnion<TUnion> = Simplify<
|
|
143
|
+
(TUnion extends any ? (k: TUnion) => void : never) extends (
|
|
144
|
+
k: infer I,
|
|
145
|
+
) => void
|
|
146
|
+
? I
|
|
147
|
+
: never
|
|
148
|
+
>;
|