@ad-sdk/bgd 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.
Files changed (54) hide show
  1. package/allocators/buffer.d.ts +115 -0
  2. package/allocators/buffer.js +409 -0
  3. package/allocators/collection.d.ts +24 -0
  4. package/allocators/collection.js +91 -0
  5. package/allocators/index.d.ts +3 -0
  6. package/allocators/index.js +38 -0
  7. package/allocators/virtual-core.d.ts +13 -0
  8. package/allocators/virtual-core.js +24 -0
  9. package/const.d.ts +19 -0
  10. package/const.js +26 -0
  11. package/errors.d.ts +32 -0
  12. package/errors.js +57 -0
  13. package/graph/def.d.ts +17 -0
  14. package/graph/def.js +5 -0
  15. package/graph/nodes/index.d.ts +1 -0
  16. package/graph/nodes/index.js +16 -0
  17. package/graph/nodes/person.d.ts +48 -0
  18. package/graph/nodes/person.js +104 -0
  19. package/index.d.ts +5 -0
  20. package/index.js +60 -0
  21. package/lifecycle/debugger.d.ts +21 -0
  22. package/lifecycle/debugger.js +5 -0
  23. package/lifecycle/disposable.d.ts +25 -0
  24. package/lifecycle/disposable.js +66 -0
  25. package/lifecycle/either.d.ts +25 -0
  26. package/lifecycle/either.js +51 -0
  27. package/lifecycle/index.d.ts +2 -0
  28. package/lifecycle/index.js +18 -0
  29. package/mathlib/core.d.ts +17 -0
  30. package/mathlib/core.js +29 -0
  31. package/mathlib/index.d.ts +1 -0
  32. package/mathlib/index.js +16 -0
  33. package/package.json +17 -0
  34. package/sqlx/core.d.ts +11 -0
  35. package/sqlx/core.js +18 -0
  36. package/sqlx/database.d.ts +45 -0
  37. package/sqlx/database.js +25 -0
  38. package/sqlx/migrations.d.ts +21 -0
  39. package/sqlx/migrations.js +115 -0
  40. package/sqlx/postgres.d.ts +51 -0
  41. package/sqlx/postgres.js +174 -0
  42. package/sss/poly.d.ts +19 -0
  43. package/sss/poly.js +76 -0
  44. package/sss/strategy.d.ts +14 -0
  45. package/sss/strategy.js +72 -0
  46. package/structured/heap.d.ts +22 -0
  47. package/structured/heap.js +46 -0
  48. package/types.d.ts +17 -0
  49. package/util/index.d.ts +2 -0
  50. package/util/index.js +27 -0
  51. package/util/runtime.d.ts +14 -0
  52. package/util/runtime.js +78 -0
  53. package/util/validator.d.ts +21 -0
  54. package/util/validator.js +75 -0
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Copyright © 2026 Alerta Dino. All rights reserved.
3
+ *
4
+ * This code was released under the BSD 3-Clause License.
5
+ * See the "LICENSE" file under project root.
6
+ *
7
+ * @author (PUBLIC_ID) 1D-C2-9B-98-D6-C3-D6-AB
8
+ * @signphrase It was created on Earth by humans, although
9
+ * I can't define what a "human" is.
10
+ */
11
+ import { type ImplicitArrayBuffer, type WithImplicitCoercion } from "node:buffer";
12
+ import { IDebugString } from "../lifecycle/debugger";
13
+ import { IDisposable } from "../lifecycle/disposable";
14
+ /**
15
+ * Provides a scoped wrapper around Node `Buffer` with
16
+ * explicit zeroization and access checks.
17
+ */
18
+ export declare class MemoryBuffer<T extends ArrayBuffer | SharedArrayBuffer = ArrayBufferLike> implements IDisposable, IDebugString {
19
+ #private;
20
+ /**
21
+ * Allocates a new zero-filled `Buffer` in heap.
22
+ */
23
+ static alloc(sizeInBytes: number): MemoryBuffer<ArrayBuffer>;
24
+ /**
25
+ * Using `from()` method may allocate a oversized buffer.
26
+ *
27
+ * It also can share memory with an external resource when
28
+ * called with `ArrayBuffer` instance, invalidating disposal logic.
29
+ *
30
+ * @advice
31
+ * Prefer to use`alloc()` with specific needed memory size.
32
+ */
33
+ static from(string: WithImplicitCoercion<string>, encoding?: BufferEncoding): MemoryBuffer<ArrayBuffer>;
34
+ /**
35
+ * Using `from()` method may allocate a oversized buffer.
36
+ *
37
+ * It also can share memory with an external resource when
38
+ * called with `ArrayBuffer` instance, invalidating disposal logic.
39
+ *
40
+ * @advice
41
+ * Prefer to use`alloc()` with specific needed memory size.
42
+ */
43
+ static from(arrayOrString: WithImplicitCoercion<ArrayLike<number> | string>): MemoryBuffer<ArrayBuffer>;
44
+ /**
45
+ * Using `from()` method may allocate a oversized buffer.
46
+ *
47
+ * It also can share memory with an external resource when
48
+ * called with `ArrayBuffer` instance, invalidating disposal logic.
49
+ *
50
+ * @advice
51
+ * Prefer to use`alloc()` with specific needed memory size.
52
+ */
53
+ static from(array: WithImplicitCoercion<ArrayLike<number>>): MemoryBuffer<ArrayBuffer>;
54
+ static from<TArrayBuffer extends WithImplicitCoercion<ArrayBufferLike>>(arrayBuffer: TArrayBuffer, byteOffset?: number, length?: number): MemoryBuffer<ImplicitArrayBuffer<TArrayBuffer>>;
55
+ private constructor();
56
+ get byteLength(): number;
57
+ get byteOffset(): number;
58
+ get disposed(): boolean;
59
+ setByte(index: number, val: number): void;
60
+ getByte(index: number): number;
61
+ writeUint8(val: number, offset?: number): number;
62
+ writeInt8(val: number, offset?: number): number;
63
+ writeUint16(val: number, offset?: number, enc?: "BE" | "LE"): number;
64
+ writeInt16(val: number, offset?: number, enc?: "BE" | "LE"): number;
65
+ writeUint32(val: number, offset?: number, enc?: "BE" | "LE"): number;
66
+ writeInt32(val: number, offset?: number, enc?: "BE" | "LE"): number;
67
+ writeUint64(val: bigint, offset?: number, enc?: "BE" | "LE"): number;
68
+ writeInt64(val: bigint, offset?: number, enc?: "BE" | "LE"): number;
69
+ writeFloat(val: number, offset?: number, enc?: "BE" | "LE"): number;
70
+ writeDouble(val: number, offset?: number, enc?: "BE" | "LE"): number;
71
+ readUint8(offset?: number): number;
72
+ readInt8(offset?: number): number;
73
+ readUint16(offset?: number, enc?: "BE" | "LE"): number;
74
+ readInt16(offset?: number, enc?: "BE" | "LE"): number;
75
+ readUint32(offset?: number, enc?: "BE" | "LE"): number;
76
+ readInt32(offset?: number, enc?: "BE" | "LE"): number;
77
+ readUint64(offset?: number, enc?: "BE" | "LE"): bigint;
78
+ readInt64(offset?: number, enc?: "BE" | "LE"): bigint;
79
+ readFloat(offset?: number, enc?: "BE" | "LE"): number;
80
+ readDouble(offset?: number, enc?: "BE" | "LE"): number;
81
+ copy(target: Uint8Array | MemoryBuffer<ArrayBufferLike>, targetStart?: number, sourceStart?: number, sourceEnd?: number): number;
82
+ indexOf(value: string | number | Uint8Array | MemoryBuffer<ArrayBufferLike>, encoding: BufferEncoding): number;
83
+ indexOf(value: string | number | Uint8Array | MemoryBuffer<ArrayBufferLike>, byteOffset?: number, encoding?: BufferEncoding): number;
84
+ lastIndexOf(value: string | number | Uint8Array | MemoryBuffer<ArrayBufferLike>, encoding: BufferEncoding): number;
85
+ lastIndexOf(value: string | number | Uint8Array | MemoryBuffer<ArrayBufferLike>, byteOffset?: number, encoding?: BufferEncoding): number;
86
+ compare(target: Uint8Array | MemoryBuffer<ArrayBufferLike>, targetStart?: number, targetEnd?: number, sourceStart?: number, sourceEnd?: number): -1 | 0 | 1;
87
+ equals(other: Uint8Array | MemoryBuffer<ArrayBufferLike>): boolean;
88
+ reverse(): this;
89
+ toReversed(): MemoryBuffer<ArrayBuffer>;
90
+ subarray(start?: number, end?: number): MemoryBuffer<T>;
91
+ toString(enc?: BufferEncoding, start?: number, end?: number): string;
92
+ /**
93
+ * **ATTENTION:** If you use this function make sure that
94
+ * will not create an external reference of the buffer, or it'll
95
+ * invalidate the disposal logic resulting in a memory leak.
96
+ */
97
+ valueOf(secure?: true): Buffer;
98
+ /**
99
+ * **ATTENTION:** If you use this function make sure that
100
+ * will not create an external reference of the buffer, or it'll
101
+ * invalidate the disposal logic resulting in a memory leak.
102
+ */
103
+ valueOf(secure: false): Buffer | null;
104
+ /**
105
+ * Clear current buffer and free allocated memory.
106
+ *
107
+ * **ATTENTION:** It won't work if the `MemoryBuffer` was created
108
+ * from external memory. When you call `from()` with an `ArrayBuffer`
109
+ * instance, or something like this, the owner of memory reference is the
110
+ * external instance, so we can't dispose it.
111
+ */
112
+ dispose(): void;
113
+ $$debug(r?: true): string;
114
+ $$debug(r: false): void;
115
+ }
@@ -0,0 +1,409 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.MemoryBuffer = void 0;
7
+ var _util = require("../util");
8
+ var _errors = require("../errors");
9
+ function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); }
10
+ function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
11
+ function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
12
+ function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
13
+ function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
14
+ function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); } /**
15
+ * Copyright © 2026 Alerta Dino. All rights reserved.
16
+ *
17
+ * This code was released under the BSD 3-Clause License.
18
+ * See the "LICENSE" file under project root.
19
+ *
20
+ * @author (PUBLIC_ID) 1D-C2-9B-98-D6-C3-D6-AB
21
+ * @signphrase It was created on Earth by humans, although
22
+ * I can't define what a "human" is.
23
+ */
24
+ var _BufRef = /*#__PURE__*/new WeakMap();
25
+ var _MemoryBuffer_brand = /*#__PURE__*/new WeakSet();
26
+ /**
27
+ * Provides a scoped wrapper around Node `Buffer` with
28
+ * explicit zeroization and access checks.
29
+ */
30
+ class MemoryBuffer {
31
+ /**
32
+ * Allocates a new zero-filled `Buffer` in heap.
33
+ */
34
+ static alloc(sizeInBytes) {
35
+ return new MemoryBuffer(Buffer.alloc(sizeInBytes));
36
+ }
37
+
38
+ /**
39
+ * Using `from()` method may allocate a oversized buffer.
40
+ *
41
+ * It also can share memory with an external resource when
42
+ * called with `ArrayBuffer` instance, invalidating disposal logic.
43
+ *
44
+ * @advice
45
+ * Prefer to use`alloc()` with specific needed memory size.
46
+ */
47
+
48
+ /**
49
+ * Using `from()` method may allocate a oversized buffer.
50
+ *
51
+ * It also can share memory with an external resource when
52
+ * called with `ArrayBuffer` instance, invalidating disposal logic.
53
+ *
54
+ * @advice
55
+ * Prefer to use`alloc()` with specific needed memory size.
56
+ */
57
+
58
+ /**
59
+ * Using `from()` method may allocate a oversized buffer.
60
+ *
61
+ * It also can share memory with an external resource when
62
+ * called with `ArrayBuffer` instance, invalidating disposal logic.
63
+ *
64
+ * @advice
65
+ * Prefer to use`alloc()` with specific needed memory size.
66
+ */
67
+
68
+ static from(arg_0, arg_1, arg_2) {
69
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
+ return new MemoryBuffer(Buffer.from(arg_0, arg_1, arg_2));
71
+ }
72
+ constructor(buf) {
73
+ _classPrivateMethodInitSpec(this, _MemoryBuffer_brand);
74
+ _classPrivateFieldInitSpec(this, _BufRef, void 0);
75
+ if (!Buffer.isBuffer(buf)) {
76
+ throw new _errors.BGDException(`[MemoryBuffer] Cannot construct a memory buffer with given 'typeof ${typeof buf}'`, "ER_INVALID_ARGUMENT" // eslint-disable-line comma-dangle
77
+ );
78
+ }
79
+ (0, _util.assert)(buf.byteLength === buf.length, "[MemoryBuffer] bytes-per-element=1");
80
+ _classPrivateFieldSet(_BufRef, this, buf);
81
+ }
82
+ get byteLength() {
83
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
84
+ return _classPrivateFieldGet(_BufRef, this).byteLength;
85
+ }
86
+ get byteOffset() {
87
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
88
+ return _classPrivateFieldGet(_BufRef, this).byteOffset;
89
+ }
90
+ get disposed() {
91
+ return _classPrivateFieldGet(_BufRef, this) == null;
92
+ }
93
+ setByte(index, val) {
94
+ if (typeof index !== "number" || isNaN(index)) {
95
+ throw new _errors.BGDException("[MemoryBuffer] Array index must be a unsigned integer", "ER_INVALID_ARGUMENT" // eslint-disable-line comma-dangle
96
+ );
97
+ }
98
+ if (typeof val !== "number" || isNaN(val)) {
99
+ throw new _errors.BGDException("[MemoryBuffer] The value \"byte\" must be a integer number", "ER_INVALID_ARGUMENT" // eslint-disable-line comma-dangle
100
+ );
101
+ }
102
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
103
+ _classPrivateFieldGet(_BufRef, this)[index] = val;
104
+ }
105
+ getByte(index) {
106
+ if (typeof index !== "number" || isNaN(index)) {
107
+ throw new _errors.BGDException("[MemoryBuffer] Array index must be a unsigned integer", "ER_INVALID_ARGUMENT" // eslint-disable-line comma-dangle
108
+ );
109
+ }
110
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
111
+ return _classPrivateFieldGet(_BufRef, this)[index];
112
+ }
113
+
114
+ // WRITE
115
+ writeUint8(val, offset) {
116
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
117
+ return _classPrivateFieldGet(_BufRef, this).writeUInt8(val, offset);
118
+ }
119
+ writeInt8(val, offset) {
120
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
121
+ return _classPrivateFieldGet(_BufRef, this).writeInt8(val, offset);
122
+ }
123
+ writeUint16(val, offset, enc = "LE") {
124
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
125
+ if (enc !== "BE" && enc !== "LE") {
126
+ throw new _errors.BGDException(`[MemoryBuffer] Unknown byte encoding "${enc}", expecting little-endian (LE) or big-endian (BE)`, "ER_INVALID_ARGUMENT" // eslint-disable-line
127
+ );
128
+ }
129
+ return _classPrivateFieldGet(_BufRef, this)[`writeUInt16${enc}`](val, offset);
130
+ }
131
+ writeInt16(val, offset, enc = "LE") {
132
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
133
+ if (enc !== "BE" && enc !== "LE") {
134
+ throw new _errors.BGDException(`[MemoryBuffer] Unknown byte encoding "${enc}", expecting little-endian (LE) or big-endian (BE)`, "ER_INVALID_ARGUMENT" // eslint-disable-line
135
+ );
136
+ }
137
+ return _classPrivateFieldGet(_BufRef, this)[`writeInt16${enc}`](val, offset);
138
+ }
139
+ writeUint32(val, offset, enc = "LE") {
140
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
141
+ if (enc !== "BE" && enc !== "LE") {
142
+ throw new _errors.BGDException(`[MemoryBuffer] Unknown byte encoding "${enc}", expecting little-endian (LE) or big-endian (BE)`, "ER_INVALID_ARGUMENT" // eslint-disable-line
143
+ );
144
+ }
145
+ return _classPrivateFieldGet(_BufRef, this)[`writeUInt32${enc}`](val, offset);
146
+ }
147
+ writeInt32(val, offset, enc = "LE") {
148
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
149
+ if (enc !== "BE" && enc !== "LE") {
150
+ throw new _errors.BGDException(`[MemoryBuffer] Unknown byte encoding "${enc}", expecting little-endian (LE) or big-endian (BE)`, "ER_INVALID_ARGUMENT" // eslint-disable-line
151
+ );
152
+ }
153
+ return _classPrivateFieldGet(_BufRef, this)[`writeInt32${enc}`](val, offset);
154
+ }
155
+ writeUint64(val, offset, enc = "LE") {
156
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
157
+ if (enc !== "BE" && enc !== "LE") {
158
+ throw new _errors.BGDException(`[MemoryBuffer] Unknown byte encoding "${enc}", expecting little-endian (LE) or big-endian (BE)`, "ER_INVALID_ARGUMENT" // eslint-disable-line
159
+ );
160
+ }
161
+ return _classPrivateFieldGet(_BufRef, this)[`writeBigUInt64${enc}`](val, offset);
162
+ }
163
+ writeInt64(val, offset, enc = "LE") {
164
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
165
+ if (enc !== "BE" && enc !== "LE") {
166
+ throw new _errors.BGDException(`[MemoryBuffer] Unknown byte encoding "${enc}", expecting little-endian (LE) or big-endian (BE)`, "ER_INVALID_ARGUMENT" // eslint-disable-line
167
+ );
168
+ }
169
+ return _classPrivateFieldGet(_BufRef, this)[`writeBigInt64${enc}`](val, offset);
170
+ }
171
+ writeFloat(val, offset, enc = "LE") {
172
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
173
+ if (enc !== "BE" && enc !== "LE") {
174
+ throw new _errors.BGDException(`[MemoryBuffer] Unknown byte encoding "${enc}", expecting little-endian (LE) or big-endian (BE)`, "ER_INVALID_ARGUMENT" // eslint-disable-line
175
+ );
176
+ }
177
+ return _classPrivateFieldGet(_BufRef, this)[`writeFloat${enc}`](val, offset);
178
+ }
179
+ writeDouble(val, offset, enc = "LE") {
180
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
181
+ if (enc !== "BE" && enc !== "LE") {
182
+ throw new _errors.BGDException(`[MemoryBuffer] Unknown byte encoding "${enc}", expecting little-endian (LE) or big-endian (BE)`, "ER_INVALID_ARGUMENT" // eslint-disable-line
183
+ );
184
+ }
185
+ return _classPrivateFieldGet(_BufRef, this)[`writeDouble${enc}`](val, offset);
186
+ }
187
+ // END WRITE
188
+
189
+ // READ
190
+ readUint8(offset) {
191
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
192
+ return _classPrivateFieldGet(_BufRef, this).readUInt8(offset);
193
+ }
194
+ readInt8(offset) {
195
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
196
+ return _classPrivateFieldGet(_BufRef, this).readInt8(offset);
197
+ }
198
+ readUint16(offset, enc = "LE") {
199
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
200
+ if (enc !== "BE" && enc !== "LE") {
201
+ throw new _errors.BGDException(`[MemoryBuffer] Unknown byte encoding "${enc}", expecting little-endian (LE) or big-endian (BE)`, "ER_INVALID_ARGUMENT" // eslint-disable-line comma-dangle
202
+ );
203
+ }
204
+ return _classPrivateFieldGet(_BufRef, this)[`readUInt16${enc}`](offset);
205
+ }
206
+ readInt16(offset, enc = "LE") {
207
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
208
+ if (enc !== "BE" && enc !== "LE") {
209
+ throw new _errors.BGDException(`[MemoryBuffer] Unknown byte encoding "${enc}", expecting little-endian (LE) or big-endian (BE)`, "ER_INVALID_ARGUMENT" // eslint-disable-line comma-dangle
210
+ );
211
+ }
212
+ return _classPrivateFieldGet(_BufRef, this)[`readInt16${enc}`](offset);
213
+ }
214
+ readUint32(offset, enc = "LE") {
215
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
216
+ if (enc !== "BE" && enc !== "LE") {
217
+ throw new _errors.BGDException(`[MemoryBuffer] Unknown byte encoding "${enc}", expecting little-endian (LE) or big-endian (BE)`, "ER_INVALID_ARGUMENT" // eslint-disable-line comma-dangle
218
+ );
219
+ }
220
+ return _classPrivateFieldGet(_BufRef, this)[`readUInt32${enc}`](offset);
221
+ }
222
+ readInt32(offset, enc = "LE") {
223
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
224
+ if (enc !== "BE" && enc !== "LE") {
225
+ throw new _errors.BGDException(`[MemoryBuffer] Unknown byte encoding "${enc}", expecting little-endian (LE) or big-endian (BE)`, "ER_INVALID_ARGUMENT" // eslint-disable-line comma-dangle
226
+ );
227
+ }
228
+ return _classPrivateFieldGet(_BufRef, this)[`readInt32${enc}`](offset);
229
+ }
230
+ readUint64(offset, enc = "LE") {
231
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
232
+ if (enc !== "BE" && enc !== "LE") {
233
+ throw new _errors.BGDException(`[MemoryBuffer] Unknown byte encoding "${enc}", expecting little-endian (LE) or big-endian (BE)`, "ER_INVALID_ARGUMENT" // eslint-disable-line comma-dangle
234
+ );
235
+ }
236
+ return _classPrivateFieldGet(_BufRef, this)[`readBigUInt64${enc}`](offset);
237
+ }
238
+ readInt64(offset, enc = "LE") {
239
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
240
+ if (enc !== "BE" && enc !== "LE") {
241
+ throw new _errors.BGDException(`[MemoryBuffer] Unknown byte encoding "${enc}", expecting little-endian (LE) or big-endian (BE)`, "ER_INVALID_ARGUMENT" // eslint-disable-line comma-dangle
242
+ );
243
+ }
244
+ return _classPrivateFieldGet(_BufRef, this)[`readBigInt64${enc}`](offset);
245
+ }
246
+ readFloat(offset, enc = "LE") {
247
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
248
+ if (enc !== "BE" && enc !== "LE") {
249
+ throw new _errors.BGDException(`[MemoryBuffer] Unknown byte encoding "${enc}", expecting little-endian (LE) or big-endian (BE)`, "ER_INVALID_ARGUMENT" // eslint-disable-line comma-dangle
250
+ );
251
+ }
252
+ return _classPrivateFieldGet(_BufRef, this)[`readFloat${enc}`](offset);
253
+ }
254
+ readDouble(offset, enc = "LE") {
255
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
256
+ if (enc !== "BE" && enc !== "LE") {
257
+ throw new _errors.BGDException(`[MemoryBuffer] Unknown byte encoding "${enc}", expecting little-endian (LE) or big-endian (BE)`, "ER_INVALID_ARGUMENT" // eslint-disable-line comma-dangle
258
+ );
259
+ }
260
+ return _classPrivateFieldGet(_BufRef, this)[`readDouble${enc}`](offset);
261
+ }
262
+ // END READ
263
+
264
+ copy(target, targetStart, sourceStart, sourceEnd) {
265
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
266
+ if (target instanceof MemoryBuffer && _classPrivateFieldGet(_BufRef, target) == null) {
267
+ throw new _errors.BGDException("[MemoryBuffer] Access to target buffer is not allowed because it's already disposed", "ER_RESOURCE_DISPOSED" // eslint-disable-line comma-dangle
268
+ );
269
+ }
270
+ return _classPrivateFieldGet(_BufRef, this).copy(target instanceof MemoryBuffer ? _classPrivateFieldGet(_BufRef, target) : target, targetStart, sourceStart, sourceEnd // eslint-disable-line comma-dangle
271
+ );
272
+ }
273
+ indexOf(value, byteOffsetOrEnc, encoding) {
274
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
275
+ if (value instanceof MemoryBuffer && _classPrivateFieldGet(_BufRef, value) == null) {
276
+ throw new _errors.BGDException("[MemoryBuffer] Access to target buffer is not allowed because it's already disposed", "ER_RESOURCE_DISPOSED" // eslint-disable-line comma-dangle
277
+ );
278
+ }
279
+ if (!!byteOffsetOrEnc && typeof byteOffsetOrEnc !== "number" && !Buffer.isBuffer(byteOffsetOrEnc)) {
280
+ throw new _errors.BGDException(`[MemoryBuffer] Unknown element byte-offset (as \`${byteOffsetOrEnc}\`)`, "ER_INVALID_ARGUMENT" // eslint-disable-line comma-dangle
281
+ );
282
+ }
283
+ return _classPrivateFieldGet(_BufRef, this).indexOf(value instanceof MemoryBuffer ? _classPrivateFieldGet(_BufRef, value) : value, byteOffsetOrEnc, encoding // eslint-disable-line comma-dangle
284
+ );
285
+ }
286
+ lastIndexOf(value, byteOffsetOrEnc, encoding) {
287
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
288
+ if (value instanceof MemoryBuffer && _classPrivateFieldGet(_BufRef, value) == null) {
289
+ throw new _errors.BGDException("[MemoryBuffer] Access to target buffer is not allowed because it's already disposed", "ER_RESOURCE_DISPOSED" // eslint-disable-line comma-dangle
290
+ );
291
+ }
292
+ if (!!byteOffsetOrEnc && typeof byteOffsetOrEnc !== "number" && !Buffer.isBuffer(byteOffsetOrEnc)) {
293
+ throw new _errors.BGDException(`[MemoryBuffer] Unknown element byte-offset (as \`${byteOffsetOrEnc}\`)`, "ER_INVALID_ARGUMENT" // eslint-disable-line comma-dangle
294
+ );
295
+ }
296
+ return _classPrivateFieldGet(_BufRef, this).lastIndexOf(value instanceof MemoryBuffer ? _classPrivateFieldGet(_BufRef, value) : value, byteOffsetOrEnc, encoding // eslint-disable-line comma-dangle
297
+ );
298
+ }
299
+ compare(target, targetStart, targetEnd, sourceStart, sourceEnd) {
300
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
301
+ if (target instanceof MemoryBuffer && _classPrivateFieldGet(_BufRef, target) == null) {
302
+ throw new _errors.BGDException("[MemoryBuffer] Access to target buffer is not allowed because it's already disposed", "ER_RESOURCE_DISPOSED" // eslint-disable-line comma-dangle
303
+ );
304
+ }
305
+ return _classPrivateFieldGet(_BufRef, this).compare(target instanceof MemoryBuffer ? _classPrivateFieldGet(_BufRef, target) : target, targetStart, targetEnd, sourceStart, sourceEnd // eslint-disable-line comma-dangle
306
+ );
307
+ }
308
+ equals(other) {
309
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
310
+ if (other instanceof MemoryBuffer && _classPrivateFieldGet(_BufRef, other) == null) {
311
+ throw new _errors.BGDException("[MemoryBuffer] Access to target buffer is not allowed because it's already disposed", "ER_RESOURCE_DISPOSED" // eslint-disable-line comma-dangle
312
+ );
313
+ }
314
+ return _classPrivateFieldGet(_BufRef, this).equals(other instanceof MemoryBuffer ? _classPrivateFieldGet(_BufRef, other) : other);
315
+ }
316
+ reverse() {
317
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
318
+ _classPrivateFieldGet(_BufRef, this).reverse();
319
+ return this;
320
+ }
321
+ toReversed() {
322
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
323
+ let buf = _classPrivateFieldGet(_BufRef, this).toReversed();
324
+ const res = MemoryBuffer.alloc(buf.byteLength);
325
+ for (let i = 0; i < buf.length; ++i) {
326
+ res.setByte(i, buf[i]);
327
+ }
328
+ buf.fill(0);
329
+ buf = null;
330
+ return res;
331
+ }
332
+ subarray(start, end) {
333
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
334
+ return new MemoryBuffer(_classPrivateFieldGet(_BufRef, this).subarray(start, end));
335
+ }
336
+ toString(enc, start, end) {
337
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
338
+ return _classPrivateFieldGet(_BufRef, this).toString(enc, start, end);
339
+ }
340
+
341
+ /**
342
+ * **ATTENTION:** If you use this function make sure that
343
+ * will not create an external reference of the buffer, or it'll
344
+ * invalidate the disposal logic resulting in a memory leak.
345
+ */
346
+
347
+ /**
348
+ * **ATTENTION:** If you use this function make sure that
349
+ * will not create an external reference of the buffer, or it'll
350
+ * invalidate the disposal logic resulting in a memory leak.
351
+ */
352
+
353
+ valueOf(secure) {
354
+ if (_classPrivateFieldGet(_BufRef, this) == null) {
355
+ if (secure !== false) {
356
+ _assertClassBrand(_MemoryBuffer_brand, this, _CheckDisposed).call(this);
357
+ }
358
+ return null;
359
+ }
360
+ return _classPrivateFieldGet(_BufRef, this);
361
+ }
362
+
363
+ /**
364
+ * Clear current buffer and free allocated memory.
365
+ *
366
+ * **ATTENTION:** It won't work if the `MemoryBuffer` was created
367
+ * from external memory. When you call `from()` with an `ArrayBuffer`
368
+ * instance, or something like this, the owner of memory reference is the
369
+ * external instance, so we can't dispose it.
370
+ */
371
+ dispose() {
372
+ if (_classPrivateFieldGet(_BufRef, this) != null) {
373
+ _classPrivateFieldGet(_BufRef, this).fill(0);
374
+ _classPrivateFieldSet(_BufRef, this, null);
375
+ }
376
+ }
377
+ $$debug(r) {
378
+ let msg = "";
379
+ if (_classPrivateFieldGet(_BufRef, this) == null) {
380
+ msg = "Buffer (__disposed__)";
381
+ } else {
382
+ msg = `Buffer (${_classPrivateFieldGet(_BufRef, this)?.byteLength}) `;
383
+ msg += `[ims=0xFF arraybuffer_size=${_classPrivateFieldGet(_BufRef, this).buffer.byteLength}]`;
384
+ if (_classPrivateFieldGet(_BufRef, this).byteLength >= 4) {
385
+ const left = [_classPrivateFieldGet(_BufRef, this)[0].toString(16), _classPrivateFieldGet(_BufRef, this)[1].toString(16)];
386
+ const right = [_classPrivateFieldGet(_BufRef, this).at(-2)?.toString(16), _classPrivateFieldGet(_BufRef, this).at(-1)?.toString(16)];
387
+ let moreInfo = "";
388
+ if (_classPrivateFieldGet(_BufRef, this).byteLength > 4) {
389
+ moreInfo = `... more ${_classPrivateFieldGet(_BufRef, this).byteLength - 4} bytes ... `;
390
+ }
391
+ msg += ` { ${left.map(i => `0x${i}`.toUpperCase()).join(", ")} ${moreInfo}${right.map(i => `0x${i}`.toUpperCase()).join(", ")} }`;
392
+ } else {
393
+ msg += ` { ${Array.from(_classPrivateFieldGet(_BufRef, this)).map(i => `0x${i.toString(16).toUpperCase()}`).join(", ")} }`;
394
+ }
395
+ }
396
+ if (r === false) {
397
+ console.log(msg);
398
+ return;
399
+ }
400
+ return msg;
401
+ }
402
+ }
403
+ exports.MemoryBuffer = MemoryBuffer;
404
+ function _CheckDisposed() {
405
+ if (_classPrivateFieldGet(_BufRef, this) == null) {
406
+ throw new _errors.BGDException("[MemoryBuffer] Trying to access a slice of memory that has already disposed", "ER_RESOURCE_DISPOSED" // eslint-disable-line comma-dangle
407
+ );
408
+ }
409
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Copyright © 2026 Alerta Dino. All rights reserved.
3
+ *
4
+ * This code was released under the BSD 3-Clause License.
5
+ * See the "LICENSE" file under project root.
6
+ *
7
+ * @author (PUBLIC_ID) 1D-C2-9B-98-D6-C3-D6-AB
8
+ * @signphrase It was created on Earth by humans, although
9
+ * I can't define what a "human" is.
10
+ */
11
+ import { MemoryBuffer } from "./buffer";
12
+ import { BGDException } from "../errors";
13
+ import { Disposable } from "../lifecycle/disposable";
14
+ import { type Either } from "../lifecycle/either";
15
+ export declare class CollectionAllocator extends Disposable {
16
+ #private;
17
+ constructor(maxSize?: number);
18
+ get byteLength(): number;
19
+ get maxBytes(): number;
20
+ get freeBytes(): number;
21
+ alloc(size: number): Either<BGDException, MemoryBuffer>;
22
+ free(buf: MemoryBuffer): boolean;
23
+ dispose(): void;
24
+ }
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CollectionAllocator = void 0;
7
+ var _util = require("../util");
8
+ var _buffer = require("./buffer");
9
+ var _errors = require("../errors");
10
+ var _disposable = require("../lifecycle/disposable");
11
+ var _either = require("../lifecycle/either");
12
+ function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
13
+ function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
14
+ function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
15
+ function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
16
+ function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); } /**
17
+ * Copyright © 2026 Alerta Dino. All rights reserved.
18
+ *
19
+ * This code was released under the BSD 3-Clause License.
20
+ * See the "LICENSE" file under project root.
21
+ *
22
+ * @author (PUBLIC_ID) 1D-C2-9B-98-D6-C3-D6-AB
23
+ * @signphrase It was created on Earth by humans, although
24
+ * I can't define what a "human" is.
25
+ */
26
+ var _Size = /*#__PURE__*/new WeakMap();
27
+ var _MaxBytes = /*#__PURE__*/new WeakMap();
28
+ var _Disposed = /*#__PURE__*/new WeakMap();
29
+ class CollectionAllocator extends _disposable.Disposable {
30
+ constructor(maxSize) {
31
+ if (typeof maxSize !== "undefined" && maxSize != null) {
32
+ (0, _util.assertType)("uint32", maxSize, "[CollectionAllocator] Max size must be a 32-bits unsigned integer");
33
+ }
34
+ super();
35
+ _classPrivateFieldInitSpec(this, _Size, void 0);
36
+ _classPrivateFieldInitSpec(this, _MaxBytes, void 0);
37
+ _classPrivateFieldInitSpec(this, _Disposed, void 0);
38
+ _classPrivateFieldSet(_Size, this, 0);
39
+ _classPrivateFieldSet(_MaxBytes, this, maxSize ?? -1);
40
+ _classPrivateFieldSet(_Disposed, this, false);
41
+ }
42
+ get byteLength() {
43
+ return _classPrivateFieldGet(_Size, this);
44
+ }
45
+ get maxBytes() {
46
+ return _classPrivateFieldGet(_MaxBytes, this);
47
+ }
48
+ get freeBytes() {
49
+ return _classPrivateFieldGet(_MaxBytes, this) - _classPrivateFieldGet(_Size, this);
50
+ }
51
+ alloc(size) {
52
+ if (_classPrivateFieldGet(_Disposed, this)) {
53
+ const err = new _errors.BGDException("[CollectionAllocator] The collection has already been disposed", "ER_RESOURCE_DISPOSED" // eslint-disable-line comma-dangle
54
+ );
55
+ return (0, _either.left)(err);
56
+ }
57
+ if (size + _classPrivateFieldGet(_Size, this) > _classPrivateFieldGet(_MaxBytes, this)) {
58
+ const err = new _errors.BGDException(`[CollectionAllocator] There's not enough space to alloc ${size} bytes`, "ER_BUFFER_OVERFLOW" // eslint-disable-line comma-dangle
59
+ );
60
+ return (0, _either.left)(err);
61
+ }
62
+ try {
63
+ const buf = _buffer.MemoryBuffer.alloc(size);
64
+ _classPrivateFieldSet(_Size, this, _classPrivateFieldGet(_Size, this) + buf.byteLength);
65
+ return (0, _either.right)(super._register(buf));
66
+ } catch (err) {
67
+ let e = err;
68
+ if (!(err instanceof _errors.BGDException)) {
69
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
+ e = new _errors.BGDException(`[CollectionAllocator] Failed to allocate buffer due to: ${err?.message || String(err) || "Unknown error"}`);
71
+ }
72
+ return (0, _either.left)(e);
73
+ }
74
+ }
75
+ free(buf) {
76
+ const size = buf.byteLength;
77
+
78
+ /** _delete() removes the object reference and call dispose() from it */
79
+ const r = super._delete(buf);
80
+ if (r) {
81
+ _classPrivateFieldSet(_Size, this, _classPrivateFieldGet(_Size, this) - size);
82
+ }
83
+ return r;
84
+ }
85
+ dispose() {
86
+ super.dispose();
87
+ _classPrivateFieldSet(_Size, this, 0);
88
+ _classPrivateFieldSet(_Disposed, this, true);
89
+ }
90
+ }
91
+ exports.CollectionAllocator = CollectionAllocator;
@@ -0,0 +1,3 @@
1
+ export * from "./buffer";
2
+ export * from "./collection";
3
+ export * from "./virtual-core";