-
-
Notifications
You must be signed in to change notification settings - Fork 753
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add hook-less methods and service option types to adapter-commo…
…ns (#1433)
- Loading branch information
Showing
15 changed files
with
160 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
test/ | ||
tsconfig.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 8 additions & 14 deletions
22
packages/adapter-commons/lib/index.js → packages/adapter-commons/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,32 @@ | ||
const { _ } = require('@feathersjs/commons'); | ||
import { _ } from '@feathersjs/commons'; | ||
|
||
const AdapterService = require('./service'); | ||
const filterQuery = require('./filter-query'); | ||
const sort = require('./sort'); | ||
export { AdapterService, InternalServiceMethods, ServiceOptions } from './service'; | ||
export { default as filterQuery, FILTERS, OPERATORS } from './filter-query'; | ||
export * from './sort'; | ||
|
||
// Return a function that filters a result object or array | ||
// and picks only the fields passed as `params.query.$select` | ||
// and additional `otherFields` | ||
const select = function select (params, ...otherFields) { | ||
export function select (params: any, ...otherFields: any[]) { | ||
const fields = params && params.query && params.query.$select; | ||
|
||
if (Array.isArray(fields) && otherFields.length) { | ||
fields.push(...otherFields); | ||
} | ||
|
||
const convert = result => { | ||
const convert = (result: any) => { | ||
if (!Array.isArray(fields)) { | ||
return result; | ||
} | ||
|
||
return _.pick(result, ...fields); | ||
}; | ||
|
||
return result => { | ||
return (result: any) => { | ||
if (Array.isArray(result)) { | ||
return result.map(convert); | ||
} | ||
|
||
return convert(result); | ||
}; | ||
}; | ||
|
||
module.exports = Object.assign({ | ||
select, | ||
filterQuery, | ||
AdapterService | ||
}, sort); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.