@highstate/library 0.15.0 → 0.17.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/highstate.library.msgpack +0 -0
- package/dist/index.js +1721 -953
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/abbreviations.ts +1 -0
- package/src/common/access-point.ts +2 -2
- package/src/common/files.ts +10 -0
- package/src/common/server.ts +15 -57
- package/src/databases/etcd.ts +97 -0
- package/src/databases/index.ts +1 -0
- package/src/databases/mariadb.ts +48 -2
- package/src/databases/mongodb.ts +48 -2
- package/src/databases/postgresql.ts +51 -2
- package/src/databases/redis.ts +48 -2
- package/src/databases/s3.ts +65 -6
- package/src/databases/shared.ts +12 -6
- package/src/dns.ts +59 -49
- package/src/k8s/apps/etcd.ts +46 -0
- package/src/k8s/apps/index.ts +2 -0
- package/src/k8s/apps/mariadb.ts +0 -5
- package/src/k8s/apps/minio.ts +0 -5
- package/src/k8s/apps/mongodb.ts +0 -5
- package/src/k8s/apps/postgresql.ts +0 -5
- package/src/k8s/apps/shared.ts +10 -1
- package/src/k8s/apps/traefik.ts +16 -1
- package/src/k8s/apps/valkey.ts +0 -5
- package/src/k8s/apps/wg-feed-server.ts +34 -0
- package/src/k8s/reduced-access.ts +23 -53
- package/src/k8s/resources.ts +78 -35
- package/src/k8s/service.ts +21 -10
- package/src/k8s/shared.ts +60 -90
- package/src/k8s/workload.ts +87 -26
- package/src/network/address-space.ts +94 -0
- package/src/network/address.ts +33 -0
- package/src/network/dynamic-endpoint.ts +39 -0
- package/src/network/endpoint-schema.ts +116 -0
- package/src/network/endpoint.ts +347 -0
- package/src/network/index.ts +6 -0
- package/src/network/subnet.ts +31 -0
- package/src/ssh.ts +66 -10
- package/src/third-party/cloudflare.ts +1 -0
- package/src/utils.ts +41 -11
- package/src/wireguard.ts +340 -150
- package/src/network.ts +0 -391
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@highstate/library",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"highstate": {
|
|
6
6
|
"type": "library"
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"remeda": "^2.21.0",
|
|
28
|
-
"@highstate/contract": "0.
|
|
28
|
+
"@highstate/contract": "0.18.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@biomejs/biome": "2.2.0",
|
|
32
32
|
"@typescript/native-preview": "^7.0.0-dev.20250920.1",
|
|
33
33
|
"type-fest": "^4.41.0",
|
|
34
|
-
"@highstate/cli": "0.
|
|
34
|
+
"@highstate/cli": "0.18.0"
|
|
35
35
|
},
|
|
36
36
|
"repository": {
|
|
37
37
|
"url": "https://github.com/highstate-io/highstate"
|
package/src/abbreviations.ts
CHANGED
|
@@ -30,9 +30,9 @@ export const tlsIssuerEntity = defineEntity({
|
|
|
30
30
|
|
|
31
31
|
schema: z.object({
|
|
32
32
|
/**
|
|
33
|
-
* The
|
|
33
|
+
* The zones for which the TLS issuer will manage certificates.
|
|
34
34
|
*/
|
|
35
|
-
|
|
35
|
+
zones: z.string().array(),
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* The reference to the implementation of the TLS issuer.
|
package/src/common/files.ts
CHANGED
|
@@ -96,8 +96,18 @@ export const remoteFile = defineUnit({
|
|
|
96
96
|
args: {
|
|
97
97
|
/**
|
|
98
98
|
* The URL of the remote file.
|
|
99
|
+
*
|
|
100
|
+
* Either this or the 'endpoint' input must be provided.
|
|
99
101
|
*/
|
|
100
102
|
url: z.string().optional(),
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The name of the file.
|
|
106
|
+
*
|
|
107
|
+
* If not provided, the name will be derived from the URL or endpoint path.
|
|
108
|
+
* If not possible, the name of the unit will be used.
|
|
109
|
+
*/
|
|
110
|
+
fileName: z.string().optional(),
|
|
101
111
|
},
|
|
102
112
|
|
|
103
113
|
inputs: {
|
package/src/common/server.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { $outputs, $secrets, defineEntity, defineUnit, z } from "@highstate/contract"
|
|
2
|
-
import * as dns from "../dns"
|
|
3
2
|
import { l3EndpointEntity } from "../network"
|
|
4
3
|
import * as ssh from "../ssh"
|
|
5
|
-
import { arrayPatchModeSchema } from "../utils"
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
6
|
* The server entity represents a server with its hostname, endpoints, and optional SSH configuration.
|
|
@@ -14,9 +12,15 @@ import { arrayPatchModeSchema } from "../utils"
|
|
|
14
12
|
export const serverEntity = defineEntity({
|
|
15
13
|
type: "common.server.v1",
|
|
16
14
|
|
|
15
|
+
includes: {
|
|
16
|
+
endpoints: {
|
|
17
|
+
entity: l3EndpointEntity,
|
|
18
|
+
multiple: true,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
|
|
17
22
|
schema: z.object({
|
|
18
23
|
hostname: z.string(),
|
|
19
|
-
endpoints: l3EndpointEntity.schema.array(),
|
|
20
24
|
ssh: ssh.connectionSchema.optional(),
|
|
21
25
|
}),
|
|
22
26
|
|
|
@@ -33,14 +37,6 @@ export const serverOutputs = $outputs({
|
|
|
33
37
|
* The server entity representing the server.
|
|
34
38
|
*/
|
|
35
39
|
server: serverEntity,
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* The L3 endpoints of the server.
|
|
39
|
-
*/
|
|
40
|
-
endpoints: {
|
|
41
|
-
entity: l3EndpointEntity,
|
|
42
|
-
multiple: true,
|
|
43
|
-
},
|
|
44
40
|
})
|
|
45
41
|
|
|
46
42
|
export const vmSshArgs = ssh.argsSchema.omit({ user: true }).prefault({})
|
|
@@ -86,9 +82,10 @@ export const existingServer = defineUnit({
|
|
|
86
82
|
},
|
|
87
83
|
|
|
88
84
|
inputs: {
|
|
89
|
-
|
|
85
|
+
endpoints: {
|
|
90
86
|
entity: l3EndpointEntity,
|
|
91
87
|
required: false,
|
|
88
|
+
multiple: true,
|
|
92
89
|
},
|
|
93
90
|
|
|
94
91
|
...ssh.inputs,
|
|
@@ -117,21 +114,18 @@ export const serverPatch = defineUnit({
|
|
|
117
114
|
|
|
118
115
|
args: {
|
|
119
116
|
/**
|
|
120
|
-
* The
|
|
121
|
-
*
|
|
122
|
-
* The entry may represent real node endpoint or virtual endpoint (like a load balancer).
|
|
117
|
+
* The new hostname of the server.
|
|
123
118
|
*
|
|
124
|
-
*
|
|
119
|
+
* If not specified, the existing hostname will be kept.
|
|
125
120
|
*/
|
|
126
|
-
|
|
121
|
+
hostname: z.string().optional(),
|
|
127
122
|
|
|
128
123
|
/**
|
|
129
|
-
* The
|
|
124
|
+
* The endpoints to set on the server.
|
|
130
125
|
*
|
|
131
|
-
*
|
|
132
|
-
* - `replace`: replace the existing endpoints with the new ones.
|
|
126
|
+
* If not specified, the existing endpoints will be kept.
|
|
133
127
|
*/
|
|
134
|
-
|
|
128
|
+
endpoints: z.string().array().default([]),
|
|
135
129
|
},
|
|
136
130
|
|
|
137
131
|
inputs: {
|
|
@@ -160,42 +154,6 @@ export const serverPatch = defineUnit({
|
|
|
160
154
|
},
|
|
161
155
|
})
|
|
162
156
|
|
|
163
|
-
/**
|
|
164
|
-
* Creates a DNS record for the server and updates the endpoints.
|
|
165
|
-
*
|
|
166
|
-
* The DNS record will be created with the provided FQDN and the endpoints will be updated with the DNS record.
|
|
167
|
-
*/
|
|
168
|
-
export const serverDns = defineUnit({
|
|
169
|
-
type: "common.server-dns.v1",
|
|
170
|
-
|
|
171
|
-
args: dns.createArgs(),
|
|
172
|
-
|
|
173
|
-
inputs: {
|
|
174
|
-
server: serverEntity,
|
|
175
|
-
...dns.inputs,
|
|
176
|
-
},
|
|
177
|
-
|
|
178
|
-
outputs: {
|
|
179
|
-
server: serverEntity,
|
|
180
|
-
endpoints: {
|
|
181
|
-
entity: l3EndpointEntity,
|
|
182
|
-
multiple: true,
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
|
|
186
|
-
meta: {
|
|
187
|
-
title: "Server DNS",
|
|
188
|
-
icon: "mdi:server",
|
|
189
|
-
secondaryIcon: "mdi:dns",
|
|
190
|
-
category: "Infrastructure",
|
|
191
|
-
},
|
|
192
|
-
|
|
193
|
-
source: {
|
|
194
|
-
package: "@highstate/common",
|
|
195
|
-
path: "units/server-dns",
|
|
196
|
-
},
|
|
197
|
-
})
|
|
198
|
-
|
|
199
157
|
/**
|
|
200
158
|
* Runs a shell script on the server.
|
|
201
159
|
*/
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { defineEntity, defineUnit, z } from "@highstate/contract"
|
|
2
|
+
import { l4EndpointEntity } from "../network"
|
|
3
|
+
import { toPatchArgs } from "../utils"
|
|
4
|
+
|
|
5
|
+
const etcdArgs = {
|
|
6
|
+
endpoints: {
|
|
7
|
+
schema: z.string().array().default([]),
|
|
8
|
+
},
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Represents the etcd database instance.
|
|
13
|
+
*/
|
|
14
|
+
export const etcdEntity = defineEntity({
|
|
15
|
+
type: "databases.etcd.v1",
|
|
16
|
+
|
|
17
|
+
includes: {
|
|
18
|
+
endpoints: {
|
|
19
|
+
entity: l4EndpointEntity,
|
|
20
|
+
multiple: true,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
schema: z.unknown(),
|
|
25
|
+
|
|
26
|
+
meta: {
|
|
27
|
+
color: "#0064bf",
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The existing etcd database instance.
|
|
33
|
+
*/
|
|
34
|
+
export const existingEtcd = defineUnit({
|
|
35
|
+
type: "databases.etcd.existing.v1",
|
|
36
|
+
|
|
37
|
+
args: etcdArgs,
|
|
38
|
+
|
|
39
|
+
inputs: {
|
|
40
|
+
endpoints: {
|
|
41
|
+
entity: l4EndpointEntity,
|
|
42
|
+
multiple: true,
|
|
43
|
+
required: false,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
outputs: {
|
|
48
|
+
etcd: etcdEntity,
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
source: {
|
|
52
|
+
package: "@highstate/common",
|
|
53
|
+
path: "units/databases/existing-etcd",
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
meta: {
|
|
57
|
+
title: "Existing etcd Database",
|
|
58
|
+
icon: "simple-icons:etcd",
|
|
59
|
+
secondaryIcon: "mdi:database",
|
|
60
|
+
category: "Databases",
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Patches some properties of the etcd database and outputs the updated database.
|
|
66
|
+
*/
|
|
67
|
+
export const etcdPatch = defineUnit({
|
|
68
|
+
type: "databases.etcd-patch.v1",
|
|
69
|
+
|
|
70
|
+
args: toPatchArgs(etcdArgs),
|
|
71
|
+
|
|
72
|
+
inputs: {
|
|
73
|
+
etcd: etcdEntity,
|
|
74
|
+
|
|
75
|
+
endpoints: {
|
|
76
|
+
entity: l4EndpointEntity,
|
|
77
|
+
multiple: true,
|
|
78
|
+
required: false,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
outputs: {
|
|
83
|
+
etcd: etcdEntity,
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
source: {
|
|
87
|
+
package: "@highstate/common",
|
|
88
|
+
path: "units/databases/etcd-patch",
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
meta: {
|
|
92
|
+
title: "etcd Patch",
|
|
93
|
+
icon: "simple-icons:etcd",
|
|
94
|
+
secondaryIcon: "fluent:patch-20-filled",
|
|
95
|
+
category: "Databases",
|
|
96
|
+
},
|
|
97
|
+
})
|
package/src/databases/index.ts
CHANGED
package/src/databases/mariadb.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { defineEntity, defineUnit,
|
|
2
|
-
import {
|
|
1
|
+
import { defineEntity, defineUnit, z } from "@highstate/contract"
|
|
2
|
+
import { l4EndpointEntity } from "../network"
|
|
3
|
+
import { toPatchArgs } from "../utils"
|
|
4
|
+
import { optionalSharedArgs, sharedArgs, sharedInputs, sharedSchema, sharedSecrets } from "./shared"
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Represents the MariaDB database or virtual database behind it.
|
|
@@ -7,6 +9,13 @@ import { sharedArgs, sharedInputs, sharedSchema, sharedSecrets } from "./shared"
|
|
|
7
9
|
export const mariadbEntity = defineEntity({
|
|
8
10
|
type: "databases.mariadb.v1",
|
|
9
11
|
|
|
12
|
+
includes: {
|
|
13
|
+
endpoints: {
|
|
14
|
+
entity: l4EndpointEntity,
|
|
15
|
+
multiple: true,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
|
|
10
19
|
schema: sharedSchema,
|
|
11
20
|
|
|
12
21
|
meta: {
|
|
@@ -41,4 +50,41 @@ export const existingMariadb = defineUnit({
|
|
|
41
50
|
},
|
|
42
51
|
})
|
|
43
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Patches some properties of the MariaDB database and outputs the updated database.
|
|
55
|
+
*/
|
|
56
|
+
export const mariadbPatch = defineUnit({
|
|
57
|
+
type: "databases.mariadb-patch.v1",
|
|
58
|
+
|
|
59
|
+
args: {
|
|
60
|
+
...toPatchArgs(optionalSharedArgs),
|
|
61
|
+
|
|
62
|
+
endpoints: {
|
|
63
|
+
...sharedArgs.endpoints,
|
|
64
|
+
schema: z.string().array().default([]),
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
inputs: {
|
|
69
|
+
mariadb: mariadbEntity,
|
|
70
|
+
...sharedInputs,
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
outputs: {
|
|
74
|
+
mariadb: mariadbEntity,
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
source: {
|
|
78
|
+
package: "@highstate/common",
|
|
79
|
+
path: "units/databases/mariadb-patch",
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
meta: {
|
|
83
|
+
title: "MariaDB Patch",
|
|
84
|
+
icon: "simple-icons:mariadb",
|
|
85
|
+
secondaryIcon: "fluent:patch-20-filled",
|
|
86
|
+
category: "Databases",
|
|
87
|
+
},
|
|
88
|
+
})
|
|
89
|
+
|
|
44
90
|
export type MariaDB = z.infer<typeof mariadbEntity.schema>
|
package/src/databases/mongodb.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { defineEntity, defineUnit,
|
|
2
|
-
import {
|
|
1
|
+
import { defineEntity, defineUnit, z } from "@highstate/contract"
|
|
2
|
+
import { l4EndpointEntity } from "../network"
|
|
3
|
+
import { toPatchArgs } from "../utils"
|
|
4
|
+
import { optionalSharedArgs, sharedArgs, sharedInputs, sharedSchema, sharedSecrets } from "./shared"
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Represents the MongoDB database or virtual database behind it.
|
|
@@ -7,6 +9,13 @@ import { sharedArgs, sharedInputs, sharedSchema, sharedSecrets } from "./shared"
|
|
|
7
9
|
export const mongodbEntity = defineEntity({
|
|
8
10
|
type: "databases.mongodb.v1",
|
|
9
11
|
|
|
12
|
+
includes: {
|
|
13
|
+
endpoints: {
|
|
14
|
+
entity: l4EndpointEntity,
|
|
15
|
+
multiple: true,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
|
|
10
19
|
schema: sharedSchema,
|
|
11
20
|
|
|
12
21
|
meta: {
|
|
@@ -41,4 +50,41 @@ export const existingMongodb = defineUnit({
|
|
|
41
50
|
},
|
|
42
51
|
})
|
|
43
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Patches some properties of the MongoDB database and outputs the updated database.
|
|
55
|
+
*/
|
|
56
|
+
export const mongodbPatch = defineUnit({
|
|
57
|
+
type: "databases.mongodb-patch.v1",
|
|
58
|
+
|
|
59
|
+
args: {
|
|
60
|
+
...toPatchArgs(optionalSharedArgs),
|
|
61
|
+
|
|
62
|
+
endpoints: {
|
|
63
|
+
...sharedArgs.endpoints,
|
|
64
|
+
schema: z.string().array().default([]),
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
inputs: {
|
|
69
|
+
mongodb: mongodbEntity,
|
|
70
|
+
...sharedInputs,
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
outputs: {
|
|
74
|
+
mongodb: mongodbEntity,
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
source: {
|
|
78
|
+
package: "@highstate/common",
|
|
79
|
+
path: "units/databases/mongodb-patch",
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
meta: {
|
|
83
|
+
title: "MongoDB Patch",
|
|
84
|
+
icon: "simple-icons:mongodb",
|
|
85
|
+
secondaryIcon: "fluent:patch-20-filled",
|
|
86
|
+
category: "Databases",
|
|
87
|
+
},
|
|
88
|
+
})
|
|
89
|
+
|
|
44
90
|
export type MongoDB = z.infer<typeof mongodbEntity.schema>
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { defineEntity, defineUnit,
|
|
2
|
-
import {
|
|
1
|
+
import { defineEntity, defineUnit, z } from "@highstate/contract"
|
|
2
|
+
import { l4EndpointEntity } from "../network"
|
|
3
|
+
import { toPatchArgs } from "../utils"
|
|
4
|
+
import { optionalSharedArgs, sharedArgs, sharedInputs, sharedSchema, sharedSecrets } from "./shared"
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Represents the PostgreSQL database or virtual database behind it.
|
|
@@ -7,6 +9,13 @@ import { sharedArgs, sharedInputs, sharedSchema, sharedSecrets } from "./shared"
|
|
|
7
9
|
export const postgresqlEntity = defineEntity({
|
|
8
10
|
type: "databases.postgresql.v1",
|
|
9
11
|
|
|
12
|
+
includes: {
|
|
13
|
+
endpoints: {
|
|
14
|
+
entity: l4EndpointEntity,
|
|
15
|
+
multiple: true,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
|
|
10
19
|
schema: sharedSchema,
|
|
11
20
|
|
|
12
21
|
meta: {
|
|
@@ -41,4 +50,44 @@ export const existingPostgresql = defineUnit({
|
|
|
41
50
|
},
|
|
42
51
|
})
|
|
43
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Patches some properties of the PostgreSQL database and outputs the updated database.
|
|
55
|
+
*/
|
|
56
|
+
export const postgresqlPatch = defineUnit({
|
|
57
|
+
type: "databases.postgresql-patch.v1",
|
|
58
|
+
|
|
59
|
+
args: {
|
|
60
|
+
...toPatchArgs(optionalSharedArgs),
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The endpoints to connect to the database in form of `host:port`.
|
|
64
|
+
*
|
|
65
|
+
* If at least one endpoint is provided (either via args or inputs), the existing endpoints
|
|
66
|
+
* will be replaced completely.
|
|
67
|
+
*/
|
|
68
|
+
endpoints: z.string().array().default([]),
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
inputs: {
|
|
72
|
+
postgresql: postgresqlEntity,
|
|
73
|
+
...sharedInputs,
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
outputs: {
|
|
77
|
+
postgresql: postgresqlEntity,
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
source: {
|
|
81
|
+
package: "@highstate/common",
|
|
82
|
+
path: "units/databases/postgresql-patch",
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
meta: {
|
|
86
|
+
title: "PostgreSQL Patch",
|
|
87
|
+
icon: "simple-icons:postgresql",
|
|
88
|
+
secondaryIcon: "fluent:patch-20-filled",
|
|
89
|
+
category: "Databases",
|
|
90
|
+
},
|
|
91
|
+
})
|
|
92
|
+
|
|
44
93
|
export type PostgreSQL = z.infer<typeof postgresqlEntity.schema>
|
package/src/databases/redis.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { defineEntity, defineUnit, z } from "@highstate/contract"
|
|
2
|
-
import {
|
|
2
|
+
import { l4EndpointEntity } from "../network"
|
|
3
|
+
import { toPatchArgs } from "../utils"
|
|
4
|
+
import { optionalSharedArgs, sharedArgs, sharedInputs } from "./shared"
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Represents the Redis database or virtual database behind it.
|
|
@@ -7,7 +9,14 @@ import { sharedArgs, sharedInputs, sharedSchema } from "./shared"
|
|
|
7
9
|
export const redisEntity = defineEntity({
|
|
8
10
|
type: "databases.redis.v1",
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
includes: {
|
|
13
|
+
endpoints: {
|
|
14
|
+
entity: l4EndpointEntity,
|
|
15
|
+
multiple: true,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
schema: z.object({
|
|
11
20
|
/**
|
|
12
21
|
* The number of the database to use.
|
|
13
22
|
*/
|
|
@@ -45,4 +54,41 @@ export const existingRedis = defineUnit({
|
|
|
45
54
|
},
|
|
46
55
|
})
|
|
47
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Patches some properties of the Redis database and outputs the updated database.
|
|
59
|
+
*/
|
|
60
|
+
export const redisPatch = defineUnit({
|
|
61
|
+
type: "databases.redis-patch.v1",
|
|
62
|
+
|
|
63
|
+
args: {
|
|
64
|
+
...toPatchArgs(optionalSharedArgs),
|
|
65
|
+
|
|
66
|
+
endpoints: {
|
|
67
|
+
...sharedArgs.endpoints,
|
|
68
|
+
schema: z.string().array().default([]),
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
inputs: {
|
|
73
|
+
redis: redisEntity,
|
|
74
|
+
...sharedInputs,
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
outputs: {
|
|
78
|
+
redis: redisEntity,
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
source: {
|
|
82
|
+
package: "@highstate/common",
|
|
83
|
+
path: "units/databases/redis-patch",
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
meta: {
|
|
87
|
+
title: "Redis Patch",
|
|
88
|
+
icon: "simple-icons:redis",
|
|
89
|
+
secondaryIcon: "fluent:patch-20-filled",
|
|
90
|
+
category: "Databases",
|
|
91
|
+
},
|
|
92
|
+
})
|
|
93
|
+
|
|
48
94
|
export type Redis = z.infer<typeof redisEntity.schema>
|
package/src/databases/s3.ts
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Simplify } from "type-fest"
|
|
2
|
+
import {
|
|
3
|
+
$args,
|
|
4
|
+
$inputs,
|
|
5
|
+
$secrets,
|
|
6
|
+
defineEntity,
|
|
7
|
+
defineUnit,
|
|
8
|
+
type FullComponentArgumentOptions,
|
|
9
|
+
z,
|
|
10
|
+
} from "@highstate/contract"
|
|
11
|
+
import { mapValues } from "remeda"
|
|
2
12
|
import { l4EndpointEntity } from "../network"
|
|
13
|
+
import { toPatchArgs } from "../utils"
|
|
3
14
|
|
|
4
15
|
export const s3BucketPolicySchema = z.enum(["none", "download", "upload", "public"])
|
|
5
16
|
|
|
@@ -37,6 +48,15 @@ const s3Args = $args({
|
|
|
37
48
|
buckets: s3BucketSchema.array().default([]),
|
|
38
49
|
})
|
|
39
50
|
|
|
51
|
+
type ToOptionalArgs<T extends Record<string, FullComponentArgumentOptions>> = Simplify<{
|
|
52
|
+
[K in keyof T]: Simplify<Omit<T[K], "schema"> & { schema: z.ZodOptional<T[K]["schema"]> }>
|
|
53
|
+
}>
|
|
54
|
+
|
|
55
|
+
const optionalS3Args = mapValues(s3Args, arg => ({
|
|
56
|
+
...arg,
|
|
57
|
+
schema: arg.schema.optional(),
|
|
58
|
+
})) as ToOptionalArgs<typeof s3Args>
|
|
59
|
+
|
|
40
60
|
const s3Secrets = $secrets({
|
|
41
61
|
/**
|
|
42
62
|
* The secret key used to authenticate against the S3-compatible API.
|
|
@@ -61,12 +81,14 @@ const s3Inputs = $inputs({
|
|
|
61
81
|
export const s3Entity = defineEntity({
|
|
62
82
|
type: "databases.s3.v1",
|
|
63
83
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
84
|
+
includes: {
|
|
85
|
+
endpoints: {
|
|
86
|
+
entity: l4EndpointEntity,
|
|
87
|
+
multiple: true,
|
|
88
|
+
},
|
|
89
|
+
},
|
|
69
90
|
|
|
91
|
+
schema: z.object({
|
|
70
92
|
/**
|
|
71
93
|
* The region associated with the object storage instance.
|
|
72
94
|
*/
|
|
@@ -120,4 +142,41 @@ export const existingS3 = defineUnit({
|
|
|
120
142
|
},
|
|
121
143
|
})
|
|
122
144
|
|
|
145
|
+
/**
|
|
146
|
+
* Patches some properties of the S3-compatible object storage and outputs the updated storage.
|
|
147
|
+
*/
|
|
148
|
+
export const s3Patch = defineUnit({
|
|
149
|
+
type: "databases.s3-patch.v1",
|
|
150
|
+
|
|
151
|
+
args: {
|
|
152
|
+
...toPatchArgs(optionalS3Args),
|
|
153
|
+
|
|
154
|
+
endpoints: {
|
|
155
|
+
...s3Args.endpoints,
|
|
156
|
+
schema: z.string().array().default([]),
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
|
|
160
|
+
inputs: {
|
|
161
|
+
s3: s3Entity,
|
|
162
|
+
...s3Inputs,
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
outputs: {
|
|
166
|
+
s3: s3Entity,
|
|
167
|
+
},
|
|
168
|
+
|
|
169
|
+
source: {
|
|
170
|
+
package: "@highstate/common",
|
|
171
|
+
path: "units/databases/s3-patch",
|
|
172
|
+
},
|
|
173
|
+
|
|
174
|
+
meta: {
|
|
175
|
+
title: "S3 Patch",
|
|
176
|
+
icon: "simple-icons:amazons3",
|
|
177
|
+
secondaryIcon: "fluent:patch-20-filled",
|
|
178
|
+
category: "Databases",
|
|
179
|
+
},
|
|
180
|
+
})
|
|
181
|
+
|
|
123
182
|
export type S3 = z.infer<typeof s3Entity.schema>
|
package/src/databases/shared.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Simplify } from "type-fest"
|
|
2
|
+
import { $args, $inputs, $secrets, type FullComponentArgumentOptions, z } from "@highstate/contract"
|
|
3
|
+
import { mapValues } from "remeda"
|
|
2
4
|
import { l4EndpointEntity } from "../network"
|
|
3
5
|
|
|
4
6
|
export const sharedSchema = z.object({
|
|
5
|
-
/**
|
|
6
|
-
* The endpoints to connect to the database.
|
|
7
|
-
*/
|
|
8
|
-
endpoints: l4EndpointEntity.schema.array(),
|
|
9
|
-
|
|
10
7
|
/**
|
|
11
8
|
* The username to connect to the database with.
|
|
12
9
|
*/
|
|
@@ -42,6 +39,15 @@ export const sharedArgs = $args({
|
|
|
42
39
|
database: z.string().optional(),
|
|
43
40
|
})
|
|
44
41
|
|
|
42
|
+
type ToOptionalArgs<T extends Record<string, FullComponentArgumentOptions>> = Simplify<{
|
|
43
|
+
[K in keyof T]: Simplify<Omit<T[K], "schema"> & { schema: z.ZodOptional<T[K]["schema"]> }>
|
|
44
|
+
}>
|
|
45
|
+
|
|
46
|
+
export const optionalSharedArgs = mapValues(sharedArgs, arg => ({
|
|
47
|
+
...arg,
|
|
48
|
+
schema: arg.schema.optional(),
|
|
49
|
+
})) as ToOptionalArgs<typeof sharedArgs>
|
|
50
|
+
|
|
45
51
|
export const sharedSecrets = $secrets({
|
|
46
52
|
/**
|
|
47
53
|
* The password to connect to the database with.
|