@blocklet/did-space-js 1.0.12 → 1.0.14

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 (39) hide show
  1. package/dist/client/index.js +1 -1
  2. package/dist/commands/audit-log/post-objects-sync-command.js +1 -1
  3. package/dist/commands/audit-log/put-objects-sync-command.js +1 -1
  4. package/dist/commands/backup/post-app-backup.js +4 -2
  5. package/dist/commands/backup/put-app-backup.js +4 -2
  6. package/dist/commands/base.d.ts +3 -2
  7. package/dist/commands/base.js +8 -4
  8. package/dist/commands/incremental-sync/sync-base.js +5 -1
  9. package/dist/commands/incremental-sync/sync-push.d.ts +4 -2
  10. package/dist/commands/incremental-sync/sync-push.js +86 -72
  11. package/dist/commands/preview/delete-preview-object.js +1 -1
  12. package/dist/commands/preview/get-preview-object.js +1 -1
  13. package/dist/commands/preview/put-preview-object.js +1 -1
  14. package/dist/commands/restore/put-app-restore.js +1 -1
  15. package/dist/commands/sync/sync-folder-base.d.ts +1 -0
  16. package/dist/libs/api.d.ts +2 -1
  17. package/dist/libs/fs.d.ts +9 -0
  18. package/dist/libs/fs.js +18 -0
  19. package/dist/libs/index.d.ts +2 -1
  20. package/dist/libs/index.js +2 -1
  21. package/dist/meta/backup/post-app-backup-command.d.ts +2 -2
  22. package/dist/meta/backup/put-app-backup-command.d.ts +2 -2
  23. package/dist/meta/nft/put-nft-object-command.d.ts +2 -2
  24. package/dist/meta/object/delete-object-command.d.ts +2 -2
  25. package/dist/meta/object/get-object-command.d.ts +2 -2
  26. package/dist/meta/object/head-object-command.d.ts +2 -2
  27. package/dist/meta/object/list-object-command.d.ts +2 -2
  28. package/dist/meta/object/list-objects-command.d.ts +2 -2
  29. package/dist/meta/object/preview-object-command.d.ts +4 -4
  30. package/dist/meta/object/preview-object-command.js +1 -0
  31. package/dist/meta/object/put-object-command.d.ts +2 -2
  32. package/dist/meta/restore/post-app-restore-command.d.ts +2 -2
  33. package/dist/meta/restore/post-app-restore-command.js +1 -0
  34. package/dist/meta/restore/put-app-restore-command.d.ts +2 -2
  35. package/dist/meta/sync/post-objects-sync-command.d.ts +2 -2
  36. package/dist/meta/sync/put-objects-sync-command.d.ts +2 -2
  37. package/dist/meta/sync/sync-base-command.d.ts +2 -2
  38. package/dist/protocol/command.protocol.d.ts +12 -0
  39. package/package.json +4 -4
@@ -28,7 +28,7 @@ class SpaceClient {
28
28
  */
29
29
  async putNftObject(command) {
30
30
  try {
31
- command.context = this.options;
31
+ Object.assign(command.context, this.options);
32
32
  return await command.request();
33
33
  }
34
34
  catch (error) {
@@ -14,7 +14,7 @@ class PostObjectsSyncCommand extends base_1.BaseCommand {
14
14
  if (error) {
15
15
  throw error;
16
16
  }
17
- this.input = data;
17
+ Object.assign(this.input, data);
18
18
  }
19
19
  getAxiosRequestConfig() {
20
20
  return Promise.resolve(null);
@@ -14,7 +14,7 @@ class PutObjectsSyncCommand extends base_1.BaseCommand {
14
14
  if (error) {
15
15
  throw error;
16
16
  }
17
- this.input = data;
17
+ Object.assign(this.input, data);
18
18
  }
19
19
  getAxiosRequestConfig() {
20
20
  return Promise.resolve(null);
@@ -9,11 +9,13 @@ const base_1 = require("../base");
9
9
  class PostAppBackupCommand extends base_1.BaseCommand {
10
10
  constructor(input, context) {
11
11
  super(input, context);
12
- const { error, value } = backup_1.PostAppBackupCommandInputSchema.validate(input);
12
+ const { error, value } = backup_1.PostAppBackupCommandInputSchema.validate(input, {
13
+ allowUnknown: true,
14
+ });
13
15
  if (error) {
14
16
  throw error;
15
17
  }
16
- this.input = value;
18
+ Object.assign(this.input, value);
17
19
  }
18
20
  getAxiosRequestConfig() {
19
21
  return Promise.resolve(null);
@@ -9,11 +9,13 @@ const base_1 = require("../base");
9
9
  class PutAppBackupCommand extends base_1.BaseCommand {
10
10
  constructor(input, context) {
11
11
  super(input, context);
12
- const { error, value } = meta_1.PutAppBackupCommandInputSchema.validate(input);
12
+ const { error, value } = meta_1.PutAppBackupCommandInputSchema.validate(input, {
13
+ allowUnknown: true,
14
+ });
13
15
  if (error) {
14
16
  throw error;
15
17
  }
16
- this.input = value;
18
+ Object.assign(this.input, value);
17
19
  }
18
20
  getAxiosRequestConfig() {
19
21
  return Promise.resolve(null);
@@ -11,11 +11,12 @@ export interface GetKeyOptions {
11
11
  encode?: true | false;
12
12
  }
13
13
  export declare abstract class BaseCommand<BaseCommandInput extends CommandInput, BaseCommandOutput extends CommandOutput> extends EventEmitter implements CommandProtocol<BaseCommandInput, BaseCommandOutput> {
14
- input: BaseCommandInput;
15
- context: SpaceClientOptions;
14
+ readonly input: BaseCommandInput;
15
+ readonly context: SpaceClientOptions;
16
16
  constructor(input: BaseCommandInput, context?: SpaceClientOptions);
17
17
  abstract getAxiosRequestConfig(): Promise<AxiosRequestConfig | null>;
18
18
  getKey(key: string, options?: GetKeyOptions): string;
19
19
  request(): Promise<BaseCommandOutput>;
20
20
  resolveMiddleware(res?: AxiosResponse<BaseCommandOutput['data'], any>): Promise<BaseCommandOutput>;
21
+ abort(): void;
21
22
  }
@@ -11,15 +11,16 @@ const core_1 = require("@did-space/core");
11
11
  const stream_1 = require("stream");
12
12
  const libs_1 = require("../libs");
13
13
  class BaseCommand extends stream_1.EventEmitter {
14
- input;
15
- context;
14
+ input = {};
15
+ context = {};
16
16
  constructor(input, context = {}) {
17
17
  super();
18
- this.input = input;
19
- this.context = context;
18
+ Object.assign(this.input, input);
19
+ Object.assign(this.context, context);
20
20
  if ((0, did_1.isValid)(process.env.BLOCKLET_COMPONENT_DID)) {
21
21
  this.context.componentDid = process.env.BLOCKLET_COMPONENT_DID;
22
22
  }
23
+ this.context.abortController = this.context.abortController ?? this.input.abortController ?? new AbortController();
23
24
  }
24
25
  getKey(key, options = { encode: true }) {
25
26
  const path = (0, isEmpty_1.default)(this.context.componentDid)
@@ -43,5 +44,8 @@ class BaseCommand extends stream_1.EventEmitter {
43
44
  data: res?.data,
44
45
  });
45
46
  }
47
+ abort() {
48
+ this.context.abortController?.abort();
49
+ }
46
50
  }
47
51
  exports.BaseCommand = BaseCommand;
@@ -119,7 +119,9 @@ class IncrementalSyncBaseCommand extends base_1.BaseCommand {
119
119
  });
120
120
  // FIXME: retryCount === 0 表示,重试次数刚好用完了,后续优化 server 显示错误的进度 @yejianchao
121
121
  // 防呆控制,retryCount < 0 说明调用基础接口始终是失败的,遇到了预料之外的事情,因此需要停止运行
122
- if (this.input.retryCount <= 0 || [400, 401, 403, 404, 413].includes(statusCode)) {
122
+ if (this.input.retryCount <= 0 ||
123
+ [400, 401, 403, 404, 413].includes(statusCode) ||
124
+ this.context.abortController?.signal.aborted) {
123
125
  return {
124
126
  statusCode,
125
127
  statusMessage: (0, libs_1.getErrorMessage)(error),
@@ -229,6 +231,8 @@ class IncrementalSyncBaseCommand extends base_1.BaseCommand {
229
231
  return true;
230
232
  }
231
233
  async destroy() {
234
+ this.queue.pause();
235
+ this.queue.clear();
232
236
  if (await (0, fs_extra_1.pathExists)(this.input.tmpDir)) {
233
237
  await (0, fs_extra_1.remove)(this.input.tmpDir);
234
238
  }
@@ -19,12 +19,14 @@ export declare class IncrementalSyncPushCommand extends IncrementalSyncBaseComma
19
19
  /**
20
20
  * @see https://github.com/ArcBlock/did-spaces/issues/955#issuecomment-1873723050
21
21
  * @description 备份的对象随时可能在进行写入操作,所以对于需要备份的文件,最佳实践是备份它们某一个时刻的副本,否则会引发错误 Error: Unexpected end of form
22
- * @param {SyncObject[]} waitSyncObjects
22
+ * @param {SyncObject[]} syncObject
23
23
  * @return {*} {Promise<SyncObject[]>}
24
24
  * @memberof IncrementalSyncPushCommand
25
25
  */
26
- copyObjects(waitSyncObjects: SyncObject[]): Promise<SyncObject[]>;
26
+ copyObjectToTmpDir(syncObject: SyncObject): Promise<SyncObject>;
27
+ destroyObject(syncObject: SyncObject): Promise<void>;
27
28
  getObject(absolutePath: string): Promise<Object>;
28
29
  registerEvents(): void;
29
30
  private sync;
31
+ private throwErrorIfAborted;
30
32
  }
@@ -13,7 +13,6 @@ const keyBy_1 = __importDefault(require("lodash/keyBy"));
13
13
  const debug_1 = __importDefault(require("debug"));
14
14
  const xbytes_1 = __importDefault(require("xbytes"));
15
15
  const pick_1 = __importDefault(require("lodash/pick"));
16
- const p_all_1 = __importDefault(require("p-all"));
17
16
  const fs_extra_1 = require("fs-extra");
18
17
  const mime_types_1 = __importDefault(require("mime-types"));
19
18
  const promises_1 = require("node:stream/promises");
@@ -21,6 +20,7 @@ const object_1 = require("../object");
21
20
  const logger_1 = require("../../libs/logger");
22
21
  const delete_object_1 = require("../object/delete-object");
23
22
  const sync_base_1 = require("./sync-base");
23
+ const libs_1 = require("../../libs");
24
24
  const { name, version } = require('../../../package.json');
25
25
  const debug = (0, debug_1.default)(`${name}@${version}:sync-folder-push`);
26
26
  /**
@@ -37,10 +37,10 @@ class IncrementalSyncPushCommand extends sync_base_1.IncrementalSyncBaseCommand
37
37
  }
38
38
  async request() {
39
39
  try {
40
+ this.throwErrorIfAborted();
40
41
  const localObjectsMap = await this.getLocalObjectsMap();
41
42
  const remoteObjectsMap = await this.getRemoteObjectsMap();
42
- const waitSyncObjects = await this.getWaitSyncObjects(localObjectsMap, remoteObjectsMap);
43
- const syncObjects = await this.copyObjects(waitSyncObjects);
43
+ const syncObjects = await this.getWaitSyncObjects(localObjectsMap, remoteObjectsMap);
44
44
  debug(`[${(0, logger_1.now)()}] [waitUpload] waitUploadCount=${syncObjects.length}`);
45
45
  debug(`[${(0, logger_1.now)()}] [context]`, { input: this.input, context: (0, pick_1.default)(this.context, ['endpoint']) });
46
46
  return await this.sync(syncObjects);
@@ -52,7 +52,9 @@ class IncrementalSyncPushCommand extends sync_base_1.IncrementalSyncBaseCommand
52
52
  // eslint-disable-next-line require-await
53
53
  async getLocalObjectsMap() {
54
54
  // @note: 注意,此处不要先计算文件 hash
55
- let objects = this.input.source;
55
+ let objects = this.input.source.filter((object) => {
56
+ return object.name !== '.DS_Store';
57
+ });
56
58
  if ((0, isFunction_1.default)(this.input.filter)) {
57
59
  objects = objects.filter(this.input.filter);
58
60
  }
@@ -69,32 +71,31 @@ class IncrementalSyncPushCommand extends sync_base_1.IncrementalSyncBaseCommand
69
71
  /**
70
72
  * @see https://github.com/ArcBlock/did-spaces/issues/955#issuecomment-1873723050
71
73
  * @description 备份的对象随时可能在进行写入操作,所以对于需要备份的文件,最佳实践是备份它们某一个时刻的副本,否则会引发错误 Error: Unexpected end of form
72
- * @param {SyncObject[]} waitSyncObjects
74
+ * @param {SyncObject[]} syncObject
73
75
  * @return {*} {Promise<SyncObject[]>}
74
76
  * @memberof IncrementalSyncPushCommand
75
77
  */
76
- async copyObjects(waitSyncObjects) {
77
- await (0, p_all_1.default)(waitSyncObjects.map((x) => {
78
- return async () => {
79
- const source = x.absolutePath;
80
- const target = (0, path_1.join)(this.input.tmpDir, x.key);
81
- if (x.action !== 'PUT' || !(await (0, fs_extra_1.pathExists)(source))) {
82
- return;
83
- }
84
- if (!(await (0, fs_extra_1.pathExists)(target))) {
85
- await (0, fs_extra_1.ensureDir)((0, path_1.dirname)(target));
86
- await (0, promises_1.pipeline)((0, fs_1.createReadStream)(source), (0, fs_1.createWriteStream)(target));
87
- }
88
- const targetObject = await this.getObject(target);
89
- x.size = targetObject.size;
90
- x.lastModified = targetObject.lastModified;
91
- x.hash = await (0, core_1.getHash)((0, fs_1.createReadStream)(targetObject.absolutePath));
92
- x.absolutePath = targetObject.absolutePath;
93
- };
94
- }), {
95
- concurrency: this.input.concurrency,
96
- });
97
- return waitSyncObjects;
78
+ async copyObjectToTmpDir(syncObject) {
79
+ const source = syncObject.absolutePath;
80
+ const tempAbsolutePath = (0, path_1.join)(this.input.tmpDir, syncObject.key);
81
+ if (syncObject.action !== 'PUT' || !(await (0, fs_extra_1.pathExists)(source))) {
82
+ return syncObject;
83
+ }
84
+ if (!(await (0, fs_extra_1.pathExists)(tempAbsolutePath))) {
85
+ await (0, fs_extra_1.ensureDir)((0, path_1.dirname)(tempAbsolutePath));
86
+ await (0, promises_1.pipeline)((0, fs_1.createReadStream)(source), (0, fs_1.createWriteStream)(tempAbsolutePath));
87
+ }
88
+ const tempObject = await this.getObject(tempAbsolutePath);
89
+ syncObject.size = tempObject.size;
90
+ syncObject.lastModified = tempObject.lastModified;
91
+ syncObject.hash = await (0, core_1.getHash)((0, fs_1.createReadStream)(tempObject.absolutePath));
92
+ syncObject.tempAbsolutePath = tempObject.absolutePath;
93
+ return syncObject;
94
+ }
95
+ async destroyObject(syncObject) {
96
+ if (syncObject.tempAbsolutePath && (await (0, fs_extra_1.pathExists)(syncObject.tempAbsolutePath))) {
97
+ await (0, libs_1.remove)(syncObject.tempAbsolutePath);
98
+ }
98
99
  }
99
100
  async getObject(absolutePath) {
100
101
  const fileStat = await (0, fs_extra_1.stat)(absolutePath);
@@ -139,54 +140,61 @@ class IncrementalSyncPushCommand extends sync_base_1.IncrementalSyncBaseCommand
139
140
  });
140
141
  const actions = syncObjects.map((x) => {
141
142
  return async () => {
142
- const sourceKey = x.absolutePath;
143
- const targetKey = (0, path_1.join)(this.input.target, x.key);
144
- if (x.action === 'PUT' && !(await this.shouldBeBackup(sourceKey))) {
145
- debug('sync.return', {
146
- sourceKey,
147
- [`$pathExists(${sourceKey})`]: false,
143
+ try {
144
+ this.throwErrorIfAborted();
145
+ await this.copyObjectToTmpDir(x);
146
+ const sourceKey = x.tempAbsolutePath;
147
+ const targetKey = (0, path_1.join)(this.input.target, x.key);
148
+ this.emit('sync.before', {
149
+ completed: completedCount,
150
+ total: totalCount,
151
+ key: sourceKey,
148
152
  });
149
- return;
150
- }
151
- this.emit('sync.before', {
152
- completed: completedCount,
153
- total: totalCount,
154
- key: sourceKey,
155
- });
156
- // 开始上传
157
- debug(`[${(0, logger_1.now)()}] [sync:${x.action}.before] ${sourceKey} => ${targetKey} size=${(0, xbytes_1.default)(x.size, {
158
- iec: true,
159
- })} completed=${completedCount} total=${totalCount}`);
160
- if (x.action === 'PUT') {
161
- await new object_1.PutObjectCommand({
162
- key: targetKey,
163
- data: (0, fs_1.createReadStream)(sourceKey),
164
- hash: x.hash,
165
- }, this.context).request();
166
- totalSize += x.size;
153
+ if (x.action === 'PUT' && !(await this.shouldBeBackup(sourceKey))) {
154
+ debug('sync.return', {
155
+ sourceKey,
156
+ [`$pathExists(${sourceKey})`]: false,
157
+ });
158
+ return;
159
+ }
160
+ // 开始上传
161
+ debug(`[${(0, logger_1.now)()}] [sync:${x.action}.before] ${sourceKey} => ${targetKey} size=${(0, xbytes_1.default)(x.size, {
162
+ iec: true,
163
+ })} completed=${completedCount} total=${totalCount}`);
164
+ if (x.action === 'PUT') {
165
+ await new object_1.PutObjectCommand({
166
+ key: targetKey,
167
+ data: (0, fs_1.createReadStream)(sourceKey),
168
+ hash: x.hash,
169
+ }, this.context).request();
170
+ totalSize += x.size;
171
+ }
172
+ else {
173
+ await new delete_object_1.DeleteObjectCommand({
174
+ key: targetKey,
175
+ }, this.context).request();
176
+ }
177
+ // progress
178
+ ++completedCount;
179
+ this.printDebugInfo({
180
+ direction: 'push',
181
+ completedCount,
182
+ errorCount,
183
+ totalCount,
184
+ });
185
+ this.emit('sync.after', {
186
+ completed: completedCount,
187
+ total: totalCount,
188
+ key: sourceKey,
189
+ });
190
+ // 结束上传
191
+ debug(`[${(0, logger_1.now)()}] [sync:${x.action}.after] ${sourceKey}=>${targetKey} size=${(0, xbytes_1.default)(x.size, {
192
+ iec: true,
193
+ })} completed=${completedCount} total=${totalCount}`);
167
194
  }
168
- else {
169
- await new delete_object_1.DeleteObjectCommand({
170
- key: targetKey,
171
- }, this.context).request();
195
+ finally {
196
+ await this.destroyObject(x);
172
197
  }
173
- // progress
174
- ++completedCount;
175
- this.printDebugInfo({
176
- direction: 'push',
177
- completedCount,
178
- errorCount,
179
- totalCount,
180
- });
181
- this.emit('sync.after', {
182
- completed: completedCount,
183
- total: totalCount,
184
- key: sourceKey,
185
- });
186
- // 结束上传
187
- debug(`[${(0, logger_1.now)()}] [sync:${x.action}.after] ${sourceKey}=>${targetKey} size=${(0, xbytes_1.default)(x.size, {
188
- iec: true,
189
- })} completed=${completedCount} total=${totalCount}`);
190
198
  };
191
199
  });
192
200
  await this.queue.addAll(actions);
@@ -201,5 +209,11 @@ class IncrementalSyncPushCommand extends sync_base_1.IncrementalSyncBaseCommand
201
209
  },
202
210
  };
203
211
  }
212
+ throwErrorIfAborted() {
213
+ if (this.context.abortController?.signal.aborted) {
214
+ this.queue.pause();
215
+ throw new Error('Operation has been aborted');
216
+ }
217
+ }
204
218
  }
205
219
  exports.IncrementalSyncPushCommand = IncrementalSyncPushCommand;
@@ -13,7 +13,7 @@ class DeletePreviewObjectCommand extends base_1.BaseCommand {
13
13
  return Promise.resolve(null);
14
14
  }
15
15
  async resolveMiddleware() {
16
- this.input = await meta_1.GetPreviewObjectCommandInputSchema.parseAsync(this.input);
16
+ Object.assign(this.input, await meta_1.GetPreviewObjectCommandInputSchema.parseAsync(this.input));
17
17
  const url = (0, ufo_1.joinURL)(this.context.endpoint, 'object', this.getKey((0, path_1.join)(this.input.key, '.meta/preview.yml')));
18
18
  const method = 'DELETE';
19
19
  const { headers } = await (0, security_1.signRequest)({
@@ -17,7 +17,7 @@ class GetPreviewObjectCommand extends base_1.BaseCommand {
17
17
  return Promise.resolve(null);
18
18
  }
19
19
  async resolveMiddleware() {
20
- this.input = await meta_1.GetPreviewObjectCommandInputSchema.parseAsync(this.input);
20
+ Object.assign(this.input, await meta_1.GetPreviewObjectCommandInputSchema.parseAsync(this.input));
21
21
  const url = (0, ufo_1.joinURL)(this.context.endpoint, 'object', this.getKey((0, path_1.join)(this.input.key, '.meta/preview.yml')));
22
22
  const method = 'GET';
23
23
  const { headers } = await (0, security_1.signRequest)({
@@ -21,7 +21,7 @@ class PutPreviewObjectCommand extends base_1.BaseCommand {
21
21
  return Promise.resolve(null);
22
22
  }
23
23
  async normalize() {
24
- this.input = await meta_1.PutPreviewObjectCommandInputSchema.parseAsync(this.input);
24
+ Object.assign(this.input, await meta_1.PutPreviewObjectCommandInputSchema.parseAsync(this.input));
25
25
  for (const resource of this.input.resources) {
26
26
  if (!resource.key.startsWith(this.input.key)) {
27
27
  console.error(`Resource key(${resource.key}) must start with ${this.input.key}`, { resource });
@@ -13,7 +13,7 @@ class PutAppRestoreCommand extends base_1.BaseCommand {
13
13
  if (error) {
14
14
  throw error;
15
15
  }
16
- this.input = value;
16
+ Object.assign(this.input, value);
17
17
  }
18
18
  getAxiosRequestConfig() {
19
19
  return Promise.resolve(null);
@@ -9,6 +9,7 @@ export interface ObjectsMap {
9
9
  }
10
10
  export interface SyncObject extends Object {
11
11
  action: 'PUT' | 'DELETE';
12
+ tempAbsolutePath?: string;
12
13
  }
13
14
  /**
14
15
  * @see s3 sync https://stackoverflow.com/questions/27932345/downloading-folders-from-aws-s3-cp-or-sync
@@ -1,3 +1,4 @@
1
+ import { type Got } from 'got';
1
2
  export declare const MIN: number;
2
3
  export declare const api: import("axios").AxiosInstance;
3
- export declare const gotApi: import("got").Got;
4
+ export declare const gotApi: Got;
@@ -0,0 +1,9 @@
1
+ /// <reference types="node" />
2
+ import type { RmOptions } from 'fs';
3
+ /**
4
+ *
5
+ * @see https://github.com/nodejs/node/issues/39853#issuecomment-906843478
6
+ * @see https://stackoverflow.com/q/48529030
7
+ * @export
8
+ */
9
+ export declare function remove(path: string, options?: RmOptions): Promise<void>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.remove = void 0;
4
+ const promises_1 = require("fs/promises");
5
+ /**
6
+ *
7
+ * @see https://github.com/nodejs/node/issues/39853#issuecomment-906843478
8
+ * @see https://stackoverflow.com/q/48529030
9
+ * @export
10
+ */
11
+ async function remove(path, options = {
12
+ force: true,
13
+ maxRetries: 3,
14
+ }) {
15
+ await (0, promises_1.truncate)(path);
16
+ await (0, promises_1.rm)(path, options);
17
+ }
18
+ exports.remove = remove;
@@ -2,10 +2,11 @@ export * from './api';
2
2
  export * from './did';
3
3
  export * from './encoding';
4
4
  export * from './error';
5
+ export * from './fs';
5
6
  export * from './hash';
6
7
  export * from './logger';
7
8
  export * from './object-integrality';
8
9
  export * from './performance';
10
+ export * from './sleep';
9
11
  export * from './space';
10
12
  export * from './stream';
11
- export * from './sleep';
@@ -18,10 +18,11 @@ __exportStar(require("./api"), exports);
18
18
  __exportStar(require("./did"), exports);
19
19
  __exportStar(require("./encoding"), exports);
20
20
  __exportStar(require("./error"), exports);
21
+ __exportStar(require("./fs"), exports);
21
22
  __exportStar(require("./hash"), exports);
22
23
  __exportStar(require("./logger"), exports);
23
24
  __exportStar(require("./object-integrality"), exports);
24
25
  __exportStar(require("./performance"), exports);
26
+ __exportStar(require("./sleep"), exports);
25
27
  __exportStar(require("./space"), exports);
26
28
  __exportStar(require("./stream"), exports);
27
- __exportStar(require("./sleep"), exports);
@@ -1,6 +1,6 @@
1
1
  import { AppBackup, AuditLogStatus } from '@did-space/core';
2
2
  import type { ObjectSchema } from 'joi';
3
- import type { CommandOutput } from '../../protocol';
3
+ import type { CommandInput, CommandOutput } from '../../protocol';
4
4
  export type AppBackupData = AppBackup & {
5
5
  id: string;
6
6
  userDid: string;
@@ -10,7 +10,7 @@ export type AppBackupData = AppBackup & {
10
10
  updatedAt: string;
11
11
  };
12
12
  export declare const PostAppBackupCommandInputSchema: ObjectSchema<any>;
13
- export interface PostAppBackupCommandInput extends Pick<AppBackupData, 'userDid' | 'referrer' | 'appName' | 'appDescription' | 'serverDid' | 'signerDid'> {
13
+ export interface PostAppBackupCommandInput extends Pick<AppBackupData, 'userDid' | 'referrer' | 'appName' | 'appDescription' | 'serverDid' | 'signerDid'>, CommandInput {
14
14
  }
15
15
  export interface PostAppBackupCommandOutput extends CommandOutput<Required<AppBackupData>> {
16
16
  }
@@ -1,7 +1,7 @@
1
1
  import type { ObjectSchema } from 'joi';
2
- import type { CommandOutput } from '../../protocol';
2
+ import type { CommandInput, CommandOutput } from '../../protocol';
3
3
  import { AppBackupData } from './post-app-backup-command';
4
4
  export declare const PutAppBackupCommandInputSchema: ObjectSchema<any>;
5
- export type PutAppBackupCommandInput = Required<Pick<AppBackupData, 'id'>> & Partial<AppBackupData>;
5
+ export type PutAppBackupCommandInput = Required<Pick<AppBackupData, 'id'>> & Partial<AppBackupData> & CommandInput;
6
6
  export interface PutAppBackupCommandOutput extends CommandOutput<Required<AppBackupData>> {
7
7
  }
@@ -1,8 +1,8 @@
1
1
  /// <reference types="node" />
2
2
  import { WalletObject } from '@ocap/wallet';
3
3
  import { Readable } from 'stream';
4
- import type { CommandOutput } from '../../protocol';
5
- export interface PutNftObjectCommandInput {
4
+ import type { CommandInput, CommandOutput } from '../../protocol';
5
+ export interface PutNftObjectCommandInput extends CommandInput {
6
6
  /**
7
7
  * @description assetDid
8
8
  * @example z8iZnaYxnkMD5AKRjTKiCb8pQr1ut8UantAcf
@@ -1,5 +1,5 @@
1
- import type { CommandOutput } from '../../protocol';
2
- export interface DeleteObjectCommandInput {
1
+ import type { CommandInput, CommandOutput } from '../../protocol';
2
+ export interface DeleteObjectCommandInput extends CommandInput {
3
3
  key: string;
4
4
  }
5
5
  export interface DeleteObjectCommandOutput extends CommandOutput<void> {
@@ -1,8 +1,8 @@
1
1
  /// <reference types="node" />
2
2
  import { Readable } from 'stream';
3
3
  import type { AxiosResponseHeaders, RawAxiosResponseHeaders } from 'axios';
4
- import type { CommandOutput } from '../../protocol';
5
- export interface GetObjectCommandInput {
4
+ import type { CommandInput, CommandOutput } from '../../protocol';
5
+ export interface GetObjectCommandInput extends CommandInput {
6
6
  key: string;
7
7
  }
8
8
  export interface GetObjectCommandOutput extends CommandOutput<Readable> {
@@ -1,6 +1,6 @@
1
1
  import type { Response } from 'got';
2
- import type { CommandOutput } from '../../protocol';
3
- export interface HeadSpaceCommandInput {
2
+ import type { CommandInput, CommandOutput } from '../../protocol';
3
+ export interface HeadSpaceCommandInput extends CommandInput {
4
4
  /**
5
5
  * @description 对象的大小
6
6
  * @default {0}
@@ -1,6 +1,6 @@
1
1
  import { Object } from '@did-space/core';
2
- import type { CommandOutput } from '../../protocol';
3
- export interface ListObjectCommandInput {
2
+ import type { CommandInput, CommandOutput } from '../../protocol';
3
+ export interface ListObjectCommandInput extends CommandInput {
4
4
  key: string;
5
5
  }
6
6
  export type ListObjectCommandOutput = CommandOutput<Object>;
@@ -1,6 +1,6 @@
1
1
  import { Object } from '@did-space/core';
2
- import { CommandOutput } from '../../protocol';
3
- export interface ListObjectsCommandInput {
2
+ import { CommandInput, CommandOutput } from '../../protocol';
3
+ export interface ListObjectsCommandInput extends CommandInput {
4
4
  key: string;
5
5
  recursive?: false | true;
6
6
  ignoreDirectories?: false | true;
@@ -1,6 +1,6 @@
1
1
  import { PreviewTemplate } from '@did-space/core';
2
2
  import { z } from 'zod';
3
- import type { CommandOutput } from '../../protocol';
3
+ import type { CommandInput, CommandOutput } from '../../protocol';
4
4
  export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
5
5
  /**
6
6
  * @description 文件夹的路径,必须以 / 结尾
@@ -366,7 +366,7 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
366
366
  hash?: string | undefined;
367
367
  }[] | undefined;
368
368
  }>;
369
- export interface PutPreviewObjectCommandInput extends z.infer<typeof PutPreviewObjectCommandInputSchema> {
369
+ export interface PutPreviewObjectCommandInput extends z.infer<typeof PutPreviewObjectCommandInputSchema>, CommandInput {
370
370
  }
371
371
  export type PutPreviewObjectCommandOutput = CommandOutput<void>;
372
372
  export declare const GetPreviewObjectCommandInputSchema: z.ZodObject<{
@@ -376,7 +376,7 @@ export declare const GetPreviewObjectCommandInputSchema: z.ZodObject<{
376
376
  }, {
377
377
  key: string;
378
378
  }>;
379
- export interface GetPreviewObjectCommandInput extends z.infer<typeof GetPreviewObjectCommandInputSchema> {
379
+ export interface GetPreviewObjectCommandInput extends z.infer<typeof GetPreviewObjectCommandInputSchema>, CommandInput {
380
380
  }
381
381
  export type GetPreviewObjectCommandOutput = CommandOutput<PreviewTemplate>;
382
382
  export declare const DeletePreviewObjectCommandInputSchema: z.ZodObject<{
@@ -386,6 +386,6 @@ export declare const DeletePreviewObjectCommandInputSchema: z.ZodObject<{
386
386
  }, {
387
387
  key: string;
388
388
  }>;
389
- export interface DeletePreviewObjectCommandInput extends z.infer<typeof DeletePreviewObjectCommandInputSchema> {
389
+ export interface DeletePreviewObjectCommandInput extends z.infer<typeof DeletePreviewObjectCommandInputSchema>, CommandInput {
390
390
  }
391
391
  export type DeletePreviewObjectCommandOutput = CommandOutput<void>;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DeletePreviewObjectCommandInputSchema = exports.GetPreviewObjectCommandInputSchema = exports.PutPreviewObjectCommandInputSchema = void 0;
4
+ /* eslint-disable @typescript-eslint/indent */
4
5
  const core_1 = require("@did-space/core");
5
6
  const zod_1 = require("zod");
6
7
  const put_object_command_1 = require("./put-object-command");
@@ -1,6 +1,6 @@
1
1
  import { Data } from '@did-space/core';
2
2
  import { z } from 'zod';
3
- import type { CommandOutput } from '../../protocol';
3
+ import type { CommandInput, CommandOutput } from '../../protocol';
4
4
  export declare const PutObjectCommandInputSchema: z.ZodObject<{
5
5
  /**
6
6
  * @description 可以是一个文件名或者文件夹
@@ -29,7 +29,7 @@ export declare const PutObjectCommandInputSchema: z.ZodObject<{
29
29
  data?: any;
30
30
  hash?: string | undefined;
31
31
  }>;
32
- export interface PutObjectCommandInput extends z.infer<typeof PutObjectCommandInputSchema> {
32
+ export interface PutObjectCommandInput extends z.infer<typeof PutObjectCommandInputSchema>, CommandInput {
33
33
  data?: Data;
34
34
  }
35
35
  export type PutObjectCommandOutput = CommandOutput<void>;
@@ -1,6 +1,6 @@
1
1
  import { AppRestore, AuditLogStatus } from '@did-space/core';
2
2
  import type { ObjectSchema } from 'joi';
3
- import { CommandOutput } from '../../protocol/command.protocol';
3
+ import { CommandOutput, type CommandInput } from '../../protocol/command.protocol';
4
4
  export type AppRestoreData = AppRestore & {
5
5
  id: string;
6
6
  userDid: string;
@@ -10,7 +10,7 @@ export type AppRestoreData = AppRestore & {
10
10
  updatedAt: string;
11
11
  };
12
12
  export declare const PostAppRestoreCommandInputSchema: ObjectSchema<any>;
13
- export interface PostAppRestoreCommandInput extends Pick<AppRestoreData, 'userDid' | 'referrer' | 'serverDid'> {
13
+ export interface PostAppRestoreCommandInput extends Pick<AppRestoreData, 'userDid' | 'referrer' | 'serverDid'>, CommandInput {
14
14
  }
15
15
  export interface PostAppRestoreCommandOutput extends CommandOutput<Required<AppRestoreData>> {
16
16
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PostAppRestoreCommandInputSchema = void 0;
4
+ /* eslint-disable @typescript-eslint/indent */
4
5
  const validator_1 = require("@arcblock/validator");
5
6
  exports.PostAppRestoreCommandInputSchema = validator_1.Joi.object({
6
7
  userDid: validator_1.Joi.DID(),
@@ -1,7 +1,7 @@
1
1
  import type { ObjectSchema } from 'joi';
2
- import type { CommandOutput } from '../../protocol';
2
+ import type { CommandInput, CommandOutput } from '../../protocol';
3
3
  import { AppRestoreData } from './post-app-restore-command';
4
4
  export declare const PutAppRestoreCommandInputSchema: ObjectSchema<any>;
5
- export type PutAppRestoreCommandInput = Required<Pick<AppRestoreData, 'id'>> & Partial<AppRestoreData>;
5
+ export type PutAppRestoreCommandInput = Required<Pick<AppRestoreData, 'id'>> & Partial<AppRestoreData> & CommandInput;
6
6
  export interface PutAppRestoreCommandOutput extends CommandOutput<Required<AppRestoreData>> {
7
7
  }
@@ -1,6 +1,6 @@
1
1
  import { AuditLogModel, AuditLogAction } from '@did-space/core';
2
2
  import { z } from 'zod';
3
- import type { CommandOutput } from '../../protocol';
3
+ import type { CommandInput, CommandOutput } from '../../protocol';
4
4
  export declare const PostObjectsSyncCommandInputSchema: z.ZodObject<{
5
5
  source: z.ZodString;
6
6
  target: z.ZodString;
@@ -14,7 +14,7 @@ export declare const PostObjectsSyncCommandInputSchema: z.ZodObject<{
14
14
  source: string;
15
15
  metadata?: Record<string, any> | undefined;
16
16
  }>;
17
- export interface PostObjectsSyncCommandInput extends z.infer<typeof PostObjectsSyncCommandInputSchema> {
17
+ export interface PostObjectsSyncCommandInput extends z.infer<typeof PostObjectsSyncCommandInputSchema>, CommandInput {
18
18
  }
19
19
  export interface PostObjectsSyncCommandOutput extends CommandOutput<AuditLogModel<AuditLogAction.APP_OBJECTS_SYNC>> {
20
20
  }
@@ -1,6 +1,6 @@
1
1
  import { AuditLogModel, AuditLogAction, AuditLogStatus } from '@did-space/core';
2
2
  import { z } from 'zod';
3
- import type { CommandOutput } from '../../protocol';
3
+ import type { CommandInput, CommandOutput } from '../../protocol';
4
4
  export declare const PutObjectsSyncCommandInputSchema: z.ZodObject<{
5
5
  id: z.ZodString;
6
6
  status: z.ZodNativeEnum<typeof AuditLogStatus>;
@@ -29,7 +29,7 @@ export declare const PutObjectsSyncCommandInputSchema: z.ZodObject<{
29
29
  reason?: string | undefined;
30
30
  successCount?: number | undefined;
31
31
  }>;
32
- export interface PutObjectsSyncCommandInput extends z.infer<typeof PutObjectsSyncCommandInputSchema> {
32
+ export interface PutObjectsSyncCommandInput extends z.infer<typeof PutObjectsSyncCommandInputSchema>, CommandInput {
33
33
  }
34
34
  export interface PutObjectsSyncCommandOutput extends CommandOutput<AuditLogModel<AuditLogAction.APP_OBJECTS_SYNC>> {
35
35
  }
@@ -1,5 +1,5 @@
1
1
  import { Object } from '@did-space/core';
2
- import type { CommandOutput } from '../../protocol';
2
+ import type { CommandInput, CommandOutput } from '../../protocol';
3
3
  export interface OnProgressInput {
4
4
  /**
5
5
  *
@@ -46,7 +46,7 @@ export interface OnAfterUploadInput {
46
46
  */
47
47
  key: string;
48
48
  }
49
- export interface SyncBaseCommandInput {
49
+ export interface SyncBaseCommandInput extends CommandInput {
50
50
  /**
51
51
  *
52
52
  * @description 将 source 同步到 target, 文件夹请添加尾杠 /
@@ -1,6 +1,12 @@
1
1
  import type { WalletObject } from '@ocap/wallet';
2
2
  import type { Response } from 'got';
3
3
  export interface CommandInput {
4
+ /**
5
+ * @description
6
+ * @type {AbortController}
7
+ * @memberof CommandInput
8
+ */
9
+ abortController?: AbortController;
4
10
  }
5
11
  export interface CommandOutput<D = any> {
6
12
  /**
@@ -60,6 +66,12 @@ export interface SpaceClientOptions {
60
66
  * @memberof SpaceClientOptions
61
67
  */
62
68
  componentDid?: string;
69
+ /**
70
+ * @description
71
+ * @type {AbortController}
72
+ * @memberof SpaceClientOptions
73
+ */
74
+ abortController?: AbortController;
63
75
  }
64
76
  export interface CommandProtocol<Input extends CommandInput, Output extends CommandOutput> {
65
77
  input: Input;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/did-space-js",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -33,7 +33,7 @@
33
33
  "@arcblock/jwt": "^1.19.9",
34
34
  "@arcblock/validator": "^1.19.9",
35
35
  "@blocklet/env": "^1.16.38",
36
- "@did-space/core": "^1.0.12",
36
+ "@did-space/core": "^1.0.14",
37
37
  "@ocap/mcrypto": "^1.19.9",
38
38
  "@ocap/util": "^1.19.9",
39
39
  "@ocap/wallet": "^1.19.9",
@@ -45,7 +45,7 @@
45
45
  "filehound": "^1.17.6",
46
46
  "form-data": "^4.0.1",
47
47
  "fs-extra": "^11.3.0",
48
- "got": "11.8.6",
48
+ "got": "^11.8.6",
49
49
  "hasha": "^5.2.2",
50
50
  "is-url": "^1.2.4",
51
51
  "joi": "^17.13.3",
@@ -76,5 +76,5 @@
76
76
  "ts-jest": "^28.0.8",
77
77
  "typescript": "^4.9.5"
78
78
  },
79
- "gitHead": "3dedeeeefac5358e622f7975c7880b91902ca8f3"
79
+ "gitHead": "1ab815d7d3a8933de2c866cff6d6abe31ef70ffc"
80
80
  }