inferred-types 0.28.4 → 0.28.5

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.d.ts CHANGED
@@ -832,9 +832,11 @@ interface MapConfig<IR extends OptRequired | undefined = undefined, D extends Ma
832
832
  cardinality?: D;
833
833
  /**
834
834
  * Whether calls to the final `MapFn` will be logged to stderr
835
- * for debugging purposes. Defaults to false.
835
+ * for debugging purposes. Defaults to false; if you specify
836
+ * a _string_ for a value that will be sent to stderr along
837
+ * with other debugging info.
836
838
  */
837
- debug?: boolean;
839
+ debug?: boolean | string;
838
840
  }
839
841
  /**
840
842
  * A finalized configuration of a **mapTo** mapper functions cardinality
@@ -843,8 +845,9 @@ interface MapConfig<IR extends OptRequired | undefined = undefined, D extends Ma
843
845
  * Note: _this configuration does _not_ yet include the actual mapping
844
846
  * configuration between the input and output._
845
847
  */
846
- declare type FinalizedMapConfig<IR extends OptRequired = MapIR<DefaultOneToManyMapping>, D extends MapCardinalityIllustrated = MapCard<DefaultOneToManyMapping>, OR extends OptRequired = MapOR<DefaultOneToManyMapping>> = Required<MapConfig<IR, D, OR>> & {
848
+ declare type FinalizedMapConfig<IR extends OptRequired = MapIR<DefaultOneToManyMapping>, D extends MapCardinalityIllustrated = MapCard<DefaultOneToManyMapping>, OR extends OptRequired = MapOR<DefaultOneToManyMapping>> = Required<Omit<MapConfig<IR, D, OR>, "debug">> & {
847
849
  finalized: true;
850
+ debug: boolean | string;
848
851
  };
849
852
  /**
850
853
  * User configuration exposed by a config function which specifies the
@@ -857,9 +860,10 @@ declare type MapCardinalityConfig<IR extends OptRequired | undefined, OR extends
857
860
  output?: OR;
858
861
  /**
859
862
  * Whether calls to the final `MapFn` will be logged to stderr
860
- * for debugging purposes. Defaults to false.
863
+ * for debugging purposes. Defaults to false; if you set to a string
864
+ * value than this will be echoed out with stderr.
861
865
  */
862
- debug?: boolean;
866
+ debug?: boolean | string;
863
867
  };
864
868
  /**
865
869
  * **ConfiguredMap**
@@ -873,6 +877,7 @@ declare type ConfiguredMap<C extends FinalizedMapConfig<OptRequired, MapCardinal
873
877
  input: MapIR<C>;
874
878
  cardinality: MapCard<C>;
875
879
  output: MapOR<C>;
880
+ debug: boolean | string;
876
881
  };
877
882
  /**
878
883
  * Extracts the IR, Cardinality, and OR generics from a FinalizedMapConfig
package/dist/index.js CHANGED
@@ -611,36 +611,31 @@ var DEFAULT_MANY_TO_ONE_MAPPING = toFinalizedConfig({
611
611
  output: "req",
612
612
  cardinality: "I[] -> O"
613
613
  });
614
- var mapper = (config) => (map) => {
615
- return (source) => {
616
- const isArray2 = config.cardinality === "I -> O[]" && Array.isArray(source) ? true : config.cardinality === "I[] -> O" && Array.isArray(source) && Array.isArray(source[0]) ? true : false;
617
- if (isArray2) {
618
- const output = source.flatMap(map);
619
- if (config.debug) {
620
- console.error(
621
- `MapFn[${config.input}, ${config.cardinality}, ${config.output}] received:
614
+ var debugMsg = (config, source, output) => {
615
+ if (config.debug) {
616
+ console.error(
617
+ `MapFn[${typeof config.output === "string" ? `${config.output}, ` : ""}${config.input}, ${config.cardinality}, ${config.output}] received:
622
618
 
623
619
  ${JSON.stringify(source)}
624
620
 
625
621
  And produced: ${JSON.stringify(
626
- output
627
- )}
622
+ output
623
+ )}
628
624
 
629
625
  `
630
- );
631
- }
626
+ );
627
+ }
628
+ };
629
+ var mapper = (config) => (map) => {
630
+ return (source) => {
631
+ const isArray2 = config.cardinality === "I -> O[]" && Array.isArray(source) ? true : config.cardinality === "I[] -> O" && Array.isArray(source) && Array.isArray(source[0]) ? true : false;
632
+ if (isArray2) {
633
+ const output = source.flatMap(map);
634
+ debugMsg(config, source, output);
632
635
  return output;
633
636
  } else {
634
637
  const output = map(source);
635
- if (config.debug) {
636
- console.error(
637
- `MapFn[${config.input}, ${config.cardinality}, ${config.output}] received:
638
-
639
- ${JSON.stringify(source)}
640
- And produced: ${JSON.stringify(output)}
641
- `
642
- );
643
- }
638
+ debugMsg(config, source, output);
644
639
  return output;
645
640
  }
646
641
  };
@@ -655,7 +650,8 @@ var setMapper = (config = { input: void 0, output: void 0, cardinality: void 0 }
655
650
  },
656
651
  input: (config == null ? void 0 : config.input) || defaultValue.input,
657
652
  output: (config == null ? void 0 : config.output) || defaultValue.output,
658
- cardinality: (config == null ? void 0 : config.cardinality) || defaultValue.cardinality
653
+ cardinality: (config == null ? void 0 : config.cardinality) || defaultValue.cardinality,
654
+ debug: (config == null ? void 0 : config.debug) || false
659
655
  });
660
656
  var mapToFn = (map) => {
661
657
  return mapper(DEFAULT_ONE_TO_MANY_MAPPING)(map);
package/dist/index.mjs CHANGED
@@ -520,36 +520,31 @@ var DEFAULT_MANY_TO_ONE_MAPPING = toFinalizedConfig({
520
520
  output: "req",
521
521
  cardinality: "I[] -> O"
522
522
  });
523
- var mapper = (config) => (map) => {
524
- return (source) => {
525
- const isArray2 = config.cardinality === "I -> O[]" && Array.isArray(source) ? true : config.cardinality === "I[] -> O" && Array.isArray(source) && Array.isArray(source[0]) ? true : false;
526
- if (isArray2) {
527
- const output = source.flatMap(map);
528
- if (config.debug) {
529
- console.error(
530
- `MapFn[${config.input}, ${config.cardinality}, ${config.output}] received:
523
+ var debugMsg = (config, source, output) => {
524
+ if (config.debug) {
525
+ console.error(
526
+ `MapFn[${typeof config.output === "string" ? `${config.output}, ` : ""}${config.input}, ${config.cardinality}, ${config.output}] received:
531
527
 
532
528
  ${JSON.stringify(source)}
533
529
 
534
530
  And produced: ${JSON.stringify(
535
- output
536
- )}
531
+ output
532
+ )}
537
533
 
538
534
  `
539
- );
540
- }
535
+ );
536
+ }
537
+ };
538
+ var mapper = (config) => (map) => {
539
+ return (source) => {
540
+ const isArray2 = config.cardinality === "I -> O[]" && Array.isArray(source) ? true : config.cardinality === "I[] -> O" && Array.isArray(source) && Array.isArray(source[0]) ? true : false;
541
+ if (isArray2) {
542
+ const output = source.flatMap(map);
543
+ debugMsg(config, source, output);
541
544
  return output;
542
545
  } else {
543
546
  const output = map(source);
544
- if (config.debug) {
545
- console.error(
546
- `MapFn[${config.input}, ${config.cardinality}, ${config.output}] received:
547
-
548
- ${JSON.stringify(source)}
549
- And produced: ${JSON.stringify(output)}
550
- `
551
- );
552
- }
547
+ debugMsg(config, source, output);
553
548
  return output;
554
549
  }
555
550
  };
@@ -564,7 +559,8 @@ var setMapper = (config = { input: void 0, output: void 0, cardinality: void 0 }
564
559
  },
565
560
  input: (config == null ? void 0 : config.input) || defaultValue.input,
566
561
  output: (config == null ? void 0 : config.output) || defaultValue.output,
567
- cardinality: (config == null ? void 0 : config.cardinality) || defaultValue.cardinality
562
+ cardinality: (config == null ? void 0 : config.cardinality) || defaultValue.cardinality,
563
+ debug: (config == null ? void 0 : config.debug) || false
568
564
  });
569
565
  var mapToFn = (map) => {
570
566
  return mapper(DEFAULT_ONE_TO_MANY_MAPPING)(map);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inferred-types",
3
- "version": "0.28.4",
3
+ "version": "0.28.5",
4
4
  "description": "Functions which provide useful type inference on TS projects",
5
5
  "license": "MIT",
6
6
  "author": "Ken Snyder<ken@ken.net>",
@@ -37,9 +37,11 @@ export interface MapConfig<
37
37
  cardinality?: D;
38
38
  /**
39
39
  * Whether calls to the final `MapFn` will be logged to stderr
40
- * for debugging purposes. Defaults to false.
40
+ * for debugging purposes. Defaults to false; if you specify
41
+ * a _string_ for a value that will be sent to stderr along
42
+ * with other debugging info.
41
43
  */
42
- debug?: boolean;
44
+ debug?: boolean | string;
43
45
  }
44
46
 
45
47
  /**
@@ -53,7 +55,7 @@ export type FinalizedMapConfig<
53
55
  IR extends OptRequired = MapIR<DefaultOneToManyMapping>,
54
56
  D extends MapCardinalityIllustrated = MapCard<DefaultOneToManyMapping>,
55
57
  OR extends OptRequired = MapOR<DefaultOneToManyMapping>
56
- > = Required<MapConfig<IR, D, OR>> & { finalized: true };
58
+ > = Required<Omit<MapConfig<IR, D, OR>, "debug">> & { finalized: true; debug: boolean | string };
57
59
 
58
60
  /**
59
61
  * User configuration exposed by a config function which specifies the
@@ -69,9 +71,10 @@ type MapCardinalityConfig<
69
71
  output?: OR;
70
72
  /**
71
73
  * Whether calls to the final `MapFn` will be logged to stderr
72
- * for debugging purposes. Defaults to false.
74
+ * for debugging purposes. Defaults to false; if you set to a string
75
+ * value than this will be echoed out with stderr.
73
76
  */
74
- debug?: boolean;
77
+ debug?: boolean | string;
75
78
  };
76
79
 
77
80
  /**
@@ -88,6 +91,7 @@ export type ConfiguredMap<
88
91
  input: MapIR<C>;
89
92
  cardinality: MapCard<C>;
90
93
  output: MapOR<C>;
94
+ debug: boolean | string;
91
95
  };
92
96
 
93
97
  /**
@@ -49,6 +49,22 @@ export type DefaultOneToManyMapping = typeof DEFAULT_ONE_TO_MANY_MAPPING;
49
49
  export type DefaultOneToOneMapping = typeof DEFAULT_ONE_TO_ONE_MAPPING;
50
50
  export type DefaultManyToOneMapping = typeof DEFAULT_MANY_TO_ONE_MAPPING;
51
51
 
52
+ const debugMsg = <C extends FinalizedMapConfig<any, any, any>>(
53
+ config: C,
54
+ source: any,
55
+ output: any
56
+ ) => {
57
+ if (config.debug) {
58
+ console.error(
59
+ `MapFn[${typeof config.output === "string" ? `${config.output}, ` : ""}${config.input}, ${
60
+ config.cardinality
61
+ }, ${config.output}] received:\n\n${JSON.stringify(source)}\n\nAnd produced: ${JSON.stringify(
62
+ output
63
+ )}\n\n`
64
+ );
65
+ }
66
+ };
67
+
52
68
  /**
53
69
  * The single implementation for all mapping
54
70
  */
@@ -78,28 +94,14 @@ const mapper =
78
94
  // TODO: we should check that the approach below doesn't work for M:1 here
79
95
  // as well
80
96
  const output = (source as any).flatMap(map) as MapFnOutput<I, O, S, MapOR<C>, MapCard<C>>;
81
- if (config.debug) {
82
- console.error(
83
- `MapFn[${config.input}, ${config.cardinality}, ${
84
- config.output
85
- }] received:\n\n${JSON.stringify(source)}\n\nAnd produced: ${JSON.stringify(
86
- output
87
- )}\n\n`
88
- );
89
- }
97
+ debugMsg(config, source, output);
90
98
 
91
99
  return output;
92
100
  } else {
93
101
  // receive _all_ inputs provided as pass into ; this is just a single input unless the
94
102
  // cardinality is
95
103
  const output = map(source as any) as MapFnOutput<I, O, S, MapOR<C>, MapCard<C>>;
96
- if (config.debug) {
97
- console.error(
98
- `MapFn[${config.input}, ${config.cardinality}, ${
99
- config.output
100
- }] received:\n\n${JSON.stringify(source)}\nAnd produced: ${JSON.stringify(output)}\n`
101
- );
102
- }
104
+ debugMsg(config, source, output);
103
105
  return output;
104
106
  }
105
107
  };
@@ -131,6 +133,7 @@ const setMapper = <
131
133
  input: config?.input || defaultValue.input,
132
134
  output: config?.output || defaultValue.output,
133
135
  cardinality: config?.cardinality || defaultValue.cardinality,
136
+ debug: config?.debug || false,
134
137
  });
135
138
 
136
139
  /**