@highstate/library 0.9.16 → 0.9.18

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/src/timeweb.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { defineEntity, defineUnit, Type } from "@highstate/contract"
1
+ import { defineEntity, defineUnit, z } from "@highstate/contract"
2
2
  import { serverEntity } from "./common"
3
3
  import { keyPairEntity } from "./ssh"
4
4
 
5
5
  export const connectionEntity = defineEntity({
6
6
  type: "timeweb.connection",
7
7
 
8
- schema: Type.Object({
9
- name: Type.String(),
10
- apiToken: Type.String(),
8
+ schema: z.object({
9
+ name: z.string(),
10
+ apiToken: z.string(),
11
11
  }),
12
12
  })
13
13
 
@@ -15,7 +15,7 @@ export const connection = defineUnit({
15
15
  type: "timeweb.connection",
16
16
 
17
17
  secrets: {
18
- apiToken: Type.String(),
18
+ apiToken: z.string(),
19
19
  },
20
20
 
21
21
  outputs: {
@@ -23,9 +23,9 @@ export const connection = defineUnit({
23
23
  },
24
24
 
25
25
  meta: {
26
- displayName: "Timeweb Connection",
26
+ title: "Timeweb Connection",
27
27
  description: "Creates a new Timeweb connection.",
28
- primaryIcon: "material-symbols:cloud",
28
+ icon: "material-symbols:cloud",
29
29
  category: "Timeweb",
30
30
  },
31
31
 
@@ -39,9 +39,9 @@ export const virtualMachine = defineUnit({
39
39
  type: "timeweb.virtual-machine",
40
40
 
41
41
  args: {
42
- presetId: Type.Optional(Type.Number()),
43
- osId: Type.Optional(Type.Number()),
44
- availabilityZone: Type.String(),
42
+ presetId: z.number().optional(),
43
+ osId: z.number().optional(),
44
+ availabilityZone: z.string(),
45
45
  },
46
46
 
47
47
  inputs: {
@@ -53,7 +53,7 @@ export const virtualMachine = defineUnit({
53
53
  },
54
54
 
55
55
  secrets: {
56
- sshPrivateKey: Type.Optional(Type.String()),
56
+ sshPrivateKey: z.string().optional(),
57
57
  },
58
58
 
59
59
  outputs: {
@@ -61,9 +61,9 @@ export const virtualMachine = defineUnit({
61
61
  },
62
62
 
63
63
  meta: {
64
- displayName: "Timeweb Virtual Machine",
64
+ title: "Timeweb Virtual Machine",
65
65
  description: "Creates a new Timeweb virtual machine.",
66
- primaryIcon: "material-symbols:cloud",
66
+ icon: "material-symbols:cloud",
67
67
  secondaryIcon: "codicon:vm",
68
68
  category: "Timeweb",
69
69
  },
package/src/utils.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Type, type Static } from "@highstate/contract"
1
+ import { z } from "@highstate/contract"
2
2
 
3
3
  type PrefixWith<TString extends string, TPrefix extends string> = TPrefix extends ""
4
4
  ? TString
@@ -26,7 +26,7 @@ export function prefixKeysWith<T extends Record<string, unknown>, Prefix extends
26
26
  ) as PrefixedKeys<T, Prefix>
27
27
  }
28
28
 
29
- export const arrayPatchModeSchema = Type.StringEnum(["prepend", "replace"])
29
+ export const arrayPatchModeSchema = z.enum(["prepend", "replace"])
30
30
 
31
31
  /**
32
32
  * The mode to use when patching some array.
@@ -34,4 +34,4 @@ export const arrayPatchModeSchema = Type.StringEnum(["prepend", "replace"])
34
34
  * - `prepend`: Prepend the values of the new array to the existing array.
35
35
  * - `replace`: Replace the existing array with the new array.
36
36
  */
37
- export type ArrayPatchMode = Static<typeof arrayPatchModeSchema>
37
+ export type ArrayPatchMode = z.infer<typeof arrayPatchModeSchema>
package/src/wireguard.ts CHANGED
@@ -1,35 +1,35 @@
1
- import { defineEntity, defineUnit, Type, type Static, type TObject } from "@highstate/contract"
1
+ import { defineEntity, defineUnit, z } from "@highstate/contract"
2
2
  import { omit } from "remeda"
3
3
  import { clusterEntity, interfaceEntity, exposableWorkloadEntity } from "./k8s"
4
4
  import { l3EndpointEntity, l4EndpointEntity } from "./network"
5
5
  import { arrayPatchModeSchema } from "./utils"
6
6
 
7
- export const backendSchema = Type.StringEnum(["wireguard", "amneziawg"])
7
+ export const backendSchema = z.enum(["wireguard", "amneziawg"])
8
8
 
9
- export type Backend = Static<typeof backendSchema>
9
+ export type Backend = z.infer<typeof backendSchema>
10
10
 
11
11
  export const networkEntity = defineEntity({
12
12
  type: "wireguard.network",
13
13
 
14
- schema: Type.Object({
14
+ schema: z.object({
15
15
  backend: backendSchema,
16
- ipv6: Type.Boolean(),
16
+ ipv6: z.boolean(),
17
17
  }),
18
18
  })
19
19
 
20
- export const nodeExposePolicySchema = Type.StringEnum(["always", "when-has-endpoint", "never"])
20
+ export const nodeExposePolicySchema = z.enum(["always", "when-has-endpoint", "never"])
21
21
 
22
22
  export const peerEntity = defineEntity({
23
23
  type: "wireguard.peer",
24
24
 
25
- schema: Type.Object({
26
- name: Type.String(),
27
- network: Type.Optional(networkEntity.schema),
28
- publicKey: Type.String(),
29
- address: Type.Optional(Type.String()),
30
- allowedIps: Type.Array(Type.String()),
31
- endpoints: Type.Array(l4EndpointEntity.schema),
32
- allowedEndpoints: Type.Array(Type.Union([l3EndpointEntity.schema, l4EndpointEntity.schema])),
25
+ schema: z.object({
26
+ name: z.string(),
27
+ network: networkEntity.schema.optional(),
28
+ publicKey: z.string(),
29
+ address: z.string().optional(),
30
+ allowedIps: z.string().array(),
31
+ endpoints: l4EndpointEntity.schema.array(),
32
+ allowedEndpoints: z.union([l3EndpointEntity.schema, l4EndpointEntity.schema]).array(),
33
33
 
34
34
  /**
35
35
  * The pre-shared key of the WireGuard peer.
@@ -38,18 +38,18 @@ export const peerEntity = defineEntity({
38
38
  *
39
39
  * Will be ignored if both peers have `presharedKeyPart` set.
40
40
  */
41
- presharedKey: Type.Optional(Type.String()),
41
+ presharedKey: z.string().optional(),
42
42
 
43
43
  /**
44
44
  * The pre-shared key part of the WireGuard peer.
45
45
  *
46
46
  * If both peers have `presharedKeyPart` set, their `presharedKey` will be calculated as XOR of the two parts.
47
47
  */
48
- presharedKeyPart: Type.Optional(Type.String()),
48
+ presharedKeyPart: z.string().optional(),
49
49
 
50
- excludedIps: Type.Array(Type.String()),
51
- dns: Type.Array(Type.String()),
52
- listenPort: Type.Optional(Type.Number()),
50
+ excludedIps: z.string().array(),
51
+ dns: z.string().array(),
52
+ listenPort: z.number().optional(),
53
53
  }),
54
54
 
55
55
  meta: {
@@ -60,9 +60,9 @@ export const peerEntity = defineEntity({
60
60
  export const identityEntity = defineEntity({
61
61
  type: "wireguard.identity",
62
62
 
63
- schema: Type.Object({
63
+ schema: z.object({
64
64
  peer: peerEntity.schema,
65
- privateKey: Type.String(),
65
+ privateKey: z.string(),
66
66
  }),
67
67
 
68
68
  meta: {
@@ -70,10 +70,10 @@ export const identityEntity = defineEntity({
70
70
  },
71
71
  })
72
72
 
73
- export type Network = Static<typeof networkEntity.schema>
74
- export type Identity = Static<typeof identityEntity.schema>
75
- export type Peer = Static<typeof peerEntity.schema>
76
- export type NodeExposePolicy = Static<typeof nodeExposePolicySchema>
73
+ export type Network = z.infer<typeof networkEntity.schema>
74
+ export type Identity = z.infer<typeof identityEntity.schema>
75
+ export type Peer = z.infer<typeof peerEntity.schema>
76
+ export type NodeExposePolicy = z.infer<typeof nodeExposePolicySchema>
77
77
 
78
78
  /**
79
79
  * The network hols the shared configuration for the WireGuard identities, peers and nodes.
@@ -91,14 +91,14 @@ export const network = defineUnit({
91
91
  *
92
92
  * By default, the `wireguard` backend is used.
93
93
  */
94
- backend: Type.Default(backendSchema, "wireguard"),
94
+ backend: backendSchema.default("wireguard"),
95
95
 
96
96
  /**
97
97
  * The option to enable IPv6 support in the network.
98
98
  *
99
99
  * By default, IPv6 support is disabled.
100
100
  */
101
- ipv6: Type.Default(Type.Boolean(), false),
101
+ ipv6: z.boolean().default(false),
102
102
  },
103
103
 
104
104
  outputs: {
@@ -107,8 +107,8 @@ export const network = defineUnit({
107
107
 
108
108
  meta: {
109
109
  description: "The WireGuard network with some shared configuration.",
110
- primaryIcon: "simple-icons:wireguard",
111
- primaryIconColor: "#88171a",
110
+ icon: "simple-icons:wireguard",
111
+ iconColor: "#88171a",
112
112
  secondaryIcon: "mdi:local-area-network-connect",
113
113
  category: "VPN",
114
114
  },
@@ -125,21 +125,21 @@ const sharedPeerArgs = {
125
125
  *
126
126
  * If not provided, the peer will be named after the unit.
127
127
  */
128
- peerName: Type.Optional(Type.String()),
128
+ peerName: z.string().optional(),
129
129
 
130
130
  /**
131
131
  * The address of the WireGuard interface.
132
132
  *
133
133
  * The address may be any IPv4 or IPv6 address. CIDR notation is also supported.
134
134
  */
135
- address: Type.Optional(Type.String()),
135
+ address: z.string().optional(),
136
136
 
137
137
  /**
138
138
  * The convenience option to set `allowedIps` to `0.0.0.0/0, ::/0`.
139
139
  *
140
140
  * Will be merged with the `allowedIps` if provided.
141
141
  */
142
- exitNode: Type.Default(Type.Boolean(), false),
142
+ exitNode: z.boolean().default(false),
143
143
 
144
144
  /**
145
145
  * The list of IP ranges to exclude from the tunnel.
@@ -150,7 +150,7 @@ const sharedPeerArgs = {
150
150
  * - Instead, the node will setup extra direct routes to these IPs via default gateway.
151
151
  * - This allows to use `0.0.0.0/0, ::/0` in the `allowedIps` (and corresponding fwmark magic) and still have some IPs excluded from the tunnel.
152
152
  */
153
- excludedIps: Type.Default(Type.Array(Type.String()), []),
153
+ excludedIps: z.string().array().default([]),
154
154
 
155
155
  /**
156
156
  * The convenience option to exclude private IPs from the tunnel.
@@ -168,38 +168,38 @@ const sharedPeerArgs = {
168
168
  *
169
169
  * Will be merged with `excludedIps` if provided.
170
170
  */
171
- excludePrivateIps: Type.Default(Type.Boolean(), false),
171
+ excludePrivateIps: z.boolean().default(false),
172
172
 
173
173
  /**
174
174
  * The endpoints of the WireGuard peer.
175
175
  */
176
- endpoints: Type.Default(Type.Array(Type.String()), []),
176
+ endpoints: z.string().array().default([]),
177
177
 
178
178
  /**
179
179
  * The allowed endpoints of the WireGuard peer.
180
180
  *
181
181
  * The non `hostname` endpoints will be added to the `allowedIps` of the peer.
182
182
  */
183
- allowedEndpoints: Type.Default(Type.Array(Type.String()), []),
183
+ allowedEndpoints: z.string().array().default([]),
184
184
 
185
185
  /**
186
186
  * The DNS servers that should be used by the interface connected to the WireGuard peer.
187
187
  *
188
188
  * If multiple peers define DNS servers, the node will merge them into a single list (but this is discouraged).
189
189
  */
190
- dns: Type.Default(Type.Array(Type.String()), []),
190
+ dns: z.string().array().default([]),
191
191
 
192
192
  /**
193
193
  * The convenience option to include the DNS servers to the allowed IPs.
194
194
  *
195
195
  * By default, is `true`.
196
196
  */
197
- includeDns: Type.Default(Type.Boolean(), true),
197
+ includeDns: z.boolean().default(true),
198
198
 
199
199
  /**
200
200
  * The port to listen on.
201
201
  */
202
- listenPort: Type.Optional(Type.Number()),
202
+ listenPort: z.number().optional(),
203
203
  }
204
204
 
205
205
  const sharedPeerInputs = {
@@ -272,7 +272,18 @@ const sharedPeerOutputs = {
272
272
  },
273
273
  } as const
274
274
 
275
- export type SharedPeerArgs = Static<TObject<typeof sharedPeerArgs>>
275
+ export type SharedPeerArgs = {
276
+ peerName?: string
277
+ address?: string
278
+ exitNode: boolean
279
+ excludedIps: string[]
280
+ excludePrivateIps: boolean
281
+ endpoints: string[]
282
+ allowedEndpoints: string[]
283
+ dns: string[]
284
+ includeDns: boolean
285
+ listenPort?: number
286
+ }
276
287
 
277
288
  export const peer = defineUnit({
278
289
  type: "wireguard.peer",
@@ -283,14 +294,14 @@ export const peer = defineUnit({
283
294
  /**
284
295
  * The public key of the WireGuard peer.
285
296
  */
286
- publicKey: Type.String(),
297
+ publicKey: z.string(),
287
298
  },
288
299
 
289
300
  secrets: {
290
301
  /**
291
302
  * The pre-shared key which should be used for the peer.
292
303
  */
293
- presharedKey: Type.Optional(Type.String()),
304
+ presharedKey: z.string().optional(),
294
305
  },
295
306
 
296
307
  inputs: sharedPeerInputs,
@@ -298,8 +309,8 @@ export const peer = defineUnit({
298
309
 
299
310
  meta: {
300
311
  description: "The WireGuard peer with the public key.",
301
- primaryIcon: "simple-icons:wireguard",
302
- primaryIconColor: "#88171a",
312
+ icon: "simple-icons:wireguard",
313
+ iconColor: "#88171a",
303
314
  secondaryIcon: "mdi:badge-account-horizontal",
304
315
  category: "VPN",
305
316
  },
@@ -317,7 +328,7 @@ export const peerPatch = defineUnit({
317
328
  /**
318
329
  * The endpoints of the WireGuard peer.
319
330
  */
320
- endpoints: Type.Default(Type.Array(Type.String()), []),
331
+ endpoints: z.string().array().default([]),
321
332
 
322
333
  /**
323
334
  * The mode to use for patching the endpoints.
@@ -325,14 +336,14 @@ export const peerPatch = defineUnit({
325
336
  * - `prepend`: prepend the new endpoints to the existing ones (default);
326
337
  * - `replace`: replace the existing endpoints with the new ones.
327
338
  */
328
- endpointsPatchMode: Type.Default(arrayPatchModeSchema, "prepend"),
339
+ endpointsPatchMode: arrayPatchModeSchema.default("prepend"),
329
340
 
330
341
  /**
331
342
  * The allowed endpoints of the WireGuard peer.
332
343
  *
333
344
  * The non `hostname` endpoints will be added to the `allowedIps` of the peer.
334
345
  */
335
- allowedEndpoints: Type.Default(Type.Array(Type.String()), []),
346
+ allowedEndpoints: z.string().array().default([]),
336
347
 
337
348
  /**
338
349
  * The mode to use for patching the allowed endpoints.
@@ -340,7 +351,7 @@ export const peerPatch = defineUnit({
340
351
  * - `prepend`: prepend the new endpoints to the existing ones (default);
341
352
  * - `replace`: replace the existing endpoints with the new ones.
342
353
  */
343
- allowedEndpointsPatchMode: Type.Default(arrayPatchModeSchema, "prepend"),
354
+ allowedEndpointsPatchMode: arrayPatchModeSchema.default("prepend"),
344
355
 
345
356
  ...omit(sharedPeerArgs, ["endpoints", "allowedEndpoints"]),
346
357
  },
@@ -361,10 +372,10 @@ export const peerPatch = defineUnit({
361
372
  },
362
373
 
363
374
  meta: {
364
- displayName: "WireGuard Peer Patch",
375
+ title: "WireGuard Peer Patch",
365
376
  description: "Patches some properties of the WireGuard peer.",
366
- primaryIcon: "simple-icons:wireguard",
367
- primaryIconColor: "#88171a",
377
+ icon: "simple-icons:wireguard",
378
+ iconColor: "#88171a",
368
379
  secondaryIcon: "mdi:badge-account-horizontal",
369
380
  category: "VPN",
370
381
  },
@@ -386,7 +397,7 @@ export const identity = defineUnit({
386
397
  *
387
398
  * Used by the implementation of the identity and to calculate the endpoint of the peer.
388
399
  */
389
- listenPort: Type.Optional(Type.Number()),
400
+ listenPort: z.number().optional(),
390
401
 
391
402
  /**
392
403
  * The endpoint of the WireGuard peer.
@@ -395,7 +406,7 @@ export const identity = defineUnit({
395
406
  *
396
407
  * Will take priority over all calculated endpoints and `l4Endpoint` input.
397
408
  */
398
- endpoints: Type.Default(Type.Array(Type.String()), []),
409
+ endpoints: z.string().array().default([]),
399
410
  },
400
411
 
401
412
  secrets: {
@@ -404,14 +415,14 @@ export const identity = defineUnit({
404
415
  *
405
416
  * If not provided, the key will be generated automatically.
406
417
  */
407
- privateKey: Type.Optional(Type.String()),
418
+ privateKey: z.string().optional(),
408
419
 
409
420
  /**
410
421
  * The part of the pre-shared of the WireGuard identity.
411
422
  *
412
423
  * Will be generated automatically if not provided.
413
424
  */
414
- presharedKeyPart: Type.Optional(Type.String()),
425
+ presharedKeyPart: z.string().optional(),
415
426
  },
416
427
 
417
428
  inputs: sharedPeerInputs,
@@ -423,8 +434,8 @@ export const identity = defineUnit({
423
434
 
424
435
  meta: {
425
436
  description: "The WireGuard identity with the public key.",
426
- primaryIcon: "simple-icons:wireguard",
427
- primaryIconColor: "#88171a",
437
+ icon: "simple-icons:wireguard",
438
+ iconColor: "#88171a",
428
439
  secondaryIcon: "mdi:account",
429
440
  category: "VPN",
430
441
  },
@@ -444,12 +455,12 @@ export const node = defineUnit({
444
455
  *
445
456
  * By default, the name is `wg-${identity.name}`.
446
457
  */
447
- appName: Type.Optional(Type.String()),
458
+ appName: z.string().optional(),
448
459
 
449
460
  /**
450
461
  * Whether to expose the WireGuard node to the outside world.
451
462
  */
452
- external: Type.Default(Type.Boolean(), false),
463
+ external: z.boolean().default(false),
453
464
 
454
465
  /**
455
466
  * The policy to use for exposing the WireGuard node.
@@ -460,14 +471,14 @@ export const node = defineUnit({
460
471
  *
461
472
  * * By default, the `when-has-endpoint` policy is used.
462
473
  */
463
- exposePolicy: Type.Default(nodeExposePolicySchema, "when-has-endpoint"),
474
+ exposePolicy: nodeExposePolicySchema.default("when-has-endpoint"),
464
475
 
465
476
  /**
466
477
  * The extra specification of the container which runs the WireGuard node.
467
478
  *
468
479
  * Will override any overlapping fields.
469
480
  */
470
- containerSpec: Type.Optional(Type.Record(Type.String(), Type.Any())),
481
+ containerSpec: z.record(z.string(), z.unknown()).optional(),
471
482
 
472
483
  /**
473
484
  * List of CIDR blocks that should be blocked from forwarding through this WireGuard node.
@@ -477,7 +488,7 @@ export const node = defineUnit({
477
488
  *
478
489
  * Useful for peer isolation where you want to prevent cross-peer communication.
479
490
  */
480
- forwardRestrictedIps: Type.Default(Type.Array(Type.String()), []),
491
+ forwardRestrictedIps: z.string().array().default([]),
481
492
  },
482
493
 
483
494
  inputs: {
@@ -521,8 +532,8 @@ export const node = defineUnit({
521
532
 
522
533
  meta: {
523
534
  description: "The WireGuard node running on the Kubernetes.",
524
- primaryIcon: "simple-icons:wireguard",
525
- primaryIconColor: "#88171a",
535
+ icon: "simple-icons:wireguard",
536
+ iconColor: "#88171a",
526
537
  secondaryIcon: "mdi:server",
527
538
  category: "VPN",
528
539
  },
@@ -542,7 +553,7 @@ export const config = defineUnit({
542
553
  *
543
554
  * If not provided, the config will not respect `excludedIps`.
544
555
  */
545
- defaultInterface: Type.Optional(Type.String()),
556
+ defaultInterface: z.string().optional(),
546
557
  },
547
558
 
548
559
  inputs: {
@@ -555,10 +566,10 @@ export const config = defineUnit({
555
566
  },
556
567
 
557
568
  meta: {
558
- displayName: "WireGuard Config",
569
+ title: "WireGuard Config",
559
570
  description: "Just the WireGuard configuration for the identity and peers.",
560
- primaryIcon: "simple-icons:wireguard",
561
- primaryIconColor: "#88171a",
571
+ icon: "simple-icons:wireguard",
572
+ iconColor: "#88171a",
562
573
  secondaryIcon: "mdi:settings",
563
574
  category: "VPN",
564
575
  },
@@ -586,10 +597,10 @@ export const configBundle = defineUnit({
586
597
  },
587
598
 
588
599
  meta: {
589
- displayName: "WireGuard Config Bundle",
600
+ title: "WireGuard Config Bundle",
590
601
  description: "The WireGuard configuration bundle for the identity and peers.",
591
- primaryIcon: "simple-icons:wireguard",
592
- primaryIconColor: "#88171a",
602
+ icon: "simple-icons:wireguard",
603
+ iconColor: "#88171a",
593
604
  secondaryIcon: "mdi:folder-settings-variant",
594
605
  category: "VPN",
595
606
  },