@sequenceholdings/studio-cli 0.9.15 → 0.9.17
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 +19 -3
- package/dist/atlas-client.d.ts +2 -1
- package/dist/atlas-client.js +5 -4
- package/dist/auth.js +52 -3
- package/dist/command-contract.d.ts +6 -0
- package/dist/command-contract.js +1 -0
- package/dist/command-help.d.ts +2 -2
- package/dist/command-help.js +9 -5
- package/dist/env-registry.d.ts +5 -1
- package/dist/env-registry.js +11 -2
- package/dist/host-token.d.ts +55 -0
- package/dist/host-token.js +117 -0
- package/dist/main.js +5 -1
- package/dist/orm/apply-source.d.ts +45 -2
- package/dist/orm/apply-source.js +82 -14
- package/dist/orm/delegate.js +30 -34
- package/dist/orm/deployment-policy.js +29 -12
- package/dist/orm/help.d.ts +1 -1
- package/dist/orm/help.js +1 -1
- package/dist/orm/history.d.ts +2 -0
- package/dist/orm/history.js +1 -1
- package/dist/pnpm-auto-update.d.ts +7 -0
- package/dist/pnpm-auto-update.js +133 -0
- package/dist/update-check.d.ts +3 -7
- package/dist/update-check.js +73 -34
- package/package.json +9 -8
- package/release-summary.json +3 -0
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
/** Mirrors `SOURCE_ENV` in `@sequenceholdings/orm/cli`; older pinned packages ignore it. */
|
|
2
2
|
export declare const ORM_SOURCE_ENV = "SEQUENCE_ORM_SOURCE";
|
|
3
|
+
/** Mirrors `SOURCE_AUTHORIZATION_ENV` in `@sequenceholdings/orm/cli`; older pinned packages ignore it. */
|
|
4
|
+
export declare const ORM_SOURCE_AUTHORIZATION_ENV = "SEQUENCE_ORM_SOURCE_AUTHORIZATION";
|
|
3
5
|
export interface OrmApplySource {
|
|
4
6
|
repository_id: string;
|
|
5
7
|
commit: string;
|
|
6
8
|
path: string;
|
|
7
9
|
dirty?: boolean;
|
|
10
|
+
/** The registered environment whose Git Service holds the repository, when it is not the target's. */
|
|
11
|
+
source_environment?: string;
|
|
12
|
+
}
|
|
13
|
+
/** Another environment whose Git Service holds the source, with the caller's own token there. */
|
|
14
|
+
export interface OrmSourceEnvironment {
|
|
15
|
+
name: string;
|
|
16
|
+
url: string;
|
|
17
|
+
token: string;
|
|
8
18
|
}
|
|
9
19
|
/** The Git Service repository a clone's origin names, when that origin is the target environment's own Git Service. */
|
|
10
20
|
export declare function gitServiceRepoIdFromOrigin({ originUrl, targetUrl }: {
|
|
@@ -37,11 +47,41 @@ export declare function takeUnverifiedSourceFlag({ sub, argv }: {
|
|
|
37
47
|
} | {
|
|
38
48
|
error: string;
|
|
39
49
|
};
|
|
50
|
+
/** Pull `--source-env <env>` (or `=env`) off the argv; only `apply` accepts it. */
|
|
51
|
+
export declare function takeSourceEnvFlag({ sub, argv }: {
|
|
52
|
+
sub: string;
|
|
53
|
+
argv: readonly string[];
|
|
54
|
+
}): {
|
|
55
|
+
sourceEnv?: string;
|
|
56
|
+
args: string[];
|
|
57
|
+
} | {
|
|
58
|
+
error: string;
|
|
59
|
+
};
|
|
60
|
+
/** `--unverified-source` and `--source-env` off the argv, in one pass for the delegate. */
|
|
61
|
+
export declare function takeApplySourceFlags({ sub, argv }: {
|
|
62
|
+
sub: string;
|
|
63
|
+
argv: readonly string[];
|
|
64
|
+
}): {
|
|
65
|
+
unverifiedReason?: string;
|
|
66
|
+
sourceEnv?: string;
|
|
67
|
+
args: string[];
|
|
68
|
+
} | {
|
|
69
|
+
error: string;
|
|
70
|
+
};
|
|
71
|
+
export declare const SOURCE_ENV_WITH_REPO_ERROR = "--source-env applies to a local checkout; apply from a clean clone of that environment's repository instead of --repo";
|
|
72
|
+
/** The `--source-env` environment and the caller's own token there, or why it cannot be used. */
|
|
73
|
+
export declare function resolveOrmSourceEnvironment({ requested }: {
|
|
74
|
+
requested: string;
|
|
75
|
+
}): Promise<OrmSourceEnvironment | {
|
|
76
|
+
error: string;
|
|
77
|
+
}>;
|
|
40
78
|
export interface ApplySourceCapabilities {
|
|
41
79
|
/** The target records apply sources; an older Atlas rejects the unknown `source` field. */
|
|
42
80
|
records: boolean;
|
|
43
81
|
/** The target refuses applies whose source it cannot verify. */
|
|
44
82
|
enforced: boolean;
|
|
83
|
+
/** The target can verify a source held in another environment's Git Service. */
|
|
84
|
+
sourceEnvironment: boolean;
|
|
45
85
|
}
|
|
46
86
|
export declare function applySourceCapabilities({ targetUrl, token }: {
|
|
47
87
|
targetUrl: string;
|
|
@@ -53,18 +93,20 @@ export declare function applySourceCapabilities({ targetUrl, token }: {
|
|
|
53
93
|
* succeed when the target enforces verified sources and this one plainly will
|
|
54
94
|
* not verify, so the caller stops before registering anything.
|
|
55
95
|
*/
|
|
56
|
-
export declare function exportApplySource({ auth, targetUrl, resolve, unverifiedReason, dryRun }: {
|
|
96
|
+
export declare function exportApplySource({ auth, targetUrl, resolve, unverifiedReason, sourceEnvironment, dryRun }: {
|
|
57
97
|
auth: {
|
|
58
98
|
token: string;
|
|
59
99
|
} | null;
|
|
60
100
|
targetUrl: string;
|
|
61
101
|
resolve: () => Promise<OrmApplySource | null>;
|
|
62
102
|
unverifiedReason?: string;
|
|
103
|
+
/** The source is a clone of this environment's Git Service, not the target's. */
|
|
104
|
+
sourceEnvironment?: OrmSourceEnvironment;
|
|
63
105
|
/** A rehearsal on a disposable fork activates nothing, so it is never refused for its source. */
|
|
64
106
|
dryRun?: boolean;
|
|
65
107
|
}): Promise<string | null>;
|
|
66
108
|
/** `orm apply <dir>` from a local checkout; every other subcommand sends no source. */
|
|
67
|
-
export declare function exportLocalApplySource({ sub, auth, targetUrl, dir, unverifiedReason, dryRun }: {
|
|
109
|
+
export declare function exportLocalApplySource({ sub, auth, targetUrl, dir, unverifiedReason, sourceEnvironment, dryRun }: {
|
|
68
110
|
sub: string;
|
|
69
111
|
auth: {
|
|
70
112
|
token: string;
|
|
@@ -72,5 +114,6 @@ export declare function exportLocalApplySource({ sub, auth, targetUrl, dir, unve
|
|
|
72
114
|
targetUrl: string | undefined;
|
|
73
115
|
dir?: string;
|
|
74
116
|
unverifiedReason?: string;
|
|
117
|
+
sourceEnvironment?: OrmSourceEnvironment;
|
|
75
118
|
dryRun?: boolean;
|
|
76
119
|
}): Promise<string | null>;
|
package/dist/orm/apply-source.js
CHANGED
|
@@ -8,8 +8,12 @@
|
|
|
8
8
|
import { execFileSync } from 'node:child_process';
|
|
9
9
|
import { resolveRepo } from '@sequenceholdings/artifact-studio/git-service-client';
|
|
10
10
|
import { localGitMetadata, localSourceRoot } from '@sequenceholdings/artifact-studio/source-resolver';
|
|
11
|
+
import { tryGetAccessTokenWithMode } from '../auth.js';
|
|
12
|
+
import { resolveConfiguredEnv } from '../config.js';
|
|
11
13
|
/** Mirrors `SOURCE_ENV` in `@sequenceholdings/orm/cli`; older pinned packages ignore it. */
|
|
12
14
|
export const ORM_SOURCE_ENV = 'SEQUENCE_ORM_SOURCE';
|
|
15
|
+
/** Mirrors `SOURCE_AUTHORIZATION_ENV` in `@sequenceholdings/orm/cli`; older pinned packages ignore it. */
|
|
16
|
+
export const ORM_SOURCE_AUTHORIZATION_ENV = 'SEQUENCE_ORM_SOURCE_AUTHORIZATION';
|
|
13
17
|
const GIT_SERVICE_REPO_PATH = /^\/api\/git-service\/repos\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\/git\/?$/i;
|
|
14
18
|
/** The Git Service repository a clone's origin names, when that origin is the target environment's own Git Service. */
|
|
15
19
|
export function gitServiceRepoIdFromOrigin({ originUrl, targetUrl }) {
|
|
@@ -68,31 +72,93 @@ export function takeUnverifiedSourceFlag({ sub, argv }) {
|
|
|
68
72
|
return { error: `${UNVERIFIED_SOURCE_FLAG} applies only to apply` };
|
|
69
73
|
return reason === undefined ? { args } : { reason, args };
|
|
70
74
|
}
|
|
75
|
+
const SOURCE_ENV_FLAG = '--source-env';
|
|
76
|
+
/** Pull `--source-env <env>` (or `=env`) off the argv; only `apply` accepts it. */
|
|
77
|
+
export function takeSourceEnvFlag({ sub, argv }) {
|
|
78
|
+
const args = [];
|
|
79
|
+
let sourceEnv;
|
|
80
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
81
|
+
const arg = argv[index];
|
|
82
|
+
if (arg !== SOURCE_ENV_FLAG && !arg.startsWith(`${SOURCE_ENV_FLAG}=`)) {
|
|
83
|
+
args.push(arg);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const value = arg === SOURCE_ENV_FLAG ? argv[(index += 1)] : arg.slice(SOURCE_ENV_FLAG.length + 1);
|
|
87
|
+
if (value === undefined || value.trim() === '' || value.startsWith('-'))
|
|
88
|
+
return { error: `${SOURCE_ENV_FLAG} needs an environment name, e.g. ${SOURCE_ENV_FLAG} banksouth` };
|
|
89
|
+
sourceEnv = value.trim();
|
|
90
|
+
}
|
|
91
|
+
if (sourceEnv !== undefined && sub !== 'apply')
|
|
92
|
+
return { error: `${SOURCE_ENV_FLAG} applies only to apply` };
|
|
93
|
+
return sourceEnv === undefined ? { args } : { sourceEnv, args };
|
|
94
|
+
}
|
|
95
|
+
/** `--unverified-source` and `--source-env` off the argv, in one pass for the delegate. */
|
|
96
|
+
export function takeApplySourceFlags({ sub, argv }) {
|
|
97
|
+
const unverified = takeUnverifiedSourceFlag({ sub, argv });
|
|
98
|
+
if ('error' in unverified)
|
|
99
|
+
return unverified;
|
|
100
|
+
const source = takeSourceEnvFlag({ sub, argv: unverified.args });
|
|
101
|
+
if ('error' in source)
|
|
102
|
+
return source;
|
|
103
|
+
return { args: source.args, ...(unverified.reason ? { unverifiedReason: unverified.reason } : {}), ...(source.sourceEnv ? { sourceEnv: source.sourceEnv } : {}) };
|
|
104
|
+
}
|
|
105
|
+
export const SOURCE_ENV_WITH_REPO_ERROR = `${SOURCE_ENV_FLAG} applies to a local checkout; apply from a clean clone of that environment's repository instead of --repo`;
|
|
106
|
+
/** The `--source-env` environment and the caller's own token there, or why it cannot be used. */
|
|
107
|
+
export async function resolveOrmSourceEnvironment({ requested }) {
|
|
108
|
+
const env = await resolveConfiguredEnv({ requested });
|
|
109
|
+
const auth = await tryGetAccessTokenWithMode({ failClosedForM2m: true, env: env.name, targetUrl: env.url });
|
|
110
|
+
if (!auth || auth.authMode === 'sandbox')
|
|
111
|
+
return { error: `${SOURCE_ENV_FLAG} ${env.name} needs your own sign-in there: run seq-studio login -e ${env.name}` };
|
|
112
|
+
return { name: env.name, url: env.url, token: auth.token };
|
|
113
|
+
}
|
|
114
|
+
/** Name the source environment on the claim and hand its credential to the pinned ORM package, which sends it only with the apply. */
|
|
115
|
+
function attachSourceEnvironment({ source, sourceEnvironment }) {
|
|
116
|
+
if (!sourceEnvironment)
|
|
117
|
+
return source;
|
|
118
|
+
process.env[ORM_SOURCE_AUTHORIZATION_ENV] = sourceEnvironment.token;
|
|
119
|
+
return { ...source, source_environment: sourceEnvironment.name };
|
|
120
|
+
}
|
|
121
|
+
const NO_CAPABILITIES = { records: false, enforced: false, sourceEnvironment: false };
|
|
71
122
|
export async function applySourceCapabilities({ targetUrl, token }) {
|
|
72
123
|
try {
|
|
73
124
|
const response = await fetch(new URL('/api/orm/runtime-capabilities', targetUrl), { headers: { authorization: `Bearer ${token}` } });
|
|
74
125
|
if (!response.ok)
|
|
75
|
-
return
|
|
126
|
+
return NO_CAPABILITIES;
|
|
76
127
|
const body = await response.json();
|
|
77
128
|
if (typeof body !== 'object' || body === null)
|
|
78
|
-
return
|
|
129
|
+
return NO_CAPABILITIES;
|
|
79
130
|
const records = 'activationSource' in body && body.activationSource === true;
|
|
80
|
-
return {
|
|
131
|
+
return {
|
|
132
|
+
records,
|
|
133
|
+
enforced: records && 'requireVerifiedSource' in body && body.requireVerifiedSource === true,
|
|
134
|
+
sourceEnvironment: records && 'activationSourceEnvironment' in body && body.activationSourceEnvironment === true,
|
|
135
|
+
};
|
|
81
136
|
}
|
|
82
137
|
catch {
|
|
83
|
-
return
|
|
138
|
+
return NO_CAPABILITIES;
|
|
84
139
|
}
|
|
85
140
|
}
|
|
141
|
+
function unverifiableSourceRefusal({ problem, sourceEnvironment }) {
|
|
142
|
+
const required = sourceEnvironment ? `--source-env ${sourceEnvironment.name} applies only` : 'This environment applies ORM changes only';
|
|
143
|
+
return `${required} from a pushed commit Atlas can verify, and this checkout ${problem}. ` +
|
|
144
|
+
`Commit and push the package (run \`seq-studio orm diff\` first so its migration is committed), then apply again${sourceEnvironment ? '' : ' or use --repo'}. ` +
|
|
145
|
+
`Namespace admins can override with ${UNVERIFIED_SOURCE_FLAG} "<reason>".`;
|
|
146
|
+
}
|
|
86
147
|
/**
|
|
87
148
|
* Hand the apply's Git Service source, and any override reason, to the pinned
|
|
88
149
|
* ORM package, which sends them with the apply. Returns why the apply cannot
|
|
89
150
|
* succeed when the target enforces verified sources and this one plainly will
|
|
90
151
|
* not verify, so the caller stops before registering anything.
|
|
91
152
|
*/
|
|
92
|
-
export async function exportApplySource({ auth, targetUrl, resolve, unverifiedReason, dryRun = false }) {
|
|
153
|
+
export async function exportApplySource({ auth, targetUrl, resolve, unverifiedReason, sourceEnvironment, dryRun = false }) {
|
|
93
154
|
delete process.env[ORM_SOURCE_ENV];
|
|
94
155
|
delete process.env[ORM_UNVERIFIED_SOURCE_REASON_ENV];
|
|
95
|
-
|
|
156
|
+
delete process.env[ORM_SOURCE_AUTHORIZATION_ENV];
|
|
157
|
+
const capabilities = auth ? await applySourceCapabilities({ targetUrl, token: auth.token }) : NO_CAPABILITIES;
|
|
158
|
+
if (sourceEnvironment && !capabilities.sourceEnvironment) {
|
|
159
|
+
return `${targetUrl} cannot verify a source in another environment's Git Service yet; apply without --source-env, ` +
|
|
160
|
+
'which records the activation as reported, once this Atlas supports it.';
|
|
161
|
+
}
|
|
96
162
|
if (!capabilities.records)
|
|
97
163
|
return null;
|
|
98
164
|
if (unverifiedReason)
|
|
@@ -105,14 +171,14 @@ export async function exportApplySource({ auth, targetUrl, resolve, unverifiedRe
|
|
|
105
171
|
console.warn(`[seq-studio] could not resolve the apply source: ${error instanceof Error ? error.message : String(error)}`);
|
|
106
172
|
}
|
|
107
173
|
if (source)
|
|
108
|
-
process.env[ORM_SOURCE_ENV] = JSON.stringify(source);
|
|
109
|
-
const
|
|
174
|
+
process.env[ORM_SOURCE_ENV] = JSON.stringify(attachSourceEnvironment({ source, sourceEnvironment }));
|
|
175
|
+
const gitService = sourceEnvironment ? `${sourceEnvironment.name}'s Git Service` : 'this environment\'s Git Service';
|
|
176
|
+
const problem = !source ? `is not a clone of ${gitService}` : source.dirty ? 'has uncommitted changes in the ORM package' : null;
|
|
110
177
|
if (!problem)
|
|
111
178
|
return null;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
`Namespace admins can override with ${UNVERIFIED_SOURCE_FLAG} "<reason>".`;
|
|
179
|
+
// --source-env asks for a verified apply, so an unverifiable checkout is refused wherever the target does not enforce.
|
|
180
|
+
if ((capabilities.enforced || sourceEnvironment) && !unverifiedReason && !dryRun) {
|
|
181
|
+
return unverifiableSourceRefusal({ problem, sourceEnvironment });
|
|
116
182
|
}
|
|
117
183
|
if (dryRun)
|
|
118
184
|
return null;
|
|
@@ -120,8 +186,10 @@ export async function exportApplySource({ auth, targetUrl, resolve, unverifiedRe
|
|
|
120
186
|
return null;
|
|
121
187
|
}
|
|
122
188
|
/** `orm apply <dir>` from a local checkout; every other subcommand sends no source. */
|
|
123
|
-
export async function exportLocalApplySource({ sub, auth, targetUrl, dir = '.', unverifiedReason, dryRun }) {
|
|
189
|
+
export async function exportLocalApplySource({ sub, auth, targetUrl, dir = '.', unverifiedReason, sourceEnvironment, dryRun }) {
|
|
124
190
|
if (sub !== 'apply' || !targetUrl)
|
|
125
191
|
return null;
|
|
126
|
-
|
|
192
|
+
// The clone's origin must be the Git Service that holds the source: the source environment's, when one is named.
|
|
193
|
+
const originUrl = sourceEnvironment?.url ?? targetUrl;
|
|
194
|
+
return exportApplySource({ auth, targetUrl, unverifiedReason, sourceEnvironment, dryRun, resolve: async () => localOrmApplySource({ dir, targetUrl: originUrl }) });
|
|
127
195
|
}
|
package/dist/orm/delegate.js
CHANGED
|
@@ -18,7 +18,7 @@ import { resolveFunctionSourceDir } from '../functions/source-selection.js';
|
|
|
18
18
|
import { warnBeforeHostDeploy } from '../manifest-roles-notice.js';
|
|
19
19
|
import { ORM_DEPLOYMENT_POLICY_HELP, ORM_DISCOVER_HELP, ORM_EXECUTE_HELP, ORM_HELP, ORM_HISTORY_HELP } from '../command-help.js';
|
|
20
20
|
import { ormVersionMismatch, requiresSchemaVersionCheck } from './version-guard.js';
|
|
21
|
-
import { exportApplySource, exportLocalApplySource, repoOrmApplySource,
|
|
21
|
+
import { exportApplySource, exportLocalApplySource, repoOrmApplySource, resolveOrmSourceEnvironment, SOURCE_ENV_WITH_REPO_ERROR, takeApplySourceFlags, } from './apply-source.js';
|
|
22
22
|
/**
|
|
23
23
|
* ORM subcommands that talk to Atlas — must not silently target `local`.
|
|
24
24
|
* `init`, `generate`, `validate`, `diff`, `migrate-from-yaml`, and `import` are offline.
|
|
@@ -114,7 +114,9 @@ function aliasOrmModuleForRemoteSource(envName) {
|
|
|
114
114
|
// error names the missing module.
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
|
-
async function runOrmFromRepo({ sub, selection, auth, targetUrl, ormCli, unverifiedReason, }) {
|
|
117
|
+
async function runOrmFromRepo({ sub, selection, auth, targetUrl, ormCli, unverifiedReason, sourceEnv, }) {
|
|
118
|
+
if (sourceEnv)
|
|
119
|
+
return failWith(SOURCE_ENV_WITH_REPO_ERROR);
|
|
118
120
|
if (!auth || !targetUrl) {
|
|
119
121
|
console.error('[seq-studio] orm --repo needs a target environment and auth. Pass -e <env> and run `seq-studio login`.');
|
|
120
122
|
return 1;
|
|
@@ -130,10 +132,8 @@ async function runOrmFromRepo({ sub, selection, auth, targetUrl, ormCli, unverif
|
|
|
130
132
|
...(selection.path !== undefined ? { path: selection.path } : {}),
|
|
131
133
|
});
|
|
132
134
|
const mismatch = await ormVersionMismatch(dir);
|
|
133
|
-
if (mismatch)
|
|
134
|
-
|
|
135
|
-
return 1;
|
|
136
|
-
}
|
|
135
|
+
if (mismatch)
|
|
136
|
+
return failWith(mismatch);
|
|
137
137
|
aliasOrmModuleForRemoteSource(ormCli.ORM_MODULE_PATH_ENV);
|
|
138
138
|
// A local apply authors any missing migration into the working tree for
|
|
139
139
|
// review. A clone is discarded, so an authored migration would be applied
|
|
@@ -147,10 +147,8 @@ async function runOrmFromRepo({ sub, selection, auth, targetUrl, ormCli, unverif
|
|
|
147
147
|
targetUrl, token: auth.token, namespace: selection.spec.namespace, name: selection.spec.name,
|
|
148
148
|
commit: source.provenance.gitCommit, path: selection.path,
|
|
149
149
|
}) }) : null;
|
|
150
|
-
if (refusal)
|
|
151
|
-
|
|
152
|
-
return 1;
|
|
153
|
-
}
|
|
150
|
+
if (refusal)
|
|
151
|
+
return failWith(refusal);
|
|
154
152
|
const args = [dir, ...selection.rest];
|
|
155
153
|
await warnBeforeHostDeploy({ sub, deploySub: 'apply', args, file: 'namespace.yaml' });
|
|
156
154
|
return await ormCli.runCli([sub, ...args]);
|
|
@@ -266,6 +264,10 @@ async function runOrmInitWithRepo(normalized) {
|
|
|
266
264
|
// The environment is for the repository setup; init itself is offline.
|
|
267
265
|
return runInitWithRepo({ args, target, scaffold: () => runOrmCommand('init', withoutEnvFlag(initArgv)) });
|
|
268
266
|
}
|
|
267
|
+
function failWith(message) {
|
|
268
|
+
console.error(`[seq-studio] ${message}`);
|
|
269
|
+
return 1;
|
|
270
|
+
}
|
|
269
271
|
export async function runOrmCommand(sub, rest) {
|
|
270
272
|
if (!sub || sub === 'help' || sub === '--help' || sub === '-h') {
|
|
271
273
|
console.log(ORM_USAGE);
|
|
@@ -273,12 +275,10 @@ export async function runOrmCommand(sub, rest) {
|
|
|
273
275
|
}
|
|
274
276
|
if (NATIVE_ORM_SUBS.has(sub))
|
|
275
277
|
return runNativeOrmCommand(sub, rest);
|
|
276
|
-
const
|
|
277
|
-
if ('error' in
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
}
|
|
281
|
-
const { reason: unverifiedReason, args: normalized } = unverified;
|
|
278
|
+
const flags = takeApplySourceFlags({ sub, argv: normalizeShortEnvFlag(rest) });
|
|
279
|
+
if ('error' in flags)
|
|
280
|
+
return failWith(flags.error);
|
|
281
|
+
const { unverifiedReason, sourceEnv, args: normalized } = flags;
|
|
282
282
|
const repoInit = sub === 'init' ? await runOrmInitWithRepo(normalized) : null;
|
|
283
283
|
if (repoInit !== null)
|
|
284
284
|
return repoInit;
|
|
@@ -290,18 +290,13 @@ export async function runOrmCommand(sub, rest) {
|
|
|
290
290
|
repoSelection = extractOrmRepoSelection(normalized);
|
|
291
291
|
}
|
|
292
292
|
catch (err) {
|
|
293
|
-
|
|
294
|
-
return 1;
|
|
295
|
-
}
|
|
296
|
-
if (repoSelection && !ORM_REPO_SUBS.has(sub)) {
|
|
297
|
-
console.error(`[seq-studio] --repo applies only to: ${[...ORM_REPO_SUBS].join(', ')}`);
|
|
298
|
-
return 1;
|
|
293
|
+
return failWith(err instanceof Error ? err.message : String(err));
|
|
299
294
|
}
|
|
295
|
+
if (repoSelection && !ORM_REPO_SUBS.has(sub))
|
|
296
|
+
return failWith(`--repo applies only to: ${[...ORM_REPO_SUBS].join(', ')}`);
|
|
300
297
|
const requested = explicitOrSandboxEnv(readEnvFromArgv(normalized));
|
|
301
|
-
if (ORM_NETWORK_SUBS.has(sub) && !requested)
|
|
302
|
-
|
|
303
|
-
return 1;
|
|
304
|
-
}
|
|
298
|
+
if (ORM_NETWORK_SUBS.has(sub) && !requested)
|
|
299
|
+
return failWith(REQUIRE_EXPLICIT_ENV_MESSAGE);
|
|
305
300
|
let targetUrl;
|
|
306
301
|
if (requested) {
|
|
307
302
|
const resolved = await resolveConfiguredEnv({ requested });
|
|
@@ -334,17 +329,18 @@ export async function runOrmCommand(sub, rest) {
|
|
|
334
329
|
}
|
|
335
330
|
});
|
|
336
331
|
if (repoSelection)
|
|
337
|
-
return runOrmFromRepo({ sub, selection: repoSelection, auth, targetUrl, ormCli, unverifiedReason });
|
|
338
|
-
return runLocalOrm({ sub, normalized, auth, targetUrl, unverifiedReason, runCli });
|
|
332
|
+
return runOrmFromRepo({ sub, selection: repoSelection, auth, targetUrl, ormCli, unverifiedReason, sourceEnv });
|
|
333
|
+
return runLocalOrm({ sub, normalized, auth, targetUrl, unverifiedReason, sourceEnv, runCli });
|
|
339
334
|
}
|
|
340
335
|
/** A namespace directory on disk: check its ORM version, attach the apply source, then forward. */
|
|
341
|
-
async function runLocalOrm({ sub, normalized, auth, targetUrl, unverifiedReason, runCli }) {
|
|
336
|
+
async function runLocalOrm({ sub, normalized, auth, targetUrl, unverifiedReason, sourceEnv, runCli }) {
|
|
337
|
+
const sourceEnvironment = sourceEnv ? await resolveOrmSourceEnvironment({ requested: sourceEnv }) : undefined;
|
|
338
|
+
if (sourceEnvironment && 'error' in sourceEnvironment)
|
|
339
|
+
return failWith(sourceEnvironment.error);
|
|
342
340
|
const problem = (requiresSchemaVersionCheck(sub) ? await ormVersionMismatch(positionalDir(normalized) ?? '.') : null) ??
|
|
343
|
-
await exportLocalApplySource({ sub, auth, targetUrl, dir: positionalDir(normalized), unverifiedReason, dryRun: normalized.includes('--dry-run') });
|
|
344
|
-
if (problem)
|
|
345
|
-
|
|
346
|
-
return 1;
|
|
347
|
-
}
|
|
341
|
+
await exportLocalApplySource({ sub, auth, targetUrl, dir: positionalDir(normalized), unverifiedReason, sourceEnvironment, dryRun: normalized.includes('--dry-run') });
|
|
342
|
+
if (problem)
|
|
343
|
+
return failWith(problem);
|
|
348
344
|
await warnBeforeHostDeploy({ sub, deploySub: 'apply', args: normalized, file: 'namespace.yaml' });
|
|
349
345
|
return runCli([sub, ...normalized]);
|
|
350
346
|
}
|
|
@@ -3,6 +3,8 @@ import { getJson, putJson } from '../atlas-client.js';
|
|
|
3
3
|
import { printCliError } from '../cli-errors.js';
|
|
4
4
|
import { requiredStringFlag, validateCommandInput } from '../command-input.js';
|
|
5
5
|
import { buildContext, clientOptions } from '../functions/commands.js';
|
|
6
|
+
import { getAccessTokenWithMode } from '../auth.js';
|
|
7
|
+
import { resolveConfiguredEnv } from '../config.js';
|
|
6
8
|
function repository(args) {
|
|
7
9
|
const repo = requiredStringFlag({ args, key: 'repo' }).split('/');
|
|
8
10
|
if (repo.length !== 2 || !repo[0] || !repo[1])
|
|
@@ -10,30 +12,39 @@ function repository(args) {
|
|
|
10
12
|
return { repositoryNamespace: repo[0], repositoryName: repo[1], branch: requiredStringFlag({ args, key: 'branch' }) };
|
|
11
13
|
}
|
|
12
14
|
function selection(args) {
|
|
13
|
-
validateCommandInput({ args, flags: { mode: 'string', repo: 'string', branch: 'string', target: 'string', path: 'string' }, positional: 1 });
|
|
15
|
+
validateCommandInput({ args, flags: { mode: 'string', repo: 'string', branch: 'string', target: 'string', path: 'string', 'source-env': 'string' }, positional: 1 });
|
|
14
16
|
const mode = args.flags.mode;
|
|
15
17
|
if (mode !== undefined && mode !== 'manual' && mode !== 'ci' && mode !== 'source')
|
|
16
18
|
throw new Error('--mode must be manual, ci or source.');
|
|
17
19
|
if (mode === undefined || mode === 'manual') {
|
|
18
|
-
if (['repo', 'branch', 'target', 'path'].some(key => args.flags[key] !== undefined))
|
|
19
|
-
throw new Error('--repo, --branch, --target and --
|
|
20
|
+
if (['repo', 'branch', 'target', 'path', 'source-env'].some(key => args.flags[key] !== undefined))
|
|
21
|
+
throw new Error('--repo, --branch, --target, --path and --source-env require --mode ci or source.');
|
|
20
22
|
return { mode };
|
|
21
23
|
}
|
|
22
24
|
if (mode === 'ci') {
|
|
23
|
-
if (args.flags.path !== undefined)
|
|
24
|
-
throw new Error('--path
|
|
25
|
+
if (args.flags.path !== undefined || args.flags['source-env'] !== undefined)
|
|
26
|
+
throw new Error('--path and --source-env apply only to --mode source.');
|
|
25
27
|
return { mode, ...repository(args), target: requiredStringFlag({ args, key: 'target' }) };
|
|
26
28
|
}
|
|
27
29
|
if (args.flags.target !== undefined)
|
|
28
30
|
throw new Error('--target applies only to --mode ci.');
|
|
29
|
-
|
|
31
|
+
const sourceEnv = args.flags['source-env'];
|
|
32
|
+
return { mode, ...repository(args), path: requiredStringFlag({ args, key: 'path' }), ...(typeof sourceEnv === 'string' ? { sourceEnv } : {}) };
|
|
30
33
|
}
|
|
31
34
|
function describe(policy) {
|
|
32
35
|
if (policy.mode === 'manual')
|
|
33
36
|
return 'manual deployment';
|
|
34
37
|
if (policy.mode === 'ci')
|
|
35
38
|
return `CI-managed (${policy.repository_id}, ${policy.branch}, ${policy.target_key})`;
|
|
36
|
-
|
|
39
|
+
const repository = policy.source_environment ? `${policy.source_environment}'s ${policy.repository_id}` : policy.repository_id;
|
|
40
|
+
return `direct applies only from ${policy.branch}:${policy.path === '' ? '.' : policy.path} in ${repository}, verified by Atlas`;
|
|
41
|
+
}
|
|
42
|
+
async function sourceEnvironmentClient(requested) {
|
|
43
|
+
const env = await resolveConfiguredEnv({ requested });
|
|
44
|
+
const auth = await getAccessTokenWithMode({ env: env.name, targetUrl: env.url });
|
|
45
|
+
if (auth.authMode === 'sandbox')
|
|
46
|
+
throw new Error(`--source-env ${env.name} needs your own sign-in there: run seq-studio login -e ${env.name}`);
|
|
47
|
+
return { name: env.name, options: { baseUrl: env.url, token: auth.token } };
|
|
37
48
|
}
|
|
38
49
|
export async function ormDeploymentPolicyCommand(args) {
|
|
39
50
|
try {
|
|
@@ -45,12 +56,18 @@ export async function ormDeploymentPolicyCommand(args) {
|
|
|
45
56
|
result = await getJson({ ...options, path });
|
|
46
57
|
else if (!('repositoryNamespace' in selected))
|
|
47
58
|
result = await putJson({ ...options, path, body: { mode: 'manual' } });
|
|
48
|
-
else {
|
|
59
|
+
else if (selected.mode === 'ci') {
|
|
49
60
|
const repositoryId = (await resolveRepo({ ...options, namespace: selected.repositoryNamespace, name: selected.repositoryName })).id;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
61
|
+
result = await putJson({ ...options, path, body: { mode: 'ci', repository_id: repositoryId, branch: selected.branch, target_key: selected.target } });
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// A source in another environment is found there, with the caller's own token, which Atlas uses to confirm read access.
|
|
65
|
+
const source = selected.sourceEnv ? await sourceEnvironmentClient(selected.sourceEnv) : null;
|
|
66
|
+
const repositoryId = (await resolveRepo({ ...(source?.options ?? options), namespace: selected.repositoryNamespace, name: selected.repositoryName })).id;
|
|
67
|
+
const body = { mode: 'source', repository_id: repositoryId, branch: selected.branch, path: selected.path,
|
|
68
|
+
...(source ? { source_environment: source.name } : {}) };
|
|
69
|
+
result = await putJson({ ...options, path, body,
|
|
70
|
+
...(source ? { headers: { 'x-sequence-source-authorization': `Bearer ${source.options.token}` } } : {}) });
|
|
54
71
|
}
|
|
55
72
|
if (args.flags.json === true)
|
|
56
73
|
console.log(JSON.stringify(result, null, 2));
|
package/dist/orm/help.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const ORM_USAGE = "usage:\n seq-studio orm init <dir> [--repo <ns>/<name>]\n scaffold a namespace package (v2: TypeScript schema + GraphQL documents);\n --repo scaffolds into a git-service repo (see Init into a repo below)\n seq-studio orm generate [dir] write schema.graphql + operations.manifest.json + typePolicies.gen.ts (offline; runs consumer codegen when codegen.ts is present)\n seq-studio orm generate [dir] --migration-export [--check]\n export reviewed ORM inputs for a coordinated pipeline migration; --check verifies without writing\n seq-studio orm validate [dir] parse + validate definitions and verify committed migrations are in sync\n seq-studio orm plan [dir] -e <env> compile definitions and diff against the registry\n seq-studio orm apply [dir] -e <env> [--timeout <duration>] [--no-wait] [--unverified-source \"<reason>\"]\n author the migration, register, apply, and refresh the generated outputs (the everyday command);\n waits until the new version is live (default up to 20m; e.g. --timeout 90s), --no-wait returns once queued\n seq-studio orm plan|apply --repo <ns>/<name> [--path <dir>] [--ref <ref>] -e <env>\n plan/apply a namespace committed to a platform git-service repo (CI deploy-from-git);\n --path selects the namespace directory (default: repo root). A remote apply never\n authors migrations: the committed ledger must already match the definitions.\n seq-studio orm execute <namespace> <operation> -e <env> [--variables-file <file>] [--var <name>=<value>]...\n run the deployed version's persisted operation by name as the caller (no checkout)\n seq-studio orm execute <operation> [dir] --variables-file <file> -e <env>\n execute from the checkout manifest through the installed ORM package\n both execute forms accept --variables-file - (or /dev/stdin) for JSON stdin until EOF\n seq-studio orm read <namespace> <table> -e <env> [--where c=op.v]... [--select c,...] [--order c.desc] [--limit N] [--offset N] [--json|--jsonl]\n read rows of a deployed v2 namespace as the caller (row-level security applies)\n seq-studio orm sql <namespace> --query <sql> | --file <path> -e <env> [--param name[:type]=v]... | [--params <json-object>] [--json|--jsonl]\n run read-only SQL against a deployed v2 namespace as the caller\n qualify tables and double-quote mixed-case columns (e.g. SELECT \"loanNumber\" FROM lending.loans)\n seq-studio orm namespaces -e <env> [--limit N] [--offset N] [--json]\n list the namespaces you can read\n seq-studio orm history <namespace> -e <env> [--limit N] [--json]\n seq-studio orm deployment-policy <namespace> -e <env> [--mode manual|ci|source] [--repo <ns>/<name> --branch <branch> (--target <target-key> | --path <dir>)] [--json]\n inspect or explicitly change the namespace's deployment controller\n seq-studio orm describe <namespace> [<table> | --operations] -e <env> [--json]\n show a namespace's tables, views, and persisted operations (with variables), or one table's columns and actions\n seq-studio orm diff [dir] write/verify the committed migration standalone (--check is the offline CI gate; --allow-destructive consents; --rebase records a v1 -> v2 conversion)\n seq-studio orm migrate-from-yaml <dir> convert a v1 YAML namespace to the v2 TypeScript format (offline; migrations/ preserved)\n seq-studio orm import [dir] --spec <file> | --table <t> --from <schema.table> --map <target=source,...>\n plan a batched copy from an existing Postgres relation into an owned table (writes a SQL script; no database connection)\n\n Environments: see `seq-studio envs list` (built-in: local; more are\n discovered after you authenticate).\n Authenticate with: seq-studio login\n\n Init into a repo: --repo <ns>/<name> on an init command creates that platform\n git-service repo if missing (same name rules as repos create), then clones it\n into <dir> and scaffolds there, or, when <dir> is inside a Git checkout, sets\n it as that checkout's origin (a different existing origin is refused). It\n needs -e <env>, or an agent sandbox. Nothing is committed or pushed; the\n command prints the git add, commit, and push to run.\n In a git-service checkout (with or without --repo), orm init, functions init\n and artifact init also declare the scaffold under resources in\n .seq/repository.yml, so repository CI checks and deploys it. A scaffold inside\n a declared application is not declared; add it to that app with seq-studio add.\n";
|
|
1
|
+
export declare const ORM_USAGE = "usage:\n seq-studio orm init <dir> [--repo <ns>/<name>]\n scaffold a namespace package (v2: TypeScript schema + GraphQL documents);\n --repo scaffolds into a git-service repo (see Init into a repo below)\n seq-studio orm generate [dir] write schema.graphql + operations.manifest.json + typePolicies.gen.ts (offline; runs consumer codegen when codegen.ts is present)\n seq-studio orm generate [dir] --migration-export [--check]\n export reviewed ORM inputs for a coordinated pipeline migration; --check verifies without writing\n seq-studio orm validate [dir] parse + validate definitions and verify committed migrations are in sync\n seq-studio orm plan [dir] -e <env> compile definitions and diff against the registry\n seq-studio orm apply [dir] -e <env> [--timeout <duration>] [--no-wait] [--unverified-source \"<reason>\"] [--source-env <env>]\n author the migration, register, apply, and refresh the generated outputs (the everyday command);\n waits until the new version is live (default up to 20m; e.g. --timeout 90s), --no-wait returns once queued\n seq-studio orm plan|apply --repo <ns>/<name> [--path <dir>] [--ref <ref>] -e <env>\n plan/apply a namespace committed to a platform git-service repo (CI deploy-from-git);\n --path selects the namespace directory (default: repo root). A remote apply never\n authors migrations: the committed ledger must already match the definitions.\n seq-studio orm execute <namespace> <operation> -e <env> [--variables-file <file>] [--var <name>=<value>]...\n run the deployed version's persisted operation by name as the caller (no checkout)\n seq-studio orm execute <operation> [dir] --variables-file <file> -e <env>\n execute from the checkout manifest through the installed ORM package\n both execute forms accept --variables-file - (or /dev/stdin) for JSON stdin until EOF\n seq-studio orm read <namespace> <table> -e <env> [--where c=op.v]... [--select c,...] [--order c.desc] [--limit N] [--offset N] [--json|--jsonl]\n read rows of a deployed v2 namespace as the caller (row-level security applies)\n seq-studio orm sql <namespace> --query <sql> | --file <path> -e <env> [--param name[:type]=v]... | [--params <json-object>] [--json|--jsonl]\n run read-only SQL against a deployed v2 namespace as the caller\n qualify tables and double-quote mixed-case columns (e.g. SELECT \"loanNumber\" FROM lending.loans)\n seq-studio orm namespaces -e <env> [--limit N] [--offset N] [--json]\n list the namespaces you can read\n seq-studio orm history <namespace> -e <env> [--limit N] [--json]\n seq-studio orm deployment-policy <namespace> -e <env> [--mode manual|ci|source] [--repo <ns>/<name> --branch <branch> (--target <target-key> | --path <dir>)] [--json]\n inspect or explicitly change the namespace's deployment controller\n seq-studio orm describe <namespace> [<table> | --operations] -e <env> [--json]\n show a namespace's tables, views, and persisted operations (with variables), or one table's columns and actions\n seq-studio orm diff [dir] write/verify the committed migration standalone (--check is the offline CI gate; --allow-destructive consents; --rebase records a v1 -> v2 conversion)\n seq-studio orm migrate-from-yaml <dir> convert a v1 YAML namespace to the v2 TypeScript format (offline; migrations/ preserved)\n seq-studio orm import [dir] --spec <file> | --table <t> --from <schema.table> --map <target=source,...>\n plan a batched copy from an existing Postgres relation into an owned table (writes a SQL script; no database connection)\n\n Environments: see `seq-studio envs list` (built-in: local; more are\n discovered after you authenticate).\n Authenticate with: seq-studio login\n\n Init into a repo: --repo <ns>/<name> on an init command creates that platform\n git-service repo if missing (same name rules as repos create), then clones it\n into <dir> and scaffolds there, or, when <dir> is inside a Git checkout, sets\n it as that checkout's origin (a different existing origin is refused). It\n needs -e <env>, or an agent sandbox. Nothing is committed or pushed; the\n command prints the git add, commit, and push to run.\n In a git-service checkout (with or without --repo), orm init, functions init\n and artifact init also declare the scaffold under resources in\n .seq/repository.yml, so repository CI checks and deploys it. A scaffold inside\n a declared application is not declared; add it to that app with seq-studio add.\n";
|
package/dist/orm/help.js
CHANGED
|
@@ -8,7 +8,7 @@ export const ORM_USAGE = `usage:
|
|
|
8
8
|
export reviewed ORM inputs for a coordinated pipeline migration; --check verifies without writing
|
|
9
9
|
seq-studio orm validate [dir] parse + validate definitions and verify committed migrations are in sync
|
|
10
10
|
seq-studio orm plan [dir] -e <env> compile definitions and diff against the registry
|
|
11
|
-
seq-studio orm apply [dir] -e <env> [--timeout <duration>] [--no-wait] [--unverified-source "<reason>"]
|
|
11
|
+
seq-studio orm apply [dir] -e <env> [--timeout <duration>] [--no-wait] [--unverified-source "<reason>"] [--source-env <env>]
|
|
12
12
|
author the migration, register, apply, and refresh the generated outputs (the everyday command);
|
|
13
13
|
waits until the new version is live (default up to 20m; e.g. --timeout 90s), --no-wait returns once queued
|
|
14
14
|
seq-studio orm plan|apply --repo <ns>/<name> [--path <dir>] [--ref <ref>] -e <env>
|
package/dist/orm/history.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export interface ActivationRow {
|
|
|
6
6
|
operation_set_id: string | null;
|
|
7
7
|
provenance_class: 'repository_verified' | 'ci_intent' | 'reported';
|
|
8
8
|
source_repository_id: string | null;
|
|
9
|
+
/** Absent on an older Atlas; null for this deployment's own Git Service. */
|
|
10
|
+
source_environment?: string | null;
|
|
9
11
|
source_commit: string | null;
|
|
10
12
|
source_branch: string | null;
|
|
11
13
|
source_path: string | null;
|
package/dist/orm/history.js
CHANGED
|
@@ -21,7 +21,7 @@ export function formatActivation({ row, active }) {
|
|
|
21
21
|
const claimed = row.reported_source;
|
|
22
22
|
const where = row.provenance_class === 'reported'
|
|
23
23
|
? `reported${typeof claimed?.commit === 'string' ? ` ${claimed.commit.slice(0, 12)}` : ''}${typeof claimed?.verification_failure === 'string' ? ` (${claimed.verification_failure})` : ''}`
|
|
24
|
-
: `${row.provenance_class === 'ci_intent' ? 'ci' : 'verified'} ${row.source_commit?.slice(0, 12)} on ${row.source_branch} at ${row.source_path === '' ? '.' : row.source_path}`;
|
|
24
|
+
: `${row.provenance_class === 'ci_intent' ? 'ci' : 'verified'} ${row.source_commit?.slice(0, 12)} on ${row.source_environment ? `${row.source_environment}:` : ''}${row.source_branch} at ${row.source_path === '' ? '.' : row.source_path}`;
|
|
25
25
|
return `${active ? '*' : ' '} ${row.activated_at.slice(0, 19).replace('T', ' ')}Z ${what.padEnd(28)} ${actor.padEnd(32)} ${where}`;
|
|
26
26
|
}
|
|
27
27
|
export async function ormHistoryCommand(args) {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type UpdateTrack = 'latest' | 'next';
|
|
2
|
+
export declare function isGlobalPnpmInstallation(): boolean;
|
|
3
|
+
export declare function globalUpdateTrack(): Promise<UpdateTrack>;
|
|
4
|
+
export declare function setGlobalUpdateTrack(track: UpdateTrack): Promise<boolean>;
|
|
5
|
+
export declare function updaterCommand(args: string[]): Promise<number>;
|
|
6
|
+
/** Runs only in the detached registry-refresh worker, never in a CLI command. */
|
|
7
|
+
export declare function maybeUpgradeGlobalPnpm(available: string, expectedTrack?: UpdateTrack): Promise<boolean>;
|