@matvdt/js-toolkit 0.0.1-canary.15 → 0.0.1-canary.17

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,12 @@ 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
+ },
150
+ aggregate: async (collection, pipeline, options) => {
151
+ const payload2 = await getClient();
152
+ return payload2.db.collections[collection].aggregate(pipeline, options);
149
153
  },
150
154
  raw: getClient
151
155
  };
@@ -153,15 +157,15 @@ var db = {
153
157
  // src/payload-cms/server/create-collection.ts
154
158
  function createCollection(collection, extend) {
155
159
  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)
160
+ find: (options) => payload.find(collection, options),
161
+ findOne: (options) => payload.findOne(collection, options),
162
+ findByID: (id, options) => payload.findByID(collection, id, options),
163
+ findBySlug: (slug, options) => payload.findBySlug(collection, slug, options),
164
+ findAll: (options) => payload.findAll(collection, options),
165
+ update: (id, data, options) => payload.update(collection, id, data, options),
166
+ updateMany: (where, data, options) => payload.updateMany(collection, where, data, options),
167
+ delete: (id, options) => payload.delete(collection, id, options),
168
+ deleteMany: (where, options) => payload.deleteMany(collection, where, options)
165
169
  };
166
170
  const extended = extend ? extend(base) : void 0;
167
171
  return {
@@ -173,7 +177,7 @@ function createCollection(collection, extend) {
173
177
  // src/payload-cms/server/create-global.ts
174
178
  function createGlobal(slug, extend) {
175
179
  const base = {
176
- get: () => db.global(slug)
180
+ get: () => payload.global(slug)
177
181
  };
178
182
  const extended = extend ? extend(base) : void 0;
179
183
  return {
@@ -186,6 +190,6 @@ function createGlobal(slug, extend) {
186
190
  configurePayload,
187
191
  createCollection,
188
192
  createGlobal,
189
- db,
190
- getPayload
193
+ getPayload,
194
+ payload
191
195
  });
@@ -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,12 @@ 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
+ },
120
+ aggregate: async (collection, pipeline, options) => {
121
+ const payload2 = await getClient();
122
+ return payload2.db.collections[collection].aggregate(pipeline, options);
119
123
  },
120
124
  raw: getClient
121
125
  };
@@ -123,15 +127,15 @@ var db = {
123
127
  // src/payload-cms/server/create-collection.ts
124
128
  function createCollection(collection, extend) {
125
129
  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)
130
+ find: (options) => payload.find(collection, options),
131
+ findOne: (options) => payload.findOne(collection, options),
132
+ findByID: (id, options) => payload.findByID(collection, id, options),
133
+ findBySlug: (slug, options) => payload.findBySlug(collection, slug, options),
134
+ findAll: (options) => payload.findAll(collection, options),
135
+ update: (id, data, options) => payload.update(collection, id, data, options),
136
+ updateMany: (where, data, options) => payload.updateMany(collection, where, data, options),
137
+ delete: (id, options) => payload.delete(collection, id, options),
138
+ deleteMany: (where, options) => payload.deleteMany(collection, where, options)
135
139
  };
136
140
  const extended = extend ? extend(base) : void 0;
137
141
  return {
@@ -143,7 +147,7 @@ function createCollection(collection, extend) {
143
147
  // src/payload-cms/server/create-global.ts
144
148
  function createGlobal(slug, extend) {
145
149
  const base = {
146
- get: () => db.global(slug)
150
+ get: () => payload.global(slug)
147
151
  };
148
152
  const extended = extend ? extend(base) : void 0;
149
153
  return {
@@ -155,6 +159,6 @@ export {
155
159
  configurePayload,
156
160
  createCollection,
157
161
  createGlobal,
158
- db,
159
- getPayload
162
+ getPayload,
163
+ payload
160
164
  };
@@ -1,11 +1,12 @@
1
1
  import type { CollectionSlug, DataFromCollectionSlug, DataFromGlobalSlug, GlobalSlug, PaginatedDocs, Where } from 'payload';
2
2
  import { getPayload } from './get-payload';
3
+ import { PipelineStage, Aggregate, AggregateOptions } from "mongoose";
3
4
  export type FindOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['find']>[0], 'collection'>;
4
5
  export type FindByIDOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['findByID']>[0], 'collection' | 'id'>;
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
- export declare const db: {
9
+ export declare const payload: {
9
10
  findOne: <TSlug extends CollectionSlug>(collection: TSlug, options?: FindOptions) => Promise<DataFromCollectionSlug<TSlug>>;
10
11
  findBySlug: <TSlug extends CollectionSlug>(collection: TSlug, slug: string, options?: FindOptions) => Promise<DataFromCollectionSlug<TSlug>>;
11
12
  find: <TSlug extends CollectionSlug>(collection: TSlug, options?: FindOptions) => Promise<PaginatedDocs<DataFromCollectionSlug<TSlug>>>;
@@ -17,5 +18,6 @@ export declare const db: {
17
18
  delete: <TSlug extends CollectionSlug>(collection: TSlug, id: string | number, options?: DeleteOptions) => Promise<import("payload").JsonObject & import("payload").TypeWithID>;
18
19
  deleteMany: <TSlug extends CollectionSlug>(collection: TSlug, where: Where, options?: DeleteOptions) => Promise<import("payload").BulkOperationResult<TSlug, import("payload").SelectExcludeType | import("payload").SelectIncludeType>>;
19
20
  global: <TSlug extends GlobalSlug>(slug: TSlug) => Promise<DataFromGlobalSlug<TSlug>>;
21
+ aggregate: <TSlug extends CollectionSlug, TData = any>(collection: TSlug, pipeline?: PipelineStage[], options?: AggregateOptions) => Promise<Aggregate<TData[]>>;
20
22
  raw: () => Promise<import("payload").BasePayload>;
21
23
  };
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.17",
4
4
  "description": "JS/TS toolkit",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -28,19 +28,19 @@
28
28
  "scripts": {
29
29
  "build": "tsup && tsc",
30
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",
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
34
  "version:latest": "npm version patch",
35
35
  "publish:canary": "npm publish --access public --tag canary",
36
- "publish:alpha" : "npm publish --access public --tag alpha",
37
- "publish:beta" : "npm publish --access public --tag beta",
38
- "publish:rc" : "npm publish --access public --tag rc",
36
+ "publish:alpha": "npm publish --access public --tag alpha",
37
+ "publish:beta": "npm publish --access public --tag beta",
38
+ "publish:rc": "npm publish --access public --tag rc",
39
39
  "publish:latest": "npm publish --access public",
40
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",
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
44
  "release:latest": "npm run version:latest && npm run publish:latest",
45
45
  "prepublishOnly": "npm run build"
46
46
  },
@@ -54,14 +54,16 @@
54
54
  "author": "Matteo Vidotto",
55
55
  "license": "MIT",
56
56
  "devDependencies": {
57
+ "@payloadcms/db-mongodb": "^3.88.0",
57
58
  "@types/node": "^26.1.2",
58
59
  "@types/react": "^19.2.17",
59
- "payload": "^3.86.0",
60
+ "payload": "^3.88.0",
60
61
  "react": "^19.2.8",
61
62
  "tsup": "^8.5.1",
62
63
  "typescript": "^7.0.2"
63
64
  },
64
65
  "peerDependencies": {
66
+ "@payloadcms/db-mongodb": ">=3.0.0",
65
67
  "payload": ">=3.0.0",
66
68
  "react": ">=18.0.0"
67
69
  },
@@ -69,6 +71,9 @@
69
71
  "payload": {
70
72
  "optional": true
71
73
  },
74
+ "@payloadcms/db-mongodb": {
75
+ "optional": true
76
+ },
72
77
  "react": {
73
78
  "optional": true
74
79
  }