@edgestore/shared 0.0.0-canary-20260730114359
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/LICENSE +21 -0
- package/README.md +1 -0
- package/dist/errors/EdgeStoreError.d.ts +47 -0
- package/dist/errors/EdgeStoreError.d.ts.map +1 -0
- package/dist/errors/EdgeStoreError.js +43 -0
- package/dist/errors/index.d.ts +9 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +20 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/internals/bucketBuilder.d.ts +315 -0
- package/dist/internals/bucketBuilder.d.ts.map +1 -0
- package/dist/internals/bucketBuilder.js +230 -0
- package/dist/internals/createPathParamProxy.d.ts +21 -0
- package/dist/internals/createPathParamProxy.d.ts.map +1 -0
- package/dist/internals/createPathParamProxy.js +29 -0
- package/dist/internals/providerCapabilities.d.ts +44 -0
- package/dist/internals/providerCapabilities.d.ts.map +1 -0
- package/dist/internals/providerTypes.d.ts +270 -0
- package/dist/internals/providerTypes.d.ts.map +1 -0
- package/dist/internals/sharedFuncTypes.d.ts +30 -0
- package/dist/internals/sharedFuncTypes.d.ts.map +1 -0
- package/dist/internals/types.d.ts +47 -0
- package/dist/internals/types.d.ts.map +1 -0
- package/dist/types.d.ts +94 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +81 -0
- package/src/errors/EdgeStoreError.ts +89 -0
- package/src/errors/index.ts +14 -0
- package/src/index.ts +7 -0
- package/src/internals/bucketBuilder.ts +677 -0
- package/src/internals/createPathParamProxy.ts +40 -0
- package/src/internals/providerCapabilities.ts +126 -0
- package/src/internals/providerTypes.ts +388 -0
- package/src/internals/sharedFuncTypes.ts +38 -0
- package/src/internals/types.ts +52 -0
- package/src/types.ts +146 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type MaybePromise } from '../types.js';
|
|
2
|
+
export type ClientUploadTransform = (params: {
|
|
3
|
+
file: File;
|
|
4
|
+
extension: string;
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
}) => MaybePromise<File | Blob | {
|
|
7
|
+
file: File | Blob;
|
|
8
|
+
extension: string;
|
|
9
|
+
}>;
|
|
10
|
+
export type UploadOptions = {
|
|
11
|
+
/**
|
|
12
|
+
* e.g. 'my-file-name.jpg'
|
|
13
|
+
*
|
|
14
|
+
* By default, a unique file name will be generated for each upload.
|
|
15
|
+
* If you want to use a custom file name, you can use this option.
|
|
16
|
+
* If you use the same file name for multiple uploads, the previous file will be overwritten.
|
|
17
|
+
* But it might take some time for the CDN cache to be cleared.
|
|
18
|
+
* So maybe you will keep seeing the old file for a while.
|
|
19
|
+
*
|
|
20
|
+
* If you want to replace an existing file, immediately leave the `manualFileName` option empty and use the `replaceTargetUrl` option.
|
|
21
|
+
*/
|
|
22
|
+
manualFileName?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Use this to replace an existing file.
|
|
25
|
+
* It will automatically delete the existing file when the upload is complete.
|
|
26
|
+
*/
|
|
27
|
+
replaceTargetUrl?: string;
|
|
28
|
+
/**
|
|
29
|
+
* If true, the file needs to be confirmed by using the `confirm` function.
|
|
30
|
+
* If the file is not confirmed within 24 hours, it will be deleted.
|
|
31
|
+
*
|
|
32
|
+
* This is useful for pages where the file is uploaded as soon as it is selected,
|
|
33
|
+
* but the user can leave the page without submitting the form.
|
|
34
|
+
*
|
|
35
|
+
* This avoids unnecessary zombie files in the bucket.
|
|
36
|
+
*/
|
|
37
|
+
temporary?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Transform the file before it is validated and uploaded.
|
|
40
|
+
*
|
|
41
|
+
* This can be used to compress images, convert formats, encrypt files, etc.
|
|
42
|
+
* The transformed file's size, MIME type, and extension will be used for the
|
|
43
|
+
* upload request.
|
|
44
|
+
*/
|
|
45
|
+
transform?: ClientUploadTransform;
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/internals/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,MAAM,MAAM,qBAAqB,GAAG,CAAC,MAAM,EAAE;IAC3C,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,KAAK,YAAY,CACd,IAAI,GACJ,IAAI,GACJ;IACE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB,CACJ,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B;;;;;;;;;;OAUG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;;;;;OAQG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,qBAAqB,CAAC;CACnC,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
*/
|
|
4
|
+
export type identity<TType> = TType;
|
|
5
|
+
export type InferOptional<TType, TKeys extends keyof TType> = Omit<TType, TKeys> & Partial<Pick<TType, TKeys>>;
|
|
6
|
+
export type UndefinedKeys<TType> = {
|
|
7
|
+
[K in keyof TType]: undefined extends TType[K] ? K : never;
|
|
8
|
+
}[keyof TType];
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export type FlatOverwrite<TType, TWith> = InferOptional<{
|
|
13
|
+
[TKey in keyof TType | keyof TWith]: TKey extends keyof TWith ? TWith[TKey] : TKey extends keyof TType ? TType[TKey] : never;
|
|
14
|
+
}, UndefinedKeys<TType> | UndefinedKeys<TWith>>;
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export type IntersectionError<TKey extends string> = `The property '${TKey}' in your router collides with a built-in method, rename this router or procedure on your backend.`;
|
|
19
|
+
/**
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export type ProtectedIntersection<TType, TWith> = keyof TType & keyof TWith extends never ? TType & TWith : IntersectionError<string & keyof TType & keyof TWith>;
|
|
23
|
+
/**
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export type Maybe<TType> = TType | null | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export type ThenArg<TType> = TType extends PromiseLike<infer U> ? ThenArg<U> : TType;
|
|
31
|
+
/**
|
|
32
|
+
* @internal
|
|
33
|
+
* @see https://github.com/ianstormtaylor/superstruct/blob/7973400cd04d8ad92bbdc2b6f35acbfb3c934079/src/utils.ts#L323-L325
|
|
34
|
+
*/
|
|
35
|
+
export type Simplify<TType> = TType extends any[] | Date ? TType : {
|
|
36
|
+
[K in keyof TType]: TType[K];
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
export type Prettify<TType> = {
|
|
42
|
+
[K in keyof TType]: TType[K];
|
|
43
|
+
} & {};
|
|
44
|
+
/**
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
export type Dict<TType> = Record<string, TType | undefined>;
|
|
48
|
+
/**
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
export type MaybePromise<TType> = Promise<TType> | TType;
|
|
52
|
+
/**
|
|
53
|
+
* @internal
|
|
54
|
+
*
|
|
55
|
+
* Creates a "lower-priority" type inference.
|
|
56
|
+
* https://github.com/microsoft/TypeScript/issues/14829#issuecomment-322267089
|
|
57
|
+
*/
|
|
58
|
+
export type InferLast<TType> = TType & {
|
|
59
|
+
[KeyType in keyof TType]: TType[KeyType];
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* @public
|
|
63
|
+
*/
|
|
64
|
+
export type inferAsyncReturnType<TFunction extends (...args: any) => any> = ThenArg<ReturnType<TFunction>>;
|
|
65
|
+
export type FilterKeys<TObj extends object, TFilter> = {
|
|
66
|
+
[TKey in keyof TObj]: TObj[TKey] extends TFilter ? TKey : never;
|
|
67
|
+
}[keyof TObj];
|
|
68
|
+
/**
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
71
|
+
export type Filter<TObj extends object, TFilter> = Pick<TObj, FilterKeys<TObj, TFilter>>;
|
|
72
|
+
/**
|
|
73
|
+
* Unwrap return type if the type is a function (sync or async), else uses the type as is
|
|
74
|
+
* @internal
|
|
75
|
+
*/
|
|
76
|
+
export type Unwrap<TType> = TType extends (...args: any[]) => infer R ? ThenArg<R> : TType;
|
|
77
|
+
/**
|
|
78
|
+
* Makes the object recursively optional.
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
81
|
+
export type DeepPartial<TObject> = TObject extends object ? {
|
|
82
|
+
[P in keyof TObject]?: DeepPartial<TObject[P]>;
|
|
83
|
+
} : TObject;
|
|
84
|
+
/**
|
|
85
|
+
* Get the keys of a union type.
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
88
|
+
export type KeysOfUnion<TUnion> = TUnion extends TUnion ? keyof TUnion extends string ? keyof TUnion : string : never;
|
|
89
|
+
/**
|
|
90
|
+
* Unify a union of objects into a single object.
|
|
91
|
+
* @internal
|
|
92
|
+
*/
|
|
93
|
+
export type UnifyUnion<TUnion> = Simplify<(TUnion extends any ? (k: TUnion) => void : never) extends (k: infer I) => void ? I : never>;
|
|
94
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,QAAQ,CAAC,KAAK,IAAI,KAAK,CA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,KAAK,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC,GACjE,OAAO,CAAC,CAAC,CAAC,GACV,KAAK,CAAC;AAEV;;;GAGG;AACH,MAAM,MAAM,WAAW,CAAC,OAAO,IAAI,OAAO,SAAS,MAAM,GACrD;KACG,CAAC,IAAI,MAAM,OAAO,CAAC,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;CAC/C,GACD,OAAO,CAAC;AAEZ;;;GAGG;AACH,MAAM,MAAM,WAAW,CAAC,MAAM,IAAI,MAAM,SAAS,MAAM,GACnD,MAAM,MAAM,SAAS,MAAM,GACzB,MAAM,MAAM,GACZ,MAAM,GACR,KAAK,CAAC;AAEV;;;GAGG;AACH,MAAM,MAAM,UAAU,CAAC,MAAM,IAAI,QAAQ,CACvC,CAAC,MAAM,SAAS,GAAG,GAAG,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,GAAG,KAAK,CAAC,SAAS,CACzD,CAAC,EAAE,MAAM,CAAC,KACP,IAAI,GACL,CAAC,GACD,KAAK,CACV,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@edgestore/shared",
|
|
3
|
+
"version": "0.0.0-canary-20260730114359",
|
|
4
|
+
"description": "Upload files with ease from React/Next.js",
|
|
5
|
+
"homepage": "https://edgestore.dev",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"type": "module",
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=24"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/edgestorejs/edgestore.git",
|
|
15
|
+
"directory": "packages/shared"
|
|
16
|
+
},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"author": "Ravi <me@ravi.com>",
|
|
21
|
+
"main": "dist/index.js",
|
|
22
|
+
"types": "dist/index.d.ts",
|
|
23
|
+
"keywords": [
|
|
24
|
+
"react",
|
|
25
|
+
"nodejs",
|
|
26
|
+
"nextjs",
|
|
27
|
+
"upload",
|
|
28
|
+
"file",
|
|
29
|
+
"image",
|
|
30
|
+
"cdn",
|
|
31
|
+
"edgestore",
|
|
32
|
+
"edge-store"
|
|
33
|
+
],
|
|
34
|
+
"exports": {
|
|
35
|
+
"./package.json": "./package.json",
|
|
36
|
+
".": {
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"import": "./dist/index.js",
|
|
39
|
+
"default": "./dist/index.js"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"dist",
|
|
44
|
+
"src",
|
|
45
|
+
"README.md",
|
|
46
|
+
"LICENSE",
|
|
47
|
+
"package.json",
|
|
48
|
+
"!**/*.test.*",
|
|
49
|
+
"!**/__tests__"
|
|
50
|
+
],
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@standard-schema/spec": "^1.1.0"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"react": ">=16.8.0",
|
|
56
|
+
"react-dom": ">=16.8.0",
|
|
57
|
+
"zod": ">=3.0.0"
|
|
58
|
+
},
|
|
59
|
+
"peerDependenciesMeta": {
|
|
60
|
+
"zod": {
|
|
61
|
+
"optional": true
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@types/node": "25.0.3",
|
|
66
|
+
"react": "19.2.7",
|
|
67
|
+
"react-dom": "19.2.7",
|
|
68
|
+
"tsx": "4.23.1",
|
|
69
|
+
"typescript": "6.0.3",
|
|
70
|
+
"zod": "3.25.76"
|
|
71
|
+
},
|
|
72
|
+
"gitHead": "a223c4cb8df50e6b64f9db5dc2daf93848748da9",
|
|
73
|
+
"scripts": {
|
|
74
|
+
"build": "rollup --config rollup.config.ts --configPlugin rollup-plugin-swc3",
|
|
75
|
+
"dev": "pnpm build --watch",
|
|
76
|
+
"codegen:entrypoints": "tsx entrypoints.script.ts",
|
|
77
|
+
"test": "vitest run",
|
|
78
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
79
|
+
"lint": "eslint --cache --report-unused-disable-directives src"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { type Simplify } from '../types';
|
|
2
|
+
|
|
3
|
+
export const EDGE_STORE_ERROR_CODES = {
|
|
4
|
+
BAD_REQUEST: 400,
|
|
5
|
+
FILE_TOO_LARGE: 400,
|
|
6
|
+
MIME_TYPE_NOT_ALLOWED: 400,
|
|
7
|
+
UNAUTHORIZED: 401,
|
|
8
|
+
UPLOAD_NOT_ALLOWED: 403,
|
|
9
|
+
DELETE_NOT_ALLOWED: 403,
|
|
10
|
+
CREATE_CONTEXT_ERROR: 500,
|
|
11
|
+
SERVER_ERROR: 500,
|
|
12
|
+
} as const;
|
|
13
|
+
|
|
14
|
+
export type EdgeStoreErrorCodeKey = keyof typeof EDGE_STORE_ERROR_CODES;
|
|
15
|
+
|
|
16
|
+
export type EdgeStoreErrorDetails<TCode extends EdgeStoreErrorCodeKey> =
|
|
17
|
+
TCode extends 'FILE_TOO_LARGE'
|
|
18
|
+
? {
|
|
19
|
+
maxFileSize: number;
|
|
20
|
+
fileSize: number;
|
|
21
|
+
}
|
|
22
|
+
: TCode extends 'MIME_TYPE_NOT_ALLOWED'
|
|
23
|
+
? {
|
|
24
|
+
allowedMimeTypes: string[];
|
|
25
|
+
mimeType: string;
|
|
26
|
+
}
|
|
27
|
+
: never;
|
|
28
|
+
|
|
29
|
+
export type EdgeStoreJsonResponse = Simplify<
|
|
30
|
+
| {
|
|
31
|
+
message: string;
|
|
32
|
+
code: 'FILE_TOO_LARGE';
|
|
33
|
+
details: EdgeStoreErrorDetails<'FILE_TOO_LARGE'>;
|
|
34
|
+
}
|
|
35
|
+
| {
|
|
36
|
+
message: string;
|
|
37
|
+
code: 'MIME_TYPE_NOT_ALLOWED';
|
|
38
|
+
details: EdgeStoreErrorDetails<'MIME_TYPE_NOT_ALLOWED'>;
|
|
39
|
+
}
|
|
40
|
+
| {
|
|
41
|
+
message: string;
|
|
42
|
+
code: Exclude<
|
|
43
|
+
EdgeStoreErrorCodeKey,
|
|
44
|
+
'FILE_TOO_LARGE' | 'MIME_TYPE_NOT_ALLOWED'
|
|
45
|
+
>;
|
|
46
|
+
}
|
|
47
|
+
>;
|
|
48
|
+
|
|
49
|
+
export class EdgeStoreError<TCode extends EdgeStoreErrorCodeKey> extends Error {
|
|
50
|
+
public readonly cause?: Error;
|
|
51
|
+
public readonly code: TCode;
|
|
52
|
+
public readonly level: 'error' | 'warn';
|
|
53
|
+
public readonly details: EdgeStoreErrorDetails<TCode>;
|
|
54
|
+
|
|
55
|
+
constructor(
|
|
56
|
+
opts: {
|
|
57
|
+
message: string;
|
|
58
|
+
code: TCode;
|
|
59
|
+
cause?: Error;
|
|
60
|
+
} & (EdgeStoreErrorDetails<TCode> extends undefined
|
|
61
|
+
? object
|
|
62
|
+
: {
|
|
63
|
+
details: EdgeStoreErrorDetails<TCode>;
|
|
64
|
+
}),
|
|
65
|
+
) {
|
|
66
|
+
super(opts.message);
|
|
67
|
+
this.name = 'EdgeStoreError';
|
|
68
|
+
|
|
69
|
+
this.code = opts.code;
|
|
70
|
+
this.cause = opts.cause;
|
|
71
|
+
this.level = EDGE_STORE_ERROR_CODES[opts.code] >= 500 ? 'error' : 'warn';
|
|
72
|
+
this.details = 'details' in opts ? opts.details : undefined!;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
formattedMessage(): string {
|
|
76
|
+
return `${this.message}${
|
|
77
|
+
this.details ? `\n Details: ${JSON.stringify(this.details)}` : ''
|
|
78
|
+
}${this.cause ? `\n Caused by: ${this.cause.message}` : ''}`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
formattedJson(): EdgeStoreJsonResponse {
|
|
82
|
+
return {
|
|
83
|
+
message:
|
|
84
|
+
this.code === 'SERVER_ERROR' ? 'Internal server error' : this.message,
|
|
85
|
+
code: this.code,
|
|
86
|
+
details: this.details,
|
|
87
|
+
} as EdgeStoreJsonResponse;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type EdgeStoreJsonResponse } from './EdgeStoreError';
|
|
2
|
+
|
|
3
|
+
export class EdgeStoreApiClientError extends Error {
|
|
4
|
+
public readonly data: EdgeStoreJsonResponse;
|
|
5
|
+
|
|
6
|
+
constructor(opts: { response: EdgeStoreJsonResponse }) {
|
|
7
|
+
super(opts.response.message);
|
|
8
|
+
this.name = 'EdgeStoreApiClientError';
|
|
9
|
+
|
|
10
|
+
this.data = opts.response;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export * from './EdgeStoreError';
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './errors';
|
|
2
|
+
export * from './types';
|
|
3
|
+
export * from './internals/bucketBuilder';
|
|
4
|
+
export * from './internals/types';
|
|
5
|
+
export * from './internals/providerTypes';
|
|
6
|
+
export * from './internals/providerCapabilities';
|
|
7
|
+
export * from './internals/sharedFuncTypes';
|