@matvdt/js-toolkit 0.0.1-canary.16 → 0.0.1-canary.18

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.
@@ -24,10 +24,16 @@ function assertPopulated(field, fieldName = "Field") {
24
24
  }
25
25
  }
26
26
 
27
+ // src/payload-cms/utils/has-id.ts
28
+ function hasId(item) {
29
+ return item.id !== null && item.id !== void 0;
30
+ }
31
+
27
32
  export {
28
33
  isPopulated,
29
34
  asPopulated,
30
35
  MONGO_ID_REGEX,
31
36
  isObjectId,
32
- assertPopulated
37
+ assertPopulated,
38
+ hasId
33
39
  };
package/dist/index.cjs CHANGED
@@ -23,6 +23,7 @@ __export(index_exports, {
23
23
  MONGO_ID_REGEX: () => MONGO_ID_REGEX,
24
24
  asPopulated: () => asPopulated,
25
25
  assertPopulated: () => assertPopulated,
26
+ hasId: () => hasId,
26
27
  isObjectId: () => isObjectId,
27
28
  isPopulated: () => isPopulated
28
29
  });
@@ -53,11 +54,17 @@ function assertPopulated(field, fieldName = "Field") {
53
54
  throw new Error(`${fieldName} is not populated (received ID: ${String(field)})`);
54
55
  }
55
56
  }
57
+
58
+ // src/payload-cms/utils/has-id.ts
59
+ function hasId(item) {
60
+ return item.id !== null && item.id !== void 0;
61
+ }
56
62
  // Annotate the CommonJS export names for ESM import in node:
57
63
  0 && (module.exports = {
58
64
  MONGO_ID_REGEX,
59
65
  asPopulated,
60
66
  assertPopulated,
67
+ hasId,
61
68
  isObjectId,
62
69
  isPopulated
63
70
  });
package/dist/index.js CHANGED
@@ -3,13 +3,15 @@ import {
3
3
  MONGO_ID_REGEX,
4
4
  asPopulated,
5
5
  assertPopulated,
6
+ hasId,
6
7
  isObjectId,
7
8
  isPopulated
8
- } from "./chunk-O4W463W3.js";
9
+ } from "./chunk-OP6OJMXX.js";
9
10
  export {
10
11
  MONGO_ID_REGEX,
11
12
  asPopulated,
12
13
  assertPopulated,
14
+ hasId,
13
15
  isObjectId,
14
16
  isPopulated
15
17
  };
@@ -23,6 +23,7 @@ __export(payload_cms_exports, {
23
23
  MONGO_ID_REGEX: () => MONGO_ID_REGEX,
24
24
  asPopulated: () => asPopulated,
25
25
  assertPopulated: () => assertPopulated,
26
+ hasId: () => hasId,
26
27
  isObjectId: () => isObjectId,
27
28
  isPopulated: () => isPopulated
28
29
  });
@@ -53,11 +54,17 @@ function assertPopulated(field, fieldName = "Field") {
53
54
  throw new Error(`${fieldName} is not populated (received ID: ${String(field)})`);
54
55
  }
55
56
  }
57
+
58
+ // src/payload-cms/utils/has-id.ts
59
+ function hasId(item) {
60
+ return item.id !== null && item.id !== void 0;
61
+ }
56
62
  // Annotate the CommonJS export names for ESM import in node:
57
63
  0 && (module.exports = {
58
64
  MONGO_ID_REGEX,
59
65
  asPopulated,
60
66
  assertPopulated,
67
+ hasId,
61
68
  isObjectId,
62
69
  isPopulated
63
70
  });
@@ -3,13 +3,15 @@ import {
3
3
  MONGO_ID_REGEX,
4
4
  asPopulated,
5
5
  assertPopulated,
6
+ hasId,
6
7
  isObjectId,
7
8
  isPopulated
8
- } from "../chunk-O4W463W3.js";
9
+ } from "../chunk-OP6OJMXX.js";
9
10
  export {
10
11
  MONGO_ID_REGEX,
11
12
  asPopulated,
12
13
  assertPopulated,
14
+ hasId,
13
15
  isObjectId,
14
16
  isPopulated
15
17
  };
@@ -147,6 +147,10 @@ var payload = {
147
147
  const payload2 = await getClient();
148
148
  return payload2.findGlobal({ slug });
149
149
  },
150
+ aggregate: async (collection, pipeline, options) => {
151
+ const payload2 = await getClient();
152
+ return payload2.db.collections[collection].aggregate(pipeline, options);
153
+ },
150
154
  raw: getClient
151
155
  };
152
156
 
@@ -117,6 +117,10 @@ var payload = {
117
117
  const payload2 = await getClient();
118
118
  return payload2.findGlobal({ slug });
119
119
  },
120
+ aggregate: async (collection, pipeline, options) => {
121
+ const payload2 = await getClient();
122
+ return payload2.db.collections[collection].aggregate(pipeline, options);
123
+ },
120
124
  raw: getClient
121
125
  };
122
126
 
@@ -1,5 +1,6 @@
1
1
  import type { CollectionSlug, DataFromCollectionSlug, DataFromGlobalSlug, GlobalSlug, PaginatedDocs, Where } from 'payload';
2
2
  import { getPayload } from './get-payload';
3
+ import { PipelineStage, Aggregate, AggregateOptions } from "mongoose";
3
4
  export type FindOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['find']>[0], 'collection'>;
4
5
  export type FindByIDOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['findByID']>[0], 'collection' | 'id'>;
5
6
  export type UpdateOptions = Omit<Parameters<Awaited<ReturnType<typeof getPayload>>['update']>[0], 'collection' | 'id' | 'data' | 'where'>;
@@ -17,5 +18,6 @@ export declare const payload: {
17
18
  delete: <TSlug extends CollectionSlug>(collection: TSlug, id: string | number, options?: DeleteOptions) => Promise<import("payload").JsonObject & import("payload").TypeWithID>;
18
19
  deleteMany: <TSlug extends CollectionSlug>(collection: TSlug, where: Where, options?: DeleteOptions) => Promise<import("payload").BulkOperationResult<TSlug, import("payload").SelectExcludeType | import("payload").SelectIncludeType>>;
19
20
  global: <TSlug extends GlobalSlug>(slug: TSlug) => Promise<DataFromGlobalSlug<TSlug>>;
21
+ aggregate: <TSlug extends CollectionSlug, TData = any>(collection: TSlug, pipeline?: PipelineStage[], options?: AggregateOptions) => Promise<Aggregate<TData[]>>;
20
22
  raw: () => Promise<import("payload").BasePayload>;
21
23
  };
@@ -0,0 +1,5 @@
1
+ export declare function hasId<T>(item: T & {
2
+ id?: string | null;
3
+ }): item is T & {
4
+ id: string;
5
+ };
@@ -23,6 +23,7 @@ __export(utils_exports, {
23
23
  MONGO_ID_REGEX: () => MONGO_ID_REGEX,
24
24
  asPopulated: () => asPopulated,
25
25
  assertPopulated: () => assertPopulated,
26
+ hasId: () => hasId,
26
27
  isObjectId: () => isObjectId,
27
28
  isPopulated: () => isPopulated
28
29
  });
@@ -53,11 +54,17 @@ function assertPopulated(field, fieldName = "Field") {
53
54
  throw new Error(`${fieldName} is not populated (received ID: ${String(field)})`);
54
55
  }
55
56
  }
57
+
58
+ // src/payload-cms/utils/has-id.ts
59
+ function hasId(item) {
60
+ return item.id !== null && item.id !== void 0;
61
+ }
56
62
  // Annotate the CommonJS export names for ESM import in node:
57
63
  0 && (module.exports = {
58
64
  MONGO_ID_REGEX,
59
65
  asPopulated,
60
66
  assertPopulated,
67
+ hasId,
61
68
  isObjectId,
62
69
  isPopulated
63
70
  });
@@ -1,4 +1,5 @@
1
1
  export * from './as-populated';
2
2
  export * from './assert-populated';
3
+ export * from './has-id';
3
4
  export * from './is-object-id';
4
5
  export * from './is-populated';
@@ -2,13 +2,15 @@ import {
2
2
  MONGO_ID_REGEX,
3
3
  asPopulated,
4
4
  assertPopulated,
5
+ hasId,
5
6
  isObjectId,
6
7
  isPopulated
7
- } from "../../chunk-O4W463W3.js";
8
+ } from "../../chunk-OP6OJMXX.js";
8
9
  export {
9
10
  MONGO_ID_REGEX,
10
11
  asPopulated,
11
12
  assertPopulated,
13
+ hasId,
12
14
  isObjectId,
13
15
  isPopulated
14
16
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matvdt/js-toolkit",
3
- "version": "0.0.1-canary.16",
3
+ "version": "0.0.1-canary.18",
4
4
  "description": "JS/TS toolkit",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -28,19 +28,19 @@
28
28
  "scripts": {
29
29
  "build": "tsup && tsc",
30
30
  "version:canary": "npm version prerelease --preid=canary",
31
- "version:alpha" : "npm version prerelease --preid=alpha",
32
- "version:beta" : "npm version prerelease --preid=beta",
33
- "version:rc" : "npm version prerelease --preid=rc",
31
+ "version:alpha": "npm version prerelease --preid=alpha",
32
+ "version:beta": "npm version prerelease --preid=beta",
33
+ "version:rc": "npm version prerelease --preid=rc",
34
34
  "version:latest": "npm version patch",
35
35
  "publish:canary": "npm publish --access public --tag canary",
36
- "publish:alpha" : "npm publish --access public --tag alpha",
37
- "publish:beta" : "npm publish --access public --tag beta",
38
- "publish:rc" : "npm publish --access public --tag rc",
36
+ "publish:alpha": "npm publish --access public --tag alpha",
37
+ "publish:beta": "npm publish --access public --tag beta",
38
+ "publish:rc": "npm publish --access public --tag rc",
39
39
  "publish:latest": "npm publish --access public",
40
40
  "release:canary": "npm run version:canary && npm run publish:canary",
41
- "release:alpha" : "npm run version:alpha && npm run publish:alpha",
42
- "release:beta" : "npm run version:beta && npm run publish:beta",
43
- "release:rc" : "npm run version:rc && npm run publish:rc",
41
+ "release:alpha": "npm run version:alpha && npm run publish:alpha",
42
+ "release:beta": "npm run version:beta && npm run publish:beta",
43
+ "release:rc": "npm run version:rc && npm run publish:rc",
44
44
  "release:latest": "npm run version:latest && npm run publish:latest",
45
45
  "prepublishOnly": "npm run build"
46
46
  },
@@ -54,14 +54,16 @@
54
54
  "author": "Matteo Vidotto",
55
55
  "license": "MIT",
56
56
  "devDependencies": {
57
+ "@payloadcms/db-mongodb": "^3.88.0",
57
58
  "@types/node": "^26.1.2",
58
59
  "@types/react": "^19.2.17",
59
- "payload": "^3.86.0",
60
+ "payload": "^3.88.0",
60
61
  "react": "^19.2.8",
61
62
  "tsup": "^8.5.1",
62
63
  "typescript": "^7.0.2"
63
64
  },
64
65
  "peerDependencies": {
66
+ "@payloadcms/db-mongodb": ">=3.0.0",
65
67
  "payload": ">=3.0.0",
66
68
  "react": ">=18.0.0"
67
69
  },
@@ -69,6 +71,9 @@
69
71
  "payload": {
70
72
  "optional": true
71
73
  },
74
+ "@payloadcms/db-mongodb": {
75
+ "optional": true
76
+ },
72
77
  "react": {
73
78
  "optional": true
74
79
  }