decoders 2.4.0 → 2.4.1

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/dist/index.cjs CHANGED
@@ -29,18 +29,12 @@ function makeObjectAnn(fields, text) {
29
29
  function makeArrayAnn(items, text) {
30
30
  return brand({ type: "array", items, text });
31
31
  }
32
- function makeFunctionAnn(text) {
33
- return brand({ type: "function", text });
34
- }
35
- function makeUnknownAnn(value, text) {
36
- return brand({ type: "unknown", value, text });
32
+ function makeOpaqueAnn(value, text) {
33
+ return brand({ type: "opaque", value, text });
37
34
  }
38
35
  function makeScalarAnn(value, text) {
39
36
  return brand({ type: "scalar", value, text });
40
37
  }
41
- function makeCircularRefAnn(text) {
42
- return brand({ type: "circular-ref", text });
43
- }
44
38
  function updateText(annotation, text) {
45
39
  if (text !== void 0) {
46
40
  return brand({ ...annotation, text });
@@ -81,22 +75,22 @@ function annotate(value, text, seen) {
81
75
  }
82
76
  if (Array.isArray(value)) {
83
77
  if (seen.has(value)) {
84
- return makeCircularRefAnn(text);
78
+ return makeOpaqueAnn("<circular ref>", text);
85
79
  } else {
86
80
  return annotateArray(value, text, seen);
87
81
  }
88
82
  }
89
83
  if (isPojo(value)) {
90
84
  if (seen.has(value)) {
91
- return makeCircularRefAnn(text);
85
+ return makeOpaqueAnn("<circular ref>", text);
92
86
  } else {
93
87
  return annotateObject(value, text, seen);
94
88
  }
95
89
  }
96
90
  if (typeof value === "function") {
97
- return makeFunctionAnn(text);
91
+ return makeOpaqueAnn("<function>", text);
98
92
  }
99
- return makeUnknownAnn(value, text);
93
+ return makeOpaqueAnn("???", text);
100
94
  }
101
95
  function public_annotate(value, text) {
102
96
  return annotate(value, text, /* @__PURE__ */ new WeakSet());
@@ -221,14 +215,12 @@ function serializeAnnotation(ann, prefix = "") {
221
215
  serialized = serializeArray(ann, prefix);
222
216
  } else if (ann.type === "object") {
223
217
  serialized = serializeObject(ann, prefix);
224
- } else if (ann.type === "function") {
225
- serialized = "<function>";
226
- } else if (ann.type === "circular-ref") {
227
- serialized = "<circular ref>";
228
- } else if (ann.type === "unknown") {
229
- serialized = "???";
230
- } else {
218
+ } else if (ann.type === "scalar") {
231
219
  serialized = serializeValue(ann.value);
220
+ } else {
221
+ /* @__PURE__ */ ((_) => {
222
+ })(ann);
223
+ serialized = ann.value;
232
224
  }
233
225
  const text = ann.text;
234
226
  if (text !== void 0) {
@@ -317,8 +309,7 @@ function define(fn) {
317
309
  function then(next) {
318
310
  return define((blob, ok2, err2) => {
319
311
  const r1 = decode(blob);
320
- if (!r1.ok)
321
- return r1;
312
+ if (!r1.ok) return r1;
322
313
  const r2 = isDecoder(next) ? next : next(r1.value, ok2, err2);
323
314
  return isDecoder(r2) ? r2.decode(r1.value) : r2;
324
315
  });
@@ -525,8 +516,7 @@ function inexact(decoders) {
525
516
  const allkeys = new Set(Object.keys(plainObj));
526
517
  return object(decoders).transform((safepart) => {
527
518
  const safekeys = new Set(Object.keys(decoders));
528
- for (const k of safekeys)
529
- allkeys.add(k);
519
+ for (const k of safekeys) allkeys.add(k);
530
520
  const rv = {};
531
521
  for (const k of allkeys) {
532
522
  if (safekeys.has(k)) {
package/dist/index.d.cts CHANGED
@@ -13,20 +13,12 @@ interface ScalarAnnotation {
13
13
  readonly value: unknown;
14
14
  readonly text?: string;
15
15
  }
16
- interface FunctionAnnotation {
17
- readonly type: 'function';
16
+ interface OpaqueAnnotation {
17
+ readonly type: 'opaque';
18
+ readonly value: string;
18
19
  readonly text?: string;
19
20
  }
20
- interface CircularRefAnnotation {
21
- readonly type: 'circular-ref';
22
- readonly text?: string;
23
- }
24
- interface UnknownAnnotation {
25
- readonly type: 'unknown';
26
- readonly value: unknown;
27
- readonly text?: string;
28
- }
29
- type Annotation = ObjectAnnotation | ArrayAnnotation | ScalarAnnotation | FunctionAnnotation | CircularRefAnnotation | UnknownAnnotation;
21
+ type Annotation = ObjectAnnotation | ArrayAnnotation | ScalarAnnotation | OpaqueAnnotation;
30
22
 
31
23
  /**
32
24
  * Result <value> <error>
package/dist/index.d.ts CHANGED
@@ -13,20 +13,12 @@ interface ScalarAnnotation {
13
13
  readonly value: unknown;
14
14
  readonly text?: string;
15
15
  }
16
- interface FunctionAnnotation {
17
- readonly type: 'function';
16
+ interface OpaqueAnnotation {
17
+ readonly type: 'opaque';
18
+ readonly value: string;
18
19
  readonly text?: string;
19
20
  }
20
- interface CircularRefAnnotation {
21
- readonly type: 'circular-ref';
22
- readonly text?: string;
23
- }
24
- interface UnknownAnnotation {
25
- readonly type: 'unknown';
26
- readonly value: unknown;
27
- readonly text?: string;
28
- }
29
- type Annotation = ObjectAnnotation | ArrayAnnotation | ScalarAnnotation | FunctionAnnotation | CircularRefAnnotation | UnknownAnnotation;
21
+ type Annotation = ObjectAnnotation | ArrayAnnotation | ScalarAnnotation | OpaqueAnnotation;
30
22
 
31
23
  /**
32
24
  * Result <value> <error>
package/dist/index.js CHANGED
@@ -29,18 +29,12 @@ function makeObjectAnn(fields, text) {
29
29
  function makeArrayAnn(items, text) {
30
30
  return brand({ type: "array", items, text });
31
31
  }
32
- function makeFunctionAnn(text) {
33
- return brand({ type: "function", text });
34
- }
35
- function makeUnknownAnn(value, text) {
36
- return brand({ type: "unknown", value, text });
32
+ function makeOpaqueAnn(value, text) {
33
+ return brand({ type: "opaque", value, text });
37
34
  }
38
35
  function makeScalarAnn(value, text) {
39
36
  return brand({ type: "scalar", value, text });
40
37
  }
41
- function makeCircularRefAnn(text) {
42
- return brand({ type: "circular-ref", text });
43
- }
44
38
  function updateText(annotation, text) {
45
39
  if (text !== void 0) {
46
40
  return brand({ ...annotation, text });
@@ -81,22 +75,22 @@ function annotate(value, text, seen) {
81
75
  }
82
76
  if (Array.isArray(value)) {
83
77
  if (seen.has(value)) {
84
- return makeCircularRefAnn(text);
78
+ return makeOpaqueAnn("<circular ref>", text);
85
79
  } else {
86
80
  return annotateArray(value, text, seen);
87
81
  }
88
82
  }
89
83
  if (isPojo(value)) {
90
84
  if (seen.has(value)) {
91
- return makeCircularRefAnn(text);
85
+ return makeOpaqueAnn("<circular ref>", text);
92
86
  } else {
93
87
  return annotateObject(value, text, seen);
94
88
  }
95
89
  }
96
90
  if (typeof value === "function") {
97
- return makeFunctionAnn(text);
91
+ return makeOpaqueAnn("<function>", text);
98
92
  }
99
- return makeUnknownAnn(value, text);
93
+ return makeOpaqueAnn("???", text);
100
94
  }
101
95
  function public_annotate(value, text) {
102
96
  return annotate(value, text, /* @__PURE__ */ new WeakSet());
@@ -221,14 +215,12 @@ function serializeAnnotation(ann, prefix = "") {
221
215
  serialized = serializeArray(ann, prefix);
222
216
  } else if (ann.type === "object") {
223
217
  serialized = serializeObject(ann, prefix);
224
- } else if (ann.type === "function") {
225
- serialized = "<function>";
226
- } else if (ann.type === "circular-ref") {
227
- serialized = "<circular ref>";
228
- } else if (ann.type === "unknown") {
229
- serialized = "???";
230
- } else {
218
+ } else if (ann.type === "scalar") {
231
219
  serialized = serializeValue(ann.value);
220
+ } else {
221
+ /* @__PURE__ */ ((_) => {
222
+ })(ann);
223
+ serialized = ann.value;
232
224
  }
233
225
  const text = ann.text;
234
226
  if (text !== void 0) {
@@ -317,8 +309,7 @@ function define(fn) {
317
309
  function then(next) {
318
310
  return define((blob, ok2, err2) => {
319
311
  const r1 = decode(blob);
320
- if (!r1.ok)
321
- return r1;
312
+ if (!r1.ok) return r1;
322
313
  const r2 = isDecoder(next) ? next : next(r1.value, ok2, err2);
323
314
  return isDecoder(r2) ? r2.decode(r1.value) : r2;
324
315
  });
@@ -525,8 +516,7 @@ function inexact(decoders) {
525
516
  const allkeys = new Set(Object.keys(plainObj));
526
517
  return object(decoders).transform((safepart) => {
527
518
  const safekeys = new Set(Object.keys(decoders));
528
- for (const k of safekeys)
529
- allkeys.add(k);
519
+ for (const k of safekeys) allkeys.add(k);
530
520
  const rv = {};
531
521
  for (const k of allkeys) {
532
522
  if (safekeys.has(k)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "decoders",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "Elegant and battle-tested validation library for type-safe input data for TypeScript",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -41,7 +41,7 @@
41
41
  "lint": "eslint --color --report-unused-disable-directives src/ test/ && prettier --list-different src/ test/ test-d/",
42
42
  "lint:docs": "cog -c --check docs/*.md || (npm run docs; git diff; echo 'Error: docs not up-to-date, please re-run \"npm docs\" to update them.' && exit 1)",
43
43
  "lint:package": "publint --strict && attw --pack",
44
- "format": "eslint --color --report-unused-disable-directives --fix src/ test/ && prettier --write src/ test/ test-d/",
44
+ "format": "eslint --color --report-unused-disable-directives --fix src/ test/ ; prettier --write src/ test/ test-d/",
45
45
  "test": "vitest run --coverage",
46
46
  "test:completeness": "./bin/check.sh",
47
47
  "test:typescript": "tsc --noEmit",
@@ -61,25 +61,27 @@
61
61
  "verify"
62
62
  ],
63
63
  "devDependencies": {
64
- "@arethetypeswrong/cli": "^0.13.5",
64
+ "@arethetypeswrong/cli": "^0.15.3",
65
65
  "@release-it/keep-a-changelog": "^5.0.0",
66
- "@typescript-eslint/eslint-plugin": "^6.19.0",
67
- "@typescript-eslint/parser": "^6.19.0",
68
- "@vitest/coverage-istanbul": "^1.2.1",
69
- "eslint": "^8.56.0",
66
+ "@types/eslint": "^8.56.10",
67
+ "@typescript-eslint/eslint-plugin": "^7.14.1",
68
+ "@typescript-eslint/parser": "^7.14.1",
69
+ "@vitest/coverage-istanbul": "^1.6.0",
70
+ "eslint": "^8.57.0",
70
71
  "eslint-plugin-import": "^2.29.1",
71
- "eslint-plugin-simple-import-sort": "^10.0.0",
72
- "fast-check": "^3.15.0",
73
- "itertools": "^2.2.3",
74
- "prettier": "^3.2.4",
75
- "publint": "^0.2.7",
76
- "release-it": "^17.0.1",
77
- "ts-morph": "^21.0.1",
78
- "tsd": "^0.30.4",
79
- "tsup": "^8.0.1",
80
- "typescript": "^5.3.3",
81
- "vite-tsconfig-paths": "^4.3.1",
82
- "vitest": "^1.2.1"
72
+ "eslint-plugin-simple-import-sort": "^12.1.0",
73
+ "fast-check": "^3.19.0",
74
+ "itertools": "^2.3.2",
75
+ "pkg-pr-new": "^0.0.9",
76
+ "prettier": "^3.3.2",
77
+ "publint": "^0.2.8",
78
+ "release-it": "^17.4.0",
79
+ "ts-morph": "^23.0.0",
80
+ "tsd": "^0.31.1",
81
+ "tsup": "^8.1.0",
82
+ "typescript": "^5.5.2",
83
+ "vite-tsconfig-paths": "^4.3.2",
84
+ "vitest": "^1.6.0"
83
85
  },
84
86
  "githubUrl": "https://github.com/nvie/decoders",
85
87
  "sideEffects": false