@matvdt/js-toolkit 0.0.1-canary.14 → 0.0.1-canary.16

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,14 +1,15 @@
1
1
  import type { CollectionSlug, Where } from 'payload';
2
- import { db, DeleteOptions, FindAllOptions, FindByIDOptions, FindOptions, UpdateData, UpdateOptions } from './db';
2
+ import { payload, DeleteOptions, FindByIDOptions, FindOptions, UpdateData, UpdateOptions } from './payload';
3
3
  export type BaseCollectionMethods<TSlug extends CollectionSlug> = {
4
- findOne: (options?: FindOptions) => ReturnType<typeof db.findOne<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
- findAll: (options?: FindAllOptions) => ReturnType<typeof db.findAll<TSlug>>;
8
- update: (id: string | number, data: UpdateData, options?: UpdateOptions) => ReturnType<typeof db.update<TSlug>>;
9
- updateMany: (where: Where, data: UpdateData, options?: UpdateOptions) => ReturnType<typeof db.updateMany<TSlug>>;
10
- delete: (id: string | number, options?: DeleteOptions) => ReturnType<typeof db.delete<TSlug>>;
11
- deleteMany: (where: Where, options?: DeleteOptions) => ReturnType<typeof db.deleteMany<TSlug>>;
4
+ find: (options?: FindOptions) => ReturnType<typeof payload.find<TSlug>>;
5
+ findOne: (options?: FindOptions) => ReturnType<typeof payload.findOne<TSlug>>;
6
+ findBySlug: (slug: string, options?: FindOptions) => ReturnType<typeof payload.findBySlug<TSlug>>;
7
+ findByID: (id: string | number, options?: FindByIDOptions) => ReturnType<typeof payload.findByID<TSlug>>;
8
+ findAll: (options?: FindOptions) => ReturnType<typeof payload.findAll<TSlug>>;
9
+ update: (id: string | number, data: UpdateData, options?: UpdateOptions) => ReturnType<typeof payload.update<TSlug>>;
10
+ updateMany: (where: Where, data: UpdateData, options?: UpdateOptions) => ReturnType<typeof payload.updateMany<TSlug>>;
11
+ delete: (id: string | number, options?: DeleteOptions) => ReturnType<typeof payload.delete<TSlug>>;
12
+ deleteMany: (where: Where, options?: DeleteOptions) => ReturnType<typeof payload.deleteMany<TSlug>>;
12
13
  };
13
14
  type ExtensionFunction = (...args: any[]) => any;
14
15
  type ExtensionObject = Record<string, unknown>;
@@ -1,7 +1,7 @@
1
1
  import type { GlobalSlug } from 'payload';
2
- import { db } from './db';
2
+ import { payload } from './payload';
3
3
  type BaseGlobalMethods<TSlug extends GlobalSlug> = {
4
- get: () => ReturnType<typeof db.global<TSlug>>;
4
+ get: () => ReturnType<typeof payload.global<TSlug>>;
5
5
  };
6
6
  export declare function createGlobal<TSlug extends GlobalSlug, TExtend extends Record<string, (...args: any[]) => any> = {}>(slug: TSlug, extend?: (base: BaseGlobalMethods<TSlug>) => TExtend): BaseGlobalMethods<TSlug> & TExtend;
7
7
  export {};
@@ -1,3 +1,3 @@
1
- import { type SanitizedConfig, type Payload } from 'payload';
1
+ import { type Payload, type SanitizedConfig } from 'payload';
2
2
  export declare function configurePayload(config: Promise<SanitizedConfig> | SanitizedConfig): void;
3
3
  export declare const getPayload: (config?: Promise<SanitizedConfig> | SanitizedConfig) => Promise<Payload>;
@@ -23,12 +23,12 @@ __export(server_exports, {
23
23
  configurePayload: () => configurePayload,
24
24
  createCollection: () => createCollection,
25
25
  createGlobal: () => createGlobal,
26
- db: () => db,
27
- getPayload: () => getPayload
26
+ getPayload: () => getPayload,
27
+ payload: () => payload
28
28
  });
29
29
  module.exports = __toCommonJS(server_exports);
30
30
 
31
- // src/payload-cms/server/db.ts
31
+ // src/payload-cms/server/payload.ts
32
32
  var import_react = require("react");
33
33
 
34
34
  // src/payload-cms/server/get-payload.ts
@@ -48,14 +48,14 @@ var getPayload = async (config) => {
48
48
  return (0, import_payload.getPayload)({ config: resolvedConfig });
49
49
  };
50
50
 
51
- // src/payload-cms/server/db.ts
51
+ // src/payload-cms/server/payload.ts
52
52
  var getClient = (0, import_react.cache)(async () => {
53
53
  return await getPayload();
54
54
  });
55
- var db = {
55
+ var payload = {
56
56
  findOne: async (collection, options) => {
57
- const payload = await getClient();
58
- const res = await payload.find({
57
+ const payload2 = await getClient();
58
+ const res = await payload2.find({
59
59
  ...options,
60
60
  collection,
61
61
  limit: 1
@@ -63,7 +63,7 @@ var db = {
63
63
  return res.docs[0] ?? null;
64
64
  },
65
65
  findBySlug: async (collection, slug, options) => {
66
- return db.findOne(
66
+ return payload.findOne(
67
67
  collection,
68
68
  {
69
69
  ...options,
@@ -74,9 +74,16 @@ var db = {
74
74
  }
75
75
  );
76
76
  },
77
+ find: async (collection, options) => {
78
+ const payload2 = await getClient();
79
+ return payload2.find({
80
+ ...options,
81
+ collection
82
+ });
83
+ },
77
84
  findAll: async (collection, options) => {
78
- const payload = await getClient();
79
- const res = await payload.find({
85
+ const payload2 = await getClient();
86
+ const res = await payload2.find({
80
87
  ...options,
81
88
  collection,
82
89
  limit: options?.limit ?? 100
@@ -84,24 +91,24 @@ var db = {
84
91
  return res.docs;
85
92
  },
86
93
  findByID: async (collection, id, options) => {
87
- const payload = await getClient();
88
- return payload.findByID({
94
+ const payload2 = await getClient();
95
+ return payload2.findByID({
89
96
  ...options,
90
97
  collection,
91
98
  id
92
99
  });
93
100
  },
94
101
  create: async (collection, data, options) => {
95
- const payload = await getClient();
96
- return payload.create({
102
+ const payload2 = await getClient();
103
+ return payload2.create({
97
104
  ...options,
98
105
  collection,
99
106
  data
100
107
  });
101
108
  },
102
109
  update: async (collection, id, data, options) => {
103
- const payload = await getClient();
104
- return payload.update({
110
+ const payload2 = await getClient();
111
+ return payload2.update({
105
112
  ...options,
106
113
  collection,
107
114
  id,
@@ -109,8 +116,8 @@ var db = {
109
116
  });
110
117
  },
111
118
  updateMany: async (collection, where, data, options) => {
112
- const payload = await getClient();
113
- return payload.update({
119
+ const payload2 = await getClient();
120
+ return payload2.update({
114
121
  ...options,
115
122
  collection,
116
123
  where,
@@ -119,8 +126,8 @@ var db = {
119
126
  });
120
127
  },
121
128
  delete: async (collection, id, options) => {
122
- const payload = await getClient();
123
- return payload.delete({
129
+ const payload2 = await getClient();
130
+ return payload2.delete({
124
131
  ...options,
125
132
  collection,
126
133
  id,
@@ -128,8 +135,8 @@ var db = {
128
135
  });
129
136
  },
130
137
  deleteMany: async (collection, where, options) => {
131
- const payload = await getClient();
132
- return payload.delete({
138
+ const payload2 = await getClient();
139
+ return payload2.delete({
133
140
  ...options,
134
141
  collection,
135
142
  where,
@@ -137,8 +144,8 @@ var db = {
137
144
  });
138
145
  },
139
146
  global: async (slug) => {
140
- const payload = await getClient();
141
- return payload.findGlobal({ slug });
147
+ const payload2 = await getClient();
148
+ return payload2.findGlobal({ slug });
142
149
  },
143
150
  raw: getClient
144
151
  };
@@ -146,14 +153,15 @@ var db = {
146
153
  // src/payload-cms/server/create-collection.ts
147
154
  function createCollection(collection, extend) {
148
155
  const base = {
149
- findOne: (options) => db.findOne(collection, options),
150
- findByID: (id, options) => db.findByID(collection, id, options),
151
- findBySlug: (slug, options) => db.findBySlug(collection, slug, options),
152
- findAll: (options) => db.findAll(collection, options),
153
- update: (id, data, options) => db.update(collection, id, data, options),
154
- updateMany: (where, data, options) => db.updateMany(collection, where, data, options),
155
- delete: (id, options) => db.delete(collection, id, options),
156
- deleteMany: (where, options) => db.deleteMany(collection, where, options)
156
+ find: (options) => payload.find(collection, options),
157
+ findOne: (options) => payload.findOne(collection, options),
158
+ findByID: (id, options) => payload.findByID(collection, id, options),
159
+ findBySlug: (slug, options) => payload.findBySlug(collection, slug, options),
160
+ findAll: (options) => payload.findAll(collection, options),
161
+ update: (id, data, options) => payload.update(collection, id, data, options),
162
+ updateMany: (where, data, options) => payload.updateMany(collection, where, data, options),
163
+ delete: (id, options) => payload.delete(collection, id, options),
164
+ deleteMany: (where, options) => payload.deleteMany(collection, where, options)
157
165
  };
158
166
  const extended = extend ? extend(base) : void 0;
159
167
  return {
@@ -165,7 +173,7 @@ function createCollection(collection, extend) {
165
173
  // src/payload-cms/server/create-global.ts
166
174
  function createGlobal(slug, extend) {
167
175
  const base = {
168
- get: () => db.global(slug)
176
+ get: () => payload.global(slug)
169
177
  };
170
178
  const extended = extend ? extend(base) : void 0;
171
179
  return {
@@ -178,6 +186,6 @@ function createGlobal(slug, extend) {
178
186
  configurePayload,
179
187
  createCollection,
180
188
  createGlobal,
181
- db,
182
- getPayload
189
+ getPayload,
190
+ payload
183
191
  });
@@ -1,4 +1,4 @@
1
1
  export * from './create-collection';
2
2
  export * from './create-global';
3
- export * from './db';
4
3
  export * from './get-payload';
4
+ export * from './payload';
@@ -1,4 +1,4 @@
1
- // src/payload-cms/server/db.ts
1
+ // src/payload-cms/server/payload.ts
2
2
  import { cache } from "react";
3
3
 
4
4
  // src/payload-cms/server/get-payload.ts
@@ -18,14 +18,14 @@ var getPayload = async (config) => {
18
18
  return getPayloadSDK({ config: resolvedConfig });
19
19
  };
20
20
 
21
- // src/payload-cms/server/db.ts
21
+ // src/payload-cms/server/payload.ts
22
22
  var getClient = cache(async () => {
23
23
  return await getPayload();
24
24
  });
25
- var db = {
25
+ var payload = {
26
26
  findOne: async (collection, options) => {
27
- const payload = await getClient();
28
- const res = await payload.find({
27
+ const payload2 = await getClient();
28
+ const res = await payload2.find({
29
29
  ...options,
30
30
  collection,
31
31
  limit: 1
@@ -33,7 +33,7 @@ var db = {
33
33
  return res.docs[0] ?? null;
34
34
  },
35
35
  findBySlug: async (collection, slug, options) => {
36
- return db.findOne(
36
+ return payload.findOne(
37
37
  collection,
38
38
  {
39
39
  ...options,
@@ -44,9 +44,16 @@ var db = {
44
44
  }
45
45
  );
46
46
  },
47
+ find: async (collection, options) => {
48
+ const payload2 = await getClient();
49
+ return payload2.find({
50
+ ...options,
51
+ collection
52
+ });
53
+ },
47
54
  findAll: async (collection, options) => {
48
- const payload = await getClient();
49
- const res = await payload.find({
55
+ const payload2 = await getClient();
56
+ const res = await payload2.find({
50
57
  ...options,
51
58
  collection,
52
59
  limit: options?.limit ?? 100
@@ -54,24 +61,24 @@ var db = {
54
61
  return res.docs;
55
62
  },
56
63
  findByID: async (collection, id, options) => {
57
- const payload = await getClient();
58
- return payload.findByID({
64
+ const payload2 = await getClient();
65
+ return payload2.findByID({
59
66
  ...options,
60
67
  collection,
61
68
  id
62
69
  });
63
70
  },
64
71
  create: async (collection, data, options) => {
65
- const payload = await getClient();
66
- return payload.create({
72
+ const payload2 = await getClient();
73
+ return payload2.create({
67
74
  ...options,
68
75
  collection,
69
76
  data
70
77
  });
71
78
  },
72
79
  update: async (collection, id, data, options) => {
73
- const payload = await getClient();
74
- return payload.update({
80
+ const payload2 = await getClient();
81
+ return payload2.update({
75
82
  ...options,
76
83
  collection,
77
84
  id,
@@ -79,8 +86,8 @@ var db = {
79
86
  });
80
87
  },
81
88
  updateMany: async (collection, where, data, options) => {
82
- const payload = await getClient();
83
- return payload.update({
89
+ const payload2 = await getClient();
90
+ return payload2.update({
84
91
  ...options,
85
92
  collection,
86
93
  where,
@@ -89,8 +96,8 @@ var db = {
89
96
  });
90
97
  },
91
98
  delete: async (collection, id, options) => {
92
- const payload = await getClient();
93
- return payload.delete({
99
+ const payload2 = await getClient();
100
+ return payload2.delete({
94
101
  ...options,
95
102
  collection,
96
103
  id,
@@ -98,8 +105,8 @@ var db = {
98
105
  });
99
106
  },
100
107
  deleteMany: async (collection, where, options) => {
101
- const payload = await getClient();
102
- return payload.delete({
108
+ const payload2 = await getClient();
109
+ return payload2.delete({
103
110
  ...options,
104
111
  collection,
105
112
  where,
@@ -107,8 +114,8 @@ var db = {
107
114
  });
108
115
  },
109
116
  global: async (slug) => {
110
- const payload = await getClient();
111
- return payload.findGlobal({ slug });
117
+ const payload2 = await getClient();
118
+ return payload2.findGlobal({ slug });
112
119
  },
113
120
  raw: getClient
114
121
  };
@@ -116,14 +123,15 @@ var db = {
116
123
  // src/payload-cms/server/create-collection.ts
117
124
  function createCollection(collection, extend) {
118
125
  const base = {
119
- findOne: (options) => db.findOne(collection, options),
120
- findByID: (id, options) => db.findByID(collection, id, options),
121
- findBySlug: (slug, options) => db.findBySlug(collection, slug, options),
122
- findAll: (options) => db.findAll(collection, options),
123
- update: (id, data, options) => db.update(collection, id, data, options),
124
- updateMany: (where, data, options) => db.updateMany(collection, where, data, options),
125
- delete: (id, options) => db.delete(collection, id, options),
126
- deleteMany: (where, options) => db.deleteMany(collection, where, options)
126
+ find: (options) => payload.find(collection, options),
127
+ findOne: (options) => payload.findOne(collection, options),
128
+ findByID: (id, options) => payload.findByID(collection, id, options),
129
+ findBySlug: (slug, options) => payload.findBySlug(collection, slug, options),
130
+ findAll: (options) => payload.findAll(collection, options),
131
+ update: (id, data, options) => payload.update(collection, id, data, options),
132
+ updateMany: (where, data, options) => payload.updateMany(collection, where, data, options),
133
+ delete: (id, options) => payload.delete(collection, id, options),
134
+ deleteMany: (where, options) => payload.deleteMany(collection, where, options)
127
135
  };
128
136
  const extended = extend ? extend(base) : void 0;
129
137
  return {
@@ -135,7 +143,7 @@ function createCollection(collection, extend) {
135
143
  // src/payload-cms/server/create-global.ts
136
144
  function createGlobal(slug, extend) {
137
145
  const base = {
138
- get: () => db.global(slug)
146
+ get: () => payload.global(slug)
139
147
  };
140
148
  const extended = extend ? extend(base) : void 0;
141
149
  return {
@@ -147,6 +155,6 @@ export {
147
155
  configurePayload,
148
156
  createCollection,
149
157
  createGlobal,
150
- db,
151
- getPayload
158
+ getPayload,
159
+ payload
152
160
  };
@@ -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
- export declare const db: {
8
+ export declare const payload: {
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
- findAll: <TSlug extends CollectionSlug>(collection: TSlug, options?: FindAllOptions) => 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
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>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matvdt/js-toolkit",
3
- "version": "0.0.1-canary.14",
3
+ "version": "0.0.1-canary.16",
4
4
  "description": "JS/TS toolkit",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",