@edgestore/server 1.0.0-next.5 → 1.0.0-rc.6

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.
Files changed (79) hide show
  1. package/agent-docs/README.md +1 -1
  2. package/agent-docs/astro.md +1 -1
  3. package/agent-docs/backend-client.md +5 -8
  4. package/agent-docs/express.md +1 -1
  5. package/agent-docs/fastify.md +1 -1
  6. package/agent-docs/hono.md +1 -1
  7. package/agent-docs/next.md +1 -1
  8. package/agent-docs/provider-azure-blob.md +150 -57
  9. package/agent-docs/provider-custom.md +17 -3
  10. package/agent-docs/provider-s3.md +4 -3
  11. package/agent-docs/remix.md +1 -1
  12. package/agent-docs/tanstack-start.md +1 -1
  13. package/dist/adapters/shared.d.ts +12 -102
  14. package/dist/adapters/shared.d.ts.map +1 -1
  15. package/dist/adapters/shared.js +63 -108
  16. package/dist/core/client/index.d.ts +0 -4
  17. package/dist/core/client/index.d.ts.map +1 -1
  18. package/dist/core/provider.d.ts +0 -1
  19. package/dist/core/provider.d.ts.map +1 -1
  20. package/dist/core/provider.js +1 -4
  21. package/dist/index.d.ts +3 -1
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +2 -1
  24. package/dist/providers/azure-blob/blocks.d.ts +48 -0
  25. package/dist/providers/azure-blob/blocks.d.ts.map +1 -0
  26. package/dist/providers/azure-blob/blocks.js +126 -0
  27. package/dist/providers/azure-blob/index.d.ts +76 -51
  28. package/dist/providers/azure-blob/index.d.ts.map +1 -1
  29. package/dist/providers/azure-blob/index.js +189 -107
  30. package/dist/providers/edgestore/index.d.ts +6 -22
  31. package/dist/providers/edgestore/index.d.ts.map +1 -1
  32. package/dist/providers/edgestore/index.js +19 -18
  33. package/dist/providers/s3/backendUpload.d.ts +2 -5
  34. package/dist/providers/s3/backendUpload.d.ts.map +1 -1
  35. package/dist/providers/s3/backendUpload.js +19 -57
  36. package/dist/providers/s3/index.d.ts +3 -12
  37. package/dist/providers/s3/index.d.ts.map +1 -1
  38. package/dist/providers/s3/index.js +23 -44
  39. package/dist/providers/s3/multipart.d.ts +3 -5
  40. package/dist/providers/s3/multipart.d.ts.map +1 -1
  41. package/dist/providers/s3/multipart.js +26 -62
  42. package/dist/providers/s3/options.d.ts +10 -32
  43. package/dist/providers/s3/options.d.ts.map +1 -1
  44. package/dist/providers/storage/multipartSession.d.ts +51 -0
  45. package/dist/providers/storage/multipartSession.d.ts.map +1 -0
  46. package/dist/providers/storage/multipartSession.js +83 -0
  47. package/dist/providers/storage/objectKeys.d.ts +41 -0
  48. package/dist/providers/storage/objectKeys.d.ts.map +1 -0
  49. package/dist/providers/{s3/keys.js → storage/objectKeys.js} +31 -4
  50. package/dist/providers/storage/transfer.d.ts +18 -0
  51. package/dist/providers/storage/transfer.d.ts.map +1 -0
  52. package/dist/providers/storage/transfer.js +69 -0
  53. package/dist/version.d.ts +1 -1
  54. package/dist/version.d.ts.map +1 -1
  55. package/package.json +4 -11
  56. package/src/adapters/shared.ts +81 -127
  57. package/src/core/client/index.ts +0 -4
  58. package/src/core/provider.ts +0 -8
  59. package/src/index.ts +3 -8
  60. package/src/providers/azure-blob/blocks.ts +201 -0
  61. package/src/providers/azure-blob/index.ts +289 -171
  62. package/src/providers/edgestore/index.ts +19 -22
  63. package/src/providers/s3/backendUpload.ts +20 -55
  64. package/src/providers/s3/index.ts +31 -58
  65. package/src/providers/s3/multipart.ts +36 -94
  66. package/src/providers/s3/options.ts +10 -33
  67. package/src/providers/storage/multipartSession.ts +145 -0
  68. package/src/providers/storage/objectKeys.ts +106 -0
  69. package/src/providers/storage/transfer.ts +105 -0
  70. package/src/version.ts +1 -1
  71. package/core/index.d.ts +0 -1
  72. package/core/index.js +0 -1
  73. package/dist/core/index.d.ts +0 -4
  74. package/dist/core/index.d.ts.map +0 -1
  75. package/dist/core/index.js +0 -3
  76. package/dist/providers/s3/keys.d.ts +0 -10
  77. package/dist/providers/s3/keys.d.ts.map +0 -1
  78. package/src/core/index.ts +0 -9
  79. package/src/providers/s3/keys.ts +0 -59
@@ -0,0 +1,106 @@
1
+ import type { MaybePromise, RequestUploadParams } from '@edgestore/shared';
2
+
3
+ export type ObjectPathFnArgs = {
4
+ /** Logical EdgeStore router bucket name. */
5
+ edgestoreBucketName: string;
6
+ /** File info after EdgeStore path and metadata generation. */
7
+ fileInfo: RequestUploadParams['fileInfo'];
8
+ /** Default object path relative to the logical bucket prefix. */
9
+ defaultPath: string;
10
+ };
11
+
12
+ /** Returns an object path relative to the logical bucket prefix. */
13
+ export type ObjectPathFn = (args: ObjectPathFnArgs) => MaybePromise<string>;
14
+
15
+ export function createObjectKeys(providerName: string, baseUrl: string) {
16
+ const normalizedBaseUrl = baseUrl.replace(/\/+$/, '');
17
+
18
+ function objectKeyToUrl(objectKey: string) {
19
+ const encodedKey = objectKey
20
+ .split('/')
21
+ .map((segment) => encodeURIComponent(segment))
22
+ .join('/');
23
+ return `${normalizedBaseUrl}/${encodedKey}`;
24
+ }
25
+
26
+ function urlToObjectKey(url: string) {
27
+ try {
28
+ const fileUrl = new URL(url);
29
+ const providerUrl = new URL(`${normalizedBaseUrl}/`);
30
+ if (
31
+ fileUrl.origin !== providerUrl.origin ||
32
+ !fileUrl.pathname.startsWith(providerUrl.pathname)
33
+ ) {
34
+ throw new Error();
35
+ }
36
+ return decodeURIComponent(
37
+ fileUrl.pathname.slice(providerUrl.pathname.length),
38
+ );
39
+ } catch {
40
+ throw new Error(
41
+ `File URL does not belong to this ${providerName} provider.`,
42
+ );
43
+ }
44
+ }
45
+
46
+ function normalizeRelativePath(value: string) {
47
+ const path = value.replace(/^\/+|\/+$/g, '');
48
+ if (
49
+ path.length === 0 ||
50
+ path.split('/').some((segment) => segment === '.' || segment === '..')
51
+ ) {
52
+ throw new Error(
53
+ `${providerName} paths must stay within the EdgeStore bucket prefix.`,
54
+ );
55
+ }
56
+ return path;
57
+ }
58
+
59
+ /** Keys from both URLs and key references must stay inside the logical bucket. */
60
+ function fromReference(
61
+ bucketName: string,
62
+ file: { url: string } | { key: string },
63
+ ) {
64
+ const key = 'url' in file ? urlToObjectKey(file.url) : file.key;
65
+ if (
66
+ normalizeRelativePath(key) !== key ||
67
+ !key.startsWith(`${bucketName}/`)
68
+ ) {
69
+ throw new Error(
70
+ `File does not belong to EdgeStore bucket "${bucketName}".`,
71
+ );
72
+ }
73
+ return key;
74
+ }
75
+
76
+ /**
77
+ * Resolves the object key for an upload. The logical bucket is always the
78
+ * first key segment, so router authorization for one bucket cannot reach
79
+ * objects from another.
80
+ */
81
+ async function forUpload(
82
+ edgestoreBucketName: string,
83
+ fileInfo: RequestUploadParams['fileInfo'],
84
+ path?: ObjectPathFn,
85
+ ) {
86
+ const extension = fileInfo.extension
87
+ ? `.${fileInfo.extension.replace(/^\./, '')}`
88
+ : '';
89
+ const defaultPath = [
90
+ ...(fileInfo.isPublic ? ['_public'] : []),
91
+ ...fileInfo.path.map((part) => part.value),
92
+ fileInfo.fileName ?? `${crypto.randomUUID()}${extension}`,
93
+ ].join('/');
94
+ const relativePath = normalizeRelativePath(
95
+ path
96
+ ? await path({ edgestoreBucketName, fileInfo, defaultPath })
97
+ : defaultPath,
98
+ );
99
+ return {
100
+ key: `${edgestoreBucketName}/${relativePath}`,
101
+ pathArgs: { edgestoreBucketName, fileInfo, defaultPath },
102
+ };
103
+ }
104
+
105
+ return { toUrl: objectKeyToUrl, fromReference, forUpload };
106
+ }
@@ -0,0 +1,105 @@
1
+ import { DEFAULT_MULTIPART_CONCURRENCY } from '@edgestore/sdk';
2
+ import type {
3
+ AnyContext,
4
+ BackendUploadParams,
5
+ EdgeStoreRouter,
6
+ } from '@edgestore/shared';
7
+
8
+ /** Validates a signed URL lifetime against the storage service's maximum. */
9
+ export function signedUrlLifetime(
10
+ providerName: string,
11
+ value: number,
12
+ maxSeconds = 604800,
13
+ ) {
14
+ if (!Number.isInteger(value) || value < 1 || value > maxSeconds) {
15
+ throw new RangeError(
16
+ `${providerName} signed URL expiration must be an integer between 1 and ${maxSeconds} seconds.`,
17
+ );
18
+ }
19
+ return value;
20
+ }
21
+
22
+ /**
23
+ * Direct-storage providers authorize private reads with backend-issued signed
24
+ * URLs. Cookie-based rules would silently not be enforced, so reject them.
25
+ */
26
+ export function assertSignedUrlAccessControl<TCtx extends AnyContext>(
27
+ providerName: string,
28
+ router: EdgeStoreRouter<TCtx>,
29
+ ) {
30
+ for (const bucket of Object.values(router.buckets)) {
31
+ const { accessControl } = bucket._def;
32
+ if (accessControl !== undefined && accessControl !== 'private') {
33
+ throw new Error(
34
+ `${providerName} supports accessControl("private") with backend signed URLs, not cookie-based access-control rules.`,
35
+ );
36
+ }
37
+ }
38
+ }
39
+
40
+ /** Reports cumulative backend upload progress. */
41
+ export function createProgress(
42
+ totalBytes: number,
43
+ onProgress: BackendUploadParams['onProgress'],
44
+ ) {
45
+ let transferredBytes = 0;
46
+ const report = (bytes: number) => {
47
+ transferredBytes += bytes;
48
+ onProgress?.({
49
+ transferredBytes,
50
+ totalBytes,
51
+ percentage: totalBytes ? (transferredBytes / totalBytes) * 100 : 100,
52
+ phase: 'uploading',
53
+ });
54
+ };
55
+ report(0);
56
+ return report;
57
+ }
58
+
59
+ /**
60
+ * Runs tasks a few at a time to bound memory use. The first failure, or
61
+ * the caller's signal, stops the remaining parts before the error is thrown.
62
+ */
63
+ export async function runConcurrently<TItem, TResult>(
64
+ items: TItem[],
65
+ signal: AbortSignal | undefined,
66
+ task: (item: TItem, signal: AbortSignal) => Promise<TResult>,
67
+ ) {
68
+ const controller = new AbortController();
69
+ const partSignal = signal
70
+ ? AbortSignal.any([signal, controller.signal])
71
+ : controller.signal;
72
+ const results = new Array<TResult>(items.length);
73
+ let next = 0;
74
+ const workers = Array.from(
75
+ { length: Math.min(DEFAULT_MULTIPART_CONCURRENCY, items.length) },
76
+ async () => {
77
+ while (next < items.length) {
78
+ partSignal.throwIfAborted();
79
+ const index = next++;
80
+ results[index] = await task(items[index]!, partSignal);
81
+ }
82
+ },
83
+ );
84
+ try {
85
+ await Promise.all(workers);
86
+ } catch (error) {
87
+ controller.abort(error);
88
+ await Promise.allSettled(workers);
89
+ throw signal?.aborted ? signal.reason : error;
90
+ }
91
+ signal?.throwIfAborted();
92
+ return results;
93
+ }
94
+
95
+ /** Reads one part of the source into memory. */
96
+ export async function readPart(
97
+ source: Blob,
98
+ partNumber: number,
99
+ partSizeBytes: number,
100
+ ) {
101
+ const start = (partNumber - 1) * partSizeBytes;
102
+ return new Uint8Array(
103
+ await source.slice(start, start + partSizeBytes).arrayBuffer(),
104
+ );
105
+ }
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export const EDGE_STORE_PACKAGE_NAME = '@edgestore/server';
2
- export const EDGE_STORE_PACKAGE_VERSION = '1.0.0-next.5';
2
+ export const EDGE_STORE_PACKAGE_VERSION = '1.0.0-rc.6';
package/core/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from '../dist/core/index.js';
package/core/index.js DELETED
@@ -1 +0,0 @@
1
- export * from '../dist/core/index.js';
@@ -1,4 +0,0 @@
1
- export type * from './client/index.js';
2
- export { EdgeStoreFileMutationError } from './client/index.js';
3
- export { defineProvider, getProviderBaseUrl, referenceFromUrl, validateProviderCursor, validateProviderReference, } from './provider.js';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,UAAU,CAAC;AAC9B,OAAO,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,YAAY,CAAC"}
@@ -1,3 +0,0 @@
1
- export { EdgeStoreFileMutationError } from '@edgestore/sdk';
2
- export { defineProvider, getProviderBaseUrl, referenceFromUrl, validateProviderCursor, validateProviderReference } from './provider.js';
3
- import '@edgestore/shared';
@@ -1,10 +0,0 @@
1
- export declare function createObjectKeys(baseUrl: string): {
2
- toUrl: (objectKey: string) => string;
3
- fromReference: (bucketName: string, file: {
4
- url: string;
5
- } | {
6
- key: string;
7
- }) => string;
8
- normalizeRelativePath: (value: string) => string;
9
- };
10
- //# sourceMappingURL=keys.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../../src/providers/s3/keys.ts"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM;uBAGX,MAAM;gCAuC3B,MAAM,QACZ;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE;mCAdH,MAAM;EA6B7C"}
package/src/core/index.ts DELETED
@@ -1,9 +0,0 @@
1
- export type * from './client';
2
- export { EdgeStoreFileMutationError } from './client';
3
- export {
4
- defineProvider,
5
- getProviderBaseUrl,
6
- referenceFromUrl,
7
- validateProviderCursor,
8
- validateProviderReference,
9
- } from './provider';
@@ -1,59 +0,0 @@
1
- export function createObjectKeys(baseUrl: string) {
2
- const normalizedBaseUrl = baseUrl.replace(/\/+$/, '');
3
-
4
- function objectKeyToUrl(objectKey: string) {
5
- const encodedKey = objectKey
6
- .split('/')
7
- .map((segment) => encodeURIComponent(segment))
8
- .join('/');
9
- return `${normalizedBaseUrl}/${encodedKey}`;
10
- }
11
-
12
- function urlToObjectKey(url: string) {
13
- try {
14
- const fileUrl = new URL(url);
15
- const providerUrl = new URL(`${normalizedBaseUrl}/`);
16
- if (
17
- fileUrl.origin !== providerUrl.origin ||
18
- !fileUrl.pathname.startsWith(providerUrl.pathname)
19
- ) {
20
- throw new Error();
21
- }
22
- return decodeURIComponent(
23
- fileUrl.pathname.slice(providerUrl.pathname.length),
24
- );
25
- } catch {
26
- throw new Error('File URL does not belong to this S3 provider.');
27
- }
28
- }
29
-
30
- function normalizeRelativePath(value: string) {
31
- const path = value.replace(/^\/+|\/+$/g, '');
32
- if (
33
- path.length === 0 ||
34
- path.split('/').some((segment) => segment === '.' || segment === '..')
35
- ) {
36
- throw new Error('S3 paths must stay within the EdgeStore bucket prefix.');
37
- }
38
- return path;
39
- }
40
-
41
- /** Keys from both URLs and key references must stay inside the logical bucket. */
42
- function fromReference(
43
- bucketName: string,
44
- file: { url: string } | { key: string },
45
- ) {
46
- const key = 'url' in file ? urlToObjectKey(file.url) : file.key;
47
- if (
48
- normalizeRelativePath(key) !== key ||
49
- !key.startsWith(`${bucketName}/`)
50
- ) {
51
- throw new Error(
52
- `File does not belong to EdgeStore bucket "${bucketName}".`,
53
- );
54
- }
55
- return key;
56
- }
57
-
58
- return { toUrl: objectKeyToUrl, fromReference, normalizeRelativePath };
59
- }