@edgestore/react 0.0.0-alpha.12 → 0.0.0-alpha.13
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/createNextProxy.d.ts +31 -5
- package/dist/createNextProxy.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.mjs +4 -2
- package/package.json +5 -5
- package/src/contextProvider.tsx +3 -2
- package/src/createNextProxy.ts +47 -14
|
@@ -3,22 +3,30 @@ import { AnyRouter, InferBucketPathKeys, InferMetadataObject } from '@edgestore/
|
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
export type BucketFunctions<TRouter extends AnyRouter> = {
|
|
5
5
|
[K in keyof TRouter['buckets']]: {
|
|
6
|
-
upload: (params: z.infer<TRouter['buckets'][K]['_def']['input']> extends
|
|
6
|
+
upload: (params: z.infer<TRouter['buckets'][K]['_def']['input']> extends never ? {
|
|
7
7
|
file: File;
|
|
8
|
-
input: z.infer<TRouter['buckets'][K]['_def']['input']>;
|
|
9
8
|
onProgressChange?: OnProgressChangeHandler;
|
|
10
9
|
options?: UploadOptions;
|
|
11
10
|
} : {
|
|
12
11
|
file: File;
|
|
12
|
+
input: z.infer<TRouter['buckets'][K]['_def']['input']>;
|
|
13
13
|
onProgressChange?: OnProgressChangeHandler;
|
|
14
14
|
options?: UploadOptions;
|
|
15
|
-
}) => Promise<{
|
|
15
|
+
}) => Promise<TRouter['buckets'][K]['_def']['type'] extends 'IMAGE' ? {
|
|
16
|
+
url: string;
|
|
17
|
+
thumbnailUrl: string | null;
|
|
18
|
+
size: number;
|
|
19
|
+
uploadedAt: Date;
|
|
20
|
+
metadata: InferMetadataObject<TRouter['buckets'][K]>;
|
|
21
|
+
path: InferBucketPathKeys<TRouter['buckets'][K]> extends never ? Record<string, never> : {
|
|
22
|
+
[TKey in InferBucketPathKeys<TRouter['buckets'][K]>]: string;
|
|
23
|
+
};
|
|
24
|
+
} : {
|
|
16
25
|
url: string;
|
|
17
|
-
thumbnailUrl: TRouter['buckets'][K]['_def']['type'] extends 'IMAGE' ? string | null : never;
|
|
18
26
|
size: number;
|
|
19
27
|
uploadedAt: Date;
|
|
20
28
|
metadata: InferMetadataObject<TRouter['buckets'][K]>;
|
|
21
|
-
path: {
|
|
29
|
+
path: InferBucketPathKeys<TRouter['buckets'][K]> extends never ? Record<string, never> : {
|
|
22
30
|
[TKey in InferBucketPathKeys<TRouter['buckets'][K]>]: string;
|
|
23
31
|
};
|
|
24
32
|
}>;
|
|
@@ -31,6 +39,24 @@ export type BucketFunctions<TRouter extends AnyRouter> = {
|
|
|
31
39
|
};
|
|
32
40
|
type OnProgressChangeHandler = (progress: number) => void;
|
|
33
41
|
type UploadOptions = {
|
|
42
|
+
/**
|
|
43
|
+
* e.g. 'my-file-name.jpg'
|
|
44
|
+
*
|
|
45
|
+
* * Not Recommended *
|
|
46
|
+
*
|
|
47
|
+
* By default, a unique file name will be generated for each upload.
|
|
48
|
+
* If you want to use a custom file name, you can use this option.
|
|
49
|
+
* If you use the same file name for multiple uploads, the previous file will be overwritten.
|
|
50
|
+
* But it will take some time for the cache to be cleared.
|
|
51
|
+
* So you will keep seeing the old file for a while.
|
|
52
|
+
*
|
|
53
|
+
* If you want to replace an existing file immediately leave the `manualFileName` option empty and use the `replaceTargetUrl` option.
|
|
54
|
+
*/
|
|
55
|
+
manualFileName?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Use this to replace an existing file.
|
|
58
|
+
* It will automatically delete the existing file when the upload is complete.
|
|
59
|
+
*/
|
|
34
60
|
replaceTargetUrl?: string;
|
|
35
61
|
};
|
|
36
62
|
export declare function createNextProxy<TRouter extends AnyRouter>({ apiPath, uploadingCountRef, maxConcurrentUploads, }: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createNextProxy.d.ts","sourceRoot":"","sources":["../src/createNextProxy.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,mBAAmB,EACpB,M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;;;OAYG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,wBAAgB,eAAe,CAAC,OAAO,SAAS,SAAS,EAAE,EACzD,OAAO,EACP,iBAAiB,EACjB,oBAAwB,GACzB,EAAE;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,KAAK,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAClD,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B,4BAiCA"}
|
package/dist/index.js
CHANGED
|
@@ -74,6 +74,7 @@ async function uploadFile({ file, input, onProgressChange, options }, { apiPath,
|
|
|
74
74
|
extension: file.name.split('.').pop(),
|
|
75
75
|
type: file.type,
|
|
76
76
|
size: file.size,
|
|
77
|
+
fileName: options?.manualFileName,
|
|
77
78
|
replaceTargetUrl: options?.replaceTargetUrl
|
|
78
79
|
}
|
|
79
80
|
}),
|
|
@@ -146,7 +147,7 @@ async function deleteFile({ url }, { apiPath, bucketName }) {
|
|
|
146
147
|
};
|
|
147
148
|
}
|
|
148
149
|
|
|
149
|
-
const DEFAULT_BASE_URL = process.env.NEXT_PUBLIC_EDGE_STORE_BASE_URL ?? 'https://files.
|
|
150
|
+
const DEFAULT_BASE_URL = process.env.NEXT_PUBLIC_EDGE_STORE_BASE_URL ?? 'https://files.edgestore.dev';
|
|
150
151
|
function createEdgeStoreProvider(opts) {
|
|
151
152
|
const EdgeStoreContext = /*#__PURE__*/ React__namespace.createContext(undefined);
|
|
152
153
|
const EdgeStoreProvider = ({ // TODO: Add basePath when custom domain is supported
|
|
@@ -193,11 +194,12 @@ function EdgeStoreProviderInner({ children, context, basePath, maxConcurrentUplo
|
|
|
193
194
|
});
|
|
194
195
|
}
|
|
195
196
|
});
|
|
197
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
196
198
|
}, []);
|
|
197
199
|
function getSrc(url) {
|
|
198
200
|
if (// in production we use cookies, so we don't need a token
|
|
199
201
|
process.env.NODE_ENV === 'production' || // public urls don't need a token
|
|
200
|
-
// e.g. https://files.
|
|
202
|
+
// e.g. https://files.edgestore.dev/project/bucket/_public/...
|
|
201
203
|
url.match(/^https?:\/\/[^\/]+\/[^\/]+\/[^\/]+\/_public\/.+/)) {
|
|
202
204
|
return `${url}`;
|
|
203
205
|
} else {
|
package/dist/index.mjs
CHANGED
|
@@ -50,6 +50,7 @@ async function uploadFile({ file, input, onProgressChange, options }, { apiPath,
|
|
|
50
50
|
extension: file.name.split('.').pop(),
|
|
51
51
|
type: file.type,
|
|
52
52
|
size: file.size,
|
|
53
|
+
fileName: options?.manualFileName,
|
|
53
54
|
replaceTargetUrl: options?.replaceTargetUrl
|
|
54
55
|
}
|
|
55
56
|
}),
|
|
@@ -122,7 +123,7 @@ async function deleteFile({ url }, { apiPath, bucketName }) {
|
|
|
122
123
|
};
|
|
123
124
|
}
|
|
124
125
|
|
|
125
|
-
const DEFAULT_BASE_URL = process.env.NEXT_PUBLIC_EDGE_STORE_BASE_URL ?? 'https://files.
|
|
126
|
+
const DEFAULT_BASE_URL = process.env.NEXT_PUBLIC_EDGE_STORE_BASE_URL ?? 'https://files.edgestore.dev';
|
|
126
127
|
function createEdgeStoreProvider(opts) {
|
|
127
128
|
const EdgeStoreContext = /*#__PURE__*/ React.createContext(undefined);
|
|
128
129
|
const EdgeStoreProvider = ({ // TODO: Add basePath when custom domain is supported
|
|
@@ -169,11 +170,12 @@ function EdgeStoreProviderInner({ children, context, basePath, maxConcurrentUplo
|
|
|
169
170
|
});
|
|
170
171
|
}
|
|
171
172
|
});
|
|
173
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
172
174
|
}, []);
|
|
173
175
|
function getSrc(url) {
|
|
174
176
|
if (// in production we use cookies, so we don't need a token
|
|
175
177
|
process.env.NODE_ENV === 'production' || // public urls don't need a token
|
|
176
|
-
// e.g. https://files.
|
|
178
|
+
// e.g. https://files.edgestore.dev/project/bucket/_public/...
|
|
177
179
|
url.match(/^https?:\/\/[^\/]+\/[^\/]+\/[^\/]+\/_public\/.+/)) {
|
|
178
180
|
return `${url}`;
|
|
179
181
|
} else {
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edgestore/react",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
3
|
+
"version": "0.0.0-alpha.13",
|
|
4
4
|
"description": "Image Handling for React/Next.js",
|
|
5
|
-
"homepage": "https://
|
|
5
|
+
"homepage": "https://edgestore.dev",
|
|
6
6
|
"repository": "https://github.com/edgestorejs/edge-store.git",
|
|
7
7
|
"author": "Ravi <me@ravi.com>",
|
|
8
8
|
"main": "dist/index.js",
|
|
@@ -52,14 +52,14 @@
|
|
|
52
52
|
"uuid": "^9.0.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@edgestore/server": "0.0.0-alpha.
|
|
55
|
+
"@edgestore/server": "0.0.0-alpha.13",
|
|
56
56
|
"next": "*",
|
|
57
57
|
"react": ">=16.8.0",
|
|
58
58
|
"react-dom": ">=16.8.0",
|
|
59
59
|
"zod": ">=3.0.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@edgestore/server": "0.0.0-alpha.
|
|
62
|
+
"@edgestore/server": "0.0.0-alpha.13",
|
|
63
63
|
"@types/cookie": "^0.5.1",
|
|
64
64
|
"@types/node": "^18.11.18",
|
|
65
65
|
"@types/uuid": "^9.0.1",
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"typescript": "^5.1.6",
|
|
70
70
|
"zod": "^3.21.4"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "f89bcb0360feec96fb842ad447d86a0e5c58900d"
|
|
73
73
|
}
|
package/src/contextProvider.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import * as React from 'react';
|
|
|
3
3
|
import { BucketFunctions, createNextProxy } from './createNextProxy';
|
|
4
4
|
|
|
5
5
|
const DEFAULT_BASE_URL =
|
|
6
|
-
process.env.NEXT_PUBLIC_EDGE_STORE_BASE_URL ?? 'https://files.
|
|
6
|
+
process.env.NEXT_PUBLIC_EDGE_STORE_BASE_URL ?? 'https://files.edgestore.dev';
|
|
7
7
|
|
|
8
8
|
type EdgeStoreContextValue<TRouter extends AnyRouter> = {
|
|
9
9
|
edgestore: BucketFunctions<TRouter>;
|
|
@@ -103,6 +103,7 @@ function EdgeStoreProviderInner<TRouter extends AnyRouter>({
|
|
|
103
103
|
});
|
|
104
104
|
}
|
|
105
105
|
});
|
|
106
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
106
107
|
}, []);
|
|
107
108
|
|
|
108
109
|
function getSrc(url: string) {
|
|
@@ -110,7 +111,7 @@ function EdgeStoreProviderInner<TRouter extends AnyRouter>({
|
|
|
110
111
|
// in production we use cookies, so we don't need a token
|
|
111
112
|
process.env.NODE_ENV === 'production' ||
|
|
112
113
|
// public urls don't need a token
|
|
113
|
-
// e.g. https://files.
|
|
114
|
+
// e.g. https://files.edgestore.dev/project/bucket/_public/...
|
|
114
115
|
url.match(/^https?:\/\/[^\/]+\/[^\/]+\/[^\/]+\/_public\/.+/)
|
|
115
116
|
) {
|
|
116
117
|
return `${url}`;
|
package/src/createNextProxy.ts
CHANGED
|
@@ -9,30 +9,44 @@ import EdgeStoreError from './libs/errors/EdgeStoreError';
|
|
|
9
9
|
export type BucketFunctions<TRouter extends AnyRouter> = {
|
|
10
10
|
[K in keyof TRouter['buckets']]: {
|
|
11
11
|
upload: (
|
|
12
|
-
params: z.infer<TRouter['buckets'][K]['_def']['input']> extends
|
|
12
|
+
params: z.infer<TRouter['buckets'][K]['_def']['input']> extends never
|
|
13
13
|
? {
|
|
14
14
|
file: File;
|
|
15
|
-
input: z.infer<TRouter['buckets'][K]['_def']['input']>;
|
|
16
15
|
onProgressChange?: OnProgressChangeHandler;
|
|
17
16
|
options?: UploadOptions;
|
|
18
17
|
}
|
|
19
18
|
: {
|
|
20
19
|
file: File;
|
|
20
|
+
input: z.infer<TRouter['buckets'][K]['_def']['input']>;
|
|
21
21
|
onProgressChange?: OnProgressChangeHandler;
|
|
22
22
|
options?: UploadOptions;
|
|
23
23
|
},
|
|
24
|
-
) => Promise<
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
) => Promise<
|
|
25
|
+
TRouter['buckets'][K]['_def']['type'] extends 'IMAGE'
|
|
26
|
+
? {
|
|
27
|
+
url: string;
|
|
28
|
+
thumbnailUrl: string | null;
|
|
29
|
+
size: number;
|
|
30
|
+
uploadedAt: Date;
|
|
31
|
+
metadata: InferMetadataObject<TRouter['buckets'][K]>;
|
|
32
|
+
path: InferBucketPathKeys<TRouter['buckets'][K]> extends never
|
|
33
|
+
? Record<string, never>
|
|
34
|
+
: {
|
|
35
|
+
[TKey in InferBucketPathKeys<TRouter['buckets'][K]>]: string;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
: {
|
|
39
|
+
url: string;
|
|
40
|
+
size: number;
|
|
41
|
+
uploadedAt: Date;
|
|
42
|
+
metadata: InferMetadataObject<TRouter['buckets'][K]>;
|
|
43
|
+
path: InferBucketPathKeys<TRouter['buckets'][K]> extends never
|
|
44
|
+
? Record<string, never>
|
|
45
|
+
: {
|
|
46
|
+
[TKey in InferBucketPathKeys<TRouter['buckets'][K]>]: string;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
>;
|
|
36
50
|
delete: (params: { url: string }) => Promise<{
|
|
37
51
|
success: boolean;
|
|
38
52
|
}>;
|
|
@@ -42,6 +56,24 @@ export type BucketFunctions<TRouter extends AnyRouter> = {
|
|
|
42
56
|
type OnProgressChangeHandler = (progress: number) => void;
|
|
43
57
|
|
|
44
58
|
type UploadOptions = {
|
|
59
|
+
/**
|
|
60
|
+
* e.g. 'my-file-name.jpg'
|
|
61
|
+
*
|
|
62
|
+
* * Not Recommended *
|
|
63
|
+
*
|
|
64
|
+
* By default, a unique file name will be generated for each upload.
|
|
65
|
+
* If you want to use a custom file name, you can use this option.
|
|
66
|
+
* If you use the same file name for multiple uploads, the previous file will be overwritten.
|
|
67
|
+
* But it will take some time for the cache to be cleared.
|
|
68
|
+
* So you will keep seeing the old file for a while.
|
|
69
|
+
*
|
|
70
|
+
* If you want to replace an existing file immediately leave the `manualFileName` option empty and use the `replaceTargetUrl` option.
|
|
71
|
+
*/
|
|
72
|
+
manualFileName?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Use this to replace an existing file.
|
|
75
|
+
* It will automatically delete the existing file when the upload is complete.
|
|
76
|
+
*/
|
|
45
77
|
replaceTargetUrl?: string;
|
|
46
78
|
};
|
|
47
79
|
|
|
@@ -119,6 +151,7 @@ async function uploadFile(
|
|
|
119
151
|
extension: file.name.split('.').pop(),
|
|
120
152
|
type: file.type,
|
|
121
153
|
size: file.size,
|
|
154
|
+
fileName: options?.manualFileName,
|
|
122
155
|
replaceTargetUrl: options?.replaceTargetUrl,
|
|
123
156
|
},
|
|
124
157
|
}),
|