@astrale-os/cli 0.8.1-alpha.2 → 0.8.1-alpha.4
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 +1 -1
- package/dist/astrale.js +206 -160
- package/package.json +1 -1
- package/src/commands/__tests__/call-describe.test.ts +67 -0
- package/src/commands/__tests__/install-direct.test.ts +20 -0
- package/src/commands/__tests__/instance-list-admin.test.ts +26 -0
- package/src/commands/__tests__/logs.test.ts +23 -0
- package/src/commands/__tests__/read-commands.test.ts +0 -12
- package/src/commands/call-describe.ts +131 -0
- package/src/commands/call.ts +17 -21
- package/src/commands/domain/install.ts +39 -13
- package/src/commands/domain/list.ts +1 -1
- package/src/commands/get.ts +3 -3
- package/src/commands/instance/list.ts +36 -3
- package/src/commands/logs.ts +29 -9
- package/src/graph/__tests__/mutation.test.ts +3 -1
- package/src/graph/mutation.ts +15 -0
- package/src/lib/__tests__/command-dx.test.ts +13 -1
- package/src/lib/command-dx.ts +12 -0
- package/src/program/__tests__/program.test.ts +3 -3
- package/src/program/build.ts +1 -3
- package/src/telemetry/__tests__/gate.test.ts +1 -1
- package/src/commands/__tests__/ls.test.ts +0 -29
- package/src/commands/ls.ts +0 -125
package/src/commands/ls.ts
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import type { Node } from '@astrale-os/sdk/graph/node'
|
|
2
|
-
import type { QueryDirection, QueryResult } from '@astrale-os/sdk/query'
|
|
3
|
-
|
|
4
|
-
import { ClassPath } from '@astrale-os/sdk/graph/class'
|
|
5
|
-
import chalk from 'chalk'
|
|
6
|
-
|
|
7
|
-
import type { KernelCommandOpts } from '../connection'
|
|
8
|
-
import type { ListProjection } from '../lib/output'
|
|
9
|
-
import type { CommandDefinition } from '../program/index'
|
|
10
|
-
|
|
11
|
-
import { expandSelfInPath, runKernelCommand, withSelfHint } from '../connection'
|
|
12
|
-
import { nodeProperty, prepareQuery } from '../graph/index'
|
|
13
|
-
import { log } from '../lib/log'
|
|
14
|
-
import { isMachine, presentList } from '../lib/output'
|
|
15
|
-
|
|
16
|
-
type LsOpts = KernelCommandOpts & {
|
|
17
|
-
edge?: string
|
|
18
|
-
direction?: QueryDirection
|
|
19
|
-
limit?: string
|
|
20
|
-
cursor?: string
|
|
21
|
-
long?: boolean
|
|
22
|
-
quiet?: boolean
|
|
23
|
-
count?: boolean
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export async function lsCommand(source: string, opts: LsOpts): Promise<void> {
|
|
27
|
-
if (opts.edge === undefined) {
|
|
28
|
-
log.error('ls requires --edge <class>; Kernel V2 has no universal child relation')
|
|
29
|
-
process.exit(1)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
let path: string
|
|
33
|
-
let meta
|
|
34
|
-
let prepared
|
|
35
|
-
try {
|
|
36
|
-
;({ path, meta } = await expandSelfInPath(source, opts))
|
|
37
|
-
prepared = prepareQuery({
|
|
38
|
-
sources: [path],
|
|
39
|
-
edge: opts.edge,
|
|
40
|
-
direction: opts.direction,
|
|
41
|
-
limit: opts.limit,
|
|
42
|
-
cursor: opts.cursor,
|
|
43
|
-
})
|
|
44
|
-
} catch (error) {
|
|
45
|
-
log.error(error instanceof Error ? error.message : 'Invalid edge neighborhood')
|
|
46
|
-
process.exit(1)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
await runKernelCommand({
|
|
50
|
-
opts,
|
|
51
|
-
label: `Neighbors of ${path}`,
|
|
52
|
-
fn: ({ graph }) => withSelfHint(() => graph.query(prepared.ast, { page: prepared.page }), meta),
|
|
53
|
-
format: (response, format) => {
|
|
54
|
-
const graph = completeGraph(response.result)
|
|
55
|
-
presentList(
|
|
56
|
-
[...graph.nodes],
|
|
57
|
-
{ ...format, long: opts.long, quiet: opts.quiet, count: opts.count },
|
|
58
|
-
listProjection,
|
|
59
|
-
)
|
|
60
|
-
if (response.page.next && !isMachine(format) && !opts.quiet && !opts.count) {
|
|
61
|
-
process.stderr.write(` cursor: ${response.page.next}\n`)
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
})
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function completeGraph(result: QueryResult) {
|
|
68
|
-
if (result.kind !== 'graph') throw new TypeError('ls expected one complete graph Query result')
|
|
69
|
-
return result.graph
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export function listProjection(nodes: Node[]): ListProjection {
|
|
73
|
-
return {
|
|
74
|
-
columns: [
|
|
75
|
-
{ key: 'name', header: 'NAME', color: chalk.cyan },
|
|
76
|
-
{ key: 'class', header: 'CLASS', color: chalk.dim },
|
|
77
|
-
{ key: 'id', header: 'ID', color: chalk.dim },
|
|
78
|
-
],
|
|
79
|
-
rows: nodes.map((node) => ({
|
|
80
|
-
name: displayName(node),
|
|
81
|
-
class: ClassPath.name(node.class),
|
|
82
|
-
id: node.id,
|
|
83
|
-
})),
|
|
84
|
-
paths: nodes.map((node) => `@${node.id}`),
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export function displayName(node: Node): string {
|
|
89
|
-
const value =
|
|
90
|
-
nodeProperty(node, 'name') ?? nodeProperty(node, 'title') ?? nodeProperty(node, 'slug')
|
|
91
|
-
return typeof value === 'string' && value.length > 0 ? value : `@${node.id}`
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export default {
|
|
95
|
-
name: 'ls',
|
|
96
|
-
description: 'List one finite exact edge neighborhood',
|
|
97
|
-
afterHelpText: `
|
|
98
|
-
Behavior:
|
|
99
|
-
Lists Nodes reached from one source through one exact Edge Class. Kernel V2
|
|
100
|
-
has no universal parent/child relation, so --edge is required and recursive
|
|
101
|
-
tree walking is intentionally absent. Direction defaults to outgoing and the
|
|
102
|
-
finite default limit is 100. -q emits one @id per line.
|
|
103
|
-
|
|
104
|
-
Examples:
|
|
105
|
-
$ astrale ls @note --edge /:notes.example.dev:class.references
|
|
106
|
-
$ astrale ls @note --edge /:notes.example.dev:class.references --direction incoming --limit 25
|
|
107
|
-
`,
|
|
108
|
-
arguments: [{ name: 'source', description: 'Canonical source Path or @id' }],
|
|
109
|
-
options: [
|
|
110
|
-
{ flags: '--edge <class>', description: 'Exact Edge Class to traverse' },
|
|
111
|
-
{
|
|
112
|
-
flags: '--direction <direction>',
|
|
113
|
-
description: 'Traversal direction (default: outgoing)',
|
|
114
|
-
choices: ['outgoing', 'incoming', 'incident'],
|
|
115
|
-
},
|
|
116
|
-
{ flags: '--limit <n>', description: 'Finite selected Node limit (default: 100)' },
|
|
117
|
-
{ flags: '--cursor <token>', description: 'Resume one live query scope' },
|
|
118
|
-
{ flags: '-l, --long', description: 'Print complete canonical Nodes' },
|
|
119
|
-
{ flags: '-q, --quiet', description: 'Print one @id per line' },
|
|
120
|
-
{ flags: '--count', description: 'Print only the number of returned Nodes' },
|
|
121
|
-
],
|
|
122
|
-
action: async (source, opts) => {
|
|
123
|
-
await lsCommand(source as string, opts as LsOpts)
|
|
124
|
-
},
|
|
125
|
-
} satisfies CommandDefinition
|