inibase 1.0.0-rc.110 → 1.0.0-rc.112
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/index.js +34 -41
- package/dist/utils.server.d.ts +4 -2
- package/dist/utils.server.js +4 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -111,9 +111,9 @@ export default class Inibase {
|
|
|
111
111
|
await writeFile(join(tablePath, ".prepend.config"), "");
|
|
112
112
|
}
|
|
113
113
|
if (schema) {
|
|
114
|
-
const
|
|
115
|
-
await writeFile(join(tablePath, "schema.json"), JSON.stringify(UtilsServer.addIdToSchema(schema,
|
|
116
|
-
await writeFile(join(tablePath, `${
|
|
114
|
+
const lastSchemaID = { value: 0 };
|
|
115
|
+
await writeFile(join(tablePath, "schema.json"), JSON.stringify(UtilsServer.addIdToSchema(schema, lastSchemaID, this.salt), null, 2));
|
|
116
|
+
await writeFile(join(tablePath, `${lastSchemaID.value}.schema`), "");
|
|
117
117
|
}
|
|
118
118
|
else
|
|
119
119
|
await writeFile(join(tablePath, "0.schema"), "");
|
|
@@ -140,14 +140,14 @@ export default class Inibase {
|
|
|
140
140
|
// remove id from schema
|
|
141
141
|
schema = schema.filter(({ key }) => !["id", "createdAt", "updatedAt"].includes(key));
|
|
142
142
|
let schemaIdFilePath;
|
|
143
|
-
for await (const
|
|
144
|
-
schemaIdFilePath =
|
|
145
|
-
const
|
|
146
|
-
? Number(parse(schemaIdFilePath).name)
|
|
147
|
-
|
|
143
|
+
for await (const fileName of glob("*.schema", { cwd: tablePath }))
|
|
144
|
+
schemaIdFilePath = join(tablePath, fileName);
|
|
145
|
+
const lastSchemaID = {
|
|
146
|
+
value: schemaIdFilePath ? Number(parse(schemaIdFilePath).name) : 0,
|
|
147
|
+
};
|
|
148
148
|
if (await File.isExists(join(tablePath, "schema.json"))) {
|
|
149
149
|
// update columns files names based on field id
|
|
150
|
-
schema = UtilsServer.addIdToSchema(schema,
|
|
150
|
+
schema = UtilsServer.addIdToSchema(schema, lastSchemaID, this.salt);
|
|
151
151
|
if (table.schema?.length) {
|
|
152
152
|
const replaceOldPathes = Utils.findChangedProperties(this._schemaToIdsPath(tableName, table.schema), this._schemaToIdsPath(tableName, schema));
|
|
153
153
|
if (replaceOldPathes)
|
|
@@ -158,12 +158,12 @@ export default class Inibase {
|
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
else
|
|
161
|
-
schema = UtilsServer.addIdToSchema(schema,
|
|
161
|
+
schema = UtilsServer.addIdToSchema(schema, lastSchemaID, this.salt);
|
|
162
162
|
await writeFile(join(tablePath, "schema.json"), JSON.stringify(schema, null, 2));
|
|
163
163
|
if (schemaIdFilePath)
|
|
164
|
-
await rename(schemaIdFilePath, join(tablePath, `${
|
|
164
|
+
await rename(schemaIdFilePath, join(tablePath, `${lastSchemaID.value}.schema`));
|
|
165
165
|
else
|
|
166
|
-
await writeFile(join(tablePath, `${
|
|
166
|
+
await writeFile(join(tablePath, `${lastSchemaID.value}.schema`), "");
|
|
167
167
|
}
|
|
168
168
|
if (config) {
|
|
169
169
|
if (config.compression !== undefined &&
|
|
@@ -553,21 +553,10 @@ export default class Inibase {
|
|
|
553
553
|
}
|
|
554
554
|
// Helper function to determine if a field is simple
|
|
555
555
|
isSimpleField(fieldType) {
|
|
556
|
-
const
|
|
557
|
-
"string",
|
|
558
|
-
"number",
|
|
559
|
-
"boolean",
|
|
560
|
-
"date",
|
|
561
|
-
"email",
|
|
562
|
-
"password",
|
|
563
|
-
"html",
|
|
564
|
-
"ip",
|
|
565
|
-
"json",
|
|
566
|
-
"id",
|
|
567
|
-
];
|
|
556
|
+
const complexTypes = ["array", "object", "table"];
|
|
568
557
|
if (Array.isArray(fieldType))
|
|
569
|
-
return fieldType.every((type) => typeof type === "string" &&
|
|
570
|
-
return
|
|
558
|
+
return fieldType.every((type) => typeof type === "string" && !complexTypes.includes(type));
|
|
559
|
+
return !complexTypes.includes(fieldType);
|
|
571
560
|
}
|
|
572
561
|
// Process a simple field (non-recursive)
|
|
573
562
|
async processSimpleField(tableName, field, linesNumber, RETURN, _options, prefix) {
|
|
@@ -911,10 +900,10 @@ export default class Inibase {
|
|
|
911
900
|
if (!schema)
|
|
912
901
|
throw this.Error("NO_SCHEMA", tableName);
|
|
913
902
|
let pagination;
|
|
914
|
-
for await (const
|
|
903
|
+
for await (const paginationFileName of glob("*.pagination", {
|
|
915
904
|
cwd: tablePath,
|
|
916
905
|
}))
|
|
917
|
-
pagination = parse(
|
|
906
|
+
pagination = parse(paginationFileName).name.split("-").map(Number);
|
|
918
907
|
if (!pagination[1])
|
|
919
908
|
return null;
|
|
920
909
|
if (options.columns?.length)
|
|
@@ -1131,8 +1120,8 @@ export default class Inibase {
|
|
|
1131
1120
|
try {
|
|
1132
1121
|
await File.lock(join(tablePath, ".tmp"), keys);
|
|
1133
1122
|
let paginationFilePath;
|
|
1134
|
-
for await (const
|
|
1135
|
-
paginationFilePath =
|
|
1123
|
+
for await (const fileName of glob("*.pagination", { cwd: tablePath }))
|
|
1124
|
+
paginationFilePath = join(tablePath, fileName);
|
|
1136
1125
|
[lastId, this.totalItems[`${tableName}-*`]] = parse(paginationFilePath)
|
|
1137
1126
|
.name.split("-")
|
|
1138
1127
|
.map(Number);
|
|
@@ -1166,7 +1155,7 @@ export default class Inibase {
|
|
|
1166
1155
|
this.totalItems[`${tableName}-*`] += Array.isArray(data)
|
|
1167
1156
|
? data.length
|
|
1168
1157
|
: 1;
|
|
1169
|
-
await rename(
|
|
1158
|
+
await rename(paginationFilePath, join(tablePath, `${lastId}-${this.totalItems[`${tableName}-*`]}.pagination`));
|
|
1170
1159
|
if (returnPostedData)
|
|
1171
1160
|
return this.get(tableName, this.tables[tableName].config.prepend
|
|
1172
1161
|
? Array.isArray(data)
|
|
@@ -1213,10 +1202,10 @@ export default class Inibase {
|
|
|
1213
1202
|
});
|
|
1214
1203
|
try {
|
|
1215
1204
|
await File.lock(join(tablePath, ".tmp"));
|
|
1216
|
-
for await (const
|
|
1205
|
+
for await (const paginationFileName of glob("*.pagination", {
|
|
1217
1206
|
cwd: tablePath,
|
|
1218
1207
|
}))
|
|
1219
|
-
this.totalItems[`${tableName}-*`] = parse(
|
|
1208
|
+
this.totalItems[`${tableName}-*`] = parse(paginationFileName)
|
|
1220
1209
|
.name.split("-")
|
|
1221
1210
|
.map(Number)[1];
|
|
1222
1211
|
await Promise.allSettled(Object.entries(pathesContents).map(async ([path, content]) => renameList.push(await File.replace(path, content, this.totalItems[`${tableName}-*`]))));
|
|
@@ -1299,18 +1288,20 @@ export default class Inibase {
|
|
|
1299
1288
|
await File.lock(join(tablePath, ".tmp"));
|
|
1300
1289
|
let paginationFilePath;
|
|
1301
1290
|
let pagination;
|
|
1302
|
-
for await (const
|
|
1291
|
+
for await (const paginationFileName of glob("*.pagination", {
|
|
1303
1292
|
cwd: tablePath,
|
|
1304
1293
|
})) {
|
|
1305
|
-
paginationFilePath =
|
|
1306
|
-
pagination = parse(
|
|
1294
|
+
paginationFilePath = join(tablePath, paginationFileName);
|
|
1295
|
+
pagination = parse(paginationFileName)
|
|
1296
|
+
.name.split("-")
|
|
1297
|
+
.map(Number);
|
|
1307
1298
|
}
|
|
1308
1299
|
await Promise.all((await readdir(tablePath))
|
|
1309
1300
|
?.filter((fileName) => fileName.endsWith(this.getFileExtension(tableName)))
|
|
1310
1301
|
.map(async (file) => unlink(join(tablePath, file))));
|
|
1311
1302
|
if (this.tables[tableName].config.cache)
|
|
1312
1303
|
await this.clearCache(tableName);
|
|
1313
|
-
await rename(
|
|
1304
|
+
await rename(paginationFilePath, join(tablePath, `${pagination[0]}-0.pagination`));
|
|
1314
1305
|
return true;
|
|
1315
1306
|
}
|
|
1316
1307
|
finally {
|
|
@@ -1332,11 +1323,13 @@ export default class Inibase {
|
|
|
1332
1323
|
await File.lock(join(tablePath, ".tmp"));
|
|
1333
1324
|
let paginationFilePath;
|
|
1334
1325
|
let pagination;
|
|
1335
|
-
for await (const
|
|
1326
|
+
for await (const paginationFileName of glob("*.pagination", {
|
|
1336
1327
|
cwd: tablePath,
|
|
1337
1328
|
})) {
|
|
1338
|
-
paginationFilePath =
|
|
1339
|
-
pagination = parse(
|
|
1329
|
+
paginationFilePath = join(tablePath, paginationFileName);
|
|
1330
|
+
pagination = parse(paginationFileName)
|
|
1331
|
+
.name.split("-")
|
|
1332
|
+
.map(Number);
|
|
1340
1333
|
}
|
|
1341
1334
|
if (pagination[1] &&
|
|
1342
1335
|
pagination[1] - (Array.isArray(where) ? where.length : 1) > 0) {
|
|
@@ -1351,7 +1344,7 @@ export default class Inibase {
|
|
|
1351
1344
|
.map(async (file) => unlink(join(tablePath, file))));
|
|
1352
1345
|
if (this.tables[tableName].config.cache)
|
|
1353
1346
|
await this.clearCache(tableName);
|
|
1354
|
-
await rename(
|
|
1347
|
+
await rename(paginationFilePath, join(tablePath, `${pagination[0]}-${pagination[1] - (Array.isArray(where) ? where.length : 1)}.pagination`));
|
|
1355
1348
|
return true;
|
|
1356
1349
|
}
|
|
1357
1350
|
finally {
|
package/dist/utils.server.d.ts
CHANGED
|
@@ -35,12 +35,14 @@ export declare const findLastIdNumber: (schema: Schema, secretKeyOrSalt: string
|
|
|
35
35
|
* Adds or updates IDs in a schema, encoding them using a provided secret key or salt.
|
|
36
36
|
*
|
|
37
37
|
* @param schema - The schema to update, defined as an array of schema objects.
|
|
38
|
-
* @param
|
|
38
|
+
* @param startWithID - An object containing the starting ID for generating new IDs.
|
|
39
39
|
* @param secretKeyOrSalt - The secret key or salt for encoding IDs, can be a string, number, or Buffer.
|
|
40
40
|
* @param encodeIDs - If true, IDs will be encoded, else they will remain as numbers.
|
|
41
41
|
* @returns The updated schema with encoded IDs.
|
|
42
42
|
*/
|
|
43
|
-
export declare const addIdToSchema: (schema: Schema, startWithID:
|
|
43
|
+
export declare const addIdToSchema: (schema: Schema, startWithID: {
|
|
44
|
+
value: number;
|
|
45
|
+
}, secretKeyOrSalt: string | number | Buffer, encodeIDs?: boolean) => Field[];
|
|
44
46
|
export declare const encodeSchemaID: (schema: Schema, secretKeyOrSalt: string | number | Buffer) => Schema;
|
|
45
47
|
export declare const hashString: (str: string) => string;
|
|
46
48
|
/**
|
package/dist/utils.server.js
CHANGED
|
@@ -88,7 +88,7 @@ export const findLastIdNumber = (schema, secretKeyOrSalt) => Math.max(...extract
|
|
|
88
88
|
* Adds or updates IDs in a schema, encoding them using a provided secret key or salt.
|
|
89
89
|
*
|
|
90
90
|
* @param schema - The schema to update, defined as an array of schema objects.
|
|
91
|
-
* @param
|
|
91
|
+
* @param startWithID - An object containing the starting ID for generating new IDs.
|
|
92
92
|
* @param secretKeyOrSalt - The secret key or salt for encoding IDs, can be a string, number, or Buffer.
|
|
93
93
|
* @param encodeIDs - If true, IDs will be encoded, else they will remain as numbers.
|
|
94
94
|
* @returns The updated schema with encoded IDs.
|
|
@@ -96,10 +96,10 @@ export const findLastIdNumber = (schema, secretKeyOrSalt) => Math.max(...extract
|
|
|
96
96
|
export const addIdToSchema = (schema, startWithID, secretKeyOrSalt, encodeIDs) => {
|
|
97
97
|
function _addIdToField(field) {
|
|
98
98
|
if (!field.id) {
|
|
99
|
-
startWithID++;
|
|
99
|
+
startWithID.value++;
|
|
100
100
|
field.id = encodeIDs
|
|
101
|
-
? encodeID(startWithID, secretKeyOrSalt)
|
|
102
|
-
: startWithID;
|
|
101
|
+
? encodeID(startWithID.value, secretKeyOrSalt)
|
|
102
|
+
: startWithID.value;
|
|
103
103
|
}
|
|
104
104
|
else {
|
|
105
105
|
if (isValidID(field.id)) {
|