@interactive-inc/flume 0.6.0 → 0.9.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 +156 -62
- package/dist/discord.d.ts +1 -1
- package/dist/discord.js +5 -4
- package/dist/{flume-source-DuUFPhSe.d.ts → flume-source.d.ts} +52 -11
- package/dist/{flume-source-DUvt9aJt.js → flume-source.js} +7 -4
- package/dist/github.d.ts +1 -1
- package/dist/github.js +12 -7
- package/dist/index.d.ts +146 -43
- package/dist/index.js +294 -83
- package/dist/is-record.js +6 -0
- package/dist/parse-error.d.ts +9 -0
- package/dist/{safe-json-parse-CfJjt-RY.js → safe-json-parse.js} +1 -1
- package/dist/{safe-read-text-JQd_5vbd.js → safe-read-text.js} +2 -2
- package/dist/{safe-stringify-DbWQw9qe.js → safe-stringify.js} +7 -13
- package/dist/slack.d.ts +1 -1
- package/dist/slack.js +13 -8
- package/dist/time.d.ts +45 -0
- package/dist/time.js +319 -0
- package/package.json +6 -1
- /package/dist/{connection-error-HUO3PC3G.js → connection-error.js} +0 -0
- /package/dist/{http-error-CPSKoSie.js → http-error.js} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import { C as
|
|
1
|
+
import { A as FlumeStreamOverflow, C as FlumeSourceName, D as FlumeStreamHandler, E as FlumeStatus, F as FlumeTimerHandle, I as FlumeLogger, M as FlumeTimeMessage, N as FlumeTimeSourceOptions, O as FlumeStreamItem, P as FlumeTimeTick, S as FlumeSourceLocalStatusHandler, T as FlumeSourceStatus, _ as FlumeRuntimeDeps, a as FlumeEvent, b as FlumeSlackEvent, c as FlumeGitHubEvent, d as FlumeLog, f as FlumeLogHandler, g as FlumeReconnectOptions, h as FlumeReconnectConfig, i as FlumeErrorHandler, j as FlumeTimeEvent, k as FlumeStreamOptions, l as FlumeGitHubNotification, m as FlumeLogLevel, n as FlumeDiscordEvent, o as FlumeEventHandler, p as FlumeLogInput, r as FlumeDiscordSourceOptions, s as FlumeGatewayMessage, t as FlumeSource, u as FlumeGitHubSourceOptions, v as FlumeSlackConnectionResponse, w as FlumeSourceStartContext, x as FlumeSlackSourceOptions, y as FlumeSlackEnvelope } from "./flume-source.js";
|
|
2
|
+
import { t as FlumeParseError } from "./parse-error.js";
|
|
2
3
|
|
|
3
4
|
//#region lib/deps.d.ts
|
|
4
5
|
/**
|
|
5
6
|
* platform 既定の IO を束ねた `FlumeRuntimeDeps`。
|
|
6
7
|
* `FlumeTimerHandle` は不透明型 (`unknown`) のため、setTimeout / clearTimeout の戻り値・引数を
|
|
7
|
-
* platform 型と橋渡しする際に境界で `as unknown as` を使う (IO 境界の最終手段)
|
|
8
|
+
* platform 型と橋渡しする際に境界で `as unknown as` を使う (IO 境界の最終手段)。
|
|
9
|
+
*
|
|
10
|
+
* `WebSocket` を含む全 IO は呼び出しごとに `globalThis` から引く lazy lookup。
|
|
11
|
+
* モジュール初期化後に `globalThis.WebSocket` が差し替わる環境
|
|
12
|
+
* (テストの `beforeEach` パッチ、jsdom などのブラウザ環境エミュレータ) でも
|
|
13
|
+
* `createFlumeDefaultDeps()` が返した deps が常に最新の参照を見る。
|
|
8
14
|
*/
|
|
9
15
|
declare function createFlumeDefaultDeps(): FlumeRuntimeDeps;
|
|
10
16
|
//#endregion
|
|
11
17
|
//#region lib/errors/connection-error.d.ts
|
|
12
|
-
type Options$
|
|
18
|
+
type Options$1 = {
|
|
13
19
|
cause?: unknown;
|
|
14
20
|
code?: number;
|
|
15
21
|
};
|
|
@@ -19,107 +25,204 @@ type Options$3 = {
|
|
|
19
25
|
*/
|
|
20
26
|
declare class FlumeConnectionError extends Error {
|
|
21
27
|
readonly code: number | null;
|
|
22
|
-
constructor(message: string, options?: Options$
|
|
28
|
+
constructor(message: string, options?: Options$1);
|
|
23
29
|
}
|
|
24
30
|
//#endregion
|
|
25
31
|
//#region lib/errors/http-error.d.ts
|
|
26
|
-
type Props$
|
|
32
|
+
type Props$4 = {
|
|
27
33
|
message: string;
|
|
28
34
|
status: number;
|
|
29
35
|
cause?: unknown;
|
|
30
36
|
};
|
|
31
37
|
declare class FlumeHttpError extends Error {
|
|
32
38
|
readonly status: number;
|
|
33
|
-
constructor(props: Props$
|
|
39
|
+
constructor(props: Props$4);
|
|
34
40
|
}
|
|
35
41
|
//#endregion
|
|
36
|
-
//#region lib/errors/
|
|
37
|
-
type Options
|
|
42
|
+
//#region lib/errors/start-error.d.ts
|
|
43
|
+
type Options = {
|
|
38
44
|
cause?: unknown;
|
|
39
45
|
};
|
|
40
|
-
declare class
|
|
41
|
-
constructor(message: string, options?: Options
|
|
46
|
+
declare class FlumeStartError extends Error {
|
|
47
|
+
constructor(message: string, options?: Options);
|
|
42
48
|
}
|
|
43
49
|
//#endregion
|
|
44
|
-
//#region lib/
|
|
45
|
-
type
|
|
46
|
-
|
|
50
|
+
//#region lib/flume-stream.d.ts
|
|
51
|
+
type Props$3 = {
|
|
52
|
+
buffer: number;
|
|
53
|
+
onOverflow: FlumeStreamOverflow;
|
|
54
|
+
onClose: () => void;
|
|
47
55
|
};
|
|
48
|
-
|
|
49
|
-
|
|
56
|
+
/**
|
|
57
|
+
* push (`FlumeStreamHub.publish`) を pull (`for await`) に変換する async iterator。
|
|
58
|
+
* consumer が待っていれば即 resolve、いなければ buffer に積み、溢れたら onOverflow に従う。
|
|
59
|
+
* `return()` (break / 例外) と hub.close() のどちらでも自然に done へ落ちる
|
|
60
|
+
*/
|
|
61
|
+
declare class FlumeStream implements AsyncIterableIterator<FlumeStreamItem> {
|
|
62
|
+
private readonly props;
|
|
63
|
+
private readonly items;
|
|
64
|
+
private readonly resolvers;
|
|
65
|
+
private closed;
|
|
66
|
+
constructor(props: Props$3);
|
|
67
|
+
push(item: FlumeStreamItem): void;
|
|
68
|
+
close(): void;
|
|
69
|
+
next(): Promise<IteratorResult<FlumeStreamItem>>;
|
|
70
|
+
return(): Promise<IteratorResult<FlumeStreamItem>>;
|
|
71
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<FlumeStreamItem>;
|
|
50
72
|
}
|
|
51
73
|
//#endregion
|
|
52
|
-
//#region lib/flume-
|
|
53
|
-
|
|
74
|
+
//#region lib/flume-stream-hub.d.ts
|
|
75
|
+
/**
|
|
76
|
+
* firehose (`onEvent` / `stream()`) の item を複数の pull consumer へ fan-out する内部ハブ。
|
|
77
|
+
* subscriber が居なければ publish は実質 no-op。Flume 停止時に close() で全 stream を終端する
|
|
78
|
+
*/
|
|
79
|
+
declare class FlumeStreamHub {
|
|
80
|
+
private readonly streams;
|
|
81
|
+
private closed;
|
|
82
|
+
publish(item: FlumeStreamItem): void;
|
|
83
|
+
subscribe(options?: FlumeStreamOptions): FlumeStream;
|
|
84
|
+
close(): void;
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region lib/flume-closed.d.ts
|
|
88
|
+
type FlumeCloseError = {
|
|
89
|
+
source: string;
|
|
90
|
+
error: Error;
|
|
91
|
+
};
|
|
92
|
+
type Props$2 = {
|
|
54
93
|
finalStatuses: ReadonlyArray<FlumeSourceStatus>;
|
|
94
|
+
closeErrors: ReadonlyArray<FlumeCloseError>;
|
|
55
95
|
};
|
|
56
96
|
/**
|
|
57
|
-
*
|
|
97
|
+
* 停止済みの終端状態。最終ステータスと、停止時に source.disconnect が throw した
|
|
98
|
+
* エラー一覧を観測できる。`errors()` を読めば `onLog` を grep せずに「どの source が
|
|
99
|
+
* きれいに close したか / どれが失敗したか」を直接判定できる
|
|
58
100
|
*/
|
|
59
|
-
declare class
|
|
101
|
+
declare class FlumeClosed {
|
|
60
102
|
private readonly props;
|
|
61
|
-
readonly kind: "
|
|
62
|
-
constructor(props: Props$
|
|
103
|
+
readonly kind: "closed";
|
|
104
|
+
constructor(props: Props$2);
|
|
63
105
|
statuses(): ReadonlyArray<FlumeSourceStatus>;
|
|
106
|
+
/**
|
|
107
|
+
* `runClose` 中に `source.stop()` が rejected で settle した source の名前と
|
|
108
|
+
* 正規化済み Error の組。`onEvent` firehose の `flume.close.failed` log と 1:1 対応する。
|
|
109
|
+
* 全 source が clean close した場合は空配列。
|
|
110
|
+
*/
|
|
111
|
+
errors(): ReadonlyArray<FlumeCloseError>;
|
|
64
112
|
}
|
|
65
113
|
//#endregion
|
|
66
114
|
//#region lib/flume-running.d.ts
|
|
67
|
-
type Props = {
|
|
115
|
+
type Props$1 = {
|
|
68
116
|
sources: ReadonlyArray<FlumeSource>;
|
|
69
117
|
signal?: AbortSignal;
|
|
70
118
|
log: FlumeLogger;
|
|
119
|
+
hub: FlumeStreamHub;
|
|
71
120
|
};
|
|
72
121
|
/**
|
|
73
|
-
* 稼働中の Flume。
|
|
122
|
+
* 稼働中の Flume。close() で FlumeClosed へ遷移する。signal が abort されると自動 close。
|
|
74
123
|
* 全ての source 呼び出し・signal 操作・status 読み取りを `attempt` 経由で扱い、
|
|
75
|
-
* `
|
|
124
|
+
* `runClose` の最外殻 try/catch で想定外の throw も `FlumeClosed` の resolve に変換する
|
|
76
125
|
*/
|
|
77
126
|
declare class FlumeRunning {
|
|
78
127
|
private readonly props;
|
|
79
128
|
readonly kind: "running";
|
|
80
|
-
private
|
|
129
|
+
private closePromise;
|
|
81
130
|
private readonly onAbort;
|
|
82
|
-
constructor(props: Props);
|
|
83
|
-
|
|
131
|
+
constructor(props: Props$1);
|
|
132
|
+
close(): Promise<FlumeClosed>;
|
|
84
133
|
statuses(): ReadonlyArray<FlumeSourceStatus>;
|
|
85
|
-
|
|
134
|
+
/**
|
|
135
|
+
* 統合 firehose を pull で受け取る async iterator。`for await (const item of running.stream())`。
|
|
136
|
+
* item は events + 全ログの union (`FlumeStreamItem`)。`item.kind` で判別する。
|
|
137
|
+
* close() / signal abort で iterator は自然に終了し、`break` すると hub から自動 unsubscribe する。
|
|
138
|
+
* consumer が遅れて buffer を超えたら `onOverflow` (既定 drop-oldest) に従う
|
|
139
|
+
*/
|
|
140
|
+
stream(options?: FlumeStreamOptions): AsyncIterableIterator<FlumeStreamItem>;
|
|
141
|
+
/**
|
|
142
|
+
* Host が `Flume({ signal })` で渡した AbortSignal をそのまま公開する。
|
|
143
|
+
* 直接の controller を持っていない呼び出し元が `running.signal?.aborted`
|
|
144
|
+
* で abort 状態を確認できる
|
|
145
|
+
*/
|
|
146
|
+
get signal(): AbortSignal | undefined;
|
|
147
|
+
private runClose;
|
|
86
148
|
private snapshotStatuses;
|
|
87
149
|
private sourceName;
|
|
88
150
|
}
|
|
89
151
|
//#endregion
|
|
90
152
|
//#region lib/flume.d.ts
|
|
91
|
-
type
|
|
92
|
-
|
|
153
|
+
type FlumeOptions = {
|
|
154
|
+
/** 統合する Source 群 (必須) */sources: ReadonlyArray<FlumeSource>;
|
|
155
|
+
/**
|
|
156
|
+
* 統合 firehose (push)。events と全レベルのログを `FlumeStreamItem` の union で受ける。
|
|
157
|
+
* 使う側が `item.kind` ("event" | "log") と `item.log.level` で filter する。
|
|
158
|
+
* pull 版は `FlumeRunning.stream()`
|
|
159
|
+
*/
|
|
160
|
+
onEvent?: FlumeStreamHandler; /** error レベルのログだけ (Sentry など error 専用の送信先用途)。firehose の error 部分の便利フィルタ */
|
|
161
|
+
onError?: FlumeErrorHandler;
|
|
93
162
|
signal?: AbortSignal;
|
|
94
|
-
onLog?: FlumeLogHandler;
|
|
95
|
-
onStatus?: FlumeStatusHandler;
|
|
96
163
|
deps?: FlumeRuntimeDeps;
|
|
97
164
|
reconnect?: FlumeReconnectOptions;
|
|
98
165
|
};
|
|
99
166
|
/**
|
|
100
|
-
* 起動前の Flume。`
|
|
101
|
-
*
|
|
102
|
-
* `onEvent`
|
|
167
|
+
* 起動前の Flume。`open()` で `FlumeRunning` へ遷移する。
|
|
168
|
+
* コンストラクタは単一オブジェクト `{ sources, ...options }` を受け取る (`sources` のみ必須)。
|
|
169
|
+
* events も全ログも 1 本の firehose (`onEvent` push / `stream()` pull) に流れ、購読側が filter する。
|
|
103
170
|
* いずれかの source 失敗時は既に成功した source を全て `stop()` してロールバックし
|
|
104
171
|
* `FlumeStartError` を返す。
|
|
105
172
|
* `source.start()` / `source.stop()` の sync throw も `Promise.resolve().then` 経由で
|
|
106
|
-
* Promise rejection に正規化して `allSettled` で捕捉する (`
|
|
173
|
+
* Promise rejection に正規化して `allSettled` で捕捉する (`open()` は決して reject しない)
|
|
107
174
|
*/
|
|
108
175
|
declare class Flume {
|
|
109
|
-
private readonly sources;
|
|
110
176
|
private readonly options;
|
|
111
177
|
private consumed;
|
|
112
178
|
private readonly log;
|
|
113
179
|
private readonly deps;
|
|
114
|
-
private readonly
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
180
|
+
private readonly sources;
|
|
181
|
+
private readonly sourceEventHandler;
|
|
182
|
+
private readonly hub;
|
|
183
|
+
constructor(options: FlumeOptions);
|
|
184
|
+
/** source が受信したログを firehose へ流す handler。error は onError にも分岐する */
|
|
185
|
+
private buildLogHandler;
|
|
186
|
+
/**
|
|
187
|
+
* firehose の単一 sink: pull の hub と push の onEvent の両方へ item を配る。
|
|
188
|
+
* onEvent への転送は this.log を経由しない (経由すると log item 経路で再帰する) ため
|
|
189
|
+
* 例外をここで握り潰す
|
|
190
|
+
*/
|
|
191
|
+
private emitItem;
|
|
192
|
+
open(): Promise<FlumeRunning | FlumeStartError>;
|
|
193
|
+
private guardOpen;
|
|
118
194
|
private isSignalAborted;
|
|
119
195
|
private sourceName;
|
|
120
196
|
private safeStart;
|
|
121
|
-
private notifyStatus;
|
|
122
197
|
private rollback;
|
|
123
198
|
}
|
|
124
199
|
//#endregion
|
|
125
|
-
|
|
200
|
+
//#region lib/flume-confluence.d.ts
|
|
201
|
+
type Props = {
|
|
202
|
+
/** 配下の全 Flume の firehose をここへ合流させる単一 sink */onEvent?: FlumeStreamHandler; /** error レベル log だけ (全 Flume 共通) */
|
|
203
|
+
onError?: FlumeErrorHandler;
|
|
204
|
+
deps?: FlumeRuntimeDeps;
|
|
205
|
+
reconnect?: FlumeReconnectOptions;
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* 複数の `Flume` を束ねて動的に増減させる上位レイヤー。各 Flume は immutable のまま、
|
|
209
|
+
* `add()` で新しいグループを起動し `remove()` で個別に停止する。全グループの firehose は
|
|
210
|
+
* `onEvent` 1 本に合流する。Flume 本体の FSM / rollback / reconnect はそのまま再利用される。
|
|
211
|
+
*
|
|
212
|
+
* id はグループの管理ハンドル (add/remove 用)。合流ストリーム自体は id を持たず、
|
|
213
|
+
* item の中の source 名で発信元を判別する。throw しない流儀に従い `add()` は `Error | null` を返す
|
|
214
|
+
*/
|
|
215
|
+
declare class FlumeConfluence {
|
|
216
|
+
private readonly props;
|
|
217
|
+
private readonly running;
|
|
218
|
+
constructor(props?: Props);
|
|
219
|
+
/** sources を 1 グループとして起動。id 重複や起動失敗は `Error` で返す (throw しない) */
|
|
220
|
+
add(id: string, sources: ReadonlyArray<FlumeSource>): Promise<Error | null>;
|
|
221
|
+
/** 指定グループだけ close。他グループは無停止。未知の id は no-op */
|
|
222
|
+
remove(id: string): Promise<void>;
|
|
223
|
+
closeAll(): Promise<void>;
|
|
224
|
+
has(id: string): boolean;
|
|
225
|
+
ids(): ReadonlyArray<string>;
|
|
226
|
+
}
|
|
227
|
+
//#endregion
|
|
228
|
+
export { Flume, type FlumeCloseError, FlumeClosed, FlumeConfluence, FlumeConnectionError, type FlumeDiscordEvent, type FlumeDiscordSourceOptions, type FlumeErrorHandler, type FlumeEvent, type FlumeEventHandler, type FlumeGatewayMessage, type FlumeGitHubEvent, type FlumeGitHubNotification, type FlumeGitHubSourceOptions, FlumeHttpError, type FlumeLog, type FlumeLogHandler, type FlumeLogInput, type FlumeLogLevel, type FlumeOptions, FlumeParseError, type FlumeReconnectConfig, type FlumeReconnectOptions, FlumeRunning, type FlumeRuntimeDeps, type FlumeSlackConnectionResponse, type FlumeSlackEnvelope, type FlumeSlackEvent, type FlumeSlackSourceOptions, FlumeSource, type FlumeSourceLocalStatusHandler, type FlumeSourceName, type FlumeSourceStartContext, type FlumeSourceStatus, FlumeStartError, type FlumeStatus, type FlumeStreamHandler, type FlumeStreamItem, type FlumeStreamOptions, type FlumeStreamOverflow, type FlumeTimeEvent, type FlumeTimeMessage, type FlumeTimeSourceOptions, type FlumeTimeTick, type FlumeTimerHandle, createFlumeDefaultDeps };
|