Skip to content

Commit 81708ed

Browse files
committed
docs: more jsdocs on core package
1 parent 9ecdd08 commit 81708ed

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

app-config-core/src/config-source.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import { logger } from '@app-config/logging';
77
import { ParsedValue, ParsingContext, ParsingExtension } from './parsed-value';
88
import { AppConfigError, NotFoundError, ParsingError, BadFileType } from './errors';
99

10+
/**
11+
* File formats that app-config supports.
12+
*/
1013
export enum FileType {
1114
YAML = 'YAML',
1215
TOML = 'TOML',
@@ -160,6 +163,9 @@ export class FallbackSource extends ConfigSource {
160163
}
161164
}
162165

166+
/**
167+
* Converts a JSON object to a string, using specified file type.
168+
*/
163169
export function stringify(config: Json, fileType: FileType, minimal: boolean = false): string {
164170
switch (fileType) {
165171
case FileType.JSON:
@@ -182,6 +188,9 @@ export function stringify(config: Json, fileType: FileType, minimal: boolean = f
182188
}
183189
}
184190

191+
/**
192+
* Returns which file type to use, based on the file extension.
193+
*/
185194
export function filePathAssumedType(filePath: string): FileType {
186195
switch (extname(filePath).toLowerCase().slice(1)) {
187196
case 'yml':
@@ -200,6 +209,9 @@ export function filePathAssumedType(filePath: string): FileType {
200209
}
201210
}
202211

212+
/**
213+
* Parses string based on a file format.
214+
*/
203215
export async function parseRawString(contents: string, fileType: FileType): Promise<Json> {
204216
switch (fileType) {
205217
case FileType.JSON:
@@ -215,6 +227,9 @@ export async function parseRawString(contents: string, fileType: FileType): Prom
215227
}
216228
}
217229

230+
/**
231+
* Try to parse string as different file formats, returning the first that worked.
232+
*/
218233
export async function guessFileType(contents: string): Promise<FileType> {
219234
for (const tryType of [FileType.JSON, FileType.TOML, FileType.JSON5, FileType.YAML]) {
220235
try {

app-config-core/src/parsed-value.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,27 @@ export const InArray = Symbol('InArray');
1212
/** The property being visited is the root object */
1313
export const Root = Symbol('Root');
1414

15+
/** Descriptor for what "key" that a value was defined under within JSON */
1516
export type ParsingExtensionKey =
1617
| [typeof InObject, string]
1718
| [typeof InArray, number]
1819
| [typeof Root];
1920

21+
/**
22+
* Arbitrary context that's passed through the hierachy during parsing, only downwards.
23+
*
24+
* This is used for environment overrides and other options, so that parsing below some
25+
* level in an object tree can override what the current environment is.
26+
*/
2027
export interface ParsingContext {
2128
[k: string]: string | string[] | undefined | ParsingContext;
2229
}
2330

31+
/**
32+
* Performs transformations on raw values that were read.
33+
*
34+
* See https://app-config.dev/guide/intro/extensions.html
35+
*/
2436
export interface ParsingExtension {
2537
(
2638
value: Json,
@@ -37,6 +49,9 @@ export interface ParsingExtension {
3749
extensionName?: string;
3850
}
3951

52+
/**
53+
* Callback that will process and potentially transform a value.
54+
*/
4055
export type ParsingExtensionTransform = (
4156
parse: (
4257
value: Json,
@@ -51,6 +66,7 @@ export type ParsingExtensionTransform = (
5166
root: Json,
5267
) => Promise<ParsedValue> | ParsedValue;
5368

69+
/** Values associated with a ParsedValue */
5470
export interface ParsedValueMetadata {
5571
[key: string]: any;
5672
}
@@ -195,7 +211,7 @@ export class ParsedValue {
195211
return this;
196212
}
197213

198-
/** Lookup property by nested key */
214+
/** Lookup property by nested key name(s) */
199215
property([key, ...rest]: string[]): ParsedValue | undefined {
200216
if (key === '') return this.property(rest);
201217

@@ -350,6 +366,7 @@ function literalParsedValue(raw: Json, source: ConfigSource): ParsedValue {
350366
return new ParsedValue(source, raw, transformed);
351367
}
352368

369+
/** Same as ParsedValue.parse */
353370
export async function parseValue(
354371
value: Json,
355372
source: ConfigSource,

0 commit comments

Comments
 (0)