tyfigo 0.0.0 → 0.1.0-next.398bcc7.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/README.md +7 -7
- package/dist/effect.d.mts +2 -13
- package/dist/effect.mjs +1 -16
- package/dist/index-_5Tr2XH2.d.mts +106 -0
- package/dist/index.d.mts +2 -10
- package/dist/index.mjs +1 -13
- package/dist/runtime/index.d.mts +93 -0
- package/dist/runtime/index.mjs +925 -0
- package/dist/runtime/index.mjs.map +1 -0
- package/package.json +13 -5
- package/dist/effect.mjs.map +0 -1
- package/dist/index.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# tyfigo
|
|
4
4
|
|
|
5
5
|
**Import YAML, TOML, JSON5, INI and .env files into TypeScript with full type inference.**
|
|
6
6
|
|
|
7
|
-
[](https://github.com/imranbarbhuiya/tyfigo/blob/main/LICENSE)
|
|
8
|
+
[](https://www.npmjs.com/package/tyfigo)
|
|
9
9
|
|
|
10
10
|
</div>
|
|
11
11
|
|
|
12
12
|
> [!WARNING]
|
|
13
|
-
>
|
|
13
|
+
> tyfigo is in early development and not usable yet.
|
|
14
14
|
|
|
15
15
|
## Install
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
|
-
npm i
|
|
18
|
+
npm i tyfigo
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
## Buy me some doughnuts
|
|
@@ -30,6 +30,6 @@ If you want to support me by donating, you can do so by using any of the followi
|
|
|
30
30
|
|
|
31
31
|
Thanks goes to these wonderful people:
|
|
32
32
|
|
|
33
|
-
<a href="https://github.com/imranbarbhuiya/
|
|
34
|
-
<img src="https://contrib.rocks/image?repo=imranbarbhuiya/
|
|
33
|
+
<a href="https://github.com/imranbarbhuiya/tyfigo/graphs/contributors">
|
|
34
|
+
<img src="https://contrib.rocks/image?repo=imranbarbhuiya/tyfigo" />
|
|
35
35
|
</a>
|
package/dist/effect.d.mts
CHANGED
|
@@ -1,13 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
readonly _tag: "EmptyNameError";
|
|
4
|
-
} & Readonly<A>;
|
|
5
|
-
export declare class EmptyNameError extends EmptyNameError_base {}
|
|
6
|
-
/**
|
|
7
|
-
* Greets someone by name.
|
|
8
|
-
*
|
|
9
|
-
* Fails with {@link EmptyNameError} when the name is blank
|
|
10
|
-
*/
|
|
11
|
-
export declare const greet: (name: string) => Effect.Effect<string, EmptyNameError, never>;
|
|
12
|
-
export {};
|
|
13
|
-
//# sourceMappingURL=effect.d.mts.map
|
|
1
|
+
import { a as Problem, c as Span, i as LocatedSpan, n as ResolvedConfig, o as ProblemCode, r as ResolvedLayer, s as Path, t as ResolveOptions } from "./index-_5Tr2XH2.mjs";
|
|
2
|
+
export type { LocatedSpan, Path, Problem, ProblemCode, ResolveOptions, ResolvedConfig, ResolvedLayer, Span };
|
package/dist/effect.mjs
CHANGED
|
@@ -1,16 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// src/effect.ts
|
|
3
|
-
var EmptyNameError = class extends Data.TaggedError("EmptyNameError") {};
|
|
4
|
-
/**
|
|
5
|
-
* Greets someone by name.
|
|
6
|
-
*
|
|
7
|
-
* Fails with {@link EmptyNameError} when the name is blank
|
|
8
|
-
*/
|
|
9
|
-
const greet = Effect.fn("greet")(function* (name) {
|
|
10
|
-
const trimmed = name.trim();
|
|
11
|
-
if (trimmed === "") return yield* new EmptyNameError();
|
|
12
|
-
return `Hello, ${trimmed}!`;
|
|
13
|
-
});
|
|
14
|
-
export { EmptyNameError, greet };
|
|
15
|
-
|
|
16
|
-
//# sourceMappingURL=effect.mjs.map
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
/**
|
|
3
|
+
* A key path into a config value. Strings are object keys and numbers are array indices.
|
|
4
|
+
*/
|
|
5
|
+
type Path = readonly (string | number)[];
|
|
6
|
+
/**
|
|
7
|
+
* Where a key and its value sit in the source, in UTF-8 byte offsets.
|
|
8
|
+
*
|
|
9
|
+
* Array elements have no key, so their key span is the same as their value span. The root (`[]`) spans the whole document value.
|
|
10
|
+
*/
|
|
11
|
+
interface Span {
|
|
12
|
+
readonly path: Path;
|
|
13
|
+
readonly keyStart: number;
|
|
14
|
+
readonly keyLength: number;
|
|
15
|
+
readonly valueStart: number;
|
|
16
|
+
readonly valueLength: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Spans keyed by {@link pathKey}.
|
|
20
|
+
*/
|
|
21
|
+
type PositionMap = ReadonlyMap<string, Span>;
|
|
22
|
+
type ProblemCode = 'parse-error' | 'duplicate-key' | 'file-not-found' | 'read-error' | 'unsupported-file' | 'missing-variable' | 'invalid-placeholder' | 'browser-placeholder' | 'unknown-key' | 'type-mismatch';
|
|
23
|
+
/**
|
|
24
|
+
* Something wrong with a config file. `start` and `length` are UTF-8 byte offsets, `line` and `column` are 1-based and
|
|
25
|
+
* `column` counts UTF-16 code units.
|
|
26
|
+
*/
|
|
27
|
+
interface Problem {
|
|
28
|
+
readonly file: string;
|
|
29
|
+
readonly start: number;
|
|
30
|
+
readonly length: number;
|
|
31
|
+
readonly line: number;
|
|
32
|
+
readonly column: number;
|
|
33
|
+
readonly message: string;
|
|
34
|
+
readonly code: ProblemCode;
|
|
35
|
+
}
|
|
36
|
+
type EnvVariables = Readonly<Record<string, string | undefined>>;
|
|
37
|
+
type FormatName = 'yaml' | 'toml' | 'jsonc' | 'json5';
|
|
38
|
+
/**
|
|
39
|
+
* A parsed config file. `value` is `undefined` when the file could not be parsed at all. An empty file is `{}`.
|
|
40
|
+
*/
|
|
41
|
+
interface ParseResult {
|
|
42
|
+
readonly value: unknown;
|
|
43
|
+
readonly positions: PositionMap;
|
|
44
|
+
readonly problems: readonly Problem[];
|
|
45
|
+
}
|
|
46
|
+
interface Format {
|
|
47
|
+
readonly name: FormatName;
|
|
48
|
+
readonly parse: (text: string, file?: string) => ParseResult;
|
|
49
|
+
/**
|
|
50
|
+
* Reads the text a whole-value placeholder resolved to with the format's scalar rules. Returns the text itself when it is not a
|
|
51
|
+
* number, boolean or null.
|
|
52
|
+
*/
|
|
53
|
+
readonly parseScalar: (text: string) => unknown;
|
|
54
|
+
}
|
|
55
|
+
type LayerKind = 'base' | 'environment' | 'local' | 'environment-local';
|
|
56
|
+
/**
|
|
57
|
+
* A {@link Span} together with the file it is in.
|
|
58
|
+
*/
|
|
59
|
+
interface LocatedSpan extends Span {
|
|
60
|
+
readonly file: string;
|
|
61
|
+
}
|
|
62
|
+
interface ResolveOptions {
|
|
63
|
+
/**
|
|
64
|
+
* The real environment variables, which win over every `.env` file. Defaults to a copy of the current ones.
|
|
65
|
+
*/
|
|
66
|
+
readonly env?: EnvVariables | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* The environment name that picks `app.<environment>.config.yaml` and `.env.<environment>`. Defaults to `env.NODE_ENV`.
|
|
69
|
+
*/
|
|
70
|
+
readonly environment?: string | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* The layer kinds to read. Defaults to all of them.
|
|
73
|
+
*/
|
|
74
|
+
readonly layers?: readonly LayerKind[] | undefined;
|
|
75
|
+
}
|
|
76
|
+
interface ResolvedLayer {
|
|
77
|
+
readonly file: string;
|
|
78
|
+
readonly kind: LayerKind;
|
|
79
|
+
readonly text: string;
|
|
80
|
+
/**
|
|
81
|
+
* The parsed value with placeholders resolved, or `undefined` when the file could not be parsed.
|
|
82
|
+
*/
|
|
83
|
+
readonly value: unknown;
|
|
84
|
+
readonly positions: PositionMap;
|
|
85
|
+
}
|
|
86
|
+
interface ResolvedConfig {
|
|
87
|
+
/**
|
|
88
|
+
* The base file, resolved to an absolute path.
|
|
89
|
+
*/
|
|
90
|
+
readonly file: string;
|
|
91
|
+
readonly format: Format | undefined;
|
|
92
|
+
readonly environment: string | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* The merged value, or `undefined` when the base file is missing or could not be parsed.
|
|
95
|
+
*/
|
|
96
|
+
readonly value: unknown;
|
|
97
|
+
readonly layers: readonly ResolvedLayer[];
|
|
98
|
+
readonly envFiles: readonly string[];
|
|
99
|
+
/**
|
|
100
|
+
* Where each key path of `value` came from, keyed by `pathKey`.
|
|
101
|
+
*/
|
|
102
|
+
readonly positions: ReadonlyMap<string, LocatedSpan>;
|
|
103
|
+
readonly problems: readonly Problem[];
|
|
104
|
+
}
|
|
105
|
+
export { Problem as a, Span as c, LocatedSpan as i, ResolvedConfig as n, ProblemCode as o, ResolvedLayer as r, Path as s, ResolveOptions as t };
|
|
106
|
+
//# sourceMappingURL=index-_5Tr2XH2.d.mts.map
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
* Greets someone by name.
|
|
4
|
-
*
|
|
5
|
-
* @param name - The name to greet
|
|
6
|
-
* @returns The greeting, or rejects with {@link EmptyNameError} when the name is blank
|
|
7
|
-
*/
|
|
8
|
-
export declare const greet: (name: string) => Promise<string>;
|
|
9
|
-
export { EmptyNameError };
|
|
10
|
-
//# sourceMappingURL=index.d.mts.map
|
|
1
|
+
import { a as Problem, c as Span, i as LocatedSpan, n as ResolvedConfig, o as ProblemCode, r as ResolvedLayer, s as Path, t as ResolveOptions } from "./index-_5Tr2XH2.mjs";
|
|
2
|
+
export type { LocatedSpan, Path, Problem, ProblemCode, ResolveOptions, ResolvedConfig, ResolvedLayer, Span };
|
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { Effect } from "effect";
|
|
3
|
-
// src/index.ts
|
|
4
|
-
/**
|
|
5
|
-
* Greets someone by name.
|
|
6
|
-
*
|
|
7
|
-
* @param name - The name to greet
|
|
8
|
-
* @returns The greeting, or rejects with {@link EmptyNameError} when the name is blank
|
|
9
|
-
*/
|
|
10
|
-
const greet = (name) => Effect.runPromise(greet$1(name));
|
|
11
|
-
export { EmptyNameError, greet };
|
|
12
|
-
|
|
13
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { a as Problem, s as Path } from "../index-_5Tr2XH2.mjs";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
export type LoadTarget = 'server' | 'browser';
|
|
4
|
+
export interface LoadOptions {
|
|
5
|
+
/**
|
|
6
|
+
* `server` resolves the config when the module runs. `browser` inlines the base and environment files at build time and
|
|
7
|
+
* reports every placeholder as a problem.
|
|
8
|
+
*/
|
|
9
|
+
readonly target: LoadTarget;
|
|
10
|
+
/**
|
|
11
|
+
* The environment name, such as the bundler's mode. Defaults to `NODE_ENV`, read when the server module runs and when
|
|
12
|
+
* `load` runs for the browser.
|
|
13
|
+
*/
|
|
14
|
+
readonly environment?: string | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* The specifier the server module imports the runtime from. Defaults to `tyfigo/runtime`.
|
|
17
|
+
*/
|
|
18
|
+
readonly runtime?: string | undefined;
|
|
19
|
+
}
|
|
20
|
+
export interface LoadResult {
|
|
21
|
+
/**
|
|
22
|
+
* The JavaScript module, with the config as its default export.
|
|
23
|
+
*/
|
|
24
|
+
readonly code: string;
|
|
25
|
+
/**
|
|
26
|
+
* Every file whose creation, change or removal changes the module, whether or not it exists now.
|
|
27
|
+
*/
|
|
28
|
+
readonly watchFiles: readonly string[];
|
|
29
|
+
readonly problems: readonly Problem[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Generates the JavaScript module for a config file import. Loaders fail the import or build when `problems` is not empty.
|
|
33
|
+
*/
|
|
34
|
+
export declare const loadModule: (path: string, options: LoadOptions) => Effect.Effect<{
|
|
35
|
+
code: string;
|
|
36
|
+
watchFiles: string[];
|
|
37
|
+
problems: Problem[];
|
|
38
|
+
}, never, never>;
|
|
39
|
+
/**
|
|
40
|
+
* {@link loadModule} for synchronous callers such as Node `registerHooks` load hooks.
|
|
41
|
+
*/
|
|
42
|
+
export declare const load: (path: string, options: LoadOptions) => LoadResult;
|
|
43
|
+
/**
|
|
44
|
+
* The key of the non-enumerable {@link ConfigSource} on a config object exported by a generated server module.
|
|
45
|
+
*/
|
|
46
|
+
export declare const configSource: unique symbol;
|
|
47
|
+
export interface SourcePosition {
|
|
48
|
+
readonly file: string;
|
|
49
|
+
readonly line: number;
|
|
50
|
+
readonly column: number;
|
|
51
|
+
}
|
|
52
|
+
export interface ConfigSource {
|
|
53
|
+
/**
|
|
54
|
+
* The base config file, as an absolute path.
|
|
55
|
+
*/
|
|
56
|
+
readonly file: string;
|
|
57
|
+
readonly environment: string | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* The layer files that were merged, in the order they apply.
|
|
60
|
+
*/
|
|
61
|
+
readonly layers: readonly string[];
|
|
62
|
+
/**
|
|
63
|
+
* The `.env` files that were read, in the order they apply.
|
|
64
|
+
*/
|
|
65
|
+
readonly envFiles: readonly string[];
|
|
66
|
+
/**
|
|
67
|
+
* Where the value at `path` was set. A path the config does not have resolves to its nearest ancestor that it does have.
|
|
68
|
+
*/
|
|
69
|
+
readonly position: (path: Path) => SourcePosition | undefined;
|
|
70
|
+
}
|
|
71
|
+
declare const ConfigModuleError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
72
|
+
readonly _tag: "ConfigModuleError";
|
|
73
|
+
} & Readonly<A>;
|
|
74
|
+
export declare class ConfigModuleError extends ConfigModuleError_base<{
|
|
75
|
+
readonly message: string;
|
|
76
|
+
readonly file: string;
|
|
77
|
+
readonly problems: readonly Problem[];
|
|
78
|
+
}> {}
|
|
79
|
+
export interface ConfigModuleOptions {
|
|
80
|
+
/**
|
|
81
|
+
* The environment name that picks `app.<environment>.config.yaml` and `.env.<environment>`. Defaults to `NODE_ENV`.
|
|
82
|
+
*/
|
|
83
|
+
readonly environment?: string | undefined;
|
|
84
|
+
}
|
|
85
|
+
export declare const deepFreeze: <T>(value: T) => T;
|
|
86
|
+
export declare const getConfigSource: (value: unknown) => ConfigSource | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* Resolves a config file with its layers, `.env` files and placeholders, and returns the deep-frozen value. This is what a
|
|
89
|
+
* generated server module calls when it is evaluated. Throws a {@link ConfigModuleError} listing every problem.
|
|
90
|
+
*/
|
|
91
|
+
export declare const resolveConfigModule: (file: string, options?: ConfigModuleOptions) => unknown;
|
|
92
|
+
export {};
|
|
93
|
+
//# sourceMappingURL=index.d.mts.map
|