modern-treasury 2.0.0 → 2.2.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/CHANGELOG.md +135 -0
- package/LICENSE +7 -0
- package/README.md +273 -0
- package/_shims/fetch.js +1 -1
- package/_shims/formdata.node.d.ts +1 -0
- package/core.d.ts +19 -11
- package/core.d.ts.map +1 -1
- package/core.js +122 -72
- package/core.js.map +1 -1
- package/core.mjs +112 -32
- package/core.mjs.map +1 -1
- package/error.d.ts +5 -0
- package/error.d.ts.map +1 -1
- package/error.js +20 -3
- package/error.js.map +1 -1
- package/error.mjs +18 -3
- package/error.mjs.map +1 -1
- package/index.d.mts +17 -8
- package/index.d.ts +17 -8
- package/index.d.ts.map +1 -1
- package/index.js +36 -20
- package/index.js.map +1 -1
- package/index.mjs +35 -20
- package/index.mjs.map +1 -1
- package/package.json +5 -5
- package/resources/account-collection-flows.d.ts +11 -11
- package/resources/account-collection-flows.d.ts.map +1 -1
- package/resources/account-collection-flows.js +4 -4
- package/resources/account-collection-flows.mjs +2 -2
- package/resources/account-details.d.ts.map +1 -1
- package/resources/connections.d.ts.map +1 -1
- package/resources/counterparties.d.ts.map +1 -1
- package/resources/documents.d.ts +2 -5
- package/resources/documents.d.ts.map +1 -1
- package/resources/documents.js +1 -7
- package/resources/documents.js.map +1 -1
- package/resources/documents.mjs +1 -7
- package/resources/documents.mjs.map +1 -1
- package/resources/events.d.ts.map +1 -1
- package/resources/expected-payments.d.ts.map +1 -1
- package/resources/external-accounts.d.ts.map +1 -1
- package/resources/incoming-payment-details.d.ts.map +1 -1
- package/resources/index.d.ts +2 -2
- package/resources/index.js +3 -3
- package/resources/index.mjs +1 -1
- package/resources/internal-accounts/balance-reports.d.ts.map +1 -1
- package/resources/internal-accounts/internal-accounts.d.ts +5 -4
- package/resources/internal-accounts/internal-accounts.d.ts.map +1 -1
- package/resources/internal-accounts/internal-accounts.js.map +1 -1
- package/resources/internal-accounts/internal-accounts.mjs.map +1 -1
- package/resources/invoices/invoices.d.ts +102 -5
- package/resources/invoices/invoices.d.ts.map +1 -1
- package/resources/invoices/invoices.js.map +1 -1
- package/resources/invoices/invoices.mjs.map +1 -1
- package/resources/invoices/line-items.d.ts +41 -0
- package/resources/invoices/line-items.d.ts.map +1 -1
- package/resources/invoices/line-items.js.map +1 -1
- package/resources/invoices/line-items.mjs.map +1 -1
- package/resources/ledger-account-categories.d.ts.map +1 -1
- package/resources/ledger-account-payouts.d.ts.map +1 -1
- package/resources/ledger-account-statements.d.ts.map +1 -1
- package/resources/ledger-accounts.d.ts +23 -16
- package/resources/ledger-accounts.d.ts.map +1 -1
- package/resources/ledger-accounts.js.map +1 -1
- package/resources/ledger-accounts.mjs.map +1 -1
- package/resources/ledger-entries.d.ts.map +1 -1
- package/resources/ledger-event-handlers.d.ts +4 -0
- package/resources/ledger-event-handlers.d.ts.map +1 -1
- package/resources/ledger-event-handlers.js.map +1 -1
- package/resources/ledger-event-handlers.mjs.map +1 -1
- package/resources/ledger-transactions/ledger-transactions.d.ts +8 -3
- package/resources/ledger-transactions/ledger-transactions.d.ts.map +1 -1
- package/resources/ledger-transactions/ledger-transactions.js.map +1 -1
- package/resources/ledger-transactions/ledger-transactions.mjs.map +1 -1
- package/resources/ledger-transactions/versions.d.ts.map +1 -1
- package/resources/ledgerable-events.d.ts +0 -16
- package/resources/ledgerable-events.d.ts.map +1 -1
- package/resources/ledgerable-events.js.map +1 -1
- package/resources/ledgerable-events.mjs.map +1 -1
- package/resources/ledgers.d.ts.map +1 -1
- package/resources/line-items.d.ts.map +1 -1
- package/resources/paper-items.d.ts.map +1 -1
- package/resources/payment-flows.d.ts.map +1 -1
- package/resources/payment-orders/payment-orders.d.ts +32 -6
- package/resources/payment-orders/payment-orders.d.ts.map +1 -1
- package/resources/payment-orders/payment-orders.js.map +1 -1
- package/resources/payment-orders/payment-orders.mjs.map +1 -1
- package/resources/payment-orders/reversals.d.ts +8 -3
- package/resources/payment-orders/reversals.d.ts.map +1 -1
- package/resources/payment-orders/reversals.js.map +1 -1
- package/resources/payment-orders/reversals.mjs.map +1 -1
- package/resources/payment-references.d.ts.map +1 -1
- package/resources/returns.d.ts.map +1 -1
- package/resources/routing-details.d.ts.map +1 -1
- package/resources/top-level.d.ts.map +1 -1
- package/resources/transactions/line-items.d.ts.map +1 -1
- package/resources/transactions/transactions.d.ts.map +1 -1
- package/resources/transactions/transactions.js.map +1 -1
- package/resources/validations.d.ts.map +1 -1
- package/resources/virtual-accounts.d.ts +59 -3
- package/resources/virtual-accounts.d.ts.map +1 -1
- package/resources/virtual-accounts.js +1 -4
- package/resources/virtual-accounts.js.map +1 -1
- package/resources/virtual-accounts.mjs +1 -4
- package/resources/virtual-accounts.mjs.map +1 -1
- package/src/_shims/fetch.deno.ts +23 -0
- package/src/_shims/fetch.js +1 -1
- package/src/_shims/fileFromPath.node.ts +1 -1
- package/src/_shims/fileFromPath.ts +1 -1
- package/src/_shims/formdata.deno.ts +16 -0
- package/src/_shims/formdata.node.d.ts +1 -0
- package/src/_shims/getMultipartRequestOptions.node.ts +1 -1
- package/src/_shims/getMultipartRequestOptions.ts +1 -1
- package/src/core.ts +123 -34
- package/src/error.ts +19 -1
- package/src/index.ts +47 -28
- package/src/resources/account-collection-flows.ts +19 -19
- package/src/resources/account-details.ts +6 -6
- package/src/resources/connections.ts +5 -5
- package/src/resources/counterparties.ts +8 -8
- package/src/resources/documents.ts +9 -18
- package/src/resources/events.ts +5 -5
- package/src/resources/expected-payments.ts +6 -6
- package/src/resources/external-accounts.ts +8 -8
- package/src/resources/incoming-payment-details.ts +7 -7
- package/src/resources/index.ts +2 -2
- package/src/resources/internal-accounts/balance-reports.ts +6 -6
- package/src/resources/internal-accounts/internal-accounts.ts +15 -14
- package/src/resources/invoices/invoices.ts +121 -13
- package/src/resources/invoices/line-items.ts +51 -6
- package/src/resources/ledger-account-categories.ts +5 -5
- package/src/resources/ledger-account-payouts.ts +5 -5
- package/src/resources/ledger-account-statements.ts +3 -3
- package/src/resources/ledger-accounts.ts +29 -21
- package/src/resources/ledger-entries.ts +5 -5
- package/src/resources/ledger-event-handlers.ts +10 -5
- package/src/resources/ledger-transactions/ledger-transactions.ts +15 -9
- package/src/resources/ledger-transactions/versions.ts +5 -5
- package/src/resources/ledgerable-events.ts +3 -23
- package/src/resources/ledgers.ts +5 -5
- package/src/resources/line-items.ts +5 -5
- package/src/resources/paper-items.ts +6 -6
- package/src/resources/payment-flows.ts +5 -5
- package/src/resources/payment-orders/payment-orders.ts +45 -15
- package/src/resources/payment-orders/reversals.ts +14 -8
- package/src/resources/payment-references.ts +5 -5
- package/src/resources/returns.ts +6 -6
- package/src/resources/routing-details.ts +6 -6
- package/src/resources/top-level.ts +1 -1
- package/src/resources/transactions/line-items.ts +5 -5
- package/src/resources/transactions/transactions.ts +6 -6
- package/src/resources/validations.ts +3 -3
- package/src/resources/virtual-accounts.ts +72 -14
- package/src/resources/webhooks.ts +3 -3
- package/src/uploads.ts +16 -14
- package/src/version.ts +1 -1
- package/uploads.d.ts +6 -5
- package/uploads.d.ts.map +1 -1
- package/uploads.js +4 -3
- package/uploads.js.map +1 -1
- package/uploads.mjs +4 -3
- package/uploads.mjs.map +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
- package/src/streaming.ts +0 -204
- package/streaming.d.ts +0 -14
- package/streaming.d.ts.map +0 -1
- package/streaming.js +0 -155
- package/streaming.js.map +0 -1
- package/streaming.mjs +0 -151
- package/streaming.mjs.map +0 -1
package/uploads.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uploads.mjs","sourceRoot":"","sources":["src/uploads.ts"],"names":[],"mappings":"OAGO,EAAE,QAAQ,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"uploads.mjs","sourceRoot":"","sources":["src/uploads.ts"],"names":[],"mappings":"OAGO,EAAE,QAAQ,EAAE,IAAI,EAAmC,MAAM,iCAAiC;OAC1F,EAAE,0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,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QAC/B,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;KAChF;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QACpC,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,IAAI,GAAG,EAAE,IAAI,CAAC,CAAC,CACzF,CAAC;KACH;SAAM;QACL,MAAM,IAAI,SAAS,CACjB,wGAAwG,KAAK,UAAU,CACxH,CAAC;KACH;AACH,CAAC,CAAC"}
|
package/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = '2.
|
|
1
|
+
export declare const VERSION = '2.2.0';
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/version.js
CHANGED
package/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '2.
|
|
1
|
+
export const VERSION = '2.2.0'; // x-release-please-version
|
|
2
2
|
//# sourceMappingURL=version.mjs.map
|
package/src/streaming.ts
DELETED
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import type { Response } from 'modern-treasury/_shims/fetch';
|
|
2
|
-
import { APIResponse, Headers, createResponseHeaders } from './core';
|
|
3
|
-
|
|
4
|
-
type ServerSentEvent = {
|
|
5
|
-
event: string | null;
|
|
6
|
-
data: string;
|
|
7
|
-
raw: string[];
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
class SSEDecoder {
|
|
11
|
-
private data: string[];
|
|
12
|
-
private event: string | null;
|
|
13
|
-
private chunks: string[];
|
|
14
|
-
|
|
15
|
-
constructor() {
|
|
16
|
-
this.event = null;
|
|
17
|
-
this.data = [];
|
|
18
|
-
this.chunks = [];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
decode(line: string) {
|
|
22
|
-
if (line.endsWith('\r')) {
|
|
23
|
-
line = line.substring(0, line.length - 1);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (!line) {
|
|
27
|
-
// empty line and we didn't previously encounter any messages
|
|
28
|
-
if (!this.event && !this.data.length) return null;
|
|
29
|
-
|
|
30
|
-
const sse: ServerSentEvent = {
|
|
31
|
-
event: this.event,
|
|
32
|
-
data: this.data.join('\n'),
|
|
33
|
-
raw: this.chunks,
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
this.event = null;
|
|
37
|
-
this.data = [];
|
|
38
|
-
this.chunks = [];
|
|
39
|
-
|
|
40
|
-
return sse;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
this.chunks.push(line);
|
|
44
|
-
|
|
45
|
-
if (line.startsWith(':')) {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
let [fieldname, _, value] = partition(line, ':');
|
|
50
|
-
|
|
51
|
-
if (value.startsWith(' ')) {
|
|
52
|
-
value = value.substring(1);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (fieldname === 'event') {
|
|
56
|
-
this.event = value;
|
|
57
|
-
} else if (fieldname === 'data') {
|
|
58
|
-
this.data.push(value);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export class Stream<Item> implements AsyncIterable<Item>, APIResponse<Stream<Item>> {
|
|
66
|
-
/** @deprecated - please use the async iterator instead. We plan to add additional helper methods shortly. */
|
|
67
|
-
response: Response;
|
|
68
|
-
/** @deprecated - we plan to add a different way to access raw response information shortly. */
|
|
69
|
-
responseHeaders: Headers;
|
|
70
|
-
controller: AbortController;
|
|
71
|
-
|
|
72
|
-
private decoder: SSEDecoder;
|
|
73
|
-
|
|
74
|
-
constructor(response: Response, controller: AbortController) {
|
|
75
|
-
this.response = response;
|
|
76
|
-
this.controller = controller;
|
|
77
|
-
this.decoder = new SSEDecoder();
|
|
78
|
-
this.responseHeaders = createResponseHeaders(response.headers);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
private async *iterMessages(): AsyncGenerator<ServerSentEvent, void, unknown> {
|
|
82
|
-
if (!this.response.body) {
|
|
83
|
-
this.controller.abort();
|
|
84
|
-
throw new Error(`Attempted to iterate over a response with no body`);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const lineDecoder = new LineDecoder();
|
|
88
|
-
|
|
89
|
-
// @ts-ignore
|
|
90
|
-
for await (const chunk of this.response.body) {
|
|
91
|
-
let text;
|
|
92
|
-
if (chunk instanceof Buffer) {
|
|
93
|
-
text = chunk.toString();
|
|
94
|
-
} else if ((chunk as any) instanceof Uint8Array) {
|
|
95
|
-
text = Buffer.from(chunk).toString();
|
|
96
|
-
} else {
|
|
97
|
-
text = chunk;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
for (const line of lineDecoder.decode(text)) {
|
|
101
|
-
const sse = this.decoder.decode(line);
|
|
102
|
-
if (sse) yield sse;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
for (const line of lineDecoder.flush()) {
|
|
107
|
-
const sse = this.decoder.decode(line);
|
|
108
|
-
if (sse) yield sse;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
async *[Symbol.asyncIterator](): AsyncIterator<Item, any, undefined> {
|
|
113
|
-
try {
|
|
114
|
-
for await (const sse of this.iterMessages()) {
|
|
115
|
-
try {
|
|
116
|
-
yield JSON.parse(sse.data);
|
|
117
|
-
} catch (e) {
|
|
118
|
-
console.error(`Could not parse message into JSON:`, sse.data);
|
|
119
|
-
console.error(`From chunk:`, sse.raw);
|
|
120
|
-
throw e;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
} catch (e) {
|
|
124
|
-
// If the user calls `stream.controller.abort()`, we should exit without throwing.
|
|
125
|
-
if (e instanceof Error && e.name === 'AbortError') return;
|
|
126
|
-
throw e;
|
|
127
|
-
} finally {
|
|
128
|
-
// If the user `break`s, abort the ongoing request.
|
|
129
|
-
this.controller.abort();
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const NEWLINE_CHARS = '\n\r\x0b\x0c\x1c\x1d\x1e\x85\u2028\u2029';
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* A re-implementation of httpx's `LineDecoder` in Python that handles incrementally
|
|
138
|
-
* reading lines from text.
|
|
139
|
-
*
|
|
140
|
-
* https://github.com/encode/httpx/blob/920333ea98118e9cf617f246905d7b202510941c/httpx/_decoders.py#L258
|
|
141
|
-
*/
|
|
142
|
-
class LineDecoder {
|
|
143
|
-
buffer: string[];
|
|
144
|
-
trailingCR: boolean;
|
|
145
|
-
|
|
146
|
-
constructor() {
|
|
147
|
-
this.buffer = [];
|
|
148
|
-
this.trailingCR = false;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
decode(text: string): string[] {
|
|
152
|
-
if (this.trailingCR) {
|
|
153
|
-
text = '\r' + text;
|
|
154
|
-
this.trailingCR = false;
|
|
155
|
-
}
|
|
156
|
-
if (text.endsWith('\r')) {
|
|
157
|
-
this.trailingCR = true;
|
|
158
|
-
text = text.slice(0, -1);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (!text) {
|
|
162
|
-
return [];
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const trailing_newline = NEWLINE_CHARS.includes(text.slice(-1));
|
|
166
|
-
let lines = text.split(/\r\n|[\n\r\x0b\x0c\x1c\x1d\x1e\x85\u2028\u2029]/g);
|
|
167
|
-
|
|
168
|
-
if (lines.length === 1 && !trailing_newline) {
|
|
169
|
-
this.buffer.push(lines[0]!);
|
|
170
|
-
return [];
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (this.buffer.length > 0) {
|
|
174
|
-
lines = [this.buffer.join('') + lines[0], ...lines.slice(1)];
|
|
175
|
-
this.buffer = [];
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if (!trailing_newline) {
|
|
179
|
-
this.buffer = [lines.pop() || ''];
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return lines;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
flush(): string[] {
|
|
186
|
-
if (!this.buffer.length && !this.trailingCR) {
|
|
187
|
-
return [];
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const lines = [this.buffer.join('')];
|
|
191
|
-
this.buffer = [];
|
|
192
|
-
this.trailingCR = false;
|
|
193
|
-
return lines;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
function partition(str: string, delimiter: string): [string, string, string] {
|
|
198
|
-
const index = str.indexOf(delimiter);
|
|
199
|
-
if (index !== -1) {
|
|
200
|
-
return [str.substring(0, index), delimiter, str.substring(index + delimiter.length)];
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return [str, '', ''];
|
|
204
|
-
}
|
package/streaming.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Response } from 'modern-treasury/_shims/fetch';
|
|
2
|
-
import { APIResponse, Headers } from './core.js';
|
|
3
|
-
export declare class Stream<Item> implements AsyncIterable<Item>, APIResponse<Stream<Item>> {
|
|
4
|
-
/** @deprecated - please use the async iterator instead. We plan to add additional helper methods shortly. */
|
|
5
|
-
response: Response;
|
|
6
|
-
/** @deprecated - we plan to add a different way to access raw response information shortly. */
|
|
7
|
-
responseHeaders: Headers;
|
|
8
|
-
controller: AbortController;
|
|
9
|
-
private decoder;
|
|
10
|
-
constructor(response: Response, controller: AbortController);
|
|
11
|
-
private iterMessages;
|
|
12
|
-
[Symbol.asyncIterator](): AsyncIterator<Item, any, undefined>;
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=streaming.d.ts.map
|
package/streaming.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["src/streaming.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,OAAO,EAAyB,MAAM,QAAQ,CAAC;AA+DrE,qBAAa,MAAM,CAAC,IAAI,CAAE,YAAW,aAAa,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACjF,6GAA6G;IAC7G,QAAQ,EAAE,QAAQ,CAAC;IACnB,+FAA+F;IAC/F,eAAe,EAAE,OAAO,CAAC;IACzB,UAAU,EAAE,eAAe,CAAC;IAE5B,OAAO,CAAC,OAAO,CAAa;gBAEhB,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,eAAe;YAO5C,YAAY;IA+BpB,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,IAAI,EAAE,GAAG,EAAE,SAAS,CAAC;CAoBrE"}
|
package/streaming.js
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
-
exports.Stream = void 0;
|
|
4
|
-
const core_1 = require('./core.js');
|
|
5
|
-
class SSEDecoder {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.event = null;
|
|
8
|
-
this.data = [];
|
|
9
|
-
this.chunks = [];
|
|
10
|
-
}
|
|
11
|
-
decode(line) {
|
|
12
|
-
if (line.endsWith('\r')) {
|
|
13
|
-
line = line.substring(0, line.length - 1);
|
|
14
|
-
}
|
|
15
|
-
if (!line) {
|
|
16
|
-
// empty line and we didn't previously encounter any messages
|
|
17
|
-
if (!this.event && !this.data.length) return null;
|
|
18
|
-
const sse = {
|
|
19
|
-
event: this.event,
|
|
20
|
-
data: this.data.join('\n'),
|
|
21
|
-
raw: this.chunks,
|
|
22
|
-
};
|
|
23
|
-
this.event = null;
|
|
24
|
-
this.data = [];
|
|
25
|
-
this.chunks = [];
|
|
26
|
-
return sse;
|
|
27
|
-
}
|
|
28
|
-
this.chunks.push(line);
|
|
29
|
-
if (line.startsWith(':')) {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
let [fieldname, _, value] = partition(line, ':');
|
|
33
|
-
if (value.startsWith(' ')) {
|
|
34
|
-
value = value.substring(1);
|
|
35
|
-
}
|
|
36
|
-
if (fieldname === 'event') {
|
|
37
|
-
this.event = value;
|
|
38
|
-
} else if (fieldname === 'data') {
|
|
39
|
-
this.data.push(value);
|
|
40
|
-
}
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
class Stream {
|
|
45
|
-
constructor(response, controller) {
|
|
46
|
-
this.response = response;
|
|
47
|
-
this.controller = controller;
|
|
48
|
-
this.decoder = new SSEDecoder();
|
|
49
|
-
this.responseHeaders = (0, core_1.createResponseHeaders)(response.headers);
|
|
50
|
-
}
|
|
51
|
-
async *iterMessages() {
|
|
52
|
-
if (!this.response.body) {
|
|
53
|
-
this.controller.abort();
|
|
54
|
-
throw new Error(`Attempted to iterate over a response with no body`);
|
|
55
|
-
}
|
|
56
|
-
const lineDecoder = new LineDecoder();
|
|
57
|
-
// @ts-ignore
|
|
58
|
-
for await (const chunk of this.response.body) {
|
|
59
|
-
let text;
|
|
60
|
-
if (chunk instanceof Buffer) {
|
|
61
|
-
text = chunk.toString();
|
|
62
|
-
} else if (chunk instanceof Uint8Array) {
|
|
63
|
-
text = Buffer.from(chunk).toString();
|
|
64
|
-
} else {
|
|
65
|
-
text = chunk;
|
|
66
|
-
}
|
|
67
|
-
for (const line of lineDecoder.decode(text)) {
|
|
68
|
-
const sse = this.decoder.decode(line);
|
|
69
|
-
if (sse) yield sse;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
for (const line of lineDecoder.flush()) {
|
|
73
|
-
const sse = this.decoder.decode(line);
|
|
74
|
-
if (sse) yield sse;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
async *[Symbol.asyncIterator]() {
|
|
78
|
-
try {
|
|
79
|
-
for await (const sse of this.iterMessages()) {
|
|
80
|
-
try {
|
|
81
|
-
yield JSON.parse(sse.data);
|
|
82
|
-
} catch (e) {
|
|
83
|
-
console.error(`Could not parse message into JSON:`, sse.data);
|
|
84
|
-
console.error(`From chunk:`, sse.raw);
|
|
85
|
-
throw e;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
} catch (e) {
|
|
89
|
-
// If the user calls `stream.controller.abort()`, we should exit without throwing.
|
|
90
|
-
if (e instanceof Error && e.name === 'AbortError') return;
|
|
91
|
-
throw e;
|
|
92
|
-
} finally {
|
|
93
|
-
// If the user `break`s, abort the ongoing request.
|
|
94
|
-
this.controller.abort();
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
exports.Stream = Stream;
|
|
99
|
-
const NEWLINE_CHARS = '\n\r\x0b\x0c\x1c\x1d\x1e\x85\u2028\u2029';
|
|
100
|
-
/**
|
|
101
|
-
* A re-implementation of httpx's `LineDecoder` in Python that handles incrementally
|
|
102
|
-
* reading lines from text.
|
|
103
|
-
*
|
|
104
|
-
* https://github.com/encode/httpx/blob/920333ea98118e9cf617f246905d7b202510941c/httpx/_decoders.py#L258
|
|
105
|
-
*/
|
|
106
|
-
class LineDecoder {
|
|
107
|
-
constructor() {
|
|
108
|
-
this.buffer = [];
|
|
109
|
-
this.trailingCR = false;
|
|
110
|
-
}
|
|
111
|
-
decode(text) {
|
|
112
|
-
if (this.trailingCR) {
|
|
113
|
-
text = '\r' + text;
|
|
114
|
-
this.trailingCR = false;
|
|
115
|
-
}
|
|
116
|
-
if (text.endsWith('\r')) {
|
|
117
|
-
this.trailingCR = true;
|
|
118
|
-
text = text.slice(0, -1);
|
|
119
|
-
}
|
|
120
|
-
if (!text) {
|
|
121
|
-
return [];
|
|
122
|
-
}
|
|
123
|
-
const trailing_newline = NEWLINE_CHARS.includes(text.slice(-1));
|
|
124
|
-
let lines = text.split(/\r\n|[\n\r\x0b\x0c\x1c\x1d\x1e\x85\u2028\u2029]/g);
|
|
125
|
-
if (lines.length === 1 && !trailing_newline) {
|
|
126
|
-
this.buffer.push(lines[0]);
|
|
127
|
-
return [];
|
|
128
|
-
}
|
|
129
|
-
if (this.buffer.length > 0) {
|
|
130
|
-
lines = [this.buffer.join('') + lines[0], ...lines.slice(1)];
|
|
131
|
-
this.buffer = [];
|
|
132
|
-
}
|
|
133
|
-
if (!trailing_newline) {
|
|
134
|
-
this.buffer = [lines.pop() || ''];
|
|
135
|
-
}
|
|
136
|
-
return lines;
|
|
137
|
-
}
|
|
138
|
-
flush() {
|
|
139
|
-
if (!this.buffer.length && !this.trailingCR) {
|
|
140
|
-
return [];
|
|
141
|
-
}
|
|
142
|
-
const lines = [this.buffer.join('')];
|
|
143
|
-
this.buffer = [];
|
|
144
|
-
this.trailingCR = false;
|
|
145
|
-
return lines;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
function partition(str, delimiter) {
|
|
149
|
-
const index = str.indexOf(delimiter);
|
|
150
|
-
if (index !== -1) {
|
|
151
|
-
return [str.substring(0, index), delimiter, str.substring(index + delimiter.length)];
|
|
152
|
-
}
|
|
153
|
-
return [str, '', ''];
|
|
154
|
-
}
|
|
155
|
-
//# sourceMappingURL=streaming.js.map
|
package/streaming.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"streaming.js","sourceRoot":"","sources":["src/streaming.ts"],"names":[],"mappings":";;;AACA,oCAAqE;AAQrE,MAAM,UAAU;IAKd;QACE,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;QACf,IAAI,C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CAAC;QACxB,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED,SAAS,SAAS,CAAC,GAAW,EAAE,SAAiB;IAC/C,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACrC,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE;QAChB,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,SAAS,EAAE,GAAG,CAAC,SAAS,CAAC,KAAK,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;KACtF;IAED,OAAO,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AACvB,CAAC"}
|
package/streaming.mjs
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { createResponseHeaders } from './core.mjs';
|
|
2
|
-
class SSEDecoder {
|
|
3
|
-
constructor() {
|
|
4
|
-
this.event = null;
|
|
5
|
-
this.data = [];
|
|
6
|
-
this.chunks = [];
|
|
7
|
-
}
|
|
8
|
-
decode(line) {
|
|
9
|
-
if (line.endsWith('\r')) {
|
|
10
|
-
line = line.substring(0, line.length - 1);
|
|
11
|
-
}
|
|
12
|
-
if (!line) {
|
|
13
|
-
// empty line and we didn't previously encounter any messages
|
|
14
|
-
if (!this.event && !this.data.length) return null;
|
|
15
|
-
const sse = {
|
|
16
|
-
event: this.event,
|
|
17
|
-
data: this.data.join('\n'),
|
|
18
|
-
raw: this.chunks,
|
|
19
|
-
};
|
|
20
|
-
this.event = null;
|
|
21
|
-
this.data = [];
|
|
22
|
-
this.chunks = [];
|
|
23
|
-
return sse;
|
|
24
|
-
}
|
|
25
|
-
this.chunks.push(line);
|
|
26
|
-
if (line.startsWith(':')) {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
let [fieldname, _, value] = partition(line, ':');
|
|
30
|
-
if (value.startsWith(' ')) {
|
|
31
|
-
value = value.substring(1);
|
|
32
|
-
}
|
|
33
|
-
if (fieldname === 'event') {
|
|
34
|
-
this.event = value;
|
|
35
|
-
} else if (fieldname === 'data') {
|
|
36
|
-
this.data.push(value);
|
|
37
|
-
}
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
export class Stream {
|
|
42
|
-
constructor(response, controller) {
|
|
43
|
-
this.response = response;
|
|
44
|
-
this.controller = controller;
|
|
45
|
-
this.decoder = new SSEDecoder();
|
|
46
|
-
this.responseHeaders = createResponseHeaders(response.headers);
|
|
47
|
-
}
|
|
48
|
-
async *iterMessages() {
|
|
49
|
-
if (!this.response.body) {
|
|
50
|
-
this.controller.abort();
|
|
51
|
-
throw new Error(`Attempted to iterate over a response with no body`);
|
|
52
|
-
}
|
|
53
|
-
const lineDecoder = new LineDecoder();
|
|
54
|
-
// @ts-ignore
|
|
55
|
-
for await (const chunk of this.response.body) {
|
|
56
|
-
let text;
|
|
57
|
-
if (chunk instanceof Buffer) {
|
|
58
|
-
text = chunk.toString();
|
|
59
|
-
} else if (chunk instanceof Uint8Array) {
|
|
60
|
-
text = Buffer.from(chunk).toString();
|
|
61
|
-
} else {
|
|
62
|
-
text = chunk;
|
|
63
|
-
}
|
|
64
|
-
for (const line of lineDecoder.decode(text)) {
|
|
65
|
-
const sse = this.decoder.decode(line);
|
|
66
|
-
if (sse) yield sse;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
for (const line of lineDecoder.flush()) {
|
|
70
|
-
const sse = this.decoder.decode(line);
|
|
71
|
-
if (sse) yield sse;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
async *[Symbol.asyncIterator]() {
|
|
75
|
-
try {
|
|
76
|
-
for await (const sse of this.iterMessages()) {
|
|
77
|
-
try {
|
|
78
|
-
yield JSON.parse(sse.data);
|
|
79
|
-
} catch (e) {
|
|
80
|
-
console.error(`Could not parse message into JSON:`, sse.data);
|
|
81
|
-
console.error(`From chunk:`, sse.raw);
|
|
82
|
-
throw e;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
} catch (e) {
|
|
86
|
-
// If the user calls `stream.controller.abort()`, we should exit without throwing.
|
|
87
|
-
if (e instanceof Error && e.name === 'AbortError') return;
|
|
88
|
-
throw e;
|
|
89
|
-
} finally {
|
|
90
|
-
// If the user `break`s, abort the ongoing request.
|
|
91
|
-
this.controller.abort();
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
const NEWLINE_CHARS = '\n\r\x0b\x0c\x1c\x1d\x1e\x85\u2028\u2029';
|
|
96
|
-
/**
|
|
97
|
-
* A re-implementation of httpx's `LineDecoder` in Python that handles incrementally
|
|
98
|
-
* reading lines from text.
|
|
99
|
-
*
|
|
100
|
-
* https://github.com/encode/httpx/blob/920333ea98118e9cf617f246905d7b202510941c/httpx/_decoders.py#L258
|
|
101
|
-
*/
|
|
102
|
-
class LineDecoder {
|
|
103
|
-
constructor() {
|
|
104
|
-
this.buffer = [];
|
|
105
|
-
this.trailingCR = false;
|
|
106
|
-
}
|
|
107
|
-
decode(text) {
|
|
108
|
-
if (this.trailingCR) {
|
|
109
|
-
text = '\r' + text;
|
|
110
|
-
this.trailingCR = false;
|
|
111
|
-
}
|
|
112
|
-
if (text.endsWith('\r')) {
|
|
113
|
-
this.trailingCR = true;
|
|
114
|
-
text = text.slice(0, -1);
|
|
115
|
-
}
|
|
116
|
-
if (!text) {
|
|
117
|
-
return [];
|
|
118
|
-
}
|
|
119
|
-
const trailing_newline = NEWLINE_CHARS.includes(text.slice(-1));
|
|
120
|
-
let lines = text.split(/\r\n|[\n\r\x0b\x0c\x1c\x1d\x1e\x85\u2028\u2029]/g);
|
|
121
|
-
if (lines.length === 1 && !trailing_newline) {
|
|
122
|
-
this.buffer.push(lines[0]);
|
|
123
|
-
return [];
|
|
124
|
-
}
|
|
125
|
-
if (this.buffer.length > 0) {
|
|
126
|
-
lines = [this.buffer.join('') + lines[0], ...lines.slice(1)];
|
|
127
|
-
this.buffer = [];
|
|
128
|
-
}
|
|
129
|
-
if (!trailing_newline) {
|
|
130
|
-
this.buffer = [lines.pop() || ''];
|
|
131
|
-
}
|
|
132
|
-
return lines;
|
|
133
|
-
}
|
|
134
|
-
flush() {
|
|
135
|
-
if (!this.buffer.length && !this.trailingCR) {
|
|
136
|
-
return [];
|
|
137
|
-
}
|
|
138
|
-
const lines = [this.buffer.join('')];
|
|
139
|
-
this.buffer = [];
|
|
140
|
-
this.trailingCR = false;
|
|
141
|
-
return lines;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
function partition(str, delimiter) {
|
|
145
|
-
const index = str.indexOf(delimiter);
|
|
146
|
-
if (index !== -1) {
|
|
147
|
-
return [str.substring(0, index), delimiter, str.substring(index + delimiter.length)];
|
|
148
|
-
}
|
|
149
|
-
return [str, '', ''];
|
|
150
|
-
}
|
|
151
|
-
//# sourceMappingURL=streaming.mjs.map
|
package/streaming.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"streaming.mjs","sourceRoot":"","sources":["src/streaming.ts"],"names":[],"mappings":"OACO,EAAwB,qBAAqB,EAAE;AAQtD,MAAM,UAAU;IAKd;QACE,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACnB,CAAC;IAED,MAAM,CAAC,IAAY;QACjB,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;YACvB,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;SAC3C;QAED,IAAI,CAAC,IAAI,EAAE;YACT,6DAA6D;YAC7D,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM;gBAAE,OAAO,IAAI,CAAC;YAElD,MAAM,GAAG,GAAoB;gBAC3B,KAAK,EAAE,IAAI,CAA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