@nuvio/shared 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Nuvio contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # `@nuvio/shared`
2
+
3
+ Wire protocol (Zod schemas), shared TypeScript types, and Node path helpers (`secure-path` export) used by `@nuvio/vite-plugin` and `@nuvio/overlay`.
4
+
5
+ See the [Nuvio README](../../README.md) and [CHANGELOG](../../CHANGELOG.md).
@@ -0,0 +1,877 @@
1
+ import { z } from 'zod';
2
+
3
+ /** WebSocket path on the Vite dev server (must match `configureServer` upgrade handler). */
4
+ declare const NUVIO_WS_PATH: "/__nuvio/ws";
5
+
6
+ /** Bump when wire payloads change incompatibly. */
7
+ declare const PROTOCOL_VERSION: 4;
8
+ declare const indexEntrySchema: z.ZodObject<{
9
+ id: z.ZodString;
10
+ file: z.ZodString;
11
+ line: z.ZodNumber;
12
+ column: z.ZodNumber;
13
+ }, "strip", z.ZodTypeAny, {
14
+ id: string;
15
+ file: string;
16
+ line: number;
17
+ column: number;
18
+ }, {
19
+ id: string;
20
+ file: string;
21
+ line: number;
22
+ column: number;
23
+ }>;
24
+ type IndexWireEntry = z.infer<typeof indexEntrySchema>;
25
+ declare const duplicateIdOccurrenceSchema: z.ZodObject<{
26
+ file: z.ZodString;
27
+ line: z.ZodNumber;
28
+ column: z.ZodNumber;
29
+ }, "strip", z.ZodTypeAny, {
30
+ file: string;
31
+ line: number;
32
+ column: number;
33
+ }, {
34
+ file: string;
35
+ line: number;
36
+ column: number;
37
+ }>;
38
+ declare const duplicateIdErrorSchema: z.ZodObject<{
39
+ id: z.ZodString;
40
+ occurrences: z.ZodArray<z.ZodObject<{
41
+ file: z.ZodString;
42
+ line: z.ZodNumber;
43
+ column: z.ZodNumber;
44
+ }, "strip", z.ZodTypeAny, {
45
+ file: string;
46
+ line: number;
47
+ column: number;
48
+ }, {
49
+ file: string;
50
+ line: number;
51
+ column: number;
52
+ }>, "many">;
53
+ }, "strip", z.ZodTypeAny, {
54
+ id: string;
55
+ occurrences: {
56
+ file: string;
57
+ line: number;
58
+ column: number;
59
+ }[];
60
+ }, {
61
+ id: string;
62
+ occurrences: {
63
+ file: string;
64
+ line: number;
65
+ column: number;
66
+ }[];
67
+ }>;
68
+ type DuplicateIdError = z.infer<typeof duplicateIdErrorSchema>;
69
+ declare const clientPingSchema: z.ZodObject<{
70
+ type: z.ZodLiteral<"ping">;
71
+ protocolVersion: z.ZodNumber;
72
+ requestId: z.ZodString;
73
+ }, "strip", z.ZodTypeAny, {
74
+ type: "ping";
75
+ protocolVersion: number;
76
+ requestId: string;
77
+ }, {
78
+ type: "ping";
79
+ protocolVersion: number;
80
+ requestId: string;
81
+ }>;
82
+ type ClientPing = z.infer<typeof clientPingSchema>;
83
+ declare const clientSelectSchema: z.ZodObject<{
84
+ type: z.ZodLiteral<"select">;
85
+ protocolVersion: z.ZodNumber;
86
+ requestId: z.ZodString;
87
+ id: z.ZodString;
88
+ }, "strip", z.ZodTypeAny, {
89
+ id: string;
90
+ type: "select";
91
+ protocolVersion: number;
92
+ requestId: string;
93
+ }, {
94
+ id: string;
95
+ type: "select";
96
+ protocolVersion: number;
97
+ requestId: string;
98
+ }>;
99
+ type ClientSelect = z.infer<typeof clientSelectSchema>;
100
+ declare const patchOpSetTextSchema: z.ZodObject<{
101
+ kind: z.ZodLiteral<"setText">;
102
+ text: z.ZodString;
103
+ }, "strip", z.ZodTypeAny, {
104
+ kind: "setText";
105
+ text: string;
106
+ }, {
107
+ kind: "setText";
108
+ text: string;
109
+ }>;
110
+ declare const patchOpMergeTailwindSchema: z.ZodObject<{
111
+ kind: z.ZodLiteral<"mergeTailwindClassName">;
112
+ classNameFragment: z.ZodString;
113
+ }, "strip", z.ZodTypeAny, {
114
+ kind: "mergeTailwindClassName";
115
+ classNameFragment: string;
116
+ }, {
117
+ kind: "mergeTailwindClassName";
118
+ classNameFragment: string;
119
+ }>;
120
+ /** Reorder host among JSX element siblings under a flex/grid parent (Phase 4). */
121
+ declare const patchOpMoveSiblingSchema: z.ZodObject<{
122
+ kind: z.ZodLiteral<"moveSibling">;
123
+ direction: z.ZodEnum<["up", "down"]>;
124
+ }, "strip", z.ZodTypeAny, {
125
+ kind: "moveSibling";
126
+ direction: "up" | "down";
127
+ }, {
128
+ kind: "moveSibling";
129
+ direction: "up" | "down";
130
+ }>;
131
+ /** Toggle `hidden` on a string-literal className (Phase 4 toolbar). */
132
+ declare const patchOpSetHiddenSchema: z.ZodObject<{
133
+ kind: z.ZodLiteral<"setHidden">;
134
+ hidden: z.ZodBoolean;
135
+ }, "strip", z.ZodTypeAny, {
136
+ kind: "setHidden";
137
+ hidden: boolean;
138
+ }, {
139
+ kind: "setHidden";
140
+ hidden: boolean;
141
+ }>;
142
+ /** Clone the host JSX element with a new unique `data-nuvio-id` (Phase 4 toolbar). */
143
+ declare const patchOpDuplicateHostSchema: z.ZodObject<{
144
+ kind: z.ZodLiteral<"duplicateHost">;
145
+ }, "strip", z.ZodTypeAny, {
146
+ kind: "duplicateHost";
147
+ }, {
148
+ kind: "duplicateHost";
149
+ }>;
150
+ declare const patchOpSchema: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
151
+ kind: z.ZodLiteral<"setText">;
152
+ text: z.ZodString;
153
+ }, "strip", z.ZodTypeAny, {
154
+ kind: "setText";
155
+ text: string;
156
+ }, {
157
+ kind: "setText";
158
+ text: string;
159
+ }>, z.ZodObject<{
160
+ kind: z.ZodLiteral<"mergeTailwindClassName">;
161
+ classNameFragment: z.ZodString;
162
+ }, "strip", z.ZodTypeAny, {
163
+ kind: "mergeTailwindClassName";
164
+ classNameFragment: string;
165
+ }, {
166
+ kind: "mergeTailwindClassName";
167
+ classNameFragment: string;
168
+ }>, z.ZodObject<{
169
+ kind: z.ZodLiteral<"moveSibling">;
170
+ direction: z.ZodEnum<["up", "down"]>;
171
+ }, "strip", z.ZodTypeAny, {
172
+ kind: "moveSibling";
173
+ direction: "up" | "down";
174
+ }, {
175
+ kind: "moveSibling";
176
+ direction: "up" | "down";
177
+ }>, z.ZodObject<{
178
+ kind: z.ZodLiteral<"setHidden">;
179
+ hidden: z.ZodBoolean;
180
+ }, "strip", z.ZodTypeAny, {
181
+ kind: "setHidden";
182
+ hidden: boolean;
183
+ }, {
184
+ kind: "setHidden";
185
+ hidden: boolean;
186
+ }>, z.ZodObject<{
187
+ kind: z.ZodLiteral<"duplicateHost">;
188
+ }, "strip", z.ZodTypeAny, {
189
+ kind: "duplicateHost";
190
+ }, {
191
+ kind: "duplicateHost";
192
+ }>]>;
193
+ type PatchOp = z.infer<typeof patchOpSchema>;
194
+ declare const clientPatchApplySchema: z.ZodObject<{
195
+ type: z.ZodLiteral<"patchApply">;
196
+ protocolVersion: z.ZodNumber;
197
+ requestId: z.ZodString;
198
+ id: z.ZodString;
199
+ ops: z.ZodArray<z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
200
+ kind: z.ZodLiteral<"setText">;
201
+ text: z.ZodString;
202
+ }, "strip", z.ZodTypeAny, {
203
+ kind: "setText";
204
+ text: string;
205
+ }, {
206
+ kind: "setText";
207
+ text: string;
208
+ }>, z.ZodObject<{
209
+ kind: z.ZodLiteral<"mergeTailwindClassName">;
210
+ classNameFragment: z.ZodString;
211
+ }, "strip", z.ZodTypeAny, {
212
+ kind: "mergeTailwindClassName";
213
+ classNameFragment: string;
214
+ }, {
215
+ kind: "mergeTailwindClassName";
216
+ classNameFragment: string;
217
+ }>, z.ZodObject<{
218
+ kind: z.ZodLiteral<"moveSibling">;
219
+ direction: z.ZodEnum<["up", "down"]>;
220
+ }, "strip", z.ZodTypeAny, {
221
+ kind: "moveSibling";
222
+ direction: "up" | "down";
223
+ }, {
224
+ kind: "moveSibling";
225
+ direction: "up" | "down";
226
+ }>, z.ZodObject<{
227
+ kind: z.ZodLiteral<"setHidden">;
228
+ hidden: z.ZodBoolean;
229
+ }, "strip", z.ZodTypeAny, {
230
+ kind: "setHidden";
231
+ hidden: boolean;
232
+ }, {
233
+ kind: "setHidden";
234
+ hidden: boolean;
235
+ }>, z.ZodObject<{
236
+ kind: z.ZodLiteral<"duplicateHost">;
237
+ }, "strip", z.ZodTypeAny, {
238
+ kind: "duplicateHost";
239
+ }, {
240
+ kind: "duplicateHost";
241
+ }>]>, "many">;
242
+ /** When true, server validates and returns `patchAck` with `diffSummary` but does not write disk or push undo. */
243
+ dryRun: z.ZodOptional<z.ZodBoolean>;
244
+ }, "strip", z.ZodTypeAny, {
245
+ id: string;
246
+ type: "patchApply";
247
+ protocolVersion: number;
248
+ requestId: string;
249
+ ops: ({
250
+ kind: "setText";
251
+ text: string;
252
+ } | {
253
+ kind: "mergeTailwindClassName";
254
+ classNameFragment: string;
255
+ } | {
256
+ kind: "moveSibling";
257
+ direction: "up" | "down";
258
+ } | {
259
+ kind: "setHidden";
260
+ hidden: boolean;
261
+ } | {
262
+ kind: "duplicateHost";
263
+ })[];
264
+ dryRun?: boolean | undefined;
265
+ }, {
266
+ id: string;
267
+ type: "patchApply";
268
+ protocolVersion: number;
269
+ requestId: string;
270
+ ops: ({
271
+ kind: "setText";
272
+ text: string;
273
+ } | {
274
+ kind: "mergeTailwindClassName";
275
+ classNameFragment: string;
276
+ } | {
277
+ kind: "moveSibling";
278
+ direction: "up" | "down";
279
+ } | {
280
+ kind: "setHidden";
281
+ hidden: boolean;
282
+ } | {
283
+ kind: "duplicateHost";
284
+ })[];
285
+ dryRun?: boolean | undefined;
286
+ }>;
287
+ type ClientPatchApply = z.infer<typeof clientPatchApplySchema>;
288
+ declare const clientPatchUndoSchema: z.ZodObject<{
289
+ type: z.ZodLiteral<"patchUndo">;
290
+ protocolVersion: z.ZodNumber;
291
+ requestId: z.ZodString;
292
+ }, "strip", z.ZodTypeAny, {
293
+ type: "patchUndo";
294
+ protocolVersion: number;
295
+ requestId: string;
296
+ }, {
297
+ type: "patchUndo";
298
+ protocolVersion: number;
299
+ requestId: string;
300
+ }>;
301
+ type ClientPatchUndo = z.infer<typeof clientPatchUndoSchema>;
302
+ declare const clientMessageSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
303
+ type: z.ZodLiteral<"ping">;
304
+ protocolVersion: z.ZodNumber;
305
+ requestId: z.ZodString;
306
+ }, "strip", z.ZodTypeAny, {
307
+ type: "ping";
308
+ protocolVersion: number;
309
+ requestId: string;
310
+ }, {
311
+ type: "ping";
312
+ protocolVersion: number;
313
+ requestId: string;
314
+ }>, z.ZodObject<{
315
+ type: z.ZodLiteral<"select">;
316
+ protocolVersion: z.ZodNumber;
317
+ requestId: z.ZodString;
318
+ id: z.ZodString;
319
+ }, "strip", z.ZodTypeAny, {
320
+ id: string;
321
+ type: "select";
322
+ protocolVersion: number;
323
+ requestId: string;
324
+ }, {
325
+ id: string;
326
+ type: "select";
327
+ protocolVersion: number;
328
+ requestId: string;
329
+ }>, z.ZodObject<{
330
+ type: z.ZodLiteral<"patchApply">;
331
+ protocolVersion: z.ZodNumber;
332
+ requestId: z.ZodString;
333
+ id: z.ZodString;
334
+ ops: z.ZodArray<z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
335
+ kind: z.ZodLiteral<"setText">;
336
+ text: z.ZodString;
337
+ }, "strip", z.ZodTypeAny, {
338
+ kind: "setText";
339
+ text: string;
340
+ }, {
341
+ kind: "setText";
342
+ text: string;
343
+ }>, z.ZodObject<{
344
+ kind: z.ZodLiteral<"mergeTailwindClassName">;
345
+ classNameFragment: z.ZodString;
346
+ }, "strip", z.ZodTypeAny, {
347
+ kind: "mergeTailwindClassName";
348
+ classNameFragment: string;
349
+ }, {
350
+ kind: "mergeTailwindClassName";
351
+ classNameFragment: string;
352
+ }>, z.ZodObject<{
353
+ kind: z.ZodLiteral<"moveSibling">;
354
+ direction: z.ZodEnum<["up", "down"]>;
355
+ }, "strip", z.ZodTypeAny, {
356
+ kind: "moveSibling";
357
+ direction: "up" | "down";
358
+ }, {
359
+ kind: "moveSibling";
360
+ direction: "up" | "down";
361
+ }>, z.ZodObject<{
362
+ kind: z.ZodLiteral<"setHidden">;
363
+ hidden: z.ZodBoolean;
364
+ }, "strip", z.ZodTypeAny, {
365
+ kind: "setHidden";
366
+ hidden: boolean;
367
+ }, {
368
+ kind: "setHidden";
369
+ hidden: boolean;
370
+ }>, z.ZodObject<{
371
+ kind: z.ZodLiteral<"duplicateHost">;
372
+ }, "strip", z.ZodTypeAny, {
373
+ kind: "duplicateHost";
374
+ }, {
375
+ kind: "duplicateHost";
376
+ }>]>, "many">;
377
+ /** When true, server validates and returns `patchAck` with `diffSummary` but does not write disk or push undo. */
378
+ dryRun: z.ZodOptional<z.ZodBoolean>;
379
+ }, "strip", z.ZodTypeAny, {
380
+ id: string;
381
+ type: "patchApply";
382
+ protocolVersion: number;
383
+ requestId: string;
384
+ ops: ({
385
+ kind: "setText";
386
+ text: string;
387
+ } | {
388
+ kind: "mergeTailwindClassName";
389
+ classNameFragment: string;
390
+ } | {
391
+ kind: "moveSibling";
392
+ direction: "up" | "down";
393
+ } | {
394
+ kind: "setHidden";
395
+ hidden: boolean;
396
+ } | {
397
+ kind: "duplicateHost";
398
+ })[];
399
+ dryRun?: boolean | undefined;
400
+ }, {
401
+ id: string;
402
+ type: "patchApply";
403
+ protocolVersion: number;
404
+ requestId: string;
405
+ ops: ({
406
+ kind: "setText";
407
+ text: string;
408
+ } | {
409
+ kind: "mergeTailwindClassName";
410
+ classNameFragment: string;
411
+ } | {
412
+ kind: "moveSibling";
413
+ direction: "up" | "down";
414
+ } | {
415
+ kind: "setHidden";
416
+ hidden: boolean;
417
+ } | {
418
+ kind: "duplicateHost";
419
+ })[];
420
+ dryRun?: boolean | undefined;
421
+ }>, z.ZodObject<{
422
+ type: z.ZodLiteral<"patchUndo">;
423
+ protocolVersion: z.ZodNumber;
424
+ requestId: z.ZodString;
425
+ }, "strip", z.ZodTypeAny, {
426
+ type: "patchUndo";
427
+ protocolVersion: number;
428
+ requestId: string;
429
+ }, {
430
+ type: "patchUndo";
431
+ protocolVersion: number;
432
+ requestId: string;
433
+ }>]>;
434
+ type ClientMessage = z.infer<typeof clientMessageSchema>;
435
+ declare const serverPongSchema: z.ZodObject<{
436
+ type: z.ZodLiteral<"pong">;
437
+ protocolVersion: z.ZodNumber;
438
+ requestId: z.ZodString;
439
+ }, "strip", z.ZodTypeAny, {
440
+ type: "pong";
441
+ protocolVersion: number;
442
+ requestId: string;
443
+ }, {
444
+ type: "pong";
445
+ protocolVersion: number;
446
+ requestId: string;
447
+ }>;
448
+ declare const serverErrorSchema: z.ZodObject<{
449
+ type: z.ZodLiteral<"error">;
450
+ code: z.ZodString;
451
+ message: z.ZodString;
452
+ requestId: z.ZodOptional<z.ZodString>;
453
+ }, "strip", z.ZodTypeAny, {
454
+ code: string;
455
+ message: string;
456
+ type: "error";
457
+ requestId?: string | undefined;
458
+ }, {
459
+ code: string;
460
+ message: string;
461
+ type: "error";
462
+ requestId?: string | undefined;
463
+ }>;
464
+ declare const serverIndexReadySchema: z.ZodObject<{
465
+ type: z.ZodLiteral<"indexReady">;
466
+ protocolVersion: z.ZodNumber;
467
+ indexVersion: z.ZodNumber;
468
+ entries: z.ZodArray<z.ZodObject<{
469
+ id: z.ZodString;
470
+ file: z.ZodString;
471
+ line: z.ZodNumber;
472
+ column: z.ZodNumber;
473
+ }, "strip", z.ZodTypeAny, {
474
+ id: string;
475
+ file: string;
476
+ line: number;
477
+ column: number;
478
+ }, {
479
+ id: string;
480
+ file: string;
481
+ line: number;
482
+ column: number;
483
+ }>, "many">;
484
+ duplicateErrors: z.ZodArray<z.ZodObject<{
485
+ id: z.ZodString;
486
+ occurrences: z.ZodArray<z.ZodObject<{
487
+ file: z.ZodString;
488
+ line: z.ZodNumber;
489
+ column: z.ZodNumber;
490
+ }, "strip", z.ZodTypeAny, {
491
+ file: string;
492
+ line: number;
493
+ column: number;
494
+ }, {
495
+ file: string;
496
+ line: number;
497
+ column: number;
498
+ }>, "many">;
499
+ }, "strip", z.ZodTypeAny, {
500
+ id: string;
501
+ occurrences: {
502
+ file: string;
503
+ line: number;
504
+ column: number;
505
+ }[];
506
+ }, {
507
+ id: string;
508
+ occurrences: {
509
+ file: string;
510
+ line: number;
511
+ column: number;
512
+ }[];
513
+ }>, "many">;
514
+ }, "strip", z.ZodTypeAny, {
515
+ type: "indexReady";
516
+ entries: {
517
+ id: string;
518
+ file: string;
519
+ line: number;
520
+ column: number;
521
+ }[];
522
+ protocolVersion: number;
523
+ indexVersion: number;
524
+ duplicateErrors: {
525
+ id: string;
526
+ occurrences: {
527
+ file: string;
528
+ line: number;
529
+ column: number;
530
+ }[];
531
+ }[];
532
+ }, {
533
+ type: "indexReady";
534
+ entries: {
535
+ id: string;
536
+ file: string;
537
+ line: number;
538
+ column: number;
539
+ }[];
540
+ protocolVersion: number;
541
+ indexVersion: number;
542
+ duplicateErrors: {
543
+ id: string;
544
+ occurrences: {
545
+ file: string;
546
+ line: number;
547
+ column: number;
548
+ }[];
549
+ }[];
550
+ }>;
551
+ type ServerIndexReady = z.infer<typeof serverIndexReadySchema>;
552
+ declare const serverSelectAckSchema: z.ZodObject<{
553
+ type: z.ZodLiteral<"selectAck">;
554
+ protocolVersion: z.ZodNumber;
555
+ requestId: z.ZodString;
556
+ id: z.ZodString;
557
+ ok: z.ZodBoolean;
558
+ file: z.ZodOptional<z.ZodString>;
559
+ line: z.ZodOptional<z.ZodNumber>;
560
+ column: z.ZodOptional<z.ZodNumber>;
561
+ errorCode: z.ZodOptional<z.ZodString>;
562
+ errorMessage: z.ZodOptional<z.ZodString>;
563
+ }, "strip", z.ZodTypeAny, {
564
+ id: string;
565
+ type: "selectAck";
566
+ protocolVersion: number;
567
+ requestId: string;
568
+ ok: boolean;
569
+ file?: string | undefined;
570
+ line?: number | undefined;
571
+ column?: number | undefined;
572
+ errorCode?: string | undefined;
573
+ errorMessage?: string | undefined;
574
+ }, {
575
+ id: string;
576
+ type: "selectAck";
577
+ protocolVersion: number;
578
+ requestId: string;
579
+ ok: boolean;
580
+ file?: string | undefined;
581
+ line?: number | undefined;
582
+ column?: number | undefined;
583
+ errorCode?: string | undefined;
584
+ errorMessage?: string | undefined;
585
+ }>;
586
+ type ServerSelectAck = z.infer<typeof serverSelectAckSchema>;
587
+ declare const serverPatchAckSchema: z.ZodObject<{
588
+ type: z.ZodLiteral<"patchAck">;
589
+ protocolVersion: z.ZodNumber;
590
+ requestId: z.ZodString;
591
+ id: z.ZodString;
592
+ ok: z.ZodBoolean;
593
+ diffSummary: z.ZodOptional<z.ZodString>;
594
+ /** Present when this ack is for a `patchApply` with `dryRun: true`. */
595
+ dryRun: z.ZodOptional<z.ZodBoolean>;
596
+ /** Absolute path written on successful non-dry apply (for touched-file log). */
597
+ writtenFile: z.ZodOptional<z.ZodString>;
598
+ /** Server undo stack size after this apply (non-dry success only). */
599
+ undoStackDepth: z.ZodOptional<z.ZodNumber>;
600
+ errorCode: z.ZodOptional<z.ZodString>;
601
+ errorMessage: z.ZodOptional<z.ZodString>;
602
+ }, "strip", z.ZodTypeAny, {
603
+ id: string;
604
+ type: "patchAck";
605
+ protocolVersion: number;
606
+ requestId: string;
607
+ ok: boolean;
608
+ dryRun?: boolean | undefined;
609
+ errorCode?: string | undefined;
610
+ errorMessage?: string | undefined;
611
+ diffSummary?: string | undefined;
612
+ writtenFile?: string | undefined;
613
+ undoStackDepth?: number | undefined;
614
+ }, {
615
+ id: string;
616
+ type: "patchAck";
617
+ protocolVersion: number;
618
+ requestId: string;
619
+ ok: boolean;
620
+ dryRun?: boolean | undefined;
621
+ errorCode?: string | undefined;
622
+ errorMessage?: string | undefined;
623
+ diffSummary?: string | undefined;
624
+ writtenFile?: string | undefined;
625
+ undoStackDepth?: number | undefined;
626
+ }>;
627
+ type ServerPatchAck = z.infer<typeof serverPatchAckSchema>;
628
+ declare const serverPatchUndoAckSchema: z.ZodObject<{
629
+ type: z.ZodLiteral<"patchUndoAck">;
630
+ protocolVersion: z.ZodNumber;
631
+ requestId: z.ZodString;
632
+ ok: z.ZodBoolean;
633
+ file: z.ZodOptional<z.ZodString>;
634
+ /** Remaining in-memory undo snapshots after this undo (success only). */
635
+ undoStackDepth: z.ZodOptional<z.ZodNumber>;
636
+ errorCode: z.ZodOptional<z.ZodString>;
637
+ errorMessage: z.ZodOptional<z.ZodString>;
638
+ }, "strip", z.ZodTypeAny, {
639
+ type: "patchUndoAck";
640
+ protocolVersion: number;
641
+ requestId: string;
642
+ ok: boolean;
643
+ file?: string | undefined;
644
+ errorCode?: string | undefined;
645
+ errorMessage?: string | undefined;
646
+ undoStackDepth?: number | undefined;
647
+ }, {
648
+ type: "patchUndoAck";
649
+ protocolVersion: number;
650
+ requestId: string;
651
+ ok: boolean;
652
+ file?: string | undefined;
653
+ errorCode?: string | undefined;
654
+ errorMessage?: string | undefined;
655
+ undoStackDepth?: number | undefined;
656
+ }>;
657
+ type ServerPatchUndoAck = z.infer<typeof serverPatchUndoAckSchema>;
658
+ declare const serverMessageSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
659
+ type: z.ZodLiteral<"pong">;
660
+ protocolVersion: z.ZodNumber;
661
+ requestId: z.ZodString;
662
+ }, "strip", z.ZodTypeAny, {
663
+ type: "pong";
664
+ protocolVersion: number;
665
+ requestId: string;
666
+ }, {
667
+ type: "pong";
668
+ protocolVersion: number;
669
+ requestId: string;
670
+ }>, z.ZodObject<{
671
+ type: z.ZodLiteral<"error">;
672
+ code: z.ZodString;
673
+ message: z.ZodString;
674
+ requestId: z.ZodOptional<z.ZodString>;
675
+ }, "strip", z.ZodTypeAny, {
676
+ code: string;
677
+ message: string;
678
+ type: "error";
679
+ requestId?: string | undefined;
680
+ }, {
681
+ code: string;
682
+ message: string;
683
+ type: "error";
684
+ requestId?: string | undefined;
685
+ }>, z.ZodObject<{
686
+ type: z.ZodLiteral<"indexReady">;
687
+ protocolVersion: z.ZodNumber;
688
+ indexVersion: z.ZodNumber;
689
+ entries: z.ZodArray<z.ZodObject<{
690
+ id: z.ZodString;
691
+ file: z.ZodString;
692
+ line: z.ZodNumber;
693
+ column: z.ZodNumber;
694
+ }, "strip", z.ZodTypeAny, {
695
+ id: string;
696
+ file: string;
697
+ line: number;
698
+ column: number;
699
+ }, {
700
+ id: string;
701
+ file: string;
702
+ line: number;
703
+ column: number;
704
+ }>, "many">;
705
+ duplicateErrors: z.ZodArray<z.ZodObject<{
706
+ id: z.ZodString;
707
+ occurrences: z.ZodArray<z.ZodObject<{
708
+ file: z.ZodString;
709
+ line: z.ZodNumber;
710
+ column: z.ZodNumber;
711
+ }, "strip", z.ZodTypeAny, {
712
+ file: string;
713
+ line: number;
714
+ column: number;
715
+ }, {
716
+ file: string;
717
+ line: number;
718
+ column: number;
719
+ }>, "many">;
720
+ }, "strip", z.ZodTypeAny, {
721
+ id: string;
722
+ occurrences: {
723
+ file: string;
724
+ line: number;
725
+ column: number;
726
+ }[];
727
+ }, {
728
+ id: string;
729
+ occurrences: {
730
+ file: string;
731
+ line: number;
732
+ column: number;
733
+ }[];
734
+ }>, "many">;
735
+ }, "strip", z.ZodTypeAny, {
736
+ type: "indexReady";
737
+ entries: {
738
+ id: string;
739
+ file: string;
740
+ line: number;
741
+ column: number;
742
+ }[];
743
+ protocolVersion: number;
744
+ indexVersion: number;
745
+ duplicateErrors: {
746
+ id: string;
747
+ occurrences: {
748
+ file: string;
749
+ line: number;
750
+ column: number;
751
+ }[];
752
+ }[];
753
+ }, {
754
+ type: "indexReady";
755
+ entries: {
756
+ id: string;
757
+ file: string;
758
+ line: number;
759
+ column: number;
760
+ }[];
761
+ protocolVersion: number;
762
+ indexVersion: number;
763
+ duplicateErrors: {
764
+ id: string;
765
+ occurrences: {
766
+ file: string;
767
+ line: number;
768
+ column: number;
769
+ }[];
770
+ }[];
771
+ }>, z.ZodObject<{
772
+ type: z.ZodLiteral<"selectAck">;
773
+ protocolVersion: z.ZodNumber;
774
+ requestId: z.ZodString;
775
+ id: z.ZodString;
776
+ ok: z.ZodBoolean;
777
+ file: z.ZodOptional<z.ZodString>;
778
+ line: z.ZodOptional<z.ZodNumber>;
779
+ column: z.ZodOptional<z.ZodNumber>;
780
+ errorCode: z.ZodOptional<z.ZodString>;
781
+ errorMessage: z.ZodOptional<z.ZodString>;
782
+ }, "strip", z.ZodTypeAny, {
783
+ id: string;
784
+ type: "selectAck";
785
+ protocolVersion: number;
786
+ requestId: string;
787
+ ok: boolean;
788
+ file?: string | undefined;
789
+ line?: number | undefined;
790
+ column?: number | undefined;
791
+ errorCode?: string | undefined;
792
+ errorMessage?: string | undefined;
793
+ }, {
794
+ id: string;
795
+ type: "selectAck";
796
+ protocolVersion: number;
797
+ requestId: string;
798
+ ok: boolean;
799
+ file?: string | undefined;
800
+ line?: number | undefined;
801
+ column?: number | undefined;
802
+ errorCode?: string | undefined;
803
+ errorMessage?: string | undefined;
804
+ }>, z.ZodObject<{
805
+ type: z.ZodLiteral<"patchAck">;
806
+ protocolVersion: z.ZodNumber;
807
+ requestId: z.ZodString;
808
+ id: z.ZodString;
809
+ ok: z.ZodBoolean;
810
+ diffSummary: z.ZodOptional<z.ZodString>;
811
+ /** Present when this ack is for a `patchApply` with `dryRun: true`. */
812
+ dryRun: z.ZodOptional<z.ZodBoolean>;
813
+ /** Absolute path written on successful non-dry apply (for touched-file log). */
814
+ writtenFile: z.ZodOptional<z.ZodString>;
815
+ /** Server undo stack size after this apply (non-dry success only). */
816
+ undoStackDepth: z.ZodOptional<z.ZodNumber>;
817
+ errorCode: z.ZodOptional<z.ZodString>;
818
+ errorMessage: z.ZodOptional<z.ZodString>;
819
+ }, "strip", z.ZodTypeAny, {
820
+ id: string;
821
+ type: "patchAck";
822
+ protocolVersion: number;
823
+ requestId: string;
824
+ ok: boolean;
825
+ dryRun?: boolean | undefined;
826
+ errorCode?: string | undefined;
827
+ errorMessage?: string | undefined;
828
+ diffSummary?: string | undefined;
829
+ writtenFile?: string | undefined;
830
+ undoStackDepth?: number | undefined;
831
+ }, {
832
+ id: string;
833
+ type: "patchAck";
834
+ protocolVersion: number;
835
+ requestId: string;
836
+ ok: boolean;
837
+ dryRun?: boolean | undefined;
838
+ errorCode?: string | undefined;
839
+ errorMessage?: string | undefined;
840
+ diffSummary?: string | undefined;
841
+ writtenFile?: string | undefined;
842
+ undoStackDepth?: number | undefined;
843
+ }>, z.ZodObject<{
844
+ type: z.ZodLiteral<"patchUndoAck">;
845
+ protocolVersion: z.ZodNumber;
846
+ requestId: z.ZodString;
847
+ ok: z.ZodBoolean;
848
+ file: z.ZodOptional<z.ZodString>;
849
+ /** Remaining in-memory undo snapshots after this undo (success only). */
850
+ undoStackDepth: z.ZodOptional<z.ZodNumber>;
851
+ errorCode: z.ZodOptional<z.ZodString>;
852
+ errorMessage: z.ZodOptional<z.ZodString>;
853
+ }, "strip", z.ZodTypeAny, {
854
+ type: "patchUndoAck";
855
+ protocolVersion: number;
856
+ requestId: string;
857
+ ok: boolean;
858
+ file?: string | undefined;
859
+ errorCode?: string | undefined;
860
+ errorMessage?: string | undefined;
861
+ undoStackDepth?: number | undefined;
862
+ }, {
863
+ type: "patchUndoAck";
864
+ protocolVersion: number;
865
+ requestId: string;
866
+ ok: boolean;
867
+ file?: string | undefined;
868
+ errorCode?: string | undefined;
869
+ errorMessage?: string | undefined;
870
+ undoStackDepth?: number | undefined;
871
+ }>]>;
872
+ type ServerMessage = z.infer<typeof serverMessageSchema>;
873
+ declare function parseClientMessage(raw: string): ClientMessage | null;
874
+ declare function parseServerMessage(raw: string): ServerMessage | null;
875
+ declare function serializeServerMessage(msg: ServerMessage): string;
876
+
877
+ export { type ClientMessage, type ClientPatchApply, type ClientPatchUndo, type ClientPing, type ClientSelect, type DuplicateIdError, type IndexWireEntry, NUVIO_WS_PATH, PROTOCOL_VERSION, type PatchOp, type ServerIndexReady, type ServerMessage, type ServerPatchAck, type ServerPatchUndoAck, type ServerSelectAck, clientMessageSchema, clientPatchApplySchema, clientPatchUndoSchema, clientPingSchema, clientSelectSchema, duplicateIdErrorSchema, duplicateIdOccurrenceSchema, indexEntrySchema, parseClientMessage, parseServerMessage, patchOpDuplicateHostSchema, patchOpMergeTailwindSchema, patchOpMoveSiblingSchema, patchOpSchema, patchOpSetHiddenSchema, patchOpSetTextSchema, serializeServerMessage, serverErrorSchema, serverIndexReadySchema, serverMessageSchema, serverPatchAckSchema, serverPatchUndoAckSchema, serverPongSchema, serverSelectAckSchema };
package/dist/index.js ADDED
@@ -0,0 +1,194 @@
1
+ // src/constants.ts
2
+ var NUVIO_WS_PATH = "/__nuvio/ws";
3
+
4
+ // src/protocol.ts
5
+ import { z } from "zod";
6
+ var PROTOCOL_VERSION = 4;
7
+ var indexEntrySchema = z.object({
8
+ id: z.string(),
9
+ file: z.string(),
10
+ line: z.number().int(),
11
+ column: z.number().int()
12
+ });
13
+ var duplicateIdOccurrenceSchema = z.object({
14
+ file: z.string(),
15
+ line: z.number().int(),
16
+ column: z.number().int()
17
+ });
18
+ var duplicateIdErrorSchema = z.object({
19
+ id: z.string(),
20
+ occurrences: z.array(duplicateIdOccurrenceSchema)
21
+ });
22
+ var clientPingSchema = z.object({
23
+ type: z.literal("ping"),
24
+ protocolVersion: z.number().int(),
25
+ requestId: z.string().min(1)
26
+ });
27
+ var clientSelectSchema = z.object({
28
+ type: z.literal("select"),
29
+ protocolVersion: z.number().int(),
30
+ requestId: z.string().min(1),
31
+ id: z.string().min(1)
32
+ });
33
+ var patchOpSetTextSchema = z.object({
34
+ kind: z.literal("setText"),
35
+ text: z.string()
36
+ });
37
+ var patchOpMergeTailwindSchema = z.object({
38
+ kind: z.literal("mergeTailwindClassName"),
39
+ classNameFragment: z.string()
40
+ });
41
+ var patchOpMoveSiblingSchema = z.object({
42
+ kind: z.literal("moveSibling"),
43
+ direction: z.enum(["up", "down"])
44
+ });
45
+ var patchOpSetHiddenSchema = z.object({
46
+ kind: z.literal("setHidden"),
47
+ hidden: z.boolean()
48
+ });
49
+ var patchOpDuplicateHostSchema = z.object({
50
+ kind: z.literal("duplicateHost")
51
+ });
52
+ var patchOpSchema = z.discriminatedUnion("kind", [
53
+ patchOpSetTextSchema,
54
+ patchOpMergeTailwindSchema,
55
+ patchOpMoveSiblingSchema,
56
+ patchOpSetHiddenSchema,
57
+ patchOpDuplicateHostSchema
58
+ ]);
59
+ var clientPatchApplySchema = z.object({
60
+ type: z.literal("patchApply"),
61
+ protocolVersion: z.number().int(),
62
+ requestId: z.string().min(1),
63
+ id: z.string().min(1),
64
+ ops: z.array(patchOpSchema).min(1),
65
+ /** When true, server validates and returns `patchAck` with `diffSummary` but does not write disk or push undo. */
66
+ dryRun: z.boolean().optional()
67
+ });
68
+ var clientPatchUndoSchema = z.object({
69
+ type: z.literal("patchUndo"),
70
+ protocolVersion: z.number().int(),
71
+ requestId: z.string().min(1)
72
+ });
73
+ var clientMessageSchema = z.discriminatedUnion("type", [
74
+ clientPingSchema,
75
+ clientSelectSchema,
76
+ clientPatchApplySchema,
77
+ clientPatchUndoSchema
78
+ ]);
79
+ var serverPongSchema = z.object({
80
+ type: z.literal("pong"),
81
+ protocolVersion: z.number().int(),
82
+ requestId: z.string()
83
+ });
84
+ var serverErrorSchema = z.object({
85
+ type: z.literal("error"),
86
+ code: z.string(),
87
+ message: z.string(),
88
+ requestId: z.string().optional()
89
+ });
90
+ var serverIndexReadySchema = z.object({
91
+ type: z.literal("indexReady"),
92
+ protocolVersion: z.number().int(),
93
+ indexVersion: z.number().int(),
94
+ entries: z.array(indexEntrySchema),
95
+ duplicateErrors: z.array(duplicateIdErrorSchema)
96
+ });
97
+ var serverSelectAckSchema = z.object({
98
+ type: z.literal("selectAck"),
99
+ protocolVersion: z.number().int(),
100
+ requestId: z.string(),
101
+ id: z.string(),
102
+ ok: z.boolean(),
103
+ file: z.string().optional(),
104
+ line: z.number().int().optional(),
105
+ column: z.number().int().optional(),
106
+ errorCode: z.string().optional(),
107
+ errorMessage: z.string().optional()
108
+ });
109
+ var serverPatchAckSchema = z.object({
110
+ type: z.literal("patchAck"),
111
+ protocolVersion: z.number().int(),
112
+ requestId: z.string(),
113
+ id: z.string(),
114
+ ok: z.boolean(),
115
+ diffSummary: z.string().optional(),
116
+ /** Present when this ack is for a `patchApply` with `dryRun: true`. */
117
+ dryRun: z.boolean().optional(),
118
+ /** Absolute path written on successful non-dry apply (for touched-file log). */
119
+ writtenFile: z.string().optional(),
120
+ /** Server undo stack size after this apply (non-dry success only). */
121
+ undoStackDepth: z.number().int().optional(),
122
+ errorCode: z.string().optional(),
123
+ errorMessage: z.string().optional()
124
+ });
125
+ var serverPatchUndoAckSchema = z.object({
126
+ type: z.literal("patchUndoAck"),
127
+ protocolVersion: z.number().int(),
128
+ requestId: z.string(),
129
+ ok: z.boolean(),
130
+ file: z.string().optional(),
131
+ /** Remaining in-memory undo snapshots after this undo (success only). */
132
+ undoStackDepth: z.number().int().optional(),
133
+ errorCode: z.string().optional(),
134
+ errorMessage: z.string().optional()
135
+ });
136
+ var serverMessageSchema = z.discriminatedUnion("type", [
137
+ serverPongSchema,
138
+ serverErrorSchema,
139
+ serverIndexReadySchema,
140
+ serverSelectAckSchema,
141
+ serverPatchAckSchema,
142
+ serverPatchUndoAckSchema
143
+ ]);
144
+ function parseClientMessage(raw) {
145
+ let json;
146
+ try {
147
+ json = JSON.parse(raw);
148
+ } catch {
149
+ return null;
150
+ }
151
+ const r = clientMessageSchema.safeParse(json);
152
+ return r.success ? r.data : null;
153
+ }
154
+ function parseServerMessage(raw) {
155
+ let json;
156
+ try {
157
+ json = JSON.parse(raw);
158
+ } catch {
159
+ return null;
160
+ }
161
+ const r = serverMessageSchema.safeParse(json);
162
+ return r.success ? r.data : null;
163
+ }
164
+ function serializeServerMessage(msg) {
165
+ return JSON.stringify(msg);
166
+ }
167
+ export {
168
+ NUVIO_WS_PATH,
169
+ PROTOCOL_VERSION,
170
+ clientMessageSchema,
171
+ clientPatchApplySchema,
172
+ clientPatchUndoSchema,
173
+ clientPingSchema,
174
+ clientSelectSchema,
175
+ duplicateIdErrorSchema,
176
+ duplicateIdOccurrenceSchema,
177
+ indexEntrySchema,
178
+ parseClientMessage,
179
+ parseServerMessage,
180
+ patchOpDuplicateHostSchema,
181
+ patchOpMergeTailwindSchema,
182
+ patchOpMoveSiblingSchema,
183
+ patchOpSchema,
184
+ patchOpSetHiddenSchema,
185
+ patchOpSetTextSchema,
186
+ serializeServerMessage,
187
+ serverErrorSchema,
188
+ serverIndexReadySchema,
189
+ serverMessageSchema,
190
+ serverPatchAckSchema,
191
+ serverPatchUndoAckSchema,
192
+ serverPongSchema,
193
+ serverSelectAckSchema
194
+ };
@@ -0,0 +1,13 @@
1
+ declare class PathEscapeError extends Error {
2
+ readonly root: string;
3
+ readonly candidate: string;
4
+ readonly name = "PathEscapeError";
5
+ constructor(root: string, candidate: string);
6
+ }
7
+ /**
8
+ * Ensures `candidateAbs` is the root directory itself or a path inside `rootAbs`.
9
+ * Use before any dev-server file write (Phase 1+).
10
+ */
11
+ declare function assertPathWithinRoot(rootAbs: string, candidateAbs: string): void;
12
+
13
+ export { PathEscapeError, assertPathWithinRoot };
@@ -0,0 +1,27 @@
1
+ // src/secure-path.ts
2
+ import path from "path";
3
+ var PathEscapeError = class extends Error {
4
+ constructor(root, candidate) {
5
+ super(`Path escapes project root: ${candidate} (root ${root})`);
6
+ this.root = root;
7
+ this.candidate = candidate;
8
+ }
9
+ root;
10
+ candidate;
11
+ name = "PathEscapeError";
12
+ };
13
+ function assertPathWithinRoot(rootAbs, candidateAbs) {
14
+ const root = path.resolve(rootAbs);
15
+ const candidate = path.resolve(candidateAbs);
16
+ if (candidate === root) {
17
+ return;
18
+ }
19
+ const relative = path.relative(root, candidate);
20
+ if (relative === "" || relative.startsWith("..") || path.isAbsolute(relative)) {
21
+ throw new PathEscapeError(root, candidate);
22
+ }
23
+ }
24
+ export {
25
+ PathEscapeError,
26
+ assertPathWithinRoot
27
+ };
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@nuvio/shared",
3
+ "version": "0.1.0",
4
+ "description": "Nuvio wire protocol (Zod), shared types, and path helpers for dev tooling.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/ehah/Nuvio.git",
9
+ "directory": "packages/shared"
10
+ },
11
+ "keywords": [
12
+ "nuvio",
13
+ "vite",
14
+ "devtools",
15
+ "protocol"
16
+ ],
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "README.md"
23
+ ],
24
+ "type": "module",
25
+ "main": "./dist/index.js",
26
+ "types": "./dist/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "import": "./dist/index.js"
31
+ },
32
+ "./secure-path": {
33
+ "types": "./dist/secure-path.d.ts",
34
+ "import": "./dist/secure-path.js"
35
+ }
36
+ },
37
+ "engines": {
38
+ "node": ">=20"
39
+ },
40
+ "dependencies": {
41
+ "zod": "^3.24.2"
42
+ },
43
+ "devDependencies": {
44
+ "@types/node": "^22.13.5",
45
+ "tsup": "^8.4.0",
46
+ "typescript": "^5.7.3",
47
+ "vitest": "^3.0.6"
48
+ },
49
+ "scripts": {
50
+ "build": "tsup src/index.ts src/secure-path.ts --format esm --dts --clean",
51
+ "typecheck": "tsc -p tsconfig.json --noEmit",
52
+ "test": "vitest run"
53
+ }
54
+ }