@medyll/idae-query 0.66.0 → 0.68.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.
@@ -1,12 +1,14 @@
1
1
  import { type DotPath } from "../path/pathResolver.js";
2
- export declare const getResultsetProxy: <T>(data: T) => object;
2
+ import { type DataOpGroupByOptions } from "@medyll/idae-engine";
3
3
  /**
4
4
  * Represents the options for a result set.
5
5
  * @template T - The type of the result set.
6
6
  */
7
7
  export type ResultsetOptions<T = any> = {
8
- /** Can receive a dot path for sorting. */
8
+ /** @deprecated use sortByCan receive a dot path for sorting. */
9
9
  sort?: Record<DotPath<T>, "asc" | "desc">;
10
+ /** Can receive a dot path for sorting. */
11
+ sortBy?: Record<DotPath<T>, "asc" | "desc">;
10
12
  /** Specifies the property to group the result set by. */
11
13
  groupBy?: DotPath<T>;
12
14
  /** Specifies the page size of the result set. */
@@ -21,9 +23,9 @@ export type ResultSet<T> = T[] & {
21
23
  /** Accepts a dot path */
22
24
  sortBy: (args: Record<string, "asc" | "desc">) => ResultSet<T>;
23
25
  /** Accepts a dot path as fieldName */
24
- groupBy: (fieldName: string | string[],
25
- /** Transformer function to generate the grouped key */
26
- transform?: (value: any) => void) => Record<string, T[]>;
26
+ groupBy: (fieldName: DataOpGroupByOptions<T>,
27
+ /** Whether to keep ungrouped data */
28
+ keepUngroupedData?: boolean) => Record<string, T[]>;
27
29
  getPage: (page: number, size: number) => ResultSet<T>;
28
30
  toObject: (dotPath: DotPath<T>) => T[];
29
31
  };
@@ -1,72 +1,5 @@
1
1
  import { dotPath } from "../path/pathResolver.js";
2
- export const getResultsetProxy = (data) => {
3
- return new Proxy(data, {
4
- get: (target, prop) => {
5
- if (prop === "setOptions") {
6
- return (options) => {
7
- if (options.sort) {
8
- target.sortBy(options.sort);
9
- }
10
- if (options.groupBy) {
11
- target.groupBy(options.groupBy);
12
- }
13
- return target;
14
- };
15
- }
16
- if (prop === "sortBy") {
17
- return (args) => {
18
- const keys = Object.keys(args);
19
- const values = Object.values(args);
20
- target.sort((a, b) => {
21
- let i = 0;
22
- let result = 0;
23
- while (i < keys.length && result === 0) {
24
- let value = keys[i];
25
- result =
26
- values[i] === "asc"
27
- ? Number(dotPath(a, value)) - Number(dotPath(b, value))
28
- : Number(dotPath(b, value)) - Number(dotPath(a, value));
29
- i++;
30
- }
31
- return result;
32
- });
33
- delete target?.sortBy;
34
- return target;
35
- };
36
- }
37
- if (prop === "groupBy") {
38
- return (fieldName, transform) => {
39
- const finalFieldName = typeof fieldName === "string" ? [fieldName] : fieldName;
40
- return target.reduce((acc, curr) => {
41
- finalFieldName.forEach((f) => {
42
- acc += dotPath(curr, f);
43
- });
44
- if (!acc[key]) {
45
- acc[key] = [];
46
- }
47
- acc[key].push(curr);
48
- return acc;
49
- }, {});
50
- };
51
- }
52
- if (prop === "getPage") {
53
- return (page, size) => {
54
- const start = (page - 1) * size;
55
- const end = page * size;
56
- return target.slice(start, end);
57
- };
58
- }
59
- /* if (prop === "toObject") {
60
- return (dotPath) => {
61
- return target.map((item) => {
62
- return dotPath(item);
63
- });
64
- };
65
- } */
66
- return target[prop];
67
- },
68
- });
69
- };
2
+ import { dataOp } from "@medyll/idae-engine";
70
3
  /**
71
4
  * Generates a ResultSet based on the provided data array and defines additional properties like setOptions, sortBy, groupBy, and getPage for customization and manipulation.
72
5
  *
@@ -78,7 +11,7 @@ export function getResultset(data) {
78
11
  Object.defineProperties(data, {
79
12
  setOptions: {
80
13
  value: function (options = {}) {
81
- if (options.sort) {
14
+ if (options.sort ?? options.sortBy) {
82
15
  this.sortBy(options.sort);
83
16
  }
84
17
  if (options.groupBy) {
@@ -113,19 +46,24 @@ export function getResultset(data) {
113
46
  configurable: true,
114
47
  },
115
48
  groupBy: {
116
- value: function (fieldName, transform) {
117
- const finalFieldName = typeof fieldName === "string" ? [fieldName] : fieldName;
118
- return this.reduce((acc, curr) => {
49
+ value: function (fieldName, keepUngroupedData = true) {
50
+ return dataOp.groupBy({ dataList: this, groupBy: fieldName });
51
+ /* const finalFieldName =
52
+ typeof fieldName === "string" ? [fieldName] : fieldName;
53
+ return this.reduce(
54
+ (acc: { [x: string]: any[] }, curr: Record<string, any>) => {
119
55
  let key = "";
120
56
  for (let i = 0; i < finalFieldName.length; i++) {
121
- key += dotPath(curr, finalFieldName[i]);
57
+ key += dotPath<typeof curr>(curr, finalFieldName[i]);
122
58
  }
123
59
  if (!acc[key]) {
124
- acc[key] = [];
60
+ acc[key] = [];
125
61
  }
126
62
  acc[key].push(curr);
127
63
  return acc;
128
- }, {});
64
+ },
65
+ {},
66
+ ); */
129
67
  },
130
68
  enumerable: true,
131
69
  configurable: true,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@medyll/idae-query",
3
3
  "scope": "@medyll",
4
- "version": "0.66.0",
4
+ "version": "0.68.0",
5
5
  "description": "A powerful and flexible IndexedDB query library for TypeScript and JavaScript applications, featuring a MongoDB-like query interface, strong TypeScript support, reactive state management, and easy integration with front-end frameworks like Svelte.",
6
6
  "scripts": {
7
7
  "dev": "vite dev",
@@ -34,21 +34,21 @@
34
34
  "devDependencies": {
35
35
  "@medyll/idae-prettier-config": "^1.1.0",
36
36
  "@sveltejs/adapter-auto": "^4.0.0",
37
- "@sveltejs/kit": "^2.17.3",
37
+ "@sveltejs/kit": "^2.18.0",
38
38
  "@sveltejs/package": "^2.3.10",
39
39
  "@sveltejs/vite-plugin-svelte": "^5.0.3",
40
40
  "@types/eslint": "^9.6.1",
41
41
  "eslint": "^9.21.0",
42
42
  "eslint-config-prettier": "^10.0.2",
43
- "eslint-plugin-svelte": "^3.0.2",
43
+ "eslint-plugin-svelte": "^3.0.3",
44
44
  "globals": "^16.0.0",
45
45
  "prettier": "^3.5.3",
46
46
  "prettier-plugin-svelte": "^3.3.3",
47
- "svelte": "^5.20.5",
47
+ "svelte": "^5.22.4",
48
48
  "svelte-check": "^4.1.4",
49
49
  "tslib": "^2.8.1",
50
50
  "typescript": "^5.8.2",
51
- "typescript-eslint": "^8.25.0",
51
+ "typescript-eslint": "^8.26.0",
52
52
  "vite": "^6.2.0",
53
53
  "vitest": "^3.0.7"
54
54
  },