@graphql-markdown/core 1.16.3 → 1.17.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.
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 +138 -0
  18. package/dist/event-handlers.d.ts +19 -0
  19. package/dist/event-handlers.d.ts.map +1 -0
  20. package/dist/event-handlers.js +54 -0
  21. package/dist/event-map.d.ts +19 -0
  22. package/dist/event-map.d.ts.map +1 -0
  23. package/dist/event-map.js +35 -0
  24. package/dist/event-types.d.ts +313 -0
  25. package/dist/event-types.d.ts.map +1 -0
  26. package/dist/event-types.js +309 -0
  27. package/dist/events/base.d.ts +114 -0
  28. package/dist/events/base.d.ts.map +1 -0
  29. package/dist/events/base.js +148 -0
  30. package/dist/events/diff-check.d.ts +25 -0
  31. package/dist/events/diff-check.d.ts.map +1 -0
  32. package/dist/events/diff-check.js +26 -0
  33. package/dist/events/diff-events.d.ts +15 -0
  34. package/dist/events/diff-events.d.ts.map +1 -0
  35. package/dist/events/diff-events.js +17 -0
  36. package/dist/events/generate-index-metafile-events.d.ts +15 -0
  37. package/dist/events/generate-index-metafile-events.d.ts.map +1 -0
  38. package/dist/events/generate-index-metafile-events.js +17 -0
  39. package/dist/events/generate-index-metafile.d.ts +28 -0
  40. package/dist/events/generate-index-metafile.d.ts.map +1 -0
  41. package/dist/events/generate-index-metafile.js +29 -0
  42. package/dist/events/index.d.ts +19 -0
  43. package/dist/events/index.d.ts.map +1 -0
  44. package/dist/events/index.js +38 -0
  45. package/dist/events/render-homepage-events.d.ts +15 -0
  46. package/dist/events/render-homepage-events.d.ts.map +1 -0
  47. package/dist/events/render-homepage-events.js +17 -0
  48. package/dist/events/render-homepage.d.ts +22 -0
  49. package/dist/events/render-homepage.d.ts.map +1 -0
  50. package/dist/events/render-homepage.js +23 -0
  51. package/dist/events/render-root-types-events.d.ts +15 -0
  52. package/dist/events/render-root-types-events.d.ts.map +1 -0
  53. package/dist/events/render-root-types-events.js +17 -0
  54. package/dist/events/render-root-types.d.ts +22 -0
  55. package/dist/events/render-root-types.d.ts.map +1 -0
  56. package/dist/events/render-root-types.js +23 -0
  57. package/dist/events/render-type-entities-events.d.ts +15 -0
  58. package/dist/events/render-type-entities-events.d.ts.map +1 -0
  59. package/dist/events/render-type-entities-events.js +17 -0
  60. package/dist/events/render-type-entities.d.ts +25 -0
  61. package/dist/events/render-type-entities.d.ts.map +1 -0
  62. package/dist/events/render-type-entities.js +26 -0
  63. package/dist/events/schema-events.d.ts +15 -0
  64. package/dist/events/schema-events.d.ts.map +1 -0
  65. package/dist/events/schema-events.js +17 -0
  66. package/dist/events/schema-load.d.ts +22 -0
  67. package/dist/events/schema-load.d.ts.map +1 -0
  68. package/dist/events/schema-load.js +23 -0
  69. package/dist/generator.d.ts +1 -0
  70. package/dist/generator.d.ts.map +1 -0
  71. package/dist/generator.js +47 -5
  72. package/dist/graphql-config.d.ts +2 -1
  73. package/dist/graphql-config.d.ts.map +1 -0
  74. package/dist/graphql-config.js +16 -10
  75. package/dist/hooks.d.ts +10 -0
  76. package/dist/hooks.d.ts.map +1 -0
  77. package/dist/hooks.js +33 -0
  78. package/dist/index.d.ts +11 -0
  79. package/dist/index.d.ts.map +1 -0
  80. package/dist/index.js +11 -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 +3 -2
  85. package/dist/printer.d.ts.map +1 -0
  86. package/dist/printer.js +1 -1
  87. package/dist/renderer.d.ts +76 -23
  88. package/dist/renderer.d.ts.map +1 -0
  89. package/dist/renderer.js +411 -67
  90. package/package.json +15 -16
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Directive name normalization and processing utilities.
3
+ *
4
+ * This module consolidates utilities for handling directive names from multiple
5
+ * sources (CLI, config file, etc.) ensuring consistent normalization across
6
+ * the application.
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ import type { DirectiveName, Maybe } from "@graphql-markdown/types";
11
+ /**
12
+ * Normalizes directive names from multiple sources into a single flattened array.
13
+ *
14
+ * This function:
15
+ * 1. Accepts multiple directive name arrays from different sources
16
+ * 2. Filters out null/undefined values and empty arrays
17
+ * 3. Flattens them into a single array
18
+ * 4. Returns the normalized array (may contain duplicates if sources contain duplicates)
19
+ *
20
+ * Useful when combining directives from CLI, config file, and environment sources.
21
+ *
22
+ * @param sources - Multiple arrays of directive names or undefined/null values
23
+ * @returns A single array of normalized directive names (may contain duplicates)
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * import { normalizeDirectiveNames } from "@graphql-markdown/core/directives/normalize";
28
+ *
29
+ * const cliDirectives = ["@example", "@internal"];
30
+ * const configDirectives = ["@auth"];
31
+ *
32
+ * const all = normalizeDirectiveNames(cliDirectives, configDirectives);
33
+ * // Result: ["@example", "@internal", "@auth"]
34
+ *
35
+ * // Safely handles undefined:
36
+ * const safe = normalizeDirectiveNames(cliDirectives, undefined, configDirectives);
37
+ * // Result: ["@example", "@internal", "@auth"]
38
+ * ```
39
+ */
40
+ export declare const normalizeDirectiveNames: (...sources: Maybe<DirectiveName[]>[]) => DirectiveName[];
41
+ /**
42
+ * Removes duplicate directive names from an array while preserving order.
43
+ *
44
+ * @param directives - Array of directive names that may contain duplicates
45
+ * @returns A new array with duplicate directive names removed
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * import { uniqueDirectiveNames } from "@graphql-markdown/core/directives/normalize";
50
+ *
51
+ * const directives = ["@auth", "@example", "@auth", "@internal"];
52
+ * const unique = uniqueDirectiveNames(directives);
53
+ * // Result: ["@auth", "@example", "@internal"]
54
+ * ```
55
+ */
56
+ export declare const uniqueDirectiveNames: (directives: DirectiveName[]) => DirectiveName[];
57
+ /**
58
+ * Combines and deduplicates directive names from multiple sources in one step.
59
+ *
60
+ * This is a convenience function that combines normalizeDirectiveNames
61
+ * with uniqueDirectiveNames for the common case where you need both
62
+ * normalization and deduplication.
63
+ *
64
+ * @param sources - Multiple arrays of directive names or undefined/null values
65
+ * @returns A single array of deduplicated directive names
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * import { combineDirectiveNames } from "@graphql-markdown/core/directives/normalize";
70
+ *
71
+ * const cliDirectives = ["@example", "@internal"];
72
+ * const configDirectives = ["@auth", "@example"]; // @example is duplicate
73
+ *
74
+ * const all = combineDirectiveNames(cliDirectives, configDirectives);
75
+ * // Result: ["@example", "@internal", "@auth"]
76
+ * ```
77
+ */
78
+ export declare const combineDirectiveNames: (...sources: Maybe<DirectiveName[]>[]) => DirectiveName[];
79
+ //# sourceMappingURL=normalize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/directives/normalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,uBAAuB,2DAMnC,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,oBAAoB,kDAIhC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,qBAAqB,2DAIjC,CAAC"}
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ /**
3
+ * Directive name normalization and processing utilities.
4
+ *
5
+ * This module consolidates utilities for handling directive names from multiple
6
+ * sources (CLI, config file, etc.) ensuring consistent normalization across
7
+ * the application.
8
+ *
9
+ * @packageDocumentation
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.combineDirectiveNames = exports.uniqueDirectiveNames = exports.normalizeDirectiveNames = void 0;
13
+ /**
14
+ * Normalizes directive names from multiple sources into a single flattened array.
15
+ *
16
+ * This function:
17
+ * 1. Accepts multiple directive name arrays from different sources
18
+ * 2. Filters out null/undefined values and empty arrays
19
+ * 3. Flattens them into a single array
20
+ * 4. Returns the normalized array (may contain duplicates if sources contain duplicates)
21
+ *
22
+ * Useful when combining directives from CLI, config file, and environment sources.
23
+ *
24
+ * @param sources - Multiple arrays of directive names or undefined/null values
25
+ * @returns A single array of normalized directive names (may contain duplicates)
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * import { normalizeDirectiveNames } from "@graphql-markdown/core/directives/normalize";
30
+ *
31
+ * const cliDirectives = ["@example", "@internal"];
32
+ * const configDirectives = ["@auth"];
33
+ *
34
+ * const all = normalizeDirectiveNames(cliDirectives, configDirectives);
35
+ * // Result: ["@example", "@internal", "@auth"]
36
+ *
37
+ * // Safely handles undefined:
38
+ * const safe = normalizeDirectiveNames(cliDirectives, undefined, configDirectives);
39
+ * // Result: ["@example", "@internal", "@auth"]
40
+ * ```
41
+ */
42
+ const normalizeDirectiveNames = (...sources) => {
43
+ return sources
44
+ .filter((s) => Array.isArray(s) && s.length > 0)
45
+ .flat();
46
+ };
47
+ exports.normalizeDirectiveNames = normalizeDirectiveNames;
48
+ /**
49
+ * Removes duplicate directive names from an array while preserving order.
50
+ *
51
+ * @param directives - Array of directive names that may contain duplicates
52
+ * @returns A new array with duplicate directive names removed
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * import { uniqueDirectiveNames } from "@graphql-markdown/core/directives/normalize";
57
+ *
58
+ * const directives = ["@auth", "@example", "@auth", "@internal"];
59
+ * const unique = uniqueDirectiveNames(directives);
60
+ * // Result: ["@auth", "@example", "@internal"]
61
+ * ```
62
+ */
63
+ const uniqueDirectiveNames = (directives) => {
64
+ return Array.from(new Set(directives));
65
+ };
66
+ exports.uniqueDirectiveNames = uniqueDirectiveNames;
67
+ /**
68
+ * Combines and deduplicates directive names from multiple sources in one step.
69
+ *
70
+ * This is a convenience function that combines normalizeDirectiveNames
71
+ * with uniqueDirectiveNames for the common case where you need both
72
+ * normalization and deduplication.
73
+ *
74
+ * @param sources - Multiple arrays of directive names or undefined/null values
75
+ * @returns A single array of deduplicated directive names
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * import { combineDirectiveNames } from "@graphql-markdown/core/directives/normalize";
80
+ *
81
+ * const cliDirectives = ["@example", "@internal"];
82
+ * const configDirectives = ["@auth", "@example"]; // @example is duplicate
83
+ *
84
+ * const all = combineDirectiveNames(cliDirectives, configDirectives);
85
+ * // Result: ["@example", "@internal", "@auth"]
86
+ * ```
87
+ */
88
+ const combineDirectiveNames = (...sources) => {
89
+ return (0, exports.uniqueDirectiveNames)((0, exports.normalizeDirectiveNames)(...sources));
90
+ };
91
+ exports.combineDirectiveNames = combineDirectiveNames;
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Configuration validation utilities for directive and configuration options.
3
+ *
4
+ * Provides type guard functions and validators for checking configuration object shapes,
5
+ * function types, and property existence patterns commonly used across the codebase.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ /**
10
+ * Type guard to check if an object has a `descriptor` function property.
11
+ *
12
+ * Validates that the object is a proper type object and contains a function named `descriptor`.
13
+ *
14
+ * @param config - The configuration object to check
15
+ * @returns True if config has a descriptor function property
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * if (hasDescriptor(option)) {
20
+ * // option.descriptor is guaranteed to be a function
21
+ * const result = option.descriptor(directive);
22
+ * }
23
+ * ```
24
+ */
25
+ export declare const hasDescriptor: (config: unknown) => config is Record<"descriptor", (...args: unknown[]) => unknown>;
26
+ /**
27
+ * Type guard to check if an object has a `tag` function property.
28
+ *
29
+ * Validates that the object is a proper type object and contains a function named `tag`.
30
+ *
31
+ * @param config - The configuration object to check
32
+ * @returns True if config has a tag function property
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * if (hasTag(option)) {
37
+ * // option.tag is guaranteed to be a function
38
+ * const result = option.tag(directive);
39
+ * }
40
+ * ```
41
+ */
42
+ export declare const hasTag: (config: unknown) => config is Record<"tag", (...args: unknown[]) => unknown>;
43
+ /**
44
+ * Type guard to check if a value is a schema string.
45
+ *
46
+ * Validates that the value is a string representing a GraphQL schema path or URL.
47
+ *
48
+ * @param schema - The schema value to check
49
+ * @returns True if schema is a string
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * if (isSchemaString(config.schema)) {
54
+ * // config.schema is a string path/URL
55
+ * const schemaUrl = config.schema;
56
+ * }
57
+ * ```
58
+ */
59
+ export declare const isSchemaString: (schema: unknown) => schema is string;
60
+ /**
61
+ * Type guard to check if a value is a schema object (key-value mapping).
62
+ *
63
+ * Validates that the value is a type object, not null, not an array, and can be treated as a schema map.
64
+ *
65
+ * @param schema - The schema value to check
66
+ * @returns True if schema is an object mapping (not an array)
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * if (isSchemaObject(projectConfig.schema)) {
71
+ * // Extract first key from schema map
72
+ * const key = Object.keys(schema)[0];
73
+ * }
74
+ * ```
75
+ */
76
+ export declare const isSchemaObject: (schema: unknown) => schema is Record<string, unknown>;
77
+ /**
78
+ * Type guard to check if a value is a valid non-empty path string.
79
+ *
80
+ * Validates that the value is a string and not empty, suitable for file paths or URLs.
81
+ *
82
+ * @param path - The path value to check
83
+ * @returns True if path is a non-empty string
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * if (isPath(folderPath)) {
88
+ * // folderPath is guaranteed to be a non-empty string
89
+ * const fullPath = join(basePath, folderPath);
90
+ * }
91
+ * ```
92
+ */
93
+ export declare const isPath: (path: unknown) => path is string;
94
+ /**
95
+ * Type guard to check if a value is a configuration group object.
96
+ *
97
+ * Validates that the value is a type object (not null, not array, not primitive).
98
+ *
99
+ * @param groups - The groups value to check
100
+ * @returns True if groups is an object mapping (not an array)
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * if (isGroupsObject(options.groups)) {
105
+ * // groups is an object with configuration overrides
106
+ * folderNames = { ...API_GROUPS, ...groups };
107
+ * }
108
+ * ```
109
+ */
110
+ export declare const isGroupsObject: (groups: unknown) => groups is Record<string, string>;
111
+ /**
112
+ * Type guard to check if a value is a loader module name (string).
113
+ *
114
+ * Validates that the value is a string representing a module name for dynamic loading.
115
+ *
116
+ * @param loader - The loader value to check
117
+ * @returns True if loader is a string module name
118
+ *
119
+ * @example
120
+ * ```typescript
121
+ * if (isLoaderString(loaders[name])) {
122
+ * // loaders[name] is a string module name that needs wrapping
123
+ * loaders[name] = { module: loaders[name], options };
124
+ * }
125
+ * ```
126
+ */
127
+ export declare const isLoaderString: (loader: unknown) => loader is string;
128
+ /**
129
+ * Type guard to check if a descriptor or tag property is NOT a function.
130
+ *
131
+ * Used for validation to detect invalid configuration where descriptor or tag
132
+ * are defined but are not callable functions.
133
+ *
134
+ * @param config - The configuration object to check
135
+ * @param property - The property name to check ("descriptor" or "tag")
136
+ * @returns True if the property exists but is not a function
137
+ *
138
+ * @example
139
+ * ```typescript
140
+ * if (isInvalidFunctionProperty(option, "descriptor")) {
141
+ * throw new Error("descriptor must be a function");
142
+ * }
143
+ * ```
144
+ */
145
+ export declare const isInvalidFunctionProperty: (config: unknown, property: "descriptor" | "tag") => config is Record<string, unknown>;
146
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/directives/validation.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAeH;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,aAAa,sFAQzB,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,MAAM,+EAQlB,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,cAAc,uCAE1B,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,cAAc,wDAI1B,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,MAAM,mCAElB,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,cAAc,uDAI1B,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,cAAc,uCAE1B,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,yBAAyB,wFASrC,CAAC"}
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+ /**
3
+ * Configuration validation utilities for directive and configuration options.
4
+ *
5
+ * Provides type guard functions and validators for checking configuration object shapes,
6
+ * function types, and property existence patterns commonly used across the codebase.
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.isInvalidFunctionProperty = exports.isLoaderString = exports.isGroupsObject = exports.isPath = exports.isSchemaObject = exports.isSchemaString = exports.hasTag = exports.hasDescriptor = void 0;
12
+ /**
13
+ * Type guard to check if an object is a proper type object (not null, not an array).
14
+ *
15
+ * @param value - The value to check
16
+ * @returns True if value is an object but not null or array
17
+ * @internal
18
+ */
19
+ const isTypeObject = (value) => {
20
+ return value !== null && typeof value === "object" && !Array.isArray(value);
21
+ };
22
+ /**
23
+ * Type guard to check if an object has a `descriptor` function property.
24
+ *
25
+ * Validates that the object is a proper type object and contains a function named `descriptor`.
26
+ *
27
+ * @param config - The configuration object to check
28
+ * @returns True if config has a descriptor function property
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * if (hasDescriptor(option)) {
33
+ * // option.descriptor is guaranteed to be a function
34
+ * const result = option.descriptor(directive);
35
+ * }
36
+ * ```
37
+ */
38
+ const hasDescriptor = (config) => {
39
+ return (isTypeObject(config) &&
40
+ "descriptor" in config &&
41
+ typeof config.descriptor === "function");
42
+ };
43
+ exports.hasDescriptor = hasDescriptor;
44
+ /**
45
+ * Type guard to check if an object has a `tag` function property.
46
+ *
47
+ * Validates that the object is a proper type object and contains a function named `tag`.
48
+ *
49
+ * @param config - The configuration object to check
50
+ * @returns True if config has a tag function property
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * if (hasTag(option)) {
55
+ * // option.tag is guaranteed to be a function
56
+ * const result = option.tag(directive);
57
+ * }
58
+ * ```
59
+ */
60
+ const hasTag = (config) => {
61
+ return (isTypeObject(config) &&
62
+ "tag" in config &&
63
+ typeof config.tag === "function");
64
+ };
65
+ exports.hasTag = hasTag;
66
+ /**
67
+ * Type guard to check if a value is a schema string.
68
+ *
69
+ * Validates that the value is a string representing a GraphQL schema path or URL.
70
+ *
71
+ * @param schema - The schema value to check
72
+ * @returns True if schema is a string
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * if (isSchemaString(config.schema)) {
77
+ * // config.schema is a string path/URL
78
+ * const schemaUrl = config.schema;
79
+ * }
80
+ * ```
81
+ */
82
+ const isSchemaString = (schema) => {
83
+ return typeof schema === "string";
84
+ };
85
+ exports.isSchemaString = isSchemaString;
86
+ /**
87
+ * Type guard to check if a value is a schema object (key-value mapping).
88
+ *
89
+ * Validates that the value is a type object, not null, not an array, and can be treated as a schema map.
90
+ *
91
+ * @param schema - The schema value to check
92
+ * @returns True if schema is an object mapping (not an array)
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * if (isSchemaObject(projectConfig.schema)) {
97
+ * // Extract first key from schema map
98
+ * const key = Object.keys(schema)[0];
99
+ * }
100
+ * ```
101
+ */
102
+ const isSchemaObject = (schema) => {
103
+ return isTypeObject(schema);
104
+ };
105
+ exports.isSchemaObject = isSchemaObject;
106
+ /**
107
+ * Type guard to check if a value is a valid non-empty path string.
108
+ *
109
+ * Validates that the value is a string and not empty, suitable for file paths or URLs.
110
+ *
111
+ * @param path - The path value to check
112
+ * @returns True if path is a non-empty string
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * if (isPath(folderPath)) {
117
+ * // folderPath is guaranteed to be a non-empty string
118
+ * const fullPath = join(basePath, folderPath);
119
+ * }
120
+ * ```
121
+ */
122
+ const isPath = (path) => {
123
+ return typeof path === "string" && path !== "";
124
+ };
125
+ exports.isPath = isPath;
126
+ /**
127
+ * Type guard to check if a value is a configuration group object.
128
+ *
129
+ * Validates that the value is a type object (not null, not array, not primitive).
130
+ *
131
+ * @param groups - The groups value to check
132
+ * @returns True if groups is an object mapping (not an array)
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * if (isGroupsObject(options.groups)) {
137
+ * // groups is an object with configuration overrides
138
+ * folderNames = { ...API_GROUPS, ...groups };
139
+ * }
140
+ * ```
141
+ */
142
+ const isGroupsObject = (groups) => {
143
+ return isTypeObject(groups);
144
+ };
145
+ exports.isGroupsObject = isGroupsObject;
146
+ /**
147
+ * Type guard to check if a value is a loader module name (string).
148
+ *
149
+ * Validates that the value is a string representing a module name for dynamic loading.
150
+ *
151
+ * @param loader - The loader value to check
152
+ * @returns True if loader is a string module name
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * if (isLoaderString(loaders[name])) {
157
+ * // loaders[name] is a string module name that needs wrapping
158
+ * loaders[name] = { module: loaders[name], options };
159
+ * }
160
+ * ```
161
+ */
162
+ const isLoaderString = (loader) => {
163
+ return typeof loader === "string";
164
+ };
165
+ exports.isLoaderString = isLoaderString;
166
+ /**
167
+ * Type guard to check if a descriptor or tag property is NOT a function.
168
+ *
169
+ * Used for validation to detect invalid configuration where descriptor or tag
170
+ * are defined but are not callable functions.
171
+ *
172
+ * @param config - The configuration object to check
173
+ * @param property - The property name to check ("descriptor" or "tag")
174
+ * @returns True if the property exists but is not a function
175
+ *
176
+ * @example
177
+ * ```typescript
178
+ * if (isInvalidFunctionProperty(option, "descriptor")) {
179
+ * throw new Error("descriptor must be a function");
180
+ * }
181
+ * ```
182
+ */
183
+ const isInvalidFunctionProperty = (config, property) => {
184
+ return (isTypeObject(config) &&
185
+ property in config &&
186
+ typeof config[property] !== "function");
187
+ };
188
+ exports.isInvalidFunctionProperty = isInvalidFunctionProperty;
@@ -0,0 +1,109 @@
1
+ import { EventEmitter } from "node:events";
2
+ import type { CancellableEvent } from "./events/base";
3
+ /**
4
+ * Result object returned when emitting a cancellable event.
5
+ *
6
+ * @category Events
7
+ */
8
+ export interface EmitResult {
9
+ /**
10
+ * Array of errors that occurred during handler execution.
11
+ * Handlers continue executing even if previous handlers throw errors.
12
+ */
13
+ errors: Error[];
14
+ /**
15
+ * Whether any handler called preventDefault() on the event.
16
+ * Only applicable if the event is cancellable.
17
+ */
18
+ defaultPrevented: boolean;
19
+ }
20
+ /**
21
+ * Custom EventEmitter that supports cancellable events with sequential handler execution.
22
+ *
23
+ * Features:
24
+ * - Executes async handlers sequentially (one after another)
25
+ * - Collects errors without stopping handler execution
26
+ * - Supports stopPropagation to halt handler chain
27
+ * - Returns execution results to emitters
28
+ *
29
+ * @category Events
30
+ */
31
+ declare class CancellableEventEmitter extends EventEmitter {
32
+ /**
33
+ * Emit an event asynchronously with cancellable event support.
34
+ *
35
+ * Handlers are executed sequentially in registration order.
36
+ * If a handler throws an error, it's collected but execution continues.
37
+ * If event.propagationStopped becomes true, remaining handlers are skipped.
38
+ *
39
+ * After all handlers execute, if the event has a defaultAction function and
40
+ * preventDefault() was not called, the default action is automatically executed.
41
+ *
42
+ * @param eventName - Name of the event to emit
43
+ * @param event - Cancellable event object with preventDefault() and stopPropagation() methods
44
+ * @returns Promise resolving to EmitResult with errors and cancellation status
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * const events = getEvents();
49
+ * const event = new SchemaLoadEvent({
50
+ * schemaLocation: '/path/to/schema',
51
+ * defaultAction: async () => {
52
+ * // This runs automatically if not prevented
53
+ * await loadSchema('/path/to/schema');
54
+ * }
55
+ * });
56
+ *
57
+ * const { errors, defaultPrevented } = await events.emitAsync('beforeLoadSchema', event);
58
+ *
59
+ * if (errors.length > 0) {
60
+ * console.error('Errors occurred:', errors);
61
+ * }
62
+ * ```
63
+ */
64
+ emitAsync(eventName: string, event: CancellableEvent): Promise<EmitResult>;
65
+ }
66
+ /**
67
+ * Get the singleton event emitter instance.
68
+ *
69
+ * Creates the instance on first call, then returns the same instance on subsequent calls.
70
+ * This ensures all parts of the application share the same event bus.
71
+ *
72
+ * @returns The singleton CancellableEventEmitter instance
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * // In generator.ts
77
+ * const events = getEvents();
78
+ * events.on('beforeLoadSchema', handler);
79
+ *
80
+ * // In renderer.ts - same instance!
81
+ * const events = getEvents();
82
+ * await events.emitAsync('beforeLoadSchema', event);
83
+ * ```
84
+ *
85
+ * @category Events
86
+ */
87
+ export declare const getEvents: () => CancellableEventEmitter;
88
+ /**
89
+ * Reset the event emitter singleton.
90
+ *
91
+ * Removes all event listeners and clears the instance.
92
+ * The next call to getEvents() will create a fresh instance.
93
+ *
94
+ * **Important:** This should only be used in tests to ensure test isolation.
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * // In test setup
99
+ * afterEach(() => {
100
+ * resetEvents();
101
+ * jest.restoreAllMocks();
102
+ * });
103
+ * ```
104
+ *
105
+ * @category Events
106
+ */
107
+ export declare const resetEvents: () => void;
108
+ export {};
109
+ //# sourceMappingURL=event-emitter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-emitter.d.ts","sourceRoot":"","sources":["../src/event-emitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB;;;OAGG;IACH,MAAM,EAAE,KAAK,EAAE,CAAC;IAEhB;;;OAGG;IACH,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;;;;GAUG;AACH,cAAM,uBAAwB,SAAQ,YAAY;IAChD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACG,SAAS,CACb,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,gBAAgB,GACtB,OAAO,CAAC,UAAU,CAAC,CAkCrB;CACF;AAQD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,SAAS,+BAGrB,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,WAAW,YAKvB,CAAC"}