@graphql-markdown/core 1.16.3 → 1.17.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.
Files changed (90) hide show
  1. package/dist/config.d.ts +17 -55
  2. package/dist/config.d.ts.map +1 -0
  3. package/dist/config.js +80 -89
  4. package/dist/const/patterns.d.ts +114 -0
  5. package/dist/const/patterns.d.ts.map +1 -0
  6. package/dist/const/patterns.js +116 -0
  7. package/dist/diff.d.ts +1 -0
  8. package/dist/diff.d.ts.map +1 -0
  9. package/dist/directives/normalize.d.ts +79 -0
  10. package/dist/directives/normalize.d.ts.map +1 -0
  11. package/dist/directives/normalize.js +91 -0
  12. package/dist/directives/validation.d.ts +146 -0
  13. package/dist/directives/validation.d.ts.map +1 -0
  14. package/dist/directives/validation.js +188 -0
  15. package/dist/event-emitter.d.ts +109 -0
  16. package/dist/event-emitter.d.ts.map +1 -0
  17. package/dist/event-emitter.js +136 -0
  18. package/dist/event-handlers.d.ts +22 -0
  19. package/dist/event-handlers.d.ts.map +1 -0
  20. package/dist/event-handlers.js +57 -0
  21. package/dist/event-map.d.ts +26 -0
  22. package/dist/event-map.d.ts.map +1 -0
  23. package/dist/event-map.js +43 -0
  24. package/dist/events/base.d.ts +119 -0
  25. package/dist/events/base.d.ts.map +1 -0
  26. package/dist/events/base.js +149 -0
  27. package/dist/events/diff-check.d.ts +25 -0
  28. package/dist/events/diff-check.d.ts.map +1 -0
  29. package/dist/events/diff-check.js +23 -0
  30. package/dist/events/diff-events.d.ts +15 -0
  31. package/dist/events/diff-events.d.ts.map +1 -0
  32. package/dist/events/diff-events.js +17 -0
  33. package/dist/events/generate-index-metafile-events.d.ts +15 -0
  34. package/dist/events/generate-index-metafile-events.d.ts.map +1 -0
  35. package/dist/events/generate-index-metafile-events.js +17 -0
  36. package/dist/events/generate-index-metafile.d.ts +25 -0
  37. package/dist/events/generate-index-metafile.d.ts.map +1 -0
  38. package/dist/events/generate-index-metafile.js +23 -0
  39. package/dist/events/index.d.ts +22 -0
  40. package/dist/events/index.d.ts.map +1 -0
  41. package/dist/events/index.js +43 -0
  42. package/dist/events/print-type-events.d.ts +33 -0
  43. package/dist/events/print-type-events.d.ts.map +1 -0
  44. package/dist/events/print-type-events.js +35 -0
  45. package/dist/events/print-type.d.ts +84 -0
  46. package/dist/events/print-type.d.ts.map +1 -0
  47. package/dist/events/print-type.js +73 -0
  48. package/dist/events/render-homepage-events.d.ts +15 -0
  49. package/dist/events/render-homepage-events.d.ts.map +1 -0
  50. package/dist/events/render-homepage-events.js +17 -0
  51. package/dist/events/render-homepage.d.ts +21 -0
  52. package/dist/events/render-homepage.d.ts.map +1 -0
  53. package/dist/events/render-homepage.js +23 -0
  54. package/dist/events/render-root-types-events.d.ts +15 -0
  55. package/dist/events/render-root-types-events.d.ts.map +1 -0
  56. package/dist/events/render-root-types-events.js +17 -0
  57. package/dist/events/render-root-types.d.ts +21 -0
  58. package/dist/events/render-root-types.d.ts.map +1 -0
  59. package/dist/events/render-root-types.js +23 -0
  60. package/dist/events/render-type-entities-events.d.ts +15 -0
  61. package/dist/events/render-type-entities-events.d.ts.map +1 -0
  62. package/dist/events/render-type-entities-events.js +17 -0
  63. package/dist/events/render-type-entities.d.ts +23 -0
  64. package/dist/events/render-type-entities.d.ts.map +1 -0
  65. package/dist/events/render-type-entities.js +23 -0
  66. package/dist/events/schema-events.d.ts +19 -0
  67. package/dist/events/schema-events.d.ts.map +1 -0
  68. package/dist/events/schema-events.js +21 -0
  69. package/dist/events/schema-load.d.ts +26 -0
  70. package/dist/events/schema-load.d.ts.map +1 -0
  71. package/dist/events/schema-load.js +23 -0
  72. package/dist/generator.d.ts +80 -1
  73. package/dist/generator.d.ts.map +1 -0
  74. package/dist/generator.js +244 -29
  75. package/dist/graphql-config.d.ts +2 -1
  76. package/dist/graphql-config.d.ts.map +1 -0
  77. package/dist/graphql-config.js +16 -10
  78. package/dist/index.d.ts +19 -0
  79. package/dist/index.d.ts.map +1 -0
  80. package/dist/index.js +26 -3
  81. package/dist/options/builder.d.ts +157 -0
  82. package/dist/options/builder.d.ts.map +1 -0
  83. package/dist/options/builder.js +215 -0
  84. package/dist/printer.d.ts +4 -3
  85. package/dist/printer.d.ts.map +1 -0
  86. package/dist/printer.js +4 -4
  87. package/dist/renderer.d.ts +85 -32
  88. package/dist/renderer.d.ts.map +1 -0
  89. package/dist/renderer.js +411 -77
  90. package/package.json +11 -12
package/dist/index.js CHANGED
@@ -4,8 +4,31 @@
4
4
  */
5
5
  /* istanbul ignore file */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.buildConfig = exports.generateDocFromSchema = void 0;
8
- var generator_1 = require("./generator");
7
+ exports.PrintTypeEvents = exports.GenerateIndexMetafileEvents = exports.RenderTypeEntitiesEvents = exports.RenderHomepageEvents = exports.RenderRootTypesEvents = exports.DiffEvents = exports.SchemaEvents = exports.EVENT_CALLBACK_MAP = exports.registerMDXEventHandlers = exports.resetEvents = exports.getEvents = exports.buildConfig = exports.generateDocFromSchema = void 0;
8
+ const generator_1 = require("./generator");
9
9
  Object.defineProperty(exports, "generateDocFromSchema", { enumerable: true, get: function () { return generator_1.generateDocFromSchema; } });
10
- var config_1 = require("./config");
10
+ const config_1 = require("./config");
11
11
  Object.defineProperty(exports, "buildConfig", { enumerable: true, get: function () { return config_1.buildConfig; } });
12
+ // Event system exports
13
+ const event_emitter_1 = require("./event-emitter");
14
+ Object.defineProperty(exports, "getEvents", { enumerable: true, get: function () { return event_emitter_1.getEvents; } });
15
+ Object.defineProperty(exports, "resetEvents", { enumerable: true, get: function () { return event_emitter_1.resetEvents; } });
16
+ const event_handlers_1 = require("./event-handlers");
17
+ Object.defineProperty(exports, "registerMDXEventHandlers", { enumerable: true, get: function () { return event_handlers_1.registerMDXEventHandlers; } });
18
+ const event_map_1 = require("./event-map");
19
+ Object.defineProperty(exports, "EVENT_CALLBACK_MAP", { enumerable: true, get: function () { return event_map_1.EVENT_CALLBACK_MAP; } });
20
+ // Event constant exports
21
+ const schema_events_1 = require("./events/schema-events");
22
+ Object.defineProperty(exports, "SchemaEvents", { enumerable: true, get: function () { return schema_events_1.SchemaEvents; } });
23
+ const diff_events_1 = require("./events/diff-events");
24
+ Object.defineProperty(exports, "DiffEvents", { enumerable: true, get: function () { return diff_events_1.DiffEvents; } });
25
+ const render_root_types_events_1 = require("./events/render-root-types-events");
26
+ Object.defineProperty(exports, "RenderRootTypesEvents", { enumerable: true, get: function () { return render_root_types_events_1.RenderRootTypesEvents; } });
27
+ const render_homepage_events_1 = require("./events/render-homepage-events");
28
+ Object.defineProperty(exports, "RenderHomepageEvents", { enumerable: true, get: function () { return render_homepage_events_1.RenderHomepageEvents; } });
29
+ const render_type_entities_events_1 = require("./events/render-type-entities-events");
30
+ Object.defineProperty(exports, "RenderTypeEntitiesEvents", { enumerable: true, get: function () { return render_type_entities_events_1.RenderTypeEntitiesEvents; } });
31
+ const generate_index_metafile_events_1 = require("./events/generate-index-metafile-events");
32
+ Object.defineProperty(exports, "GenerateIndexMetafileEvents", { enumerable: true, get: function () { return generate_index_metafile_events_1.GenerateIndexMetafileEvents; } });
33
+ const print_type_events_1 = require("./events/print-type-events");
34
+ Object.defineProperty(exports, "PrintTypeEvents", { enumerable: true, get: function () { return print_type_events_1.PrintTypeEvents; } });
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Option builder for handling CLI/config/default option precedence.
3
+ *
4
+ * This utility provides a fluent interface for merging options from multiple
5
+ * sources (CLI, config file, defaults) with consistent precedence rules:
6
+ * 1. CLI options (highest priority)
7
+ * 2. Config file options
8
+ * 3. Default values (lowest priority)
9
+ *
10
+ * Precedence is enforced semantically via the setIfProvided() method,
11
+ * regardless of the order in which methods are called. Each value tracks its
12
+ * source, and only higher-precedence sources can override existing values.
13
+ *
14
+ * Eliminates repetitive if/coalesce patterns throughout the codebase.
15
+ *
16
+ * @packageDocumentation
17
+ */
18
+ import type { Maybe } from "@graphql-markdown/types";
19
+ /**
20
+ * Builder for constructing options from multiple sources with priority precedence.
21
+ *
22
+ * Precedence is enforced semantically via source tracking, not by call order.
23
+ * CLI values always override config values, which always override defaults,
24
+ * regardless of the order in which methods are called.
25
+ *
26
+ * @template T - The type of the options object being built
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * const options = new OptionBuilder<MyOptions>()
31
+ * // Add in order: default -> config -> cli
32
+ * .addDefault(false, "pretty")
33
+ * .addFromConfig(undefined, "pretty")
34
+ * .addFromCli(true, "pretty") // CLI overrides default
35
+ * .addDefault("/", "baseURL")
36
+ * .addFromConfig("/api", "baseURL") // Config overrides default
37
+ * .addFromCli(undefined, "baseURL")
38
+ * .build();
39
+ * // Result: { pretty: true, baseURL: "/api" }
40
+ * ```
41
+ */
42
+ export declare class OptionBuilder<T extends Record<string, unknown>> {
43
+ private static readonly PRECEDENCE_ORDER;
44
+ private merged;
45
+ private readonly sources;
46
+ /**
47
+ * Adds a default value (lowest priority).
48
+ * Sets a value that can be overwritten by config or CLI options.
49
+ * This method can be called at any time; precedence is enforced semantically.
50
+ *
51
+ * @param value - The default value
52
+ * @param key - The key to store the value under
53
+ * @returns This builder for method chaining
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * builder.addDefault(3000, "port")
58
+ * ```
59
+ */
60
+ addDefault<K extends keyof T>(value: Maybe<T[K]>, key: K): this;
61
+ /**
62
+ * Adds a value from config file if provided (medium priority).
63
+ * Can override default values if the config value exists.
64
+ * This method can be called at any time; precedence is enforced semantically.
65
+ *
66
+ * @param value - The config file option value
67
+ * @param key - The key to store the value under
68
+ * @returns This builder for method chaining
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * builder.addFromConfig(config.port, "port")
73
+ * ```
74
+ */
75
+ addFromConfig<K extends keyof T>(value: Maybe<T[K]>, key: K): this;
76
+ /**
77
+ * Adds a value from CLI options if provided (highest priority).
78
+ * Can override both default and config values for this key.
79
+ * This method can be called at any time; precedence is enforced semantically.
80
+ *
81
+ * @param value - The CLI option value
82
+ * @param key - The key to store the value under
83
+ * @returns This builder for method chaining
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * builder.addFromCli(cliOpts.port, "port")
88
+ * ```
89
+ */
90
+ addFromCli<K extends keyof T>(value: Maybe<T[K]>, key: K): this;
91
+ /**
92
+ * Sets a value if it's not null or undefined, respecting precedence.
93
+ * Internal helper method used by addDefault, addFromConfig, and addFromCli.
94
+ *
95
+ * Only updates the merged value if the source has equal or higher precedence
96
+ * than the currently stored source. Precedence order: default < config < cli.
97
+ *
98
+ * @param value - The value to set
99
+ * @param key - The key to set
100
+ * @param source - The source of this value ('default', 'config', or 'cli')
101
+ * @returns This builder for method chaining
102
+ */
103
+ private setIfProvided;
104
+ /**
105
+ * Transforms a value using a function if the key exists.
106
+ * Useful for processing values after they've been set.
107
+ *
108
+ * @param key - The key to transform
109
+ * @param fn - Function that transforms the current value
110
+ * @returns This builder for method chaining
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * builder.transform("path", (p) => resolve(p))
115
+ * ```
116
+ */
117
+ transform<K extends keyof T>(key: K, fn: (v: T[K]) => T[K]): this;
118
+ /**
119
+ * Conditionally applies a transformation if a predicate is true.
120
+ * Useful for applying different transformations based on other values.
121
+ *
122
+ * @param key - The key to potentially transform
123
+ * @param predicate - Function that determines if transformation should apply
124
+ * @param fn - Function that transforms the value if predicate is true
125
+ * @returns This builder for method chaining
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * builder.transformIf("path", () => force, (p) => resolve(p))
130
+ * ```
131
+ */
132
+ transformIf<K extends keyof T>(key: K, predicate: (merged: Partial<T>) => boolean, fn: (v: T[K]) => T[K]): this;
133
+ /**
134
+ * Gets the current value for a key without building.
135
+ * Useful for conditional logic during building.
136
+ * Returns a shallow copy for arrays and objects to prevent external mutations.
137
+ * Note: Nested objects and arrays are not deep copied.
138
+ *
139
+ * @param key - The key to get
140
+ * @returns The current value for the key, or `undefined` if not set
141
+ */
142
+ get<K extends keyof T>(key: K): T[K] | undefined;
143
+ /**
144
+ * Returns the built options object with all accumulated values.
145
+ * The object contains all keys that were set during the building process.
146
+ *
147
+ * Note: The returned object may be a partial object containing only the keys
148
+ * that were set. Callers should handle potentially missing properties.
149
+ * Returns a defensive copy of the object to prevent external mutations of
150
+ * internal state. Arrays and objects are shallow-copied to protect against
151
+ * external modifications.
152
+ *
153
+ * @returns The constructed options object with type `Partial<T>` (may not have all properties of `T`)
154
+ */
155
+ build(): Partial<T>;
156
+ }
157
+ //# sourceMappingURL=builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../src/options/builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAOrD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC1D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAItC;IAEF,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyC;IAEjE;;;;;;;;;;;;;OAaG;IACH,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,IAAI,CAE9D;IAED;;;;;;;;;;;;;OAaG;IACH,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,IAAI,CAEjE;IAED;;;;;;;;;;;;;OAaG;IACH,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,IAAI,CAE9D;IAED;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,aAAa;IAoBrB;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAKhE;IAED;;;;;;;;;;;;;OAaG;IACH,WAAW,CAAC,CAAC,SAAS,MAAM,CAAC,EAC3B,GAAG,EAAE,CAAC,EACN,SAAS,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,EAC1C,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GACpB,IAAI,CAKN;IAED;;;;;;;;OAQG;IACH,GAAG,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAS/C;IAED;;;;;;;;;;;OAWG;IACH,KAAK,IAAI,OAAO,CAAC,CAAC,CAAC,CAalB;CACF"}
@@ -0,0 +1,215 @@
1
+ "use strict";
2
+ /**
3
+ * Option builder for handling CLI/config/default option precedence.
4
+ *
5
+ * This utility provides a fluent interface for merging options from multiple
6
+ * sources (CLI, config file, defaults) with consistent precedence rules:
7
+ * 1. CLI options (highest priority)
8
+ * 2. Config file options
9
+ * 3. Default values (lowest priority)
10
+ *
11
+ * Precedence is enforced semantically via the setIfProvided() method,
12
+ * regardless of the order in which methods are called. Each value tracks its
13
+ * source, and only higher-precedence sources can override existing values.
14
+ *
15
+ * Eliminates repetitive if/coalesce patterns throughout the codebase.
16
+ *
17
+ * @packageDocumentation
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.OptionBuilder = void 0;
21
+ /**
22
+ * Builder for constructing options from multiple sources with priority precedence.
23
+ *
24
+ * Precedence is enforced semantically via source tracking, not by call order.
25
+ * CLI values always override config values, which always override defaults,
26
+ * regardless of the order in which methods are called.
27
+ *
28
+ * @template T - The type of the options object being built
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * const options = new OptionBuilder<MyOptions>()
33
+ * // Add in order: default -> config -> cli
34
+ * .addDefault(false, "pretty")
35
+ * .addFromConfig(undefined, "pretty")
36
+ * .addFromCli(true, "pretty") // CLI overrides default
37
+ * .addDefault("/", "baseURL")
38
+ * .addFromConfig("/api", "baseURL") // Config overrides default
39
+ * .addFromCli(undefined, "baseURL")
40
+ * .build();
41
+ * // Result: { pretty: true, baseURL: "/api" }
42
+ * ```
43
+ */
44
+ class OptionBuilder {
45
+ static PRECEDENCE_ORDER = {
46
+ default: 0,
47
+ config: 1,
48
+ cli: 2,
49
+ };
50
+ merged = {};
51
+ sources = new Map();
52
+ /**
53
+ * Adds a default value (lowest priority).
54
+ * Sets a value that can be overwritten by config or CLI options.
55
+ * This method can be called at any time; precedence is enforced semantically.
56
+ *
57
+ * @param value - The default value
58
+ * @param key - The key to store the value under
59
+ * @returns This builder for method chaining
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * builder.addDefault(3000, "port")
64
+ * ```
65
+ */
66
+ addDefault(value, key) {
67
+ return this.setIfProvided(value, key, "default");
68
+ }
69
+ /**
70
+ * Adds a value from config file if provided (medium priority).
71
+ * Can override default values if the config value exists.
72
+ * This method can be called at any time; precedence is enforced semantically.
73
+ *
74
+ * @param value - The config file option value
75
+ * @param key - The key to store the value under
76
+ * @returns This builder for method chaining
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * builder.addFromConfig(config.port, "port")
81
+ * ```
82
+ */
83
+ addFromConfig(value, key) {
84
+ return this.setIfProvided(value, key, "config");
85
+ }
86
+ /**
87
+ * Adds a value from CLI options if provided (highest priority).
88
+ * Can override both default and config values for this key.
89
+ * This method can be called at any time; precedence is enforced semantically.
90
+ *
91
+ * @param value - The CLI option value
92
+ * @param key - The key to store the value under
93
+ * @returns This builder for method chaining
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * builder.addFromCli(cliOpts.port, "port")
98
+ * ```
99
+ */
100
+ addFromCli(value, key) {
101
+ return this.setIfProvided(value, key, "cli");
102
+ }
103
+ /**
104
+ * Sets a value if it's not null or undefined, respecting precedence.
105
+ * Internal helper method used by addDefault, addFromConfig, and addFromCli.
106
+ *
107
+ * Only updates the merged value if the source has equal or higher precedence
108
+ * than the currently stored source. Precedence order: default < config < cli.
109
+ *
110
+ * @param value - The value to set
111
+ * @param key - The key to set
112
+ * @param source - The source of this value ('default', 'config', or 'cli')
113
+ * @returns This builder for method chaining
114
+ */
115
+ setIfProvided(value, key, source) {
116
+ if (value !== null && value !== undefined) {
117
+ const currentSource = this.sources.get(key);
118
+ const shouldUpdate = !currentSource ||
119
+ OptionBuilder.PRECEDENCE_ORDER[source] >=
120
+ OptionBuilder.PRECEDENCE_ORDER[currentSource];
121
+ if (shouldUpdate) {
122
+ this.merged[key] = value;
123
+ this.sources.set(key, source);
124
+ }
125
+ }
126
+ return this;
127
+ }
128
+ /**
129
+ * Transforms a value using a function if the key exists.
130
+ * Useful for processing values after they've been set.
131
+ *
132
+ * @param key - The key to transform
133
+ * @param fn - Function that transforms the current value
134
+ * @returns This builder for method chaining
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * builder.transform("path", (p) => resolve(p))
139
+ * ```
140
+ */
141
+ transform(key, fn) {
142
+ if (key in this.merged) {
143
+ this.merged[key] = fn(this.merged[key]);
144
+ }
145
+ return this;
146
+ }
147
+ /**
148
+ * Conditionally applies a transformation if a predicate is true.
149
+ * Useful for applying different transformations based on other values.
150
+ *
151
+ * @param key - The key to potentially transform
152
+ * @param predicate - Function that determines if transformation should apply
153
+ * @param fn - Function that transforms the value if predicate is true
154
+ * @returns This builder for method chaining
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * builder.transformIf("path", () => force, (p) => resolve(p))
159
+ * ```
160
+ */
161
+ transformIf(key, predicate, fn) {
162
+ if (key in this.merged && predicate({ ...this.merged })) {
163
+ this.merged[key] = fn(this.merged[key]);
164
+ }
165
+ return this;
166
+ }
167
+ /**
168
+ * Gets the current value for a key without building.
169
+ * Useful for conditional logic during building.
170
+ * Returns a shallow copy for arrays and objects to prevent external mutations.
171
+ * Note: Nested objects and arrays are not deep copied.
172
+ *
173
+ * @param key - The key to get
174
+ * @returns The current value for the key, or `undefined` if not set
175
+ */
176
+ get(key) {
177
+ const value = this.merged[key];
178
+ if (Array.isArray(value)) {
179
+ return [...value];
180
+ }
181
+ if (value && typeof value === "object") {
182
+ return { ...value };
183
+ }
184
+ return value;
185
+ }
186
+ /**
187
+ * Returns the built options object with all accumulated values.
188
+ * The object contains all keys that were set during the building process.
189
+ *
190
+ * Note: The returned object may be a partial object containing only the keys
191
+ * that were set. Callers should handle potentially missing properties.
192
+ * Returns a defensive copy of the object to prevent external mutations of
193
+ * internal state. Arrays and objects are shallow-copied to protect against
194
+ * external modifications.
195
+ *
196
+ * @returns The constructed options object with type `Partial<T>` (may not have all properties of `T`)
197
+ */
198
+ build() {
199
+ const result = {};
200
+ for (const key in this.merged) {
201
+ const value = this.merged[key];
202
+ if (Array.isArray(value)) {
203
+ result[key] = [...value];
204
+ }
205
+ else if (value && typeof value === "object") {
206
+ result[key] = { ...value };
207
+ }
208
+ else {
209
+ result[key] = value;
210
+ }
211
+ }
212
+ return result;
213
+ }
214
+ }
215
+ exports.OptionBuilder = OptionBuilder;
package/dist/printer.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * This module provides the functionality to load and initialize a printer for GraphQL schema documentation.
5
5
  * It dynamically imports a printer module and configures it with the provided schema and options.
6
6
  */
7
- import type { Maybe, PackageName, Printer, PrinterConfig, PrinterOptions } from "@graphql-markdown/types";
7
+ import type { Formatter, IPrinter, Maybe, PackageName, PrinterConfig, PrinterEventEmitter, PrinterOptions } from "@graphql-markdown/types";
8
8
  /**
9
9
  * Loads and initializes a printer module for GraphQL schema documentation.
10
10
  *
@@ -15,7 +15,7 @@ import type { Maybe, PackageName, Printer, PrinterConfig, PrinterOptions } from
15
15
  * @param printerModule - The name/path of the printer module to load
16
16
  * @param config - Configuration for the printer including schema, baseURL, and linkRoot
17
17
  * @param options - Additional options for customizing the printer's behavior
18
- * @param mdxModule - Optional MDX module for MDX-specific functionality
18
+ * @param formatter - Optional formatter functions for customizing output format (e.g., MDX)
19
19
  *
20
20
  * @returns A promise that resolves to the initialized Printer instance
21
21
  *
@@ -49,4 +49,5 @@ import type { Maybe, PackageName, Printer, PrinterConfig, PrinterOptions } from
49
49
  * const output = printer.printSchema();
50
50
  * ```
51
51
  */
52
- export declare const getPrinter: (printerModule?: Maybe<PackageName>, config?: Maybe<PrinterConfig>, options?: Maybe<PrinterOptions>, mdxModule?: unknown) => Promise<Printer>;
52
+ export declare const getPrinter: (printerModule?: Maybe<PackageName>, config?: Maybe<PrinterConfig>, options?: Maybe<PrinterOptions>, formatter?: Partial<Formatter> | undefined, mdxDeclaration?: Maybe<string>, eventEmitter?: Maybe<PrinterEventEmitter>) => Promise<typeof IPrinter>;
53
+ //# sourceMappingURL=printer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"printer.d.ts","sourceRoot":"","sources":["../src/printer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EACV,SAAS,EACT,QAAQ,EACR,KAAK,EACL,WAAW,EAEX,aAAa,EACb,mBAAmB,EACnB,cAAc,EACf,MAAM,yBAAyB,CAAC;AAEjC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,eAAO,MAAM,UAAU,yPAoCtB,CAAC"}
package/dist/printer.js CHANGED
@@ -44,7 +44,7 @@ exports.getPrinter = void 0;
44
44
  * @param printerModule - The name/path of the printer module to load
45
45
  * @param config - Configuration for the printer including schema, baseURL, and linkRoot
46
46
  * @param options - Additional options for customizing the printer's behavior
47
- * @param mdxModule - Optional MDX module for MDX-specific functionality
47
+ * @param formatter - Optional formatter functions for customizing output format (e.g., MDX)
48
48
  *
49
49
  * @returns A promise that resolves to the initialized Printer instance
50
50
  *
@@ -78,9 +78,9 @@ exports.getPrinter = void 0;
78
78
  * const output = printer.printSchema();
79
79
  * ```
80
80
  */
81
- const getPrinter = async (printerModule, config, options, mdxModule) => {
81
+ const getPrinter = async (printerModule, config, options, formatter, mdxDeclaration, eventEmitter) => {
82
82
  if (typeof printerModule !== "string") {
83
- throw new Error("Invalid printer module name.");
83
+ throw new TypeError("Invalid printer module name.");
84
84
  }
85
85
  if (!config) {
86
86
  throw new Error("Invalid printer config.");
@@ -88,7 +88,7 @@ const getPrinter = async (printerModule, config, options, mdxModule) => {
88
88
  try {
89
89
  const { Printer } = await Promise.resolve(`${printerModule}`).then(s => __importStar(require(s)));
90
90
  const { schema, baseURL, linkRoot } = config;
91
- await Printer.init(schema, baseURL, linkRoot, { ...options }, mdxModule);
91
+ await Printer.init(schema, baseURL, linkRoot, { ...options }, formatter, mdxDeclaration, eventEmitter);
92
92
  return Printer;
93
93
  }
94
94
  catch {