@ones-open/node-sdk 0.0.1 → 0.0.3
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 +201 -0
- package/dist/index.cjs +538 -2
- package/dist/index.js +538 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/packages/node/index.d.ts +5 -0
- package/dist/types/packages/node/index.d.ts.map +1 -0
- package/dist/types/packages/node/storage/entity/entity/index.d.ts +13 -0
- package/dist/types/packages/node/storage/entity/entity/index.d.ts.map +1 -0
- package/dist/types/packages/node/storage/entity/entity/types.d.ts +68 -0
- package/dist/types/packages/node/storage/entity/entity/types.d.ts.map +1 -0
- package/dist/types/packages/node/storage/entity/error/consts.d.ts +127 -0
- package/dist/types/packages/node/storage/entity/error/consts.d.ts.map +1 -0
- package/dist/types/packages/node/storage/entity/error/index.d.ts +2 -0
- package/dist/types/packages/node/storage/entity/error/index.d.ts.map +1 -0
- package/dist/types/packages/node/storage/entity/fetch/index.d.ts +7 -0
- package/dist/types/packages/node/storage/entity/fetch/index.d.ts.map +1 -0
- package/dist/types/packages/node/storage/entity/fetch/types.d.ts +50 -0
- package/dist/types/packages/node/storage/entity/fetch/types.d.ts.map +1 -0
- package/dist/types/packages/node/storage/entity/index.d.ts +23 -0
- package/dist/types/packages/node/storage/entity/index.d.ts.map +1 -0
- package/dist/types/packages/node/storage/entity/query/consts.d.ts +6 -0
- package/dist/types/packages/node/storage/entity/query/consts.d.ts.map +1 -0
- package/dist/types/packages/node/storage/entity/query/index.d.ts +27 -0
- package/dist/types/packages/node/storage/entity/query/index.d.ts.map +1 -0
- package/dist/types/packages/node/storage/entity/query/types.d.ts +174 -0
- package/dist/types/packages/node/storage/entity/query/types.d.ts.map +1 -0
- package/dist/types/packages/node/storage/entity/result/index.d.ts +2 -0
- package/dist/types/packages/node/storage/entity/result/index.d.ts.map +1 -0
- package/dist/types/packages/node/storage/entity/result/types.d.ts +53 -0
- package/dist/types/packages/node/storage/entity/result/types.d.ts.map +1 -0
- package/dist/types/packages/node/storage/entity/sort/consts.d.ts +15 -0
- package/dist/types/packages/node/storage/entity/sort/consts.d.ts.map +1 -0
- package/dist/types/packages/node/storage/entity/sort/index.d.ts +2 -0
- package/dist/types/packages/node/storage/entity/sort/index.d.ts.map +1 -0
- package/dist/types/packages/node/storage/entity/static.d.ts +3 -0
- package/dist/types/packages/node/storage/entity/static.d.ts.map +1 -0
- package/dist/types/packages/node/storage/entity/types.d.ts +114 -0
- package/dist/types/packages/node/storage/entity/types.d.ts.map +1 -0
- package/dist/types/packages/node/storage/entity/where/consts.d.ts +11 -0
- package/dist/types/packages/node/storage/entity/where/consts.d.ts.map +1 -0
- package/dist/types/packages/node/storage/entity/where/index.d.ts +50 -0
- package/dist/types/packages/node/storage/entity/where/index.d.ts.map +1 -0
- package/dist/types/packages/node/storage/entity/where/types.d.ts +13 -0
- package/dist/types/packages/node/storage/entity/where/types.d.ts.map +1 -0
- package/dist/types/packages/node/storage/index.d.ts +5 -0
- package/dist/types/packages/node/storage/index.d.ts.map +1 -0
- package/dist/types/packages/node/storage/object/error/consts.d.ts +20 -0
- package/dist/types/packages/node/storage/object/error/consts.d.ts.map +1 -0
- package/dist/types/packages/node/storage/object/error/index.d.ts +22 -0
- package/dist/types/packages/node/storage/object/error/index.d.ts.map +1 -0
- package/dist/types/packages/node/storage/object/error/types.d.ts +4 -0
- package/dist/types/packages/node/storage/object/error/types.d.ts.map +1 -0
- package/dist/types/packages/node/storage/object/fetch/index.d.ts +7 -0
- package/dist/types/packages/node/storage/object/fetch/index.d.ts.map +1 -0
- package/dist/types/packages/node/storage/object/fetch/types.d.ts +34 -0
- package/dist/types/packages/node/storage/object/fetch/types.d.ts.map +1 -0
- package/dist/types/packages/node/storage/object/index.d.ts +17 -0
- package/dist/types/packages/node/storage/object/index.d.ts.map +1 -0
- package/dist/types/packages/node/storage/object/result/index.d.ts +2 -0
- package/dist/types/packages/node/storage/object/result/index.d.ts.map +1 -0
- package/dist/types/packages/node/storage/object/result/types.d.ts +31 -0
- package/dist/types/packages/node/storage/object/result/types.d.ts.map +1 -0
- package/dist/types/packages/node/storage/object/types.d.ts +66 -0
- package/dist/types/packages/node/storage/object/types.d.ts.map +1 -0
- package/dist/types/packages/strict/common/index.d.ts +2 -0
- package/dist/types/packages/strict/common/index.d.ts.map +1 -0
- package/dist/types/packages/strict/common/types.d.ts +6 -0
- package/dist/types/packages/strict/common/types.d.ts.map +1 -0
- package/dist/types/packages/strict/env/index.d.ts +35 -0
- package/dist/types/packages/strict/env/index.d.ts.map +1 -0
- package/dist/types/packages/strict/error/consts.d.ts +5 -0
- package/dist/types/packages/strict/error/consts.d.ts.map +1 -0
- package/dist/types/packages/strict/error/index.d.ts +2 -0
- package/dist/types/packages/strict/error/index.d.ts.map +1 -0
- package/dist/types/packages/strict/fetch/index.d.ts +4 -0
- package/dist/types/packages/strict/fetch/index.d.ts.map +1 -0
- package/dist/types/packages/strict/result/index.d.ts +8 -0
- package/dist/types/packages/strict/result/index.d.ts.map +1 -0
- package/dist/types/packages/strict/result/types.d.ts +31 -0
- package/dist/types/packages/strict/result/types.d.ts.map +1 -0
- package/package.json +12 -2
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,540 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
4
|
-
|
|
3
|
+
const _defineProperty = require("@babel/runtime-corejs3/helpers/defineProperty");
|
|
4
|
+
const lodashEs = require("lodash-es");
|
|
5
|
+
const Fetch = require("axios");
|
|
6
|
+
const _sortInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/sort");
|
|
7
|
+
const getPlatformApiHost = () => {
|
|
8
|
+
return "platformApiHost";
|
|
9
|
+
};
|
|
10
|
+
const getPlatformAPIHost = getPlatformApiHost;
|
|
11
|
+
const getInstanceId = () => {
|
|
12
|
+
return "instanceId";
|
|
13
|
+
};
|
|
14
|
+
const getApplicationId = () => {
|
|
15
|
+
return "applicationId";
|
|
16
|
+
};
|
|
17
|
+
const getAppId = getApplicationId;
|
|
18
|
+
const index$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
19
|
+
__proto__: null,
|
|
20
|
+
getAppId,
|
|
21
|
+
getApplicationId,
|
|
22
|
+
getInstanceId,
|
|
23
|
+
getPlatformAPIHost,
|
|
24
|
+
getPlatformApiHost
|
|
25
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
26
|
+
var EntityWhereConditionEnum = /* @__PURE__ */ ((EntityWhereConditionEnum2) => {
|
|
27
|
+
EntityWhereConditionEnum2["beginsWith"] = "beginsWith";
|
|
28
|
+
EntityWhereConditionEnum2["between"] = "between";
|
|
29
|
+
EntityWhereConditionEnum2["equalTo"] = "equalTo";
|
|
30
|
+
EntityWhereConditionEnum2["greaterThan"] = "greaterThan";
|
|
31
|
+
EntityWhereConditionEnum2["lessThan"] = "lessThan";
|
|
32
|
+
EntityWhereConditionEnum2["greaterThanEqualTo"] = "greaterThanEqualTo";
|
|
33
|
+
EntityWhereConditionEnum2["lessThanEqualTo"] = "lessThanEqualTo";
|
|
34
|
+
EntityWhereConditionEnum2["containsAny"] = "containsAny";
|
|
35
|
+
return EntityWhereConditionEnum2;
|
|
36
|
+
})(EntityWhereConditionEnum || {});
|
|
37
|
+
const WhereConditions = {
|
|
38
|
+
/**
|
|
39
|
+
* @description beginsWith
|
|
40
|
+
* @returns EntityWhereCondition
|
|
41
|
+
*/
|
|
42
|
+
[EntityWhereConditionEnum.beginsWith]: (value) => {
|
|
43
|
+
return {
|
|
44
|
+
[EntityWhereConditionEnum.beginsWith]: [value]
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
/**
|
|
48
|
+
* @description between
|
|
49
|
+
* @returns EntityWhereCondition
|
|
50
|
+
*/
|
|
51
|
+
[EntityWhereConditionEnum.between]: (min, max) => {
|
|
52
|
+
return {
|
|
53
|
+
[EntityWhereConditionEnum.between]: [min, max]
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
/**
|
|
57
|
+
* @description equalTo
|
|
58
|
+
* @returns EntityWhereCondition
|
|
59
|
+
*/
|
|
60
|
+
[EntityWhereConditionEnum.equalTo]: (value) => {
|
|
61
|
+
return {
|
|
62
|
+
[EntityWhereConditionEnum.equalTo]: [value]
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
/**
|
|
66
|
+
* @description greaterThan
|
|
67
|
+
* @returns EntityWhereCondition
|
|
68
|
+
*/
|
|
69
|
+
[EntityWhereConditionEnum.greaterThan]: (value) => {
|
|
70
|
+
return {
|
|
71
|
+
[EntityWhereConditionEnum.greaterThan]: [value]
|
|
72
|
+
};
|
|
73
|
+
},
|
|
74
|
+
/**
|
|
75
|
+
* @description lessThan
|
|
76
|
+
* @returns EntityWhereCondition
|
|
77
|
+
*/
|
|
78
|
+
[EntityWhereConditionEnum.lessThan]: (value) => {
|
|
79
|
+
return {
|
|
80
|
+
[EntityWhereConditionEnum.lessThan]: [value]
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
/**
|
|
84
|
+
* @description greaterThanEqualTo
|
|
85
|
+
* @returns EntityWhereCondition
|
|
86
|
+
*/
|
|
87
|
+
[EntityWhereConditionEnum.greaterThanEqualTo]: (value) => {
|
|
88
|
+
return {
|
|
89
|
+
[EntityWhereConditionEnum.greaterThanEqualTo]: [value]
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
/**
|
|
93
|
+
* @description lessThanEqualTo
|
|
94
|
+
* @returns EntityWhereCondition
|
|
95
|
+
*/
|
|
96
|
+
[EntityWhereConditionEnum.lessThanEqualTo]: (value) => {
|
|
97
|
+
return {
|
|
98
|
+
[EntityWhereConditionEnum.lessThanEqualTo]: [value]
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
/**
|
|
102
|
+
* @description containsAny
|
|
103
|
+
* @returns EntityWhereCondition
|
|
104
|
+
*/
|
|
105
|
+
[EntityWhereConditionEnum.containsAny]: function() {
|
|
106
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
107
|
+
args[_key] = arguments[_key];
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
[EntityWhereConditionEnum.containsAny]: [...args]
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
|
|
115
|
+
ErrorCode2["ServerError"] = "ServerError";
|
|
116
|
+
ErrorCode2["UnknownError"] = "UnknownError";
|
|
117
|
+
return ErrorCode2;
|
|
118
|
+
})(ErrorCode || {});
|
|
119
|
+
const createErrorResult = (code, message, error) => {
|
|
120
|
+
return Object.assign({}, {
|
|
121
|
+
code,
|
|
122
|
+
err_msg: `${message}`
|
|
123
|
+
}, error);
|
|
124
|
+
};
|
|
125
|
+
const fetch$1 = Fetch.create();
|
|
126
|
+
const fetchBase$1 = (path, params, config) => {
|
|
127
|
+
return Promise.all([getPlatformAPIHost(), getInstanceId()]).then((_ref) => {
|
|
128
|
+
let [base, instance_id] = _ref;
|
|
129
|
+
if (base && instance_id) {
|
|
130
|
+
const url = `${base}${path}`;
|
|
131
|
+
const data = {
|
|
132
|
+
...params,
|
|
133
|
+
instance_id
|
|
134
|
+
};
|
|
135
|
+
return fetch$1({
|
|
136
|
+
...config,
|
|
137
|
+
url,
|
|
138
|
+
data
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
throw new Error(JSON.stringify({
|
|
142
|
+
base,
|
|
143
|
+
instance_id
|
|
144
|
+
}));
|
|
145
|
+
}).then((response) => {
|
|
146
|
+
return response.data;
|
|
147
|
+
}).catch((error) => {
|
|
148
|
+
if (error instanceof Fetch.AxiosError) {
|
|
149
|
+
const $error = error;
|
|
150
|
+
const data = $error.response.data;
|
|
151
|
+
if (data.code) {
|
|
152
|
+
return data;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const message = createErrorResult(ErrorCode.ServerError, error);
|
|
156
|
+
return message;
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
const fetchPost = (params) => {
|
|
160
|
+
return fetchBase$1("/plugin_ability_fetch/storage/entity_data", params, {
|
|
161
|
+
method: "post"
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
const fetchDelete$1 = (params) => {
|
|
165
|
+
return fetchBase$1("/plugin_ability_fetch/storage/entity_data", params, {
|
|
166
|
+
method: "delete"
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
const fetchQuery = (params) => {
|
|
170
|
+
return fetchBase$1("/plugin_ability_fetch/storage/entity_data/get_many", params, {
|
|
171
|
+
method: "post"
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
const fetchCount = (params) => {
|
|
175
|
+
return fetchBase$1("/plugin_ability_fetch/storage/entity_data/count", params, {
|
|
176
|
+
method: "post"
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
const defaultEntityQuery = {
|
|
180
|
+
cursor: Symbol("cursor"),
|
|
181
|
+
limit: Symbol("limit"),
|
|
182
|
+
sort: Symbol("sort"),
|
|
183
|
+
index: Symbol("index"),
|
|
184
|
+
where: Symbol("where")
|
|
185
|
+
};
|
|
186
|
+
const defaultEntityQueryCursor = defaultEntityQuery.cursor;
|
|
187
|
+
const defaultEntityQueryLimit = defaultEntityQuery.limit;
|
|
188
|
+
const defaultEntityQuerySort = _sortInstanceProperty(defaultEntityQuery);
|
|
189
|
+
const defaultEntityQueryIndex = defaultEntityQuery.index;
|
|
190
|
+
const defaultEntityQueryWhere = defaultEntityQuery.where;
|
|
191
|
+
class EntityQueryClass {
|
|
192
|
+
constructor(name) {
|
|
193
|
+
_defineProperty(this, "_name", "");
|
|
194
|
+
_defineProperty(this, "_cursor", [defaultEntityQueryCursor]);
|
|
195
|
+
_defineProperty(this, "_limit", [defaultEntityQueryLimit]);
|
|
196
|
+
_defineProperty(this, "_sort", [defaultEntityQuerySort]);
|
|
197
|
+
_defineProperty(this, "_index", [defaultEntityQueryIndex]);
|
|
198
|
+
_defineProperty(this, "_where", [defaultEntityQueryWhere]);
|
|
199
|
+
this._name = name;
|
|
200
|
+
}
|
|
201
|
+
cursor(cursor) {
|
|
202
|
+
this._cursor = [cursor];
|
|
203
|
+
return this;
|
|
204
|
+
}
|
|
205
|
+
limit(limit) {
|
|
206
|
+
this._limit = [limit];
|
|
207
|
+
return this;
|
|
208
|
+
}
|
|
209
|
+
sort(sort) {
|
|
210
|
+
this._sort = [sort];
|
|
211
|
+
return this;
|
|
212
|
+
}
|
|
213
|
+
index(index2, partitions) {
|
|
214
|
+
if (typeof index2 === "string") {
|
|
215
|
+
if (partitions) {
|
|
216
|
+
this._index = [index2, partitions];
|
|
217
|
+
return this;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
this._index = [index2];
|
|
221
|
+
return this;
|
|
222
|
+
}
|
|
223
|
+
where(where) {
|
|
224
|
+
this._where = [where];
|
|
225
|
+
return this;
|
|
226
|
+
}
|
|
227
|
+
_getParams() {
|
|
228
|
+
const data = {
|
|
229
|
+
index: {}
|
|
230
|
+
};
|
|
231
|
+
const array = [[this._cursor[0], "after_cursor"], [this._limit[0], "limit"], [this._sort[0], "sort"], [this._index[0], "index.name"], [this._index[1], "index.partition_values"], [this._where[0], "where"]];
|
|
232
|
+
array.forEach((item) => {
|
|
233
|
+
const [value, path] = item;
|
|
234
|
+
if (lodashEs.isNull(value) || lodashEs.isUndefined(value) || lodashEs.isSymbol(value))
|
|
235
|
+
;
|
|
236
|
+
else {
|
|
237
|
+
lodashEs.set(data, path, value);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
const result = {
|
|
241
|
+
entity_name: this._name,
|
|
242
|
+
data
|
|
243
|
+
};
|
|
244
|
+
return result;
|
|
245
|
+
}
|
|
246
|
+
async getOne() {
|
|
247
|
+
const params = this._getParams();
|
|
248
|
+
params.data.limit = 1;
|
|
249
|
+
const result = await fetchQuery(params);
|
|
250
|
+
const {
|
|
251
|
+
code,
|
|
252
|
+
data
|
|
253
|
+
} = result;
|
|
254
|
+
if (code === "OK") {
|
|
255
|
+
var _data$data;
|
|
256
|
+
return data === null || data === void 0 || (_data$data = data.data) === null || _data$data === void 0 ? void 0 : _data$data[0];
|
|
257
|
+
}
|
|
258
|
+
throw result;
|
|
259
|
+
}
|
|
260
|
+
async getMany() {
|
|
261
|
+
const params = this._getParams();
|
|
262
|
+
const result = await fetchQuery(params);
|
|
263
|
+
const {
|
|
264
|
+
code,
|
|
265
|
+
data
|
|
266
|
+
} = result;
|
|
267
|
+
if (code === "OK") {
|
|
268
|
+
if (data) {
|
|
269
|
+
return data;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
throw result;
|
|
273
|
+
}
|
|
274
|
+
async count() {
|
|
275
|
+
const params = this._getParams();
|
|
276
|
+
const result = await fetchCount(params);
|
|
277
|
+
const {
|
|
278
|
+
code,
|
|
279
|
+
data
|
|
280
|
+
} = result;
|
|
281
|
+
if (code === "OK") {
|
|
282
|
+
const number = data === null || data === void 0 ? void 0 : data.count;
|
|
283
|
+
if (typeof number === "number") {
|
|
284
|
+
return number;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
throw result;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
class EntityClass {
|
|
291
|
+
constructor(name) {
|
|
292
|
+
_defineProperty(this, "_name", "");
|
|
293
|
+
this._name = name;
|
|
294
|
+
}
|
|
295
|
+
async get(key) {
|
|
296
|
+
const query = this.query();
|
|
297
|
+
return await query.index(defaultEntityQueryIndex).where(WhereConditions.equalTo(key)).getOne().then((data) => {
|
|
298
|
+
return data === null || data === void 0 ? void 0 : data.value;
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
async set(key, value) {
|
|
302
|
+
const item = {
|
|
303
|
+
key,
|
|
304
|
+
value
|
|
305
|
+
};
|
|
306
|
+
await this.batchSet([item]);
|
|
307
|
+
}
|
|
308
|
+
async delete(key) {
|
|
309
|
+
await this.batchDelete([key]);
|
|
310
|
+
}
|
|
311
|
+
query() {
|
|
312
|
+
return new EntityQueryClass(this._name);
|
|
313
|
+
}
|
|
314
|
+
async batchSet(items) {
|
|
315
|
+
const result = await fetchPost({
|
|
316
|
+
entity_name: this._name,
|
|
317
|
+
data: items
|
|
318
|
+
});
|
|
319
|
+
const {
|
|
320
|
+
code
|
|
321
|
+
} = result;
|
|
322
|
+
if (code !== "OK") {
|
|
323
|
+
throw result;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
async batchDelete(keys) {
|
|
327
|
+
const result = await fetchDelete$1({
|
|
328
|
+
entity_name: this._name,
|
|
329
|
+
data: keys
|
|
330
|
+
});
|
|
331
|
+
const {
|
|
332
|
+
code
|
|
333
|
+
} = result;
|
|
334
|
+
if (code !== "OK") {
|
|
335
|
+
throw result;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
var EntitySortEnum = /* @__PURE__ */ ((EntitySortEnum2) => {
|
|
340
|
+
EntitySortEnum2["ASC"] = "ASC";
|
|
341
|
+
EntitySortEnum2["DESC"] = "DESC";
|
|
342
|
+
return EntitySortEnum2;
|
|
343
|
+
})(EntitySortEnum || {});
|
|
344
|
+
var EntityErrorCode = /* @__PURE__ */ ((EntityErrorCode2) => {
|
|
345
|
+
EntityErrorCode2["EntityNameInvalid"] = "EntityNameInvalid";
|
|
346
|
+
EntityErrorCode2["EntityNotFound"] = "EntityNotFound";
|
|
347
|
+
EntityErrorCode2["EntityDataEmpty"] = "EntityDataEmpty";
|
|
348
|
+
EntityErrorCode2["EntityDataBatchLimit"] = "EntityDataBatchLimit";
|
|
349
|
+
EntityErrorCode2["EntityDataKeyInvalid"] = "EntityDataKeyInvalid";
|
|
350
|
+
EntityErrorCode2["EntityDataKeyDuplicate"] = "EntityDataKeyDuplicate";
|
|
351
|
+
EntityErrorCode2["EntityDataValueAttrInvalid"] = "EntityDataValueAttrInvalid";
|
|
352
|
+
EntityErrorCode2["EntityDataValueAttrNotFound"] = "EntityDataValueAttrNotFound";
|
|
353
|
+
EntityErrorCode2["EntityDataValueEmpty"] = "EntityDataValueEmpty";
|
|
354
|
+
EntityErrorCode2["EntityDataValueInvalid"] = "EntityDataValueInvalid";
|
|
355
|
+
EntityErrorCode2["EntityDataStringValueTooLong"] = "EntityDataStringValueTooLong";
|
|
356
|
+
EntityErrorCode2["EntityDataTextValueTooLong"] = "EntityDataTextValueTooLong";
|
|
357
|
+
EntityErrorCode2["EntityDataAttrRequired"] = "EntityDataAttrRequired";
|
|
358
|
+
EntityErrorCode2["EntityDataValueTypeInvalid"] = "EntityDataValueTypeInvalid";
|
|
359
|
+
EntityErrorCode2["EntityDataIndexEmpty"] = "EntityDataIndexEmpty";
|
|
360
|
+
EntityErrorCode2["EntityDataIndexNameInvalid"] = "EntityDataIndexNameInvalid";
|
|
361
|
+
EntityErrorCode2["EntityDataIndexNotFound"] = "EntityDataIndexNotFound";
|
|
362
|
+
EntityErrorCode2["EntityDataPartitionValueInvalid"] = "EntityDataPartitionValueInvalid";
|
|
363
|
+
EntityErrorCode2["EntityDataPartitionValueTypeInvalid"] = "EntityDataPartitionValueTypeInvalid";
|
|
364
|
+
EntityErrorCode2["EntityDataPartitionValueTooLong"] = "EntityDataPartitionValueTooLong";
|
|
365
|
+
EntityErrorCode2["EntityDataUniqueConstraintFailed"] = "EntityDataUniqueConstraintFailed";
|
|
366
|
+
EntityErrorCode2["EntityDataWhereConditionValueTypeInvalid"] = "EntityDataWhereConditionValueTypeInvalid";
|
|
367
|
+
EntityErrorCode2["EntityDataWhereConditionValueTooLong"] = "EntityDataWhereConditionValueTooLong";
|
|
368
|
+
EntityErrorCode2["EntityDataPageCursorInvalid"] = "EntityDataPageCursorInvalid";
|
|
369
|
+
EntityErrorCode2["EntityDataSortValueInvalid"] = "EntityDataSortValueInvalid";
|
|
370
|
+
EntityErrorCode2["EntityDataPageLimitNotInRange"] = "EntityDataPageLimitNotInRange";
|
|
371
|
+
EntityErrorCode2["EntityDataAPITimeOut"] = "EntityDataAPITimeOut";
|
|
372
|
+
EntityErrorCode2["MalformedJSON"] = "Malformed.JSON";
|
|
373
|
+
return EntityErrorCode2;
|
|
374
|
+
})(EntityErrorCode || {});
|
|
375
|
+
const entityStatic = {
|
|
376
|
+
Sort: EntitySortEnum,
|
|
377
|
+
EntityErrorCode,
|
|
378
|
+
WhereConditions,
|
|
379
|
+
defaultEntityQueryCursor,
|
|
380
|
+
defaultEntityQueryIndex,
|
|
381
|
+
defaultEntityQueryLimit,
|
|
382
|
+
defaultEntityQuerySort,
|
|
383
|
+
defaultEntityQueryWhere
|
|
384
|
+
};
|
|
385
|
+
function factory(entityName) {
|
|
386
|
+
return new EntityClass(entityName);
|
|
387
|
+
}
|
|
388
|
+
const entityFactory = factory;
|
|
389
|
+
const entityDefault = Object.assign(entityFactory, entityStatic);
|
|
390
|
+
const entity = entityDefault;
|
|
391
|
+
var ObjectErrorCode = /* @__PURE__ */ ((ObjectErrorCode2) => {
|
|
392
|
+
ObjectErrorCode2["ObjectKeyInvalid"] = "ObjectKeyInvalid";
|
|
393
|
+
ObjectErrorCode2["ObjectKeyNotfound"] = "ObjectKeyNotfound";
|
|
394
|
+
ObjectErrorCode2["RequestTimeOut"] = "RequestTimeOut";
|
|
395
|
+
return ObjectErrorCode2;
|
|
396
|
+
})(ObjectErrorCode || {});
|
|
397
|
+
class ObjectError {
|
|
398
|
+
/**
|
|
399
|
+
* @description 错误载荷
|
|
400
|
+
*/
|
|
401
|
+
constructor(result) {
|
|
402
|
+
_defineProperty(this, "err_msg", "");
|
|
403
|
+
this.code = result.code;
|
|
404
|
+
this.err_msg = result.err_msg;
|
|
405
|
+
this.err_values = result.err_values;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
const fetch = Fetch.create();
|
|
409
|
+
const fetchBase = (path, params) => {
|
|
410
|
+
return Promise.all([getPlatformAPIHost(), getInstanceId()]).then((_ref) => {
|
|
411
|
+
let [base, instance_id] = _ref;
|
|
412
|
+
if (base && instance_id) {
|
|
413
|
+
const url = `${base}${path}`;
|
|
414
|
+
const data = {
|
|
415
|
+
...params,
|
|
416
|
+
instance_id
|
|
417
|
+
};
|
|
418
|
+
return fetch.post(url, data);
|
|
419
|
+
}
|
|
420
|
+
throw new Error(JSON.stringify({
|
|
421
|
+
base,
|
|
422
|
+
instance_id
|
|
423
|
+
}));
|
|
424
|
+
}).then((response) => {
|
|
425
|
+
return response.data;
|
|
426
|
+
}).catch((error) => {
|
|
427
|
+
if (error instanceof Fetch.AxiosError) {
|
|
428
|
+
const $error = error;
|
|
429
|
+
const data = $error.response.data;
|
|
430
|
+
if (data.code) {
|
|
431
|
+
return data;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
const message = createErrorResult(ErrorCode.ServerError, error);
|
|
435
|
+
return message;
|
|
436
|
+
});
|
|
437
|
+
};
|
|
438
|
+
const fetchUpload = (params) => {
|
|
439
|
+
return fetchBase("/plugin_ability_fetch/storage/object/get_upload_policy_info", params);
|
|
440
|
+
};
|
|
441
|
+
const fetchDownload = (params) => {
|
|
442
|
+
return fetchBase("/plugin_ability_fetch/storage/object/get_download_pre_signed_url", params);
|
|
443
|
+
};
|
|
444
|
+
const fetchDelete = (params) => {
|
|
445
|
+
return fetchBase("/plugin_ability_fetch/storage/object/delete", params);
|
|
446
|
+
};
|
|
447
|
+
const fetchMetadata = (params) => {
|
|
448
|
+
return fetchBase("/plugin_ability_fetch/storage/object/get_metadata", params);
|
|
449
|
+
};
|
|
450
|
+
const object = {
|
|
451
|
+
ObjectError,
|
|
452
|
+
ObjectErrorCode,
|
|
453
|
+
upload: async (key) => {
|
|
454
|
+
const result = await fetchUpload({
|
|
455
|
+
object_key: key
|
|
456
|
+
});
|
|
457
|
+
if (result.code === "OK") {
|
|
458
|
+
if (result.data) {
|
|
459
|
+
const {
|
|
460
|
+
url,
|
|
461
|
+
fields
|
|
462
|
+
} = result.data;
|
|
463
|
+
const {
|
|
464
|
+
internal,
|
|
465
|
+
outbound
|
|
466
|
+
} = url;
|
|
467
|
+
if (internal && outbound) {
|
|
468
|
+
return {
|
|
469
|
+
getUrl: () => internal,
|
|
470
|
+
getWebUrl: () => outbound,
|
|
471
|
+
getFields: () => ({
|
|
472
|
+
...fields
|
|
473
|
+
})
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
return new ObjectError(createErrorResult(ErrorCode.ServerError, "", {
|
|
478
|
+
err_values: result
|
|
479
|
+
}));
|
|
480
|
+
}
|
|
481
|
+
return new ObjectError(result);
|
|
482
|
+
},
|
|
483
|
+
download: async (key) => {
|
|
484
|
+
const result = await fetchDownload({
|
|
485
|
+
object_key: key
|
|
486
|
+
});
|
|
487
|
+
if (result.code === "OK") {
|
|
488
|
+
if (result.data) {
|
|
489
|
+
const {
|
|
490
|
+
url
|
|
491
|
+
} = result.data;
|
|
492
|
+
const {
|
|
493
|
+
internal,
|
|
494
|
+
outbound
|
|
495
|
+
} = url;
|
|
496
|
+
if (internal && outbound) {
|
|
497
|
+
return {
|
|
498
|
+
getUrl: () => internal,
|
|
499
|
+
getWebUrl: () => outbound
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
return new ObjectError(createErrorResult(ErrorCode.ServerError, "", {
|
|
504
|
+
err_values: result
|
|
505
|
+
}));
|
|
506
|
+
}
|
|
507
|
+
return new ObjectError(result);
|
|
508
|
+
},
|
|
509
|
+
delete: async (key) => {
|
|
510
|
+
const result = await fetchDelete({
|
|
511
|
+
object_key: key
|
|
512
|
+
});
|
|
513
|
+
if (result.code === "OK") {
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
return new ObjectError(result);
|
|
517
|
+
},
|
|
518
|
+
metadata: async (key) => {
|
|
519
|
+
const result = await fetchMetadata({
|
|
520
|
+
object_key: key
|
|
521
|
+
});
|
|
522
|
+
if (result.code === "OK") {
|
|
523
|
+
if (result.data) {
|
|
524
|
+
return result.data;
|
|
525
|
+
}
|
|
526
|
+
return new ObjectError(createErrorResult(ErrorCode.ServerError, "", {
|
|
527
|
+
err_values: result
|
|
528
|
+
}));
|
|
529
|
+
}
|
|
530
|
+
return new ObjectError(result);
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
534
|
+
__proto__: null,
|
|
535
|
+
entity,
|
|
536
|
+
object
|
|
537
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
538
|
+
exports.ErrorCode = ErrorCode;
|
|
539
|
+
exports.env = index$1;
|
|
540
|
+
exports.storage = index;
|