inibase 1.0.0-rc.64 → 1.0.0-rc.65

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 +17 -10
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -118,17 +118,17 @@ export default class Inibase {
118
118
  if (config.compression !== undefined) {
119
119
  if (!config.compression && table.config.compression) {
120
120
  try {
121
- await UtilsServer.exec(`gunzip ${tablePath}/*.${this.fileExtension}.gz 2>/dev/null`);
122
- await unlink(join(tablePath, ".compression.config"));
121
+ await UtilsServer.exec(`find ${tablePath} -type f -name '*${this.fileExtension}.gz' -exec gunzip -f {} +`);
123
122
  }
124
123
  catch { }
124
+ await unlink(join(tablePath, ".compression.config"));
125
125
  }
126
126
  else if (config.compression && !table.config.compression) {
127
127
  try {
128
- await UtilsServer.exec(`gzip ${tablePath}/*.${this.fileExtension} 2>/dev/null`);
129
- await writeFile(join(tablePath, ".compression.config"), "");
128
+ await UtilsServer.exec(`find ${tablePath} -type f -name '*${this.fileExtension}' -exec gzip -f {} +`);
130
129
  }
131
130
  catch { }
131
+ await writeFile(join(tablePath, ".compression.config"), "");
132
132
  }
133
133
  }
134
134
  if (config.cache !== undefined) {
@@ -138,6 +138,14 @@ export default class Inibase {
138
138
  await unlink(join(tablePath, ".cache.config"));
139
139
  }
140
140
  if (config.prepend !== undefined) {
141
+ if (config.prepend !== table.config.prepend) {
142
+ try {
143
+ await UtilsServer.exec(config.compression || table.config.compression
144
+ ? `find ${tablePath} -type f -name '*${this.fileExtension}.gz' -exec sh -c 'zcat "$0" | tac | gzip > "$0.reversed" && mv "$0.reversed" "$0"' {} +`
145
+ : `find ${tablePath} -type f -name '*${this.fileExtension}' -exec sh -c 'tac "$0" > "$0.reversed" && mv "$0.reversed" "$0"' {} +`);
146
+ }
147
+ catch { }
148
+ }
141
149
  if (config.prepend && !table.config.prepend)
142
150
  await writeFile(join(tablePath, ".prepend.config"), "");
143
151
  else if (!config.prepend && table.config.prepend)
@@ -149,12 +157,11 @@ export default class Inibase {
149
157
  schema = schema.filter(({ key }) => !["id", "createdAt", "updatedAt"].includes(key));
150
158
  if (await File.isExists(join(tablePath, "schema.json"))) {
151
159
  // update columns files names based on field id
152
- const currentSchema = await this.getTableSchema(tableName, false);
153
- schema = UtilsServer.addIdToSchema(schema, currentSchema?.length
154
- ? UtilsServer.findLastIdNumber(currentSchema, this.salt)
160
+ schema = UtilsServer.addIdToSchema(schema, table.schema?.length
161
+ ? UtilsServer.findLastIdNumber(table.schema, this.salt)
155
162
  : 0, this.salt, false);
156
- if (currentSchema?.length) {
157
- const replaceOldPathes = Utils.findChangedProperties(this._schemaToIdsPath(tableName, currentSchema), this._schemaToIdsPath(tableName, schema));
163
+ if (table.schema?.length) {
164
+ const replaceOldPathes = Utils.findChangedProperties(this._schemaToIdsPath(tableName, table.schema), this._schemaToIdsPath(tableName, schema));
158
165
  if (replaceOldPathes)
159
166
  await Promise.all(Object.entries(replaceOldPathes).map(async ([oldPath, newPath]) => {
160
167
  if (await File.isExists(join(tablePath, oldPath)))
@@ -165,8 +172,8 @@ export default class Inibase {
165
172
  else
166
173
  schema = UtilsServer.addIdToSchema(schema, 0, this.salt, false);
167
174
  await writeFile(join(tablePath, "schema.json"), JSON.stringify(schema, null, 2));
168
- delete this.tables[tableName];
169
175
  }
176
+ delete this.tables[tableName];
170
177
  }
171
178
  /**
172
179
  * Get table schema and config
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inibase",
3
- "version": "1.0.0-rc.64",
3
+ "version": "1.0.0-rc.65",
4
4
  "author": {
5
5
  "name": "Karim Amahtil",
6
6
  "email": "karim.amahtil@gmail.com"