@highstate/backend 0.6.2 → 0.7.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.
@@ -0,0 +1,22 @@
1
+ import { workerData, parentPort } from 'node:worker_threads';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { dirname } from 'node:path';
4
+ import pino from 'pino';
5
+ import { resolve } from 'import-meta-resolve';
6
+ import { readPackageJSON } from 'pkg-types';
7
+
8
+ const { source, logLevel } = workerData;
9
+ const logger = pino({ name: "source-resolution-worker", level: logLevel ?? "silent" });
10
+ const fullPath = source.path ? `${source.package}/${source.path}` : source.package;
11
+ const url = resolve(fullPath, import.meta.url);
12
+ const path = fileURLToPath(url);
13
+ const projectPath = dirname(path);
14
+ logger.info("source path resolved", { url, path, projectPath });
15
+ const packageJson = await readPackageJSON(projectPath);
16
+ const allowedDependencies = Object.keys(packageJson.peerDependencies ?? {});
17
+ logger.info("package.json read", { packageJson, allowedDependencies });
18
+ parentPort.postMessage({
19
+ type: "result",
20
+ projectPath,
21
+ allowedDependencies
22
+ });
@@ -1,5 +1,5 @@
1
- import { H as HubModel, b as InstanceState } from '../terminal-NNJYvGqi.js';
2
- export { C as CompositeInstance, a as HubModelPatch, J as InstanceFileMeta, I as InstanceModelPatch, e as InstancePageBlock, G as InstancePageMeta, d as InstanceStatePatch, c as InstanceStatus, F as InstanceStatusField, f as InstanceTerminal, L as InstanceTrigger, M as InstanceTriggerInvocation, K as InstanceTriggerSpec, X as OperationStatus, W as OperationType, P as ProjectOperation, g as ProjectOperationRequest, T as TerminalSession, O as applyPartialInstanceState, l as compositeInstanceSchema, N as createInstanceState, Q as createInstanceStateFrontendPatch, h as hubInstanceInputSchema, m as hubModelPatchSchema, n as hubModelSchema, r as instanceFileMetaSchema, s as instanceFileSchema, i as instanceInputSchema, j as instanceModelPatchSchema, k as instanceModelSchema, t as instancePageBlockSchema, u as instancePageMetaSchema, v as instancePageSchema, E as instanceStatePatchSchema, D as instanceStateSchema, q as instanceStatusFieldSchema, o as instanceStatusSchema, x as instanceTerminalFileSchema, w as instanceTerminalMetaSchema, y as instanceTerminalSchema, B as instanceTriggerInvocationSchema, A as instanceTriggerSchema, z as instanceTriggerSpecSchema, Y as isFinalOperationStatus, S as operationStatusSchema, R as operationTypeSchema, p as positionSchema, V as projectOperationRequestSchema, U as projectOperationSchema, Z as terminalSessionSchema } from '../terminal-NNJYvGqi.js';
1
+ import { H as HubModel, b as InstanceState } from '../terminal-Cm2WqcyB.js';
2
+ export { C as CompositeInstance, a as HubModelPatch, J as InstanceFileMeta, I as InstanceModelPatch, e as InstancePageBlock, G as InstancePageMeta, d as InstanceStatePatch, c as InstanceStatus, F as InstanceStatusField, f as InstanceTerminal, L as InstanceTrigger, M as InstanceTriggerInvocation, K as InstanceTriggerSpec, $ as OperationOptions, _ as OperationStatus, Z as OperationType, P as ProjectOperation, g as ProjectOperationRequest, T as TerminalSession, O as applyPartialInstanceState, R as buildDependentInstanceStateMap, l as compositeInstanceSchema, N as createInstanceState, Q as createInstanceStateFrontendPatch, S as getAllDependentInstanceIds, h as hubInstanceInputSchema, m as hubModelPatchSchema, n as hubModelSchema, r as instanceFileMetaSchema, s as instanceFileSchema, i as instanceInputSchema, j as instanceModelPatchSchema, k as instanceModelSchema, t as instancePageBlockSchema, u as instancePageMetaSchema, v as instancePageSchema, E as instanceStatePatchSchema, D as instanceStateSchema, q as instanceStatusFieldSchema, o as instanceStatusSchema, x as instanceTerminalFileSchema, w as instanceTerminalMetaSchema, y as instanceTerminalSchema, B as instanceTriggerInvocationSchema, A as instanceTriggerSchema, z as instanceTriggerSpecSchema, a0 as isFinalOperationStatus, W as operationOptionsSchema, V as operationStatusSchema, U as operationTypeSchema, p as positionSchema, X as projectOperationRequestSchema, Y as projectOperationSchema, a1 as terminalSessionSchema } from '../terminal-Cm2WqcyB.js';
3
3
  import { Logger } from 'pino';
4
4
  import { InstanceModel, ComponentModel, InstanceInput } from '@highstate/contract';
5
5
  import 'zod';
@@ -1,5 +1,5 @@
1
- import { q as defineGraphResolver } from '../terminal-C4MfopTF.mjs';
2
- export { J as CircularDependencyError, n as applyPartialInstanceState, k as compositeInstanceSchema, K as createDefaultGraphResolverBackend, a as createInputHashResolver, c as createInputResolver, b as createInstanceState, o as createInstanceStateFrontendPatch, O as getMatchedInjectionInstanceInputs, L as getResolvedHubInputs, N as getResolvedInjectionInstanceInputs, M as getResolvedInstanceInputs, u as hubInstanceInputSchema, w as hubModelPatchSchema, h as hubModelSchema, y as instanceFileMetaSchema, f as instanceFileSchema, s as instanceInputSchema, v as instanceModelPatchSchema, i as instanceModelSchema, z as instancePageBlockSchema, A as instancePageMetaSchema, e as instancePageSchema, F as instanceStatePatchSchema, l as instanceStateSchema, g as instanceStatusFieldSchema, x as instanceStatusSchema, C as instanceTerminalFileSchema, B as instanceTerminalMetaSchema, d as instanceTerminalSchema, E as instanceTriggerInvocationSchema, j as instanceTriggerSchema, D as instanceTriggerSpecSchema, m as isFinalOperationStatus, H as operationStatusSchema, G as operationTypeSchema, r as positionSchema, I as projectOperationRequestSchema, p as projectOperationSchema, t as terminalSessionSchema } from '../terminal-C4MfopTF.mjs';
1
+ import { q as defineGraphResolver } from '../terminal-CqIsctlZ.mjs';
2
+ export { M as CircularDependencyError, o as applyPartialInstanceState, G as buildDependentInstanceStateMap, k as compositeInstanceSchema, N as createDefaultGraphResolverBackend, a as createInputHashResolver, c as createInputResolver, b as createInstanceState, n as createInstanceStateFrontendPatch, H as getAllDependentInstanceIds, R as getMatchedInjectionInstanceInputs, O as getResolvedHubInputs, Q as getResolvedInjectionInstanceInputs, P as getResolvedInstanceInputs, u as hubInstanceInputSchema, w as hubModelPatchSchema, h as hubModelSchema, y as instanceFileMetaSchema, f as instanceFileSchema, s as instanceInputSchema, v as instanceModelPatchSchema, i as instanceModelSchema, z as instancePageBlockSchema, A as instancePageMetaSchema, e as instancePageSchema, F as instanceStatePatchSchema, l as instanceStateSchema, g as instanceStatusFieldSchema, x as instanceStatusSchema, C as instanceTerminalFileSchema, B as instanceTerminalMetaSchema, d as instanceTerminalSchema, E as instanceTriggerInvocationSchema, j as instanceTriggerSchema, D as instanceTriggerSpecSchema, m as isFinalOperationStatus, K as operationOptionsSchema, J as operationStatusSchema, I as operationTypeSchema, r as positionSchema, L as projectOperationRequestSchema, p as projectOperationSchema, t as terminalSessionSchema } from '../terminal-CqIsctlZ.mjs';
3
3
  import { Ajv } from 'ajv';
4
4
  import 'zod';
5
5
  import 'remeda';
@@ -611,7 +611,7 @@ type CompositeInstance = z.infer<typeof compositeInstanceSchema>;
611
611
  type HubModel = z.infer<typeof hubModelSchema>;
612
612
  type HubModelPatch = z.infer<typeof hubModelPatchSchema>;
613
613
 
614
- declare const instanceStatusSchema: z.ZodEnum<["not_created", "updating", "destroying", "refreshing", "created", "error", "pending", "unknown"]>;
614
+ declare const instanceStatusSchema: z.ZodEnum<["not_created", "updating", "previewing", "destroying", "refreshing", "created", "error", "pending", "unknown"]>;
615
615
  declare const instanceStatusFieldSchema: z.ZodObject<{
616
616
  name: z.ZodString;
617
617
  value: z.ZodOptional<z.ZodString>;
@@ -961,7 +961,8 @@ declare const instanceTriggerInvocationSchema: z.ZodObject<{
961
961
  declare const instanceStateSchema: z.ZodObject<{
962
962
  id: z.ZodString;
963
963
  parentId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
964
- status: z.ZodEnum<["not_created", "updating", "destroying", "refreshing", "created", "error", "pending", "unknown"]>;
964
+ status: z.ZodEnum<["not_created", "updating", "previewing", "destroying", "refreshing", "created", "error", "pending", "unknown"]>;
965
+ dependencyIds: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
965
966
  latestOperationId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
966
967
  currentResourceCount: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
967
968
  totalResourceCount: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
@@ -1066,7 +1067,7 @@ declare const instanceStateSchema: z.ZodObject<{
1066
1067
  }>, "many">>;
1067
1068
  }, "strip", z.ZodTypeAny, {
1068
1069
  error: string | null;
1069
- status: "error" | "unknown" | "not_created" | "updating" | "destroying" | "refreshing" | "created" | "pending";
1070
+ status: "error" | "unknown" | "not_created" | "updating" | "previewing" | "destroying" | "refreshing" | "created" | "pending";
1070
1071
  id: string;
1071
1072
  parentId: string | null;
1072
1073
  files: {
@@ -1074,6 +1075,7 @@ declare const instanceStateSchema: z.ZodObject<{
1074
1075
  contentType: string;
1075
1076
  isBinary?: boolean | undefined;
1076
1077
  }[];
1078
+ dependencyIds: string[];
1077
1079
  latestOperationId: string | null;
1078
1080
  currentResourceCount: number | null;
1079
1081
  totalResourceCount: number | null;
@@ -1107,7 +1109,7 @@ declare const instanceStateSchema: z.ZodObject<{
1107
1109
  description?: string | undefined;
1108
1110
  }[];
1109
1111
  }, {
1110
- status: "error" | "unknown" | "not_created" | "updating" | "destroying" | "refreshing" | "created" | "pending";
1112
+ status: "error" | "unknown" | "not_created" | "updating" | "previewing" | "destroying" | "refreshing" | "created" | "pending";
1111
1113
  id: string;
1112
1114
  error?: string | null | undefined;
1113
1115
  parentId?: string | null | undefined;
@@ -1116,6 +1118,7 @@ declare const instanceStateSchema: z.ZodObject<{
1116
1118
  contentType: string;
1117
1119
  isBinary?: boolean | undefined;
1118
1120
  }[] | undefined;
1121
+ dependencyIds?: string[] | undefined;
1119
1122
  latestOperationId?: string | null | undefined;
1120
1123
  currentResourceCount?: number | null | undefined;
1121
1124
  totalResourceCount?: number | null | undefined;
@@ -1154,7 +1157,8 @@ declare const instanceStatePatchSchema: z.ZodObject<{
1154
1157
  logLine: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1155
1158
  id: z.ZodOptional<z.ZodString>;
1156
1159
  parentId: z.ZodOptional<z.ZodDefault<z.ZodNullable<z.ZodString>>>;
1157
- status: z.ZodOptional<z.ZodEnum<["not_created", "updating", "destroying", "refreshing", "created", "error", "pending", "unknown"]>>;
1160
+ status: z.ZodOptional<z.ZodEnum<["not_created", "updating", "previewing", "destroying", "refreshing", "created", "error", "pending", "unknown"]>>;
1161
+ dependencyIds: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString, "many">>>;
1158
1162
  latestOperationId: z.ZodOptional<z.ZodDefault<z.ZodNullable<z.ZodString>>>;
1159
1163
  currentResourceCount: z.ZodOptional<z.ZodDefault<z.ZodNullable<z.ZodNumber>>>;
1160
1164
  totalResourceCount: z.ZodOptional<z.ZodDefault<z.ZodNullable<z.ZodNumber>>>;
@@ -1259,7 +1263,7 @@ declare const instanceStatePatchSchema: z.ZodObject<{
1259
1263
  }>, "many">>>;
1260
1264
  }, "strip", z.ZodTypeAny, {
1261
1265
  error?: string | null | undefined;
1262
- status?: "error" | "unknown" | "not_created" | "updating" | "destroying" | "refreshing" | "created" | "pending" | undefined;
1266
+ status?: "error" | "unknown" | "not_created" | "updating" | "previewing" | "destroying" | "refreshing" | "created" | "pending" | undefined;
1263
1267
  id?: string | undefined;
1264
1268
  parentId?: string | null | undefined;
1265
1269
  files?: {
@@ -1267,6 +1271,7 @@ declare const instanceStatePatchSchema: z.ZodObject<{
1267
1271
  contentType: string;
1268
1272
  isBinary?: boolean | undefined;
1269
1273
  }[] | undefined;
1274
+ dependencyIds?: string[] | undefined;
1270
1275
  latestOperationId?: string | null | undefined;
1271
1276
  currentResourceCount?: number | null | undefined;
1272
1277
  totalResourceCount?: number | null | undefined;
@@ -1303,7 +1308,7 @@ declare const instanceStatePatchSchema: z.ZodObject<{
1303
1308
  logLine?: string | null | undefined;
1304
1309
  }, {
1305
1310
  error?: string | null | undefined;
1306
- status?: "error" | "unknown" | "not_created" | "updating" | "destroying" | "refreshing" | "created" | "pending" | undefined;
1311
+ status?: "error" | "unknown" | "not_created" | "updating" | "previewing" | "destroying" | "refreshing" | "created" | "pending" | undefined;
1307
1312
  id?: string | undefined;
1308
1313
  parentId?: string | null | undefined;
1309
1314
  files?: {
@@ -1311,6 +1316,7 @@ declare const instanceStatePatchSchema: z.ZodObject<{
1311
1316
  contentType: string;
1312
1317
  isBinary?: boolean | undefined;
1313
1318
  }[] | undefined;
1319
+ dependencyIds?: string[] | undefined;
1314
1320
  latestOperationId?: string | null | undefined;
1315
1321
  currentResourceCount?: number | null | undefined;
1316
1322
  totalResourceCount?: number | null | undefined;
@@ -1360,54 +1366,212 @@ type InstanceTriggerInvocation = z.infer<typeof instanceTriggerInvocationSchema>
1360
1366
  declare function createInstanceState(id: string, status?: InstanceStatus, fields?: Partial<InstanceState>): InstanceState;
1361
1367
  declare function applyPartialInstanceState(states: Map<string, InstanceState>, patch: Partial<InstanceState>): InstanceState;
1362
1368
  declare function createInstanceStateFrontendPatch(patch: InstanceStatePatch): Partial<InstanceState>;
1369
+ /**
1370
+ * Builds a map where instance id -> instance state ids that directly depend on the instance.
1371
+ *
1372
+ * @param instanceStates The instance states to build the map from.
1373
+ */
1374
+ declare function buildDependentInstanceStateMap(instanceStates: Map<string, InstanceState>): Map<string, string[]>;
1375
+ /**
1376
+ * Gets all instance ids that depend on the given instance id (including recursively).
1377
+ * The instance id itself is not included in the result.
1378
+ *
1379
+ * @param dependentMap The dependent map.
1380
+ * @param instanceId The instance id to get all dependent instance ids.
1381
+ */
1382
+ declare function getAllDependentInstanceIds(dependentMap: Map<string, string[]>, instanceId: string): string[];
1363
1383
 
1364
- declare const operationTypeSchema: z.ZodEnum<["update", "destroy", "recreate", "refresh", "evaluate"]>;
1384
+ declare const operationTypeSchema: z.ZodEnum<["update", "preview", "destroy", "recreate", "refresh", "evaluate"]>;
1365
1385
  declare const operationStatusSchema: z.ZodEnum<["pending", "evaluating", "running", "completed", "failed", "cancelled"]>;
1386
+ declare const operationOptionsSchema: z.ZodObject<{
1387
+ /**
1388
+ * Whether to force update all dependencies of the instances even if they are not changed.
1389
+ *
1390
+ * Only applicable for `update`, `preview`, `recreate`, and `refresh` operations.
1391
+ * By default, `false`.
1392
+ */
1393
+ forceUpdateDependencies: z.ZodDefault<z.ZodBoolean>;
1394
+ /**
1395
+ * Whether to destroy all dependents of the instances when destroying them.
1396
+ *
1397
+ * Only applicable for `destroy`.
1398
+ * By default, `true`.
1399
+ */
1400
+ destroyDependentInstances: z.ZodDefault<z.ZodBoolean>;
1401
+ /**
1402
+ * Whether to invoke destroy triggers when destroying the instances.
1403
+ *
1404
+ * Only applicable for `destroy`.
1405
+ * By default, `true`.
1406
+ */
1407
+ invokeDestroyTriggers: z.ZodDefault<z.ZodBoolean>;
1408
+ /**
1409
+ * Whether to delete unreachable resources when updating or destroying the instances.
1410
+ * This is potentially dangerous and should be used with caution.
1411
+ *
1412
+ * By default, `false`.
1413
+ */
1414
+ deleteUnreachableResources: z.ZodDefault<z.ZodBoolean>;
1415
+ /**
1416
+ * Whether to refresh the state before running the operation.
1417
+ *
1418
+ * By default, `false`.
1419
+ */
1420
+ refresh: z.ZodDefault<z.ZodBoolean>;
1421
+ }, "strip", z.ZodTypeAny, {
1422
+ refresh: boolean;
1423
+ forceUpdateDependencies: boolean;
1424
+ destroyDependentInstances: boolean;
1425
+ invokeDestroyTriggers: boolean;
1426
+ deleteUnreachableResources: boolean;
1427
+ }, {
1428
+ refresh?: boolean | undefined;
1429
+ forceUpdateDependencies?: boolean | undefined;
1430
+ destroyDependentInstances?: boolean | undefined;
1431
+ invokeDestroyTriggers?: boolean | undefined;
1432
+ deleteUnreachableResources?: boolean | undefined;
1433
+ }>;
1434
+ declare const projectOperationRequestSchema: z.ZodObject<{
1435
+ projectId: z.ZodString;
1436
+ type: z.ZodEnum<["update", "preview", "destroy", "recreate", "refresh", "evaluate"]>;
1437
+ instanceIds: z.ZodArray<z.ZodString, "many">;
1438
+ options: z.ZodOptional<z.ZodObject<{
1439
+ forceUpdateDependencies: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
1440
+ destroyDependentInstances: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
1441
+ invokeDestroyTriggers: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
1442
+ deleteUnreachableResources: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
1443
+ refresh: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
1444
+ }, "strip", z.ZodTypeAny, {
1445
+ refresh?: boolean | undefined;
1446
+ forceUpdateDependencies?: boolean | undefined;
1447
+ destroyDependentInstances?: boolean | undefined;
1448
+ invokeDestroyTriggers?: boolean | undefined;
1449
+ deleteUnreachableResources?: boolean | undefined;
1450
+ }, {
1451
+ refresh?: boolean | undefined;
1452
+ forceUpdateDependencies?: boolean | undefined;
1453
+ destroyDependentInstances?: boolean | undefined;
1454
+ invokeDestroyTriggers?: boolean | undefined;
1455
+ deleteUnreachableResources?: boolean | undefined;
1456
+ }>>;
1457
+ }, "strip", z.ZodTypeAny, {
1458
+ projectId: string;
1459
+ type: "update" | "refresh" | "preview" | "destroy" | "recreate" | "evaluate";
1460
+ instanceIds: string[];
1461
+ options?: {
1462
+ refresh?: boolean | undefined;
1463
+ forceUpdateDependencies?: boolean | undefined;
1464
+ destroyDependentInstances?: boolean | undefined;
1465
+ invokeDestroyTriggers?: boolean | undefined;
1466
+ deleteUnreachableResources?: boolean | undefined;
1467
+ } | undefined;
1468
+ }, {
1469
+ projectId: string;
1470
+ type: "update" | "refresh" | "preview" | "destroy" | "recreate" | "evaluate";
1471
+ instanceIds: string[];
1472
+ options?: {
1473
+ refresh?: boolean | undefined;
1474
+ forceUpdateDependencies?: boolean | undefined;
1475
+ destroyDependentInstances?: boolean | undefined;
1476
+ invokeDestroyTriggers?: boolean | undefined;
1477
+ deleteUnreachableResources?: boolean | undefined;
1478
+ } | undefined;
1479
+ }>;
1366
1480
  declare const projectOperationSchema: z.ZodObject<{
1367
1481
  id: z.ZodString;
1368
- projectId: z.ZodString;
1369
- type: z.ZodEnum<["update", "destroy", "recreate", "refresh", "evaluate"]>;
1370
1482
  status: z.ZodEnum<["pending", "evaluating", "running", "completed", "failed", "cancelled"]>;
1483
+ projectId: z.ZodString;
1484
+ type: z.ZodEnum<["update", "preview", "destroy", "recreate", "refresh", "evaluate"]>;
1371
1485
  instanceIds: z.ZodArray<z.ZodString, "many">;
1486
+ options: z.ZodDefault<z.ZodObject<{
1487
+ /**
1488
+ * Whether to force update all dependencies of the instances even if they are not changed.
1489
+ *
1490
+ * Only applicable for `update`, `preview`, `recreate`, and `refresh` operations.
1491
+ * By default, `false`.
1492
+ */
1493
+ forceUpdateDependencies: z.ZodDefault<z.ZodBoolean>;
1494
+ /**
1495
+ * Whether to destroy all dependents of the instances when destroying them.
1496
+ *
1497
+ * Only applicable for `destroy`.
1498
+ * By default, `true`.
1499
+ */
1500
+ destroyDependentInstances: z.ZodDefault<z.ZodBoolean>;
1501
+ /**
1502
+ * Whether to invoke destroy triggers when destroying the instances.
1503
+ *
1504
+ * Only applicable for `destroy`.
1505
+ * By default, `true`.
1506
+ */
1507
+ invokeDestroyTriggers: z.ZodDefault<z.ZodBoolean>;
1508
+ /**
1509
+ * Whether to delete unreachable resources when updating or destroying the instances.
1510
+ * This is potentially dangerous and should be used with caution.
1511
+ *
1512
+ * By default, `false`.
1513
+ */
1514
+ deleteUnreachableResources: z.ZodDefault<z.ZodBoolean>;
1515
+ /**
1516
+ * Whether to refresh the state before running the operation.
1517
+ *
1518
+ * By default, `false`.
1519
+ */
1520
+ refresh: z.ZodDefault<z.ZodBoolean>;
1521
+ }, "strip", z.ZodTypeAny, {
1522
+ refresh: boolean;
1523
+ forceUpdateDependencies: boolean;
1524
+ destroyDependentInstances: boolean;
1525
+ invokeDestroyTriggers: boolean;
1526
+ deleteUnreachableResources: boolean;
1527
+ }, {
1528
+ refresh?: boolean | undefined;
1529
+ forceUpdateDependencies?: boolean | undefined;
1530
+ destroyDependentInstances?: boolean | undefined;
1531
+ invokeDestroyTriggers?: boolean | undefined;
1532
+ deleteUnreachableResources?: boolean | undefined;
1533
+ }>>;
1372
1534
  error: z.ZodNullable<z.ZodString>;
1373
1535
  startedAt: z.ZodNumber;
1374
1536
  completedAt: z.ZodNullable<z.ZodNumber>;
1375
1537
  }, "strip", z.ZodTypeAny, {
1376
1538
  error: string | null;
1377
- type: "update" | "refresh" | "destroy" | "recreate" | "evaluate";
1378
- status: "pending" | "evaluating" | "running" | "completed" | "failed" | "cancelled";
1379
1539
  projectId: string;
1540
+ options: {
1541
+ refresh: boolean;
1542
+ forceUpdateDependencies: boolean;
1543
+ destroyDependentInstances: boolean;
1544
+ invokeDestroyTriggers: boolean;
1545
+ deleteUnreachableResources: boolean;
1546
+ };
1547
+ type: "update" | "refresh" | "preview" | "destroy" | "recreate" | "evaluate";
1548
+ status: "pending" | "evaluating" | "running" | "completed" | "failed" | "cancelled";
1380
1549
  instanceIds: string[];
1381
1550
  id: string;
1382
1551
  startedAt: number;
1383
1552
  completedAt: number | null;
1384
1553
  }, {
1385
1554
  error: string | null;
1386
- type: "update" | "refresh" | "destroy" | "recreate" | "evaluate";
1387
- status: "pending" | "evaluating" | "running" | "completed" | "failed" | "cancelled";
1388
1555
  projectId: string;
1556
+ type: "update" | "refresh" | "preview" | "destroy" | "recreate" | "evaluate";
1557
+ status: "pending" | "evaluating" | "running" | "completed" | "failed" | "cancelled";
1389
1558
  instanceIds: string[];
1390
1559
  id: string;
1391
1560
  startedAt: number;
1392
1561
  completedAt: number | null;
1393
- }>;
1394
- declare const projectOperationRequestSchema: z.ZodObject<{
1395
- projectId: z.ZodString;
1396
- type: z.ZodEnum<["update", "destroy", "recreate", "refresh", "evaluate"]>;
1397
- instanceIds: z.ZodArray<z.ZodString, "many">;
1398
- }, "strip", z.ZodTypeAny, {
1399
- type: "update" | "refresh" | "destroy" | "recreate" | "evaluate";
1400
- projectId: string;
1401
- instanceIds: string[];
1402
- }, {
1403
- type: "update" | "refresh" | "destroy" | "recreate" | "evaluate";
1404
- projectId: string;
1405
- instanceIds: string[];
1562
+ options?: {
1563
+ refresh?: boolean | undefined;
1564
+ forceUpdateDependencies?: boolean | undefined;
1565
+ destroyDependentInstances?: boolean | undefined;
1566
+ invokeDestroyTriggers?: boolean | undefined;
1567
+ deleteUnreachableResources?: boolean | undefined;
1568
+ } | undefined;
1406
1569
  }>;
1407
1570
  type OperationType = z.infer<typeof operationTypeSchema>;
1408
1571
  type OperationStatus = z.infer<typeof operationStatusSchema>;
1409
1572
  type ProjectOperation = z.infer<typeof projectOperationSchema>;
1410
1573
  type ProjectOperationRequest = z.infer<typeof projectOperationRequestSchema>;
1574
+ type OperationOptions = z.infer<typeof operationOptionsSchema>;
1411
1575
  declare function isFinalOperationStatus(status: OperationStatus): boolean;
1412
1576
 
1413
1577
  declare const terminalSessionSchema: z.ZodObject<{
@@ -1422,4 +1586,4 @@ declare const terminalSessionSchema: z.ZodObject<{
1422
1586
  }>;
1423
1587
  type TerminalSession = z.infer<typeof terminalSessionSchema>;
1424
1588
 
1425
- export { instanceTriggerSchema as A, instanceTriggerInvocationSchema as B, type CompositeInstance as C, instanceStateSchema as D, instanceStatePatchSchema as E, type InstanceStatusField as F, type InstancePageMeta as G, type HubModel as H, type InstanceModelPatch as I, type InstanceFileMeta as J, type InstanceTriggerSpec as K, type InstanceTrigger as L, type InstanceTriggerInvocation as M, createInstanceState as N, applyPartialInstanceState as O, type ProjectOperation as P, createInstanceStateFrontendPatch as Q, operationTypeSchema as R, operationStatusSchema as S, type TerminalSession as T, projectOperationSchema as U, projectOperationRequestSchema as V, type OperationType as W, type OperationStatus as X, isFinalOperationStatus as Y, terminalSessionSchema as Z, type HubModelPatch as a, type InstanceState as b, type InstanceStatus as c, type InstanceStatePatch as d, type InstancePageBlock as e, type InstanceTerminal as f, type ProjectOperationRequest as g, hubInstanceInputSchema as h, instanceInputSchema as i, instanceModelPatchSchema as j, instanceModelSchema as k, compositeInstanceSchema as l, hubModelPatchSchema as m, hubModelSchema as n, instanceStatusSchema as o, positionSchema as p, instanceStatusFieldSchema as q, instanceFileMetaSchema as r, instanceFileSchema as s, instancePageBlockSchema as t, instancePageMetaSchema as u, instancePageSchema as v, instanceTerminalMetaSchema as w, instanceTerminalFileSchema as x, instanceTerminalSchema as y, instanceTriggerSpecSchema as z };
1589
+ export { type OperationOptions as $, instanceTriggerSchema as A, instanceTriggerInvocationSchema as B, type CompositeInstance as C, instanceStateSchema as D, instanceStatePatchSchema as E, type InstanceStatusField as F, type InstancePageMeta as G, type HubModel as H, type InstanceModelPatch as I, type InstanceFileMeta as J, type InstanceTriggerSpec as K, type InstanceTrigger as L, type InstanceTriggerInvocation as M, createInstanceState as N, applyPartialInstanceState as O, type ProjectOperation as P, createInstanceStateFrontendPatch as Q, buildDependentInstanceStateMap as R, getAllDependentInstanceIds as S, type TerminalSession as T, operationTypeSchema as U, operationStatusSchema as V, operationOptionsSchema as W, projectOperationRequestSchema as X, projectOperationSchema as Y, type OperationType as Z, type OperationStatus as _, type HubModelPatch as a, isFinalOperationStatus as a0, terminalSessionSchema as a1, type InstanceState as b, type InstanceStatus as c, type InstanceStatePatch as d, type InstancePageBlock as e, type InstanceTerminal as f, type ProjectOperationRequest as g, hubInstanceInputSchema as h, instanceInputSchema as i, instanceModelPatchSchema as j, instanceModelSchema as k, compositeInstanceSchema as l, hubModelPatchSchema as m, hubModelSchema as n, instanceStatusSchema as o, positionSchema as p, instanceStatusFieldSchema as q, instanceFileMetaSchema as r, instanceFileSchema as s, instancePageBlockSchema as t, instancePageMetaSchema as u, instancePageSchema as v, instanceTerminalMetaSchema as w, instanceTerminalFileSchema as x, instanceTerminalSchema as y, instanceTriggerSpecSchema as z };
@@ -47,6 +47,7 @@ const hubModelSchema = z.object({
47
47
  const instanceStatusSchema = z.enum([
48
48
  "not_created",
49
49
  "updating",
50
+ "previewing",
50
51
  "destroying",
51
52
  "refreshing",
52
53
  "created",
@@ -134,6 +135,7 @@ const instanceStateSchema = z.object({
134
135
  id: z.string(),
135
136
  parentId: z.string().nullable().default(null),
136
137
  status: instanceStatusSchema,
138
+ dependencyIds: z.array(z.string()).default(() => []),
137
139
  latestOperationId: z.string().nullable().default(null),
138
140
  currentResourceCount: z.number().nullable().default(null),
139
141
  totalResourceCount: z.number().nullable().default(null),
@@ -157,6 +159,7 @@ function createInstanceState(id, status = "not_created", fields = {}) {
157
159
  return {
158
160
  id,
159
161
  parentId: null,
162
+ dependencyIds: [],
160
163
  status,
161
164
  latestOperationId: null,
162
165
  currentResourceCount: null,
@@ -184,6 +187,9 @@ function applyPartialInstanceState(states, patch) {
184
187
  if (patch.status !== void 0) {
185
188
  state.status = patch.status;
186
189
  }
190
+ if (patch.dependencyIds !== void 0) {
191
+ state.dependencyIds = patch.dependencyIds;
192
+ }
187
193
  if (patch.latestOperationId !== void 0) {
188
194
  state.latestOperationId = patch.latestOperationId;
189
195
  }
@@ -222,8 +228,45 @@ function applyPartialInstanceState(states, patch) {
222
228
  function createInstanceStateFrontendPatch(patch) {
223
229
  return omit(patch, ["secrets", "logLine"]);
224
230
  }
231
+ function buildDependentInstanceStateMap(instanceStates) {
232
+ const dependentMap = /* @__PURE__ */ new Map();
233
+ for (const state of instanceStates.values()) {
234
+ for (const dependency of state.dependencyIds) {
235
+ let dependents = dependentMap.get(dependency);
236
+ if (!dependents) {
237
+ dependents = [];
238
+ dependentMap.set(dependency, dependents);
239
+ }
240
+ dependents.push(state.id);
241
+ }
242
+ }
243
+ return dependentMap;
244
+ }
245
+ function getAllDependentInstanceIds(dependentMap, instanceId) {
246
+ const result = /* @__PURE__ */ new Set();
247
+ const visited = /* @__PURE__ */ new Set();
248
+ const traverse = (id) => {
249
+ if (visited.has(id)) return;
250
+ visited.add(id);
251
+ const dependents = dependentMap.get(id);
252
+ if (!dependents) return;
253
+ for (const dependent of dependents) {
254
+ result.add(dependent);
255
+ traverse(dependent);
256
+ }
257
+ };
258
+ traverse(instanceId);
259
+ return Array.from(result);
260
+ }
225
261
 
226
- const operationTypeSchema = z.enum(["update", "destroy", "recreate", "refresh", "evaluate"]);
262
+ const operationTypeSchema = z.enum([
263
+ "update",
264
+ "preview",
265
+ "destroy",
266
+ "recreate",
267
+ "refresh",
268
+ "evaluate"
269
+ ]);
227
270
  const operationStatusSchema = z.enum([
228
271
  "pending",
229
272
  "evaluating",
@@ -232,21 +275,59 @@ const operationStatusSchema = z.enum([
232
275
  "failed",
233
276
  "cancelled"
234
277
  ]);
278
+ const operationOptionsSchema = z.object({
279
+ /**
280
+ * Whether to force update all dependencies of the instances even if they are not changed.
281
+ *
282
+ * Only applicable for `update`, `preview`, `recreate`, and `refresh` operations.
283
+ * By default, `false`.
284
+ */
285
+ forceUpdateDependencies: z.boolean().default(false),
286
+ /**
287
+ * Whether to destroy all dependents of the instances when destroying them.
288
+ *
289
+ * Only applicable for `destroy`.
290
+ * By default, `true`.
291
+ */
292
+ destroyDependentInstances: z.boolean().default(true),
293
+ /**
294
+ * Whether to invoke destroy triggers when destroying the instances.
295
+ *
296
+ * Only applicable for `destroy`.
297
+ * By default, `true`.
298
+ */
299
+ invokeDestroyTriggers: z.boolean().default(true),
300
+ /**
301
+ * Whether to delete unreachable resources when updating or destroying the instances.
302
+ * This is potentially dangerous and should be used with caution.
303
+ *
304
+ * By default, `false`.
305
+ */
306
+ deleteUnreachableResources: z.boolean().default(false),
307
+ /**
308
+ * Whether to refresh the state before running the operation.
309
+ *
310
+ * By default, `false`.
311
+ */
312
+ refresh: z.boolean().default(false)
313
+ });
314
+ const projectOperationRequestSchema = z.object({
315
+ projectId: z.string(),
316
+ type: operationTypeSchema,
317
+ instanceIds: z.array(z.string()),
318
+ options: operationOptionsSchema.partial().optional()
319
+ });
235
320
  const projectOperationSchema = z.object({
236
321
  id: z.string().uuid(),
322
+ status: operationStatusSchema,
237
323
  projectId: z.string(),
238
324
  type: operationTypeSchema,
239
- status: operationStatusSchema,
240
325
  instanceIds: z.array(z.string()),
326
+ options: operationOptionsSchema.default(() => ({})),
241
327
  error: z.string().nullable(),
242
328
  startedAt: z.number(),
243
329
  completedAt: z.number().nullable()
244
330
  });
245
- const projectOperationRequestSchema = z.object({
246
- projectId: z.string(),
247
- type: operationTypeSchema,
248
- instanceIds: z.array(z.string())
249
- });
250
331
  function isFinalOperationStatus(status) {
251
332
  return status === "completed" || status === "failed" || status === "cancelled";
252
333
  }
@@ -338,7 +419,7 @@ const createInputResolver = defineGraphResolver({
338
419
  const getHubOutput = (input) => {
339
420
  const output = dependencies.get(`hub:${input.hubId}`);
340
421
  if (!output) {
341
- throw new Error("Hub not found");
422
+ return { resolvedInputs: [] };
342
423
  }
343
424
  if (output.kind !== "hub") {
344
425
  throw new Error("Expected hub node");
@@ -348,7 +429,7 @@ const createInputResolver = defineGraphResolver({
348
429
  const getInstanceOutput = (input) => {
349
430
  const output = dependencies.get(`instance:${input.instanceId}`);
350
431
  if (!output) {
351
- throw new Error("Instance not found");
432
+ return { component: null };
352
433
  }
353
434
  if (output.kind !== "instance") {
354
435
  throw new Error("Expected instance node");
@@ -362,7 +443,7 @@ const createInputResolver = defineGraphResolver({
362
443
  };
363
444
  for (const input of node.hub.inputs ?? []) {
364
445
  const { component } = getInstanceOutput(input);
365
- const componentInput = component.outputs[input.output];
446
+ const componentInput = component?.outputs[input.output];
366
447
  if (!componentInput) {
367
448
  logger.warn({ msg: "output not found in the component", input, component });
368
449
  continue;
@@ -506,4 +587,4 @@ const terminalSessionSchema = z.object({
506
587
  terminalName: z.string()
507
588
  });
508
589
 
509
- export { instancePageMetaSchema as A, instanceTerminalMetaSchema as B, instanceTerminalFileSchema as C, instanceTriggerSpecSchema as D, instanceTriggerInvocationSchema as E, instanceStatePatchSchema as F, operationTypeSchema as G, operationStatusSchema as H, projectOperationRequestSchema as I, CircularDependencyError as J, createDefaultGraphResolverBackend as K, getResolvedHubInputs as L, getResolvedInstanceInputs as M, getResolvedInjectionInstanceInputs as N, getMatchedInjectionInstanceInputs as O, createInputHashResolver as a, createInstanceState as b, createInputResolver as c, instanceTerminalSchema as d, instancePageSchema as e, instanceFileSchema as f, instanceStatusFieldSchema as g, hubModelSchema as h, instanceModelSchema as i, instanceTriggerSchema as j, compositeInstanceSchema as k, instanceStateSchema as l, isFinalOperationStatus as m, applyPartialInstanceState as n, createInstanceStateFrontendPatch as o, projectOperationSchema as p, defineGraphResolver as q, positionSchema as r, instanceInputSchema as s, terminalSessionSchema as t, hubInstanceInputSchema as u, instanceModelPatchSchema as v, hubModelPatchSchema as w, instanceStatusSchema as x, instanceFileMetaSchema as y, instancePageBlockSchema as z };
590
+ export { instancePageMetaSchema as A, instanceTerminalMetaSchema as B, instanceTerminalFileSchema as C, instanceTriggerSpecSchema as D, instanceTriggerInvocationSchema as E, instanceStatePatchSchema as F, buildDependentInstanceStateMap as G, getAllDependentInstanceIds as H, operationTypeSchema as I, operationStatusSchema as J, operationOptionsSchema as K, projectOperationRequestSchema as L, CircularDependencyError as M, createDefaultGraphResolverBackend as N, getResolvedHubInputs as O, getResolvedInstanceInputs as P, getResolvedInjectionInstanceInputs as Q, getMatchedInjectionInstanceInputs as R, createInputHashResolver as a, createInstanceState as b, createInputResolver as c, instanceTerminalSchema as d, instancePageSchema as e, instanceFileSchema as f, instanceStatusFieldSchema as g, hubModelSchema as h, instanceModelSchema as i, instanceTriggerSchema as j, compositeInstanceSchema as k, instanceStateSchema as l, isFinalOperationStatus as m, createInstanceStateFrontendPatch as n, applyPartialInstanceState as o, projectOperationSchema as p, defineGraphResolver as q, positionSchema as r, instanceInputSchema as s, terminalSessionSchema as t, hubInstanceInputSchema as u, instanceModelPatchSchema as v, hubModelPatchSchema as w, instanceStatusSchema as x, instanceFileMetaSchema as y, instancePageBlockSchema as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@highstate/backend",
3
- "version": "0.6.2",
3
+ "version": "0.7.1",
4
4
  "type": "module",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -18,6 +18,9 @@
18
18
  },
19
19
  "./library-worker": {
20
20
  "default": "./dist/library/worker/main.mjs"
21
+ },
22
+ "./source-resolution-worker": {
23
+ "default": "./dist/runner/source-resolution-worker.mjs"
21
24
  }
22
25
  },
23
26
  "publishConfig": {
@@ -27,7 +30,7 @@
27
30
  "build": "pkgroll --tsconfig=tsconfig.build.json"
28
31
  },
29
32
  "dependencies": {
30
- "@highstate/contract": "^0.6.2",
33
+ "@highstate/contract": "^0.7.1",
31
34
  "@types/node": "^22.10.1",
32
35
  "ajv": "^8.17.1",
33
36
  "better-lock": "^3.2.0",
@@ -65,5 +68,5 @@
65
68
  "rollup": "^4.28.1",
66
69
  "typescript": "^5.7.2"
67
70
  },
68
- "gitHead": "dfd1d6878fc7d12954b6591d5ee1783d3c501eca"
71
+ "gitHead": "76c38ce5dbf7a710cf0e6339f52e86358537a99a"
69
72
  }