@did-space/core 0.1.53
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/README.md +1 -0
- package/dist/configuration/index.d.ts +1 -0
- package/dist/configuration/index.js +13 -0
- package/dist/configuration/space-config.d.ts +23 -0
- package/dist/configuration/space-config.js +8 -0
- package/dist/constants/index.d.ts +2 -0
- package/dist/constants/index.js +5 -0
- package/dist/drivers/base.d.ts +38 -0
- package/dist/drivers/base.js +171 -0
- package/dist/drivers/index.d.ts +1 -0
- package/dist/drivers/index.js +13 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +20 -0
- package/dist/meta/data.d.ts +3 -0
- package/dist/meta/data.js +2 -0
- package/dist/meta/index.d.ts +2 -0
- package/dist/meta/index.js +14 -0
- package/dist/meta/object.d.ts +10 -0
- package/dist/meta/object.js +2 -0
- package/dist/protocols/base-space.d.ts +4 -0
- package/dist/protocols/base-space.js +2 -0
- package/dist/protocols/driver.d.ts +7 -0
- package/dist/protocols/driver.js +2 -0
- package/dist/protocols/index.d.ts +5 -0
- package/dist/protocols/index.js +17 -0
- package/dist/protocols/space-config.d.ts +17 -0
- package/dist/protocols/space-config.js +2 -0
- package/dist/protocols/space-operator.d.ts +36 -0
- package/dist/protocols/space-operator.js +2 -0
- package/dist/protocols/space-owner-operator.d.ts +9 -0
- package/dist/protocols/space-owner-operator.js +2 -0
- package/dist/protocols/space.d.ts +5 -0
- package/dist/protocols/space.js +2 -0
- package/dist/schemas/index.d.ts +2 -0
- package/dist/schemas/index.js +14 -0
- package/dist/schemas/space-configuration.d.ts +4 -0
- package/dist/schemas/space-configuration.js +28 -0
- package/dist/schemas/space-options.d.ts +1 -0
- package/dist/schemas/space-options.js +7 -0
- package/dist/space/index.d.ts +38 -0
- package/dist/space/index.js +160 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +15 -0
- package/dist/utils/logger.d.ts +2 -0
- package/dist/utils/logger.js +5 -0
- package/dist/utils/stream-to-string.d.ts +1 -0
- package/dist/utils/stream-to-string.js +10 -0
- package/dist/utils/string-to-stream.d.ts +3 -0
- package/dist/utils/string-to-stream.js +11 -0
- package/package.json +64 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# DID Space Core
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './space-config';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./space-config"), exports);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface SpaceConfig {
|
|
2
|
+
did: string;
|
|
3
|
+
drive?: 'fs' | 's3';
|
|
4
|
+
type?: 'buy' | 'default';
|
|
5
|
+
name: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
size?: number;
|
|
8
|
+
assetDid: string;
|
|
9
|
+
createAt: string;
|
|
10
|
+
updateAt: string;
|
|
11
|
+
expireAt: string;
|
|
12
|
+
ownerDid: string;
|
|
13
|
+
permissions?: Permissions;
|
|
14
|
+
}
|
|
15
|
+
export interface Permissions {
|
|
16
|
+
[fromAppDid: string]: {
|
|
17
|
+
[toAppDid: string]: number;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export declare type Scope = 'list:object' | 'read:object' | 'write:object';
|
|
21
|
+
export declare const Scopes: {
|
|
22
|
+
[key in Scope]: number;
|
|
23
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Stream } from 'stream';
|
|
3
|
+
import { SpaceConfig } from '../configuration';
|
|
4
|
+
import { Data, Object } from '../meta';
|
|
5
|
+
import { AppSpaceOptions, DeleteOptions, DriverOptions, DriverProtocol, ListOptions, PermissionOptions, ReadOptions, SpaceConfigProtocol, SpaceOperatorProtocol, WriteOptions } from '../protocols';
|
|
6
|
+
export declare abstract class BaseDriver implements DriverProtocol {
|
|
7
|
+
readonly options: DriverOptions;
|
|
8
|
+
constructor(options: DriverOptions);
|
|
9
|
+
abstract get spaceOperator(): SpaceOperatorProtocol;
|
|
10
|
+
abstract get spaceConfig(): SpaceConfigProtocol;
|
|
11
|
+
createSpace(spaceConfig: SpaceConfig): Promise<void>;
|
|
12
|
+
destroySpace(): Promise<void>;
|
|
13
|
+
isSpaceCreated(): Promise<boolean>;
|
|
14
|
+
getSpaceSize(): Promise<number>;
|
|
15
|
+
createAppSpace(options: AppSpaceOptions): Promise<void>;
|
|
16
|
+
destroyAppSpace(options: AppSpaceOptions): Promise<void>;
|
|
17
|
+
getAppSpacePath(options: AppSpaceOptions): Promise<string>;
|
|
18
|
+
createConfig(spaceConfig: SpaceConfig): Promise<void>;
|
|
19
|
+
destroyConfig(): Promise<void>;
|
|
20
|
+
set<T = any>(key: string, value: T): Promise<void>;
|
|
21
|
+
get<T = any>(key: string): Promise<T>;
|
|
22
|
+
setListable(options: PermissionOptions, value: boolean): Promise<void>;
|
|
23
|
+
setReadable(options: PermissionOptions, value: boolean): Promise<void>;
|
|
24
|
+
setWritable(options: PermissionOptions, value: boolean): Promise<void>;
|
|
25
|
+
isListable(options: PermissionOptions): Promise<boolean>;
|
|
26
|
+
isReadable(options: PermissionOptions): Promise<boolean>;
|
|
27
|
+
isWritable(options: PermissionOptions): Promise<boolean>;
|
|
28
|
+
write(options: WriteOptions): Promise<void>;
|
|
29
|
+
delete(options: DeleteOptions): Promise<void>;
|
|
30
|
+
read(options: ReadOptions): Promise<Stream>;
|
|
31
|
+
exists(options: ReadOptions): Promise<boolean>;
|
|
32
|
+
lists(options: ListOptions): Promise<Object[]>;
|
|
33
|
+
list(options: ListOptions): Promise<Object>;
|
|
34
|
+
writeAsOwner(key: string, data: Data): Promise<void>;
|
|
35
|
+
deleteAsOwner(key: string): Promise<void>;
|
|
36
|
+
readAsOwner(key: string): Promise<Stream>;
|
|
37
|
+
existsAsOwner(key: string): Promise<boolean>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.BaseDriver = void 0;
|
|
13
|
+
class BaseDriver {
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.options = options;
|
|
16
|
+
}
|
|
17
|
+
createSpace(spaceConfig) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
yield this.spaceConfig.createConfig(spaceConfig);
|
|
20
|
+
yield this.spaceOperator.createSpace(spaceConfig);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
destroySpace() {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
yield this.spaceConfig.destroyConfig();
|
|
26
|
+
yield this.spaceOperator.destroySpace();
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
isSpaceCreated() {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
return this.spaceOperator.isSpaceCreated();
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
getSpaceSize() {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
return this.spaceOperator.getSpaceSize();
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
createAppSpace(options) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
yield this.spaceOperator.createAppSpace(options);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
destroyAppSpace(options) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
yield this.spaceOperator.destroyAppSpace(options);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
getAppSpacePath(options) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
return this.spaceOperator.getAppSpacePath(options);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
createConfig(spaceConfig) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
yield this.spaceConfig.createConfig(spaceConfig);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
destroyConfig() {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
yield this.spaceConfig.destroyConfig();
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
set(key, value) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
yield this.spaceConfig.set(key, value);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
get(key) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
return this.spaceConfig.get(key);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
setListable(options, value) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
yield this.spaceConfig.setListable(options, value);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
setReadable(options, value) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
yield this.spaceConfig.setReadable(options, value);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
setWritable(options, value) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
yield this.spaceConfig.setWritable(options, value);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
isListable(options) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
return this.spaceConfig.isListable(options);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
isReadable(options) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
return this.spaceConfig.isReadable(options);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
isWritable(options) {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
return this.spaceConfig.isWritable(options);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
write(options) {
|
|
105
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
if (!(yield this.spaceConfig.isWritable({
|
|
107
|
+
fromAppDid: options.appDid,
|
|
108
|
+
toAppDid: options.appDid,
|
|
109
|
+
}))) {
|
|
110
|
+
throw new Error('Unable to write object with insufficient permissions');
|
|
111
|
+
}
|
|
112
|
+
yield this.spaceOperator.write(options);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
delete(options) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
yield this.spaceOperator.delete(options);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
read(options) {
|
|
121
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
if (!(yield this.spaceConfig.isReadable({
|
|
123
|
+
fromAppDid: options.appDid,
|
|
124
|
+
toAppDid: options.appDid,
|
|
125
|
+
}))) {
|
|
126
|
+
throw new Error('Unable to read object with insufficient permissions');
|
|
127
|
+
}
|
|
128
|
+
return this.spaceOperator.read(options);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
exists(options) {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
if (!(yield this.spaceConfig.isListable({
|
|
134
|
+
fromAppDid: options.appDid,
|
|
135
|
+
toAppDid: options.appDid,
|
|
136
|
+
}))) {
|
|
137
|
+
throw new Error('Unable to list object with insufficient permissions');
|
|
138
|
+
}
|
|
139
|
+
return this.spaceOperator.exists(options);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
lists(options) {
|
|
143
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
+
return this.spaceOperator.lists(options);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
list(options) {
|
|
148
|
+
return this.spaceOperator.list(options);
|
|
149
|
+
}
|
|
150
|
+
writeAsOwner(key, data) {
|
|
151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
return this.spaceOperator.writeAsOwner(key, data);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
deleteAsOwner(key) {
|
|
156
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
157
|
+
return this.spaceOperator.deleteAsOwner(key);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
readAsOwner(key) {
|
|
161
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
return this.spaceOperator.readAsOwner(key);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
existsAsOwner(key) {
|
|
166
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
167
|
+
return this.spaceOperator.existsAsOwner(key);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
exports.BaseDriver = BaseDriver;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './base';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./base"), exports);
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
// eslint-disable-next-line import/export
|
|
14
|
+
__exportStar(require("./meta"), exports);
|
|
15
|
+
__exportStar(require("./configuration"), exports);
|
|
16
|
+
__exportStar(require("./drivers"), exports);
|
|
17
|
+
__exportStar(require("./protocols"), exports);
|
|
18
|
+
__exportStar(require("./schemas"), exports);
|
|
19
|
+
__exportStar(require("./utils"), exports);
|
|
20
|
+
__exportStar(require("./space"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./data"), exports);
|
|
14
|
+
__exportStar(require("./object"), exports);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./driver"), exports);
|
|
14
|
+
__exportStar(require("./space"), exports);
|
|
15
|
+
__exportStar(require("./space-config"), exports);
|
|
16
|
+
__exportStar(require("./space-operator"), exports);
|
|
17
|
+
__exportStar(require("./space-owner-operator"), exports);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SpaceConfig } from '../configuration';
|
|
2
|
+
export interface PermissionOptions {
|
|
3
|
+
fromAppDid: string;
|
|
4
|
+
toAppDid: string;
|
|
5
|
+
}
|
|
6
|
+
export interface SpaceConfigProtocol {
|
|
7
|
+
createConfig(spaceConfig: SpaceConfig): Promise<void>;
|
|
8
|
+
destroyConfig(): Promise<void>;
|
|
9
|
+
set<T = any>(key: string, value: T): Promise<void>;
|
|
10
|
+
get<T = any>(key: string): Promise<T>;
|
|
11
|
+
setListable(options: PermissionOptions, value: boolean): Promise<void>;
|
|
12
|
+
setReadable(options: PermissionOptions, value: boolean): Promise<void>;
|
|
13
|
+
setWritable(options: PermissionOptions, value: boolean): Promise<void>;
|
|
14
|
+
isListable(options: PermissionOptions): Promise<boolean>;
|
|
15
|
+
isReadable(options: PermissionOptions): Promise<boolean>;
|
|
16
|
+
isWritable(options: PermissionOptions): Promise<boolean>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Stream } from 'stream';
|
|
3
|
+
import { SpaceConfig } from '../configuration';
|
|
4
|
+
import { Data, Object } from '../meta';
|
|
5
|
+
import { SpaceOwnerOperatorProtocol } from './space-owner-operator';
|
|
6
|
+
export interface AppSpaceOptions {
|
|
7
|
+
appDid: string;
|
|
8
|
+
}
|
|
9
|
+
export interface WriteOptions extends AppSpaceOptions {
|
|
10
|
+
key: string;
|
|
11
|
+
data: Data;
|
|
12
|
+
}
|
|
13
|
+
export interface DeleteOptions extends AppSpaceOptions {
|
|
14
|
+
key: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ReadOptions extends AppSpaceOptions {
|
|
17
|
+
key: string;
|
|
18
|
+
}
|
|
19
|
+
export interface ListOptions {
|
|
20
|
+
key: string;
|
|
21
|
+
}
|
|
22
|
+
export interface SpaceOperatorProtocol extends SpaceOwnerOperatorProtocol {
|
|
23
|
+
createSpace(spaceConfig: SpaceConfig): Promise<void>;
|
|
24
|
+
isSpaceCreated(): Promise<boolean>;
|
|
25
|
+
destroySpace(): Promise<void>;
|
|
26
|
+
getSpaceSize(): Promise<number>;
|
|
27
|
+
createAppSpace(options: AppSpaceOptions): Promise<void>;
|
|
28
|
+
destroyAppSpace(options: AppSpaceOptions): Promise<void>;
|
|
29
|
+
getAppSpacePath(options: AppSpaceOptions): Promise<string>;
|
|
30
|
+
write(options: WriteOptions): Promise<void>;
|
|
31
|
+
delete(options: DeleteOptions): Promise<void>;
|
|
32
|
+
read(options: ReadOptions): Promise<Stream>;
|
|
33
|
+
exists(options: ReadOptions): Promise<boolean>;
|
|
34
|
+
lists(options: ListOptions): Promise<Object[]>;
|
|
35
|
+
list(options: ListOptions): Promise<Object>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Stream } from 'stream';
|
|
3
|
+
import { Data } from '../meta';
|
|
4
|
+
export interface SpaceOwnerOperatorProtocol {
|
|
5
|
+
writeAsOwner(key: string, data: Data): Promise<void>;
|
|
6
|
+
deleteAsOwner(key: string): Promise<void>;
|
|
7
|
+
readAsOwner(key: string): Promise<Stream>;
|
|
8
|
+
existsAsOwner(key: string): Promise<boolean>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./space-options"), exports);
|
|
14
|
+
__exportStar(require("./space-configuration"), exports);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SpaceConfigSchema = void 0;
|
|
7
|
+
const xbytes_1 = __importDefault(require("xbytes"));
|
|
8
|
+
const validator_1 = require("@arcblock/validator");
|
|
9
|
+
/**
|
|
10
|
+
* @see {SpaceConfig}
|
|
11
|
+
*/
|
|
12
|
+
exports.SpaceConfigSchema = validator_1.Joi.object({
|
|
13
|
+
did: validator_1.Joi.DID(),
|
|
14
|
+
// 标识这个驱动是什么,默认取值为 fs, 表示文件存储到了本地的文件系统
|
|
15
|
+
drive: validator_1.Joi.string().valid('fs', 's3').optional().allow('').default('fs'),
|
|
16
|
+
// type: 'buy | 'default'
|
|
17
|
+
type: validator_1.Joi.string().required().default('buy'),
|
|
18
|
+
name: validator_1.Joi.string().required(),
|
|
19
|
+
// @see: https://github.com/sideway/joi/blob/master/API.md#string
|
|
20
|
+
description: validator_1.Joi.string().required().allow('').default(''),
|
|
21
|
+
// 字节数,默认给个1GB
|
|
22
|
+
size: validator_1.Joi.number().required().default(xbytes_1.default.parseSize('1GB')),
|
|
23
|
+
assetDid: validator_1.Joi.DID(),
|
|
24
|
+
createAt: validator_1.Joi.string().required(),
|
|
25
|
+
updateAt: validator_1.Joi.string().required(),
|
|
26
|
+
expireAt: validator_1.Joi.string().required(),
|
|
27
|
+
ownerDid: validator_1.Joi.DID(),
|
|
28
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SpaceOptionsSchema: import("joi").ObjectSchema<any>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SpaceOptionsSchema = void 0;
|
|
4
|
+
const validator_1 = require("@arcblock/validator");
|
|
5
|
+
exports.SpaceOptionsSchema = validator_1.Joi.object({
|
|
6
|
+
root: validator_1.Joi.string().required(),
|
|
7
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Stream } from 'stream';
|
|
3
|
+
import { SpaceConfig } from '../configuration';
|
|
4
|
+
import { Data, Object } from '../meta';
|
|
5
|
+
import { WriteOptions, ReadOptions, SpaceProtocol, DriverProtocol, AppSpaceOptions, PermissionOptions, DeleteOptions, ListOptions } 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
|
+
write(options: WriteOptions): Promise<void>;
|
|
28
|
+
delete(options: DeleteOptions): Promise<void>;
|
|
29
|
+
read(options: ReadOptions): Promise<Stream>;
|
|
30
|
+
exists(options: ReadOptions): Promise<boolean>;
|
|
31
|
+
lists(options: ListOptions): Promise<Object[]>;
|
|
32
|
+
list(options: ListOptions): Promise<Object>;
|
|
33
|
+
writeAsOwner(key: string, data: Data): Promise<void>;
|
|
34
|
+
deleteAsOwner(key: string): Promise<void>;
|
|
35
|
+
readAsOwner(key: string): Promise<Stream>;
|
|
36
|
+
existsAsOwner(key: string): Promise<boolean>;
|
|
37
|
+
static editable(key: string): boolean;
|
|
38
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Space = void 0;
|
|
13
|
+
class Space {
|
|
14
|
+
constructor(driver) {
|
|
15
|
+
this.driver = driver;
|
|
16
|
+
}
|
|
17
|
+
createSpace(spaceConfiguration) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
return this.driver.createSpace(spaceConfiguration);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
destroySpace() {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
return this.driver.destroySpace();
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
isSpaceCreated() {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
return this.driver.isSpaceCreated();
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
getSpaceSize() {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
return this.driver.getSpaceSize();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
createAppSpace(options) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
return this.driver.createAppSpace(options);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
destroyAppSpace(options) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
return this.driver.destroyAppSpace(options);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
getAppSpacePath(options) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
return this.driver.getAppSpacePath(options);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
createConfig(spaceConfig) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
return this.driver.createConfig(spaceConfig);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
destroyConfig() {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
return this.driver.destroyConfig();
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
set(key, value) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
return this.driver.set(key, value);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
get(key) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
return this.driver.get(key);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
setListable(options, value) {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
return this.driver.setListable(options, value);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
setReadable(options, value) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
return this.driver.setReadable(options, value);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
setWritable(options, value) {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
return this.driver.setWritable(options, value);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
isListable(options) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
return this.driver.isListable(options);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
isReadable(options) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
return this.driver.isReadable(options);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
isWritable(options) {
|
|
98
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
return this.driver.isWritable(options);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
write(options) {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
return this.driver.write(options);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
delete(options) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
return this.driver.delete(options);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
read(options) {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
return this.driver.read(options);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
exists(options) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
return this.driver.exists(options);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
lists(options) {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
return this.driver.lists(options);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
list(options) {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
return this.driver.list(options);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
writeAsOwner(key, data) {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
return this.driver.writeAsOwner(key, data);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
deleteAsOwner(key) {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
if (Space.READONLY_OBJECT_KEYS.includes(key)) {
|
|
140
|
+
throw new Error(`Object ${key} cannot be deleted`);
|
|
141
|
+
}
|
|
142
|
+
return this.driver.deleteAsOwner(key);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
readAsOwner(key) {
|
|
146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
return this.driver.readAsOwner(key);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
existsAsOwner(key) {
|
|
151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
return this.driver.existsAsOwner(key);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
static editable(key) {
|
|
156
|
+
return !Space.READONLY_OBJECT_KEYS.includes(key);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
exports.Space = Space;
|
|
160
|
+
Space.READONLY_OBJECT_KEYS = ['/config.yml'];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./logger"), exports);
|
|
14
|
+
__exportStar(require("./stream-to-string"), exports);
|
|
15
|
+
__exportStar(require("./string-to-stream"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const streamToString: (stream: any) => Promise<string>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.streamToString = void 0;
|
|
4
|
+
const streamToString = (stream) => new Promise((resolve, reject) => {
|
|
5
|
+
const chunks = [];
|
|
6
|
+
stream.on('data', (chunk) => chunks.push(chunk));
|
|
7
|
+
stream.on('error', reject);
|
|
8
|
+
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
|
|
9
|
+
});
|
|
10
|
+
exports.streamToString = streamToString;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringToStream = void 0;
|
|
4
|
+
const stream_1 = require("stream");
|
|
5
|
+
function stringToStream(str) {
|
|
6
|
+
const stream = new stream_1.Readable();
|
|
7
|
+
stream.push(str);
|
|
8
|
+
stream.push(null);
|
|
9
|
+
return stream;
|
|
10
|
+
}
|
|
11
|
+
exports.stringToStream = stringToStream;
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@did-space/core",
|
|
3
|
+
"version": "0.1.53",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"description": "Decentralized file space managed by DID",
|
|
8
|
+
"author": "linchen1987 <linchen.1987@foxmail.com>",
|
|
9
|
+
"homepage": "",
|
|
10
|
+
"license": "ISC",
|
|
11
|
+
"main": "dist/index.js",
|
|
12
|
+
"typings": "dist/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"lint": "eslint src tests",
|
|
18
|
+
"lint:fix": "npm run lint -- --fix",
|
|
19
|
+
"test": "jest --forceExit --detectOpenHandles --passWithNoTests",
|
|
20
|
+
"coverage": "npm run test -- --coverage",
|
|
21
|
+
"verify": "npm run lint && npm run test && npm run build",
|
|
22
|
+
"prebuild": "rm -fr dist",
|
|
23
|
+
"build": "tsc",
|
|
24
|
+
"build:watch": "npm run build -- -w",
|
|
25
|
+
"pre-commit": "lint-staged"
|
|
26
|
+
},
|
|
27
|
+
"lint-staged": {
|
|
28
|
+
"**/*.{js,ts}": [
|
|
29
|
+
"npm run lint",
|
|
30
|
+
"npm run test",
|
|
31
|
+
"git add ."
|
|
32
|
+
]
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@arcblock/did": "^1.18.26",
|
|
36
|
+
"@arcblock/jwt": "^1.18.26",
|
|
37
|
+
"@arcblock/validator": "^1.18.26",
|
|
38
|
+
"@aws-sdk/client-s3": "^3.45.0",
|
|
39
|
+
"@aws-sdk/signature-v4-crt": "^3.45.0",
|
|
40
|
+
"@blocklet/meta": "^1.8.40",
|
|
41
|
+
"@ocap/mcrypto": "^1.18.26",
|
|
42
|
+
"@ocap/wallet": "^1.18.26",
|
|
43
|
+
"fs-extra": "^10.0.0",
|
|
44
|
+
"joi": "^17.5.0",
|
|
45
|
+
"js-yaml": "^4.1.0",
|
|
46
|
+
"lodash": "^4.17.21",
|
|
47
|
+
"url-join": "^4.0.1",
|
|
48
|
+
"xbytes": "^1.8.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@arcblock/eslint-config-ts": "^0.2.3",
|
|
52
|
+
"@types/fs-extra": "^9.0.13",
|
|
53
|
+
"@types/jest": "^28.1.5",
|
|
54
|
+
"@types/js-yaml": "^4.0.5",
|
|
55
|
+
"@types/lodash": "^4.14.182",
|
|
56
|
+
"@types/node": "15.12.2",
|
|
57
|
+
"@typescript-eslint/eslint-plugin": "^5.30.6",
|
|
58
|
+
"eslint": "^8.19.0",
|
|
59
|
+
"lint-staged": "^13.0.3",
|
|
60
|
+
"ts-jest": "^28.0.6",
|
|
61
|
+
"typescript": "4.4.4"
|
|
62
|
+
},
|
|
63
|
+
"gitHead": "48625a15f22a5b9d6830f2336848cd75f9db42a4"
|
|
64
|
+
}
|