@nestjs-filter-grammar/prisma 0.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 +102 -0
- package/dist/apply-filter.d.ts +4 -0
- package/dist/apply-filter.d.ts.map +1 -0
- package/dist/apply-filter.js +74 -0
- package/dist/apply-filter.js.map +1 -0
- package/dist/apply-sort.d.ts +4 -0
- package/dist/apply-sort.d.ts.map +1 -0
- package/dist/apply-sort.js +17 -0
- package/dist/apply-sort.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/operators.d.ts +9 -0
- package/dist/operators.d.ts.map +1 -0
- package/dist/operators.js +24 -0
- package/dist/operators.js.map +1 -0
- package/dist/types.d.ts +16 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +23 -0
package/README.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# @nestjs-filter-grammar/prisma
|
|
2
|
+
|
|
3
|
+
Prisma adapter for nestjs-filter-grammar. Translates `FilterTree` and `SortEntry[]` into Prisma `where` and `orderBy` objects.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @nestjs-filter-grammar/prisma @nestjs-filter-grammar/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Peer Dependencies
|
|
12
|
+
|
|
13
|
+
- `@prisma/client` >= 5.0.0
|
|
14
|
+
|
|
15
|
+
## API
|
|
16
|
+
|
|
17
|
+
### `applyFilter(tree, options?): Record<string, PrismaQueryValue>`
|
|
18
|
+
|
|
19
|
+
Converts a `FilterTree` into a Prisma `where` object.
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { applyFilter } from '@nestjs-filter-grammar/prisma';
|
|
23
|
+
|
|
24
|
+
const users = await prisma.user.findMany({
|
|
25
|
+
where: applyFilter(filterTree),
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**Output examples:**
|
|
30
|
+
|
|
31
|
+
| Input | Output |
|
|
32
|
+
|-------|--------|
|
|
33
|
+
| `status=active` | `{ status: { equals: 'active' } }` |
|
|
34
|
+
| `status!=deleted` | `{ status: { not: { equals: 'deleted' } } }` |
|
|
35
|
+
| `status=active,pending` | `{ status: { in: ['active', 'pending'] } }` |
|
|
36
|
+
| `name*~john` | `{ name: { contains: 'john', mode: 'insensitive' } }` |
|
|
37
|
+
| `status=active;age>=18` | `{ AND: [{ status: { equals: 'active' } }, { age: { gte: '18' } }] }` |
|
|
38
|
+
| `status=active\|status=pending` | `{ OR: [{ status: { equals: 'active' } }, { status: { equals: 'pending' } }] }` |
|
|
39
|
+
|
|
40
|
+
### `applySort(entries, options?): Record<string, PrismaQueryValue>[]`
|
|
41
|
+
|
|
42
|
+
Converts `SortEntry[]` into a Prisma `orderBy` array.
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { applySort } from '@nestjs-filter-grammar/prisma';
|
|
46
|
+
|
|
47
|
+
const users = await prisma.user.findMany({
|
|
48
|
+
orderBy: applySort(sortEntries),
|
|
49
|
+
});
|
|
50
|
+
// orderBy: [{ name: 'asc' }, { age: 'desc' }]
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Column Mapping
|
|
54
|
+
|
|
55
|
+
**String rename:**
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
applyFilter(tree, {
|
|
59
|
+
columnMap: { name: 'userName' },
|
|
60
|
+
});
|
|
61
|
+
// { userName: { equals: 'John' } }
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**Callback for nested relations:**
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
applyFilter(tree, {
|
|
68
|
+
columnMap: {
|
|
69
|
+
department: (operator, values) => ({
|
|
70
|
+
department: { name: { equals: values[0].value } },
|
|
71
|
+
}),
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Sort column mapping:
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
applySort(entries, {
|
|
80
|
+
columnMap: {
|
|
81
|
+
department: (direction) => ({ department: { name: direction } }),
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
// [{ department: { name: 'asc' } }]
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Full Example
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
@Controller('users')
|
|
91
|
+
export class UsersController {
|
|
92
|
+
constructor(private readonly prisma: PrismaService) {}
|
|
93
|
+
|
|
94
|
+
@Get()
|
|
95
|
+
async findAll(@Filter(UserQuery, { optional: true }) { filter, sort }: FilterResult) {
|
|
96
|
+
return this.prisma.user.findMany({
|
|
97
|
+
where: filter ? applyFilter(filter) : undefined,
|
|
98
|
+
orderBy: sort ? applySort(sort) : undefined,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { FilterTree } from '@nestjs-filter-grammar/core';
|
|
2
|
+
import type { ApplyFilterOptions, PrismaQueryValue } from './types';
|
|
3
|
+
export declare function applyFilter(tree: FilterTree, options?: ApplyFilterOptions): Record<string, PrismaQueryValue>;
|
|
4
|
+
//# sourceMappingURL=apply-filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-filter.d.ts","sourceRoot":"","sources":["../src/apply-filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAGX,MAAM,6BAA6B,CAAC;AAErC,OAAO,KAAK,EAAE,kBAAkB,EAAqB,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEvF,wBAAgB,WAAW,CACzB,IAAI,EAAE,UAAU,EAChB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAElC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyFilter = applyFilter;
|
|
4
|
+
const operators_1 = require("./operators");
|
|
5
|
+
function applyFilter(tree, options) {
|
|
6
|
+
return buildNode(tree, options?.columnMap);
|
|
7
|
+
}
|
|
8
|
+
function buildNode(node, columnMap) {
|
|
9
|
+
if ('field' in node) {
|
|
10
|
+
return buildCondition(node, columnMap);
|
|
11
|
+
}
|
|
12
|
+
return buildGroup(node, columnMap);
|
|
13
|
+
}
|
|
14
|
+
function buildGroup(group, columnMap) {
|
|
15
|
+
const children = group.conditions.map((c) => buildNode(c, columnMap));
|
|
16
|
+
return { [group.type]: children };
|
|
17
|
+
}
|
|
18
|
+
function buildCondition(condition, columnMap) {
|
|
19
|
+
// Check for column map callback
|
|
20
|
+
if (columnMap && condition.field in columnMap) {
|
|
21
|
+
const mapping = columnMap[condition.field];
|
|
22
|
+
if (typeof mapping === 'function') {
|
|
23
|
+
return mapping(condition.operator, condition.values);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
// Resolve column name
|
|
27
|
+
const column = (columnMap && typeof columnMap[condition.field] === 'string')
|
|
28
|
+
? columnMap[condition.field]
|
|
29
|
+
: condition.field;
|
|
30
|
+
const { values, operator } = condition;
|
|
31
|
+
const opMapping = (0, operators_1.getPrismaOperator)(operator);
|
|
32
|
+
const nullValues = values.filter((v) => v.type === 'null');
|
|
33
|
+
const scalarValues = values.filter((v) => v.type !== 'null');
|
|
34
|
+
// All null
|
|
35
|
+
if (scalarValues.length === 0 && nullValues.length > 0) {
|
|
36
|
+
if (opMapping.negate) {
|
|
37
|
+
return { [column]: { not: { equals: null } } };
|
|
38
|
+
}
|
|
39
|
+
return { [column]: { equals: null } };
|
|
40
|
+
}
|
|
41
|
+
// Multi-value: IN / NOT IN
|
|
42
|
+
if (scalarValues.length > 1) {
|
|
43
|
+
const vals = scalarValues.map((v) => v.value);
|
|
44
|
+
const inKey = opMapping.negate ? 'notIn' : 'in';
|
|
45
|
+
if (nullValues.length > 0) {
|
|
46
|
+
return {
|
|
47
|
+
OR: [
|
|
48
|
+
{ [column]: { [inKey]: vals } },
|
|
49
|
+
{ [column]: { equals: null } },
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return { [column]: { [inKey]: vals } };
|
|
54
|
+
}
|
|
55
|
+
// Single value
|
|
56
|
+
const rawValue = scalarValues.length > 0 ? scalarValues[0].value : null;
|
|
57
|
+
let fieldExpr = { [opMapping.key]: rawValue };
|
|
58
|
+
if (opMapping.insensitive) {
|
|
59
|
+
fieldExpr.mode = 'insensitive';
|
|
60
|
+
}
|
|
61
|
+
if (opMapping.negate) {
|
|
62
|
+
fieldExpr = { not: fieldExpr };
|
|
63
|
+
}
|
|
64
|
+
if (nullValues.length > 0 && rawValue !== null) {
|
|
65
|
+
return {
|
|
66
|
+
OR: [
|
|
67
|
+
{ [column]: fieldExpr },
|
|
68
|
+
{ [column]: { equals: null } },
|
|
69
|
+
],
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return { [column]: fieldExpr };
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=apply-filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-filter.js","sourceRoot":"","sources":["../src/apply-filter.ts"],"names":[],"mappings":";;AAQA,kCAKC;AARD,2CAAgD;AAGhD,SAAgB,WAAW,CACzB,IAAgB,EAChB,OAA4B;IAE5B,OAAO,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;AAC7C,CAAC;AAED,SAAS,SAAS,CAChB,IAAgB,EAChB,SAA2C;IAE3C,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;QACpB,OAAO,cAAc,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACzC,CAAC;I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,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC;IAEhF,IAAI,SAAS,CAAC,WAAW,EAAE,CAAC;QAC1B,SAAS,CAAC,IAAI,GAAG,aAAa,CAAC;IACjC,CAAC;IAED,IAAI,SAAS,CAAC,MAAM,EAAE,CAAC;QACrB,SAAS,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC;IACjC,CAAC;IAED,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QAC/C,OAAO;YACL,EAAE,EAAE;gBACF,EAAE,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE;gBACvB,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE;aAC/B;SACF,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SortEntry } from '@nestjs-filter-grammar/core';
|
|
2
|
+
import type { ApplySortOptions, PrismaQueryValue } from './types';
|
|
3
|
+
export declare function applySort(entries: SortEntry[], options?: ApplySortOptions): Record<string, PrismaQueryValue>[];
|
|
4
|
+
//# sourceMappingURL=apply-sort.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-sort.d.ts","sourceRoot":"","sources":["../src/apply-sort.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAmB,MAAM,SAAS,CAAC;AAEnF,wBAAgB,SAAS,CACvB,OAAO,EAAE,SAAS,EAAE,EACpB,OAAO,CAAC,EAAE,gBAAgB,GACzB,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,EAAE,CAcpC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applySort = applySort;
|
|
4
|
+
function applySort(entries, options) {
|
|
5
|
+
return entries.map((entry) => {
|
|
6
|
+
const direction = entry.direction;
|
|
7
|
+
if (options?.columnMap && entry.field in options.columnMap) {
|
|
8
|
+
const mapping = options.columnMap[entry.field];
|
|
9
|
+
if (typeof mapping === 'function') {
|
|
10
|
+
return mapping(direction);
|
|
11
|
+
}
|
|
12
|
+
return { [mapping]: direction };
|
|
13
|
+
}
|
|
14
|
+
return { [entry.field]: direction };
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=apply-sort.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-sort.js","sourceRoot":"","sources":["../src/apply-sort.ts"],"names":[],"mappings":";;AAGA,8BAiBC;AAjBD,SAAgB,SAAS,CACvB,OAAoB,EACpB,OAA0B;IAE1B,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QAC3B,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;QAElC,IAAI,OAAO,EAAE,SAAS,IAAI,KAAK,CAAC,KAAK,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;YAC3D,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC/C,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;gBAClC,OAAQ,OAA2B,CAAC,SAAS,CAAC,CAAC;YACjD,CAAC;YACD,OAAO,EAAE,CAAC,OAAiB,CAAC,EAAE,SAAS,EAAE,CAAC;QAC5C,CAAC;QAED,OAAO,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { applyFilter } from './apply-filter';
|
|
2
|
+
export { applySort } from './apply-sort';
|
|
3
|
+
export type { PrismaQueryValue, PrismaColumnMapFn, PrismaColumnMap, PrismaSortMapFn, PrismaSortMap, ApplyFilterOptions, ApplySortOptions, } from './types';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,YAAY,EACV,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applySort = exports.applyFilter = void 0;
|
|
4
|
+
var apply_filter_1 = require("./apply-filter");
|
|
5
|
+
Object.defineProperty(exports, "applyFilter", { enumerable: true, get: function () { return apply_filter_1.applyFilter; } });
|
|
6
|
+
var apply_sort_1 = require("./apply-sort");
|
|
7
|
+
Object.defineProperty(exports, "applySort", { enumerable: true, get: function () { return apply_sort_1.applySort; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AACpB,2CAAyC;AAAhC,uGAAA,SAAS,OAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FilterOperator } from '@nestjs-filter-grammar/core';
|
|
2
|
+
export type PrismaOperatorKey = 'equals' | 'not' | 'gt' | 'lt' | 'gte' | 'lte' | 'startsWith' | 'endsWith' | 'contains';
|
|
3
|
+
export interface PrismaOperatorMapping {
|
|
4
|
+
key: PrismaOperatorKey;
|
|
5
|
+
insensitive?: boolean;
|
|
6
|
+
negate?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function getPrismaOperator(op: FilterOperator): PrismaOperatorMapping;
|
|
9
|
+
//# sourceMappingURL=operators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operators.d.ts","sourceRoot":"","sources":["../src/operators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D,MAAM,MAAM,iBAAiB,GACzB,QAAQ,GACR,KAAK,GACL,IAAI,GACJ,IAAI,GACJ,KAAK,GACL,KAAK,GACL,YAAY,GACZ,UAAU,GACV,UAAU,CAAC;AAEf,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,iBAAiB,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAmBD,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,cAAc,GAAG,qBAAqB,CAE3E"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPrismaOperator = getPrismaOperator;
|
|
4
|
+
const core_1 = require("@nestjs-filter-grammar/core");
|
|
5
|
+
const OPERATOR_MAP = {
|
|
6
|
+
[core_1.FilterOperator.eq]: { key: 'equals' },
|
|
7
|
+
[core_1.FilterOperator.neq]: { key: 'equals', negate: true },
|
|
8
|
+
[core_1.FilterOperator.gt]: { key: 'gt' },
|
|
9
|
+
[core_1.FilterOperator.lt]: { key: 'lt' },
|
|
10
|
+
[core_1.FilterOperator.gte]: { key: 'gte' },
|
|
11
|
+
[core_1.FilterOperator.lte]: { key: 'lte' },
|
|
12
|
+
[core_1.FilterOperator.iEq]: { key: 'equals', insensitive: true },
|
|
13
|
+
[core_1.FilterOperator.iNeq]: { key: 'equals', negate: true, insensitive: true },
|
|
14
|
+
[core_1.FilterOperator.startsWith]: { key: 'startsWith' },
|
|
15
|
+
[core_1.FilterOperator.endsWith]: { key: 'endsWith' },
|
|
16
|
+
[core_1.FilterOperator.contains]: { key: 'contains' },
|
|
17
|
+
[core_1.FilterOperator.iStartsWith]: { key: 'startsWith', insensitive: true },
|
|
18
|
+
[core_1.FilterOperator.iEndsWith]: { key: 'endsWith', insensitive: true },
|
|
19
|
+
[core_1.FilterOperator.iContains]: { key: 'contains', insensitive: true },
|
|
20
|
+
};
|
|
21
|
+
function getPrismaOperator(op) {
|
|
22
|
+
return OPERATOR_MAP[op];
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=operators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operators.js","sourceRoot":"","sources":["../src/operators.ts"],"names":[],"mappings":";;AAoCA,8CAEC;AAtCD,sDAA6D;AAmB7D,MAAM,YAAY,GAAkD;IAClE,CAAC,qBAAc,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE;IACtC,CAAC,qBAAc,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE;IACrD,CAAC,qBAAc,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE;IAClC,CAAC,qBAAc,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE;IAClC,CAAC,qBAAc,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE;IACpC,CAAC,qBAAc,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE;IACpC,CAAC,qBAAc,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE;IAC1D,CAAC,qBAAc,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE;IACzE,CAAC,qBAAc,CAAC,UAAU,CAAC,EAAE,EAAE,GAAG,EAAE,YAAY,EAAE;IAClD,CAAC,qBAAc,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE;IAC9C,CAAC,qBAAc,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE;IAC9C,CAAC,qBAAc,CAAC,WAAW,CAAC,EAAE,EAAE,GAAG,EAAE,YAAY,EAAE,WAAW,EAAE,IAAI,EAAE;IACtE,CAAC,qBAAc,CAAC,SAAS,CAAC,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE,WAAW,EAAE,IAAI,EAAE;IAClE,CAAC,qBAAc,CAAC,SAAS,CAAC,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE,WAAW,EAAE,IAAI,EAAE;CACnE,CAAC;AAEF,SAAgB,iBAAiB,CAAC,EAAkB;IAClD,OAAO,YAAY,CAAC,EAAE,CAAC,CAAC;AAC1B,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FilterOperator, FilterValue } from '@nestjs-filter-grammar/core';
|
|
2
|
+
/** Recursive type representing a Prisma where/orderBy object value */
|
|
3
|
+
export type PrismaQueryValue = string | number | boolean | null | PrismaQueryValue[] | {
|
|
4
|
+
[key: string]: PrismaQueryValue;
|
|
5
|
+
};
|
|
6
|
+
export type PrismaColumnMapFn = (operator: FilterOperator, values: FilterValue[]) => Record<string, PrismaQueryValue>;
|
|
7
|
+
export type PrismaColumnMap = Record<string, string | PrismaColumnMapFn>;
|
|
8
|
+
export type PrismaSortMapFn = (direction: 'asc' | 'desc') => Record<string, PrismaQueryValue>;
|
|
9
|
+
export type PrismaSortMap = Record<string, string | PrismaSortMapFn>;
|
|
10
|
+
export interface ApplyFilterOptions {
|
|
11
|
+
columnMap?: PrismaColumnMap;
|
|
12
|
+
}
|
|
13
|
+
export interface ApplySortOptions {
|
|
14
|
+
columnMap?: PrismaSortMap;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE/E,sEAAsE;AACtE,MAAM,MAAM,gBAAgB,GACxB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,gBAAgB,EAAE,GAClB;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,gBAAgB,CAAA;CAAE,CAAC;AAExC,MAAM,MAAM,iBAAiB,GAAG,CAC9B,QAAQ,EAAE,cAAc,EACxB,MAAM,EAAE,WAAW,EAAE,KAClB,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;AAEtC,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAAC,CAAC;AAEzE,MAAM,MAAM,eAAe,GAAG,CAC5B,SAAS,EAAE,KAAK,GAAG,MAAM,KACtB,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;AAEtC,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,eAAe,CAAC,CAAC;AAErE,MAAM,WAAW,kBAAkB;IACjC,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,EAAE,aAAa,CAAC;CAC3B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nestjs-filter-grammar/prisma",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Prisma adapter for @nestjs-filter-grammar — translates FilterTree into Prisma where/orderBy objects",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc -p tsconfig.build.json",
|
|
9
|
+
"test": "vitest run",
|
|
10
|
+
"test:watch": "vitest",
|
|
11
|
+
"typecheck": "tsc --noEmit"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@nestjs-filter-grammar/core": "workspace:*"
|
|
15
|
+
},
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"@prisma/client": ">=5.0.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@prisma/client": "^6.0.0"
|
|
21
|
+
},
|
|
22
|
+
"files": ["dist"]
|
|
23
|
+
}
|