@tanglemedia/svelte-starter-directus-api 4.0.0 → 4.0.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.
@@ -38,14 +38,16 @@ export class DirectusApiAdapter extends ApiAdapterAbstract {
38
38
  return null;
39
39
  }
40
40
  const { filter, search } = query || {};
41
- // default to countDistinct. Note that there is a bug in directus where
41
+ // default to count. Note that there is a bug in directus where
42
42
  // the wrong counts are being returned if there are nested filters.
43
- const k = this.config.configuration.totalAggregate || 'countDistinct';
43
+ // A quick fix is to set totalAggregate to countDistinct
44
+ const k = this.config.configuration.totalAggregate || 'count';
45
+ const f = this.config.configuration.totalField || 'id';
44
46
  const data = await this.directus.request(aggregate(collection, {
45
- aggregate: { [k]: '*' },
47
+ aggregate: { [k]: f },
46
48
  query: {
47
49
  ...(filter ? { filter } : {}),
48
- ...(search ? { search } : {})
50
+ ...(search ? { search } : {}),
49
51
  }
50
52
  }));
51
53
  if (data && data.length === 1) {
@@ -88,7 +90,7 @@ export class DirectusApiAdapter extends ApiAdapterAbstract {
88
90
  }
89
91
  }
90
92
  async find(collection, query) {
91
- const response = (await this.directus.request(readItems(collection, query)));
93
+ const response = await this.directus.request(readItems(collection, query));
92
94
  const total = await this.includeTotals(collection, query);
93
95
  if (null === total) {
94
96
  return this.transformResponse({ data: response });
@@ -101,13 +103,11 @@ export class DirectusApiAdapter extends ApiAdapterAbstract {
101
103
  return this.transformResponse({ data });
102
104
  }
103
105
  async aggregate(collection, query) {
104
- const { aggregate: aggregate_, ...rest } = query || {};
106
+ const { aggregate: aggregate_, ...rest } = (query || {});
105
107
  const data = await this.directus.request(aggregate(collection, {
106
- aggregate: aggregate_
107
- ? aggregate_
108
- : {
109
- count: 'id'
110
- },
108
+ aggregate: aggregate_ ? aggregate_ : {
109
+ count: 'id'
110
+ },
111
111
  query: rest
112
112
  }));
113
113
  return this.transformResponse({ data });
@@ -126,7 +126,7 @@ export class DirectusApiAdapter extends ApiAdapterAbstract {
126
126
  }
127
127
  async put(collection, key, payload) {
128
128
  if (key) {
129
- const data = (await this.directus.request(updateItem(collection, key, payload)));
129
+ const data = await this.directus.request(updateItem(collection, key, payload));
130
130
  return this.transformResponse({ data }, 201);
131
131
  }
132
132
  else {
@@ -20,6 +20,7 @@ export type DirectusApiAdapterOptions = {
20
20
  };
21
21
  includeTotals?: boolean;
22
22
  totalAggregate?: 'count' | 'countDistinct';
23
+ totalField?: string;
23
24
  };
24
25
  export type DirectusConfig = BaseApiAdapterConfig<DirectusApiAdapterOptions>;
25
26
  export type SchemaShape = Record<string, object>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanglemedia/svelte-starter-directus-api",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "main": "src/index.ts",
5
5
  "types": "src/index.ts",
6
6
  "description": "directus API wrapper for all the directus sdk functionality",
@@ -85,12 +85,14 @@ export class DirectusApiAdapter<
85
85
 
86
86
  const { filter, search } = query || {};
87
87
 
88
- // default to countDistinct. Note that there is a bug in directus where
88
+ // default to count. Note that there is a bug in directus where
89
89
  // the wrong counts are being returned if there are nested filters.
90
- const k = this.config.configuration.totalAggregate || 'countDistinct';
90
+ // A quick fix is to set totalAggregate to countDistinct
91
+ const k = this.config.configuration.totalAggregate || 'count';
92
+ const f = this.config.configuration.totalField || 'id';
91
93
 
92
94
  const data = await this.directus.request(aggregate(collection, {
93
- aggregate: { [k]: '*' },
95
+ aggregate: { [k]: f },
94
96
  query: {
95
97
  ...(filter ? { filter } : {}),
96
98
  ...(search ? { search } : {}),
@@ -26,6 +26,7 @@ export type DirectusApiAdapterOptions = {
26
26
 
27
27
  includeTotals?: boolean;
28
28
  totalAggregate?: 'count' | 'countDistinct';
29
+ totalField?: string;
29
30
  };
30
31
 
31
32
  export type DirectusConfig = BaseApiAdapterConfig<DirectusApiAdapterOptions>;