@matvdt/js-toolkit 0.0.1-canary.13 → 0.0.1-canary.14
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,9 +1,9 @@
|
|
|
1
1
|
import type { CollectionSlug, Where } from 'payload';
|
|
2
|
-
import { db, DeleteOptions, FindAllOptions, FindOptions, UpdateData, UpdateOptions } from './db';
|
|
2
|
+
import { db, DeleteOptions, FindAllOptions, FindByIDOptions, FindOptions, UpdateData, UpdateOptions } from './db';
|
|
3
3
|
export type BaseCollectionMethods<TSlug extends CollectionSlug> = {
|
|
4
4
|
findOne: (options?: FindOptions) => ReturnType<typeof db.findOne<TSlug>>;
|
|
5
|
-
findBySlug: (slug: string) => ReturnType<typeof db.findBySlug<TSlug>>;
|
|
6
|
-
findByID: (id: string | number) => ReturnType<typeof db.findByID<TSlug>>;
|
|
5
|
+
findBySlug: (slug: string, options?: FindOptions) => ReturnType<typeof db.findBySlug<TSlug>>;
|
|
6
|
+
findByID: (id: string | number, options?: FindByIDOptions) => ReturnType<typeof db.findByID<TSlug>>;
|
|
7
7
|
findAll: (options?: FindAllOptions) => ReturnType<typeof db.findAll<TSlug>>;
|
|
8
8
|
update: (id: string | number, data: UpdateData, options?: UpdateOptions) => ReturnType<typeof db.update<TSlug>>;
|
|
9
9
|
updateMany: (where: Where, data: UpdateData, options?: UpdateOptions) => ReturnType<typeof db.updateMany<TSlug>>;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import type { CollectionSlug, DataFromCollectionSlug, DataFromGlobalSlug, GlobalSlug, 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
|
+
export type FindByIDOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['findByID']>[0], 'collection' | 'id'>;
|
|
4
5
|
export type FindAllOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['find']>[0], 'collection'>;
|
|
5
6
|
export type UpdateOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['update']>[0], 'collection' | 'id' | 'data' | 'where'>;
|
|
6
7
|
export type DeleteOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['delete']>[0], 'collection' | 'id' | 'where'>;
|
|
7
8
|
export type UpdateData = Parameters<Awaited<ReturnType<typeof getPayload>>['update']>[0]['data'];
|
|
8
9
|
export declare const db: {
|
|
9
10
|
findOne: <TSlug extends CollectionSlug>(collection: TSlug, options?: FindOptions) => Promise<DataFromCollectionSlug<TSlug>>;
|
|
10
|
-
findBySlug: <TSlug extends CollectionSlug>(collection: TSlug, slug: string) => Promise<DataFromCollectionSlug<TSlug>>;
|
|
11
|
+
findBySlug: <TSlug extends CollectionSlug>(collection: TSlug, slug: string, options?: FindOptions) => Promise<DataFromCollectionSlug<TSlug>>;
|
|
11
12
|
findAll: <TSlug extends CollectionSlug>(collection: TSlug, options?: FindAllOptions) => Promise<DataFromCollectionSlug<TSlug>[]>;
|
|
12
|
-
findByID: <TSlug extends CollectionSlug>(collection: TSlug, id: string | number) => Promise<DataFromCollectionSlug<TSlug>>;
|
|
13
|
+
findByID: <TSlug extends CollectionSlug>(collection: TSlug, id: string | number, options?: FindByIDOptions) => Promise<DataFromCollectionSlug<TSlug>>;
|
|
13
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>;
|
|
14
15
|
update: <TSlug extends CollectionSlug>(collection: TSlug, id: string | number, data: UpdateData, options?: UpdateOptions) => Promise<import("payload").JsonObject & import("payload").TypeWithID>;
|
|
15
16
|
updateMany: <TSlug extends CollectionSlug>(collection: TSlug, where: Where, data: UpdateData, options?: UpdateOptions) => Promise<import("payload").BulkOperationResult<TSlug, import("payload").SelectExcludeType | import("payload").SelectIncludeType>>;
|
|
@@ -62,8 +62,17 @@ var db = {
|
|
|
62
62
|
});
|
|
63
63
|
return res.docs[0] ?? null;
|
|
64
64
|
},
|
|
65
|
-
findBySlug: async (collection, slug) => {
|
|
66
|
-
return db.findOne(
|
|
65
|
+
findBySlug: async (collection, slug, options) => {
|
|
66
|
+
return db.findOne(
|
|
67
|
+
collection,
|
|
68
|
+
{
|
|
69
|
+
...options,
|
|
70
|
+
where: {
|
|
71
|
+
...options?.where,
|
|
72
|
+
slug: { equals: slug }
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
);
|
|
67
76
|
},
|
|
68
77
|
findAll: async (collection, options) => {
|
|
69
78
|
const payload = await getClient();
|
|
@@ -74,9 +83,13 @@ var db = {
|
|
|
74
83
|
});
|
|
75
84
|
return res.docs;
|
|
76
85
|
},
|
|
77
|
-
findByID: async (collection, id) => {
|
|
86
|
+
findByID: async (collection, id, options) => {
|
|
78
87
|
const payload = await getClient();
|
|
79
|
-
return payload.findByID({
|
|
88
|
+
return payload.findByID({
|
|
89
|
+
...options,
|
|
90
|
+
collection,
|
|
91
|
+
id
|
|
92
|
+
});
|
|
80
93
|
},
|
|
81
94
|
create: async (collection, data, options) => {
|
|
82
95
|
const payload = await getClient();
|
|
@@ -134,8 +147,8 @@ var db = {
|
|
|
134
147
|
function createCollection(collection, extend) {
|
|
135
148
|
const base = {
|
|
136
149
|
findOne: (options) => db.findOne(collection, options),
|
|
137
|
-
findByID: (id) => db.findByID(collection, id),
|
|
138
|
-
findBySlug: (slug) => db.findBySlug(collection, slug),
|
|
150
|
+
findByID: (id, options) => db.findByID(collection, id, options),
|
|
151
|
+
findBySlug: (slug, options) => db.findBySlug(collection, slug, options),
|
|
139
152
|
findAll: (options) => db.findAll(collection, options),
|
|
140
153
|
update: (id, data, options) => db.update(collection, id, data, options),
|
|
141
154
|
updateMany: (where, data, options) => db.updateMany(collection, where, data, options),
|
|
@@ -32,8 +32,17 @@ var db = {
|
|
|
32
32
|
});
|
|
33
33
|
return res.docs[0] ?? null;
|
|
34
34
|
},
|
|
35
|
-
findBySlug: async (collection, slug) => {
|
|
36
|
-
return db.findOne(
|
|
35
|
+
findBySlug: async (collection, slug, options) => {
|
|
36
|
+
return db.findOne(
|
|
37
|
+
collection,
|
|
38
|
+
{
|
|
39
|
+
...options,
|
|
40
|
+
where: {
|
|
41
|
+
...options?.where,
|
|
42
|
+
slug: { equals: slug }
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
);
|
|
37
46
|
},
|
|
38
47
|
findAll: async (collection, options) => {
|
|
39
48
|
const payload = await getClient();
|
|
@@ -44,9 +53,13 @@ var db = {
|
|
|
44
53
|
});
|
|
45
54
|
return res.docs;
|
|
46
55
|
},
|
|
47
|
-
findByID: async (collection, id) => {
|
|
56
|
+
findByID: async (collection, id, options) => {
|
|
48
57
|
const payload = await getClient();
|
|
49
|
-
return payload.findByID({
|
|
58
|
+
return payload.findByID({
|
|
59
|
+
...options,
|
|
60
|
+
collection,
|
|
61
|
+
id
|
|
62
|
+
});
|
|
50
63
|
},
|
|
51
64
|
create: async (collection, data, options) => {
|
|
52
65
|
const payload = await getClient();
|
|
@@ -104,8 +117,8 @@ var db = {
|
|
|
104
117
|
function createCollection(collection, extend) {
|
|
105
118
|
const base = {
|
|
106
119
|
findOne: (options) => db.findOne(collection, options),
|
|
107
|
-
findByID: (id) => db.findByID(collection, id),
|
|
108
|
-
findBySlug: (slug) => db.findBySlug(collection, slug),
|
|
120
|
+
findByID: (id, options) => db.findByID(collection, id, options),
|
|
121
|
+
findBySlug: (slug, options) => db.findBySlug(collection, slug, options),
|
|
109
122
|
findAll: (options) => db.findAll(collection, options),
|
|
110
123
|
update: (id, data, options) => db.update(collection, id, data, options),
|
|
111
124
|
updateMany: (where, data, options) => db.updateMany(collection, where, data, options),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@matvdt/js-toolkit",
|
|
3
|
-
"version": "0.0.1-canary.
|
|
3
|
+
"version": "0.0.1-canary.14",
|
|
4
4
|
"description": "JS/TS toolkit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -27,11 +27,21 @@
|
|
|
27
27
|
],
|
|
28
28
|
"scripts": {
|
|
29
29
|
"build": "tsup && tsc",
|
|
30
|
+
"version:canary": "npm version prerelease --preid=canary",
|
|
31
|
+
"version:alpha" : "npm version prerelease --preid=alpha",
|
|
32
|
+
"version:beta" : "npm version prerelease --preid=beta",
|
|
33
|
+
"version:rc" : "npm version prerelease --preid=rc",
|
|
34
|
+
"version:latest": "npm version patch",
|
|
30
35
|
"publish:canary": "npm publish --access public --tag canary",
|
|
31
36
|
"publish:alpha" : "npm publish --access public --tag alpha",
|
|
32
37
|
"publish:beta" : "npm publish --access public --tag beta",
|
|
33
38
|
"publish:rc" : "npm publish --access public --tag rc",
|
|
34
39
|
"publish:latest": "npm publish --access public",
|
|
40
|
+
"release:canary": "npm run version:canary && npm run publish:canary",
|
|
41
|
+
"release:alpha" : "npm run version:alpha && npm run publish:alpha",
|
|
42
|
+
"release:beta" : "npm run version:beta && npm run publish:beta",
|
|
43
|
+
"release:rc" : "npm run version:rc && npm run publish:rc",
|
|
44
|
+
"release:latest": "npm run version:latest && npm run publish:latest",
|
|
35
45
|
"prepublishOnly": "npm run build"
|
|
36
46
|
},
|
|
37
47
|
"publishConfig": {
|