inibase 1.1.22 → 1.1.24
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.
- package/dist/cli.js +7 -2
- package/dist/file.js +14 -8
- package/dist/index.d.ts +7 -8
- package/dist/index.js +22 -22
- package/dist/utils.server.d.ts +1 -2
- package/dist/utils.server.js +1 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -7,7 +7,7 @@ import { parseArgs } from "node:util";
|
|
|
7
7
|
import Inison from "inison";
|
|
8
8
|
import { isExists } from "./file.js";
|
|
9
9
|
import Inibase, {} from "./index.js";
|
|
10
|
-
import {
|
|
10
|
+
import { isNumber, isStringified, setField, unsetField } from "./utils.js";
|
|
11
11
|
const textGreen = (input) => `\u001b[1;32m${input}\u001b[0m`;
|
|
12
12
|
const textRed = (input) => `\u001b[1;31m${input}\u001b[0m`;
|
|
13
13
|
const textBlue = (input) => `\u001b[1;34m${input}\u001b[0m`;
|
|
@@ -197,7 +197,12 @@ rl.on("line", async (input) => {
|
|
|
197
197
|
console.log(`${textRed(" Err:")} Please specify table name`);
|
|
198
198
|
break;
|
|
199
199
|
}
|
|
200
|
-
let where = undefined
|
|
200
|
+
let where = undefined;
|
|
201
|
+
let page = undefined;
|
|
202
|
+
let perPage = undefined;
|
|
203
|
+
let columns = undefined;
|
|
204
|
+
let sort = undefined;
|
|
205
|
+
let data = undefined;
|
|
201
206
|
if (splitedInput.toSpliced(0, 1).length) {
|
|
202
207
|
const parsedArgs = parseArgs({
|
|
203
208
|
args: splitedInput.toSpliced(0, table ? 1 : 2),
|
package/dist/file.js
CHANGED
|
@@ -133,7 +133,6 @@ const unSecureString = (input) => {
|
|
|
133
133
|
*
|
|
134
134
|
* @param value - The value to be decoded, can be string, number, or array.
|
|
135
135
|
* @param field - Field object config.
|
|
136
|
-
* @param fieldChildrenType - Optional type for children elements, used for arrays.
|
|
137
136
|
* @returns Decoded value, transformed according to the specified field type(s).
|
|
138
137
|
*/
|
|
139
138
|
const decodeHelper = (value, field) => {
|
|
@@ -159,7 +158,7 @@ const decodeHelper = (value, field) => {
|
|
|
159
158
|
return isNumber(value) &&
|
|
160
159
|
(!field.table ||
|
|
161
160
|
!field.databasePath ||
|
|
162
|
-
!globalConfig[field.databasePath].tables
|
|
161
|
+
!globalConfig[field.databasePath].tables?.get(field.table)?.config
|
|
163
162
|
.decodeID)
|
|
164
163
|
? encodeID(value)
|
|
165
164
|
: value;
|
|
@@ -217,7 +216,8 @@ export async function get(filePath, lineNumbers, field, readWholeFile = false) {
|
|
|
217
216
|
let fileHandle = null;
|
|
218
217
|
try {
|
|
219
218
|
fileHandle = await open(filePath, "r");
|
|
220
|
-
const rl = createReadLineInternface(filePath, fileHandle)
|
|
219
|
+
const rl = createReadLineInternface(filePath, fileHandle);
|
|
220
|
+
const lines = {};
|
|
221
221
|
let linesCount = 0;
|
|
222
222
|
if (!lineNumbers) {
|
|
223
223
|
for await (const line of rl) {
|
|
@@ -229,7 +229,8 @@ export async function get(filePath, lineNumbers, field, readWholeFile = false) {
|
|
|
229
229
|
const escapedFilePath = escapeShellPath(filePath);
|
|
230
230
|
const command = filePath.endsWith(".gz")
|
|
231
231
|
? `zcat ${escapedFilePath} | sed -n '$p'`
|
|
232
|
-
: `sed -n '$p' ${escapedFilePath}
|
|
232
|
+
: `sed -n '$p' ${escapedFilePath}`;
|
|
233
|
+
const foundedLine = (await exec(command)).stdout.trimEnd();
|
|
233
234
|
if (foundedLine)
|
|
234
235
|
lines[linesCount] = decode(foundedLine, field);
|
|
235
236
|
}
|
|
@@ -251,7 +252,8 @@ export async function get(filePath, lineNumbers, field, readWholeFile = false) {
|
|
|
251
252
|
const escapedFilePath = escapeShellPath(filePath);
|
|
252
253
|
const command = filePath.endsWith(".gz")
|
|
253
254
|
? `zcat ${escapedFilePath} | sed -n '${_groupIntoRanges(lineNumbers)}'`
|
|
254
|
-
: `sed -n '${_groupIntoRanges(lineNumbers)}' ${escapedFilePath}
|
|
255
|
+
: `sed -n '${_groupIntoRanges(lineNumbers)}' ${escapedFilePath}`;
|
|
256
|
+
const foundedLines = (await exec(command)).stdout.trimEnd().split("\n");
|
|
255
257
|
let index = 0;
|
|
256
258
|
for (const line of foundedLines) {
|
|
257
259
|
lines[lineNumbers[index]] = decode(line, field);
|
|
@@ -589,7 +591,8 @@ export const search = async (filePath, operator, comparedAtValue, logicalOperato
|
|
|
589
591
|
* Note: Decodes each line as a number using the 'decode' function. Non-numeric lines contribute 0 to the sum.
|
|
590
592
|
*/
|
|
591
593
|
export const sum = async (filePath, lineNumbers) => {
|
|
592
|
-
let sum = 0
|
|
594
|
+
let sum = 0;
|
|
595
|
+
let fileHandle = null;
|
|
593
596
|
try {
|
|
594
597
|
fileHandle = await open(filePath, "r");
|
|
595
598
|
const rl = createReadLineInternface(filePath, fileHandle);
|
|
@@ -625,7 +628,9 @@ export const sum = async (filePath, lineNumbers) => {
|
|
|
625
628
|
* Note: Decodes each line as a number using the 'decode' function. Considers only numerical values for determining the maximum.
|
|
626
629
|
*/
|
|
627
630
|
export const max = async (filePath, lineNumbers) => {
|
|
628
|
-
let max = 0
|
|
631
|
+
let max = 0;
|
|
632
|
+
let fileHandle = null;
|
|
633
|
+
let rl = null;
|
|
629
634
|
try {
|
|
630
635
|
fileHandle = await open(filePath, "r");
|
|
631
636
|
rl = createReadLineInternface(filePath, fileHandle);
|
|
@@ -666,7 +671,8 @@ export const max = async (filePath, lineNumbers) => {
|
|
|
666
671
|
* Note: Decodes each line as a number using the 'decode' function. Considers only numerical values for determining the minimum.
|
|
667
672
|
*/
|
|
668
673
|
export const min = async (filePath, lineNumbers) => {
|
|
669
|
-
let min = 0
|
|
674
|
+
let min = 0;
|
|
675
|
+
let fileHandle = null;
|
|
670
676
|
try {
|
|
671
677
|
fileHandle = await open(filePath, "r");
|
|
672
678
|
const rl = createReadLineInternface(filePath, fileHandle);
|
package/dist/index.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export interface Options {
|
|
|
23
23
|
columns?: string[] | string;
|
|
24
24
|
sort?: Record<string, 1 | -1 | "asc" | "ASC" | "desc" | "DESC"> | string[] | string;
|
|
25
25
|
}
|
|
26
|
-
export interface
|
|
26
|
+
export interface TableConfig {
|
|
27
27
|
compression?: boolean;
|
|
28
28
|
cache?: boolean;
|
|
29
29
|
prepend?: boolean;
|
|
@@ -31,7 +31,7 @@ export interface Config {
|
|
|
31
31
|
}
|
|
32
32
|
export interface TableObject {
|
|
33
33
|
schema?: Schema;
|
|
34
|
-
config:
|
|
34
|
+
config: TableConfig;
|
|
35
35
|
}
|
|
36
36
|
export type ComparisonOperator = "=" | "!=" | ">" | "<" | ">=" | "<=" | "*" | "!*" | "[]" | "![]";
|
|
37
37
|
export type pageInfo = {
|
|
@@ -70,7 +70,6 @@ export default class Inibase {
|
|
|
70
70
|
constructor(database: string, mainFolder?: string, language?: ErrorLang);
|
|
71
71
|
private static errorMessages;
|
|
72
72
|
createError(name: ErrorCodes, variable?: string | number | (string | number)[]): Error;
|
|
73
|
-
clear(): void;
|
|
74
73
|
private getFileExtension;
|
|
75
74
|
private _schemaToIdsPath;
|
|
76
75
|
/**
|
|
@@ -78,18 +77,18 @@ export default class Inibase {
|
|
|
78
77
|
*
|
|
79
78
|
* @param {string} tableName
|
|
80
79
|
* @param {Schema} [schema]
|
|
81
|
-
* @param {
|
|
80
|
+
* @param {TableConfig} [config]
|
|
82
81
|
*/
|
|
83
|
-
createTable(tableName: string, schema?: Schema, config?:
|
|
82
|
+
createTable(tableName: string, schema?: Schema, config?: TableConfig): Promise<void>;
|
|
84
83
|
private replaceStringInFile;
|
|
85
84
|
/**
|
|
86
85
|
* Update table schema or config
|
|
87
86
|
*
|
|
88
87
|
* @param {string} tableName
|
|
89
88
|
* @param {Schema} [schema]
|
|
90
|
-
* @param {(
|
|
89
|
+
* @param {(TableConfig&{name?: string})} [config]
|
|
91
90
|
*/
|
|
92
|
-
updateTable(tableName: string, schema?: Schema, config?:
|
|
91
|
+
updateTable(tableName: string, schema?: Schema, config?: TableConfig & {
|
|
93
92
|
name?: string;
|
|
94
93
|
}): Promise<void>;
|
|
95
94
|
/**
|
|
@@ -99,7 +98,7 @@ export default class Inibase {
|
|
|
99
98
|
* @return {*} {Promise<TableObject>}
|
|
100
99
|
*/
|
|
101
100
|
getTable(tableName: string, encodeIDs?: boolean): Promise<TableObject>;
|
|
102
|
-
getTableSchema(tableName: string, encodeIDs?: boolean): Promise<Schema
|
|
101
|
+
getTableSchema(tableName: string, encodeIDs?: boolean): Promise<Schema>;
|
|
103
102
|
private throwErrorIfTableEmpty;
|
|
104
103
|
private _validateData;
|
|
105
104
|
private validateData;
|
package/dist/index.js
CHANGED
|
@@ -20,8 +20,12 @@ export default class Inibase {
|
|
|
20
20
|
totalItems;
|
|
21
21
|
constructor(database, mainFolder = ".", language = "en") {
|
|
22
22
|
this.databasePath = join(mainFolder, database);
|
|
23
|
-
this.clear();
|
|
24
23
|
this.language = language;
|
|
24
|
+
this.pageInfo = {};
|
|
25
|
+
this.totalItems = new Map();
|
|
26
|
+
this.uniqueMap = new Map();
|
|
27
|
+
if (!globalConfig[this.databasePath])
|
|
28
|
+
globalConfig[this.databasePath] = { tables: new Map() };
|
|
25
29
|
if (!process.env.INIBASE_SECRET) {
|
|
26
30
|
if (existsSync(".env") &&
|
|
27
31
|
readFileSync(".env").includes("INIBASE_SECRET="))
|
|
@@ -110,12 +114,6 @@ export default class Inibase {
|
|
|
110
114
|
error.name = name;
|
|
111
115
|
return error;
|
|
112
116
|
}
|
|
113
|
-
clear() {
|
|
114
|
-
globalConfig[this.databasePath] = { tables: new Map() };
|
|
115
|
-
this.totalItems = new Map();
|
|
116
|
-
this.pageInfo = {};
|
|
117
|
-
this.uniqueMap = new Map();
|
|
118
|
-
}
|
|
119
117
|
getFileExtension(tableName) {
|
|
120
118
|
let mainExtension = this.fileExtension;
|
|
121
119
|
// TODO: ADD ENCRYPTION
|
|
@@ -141,7 +139,7 @@ export default class Inibase {
|
|
|
141
139
|
*
|
|
142
140
|
* @param {string} tableName
|
|
143
141
|
* @param {Schema} [schema]
|
|
144
|
-
* @param {
|
|
142
|
+
* @param {TableConfig} [config]
|
|
145
143
|
*/
|
|
146
144
|
async createTable(tableName, schema, config) {
|
|
147
145
|
const tablePath = join(this.databasePath, tableName);
|
|
@@ -187,7 +185,7 @@ export default class Inibase {
|
|
|
187
185
|
*
|
|
188
186
|
* @param {string} tableName
|
|
189
187
|
* @param {Schema} [schema]
|
|
190
|
-
* @param {(
|
|
188
|
+
* @param {(TableConfig&{name?: string})} [config]
|
|
191
189
|
*/
|
|
192
190
|
async updateTable(tableName, schema, config) {
|
|
193
191
|
const table = await this.getTable(tableName);
|
|
@@ -436,28 +434,30 @@ export default class Inibase {
|
|
|
436
434
|
}, {});
|
|
437
435
|
return Object.keys(cleanedObject).length > 0 ? cleanedObject : null;
|
|
438
436
|
}
|
|
439
|
-
formatField(value,
|
|
437
|
+
formatField(value, field, _formatOnlyAvailiableKeys) {
|
|
440
438
|
if (value === null || value === undefined)
|
|
441
439
|
return value;
|
|
442
|
-
if (Array.isArray(
|
|
443
|
-
|
|
444
|
-
if (Array.isArray(value) && !["array", "json"].includes(
|
|
440
|
+
if (Array.isArray(field.type))
|
|
441
|
+
field.type = Utils.detectFieldType(value, field.type) ?? field.type[0];
|
|
442
|
+
if (Array.isArray(value) && !["array", "json"].includes(field.type))
|
|
445
443
|
value = value[0];
|
|
446
|
-
switch (
|
|
444
|
+
switch (field.type) {
|
|
447
445
|
case "array":
|
|
448
|
-
if (!
|
|
446
|
+
if (!field.children)
|
|
449
447
|
return null;
|
|
450
448
|
if (!Array.isArray(value))
|
|
451
449
|
value = [value];
|
|
452
|
-
if (Utils.isArrayOfObjects(
|
|
453
|
-
return this.formatData(value,
|
|
454
|
-
}
|
|
450
|
+
if (Utils.isArrayOfObjects(field.children))
|
|
451
|
+
return this.formatData(value, field.children, _formatOnlyAvailiableKeys);
|
|
455
452
|
if (!value.length)
|
|
456
453
|
return null;
|
|
457
|
-
return value.map((_value) => this.formatField(_value,
|
|
454
|
+
return value.map((_value) => this.formatField(_value, {
|
|
455
|
+
...field,
|
|
456
|
+
type: field.children,
|
|
457
|
+
}));
|
|
458
458
|
case "object":
|
|
459
|
-
if (Utils.isArrayOfObjects(
|
|
460
|
-
return this.formatData(value,
|
|
459
|
+
if (Utils.isArrayOfObjects(field.children))
|
|
460
|
+
return this.formatData(value, field.children, _formatOnlyAvailiableKeys);
|
|
461
461
|
break;
|
|
462
462
|
case "table":
|
|
463
463
|
if (Utils.isObject(value)) {
|
|
@@ -569,7 +569,7 @@ export default class Inibase {
|
|
|
569
569
|
RETURN[field.key] = this.getDefaultValue(field);
|
|
570
570
|
continue;
|
|
571
571
|
}
|
|
572
|
-
RETURN[field.key] = this.formatField(clonedData[field.key], field
|
|
572
|
+
RETURN[field.key] = this.formatField(clonedData[field.key], field, formatOnlyAvailiableKeys);
|
|
573
573
|
}
|
|
574
574
|
return RETURN;
|
|
575
575
|
}
|
package/dist/utils.server.d.ts
CHANGED
|
@@ -49,8 +49,7 @@ export declare const hashString: (str: string) => string;
|
|
|
49
49
|
* @param operator - The comparison operator (e.g., '=', '!=', '>', '<', '>=', '<=', '[]', '![]', '*', '!*').
|
|
50
50
|
* @param originalValue - The value to compare, can be a single value or an array of values.
|
|
51
51
|
* @param comparedValue - The value or values to compare against.
|
|
52
|
-
* @param
|
|
53
|
-
* @param fieldChildrenType - Optional type for child elements in array inputs.
|
|
52
|
+
* @param fieldType - Optional type of the field.
|
|
54
53
|
* @returns boolean - Result of the comparison operation.
|
|
55
54
|
*
|
|
56
55
|
* Note: Handles various data types and comparison logic, including special handling for passwords and regex patterns.
|
package/dist/utils.server.js
CHANGED
|
@@ -124,8 +124,7 @@ export const hashString = (str) => createHash("sha256").update(str).digest("hex"
|
|
|
124
124
|
* @param operator - The comparison operator (e.g., '=', '!=', '>', '<', '>=', '<=', '[]', '![]', '*', '!*').
|
|
125
125
|
* @param originalValue - The value to compare, can be a single value or an array of values.
|
|
126
126
|
* @param comparedValue - The value or values to compare against.
|
|
127
|
-
* @param
|
|
128
|
-
* @param fieldChildrenType - Optional type for child elements in array inputs.
|
|
127
|
+
* @param fieldType - Optional type of the field.
|
|
129
128
|
* @returns boolean - Result of the comparison operation.
|
|
130
129
|
*
|
|
131
130
|
* Note: Handles various data types and comparison logic, including special handling for passwords and regex patterns.
|