@tanglemedia/svelte-starter-directus-api 3.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.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Directus-api
1
+ # [@tanglemedia/svelte-starter-directus-api](https://tanglemedia-svelte-docs.netlify.app/docs/directus-api-package/functionality)
2
2
 
3
3
  <p align="center" style="align: center;">
4
4
  <a href="https://npm.im/@tanglemedia/svelte-starter-directus-api">
@@ -260,3 +260,4 @@ export const formsServiceClient = configureService<FormInterface>(Forms, {
260
260
  adapterKey: 'directus-client'
261
261
  });
262
262
  ```
263
+ ### For mode demos and to check out all the components, please visit our [documentation website](https://tanglemedia-svelte-docs.netlify.app/docs/directus-api-package/functionality)
@@ -38,8 +38,13 @@ export class DirectusApiAdapter extends ApiAdapterAbstract {
38
38
  return null;
39
39
  }
40
40
  const { filter, search } = query || {};
41
+ // default to count. Note that there is a bug in directus where
42
+ // the wrong counts are being returned if there are nested filters.
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';
41
46
  const data = await this.directus.request(aggregate(collection, {
42
- aggregate: { count: '*' },
47
+ aggregate: { [k]: f },
43
48
  query: {
44
49
  ...(filter ? { filter } : {}),
45
50
  ...(search ? { search } : {}),
@@ -19,6 +19,8 @@ export type DirectusApiAdapterOptions = {
19
19
  credentials?: RequestCredentials;
20
20
  };
21
21
  includeTotals?: boolean;
22
+ totalAggregate?: 'count' | 'countDistinct';
23
+ totalField?: string;
22
24
  };
23
25
  export type DirectusConfig = BaseApiAdapterConfig<DirectusApiAdapterOptions>;
24
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": "3.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",
@@ -35,8 +35,8 @@
35
35
  "svelte-check": "^4.0.4",
36
36
  "vite": "^5.4.8",
37
37
  "vitest": "^2.1.2",
38
- "@tanglemedia/svelte-starter-core": "0.3.0",
39
- "@internal/eslint-config": "0.0.0"
38
+ "@internal/eslint-config": "0.0.0",
39
+ "@tanglemedia/svelte-starter-core": "0.5.0"
40
40
  },
41
41
  "dependencies": {
42
42
  "@directus/sdk": "^17.0.2",
@@ -46,7 +46,7 @@
46
46
  },
47
47
  "peerDependencies": {
48
48
  "@sveltejs/kit": ">=2 <3",
49
- "@tanglemedia/svelte-starter-core": ">=0.3.0",
49
+ "@tanglemedia/svelte-starter-core": ">=0.5.0",
50
50
  "svelte": ">=4 <5"
51
51
  },
52
52
  "scripts": {
@@ -85,8 +85,14 @@ export class DirectusApiAdapter<
85
85
 
86
86
  const { filter, search } = query || {};
87
87
 
88
+ // default to count. Note that there is a bug in directus where
89
+ // the wrong counts are being returned if there are nested filters.
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';
93
+
88
94
  const data = await this.directus.request(aggregate(collection, {
89
- aggregate: { count: '*' },
95
+ aggregate: { [k]: f },
90
96
  query: {
91
97
  ...(filter ? { filter } : {}),
92
98
  ...(search ? { search } : {}),
@@ -25,6 +25,8 @@ export type DirectusApiAdapterOptions = {
25
25
  };
26
26
 
27
27
  includeTotals?: boolean;
28
+ totalAggregate?: 'count' | 'countDistinct';
29
+ totalField?: string;
28
30
  };
29
31
 
30
32
  export type DirectusConfig = BaseApiAdapterConfig<DirectusApiAdapterOptions>;