@goast/core 0.7.0 → 0.7.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 (85) hide show
  1. package/dist/src/ast/node.d.ts +43 -0
  2. package/dist/src/ast/node.js +29 -0
  3. package/dist/src/codegen/config.d.ts +9 -0
  4. package/dist/src/codegen/config.js +4 -0
  5. package/dist/src/codegen/endpoints-generator.d.ts +32 -0
  6. package/dist/src/codegen/endpoints-generator.js +19 -0
  7. package/dist/src/codegen/generator.d.ts +108 -0
  8. package/dist/src/codegen/generator.js +103 -0
  9. package/dist/src/codegen/internal-utils.d.ts +8 -0
  10. package/dist/src/codegen/internal-utils.js +8 -0
  11. package/dist/src/codegen/schemas-generator.d.ts +33 -0
  12. package/dist/src/codegen/schemas-generator.js +20 -0
  13. package/dist/src/codegen/services-generator.d.ts +24 -0
  14. package/dist/src/codegen/services-generator.js +11 -0
  15. package/dist/src/codegen/types.d.ts +56 -0
  16. package/dist/src/collect/collector.d.ts +8 -0
  17. package/dist/src/collect/collector.js +8 -0
  18. package/dist/src/collect/helpers.d.ts +16 -0
  19. package/dist/src/collect/helpers.js +16 -0
  20. package/dist/src/collect/types.d.ts +28 -0
  21. package/dist/src/internal-utils.d.ts +7 -0
  22. package/dist/src/internal-utils.js +7 -0
  23. package/dist/src/parse/deref-proxy.d.ts +19 -0
  24. package/dist/src/parse/deref-proxy.js +19 -0
  25. package/dist/src/parse/openapi-types.d.ts +168 -0
  26. package/dist/src/parse/parser.d.ts +38 -0
  27. package/dist/src/parse/parser.js +38 -0
  28. package/dist/src/parse/types.d.ts +37 -0
  29. package/dist/src/parse/types.js +4 -0
  30. package/dist/src/transform/api-types.d.ts +408 -0
  31. package/dist/src/transform/helpers.d.ts +73 -0
  32. package/dist/src/transform/helpers.js +73 -0
  33. package/dist/src/transform/transform-document.d.ts +7 -0
  34. package/dist/src/transform/transform-document.js +7 -0
  35. package/dist/src/transform/transform-endpoint.d.ts +8 -0
  36. package/dist/src/transform/transform-endpoint.js +8 -0
  37. package/dist/src/transform/transform-schema.d.ts +10 -0
  38. package/dist/src/transform/transform-schema.js +10 -0
  39. package/dist/src/transform/transformer.d.ts +7 -0
  40. package/dist/src/transform/transformer.js +7 -0
  41. package/dist/src/transform/types.d.ts +61 -0
  42. package/dist/src/transform/types.js +4 -0
  43. package/dist/src/utils/action-provider.d.ts +38 -0
  44. package/dist/src/utils/action-provider.js +38 -0
  45. package/dist/src/utils/api-data.utils.d.ts +9 -0
  46. package/dist/src/utils/api-data.utils.js +9 -0
  47. package/dist/src/utils/array.utils.d.ts +7 -0
  48. package/dist/src/utils/array.utils.js +7 -0
  49. package/dist/src/utils/asset-manager.d.ts +22 -0
  50. package/dist/src/utils/asset-manager.js +22 -0
  51. package/dist/src/utils/class.utils.d.ts +22 -0
  52. package/dist/src/utils/class.utils.js +22 -0
  53. package/dist/src/utils/common.utils.d.ts +81 -0
  54. package/dist/src/utils/common.utils.js +81 -0
  55. package/dist/src/utils/condition.d.ts +22 -0
  56. package/dist/src/utils/endpoint.utils.d.ts +12 -0
  57. package/dist/src/utils/endpoint.utils.js +12 -0
  58. package/dist/src/utils/error.utils.d.ts +6 -0
  59. package/dist/src/utils/error.utils.js +6 -0
  60. package/dist/src/utils/factory.d.ts +45 -0
  61. package/dist/src/utils/factory.js +45 -0
  62. package/dist/src/utils/file-system.utils.d.ts +37 -0
  63. package/dist/src/utils/file-system.utils.js +20 -0
  64. package/dist/src/utils/generator.utils.d.ts +7 -0
  65. package/dist/src/utils/generator.utils.js +7 -0
  66. package/dist/src/utils/object.utils.d.ts +16 -0
  67. package/dist/src/utils/object.utils.js +16 -0
  68. package/dist/src/utils/schema-factory.d.ts +197 -0
  69. package/dist/src/utils/schema-factory.js +146 -0
  70. package/dist/src/utils/schema.utils.d.ts +15 -0
  71. package/dist/src/utils/schema.utils.js +15 -0
  72. package/dist/src/utils/source-builder.d.ts +103 -0
  73. package/dist/src/utils/source-builder.js +58 -0
  74. package/dist/src/utils/string-builder/string-builder.d.ts +24 -0
  75. package/dist/src/utils/string-builder/string-builder.js +11 -0
  76. package/dist/src/utils/string-builder/utils.d.ts +68 -0
  77. package/dist/src/utils/string-builder/utils.js +33 -0
  78. package/dist/src/utils/string.utils.d.ts +78 -0
  79. package/dist/src/utils/string.utils.js +64 -0
  80. package/dist/src/utils/string.utils.types.d.ts +34 -0
  81. package/dist/src/utils/type.utils.d.ts +132 -0
  82. package/dist/src/utils/type.utils.js +19 -0
  83. package/dist/src/utils/yaml-info.d.ts +35 -0
  84. package/dist/src/utils/yaml-info.js +25 -0
  85. package/package.json +1 -1
@@ -15,15 +15,37 @@ export function adjustCasing(a, b) {
15
15
  return { ...a, ...b };
16
16
  }
17
17
  }
18
+ /**
19
+ * Converts all characters of a string to lower case.
20
+ * @param str The string to convert.
21
+ * @returns The lower case string.
22
+ */
18
23
  export function lowercase(str) {
19
24
  return str.toLowerCase();
20
25
  }
26
+ /**
27
+ * Converts all characters of a string to upper case.
28
+ * @param str The string to convert.
29
+ * @returns The upper case string.
30
+ */
21
31
  export function uppercase(str) {
22
32
  return str.toUpperCase();
23
33
  }
34
+ /**
35
+ * Converts the first character of a string to upper case and leaves the remaining characters unchanged.
36
+ * An empty string is returned as is.
37
+ * @param str The string to capitalize.
38
+ * @returns The capitalized string.
39
+ */
24
40
  export function capitalize(str) {
25
41
  return (str.charAt(0).toUpperCase() + str.slice(1));
26
42
  }
43
+ /**
44
+ * Converts the first character of a string to lower case and leaves the remaining characters unchanged.
45
+ * An empty string is returned as is.
46
+ * @param str The string to uncapitalize.
47
+ * @returns The uncapitalized string.
48
+ */
27
49
  export function uncapitalize(str) {
28
50
  return (str.charAt(0).toLowerCase() + str.slice(1));
29
51
  }
@@ -92,6 +114,21 @@ export function wordToCasing(str, casing) {
92
114
  .join('');
93
115
  }
94
116
  }
117
+ /**
118
+ * Converts a string to the specified casing. The `camel`, `pascal`, `kebab`, `snake` and `custom` casings are
119
+ * delegated to their dedicated functions. All other casings are applied to the words of the string joined together,
120
+ * so non-alphanumerical characters are removed.
121
+ * @param str The string to convert. `null` and `undefined` are treated as an empty string. The `first-*` word casings
122
+ * throw a `TypeError` for an empty string.
123
+ * @param casing The casing to convert to, optionally with options for that casing.
124
+ * @returns The converted string.
125
+ * @example
126
+ * ```ts
127
+ * toCasing('foo bar', 'pascal'); // => 'FooBar'
128
+ * toCasing('foo bar', 'first-upper'); // => 'Foobar'
129
+ * toCasing('foo_bar', { casing: 'kebab', wordCasing: 'all-upper' }); // => 'FOO-BAR'
130
+ * ```
131
+ */
95
132
  export function toCasing(str, casing) {
96
133
  let options;
97
134
  let casingType;
@@ -311,6 +348,13 @@ function isNonLineBreakWhitespaceChar(char) {
311
348
  char === '\u3000' ||
312
349
  char === '\ufeff');
313
350
  }
351
+ /**
352
+ * Removes trailing whitespace from a string.
353
+ * @param str The string to trim.
354
+ * @param includeNewLine Whether to also remove trailing line breaks. Defaults to `true`. If `false`, only whitespace
355
+ * characters other than line breaks are removed.
356
+ * @returns The trimmed string.
357
+ */
314
358
  export function trimEnd(str, includeNewLine = true) {
315
359
  if (includeNewLine)
316
360
  return str.trimEnd();
@@ -319,6 +363,13 @@ export function trimEnd(str, includeNewLine = true) {
319
363
  ;
320
364
  return str.substring(0, i);
321
365
  }
366
+ /**
367
+ * Removes leading whitespace from a string.
368
+ * @param str The string to trim.
369
+ * @param includeNewLine Whether to also remove leading line breaks. Defaults to `true`. If `false`, only whitespace
370
+ * characters other than line breaks are removed.
371
+ * @returns The trimmed string.
372
+ */
322
373
  export function trimStart(str, includeNewLine = true) {
323
374
  if (includeNewLine)
324
375
  return str.trimStart();
@@ -327,6 +378,13 @@ export function trimStart(str, includeNewLine = true) {
327
378
  ;
328
379
  return str.substring(i);
329
380
  }
381
+ /**
382
+ * Removes leading and trailing whitespace from a string.
383
+ * @param str The string to trim.
384
+ * @param includeNewLine Whether to also remove leading and trailing line breaks. Defaults to `true`. If `false`, only
385
+ * whitespace characters other than line breaks are removed.
386
+ * @returns The trimmed string.
387
+ */
330
388
  export function trim(str, includeNewLine = true) {
331
389
  if (includeNewLine)
332
390
  return str.trim();
@@ -338,6 +396,12 @@ export function trim(str, includeNewLine = true) {
338
396
  ;
339
397
  return str.substring(s, e);
340
398
  }
399
+ /**
400
+ * Removes all occurrences of a substring from a string. The substring is matched literally, not as a regex.
401
+ * @param str The string to remove the substring from.
402
+ * @param rem The substring to remove. Must not be empty, because the search would never advance.
403
+ * @returns The string without the occurrences of `rem`, or `str` itself if `rem` does not occur in it.
404
+ */
341
405
  export function removeStr(str, rem) {
342
406
  let i = str.indexOf(rem);
343
407
  if (i === -1)
@@ -30,11 +30,30 @@ export type WordCasing = 'unchanged' | 'all-lower' | 'all-upper' | 'first-upper'
30
30
  * toCase('fooBar', 'snake') // => 'foo_bar'
31
31
  */
32
32
  export type StringCasing = WordCasing | 'camel' | 'pascal' | 'kebab' | 'snake' | 'custom';
33
+ /**
34
+ * Represents a casing together with the options that apply to it.
35
+ * @template T The casing that determines which options are available.
36
+ */
33
37
  export type StringCasingWithOptions<T extends StringCasing = StringCasing> = {
38
+ /**
39
+ * The casing to apply.
40
+ */
34
41
  casing: T;
35
42
  } & CaseOptions<T>;
43
+ /**
44
+ * Represents either a plain casing or a casing with options.
45
+ * @see StringCasing
46
+ * @see StringCasingWithOptions
47
+ */
36
48
  export type ExtendedStringCasing = StringCasing | StringCasingWithOptions;
49
+ /**
50
+ * Resolves the options that a casing accepts. Casings without options resolve to `never`.
51
+ * @template T The casing to resolve the options for.
52
+ */
37
53
  export type CaseOptions<T extends StringCasing> = T extends 'camel' ? Partial<CamelCaseOptions> : T extends 'pascal' ? Partial<PascalCaseOptions> : T extends 'kebab' ? Partial<KebabCaseOptions> : T extends 'snake' ? Partial<SnakeCaseOptions> : T extends 'custom' ? CustomCaseOptions : never;
54
+ /**
55
+ * Options that are shared by all casings and add text around the converted string.
56
+ */
38
57
  export type BaseCaseOptions = {
39
58
  /**
40
59
  * Specifies a prefix to add to the string.
@@ -51,6 +70,9 @@ export type BaseCaseOptions = {
51
70
  */
52
71
  suffix?: string;
53
72
  };
73
+ /**
74
+ * Options for the camel casing.
75
+ */
54
76
  export type CamelCaseOptions = BaseCaseOptions & {
55
77
  /**
56
78
  * Controls the casing of all characters except the first one for each word.
@@ -65,6 +87,9 @@ export type CamelCaseOptions = BaseCaseOptions & {
65
87
  */
66
88
  keepOriginalCase: boolean;
67
89
  };
90
+ /**
91
+ * Options for the pascal casing.
92
+ */
68
93
  export type PascalCaseOptions = BaseCaseOptions & {
69
94
  /**
70
95
  * Controls the casing of all characters except the first one for each word.
@@ -79,6 +104,9 @@ export type PascalCaseOptions = BaseCaseOptions & {
79
104
  */
80
105
  keepOriginalCase: boolean;
81
106
  };
107
+ /**
108
+ * Options for the kebab casing, which joins the words with hyphens.
109
+ */
82
110
  export type KebabCaseOptions = BaseCaseOptions & {
83
111
  /**
84
112
  * Specifies the casing of words.
@@ -98,6 +126,9 @@ export type KebabCaseOptions = BaseCaseOptions & {
98
126
  */
99
127
  firstWordCasing?: WordCasing;
100
128
  };
129
+ /**
130
+ * Options for the snake casing, which joins the words with underscores.
131
+ */
101
132
  export type SnakeCaseOptions = BaseCaseOptions & {
102
133
  /**
103
134
  * Specifies the casing of words.
@@ -117,6 +148,9 @@ export type SnakeCaseOptions = BaseCaseOptions & {
117
148
  */
118
149
  firstWordCasing?: WordCasing;
119
150
  };
151
+ /**
152
+ * Options for the custom casing, which applies the word casing and joins the words with an optional separator.
153
+ */
120
154
  export type CustomCaseOptions = BaseCaseOptions & {
121
155
  /**
122
156
  * Specifies the separator between words.
@@ -1,27 +1,138 @@
1
+ /**
2
+ * Intersects all types of a tuple, e.g. `Merge<[A, B]>` resolves to `A & B`.
3
+ * @template U The tuple of types to intersect.
4
+ * @example
5
+ * ```ts
6
+ * type AB = Merge<[{ a: string }, { b: number }]>; // { a: string } & { b: number }
7
+ * ```
8
+ */
1
9
  export type Merge<U extends unknown[]> = U extends [infer A, ...infer R] ? A & Merge<R> : {};
10
+ /**
11
+ * Makes the properties `K` of `T` optional, leaving all other properties unchanged.
12
+ * @template T The object type.
13
+ * @template K The keys of `T` to make optional.
14
+ */
2
15
  export type OptionalProperties<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
16
+ /**
17
+ * Makes the properties `K` of `T` required, leaving all other properties unchanged.
18
+ * @template T The object type.
19
+ * @template K The keys of `T` to make required.
20
+ */
3
21
  export type RequiredProperties<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
22
+ /**
23
+ * Gets the item type of an array type, or `never` if `T` is not an array.
24
+ * @template T The type to inspect.
25
+ */
4
26
  export type ArrayItem<T> = T extends (infer U)[] ? U : never;
27
+ /**
28
+ * A value of type `T` or an array of `T`.
29
+ * @template T The item type.
30
+ */
5
31
  export type SingleOrMultiple<T> = T | T[];
32
+ /**
33
+ * Gets the single item type of `T`: the item type if `T` is an array, otherwise `T` itself. Distributes over unions.
34
+ * @template T The type to unwrap.
35
+ * @see SingleOrMultiple
36
+ */
6
37
  export type Single<T> = T extends (infer U)[] ? U : T;
38
+ /**
39
+ * Gets the array type of `T`: `T[]` if `T` is not an array, otherwise an array with the same item type.
40
+ * Distributes over unions.
41
+ * @template T The type to convert to an array.
42
+ * @see SingleOrMultiple
43
+ */
7
44
  export type Multiple<T> = T extends (infer U)[] ? U[] : T[];
45
+ /**
46
+ * A value of type `T` that may also be `null` or `undefined`.
47
+ * @template T The non-nullable type.
48
+ */
8
49
  export type Nullable<T> = T | null | undefined;
50
+ /**
51
+ * Describes a class constructor that creates an instance of `T` from arguments of types `TArgs`.
52
+ * @template T The type of the created instance.
53
+ * @template TArgs The types of the constructor parameters.
54
+ */
9
55
  export interface Constructor<T, TArgs extends any[] = any[]> extends Function {
10
56
  new (...args: TArgs): T;
11
57
  }
58
+ /**
59
+ * Describes a class constructor that takes no arguments and creates an instance of `T`.
60
+ * @template T The type of the created instance.
61
+ */
12
62
  export type EmptyConstructor<T> = Constructor<T, []>;
63
+ /**
64
+ * Gets the union of the keys of `T` whose values are functions.
65
+ * @template T The object type to inspect.
66
+ */
13
67
  export type FunctionNames<T> = {
14
68
  [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;
15
69
  }[keyof T];
70
+ /**
71
+ * Flattens an intersection type (e.g. `Omit<A, K> & B`) into a single object type, so that editor tooltips show
72
+ * the resulting properties directly.
73
+ * @template T The type to flatten.
74
+ */
16
75
  export type Prettify<T> = {
17
76
  [K in keyof T]: T[K];
18
77
  } & {};
78
+ /**
79
+ * Gets the union of all property value types of `T`.
80
+ * @template T The object type.
81
+ */
19
82
  export type ValueOf<T> = T[keyof T];
83
+ /**
84
+ * An array type with at least one element.
85
+ * @template T The element type.
86
+ */
20
87
  export type NonEmptyArray<T> = [T, ...T[]];
88
+ /**
89
+ * Resolves to `U` only if `U` contains every member of `T`, otherwise to `never`. Used by `stringUnionToArray`.
90
+ * @template T The union type whose members must all be included.
91
+ * @template U The tuple of listed members.
92
+ */
21
93
  type MustInclude<T, U extends T[]> = [T] extends [ValueOf<U>] ? U : never;
94
+ /**
95
+ * Creates a function that returns the members of the string union type `T` as an array. The compiler checks that
96
+ * every member of `T` is listed.
97
+ * @template T The string union type whose members must all be listed.
98
+ * @returns A function that takes the members as arguments and returns them as an array.
99
+ * @example
100
+ * ```ts
101
+ * type Color = 'red' | 'green' | 'blue';
102
+ * const colors = stringUnionToArray<Color>()('red', 'green', 'blue'); // ['red', 'green', 'blue']
103
+ * // stringUnionToArray<Color>()('red', 'green'); // Compile error: a member is missing.
104
+ * ```
105
+ */
22
106
  export declare function stringUnionToArray<T>(): <U extends NonEmptyArray<T>>(...elements: MustInclude<T, U>) => MustInclude<T, U>;
107
+ /**
108
+ * Either one of the suggested string values `T`, or any other string. Editors offer `T` as completions while
109
+ * arbitrary strings remain allowed.
110
+ * @template T The suggested string values.
111
+ * @example
112
+ * ```ts
113
+ * type Access = StringSuggestions<'public' | 'private'>;
114
+ * const access: Access = 'protected'; // allowed, while 'public' and 'private' are suggested
115
+ * ```
116
+ */
23
117
  export type StringSuggestions<T extends string> = T | Omit<string, T>;
118
+ /**
119
+ * Returns `value` unchanged at runtime. At the type level, a `StringSuggestions` type is widened to `string`, so the
120
+ * suggested literals no longer narrow it. Other types are returned as they are.
121
+ * @template T The type of the value.
122
+ * @param value The value to return.
123
+ * @returns The same value, typed as `string` where `T` is a string suggestion.
124
+ */
24
125
  export declare function suggestionsAsString<T>(value: T): T extends StringSuggestions<infer U> ? Exclude<T, StringSuggestions<U>> | string : T;
126
+ /**
127
+ * Gets the union of the parameter tuples of all overloads of the function type `T`. Considers up to six overloads.
128
+ * @template T The function type to inspect.
129
+ * @example
130
+ * ```ts
131
+ * declare function parse(input: string): number;
132
+ * declare function parse(input: string, radix: number): number;
133
+ * type ParseArgs = ParametersWithOverloads<typeof parse>; // [input: string] | [input: string, radix: number]
134
+ * ```
135
+ */
25
136
  export type ParametersWithOverloads<T extends (...args: any[]) => any> = T extends {
26
137
  (...args: infer A1): any;
27
138
  (...args: infer A2): any;
@@ -50,7 +161,28 @@ export type ParametersWithOverloads<T extends (...args: any[]) => any> = T exten
50
161
  } ? A1 | A2 : T extends {
51
162
  (...args: infer A1): any;
52
163
  } ? A1 : never;
164
+ /**
165
+ * Helper for `TupleWithCount`: prepends `T` to `R` until `R` has `N` elements.
166
+ * @template T The element type.
167
+ * @template N The target length of the tuple.
168
+ * @template R The tuple built so far.
169
+ */
53
170
  type _TupleOf<T, N extends number, R extends unknown[]> = R['length'] extends N ? R : _TupleOf<T, N, [T, ...R]>;
171
+ /**
172
+ * Creates a tuple type of `T` with a fixed length. A non-literal `number` or `number[]` gives `T[]`, a literal number
173
+ * gives a tuple of that length, and a union of numbers or a number array gives a union of tuples.
174
+ * @template T The element type.
175
+ * @template N The tuple length, or the array of allowed lengths.
176
+ * @example
177
+ * ```ts
178
+ * type Pair = TupleWithCount<string, 2>; // [string, string]
179
+ * type Odd = TupleWithCount<string, [1, 3]>; // [string] | [string, string, string]
180
+ * ```
181
+ */
54
182
  export type TupleWithCount<T, N extends number | number[]> = N extends number ? number extends N ? T[] : _TupleOf<T, N, []> : N extends [infer A, ...infer R] ? A extends number ? R extends number[] ? TupleWithCount<T, A> | TupleWithCount<T, R> : never : never : N extends [] ? never : T[];
183
+ /**
184
+ * A value of type `T` or a `Promise` of it, for functions that may complete synchronously or asynchronously.
185
+ * @template T The resolved value type.
186
+ */
55
187
  export type MaybePromise<T> = T | Promise<T>;
56
188
  export {};
@@ -1,6 +1,25 @@
1
+ /**
2
+ * Creates a function that returns the members of the string union type `T` as an array. The compiler checks that
3
+ * every member of `T` is listed.
4
+ * @template T The string union type whose members must all be listed.
5
+ * @returns A function that takes the members as arguments and returns them as an array.
6
+ * @example
7
+ * ```ts
8
+ * type Color = 'red' | 'green' | 'blue';
9
+ * const colors = stringUnionToArray<Color>()('red', 'green', 'blue'); // ['red', 'green', 'blue']
10
+ * // stringUnionToArray<Color>()('red', 'green'); // Compile error: a member is missing.
11
+ * ```
12
+ */
1
13
  export function stringUnionToArray() {
2
14
  return (...elements) => elements;
3
15
  }
16
+ /**
17
+ * Returns `value` unchanged at runtime. At the type level, a `StringSuggestions` type is widened to `string`, so the
18
+ * suggested literals no longer narrow it. Other types are returned as they are.
19
+ * @template T The type of the value.
20
+ * @param value The value to return.
21
+ * @returns The same value, typed as `string` where `T` is a string suggestion.
22
+ */
4
23
  export function suggestionsAsString(value) {
5
24
  return value;
6
25
  }
@@ -1,12 +1,47 @@
1
1
  import * as YAML from 'yaml';
2
+ /**
3
+ * Symbol under which `parseYamlWithInfo` stores the `YamlInfo` of the parsed value.
4
+ * @see parseYamlWithInfo
5
+ */
2
6
  export declare const yamlInfoSymbol: unique symbol;
7
+ /**
8
+ * The parsed YAML document and line counter that `parseYamlWithInfo` attaches to a parsed value.
9
+ * @see parseYamlWithInfo
10
+ */
3
11
  export type YamlInfo = {
12
+ /**
13
+ * The parsed YAML document, used to look up nodes by their path.
14
+ */
4
15
  document: YAML.Document.Parsed;
16
+ /**
17
+ * The line counter, used to convert the character offset of a node into a line and column.
18
+ */
5
19
  lineCounter: YAML.LineCounter;
6
20
  };
21
+ /**
22
+ * Gets the YAML information that `parseYamlWithInfo` attached to the specified object. Throws an error if the object
23
+ * has no such information.
24
+ * @param obj The object to get the YAML information from.
25
+ * @returns The YAML information of the object.
26
+ */
7
27
  export declare function getYamlInfo(obj: unknown): YamlInfo;
28
+ /**
29
+ * Gets the line and column of the node at the specified path within the YAML document that the object was parsed from.
30
+ * Logs a warning and returns `{ line: 0, col: 0 }` if the node cannot be found or has no source range. Throws if the
31
+ * object has no YAML information.
32
+ * @param obj The object that was returned by `parseYamlWithInfo`.
33
+ * @param path The path of the node, as keys and array indices. Numeric strings are also matched against array indices.
34
+ * @returns The line and column of the node.
35
+ */
8
36
  export declare function getLineInfo(obj: unknown, path: unknown[]): {
9
37
  line: number;
10
38
  col: number;
11
39
  };
40
+ /**
41
+ * Parses a YAML or JSON string into a value and attaches its YAML information under `yamlInfoSymbol`. The attached
42
+ * property is non-enumerable, so it does not appear in keys or serialized output. Throws if the document is a scalar
43
+ * value such as a string or `null`, because only objects can carry the information.
44
+ * @param yamlString The YAML or JSON string to parse.
45
+ * @returns The parsed value, with the YAML information attached.
46
+ */
12
47
  export declare function parseYamlWithInfo(yamlString: string): unknown;
@@ -1,5 +1,15 @@
1
1
  import * as YAML from 'yaml';
2
+ /**
3
+ * Symbol under which `parseYamlWithInfo` stores the `YamlInfo` of the parsed value.
4
+ * @see parseYamlWithInfo
5
+ */
2
6
  export const yamlInfoSymbol = Symbol('yamlInfo');
7
+ /**
8
+ * Gets the YAML information that `parseYamlWithInfo` attached to the specified object. Throws an error if the object
9
+ * has no such information.
10
+ * @param obj The object to get the YAML information from.
11
+ * @returns The YAML information of the object.
12
+ */
3
13
  export function getYamlInfo(obj) {
4
14
  const yamlInfo = obj[yamlInfoSymbol];
5
15
  if (!yamlInfo) {
@@ -7,6 +17,14 @@ export function getYamlInfo(obj) {
7
17
  }
8
18
  return yamlInfo;
9
19
  }
20
+ /**
21
+ * Gets the line and column of the node at the specified path within the YAML document that the object was parsed from.
22
+ * Logs a warning and returns `{ line: 0, col: 0 }` if the node cannot be found or has no source range. Throws if the
23
+ * object has no YAML information.
24
+ * @param obj The object that was returned by `parseYamlWithInfo`.
25
+ * @param path The path of the node, as keys and array indices. Numeric strings are also matched against array indices.
26
+ * @returns The line and column of the node.
27
+ */
10
28
  export function getLineInfo(obj, path) {
11
29
  const yamlInfo = getYamlInfo(obj);
12
30
  const node = yamlInfo.document.getIn(path, true) ??
@@ -24,6 +42,13 @@ export function getLineInfo(obj, path) {
24
42
  }
25
43
  return yamlInfo.lineCounter.linePos(node.range[0]);
26
44
  }
45
+ /**
46
+ * Parses a YAML or JSON string into a value and attaches its YAML information under `yamlInfoSymbol`. The attached
47
+ * property is non-enumerable, so it does not appear in keys or serialized output. Throws if the document is a scalar
48
+ * value such as a string or `null`, because only objects can carry the information.
49
+ * @param yamlString The YAML or JSON string to parse.
50
+ * @returns The parsed value, with the YAML information attached.
51
+ */
27
52
  export function parseYamlWithInfo(yamlString) {
28
53
  const lineCounter = new YAML.LineCounter();
29
54
  const document = YAML.parseDocument(yamlString, { lineCounter });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goast/core",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "A tool designed to transform OpenAPI specifications into various forms with flexibility and extensibility at its core.",
5
5
  "bugs": {
6
6
  "url": "https://github.com/MaSch0212/goast/issues"