@matvdt/js-toolkit 0.0.1-canary.14 → 0.0.1-canary.15
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,10 +1,11 @@
|
|
|
1
1
|
import type { CollectionSlug, Where } from 'payload';
|
|
2
|
-
import { db, DeleteOptions,
|
|
2
|
+
import { db, DeleteOptions, FindByIDOptions, FindOptions, UpdateData, UpdateOptions } from './db';
|
|
3
3
|
export type BaseCollectionMethods<TSlug extends CollectionSlug> = {
|
|
4
|
+
find: (options?: FindOptions) => ReturnType<typeof db.find<TSlug>>;
|
|
4
5
|
findOne: (options?: FindOptions) => ReturnType<typeof db.findOne<TSlug>>;
|
|
5
6
|
findBySlug: (slug: string, options?: FindOptions) => ReturnType<typeof db.findBySlug<TSlug>>;
|
|
6
7
|
findByID: (id: string | number, options?: FindByIDOptions) => ReturnType<typeof db.findByID<TSlug>>;
|
|
7
|
-
findAll: (options?:
|
|
8
|
+
findAll: (options?: FindOptions) => ReturnType<typeof db.findAll<TSlug>>;
|
|
8
9
|
update: (id: string | number, data: UpdateData, options?: UpdateOptions) => ReturnType<typeof db.update<TSlug>>;
|
|
9
10
|
updateMany: (where: Where, data: UpdateData, options?: UpdateOptions) => ReturnType<typeof db.updateMany<TSlug>>;
|
|
10
11
|
delete: (id: string | number, options?: DeleteOptions) => ReturnType<typeof db.delete<TSlug>>;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type { CollectionSlug, DataFromCollectionSlug, DataFromGlobalSlug, GlobalSlug, Where } from 'payload';
|
|
1
|
+
import type { CollectionSlug, DataFromCollectionSlug, DataFromGlobalSlug, GlobalSlug, PaginatedDocs, Where } from 'payload';
|
|
2
2
|
import { getPayload } from './get-payload';
|
|
3
3
|
export type FindOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['find']>[0], 'collection'>;
|
|
4
4
|
export type FindByIDOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['findByID']>[0], 'collection' | 'id'>;
|
|
5
|
-
export type FindAllOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['find']>[0], 'collection'>;
|
|
6
5
|
export type UpdateOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['update']>[0], 'collection' | 'id' | 'data' | 'where'>;
|
|
7
6
|
export type DeleteOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['delete']>[0], 'collection' | 'id' | 'where'>;
|
|
8
7
|
export type UpdateData = Parameters<Awaited<ReturnType<typeof getPayload>>['update']>[0]['data'];
|
|
9
8
|
export declare const db: {
|
|
10
9
|
findOne: <TSlug extends CollectionSlug>(collection: TSlug, options?: FindOptions) => Promise<DataFromCollectionSlug<TSlug>>;
|
|
11
10
|
findBySlug: <TSlug extends CollectionSlug>(collection: TSlug, slug: string, options?: FindOptions) => Promise<DataFromCollectionSlug<TSlug>>;
|
|
12
|
-
|
|
11
|
+
find: <TSlug extends CollectionSlug>(collection: TSlug, options?: FindOptions) => Promise<PaginatedDocs<DataFromCollectionSlug<TSlug>>>;
|
|
12
|
+
findAll: <TSlug extends CollectionSlug>(collection: TSlug, options?: FindOptions) => Promise<DataFromCollectionSlug<TSlug>[]>;
|
|
13
13
|
findByID: <TSlug extends CollectionSlug>(collection: TSlug, id: string | number, options?: FindByIDOptions) => Promise<DataFromCollectionSlug<TSlug>>;
|
|
14
14
|
create: <TSlug extends CollectionSlug>(collection: TSlug, data: Parameters<Awaited<ReturnType<typeof getPayload>>['create']>[0]['data'], options?: Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['create']>[0], 'collection' | 'data'>) => Promise<import("payload").JsonObject & import("payload").TypeWithID>;
|
|
15
15
|
update: <TSlug extends CollectionSlug>(collection: TSlug, id: string | number, data: UpdateData, options?: UpdateOptions) => Promise<import("payload").JsonObject & import("payload").TypeWithID>;
|
|
@@ -74,6 +74,13 @@ var db = {
|
|
|
74
74
|
}
|
|
75
75
|
);
|
|
76
76
|
},
|
|
77
|
+
find: async (collection, options) => {
|
|
78
|
+
const payload = await getClient();
|
|
79
|
+
return payload.find({
|
|
80
|
+
...options,
|
|
81
|
+
collection
|
|
82
|
+
});
|
|
83
|
+
},
|
|
77
84
|
findAll: async (collection, options) => {
|
|
78
85
|
const payload = await getClient();
|
|
79
86
|
const res = await payload.find({
|
|
@@ -146,6 +153,7 @@ var db = {
|
|
|
146
153
|
// src/payload-cms/server/create-collection.ts
|
|
147
154
|
function createCollection(collection, extend) {
|
|
148
155
|
const base = {
|
|
156
|
+
find: (options) => db.find(collection, options),
|
|
149
157
|
findOne: (options) => db.findOne(collection, options),
|
|
150
158
|
findByID: (id, options) => db.findByID(collection, id, options),
|
|
151
159
|
findBySlug: (slug, options) => db.findBySlug(collection, slug, options),
|
|
@@ -44,6 +44,13 @@ var db = {
|
|
|
44
44
|
}
|
|
45
45
|
);
|
|
46
46
|
},
|
|
47
|
+
find: async (collection, options) => {
|
|
48
|
+
const payload = await getClient();
|
|
49
|
+
return payload.find({
|
|
50
|
+
...options,
|
|
51
|
+
collection
|
|
52
|
+
});
|
|
53
|
+
},
|
|
47
54
|
findAll: async (collection, options) => {
|
|
48
55
|
const payload = await getClient();
|
|
49
56
|
const res = await payload.find({
|
|
@@ -116,6 +123,7 @@ var db = {
|
|
|
116
123
|
// src/payload-cms/server/create-collection.ts
|
|
117
124
|
function createCollection(collection, extend) {
|
|
118
125
|
const base = {
|
|
126
|
+
find: (options) => db.find(collection, options),
|
|
119
127
|
findOne: (options) => db.findOne(collection, options),
|
|
120
128
|
findByID: (id, options) => db.findByID(collection, id, options),
|
|
121
129
|
findBySlug: (slug, options) => db.findBySlug(collection, slug, options),
|