ui-router-devtools 0.0.1-alpha.0 → 0.1.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/LICENSE +9 -0
- package/README.md +161 -0
- package/dist/console.d.ts +5 -0
- package/dist/console.d.ts.map +1 -0
- package/dist/console.js +47 -0
- package/dist/console.js.map +1 -0
- package/dist/define.d.ts +8 -0
- package/dist/define.d.ts.map +1 -0
- package/dist/define.js +4 -0
- package/dist/define.js.map +1 -0
- package/dist/edges.d.ts +25 -0
- package/dist/edges.d.ts.map +1 -0
- package/dist/edges.js +28 -0
- package/dist/edges.js.map +1 -0
- package/dist/element/chips.d.ts +17 -0
- package/dist/element/chips.d.ts.map +1 -0
- package/dist/element/chips.js +134 -0
- package/dist/element/chips.js.map +1 -0
- package/dist/element/glyphs.d.ts +34 -0
- package/dist/element/glyphs.d.ts.map +1 -0
- package/dist/element/glyphs.js +107 -0
- package/dist/element/glyphs.js.map +1 -0
- package/dist/element/inspector.d.ts +7 -0
- package/dist/element/inspector.d.ts.map +1 -0
- package/dist/element/inspector.js +183 -0
- package/dist/element/inspector.js.map +1 -0
- package/dist/element/links.d.ts +4 -0
- package/dist/element/links.d.ts.map +1 -0
- package/dist/element/links.js +87 -0
- package/dist/element/links.js.map +1 -0
- package/dist/element/log.d.ts +12 -0
- package/dist/element/log.d.ts.map +1 -0
- package/dist/element/log.js +272 -0
- package/dist/element/log.js.map +1 -0
- package/dist/element/map.d.ts +5 -0
- package/dist/element/map.d.ts.map +1 -0
- package/dist/element/map.js +5 -0
- package/dist/element/map.js.map +1 -0
- package/dist/element/mapview.d.ts +17 -0
- package/dist/element/mapview.d.ts.map +1 -0
- package/dist/element/mapview.js +158 -0
- package/dist/element/mapview.js.map +1 -0
- package/dist/element/measure.d.ts +3 -0
- package/dist/element/measure.d.ts.map +1 -0
- package/dist/element/measure.js +9 -0
- package/dist/element/measure.js.map +1 -0
- package/dist/element/nested.d.ts +45 -0
- package/dist/element/nested.d.ts.map +1 -0
- package/dist/element/nested.js +686 -0
- package/dist/element/nested.js.map +1 -0
- package/dist/element/pack.d.ts +75 -0
- package/dist/element/pack.d.ts.map +1 -0
- package/dist/element/pack.js +281 -0
- package/dist/element/pack.js.map +1 -0
- package/dist/element/panel.d.ts +159 -0
- package/dist/element/panel.d.ts.map +1 -0
- package/dist/element/panel.js +1542 -0
- package/dist/element/panel.js.map +1 -0
- package/dist/element/popover.d.ts +12 -0
- package/dist/element/popover.d.ts.map +1 -0
- package/dist/element/popover.js +38 -0
- package/dist/element/popover.js.map +1 -0
- package/dist/element/route.d.ts +75 -0
- package/dist/element/route.d.ts.map +1 -0
- package/dist/element/route.js +883 -0
- package/dist/element/route.js.map +1 -0
- package/dist/element/scrubber.d.ts +4 -0
- package/dist/element/scrubber.d.ts.map +1 -0
- package/dist/element/scrubber.js +67 -0
- package/dist/element/scrubber.js.map +1 -0
- package/dist/element/styles.d.ts +3 -0
- package/dist/element/styles.d.ts.map +1 -0
- package/dist/element/styles.js +2084 -0
- package/dist/element/styles.js.map +1 -0
- package/dist/element/timeline-styles.d.ts +3 -0
- package/dist/element/timeline-styles.d.ts.map +1 -0
- package/dist/element/timeline-styles.js +286 -0
- package/dist/element/timeline-styles.js.map +1 -0
- package/dist/element/timeline.d.ts +9 -0
- package/dist/element/timeline.d.ts.map +1 -0
- package/dist/element/timeline.js +225 -0
- package/dist/element/timeline.js.map +1 -0
- package/dist/element/tree.d.ts +24 -0
- package/dist/element/tree.d.ts.map +1 -0
- package/dist/element/tree.js +149 -0
- package/dist/element/tree.js.map +1 -0
- package/dist/element/viewmap-styles.d.ts +3 -0
- package/dist/element/viewmap-styles.d.ts.map +1 -0
- package/dist/element/viewmap-styles.js +282 -0
- package/dist/element/viewmap-styles.js.map +1 -0
- package/dist/element/viewmap.d.ts +39 -0
- package/dist/element/viewmap.d.ts.map +1 -0
- package/dist/element/viewmap.js +406 -0
- package/dist/element/viewmap.js.map +1 -0
- package/dist/element/viewport.d.ts +31 -0
- package/dist/element/viewport.d.ts.map +1 -0
- package/dist/element/viewport.js +37 -0
- package/dist/element/viewport.js.map +1 -0
- package/dist/element/waterfall.d.ts +85 -0
- package/dist/element/waterfall.d.ts.map +1 -0
- package/dist/element/waterfall.js +284 -0
- package/dist/element/waterfall.js.map +1 -0
- package/dist/fold.d.ts +27 -0
- package/dist/fold.d.ts.map +1 -0
- package/dist/fold.js +104 -0
- package/dist/fold.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/lit-ui-router.d.ts +24 -0
- package/dist/lit-ui-router.d.ts.map +1 -0
- package/dist/lit-ui-router.js +102 -0
- package/dist/lit-ui-router.js.map +1 -0
- package/dist/notation.d.ts +28 -0
- package/dist/notation.d.ts.map +1 -0
- package/dist/notation.js +105 -0
- package/dist/notation.js.map +1 -0
- package/dist/performance.d.ts +5 -0
- package/dist/performance.d.ts.map +1 -0
- package/dist/performance.js +66 -0
- package/dist/performance.js.map +1 -0
- package/dist/plugin.d.ts +32 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +21 -0
- package/dist/plugin.js.map +1 -0
- package/dist/recorder.d.ts +30 -0
- package/dist/recorder.d.ts.map +1 -0
- package/dist/recorder.js +117 -0
- package/dist/recorder.js.map +1 -0
- package/dist/schema.d.ts +2 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +2 -0
- package/dist/schema.js.map +1 -0
- package/dist/session-schema.d.ts +31 -0
- package/dist/session-schema.d.ts.map +1 -0
- package/dist/session-schema.js +314 -0
- package/dist/session-schema.js.map +1 -0
- package/dist/session.schema.json +1172 -0
- package/dist/shared/event-schema.d.ts +225 -0
- package/dist/shared/event-schema.d.ts.map +1 -0
- package/dist/shared/event-schema.js +2 -0
- package/dist/shared/event-schema.js.map +1 -0
- package/dist/shared/redaction.d.ts +19 -0
- package/dist/shared/redaction.d.ts.map +1 -0
- package/dist/shared/redaction.js +56 -0
- package/dist/shared/redaction.js.map +1 -0
- package/dist/shared/resolve-timing.d.ts +6 -0
- package/dist/shared/resolve-timing.d.ts.map +1 -0
- package/dist/shared/resolve-timing.js +61 -0
- package/dist/shared/resolve-timing.js.map +1 -0
- package/dist/shared/router-events.d.ts +10 -0
- package/dist/shared/router-events.d.ts.map +1 -0
- package/dist/shared/router-events.js +296 -0
- package/dist/shared/router-events.js.map +1 -0
- package/dist/shared/thrown.d.ts +5 -0
- package/dist/shared/thrown.d.ts.map +1 -0
- package/dist/shared/thrown.js +12 -0
- package/dist/shared/thrown.js.map +1 -0
- package/dist/shared/transition-source.d.ts +4 -0
- package/dist/shared/transition-source.d.ts.map +1 -0
- package/dist/shared/transition-source.js +2 -0
- package/dist/shared/transition-source.js.map +1 -0
- package/dist/shared/views.d.ts +10 -0
- package/dist/shared/views.d.ts.map +1 -0
- package/dist/shared/views.js +67 -0
- package/dist/shared/views.js.map +1 -0
- package/dist/spans.d.ts +15 -0
- package/dist/spans.d.ts.map +1 -0
- package/dist/spans.js +24 -0
- package/dist/spans.js.map +1 -0
- package/dist/testing.d.ts +32 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +28 -0
- package/dist/testing.js.map +1 -0
- package/dist/ui-router-devtools.d.ts +36 -0
- package/dist/ui-router-devtools.d.ts.map +1 -0
- package/dist/ui-router-devtools.js +3 -0
- package/dist/ui-router-devtools.js.map +1 -0
- package/dist/views.d.ts +44 -0
- package/dist/views.d.ts.map +1 -0
- package/dist/views.js +43 -0
- package/dist/views.js.map +1 -0
- package/package.json +112 -2
- package/src/console.ts +104 -0
- package/src/define.ts +12 -0
- package/src/edges.ts +64 -0
- package/src/element/chips.ts +187 -0
- package/src/element/glyphs.ts +218 -0
- package/src/element/inspector.ts +315 -0
- package/src/element/links.ts +136 -0
- package/src/element/log.ts +410 -0
- package/src/element/map.ts +22 -0
- package/src/element/mapview.ts +224 -0
- package/src/element/measure.ts +13 -0
- package/src/element/nested.ts +1124 -0
- package/src/element/pack.ts +526 -0
- package/src/element/panel.ts +2378 -0
- package/src/element/popover.ts +64 -0
- package/src/element/route.ts +1481 -0
- package/src/element/scrubber.ts +103 -0
- package/src/element/styles.ts +2084 -0
- package/src/element/timeline-styles.ts +287 -0
- package/src/element/timeline.ts +392 -0
- package/src/element/tree.ts +271 -0
- package/src/element/viewmap-styles.ts +283 -0
- package/src/element/viewmap.ts +733 -0
- package/src/element/viewport.ts +112 -0
- package/src/element/waterfall.ts +585 -0
- package/src/fold.ts +151 -0
- package/src/index.ts +40 -0
- package/src/lit-ui-router.ts +194 -0
- package/src/notation.ts +181 -0
- package/src/performance.ts +142 -0
- package/src/plugin.ts +57 -0
- package/src/recorder.ts +228 -0
- package/src/schema.ts +32 -0
- package/src/session-schema.ts +362 -0
- package/src/spans.ts +53 -0
- package/src/testing.ts +74 -0
- package/src/types/import-meta-env.d.ts +9 -0
- package/src/ui-router-devtools.ts +39 -0
- package/src/views.ts +116 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bumped only by a breaking change. Added optional fields, new event types and new values of an open enum keep it,
|
|
3
|
+
* so a reader ignores fields and event types it does not know and tolerates open-enum values it does not know.
|
|
4
|
+
*/
|
|
5
|
+
export declare const SCHEMA_VERSION = 1;
|
|
6
|
+
export type SchemaVersion = typeof SCHEMA_VERSION;
|
|
7
|
+
export type Scalar = string | number | boolean | null;
|
|
8
|
+
/** A recorded param value: arrays stay arrays, Dates become ISO strings, anything JSON cannot hold becomes a tag such as `[function]`. */
|
|
9
|
+
export type ParamValue = Scalar | Scalar[];
|
|
10
|
+
export type Params = Record<string, ParamValue>;
|
|
11
|
+
export interface ParamInfo {
|
|
12
|
+
id: string;
|
|
13
|
+
type: string;
|
|
14
|
+
optional: boolean;
|
|
15
|
+
dynamic: boolean;
|
|
16
|
+
array: boolean;
|
|
17
|
+
inherit: boolean;
|
|
18
|
+
squash: boolean | string;
|
|
19
|
+
}
|
|
20
|
+
export interface StateInfo {
|
|
21
|
+
/** As registered; a lazy (future) state keeps its `.**` suffix. */
|
|
22
|
+
name: string;
|
|
23
|
+
parent: string | null;
|
|
24
|
+
/** The declared url fragment, relative to the parent's. */
|
|
25
|
+
url: string | null;
|
|
26
|
+
params: ParamInfo[];
|
|
27
|
+
resolves: string[];
|
|
28
|
+
future: boolean;
|
|
29
|
+
abstract: boolean;
|
|
30
|
+
redirects: boolean;
|
|
31
|
+
redirectTo?: string;
|
|
32
|
+
dsr?: {
|
|
33
|
+
default: string | null;
|
|
34
|
+
};
|
|
35
|
+
sticky?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/** The phases the adapter emits. */
|
|
38
|
+
export type KnownPhase = "before" | "start" | "exit" | "retain" | "enter" | "finish" | "success" | "error";
|
|
39
|
+
/** A known phase, or one a later v1 adds (a plugin's hook type, say), kept by its own name. */
|
|
40
|
+
export type Phase = KnownPhase | (string & {});
|
|
41
|
+
export type Outcome = "success" | "error" | "redirected" | "superseded" | "aborted" | "ignored" | "invalid";
|
|
42
|
+
export type Source = "sref" | "url" | "redirect" | "otherwise" | "unknown";
|
|
43
|
+
export interface TransitionOptionsInfo {
|
|
44
|
+
source: Source;
|
|
45
|
+
location: boolean | "replace";
|
|
46
|
+
reload: boolean | string;
|
|
47
|
+
inherit: boolean;
|
|
48
|
+
supercede: boolean;
|
|
49
|
+
}
|
|
50
|
+
export interface LocationInfo {
|
|
51
|
+
kind: "hash" | "pushState" | "memory" | "other";
|
|
52
|
+
plugin: string | null;
|
|
53
|
+
baseHref: string;
|
|
54
|
+
hashPrefix: string;
|
|
55
|
+
html5Mode: boolean;
|
|
56
|
+
}
|
|
57
|
+
export interface EventBase {
|
|
58
|
+
v: SchemaVersion;
|
|
59
|
+
/** Per observer, from 1, one per emitted event; a gap means events were dropped. */
|
|
60
|
+
seq: number;
|
|
61
|
+
/** Milliseconds since the realm's `performance.timeOrigin`. */
|
|
62
|
+
t: number;
|
|
63
|
+
}
|
|
64
|
+
export interface ConfigEvent extends EventBase {
|
|
65
|
+
type: "config";
|
|
66
|
+
location: LocationInfo;
|
|
67
|
+
strictMode: boolean;
|
|
68
|
+
caseInsensitive: boolean;
|
|
69
|
+
plugins: string[];
|
|
70
|
+
}
|
|
71
|
+
export interface StatesEvent extends EventBase {
|
|
72
|
+
type: "states";
|
|
73
|
+
states: StateInfo[];
|
|
74
|
+
}
|
|
75
|
+
/** The root state is `''` in `from`, `to` and `name`, and is never listed in a path. */
|
|
76
|
+
export interface TransitionEvent extends EventBase {
|
|
77
|
+
type: "transition";
|
|
78
|
+
/** Core's `Transition.$id`: unique per router, from 0. */
|
|
79
|
+
id: number;
|
|
80
|
+
from: string;
|
|
81
|
+
to: string;
|
|
82
|
+
fromParams: Params;
|
|
83
|
+
toParams: Params;
|
|
84
|
+
entering: string[];
|
|
85
|
+
exiting: string[];
|
|
86
|
+
retained: string[];
|
|
87
|
+
redirectedFrom: number | null;
|
|
88
|
+
options: TransitionOptionsInfo;
|
|
89
|
+
dynamic: boolean;
|
|
90
|
+
}
|
|
91
|
+
export interface PhaseEvent extends EventBase {
|
|
92
|
+
type: "phase";
|
|
93
|
+
id: number;
|
|
94
|
+
phase: Phase;
|
|
95
|
+
edge: "start" | "end";
|
|
96
|
+
/** The state a per-state phase (exit, retain, enter) runs for; null for a transition-wide phase. */
|
|
97
|
+
state: string | null;
|
|
98
|
+
}
|
|
99
|
+
export interface ResolveEvent extends EventBase {
|
|
100
|
+
type: "resolve";
|
|
101
|
+
id: number;
|
|
102
|
+
token: string;
|
|
103
|
+
state: string;
|
|
104
|
+
start: number;
|
|
105
|
+
end: number;
|
|
106
|
+
ok: boolean;
|
|
107
|
+
cached: boolean;
|
|
108
|
+
/** Free text from the app; redactable. */
|
|
109
|
+
message?: string;
|
|
110
|
+
/** The thrown Error's `name`, when the resolve threw or rejected with one. */
|
|
111
|
+
errorName?: string;
|
|
112
|
+
}
|
|
113
|
+
export interface ResultEvent extends EventBase {
|
|
114
|
+
type: "result";
|
|
115
|
+
id: number;
|
|
116
|
+
outcome: Outcome;
|
|
117
|
+
/** The transition that took over: a redirect's successor, or the transition that superseded this one. */
|
|
118
|
+
by?: number;
|
|
119
|
+
/** Free text from the app or from core; redactable. Present on error and invalid, and on aborted when core gives a reason. */
|
|
120
|
+
message?: string;
|
|
121
|
+
/** The thrown Error's `name`, on an error outcome where a hook or resolve threw one. */
|
|
122
|
+
errorName?: string;
|
|
123
|
+
/** Ids of the params that failed validation, on an invalid outcome. */
|
|
124
|
+
invalidParams?: string[];
|
|
125
|
+
}
|
|
126
|
+
/** A target that names no state; core creates no Transition for it. */
|
|
127
|
+
export interface InvalidEvent extends EventBase {
|
|
128
|
+
type: "invalid";
|
|
129
|
+
from: string;
|
|
130
|
+
to: string;
|
|
131
|
+
toParams: Params;
|
|
132
|
+
}
|
|
133
|
+
export interface CurrentEvent extends EventBase {
|
|
134
|
+
type: "current";
|
|
135
|
+
name: string;
|
|
136
|
+
params: Params;
|
|
137
|
+
}
|
|
138
|
+
/** The view config filling a `ui-view`: which state declared it, under which key, and the view it targets. */
|
|
139
|
+
export interface ViewFill {
|
|
140
|
+
/** The state whose `views` declared it; `''` for the root. */
|
|
141
|
+
state: string;
|
|
142
|
+
/** Its key in that state's `views`, `$default` for a state's one view. */
|
|
143
|
+
view: string;
|
|
144
|
+
/** The view it targets, as core normalized it: a `ui-view` name, or a dotted path of them, and the state it is anchored to. */
|
|
145
|
+
target: {
|
|
146
|
+
name: string;
|
|
147
|
+
anchor: string;
|
|
148
|
+
};
|
|
149
|
+
/** The declared component's name: a string as declared, or a function's or class's own name; absent when it has none. */
|
|
150
|
+
component?: string;
|
|
151
|
+
}
|
|
152
|
+
/** A `ui-view` registered with core's view service. Nesting is read from `fqn`, one segment per enclosing view. */
|
|
153
|
+
export interface ViewInfo {
|
|
154
|
+
/** The renderer's id for the view, unique among a router's registered views. */
|
|
155
|
+
id: number;
|
|
156
|
+
/** The view's name, `$default` when it has none. */
|
|
157
|
+
name: string;
|
|
158
|
+
/** The names of the enclosing views and its own, outermost first, joined by dots. */
|
|
159
|
+
fqn: string;
|
|
160
|
+
/** The renderer's view type, such as `lit`, `ng1` or `react`. */
|
|
161
|
+
type: string;
|
|
162
|
+
/** The state whose content created the view; `''` for the root. */
|
|
163
|
+
context: string;
|
|
164
|
+
/** What fills it; null while it is empty. */
|
|
165
|
+
fill: ViewFill | null;
|
|
166
|
+
}
|
|
167
|
+
/** The router's `ui-view`s after core's view service synced them, sent when they change. */
|
|
168
|
+
export interface ViewsEvent extends EventBase {
|
|
169
|
+
type: "views";
|
|
170
|
+
views: ViewInfo[];
|
|
171
|
+
/** Active view configs that no `ui-view` took, so their content is nowhere on the page. */
|
|
172
|
+
unmatched: ViewFill[];
|
|
173
|
+
}
|
|
174
|
+
export type RouterEvent = ConfigEvent | StatesEvent | TransitionEvent | PhaseEvent | ResolveEvent | ResultEvent | InvalidEvent | CurrentEvent | ViewsEvent;
|
|
175
|
+
export interface Redaction {
|
|
176
|
+
/** Param keys whose values are kept; every other value becomes `[redacted]`. `'all'` keeps every value. */
|
|
177
|
+
params: readonly string[] | "all";
|
|
178
|
+
/** Whether free-text `message` fields are kept. */
|
|
179
|
+
messages: boolean;
|
|
180
|
+
}
|
|
181
|
+
/** A span attribute's value, as tracing libraries allow it: a scalar or an array of one kind of scalar. */
|
|
182
|
+
export type SpanAttributeValue = string | number | boolean | (string | number | boolean | null)[];
|
|
183
|
+
/**
|
|
184
|
+
* A span from a tracer, in a shape that names no tracing library. Times are epoch milliseconds, so a span's offset on
|
|
185
|
+
* the event clock is `startTime - timeOrigin`.
|
|
186
|
+
*/
|
|
187
|
+
export interface SpanRecord {
|
|
188
|
+
traceId: string;
|
|
189
|
+
spanId: string;
|
|
190
|
+
/** Absent on the root of a trace. */
|
|
191
|
+
parentSpanId?: string;
|
|
192
|
+
name: string;
|
|
193
|
+
startTime: number;
|
|
194
|
+
/** Absent while the span is still running. */
|
|
195
|
+
endTime?: number;
|
|
196
|
+
status?: "unset" | "ok" | "error";
|
|
197
|
+
attributes?: Record<string, SpanAttributeValue>;
|
|
198
|
+
}
|
|
199
|
+
export interface Session {
|
|
200
|
+
format: "ui-router-session";
|
|
201
|
+
v: SchemaVersion;
|
|
202
|
+
/** Minted when the recorder starts, with `crypto.randomUUID()`. */
|
|
203
|
+
id: string;
|
|
204
|
+
generator: {
|
|
205
|
+
name: string;
|
|
206
|
+
version: string;
|
|
207
|
+
};
|
|
208
|
+
/** The recorder's label for its router, unique within one page. */
|
|
209
|
+
routerId: string;
|
|
210
|
+
/** Epoch milliseconds of the recording realm's `performance.timeOrigin`; an event's epoch time is `timeOrigin + t`. */
|
|
211
|
+
timeOrigin: number;
|
|
212
|
+
/** The event clock at export, so an imported running transition has an end. */
|
|
213
|
+
t: number;
|
|
214
|
+
/** Events the recorder discarded; 0 means the session is complete since recording began. */
|
|
215
|
+
dropped: number;
|
|
216
|
+
/** Whether the recorder timed resolves; without it a session has no resolve events. */
|
|
217
|
+
timeResolves: boolean;
|
|
218
|
+
/** What the export scrubbed. */
|
|
219
|
+
redaction: Redaction;
|
|
220
|
+
/** The latest config, states, current and views snapshots first, then the kept events in `seq` order. */
|
|
221
|
+
events: RouterEvent[];
|
|
222
|
+
/** Spans that ran during a recorded transition, when the panel was given any; absent otherwise. */
|
|
223
|
+
spans?: SpanRecord[];
|
|
224
|
+
}
|
|
225
|
+
//# sourceMappingURL=event-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-schema.d.ts","mappings":";;;;AAIA,OAAO,cAAM,iBAAiB;AAE9B,YAAY,uBAAuB;AAEnC,YAAY;;AAGZ,YAAY,aAAa,SAAS;AAElC,YAAY,SAAS,eAAe;AAEpC,iBAAiB,UAAU;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,iBAAiB,UAAU;;CAEzB;CACA;;CAEA;CACA,QAAQ;CACR;CACA;CACA;CACA;CACA;CACA,MAAM;EAAE;CAAuB;CAC/B;AACF;;AAGA,YAAY,aACR,WACA,UACA,SACA,WACA,UACA,WACA,YACA;;AAGJ,YAAY,QAAQ,uBAAuB,CAAC;AAE5C,YAAY,UACR,YACA,UACA,eACA,eACA,YACA,YACA;AAEJ,YAAY,SAAS,SAAS,QAAQ,aAAa,cAAc;AAEjE,iBAAiB,sBAAsB;CACrC,QAAQ;CACR,oBAAoB;CACpB;CACA;CACA;AACF;AAEA,iBAAiB,aAAa;CAC5B,MAAM,SAAS,cAAc,WAAW;CACxC;CACA;CACA;CACA;AACF;AAEA,iBAAiB,UAAU;CACzB,GAAG;;CAEH;;CAEA;AACF;AAEA,iBAAiB,oBAAoB,UAAU;CAC7C,MAAM;CACN,UAAU;CACV;CACA;CACA;AACF;AAEA,iBAAiB,oBAAoB,UAAU;CAC7C,MAAM;CACN,QAAQ;AACV;;AAGA,iBAAiB,wBAAwB,UAAU;CACjD,MAAM;;CAEN;CACA;CACA;CACA,YAAY;CACZ,UAAU;CACV;CACA;CACA;CACA;CACA,SAAS;CACT;AACF;AAEA,iBAAiB,mBAAmB,UAAU;CAC5C,MAAM;CACN;CACA,OAAO;CACP,MAAM,UAAU;;CAEhB;AACF;AAEA,iBAAiB,qBAAqB,UAAU;CAC9C,MAAM;CACN;CACA;CACA;CACA;CACA;CACA;CACA;;CAEA;;CAEA;AACF;AAEA,iBAAiB,oBAAoB,UAAU;CAC7C,MAAM;CACN;CACA,SAAS;;CAET;;CAEA;;CAEA;;CAEA;AACF;;AAGA,iBAAiB,qBAAqB,UAAU;CAC9C,MAAM;CACN;CACA;CACA,UAAU;AACZ;AAEA,iBAAiB,qBAAqB,UAAU;CAC9C,MAAM;CACN;CACA,QAAQ;AACV;;AAGA,iBAAiB,SAAS;;CAExB;;CAEA;;CAEA,QAAQ;EAAE;EAAc;CAAe;;CAEvC;AACF;;AAGA,iBAAiB,SAAS;;CAExB;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA,MAAM;AACR;;AAGA,iBAAiB,mBAAmB,UAAU;CAC5C,MAAM;CACN,OAAO;;CAEP,WAAW;AACb;AAEA,YAAY,cACR,cACA,cACA,kBACA,aACA,eACA,cACA,eACA,eACA;AAEJ,iBAAiB,UAAU;;CAEzB,4BAA4B;;CAE5B;AACF;;AAGA,YAAY;;;;;AAUZ,iBAAiB,WAAW;CAC1B;CACA;;CAEA;CACA;CACA;;CAEA;CACA,SAAS,UAAU,OAAO;CAC1B,aAAa,eAAe;AAC9B;AAEA,iBAAiB,QAAQ;CACvB,QAAQ;CACR,GAAG;;CAEH;CACA,WAAW;EAAE;EAAc;CAAgB;;CAE3C;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA,WAAW;;CAEX,QAAQ;;CAER,QAAQ;AACV","names":[],"ignoreList":[],"sources":["../../../shared/router-events/src/event-schema.ts"],"sourcesContent":["/**\n * Bumped only by a breaking change. Added optional fields, new event types and new values of an open enum keep it,\n * so a reader ignores fields and event types it does not know and tolerates open-enum values it does not know.\n */\nexport const SCHEMA_VERSION = 1;\n\nexport type SchemaVersion = typeof SCHEMA_VERSION;\n\nexport type Scalar = string | number | boolean | null;\n\n/** A recorded param value: arrays stay arrays, Dates become ISO strings, anything JSON cannot hold becomes a tag such as `[function]`. */\nexport type ParamValue = Scalar | Scalar[];\n\nexport type Params = Record<string, ParamValue>;\n\nexport interface ParamInfo {\n id: string;\n type: string;\n optional: boolean;\n dynamic: boolean;\n array: boolean;\n inherit: boolean;\n squash: boolean | string;\n}\n\nexport interface StateInfo {\n /** As registered; a lazy (future) state keeps its `.**` suffix. */\n name: string;\n parent: string | null;\n /** The declared url fragment, relative to the parent's. */\n url: string | null;\n params: ParamInfo[];\n resolves: string[];\n future: boolean;\n abstract: boolean;\n redirects: boolean;\n redirectTo?: string;\n dsr?: { default: string | null };\n sticky?: boolean;\n}\n\n/** The phases the adapter emits. */\nexport type KnownPhase =\n | 'before'\n | 'start'\n | 'exit'\n | 'retain'\n | 'enter'\n | 'finish'\n | 'success'\n | 'error';\n\n/** A known phase, or one a later v1 adds (a plugin's hook type, say), kept by its own name. */\nexport type Phase = KnownPhase | (string & {});\n\nexport type Outcome =\n | 'success'\n | 'error'\n | 'redirected'\n | 'superseded'\n | 'aborted'\n | 'ignored'\n | 'invalid';\n\nexport type Source = 'sref' | 'url' | 'redirect' | 'otherwise' | 'unknown';\n\nexport interface TransitionOptionsInfo {\n source: Source;\n location: boolean | 'replace';\n reload: boolean | string;\n inherit: boolean;\n supercede: boolean;\n}\n\nexport interface LocationInfo {\n kind: 'hash' | 'pushState' | 'memory' | 'other';\n plugin: string | null;\n baseHref: string;\n hashPrefix: string;\n html5Mode: boolean;\n}\n\nexport interface EventBase {\n v: SchemaVersion;\n /** Per observer, from 1, one per emitted event; a gap means events were dropped. */\n seq: number;\n /** Milliseconds since the realm's `performance.timeOrigin`. */\n t: number;\n}\n\nexport interface ConfigEvent extends EventBase {\n type: 'config';\n location: LocationInfo;\n strictMode: boolean;\n caseInsensitive: boolean;\n plugins: string[];\n}\n\nexport interface StatesEvent extends EventBase {\n type: 'states';\n states: StateInfo[];\n}\n\n/** The root state is `''` in `from`, `to` and `name`, and is never listed in a path. */\nexport interface TransitionEvent extends EventBase {\n type: 'transition';\n /** Core's `Transition.$id`: unique per router, from 0. */\n id: number;\n from: string;\n to: string;\n fromParams: Params;\n toParams: Params;\n entering: string[];\n exiting: string[];\n retained: string[];\n redirectedFrom: number | null;\n options: TransitionOptionsInfo;\n dynamic: boolean;\n}\n\nexport interface PhaseEvent extends EventBase {\n type: 'phase';\n id: number;\n phase: Phase;\n edge: 'start' | 'end';\n /** The state a per-state phase (exit, retain, enter) runs for; null for a transition-wide phase. */\n state: string | null;\n}\n\nexport interface ResolveEvent extends EventBase {\n type: 'resolve';\n id: number;\n token: string;\n state: string;\n start: number;\n end: number;\n ok: boolean;\n cached: boolean;\n /** Free text from the app; redactable. */\n message?: string;\n /** The thrown Error's `name`, when the resolve threw or rejected with one. */\n errorName?: string;\n}\n\nexport interface ResultEvent extends EventBase {\n type: 'result';\n id: number;\n outcome: Outcome;\n /** The transition that took over: a redirect's successor, or the transition that superseded this one. */\n by?: number;\n /** Free text from the app or from core; redactable. Present on error and invalid, and on aborted when core gives a reason. */\n message?: string;\n /** The thrown Error's `name`, on an error outcome where a hook or resolve threw one. */\n errorName?: string;\n /** Ids of the params that failed validation, on an invalid outcome. */\n invalidParams?: string[];\n}\n\n/** A target that names no state; core creates no Transition for it. */\nexport interface InvalidEvent extends EventBase {\n type: 'invalid';\n from: string;\n to: string;\n toParams: Params;\n}\n\nexport interface CurrentEvent extends EventBase {\n type: 'current';\n name: string;\n params: Params;\n}\n\n/** The view config filling a `ui-view`: which state declared it, under which key, and the view it targets. */\nexport interface ViewFill {\n /** The state whose `views` declared it; `''` for the root. */\n state: string;\n /** Its key in that state's `views`, `$default` for a state's one view. */\n view: string;\n /** The view it targets, as core normalized it: a `ui-view` name, or a dotted path of them, and the state it is anchored to. */\n target: { name: string; anchor: string };\n /** The declared component's name: a string as declared, or a function's or class's own name; absent when it has none. */\n component?: string;\n}\n\n/** A `ui-view` registered with core's view service. Nesting is read from `fqn`, one segment per enclosing view. */\nexport interface ViewInfo {\n /** The renderer's id for the view, unique among a router's registered views. */\n id: number;\n /** The view's name, `$default` when it has none. */\n name: string;\n /** The names of the enclosing views and its own, outermost first, joined by dots. */\n fqn: string;\n /** The renderer's view type, such as `lit`, `ng1` or `react`. */\n type: string;\n /** The state whose content created the view; `''` for the root. */\n context: string;\n /** What fills it; null while it is empty. */\n fill: ViewFill | null;\n}\n\n/** The router's `ui-view`s after core's view service synced them, sent when they change. */\nexport interface ViewsEvent extends EventBase {\n type: 'views';\n views: ViewInfo[];\n /** Active view configs that no `ui-view` took, so their content is nowhere on the page. */\n unmatched: ViewFill[];\n}\n\nexport type RouterEvent =\n | ConfigEvent\n | StatesEvent\n | TransitionEvent\n | PhaseEvent\n | ResolveEvent\n | ResultEvent\n | InvalidEvent\n | CurrentEvent\n | ViewsEvent;\n\nexport interface Redaction {\n /** Param keys whose values are kept; every other value becomes `[redacted]`. `'all'` keeps every value. */\n params: readonly string[] | 'all';\n /** Whether free-text `message` fields are kept. */\n messages: boolean;\n}\n\n/** A span attribute's value, as tracing libraries allow it: a scalar or an array of one kind of scalar. */\nexport type SpanAttributeValue =\n | string\n | number\n | boolean\n | (string | number | boolean | null)[];\n\n/**\n * A span from a tracer, in a shape that names no tracing library. Times are epoch milliseconds, so a span's offset on\n * the event clock is `startTime - timeOrigin`.\n */\nexport interface SpanRecord {\n traceId: string;\n spanId: string;\n /** Absent on the root of a trace. */\n parentSpanId?: string;\n name: string;\n startTime: number;\n /** Absent while the span is still running. */\n endTime?: number;\n status?: 'unset' | 'ok' | 'error';\n attributes?: Record<string, SpanAttributeValue>;\n}\n\nexport interface Session {\n format: 'ui-router-session';\n v: SchemaVersion;\n /** Minted when the recorder starts, with `crypto.randomUUID()`. */\n id: string;\n generator: { name: string; version: string };\n /** The recorder's label for its router, unique within one page. */\n routerId: string;\n /** Epoch milliseconds of the recording realm's `performance.timeOrigin`; an event's epoch time is `timeOrigin + t`. */\n timeOrigin: number;\n /** The event clock at export, so an imported running transition has an end. */\n t: number;\n /** Events the recorder discarded; 0 means the session is complete since recording began. */\n dropped: number;\n /** Whether the recorder timed resolves; without it a session has no resolve events. */\n timeResolves: boolean;\n /** What the export scrubbed. */\n redaction: Redaction;\n /** The latest config, states, current and views snapshots first, then the kept events in `seq` order. */\n events: RouterEvent[];\n /** Spans that ran during a recorded transition, when the panel was given any; absent otherwise. */\n spans?: SpanRecord[];\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-schema.js","mappings":"AAIA,OAAO,MAAM,iBAAiB","names":[],"ignoreList":[],"sources":["../../../shared/router-events/src/event-schema.ts"],"sourcesContent":["/**\n * Bumped only by a breaking change. Added optional fields, new event types and new values of an open enum keep it,\n * so a reader ignores fields and event types it does not know and tolerates open-enum values it does not know.\n */\nexport const SCHEMA_VERSION = 1;\n\nexport type SchemaVersion = typeof SCHEMA_VERSION;\n\nexport type Scalar = string | number | boolean | null;\n\n/** A recorded param value: arrays stay arrays, Dates become ISO strings, anything JSON cannot hold becomes a tag such as `[function]`. */\nexport type ParamValue = Scalar | Scalar[];\n\nexport type Params = Record<string, ParamValue>;\n\nexport interface ParamInfo {\n id: string;\n type: string;\n optional: boolean;\n dynamic: boolean;\n array: boolean;\n inherit: boolean;\n squash: boolean | string;\n}\n\nexport interface StateInfo {\n /** As registered; a lazy (future) state keeps its `.**` suffix. */\n name: string;\n parent: string | null;\n /** The declared url fragment, relative to the parent's. */\n url: string | null;\n params: ParamInfo[];\n resolves: string[];\n future: boolean;\n abstract: boolean;\n redirects: boolean;\n redirectTo?: string;\n dsr?: { default: string | null };\n sticky?: boolean;\n}\n\n/** The phases the adapter emits. */\nexport type KnownPhase =\n | 'before'\n | 'start'\n | 'exit'\n | 'retain'\n | 'enter'\n | 'finish'\n | 'success'\n | 'error';\n\n/** A known phase, or one a later v1 adds (a plugin's hook type, say), kept by its own name. */\nexport type Phase = KnownPhase | (string & {});\n\nexport type Outcome =\n | 'success'\n | 'error'\n | 'redirected'\n | 'superseded'\n | 'aborted'\n | 'ignored'\n | 'invalid';\n\nexport type Source = 'sref' | 'url' | 'redirect' | 'otherwise' | 'unknown';\n\nexport interface TransitionOptionsInfo {\n source: Source;\n location: boolean | 'replace';\n reload: boolean | string;\n inherit: boolean;\n supercede: boolean;\n}\n\nexport interface LocationInfo {\n kind: 'hash' | 'pushState' | 'memory' | 'other';\n plugin: string | null;\n baseHref: string;\n hashPrefix: string;\n html5Mode: boolean;\n}\n\nexport interface EventBase {\n v: SchemaVersion;\n /** Per observer, from 1, one per emitted event; a gap means events were dropped. */\n seq: number;\n /** Milliseconds since the realm's `performance.timeOrigin`. */\n t: number;\n}\n\nexport interface ConfigEvent extends EventBase {\n type: 'config';\n location: LocationInfo;\n strictMode: boolean;\n caseInsensitive: boolean;\n plugins: string[];\n}\n\nexport interface StatesEvent extends EventBase {\n type: 'states';\n states: StateInfo[];\n}\n\n/** The root state is `''` in `from`, `to` and `name`, and is never listed in a path. */\nexport interface TransitionEvent extends EventBase {\n type: 'transition';\n /** Core's `Transition.$id`: unique per router, from 0. */\n id: number;\n from: string;\n to: string;\n fromParams: Params;\n toParams: Params;\n entering: string[];\n exiting: string[];\n retained: string[];\n redirectedFrom: number | null;\n options: TransitionOptionsInfo;\n dynamic: boolean;\n}\n\nexport interface PhaseEvent extends EventBase {\n type: 'phase';\n id: number;\n phase: Phase;\n edge: 'start' | 'end';\n /** The state a per-state phase (exit, retain, enter) runs for; null for a transition-wide phase. */\n state: string | null;\n}\n\nexport interface ResolveEvent extends EventBase {\n type: 'resolve';\n id: number;\n token: string;\n state: string;\n start: number;\n end: number;\n ok: boolean;\n cached: boolean;\n /** Free text from the app; redactable. */\n message?: string;\n /** The thrown Error's `name`, when the resolve threw or rejected with one. */\n errorName?: string;\n}\n\nexport interface ResultEvent extends EventBase {\n type: 'result';\n id: number;\n outcome: Outcome;\n /** The transition that took over: a redirect's successor, or the transition that superseded this one. */\n by?: number;\n /** Free text from the app or from core; redactable. Present on error and invalid, and on aborted when core gives a reason. */\n message?: string;\n /** The thrown Error's `name`, on an error outcome where a hook or resolve threw one. */\n errorName?: string;\n /** Ids of the params that failed validation, on an invalid outcome. */\n invalidParams?: string[];\n}\n\n/** A target that names no state; core creates no Transition for it. */\nexport interface InvalidEvent extends EventBase {\n type: 'invalid';\n from: string;\n to: string;\n toParams: Params;\n}\n\nexport interface CurrentEvent extends EventBase {\n type: 'current';\n name: string;\n params: Params;\n}\n\n/** The view config filling a `ui-view`: which state declared it, under which key, and the view it targets. */\nexport interface ViewFill {\n /** The state whose `views` declared it; `''` for the root. */\n state: string;\n /** Its key in that state's `views`, `$default` for a state's one view. */\n view: string;\n /** The view it targets, as core normalized it: a `ui-view` name, or a dotted path of them, and the state it is anchored to. */\n target: { name: string; anchor: string };\n /** The declared component's name: a string as declared, or a function's or class's own name; absent when it has none. */\n component?: string;\n}\n\n/** A `ui-view` registered with core's view service. Nesting is read from `fqn`, one segment per enclosing view. */\nexport interface ViewInfo {\n /** The renderer's id for the view, unique among a router's registered views. */\n id: number;\n /** The view's name, `$default` when it has none. */\n name: string;\n /** The names of the enclosing views and its own, outermost first, joined by dots. */\n fqn: string;\n /** The renderer's view type, such as `lit`, `ng1` or `react`. */\n type: string;\n /** The state whose content created the view; `''` for the root. */\n context: string;\n /** What fills it; null while it is empty. */\n fill: ViewFill | null;\n}\n\n/** The router's `ui-view`s after core's view service synced them, sent when they change. */\nexport interface ViewsEvent extends EventBase {\n type: 'views';\n views: ViewInfo[];\n /** Active view configs that no `ui-view` took, so their content is nowhere on the page. */\n unmatched: ViewFill[];\n}\n\nexport type RouterEvent =\n | ConfigEvent\n | StatesEvent\n | TransitionEvent\n | PhaseEvent\n | ResolveEvent\n | ResultEvent\n | InvalidEvent\n | CurrentEvent\n | ViewsEvent;\n\nexport interface Redaction {\n /** Param keys whose values are kept; every other value becomes `[redacted]`. `'all'` keeps every value. */\n params: readonly string[] | 'all';\n /** Whether free-text `message` fields are kept. */\n messages: boolean;\n}\n\n/** A span attribute's value, as tracing libraries allow it: a scalar or an array of one kind of scalar. */\nexport type SpanAttributeValue =\n | string\n | number\n | boolean\n | (string | number | boolean | null)[];\n\n/**\n * A span from a tracer, in a shape that names no tracing library. Times are epoch milliseconds, so a span's offset on\n * the event clock is `startTime - timeOrigin`.\n */\nexport interface SpanRecord {\n traceId: string;\n spanId: string;\n /** Absent on the root of a trace. */\n parentSpanId?: string;\n name: string;\n startTime: number;\n /** Absent while the span is still running. */\n endTime?: number;\n status?: 'unset' | 'ok' | 'error';\n attributes?: Record<string, SpanAttributeValue>;\n}\n\nexport interface Session {\n format: 'ui-router-session';\n v: SchemaVersion;\n /** Minted when the recorder starts, with `crypto.randomUUID()`. */\n id: string;\n generator: { name: string; version: string };\n /** The recorder's label for its router, unique within one page. */\n routerId: string;\n /** Epoch milliseconds of the recording realm's `performance.timeOrigin`; an event's epoch time is `timeOrigin + t`. */\n timeOrigin: number;\n /** The event clock at export, so an imported running transition has an end. */\n t: number;\n /** Events the recorder discarded; 0 means the session is complete since recording began. */\n dropped: number;\n /** Whether the recorder timed resolves; without it a session has no resolve events. */\n timeResolves: boolean;\n /** What the export scrubbed. */\n redaction: Redaction;\n /** The latest config, states, current and views snapshots first, then the kept events in `seq` order. */\n events: RouterEvent[];\n /** Spans that ran during a recorded transition, when the panel was given any; absent otherwise. */\n spans?: SpanRecord[];\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Params, Redaction, RouterEvent, Session, SpanRecord } from "./event-schema.js";
|
|
2
|
+
/** What a redacted param value becomes. */
|
|
3
|
+
export declare const REDACTED = "[redacted]";
|
|
4
|
+
/** Keeps every param value and message. */
|
|
5
|
+
export declare const keepAll: () => Redaction;
|
|
6
|
+
/** The default for anything that leaves the page: param keys kept with their values redacted, messages kept. */
|
|
7
|
+
export declare const defaultRedaction: () => Redaction;
|
|
8
|
+
/** Fills the parts of a redaction the caller left out from the default. */
|
|
9
|
+
export declare const redactionOf: (partial?: Partial<Redaction>) => Redaction;
|
|
10
|
+
/** Keeps the values of the listed keys; every other non-null value becomes `[redacted]`. */
|
|
11
|
+
export declare const redactParams: (params: Params, keep: Redaction["params"]) => Params;
|
|
12
|
+
export declare const redactEvent: (event: RouterEvent, { params, messages }: Redaction) => RouterEvent;
|
|
13
|
+
/** What two redactions applied one after the other leave: the keys both keep, and messages only if both keep them. */
|
|
14
|
+
export declare const combineRedaction: (first: Redaction, second: Redaction) => Redaction;
|
|
15
|
+
/** Keeps a span's name, ids, times and status; an attribute value the param allowlist does not keep becomes `[redacted]`. */
|
|
16
|
+
export declare const redactSpan: (span: SpanRecord, { params }: Redaction) => SpanRecord;
|
|
17
|
+
/** The session with `redaction` applied on top of whatever it already scrubbed. */
|
|
18
|
+
export declare const redactSession: (session: Session, redaction: Redaction) => Session;
|
|
19
|
+
//# sourceMappingURL=redaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redaction.d.ts","mappings":"AAAA,cACE,QACA,WACA,aACA,SACA,kBACK;;AAGP,OAAO,cAAM,WAAW;;AAGxB,OAAO,cAAM,eAAc;;AAG3B,OAAO,cAAM,wBAAuB;;AAMpC,OAAO,cAAM,cAAe,UAAS,QAAQ,eAAkB;;AAM/D,OAAO,cAAM,eACX,QAAQ,QACR,MAAM,UAAU,cACf;AAeH,OAAO,cAAM,cACX,OAAO,aACP,EAAE,QAAQ,YAAY,cACrB;;AAsBH,OAAO,cAAM,mBACX,OAAO,WACP,QAAQ,cACP;;AAuBH,OAAO,cAAM,aACX,MAAM,YACN,EAAE,UAAU,cACX;;AAcH,OAAO,cAAM,gBACX,SAAS,SACT,WAAW,cACV","names":[],"ignoreList":[],"sources":["../../../shared/router-events/src/redaction.ts"],"sourcesContent":["import type {\n Params,\n Redaction,\n RouterEvent,\n Session,\n SpanRecord,\n} from './event-schema.ts';\n\n/** What a redacted param value becomes. */\nexport const REDACTED = '[redacted]';\n\n/** Keeps every param value and message. */\nexport const keepAll = (): Redaction => ({ params: 'all', messages: true });\n\n/** The default for anything that leaves the page: param keys kept with their values redacted, messages kept. */\nexport const defaultRedaction = (): Redaction => ({\n params: [],\n messages: true,\n});\n\n/** Fills the parts of a redaction the caller left out from the default. */\nexport const redactionOf = (partial: Partial<Redaction> = {}): Redaction => ({\n ...defaultRedaction(),\n ...partial,\n});\n\n/** Keeps the values of the listed keys; every other non-null value becomes `[redacted]`. */\nexport const redactParams = (\n params: Params,\n keep: Redaction['params'],\n): Params =>\n keep === 'all'\n ? params\n : Object.fromEntries(\n Object.entries(params).map(([key, value]) => [\n key,\n value === null || keep.includes(key) ? value : REDACTED,\n ]),\n );\n\nconst withoutMessage = <E extends { message?: string }>({\n message: _message,\n ...rest\n}: E): Omit<E, 'message'> => rest;\n\nexport const redactEvent = (\n event: RouterEvent,\n { params, messages }: Redaction,\n): RouterEvent => {\n switch (event.type) {\n case 'transition':\n return {\n ...event,\n fromParams: redactParams(event.fromParams, params),\n toParams: redactParams(event.toParams, params),\n };\n case 'invalid':\n return { ...event, toParams: redactParams(event.toParams, params) };\n case 'current':\n return { ...event, params: redactParams(event.params, params) };\n case 'result':\n return messages ? event : withoutMessage(event);\n case 'resolve':\n return messages ? event : withoutMessage(event);\n default:\n return event;\n }\n};\n\n/** What two redactions applied one after the other leave: the keys both keep, and messages only if both keep them. */\nexport const combineRedaction = (\n first: Redaction,\n second: Redaction,\n): Redaction => ({\n params:\n first.params === 'all'\n ? second.params\n : second.params === 'all'\n ? first.params\n : first.params.filter((key) => second.params.includes(key)),\n messages: first.messages && second.messages,\n});\n\nconst PARAM_ATTRIBUTE = 'uirouter.transition.param.';\n\n// The router's own attributes name states and ids, except its params; any other library's can hold a URL or user data.\nconst keepsAttribute = (key: string, keep: Redaction['params']): boolean => {\n if (keep === 'all') return true;\n\n if (key.startsWith(PARAM_ATTRIBUTE))\n return keep.includes(key.slice(PARAM_ATTRIBUTE.length));\n\n return key.startsWith('uirouter.');\n};\n\n/** Keeps a span's name, ids, times and status; an attribute value the param allowlist does not keep becomes `[redacted]`. */\nexport const redactSpan = (\n span: SpanRecord,\n { params }: Redaction,\n): SpanRecord =>\n span.attributes && params !== 'all'\n ? {\n ...span,\n attributes: Object.fromEntries(\n Object.entries(span.attributes).map(([key, value]) => [\n key,\n keepsAttribute(key, params) ? value : REDACTED,\n ]),\n ),\n }\n : span;\n\n/** The session with `redaction` applied on top of whatever it already scrubbed. */\nexport const redactSession = (\n session: Session,\n redaction: Redaction,\n): Session => ({\n ...session,\n redaction: combineRedaction(session.redaction, redaction),\n events: session.events.map((event) => redactEvent(event, redaction)),\n ...(session.spans && {\n spans: session.spans.map((span) => redactSpan(span, redaction)),\n }),\n});\n"]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export const REDACTED = "[redacted]";
|
|
2
|
+
export const keepAll = () => ({
|
|
3
|
+
params: "all",
|
|
4
|
+
messages: true
|
|
5
|
+
});
|
|
6
|
+
export const defaultRedaction = () => ({
|
|
7
|
+
params: [],
|
|
8
|
+
messages: true
|
|
9
|
+
});
|
|
10
|
+
export const redactionOf = (partial = {}) => ({
|
|
11
|
+
...defaultRedaction(),
|
|
12
|
+
...partial
|
|
13
|
+
});
|
|
14
|
+
export const redactParams = (params, keep) => keep === "all" ? params : Object.fromEntries(Object.entries(params).map(([key, value]) => [key, value === null || keep.includes(key) ? value : REDACTED]));
|
|
15
|
+
const withoutMessage = ({ message: _message, ...rest }) => rest;
|
|
16
|
+
export const redactEvent = (event, { params, messages }) => {
|
|
17
|
+
switch (event.type) {
|
|
18
|
+
case "transition": return {
|
|
19
|
+
...event,
|
|
20
|
+
fromParams: redactParams(event.fromParams, params),
|
|
21
|
+
toParams: redactParams(event.toParams, params)
|
|
22
|
+
};
|
|
23
|
+
case "invalid": return {
|
|
24
|
+
...event,
|
|
25
|
+
toParams: redactParams(event.toParams, params)
|
|
26
|
+
};
|
|
27
|
+
case "current": return {
|
|
28
|
+
...event,
|
|
29
|
+
params: redactParams(event.params, params)
|
|
30
|
+
};
|
|
31
|
+
case "result": return messages ? event : withoutMessage(event);
|
|
32
|
+
case "resolve": return messages ? event : withoutMessage(event);
|
|
33
|
+
default: return event;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
export const combineRedaction = (first, second) => ({
|
|
37
|
+
params: first.params === "all" ? second.params : second.params === "all" ? first.params : first.params.filter((key) => second.params.includes(key)),
|
|
38
|
+
messages: first.messages && second.messages
|
|
39
|
+
});
|
|
40
|
+
const PARAM_ATTRIBUTE = "uirouter.transition.param.";
|
|
41
|
+
const keepsAttribute = (key, keep) => {
|
|
42
|
+
if (keep === "all") return true;
|
|
43
|
+
if (key.startsWith(PARAM_ATTRIBUTE)) return keep.includes(key.slice(PARAM_ATTRIBUTE.length));
|
|
44
|
+
return key.startsWith("uirouter.");
|
|
45
|
+
};
|
|
46
|
+
export const redactSpan = (span, { params }) => span.attributes && params !== "all" ? {
|
|
47
|
+
...span,
|
|
48
|
+
attributes: Object.fromEntries(Object.entries(span.attributes).map(([key, value]) => [key, keepsAttribute(key, params) ? value : REDACTED]))
|
|
49
|
+
} : span;
|
|
50
|
+
export const redactSession = (session, redaction) => ({
|
|
51
|
+
...session,
|
|
52
|
+
redaction: combineRedaction(session.redaction, redaction),
|
|
53
|
+
events: session.events.map((event) => redactEvent(event, redaction)),
|
|
54
|
+
...session.spans && { spans: session.spans.map((span) => redactSpan(span, redaction)) }
|
|
55
|
+
});
|
|
56
|
+
//# sourceMappingURL=redaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redaction.js","mappings":"AASA,OAAO,MAAM,WAAW;AAGxB,OAAO,MAAM,iBAA4B;CAAE,QAAQ;CAAO,UAAU;AAAK;AAGzE,OAAO,MAAM,0BAAqC;CAChD,QAAQ,CAAC;CACT,UAAU;AACZ;AAGA,OAAO,MAAM,eAAe,UAA8B,CAAC,OAAkB;CAC3E,GAAG,iBAAiB;CACpB,GAAG;AACL;AAGA,OAAO,MAAM,gBACX,QACA,SAEA,SAAS,QACL,SACA,OAAO,YACL,OAAO,QAAQ,MAAM,CAAC,CAAC,KAAK,CAAC,KAAK,WAAW,CAC3C,KACA,UAAU,QAAQ,KAAK,SAAS,GAAG,IAAI,QAAQ,QACjD,CAAC,CACH;AAEN,MAAM,kBAAkD,EACtD,SAAS,UACT,GAAG,WACwB;AAE7B,OAAO,MAAM,eACX,OACA,EAAE,QAAQ,eACM;CAChB,QAAQ,MAAM,MAAd;EACE,KAAK,cACH,OAAO;GACL,GAAG;GACH,YAAY,aAAa,MAAM,YAAY,MAAM;GACjD,UAAU,aAAa,MAAM,UAAU,MAAM;EAC/C;EACF,KAAK,WACH,OAAO;GAAE,GAAG;GAAO,UAAU,aAAa,MAAM,UAAU,MAAM;EAAE;EACpE,KAAK,WACH,OAAO;GAAE,GAAG;GAAO,QAAQ,aAAa,MAAM,QAAQ,MAAM;EAAE;EAChE,KAAK,UACH,OAAO,WAAW,QAAQ,eAAe,KAAK;EAChD,KAAK,WACH,OAAO,WAAW,QAAQ,eAAe,KAAK;EAChD,SACE,OAAO;CACX;AACF;AAGA,OAAO,MAAM,oBACX,OACA,YACe;CACf,QACE,MAAM,WAAW,QACb,OAAO,SACP,OAAO,WAAW,QAChB,MAAM,SACN,MAAM,OAAO,QAAQ,QAAQ,OAAO,OAAO,SAAS,GAAG,CAAC;CAChE,UAAU,MAAM,YAAY,OAAO;AACrC;AAEA,MAAM,kBAAkB;AAGxB,MAAM,kBAAkB,KAAa,SAAuC;CAC1E,IAAI,SAAS,OAAO,OAAO;CAE3B,IAAI,IAAI,WAAW,eAAe,GAChC,OAAO,KAAK,SAAS,IAAI,MAAM,gBAAgB,MAAM,CAAC;CAExD,OAAO,IAAI,WAAW,WAAW;AACnC;AAGA,OAAO,MAAM,cACX,MACA,EAAE,aAEF,KAAK,cAAc,WAAW,QAC1B;CACE,GAAG;CACH,YAAY,OAAO,YACjB,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,KAAK,CAAC,KAAK,WAAW,CACpD,KACA,eAAe,KAAK,MAAM,IAAI,QAAQ,QACxC,CAAC,CACH;AACF,IACA;AAGN,OAAO,MAAM,iBACX,SACA,eACa;CACb,GAAG;CACH,WAAW,iBAAiB,QAAQ,WAAW,SAAS;CACxD,QAAQ,QAAQ,OAAO,KAAK,UAAU,YAAY,OAAO,SAAS,CAAC;CACnE,GAAI,QAAQ,SAAS,EACnB,OAAO,QAAQ,MAAM,KAAK,SAAS,WAAW,MAAM,SAAS,CAAC,EAChE;AACF","names":[],"ignoreList":[],"sources":["../../../shared/router-events/src/redaction.ts"],"sourcesContent":["import type {\n Params,\n Redaction,\n RouterEvent,\n Session,\n SpanRecord,\n} from './event-schema.ts';\n\n/** What a redacted param value becomes. */\nexport const REDACTED = '[redacted]';\n\n/** Keeps every param value and message. */\nexport const keepAll = (): Redaction => ({ params: 'all', messages: true });\n\n/** The default for anything that leaves the page: param keys kept with their values redacted, messages kept. */\nexport const defaultRedaction = (): Redaction => ({\n params: [],\n messages: true,\n});\n\n/** Fills the parts of a redaction the caller left out from the default. */\nexport const redactionOf = (partial: Partial<Redaction> = {}): Redaction => ({\n ...defaultRedaction(),\n ...partial,\n});\n\n/** Keeps the values of the listed keys; every other non-null value becomes `[redacted]`. */\nexport const redactParams = (\n params: Params,\n keep: Redaction['params'],\n): Params =>\n keep === 'all'\n ? params\n : Object.fromEntries(\n Object.entries(params).map(([key, value]) => [\n key,\n value === null || keep.includes(key) ? value : REDACTED,\n ]),\n );\n\nconst withoutMessage = <E extends { message?: string }>({\n message: _message,\n ...rest\n}: E): Omit<E, 'message'> => rest;\n\nexport const redactEvent = (\n event: RouterEvent,\n { params, messages }: Redaction,\n): RouterEvent => {\n switch (event.type) {\n case 'transition':\n return {\n ...event,\n fromParams: redactParams(event.fromParams, params),\n toParams: redactParams(event.toParams, params),\n };\n case 'invalid':\n return { ...event, toParams: redactParams(event.toParams, params) };\n case 'current':\n return { ...event, params: redactParams(event.params, params) };\n case 'result':\n return messages ? event : withoutMessage(event);\n case 'resolve':\n return messages ? event : withoutMessage(event);\n default:\n return event;\n }\n};\n\n/** What two redactions applied one after the other leave: the keys both keep, and messages only if both keep them. */\nexport const combineRedaction = (\n first: Redaction,\n second: Redaction,\n): Redaction => ({\n params:\n first.params === 'all'\n ? second.params\n : second.params === 'all'\n ? first.params\n : first.params.filter((key) => second.params.includes(key)),\n messages: first.messages && second.messages,\n});\n\nconst PARAM_ATTRIBUTE = 'uirouter.transition.param.';\n\n// The router's own attributes name states and ids, except its params; any other library's can hold a URL or user data.\nconst keepsAttribute = (key: string, keep: Redaction['params']): boolean => {\n if (keep === 'all') return true;\n\n if (key.startsWith(PARAM_ATTRIBUTE))\n return keep.includes(key.slice(PARAM_ATTRIBUTE.length));\n\n return key.startsWith('uirouter.');\n};\n\n/** Keeps a span's name, ids, times and status; an attribute value the param allowlist does not keep becomes `[redacted]`. */\nexport const redactSpan = (\n span: SpanRecord,\n { params }: Redaction,\n): SpanRecord =>\n span.attributes && params !== 'all'\n ? {\n ...span,\n attributes: Object.fromEntries(\n Object.entries(span.attributes).map(([key, value]) => [\n key,\n keepsAttribute(key, params) ? value : REDACTED,\n ]),\n ),\n }\n : span;\n\n/** The session with `redaction` applied on top of whatever it already scrubbed. */\nexport const redactSession = (\n session: Session,\n redaction: Redaction,\n): Session => ({\n ...session,\n redaction: combineRedaction(session.redaction, redaction),\n events: session.events.map((event) => redactEvent(event, redaction)),\n ...(session.spans && {\n spans: session.spans.map((span) => redactSpan(span, redaction)),\n }),\n});\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PathNode, Transition } from "@uirouter/core";
|
|
2
|
+
import type { ResolveEvent } from "./event-schema.js";
|
|
3
|
+
/** A resolve event before the adapter stamps its schema version, sequence number and time. */
|
|
4
|
+
export type ResolveDraft = Omit<ResolveEvent, "v" | "seq" | "t">;
|
|
5
|
+
export declare const timeResolvables: (trans: Transition, node: PathNode, now: () => number, emit: (draft: ResolveDraft) => void) => void;
|
|
6
|
+
//# sourceMappingURL=resolve-timing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-timing.d.ts","mappings":"AAAA,cAAc,UAAU,kBAAkB;AAG1C,cAAc,oBAAoB;;AAGlC,YAAY,eAAe,KAAK,cAAc,MAAM,QAAQ;AAG5D,OAAO,cAAM,kBACX,OAAO,YACP,MAAM,UACN,mBACA,OAAO,OAAO","names":[],"ignoreList":[],"sources":["../../../shared/router-events/src/resolve-timing.ts"],"sourcesContent":["import type { PathNode, Transition } from '@uirouter/core';\n\nimport { errorNameOf, messageOf } from './thrown.ts';\nimport type { ResolveEvent } from './event-schema.ts';\n\n/** A resolve event before the adapter stamps its schema version, sequence number and time. */\nexport type ResolveDraft = Omit<ResolveEvent, 'v' | 'seq' | 't'>;\n\n// Opt-in monkey-patch: core has no resolve notification, so this wraps each per-transition Resolvable clone's resolveFn.\nexport const timeResolvables = (\n trans: Transition,\n node: PathNode,\n now: () => number,\n emit: (draft: ResolveDraft) => void,\n): void => {\n for (const resolvable of node.resolvables) {\n const token: unknown = resolvable.token;\n\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- core types tokens any; the app's resolves are the string tokens without a `$`\n if (typeof token !== 'string' || token.startsWith('$')) continue;\n\n const base = {\n type: 'resolve' as const,\n id: trans.$id,\n token,\n state: node.state.name,\n };\n\n if (resolvable.resolved) {\n const t = now();\n emit({ ...base, start: t, end: t, ok: true, cached: true });\n continue;\n }\n\n // SAFETY: core types `promise` as always set; it is undefined until the resolve starts\n if ((resolvable.promise as unknown) || !resolvable.resolveFn) continue;\n\n // SAFETY: a resolveFn takes its deps in order and returns a value or a promise\n // oxlint-disable-next-line anti-slop/no-unknown-returns -- the app's resolved value, which core types any\n const original = resolvable.resolveFn as (...deps: unknown[]) => unknown;\n resolvable.resolveFn = (...deps: unknown[]) => {\n const start = now();\n\n // oxlint-disable-next-line anti-slop/no-unknown-parameters -- a resolve's rejection reason, which the app types\n const done = (error?: unknown) => {\n const end = now();\n\n if (error === undefined) {\n emit({ ...base, start, end, ok: true, cached: false });\n\n return;\n }\n\n const errorName = errorNameOf(error);\n\n emit({\n ...base,\n start,\n end,\n ok: false,\n cached: false,\n message: messageOf(error),\n ...(errorName !== undefined && { errorName }),\n });\n };\n\n try {\n const value: unknown = original(...deps);\n Promise.resolve(value).then(\n () => done(),\n // oxlint-disable-next-line anti-slop/no-unknown-parameters -- a resolve's rejection reason, which the app types\n (error: unknown) => done(error ?? 'rejected'),\n );\n\n return value;\n } catch (error) {\n done(error ?? 'threw');\n throw error;\n }\n };\n }\n};\n"]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { errorNameOf, messageOf } from "./thrown.js";
|
|
2
|
+
export const timeResolvables = (trans, node, now, emit) => {
|
|
3
|
+
for (const resolvable of node.resolvables) {
|
|
4
|
+
const token = resolvable.token;
|
|
5
|
+
if (typeof token !== "string" || token.startsWith("$")) continue;
|
|
6
|
+
const base = {
|
|
7
|
+
type: "resolve",
|
|
8
|
+
id: trans.$id,
|
|
9
|
+
token,
|
|
10
|
+
state: node.state.name
|
|
11
|
+
};
|
|
12
|
+
if (resolvable.resolved) {
|
|
13
|
+
const t = now();
|
|
14
|
+
emit({
|
|
15
|
+
...base,
|
|
16
|
+
start: t,
|
|
17
|
+
end: t,
|
|
18
|
+
ok: true,
|
|
19
|
+
cached: true
|
|
20
|
+
});
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (resolvable.promise || !resolvable.resolveFn) continue;
|
|
24
|
+
const original = resolvable.resolveFn;
|
|
25
|
+
resolvable.resolveFn = (...deps) => {
|
|
26
|
+
const start = now();
|
|
27
|
+
const done = (error) => {
|
|
28
|
+
const end = now();
|
|
29
|
+
if (error === undefined) {
|
|
30
|
+
emit({
|
|
31
|
+
...base,
|
|
32
|
+
start,
|
|
33
|
+
end,
|
|
34
|
+
ok: true,
|
|
35
|
+
cached: false
|
|
36
|
+
});
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const errorName = errorNameOf(error);
|
|
40
|
+
emit({
|
|
41
|
+
...base,
|
|
42
|
+
start,
|
|
43
|
+
end,
|
|
44
|
+
ok: false,
|
|
45
|
+
cached: false,
|
|
46
|
+
message: messageOf(error),
|
|
47
|
+
...errorName !== undefined && { errorName }
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
try {
|
|
51
|
+
const value = original(...deps);
|
|
52
|
+
Promise.resolve(value).then(() => done(), (error) => done(error ?? "rejected"));
|
|
53
|
+
return value;
|
|
54
|
+
} catch (error) {
|
|
55
|
+
done(error ?? "threw");
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=resolve-timing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-timing.js","mappings":"AAEA,SAAS,aAAa,iBAAiB;AAOvC,OAAO,MAAM,mBACX,OACA,MACA,KACA,SACS;CACT,KAAK,MAAM,cAAc,KAAK,aAAa;EACzC,MAAM,QAAiB,WAAW;EAGlC,IAAI,OAAO,UAAU,YAAY,MAAM,WAAW,GAAG,GAAG;EAExD,MAAM,OAAO;GACX,MAAM;GACN,IAAI,MAAM;GACV;GACA,OAAO,KAAK,MAAM;EACpB;EAEA,IAAI,WAAW,UAAU;GACvB,MAAM,IAAI,IAAI;GACd,KAAK;IAAE,GAAG;IAAM,OAAO;IAAG,KAAK;IAAG,IAAI;IAAM,QAAQ;GAAK,CAAC;GAC1D;EACF;EAGA,IAAK,WAAW,WAAuB,CAAC,WAAW,WAAW;EAI9D,MAAM,WAAW,WAAW;EAC5B,WAAW,aAAa,GAAG,SAAoB;GAC7C,MAAM,QAAQ,IAAI;GAGlB,MAAM,QAAQ,UAAoB;IAChC,MAAM,MAAM,IAAI;IAEhB,IAAI,UAAU,WAAW;KACvB,KAAK;MAAE,GAAG;MAAM;MAAO;MAAK,IAAI;MAAM,QAAQ;KAAM,CAAC;KAErD;IACF;IAEA,MAAM,YAAY,YAAY,KAAK;IAEnC,KAAK;KACH,GAAG;KACH;KACA;KACA,IAAI;KACJ,QAAQ;KACR,SAAS,UAAU,KAAK;KACxB,GAAI,cAAc,aAAa,EAAE,UAAU;IAC7C,CAAC;GACH;GAEA,IAAI;IACF,MAAM,QAAiB,SAAS,GAAG,IAAI;IACvC,QAAQ,QAAQ,KAAK,CAAC,CAAC,WACf,KAAK,IAEV,UAAmB,KAAK,SAAS,UAAU,CAC9C;IAEA,OAAO;GACT,SAAS,OAAO;IACd,KAAK,SAAS,OAAO;IACrB,MAAM;GACR;EACF;CACF;AACF","names":[],"ignoreList":[],"sources":["../../../shared/router-events/src/resolve-timing.ts"],"sourcesContent":["import type { PathNode, Transition } from '@uirouter/core';\n\nimport { errorNameOf, messageOf } from './thrown.ts';\nimport type { ResolveEvent } from './event-schema.ts';\n\n/** A resolve event before the adapter stamps its schema version, sequence number and time. */\nexport type ResolveDraft = Omit<ResolveEvent, 'v' | 'seq' | 't'>;\n\n// Opt-in monkey-patch: core has no resolve notification, so this wraps each per-transition Resolvable clone's resolveFn.\nexport const timeResolvables = (\n trans: Transition,\n node: PathNode,\n now: () => number,\n emit: (draft: ResolveDraft) => void,\n): void => {\n for (const resolvable of node.resolvables) {\n const token: unknown = resolvable.token;\n\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- core types tokens any; the app's resolves are the string tokens without a `$`\n if (typeof token !== 'string' || token.startsWith('$')) continue;\n\n const base = {\n type: 'resolve' as const,\n id: trans.$id,\n token,\n state: node.state.name,\n };\n\n if (resolvable.resolved) {\n const t = now();\n emit({ ...base, start: t, end: t, ok: true, cached: true });\n continue;\n }\n\n // SAFETY: core types `promise` as always set; it is undefined until the resolve starts\n if ((resolvable.promise as unknown) || !resolvable.resolveFn) continue;\n\n // SAFETY: a resolveFn takes its deps in order and returns a value or a promise\n // oxlint-disable-next-line anti-slop/no-unknown-returns -- the app's resolved value, which core types any\n const original = resolvable.resolveFn as (...deps: unknown[]) => unknown;\n resolvable.resolveFn = (...deps: unknown[]) => {\n const start = now();\n\n // oxlint-disable-next-line anti-slop/no-unknown-parameters -- a resolve's rejection reason, which the app types\n const done = (error?: unknown) => {\n const end = now();\n\n if (error === undefined) {\n emit({ ...base, start, end, ok: true, cached: false });\n\n return;\n }\n\n const errorName = errorNameOf(error);\n\n emit({\n ...base,\n start,\n end,\n ok: false,\n cached: false,\n message: messageOf(error),\n ...(errorName !== undefined && { errorName }),\n });\n };\n\n try {\n const value: unknown = original(...deps);\n Promise.resolve(value).then(\n () => done(),\n // oxlint-disable-next-line anti-slop/no-unknown-parameters -- a resolve's rejection reason, which the app types\n (error: unknown) => done(error ?? 'rejected'),\n );\n\n return value;\n } catch (error) {\n done(error ?? 'threw');\n throw error;\n }\n };\n }\n};\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type UIRouter } from "@uirouter/core";
|
|
2
|
+
import { type RouterEvent } from "./event-schema.js";
|
|
3
|
+
export interface ObserveOptions {
|
|
4
|
+
/** Time each resolve by wrapping its `resolveFn`; off by default because it patches core objects. */
|
|
5
|
+
timeResolves?: boolean;
|
|
6
|
+
/** Send a `views` snapshot of the router's `ui-view`s whenever core syncs them; off by default. */
|
|
7
|
+
views?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const observe: (router: UIRouter, listener: (event: RouterEvent) => void, { timeResolves, views }?: ObserveOptions) => (() => void);
|
|
10
|
+
//# sourceMappingURL=router-events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-events.d.ts","mappings":"AAAA,cASO,gBACA;AAKP,cAGO,mBAUA;AAEP,iBAAiB,eAAe;;CAE9B;;CAEA;AACF;AA+TA,OAAO,cAAM,UACX,QAAQ,UACR,WAAW,OAAO,sBAClB,EAAE,cAAsB,UAAiB","names":[],"ignoreList":[],"sources":["../../../shared/router-events/src/router-events.ts"],"sourcesContent":["import {\n Rejection,\n RejectType,\n type HookMatchCriteria,\n type PathNode,\n type RawParams,\n type StateDeclaration,\n TargetState,\n type Transition,\n type UIRouter,\n} from '@uirouter/core';\nimport { errorNameOf, messageOf } from './thrown.ts';\nimport { timeResolvables } from './resolve-timing.ts';\nimport { sourceOf } from './transition-source.ts';\nimport { observeViews } from './views.ts';\nimport {\n SCHEMA_VERSION,\n type ConfigEvent,\n type RouterEvent,\n type LocationInfo,\n type Outcome,\n type ParamValue,\n type Params,\n type KnownPhase,\n type ResultEvent,\n type Scalar,\n type StateInfo,\n type TransitionOptionsInfo,\n} from './event-schema.ts';\n\nexport interface ObserveOptions {\n /** Time each resolve by wrapping its `resolveFn`; off by default because it patches core objects. */\n timeResolves?: boolean;\n /** Send a `views` snapshot of the router's `ui-view`s whenever core syncs them; off by default. */\n views?: boolean;\n}\n\ntype Draft<E> = E extends RouterEvent ? Omit<E, 'v' | 'seq' | 't'> : never;\n\ntype Emit = (event: Draft<RouterEvent>) => void;\n\n// Number.MAX_SAFE_INTEGER as a literal: shared source holds no evaluated module state.\nconst HIGH = 9_007_199_254_740_991;\n\nconst LOW = -9_007_199_254_740_991;\n\n// Every target runtime has these; declared here so the module compiles without DOM or node types.\ndeclare const performance: { now(): number };\n\ndeclare function setTimeout(handler: () => void): void;\n\nconst now = (): number => performance.now();\n\n// oxlint-disable-next-line anti-slop/no-unknown-parameters -- an object param value, which the app types\nconst jsonText = (value: unknown): string => {\n try {\n // JSON.stringify returns undefined for a value whose toJSON returns undefined.\n const text: string | undefined = JSON.stringify(value);\n\n return text ?? '[unserializable]';\n } catch {\n return '[unserializable]';\n }\n};\n\n// oxlint-disable-next-line anti-slop/no-unknown-parameters -- a param value, which the app types\nconst scalarOf = (value: unknown): Scalar => {\n if (value === null || value === undefined) return null;\n\n if (value instanceof Date)\n return Number.isNaN(value.getTime()) ? 'Invalid Date' : value.toISOString();\n\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- sorting an app's param value into what JSON can hold is this function's job\n switch (typeof value) {\n case 'string':\n case 'boolean':\n return value;\n case 'number':\n return Number.isFinite(value) ? value : String(value);\n case 'bigint':\n return `[bigint ${value}n]`;\n case 'function':\n return '[function]';\n case 'symbol':\n return '[symbol]';\n default:\n return jsonText(value);\n }\n};\n\n// oxlint-disable-next-line anti-slop/no-unknown-parameters -- a param value, which the app types\nconst paramValueOf = (value: unknown): ParamValue =>\n Array.isArray(value) ? value.map(scalarOf) : scalarOf(value);\n\nconst paramsOf = (params: RawParams): Params =>\n Object.fromEntries(\n Object.entries(params)\n .filter(([key, value]) => !(key === '#' && value == null))\n .map(([key, value]) => [key, paramValueOf(value)]),\n );\n\n// oxlint-disable-next-line anti-slop/no-unknown-parameters -- core types resolve tokens any\nconst tokenName = (token: unknown): string =>\n token instanceof Function ? token.name || '[function]' : String(token);\n\nconst resolveTokens = (decl: StateDeclaration): string[] => {\n const resolve = decl.resolve;\n\n return Array.isArray(resolve)\n ? resolve.map((entry) =>\n tokenName('token' in entry ? entry.token : entry.provide),\n )\n : Object.keys(resolve ?? {});\n};\n\ninterface NamedTarget {\n state?: string | StateDeclaration;\n}\n\ntype DsrProp =\n | boolean\n | string\n | ((...args: never[]) => void)\n | { default?: string | NamedTarget };\n\n// The @uirouter/dsr and @uirouter/sticky-states declaration properties, which core does not declare.\ninterface PluginDeclaration extends StateDeclaration {\n dsr?: DsrProp;\n deepStateRedirect?: DsrProp;\n sticky?: boolean;\n}\n\ntype DeclaredTarget =\n | StateDeclaration['redirectTo']\n | NamedTarget\n | boolean\n | ((...args: never[]) => void);\n\n// A target is named only when the declaration holds it as data; a function's result is unknown until it runs.\nconst staticTarget = (target: DeclaredTarget): string | null => {\n if (target instanceof TargetState) return target.name();\n\n /* oxlint-disable anti-slop/no-runtime-typeof -- the declaration's own union: a name, a target literal or a function */\n if (typeof target === 'string') return target;\n\n if (typeof target !== 'object' || target === null) return null;\n\n const state: NamedTarget['state'] = target.state;\n\n return (typeof state === 'string' ? state : state?.name) ?? null;\n /* oxlint-enable anti-slop/no-runtime-typeof */\n};\n\nconst dsrOf = (decl: PluginDeclaration): StateInfo['dsr'] => {\n const prop = decl.deepStateRedirect || decl.dsr;\n\n if (!prop) return undefined;\n\n return {\n default: staticTarget(\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- the plugin's own union: a config object or a bare target\n typeof prop === 'object' ? prop.default : prop,\n ),\n };\n};\n\nconst describeState = (\n router: UIRouter,\n decl: PluginDeclaration,\n): StateInfo => {\n const name = decl.name ?? '';\n const future = name.endsWith('.**');\n const bare = future ? name.slice(0, -3) : name;\n const dot = bare.lastIndexOf('.');\n\n const declaredParent =\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- the declaration's own union: a name or a parent declaration\n typeof decl.parent === 'string' ? decl.parent : decl.parent?.name;\n\n // TargetState.$state() is the public route to the built StateObject.\n const object = router.stateService.target(name).$state();\n\n const params = (object?.parameters({ inherit: false }) ?? [])\n .filter((param) => param.id !== '#')\n .map((param) => ({\n id: param.id,\n type: param.type.name,\n optional: param.isOptional,\n dynamic: param.dynamic,\n array: param.array,\n inherit: param.inherit,\n squash: param.squash,\n }));\n\n const redirectTo = staticTarget(decl.redirectTo);\n const dsr = dsrOf(decl);\n\n return {\n name,\n parent: declaredParent ?? (dot === -1 ? null : bare.slice(0, dot)),\n url: decl.url ?? null,\n params,\n resolves: resolveTokens(decl),\n future,\n abstract: Boolean(decl.abstract),\n redirects: decl.redirectTo !== undefined,\n ...(redirectTo !== null && { redirectTo }),\n ...(dsr && { dsr }),\n ...(decl.sticky && { sticky: true }),\n };\n};\n\nconst locationKind = (plugin: string | null): LocationInfo['kind'] => {\n if (!plugin) return 'other';\n\n if (/hash/i.test(plugin)) return 'hash';\n\n if (/pushstate/i.test(plugin)) return 'pushState';\n\n if (/memory/i.test(plugin)) return 'memory';\n\n return 'other';\n};\n\nconst readConfig = (router: UIRouter): Draft<ConfigEvent> => {\n const config = router.urlService.config;\n const plugins = router.getPlugin().map((plugin) => plugin.name);\n\n // Location plugins are the ones that carry a `service`; the plugin type does not declare it.\n const location =\n router\n .getPlugin()\n .find((plugin) => 'service' in plugin && 'configuration' in plugin)\n ?.name ?? null;\n\n return {\n type: 'config',\n location: {\n kind: locationKind(location),\n plugin: location,\n baseHref: config.baseHref(),\n hashPrefix: config.hashPrefix(),\n html5Mode: config.html5Mode(),\n },\n strictMode: config.strictMode(),\n caseInsensitive: config.caseInsensitive(),\n plugins,\n };\n};\n\nconst optionsOf = (trans: Transition): TransitionOptionsInfo => {\n const options = trans.options();\n const reload = options.reload;\n\n return {\n source: sourceOf(options),\n location: options.location ?? true,\n reload:\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- the option's own union: a flag, a state name or a state\n typeof reload === 'object' && reload !== null\n ? String(reload.name)\n : (reload ?? false),\n inherit: options.inherit ?? true,\n supercede: options.supercede ?? true,\n };\n};\n\n// oxlint-disable-next-line anti-slop/no-unknown-parameters -- a transition's rejection reason, which core types any\nconst outcomeOf = (error: unknown): Outcome => {\n if (!(error instanceof Rejection)) return 'error';\n\n switch (error.type) {\n case RejectType.SUPERSEDED:\n return error.redirected ? 'redirected' : 'superseded';\n case RejectType.ABORTED:\n return 'aborted';\n case RejectType.IGNORED:\n return 'ignored';\n case RejectType.INVALID:\n return 'invalid';\n default:\n return 'error';\n }\n};\n\n// Core's invalid-transition hook throws `trans.error()` as a plain Error's message, so the rejection arrives as an error.\n// oxlint-disable-next-line anti-slop/no-unknown-parameters -- a transition's rejection reason, which core types any\nconst invalidOf = (trans: Transition, error: unknown): Rejection | null => {\n if (!(error instanceof Rejection) || error.type !== RejectType.ERROR)\n return null;\n\n const invalid: unknown = trans.error();\n\n if (!(invalid instanceof Rejection) || invalid.type !== RejectType.INVALID)\n return null;\n\n const thrown: unknown = error.detail;\n\n return thrown instanceof Error &&\n thrown.message.includes(String(invalid.detail))\n ? invalid\n : null;\n};\n\nconst invalidParamsOf = (trans: Transition): string[] => {\n const values = trans.params();\n\n return trans\n .$to()\n .parameters()\n .filter((param) => !param.validates(values[param.id]))\n .map((param) => param.id);\n};\n\ntype Settled = Omit<Draft<ResultEvent>, 'type' | 'id'>;\n\n// What a rejection says, read from core's own objects rather than its printed form.\n// oxlint-disable-next-line anti-slop/no-unknown-parameters -- a transition's rejection reason, which core types any\nconst settledOf = (trans: Transition, error: unknown): Settled => {\n const invalid = invalidOf(trans, error);\n\n if (invalid) {\n const invalidParams = invalidParamsOf(trans);\n\n return {\n outcome: 'invalid',\n message: messageOf(invalid),\n ...(invalidParams.length && { invalidParams }),\n };\n }\n\n const outcome = outcomeOf(error);\n const detail: unknown = error instanceof Rejection ? error.detail : null;\n\n // Core says why it aborted: a hook returned false, or the router was disposed; abort() gives no reason.\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- core's abort reason is a string or nothing\n if (outcome === 'aborted' && typeof detail === 'string')\n return { outcome, message: detail };\n\n if (outcome !== 'error' && outcome !== 'invalid') return { outcome };\n\n const errorName = errorNameOf(error);\n\n return {\n outcome,\n message: messageOf(error),\n ...(errorName !== undefined && { errorName }),\n };\n};\n\nconst names = (nodes: PathNode[]): string[] =>\n nodes.flatMap((node) => (node.state.name ? [node.state.name] : []));\n\n// Observes one router through public hooks and calls `listener` with JSON-safe events; returns the disposer.\nexport const observe = (\n router: UIRouter,\n listener: (event: RouterEvent) => void,\n { timeResolves = false, views = false }: ObserveOptions = {},\n): (() => void) => {\n let seq = 0;\n\n const emit: Emit = (draft) =>\n listener({ v: SCHEMA_VERSION, seq: ++seq, t: now(), ...draft });\n\n const started: { id: number; redirectedFrom: number | null }[] = [];\n // Ids in the order they left the before phase, the order core makes each the current transition.\n const began: number[] = [];\n let lastConfig = '';\n\n const emitConfig = () => {\n const config = readConfig(router);\n const key = JSON.stringify(config);\n\n if (key === lastConfig) return;\n lastConfig = key;\n emit(config);\n };\n\n const emitStates = () =>\n emit({\n type: 'states',\n states: router.stateRegistry\n .get()\n .filter((decl) => decl.name)\n .map((decl) => describeState(router, decl)),\n });\n\n const emitCurrent = () =>\n emit({\n type: 'current',\n name: router.globals.current.name ?? '',\n params: paramsOf(router.globals.params),\n });\n\n emitConfig();\n emitStates();\n emitCurrent();\n\n const stopViews = views ? observeViews(router, emit) : undefined;\n\n // A redirect's origin rejects before its successor starts, so its result waits for the successor or a task.\n const pendingRedirects = new Map<number, () => void>();\n\n // Core's superseded detail is whichever transition is current when this one notices: possibly a later one, or none.\n const takenOverBy = (outcome: Outcome, id: number): number | undefined => {\n if (outcome === 'redirected')\n return started.find((s) => s.redirectedFrom === id)?.id;\n\n if (outcome !== 'superseded') return undefined;\n\n // An id that has left the window has no known successor.\n const index = began.indexOf(id);\n\n return index === -1 ? undefined : began[index + 1];\n };\n\n // oxlint-disable-next-line anti-slop/no-unknown-parameters -- a transition's rejection reason, which core types any\n const settle = (trans: Transition, error?: unknown) => {\n const id = trans.$id;\n\n const settled: Settled =\n error === undefined ? { outcome: 'success' } : settledOf(trans, error);\n\n const send = () => {\n pendingRedirects.delete(id);\n\n const by = takenOverBy(settled.outcome, id);\n\n emit({\n type: 'result',\n id,\n ...settled,\n ...(by !== undefined && { by }),\n });\n };\n\n if (settled.outcome !== 'redirected') {\n send();\n\n return;\n }\n\n pendingRedirects.set(id, send);\n setTimeout(() => pendingRedirects.get(id)?.());\n };\n\n const service = router.transitionService;\n const deregister: (() => void)[] = [];\n\n // SAFETY: core types every hook deregistration as Function; each takes no arguments\n const add = (fn: ReturnType<typeof service.onStart>) =>\n deregister.push(fn as () => void);\n\n const mark =\n (phase: KnownPhase, edge: 'start' | 'end') =>\n (trans: Transition, state?: StateDeclaration) => {\n // State hooks also fire for the unnamed root state; it is not a row anywhere.\n if (state && !state.name) return;\n\n // The lowest-priority before hook runs after core's ignore and validity checks, just before core makes the transition current.\n if (phase === 'before' && edge === 'end') {\n began.push(trans.$id);\n\n if (began.length > 256) began.shift();\n }\n\n emit({\n type: 'phase',\n id: trans.$id,\n phase,\n edge,\n state: state?.name || null,\n });\n };\n\n const bracket = (\n register: typeof service.onStart,\n phase: KnownPhase,\n criteria: HookMatchCriteria = {},\n ) => {\n add(\n register.call(service, criteria, mark(phase, 'start'), {\n priority: HIGH,\n }),\n );\n add(\n register.call(service, criteria, mark(phase, 'end'), { priority: LOW }),\n );\n };\n\n add(\n service.onBefore(\n {},\n (trans) => {\n emitConfig();\n const changes = trans.treeChanges();\n const redirectedFrom = trans.redirectedFrom()?.$id ?? null;\n started.push({ id: trans.$id, redirectedFrom });\n\n if (started.length > 256) started.shift();\n\n if (redirectedFrom !== null) pendingRedirects.get(redirectedFrom)?.();\n emit({\n type: 'transition',\n id: trans.$id,\n from: trans.from().name ?? '',\n to: trans.to().name ?? '',\n fromParams: paramsOf(trans.params('from')),\n toParams: paramsOf(trans.params('to')),\n entering: names(changes.entering),\n exiting: names(changes.exiting),\n retained: names(changes.retained),\n redirectedFrom,\n options: optionsOf(trans),\n dynamic: trans.dynamic(),\n });\n trans.promise.then(\n () => settle(trans),\n // oxlint-disable-next-line anti-slop/no-unknown-parameters -- a transition's rejection reason, which core types any\n (error: unknown) => settle(trans, error ?? 'rejected'),\n );\n },\n { priority: HIGH + 1 },\n ),\n );\n\n if (timeResolves)\n add(\n service.onStart(\n {},\n (trans) => {\n for (const node of trans.treeChanges('to'))\n timeResolvables(trans, node, now, emit);\n },\n { priority: HIGH },\n ),\n );\n\n bracket(service.onBefore, 'before');\n bracket(service.onStart, 'start');\n bracket(service.onExit, 'exit', { exiting: () => true });\n bracket(service.onRetain, 'retain', { retained: () => true });\n bracket(service.onEnter, 'enter', { entering: () => true });\n bracket(service.onFinish, 'finish');\n bracket(service.onSuccess, 'success');\n bracket(service.onError, 'error');\n\n add(service.onSuccess({}, emitCurrent, { priority: LOW }));\n add(router.stateRegistry.onStatesChanged(emitStates));\n // Returning undefined leaves core's onInvalid chain unchanged.\n add(\n router.stateService.onInvalid((to, from) => {\n emit({\n type: 'invalid',\n // name() returns the state object for the root state, whose name is empty.\n from: from?.$state()?.name ?? router.globals.current.name ?? '',\n to: to?.name() ?? '',\n toParams: paramsOf(to?.params() ?? {}),\n });\n\n return undefined;\n }),\n );\n\n return () => {\n stopViews?.();\n deregister.splice(0).forEach((fn) => fn());\n };\n};\n"]}
|