@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,14 @@
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 { BufferLike } from "../types";
12
+ import { MemoryBuffer } from "../allocators";
13
+ export declare const SALT_LEN = 76;
14
+ export declare function deriveKey(imk: BufferLike, rkl?: number): Promise<readonly [MemoryBuffer, MemoryBuffer, MemoryBuffer]>;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SALT_LEN = void 0;
7
+ exports.deriveKey = deriveKey;
8
+ var _nodeCrypto = require("node:crypto");
9
+ var _util = require("../util");
10
+ var _allocators = require("../allocators");
11
+ /**
12
+ * Copyright © 2026 Alerta Dino. All rights reserved.
13
+ *
14
+ * This code was released under the BSD 3-Clause License.
15
+ * See the "LICENSE" file under project root.
16
+ *
17
+ * @author (PUBLIC_ID) 1D-C2-9B-98-D6-C3-D6-AB
18
+ * @signphrase It was created on Earth by humans, although
19
+ * I can't define what a "human" is.
20
+ */
21
+
22
+ // Input (plain text) -> f(n, k) -> [n slices of cipher text]
23
+ // Input (cipher_slice[n]) -> f(n >= k) -> [plain text]
24
+
25
+ // WHERE:
26
+
27
+ // `f()` is the secret redactor/unwrapper function
28
+ // `n` is the number of input/output slices
29
+ // `k` is the minimun required slices to recover original payload
30
+
31
+ const SALT_LEN = exports.SALT_LEN = 0x4C;
32
+ async function deriveKey(imk, rkl = 32 // eslint-disable-line comma-dangle
33
+ ) {
34
+ const data = (0, _util.toBuffer)(imk);
35
+ try {
36
+ return await Promise.all([new Promise((resolve, reject) => {
37
+ (0, _nodeCrypto.randomBytes)(SALT_LEN, (err, buf) => {
38
+ if (!err) {
39
+ const out = _allocators.MemoryBuffer.alloc(buf.length);
40
+ for (let i = 0; i < buf.length; ++i) {
41
+ out.setByte(i, buf[i]);
42
+ }
43
+ buf.fill(0);
44
+ buf = null;
45
+ resolve(out);
46
+ } else {
47
+ reject(err);
48
+ }
49
+ });
50
+ }), new Promise((resolve, reject) => {
51
+ (0, _nodeCrypto.hkdf)("sha512", data.valueOf(), Buffer.alloc(0), "::DBGD_K_SSS.HEAD::", rkl, (err, ab) => {
52
+ if (!err) {
53
+ resolve((0, _util.toBuffer)(ab));
54
+ } else {
55
+ reject(err);
56
+ }
57
+ } // eslint-disable-line comma-dangle
58
+ );
59
+ }), new Promise((resolve, reject) => {
60
+ (0, _nodeCrypto.hkdf)("sha512", data.valueOf(), Buffer.alloc(0), "::DBGD_K_SSS.PAYLOAD::", rkl, (err, ab) => {
61
+ if (!err) {
62
+ resolve((0, _util.toBuffer)(ab));
63
+ } else {
64
+ reject(err);
65
+ }
66
+ } // eslint-disable-line comma-dangle
67
+ );
68
+ })]);
69
+ } finally {
70
+ data.dispose();
71
+ }
72
+ }
@@ -0,0 +1,22 @@
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
+ export type Comparator<T> = (a: T, b: T) => number;
12
+ export type IsEqual<T> = (s: T, o: T) => boolean;
13
+ export declare abstract class Heap<T> {
14
+ abstract readonly comparator: Comparator<T>;
15
+ abstract readonly capacity: number;
16
+ abstract push(item: T): void;
17
+ static getChildrenIndexOf(index: number): readonly [number, number];
18
+ static getParentIndexOf(index: number): number;
19
+ static getSiblingIndexOf(index: number): number;
20
+ static minComparator<N>(a: N, b: N): number;
21
+ static maxComparator<N>(a: N, b: N): number;
22
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Heap = void 0;
7
+ /**
8
+ * Copyright © 2026 Alerta Dino. All rights reserved.
9
+ *
10
+ * This code was released under the BSD 3-Clause License.
11
+ * See the "LICENSE" file under project root.
12
+ *
13
+ * @author (PUBLIC_ID) 1D-C2-9B-98-D6-C3-D6-AB
14
+ * @signphrase It was created on Earth by humans, although
15
+ * I can't define what a "human" is.
16
+ */
17
+
18
+ // import { assertType } from "../util";
19
+
20
+ class Heap {
21
+ // ABSTRACT INSTANCE METHODS
22
+
23
+ // STATIC METHODS
24
+
25
+ static getChildrenIndexOf(index) {
26
+ return [index * 2 + 1, index * 2 + 2];
27
+ }
28
+ static getParentIndexOf(index) {
29
+ return index > 0 ? index - 1 >> 1 : -1;
30
+ }
31
+ static getSiblingIndexOf(index) {
32
+ if (index <= 0) return -1;
33
+ return index + (index % 2 ? 1 : -1);
34
+ }
35
+ static minComparator(a, b) {
36
+ if (a > b) return 1;
37
+ if (a < b) return -1;
38
+ return 0;
39
+ }
40
+ static maxComparator(a, b) {
41
+ if (b > a) return 1;
42
+ if (b < a) return -1;
43
+ return 0;
44
+ }
45
+ }
46
+ exports.Heap = Heap;
package/types.d.ts ADDED
@@ -0,0 +1,17 @@
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
+ /** Represents a struct (object with string keys) */
12
+ export type Dict<T> = {
13
+ [key: string]: T;
14
+ };
15
+ export type BufferLike = Buffer | string | ArrayBuffer | Uint8Array | Uint16Array | Uint32Array | SharedArrayBuffer | ArrayBufferView | DataView | readonly number[];
16
+ export type GenericFunction = (...args: any[]) => unknown;
17
+ export type MaybePromise<T> = T | Promise<T>;
@@ -0,0 +1,2 @@
1
+ export * from "./runtime";
2
+ export * from "./validator";
package/util/index.js ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _runtime = require("./runtime");
7
+ Object.keys(_runtime).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _runtime[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _runtime[key];
14
+ }
15
+ });
16
+ });
17
+ var _validator = require("./validator");
18
+ Object.keys(_validator).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _validator[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _validator[key];
25
+ }
26
+ });
27
+ });
@@ -0,0 +1,14 @@
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 { BufferLike } from "../types";
12
+ import { MemoryBuffer } from "../allocators";
13
+ export declare function toInt(n: number): number;
14
+ export declare function toBuffer(chunk: BufferLike): MemoryBuffer;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.toBuffer = toBuffer;
7
+ exports.toInt = toInt;
8
+ var _errors = require("../errors");
9
+ var _allocators = require("../allocators");
10
+ /**
11
+ * Copyright © 2026 Alerta Dino. All rights reserved.
12
+ *
13
+ * This code was released under the BSD 3-Clause License.
14
+ * See the "LICENSE" file under project root.
15
+ *
16
+ * @author (PUBLIC_ID) 1D-C2-9B-98-D6-C3-D6-AB
17
+ * @signphrase It was created on Earth by humans, although
18
+ * I can't define what a "human" is.
19
+ */
20
+
21
+ function toInt(n) {
22
+ return ~~n;
23
+ }
24
+ function toBuffer(chunk) {
25
+ let target = Buffer.isBuffer(chunk) ? chunk : null;
26
+ if (typeof chunk === "string") {
27
+ target = Buffer.from(chunk);
28
+ }
29
+ if (chunk instanceof ArrayBuffer) {
30
+ target = Buffer.from(chunk);
31
+ }
32
+ if (chunk instanceof Uint8Array) {
33
+ target = Buffer.from(chunk);
34
+ }
35
+ if (chunk instanceof Uint16Array) {
36
+ target = Buffer.from(chunk);
37
+ }
38
+ if (chunk instanceof Uint32Array) {
39
+ target = Buffer.from(chunk);
40
+ }
41
+ if (chunk instanceof Int8Array) {
42
+ target = Buffer.from(chunk);
43
+ }
44
+ if (chunk instanceof Int16Array) {
45
+ target = Buffer.from(chunk);
46
+ }
47
+ if (chunk instanceof Int32Array) {
48
+ target = Buffer.from(chunk);
49
+ }
50
+ if (chunk instanceof Float32Array) {
51
+ target = Buffer.from(chunk);
52
+ }
53
+ if (chunk instanceof Float64Array) {
54
+ target = Buffer.from(chunk);
55
+ }
56
+ if (chunk instanceof SharedArrayBuffer) {
57
+ target = Buffer.from(chunk);
58
+ }
59
+ if (chunk instanceof DataView) {
60
+ target = Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength);
61
+ }
62
+ if (ArrayBuffer.isView(chunk)) {
63
+ target = Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength);
64
+ }
65
+ if (Array.isArray(chunk) && chunk.every(x => typeof x === "number")) {
66
+ target = Buffer.from(chunk);
67
+ }
68
+ if (!target || !Buffer.isBuffer(target)) {
69
+ throw new _errors.BGDException(`[@@toBuffer] Failed to cast 'typeof ${typeof chunk}' to binary data`, "ER_INVALID_ARGUMENT");
70
+ }
71
+ const out = _allocators.MemoryBuffer.alloc(target.length);
72
+ for (let i = 0; i < target.length; ++i) {
73
+ out.setByte(i, target[i]);
74
+ }
75
+ target.fill(0);
76
+ target = null;
77
+ return out;
78
+ }
@@ -0,0 +1,21 @@
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 { GenericFunction } from "../types";
12
+ type Tn = "uint8" | "uint16" | "uint32" | "func";
13
+ interface Tmap {
14
+ uint8: number;
15
+ uint16: number;
16
+ uint32: number;
17
+ func: GenericFunction;
18
+ }
19
+ export declare function assertType(typename: Tn, val: unknown, message?: string): asserts val is Tmap[Tn];
20
+ export declare function assert(c: unknown, message?: string): asserts c;
21
+ export {};
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.assert = assert;
7
+ exports.assertType = assertType;
8
+ var _const = require("../const");
9
+ var _errors = require("../errors");
10
+ /**
11
+ * Copyright © 2026 Alerta Dino. All rights reserved.
12
+ *
13
+ * This code was released under the BSD 3-Clause License.
14
+ * See the "LICENSE" file under project root.
15
+ *
16
+ * @author (PUBLIC_ID) 1D-C2-9B-98-D6-C3-D6-AB
17
+ * @signphrase It was created on Earth by humans, although
18
+ * I can't define what a "human" is.
19
+ */
20
+
21
+ function assertType(typename, val, message) {
22
+ let isValid = false;
23
+ switch (typename) {
24
+ case "uint8":
25
+ {
26
+ isValid = typeof val === "number" && !Number.isNaN(val) && Number.isFinite(val) && Number.isInteger(val) && val >= _const.UINT8_RANGE[0] && val <= _const.UINT8_RANGE[1];
27
+ }
28
+ break;
29
+ case "uint16":
30
+ {
31
+ isValid = typeof val === "number" && !Number.isNaN(val) && Number.isFinite(val) && Number.isInteger(val) && val >= _const.UINT16_RANGE[0] && val <= _const.UINT16_RANGE[1];
32
+ }
33
+ break;
34
+ case "uint32":
35
+ {
36
+ isValid = typeof val === "number" && !Number.isNaN(val) && Number.isFinite(val) && Number.isInteger(val) && val >= _const.UINT32_RANGE[0] && val <= _const.UINT32_RANGE[1];
37
+ }
38
+ break;
39
+ case "func":
40
+ {
41
+ isValid = typeof val === "function";
42
+ }
43
+ break;
44
+ }
45
+ if (!isValid) {
46
+ throw new _errors.BGDException(message?.trim() || `[@@assertType] Assertation failed for 'typeof ${typename}'`, "ER_ASSERTATION_FAILED" // eslint-disable-line comma-dangle
47
+ );
48
+ }
49
+ }
50
+ function assert(c, message) {
51
+ let isValid = false;
52
+ switch (typeof c) {
53
+ case "string":
54
+ {
55
+ isValid = c.trim().length > 0;
56
+ }
57
+ break;
58
+ case "boolean":
59
+ {
60
+ isValid = c;
61
+ }
62
+ break;
63
+ case "number":
64
+ {
65
+ isValid = !isNaN(c);
66
+ }
67
+ break;
68
+ default:
69
+ isValid = !!c;
70
+ }
71
+ if (!isValid) {
72
+ throw new _errors.BGDException(message?.trim() || `[@@assert] Assertation failed for 'typeof ${typeof c}'`, "ER_ASSERTATION_FAILED" // eslint-disable-line comma-dangle
73
+ );
74
+ }
75
+ }