@duplojs/data-parser-tools 0.2.1 → 0.2.2

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.
@@ -6,28 +6,42 @@ function getRecursiveDataParser(schema) {
6
6
  const countMap = new Map();
7
7
  void (function countDataParser(schema) {
8
8
  utils.P.match(schema)
9
- .when((value) => (utils.DP.stringKind.has(value)
10
- || utils.DP.stringKind.has(value)
11
- || utils.DP.numberKind.has(value)
12
- || utils.DP.nilKind.has(value)
13
- || utils.DP.dateKind.has(value)
14
- || utils.DP.emptyKind.has(value)
15
- || utils.DP.bigIntKind.has(value)
16
- || utils.DP.booleanKind.has(value)
17
- || utils.DP.literalKind.has(value)
18
- || utils.DP.unknownKind.has(value)
19
- || utils.DP.templateLiteralKind.has(value)
20
- || utils.DP.recordKind.has(value)), () => void 0)
21
- .when((value) => (utils.DP.nullableKind.has(value)
22
- || utils.DP.optionalKind.has(value)
23
- || utils.DP.recoverKind.has(value)
24
- || utils.DP.transformKind.has(value)), (dataParser) => void countDataParser(dataParser.definition.inner))
9
+ .when(utils.hasSomeKinds([
10
+ utils.DP.stringKind,
11
+ utils.DP.stringKind,
12
+ utils.DP.numberKind,
13
+ utils.DP.nilKind,
14
+ utils.DP.dateKind,
15
+ utils.DP.emptyKind,
16
+ utils.DP.bigIntKind,
17
+ utils.DP.booleanKind,
18
+ utils.DP.literalKind,
19
+ utils.DP.unknownKind,
20
+ utils.DP.templateLiteralKind,
21
+ utils.DP.recordKind,
22
+ ]), () => void 0)
23
+ .when(utils.hasSomeKinds([
24
+ utils.DP.nullableKind,
25
+ utils.DP.optionalKind,
26
+ utils.DP.recoverKind,
27
+ utils.DP.transformKind,
28
+ ]), (dataParser) => void countDataParser(dataParser.definition.inner))
25
29
  .when(utils.DP.lazyKind.has, (dataParser) => void countDataParser(dataParser.definition.getter.value))
26
30
  .when(utils.DP.pipeKind.has, (dataParser) => {
27
31
  countDataParser(dataParser.definition.input);
28
32
  countDataParser(dataParser.definition.output);
29
33
  })
30
- .when(utils.DP.unionKind.has, (dataParser) => utils.A.map(dataParser.definition.options, countDataParser))
34
+ .when(utils.DP.unionKind.has, (dataParser) => {
35
+ const count = (countMap.get(dataParser) ?? 0) + 1;
36
+ countMap.set(dataParser, count);
37
+ if (count > 1) {
38
+ return;
39
+ }
40
+ utils.A.map(dataParser.definition.options, countDataParser);
41
+ if (countMap.get(dataParser) === 1) {
42
+ countMap.delete(dataParser);
43
+ }
44
+ })
31
45
  .when(utils.DP.arrayKind.has, (dataParser) => {
32
46
  const count = (countMap.get(dataParser) ?? 0) + 1;
33
47
  countMap.set(dataParser, count);
@@ -35,6 +49,9 @@ function getRecursiveDataParser(schema) {
35
49
  return;
36
50
  }
37
51
  countDataParser(dataParser.definition.element);
52
+ if (countMap.get(dataParser) === 1) {
53
+ countMap.delete(dataParser);
54
+ }
38
55
  })
39
56
  .when(utils.DP.objectKind.has, (dataParser) => {
40
57
  const count = (countMap.get(dataParser) ?? 0) + 1;
@@ -43,6 +60,9 @@ function getRecursiveDataParser(schema) {
43
60
  return;
44
61
  }
45
62
  utils.pipe(dataParser.definition.shape, utils.O.entries, utils.A.map(([, value]) => void countDataParser(value)));
63
+ if (countMap.get(dataParser) === 1) {
64
+ countMap.delete(dataParser);
65
+ }
46
66
  })
47
67
  .when(utils.DP.tupleKind.has, (dataParser) => {
48
68
  const count = (countMap.get(dataParser) ?? 0) + 1;
@@ -51,6 +71,9 @@ function getRecursiveDataParser(schema) {
51
71
  return;
52
72
  }
53
73
  utils.A.map(dataParser.definition.shape, countDataParser);
74
+ if (countMap.get(dataParser) === 1) {
75
+ countMap.delete(dataParser);
76
+ }
54
77
  })
55
78
  .when(utils.DP.dataParserKind.has, () => void 0)
56
79
  .exhaustive();
@@ -1,31 +1,45 @@
1
- import { P, DP, A, pipe, O, G } from '@duplojs/utils';
1
+ import { P, hasSomeKinds, DP, A, pipe, O, G } from '@duplojs/utils';
2
2
 
3
3
  function getRecursiveDataParser(schema) {
4
4
  const countMap = new Map();
5
5
  void (function countDataParser(schema) {
6
6
  P.match(schema)
7
- .when((value) => (DP.stringKind.has(value)
8
- || DP.stringKind.has(value)
9
- || DP.numberKind.has(value)
10
- || DP.nilKind.has(value)
11
- || DP.dateKind.has(value)
12
- || DP.emptyKind.has(value)
13
- || DP.bigIntKind.has(value)
14
- || DP.booleanKind.has(value)
15
- || DP.literalKind.has(value)
16
- || DP.unknownKind.has(value)
17
- || DP.templateLiteralKind.has(value)
18
- || DP.recordKind.has(value)), () => void 0)
19
- .when((value) => (DP.nullableKind.has(value)
20
- || DP.optionalKind.has(value)
21
- || DP.recoverKind.has(value)
22
- || DP.transformKind.has(value)), (dataParser) => void countDataParser(dataParser.definition.inner))
7
+ .when(hasSomeKinds([
8
+ DP.stringKind,
9
+ DP.stringKind,
10
+ DP.numberKind,
11
+ DP.nilKind,
12
+ DP.dateKind,
13
+ DP.emptyKind,
14
+ DP.bigIntKind,
15
+ DP.booleanKind,
16
+ DP.literalKind,
17
+ DP.unknownKind,
18
+ DP.templateLiteralKind,
19
+ DP.recordKind,
20
+ ]), () => void 0)
21
+ .when(hasSomeKinds([
22
+ DP.nullableKind,
23
+ DP.optionalKind,
24
+ DP.recoverKind,
25
+ DP.transformKind,
26
+ ]), (dataParser) => void countDataParser(dataParser.definition.inner))
23
27
  .when(DP.lazyKind.has, (dataParser) => void countDataParser(dataParser.definition.getter.value))
24
28
  .when(DP.pipeKind.has, (dataParser) => {
25
29
  countDataParser(dataParser.definition.input);
26
30
  countDataParser(dataParser.definition.output);
27
31
  })
28
- .when(DP.unionKind.has, (dataParser) => A.map(dataParser.definition.options, countDataParser))
32
+ .when(DP.unionKind.has, (dataParser) => {
33
+ const count = (countMap.get(dataParser) ?? 0) + 1;
34
+ countMap.set(dataParser, count);
35
+ if (count > 1) {
36
+ return;
37
+ }
38
+ A.map(dataParser.definition.options, countDataParser);
39
+ if (countMap.get(dataParser) === 1) {
40
+ countMap.delete(dataParser);
41
+ }
42
+ })
29
43
  .when(DP.arrayKind.has, (dataParser) => {
30
44
  const count = (countMap.get(dataParser) ?? 0) + 1;
31
45
  countMap.set(dataParser, count);
@@ -33,6 +47,9 @@ function getRecursiveDataParser(schema) {
33
47
  return;
34
48
  }
35
49
  countDataParser(dataParser.definition.element);
50
+ if (countMap.get(dataParser) === 1) {
51
+ countMap.delete(dataParser);
52
+ }
36
53
  })
37
54
  .when(DP.objectKind.has, (dataParser) => {
38
55
  const count = (countMap.get(dataParser) ?? 0) + 1;
@@ -41,6 +58,9 @@ function getRecursiveDataParser(schema) {
41
58
  return;
42
59
  }
43
60
  pipe(dataParser.definition.shape, O.entries, A.map(([, value]) => void countDataParser(value)));
61
+ if (countMap.get(dataParser) === 1) {
62
+ countMap.delete(dataParser);
63
+ }
44
64
  })
45
65
  .when(DP.tupleKind.has, (dataParser) => {
46
66
  const count = (countMap.get(dataParser) ?? 0) + 1;
@@ -49,6 +69,9 @@ function getRecursiveDataParser(schema) {
49
69
  return;
50
70
  }
51
71
  A.map(dataParser.definition.shape, countDataParser);
72
+ if (countMap.get(dataParser) === 1) {
73
+ countMap.delete(dataParser);
74
+ }
52
75
  })
53
76
  .when(DP.dataParserKind.has, () => void 0)
54
77
  .exhaustive();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duplojs/data-parser-tools",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "license": "MIT",
5
5
  "author": "duplojs",
6
6
  "contributors": [