inibase 1.0.0-rc.26 → 1.0.0-rc.28

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.
@@ -47,12 +47,56 @@ export declare const findLastIdNumber: (schema: Schema, secretKeyOrSalt: string
47
47
  * @param secretKeyOrSalt - The secret key or salt for encoding IDs, can be a string, number, or Buffer.
48
48
  * @returns The updated schema with encoded IDs.
49
49
  */
50
- export declare const addIdToSchema: (schema: Schema, oldIndex: number | undefined, secretKeyOrSalt: string | number | Buffer) => import("./index.js").Field[];
50
+ export declare const addIdToSchema: (schema: Schema, oldIndex: number | undefined, secretKeyOrSalt: string | number | Buffer) => (({
51
+ id?: string | number | undefined;
52
+ key: string;
53
+ required?: boolean | undefined;
54
+ } & {
55
+ type: "string" | "number" | "boolean" | "id" | "url" | "html" | "table" | "email" | "date" | "password" | "ip";
56
+ children?: undefined;
57
+ }) | ({
58
+ id?: string | number | undefined;
59
+ key: string;
60
+ required?: boolean | undefined;
61
+ } & {
62
+ type: "object";
63
+ children: Schema;
64
+ }) | ({
65
+ id?: string | number | undefined;
66
+ key: string;
67
+ required?: boolean | undefined;
68
+ } & {
69
+ type: "array";
70
+ children: "string" | "number" | "boolean" | "object" | "id" | "url" | "html" | "table" | "email" | "date" | "password" | "ip" | Schema | ("string" | "number" | "boolean" | "object" | "id" | "url" | "html" | "table" | "email" | "date" | "password" | "ip")[];
71
+ }))[];
72
+ export declare const hashObject: (obj: any) => string;
51
73
  export default class UtilsServer {
52
74
  static encodeID: (id: string | number, secretKeyOrSalt: string | number | Buffer) => string;
53
75
  static decodeID: (input: string, secretKeyOrSalt: string | number | Buffer) => number;
54
76
  static hashPassword: (password: string) => string;
55
77
  static comparePassword: (hashedPassword: string, inputPassword: string) => boolean;
56
78
  static findLastIdNumber: (schema: Schema, secretKeyOrSalt: string | number | Buffer) => number;
57
- static addIdToSchema: (schema: Schema, oldIndex: number | undefined, secretKeyOrSalt: string | number | Buffer) => import("./index.js").Field[];
79
+ static addIdToSchema: (schema: Schema, oldIndex: number | undefined, secretKeyOrSalt: string | number | Buffer) => (({
80
+ id?: string | number | undefined;
81
+ key: string;
82
+ required?: boolean | undefined;
83
+ } & {
84
+ type: "string" | "number" | "boolean" | "id" | "url" | "html" | "table" | "email" | "date" | "password" | "ip";
85
+ children?: undefined;
86
+ }) | ({
87
+ id?: string | number | undefined;
88
+ key: string;
89
+ required?: boolean | undefined;
90
+ } & {
91
+ type: "object";
92
+ children: Schema;
93
+ }) | ({
94
+ id?: string | number | undefined;
95
+ key: string;
96
+ required?: boolean | undefined;
97
+ } & {
98
+ type: "array";
99
+ children: "string" | "number" | "boolean" | "object" | "id" | "url" | "html" | "table" | "email" | "date" | "password" | "ip" | Schema | ("string" | "number" | "boolean" | "object" | "id" | "url" | "html" | "table" | "email" | "date" | "password" | "ip")[];
100
+ }))[];
101
+ static hashObject: (obj: any) => string;
58
102
  }
@@ -109,6 +109,35 @@ export const addIdToSchema = (schema, oldIndex = 0, secretKeyOrSalt) => schema.m
109
109
  }
110
110
  return field;
111
111
  });
112
+ function sortObject(obj) {
113
+ if (typeof obj !== "object" || obj === null)
114
+ return obj;
115
+ if (Array.isArray(obj))
116
+ return obj.toSorted().map(sortObject);
117
+ const sorted = {};
118
+ const keys = Object.keys(obj).sort();
119
+ const length = keys.length;
120
+ for (let i = 0; i < length; i++) {
121
+ const key = keys[i];
122
+ sorted[key] = sortObject(obj[key]);
123
+ }
124
+ return sorted;
125
+ }
126
+ function stringifyObject(obj) {
127
+ if (typeof obj !== "object" || obj === null)
128
+ return String(obj);
129
+ if (Array.isArray(obj))
130
+ return "[" + obj.map((value) => stringifyObject(value)).join(",") + "]";
131
+ return ("{" +
132
+ Object.keys(obj)
133
+ .toSorted()
134
+ .map((key) => `${key}:${stringifyObject(obj[key])}`)
135
+ .join(",") +
136
+ "}");
137
+ }
138
+ export const hashObject = (obj) => createHash("sha256")
139
+ .update(stringifyObject(sortObject(obj)))
140
+ .digest("hex");
112
141
  export default class UtilsServer {
113
142
  static encodeID = encodeID;
114
143
  static decodeID = decodeID;
@@ -116,4 +145,5 @@ export default class UtilsServer {
116
145
  static comparePassword = comparePassword;
117
146
  static findLastIdNumber = findLastIdNumber;
118
147
  static addIdToSchema = addIdToSchema;
148
+ static hashObject = hashObject;
119
149
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inibase",
3
- "version": "1.0.0-rc.26",
3
+ "version": "1.0.0-rc.28",
4
4
  "author": {
5
5
  "name": "Karim Amahtil",
6
6
  "email": "karim.amahtil@gmail.com"
@@ -62,12 +62,10 @@
62
62
  "@types/node": "^20.10.4",
63
63
  "typescript": "^5.3.3"
64
64
  },
65
- "dependencies": {
66
- "csv-parser": "^3.0.0"
67
- },
68
65
  "scripts": {
69
66
  "build": "npx tsc",
70
67
  "test": "npx tsx watch --expose-gc --env-file=.env ./index.test",
71
- "benchmark": "npx tsx watch --expose-gc --env-file=.env ./benchmark"
68
+ "benchmark:single": "npx tsx watch --expose-gc --env-file=.env ./benchmark/single",
69
+ "benchmark:bulk": "npx tsx watch --expose-gc --env-file=.env ./benchmark/bulk"
72
70
  }
73
71
  }