@bhofstaetter/payloadcms-repository 0.1.0 → 1.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 +16 -16
- package/dist/collection/{CollectionQuery.d.ts → CollectionOperations.d.ts} +2 -2
- package/dist/collection/{CollectionQuery.js → CollectionOperations.js} +1 -1
- package/dist/collection/CollectionRepository.d.ts +1 -1
- package/dist/global/{GlobalQuery.d.ts → GlobalOperations.d.ts} +2 -2
- package/dist/global/{GlobalQuery.js → GlobalOperations.js} +1 -1
- package/dist/global/GlobalRepository.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/package.json +10 -7
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# payload-repository
|
|
2
2
|
|
|
3
|
-
Opinionated repository and
|
|
3
|
+
Opinionated repository and operations object wrapper around Payload's Local API.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -12,16 +12,16 @@ npm install @bhofstaetter/payloadcms-repository
|
|
|
12
12
|
|
|
13
13
|
Pass your generated Payload `Config` type as the first type argument to get full type safety on fields, select, and return types.
|
|
14
14
|
|
|
15
|
-
###
|
|
15
|
+
### CollectionOperations
|
|
16
16
|
|
|
17
|
-
Extend `
|
|
17
|
+
Extend `CollectionOperations` to encapsulate domain-specific operations logic for a collection:
|
|
18
18
|
|
|
19
19
|
```ts
|
|
20
20
|
import type {BasePayload} from 'payload';
|
|
21
21
|
import type {Config} from '@/payload-types';
|
|
22
|
-
import {
|
|
22
|
+
import {CollectionOperations} from '@bhofstaetter/payloadcms-repository';
|
|
23
23
|
|
|
24
|
-
class
|
|
24
|
+
class PostsOperations extends CollectionOperations<Config, 'posts'> {
|
|
25
25
|
constructor(payload: BasePayload) {
|
|
26
26
|
super(payload, 'posts');
|
|
27
27
|
}
|
|
@@ -52,23 +52,23 @@ class PostsQuery extends CollectionQuery<Config, 'posts'> {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
// Usage
|
|
55
|
-
const
|
|
55
|
+
const postsOperations = new PostsOperations(payload);
|
|
56
56
|
|
|
57
|
-
const post = await
|
|
58
|
-
const published = await
|
|
59
|
-
await
|
|
57
|
+
const post = await postsOperations.create('Hello World');
|
|
58
|
+
const published = await postsOperations.findPublished();
|
|
59
|
+
await postsOperations.publish(post.id);
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
###
|
|
62
|
+
### GlobalOperations
|
|
63
63
|
|
|
64
|
-
Extend `
|
|
64
|
+
Extend `GlobalOperations` to encapsulate domain-specific operations logic for a global:
|
|
65
65
|
|
|
66
66
|
```ts
|
|
67
67
|
import type {BasePayload} from 'payload';
|
|
68
68
|
import type {Config} from '@/payload-types';
|
|
69
|
-
import {
|
|
69
|
+
import {GlobalOperations} from '@bhofstaetter/payloadcms-repository';
|
|
70
70
|
|
|
71
|
-
class
|
|
71
|
+
class SettingsOperations extends GlobalOperations<Config, 'settings'> {
|
|
72
72
|
constructor(payload: BasePayload) {
|
|
73
73
|
super(payload, 'settings');
|
|
74
74
|
}
|
|
@@ -83,10 +83,10 @@ class SettingsQuery extends GlobalQuery<Config, 'settings'> {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
// Usage
|
|
86
|
-
const
|
|
86
|
+
const settingsOperations = new SettingsOperations(payload);
|
|
87
87
|
|
|
88
|
-
const settings = await
|
|
89
|
-
await
|
|
88
|
+
const settings = await settingsOperations.get();
|
|
89
|
+
await settingsOperations.setSiteTitle('My Site');
|
|
90
90
|
```
|
|
91
91
|
|
|
92
92
|
## License
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BasePayload, CollectionSlug } from 'payload';
|
|
2
|
-
import type { AnyCollectionConfig } from '
|
|
2
|
+
import type { AnyCollectionConfig } from '../types';
|
|
3
3
|
import { CollectionRepository } from './CollectionRepository';
|
|
4
|
-
export declare abstract class
|
|
4
|
+
export declare abstract class CollectionOperations<TConfig extends AnyCollectionConfig, TSlug extends CollectionSlug> {
|
|
5
5
|
protected readonly repository: CollectionRepository<TConfig, TSlug>;
|
|
6
6
|
protected constructor(payload: BasePayload, collectionSlug: TSlug);
|
|
7
7
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BasePayload, BulkOperationResult, CollectionSlug, DataFromCollectionSlug, PaginatedDistinctDocs, PaginatedDocs, RequiredDataFromCollectionSlug, SelectType, TransformCollectionWithSelect, TypeWithVersion, Where } from 'payload';
|
|
2
2
|
import type { DeepPartial } from 'ts-essentials';
|
|
3
|
-
import type { AnyCollectionConfig, DbId } from '
|
|
3
|
+
import type { AnyCollectionConfig, DbId } from '../types';
|
|
4
4
|
export declare class CollectionRepository<TConfig extends AnyCollectionConfig, TSlug extends CollectionSlug> {
|
|
5
5
|
protected readonly payload: BasePayload;
|
|
6
6
|
protected readonly collectionSlug: TSlug;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BasePayload, GlobalSlug } from 'payload';
|
|
2
|
-
import type { AnyGlobalConfig } from '
|
|
2
|
+
import type { AnyGlobalConfig } from '../types';
|
|
3
3
|
import { GlobalRepository } from './GlobalRepository';
|
|
4
|
-
export declare abstract class
|
|
4
|
+
export declare abstract class GlobalOperations<TConfig extends AnyGlobalConfig, TSlug extends GlobalSlug> {
|
|
5
5
|
protected readonly repository: GlobalRepository<TConfig, TSlug>;
|
|
6
6
|
protected constructor(payload: BasePayload, globalSlug: TSlug);
|
|
7
7
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BasePayload, DataFromGlobalSlug, GlobalSlug, PaginatedDocs, SelectType, TransformGlobalWithSelect, TypeWithVersion } from 'payload';
|
|
2
2
|
import type { DeepPartial } from 'ts-essentials';
|
|
3
|
-
import type { AnyGlobalConfig, DbId } from '
|
|
3
|
+
import type { AnyGlobalConfig, DbId } from '../types';
|
|
4
4
|
export declare class GlobalRepository<TConfig extends AnyGlobalConfig, TSlug extends GlobalSlug> {
|
|
5
5
|
protected readonly payload: BasePayload;
|
|
6
6
|
protected readonly globalSlug: TSlug;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { CollectionOperations } from './collection/CollectionOperations';
|
|
2
2
|
export { CollectionRepository } from './collection/CollectionRepository';
|
|
3
|
-
export {
|
|
3
|
+
export { GlobalOperations } from './global/GlobalOperations';
|
|
4
4
|
export { GlobalRepository } from './global/GlobalRepository';
|
|
5
5
|
export type { AnyCollectionConfig, AnyGlobalConfig, DbId } from './types.js';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { CollectionOperations } from './collection/CollectionOperations';
|
|
2
2
|
export { CollectionRepository } from './collection/CollectionRepository';
|
|
3
|
-
export {
|
|
3
|
+
export { GlobalOperations } from './global/GlobalOperations';
|
|
4
4
|
export { GlobalRepository } from './global/GlobalRepository';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bhofstaetter/payloadcms-repository",
|
|
3
|
-
"version": "0.1
|
|
4
|
-
"description": "Opinionated repository and
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Opinionated repository and operations object wrapper around Payload's Local API.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Benedikt Hofstätter",
|
|
7
7
|
"homepage": "https://github.com/bhofstaetter/payloadcms-repository",
|
|
@@ -29,23 +29,26 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
|
-
"build": "tsc -p tsconfig.build.json",
|
|
32
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
|
|
33
33
|
"typecheck": "tsc",
|
|
34
34
|
"lint": "biome check",
|
|
35
35
|
"lint:fix": "biome check --fix",
|
|
36
|
-
"
|
|
36
|
+
"test": "vitest run",
|
|
37
|
+
"prepublishOnly": "npm run lint && npm run typecheck && npm run test && npm run build"
|
|
37
38
|
},
|
|
38
39
|
"peerDependencies": {
|
|
39
40
|
"payload": ">=3",
|
|
40
41
|
"ts-essentials": ">=10"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
|
-
"
|
|
44
|
+
"@bhofstaetter/payloadcms-it-helper": "^1.0.0",
|
|
45
|
+
"@biomejs/biome": "2.4.4",
|
|
44
46
|
"@payloadcms/db-postgres": "^3.78.0",
|
|
47
|
+
"@testcontainers/postgresql": "^11.11.0",
|
|
48
|
+
"payload": "^3.78.0",
|
|
45
49
|
"ts-essentials": "^10.0.0",
|
|
50
|
+
"tsc-alias": "^1.8.16",
|
|
46
51
|
"typescript": "^5",
|
|
47
|
-
"@biomejs/biome": "2.4.4",
|
|
48
|
-
"@testcontainers/postgresql": "^11.11.0",
|
|
49
52
|
"vite-tsconfig-paths": "^6.1.1",
|
|
50
53
|
"vitest": "^4.0.18"
|
|
51
54
|
},
|