@mtkruto/node 0.0.823 → 0.0.825

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 (45) hide show
  1. package/esm/client/client.d.ts +12 -6
  2. package/esm/client/client.js +165 -31
  3. package/esm/client/client_abstract.d.ts +2 -1
  4. package/esm/client/client_abstract.js +1 -0
  5. package/esm/constants.d.ts +4 -0
  6. package/esm/constants.js +4 -0
  7. package/esm/mod.d.ts +4 -3
  8. package/esm/mod.js +4 -3
  9. package/esm/storage/storage.d.ts +23 -0
  10. package/esm/storage/storage.js +98 -0
  11. package/esm/storage/storage_local_storage.d.ts +9 -0
  12. package/esm/storage/storage_local_storage.js +36 -0
  13. package/esm/storage/storage_memory.d.ts +8 -0
  14. package/esm/storage/storage_memory.js +25 -0
  15. package/esm/storage/storage_session_storage.d.ts +9 -0
  16. package/esm/storage/storage_session_storage.js +36 -0
  17. package/package.json +1 -1
  18. package/script/client/client.d.ts +12 -6
  19. package/script/client/client.js +163 -29
  20. package/script/client/client_abstract.d.ts +2 -1
  21. package/script/client/client_abstract.js +1 -0
  22. package/script/constants.d.ts +4 -0
  23. package/script/constants.js +5 -1
  24. package/script/mod.d.ts +4 -3
  25. package/script/mod.js +4 -3
  26. package/script/storage/storage.d.ts +23 -0
  27. package/script/storage/storage.js +102 -0
  28. package/script/storage/storage_local_storage.d.ts +9 -0
  29. package/script/storage/storage_local_storage.js +40 -0
  30. package/script/storage/storage_memory.d.ts +8 -0
  31. package/script/storage/storage_memory.js +29 -0
  32. package/script/storage/storage_session_storage.d.ts +9 -0
  33. package/script/storage/storage_session_storage.js +40 -0
  34. package/esm/session/session.d.ts +0 -12
  35. package/esm/session/session.js +0 -36
  36. package/esm/session/session_local_storage.d.ts +0 -7
  37. package/esm/session/session_local_storage.js +0 -26
  38. package/esm/session/session_memory.d.ts +0 -5
  39. package/esm/session/session_memory.js +0 -5
  40. package/script/session/session.d.ts +0 -12
  41. package/script/session/session.js +0 -40
  42. package/script/session/session_local_storage.d.ts +0 -7
  43. package/script/session/session_local_storage.js +0 -30
  44. package/script/session/session_memory.d.ts +0 -5
  45. package/script/session/session_memory.js +0 -9
@@ -0,0 +1,8 @@
1
+ import { MaybePromise } from "../types.js";
2
+ import { Storage } from "./storage.js";
3
+ export declare class StorageMemory extends Storage implements Storage {
4
+ protected map: Map<string, string>;
5
+ init(): void;
6
+ get(key: string): string | null;
7
+ set(key: string, value: string | null): MaybePromise<void>;
8
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StorageMemory = void 0;
4
+ const storage_js_1 = require("./storage.js");
5
+ class StorageMemory extends storage_js_1.Storage {
6
+ constructor() {
7
+ super(...arguments);
8
+ Object.defineProperty(this, "map", {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value: new Map()
13
+ });
14
+ }
15
+ init() {
16
+ }
17
+ get(key) {
18
+ return this.map.get(key) ?? null;
19
+ }
20
+ set(key, value) {
21
+ if (value != null) {
22
+ this.map.set(key, value);
23
+ }
24
+ else {
25
+ this.map.delete(key);
26
+ }
27
+ }
28
+ }
29
+ exports.StorageMemory = StorageMemory;
@@ -0,0 +1,9 @@
1
+ import { MaybePromise } from "../types.js";
2
+ import { Storage } from "./storage.js";
3
+ export declare class StorageSessionStorage extends Storage implements Storage {
4
+ private readonly prefix;
5
+ constructor(prefix: string);
6
+ init(): void;
7
+ get(key: string): string | null;
8
+ set(key: string, value: string | null): MaybePromise<void>;
9
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StorageSessionStorage = void 0;
4
+ const storage_js_1 = require("./storage.js");
5
+ class StorageSessionStorage extends storage_js_1.Storage {
6
+ constructor(prefix) {
7
+ if (typeof sessionStorage === "undefined") {
8
+ throw new Error("Unavailable in current environment");
9
+ }
10
+ if (prefix.length <= 0) {
11
+ throw new Error("Empty prefix");
12
+ }
13
+ else if (!/^[0-9a-zA-Z]+$/.test(prefix)) {
14
+ throw new Error("Unallowed prefix");
15
+ }
16
+ super();
17
+ Object.defineProperty(this, "prefix", {
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true,
21
+ value: prefix
22
+ });
23
+ }
24
+ init() {
25
+ }
26
+ get(key) {
27
+ key = this.prefix + key;
28
+ return sessionStorage.getItem(key);
29
+ }
30
+ set(key, value) {
31
+ key = this.prefix + key;
32
+ if (value != null) {
33
+ sessionStorage.setItem(key, value);
34
+ }
35
+ else {
36
+ sessionStorage.removeItem(key);
37
+ }
38
+ }
39
+ }
40
+ exports.StorageSessionStorage = StorageSessionStorage;
@@ -1,12 +0,0 @@
1
- import { MaybePromise } from "../types.js";
2
- import { DC } from "../transport/transport_provider.js";
3
- export declare abstract class Session {
4
- dc: DC | null;
5
- private _authKeyId;
6
- private _authKey;
7
- abstract load(): MaybePromise<void>;
8
- abstract save(): MaybePromise<void>;
9
- get authKeyId(): Promise<bigint | null>;
10
- set authKey(authKey: Uint8Array | null);
11
- get authKey(): Uint8Array | null;
12
- }
@@ -1,36 +0,0 @@
1
- import { sha1 } from "../utilities/0_hash.js";
2
- import { bigIntFromBuffer } from "../utilities/0_bigint.js";
3
- export class Session {
4
- constructor() {
5
- Object.defineProperty(this, "dc", {
6
- enumerable: true,
7
- configurable: true,
8
- writable: true,
9
- value: null
10
- });
11
- Object.defineProperty(this, "_authKeyId", {
12
- enumerable: true,
13
- configurable: true,
14
- writable: true,
15
- value: Promise.resolve(null)
16
- });
17
- Object.defineProperty(this, "_authKey", {
18
- enumerable: true,
19
- configurable: true,
20
- writable: true,
21
- value: null
22
- });
23
- }
24
- get authKeyId() {
25
- return this._authKeyId;
26
- }
27
- set authKey(authKey) {
28
- this._authKey = authKey;
29
- if (authKey != null) {
30
- this._authKeyId = sha1(authKey).then((hash) => bigIntFromBuffer(hash.slice(-8), true, false));
31
- }
32
- }
33
- get authKey() {
34
- return this._authKey;
35
- }
36
- }
@@ -1,7 +0,0 @@
1
- import { Session } from "./session.js";
2
- export declare class SessionLocalStorage extends Session implements Session {
3
- private readonly key;
4
- constructor(key: string);
5
- load(): void;
6
- save(): void;
7
- }
@@ -1,26 +0,0 @@
1
- import { Session } from "./session.js";
2
- export class SessionLocalStorage extends Session {
3
- constructor(key) {
4
- if (typeof localStorage == "undefined") {
5
- throw new Error("Unavailable in current environment");
6
- }
7
- super();
8
- Object.defineProperty(this, "key", {
9
- enumerable: true,
10
- configurable: true,
11
- writable: true,
12
- value: key
13
- });
14
- }
15
- load() {
16
- const { dc = null, authKey = null } = JSON.parse(localStorage.getItem(this.key) ?? "{}");
17
- this.dc = dc;
18
- if (authKey != null) {
19
- this.authKey = new Uint8Array(authKey.split(/([0-9a-f]{2})/).filter((v) => v).map((v) => parseInt(v, 16)));
20
- }
21
- }
22
- save() {
23
- const authKey = this.authKey == null ? undefined : Array.from(this.authKey).map((v) => v.toString(16)).map((v) => v.padStart(2, "0")).join("");
24
- localStorage.setItem(this.key, JSON.stringify({ dc: this.dc, authKey }));
25
- }
26
- }
@@ -1,5 +0,0 @@
1
- import { Session } from "./session.js";
2
- export declare class SessionMemory extends Session implements Session {
3
- load(): void;
4
- save(): void;
5
- }
@@ -1,5 +0,0 @@
1
- import { Session } from "./session.js";
2
- export class SessionMemory extends Session {
3
- load() { }
4
- save() { }
5
- }
@@ -1,12 +0,0 @@
1
- import { MaybePromise } from "../types.js";
2
- import { DC } from "../transport/transport_provider.js";
3
- export declare abstract class Session {
4
- dc: DC | null;
5
- private _authKeyId;
6
- private _authKey;
7
- abstract load(): MaybePromise<void>;
8
- abstract save(): MaybePromise<void>;
9
- get authKeyId(): Promise<bigint | null>;
10
- set authKey(authKey: Uint8Array | null);
11
- get authKey(): Uint8Array | null;
12
- }
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Session = void 0;
4
- const _0_hash_js_1 = require("../utilities/0_hash.js");
5
- const _0_bigint_js_1 = require("../utilities/0_bigint.js");
6
- class Session {
7
- constructor() {
8
- Object.defineProperty(this, "dc", {
9
- enumerable: true,
10
- configurable: true,
11
- writable: true,
12
- value: null
13
- });
14
- Object.defineProperty(this, "_authKeyId", {
15
- enumerable: true,
16
- configurable: true,
17
- writable: true,
18
- value: Promise.resolve(null)
19
- });
20
- Object.defineProperty(this, "_authKey", {
21
- enumerable: true,
22
- configurable: true,
23
- writable: true,
24
- value: null
25
- });
26
- }
27
- get authKeyId() {
28
- return this._authKeyId;
29
- }
30
- set authKey(authKey) {
31
- this._authKey = authKey;
32
- if (authKey != null) {
33
- this._authKeyId = (0, _0_hash_js_1.sha1)(authKey).then((hash) => (0, _0_bigint_js_1.bigIntFromBuffer)(hash.slice(-8), true, false));
34
- }
35
- }
36
- get authKey() {
37
- return this._authKey;
38
- }
39
- }
40
- exports.Session = Session;
@@ -1,7 +0,0 @@
1
- import { Session } from "./session.js";
2
- export declare class SessionLocalStorage extends Session implements Session {
3
- private readonly key;
4
- constructor(key: string);
5
- load(): void;
6
- save(): void;
7
- }
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SessionLocalStorage = void 0;
4
- const session_js_1 = require("./session.js");
5
- class SessionLocalStorage extends session_js_1.Session {
6
- constructor(key) {
7
- if (typeof localStorage == "undefined") {
8
- throw new Error("Unavailable in current environment");
9
- }
10
- super();
11
- Object.defineProperty(this, "key", {
12
- enumerable: true,
13
- configurable: true,
14
- writable: true,
15
- value: key
16
- });
17
- }
18
- load() {
19
- const { dc = null, authKey = null } = JSON.parse(localStorage.getItem(this.key) ?? "{}");
20
- this.dc = dc;
21
- if (authKey != null) {
22
- this.authKey = new Uint8Array(authKey.split(/([0-9a-f]{2})/).filter((v) => v).map((v) => parseInt(v, 16)));
23
- }
24
- }
25
- save() {
26
- const authKey = this.authKey == null ? undefined : Array.from(this.authKey).map((v) => v.toString(16)).map((v) => v.padStart(2, "0")).join("");
27
- localStorage.setItem(this.key, JSON.stringify({ dc: this.dc, authKey }));
28
- }
29
- }
30
- exports.SessionLocalStorage = SessionLocalStorage;
@@ -1,5 +0,0 @@
1
- import { Session } from "./session.js";
2
- export declare class SessionMemory extends Session implements Session {
3
- load(): void;
4
- save(): void;
5
- }
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SessionMemory = void 0;
4
- const session_js_1 = require("./session.js");
5
- class SessionMemory extends session_js_1.Session {
6
- load() { }
7
- save() { }
8
- }
9
- exports.SessionMemory = SessionMemory;