@iobroker/db-base 4.0.20 → 4.1.0-alpha.0-20220804-d8f17893

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.
@@ -0,0 +1,4 @@
1
+ export { InMemoryFileDB } from './lib/inMemFileDB';
2
+ export { RedisHandler } from './lib/redisHandler';
3
+ export { tools } from '@iobroker/js-controller-common';
4
+ //# sourceMappingURL=index.d.ts.map
package/build/index.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tools = exports.RedisHandler = exports.InMemoryFileDB = void 0;
4
+ var inMemFileDB_1 = require("./lib/inMemFileDB");
5
+ Object.defineProperty(exports, "InMemoryFileDB", { enumerable: true, get: function () { return inMemFileDB_1.InMemoryFileDB; } });
6
+ var redisHandler_1 = require("./lib/redisHandler");
7
+ Object.defineProperty(exports, "RedisHandler", { enumerable: true, get: function () { return redisHandler_1.RedisHandler; } });
8
+ var js_controller_common_1 = require("@iobroker/js-controller-common");
9
+ Object.defineProperty(exports, "tools", { enumerable: true, get: function () { return js_controller_common_1.tools; } });
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,4 @@
1
+ /// <reference types="node" />
2
+ export declare const QUEUED_STR_BUF: Buffer;
3
+ export declare const OK_STR_BUF: Buffer;
4
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/lib/constants.ts"],"names":[],"mappings":";AAGA,eAAO,MAAM,cAAc,EAAE,MAAoC,CAAC;AAClE,eAAO,MAAM,UAAU,EAAE,MAAgC,CAAC"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.OK_STR_BUF = exports.QUEUED_STR_BUF = void 0;
7
+ // @ts-expect-error types missing
8
+ const respjs_1 = __importDefault(require("respjs"));
9
+ exports.QUEUED_STR_BUF = respjs_1.default.encodeString('QUEUED');
10
+ exports.OK_STR_BUF = respjs_1.default.encodeString('OK');
11
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/lib/constants.ts"],"names":[],"mappings":";;;;;;AAAA,iCAAiC;AACjC,oDAA0B;AAEb,QAAA,cAAc,GAAW,gBAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;AACrD,QAAA,UAAU,GAAW,gBAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC"}
@@ -0,0 +1,130 @@
1
+ /**
2
+ * States DB in memory - Server
3
+ *
4
+ * Copyright 2013-2022 bluefox <dogafox@gmail.com>
5
+ *
6
+ * MIT License
7
+ *
8
+ */
9
+ import type { InternalLogger } from '@iobroker/js-controller-common/tools';
10
+ export interface ConnectionOptions {
11
+ pass?: string;
12
+ sentinelName?: string;
13
+ /** array on sentinel */
14
+ host: string | string[];
15
+ /** array on sentinel */
16
+ port: number | number[];
17
+ options: Record<string, any>;
18
+ maxQueue?: number;
19
+ enhancedLogging?: boolean;
20
+ backup?: BackupOptions;
21
+ /** relative path to the data dir */
22
+ dataDir: string;
23
+ }
24
+ declare type ChangeFunction = (id: string, state: any) => void;
25
+ export interface DbStatus {
26
+ type: string;
27
+ server: boolean;
28
+ }
29
+ interface BackupOptions {
30
+ /** deactivates backup if true */
31
+ disabled: boolean;
32
+ /** minimum number of files */
33
+ files: number;
34
+ hours: number;
35
+ /** minutes */
36
+ period: number;
37
+ path: string;
38
+ }
39
+ export interface DbOptions {
40
+ backupDirName: string;
41
+ fileName: string;
42
+ }
43
+ interface FileDbSettings {
44
+ fileDB: DbOptions;
45
+ jsonlDB: DbOptions;
46
+ backup: BackupOptions;
47
+ change?: ChangeFunction;
48
+ connected: (nameOfServer: string) => void;
49
+ logger: InternalLogger;
50
+ connection: ConnectionOptions;
51
+ /** unused */
52
+ auth?: null;
53
+ secure: boolean;
54
+ /** as required by createServer TODO: if createServer is typed, add type */
55
+ certificates: any;
56
+ port: number;
57
+ host: string;
58
+ /** logging namespace */
59
+ namespace?: string;
60
+ }
61
+ interface Subscription {
62
+ pattern: string;
63
+ regex: RegExp;
64
+ options: any;
65
+ }
66
+ interface SubscriptionClient {
67
+ _subscribe?: Record<string, Subscription[]>;
68
+ }
69
+ /**
70
+ * The parent of the class structure, which provides basic JSON storage
71
+ * and general subscription and publish functionality
72
+ **/
73
+ export declare class InMemoryFileDB {
74
+ private settings;
75
+ private readonly change;
76
+ private dataset;
77
+ private readonly namespace;
78
+ private lastSave;
79
+ private stateTimer;
80
+ private callbackSubscriptionClient;
81
+ private readonly dataDir;
82
+ private readonly datasetName;
83
+ private log;
84
+ private readonly backupDir;
85
+ constructor(settings: FileDbSettings);
86
+ open(): Promise<void>;
87
+ /**
88
+ * Loads a dataset file
89
+ *
90
+ * @param datasetName Filename of the file to load
91
+ * @returns obj read data, normally as object
92
+ */
93
+ loadDatasetFile(datasetName: string): Promise<Record<string, any>>;
94
+ /**
95
+ * Loads the dataset including pot. Fallback handling
96
+ *
97
+ * @param datasetName Filename of the file to load
98
+ * @returns obj dataset read as object
99
+ */
100
+ loadDataset(datasetName: string): Promise<Record<string, any>>;
101
+ initBackupDir(): void;
102
+ handleSubscribe(client: SubscriptionClient, type: string, pattern: string | string[], cb?: () => void): void;
103
+ handleSubscribe(client: SubscriptionClient, type: string, pattern: string | string[], options: any, cb?: () => void): void;
104
+ handleUnsubscribe(client: SubscriptionClient, type: string, pattern: string | string[], cb?: () => void): void | Promise<void>;
105
+ publishToClients(_client: SubscriptionClient, _type: string, _id: string, _obj: any): number;
106
+ deleteOldBackupFiles(baseFilename: string): void;
107
+ getTimeStr(date: number): string;
108
+ /**
109
+ * Handle saving the dataset incl. backups
110
+ */
111
+ saveState(): Promise<void>;
112
+ /**
113
+ * Saves the dataset into File incl. handling of a fallback backup file
114
+ *
115
+ * @returns dataset JSON string of the complete dataset to also be stored into a compressed backup file
116
+ */
117
+ saveDataset(): Promise<string>;
118
+ /**
119
+ * Stores a compressed backup of the DB in definable intervals
120
+ *
121
+ * @param jsonString JSON string of the complete dataset to also be stored into a compressed backup file
122
+ */
123
+ saveBackup(jsonString: string): void;
124
+ getStatus(): DbStatus;
125
+ getClients(): Record<string, any>;
126
+ publishAll(type: string, id: string, obj: any): number;
127
+ destroy(): Promise<void>;
128
+ }
129
+ export {};
130
+ //# sourceMappingURL=inMemFileDB.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inMemFileDB.d.ts","sourceRoot":"","sources":["../../src/lib/inMemFileDB.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AAwB3E,MAAM,WAAW,iBAAiB;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,wBAAwB;IACxB,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,wBAAwB;IACxB,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,oCAAoC;IACpC,OAAO,EAAE,MAAM,CAAC;CACnB;AAED,aAAK,cAAc,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;AAEvD,MAAM,WAAW,QAAQ;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;CACnB;AAED,UAAU,aAAa;IACnB,iCAAiC;IACjC,QAAQ,EAAE,OAAO,CAAC;IAClB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