@matvdt/js-toolkit 0.0.1-canary.10

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.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # js-toolkit
File without changes
@@ -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 ADDED
@@ -0,0 +1,63 @@
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/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ MONGO_ID_REGEX: () => MONGO_ID_REGEX,
24
+ asPopulated: () => asPopulated,
25
+ assertPopulated: () => assertPopulated,
26
+ isObjectId: () => isObjectId,
27
+ isPopulated: () => isPopulated
28
+ });
29
+ module.exports = __toCommonJS(index_exports);
30
+
31
+ // src/payload-cms/utils/is-populated.ts
32
+ function isPopulated(relation) {
33
+ return typeof relation !== "string";
34
+ }
35
+
36
+ // src/payload-cms/utils/as-populated.ts
37
+ function asPopulated(relation) {
38
+ return isPopulated(relation) ? relation : void 0;
39
+ }
40
+
41
+ // src/payload-cms/utils/is-object-id.ts
42
+ var MONGO_ID_REGEX = /^[0-9a-fA-F]{24}$/;
43
+ function isObjectId(value) {
44
+ return typeof value === "string" && MONGO_ID_REGEX.test(value);
45
+ }
46
+
47
+ // src/payload-cms/utils/assert-populated.ts
48
+ function assertPopulated(field, fieldName = "Field") {
49
+ if (field === null || field === void 0) {
50
+ throw new Error(`${fieldName} is undefined or null`);
51
+ }
52
+ if (isObjectId(field)) {
53
+ throw new Error(`${fieldName} is not populated (received ID: ${String(field)})`);
54
+ }
55
+ }
56
+ // Annotate the CommonJS export names for ESM import in node:
57
+ 0 && (module.exports = {
58
+ MONGO_ID_REGEX,
59
+ asPopulated,
60
+ assertPopulated,
61
+ isObjectId,
62
+ isPopulated
63
+ });
@@ -0,0 +1 @@
1
+ export * from './payload-cms';
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ import "./chunk-7GZ4G2P3.js";
2
+ import {
3
+ MONGO_ID_REGEX,
4
+ asPopulated,
5
+ assertPopulated,
6
+ isObjectId,
7
+ isPopulated
8
+ } from "./chunk-O4W463W3.js";
9
+ export {
10
+ MONGO_ID_REGEX,
11
+ asPopulated,
12
+ assertPopulated,
13
+ isObjectId,
14
+ isPopulated
15
+ };
@@ -0,0 +1,63 @@
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/index.ts
21
+ var payload_cms_exports = {};
22
+ __export(payload_cms_exports, {
23
+ MONGO_ID_REGEX: () => MONGO_ID_REGEX,
24
+ asPopulated: () => asPopulated,
25
+ assertPopulated: () => assertPopulated,
26
+ isObjectId: () => isObjectId,
27
+ isPopulated: () => isPopulated
28
+ });
29
+ module.exports = __toCommonJS(payload_cms_exports);
30
+
31
+ // src/payload-cms/utils/is-populated.ts
32
+ function isPopulated(relation) {
33
+ return typeof relation !== "string";
34
+ }
35
+
36
+ // src/payload-cms/utils/as-populated.ts
37
+ function asPopulated(relation) {
38
+ return isPopulated(relation) ? relation : void 0;
39
+ }
40
+
41
+ // src/payload-cms/utils/is-object-id.ts
42
+ var MONGO_ID_REGEX = /^[0-9a-fA-F]{24}$/;
43
+ function isObjectId(value) {
44
+ return typeof value === "string" && MONGO_ID_REGEX.test(value);
45
+ }
46
+
47
+ // src/payload-cms/utils/assert-populated.ts
48
+ function assertPopulated(field, fieldName = "Field") {
49
+ if (field === null || field === void 0) {
50
+ throw new Error(`${fieldName} is undefined or null`);
51
+ }
52
+ if (isObjectId(field)) {
53
+ throw new Error(`${fieldName} is not populated (received ID: ${String(field)})`);
54
+ }
55
+ }
56
+ // Annotate the CommonJS export names for ESM import in node:
57
+ 0 && (module.exports = {
58
+ MONGO_ID_REGEX,
59
+ asPopulated,
60
+ assertPopulated,
61
+ isObjectId,
62
+ isPopulated
63
+ });
@@ -0,0 +1 @@
1
+ export * from './utils';
@@ -0,0 +1,15 @@
1
+ import "../chunk-7GZ4G2P3.js";
2
+ import {
3
+ MONGO_ID_REGEX,
4
+ asPopulated,
5
+ assertPopulated,
6
+ isObjectId,
7
+ isPopulated
8
+ } from "../chunk-O4W463W3.js";
9
+ export {
10
+ MONGO_ID_REGEX,
11
+ asPopulated,
12
+ assertPopulated,
13
+ isObjectId,
14
+ isPopulated
15
+ };
@@ -0,0 +1,13 @@
1
+ import type { CollectionSlug, Where } from 'payload';
2
+ import { db, DeleteOptions, FindAllOptions, UpdateData, UpdateOptions } from './db';
3
+ export type BaseCollectionMethods<TSlug extends CollectionSlug> = {
4
+ findOne: (where?: Where) => ReturnType<typeof db.findOne<TSlug>>;
5
+ findBySlug: (slug: string) => ReturnType<typeof db.findBySlug<TSlug>>;
6
+ findByID: (id: string | number) => ReturnType<typeof db.findByID<TSlug>>;
7
+ findAll: (options?: FindAllOptions) => ReturnType<typeof db.findAll<TSlug>>;
8
+ update: (id: string | number, data: UpdateData, options?: UpdateOptions) => ReturnType<typeof db.update<TSlug>>;
9
+ updateMany: (where: Where, data: UpdateData, options?: UpdateOptions) => ReturnType<typeof db.updateMany<TSlug>>;
10
+ delete: (id: string | number, options?: DeleteOptions) => ReturnType<typeof db.delete<TSlug>>;
11
+ deleteMany: (where: Where, options?: DeleteOptions) => ReturnType<typeof db.deleteMany<TSlug>>;
12
+ };
13
+ export declare function createCollection<TSlug extends CollectionSlug, TExtend extends Record<string, (...args: any[]) => any> = {}>(collection: TSlug, extend?: (base: BaseCollectionMethods<TSlug>) => TExtend): BaseCollectionMethods<TSlug> & TExtend;
@@ -0,0 +1,7 @@
1
+ import type { GlobalSlug } from 'payload';
2
+ import { db } from './db';
3
+ type BaseGlobalMethods<TSlug extends GlobalSlug> = {
4
+ get: () => ReturnType<typeof db.global<TSlug>>;
5
+ };
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
+ export {};
@@ -0,0 +1,19 @@
1
+ import type { CollectionSlug, DataFromCollectionSlug, DataFromGlobalSlug, GlobalSlug, Where } from 'payload';
2
+ import { getPayload } from './get-payload';
3
+ export type FindAllOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['find']>[0], 'collection'>;
4
+ export type UpdateOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['update']>[0], 'collection' | 'id' | 'data' | 'where'>;
5
+ export type DeleteOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['delete']>[0], 'collection' | 'id' | 'where'>;
6
+ 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<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
+ 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
+ update: <TSlug extends CollectionSlug>(collection: TSlug, id: string | number, data: UpdateData, options?: UpdateOptions) => Promise<import("payload").JsonObject & import("payload").TypeWithID>;
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
+ delete: <TSlug extends CollectionSlug>(collection: TSlug, id: string | number, options?: DeleteOptions) => Promise<import("payload").JsonObject & import("payload").TypeWithID>;
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<DataFromGlobalSlug<TSlug>>;
18
+ raw: () => Promise<import("payload").BasePayload>;
19
+ };
@@ -0,0 +1,3 @@
1
+ import { type SanitizedConfig, type Payload } from 'payload';
2
+ export declare function configurePayload(config: Promise<SanitizedConfig> | SanitizedConfig): void;
3
+ export declare const getPayload: (config?: Promise<SanitizedConfig> | SanitizedConfig) => Promise<Payload>;
@@ -0,0 +1,161 @@
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
+ configurePayload: () => configurePayload,
24
+ createCollection: () => createCollection,
25
+ createGlobal: () => createGlobal,
26
+ db: () => db,
27
+ getPayload: () => getPayload
28
+ });
29
+ module.exports = __toCommonJS(server_exports);
30
+
31
+ // src/payload-cms/server/db.ts
32
+ var import_react = require("react");
33
+
34
+ // src/payload-cms/server/get-payload.ts
35
+ var import_payload = require("payload");
36
+ var payloadConfig;
37
+ function configurePayload(config) {
38
+ payloadConfig = config;
39
+ }
40
+ var getPayload = async (config) => {
41
+ const resolvedConfig = config ?? payloadConfig;
42
+ if (!resolvedConfig) {
43
+ throw new Error(
44
+ "[@matvdt/js-toolkit] No Payload config available. Call configurePayload(config) once at app startup, or pass config explicitly to getPayload(config)."
45
+ );
46
+ }
47
+ return (0, import_payload.getPayload)({ config: resolvedConfig });
48
+ };
49
+
50
+ // src/payload-cms/server/db.ts
51
+ var getClient = (0, import_react.cache)(async () => {
52
+ return await getPayload();
53
+ });
54
+ var db = {
55
+ findOne: async (collection, where) => {
56
+ const payload = await getClient();
57
+ const res = await payload.find({ collection, where, limit: 1 });
58
+ return res.docs[0] ?? null;
59
+ },
60
+ findBySlug: async (collection, slug) => {
61
+ return db.findOne(collection, { slug: { equals: slug } });
62
+ },
63
+ findAll: async (collection, options) => {
64
+ const payload = await getClient();
65
+ const res = await payload.find({
66
+ collection,
67
+ limit: options?.limit ?? 100,
68
+ ...options
69
+ });
70
+ return res.docs;
71
+ },
72
+ findByID: async (collection, id) => {
73
+ const payload = await getClient();
74
+ return payload.findByID({ collection, id });
75
+ },
76
+ create: async (collection, data, options) => {
77
+ const payload = await getClient();
78
+ return payload.create({ collection, data, ...options });
79
+ },
80
+ update: async (collection, id, data, options) => {
81
+ const payload = await getClient();
82
+ return payload.update({
83
+ collection,
84
+ id,
85
+ data,
86
+ ...options
87
+ });
88
+ },
89
+ updateMany: async (collection, where, data, options) => {
90
+ const payload = await getClient();
91
+ return payload.update({
92
+ collection,
93
+ where,
94
+ data,
95
+ ...options,
96
+ id: void 0
97
+ });
98
+ },
99
+ delete: async (collection, id, options) => {
100
+ const payload = await getClient();
101
+ return payload.delete({
102
+ collection,
103
+ id,
104
+ where: void 0,
105
+ ...options
106
+ });
107
+ },
108
+ deleteMany: async (collection, where, options) => {
109
+ const payload = await getClient();
110
+ return payload.delete({
111
+ collection,
112
+ where,
113
+ id: void 0,
114
+ ...options
115
+ });
116
+ },
117
+ global: async (slug) => {
118
+ const payload = await getClient();
119
+ return payload.findGlobal({ slug });
120
+ },
121
+ raw: getClient
122
+ };
123
+
124
+ // src/payload-cms/server/create-collection.ts
125
+ function createCollection(collection, extend) {
126
+ const base = {
127
+ findOne: (where) => db.findOne(collection, where),
128
+ findByID: (id) => db.findByID(collection, id),
129
+ findBySlug: (slug) => db.findBySlug(collection, slug),
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)
135
+ };
136
+ const extended = extend ? extend(base) : void 0;
137
+ return {
138
+ ...base,
139
+ ...extended
140
+ };
141
+ }
142
+
143
+ // src/payload-cms/server/create-global.ts
144
+ function createGlobal(slug, extend) {
145
+ const base = {
146
+ get: () => db.global(slug)
147
+ };
148
+ const extended = extend ? extend(base) : void 0;
149
+ return {
150
+ ...base,
151
+ ...extended
152
+ };
153
+ }
154
+ // Annotate the CommonJS export names for ESM import in node:
155
+ 0 && (module.exports = {
156
+ configurePayload,
157
+ createCollection,
158
+ createGlobal,
159
+ db,
160
+ getPayload
161
+ });
@@ -0,0 +1,4 @@
1
+ export * from './create-collection';
2
+ export * from './create-global';
3
+ export * from './db';
4
+ export * from './get-payload';
@@ -0,0 +1,130 @@
1
+ // src/payload-cms/server/db.ts
2
+ import { cache } from "react";
3
+
4
+ // src/payload-cms/server/get-payload.ts
5
+ import { getPayload as getPayloadSDK } from "payload";
6
+ var payloadConfig;
7
+ function configurePayload(config) {
8
+ payloadConfig = config;
9
+ }
10
+ var getPayload = async (config) => {
11
+ const resolvedConfig = config ?? payloadConfig;
12
+ if (!resolvedConfig) {
13
+ throw new Error(
14
+ "[@matvdt/js-toolkit] No Payload config available. Call configurePayload(config) once at app startup, or pass config explicitly to getPayload(config)."
15
+ );
16
+ }
17
+ return getPayloadSDK({ config: resolvedConfig });
18
+ };
19
+
20
+ // src/payload-cms/server/db.ts
21
+ var getClient = cache(async () => {
22
+ return await getPayload();
23
+ });
24
+ var db = {
25
+ findOne: async (collection, where) => {
26
+ const payload = await getClient();
27
+ const res = await payload.find({ collection, where, limit: 1 });
28
+ return res.docs[0] ?? null;
29
+ },
30
+ findBySlug: async (collection, slug) => {
31
+ return db.findOne(collection, { slug: { equals: slug } });
32
+ },
33
+ findAll: async (collection, options) => {
34
+ const payload = await getClient();
35
+ const res = await payload.find({
36
+ collection,
37
+ limit: options?.limit ?? 100,
38
+ ...options
39
+ });
40
+ return res.docs;
41
+ },
42
+ findByID: async (collection, id) => {
43
+ const payload = await getClient();
44
+ return payload.findByID({ collection, id });
45
+ },
46
+ create: async (collection, data, options) => {
47
+ const payload = await getClient();
48
+ return payload.create({ collection, data, ...options });
49
+ },
50
+ update: async (collection, id, data, options) => {
51
+ const payload = await getClient();
52
+ return payload.update({
53
+ collection,
54
+ id,
55
+ data,
56
+ ...options
57
+ });
58
+ },
59
+ updateMany: async (collection, where, data, options) => {
60
+ const payload = await getClient();
61
+ return payload.update({
62
+ collection,
63
+ where,
64
+ data,
65
+ ...options,
66
+ id: void 0
67
+ });
68
+ },
69
+ delete: async (collection, id, options) => {
70
+ const payload = await getClient();
71
+ return payload.delete({
72
+ collection,
73
+ id,
74
+ where: void 0,
75
+ ...options
76
+ });
77
+ },
78
+ deleteMany: async (collection, where, options) => {
79
+ const payload = await getClient();
80
+ return payload.delete({
81
+ collection,
82
+ where,
83
+ id: void 0,
84
+ ...options
85
+ });
86
+ },
87
+ global: async (slug) => {
88
+ const payload = await getClient();
89
+ return payload.findGlobal({ slug });
90
+ },
91
+ raw: getClient
92
+ };
93
+
94
+ // src/payload-cms/server/create-collection.ts
95
+ function createCollection(collection, extend) {
96
+ const base = {
97
+ findOne: (where) => db.findOne(collection, where),
98
+ findByID: (id) => db.findByID(collection, id),
99
+ findBySlug: (slug) => db.findBySlug(collection, slug),
100
+ findAll: (options) => db.findAll(collection, options),
101
+ update: (id, data, options) => db.update(collection, id, data, options),
102
+ updateMany: (where, data, options) => db.updateMany(collection, where, data, options),
103
+ delete: (id, options) => db.delete(collection, id, options),
104
+ deleteMany: (where, options) => db.deleteMany(collection, where, options)
105
+ };
106
+ const extended = extend ? extend(base) : void 0;
107
+ return {
108
+ ...base,
109
+ ...extended
110
+ };
111
+ }
112
+
113
+ // src/payload-cms/server/create-global.ts
114
+ function createGlobal(slug, extend) {
115
+ const base = {
116
+ get: () => db.global(slug)
117
+ };
118
+ const extended = extend ? extend(base) : void 0;
119
+ return {
120
+ ...base,
121
+ ...extended
122
+ };
123
+ }
124
+ export {
125
+ configurePayload,
126
+ createCollection,
127
+ createGlobal,
128
+ db,
129
+ getPayload
130
+ };
@@ -0,0 +1 @@
1
+ export declare function asPopulated<T>(relation: string | T): T | undefined;
@@ -0,0 +1 @@
1
+ export declare function assertPopulated<T extends object>(field: string | T | null | undefined, fieldName?: string): asserts field is NonNullable<T>;
@@ -0,0 +1,63 @@
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/utils/index.ts
21
+ var utils_exports = {};
22
+ __export(utils_exports, {
23
+ MONGO_ID_REGEX: () => MONGO_ID_REGEX,
24
+ asPopulated: () => asPopulated,
25
+ assertPopulated: () => assertPopulated,
26
+ isObjectId: () => isObjectId,
27
+ isPopulated: () => isPopulated
28
+ });
29
+ module.exports = __toCommonJS(utils_exports);
30
+
31
+ // src/payload-cms/utils/is-populated.ts
32
+ function isPopulated(relation) {
33
+ return typeof relation !== "string";
34
+ }
35
+
36
+ // src/payload-cms/utils/as-populated.ts
37
+ function asPopulated(relation) {
38
+ return isPopulated(relation) ? relation : void 0;
39
+ }
40
+
41
+ // src/payload-cms/utils/is-object-id.ts
42
+ var MONGO_ID_REGEX = /^[0-9a-fA-F]{24}$/;
43
+ function isObjectId(value) {
44
+ return typeof value === "string" && MONGO_ID_REGEX.test(value);
45
+ }
46
+
47
+ // src/payload-cms/utils/assert-populated.ts
48
+ function assertPopulated(field, fieldName = "Field") {
49
+ if (field === null || field === void 0) {
50
+ throw new Error(`${fieldName} is undefined or null`);
51
+ }
52
+ if (isObjectId(field)) {
53
+ throw new Error(`${fieldName} is not populated (received ID: ${String(field)})`);
54
+ }
55
+ }
56
+ // Annotate the CommonJS export names for ESM import in node:
57
+ 0 && (module.exports = {
58
+ MONGO_ID_REGEX,
59
+ asPopulated,
60
+ assertPopulated,
61
+ isObjectId,
62
+ isPopulated
63
+ });
@@ -0,0 +1,4 @@
1
+ export * from './as-populated';
2
+ export * from './assert-populated';
3
+ export * from './is-object-id';
4
+ export * from './is-populated';
@@ -0,0 +1,14 @@
1
+ import {
2
+ MONGO_ID_REGEX,
3
+ asPopulated,
4
+ assertPopulated,
5
+ isObjectId,
6
+ isPopulated
7
+ } from "../../chunk-O4W463W3.js";
8
+ export {
9
+ MONGO_ID_REGEX,
10
+ asPopulated,
11
+ assertPopulated,
12
+ isObjectId,
13
+ isPopulated
14
+ };
@@ -0,0 +1,2 @@
1
+ export declare const MONGO_ID_REGEX: RegExp;
2
+ export declare function isObjectId(value: unknown): value is string;
@@ -0,0 +1 @@
1
+ export declare function isPopulated<T>(relation: string | T): relation is T;
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@matvdt/js-toolkit",
3
+ "version": "0.0.1-canary.10",
4
+ "description": "JS/TS toolkit",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ },
14
+ "./payload-cms": {
15
+ "types": "./dist/payload-cms/index.d.ts",
16
+ "import": "./dist/payload-cms/index.js",
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"
23
+ }
24
+ },
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "scripts": {
29
+ "build": "tsup && tsc",
30
+ "publish:canary": "npm publish --access public --tag canary",
31
+ "publish:alpha" : "npm publish --access public --tag alpha",
32
+ "publish:beta" : "npm publish --access public --tag beta",
33
+ "publish:rc" : "npm publish --access public --tag rc",
34
+ "publish:latest": "npm publish --access public",
35
+ "prepublishOnly": "npm run build"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "keywords": [
41
+ "toolkit",
42
+ "javascript"
43
+ ],
44
+ "author": "Matteo Vidotto",
45
+ "license": "MIT",
46
+ "devDependencies": {
47
+ "@types/node": "^26.1.2",
48
+ "@types/react": "^19.2.17",
49
+ "payload": "^3.86.0",
50
+ "react": "^19.2.8",
51
+ "tsup": "^8.5.1",
52
+ "typescript": "^7.0.2"
53
+ },
54
+ "peerDependencies": {
55
+ "payload": ">=3.0.0",
56
+ "react": ">=18.0.0"
57
+ },
58
+ "peerDependenciesMeta": {
59
+ "payload": {
60
+ "optional": true
61
+ },
62
+ "react": {
63
+ "optional": true
64
+ }
65
+ }
66
+ }