@sequenceholdings/studio-cli 0.2.2 → 0.4.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.
- package/README.md +616 -78
- package/dist/access/commands.d.ts +3 -0
- package/dist/access/commands.js +91 -0
- package/dist/agents/commands.d.ts +1 -1
- package/dist/agents/commands.js +5 -0
- package/dist/agents/scaffold.js +5 -7
- package/dist/agents/voice-authoring.d.ts +5 -0
- package/dist/agents/voice-authoring.js +75 -0
- package/dist/agents/voice-publication.d.ts +5 -0
- package/dist/agents/voice-publication.js +63 -0
- package/dist/agents/voice-shared.d.ts +20 -0
- package/dist/agents/voice-shared.js +112 -0
- package/dist/agents/voice.d.ts +3 -0
- package/dist/agents/voice.js +57 -0
- package/dist/app/adapters.d.ts +6 -0
- package/dist/app/adapters.js +17 -2
- package/dist/app/agent-refs.d.ts +16 -0
- package/dist/app/agent-refs.js +36 -0
- package/dist/app/application-registration.d.ts +36 -6
- package/dist/app/application-registration.js +60 -15
- package/dist/app/commands.js +19 -2
- package/dist/app/deploy.d.ts +3 -0
- package/dist/app/deploy.js +22 -6
- package/dist/app/env-bindings.d.ts +21 -0
- package/dist/app/env-bindings.js +184 -0
- package/dist/app/manifest-validation.js +8 -0
- package/dist/app/manifest.d.ts +32 -14
- package/dist/app/manifest.js +16 -6
- package/dist/app/primitive-scaffold.d.ts +4 -1
- package/dist/app/primitive-scaffold.js +4 -4
- package/dist/app/readme.js +1 -0
- package/dist/app/scaffold-files.js +1 -1
- package/dist/app/scaffold.d.ts +6 -4
- package/dist/app/scaffold.js +7 -4
- package/dist/app/workspace-scaffold.js +12 -7
- package/dist/argv.d.ts +7 -0
- package/dist/argv.js +56 -0
- package/dist/artifact/delegate.js +8 -4
- package/dist/atlas-client.d.ts +6 -0
- package/dist/atlas-client.js +39 -2
- package/dist/auth-cmds/commands.d.ts +1 -1
- package/dist/auth-cmds/commands.js +16 -0
- package/dist/auth.d.ts +32 -0
- package/dist/auth.js +170 -33
- package/dist/bin.js +23 -4
- package/dist/command-contract.d.ts +137 -0
- package/dist/command-contract.js +43 -0
- package/dist/command-help.d.ts +8 -0
- package/dist/command-help.js +71 -0
- package/dist/command-input.d.ts +15 -0
- package/dist/command-input.js +33 -0
- package/dist/functions/commands.d.ts +2 -1
- package/dist/functions/commands.js +78 -33
- package/dist/functions/deploy-preflight.d.ts +21 -0
- package/dist/functions/deploy-preflight.js +58 -0
- package/dist/functions/egress-postgres.d.ts +7 -0
- package/dist/functions/egress-postgres.js +36 -0
- package/dist/functions/manifest.d.ts +15 -1
- package/dist/functions/manifest.js +49 -12
- package/dist/functions/secret-reconcile.d.ts +3 -3
- package/dist/functions/secret-reconcile.js +5 -7
- package/dist/functions/source-selection.js +4 -1
- package/dist/main.d.ts +2 -0
- package/dist/main.js +75 -25
- package/dist/manifest-roles-notice.d.ts +33 -0
- package/dist/manifest-roles-notice.js +75 -0
- package/dist/orm/delegate.d.ts +16 -0
- package/dist/orm/delegate.js +142 -7
- package/dist/pipeline/clone-deploy.d.ts +37 -0
- package/dist/pipeline/clone-deploy.js +125 -0
- package/dist/pipeline/codegen.js +6 -2
- package/dist/pipeline/commands.js +21 -5
- package/dist/pipeline/lifecycle.d.ts +1 -0
- package/dist/pipeline/lifecycle.js +95 -44
- package/dist/pipeline/repin-orm.js +6 -2
- package/dist/pipeline/stage-secrets.d.ts +4 -1
- package/dist/pipeline/stage-secrets.js +7 -3
- package/dist/process/build.js +17 -0
- package/dist/process/codegen.js +16 -0
- package/dist/process/commands.d.ts +15 -7
- package/dist/process/commands.js +294 -98
- package/dist/process/lint.js +35 -0
- package/dist/process/plan-diff.js +9 -0
- package/dist/process/simulate.js +8 -0
- package/dist/release-age.d.ts +12 -0
- package/dist/release-age.js +24 -0
- package/dist/repos/commands.d.ts +10 -1
- package/dist/repos/commands.js +42 -8
- package/dist/repos/pulls.d.ts +3 -0
- package/dist/repos/pulls.js +131 -0
- package/dist/scaffold-guidance.d.ts +4 -0
- package/dist/scaffold-guidance.js +15 -0
- package/dist/secrets/commands.d.ts +1 -1
- package/dist/secrets/commands.js +97 -16
- package/dist/service-accounts/commands.d.ts +3 -0
- package/dist/service-accounts/commands.js +50 -0
- package/dist/storage/commands.js +23 -1
- package/dist/storage/gcs-download.d.ts +13 -0
- package/dist/storage/gcs-download.js +41 -0
- package/dist/storage/import-cycle.d.ts +41 -0
- package/dist/storage/import-cycle.js +123 -0
- package/dist/storage/import-files.d.ts +30 -0
- package/dist/storage/import-files.js +133 -0
- package/dist/storage/import-gcloud.d.ts +12 -0
- package/dist/storage/import-gcloud.js +54 -0
- package/dist/storage/import-identity.d.ts +12 -0
- package/dist/storage/import-identity.js +15 -0
- package/dist/storage/import-plan.d.ts +120 -0
- package/dist/storage/import-plan.js +189 -0
- package/dist/storage/import-preflight.d.ts +36 -0
- package/dist/storage/import-preflight.js +62 -0
- package/dist/storage/import-progress-map.d.ts +5 -0
- package/dist/storage/import-progress-map.js +22 -0
- package/dist/storage/import-recover.d.ts +97 -0
- package/dist/storage/import-recover.js +186 -0
- package/dist/storage/import-run.d.ts +14 -0
- package/dist/storage/import-run.js +140 -0
- package/dist/templates/guidance/AGENTS.md +10 -0
- package/dist/templates/guidance/CLAUDE.md +1 -0
- package/dist/templates/process/package.json +2 -2
- package/dist/templates/process/pnpm-workspace.yaml +7 -4
- package/dist/validation-detail.d.ts +2 -0
- package/dist/validation-detail.js +20 -0
- package/package.json +9 -9
- package/templates/guidance/AGENTS.md +10 -0
- package/templates/guidance/CLAUDE.md +1 -0
- package/templates/process/package.json +2 -2
- package/templates/process/pnpm-workspace.yaml +7 -4
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export interface ImportSourceObject {
|
|
3
|
+
relativePath: string;
|
|
4
|
+
size: number;
|
|
5
|
+
checksum?: string;
|
|
6
|
+
contentType: string;
|
|
7
|
+
sourceName?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ImportProgressEntry {
|
|
10
|
+
fileId: string;
|
|
11
|
+
uploadId: string;
|
|
12
|
+
size: number;
|
|
13
|
+
checksum?: string;
|
|
14
|
+
idempotencyKey?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ImportProgress {
|
|
17
|
+
version: 1;
|
|
18
|
+
source: string;
|
|
19
|
+
workspaceId: string;
|
|
20
|
+
destPrefix: string;
|
|
21
|
+
parentId: string | null;
|
|
22
|
+
completed: Record<string, ImportProgressEntry>;
|
|
23
|
+
inflight: Record<string, ImportProgressEntry>;
|
|
24
|
+
}
|
|
25
|
+
export declare const importProgressSchema: z.ZodObject<{
|
|
26
|
+
version: z.ZodLiteral<1>;
|
|
27
|
+
source: z.ZodString;
|
|
28
|
+
workspaceId: z.ZodString;
|
|
29
|
+
destPrefix: z.ZodString;
|
|
30
|
+
parentId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
31
|
+
completed: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
32
|
+
fileId: z.ZodString;
|
|
33
|
+
uploadId: z.ZodString;
|
|
34
|
+
size: z.ZodNumber;
|
|
35
|
+
checksum: z.ZodOptional<z.ZodString>;
|
|
36
|
+
idempotencyKey: z.ZodOptional<z.ZodString>;
|
|
37
|
+
}, z.core.$strip>>;
|
|
38
|
+
inflight: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
39
|
+
fileId: z.ZodString;
|
|
40
|
+
uploadId: z.ZodString;
|
|
41
|
+
size: z.ZodNumber;
|
|
42
|
+
checksum: z.ZodOptional<z.ZodString>;
|
|
43
|
+
idempotencyKey: z.ZodOptional<z.ZodString>;
|
|
44
|
+
}, z.core.$strip>>;
|
|
45
|
+
}, z.core.$strip>;
|
|
46
|
+
export declare function parseGsUri(value: string): {
|
|
47
|
+
bucket: string;
|
|
48
|
+
prefix: string;
|
|
49
|
+
};
|
|
50
|
+
/** Path under the destination prefix, or null when the object is outside it. */
|
|
51
|
+
export declare function relativeObjectPath({ prefix, name, }: {
|
|
52
|
+
prefix: string;
|
|
53
|
+
name: string;
|
|
54
|
+
}): string | null;
|
|
55
|
+
export declare function importContentType(value: string | undefined): string;
|
|
56
|
+
export declare function objectsFromGcsList(raw: unknown, prefix: string): {
|
|
57
|
+
objects: ImportSourceObject[];
|
|
58
|
+
skipped: string[];
|
|
59
|
+
};
|
|
60
|
+
export declare function importDestination({ destPrefix, relativePath, }: {
|
|
61
|
+
destPrefix: string;
|
|
62
|
+
relativePath: string;
|
|
63
|
+
}): string;
|
|
64
|
+
export declare function importIdempotencyKey({ workspaceId, parentId, destination, size, checksum, }: {
|
|
65
|
+
workspaceId: string;
|
|
66
|
+
parentId: string | null;
|
|
67
|
+
destination: string;
|
|
68
|
+
size: number;
|
|
69
|
+
checksum?: string;
|
|
70
|
+
}): string;
|
|
71
|
+
export declare function emptyImportProgress({ source, workspaceId, destPrefix, parentId, }: {
|
|
72
|
+
source: string;
|
|
73
|
+
workspaceId: string;
|
|
74
|
+
destPrefix: string;
|
|
75
|
+
parentId: string | null;
|
|
76
|
+
}): ImportProgress;
|
|
77
|
+
export declare function parseImportProgress(raw: unknown, expected: {
|
|
78
|
+
source: string;
|
|
79
|
+
workspaceId: string;
|
|
80
|
+
destPrefix: string;
|
|
81
|
+
parentId: string | null;
|
|
82
|
+
}): ImportProgress;
|
|
83
|
+
export interface ClassifiedImport {
|
|
84
|
+
skip: ImportSourceObject[];
|
|
85
|
+
resume: Array<{
|
|
86
|
+
object: ImportSourceObject;
|
|
87
|
+
destination: string;
|
|
88
|
+
uploadId: string;
|
|
89
|
+
fileId: string;
|
|
90
|
+
idempotencyKey: string;
|
|
91
|
+
}>;
|
|
92
|
+
pending: Array<{
|
|
93
|
+
object: ImportSourceObject;
|
|
94
|
+
destination: string;
|
|
95
|
+
idempotencyKey: string;
|
|
96
|
+
}>;
|
|
97
|
+
changed: Array<{
|
|
98
|
+
relativePath: string;
|
|
99
|
+
reason: string;
|
|
100
|
+
}>;
|
|
101
|
+
rejected: Array<{
|
|
102
|
+
relativePath: string;
|
|
103
|
+
reason: string;
|
|
104
|
+
}>;
|
|
105
|
+
}
|
|
106
|
+
/** Classify a source listing against a progress file. Does not mutate. */
|
|
107
|
+
export declare function classifyImport({ objects, progress, workspaceId, destPrefix, parentId, }: {
|
|
108
|
+
objects: ImportSourceObject[];
|
|
109
|
+
progress: ImportProgress;
|
|
110
|
+
workspaceId: string;
|
|
111
|
+
destPrefix: string;
|
|
112
|
+
parentId: string | null;
|
|
113
|
+
}): ClassifiedImport;
|
|
114
|
+
export declare function nextImportWave<T>({ pending, slots, }: {
|
|
115
|
+
pending: T[];
|
|
116
|
+
slots: number;
|
|
117
|
+
}): {
|
|
118
|
+
wave: T[];
|
|
119
|
+
rest: T[];
|
|
120
|
+
};
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { splitStoragePath, storageChecksum, STORAGE_UPLOAD_BATCH_LIMIT, } from '@sequenceholdings/storage';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { progressRecord, progressRecordFromUnknown, storedProgress } from './import-progress-map.js';
|
|
5
|
+
const contentTypePattern = /^[\w!#$&^.+-]+\/[\w!#$&^.+-]+$/;
|
|
6
|
+
const progressEntry = z.object({
|
|
7
|
+
fileId: z.string(),
|
|
8
|
+
uploadId: z.string(),
|
|
9
|
+
size: z.number().int().nonnegative(),
|
|
10
|
+
checksum: z.string().optional(),
|
|
11
|
+
idempotencyKey: z.string().optional(),
|
|
12
|
+
});
|
|
13
|
+
export const importProgressSchema = z.object({
|
|
14
|
+
version: z.literal(1),
|
|
15
|
+
source: z.string(),
|
|
16
|
+
workspaceId: z.string(),
|
|
17
|
+
destPrefix: z.string(),
|
|
18
|
+
parentId: z.string().nullable().default(null),
|
|
19
|
+
completed: z.record(z.string(), progressEntry),
|
|
20
|
+
inflight: z.record(z.string(), progressEntry),
|
|
21
|
+
});
|
|
22
|
+
export function parseGsUri(value) {
|
|
23
|
+
const match = /^gs:\/\/([^/]+)\/?(.*)$/.exec(value.trim());
|
|
24
|
+
const bucket = match?.[1];
|
|
25
|
+
if (!bucket || bucket === '.' || bucket === '..' || bucket.includes(' '))
|
|
26
|
+
throw new Error('Source must be gs://bucket or gs://bucket/prefix');
|
|
27
|
+
const prefix = (match?.[2] ?? '').replace(/^\/+/, '');
|
|
28
|
+
if (prefix.split('/').includes('..') || prefix.includes('\\'))
|
|
29
|
+
throw new Error('GCS prefix cannot contain .. or backslashes');
|
|
30
|
+
return { bucket, prefix };
|
|
31
|
+
}
|
|
32
|
+
/** Path under the destination prefix, or null when the object is outside it. */
|
|
33
|
+
export function relativeObjectPath({ prefix, name, }) {
|
|
34
|
+
if (!name || name.endsWith('/'))
|
|
35
|
+
return null;
|
|
36
|
+
if (prefix === '')
|
|
37
|
+
return name;
|
|
38
|
+
if (name === prefix)
|
|
39
|
+
return name.split('/').pop() ?? null;
|
|
40
|
+
const directory = prefix.endsWith('/') ? prefix : `${prefix}/`;
|
|
41
|
+
if (!name.startsWith(directory))
|
|
42
|
+
return null;
|
|
43
|
+
const relative = name.slice(directory.length);
|
|
44
|
+
return relative && !relative.endsWith('/') ? relative : null;
|
|
45
|
+
}
|
|
46
|
+
export function importContentType(value) {
|
|
47
|
+
return value && contentTypePattern.test(value)
|
|
48
|
+
? value
|
|
49
|
+
: 'application/octet-stream';
|
|
50
|
+
}
|
|
51
|
+
export function objectsFromGcsList(raw, prefix) {
|
|
52
|
+
const rows = z.array(z.unknown()).parse(raw);
|
|
53
|
+
const objects = [];
|
|
54
|
+
const skipped = [];
|
|
55
|
+
for (const row of rows) {
|
|
56
|
+
const parsed = z
|
|
57
|
+
.object({
|
|
58
|
+
name: z.string(),
|
|
59
|
+
size: z.coerce.number().int().nonnegative(),
|
|
60
|
+
crc32c: z.string().optional(),
|
|
61
|
+
contentType: z.string().optional(),
|
|
62
|
+
})
|
|
63
|
+
.safeParse(row);
|
|
64
|
+
if (!parsed.success) {
|
|
65
|
+
skipped.push('unreadable GCS listing row');
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const relativePath = relativeObjectPath({ prefix, name: parsed.data.name });
|
|
69
|
+
if (!relativePath)
|
|
70
|
+
continue;
|
|
71
|
+
const checksum = storageChecksum.safeParse(parsed.data.crc32c);
|
|
72
|
+
objects.push({
|
|
73
|
+
relativePath,
|
|
74
|
+
size: parsed.data.size,
|
|
75
|
+
contentType: importContentType(parsed.data.contentType),
|
|
76
|
+
sourceName: parsed.data.name,
|
|
77
|
+
...(checksum.success ? { checksum: checksum.data } : {}),
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return { objects, skipped };
|
|
81
|
+
}
|
|
82
|
+
export function importDestination({ destPrefix, relativePath, }) {
|
|
83
|
+
const prefix = destPrefix.replace(/^\/+|\/+$/g, '');
|
|
84
|
+
const relative = relativePath.replace(/^\/+/, '');
|
|
85
|
+
const joined = [prefix, relative].filter(Boolean).join('/');
|
|
86
|
+
return splitStoragePath(joined).join('/');
|
|
87
|
+
}
|
|
88
|
+
export function importIdempotencyKey({ workspaceId, parentId, destination, size, checksum, }) {
|
|
89
|
+
const digest = createHash('sha256')
|
|
90
|
+
.update(`${workspaceId}\0${parentId ?? ''}\0${destination}\0${size}\0${checksum ?? ''}`)
|
|
91
|
+
.digest('hex');
|
|
92
|
+
return `import:${digest}`;
|
|
93
|
+
}
|
|
94
|
+
export function emptyImportProgress({ source, workspaceId, destPrefix, parentId, }) {
|
|
95
|
+
return {
|
|
96
|
+
version: 1,
|
|
97
|
+
source,
|
|
98
|
+
workspaceId,
|
|
99
|
+
destPrefix,
|
|
100
|
+
parentId,
|
|
101
|
+
completed: progressRecord(),
|
|
102
|
+
inflight: progressRecord(),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
export function parseImportProgress(raw, expected) {
|
|
106
|
+
const progress = importProgressSchema.parse(raw);
|
|
107
|
+
progress.completed = progressRecordFromUnknown(objectField(raw, 'completed'), (entry) => progressEntry.parse(entry));
|
|
108
|
+
progress.inflight = progressRecordFromUnknown(objectField(raw, 'inflight'), (entry) => progressEntry.parse(entry));
|
|
109
|
+
if (progress.source !== expected.source ||
|
|
110
|
+
progress.workspaceId !== expected.workspaceId ||
|
|
111
|
+
progress.destPrefix !== expected.destPrefix ||
|
|
112
|
+
progress.parentId !== expected.parentId)
|
|
113
|
+
throw new Error('Progress file belongs to a different source, workspace, or destination');
|
|
114
|
+
return progress;
|
|
115
|
+
}
|
|
116
|
+
function objectField(value, key) {
|
|
117
|
+
if (!value || typeof value !== 'object' || !Object.hasOwn(value, key))
|
|
118
|
+
return undefined;
|
|
119
|
+
return Object.entries(value).find(([name]) => name === key)?.[1];
|
|
120
|
+
}
|
|
121
|
+
function sameBytes(recorded, object) {
|
|
122
|
+
return (recorded.size === object.size &&
|
|
123
|
+
(recorded.checksum ?? '') === (object.checksum ?? ''));
|
|
124
|
+
}
|
|
125
|
+
/** Classify a source listing against a progress file. Does not mutate. */
|
|
126
|
+
export function classifyImport({ objects, progress, workspaceId, destPrefix, parentId, }) {
|
|
127
|
+
const result = {
|
|
128
|
+
skip: [],
|
|
129
|
+
resume: [],
|
|
130
|
+
pending: [],
|
|
131
|
+
changed: [],
|
|
132
|
+
rejected: [],
|
|
133
|
+
};
|
|
134
|
+
for (const object of objects) {
|
|
135
|
+
let destination;
|
|
136
|
+
try {
|
|
137
|
+
destination = importDestination({ destPrefix, relativePath: object.relativePath });
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
result.rejected.push({
|
|
141
|
+
relativePath: object.relativePath,
|
|
142
|
+
reason: error instanceof Error ? error.message : 'Invalid path',
|
|
143
|
+
});
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const done = storedProgress(progress.completed, object.relativePath);
|
|
147
|
+
if (done) {
|
|
148
|
+
if (sameBytes(done, object))
|
|
149
|
+
result.skip.push(object);
|
|
150
|
+
else
|
|
151
|
+
result.changed.push({
|
|
152
|
+
relativePath: object.relativePath,
|
|
153
|
+
reason: `already imported at ${done.size} bytes; source is now ${object.size} bytes`,
|
|
154
|
+
});
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const flight = storedProgress(progress.inflight, object.relativePath);
|
|
158
|
+
const idempotencyKey = flight?.idempotencyKey ??
|
|
159
|
+
importIdempotencyKey({
|
|
160
|
+
workspaceId,
|
|
161
|
+
parentId,
|
|
162
|
+
destination,
|
|
163
|
+
size: object.size,
|
|
164
|
+
checksum: object.checksum,
|
|
165
|
+
});
|
|
166
|
+
if (flight) {
|
|
167
|
+
if (sameBytes(flight, object))
|
|
168
|
+
result.resume.push({
|
|
169
|
+
object,
|
|
170
|
+
destination,
|
|
171
|
+
uploadId: flight.uploadId,
|
|
172
|
+
fileId: flight.fileId,
|
|
173
|
+
idempotencyKey,
|
|
174
|
+
});
|
|
175
|
+
else
|
|
176
|
+
result.changed.push({
|
|
177
|
+
relativePath: object.relativePath,
|
|
178
|
+
reason: 'unfinished upload was reserved for different bytes; reconcile it before retrying',
|
|
179
|
+
});
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
result.pending.push({ object, destination, idempotencyKey });
|
|
183
|
+
}
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
export function nextImportWave({ pending, slots, }) {
|
|
187
|
+
const count = Math.max(0, Math.min(slots, STORAGE_UPLOAD_BATCH_LIMIT, pending.length));
|
|
188
|
+
return { wave: pending.slice(0, count), rest: pending.slice(count) };
|
|
189
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare function importConcurrency(requested: number | undefined): number;
|
|
2
|
+
export declare function jwtExpiryIso(token: string): string | null;
|
|
3
|
+
export declare function credentialFreshness({ expiry, now, minimumMs, }: {
|
|
4
|
+
expiry: string | null;
|
|
5
|
+
now: number;
|
|
6
|
+
minimumMs: number;
|
|
7
|
+
}): 'missing' | 'expired' | 'soon' | 'ok';
|
|
8
|
+
export declare function importMayProceed({ yes, sourceKind, freshness, }: {
|
|
9
|
+
yes: boolean;
|
|
10
|
+
sourceKind: 'gcs' | 'local';
|
|
11
|
+
freshness: 'missing' | 'expired' | 'soon' | 'ok';
|
|
12
|
+
}): {
|
|
13
|
+
proceed: boolean;
|
|
14
|
+
exitCode: number;
|
|
15
|
+
reason: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function formatImportPreflight(info: {
|
|
18
|
+
atlasUrl: string;
|
|
19
|
+
environment: string;
|
|
20
|
+
gcpProject: string | null;
|
|
21
|
+
gcpAccount: string | null;
|
|
22
|
+
gcpCredentialExpiry: string | null;
|
|
23
|
+
gcloudError: string | null;
|
|
24
|
+
atlasTokenExpiry: string | null;
|
|
25
|
+
source: string;
|
|
26
|
+
workspaceName: string;
|
|
27
|
+
workspaceId: string;
|
|
28
|
+
destinationPrefix: string;
|
|
29
|
+
objectCount: number;
|
|
30
|
+
totalBytes: number;
|
|
31
|
+
pendingForYou: number;
|
|
32
|
+
perPrincipal: number;
|
|
33
|
+
perWorkspace: number;
|
|
34
|
+
concurrency: number;
|
|
35
|
+
progressPath: string;
|
|
36
|
+
}): string;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { STORAGE_IMPORT_CONCURRENCY_DEFAULT, STORAGE_IMPORT_CONCURRENCY_MAX } from '@sequenceholdings/storage';
|
|
2
|
+
export function importConcurrency(requested) {
|
|
3
|
+
if (requested === undefined)
|
|
4
|
+
return STORAGE_IMPORT_CONCURRENCY_DEFAULT;
|
|
5
|
+
if (!Number.isInteger(requested) || requested < 1 || requested > STORAGE_IMPORT_CONCURRENCY_MAX)
|
|
6
|
+
throw new Error(`--concurrency must be an integer from 1 to ${STORAGE_IMPORT_CONCURRENCY_MAX}`);
|
|
7
|
+
return requested;
|
|
8
|
+
}
|
|
9
|
+
export function jwtExpiryIso(token) {
|
|
10
|
+
const part = token.split('.')[1];
|
|
11
|
+
if (!part)
|
|
12
|
+
return null;
|
|
13
|
+
try {
|
|
14
|
+
const payload = JSON.parse(Buffer.from(part, 'base64url').toString('utf8'));
|
|
15
|
+
if (typeof payload.exp !== 'number' || !Number.isFinite(payload.exp))
|
|
16
|
+
return null;
|
|
17
|
+
return new Date(payload.exp * 1000).toISOString();
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export function credentialFreshness({ expiry, now, minimumMs, }) {
|
|
24
|
+
if (!expiry)
|
|
25
|
+
return 'missing';
|
|
26
|
+
const at = Date.parse(expiry);
|
|
27
|
+
if (!Number.isFinite(at) || at <= now)
|
|
28
|
+
return 'expired';
|
|
29
|
+
if (at - now < minimumMs)
|
|
30
|
+
return 'soon';
|
|
31
|
+
return 'ok';
|
|
32
|
+
}
|
|
33
|
+
export function importMayProceed({ yes, sourceKind, freshness, }) {
|
|
34
|
+
if (!yes)
|
|
35
|
+
return { proceed: false, exitCode: 0, reason: 'Preflight only. Re-run with --yes to import.' };
|
|
36
|
+
if (sourceKind === 'gcs' && freshness !== 'ok')
|
|
37
|
+
return {
|
|
38
|
+
proceed: false,
|
|
39
|
+
exitCode: 1,
|
|
40
|
+
reason: 'GCS credentials are missing or expire within 10 minutes. Refresh gcloud auth, then re-run.',
|
|
41
|
+
};
|
|
42
|
+
return { proceed: true, exitCode: 0, reason: '' };
|
|
43
|
+
}
|
|
44
|
+
export function formatImportPreflight(info) {
|
|
45
|
+
const gcp = info.gcloudError
|
|
46
|
+
? `unavailable (${info.gcloudError})`
|
|
47
|
+
: `${info.gcpProject ?? 'unset'} as ${info.gcpAccount ?? 'unset'}, expires ${info.gcpCredentialExpiry ?? 'unknown'}`;
|
|
48
|
+
return [
|
|
49
|
+
'Workspaces V2 import preflight',
|
|
50
|
+
` Atlas URL: ${info.atlasUrl}`,
|
|
51
|
+
` Environment: ${info.environment}`,
|
|
52
|
+
` GCP project: ${gcp}`,
|
|
53
|
+
` Atlas token expiry: ${info.atlasTokenExpiry ?? 'unknown'}`,
|
|
54
|
+
` Source: ${info.source}`,
|
|
55
|
+
` Destination workspace: ${info.workspaceName} (${info.workspaceId})`,
|
|
56
|
+
` Destination prefix: ${info.destinationPrefix || '(workspace root)'}`,
|
|
57
|
+
` Objects: ${info.objectCount} (${info.totalBytes} bytes)`,
|
|
58
|
+
` Pending uploads: ${info.pendingForYou} of ${info.perPrincipal} for you (workspace limit ${info.perWorkspace})`,
|
|
59
|
+
` Transfer concurrency: ${info.concurrency} (maximum ${STORAGE_IMPORT_CONCURRENCY_MAX})`,
|
|
60
|
+
` Progress file: ${info.progressPath}`,
|
|
61
|
+
].join('\n');
|
|
62
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ImportProgressEntry } from './import-plan.js';
|
|
2
|
+
/** Prototype keys such as `__proto__` are ordinary filenames, not inherited properties. */
|
|
3
|
+
export declare function progressRecord(entries?: Record<string, ImportProgressEntry>): Record<string, ImportProgressEntry>;
|
|
4
|
+
export declare function progressRecordFromUnknown(value: unknown, parseEntry: (entry: unknown) => ImportProgressEntry): Record<string, ImportProgressEntry>;
|
|
5
|
+
export declare function storedProgress(entries: Record<string, ImportProgressEntry>, relativePath: string): ImportProgressEntry | undefined;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Prototype keys such as `__proto__` are ordinary filenames, not inherited properties. */
|
|
2
|
+
export function progressRecord(entries) {
|
|
3
|
+
const record = Object.create(null);
|
|
4
|
+
if (!entries)
|
|
5
|
+
return record;
|
|
6
|
+
for (const [key, value] of Object.entries(entries))
|
|
7
|
+
record[key] = value;
|
|
8
|
+
return record;
|
|
9
|
+
}
|
|
10
|
+
export function progressRecordFromUnknown(value, parseEntry) {
|
|
11
|
+
if (value === undefined)
|
|
12
|
+
return progressRecord();
|
|
13
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
14
|
+
throw new Error('Progress entries must be an object');
|
|
15
|
+
const record = progressRecord();
|
|
16
|
+
for (const [key, entry] of Object.entries(value))
|
|
17
|
+
record[key] = parseEntry(entry);
|
|
18
|
+
return record;
|
|
19
|
+
}
|
|
20
|
+
export function storedProgress(entries, relativePath) {
|
|
21
|
+
return Object.hasOwn(entries, relativePath) ? entries[relativePath] : undefined;
|
|
22
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { type StartStorageUpload } from '@sequenceholdings/storage';
|
|
2
|
+
import type { ClassifiedImport, ImportProgress, ImportSourceObject } from './import-plan.js';
|
|
3
|
+
type ResumeItem = ClassifiedImport['resume'][number];
|
|
4
|
+
export declare function retryIdempotencyKey({ key, uploadId, }: {
|
|
5
|
+
key: string;
|
|
6
|
+
uploadId: string;
|
|
7
|
+
}): string;
|
|
8
|
+
export declare function inflightDisposition({ state, expiresAt, now, }: {
|
|
9
|
+
state: 'pending' | 'complete' | 'aborted' | 'missing';
|
|
10
|
+
expiresAt?: string;
|
|
11
|
+
now: number;
|
|
12
|
+
}): 'resume' | 'done' | 'replace';
|
|
13
|
+
interface UploadSession {
|
|
14
|
+
id: string;
|
|
15
|
+
fileId: string;
|
|
16
|
+
state: 'pending' | 'complete' | 'aborted';
|
|
17
|
+
expiresAt: string;
|
|
18
|
+
}
|
|
19
|
+
interface StoredNode {
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
parentId: string | null;
|
|
23
|
+
revision: number;
|
|
24
|
+
currentVersionId: string | null;
|
|
25
|
+
size: number | null;
|
|
26
|
+
}
|
|
27
|
+
export interface ResumeWorkspace {
|
|
28
|
+
uploads: {
|
|
29
|
+
get: (id: string) => Promise<UploadSession>;
|
|
30
|
+
};
|
|
31
|
+
getNode: (id: string) => Promise<StoredNode>;
|
|
32
|
+
versions?: (fileId: string) => Promise<{
|
|
33
|
+
items: Array<{
|
|
34
|
+
id: string;
|
|
35
|
+
checksum: string;
|
|
36
|
+
}>;
|
|
37
|
+
}>;
|
|
38
|
+
}
|
|
39
|
+
export interface RecoveredStart {
|
|
40
|
+
object: ImportSourceObject;
|
|
41
|
+
destination: string;
|
|
42
|
+
idempotencyKey: string;
|
|
43
|
+
/** Replay of a reservation already requested. It does not need a free slot. */
|
|
44
|
+
replay: boolean;
|
|
45
|
+
input: StartStorageUpload;
|
|
46
|
+
resumeItem: ResumeItem;
|
|
47
|
+
}
|
|
48
|
+
type WaveItem = {
|
|
49
|
+
object: ImportSourceObject;
|
|
50
|
+
destination: string;
|
|
51
|
+
idempotencyKey: string;
|
|
52
|
+
};
|
|
53
|
+
/** Reserve this wave, after its idempotency keys are durable. */
|
|
54
|
+
export declare function prepareWave({ workspace, progress, progressPath, resume, starts, wave, parentId, }: {
|
|
55
|
+
workspace: ResumeWorkspace & {
|
|
56
|
+
uploads: ResumeWorkspace['uploads'] & {
|
|
57
|
+
startBatch: (items: StartStorageUpload[]) => Promise<{
|
|
58
|
+
items: Array<{
|
|
59
|
+
id: string;
|
|
60
|
+
fileId: string;
|
|
61
|
+
}>;
|
|
62
|
+
}>;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
progress: ImportProgress;
|
|
66
|
+
progressPath: string;
|
|
67
|
+
resume: ResumeItem[];
|
|
68
|
+
starts: RecoveredStart[];
|
|
69
|
+
wave: WaveItem[];
|
|
70
|
+
parentId: string | null;
|
|
71
|
+
}): Promise<Array<{
|
|
72
|
+
object: ImportSourceObject;
|
|
73
|
+
sessionId: string;
|
|
74
|
+
idempotencyKey: string;
|
|
75
|
+
}>>;
|
|
76
|
+
export declare function recoverResume({ workspace, resume, parentId, now, }: {
|
|
77
|
+
workspace: ResumeWorkspace;
|
|
78
|
+
resume: ResumeItem[];
|
|
79
|
+
parentId: string | null;
|
|
80
|
+
now?: number;
|
|
81
|
+
}): Promise<{
|
|
82
|
+
resume: Array<ResumeItem & {
|
|
83
|
+
sessionId: string;
|
|
84
|
+
}>;
|
|
85
|
+
starts: RecoveredStart[];
|
|
86
|
+
done: Array<{
|
|
87
|
+
relativePath: string;
|
|
88
|
+
fileId: string;
|
|
89
|
+
uploadId: string;
|
|
90
|
+
idempotencyKey: string;
|
|
91
|
+
}>;
|
|
92
|
+
conflicts: Array<{
|
|
93
|
+
relativePath: string;
|
|
94
|
+
reason: string;
|
|
95
|
+
}>;
|
|
96
|
+
}>;
|
|
97
|
+
export {};
|