@wxn0brp/db-core 0.10.0-alpha.0 → 0.10.0

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.
@@ -13,7 +13,7 @@ export class CustomActionsBase extends ActionsBase {
13
13
  await this.ensureCollection(query.collection);
14
14
  await addId(query, this);
15
15
  const { collection, data } = query;
16
- await this.fileCpu.add({ collection, data });
16
+ await this.fileCpu.add(collection, query);
17
17
  return data;
18
18
  }
19
19
  /**
@@ -29,7 +29,7 @@ export class CustomActionsBase extends ActionsBase {
29
29
  */
30
30
  async findOne(query) {
31
31
  await this.ensureCollection(query.collection);
32
- let data = await this.fileCpu.findOne(query);
32
+ let data = await this.fileCpu.findOne(query.collection, query);
33
33
  return data || null;
34
34
  }
35
35
  /**
@@ -37,14 +37,14 @@ export class CustomActionsBase extends ActionsBase {
37
37
  */
38
38
  async update(query) {
39
39
  await this.ensureCollection(query.collection);
40
- return await this.fileCpu.update(query, false);
40
+ return await this.fileCpu.update(query.collection, query, false);
41
41
  }
42
42
  /**
43
43
  * Update the first matching entry in the specified database based on search criteria and an updater function or object.
44
44
  */
45
45
  async updateOne(query) {
46
46
  await this.ensureCollection(query.collection);
47
- const res = await this.fileCpu.update(query, true);
47
+ const res = await this.fileCpu.update(query.collection, query, true);
48
48
  return res.length ? res[0] : null;
49
49
  }
50
50
  /**
@@ -52,14 +52,14 @@ export class CustomActionsBase extends ActionsBase {
52
52
  */
53
53
  async remove(query) {
54
54
  await this.ensureCollection(query.collection);
55
- return await this.fileCpu.remove(query, false);
55
+ return await this.fileCpu.remove(query.collection, query, false);
56
56
  }
57
57
  /**
58
58
  * Remove the first matching entry from the specified database based on search criteria.
59
59
  */
60
60
  async removeOne(query) {
61
61
  await this.ensureCollection(query.collection);
62
- const res = await this.fileCpu.remove(query, true);
62
+ const res = await this.fileCpu.remove(query.collection, query, true);
63
63
  return res.length ? res[0] : null;
64
64
  }
65
65
  }
@@ -8,9 +8,9 @@ export declare class CustomFileCpu implements FileCpu {
8
8
  _readFile: ReadFile;
9
9
  _writeFile: WriteFile;
10
10
  constructor(readFile: ReadFile, writeFile: WriteFile);
11
- add(config: Query.AddQuery): Promise<void>;
12
- find(config: Query.FindQuery): Promise<Data[]>;
13
- findOne(config: Query.FindOneQuery): Promise<Data | false>;
14
- remove(config: Query.RemoveQuery, one: boolean): Promise<Data[]>;
15
- update(config: Query.UpdateQuery, one: boolean): Promise<Data[]>;
11
+ add(file: string, config: Query.AddQuery): Promise<void>;
12
+ find(file: string, config: Query.FindQuery): Promise<Data[]>;
13
+ findOne(file: string, config: Query.FindOneQuery): Promise<Data | false>;
14
+ remove(file: string, config: Query.RemoveQuery, one: boolean): Promise<Data[]>;
15
+ update(file: string, config: Query.UpdateQuery, one: boolean): Promise<Data[]>;
16
16
  }
@@ -11,14 +11,14 @@ export class CustomFileCpu {
11
11
  this._readFile = readFile;
12
12
  this._writeFile = writeFile;
13
13
  }
14
- async add(config) {
15
- const file = pathRepair(config.collection);
14
+ async add(file, config) {
15
+ file = pathRepair(file);
16
16
  let entries = await this._readFile(file);
17
17
  entries.push(config.data);
18
18
  await this._writeFile(file, entries);
19
19
  }
20
- async find(config) {
21
- const file = pathRepair(config.collection);
20
+ async find(file, config) {
21
+ file = pathRepair(file);
22
22
  const entries = await this._readFile(file);
23
23
  const { search, context = {}, findOpts = {} } = config;
24
24
  const results = entries.filter(entry => typeof search === "function" ? search(entry, context) : hasFieldsAdvanced(entry, search));
@@ -26,8 +26,8 @@ export class CustomFileCpu {
26
26
  results.map(res => updateFindObject(res, findOpts)) :
27
27
  [];
28
28
  }
29
- async findOne(config) {
30
- const file = pathRepair(config.collection);
29
+ async findOne(file, config) {
30
+ file = pathRepair(file);
31
31
  const entries = await this._readFile(file);
32
32
  const { search, context = {}, findOpts = {} } = config;
33
33
  const result = entries.find(entry => typeof search === "function" ? search(entry, context) : hasFieldsAdvanced(entry, search));
@@ -35,8 +35,8 @@ export class CustomFileCpu {
35
35
  updateFindObject(result, findOpts) :
36
36
  false;
37
37
  }
38
- async remove(config, one) {
39
- const file = pathRepair(config.collection);
38
+ async remove(file, config, one) {
39
+ file = pathRepair(file);
40
40
  let entries = await this._readFile(file);
41
41
  const removed = [];
42
42
  const { search, context = {} } = config;
@@ -54,8 +54,8 @@ export class CustomFileCpu {
54
54
  await this._writeFile(file, entries);
55
55
  return removed;
56
56
  }
57
- async update(config, one) {
58
- const file = pathRepair(config.collection);
57
+ async update(file, config, one) {
58
+ file = pathRepair(file);
59
59
  let entries = await this._readFile(file);
60
60
  const updated = [];
61
61
  const { search, updater, context = {} } = config;
@@ -5,27 +5,27 @@ export interface FileCpu {
5
5
  * Asynchronously adds an entry to a file.
6
6
  * @returns A promise resolving to `void`.
7
7
  */
8
- add(config: Query.AddQuery): Promise<void>;
8
+ add(file: string, config: Query.AddQuery): Promise<void>;
9
9
  /**
10
10
  * Asynchronously finds multiple entries in a file based on search criteria.
11
11
  * @returns A promise resolving to an array of found entries, or `false` if the file does not exist.
12
12
  */
13
- find(config: Query.FindQuery): Promise<DataInternal[]>;
13
+ find(file: string, config: Query.FindQuery): Promise<DataInternal[]>;
14
14
  /**
15
15
  * Asynchronously finds one entry in a file based on search criteria.
16
16
  * @returns A promise resolving to the found entry or `false` if not found.
17
17
  */
18
- findOne(config: Query.FindOneQuery): Promise<DataInternal | false>;
18
+ findOne(file: string, config: Query.FindOneQuery): Promise<DataInternal | false>;
19
19
  /**
20
20
  * Asynchronously removes entries from a file based on search criteria.
21
21
  * @param one If `true`, removes only the first matching entry.
22
22
  * @returns A promise resolving to `true` if at least one entry was removed, otherwise `false`.
23
23
  */
24
- remove(config: Query.RemoveQuery, one: boolean): Promise<DataInternal[]>;
24
+ remove(file: string, config: Query.RemoveQuery, one: boolean): Promise<DataInternal[]>;
25
25
  /**
26
26
  * Asynchronously updates entries in a file based on search criteria and an updater function or object.
27
27
  * @param one If `true`, updates only the first matching entry.
28
28
  * @returns A promise resolving to `true` if at least one entry was updated, otherwise `false`.
29
29
  */
30
- update(config: Query.UpdateQuery, one: boolean): Promise<DataInternal[]>;
30
+ update(file: string, config: Query.UpdateQuery, one: boolean): Promise<DataInternal[]>;
31
31
  }
@@ -1,4 +1,4 @@
1
1
  import { Data } from "../types/data.js";
2
2
  import { FileCpu } from "../types/fileCpu.js";
3
- import { VQuery } from "../types/query.js";
4
- export declare function findUtil(query: VQuery, fileCpu: FileCpu, files: string[]): Promise<Data[]>;
3
+ import { FindQuery } from "../types/query.js";
4
+ export declare function findUtil(query: FindQuery, fileCpu: FileCpu, files: string[]): Promise<Data[]>;
@@ -8,7 +8,7 @@ export async function findUtil(query, fileCpu, files) {
8
8
  let totalEntries = 0;
9
9
  let skippedEntries = 0;
10
10
  for (const f of files) {
11
- let entries = await fileCpu.find(Object.assign({}, query, { collection: f }));
11
+ let entries = await fileCpu.find(f, query);
12
12
  if (reverse && !sortBy)
13
13
  entries.reverse();
14
14
  if (!sortBy) {
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = "0.10.0-alpha.0";
1
+ export const version = "0.10.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/db-core",
3
- "version": "0.10.0-alpha.0",
3
+ "version": "0.10.0",
4
4
  "types": "dist/index.d.ts",
5
5
  "main": "dist/index.js",
6
6
  "author": "wxn0brP",