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