@edgestore/react 0.6.0-canary.1 → 0.6.0-canary.3
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 +65 -0
- package/dist/contextProvider.d.ts.map +1 -0
- package/dist/contextProvider.js +152 -0
- package/dist/contextProvider.mjs +131 -0
- package/dist/createNextProxy.d.ts +71 -0
- package/dist/createNextProxy.d.ts.map +1 -0
- package/dist/createNextProxy.js +322 -0
- package/dist/createNextProxy.mjs +320 -0
- package/dist/errors/index.d.ts +3 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +12 -0
- package/dist/errors/index.mjs +2 -4
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.mjs +1 -397
- package/dist/libs/errors/EdgeStoreClientError.d.ts +5 -0
- package/dist/libs/errors/EdgeStoreClientError.d.ts.map +1 -0
- package/dist/libs/errors/EdgeStoreClientError.js +10 -0
- package/dist/libs/errors/EdgeStoreClientError.mjs +8 -0
- package/dist/libs/errors/handleError.d.ts +2 -0
- package/dist/libs/errors/handleError.d.ts.map +1 -0
- package/dist/libs/errors/handleError.js +18 -0
- package/dist/libs/errors/handleError.mjs +16 -0
- package/dist/libs/errors/uploadAbortedError.d.ts +4 -0
- package/dist/libs/errors/uploadAbortedError.d.ts.map +1 -0
- package/dist/libs/errors/uploadAbortedError.js +10 -0
- package/dist/libs/errors/uploadAbortedError.mjs +8 -0
- package/dist/shared/index.d.ts +7 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/index.js +11 -0
- package/dist/shared/index.mjs +5 -7
- package/dist/utils/{index.d.cts → index.d.ts} +3 -6
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +37 -0
- package/dist/utils/index.mjs +28 -33
- package/errors/index.d.ts +1 -0
- package/errors/index.js +1 -0
- package/package.json +32 -46
- package/shared/index.d.ts +1 -0
- package/shared/index.js +1 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/dist/errors/index.cjs +0 -11
- package/dist/errors/index.d.cts +0 -9
- package/dist/errors/index.d.cts.map +0 -1
- package/dist/errors/index.d.mts +0 -9
- package/dist/errors/index.d.mts.map +0 -1
- package/dist/index.cjs +0 -425
- package/dist/index.d.cts +0 -131
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts +0 -131
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/shared/index.cjs +0 -11
- package/dist/shared/index.d.cts +0 -11
- package/dist/shared/index.d.cts.map +0 -1
- package/dist/shared/index.d.mts +0 -11
- package/dist/shared/index.d.mts.map +0 -1
- package/dist/shared/index.mjs.map +0 -1
- package/dist/uploadAbortedError-1Hka0_24.mjs +0 -11
- package/dist/uploadAbortedError-1Hka0_24.mjs.map +0 -1
- package/dist/uploadAbortedError-CyhLukhg.cjs +0 -16
- package/dist/utils/index.cjs +0 -40
- package/dist/utils/index.d.cts.map +0 -1
- package/dist/utils/index.d.mts +0 -17
- package/dist/utils/index.d.mts.map +0 -1
- package/dist/utils/index.mjs.map +0 -1
- package/errors/package.json +0 -1
- package/shared/package.json +0 -1
- package/utils/package.json +0 -1
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { type AnyRouter } from '@edgestore/shared';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { type BucketFunctions } from './createNextProxy';
|
|
4
|
+
type EdgeStoreContextValue<TRouter extends AnyRouter> = {
|
|
5
|
+
edgestore: BucketFunctions<TRouter>;
|
|
6
|
+
/**
|
|
7
|
+
* This will re-run the EdgeStore initialization process,
|
|
8
|
+
* which will run the `createContext` function again.
|
|
9
|
+
*
|
|
10
|
+
* Can be used after a sign-in or sign-out, for example.
|
|
11
|
+
*/
|
|
12
|
+
reset: () => Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* The current state of the EdgeStore provider.
|
|
15
|
+
*
|
|
16
|
+
* You can use this to wait for the provider to be initialized
|
|
17
|
+
* before trying to show private images on your app.
|
|
18
|
+
*/
|
|
19
|
+
state: ProviderState;
|
|
20
|
+
};
|
|
21
|
+
export declare function createEdgeStoreProvider<TRouter extends AnyRouter>(opts?: {
|
|
22
|
+
/**
|
|
23
|
+
* The maximum number of concurrent uploads.
|
|
24
|
+
*
|
|
25
|
+
* Uploads will automatically be queued if this limit is reached.
|
|
26
|
+
*
|
|
27
|
+
* @default 5
|
|
28
|
+
*/
|
|
29
|
+
maxConcurrentUploads?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Accessing EdgeStore protected files in development mode requires a proxy.
|
|
32
|
+
* You might want to disable this for other providers if you are overwriting the path.
|
|
33
|
+
*
|
|
34
|
+
* @default false
|
|
35
|
+
*/
|
|
36
|
+
disableDevProxy?: boolean;
|
|
37
|
+
}): {
|
|
38
|
+
EdgeStoreProvider: ({ children, basePath, }: {
|
|
39
|
+
children: React.ReactNode;
|
|
40
|
+
/**
|
|
41
|
+
* In case your app is not hosted at the root of your domain, you can specify the base path here.
|
|
42
|
+
* If you set this, make sure to set the full path to the EdgeStore API.
|
|
43
|
+
* e.g. `/my-app/api/edgestore` or `https://example.com/my-app/api/edgestore`
|
|
44
|
+
*
|
|
45
|
+
* @example - If your app is hosted at `https://example.com/my-app`, you can set the `basePath` to `/my-app/api/edgestore`.
|
|
46
|
+
*/
|
|
47
|
+
basePath?: string;
|
|
48
|
+
}) => React.JSX.Element;
|
|
49
|
+
useEdgeStore: () => EdgeStoreContextValue<TRouter>;
|
|
50
|
+
};
|
|
51
|
+
type ProviderState = {
|
|
52
|
+
loading: true;
|
|
53
|
+
initialized: false;
|
|
54
|
+
error: false;
|
|
55
|
+
} | {
|
|
56
|
+
loading: false;
|
|
57
|
+
initialized: false;
|
|
58
|
+
error: true;
|
|
59
|
+
} | {
|
|
60
|
+
loading: false;
|
|
61
|
+
initialized: true;
|
|
62
|
+
error: false;
|
|
63
|
+
};
|
|
64
|
+
export {};
|
|
65
|
+
//# sourceMappingURL=contextProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contextProvider.d.ts","sourceRoot":"","sources":["../src/contextProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAU1E,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;IAC3B;;;;;OAKG;IACH,KAAK,EAAE,aAAa,CAAC;CACtB,CAAC;AAEF,wBAAgB,uBAAuB,CAAC,OAAO,SAAS,SAAS,EAAE,IAAI,CAAC,EAAE;IACxE;;;;;;OAMG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;;OAKG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;iDAQI;QACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;QAC1B;;;;;;WAMG;QACH,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB;;EA+BF;AAED,KAAK,aAAa,GACd;IACE,OAAO,EAAE,IAAI,CAAC;IACd,WAAW,EAAE,KAAK,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC;CACd,GACD;IACE,OAAO,EAAE,KAAK,CAAC;IACf,WAAW,EAAE,KAAK,CAAC;IACnB,KAAK,EAAE,IAAI,CAAC;CACb,GACD;IACE,OAAO,EAAE,KAAK,CAAC;IACf,WAAW,EAAE,IAAI,CAAC;IAClB,KAAK,EAAE,KAAK,CAAC;CACd,CAAC"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var createNextProxy = require('./createNextProxy.js');
|
|
5
|
+
var EdgeStoreClientError = require('./libs/errors/EdgeStoreClientError.js');
|
|
6
|
+
var handleError = require('./libs/errors/handleError.js');
|
|
7
|
+
|
|
8
|
+
function _interopNamespaceDefault(e) {
|
|
9
|
+
var n = Object.create(null);
|
|
10
|
+
if (e) {
|
|
11
|
+
Object.keys(e).forEach(function (k) {
|
|
12
|
+
if (k !== 'default') {
|
|
13
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () { return e[k]; }
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
n.default = e;
|
|
22
|
+
return Object.freeze(n);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
26
|
+
|
|
27
|
+
const DEFAULT_BASE_URL = (typeof process !== 'undefined' ? process.env.NEXT_PUBLIC_EDGE_STORE_BASE_URL : undefined?.EDGE_STORE_BASE_URL) ?? 'https://files.edgestore.dev';
|
|
28
|
+
function createEdgeStoreProvider(opts) {
|
|
29
|
+
const EdgeStoreContext = /*#__PURE__*/ React__namespace.createContext(undefined);
|
|
30
|
+
const EdgeStoreProvider = ({ children, basePath })=>{
|
|
31
|
+
return EdgeStoreProviderInner({
|
|
32
|
+
children,
|
|
33
|
+
context: EdgeStoreContext,
|
|
34
|
+
basePath,
|
|
35
|
+
maxConcurrentUploads: opts?.maxConcurrentUploads,
|
|
36
|
+
disableDevProxy: opts?.disableDevProxy
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
function useEdgeStore() {
|
|
40
|
+
if (!EdgeStoreContext) {
|
|
41
|
+
throw new Error('React Context is unavailable in Server Components');
|
|
42
|
+
}
|
|
43
|
+
// @ts-expect-error - We know that the context value should not be undefined
|
|
44
|
+
const value = React__namespace.useContext(EdgeStoreContext);
|
|
45
|
+
if (!value && process.env.NODE_ENV !== 'production') {
|
|
46
|
+
throw new Error('[edgestore]: `useEdgeStore` must be wrapped in a <EdgeStoreProvider />');
|
|
47
|
+
}
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
EdgeStoreProvider,
|
|
52
|
+
useEdgeStore
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function EdgeStoreProviderInner({ children, context, basePath, maxConcurrentUploads, disableDevProxy }) {
|
|
56
|
+
const apiPath = basePath ? `${basePath}` : '/api/edgestore';
|
|
57
|
+
const [state, setState] = React__namespace.useState({
|
|
58
|
+
loading: true,
|
|
59
|
+
initialized: false,
|
|
60
|
+
error: false
|
|
61
|
+
});
|
|
62
|
+
const uploadingCountRef = React__namespace.useRef(0);
|
|
63
|
+
const initExecuted = React__namespace.useRef(false); // to make sure we don't run init twice
|
|
64
|
+
React__namespace.useEffect(()=>{
|
|
65
|
+
if (!initExecuted.current) {
|
|
66
|
+
void init();
|
|
67
|
+
}
|
|
68
|
+
return ()=>{
|
|
69
|
+
initExecuted.current = true;
|
|
70
|
+
};
|
|
71
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
72
|
+
}, []);
|
|
73
|
+
async function init() {
|
|
74
|
+
try {
|
|
75
|
+
setState({
|
|
76
|
+
loading: true,
|
|
77
|
+
initialized: false,
|
|
78
|
+
error: false
|
|
79
|
+
});
|
|
80
|
+
const res = await fetch(`${apiPath}/init`, {
|
|
81
|
+
method: 'POST',
|
|
82
|
+
credentials: 'include'
|
|
83
|
+
});
|
|
84
|
+
if (res.ok) {
|
|
85
|
+
const json = await res.json();
|
|
86
|
+
// Only call _init API if provider is edgestore
|
|
87
|
+
if (json.providerName === 'edgestore') {
|
|
88
|
+
const innerRes = await fetch(`${DEFAULT_BASE_URL}/_init`, {
|
|
89
|
+
method: 'GET',
|
|
90
|
+
credentials: 'include',
|
|
91
|
+
headers: {
|
|
92
|
+
'x-edgestore-token': json.token
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
if (innerRes.ok) {
|
|
96
|
+
// update state
|
|
97
|
+
setState({
|
|
98
|
+
loading: false,
|
|
99
|
+
initialized: true,
|
|
100
|
+
error: false
|
|
101
|
+
});
|
|
102
|
+
} else {
|
|
103
|
+
setState({
|
|
104
|
+
loading: false,
|
|
105
|
+
initialized: false,
|
|
106
|
+
error: true
|
|
107
|
+
});
|
|
108
|
+
throw new EdgeStoreClientError("Couldn't initialize EdgeStore.");
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
// For non-edgestore providers, just update state without calling _init
|
|
112
|
+
setState({
|
|
113
|
+
loading: false,
|
|
114
|
+
initialized: true,
|
|
115
|
+
error: false
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
setState({
|
|
120
|
+
loading: false,
|
|
121
|
+
initialized: false,
|
|
122
|
+
error: true
|
|
123
|
+
});
|
|
124
|
+
await handleError.handleError(res);
|
|
125
|
+
}
|
|
126
|
+
} catch (err) {
|
|
127
|
+
setState({
|
|
128
|
+
loading: false,
|
|
129
|
+
initialized: false,
|
|
130
|
+
error: true
|
|
131
|
+
});
|
|
132
|
+
throw err;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
async function reset() {
|
|
136
|
+
await init();
|
|
137
|
+
}
|
|
138
|
+
return /*#__PURE__*/ React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/ React__namespace.createElement(context.Provider, {
|
|
139
|
+
value: {
|
|
140
|
+
edgestore: createNextProxy.createNextProxy({
|
|
141
|
+
apiPath,
|
|
142
|
+
uploadingCountRef,
|
|
143
|
+
maxConcurrentUploads,
|
|
144
|
+
disableDevProxy
|
|
145
|
+
}),
|
|
146
|
+
reset,
|
|
147
|
+
state
|
|
148
|
+
}
|
|
149
|
+
}, children));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
exports.createEdgeStoreProvider = createEdgeStoreProvider;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { createNextProxy } from './createNextProxy.mjs';
|
|
3
|
+
import EdgeStoreClientError from './libs/errors/EdgeStoreClientError.mjs';
|
|
4
|
+
import { handleError } from './libs/errors/handleError.mjs';
|
|
5
|
+
|
|
6
|
+
const DEFAULT_BASE_URL = (typeof process !== 'undefined' ? process.env.NEXT_PUBLIC_EDGE_STORE_BASE_URL : import.meta.env?.EDGE_STORE_BASE_URL) ?? 'https://files.edgestore.dev';
|
|
7
|
+
function createEdgeStoreProvider(opts) {
|
|
8
|
+
const EdgeStoreContext = /*#__PURE__*/ React.createContext(undefined);
|
|
9
|
+
const EdgeStoreProvider = ({ children, basePath })=>{
|
|
10
|
+
return EdgeStoreProviderInner({
|
|
11
|
+
children,
|
|
12
|
+
context: EdgeStoreContext,
|
|
13
|
+
basePath,
|
|
14
|
+
maxConcurrentUploads: opts?.maxConcurrentUploads,
|
|
15
|
+
disableDevProxy: opts?.disableDevProxy
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
function useEdgeStore() {
|
|
19
|
+
if (!EdgeStoreContext) {
|
|
20
|
+
throw new Error('React Context is unavailable in Server Components');
|
|
21
|
+
}
|
|
22
|
+
// @ts-expect-error - We know that the context value should not be undefined
|
|
23
|
+
const value = React.useContext(EdgeStoreContext);
|
|
24
|
+
if (!value && process.env.NODE_ENV !== 'production') {
|
|
25
|
+
throw new Error('[edgestore]: `useEdgeStore` must be wrapped in a <EdgeStoreProvider />');
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
EdgeStoreProvider,
|
|
31
|
+
useEdgeStore
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function EdgeStoreProviderInner({ children, context, basePath, maxConcurrentUploads, disableDevProxy }) {
|
|
35
|
+
const apiPath = basePath ? `${basePath}` : '/api/edgestore';
|
|
36
|
+
const [state, setState] = React.useState({
|
|
37
|
+
loading: true,
|
|
38
|
+
initialized: false,
|
|
39
|
+
error: false
|
|
40
|
+
});
|
|
41
|
+
const uploadingCountRef = React.useRef(0);
|
|
42
|
+
const initExecuted = React.useRef(false); // to make sure we don't run init twice
|
|
43
|
+
React.useEffect(()=>{
|
|
44
|
+
if (!initExecuted.current) {
|
|
45
|
+
void init();
|
|
46
|
+
}
|
|
47
|
+
return ()=>{
|
|
48
|
+
initExecuted.current = true;
|
|
49
|
+
};
|
|
50
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
51
|
+
}, []);
|
|
52
|
+
async function init() {
|
|
53
|
+
try {
|
|
54
|
+
setState({
|
|
55
|
+
loading: true,
|
|
56
|
+
initialized: false,
|
|
57
|
+
error: false
|
|
58
|
+
});
|
|
59
|
+
const res = await fetch(`${apiPath}/init`, {
|
|
60
|
+
method: 'POST',
|
|
61
|
+
credentials: 'include'
|
|
62
|
+
});
|
|
63
|
+
if (res.ok) {
|
|
64
|
+
const json = await res.json();
|
|
65
|
+
// Only call _init API if provider is edgestore
|
|
66
|
+
if (json.providerName === 'edgestore') {
|
|
67
|
+
const innerRes = await fetch(`${DEFAULT_BASE_URL}/_init`, {
|
|
68
|
+
method: 'GET',
|
|
69
|
+
credentials: 'include',
|
|
70
|
+
headers: {
|
|
71
|
+
'x-edgestore-token': json.token
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
if (innerRes.ok) {
|
|
75
|
+
// update state
|
|
76
|
+
setState({
|
|
77
|
+
loading: false,
|
|
78
|
+
initialized: true,
|
|
79
|
+
error: false
|
|
80
|
+
});
|
|
81
|
+
} else {
|
|
82
|
+
setState({
|
|
83
|
+
loading: false,
|
|
84
|
+
initialized: false,
|
|
85
|
+
error: true
|
|
86
|
+
});
|
|
87
|
+
throw new EdgeStoreClientError("Couldn't initialize EdgeStore.");
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
// For non-edgestore providers, just update state without calling _init
|
|
91
|
+
setState({
|
|
92
|
+
loading: false,
|
|
93
|
+
initialized: true,
|
|
94
|
+
error: false
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
setState({
|
|
99
|
+
loading: false,
|
|
100
|
+
initialized: false,
|
|
101
|
+
error: true
|
|
102
|
+
});
|
|
103
|
+
await handleError(res);
|
|
104
|
+
}
|
|
105
|
+
} catch (err) {
|
|
106
|
+
setState({
|
|
107
|
+
loading: false,
|
|
108
|
+
initialized: false,
|
|
109
|
+
error: true
|
|
110
|
+
});
|
|
111
|
+
throw err;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async function reset() {
|
|
115
|
+
await init();
|
|
116
|
+
}
|
|
117
|
+
return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(context.Provider, {
|
|
118
|
+
value: {
|
|
119
|
+
edgestore: createNextProxy({
|
|
120
|
+
apiPath,
|
|
121
|
+
uploadingCountRef,
|
|
122
|
+
maxConcurrentUploads,
|
|
123
|
+
disableDevProxy
|
|
124
|
+
}),
|
|
125
|
+
reset,
|
|
126
|
+
state
|
|
127
|
+
}
|
|
128
|
+
}, children));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export { createEdgeStoreProvider };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type AnyRouter, type InferBucketPathObject, type InferMetadataObject, type UploadOptions } from '@edgestore/shared';
|
|
2
|
+
import { type z } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
* @see https://www.totaltypescript.com/concepts/the-prettify-helper
|
|
6
|
+
*/
|
|
7
|
+
export type Prettify<TType> = {
|
|
8
|
+
[K in keyof TType]: TType[K];
|
|
9
|
+
} & {};
|
|
10
|
+
export type BucketFunctions<TRouter extends AnyRouter> = {
|
|
11
|
+
[K in keyof TRouter['buckets']]: {
|
|
12
|
+
/**
|
|
13
|
+
* Upload a file to the bucket
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* await edgestore.myBucket.upload({
|
|
17
|
+
* file: file,
|
|
18
|
+
* signal: abortController.signal, // if you want to be able to cancel the ongoing upload
|
|
19
|
+
* onProgressChange: (progress) => { console.log(progress) }, // if you want to show the progress of the upload
|
|
20
|
+
* input: {...} // if the bucket has an input schema
|
|
21
|
+
* options: {
|
|
22
|
+
* manualFileName: file.name, // if you want to use a custom file name
|
|
23
|
+
* replaceTargetUrl: url, // if you want to replace an existing file
|
|
24
|
+
* temporary: true, // if you want to delete the file after 24 hours
|
|
25
|
+
* }
|
|
26
|
+
* })
|
|
27
|
+
*/
|
|
28
|
+
upload: (params: z.infer<TRouter['buckets'][K]['_def']['input']> extends never ? {
|
|
29
|
+
file: File;
|
|
30
|
+
signal?: AbortSignal;
|
|
31
|
+
onProgressChange?: OnProgressChangeHandler;
|
|
32
|
+
options?: UploadOptions;
|
|
33
|
+
} : {
|
|
34
|
+
file: File;
|
|
35
|
+
signal?: AbortSignal;
|
|
36
|
+
input: z.infer<TRouter['buckets'][K]['_def']['input']>;
|
|
37
|
+
onProgressChange?: OnProgressChangeHandler;
|
|
38
|
+
options?: UploadOptions;
|
|
39
|
+
}) => Promise<TRouter['buckets'][K]['_def']['type'] extends 'IMAGE' ? {
|
|
40
|
+
url: string;
|
|
41
|
+
thumbnailUrl: string | null;
|
|
42
|
+
size: number;
|
|
43
|
+
uploadedAt: Date;
|
|
44
|
+
metadata: InferMetadataObject<TRouter['buckets'][K]>;
|
|
45
|
+
path: InferBucketPathObject<TRouter['buckets'][K]>;
|
|
46
|
+
pathOrder: Prettify<keyof InferBucketPathObject<TRouter['buckets'][K]>>[];
|
|
47
|
+
} : {
|
|
48
|
+
url: string;
|
|
49
|
+
size: number;
|
|
50
|
+
uploadedAt: Date;
|
|
51
|
+
metadata: InferMetadataObject<TRouter['buckets'][K]>;
|
|
52
|
+
path: InferBucketPathObject<TRouter['buckets'][K]>;
|
|
53
|
+
pathOrder: Prettify<keyof InferBucketPathObject<TRouter['buckets'][K]>>[];
|
|
54
|
+
}>;
|
|
55
|
+
confirmUpload: (params: {
|
|
56
|
+
url: string;
|
|
57
|
+
}) => Promise<void>;
|
|
58
|
+
delete: (params: {
|
|
59
|
+
url: string;
|
|
60
|
+
}) => Promise<void>;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
type OnProgressChangeHandler = (progress: number) => void;
|
|
64
|
+
export declare function createNextProxy<TRouter extends AnyRouter>({ apiPath, uploadingCountRef, maxConcurrentUploads, disableDevProxy, }: {
|
|
65
|
+
apiPath: string;
|
|
66
|
+
uploadingCountRef: React.MutableRefObject<number>;
|
|
67
|
+
maxConcurrentUploads?: number;
|
|
68
|
+
disableDevProxy?: boolean;
|
|
69
|
+
}): BucketFunctions<TRouter>;
|
|
70
|
+
export {};
|
|
71
|
+
//# sourceMappingURL=createNextProxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createNextProxy.d.ts","sourceRoot":"","sources":["../src/createNextProxy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EAExB,KAAK,aAAa,EACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,CAAC;AAK7B;;;GAGG;AACH,MAAM,MAAM,QAAQ,CAAC,KAAK,IAAI;KAC3B,CAAC,IAAI,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC;CAE7B,GAAG,EAAE,CAAC;AAEP,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,SAAS,IAAI;KACtD,CAAC,IAAI,MAAM,OAAO,CAAC,SAAS,CAAC,GAAG;QAC/B;;;;;;;;;;;;;;;WAeG;QACH,MAAM,EAAE,CACN,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,OA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