@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.
Files changed (82) hide show
  1. package/LICENSE +201 -0
  2. package/dist/index.cjs +538 -2
  3. package/dist/index.js +538 -2
  4. package/dist/types/index.d.ts +1 -1
  5. package/dist/types/index.d.ts.map +1 -1
  6. package/dist/types/packages/node/index.d.ts +5 -0
  7. package/dist/types/packages/node/index.d.ts.map +1 -0
  8. package/dist/types/packages/node/storage/entity/entity/index.d.ts +13 -0
  9. package/dist/types/packages/node/storage/entity/entity/index.d.ts.map +1 -0
  10. package/dist/types/packages/node/storage/entity/entity/types.d.ts +68 -0
  11. package/dist/types/packages/node/storage/entity/entity/types.d.ts.map +1 -0
  12. package/dist/types/packages/node/storage/entity/error/consts.d.ts +127 -0
  13. package/dist/types/packages/node/storage/entity/error/consts.d.ts.map +1 -0
  14. package/dist/types/packages/node/storage/entity/error/index.d.ts +2 -0
  15. package/dist/types/packages/node/storage/entity/error/index.d.ts.map +1 -0
  16. package/dist/types/packages/node/storage/entity/fetch/index.d.ts +7 -0
  17. package/dist/types/packages/node/storage/entity/fetch/index.d.ts.map +1 -0
  18. package/dist/types/packages/node/storage/entity/fetch/types.d.ts +50 -0
  19. package/dist/types/packages/node/storage/entity/fetch/types.d.ts.map +1 -0
  20. package/dist/types/packages/node/storage/entity/index.d.ts +23 -0
  21. package/dist/types/packages/node/storage/entity/index.d.ts.map +1 -0
  22. package/dist/types/packages/node/storage/entity/query/consts.d.ts +6 -0
  23. package/dist/types/packages/node/storage/entity/query/consts.d.ts.map +1 -0
  24. package/dist/types/packages/node/storage/entity/query/index.d.ts +27 -0
  25. package/dist/types/packages/node/storage/entity/query/index.d.ts.map +1 -0
  26. package/dist/types/packages/node/storage/entity/query/types.d.ts +174 -0
  27. package/dist/types/packages/node/storage/entity/query/types.d.ts.map +1 -0
  28. package/dist/types/packages/node/storage/entity/result/index.d.ts +2 -0
  29. package/dist/types/packages/node/storage/entity/result/index.d.ts.map +1 -0
  30. package/dist/types/packages/node/storage/entity/result/types.d.ts +53 -0
  31. package/dist/types/packages/node/storage/entity/result/types.d.ts.map +1 -0
  32. package/dist/types/packages/node/storage/entity/sort/consts.d.ts +15 -0
  33. package/dist/types/packages/node/storage/entity/sort/consts.d.ts.map +1 -0
  34. package/dist/types/packages/node/storage/entity/sort/index.d.ts +2 -0
  35. package/dist/types/packages/node/storage/entity/sort/index.d.ts.map +1 -0
  36. package/dist/types/packages/node/storage/entity/static.d.ts +3 -0
  37. package/dist/types/packages/node/storage/entity/static.d.ts.map +1 -0
  38. package/dist/types/packages/node/storage/entity/types.d.ts +114 -0
  39. package/dist/types/packages/node/storage/entity/types.d.ts.map +1 -0
  40. package/dist/types/packages/node/storage/entity/where/consts.d.ts +11 -0
  41. package/dist/types/packages/node/storage/entity/where/consts.d.ts.map +1 -0
  42. package/dist/types/packages/node/storage/entity/where/index.d.ts +50 -0
  43. package/dist/types/packages/node/storage/entity/where/index.d.ts.map +1 -0
  44. package/dist/types/packages/node/storage/entity/where/types.d.ts +13 -0
  45. package/dist/types/packages/node/storage/entity/where/types.d.ts.map +1 -0
  46. package/dist/types/packages/node/storage/index.d.ts +5 -0
  47. package/dist/types/packages/node/storage/index.d.ts.map +1 -0
  48. package/dist/types/packages/node/storage/object/error/consts.d.ts +20 -0
  49. package/dist/types/packages/node/storage/object/error/consts.d.ts.map +1 -0
  50. package/dist/types/packages/node/storage/object/error/index.d.ts +22 -0
  51. package/dist/types/packages/node/storage/object/error/index.d.ts.map +1 -0
  52. package/dist/types/packages/node/storage/object/error/types.d.ts +4 -0
  53. package/dist/types/packages/node/storage/object/error/types.d.ts.map +1 -0
  54. package/dist/types/packages/node/storage/object/fetch/index.d.ts +7 -0
  55. package/dist/types/packages/node/storage/object/fetch/index.d.ts.map +1 -0
  56. package/dist/types/packages/node/storage/object/fetch/types.d.ts +34 -0
  57. package/dist/types/packages/node/storage/object/fetch/types.d.ts.map +1 -0
  58. package/dist/types/packages/node/storage/object/index.d.ts +17 -0
  59. package/dist/types/packages/node/storage/object/index.d.ts.map +1 -0
  60. package/dist/types/packages/node/storage/object/result/index.d.ts +2 -0
  61. package/dist/types/packages/node/storage/object/result/index.d.ts.map +1 -0
  62. package/dist/types/packages/node/storage/object/result/types.d.ts +31 -0
  63. package/dist/types/packages/node/storage/object/result/types.d.ts.map +1 -0
  64. package/dist/types/packages/node/storage/object/types.d.ts +66 -0
  65. package/dist/types/packages/node/storage/object/types.d.ts.map +1 -0
  66. package/dist/types/packages/strict/common/index.d.ts +2 -0
  67. package/dist/types/packages/strict/common/index.d.ts.map +1 -0
  68. package/dist/types/packages/strict/common/types.d.ts +6 -0
  69. package/dist/types/packages/strict/common/types.d.ts.map +1 -0
  70. package/dist/types/packages/strict/env/index.d.ts +35 -0
  71. package/dist/types/packages/strict/env/index.d.ts.map +1 -0
  72. package/dist/types/packages/strict/error/consts.d.ts +5 -0
  73. package/dist/types/packages/strict/error/consts.d.ts.map +1 -0
  74. package/dist/types/packages/strict/error/index.d.ts +2 -0
  75. package/dist/types/packages/strict/error/index.d.ts.map +1 -0
  76. package/dist/types/packages/strict/fetch/index.d.ts +4 -0
  77. package/dist/types/packages/strict/fetch/index.d.ts.map +1 -0
  78. package/dist/types/packages/strict/result/index.d.ts +8 -0
  79. package/dist/types/packages/strict/result/index.d.ts.map +1 -0
  80. package/dist/types/packages/strict/result/types.d.ts +31 -0
  81. package/dist/types/packages/strict/result/types.d.ts.map +1 -0
  82. package/package.json +12 -2
package/dist/index.js CHANGED
@@ -1,4 +1,540 @@
1
- const ONES = "ONES";
1
+ import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
2
+ import { isNull, isUndefined, isSymbol, set } from "lodash-es";
3
+ import Fetch, { AxiosError } from "axios";
4
+ import _sortInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/sort";
5
+ const getPlatformApiHost = () => {
6
+ return "platformApiHost";
7
+ };
8
+ const getPlatformAPIHost = getPlatformApiHost;
9
+ const getInstanceId = () => {
10
+ return "instanceId";
11
+ };
12
+ const getApplicationId = () => {
13
+ return "applicationId";
14
+ };
15
+ const getAppId = getApplicationId;
16
+ const index$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
17
+ __proto__: null,
18
+ getAppId,
19
+ getApplicationId,
20
+ getInstanceId,
21
+ getPlatformAPIHost,
22
+ getPlatformApiHost
23
+ }, Symbol.toStringTag, { value: "Module" }));
24
+ var EntityWhereConditionEnum = /* @__PURE__ */ ((EntityWhereConditionEnum2) => {
25
+ EntityWhereConditionEnum2["beginsWith"] = "beginsWith";
26
+ EntityWhereConditionEnum2["between"] = "between";
27
+ EntityWhereConditionEnum2["equalTo"] = "equalTo";
28
+ EntityWhereConditionEnum2["greaterThan"] = "greaterThan";
29
+ EntityWhereConditionEnum2["lessThan"] = "lessThan";
30
+ EntityWhereConditionEnum2["greaterThanEqualTo"] = "greaterThanEqualTo";
31
+ EntityWhereConditionEnum2["lessThanEqualTo"] = "lessThanEqualTo";
32
+ EntityWhereConditionEnum2["containsAny"] = "containsAny";
33
+ return EntityWhereConditionEnum2;
34
+ })(EntityWhereConditionEnum || {});
35
+ const WhereConditions = {
36
+ /**
37
+ * @description beginsWith
38
+ * @returns EntityWhereCondition
39
+ */
40
+ [EntityWhereConditionEnum.beginsWith]: (value) => {
41
+ return {
42
+ [EntityWhereConditionEnum.beginsWith]: [value]
43
+ };
44
+ },
45
+ /**
46
+ * @description between
47
+ * @returns EntityWhereCondition
48
+ */
49
+ [EntityWhereConditionEnum.between]: (min, max) => {
50
+ return {
51
+ [EntityWhereConditionEnum.between]: [min, max]
52
+ };
53
+ },
54
+ /**
55
+ * @description equalTo
56
+ * @returns EntityWhereCondition
57
+ */
58
+ [EntityWhereConditionEnum.equalTo]: (value) => {
59
+ return {
60
+ [EntityWhereConditionEnum.equalTo]: [value]
61
+ };
62
+ },
63
+ /**
64
+ * @description greaterThan
65
+ * @returns EntityWhereCondition
66
+ */
67
+ [EntityWhereConditionEnum.greaterThan]: (value) => {
68
+ return {
69
+ [EntityWhereConditionEnum.greaterThan]: [value]
70
+ };
71
+ },
72
+ /**
73
+ * @description lessThan
74
+ * @returns EntityWhereCondition
75
+ */
76
+ [EntityWhereConditionEnum.lessThan]: (value) => {
77
+ return {
78
+ [EntityWhereConditionEnum.lessThan]: [value]
79
+ };
80
+ },
81
+ /**
82
+ * @description greaterThanEqualTo
83
+ * @returns EntityWhereCondition
84
+ */
85
+ [EntityWhereConditionEnum.greaterThanEqualTo]: (value) => {
86
+ return {
87
+ [EntityWhereConditionEnum.greaterThanEqualTo]: [value]
88
+ };
89
+ },
90
+ /**
91
+ * @description lessThanEqualTo
92
+ * @returns EntityWhereCondition
93
+ */
94
+ [EntityWhereConditionEnum.lessThanEqualTo]: (value) => {
95
+ return {
96
+ [EntityWhereConditionEnum.lessThanEqualTo]: [value]
97
+ };
98
+ },
99
+ /**
100
+ * @description containsAny
101
+ * @returns EntityWhereCondition
102
+ */
103
+ [EntityWhereConditionEnum.containsAny]: function() {
104
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
105
+ args[_key] = arguments[_key];
106
+ }
107
+ return {
108
+ [EntityWhereConditionEnum.containsAny]: [...args]
109
+ };
110
+ }
111
+ };
112
+ var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
113
+ ErrorCode2["ServerError"] = "ServerError";
114
+ ErrorCode2["UnknownError"] = "UnknownError";
115
+ return ErrorCode2;
116
+ })(ErrorCode || {});
117
+ const createErrorResult = (code, message, error) => {
118
+ return Object.assign({}, {
119
+ code,
120
+ err_msg: `${message}`
121
+ }, error);
122
+ };
123
+ const fetch$1 = Fetch.create();
124
+ const fetchBase$1 = (path, params, config) => {
125
+ return Promise.all([getPlatformAPIHost(), getInstanceId()]).then((_ref) => {
126
+ let [base, instance_id] = _ref;
127
+ if (base && instance_id) {
128
+ const url = `${base}${path}`;
129
+ const data = {
130
+ ...params,
131
+ instance_id
132
+ };
133
+ return fetch$1({
134
+ ...config,
135
+ url,
136
+ data
137
+ });
138
+ }
139
+ throw new Error(JSON.stringify({
140
+ base,
141
+ instance_id
142
+ }));
143
+ }).then((response) => {
144
+ return response.data;
145
+ }).catch((error) => {
146
+ if (error instanceof AxiosError) {
147
+ const $error = error;
148
+ const data = $error.response.data;
149
+ if (data.code) {
150
+ return data;
151
+ }
152
+ }
153
+ const message = createErrorResult(ErrorCode.ServerError, error);
154
+ return message;
155
+ });
156
+ };
157
+ const fetchPost = (params) => {
158
+ return fetchBase$1("/plugin_ability_fetch/storage/entity_data", params, {
159
+ method: "post"
160
+ });
161
+ };
162
+ const fetchDelete$1 = (params) => {
163
+ return fetchBase$1("/plugin_ability_fetch/storage/entity_data", params, {
164
+ method: "delete"
165
+ });
166
+ };
167
+ const fetchQuery = (params) => {
168
+ return fetchBase$1("/plugin_ability_fetch/storage/entity_data/get_many", params, {
169
+ method: "post"
170
+ });
171
+ };
172
+ const fetchCount = (params) => {
173
+ return fetchBase$1("/plugin_ability_fetch/storage/entity_data/count", params, {
174
+ method: "post"
175
+ });
176
+ };
177
+ const defaultEntityQuery = {
178
+ cursor: Symbol("cursor"),
179
+ limit: Symbol("limit"),
180
+ sort: Symbol("sort"),
181
+ index: Symbol("index"),
182
+ where: Symbol("where")
183
+ };
184
+ const defaultEntityQueryCursor = defaultEntityQuery.cursor;
185
+ const defaultEntityQueryLimit = defaultEntityQuery.limit;
186
+ const defaultEntityQuerySort = _sortInstanceProperty(defaultEntityQuery);
187
+ const defaultEntityQueryIndex = defaultEntityQuery.index;
188
+ const defaultEntityQueryWhere = defaultEntityQuery.where;
189
+ class EntityQueryClass {
190
+ constructor(name) {
191
+ _defineProperty(this, "_name", "");
192
+ _defineProperty(this, "_cursor", [defaultEntityQueryCursor]);
193
+ _defineProperty(this, "_limit", [defaultEntityQueryLimit]);
194
+ _defineProperty(this, "_sort", [defaultEntityQuerySort]);
195
+ _defineProperty(this, "_index", [defaultEntityQueryIndex]);
196
+ _defineProperty(this, "_where", [defaultEntityQueryWhere]);
197
+ this._name = name;
198
+ }
199
+ cursor(cursor) {
200
+ this._cursor = [cursor];
201
+ return this;
202
+ }
203
+ limit(limit) {
204
+ this._limit = [limit];
205
+ return this;
206
+ }
207
+ sort(sort) {
208
+ this._sort = [sort];
209
+ return this;
210
+ }
211
+ index(index2, partitions) {
212
+ if (typeof index2 === "string") {
213
+ if (partitions) {
214
+ this._index = [index2, partitions];
215
+ return this;
216
+ }
217
+ }
218
+ this._index = [index2];
219
+ return this;
220
+ }
221
+ where(where) {
222
+ this._where = [where];
223
+ return this;
224
+ }
225
+ _getParams() {
226
+ const data = {
227
+ index: {}
228
+ };
229
+ 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"]];
230
+ array.forEach((item) => {
231
+ const [value, path] = item;
232
+ if (isNull(value) || isUndefined(value) || isSymbol(value))
233
+ ;
234
+ else {
235
+ set(data, path, value);
236
+ }
237
+ });
238
+ const result = {
239
+ entity_name: this._name,
240
+ data
241
+ };
242
+ return result;
243
+ }
244
+ async getOne() {
245
+ const params = this._getParams();
246
+ params.data.limit = 1;
247
+ const result = await fetchQuery(params);
248
+ const {
249
+ code,
250
+ data
251
+ } = result;
252
+ if (code === "OK") {
253
+ var _data$data;
254
+ return data === null || data === void 0 || (_data$data = data.data) === null || _data$data === void 0 ? void 0 : _data$data[0];
255
+ }
256
+ throw result;
257
+ }
258
+ async getMany() {
259
+ const params = this._getParams();
260
+ const result = await fetchQuery(params);
261
+ const {
262
+ code,
263
+ data
264
+ } = result;
265
+ if (code === "OK") {
266
+ if (data) {
267
+ return data;
268
+ }
269
+ }
270
+ throw result;
271
+ }
272
+ async count() {
273
+ const params = this._getParams();
274
+ const result = await fetchCount(params);
275
+ const {
276
+ code,
277
+ data
278
+ } = result;
279
+ if (code === "OK") {
280
+ const number = data === null || data === void 0 ? void 0 : data.count;
281
+ if (typeof number === "number") {
282
+ return number;
283
+ }
284
+ }
285
+ throw result;
286
+ }
287
+ }
288
+ class EntityClass {
289
+ constructor(name) {
290
+ _defineProperty(this, "_name", "");
291
+ this._name = name;
292
+ }
293
+ async get(key) {
294
+ const query = this.query();
295
+ return await query.index(defaultEntityQueryIndex).where(WhereConditions.equalTo(key)).getOne().then((data) => {
296
+ return data === null || data === void 0 ? void 0 : data.value;
297
+ });
298
+ }
299
+ async set(key, value) {
300
+ const item = {
301
+ key,
302
+ value
303
+ };
304
+ await this.batchSet([item]);
305
+ }
306
+ async delete(key) {
307
+ await this.batchDelete([key]);
308
+ }
309
+ query() {
310
+ return new EntityQueryClass(this._name);
311
+ }
312
+ async batchSet(items) {
313
+ const result = await fetchPost({
314
+ entity_name: this._name,
315
+ data: items
316
+ });
317
+ const {
318
+ code
319
+ } = result;
320
+ if (code !== "OK") {
321
+ throw result;
322
+ }
323
+ }
324
+ async batchDelete(keys) {
325
+ const result = await fetchDelete$1({
326
+ entity_name: this._name,
327
+ data: keys
328
+ });
329
+ const {
330
+ code
331
+ } = result;
332
+ if (code !== "OK") {
333
+ throw result;
334
+ }
335
+ }
336
+ }
337
+ var EntitySortEnum = /* @__PURE__ */ ((EntitySortEnum2) => {
338
+ EntitySortEnum2["ASC"] = "ASC";
339
+ EntitySortEnum2["DESC"] = "DESC";
340
+ return EntitySortEnum2;
341
+ })(EntitySortEnum || {});
342
+ var EntityErrorCode = /* @__PURE__ */ ((EntityErrorCode2) => {
343
+ EntityErrorCode2["EntityNameInvalid"] = "EntityNameInvalid";
344
+ EntityErrorCode2["EntityNotFound"] = "EntityNotFound";
345
+ EntityErrorCode2["EntityDataEmpty"] = "EntityDataEmpty";
346
+ EntityErrorCode2["EntityDataBatchLimit"] = "EntityDataBatchLimit";
347
+ EntityErrorCode2["EntityDataKeyInvalid"] = "EntityDataKeyInvalid";
348
+ EntityErrorCode2["EntityDataKeyDuplicate"] = "EntityDataKeyDuplicate";
349
+ EntityErrorCode2["EntityDataValueAttrInvalid"] = "EntityDataValueAttrInvalid";
350
+ EntityErrorCode2["EntityDataValueAttrNotFound"] = "EntityDataValueAttrNotFound";
351
+ EntityErrorCode2["EntityDataValueEmpty"] = "EntityDataValueEmpty";
352
+ EntityErrorCode2["EntityDataValueInvalid"] = "EntityDataValueInvalid";
353
+ EntityErrorCode2["EntityDataStringValueTooLong"] = "EntityDataStringValueTooLong";
354
+ EntityErrorCode2["EntityDataTextValueTooLong"] = "EntityDataTextValueTooLong";
355
+ EntityErrorCode2["EntityDataAttrRequired"] = "EntityDataAttrRequired";
356
+ EntityErrorCode2["EntityDataValueTypeInvalid"] = "EntityDataValueTypeInvalid";
357
+ EntityErrorCode2["EntityDataIndexEmpty"] = "EntityDataIndexEmpty";
358
+ EntityErrorCode2["EntityDataIndexNameInvalid"] = "EntityDataIndexNameInvalid";
359
+ EntityErrorCode2["EntityDataIndexNotFound"] = "EntityDataIndexNotFound";
360
+ EntityErrorCode2["EntityDataPartitionValueInvalid"] = "EntityDataPartitionValueInvalid";
361
+ EntityErrorCode2["EntityDataPartitionValueTypeInvalid"] = "EntityDataPartitionValueTypeInvalid";
362
+ EntityErrorCode2["EntityDataPartitionValueTooLong"] = "EntityDataPartitionValueTooLong";
363
+ EntityErrorCode2["EntityDataUniqueConstraintFailed"] = "EntityDataUniqueConstraintFailed";
364
+ EntityErrorCode2["EntityDataWhereConditionValueTypeInvalid"] = "EntityDataWhereConditionValueTypeInvalid";
365
+ EntityErrorCode2["EntityDataWhereConditionValueTooLong"] = "EntityDataWhereConditionValueTooLong";
366
+ EntityErrorCode2["EntityDataPageCursorInvalid"] = "EntityDataPageCursorInvalid";
367
+ EntityErrorCode2["EntityDataSortValueInvalid"] = "EntityDataSortValueInvalid";
368
+ EntityErrorCode2["EntityDataPageLimitNotInRange"] = "EntityDataPageLimitNotInRange";
369
+ EntityErrorCode2["EntityDataAPITimeOut"] = "EntityDataAPITimeOut";
370
+ EntityErrorCode2["MalformedJSON"] = "Malformed.JSON";
371
+ return EntityErrorCode2;
372
+ })(EntityErrorCode || {});
373
+ const entityStatic = {
374
+ Sort: EntitySortEnum,
375
+ EntityErrorCode,
376
+ WhereConditions,
377
+ defaultEntityQueryCursor,
378
+ defaultEntityQueryIndex,
379
+ defaultEntityQueryLimit,
380
+ defaultEntityQuerySort,
381
+ defaultEntityQueryWhere
382
+ };
383
+ function factory(entityName) {
384
+ return new EntityClass(entityName);
385
+ }
386
+ const entityFactory = factory;
387
+ const entityDefault = Object.assign(entityFactory, entityStatic);
388
+ const entity = entityDefault;
389
+ var ObjectErrorCode = /* @__PURE__ */ ((ObjectErrorCode2) => {
390
+ ObjectErrorCode2["ObjectKeyInvalid"] = "ObjectKeyInvalid";
391
+ ObjectErrorCode2["ObjectKeyNotfound"] = "ObjectKeyNotfound";
392
+ ObjectErrorCode2["RequestTimeOut"] = "RequestTimeOut";
393
+ return ObjectErrorCode2;
394
+ })(ObjectErrorCode || {});
395
+ class ObjectError {
396
+ /**
397
+ * @description 错误载荷
398
+ */
399
+ constructor(result) {
400
+ _defineProperty(this, "err_msg", "");
401
+ this.code = result.code;
402
+ this.err_msg = result.err_msg;
403
+ this.err_values = result.err_values;
404
+ }
405
+ }
406
+ const fetch = Fetch.create();
407
+ const fetchBase = (path, params) => {
408
+ return Promise.all([getPlatformAPIHost(), getInstanceId()]).then((_ref) => {
409
+ let [base, instance_id] = _ref;
410
+ if (base && instance_id) {
411
+ const url = `${base}${path}`;
412
+ const data = {
413
+ ...params,
414
+ instance_id
415
+ };
416
+ return fetch.post(url, data);
417
+ }
418
+ throw new Error(JSON.stringify({
419
+ base,
420
+ instance_id
421
+ }));
422
+ }).then((response) => {
423
+ return response.data;
424
+ }).catch((error) => {
425
+ if (error instanceof AxiosError) {
426
+ const $error = error;
427
+ const data = $error.response.data;
428
+ if (data.code) {
429
+ return data;
430
+ }
431
+ }
432
+ const message = createErrorResult(ErrorCode.ServerError, error);
433
+ return message;
434
+ });
435
+ };
436
+ const fetchUpload = (params) => {
437
+ return fetchBase("/plugin_ability_fetch/storage/object/get_upload_policy_info", params);
438
+ };
439
+ const fetchDownload = (params) => {
440
+ return fetchBase("/plugin_ability_fetch/storage/object/get_download_pre_signed_url", params);
441
+ };
442
+ const fetchDelete = (params) => {
443
+ return fetchBase("/plugin_ability_fetch/storage/object/delete", params);
444
+ };
445
+ const fetchMetadata = (params) => {
446
+ return fetchBase("/plugin_ability_fetch/storage/object/get_metadata", params);
447
+ };
448
+ const object = {
449
+ ObjectError,
450
+ ObjectErrorCode,
451
+ upload: async (key) => {
452
+ const result = await fetchUpload({
453
+ object_key: key
454
+ });
455
+ if (result.code === "OK") {
456
+ if (result.data) {
457
+ const {
458
+ url,
459
+ fields
460
+ } = result.data;
461
+ const {
462
+ internal,
463
+ outbound
464
+ } = url;
465
+ if (internal && outbound) {
466
+ return {
467
+ getUrl: () => internal,
468
+ getWebUrl: () => outbound,
469
+ getFields: () => ({
470
+ ...fields
471
+ })
472
+ };
473
+ }
474
+ }
475
+ return new ObjectError(createErrorResult(ErrorCode.ServerError, "", {
476
+ err_values: result
477
+ }));
478
+ }
479
+ return new ObjectError(result);
480
+ },
481
+ download: async (key) => {
482
+ const result = await fetchDownload({
483
+ object_key: key
484
+ });
485
+ if (result.code === "OK") {
486
+ if (result.data) {
487
+ const {
488
+ url
489
+ } = result.data;
490
+ const {
491
+ internal,
492
+ outbound
493
+ } = url;
494
+ if (internal && outbound) {
495
+ return {
496
+ getUrl: () => internal,
497
+ getWebUrl: () => outbound
498
+ };
499
+ }
500
+ }
501
+ return new ObjectError(createErrorResult(ErrorCode.ServerError, "", {
502
+ err_values: result
503
+ }));
504
+ }
505
+ return new ObjectError(result);
506
+ },
507
+ delete: async (key) => {
508
+ const result = await fetchDelete({
509
+ object_key: key
510
+ });
511
+ if (result.code === "OK") {
512
+ return;
513
+ }
514
+ return new ObjectError(result);
515
+ },
516
+ metadata: async (key) => {
517
+ const result = await fetchMetadata({
518
+ object_key: key
519
+ });
520
+ if (result.code === "OK") {
521
+ if (result.data) {
522
+ return result.data;
523
+ }
524
+ return new ObjectError(createErrorResult(ErrorCode.ServerError, "", {
525
+ err_values: result
526
+ }));
527
+ }
528
+ return new ObjectError(result);
529
+ }
530
+ };
531
+ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
532
+ __proto__: null,
533
+ entity,
534
+ object
535
+ }, Symbol.toStringTag, { value: "Module" }));
2
536
  export {
3
- ONES
537
+ ErrorCode,
538
+ index$1 as env,
539
+ index as storage
4
540
  };
@@ -1,2 +1,2 @@
1
- export declare const ONES = "ONES";
1
+ export * from './packages/node';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
@@ -0,0 +1,5 @@
1
+ export * as env from '../../packages/strict/env';
2
+ export * as storage from './storage';
3
+ export { ErrorCode } from '../../packages/strict/error';
4
+ export type { Entity, EntityBatchSetItem, EntityQuery, EntityListResultData, EntityError, ObjectError, ObjectStoreUploadResult, ObjectStoreDownloadResult, } from './storage';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/packages/node/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,uBAAuB,CAAA;AAC5C,OAAO,KAAK,OAAO,MAAM,WAAW,CAAA;AAEpC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAEnD,YAAY,EACV,MAAM,EACN,kBAAkB,EAClB,WAAW,EACX,oBAAoB,EACpB,WAAW,EACX,WAAW,EACX,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,WAAW,CAAA"}
@@ -0,0 +1,13 @@
1
+ import type { Entity, EntityPrivate, EntityBatchSetItem, BaseEntityStruct, BaseIndexesStruct } from './types';
2
+ export * from './types';
3
+ export declare class EntityClass<EntityStruct extends BaseEntityStruct<EntityStruct>, IndexesStruct extends BaseIndexesStruct<IndexesStruct>> implements Entity<EntityStruct, IndexesStruct>, EntityPrivate {
4
+ _name: string;
5
+ constructor(name: string);
6
+ get(key: string): Promise<EntityStruct | undefined>;
7
+ set(key: string, value: Partial<EntityStruct>): Promise<void>;
8
+ delete(key: string): Promise<void>;
9
+ query(): import("type-fest").IfNull<IndexesStruct, import("../../../../../packages/node/storage/entity/query").BaseEntityQuery<EntityStruct, import("type-fest").EmptyObject>, import("type-fest").IfEmptyObject<IndexesStruct, import("../../../../../packages/node/storage/entity/query").InputIndexEntityQuery<EntityStruct, import("type-fest").EmptyObject>, import("../../../../../packages/node/storage/entity/query").InferIndexEntityQuery<EntityStruct, Exclude<IndexesStruct, import("type-fest").EmptyObject | null>>>>;
10
+ batchSet(items: EntityBatchSetItem<EntityStruct>[]): Promise<void>;
11
+ batchDelete(keys: string[]): Promise<void>;
12
+ }
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../src/packages/node/storage/entity/entity/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,MAAM,EACN,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EAElB,MAAM,SAAS,CAAA;AAEhB,cAAc,SAAS,CAAA;AAEvB,qBAAa,WAAW,CACpB,YAAY,SAAS,gBAAgB,CAAC,YAAY,CAAC,EACnD,aAAa,SAAS,iBAAiB,CAAC,aAAa,CAAC,CAExD,YAAW,MAAM,CAAC,YAAY,EAAE,aAAa,CAAC,EAAE,aAAa;IAE7D,KAAK,SAAK;gBAEE,IAAI,EAAE,MAAM;IAGlB,GAAG,CAAC,GAAG,EAAE,MAAM;IAUf,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,YAAY,CAAC;IAO7C,MAAM,CAAC,GAAG,EAAE,MAAM;IAGxB,KAAK;IAKC,QAAQ,CAAC,KAAK,EAAE,kBAAkB,CAAC,YAAY,CAAC,EAAE;IAUlD,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE;CAUjC"}
@@ -0,0 +1,68 @@
1
+ import type { SetFieldType, EmptyObject, IfEmptyObject, IfNull } from 'type-fest';
2
+ import type { StringOrNumberOrBoolean, NotEmptyString, NotEmptyArray } from '../../../../../packages/strict/common';
3
+ import type { BaseEntityQuery, InferIndexEntityQuery, InputIndexEntityQuery } from '../../../../../packages/node/storage/entity/query';
4
+ export type BaseEntityStructValue = StringOrNumberOrBoolean;
5
+ export type BaseEntityStruct<EntityStruct> = SetFieldType<EntityStruct, keyof EntityStruct, BaseEntityStructValue>;
6
+ export type BaseIndexesStructValue = null | StringOrNumberOrBoolean[] | [StringOrNumberOrBoolean, ...StringOrNumberOrBoolean[]];
7
+ export type BaseIndexesStruct<IndexesStruct> = SetFieldType<IndexesStruct, keyof IndexesStruct, BaseIndexesStructValue>;
8
+ export type UnionIndexesStruct<IndexesStruct> = BaseIndexesStruct<IndexesStruct> | EmptyObject | null;
9
+ /**
10
+ * @description 实体操作对象
11
+ * @typedef EntityStruct 实体数据结构体
12
+ * @typedef IndexesStruct 实体索引结构体
13
+ */
14
+ export interface Entity<EntityStruct extends BaseEntityStruct<EntityStruct>, IndexesStruct extends UnionIndexesStruct<IndexesStruct>> {
15
+ /**
16
+ * @description 获取一条实体数据
17
+ * @param key 实体数据 key
18
+ * @returns 实体数据 value
19
+ */
20
+ get<Key extends string>(key: NotEmptyString<Key>): Promise<EntityStruct | undefined>;
21
+ /**
22
+ * @description 创建或者更新一条实体数据
23
+ * @param key 实体数据 key
24
+ * @param value 实体数据 value
25
+ */
26
+ set<Key extends string>(key: NotEmptyString<Key>, value: Partial<EntityStruct>): Promise<void>;
27
+ /**
28
+ * @description 删除一条实体数据
29
+ * @param key 实体数据 key
30
+ */
31
+ delete<Key extends string>(key: NotEmptyString<Key>): Promise<void>;
32
+ /**
33
+ * @description 创建实体查询对象
34
+ * @returns EntityQuery
35
+ */
36
+ query(): IfNull<IndexesStruct, BaseEntityQuery<EntityStruct, EmptyObject>, IfEmptyObject<IndexesStruct, InputIndexEntityQuery<EntityStruct, EmptyObject>, InferIndexEntityQuery<EntityStruct, Exclude<IndexesStruct, EmptyObject | null>>>>;
37
+ /**
38
+ * @description 批量创建或者更新实体数据
39
+ * @param items 数组
40
+ */
41
+ batchSet<Items extends EntityBatchSetItem<EntityStruct>[]>(items: NotEmptyArray<Items>): Promise<void>;
42
+ /**
43
+ * @description 批量删除实体数据
44
+ * @param keys 实体数据 key 数组
45
+ */
46
+ batchDelete<Keys extends string[]>(keys: NotEmptyArray<Keys>): Promise<void>;
47
+ }
48
+ /**
49
+ * @description 批量创建或者更新实体数据的 item
50
+ * @typedef EntityStruct 实体数据结构体
51
+ */
52
+ export interface EntityBatchSetItem<EntityStruct extends BaseEntityStruct<EntityStruct>> {
53
+ /**
54
+ * @description 实体数据 key
55
+ */
56
+ key: string;
57
+ /**
58
+ * @description 实体数据 value
59
+ */
60
+ value: Partial<EntityStruct>;
61
+ }
62
+ export interface EntityPrivate {
63
+ _name: string;
64
+ }
65
+ export interface InternalIndexesStruct {
66
+ __key__: null;
67
+ }
68
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../../src/packages/node/storage/entity/entity/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AACjF,OAAO,KAAK,EACV,uBAAuB,EACvB,cAAc,EACd,aAAa,EACd,MAAM,0BAA0B,CAAA;AACjC,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,sCAAsC,CAAA;AAE7C,MAAM,MAAM,qBAAqB,GAAG,uBAAuB,CAAA;AAE3D,MAAM,MAAM,gBAAgB,CAAC,YAAY,IAAI,YAAY,CACvD,YAAY,EACZ,MAAM,YAAY,EAClB,qBAAqB,CACtB,CAAA;AAED,MAAM,MAAM,sBAAsB,GAC9B,IAAI,GACJ,uBAAuB,EAAE,GACzB,CAAC,uBAAuB,EAAE,GAAG,uBAAuB,EAAE,CAAC,CAAA;AAE3D,MAAM,MAAM,iBAAiB,CAAC,aAAa,IAAI,YAAY,CACzD,aAAa,EACb,MAAM,aAAa,EACnB,sBAAsB,CACvB,CAAA;AAED,MAAM,MAAM,kBAAkB,CAAC,aAAa,IACxC,iBAAiB,CAAC,aAAa,CAAC,GAChC,WAAW,GACX,IAAI,CAAA;AAER;;;;GAIG;AACH,MAAM,WAAW,MAAM,CACrB,YAAY,SAAS,gBAAgB,CAAC,YAAY,CAAC,EACnD,aAAa,SAAS,kBAAkB,CAAC,aAAa,CAAC;IAEvD;;;;OAIG;IACH,GAAG,CAAC,GAAG,SAAS,MAAM,EAAE,GAAG,EAAE,cAAc,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAAA;IACpF;;;;OAIG;IACH,GAAG,CAAC,GAAG,SAAS,MAAM,EAAE,GAAG,EAAE,cAAc,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC9F;;;OAGG;IACH,MAAM,CAAC,GAAG,SAAS,MAAM,EAAE,GAAG,EAAE,cAAc,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACnE;;;OAGG;IACH,KAAK,IAAI,MAAM,CACb,aAAa,EACb,eAAe,CAAC,YAAY,EAAE,WAAW,CAAC,EAC1C,aAAa,CACX,aAAa,EACb,qBAAqB,CAAC,YAAY,EAAE,WAAW,CAAC,EAChD,qBAAqB,CAAC,YAAY,EAAE,OAAO,CAAC,aAAa,EAAE,WAAW,GAAG,IAAI,CAAC,CAAC,CAChF,CACF,CAAA;IACD;;;OAGG;IACH,QAAQ,CAAC,KAAK,SAAS,kBAAkB,CAAC,YAAY,CAAC,EAAE,EACvD,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,GAC1B,OAAO,CAAC,IAAI,CAAC,CAAA;IAChB;;;OAGG;IACH,WAAW,CAAC,IAAI,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC7E;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB,CAAC,YAAY,SAAS,gBAAgB,CAAC,YAAY,CAAC;IACrF;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;IACX;;OAEG;IACH,KAAK,EAAE,OAAO,CAAC,YAAY,CAAC,CAAA;CAC7B;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,IAAI,CAAA;CACd"}