inibase 1.0.0-rc.105 → 1.0.0-rc.107

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.
Files changed (2) hide show
  1. package/dist/index.js +15 -9
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -142,7 +142,9 @@ export default class Inibase {
142
142
  let schemaIdFilePath;
143
143
  for await (const filePath of glob("*.schema", { cwd: this.databasePath }))
144
144
  schemaIdFilePath = filePath;
145
- const lastSchemaId = Number(parse(schemaIdFilePath).name);
145
+ const lastSchemaId = schemaIdFilePath
146
+ ? Number(parse(schemaIdFilePath).name)
147
+ : 0;
146
148
  if (await File.isExists(join(tablePath, "schema.json"))) {
147
149
  // update columns files names based on field id
148
150
  schema = UtilsServer.addIdToSchema(schema, lastSchemaId, this.salt);
@@ -158,7 +160,10 @@ export default class Inibase {
158
160
  else
159
161
  schema = UtilsServer.addIdToSchema(schema, lastSchemaId, this.salt);
160
162
  await writeFile(join(tablePath, "schema.json"), JSON.stringify(schema, null, 2));
161
- await rename(schemaIdFilePath, join(tablePath, `${lastSchemaId}.schema`));
163
+ if (schemaIdFilePath)
164
+ await rename(schemaIdFilePath, join(tablePath, `${lastSchemaId}.schema`));
165
+ else
166
+ await writeFile(join(tablePath, `${lastSchemaId}.schema`), "");
162
167
  }
163
168
  if (config) {
164
169
  if (config.compression !== undefined &&
@@ -1074,8 +1079,8 @@ export default class Inibase {
1074
1079
  if (!returnPostedData)
1075
1080
  returnPostedData = false;
1076
1081
  const keys = UtilsServer.hashString(Object.keys(Array.isArray(data) ? data[0] : data).join("."));
1077
- // Skip Id and (created|updated)At
1078
- this.validateData(data, schema.slice(3));
1082
+ // Skip ID and (created|updated)At
1083
+ this.validateData(data, schema.slice(1, -2));
1079
1084
  let lastId = 0;
1080
1085
  const renameList = [];
1081
1086
  try {
@@ -1153,9 +1158,10 @@ export default class Inibase {
1153
1158
  throw this.Error("INVALID_ID", data.id);
1154
1159
  return this.put(tableName, data, data.id, options, returnUpdatedData || undefined);
1155
1160
  }
1156
- this.validateData(data, schema, true);
1161
+ // Skip ID and (created|updated)At
1162
+ this.validateData(data, schema.slice(1, -2), true);
1157
1163
  await this.checkUnique(tableName, schema);
1158
- data = this.formatData(data, schema, true);
1164
+ this.formatData(data, schema, true);
1159
1165
  const pathesContents = this.joinPathesContents(tableName, {
1160
1166
  ...(({ id, ...restOfData }) => restOfData)(data),
1161
1167
  updatedAt: Date.now(),
@@ -1191,9 +1197,9 @@ export default class Inibase {
1191
1197
  else if ((Array.isArray(where) && where.every(Utils.isNumber)) ||
1192
1198
  Utils.isNumber(where)) {
1193
1199
  // "where" in this case, is the line(s) number(s) and not id(s)
1194
- this.validateData(data, schema, true);
1195
- await this.checkUnique(tableName, schema);
1196
- data = this.formatData(data, schema, true);
1200
+ this.validateData(data, schema.slice(1, -2), true);
1201
+ await this.checkUnique(tableName, schema.slice(1, -2));
1202
+ this.formatData(data, schema, true);
1197
1203
  const pathesContents = Object.fromEntries(Object.entries(this.joinPathesContents(tableName, Utils.isArrayOfObjects(data)
1198
1204
  ? data.map((item) => ({
1199
1205
  ...item,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inibase",
3
- "version": "1.0.0-rc.105",
3
+ "version": "1.0.0-rc.107",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Karim Amahtil",