@sequenceholdings/studio-cli 0.7.0 → 0.7.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 +68 -8
- package/dist/app/commands.d.ts +3 -1
- package/dist/app/commands.js +51 -0
- package/dist/app/validate.d.ts +16 -0
- package/dist/app/validate.js +40 -0
- package/dist/atlas-client.d.ts +2 -0
- package/dist/atlas-client.js +8 -0
- package/dist/bin.js +2 -1
- package/dist/cli-errors.js +8 -3
- package/dist/command-contract.d.ts +6 -0
- package/dist/command-contract.js +1 -0
- package/dist/command-help.d.ts +4 -3
- package/dist/command-help.js +39 -3
- package/dist/functions/commands.d.ts +4 -0
- package/dist/functions/commands.js +61 -0
- package/dist/main.js +5 -0
- package/dist/orm/delegate.d.ts +1 -0
- package/dist/orm/delegate.js +40 -14
- package/dist/orm/discover-schema.d.ts +98 -0
- package/dist/orm/discover-schema.js +32 -0
- package/dist/orm/discover.js +28 -3
- package/dist/orm/execute.d.ts +33 -0
- package/dist/orm/execute.js +208 -0
- package/dist/orm/operation-show.d.ts +2 -0
- package/dist/orm/operation-show.js +35 -0
- package/dist/orm/read.js +2 -2
- package/dist/transient-503.d.ts +4 -0
- package/dist/transient-503.js +25 -0
- package/package.json +5 -4
|
@@ -955,11 +955,72 @@ async function printFunctionShowDetails({ ctx, fn, }) {
|
|
|
955
955
|
egressEnforced: detail?.function.egressEnforced ?? fn.egressEnforced ?? false,
|
|
956
956
|
});
|
|
957
957
|
}
|
|
958
|
+
async function printFunctionReleaseJson(ctx, fn, selected) {
|
|
959
|
+
if (!fn.currentUserAccess) {
|
|
960
|
+
throw new Error('Release provenance requires read access to this function');
|
|
961
|
+
}
|
|
962
|
+
const detail = await getFunctionDetail(ctx, fn.id);
|
|
963
|
+
if (!detail)
|
|
964
|
+
throw new Error(`Function ${fn.slug} is no longer available on ${ctx.env.name}`);
|
|
965
|
+
const release = detail.function;
|
|
966
|
+
if (release.activeVersionId === undefined || typeof release.immutableRelease !== 'boolean') {
|
|
967
|
+
throw new Error('This environment does not expose activeVersionId and immutableRelease for release inspection');
|
|
968
|
+
}
|
|
969
|
+
const versions = await listVersions(ctx, fn.id);
|
|
970
|
+
const active = release.activeVersionId
|
|
971
|
+
? versions.find((version) => version.id === release.activeVersionId)
|
|
972
|
+
: undefined;
|
|
973
|
+
if (release.activeVersionId && !active) {
|
|
974
|
+
throw new Error(`Active version ${release.activeVersionId} is missing from the version list; retry inspection`);
|
|
975
|
+
}
|
|
976
|
+
const selectedVersion = selected === undefined
|
|
977
|
+
? undefined
|
|
978
|
+
: versions.find((version) => version.id === selected || version.version === selected);
|
|
979
|
+
if (selected !== undefined && !selectedVersion) {
|
|
980
|
+
throw new Error(`Version ${selected} was not found for ${fn.slug} on ${ctx.env.name}`);
|
|
981
|
+
}
|
|
982
|
+
const projectVersion = (version) => ({
|
|
983
|
+
id: version.id,
|
|
984
|
+
version: version.version,
|
|
985
|
+
status: version.status ?? null,
|
|
986
|
+
isActive: version.id === release.activeVersionId,
|
|
987
|
+
sourceHash: version.sourceHash ?? null,
|
|
988
|
+
gitCommit: version.gitCommit ?? null,
|
|
989
|
+
gitBranch: version.gitBranch ?? null,
|
|
990
|
+
gitDirty: version.gitDirty ?? null,
|
|
991
|
+
createdAt: version.createdAt ?? null,
|
|
992
|
+
deployedAt: version.deployedAt ?? null,
|
|
993
|
+
});
|
|
994
|
+
console.log(JSON.stringify({
|
|
995
|
+
environment: ctx.env.name,
|
|
996
|
+
function: {
|
|
997
|
+
id: release.id,
|
|
998
|
+
slug: release.slug,
|
|
999
|
+
title: release.title,
|
|
1000
|
+
deployed: release.deployed,
|
|
1001
|
+
activeVersionId: release.activeVersionId,
|
|
1002
|
+
immutableRelease: release.immutableRelease,
|
|
1003
|
+
},
|
|
1004
|
+
activeVersion: active ? projectVersion(active) : null,
|
|
1005
|
+
versions: versions.map(projectVersion),
|
|
1006
|
+
...(selectedVersion ? { selectedVersion: projectVersion(selectedVersion) } : {}),
|
|
1007
|
+
}, null, 2));
|
|
1008
|
+
return 0;
|
|
1009
|
+
}
|
|
958
1010
|
export async function functionsShowCommand(args) {
|
|
1011
|
+
const selected = args.flags.version;
|
|
1012
|
+
if (selected !== undefined && (typeof selected !== 'string' || !selected.trim())) {
|
|
1013
|
+
throw new Error('--version requires a version ID or name');
|
|
1014
|
+
}
|
|
1015
|
+
if (selected !== undefined && !flagBool(args.flags, 'json')) {
|
|
1016
|
+
throw new Error('--version requires --json');
|
|
1017
|
+
}
|
|
959
1018
|
const ctx = await buildContext(args);
|
|
960
1019
|
const fn = await resolveFunction({ ctx, args, required: true });
|
|
961
1020
|
if (!fn)
|
|
962
1021
|
return 1;
|
|
1022
|
+
if (flagBool(args.flags, 'json'))
|
|
1023
|
+
return printFunctionReleaseJson(ctx, fn, selected);
|
|
963
1024
|
console.log(`${LOG} function on ${ctx.env.name}:`);
|
|
964
1025
|
console.log(` id: ${fn.id}`);
|
|
965
1026
|
console.log(` slug: ${fn.slug}`);
|
package/dist/main.js
CHANGED
|
@@ -33,6 +33,7 @@ import { sandboxUsageFooter } from './sandbox-auth.js';
|
|
|
33
33
|
const TOP_LEVEL_USAGE = `usage:
|
|
34
34
|
seq-studio init <dir> [options] scaffold an app or use a published template
|
|
35
35
|
seq-studio add <kind> <name> [internal] add a primitive to the current app monorepo
|
|
36
|
+
seq-studio validate [--dir <path>] validate an app manifest offline
|
|
36
37
|
seq-studio deploy -e <env> [internal] deploy primitives from sequence.app.yml
|
|
37
38
|
seq-studio process <sub> [args] lint | plan | apply | runs | test | simulate | bundle | init
|
|
38
39
|
seq-studio artifact <sub> [args] init | whoami | link | env | status | list | show | validate | build | plan | deploy | dev | promote | pull | rollback
|
|
@@ -149,6 +150,10 @@ export async function run(argv = process.argv.slice(2)) {
|
|
|
149
150
|
const { runAppDeployCommand } = await import('./app/commands.js');
|
|
150
151
|
return runAppDeployCommand(parseArgs([sub, ...rest].filter((a) => Boolean(a))));
|
|
151
152
|
}
|
|
153
|
+
case 'validate': {
|
|
154
|
+
const { runAppValidateCommand } = await import('./app/commands.js');
|
|
155
|
+
return runAppValidateCommand(parseArgs([sub, ...rest].filter((a) => Boolean(a))));
|
|
156
|
+
}
|
|
152
157
|
case 'process':
|
|
153
158
|
return runProcessNamespace(sub, rest);
|
|
154
159
|
case 'artifact': {
|
package/dist/orm/delegate.d.ts
CHANGED
|
@@ -30,4 +30,5 @@ export interface OrmRepoSelection {
|
|
|
30
30
|
* so these values must never be forwarded to it.
|
|
31
31
|
*/
|
|
32
32
|
export declare function extractOrmRepoSelection(argv: readonly string[]): OrmRepoSelection | null;
|
|
33
|
+
export declare function formatOrmDependencyFailure(message: string): string;
|
|
33
34
|
export declare function runOrmCommand(sub: string | undefined, rest: string[]): Promise<number>;
|
package/dist/orm/delegate.js
CHANGED
|
@@ -15,7 +15,7 @@ import { explicitOrSandboxEnv, normalizeShortEnvFlag, readEnvFromArgv } from '..
|
|
|
15
15
|
import { REQUIRE_EXPLICIT_ENV_MESSAGE } from '../env-flags.js';
|
|
16
16
|
import { resolveFunctionSourceDir } from '../functions/source-selection.js';
|
|
17
17
|
import { warnBeforeHostDeploy } from '../manifest-roles-notice.js';
|
|
18
|
-
import { ORM_DISCOVER_HELP, ORM_HELP } from '../command-help.js';
|
|
18
|
+
import { ORM_DISCOVER_HELP, ORM_EXECUTE_HELP, ORM_HELP } from '../command-help.js';
|
|
19
19
|
/**
|
|
20
20
|
* ORM subcommands that talk to Atlas — must not silently target `local`.
|
|
21
21
|
* `init`, `generate`, `validate`, `diff`, `migrate-from-yaml`, and `import` are offline.
|
|
@@ -35,16 +35,18 @@ const ORM_USAGE = `usage:
|
|
|
35
35
|
plan/apply a namespace committed to a platform git-service repo (CI deploy-from-git);
|
|
36
36
|
--path selects the namespace directory (default: repo root). A remote apply never
|
|
37
37
|
authors migrations: the committed ledger must already match the definitions.
|
|
38
|
+
seq-studio orm execute <namespace> <operation> -e <env> [--variables-file <file>] [--var <name>=<value>]...
|
|
39
|
+
run the deployed version's persisted operation by name as the caller (no checkout)
|
|
38
40
|
seq-studio orm execute <operation> [dir] --variables-file <file> -e <env>
|
|
39
|
-
|
|
41
|
+
run a persisted operation as hashed in this checkout's operations.manifest.json
|
|
40
42
|
seq-studio orm read <namespace> <table> -e <env> [--where c=op.v]... [--select c,...] [--order c.desc] [--limit N] [--offset N] [--json|--jsonl]
|
|
41
43
|
read rows of a deployed v2 namespace as the caller (row-level security applies)
|
|
42
44
|
seq-studio orm sql <namespace> --query <sql> | --file <path> -e <env> [--param name[:type]=v]... | [--params <json-object>] [--json|--jsonl]
|
|
43
45
|
run read-only SQL against a deployed v2 namespace as the caller
|
|
44
46
|
seq-studio orm namespaces -e <env> [--limit N] [--offset N] [--json]
|
|
45
47
|
list the namespaces you can read
|
|
46
|
-
seq-studio orm describe <namespace> [<table>] -e <env> [--json]
|
|
47
|
-
show a namespace's tables, views, and persisted operations, or one table's columns and actions
|
|
48
|
+
seq-studio orm describe <namespace> [<table> | --operations] -e <env> [--json]
|
|
49
|
+
show a namespace's tables, views, and persisted operations (with variables), or one table's columns and actions
|
|
48
50
|
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)
|
|
49
51
|
seq-studio orm migrate-from-yaml <dir> convert a v1 YAML namespace to the v2 TypeScript format (offline; migrations/ preserved)
|
|
50
52
|
seq-studio orm import [dir] --spec <file> | --table <t> --from <schema.table> --map <target=source,...>
|
|
@@ -187,27 +189,37 @@ async function loadOrmCli() {
|
|
|
187
189
|
' pnpm exec seq-studio orm …');
|
|
188
190
|
}
|
|
189
191
|
else {
|
|
190
|
-
console.error(
|
|
191
|
-
'A CLI installed globally with pnpm 11 cannot load drizzle-kit, which imports drizzle-orm without declaring it; ' +
|
|
192
|
-
'run the app\'s own CLI instead (`pnpm exec seq-studio orm …`).\n' +
|
|
193
|
-
` ${message}`);
|
|
192
|
+
console.error(formatOrmDependencyFailure(message));
|
|
194
193
|
}
|
|
195
194
|
return null;
|
|
196
195
|
}
|
|
197
196
|
}
|
|
197
|
+
export function formatOrmDependencyFailure(message) {
|
|
198
|
+
if (/Cannot find package 'drizzle-orm' imported from .*[/\\]drizzle-kit[/\\]api\.mjs/.test(message)) {
|
|
199
|
+
return 'drizzle-kit cannot resolve drizzle-orm from this CLI installation. Update or reinstall ' +
|
|
200
|
+
'@sequenceholdings/studio-cli so drizzle-orm is installed beside drizzle-kit, then retry.\n' +
|
|
201
|
+
` ${message}`;
|
|
202
|
+
}
|
|
203
|
+
return '@sequenceholdings/orm is installed but a dependency failed to load. Reinstall dependencies, then retry.\n' +
|
|
204
|
+
` ${message}`;
|
|
205
|
+
}
|
|
198
206
|
/**
|
|
199
207
|
* Subcommands seq-studio implements itself rather than forwarding to the ORM
|
|
200
208
|
* CLI: discovery reads Atlas's registry, and ad-hoc reads go through the ORM
|
|
201
209
|
* client. None of them needs a namespace directory.
|
|
202
210
|
*/
|
|
203
|
-
const NATIVE_ORM_SUBS = new Set(['namespaces', 'describe', 'read', 'sql']);
|
|
211
|
+
const NATIVE_ORM_SUBS = new Set(['namespaces', 'describe', 'operation', 'read', 'sql']);
|
|
204
212
|
async function runNativeOrmCommand(sub, rest) {
|
|
205
213
|
const help = rest.includes('--help') || rest.includes('-h');
|
|
206
|
-
if (sub === 'namespaces' || sub === 'describe') {
|
|
214
|
+
if (sub === 'namespaces' || sub === 'describe' || sub === 'operation') {
|
|
207
215
|
if (help) {
|
|
208
216
|
console.log(ORM_DISCOVER_HELP);
|
|
209
217
|
return 0;
|
|
210
218
|
}
|
|
219
|
+
if (sub === 'operation') {
|
|
220
|
+
const { ormOperationShowCommand } = await import('./operation-show.js');
|
|
221
|
+
return ormOperationShowCommand(parseArgs(rest));
|
|
222
|
+
}
|
|
211
223
|
const { ormDescribeCommand, ormNamespacesCommand } = await import('./discover.js');
|
|
212
224
|
return sub === 'namespaces' ? ormNamespacesCommand(parseArgs(rest)) : ormDescribeCommand(parseArgs(rest));
|
|
213
225
|
}
|
|
@@ -218,6 +230,21 @@ async function runNativeOrmCommand(sub, rest) {
|
|
|
218
230
|
}
|
|
219
231
|
return sub === 'read' ? ormReadCommand(parseArgs(rest)) : ormSqlCommand(parseArgs(rest));
|
|
220
232
|
}
|
|
233
|
+
/**
|
|
234
|
+
* Help, and by-name execute: it reads the deployed version, so it needs neither
|
|
235
|
+
* a namespace directory nor the ORM package. Null for everything else.
|
|
236
|
+
*/
|
|
237
|
+
async function runWithoutOrmPackage({ sub, rest, normalized }) {
|
|
238
|
+
if (normalized.includes('--help') || normalized.includes('-h')) {
|
|
239
|
+
console.log(sub === 'execute' ? ORM_EXECUTE_HELP : ORM_HELP);
|
|
240
|
+
return 0;
|
|
241
|
+
}
|
|
242
|
+
if (sub !== 'execute')
|
|
243
|
+
return null;
|
|
244
|
+
const { isDeployedExecute, ormExecuteDeployedCommand } = await import('./execute.js');
|
|
245
|
+
const args = parseArgs(rest);
|
|
246
|
+
return (await isDeployedExecute(args)) ? ormExecuteDeployedCommand(args) : null;
|
|
247
|
+
}
|
|
221
248
|
export async function runOrmCommand(sub, rest) {
|
|
222
249
|
if (!sub || sub === 'help' || sub === '--help' || sub === '-h') {
|
|
223
250
|
console.log(ORM_USAGE);
|
|
@@ -226,10 +253,9 @@ export async function runOrmCommand(sub, rest) {
|
|
|
226
253
|
if (NATIVE_ORM_SUBS.has(sub))
|
|
227
254
|
return runNativeOrmCommand(sub, rest);
|
|
228
255
|
const normalized = normalizeShortEnvFlag(rest);
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
return
|
|
232
|
-
}
|
|
256
|
+
const answered = await runWithoutOrmPackage({ sub, rest, normalized });
|
|
257
|
+
if (answered !== null)
|
|
258
|
+
return answered;
|
|
233
259
|
let repoSelection;
|
|
234
260
|
try {
|
|
235
261
|
repoSelection = extractOrmRepoSelection(normalized);
|
|
@@ -149,8 +149,24 @@ export declare const schemaViewSchema: z.ZodObject<{
|
|
|
149
149
|
view: z.ZodString;
|
|
150
150
|
}, z.core.$loose>>>;
|
|
151
151
|
}, z.core.$loose>;
|
|
152
|
+
/** A declared variable as the stored IR types it: scalar, enum, or a table's dynamic input. */
|
|
153
|
+
declare const variableSchema: z.ZodObject<{
|
|
154
|
+
name: z.ZodString;
|
|
155
|
+
type: z.ZodObject<{
|
|
156
|
+
kind: z.ZodString;
|
|
157
|
+
scalar: z.ZodOptional<z.ZodString>;
|
|
158
|
+
name: z.ZodOptional<z.ZodString>;
|
|
159
|
+
values: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
160
|
+
input: z.ZodOptional<z.ZodString>;
|
|
161
|
+
table: z.ZodOptional<z.ZodString>;
|
|
162
|
+
}, z.core.$loose>;
|
|
163
|
+
nullable: z.ZodBoolean;
|
|
164
|
+
list: z.ZodBoolean;
|
|
165
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
166
|
+
}, z.core.$loose>;
|
|
152
167
|
declare const operationSchema: z.ZodObject<{
|
|
153
168
|
name: z.ZodString;
|
|
169
|
+
op_hash: z.ZodString;
|
|
154
170
|
kind: z.ZodString;
|
|
155
171
|
requires: z.ZodNullable<z.ZodObject<{
|
|
156
172
|
capability: z.ZodOptional<z.ZodString>;
|
|
@@ -160,10 +176,25 @@ declare const operationSchema: z.ZodObject<{
|
|
|
160
176
|
table: z.ZodString;
|
|
161
177
|
op: z.ZodString;
|
|
162
178
|
}, z.core.$loose>>>;
|
|
179
|
+
variables: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
180
|
+
name: z.ZodString;
|
|
181
|
+
type: z.ZodObject<{
|
|
182
|
+
kind: z.ZodString;
|
|
183
|
+
scalar: z.ZodOptional<z.ZodString>;
|
|
184
|
+
name: z.ZodOptional<z.ZodString>;
|
|
185
|
+
values: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
186
|
+
input: z.ZodOptional<z.ZodString>;
|
|
187
|
+
table: z.ZodOptional<z.ZodString>;
|
|
188
|
+
}, z.core.$loose>;
|
|
189
|
+
nullable: z.ZodBoolean;
|
|
190
|
+
list: z.ZodBoolean;
|
|
191
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
192
|
+
}, z.core.$loose>>>;
|
|
163
193
|
}, z.core.$loose>;
|
|
164
194
|
export declare const operationsPageSchema: z.ZodObject<{
|
|
165
195
|
operations: z.ZodArray<z.ZodObject<{
|
|
166
196
|
name: z.ZodString;
|
|
197
|
+
op_hash: z.ZodString;
|
|
167
198
|
kind: z.ZodString;
|
|
168
199
|
requires: z.ZodNullable<z.ZodObject<{
|
|
169
200
|
capability: z.ZodOptional<z.ZodString>;
|
|
@@ -173,11 +204,78 @@ export declare const operationsPageSchema: z.ZodObject<{
|
|
|
173
204
|
table: z.ZodString;
|
|
174
205
|
op: z.ZodString;
|
|
175
206
|
}, z.core.$loose>>>;
|
|
207
|
+
variables: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
208
|
+
name: z.ZodString;
|
|
209
|
+
type: z.ZodObject<{
|
|
210
|
+
kind: z.ZodString;
|
|
211
|
+
scalar: z.ZodOptional<z.ZodString>;
|
|
212
|
+
name: z.ZodOptional<z.ZodString>;
|
|
213
|
+
values: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
214
|
+
input: z.ZodOptional<z.ZodString>;
|
|
215
|
+
table: z.ZodOptional<z.ZodString>;
|
|
216
|
+
}, z.core.$loose>;
|
|
217
|
+
nullable: z.ZodBoolean;
|
|
218
|
+
list: z.ZodBoolean;
|
|
219
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
220
|
+
}, z.core.$loose>>>;
|
|
176
221
|
}, z.core.$loose>>;
|
|
177
222
|
total: z.ZodNumber;
|
|
223
|
+
schema_version_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
224
|
+
}, z.core.$loose>;
|
|
225
|
+
/** `GET /api/orm/namespaces/<ns>/operations/<name>`: one operation of the active set. */
|
|
226
|
+
export declare const operationDetailSchema: z.ZodObject<{
|
|
227
|
+
name: z.ZodString;
|
|
228
|
+
op_hash: z.ZodString;
|
|
229
|
+
kind: z.ZodString;
|
|
230
|
+
requires: z.ZodNullable<z.ZodObject<{
|
|
231
|
+
capability: z.ZodOptional<z.ZodString>;
|
|
232
|
+
role: z.ZodOptional<z.ZodString>;
|
|
233
|
+
}, z.core.$loose>>;
|
|
234
|
+
variables: z.ZodArray<z.ZodObject<{
|
|
235
|
+
name: z.ZodString;
|
|
236
|
+
type: z.ZodObject<{
|
|
237
|
+
kind: z.ZodString;
|
|
238
|
+
scalar: z.ZodOptional<z.ZodString>;
|
|
239
|
+
name: z.ZodOptional<z.ZodString>;
|
|
240
|
+
values: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
241
|
+
input: z.ZodOptional<z.ZodString>;
|
|
242
|
+
table: z.ZodOptional<z.ZodString>;
|
|
243
|
+
}, z.core.$loose>;
|
|
244
|
+
nullable: z.ZodBoolean;
|
|
245
|
+
list: z.ZodBoolean;
|
|
246
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
247
|
+
}, z.core.$loose>>;
|
|
248
|
+
}, z.core.$loose>;
|
|
249
|
+
/** The reader-gated active operation detail also includes its registered document. */
|
|
250
|
+
export declare const operationInspectionSchema: z.ZodObject<{
|
|
251
|
+
name: z.ZodString;
|
|
252
|
+
op_hash: z.ZodString;
|
|
253
|
+
kind: z.ZodString;
|
|
254
|
+
requires: z.ZodNullable<z.ZodObject<{
|
|
255
|
+
capability: z.ZodOptional<z.ZodString>;
|
|
256
|
+
role: z.ZodOptional<z.ZodString>;
|
|
257
|
+
}, z.core.$loose>>;
|
|
258
|
+
variables: z.ZodArray<z.ZodObject<{
|
|
259
|
+
name: z.ZodString;
|
|
260
|
+
type: z.ZodObject<{
|
|
261
|
+
kind: z.ZodString;
|
|
262
|
+
scalar: z.ZodOptional<z.ZodString>;
|
|
263
|
+
name: z.ZodOptional<z.ZodString>;
|
|
264
|
+
values: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
265
|
+
input: z.ZodOptional<z.ZodString>;
|
|
266
|
+
table: z.ZodOptional<z.ZodString>;
|
|
267
|
+
}, z.core.$loose>;
|
|
268
|
+
nullable: z.ZodBoolean;
|
|
269
|
+
list: z.ZodBoolean;
|
|
270
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
271
|
+
}, z.core.$loose>>;
|
|
272
|
+
namespace: z.ZodString;
|
|
273
|
+
document: z.ZodString;
|
|
178
274
|
}, z.core.$loose>;
|
|
179
275
|
export type SchemaView = z.infer<typeof schemaViewSchema>;
|
|
180
276
|
export type Operation = z.infer<typeof operationSchema>;
|
|
277
|
+
export type OperationDetail = z.infer<typeof operationDetailSchema>;
|
|
278
|
+
export type OperationVariable = z.infer<typeof variableSchema>;
|
|
181
279
|
export type Column = z.infer<typeof columnSchema>;
|
|
182
280
|
export type Relation = {
|
|
183
281
|
kind: 'table';
|
|
@@ -65,15 +65,47 @@ export const schemaViewSchema = z.looseObject({
|
|
|
65
65
|
tables: z.array(tableSchema),
|
|
66
66
|
views: z.array(viewSchema).default([]),
|
|
67
67
|
});
|
|
68
|
+
/** A declared variable as the stored IR types it: scalar, enum, or a table's dynamic input. */
|
|
69
|
+
const variableSchema = z.looseObject({
|
|
70
|
+
name: z.string(),
|
|
71
|
+
type: z.looseObject({
|
|
72
|
+
kind: z.string(),
|
|
73
|
+
scalar: z.string().optional(),
|
|
74
|
+
name: z.string().optional(),
|
|
75
|
+
values: z.array(z.string()).optional(),
|
|
76
|
+
input: z.string().optional(),
|
|
77
|
+
table: z.string().optional(),
|
|
78
|
+
}),
|
|
79
|
+
nullable: z.boolean(),
|
|
80
|
+
list: z.boolean(),
|
|
81
|
+
default: z.unknown().optional(),
|
|
82
|
+
});
|
|
68
83
|
const operationSchema = z.looseObject({
|
|
69
84
|
name: z.string(),
|
|
85
|
+
op_hash: z.string(),
|
|
70
86
|
kind: z.string(),
|
|
71
87
|
requires: requiresSchema,
|
|
72
88
|
mutation_roots: z.array(z.looseObject({ table: z.string(), op: z.string() })).default([]),
|
|
89
|
+
/** Absent from servers that predate variables in the listing. */
|
|
90
|
+
variables: z.array(variableSchema).optional(),
|
|
73
91
|
});
|
|
74
92
|
export const operationsPageSchema = z.looseObject({
|
|
75
93
|
operations: z.array(operationSchema),
|
|
76
94
|
total: z.number(),
|
|
95
|
+
schema_version_id: z.string().nullable().optional(),
|
|
96
|
+
});
|
|
97
|
+
/** `GET /api/orm/namespaces/<ns>/operations/<name>`: one operation of the active set. */
|
|
98
|
+
export const operationDetailSchema = z.looseObject({
|
|
99
|
+
name: z.string(),
|
|
100
|
+
op_hash: z.string(),
|
|
101
|
+
kind: z.string(),
|
|
102
|
+
requires: requiresSchema,
|
|
103
|
+
variables: z.array(variableSchema),
|
|
104
|
+
});
|
|
105
|
+
/** The reader-gated active operation detail also includes its registered document. */
|
|
106
|
+
export const operationInspectionSchema = operationDetailSchema.safeExtend({
|
|
107
|
+
namespace: z.string(),
|
|
108
|
+
document: z.string(),
|
|
77
109
|
});
|
|
78
110
|
export function parseResponse({ schema, body, what }) {
|
|
79
111
|
const parsed = schema.safeParse(body);
|
package/dist/orm/discover.js
CHANGED
|
@@ -14,6 +14,7 @@ import { validateCommandInput } from '../command-input.js';
|
|
|
14
14
|
import { buildContext, clientOptions } from '../functions/commands.js';
|
|
15
15
|
import { table } from '../text-table.js';
|
|
16
16
|
import { namespaceListSchema, operationsPageSchema, parseResponse, schemaViewSchema, } from './discover-schema.js';
|
|
17
|
+
import { variablesLabel } from './execute.js';
|
|
17
18
|
/** The server's maximum operations page; describe pages until it has them all. */
|
|
18
19
|
const OPERATIONS_PAGE_SIZE = 500;
|
|
19
20
|
const DESCRIPTION_WIDTH = 60;
|
|
@@ -141,9 +142,16 @@ function printOperations({ operations, heading }) {
|
|
|
141
142
|
console.log(' (none)');
|
|
142
143
|
return;
|
|
143
144
|
}
|
|
145
|
+
// Servers that predate variables in the listing omit the field entirely.
|
|
146
|
+
const withVariables = operations.some((operation) => operation.variables !== undefined);
|
|
144
147
|
table({
|
|
145
|
-
headers: ['OPERATION', 'KIND', 'REQUIRES'],
|
|
146
|
-
rows: operations.map((operation) => [
|
|
148
|
+
headers: ['OPERATION', 'KIND', 'REQUIRES', ...(withVariables ? ['VARIABLES'] : [])],
|
|
149
|
+
rows: operations.map((operation) => [
|
|
150
|
+
operation.name,
|
|
151
|
+
operation.kind,
|
|
152
|
+
requiresLabel(operation.requires),
|
|
153
|
+
...(withVariables ? [variablesLabel(operation.variables ?? [])] : []),
|
|
154
|
+
]),
|
|
147
155
|
});
|
|
148
156
|
}
|
|
149
157
|
function printNamespace({ schema, operations }) {
|
|
@@ -233,7 +241,11 @@ function operationsWriting({ operations, name }) {
|
|
|
233
241
|
export async function ormDescribeCommand(args) {
|
|
234
242
|
try {
|
|
235
243
|
const [namespace, tableName] = args.positional;
|
|
236
|
-
validateCommandInput({ args, flags: {}, positional: tableName === undefined ? 1 : 2 });
|
|
244
|
+
validateCommandInput({ args, flags: { operations: 'boolean' }, positional: tableName === undefined ? 1 : 2 });
|
|
245
|
+
const onlyOperations = args.flags.operations === true;
|
|
246
|
+
if (onlyOperations && tableName !== undefined) {
|
|
247
|
+
throw new Error('--operations lists the whole namespace\'s operations; drop <table>.');
|
|
248
|
+
}
|
|
237
249
|
const options = clientOptions(await buildContext(args));
|
|
238
250
|
const encoded = encodeURIComponent(namespace);
|
|
239
251
|
const [schemaBody, operations] = await Promise.all([
|
|
@@ -241,6 +253,17 @@ export async function ormDescribeCommand(args) {
|
|
|
241
253
|
listAllOperations({ options, namespace: namespace }),
|
|
242
254
|
]);
|
|
243
255
|
const schema = parseResponse({ schema: schemaViewSchema, body: schemaBody, what: 'schema' });
|
|
256
|
+
if (onlyOperations) {
|
|
257
|
+
if (args.flags.json === true) {
|
|
258
|
+
console.log(JSON.stringify({ namespace: schema.namespace, version_id: schema.version_id, operations }, null, 2));
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
console.log(`${schema.namespace} ${formatLabel(schema.definition_format)} version ${schema.version_id}`);
|
|
262
|
+
printOperations({ operations, heading: 'Persisted operations:' });
|
|
263
|
+
console.error(`Run one: seq-studio orm execute ${schema.namespace} <operation> --var <name>=<value>`);
|
|
264
|
+
}
|
|
265
|
+
return 0;
|
|
266
|
+
}
|
|
244
267
|
if (tableName === undefined) {
|
|
245
268
|
// The generated GraphQL SDL is large and restates the tables; leave it out.
|
|
246
269
|
const { sdl: _sdl, ...described } = schema;
|
|
@@ -249,6 +272,8 @@ export async function ormDescribeCommand(args) {
|
|
|
249
272
|
else {
|
|
250
273
|
printNamespace({ schema, operations });
|
|
251
274
|
console.error(`Describe a table: seq-studio orm describe ${schema.namespace} <table>`);
|
|
275
|
+
if (operations.length > 0)
|
|
276
|
+
console.error(`Run an operation: seq-studio orm execute ${schema.namespace} <operation>`);
|
|
252
277
|
}
|
|
253
278
|
}
|
|
254
279
|
else {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `seq-studio orm execute <namespace> <operation>` — run a deployed persisted
|
|
3
|
+
* operation by name, with no checkout.
|
|
4
|
+
*
|
|
5
|
+
* The data endpoint selects an operation by content hash, so a checkout's
|
|
6
|
+
* manifest only works while it matches what is deployed. This form asks the
|
|
7
|
+
* control plane for the ACTIVE version's operation (hash and declared
|
|
8
|
+
* variables) and posts that hash, so it always runs what is deployed. The
|
|
9
|
+
* server still applies the operation's requirements and the namespace's row
|
|
10
|
+
* policies to the caller.
|
|
11
|
+
*/
|
|
12
|
+
import type { ParsedArgs } from '../process/commands.js';
|
|
13
|
+
import { type OperationDetail, type OperationVariable } from './discover-schema.js';
|
|
14
|
+
type Variables = Record<string, unknown>;
|
|
15
|
+
/**
|
|
16
|
+
* `<namespace> <operation>` when the second argument is an operation name and
|
|
17
|
+
* not a directory; otherwise the checkout form `<operation> [dir]`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function isDeployedExecute(args: ParsedArgs): Promise<boolean>;
|
|
20
|
+
/** `id: uuid!`, `ids: [uuid]`, `where: boolExp(loans)`, `limit: integer = 50`. */
|
|
21
|
+
export declare function variableLabel(variable: OperationVariable): string;
|
|
22
|
+
export declare function variablesLabel(variables: readonly OperationVariable[]): string;
|
|
23
|
+
/** One `--var` value, typed by the deployed operation's declaration. */
|
|
24
|
+
export declare function coerceVariable({ variable, raw }: {
|
|
25
|
+
variable: OperationVariable;
|
|
26
|
+
raw: string;
|
|
27
|
+
}): unknown;
|
|
28
|
+
export declare function parseVarFlags({ args, operation }: {
|
|
29
|
+
args: ParsedArgs;
|
|
30
|
+
operation: OperationDetail;
|
|
31
|
+
}): Variables;
|
|
32
|
+
export declare function ormExecuteDeployedCommand(args: ParsedArgs): Promise<number>;
|
|
33
|
+
export {};
|