@sequenceholdings/studio-cli 1.0.0 → 1.0.2
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 +3 -2
- package/dist/access/custom-role-hosts.js +8 -6
- package/dist/app/manifest-validation.js +4 -2
- package/dist/app/manifest.d.ts +2 -0
- package/dist/app/manifest.js +2 -0
- package/dist/app/paths.js +3 -0
- package/dist/app-preview/bundle-dependencies.d.ts +52 -0
- package/dist/app-preview/bundle-dependencies.js +121 -0
- package/dist/app-preview/commands.d.ts +2 -5
- package/dist/app-preview/commands.js +57 -62
- package/dist/app-preview/fork-setup.d.ts +66 -0
- package/dist/app-preview/fork-setup.js +123 -0
- package/dist/app-preview/fork.d.ts +171 -0
- package/dist/app-preview/fork.js +279 -0
- package/dist/app-preview/install.d.ts +23 -2
- package/dist/app-preview/install.js +67 -6
- package/dist/app-preview/orm-sdk.d.ts +31 -0
- package/dist/app-preview/orm-sdk.js +16 -0
- package/dist/app-preview/plan.d.ts +2 -0
- package/dist/app-preview/plan.js +2 -2
- package/dist/app-preview/report.d.ts +30 -0
- package/dist/app-preview/report.js +80 -0
- package/dist/app-preview/repository-manifest.d.ts +83 -0
- package/dist/app-preview/repository-manifest.js +179 -0
- package/dist/app-preview/runners.d.ts +14 -0
- package/dist/app-preview/runners.js +83 -23
- package/dist/app-preview/session-output.d.ts +5 -0
- package/dist/app-preview/session-output.js +28 -0
- package/dist/app-preview/source-includes.d.ts +12 -0
- package/dist/app-preview/source-includes.js +74 -0
- package/dist/app-preview/target.d.ts +8 -0
- package/dist/app-preview/target.js +4 -1
- package/dist/app-preview/usage.d.ts +7 -0
- package/dist/app-preview/usage.js +57 -0
- package/dist/envs/commands.js +2 -1
- package/dist/login.js +1 -1
- package/dist/orm/break-glass.d.ts +15 -0
- package/dist/orm/break-glass.js +22 -0
- package/dist/orm/delegate.js +10 -8
- package/dist/orm/version-guard.d.ts +6 -2
- package/dist/orm/version-guard.js +27 -7
- package/dist/registry/help.js +5 -6
- package/dist/repos/github-init.js +4 -1
- package/dist/repos/primitive-declaration.d.ts +27 -0
- package/dist/repos/primitive-declaration.js +22 -6
- package/dist/repos/seq-ci-release.d.ts +10 -0
- package/dist/repos/seq-ci-release.js +27 -0
- package/dist/sdk-source.d.ts +15 -0
- package/dist/sdk-source.js +30 -11
- package/package.json +5 -5
- package/release-summary.json +3 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
-
import { join } from 'node:path';
|
|
3
|
+
import { dirname, isAbsolute, join, relative, sep } from 'node:path';
|
|
4
|
+
import { parse as parseYaml } from 'yaml';
|
|
4
5
|
/**
|
|
5
6
|
* A frozen install fails when pnpm's peer setting differs from the one the lockfile was written
|
|
6
7
|
* with, and a fresh clone has no local workspace file to say which that was. The lockfile records
|
|
@@ -19,15 +20,59 @@ const readText = (path) => {
|
|
|
19
20
|
return undefined;
|
|
20
21
|
}
|
|
21
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* A hosted build replaces an app's workspace file with the platform's own, which has no
|
|
25
|
+
* `overrides`, so an app built there commits a lockfile that does not record the overrides its
|
|
26
|
+
* workspace file declares. A frozen install with that workspace file is refused; installing as the
|
|
27
|
+
* hosted build does, without it, is not. Only for a workspace of the one package: without its
|
|
28
|
+
* workspace file a larger one would install its root alone.
|
|
29
|
+
*/
|
|
30
|
+
export function lockfileOmitsWorkspaceOverrides({ workspace, lockfile }) {
|
|
31
|
+
if (workspace === undefined || /^overrides:/m.test(lockfile))
|
|
32
|
+
return false;
|
|
33
|
+
let parsed;
|
|
34
|
+
try {
|
|
35
|
+
parsed = parseYaml(workspace);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
if (typeof parsed !== 'object' || parsed === null)
|
|
41
|
+
return false;
|
|
42
|
+
const overrides = Reflect.get(parsed, 'overrides');
|
|
43
|
+
const packages = Reflect.get(parsed, 'packages');
|
|
44
|
+
const declaresOverrides = typeof overrides === 'object' && overrides !== null && Object.keys(overrides).length > 0;
|
|
45
|
+
const onePackage = packages === undefined || (Array.isArray(packages) && packages.every((entry) => entry === '.'));
|
|
46
|
+
return declaresOverrides && onePackage;
|
|
47
|
+
}
|
|
48
|
+
/** Whether `directory` is `root` or below it. */
|
|
49
|
+
const within = (root, directory) => {
|
|
50
|
+
const path = relative(root, directory);
|
|
51
|
+
return path !== '..' && !path.startsWith(`..${sep}`) && !isAbsolute(path);
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* The nearest directory from `dir` up to, but not including, the app root that keeps its own workspace
|
|
55
|
+
* or lockfile. A process bundle keeps its package one level above each process's directory, so the
|
|
56
|
+
* primitive's own directory is not the only place a standalone install can live.
|
|
57
|
+
*/
|
|
58
|
+
function standaloneRoot({ dir, appRoot, exists }) {
|
|
59
|
+
const own = (directory) => exists(join(directory, 'pnpm-workspace.yaml')) || exists(join(directory, 'pnpm-lock.yaml'));
|
|
60
|
+
if (!within(appRoot, dir))
|
|
61
|
+
return own(dir) ? dir : undefined;
|
|
62
|
+
for (let directory = dir; directory !== appRoot; directory = dirname(directory)) {
|
|
63
|
+
if (own(directory))
|
|
64
|
+
return directory;
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
22
68
|
/**
|
|
23
69
|
* A fresh clone has no node_modules, and an artifact cannot build without them. Install where the
|
|
24
|
-
* artifact resolves its dependencies from:
|
|
25
|
-
* lockfile, else the app root. A committed lockfile is installed exactly; one is never rewritten
|
|
70
|
+
* artifact resolves its dependencies from: the nearest directory, its own or one above it inside the
|
|
71
|
+
* app, that keeps its own workspace or lockfile, else the app root. A committed lockfile is installed exactly; one is never rewritten
|
|
26
72
|
* by a preview.
|
|
27
73
|
*/
|
|
28
74
|
export function decideInstall({ artifactDir, appRoot, exists = existsSync, read = readText }) {
|
|
29
|
-
const
|
|
30
|
-
const root = standalone ? artifactDir : appRoot;
|
|
75
|
+
const root = standaloneRoot({ dir: artifactDir, appRoot, exists }) ?? appRoot;
|
|
31
76
|
if (!exists(join(root, 'package.json')))
|
|
32
77
|
return { install: false, reason: 'no-package' };
|
|
33
78
|
if (exists(join(root, 'node_modules')))
|
|
@@ -40,9 +85,25 @@ export function decideInstall({ artifactDir, appRoot, exists = existsSync, read
|
|
|
40
85
|
install: true,
|
|
41
86
|
root,
|
|
42
87
|
// Dependency build scripts are not needed to bundle a browser app and are not run for a preview.
|
|
43
|
-
args: [
|
|
88
|
+
args: [
|
|
89
|
+
'install', '--frozen-lockfile', '--ignore-scripts',
|
|
90
|
+
...(peers === undefined ? [] : [`--config.auto-install-peers=${peers}`]),
|
|
91
|
+
...(lockfileOmitsWorkspaceOverrides({ workspace: read(join(root, 'pnpm-workspace.yaml')), lockfile }) ? ['--ignore-workspace'] : []),
|
|
92
|
+
],
|
|
44
93
|
};
|
|
45
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Where an artifact of a repository with no app manifest installs from, chosen as repository CI chooses it:
|
|
97
|
+
* the nearest directory at or above the artifact, no higher than the git root, that holds a lockfile; the
|
|
98
|
+
* artifact's own directory when there is none. Only pnpm's lockfile counts, since pnpm is what installs here.
|
|
99
|
+
*/
|
|
100
|
+
export function repositoryInstallRoot({ artifactDir, gitRoot, exists = existsSync }) {
|
|
101
|
+
for (let directory = artifactDir; within(gitRoot, directory); directory = dirname(directory)) {
|
|
102
|
+
if (exists(join(directory, 'pnpm-lock.yaml')))
|
|
103
|
+
return directory;
|
|
104
|
+
}
|
|
105
|
+
return artifactDir;
|
|
106
|
+
}
|
|
46
107
|
/** Progress goes to stderr so `--json` output stays a single document. */
|
|
47
108
|
export async function installDependencies({ root, args }) {
|
|
48
109
|
return new Promise((resolvePromise, reject) => {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type OrmSdkChoice =
|
|
2
|
+
/** Nothing to decide: the namespace pins no range, or the bundled ORM satisfies it. */
|
|
3
|
+
{
|
|
4
|
+
use: 'default';
|
|
5
|
+
} | {
|
|
6
|
+
use: 'project';
|
|
7
|
+
version: string;
|
|
8
|
+
}
|
|
9
|
+
/** The range is satisfied by neither the bundled ORM nor what the namespace has installed. */
|
|
10
|
+
| {
|
|
11
|
+
use: 'install';
|
|
12
|
+
range: string;
|
|
13
|
+
bundled?: string;
|
|
14
|
+
installed?: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Which ORM applies a namespace. A namespace pinned to a range the bundled ORM is outside of is compiled by
|
|
18
|
+
* its own installed copy; the bundled one would be refused by the version guard.
|
|
19
|
+
*/
|
|
20
|
+
export declare function chooseOrmSdk({ range, bundled, project }: {
|
|
21
|
+
range: string | null;
|
|
22
|
+
bundled?: string;
|
|
23
|
+
project?: string;
|
|
24
|
+
}): OrmSdkChoice;
|
|
25
|
+
export declare function installOrmMessage({ namespace, dir, choice }: {
|
|
26
|
+
namespace: string;
|
|
27
|
+
dir: string;
|
|
28
|
+
choice: Extract<OrmSdkChoice, {
|
|
29
|
+
use: 'install';
|
|
30
|
+
}>;
|
|
31
|
+
}): string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { satisfies } from 'semver';
|
|
2
|
+
/**
|
|
3
|
+
* Which ORM applies a namespace. A namespace pinned to a range the bundled ORM is outside of is compiled by
|
|
4
|
+
* its own installed copy; the bundled one would be refused by the version guard.
|
|
5
|
+
*/
|
|
6
|
+
export function chooseOrmSdk({ range, bundled, project }) {
|
|
7
|
+
if (range === null || (bundled !== undefined && satisfies(bundled, range)))
|
|
8
|
+
return { use: 'default' };
|
|
9
|
+
if (project !== undefined && satisfies(project, range))
|
|
10
|
+
return { use: 'project', version: project };
|
|
11
|
+
return { use: 'install', range, bundled, installed: project };
|
|
12
|
+
}
|
|
13
|
+
export function installOrmMessage({ namespace, dir, choice }) {
|
|
14
|
+
return `namespace ${namespace} requires @sequenceholdings/orm ${choice.range}; this seq-studio bundles ${choice.bundled ?? 'none'} and ` +
|
|
15
|
+
`${choice.installed ? `${dir} has ${choice.installed} installed` : `${dir} has none installed`}. Run: (cd ${dir} && pnpm install)`;
|
|
16
|
+
}
|
|
@@ -14,6 +14,8 @@ export interface PreviewPlan {
|
|
|
14
14
|
steps: PreviewStep[];
|
|
15
15
|
/** Declared in the manifest but not needed by what is being previewed. */
|
|
16
16
|
omitted: PrimitiveEntry[];
|
|
17
|
+
/** The ids the plan starts from: `only`, or the app's artifacts. */
|
|
18
|
+
selected: string[];
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
19
21
|
* Choose what to stand up and in which order.
|
package/dist/app-preview/plan.js
CHANGED
|
@@ -7,7 +7,7 @@ const ACTION_BY_KIND = {
|
|
|
7
7
|
process: 'apply-process',
|
|
8
8
|
};
|
|
9
9
|
const UNSUPPORTED_REASON = {
|
|
10
|
-
workspace: 'a
|
|
10
|
+
workspace: 'a preview does not create workspaces; on a devbox fork it adopts this one from the database copy',
|
|
11
11
|
agent: 'agents are not part of an app preview; deploy them with seq-studio agent apply',
|
|
12
12
|
pipeline: 'pipelines run on the data platform, not on a local Atlas',
|
|
13
13
|
};
|
|
@@ -37,5 +37,5 @@ export function planPreview({ manifest, only }) {
|
|
|
37
37
|
? { entry, action }
|
|
38
38
|
: { entry, action: 'unsupported', reason: UNSUPPORTED_REASON[entry.kind] ?? `${entry.kind} primitives cannot be previewed` };
|
|
39
39
|
});
|
|
40
|
-
return { steps, omitted: primitives.filter((entry) => !needed.has(entry.id)) };
|
|
40
|
+
return { steps, omitted: primitives.filter((entry) => !needed.has(entry.id)), selected };
|
|
41
41
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Prerequisite } from './bundle-dependencies.js';
|
|
2
|
+
import type { PreviewFork, SecretSourceDecision } from './fork.js';
|
|
3
|
+
import type { PreviewPlan } from './plan.js';
|
|
4
|
+
import { type PreviewManifest } from './repository-manifest.js';
|
|
5
|
+
import type { FunctionInspection } from './runners.js';
|
|
6
|
+
/** What a function can reach and where each secret comes from, shown before it deploys. */
|
|
7
|
+
export declare function functionReport(inspection: FunctionInspection): string[];
|
|
8
|
+
/** Says where the plan came from when the app has no manifest of its own. */
|
|
9
|
+
export declare function sourceReport(preview: PreviewManifest): string[];
|
|
10
|
+
/** What each artifact declares that the preview leaves to its operator. */
|
|
11
|
+
export declare function prerequisiteReport(prerequisites: readonly Prerequisite[]): string[];
|
|
12
|
+
/**
|
|
13
|
+
* How to register the processes an artifact starts. A preview registers only a process it plans, and a
|
|
14
|
+
* database copy brings a process's record without its compiled bundle, so a run of one that was only
|
|
15
|
+
* copied fails to start. Said once, with the command, when an artifact starts a process this plan leaves out.
|
|
16
|
+
*/
|
|
17
|
+
export declare function processRegistrationHint({ preview, plan, prerequisites }: {
|
|
18
|
+
preview: Pick<PreviewManifest, 'repositoryResources'>;
|
|
19
|
+
plan: Pick<PreviewPlan, 'steps'>;
|
|
20
|
+
prerequisites: readonly Prerequisite[];
|
|
21
|
+
}): string[];
|
|
22
|
+
/** What a preview sets up first on a devbox's copy of a hosted deployment's database, said before any of it happens. */
|
|
23
|
+
export declare function forkReport({ fork, workspaceNames, secretSource, next }: {
|
|
24
|
+
fork: PreviewFork | undefined;
|
|
25
|
+
workspaceNames: readonly string[];
|
|
26
|
+
secretSource: SecretSourceDecision | undefined;
|
|
27
|
+
next: {
|
|
28
|
+
projectId: string;
|
|
29
|
+
} | undefined;
|
|
30
|
+
}): string[];
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { APP_MANIFEST_FILENAME } from '../app/manifest.js';
|
|
2
|
+
import { REPOSITORY_INDEX_PATH } from '../app/repository-index.js';
|
|
3
|
+
import { LOG } from '../prompt.js';
|
|
4
|
+
import { unplannedProcessResources } from './repository-manifest.js';
|
|
5
|
+
import { describeSecretSource } from './secrets.js';
|
|
6
|
+
/** What a function can reach and where each secret comes from, shown before it deploys. */
|
|
7
|
+
export function functionReport(inspection) {
|
|
8
|
+
const lines = [`${LOG} function ${inspection.slug} (${inspection.entry.id})`];
|
|
9
|
+
lines.push(inspection.egress.length
|
|
10
|
+
? `${LOG} declares egress to: ${inspection.egress.join(', ')}`
|
|
11
|
+
: `${LOG} declares no egress`);
|
|
12
|
+
lines.push(`${LOG} egress is NOT enforced here: the local runtime can reach any host its credentials open`);
|
|
13
|
+
if (inspection.secrets.sources.length === 0 && inspection.unavailableSets.length === 0) {
|
|
14
|
+
lines.push(`${LOG} secrets: none declared`);
|
|
15
|
+
}
|
|
16
|
+
for (const source of inspection.secrets.sources) {
|
|
17
|
+
lines.push(`${LOG} secret ${source.name}: ${describeSecretSource(source)}`);
|
|
18
|
+
}
|
|
19
|
+
for (const set of inspection.unavailableSets) {
|
|
20
|
+
lines.push(`${LOG} key/value set ${set}: NO VALUE in this local Atlas`);
|
|
21
|
+
}
|
|
22
|
+
return lines;
|
|
23
|
+
}
|
|
24
|
+
/** Says where the plan came from when the app has no manifest of its own. */
|
|
25
|
+
export function sourceReport(preview) {
|
|
26
|
+
if (preview.source === 'app-manifest')
|
|
27
|
+
return [];
|
|
28
|
+
return [
|
|
29
|
+
`${LOG} no ${APP_MANIFEST_FILENAME} here: using the resources ${REPOSITORY_INDEX_PATH} declares under ${preview.requestedPath}, ` +
|
|
30
|
+
'and what each artifact.bundle.yml reaches',
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
/** What each artifact declares that the preview leaves to its operator. */
|
|
34
|
+
export function prerequisiteReport(prerequisites) {
|
|
35
|
+
const lines = [];
|
|
36
|
+
for (const artifact of new Set(prerequisites.map((line) => line.artifact))) {
|
|
37
|
+
lines.push(`${LOG} artifact ${artifact} declares, and this preview does not set up:`);
|
|
38
|
+
for (const line of prerequisites)
|
|
39
|
+
if (line.artifact === artifact)
|
|
40
|
+
lines.push(`${LOG} ${line.detail}`);
|
|
41
|
+
}
|
|
42
|
+
return lines;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* How to register the processes an artifact starts. A preview registers only a process it plans, and a
|
|
46
|
+
* database copy brings a process's record without its compiled bundle, so a run of one that was only
|
|
47
|
+
* copied fails to start. Said once, with the command, when an artifact starts a process this plan leaves out.
|
|
48
|
+
*/
|
|
49
|
+
export function processRegistrationHint({ preview, plan, prerequisites }) {
|
|
50
|
+
if (!prerequisites.some((line) => line.kind === 'process'))
|
|
51
|
+
return [];
|
|
52
|
+
const unplanned = unplannedProcessResources({ resources: preview.repositoryResources, planned: plan.steps.map((step) => step.entry) });
|
|
53
|
+
if (unplanned.length === 0)
|
|
54
|
+
return [];
|
|
55
|
+
return [
|
|
56
|
+
`${LOG} processes an artifact starts are not registered by this preview. A copied database has their records but ` +
|
|
57
|
+
'not their bundles, so a run cannot start until the process is registered on this Atlas. This repository declares:',
|
|
58
|
+
...unplanned.map(({ id, path }) => `${LOG} ${id}: seq-studio preview ${path} --only ${id} -e local`),
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
/** What a preview sets up first on a devbox's copy of a hosted deployment's database, said before any of it happens. */
|
|
62
|
+
export function forkReport({ fork, workspaceNames, secretSource, next }) {
|
|
63
|
+
const nextProject = next?.projectId;
|
|
64
|
+
const lines = [];
|
|
65
|
+
if (fork && workspaceNames.length) {
|
|
66
|
+
lines.push(`workspaces ${workspaceNames.join(', ')}: adopted from the database copy before anything starts. ` +
|
|
67
|
+
'Their files are NOT copied: folders and listings work, opening or uploading a file fails with a storage error.');
|
|
68
|
+
}
|
|
69
|
+
if (fork && nextProject) {
|
|
70
|
+
lines.push(`service identities the copied project ${nextProject} records: approved for development sessions on this fork only`);
|
|
71
|
+
}
|
|
72
|
+
if (secretSource?.line)
|
|
73
|
+
lines.push(secretSource.line);
|
|
74
|
+
if (lines.length === 0)
|
|
75
|
+
return [];
|
|
76
|
+
const heading = fork
|
|
77
|
+
? `this database is a devbox's copy of ${fork.upstreamEnvironment ?? 'another deployment'}; what the copy does not carry:`
|
|
78
|
+
: 'server secrets:';
|
|
79
|
+
return [`${LOG} ${heading}`, ...lines.map((line) => `${LOG} ${line}`)];
|
|
80
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { type AppManifest, type PrimitiveEntry } from '../app/manifest.js';
|
|
2
|
+
import { type IndexedResource } from '../repos/primitive-declaration.js';
|
|
3
|
+
import { type BundleDependencies } from './bundle-dependencies.js';
|
|
4
|
+
export type PreviewManifestSource = 'app-manifest' | 'repository-index';
|
|
5
|
+
export interface PreviewManifest {
|
|
6
|
+
manifest: AppManifest;
|
|
7
|
+
source: PreviewManifestSource;
|
|
8
|
+
/** What primitive paths are relative to: the app directory, or the git root when the manifest came from the index. */
|
|
9
|
+
rootDir: string;
|
|
10
|
+
/** The directory that was asked for; for an index-derived manifest, where it really is (symlinks resolved). */
|
|
11
|
+
appDir: string;
|
|
12
|
+
/** `appDir` relative to `rootDir` (`.` when they are the same). */
|
|
13
|
+
requestedPath: string;
|
|
14
|
+
/** Ids declared at or under `appDir`. A dependency found elsewhere in the index is in the manifest but not here. */
|
|
15
|
+
inDirectory: ReadonlySet<string>;
|
|
16
|
+
/** By artifact id: what its bundle reaches that no index resource declares. */
|
|
17
|
+
unresolved: Readonly<Record<string, BundleDependencies['unresolved']>>;
|
|
18
|
+
/** Every resource the repository's index declares; none for an app read from its own manifest. */
|
|
19
|
+
repositoryResources: ReadonlyArray<{
|
|
20
|
+
id: string;
|
|
21
|
+
kind?: string;
|
|
22
|
+
path: string;
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Build the manifest for the resources at or under `requestedPath`, or for the ones `only` names, plus
|
|
27
|
+
* everything they need from the rest of the index: a resource's own `depends_on` and what an artifact's
|
|
28
|
+
* bundle reaches. `bundles` holds each artifact's parsed `artifact.bundle.yml` by resource id.
|
|
29
|
+
*/
|
|
30
|
+
export declare function manifestFromIndex({ resources, requestedPath, bundles, appId, cliVersion, only }: {
|
|
31
|
+
resources: readonly IndexedResource[];
|
|
32
|
+
requestedPath: string;
|
|
33
|
+
bundles: Readonly<Record<string, unknown>>;
|
|
34
|
+
appId: string;
|
|
35
|
+
cliVersion: string;
|
|
36
|
+
only?: readonly string[];
|
|
37
|
+
}): Pick<PreviewManifest, 'manifest' | 'inDirectory' | 'unresolved'>;
|
|
38
|
+
/**
|
|
39
|
+
* The repository's process resources a plan leaves out, nearest first: those in the same top-level
|
|
40
|
+
* directory as a planned artifact, which is where an app keeps its own. A repository of many apps
|
|
41
|
+
* declares many more; they are listed only when none sits beside the artifact.
|
|
42
|
+
*
|
|
43
|
+
* An artifact names the processes it starts by process id, and a resource bundles several under its
|
|
44
|
+
* own id, so the two cannot be matched without building; these are what its operator may need to
|
|
45
|
+
* register. `planned` is the plan's steps, not the manifest: a process under the previewed directory
|
|
46
|
+
* is in the manifest and still left out of a plan that starts from the artifact.
|
|
47
|
+
*/
|
|
48
|
+
export declare function unplannedProcessResources({ resources, planned }: {
|
|
49
|
+
resources: ReadonlyArray<{
|
|
50
|
+
id: string;
|
|
51
|
+
kind?: string;
|
|
52
|
+
path: string;
|
|
53
|
+
}>;
|
|
54
|
+
planned: ReadonlyArray<{
|
|
55
|
+
id: string;
|
|
56
|
+
kind?: string;
|
|
57
|
+
path?: string;
|
|
58
|
+
}>;
|
|
59
|
+
}): Array<{
|
|
60
|
+
id: string;
|
|
61
|
+
path: string;
|
|
62
|
+
}>;
|
|
63
|
+
export declare function loadPreviewManifest({ dir, only }: {
|
|
64
|
+
dir: string;
|
|
65
|
+
only?: readonly string[];
|
|
66
|
+
}): Promise<PreviewManifest>;
|
|
67
|
+
/**
|
|
68
|
+
* Whether `--apply-orm` applies this namespace. An index-derived preview applies only what the requested
|
|
69
|
+
* directory declares: a namespace pulled in from elsewhere in the repository belongs to another owner, so it
|
|
70
|
+
* is read and left as it is unless it was named with `--only`. `--only` replaces what the preview starts
|
|
71
|
+
* from, so the note names the whole selection to pass.
|
|
72
|
+
*/
|
|
73
|
+
export declare function ormApplyScope({ applyOrm, entry, preview, only, started }: {
|
|
74
|
+
applyOrm: boolean;
|
|
75
|
+
entry: Pick<PrimitiveEntry, 'id' | 'path'>;
|
|
76
|
+
preview: Pick<PreviewManifest, 'source' | 'inDirectory' | 'requestedPath'>;
|
|
77
|
+
only?: readonly string[];
|
|
78
|
+
/** What this preview starts from: `--only`, or the artifacts it defaults to. */
|
|
79
|
+
started?: readonly string[];
|
|
80
|
+
}): {
|
|
81
|
+
apply: boolean;
|
|
82
|
+
note?: string;
|
|
83
|
+
};
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The manifest a preview plans from. An app with a `sequence.app.yml` is read as it is. An app declared only
|
|
3
|
+
* as resources in its repository's `.seq/repository.yml` gets a manifest built in memory from the resources
|
|
4
|
+
* at or under the requested directory, with each artifact's dependencies read from its `artifact.bundle.yml`
|
|
5
|
+
* (the index carries none). Nothing is written to the app's checkout.
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync } from 'node:fs';
|
|
8
|
+
import { readFile, realpath } from 'node:fs/promises';
|
|
9
|
+
import { basename, join, relative, resolve, sep } from 'node:path';
|
|
10
|
+
import { parse as parseYaml } from 'yaml';
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
import { APP_MANIFEST_FILENAME, loadAppManifest, parseAppManifest, PRIMITIVE_ENTRY_FIELDS, slugifyAppId, titleizeSlug, } from '../app/manifest.js';
|
|
13
|
+
import { findGitRoot, REPOSITORY_INDEX_PATH, under } from '../app/repository-index.js';
|
|
14
|
+
import { readRepositoryResources } from '../repos/primitive-declaration.js';
|
|
15
|
+
import { currentVersion } from '../update-check.js';
|
|
16
|
+
import { inferBundleDependencies } from './bundle-dependencies.js';
|
|
17
|
+
const BUNDLE_FILENAME = 'artifact.bundle.yml';
|
|
18
|
+
/** A resource's manifest fields: `stages`, `ci` and whatever else the index carries are not part of an app manifest. */
|
|
19
|
+
function toEntry(resource) {
|
|
20
|
+
return Object.fromEntries(PRIMITIVE_ENTRY_FIELDS.flatMap((field) => {
|
|
21
|
+
const value = Reflect.get(resource, field);
|
|
22
|
+
return value === undefined || value === null ? [] : [[field, value]];
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
const declaredDependencies = (resource) => {
|
|
26
|
+
const value = Reflect.get(resource, 'depends_on');
|
|
27
|
+
return Array.isArray(value) ? value.filter((id) => typeof id === 'string') : [];
|
|
28
|
+
};
|
|
29
|
+
/** A kebab-case app id from a directory name, which may start with a digit or hold other characters. */
|
|
30
|
+
function appIdFor(directory) {
|
|
31
|
+
const slug = slugifyAppId(basename(directory));
|
|
32
|
+
return (/^[a-z]/.test(slug) ? slug : `app-${slug}`).slice(0, 64).replace(/-+$/, '');
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Build the manifest for the resources at or under `requestedPath`, or for the ones `only` names, plus
|
|
36
|
+
* everything they need from the rest of the index: a resource's own `depends_on` and what an artifact's
|
|
37
|
+
* bundle reaches. `bundles` holds each artifact's parsed `artifact.bundle.yml` by resource id.
|
|
38
|
+
*/
|
|
39
|
+
export function manifestFromIndex({ resources, requestedPath, bundles, appId, cliVersion, only = [] }) {
|
|
40
|
+
const byId = new Map(resources.map((resource) => [resource.id, resource]));
|
|
41
|
+
const local = resources.filter((resource) => under({ path: resource.path, root: requestedPath }));
|
|
42
|
+
const dependsOn = new Map();
|
|
43
|
+
const unresolved = {};
|
|
44
|
+
// `--only` replaces what the preview starts from, so nothing else under the directory is planned, or read.
|
|
45
|
+
const named = only.filter((id) => byId.has(id));
|
|
46
|
+
const pending = named.length > 0 ? named : local.map((resource) => resource.id);
|
|
47
|
+
while (pending.length > 0) {
|
|
48
|
+
const id = pending.pop();
|
|
49
|
+
const resource = byId.get(id);
|
|
50
|
+
// An id the index does not declare stays in depends_on, where the manifest check names it.
|
|
51
|
+
if (!resource || dependsOn.has(id))
|
|
52
|
+
continue;
|
|
53
|
+
const inferred = resource.kind === 'artifact' && id in bundles
|
|
54
|
+
? inferBundleDependencies({ bundle: bundles[id], resources })
|
|
55
|
+
: { dependsOn: [], unresolved: [] };
|
|
56
|
+
if (inferred.unresolved.length)
|
|
57
|
+
unresolved[id] = inferred.unresolved;
|
|
58
|
+
const needs = [...new Set([...declaredDependencies(resource), ...inferred.dependsOn])].filter((dependency) => dependency !== id);
|
|
59
|
+
dependsOn.set(id, needs);
|
|
60
|
+
pending.push(...needs);
|
|
61
|
+
}
|
|
62
|
+
// Index order, so the plan's tie-breaks do not depend on which resource pulled another in.
|
|
63
|
+
const primitives = resources
|
|
64
|
+
.filter((resource) => dependsOn.has(resource.id))
|
|
65
|
+
.map((resource) => ({ ...toEntry(resource), depends_on: dependsOn.get(resource.id) }));
|
|
66
|
+
let manifest;
|
|
67
|
+
try {
|
|
68
|
+
manifest = parseAppManifest({
|
|
69
|
+
schema_version: 3,
|
|
70
|
+
app: { id: appId, title: titleizeSlug(appId) },
|
|
71
|
+
studio: { created_with: cliVersion, min_cli: cliVersion },
|
|
72
|
+
primitives,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
if (!(error instanceof z.ZodError))
|
|
77
|
+
throw error;
|
|
78
|
+
const detail = error.issues.map((issue) => `${issue.path.join('.')}: ${issue.message}`).join('; ');
|
|
79
|
+
throw new Error(`The resources ${REPOSITORY_INDEX_PATH} declares under ${requestedPath} cannot be previewed: ${detail}`);
|
|
80
|
+
}
|
|
81
|
+
return { manifest, inDirectory: new Set(local.map((resource) => resource.id)), unresolved };
|
|
82
|
+
}
|
|
83
|
+
async function readBundle(directory) {
|
|
84
|
+
const path = join(directory, BUNDLE_FILENAME);
|
|
85
|
+
if (!existsSync(path))
|
|
86
|
+
return undefined;
|
|
87
|
+
try {
|
|
88
|
+
return parseYaml(await readFile(path, 'utf8'));
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
throw new Error(`${path} is not valid YAML: ${error instanceof Error ? error.message.split('\n')[0] : String(error)}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The repository's process resources a plan leaves out, nearest first: those in the same top-level
|
|
96
|
+
* directory as a planned artifact, which is where an app keeps its own. A repository of many apps
|
|
97
|
+
* declares many more; they are listed only when none sits beside the artifact.
|
|
98
|
+
*
|
|
99
|
+
* An artifact names the processes it starts by process id, and a resource bundles several under its
|
|
100
|
+
* own id, so the two cannot be matched without building; these are what its operator may need to
|
|
101
|
+
* register. `planned` is the plan's steps, not the manifest: a process under the previewed directory
|
|
102
|
+
* is in the manifest and still left out of a plan that starts from the artifact.
|
|
103
|
+
*/
|
|
104
|
+
export function unplannedProcessResources({ resources, planned }) {
|
|
105
|
+
const plannedIds = new Set(planned.map((entry) => entry.id));
|
|
106
|
+
const top = (path) => path.split('/')[0] ?? '';
|
|
107
|
+
const appDirs = new Set(planned.filter((entry) => entry.kind === 'artifact' && entry.path).map((entry) => top(entry.path)));
|
|
108
|
+
const unplanned = resources.filter((resource) => resource.kind === 'process' && !plannedIds.has(resource.id));
|
|
109
|
+
const beside = unplanned.filter((resource) => appDirs.has(top(resource.path)));
|
|
110
|
+
return (beside.length > 0 ? beside : unplanned).map(({ id, path }) => ({ id, path }));
|
|
111
|
+
}
|
|
112
|
+
export async function loadPreviewManifest({ dir, only }) {
|
|
113
|
+
const appDir = resolve(dir);
|
|
114
|
+
if (existsSync(join(appDir, APP_MANIFEST_FILENAME))) {
|
|
115
|
+
const manifest = await loadAppManifest(appDir);
|
|
116
|
+
return {
|
|
117
|
+
manifest,
|
|
118
|
+
source: 'app-manifest',
|
|
119
|
+
rootDir: appDir,
|
|
120
|
+
appDir,
|
|
121
|
+
requestedPath: '.',
|
|
122
|
+
inDirectory: new Set(manifest.primitives.map((entry) => entry.id)),
|
|
123
|
+
unresolved: {},
|
|
124
|
+
repositoryResources: [],
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
// The index lists paths from the git root as git sees it, so a directory reached through a symlink is
|
|
128
|
+
// matched by where it really is. The manifest check above stays lexical: it only reads <dir>/sequence.app.yml.
|
|
129
|
+
const realDir = await realpath(appDir).catch(() => appDir);
|
|
130
|
+
const gitRoot = findGitRoot(realDir);
|
|
131
|
+
const resources = gitRoot === null ? null : await readRepositoryResources({ gitRoot });
|
|
132
|
+
if (gitRoot === null || resources === null) {
|
|
133
|
+
throw new Error(`No ${APP_MANIFEST_FILENAME} in ${appDir}, and no ${REPOSITORY_INDEX_PATH} ` +
|
|
134
|
+
`${gitRoot === null ? 'because it is not inside a git repository' : `at its git root ${gitRoot}`}. ` +
|
|
135
|
+
'Pass the app\'s directory, or run `seq-studio init` to scaffold an app.');
|
|
136
|
+
}
|
|
137
|
+
const requestedPath = relative(gitRoot, realDir).split(sep).join('/') || '.';
|
|
138
|
+
if (!resources.some((resource) => under({ path: resource.path, root: requestedPath }))) {
|
|
139
|
+
throw new Error(`No ${APP_MANIFEST_FILENAME} in ${appDir}, and ${join(gitRoot, REPOSITORY_INDEX_PATH)} declares no resource at or under ${requestedPath}.`);
|
|
140
|
+
}
|
|
141
|
+
// An artifact can enter the plan through another's dependencies, and its own bundle then adds more: read
|
|
142
|
+
// each one that is planned until none is left unread. An artifact outside the plan is never opened.
|
|
143
|
+
const bundles = {};
|
|
144
|
+
const read = new Set();
|
|
145
|
+
const build = () => manifestFromIndex({ resources, requestedPath, bundles, appId: appIdFor(realDir), cliVersion: currentVersion(), only });
|
|
146
|
+
let built = build();
|
|
147
|
+
for (;;) {
|
|
148
|
+
const unread = built.manifest.primitives.filter((entry) => entry.kind === 'artifact' && !read.has(entry.id));
|
|
149
|
+
if (unread.length === 0)
|
|
150
|
+
break;
|
|
151
|
+
for (const entry of unread) {
|
|
152
|
+
read.add(entry.id);
|
|
153
|
+
// A missing bundle is reported by the artifact's own step, which names the directory.
|
|
154
|
+
const bundle = await readBundle(join(gitRoot, entry.path));
|
|
155
|
+
if (bundle !== undefined)
|
|
156
|
+
bundles[entry.id] = bundle;
|
|
157
|
+
}
|
|
158
|
+
built = build();
|
|
159
|
+
}
|
|
160
|
+
return { ...built, source: 'repository-index', rootDir: gitRoot, appDir: realDir, requestedPath, repositoryResources: resources };
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Whether `--apply-orm` applies this namespace. An index-derived preview applies only what the requested
|
|
164
|
+
* directory declares: a namespace pulled in from elsewhere in the repository belongs to another owner, so it
|
|
165
|
+
* is read and left as it is unless it was named with `--only`. `--only` replaces what the preview starts
|
|
166
|
+
* from, so the note names the whole selection to pass.
|
|
167
|
+
*/
|
|
168
|
+
export function ormApplyScope({ applyOrm, entry, preview, only = [], started = [] }) {
|
|
169
|
+
if (!applyOrm)
|
|
170
|
+
return { apply: false };
|
|
171
|
+
if (preview.source === 'app-manifest' || preview.inDirectory.has(entry.id) || only.includes(entry.id))
|
|
172
|
+
return { apply: true };
|
|
173
|
+
// --only replaces the selection, so the hint repeats what is already being previewed.
|
|
174
|
+
return {
|
|
175
|
+
apply: false,
|
|
176
|
+
note: `checked only, not applied: ${entry.path} is outside ${preview.requestedPath} ` +
|
|
177
|
+
`(to apply it too, rerun with --only ${[...new Set([...started, entry.id])].join(',')})`,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
@@ -3,7 +3,10 @@ import { type SecretPlan } from './secrets.js';
|
|
|
3
3
|
import type { StepOutcome } from './run.js';
|
|
4
4
|
import type { PreviewTarget } from './target.js';
|
|
5
5
|
export interface PreviewContext {
|
|
6
|
+
/** What primitive paths are relative to: the app directory, or the git root for an app declared in the repository index. */
|
|
6
7
|
rootDir: string;
|
|
8
|
+
/** Whether the app has its own manifest; without one an artifact installs as repository CI would. */
|
|
9
|
+
source: 'app-manifest' | 'repository-index';
|
|
7
10
|
env: string;
|
|
8
11
|
client: {
|
|
9
12
|
baseUrl: string;
|
|
@@ -22,6 +25,15 @@ export declare function checkNamespace({ ctx, entry, apply }: {
|
|
|
22
25
|
entry: PrimitiveEntry;
|
|
23
26
|
apply: boolean;
|
|
24
27
|
}): Promise<StepOutcome>;
|
|
28
|
+
/** Relations to try reading, in order: every table, then every view. */
|
|
29
|
+
export declare function probeRelations({ tables, views }: {
|
|
30
|
+
tables: readonly {
|
|
31
|
+
table: string;
|
|
32
|
+
}[];
|
|
33
|
+
views: readonly {
|
|
34
|
+
view: string;
|
|
35
|
+
}[];
|
|
36
|
+
}): string[];
|
|
25
37
|
export interface FunctionInspection {
|
|
26
38
|
entry: PrimitiveEntry;
|
|
27
39
|
slug: string;
|
|
@@ -47,6 +59,8 @@ export interface ArtifactInspection {
|
|
|
47
59
|
dir: string;
|
|
48
60
|
projectId: string;
|
|
49
61
|
nextjs: boolean;
|
|
62
|
+
/** The parsed artifact.bundle.yml, as written. */
|
|
63
|
+
bundle: unknown;
|
|
50
64
|
}
|
|
51
65
|
export declare function inspectArtifact({ ctx, entry }: {
|
|
52
66
|
ctx: PreviewContext;
|