json-seq-stream 1.0.5 → 1.0.6
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/InputJsonSequenceParseStream.d.ts +24 -0
- package/InputJsonSequenceStream.d.ts +25 -0
- package/InputSequenceStream.d.ts +20 -0
- package/LICENSE +21 -21
- package/OutputJsonSequenceStfingifyStream.d.ts +14 -0
- package/OutputJsonSequenceStream.d.ts +12 -0
- package/OutputSequenceStream.d.ts +10 -0
- package/README.md +27 -22
- package/index.d.ts +6 -5
- package/index.js +117 -48
- package/index.umd.cjs +2 -2
- package/package.json +62 -59
- package/rfc7464.d.ts +16 -0
- package/JsonSequenceFormatStream.d.ts +0 -14
- package/JsonSequenceStream.d.ts +0 -17
- package/SequenceStream.d.ts +0 -10
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type InputJsonSequenceParseStreamOptions<T> = {
|
|
2
|
+
parse?: (text: string) => (T | undefined);
|
|
3
|
+
errorFallback?: false | ((error: unknown, args: {
|
|
4
|
+
error: (reason: unknown) => void;
|
|
5
|
+
chunk: string;
|
|
6
|
+
enqueue: (arg: T) => void;
|
|
7
|
+
}) => (void | Promise<void>));
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* string の sequence を 連続した `T` の sequence に変換する TransformStream
|
|
11
|
+
*/
|
|
12
|
+
export declare class InputJsonSequenceParseStream<T> extends TransformStream<string, T> {
|
|
13
|
+
constructor(options?: InputJsonSequenceParseStreamOptions<T>);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated rename to InputJsonSequenceFormatStreamOptions
|
|
17
|
+
* @see InputJsonSequenceParseStreamOptions
|
|
18
|
+
*/
|
|
19
|
+
export type JsonSequenceFormatStreamOptions<T> = InputJsonSequenceParseStreamOptions<T>;
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated rename to InputJsonSequenceFormatStream
|
|
22
|
+
* @see InputJsonSequenceParseStream
|
|
23
|
+
*/
|
|
24
|
+
export declare const JsonSequenceFormatStream: typeof InputJsonSequenceParseStream;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { InputJsonSequenceParseStreamOptions } from "./InputJsonSequenceParseStream";
|
|
2
|
+
import type { InputSequenceStreamOptions } from "./InputSequenceStream";
|
|
3
|
+
export type InputJsonSequenceStreamOptions<T> = {
|
|
4
|
+
label?: string;
|
|
5
|
+
} & TextDecoderOptions & InputJsonSequenceParseStreamOptions<T> & InputSequenceStreamOptions;
|
|
6
|
+
/**
|
|
7
|
+
* fetch 等の stream() に接続する目的の application/json-seq フォーマットを T型の json として パースする Stream
|
|
8
|
+
*/
|
|
9
|
+
declare class InputJsonSequenceStream<T> extends TransformStream<BufferSource, T> {
|
|
10
|
+
#private;
|
|
11
|
+
get writable(): WritableStream<BufferSource>;
|
|
12
|
+
get readable(): ReadableStream<T>;
|
|
13
|
+
constructor(options?: InputJsonSequenceStreamOptions<T>);
|
|
14
|
+
}
|
|
15
|
+
export { InputJsonSequenceStream, InputJsonSequenceStream as default, };
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated rename to InputJsonSequenceStream
|
|
18
|
+
* @see InputJsonSequenceStream
|
|
19
|
+
*/
|
|
20
|
+
export declare const JsonSequenceStream: typeof InputJsonSequenceStream;
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated rename to InputJsonSequenceStreamOptions
|
|
23
|
+
* @see InputJsonSequenceStreamOptions
|
|
24
|
+
*/
|
|
25
|
+
export type JsonSequenceStreamOptions<T> = InputJsonSequenceStreamOptions<T>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type InputSequenceStreamOptions = {
|
|
2
|
+
lineBegin?: string;
|
|
3
|
+
lineEnd?: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* RS で始まって LF で1行を表す 連続した文字列データを 行データとして整形して返す
|
|
7
|
+
*/
|
|
8
|
+
export declare class InputSequenceStream extends TransformStream<string, string> {
|
|
9
|
+
constructor(options?: InputSequenceStreamOptions);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated rename to InputSequenceStreamOptions
|
|
13
|
+
* @see InputSequenceStreamOptions
|
|
14
|
+
*/
|
|
15
|
+
export type SequenceStreamOptions = InputSequenceStreamOptions;
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated rename to InputSequenceStream
|
|
18
|
+
* @see InputSequenceStream
|
|
19
|
+
*/
|
|
20
|
+
export declare const SequenceStream: typeof InputSequenceStream;
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 juner
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 juner
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type OutputJsonSequenceStringifyStreamOptions<T> = {
|
|
2
|
+
stringify?: (value: T) => (string | undefined);
|
|
3
|
+
errorFallback?: false | ((error: unknown, args: {
|
|
4
|
+
error: (reason: unknown) => void;
|
|
5
|
+
chunk: T;
|
|
6
|
+
enqueue: (arg: string) => void;
|
|
7
|
+
}) => (void | Promise<void>));
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* 連続した `T` の sequence を string の sequence に変換する TransformStream
|
|
11
|
+
*/
|
|
12
|
+
export declare class OutputJsonSequenceStringifyStream<T> extends TransformStream<T, string> {
|
|
13
|
+
constructor(options?: OutputJsonSequenceStringifyStreamOptions<T>);
|
|
14
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { OutputJsonSequenceStringifyStreamOptions } from "./OutputJsonSequenceStfingifyStream";
|
|
2
|
+
import type { OutputSequenceStreamOptions } from "./OutputSequenceStream";
|
|
3
|
+
export type OutputJsonSequenceStreamOptions<T> = OutputJsonSequenceStringifyStreamOptions<T> & OutputSequenceStreamOptions;
|
|
4
|
+
/**
|
|
5
|
+
* T型 を application/json-seq フォーマットに変換する Stream
|
|
6
|
+
*/
|
|
7
|
+
export declare class OutputJsonSequenceStream<T> extends TransformStream<T, BufferSource> {
|
|
8
|
+
#private;
|
|
9
|
+
get writable(): WritableStream<T>;
|
|
10
|
+
get readable(): ReadableStream<BufferSource>;
|
|
11
|
+
constructor(options?: OutputJsonSequenceStreamOptions<T>);
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type OutputSequenceStreamOptions = {
|
|
2
|
+
lineBegin?: string;
|
|
3
|
+
lineEnd?: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* 行データを RS で始まって LF で1行を表す 連続した文字列データに変換する
|
|
7
|
+
*/
|
|
8
|
+
export declare class OutputSequenceStream extends TransformStream<string, string> {
|
|
9
|
+
constructor(options?: OutputSequenceStreamOptions);
|
|
10
|
+
}
|
package/README.md
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
|
-
# json-seq-stream
|
|
2
|
-
|
|
3
|
-
application/json-seq support stream / async iterator library
|
|
4
|
-
|
|
5
|
-
## usage
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
import { JsonSequenceStream } from "json-seq-stream";
|
|
9
|
-
|
|
10
|
-
type Value = {
|
|
11
|
-
value: number;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const sequenceStream = new JsonSequenceStream<Value>();
|
|
15
|
-
|
|
16
|
-
const response = await fetch(url);
|
|
17
|
-
if (!response.ok) throw new Error();
|
|
18
|
-
const readable = response.body!.pipeThrough(sequenceStream);
|
|
19
|
-
for await (const value of readable) {
|
|
20
|
-
console.log(value);
|
|
21
|
-
}
|
|
22
|
-
```
|
|
1
|
+
# json-seq-stream
|
|
2
|
+
|
|
3
|
+
application/json-seq support stream / async iterator library
|
|
4
|
+
|
|
5
|
+
## usage
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { InputJsonSequenceStream as JsonSequenceStream } from "json-seq-stream";
|
|
9
|
+
|
|
10
|
+
type Value = {
|
|
11
|
+
value: number;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const sequenceStream = new JsonSequenceStream<Value>();
|
|
15
|
+
|
|
16
|
+
const response = await fetch(url);
|
|
17
|
+
if (!response.ok) throw new Error();
|
|
18
|
+
const readable = response.body!.pipeThrough(sequenceStream);
|
|
19
|
+
for await (const value of readable) {
|
|
20
|
+
console.log(value);
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## see also
|
|
25
|
+
|
|
26
|
+
- rfc7464 - JavaScript Object Notation (JSON) Text Sequences \
|
|
27
|
+
[https://datatracker.ietf.org/doc/html/rfc7464](https://datatracker.ietf.org/doc/html/rfc7464)
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
4
|
-
export
|
|
5
|
-
export
|
|
1
|
+
export * from "./InputSequenceStream";
|
|
2
|
+
export * from "./InputJsonSequenceParseStream";
|
|
3
|
+
export * from "./InputJsonSequenceStream";
|
|
4
|
+
export * from "./OutputSequenceStream";
|
|
5
|
+
export * from "./OutputJsonSequenceStfingifyStream";
|
|
6
|
+
export * from "./OutputJsonSequenceStream";
|
package/index.js
CHANGED
|
@@ -1,15 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const S = "á", m = `
|
|
2
|
+
`, d = S, h = m;
|
|
3
|
+
function l({ lineBegin: t, lineEnd: e } = {}) {
|
|
4
|
+
t ??= d, e ??= h;
|
|
5
|
+
const n = [], c = new RegExp(`(${RegExp.escape(t)}|${RegExp.escape(e)})`, "u");
|
|
6
|
+
return {
|
|
7
|
+
args: [
|
|
8
|
+
{
|
|
9
|
+
transform(u, a) {
|
|
10
|
+
for (const o of u.split(c)) {
|
|
11
|
+
if (o === t) {
|
|
12
|
+
const i = s(n);
|
|
13
|
+
if (i.length <= 0) continue;
|
|
14
|
+
a.enqueue(i);
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
o !== e && n.push(o);
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
flush(u) {
|
|
21
|
+
const a = s(n);
|
|
22
|
+
a.length <= 0 || u.enqueue(a);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
};
|
|
27
|
+
function s(u) {
|
|
28
|
+
return u.splice(0, u.length).join("");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
class f extends TransformStream {
|
|
32
|
+
constructor(e) {
|
|
33
|
+
const { args: n } = l(e);
|
|
34
|
+
super(...n);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const y = f;
|
|
38
|
+
function b({ parse: t, errorFallback: e } = {}) {
|
|
39
|
+
return t ??= JSON.parse, e ??= !1, { args: [
|
|
3
40
|
{
|
|
4
|
-
transform(
|
|
41
|
+
transform(c, r) {
|
|
5
42
|
try {
|
|
6
|
-
const s =
|
|
7
|
-
s &&
|
|
43
|
+
const s = t(c);
|
|
44
|
+
s && r.enqueue(s);
|
|
8
45
|
} catch (s) {
|
|
9
46
|
if (!e) return;
|
|
10
|
-
const
|
|
11
|
-
if (
|
|
12
|
-
return
|
|
47
|
+
const u = r.error.bind(r), a = r.enqueue.bind(r), o = e(s, { chunk: c, error: u, enqueue: a });
|
|
48
|
+
if (o?.then)
|
|
49
|
+
return o.catch(() => {
|
|
13
50
|
});
|
|
14
51
|
}
|
|
15
52
|
}
|
|
@@ -18,69 +55,101 @@ function S({ parse: n, errorFallback: e } = {}) {
|
|
|
18
55
|
}
|
|
19
56
|
class p extends TransformStream {
|
|
20
57
|
constructor(e = {}) {
|
|
21
|
-
const { args:
|
|
22
|
-
super(...
|
|
58
|
+
const { args: n } = b(e);
|
|
59
|
+
super(...n);
|
|
23
60
|
}
|
|
24
61
|
}
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
62
|
+
const L = p;
|
|
63
|
+
function I(t) {
|
|
64
|
+
const { label: e, fatal: n, lineBegin: c, lineEnd: r, parse: s, errorFallback: u } = t, a = new TextDecoderStream(e, { fatal: n }), o = new f({ lineBegin: c, lineEnd: r }), i = new p({ parse: s, errorFallback: u }), { writable: q } = a, g = a.readable.pipeThrough(o).pipeThrough(i);
|
|
65
|
+
return { writable: q, readable: g };
|
|
66
|
+
}
|
|
67
|
+
class w extends TransformStream {
|
|
68
|
+
#e;
|
|
69
|
+
#t;
|
|
70
|
+
get writable() {
|
|
71
|
+
return this.#e;
|
|
72
|
+
}
|
|
73
|
+
get readable() {
|
|
74
|
+
return this.#t;
|
|
75
|
+
}
|
|
76
|
+
constructor(e = {}) {
|
|
77
|
+
super(), {
|
|
78
|
+
readable: this.#t,
|
|
79
|
+
writable: this.#e
|
|
80
|
+
} = I(e);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const R = w, x = S, J = m;
|
|
84
|
+
function T({ lineBegin: t, lineEnd: e } = {}) {
|
|
85
|
+
return t ??= x, e ??= J, {
|
|
31
86
|
args: [
|
|
32
87
|
{
|
|
33
|
-
transform(
|
|
34
|
-
|
|
35
|
-
if (c === n) {
|
|
36
|
-
const i = s(t);
|
|
37
|
-
if (i.length <= 0) continue;
|
|
38
|
-
a.enqueue(i);
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
c !== e && t.push(c);
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
flush(r) {
|
|
45
|
-
const a = s(t);
|
|
46
|
-
a.length <= 0 || r.enqueue(a);
|
|
88
|
+
transform(c, r) {
|
|
89
|
+
r.enqueue(`${t}${c}${e}`);
|
|
47
90
|
}
|
|
48
91
|
}
|
|
49
92
|
]
|
|
50
93
|
};
|
|
51
|
-
function s(r) {
|
|
52
|
-
return r.splice(0, r.length).join("");
|
|
53
|
-
}
|
|
54
94
|
}
|
|
55
|
-
class
|
|
95
|
+
class E extends TransformStream {
|
|
56
96
|
constructor(e) {
|
|
57
|
-
const { args:
|
|
58
|
-
super(...
|
|
97
|
+
const { args: n } = T(e);
|
|
98
|
+
super(...n);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function N({ stringify: t, errorFallback: e } = {}) {
|
|
102
|
+
return t ??= JSON.stringify, e ??= !1, { args: [
|
|
103
|
+
{
|
|
104
|
+
transform(c, r) {
|
|
105
|
+
try {
|
|
106
|
+
const s = t(c);
|
|
107
|
+
(s?.length ?? 0) > 0 && r.enqueue(s);
|
|
108
|
+
} catch (s) {
|
|
109
|
+
if (!e) return;
|
|
110
|
+
const u = r.error.bind(r), a = r.enqueue.bind(r), o = e(s, { chunk: c, error: u, enqueue: a });
|
|
111
|
+
if (o?.then)
|
|
112
|
+
return o.catch(() => {
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
] };
|
|
118
|
+
}
|
|
119
|
+
class O extends TransformStream {
|
|
120
|
+
constructor(e = {}) {
|
|
121
|
+
const { args: n } = N(e);
|
|
122
|
+
super(...n);
|
|
59
123
|
}
|
|
60
124
|
}
|
|
61
|
-
function
|
|
62
|
-
const {
|
|
63
|
-
return { writable:
|
|
125
|
+
function $(t) {
|
|
126
|
+
const { lineBegin: e, lineEnd: n, stringify: c, errorFallback: r } = t, s = new TextEncoderStream(), u = new E({ lineBegin: e, lineEnd: n }), a = new O({ stringify: c, errorFallback: r }), { writable: o } = a, i = a.readable.pipeThrough(u).pipeThrough(s);
|
|
127
|
+
return { writable: o, readable: i };
|
|
64
128
|
}
|
|
65
|
-
class
|
|
129
|
+
class _ extends TransformStream {
|
|
66
130
|
#e;
|
|
67
|
-
#
|
|
131
|
+
#t;
|
|
68
132
|
get writable() {
|
|
69
133
|
return this.#e;
|
|
70
134
|
}
|
|
71
135
|
get readable() {
|
|
72
|
-
return this.#
|
|
136
|
+
return this.#t;
|
|
73
137
|
}
|
|
74
138
|
constructor(e = {}) {
|
|
75
139
|
super(), {
|
|
76
|
-
readable: this.#
|
|
140
|
+
readable: this.#t,
|
|
77
141
|
writable: this.#e
|
|
78
|
-
} =
|
|
142
|
+
} = $(e);
|
|
79
143
|
}
|
|
80
144
|
}
|
|
81
145
|
export {
|
|
82
|
-
p as
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
146
|
+
p as InputJsonSequenceParseStream,
|
|
147
|
+
w as InputJsonSequenceStream,
|
|
148
|
+
f as InputSequenceStream,
|
|
149
|
+
L as JsonSequenceFormatStream,
|
|
150
|
+
R as JsonSequenceStream,
|
|
151
|
+
_ as OutputJsonSequenceStream,
|
|
152
|
+
O as OutputJsonSequenceStringifyStream,
|
|
153
|
+
E as OutputSequenceStream,
|
|
154
|
+
y as SequenceStream
|
|
86
155
|
};
|
package/index.umd.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
|
|
1
|
+
(function(u,S){typeof exports=="object"&&typeof module<"u"?S(exports):typeof define=="function"&&define.amd?define(["exports"],S):(u=typeof globalThis<"u"?globalThis:u||self,S(u.index={}))})(this,function(u){"use strict";const S="á",p=`
|
|
2
|
+
`,l=S,b=p;function I({lineBegin:n,lineEnd:e}={}){n??=l,e??=b;const t=[],o=new RegExp(`(${RegExp.escape(n)}|${RegExp.escape(e)})`,"u");return{args:[{transform(a,c){for(const i of a.split(o)){if(i===n){const m=s(t);if(m.length<=0)continue;c.enqueue(m);continue}i!==e&&t.push(i)}},flush(a){const c=s(t);c.length<=0||a.enqueue(c)}}]};function s(a){return a.splice(0,a.length).join("")}}class f extends TransformStream{constructor(e){const{args:t}=I(e);super(...t)}}const J=f;function w({parse:n,errorFallback:e}={}){return n??=JSON.parse,e??=!1,{args:[{transform(o,r){try{const s=n(o);s&&r.enqueue(s)}catch(s){if(!e)return;const a=r.error.bind(r),c=r.enqueue.bind(r),i=e(s,{chunk:o,error:a,enqueue:c});if(i?.then)return i.catch(()=>{})}}}]}}class q extends TransformStream{constructor(e={}){const{args:t}=w(e);super(...t)}}const T=q;function O(n){const{label:e,fatal:t,lineBegin:o,lineEnd:r,parse:s,errorFallback:a}=n,c=new TextDecoderStream(e,{fatal:t}),i=new f({lineBegin:o,lineEnd:r}),m=new q({parse:s,errorFallback:a}),{writable:P}=c,R=c.readable.pipeThrough(i).pipeThrough(m);return{writable:P,readable:R}}class d extends TransformStream{#e;#n;get writable(){return this.#e}get readable(){return this.#n}constructor(e={}){super(),{readable:this.#n,writable:this.#e}=O(e)}}const E=d,y=S,N=p;function $({lineBegin:n,lineEnd:e}={}){return n??=y,e??=N,{args:[{transform(o,r){r.enqueue(`${n}${o}${e}`)}}]}}class g extends TransformStream{constructor(e){const{args:t}=$(e);super(...t)}}function x({stringify:n,errorFallback:e}={}){return n??=JSON.stringify,e??=!1,{args:[{transform(o,r){try{const s=n(o);(s?.length??0)>0&&r.enqueue(s)}catch(s){if(!e)return;const a=r.error.bind(r),c=r.enqueue.bind(r),i=e(s,{chunk:o,error:a,enqueue:c});if(i?.then)return i.catch(()=>{})}}}]}}class h extends TransformStream{constructor(e={}){const{args:t}=x(e);super(...t)}}function j(n){const{lineBegin:e,lineEnd:t,stringify:o,errorFallback:r}=n,s=new TextEncoderStream,a=new g({lineBegin:e,lineEnd:t}),c=new h({stringify:o,errorFallback:r}),{writable:i}=c,m=c.readable.pipeThrough(a).pipeThrough(s);return{writable:i,readable:m}}class L extends TransformStream{#e;#n;get writable(){return this.#e}get readable(){return this.#n}constructor(e={}){super(),{readable:this.#n,writable:this.#e}=j(e)}}u.InputJsonSequenceParseStream=q,u.InputJsonSequenceStream=d,u.InputSequenceStream=f,u.JsonSequenceFormatStream=T,u.JsonSequenceStream=E,u.OutputJsonSequenceStream=L,u.OutputJsonSequenceStringifyStream=h,u.OutputSequenceStream=g,u.SequenceStream=J,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,59 +1,62 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "json-seq-stream",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "application/json-seq support stream / async iterator library",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "./index.js",
|
|
7
|
-
"exports": {
|
|
8
|
-
".": {
|
|
9
|
-
"import": {
|
|
10
|
-
"types": "./index.d.ts",
|
|
11
|
-
"default": "./index.js"
|
|
12
|
-
},
|
|
13
|
-
"require": {
|
|
14
|
-
"types": "./index.d.ts",
|
|
15
|
-
"default": "./index.umd.cjs"
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
"scripts": {
|
|
20
|
-
"test:watch": "vitest watch --coverage",
|
|
21
|
-
"test
|
|
22
|
-
"lint": "eslint .",
|
|
23
|
-
"lint:fix": "eslint . --fix",
|
|
24
|
-
"build": "vite build && tsc --project tsconfig.build.json && cpx ./package.json dist && cpx README.md dist && cpx LICENSE dist"
|
|
25
|
-
},
|
|
26
|
-
"repository": {
|
|
27
|
-
"type": "git",
|
|
28
|
-
"url": "git+https://github.com/juner/json-seq-stream.git"
|
|
29
|
-
},
|
|
30
|
-
"keywords": [
|
|
31
|
-
"application/json-seq",
|
|
32
|
-
"TransformStream",
|
|
33
|
-
"web streams",
|
|
34
|
-
"asyncIterator",
|
|
35
|
-
"Symbol.asyncIterator",
|
|
36
|
-
"rfc7464",
|
|
37
|
-
"json-seq"
|
|
38
|
-
],
|
|
39
|
-
"author": "juners",
|
|
40
|
-
"license": "MIT",
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
},
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"@
|
|
50
|
-
"
|
|
51
|
-
"eslint": "^
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
|
|
59
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "json-seq-stream",
|
|
3
|
+
"version": "1.0.6",
|
|
4
|
+
"description": "application/json-seq support stream / async iterator library",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": {
|
|
10
|
+
"types": "./index.d.ts",
|
|
11
|
+
"default": "./index.js"
|
|
12
|
+
},
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./index.d.ts",
|
|
15
|
+
"default": "./index.umd.cjs"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"test:watch": "vitest watch --coverage",
|
|
21
|
+
"test": "vitest run --coverage --coverage.reporter=cobertura --coverage.reporter=text",
|
|
22
|
+
"lint": "eslint .",
|
|
23
|
+
"lint:fix": "eslint . --fix",
|
|
24
|
+
"build": "vite build && tsc --project tsconfig.build.json && cpx ./package.json dist && cpx README.md dist && cpx LICENSE dist"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/juner/json-seq-stream.git"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"application/json-seq",
|
|
32
|
+
"TransformStream",
|
|
33
|
+
"web streams",
|
|
34
|
+
"asyncIterator",
|
|
35
|
+
"Symbol.asyncIterator",
|
|
36
|
+
"rfc7464",
|
|
37
|
+
"json-seq"
|
|
38
|
+
],
|
|
39
|
+
"author": "juners",
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": "^24.x"
|
|
43
|
+
},
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/juner/json-seq-stream/issues"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://github.com/juner/json-seq-stream#readme",
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@eslint/js": "^9.30.1",
|
|
50
|
+
"@eslint/json": "^0.12.0",
|
|
51
|
+
"@eslint/markdown": "^6.6.0",
|
|
52
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
53
|
+
"cpx": "^1.2.1",
|
|
54
|
+
"eslint": "^9.30.1",
|
|
55
|
+
"globals": "^16.3.0",
|
|
56
|
+
"path": "^0.12.7",
|
|
57
|
+
"typescript": "^5.8.3",
|
|
58
|
+
"typescript-eslint": "^8.36.0",
|
|
59
|
+
"vite": "^7.0.3",
|
|
60
|
+
"vitest": "^3.2.4"
|
|
61
|
+
}
|
|
62
|
+
}
|
package/rfc7464.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JavaScript Object Notation (JSON) Text Sequences
|
|
3
|
+
* @see https://datatracker.ietf.org/doc/html/rfc7464
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* RS = %x1E; "record separator" (RS), see RFC 20
|
|
7
|
+
* @see https://datatracker.ietf.org/doc/html/rfc7464#section-2.2
|
|
8
|
+
* @see https://datatracker.ietf.org/doc/html/rfc20
|
|
9
|
+
*/
|
|
10
|
+
export declare const RS = "\u00E1";
|
|
11
|
+
/**
|
|
12
|
+
* LF = %x0A; "line feed" (LF), see RFC 20
|
|
13
|
+
* @see https://datatracker.ietf.org/doc/html/rfc7464#section-2.2
|
|
14
|
+
* @see https://datatracker.ietf.org/doc/html/rfc20
|
|
15
|
+
*/
|
|
16
|
+
export declare const LF = "\n";
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export type JsonSequenceFormatStreamOptions<T> = {
|
|
2
|
-
parse?: (text: string) => (T | undefined);
|
|
3
|
-
errorFallback?: false | ((error: unknown, args: {
|
|
4
|
-
error: (reason: unknown) => void;
|
|
5
|
-
chunk: string;
|
|
6
|
-
enqueue: (arg: T) => void;
|
|
7
|
-
}) => (void | Promise<void>));
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* string の sequence を 連続した `T` の sequence に変換する TransformStream
|
|
11
|
-
*/
|
|
12
|
-
export declare class JsonSequenceFormatStream<T> extends TransformStream<string, T> {
|
|
13
|
-
constructor(options?: JsonSequenceFormatStreamOptions<T>);
|
|
14
|
-
}
|
package/JsonSequenceStream.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { type JsonSequenceFormatStreamOptions } from "./JsonSequenceFormatStream";
|
|
2
|
-
import type { SequenceStreamOptions } from "./SequenceStream";
|
|
3
|
-
export type JsonSequenceStreamOptions<T> = {
|
|
4
|
-
label?: string;
|
|
5
|
-
} & TextDecoderOptions & JsonSequenceFormatStreamOptions<T> & SequenceStreamOptions;
|
|
6
|
-
/**
|
|
7
|
-
* fetch 等の stream() に接続する目的の application/json-seq フォーマットを T型の json として パースする Stream
|
|
8
|
-
*/
|
|
9
|
-
declare class JsonSequenceStream<T> extends TransformStream<BufferSource, T> {
|
|
10
|
-
#private;
|
|
11
|
-
get writable(): WritableStream<BufferSource>;
|
|
12
|
-
get readable(): ReadableStream<T>;
|
|
13
|
-
constructor(options?: {
|
|
14
|
-
label?: string;
|
|
15
|
-
} & TextDecoderOptions & JsonSequenceFormatStreamOptions<T> & SequenceStreamOptions);
|
|
16
|
-
}
|
|
17
|
-
export { JsonSequenceStream, JsonSequenceStream as default, };
|
package/SequenceStream.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export type SequenceStreamOptions = {
|
|
2
|
-
lineBegin?: string;
|
|
3
|
-
lineEnd?: string;
|
|
4
|
-
};
|
|
5
|
-
/**
|
|
6
|
-
* RS で始まって LF で1行を表す 連続した文字列データを 行データとして整形して返す
|
|
7
|
-
*/
|
|
8
|
-
export declare class SequenceStream extends TransformStream<string, string> {
|
|
9
|
-
constructor(options?: SequenceStreamOptions);
|
|
10
|
-
}
|