Skip to content

Commit

Permalink
refactor: Replace matcher by outmatch
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
Configuration `useInputType` changed underlying library for pattern matching
https://github.com/axtgr/outmatch, prefix renamed to `match:`
  • Loading branch information
unlight committed Sep 6, 2021
1 parent a00156b commit fa7c003
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ Where:
Example: `UserCreateInput` full name, `WhereInput` partial name, matches `UserWhereInput`, `PostWhereInput`, etc.
- `property` Property of the class for which need to choose type. Special case name `ALL` means any / all properties.
- `pattern` Part of name (or full) of type which should be chosen, you can use
wild card or negate symbols, in this case pattern should starts with `matcher:`,
e.g. `matcher:*UncheckedCreateInput` See [matcher](https://github.com/sindresorhus/matcher) for details.
wild card or negate symbols, in this case pattern should starts with `match:`,
e.g. `match:*UncheckedCreateInput` see [outmatch](https://github.com/axtgr/outmatch#usage) for details.

Example:

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"get-relative-path": "^1.0.2",
"json5": "^2.2.0",
"lodash": "^4.17.21",
"matcher": "^4.0.0",
"outmatch": "^0.7.0",
"pluralize": "^8.0.0",
"pupa": "2.X",
Expand Down
12 changes: 6 additions & 6 deletions src/helpers/get-graphql-input-type.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { countBy } from 'lodash';
import matcher from 'matcher';
import outmatch from 'outmatch';

import { DMMF } from '../types';

Expand Down Expand Up @@ -29,11 +29,11 @@ export function getGraphqlInputType(
}

if (pattern) {
if (pattern.startsWith('matcher:')) {
const patternValue = pattern.slice(8);
result = inputTypes.find(x =>
matcher.isMatch(String(x.type), patternValue),
);
if (pattern.startsWith('matcher:') || pattern.startsWith('match:')) {
const { 1: patternValue } = pattern.split(':', 2);
console.log('patternValue', patternValue);
const isMatch = outmatch(patternValue, { separator: false });
result = inputTypes.find(x => isMatch(String(x.type)));
if (result) {
return result;
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/generate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1775,9 +1775,9 @@ describe('select input type', () => {
`,
options: [
`outputFilePattern = "{name}.{type}.ts"`,
`useInputType_UpdateInput_ALL = "matcher:!*FieldUpdateOperationsInput"`,
`useInputType_UpdateMany_ALL = "matcher:!*FieldUpdateOperationsInput"`,
`useInputType_UpdateWithout_ALL = "matcher:!*FieldUpdateOperationsInput"`,
`useInputType_UpdateInput_ALL = "match:!*FieldUpdateOperationsInput"`,
`useInputType_UpdateMany_ALL = "match:!*FieldUpdateOperationsInput"`,
`useInputType_UpdateWithout_ALL = "match:!*FieldUpdateOperationsInput"`,
],
}));
});
Expand Down

0 comments on commit fa7c003

Please sign in to comment.