@effected/toml 0.10.0 → 0.11.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.
- package/README.md +4 -4
- package/Toml.js +11 -1
- package/TomlDiagnostic.js +5 -1
- package/TomlDocument.js +4 -0
- package/TomlEdit.js +7 -3
- package/TomlFormat.js +50 -2
- package/TomlVisitor.js +15 -1
- package/index.d.ts +94 -8
- package/internal/parser.js +1 -1
- package/internal/scanner.js +2 -2
- package/internal/semantic.js +6 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
|
|
8
8
|
Zero-dependency TOML 1.1.0 parsing, editing and formatting expressed as Effect schemas and pure functions. Parse TOML into plain values or a byte-exact linear CST, compute comment-preserving edits, format, modify by path, walk a document as a `Stream`, and decode straight into a validated domain schema.
|
|
9
9
|
|
|
10
|
-
> **Pre
|
|
11
|
-
>
|
|
12
|
-
> `1.0.0`
|
|
13
|
-
>
|
|
10
|
+
> **Pre-`1.0.0`.** This package is part of the `@effected/*` kit, built on stable
|
|
11
|
+
> Effect v4 (`effect` `^4.0.0`) and still in `0.x` development. Stable Effect
|
|
12
|
+
> makes a kit `1.0.0` possible, not automatic. To keep your `effect` and
|
|
13
|
+
> `@effect/*` versions on the line the kit is built and tested against, install
|
|
14
14
|
> [`@effected/pnpm-plugin-effect`](https://www.npmjs.com/package/@effected/pnpm-plugin-effect).
|
|
15
15
|
>
|
|
16
16
|
> **Stability: unstable.** This package's API surface is not yet considered
|
package/Toml.js
CHANGED
|
@@ -27,13 +27,20 @@ var TomlStringifyOptions = class extends Schema.Class("TomlStringifyOptions")({
|
|
|
27
27
|
* array shape matches `@effected/yaml`'s aggregate contract). Raised by
|
|
28
28
|
* {@link Toml.parse} and the decode direction of the schema factories.
|
|
29
29
|
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* The `message` renders the first diagnostic's position 1-based
|
|
32
|
+
* (`line + 1:character + 1`) for human readers — a CLI printing this string
|
|
33
|
+
* shows the line/column a person counts in their editor. The structured
|
|
34
|
+
* {@link TomlDiagnostic} `line`/`character` fields stay 0-based (LSP
|
|
35
|
+
* convention); the offset applies to the rendered message only.
|
|
36
|
+
*
|
|
30
37
|
* @public
|
|
31
38
|
*/
|
|
32
39
|
var TomlParseError = class extends Schema.TaggedError()("TomlParseError", { diagnostics: Schema.Array(TomlDiagnostic) }) {
|
|
33
40
|
get message() {
|
|
34
41
|
const count = this.diagnostics.length;
|
|
35
42
|
const first = this.diagnostics[0];
|
|
36
|
-
const detail = first === void 0 ? "" : `: ${first.code} at ${first.line}:${first.character} ${first.message}`;
|
|
43
|
+
const detail = first === void 0 ? "" : `: ${first.code} at ${first.line + 1}:${first.character + 1} ${first.message}`;
|
|
37
44
|
return `TOML parse failed with ${count} error${count === 1 ? "" : "s"}${detail}`;
|
|
38
45
|
}
|
|
39
46
|
};
|
|
@@ -244,6 +251,9 @@ var Toml = class Toml {
|
|
|
244
251
|
*
|
|
245
252
|
* Schema-producing: bind the result to a `const` on hot paths (see
|
|
246
253
|
* {@link Toml.fromString}).
|
|
254
|
+
*
|
|
255
|
+
* @param target - The domain schema decoded values must satisfy.
|
|
256
|
+
* @returns A `Schema.Codec<T, string>` decoding TOML text straight into `T`.
|
|
247
257
|
*/
|
|
248
258
|
static schema(target) {
|
|
249
259
|
return Toml.TomlFromString.pipe(Schema.decodeTo(target));
|
package/TomlDiagnostic.js
CHANGED
|
@@ -61,8 +61,12 @@ var TomlDiagnostic = class TomlDiagnostic extends Schema.Class("TomlDiagnostic")
|
|
|
61
61
|
}) {
|
|
62
62
|
/**
|
|
63
63
|
* Materialize an engine record, deriving `line`/`character` (0-based)
|
|
64
|
-
* from `offset` against the source
|
|
64
|
+
* from `offset` against the source text. Advanced — the parse/stringify
|
|
65
65
|
* entry points call this for you.
|
|
66
|
+
*
|
|
67
|
+
* @param source - The source text the record's `offset` indexes into.
|
|
68
|
+
* @param raw - The engine record: `code`, `message`, `offset` and `length`.
|
|
69
|
+
* @returns The diagnostic with `line` and `character` filled in.
|
|
66
70
|
*/
|
|
67
71
|
static fromRaw(source, raw) {
|
|
68
72
|
const { line, character } = lineChar(source, raw.offset);
|
package/TomlDocument.js
CHANGED
|
@@ -68,6 +68,10 @@ var TomlDocument = class TomlDocument extends Schema.Class("TomlDocument")({
|
|
|
68
68
|
* diagnostic, never an unhandled defect. Semantic violations do not fail:
|
|
69
69
|
* they land in `diagnostics` as data (first violation wins, so there is at
|
|
70
70
|
* most one today; the array shape is the contract).
|
|
71
|
+
*
|
|
72
|
+
* @param text - The TOML source to parse.
|
|
73
|
+
* @returns An `Effect` that succeeds with the {@link TomlDocument}, or fails
|
|
74
|
+
* with {@link TomlParseError}.
|
|
71
75
|
*/
|
|
72
76
|
static parse = Effect.fn("TomlDocument.parse")(function* (text) {
|
|
73
77
|
const expressions = yield* Effect.try({
|
package/TomlEdit.js
CHANGED
|
@@ -17,9 +17,9 @@ var TomlRange = class extends Schema.Class("TomlRange")({
|
|
|
17
17
|
* `content`. Set `length` to `0` to insert, `content` to `""` to delete.
|
|
18
18
|
*
|
|
19
19
|
* @remarks
|
|
20
|
-
* Structurally identical to
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
* Structurally identical to the edit shapes of `@effected/jsonc`,
|
|
21
|
+
* `@effected/yaml` and `@effected/markdown` (same field names, types and
|
|
22
|
+
* semantics), so consumer code can be written once over "a document codec's
|
|
23
23
|
* Edit/Range/Path".
|
|
24
24
|
*
|
|
25
25
|
* @public
|
|
@@ -34,6 +34,10 @@ var TomlEdit = class extends Schema.Class("TomlEdit")({
|
|
|
34
34
|
* reverse-offset order so earlier offsets stay valid; the input `edits`
|
|
35
35
|
* array is not mutated. Overlapping edits are a programmer error and throw
|
|
36
36
|
* as a defect — `TomlFormat` never produces them.
|
|
37
|
+
*
|
|
38
|
+
* @param text - The source text to edit.
|
|
39
|
+
* @param edits - The edits to apply, in any order.
|
|
40
|
+
* @returns The edited text.
|
|
37
41
|
*/
|
|
38
42
|
static applyAll(text, edits) {
|
|
39
43
|
const sorted = [...edits].sort((a, b) => b.offset - a.offset);
|
package/TomlFormat.js
CHANGED
|
@@ -508,7 +508,22 @@ const terminal = (cur, segment, value, ctx) => {
|
|
|
508
508
|
return failResolve("DottedKeyConflict", "cannot address a key beneath a scalar value", node.offset, node.length);
|
|
509
509
|
};
|
|
510
510
|
/**
|
|
511
|
-
*
|
|
511
|
+
* Formats TOML text and modifies values at a path as byte-minimal edits that
|
|
512
|
+
* leave comments and layout elsewhere untouched. Not instantiable.
|
|
513
|
+
*
|
|
514
|
+
* @example
|
|
515
|
+
* ```ts
|
|
516
|
+
* import { TomlFormat } from "@effected/toml";
|
|
517
|
+
* import { Effect } from "effect";
|
|
518
|
+
*
|
|
519
|
+
* const formatted = TomlFormat.formatToString(' title="x" #note\n[server]\nport=1');
|
|
520
|
+
* // => 'title = "x" # note\n[server]\nport = 1\n'
|
|
521
|
+
*
|
|
522
|
+
* const program = Effect.gen(function* () {
|
|
523
|
+
* return yield* TomlFormat.modifyToString("[server]\nport = 1 # dev\n", ["server", "port"], 2);
|
|
524
|
+
* // => "[server]\nport = 2 # dev\n"
|
|
525
|
+
* });
|
|
526
|
+
* ```
|
|
512
527
|
*
|
|
513
528
|
* @remarks
|
|
514
529
|
* `format`/`formatToString` are pure and total: malformed input yields no
|
|
@@ -532,7 +547,14 @@ var TomlFormat = class TomlFormat {
|
|
|
532
547
|
* strings. Nothing else: no reordering, no blank-line collapsing, no value
|
|
533
548
|
* rewriting. `range` restricts edits to the expressions intersecting it.
|
|
534
549
|
* Non-mutating — apply with `TomlEdit.applyAll` (or use
|
|
535
|
-
* {@link TomlFormat.formatToString}).
|
|
550
|
+
* {@link TomlFormat.formatToString}). Pure and total.
|
|
551
|
+
*
|
|
552
|
+
* @param text - The TOML source to format.
|
|
553
|
+
* @param range - Optional sub-range; only edits whose expression intersects
|
|
554
|
+
* it are returned.
|
|
555
|
+
* @param options - Optional {@link TomlFormattingOptions}.
|
|
556
|
+
* @returns The edits that bring `text` (or `range`) to canonical shape;
|
|
557
|
+
* apply them with `TomlEdit.applyAll`.
|
|
536
558
|
*/
|
|
537
559
|
static format(text, range, options) {
|
|
538
560
|
const tagged = computeFormatEdits(text, options);
|
|
@@ -545,6 +567,12 @@ var TomlFormat = class TomlFormat {
|
|
|
545
567
|
/**
|
|
546
568
|
* Format `text` and apply the resulting edits in one step
|
|
547
569
|
* (`TomlEdit.applyAll ∘ format`). Pure and total.
|
|
570
|
+
*
|
|
571
|
+
* @param text - The TOML source to format.
|
|
572
|
+
* @param range - Optional sub-range; only edits whose expression intersects
|
|
573
|
+
* it are applied.
|
|
574
|
+
* @param options - Optional {@link TomlFormattingOptions}.
|
|
575
|
+
* @returns The formatted text.
|
|
548
576
|
*/
|
|
549
577
|
static formatToString(text, range, options) {
|
|
550
578
|
return TomlEdit.applyAll(text, TomlFormat.format(text, range, options));
|
|
@@ -561,6 +589,17 @@ var TomlFormat = class TomlFormat {
|
|
|
561
589
|
* section; inline and implicitly created tables refuse. Inserted lines
|
|
562
590
|
* inherit the document's dominant newline unless `options.newline`
|
|
563
591
|
* overrides it. Every modified document reparses cleanly.
|
|
592
|
+
*
|
|
593
|
+
* @param text - The TOML source to modify.
|
|
594
|
+
* @param path - The location to set, replace or delete.
|
|
595
|
+
* @param value - The plain JavaScript value to write; `undefined` deletes the
|
|
596
|
+
* target instead.
|
|
597
|
+
* @param options - Optional {@link TomlFormattingOptions}; `newline` overrides
|
|
598
|
+
* the newline used for inserted lines.
|
|
599
|
+
* @returns An `Effect` that succeeds with the edits to apply (via
|
|
600
|
+
* `TomlEdit.applyAll`), or fails with {@link TomlParseError} when the
|
|
601
|
+
* source does not parse, or {@link TomlModificationError} when `path`
|
|
602
|
+
* cannot be resolved or the insertion target is not allowed.
|
|
564
603
|
*/
|
|
565
604
|
static modify = Effect.fn("TomlFormat.modify")(function* (text, path, value, options) {
|
|
566
605
|
const failWith = (code, message, offset = 0, length = 0) => new TomlModificationError({ diagnostic: TomlDiagnostic.fromRaw(text, {
|
|
@@ -602,6 +641,15 @@ var TomlFormat = class TomlFormat {
|
|
|
602
641
|
/**
|
|
603
642
|
* Modify `text` and apply the resulting edits in one step
|
|
604
643
|
* (`TomlEdit.applyAll ∘ modify`).
|
|
644
|
+
*
|
|
645
|
+
* @param text - The TOML source to modify.
|
|
646
|
+
* @param path - The location to set, replace or delete.
|
|
647
|
+
* @param value - The plain JavaScript value to write; `undefined` deletes the
|
|
648
|
+
* target instead.
|
|
649
|
+
* @param options - Optional {@link TomlFormattingOptions}.
|
|
650
|
+
* @returns An `Effect` that succeeds with the modified text, or fails with
|
|
651
|
+
* {@link TomlParseError} or {@link TomlModificationError}, as
|
|
652
|
+
* {@link TomlFormat.modify} does.
|
|
605
653
|
*/
|
|
606
654
|
static modifyToString = Effect.fn("TomlFormat.modifyToString")(function* (text, path, value, options) {
|
|
607
655
|
const edits = yield* TomlFormat.modify(text, path, value, options);
|
package/TomlVisitor.js
CHANGED
|
@@ -125,7 +125,21 @@ const collectEventsOrFail = (text) => Effect.try({
|
|
|
125
125
|
}
|
|
126
126
|
});
|
|
127
127
|
/**
|
|
128
|
-
*
|
|
128
|
+
* Walks TOML text as a `Stream` of table, array-table, key-value and comment
|
|
129
|
+
* events in document order, without building a value. Not instantiable.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* import { TomlVisitor, TomlVisitorEvent } from "@effected/toml";
|
|
134
|
+
* import { Effect, Stream } from "effect";
|
|
135
|
+
*
|
|
136
|
+
* const keys = TomlVisitor.visit("[server]\nport = 1\n").pipe(
|
|
137
|
+
* Stream.filter(TomlVisitorEvent.$is("KeyValue")),
|
|
138
|
+
* Stream.map((event) => event.path.join(".")),
|
|
139
|
+
* Stream.runCollect,
|
|
140
|
+
* );
|
|
141
|
+
* // Effect.runSync(keys) // => ["server.port"]
|
|
142
|
+
* ```
|
|
129
143
|
*
|
|
130
144
|
* @public
|
|
131
145
|
*/
|
package/index.d.ts
CHANGED
|
@@ -85,8 +85,12 @@ declare const TomlDiagnostic_base: Schema.Class<TomlDiagnostic, Schema.Struct<{
|
|
|
85
85
|
export declare class TomlDiagnostic extends TomlDiagnostic_base {
|
|
86
86
|
/**
|
|
87
87
|
* Materialize an engine record, deriving `line`/`character` (0-based)
|
|
88
|
-
* from `offset` against the source
|
|
88
|
+
* from `offset` against the source text. Advanced — the parse/stringify
|
|
89
89
|
* entry points call this for you.
|
|
90
|
+
*
|
|
91
|
+
* @param source - The source text the record's `offset` indexes into.
|
|
92
|
+
* @param raw - The engine record: `code`, `message`, `offset` and `length`.
|
|
93
|
+
* @returns The diagnostic with `line` and `character` filled in.
|
|
90
94
|
*/
|
|
91
95
|
static fromRaw(source: string, raw: {
|
|
92
96
|
readonly code: TomlErrorCode;
|
|
@@ -123,6 +127,13 @@ declare const TomlParseError_base: Schema.Class<TomlParseError, Schema.TaggedStr
|
|
|
123
127
|
* array shape matches `@effected/yaml`'s aggregate contract). Raised by
|
|
124
128
|
* {@link Toml.parse} and the decode direction of the schema factories.
|
|
125
129
|
*
|
|
130
|
+
* @remarks
|
|
131
|
+
* The `message` renders the first diagnostic's position 1-based
|
|
132
|
+
* (`line + 1:character + 1`) for human readers — a CLI printing this string
|
|
133
|
+
* shows the line/column a person counts in their editor. The structured
|
|
134
|
+
* {@link TomlDiagnostic} `line`/`character` fields stay 0-based (LSP
|
|
135
|
+
* convention); the offset applies to the rendered message only.
|
|
136
|
+
*
|
|
126
137
|
* @public
|
|
127
138
|
*/
|
|
128
139
|
export declare class TomlParseError extends TomlParseError_base {
|
|
@@ -307,6 +318,9 @@ export declare class Toml {
|
|
|
307
318
|
*
|
|
308
319
|
* Schema-producing: bind the result to a `const` on hot paths (see
|
|
309
320
|
* {@link Toml.fromString}).
|
|
321
|
+
*
|
|
322
|
+
* @param target - The domain schema decoded values must satisfy.
|
|
323
|
+
* @returns A `Schema.Codec<T, string>` decoding TOML text straight into `T`.
|
|
310
324
|
*/
|
|
311
325
|
static schema<T, E, RD = never, RE = never>(target: Schema.Codec<T, E, RD, RE>): Schema.Codec<T, string, RD, RE>;
|
|
312
326
|
/**
|
|
@@ -680,6 +694,10 @@ export declare class TomlDocument extends TomlDocument_base {
|
|
|
680
694
|
* diagnostic, never an unhandled defect. Semantic violations do not fail:
|
|
681
695
|
* they land in `diagnostics` as data (first violation wins, so there is at
|
|
682
696
|
* most one today; the array shape is the contract).
|
|
697
|
+
*
|
|
698
|
+
* @param text - The TOML source to parse.
|
|
699
|
+
* @returns An `Effect` that succeeds with the {@link TomlDocument}, or fails
|
|
700
|
+
* with {@link TomlParseError}.
|
|
683
701
|
*/
|
|
684
702
|
static readonly parse: (text: string) => Effect.Effect<TomlDocument, TomlParseError, never>;
|
|
685
703
|
/**
|
|
@@ -746,9 +764,9 @@ declare const TomlEdit_base: Schema.Class<TomlEdit, Schema.Struct<{
|
|
|
746
764
|
* `content`. Set `length` to `0` to insert, `content` to `""` to delete.
|
|
747
765
|
*
|
|
748
766
|
* @remarks
|
|
749
|
-
* Structurally identical to
|
|
750
|
-
*
|
|
751
|
-
*
|
|
767
|
+
* Structurally identical to the edit shapes of `@effected/jsonc`,
|
|
768
|
+
* `@effected/yaml` and `@effected/markdown` (same field names, types and
|
|
769
|
+
* semantics), so consumer code can be written once over "a document codec's
|
|
752
770
|
* Edit/Range/Path".
|
|
753
771
|
*
|
|
754
772
|
* @public
|
|
@@ -759,6 +777,10 @@ export declare class TomlEdit extends TomlEdit_base {
|
|
|
759
777
|
* reverse-offset order so earlier offsets stay valid; the input `edits`
|
|
760
778
|
* array is not mutated. Overlapping edits are a programmer error and throw
|
|
761
779
|
* as a defect — `TomlFormat` never produces them.
|
|
780
|
+
*
|
|
781
|
+
* @param text - The source text to edit.
|
|
782
|
+
* @param edits - The edits to apply, in any order.
|
|
783
|
+
* @returns The edited text.
|
|
762
784
|
*/
|
|
763
785
|
static applyAll(text: string, edits: ReadonlyArray<TomlEdit>): string;
|
|
764
786
|
}
|
|
@@ -803,7 +825,22 @@ export declare class TomlModificationError extends TomlModificationError_base {
|
|
|
803
825
|
get message(): string;
|
|
804
826
|
}
|
|
805
827
|
/**
|
|
806
|
-
*
|
|
828
|
+
* Formats TOML text and modifies values at a path as byte-minimal edits that
|
|
829
|
+
* leave comments and layout elsewhere untouched. Not instantiable.
|
|
830
|
+
*
|
|
831
|
+
* @example
|
|
832
|
+
* ```ts
|
|
833
|
+
* import { TomlFormat } from "@effected/toml";
|
|
834
|
+
* import { Effect } from "effect";
|
|
835
|
+
*
|
|
836
|
+
* const formatted = TomlFormat.formatToString(' title="x" #note\n[server]\nport=1');
|
|
837
|
+
* // => 'title = "x" # note\n[server]\nport = 1\n'
|
|
838
|
+
*
|
|
839
|
+
* const program = Effect.gen(function* () {
|
|
840
|
+
* return yield* TomlFormat.modifyToString("[server]\nport = 1 # dev\n", ["server", "port"], 2);
|
|
841
|
+
* // => "[server]\nport = 2 # dev\n"
|
|
842
|
+
* });
|
|
843
|
+
* ```
|
|
807
844
|
*
|
|
808
845
|
* @remarks
|
|
809
846
|
* `format`/`formatToString` are pure and total: malformed input yields no
|
|
@@ -827,12 +864,25 @@ export declare class TomlFormat {
|
|
|
827
864
|
* strings. Nothing else: no reordering, no blank-line collapsing, no value
|
|
828
865
|
* rewriting. `range` restricts edits to the expressions intersecting it.
|
|
829
866
|
* Non-mutating — apply with `TomlEdit.applyAll` (or use
|
|
830
|
-
* {@link TomlFormat.formatToString}).
|
|
867
|
+
* {@link TomlFormat.formatToString}). Pure and total.
|
|
868
|
+
*
|
|
869
|
+
* @param text - The TOML source to format.
|
|
870
|
+
* @param range - Optional sub-range; only edits whose expression intersects
|
|
871
|
+
* it are returned.
|
|
872
|
+
* @param options - Optional {@link TomlFormattingOptions}.
|
|
873
|
+
* @returns The edits that bring `text` (or `range`) to canonical shape;
|
|
874
|
+
* apply them with `TomlEdit.applyAll`.
|
|
831
875
|
*/
|
|
832
876
|
static format(text: string, range?: TomlRangeLike, options?: TomlFormattingOptions): ReadonlyArray<TomlEdit>;
|
|
833
877
|
/**
|
|
834
878
|
* Format `text` and apply the resulting edits in one step
|
|
835
879
|
* (`TomlEdit.applyAll ∘ format`). Pure and total.
|
|
880
|
+
*
|
|
881
|
+
* @param text - The TOML source to format.
|
|
882
|
+
* @param range - Optional sub-range; only edits whose expression intersects
|
|
883
|
+
* it are applied.
|
|
884
|
+
* @param options - Optional {@link TomlFormattingOptions}.
|
|
885
|
+
* @returns The formatted text.
|
|
836
886
|
*/
|
|
837
887
|
static formatToString(text: string, range?: TomlRangeLike, options?: TomlFormattingOptions): string;
|
|
838
888
|
/**
|
|
@@ -847,11 +897,31 @@ export declare class TomlFormat {
|
|
|
847
897
|
* section; inline and implicitly created tables refuse. Inserted lines
|
|
848
898
|
* inherit the document's dominant newline unless `options.newline`
|
|
849
899
|
* overrides it. Every modified document reparses cleanly.
|
|
900
|
+
*
|
|
901
|
+
* @param text - The TOML source to modify.
|
|
902
|
+
* @param path - The location to set, replace or delete.
|
|
903
|
+
* @param value - The plain JavaScript value to write; `undefined` deletes the
|
|
904
|
+
* target instead.
|
|
905
|
+
* @param options - Optional {@link TomlFormattingOptions}; `newline` overrides
|
|
906
|
+
* the newline used for inserted lines.
|
|
907
|
+
* @returns An `Effect` that succeeds with the edits to apply (via
|
|
908
|
+
* `TomlEdit.applyAll`), or fails with {@link TomlParseError} when the
|
|
909
|
+
* source does not parse, or {@link TomlModificationError} when `path`
|
|
910
|
+
* cannot be resolved or the insertion target is not allowed.
|
|
850
911
|
*/
|
|
851
912
|
static readonly modify: (text: string, path: TomlPath, value: unknown, options?: TomlFormattingOptions | undefined) => Effect.Effect<readonly TomlEdit[], TomlModificationError | TomlParseError, never>;
|
|
852
913
|
/**
|
|
853
914
|
* Modify `text` and apply the resulting edits in one step
|
|
854
915
|
* (`TomlEdit.applyAll ∘ modify`).
|
|
916
|
+
*
|
|
917
|
+
* @param text - The TOML source to modify.
|
|
918
|
+
* @param path - The location to set, replace or delete.
|
|
919
|
+
* @param value - The plain JavaScript value to write; `undefined` deletes the
|
|
920
|
+
* target instead.
|
|
921
|
+
* @param options - Optional {@link TomlFormattingOptions}.
|
|
922
|
+
* @returns An `Effect` that succeeds with the modified text, or fails with
|
|
923
|
+
* {@link TomlParseError} or {@link TomlModificationError}, as
|
|
924
|
+
* {@link TomlFormat.modify} does.
|
|
855
925
|
*/
|
|
856
926
|
static readonly modifyToString: (text: string, path: TomlPath, value: unknown, options?: TomlFormattingOptions | undefined) => Effect.Effect<string, TomlModificationError | TomlParseError, never>;
|
|
857
927
|
}
|
|
@@ -863,7 +933,9 @@ export declare class TomlFormat {
|
|
|
863
933
|
* event, then again for every `[table]` header. `ArrayTableStart` fires for
|
|
864
934
|
* every `[[array]]` header with the 0-based element `index`. `KeyValue.path`
|
|
865
935
|
* includes the final key. `Comment` covers both standalone (trivia) and
|
|
866
|
-
* trailing comments
|
|
936
|
+
* trailing comments: `offset` is the source position of the comment's `#`
|
|
937
|
+
* marker, and `text` is the comment after the `#` with one leading space
|
|
938
|
+
* removed.
|
|
867
939
|
*
|
|
868
940
|
* @public
|
|
869
941
|
*/
|
|
@@ -1010,7 +1082,21 @@ export declare const TomlVisitorEvent: {
|
|
|
1010
1082
|
}, "_tag">;
|
|
1011
1083
|
};
|
|
1012
1084
|
/**
|
|
1013
|
-
*
|
|
1085
|
+
* Walks TOML text as a `Stream` of table, array-table, key-value and comment
|
|
1086
|
+
* events in document order, without building a value. Not instantiable.
|
|
1087
|
+
*
|
|
1088
|
+
* @example
|
|
1089
|
+
* ```ts
|
|
1090
|
+
* import { TomlVisitor, TomlVisitorEvent } from "@effected/toml";
|
|
1091
|
+
* import { Effect, Stream } from "effect";
|
|
1092
|
+
*
|
|
1093
|
+
* const keys = TomlVisitor.visit("[server]\nport = 1\n").pipe(
|
|
1094
|
+
* Stream.filter(TomlVisitorEvent.$is("KeyValue")),
|
|
1095
|
+
* Stream.map((event) => event.path.join(".")),
|
|
1096
|
+
* Stream.runCollect,
|
|
1097
|
+
* );
|
|
1098
|
+
* // Effect.runSync(keys) // => ["server.port"]
|
|
1099
|
+
* ```
|
|
1014
1100
|
*
|
|
1015
1101
|
* @public
|
|
1016
1102
|
*/
|
package/internal/parser.js
CHANGED
|
@@ -363,7 +363,7 @@ const parseHeaderExpression = (source, lineStart, bracketPos) => {
|
|
|
363
363
|
/**
|
|
364
364
|
* Parse a TOML document into its linear CST: the flat, source-tiling list of
|
|
365
365
|
* expressions. Throws RawTomlError on malformed input and GuardExceeded when
|
|
366
|
-
* value nesting exceeds MAX_NESTING_DEPTH; the facade
|
|
366
|
+
* value nesting exceeds MAX_NESTING_DEPTH; the facade materializes
|
|
367
367
|
* both into typed errors.
|
|
368
368
|
*/
|
|
369
369
|
const parseExpressions = (source) => {
|
package/internal/scanner.js
CHANGED
|
@@ -339,7 +339,7 @@ const LOCAL_DATE = /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/;
|
|
|
339
339
|
const LOCAL_TIME = /^([0-9]{2}):([0-9]{2})(?::([0-9]{2})(?:\.([0-9]+))?)?$/;
|
|
340
340
|
/**
|
|
341
341
|
* Scan a non-string scalar value token. Stops at whitespace, newlines, `,`,
|
|
342
|
-
* `]`, `}` and `#` — with
|
|
342
|
+
* `]`, `}` and `#` — with one extension: a token that scanned as a full
|
|
343
343
|
* date followed by a single space and a digit continues through the time
|
|
344
344
|
* part, so `1979-05-27 07:32:00Z` is one token.
|
|
345
345
|
*/
|
|
@@ -412,7 +412,7 @@ const decodeOffsetMinutes = (text, offset, length) => {
|
|
|
412
412
|
return text.charCodeAt(0) === HYPHEN ? -total : total;
|
|
413
413
|
};
|
|
414
414
|
/**
|
|
415
|
-
* Classify a scanned value token
|
|
415
|
+
* Classify a scanned value token: booleans, the four datetime
|
|
416
416
|
* shapes (validated against the Gregorian calendar and clock ranges before
|
|
417
417
|
* construction), integers across four radixes with int64 range checking and
|
|
418
418
|
* number/bigint narrowing, and floats including the special spellings.
|
package/internal/semantic.js
CHANGED
|
@@ -17,7 +17,7 @@ const raise = (code, message, key) => {
|
|
|
17
17
|
});
|
|
18
18
|
};
|
|
19
19
|
/**
|
|
20
|
-
* Header navigation (
|
|
20
|
+
* Header navigation (rules 1 and 2, shared prefix): walk every segment but
|
|
21
21
|
* the last, creating `table-implicit` for absent names, passing through
|
|
22
22
|
* tables (dotted included — the corpus deviation) and descending into the
|
|
23
23
|
* last element of an array of tables.
|
|
@@ -49,7 +49,7 @@ const navigateHeaderPrefix = (root, keyPath) => {
|
|
|
49
49
|
}
|
|
50
50
|
return current;
|
|
51
51
|
};
|
|
52
|
-
/**
|
|
52
|
+
/** Rule 1, final segment: create `table-explicit`, promote `table-implicit`, or error. */
|
|
53
53
|
const openTable = (root, keyPath) => {
|
|
54
54
|
const parent = navigateHeaderPrefix(root, keyPath);
|
|
55
55
|
const key = keyPath[keyPath.length - 1];
|
|
@@ -65,7 +65,7 @@ const openTable = (root, keyPath) => {
|
|
|
65
65
|
}
|
|
66
66
|
return raise("TableRedefined", `table "${key.value}" is already defined`, key);
|
|
67
67
|
};
|
|
68
|
-
/**
|
|
68
|
+
/** Rule 2, final segment: create the array and its first element, append to an existing one, or error. */
|
|
69
69
|
const openArrayTable = (root, keyPath) => {
|
|
70
70
|
const parent = navigateHeaderPrefix(root, keyPath);
|
|
71
71
|
const key = keyPath[keyPath.length - 1];
|
|
@@ -91,7 +91,7 @@ const openArrayTable = (root, keyPath) => {
|
|
|
91
91
|
return raise("ArrayOfTablesConflict", `"${key.value}" cannot be redefined as an array of tables`, key);
|
|
92
92
|
};
|
|
93
93
|
/**
|
|
94
|
-
*
|
|
94
|
+
* Rule 3: a (possibly dotted) key assignment scoped to `table` under
|
|
95
95
|
* `sectionId`. Intermediates must be absent (create `table-dotted`) or
|
|
96
96
|
* `table-dotted` from the same section; the final key must be absent.
|
|
97
97
|
*/
|
|
@@ -135,7 +135,7 @@ const checkArrayItem = (item, context) => {
|
|
|
135
135
|
if (item instanceof TomlArray) for (const inner of item.items) checkArrayItem(inner, context);
|
|
136
136
|
};
|
|
137
137
|
/**
|
|
138
|
-
*
|
|
138
|
+
* Rule 4: build an inline table's own scope (dotted keys follow rule 3
|
|
139
139
|
* inside it), then freeze it — the returned node's `inline` kind makes every
|
|
140
140
|
* later navigation through it an `InlineTableExtended` error.
|
|
141
141
|
*/
|
|
@@ -147,7 +147,7 @@ const inlineNode = (node, context) => {
|
|
|
147
147
|
return sem;
|
|
148
148
|
};
|
|
149
149
|
/**
|
|
150
|
-
* Walk the expressions through the
|
|
150
|
+
* Walk the expressions through the provenance state machine, firing the visitor after
|
|
151
151
|
* each expression validates; throws `RawTomlError` at the first violation.
|
|
152
152
|
*/
|
|
153
153
|
const analyze = (expressions, visitor) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effected/toml",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "TOML 1.1.0 parsing, editing and formatting as Effect schemas: typed diagnostics, a lossless CST and first-class date-time values.",
|
|
6
6
|
"keywords": [
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"./package.json": "./package.json"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"effect": "4.0.0
|
|
41
|
+
"effect": "^4.0.0"
|
|
42
42
|
},
|
|
43
43
|
"engines": {
|
|
44
44
|
"node": ">=24.11.0"
|