@matvdt/js-toolkit 0.0.1-canary.11 → 0.0.1-canary.12
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CollectionSlug, Where } from 'payload';
|
|
2
|
-
import { db, DeleteOptions, FindAllOptions, UpdateData, UpdateOptions } from './db';
|
|
2
|
+
import { db, DeleteOptions, FindAllOptions, FindOptions, UpdateData, UpdateOptions } from './db';
|
|
3
3
|
export type BaseCollectionMethods<TSlug extends CollectionSlug> = {
|
|
4
|
-
findOne: (
|
|
4
|
+
findOne: (options?: FindOptions) => ReturnType<typeof db.findOne<TSlug>>;
|
|
5
5
|
findBySlug: (slug: string) => ReturnType<typeof db.findBySlug<TSlug>>;
|
|
6
6
|
findByID: (id: string | number) => ReturnType<typeof db.findByID<TSlug>>;
|
|
7
7
|
findAll: (options?: FindAllOptions) => ReturnType<typeof db.findAll<TSlug>>;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { CollectionSlug, DataFromCollectionSlug, DataFromGlobalSlug, GlobalSlug, Where } from 'payload';
|
|
2
2
|
import { getPayload } from './get-payload';
|
|
3
|
+
export type FindOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['find']>[0], 'collection'>;
|
|
3
4
|
export type FindAllOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['find']>[0], 'collection'>;
|
|
4
5
|
export type UpdateOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['update']>[0], 'collection' | 'id' | 'data' | 'where'>;
|
|
5
6
|
export type DeleteOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['delete']>[0], 'collection' | 'id' | 'where'>;
|
|
6
7
|
export type UpdateData = Parameters<Awaited<ReturnType<typeof getPayload>>['update']>[0]['data'];
|
|
7
8
|
export declare const db: {
|
|
8
|
-
findOne: <TSlug extends CollectionSlug>(collection: TSlug,
|
|
9
|
+
findOne: <TSlug extends CollectionSlug>(collection: TSlug, options?: FindOptions) => Promise<DataFromCollectionSlug<TSlug>>;
|
|
9
10
|
findBySlug: <TSlug extends CollectionSlug>(collection: TSlug, slug: string) => Promise<DataFromCollectionSlug<TSlug>>;
|
|
10
11
|
findAll: <TSlug extends CollectionSlug>(collection: TSlug, options?: FindAllOptions) => Promise<DataFromCollectionSlug<TSlug>[]>;
|
|
11
12
|
findByID: <TSlug extends CollectionSlug>(collection: TSlug, id: string | number) => Promise<DataFromCollectionSlug<TSlug>>;
|
|
@@ -53,20 +53,24 @@ var getClient = (0, import_react.cache)(async () => {
|
|
|
53
53
|
return await getPayload();
|
|
54
54
|
});
|
|
55
55
|
var db = {
|
|
56
|
-
findOne: async (collection,
|
|
56
|
+
findOne: async (collection, options) => {
|
|
57
57
|
const payload = await getClient();
|
|
58
|
-
const res = await payload.find({
|
|
58
|
+
const res = await payload.find({
|
|
59
|
+
...options,
|
|
60
|
+
collection,
|
|
61
|
+
limit: 1
|
|
62
|
+
});
|
|
59
63
|
return res.docs[0] ?? null;
|
|
60
64
|
},
|
|
61
65
|
findBySlug: async (collection, slug) => {
|
|
62
|
-
return db.findOne(collection, { slug: { equals: slug } });
|
|
66
|
+
return db.findOne(collection, { where: { slug: { equals: slug } } });
|
|
63
67
|
},
|
|
64
68
|
findAll: async (collection, options) => {
|
|
65
69
|
const payload = await getClient();
|
|
66
70
|
const res = await payload.find({
|
|
71
|
+
...options,
|
|
67
72
|
collection,
|
|
68
|
-
limit: options?.limit ?? 100
|
|
69
|
-
...options
|
|
73
|
+
limit: options?.limit ?? 100
|
|
70
74
|
});
|
|
71
75
|
return res.docs;
|
|
72
76
|
},
|
|
@@ -76,43 +80,47 @@ var db = {
|
|
|
76
80
|
},
|
|
77
81
|
create: async (collection, data, options) => {
|
|
78
82
|
const payload = await getClient();
|
|
79
|
-
return payload.create({
|
|
83
|
+
return payload.create({
|
|
84
|
+
...options,
|
|
85
|
+
collection,
|
|
86
|
+
data
|
|
87
|
+
});
|
|
80
88
|
},
|
|
81
89
|
update: async (collection, id, data, options) => {
|
|
82
90
|
const payload = await getClient();
|
|
83
91
|
return payload.update({
|
|
92
|
+
...options,
|
|
84
93
|
collection,
|
|
85
94
|
id,
|
|
86
|
-
data
|
|
87
|
-
...options
|
|
95
|
+
data
|
|
88
96
|
});
|
|
89
97
|
},
|
|
90
98
|
updateMany: async (collection, where, data, options) => {
|
|
91
99
|
const payload = await getClient();
|
|
92
100
|
return payload.update({
|
|
101
|
+
...options,
|
|
93
102
|
collection,
|
|
94
103
|
where,
|
|
95
104
|
data,
|
|
96
|
-
...options,
|
|
97
105
|
id: void 0
|
|
98
106
|
});
|
|
99
107
|
},
|
|
100
108
|
delete: async (collection, id, options) => {
|
|
101
109
|
const payload = await getClient();
|
|
102
110
|
return payload.delete({
|
|
111
|
+
...options,
|
|
103
112
|
collection,
|
|
104
113
|
id,
|
|
105
|
-
where: void 0
|
|
106
|
-
...options
|
|
114
|
+
where: void 0
|
|
107
115
|
});
|
|
108
116
|
},
|
|
109
117
|
deleteMany: async (collection, where, options) => {
|
|
110
118
|
const payload = await getClient();
|
|
111
119
|
return payload.delete({
|
|
120
|
+
...options,
|
|
112
121
|
collection,
|
|
113
122
|
where,
|
|
114
|
-
id: void 0
|
|
115
|
-
...options
|
|
123
|
+
id: void 0
|
|
116
124
|
});
|
|
117
125
|
},
|
|
118
126
|
global: async (slug) => {
|
|
@@ -125,7 +133,7 @@ var db = {
|
|
|
125
133
|
// src/payload-cms/server/create-collection.ts
|
|
126
134
|
function createCollection(collection, extend) {
|
|
127
135
|
const base = {
|
|
128
|
-
findOne: (
|
|
136
|
+
findOne: (options) => db.findOne(collection, options),
|
|
129
137
|
findByID: (id) => db.findByID(collection, id),
|
|
130
138
|
findBySlug: (slug) => db.findBySlug(collection, slug),
|
|
131
139
|
findAll: (options) => db.findAll(collection, options),
|
|
@@ -23,20 +23,24 @@ var getClient = cache(async () => {
|
|
|
23
23
|
return await getPayload();
|
|
24
24
|
});
|
|
25
25
|
var db = {
|
|
26
|
-
findOne: async (collection,
|
|
26
|
+
findOne: async (collection, options) => {
|
|
27
27
|
const payload = await getClient();
|
|
28
|
-
const res = await payload.find({
|
|
28
|
+
const res = await payload.find({
|
|
29
|
+
...options,
|
|
30
|
+
collection,
|
|
31
|
+
limit: 1
|
|
32
|
+
});
|
|
29
33
|
return res.docs[0] ?? null;
|
|
30
34
|
},
|
|
31
35
|
findBySlug: async (collection, slug) => {
|
|
32
|
-
return db.findOne(collection, { slug: { equals: slug } });
|
|
36
|
+
return db.findOne(collection, { where: { slug: { equals: slug } } });
|
|
33
37
|
},
|
|
34
38
|
findAll: async (collection, options) => {
|
|
35
39
|
const payload = await getClient();
|
|
36
40
|
const res = await payload.find({
|
|
41
|
+
...options,
|
|
37
42
|
collection,
|
|
38
|
-
limit: options?.limit ?? 100
|
|
39
|
-
...options
|
|
43
|
+
limit: options?.limit ?? 100
|
|
40
44
|
});
|
|
41
45
|
return res.docs;
|
|
42
46
|
},
|
|
@@ -46,43 +50,47 @@ var db = {
|
|
|
46
50
|
},
|
|
47
51
|
create: async (collection, data, options) => {
|
|
48
52
|
const payload = await getClient();
|
|
49
|
-
return payload.create({
|
|
53
|
+
return payload.create({
|
|
54
|
+
...options,
|
|
55
|
+
collection,
|
|
56
|
+
data
|
|
57
|
+
});
|
|
50
58
|
},
|
|
51
59
|
update: async (collection, id, data, options) => {
|
|
52
60
|
const payload = await getClient();
|
|
53
61
|
return payload.update({
|
|
62
|
+
...options,
|
|
54
63
|
collection,
|
|
55
64
|
id,
|
|
56
|
-
data
|
|
57
|
-
...options
|
|
65
|
+
data
|
|
58
66
|
});
|
|
59
67
|
},
|
|
60
68
|
updateMany: async (collection, where, data, options) => {
|
|
61
69
|
const payload = await getClient();
|
|
62
70
|
return payload.update({
|
|
71
|
+
...options,
|
|
63
72
|
collection,
|
|
64
73
|
where,
|
|
65
74
|
data,
|
|
66
|
-
...options,
|
|
67
75
|
id: void 0
|
|
68
76
|
});
|
|
69
77
|
},
|
|
70
78
|
delete: async (collection, id, options) => {
|
|
71
79
|
const payload = await getClient();
|
|
72
80
|
return payload.delete({
|
|
81
|
+
...options,
|
|
73
82
|
collection,
|
|
74
83
|
id,
|
|
75
|
-
where: void 0
|
|
76
|
-
...options
|
|
84
|
+
where: void 0
|
|
77
85
|
});
|
|
78
86
|
},
|
|
79
87
|
deleteMany: async (collection, where, options) => {
|
|
80
88
|
const payload = await getClient();
|
|
81
89
|
return payload.delete({
|
|
90
|
+
...options,
|
|
82
91
|
collection,
|
|
83
92
|
where,
|
|
84
|
-
id: void 0
|
|
85
|
-
...options
|
|
93
|
+
id: void 0
|
|
86
94
|
});
|
|
87
95
|
},
|
|
88
96
|
global: async (slug) => {
|
|
@@ -95,7 +103,7 @@ var db = {
|
|
|
95
103
|
// src/payload-cms/server/create-collection.ts
|
|
96
104
|
function createCollection(collection, extend) {
|
|
97
105
|
const base = {
|
|
98
|
-
findOne: (
|
|
106
|
+
findOne: (options) => db.findOne(collection, options),
|
|
99
107
|
findByID: (id) => db.findByID(collection, id),
|
|
100
108
|
findBySlug: (slug) => db.findBySlug(collection, slug),
|
|
101
109
|
findAll: (options) => db.findAll(collection, options),
|