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

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,7 +1,6 @@
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';
3
+ export * from './has-id';
6
4
  export * from './is-object-id';
7
5
  export * from './is-populated';
6
+ export * from './unwrap-populated';
@@ -2,20 +2,17 @@ import {
2
2
  MONGO_ID_REGEX,
3
3
  asPopulated,
4
4
  assertPopulated,
5
- createCollection,
6
- createGlobal,
7
- db,
5
+ hasId,
8
6
  isObjectId,
9
- isPopulated
10
- } from "../../chunk-EZIPIKRW.js";
11
- import "../../chunk-CWTTD7TW.js";
7
+ isPopulated,
8
+ unwrapPopulated
9
+ } from "../../chunk-UYAULMAI.js";
12
10
  export {
13
11
  MONGO_ID_REGEX,
14
12
  asPopulated,
15
13
  assertPopulated,
16
- createCollection,
17
- createGlobal,
18
- db,
14
+ hasId,
19
15
  isObjectId,
20
- isPopulated
16
+ isPopulated,
17
+ unwrapPopulated
21
18
  };
@@ -0,0 +1 @@
1
+ export declare function unwrapPopulated<T>(value: string | T | null | undefined, message?: string): T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matvdt/js-toolkit",
3
- "version": "0.0.1-canary.2",
3
+ "version": "0.0.1-canary.21",
4
4
  "description": "JS/TS toolkit",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -12,9 +12,14 @@
12
12
  "require": "./dist/index.cjs"
13
13
  },
14
14
  "./payload-cms": {
15
- "types": "./dist/index.d.ts",
16
- "import": "./dist/index.js",
17
- "require": "./dist/index.cjs"
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"
18
23
  }
19
24
  },
20
25
  "files": [
@@ -22,11 +27,23 @@
22
27
  ],
23
28
  "scripts": {
24
29
  "build": "tsup && tsc",
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",
34
+ "version:latest": "npm version patch",
35
+
25
36
  "publish:canary": "npm publish --access public --tag canary",
26
- "publish:alpha" : "npm publish --access public --tag alpha",
27
- "publish:beta" : "npm publish --access public --tag beta",
28
- "publish:rc" : "npm publish --access public --tag rc",
37
+
38
+ "publish:alpha": "npm publish --access public --tag alpha",
39
+ "publish:beta": "npm publish --access public --tag beta",
40
+ "publish:rc": "npm publish --access public --tag rc",
29
41
  "publish:latest": "npm publish --access public",
42
+ "release:canary": "npm run version:canary && npm run publish:canary",
43
+ "release:alpha": "npm run version:alpha && npm run publish:alpha",
44
+ "release:beta": "npm run version:beta && npm run publish:beta",
45
+ "release:rc": "npm run version:rc && npm run publish:rc",
46
+ "release:latest": "npm run version:latest && npm run publish:latest",
30
47
  "prepublishOnly": "npm run build"
31
48
  },
32
49
  "publishConfig": {
@@ -39,21 +56,28 @@
39
56
  "author": "Matteo Vidotto",
40
57
  "license": "MIT",
41
58
  "devDependencies": {
59
+ "@payloadcms/db-mongodb": "^3.88.0",
42
60
  "@types/node": "^26.1.2",
43
61
  "@types/react": "^19.2.17",
44
- "payload": "^3.86.0",
62
+ "payload": "^3.88.0",
45
63
  "react": "^19.2.8",
46
64
  "tsup": "^8.5.1",
47
- "typescript": "^7.0.2"
65
+ "typescript": "^7.0.2",
66
+ "next": "^16.0.0"
48
67
  },
49
68
  "peerDependencies": {
69
+ "@payloadcms/db-mongodb": ">=3.0.0",
50
70
  "payload": ">=3.0.0",
51
- "react": ">=18.0.0"
71
+ "react": ">=18.0.0",
72
+ "next": ">=15.0.0"
52
73
  },
53
74
  "peerDependenciesMeta": {
54
75
  "payload": {
55
76
  "optional": true
56
77
  },
78
+ "@payloadcms/db-mongodb": {
79
+ "optional": true
80
+ },
57
81
  "react": {
58
82
  "optional": true
59
83
  }
@@ -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
- };
@@ -1,146 +0,0 @@
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
- }
20
-
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`);
25
- }
26
- if (isObjectId(field)) {
27
- throw new Error(`${fieldName} is not populated (received ID: ${String(field)})`);
28
- }
29
- }
30
-
31
- // src/payload-cms/utils/db.ts
32
- import { cache } from "react";
33
- var getClient = cache(async () => {
34
- return await getPayload();
35
- });
36
- var db = {
37
- findOne: async (collection, where) => {
38
- const payload = await getClient();
39
- const res = await payload.find({ collection, where, limit: 1 });
40
- return res.docs[0] ?? null;
41
- },
42
- findBySlug: async (collection, slug) => {
43
- return db.findOne(collection, { slug: { equals: slug } });
44
- },
45
- findAll: async (collection, options) => {
46
- const payload = await getClient();
47
- const res = await payload.find({
48
- collection,
49
- limit: options?.limit ?? 100,
50
- ...options
51
- });
52
- return res.docs;
53
- },
54
- findByID: async (collection, id) => {
55
- const payload = await getClient();
56
- return payload.findByID({ collection, id });
57
- },
58
- create: async (collection, data, options) => {
59
- const payload = await getClient();
60
- return payload.create({ collection, data, ...options });
61
- },
62
- update: async (collection, id, data, options) => {
63
- const payload = await getClient();
64
- return payload.update({
65
- collection,
66
- id,
67
- data,
68
- ...options
69
- });
70
- },
71
- updateMany: async (collection, where, data, options) => {
72
- const payload = await getClient();
73
- return payload.update({
74
- collection,
75
- where,
76
- data,
77
- ...options,
78
- id: void 0
79
- });
80
- },
81
- delete: async (collection, id, options) => {
82
- const payload = await getClient();
83
- return payload.delete({
84
- collection,
85
- id,
86
- where: void 0,
87
- ...options
88
- });
89
- },
90
- deleteMany: async (collection, where, options) => {
91
- const payload = await getClient();
92
- return payload.delete({
93
- collection,
94
- where,
95
- id: void 0,
96
- ...options
97
- });
98
- },
99
- global: async (slug) => {
100
- const payload = await getClient();
101
- return payload.findGlobal({ slug });
102
- },
103
- raw: getClient
104
- };
105
-
106
- // src/payload-cms/utils/create-collection.ts
107
- function createCollection(collection, extend) {
108
- const base = {
109
- findOne: (where) => db.findOne(collection, where),
110
- findByID: (id) => db.findByID(collection, id),
111
- findBySlug: (slug) => db.findBySlug(collection, slug),
112
- findAll: (options) => db.findAll(collection, options),
113
- update: (id, data, options) => db.update(collection, id, data, options),
114
- updateMany: (where, data, options) => db.updateMany(collection, where, data, options),
115
- delete: (id, options) => db.delete(collection, id, options),
116
- deleteMany: (where, options) => db.deleteMany(collection, where, options)
117
- };
118
- const extended = extend ? extend(base) : void 0;
119
- return {
120
- ...base,
121
- ...extended
122
- };
123
- }
124
-
125
- // src/payload-cms/utils/create-global.ts
126
- function createGlobal(slug, extend) {
127
- const base = {
128
- get: () => db.global(slug)
129
- };
130
- const extended = extend ? extend(base) : void 0;
131
- return {
132
- ...base,
133
- ...extended
134
- };
135
- }
136
-
137
- export {
138
- isPopulated,
139
- asPopulated,
140
- MONGO_ID_REGEX,
141
- isObjectId,
142
- assertPopulated,
143
- db,
144
- createCollection,
145
- createGlobal
146
- };
File without changes
@@ -1,2 +0,0 @@
1
- import { SanitizedConfig, type Payload } from 'payload';
2
- export declare const getPayload: (config?: Promise<SanitizedConfig> | SanitizedConfig) => Promise<Payload>;
@@ -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
- };
@@ -1,13 +0,0 @@
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;
File without changes