@matvdt/js-toolkit 0.0.1-canary.19 → 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.
@@ -29,11 +29,23 @@ function hasId(item) {
29
29
  return item.id !== null && item.id !== void 0;
30
30
  }
31
31
 
32
+ // src/payload-cms/utils/unwrap-populated.ts
33
+ function unwrapPopulated(value, message = "Value is missing or not populated") {
34
+ if (value === null || value === void 0) {
35
+ throw new Error(message);
36
+ }
37
+ if (typeof value === "string" && isObjectId(value)) {
38
+ throw new Error(message);
39
+ }
40
+ return value;
41
+ }
42
+
32
43
  export {
33
44
  isPopulated,
34
45
  asPopulated,
35
46
  MONGO_ID_REGEX,
36
47
  isObjectId,
37
48
  assertPopulated,
38
- hasId
49
+ hasId,
50
+ unwrapPopulated
39
51
  };
package/dist/index.cjs CHANGED
@@ -25,7 +25,8 @@ __export(index_exports, {
25
25
  assertPopulated: () => assertPopulated,
26
26
  hasId: () => hasId,
27
27
  isObjectId: () => isObjectId,
28
- isPopulated: () => isPopulated
28
+ isPopulated: () => isPopulated,
29
+ unwrapPopulated: () => unwrapPopulated
29
30
  });
30
31
  module.exports = __toCommonJS(index_exports);
31
32
 
@@ -59,6 +60,17 @@ function assertPopulated(field, fieldName = "Field") {
59
60
  function hasId(item) {
60
61
  return item.id !== null && item.id !== void 0;
61
62
  }
63
+
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;
73
+ }
62
74
  // Annotate the CommonJS export names for ESM import in node:
63
75
  0 && (module.exports = {
64
76
  MONGO_ID_REGEX,
@@ -66,5 +78,6 @@ function hasId(item) {
66
78
  assertPopulated,
67
79
  hasId,
68
80
  isObjectId,
69
- isPopulated
81
+ isPopulated,
82
+ unwrapPopulated
70
83
  });
package/dist/index.js CHANGED
@@ -5,13 +5,15 @@ import {
5
5
  assertPopulated,
6
6
  hasId,
7
7
  isObjectId,
8
- isPopulated
9
- } from "./chunk-OP6OJMXX.js";
8
+ isPopulated,
9
+ unwrapPopulated
10
+ } from "./chunk-UYAULMAI.js";
10
11
  export {
11
12
  MONGO_ID_REGEX,
12
13
  asPopulated,
13
14
  assertPopulated,
14
15
  hasId,
15
16
  isObjectId,
16
- isPopulated
17
+ isPopulated,
18
+ unwrapPopulated
17
19
  };
@@ -25,7 +25,8 @@ __export(payload_cms_exports, {
25
25
  assertPopulated: () => assertPopulated,
26
26
  hasId: () => hasId,
27
27
  isObjectId: () => isObjectId,
28
- isPopulated: () => isPopulated
28
+ isPopulated: () => isPopulated,
29
+ unwrapPopulated: () => unwrapPopulated
29
30
  });
30
31
  module.exports = __toCommonJS(payload_cms_exports);
31
32
 
@@ -59,6 +60,17 @@ function assertPopulated(field, fieldName = "Field") {
59
60
  function hasId(item) {
60
61
  return item.id !== null && item.id !== void 0;
61
62
  }
63
+
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;
73
+ }
62
74
  // Annotate the CommonJS export names for ESM import in node:
63
75
  0 && (module.exports = {
64
76
  MONGO_ID_REGEX,
@@ -66,5 +78,6 @@ function hasId(item) {
66
78
  assertPopulated,
67
79
  hasId,
68
80
  isObjectId,
69
- isPopulated
81
+ isPopulated,
82
+ unwrapPopulated
70
83
  });
@@ -5,13 +5,15 @@ import {
5
5
  assertPopulated,
6
6
  hasId,
7
7
  isObjectId,
8
- isPopulated
9
- } from "../chunk-OP6OJMXX.js";
8
+ isPopulated,
9
+ unwrapPopulated
10
+ } from "../chunk-UYAULMAI.js";
10
11
  export {
11
12
  MONGO_ID_REGEX,
12
13
  asPopulated,
13
14
  assertPopulated,
14
15
  hasId,
15
16
  isObjectId,
16
- isPopulated
17
+ isPopulated,
18
+ unwrapPopulated
17
19
  };
@@ -25,7 +25,8 @@ __export(utils_exports, {
25
25
  assertPopulated: () => assertPopulated,
26
26
  hasId: () => hasId,
27
27
  isObjectId: () => isObjectId,
28
- isPopulated: () => isPopulated
28
+ isPopulated: () => isPopulated,
29
+ unwrapPopulated: () => unwrapPopulated
29
30
  });
30
31
  module.exports = __toCommonJS(utils_exports);
31
32
 
@@ -59,6 +60,17 @@ function assertPopulated(field, fieldName = "Field") {
59
60
  function hasId(item) {
60
61
  return item.id !== null && item.id !== void 0;
61
62
  }
63
+
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;
73
+ }
62
74
  // Annotate the CommonJS export names for ESM import in node:
63
75
  0 && (module.exports = {
64
76
  MONGO_ID_REGEX,
@@ -66,5 +78,6 @@ function hasId(item) {
66
78
  assertPopulated,
67
79
  hasId,
68
80
  isObjectId,
69
- isPopulated
81
+ isPopulated,
82
+ unwrapPopulated
70
83
  });
@@ -3,3 +3,4 @@ export * from './assert-populated';
3
3
  export * from './has-id';
4
4
  export * from './is-object-id';
5
5
  export * from './is-populated';
6
+ export * from './unwrap-populated';
@@ -4,13 +4,15 @@ import {
4
4
  assertPopulated,
5
5
  hasId,
6
6
  isObjectId,
7
- isPopulated
8
- } from "../../chunk-OP6OJMXX.js";
7
+ isPopulated,
8
+ unwrapPopulated
9
+ } from "../../chunk-UYAULMAI.js";
9
10
  export {
10
11
  MONGO_ID_REGEX,
11
12
  asPopulated,
12
13
  assertPopulated,
13
14
  hasId,
14
15
  isObjectId,
15
- isPopulated
16
+ isPopulated,
17
+ unwrapPopulated
16
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.19",
3
+ "version": "0.0.1-canary.20",
4
4
  "description": "JS/TS toolkit",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",