@xpgamesllc/ipcs-be 0.0.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/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # ipcs-be
2
+
3
+ A set of standardized types and functions for interacting with other Minecraft Bedrock Edition add-ons.
4
+
5
+ ## Contributing
6
+
7
+ Feel free to raise an issue or submit a pull request if you have any improvements or features to suggest.
8
+
9
+ ## License
10
+
11
+ This project is licensed under the GNU GPLv3 License.
@@ -0,0 +1,20 @@
1
+ declare function setVersion(v: number): void;
2
+ /**
3
+ * Send a script event, fragmenting JSON/text payload if needed. Optionally receive a response.
4
+ * @param channel - The script-event channel to send to.
5
+ * @param payload - The payload to send.
6
+ * @param opts - Optional encoding and message ID.
7
+ * @param callback - Optional callback to receive a response.
8
+ */
9
+ declare function send(channel: string, payload: any, opts?: {
10
+ encoding?: string;
11
+ id?: string;
12
+ }, callback?: (response: any) => void): void;
13
+ /**
14
+ * Subscribe to reassembled messages on a channel.
15
+ * @param channel - The script-event channel to subscribe to.
16
+ * @param cb - The callback to invoke when a message is received.
17
+ */
18
+ declare function on(channel: string, cb: (payload: any, respond?: (resp: any) => void) => void): void;
19
+
20
+ export { on, send, setVersion };
@@ -0,0 +1,20 @@
1
+ declare function setVersion(v: number): void;
2
+ /**
3
+ * Send a script event, fragmenting JSON/text payload if needed. Optionally receive a response.
4
+ * @param channel - The script-event channel to send to.
5
+ * @param payload - The payload to send.
6
+ * @param opts - Optional encoding and message ID.
7
+ * @param callback - Optional callback to receive a response.
8
+ */
9
+ declare function send(channel: string, payload: any, opts?: {
10
+ encoding?: string;
11
+ id?: string;
12
+ }, callback?: (response: any) => void): void;
13
+ /**
14
+ * Subscribe to reassembled messages on a channel.
15
+ * @param channel - The script-event channel to subscribe to.
16
+ * @param cb - The callback to invoke when a message is received.
17
+ */
18
+ declare function on(channel: string, cb: (payload: any, respond?: (resp: any) => void) => void): void;
19
+
20
+ export { on, send, setVersion };
package/dist/index.js ADDED
@@ -0,0 +1,572 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ on: () => on,
24
+ send: () => send,
25
+ setVersion: () => setVersion
26
+ });
27
+ module.exports = __toCommonJS(src_exports);
28
+ var import_server2 = require("@minecraft/server");
29
+
30
+ // src/v1/net.ts
31
+ var import_server = require("@minecraft/server");
32
+
33
+ // src/v1/encoding/encoding.ts
34
+ var MAX_CHUNK = 2047;
35
+ var SPEC_VERSION = 1;
36
+
37
+ // src/v1/envelope.ts
38
+ var RS = "";
39
+ var ETX = "";
40
+ function buildEnvelope(meta, enc, chunk) {
41
+ const metaPart = `${meta.version}|${meta.encoding}`;
42
+ return `${metaPart}${RS}${enc}${ETX}${chunk}`;
43
+ }
44
+ function getEnvelopeLength(meta) {
45
+ const metaPart = `${meta.version}|${meta.encoding}`;
46
+ return `${metaPart}${RS}${ETX}`.length;
47
+ }
48
+
49
+ // src/utils/uuid.ts
50
+ function makeUUID() {
51
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
52
+ const r = Math.random() * 16 | 0;
53
+ const v = c === "x" ? r : r & 3 | 8;
54
+ return v.toString(16);
55
+ });
56
+ }
57
+ function uuidToBytes(uuid) {
58
+ const hex = uuid.replace(/-/g, "");
59
+ if (hex.length !== 32) {
60
+ throw new Error(`Invalid UUID: expected 36 chars with hyphens, got "${uuid}"`);
61
+ }
62
+ const bytes = new Uint8Array(16);
63
+ for (let i = 0; i < 16; i++) {
64
+ bytes[i] = parseInt(hex.substr(i * 2, 2), 16);
65
+ }
66
+ return bytes;
67
+ }
68
+ function bytesToUuid(bytes) {
69
+ if (bytes.length !== 16) {
70
+ throw new Error(`Invalid byte array: expected length 16, got ${bytes.length}`);
71
+ }
72
+ const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
73
+ return hex.join("");
74
+ }
75
+
76
+ // src/v1/encoding/TextPacketEncoder.ts
77
+ var TextPacketEncoder = class {
78
+ encoding = "text";
79
+ encode(payload) {
80
+ return JSON.stringify(payload);
81
+ }
82
+ encodeHeader(header) {
83
+ const parts = [header.id];
84
+ if (header.frag !== void 0 && header.last !== void 0) {
85
+ parts.push(header.frag.toString(), (header.last ? 1 : 0).toString());
86
+ }
87
+ return parts.join("|");
88
+ }
89
+ decode(raw) {
90
+ try {
91
+ return JSON.parse(raw);
92
+ } catch {
93
+ return null;
94
+ }
95
+ }
96
+ decodeHeader(raw) {
97
+ const parts = raw.split("|");
98
+ const id = parts[0];
99
+ const header = { id };
100
+ if (parts.length === 3) {
101
+ const frag = parseInt(parts[1], 10);
102
+ const last = parseInt(parts[2], 10);
103
+ if (isNaN(frag) || isNaN(last))
104
+ return null;
105
+ header.frag = frag;
106
+ header.last = last === 1;
107
+ } else if (parts.length !== 1) {
108
+ return null;
109
+ }
110
+ return header;
111
+ }
112
+ };
113
+
114
+ // src/utils/base64.ts
115
+ var Base64 = class _Base64 {
116
+ static _alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
117
+ static _pad = "=";
118
+ /* UTF-8 encode/decode helpers for ES2023-only environments */
119
+ static utf8Encode(str) {
120
+ const bytes = [];
121
+ for (const ch of str) {
122
+ const cp = ch.codePointAt(0);
123
+ if (cp <= 127) {
124
+ bytes.push(cp);
125
+ } else if (cp <= 2047) {
126
+ bytes.push(192 | cp >> 6, 128 | cp & 63);
127
+ } else if (cp <= 65535) {
128
+ bytes.push(
129
+ 224 | cp >> 12,
130
+ 128 | cp >> 6 & 63,
131
+ 128 | cp & 63
132
+ );
133
+ } else {
134
+ bytes.push(
135
+ 240 | cp >> 18,
136
+ 128 | cp >> 12 & 63,
137
+ 128 | cp >> 6 & 63,
138
+ 128 | cp & 63
139
+ );
140
+ }
141
+ }
142
+ return new Uint8Array(bytes);
143
+ }
144
+ static utf8Decode(bytes) {
145
+ let str = "";
146
+ for (let i = 0; i < bytes.length; ) {
147
+ const b1 = bytes[i++];
148
+ if (b1 < 128) {
149
+ str += String.fromCodePoint(b1);
150
+ } else if (b1 < 224) {
151
+ const b2 = bytes[i++];
152
+ str += String.fromCodePoint((b1 & 31) << 6 | b2 & 63);
153
+ } else if (b1 < 240) {
154
+ const b2 = bytes[i++], b3 = bytes[i++];
155
+ str += String.fromCodePoint(
156
+ (b1 & 15) << 12 | (b2 & 63) << 6 | b3 & 63
157
+ );
158
+ } else {
159
+ const b2 = bytes[i++], b3 = bytes[i++], b4 = bytes[i++];
160
+ str += String.fromCodePoint(
161
+ (b1 & 7) << 18 | (b2 & 63) << 12 | (b3 & 63) << 6 | b4 & 63
162
+ );
163
+ }
164
+ }
165
+ return str;
166
+ }
167
+ /* ------------------------------------------------------------------ */
168
+ /* Low-level byte-wise codec */
169
+ /* ------------------------------------------------------------------ */
170
+ /** Encode raw bytes (Uint8Array) -> Base-64 text. */
171
+ static encodeBytes(bytes) {
172
+ let out = "";
173
+ let i = 0;
174
+ while (i < bytes.length) {
175
+ const b1 = bytes[i++] ?? NaN;
176
+ const b2 = bytes[i++] ?? NaN;
177
+ const b3 = bytes[i++] ?? NaN;
178
+ const enc1 = b1 >> 2;
179
+ const enc2 = (b1 & 3) << 4 | b2 >> 4;
180
+ const enc3 = isNaN(b2) ? 64 : (b2 & 15) << 2 | b3 >> 6;
181
+ const enc4 = isNaN(b3) ? 64 : b3 & 63;
182
+ out += _Base64._alphabet.charAt(enc1);
183
+ out += _Base64._alphabet.charAt(enc2);
184
+ out += enc3 === 64 ? _Base64._pad : _Base64._alphabet.charAt(enc3);
185
+ out += enc4 === 64 ? _Base64._pad : _Base64._alphabet.charAt(enc4);
186
+ }
187
+ return out;
188
+ }
189
+ /** Decode Base-64 text -> raw bytes (Uint8Array). */
190
+ static decodeToBytes(base64) {
191
+ base64 = base64.replace(/[^A-Za-z0-9+/=]/g, "");
192
+ const byteLen = base64.length / 4 * 3 - (base64.endsWith("==") ? 2 : base64.endsWith("=") ? 1 : 0);
193
+ const bytes = new Uint8Array(byteLen);
194
+ let byteIdx = 0, i = 0;
195
+ while (i < base64.length) {
196
+ const enc1 = _Base64._alphabet.indexOf(base64.charAt(i++));
197
+ const enc2 = _Base64._alphabet.indexOf(base64.charAt(i++));
198
+ const enc3 = _Base64._alphabet.indexOf(base64.charAt(i++));
199
+ const enc4 = _Base64._alphabet.indexOf(base64.charAt(i++));
200
+ const b1 = enc1 << 2 | enc2 >> 4;
201
+ const b2 = (enc2 & 15) << 4 | enc3 >> 2;
202
+ const b3 = (enc3 & 3) << 6 | enc4;
203
+ bytes[byteIdx++] = b1;
204
+ if (enc3 !== 64 && byteIdx < byteLen)
205
+ bytes[byteIdx++] = b2;
206
+ if (enc4 !== 64 && byteIdx < byteLen)
207
+ bytes[byteIdx++] = b3;
208
+ }
209
+ return bytes;
210
+ }
211
+ /* ------------------------------------------------------------------ */
212
+ /* Convenience wrappers for regular JS strings (UTF-8) */
213
+ /* ------------------------------------------------------------------ */
214
+ /** Encode a JS string to Base-64 using UTF-8. */
215
+ static encode(str) {
216
+ const bytes = _Base64.utf8Encode(str);
217
+ return _Base64.encodeBytes(bytes);
218
+ }
219
+ /** Decode Base-64 to a JS string using UTF-8. */
220
+ static decode(base64) {
221
+ const bytes = _Base64.decodeToBytes(base64);
222
+ return _Base64.utf8Decode(bytes);
223
+ }
224
+ /* ------------------------------------------------------------------ */
225
+ /* Helper factories */
226
+ /* ------------------------------------------------------------------ */
227
+ static createOutputStream() {
228
+ return new Base64OutputStream();
229
+ }
230
+ static createInputStream(encoded) {
231
+ return new Base64InputStream(encoded);
232
+ }
233
+ };
234
+ var Base64OutputStream = class {
235
+ _buf = [];
236
+ get length() {
237
+ return this._buf.length;
238
+ }
239
+ writeBytes(arr) {
240
+ for (let i = 0; i < arr.length; i++) {
241
+ this.writeByte(arr[i]);
242
+ }
243
+ }
244
+ /* ---------- range-checked primitives ---------- */
245
+ writeByte(v) {
246
+ if (!Number.isInteger(v) || v < 0 || v > 255)
247
+ throw new RangeError("byte 0-255");
248
+ this._buf.push(v);
249
+ }
250
+ writeShort(v) {
251
+ if (!Number.isInteger(v) || v < 0 || v > 65535)
252
+ throw new RangeError("short 0-65535");
253
+ this.writeByte(v >>> 8 & 255);
254
+ this.writeByte(v & 255);
255
+ }
256
+ writeInt(v) {
257
+ if (!Number.isInteger(v) || v < 0 || v > 4294967295)
258
+ throw new RangeError("int 0-4294967295");
259
+ this.writeByte(v >>> 24 & 255);
260
+ this.writeByte(v >>> 16 & 255);
261
+ this.writeByte(v >>> 8 & 255);
262
+ this.writeByte(v & 255);
263
+ }
264
+ /* ---------- IEEE-754 ---------- */
265
+ writeFloat(v) {
266
+ const dv = new DataView(new ArrayBuffer(4));
267
+ dv.setFloat32(0, v, false);
268
+ for (let i = 0; i < 4; i++)
269
+ this.writeByte(dv.getUint8(i));
270
+ }
271
+ writeDouble(v) {
272
+ const dv = new DataView(new ArrayBuffer(8));
273
+ dv.setFloat64(0, v, false);
274
+ for (let i = 0; i < 8; i++)
275
+ this.writeByte(dv.getUint8(i));
276
+ }
277
+ /* ---------- strings ---------- */
278
+ writeUTF(str) {
279
+ const bytes = Base64.utf8Encode(str);
280
+ this.writeShort(bytes.length);
281
+ for (const b of bytes)
282
+ this.writeByte(b);
283
+ }
284
+ /** Finalize & return Base-64. */
285
+ toString() {
286
+ return Base64.encodeBytes(Uint8Array.from(this._buf));
287
+ }
288
+ };
289
+ var Base64InputStream = class {
290
+ _bytes;
291
+ _pos = 0;
292
+ constructor(encoded) {
293
+ this._bytes = Base64.decodeToBytes(encoded);
294
+ }
295
+ _need(n) {
296
+ if (this._pos + n > this._bytes.length)
297
+ throw new RangeError("EOF");
298
+ }
299
+ readBytes(n) {
300
+ const arr = new Uint8Array(n);
301
+ for (let i = 0; i < n; i++) {
302
+ arr[i] = this.readByte();
303
+ }
304
+ return arr;
305
+ }
306
+ readByte() {
307
+ this._need(1);
308
+ return this._bytes[this._pos++];
309
+ }
310
+ readShort() {
311
+ return this.readByte() << 8 | this.readByte();
312
+ }
313
+ readInt() {
314
+ return this.readByte() << 24 | this.readByte() << 16 | this.readByte() << 8 | this.readByte();
315
+ }
316
+ readFloat() {
317
+ this._need(4);
318
+ const dv = new DataView(this._bytes.buffer, this._bytes.byteOffset + this._pos, 4);
319
+ const v = dv.getFloat32(0, false);
320
+ this._pos += 4;
321
+ return v;
322
+ }
323
+ readDouble() {
324
+ this._need(8);
325
+ const dv = new DataView(this._bytes.buffer, this._bytes.byteOffset + this._pos, 8);
326
+ const v = dv.getFloat64(0, false);
327
+ this._pos += 8;
328
+ return v;
329
+ }
330
+ readUTF() {
331
+ const len = this.readShort();
332
+ this._need(len);
333
+ const slice = this._bytes.subarray(this._pos, this._pos + len);
334
+ this._pos += len;
335
+ return Base64.utf8Decode(slice);
336
+ }
337
+ get remaining() {
338
+ return this._bytes.length - this._pos;
339
+ }
340
+ };
341
+
342
+ // src/v1/encoding/Base64PacketEncoder.ts
343
+ var Base64PacketEncoder = class {
344
+ // encoding name for Base64 transport
345
+ encoding = "b64";
346
+ encode(payload) {
347
+ const json = JSON.stringify(payload);
348
+ return Base64.encode(json);
349
+ }
350
+ encodeHeader(header) {
351
+ const { id, frag, last } = header;
352
+ const out = new Base64OutputStream();
353
+ out.writeBytes(uuidToBytes(id));
354
+ let flags = 0;
355
+ if (last !== void 0)
356
+ flags |= 1;
357
+ out.writeByte(flags);
358
+ if (flags & 1) {
359
+ out.writeShort(frag);
360
+ out.writeByte(last ? 1 : 0);
361
+ }
362
+ return out.toString();
363
+ }
364
+ decode(raw) {
365
+ try {
366
+ const json = Base64.decode(raw);
367
+ return JSON.parse(json);
368
+ } catch {
369
+ return null;
370
+ }
371
+ }
372
+ decodeHeader(raw) {
373
+ try {
374
+ const inp = new Base64InputStream(raw);
375
+ const bytes = inp.readBytes(16);
376
+ const id = bytesToUuid(bytes);
377
+ const flags = inp.readByte();
378
+ const header = { id };
379
+ if (flags & 1) {
380
+ header.frag = inp.readShort();
381
+ header.last = inp.readByte() === 1;
382
+ }
383
+ return header;
384
+ } catch {
385
+ return null;
386
+ }
387
+ }
388
+ };
389
+
390
+ // src/v1/net.ts
391
+ var Net = class _Net {
392
+ static listeners = /* @__PURE__ */ new Map();
393
+ static buffers = /* @__PURE__ */ new Map();
394
+ static encoders = /* @__PURE__ */ new Map();
395
+ static DefaultEncoding = "text";
396
+ /**
397
+ * Register a new encoder implementation by its unique name.
398
+ */
399
+ static registerEncoder(encoder) {
400
+ this.encoders.set(encoder.encoding, encoder);
401
+ }
402
+ /** fire a script event, fragmenting JSON/text payload if needed. Optionally receive a response. */
403
+ static send(channel, payload, opts, callback) {
404
+ const encodingName = opts?.encoding ?? _Net.DefaultEncoding;
405
+ const encoder = _Net.encoders.get(encodingName);
406
+ if (!encoder)
407
+ throw new Error(`Unknown encoder: ${encodingName}`);
408
+ const raw = encoder.encode(payload);
409
+ const id = (opts?.id ?? makeUUID()).replace(/-/g, "");
410
+ if (callback) {
411
+ const respChannel = `ipcs:${id}`;
412
+ const wrapper = (respPayload) => {
413
+ try {
414
+ callback(respPayload);
415
+ } finally {
416
+ _Net.off(respChannel, wrapper);
417
+ }
418
+ };
419
+ _Net.on(respChannel, wrapper);
420
+ }
421
+ const totalLen = raw.length;
422
+ const metaPart = `${SPEC_VERSION}|${encodingName}`;
423
+ let chunks = [];
424
+ const meta = { version: SPEC_VERSION, encoding: encodingName };
425
+ const metaLength = getEnvelopeLength(meta);
426
+ const noFragHdr = encoder.encodeHeader({ id });
427
+ const noFragHdrLen = noFragHdr.length;
428
+ const noFragOverhead = metaPart.length + RS.length + ETX.length + noFragHdrLen;
429
+ if (totalLen + noFragOverhead + metaLength <= MAX_CHUNK) {
430
+ chunks = [[noFragHdr, raw]];
431
+ } else {
432
+ let i = 0;
433
+ let remaining = totalLen;
434
+ let written = 0;
435
+ while (remaining > 0) {
436
+ const hdr = encoder.encodeHeader({ id, frag: i, last: 0 });
437
+ const hdrLen = hdr.length;
438
+ const chunkSize = Math.min(MAX_CHUNK - hdrLen - metaLength, remaining);
439
+ chunks.push([hdr, raw.slice(written, written + chunkSize)]);
440
+ remaining -= chunkSize;
441
+ written += chunkSize;
442
+ i++;
443
+ }
444
+ }
445
+ if (chunks.length === 1) {
446
+ const hdrString = chunks[0][0];
447
+ const envelope = buildEnvelope(meta, hdrString, chunks[0][1]);
448
+ import_server.system.sendScriptEvent(channel, envelope);
449
+ } else {
450
+ for (let i = 0; i < chunks.length; i++) {
451
+ const encHdr = { id, frag: i, last: i === chunks.length - 1 };
452
+ const hdrString = encHdr.last ? encoder.encodeHeader(encHdr) : chunks[i][0];
453
+ const envelope = buildEnvelope(meta, hdrString, chunks[i][1]);
454
+ import_server.system.sendScriptEvent(channel, envelope);
455
+ }
456
+ }
457
+ }
458
+ /** subscribe to reassembled messages on a channel */
459
+ static on(channel, cb) {
460
+ const arr = _Net.listeners.get(channel) ?? [];
461
+ arr.push(cb);
462
+ _Net.listeners.set(channel, arr);
463
+ }
464
+ /** unsubscribe a callback from a channel */
465
+ static off(channel, cb) {
466
+ const arr = this.listeners.get(channel);
467
+ if (!arr)
468
+ return;
469
+ const filtered = arr.filter((fn) => fn !== cb);
470
+ if (filtered.length)
471
+ this.listeners.set(channel, filtered);
472
+ else
473
+ this.listeners.delete(channel);
474
+ }
475
+ /** invoke all cbs registered on this channel, providing optional respond function */
476
+ static dispatch(channel, payload, id, encodingName) {
477
+ const arr = _Net.listeners.get(channel);
478
+ if (!arr)
479
+ return;
480
+ for (const cb of arr) {
481
+ try {
482
+ if (id && !channel.startsWith("ipcs:")) {
483
+ const respond = (responsePayload) => {
484
+ _Net.send(`ipcs:${id}`, responsePayload, { encoding: encodingName, id });
485
+ };
486
+ cb(payload, respond);
487
+ } else {
488
+ cb(payload);
489
+ }
490
+ } catch {
491
+ }
492
+ }
493
+ }
494
+ /** internal dispatcher: parse envelope, reassemble if needed, then fire user-cb */
495
+ static handleScriptEvent(channel, raw) {
496
+ const [metaPart, rest] = raw.split(RS, 2);
497
+ if (!rest)
498
+ return;
499
+ const [encPart, body] = rest.split(ETX, 2);
500
+ if (body === void 0)
501
+ return;
502
+ const [verStr, encodingName] = metaPart.split("|");
503
+ if (parseInt(verStr, 10) !== SPEC_VERSION)
504
+ return;
505
+ const encoder = _Net.encoders.get(encodingName);
506
+ if (!encoder)
507
+ return;
508
+ const header = encoder.decodeHeader(encPart);
509
+ if (!header)
510
+ return;
511
+ const { id, frag, last } = header;
512
+ if (frag === void 0 || last === void 0) {
513
+ const payload = encoder.decode(body);
514
+ if (payload !== null)
515
+ _Net.dispatch(channel, payload, id, encodingName);
516
+ return;
517
+ }
518
+ let buf = _Net.buffers.get(id);
519
+ if (!buf) {
520
+ buf = { parts: [] };
521
+ _Net.buffers.set(id, buf);
522
+ }
523
+ if (frag !== void 0 && buf.parts[frag] === void 0) {
524
+ buf.parts[frag] = {
525
+ body,
526
+ frag: header.frag,
527
+ last: header.last
528
+ };
529
+ if (header.last) {
530
+ buf.lastIndex = frag;
531
+ }
532
+ }
533
+ if (buf.lastIndex !== void 0 && buf.parts.length === buf.lastIndex + 1 && buf.parts.sort((a, b) => a.frag - b.frag)[buf.lastIndex].frag === buf.lastIndex) {
534
+ const full = buf.parts.map((p) => p.body).join("");
535
+ _Net.buffers.delete(id);
536
+ const payload = encoder.decode(full);
537
+ if (payload !== null)
538
+ _Net.dispatch(channel, payload, id, encodingName);
539
+ }
540
+ }
541
+ };
542
+ Net.registerEncoder(new TextPacketEncoder());
543
+ Net.registerEncoder(new Base64PacketEncoder());
544
+
545
+ // src/index.ts
546
+ var version = 1;
547
+ var MaxVersion = 1;
548
+ var MinVersion = 1;
549
+ function setVersion(v) {
550
+ if (version < MinVersion || version > MaxVersion) {
551
+ throw new Error(`IPCS-BE spec version ${version} is not supported`);
552
+ }
553
+ version = v;
554
+ }
555
+ function send(channel, payload, opts, callback) {
556
+ if (version === 1) {
557
+ Net.send(channel, payload, opts, callback);
558
+ }
559
+ }
560
+ function on(channel, cb) {
561
+ Net.on(channel, cb);
562
+ }
563
+ import_server2.system.afterEvents.scriptEventReceive.subscribe((evt) => {
564
+ Net.handleScriptEvent(evt.id, evt.message);
565
+ });
566
+ // Annotate the CommonJS export names for ESM import in node:
567
+ 0 && (module.exports = {
568
+ on,
569
+ send,
570
+ setVersion
571
+ });
572
+ //# sourceMappingURL=index.js.map