@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 ADDED
@@ -0,0 +1,215 @@
1
+ let zod = require("zod");
2
+
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
+ }
43
+ };
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
+ } });
70
+ }
71
+
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);
81
+ }
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);
94
+ }
95
+
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 + "";
101
+ }
102
+
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);
143
+ };
144
+ function createBuilder(opts, initDef) {
145
+ const _def = _objectSpread2({
146
+ type: opts.type,
147
+ input: zod.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
+ };
173
+ }
174
+ var EdgeStoreBuilder = class EdgeStoreBuilder {
175
+ context() {
176
+ return new EdgeStoreBuilder();
177
+ }
178
+ create() {
179
+ return createEdgeStoreInner()();
180
+ }
181
+ };
182
+ function createRouterFactory() {
183
+ return function createRouterInner(buckets) {
184
+ return {
185
+ $config: { ctx: void 0 },
186
+ buckets
187
+ };
188
+ };
189
+ }
190
+ function initBucket(type, config) {
191
+ return createBuilder({ type }, { bucketConfig: config });
192
+ }
193
+ function createEdgeStoreInner() {
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
+ };
205
+ }
206
+ /**
207
+ * Initialize EdgeStore - be done exactly once per backend
208
+ */
209
+ const initEdgeStore = new EdgeStoreBuilder();
210
+
211
+ //#endregion
212
+ exports.EDGE_STORE_ERROR_CODES = EDGE_STORE_ERROR_CODES;
213
+ exports.EdgeStoreApiClientError = EdgeStoreApiClientError;
214
+ exports.EdgeStoreError = EdgeStoreError;
215
+ exports.initEdgeStore = initEdgeStore;