@matvdt/js-toolkit 0.0.1-canary.13 → 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, FindAllOptions, FindOptions, UpdateData, UpdateOptions } from './db';
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
- findBySlug: (slug: string) => ReturnType<typeof db.findBySlug<TSlug>>;
6
- findByID: (id: string | number) => ReturnType<typeof db.findByID<TSlug>>;
7
- findAll: (options?: FindAllOptions) => ReturnType<typeof db.findAll<TSlug>>;
6
+ findBySlug: (slug: string, options?: FindOptions) => ReturnType<typeof db.findBySlug<TSlug>>;
7
+ findByID: (id: string | number, options?: FindByIDOptions) => ReturnType<typeof db.findByID<TSlug>>;
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,16 @@
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
- export type FindAllOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['find']>[0], 'collection'>;
4
+ export type FindByIDOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['findByID']>[0], 'collection' | 'id'>;
5
5
  export type UpdateOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['update']>[0], 'collection' | 'id' | 'data' | 'where'>;
6
6
  export type DeleteOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['delete']>[0], 'collection' | 'id' | 'where'>;
7
7
  export type UpdateData = Parameters<Awaited<ReturnType<typeof getPayload>>['update']>[0]['data'];
8
8
  export declare const db: {
9
9
  findOne: <TSlug extends CollectionSlug>(collection: TSlug, options?: FindOptions) => Promise<DataFromCollectionSlug<TSlug>>;
10
- findBySlug: <TSlug extends CollectionSlug>(collection: TSlug, slug: string) => Promise<DataFromCollectionSlug<TSlug>>;
11
- findAll: <TSlug extends CollectionSlug>(collection: TSlug, options?: FindAllOptions) => Promise<DataFromCollectionSlug<TSlug>[]>;
12
- findByID: <TSlug extends CollectionSlug>(collection: TSlug, id: string | number) => Promise<DataFromCollectionSlug<TSlug>>;
10
+ findBySlug: <TSlug extends CollectionSlug>(collection: TSlug, slug: string, options?: FindOptions) => Promise<DataFromCollectionSlug<TSlug>>;
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
+ 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,24 @@ var db = {
62
62
  });
63
63
  return res.docs[0] ?? null;
64
64
  },
65
- findBySlug: async (collection, slug) => {
66
- return db.findOne(collection, { where: { slug: { equals: slug } } });
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
+ );
76
+ },
77
+ find: async (collection, options) => {
78
+ const payload = await getClient();
79
+ return payload.find({
80
+ ...options,
81
+ collection
82
+ });
67
83
  },
68
84
  findAll: async (collection, options) => {
69
85
  const payload = await getClient();
@@ -74,9 +90,13 @@ var db = {
74
90
  });
75
91
  return res.docs;
76
92
  },
77
- findByID: async (collection, id) => {
93
+ findByID: async (collection, id, options) => {
78
94
  const payload = await getClient();
79
- return payload.findByID({ collection, id });
95
+ return payload.findByID({
96
+ ...options,
97
+ collection,
98
+ id
99
+ });
80
100
  },
81
101
  create: async (collection, data, options) => {
82
102
  const payload = await getClient();
@@ -133,9 +153,10 @@ var db = {
133
153
  // src/payload-cms/server/create-collection.ts
134
154
  function createCollection(collection, extend) {
135
155
  const base = {
156
+ find: (options) => db.find(collection, options),
136
157
  findOne: (options) => db.findOne(collection, options),
137
- findByID: (id) => db.findByID(collection, id),
138
- findBySlug: (slug) => db.findBySlug(collection, slug),
158
+ findByID: (id, options) => db.findByID(collection, id, options),
159
+ findBySlug: (slug, options) => db.findBySlug(collection, slug, options),
139
160
  findAll: (options) => db.findAll(collection, options),
140
161
  update: (id, data, options) => db.update(collection, id, data, options),
141
162
  updateMany: (where, data, options) => db.updateMany(collection, where, data, options),
@@ -32,8 +32,24 @@ var db = {
32
32
  });
33
33
  return res.docs[0] ?? null;
34
34
  },
35
- findBySlug: async (collection, slug) => {
36
- return db.findOne(collection, { where: { slug: { equals: slug } } });
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
+ );
46
+ },
47
+ find: async (collection, options) => {
48
+ const payload = await getClient();
49
+ return payload.find({
50
+ ...options,
51
+ collection
52
+ });
37
53
  },
38
54
  findAll: async (collection, options) => {
39
55
  const payload = await getClient();
@@ -44,9 +60,13 @@ var db = {
44
60
  });
45
61
  return res.docs;
46
62
  },
47
- findByID: async (collection, id) => {
63
+ findByID: async (collection, id, options) => {
48
64
  const payload = await getClient();
49
- return payload.findByID({ collection, id });
65
+ return payload.findByID({
66
+ ...options,
67
+ collection,
68
+ id
69
+ });
50
70
  },
51
71
  create: async (collection, data, options) => {
52
72
  const payload = await getClient();
@@ -103,9 +123,10 @@ var db = {
103
123
  // src/payload-cms/server/create-collection.ts
104
124
  function createCollection(collection, extend) {
105
125
  const base = {
126
+ find: (options) => db.find(collection, options),
106
127
  findOne: (options) => db.findOne(collection, options),
107
- findByID: (id) => db.findByID(collection, id),
108
- findBySlug: (slug) => db.findBySlug(collection, slug),
128
+ findByID: (id, options) => db.findByID(collection, id, options),
129
+ findBySlug: (slug, options) => db.findBySlug(collection, slug, options),
109
130
  findAll: (options) => db.findAll(collection, options),
110
131
  update: (id, data, options) => db.update(collection, id, data, options),
111
132
  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.13",
3
+ "version": "0.0.1-canary.15",
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": {