@mtkruto/node 0.0.922 → 0.0.923

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.
@@ -4,7 +4,7 @@ export declare const publicKeys: Map<bigint, [bigint, bigint]>;
4
4
  export declare const VECTOR_CONSTRUCTOR = 481674261;
5
5
  export declare const DEFAULT_INITIAL_DC: DC;
6
6
  export declare const LAYER = 158;
7
- export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.922";
7
+ export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.923";
8
8
  export declare const DEFAULT_DEVICE_MODEL: string;
9
9
  export declare const DEFAULT_LANG_CODE: string;
10
10
  export declare const DEFAULT_LANG_PACK = "";
package/esm/constants.js CHANGED
@@ -62,7 +62,7 @@ export const publicKeys = new Map([
62
62
  export const VECTOR_CONSTRUCTOR = 0x1CB5C415;
63
63
  export const DEFAULT_INITIAL_DC = "2-test";
64
64
  export const LAYER = 158;
65
- export const DEFAULT_APP_VERSION = "MTKruto 0.0.922";
65
+ export const DEFAULT_APP_VERSION = "MTKruto 0.0.923";
66
66
  // @ts-ignore: lib
67
67
  export const DEFAULT_DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
68
68
  export const DEFAULT_LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
package/esm/mod.d.ts CHANGED
@@ -16,6 +16,7 @@ export * from "./storage/0_storage.js";
16
16
  export * from "./storage/1_storage_memory.js";
17
17
  export * from "./storage/1_storage_local_storage.js";
18
18
  export * from "./storage/1_storage_session_storage.js";
19
+ export * from "./storage/1_storage_indexed_db.js";
19
20
  export * from "./transport/1_transport_abridged.js";
20
21
  export * from "./transport/1_transport_intermediate.js";
21
22
  export * from "./transport/0_transport.js";
package/esm/mod.js CHANGED
@@ -13,6 +13,7 @@ export * from "./storage/0_storage.js";
13
13
  export * from "./storage/1_storage_memory.js";
14
14
  export * from "./storage/1_storage_local_storage.js";
15
15
  export * from "./storage/1_storage_session_storage.js";
16
+ export * from "./storage/1_storage_indexed_db.js";
16
17
  export * from "./transport/1_transport_abridged.js";
17
18
  export * from "./transport/1_transport_intermediate.js";
18
19
  export * from "./transport/0_transport.js";
@@ -0,0 +1,9 @@
1
+ import { Storage } from "./0_storage.js";
2
+ export declare class StorageIndexedDB extends Storage {
3
+ readonly name: string;
4
+ database: IDBDatabase | null;
5
+ constructor(name: string);
6
+ init(): Promise<void>;
7
+ set(k: string, v: string | null): Promise<void>;
8
+ get(k: string): Promise<string | null>;
9
+ }
@@ -0,0 +1,74 @@
1
+ import { Storage } from "./0_storage.js";
2
+ const VERSION = 1;
3
+ const KV_OBJECT_STORE = "kv";
4
+ export class StorageIndexedDB extends Storage {
5
+ constructor(name) {
6
+ if (typeof indexedDB == "undefined") {
7
+ throw new Error("Unavailable in current environment");
8
+ }
9
+ super();
10
+ Object.defineProperty(this, "name", {
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true,
14
+ value: name
15
+ });
16
+ Object.defineProperty(this, "database", {
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true,
20
+ value: null
21
+ });
22
+ }
23
+ init() {
24
+ const db = indexedDB.open(this.name, VERSION);
25
+ return new Promise((res, rej) => {
26
+ db.onblocked = rej;
27
+ db.onerror = rej;
28
+ db.onupgradeneeded = () => {
29
+ db.result.createObjectStore(KV_OBJECT_STORE);
30
+ };
31
+ db.onsuccess = () => {
32
+ this.database = db.result;
33
+ res();
34
+ };
35
+ });
36
+ }
37
+ set(k, v) {
38
+ if (!this.database) {
39
+ throw new Error("Not initialized");
40
+ }
41
+ const store = this.database
42
+ .transaction(KV_OBJECT_STORE, "readwrite")
43
+ .objectStore(KV_OBJECT_STORE);
44
+ // deno-lint-ignore no-explicit-any
45
+ let tx;
46
+ if (v == null) {
47
+ tx = store.delete(k);
48
+ }
49
+ else {
50
+ tx = store.put(v, k);
51
+ }
52
+ return new Promise((res, rej) => {
53
+ tx.onerror = rej;
54
+ tx.onsuccess = () => {
55
+ res();
56
+ };
57
+ });
58
+ }
59
+ get(k) {
60
+ if (!this.database) {
61
+ throw new Error("Not initialized");
62
+ }
63
+ const tx = this.database
64
+ .transaction(KV_OBJECT_STORE, "readonly")
65
+ .objectStore(KV_OBJECT_STORE)
66
+ .get(k);
67
+ return new Promise((res, rej) => {
68
+ tx.onerror = rej;
69
+ tx.onsuccess = () => {
70
+ res(tx.result == undefined ? null : tx.result);
71
+ };
72
+ });
73
+ }
74
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "module": "./esm/mod.js",
3
3
  "main": "./script/mod.js",
4
4
  "name": "@mtkruto/node",
5
- "version": "0.0.922",
5
+ "version": "0.0.923",
6
6
  "description": "MTKruto for Node.js",
7
7
  "author": "Roj <rojvv@icloud.com>",
8
8
  "license": "LGPL-3.0-or-later",
@@ -4,7 +4,7 @@ export declare const publicKeys: Map<bigint, [bigint, bigint]>;
4
4
  export declare const VECTOR_CONSTRUCTOR = 481674261;
5
5
  export declare const DEFAULT_INITIAL_DC: DC;
6
6
  export declare const LAYER = 158;
7
- export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.922";
7
+ export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.923";
8
8
  export declare const DEFAULT_DEVICE_MODEL: string;
9
9
  export declare const DEFAULT_LANG_CODE: string;
10
10
  export declare const DEFAULT_LANG_PACK = "";
@@ -88,7 +88,7 @@ exports.publicKeys = new Map([
88
88
  exports.VECTOR_CONSTRUCTOR = 0x1CB5C415;
89
89
  exports.DEFAULT_INITIAL_DC = "2-test";
90
90
  exports.LAYER = 158;
91
- exports.DEFAULT_APP_VERSION = "MTKruto 0.0.922";
91
+ exports.DEFAULT_APP_VERSION = "MTKruto 0.0.923";
92
92
  // @ts-ignore: lib
93
93
  exports.DEFAULT_DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
94
94
  exports.DEFAULT_LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
package/script/mod.d.ts CHANGED
@@ -16,6 +16,7 @@ export * from "./storage/0_storage.js";
16
16
  export * from "./storage/1_storage_memory.js";
17
17
  export * from "./storage/1_storage_local_storage.js";
18
18
  export * from "./storage/1_storage_session_storage.js";
19
+ export * from "./storage/1_storage_indexed_db.js";
19
20
  export * from "./transport/1_transport_abridged.js";
20
21
  export * from "./transport/1_transport_intermediate.js";
21
22
  export * from "./transport/0_transport.js";
package/script/mod.js CHANGED
@@ -43,6 +43,7 @@ __exportStar(require("./storage/0_storage.js"), exports);
43
43
  __exportStar(require("./storage/1_storage_memory.js"), exports);
44
44
  __exportStar(require("./storage/1_storage_local_storage.js"), exports);
45
45
  __exportStar(require("./storage/1_storage_session_storage.js"), exports);
46
+ __exportStar(require("./storage/1_storage_indexed_db.js"), exports);
46
47
  __exportStar(require("./transport/1_transport_abridged.js"), exports);
47
48
  __exportStar(require("./transport/1_transport_intermediate.js"), exports);
48
49
  __exportStar(require("./transport/0_transport.js"), exports);
@@ -0,0 +1,9 @@
1
+ import { Storage } from "./0_storage.js";
2
+ export declare class StorageIndexedDB extends Storage {
3
+ readonly name: string;
4
+ database: IDBDatabase | null;
5
+ constructor(name: string);
6
+ init(): Promise<void>;
7
+ set(k: string, v: string | null): Promise<void>;
8
+ get(k: string): Promise<string | null>;
9
+ }
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StorageIndexedDB = void 0;
4
+ const _0_storage_js_1 = require("./0_storage.js");
5
+ const VERSION = 1;
6
+ const KV_OBJECT_STORE = "kv";
7
+ class StorageIndexedDB extends _0_storage_js_1.Storage {
8
+ constructor(name) {
9
+ if (typeof indexedDB == "undefined") {
10
+ throw new Error("Unavailable in current environment");
11
+ }
12
+ super();
13
+ Object.defineProperty(this, "name", {
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true,
17
+ value: name
18
+ });
19
+ Object.defineProperty(this, "database", {
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true,
23
+ value: null
24
+ });
25
+ }
26
+ init() {
27
+ const db = indexedDB.open(this.name, VERSION);
28
+ return new Promise((res, rej) => {
29
+ db.onblocked = rej;
30
+ db.onerror = rej;
31
+ db.onupgradeneeded = () => {
32
+ db.result.createObjectStore(KV_OBJECT_STORE);
33
+ };
34
+ db.onsuccess = () => {
35
+ this.database = db.result;
36
+ res();
37
+ };
38
+ });
39
+ }
40
+ set(k, v) {
41
+ if (!this.database) {
42
+ throw new Error("Not initialized");
43
+ }
44
+ const store = this.database
45
+ .transaction(KV_OBJECT_STORE, "readwrite")
46
+ .objectStore(KV_OBJECT_STORE);
47
+ // deno-lint-ignore no-explicit-any
48
+ let tx;
49
+ if (v == null) {
50
+ tx = store.delete(k);
51
+ }
52
+ else {
53
+ tx = store.put(v, k);
54
+ }
55
+ return new Promise((res, rej) => {
56
+ tx.onerror = rej;
57
+ tx.onsuccess = () => {
58
+ res();
59
+ };
60
+ });
61
+ }
62
+ get(k) {
63
+ if (!this.database) {
64
+ throw new Error("Not initialized");
65
+ }
66
+ const tx = this.database
67
+ .transaction(KV_OBJECT_STORE, "readonly")
68
+ .objectStore(KV_OBJECT_STORE)
69
+ .get(k);
70
+ return new Promise((res, rej) => {
71
+ tx.onerror = rej;
72
+ tx.onsuccess = () => {
73
+ res(tx.result == undefined ? null : tx.result);
74
+ };
75
+ });
76
+ }
77
+ }
78
+ exports.StorageIndexedDB = StorageIndexedDB;