@edgestore/react 0.1.2 → 0.1.3-alpha.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/dist/contextProvider.d.ts +5 -3
- package/dist/contextProvider.d.ts.map +1 -1
- package/dist/index.js +17 -29
- package/dist/index.mjs +17 -29
- package/package.json +4 -4
- package/src/contextProvider.tsx +23 -33
- package/src/createNextProxy.ts +0 -2
|
@@ -4,10 +4,12 @@ import { type BucketFunctions } from './createNextProxy';
|
|
|
4
4
|
type EdgeStoreContextValue<TRouter extends AnyRouter> = {
|
|
5
5
|
edgestore: BucketFunctions<TRouter>;
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* This will re-run the Edge Store initialization process,
|
|
8
|
+
* which will run the `createContext` function again.
|
|
9
|
+
*
|
|
10
|
+
* Can be used after a sign-in or sign-out, for example.
|
|
9
11
|
*/
|
|
10
|
-
|
|
12
|
+
reset: () => Promise<void>;
|
|
11
13
|
};
|
|
12
14
|
export declare function createEdgeStoreProvider<TRouter extends AnyRouter>(opts?: {
|
|
13
15
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contextProvider.d.ts","sourceRoot":"","sources":["../src/contextProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAK1E,KAAK,qBAAqB,CAAC,OAAO,SAAS,SAAS,IAAI;IACtD,SAAS,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;IACpC
|
|
1
|
+
{"version":3,"file":"contextProvider.d.ts","sourceRoot":"","sources":["../src/contextProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAK1E,KAAK,qBAAqB,CAAC,OAAO,SAAS,SAAS,IAAI;IACtD,SAAS,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;IACpC;;;;;OAKG;IACH,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B,CAAC;AAEF,wBAAgB,uBAAuB,CAAC,OAAO,SAAS,SAAS,EAAE,IAAI,CAAC,EAAE;IACxE;;;;;;OAMG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;;kBASa,MAAM,SAAS;QACzB;;;;;;WAMG;;;;EAgCN"}
|
package/dist/index.js
CHANGED
|
@@ -110,9 +110,7 @@ async function uploadFile({ file, input, onProgressChange, options }, { apiPath,
|
|
|
110
110
|
thumbnailUrl: json.thumbnailUrl ? getUrl(json.thumbnailUrl, apiPath) : null,
|
|
111
111
|
size: json.size,
|
|
112
112
|
uploadedAt: new Date(json.uploadedAt),
|
|
113
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
114
113
|
path: json.path,
|
|
115
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
116
114
|
metadata: json.metadata
|
|
117
115
|
};
|
|
118
116
|
} catch (e) {
|
|
@@ -321,38 +319,28 @@ function createEdgeStoreProvider(opts) {
|
|
|
321
319
|
}
|
|
322
320
|
function EdgeStoreProviderInner({ children, context, basePath, maxConcurrentUploads }) {
|
|
323
321
|
const apiPath = basePath ? `${basePath}` : '/api/edgestore';
|
|
324
|
-
const [token, setToken] = React__namespace.useState(null);
|
|
325
322
|
const uploadingCountRef = React__namespace.useRef(0);
|
|
326
323
|
React__namespace.useEffect(()=>{
|
|
327
|
-
void
|
|
328
|
-
method: 'POST'
|
|
329
|
-
}).then(async (res)=>{
|
|
330
|
-
if (res.ok) {
|
|
331
|
-
const json = await res.json();
|
|
332
|
-
setToken(json.token);
|
|
333
|
-
await fetch(`${DEFAULT_BASE_URL}/_init`, {
|
|
334
|
-
method: 'GET',
|
|
335
|
-
headers: {
|
|
336
|
-
'x-edgestore-token': json.token
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
});
|
|
324
|
+
void init();
|
|
341
325
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
342
326
|
}, []);
|
|
343
|
-
function
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
327
|
+
async function init() {
|
|
328
|
+
const res = await fetch(`${apiPath}/init`, {
|
|
329
|
+
method: 'POST'
|
|
330
|
+
});
|
|
331
|
+
if (res.ok) {
|
|
332
|
+
const json = await res.json();
|
|
333
|
+
await fetch(`${DEFAULT_BASE_URL}/_init`, {
|
|
334
|
+
method: 'GET',
|
|
335
|
+
headers: {
|
|
336
|
+
'x-edgestore-token': json.token
|
|
337
|
+
}
|
|
338
|
+
});
|
|
354
339
|
}
|
|
355
340
|
}
|
|
341
|
+
async function reset() {
|
|
342
|
+
await init();
|
|
343
|
+
}
|
|
356
344
|
return /*#__PURE__*/ React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/ React__namespace.createElement(context.Provider, {
|
|
357
345
|
value: {
|
|
358
346
|
edgestore: createNextProxy({
|
|
@@ -360,7 +348,7 @@ function EdgeStoreProviderInner({ children, context, basePath, maxConcurrentUplo
|
|
|
360
348
|
uploadingCountRef,
|
|
361
349
|
maxConcurrentUploads
|
|
362
350
|
}),
|
|
363
|
-
|
|
351
|
+
reset
|
|
364
352
|
}
|
|
365
353
|
}, children));
|
|
366
354
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -86,9 +86,7 @@ async function uploadFile({ file, input, onProgressChange, options }, { apiPath,
|
|
|
86
86
|
thumbnailUrl: json.thumbnailUrl ? getUrl(json.thumbnailUrl, apiPath) : null,
|
|
87
87
|
size: json.size,
|
|
88
88
|
uploadedAt: new Date(json.uploadedAt),
|
|
89
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
90
89
|
path: json.path,
|
|
91
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
92
90
|
metadata: json.metadata
|
|
93
91
|
};
|
|
94
92
|
} catch (e) {
|
|
@@ -297,38 +295,28 @@ function createEdgeStoreProvider(opts) {
|
|
|
297
295
|
}
|
|
298
296
|
function EdgeStoreProviderInner({ children, context, basePath, maxConcurrentUploads }) {
|
|
299
297
|
const apiPath = basePath ? `${basePath}` : '/api/edgestore';
|
|
300
|
-
const [token, setToken] = React.useState(null);
|
|
301
298
|
const uploadingCountRef = React.useRef(0);
|
|
302
299
|
React.useEffect(()=>{
|
|
303
|
-
void
|
|
304
|
-
method: 'POST'
|
|
305
|
-
}).then(async (res)=>{
|
|
306
|
-
if (res.ok) {
|
|
307
|
-
const json = await res.json();
|
|
308
|
-
setToken(json.token);
|
|
309
|
-
await fetch(`${DEFAULT_BASE_URL}/_init`, {
|
|
310
|
-
method: 'GET',
|
|
311
|
-
headers: {
|
|
312
|
-
'x-edgestore-token': json.token
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
});
|
|
300
|
+
void init();
|
|
317
301
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
318
302
|
}, []);
|
|
319
|
-
function
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
303
|
+
async function init() {
|
|
304
|
+
const res = await fetch(`${apiPath}/init`, {
|
|
305
|
+
method: 'POST'
|
|
306
|
+
});
|
|
307
|
+
if (res.ok) {
|
|
308
|
+
const json = await res.json();
|
|
309
|
+
await fetch(`${DEFAULT_BASE_URL}/_init`, {
|
|
310
|
+
method: 'GET',
|
|
311
|
+
headers: {
|
|
312
|
+
'x-edgestore-token': json.token
|
|
313
|
+
}
|
|
314
|
+
});
|
|
330
315
|
}
|
|
331
316
|
}
|
|
317
|
+
async function reset() {
|
|
318
|
+
await init();
|
|
319
|
+
}
|
|
332
320
|
return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(context.Provider, {
|
|
333
321
|
value: {
|
|
334
322
|
edgestore: createNextProxy({
|
|
@@ -336,7 +324,7 @@ function EdgeStoreProviderInner({ children, context, basePath, maxConcurrentUplo
|
|
|
336
324
|
uploadingCountRef,
|
|
337
325
|
maxConcurrentUploads
|
|
338
326
|
}),
|
|
339
|
-
|
|
327
|
+
reset
|
|
340
328
|
}
|
|
341
329
|
}, children));
|
|
342
330
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edgestore/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3-alpha.0",
|
|
4
4
|
"description": "Upload files with ease from React/Next.js",
|
|
5
5
|
"homepage": "https://edgestore.dev",
|
|
6
6
|
"repository": "https://github.com/edgestorejs/edgestore.git",
|
|
@@ -54,14 +54,14 @@
|
|
|
54
54
|
"uuid": "^9.0.0"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@edgestore/server": "0.1.
|
|
57
|
+
"@edgestore/server": "0.1.3-alpha.0",
|
|
58
58
|
"next": "*",
|
|
59
59
|
"react": ">=16.8.0",
|
|
60
60
|
"react-dom": ">=16.8.0",
|
|
61
61
|
"zod": ">=3.0.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@edgestore/server": "0.1.
|
|
64
|
+
"@edgestore/server": "0.1.3-alpha.0",
|
|
65
65
|
"@types/cookie": "^0.5.1",
|
|
66
66
|
"@types/node": "^18.11.18",
|
|
67
67
|
"@types/uuid": "^9.0.1",
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"typescript": "^5.1.6",
|
|
72
72
|
"zod": "^3.21.4"
|
|
73
73
|
},
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "3ed23e543ee1ed151685884bb0983c2471e03880"
|
|
75
75
|
}
|
package/src/contextProvider.tsx
CHANGED
|
@@ -8,10 +8,12 @@ const DEFAULT_BASE_URL =
|
|
|
8
8
|
type EdgeStoreContextValue<TRouter extends AnyRouter> = {
|
|
9
9
|
edgestore: BucketFunctions<TRouter>;
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* This will re-run the Edge Store initialization process,
|
|
12
|
+
* which will run the `createContext` function again.
|
|
13
|
+
*
|
|
14
|
+
* Can be used after a sign-in or sign-out, for example.
|
|
13
15
|
*/
|
|
14
|
-
|
|
16
|
+
reset: () => Promise<void>;
|
|
15
17
|
};
|
|
16
18
|
|
|
17
19
|
export function createEdgeStoreProvider<TRouter extends AnyRouter>(opts?: {
|
|
@@ -85,43 +87,31 @@ function EdgeStoreProviderInner<TRouter extends AnyRouter>({
|
|
|
85
87
|
maxConcurrentUploads?: number;
|
|
86
88
|
}) {
|
|
87
89
|
const apiPath = basePath ? `${basePath}` : '/api/edgestore';
|
|
88
|
-
const [token, setToken] = React.useState<string | null>(null);
|
|
89
90
|
const uploadingCountRef = React.useRef(0);
|
|
90
91
|
React.useEffect(() => {
|
|
91
|
-
void
|
|
92
|
-
method: 'POST',
|
|
93
|
-
}).then(async (res) => {
|
|
94
|
-
if (res.ok) {
|
|
95
|
-
const json = await res.json();
|
|
96
|
-
setToken(json.token);
|
|
97
|
-
await fetch(`${DEFAULT_BASE_URL}/_init`, {
|
|
98
|
-
method: 'GET',
|
|
99
|
-
headers: {
|
|
100
|
-
'x-edgestore-token': json.token,
|
|
101
|
-
},
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
});
|
|
92
|
+
void init();
|
|
105
93
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
106
94
|
}, []);
|
|
107
95
|
|
|
108
|
-
function
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
uri.searchParams.set('token', token ?? '');
|
|
121
|
-
return `${uri}`;
|
|
96
|
+
async function init() {
|
|
97
|
+
const res = await fetch(`${apiPath}/init`, {
|
|
98
|
+
method: 'POST',
|
|
99
|
+
});
|
|
100
|
+
if (res.ok) {
|
|
101
|
+
const json = await res.json();
|
|
102
|
+
await fetch(`${DEFAULT_BASE_URL}/_init`, {
|
|
103
|
+
method: 'GET',
|
|
104
|
+
headers: {
|
|
105
|
+
'x-edgestore-token': json.token,
|
|
106
|
+
},
|
|
107
|
+
});
|
|
122
108
|
}
|
|
123
109
|
}
|
|
124
110
|
|
|
111
|
+
async function reset() {
|
|
112
|
+
await init();
|
|
113
|
+
}
|
|
114
|
+
|
|
125
115
|
return (
|
|
126
116
|
<>
|
|
127
117
|
<context.Provider
|
|
@@ -131,7 +121,7 @@ function EdgeStoreProviderInner<TRouter extends AnyRouter>({
|
|
|
131
121
|
uploadingCountRef,
|
|
132
122
|
maxConcurrentUploads,
|
|
133
123
|
}),
|
|
134
|
-
|
|
124
|
+
reset,
|
|
135
125
|
}}
|
|
136
126
|
>
|
|
137
127
|
{children}
|
package/src/createNextProxy.ts
CHANGED
|
@@ -193,9 +193,7 @@ async function uploadFile(
|
|
|
193
193
|
: null,
|
|
194
194
|
size: json.size,
|
|
195
195
|
uploadedAt: new Date(json.uploadedAt),
|
|
196
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
197
196
|
path: json.path as any,
|
|
198
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
199
197
|
metadata: json.metadata as any,
|
|
200
198
|
};
|
|
201
199
|
} catch (e) {
|