@svadmin/directus 0.9.2 → 0.9.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@svadmin/directus",
3
- "version": "0.9.2",
3
+ "version": "0.9.4",
4
4
  "description": "Directus DataProvider for svadmin",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -16,7 +16,7 @@
16
16
  }
17
17
  },
18
18
  "peerDependencies": {
19
- "@svadmin/core": "^0.19.3"
19
+ "@svadmin/core": "^0.22.1"
20
20
  },
21
21
  "license": "MIT",
22
22
  "repository": {
@@ -1,17 +1,20 @@
1
1
  import type {
2
2
  DataProvider, GetListParams, GetListResult, GetOneParams, GetOneResult,
3
3
  CreateParams, CreateResult, UpdateParams, UpdateResult, DeleteParams, DeleteResult,
4
- GetManyParams, GetManyResult, CustomParams, CustomResult, Sort, Filter
5
- , BaseRecord } from '@svadmin/core';
4
+ GetManyParams, GetManyResult, CustomParams, CustomResult, Sort, Filter, LogicalFilter,
5
+ BaseRecord
6
+ } from '@svadmin/core';
6
7
 
7
- function buildDirectusFilter(filters?: Filter[]): Record<string, unknown> {
8
+ function buildDirectusFilter(filters?: (Filter | LogicalFilter | any)[]): Record<string, unknown> {
8
9
  if (!filters?.length) return {};
9
- const filter: Record<string, unknown> = {};
10
- const opMap: Record<string, string> = { eq: '_eq', ne: '_neq', lt: '_lt', gt: '_gt', lte: '_lte', gte: '_gte', contains: '_contains', in: '_in', null: '_null' };
11
- for (const f of filters) {
12
- if ('field' in f) filter[f.field as string] = { [opMap[f.operator as string] ?? '_eq']: f.value };
13
- }
14
- return filter;
10
+ const opMap: Record<string, string> = { eq: '_eq', ne: '_neq', lt: '_lt', gt: '_gt', lte: '_lte', gte: '_gte', contains: '_contains', in: '_in', null: '_null', and: '_and', or: '_or' };
11
+
12
+ const rules = filters.map(f => {
13
+ if ('field' in f) return { [f.field as string]: { [opMap[f.operator as string] ?? '_eq']: f.value } };
14
+ return { [opMap[f.operator]]: (f.value as any[]).map(sub => buildDirectusFilter([sub])) };
15
+ });
16
+
17
+ return rules.length === 1 ? rules[0] : { _and: rules };
15
18
  }
16
19
 
17
20
  export function createDirectusDataProvider(apiUrl: string, token?: string): DataProvider {