@edgestore/server 1.0.0-next.3 → 1.0.0-next.5
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/README.md +2 -8
- package/agent-docs/README.md +20 -0
- package/agent-docs/astro.md +147 -0
- package/agent-docs/backend-client.md +284 -0
- package/agent-docs/configuration.md +300 -0
- package/agent-docs/express.md +124 -0
- package/agent-docs/fastify.md +123 -0
- package/agent-docs/hono.md +131 -0
- package/agent-docs/next.md +82 -0
- package/agent-docs/provider-azure-blob.md +85 -0
- package/agent-docs/provider-custom.md +281 -0
- package/agent-docs/provider-edgestore.md +53 -0
- package/agent-docs/provider-s3.md +270 -0
- package/agent-docs/remix.md +117 -0
- package/agent-docs/tanstack-start.md +99 -0
- package/agent-docs/troubleshooting.md +83 -0
- package/dist/adapters/astro/index.d.ts +2 -2
- package/dist/adapters/astro/index.d.ts.map +1 -1
- package/dist/adapters/astro/index.js +1 -2
- package/dist/adapters/dispatcher.d.ts +2 -3
- package/dist/adapters/dispatcher.d.ts.map +1 -1
- package/dist/adapters/dispatcher.js +17 -22
- package/dist/adapters/express/index.d.ts +2 -2
- package/dist/adapters/express/index.d.ts.map +1 -1
- package/dist/adapters/express/index.js +1 -5
- package/dist/adapters/fastify/index.d.ts +2 -2
- package/dist/adapters/fastify/index.d.ts.map +1 -1
- package/dist/adapters/fastify/index.js +1 -5
- package/dist/adapters/hono/index.d.ts +2 -2
- package/dist/adapters/hono/index.d.ts.map +1 -1
- package/dist/adapters/hono/index.js +1 -2
- package/dist/adapters/next/app/index.d.ts +2 -2
- package/dist/adapters/next/app/index.d.ts.map +1 -1
- package/dist/adapters/next/app/index.js +1 -2
- package/dist/adapters/next/pages/index.d.ts +2 -2
- package/dist/adapters/next/pages/index.d.ts.map +1 -1
- package/dist/adapters/next/pages/index.js +1 -5
- package/dist/adapters/remix/index.d.ts +2 -2
- package/dist/adapters/remix/index.d.ts.map +1 -1
- package/dist/adapters/remix/index.js +1 -2
- package/dist/adapters/shared.d.ts +45 -67
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/adapters/shared.js +60 -97
- package/dist/adapters/start/index.d.ts +2 -2
- package/dist/adapters/start/index.d.ts.map +1 -1
- package/dist/adapters/start/index.js +1 -2
- package/dist/core/client/bucketClient.d.ts +0 -1
- package/dist/core/client/bucketClient.d.ts.map +1 -1
- package/dist/core/client/bucketClient.js +6 -28
- package/dist/core/client/index.d.ts +29 -26
- package/dist/core/client/index.d.ts.map +1 -1
- package/dist/core/client/index.js +2 -3
- package/dist/core/index.d.ts +2 -20
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -13
- package/dist/core/provider.d.ts +11 -1
- package/dist/core/provider.d.ts.map +1 -1
- package/dist/core/provider.js +21 -1
- package/dist/core/router.d.ts +25 -0
- package/dist/core/router.d.ts.map +1 -0
- package/dist/core/router.js +49 -0
- package/dist/core/routerRules.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/providers/azure-blob/index.d.ts +7 -0
- package/dist/providers/azure-blob/index.d.ts.map +1 -1
- package/dist/providers/azure-blob/index.js +7 -0
- package/dist/providers/edgestore/index.d.ts +10 -11
- package/dist/providers/edgestore/index.d.ts.map +1 -1
- package/dist/providers/edgestore/index.js +26 -15
- package/dist/providers/s3/backendUpload.d.ts +13 -0
- package/dist/providers/s3/backendUpload.d.ts.map +1 -0
- package/dist/providers/s3/backendUpload.js +97 -0
- package/dist/providers/s3/index.d.ts +57 -93
- package/dist/providers/s3/index.d.ts.map +1 -1
- package/dist/providers/s3/index.js +241 -90
- package/dist/providers/s3/keys.d.ts +10 -0
- package/dist/providers/s3/keys.d.ts.map +1 -0
- package/dist/providers/s3/keys.js +40 -0
- package/dist/providers/s3/multipart.d.ts +25 -0
- package/dist/providers/s3/multipart.d.ts.map +1 -0
- package/dist/providers/s3/multipart.js +132 -0
- package/dist/providers/s3/objectHeaders.d.ts +4 -0
- package/dist/providers/s3/objectHeaders.d.ts.map +1 -0
- package/dist/providers/s3/objectHeaders.js +22 -0
- package/dist/providers/s3/options.d.ts +107 -0
- package/dist/providers/s3/options.d.ts.map +1 -0
- package/dist/version.d.ts +1 -1
- package/package.json +7 -5
- package/src/adapters/astro/index.ts +3 -4
- package/src/adapters/dispatcher.ts +21 -30
- package/src/adapters/express/index.ts +3 -9
- package/src/adapters/fastify/index.ts +3 -9
- package/src/adapters/hono/index.ts +3 -4
- package/src/adapters/next/app/index.ts +3 -4
- package/src/adapters/next/pages/index.ts +3 -9
- package/src/adapters/remix/index.ts +3 -4
- package/src/adapters/shared.ts +90 -163
- package/src/adapters/start/index.ts +3 -4
- package/src/core/client/bucketClient.ts +10 -41
- package/src/core/client/index.ts +32 -48
- package/src/core/index.ts +2 -36
- package/src/core/provider.ts +28 -5
- package/src/core/router.ts +97 -0
- package/src/index.ts +1 -3
- package/src/providers/azure-blob/index.ts +2 -0
- package/src/providers/edgestore/index.ts +28 -14
- package/src/providers/s3/backendUpload.ts +117 -0
- package/src/providers/s3/index.ts +302 -223
- package/src/providers/s3/keys.ts +59 -0
- package/src/providers/s3/multipart.ts +196 -0
- package/src/providers/s3/objectHeaders.ts +23 -0
- package/src/providers/s3/options.ts +125 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Quick Start
|
|
2
|
+
|
|
3
|
+
Source: https://next.edgestore.dev/docs/quick-start
|
|
4
|
+
|
|
5
|
+
### Install
|
|
6
|
+
|
|
7
|
+
Packages to install (use the application’s package manager):
|
|
8
|
+
|
|
9
|
+
```text
|
|
10
|
+
@edgestore/server @edgestore/react
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Environment Variables
|
|
14
|
+
|
|
15
|
+
Copy your project's keys from the [dashboard](https://dashboard.edgestore.dev/) to the backend env file:
|
|
16
|
+
|
|
17
|
+
Example: title=".env.local"
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
EDGE_STORE_ACCESS_KEY=your-access-key
|
|
21
|
+
EDGE_STORE_SECRET_KEY=your-secret-key
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
> WARNING
|
|
25
|
+
>
|
|
26
|
+
> Use the app's existing env file, or `.env.local` for a new app. Keep it gitignored.
|
|
27
|
+
|
|
28
|
+
### Backend
|
|
29
|
+
|
|
30
|
+
Choose your router below. This bucket's files are accessible to anyone with the link.
|
|
31
|
+
|
|
32
|
+
Example: tab="app" title="src/app/api/edgestore/\[...edgestore]/route.ts"
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { initEdgeStore } from '@edgestore/server';
|
|
36
|
+
import { createEdgeStoreNextHandler } from '@edgestore/server/adapters/next/app';
|
|
37
|
+
|
|
38
|
+
const es = initEdgeStore.create();
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* This is the main router for the EdgeStore buckets.
|
|
42
|
+
*/
|
|
43
|
+
const router = es.router({
|
|
44
|
+
publicFiles: es.fileBucket(),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const handler = createEdgeStoreNextHandler({
|
|
48
|
+
router,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
export { handler as GET, handler as POST };
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* This type is used to create the type-safe client for the frontend.
|
|
55
|
+
*/
|
|
56
|
+
export type EdgeStoreRouter = typeof router;
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Example: tab="pages" title="src/pages/api/edgestore/\[...edgestore].ts"
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { initEdgeStore } from '@edgestore/server';
|
|
63
|
+
import { createEdgeStoreNextHandler } from '@edgestore/server/adapters/next/pages';
|
|
64
|
+
|
|
65
|
+
const es = initEdgeStore.create();
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* This is the main router for the edgestore buckets.
|
|
69
|
+
*/
|
|
70
|
+
const router = es.router({
|
|
71
|
+
publicFiles: es.fileBucket(),
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
export default createEdgeStoreNextHandler({
|
|
75
|
+
router,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* This type is used to create the type-safe client for the frontend.
|
|
80
|
+
*/
|
|
81
|
+
export type EdgeStoreRouter = typeof router;
|
|
82
|
+
```
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Azure Blob Storage
|
|
2
|
+
|
|
3
|
+
Source: https://next.edgestore.dev/docs/providers/azure-blob
|
|
4
|
+
|
|
5
|
+
You can also use the EdgeStore package with your own Azure Blob Storage. You might want to do that in case you have strict company policies that require you to have all the data in your own Azure account.
|
|
6
|
+
|
|
7
|
+
The provider creates short-lived, blob-scoped SAS URLs for browser uploads and
|
|
8
|
+
private reads. Permanent file URLs never contain credentials. Advanced hosted
|
|
9
|
+
features such as image processing still require separate infrastructure.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
You need to install some peer dependencies to use this provider.
|
|
14
|
+
|
|
15
|
+
Packages to install (use the application’s package manager):
|
|
16
|
+
|
|
17
|
+
```text
|
|
18
|
+
@azure/storage-blob
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Chain `.provider()` when defining your router, then pass the router to the adapter.
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { initEdgeStore } from '@edgestore/server';
|
|
25
|
+
import {
|
|
26
|
+
createEdgeStoreNextHandler,
|
|
27
|
+
type CreateContextOptions,
|
|
28
|
+
} from '@edgestore/server/adapters/next/pages';
|
|
29
|
+
// [!code ++]
|
|
30
|
+
import { azureBlob } from '@edgestore/server/providers/azure-blob';
|
|
31
|
+
import { z } from 'zod';
|
|
32
|
+
|
|
33
|
+
// ...
|
|
34
|
+
|
|
35
|
+
const es = initEdgeStore.context<Context>().create();
|
|
36
|
+
const router = es.router({
|
|
37
|
+
publicFiles: es.fileBucket(),
|
|
38
|
+
}).provider(azureBlob());
|
|
39
|
+
|
|
40
|
+
export default createEdgeStoreNextHandler<Context>({
|
|
41
|
+
router,
|
|
42
|
+
createContext,
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Options
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
export type AzureBlobProviderOptions = {
|
|
50
|
+
/**
|
|
51
|
+
* The storage account name for Azure Blob Storage
|
|
52
|
+
* Can also be set via the `ES_AZURE_ACCOUNT_NAME` environment variable.
|
|
53
|
+
*/
|
|
54
|
+
storageAccountName?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Account key used for server-side requests and signing short-lived URLs.
|
|
57
|
+
* Can also be set via the `ES_AZURE_ACCOUNT_KEY` environment variable.
|
|
58
|
+
*/
|
|
59
|
+
storageAccountKey?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Azure Blob Storage container name
|
|
62
|
+
* Can also be set via the `ES_AZURE_CONTAINER_NAME` environment variable.
|
|
63
|
+
*/
|
|
64
|
+
containerName?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Optional base URL for Azurite or another compatible endpoint.
|
|
67
|
+
* Can also be set via the `ES_AZURE_BASE_URL` environment variable.
|
|
68
|
+
*/
|
|
69
|
+
customBaseUrl?: string;
|
|
70
|
+
/**
|
|
71
|
+
* Lifetime of browser upload URLs in seconds.
|
|
72
|
+
* @default 3600
|
|
73
|
+
*/
|
|
74
|
+
uploadUrlExpiresIn?: number;
|
|
75
|
+
/**
|
|
76
|
+
* Default lifetime of private read URLs in seconds.
|
|
77
|
+
* @default 3600
|
|
78
|
+
*/
|
|
79
|
+
signedUrlExpiresIn?: number;
|
|
80
|
+
};
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The account key stays on the server. Upload URLs receive only create/write
|
|
84
|
+
permissions, while private read URLs receive only read permission and expire
|
|
85
|
+
independently.
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
# Custom
|
|
2
|
+
|
|
3
|
+
Source: https://next.edgestore.dev/docs/providers/custom
|
|
4
|
+
|
|
5
|
+
Use `defineProvider` to integrate another storage service or a custom storage
|
|
6
|
+
implementation. The same provider instance powers the EdgeStore HTTP handler
|
|
7
|
+
and the router-derived backend client:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const router = es.router({
|
|
11
|
+
files: es.fileBucket(),
|
|
12
|
+
}).provider(myProvider);
|
|
13
|
+
|
|
14
|
+
createEdgeStoreNextHandler({ router });
|
|
15
|
+
router.client.files.get({ key: 'files/report.pdf' });
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Method inputs are contextually typed. File references, cursors, returned file
|
|
19
|
+
fields, and provider-specific errors are inferred from the definition, so you
|
|
20
|
+
do not need to maintain a parallel provider interface or backend-operation
|
|
21
|
+
map.
|
|
22
|
+
|
|
23
|
+
## Minimal provider
|
|
24
|
+
|
|
25
|
+
A provider must implement the upload-planning operations used by browser
|
|
26
|
+
uploads and `files.get`, which EdgeStore uses to resolve a file before running
|
|
27
|
+
router lifecycle hooks. Other operations are optional and only appear on the
|
|
28
|
+
backend client when implemented.
|
|
29
|
+
|
|
30
|
+
This single-part example delegates storage-specific work to a small driver:
|
|
31
|
+
|
|
32
|
+
Example: title="src/lib/my-provider.ts"
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { defineProvider } from '@edgestore/server';
|
|
36
|
+
import { z } from 'zod';
|
|
37
|
+
import { storage } from './storage';
|
|
38
|
+
|
|
39
|
+
const baseUrl = 'https://files.example.com';
|
|
40
|
+
|
|
41
|
+
export const myProvider = defineProvider({
|
|
42
|
+
name: 'my-storage',
|
|
43
|
+
baseUrl,
|
|
44
|
+
async init() {
|
|
45
|
+
return {};
|
|
46
|
+
},
|
|
47
|
+
reference: {
|
|
48
|
+
schema: z.object({ key: z.string().min(1) }),
|
|
49
|
+
fromUrl(url) {
|
|
50
|
+
return { key: new URL(url).pathname.slice(1) };
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
uploads: {
|
|
54
|
+
async request({ bucketName, fileInfo }) {
|
|
55
|
+
const key = storage.createKey({ bucketName, fileInfo });
|
|
56
|
+
return {
|
|
57
|
+
uploadUrl: await storage.signUpload(key),
|
|
58
|
+
accessUrl: `${baseUrl}/${key}`,
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
files: {
|
|
63
|
+
async get({ bucketName, file }) {
|
|
64
|
+
const object = await storage.head({
|
|
65
|
+
bucketName,
|
|
66
|
+
key: file.key,
|
|
67
|
+
});
|
|
68
|
+
return {
|
|
69
|
+
url: `${baseUrl}/${file.key}`,
|
|
70
|
+
sizeBytes: object.size,
|
|
71
|
+
path: object.path,
|
|
72
|
+
metadata: object.metadata,
|
|
73
|
+
uploadedAt: object.createdAt,
|
|
74
|
+
updatedAt: object.updatedAt,
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
The resulting backend client exposes `get`, but not `upload`, `list`, or
|
|
82
|
+
mutations, because those optional capabilities were not defined.
|
|
83
|
+
|
|
84
|
+
## Complete provider
|
|
85
|
+
|
|
86
|
+
A complete provider can add direct backend uploads, pagination, mutations, and
|
|
87
|
+
signed read URLs. Standard Schema transformations let callers use convenient
|
|
88
|
+
input references while provider methods receive one normalized output shape:
|
|
89
|
+
|
|
90
|
+
Example: title="src/lib/my-provider.ts"
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
import { defineProvider } from '@edgestore/server';
|
|
94
|
+
import { z } from 'zod';
|
|
95
|
+
import { storage } from './storage';
|
|
96
|
+
|
|
97
|
+
const baseUrl = 'https://files.example.com';
|
|
98
|
+
const referenceSchema = z
|
|
99
|
+
.union([z.string().url(), z.object({ key: z.string().min(1) })])
|
|
100
|
+
.transform((reference) =>
|
|
101
|
+
typeof reference === 'string'
|
|
102
|
+
? { key: new URL(reference).pathname.slice(1) }
|
|
103
|
+
: reference,
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
const toFile = (object: Awaited<ReturnType<typeof storage.head>>) => ({
|
|
107
|
+
url: `${baseUrl}/${object.key}`,
|
|
108
|
+
sizeBytes: object.size,
|
|
109
|
+
path: object.path,
|
|
110
|
+
metadata: object.metadata,
|
|
111
|
+
uploadedAt: object.createdAt,
|
|
112
|
+
updatedAt: object.updatedAt,
|
|
113
|
+
etag: object.etag,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
export const myProvider = defineProvider({
|
|
117
|
+
name: 'my-storage',
|
|
118
|
+
baseUrl,
|
|
119
|
+
async init() {
|
|
120
|
+
return {};
|
|
121
|
+
},
|
|
122
|
+
reference: {
|
|
123
|
+
schema: referenceSchema,
|
|
124
|
+
fromUrl: (url) => url,
|
|
125
|
+
},
|
|
126
|
+
uploads: {
|
|
127
|
+
async request({ bucketName, fileInfo }) {
|
|
128
|
+
return storage.createUploadPlan({ bucketName, fileInfo });
|
|
129
|
+
},
|
|
130
|
+
multipart: {
|
|
131
|
+
async requestParts({ uploadId, key, parts }) {
|
|
132
|
+
return { parts: await storage.signUploadParts({ uploadId, key, parts }) };
|
|
133
|
+
},
|
|
134
|
+
async complete({ uploadId, key, parts }) {
|
|
135
|
+
await storage.completeMultipart({ uploadId, key, parts });
|
|
136
|
+
},
|
|
137
|
+
async abort({ uploadId, key }) {
|
|
138
|
+
await storage.abortMultipart({ uploadId, key });
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
async upload({ bucketName, fileInfo, source, signal, onProgress }) {
|
|
142
|
+
const object = await storage.upload({
|
|
143
|
+
bucketName,
|
|
144
|
+
fileInfo,
|
|
145
|
+
source,
|
|
146
|
+
signal,
|
|
147
|
+
onProgress,
|
|
148
|
+
});
|
|
149
|
+
return { file: toFile(object) };
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
files: {
|
|
153
|
+
cursorSchema: z.string().min(1),
|
|
154
|
+
async get({ bucketName, file }) {
|
|
155
|
+
return toFile(
|
|
156
|
+
await storage.head({
|
|
157
|
+
bucketName,
|
|
158
|
+
key: file.key,
|
|
159
|
+
}),
|
|
160
|
+
);
|
|
161
|
+
},
|
|
162
|
+
async list({ bucketName, cursor, filter, limit = 20 }) {
|
|
163
|
+
const page = await storage.list({ bucketName, cursor, filter, limit });
|
|
164
|
+
return {
|
|
165
|
+
items: page.objects.map(toFile),
|
|
166
|
+
limit,
|
|
167
|
+
nextCursor: page.nextCursor,
|
|
168
|
+
hasMore: page.nextCursor !== null,
|
|
169
|
+
};
|
|
170
|
+
},
|
|
171
|
+
async confirm({ bucketName, files }) {
|
|
172
|
+
return {
|
|
173
|
+
results: await storage.confirm({
|
|
174
|
+
bucketName,
|
|
175
|
+
files,
|
|
176
|
+
}),
|
|
177
|
+
};
|
|
178
|
+
},
|
|
179
|
+
async delete({ bucketName, files }) {
|
|
180
|
+
return {
|
|
181
|
+
results: await storage.delete({
|
|
182
|
+
bucketName,
|
|
183
|
+
files,
|
|
184
|
+
}),
|
|
185
|
+
};
|
|
186
|
+
},
|
|
187
|
+
async restore({ bucketName, files }) {
|
|
188
|
+
return {
|
|
189
|
+
results: await storage.restore({
|
|
190
|
+
bucketName,
|
|
191
|
+
files,
|
|
192
|
+
}),
|
|
193
|
+
};
|
|
194
|
+
},
|
|
195
|
+
async getSignedUrls({ bucketName, files, expiresIn = 3600 }) {
|
|
196
|
+
return Promise.all(
|
|
197
|
+
files.map(async (file) => ({
|
|
198
|
+
url: `${baseUrl}/${file.key}`,
|
|
199
|
+
signedUrl: await storage.signRead({
|
|
200
|
+
bucketName,
|
|
201
|
+
key: file.key,
|
|
202
|
+
expiresIn,
|
|
203
|
+
}),
|
|
204
|
+
expiresAt: new Date(Date.now() + expiresIn * 1000),
|
|
205
|
+
expiresIn,
|
|
206
|
+
})),
|
|
207
|
+
);
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Here, callers may pass either a URL or `{ key }`, but every provider operation
|
|
214
|
+
receives `{ key: string }` after runtime validation. The backend client also
|
|
215
|
+
inherits the string cursor, the extra `etag` file field, and any literal
|
|
216
|
+
mutation error codes returned by the storage driver.
|
|
217
|
+
|
|
218
|
+
The backend client uses bucket-scoped names: `get`, `list`, `confirm`,
|
|
219
|
+
`confirmMany`, `delete`, `deleteMany`, `restore`, `restoreMany`,
|
|
220
|
+
`createSignedUrl`, and `createSignedUrls`. Provider method names remain
|
|
221
|
+
resource operations (`files.get`, `files.list`, `files.getSignedUrls`) and do
|
|
222
|
+
not need to mirror that public client surface.
|
|
223
|
+
|
|
224
|
+
`get` and `list` preserve the exact file fields inferred from the provider,
|
|
225
|
+
including its `path` and `metadata` shapes. An `upload` result instead exposes
|
|
226
|
+
the path and metadata EdgeStore computed from the router, even if the storage
|
|
227
|
+
driver returns different placeholders.
|
|
228
|
+
|
|
229
|
+
Every file operation must enforce the logical EdgeStore `bucketName`. Treat
|
|
230
|
+
`bucketName` and the normalized file reference as the complete storage
|
|
231
|
+
identity, and reject a reference that belongs to another logical bucket. This
|
|
232
|
+
keeps a frontend request authorized through bucket A from loading or mutating a
|
|
233
|
+
file in bucket B. The official providers enforce the same ownership invariant.
|
|
234
|
+
|
|
235
|
+
Mutation providers return exactly one status for each input file, in the same
|
|
236
|
+
order. EdgeStore attaches the original file references and derives success and
|
|
237
|
+
failure counts for the public client. A provider result therefore contains
|
|
238
|
+
only `{ success: true }` or `{ success: false, error }`; it does not repeat the
|
|
239
|
+
file reference or calculate counts.
|
|
240
|
+
|
|
241
|
+
Multipart support is optional. A single-part provider defines only
|
|
242
|
+
`uploads.request`. When `uploads.multipart` is present, `uploads.request` may
|
|
243
|
+
return a multipart plan and EdgeStore exposes the matching part-request,
|
|
244
|
+
completion, and cancellation routes. The plan only needs signed URLs for the
|
|
245
|
+
first parts: the browser requests the rest through `requestParts` in batches as
|
|
246
|
+
it reaches them, and requests a fresh URL once when storage rejects one. The
|
|
247
|
+
browser calls `abort` after a failed or canceled transfer. Cleanup is best
|
|
248
|
+
effort, so storage lifecycle rules should still remove abandoned uploads.
|
|
249
|
+
|
|
250
|
+
A single-part plan can include `uploadHeaders`. The browser sends them with the
|
|
251
|
+
upload request, which lets a provider sign headers such as `Content-Type` or
|
|
252
|
+
storage metadata into the URL.
|
|
253
|
+
|
|
254
|
+
Set `uploads.supportedOptions` to reject upload options your storage cannot
|
|
255
|
+
honor. For example, `supportedOptions: { temporary: false }` removes
|
|
256
|
+
`temporary` from the browser and backend upload types, and EdgeStore rejects it
|
|
257
|
+
at runtime before calling the provider.
|
|
258
|
+
|
|
259
|
+
`uploads.request` and `uploads.upload` remain separate because they perform
|
|
260
|
+
different work: the former creates signed instructions for a browser transfer,
|
|
261
|
+
while the latter receives bytes and performs a privileged server-side upload.
|
|
262
|
+
|
|
263
|
+
## Operation groups
|
|
264
|
+
|
|
265
|
+
The provider is organized by storage resource, not by caller:
|
|
266
|
+
|
|
267
|
+
* `uploads` contains browser upload planning and optional direct backend
|
|
268
|
+
upload.
|
|
269
|
+
* `files` contains canonical file operations shared by HTTP adapters and the
|
|
270
|
+
backend client.
|
|
271
|
+
* `reference` defines how frontend URLs and backend inputs become the
|
|
272
|
+
provider's normalized file reference.
|
|
273
|
+
|
|
274
|
+
Frontend deletion still obeys the router: EdgeStore loads every file and runs
|
|
275
|
+
`beforeDelete` for all of them before calling `files.delete`. The privileged
|
|
276
|
+
backend client calls `files.delete` directly and is responsible for its own
|
|
277
|
+
authorization.
|
|
278
|
+
|
|
279
|
+
The official EdgeStore, S3, and Azure Blob providers use `defineProvider`
|
|
280
|
+
themselves and are useful reference implementations. If your provider could be
|
|
281
|
+
useful to others, consider contributing it to EdgeStore.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# EdgeStore
|
|
2
|
+
|
|
3
|
+
Source: https://next.edgestore.dev/docs/providers/edgestore
|
|
4
|
+
|
|
5
|
+
The hosted EdgeStore provider uses API v2 and is the default for `es.router()`.
|
|
6
|
+
No provider configuration is needed when using environment credentials. Chain
|
|
7
|
+
`.provider(edgestore(options))` to supply custom credentials or an API URL.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { initEdgeStore } from '@edgestore/server';
|
|
11
|
+
import {
|
|
12
|
+
createEdgeStoreNextHandler,
|
|
13
|
+
type CreateContextOptions,
|
|
14
|
+
} from '@edgestore/server/adapters/next/pages';
|
|
15
|
+
// [!code ++]
|
|
16
|
+
import { edgestore } from '@edgestore/server/providers/edgestore';
|
|
17
|
+
import { z } from 'zod';
|
|
18
|
+
|
|
19
|
+
const es = initEdgeStore.context<Context>().create();
|
|
20
|
+
const router = es.router({
|
|
21
|
+
publicFiles: es.fileBucket(),
|
|
22
|
+
}).provider(edgestore());
|
|
23
|
+
|
|
24
|
+
export default createEdgeStoreNextHandler<Context>({
|
|
25
|
+
router,
|
|
26
|
+
createContext,
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Options
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
export type EdgeStoreProviderOptions = {
|
|
34
|
+
/**
|
|
35
|
+
* Access key for your EdgeStore project.
|
|
36
|
+
* Can be found in the EdgeStore dashboard.
|
|
37
|
+
*
|
|
38
|
+
* This can be omitted if the `EDGE_STORE_ACCESS_KEY` environment variable is set.
|
|
39
|
+
*/
|
|
40
|
+
accessKey?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Secret key for your EdgeStore project.
|
|
43
|
+
* Can be found in the EdgeStore dashboard.
|
|
44
|
+
*
|
|
45
|
+
* This can be omitted if the `EDGE_STORE_SECRET_KEY` environment variable is set.
|
|
46
|
+
*/
|
|
47
|
+
secretKey?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Override the API v2 base URL.
|
|
50
|
+
*/
|
|
51
|
+
apiUrl?: string;
|
|
52
|
+
};
|
|
53
|
+
```
|