@matvdt/js-toolkit 0.0.1-canary.2 → 0.0.1-canary.20

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,247 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/payload-cms/server/index.ts
21
+ var server_exports = {};
22
+ __export(server_exports, {
23
+ cacheKey: () => cacheKey,
24
+ configurePayload: () => configurePayload,
25
+ createCollection: () => createCollection,
26
+ createGlobal: () => createGlobal,
27
+ getPayload: () => getPayload,
28
+ payload: () => payload,
29
+ revalidateCollection: () => revalidateCollection,
30
+ revalidateDoc: () => revalidateDoc,
31
+ revalidateGlobal: () => revalidateGlobal,
32
+ withCache: () => withCache
33
+ });
34
+ module.exports = __toCommonJS(server_exports);
35
+
36
+ // src/payload-cms/server/cache.ts
37
+ var import_cache = require("next/cache");
38
+ function cacheKey(collection, method, args) {
39
+ return [`payload:${collection}:${method}`, JSON.stringify(args)];
40
+ }
41
+ function withCache(collection, method, args, tags, fn) {
42
+ return (0, import_cache.unstable_cache)(fn, cacheKey(collection, method, args), { tags })();
43
+ }
44
+ function revalidateCollection(collection) {
45
+ (0, import_cache.revalidateTag)(`collection:${collection}`, "max");
46
+ }
47
+ function revalidateDoc(collection, id) {
48
+ (0, import_cache.revalidateTag)(`doc:${collection}:${id}`, "max");
49
+ }
50
+ function revalidateGlobal(slug) {
51
+ (0, import_cache.revalidateTag)(`global:${slug}`, "max");
52
+ }
53
+
54
+ // src/payload-cms/server/payload.ts
55
+ var import_react = require("react");
56
+
57
+ // src/payload-cms/server/get-payload.ts
58
+ var import_payload = require("payload");
59
+ var payloadConfig;
60
+ function configurePayload(config) {
61
+ if (payloadConfig) return;
62
+ payloadConfig = config;
63
+ }
64
+ var getPayload = async (config) => {
65
+ const resolvedConfig = config ?? payloadConfig;
66
+ if (!resolvedConfig) {
67
+ throw new Error(
68
+ "[@matvdt/js-toolkit] No Payload config available. Call configurePayload(config) once at app startup, or pass config explicitly to getPayload(config)."
69
+ );
70
+ }
71
+ return (0, import_payload.getPayload)({ config: resolvedConfig });
72
+ };
73
+
74
+ // src/payload-cms/server/payload.ts
75
+ var getClient = (0, import_react.cache)(async () => {
76
+ return await getPayload();
77
+ });
78
+ var payload = {
79
+ findOne: async (collection, options) => {
80
+ return withCache(collection, "findOne", [options], [`collection:${collection}`], async () => {
81
+ const client = await getClient();
82
+ const res = await client.find({
83
+ ...options,
84
+ collection,
85
+ limit: 1
86
+ });
87
+ return res.docs[0] ?? null;
88
+ });
89
+ },
90
+ findBySlug: async (collection, slug, options) => {
91
+ return payload.findOne(
92
+ collection,
93
+ {
94
+ ...options,
95
+ where: {
96
+ ...options?.where,
97
+ slug: { equals: slug }
98
+ }
99
+ }
100
+ );
101
+ },
102
+ find: async (collection, options) => {
103
+ return withCache(collection, "find", [options], [`collection:${collection}`], async () => {
104
+ const client = await getClient();
105
+ return client.find({
106
+ ...options,
107
+ collection
108
+ });
109
+ });
110
+ },
111
+ findAll: async (collection, options) => {
112
+ return withCache(collection, "findAll", [options], [`collection:${collection}`], async () => {
113
+ const client = await getClient();
114
+ const res = await client.find({
115
+ ...options,
116
+ collection,
117
+ limit: options?.limit ?? 100
118
+ });
119
+ return res.docs;
120
+ });
121
+ },
122
+ findByID: async (collection, id, options) => {
123
+ return withCache(collection, "findByID", [id, options], [`collection:${collection}`, `doc:${collection}:${id}`], async () => {
124
+ const client = await getClient();
125
+ return client.findByID({
126
+ ...options,
127
+ collection,
128
+ id
129
+ });
130
+ });
131
+ },
132
+ create: async (collection, data, options) => {
133
+ const client = await getClient();
134
+ const result = await client.create({
135
+ ...options,
136
+ collection,
137
+ data
138
+ });
139
+ revalidateCollection(collection);
140
+ return result;
141
+ },
142
+ update: async (collection, id, data, options) => {
143
+ const client = await getClient();
144
+ const result = await client.update({
145
+ ...options,
146
+ collection,
147
+ id,
148
+ data
149
+ });
150
+ revalidateCollection(collection);
151
+ revalidateDoc(collection, id);
152
+ return result;
153
+ },
154
+ updateMany: async (collection, where, data, options) => {
155
+ const client = await getClient();
156
+ const result = await client.update({
157
+ ...options,
158
+ collection,
159
+ where,
160
+ data,
161
+ id: void 0
162
+ });
163
+ revalidateCollection(collection);
164
+ return result;
165
+ },
166
+ delete: async (collection, id, options) => {
167
+ const client = await getClient();
168
+ const result = await client.delete({
169
+ ...options,
170
+ collection,
171
+ id,
172
+ where: void 0
173
+ });
174
+ revalidateCollection(collection);
175
+ revalidateDoc(collection, id);
176
+ return result;
177
+ },
178
+ deleteMany: async (collection, where, options) => {
179
+ const client = await getClient();
180
+ const result = await client.delete({
181
+ ...options,
182
+ collection,
183
+ where,
184
+ id: void 0
185
+ });
186
+ revalidateCollection(collection);
187
+ return result;
188
+ },
189
+ global: async (slug) => {
190
+ return withCache("global", slug, [], [`global:${slug}`], async () => {
191
+ const client = await getClient();
192
+ return client.findGlobal({ slug });
193
+ });
194
+ },
195
+ aggregate: async (collection, pipeline, options) => {
196
+ return withCache(collection, "aggregate", [pipeline, options], [`collection:${collection}`], async () => {
197
+ const client = await getClient();
198
+ return client.db.collections[collection].aggregate(pipeline, options);
199
+ });
200
+ },
201
+ raw: getClient
202
+ };
203
+
204
+ // src/payload-cms/server/create-collection.ts
205
+ function createCollection(collection, extend) {
206
+ const base = {
207
+ find: (options) => payload.find(collection, options),
208
+ findOne: (options) => payload.findOne(collection, options),
209
+ findByID: (id, options) => payload.findByID(collection, id, options),
210
+ findBySlug: (slug, options) => payload.findBySlug(collection, slug, options),
211
+ findAll: (options) => payload.findAll(collection, options),
212
+ update: (id, data, options) => payload.update(collection, id, data, options),
213
+ updateMany: (where, data, options) => payload.updateMany(collection, where, data, options),
214
+ delete: (id, options) => payload.delete(collection, id, options),
215
+ deleteMany: (where, options) => payload.deleteMany(collection, where, options)
216
+ };
217
+ const extended = extend ? extend(base) : void 0;
218
+ return {
219
+ ...base,
220
+ ...extended
221
+ };
222
+ }
223
+
224
+ // src/payload-cms/server/create-global.ts
225
+ function createGlobal(slug, extend) {
226
+ const base = {
227
+ get: () => payload.global(slug)
228
+ };
229
+ const extended = extend ? extend(base) : void 0;
230
+ return {
231
+ ...base,
232
+ ...extended
233
+ };
234
+ }
235
+ // Annotate the CommonJS export names for ESM import in node:
236
+ 0 && (module.exports = {
237
+ cacheKey,
238
+ configurePayload,
239
+ createCollection,
240
+ createGlobal,
241
+ getPayload,
242
+ payload,
243
+ revalidateCollection,
244
+ revalidateDoc,
245
+ revalidateGlobal,
246
+ withCache
247
+ });
@@ -0,0 +1,5 @@
1
+ export * from './cache';
2
+ export * from './create-collection';
3
+ export * from './create-global';
4
+ export * from './get-payload';
5
+ export * from './payload';
@@ -0,0 +1,211 @@
1
+ // src/payload-cms/server/cache.ts
2
+ import { unstable_cache, revalidateTag } from "next/cache";
3
+ function cacheKey(collection, method, args) {
4
+ return [`payload:${collection}:${method}`, JSON.stringify(args)];
5
+ }
6
+ function withCache(collection, method, args, tags, fn) {
7
+ return unstable_cache(fn, cacheKey(collection, method, args), { tags })();
8
+ }
9
+ function revalidateCollection(collection) {
10
+ revalidateTag(`collection:${collection}`, "max");
11
+ }
12
+ function revalidateDoc(collection, id) {
13
+ revalidateTag(`doc:${collection}:${id}`, "max");
14
+ }
15
+ function revalidateGlobal(slug) {
16
+ revalidateTag(`global:${slug}`, "max");
17
+ }
18
+
19
+ // src/payload-cms/server/payload.ts
20
+ import { cache } from "react";
21
+
22
+ // src/payload-cms/server/get-payload.ts
23
+ import { getPayload as getPayloadSDK } from "payload";
24
+ var payloadConfig;
25
+ function configurePayload(config) {
26
+ if (payloadConfig) return;
27
+ payloadConfig = config;
28
+ }
29
+ var getPayload = async (config) => {
30
+ const resolvedConfig = config ?? payloadConfig;
31
+ if (!resolvedConfig) {
32
+ throw new Error(
33
+ "[@matvdt/js-toolkit] No Payload config available. Call configurePayload(config) once at app startup, or pass config explicitly to getPayload(config)."
34
+ );
35
+ }
36
+ return getPayloadSDK({ config: resolvedConfig });
37
+ };
38
+
39
+ // src/payload-cms/server/payload.ts
40
+ var getClient = cache(async () => {
41
+ return await getPayload();
42
+ });
43
+ var payload = {
44
+ findOne: async (collection, options) => {
45
+ return withCache(collection, "findOne", [options], [`collection:${collection}`], async () => {
46
+ const client = await getClient();
47
+ const res = await client.find({
48
+ ...options,
49
+ collection,
50
+ limit: 1
51
+ });
52
+ return res.docs[0] ?? null;
53
+ });
54
+ },
55
+ findBySlug: async (collection, slug, options) => {
56
+ return payload.findOne(
57
+ collection,
58
+ {
59
+ ...options,
60
+ where: {
61
+ ...options?.where,
62
+ slug: { equals: slug }
63
+ }
64
+ }
65
+ );
66
+ },
67
+ find: async (collection, options) => {
68
+ return withCache(collection, "find", [options], [`collection:${collection}`], async () => {
69
+ const client = await getClient();
70
+ return client.find({
71
+ ...options,
72
+ collection
73
+ });
74
+ });
75
+ },
76
+ findAll: async (collection, options) => {
77
+ return withCache(collection, "findAll", [options], [`collection:${collection}`], async () => {
78
+ const client = await getClient();
79
+ const res = await client.find({
80
+ ...options,
81
+ collection,
82
+ limit: options?.limit ?? 100
83
+ });
84
+ return res.docs;
85
+ });
86
+ },
87
+ findByID: async (collection, id, options) => {
88
+ return withCache(collection, "findByID", [id, options], [`collection:${collection}`, `doc:${collection}:${id}`], async () => {
89
+ const client = await getClient();
90
+ return client.findByID({
91
+ ...options,
92
+ collection,
93
+ id
94
+ });
95
+ });
96
+ },
97
+ create: async (collection, data, options) => {
98
+ const client = await getClient();
99
+ const result = await client.create({
100
+ ...options,
101
+ collection,
102
+ data
103
+ });
104
+ revalidateCollection(collection);
105
+ return result;
106
+ },
107
+ update: async (collection, id, data, options) => {
108
+ const client = await getClient();
109
+ const result = await client.update({
110
+ ...options,
111
+ collection,
112
+ id,
113
+ data
114
+ });
115
+ revalidateCollection(collection);
116
+ revalidateDoc(collection, id);
117
+ return result;
118
+ },
119
+ updateMany: async (collection, where, data, options) => {
120
+ const client = await getClient();
121
+ const result = await client.update({
122
+ ...options,
123
+ collection,
124
+ where,
125
+ data,
126
+ id: void 0
127
+ });
128
+ revalidateCollection(collection);
129
+ return result;
130
+ },
131
+ delete: async (collection, id, options) => {
132
+ const client = await getClient();
133
+ const result = await client.delete({
134
+ ...options,
135
+ collection,
136
+ id,
137
+ where: void 0
138
+ });
139
+ revalidateCollection(collection);
140
+ revalidateDoc(collection, id);
141
+ return result;
142
+ },
143
+ deleteMany: async (collection, where, options) => {
144
+ const client = await getClient();
145
+ const result = await client.delete({
146
+ ...options,
147
+ collection,
148
+ where,
149
+ id: void 0
150
+ });
151
+ revalidateCollection(collection);
152
+ return result;
153
+ },
154
+ global: async (slug) => {
155
+ return withCache("global", slug, [], [`global:${slug}`], async () => {
156
+ const client = await getClient();
157
+ return client.findGlobal({ slug });
158
+ });
159
+ },
160
+ aggregate: async (collection, pipeline, options) => {
161
+ return withCache(collection, "aggregate", [pipeline, options], [`collection:${collection}`], async () => {
162
+ const client = await getClient();
163
+ return client.db.collections[collection].aggregate(pipeline, options);
164
+ });
165
+ },
166
+ raw: getClient
167
+ };
168
+
169
+ // src/payload-cms/server/create-collection.ts
170
+ function createCollection(collection, extend) {
171
+ const base = {
172
+ find: (options) => payload.find(collection, options),
173
+ findOne: (options) => payload.findOne(collection, options),
174
+ findByID: (id, options) => payload.findByID(collection, id, options),
175
+ findBySlug: (slug, options) => payload.findBySlug(collection, slug, options),
176
+ findAll: (options) => payload.findAll(collection, options),
177
+ update: (id, data, options) => payload.update(collection, id, data, options),
178
+ updateMany: (where, data, options) => payload.updateMany(collection, where, data, options),
179
+ delete: (id, options) => payload.delete(collection, id, options),
180
+ deleteMany: (where, options) => payload.deleteMany(collection, where, options)
181
+ };
182
+ const extended = extend ? extend(base) : void 0;
183
+ return {
184
+ ...base,
185
+ ...extended
186
+ };
187
+ }
188
+
189
+ // src/payload-cms/server/create-global.ts
190
+ function createGlobal(slug, extend) {
191
+ const base = {
192
+ get: () => payload.global(slug)
193
+ };
194
+ const extended = extend ? extend(base) : void 0;
195
+ return {
196
+ ...base,
197
+ ...extended
198
+ };
199
+ }
200
+ export {
201
+ cacheKey,
202
+ configurePayload,
203
+ createCollection,
204
+ createGlobal,
205
+ getPayload,
206
+ payload,
207
+ revalidateCollection,
208
+ revalidateDoc,
209
+ revalidateGlobal,
210
+ withCache
211
+ };
@@ -1,19 +1,23 @@
1
- import type { CollectionSlug, GlobalSlug, Where } from 'payload';
2
- import { getPayload } from '../client/get-payload';
3
- export type FindAllOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['find']>[0], 'collection'>;
1
+ import type { CollectionSlug, DataFromCollectionSlug, DataFromGlobalSlug, GlobalSlug, PaginatedDocs, Where } from 'payload';
2
+ import { getPayload } from './get-payload';
3
+ import { PipelineStage, Aggregate, AggregateOptions } from "mongoose";
4
+ export type FindOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['find']>[0], 'collection'>;
5
+ export type FindByIDOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['findByID']>[0], 'collection' | 'id'>;
4
6
  export type UpdateOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['update']>[0], 'collection' | 'id' | 'data' | 'where'>;
5
7
  export type DeleteOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['delete']>[0], 'collection' | 'id' | 'where'>;
6
8
  export type UpdateData = Parameters<Awaited<ReturnType<typeof getPayload>>['update']>[0]['data'];
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>;
9
+ export declare const payload: {
10
+ findOne: <TSlug extends CollectionSlug>(collection: TSlug, options?: FindOptions) => Promise<DataFromCollectionSlug<TSlug>>;
11
+ findBySlug: <TSlug extends CollectionSlug>(collection: TSlug, slug: string, options?: FindOptions) => Promise<DataFromCollectionSlug<TSlug>>;
12
+ find: <TSlug extends CollectionSlug>(collection: TSlug, options?: FindOptions) => Promise<PaginatedDocs<DataFromCollectionSlug<TSlug>>>;
13
+ findAll: <TSlug extends CollectionSlug>(collection: TSlug, options?: FindOptions) => Promise<DataFromCollectionSlug<TSlug>[]>;
14
+ findByID: <TSlug extends CollectionSlug>(collection: TSlug, id: string | number, options?: FindByIDOptions) => Promise<DataFromCollectionSlug<TSlug>>;
12
15
  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
16
  update: <TSlug extends CollectionSlug>(collection: TSlug, id: string | number, data: UpdateData, options?: UpdateOptions) => Promise<import("payload").JsonObject & import("payload").TypeWithID>;
14
17
  updateMany: <TSlug extends CollectionSlug>(collection: TSlug, where: Where, data: UpdateData, options?: UpdateOptions) => Promise<import("payload").BulkOperationResult<TSlug, import("payload").SelectExcludeType | import("payload").SelectIncludeType>>;
15
18
  delete: <TSlug extends CollectionSlug>(collection: TSlug, id: string | number, options?: DeleteOptions) => Promise<import("payload").JsonObject & import("payload").TypeWithID>;
16
19
  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>;
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[]>>;
18
22
  raw: () => Promise<import("payload").BasePayload>;
19
23
  };
@@ -0,0 +1,5 @@
1
+ export declare function hasId<T>(item: T & {
2
+ id?: string | null;
3
+ }): item is T & {
4
+ id: string;
5
+ };
@@ -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,11 +23,10 @@ __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,
26
+ hasId: () => hasId,
39
27
  isObjectId: () => isObjectId,
40
- isPopulated: () => isPopulated
28
+ isPopulated: () => isPopulated,
29
+ unwrapPopulated: () => unwrapPopulated
41
30
  });
42
31
  module.exports = __toCommonJS(utils_exports);
43
32
 
@@ -67,131 +56,28 @@ function assertPopulated(field, fieldName = "Field") {
67
56
  }
68
57
  }
69
58
 
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
- };
59
+ // src/payload-cms/utils/has-id.ts
60
+ function hasId(item) {
61
+ return item.id !== null && item.id !== void 0;
174
62
  }
175
63
 
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
- };
64
+ // src/payload-cms/utils/unwrap-populated.ts
65
+ function unwrapPopulated(value, message = "Value is missing or not populated") {
66
+ if (value === null || value === void 0) {
67
+ throw new Error(message);
68
+ }
69
+ if (typeof value === "string" && isObjectId(value)) {
70
+ throw new Error(message);
71
+ }
72
+ return value;
186
73
  }
187
74
  // Annotate the CommonJS export names for ESM import in node:
188
75
  0 && (module.exports = {
189
76
  MONGO_ID_REGEX,
190
77
  asPopulated,
191
78
  assertPopulated,
192
- createCollection,
193
- createGlobal,
194
- db,
79
+ hasId,
195
80
  isObjectId,
196
- isPopulated
81
+ isPopulated,
82
+ unwrapPopulated
197
83
  });