@did-space/core 0.3.21 → 0.3.22

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.
@@ -23,6 +23,7 @@ export interface GetHashOptions extends AppSpaceOptions {
23
23
  }
24
24
  export interface ListOptions {
25
25
  key: string;
26
+ useGlobal?: false | true;
26
27
  }
27
28
  export interface ListsOptions {
28
29
  key: string;
@@ -57,5 +58,5 @@ export interface SpaceOperatorProtocol extends SpaceOwnerOperatorProtocol {
57
58
  getHash(options: GetHashOptions): Promise<string>;
58
59
  exists(options: ReadOptions): Promise<boolean>;
59
60
  lists(options: ListsOptions): Promise<Object[]>;
60
- list(options: ListOptions): Promise<Object>;
61
+ list(options: ListOptions): Promise<Object | null>;
61
62
  }
@@ -64,8 +64,12 @@ class GlobalSpace {
64
64
  raw: true,
65
65
  });
66
66
  debug('add.$objectRecord', JSON.stringify(objectRecord));
67
+ const listObject = yield this.driver.list({
68
+ key: (0, utils_1.getHashPath)(options.hash),
69
+ useGlobal: true,
70
+ });
67
71
  // @note: 运行时的纠错机制,我们发现 size 有时候保存出错(修复后将不可能出现),必须 hash 和 size 都相同,才不需要修改底层存储
68
- if (objectRecord && objectRecord.size === options.size) {
72
+ if (objectRecord && objectRecord.size === options.size && (listObject === null || listObject === void 0 ? void 0 : listObject.size) === options.size) {
69
73
  return;
70
74
  }
71
75
  // 存储新对象到全局存储区
@@ -350,8 +350,14 @@ class ObjectSpace {
350
350
  include: this.objectRepository,
351
351
  });
352
352
  debug('_updateAsOwner.$oldTree', JSON.stringify(oldTree));
353
+ const listObject = yield this.driver.list({
354
+ key: (0, utils_1.getHashPath)(options.hash),
355
+ useGlobal: true,
356
+ });
353
357
  // @note: 运行时的纠错机制,我们发现 size 有时候保存出错(修复后将不可能出现),必须 hash 和 size 都相同,才不需要修改底层存储
354
- if (oldTree.objectId === options.hash && oldTree.Object.size === options.size) {
358
+ if (oldTree.objectId === options.hash &&
359
+ oldTree.Object.size === options.size &&
360
+ (listObject === null || listObject === void 0 ? void 0 : listObject.size) === options.size) {
355
361
  // 内容不变,不需要再次存储对象,只需要更新对象的事件即可
356
362
  yield this.treeRepository.update({
357
363
  updatedAt: new Date().toISOString(),
@@ -1,3 +1,4 @@
1
1
  import { Data } from '../meta';
2
2
  export declare function getSize(data: Data): number;
3
3
  export declare function isDirectory(key: string): boolean;
4
+ export declare function isValidData(data: Data): boolean;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isDirectory = exports.getSize = void 0;
3
+ exports.isValidData = exports.isDirectory = exports.getSize = void 0;
4
+ const lodash_1 = require("lodash");
5
+ const stream_1 = require("stream");
4
6
  function getSize(data) {
5
7
  if (typeof data === 'string') {
6
8
  return Buffer.byteLength(data, 'utf-8');
@@ -15,3 +17,13 @@ function isDirectory(key) {
15
17
  return key.endsWith('/');
16
18
  }
17
19
  exports.isDirectory = isDirectory;
20
+ function isValidData(data) {
21
+ if ((0, lodash_1.isString)(data) || (0, lodash_1.isBuffer)(data)) {
22
+ return true;
23
+ }
24
+ if (data instanceof stream_1.Stream || data instanceof stream_1.Readable || (0, lodash_1.isFunction)(data === null || data === void 0 ? void 0 : data.pipe)) {
25
+ return true;
26
+ }
27
+ return false;
28
+ }
29
+ exports.isValidData = isValidData;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@did-space/core",
3
- "version": "0.3.21",
3
+ "version": "0.3.22",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -60,5 +60,5 @@
60
60
  "ts-jest": "^28.0.6",
61
61
  "typescript": "^4.9.5"
62
62
  },
63
- "gitHead": "558719cb308f43ce1cc62c60125522726d8e1014"
63
+ "gitHead": "09a609e207a621b158581f3d3f8623e61ccbb90a"
64
64
  }