n3.js-messages 0.2.0 → 0.2.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 +42 -1
- package/browser/index.global.js +4 -4
- package/browser/index.global.js.map +3 -3
- package/browser/index.js +5 -5
- package/browser/index.js.map +3 -3
- package/common.d.ts +6 -4
- package/lib/MessageParserCore.js +9 -6
- package/lib/MessageParserCore.js.map +1 -1
- package/lib/MessageWriter.js +2 -2
- package/lib/MessageWriter.js.map +1 -1
- package/lib/formats.js +14 -1
- package/lib/formats.js.map +1 -1
- package/package.json +1 -1
- package/src/MessageParserCore.js +9 -6
- package/src/MessageWriter.js +2 -2
- package/src/formats.js +12 -1
package/README.md
CHANGED
|
@@ -68,7 +68,34 @@ new MessageParser({ format: 'TriG' }).parse(text, {
|
|
|
68
68
|
```
|
|
69
69
|
|
|
70
70
|
Messages are not merged, empty messages are preserved, and quads keep the order of the document.
|
|
71
|
-
A document that does not announce a `-messages` version is one message, and a delimiter in it is an error.
|
|
71
|
+
A document that does not announce a `-messages` version (in-line or externally) is one message, and a delimiter in it is an error.
|
|
72
|
+
|
|
73
|
+
### Announcing messages through Content-Type
|
|
74
|
+
|
|
75
|
+
An in-line `VERSION` statement is optional when the version is announced externally, for example by an HTTP response header:
|
|
76
|
+
|
|
77
|
+
```http
|
|
78
|
+
Content-Type: text/turtle; version=1.2-messages
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Pass the full media type as `format`; its `version` parameter enables message parsing even when the body has no `VERSION` statement:
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
const messages = parseMessages(body, {
|
|
85
|
+
format: 'text/turtle; version=1.2-messages',
|
|
86
|
+
});
|
|
87
|
+
// Equivalent: { format: 'Turtle', version: '1.2-messages' }
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Quoted parameter values and case-insensitive parameter names are supported; unrelated parameters such as `charset` are ignored.
|
|
91
|
+
An explicit `version` option overrides the media type parameter. Either external version takes precedence over in-line announcements;
|
|
92
|
+
`onVersion` still reports the labels encountered in the body. Without an external version, in-line announcements determine message mode.
|
|
93
|
+
`messages: true` explicitly enables message mode regardless of the version label.
|
|
94
|
+
These options work with synchronous, Node.js stream, and browser parsers.
|
|
95
|
+
|
|
96
|
+
HTTP clients can request a message log using `Accept: text/turtle; version=1.2-messages`, but should configure parsing from
|
|
97
|
+
the response's `Content-Type`, since content negotiation may return a different version. This package parses RDF payloads;
|
|
98
|
+
the application reads and writes HTTP headers.
|
|
72
99
|
|
|
73
100
|
## Streaming
|
|
74
101
|
|
|
@@ -148,6 +175,20 @@ await writer.end();
|
|
|
148
175
|
const text = writeMessages(messages, { format: 'N-Quads' }); // synchronous, returns a string
|
|
149
176
|
```
|
|
150
177
|
|
|
178
|
+
When the application announces the version externally, use `writeVersion: false` to omit the in-line announcement:
|
|
179
|
+
|
|
180
|
+
```js
|
|
181
|
+
// Send with Content-Type: text/turtle; version=1.2-messages
|
|
182
|
+
const body = writeMessages(messages, {
|
|
183
|
+
format: 'text/turtle; version=1.2-messages',
|
|
184
|
+
writeVersion: false,
|
|
185
|
+
});
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
This option also works with `MessageWriter` and both stream writers. It preserves delimiters, prefixes, and base declarations.
|
|
189
|
+
The writer reads the version from the media type unless overridden by `version`; it defaults to `1.2-messages` and
|
|
190
|
+
still validates the label when `writeVersion: false`. By default, it writes the in-line announcement even when the media type includes a version.
|
|
191
|
+
|
|
151
192
|
- Writes `VERSION "1.2-messages"` (`@version "1.2-messages".` in Turtle/TriG) first, and a delimiter after each message:
|
|
152
193
|
`MESSAGE` in N-Triples and N-Quads, `@message .` in Turtle and TriG. A parser gets a message when it is written, and a trailing empty
|
|
153
194
|
message survives a round trip.
|