@highstate/backend 0.9.18 → 0.9.19
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/chunk-5WVU2AK4.js +1535 -0
- package/dist/chunk-5WVU2AK4.js.map +1 -0
- package/dist/{chunk-OU5OQBLB.js → chunk-I7BWSAN6.js} +3 -28
- package/dist/{chunk-OU5OQBLB.js.map → chunk-I7BWSAN6.js.map} +1 -1
- package/dist/chunk-VB4YL327.js +139 -0
- package/dist/chunk-VB4YL327.js.map +1 -0
- package/dist/database/local/prisma.config.js +26 -0
- package/dist/database/local/prisma.config.js.map +1 -0
- package/dist/highstate.manifest.json +2 -1
- package/dist/index.js +7587 -7291
- package/dist/index.js.map +1 -1
- package/dist/library/package-resolution-worker.js +1 -1
- package/dist/library/package-resolution-worker.js.map +1 -1
- package/dist/library/worker/main.js +35 -29
- package/dist/library/worker/main.js.map +1 -1
- package/dist/shared/index.js +2 -2
- package/package.json +18 -9
- package/prisma/backend/_schema/layout.prisma +7 -0
- package/prisma/backend/_schema/library.prisma +17 -0
- package/prisma/backend/_schema/project.prisma +101 -0
- package/prisma/backend/_schema/pulumi.prisma +17 -0
- package/prisma/backend/postgresql/main.prisma +17 -0
- package/prisma/backend/sqlite/main.prisma +17 -0
- package/prisma/backend/sqlite/migrations/20250817070609_initiial/migration.sql +34 -0
- package/prisma/backend/sqlite/migrations/20250817104948_add_fields/migration.sql +59 -0
- package/prisma/backend/sqlite/migrations/20250818082732_add_models/migration.sql +41 -0
- package/prisma/backend/sqlite/migrations/20250818083106_a/migration.sql +19 -0
- package/prisma/backend/sqlite/migrations/20250818101945_hi/migration.sql +1 -0
- package/prisma/backend/sqlite/migrations/20250819082315_a/migration.sql +5 -0
- package/prisma/backend/sqlite/migrations/migration_lock.toml +3 -0
- package/prisma/project/api-key.prisma +27 -0
- package/prisma/project/artifact.prisma +52 -0
- package/prisma/project/custom-status.prisma +46 -0
- package/prisma/project/evaluation.prisma +35 -0
- package/prisma/project/instance.prisma +160 -0
- package/prisma/project/layout.prisma +23 -0
- package/prisma/project/lock.prisma +18 -0
- package/prisma/project/main.prisma +17 -0
- package/prisma/project/migrations/20250816081310_initial/migration.sql +300 -0
- package/prisma/project/migrations/20250816082523_test/migration.sql +72 -0
- package/prisma/project/migrations/20250818065643_update/migration.sql +42 -0
- package/prisma/project/migrations/20250818070758_a/migration.sql +8 -0
- package/prisma/project/migrations/20250818070913_a/migration.sql +8 -0
- package/prisma/project/migrations/20250818082720_add_motels/migration.sql +11 -0
- package/prisma/project/migrations/20250818112523_hello/migration.sql +35 -0
- package/prisma/project/migrations/20250819082305_a/migration.sql +14 -0
- package/prisma/project/migrations/20250819165004_add_missing_fields/migration.sql +216 -0
- package/prisma/project/migrations/20250819171309_a/migration.sql +22 -0
- package/prisma/project/migrations/20250820113949_a/migration.sql +66 -0
- package/prisma/project/migrations/20250820144256_b/migration.sql +31 -0
- package/prisma/project/migrations/20250820145547_a/migration.sql +24 -0
- package/prisma/project/migrations/20250820182517_b/migration.sql +2 -0
- package/prisma/project/migrations/20250821172324_a/migration.sql +2 -0
- package/prisma/project/migrations/20250822081339_a/migration.sql +219 -0
- package/prisma/project/migrations/20250822083742_b/migration.sql +1 -0
- package/prisma/project/migrations/20250822105134_boom/migration.sql +1 -0
- package/prisma/project/migrations/20250822141028_b/migration.sql +1 -0
- package/prisma/project/migrations/20250822142342_b/migration.sql +16 -0
- package/prisma/project/migrations/20250824072720_a/migration.sql +1 -0
- package/prisma/project/migrations/20250824093656_b/migration.sql +21 -0
- package/prisma/project/migrations/20250825082518_a/migration.sql +1 -0
- package/prisma/project/migrations/20250825085343_b/migration.sql +1 -0
- package/prisma/project/migrations/20250825091312_a/migration.sql +1 -0
- package/prisma/project/migrations/20250903095431_hi/migration.sql +44 -0
- package/prisma/project/migrations/20250903174255_a/migration.sql +24 -0
- package/prisma/project/migrations/20250908095205_hi/migration.sql +18 -0
- package/prisma/project/migrations/20250909155857_hi/migration.sql +15 -0
- package/prisma/project/migrations/migration_lock.toml +3 -0
- package/prisma/project/model.prisma +37 -0
- package/prisma/project/operation.prisma +148 -0
- package/prisma/project/page.prisma +41 -0
- package/prisma/project/secret.prisma +42 -0
- package/prisma/project/service-account.prisma +36 -0
- package/prisma/project/terminal.prisma +90 -0
- package/prisma/project/trigger.prisma +31 -0
- package/prisma/project/unlock-method.prisma +32 -0
- package/prisma/project/worker.prisma +138 -0
- package/src/artifact/abstractions.ts +13 -13
- package/src/artifact/encryption.ts +30 -54
- package/src/artifact/factory.ts +6 -9
- package/src/artifact/local.ts +33 -46
- package/src/business/api-key.ts +24 -36
- package/src/business/artifact.test.ts +978 -0
- package/src/business/artifact.ts +136 -216
- package/src/business/evaluation.ts +328 -0
- package/src/business/index.ts +5 -2
- package/src/business/instance-lock.test.ts +1060 -0
- package/src/business/instance-lock.ts +387 -78
- package/src/business/instance-state.test.ts +735 -0
- package/src/business/instance-state.ts +582 -337
- package/src/business/operation.test.ts +439 -0
- package/src/business/operation.ts +174 -208
- package/src/business/project-model.ts +258 -0
- package/src/business/project-unlock.ts +168 -126
- package/src/business/project.ts +287 -179
- package/src/business/secret.test.ts +465 -130
- package/src/business/secret.ts +186 -217
- package/src/business/settings.test.ts +695 -0
- package/src/business/settings.ts +855 -0
- package/src/business/terminal-session.ts +90 -0
- package/src/business/unit-extra.test.ts +539 -0
- package/src/business/unit-extra.ts +160 -0
- package/src/business/worker.test.ts +356 -579
- package/src/business/worker.ts +238 -339
- package/src/common/codebase.ts +65 -0
- package/src/common/index.ts +3 -5
- package/src/common/logger.ts +5 -0
- package/src/common/utils.ts +4 -3
- package/src/config.ts +10 -11
- package/src/database/_generated/backend/postgresql/client.ts +72 -0
- package/src/database/_generated/backend/postgresql/commonInputTypes.ts +350 -0
- package/src/database/_generated/backend/postgresql/enums.ts +13 -0
- package/src/database/_generated/backend/postgresql/internal/class.ts +320 -0
- package/src/database/_generated/backend/postgresql/internal/prismaNamespace.ts +1238 -0
- package/src/database/_generated/backend/postgresql/models/Library.ts +1263 -0
- package/src/database/_generated/backend/postgresql/models/Project.ts +2175 -0
- package/src/database/_generated/backend/postgresql/models/ProjectModelStorage.ts +1263 -0
- package/src/database/_generated/backend/postgresql/models/ProjectSpace.ts +1602 -0
- package/src/database/_generated/backend/postgresql/models/PulumiBackend.ts +1263 -0
- package/src/database/_generated/backend/postgresql/models/UserWorkspaseLayout.ts +1065 -0
- package/src/database/_generated/backend/postgresql/models.ts +16 -0
- package/src/database/_generated/backend/postgresql/pjtg.ts +182 -0
- package/src/database/_generated/backend/sqlite/client.ts +72 -0
- package/src/database/_generated/backend/sqlite/commonInputTypes.ts +331 -0
- package/src/database/_generated/backend/sqlite/enums.ts +13 -0
- package/src/database/_generated/backend/sqlite/internal/class.ts +318 -0
- package/src/database/_generated/backend/sqlite/internal/prismaNamespace.ts +1207 -0
- package/src/database/_generated/backend/sqlite/models/Library.ts +1261 -0
- package/src/database/_generated/backend/sqlite/models/Project.ts +2169 -0
- package/src/database/_generated/backend/sqlite/models/ProjectModelStorage.ts +1261 -0
- package/src/database/_generated/backend/sqlite/models/ProjectSpace.ts +1599 -0
- package/src/database/_generated/backend/sqlite/models/PulumiBackend.ts +1261 -0
- package/src/database/_generated/backend/sqlite/models/UserWorkspaseLayout.ts +1063 -0
- package/src/database/_generated/backend/sqlite/models.ts +16 -0
- package/src/database/_generated/backend/sqlite/pjtg.ts +182 -0
- package/src/database/_generated/project/client.ts +204 -0
- package/src/database/_generated/project/commonInputTypes.ts +827 -0
- package/src/database/_generated/project/enums.ts +104 -0
- package/src/database/_generated/project/internal/class.ts +479 -0
- package/src/database/_generated/project/internal/prismaNamespace.ts +2974 -0
- package/src/database/_generated/project/models/ApiKey.ts +1506 -0
- package/src/database/_generated/project/models/Artifact.ts +2051 -0
- package/src/database/_generated/project/models/HubModel.ts +1125 -0
- package/src/database/_generated/project/models/InstanceCustomStatus.ts +1713 -0
- package/src/database/_generated/project/models/InstanceEvaluationState.ts +1312 -0
- package/src/database/_generated/project/models/InstanceLock.ts +1268 -0
- package/src/database/_generated/project/models/InstanceModel.ts +1125 -0
- package/src/database/_generated/project/models/InstanceOperationState.ts +1707 -0
- package/src/database/_generated/project/models/InstanceState.ts +4613 -0
- package/src/database/_generated/project/models/Operation.ts +1647 -0
- package/src/database/_generated/project/models/OperationLog.ts +1455 -0
- package/src/database/_generated/project/models/Page.ts +1838 -0
- package/src/database/_generated/project/models/Secret.ts +1692 -0
- package/src/database/_generated/project/models/ServiceAccount.ts +2165 -0
- package/src/database/_generated/project/models/Terminal.ts +2038 -0
- package/src/database/_generated/project/models/TerminalSession.ts +1454 -0
- package/src/database/_generated/project/models/TerminalSessionLog.ts +1280 -0
- package/src/database/_generated/project/models/Trigger.ts +1430 -0
- package/src/database/_generated/project/models/UnlockMethod.ts +1220 -0
- package/src/database/_generated/project/models/UserCompositeViewport.ts +1280 -0
- package/src/database/_generated/project/models/UserProjectViewport.ts +1059 -0
- package/src/database/_generated/project/models/Worker.ts +1459 -0
- package/src/database/_generated/project/models/WorkerUnitRegistration.ts +1524 -0
- package/src/database/_generated/project/models/WorkerVersion.ts +1974 -0
- package/src/database/_generated/project/models/WorkerVersionLog.ts +1318 -0
- package/src/database/_generated/project/models.ts +35 -0
- package/src/database/_generated/project/pjtg.ts +182 -0
- package/src/database/abstractions.ts +19 -0
- package/src/database/factory.ts +37 -0
- package/src/database/index.ts +6 -0
- package/src/database/local/backend.ts +134 -0
- package/src/database/local/index.ts +3 -0
- package/src/database/local/meta.ts +46 -0
- package/src/database/local/prisma.config.ts +25 -0
- package/src/database/local/project.ts +39 -0
- package/src/database/manager.ts +181 -0
- package/src/database/migrate.ts +35 -0
- package/src/database/prisma.ts +56 -0
- package/src/database/well-known.ts +38 -0
- package/src/index.ts +4 -4
- package/src/library/abstractions.ts +3 -5
- package/src/library/factory.ts +1 -1
- package/src/library/local.ts +81 -26
- package/src/library/package-resolution-worker.ts +1 -1
- package/src/library/worker/evaluator.ts +40 -23
- package/src/library/worker/loader.lite.ts +1 -1
- package/src/library/worker/main.ts +3 -10
- package/src/library/worker/protocol.ts +0 -1
- package/src/lock/index.ts +0 -1
- package/src/lock/manager.ts +0 -10
- package/src/orchestrator/manager.ts +190 -104
- package/src/orchestrator/operation-context.ts +357 -0
- package/src/orchestrator/operation-plan.destroy.test.md +357 -0
- package/src/orchestrator/operation-plan.destroy.test.ts +775 -0
- package/src/orchestrator/operation-plan.fixtures.ts +213 -0
- package/src/orchestrator/operation-plan.md +198 -0
- package/src/orchestrator/operation-plan.refresh.test.md +199 -0
- package/src/orchestrator/operation-plan.refresh.test.ts +367 -0
- package/src/orchestrator/operation-plan.ts +709 -0
- package/src/orchestrator/operation-plan.update.test.md +485 -0
- package/src/orchestrator/operation-plan.update.test.ts +1066 -0
- package/src/orchestrator/operation-workset.ts +233 -578
- package/src/orchestrator/operation.ts +435 -948
- package/src/orchestrator/plan-test-builder.ts +267 -0
- package/src/project-model/abstractions.ts +118 -0
- package/src/project-model/backends/codebase.ts +365 -0
- package/src/project-model/backends/database.ts +440 -0
- package/src/project-model/errors.ts +81 -0
- package/src/project-model/factory.ts +24 -0
- package/src/project-model/index.ts +4 -0
- package/src/project-model/utils.test.ts +544 -0
- package/src/project-model/utils.ts +242 -0
- package/src/pubsub/abstractions.ts +10 -1
- package/src/pubsub/factory.ts +4 -4
- package/src/pubsub/index.ts +1 -0
- package/src/pubsub/manager.ts +29 -13
- package/src/pubsub/memory.ts +31 -0
- package/src/runner/abstractions.ts +33 -41
- package/src/runner/artifact-env.ts +19 -8
- package/src/runner/factory.ts +6 -6
- package/src/runner/force-abort.ts +3 -6
- package/src/runner/local.ts +64 -67
- package/src/runner/pulumi.ts +23 -63
- package/src/services.ts +181 -123
- package/src/shared/models/backend/index.ts +3 -1
- package/src/shared/models/backend/library.ts +9 -1
- package/src/shared/models/backend/project.ts +43 -42
- package/src/shared/models/backend/pulumi.ts +14 -0
- package/src/shared/models/backend/unlock-method.ts +1 -1
- package/src/shared/models/backend/well-known.ts +58 -0
- package/src/shared/models/base.ts +40 -26
- package/src/shared/models/errors.ts +82 -1
- package/src/shared/models/index.ts +3 -2
- package/src/shared/models/prisma.ts +36 -0
- package/src/shared/models/project/api-key.ts +37 -59
- package/src/shared/models/project/artifact.ts +16 -76
- package/src/shared/models/project/custom-status.ts +12 -0
- package/src/shared/models/project/index.ts +8 -7
- package/src/shared/models/project/lock.ts +10 -78
- package/src/shared/models/project/model.ts +19 -1
- package/src/shared/models/project/operation.ts +222 -99
- package/src/shared/models/project/page.ts +37 -48
- package/src/shared/models/project/secret.ts +29 -89
- package/src/shared/models/project/service-account.ts +12 -17
- package/src/shared/models/project/state.ts +100 -407
- package/src/shared/models/project/terminal.ts +75 -88
- package/src/shared/models/project/trigger.ts +13 -49
- package/src/shared/models/project/unlock-method.ts +20 -26
- package/src/shared/models/project/worker.ts +89 -90
- package/src/shared/resolvers/graph-resolver.ts +21 -0
- package/src/shared/resolvers/index.ts +1 -1
- package/src/shared/resolvers/input-hash.ts +24 -14
- package/src/shared/resolvers/input.ts +1 -1
- package/src/shared/resolvers/registry.ts +5 -4
- package/src/shared/resolvers/state.ts +12 -1
- package/src/shared/resolvers/validation.ts +7 -3
- package/src/shared/utils/index.ts +1 -2
- package/src/shared/utils/promise-tracker.ts +30 -3
- package/src/terminal/abstractions.ts +1 -1
- package/src/terminal/docker.ts +3 -3
- package/src/terminal/manager.ts +102 -118
- package/src/test-utils/database.ts +119 -0
- package/src/test-utils/index.ts +2 -0
- package/src/test-utils/services.ts +134 -0
- package/src/unlock/abstractions.ts +5 -23
- package/src/unlock/memory.ts +9 -14
- package/src/worker/abstractions.ts +7 -4
- package/src/worker/docker.ts +14 -19
- package/src/worker/manager.ts +366 -97
- package/dist/chunk-NAAIDR4U.js +0 -8499
- package/dist/chunk-NAAIDR4U.js.map +0 -1
- package/dist/chunk-Y7DXREVO.js +0 -1745
- package/dist/chunk-Y7DXREVO.js.map +0 -1
- package/dist/magic-string.es-5ABAC4JN.js +0 -1292
- package/dist/magic-string.es-5ABAC4JN.js.map +0 -1
- package/src/business/__traces__/secret/update-instance-secrets/create-and-delete-secrets-simultaneously.md +0 -356
- package/src/business/__traces__/secret/update-instance-secrets/create-new-secrets-for-instance.md +0 -274
- package/src/business/__traces__/secret/update-instance-secrets/delete-existing-secrets.md +0 -223
- package/src/business/__traces__/secret/update-instance-secrets/no-op-when-no-changes.md +0 -147
- package/src/business/__traces__/secret/update-instance-secrets/update-existing-secrets.md +0 -280
- package/src/business/__traces__/worker/update-unit-registrations/add-new-unit-registration-when-other-exists.md +0 -360
- package/src/business/__traces__/worker/update-unit-registrations/add-new-unit-registration.md +0 -215
- package/src/business/__traces__/worker/update-unit-registrations/create-multiple-workers-with-different-identities.md +0 -427
- package/src/business/__traces__/worker/update-unit-registrations/handle-nonexistent-registration-id-gracefully.md +0 -217
- package/src/business/__traces__/worker/update-unit-registrations/no-op-when-no-changes.md +0 -132
- package/src/business/__traces__/worker/update-unit-registrations/recreate-worker-when-image-changes.md +0 -454
- package/src/business/__traces__/worker/update-unit-registrations/recreate-worker-when-image-version-changes.md +0 -426
- package/src/business/__traces__/worker/update-unit-registrations/recreate-worker-with-same-identity-reuses-service-account.md +0 -372
- package/src/business/__traces__/worker/update-unit-registrations/remove-one-of-multiple-unit-registrations.md +0 -383
- package/src/business/__traces__/worker/update-unit-registrations/remove-unit-registration.md +0 -245
- package/src/business/__traces__/worker/update-unit-registrations/update-existing-unit-registration-when-params-change.md +0 -174
- package/src/business/__traces__/worker/update-unit-registrations/update-params-and-image-simultaneously.md +0 -432
- package/src/business/__traces__/worker/update-unit-registrations/worker-with-multiple-registrations-not-deleted-when-one-removed.md +0 -220
- package/src/business/backend-unlock.ts +0 -10
- package/src/common/clock.ts +0 -18
- package/src/common/performance.ts +0 -44
- package/src/common/random.ts +0 -68
- package/src/common/test/index.ts +0 -2
- package/src/common/test/render.ts +0 -98
- package/src/common/test/tracer.ts +0 -359
- package/src/hotstate/abstractions.ts +0 -48
- package/src/hotstate/factory.ts +0 -17
- package/src/hotstate/index.ts +0 -3
- package/src/hotstate/manager.ts +0 -192
- package/src/hotstate/memory.ts +0 -100
- package/src/hotstate/validation.ts +0 -100
- package/src/lock/test.ts +0 -108
- package/src/project/abstractions.ts +0 -78
- package/src/project/evaluation.ts +0 -248
- package/src/project/factory.ts +0 -11
- package/src/project/index.ts +0 -3
- package/src/project/local.ts +0 -417
- package/src/pubsub/local.ts +0 -36
- package/src/pubsub/validation.ts +0 -33
- package/src/shared/utils/args.ts +0 -25
- package/src/state/abstractions.ts +0 -289
- package/src/state/encryption.ts +0 -98
- package/src/state/factory.ts +0 -20
- package/src/state/index.ts +0 -7
- package/src/state/local/backend.ts +0 -106
- package/src/state/local/collection.ts +0 -361
- package/src/state/local/index.ts +0 -2
- package/src/state/manager.ts +0 -890
- package/src/state/memory/backend.ts +0 -70
- package/src/state/memory/collection.ts +0 -270
- package/src/state/memory/index.ts +0 -2
- package/src/state/repository/index.ts +0 -2
- package/src/state/repository/repository.index.ts +0 -193
- package/src/state/repository/repository.ts +0 -507
- package/src/state/test.ts +0 -457
- /package/src/{state → database/local}/keyring.ts +0 -0
|
@@ -1,449 +1,142 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type { InstanceId } from "@highstate/contract"
|
|
2
|
+
import type {
|
|
3
|
+
InstanceState as DatabaseInstanceState,
|
|
4
|
+
InstanceCustomStatus,
|
|
5
|
+
InstanceEvaluationState,
|
|
6
|
+
InstanceOperationState,
|
|
7
|
+
InstanceOperationStatus,
|
|
8
|
+
} from "../../../database"
|
|
6
9
|
import { z } from "zod"
|
|
7
|
-
import { objectMetaSchema, userObjectMetaSchema } from "@highstate/contract"
|
|
8
|
-
|
|
9
|
-
export const instanceOperationStatusEnumSchema = z.enum([
|
|
10
|
-
// transient statuses
|
|
11
|
-
"updating",
|
|
12
|
-
"processing-triggers",
|
|
13
|
-
"previewing",
|
|
14
|
-
"destroying",
|
|
15
|
-
"refreshing",
|
|
16
|
-
"pending",
|
|
17
|
-
"cancelling",
|
|
18
|
-
|
|
19
|
-
// stable statuses
|
|
20
|
-
"created",
|
|
21
|
-
"error",
|
|
22
|
-
])
|
|
23
|
-
|
|
24
|
-
export const instanceOperationStatusSchema = z.object({
|
|
25
|
-
/**
|
|
26
|
-
* The enum representing the current status of the instance from the operation perspective.
|
|
27
|
-
*/
|
|
28
|
-
status: instanceOperationStatusEnumSchema,
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* The ID of the latest operation that this instance is associated with.
|
|
32
|
-
*/
|
|
33
|
-
latestOperationId: z.string(),
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* The IDs of the instances that this instance depends on at the moment of latest operation.
|
|
37
|
-
*/
|
|
38
|
-
dependencyIds: z.array(z.string()),
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* The some human-readable message describing the current status.
|
|
42
|
-
* Typically used to show the error message if the status is "error".
|
|
43
|
-
*/
|
|
44
|
-
message: z.string().optional(),
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* The current count of the Pulumi resources being managed by this instance.
|
|
48
|
-
*/
|
|
49
|
-
currentResourceCount: z.number().optional(),
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* The total count of the Pulumi resources that this instance is expected to manage.
|
|
53
|
-
*/
|
|
54
|
-
totalResourceCount: z.number().optional(),
|
|
55
10
|
|
|
11
|
+
/**
|
|
12
|
+
* The instance state aggregate including all related states.
|
|
13
|
+
*/
|
|
14
|
+
export type InstanceState = DatabaseInstanceState & {
|
|
56
15
|
/**
|
|
57
|
-
* The
|
|
16
|
+
* The ID of the parent instance, if any.
|
|
58
17
|
*
|
|
59
|
-
*
|
|
60
|
-
* - the instance's configuration (name, args, secret hashes);
|
|
61
|
-
* - the component definition hash;
|
|
62
|
-
* - the unit's source hash (if applicable);
|
|
63
|
-
* - the input hashes and output hashes of all input instances.
|
|
18
|
+
* Not to be confused with `parentId` which is the surrogate ID of the parent state.
|
|
64
19
|
*/
|
|
65
|
-
|
|
20
|
+
parentInstanceId?: InstanceId | null
|
|
66
21
|
|
|
67
22
|
/**
|
|
68
|
-
* The
|
|
69
|
-
*
|
|
70
|
-
* It is changed every time the instance secrets are updated,
|
|
71
|
-
* to invalidate the input hash and force running the instance again.
|
|
72
|
-
*/
|
|
73
|
-
inputHashNonce: z.number().optional(),
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* The sha256 of the output produced by the instance at the moment of latest operation completion.
|
|
77
|
-
*
|
|
78
|
-
* Does not depend on anything except the instance's output.
|
|
79
|
-
*/
|
|
80
|
-
outputHash: z.string().optional(),
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* The calculated sha256 dependency output hash at the moment of latest operation completion.
|
|
84
|
-
*
|
|
85
|
-
* This hash is calculated as combination of output hashes of all input instances and nothing else.
|
|
86
|
-
*
|
|
87
|
-
* The primary use case of this hash is to "short-circuit" execution:
|
|
88
|
-
* if the outputs of input instances have not changed, dependent instances can skip execution,
|
|
89
|
-
* even if their input hashes changed due to upstream config changes.
|
|
90
|
-
* This prevents unnecessary re-execution of the entire dependency graph when only non-output-affecting inputs are modified.
|
|
91
|
-
*/
|
|
92
|
-
dependencyOutputHash: z.string().optional(),
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* The arguments of the instances at the moment of latest operation start.
|
|
23
|
+
* The names of the instance secrets which have values set.
|
|
96
24
|
*/
|
|
97
|
-
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
export const instanceEvaludationStatusEnumSchema = z.enum([
|
|
101
|
-
// transient statuses
|
|
102
|
-
"evaluating",
|
|
25
|
+
secretNames?: string[]
|
|
103
26
|
|
|
104
|
-
// stable statuses
|
|
105
|
-
"evaluated",
|
|
106
|
-
"error",
|
|
107
|
-
])
|
|
108
|
-
|
|
109
|
-
export const instanceEvaluationStatusSchema = z.object({
|
|
110
27
|
/**
|
|
111
|
-
* The
|
|
112
|
-
*
|
|
113
|
-
* The stable status when instance is not evaludated is forbidden.
|
|
28
|
+
* The last operation state of the instance.
|
|
114
29
|
*/
|
|
115
|
-
|
|
30
|
+
lastOperationState?: InstanceOperationState | null
|
|
116
31
|
|
|
117
32
|
/**
|
|
118
|
-
* The
|
|
119
|
-
* Typically used to show the error message if the status is "error".
|
|
33
|
+
* The evaluation state of the instance.
|
|
120
34
|
*/
|
|
121
|
-
|
|
122
|
-
})
|
|
35
|
+
evaluationState?: InstanceEvaluationState | null
|
|
123
36
|
|
|
124
|
-
export enum WellKnownInstanceCustomStatus {
|
|
125
37
|
/**
|
|
126
|
-
* The
|
|
38
|
+
* The IDs of the terminals produced by this unit instance.
|
|
127
39
|
*/
|
|
128
|
-
|
|
40
|
+
terminalIds?: string[]
|
|
129
41
|
|
|
130
42
|
/**
|
|
131
|
-
* The
|
|
43
|
+
* The IDs of the pages produced by this unit instance.
|
|
132
44
|
*/
|
|
133
|
-
|
|
45
|
+
pageIds?: string[]
|
|
134
46
|
|
|
135
47
|
/**
|
|
136
|
-
* The
|
|
48
|
+
* The IDs of the triggers produced by this unit instance.
|
|
137
49
|
*/
|
|
138
|
-
|
|
50
|
+
triggerIds?: string[]
|
|
139
51
|
|
|
140
52
|
/**
|
|
141
|
-
* The
|
|
53
|
+
* The custom statuses attached to this instance.
|
|
142
54
|
*/
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* The instance is progressing with some external sync operation,
|
|
147
|
-
* such as a deployment or a data migration.
|
|
148
|
-
*/
|
|
149
|
-
Progressing = "progressing",
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* The instance is in an error state.
|
|
153
|
-
*/
|
|
154
|
-
Error = "error",
|
|
55
|
+
customStatuses?: InstanceCustomStatus[]
|
|
155
56
|
}
|
|
156
57
|
|
|
157
|
-
export const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* The title of the instance's extra status.
|
|
174
|
-
*/
|
|
175
|
-
title: z.string(),
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* The `iconify` icon representing the instance's extra status.
|
|
179
|
-
*
|
|
180
|
-
* If not provided and status is a well-known value, the icon will be derived from the status.
|
|
181
|
-
*/
|
|
182
|
-
icon: z.string().optional(),
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* The HEX color of the status badge.
|
|
186
|
-
*
|
|
187
|
-
* If not provided and status is a well-known value, the color will be derived from the status.
|
|
188
|
-
*/
|
|
189
|
-
color: z.string().optional(),
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* The message describing the instance's extra status.
|
|
193
|
-
*
|
|
194
|
-
* Can be used to provide additional context or information about the status.
|
|
195
|
-
*
|
|
196
|
-
* The message will be displayed in the 800x600 ANSI terminal in the UI,
|
|
197
|
-
* so differenet TUI elements should be drawn within this area.
|
|
198
|
-
*/
|
|
199
|
-
message: z.string().optional(),
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* The order of the status in the list of statuses.
|
|
203
|
-
*
|
|
204
|
-
* Must be in the range from `0` to `100`, lower values are displayed first.
|
|
205
|
-
*
|
|
206
|
-
* If not provided, the default is `50`.
|
|
207
|
-
*/
|
|
208
|
-
order: z.number().min(0).max(100).optional(),
|
|
209
|
-
})
|
|
210
|
-
|
|
211
|
-
export const instanceStatusFieldValueSchema = z.union([
|
|
212
|
-
z.string(),
|
|
213
|
-
z.number(),
|
|
214
|
-
z.boolean(),
|
|
215
|
-
z.array(z.string()),
|
|
58
|
+
export const instanceStateEventSchema = z.discriminatedUnion("type", [
|
|
59
|
+
z.object({
|
|
60
|
+
type: z.literal("updated"),
|
|
61
|
+
state: z.custom<InstanceState>(),
|
|
62
|
+
}),
|
|
63
|
+
z.object({
|
|
64
|
+
type: z.literal("patched"),
|
|
65
|
+
stateId: z.string(),
|
|
66
|
+
patch: z.custom<Partial<InstanceState>>(),
|
|
67
|
+
}),
|
|
68
|
+
z.object({
|
|
69
|
+
type: z.literal("deleted"),
|
|
70
|
+
stateId: z.string(),
|
|
71
|
+
}),
|
|
216
72
|
])
|
|
217
73
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
* The status fields reported by the unit or attached via the API.
|
|
234
|
-
*
|
|
235
|
-
* Do not confuse with `customStatuses`.
|
|
236
|
-
*
|
|
237
|
-
* These fields are used to store additional information about the instance,
|
|
238
|
-
* such as URLs, display names, and other metadata.
|
|
239
|
-
*/
|
|
240
|
-
statusFields: z.array(instanceStatusFieldSchema).optional(),
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* The extra statuses of the instance reported by the unit or attached via the API.
|
|
244
|
-
*
|
|
245
|
-
* Do not confuse with `statusFields.
|
|
246
|
-
*/
|
|
247
|
-
customStatuses: z.array(instanceCustomStatusSchema).optional(),
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* The IDs of the pages that are owned by this instance.
|
|
251
|
-
*
|
|
252
|
-
* The keys are the local page names, and the values are the page IDs.
|
|
253
|
-
*/
|
|
254
|
-
pageIds: z.record(z.string(), z.string()).optional(),
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* The IDs of the terminals that are owned by this instance.
|
|
258
|
-
*
|
|
259
|
-
* The keys are the local terminal names, and the values are the terminal IDs.
|
|
260
|
-
*/
|
|
261
|
-
terminalIds: z.record(z.string(), z.string()).optional(),
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* The IDs of the triggers that are owned by this instance.
|
|
265
|
-
*
|
|
266
|
-
* The keys are the local trigger names, and the values are the trigger IDs.
|
|
267
|
-
*/
|
|
268
|
-
triggerIds: z.record(z.string(), z.string()).optional(),
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* The IDs of the artifacts that this instance exports via outputs.
|
|
272
|
-
*
|
|
273
|
-
* The keys are the output keys, and the values are the artifact IDs.
|
|
274
|
-
*
|
|
275
|
-
* These artifacts can be both: produced by this instance or reexported from input instances.
|
|
276
|
-
*/
|
|
277
|
-
exportedArtifactIds: z.record(z.string(), z.array(z.string())).optional(),
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* The IDs of the secrets that this instance exports via outputs.
|
|
281
|
-
*
|
|
282
|
-
* The keys are the output keys, and the values are the secret IDs.
|
|
283
|
-
*
|
|
284
|
-
* These secrets can be both: produced by this instance or reexported from input instances.
|
|
285
|
-
*/
|
|
286
|
-
exportedSecretIds: z.record(z.string(), z.string().array()).optional(),
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* The IDs of the worker registrations that are owned by this instance.
|
|
290
|
-
*
|
|
291
|
-
* The keys are the unit worker names, and the values are the registration IDs.
|
|
292
|
-
*/
|
|
293
|
-
workerRegistrationIds: z.record(z.string(), z.string()).optional(),
|
|
294
|
-
})
|
|
295
|
-
|
|
296
|
-
export const instanceStateSchema = z.object({
|
|
297
|
-
/**
|
|
298
|
-
* The unique identifier of the instance.
|
|
299
|
-
* The format is `{componentType}:{instanceName}`, so each instance must have a unique name within its component type.
|
|
300
|
-
*/
|
|
301
|
-
id: z.string(),
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* The ID of the parent instance, if this instance is a child of another composite instance.
|
|
305
|
-
*/
|
|
306
|
-
parentId: z.string().optional(),
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* The names of the secrets that has values in this instance.
|
|
310
|
-
*/
|
|
311
|
-
secretNames: z.array(z.string()).optional(),
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* The current status of the instance from the operation perspective.
|
|
315
|
-
*
|
|
316
|
-
* This status persists in the storage only when the operation is completed.
|
|
317
|
-
*
|
|
318
|
-
* If the operation was interrupted, the status will be "error" with corresponding error message.
|
|
319
|
-
*
|
|
320
|
-
* If the instance was not created or was successfully destroyed, the whole "operationStatus" field will be undefined.
|
|
321
|
-
*/
|
|
322
|
-
operationStatus: instanceOperationStatusSchema.optional(),
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* The current status of the instance from the evaluation perspective.
|
|
326
|
-
*
|
|
327
|
-
* Only applies to composite instances, will always be `undefined` for unit instances.
|
|
328
|
-
*/
|
|
329
|
-
evaluationStatus: instanceEvaluationStatusSchema.optional(),
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* The extra components of the instance.
|
|
333
|
-
*
|
|
334
|
-
* Applies to both unit and composite instances.
|
|
335
|
-
*/
|
|
336
|
-
extra: instanceStateExtraSchema.optional(),
|
|
337
|
-
})
|
|
338
|
-
|
|
339
|
-
export type InstanceStatusFieldValue = z.infer<typeof instanceStatusFieldValueSchema>
|
|
340
|
-
export type InstanceStatusField = z.infer<typeof instanceStatusFieldSchema>
|
|
341
|
-
export type UnitInstanceStatusField = z.infer<typeof unitInstanceStatusFieldSchema>
|
|
342
|
-
|
|
343
|
-
export type InstanceOperationStatus = z.infer<typeof instanceOperationStatusSchema>
|
|
344
|
-
export type InstanceOperataionStatusEnum = z.infer<typeof instanceOperationStatusEnumSchema>
|
|
345
|
-
|
|
346
|
-
export type InstanceEvaluationStatus = z.infer<typeof instanceEvaluationStatusSchema>
|
|
347
|
-
export type InstanceEvaluationStatusEnum = z.infer<typeof instanceEvaludationStatusEnumSchema>
|
|
348
|
-
|
|
349
|
-
export type InstanceCustomStatus = z.infer<typeof instanceCustomStatusSchema>
|
|
350
|
-
|
|
351
|
-
export type InstanceState = z.infer<typeof instanceStateSchema>
|
|
352
|
-
|
|
353
|
-
export type NullableRecord<T extends Record<string, any>> = {
|
|
354
|
-
[K in keyof T]: T[K] | null
|
|
74
|
+
/**
|
|
75
|
+
* Checks if the given instance state represents a "virtual ghost" instance.
|
|
76
|
+
*
|
|
77
|
+
* Note: The evaluation state must be loaded, otherwise this function will always return true.
|
|
78
|
+
*
|
|
79
|
+
* @param state The instance state to check.
|
|
80
|
+
* @returns True if the instance is a virtual ghost, false otherwise.
|
|
81
|
+
*/
|
|
82
|
+
export function isVirtualGhostInstance(
|
|
83
|
+
state: Pick<InstanceState, "status" | "source" | "evaluationState">,
|
|
84
|
+
): boolean {
|
|
85
|
+
if (state.source !== "virtual") return false
|
|
86
|
+
if (state.status === "undeployed") return false
|
|
87
|
+
|
|
88
|
+
return !state.evaluationState
|
|
355
89
|
}
|
|
356
90
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
export const instanceStatePatchSchema = z.object({
|
|
369
|
-
id: z.string(),
|
|
370
|
-
parentId: z.string().nullish(),
|
|
371
|
-
secretNames: z.array(z.string()).nullish(),
|
|
372
|
-
operationStatus: instanceOperationStatusSchema.partial().nullish(),
|
|
373
|
-
evaluationStatus: instanceEvaluationStatusSchema.partial().nullish(),
|
|
374
|
-
extra: instanceStateExtraPath.nullish(),
|
|
375
|
-
})
|
|
376
|
-
|
|
377
|
-
export type InstanceStatePatch = z.infer<typeof instanceStatePatchSchema>
|
|
378
|
-
|
|
379
|
-
export function applyStatePatch(
|
|
380
|
-
existingState: InstanceState | null | undefined,
|
|
381
|
-
patch: InstanceStatePatch,
|
|
382
|
-
): InstanceState {
|
|
383
|
-
const state: any = existingState ? { ...existingState } : { id: patch.id }
|
|
384
|
-
|
|
385
|
-
const anyPatch = patch as any
|
|
386
|
-
|
|
387
|
-
// merge the patch with the existing state with 2-level deep merge
|
|
388
|
-
// (merge objects nested in the state, but replace objects inside these nested objects)
|
|
389
|
-
for (const key of Object.keys(patch)) {
|
|
390
|
-
if (typeof anyPatch[key] === "undefined") {
|
|
391
|
-
// ignore undefined values
|
|
392
|
-
continue
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
if (
|
|
396
|
-
typeof anyPatch[key] !== "object" ||
|
|
397
|
-
anyPatch[key] === null ||
|
|
398
|
-
Array.isArray(anyPatch[key])
|
|
399
|
-
) {
|
|
400
|
-
// if the value is not an object, just replace it
|
|
401
|
-
// transform null to undefined
|
|
402
|
-
state[key] = anyPatch[key] === null ? undefined : anyPatch[key]
|
|
403
|
-
continue
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
// if the value is an object, merge it with the existing state
|
|
407
|
-
const existingValue = state[key] ? { ...state[key] } : {}
|
|
408
|
-
|
|
409
|
-
for (const subKey of Object.keys(anyPatch[key])) {
|
|
410
|
-
existingValue[subKey] = anyPatch[key][subKey]
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
state[key] = existingValue
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
return state as InstanceState
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
export function isStateEmpty(state: InstanceState): boolean {
|
|
420
|
-
return (
|
|
421
|
-
!state.operationStatus &&
|
|
422
|
-
!state.evaluationStatus &&
|
|
423
|
-
(!state.extra || Object.keys(state.extra).length === 0) &&
|
|
424
|
-
(!state.secretNames || state.secretNames.length === 0)
|
|
425
|
-
)
|
|
91
|
+
/**
|
|
92
|
+
* Checks if the given instance state represents a deployed instance.
|
|
93
|
+
*
|
|
94
|
+
* An instance is considered deployed if the state exists and its status is not "undeployed".
|
|
95
|
+
*
|
|
96
|
+
* @param state The instance state to check (can be undefined).
|
|
97
|
+
* @returns True if the instance is deployed, false otherwise.
|
|
98
|
+
*/
|
|
99
|
+
export function isInstanceDeployed(state: InstanceState | undefined): boolean {
|
|
100
|
+
return !!state && state.status !== "undeployed"
|
|
426
101
|
}
|
|
427
102
|
|
|
428
|
-
export
|
|
429
|
-
|
|
103
|
+
export type {
|
|
104
|
+
InstanceEvaluationState,
|
|
105
|
+
InstanceEvaluationStatus,
|
|
106
|
+
InstanceOperationState,
|
|
107
|
+
InstanceOperationStatus,
|
|
108
|
+
InstanceStatus,
|
|
109
|
+
} from "../../../database"
|
|
110
|
+
|
|
111
|
+
export const finalInstanceOperationStatuses: InstanceOperationStatus[] = [
|
|
112
|
+
"destroyed",
|
|
113
|
+
"updated",
|
|
114
|
+
"cancelled",
|
|
115
|
+
"destroyed",
|
|
116
|
+
"failed",
|
|
117
|
+
"skipped",
|
|
118
|
+
]
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Checks if an instance operation status exists and is final transient (not stable).
|
|
122
|
+
*
|
|
123
|
+
* @param status The instance operation status to check
|
|
124
|
+
* @returns True if the status is transient
|
|
125
|
+
*/
|
|
126
|
+
export function isTransientInstanceOperationStatus(status?: InstanceOperationStatus): boolean {
|
|
127
|
+
return !!status && !finalInstanceOperationStatuses.includes(status)
|
|
430
128
|
}
|
|
431
129
|
|
|
432
|
-
export
|
|
433
|
-
return status === "created" || status === "error"
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
export const instanceStateEventSchema = z.discriminatedUnion("type", [
|
|
437
|
-
z.object({
|
|
438
|
-
type: z.literal("patched"),
|
|
439
|
-
patch: instanceStatePatchSchema,
|
|
440
|
-
}),
|
|
130
|
+
export const workerUnitRegistrationEventSchema = z.discriminatedUnion("type", [
|
|
441
131
|
z.object({
|
|
442
|
-
type: z.literal("
|
|
443
|
-
|
|
132
|
+
type: z.literal("registered"),
|
|
133
|
+
instanceId: z.string(),
|
|
134
|
+
params: z.record(z.string(), z.unknown()),
|
|
444
135
|
}),
|
|
445
136
|
z.object({
|
|
446
|
-
type: z.literal("
|
|
137
|
+
type: z.literal("deregistered"),
|
|
447
138
|
instanceId: z.string(),
|
|
448
139
|
}),
|
|
449
140
|
])
|
|
141
|
+
|
|
142
|
+
export type WorkerUnitRegistrationEvent = z.infer<typeof workerUnitRegistrationEventSchema>
|