@effected/toml 0.16.0 → 0.17.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/TomlDiagnostic.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { TOML_LEX_ERROR_CODES, TOML_PARSE_ERROR_CODES, TOML_SEMANTIC_ERROR_CODES, TOML_STRINGIFY_ERROR_CODES } from "./internal/diagnostics.js";
2
2
  import { Schema } from "effect";
3
+ import { LineIndex } from "@effected/source";
3
4
 
4
5
  // src/TomlDiagnostic.ts
5
6
  /**
@@ -49,6 +50,15 @@ const TomlErrorCode = Schema.Union([
49
50
  * and `@effected/yaml`'s `YamlDiagnostic`; `message` is this package's
50
51
  * additive extra.
51
52
  *
53
+ * With `message` it satisfies `@effected/source`'s `SourceDiagnostic`
54
+ * structurally, so a consumer written over that interface (an LSP server, a
55
+ * CLI printing annotations) reads it directly. `line` and `character` come
56
+ * from `@effected/source`'s `LineIndex` under its default `"lsp"` rule: a line
57
+ * ends at `\n`, `\r\n` or a bare `\r`, as an LSP client counts. TOML's own
58
+ * newline is `\n` or `\r\n` only, so a bare `\r` is invalid TOML; it is
59
+ * counted as a line break only so a diagnostic about it positions LSP-style.
60
+ * An offset at the `\n` of a `\r\n` reads as the end of its line.
61
+ *
52
62
  * @public
53
63
  */
54
64
  var TomlDiagnostic = class TomlDiagnostic extends Schema.Class("TomlDiagnostic")({
@@ -69,7 +79,7 @@ var TomlDiagnostic = class TomlDiagnostic extends Schema.Class("TomlDiagnostic")
69
79
  * @returns The diagnostic with `line` and `character` filled in.
70
80
  */
71
81
  static fromRaw(source, raw) {
72
- const { line, character } = lineChar(source, raw.offset);
82
+ const { line, character } = LineIndex.make(source).positionAt(raw.offset);
73
83
  return TomlDiagnostic.make({
74
84
  code: raw.code,
75
85
  message: raw.message,
@@ -80,30 +90,5 @@ var TomlDiagnostic = class TomlDiagnostic extends Schema.Class("TomlDiagnostic")
80
90
  });
81
91
  }
82
92
  };
83
- /**
84
- * Compute the zero-based line/character position of `offset` within `text`.
85
- * Recognizes `\n`, `\r` and `\r\n` as line breaks (TOML's newline grammar);
86
- * a CRLF pair counts as a single newline.
87
- */
88
- function lineChar(text, offset) {
89
- let line = 0;
90
- let lineStart = 0;
91
- const limit = Math.min(offset, text.length);
92
- for (let i = 0; i < limit; i++) {
93
- const ch = text.charCodeAt(i);
94
- if (ch === 10) {
95
- line++;
96
- lineStart = i + 1;
97
- } else if (ch === 13) {
98
- if (i + 1 < text.length && text.charCodeAt(i + 1) === 10) i++;
99
- line++;
100
- lineStart = i + 1;
101
- }
102
- }
103
- return {
104
- line,
105
- character: offset - lineStart
106
- };
107
- }
108
93
 
109
94
  export { TomlDiagnostic, TomlErrorCode, TomlLexErrorCode, TomlParseErrorCode, TomlSemanticErrorCode, TomlStringifyErrorCode };
package/index.d.ts CHANGED
@@ -79,6 +79,15 @@ declare const TomlDiagnostic_base: Schema.Class<TomlDiagnostic, Schema.Struct<{
79
79
  * and `@effected/yaml`'s `YamlDiagnostic`; `message` is this package's
80
80
  * additive extra.
81
81
  *
82
+ * With `message` it satisfies `@effected/source`'s `SourceDiagnostic`
83
+ * structurally, so a consumer written over that interface (an LSP server, a
84
+ * CLI printing annotations) reads it directly. `line` and `character` come
85
+ * from `@effected/source`'s `LineIndex` under its default `"lsp"` rule: a line
86
+ * ends at `\n`, `\r\n` or a bare `\r`, as an LSP client counts. TOML's own
87
+ * newline is `\n` or `\r\n` only, so a bare `\r` is invalid TOML; it is
88
+ * counted as a line break only so a diagnostic about it positions LSP-style.
89
+ * An offset at the `\n` of a `\r\n` reads as the end of its line.
90
+ *
82
91
  * @public
83
92
  */
84
93
  export declare class TomlDiagnostic extends TomlDiagnostic_base {
@@ -1055,125 +1064,22 @@ export type TomlVisitorEvent = Data.TaggedEnum<{
1055
1064
  *
1056
1065
  * @public
1057
1066
  */
1058
- export declare const TomlVisitorEvent: {
1059
- readonly $is: <Tag extends "ArrayTableStart" | "Comment" | "KeyValue" | "TableStart">(tag: Tag) => (u: unknown) => u is Extract<{
1060
- readonly _tag: "ArrayTableStart";
1061
- readonly path: ReadonlyArray<string>;
1062
- readonly index: number;
1063
- }, {
1064
- readonly _tag: Tag;
1065
- }> | Extract<{
1066
- readonly _tag: "Comment";
1067
- readonly text: string;
1068
- readonly offset: number;
1069
- }, {
1070
- readonly _tag: Tag;
1071
- }> | Extract<{
1072
- readonly _tag: "KeyValue";
1073
- readonly path: ReadonlyArray<string>;
1074
- readonly node: TomlKeyValue;
1075
- }, {
1076
- readonly _tag: Tag;
1077
- }> | Extract<{
1078
- readonly _tag: "TableStart";
1079
- readonly path: ReadonlyArray<string>;
1080
- }, {
1081
- readonly _tag: Tag;
1082
- }>;
1083
- readonly $match: {
1084
- <Cases extends {
1085
- readonly ArrayTableStart: (args: {
1086
- readonly _tag: "ArrayTableStart";
1087
- readonly path: ReadonlyArray<string>;
1088
- readonly index: number;
1089
- }) => any;
1090
- readonly Comment: (args: {
1091
- readonly _tag: "Comment";
1092
- readonly text: string;
1093
- readonly offset: number;
1094
- }) => any;
1095
- readonly KeyValue: (args: {
1096
- readonly _tag: "KeyValue";
1097
- readonly path: ReadonlyArray<string>;
1098
- readonly node: TomlKeyValue;
1099
- }) => any;
1100
- readonly TableStart: (args: {
1101
- readonly _tag: "TableStart";
1102
- readonly path: ReadonlyArray<string>;
1103
- }) => any;
1104
- }>(cases: Cases): (value: {
1105
- readonly _tag: "ArrayTableStart";
1106
- readonly path: ReadonlyArray<string>;
1107
- readonly index: number;
1108
- } | {
1109
- readonly _tag: "Comment";
1110
- readonly text: string;
1111
- readonly offset: number;
1112
- } | {
1113
- readonly _tag: "KeyValue";
1114
- readonly path: ReadonlyArray<string>;
1115
- readonly node: TomlKeyValue;
1116
- } | {
1117
- readonly _tag: "TableStart";
1118
- readonly path: ReadonlyArray<string>;
1119
- }) => import("effect/Unify").Unify<ReturnType<Cases["ArrayTableStart" | "Comment" | "KeyValue" | "TableStart"]>>;
1120
- <Cases extends {
1121
- readonly ArrayTableStart: (args: {
1122
- readonly _tag: "ArrayTableStart";
1123
- readonly path: ReadonlyArray<string>;
1124
- readonly index: number;
1125
- }) => any;
1126
- readonly Comment: (args: {
1127
- readonly _tag: "Comment";
1128
- readonly text: string;
1129
- readonly offset: number;
1130
- }) => any;
1131
- readonly KeyValue: (args: {
1132
- readonly _tag: "KeyValue";
1133
- readonly path: ReadonlyArray<string>;
1134
- readonly node: TomlKeyValue;
1135
- }) => any;
1136
- readonly TableStart: (args: {
1137
- readonly _tag: "TableStart";
1138
- readonly path: ReadonlyArray<string>;
1139
- }) => any;
1140
- }>(value: {
1141
- readonly _tag: "ArrayTableStart";
1142
- readonly path: ReadonlyArray<string>;
1143
- readonly index: number;
1144
- } | {
1145
- readonly _tag: "Comment";
1146
- readonly text: string;
1147
- readonly offset: number;
1148
- } | {
1149
- readonly _tag: "KeyValue";
1150
- readonly path: ReadonlyArray<string>;
1151
- readonly node: TomlKeyValue;
1152
- } | {
1153
- readonly _tag: "TableStart";
1154
- readonly path: ReadonlyArray<string>;
1155
- }, cases: Cases): import("effect/Unify").Unify<ReturnType<Cases["ArrayTableStart" | "Comment" | "KeyValue" | "TableStart"]>>;
1156
- };
1157
- readonly ArrayTableStart: Data.TaggedEnum.ConstructorFrom<{
1158
- readonly _tag: "ArrayTableStart";
1159
- readonly path: ReadonlyArray<string>;
1160
- readonly index: number;
1161
- }, "_tag">;
1162
- readonly Comment: Data.TaggedEnum.ConstructorFrom<{
1163
- readonly _tag: "Comment";
1164
- readonly text: string;
1165
- readonly offset: number;
1166
- }, "_tag">;
1167
- readonly KeyValue: Data.TaggedEnum.ConstructorFrom<{
1168
- readonly _tag: "KeyValue";
1169
- readonly path: ReadonlyArray<string>;
1170
- readonly node: TomlKeyValue;
1171
- }, "_tag">;
1172
- readonly TableStart: Data.TaggedEnum.ConstructorFrom<{
1173
- readonly _tag: "TableStart";
1174
- readonly path: ReadonlyArray<string>;
1175
- }, "_tag">;
1176
- };
1067
+ export declare const TomlVisitorEvent: Data.TaggedEnum.Constructor<{
1068
+ readonly _tag: "ArrayTableStart";
1069
+ readonly path: ReadonlyArray<string>;
1070
+ readonly index: number;
1071
+ } | {
1072
+ readonly _tag: "Comment";
1073
+ readonly text: string;
1074
+ readonly offset: number;
1075
+ } | {
1076
+ readonly _tag: "KeyValue";
1077
+ readonly path: ReadonlyArray<string>;
1078
+ readonly node: TomlKeyValue;
1079
+ } | {
1080
+ readonly _tag: "TableStart";
1081
+ readonly path: ReadonlyArray<string>;
1082
+ }>;
1177
1083
  /**
1178
1084
  * Walks TOML text as a `Stream` of table, array-table, key-value and comment
1179
1085
  * events in document order, without building a value. Not instantiable.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effected/toml",
3
- "version": "0.16.0",
3
+ "version": "0.17.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": [
@@ -37,6 +37,9 @@
37
37
  },
38
38
  "./package.json": "./package.json"
39
39
  },
40
+ "dependencies": {
41
+ "@effected/source": "^0.1.0"
42
+ },
40
43
  "peerDependencies": {
41
44
  "effect": "^4.0.0"
42
45
  },
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.59.1"
8
+ "packageVersion": "7.59.4"
9
9
  }
10
10
  ]
11
11
  }