@wxn0brp/db-core 0.12.0 → 0.12.1

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.
@@ -5,9 +5,10 @@ export type WriteFile = (file: string, data: any[]) => Promise<void>;
5
5
  export type ReadFile = (file: string) => Promise<any[]>;
6
6
  export declare function pathRepair(path: string): string;
7
7
  export declare class CustomFileCpu implements FileCpu {
8
+ requireClone: boolean;
8
9
  _readFile: ReadFile;
9
10
  _writeFile: WriteFile;
10
- constructor(readFile: ReadFile, writeFile: WriteFile);
11
+ constructor(readFile: ReadFile, writeFile: WriteFile, requireClone?: boolean);
11
12
  add(file: string, config: VQueryT.Add): Promise<void>;
12
13
  find(file: string, config: VQueryT.Find): Promise<Data[]>;
13
14
  findOne(file: string, config: VQueryT.FindOne): Promise<DataInternal | false>;
@@ -1,11 +1,14 @@
1
- import { matchObj, findObj, updateObj } from "./utils/process.js";
1
+ import { matchObj, updateObj } from "./utils/process.js";
2
+ import { updateFindObject } from "./utils/updateFindObject.js";
2
3
  export function pathRepair(path) {
3
4
  return path.replace(/\/+/g, "/");
4
5
  }
5
6
  export class CustomFileCpu {
7
+ requireClone;
6
8
  _readFile;
7
9
  _writeFile;
8
- constructor(readFile, writeFile) {
10
+ constructor(readFile, writeFile, requireClone = false) {
11
+ this.requireClone = requireClone;
9
12
  this._readFile = readFile;
10
13
  this._writeFile = writeFile;
11
14
  }
@@ -18,15 +21,19 @@ export class CustomFileCpu {
18
21
  async find(file, config) {
19
22
  file = pathRepair(file);
20
23
  const entries = await this._readFile(file);
21
- return entries.map(entry => findObj(config, entry)).filter(Boolean);
24
+ const result = entries.filter(entry => matchObj(config, entry));
25
+ const objs = this.requireClone ? structuredClone(result) : result;
26
+ return objs.map(obj => updateFindObject(obj, config.findOpts || {}));
22
27
  }
23
28
  async findOne(file, config) {
24
29
  file = pathRepair(file);
25
30
  const entries = await this._readFile(file);
26
31
  for (const entry of entries) {
27
- const result = findObj(config, entry);
28
- if (result)
29
- return result;
32
+ const isMatch = matchObj(config, entry);
33
+ if (!isMatch)
34
+ continue;
35
+ const obj = this.requireClone ? structuredClone(entry) : entry;
36
+ return updateFindObject(obj, config.findOpts || {});
30
37
  }
31
38
  return false;
32
39
  }
package/dist/db/memory.js CHANGED
@@ -7,16 +7,16 @@ export class MemoryAction extends CustomActionsBase {
7
7
  smartExecutor = true;
8
8
  constructor() {
9
9
  super();
10
- this.fileCpu = new CustomFileCpu(this._readMemory.bind(this), this._writeMemory.bind(this));
10
+ this.fileCpu = new CustomFileCpu(this._readMemory.bind(this), this._writeMemory.bind(this), true);
11
11
  this.memory = new Map();
12
12
  }
13
13
  _readMemory(key) {
14
14
  if (!this.memory.has(key))
15
15
  return [];
16
- return structuredClone(this.memory.get(key));
16
+ return this.memory.get(key);
17
17
  }
18
18
  _writeMemory(key, data) {
19
- this.memory.set(key, structuredClone(data));
19
+ this.memory.set(key, data);
20
20
  }
21
21
  async getCollections() {
22
22
  const collections = Array.from(this.memory.keys());
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = "0.12.0";
1
+ export const version = "0.12.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/db-core",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "types": "dist/index.d.ts",
5
5
  "main": "dist/index.js",
6
6
  "author": "wxn0brP",