@omujs/omu 0.9.47 → 0.9.49
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/dts/api/asset/extension.d.ts +25 -0
- package/dist/dts/api/asset/index.d.ts +2 -0
- package/dist/dts/api/dashboard/extension.d.ts +183 -0
- package/{src/api/dashboard/handler.ts → dist/dts/api/dashboard/handler.d.ts} +0 -2
- package/dist/dts/api/dashboard/index.d.ts +3 -0
- package/dist/dts/api/dashboard/packets.d.ts +73 -0
- package/dist/dts/api/endpoint/endpoint.d.ts +21 -0
- package/dist/dts/api/endpoint/extension.d.ts +17 -0
- package/{src/api/endpoint/index.ts → dist/dts/api/endpoint/index.d.ts} +0 -1
- package/dist/dts/api/endpoint/packets.d.ts +51 -0
- package/dist/dts/api/extension-registry.d.ts +8 -0
- package/dist/dts/api/extension.d.ts +11 -0
- package/dist/dts/api/http/extension.d.ts +41 -0
- package/dist/dts/api/http/http.d.ts +36 -0
- package/{src/api/http/index.ts → dist/dts/api/http/index.d.ts} +0 -1
- package/dist/dts/api/http/websocket.d.ts +125 -0
- package/dist/dts/api/i18n/extension.d.ts +19 -0
- package/{src/api/i18n/index.ts → dist/dts/api/i18n/index.d.ts} +0 -1
- package/{src/api/index.ts → dist/dts/api/index.d.ts} +0 -1
- package/dist/dts/api/logger/extension.d.ts +25 -0
- package/dist/dts/api/logger/index.d.ts +1 -0
- package/dist/dts/api/logger/packets.d.ts +18 -0
- package/dist/dts/api/permission/extension.d.ts +19 -0
- package/{src/api/permission/index.ts → dist/dts/api/permission/index.d.ts} +0 -1
- package/dist/dts/api/permission/permission.d.ts +25 -0
- package/dist/dts/api/plugin/extension.d.ts +43 -0
- package/{src/api/plugin/index.ts → dist/dts/api/plugin/index.d.ts} +0 -1
- package/{src/api/plugin/package-info.ts → dist/dts/api/plugin/package-info.d.ts} +0 -7
- package/dist/dts/api/registry/extension.d.ts +23 -0
- package/{src/api/registry/index.ts → dist/dts/api/registry/index.d.ts} +0 -1
- package/dist/dts/api/registry/packets.d.ts +20 -0
- package/{src/api/registry/registry.ts → dist/dts/api/registry/registry.d.ts} +11 -53
- package/dist/dts/api/server/extension.d.ts +61 -0
- package/dist/dts/api/server/index.d.ts +1 -0
- package/dist/dts/api/session/extension.d.ts +52 -0
- package/dist/dts/api/session/index.d.ts +1 -0
- package/dist/dts/api/signal/extension.d.ts +19 -0
- package/dist/dts/api/signal/packets.d.ts +21 -0
- package/dist/dts/api/signal/signal.d.ts +33 -0
- package/dist/dts/api/table/extension.d.ts +26 -0
- package/{src/api/table/index.ts → dist/dts/api/table/index.d.ts} +0 -1
- package/dist/dts/api/table/packets.d.ts +65 -0
- package/dist/dts/api/table/table.d.ts +75 -0
- package/dist/dts/app.d.ts +49 -0
- package/dist/dts/const.d.ts +2 -0
- package/dist/dts/errors.d.ts +36 -0
- package/dist/dts/event/index.d.ts +6 -0
- package/dist/dts/helper.d.ts +10 -0
- package/dist/dts/identifier.d.ts +51 -0
- package/dist/dts/index.d.ts +36 -0
- package/{src/localization/index.ts → dist/dts/localization/index.d.ts} +0 -1
- package/dist/dts/localization/locale.d.ts +735 -0
- package/{src/localization/localization.ts → dist/dts/localization/localization.d.ts} +0 -2
- package/dist/dts/lock.d.ts +6 -0
- package/dist/dts/network/connection.d.ts +17 -0
- package/dist/dts/network/encryption.d.ts +38 -0
- package/dist/dts/network/frame-transport.d.ts +22 -0
- package/{src/network/index.ts → dist/dts/network/index.d.ts} +0 -1
- package/dist/dts/network/network.d.ts +59 -0
- package/{src/network/packet/index.ts → dist/dts/network/packet/index.d.ts} +0 -1
- package/dist/dts/network/packet/packet-types.d.ts +84 -0
- package/dist/dts/network/packet/packet.d.ts +25 -0
- package/dist/dts/network/websocket-transport.d.ts +24 -0
- package/dist/dts/omu.d.ts +61 -0
- package/dist/dts/result.d.ts +26 -0
- package/dist/dts/serialize/bytebuffer.d.ts +73 -0
- package/dist/dts/serialize/serializer.d.ts +26 -0
- package/dist/dts/token.d.ts +14 -0
- package/dist/dts/version.d.ts +2 -0
- package/dist/esm/address.js +4 -0
- package/dist/esm/api/asset/extension.js +911 -0
- package/dist/esm/api/asset/index.js +909 -0
- package/dist/esm/api/dashboard/extension.js +1362 -0
- package/dist/esm/api/dashboard/handler.js +4 -0
- package/dist/esm/api/dashboard/index.js +1361 -0
- package/dist/esm/api/dashboard/packets.js +419 -0
- package/dist/esm/api/endpoint/endpoint.js +383 -0
- package/dist/esm/api/endpoint/extension.js +1096 -0
- package/dist/esm/api/endpoint/index.js +383 -0
- package/dist/esm/api/endpoint/packets.js +799 -0
- package/dist/esm/api/extension-registry.js +23 -0
- package/dist/esm/api/extension.js +278 -0
- package/dist/esm/api/http/extension.js +1420 -0
- package/dist/esm/api/http/http.js +448 -0
- package/dist/esm/api/http/index.js +1419 -0
- package/dist/esm/api/http/websocket.js +220 -0
- package/dist/esm/api/i18n/extension.js +1339 -0
- package/dist/esm/api/i18n/index.js +1337 -0
- package/dist/esm/api/index.js +295 -0
- package/dist/esm/api/logger/extension.js +856 -0
- package/dist/esm/api/logger/index.js +852 -0
- package/dist/esm/api/logger/packets.js +673 -0
- package/dist/esm/api/permission/extension.js +535 -0
- package/dist/esm/api/permission/index.js +294 -0
- package/dist/esm/api/permission/permission.js +294 -0
- package/dist/esm/api/plugin/extension.js +531 -0
- package/dist/esm/api/plugin/index.js +529 -0
- package/dist/esm/api/plugin/package-info.js +4 -0
- package/dist/esm/api/registry/extension.js +1286 -0
- package/dist/esm/api/registry/index.js +1285 -0
- package/dist/esm/api/registry/packets.js +694 -0
- package/dist/esm/api/registry/registry.js +383 -0
- package/dist/esm/api/server/extension.js +2140 -0
- package/dist/esm/api/server/index.js +2118 -0
- package/dist/esm/api/session/extension.js +2235 -0
- package/dist/esm/api/session/index.js +2235 -0
- package/dist/esm/api/signal/extension.js +1031 -0
- package/dist/esm/api/signal/index.js +379 -0
- package/dist/esm/api/signal/packets.js +690 -0
- package/dist/esm/api/signal/signal.js +379 -0
- package/dist/esm/api/table/extension.js +1553 -0
- package/dist/esm/api/table/index.js +1552 -0
- package/dist/esm/api/table/packets.js +904 -0
- package/dist/esm/api/table/table.js +383 -0
- package/dist/esm/app.js +264 -0
- package/dist/esm/const.js +11 -0
- package/dist/esm/errors.js +548 -0
- package/dist/esm/event/index.js +22 -0
- package/dist/esm/helper.js +15 -0
- package/dist/esm/identifier.js +266 -0
- package/dist/esm/index.js +5186 -0
- package/dist/esm/localization/index.js +742 -0
- package/dist/esm/localization/locale.js +742 -0
- package/dist/esm/localization/localization.js +4 -0
- package/dist/esm/lock.js +46 -0
- package/dist/esm/network/connection.js +293 -0
- package/dist/esm/network/encryption.js +986 -0
- package/dist/esm/network/frame-transport.js +531 -0
- package/dist/esm/network/index.js +1627 -0
- package/dist/esm/network/network.js +1368 -0
- package/dist/esm/network/packet/index.js +485 -0
- package/dist/esm/network/packet/packet-types.js +486 -0
- package/dist/esm/network/packet/packet.js +126 -0
- package/dist/esm/network/websocket-transport.js +493 -0
- package/dist/esm/omu.js +4945 -0
- package/dist/esm/result.js +68 -0
- package/dist/esm/serialize/bytebuffer.js +384 -0
- package/dist/esm/serialize/index.js +471 -0
- package/dist/esm/serialize/serializer.js +97 -0
- package/dist/esm/token.js +42 -0
- package/dist/esm/version.js +11 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +4 -1
- package/CHANGELOG.md +0 -1837
- package/src/api/asset/extension.ts +0 -193
- package/src/api/asset/index.ts +0 -5
- package/src/api/dashboard/extension.ts +0 -651
- package/src/api/dashboard/index.ts +0 -38
- package/src/api/dashboard/packets.ts +0 -126
- package/src/api/endpoint/endpoint.ts +0 -56
- package/src/api/endpoint/extension.ts +0 -133
- package/src/api/endpoint/packets.ts +0 -176
- package/src/api/extension-registry.ts +0 -17
- package/src/api/extension.ts +0 -19
- package/src/api/http/extension.ts +0 -401
- package/src/api/http/http.ts +0 -79
- package/src/api/http/websocket.ts +0 -283
- package/src/api/i18n/extension.ts +0 -65
- package/src/api/logger/extension.ts +0 -75
- package/src/api/logger/index.ts +0 -4
- package/src/api/logger/packets.ts +0 -38
- package/src/api/permission/extension.ts +0 -107
- package/src/api/permission/permission.ts +0 -53
- package/src/api/plugin/extension.ts +0 -100
- package/src/api/registry/extension.ts +0 -326
- package/src/api/registry/packets.ts +0 -64
- package/src/api/server/extension.ts +0 -155
- package/src/api/server/index.ts +0 -11
- package/src/api/session/extension.ts +0 -205
- package/src/api/session/index.ts +0 -7
- package/src/api/signal/extension.ts +0 -125
- package/src/api/signal/packets.ts +0 -61
- package/src/api/signal/signal.ts +0 -67
- package/src/api/table/extension.ts +0 -554
- package/src/api/table/packets.ts +0 -252
- package/src/api/table/table.ts +0 -113
- package/src/app.ts +0 -95
- package/src/const.ts +0 -2
- package/src/errors.ts +0 -70
- package/src/event/index.ts +0 -18
- package/src/helper.ts +0 -16
- package/src/identifier.ts +0 -256
- package/src/index.ts +0 -87
- package/src/localization/locale.ts +0 -737
- package/src/lock.ts +0 -43
- package/src/network/connection.ts +0 -45
- package/src/network/encryption.ts +0 -221
- package/src/network/frame-transport.ts +0 -186
- package/src/network/network.ts +0 -322
- package/src/network/packet/packet-types.ts +0 -164
- package/src/network/packet/packet.ts +0 -55
- package/src/network/websocket-transport.ts +0 -123
- package/src/omu.ts +0 -156
- package/src/result.ts +0 -78
- package/src/serialize/bytebuffer.ts +0 -432
- package/src/serialize/serializer.ts +0 -149
- package/src/token.ts +0 -39
- package/src/version.ts +0 -2
- package/tsconfig.json +0 -18
- /package/{src/address.ts → dist/dts/address.d.ts} +0 -0
- /package/{src/api/signal/index.ts → dist/dts/api/signal/index.d.ts} +0 -0
- /package/{src/serialize/index.ts → dist/dts/serialize/index.d.ts} +0 -0
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import { Identifier, IntoId } from '../../identifier';
|
|
2
|
-
import { Omu } from '../../omu';
|
|
3
|
-
import { ByteReader, ByteWriter, Serializer } from '../../serialize';
|
|
4
|
-
import { EndpointType } from '../endpoint/endpoint.js';
|
|
5
|
-
import { ExtensionType } from '../extension.js';
|
|
6
|
-
|
|
7
|
-
export const ASSET_EXTENSION_TYPE: ExtensionType<AssetExtension> = new ExtensionType(
|
|
8
|
-
'asset',
|
|
9
|
-
(omu: Omu) => new AssetExtension(omu),
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
export type Asset = {
|
|
13
|
-
id: Identifier;
|
|
14
|
-
buffer: Uint8Array;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const FILE_SERIALIZER = new Serializer<Asset, Uint8Array>(
|
|
18
|
-
(file) => {
|
|
19
|
-
const writer = new ByteWriter();
|
|
20
|
-
writer.writeString(file.id.key());
|
|
21
|
-
writer.writeUint8Array(file.buffer);
|
|
22
|
-
return writer.finish();
|
|
23
|
-
},
|
|
24
|
-
(data) => {
|
|
25
|
-
const reader = ByteReader.fromUint8Array(data);
|
|
26
|
-
const identifier = Identifier.fromKey(reader.readString());
|
|
27
|
-
const buffer = reader.readUint8Array();
|
|
28
|
-
reader.finish();
|
|
29
|
-
return { id: identifier, buffer };
|
|
30
|
-
},
|
|
31
|
-
);
|
|
32
|
-
const FILE_ARRAY_SERIALIZER = new Serializer<Asset[], Uint8Array>(
|
|
33
|
-
(files) => {
|
|
34
|
-
const writer = new ByteWriter();
|
|
35
|
-
writer.writeULEB128(files.length);
|
|
36
|
-
for (const file of files) {
|
|
37
|
-
writer.writeString(file.id.key());
|
|
38
|
-
writer.writeUint8Array(file.buffer);
|
|
39
|
-
}
|
|
40
|
-
return writer.finish();
|
|
41
|
-
},
|
|
42
|
-
(data) => {
|
|
43
|
-
const reader = ByteReader.fromUint8Array(data);
|
|
44
|
-
const length = reader.readULEB128();
|
|
45
|
-
const files: Asset[] = [];
|
|
46
|
-
for (let i = 0; i < length; i++) {
|
|
47
|
-
const identifier = Identifier.fromKey(reader.readString());
|
|
48
|
-
const buffer = reader.readUint8Array();
|
|
49
|
-
files.push({ id: identifier, buffer });
|
|
50
|
-
}
|
|
51
|
-
reader.finish();
|
|
52
|
-
return files;
|
|
53
|
-
},
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
export const ASSET_PERMISSION_ID: Identifier = ASSET_EXTENSION_TYPE.join('permission');
|
|
57
|
-
|
|
58
|
-
const ASSET_UPLOAD_ENDPOINT = EndpointType.createSerialized<Asset, Identifier>(
|
|
59
|
-
ASSET_EXTENSION_TYPE,
|
|
60
|
-
{
|
|
61
|
-
name: 'upload',
|
|
62
|
-
requestSerializer: FILE_SERIALIZER,
|
|
63
|
-
responseSerializer: Serializer.of(Identifier).toJson(),
|
|
64
|
-
permissionId: ASSET_PERMISSION_ID,
|
|
65
|
-
},
|
|
66
|
-
);
|
|
67
|
-
const ASSET_UPLOAD_MANY_ENDPOINT = EndpointType.createSerialized<Asset[], Identifier[]>(
|
|
68
|
-
ASSET_EXTENSION_TYPE,
|
|
69
|
-
{
|
|
70
|
-
name: 'upload_many',
|
|
71
|
-
requestSerializer: FILE_ARRAY_SERIALIZER,
|
|
72
|
-
responseSerializer: Serializer.of(Identifier).toArray().pipe(Serializer.json()),
|
|
73
|
-
permissionId: ASSET_PERMISSION_ID,
|
|
74
|
-
},
|
|
75
|
-
);
|
|
76
|
-
const ASSET_DOWNLOAD_ENDPOINT = EndpointType.createSerialized<Identifier, Asset>(
|
|
77
|
-
ASSET_EXTENSION_TYPE,
|
|
78
|
-
{
|
|
79
|
-
name: 'download',
|
|
80
|
-
requestSerializer: Serializer.of(Identifier).pipe(Serializer.json()),
|
|
81
|
-
responseSerializer: FILE_SERIALIZER,
|
|
82
|
-
permissionId: ASSET_PERMISSION_ID,
|
|
83
|
-
},
|
|
84
|
-
);
|
|
85
|
-
const ASSET_DOWNLOAD_MANY_ENDPOINT = EndpointType.createSerialized<Identifier[], Asset[]>(
|
|
86
|
-
ASSET_EXTENSION_TYPE,
|
|
87
|
-
{
|
|
88
|
-
name: 'download_many',
|
|
89
|
-
requestSerializer: Serializer.of(Identifier).toArray().pipe(Serializer.json()),
|
|
90
|
-
responseSerializer: FILE_ARRAY_SERIALIZER,
|
|
91
|
-
permissionId: ASSET_PERMISSION_ID,
|
|
92
|
-
},
|
|
93
|
-
);
|
|
94
|
-
const ASSET_DELETE_ENDPOINT = EndpointType.createJson<Identifier, null>(
|
|
95
|
-
ASSET_EXTENSION_TYPE,
|
|
96
|
-
{
|
|
97
|
-
name: 'delete',
|
|
98
|
-
requestSerializer: Identifier,
|
|
99
|
-
permissionId: ASSET_PERMISSION_ID,
|
|
100
|
-
},
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
const ASSET_GENERATE_TOKEN_ENDPOINT = EndpointType.createJson<object, { token: string }>(
|
|
104
|
-
ASSET_EXTENSION_TYPE,
|
|
105
|
-
{
|
|
106
|
-
name: 'token_generate',
|
|
107
|
-
permissionId: ASSET_PERMISSION_ID,
|
|
108
|
-
},
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
export class AssetExtension {
|
|
112
|
-
public readonly type: ExtensionType<AssetExtension> = ASSET_EXTENSION_TYPE;
|
|
113
|
-
private assetToken: string | undefined = undefined;
|
|
114
|
-
|
|
115
|
-
constructor(private readonly omu: Omu) {
|
|
116
|
-
omu.network.event.disconnected.listen(() => {
|
|
117
|
-
this.assetToken = undefined;
|
|
118
|
-
});
|
|
119
|
-
omu.onReady(async () => {
|
|
120
|
-
if (omu.permissions.required(ASSET_PERMISSION_ID)) {
|
|
121
|
-
await this.requestGenerateAssetToken();
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
public async upload(identifier: IntoId, buffer: Uint8Array): Promise<Identifier> {
|
|
127
|
-
const assetIdentifier = await this.omu.endpoints.call(ASSET_UPLOAD_ENDPOINT, {
|
|
128
|
-
id: Identifier.from(identifier),
|
|
129
|
-
buffer,
|
|
130
|
-
});
|
|
131
|
-
return assetIdentifier;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
public async uploadMany(...files: Asset[]): Promise<Identifier[]> {
|
|
135
|
-
const uploaded = await this.omu.endpoints.call(ASSET_UPLOAD_MANY_ENDPOINT, files);
|
|
136
|
-
return uploaded;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
public async download(identifier: IntoId): Promise<Asset> {
|
|
140
|
-
const id = Identifier.from(identifier);
|
|
141
|
-
const downloaded = await this.omu.endpoints.call(ASSET_DOWNLOAD_ENDPOINT, id);
|
|
142
|
-
return downloaded;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
public async downloadMany(...identifiers: IntoId[]): Promise<Asset[]> {
|
|
146
|
-
const downloaded = await this.omu.endpoints.call(
|
|
147
|
-
ASSET_DOWNLOAD_MANY_ENDPOINT,
|
|
148
|
-
identifiers.map((id) => Identifier.from(id)),
|
|
149
|
-
);
|
|
150
|
-
return downloaded;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
public async delete(identifier: IntoId): Promise<void> {
|
|
154
|
-
const id = Identifier.from(identifier);
|
|
155
|
-
await this.omu.endpoints.call(ASSET_DELETE_ENDPOINT, id);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
private async requestGenerateAssetToken() {
|
|
159
|
-
const result = await this.omu.endpoints.call(ASSET_GENERATE_TOKEN_ENDPOINT, {});
|
|
160
|
-
this.assetToken = result.token;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
public url(
|
|
164
|
-
id: IntoId,
|
|
165
|
-
options?: { cache?: 'no-cache' },
|
|
166
|
-
): string {
|
|
167
|
-
if (!this.assetToken) {
|
|
168
|
-
throw new Error('Asset token is not set');
|
|
169
|
-
}
|
|
170
|
-
const key = Identifier.from(id).key();
|
|
171
|
-
const address = this.omu.network.address;
|
|
172
|
-
const protocol = address.secure ? 'https' : 'http';
|
|
173
|
-
const url = new URL(`${protocol}://${address.host}:${address.port}/asset`);
|
|
174
|
-
url.searchParams.set('asset_token', this.assetToken);
|
|
175
|
-
url.searchParams.set('id', key);
|
|
176
|
-
if (options?.cache === 'no-cache') {
|
|
177
|
-
url.searchParams.set('t', Date.now().toString());
|
|
178
|
-
}
|
|
179
|
-
return url.toString();
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
public proxy(url: string): string {
|
|
183
|
-
if (!this.assetToken) {
|
|
184
|
-
throw new Error('Asset token is not set');
|
|
185
|
-
}
|
|
186
|
-
const address = this.omu.network.address;
|
|
187
|
-
const protocol = address.secure ? 'https' : 'http';
|
|
188
|
-
const proxyUrl = new URL(`${protocol}://${address.host}:${address.port}/proxy`);
|
|
189
|
-
proxyUrl.searchParams.set('asset_token', this.assetToken);
|
|
190
|
-
proxyUrl.searchParams.set('url', url);
|
|
191
|
-
return proxyUrl.toString();
|
|
192
|
-
}
|
|
193
|
-
}
|