inibase 1.0.0-rc.60 → 1.0.0-rc.61
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/README.md +111 -78
- package/dist/file.d.ts +3 -3
- package/dist/file.js +42 -44
- package/dist/index.d.ts +20 -11
- package/dist/index.js +206 -156
- package/dist/utils.d.ts +1 -3
- package/dist/utils.js +37 -1
- package/dist/utils.server.d.ts +5 -0
- package/dist/utils.server.js +6 -3
- package/package.json +1 -1
package/dist/utils.d.ts
CHANGED
|
@@ -169,11 +169,9 @@ export declare function FormatObjectCriteriaValue(value: string, isParentArray?:
|
|
|
169
169
|
ComparisonOperator,
|
|
170
170
|
string | number | boolean | null | (string | number | null)[]
|
|
171
171
|
];
|
|
172
|
-
type ValidKey = number | string;
|
|
173
|
-
export declare const swapKeyValue: <K extends ValidKey, V extends ValidKey>(object: Record<K, V>) => Record<V, K>;
|
|
174
172
|
export declare function getField(keyPath: string, schema: Schema): Field | null;
|
|
175
173
|
export declare function setField(keyPath: string, schema: Schema, field: Omit<Field, "key" | "type"> & {
|
|
176
174
|
key?: string;
|
|
177
175
|
type?: FieldType | FieldType[];
|
|
178
176
|
}): Field | null | undefined;
|
|
179
|
-
export
|
|
177
|
+
export declare function unsetField(keyPath: string, schema: Schema): Field | null | undefined;
|
package/dist/utils.js
CHANGED
|
@@ -346,7 +346,6 @@ export function FormatObjectCriteriaValue(value, isParentArray = false) {
|
|
|
346
346
|
return ["=", value];
|
|
347
347
|
}
|
|
348
348
|
}
|
|
349
|
-
export const swapKeyValue = (object) => Object.entries(object).reduce((swapped, [key, value]) => Object.assign(swapped, { [value]: key }), {});
|
|
350
349
|
export function getField(keyPath, schema) {
|
|
351
350
|
let RETURN = null;
|
|
352
351
|
const keyPathSplited = keyPath.split(".");
|
|
@@ -381,3 +380,40 @@ export function setField(keyPath, schema, field) {
|
|
|
381
380
|
schema = foundItem.children;
|
|
382
381
|
}
|
|
383
382
|
}
|
|
383
|
+
export function unsetField(keyPath, schema) {
|
|
384
|
+
const keyPathSplited = keyPath.split(".");
|
|
385
|
+
let parent = null;
|
|
386
|
+
let targetIndex;
|
|
387
|
+
for (const [index, key] of keyPathSplited.entries()) {
|
|
388
|
+
const foundItem = schema.find((item) => item.key === key);
|
|
389
|
+
if (!foundItem)
|
|
390
|
+
return null;
|
|
391
|
+
if (index === keyPathSplited.length - 1) {
|
|
392
|
+
if (parent) {
|
|
393
|
+
if (Array.isArray(parent)) {
|
|
394
|
+
if (targetIndex !== undefined)
|
|
395
|
+
parent.splice(targetIndex, 1);
|
|
396
|
+
}
|
|
397
|
+
else
|
|
398
|
+
delete parent[key];
|
|
399
|
+
}
|
|
400
|
+
else {
|
|
401
|
+
const indexToRemove = schema.indexOf(foundItem);
|
|
402
|
+
if (indexToRemove !== -1)
|
|
403
|
+
schema.splice(indexToRemove, 1);
|
|
404
|
+
}
|
|
405
|
+
return foundItem;
|
|
406
|
+
}
|
|
407
|
+
if ((foundItem.type === "array" || foundItem.type === "object") &&
|
|
408
|
+
foundItem.children &&
|
|
409
|
+
isArrayOfObjects(foundItem.children)) {
|
|
410
|
+
parent = foundItem.children;
|
|
411
|
+
targetIndex = schema.indexOf(foundItem);
|
|
412
|
+
schema = foundItem.children;
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
parent = foundItem;
|
|
416
|
+
targetIndex = undefined;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
package/dist/utils.server.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
4
|
import type { ComparisonOperator, FieldType, Schema } from "./index.js";
|
|
4
5
|
import { exec as execAsync } from "node:child_process";
|
|
6
|
+
import { gunzip as gunzipAsync, gzip as gzipAsync } from "node:zlib";
|
|
5
7
|
export declare const exec: typeof execAsync.__promisify__;
|
|
8
|
+
export declare const gzip: typeof gzipAsync.__promisify__;
|
|
9
|
+
export declare const gunzip: typeof gunzipAsync.__promisify__;
|
|
6
10
|
/**
|
|
7
11
|
* Generates a hashed password using SHA-256.
|
|
8
12
|
*
|
|
@@ -34,6 +38,7 @@ export declare const encodeID: (id: number | string, secretKeyOrSalt: string | n
|
|
|
34
38
|
* @returns The decoded ID as a number.
|
|
35
39
|
*/
|
|
36
40
|
export declare const decodeID: (input: string, secretKeyOrSalt: string | number | Buffer) => number;
|
|
41
|
+
export declare const flattenSchema: (schema: Schema, secretKeyOrSalt: string | number | Buffer) => number[];
|
|
37
42
|
/**
|
|
38
43
|
* Finds the last ID number in a schema, potentially decoding it if encrypted.
|
|
39
44
|
*
|
package/dist/utils.server.js
CHANGED
|
@@ -2,7 +2,10 @@ import { createCipheriv, createDecipheriv, randomBytes, scryptSync, createHash,
|
|
|
2
2
|
import { detectFieldType, isArrayOfObjects, isNumber, isPassword, isValidID, } from "./utils.js";
|
|
3
3
|
import { promisify } from "node:util";
|
|
4
4
|
import { exec as execAsync } from "node:child_process";
|
|
5
|
+
import { gunzip as gunzipAsync, gzip as gzipAsync } from "node:zlib";
|
|
5
6
|
export const exec = promisify(execAsync);
|
|
7
|
+
export const gzip = promisify(gzipAsync);
|
|
8
|
+
export const gunzip = promisify(gunzipAsync);
|
|
6
9
|
/**
|
|
7
10
|
* Generates a hashed password using SHA-256.
|
|
8
11
|
*
|
|
@@ -65,7 +68,7 @@ export const decodeID = (input, secretKeyOrSalt) => {
|
|
|
65
68
|
return Number(decipher.update(input, "hex", "utf8") + decipher.final("utf8"));
|
|
66
69
|
};
|
|
67
70
|
// Function to recursively flatten an array of objects and their nested children
|
|
68
|
-
const
|
|
71
|
+
export const flattenSchema = (schema, secretKeyOrSalt) => {
|
|
69
72
|
const result = [];
|
|
70
73
|
for (const field of schema) {
|
|
71
74
|
if (field.id)
|
|
@@ -73,7 +76,7 @@ const _flattenSchema = (schema, secretKeyOrSalt) => {
|
|
|
73
76
|
? field.id
|
|
74
77
|
: decodeID(field.id, secretKeyOrSalt));
|
|
75
78
|
if (field.children && isArrayOfObjects(field.children))
|
|
76
|
-
result.push(...
|
|
79
|
+
result.push(...flattenSchema(field.children, secretKeyOrSalt));
|
|
77
80
|
}
|
|
78
81
|
return result;
|
|
79
82
|
};
|
|
@@ -84,7 +87,7 @@ const _flattenSchema = (schema, secretKeyOrSalt) => {
|
|
|
84
87
|
* @param secretKeyOrSalt - The secret key or salt for decoding an encrypted ID, can be a string, number, or Buffer.
|
|
85
88
|
* @returns The last ID number in the schema, decoded if necessary.
|
|
86
89
|
*/
|
|
87
|
-
export const findLastIdNumber = (schema, secretKeyOrSalt) => Math.max(...
|
|
90
|
+
export const findLastIdNumber = (schema, secretKeyOrSalt) => Math.max(...flattenSchema(schema, secretKeyOrSalt));
|
|
88
91
|
/**
|
|
89
92
|
* Adds or updates IDs in a schema, encoding them using a provided secret key or salt.
|
|
90
93
|
*
|