@did-space/core 0.3.66 → 0.3.68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants/index.d.ts +6 -0
- package/dist/constants/index.js +9 -1
- package/dist/meta/object.d.ts +8 -0
- package/dist/meta/template/app.d.ts +6 -0
- package/dist/model/app-space-apply.d.ts +62 -0
- package/dist/model/app-space-apply.js +2 -0
- package/dist/model/index.d.ts +3 -2
- package/dist/model/index.js +3 -2
- package/dist/model/object-collection.d.ts +15 -1
- package/dist/protocols/space-operator.d.ts +2 -1
- package/dist/protocols/space-owner-operator.d.ts +2 -0
- package/dist/schemas/object-space.d.ts +1 -1
- package/dist/schemas/object-space.js +14 -7
- package/dist/space/object-space.d.ts +3 -2
- package/dist/space/object-space.js +81 -47
- package/package.json +3 -3
package/dist/constants/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HEADERS = exports.APP_BACKUP_STATUS = exports.DID_OBJECTS = exports.APPS = void 0;
|
|
3
|
+
exports.APP = exports.HEADERS = exports.APP_BACKUP_STATUS = exports.DID_OBJECTS = exports.APPS = void 0;
|
|
4
4
|
exports.APPS = 'apps';
|
|
5
5
|
exports.DID_OBJECTS = '.did-objects';
|
|
6
6
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
@@ -18,3 +18,11 @@ exports.HEADERS = {
|
|
|
18
18
|
// 取值为 2,表示 url 使用了 base64url 编码的方式
|
|
19
19
|
X_SIGNATURE_VERSION: 'x-signature-version',
|
|
20
20
|
};
|
|
21
|
+
exports.APP = {
|
|
22
|
+
// @example: /${spaceDid}/apps/${appDid}
|
|
23
|
+
FOLDER_PREFIX: 'apps',
|
|
24
|
+
COMPONENT: {
|
|
25
|
+
// @example: /${spaceDid}/apps/${appDid}/.components/${componentDid}
|
|
26
|
+
FOLDER_PREFIX: '.components',
|
|
27
|
+
},
|
|
28
|
+
};
|
package/dist/meta/object.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ObjectMetadata } from '../protocols';
|
|
1
2
|
export interface Object {
|
|
2
3
|
/**
|
|
3
4
|
*
|
|
@@ -58,5 +59,12 @@ export interface Object {
|
|
|
58
59
|
* @memberof Object
|
|
59
60
|
*/
|
|
60
61
|
hash?: string;
|
|
62
|
+
/**
|
|
63
|
+
* @description 存储 metadata 信息
|
|
64
|
+
* @default {{}}
|
|
65
|
+
* @type {ObjectMetadata}
|
|
66
|
+
* @memberof Object
|
|
67
|
+
*/
|
|
68
|
+
metadata?: ObjectMetadata;
|
|
61
69
|
[key: string]: any;
|
|
62
70
|
}
|
|
@@ -3,6 +3,11 @@ import { AppConnected } from './app-connected';
|
|
|
3
3
|
import { AppDisconnected } from './app-disconnected';
|
|
4
4
|
import { AppRestore } from './app-restore';
|
|
5
5
|
export declare const APP_TYPE = "app";
|
|
6
|
+
export interface AppPermissions {
|
|
7
|
+
[scope: string]: {
|
|
8
|
+
[authorizedAppDid: string]: number;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
6
11
|
/**
|
|
7
12
|
*
|
|
8
13
|
* @description 此文件存储的位置在 ${spaceDid}/apps/${appDid}/.meta/config.yml
|
|
@@ -24,6 +29,7 @@ export interface App {
|
|
|
24
29
|
disconnected: Array<AppDisconnected>;
|
|
25
30
|
backup: Array<AppBackup>;
|
|
26
31
|
restore: Array<AppRestore>;
|
|
32
|
+
permissions: AppPermissions;
|
|
27
33
|
createAt: string;
|
|
28
34
|
updateAt: string;
|
|
29
35
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { AppPermissions } from '../meta';
|
|
2
|
+
export interface AppSpaceApplyModel {
|
|
3
|
+
/**
|
|
4
|
+
* @description 记录的唯一标识,是一个 UUIDV4
|
|
5
|
+
* @type {string}
|
|
6
|
+
* @memberof AppSpaceApplyModel
|
|
7
|
+
*/
|
|
8
|
+
id: string;
|
|
9
|
+
/**
|
|
10
|
+
* @description
|
|
11
|
+
* @type {string}
|
|
12
|
+
* @memberof AppSpaceApplyModel
|
|
13
|
+
*/
|
|
14
|
+
storageDid: string;
|
|
15
|
+
/**
|
|
16
|
+
* @description
|
|
17
|
+
* @type {string}
|
|
18
|
+
* @memberof AppSpaceApplyModel
|
|
19
|
+
*/
|
|
20
|
+
assetDid: string;
|
|
21
|
+
/**
|
|
22
|
+
* @description
|
|
23
|
+
* @type {string}
|
|
24
|
+
* @memberof AppSpaceApplyModel
|
|
25
|
+
*/
|
|
26
|
+
ownerDid: string;
|
|
27
|
+
/**
|
|
28
|
+
* @description 应用最新的 appDid,如果应用被迁移了,这个值也会更新到最新
|
|
29
|
+
* @type {string}
|
|
30
|
+
* @memberof AppSpaceApplyModel
|
|
31
|
+
*/
|
|
32
|
+
appDid: string;
|
|
33
|
+
/**
|
|
34
|
+
* @description
|
|
35
|
+
* @type {string}
|
|
36
|
+
* @memberof AppSpaceApplyModel
|
|
37
|
+
*/
|
|
38
|
+
appName: string;
|
|
39
|
+
/**
|
|
40
|
+
* @description
|
|
41
|
+
* @type {string}
|
|
42
|
+
* @default {''}
|
|
43
|
+
* @memberof AppSpaceApplyModel
|
|
44
|
+
*/
|
|
45
|
+
appDescription?: string;
|
|
46
|
+
/**
|
|
47
|
+
* @description 目前存储着授权信息
|
|
48
|
+
* @memberof AppSpaceApplyModel
|
|
49
|
+
*/
|
|
50
|
+
metadata: {
|
|
51
|
+
permissions: AppPermissions;
|
|
52
|
+
};
|
|
53
|
+
createAt: string;
|
|
54
|
+
updateAt: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* @description
|
|
58
|
+
* @export
|
|
59
|
+
* @interface CreationAppSpaceApplyModel
|
|
60
|
+
*/
|
|
61
|
+
export interface CreationAppSpaceApplyModel extends Omit<AppSpaceApplyModel, 'id'> {
|
|
62
|
+
}
|
package/dist/model/index.d.ts
CHANGED
package/dist/model/index.js
CHANGED
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
18
|
-
__exportStar(require("./object"), exports);
|
|
17
|
+
__exportStar(require("./app-space-apply"), exports);
|
|
19
18
|
__exportStar(require("./object-collection"), exports);
|
|
19
|
+
__exportStar(require("./object"), exports);
|
|
20
|
+
__exportStar(require("./tree"), exports);
|
|
@@ -21,8 +21,22 @@ export interface ObjectCollectionModel {
|
|
|
21
21
|
*/
|
|
22
22
|
createdAt: string;
|
|
23
23
|
}
|
|
24
|
-
export
|
|
24
|
+
export type ObjectCollectionModelCreation = Pick<ObjectCollectionModel, 'id'>;
|
|
25
|
+
export declare class ObjectCollectionRepositoryClass extends Model<ObjectCollectionModel, ObjectCollectionModelCreation> {
|
|
26
|
+
/**
|
|
27
|
+
* @primaryKey
|
|
28
|
+
* @description 对象的唯一标识,格式是 ipfs cid v1
|
|
29
|
+
* @type {string}
|
|
30
|
+
* @column {DataTypes.CHAR(64)}
|
|
31
|
+
* @memberof ObjectCollectionModel
|
|
32
|
+
*/
|
|
25
33
|
id: string;
|
|
34
|
+
/**
|
|
35
|
+
* @description 对象的创建时间
|
|
36
|
+
* @type {string}
|
|
37
|
+
* @column {DataTypes.DATE}
|
|
38
|
+
* @memberof ObjectCollectionModel
|
|
39
|
+
*/
|
|
26
40
|
createdAt: string;
|
|
27
41
|
}
|
|
28
42
|
export type ObjectCollectionRepository = typeof ObjectCollectionRepositoryClass;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Stream } from 'stream';
|
|
3
3
|
import { SpaceConfig } from '../configuration';
|
|
4
4
|
import { Data, Object } from '../meta';
|
|
5
|
-
import { SpaceOwnerOperatorProtocol } from './space-owner-operator';
|
|
5
|
+
import { SpaceOwnerOperatorProtocol, type ObjectMetadata } from './space-owner-operator';
|
|
6
6
|
export interface AppSpaceOptions {
|
|
7
7
|
appDid: string;
|
|
8
8
|
}
|
|
@@ -11,6 +11,7 @@ export interface WriteOptions extends AppSpaceOptions {
|
|
|
11
11
|
data: Data;
|
|
12
12
|
hash?: string;
|
|
13
13
|
size?: number;
|
|
14
|
+
metadata?: ObjectMetadata;
|
|
14
15
|
}
|
|
15
16
|
export interface DeleteOptions extends AppSpaceOptions {
|
|
16
17
|
key: string;
|
|
@@ -18,10 +18,12 @@ export type KeyStatus = {
|
|
|
18
18
|
*/
|
|
19
19
|
size: number;
|
|
20
20
|
};
|
|
21
|
+
export type ObjectMetadata = Record<string, any>;
|
|
21
22
|
export type WriteAsOwnerOptions = {
|
|
22
23
|
hash: string;
|
|
23
24
|
size: number;
|
|
24
25
|
useGlobal?: false | true;
|
|
26
|
+
metadata?: ObjectMetadata;
|
|
25
27
|
};
|
|
26
28
|
export type ReadAsOwnerOptions = {
|
|
27
29
|
useGlobal?: false | true;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const OwnerOperatorKeySchema: import("joi").StringSchema<string>;
|
|
2
2
|
export declare const WriteAsOwnerOptionsSchema: import("joi").ObjectSchema<any>;
|
|
3
3
|
export declare const ObjectSpaceOptionsSchema: import("joi").ObjectSchema<any>;
|
|
4
4
|
export declare const DeleteAsOwnerOptionsSchema: import("joi").ObjectSchema<any>;
|
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GetHashOptionsSchema = exports.WriteOptionsSchema = exports.DeleteAsOwnerOptionsSchema = exports.ObjectSpaceOptionsSchema = exports.WriteAsOwnerOptionsSchema = exports.
|
|
3
|
+
exports.GetHashOptionsSchema = exports.WriteOptionsSchema = exports.DeleteAsOwnerOptionsSchema = exports.ObjectSpaceOptionsSchema = exports.WriteAsOwnerOptionsSchema = exports.OwnerOperatorKeySchema = void 0;
|
|
4
4
|
const validator_1 = require("@arcblock/validator");
|
|
5
|
-
exports.
|
|
5
|
+
exports.OwnerOperatorKeySchema = validator_1.Joi.string().regex(/^\//).required();
|
|
6
6
|
const WriteAsOwnerOptionsByFolderSchema = {
|
|
7
7
|
is: validator_1.Joi.string().regex(/\/$/),
|
|
8
|
-
then: validator_1.Joi.
|
|
8
|
+
then: validator_1.Joi.optional().default(null),
|
|
9
|
+
otherwise: validator_1.Joi.required(),
|
|
10
|
+
};
|
|
11
|
+
const MetadataSchema = {
|
|
12
|
+
is: validator_1.Joi.object(),
|
|
13
|
+
then: validator_1.Joi.optional().default(null),
|
|
9
14
|
otherwise: validator_1.Joi.required(),
|
|
10
15
|
};
|
|
11
16
|
exports.WriteAsOwnerOptionsSchema = validator_1.Joi.object({
|
|
12
|
-
key: exports.
|
|
13
|
-
data: validator_1.Joi.any().when('key', WriteAsOwnerOptionsByFolderSchema),
|
|
17
|
+
key: exports.OwnerOperatorKeySchema,
|
|
18
|
+
data: validator_1.Joi.any().when('key', WriteAsOwnerOptionsByFolderSchema).when('metadata', MetadataSchema),
|
|
14
19
|
// @FIXME: 当 key 是文件夹 或者 data 不是一个 stream 的时候,hash, size 是可选的,现在的规则尝试之后没能做到这么精细化(使用 when 无法满足要求) @jianchao
|
|
15
20
|
hash: validator_1.Joi.string().optional().allow(null).default(null),
|
|
16
21
|
size: validator_1.Joi.number().integer().optional().allow(null).default(null),
|
|
17
22
|
useGlobal: validator_1.Joi.boolean().optional().default(false),
|
|
23
|
+
metadata: validator_1.Joi.object().optional().default({}),
|
|
18
24
|
});
|
|
19
25
|
exports.ObjectSpaceOptionsSchema = validator_1.Joi.object({
|
|
20
26
|
driver: validator_1.Joi.any().required(),
|
|
@@ -24,14 +30,15 @@ exports.ObjectSpaceOptionsSchema = validator_1.Joi.object({
|
|
|
24
30
|
objectCollectionRepository: validator_1.Joi.any().required(),
|
|
25
31
|
});
|
|
26
32
|
exports.DeleteAsOwnerOptionsSchema = validator_1.Joi.object({
|
|
27
|
-
key: exports.
|
|
33
|
+
key: exports.OwnerOperatorKeySchema,
|
|
28
34
|
});
|
|
29
35
|
exports.WriteOptionsSchema = validator_1.Joi.object({
|
|
30
36
|
appDid: validator_1.Joi.DID().required(),
|
|
31
37
|
key: validator_1.Joi.string().required(),
|
|
32
|
-
data: validator_1.Joi.any().
|
|
38
|
+
data: validator_1.Joi.any().when('key', WriteAsOwnerOptionsByFolderSchema).when('metadata', MetadataSchema),
|
|
33
39
|
hash: validator_1.Joi.string().optional().allow(null).default(null),
|
|
34
40
|
size: validator_1.Joi.number().integer().optional().allow(null).default(null),
|
|
41
|
+
metadata: validator_1.Joi.object().optional().default({}),
|
|
35
42
|
});
|
|
36
43
|
exports.GetHashOptionsSchema = validator_1.Joi.object({
|
|
37
44
|
appDid: validator_1.Joi.DID().required(),
|
|
@@ -63,8 +63,6 @@ export declare class ObjectSpace implements SpaceProtocol {
|
|
|
63
63
|
* @memberof ObjectSpace
|
|
64
64
|
*/
|
|
65
65
|
list(options: ListOptions): Promise<Object>;
|
|
66
|
-
private _updateAsOwner;
|
|
67
|
-
private _createAsOwner;
|
|
68
66
|
/**
|
|
69
67
|
* @refactor: @jianchao 后续让 write 的接口参数保持一致,即 key, data 都在 options 里面,目前改动收益比较小
|
|
70
68
|
* @description
|
|
@@ -75,6 +73,9 @@ export declare class ObjectSpace implements SpaceProtocol {
|
|
|
75
73
|
* @memberof ObjectSpace
|
|
76
74
|
*/
|
|
77
75
|
writeAsOwner(key: string, data: Data, options?: WriteAsOwnerOptions): Promise<void>;
|
|
76
|
+
private updateAsOwner;
|
|
77
|
+
private createAsOwner;
|
|
78
|
+
private updateMetadata;
|
|
78
79
|
deleteAsOwner(key: string): Promise<void>;
|
|
79
80
|
readAsOwner(key: string, options?: ReadAsOwnerOptions): Promise<Stream>;
|
|
80
81
|
existsAsOwner(key: string): Promise<boolean>;
|
|
@@ -17,7 +17,9 @@ const debug_1 = __importDefault(require("debug"));
|
|
|
17
17
|
const skypesky_sequelize_1 = require("skypesky-sequelize");
|
|
18
18
|
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
19
19
|
const path_1 = require("path");
|
|
20
|
-
const
|
|
20
|
+
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
21
|
+
const isUndefined_1 = __importDefault(require("lodash/isUndefined"));
|
|
22
|
+
const omit_1 = __importDefault(require("lodash/omit"));
|
|
21
23
|
const xbytes_1 = __importDefault(require("xbytes"));
|
|
22
24
|
const configuration_1 = require("../configuration");
|
|
23
25
|
const model_1 = require("../model");
|
|
@@ -128,6 +130,7 @@ class ObjectSpace {
|
|
|
128
130
|
}
|
|
129
131
|
const [did, capacity, usedCapacity] = yield Promise.all([
|
|
130
132
|
this.spaceDid,
|
|
133
|
+
// @FIXME: 此处应该用 cache 层的数据,可以加速查询
|
|
131
134
|
this.get('size'),
|
|
132
135
|
this.getSpaceSize(),
|
|
133
136
|
]);
|
|
@@ -143,7 +146,7 @@ class ObjectSpace {
|
|
|
143
146
|
}
|
|
144
147
|
write(options) {
|
|
145
148
|
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
-
debug('write.before', JSON.stringify((0,
|
|
149
|
+
debug('write.before', JSON.stringify((0, omit_1.default)(options, 'data')));
|
|
147
150
|
const { error } = schemas_1.WriteOptionsSchema.validate(options, {
|
|
148
151
|
allowUnknown: true,
|
|
149
152
|
stripUnknown: true,
|
|
@@ -196,7 +199,7 @@ class ObjectSpace {
|
|
|
196
199
|
}
|
|
197
200
|
exists(options) {
|
|
198
201
|
return __awaiter(this, void 0, void 0, function* () {
|
|
199
|
-
debug('exists.before', JSON.stringify({ options: (0,
|
|
202
|
+
debug('exists.before', JSON.stringify({ options: (0, omit_1.default)(options, 'data') }));
|
|
200
203
|
const key = (0, path_1.join)(yield this.getAppSpacePath(options), options.key);
|
|
201
204
|
return this.existsAsOwner(key);
|
|
202
205
|
});
|
|
@@ -223,6 +226,7 @@ class ObjectSpace {
|
|
|
223
226
|
return Promise.all(trees.map((x) => __awaiter(this, void 0, void 0, function* () {
|
|
224
227
|
const absolutePath = (0, path_1.join)(x.spaceDid, x.key);
|
|
225
228
|
if (x.type === model_1.TreeModelType.FOLDER) {
|
|
229
|
+
// @FIXME: 如果追求极速,此处是一个优化的点,文件夹不一定需要看到 更新时间和大小,S3 就是这么做的,默认是不展示的
|
|
226
230
|
const { size, lastModified } = yield this.getStatusAsOwner(x.key);
|
|
227
231
|
return {
|
|
228
232
|
key: x.key,
|
|
@@ -233,6 +237,7 @@ class ObjectSpace {
|
|
|
233
237
|
editable: true,
|
|
234
238
|
mimeType: null,
|
|
235
239
|
absolutePath,
|
|
240
|
+
metadata: x.meta,
|
|
236
241
|
};
|
|
237
242
|
}
|
|
238
243
|
return {
|
|
@@ -245,6 +250,7 @@ class ObjectSpace {
|
|
|
245
250
|
mimeType: x.Object.meta.mimeType,
|
|
246
251
|
hash: x.objectId,
|
|
247
252
|
absolutePath,
|
|
253
|
+
metadata: x.meta,
|
|
248
254
|
};
|
|
249
255
|
})));
|
|
250
256
|
});
|
|
@@ -274,6 +280,7 @@ class ObjectSpace {
|
|
|
274
280
|
mimeType: x.Object.meta.mimeType,
|
|
275
281
|
hash: x.objectId,
|
|
276
282
|
absolutePath: (0, path_1.join)(x.spaceDid, x.key),
|
|
283
|
+
metadata: x.meta,
|
|
277
284
|
};
|
|
278
285
|
});
|
|
279
286
|
});
|
|
@@ -331,12 +338,59 @@ class ObjectSpace {
|
|
|
331
338
|
editable: true,
|
|
332
339
|
mimeType: x.type === model_1.TreeModelType.FOLDER ? null : x.Object.meta.mimeType,
|
|
333
340
|
absolutePath: (0, path_1.join)(x.spaceDid, x.key),
|
|
341
|
+
metadata: x.meta,
|
|
334
342
|
};
|
|
335
343
|
});
|
|
336
344
|
}
|
|
337
|
-
|
|
345
|
+
/**
|
|
346
|
+
* @refactor: @jianchao 后续让 write 的接口参数保持一致,即 key, data 都在 options 里面,目前改动收益比较小
|
|
347
|
+
* @description
|
|
348
|
+
* @param {string} key
|
|
349
|
+
* @param {Data} data
|
|
350
|
+
* @param {WriteAsOwnerOptions} options
|
|
351
|
+
* @return {*} {Promise<void>}
|
|
352
|
+
* @memberof ObjectSpace
|
|
353
|
+
*/
|
|
354
|
+
writeAsOwner(key, data, options = { hash: null, size: 0 }) {
|
|
338
355
|
return __awaiter(this, void 0, void 0, function* () {
|
|
339
|
-
debug('
|
|
356
|
+
debug('writeAsOwner.before', JSON.stringify({ key, options: (0, omit_1.default)(options, 'data') }));
|
|
357
|
+
const { error } = schemas_1.WriteAsOwnerOptionsSchema.validate(Object.assign(Object.assign({}, options), { key,
|
|
358
|
+
data }), {
|
|
359
|
+
allowUnknown: true,
|
|
360
|
+
stripUnknown: true,
|
|
361
|
+
});
|
|
362
|
+
if (error) {
|
|
363
|
+
throw error;
|
|
364
|
+
}
|
|
365
|
+
if (!(0, utils_1.isDirectory)(key) && !(0, stream_1.isStream)(data)) {
|
|
366
|
+
options.hash = options.hash || (yield (0, utils_1.getHash)(data));
|
|
367
|
+
options.size = options.size || (0, utils_1.getSize)(data);
|
|
368
|
+
if (!options.hash || !options.size) {
|
|
369
|
+
throw new Error('Hash and size cannot be empty');
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
const exists = yield this.existsAsOwner(key);
|
|
373
|
+
debug('writeAsOwner.$exists', exists);
|
|
374
|
+
if (exists) {
|
|
375
|
+
// 更新对象
|
|
376
|
+
yield this.updateAsOwner(key, data, options);
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
// @note: 只有新增的时候才会触发检测
|
|
380
|
+
yield this.verifySpace(options === null || options === void 0 ? void 0 : options.size);
|
|
381
|
+
// 添加新对象
|
|
382
|
+
yield this.createAsOwner(key, data, options);
|
|
383
|
+
}
|
|
384
|
+
debug('writeAsOwner.after', JSON.stringify({ key, options: (0, omit_1.default)(options, 'data') }));
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
updateAsOwner(key, data, options) {
|
|
388
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
389
|
+
debug('updateAsOwner.before', { key, options: (0, omit_1.default)(options, 'data') });
|
|
390
|
+
yield this.updateMetadata(key, data, options);
|
|
391
|
+
if ((0, isUndefined_1.default)(data)) {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
340
394
|
if ((0, utils_1.isDirectory)(key)) {
|
|
341
395
|
return;
|
|
342
396
|
}
|
|
@@ -344,12 +398,12 @@ class ObjectSpace {
|
|
|
344
398
|
spaceDid: this.spaceDid,
|
|
345
399
|
key,
|
|
346
400
|
};
|
|
347
|
-
debug('
|
|
401
|
+
debug('updateAsOwner.before', JSON.stringify({ key, options: (0, omit_1.default)(options, 'data'), where }));
|
|
348
402
|
const oldTree = yield this.treeRepository.findOne({
|
|
349
403
|
where,
|
|
350
404
|
include: this.objectRepository,
|
|
351
405
|
});
|
|
352
|
-
debug('
|
|
406
|
+
debug('updateAsOwner.$oldTree', JSON.stringify(oldTree));
|
|
353
407
|
const listObject = yield this.driver.list({
|
|
354
408
|
key: (0, utils_1.getHashPath)(options.hash),
|
|
355
409
|
useGlobal: true,
|
|
@@ -382,9 +436,9 @@ class ObjectSpace {
|
|
|
382
436
|
yield this.globalSpace.mark(oldTree.objectId);
|
|
383
437
|
});
|
|
384
438
|
}
|
|
385
|
-
|
|
439
|
+
createAsOwner(key, data, options) {
|
|
386
440
|
return __awaiter(this, void 0, void 0, function* () {
|
|
387
|
-
debug('
|
|
441
|
+
debug('createAsOwner.before', JSON.stringify({ key, options: (0, omit_1.default)(options, 'data') }));
|
|
388
442
|
const isDir = key.endsWith('/');
|
|
389
443
|
if (isDir) {
|
|
390
444
|
// 添加 tree 记录
|
|
@@ -395,6 +449,7 @@ class ObjectSpace {
|
|
|
395
449
|
key,
|
|
396
450
|
type: model_1.TreeModelType.FOLDER,
|
|
397
451
|
});
|
|
452
|
+
yield this.updateMetadata(key, data, options);
|
|
398
453
|
return;
|
|
399
454
|
}
|
|
400
455
|
// 存储新对象到全局存储区
|
|
@@ -407,48 +462,27 @@ class ObjectSpace {
|
|
|
407
462
|
key,
|
|
408
463
|
type: key.endsWith('/') ? model_1.TreeModelType.FOLDER : model_1.TreeModelType.FILE,
|
|
409
464
|
});
|
|
465
|
+
yield this.updateMetadata(key, data, options);
|
|
410
466
|
});
|
|
411
467
|
}
|
|
412
|
-
|
|
413
|
-
* @refactor: @jianchao 后续让 write 的接口参数保持一致,即 key, data 都在 options 里面,目前改动收益比较小
|
|
414
|
-
* @description
|
|
415
|
-
* @param {string} key
|
|
416
|
-
* @param {Data} data
|
|
417
|
-
* @param {WriteAsOwnerOptions} options
|
|
418
|
-
* @return {*} {Promise<void>}
|
|
419
|
-
* @memberof ObjectSpace
|
|
420
|
-
*/
|
|
421
|
-
writeAsOwner(key, data, options = { hash: null, size: 0 }) {
|
|
468
|
+
updateMetadata(key, data, options) {
|
|
422
469
|
return __awaiter(this, void 0, void 0, function* () {
|
|
423
|
-
debug('
|
|
424
|
-
const
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
470
|
+
debug('updateMetadata.before', { key, options: (0, omit_1.default)(options, 'data') });
|
|
471
|
+
const where = {
|
|
472
|
+
spaceDid: this.spaceDid,
|
|
473
|
+
key,
|
|
474
|
+
type: key.endsWith('/') ? model_1.TreeModelType.FOLDER : model_1.TreeModelType.FILE,
|
|
475
|
+
};
|
|
476
|
+
debug('updateMetadata.before', JSON.stringify({ key, options: (0, omit_1.default)(options, 'data'), where }));
|
|
477
|
+
const oldTree = yield this.treeRepository.findOne({
|
|
478
|
+
where,
|
|
428
479
|
});
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
options.size = options.size || (0, utils_1.getSize)(data);
|
|
435
|
-
if (!options.hash || !options.size) {
|
|
436
|
-
throw new Error('Hash and size cannot be empty');
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
const exists = yield this.existsAsOwner(key);
|
|
440
|
-
debug('writeAsOwner.$exists', exists);
|
|
441
|
-
if (exists) {
|
|
442
|
-
// 更新对象
|
|
443
|
-
yield this._updateAsOwner(key, data, options);
|
|
444
|
-
}
|
|
445
|
-
else {
|
|
446
|
-
// @note: 只有新增的时候才会触发检测
|
|
447
|
-
yield this.verifySpace(options === null || options === void 0 ? void 0 : options.size);
|
|
448
|
-
// 添加新对象
|
|
449
|
-
yield this._createAsOwner(key, data, options);
|
|
480
|
+
debug('updateMetadata.$oldTree', JSON.stringify(oldTree));
|
|
481
|
+
if (!(0, isEmpty_1.default)(options.metadata)) {
|
|
482
|
+
yield oldTree.update({
|
|
483
|
+
meta: Object.assign(Object.assign({}, oldTree.meta), options.metadata),
|
|
484
|
+
});
|
|
450
485
|
}
|
|
451
|
-
debug('writeAsOwner.after', JSON.stringify({ key, options: (0, lodash_1.omit)(options, 'data') }));
|
|
452
486
|
});
|
|
453
487
|
}
|
|
454
488
|
deleteAsOwner(key) {
|
|
@@ -537,7 +571,7 @@ class ObjectSpace {
|
|
|
537
571
|
spaceDid: this.spaceDid,
|
|
538
572
|
key,
|
|
539
573
|
}));
|
|
540
|
-
const { error } = schemas_1.
|
|
574
|
+
const { error } = schemas_1.OwnerOperatorKeySchema.validate(key);
|
|
541
575
|
if (error) {
|
|
542
576
|
throw error;
|
|
543
577
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@did-space/core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.68",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@arcblock/ipfs-only-hash": "^0.0.2",
|
|
40
|
-
"@arcblock/validator": "^1.18.
|
|
40
|
+
"@arcblock/validator": "^1.18.113",
|
|
41
41
|
"debug": "^4.3.4",
|
|
42
42
|
"hasha": "^5.2.2",
|
|
43
43
|
"joi": "^17.12.2",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"ts-jest": "^28.0.8",
|
|
61
61
|
"typescript": "^4.9.5"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "64012c24c566b0d066689cbe6d4ba689c54c8065"
|
|
64
64
|
}
|