noofpi 1.2.0 → 2.0.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.
Files changed (42) hide show
  1. package/README.md +20 -4
  2. package/dist/{build-25H52PWT.js → build-PFCGDPPJ.js} +5 -4
  3. package/dist/chunk-3PSMWWUB.js +68 -0
  4. package/dist/{chunk-NALDZ3PS.js → chunk-I6TFIGFO.js} +13 -5
  5. package/dist/{chunk-NX6BO7UB.js → chunk-IE3WF5XF.js} +82 -2
  6. package/dist/{chunk-UF6YTIXD.js → chunk-LL3NO5EI.js} +361 -128
  7. package/dist/{chunk-FIJJ3EGL.js → chunk-MN5PVHC5.js} +4 -0
  8. package/dist/chunk-OKNF6XDO.js +14 -0
  9. package/dist/chunk-PPUFFGCH.js +168 -0
  10. package/dist/{chunk-WX2V6EYH.js → chunk-RUNIVVFH.js} +34 -10
  11. package/dist/{chunk-2XCZWFIQ.js → chunk-X3DYEZLK.js} +1 -1
  12. package/dist/{chunk-4YOOGEOF.js → chunk-YJVMBHNL.js} +1 -1
  13. package/dist/cli.js +130 -34
  14. package/dist/{dev-CC3RXV3G.js → dev-HTWUY27O.js} +47 -59
  15. package/dist/devtools-PLUN2DYV.js +958 -0
  16. package/dist/handler-C6NnwBfC.d.ts +17 -0
  17. package/dist/index.d.ts +21 -1
  18. package/dist/index.js +2 -2
  19. package/dist/{validation-ClXd_DAW.d.ts → payload-CL6tYBin.d.ts} +2 -40
  20. package/dist/prepare-KKQ2AEBW.js +24 -0
  21. package/dist/runtime/default-app.d.ts +6 -0
  22. package/dist/runtime/entry-client.d.ts +3 -0
  23. package/dist/runtime/entry-client.js +12 -4
  24. package/dist/runtime/entry-server.d.ts +8 -0
  25. package/dist/runtime/entry-server.js +2 -2
  26. package/dist/runtime/index.d.ts +7 -8
  27. package/dist/runtime/index.js +2 -2
  28. package/dist/runtime/routes.d.ts +13 -0
  29. package/dist/runtime/silent-diagnostics.d.ts +5 -0
  30. package/dist/server/bun.d.ts +15 -0
  31. package/dist/server/bun.js +14 -11
  32. package/dist/server/index.d.ts +9 -90
  33. package/dist/server/index.js +2 -2
  34. package/dist/server/node.d.ts +20 -0
  35. package/dist/server/node.js +2 -2
  36. package/dist/{start-PARBW5KN.js → start-AJKNZRJQ.js} +11 -7
  37. package/dist/typecheck-QACZZ6FN.js +30 -0
  38. package/dist/types-B6rQOOxS.d.ts +76 -0
  39. package/dist/validation-Dwpex2JZ.d.ts +40 -0
  40. package/package.json +22 -6
  41. package/dist/chunk-KGZP2RCF.js +0 -51
  42. package/dist/devtools-KTDSD5PR.js +0 -564
@@ -1,564 +0,0 @@
1
- import {
2
- normalizeMiddleware,
3
- parseMiddlewareFile
4
- } from "./chunk-6OWKWAIW.js";
5
- import {
6
- isServerRendered,
7
- matchRouteRules,
8
- resolveFetchMode
9
- } from "./chunk-FIJJ3EGL.js";
10
-
11
- // src/runtime/devtools.ts
12
- import {
13
- computed,
14
- createApp,
15
- defineComponent,
16
- h,
17
- reactive,
18
- ref
19
- } from "vue";
20
- function inspectRoute(route, config, middlewareFiles) {
21
- const files = [...middlewareFiles].sort().map(parseMiddlewareFile);
22
- const known = new Set(files.map((file) => file.name));
23
- const { layout } = route.meta;
24
- return {
25
- path: route.path,
26
- pattern: route.matched.at(-1)?.path ?? "(no match)",
27
- layout: layout === false ? "none" : typeof layout === "string" ? layout : "default",
28
- middleware: [
29
- ...files.filter((file) => file.global).map((file) => ({
30
- name: file.name,
31
- scope: "global",
32
- missing: false
33
- })),
34
- ...normalizeMiddleware(route.meta.middleware).map((name) => ({
35
- name,
36
- scope: "named",
37
- missing: !known.has(name)
38
- }))
39
- ],
40
- fetch: resolveFetchMode(config.doofpi.fetch, config.routeRules, route.path),
41
- rendering: isServerRendered(config.ssr, config.routeRules, route.path) ? "server" : "client",
42
- rule: matchRouteRules(config.routeRules, route.path)
43
- };
44
- }
45
- function describeRequest(entry, origin) {
46
- const url = entry.url.startsWith(origin) ? entry.url.slice(origin.length) : entry.url;
47
- const result = entry.error !== void 0 ? `failed: ${entry.error}` : entry.status === void 0 ? "pending" : String(entry.status);
48
- return {
49
- request: `${entry.method} ${url}`,
50
- detail: [
51
- entry.side,
52
- entry.mode,
53
- entry.transport,
54
- result,
55
- ...entry.ms === void 0 ? [] : [`${entry.ms}ms`]
56
- ].join(" \xB7 ")
57
- };
58
- }
59
- var MAX_VIOLATIONS = 50;
60
- var colors = {
61
- bg: "rgba(24,24,27,.96)",
62
- fg: "#e4e4e7",
63
- dim: "#a1a1aa",
64
- accent: "#42d392",
65
- alert: "#f87171",
66
- line: "rgba(255,255,255,.08)",
67
- card: "rgba(255,255,255,.035)"
68
- };
69
- var sans = "ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif";
70
- var mono = "ui-monospace, 'SF Mono', Menlo, Consolas, monospace";
71
- var panelStyle = {
72
- position: "fixed",
73
- right: "12px",
74
- bottom: "52px",
75
- zIndex: "2147483647",
76
- width: "380px",
77
- maxHeight: "70vh",
78
- display: "flex",
79
- flexDirection: "column",
80
- overflow: "hidden",
81
- boxSizing: "border-box",
82
- background: colors.bg,
83
- backdropFilter: "blur(12px)",
84
- color: colors.fg,
85
- font: `12px/1.5 ${sans}`,
86
- borderRadius: "14px",
87
- border: "1px solid rgba(66,211,146,.28)",
88
- boxShadow: "0 16px 48px rgba(0,0,0,.55), 0 0 32px rgba(66,211,146,.1), inset 0 1px 0 rgba(255,255,255,.06)"
89
- };
90
- var headerStyle = {
91
- display: "flex",
92
- alignItems: "center",
93
- gap: "10px",
94
- padding: "12px 14px",
95
- background: "linear-gradient(120deg, rgba(34,70,57,.9) 0%, rgba(24,24,27,0) 75%)",
96
- borderBottom: `1px solid ${colors.line}`,
97
- flexShrink: "0"
98
- };
99
- var bodyStyle = {
100
- overflow: "auto",
101
- padding: "10px 12px 12px",
102
- display: "flex",
103
- flexDirection: "column",
104
- gap: "10px"
105
- };
106
- var closeStyle = {
107
- display: "grid",
108
- placeItems: "center",
109
- width: "24px",
110
- height: "24px",
111
- padding: "0",
112
- background: "rgba(255,255,255,.06)",
113
- border: `1px solid ${colors.line}`,
114
- borderRadius: "50%",
115
- color: colors.dim,
116
- cursor: "pointer",
117
- font: `16px/1 ${sans}`
118
- };
119
- var sectionStyle = {
120
- background: colors.card,
121
- border: `1px solid ${colors.line}`,
122
- borderRadius: "10px",
123
- padding: "8px 10px 10px"
124
- };
125
- var sectionTitleStyle = {
126
- display: "flex",
127
- alignItems: "center",
128
- gap: "6px",
129
- marginBottom: "6px",
130
- color: colors.accent,
131
- fontSize: "10px",
132
- fontWeight: "700",
133
- letterSpacing: ".1em",
134
- textTransform: "uppercase"
135
- };
136
- var tones = {
137
- accent: {
138
- bg: "rgba(66,211,146,.14)",
139
- fg: "#6ee7b7",
140
- border: "rgba(66,211,146,.35)"
141
- },
142
- neutral: {
143
- bg: "rgba(255,255,255,.06)",
144
- fg: "#d4d4d8",
145
- border: colors.line
146
- },
147
- alert: {
148
- bg: "rgba(248,113,113,.14)",
149
- fg: "#fca5a5",
150
- border: "rgba(248,113,113,.4)"
151
- }
152
- };
153
- var chipStyle = (tone) => ({
154
- display: "inline-block",
155
- padding: "1px 7px",
156
- borderRadius: "999px",
157
- background: tones[tone].bg,
158
- color: tones[tone].fg,
159
- border: `1px solid ${tones[tone].border}`,
160
- fontSize: "10px",
161
- fontWeight: "600",
162
- letterSpacing: ".03em",
163
- whiteSpace: "nowrap"
164
- });
165
- var buttonStyle = {
166
- position: "fixed",
167
- right: "12px",
168
- bottom: "12px",
169
- zIndex: "2147483647",
170
- display: "inline-flex",
171
- alignItems: "center",
172
- gap: "8px",
173
- height: "34px",
174
- boxSizing: "border-box",
175
- padding: "0 14px 0 12px",
176
- background: "linear-gradient(135deg, rgba(34,70,57,.92) 0%, rgba(24,24,27,.92) 70%)",
177
- backdropFilter: "blur(8px)",
178
- color: colors.fg,
179
- font: "600 12px/1 ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif",
180
- letterSpacing: ".02em",
181
- border: "1px solid rgba(66,211,146,.4)",
182
- borderRadius: "999px",
183
- boxShadow: "0 6px 20px rgba(0,0,0,.35), 0 0 18px rgba(66,211,146,.18), inset 0 1px 0 rgba(255,255,255,.08)",
184
- cursor: "grab",
185
- touchAction: "none",
186
- userSelect: "none"
187
- };
188
- var dotStyle = (color) => ({
189
- width: "8px",
190
- height: "8px",
191
- borderRadius: "50%",
192
- background: color,
193
- boxShadow: `0 0 0 3px ${color}33, 0 0 10px ${color}`,
194
- flexShrink: "0"
195
- });
196
- var badgeStyle = {
197
- padding: "3px 7px",
198
- borderRadius: "999px",
199
- background: "rgba(248,113,113,.16)",
200
- border: "1px solid rgba(248,113,113,.4)",
201
- color: "#fca5a5",
202
- fontSize: "10px",
203
- fontWeight: "700",
204
- letterSpacing: ".04em"
205
- };
206
- var alertColor = colors.alert;
207
- var POSITION_KEY = "__noofpi_devtools_position";
208
- var DRAG_THRESHOLD = 4;
209
- var EDGE = 4;
210
- var BUTTON_SIZE = { width: 140, height: 34 };
211
- var PANEL_WIDTH = 380;
212
- var PANEL_GAP = 10;
213
- function clampPosition({ right, bottom }) {
214
- return {
215
- right: Math.max(
216
- EDGE,
217
- Math.min(right, window.innerWidth - BUTTON_SIZE.width - EDGE)
218
- ),
219
- bottom: Math.max(
220
- EDGE,
221
- Math.min(bottom, window.innerHeight - BUTTON_SIZE.height - EDGE)
222
- )
223
- };
224
- }
225
- function loadPosition() {
226
- try {
227
- const saved = JSON.parse(localStorage.getItem(POSITION_KEY) ?? "null");
228
- if (typeof saved?.right === "number" && typeof saved?.bottom === "number") {
229
- return clampPosition(saved);
230
- }
231
- } catch {
232
- }
233
- return { right: 12, bottom: 12 };
234
- }
235
- function savePosition(position) {
236
- try {
237
- localStorage.setItem(POSITION_KEY, JSON.stringify(position));
238
- } catch {
239
- }
240
- }
241
- function panelPlacement({ right, bottom }) {
242
- const maxRight = Math.max(EDGE, window.innerWidth - PANEL_WIDTH - EDGE);
243
- const horizontal = { right: `${Math.min(right, maxRight)}px` };
244
- return bottom > window.innerHeight / 2 ? {
245
- ...horizontal,
246
- top: `${window.innerHeight - bottom + PANEL_GAP}px`,
247
- bottom: "auto"
248
- } : { ...horizontal, bottom: `${bottom + BUTTON_SIZE.height + PANEL_GAP}px` };
249
- }
250
- var Devtools = defineComponent({
251
- name: "NoofpiDevtools",
252
- props: {
253
- router: { type: Object, required: true },
254
- config: { type: Object, required: true },
255
- middlewareFiles: { type: Array, required: true },
256
- violations: {
257
- type: Object,
258
- required: true
259
- },
260
- requests: { type: Object, required: false }
261
- },
262
- setup(props) {
263
- const open = ref(false);
264
- const pos = reactive(loadPosition());
265
- let drag = null;
266
- let moved = false;
267
- const report = computed(
268
- () => inspectRoute(
269
- props.router.currentRoute.value,
270
- props.config,
271
- props.middlewareFiles
272
- )
273
- );
274
- const onPointerDown = (event) => {
275
- drag = {
276
- x: event.clientX,
277
- y: event.clientY,
278
- right: pos.right,
279
- bottom: pos.bottom
280
- };
281
- moved = false;
282
- event.currentTarget.setPointerCapture(event.pointerId);
283
- };
284
- const onPointerMove = (event) => {
285
- if (!drag) return;
286
- const dx = event.clientX - drag.x;
287
- const dy = event.clientY - drag.y;
288
- if (!moved && Math.hypot(dx, dy) < DRAG_THRESHOLD) return;
289
- moved = true;
290
- Object.assign(
291
- pos,
292
- clampPosition({ right: drag.right - dx, bottom: drag.bottom - dy })
293
- );
294
- };
295
- const onPointerUp = () => {
296
- if (drag && moved) savePosition(pos);
297
- drag = null;
298
- };
299
- const onToggle = () => {
300
- if (moved) return void (moved = false);
301
- open.value = !open.value;
302
- };
303
- const chip = (text, tone = "neutral") => h("span", { style: chipStyle(tone) }, text);
304
- const none = () => h("div", { style: { color: colors.dim, fontStyle: "italic" } }, "none");
305
- const row = (label, value) => h("div", { style: { display: "flex", gap: "10px", padding: "2px 0" } }, [
306
- h("span", { style: { color: colors.dim, flex: "0 0 68px" } }, label),
307
- h(
308
- "span",
309
- {
310
- style: { fontFamily: mono, wordBreak: "break-all", minWidth: "0" }
311
- },
312
- value
313
- )
314
- ]);
315
- const section = (title, children, count) => h("section", { style: sectionStyle }, [
316
- h("div", { style: sectionTitleStyle }, [
317
- h("span", title),
318
- ...count === void 0 ? [] : [chip(String(count), count ? "accent" : "neutral")]
319
- ]),
320
- ...children
321
- ]);
322
- const requestStatus = (entry) => entry.error !== void 0 || entry.status !== void 0 && entry.status >= 400 ? colors.alert : entry.status === void 0 ? colors.dim : colors.accent;
323
- return () => {
324
- const r = report.value;
325
- const count = props.violations.list.length;
326
- const requests = props.requests?.list ?? [];
327
- const at = clampPosition(pos);
328
- const nodes = [
329
- h(
330
- "button",
331
- {
332
- type: "button",
333
- title: "Drag to move",
334
- style: {
335
- ...buttonStyle,
336
- right: `${at.right}px`,
337
- bottom: `${at.bottom}px`
338
- },
339
- "data-noofpi-devtools": "toggle",
340
- onPointerdown: onPointerDown,
341
- onPointermove: onPointerMove,
342
- onPointerup: onPointerUp,
343
- onPointercancel: onPointerUp,
344
- onClick: onToggle
345
- },
346
- [
347
- h("span", { style: dotStyle(count ? alertColor : colors.accent) }),
348
- h("span", "noofpi"),
349
- ...count ? [h("span", { style: badgeStyle }, `${count} CSP`)] : []
350
- ]
351
- )
352
- ];
353
- if (open.value) {
354
- nodes.push(
355
- h(
356
- "div",
357
- {
358
- style: { ...panelStyle, ...panelPlacement(at) },
359
- "data-noofpi-devtools": "panel"
360
- },
361
- [
362
- h("div", { style: headerStyle }, [
363
- h("span", { style: dotStyle(colors.accent) }),
364
- h(
365
- "span",
366
- {
367
- style: {
368
- flex: "1",
369
- fontSize: "14px",
370
- fontWeight: "700",
371
- letterSpacing: ".02em"
372
- }
373
- },
374
- [
375
- h("span", { style: { color: colors.accent } }, "noofpi"),
376
- h(
377
- "span",
378
- { style: { color: colors.dim, fontWeight: "500" } },
379
- " devtools"
380
- )
381
- ]
382
- ),
383
- h(
384
- "button",
385
- {
386
- type: "button",
387
- "aria-label": "Close devtools",
388
- style: closeStyle,
389
- onClick: () => open.value = false
390
- },
391
- "\xD7"
392
- )
393
- ]),
394
- h("div", { style: bodyStyle }, [
395
- section("Route", [
396
- row("path", r.path),
397
- row("pattern", r.pattern),
398
- row("layout", r.layout),
399
- row(
400
- "mode",
401
- h("span", { style: { display: "flex", gap: "6px" } }, [
402
- chip(
403
- `${r.rendering} render`,
404
- r.rendering === "server" ? "accent" : "neutral"
405
- ),
406
- chip(`${r.fetch} fetch`, "accent")
407
- ])
408
- )
409
- ]),
410
- section(
411
- "Middleware chain",
412
- r.middleware.length ? r.middleware.map(
413
- (m, index) => h(
414
- "div",
415
- {
416
- style: {
417
- display: "flex",
418
- alignItems: "center",
419
- gap: "8px",
420
- padding: "2px 0"
421
- }
422
- },
423
- [
424
- h(
425
- "span",
426
- { style: { color: colors.dim, width: "14px" } },
427
- String(index + 1)
428
- ),
429
- chip(
430
- m.scope,
431
- m.scope === "global" ? "neutral" : "accent"
432
- ),
433
- h("span", { style: { fontFamily: mono } }, m.name),
434
- ...m.missing ? [chip("missing", "alert")] : []
435
- ]
436
- )
437
- ) : [none()],
438
- r.middleware.length
439
- ),
440
- section("Route rules", [
441
- Object.keys(r.rule).length ? h(
442
- "div",
443
- {
444
- style: {
445
- fontFamily: mono,
446
- wordBreak: "break-all"
447
- }
448
- },
449
- JSON.stringify(r.rule)
450
- ) : none()
451
- ]),
452
- section(
453
- "doofpi requests",
454
- requests.length ? requests.map((entry) => {
455
- const { request, detail } = describeRequest(
456
- entry,
457
- window.location.origin
458
- );
459
- return h(
460
- "div",
461
- {
462
- style: {
463
- margin: "4px 0",
464
- padding: "2px 0 2px 8px",
465
- borderLeft: `2px solid ${requestStatus(entry)}`
466
- }
467
- },
468
- [
469
- h(
470
- "div",
471
- {
472
- style: {
473
- fontFamily: mono,
474
- wordBreak: "break-all"
475
- }
476
- },
477
- request
478
- ),
479
- h(
480
- "div",
481
- {
482
- style: { color: colors.dim, fontSize: "11px" }
483
- },
484
- detail
485
- )
486
- ]
487
- );
488
- }) : [none()],
489
- requests.length
490
- ),
491
- section(
492
- "CSP violations",
493
- count ? props.violations.list.map(
494
- (v) => h(
495
- "div",
496
- {
497
- style: {
498
- display: "flex",
499
- gap: "8px",
500
- padding: "2px 0",
501
- alignItems: "baseline"
502
- }
503
- },
504
- [
505
- chip(v.directive, "alert"),
506
- h(
507
- "span",
508
- {
509
- style: {
510
- fontFamily: mono,
511
- wordBreak: "break-all",
512
- minWidth: "0"
513
- }
514
- },
515
- `${v.blocked} ${v.source}`.trim()
516
- )
517
- ]
518
- )
519
- ) : [none()],
520
- count
521
- )
522
- ])
523
- ]
524
- )
525
- );
526
- }
527
- return nodes;
528
- };
529
- }
530
- });
531
- function mountDevtools(options) {
532
- const violations = reactive({ list: [] });
533
- const onViolation = (event) => {
534
- violations.list = [
535
- ...violations.list,
536
- {
537
- directive: event.effectiveDirective,
538
- blocked: event.blockedURI || "inline",
539
- source: event.sourceFile ? `${event.sourceFile}:${event.lineNumber}` : ""
540
- }
541
- ].slice(-MAX_VIOLATIONS);
542
- };
543
- document.addEventListener("securitypolicyviolation", onViolation);
544
- const host = document.createElement("div");
545
- host.id = "__noofpi_devtools";
546
- document.body.append(host);
547
- const app = createApp({
548
- render: () => h(Devtools, {
549
- ...options,
550
- violations
551
- })
552
- });
553
- app.mount(host);
554
- return () => {
555
- document.removeEventListener("securitypolicyviolation", onViolation);
556
- app.unmount();
557
- host.remove();
558
- };
559
- }
560
- export {
561
- describeRequest,
562
- inspectRoute,
563
- mountDevtools
564
- };