@wxn0brp/db-core 0.11.0-alpha.2 → 0.11.0-alpha.4

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.
@@ -20,17 +20,17 @@ export declare abstract class CustomActionsBase extends ActionsBase {
20
20
  /**
21
21
  * Update entries in the specified database based on search criteria and an updater function or object.
22
22
  */
23
- update(query: VQueryT.Update): Promise<Data[]>;
23
+ update(query: VQueryT.Update): Promise<import("../types/data.js").DataInternal[]>;
24
24
  /**
25
25
  * Update the first matching entry in the specified database based on search criteria and an updater function or object.
26
26
  */
27
- updateOne(query: VQueryT.Update): Promise<Data>;
27
+ updateOne(query: VQueryT.Update): Promise<import("../types/data.js").DataInternal>;
28
28
  /**
29
29
  * Remove entries from the specified database based on search criteria.
30
30
  */
31
- remove(query: VQueryT.Remove): Promise<Data[]>;
31
+ remove(query: VQueryT.Remove): Promise<import("../types/data.js").DataInternal[]>;
32
32
  /**
33
33
  * Remove the first matching entry from the specified database based on search criteria.
34
34
  */
35
- removeOne(query: VQueryT.Remove): Promise<Data>;
35
+ removeOne(query: VQueryT.Remove): Promise<import("../types/data.js").DataInternal>;
36
36
  }
@@ -1,4 +1,4 @@
1
- import { Data } from "./types/data.js";
1
+ import { Data, DataInternal } from "./types/data.js";
2
2
  import { FileCpu } from "./types/fileCpu.js";
3
3
  import { VQueryT } from "./types/query.js";
4
4
  export type WriteFile = (file: string, data: any[]) => Promise<void>;
@@ -10,7 +10,7 @@ export declare class CustomFileCpu implements FileCpu {
10
10
  constructor(readFile: ReadFile, writeFile: WriteFile);
11
11
  add(file: string, config: VQueryT.Add): Promise<void>;
12
12
  find(file: string, config: VQueryT.Find): Promise<Data[]>;
13
- findOne(file: string, config: VQueryT.FindOne): Promise<Data | false>;
14
- remove(file: string, config: VQueryT.Remove, one: boolean): Promise<Data[]>;
15
- update(file: string, config: VQueryT.Update, one: boolean): Promise<Data[]>;
13
+ findOne(file: string, config: VQueryT.FindOne): Promise<DataInternal | false>;
14
+ remove(file: string, config: VQueryT.Remove, one: boolean): Promise<DataInternal[]>;
15
+ update(file: string, config: VQueryT.Update, one: boolean): Promise<DataInternal[]>;
16
16
  }
@@ -1,4 +1,4 @@
1
- import { match, findProcessLine, update } from "./utils/process.js";
1
+ import { matchObj, findObj, updateObj } from "./utils/process.js";
2
2
  export function pathRepair(path) {
3
3
  return path.replaceAll("//", "/");
4
4
  }
@@ -19,14 +19,14 @@ export class CustomFileCpu {
19
19
  file = pathRepair(file);
20
20
  const entries = await this._readFile(file);
21
21
  return entries
22
- .map((entry) => findProcessLine(config, entry))
22
+ .map((entry) => findObj(config, entry))
23
23
  .filter(Boolean);
24
24
  }
25
25
  async findOne(file, config) {
26
26
  file = pathRepair(file);
27
27
  const entries = await this._readFile(file);
28
28
  for (const entry of entries) {
29
- const result = findProcessLine(config, entry);
29
+ const result = findObj(config, entry);
30
30
  if (result)
31
31
  return result;
32
32
  }
@@ -39,7 +39,7 @@ export class CustomFileCpu {
39
39
  entries = entries.filter((entry) => {
40
40
  if (removed.length && one)
41
41
  return true;
42
- if (match(config, entry)) {
42
+ if (matchObj(config, entry)) {
43
43
  removed.push(entry);
44
44
  return false;
45
45
  }
@@ -56,8 +56,8 @@ export class CustomFileCpu {
56
56
  entries = entries.map((entry) => {
57
57
  if (updated.length && one)
58
58
  return entry;
59
- if (match(config, entry)) {
60
- const updatedEntry = update(config, entry);
59
+ if (matchObj(config, entry)) {
60
+ const updatedEntry = updateObj(config, entry);
61
61
  updated.push(updatedEntry);
62
62
  return updatedEntry;
63
63
  }
@@ -7,6 +7,13 @@ export async function findUtil(query, fileCpuOrData, files) {
7
7
  let skippedEntries = 0;
8
8
  if (Array.isArray(fileCpuOrData)) {
9
9
  datas = [...fileCpuOrData];
10
+ if (!needsAllData) {
11
+ if (offset > 0 || limit !== -1) {
12
+ const start = offset;
13
+ const end = limit !== -1 ? offset + limit : undefined;
14
+ datas = datas.slice(start, end);
15
+ }
16
+ }
10
17
  }
11
18
  else {
12
19
  const filesToProcess = reverse && !sortBy ? [...files].reverse() : files;
@@ -1,5 +1,5 @@
1
- import { Data } from "../types/data.js";
1
+ import { Data, DataInternal } from "../types/data.js";
2
2
  import { VQuery, VQueryT } from "../types/query.js";
3
- export declare function findProcessLine(config: VQueryT.Find | VQueryT.FindOne, obj: Data): Object;
4
- export declare function match(config: VQuery, obj: Data): boolean;
5
- export declare function update(config: VQueryT.Update, obj: Data): Data;
3
+ export declare function findObj(config: VQueryT.Find | VQueryT.FindOne, obj: Data): DataInternal | null;
4
+ export declare function matchObj(config: VQuery, obj: Data): boolean;
5
+ export declare function updateObj(config: VQueryT.Update, obj: Data): DataInternal;
@@ -1,12 +1,12 @@
1
1
  import { hasFieldsAdvanced } from "./hasFieldsAdvanced.js";
2
2
  import { updateFindObject } from "./updateFindObject.js";
3
3
  import { updateObjectAdvanced } from "./updateObject.js";
4
- export function findProcessLine(config, obj) {
5
- if (match(config, obj))
4
+ export function findObj(config, obj) {
5
+ if (matchObj(config, obj))
6
6
  return updateFindObject(obj, config.findOpts || {});
7
7
  return null;
8
8
  }
9
- export function match(config, obj) {
9
+ export function matchObj(config, obj) {
10
10
  const { search, context } = config;
11
11
  if (search === undefined || search === null)
12
12
  return true;
@@ -16,7 +16,7 @@ export function match(config, obj) {
16
16
  return true;
17
17
  return false;
18
18
  }
19
- export function update(config, obj) {
19
+ export function updateObj(config, obj) {
20
20
  const { updater, context } = config;
21
21
  if (typeof updater === "object" && !Array.isArray(updater))
22
22
  return updateObjectAdvanced(obj, updater);
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = "0.11.0-alpha.2";
1
+ export const version = "0.11.0-alpha.4";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/db-core",
3
- "version": "0.11.0-alpha.2",
3
+ "version": "0.11.0-alpha.4",
4
4
  "types": "dist/index.d.ts",
5
5
  "main": "dist/index.js",
6
6
  "author": "wxn0brP",