@highstate/library 0.19.1 → 0.21.1

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 (66) hide show
  1. package/dist/highstate.library.msgpack +0 -0
  2. package/dist/index.js +2836 -3440
  3. package/package.json +12 -12
  4. package/src/abbreviations.ts +3 -0
  5. package/src/common/access-point.ts +19 -4
  6. package/src/common/files.ts +24 -17
  7. package/src/common/server.ts +19 -6
  8. package/src/databases/etcd.ts +141 -39
  9. package/src/databases/index.ts +8 -7
  10. package/src/databases/influxdb3.ts +103 -0
  11. package/src/databases/minio.ts +157 -0
  12. package/src/databases/mongodb.ts +122 -41
  13. package/src/databases/mysql.ts +172 -0
  14. package/src/databases/postgresql.ts +133 -40
  15. package/src/databases/redis.ts +118 -44
  16. package/src/databases/s3.ts +48 -127
  17. package/src/dns.ts +11 -7
  18. package/src/index.ts +3 -1
  19. package/src/k3s.ts +7 -0
  20. package/src/k8s/apps/etcd.ts +3 -3
  21. package/src/k8s/apps/gitea.ts +1 -1
  22. package/src/k8s/apps/grafana.ts +48 -0
  23. package/src/k8s/apps/index.ts +4 -2
  24. package/src/k8s/apps/mariadb.ts +7 -38
  25. package/src/k8s/apps/matrix-stack.ts +62 -0
  26. package/src/k8s/apps/minio.ts +38 -45
  27. package/src/k8s/apps/mongodb.ts +6 -38
  28. package/src/k8s/apps/portal.ts +27 -0
  29. package/src/k8s/apps/postgresql.ts +7 -41
  30. package/src/k8s/apps/refluxdb.ts +49 -0
  31. package/src/k8s/apps/remnawave.ts +15 -2
  32. package/src/k8s/apps/shared.ts +16 -15
  33. package/src/k8s/apps/traefik.ts +5 -0
  34. package/src/k8s/apps/valkey.ts +5 -5
  35. package/src/k8s/apps/vaultwarden.ts +2 -6
  36. package/src/k8s/apps/workload.ts +14 -11
  37. package/src/k8s/cert-manager.ts +22 -0
  38. package/src/k8s/cilium.ts +17 -2
  39. package/src/k8s/resources.ts +41 -9
  40. package/src/k8s/service.ts +6 -2
  41. package/src/k8s/shared.ts +49 -18
  42. package/src/k8s/workload.ts +59 -43
  43. package/src/network/address-space.ts +30 -7
  44. package/src/network/address.ts +13 -2
  45. package/src/network/endpoint-container.ts +235 -0
  46. package/src/network/endpoint-schema.ts +8 -0
  47. package/src/network/endpoint.ts +20 -39
  48. package/src/network/index.ts +1 -1
  49. package/src/network/subnet.ts +4 -2
  50. package/src/proxmox.ts +24 -7
  51. package/src/restic.ts +8 -2
  52. package/src/ssh.ts +52 -30
  53. package/src/talos.ts +8 -2
  54. package/src/third-party/cloudflare.ts +4 -4
  55. package/src/third-party/timeweb.ts +17 -3
  56. package/src/third-party/yandex.ts +198 -88
  57. package/src/tls.ts +22 -0
  58. package/src/utils.ts +16 -1
  59. package/src/wireguard.ts +362 -120
  60. package/LICENSE +0 -21
  61. package/dist/index.js.map +0 -1
  62. package/src/databases/mariadb.ts +0 -91
  63. package/src/databases/shared.ts +0 -67
  64. package/src/k8s/apps/kubernetes-dashboard.ts +0 -28
  65. package/src/k8s/apps/maybe.ts +0 -39
  66. package/src/network/dynamic-endpoint.ts +0 -43
@@ -0,0 +1,157 @@
1
+ import {
2
+ defineEntity,
3
+ defineUnit,
4
+ type EntityInput,
5
+ type EntityValue,
6
+ secretSchema,
7
+ z,
8
+ } from "@highstate/contract"
9
+ import { l7EndpointContainer, l7EndpointEntity } from "../network"
10
+ import { bucketEntity } from "./s3"
11
+
12
+ export const credentialsSchema = z.object({
13
+ /**
14
+ * The username used to authenticate against the API.
15
+ */
16
+ username: z.string(),
17
+
18
+ /**
19
+ * The password used to authenticate against the API.
20
+ */
21
+ password: secretSchema(z.string()),
22
+ })
23
+
24
+ /**
25
+ * Represents a connection to a MinIO instance, including the endpoints and credentials.
26
+ */
27
+ export const connectionEntity = defineEntity({
28
+ type: "minio.connection.v1",
29
+
30
+ extends: { l7EndpointContainer },
31
+
32
+ schema: z.object({
33
+ /**
34
+ * The region of the MinIO instance.
35
+ */
36
+ region: z.string(),
37
+
38
+ /**
39
+ * The credentials for authenticating to the MinIO instance.
40
+ */
41
+ credentials: credentialsSchema,
42
+ }),
43
+
44
+ meta: {
45
+ color: "#C72E49",
46
+ },
47
+ })
48
+
49
+ /**
50
+ * The existing MinIO connection hosted on a server or a managed service.
51
+ */
52
+ export const connection = defineUnit({
53
+ type: "minio.connection.v1",
54
+
55
+ args: {
56
+ /**
57
+ * The username to authenticate with.
58
+ */
59
+ username: z.string(),
60
+
61
+ /**
62
+ * The region of the MinIO instance.
63
+ *
64
+ * If not provided, it will default to "us-east-1".
65
+ */
66
+ region: z.string().default("us-east-1"),
67
+
68
+ /**
69
+ * The endpoints to connect to the MinIO instance.
70
+ */
71
+ endpoints: z.string().array().default([]),
72
+ },
73
+
74
+ inputs: {
75
+ /**
76
+ * The endpoints to connect to the MinIO instance.
77
+ */
78
+ endpoints: {
79
+ entity: l7EndpointEntity,
80
+ multiple: true,
81
+ required: false,
82
+ },
83
+ },
84
+
85
+ secrets: {
86
+ /**
87
+ * The password to authenticate with.
88
+ */
89
+ password: z.string(),
90
+ },
91
+
92
+ outputs: {
93
+ connection: connectionEntity,
94
+ },
95
+
96
+ source: {
97
+ package: "@highstate/minio",
98
+ path: "connection",
99
+ },
100
+
101
+ meta: {
102
+ title: "MinIO Connection",
103
+ icon: "simple-icons:minio",
104
+ secondaryIcon: "mdi:database",
105
+ category: "Databases",
106
+ },
107
+ })
108
+
109
+ /**
110
+ * Creates a bucket on a MinIO instance.
111
+ */
112
+ export const bucket = defineUnit({
113
+ type: "minio.bucket.v1",
114
+
115
+ args: {
116
+ /**
117
+ * The name of the bucket to create.
118
+ *
119
+ * Defaults to the name of the unit if not provided.
120
+ */
121
+ bucketName: z.string().optional(),
122
+
123
+ /**
124
+ * The quota for the bucket as string with size suffix, e.g. "10GB". If not provided, the bucket will have no quota.
125
+ */
126
+ quota: z.string().optional(),
127
+ },
128
+
129
+ inputs: {
130
+ /**
131
+ * The connection to the MinIO instance where the bucket should be created.
132
+ */
133
+ connection: connectionEntity,
134
+ },
135
+
136
+ outputs: {
137
+ /**
138
+ * The created bucket.
139
+ */
140
+ bucket: bucketEntity,
141
+ },
142
+
143
+ source: {
144
+ package: "@highstate/minio",
145
+ path: "bucket",
146
+ },
147
+
148
+ meta: {
149
+ title: "MinIO Bucket",
150
+ icon: "simple-icons:minio",
151
+ secondaryIcon: "mdi:database",
152
+ category: "Databases",
153
+ },
154
+ })
155
+
156
+ export type Connection = EntityValue<typeof connectionEntity>
157
+ export type ConnectionInput = EntityInput<typeof connectionEntity>
@@ -1,22 +1,59 @@
1
- import { defineEntity, defineUnit, type EntityInput, z } from "@highstate/contract"
2
- import { l4EndpointEntity } from "../network"
3
- import { toPatchArgs } from "../utils"
4
- import { optionalSharedArgs, sharedArgs, sharedInputs, sharedSchema, sharedSecrets } from "./shared"
1
+ import {
2
+ defineEntity,
3
+ defineUnit,
4
+ type EntityInput,
5
+ type EntityValue,
6
+ secretSchema,
7
+ z,
8
+ } from "@highstate/contract"
9
+ import { l4EndpointContainer, l4EndpointEntity } from "../network"
10
+ import { certificateEntity } from "../tls"
11
+
12
+ export const credentialsSchema = z.discriminatedUnion("type", [
13
+ z.object({
14
+ type: z.literal("password"),
15
+
16
+ /**
17
+ * The username used to authenticate against the database.
18
+ */
19
+ username: z.string(),
20
+
21
+ /**
22
+ * The password used to authenticate against the database.
23
+ */
24
+ password: secretSchema(z.string()),
25
+ }),
26
+ ])
5
27
 
6
28
  /**
7
- * Represents the MongoDB database or virtual database behind it.
29
+ * Represents a connection to a MongoDB instance, including the endpoints and credentials.
8
30
  */
9
- export const mongodbEntity = defineEntity({
10
- type: "databases.mongodb.v1",
31
+ export const connectionEntity = defineEntity({
32
+ type: "mongodb.connection.v1",
33
+
34
+ extends: { l4EndpointContainer },
11
35
 
12
36
  includes: {
13
- endpoints: {
14
- entity: l4EndpointEntity,
15
- multiple: true,
37
+ /**
38
+ * The TLS certificate of the server if any.
39
+ */
40
+ certificate: {
41
+ entity: certificateEntity,
42
+ required: false,
16
43
  },
17
44
  },
18
45
 
19
- schema: sharedSchema,
46
+ schema: z.object({
47
+ /**
48
+ * The credentials for authenticating to the MongoDB instance.
49
+ */
50
+ credentials: credentialsSchema,
51
+
52
+ /**
53
+ * The name of the database to operate on.
54
+ */
55
+ database: z.string().optional(),
56
+ }),
20
57
 
21
58
  meta: {
22
59
  color: "#13aa52",
@@ -24,26 +61,52 @@ export const mongodbEntity = defineEntity({
24
61
  })
25
62
 
26
63
  /**
27
- * The existing MongoDB database or virtual database behind it.
64
+ * The existing MongoDB connection hosted on a server or a managed service.
28
65
  */
29
- export const existingMongodb = defineUnit({
30
- type: "databases.mongodb.existing.v1",
66
+ export const connection = defineUnit({
67
+ type: "mongodb.connection.v1",
31
68
 
32
- args: sharedArgs,
33
- secrets: sharedSecrets,
34
- inputs: sharedInputs,
69
+ args: {
70
+ /**
71
+ * The username to authenticate with.
72
+ */
73
+ username: z.string(),
74
+
75
+ /**
76
+ * The endpoints to connect to the MongoDB instance in form of `host:port`.
77
+ */
78
+ endpoints: z.string().array().default([]),
79
+ },
80
+
81
+ inputs: {
82
+ /**
83
+ * The endpoints to connect to the MongoDB instance.
84
+ */
85
+ endpoints: {
86
+ entity: l4EndpointEntity,
87
+ multiple: true,
88
+ required: false,
89
+ },
90
+ },
91
+
92
+ secrets: {
93
+ /**
94
+ * The password to authenticate with.
95
+ */
96
+ password: z.string(),
97
+ },
35
98
 
36
99
  outputs: {
37
- mongodb: mongodbEntity,
100
+ connection: connectionEntity,
38
101
  },
39
102
 
40
103
  source: {
41
- package: "@highstate/common",
42
- path: "units/databases/existing-mongodb",
104
+ package: "@highstate/mongodb",
105
+ path: "units/connection",
43
106
  },
44
107
 
45
108
  meta: {
46
- title: "Existing MongoDB Database",
109
+ title: "MongoDB Connection",
47
110
  icon: "simple-icons:mongodb",
48
111
  secondaryIcon: "mdi:database",
49
112
  category: "Databases",
@@ -51,41 +114,59 @@ export const existingMongodb = defineUnit({
51
114
  })
52
115
 
53
116
  /**
54
- * Patches some properties of the MongoDB database and outputs the updated database.
117
+ * Creates a database in a MongoDB instance.
55
118
  */
56
- export const mongodbPatch = defineUnit({
57
- type: "databases.mongodb-patch.v1",
119
+ export const database = defineUnit({
120
+ type: "mongodb.database.v1",
58
121
 
59
122
  args: {
60
- ...toPatchArgs(optionalSharedArgs),
61
-
62
- endpoints: {
63
- ...sharedArgs.endpoints,
64
- schema: z.string().array().default([]),
65
- },
123
+ /**
124
+ * The name of the database.
125
+ *
126
+ * If not provided, it will be set to the unit name.
127
+ */
128
+ databaseName: z.string().optional(),
129
+
130
+ /**
131
+ * The username to create.
132
+ *
133
+ * If not provided, it will be set to the database name.
134
+ */
135
+ username: z.string().optional(),
66
136
  },
67
137
 
68
138
  inputs: {
69
- mongodb: mongodbEntity,
70
- ...sharedInputs,
139
+ /**
140
+ * The connection to the MongoDB instance where the database should be created.
141
+ */
142
+ connection: connectionEntity,
71
143
  },
72
144
 
73
- outputs: {
74
- mongodb: mongodbEntity,
145
+ secrets: {
146
+ /**
147
+ * The password of the created user.
148
+ *
149
+ * If not provided, a random password will be generated.
150
+ */
151
+ password: z.string().optional(),
75
152
  },
76
153
 
77
- source: {
78
- package: "@highstate/common",
79
- path: "units/databases/mongodb-patch",
154
+ outputs: {
155
+ connection: connectionEntity,
80
156
  },
81
157
 
82
158
  meta: {
83
- title: "MongoDB Patch",
159
+ title: "MongoDB Database",
84
160
  icon: "simple-icons:mongodb",
85
- secondaryIcon: "fluent:patch-20-filled",
161
+ secondaryIcon: "mdi:database-plus",
86
162
  category: "Databases",
87
163
  },
164
+
165
+ source: {
166
+ package: "@highstate/mongodb",
167
+ path: "units/database",
168
+ },
88
169
  })
89
170
 
90
- export type MongoDB = z.infer<typeof mongodbEntity.schema>
91
- export type MongoDBInput = EntityInput<typeof mongodbEntity>
171
+ export type Connection = EntityValue<typeof connectionEntity>
172
+ export type ConnectionInput = EntityInput<typeof connectionEntity>
@@ -0,0 +1,172 @@
1
+ import {
2
+ defineEntity,
3
+ defineUnit,
4
+ type EntityInput,
5
+ type EntityValue,
6
+ secretSchema,
7
+ z,
8
+ } from "@highstate/contract"
9
+ import { l4EndpointContainer, l4EndpointEntity } from "../network"
10
+ import { certificateEntity } from "../tls"
11
+
12
+ export const credentialsSchema = z.discriminatedUnion("type", [
13
+ z.object({
14
+ type: z.literal("password"),
15
+
16
+ /**
17
+ * The username used to authenticate against the database.
18
+ */
19
+ username: z.string(),
20
+
21
+ /**
22
+ * The password used to authenticate against the database.
23
+ */
24
+ password: secretSchema(z.string()),
25
+ }),
26
+ ])
27
+
28
+ /**
29
+ * Represents a connection to a MySQL instance, including the endpoints and credentials.
30
+ */
31
+ export const connectionEntity = defineEntity({
32
+ type: "mysql.connection.v1",
33
+
34
+ extends: { l4EndpointContainer },
35
+
36
+ includes: {
37
+ /**
38
+ * The TLS certificate of the server if any.
39
+ */
40
+ certificate: {
41
+ entity: certificateEntity,
42
+ required: false,
43
+ },
44
+ },
45
+
46
+ schema: z.object({
47
+ /**
48
+ * The credentials for authenticating to the MySQL instance.
49
+ */
50
+ credentials: credentialsSchema,
51
+
52
+ /**
53
+ * The optional name of the database to operate on.
54
+ */
55
+ database: z.string().optional(),
56
+ }),
57
+
58
+ meta: {
59
+ color: "#f06292",
60
+ },
61
+ })
62
+
63
+ /**
64
+ * The existing MySQL connection hosted on a server or a managed service.
65
+ */
66
+ export const connection = defineUnit({
67
+ type: "mysql.connection.v1",
68
+
69
+ args: {
70
+ /**
71
+ * The username to authenticate with.
72
+ */
73
+ username: z.string(),
74
+
75
+ /**
76
+ * The endpoints to connect to the MySQL instance in form of `host:port`.
77
+ */
78
+ endpoints: z.string().array().default([]),
79
+ },
80
+
81
+ inputs: {
82
+ /**
83
+ * The endpoints to connect to the MySQL instance.
84
+ */
85
+ endpoints: {
86
+ entity: l4EndpointEntity,
87
+ multiple: true,
88
+ required: false,
89
+ },
90
+ },
91
+
92
+ secrets: {
93
+ /**
94
+ * The password to authenticate with.
95
+ */
96
+ password: z.string(),
97
+ },
98
+
99
+ outputs: {
100
+ connection: connectionEntity,
101
+ },
102
+
103
+ source: {
104
+ package: "@highstate/mysql",
105
+ path: "units/connection",
106
+ },
107
+
108
+ meta: {
109
+ title: "MySQL Connection",
110
+ icon: "simple-icons:mysql",
111
+ secondaryIcon: "mdi:database",
112
+ category: "Databases",
113
+ },
114
+ })
115
+
116
+ /**
117
+ * Creates a database in a MySQL instance.
118
+ */
119
+ export const database = defineUnit({
120
+ type: "mysql.database.v1",
121
+
122
+ args: {
123
+ /**
124
+ * The name of the database.
125
+ *
126
+ * If not provided, it will be set to the unit name.
127
+ */
128
+ databaseName: z.string().optional(),
129
+
130
+ /**
131
+ * The username of the database admin user to create.
132
+ *
133
+ * If not provided, it will be set to the database name.
134
+ */
135
+ username: z.string().optional(),
136
+ },
137
+
138
+ inputs: {
139
+ /**
140
+ * The connection to the MySQL instance where the database should be created.
141
+ */
142
+ connection: connectionEntity,
143
+ },
144
+
145
+ secrets: {
146
+ /**
147
+ * The password of the created user.
148
+ *
149
+ * If not provided, a random password will be generated.
150
+ */
151
+ password: z.string().optional(),
152
+ },
153
+
154
+ outputs: {
155
+ connection: connectionEntity,
156
+ },
157
+
158
+ meta: {
159
+ title: "MySQL Database",
160
+ icon: "simple-icons:mysql",
161
+ secondaryIcon: "mdi:database-plus",
162
+ category: "Databases",
163
+ },
164
+
165
+ source: {
166
+ package: "@highstate/mysql",
167
+ path: "units/database",
168
+ },
169
+ })
170
+
171
+ export type Connection = EntityValue<typeof connectionEntity>
172
+ export type ConnectionInput = EntityInput<typeof connectionEntity>