@karmaniverous/jsonmap 2.0.5 → 2.1.0

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.cts CHANGED
@@ -1,57 +1,98 @@
1
1
  import { z } from 'zod';
2
2
 
3
- interface JsonMapOptions {
4
- ignore?: string | RegExp;
5
- }
6
- declare const JsonMapDynamic: z.ZodObject<{
7
- $: z.ZodUnion<[z.ZodObject<{
3
+ /**
4
+ * Type definitions and Zod schemas for JsonMap.
5
+ *
6
+ * @remarks
7
+ * All Zod schemas are the source of truth; TypeScript types are derived via `z.infer<>`.
8
+ *
9
+ */
10
+
11
+ /**
12
+ * Schema for a single JsonMap transformation step.
13
+ *
14
+ * @remarks
15
+ * A transform specifies a method path and one or more parameter paths
16
+ * used during map evaluation.
17
+ */
18
+ declare const jsonMapTransformSchema: z.ZodObject<{
19
+ method: z.ZodString;
20
+ params: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
21
+ }, z.core.$strip>;
22
+ /** A single JsonMap transformation step. */
23
+ type JsonMapTransform = z.infer<typeof jsonMapTransformSchema>;
24
+ /**
25
+ * Schema for a dynamic value node in a JsonMap.
26
+ *
27
+ * @remarks
28
+ * A dynamic node is an object whose sole key is `$`, holding one or more
29
+ * {@link JsonMapTransform} steps.
30
+ */
31
+ declare const jsonMapDynamicSchema: z.ZodObject<{
32
+ $: z.ZodUnion<readonly [z.ZodObject<{
8
33
  method: z.ZodString;
9
- params: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
10
- }, "strip", z.ZodTypeAny, {
11
- method: string;
12
- params: string | string[];
13
- }, {
14
- method: string;
15
- params: string | string[];
16
- }>, z.ZodArray<z.ZodObject<{
34
+ params: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
35
+ }, z.core.$strip>, z.ZodArray<z.ZodObject<{
17
36
  method: z.ZodString;
18
- params: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
19
- }, "strip", z.ZodTypeAny, {
20
- method: string;
21
- params: string | string[];
22
- }, {
23
- method: string;
24
- params: string | string[];
25
- }>, "many">]>;
26
- }, "strip", z.ZodTypeAny, {
27
- $: {
28
- method: string;
29
- params: string | string[];
30
- } | {
31
- method: string;
32
- params: string | string[];
33
- }[];
34
- }, {
35
- $: {
36
- method: string;
37
- params: string | string[];
38
- } | {
39
- method: string;
40
- params: string | string[];
41
- }[];
42
- }>;
43
- type JsonMapDynamic = z.infer<typeof JsonMapDynamic>;
44
- declare const literalSchema: z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
37
+ params: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
38
+ }, z.core.$strip>>]>;
39
+ }, z.core.$strip>;
40
+ /** A dynamic value node in a JsonMap. */
41
+ type JsonMapDynamic = z.infer<typeof jsonMapDynamicSchema>;
42
+ declare const literalSchema: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
43
+ /** A JSON literal value. */
45
44
  type Literal = z.infer<typeof literalSchema>;
45
+ /** Any valid JSON value. */
46
46
  type Json = Literal | {
47
47
  [key: string]: Json;
48
48
  } | Json[];
49
+ /** A library of functions available to JsonMap transformations. */
49
50
  type JsonMapLib = {
50
51
  [key: string]: JsonMapLib | ((x: any) => any);
51
52
  } | JsonMapLib[];
53
+ /**
54
+ * A recursive JsonMap map definition.
55
+ *
56
+ * @remarks
57
+ * This type is the union of JSON literals, objects mapping string keys to
58
+ * either nested maps or {@link JsonMapDynamic} nodes, and arrays of maps.
59
+ */
52
60
  type JsonMapMap = Literal | {
53
61
  [key: string]: JsonMapMap | JsonMapDynamic;
54
62
  } | JsonMapMap[];
63
+ /**
64
+ * Schema for a recursive JsonMap map definition.
65
+ *
66
+ * @remarks
67
+ * A map node is either a JSON literal, an array of map nodes, or an object
68
+ * whose values are map nodes or {@link JsonMapDynamic} nodes.
69
+ */
70
+ declare const jsonMapMapSchema: z.ZodType<JsonMapMap>;
71
+ /**
72
+ * Schema for JsonMap constructor options.
73
+ *
74
+ * @remarks
75
+ * The `ignore` field accepts a string or RegExp. The RegExp branch uses
76
+ * `z.custom` and cannot be faithfully represented in standard JSON Schema.
77
+ * JSON Schema consumers should treat this field as a string pattern.
78
+ */
79
+ declare const jsonMapOptionsSchema: z.ZodObject<{
80
+ ignore: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<RegExp, RegExp>]>>;
81
+ }, z.core.$strip>;
82
+ /** Options passed to the {@link JsonMap} constructor. */
83
+ type JsonMapOptions = z.infer<typeof jsonMapOptionsSchema>;
84
+ /** Parameters for path resolution. */
85
+ interface PathResolutionParams {
86
+ obj?: string;
87
+ path: string;
88
+ }
89
+ /** Map of pattern strings to path resolution functions. */
90
+ type PathResolutionMap = Record<string, (x: PathResolutionParams) => {
91
+ obj: unknown;
92
+ path: string;
93
+ }>;
94
+ /** Replacer/reviver function signature for JSON serialisation. */
95
+ type JsonFn = (this: unknown, key: string, value: unknown) => unknown;
55
96
 
56
97
  /**
57
98
  * JsonMap class to apply transformations to a JSON object
@@ -70,4 +111,5 @@ declare class JsonMap {
70
111
  transform(input: Json): Promise<Json>;
71
112
  }
72
113
 
73
- export { JsonMap };
114
+ export { JsonMap, jsonMapDynamicSchema, jsonMapMapSchema, jsonMapOptionsSchema, jsonMapTransformSchema };
115
+ export type { Json, JsonFn, JsonMapDynamic, JsonMapLib, JsonMapMap, JsonMapOptions, JsonMapTransform, PathResolutionMap, PathResolutionParams };
package/dist/index.d.mts CHANGED
@@ -1,57 +1,98 @@
1
1
  import { z } from 'zod';
2
2
 
3
- interface JsonMapOptions {
4
- ignore?: string | RegExp;
5
- }
6
- declare const JsonMapDynamic: z.ZodObject<{
7
- $: z.ZodUnion<[z.ZodObject<{
3
+ /**
4
+ * Type definitions and Zod schemas for JsonMap.
5
+ *
6
+ * @remarks
7
+ * All Zod schemas are the source of truth; TypeScript types are derived via `z.infer<>`.
8
+ *
9
+ */
10
+
11
+ /**
12
+ * Schema for a single JsonMap transformation step.
13
+ *
14
+ * @remarks
15
+ * A transform specifies a method path and one or more parameter paths
16
+ * used during map evaluation.
17
+ */
18
+ declare const jsonMapTransformSchema: z.ZodObject<{
19
+ method: z.ZodString;
20
+ params: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
21
+ }, z.core.$strip>;
22
+ /** A single JsonMap transformation step. */
23
+ type JsonMapTransform = z.infer<typeof jsonMapTransformSchema>;
24
+ /**
25
+ * Schema for a dynamic value node in a JsonMap.
26
+ *
27
+ * @remarks
28
+ * A dynamic node is an object whose sole key is `$`, holding one or more
29
+ * {@link JsonMapTransform} steps.
30
+ */
31
+ declare const jsonMapDynamicSchema: z.ZodObject<{
32
+ $: z.ZodUnion<readonly [z.ZodObject<{
8
33
  method: z.ZodString;
9
- params: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
10
- }, "strip", z.ZodTypeAny, {
11
- method: string;
12
- params: string | string[];
13
- }, {
14
- method: string;
15
- params: string | string[];
16
- }>, z.ZodArray<z.ZodObject<{
34
+ params: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
35
+ }, z.core.$strip>, z.ZodArray<z.ZodObject<{
17
36
  method: z.ZodString;
18
- params: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
19
- }, "strip", z.ZodTypeAny, {
20
- method: string;
21
- params: string | string[];
22
- }, {
23
- method: string;
24
- params: string | string[];
25
- }>, "many">]>;
26
- }, "strip", z.ZodTypeAny, {
27
- $: {
28
- method: string;
29
- params: string | string[];
30
- } | {
31
- method: string;
32
- params: string | string[];
33
- }[];
34
- }, {
35
- $: {
36
- method: string;
37
- params: string | string[];
38
- } | {
39
- method: string;
40
- params: string | string[];
41
- }[];
42
- }>;
43
- type JsonMapDynamic = z.infer<typeof JsonMapDynamic>;
44
- declare const literalSchema: z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
37
+ params: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
38
+ }, z.core.$strip>>]>;
39
+ }, z.core.$strip>;
40
+ /** A dynamic value node in a JsonMap. */
41
+ type JsonMapDynamic = z.infer<typeof jsonMapDynamicSchema>;
42
+ declare const literalSchema: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
43
+ /** A JSON literal value. */
45
44
  type Literal = z.infer<typeof literalSchema>;
45
+ /** Any valid JSON value. */
46
46
  type Json = Literal | {
47
47
  [key: string]: Json;
48
48
  } | Json[];
49
+ /** A library of functions available to JsonMap transformations. */
49
50
  type JsonMapLib = {
50
51
  [key: string]: JsonMapLib | ((x: any) => any);
51
52
  } | JsonMapLib[];
53
+ /**
54
+ * A recursive JsonMap map definition.
55
+ *
56
+ * @remarks
57
+ * This type is the union of JSON literals, objects mapping string keys to
58
+ * either nested maps or {@link JsonMapDynamic} nodes, and arrays of maps.
59
+ */
52
60
  type JsonMapMap = Literal | {
53
61
  [key: string]: JsonMapMap | JsonMapDynamic;
54
62
  } | JsonMapMap[];
63
+ /**
64
+ * Schema for a recursive JsonMap map definition.
65
+ *
66
+ * @remarks
67
+ * A map node is either a JSON literal, an array of map nodes, or an object
68
+ * whose values are map nodes or {@link JsonMapDynamic} nodes.
69
+ */
70
+ declare const jsonMapMapSchema: z.ZodType<JsonMapMap>;
71
+ /**
72
+ * Schema for JsonMap constructor options.
73
+ *
74
+ * @remarks
75
+ * The `ignore` field accepts a string or RegExp. The RegExp branch uses
76
+ * `z.custom` and cannot be faithfully represented in standard JSON Schema.
77
+ * JSON Schema consumers should treat this field as a string pattern.
78
+ */
79
+ declare const jsonMapOptionsSchema: z.ZodObject<{
80
+ ignore: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<RegExp, RegExp>]>>;
81
+ }, z.core.$strip>;
82
+ /** Options passed to the {@link JsonMap} constructor. */
83
+ type JsonMapOptions = z.infer<typeof jsonMapOptionsSchema>;
84
+ /** Parameters for path resolution. */
85
+ interface PathResolutionParams {
86
+ obj?: string;
87
+ path: string;
88
+ }
89
+ /** Map of pattern strings to path resolution functions. */
90
+ type PathResolutionMap = Record<string, (x: PathResolutionParams) => {
91
+ obj: unknown;
92
+ path: string;
93
+ }>;
94
+ /** Replacer/reviver function signature for JSON serialisation. */
95
+ type JsonFn = (this: unknown, key: string, value: unknown) => unknown;
55
96
 
56
97
  /**
57
98
  * JsonMap class to apply transformations to a JSON object
@@ -70,4 +111,5 @@ declare class JsonMap {
70
111
  transform(input: Json): Promise<Json>;
71
112
  }
72
113
 
73
- export { JsonMap };
114
+ export { JsonMap, jsonMapDynamicSchema, jsonMapMapSchema, jsonMapOptionsSchema, jsonMapTransformSchema };
115
+ export type { Json, JsonFn, JsonMapDynamic, JsonMapLib, JsonMapMap, JsonMapOptions, JsonMapTransform, PathResolutionMap, PathResolutionParams };
package/dist/index.d.ts CHANGED
@@ -1,57 +1,98 @@
1
1
  import { z } from 'zod';
2
2
 
3
- interface JsonMapOptions {
4
- ignore?: string | RegExp;
5
- }
6
- declare const JsonMapDynamic: z.ZodObject<{
7
- $: z.ZodUnion<[z.ZodObject<{
3
+ /**
4
+ * Type definitions and Zod schemas for JsonMap.
5
+ *
6
+ * @remarks
7
+ * All Zod schemas are the source of truth; TypeScript types are derived via `z.infer<>`.
8
+ *
9
+ */
10
+
11
+ /**
12
+ * Schema for a single JsonMap transformation step.
13
+ *
14
+ * @remarks
15
+ * A transform specifies a method path and one or more parameter paths
16
+ * used during map evaluation.
17
+ */
18
+ declare const jsonMapTransformSchema: z.ZodObject<{
19
+ method: z.ZodString;
20
+ params: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
21
+ }, z.core.$strip>;
22
+ /** A single JsonMap transformation step. */
23
+ type JsonMapTransform = z.infer<typeof jsonMapTransformSchema>;
24
+ /**
25
+ * Schema for a dynamic value node in a JsonMap.
26
+ *
27
+ * @remarks
28
+ * A dynamic node is an object whose sole key is `$`, holding one or more
29
+ * {@link JsonMapTransform} steps.
30
+ */
31
+ declare const jsonMapDynamicSchema: z.ZodObject<{
32
+ $: z.ZodUnion<readonly [z.ZodObject<{
8
33
  method: z.ZodString;
9
- params: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
10
- }, "strip", z.ZodTypeAny, {
11
- method: string;
12
- params: string | string[];
13
- }, {
14
- method: string;
15
- params: string | string[];
16
- }>, z.ZodArray<z.ZodObject<{
34
+ params: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
35
+ }, z.core.$strip>, z.ZodArray<z.ZodObject<{
17
36
  method: z.ZodString;
18
- params: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
19
- }, "strip", z.ZodTypeAny, {
20
- method: string;
21
- params: string | string[];
22
- }, {
23
- method: string;
24
- params: string | string[];
25
- }>, "many">]>;
26
- }, "strip", z.ZodTypeAny, {
27
- $: {
28
- method: string;
29
- params: string | string[];
30
- } | {
31
- method: string;
32
- params: string | string[];
33
- }[];
34
- }, {
35
- $: {
36
- method: string;
37
- params: string | string[];
38
- } | {
39
- method: string;
40
- params: string | string[];
41
- }[];
42
- }>;
43
- type JsonMapDynamic = z.infer<typeof JsonMapDynamic>;
44
- declare const literalSchema: z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
37
+ params: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
38
+ }, z.core.$strip>>]>;
39
+ }, z.core.$strip>;
40
+ /** A dynamic value node in a JsonMap. */
41
+ type JsonMapDynamic = z.infer<typeof jsonMapDynamicSchema>;
42
+ declare const literalSchema: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
43
+ /** A JSON literal value. */
45
44
  type Literal = z.infer<typeof literalSchema>;
45
+ /** Any valid JSON value. */
46
46
  type Json = Literal | {
47
47
  [key: string]: Json;
48
48
  } | Json[];
49
+ /** A library of functions available to JsonMap transformations. */
49
50
  type JsonMapLib = {
50
51
  [key: string]: JsonMapLib | ((x: any) => any);
51
52
  } | JsonMapLib[];
53
+ /**
54
+ * A recursive JsonMap map definition.
55
+ *
56
+ * @remarks
57
+ * This type is the union of JSON literals, objects mapping string keys to
58
+ * either nested maps or {@link JsonMapDynamic} nodes, and arrays of maps.
59
+ */
52
60
  type JsonMapMap = Literal | {
53
61
  [key: string]: JsonMapMap | JsonMapDynamic;
54
62
  } | JsonMapMap[];
63
+ /**
64
+ * Schema for a recursive JsonMap map definition.
65
+ *
66
+ * @remarks
67
+ * A map node is either a JSON literal, an array of map nodes, or an object
68
+ * whose values are map nodes or {@link JsonMapDynamic} nodes.
69
+ */
70
+ declare const jsonMapMapSchema: z.ZodType<JsonMapMap>;
71
+ /**
72
+ * Schema for JsonMap constructor options.
73
+ *
74
+ * @remarks
75
+ * The `ignore` field accepts a string or RegExp. The RegExp branch uses
76
+ * `z.custom` and cannot be faithfully represented in standard JSON Schema.
77
+ * JSON Schema consumers should treat this field as a string pattern.
78
+ */
79
+ declare const jsonMapOptionsSchema: z.ZodObject<{
80
+ ignore: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<RegExp, RegExp>]>>;
81
+ }, z.core.$strip>;
82
+ /** Options passed to the {@link JsonMap} constructor. */
83
+ type JsonMapOptions = z.infer<typeof jsonMapOptionsSchema>;
84
+ /** Parameters for path resolution. */
85
+ interface PathResolutionParams {
86
+ obj?: string;
87
+ path: string;
88
+ }
89
+ /** Map of pattern strings to path resolution functions. */
90
+ type PathResolutionMap = Record<string, (x: PathResolutionParams) => {
91
+ obj: unknown;
92
+ path: string;
93
+ }>;
94
+ /** Replacer/reviver function signature for JSON serialisation. */
95
+ type JsonFn = (this: unknown, key: string, value: unknown) => unknown;
55
96
 
56
97
  /**
57
98
  * JsonMap class to apply transformations to a JSON object
@@ -70,4 +111,5 @@ declare class JsonMap {
70
111
  transform(input: Json): Promise<Json>;
71
112
  }
72
113
 
73
- export { JsonMap };
114
+ export { JsonMap, jsonMapDynamicSchema, jsonMapMapSchema, jsonMapOptionsSchema, jsonMapTransformSchema };
115
+ export type { Json, JsonFn, JsonMapDynamic, JsonMapLib, JsonMapMap, JsonMapOptions, JsonMapTransform, PathResolutionMap, PathResolutionParams };