@revoengine/cli 1.0.21 → 1.0.22
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/README.md +15 -2
- package/dist/src/client.d.ts +23 -7
- package/dist/src/client.js +14 -0
- package/dist/src/commands/component.js +17 -0
- package/dist/src/commands/env.js +8 -5
- package/dist/src/commands/migrate.js +5 -1
- package/dist/src/commands/schedules.js +11 -9
- package/dist/src/component-contract.d.ts +8 -0
- package/dist/src/component-contract.js +68 -0
- package/dist/src/component-lock.d.ts +4 -2
- package/dist/src/component-lock.js +4 -2
- package/dist/src/database-indexes.d.ts +14 -0
- package/dist/src/database-indexes.js +124 -0
- package/dist/src/env-sync.d.ts +2 -0
- package/dist/src/env-sync.js +18 -2
- package/dist/src/migration-actions.js +1 -1
- package/dist/src/migration.js +3 -3
- package/dist/src/resource-syncs/agent-sync.js +28 -2
- package/dist/src/resource-syncs/database-table-sync.d.ts +3 -0
- package/dist/src/resource-syncs/database-table-sync.js +10 -6
- package/dist/src/resource-syncs/database-view-sync.d.ts +2 -4
- package/dist/src/resource-syncs/database-view-sync.js +16 -38
- package/dist/src/resource-syncs/endpoint-sync.js +53 -26
- package/dist/src/resource-syncs/job-template-sync.d.ts +1 -0
- package/dist/src/resource-syncs/job-template-sync.js +31 -10
- package/dist/src/resource-syncs/schedule-sync.d.ts +7 -3
- package/dist/src/resource-syncs/schedule-sync.js +85 -16
- package/dist/src/types.d.ts +2 -0
- package/dist/src/ui.js +1 -1
- package/package.json +2 -2
package/dist/src/env-sync.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { verifyComponentRuntime } from "./component-contract.js";
|
|
1
2
|
import { buildPortableComponentUpdatePayload, diffPortableComponentSource, hashPortableComponentSource, normalizePortableComponentSource, sanitizeComponentSource, } from "./component-lock.js";
|
|
2
3
|
import { buildStableKey as buildComponentStableKey, DEFAULT_STABLE_KEY_NAME, NULL_CATEGORY_KEY, sanitizeUserMetadata, } from "./resource-metadata.js";
|
|
3
4
|
import { mapWithConcurrency } from "./utils.js";
|
|
@@ -34,6 +35,14 @@ export async function captureEnvSnapshot(client, envName, options = {}) {
|
|
|
34
35
|
portable: normalizePortableComponentSource(component),
|
|
35
36
|
portableHash: hashPortableComponentSource(component),
|
|
36
37
|
};
|
|
38
|
+
if (component.type === 'CUSTOM_NODEJS') {
|
|
39
|
+
try {
|
|
40
|
+
await verifyComponentRuntime(client, component);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
entry.runtimeBlocker = error instanceof Error ? error.message : String(error);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
37
46
|
return entry;
|
|
38
47
|
});
|
|
39
48
|
for (const entry of entries) {
|
|
@@ -169,7 +178,8 @@ export function buildEnvSyncPlan(source, target, options) {
|
|
|
169
178
|
continue;
|
|
170
179
|
}
|
|
171
180
|
if (sourceEntry.portableHash === targetEntry.portableHash) {
|
|
172
|
-
items.push({ ...base, action: 'noop', reason: 'up to date'
|
|
181
|
+
items.push({ ...base, action: 'noop', reason: targetEntry.runtimeBlocker || 'up to date',
|
|
182
|
+
...(targetEntry.runtimeBlocker ? { blocked: true } : {}) });
|
|
173
183
|
continue;
|
|
174
184
|
}
|
|
175
185
|
const changedFields = diffPortableComponentSource(sourceEntry.component, targetEntry.component).configurationFields;
|
|
@@ -240,10 +250,16 @@ function buildCreatePayload(component) {
|
|
|
240
250
|
}
|
|
241
251
|
async function verifyAppliedComponent(targetClient, componentId, expectedHash) {
|
|
242
252
|
const component = unwrapComponent(await targetClient.getComponent(componentId));
|
|
243
|
-
|
|
253
|
+
if (hashPortableComponentSource(component) !== expectedHash)
|
|
254
|
+
return false;
|
|
255
|
+
await verifyComponentRuntime(targetClient, component, 120_000);
|
|
256
|
+
return true;
|
|
244
257
|
}
|
|
245
258
|
export async function applyEnvSyncPlan(input) {
|
|
246
259
|
const { targetClient, plan, source, target, stableKeyName, onItem } = input;
|
|
260
|
+
const blocked = plan.items.filter(item => item.blocked);
|
|
261
|
+
if (blocked.length)
|
|
262
|
+
throw new Error(`Cannot apply: ${blocked.length} component runtime(s) are not ready. ${blocked.map(item => item.reason).join(' ')}`);
|
|
247
263
|
const collisions = plan.items.filter((item) => item.action === 'collision');
|
|
248
264
|
if (collisions.length > 0) {
|
|
249
265
|
throw new Error(`Cannot apply: ${collisions.length} stable-key collision(s) in scope. Resolve duplicates or narrow the scope with --key/--category.`);
|
|
@@ -125,7 +125,7 @@ export function scheduleItemAction(item) {
|
|
|
125
125
|
if (item.status === 'missing-lock') {
|
|
126
126
|
return item.desiredHash === item.currentHash ? 'adopt' : 'update';
|
|
127
127
|
}
|
|
128
|
-
if (item.status === 'orphan' || item.status === 'skipped') {
|
|
128
|
+
if (item.status === 'orphan' || item.status === 'skipped' || item.status === 'activation-drift') {
|
|
129
129
|
return 'excluded';
|
|
130
130
|
}
|
|
131
131
|
return 'noop';
|
package/dist/src/migration.js
CHANGED
|
@@ -261,7 +261,7 @@ function summarizeSchedulePhase(plan) {
|
|
|
261
261
|
return {
|
|
262
262
|
order: 6,
|
|
263
263
|
resource: 'schedule',
|
|
264
|
-
needsChanges: operations.create + operations.update > 0,
|
|
264
|
+
needsChanges: operations.create + operations.update > 0 || plan.items.some((item) => item.status === 'activation-drift'),
|
|
265
265
|
readyToMigrate: blockers.length === 0,
|
|
266
266
|
verdict: phaseVerdict(blockers, warnings),
|
|
267
267
|
operations,
|
|
@@ -291,7 +291,7 @@ function summarizeEventPhase(plan) {
|
|
|
291
291
|
return {
|
|
292
292
|
order: 7,
|
|
293
293
|
resource: 'event',
|
|
294
|
-
needsChanges: operations.create + operations.update > 0,
|
|
294
|
+
needsChanges: operations.create + operations.update > 0 || plan.items.some(item => item.status === 'activation-drift'),
|
|
295
295
|
readyToMigrate: blockers.length === 0,
|
|
296
296
|
verdict: phaseVerdict(blockers, warnings),
|
|
297
297
|
operations,
|
|
@@ -1089,7 +1089,7 @@ async function planWorkspace(input) {
|
|
|
1089
1089
|
if (serviceAccounts && identities) {
|
|
1090
1090
|
serviceAccounts.blockers.push(...identities.blockers);
|
|
1091
1091
|
}
|
|
1092
|
-
const projected = { component: input.projectDependencies && components ? components.items.filter(item => !item.blocked).flatMap(item => item.stableKey ? [item.stableKey] : []) : [],
|
|
1092
|
+
const projected = { component: input.projectDependencies && components ? components.items.filter(item => !item.blocked && ['create', 'update'].includes(componentItemAction(item))).flatMap(item => item.stableKey ? [item.stableKey] : []) : [],
|
|
1093
1093
|
'service-account': identities?.projection.serviceAccounts || [], group: identities?.projection.groups || [] };
|
|
1094
1094
|
const agentPlugins = resources.includes('agent-plugin') ? await runMigrationStage('target plan', 'agent-plugin', environmentLabel, () => buildAgentsPlan({ client, cwd: input.cwd, envName: environmentKey, stableKeyName, family: 'agent-plugin', projected })) : undefined;
|
|
1095
1095
|
const agents = resources.includes('agent') ? await runMigrationStage('target plan', 'agent', environmentLabel, () => buildAgentsPlan({ client, cwd: input.cwd, envName: environmentKey, stableKeyName, family: 'agent', projected: { ...projected,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { componentRevisionByDigest, verifyComponentRuntime } from "../component-contract.js";
|
|
1
2
|
import fs from 'node:fs';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
import { hashStable, readComponentLock, writeComponentLock } from "../component-lock.js";
|
|
@@ -327,6 +328,8 @@ async function resolveKey(input, family, key, cache = new Map()) {
|
|
|
327
328
|
const matches = values.filter(value => active(value) && readConfiguredResourceMetadataStableKey(value, input.stableKeyName) === key);
|
|
328
329
|
if (matches.length !== 1)
|
|
329
330
|
throw new Error(`${family} "${key}" must resolve to exactly one active target resource.`);
|
|
331
|
+
if (family === 'component' && matches[0].active !== true)
|
|
332
|
+
throw new Error('Backing component must be active.');
|
|
330
333
|
if (family === 'service-account' && (matches[0].serviceAccount !== true || ![0, 'ACTIVE'].includes(matches[0].status)))
|
|
331
334
|
throw new Error('Agent execution Service Account must be active.');
|
|
332
335
|
return resourceIdOf(matches[0]);
|
|
@@ -364,7 +367,7 @@ async function pluginPayload(input, definition, current, cache = new Map()) {
|
|
|
364
367
|
async function writePayload(input, manifest, current) {
|
|
365
368
|
const cache = new Map();
|
|
366
369
|
if (manifest.kind === 'agent-plugin')
|
|
367
|
-
return { ...await pluginPayload(input, manifest.definition, isRecord(current?.config) ? current.config : undefined, cache), metadata: manifest.metadata };
|
|
370
|
+
return { ...await pluginPayload(input, manifest.definition, isRecord(current?.config) ? current.config : undefined, cache), category: manifest.definition.category ?? null, metadata: manifest.metadata };
|
|
368
371
|
if (manifest.executionPrincipal?.kind === 'service-account') {
|
|
369
372
|
const id = await resolveKey(input, 'service-account', manifest.executionPrincipal.stableKey, cache);
|
|
370
373
|
if ((await input.client.getServiceAccount(id)).platformAccess !== true)
|
|
@@ -394,6 +397,27 @@ async function writePayload(input, manifest, current) {
|
|
|
394
397
|
}
|
|
395
398
|
return result;
|
|
396
399
|
}
|
|
400
|
+
async function verifyPluginComponents(input, manifest, cache, projected) {
|
|
401
|
+
const definitions = manifest.kind === 'agent-plugin' ? [manifest.definition]
|
|
402
|
+
: ['config', 'policy'].flatMap(field => {
|
|
403
|
+
const section = manifest.definition[field];
|
|
404
|
+
return isRecord(section) && Array.isArray(section.plugins) ? section.plugins.map(record) : [];
|
|
405
|
+
});
|
|
406
|
+
for (const definition of definitions) {
|
|
407
|
+
if (!definition.componentStableKey)
|
|
408
|
+
continue;
|
|
409
|
+
const key = String(definition.componentStableKey);
|
|
410
|
+
if (projected?.component?.includes(key))
|
|
411
|
+
continue;
|
|
412
|
+
const id = await resolveKey(input, 'component', key, cache);
|
|
413
|
+
const component = unwrapData(await input.client.getComponent(id));
|
|
414
|
+
if (component.active !== true || component.deletedAt || component.deletedBy)
|
|
415
|
+
throw new Error('Backing component must be active and not deleted.');
|
|
416
|
+
await verifyComponentRuntime(input.client, component);
|
|
417
|
+
if (definition.componentDigest)
|
|
418
|
+
await componentRevisionByDigest(input.client, id, String(definition.componentDigest));
|
|
419
|
+
}
|
|
420
|
+
}
|
|
397
421
|
export async function buildAgentsPlan(input) {
|
|
398
422
|
const plan = { resourceType: input.family, env: input.envName, items: [], counts: { clean: 0, create: 0, 'safe-update': 0, 'remote-changed': 0, conflict: 0, 'missing-lock': 0, orphan: 0, skipped: 0, collision: 0 }, blockers: [], warnings: [], exclusions: ['Agent memory, sessions, workspace files, terminals, automation recipients, avatars and MCP secrets remain target-local.'] };
|
|
399
423
|
const locals = readWorkspaceAgents(input.cwd, input.family);
|
|
@@ -468,10 +492,11 @@ export async function buildAgentsPlan(input) {
|
|
|
468
492
|
// A projected create can fill an absent dependency, never hide duplicate target identities.
|
|
469
493
|
const candidates = await dependencyRecords(input, family, cache);
|
|
470
494
|
const matches = candidates.filter(value => active(value) && readConfiguredResourceMetadataStableKey(value, input.stableKeyName) === key);
|
|
471
|
-
if (matches.length
|
|
495
|
+
if (matches.length <= 1 && input.projected?.[family]?.includes(key) && (family === 'component' || matches.length === 0))
|
|
472
496
|
continue;
|
|
473
497
|
await resolveKey(input, family, key, cache);
|
|
474
498
|
}
|
|
499
|
+
await verifyPluginComponents(input, manifest, cache, input.projected);
|
|
475
500
|
if (manifest.owner?.type === 'system' && !await ownerIsAvailable(input.client, manifest.owner, input.stableKeyName))
|
|
476
501
|
throw new Error('System owner unavailable.');
|
|
477
502
|
if (manifest.executionPrincipal?.kind === 'service-account' && !input.projected?.['service-account']?.includes(manifest.executionPrincipal.stableKey)) {
|
|
@@ -549,6 +574,7 @@ export async function pushAgents(input) {
|
|
|
549
574
|
const current = target ? await agentManifestFromRecord(input, target) : null;
|
|
550
575
|
if ((current ? hashPortableAgent(comparableAgent(manifest, current)) : undefined) !== item.currentHash)
|
|
551
576
|
throw new Error('Target definition changed after planning.');
|
|
577
|
+
await verifyPluginComponents(input, manifest, new Map());
|
|
552
578
|
let written = target;
|
|
553
579
|
if (item.desiredHash !== item.currentHash) {
|
|
554
580
|
const payload = await writePayload(input, manifest, target);
|
|
@@ -11,6 +11,9 @@ export type DatabaseSchemaManifest = {
|
|
|
11
11
|
metadata: Record<string, unknown>;
|
|
12
12
|
type?: string;
|
|
13
13
|
definition?: PortableDefinition[];
|
|
14
|
+
options?: {
|
|
15
|
+
indexes: Record<string, unknown>[];
|
|
16
|
+
};
|
|
14
17
|
partition?: Record<string, unknown>;
|
|
15
18
|
parentStableKey?: string;
|
|
16
19
|
migration?: {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { databaseIndexPayload } from "../database-indexes.js";
|
|
1
2
|
import fs from 'node:fs';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
import { ApiError } from "../client.js";
|
|
@@ -134,6 +135,7 @@ function manifestFromEntry(entry, stableKeyName) {
|
|
|
134
135
|
...common,
|
|
135
136
|
...(typeof record.type === 'string' ? { type: record.type } : {}),
|
|
136
137
|
definition,
|
|
138
|
+
options: { indexes: databaseIndexPayload(isRecord(record.options) ? record.options.indexes : undefined) },
|
|
137
139
|
...(partition ? { partition } : {}),
|
|
138
140
|
...(hasForeignReferences(definition) ? { migration: { foreignReferences: 'manual' } } : {}),
|
|
139
141
|
};
|
|
@@ -163,6 +165,7 @@ function portableDatabaseSchemaManifest(manifest) {
|
|
|
163
165
|
kind: manifest.kind,
|
|
164
166
|
...common,
|
|
165
167
|
...(manifest.type === undefined ? {} : { type: manifest.type }),
|
|
168
|
+
options: { indexes: databaseIndexPayload(manifest.options?.indexes) },
|
|
166
169
|
...(manifest.definition === undefined
|
|
167
170
|
? {}
|
|
168
171
|
: { definition: portableDefinitions(manifest.definition) }),
|
|
@@ -604,19 +607,18 @@ function diffDatabaseSchemas(desired, current, stableKeyName) {
|
|
|
604
607
|
hint: 'Changing the physical table kind can rebuild storage and dependencies; use a replacement table with a new Stable Key and an explicit data migration.',
|
|
605
608
|
});
|
|
606
609
|
}
|
|
607
|
-
for (const field of ['category', 'description', 'metadata']) {
|
|
610
|
+
for (const field of ['category', 'description', 'metadata', 'options']) {
|
|
608
611
|
if (valuesEqual(desired[field], current[field])) {
|
|
609
612
|
continue;
|
|
610
613
|
}
|
|
611
|
-
const cannotClearCategory = field === 'category' && (desired.category === undefined || desired.category === null);
|
|
612
614
|
changes.push({
|
|
613
615
|
kind: 'field-changed',
|
|
614
616
|
field,
|
|
615
|
-
risk:
|
|
617
|
+
risk: field === 'options' ? 'operational' : 'safe',
|
|
616
618
|
before: current[field],
|
|
617
619
|
after: desired[field],
|
|
618
|
-
hint:
|
|
619
|
-
? '
|
|
620
|
+
hint: field === 'options'
|
|
621
|
+
? 'Index changes may scan data and hold schema locks; review target size and deployment timing before applying.'
|
|
620
622
|
: safeFieldHint(field),
|
|
621
623
|
});
|
|
622
624
|
}
|
|
@@ -1538,6 +1540,7 @@ function createPayloadForDatabaseSchema(input) {
|
|
|
1538
1540
|
return {
|
|
1539
1541
|
...common,
|
|
1540
1542
|
definition: portableDefinitions(input.manifest.definition),
|
|
1543
|
+
options: { indexes: databaseIndexPayload(input.manifest.options?.indexes) },
|
|
1541
1544
|
...(input.manifest.partition === undefined
|
|
1542
1545
|
? {}
|
|
1543
1546
|
: { partition: canonicalValue(input.manifest.partition, true) }),
|
|
@@ -1725,7 +1728,7 @@ function buildDatabaseSchemaUpdatePayload(input) {
|
|
|
1725
1728
|
...(input.sourceWins === true && input.desired.name !== input.target.name
|
|
1726
1729
|
? { name: input.desired.name }
|
|
1727
1730
|
: {}),
|
|
1728
|
-
|
|
1731
|
+
category: input.desired.category ?? null,
|
|
1729
1732
|
...(input.desired.description === undefined
|
|
1730
1733
|
? (typeof input.target.desc === 'string' && input.target.desc ? { desc: '' } : {})
|
|
1731
1734
|
: { desc: input.desired.description }),
|
|
@@ -1756,6 +1759,7 @@ function buildDatabaseSchemaUpdatePayload(input) {
|
|
|
1756
1759
|
desiredStableKeyOwners.set(stableKey, [...(desiredStableKeyOwners.get(stableKey) || []), definition]);
|
|
1757
1760
|
}
|
|
1758
1761
|
}
|
|
1762
|
+
payload.options = { indexes: databaseIndexPayload(input.desired.options?.indexes) };
|
|
1759
1763
|
payload.definition = (input.desired.definition || []).map((definition) => {
|
|
1760
1764
|
const value = portableDefinition(definition);
|
|
1761
1765
|
const stableKey = columnStableKey(value, stableKeyName);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type DatabaseIndex } from '../database-indexes.ts';
|
|
1
2
|
import { type FieldChange } from '../diff-details.ts';
|
|
2
3
|
import type { RevoClient } from '../client.ts';
|
|
3
4
|
import type { DatabaseSchemaRecord } from '../types.ts';
|
|
@@ -23,10 +24,7 @@ export type DatabaseViewOutputField = {
|
|
|
23
24
|
type: string;
|
|
24
25
|
isArray: boolean;
|
|
25
26
|
};
|
|
26
|
-
export type DatabaseViewIndex =
|
|
27
|
-
columns: string[];
|
|
28
|
-
unique?: boolean;
|
|
29
|
-
};
|
|
27
|
+
export type DatabaseViewIndex = DatabaseIndex;
|
|
30
28
|
type DatabaseViewManifestBase = {
|
|
31
29
|
kind: 'database-view';
|
|
32
30
|
stableKey: string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { normalizeDatabaseIndexes, databaseIndexPayload, databaseIndexReferences } from "../database-indexes.js";
|
|
1
2
|
import path from 'node:path';
|
|
2
3
|
import { describeFieldChanges, unifiedLineDiff } from "../diff-details.js";
|
|
3
4
|
import { hashStable, readComponentLock, writeComponentLock } from "../component-lock.js";
|
|
@@ -119,13 +120,10 @@ function validManifest(value, stableKeyName) {
|
|
|
119
120
|
|| !value.uniqueKey.every(isNonEmptyString)) {
|
|
120
121
|
return false;
|
|
121
122
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
&& index.columns.every(isNonEmptyString)
|
|
127
|
-
&& (index.unique === undefined || typeof index.unique === 'boolean')
|
|
128
|
-
&& Object.keys(index).every((key) => key === 'columns' || key === 'unique'))))) {
|
|
123
|
+
try {
|
|
124
|
+
normalizeDatabaseIndexes(value.indexes);
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
129
127
|
return false;
|
|
130
128
|
}
|
|
131
129
|
}
|
|
@@ -134,6 +132,7 @@ function validManifest(value, stableKeyName) {
|
|
|
134
132
|
export function hashPortableDatabaseView(manifest) {
|
|
135
133
|
return hashStable(canonicalValue({
|
|
136
134
|
...manifest,
|
|
135
|
+
...(manifest.type === 'MATERIALIZED_VIEW' ? { indexes: normalizeDatabaseIndexes(manifest.indexes) } : {}),
|
|
137
136
|
sources: [...manifest.sources].sort((left, right) => (left.databaseStableKey.localeCompare(right.databaseStableKey)
|
|
138
137
|
|| left.name.localeCompare(right.name))),
|
|
139
138
|
}));
|
|
@@ -235,33 +234,15 @@ function materializedConfiguration(record, output) {
|
|
|
235
234
|
if (record.uniqueKey.some((column) => !outputNames.has(column))) {
|
|
236
235
|
return `Database View "${String(record.name || viewIdOf(record) || 'unknown')}" uniqueKey references an unknown output column`;
|
|
237
236
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
for (const column of index.columns) {
|
|
248
|
-
const name = isNonEmptyString(column)
|
|
249
|
-
? column
|
|
250
|
-
: isRecord(column) && isNonEmptyString(column.name)
|
|
251
|
-
? column.name
|
|
252
|
-
: undefined;
|
|
253
|
-
if (!name) {
|
|
254
|
-
return `Database View "${String(record.name || viewIdOf(record) || 'unknown')}" has an invalid materialized index`;
|
|
255
|
-
}
|
|
256
|
-
columns.push(name);
|
|
257
|
-
}
|
|
258
|
-
if (columns.some((column) => !outputNames.has(column))) {
|
|
259
|
-
return `Database View "${String(record.name || viewIdOf(record) || 'unknown')}" index references an unknown output column`;
|
|
260
|
-
}
|
|
261
|
-
if (index.unique !== undefined && typeof index.unique !== 'boolean') {
|
|
262
|
-
return `Database View "${String(record.name || viewIdOf(record) || 'unknown')}" has an invalid materialized index unique flag`;
|
|
263
|
-
}
|
|
264
|
-
indexes.push({ columns, ...(index.unique === true ? { unique: true } : {}) });
|
|
237
|
+
let indexes;
|
|
238
|
+
try {
|
|
239
|
+
indexes = normalizeDatabaseIndexes(record.indexes);
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
return `Database View "${String(record.name || viewIdOf(record))}" has an invalid materialized index: ${String(error)}`;
|
|
243
|
+
}
|
|
244
|
+
if (indexes.some(index => databaseIndexReferences(index).some(column => !outputNames.has(column)))) {
|
|
245
|
+
return `Database View "${String(record.name || viewIdOf(record))}" index references an unknown output column`;
|
|
265
246
|
}
|
|
266
247
|
return {
|
|
267
248
|
uniqueKey: [...record.uniqueKey],
|
|
@@ -809,10 +790,7 @@ function createDatabaseViewPayload(manifest) {
|
|
|
809
790
|
};
|
|
810
791
|
}
|
|
811
792
|
function databaseViewWriteIndexes(indexes) {
|
|
812
|
-
return indexes
|
|
813
|
-
columns: index.columns.map((name) => ({ name })),
|
|
814
|
-
...(index.unique === true ? { unique: true } : {}),
|
|
815
|
-
}));
|
|
793
|
+
return databaseIndexPayload(indexes);
|
|
816
794
|
}
|
|
817
795
|
function assertTargetPreviewMatchesManifest(manifest, preview) {
|
|
818
796
|
const output = previewOutput(preview);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { componentContentDigest, componentRevisionByDigest, isComponentDigest } from "../component-contract.js";
|
|
1
2
|
import { executionPrincipalAvailable, portableExecutionPolicy, runtimeExecutionPolicyPayload, validPortableExecutionPolicy } from "./account-principal.js";
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
import { describeFieldChanges } from "../diff-details.js";
|
|
4
|
-
import { hashPortableComponentSource, hashStable, readComponentLock, writeComponentLock } from "../component-lock.js";
|
|
5
|
+
import { hashPortableComponentSource, normalizePortableComponentSource, hashStable, readComponentLock, writeComponentLock } from "../component-lock.js";
|
|
5
6
|
import { withHttpTraceContext } from "../http-trace.js";
|
|
6
7
|
import { readConfiguredResourceMetadataStableKey, sanitizeUserMetadata } from "../resource-metadata.js";
|
|
7
8
|
import { HTTP_REQUEST_CONCURRENCY } from "../request-queue.js";
|
|
@@ -68,6 +69,7 @@ function portableOptions(record) {
|
|
|
68
69
|
const options = { ...record.options };
|
|
69
70
|
delete options.componentSchemaId;
|
|
70
71
|
delete options.componentSchemaVersion;
|
|
72
|
+
delete options.componentSchemaDigest;
|
|
71
73
|
delete options.componentSchemaElement;
|
|
72
74
|
return Object.keys(options).length > 0 ? canonicalValue(options) : undefined;
|
|
73
75
|
}
|
|
@@ -75,10 +77,7 @@ function canonicalPortableOptions(options) {
|
|
|
75
77
|
if (options === undefined) {
|
|
76
78
|
return undefined;
|
|
77
79
|
}
|
|
78
|
-
return canonicalValue(
|
|
79
|
-
...options,
|
|
80
|
-
...(options.memory === null ? { memory: ENDPOINT_DEFAULT_MEMORY_MB } : {}),
|
|
81
|
-
});
|
|
80
|
+
return canonicalValue(options);
|
|
82
81
|
}
|
|
83
82
|
function endpointLabel(record, fallback = 'remote-id') {
|
|
84
83
|
const category = typeof record.category === 'string' && record.category.trim()
|
|
@@ -113,7 +112,7 @@ const ENDPOINT_MANIFEST_FIELDS = new Set([
|
|
|
113
112
|
'route', 'options', 'execution', 'executionPolicy', 'schema',
|
|
114
113
|
]);
|
|
115
114
|
const INSTANCE_LOCAL_SCHEMA_OPTION_FIELDS = new Set([
|
|
116
|
-
'componentSchemaId', 'componentSchemaVersion', 'componentSchemaElement',
|
|
115
|
+
'componentSchemaId', 'componentSchemaVersion', 'componentSchemaDigest', 'componentSchemaElement',
|
|
117
116
|
]);
|
|
118
117
|
function hasOnlyKeys(value, allowed) {
|
|
119
118
|
return Object.keys(value).every((key) => allowed.has(key));
|
|
@@ -131,7 +130,7 @@ function hasValidBinding(value) {
|
|
|
131
130
|
if (value.binding === 'latest') {
|
|
132
131
|
return value.pinnedDigest === undefined;
|
|
133
132
|
}
|
|
134
|
-
return
|
|
133
|
+
return isComponentDigest(value.pinnedDigest);
|
|
135
134
|
}
|
|
136
135
|
function hasValidSchemaBinding(value) {
|
|
137
136
|
if (!isRecord(value) || !hasOnlyKeys(value, new Set(['stableKey', 'binding', 'pinnedDigest', 'element']))) {
|
|
@@ -197,12 +196,28 @@ export function hashPortableEndpoint(manifest) {
|
|
|
197
196
|
...(manifest.schema === undefined ? {} : { schema: canonicalValue(manifest.schema) }),
|
|
198
197
|
});
|
|
199
198
|
}
|
|
200
|
-
function readWorkspaceEndpoints(cwd) {
|
|
199
|
+
function readWorkspaceEndpoints(cwd, stableKeyName = 'stableKey') {
|
|
201
200
|
const { workspaceRoot } = requireProjectLayout(cwd, 'Endpoint');
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
manifest
|
|
205
|
-
|
|
201
|
+
let components;
|
|
202
|
+
return findManifestFiles(path.join(workspaceRoot, ENDPOINTS_DIRECTORY), ENDPOINT_MANIFEST_FILE).map(manifestPath => {
|
|
203
|
+
const manifest = readJsonFile(manifestPath);
|
|
204
|
+
if (isRecord(manifest))
|
|
205
|
+
for (const field of ['execution', 'schema']) {
|
|
206
|
+
const binding = manifest[field];
|
|
207
|
+
if (!isRecord(binding) || typeof binding.pinnedDigest !== 'string' || !/^[a-f0-9]{64}$/i.test(binding.pinnedDigest))
|
|
208
|
+
continue;
|
|
209
|
+
components ??= readWorkspaceComponents(cwd, stableKeyName);
|
|
210
|
+
const matches = components.get(String(binding.stableKey)) || [];
|
|
211
|
+
if (matches.length !== 1)
|
|
212
|
+
continue;
|
|
213
|
+
// Before 1.0.22 this value was a configuration fingerprint. Upgrade only
|
|
214
|
+
// when the exact local source proves which content it identifies.
|
|
215
|
+
const { metadata, ...legacy } = normalizePortableComponentSource(matches[0]);
|
|
216
|
+
if (hashStable(legacy) === binding.pinnedDigest)
|
|
217
|
+
binding.pinnedDigest = componentContentDigest(matches[0]);
|
|
218
|
+
}
|
|
219
|
+
return { manifestPath, manifest };
|
|
220
|
+
});
|
|
206
221
|
}
|
|
207
222
|
function readWorkspaceComponents(cwd, stableKeyName) {
|
|
208
223
|
const { workspaceRoot } = requireProjectLayout(cwd, 'Endpoint');
|
|
@@ -255,6 +270,10 @@ async function componentBinding(input) {
|
|
|
255
270
|
throw new Error(`Endpoint "${input.endpointStableKey}" ${input.relation} component is unmanaged: missing ${input.stableKeyName}.`);
|
|
256
271
|
}
|
|
257
272
|
const componentVersion = input.componentVersion;
|
|
273
|
+
if (input.componentDigest) {
|
|
274
|
+
const snapshot = await componentRevisionByDigest(input.client, input.componentId, String(input.componentDigest));
|
|
275
|
+
return { stableKey, binding: 'pinned', pinnedDigest: componentContentDigest(snapshot) };
|
|
276
|
+
}
|
|
258
277
|
if (typeof componentVersion !== 'number') {
|
|
259
278
|
return { stableKey, binding: 'latest' };
|
|
260
279
|
}
|
|
@@ -263,7 +282,7 @@ async function componentBinding(input) {
|
|
|
263
282
|
operation: 'get-snapshot',
|
|
264
283
|
entityId: input.componentId,
|
|
265
284
|
}, () => input.client.getComponentSnapshotVersion(input.componentId, componentVersion)));
|
|
266
|
-
return { stableKey, binding: 'pinned', pinnedDigest:
|
|
285
|
+
return { stableKey, binding: 'pinned', pinnedDigest: componentContentDigest(snapshot) };
|
|
267
286
|
}
|
|
268
287
|
async function manifestFromRecord(input) {
|
|
269
288
|
const { record } = input;
|
|
@@ -286,6 +305,7 @@ async function manifestFromRecord(input) {
|
|
|
286
305
|
componentsById: input.componentsById,
|
|
287
306
|
componentId: executionComponentId,
|
|
288
307
|
componentVersion: record.componentVersion,
|
|
308
|
+
componentDigest: record.componentDigest,
|
|
289
309
|
stableKeyName: input.stableKeyName,
|
|
290
310
|
endpointStableKey: input.stableKey,
|
|
291
311
|
relation: 'execution',
|
|
@@ -304,6 +324,7 @@ async function manifestFromRecord(input) {
|
|
|
304
324
|
componentsById: input.componentsById,
|
|
305
325
|
componentId: schemaComponentId,
|
|
306
326
|
componentVersion: record.options?.componentSchemaVersion,
|
|
327
|
+
componentDigest: record.options?.componentSchemaDigest,
|
|
307
328
|
stableKeyName: input.stableKeyName,
|
|
308
329
|
endpointStableKey: input.stableKey,
|
|
309
330
|
relation: 'schema',
|
|
@@ -374,7 +395,7 @@ export async function pullEndpointsToWorkspace(input) {
|
|
|
374
395
|
const lock = readComponentLock(projectRoot);
|
|
375
396
|
const existingByKey = new Map();
|
|
376
397
|
const existingByPath = new Map();
|
|
377
|
-
for (const entry of readWorkspaceEndpoints(input.cwd)) {
|
|
398
|
+
for (const entry of readWorkspaceEndpoints(input.cwd, input.stableKeyName)) {
|
|
378
399
|
if (!validateManifest(entry.manifest, input.stableKeyName)) {
|
|
379
400
|
throw new Error(`Cannot pull over invalid endpoint manifest ${path.relative(projectRoot, entry.manifestPath)}.`);
|
|
380
401
|
}
|
|
@@ -550,11 +571,11 @@ function componentDependencyDiagnostics(input) {
|
|
|
550
571
|
}
|
|
551
572
|
const workspace = workspaceMatches[0];
|
|
552
573
|
const target = targetMatches.length === 1 ? targetMatches[0] : undefined;
|
|
553
|
-
const workspaceDigest = hashPortableComponentSource(workspace);
|
|
554
|
-
const targetDigest = target ? hashPortableComponentSource(target) : null;
|
|
574
|
+
const workspaceDigest = binding.binding === 'pinned' ? componentContentDigest(workspace) : hashPortableComponentSource(workspace);
|
|
575
|
+
const targetDigest = target ? (binding.binding === 'pinned' ? componentContentDigest(target) : hashPortableComponentSource(target)) : null;
|
|
555
576
|
const projected = usesProjection ? projectedMatches[0] : undefined;
|
|
556
577
|
const expectedHash = binding.binding === 'pinned' ? binding.pinnedDigest || '' : workspaceDigest;
|
|
557
|
-
const projectedHash = projected?.desiredHash ?? targetDigest;
|
|
578
|
+
const projectedHash = binding.binding === 'pinned' && projected ? workspaceDigest : projected?.desiredHash ?? targetDigest;
|
|
558
579
|
const readiness = projected?.state === 'pending-create'
|
|
559
580
|
? 'pending-component-create'
|
|
560
581
|
: projected?.state === 'pending-update'
|
|
@@ -648,6 +669,7 @@ function endpointRevisionHash(record) {
|
|
|
648
669
|
method: record.method ?? null,
|
|
649
670
|
componentId: record.componentId ?? null,
|
|
650
671
|
componentVersion: record.componentVersion ?? null,
|
|
672
|
+
componentDigest: record.componentDigest ?? null,
|
|
651
673
|
options: canonicalValue(record.options ?? null),
|
|
652
674
|
version: record.version ?? null,
|
|
653
675
|
deletedAt: record.deletedAt ?? null,
|
|
@@ -659,7 +681,7 @@ async function activeDeletedEndpointRestoreBlockers(input) {
|
|
|
659
681
|
return [];
|
|
660
682
|
}
|
|
661
683
|
const blockers = [];
|
|
662
|
-
const loadBinding = async (componentId, version, relation) => {
|
|
684
|
+
const loadBinding = async (componentId, version, relation, digest) => {
|
|
663
685
|
const current = input.componentsById.get(componentId);
|
|
664
686
|
if (!current) {
|
|
665
687
|
blockers.push(`old ${relation} Component "${componentId}" is missing`);
|
|
@@ -670,9 +692,11 @@ async function activeDeletedEndpointRestoreBlockers(input) {
|
|
|
670
692
|
return undefined;
|
|
671
693
|
}
|
|
672
694
|
try {
|
|
673
|
-
const component =
|
|
674
|
-
?
|
|
675
|
-
:
|
|
695
|
+
const component = digest
|
|
696
|
+
? await componentRevisionByDigest(input.client, componentId, String(digest))
|
|
697
|
+
: typeof version === 'number'
|
|
698
|
+
? unwrapData(await input.client.getComponentSnapshotVersion(componentId, version))
|
|
699
|
+
: current;
|
|
676
700
|
if (!component) {
|
|
677
701
|
blockers.push(`old ${relation} Component "${componentId}" is missing`);
|
|
678
702
|
}
|
|
@@ -684,7 +708,7 @@ async function activeDeletedEndpointRestoreBlockers(input) {
|
|
|
684
708
|
}
|
|
685
709
|
};
|
|
686
710
|
if (typeof input.record.componentId === 'string' && input.record.componentId) {
|
|
687
|
-
const execution = await loadBinding(input.record.componentId, input.record.componentVersion, 'execution');
|
|
711
|
+
const execution = await loadBinding(input.record.componentId, input.record.componentVersion, 'execution', input.record.componentDigest);
|
|
688
712
|
if (execution && !new Set(['CODE_JS', 'CODE_TS']).has(componentType(execution))) {
|
|
689
713
|
blockers.push(`old execution Component "${input.record.componentId}" is not executable`);
|
|
690
714
|
}
|
|
@@ -692,7 +716,7 @@ async function activeDeletedEndpointRestoreBlockers(input) {
|
|
|
692
716
|
const options = isRecord(input.record.options) ? input.record.options : {};
|
|
693
717
|
const schemaId = typeof options.componentSchemaId === 'string' ? options.componentSchemaId : '';
|
|
694
718
|
if (schemaId) {
|
|
695
|
-
const schema = await loadBinding(schemaId, options.componentSchemaVersion, 'schema');
|
|
719
|
+
const schema = await loadBinding(schemaId, options.componentSchemaVersion, 'schema', options.componentSchemaDigest);
|
|
696
720
|
if (schema && componentType(schema) !== 'JSON_VALIDATOR') {
|
|
697
721
|
blockers.push(`old schema Component "${schemaId}" is not JSON_VALIDATOR`);
|
|
698
722
|
}
|
|
@@ -715,7 +739,7 @@ export async function buildEndpointsPlan(input) {
|
|
|
715
739
|
const warnings = [];
|
|
716
740
|
const exclusions = [];
|
|
717
741
|
const localByStableKey = new Map();
|
|
718
|
-
for (const entry of readWorkspaceEndpoints(input.cwd)) {
|
|
742
|
+
for (const entry of readWorkspaceEndpoints(input.cwd, input.stableKeyName)) {
|
|
719
743
|
if (!validateManifest(entry.manifest, input.stableKeyName)) {
|
|
720
744
|
const relativePath = path.relative(projectRoot, entry.manifestPath);
|
|
721
745
|
blockers.push(`Invalid Endpoint manifest "${relativePath}".`);
|
|
@@ -1095,7 +1119,7 @@ export async function buildEndpointsPlan(input) {
|
|
|
1095
1119
|
}
|
|
1096
1120
|
function readValidWorkspaceEndpoints(cwd, stableKeyName) {
|
|
1097
1121
|
const result = new Map();
|
|
1098
|
-
for (const entry of readWorkspaceEndpoints(cwd)) {
|
|
1122
|
+
for (const entry of readWorkspaceEndpoints(cwd, stableKeyName)) {
|
|
1099
1123
|
if (validateManifest(entry.manifest, stableKeyName)) {
|
|
1100
1124
|
result.set(entry.manifest.stableKey, { manifest: entry.manifest, manifestPath: entry.manifestPath });
|
|
1101
1125
|
}
|
|
@@ -1113,6 +1137,7 @@ function endpointWriteOptions(manifest, schemaComponent) {
|
|
|
1113
1137
|
options.componentSchemaVersion = manifest.schema.binding === 'pinned'
|
|
1114
1138
|
? schemaComponent.version
|
|
1115
1139
|
: null;
|
|
1140
|
+
options.componentSchemaDigest = manifest.schema.binding === 'pinned' ? componentContentDigest(schemaComponent) : null;
|
|
1116
1141
|
options.componentSchemaElement = manifest.schema.element ?? null;
|
|
1117
1142
|
}
|
|
1118
1143
|
return Object.keys(options).length > 0 ? options : undefined;
|
|
@@ -1162,9 +1187,10 @@ async function resolveEndpointWritePayload(input) {
|
|
|
1162
1187
|
...(execution
|
|
1163
1188
|
? {
|
|
1164
1189
|
componentId,
|
|
1190
|
+
componentDigest: input.manifest.execution?.binding === 'pinned' ? componentContentDigest(execution) : null,
|
|
1165
1191
|
componentVersion: input.manifest.execution?.binding === 'pinned' ? execution.version : null,
|
|
1166
1192
|
}
|
|
1167
|
-
: { componentId: null, componentVersion: null }),
|
|
1193
|
+
: { componentId: null, componentDigest: null, componentVersion: null }),
|
|
1168
1194
|
timeout: input.manifest.timeout ?? ENDPOINT_DEFAULT_TIMEOUT_SECONDS,
|
|
1169
1195
|
path: input.manifest.route.path,
|
|
1170
1196
|
method: input.manifest.route.method,
|
|
@@ -1433,6 +1459,7 @@ export async function pushEndpoints(input) {
|
|
|
1433
1459
|
if (!prepared.manifest.execution) {
|
|
1434
1460
|
delete createPayload.componentId;
|
|
1435
1461
|
delete createPayload.componentVersion;
|
|
1462
|
+
delete createPayload.componentDigest;
|
|
1436
1463
|
}
|
|
1437
1464
|
const created = unwrapData(await input.client.createEndpoint(createPayload));
|
|
1438
1465
|
const createdId = endpointIdOf(created);
|