@matvdt/js-toolkit 0.0.1-canary.5 → 0.0.1-canary.7

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.
@@ -0,0 +1,33 @@
1
+ // src/payload-cms/utils/is-populated.ts
2
+ function isPopulated(relation) {
3
+ return typeof relation !== "string";
4
+ }
5
+
6
+ // src/payload-cms/utils/as-populated.ts
7
+ function asPopulated(relation) {
8
+ return isPopulated(relation) ? relation : void 0;
9
+ }
10
+
11
+ // src/payload-cms/utils/is-object-id.ts
12
+ var MONGO_ID_REGEX = /^[0-9a-fA-F]{24}$/;
13
+ function isObjectId(value) {
14
+ return typeof value === "string" && MONGO_ID_REGEX.test(value);
15
+ }
16
+
17
+ // src/payload-cms/utils/assert-populated.ts
18
+ function assertPopulated(field, fieldName = "Field") {
19
+ if (field === null || field === void 0) {
20
+ throw new Error(`${fieldName} is undefined or null`);
21
+ }
22
+ if (isObjectId(field)) {
23
+ throw new Error(`${fieldName} is not populated (received ID: ${String(field)})`);
24
+ }
25
+ }
26
+
27
+ export {
28
+ isPopulated,
29
+ asPopulated,
30
+ MONGO_ID_REGEX,
31
+ isObjectId,
32
+ assertPopulated
33
+ };
package/dist/index.cjs CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/index.ts
@@ -33,25 +23,11 @@ __export(index_exports, {
33
23
  MONGO_ID_REGEX: () => MONGO_ID_REGEX,
34
24
  asPopulated: () => asPopulated,
35
25
  assertPopulated: () => assertPopulated,
36
- createCollection: () => createCollection,
37
- createGlobal: () => createGlobal,
38
- db: () => db,
39
- getPayload: () => getPayload,
40
26
  isObjectId: () => isObjectId,
41
27
  isPopulated: () => isPopulated
42
28
  });
43
29
  module.exports = __toCommonJS(index_exports);
44
30
 
45
- // src/payload-cms/client/get-payload.ts
46
- var import_payload = require("payload");
47
- var getPayload = async (config) => {
48
- if (config) {
49
- return (0, import_payload.getPayload)({ config });
50
- }
51
- const defaultConfig = await import("@payload-config");
52
- return (0, import_payload.getPayload)({ config: defaultConfig });
53
- };
54
-
55
31
  // src/payload-cms/utils/is-populated.ts
56
32
  function isPopulated(relation) {
57
33
  return typeof relation !== "string";
@@ -77,121 +53,11 @@ function assertPopulated(field, fieldName = "Field") {
77
53
  throw new Error(`${fieldName} is not populated (received ID: ${String(field)})`);
78
54
  }
79
55
  }
80
-
81
- // src/payload-cms/utils/db.ts
82
- var import_react = require("react");
83
- var getClient = (0, import_react.cache)(async () => {
84
- return await getPayload();
85
- });
86
- var db = {
87
- findOne: async (collection, where) => {
88
- const payload = await getClient();
89
- const res = await payload.find({ collection, where, limit: 1 });
90
- return res.docs[0] ?? null;
91
- },
92
- findBySlug: async (collection, slug) => {
93
- return db.findOne(collection, { slug: { equals: slug } });
94
- },
95
- findAll: async (collection, options) => {
96
- const payload = await getClient();
97
- const res = await payload.find({
98
- collection,
99
- limit: options?.limit ?? 100,
100
- ...options
101
- });
102
- return res.docs;
103
- },
104
- findByID: async (collection, id) => {
105
- const payload = await getClient();
106
- return payload.findByID({ collection, id });
107
- },
108
- create: async (collection, data, options) => {
109
- const payload = await getClient();
110
- return payload.create({ collection, data, ...options });
111
- },
112
- update: async (collection, id, data, options) => {
113
- const payload = await getClient();
114
- return payload.update({
115
- collection,
116
- id,
117
- data,
118
- ...options
119
- });
120
- },
121
- updateMany: async (collection, where, data, options) => {
122
- const payload = await getClient();
123
- return payload.update({
124
- collection,
125
- where,
126
- data,
127
- ...options,
128
- id: void 0
129
- });
130
- },
131
- delete: async (collection, id, options) => {
132
- const payload = await getClient();
133
- return payload.delete({
134
- collection,
135
- id,
136
- where: void 0,
137
- ...options
138
- });
139
- },
140
- deleteMany: async (collection, where, options) => {
141
- const payload = await getClient();
142
- return payload.delete({
143
- collection,
144
- where,
145
- id: void 0,
146
- ...options
147
- });
148
- },
149
- global: async (slug) => {
150
- const payload = await getClient();
151
- return payload.findGlobal({ slug });
152
- },
153
- raw: getClient
154
- };
155
-
156
- // src/payload-cms/utils/create-collection.ts
157
- function createCollection(collection, extend) {
158
- const base = {
159
- findOne: (where) => db.findOne(collection, where),
160
- findByID: (id) => db.findByID(collection, id),
161
- findBySlug: (slug) => db.findBySlug(collection, slug),
162
- findAll: (options) => db.findAll(collection, options),
163
- update: (id, data, options) => db.update(collection, id, data, options),
164
- updateMany: (where, data, options) => db.updateMany(collection, where, data, options),
165
- delete: (id, options) => db.delete(collection, id, options),
166
- deleteMany: (where, options) => db.deleteMany(collection, where, options)
167
- };
168
- const extended = extend ? extend(base) : void 0;
169
- return {
170
- ...base,
171
- ...extended
172
- };
173
- }
174
-
175
- // src/payload-cms/utils/create-global.ts
176
- function createGlobal(slug, extend) {
177
- const base = {
178
- get: () => db.global(slug)
179
- };
180
- const extended = extend ? extend(base) : void 0;
181
- return {
182
- ...base,
183
- ...extended
184
- };
185
- }
186
56
  // Annotate the CommonJS export names for ESM import in node:
187
57
  0 && (module.exports = {
188
58
  MONGO_ID_REGEX,
189
59
  asPopulated,
190
60
  assertPopulated,
191
- createCollection,
192
- createGlobal,
193
- db,
194
- getPayload,
195
61
  isObjectId,
196
62
  isPopulated
197
63
  });
package/dist/index.js CHANGED
@@ -1,26 +1,15 @@
1
- import "./chunk-EMH4G65N.js";
2
- import "./chunk-NSY6BIWE.js";
1
+ import "./chunk-7GZ4G2P3.js";
3
2
  import {
4
3
  MONGO_ID_REGEX,
5
4
  asPopulated,
6
5
  assertPopulated,
7
- createCollection,
8
- createGlobal,
9
- db,
10
6
  isObjectId,
11
7
  isPopulated
12
- } from "./chunk-EZIPIKRW.js";
13
- import {
14
- getPayload
15
- } from "./chunk-CWTTD7TW.js";
8
+ } from "./chunk-O4W463W3.js";
16
9
  export {
17
10
  MONGO_ID_REGEX,
18
11
  asPopulated,
19
12
  assertPopulated,
20
- createCollection,
21
- createGlobal,
22
- db,
23
- getPayload,
24
13
  isObjectId,
25
14
  isPopulated
26
15
  };
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/payload-cms/index.ts
@@ -33,25 +23,11 @@ __export(payload_cms_exports, {
33
23
  MONGO_ID_REGEX: () => MONGO_ID_REGEX,
34
24
  asPopulated: () => asPopulated,
35
25
  assertPopulated: () => assertPopulated,
36
- createCollection: () => createCollection,
37
- createGlobal: () => createGlobal,
38
- db: () => db,
39
- getPayload: () => getPayload,
40
26
  isObjectId: () => isObjectId,
41
27
  isPopulated: () => isPopulated
42
28
  });
43
29
  module.exports = __toCommonJS(payload_cms_exports);
44
30
 
45
- // src/payload-cms/client/get-payload.ts
46
- var import_payload = require("payload");
47
- var getPayload = async (config) => {
48
- if (config) {
49
- return (0, import_payload.getPayload)({ config });
50
- }
51
- const defaultConfig = await import("@payload-config");
52
- return (0, import_payload.getPayload)({ config: defaultConfig });
53
- };
54
-
55
31
  // src/payload-cms/utils/is-populated.ts
56
32
  function isPopulated(relation) {
57
33
  return typeof relation !== "string";
@@ -77,121 +53,11 @@ function assertPopulated(field, fieldName = "Field") {
77
53
  throw new Error(`${fieldName} is not populated (received ID: ${String(field)})`);
78
54
  }
79
55
  }
80
-
81
- // src/payload-cms/utils/db.ts
82
- var import_react = require("react");
83
- var getClient = (0, import_react.cache)(async () => {
84
- return await getPayload();
85
- });
86
- var db = {
87
- findOne: async (collection, where) => {
88
- const payload = await getClient();
89
- const res = await payload.find({ collection, where, limit: 1 });
90
- return res.docs[0] ?? null;
91
- },
92
- findBySlug: async (collection, slug) => {
93
- return db.findOne(collection, { slug: { equals: slug } });
94
- },
95
- findAll: async (collection, options) => {
96
- const payload = await getClient();
97
- const res = await payload.find({
98
- collection,
99
- limit: options?.limit ?? 100,
100
- ...options
101
- });
102
- return res.docs;
103
- },
104
- findByID: async (collection, id) => {
105
- const payload = await getClient();
106
- return payload.findByID({ collection, id });
107
- },
108
- create: async (collection, data, options) => {
109
- const payload = await getClient();
110
- return payload.create({ collection, data, ...options });
111
- },
112
- update: async (collection, id, data, options) => {
113
- const payload = await getClient();
114
- return payload.update({
115
- collection,
116
- id,
117
- data,
118
- ...options
119
- });
120
- },
121
- updateMany: async (collection, where, data, options) => {
122
- const payload = await getClient();
123
- return payload.update({
124
- collection,
125
- where,
126
- data,
127
- ...options,
128
- id: void 0
129
- });
130
- },
131
- delete: async (collection, id, options) => {
132
- const payload = await getClient();
133
- return payload.delete({
134
- collection,
135
- id,
136
- where: void 0,
137
- ...options
138
- });
139
- },
140
- deleteMany: async (collection, where, options) => {
141
- const payload = await getClient();
142
- return payload.delete({
143
- collection,
144
- where,
145
- id: void 0,
146
- ...options
147
- });
148
- },
149
- global: async (slug) => {
150
- const payload = await getClient();
151
- return payload.findGlobal({ slug });
152
- },
153
- raw: getClient
154
- };
155
-
156
- // src/payload-cms/utils/create-collection.ts
157
- function createCollection(collection, extend) {
158
- const base = {
159
- findOne: (where) => db.findOne(collection, where),
160
- findByID: (id) => db.findByID(collection, id),
161
- findBySlug: (slug) => db.findBySlug(collection, slug),
162
- findAll: (options) => db.findAll(collection, options),
163
- update: (id, data, options) => db.update(collection, id, data, options),
164
- updateMany: (where, data, options) => db.updateMany(collection, where, data, options),
165
- delete: (id, options) => db.delete(collection, id, options),
166
- deleteMany: (where, options) => db.deleteMany(collection, where, options)
167
- };
168
- const extended = extend ? extend(base) : void 0;
169
- return {
170
- ...base,
171
- ...extended
172
- };
173
- }
174
-
175
- // src/payload-cms/utils/create-global.ts
176
- function createGlobal(slug, extend) {
177
- const base = {
178
- get: () => db.global(slug)
179
- };
180
- const extended = extend ? extend(base) : void 0;
181
- return {
182
- ...base,
183
- ...extended
184
- };
185
- }
186
56
  // Annotate the CommonJS export names for ESM import in node:
187
57
  0 && (module.exports = {
188
58
  MONGO_ID_REGEX,
189
59
  asPopulated,
190
60
  assertPopulated,
191
- createCollection,
192
- createGlobal,
193
- db,
194
- getPayload,
195
61
  isObjectId,
196
62
  isPopulated
197
63
  });
@@ -1,2 +1 @@
1
- export * from './client';
2
1
  export * from './utils';
@@ -1,26 +1,15 @@
1
- import "../chunk-EMH4G65N.js";
2
- import "../chunk-NSY6BIWE.js";
1
+ import "../chunk-7GZ4G2P3.js";
3
2
  import {
4
3
  MONGO_ID_REGEX,
5
4
  asPopulated,
6
5
  assertPopulated,
7
- createCollection,
8
- createGlobal,
9
- db,
10
6
  isObjectId,
11
7
  isPopulated
12
- } from "../chunk-EZIPIKRW.js";
13
- import {
14
- getPayload
15
- } from "../chunk-CWTTD7TW.js";
8
+ } from "../chunk-O4W463W3.js";
16
9
  export {
17
10
  MONGO_ID_REGEX,
18
11
  asPopulated,
19
12
  assertPopulated,
20
- createCollection,
21
- createGlobal,
22
- db,
23
- getPayload,
24
13
  isObjectId,
25
14
  isPopulated
26
15
  };
@@ -1,19 +1,19 @@
1
- import type { CollectionSlug, GlobalSlug, Where } from 'payload';
2
- import { getPayload } from '../client/get-payload';
1
+ import type { CollectionSlug, DataFromCollectionSlug, DataFromGlobalSlug, GlobalSlug, Where } from 'payload';
2
+ import { getPayload } from './get-payload';
3
3
  export type FindAllOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['find']>[0], 'collection'>;
4
4
  export type UpdateOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['update']>[0], 'collection' | 'id' | 'data' | 'where'>;
5
5
  export type DeleteOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['delete']>[0], 'collection' | 'id' | 'where'>;
6
6
  export type UpdateData = Parameters<Awaited<ReturnType<typeof getPayload>>['update']>[0]['data'];
7
7
  export declare const db: {
8
- findOne: <TSlug extends CollectionSlug>(collection: TSlug, where?: Where) => Promise<import("payload").JsonObject & import("payload").TypeWithID>;
9
- findBySlug: <TSlug extends CollectionSlug>(collection: TSlug, slug: string) => Promise<import("payload").JsonObject & import("payload").TypeWithID>;
10
- findAll: <TSlug extends CollectionSlug>(collection: TSlug, options?: FindAllOptions) => Promise<(import("payload").JsonObject & import("payload").TypeWithID)[]>;
11
- findByID: <TSlug extends CollectionSlug>(collection: TSlug, id: string | number) => Promise<import("payload").JsonObject & import("payload").TypeWithID>;
8
+ findOne: <TSlug extends CollectionSlug>(collection: TSlug, where?: Where) => Promise<DataFromCollectionSlug<TSlug>>;
9
+ findBySlug: <TSlug extends CollectionSlug>(collection: TSlug, slug: string) => Promise<DataFromCollectionSlug<TSlug>>;
10
+ findAll: <TSlug extends CollectionSlug>(collection: TSlug, options?: FindAllOptions) => Promise<DataFromCollectionSlug<TSlug>[]>;
11
+ findByID: <TSlug extends CollectionSlug>(collection: TSlug, id: string | number) => Promise<DataFromCollectionSlug<TSlug>>;
12
12
  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>;
13
13
  update: <TSlug extends CollectionSlug>(collection: TSlug, id: string | number, data: UpdateData, options?: UpdateOptions) => Promise<import("payload").JsonObject & import("payload").TypeWithID>;
14
14
  updateMany: <TSlug extends CollectionSlug>(collection: TSlug, where: Where, data: UpdateData, options?: UpdateOptions) => Promise<import("payload").BulkOperationResult<TSlug, import("payload").SelectExcludeType | import("payload").SelectIncludeType>>;
15
15
  delete: <TSlug extends CollectionSlug>(collection: TSlug, id: string | number, options?: DeleteOptions) => Promise<import("payload").JsonObject & import("payload").TypeWithID>;
16
16
  deleteMany: <TSlug extends CollectionSlug>(collection: TSlug, where: Where, options?: DeleteOptions) => Promise<import("payload").BulkOperationResult<TSlug, import("payload").SelectExcludeType | import("payload").SelectIncludeType>>;
17
- global: <TSlug extends GlobalSlug>(slug: TSlug) => Promise<import("payload").JsonObject>;
17
+ global: <TSlug extends GlobalSlug>(slug: TSlug) => Promise<DataFromGlobalSlug<TSlug>>;
18
18
  raw: () => Promise<import("payload").BasePayload>;
19
19
  };
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/payload-cms/server/index.ts
31
+ var server_exports = {};
32
+ __export(server_exports, {
33
+ createCollection: () => createCollection,
34
+ createGlobal: () => createGlobal,
35
+ db: () => db,
36
+ getPayload: () => getPayload
37
+ });
38
+ module.exports = __toCommonJS(server_exports);
39
+
40
+ // src/payload-cms/server/db.ts
41
+ var import_react = require("react");
42
+
43
+ // src/payload-cms/server/get-payload.ts
44
+ var import_payload = require("payload");
45
+ var getPayload = async (config) => {
46
+ if (config) {
47
+ return (0, import_payload.getPayload)({ config });
48
+ }
49
+ const payloadConfig = await import(
50
+ /* webpackIgnore: true */
51
+ "@payload-config"
52
+ );
53
+ const resolvedConfig = payloadConfig.default || payloadConfig;
54
+ return (0, import_payload.getPayload)({ config: resolvedConfig });
55
+ };
56
+
57
+ // src/payload-cms/server/db.ts
58
+ var getClient = (0, import_react.cache)(async () => {
59
+ return await getPayload();
60
+ });
61
+ var db = {
62
+ findOne: async (collection, where) => {
63
+ const payload = await getClient();
64
+ const res = await payload.find({ collection, where, limit: 1 });
65
+ return res.docs[0] ?? null;
66
+ },
67
+ findBySlug: async (collection, slug) => {
68
+ return db.findOne(collection, { slug: { equals: slug } });
69
+ },
70
+ findAll: async (collection, options) => {
71
+ const payload = await getClient();
72
+ const res = await payload.find({
73
+ collection,
74
+ limit: options?.limit ?? 100,
75
+ ...options
76
+ });
77
+ return res.docs;
78
+ },
79
+ findByID: async (collection, id) => {
80
+ const payload = await getClient();
81
+ return payload.findByID({ collection, id });
82
+ },
83
+ create: async (collection, data, options) => {
84
+ const payload = await getClient();
85
+ return payload.create({ collection, data, ...options });
86
+ },
87
+ update: async (collection, id, data, options) => {
88
+ const payload = await getClient();
89
+ return payload.update({
90
+ collection,
91
+ id,
92
+ data,
93
+ ...options
94
+ });
95
+ },
96
+ updateMany: async (collection, where, data, options) => {
97
+ const payload = await getClient();
98
+ return payload.update({
99
+ collection,
100
+ where,
101
+ data,
102
+ ...options,
103
+ id: void 0
104
+ });
105
+ },
106
+ delete: async (collection, id, options) => {
107
+ const payload = await getClient();
108
+ return payload.delete({
109
+ collection,
110
+ id,
111
+ where: void 0,
112
+ ...options
113
+ });
114
+ },
115
+ deleteMany: async (collection, where, options) => {
116
+ const payload = await getClient();
117
+ return payload.delete({
118
+ collection,
119
+ where,
120
+ id: void 0,
121
+ ...options
122
+ });
123
+ },
124
+ global: async (slug) => {
125
+ const payload = await getClient();
126
+ return payload.findGlobal({ slug });
127
+ },
128
+ raw: getClient
129
+ };
130
+
131
+ // src/payload-cms/server/create-collection.ts
132
+ function createCollection(collection, extend) {
133
+ const base = {
134
+ findOne: (where) => db.findOne(collection, where),
135
+ findByID: (id) => db.findByID(collection, id),
136
+ findBySlug: (slug) => db.findBySlug(collection, slug),
137
+ findAll: (options) => db.findAll(collection, options),
138
+ update: (id, data, options) => db.update(collection, id, data, options),
139
+ updateMany: (where, data, options) => db.updateMany(collection, where, data, options),
140
+ delete: (id, options) => db.delete(collection, id, options),
141
+ deleteMany: (where, options) => db.deleteMany(collection, where, options)
142
+ };
143
+ const extended = extend ? extend(base) : void 0;
144
+ return {
145
+ ...base,
146
+ ...extended
147
+ };
148
+ }
149
+
150
+ // src/payload-cms/server/create-global.ts
151
+ function createGlobal(slug, extend) {
152
+ const base = {
153
+ get: () => db.global(slug)
154
+ };
155
+ const extended = extend ? extend(base) : void 0;
156
+ return {
157
+ ...base,
158
+ ...extended
159
+ };
160
+ }
161
+ // Annotate the CommonJS export names for ESM import in node:
162
+ 0 && (module.exports = {
163
+ createCollection,
164
+ createGlobal,
165
+ db,
166
+ getPayload
167
+ });
@@ -0,0 +1,4 @@
1
+ export * from './create-collection';
2
+ export * from './create-global';
3
+ export * from './db';
4
+ export * from './get-payload';
@@ -1,35 +1,21 @@
1
- import {
2
- getPayload
3
- } from "./chunk-CWTTD7TW.js";
4
-
5
- // src/payload-cms/utils/is-populated.ts
6
- function isPopulated(relation) {
7
- return typeof relation !== "string";
8
- }
9
-
10
- // src/payload-cms/utils/as-populated.ts
11
- function asPopulated(relation) {
12
- return isPopulated(relation) ? relation : void 0;
13
- }
14
-
15
- // src/payload-cms/utils/is-object-id.ts
16
- var MONGO_ID_REGEX = /^[0-9a-fA-F]{24}$/;
17
- function isObjectId(value) {
18
- return typeof value === "string" && MONGO_ID_REGEX.test(value);
19
- }
1
+ // src/payload-cms/server/db.ts
2
+ import { cache } from "react";
20
3
 
21
- // src/payload-cms/utils/assert-populated.ts
22
- function assertPopulated(field, fieldName = "Field") {
23
- if (field === null || field === void 0) {
24
- throw new Error(`${fieldName} is undefined or null`);
4
+ // src/payload-cms/server/get-payload.ts
5
+ import { getPayload as getPayloadSDK } from "payload";
6
+ var getPayload = async (config) => {
7
+ if (config) {
8
+ return getPayloadSDK({ config });
25
9
  }
26
- if (isObjectId(field)) {
27
- throw new Error(`${fieldName} is not populated (received ID: ${String(field)})`);
28
- }
29
- }
10
+ const payloadConfig = await import(
11
+ /* webpackIgnore: true */
12
+ "@payload-config"
13
+ );
14
+ const resolvedConfig = payloadConfig.default || payloadConfig;
15
+ return getPayloadSDK({ config: resolvedConfig });
16
+ };
30
17
 
31
- // src/payload-cms/utils/db.ts
32
- import { cache } from "react";
18
+ // src/payload-cms/server/db.ts
33
19
  var getClient = cache(async () => {
34
20
  return await getPayload();
35
21
  });
@@ -103,7 +89,7 @@ var db = {
103
89
  raw: getClient
104
90
  };
105
91
 
106
- // src/payload-cms/utils/create-collection.ts
92
+ // src/payload-cms/server/create-collection.ts
107
93
  function createCollection(collection, extend) {
108
94
  const base = {
109
95
  findOne: (where) => db.findOne(collection, where),
@@ -122,7 +108,7 @@ function createCollection(collection, extend) {
122
108
  };
123
109
  }
124
110
 
125
- // src/payload-cms/utils/create-global.ts
111
+ // src/payload-cms/server/create-global.ts
126
112
  function createGlobal(slug, extend) {
127
113
  const base = {
128
114
  get: () => db.global(slug)
@@ -133,14 +119,9 @@ function createGlobal(slug, extend) {
133
119
  ...extended
134
120
  };
135
121
  }
136
-
137
122
  export {
138
- isPopulated,
139
- asPopulated,
140
- MONGO_ID_REGEX,
141
- isObjectId,
142
- assertPopulated,
143
- db,
144
123
  createCollection,
145
- createGlobal
124
+ createGlobal,
125
+ db,
126
+ getPayload
146
127
  };
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/payload-cms/utils/index.ts
@@ -33,9 +23,6 @@ __export(utils_exports, {
33
23
  MONGO_ID_REGEX: () => MONGO_ID_REGEX,
34
24
  asPopulated: () => asPopulated,
35
25
  assertPopulated: () => assertPopulated,
36
- createCollection: () => createCollection,
37
- createGlobal: () => createGlobal,
38
- db: () => db,
39
26
  isObjectId: () => isObjectId,
40
27
  isPopulated: () => isPopulated
41
28
  });
@@ -66,132 +53,11 @@ function assertPopulated(field, fieldName = "Field") {
66
53
  throw new Error(`${fieldName} is not populated (received ID: ${String(field)})`);
67
54
  }
68
55
  }
69
-
70
- // src/payload-cms/utils/db.ts
71
- var import_react = require("react");
72
-
73
- // src/payload-cms/client/get-payload.ts
74
- var import_payload = require("payload");
75
- var getPayload = async (config) => {
76
- if (config) {
77
- return (0, import_payload.getPayload)({ config });
78
- }
79
- const defaultConfig = await import("@payload-config");
80
- return (0, import_payload.getPayload)({ config: defaultConfig });
81
- };
82
-
83
- // src/payload-cms/utils/db.ts
84
- var getClient = (0, import_react.cache)(async () => {
85
- return await getPayload();
86
- });
87
- var db = {
88
- findOne: async (collection, where) => {
89
- const payload = await getClient();
90
- const res = await payload.find({ collection, where, limit: 1 });
91
- return res.docs[0] ?? null;
92
- },
93
- findBySlug: async (collection, slug) => {
94
- return db.findOne(collection, { slug: { equals: slug } });
95
- },
96
- findAll: async (collection, options) => {
97
- const payload = await getClient();
98
- const res = await payload.find({
99
- collection,
100
- limit: options?.limit ?? 100,
101
- ...options
102
- });
103
- return res.docs;
104
- },
105
- findByID: async (collection, id) => {
106
- const payload = await getClient();
107
- return payload.findByID({ collection, id });
108
- },
109
- create: async (collection, data, options) => {
110
- const payload = await getClient();
111
- return payload.create({ collection, data, ...options });
112
- },
113
- update: async (collection, id, data, options) => {
114
- const payload = await getClient();
115
- return payload.update({
116
- collection,
117
- id,
118
- data,
119
- ...options
120
- });
121
- },
122
- updateMany: async (collection, where, data, options) => {
123
- const payload = await getClient();
124
- return payload.update({
125
- collection,
126
- where,
127
- data,
128
- ...options,
129
- id: void 0
130
- });
131
- },
132
- delete: async (collection, id, options) => {
133
- const payload = await getClient();
134
- return payload.delete({
135
- collection,
136
- id,
137
- where: void 0,
138
- ...options
139
- });
140
- },
141
- deleteMany: async (collection, where, options) => {
142
- const payload = await getClient();
143
- return payload.delete({
144
- collection,
145
- where,
146
- id: void 0,
147
- ...options
148
- });
149
- },
150
- global: async (slug) => {
151
- const payload = await getClient();
152
- return payload.findGlobal({ slug });
153
- },
154
- raw: getClient
155
- };
156
-
157
- // src/payload-cms/utils/create-collection.ts
158
- function createCollection(collection, extend) {
159
- const base = {
160
- findOne: (where) => db.findOne(collection, where),
161
- findByID: (id) => db.findByID(collection, id),
162
- findBySlug: (slug) => db.findBySlug(collection, slug),
163
- findAll: (options) => db.findAll(collection, options),
164
- update: (id, data, options) => db.update(collection, id, data, options),
165
- updateMany: (where, data, options) => db.updateMany(collection, where, data, options),
166
- delete: (id, options) => db.delete(collection, id, options),
167
- deleteMany: (where, options) => db.deleteMany(collection, where, options)
168
- };
169
- const extended = extend ? extend(base) : void 0;
170
- return {
171
- ...base,
172
- ...extended
173
- };
174
- }
175
-
176
- // src/payload-cms/utils/create-global.ts
177
- function createGlobal(slug, extend) {
178
- const base = {
179
- get: () => db.global(slug)
180
- };
181
- const extended = extend ? extend(base) : void 0;
182
- return {
183
- ...base,
184
- ...extended
185
- };
186
- }
187
56
  // Annotate the CommonJS export names for ESM import in node:
188
57
  0 && (module.exports = {
189
58
  MONGO_ID_REGEX,
190
59
  asPopulated,
191
60
  assertPopulated,
192
- createCollection,
193
- createGlobal,
194
- db,
195
61
  isObjectId,
196
62
  isPopulated
197
63
  });
@@ -1,7 +1,4 @@
1
1
  export * from './as-populated';
2
2
  export * from './assert-populated';
3
- export * from './create-collection';
4
- export * from './create-global';
5
- export * from './db';
6
3
  export * from './is-object-id';
7
4
  export * from './is-populated';
@@ -2,20 +2,13 @@ import {
2
2
  MONGO_ID_REGEX,
3
3
  asPopulated,
4
4
  assertPopulated,
5
- createCollection,
6
- createGlobal,
7
- db,
8
5
  isObjectId,
9
6
  isPopulated
10
- } from "../../chunk-EZIPIKRW.js";
11
- import "../../chunk-CWTTD7TW.js";
7
+ } from "../../chunk-O4W463W3.js";
12
8
  export {
13
9
  MONGO_ID_REGEX,
14
10
  asPopulated,
15
11
  assertPopulated,
16
- createCollection,
17
- createGlobal,
18
- db,
19
12
  isObjectId,
20
13
  isPopulated
21
14
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matvdt/js-toolkit",
3
- "version": "0.0.1-canary.5",
3
+ "version": "0.0.1-canary.7",
4
4
  "description": "JS/TS toolkit",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -15,6 +15,11 @@
15
15
  "types": "./dist/payload-cms/index.d.ts",
16
16
  "import": "./dist/payload-cms/index.js",
17
17
  "require": "./dist/payload-cms/index.cjs"
18
+ },
19
+ "./payload-cms/server": {
20
+ "types": "./dist/payload-cms/server/index.d.ts",
21
+ "import": "./dist/payload-cms/server/index.js",
22
+ "require": "./dist/payload-cms/server/index.cjs"
18
23
  }
19
24
  },
20
25
  "files": [
@@ -1,13 +0,0 @@
1
- // src/payload-cms/client/get-payload.ts
2
- import { getPayload as getPayloadSDK } from "payload";
3
- var getPayload = async (config) => {
4
- if (config) {
5
- return getPayloadSDK({ config });
6
- }
7
- const defaultConfig = await import("@payload-config");
8
- return getPayloadSDK({ config: defaultConfig });
9
- };
10
-
11
- export {
12
- getPayload
13
- };
File without changes
@@ -1,49 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/payload-cms/client/index.ts
31
- var client_exports = {};
32
- __export(client_exports, {
33
- getPayload: () => getPayload
34
- });
35
- module.exports = __toCommonJS(client_exports);
36
-
37
- // src/payload-cms/client/get-payload.ts
38
- var import_payload = require("payload");
39
- var getPayload = async (config) => {
40
- if (config) {
41
- return (0, import_payload.getPayload)({ config });
42
- }
43
- const defaultConfig = await import("@payload-config");
44
- return (0, import_payload.getPayload)({ config: defaultConfig });
45
- };
46
- // Annotate the CommonJS export names for ESM import in node:
47
- 0 && (module.exports = {
48
- getPayload
49
- });
@@ -1 +0,0 @@
1
- export * from './get-payload';
@@ -1,7 +0,0 @@
1
- import "../../chunk-NSY6BIWE.js";
2
- import {
3
- getPayload
4
- } from "../../chunk-CWTTD7TW.js";
5
- export {
6
- getPayload
7
- };
File without changes