inibase 1.0.0-rc.111 → 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 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 lastSchemaId = 0;
115
- await writeFile(join(tablePath, "schema.json"), JSON.stringify(UtilsServer.addIdToSchema(schema, lastSchemaId, this.salt), null, 2));
116
- await writeFile(join(tablePath, `${lastSchemaId}.schema`), "");
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 filePath of glob("*.schema", { cwd: this.databasePath }))
144
- schemaIdFilePath = filePath;
145
- const lastSchemaId = schemaIdFilePath
146
- ? Number(parse(schemaIdFilePath).name)
147
- : 0;
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, lastSchemaId, this.salt);
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, lastSchemaId, this.salt);
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, `${lastSchemaId}.schema`));
164
+ await rename(schemaIdFilePath, join(tablePath, `${lastSchemaID.value}.schema`));
165
165
  else
166
- await writeFile(join(tablePath, `${lastSchemaId}.schema`), "");
166
+ await writeFile(join(tablePath, `${lastSchemaID.value}.schema`), "");
167
167
  }
168
168
  if (config) {
169
169
  if (config.compression !== undefined &&
@@ -900,10 +900,10 @@ export default class Inibase {
900
900
  if (!schema)
901
901
  throw this.Error("NO_SCHEMA", tableName);
902
902
  let pagination;
903
- for await (const paginationFilePath of glob("*.pagination", {
903
+ for await (const paginationFileName of glob("*.pagination", {
904
904
  cwd: tablePath,
905
905
  }))
906
- pagination = parse(paginationFilePath).name.split("-").map(Number);
906
+ pagination = parse(paginationFileName).name.split("-").map(Number);
907
907
  if (!pagination[1])
908
908
  return null;
909
909
  if (options.columns?.length)
@@ -1120,8 +1120,8 @@ export default class Inibase {
1120
1120
  try {
1121
1121
  await File.lock(join(tablePath, ".tmp"), keys);
1122
1122
  let paginationFilePath;
1123
- for await (const filePath of glob("*.pagination", { cwd: tablePath }))
1124
- paginationFilePath = filePath;
1123
+ for await (const fileName of glob("*.pagination", { cwd: tablePath }))
1124
+ paginationFilePath = join(tablePath, fileName);
1125
1125
  [lastId, this.totalItems[`${tableName}-*`]] = parse(paginationFilePath)
1126
1126
  .name.split("-")
1127
1127
  .map(Number);
@@ -1155,7 +1155,7 @@ export default class Inibase {
1155
1155
  this.totalItems[`${tableName}-*`] += Array.isArray(data)
1156
1156
  ? data.length
1157
1157
  : 1;
1158
- await rename(join(tablePath, paginationFilePath), join(tablePath, `${lastId}-${this.totalItems[`${tableName}-*`]}.pagination`));
1158
+ await rename(paginationFilePath, join(tablePath, `${lastId}-${this.totalItems[`${tableName}-*`]}.pagination`));
1159
1159
  if (returnPostedData)
1160
1160
  return this.get(tableName, this.tables[tableName].config.prepend
1161
1161
  ? Array.isArray(data)
@@ -1202,10 +1202,10 @@ export default class Inibase {
1202
1202
  });
1203
1203
  try {
1204
1204
  await File.lock(join(tablePath, ".tmp"));
1205
- for await (const paginationFilePath of glob("*.pagination", {
1205
+ for await (const paginationFileName of glob("*.pagination", {
1206
1206
  cwd: tablePath,
1207
1207
  }))
1208
- this.totalItems[`${tableName}-*`] = parse(paginationFilePath)
1208
+ this.totalItems[`${tableName}-*`] = parse(paginationFileName)
1209
1209
  .name.split("-")
1210
1210
  .map(Number)[1];
1211
1211
  await Promise.allSettled(Object.entries(pathesContents).map(async ([path, content]) => renameList.push(await File.replace(path, content, this.totalItems[`${tableName}-*`]))));
@@ -1288,18 +1288,20 @@ export default class Inibase {
1288
1288
  await File.lock(join(tablePath, ".tmp"));
1289
1289
  let paginationFilePath;
1290
1290
  let pagination;
1291
- for await (const filePath of glob("*.pagination", {
1291
+ for await (const paginationFileName of glob("*.pagination", {
1292
1292
  cwd: tablePath,
1293
1293
  })) {
1294
- paginationFilePath = filePath;
1295
- pagination = parse(filePath).name.split("-").map(Number);
1294
+ paginationFilePath = join(tablePath, paginationFileName);
1295
+ pagination = parse(paginationFileName)
1296
+ .name.split("-")
1297
+ .map(Number);
1296
1298
  }
1297
1299
  await Promise.all((await readdir(tablePath))
1298
1300
  ?.filter((fileName) => fileName.endsWith(this.getFileExtension(tableName)))
1299
1301
  .map(async (file) => unlink(join(tablePath, file))));
1300
1302
  if (this.tables[tableName].config.cache)
1301
1303
  await this.clearCache(tableName);
1302
- await rename(join(tablePath, paginationFilePath), join(tablePath, `${pagination[0]}-0.pagination`));
1304
+ await rename(paginationFilePath, join(tablePath, `${pagination[0]}-0.pagination`));
1303
1305
  return true;
1304
1306
  }
1305
1307
  finally {
@@ -1321,11 +1323,13 @@ export default class Inibase {
1321
1323
  await File.lock(join(tablePath, ".tmp"));
1322
1324
  let paginationFilePath;
1323
1325
  let pagination;
1324
- for await (const filePath of glob("*.pagination", {
1326
+ for await (const paginationFileName of glob("*.pagination", {
1325
1327
  cwd: tablePath,
1326
1328
  })) {
1327
- paginationFilePath = filePath;
1328
- pagination = parse(filePath).name.split("-").map(Number);
1329
+ paginationFilePath = join(tablePath, paginationFileName);
1330
+ pagination = parse(paginationFileName)
1331
+ .name.split("-")
1332
+ .map(Number);
1329
1333
  }
1330
1334
  if (pagination[1] &&
1331
1335
  pagination[1] - (Array.isArray(where) ? where.length : 1) > 0) {
@@ -1340,7 +1344,7 @@ export default class Inibase {
1340
1344
  .map(async (file) => unlink(join(tablePath, file))));
1341
1345
  if (this.tables[tableName].config.cache)
1342
1346
  await this.clearCache(tableName);
1343
- await rename(join(tablePath, paginationFilePath), join(tablePath, `${pagination[0]}-${pagination[1] - (Array.isArray(where) ? where.length : 1)}.pagination`));
1347
+ await rename(paginationFilePath, join(tablePath, `${pagination[0]}-${pagination[1] - (Array.isArray(where) ? where.length : 1)}.pagination`));
1344
1348
  return true;
1345
1349
  }
1346
1350
  finally {
@@ -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 oldIndex - The starting index for generating new IDs, defaults to 0.
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: number, secretKeyOrSalt: string | number | Buffer, encodeIDs?: boolean) => Field[];
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
  /**
@@ -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 oldIndex - The starting index for generating new IDs, defaults to 0.
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)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inibase",
3
- "version": "1.0.0-rc.111",
3
+ "version": "1.0.0-rc.112",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Karim Amahtil",