generated from payloadcms/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* pass after operation, fields select package * add fields-select package * fields select doc * bump * publish script * publish scripts
- Loading branch information
Showing
22 changed files
with
1,600 additions
and
958 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
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
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** @type {import('eslint').Linter.Config} */ | ||
module.exports = { | ||
extends: ['../../.eslintrc.cjs'], | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? | ||
|
||
tsconfig.tsbuildinfo |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/swcrc", | ||
"sourceMaps": true, | ||
"jsc": { | ||
"target": "esnext", | ||
"parser": { | ||
"syntax": "typescript", | ||
"tsx": true, | ||
"dts": true | ||
}, | ||
"transform": { | ||
"react": { | ||
"runtime": "automatic" | ||
} | ||
} | ||
}, | ||
"module": { | ||
"type": "es6" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Fields select plugin for Payload 3.0 | ||
|
||
## Install | ||
|
||
`pnpm add @payload-enchants/fields-select` | ||
|
||
In your payload.config.ts: | ||
|
||
```ts | ||
/// .... | ||
import { fieldsSelect } from '@payload-enchants/fields-select'; | ||
|
||
export default buildConfig({ | ||
// ... | ||
plugins: [fieldsSelect()], | ||
}); | ||
``` | ||
|
||
## Description | ||
|
||
Adds an option to select fields from Local API / REST API response like with GraphQL | ||
As well solves a problem, when you need only specific fields to populate from relationship field with `defaultSelect` option | ||
Could significally reduce your pages data sizes, especially when they are related to each other. | ||
PR with more powerful version of this to Payload - https://github.com/payloadcms/payload/pull/5942 | ||
|
||
## Usage | ||
|
||
### Local API: | ||
|
||
```ts | ||
/** As well findByID **/ | ||
payload.find({ | ||
collection: 'posts', | ||
context: { | ||
/** | ||
* Selects: | ||
* top level id, title fields | ||
* text field from "nestedGroup" group field | ||
* all fields from "nestedArray" field | ||
* "title" field from populated relationship document | ||
**/ | ||
select: ['id', 'title', 'nestedGroup.text', 'nestedArray', 'relationship.title'], | ||
}, | ||
}); | ||
``` | ||
|
||
### REST API: | ||
|
||
Use `select` query parameter, example: | ||
`?select[0]=id&select[1]=title` | ||
|
||
### Default Select option for relationship fields | ||
|
||
```ts | ||
const linkField: RelationshipField = { | ||
custom: { | ||
/** Field will be populated only with id, slug and title fields **/ | ||
defaultSelect: ['id', 'slug', 'title'], | ||
}, | ||
name: 'link', | ||
relationTo: 'pages', | ||
}; | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"name": "@payload-enchants/fields-select", | ||
"version": "1.1.39", | ||
"private": false, | ||
"bugs": "https://github.com/r1tsuu/payload-enchants/issues", | ||
"repository": "https://github.com/r1tsuu/payload-enchants", | ||
"license": "MIT", | ||
"author": "r1tsuu", | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"import": "./src/index.ts", | ||
"require": "./src/index.ts", | ||
"types": "./src/index.ts" | ||
} | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "pnpm copyfiles && pnpm build:swc && pnpm build:types", | ||
"build:swc": "swc ./src -d ./dist --config-file .swcrc", | ||
"build:types": "tsc --emitDeclarationOnly --outDir dist", | ||
"clean": "rimraf dist && rimraf tsconfig.tsbuildinfo", | ||
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/", | ||
"lint": "eslint src", | ||
"lint:fix": "eslint --fix --ext .ts,.tsx src", | ||
"prepublishOnly": "pnpm clean && pnpm build" | ||
}, | ||
"devDependencies": { | ||
"payload": "3.0.0-beta.41", | ||
"typescript": "^5.4.5" | ||
}, | ||
"peerDependencies": { | ||
"payload": "^3.0.0-beta.41" | ||
}, | ||
"publishConfig": { | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.js", | ||
"types": "./dist/index.d.ts" | ||
} | ||
}, | ||
"main": "./dist/index.js", | ||
"registry": "https://registry.npmjs.org/", | ||
"types": "./dist/index.d.ts" | ||
} | ||
} |
Oops, something went wrong.