@effected/toml 0.3.1 → 0.4.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/Toml.js +5 -5
- package/TomlDocument.js +2 -2
- package/TomlFormat.js +5 -3
- package/package.json +2 -2
package/Toml.js
CHANGED
|
@@ -4,7 +4,7 @@ import { parseExpressions } from "./internal/parser.js";
|
|
|
4
4
|
import { buildValue } from "./internal/semantic.js";
|
|
5
5
|
import { stringifyValue } from "./internal/stringifyValue.js";
|
|
6
6
|
import { TomlDiagnostic } from "./TomlDiagnostic.js";
|
|
7
|
-
import { Effect,
|
|
7
|
+
import { Effect, Result, Schema, SchemaIssue, SchemaTransformation } from "effect";
|
|
8
8
|
|
|
9
9
|
//#region src/Toml.ts
|
|
10
10
|
/**
|
|
@@ -29,7 +29,7 @@ var TomlStringifyOptions = class extends Schema.Class("TomlStringifyOptions")({
|
|
|
29
29
|
*
|
|
30
30
|
* @public
|
|
31
31
|
*/
|
|
32
|
-
var TomlParseError = class extends Schema.
|
|
32
|
+
var TomlParseError = class extends Schema.TaggedError()("TomlParseError", { diagnostics: Schema.Array(TomlDiagnostic) }) {
|
|
33
33
|
get message() {
|
|
34
34
|
const count = this.diagnostics.length;
|
|
35
35
|
const first = this.diagnostics[0];
|
|
@@ -45,7 +45,7 @@ var TomlParseError = class extends Schema.TaggedErrorClass()("TomlParseError", {
|
|
|
45
45
|
*
|
|
46
46
|
* @public
|
|
47
47
|
*/
|
|
48
|
-
var TomlStringifyError = class extends Schema.
|
|
48
|
+
var TomlStringifyError = class extends Schema.TaggedError()("TomlStringifyError", { diagnostic: TomlDiagnostic }) {
|
|
49
49
|
get message() {
|
|
50
50
|
return `TOML stringify failed: ${this.diagnostic.code} ${this.diagnostic.message}`;
|
|
51
51
|
}
|
|
@@ -228,8 +228,8 @@ var Toml = class Toml {
|
|
|
228
228
|
*/
|
|
229
229
|
static fromString() {
|
|
230
230
|
return Schema.String.pipe(Schema.decodeTo(Schema.Unknown, SchemaTransformation.transformOrFail({
|
|
231
|
-
decode: (input) => Toml.parse(input).pipe(Effect.mapError((error) => new SchemaIssue.InvalidValue(
|
|
232
|
-
encode: (value) => Effect.fromResult(Toml.stringifyResult(value)).pipe(Effect.mapError((error) => new SchemaIssue.InvalidValue(
|
|
231
|
+
decode: (input) => Toml.parse(input).pipe(Effect.mapError((error) => new SchemaIssue.InvalidValue({ message: error.message }, input))),
|
|
232
|
+
encode: (value) => Effect.fromResult(Toml.stringifyResult(value)).pipe(Effect.mapError((error) => new SchemaIssue.InvalidValue({ message: error.message }, value)))
|
|
233
233
|
})));
|
|
234
234
|
}
|
|
235
235
|
/**
|
package/TomlDocument.js
CHANGED
|
@@ -5,7 +5,7 @@ import { parseExpressions } from "./internal/parser.js";
|
|
|
5
5
|
import { analyze, buildValue } from "./internal/semantic.js";
|
|
6
6
|
import { TomlDiagnostic } from "./TomlDiagnostic.js";
|
|
7
7
|
import { TomlParseError } from "./Toml.js";
|
|
8
|
-
import { Effect,
|
|
8
|
+
import { Effect, Schema, SchemaIssue, SchemaTransformation } from "effect";
|
|
9
9
|
|
|
10
10
|
//#region src/TomlDocument.ts
|
|
11
11
|
/**
|
|
@@ -98,7 +98,7 @@ var TomlDocument = class TomlDocument extends Schema.Class("TomlDocument")({
|
|
|
98
98
|
*/
|
|
99
99
|
static schema() {
|
|
100
100
|
return Schema.String.pipe(Schema.decodeTo(Schema.instanceOf(TomlDocument), SchemaTransformation.transformOrFail({
|
|
101
|
-
decode: (input) => TomlDocument.parse(input).pipe(Effect.mapError((error) => new SchemaIssue.InvalidValue(
|
|
101
|
+
decode: (input) => TomlDocument.parse(input).pipe(Effect.mapError((error) => new SchemaIssue.InvalidValue({ message: error.message }, input))),
|
|
102
102
|
encode: (doc) => Effect.succeed(doc.stringify())
|
|
103
103
|
})));
|
|
104
104
|
}
|
package/TomlFormat.js
CHANGED
|
@@ -28,7 +28,7 @@ var TomlFormattingOptions = class extends Schema.Class("TomlFormattingOptions")(
|
|
|
28
28
|
*
|
|
29
29
|
* @public
|
|
30
30
|
*/
|
|
31
|
-
var TomlModificationError = class extends Schema.
|
|
31
|
+
var TomlModificationError = class extends Schema.TaggedError()("TomlModificationError", { diagnostic: TomlDiagnostic }) {
|
|
32
32
|
get message() {
|
|
33
33
|
return `TOML modification failed: ${this.diagnostic.code} ${this.diagnostic.message}`;
|
|
34
34
|
}
|
|
@@ -55,8 +55,10 @@ const scanWsBack = (source, pos, start) => {
|
|
|
55
55
|
const dominantNewline = (source) => {
|
|
56
56
|
let lf = 0;
|
|
57
57
|
let crlf = 0;
|
|
58
|
-
for (let i = 0; i < source.length; i++) if (source.charCodeAt(i) === LF)
|
|
59
|
-
|
|
58
|
+
for (let i = 0; i < source.length; i++) if (source.charCodeAt(i) === LF) {
|
|
59
|
+
if (i > 0 && source.charCodeAt(i - 1) === CR) crlf++;
|
|
60
|
+
else lf++;
|
|
61
|
+
}
|
|
60
62
|
return crlf > lf ? "\r\n" : "\n";
|
|
61
63
|
};
|
|
62
64
|
/** Multi-line string value spans — the bytes formatting must never touch. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effected/toml",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
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-beta.
|
|
41
|
+
"effect": "4.0.0-beta.107"
|
|
42
42
|
},
|
|
43
43
|
"engines": {
|
|
44
44
|
"node": ">=24.11.0"
|