@hostlink/nuxt-light 0.0.60 → 0.0.61

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.
package/dist/module.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "light",
3
3
  "configKey": "light",
4
- "version": "0.0.60"
4
+ "version": "0.0.61"
5
5
  }
@@ -1 +1 @@
1
- export default function (fields?: Array<string>): Promise<any>;
1
+ export default function (fields?: Array<string | Object>): Promise<any>;
@@ -9,7 +9,7 @@ export default async function(fields = []) {
9
9
  const id = parseInt(route.params[id_name]);
10
10
  const filters = {};
11
11
  filters[id_name] = id;
12
- if (fields.length == 0) {
12
+ if (fields instanceof Array && fields.length == 0) {
13
13
  fields.push(id_name);
14
14
  }
15
15
  let { data } = await listData(module, {
@@ -1 +1 @@
1
- export default function listData(name: string, props?: any, fields?: Array<string>): Promise<any>;
1
+ export default function listData(name: string, props?: any, fields?: Array<string | Object> | Object): Promise<any>;
@@ -1,32 +1,48 @@
1
- import q from "./q.mjs";
2
- import f from "./f.mjs";
1
+ import { query, toQuery } from "@hostlink/light";
3
2
  export default async function listData(name, props = {}, fields = []) {
4
- let v = {};
3
+ let json = {};
5
4
  if (props.sort) {
6
- v.sort = props.sort;
5
+ json.__args = json.__args || {};
6
+ json.__args.sort = props.sort;
7
7
  }
8
8
  if (props.filters) {
9
- v.filters = props.filters;
9
+ json.__args = json.__args || {};
10
+ json.__args.filters = props.filters;
10
11
  }
11
- let offset_limit = {};
12
+ json.data = {};
12
13
  if (props.offset) {
13
- offset_limit.offset = props.offset;
14
+ json.data.__args = json.data.__args || {};
15
+ json.data.__args.offset = props.offset;
14
16
  }
15
17
  if (props.limit) {
16
- offset_limit.limit = props.limit;
18
+ json.data.__args = json.data.__args || {};
19
+ json.data.__args.limit = props.limit;
17
20
  }
18
- const fs = fields;
19
- if (props.fields) {
20
- fs.push(...props.fields);
21
- }
22
- let data = await q(`list${name}`, v, [f("data", offset_limit, fs), f("meta", ["total", "key", "name"])]);
23
- if (props.done) {
24
- props.done({
25
- rows: data.data,
26
- total: data.meta.total,
27
- key: data.meta.key,
28
- name: data.meta.name
21
+ if (fields instanceof Array) {
22
+ fields.forEach((field) => {
23
+ if (field instanceof Object) {
24
+ Object.entries(field).forEach(([key, value]) => {
25
+ json.data[key] = toQuery(value);
26
+ });
27
+ } else {
28
+ json.data[field] = true;
29
+ }
29
30
  });
31
+ } else if (fields instanceof Object) {
32
+ json.data = Object.assign({}, fields);
33
+ if (props.fields) {
34
+ props.fields.forEach((field) => {
35
+ json.data[field] = true;
36
+ });
37
+ }
30
38
  }
31
- return data;
39
+ json.meta = {
40
+ total: true,
41
+ key: true,
42
+ name: true
43
+ };
44
+ const q = {};
45
+ q[`list${name}`] = json;
46
+ let data = await query(q);
47
+ return data[`list${name}`];
32
48
  }
@@ -1 +1 @@
1
- export default function (operation: string | object, args: any, fields?: Array<any>): Promise<any>;
1
+ export default function (operation: string | object, args?: any, fields?: Array<any>): Promise<any>;
@@ -3,7 +3,7 @@ import f from "./f.mjs";
3
3
  import { jsonToGraphQLQuery } from "json-to-graphql-query";
4
4
  import { getApiBase } from "./index.mjs";
5
5
  import toJson from "./toJson.mjs";
6
- export default async function(operation, args, fields = []) {
6
+ export default async function(operation, args = null, fields = []) {
7
7
  const service = axios.create({
8
8
  withCredentials: true
9
9
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hostlink/nuxt-light",
3
- "version": "0.0.60",
3
+ "version": "0.0.61",
4
4
  "description": "HostLink Nuxt Light Framework",
5
5
  "repository": "@hostlink/nuxt-light",
6
6
  "license": "MIT",