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