@substrat-run/contracts 0.149.0 → 0.151.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/dist/control-plane.d.ts +4 -0
- package/dist/control-plane.d.ts.map +1 -1
- package/dist/deploy.d.ts +52 -5
- package/dist/deploy.d.ts.map +1 -1
- package/dist/deploy.js +129 -8
- package/dist/deploy.js.map +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +1 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/operations.d.ts +34 -0
- package/dist/operations.d.ts.map +1 -1
- package/dist/operations.js +36 -0
- package/dist/operations.js.map +1 -1
- package/dist/permission.d.ts +8 -0
- package/dist/permission.d.ts.map +1 -1
- package/dist/permission.js +7 -0
- package/dist/permission.js.map +1 -1
- package/dist/request-trace.d.ts +295 -0
- package/dist/request-trace.d.ts.map +1 -0
- package/dist/request-trace.js +127 -0
- package/dist/request-trace.js.map +1 -0
- package/dist/trace-sink.d.ts +199 -0
- package/dist/trace-sink.d.ts.map +1 -0
- package/dist/trace-sink.js +50 -0
- package/dist/trace-sink.js.map +1 -0
- package/package.json +6 -2
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const traceCheckStep: z.ZodObject<{
|
|
3
|
+
atMs: z.ZodNumber;
|
|
4
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
5
|
+
type: z.ZodLiteral<"check">;
|
|
6
|
+
permission: z.ZodString;
|
|
7
|
+
entity: z.ZodNullable<z.ZodString>;
|
|
8
|
+
allowed: z.ZodBoolean;
|
|
9
|
+
decidedBy: z.ZodNullable<z.ZodString>;
|
|
10
|
+
requires: z.ZodArray<z.ZodString>;
|
|
11
|
+
callerHas: z.ZodArray<z.ZodString>;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
export declare const traceSqlStep: z.ZodObject<{
|
|
14
|
+
atMs: z.ZodNumber;
|
|
15
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
16
|
+
type: z.ZodLiteral<"sql">;
|
|
17
|
+
operation: z.ZodEnum<{
|
|
18
|
+
exec: "exec";
|
|
19
|
+
query: "query";
|
|
20
|
+
}>;
|
|
21
|
+
statement: z.ZodString;
|
|
22
|
+
params: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
|
|
23
|
+
rowsRead: z.ZodOptional<z.ZodNumber>;
|
|
24
|
+
rowsWritten: z.ZodOptional<z.ZodNumber>;
|
|
25
|
+
error: z.ZodOptional<z.ZodString>;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
export declare const traceEmitStep: z.ZodObject<{
|
|
28
|
+
atMs: z.ZodNumber;
|
|
29
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
30
|
+
type: z.ZodLiteral<"emit">;
|
|
31
|
+
eventType: z.ZodString;
|
|
32
|
+
entity: z.ZodString;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
export declare const traceLogStep: z.ZodObject<{
|
|
35
|
+
atMs: z.ZodNumber;
|
|
36
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
37
|
+
type: z.ZodLiteral<"log">;
|
|
38
|
+
level: z.ZodString;
|
|
39
|
+
message: z.ZodString;
|
|
40
|
+
}, z.core.$strip>;
|
|
41
|
+
export declare const traceValidationStep: z.ZodObject<{
|
|
42
|
+
atMs: z.ZodNumber;
|
|
43
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
44
|
+
type: z.ZodLiteral<"validation">;
|
|
45
|
+
issues: z.ZodArray<z.ZodObject<{
|
|
46
|
+
path: z.ZodString;
|
|
47
|
+
message: z.ZodString;
|
|
48
|
+
}, z.core.$strip>>;
|
|
49
|
+
}, z.core.$strip>;
|
|
50
|
+
export declare const traceOutboundStep: z.ZodObject<{
|
|
51
|
+
atMs: z.ZodNumber;
|
|
52
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
53
|
+
type: z.ZodLiteral<"outbound">;
|
|
54
|
+
host: z.ZodString;
|
|
55
|
+
path: z.ZodString;
|
|
56
|
+
method: z.ZodString;
|
|
57
|
+
status: z.ZodNullable<z.ZodNumber>;
|
|
58
|
+
outcome: z.ZodString;
|
|
59
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
60
|
+
}, z.core.$strip>;
|
|
61
|
+
export declare const traceStoreStep: z.ZodObject<{
|
|
62
|
+
atMs: z.ZodNumber;
|
|
63
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
64
|
+
type: z.ZodLiteral<"store">;
|
|
65
|
+
binding: z.ZodString;
|
|
66
|
+
operation: z.ZodString;
|
|
67
|
+
outcome: z.ZodString;
|
|
68
|
+
}, z.core.$strip>;
|
|
69
|
+
export declare const traceErrorStep: z.ZodObject<{
|
|
70
|
+
atMs: z.ZodNumber;
|
|
71
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
72
|
+
type: z.ZodLiteral<"error">;
|
|
73
|
+
code: z.ZodNullable<z.ZodString>;
|
|
74
|
+
message: z.ZodString;
|
|
75
|
+
stack: z.ZodOptional<z.ZodString>;
|
|
76
|
+
}, z.core.$strip>;
|
|
77
|
+
export declare const traceStep: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
78
|
+
atMs: z.ZodNumber;
|
|
79
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
80
|
+
type: z.ZodLiteral<"check">;
|
|
81
|
+
permission: z.ZodString;
|
|
82
|
+
entity: z.ZodNullable<z.ZodString>;
|
|
83
|
+
allowed: z.ZodBoolean;
|
|
84
|
+
decidedBy: z.ZodNullable<z.ZodString>;
|
|
85
|
+
requires: z.ZodArray<z.ZodString>;
|
|
86
|
+
callerHas: z.ZodArray<z.ZodString>;
|
|
87
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
88
|
+
atMs: z.ZodNumber;
|
|
89
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
90
|
+
type: z.ZodLiteral<"sql">;
|
|
91
|
+
operation: z.ZodEnum<{
|
|
92
|
+
exec: "exec";
|
|
93
|
+
query: "query";
|
|
94
|
+
}>;
|
|
95
|
+
statement: z.ZodString;
|
|
96
|
+
params: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
|
|
97
|
+
rowsRead: z.ZodOptional<z.ZodNumber>;
|
|
98
|
+
rowsWritten: z.ZodOptional<z.ZodNumber>;
|
|
99
|
+
error: z.ZodOptional<z.ZodString>;
|
|
100
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
101
|
+
atMs: z.ZodNumber;
|
|
102
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
103
|
+
type: z.ZodLiteral<"emit">;
|
|
104
|
+
eventType: z.ZodString;
|
|
105
|
+
entity: z.ZodString;
|
|
106
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
107
|
+
atMs: z.ZodNumber;
|
|
108
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
109
|
+
type: z.ZodLiteral<"log">;
|
|
110
|
+
level: z.ZodString;
|
|
111
|
+
message: z.ZodString;
|
|
112
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
113
|
+
atMs: z.ZodNumber;
|
|
114
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
115
|
+
type: z.ZodLiteral<"validation">;
|
|
116
|
+
issues: z.ZodArray<z.ZodObject<{
|
|
117
|
+
path: z.ZodString;
|
|
118
|
+
message: z.ZodString;
|
|
119
|
+
}, z.core.$strip>>;
|
|
120
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
121
|
+
atMs: z.ZodNumber;
|
|
122
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
123
|
+
type: z.ZodLiteral<"outbound">;
|
|
124
|
+
host: z.ZodString;
|
|
125
|
+
path: z.ZodString;
|
|
126
|
+
method: z.ZodString;
|
|
127
|
+
status: z.ZodNullable<z.ZodNumber>;
|
|
128
|
+
outcome: z.ZodString;
|
|
129
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
130
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
131
|
+
atMs: z.ZodNumber;
|
|
132
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
133
|
+
type: z.ZodLiteral<"store">;
|
|
134
|
+
binding: z.ZodString;
|
|
135
|
+
operation: z.ZodString;
|
|
136
|
+
outcome: z.ZodString;
|
|
137
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
138
|
+
atMs: z.ZodNumber;
|
|
139
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
140
|
+
type: z.ZodLiteral<"error">;
|
|
141
|
+
code: z.ZodNullable<z.ZodString>;
|
|
142
|
+
message: z.ZodString;
|
|
143
|
+
stack: z.ZodOptional<z.ZodString>;
|
|
144
|
+
}, z.core.$strip>], "type">;
|
|
145
|
+
export declare const traceHead: z.ZodObject<{
|
|
146
|
+
invocationId: z.ZodString;
|
|
147
|
+
startedAt: z.ZodString;
|
|
148
|
+
tenantId: z.ZodString;
|
|
149
|
+
scopeId: z.ZodNullable<z.ZodString>;
|
|
150
|
+
vertical: z.ZodNullable<z.ZodString>;
|
|
151
|
+
surface: z.ZodNullable<z.ZodString>;
|
|
152
|
+
method: z.ZodNullable<z.ZodString>;
|
|
153
|
+
path: z.ZodNullable<z.ZodString>;
|
|
154
|
+
status: z.ZodNullable<z.ZodNumber>;
|
|
155
|
+
threw: z.ZodBoolean;
|
|
156
|
+
durationMs: z.ZodNumber;
|
|
157
|
+
level: z.ZodEnum<{
|
|
158
|
+
error: "error";
|
|
159
|
+
info: "info";
|
|
160
|
+
warn: "warn";
|
|
161
|
+
}>;
|
|
162
|
+
operation: z.ZodNullable<z.ZodString>;
|
|
163
|
+
problemCode: z.ZodNullable<z.ZodString>;
|
|
164
|
+
principalKind: z.ZodNullable<z.ZodString>;
|
|
165
|
+
principal: z.ZodNullable<z.ZodUnion<readonly [z.core.$ZodBranded<z.ZodString, "PrincipalId", "out">, z.ZodObject<{
|
|
166
|
+
system: z.core.$ZodBranded<z.ZodString, "ModuleId", "out">;
|
|
167
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
168
|
+
connection: z.ZodString;
|
|
169
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
170
|
+
capability: z.core.$ZodBranded<z.ZodString, "CapabilityId", "out">;
|
|
171
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
172
|
+
vertical: z.ZodString;
|
|
173
|
+
scope: z.core.$ZodBranded<z.ZodString, "ScopeId", "out">;
|
|
174
|
+
}, z.core.$strip>]>>;
|
|
175
|
+
eventCount: z.ZodNullable<z.ZodNumber>;
|
|
176
|
+
eventTypes: z.ZodArray<z.ZodString>;
|
|
177
|
+
entities: z.ZodArray<z.ZodString>;
|
|
178
|
+
versionId: z.ZodNullable<z.ZodString>;
|
|
179
|
+
specVersion: z.ZodNullable<z.ZodString>;
|
|
180
|
+
}, z.core.$strip>;
|
|
181
|
+
/** What a recorder kept and left out, so a reader never mistakes a thin trace for a quiet call. */
|
|
182
|
+
export declare const traceCapture: z.ZodObject<{
|
|
183
|
+
sqlParams: z.ZodBoolean;
|
|
184
|
+
stepsDropped: z.ZodNumber;
|
|
185
|
+
}, z.core.$strip>;
|
|
186
|
+
export declare const requestTrace: z.ZodObject<{
|
|
187
|
+
invocationId: z.ZodString;
|
|
188
|
+
startedAt: z.ZodString;
|
|
189
|
+
tenantId: z.ZodString;
|
|
190
|
+
scopeId: z.ZodNullable<z.ZodString>;
|
|
191
|
+
vertical: z.ZodNullable<z.ZodString>;
|
|
192
|
+
surface: z.ZodNullable<z.ZodString>;
|
|
193
|
+
method: z.ZodNullable<z.ZodString>;
|
|
194
|
+
path: z.ZodNullable<z.ZodString>;
|
|
195
|
+
status: z.ZodNullable<z.ZodNumber>;
|
|
196
|
+
threw: z.ZodBoolean;
|
|
197
|
+
durationMs: z.ZodNumber;
|
|
198
|
+
level: z.ZodEnum<{
|
|
199
|
+
error: "error";
|
|
200
|
+
info: "info";
|
|
201
|
+
warn: "warn";
|
|
202
|
+
}>;
|
|
203
|
+
operation: z.ZodNullable<z.ZodString>;
|
|
204
|
+
problemCode: z.ZodNullable<z.ZodString>;
|
|
205
|
+
principalKind: z.ZodNullable<z.ZodString>;
|
|
206
|
+
principal: z.ZodNullable<z.ZodUnion<readonly [z.core.$ZodBranded<z.ZodString, "PrincipalId", "out">, z.ZodObject<{
|
|
207
|
+
system: z.core.$ZodBranded<z.ZodString, "ModuleId", "out">;
|
|
208
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
209
|
+
connection: z.ZodString;
|
|
210
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
211
|
+
capability: z.core.$ZodBranded<z.ZodString, "CapabilityId", "out">;
|
|
212
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
213
|
+
vertical: z.ZodString;
|
|
214
|
+
scope: z.core.$ZodBranded<z.ZodString, "ScopeId", "out">;
|
|
215
|
+
}, z.core.$strip>]>>;
|
|
216
|
+
eventCount: z.ZodNullable<z.ZodNumber>;
|
|
217
|
+
eventTypes: z.ZodArray<z.ZodString>;
|
|
218
|
+
entities: z.ZodArray<z.ZodString>;
|
|
219
|
+
versionId: z.ZodNullable<z.ZodString>;
|
|
220
|
+
specVersion: z.ZodNullable<z.ZodString>;
|
|
221
|
+
steps: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
222
|
+
atMs: z.ZodNumber;
|
|
223
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
224
|
+
type: z.ZodLiteral<"check">;
|
|
225
|
+
permission: z.ZodString;
|
|
226
|
+
entity: z.ZodNullable<z.ZodString>;
|
|
227
|
+
allowed: z.ZodBoolean;
|
|
228
|
+
decidedBy: z.ZodNullable<z.ZodString>;
|
|
229
|
+
requires: z.ZodArray<z.ZodString>;
|
|
230
|
+
callerHas: z.ZodArray<z.ZodString>;
|
|
231
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
232
|
+
atMs: z.ZodNumber;
|
|
233
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
234
|
+
type: z.ZodLiteral<"sql">;
|
|
235
|
+
operation: z.ZodEnum<{
|
|
236
|
+
exec: "exec";
|
|
237
|
+
query: "query";
|
|
238
|
+
}>;
|
|
239
|
+
statement: z.ZodString;
|
|
240
|
+
params: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
|
|
241
|
+
rowsRead: z.ZodOptional<z.ZodNumber>;
|
|
242
|
+
rowsWritten: z.ZodOptional<z.ZodNumber>;
|
|
243
|
+
error: z.ZodOptional<z.ZodString>;
|
|
244
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
245
|
+
atMs: z.ZodNumber;
|
|
246
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
247
|
+
type: z.ZodLiteral<"emit">;
|
|
248
|
+
eventType: z.ZodString;
|
|
249
|
+
entity: z.ZodString;
|
|
250
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
251
|
+
atMs: z.ZodNumber;
|
|
252
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
253
|
+
type: z.ZodLiteral<"log">;
|
|
254
|
+
level: z.ZodString;
|
|
255
|
+
message: z.ZodString;
|
|
256
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
257
|
+
atMs: z.ZodNumber;
|
|
258
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
259
|
+
type: z.ZodLiteral<"validation">;
|
|
260
|
+
issues: z.ZodArray<z.ZodObject<{
|
|
261
|
+
path: z.ZodString;
|
|
262
|
+
message: z.ZodString;
|
|
263
|
+
}, z.core.$strip>>;
|
|
264
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
265
|
+
atMs: z.ZodNumber;
|
|
266
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
267
|
+
type: z.ZodLiteral<"outbound">;
|
|
268
|
+
host: z.ZodString;
|
|
269
|
+
path: z.ZodString;
|
|
270
|
+
method: z.ZodString;
|
|
271
|
+
status: z.ZodNullable<z.ZodNumber>;
|
|
272
|
+
outcome: z.ZodString;
|
|
273
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
274
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
275
|
+
atMs: z.ZodNumber;
|
|
276
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
277
|
+
type: z.ZodLiteral<"store">;
|
|
278
|
+
binding: z.ZodString;
|
|
279
|
+
operation: z.ZodString;
|
|
280
|
+
outcome: z.ZodString;
|
|
281
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
282
|
+
atMs: z.ZodNumber;
|
|
283
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
284
|
+
type: z.ZodLiteral<"error">;
|
|
285
|
+
code: z.ZodNullable<z.ZodString>;
|
|
286
|
+
message: z.ZodString;
|
|
287
|
+
stack: z.ZodOptional<z.ZodString>;
|
|
288
|
+
}, z.core.$strip>], "type">>;
|
|
289
|
+
capture: z.ZodObject<{
|
|
290
|
+
sqlParams: z.ZodBoolean;
|
|
291
|
+
stepsDropped: z.ZodNumber;
|
|
292
|
+
}, z.core.$strip>;
|
|
293
|
+
}, z.core.$strip>;
|
|
294
|
+
export type RequestTrace = z.infer<typeof requestTrace>;
|
|
295
|
+
//# sourceMappingURL=request-trace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-trace.d.ts","sourceRoot":"","sources":["../src/request-trace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAuBxB,eAAO,MAAM,cAAc;;;;;;;;;;iBASzB,CAAC;AAEH,eAAO,MAAM,YAAY;;;;;;;;;;;;;iBASvB,CAAC;AAEH,eAAO,MAAM,aAAa;;;;;;iBAKxB,CAAC;AAEH,eAAO,MAAM,YAAY;;;;;;iBAKvB,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;;;iBAI9B,CAAC;AAEH,eAAO,MAAM,iBAAiB;;;;;;;;;;iBAS5B,CAAC;AAEH,eAAO,MAAM,cAAc;;;;;;;iBAMzB,CAAC;AAEH,eAAO,MAAM,cAAc;;;;;;;iBAMzB,CAAC;AAEH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BASpB,CAAC;AAEH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsBpB,CAAC;AAEH,mGAAmG;AACnG,eAAO,MAAM,YAAY;;;iBAKvB,CAAC;AAEH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAIvB,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { actor } from './events.js';
|
|
3
|
+
import { TRACE_STEP_CAP } from './trace-sink.js';
|
|
4
|
+
/**
|
|
5
|
+
* A recorded request trace (#2358): the head of the hosted invocation line (#1746) plus the
|
|
6
|
+
* steps inside the call.
|
|
7
|
+
*
|
|
8
|
+
* The same shape serves every source. A local recorder fills the whole thing; the hosted
|
|
9
|
+
* record can fill the head and leave `steps` empty, because a step costs per-call
|
|
10
|
+
* instrumentation the hosted path samples or skips. A reader therefore treats an empty
|
|
11
|
+
* `steps` as "not recorded", never as "nothing happened" — which is why `stepsDropped` and
|
|
12
|
+
* `capture` exist: they say what the recorder kept and what it left out.
|
|
13
|
+
*
|
|
14
|
+
* The plain-TypeScript twin of these schemas is `trace-sink.ts`, which the platform entry can
|
|
15
|
+
* import without zod; `request-trace.test.ts` fails the build if the two disagree.
|
|
16
|
+
*/
|
|
17
|
+
// Not `.int()`: a recorder times with `performance.now()`, and a sub-millisecond SQL statement
|
|
18
|
+
// is the common case. The head's `durationMs` is fractional for the same reason.
|
|
19
|
+
const atMs = z.number().min(0);
|
|
20
|
+
const stepBase = { atMs, durationMs: z.number().min(0).optional() };
|
|
21
|
+
export const traceCheckStep = z.object({
|
|
22
|
+
type: z.literal('check'),
|
|
23
|
+
...stepBase,
|
|
24
|
+
permission: z.string().min(1),
|
|
25
|
+
entity: z.string().nullable(),
|
|
26
|
+
allowed: z.boolean(),
|
|
27
|
+
decidedBy: z.string().nullable(),
|
|
28
|
+
requires: z.array(z.string()),
|
|
29
|
+
callerHas: z.array(z.string()),
|
|
30
|
+
});
|
|
31
|
+
export const traceSqlStep = z.object({
|
|
32
|
+
type: z.literal('sql'),
|
|
33
|
+
...stepBase,
|
|
34
|
+
operation: z.enum(['query', 'exec']),
|
|
35
|
+
statement: z.string(),
|
|
36
|
+
params: z.array(z.unknown()).optional(),
|
|
37
|
+
rowsRead: z.number().int().min(0).optional(),
|
|
38
|
+
rowsWritten: z.number().int().min(0).optional(),
|
|
39
|
+
error: z.string().optional(),
|
|
40
|
+
});
|
|
41
|
+
export const traceEmitStep = z.object({
|
|
42
|
+
type: z.literal('emit'),
|
|
43
|
+
...stepBase,
|
|
44
|
+
eventType: z.string().min(1),
|
|
45
|
+
entity: z.string().min(1),
|
|
46
|
+
});
|
|
47
|
+
export const traceLogStep = z.object({
|
|
48
|
+
type: z.literal('log'),
|
|
49
|
+
...stepBase,
|
|
50
|
+
level: z.string(),
|
|
51
|
+
message: z.string(),
|
|
52
|
+
});
|
|
53
|
+
export const traceValidationStep = z.object({
|
|
54
|
+
type: z.literal('validation'),
|
|
55
|
+
...stepBase,
|
|
56
|
+
issues: z.array(z.object({ path: z.string(), message: z.string() })),
|
|
57
|
+
});
|
|
58
|
+
export const traceOutboundStep = z.object({
|
|
59
|
+
type: z.literal('outbound'),
|
|
60
|
+
...stepBase,
|
|
61
|
+
host: z.string(),
|
|
62
|
+
path: z.string(),
|
|
63
|
+
method: z.string(),
|
|
64
|
+
status: z.number().int().nullable(),
|
|
65
|
+
outcome: z.string(),
|
|
66
|
+
reason: z.string().optional(),
|
|
67
|
+
});
|
|
68
|
+
export const traceStoreStep = z.object({
|
|
69
|
+
type: z.literal('store'),
|
|
70
|
+
...stepBase,
|
|
71
|
+
binding: z.string(),
|
|
72
|
+
operation: z.string(),
|
|
73
|
+
outcome: z.string(),
|
|
74
|
+
});
|
|
75
|
+
export const traceErrorStep = z.object({
|
|
76
|
+
type: z.literal('error'),
|
|
77
|
+
...stepBase,
|
|
78
|
+
code: z.string().nullable(),
|
|
79
|
+
message: z.string(),
|
|
80
|
+
stack: z.string().optional(),
|
|
81
|
+
});
|
|
82
|
+
export const traceStep = z.discriminatedUnion('type', [
|
|
83
|
+
traceCheckStep,
|
|
84
|
+
traceSqlStep,
|
|
85
|
+
traceEmitStep,
|
|
86
|
+
traceLogStep,
|
|
87
|
+
traceValidationStep,
|
|
88
|
+
traceOutboundStep,
|
|
89
|
+
traceStoreStep,
|
|
90
|
+
traceErrorStep,
|
|
91
|
+
]);
|
|
92
|
+
export const traceHead = z.object({
|
|
93
|
+
invocationId: z.string().min(1),
|
|
94
|
+
startedAt: z.string().min(1),
|
|
95
|
+
tenantId: z.string(),
|
|
96
|
+
scopeId: z.string().nullable(),
|
|
97
|
+
vertical: z.string().nullable(),
|
|
98
|
+
surface: z.string().nullable(),
|
|
99
|
+
method: z.string().nullable(),
|
|
100
|
+
path: z.string().nullable(),
|
|
101
|
+
status: z.number().int().nullable(),
|
|
102
|
+
threw: z.boolean(),
|
|
103
|
+
durationMs: z.number().min(0),
|
|
104
|
+
level: z.enum(['error', 'warn', 'info']),
|
|
105
|
+
operation: z.string().nullable(),
|
|
106
|
+
problemCode: z.string().nullable(),
|
|
107
|
+
principalKind: z.string().nullable(),
|
|
108
|
+
principal: actor.nullable(),
|
|
109
|
+
eventCount: z.number().int().min(0).nullable(),
|
|
110
|
+
eventTypes: z.array(z.string()),
|
|
111
|
+
entities: z.array(z.string()),
|
|
112
|
+
versionId: z.string().nullable(),
|
|
113
|
+
specVersion: z.string().nullable(),
|
|
114
|
+
});
|
|
115
|
+
/** What a recorder kept and left out, so a reader never mistakes a thin trace for a quiet call. */
|
|
116
|
+
export const traceCapture = z.object({
|
|
117
|
+
/** SQL parameter values were stored (otherwise only the statement text). */
|
|
118
|
+
sqlParams: z.boolean(),
|
|
119
|
+
/** Steps past {@link TRACE_STEP_CAP}, counted rather than stored. */
|
|
120
|
+
stepsDropped: z.number().int().min(0),
|
|
121
|
+
});
|
|
122
|
+
export const requestTrace = z.object({
|
|
123
|
+
...traceHead.shape,
|
|
124
|
+
steps: z.array(traceStep).max(TRACE_STEP_CAP),
|
|
125
|
+
capture: traceCapture,
|
|
126
|
+
});
|
|
127
|
+
//# sourceMappingURL=request-trace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-trace.js","sourceRoot":"","sources":["../src/request-trace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD;;;;;;;;;;;;GAYG;AAEH,+FAA+F;AAC/F,iFAAiF;AACjF,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAC/B,MAAM,QAAQ,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC;AAEpE,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;IACxB,GAAG,QAAQ;IAC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AAC,MAAM,CAAC;IACnC,GAAG,SAAS,CAAC,KAAK;IAClB,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC;IAC7C,OAAO,EAAE,YAAY;CACtB,CAAC,CAAC"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The seam a request trace is recorded through (#2358).
|
|
3
|
+
*
|
|
4
|
+
* Plain TypeScript with no runtime import, for the reason `invocation-record.ts` is: the
|
|
5
|
+
* middleware that feeds a sink is bundled into the platform entry in front of every
|
|
6
|
+
* vertical, and that bundle may not carry zod. The matching zod schemas — what a recorder
|
|
7
|
+
* WRITES and `substrat logs` READS — are in `request-trace.ts`; a type-level test holds the
|
|
8
|
+
* two in step, so this file stays the narrow one without becoming a second source of truth.
|
|
9
|
+
*
|
|
10
|
+
* ## How a sink is found
|
|
11
|
+
*
|
|
12
|
+
* A host does not take a sink as an option. It reads one slot on `globalThis`,
|
|
13
|
+
* {@link TRACE_SINK_KEY}, at each hook, and does nothing when the slot is empty. That is the
|
|
14
|
+
* same arrangement the store-call tally uses, and it is what lets `substrat dev` turn traces
|
|
15
|
+
* on in a vertical's process with a `--import` preload and no edit to the vertical's
|
|
16
|
+
* `server.ts`. Nothing on a hosted path ever fills the slot, so "off in production" is a
|
|
17
|
+
* property of who installs a sink, not of a flag a deploy could forget to set.
|
|
18
|
+
*
|
|
19
|
+
* ## What a sink is NOT
|
|
20
|
+
*
|
|
21
|
+
* Not authority and not evidence. A trace is a debugging aid for the person running the
|
|
22
|
+
* vertical locally; nothing reads it to decide a request. A sink that throws must never fail
|
|
23
|
+
* a request, so a host calls it inside a guard and swallows the error.
|
|
24
|
+
*/
|
|
25
|
+
import type { Actor } from './events.js';
|
|
26
|
+
/** The `globalThis` slot a host reads its sink from. A registered symbol, so two copies of a package agree. */
|
|
27
|
+
export declare const TRACE_SINK_KEY: unique symbol;
|
|
28
|
+
/** The most steps one trace keeps; later ones are counted in `stepsDropped`, not stored. */
|
|
29
|
+
export declare const TRACE_STEP_CAP = 500;
|
|
30
|
+
/** The step kinds, in the order a reader lists them. */
|
|
31
|
+
export declare const TRACE_STEP_TYPES: readonly ['check', 'sql', 'emit', 'log', 'validation', 'outbound', 'store', 'error'];
|
|
32
|
+
export type TraceStepType = (typeof TRACE_STEP_TYPES)[number];
|
|
33
|
+
/** Fields every step carries. */
|
|
34
|
+
interface TraceStepBase {
|
|
35
|
+
/** Milliseconds from the invocation's start to this step; fractional where the clock is. */
|
|
36
|
+
atMs: number;
|
|
37
|
+
/** How long it took, when it has a duration. */
|
|
38
|
+
durationMs?: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* One permission check. `decidedBy` names the path an ALLOW took — `role:<key>`,
|
|
42
|
+
* `grant:<entity>`, `system:<module>` — read off the proof tuples. A DENY has no rule to
|
|
43
|
+
* name (the checker returns only the key it checked), so the recorder fills `requires` with
|
|
44
|
+
* the roles that hold the permission and `callerHas` with the roles the caller holds: that
|
|
45
|
+
* pair is "requires finance; caller has member". For a check on one entity the missing piece may
|
|
46
|
+
* be a grant rather than a role, so `requires` also names `grant:<permission>@<entity>` and
|
|
47
|
+
* `callerHas` lists the grants the caller holds for that permission. `callerHas` is empty for a
|
|
48
|
+
* subject that is not a principal (a system module, a connection), which holds no role to list:
|
|
49
|
+
* empty there means "not explained", not "holds nothing".
|
|
50
|
+
*/
|
|
51
|
+
export interface TraceCheckStep extends TraceStepBase {
|
|
52
|
+
type: 'check';
|
|
53
|
+
permission: string;
|
|
54
|
+
/** `<entityType>:<entityId>`, or `null` for a scope-wide check. */
|
|
55
|
+
entity: string | null;
|
|
56
|
+
allowed: boolean;
|
|
57
|
+
decidedBy: string | null;
|
|
58
|
+
requires: string[];
|
|
59
|
+
callerHas: string[];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* One `ctx.sql` statement, as it RAN. A statement in an operation that later rolled back (a
|
|
63
|
+
* refused check, a failed `ctx.atomic`) is still listed: a trace says what the call did, and the
|
|
64
|
+
* `error` step says how it ended, not which writes survived.
|
|
65
|
+
*
|
|
66
|
+
* `params` is present only when the sink asked for it ({@link TraceSink.capture}): a host never
|
|
67
|
+
* sends values a sink did not request, because a bound value is as likely to be a person's data
|
|
68
|
+
* or a password hash as an id.
|
|
69
|
+
*/
|
|
70
|
+
export interface TraceSqlStep extends TraceStepBase {
|
|
71
|
+
type: 'sql';
|
|
72
|
+
operation: 'query' | 'exec';
|
|
73
|
+
statement: string;
|
|
74
|
+
params?: unknown[];
|
|
75
|
+
/** Rows a `query` returned. */
|
|
76
|
+
rowsRead?: number;
|
|
77
|
+
/** Rows an `exec` changed. */
|
|
78
|
+
rowsWritten?: number;
|
|
79
|
+
/** The statement's error class and message, when it threw. */
|
|
80
|
+
error?: string;
|
|
81
|
+
}
|
|
82
|
+
/** One event the operation emitted. Ids and types only — never the payload. */
|
|
83
|
+
export interface TraceEmitStep extends TraceStepBase {
|
|
84
|
+
type: 'emit';
|
|
85
|
+
eventType: string;
|
|
86
|
+
/** `<entityType>:<entityId>`. */
|
|
87
|
+
entity: string;
|
|
88
|
+
}
|
|
89
|
+
/** One `ctx.log` line the operation wrote. */
|
|
90
|
+
export interface TraceLogStep extends TraceStepBase {
|
|
91
|
+
type: 'log';
|
|
92
|
+
level: string;
|
|
93
|
+
message: string;
|
|
94
|
+
}
|
|
95
|
+
/** The input did not parse. One entry per issue: a dotted path and a message. */
|
|
96
|
+
export interface TraceValidationStep extends TraceStepBase {
|
|
97
|
+
type: 'validation';
|
|
98
|
+
issues: {
|
|
99
|
+
path: string;
|
|
100
|
+
message: string;
|
|
101
|
+
}[];
|
|
102
|
+
}
|
|
103
|
+
/** One outbound `fetch`: host, redacted path, method, status and outcome — no header, body or query. */
|
|
104
|
+
export interface TraceOutboundStep extends TraceStepBase {
|
|
105
|
+
type: 'outbound';
|
|
106
|
+
host: string;
|
|
107
|
+
path: string;
|
|
108
|
+
method: string;
|
|
109
|
+
status: number | null;
|
|
110
|
+
outcome: string;
|
|
111
|
+
/** A failed call's error class, never its message. */
|
|
112
|
+
reason?: string;
|
|
113
|
+
}
|
|
114
|
+
/** One store call (a blob, a scope store). The input is not a field. */
|
|
115
|
+
export interface TraceStoreStep extends TraceStepBase {
|
|
116
|
+
type: 'store';
|
|
117
|
+
binding: string;
|
|
118
|
+
operation: string;
|
|
119
|
+
outcome: string;
|
|
120
|
+
}
|
|
121
|
+
/** An error that ended the invocation. `stack` is source-mapped where the host can. */
|
|
122
|
+
export interface TraceErrorStep extends TraceStepBase {
|
|
123
|
+
type: 'error';
|
|
124
|
+
code: string | null;
|
|
125
|
+
message: string;
|
|
126
|
+
stack?: string;
|
|
127
|
+
}
|
|
128
|
+
export type TraceStep = TraceCheckStep | TraceSqlStep | TraceEmitStep | TraceLogStep | TraceValidationStep | TraceOutboundStep | TraceStoreStep | TraceErrorStep;
|
|
129
|
+
/**
|
|
130
|
+
* The head of a trace. Every key below is the name the hosted invocation line (#1746) already
|
|
131
|
+
* uses for the same fact — a rename here would split the two. `null` reads as "not recorded".
|
|
132
|
+
*/
|
|
133
|
+
export interface TraceHead {
|
|
134
|
+
invocationId: string;
|
|
135
|
+
/** ISO 8601 instant the invocation started. */
|
|
136
|
+
startedAt: string;
|
|
137
|
+
tenantId: string;
|
|
138
|
+
scopeId: string | null;
|
|
139
|
+
vertical: string | null;
|
|
140
|
+
surface: string | null;
|
|
141
|
+
method: string | null;
|
|
142
|
+
/** Path only; the query string is dropped. */
|
|
143
|
+
path: string | null;
|
|
144
|
+
status: number | null;
|
|
145
|
+
threw: boolean;
|
|
146
|
+
durationMs: number;
|
|
147
|
+
level: 'error' | 'warn' | 'info';
|
|
148
|
+
operation: string | null;
|
|
149
|
+
problemCode: string | null;
|
|
150
|
+
principalKind: string | null;
|
|
151
|
+
/** Who the call ran as. Local only: the hosted line carries `principalKind` and no id. */
|
|
152
|
+
principal: Actor | null;
|
|
153
|
+
eventCount: number | null;
|
|
154
|
+
eventTypes: string[];
|
|
155
|
+
entities: string[];
|
|
156
|
+
versionId: string | null;
|
|
157
|
+
/** The vertical's spec version, when the host knows it. */
|
|
158
|
+
specVersion: string | null;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Two parts of one request report themselves: the HTTP middleware (method, path, status,
|
|
162
|
+
* duration) and the scope host (operation, principal, events). Each sends the keys it knows.
|
|
163
|
+
*/
|
|
164
|
+
export type TraceHeadPatch = Partial<TraceHead> & {
|
|
165
|
+
/**
|
|
166
|
+
* Steps the host knew of and did not send (outbound calls past the cap), so a reader sees a
|
|
167
|
+
* truncated list as truncated. The recorder adds it to `capture.stepsDropped`.
|
|
168
|
+
*/
|
|
169
|
+
stepsDropped?: number;
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Where a host sends what it saw. All three are synchronous and best-effort: a recorder
|
|
173
|
+
* batches and writes elsewhere, and a host calls them inside a guard.
|
|
174
|
+
*/
|
|
175
|
+
export interface TraceSink {
|
|
176
|
+
/**
|
|
177
|
+
* What this sink wants a host to send beyond the default. Absent reads as everything off.
|
|
178
|
+
* `sqlParams` is the one such request today: the values bound to a statement.
|
|
179
|
+
*/
|
|
180
|
+
readonly capture?: {
|
|
181
|
+
readonly sqlParams?: boolean;
|
|
182
|
+
};
|
|
183
|
+
/** Merge what one part of the host knows about the invocation; `undefined` values are skipped. */
|
|
184
|
+
head(invocationId: string, patch: TraceHeadPatch): void;
|
|
185
|
+
/** Append one step. */
|
|
186
|
+
step(invocationId: string, step: TraceStep): void;
|
|
187
|
+
/** The invocation is over: the head is as complete as it will get, so write the trace. */
|
|
188
|
+
end(invocationId: string): void;
|
|
189
|
+
}
|
|
190
|
+
/** Note that an invocation started now (or at `at`, on the `performance.now()` clock). */
|
|
191
|
+
export declare function markTraceStart(invocationId: string, at?: number): void;
|
|
192
|
+
/** Milliseconds since the invocation started, starting it now when nothing has. */
|
|
193
|
+
export declare function traceOffsetMs(invocationId: string): number;
|
|
194
|
+
/** The invocation is over: release its start. */
|
|
195
|
+
export declare function forgetTraceStart(invocationId: string): void;
|
|
196
|
+
/** The sink installed on this runtime, or `undefined` when tracing is off. */
|
|
197
|
+
export declare function installedTraceSink(): TraceSink | undefined;
|
|
198
|
+
export {};
|
|
199
|
+
//# sourceMappingURL=trace-sink.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace-sink.d.ts","sourceRoot":"","sources":["../src/trace-sink.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzC,+GAA+G;AAC/G,eAAO,MAAM,cAAc,EAAE,OAAO,MAAmD,CAAC;AAExF,4FAA4F;AAC5F,eAAO,MAAM,cAAc,MAAM,CAAC;AAElC,wDAAwD;AACxD,eAAO,MAAM,gBAAgB,YAC3B,OAAO,EACP,KAAK,EACL,MAAM,EACN,KAAK,EACL,YAAY,EACZ,UAAU,EACV,OAAO,EACP,OAAO,CACC,CAAC;AACX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE9D,iCAAiC;AACjC,UAAU,aAAa;IACrB,4FAA4F;IAC5F,IAAI,EAAE,MAAM,CAAC;IACb,gDAAgD;IAChD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,cAAe,SAAQ,aAAa;IACnD,IAAI,EAAE,OAAO,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,mEAAmE;IACnE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW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