@tanglemedia/svelte-starter-directus-api 3.0.0 → 4.0.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.
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
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,11 +38,14 @@ 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
|
|
42
|
+
// the wrong counts are being returned if there are nested filters.
|
|
43
|
+
const k = this.config.configuration.totalAggregate || 'countDistinct';
|
|
41
44
|
const data = await this.directus.request(aggregate(collection, {
|
|
42
|
-
aggregate: {
|
|
45
|
+
aggregate: { [k]: '*' },
|
|
43
46
|
query: {
|
|
44
47
|
...(filter ? { filter } : {}),
|
|
45
|
-
...(search ? { search } : {})
|
|
48
|
+
...(search ? { search } : {})
|
|
46
49
|
}
|
|
47
50
|
}));
|
|
48
51
|
if (data && data.length === 1) {
|
|
@@ -85,7 +88,7 @@ export class DirectusApiAdapter extends ApiAdapterAbstract {
|
|
|
85
88
|
}
|
|
86
89
|
}
|
|
87
90
|
async find(collection, query) {
|
|
88
|
-
const response = await this.directus.request(readItems(collection, query));
|
|
91
|
+
const response = (await this.directus.request(readItems(collection, query)));
|
|
89
92
|
const total = await this.includeTotals(collection, query);
|
|
90
93
|
if (null === total) {
|
|
91
94
|
return this.transformResponse({ data: response });
|
|
@@ -98,11 +101,13 @@ export class DirectusApiAdapter extends ApiAdapterAbstract {
|
|
|
98
101
|
return this.transformResponse({ data });
|
|
99
102
|
}
|
|
100
103
|
async aggregate(collection, query) {
|
|
101
|
-
const { aggregate: aggregate_, ...rest } =
|
|
104
|
+
const { aggregate: aggregate_, ...rest } = query || {};
|
|
102
105
|
const data = await this.directus.request(aggregate(collection, {
|
|
103
|
-
aggregate: aggregate_
|
|
104
|
-
|
|
105
|
-
|
|
106
|
+
aggregate: aggregate_
|
|
107
|
+
? aggregate_
|
|
108
|
+
: {
|
|
109
|
+
count: 'id'
|
|
110
|
+
},
|
|
106
111
|
query: rest
|
|
107
112
|
}));
|
|
108
113
|
return this.transformResponse({ data });
|
|
@@ -121,7 +126,7 @@ export class DirectusApiAdapter extends ApiAdapterAbstract {
|
|
|
121
126
|
}
|
|
122
127
|
async put(collection, key, payload) {
|
|
123
128
|
if (key) {
|
|
124
|
-
const data = await this.directus.request(updateItem(collection, key, payload));
|
|
129
|
+
const data = (await this.directus.request(updateItem(collection, key, payload)));
|
|
125
130
|
return this.transformResponse({ data }, 201);
|
|
126
131
|
}
|
|
127
132
|
else {
|
|
@@ -19,6 +19,7 @@ export type DirectusApiAdapterOptions = {
|
|
|
19
19
|
credentials?: RequestCredentials;
|
|
20
20
|
};
|
|
21
21
|
includeTotals?: boolean;
|
|
22
|
+
totalAggregate?: 'count' | 'countDistinct';
|
|
22
23
|
};
|
|
23
24
|
export type DirectusConfig = BaseApiAdapterConfig<DirectusApiAdapterOptions>;
|
|
24
25
|
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
|
+
"version": "4.0.0",
|
|
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
|
-
"@
|
|
39
|
-
"@
|
|
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.
|
|
49
|
+
"@tanglemedia/svelte-starter-core": ">=0.5.0",
|
|
50
50
|
"svelte": ">=4 <5"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
@@ -85,8 +85,12 @@ 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
|
|
89
|
+
// the wrong counts are being returned if there are nested filters.
|
|
90
|
+
const k = this.config.configuration.totalAggregate || 'countDistinct';
|
|
91
|
+
|
|
88
92
|
const data = await this.directus.request(aggregate(collection, {
|
|
89
|
-
aggregate: {
|
|
93
|
+
aggregate: { [k]: '*' },
|
|
90
94
|
query: {
|
|
91
95
|
...(filter ? { filter } : {}),
|
|
92
96
|
...(search ? { search } : {}),
|