inibase 1.0.0-rc.50 → 1.0.0-rc.51
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/config.d.ts +3 -5
- package/dist/config.js +3 -5
- package/dist/file.d.ts +1 -32
- package/dist/file.js +65 -79
- package/dist/file.thread.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +149 -157
- package/dist/utils.d.ts +0 -25
- package/dist/utils.js +23 -51
- package/dist/utils.server.d.ts +1 -16
- package/dist/utils.server.js +4 -19
- package/package.json +1 -1
package/dist/utils.d.ts
CHANGED
|
@@ -181,29 +181,4 @@ export declare function FormatObjectCriteriaValue(value: string, isParentArray?:
|
|
|
181
181
|
type ValidKey = number | string;
|
|
182
182
|
export declare const swapKeyValue: <K extends ValidKey, V extends ValidKey>(object: Record<K, V>) => Record<V, K>;
|
|
183
183
|
export declare function getField(keyPath: string, schema: Schema): Field | null;
|
|
184
|
-
export default class Utils {
|
|
185
|
-
static isNumber: (input: any) => input is number;
|
|
186
|
-
static isObject: (obj: any) => obj is Record<any, any>;
|
|
187
|
-
static isEmail: (input: any) => boolean;
|
|
188
|
-
static isDate: (input: any) => boolean;
|
|
189
|
-
static isURL: (input: any) => boolean;
|
|
190
|
-
static isValidID: (input: any) => input is string;
|
|
191
|
-
static isPassword: (input: any) => input is string;
|
|
192
|
-
static deepMerge: (target: any, source: any) => any;
|
|
193
|
-
static combineObjects: (arr: Record<string, any>[]) => Record<string, any>;
|
|
194
|
-
static isArrayOfObjects: (input: any) => input is Record<any, any>[];
|
|
195
|
-
static findChangedProperties: (obj1: Record<string, string>, obj2: Record<string, string>) => Record<string, string> | null;
|
|
196
|
-
static detectFieldType: (input: any, availableTypes: FieldType[]) => FieldType | undefined;
|
|
197
|
-
static isArrayOfArrays: (input: any) => input is any[][];
|
|
198
|
-
static isBoolean: (input: any) => input is boolean;
|
|
199
|
-
static isString: (input: any) => input is string;
|
|
200
|
-
static isHTML: (input: any) => boolean;
|
|
201
|
-
static isIP: (input: any) => boolean;
|
|
202
|
-
static validateFieldType: (value: any, fieldType: FieldType | FieldType[], fieldChildrenType?: FieldType | FieldType[] | undefined) => boolean;
|
|
203
|
-
static isArrayOfNulls: (input: any) => input is null[] | null[][];
|
|
204
|
-
static FormatObjectCriteriaValue: typeof FormatObjectCriteriaValue;
|
|
205
|
-
static swapKeyValue: <K extends ValidKey, V extends ValidKey>(object: Record<K, V>) => Record<V, K>;
|
|
206
|
-
static getField: typeof getField;
|
|
207
|
-
static isJSON: (str: string) => boolean;
|
|
208
|
-
}
|
|
209
184
|
export {};
|
package/dist/utils.js
CHANGED
|
@@ -47,7 +47,7 @@ export const isObject = (obj) => obj != null &&
|
|
|
47
47
|
*/
|
|
48
48
|
export const deepMerge = (target, source) => {
|
|
49
49
|
for (const key in source) {
|
|
50
|
-
if (
|
|
50
|
+
if (Object.hasOwn(source, key)) {
|
|
51
51
|
if (isObject(source[key]) && isObject(target[key]))
|
|
52
52
|
target[key] = deepMerge(target[key], source[key]);
|
|
53
53
|
else
|
|
@@ -68,7 +68,7 @@ export const combineObjects = (arr) => {
|
|
|
68
68
|
const result = {};
|
|
69
69
|
for (const obj of arr) {
|
|
70
70
|
for (const key in obj) {
|
|
71
|
-
if (
|
|
71
|
+
if (Object.hasOwn(obj, key)) {
|
|
72
72
|
const existingValue = result[key];
|
|
73
73
|
const newValue = obj[key];
|
|
74
74
|
if (isObject(existingValue) &&
|
|
@@ -106,7 +106,7 @@ export const combineObjects = (arr) => {
|
|
|
106
106
|
*
|
|
107
107
|
* Note: Validates that the input can be parsed as a float and that subtracting zero results in a number, ensuring it's a numeric value.
|
|
108
108
|
*/
|
|
109
|
-
export const isNumber = (input) => !isNaN(parseFloat(input)) && !isNaN(input - 0);
|
|
109
|
+
export const isNumber = (input) => !Number.isNaN(Number.parseFloat(input)) && !Number.isNaN(input - 0);
|
|
110
110
|
/**
|
|
111
111
|
* Checks if the input is a valid email format.
|
|
112
112
|
*
|
|
@@ -132,16 +132,14 @@ export const isURL = (input) => {
|
|
|
132
132
|
input.startsWith("tel:") ||
|
|
133
133
|
input.startsWith("mailto:"))
|
|
134
134
|
return true;
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
return !!pattern.test(input);
|
|
144
|
-
}
|
|
135
|
+
const pattern = new RegExp("^(https?:\\/\\/)?" + // protocol
|
|
136
|
+
"((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|" + // domain name
|
|
137
|
+
"localhost|" + // OR localhost
|
|
138
|
+
"((\\d{1,3}\\.){3}\\d{1,3}))" + // OR ip (v4) address
|
|
139
|
+
"(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*" + // port and path
|
|
140
|
+
"(\\?[;&a-z\\d%_.~+=-]*)?" + // query string
|
|
141
|
+
"(\\#[-a-z\\d_]*)?$", "i"); // fragment locator
|
|
142
|
+
return !!pattern.test(input);
|
|
145
143
|
};
|
|
146
144
|
/**
|
|
147
145
|
* Checks if the input contains HTML tags or entities.
|
|
@@ -200,7 +198,7 @@ export const isPassword = (input) => typeof input === "string" && input.length =
|
|
|
200
198
|
* @param input - The input to be checked, can be of any type.
|
|
201
199
|
* @returns A boolean indicating whether the input is a valid date.
|
|
202
200
|
*/
|
|
203
|
-
export const isDate = (input) => !isNaN(new Date(input).getTime()) || !isNaN(Date.parse(input));
|
|
201
|
+
export const isDate = (input) => !Number.isNaN(new Date(input).getTime()) || !Number.isNaN(Date.parse(input));
|
|
204
202
|
/**
|
|
205
203
|
* Checks if the input is a valid ID.
|
|
206
204
|
*
|
|
@@ -227,7 +225,7 @@ export const isJSON = (str) => str === "null" || str === "undefined" || str[0] =
|
|
|
227
225
|
export const findChangedProperties = (obj1, obj2) => {
|
|
228
226
|
const result = {};
|
|
229
227
|
for (const key1 in obj1)
|
|
230
|
-
if (
|
|
228
|
+
if (Object.hasOwn(obj2, key1) && obj1[key1] !== obj2[key1])
|
|
231
229
|
result[obj1[key1]] = obj2[key1];
|
|
232
230
|
return Object.keys(result).length ? result : null;
|
|
233
231
|
};
|
|
@@ -247,12 +245,12 @@ export const detectFieldType = (input, availableTypes) => {
|
|
|
247
245
|
input === "false") &&
|
|
248
246
|
availableTypes.includes("boolean"))
|
|
249
247
|
return "boolean";
|
|
250
|
-
|
|
248
|
+
if (isNumber(input)) {
|
|
251
249
|
if (availableTypes.includes("table"))
|
|
252
250
|
return "table";
|
|
253
|
-
|
|
251
|
+
if (availableTypes.includes("date"))
|
|
254
252
|
return "date";
|
|
255
|
-
|
|
253
|
+
if (availableTypes.includes("number"))
|
|
256
254
|
return "number";
|
|
257
255
|
}
|
|
258
256
|
else if (availableTypes.includes("table") && isValidID(input))
|
|
@@ -322,15 +320,14 @@ export const validateFieldType = (value, fieldType, fieldChildrenType) => {
|
|
|
322
320
|
// feat: check if id exists
|
|
323
321
|
if (Array.isArray(value))
|
|
324
322
|
return ((isArrayOfObjects(value) &&
|
|
325
|
-
value.every((element) =>
|
|
323
|
+
value.every((element) => Object.hasOwn(element, "id") &&
|
|
326
324
|
(isValidID(element.id) || isNumber(element.id)))) ||
|
|
327
325
|
value.every(isNumber) ||
|
|
328
326
|
isValidID(value));
|
|
329
|
-
|
|
330
|
-
return (
|
|
327
|
+
if (isObject(value))
|
|
328
|
+
return (Object.hasOwn(value, "id") &&
|
|
331
329
|
(isValidID(value.id) || isNumber(value.id)));
|
|
332
|
-
|
|
333
|
-
return isNumber(value) || isValidID(value);
|
|
330
|
+
return isNumber(value) || isValidID(value);
|
|
334
331
|
case "id":
|
|
335
332
|
return isNumber(value) || isValidID(value);
|
|
336
333
|
case "json":
|
|
@@ -371,7 +368,7 @@ export function FormatObjectCriteriaValue(value, isParentArray = false) {
|
|
|
371
368
|
value.slice(3),
|
|
372
369
|
]
|
|
373
370
|
: [
|
|
374
|
-
|
|
371
|
+
`${value.slice(0, 1)}=`,
|
|
375
372
|
value.slice(1),
|
|
376
373
|
];
|
|
377
374
|
case "=":
|
|
@@ -382,7 +379,7 @@ export function FormatObjectCriteriaValue(value, isParentArray = false) {
|
|
|
382
379
|
]
|
|
383
380
|
: [
|
|
384
381
|
value.slice(0, 1),
|
|
385
|
-
|
|
382
|
+
`${value.slice(1)},`,
|
|
386
383
|
];
|
|
387
384
|
case "*":
|
|
388
385
|
return [
|
|
@@ -393,7 +390,7 @@ export function FormatObjectCriteriaValue(value, isParentArray = false) {
|
|
|
393
390
|
return ["=", value];
|
|
394
391
|
}
|
|
395
392
|
}
|
|
396
|
-
export const swapKeyValue = (object) => Object.entries(object).reduce((swapped, [key, value]) => (
|
|
393
|
+
export const swapKeyValue = (object) => Object.entries(object).reduce((swapped, [key, value]) => Object.assign(swapped, { [value]: key }), {});
|
|
397
394
|
export function getField(keyPath, schema) {
|
|
398
395
|
let RETURN = null;
|
|
399
396
|
const keyPathSplited = keyPath.split(".");
|
|
@@ -412,28 +409,3 @@ export function getField(keyPath, schema) {
|
|
|
412
409
|
return null;
|
|
413
410
|
return isArrayOfObjects(RETURN) ? RETURN[0] : RETURN;
|
|
414
411
|
}
|
|
415
|
-
export default class Utils {
|
|
416
|
-
static isNumber = isNumber;
|
|
417
|
-
static isObject = isObject;
|
|
418
|
-
static isEmail = isEmail;
|
|
419
|
-
static isDate = isDate;
|
|
420
|
-
static isURL = isURL;
|
|
421
|
-
static isValidID = isValidID;
|
|
422
|
-
static isPassword = isPassword;
|
|
423
|
-
static deepMerge = deepMerge;
|
|
424
|
-
static combineObjects = combineObjects;
|
|
425
|
-
static isArrayOfObjects = isArrayOfObjects;
|
|
426
|
-
static findChangedProperties = findChangedProperties;
|
|
427
|
-
static detectFieldType = detectFieldType;
|
|
428
|
-
static isArrayOfArrays = isArrayOfArrays;
|
|
429
|
-
static isBoolean = isBoolean;
|
|
430
|
-
static isString = isString;
|
|
431
|
-
static isHTML = isHTML;
|
|
432
|
-
static isIP = isIP;
|
|
433
|
-
static validateFieldType = validateFieldType;
|
|
434
|
-
static isArrayOfNulls = isArrayOfNulls;
|
|
435
|
-
static FormatObjectCriteriaValue = FormatObjectCriteriaValue;
|
|
436
|
-
static swapKeyValue = swapKeyValue;
|
|
437
|
-
static getField = getField;
|
|
438
|
-
static isJSON = isJSON;
|
|
439
|
-
}
|
package/dist/utils.server.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ export declare const findLastIdNumber: (schema: Schema, secretKeyOrSalt: string
|
|
|
51
51
|
* @param encodeIDs - If true, IDs will be encoded, else they will remain as numbers.
|
|
52
52
|
* @returns The updated schema with encoded IDs.
|
|
53
53
|
*/
|
|
54
|
-
export declare const addIdToSchema: (schema: Schema, oldIndex: number
|
|
54
|
+
export declare const addIdToSchema: (schema: Schema, oldIndex: number, secretKeyOrSalt: string | number | Buffer, encodeIDs?: boolean) => import("./index.js").Field[];
|
|
55
55
|
export declare const encodeSchemaID: (schema: Schema, secretKeyOrSalt: string | number | Buffer) => Schema;
|
|
56
56
|
export declare const hashString: (str: string) => string;
|
|
57
57
|
/**
|
|
@@ -92,18 +92,3 @@ export declare const isArrayEqual: (originalValue: string | number | boolean | n
|
|
|
92
92
|
* @returns boolean - Result of the wildcard pattern matching.
|
|
93
93
|
*/
|
|
94
94
|
export declare const isWildcardMatch: (originalValue: string | number | boolean | null | (string | number | boolean | null)[], comparedAtValue: string | number | boolean | null | (string | number | boolean | null)[]) => boolean;
|
|
95
|
-
export default class UtilsServer {
|
|
96
|
-
static encodeID: (id: string | number, secretKeyOrSalt: string | number | Buffer) => string;
|
|
97
|
-
static decodeID: (input: string, secretKeyOrSalt: string | number | Buffer) => number;
|
|
98
|
-
static hashPassword: (password: string) => string;
|
|
99
|
-
static comparePassword: (hashedPassword: string, inputPassword: string) => boolean;
|
|
100
|
-
static findLastIdNumber: (schema: Schema, secretKeyOrSalt: string | number | Buffer) => number;
|
|
101
|
-
static addIdToSchema: (schema: Schema, oldIndex: number | undefined, secretKeyOrSalt: string | number | Buffer, encodeIDs?: boolean | undefined) => import("./index.js").Field[];
|
|
102
|
-
static hashString: (str: string) => string;
|
|
103
|
-
static exec: typeof execAsync.__promisify__;
|
|
104
|
-
static compare: (operator: ComparisonOperator, originalValue: string | number | boolean | (string | number | boolean | null)[] | null, comparedAtValue: string | number | boolean | (string | number | boolean | null)[] | null, fieldType?: FieldType | FieldType[] | undefined, fieldChildrenType?: FieldType | FieldType[] | undefined) => boolean;
|
|
105
|
-
static isEqual: (originalValue: string | number | boolean | (string | number | boolean | null)[] | null, comparedAtValue: string | number | boolean | (string | number | boolean | null)[] | null, fieldType?: FieldType | FieldType[] | undefined) => boolean;
|
|
106
|
-
static isArrayEqual: (originalValue: string | number | boolean | (string | number | boolean | null)[] | null, comparedAtValue: string | number | boolean | (string | number | boolean | null)[] | null) => boolean;
|
|
107
|
-
static isWildcardMatch: (originalValue: string | number | boolean | (string | number | boolean | null)[] | null, comparedAtValue: string | number | boolean | (string | number | boolean | null)[] | null) => boolean;
|
|
108
|
-
static encodeSchemaID: (schema: Schema, secretKeyOrSalt: string | number | Buffer) => Schema;
|
|
109
|
-
}
|
package/dist/utils.server.js
CHANGED
|
@@ -42,7 +42,7 @@ export const encodeID = (id, secretKeyOrSalt) => {
|
|
|
42
42
|
if (Buffer.isBuffer(secretKeyOrSalt))
|
|
43
43
|
cipher = createCipheriv("aes-256-cbc", secretKeyOrSalt, secretKeyOrSalt.subarray(0, 16));
|
|
44
44
|
else {
|
|
45
|
-
const salt = scryptSync(secretKeyOrSalt.toString(),
|
|
45
|
+
const salt = scryptSync(secretKeyOrSalt.toString(), `${process.env.INIBASE_SECRET ?? "inibase"}_salt`, 32);
|
|
46
46
|
cipher = createCipheriv("aes-256-cbc", salt, salt.subarray(0, 16));
|
|
47
47
|
}
|
|
48
48
|
return cipher.update(id.toString(), "utf8", "hex") + cipher.final("hex");
|
|
@@ -59,7 +59,7 @@ export const decodeID = (input, secretKeyOrSalt) => {
|
|
|
59
59
|
if (Buffer.isBuffer(secretKeyOrSalt))
|
|
60
60
|
decipher = createDecipheriv("aes-256-cbc", secretKeyOrSalt, secretKeyOrSalt.subarray(0, 16));
|
|
61
61
|
else {
|
|
62
|
-
const salt = scryptSync(secretKeyOrSalt.toString(),
|
|
62
|
+
const salt = scryptSync(secretKeyOrSalt.toString(), `${process.env.INIBASE_SECRET ?? "inibase"}_salt`, 32);
|
|
63
63
|
decipher = createDecipheriv("aes-256-cbc", salt, salt.subarray(0, 16));
|
|
64
64
|
}
|
|
65
65
|
return Number(decipher.update(input, "hex", "utf8") + decipher.final("utf8"));
|
|
@@ -94,7 +94,7 @@ export const findLastIdNumber = (schema, secretKeyOrSalt) => Math.max(..._flatte
|
|
|
94
94
|
* @param encodeIDs - If true, IDs will be encoded, else they will remain as numbers.
|
|
95
95
|
* @returns The updated schema with encoded IDs.
|
|
96
96
|
*/
|
|
97
|
-
export const addIdToSchema = (schema, oldIndex
|
|
97
|
+
export const addIdToSchema = (schema, oldIndex, secretKeyOrSalt, encodeIDs) => schema.map((field) => {
|
|
98
98
|
if (!field.id) {
|
|
99
99
|
oldIndex++;
|
|
100
100
|
field.id = encodeIDs ? encodeID(oldIndex, secretKeyOrSalt) : oldIndex;
|
|
@@ -251,21 +251,6 @@ export const isArrayEqual = (originalValue, comparedAtValue) => {
|
|
|
251
251
|
export const isWildcardMatch = (originalValue, comparedAtValue) => {
|
|
252
252
|
const wildcardPattern = `^${(String(comparedAtValue).includes("%")
|
|
253
253
|
? String(comparedAtValue)
|
|
254
|
-
:
|
|
254
|
+
: `%${String(comparedAtValue)}%`).replace(/%/g, ".*")}$`;
|
|
255
255
|
return new RegExp(wildcardPattern, "i").test(String(originalValue));
|
|
256
256
|
};
|
|
257
|
-
export default class UtilsServer {
|
|
258
|
-
static encodeID = encodeID;
|
|
259
|
-
static decodeID = decodeID;
|
|
260
|
-
static hashPassword = hashPassword;
|
|
261
|
-
static comparePassword = comparePassword;
|
|
262
|
-
static findLastIdNumber = findLastIdNumber;
|
|
263
|
-
static addIdToSchema = addIdToSchema;
|
|
264
|
-
static hashString = hashString;
|
|
265
|
-
static exec = exec;
|
|
266
|
-
static compare = compare;
|
|
267
|
-
static isEqual = isEqual;
|
|
268
|
-
static isArrayEqual = isArrayEqual;
|
|
269
|
-
static isWildcardMatch = isWildcardMatch;
|
|
270
|
-
static encodeSchemaID = encodeSchemaID;
|
|
271
|
-
}
|