@omujs/omu 0.9.48 → 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.
Files changed (202) hide show
  1. package/dist/dts/api/asset/extension.d.ts +25 -0
  2. package/dist/dts/api/asset/index.d.ts +2 -0
  3. package/dist/dts/api/dashboard/extension.d.ts +183 -0
  4. package/{src/api/dashboard/handler.ts → dist/dts/api/dashboard/handler.d.ts} +0 -2
  5. package/dist/dts/api/dashboard/index.d.ts +3 -0
  6. package/dist/dts/api/dashboard/packets.d.ts +73 -0
  7. package/dist/dts/api/endpoint/endpoint.d.ts +21 -0
  8. package/dist/dts/api/endpoint/extension.d.ts +17 -0
  9. package/{src/api/endpoint/index.ts → dist/dts/api/endpoint/index.d.ts} +0 -1
  10. package/dist/dts/api/endpoint/packets.d.ts +51 -0
  11. package/dist/dts/api/extension-registry.d.ts +8 -0
  12. package/dist/dts/api/extension.d.ts +11 -0
  13. package/dist/dts/api/http/extension.d.ts +41 -0
  14. package/dist/dts/api/http/http.d.ts +36 -0
  15. package/{src/api/http/index.ts → dist/dts/api/http/index.d.ts} +0 -1
  16. package/dist/dts/api/http/websocket.d.ts +125 -0
  17. package/dist/dts/api/i18n/extension.d.ts +19 -0
  18. package/{src/api/i18n/index.ts → dist/dts/api/i18n/index.d.ts} +0 -1
  19. package/{src/api/index.ts → dist/dts/api/index.d.ts} +0 -1
  20. package/dist/dts/api/logger/extension.d.ts +25 -0
  21. package/dist/dts/api/logger/index.d.ts +1 -0
  22. package/dist/dts/api/logger/packets.d.ts +18 -0
  23. package/dist/dts/api/permission/extension.d.ts +19 -0
  24. package/{src/api/permission/index.ts → dist/dts/api/permission/index.d.ts} +0 -1
  25. package/dist/dts/api/permission/permission.d.ts +25 -0
  26. package/dist/dts/api/plugin/extension.d.ts +43 -0
  27. package/{src/api/plugin/index.ts → dist/dts/api/plugin/index.d.ts} +0 -1
  28. package/{src/api/plugin/package-info.ts → dist/dts/api/plugin/package-info.d.ts} +0 -7
  29. package/dist/dts/api/registry/extension.d.ts +23 -0
  30. package/{src/api/registry/index.ts → dist/dts/api/registry/index.d.ts} +0 -1
  31. package/dist/dts/api/registry/packets.d.ts +20 -0
  32. package/{src/api/registry/registry.ts → dist/dts/api/registry/registry.d.ts} +11 -53
  33. package/dist/dts/api/server/extension.d.ts +61 -0
  34. package/dist/dts/api/server/index.d.ts +1 -0
  35. package/dist/dts/api/session/extension.d.ts +52 -0
  36. package/dist/dts/api/session/index.d.ts +1 -0
  37. package/dist/dts/api/signal/extension.d.ts +19 -0
  38. package/dist/dts/api/signal/packets.d.ts +21 -0
  39. package/dist/dts/api/signal/signal.d.ts +33 -0
  40. package/dist/dts/api/table/extension.d.ts +26 -0
  41. package/{src/api/table/index.ts → dist/dts/api/table/index.d.ts} +0 -1
  42. package/dist/dts/api/table/packets.d.ts +65 -0
  43. package/dist/dts/api/table/table.d.ts +75 -0
  44. package/dist/dts/app.d.ts +49 -0
  45. package/dist/dts/const.d.ts +2 -0
  46. package/dist/dts/errors.d.ts +36 -0
  47. package/dist/dts/event/index.d.ts +6 -0
  48. package/dist/dts/helper.d.ts +10 -0
  49. package/dist/dts/identifier.d.ts +51 -0
  50. package/dist/dts/index.d.ts +36 -0
  51. package/{src/localization/index.ts → dist/dts/localization/index.d.ts} +0 -1
  52. package/dist/dts/localization/locale.d.ts +735 -0
  53. package/{src/localization/localization.ts → dist/dts/localization/localization.d.ts} +0 -2
  54. package/dist/dts/lock.d.ts +6 -0
  55. package/dist/dts/network/connection.d.ts +17 -0
  56. package/dist/dts/network/encryption.d.ts +38 -0
  57. package/dist/dts/network/frame-transport.d.ts +22 -0
  58. package/{src/network/index.ts → dist/dts/network/index.d.ts} +0 -1
  59. package/dist/dts/network/network.d.ts +59 -0
  60. package/{src/network/packet/index.ts → dist/dts/network/packet/index.d.ts} +0 -1
  61. package/dist/dts/network/packet/packet-types.d.ts +84 -0
  62. package/dist/dts/network/packet/packet.d.ts +25 -0
  63. package/dist/dts/network/websocket-transport.d.ts +24 -0
  64. package/dist/dts/omu.d.ts +61 -0
  65. package/dist/dts/result.d.ts +26 -0
  66. package/dist/dts/serialize/bytebuffer.d.ts +73 -0
  67. package/dist/dts/serialize/serializer.d.ts +26 -0
  68. package/dist/dts/token.d.ts +14 -0
  69. package/dist/dts/version.d.ts +2 -0
  70. package/dist/esm/address.js +4 -0
  71. package/dist/esm/api/asset/extension.js +911 -0
  72. package/dist/esm/api/asset/index.js +909 -0
  73. package/dist/esm/api/dashboard/extension.js +1362 -0
  74. package/dist/esm/api/dashboard/handler.js +4 -0
  75. package/dist/esm/api/dashboard/index.js +1361 -0
  76. package/dist/esm/api/dashboard/packets.js +419 -0
  77. package/dist/esm/api/endpoint/endpoint.js +383 -0
  78. package/dist/esm/api/endpoint/extension.js +1096 -0
  79. package/dist/esm/api/endpoint/index.js +383 -0
  80. package/dist/esm/api/endpoint/packets.js +799 -0
  81. package/dist/esm/api/extension-registry.js +23 -0
  82. package/dist/esm/api/extension.js +278 -0
  83. package/dist/esm/api/http/extension.js +1420 -0
  84. package/dist/esm/api/http/http.js +448 -0
  85. package/dist/esm/api/http/index.js +1419 -0
  86. package/dist/esm/api/http/websocket.js +220 -0
  87. package/dist/esm/api/i18n/extension.js +1339 -0
  88. package/dist/esm/api/i18n/index.js +1337 -0
  89. package/dist/esm/api/index.js +295 -0
  90. package/dist/esm/api/logger/extension.js +856 -0
  91. package/dist/esm/api/logger/index.js +852 -0
  92. package/dist/esm/api/logger/packets.js +673 -0
  93. package/dist/esm/api/permission/extension.js +535 -0
  94. package/dist/esm/api/permission/index.js +294 -0
  95. package/dist/esm/api/permission/permission.js +294 -0
  96. package/dist/esm/api/plugin/extension.js +531 -0
  97. package/dist/esm/api/plugin/index.js +529 -0
  98. package/dist/esm/api/plugin/package-info.js +4 -0
  99. package/dist/esm/api/registry/extension.js +1286 -0
  100. package/dist/esm/api/registry/index.js +1285 -0
  101. package/dist/esm/api/registry/packets.js +694 -0
  102. package/dist/esm/api/registry/registry.js +383 -0
  103. package/dist/esm/api/server/extension.js +2140 -0
  104. package/dist/esm/api/server/index.js +2118 -0
  105. package/dist/esm/api/session/extension.js +2235 -0
  106. package/dist/esm/api/session/index.js +2235 -0
  107. package/dist/esm/api/signal/extension.js +1031 -0
  108. package/dist/esm/api/signal/index.js +379 -0
  109. package/dist/esm/api/signal/packets.js +690 -0
  110. package/dist/esm/api/signal/signal.js +379 -0
  111. package/dist/esm/api/table/extension.js +1553 -0
  112. package/dist/esm/api/table/index.js +1552 -0
  113. package/dist/esm/api/table/packets.js +904 -0
  114. package/dist/esm/api/table/table.js +383 -0
  115. package/dist/esm/app.js +264 -0
  116. package/dist/esm/const.js +11 -0
  117. package/dist/esm/errors.js +548 -0
  118. package/dist/esm/event/index.js +22 -0
  119. package/dist/esm/helper.js +15 -0
  120. package/dist/esm/identifier.js +266 -0
  121. package/dist/esm/index.js +5186 -0
  122. package/dist/esm/localization/index.js +742 -0
  123. package/dist/esm/localization/locale.js +742 -0
  124. package/dist/esm/localization/localization.js +4 -0
  125. package/dist/esm/lock.js +46 -0
  126. package/dist/esm/network/connection.js +293 -0
  127. package/dist/esm/network/encryption.js +986 -0
  128. package/dist/esm/network/frame-transport.js +531 -0
  129. package/dist/esm/network/index.js +1627 -0
  130. package/dist/esm/network/network.js +1368 -0
  131. package/dist/esm/network/packet/index.js +485 -0
  132. package/dist/esm/network/packet/packet-types.js +486 -0
  133. package/dist/esm/network/packet/packet.js +126 -0
  134. package/dist/esm/network/websocket-transport.js +493 -0
  135. package/dist/esm/omu.js +4945 -0
  136. package/dist/esm/result.js +68 -0
  137. package/dist/esm/serialize/bytebuffer.js +384 -0
  138. package/dist/esm/serialize/index.js +471 -0
  139. package/dist/esm/serialize/serializer.js +97 -0
  140. package/dist/esm/token.js +42 -0
  141. package/dist/esm/version.js +11 -0
  142. package/dist/tsconfig.tsbuildinfo +1 -0
  143. package/package.json +4 -1
  144. package/CHANGELOG.md +0 -1845
  145. package/src/api/asset/extension.ts +0 -193
  146. package/src/api/asset/index.ts +0 -5
  147. package/src/api/dashboard/extension.ts +0 -651
  148. package/src/api/dashboard/index.ts +0 -38
  149. package/src/api/dashboard/packets.ts +0 -126
  150. package/src/api/endpoint/endpoint.ts +0 -56
  151. package/src/api/endpoint/extension.ts +0 -133
  152. package/src/api/endpoint/packets.ts +0 -176
  153. package/src/api/extension-registry.ts +0 -17
  154. package/src/api/extension.ts +0 -19
  155. package/src/api/http/extension.ts +0 -401
  156. package/src/api/http/http.ts +0 -79
  157. package/src/api/http/websocket.ts +0 -283
  158. package/src/api/i18n/extension.ts +0 -65
  159. package/src/api/logger/extension.ts +0 -75
  160. package/src/api/logger/index.ts +0 -4
  161. package/src/api/logger/packets.ts +0 -38
  162. package/src/api/permission/extension.ts +0 -107
  163. package/src/api/permission/permission.ts +0 -53
  164. package/src/api/plugin/extension.ts +0 -100
  165. package/src/api/registry/extension.ts +0 -326
  166. package/src/api/registry/packets.ts +0 -64
  167. package/src/api/server/extension.ts +0 -155
  168. package/src/api/server/index.ts +0 -11
  169. package/src/api/session/extension.ts +0 -205
  170. package/src/api/session/index.ts +0 -7
  171. package/src/api/signal/extension.ts +0 -125
  172. package/src/api/signal/packets.ts +0 -61
  173. package/src/api/signal/signal.ts +0 -67
  174. package/src/api/table/extension.ts +0 -554
  175. package/src/api/table/packets.ts +0 -252
  176. package/src/api/table/table.ts +0 -113
  177. package/src/app.ts +0 -95
  178. package/src/const.ts +0 -2
  179. package/src/errors.ts +0 -70
  180. package/src/event/index.ts +0 -18
  181. package/src/helper.ts +0 -16
  182. package/src/identifier.ts +0 -256
  183. package/src/index.ts +0 -87
  184. package/src/localization/locale.ts +0 -737
  185. package/src/lock.ts +0 -43
  186. package/src/network/connection.ts +0 -45
  187. package/src/network/encryption.ts +0 -221
  188. package/src/network/frame-transport.ts +0 -186
  189. package/src/network/network.ts +0 -322
  190. package/src/network/packet/packet-types.ts +0 -164
  191. package/src/network/packet/packet.ts +0 -55
  192. package/src/network/websocket-transport.ts +0 -123
  193. package/src/omu.ts +0 -156
  194. package/src/result.ts +0 -78
  195. package/src/serialize/bytebuffer.ts +0 -432
  196. package/src/serialize/serializer.ts +0 -149
  197. package/src/token.ts +0 -39
  198. package/src/version.ts +0 -2
  199. package/tsconfig.json +0 -18
  200. /package/{src/address.ts → dist/dts/address.d.ts} +0 -0
  201. /package/{src/api/signal/index.ts → dist/dts/api/signal/index.d.ts} +0 -0
  202. /package/{src/serialize/index.ts → dist/dts/serialize/index.d.ts} +0 -0
@@ -1,252 +0,0 @@
1
- import { Identifier } from '../../identifier';
2
- import { ByteReader, ByteWriter, Flags } from '../../serialize';
3
-
4
- import type { TableConfig } from './table.js';
5
-
6
- export class TablePacket {
7
- constructor(public readonly id: Identifier) {}
8
-
9
- public static serialize(packet: TablePacket): Uint8Array {
10
- const writer = new ByteWriter();
11
- writer.writeString(packet.id.key());
12
- return writer.finish();
13
- }
14
-
15
- public static deserialize(data: Uint8Array): TablePacket {
16
- const reader = ByteReader.fromUint8Array(data);
17
- const id = Identifier.fromKey(reader.readString());
18
- return new TablePacket(id);
19
- }
20
- }
21
-
22
- export class TableItemsPacket {
23
- constructor(
24
- public readonly id: Identifier,
25
- public readonly items: Record<string, Uint8Array>,
26
- ) {}
27
-
28
- public static serialize(packet: TableItemsPacket): Uint8Array {
29
- const writer = new ByteWriter();
30
- writer.writeString(packet.id.key());
31
- writer.writeULEB128(Object.keys(packet.items).length);
32
- for (const [key, value] of Object.entries(packet.items)) {
33
- writer.writeString(key);
34
- writer.writeUint8Array(value);
35
- }
36
- return writer.finish();
37
- }
38
-
39
- public static deserialize(data: Uint8Array): TableItemsPacket {
40
- const reader = ByteReader.fromUint8Array(data);
41
- const id = Identifier.fromKey(reader.readString());
42
- const count = reader.readULEB128();
43
- const items: Record<string, Uint8Array> = {};
44
- for (let i = 0; i < count; i++) {
45
- const key = reader.readString();
46
- const value = reader.readUint8Array();
47
- items[key] = value;
48
- }
49
- return new TableItemsPacket(id, items);
50
- }
51
- }
52
-
53
- export class TableKeysPacket {
54
- constructor(
55
- public readonly id: Identifier,
56
- public readonly keys: string[],
57
- ) {}
58
-
59
- public static serialize(packet: TableKeysPacket): Uint8Array {
60
- const writer = new ByteWriter();
61
- writer.writeString(packet.id.key());
62
- writer.writeULEB128(packet.keys.length);
63
- for (const key of packet.keys) {
64
- writer.writeString(key);
65
- }
66
- return writer.finish();
67
- }
68
-
69
- public static deserialize(data: Uint8Array): TableKeysPacket {
70
- const reader = ByteReader.fromUint8Array(data);
71
- const id = Identifier.fromKey(reader.readString());
72
- const count = reader.readULEB128();
73
- const keys: string[] = [];
74
- for (let i = 0; i < count; i++) {
75
- keys.push(reader.readString());
76
- }
77
- return new TableKeysPacket(id, keys);
78
- }
79
- }
80
-
81
- export class TableProxyPacket {
82
- constructor(
83
- public readonly id: Identifier,
84
- public readonly items: Record<string, Uint8Array>,
85
- public readonly key: number,
86
- ) {}
87
-
88
- public static serialize(packet: TableProxyPacket): Uint8Array {
89
- const writer = new ByteWriter();
90
- writer.writeString(packet.id.key());
91
- writer.writeULEB128(packet.key);
92
- writer.writeULEB128(Object.keys(packet.items).length);
93
- for (const [key, value] of Object.entries(packet.items)) {
94
- writer.writeString(key);
95
- writer.writeUint8Array(value);
96
- }
97
- return writer.finish();
98
- }
99
-
100
- public static deserialize(data: Uint8Array): TableProxyPacket {
101
- const reader = ByteReader.fromUint8Array(data);
102
- const id = Identifier.fromKey(reader.readString());
103
- const key = reader.readULEB128();
104
- const count = reader.readULEB128();
105
- const items: Record<string, Uint8Array> = {};
106
- for (let i = 0; i < count; i++) {
107
- const key = reader.readString();
108
- const value = reader.readUint8Array();
109
- items[key] = value;
110
- }
111
- return new TableProxyPacket(id, items, key);
112
- }
113
- }
114
- export class TableFetchPacket {
115
- constructor(
116
- public readonly id: Identifier,
117
- public readonly limit: number,
118
- public readonly backward: boolean = false,
119
- public readonly cursor: string | null = null,
120
- ) {}
121
-
122
- public static serialize(packet: TableFetchPacket): Uint8Array {
123
- const writer = new ByteWriter();
124
- writer.writeString(packet.id.key());
125
- writer.writeULEB128(packet.limit);
126
- const flags = new Flags({ length: 2 });
127
- flags.set(0, packet.backward);
128
- flags.set(1, packet.cursor !== null);
129
- writer.writeFlags(flags);
130
- if (packet.cursor !== null) {
131
- writer.writeString(packet.cursor);
132
- }
133
- return writer.finish();
134
- }
135
-
136
- public static deserialize(data: Uint8Array): TableFetchPacket {
137
- const reader = ByteReader.fromUint8Array(data);
138
- const id = Identifier.fromKey(reader.readString());
139
- const limit = reader.readULEB128();
140
- const flags = reader.readFlags(2);
141
- const backward = flags.get(0);
142
- const cursor = flags.ifSet(1, () => reader.readString());
143
- return new TableFetchPacket(id, limit, backward, cursor);
144
- }
145
- }
146
-
147
- export class TableFetchRangePacket {
148
- constructor(
149
- public readonly id: Identifier,
150
- public readonly start: string,
151
- public readonly end: string,
152
- ) {}
153
-
154
- public static serialize(packet: TableFetchRangePacket): Uint8Array {
155
- const writer = new ByteWriter();
156
- writer.writeString(packet.id.key());
157
- writer.writeString(packet.start);
158
- writer.writeString(packet.end);
159
- return writer.finish();
160
- }
161
-
162
- public static deserialize(data: Uint8Array): TableFetchRangePacket {
163
- const reader = ByteReader.fromUint8Array(data);
164
- const id = Identifier.fromKey(reader.readString());
165
- const start = reader.readString();
166
- const end = reader.readString();
167
- return new TableFetchRangePacket(id, start, end);
168
- }
169
- }
170
-
171
- export class SetConfigPacket {
172
- constructor(
173
- public readonly id: Identifier,
174
- public readonly config: TableConfig,
175
- ) {}
176
-
177
- public static serialize(packet: SetConfigPacket): Uint8Array {
178
- const writer = new ByteWriter();
179
- writer.writeString(packet.id.key());
180
- writer.writeString(JSON.stringify(packet.config));
181
- return writer.finish();
182
- }
183
-
184
- public static deserialize(data: Uint8Array): SetConfigPacket {
185
- const reader = ByteReader.fromUint8Array(data);
186
- const id = Identifier.fromKey(reader.readString());
187
- const config = JSON.parse(reader.readString());
188
- return new SetConfigPacket(id, config);
189
- }
190
- }
191
-
192
- export class SetPermissionPacket {
193
- constructor(
194
- public readonly id: Identifier,
195
- public readonly all: Identifier | null,
196
- public readonly read: Identifier | null,
197
- public readonly write: Identifier | null,
198
- public readonly remove: Identifier | null,
199
- public readonly proxy: Identifier | null,
200
- ) {}
201
-
202
- public static serialize(packet: SetPermissionPacket): Uint8Array {
203
- const writer = new ByteWriter();
204
- writer.writeString(packet.id.key());
205
- let flags = 0;
206
- if (packet.all !== null) {
207
- flags |= 0b1;
208
- }
209
- if (packet.read !== null) {
210
- flags |= 0b10;
211
- }
212
- if (packet.write !== null) {
213
- flags |= 0b100;
214
- }
215
- if (packet.remove !== null) {
216
- flags |= 0b1000;
217
- }
218
- if (packet.proxy !== null) {
219
- flags |= 0b10000;
220
- }
221
- writer.writeUint8(flags);
222
- if (packet.all) {
223
- writer.writeString(packet.all.key());
224
- }
225
- if (packet.read) {
226
- writer.writeString(packet.read.key());
227
- }
228
- if (packet.write) {
229
- writer.writeString(packet.write.key());
230
- }
231
- if (packet.remove) {
232
- writer.writeString(packet.remove.key());
233
- }
234
- if (packet.proxy) {
235
- writer.writeString(packet.proxy.key());
236
- }
237
- return writer.finish();
238
- }
239
-
240
- public static deserialize(data: Uint8Array): SetPermissionPacket {
241
- const reader = ByteReader.fromUint8Array(data);
242
- const id = Identifier.fromKey(reader.readString());
243
- const flags = reader.readUint8();
244
- const all = flags & 0b1 ? Identifier.fromKey(reader.readString()) : null;
245
- const read = flags & 0b10 ? Identifier.fromKey(reader.readString()) : null;
246
- const write = flags & 0b100 ? Identifier.fromKey(reader.readString()) : null;
247
- const remove = flags & 0b1000 ? Identifier.fromKey(reader.readString()) : null;
248
- const proxy = flags & 0b10000 ? Identifier.fromKey(reader.readString()) : null;
249
- return new SetPermissionPacket(id, all, read, write, remove, proxy);
250
- }
251
- }
252
-
@@ -1,113 +0,0 @@
1
- import type { EventEmitter, Unlisten } from '../../event';
2
- import { Identifier, IntoId } from '../../identifier';
3
- import type { JsonType, Serializable } from '../../serialize';
4
- import { Serializer } from '../../serialize';
5
-
6
- export type TableConfig = {
7
- cache_size: number;
8
- };
9
-
10
- export interface Table<T> {
11
- readonly cache: ReadonlyMap<string, T>;
12
- readonly event: TableEvents<T>;
13
- get(key: string): Promise<T | undefined>;
14
- getMany(...keys: string[]): Promise<Map<string, T>>;
15
- add(...item: T[]): Promise<void>;
16
- update(...item: T[]): Promise<void>;
17
- remove(...items: T[]): Promise<void>;
18
- clear(): Promise<void>;
19
- has(key: string): Promise<boolean>;
20
- hasMany<T extends Record<string, unknown>>(...keys: (keyof T)[]): Promise<{ [key in keyof T]: boolean }>;
21
- hasAll(...keys: string[]): Promise<boolean>;
22
- hasAny(...keys: string[]): Promise<boolean>;
23
-
24
- fetchItems({
25
- limit,
26
- backward,
27
- cursor,
28
- }: {
29
- limit: number;
30
- backward?: boolean;
31
- cursor?: string;
32
- }): Promise<Map<string, T>>;
33
- fetchRange({ start, end }: { start: string; end: string }): Promise<Map<string, T>>;
34
- fetchAll(): Promise<Map<string, T>>;
35
- iterate({ backward, cursor }: { backward?: boolean; cursor?: string }): AsyncIterable<T>;
36
- size(): Promise<number>;
37
-
38
- proxy(proxy: (item: T) => T | undefined): Unlisten;
39
- setCacheSize(size: number): void;
40
- setConfig(config: TableConfig): void;
41
- setPermissions(permissions: TablePermissions): void;
42
-
43
- listen(listener?: (items: Map<string, T>) => void): Unlisten;
44
- }
45
-
46
- export type TableEvents<T> = {
47
- add: EventEmitter<[Map<string, T>]>;
48
- update: EventEmitter<[Map<string, T>]>;
49
- remove: EventEmitter<[Map<string, T>]>;
50
- clear: EventEmitter<[]>;
51
- cacheUpdate: EventEmitter<[Map<string, T>]>;
52
- };
53
-
54
- export type TablePermissions = {
55
- all?: Identifier;
56
- read?: Identifier;
57
- write?: Identifier;
58
- remove?: Identifier;
59
- proxy?: Identifier;
60
- };
61
-
62
- export class TableType<T> {
63
- constructor(
64
- public id: Identifier,
65
- public serializer: Serializable<T, Uint8Array>,
66
- public keyFunction: (item: T) => string,
67
- public permissions?: TablePermissions | undefined,
68
- ) {}
69
-
70
- public static createJson<T, D extends JsonType = JsonType>(
71
- identifier: IntoId,
72
- {
73
- name,
74
- key,
75
- permissions,
76
- serializer,
77
- }: {
78
- name: string;
79
- key: (item: T) => string;
80
- permissions?: TablePermissions;
81
- serializer?: Serializable<T, D>;
82
- },
83
- ): TableType<T> {
84
- return new TableType<T>(
85
- Identifier.from(identifier).join(name),
86
- Serializer.pipe<T, D, Uint8Array>(serializer ?? Serializer.noop(), Serializer.json()),
87
- key,
88
- permissions,
89
- );
90
- }
91
-
92
- public static createSerialized<T>(
93
- identifier: IntoId,
94
- {
95
- name,
96
- key,
97
- permissions,
98
- serializer,
99
- }: {
100
- name: string;
101
- key: (item: T) => string;
102
- permissions?: TablePermissions;
103
- serializer: Serializable<T, Uint8Array>;
104
- },
105
- ): TableType<T> {
106
- return new TableType<T>(
107
- Identifier.from(identifier).join(name),
108
- serializer,
109
- key,
110
- permissions,
111
- );
112
- }
113
- }
package/src/app.ts DELETED
@@ -1,95 +0,0 @@
1
- import { Identifier, IntoId } from './identifier';
2
- import type { Locale } from './localization/locale.js';
3
- import type { LocalizedText } from './localization/localization.js';
4
-
5
- export type AppMetadata = {
6
- locale: Locale;
7
- name?: LocalizedText;
8
- icon?: LocalizedText;
9
- description?: LocalizedText;
10
- image?: LocalizedText;
11
- site?: LocalizedText;
12
- repository?: LocalizedText;
13
- authors?: LocalizedText;
14
- license?: LocalizedText;
15
- tags?: string[];
16
- };
17
-
18
- export type AppType = 'app' | 'service' | 'remote' | 'plugin' | 'dashboard';
19
-
20
- export type DependencySpecifier = {
21
- version: string;
22
- index?: string;
23
- };
24
-
25
- export type AppJson = {
26
- id: string;
27
- type: AppType;
28
- parent_id?: string;
29
- version?: string;
30
- url?: string;
31
- metadata?: AppMetadata;
32
- dependencies?: Record<string, DependencySpecifier | string>;
33
- };
34
-
35
- export class App {
36
- public readonly id: Identifier;
37
- public readonly type: AppType;
38
- public readonly parentId?: Identifier;
39
- public readonly version?: string;
40
- public readonly url?: string;
41
- public readonly metadata?: AppMetadata;
42
- public readonly dependencies: Record<string, DependencySpecifier | string>;
43
-
44
- constructor(id: IntoId, options: {
45
- type?: AppType;
46
- parentId?: IntoId;
47
- version?: string;
48
- url?: string;
49
- metadata?: AppMetadata;
50
- dependencies?: Record<string, DependencySpecifier | string>;
51
- }) {
52
- this.id = Identifier.from(id);
53
- this.parentId = Identifier.fromOptional(options.parentId);
54
- this.version = options.version;
55
- this.url = options.url;
56
- this.metadata = options.metadata;
57
- this.type = options.type ?? 'app';
58
- this.dependencies = options.dependencies ?? {};
59
- }
60
-
61
- public static deserialize(info: AppJson): App {
62
- const id = Identifier.fromKey(info.id);
63
- return new App(id, {
64
- parentId: Identifier.fromOptional(info.parent_id),
65
- version: info.version,
66
- url: info.url,
67
- type: info.type,
68
- metadata: info.metadata,
69
- dependencies: info.dependencies ?? {},
70
- });
71
- }
72
-
73
- public static serialize(data: App): AppJson {
74
- return {
75
- id: data.id.key(),
76
- type: data.type,
77
- parent_id: data.parentId?.key(),
78
- version: data.version,
79
- url: data.url,
80
- metadata: data.metadata,
81
- dependencies: data.dependencies,
82
- };
83
- }
84
-
85
- public join(...paths: string[]): App {
86
- return new App(this.id.join(...paths), {
87
- parentId: this.parentId,
88
- version: this.version,
89
- url: this.url,
90
- type: this.type,
91
- metadata: this.metadata,
92
- dependencies: this.dependencies,
93
- });
94
- }
95
- }
package/src/const.ts DELETED
@@ -1,2 +0,0 @@
1
- export const textEncoder: TextEncoder = new TextEncoder();
2
- export const textDecoder: TextDecoder = new TextDecoder();
package/src/errors.ts DELETED
@@ -1,70 +0,0 @@
1
- import { DisconnectType } from './network/packet/packet-types.js';
2
- export class OmuError extends Error {
3
- constructor(message: string | null) {
4
- super(message ?? undefined);
5
- this.name = this.constructor.name;
6
- }
7
- }
8
-
9
- export class DisconnectReason extends OmuError {
10
- constructor(
11
- public type: DisconnectType,
12
- public message = '',
13
- ) {
14
- super(message);
15
- }
16
- }
17
-
18
- export class ServerRestart extends DisconnectReason {
19
- constructor(message: string) {
20
- super(DisconnectType.SERVER_RESTART, message);
21
- }
22
- }
23
-
24
- export class AnotherConnection extends DisconnectReason {
25
- constructor(message: string) {
26
- super(DisconnectType.ANOTHER_CONNECTION, message);
27
- }
28
- }
29
-
30
- export class PermissionDenied extends DisconnectReason {
31
- constructor(message: string) {
32
- super(DisconnectType.PERMISSION_DENIED, message);
33
- }
34
- }
35
-
36
- export class AppRemoved extends DisconnectReason {
37
- constructor(message: string) {
38
- super(DisconnectType.APP_REMOVED, message);
39
- }
40
- }
41
-
42
- export class InvalidToken extends DisconnectReason {
43
- constructor(message: string) {
44
- super(DisconnectType.INVALID_TOKEN, message);
45
- }
46
- }
47
-
48
- export class InvalidOrigin extends DisconnectReason {
49
- constructor(message: string) {
50
- super(DisconnectType.INVALID_ORIGIN, message);
51
- }
52
- }
53
-
54
- export class InvalidVersion extends DisconnectReason {
55
- constructor(message: string) {
56
- super(DisconnectType.INVALID_VERSION, message);
57
- }
58
- }
59
-
60
- export class InvalidPacket extends DisconnectReason {
61
- constructor(message: string) {
62
- super(DisconnectType.INVALID_PACKET, message);
63
- }
64
- }
65
-
66
- export class InternalError extends DisconnectReason {
67
- constructor(message: string) {
68
- super(DisconnectType.INTERNAL_ERROR, message);
69
- }
70
- }
@@ -1,18 +0,0 @@
1
- export type Unlisten = () => void;
2
-
3
- export class EventEmitter<P extends Array<any>> {
4
- private readonly listeners: Array<(...args: P) => Promise<void> | void> = [];
5
-
6
- public listen(listener: (...args: P) => any): Unlisten {
7
- this.listeners.push(listener);
8
- return () => {
9
- this.listeners.splice(this.listeners.indexOf(listener), 1);
10
- };
11
- }
12
-
13
- public async emit(...args: P): Promise<void> {
14
- for (const listener of [...this.listeners]) {
15
- await listener(...args);
16
- }
17
- }
18
- }
package/src/helper.ts DELETED
@@ -1,16 +0,0 @@
1
- type Ok<T> = {
2
- ok: true;
3
- data: T;
4
- };
5
- type Err<E> = {
6
- ok: false;
7
- data: E;
8
- };
9
-
10
- export function tryCatch<T, E = Error>(func: () => T): Ok<T> | Err<E> {
11
- try {
12
- return { ok: true, data: func() };
13
- } catch (e) {
14
- return { ok: false, data: e as E };
15
- }
16
- }