@edgestore/shared 0.5.7 → 0.6.0-canary.1
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/index.cjs +215 -0
- package/dist/index.d.cts +560 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +560 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +192 -267
- package/dist/index.mjs.map +1 -0
- package/package.json +19 -15
- package/dist/errors/EdgeStoreError.d.ts +0 -47
- package/dist/errors/EdgeStoreError.d.ts.map +0 -1
- package/dist/errors/index.d.ts +0 -9
- package/dist/errors/index.d.ts.map +0 -1
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -295
- package/dist/internals/bucketBuilder.d.ts +0 -270
- package/dist/internals/bucketBuilder.d.ts.map +0 -1
- package/dist/internals/createPathParamProxy.d.ts +0 -21
- package/dist/internals/createPathParamProxy.d.ts.map +0 -1
- package/dist/internals/providerTypes.d.ts +0 -115
- package/dist/internals/providerTypes.d.ts.map +0 -1
- package/dist/internals/sharedFuncTypes.d.ts +0 -19
- package/dist/internals/sharedFuncTypes.d.ts.map +0 -1
- package/dist/internals/types.d.ts +0 -30
- package/dist/internals/types.d.ts.map +0 -1
- package/dist/types.d.ts +0 -94
- package/dist/types.d.ts.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,288 +1,213 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
3
|
+
//#region src/errors/EdgeStoreError.ts
|
|
4
|
+
const EDGE_STORE_ERROR_CODES = {
|
|
5
|
+
BAD_REQUEST: 400,
|
|
6
|
+
FILE_TOO_LARGE: 400,
|
|
7
|
+
MIME_TYPE_NOT_ALLOWED: 400,
|
|
8
|
+
UNAUTHORIZED: 401,
|
|
9
|
+
UPLOAD_NOT_ALLOWED: 403,
|
|
10
|
+
DELETE_NOT_ALLOWED: 403,
|
|
11
|
+
CREATE_CONTEXT_ERROR: 500,
|
|
12
|
+
SERVER_ERROR: 500
|
|
13
|
+
};
|
|
14
|
+
var EdgeStoreError = class extends Error {
|
|
15
|
+
constructor(opts) {
|
|
16
|
+
super(opts.message);
|
|
17
|
+
this.name = "EdgeStoreError";
|
|
18
|
+
this.code = opts.code;
|
|
19
|
+
this.cause = opts.cause;
|
|
20
|
+
this.level = EDGE_STORE_ERROR_CODES[opts.code] >= 500 ? "error" : "warn";
|
|
21
|
+
this.details = "details" in opts ? opts.details : void 0;
|
|
22
|
+
}
|
|
23
|
+
formattedMessage() {
|
|
24
|
+
return `${this.message}${this.details ? `\n Details: ${JSON.stringify(this.details)}` : ""}${this.cause ? `\n Caused by: ${this.cause.message}` : ""}`;
|
|
25
|
+
}
|
|
26
|
+
formattedJson() {
|
|
27
|
+
return {
|
|
28
|
+
message: this.code === "SERVER_ERROR" ? "Internal server error" : this.message,
|
|
29
|
+
code: this.code,
|
|
30
|
+
details: this.details
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/errors/index.ts
|
|
37
|
+
var EdgeStoreApiClientError = class extends Error {
|
|
38
|
+
constructor(opts) {
|
|
39
|
+
super(opts.response.message);
|
|
40
|
+
this.name = "EdgeStoreApiClientError";
|
|
41
|
+
this.data = opts.response;
|
|
42
|
+
}
|
|
25
43
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/internals/createPathParamProxy.ts
|
|
47
|
+
/**
|
|
48
|
+
* Creates a Proxy that prints the path to the property when called.
|
|
49
|
+
*
|
|
50
|
+
* Example:
|
|
51
|
+
*
|
|
52
|
+
* ```ts
|
|
53
|
+
* const pathParamProxy = createPathParamProxy();
|
|
54
|
+
* console.log(pathParamProxy.ctx.user.id());
|
|
55
|
+
* // Logs: "ctx.user.id"
|
|
56
|
+
* console.log(pathParamProxy.input.type());
|
|
57
|
+
* // Logs: "input.type"
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
function createPathParamProxy() {
|
|
61
|
+
const getPath = (target, _prop) => {
|
|
62
|
+
const proxyFunction = (() => target);
|
|
63
|
+
return new Proxy(proxyFunction, { get: (_target, propChild) => {
|
|
64
|
+
return getPath(`${target}.${String(propChild)}`, propChild);
|
|
65
|
+
} });
|
|
66
|
+
};
|
|
67
|
+
return new Proxy((() => ""), { get: (_target, prop) => {
|
|
68
|
+
return getPath(String(prop), String(prop));
|
|
69
|
+
} });
|
|
49
70
|
}
|
|
50
71
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
obj[key] = value;
|
|
61
|
-
}
|
|
62
|
-
return obj;
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/typeof.js
|
|
74
|
+
function _typeof(o) {
|
|
75
|
+
"@babel/helpers - typeof";
|
|
76
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
77
|
+
return typeof o$1;
|
|
78
|
+
} : function(o$1) {
|
|
79
|
+
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
80
|
+
}, _typeof(o);
|
|
63
81
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
82
|
+
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/toPrimitive.js
|
|
85
|
+
function toPrimitive(t, r) {
|
|
86
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
87
|
+
var e = t[Symbol.toPrimitive];
|
|
88
|
+
if (void 0 !== e) {
|
|
89
|
+
var i = e.call(t, r || "default");
|
|
90
|
+
if ("object" != _typeof(i)) return i;
|
|
91
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
92
|
+
}
|
|
93
|
+
return ("string" === r ? String : Number)(t);
|
|
71
94
|
}
|
|
72
95
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
* ```ts
|
|
79
|
-
* const pathParamProxy = createPathParamProxy();
|
|
80
|
-
* console.log(pathParamProxy.ctx.user.id());
|
|
81
|
-
* // Logs: "ctx.user.id"
|
|
82
|
-
* console.log(pathParamProxy.input.type());
|
|
83
|
-
* // Logs: "input.type"
|
|
84
|
-
* ```
|
|
85
|
-
*/ function createPathParamProxy() {
|
|
86
|
-
const getPath = (target, _prop)=>{
|
|
87
|
-
const proxyFunction = ()=>target;
|
|
88
|
-
return new Proxy(proxyFunction, {
|
|
89
|
-
get: (_target, propChild)=>{
|
|
90
|
-
return getPath(`${target}.${String(propChild)}`);
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
};
|
|
94
|
-
return new Proxy(()=>'', {
|
|
95
|
-
get: (_target, prop)=>{
|
|
96
|
-
return getPath(String(prop));
|
|
97
|
-
}
|
|
98
|
-
});
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/toPropertyKey.js
|
|
98
|
+
function toPropertyKey(t) {
|
|
99
|
+
var i = toPrimitive(t, "string");
|
|
100
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
99
101
|
}
|
|
100
102
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/defineProperty.js
|
|
105
|
+
function _defineProperty(e, r, t) {
|
|
106
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
107
|
+
value: t,
|
|
108
|
+
enumerable: !0,
|
|
109
|
+
configurable: !0,
|
|
110
|
+
writable: !0
|
|
111
|
+
}) : e[r] = t, e;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/objectSpread2.js
|
|
116
|
+
function ownKeys(e, r) {
|
|
117
|
+
var t = Object.keys(e);
|
|
118
|
+
if (Object.getOwnPropertySymbols) {
|
|
119
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
120
|
+
r && (o = o.filter(function(r$1) {
|
|
121
|
+
return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
|
|
122
|
+
})), t.push.apply(t, o);
|
|
123
|
+
}
|
|
124
|
+
return t;
|
|
125
|
+
}
|
|
126
|
+
function _objectSpread2(e) {
|
|
127
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
128
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
129
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function(r$1) {
|
|
130
|
+
_defineProperty(e, r$1, t[r$1]);
|
|
131
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
|
|
132
|
+
Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
return e;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
//#endregion
|
|
139
|
+
//#region src/internals/bucketBuilder.ts
|
|
140
|
+
const createNewBuilder = (initDef, newDef) => {
|
|
141
|
+
const mergedDef = _objectSpread2(_objectSpread2({}, initDef), newDef);
|
|
142
|
+
return createBuilder({ type: mergedDef.type }, mergedDef);
|
|
109
143
|
};
|
|
110
144
|
function createBuilder(opts, initDef) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
metadata (metadata) {
|
|
140
|
-
return createNewBuilder(_def, {
|
|
141
|
-
metadata
|
|
142
|
-
});
|
|
143
|
-
},
|
|
144
|
-
accessControl (accessControl) {
|
|
145
|
-
return createNewBuilder(_def, {
|
|
146
|
-
accessControl: accessControl
|
|
147
|
-
});
|
|
148
|
-
},
|
|
149
|
-
beforeUpload (beforeUpload) {
|
|
150
|
-
return createNewBuilder(_def, {
|
|
151
|
-
beforeUpload
|
|
152
|
-
});
|
|
153
|
-
},
|
|
154
|
-
beforeDelete (beforeDelete) {
|
|
155
|
-
return createNewBuilder(_def, {
|
|
156
|
-
beforeDelete
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
class EdgeStoreBuilder {
|
|
162
|
-
context() {
|
|
163
|
-
return new EdgeStoreBuilder();
|
|
164
|
-
}
|
|
165
|
-
create() {
|
|
166
|
-
return createEdgeStoreInner()();
|
|
167
|
-
}
|
|
145
|
+
const _def = _objectSpread2({
|
|
146
|
+
type: opts.type,
|
|
147
|
+
input: z.never(),
|
|
148
|
+
path: [],
|
|
149
|
+
metadata: () => ({})
|
|
150
|
+
}, initDef);
|
|
151
|
+
return {
|
|
152
|
+
$config: { ctx: void 0 },
|
|
153
|
+
_def,
|
|
154
|
+
input(input) {
|
|
155
|
+
return createNewBuilder(_def, { input });
|
|
156
|
+
},
|
|
157
|
+
path(pathResolver) {
|
|
158
|
+
return createNewBuilder(_def, { path: pathResolver(createPathParamProxy()) });
|
|
159
|
+
},
|
|
160
|
+
metadata(metadata) {
|
|
161
|
+
return createNewBuilder(_def, { metadata });
|
|
162
|
+
},
|
|
163
|
+
accessControl(accessControl) {
|
|
164
|
+
return createNewBuilder(_def, { accessControl });
|
|
165
|
+
},
|
|
166
|
+
beforeUpload(beforeUpload) {
|
|
167
|
+
return createNewBuilder(_def, { beforeUpload });
|
|
168
|
+
},
|
|
169
|
+
beforeDelete(beforeDelete) {
|
|
170
|
+
return createNewBuilder(_def, { beforeDelete });
|
|
171
|
+
}
|
|
172
|
+
};
|
|
168
173
|
}
|
|
174
|
+
var EdgeStoreBuilder = class EdgeStoreBuilder {
|
|
175
|
+
context() {
|
|
176
|
+
return new EdgeStoreBuilder();
|
|
177
|
+
}
|
|
178
|
+
create() {
|
|
179
|
+
return createEdgeStoreInner()();
|
|
180
|
+
}
|
|
181
|
+
};
|
|
169
182
|
function createRouterFactory() {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
};
|
|
177
|
-
};
|
|
183
|
+
return function createRouterInner(buckets) {
|
|
184
|
+
return {
|
|
185
|
+
$config: { ctx: void 0 },
|
|
186
|
+
buckets
|
|
187
|
+
};
|
|
188
|
+
};
|
|
178
189
|
}
|
|
179
190
|
function initBucket(type, config) {
|
|
180
|
-
|
|
181
|
-
type
|
|
182
|
-
}, {
|
|
183
|
-
bucketConfig: config
|
|
184
|
-
});
|
|
191
|
+
return createBuilder({ type }, { bucketConfig: config });
|
|
185
192
|
}
|
|
186
193
|
function createEdgeStoreInner() {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
},
|
|
199
|
-
/**
|
|
200
|
-
* Create a router
|
|
201
|
-
*/ router: createRouterFactory()
|
|
202
|
-
};
|
|
203
|
-
};
|
|
194
|
+
return function initEdgeStoreInner() {
|
|
195
|
+
return {
|
|
196
|
+
imageBucket(config) {
|
|
197
|
+
return initBucket("IMAGE", config);
|
|
198
|
+
},
|
|
199
|
+
fileBucket(config) {
|
|
200
|
+
return initBucket("FILE", config);
|
|
201
|
+
},
|
|
202
|
+
router: createRouterFactory()
|
|
203
|
+
};
|
|
204
|
+
};
|
|
204
205
|
}
|
|
205
206
|
/**
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
// userId: string;
|
|
210
|
-
// userRole: 'admin' | 'visitor';
|
|
211
|
-
// };
|
|
212
|
-
// const es = initEdgeStore.context<Context>().create();
|
|
213
|
-
// const imagesBucket = es.imageBucket()
|
|
214
|
-
// .input(
|
|
215
|
-
// z.object({
|
|
216
|
-
// type: z.enum(['profile', 'post']),
|
|
217
|
-
// extension: z.string().optional(),
|
|
218
|
-
// }),
|
|
219
|
-
// )
|
|
220
|
-
// .path(({ ctx, input }) => [{ author: ctx.userId }, { type: input.type }])
|
|
221
|
-
// .metadata(({ ctx, input }) => ({
|
|
222
|
-
// extension: input.extension,
|
|
223
|
-
// role: ctx.userRole,
|
|
224
|
-
// }))
|
|
225
|
-
// .beforeUpload(() => {
|
|
226
|
-
// return true;
|
|
227
|
-
// });
|
|
228
|
-
// const a = es.imageBucket()
|
|
229
|
-
// .input(z.object({ type: z.string(), someMeta: z.string().optional() }))
|
|
230
|
-
// .path(({ ctx, input }) => [{ author: ctx.userId }, { type: input.type }])
|
|
231
|
-
// .metadata(({ ctx, input }) => ({
|
|
232
|
-
// role: ctx.userRole,
|
|
233
|
-
// someMeta: input.someMeta,
|
|
234
|
-
// }))
|
|
235
|
-
// .accessControl({
|
|
236
|
-
// OR: [
|
|
237
|
-
// {
|
|
238
|
-
// userId: { path: 'author' }, // this will check if the userId is the same as the author in the path parameter
|
|
239
|
-
// },
|
|
240
|
-
// {
|
|
241
|
-
// userRole: 'admin', // this is the same as { userRole: { eq: "admin" } }
|
|
242
|
-
// },
|
|
243
|
-
// ],
|
|
244
|
-
// })
|
|
245
|
-
// .beforeUpload(({ ctx, input }) => {
|
|
246
|
-
// return true;
|
|
247
|
-
// })
|
|
248
|
-
// .beforeDelete(({ ctx, file }) => {
|
|
249
|
-
// return true;
|
|
250
|
-
// });
|
|
251
|
-
// const b = es.imageBucket().path(({ ctx }) => [{ author: ctx.userId }]);
|
|
252
|
-
// const router = es.router({
|
|
253
|
-
// original: imagesBucket,
|
|
254
|
-
// imageBucket: a,
|
|
255
|
-
// imageBucket2: b,
|
|
256
|
-
// });
|
|
257
|
-
// export { router };
|
|
258
|
-
// type ListFilesResponse<TBucket extends AnyRouter['buckets'][string]> = {
|
|
259
|
-
// data: {
|
|
260
|
-
// // url: string;
|
|
261
|
-
// // size: number;
|
|
262
|
-
// // uploadedAt: Date;
|
|
263
|
-
// // metadata: InferMetadataObject<TBucket>;
|
|
264
|
-
// path: InferBucketPathKeys<TBucket> extends string ? {
|
|
265
|
-
// [key: string]: string;
|
|
266
|
-
// } :{
|
|
267
|
-
// [TKey in InferBucketPathKeys<TBucket>]: string;
|
|
268
|
-
// };
|
|
269
|
-
// }[];
|
|
270
|
-
// pagination: {
|
|
271
|
-
// currentPage: number;
|
|
272
|
-
// totalPages: number;
|
|
273
|
-
// totalCount: number;
|
|
274
|
-
// };
|
|
275
|
-
// };
|
|
276
|
-
// type TPathKeys = 'author' | 'type';
|
|
277
|
-
// type TPathKeys2 = InferBucketPathKeys<AnyBuilder>;
|
|
278
|
-
// type ObjectWithKeys<TKeys extends string> = {
|
|
279
|
-
// [TKey in TKeys]: string;
|
|
280
|
-
// };
|
|
281
|
-
// type Test1 = ObjectWithKeys<TPathKeys>;
|
|
282
|
-
// type Test2 = ObjectWithKeys<TPathKeys2>;
|
|
283
|
-
// type PathKeys = InferBucketPathKeys<typeof router.buckets.imageBucket>;
|
|
284
|
-
// type MetadataKeys = InferMetadataObject<typeof router.buckets.imageBucket>;
|
|
285
|
-
// type MyEdgeStoreRouter = typeof router;
|
|
286
|
-
// type MyAccessControl = AccessControlSchema<Context, AnyDef>;
|
|
207
|
+
* Initialize EdgeStore - be done exactly once per backend
|
|
208
|
+
*/
|
|
209
|
+
const initEdgeStore = new EdgeStoreBuilder();
|
|
287
210
|
|
|
211
|
+
//#endregion
|
|
288
212
|
export { EDGE_STORE_ERROR_CODES, EdgeStoreApiClientError, EdgeStoreError, initEdgeStore };
|
|
213
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["proxyFunction: RecursivePathProxy","_def: AnyDef"],"sources":["../src/errors/EdgeStoreError.ts","../src/errors/index.ts","../src/internals/createPathParamProxy.ts","../src/internals/bucketBuilder.ts"],"sourcesContent":["import { type Simplify } from '../types';\n\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\nexport const EDGE_STORE_ERROR_CODES = {\n BAD_REQUEST: 400,\n FILE_TOO_LARGE: 400,\n MIME_TYPE_NOT_ALLOWED: 400,\n UNAUTHORIZED: 401,\n UPLOAD_NOT_ALLOWED: 403,\n DELETE_NOT_ALLOWED: 403,\n CREATE_CONTEXT_ERROR: 500,\n SERVER_ERROR: 500,\n} as const;\n\nexport type EdgeStoreErrorCodeKey = keyof typeof EDGE_STORE_ERROR_CODES;\n\nexport type EdgeStoreErrorDetails<TCode extends EdgeStoreErrorCodeKey> =\n TCode extends 'FILE_TOO_LARGE'\n ? {\n maxFileSize: number;\n fileSize: number;\n }\n : TCode extends 'MIME_TYPE_NOT_ALLOWED'\n ? {\n allowedMimeTypes: string[];\n mimeType: string;\n }\n : never;\n\nexport type EdgeStoreJsonResponse = Simplify<\n | {\n message: string;\n code: 'FILE_TOO_LARGE';\n details: EdgeStoreErrorDetails<'FILE_TOO_LARGE'>;\n }\n | {\n message: string;\n code: 'MIME_TYPE_NOT_ALLOWED';\n details: EdgeStoreErrorDetails<'MIME_TYPE_NOT_ALLOWED'>;\n }\n | {\n message: string;\n code: Exclude<\n EdgeStoreErrorCodeKey,\n 'FILE_TOO_LARGE' | 'MIME_TYPE_NOT_ALLOWED'\n >;\n }\n>;\n\nexport class EdgeStoreError<TCode extends EdgeStoreErrorCodeKey> extends Error {\n public readonly cause?: Error;\n public readonly code: TCode;\n public readonly level: 'error' | 'warn';\n public readonly details: EdgeStoreErrorDetails<TCode>;\n\n constructor(\n opts: {\n message: string;\n code: TCode;\n cause?: Error;\n } & (EdgeStoreErrorDetails<TCode> extends undefined\n ? object\n : {\n details: EdgeStoreErrorDetails<TCode>;\n }),\n ) {\n super(opts.message);\n this.name = 'EdgeStoreError';\n\n this.code = opts.code;\n this.cause = opts.cause;\n this.level = EDGE_STORE_ERROR_CODES[opts.code] >= 500 ? 'error' : 'warn';\n this.details = 'details' in opts ? opts.details : undefined!;\n }\n\n formattedMessage(): string {\n return `${this.message}${\n this.details ? `\\n Details: ${JSON.stringify(this.details)}` : ''\n }${this.cause ? `\\n Caused by: ${this.cause.message}` : ''}`;\n }\n\n formattedJson(): EdgeStoreJsonResponse {\n return {\n message:\n this.code === 'SERVER_ERROR' ? 'Internal server error' : this.message,\n code: this.code,\n details: this.details as any,\n } satisfies EdgeStoreJsonResponse;\n }\n}\n","import { type EdgeStoreJsonResponse } from './EdgeStoreError';\n\nexport class EdgeStoreApiClientError extends Error {\n public readonly data: EdgeStoreJsonResponse;\n\n constructor(opts: { response: EdgeStoreJsonResponse }) {\n super(opts.response.message);\n this.name = 'EdgeStoreApiClientError';\n\n this.data = opts.response;\n }\n}\n\nexport * from './EdgeStoreError';\n","type RecursivePathProxy = {\n (): string;\n ctx: any;\n input: any;\n};\n\n/**\n * Creates a Proxy that prints the path to the property when called.\n *\n * Example:\n *\n * ```ts\n * const pathParamProxy = createPathParamProxy();\n * console.log(pathParamProxy.ctx.user.id());\n * // Logs: \"ctx.user.id\"\n * console.log(pathParamProxy.input.type());\n * // Logs: \"input.type\"\n * ```\n */\nexport function createPathParamProxy(): RecursivePathProxy {\n const getPath = (\n target: string,\n _prop: string | symbol,\n ): RecursivePathProxy => {\n const proxyFunction: RecursivePathProxy = (() =>\n target) as RecursivePathProxy;\n\n return new Proxy(proxyFunction, {\n get: (_target, propChild) => {\n return getPath(`${target}.${String(propChild)}`, propChild);\n },\n });\n };\n\n return new Proxy((() => '') as RecursivePathProxy, {\n get: (_target, prop) => {\n return getPath(String(prop), String(prop));\n },\n });\n}\n","import { z } from 'zod';\nimport { type KeysOfUnion, type MaybePromise, type Simplify } from '../types';\nimport { createPathParamProxy } from './createPathParamProxy';\n\ntype Merge<TType, TWith> = {\n [TKey in keyof TType | keyof TWith]?: TKey extends keyof TType\n ? TKey extends keyof TWith\n ? TType[TKey] & TWith[TKey]\n : TType[TKey]\n : TWith[TKey & keyof TWith];\n};\n\ntype ConvertStringToFunction<TType> = {\n [K in keyof TType]: TType[K] extends object\n ? Simplify<ConvertStringToFunction<TType[K]>>\n : () => string;\n};\n\ntype UnionToIntersection<TType> = (\n TType extends any ? (k: TType) => void : never\n) extends (k: infer I) => void\n ? I\n : never;\n\nexport type InferBucketPathKeys<TBucket extends Builder<any, AnyDef>> =\n KeysOfUnion<TBucket['_def']['path'][number]>;\n\ntype InferBucketPathKeysFromDef<TDef extends AnyDef> = KeysOfUnion<\n TDef['path'][number]\n>;\n\nexport type InferBucketPathObject<TBucket extends Builder<any, AnyDef>> =\n InferBucketPathKeys<TBucket> extends never\n ? Record<string, never>\n : {\n [TKey in InferBucketPathKeys<TBucket>]: string;\n };\n\nexport type InferBucketPathObjectFromDef<TDef extends AnyDef> =\n InferBucketPathKeysFromDef<TDef> extends never\n ? Record<string, never>\n : {\n [TKey in InferBucketPathKeysFromDef<TDef>]: string;\n };\n\nexport type InferMetadataObject<TBucket extends Builder<any, AnyDef>> =\n TBucket['_def']['metadata'] extends (...args: any) => any\n ? Awaited<ReturnType<TBucket['_def']['metadata']>>\n : Record<string, never>;\n\ntype InferMetadataObjectFromDef<TDef extends AnyDef> =\n TDef['metadata'] extends (...args: any) => any\n ? Awaited<ReturnType<TDef['metadata']>>\n : Record<string, never>;\n\nexport type AnyContext = Record<string, string | undefined | null>;\n\nexport type AnyInput = z.AnyZodObject | z.ZodNever;\n\nexport type AnyPath = Record<string, () => string>[];\n\ntype PathParam<TPath extends AnyPath> = {\n path: keyof UnionToIntersection<TPath[number]>;\n};\n\ntype Conditions<TPath extends AnyPath> = {\n eq?: string | PathParam<TPath>;\n lt?: string | PathParam<TPath>;\n lte?: string | PathParam<TPath>;\n gt?: string | PathParam<TPath>;\n gte?: string | PathParam<TPath>;\n contains?: string | PathParam<TPath>;\n in?: string | PathParam<TPath> | (string | PathParam<TPath>)[];\n not?: string | PathParam<TPath> | Conditions<TPath>;\n};\n\nexport type AccessControlSchema<TCtx, TDef extends AnyDef> = Merge<\n {\n [TKey in keyof TCtx]?:\n | string\n | PathParam<TDef['path']>\n | Conditions<TDef['path']>;\n },\n {\n OR?: AccessControlSchema<TCtx, TDef>[];\n AND?: AccessControlSchema<TCtx, TDef>[];\n NOT?: AccessControlSchema<TCtx, TDef>[];\n }\n>;\n\ntype BucketConfig = {\n /**\n * Maximum size for a single file in bytes\n *\n * e.g. 1024 * 1024 * 10 = 10MB\n */\n maxSize?: number;\n /**\n * Accepted MIME types\n *\n * e.g. ['image/jpeg', 'image/png']\n *\n * You can also use wildcards after the slash:\n *\n * e.g. ['image/*']\n */\n accept?: string[];\n};\n\ntype FileInfo = {\n size: number;\n type: string;\n extension: string;\n fileName?: string;\n replaceTargetUrl?: string;\n temporary: boolean;\n};\n\ntype BeforeUploadFn<TCtx, TDef extends AnyDef> = (params: {\n ctx: TCtx;\n input: z.infer<TDef['input']>;\n fileInfo: FileInfo;\n}) => MaybePromise<boolean>;\n\ntype BeforeDeleteFn<TCtx, TDef extends AnyDef> = (params: {\n ctx: TCtx;\n fileInfo: {\n url: string;\n size: number;\n uploadedAt: Date;\n path: InferBucketPathObjectFromDef<TDef>;\n metadata: InferMetadataObjectFromDef<TDef>;\n };\n}) => MaybePromise<boolean>;\n\nexport type AnyMetadata = Record<string, string | undefined | null>;\n\ntype MetadataFn<\n TCtx,\n TInput extends AnyInput,\n TMetadata extends AnyMetadata,\n> = (params: { ctx: TCtx; input: z.infer<TInput> }) => MaybePromise<TMetadata>;\n\nexport type AnyMetadataFn = MetadataFn<any, AnyInput, AnyMetadata>;\n\ntype BucketType = 'IMAGE' | 'FILE';\n\ntype Def<\n TInput extends AnyInput,\n TPath extends AnyPath,\n TMetadata extends AnyMetadataFn,\n> = {\n type: BucketType;\n input: TInput;\n path: TPath;\n metadata: TMetadata;\n bucketConfig?: BucketConfig;\n accessControl?: AccessControlSchema<any, any>;\n beforeUpload?: BeforeUploadFn<any, any>;\n beforeDelete?: BeforeDeleteFn<any, any>;\n};\n\ntype AnyDef = Def<AnyInput, AnyPath, AnyMetadataFn>;\n\ntype Builder<TCtx, TDef extends AnyDef> = {\n /** only used for types */\n $config: {\n ctx: TCtx;\n };\n /**\n * @internal\n */\n _def: TDef;\n /**\n * You can set an input that will be required in every upload from the client.\n *\n * This can be used to add additional information to the file, like choose the file path or add metadata.\n */\n input<TInput extends AnyInput>(\n input: TInput,\n ): Builder<\n TCtx,\n {\n type: TDef['type'];\n input: TInput;\n path: TDef['path'];\n metadata: TDef['metadata'];\n bucketConfig: TDef['bucketConfig'];\n accessControl: TDef['accessControl'];\n beforeUpload: TDef['beforeUpload'];\n beforeDelete: TDef['beforeDelete'];\n }\n >;\n /**\n * The `path` is similar to folders in a file system.\n * But in this case, every segment of the path must have a meaning.\n *\n * ```\n * // e.g. 123/profile/file.jpg\n * {\n * author: '123',\n * type: 'profile',\n * }\n * ```\n */\n path<TParams extends AnyPath>(\n pathResolver: (params: {\n ctx: Simplify<ConvertStringToFunction<TCtx>>;\n input: Simplify<ConvertStringToFunction<z.infer<TDef['input']>>>;\n }) => [...TParams],\n ): Builder<\n TCtx,\n {\n type: TDef['type'];\n input: TDef['input'];\n path: TParams;\n metadata: TDef['metadata'];\n bucketConfig: TDef['bucketConfig'];\n accessControl: TDef['accessControl'];\n beforeUpload: TDef['beforeUpload'];\n beforeDelete: TDef['beforeDelete'];\n }\n >;\n /**\n * This metadata will be added to every file uploaded to this bucket.\n *\n * This can be used, for example, to filter files.\n */\n metadata<TMetadata extends AnyMetadata>(\n metadata: MetadataFn<TCtx, TDef['input'], TMetadata>,\n ): Builder<\n TCtx,\n {\n type: TDef['type'];\n input: TDef['input'];\n path: TDef['path'];\n metadata: MetadataFn<any, any, TMetadata>;\n bucketConfig: TDef['bucketConfig'];\n accessControl: TDef['accessControl'];\n beforeUpload: TDef['beforeUpload'];\n beforeDelete: TDef['beforeDelete'];\n }\n >;\n /**\n * If you set this, your bucket will automatically be configured as a protected bucket.\n *\n * This means that images will only be accessible from within your app.\n * And only if it passes the check set in this function.\n */\n accessControl(accessControl: AccessControlSchema<TCtx, TDef>): Builder<\n TCtx,\n {\n type: TDef['type'];\n input: TDef['input'];\n path: TDef['path'];\n metadata: TDef['metadata'];\n bucketConfig: TDef['bucketConfig'];\n accessControl: AccessControlSchema<any, any>;\n beforeUpload: TDef['beforeUpload'];\n beforeDelete: TDef['beforeDelete'];\n }\n >;\n /**\n * return `true` to allow upload\n *\n * By default, every upload from your app is allowed.\n */\n beforeUpload(beforeUpload: BeforeUploadFn<TCtx, TDef>): Builder<\n TCtx,\n {\n type: TDef['type'];\n input: TDef['input'];\n path: TDef['path'];\n metadata: TDef['metadata'];\n bucketConfig: TDef['bucketConfig'];\n accessControl: TDef['accessControl'];\n beforeUpload: BeforeUploadFn<any, any>;\n beforeDelete: TDef['beforeDelete'];\n }\n >;\n /**\n * return `true` to allow delete\n *\n * This function must be defined if you want to delete files directly from the client.\n */\n beforeDelete(beforeDelete: BeforeDeleteFn<TCtx, TDef>): Builder<\n TCtx,\n {\n type: TDef['type'];\n input: TDef['input'];\n path: TDef['path'];\n metadata: TDef['metadata'];\n bucketConfig: TDef['bucketConfig'];\n accessControl: TDef['accessControl'];\n beforeUpload: TDef['beforeUpload'];\n beforeDelete: BeforeDeleteFn<any, any>;\n }\n >;\n};\n\nexport type AnyBuilder = Builder<any, AnyDef>;\n\nconst createNewBuilder = (initDef: AnyDef, newDef: Partial<AnyDef>) => {\n const mergedDef = {\n ...initDef,\n ...newDef,\n };\n return createBuilder(\n {\n type: mergedDef.type,\n },\n mergedDef,\n );\n};\n\nfunction createBuilder<\n TCtx,\n TType extends BucketType,\n TInput extends AnyInput = z.ZodNever,\n TPath extends AnyPath = [],\n TMetadata extends AnyMetadataFn = () => Record<string, never>,\n>(\n opts: { type: TType },\n initDef?: Partial<AnyDef>,\n): Builder<\n TCtx,\n {\n type: TType;\n input: TInput;\n path: TPath;\n metadata: TMetadata;\n bucketConfig?: BucketConfig;\n accessControl?: AccessControlSchema<any, any>;\n beforeUpload?: BeforeUploadFn<any, any>;\n beforeDelete?: BeforeDeleteFn<any, any>;\n }\n> {\n const _def: AnyDef = {\n type: opts.type,\n input: z.never(),\n path: [],\n metadata: () => ({}),\n ...initDef,\n };\n\n return {\n $config: {\n ctx: undefined as TCtx,\n },\n // @ts-expect-error - I think it would be too much work to make this type correct.\n _def,\n input(input) {\n return createNewBuilder(_def, {\n input,\n }) as any;\n },\n path(pathResolver) {\n // TODO: Should throw a runtime error in the following cases:\n // 1. in case of multiple keys in one object\n // 2. in case of duplicate keys\n const pathParamProxy = createPathParamProxy();\n const params = pathResolver(pathParamProxy);\n return createNewBuilder(_def, {\n path: params,\n }) as any;\n },\n metadata(metadata) {\n return createNewBuilder(_def, {\n metadata,\n }) as any;\n },\n accessControl(accessControl) {\n return createNewBuilder(_def, {\n accessControl: accessControl,\n }) as any;\n },\n beforeUpload(beforeUpload) {\n return createNewBuilder(_def, {\n beforeUpload,\n }) as any;\n },\n beforeDelete(beforeDelete) {\n return createNewBuilder(_def, {\n beforeDelete,\n }) as any;\n },\n };\n}\n\nclass EdgeStoreBuilder<TCtx = Record<string, never>> {\n context<TNewContext extends AnyContext>() {\n return new EdgeStoreBuilder<TNewContext>();\n }\n\n create() {\n return createEdgeStoreInner<TCtx>()();\n }\n}\n\nexport type EdgeStoreRouter<TCtx> = {\n /**\n * Only used for types\n * @internal\n */\n $config: {\n ctx: TCtx;\n };\n buckets: Record<string, Builder<TCtx, AnyDef>>;\n};\n\nexport type AnyRouter = EdgeStoreRouter<any>;\n\nfunction createRouterFactory<TCtx>() {\n return function createRouterInner<\n TBuckets extends EdgeStoreRouter<TCtx>['buckets'],\n >(buckets: TBuckets) {\n return {\n $config: {\n ctx: undefined as TCtx,\n },\n buckets,\n } satisfies EdgeStoreRouter<TCtx>;\n };\n}\n\nfunction initBucket<TCtx, TType extends BucketType>(\n type: TType,\n config?: BucketConfig,\n) {\n return createBuilder<TCtx, TType>({ type }, { bucketConfig: config });\n}\n\nfunction createEdgeStoreInner<TCtx>() {\n return function initEdgeStoreInner() {\n return {\n /**\n * Builder object for creating an image bucket\n */\n imageBucket(config?: BucketConfig) {\n return initBucket<TCtx, 'IMAGE'>('IMAGE', config);\n },\n /**\n * Builder object for creating a file bucket\n */\n fileBucket(config?: BucketConfig) {\n return initBucket<TCtx, 'FILE'>('FILE', config);\n },\n /**\n * Create a router\n */\n router: createRouterFactory<TCtx>(),\n };\n };\n}\n\n/**\n * Initialize EdgeStore - be done exactly once per backend\n */\nexport const initEdgeStore = new EdgeStoreBuilder();\n\n// ↓↓↓ TYPE TESTS ↓↓↓\n\n// type Context = {\n// userId: string;\n// userRole: 'admin' | 'visitor';\n// };\n\n// const es = initEdgeStore.context<Context>().create();\n\n// const imagesBucket = es.imageBucket()\n// .input(\n// z.object({\n// type: z.enum(['profile', 'post']),\n// extension: z.string().optional(),\n// }),\n// )\n// .path(({ ctx, input }) => [{ author: ctx.userId }, { type: input.type }])\n// .metadata(({ ctx, input }) => ({\n// extension: input.extension,\n// role: ctx.userRole,\n// }))\n// .beforeUpload(() => {\n// return true;\n// });\n// const a = es.imageBucket()\n// .input(z.object({ type: z.string(), someMeta: z.string().optional() }))\n// .path(({ ctx, input }) => [{ author: ctx.userId }, { type: input.type }])\n// .metadata(({ ctx, input }) => ({\n// role: ctx.userRole,\n// someMeta: input.someMeta,\n// }))\n// .accessControl({\n// OR: [\n// {\n// userId: { path: 'author' }, // this will check if the userId is the same as the author in the path parameter\n// },\n// {\n// userRole: 'admin', // this is the same as { userRole: { eq: \"admin\" } }\n// },\n// ],\n// })\n// .beforeUpload(({ ctx, input }) => {\n// return true;\n// })\n// .beforeDelete(({ ctx, file }) => {\n// return true;\n// });\n\n// const b = es.imageBucket().path(({ ctx }) => [{ author: ctx.userId }]);\n\n// const router = es.router({\n// original: imagesBucket,\n// imageBucket: a,\n// imageBucket2: b,\n// });\n\n// export { router };\n\n// type ListFilesResponse<TBucket extends AnyRouter['buckets'][string]> = {\n// data: {\n// // url: string;\n// // size: number;\n// // uploadedAt: Date;\n// // metadata: InferMetadataObject<TBucket>;\n// path: InferBucketPathKeys<TBucket> extends string ? {\n// [key: string]: string;\n// } :{\n// [TKey in InferBucketPathKeys<TBucket>]: string;\n// };\n// }[];\n// pagination: {\n// currentPage: number;\n// totalPages: number;\n// totalCount: number;\n// };\n// };\n\n// type TPathKeys = 'author' | 'type';\n// type TPathKeys2 = InferBucketPathKeys<AnyBuilder>;\n\n// type ObjectWithKeys<TKeys extends string> = {\n// [TKey in TKeys]: string;\n// };\n\n// type Test1 = ObjectWithKeys<TPathKeys>;\n// type Test2 = ObjectWithKeys<TPathKeys2>;\n// type PathKeys = InferBucketPathKeys<typeof router.buckets.imageBucket>;\n\n// type MetadataKeys = InferMetadataObject<typeof router.buckets.imageBucket>;\n\n// type MyEdgeStoreRouter = typeof router;\n\n// type MyAccessControl = AccessControlSchema<Context, AnyDef>;\n"],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edgestore/shared",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0-canary.1",
|
|
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",
|
|
7
7
|
"author": "Ravi <me@ravi.com>",
|
|
8
|
-
"main": "dist/index.
|
|
9
|
-
"module": "dist/index.mjs",
|
|
10
|
-
"
|
|
8
|
+
"main": "./dist/index.cjs",
|
|
9
|
+
"module": "./dist/index.mjs",
|
|
10
|
+
"types": "./dist/index.d.cts",
|
|
11
11
|
"keywords": [
|
|
12
12
|
"react",
|
|
13
13
|
"nodejs",
|
|
@@ -19,18 +19,17 @@
|
|
|
19
19
|
"edgestore",
|
|
20
20
|
"edge-store"
|
|
21
21
|
],
|
|
22
|
-
"scripts": {
|
|
23
|
-
"build": "rollup --config rollup.config.ts --configPlugin rollup-plugin-swc3",
|
|
24
|
-
"dev": "pnpm build --watch",
|
|
25
|
-
"codegen:entrypoints": "tsx entrypoints.script.ts",
|
|
26
|
-
"lint": "eslint --cache --ext \".js,.ts,.tsx\" --ignore-path ../../.gitignore --report-unused-disable-directives src"
|
|
27
|
-
},
|
|
28
22
|
"exports": {
|
|
29
23
|
"./package.json": "./package.json",
|
|
30
24
|
".": {
|
|
31
|
-
"import":
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
"import": {
|
|
26
|
+
"types": "./dist/index.d.mts",
|
|
27
|
+
"default": "./dist/index.mjs"
|
|
28
|
+
},
|
|
29
|
+
"require": {
|
|
30
|
+
"types": "./dist/index.d.cts",
|
|
31
|
+
"default": "./dist/index.cjs"
|
|
32
|
+
}
|
|
34
33
|
}
|
|
35
34
|
},
|
|
36
35
|
"files": [
|
|
@@ -63,5 +62,10 @@
|
|
|
63
62
|
"typescript": "^5",
|
|
64
63
|
"zod": "3.25.42"
|
|
65
64
|
},
|
|
66
|
-
"gitHead": "
|
|
67
|
-
|
|
65
|
+
"gitHead": "a223c4cb8df50e6b64f9db5dc2daf93848748da9",
|
|
66
|
+
"scripts": {
|
|
67
|
+
"build": "tsdown",
|
|
68
|
+
"dev": "tsdown --watch",
|
|
69
|
+
"lint": "eslint --cache --ext \".js,.ts,.tsx\" --ignore-path ../../.gitignore --report-unused-disable-directives src"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { type Simplify } from '../types';
|
|
2
|
-
export declare const EDGE_STORE_ERROR_CODES: {
|
|
3
|
-
readonly BAD_REQUEST: 400;
|
|
4
|
-
readonly FILE_TOO_LARGE: 400;
|
|
5
|
-
readonly MIME_TYPE_NOT_ALLOWED: 400;
|
|
6
|
-
readonly UNAUTHORIZED: 401;
|
|
7
|
-
readonly UPLOAD_NOT_ALLOWED: 403;
|
|
8
|
-
readonly DELETE_NOT_ALLOWED: 403;
|
|
9
|
-
readonly CREATE_CONTEXT_ERROR: 500;
|
|
10
|
-
readonly SERVER_ERROR: 500;
|
|
11
|
-
};
|
|
12
|
-
export type EdgeStoreErrorCodeKey = keyof typeof EDGE_STORE_ERROR_CODES;
|
|
13
|
-
export type EdgeStoreErrorDetails<TCode extends EdgeStoreErrorCodeKey> = TCode extends 'FILE_TOO_LARGE' ? {
|
|
14
|
-
maxFileSize: number;
|
|
15
|
-
fileSize: number;
|
|
16
|
-
} : TCode extends 'MIME_TYPE_NOT_ALLOWED' ? {
|
|
17
|
-
allowedMimeTypes: string[];
|
|
18
|
-
mimeType: string;
|
|
19
|
-
} : never;
|
|
20
|
-
export type EdgeStoreJsonResponse = Simplify<{
|
|
21
|
-
message: string;
|
|
22
|
-
code: 'FILE_TOO_LARGE';
|
|
23
|
-
details: EdgeStoreErrorDetails<'FILE_TOO_LARGE'>;
|
|
24
|
-
} | {
|
|
25
|
-
message: string;
|
|
26
|
-
code: 'MIME_TYPE_NOT_ALLOWED';
|
|
27
|
-
details: EdgeStoreErrorDetails<'MIME_TYPE_NOT_ALLOWED'>;
|
|
28
|
-
} | {
|
|
29
|
-
message: string;
|
|
30
|
-
code: Exclude<EdgeStoreErrorCodeKey, 'FILE_TOO_LARGE' | 'MIME_TYPE_NOT_ALLOWED'>;
|
|
31
|
-
}>;
|
|
32
|
-
export declare class EdgeStoreError<TCode extends EdgeStoreErrorCodeKey> extends Error {
|
|
33
|
-
readonly cause?: Error;
|
|
34
|
-
readonly code: TCode;
|
|
35
|
-
readonly level: 'error' | 'warn';
|
|
36
|
-
readonly details: EdgeStoreErrorDetails<TCode>;
|
|
37
|
-
constructor(opts: {
|
|
38
|
-
message: string;
|
|
39
|
-
code: TCode;
|
|
40
|
-
cause?: Error;
|
|
41
|
-
} & (EdgeStoreErrorDetails<TCode> extends undefined ? object : {
|
|
42
|
-
details: EdgeStoreErrorDetails<TCode>;
|
|
43
|
-
}));
|
|
44
|
-
formattedMessage(): string;
|
|
45
|
-
formattedJson(): EdgeStoreJsonResponse;
|
|
46
|
-
}
|
|
47
|
-
//# sourceMappingURL=EdgeStoreError.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EdgeStoreError.d.ts","sourceRoot":"","sources":["../../src/errors/EdgeStoreError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGzC,eAAO,MAAM,sBAAsB;;;;;;;;;CASzB,CAAC;AAEX,MAAM,MAAM,qBAAqB,GAAG,MAAM,OAAO,sBAAsB,CAAC;AAExE,MAAM,MAAM,qBAAqB,CAAC,KAAK,SAAS,qBAAqB,IACnE,KAAK,SAAS,gBAAgB,GAC1B;IACE,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB,GACD,KAAK,SAAS,uBAAuB,GACrC;IACE,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;CAClB,GACD,KAAK,CAAC;AAEZ,MAAM,MAAM,qBAAqB,GAAG,QAAQ,CACxC;IACE,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,gBAAgB,CAAC;IACvB,OAAO,EAAE,qBAAqB,CAAC,gBAAgB,CAAC,CAAC;CAClD,GACD;IACE,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,uBAAuB,CAAC;IAC9B,OAAO,EAAE,qBAAqB,CAAC,uBAAuB,CAAC,CAAC;CACzD,GACD;IACE,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,CACX,qBAAqB,EACrB,gBAAgB,GAAG,uBAAuB,CAC3C,CAAC;CACH,CACJ,CAAC;AAEF,qBAAa,cAAc,CAAC,KAAK,SAAS,qBAAqB,CAAE,SAAQ,KAAK;IAC5E,SAAgB,KAAK,CAAC,EAAE,KAAK,CAAC;IAC9B,SAAgB,IAAI,EAAE,KAAK,CAAC;IAC5B,SAAgB,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC;IACxC,SAAgB,OAAO,EAAE,qBAAqB,CAAC,KAAK,CAAC,CAAC;gBAGpD,IAAI,EAAE;QACJ,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,KAAK,CAAC;QACZ,KAAK,CAAC,EAAE,KAAK,CAAC;KACf,GAAG,CAAC,qBAAqB,CAAC,KAAK,CAAC,SAAS,SAAS,GAC/C,MAAM,GACN;QACE,OAAO,EAAE,qBAAqB,CAAC,KAAK,CAAC,CAAC;KACvC,CAAC;IAWR,gBAAgB,IAAI,MAAM;IAM1B,aAAa,IAAI,qBAAqB;CAQvC"}
|
package/dist/errors/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type EdgeStoreJsonResponse } from './EdgeStoreError';
|
|
2
|
-
export declare class EdgeStoreApiClientError extends Error {
|
|
3
|
-
readonly data: EdgeStoreJsonResponse;
|
|
4
|
-
constructor(opts: {
|
|
5
|
-
response: EdgeStoreJsonResponse;
|
|
6
|
-
});
|
|
7
|
-
}
|
|
8
|
-
export * from './EdgeStoreError';
|
|
9
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAE9D,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,SAAgB,IAAI,EAAE,qBAAqB,CAAC;gBAEhC,IAAI,EAAE;QAAE,QAAQ,EAAE,qBAAqB,CAAA;KAAE;CAMtD;AAED,cAAc,kBAAkB,CAAC"}
|