@did-space/core 0.2.173 → 0.3.1
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/drivers/base.d.ts +5 -5
- package/dist/drivers/base.js +8 -8
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/meta/object.d.ts +5 -0
- package/dist/model/index.d.ts +3 -0
- package/dist/model/index.js +19 -0
- package/dist/model/object-collection.d.ts +28 -0
- package/dist/model/object-collection.js +7 -0
- package/dist/model/object.d.ts +59 -0
- package/dist/model/object.js +7 -0
- package/dist/model/tree.d.ts +94 -0
- package/dist/model/tree.js +18 -0
- package/dist/protocols/space-operator.d.ts +2 -0
- package/dist/protocols/space-owner-operator.d.ts +30 -4
- package/dist/schemas/global-space.d.ts +2 -0
- package/dist/schemas/global-space.js +21 -0
- package/dist/schemas/index.d.ts +1 -0
- package/dist/schemas/index.js +1 -0
- package/dist/schemas/object-space.d.ts +6 -0
- package/dist/schemas/object-space.js +39 -0
- package/dist/space/global-space.d.ts +43 -0
- package/dist/space/global-space.js +153 -0
- package/dist/space/index.d.ts +3 -45
- package/dist/space/index.js +16 -187
- package/dist/space/object-space.d.ts +111 -0
- package/dist/space/object-space.js +652 -0
- package/dist/space/space.d.ts +45 -0
- package/dist/space/space.js +190 -0
- package/dist/utils/common.d.ts +3 -0
- package/dist/utils/common.js +17 -0
- package/dist/utils/hash.d.ts +20 -0
- package/dist/utils/hash.js +60 -0
- package/dist/utils/index.d.ts +3 -2
- package/dist/utils/index.js +3 -2
- package/dist/utils/{string-to-stream.d.ts → stream.d.ts} +2 -0
- package/dist/utils/stream.js +23 -0
- package/package.json +12 -3
- package/dist/utils/stream-to-string.d.ts +0 -1
- package/dist/utils/stream-to-string.js +0 -10
- package/dist/utils/string-to-stream.js +0 -11
package/dist/space/index.d.ts
CHANGED
|
@@ -1,45 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { Data, Object } from '../meta';
|
|
5
|
-
import { WriteOptions, ReadOptions, SpaceProtocol, DriverProtocol, AppSpaceOptions, PermissionOptions, DeleteOptions, ListOptions, ListsOptions, GetHashOptions, KeyStatus } from '../protocols';
|
|
6
|
-
export declare class Space implements SpaceProtocol {
|
|
7
|
-
readonly driver: DriverProtocol;
|
|
8
|
-
static readonly READONLY_OBJECT_KEYS: string[];
|
|
9
|
-
constructor(driver: DriverProtocol);
|
|
10
|
-
createSpace(spaceConfiguration: SpaceConfig): Promise<void>;
|
|
11
|
-
destroySpace(): Promise<void>;
|
|
12
|
-
isSpaceCreated(): Promise<boolean>;
|
|
13
|
-
getSpaceSize(): Promise<number>;
|
|
14
|
-
createAppSpace(options: AppSpaceOptions): Promise<void>;
|
|
15
|
-
destroyAppSpace(options: AppSpaceOptions): Promise<void>;
|
|
16
|
-
getAppSpacePath(options: AppSpaceOptions): Promise<string>;
|
|
17
|
-
createConfig(spaceConfig: SpaceConfig): Promise<void>;
|
|
18
|
-
destroyConfig(): Promise<void>;
|
|
19
|
-
set<T = any>(key: string, value: T): Promise<void>;
|
|
20
|
-
get<T = any>(key: string): Promise<T>;
|
|
21
|
-
setListable(options: PermissionOptions, value: boolean): Promise<void>;
|
|
22
|
-
setReadable(options: PermissionOptions, value: boolean): Promise<void>;
|
|
23
|
-
setWritable(options: PermissionOptions, value: boolean): Promise<void>;
|
|
24
|
-
isListable(options: PermissionOptions): Promise<boolean>;
|
|
25
|
-
isReadable(options: PermissionOptions): Promise<boolean>;
|
|
26
|
-
isWritable(options: PermissionOptions): Promise<boolean>;
|
|
27
|
-
getSpaceStatus(): Promise<{
|
|
28
|
-
totalCapacity: number;
|
|
29
|
-
usedCapacity: number;
|
|
30
|
-
isFull: boolean;
|
|
31
|
-
}>;
|
|
32
|
-
write(options: WriteOptions): Promise<void>;
|
|
33
|
-
delete(options: DeleteOptions): Promise<void>;
|
|
34
|
-
read(options: ReadOptions): Promise<Stream>;
|
|
35
|
-
getHash(options: GetHashOptions): Promise<string>;
|
|
36
|
-
exists(options: ReadOptions): Promise<boolean>;
|
|
37
|
-
lists(options: ListsOptions): Promise<Object[]>;
|
|
38
|
-
list(options: ListOptions): Promise<Object>;
|
|
39
|
-
writeAsOwner(key: string, data: Data): Promise<void>;
|
|
40
|
-
deleteAsOwner(key: string): Promise<void>;
|
|
41
|
-
readAsOwner(key: string): Promise<Stream>;
|
|
42
|
-
existsAsOwner(key: string): Promise<boolean>;
|
|
43
|
-
getStatusAsOwner(key: string): Promise<KeyStatus>;
|
|
44
|
-
static editable(key: string): boolean;
|
|
45
|
-
}
|
|
1
|
+
export * from './space';
|
|
2
|
+
export * from './object-space';
|
|
3
|
+
export * from './global-space';
|
package/dist/space/index.js
CHANGED
|
@@ -1,190 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
13
15
|
};
|
|
14
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
constructor(driver) {
|
|
19
|
-
this.driver = driver;
|
|
20
|
-
}
|
|
21
|
-
createSpace(spaceConfiguration) {
|
|
22
|
-
return this.driver.createSpace(spaceConfiguration);
|
|
23
|
-
}
|
|
24
|
-
destroySpace() {
|
|
25
|
-
return this.driver.destroySpace();
|
|
26
|
-
}
|
|
27
|
-
isSpaceCreated() {
|
|
28
|
-
return this.driver.isSpaceCreated();
|
|
29
|
-
}
|
|
30
|
-
getSpaceSize() {
|
|
31
|
-
return this.driver.getSpaceSize();
|
|
32
|
-
}
|
|
33
|
-
createAppSpace(options) {
|
|
34
|
-
return this.driver.createAppSpace(options);
|
|
35
|
-
}
|
|
36
|
-
destroyAppSpace(options) {
|
|
37
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
const permissionOptions = {
|
|
39
|
-
fromAppDid: options.appDid,
|
|
40
|
-
toAppDid: options.appDid,
|
|
41
|
-
};
|
|
42
|
-
yield this.driver.setListable(permissionOptions, false);
|
|
43
|
-
yield this.driver.setReadable(permissionOptions, false);
|
|
44
|
-
yield this.driver.setWritable(permissionOptions, false);
|
|
45
|
-
return this.driver.destroyAppSpace(options);
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
getAppSpacePath(options) {
|
|
49
|
-
return this.driver.getAppSpacePath(options);
|
|
50
|
-
}
|
|
51
|
-
createConfig(spaceConfig) {
|
|
52
|
-
return this.driver.createConfig(spaceConfig);
|
|
53
|
-
}
|
|
54
|
-
destroyConfig() {
|
|
55
|
-
return this.driver.destroyConfig();
|
|
56
|
-
}
|
|
57
|
-
set(key, value) {
|
|
58
|
-
return this.driver.set(key, value);
|
|
59
|
-
}
|
|
60
|
-
get(key) {
|
|
61
|
-
return this.driver.get(key);
|
|
62
|
-
}
|
|
63
|
-
setListable(options, value) {
|
|
64
|
-
return this.driver.setListable(options, value);
|
|
65
|
-
}
|
|
66
|
-
setReadable(options, value) {
|
|
67
|
-
return this.driver.setReadable(options, value);
|
|
68
|
-
}
|
|
69
|
-
setWritable(options, value) {
|
|
70
|
-
return this.driver.setWritable(options, value);
|
|
71
|
-
}
|
|
72
|
-
isListable(options) {
|
|
73
|
-
return this.driver.isListable(options);
|
|
74
|
-
}
|
|
75
|
-
isReadable(options) {
|
|
76
|
-
return this.driver.isReadable(options);
|
|
77
|
-
}
|
|
78
|
-
isWritable(options) {
|
|
79
|
-
return this.driver.isWritable(options);
|
|
80
|
-
}
|
|
81
|
-
getSpaceStatus() {
|
|
82
|
-
var _a, _b;
|
|
83
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
-
// FIXME: @yejianchao 临时性解决方案,需要新增拓容功能,需要去除白名单功能
|
|
85
|
-
const [did, totalCapacity, usedCapacity] = yield Promise.all([
|
|
86
|
-
this.driver.get('did'),
|
|
87
|
-
this.driver.get('size'),
|
|
88
|
-
this.driver.getSpaceSize(),
|
|
89
|
-
]);
|
|
90
|
-
const whiteList = ((_b = (_a = process.env) === null || _a === void 0 ? void 0 : _a.SPACE_WHITE_LIST) !== null && _b !== void 0 ? _b : '')
|
|
91
|
-
.split(',')
|
|
92
|
-
.map((s) => s.trim())
|
|
93
|
-
.filter(Boolean);
|
|
94
|
-
// @see: https://github.com/ArcBlock/did-spaces/issues/269#issuecomment-1430852234
|
|
95
|
-
// 存储空间无限制
|
|
96
|
-
if (totalCapacity === 0) {
|
|
97
|
-
return {
|
|
98
|
-
isFull: false,
|
|
99
|
-
totalCapacity,
|
|
100
|
-
usedCapacity,
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
// 跳过白名单
|
|
104
|
-
if (whiteList.length && whiteList.includes(did)) {
|
|
105
|
-
return {
|
|
106
|
-
isFull: false,
|
|
107
|
-
totalCapacity,
|
|
108
|
-
usedCapacity,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
// 存储空间不足
|
|
112
|
-
if (usedCapacity >= totalCapacity) {
|
|
113
|
-
return {
|
|
114
|
-
isFull: true,
|
|
115
|
-
totalCapacity,
|
|
116
|
-
usedCapacity,
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
return {
|
|
120
|
-
isFull: false,
|
|
121
|
-
totalCapacity,
|
|
122
|
-
usedCapacity,
|
|
123
|
-
};
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
write(options) {
|
|
127
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
-
// FIXME: @yejianchao 插入数据和编辑数据应该分离?
|
|
129
|
-
if (yield this.exists(options)) {
|
|
130
|
-
return this.driver.write(options);
|
|
131
|
-
}
|
|
132
|
-
const spaceStatus = yield this.getSpaceStatus();
|
|
133
|
-
if (spaceStatus.isFull) {
|
|
134
|
-
throw new Error(`Insufficient free space, total capacity is ${(0, xbytes_1.default)(spaceStatus.totalCapacity)}, used capacity is ${(0, xbytes_1.default)(spaceStatus.usedCapacity)}`);
|
|
135
|
-
}
|
|
136
|
-
return this.driver.write(options);
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
delete(options) {
|
|
140
|
-
return this.driver.delete(options);
|
|
141
|
-
}
|
|
142
|
-
read(options) {
|
|
143
|
-
return this.driver.read(options);
|
|
144
|
-
}
|
|
145
|
-
getHash(options) {
|
|
146
|
-
return this.driver.getHash(options);
|
|
147
|
-
}
|
|
148
|
-
exists(options) {
|
|
149
|
-
return this.driver.exists(options);
|
|
150
|
-
}
|
|
151
|
-
lists(options) {
|
|
152
|
-
return this.driver.lists(options);
|
|
153
|
-
}
|
|
154
|
-
list(options) {
|
|
155
|
-
return this.driver.list(options);
|
|
156
|
-
}
|
|
157
|
-
writeAsOwner(key, data) {
|
|
158
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
-
// FIXME: @yejianchao 插入数据和编辑数据应该分离
|
|
160
|
-
if (yield this.existsAsOwner(key)) {
|
|
161
|
-
return this.driver.writeAsOwner(key, data);
|
|
162
|
-
}
|
|
163
|
-
const spaceStatus = yield this.getSpaceStatus();
|
|
164
|
-
if (spaceStatus.isFull) {
|
|
165
|
-
throw new Error(`Insufficient free space, total capacity is ${(0, xbytes_1.default)(spaceStatus.totalCapacity)}, used capacity is ${(0, xbytes_1.default)(spaceStatus.usedCapacity)}`);
|
|
166
|
-
}
|
|
167
|
-
return this.driver.writeAsOwner(key, data);
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
deleteAsOwner(key) {
|
|
171
|
-
if (Space.READONLY_OBJECT_KEYS.includes(key)) {
|
|
172
|
-
throw new Error(`Object ${key} cannot be deleted`);
|
|
173
|
-
}
|
|
174
|
-
return this.driver.deleteAsOwner(key);
|
|
175
|
-
}
|
|
176
|
-
readAsOwner(key) {
|
|
177
|
-
return this.driver.readAsOwner(key);
|
|
178
|
-
}
|
|
179
|
-
existsAsOwner(key) {
|
|
180
|
-
return this.driver.existsAsOwner(key);
|
|
181
|
-
}
|
|
182
|
-
getStatusAsOwner(key) {
|
|
183
|
-
return this.driver.getStatusAsOwner(key);
|
|
184
|
-
}
|
|
185
|
-
static editable(key) {
|
|
186
|
-
return !Space.READONLY_OBJECT_KEYS.includes(key);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
exports.Space = Space;
|
|
190
|
-
Space.READONLY_OBJECT_KEYS = ['/config.yml'];
|
|
17
|
+
__exportStar(require("./space"), exports);
|
|
18
|
+
__exportStar(require("./object-space"), exports);
|
|
19
|
+
__exportStar(require("./global-space"), exports);
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Stream } from 'stream';
|
|
3
|
+
import { SpaceConfig } from '../configuration';
|
|
4
|
+
import { Object, Data } from '../meta';
|
|
5
|
+
import { AppSpaceOptions, DeleteOptions, DriverProtocol, GetHashOptions, KeyStatus, ListOptions, ListsOptions, PermissionOptions, ReadAsOwnerOptions, ReadOptions, SpaceProtocol, WriteAsOwnerOptions, WriteOptions } from '../protocols';
|
|
6
|
+
import { ObjectCollectionRepository, ObjectRepository, TreeRepository } from '../model';
|
|
7
|
+
import { GlobalSpace } from './global-space';
|
|
8
|
+
export type ObjectSpaceOptions = {
|
|
9
|
+
driver: DriverProtocol;
|
|
10
|
+
spaceDid: string;
|
|
11
|
+
treeRepository: TreeRepository;
|
|
12
|
+
objectRepository: ObjectRepository;
|
|
13
|
+
objectCollectionRepository: ObjectCollectionRepository;
|
|
14
|
+
};
|
|
15
|
+
export declare class ObjectSpace implements SpaceProtocol {
|
|
16
|
+
readonly spaceDid: string;
|
|
17
|
+
readonly driver: DriverProtocol;
|
|
18
|
+
readonly objectRepository: ObjectRepository;
|
|
19
|
+
readonly treeRepository: TreeRepository;
|
|
20
|
+
readonly objectCollectionRepository: ObjectCollectionRepository;
|
|
21
|
+
readonly globalSpace: GlobalSpace;
|
|
22
|
+
constructor(options: ObjectSpaceOptions);
|
|
23
|
+
createSpace(spaceConfig: SpaceConfig): Promise<void>;
|
|
24
|
+
isSpaceCreated(): Promise<boolean>;
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @description
|
|
28
|
+
* @return {*} {Promise<void>}
|
|
29
|
+
* @memberof ObjectSpace
|
|
30
|
+
*/
|
|
31
|
+
destroySpace(): Promise<void>;
|
|
32
|
+
getSpaceSize(): Promise<number>;
|
|
33
|
+
createAppSpace(options: AppSpaceOptions): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* @description
|
|
36
|
+
* @param {AppSpaceOptions} options
|
|
37
|
+
* @return {Promise<void>} {Promise<void>}
|
|
38
|
+
* @memberof ObjectSpace
|
|
39
|
+
*/
|
|
40
|
+
destroyAppSpace(options: AppSpaceOptions): Promise<void>;
|
|
41
|
+
getAppSpacePath(options: AppSpaceOptions): Promise<string>;
|
|
42
|
+
write(options: WriteOptions): Promise<void>;
|
|
43
|
+
delete(options: DeleteOptions): Promise<void>;
|
|
44
|
+
read(options: ReadOptions): Promise<Stream>;
|
|
45
|
+
getHash(options: GetHashOptions): Promise<string>;
|
|
46
|
+
exists(options: ReadOptions): Promise<boolean>;
|
|
47
|
+
private listsOneLevelAsOwner;
|
|
48
|
+
private listsRecursiveAsOwner;
|
|
49
|
+
/**
|
|
50
|
+
* @description 后续改名为 listsAsOwner 更合适
|
|
51
|
+
* @param {ListsOptions} options
|
|
52
|
+
* @return {*} {Promise<Object[]>}
|
|
53
|
+
* @memberof ObjectSpace
|
|
54
|
+
*/
|
|
55
|
+
lists(options: ListsOptions): Promise<Object[]>;
|
|
56
|
+
/**
|
|
57
|
+
* @FIXME: 接口的功能实际应该是 listAsOwner 实现的,属于技术债 @jianchao
|
|
58
|
+
* @description
|
|
59
|
+
* @param {ListOptions} options
|
|
60
|
+
* @return {*} {Promise<Object>}
|
|
61
|
+
* @memberof ObjectSpace
|
|
62
|
+
*/
|
|
63
|
+
list(options: ListOptions): Promise<Object>;
|
|
64
|
+
private _updateAsOwner;
|
|
65
|
+
private _createAsOwner;
|
|
66
|
+
/**
|
|
67
|
+
* @refactor: @jianchao 后续让 write 的接口参数保持一致,即 key, data 都在 options 里面,目前改动收益比较小
|
|
68
|
+
* @description
|
|
69
|
+
* @param {string} key
|
|
70
|
+
* @param {Data} data
|
|
71
|
+
* @param {WriteAsOwnerOptions} options
|
|
72
|
+
* @return {*} {Promise<void>}
|
|
73
|
+
* @memberof ObjectSpace
|
|
74
|
+
*/
|
|
75
|
+
writeAsOwner(key: string, data: Data, options?: WriteAsOwnerOptions): Promise<void>;
|
|
76
|
+
deleteAsOwner(key: string): Promise<void>;
|
|
77
|
+
readAsOwner(key: string, options?: ReadAsOwnerOptions): Promise<Stream>;
|
|
78
|
+
existsAsOwner(key: string): Promise<boolean>;
|
|
79
|
+
getStatusAsOwner(key: string): Promise<KeyStatus>;
|
|
80
|
+
createConfig(spaceConfig: SpaceConfig): Promise<void>;
|
|
81
|
+
destroyConfig(): Promise<void>;
|
|
82
|
+
set<T = any>(key: string, value: T): Promise<void>;
|
|
83
|
+
get<T = any>(key: string, defaultValue?: T): Promise<T>;
|
|
84
|
+
private getPermission;
|
|
85
|
+
/**
|
|
86
|
+
*
|
|
87
|
+
* @see https://blog.csdn.net/a1173537204/article/details/89765932
|
|
88
|
+
* @private
|
|
89
|
+
* @param {PermissionOptions} { fromAppDid, toAppDid }
|
|
90
|
+
* @param {number} permission
|
|
91
|
+
* @param {boolean} status
|
|
92
|
+
* @return {*} {Promise<void>}
|
|
93
|
+
* @memberof S3SpaceConfig
|
|
94
|
+
*/
|
|
95
|
+
private setPermission;
|
|
96
|
+
/**
|
|
97
|
+
*
|
|
98
|
+
* @refactor 这部分的实现大同小异,之后可以抽象到上层实现,这样可以减少代码量 @jianchao
|
|
99
|
+
* @description
|
|
100
|
+
* @param {PermissionOptions} options
|
|
101
|
+
* @param {boolean} value
|
|
102
|
+
* @return {*} {Promise<void>}
|
|
103
|
+
* @memberof ObjectSpace
|
|
104
|
+
*/
|
|
105
|
+
setListable(options: PermissionOptions, value: boolean): Promise<void>;
|
|
106
|
+
setReadable(options: PermissionOptions, value: boolean): Promise<void>;
|
|
107
|
+
setWritable(options: PermissionOptions, value: boolean): Promise<void>;
|
|
108
|
+
isListable(options: PermissionOptions): Promise<boolean>;
|
|
109
|
+
isReadable(options: PermissionOptions): Promise<boolean>;
|
|
110
|
+
isWritable(options: PermissionOptions): Promise<boolean>;
|
|
111
|
+
}
|