@usestatemachines/cli 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +34 -2
- package/dist/agents/bundled.d.ts +5 -0
- package/dist/agents/bundled.js +6 -0
- package/dist/agents/destinations.d.ts +13 -0
- package/dist/agents/destinations.js +16 -0
- package/dist/api-internal.d.ts +62 -0
- package/dist/api-internal.js +348 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +4 -0
- package/dist/command.d.ts +119 -0
- package/dist/command.js +195 -0
- package/dist/commands/api/command.d.ts +15 -0
- package/dist/commands/api/command.js +38 -0
- package/dist/commands/api/run.d.ts +4 -0
- package/dist/commands/api/run.js +24 -0
- package/dist/commands/apps/command.d.ts +19 -0
- package/dist/commands/apps/command.js +29 -0
- package/dist/commands/apps/list.d.ts +8 -0
- package/dist/commands/apps/list.js +10 -0
- package/dist/commands/connect/command.d.ts +34 -0
- package/dist/commands/connect/command.js +70 -0
- package/dist/commands/connect/run.d.ts +10 -0
- package/dist/commands/connect/run.js +71 -0
- package/dist/commands/doctor/command.d.ts +29 -0
- package/dist/commands/doctor/command.js +36 -0
- package/dist/commands/doctor/run.d.ts +13 -0
- package/dist/commands/doctor/run.js +12 -0
- package/dist/commands/env/command.d.ts +5 -0
- package/dist/commands/env/command.js +19 -0
- package/dist/commands/env/pull.d.ts +6 -0
- package/dist/commands/env/pull.js +6 -0
- package/dist/commands/environments/command.d.ts +121 -0
- package/dist/commands/environments/command.js +170 -0
- package/dist/commands/environments/create.d.ts +9 -0
- package/dist/commands/environments/create.js +42 -0
- package/dist/commands/environments/delete.d.ts +7 -0
- package/dist/commands/environments/delete.js +48 -0
- package/dist/commands/environments/get.d.ts +39 -0
- package/dist/commands/environments/get.js +5 -0
- package/dist/commands/environments/list.d.ts +41 -0
- package/dist/commands/environments/list.js +18 -0
- package/dist/commands/environments/wait.d.ts +39 -0
- package/dist/commands/environments/wait.js +21 -0
- package/dist/commands/init/command.d.ts +68 -0
- package/dist/commands/init/command.js +90 -0
- package/dist/commands/init/run.d.ts +8 -0
- package/dist/commands/init/run.js +422 -0
- package/dist/commands/link/command.d.ts +13 -0
- package/dist/commands/link/command.js +32 -0
- package/dist/commands/link/run.d.ts +12 -0
- package/dist/commands/link/run.js +7 -0
- package/dist/commands/login/command.d.ts +1 -0
- package/dist/commands/login/command.js +43 -0
- package/dist/commands/login/run.d.ts +30 -0
- package/dist/commands/login/run.js +43 -0
- package/dist/commands/login/schema.d.ts +33 -0
- package/dist/commands/login/schema.js +33 -0
- package/dist/commands/logout/command.d.ts +1 -0
- package/dist/commands/logout/command.js +24 -0
- package/dist/commands/logout/run.d.ts +10 -0
- package/dist/commands/logout/run.js +19 -0
- package/dist/commands/logout/schema.d.ts +10 -0
- package/dist/commands/logout/schema.js +10 -0
- package/dist/commands/profiles/command.d.ts +2 -0
- package/dist/commands/profiles/command.js +29 -0
- package/dist/commands/profiles/list.d.ts +20 -0
- package/dist/commands/profiles/list.js +10 -0
- package/dist/commands/profiles/schema.d.ts +24 -0
- package/dist/commands/profiles/schema.js +19 -0
- package/dist/commands/profiles/use.d.ts +7 -0
- package/dist/commands/profiles/use.js +7 -0
- package/dist/commands/requests/command.d.ts +39 -0
- package/dist/commands/requests/command.js +65 -0
- package/dist/commands/requests/get.d.ts +32 -0
- package/dist/commands/requests/get.js +15 -0
- package/dist/commands/requests/list.d.ts +27 -0
- package/dist/commands/requests/list.js +25 -0
- package/dist/commands/snapshots/command.d.ts +48 -0
- package/dist/commands/snapshots/command.js +80 -0
- package/dist/commands/snapshots/create.d.ts +7 -0
- package/dist/commands/snapshots/create.js +26 -0
- package/dist/commands/snapshots/delete.d.ts +34 -0
- package/dist/commands/snapshots/delete.js +8 -0
- package/dist/commands/snapshots/get.d.ts +35 -0
- package/dist/commands/snapshots/get.js +5 -0
- package/dist/commands/snapshots/list.d.ts +37 -0
- package/dist/commands/snapshots/list.js +10 -0
- package/dist/commands/unlink/command.d.ts +1 -0
- package/dist/commands/unlink/command.js +15 -0
- package/dist/commands/unlink/run.d.ts +7 -0
- package/dist/commands/unlink/run.js +8 -0
- package/dist/commands/whoami/command.d.ts +28 -0
- package/dist/commands/whoami/command.js +44 -0
- package/dist/commands/whoami/run.d.ts +5 -0
- package/dist/commands/whoami/run.js +39 -0
- package/dist/commands/workspaces/command.d.ts +33 -0
- package/dist/commands/workspaces/command.js +73 -0
- package/dist/commands/workspaces/list.d.ts +5 -0
- package/dist/commands/workspaces/list.js +42 -0
- package/dist/commands/workspaces/use.d.ts +5 -0
- package/dist/commands/workspaces/use.js +18 -0
- package/dist/config/project.d.ts +21 -0
- package/dist/config/project.js +105 -0
- package/dist/config/schema.d.ts +616 -0
- package/dist/config/schema.js +282 -0
- package/dist/context-types.d.ts +89 -0
- package/dist/context-types.js +56 -0
- package/dist/context.d.ts +13 -0
- package/dist/context.js +290 -0
- package/dist/credentials/sealing.d.ts +10 -0
- package/dist/credentials/sealing.js +72 -0
- package/dist/credentials/store.d.ts +17 -0
- package/dist/credentials/store.js +156 -0
- package/dist/doctor.d.ts +4 -0
- package/dist/doctor.js +239 -0
- package/dist/env-file.d.ts +10 -0
- package/dist/env-file.js +254 -0
- package/dist/errors.d.ts +784 -0
- package/dist/errors.js +459 -0
- package/dist/flags.d.ts +22 -0
- package/dist/flags.js +56 -0
- package/dist/generated/internal.d.ts +138 -0
- package/dist/generated/internal.js +2627 -0
- package/dist/generated/retry.d.ts +1 -0
- package/dist/generated/retry.js +11 -0
- package/dist/help.d.ts +408 -0
- package/dist/help.js +220 -0
- package/dist/io-types.d.ts +127 -0
- package/dist/io-types.js +1 -0
- package/dist/io.d.ts +13 -0
- package/dist/io.js +1017 -0
- package/dist/keys.d.ts +50 -0
- package/dist/keys.js +691 -0
- package/dist/link.d.ts +6 -0
- package/dist/link.js +58 -0
- package/dist/login.d.ts +92 -0
- package/dist/login.js +965 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +126 -0
- package/dist/native-helper.d.ts +1 -0
- package/dist/native-helper.js +2 -0
- package/dist/output.d.ts +8 -0
- package/dist/output.js +135 -0
- package/dist/parser.d.ts +28 -0
- package/dist/parser.js +250 -0
- package/dist/program-types.d.ts +67 -0
- package/dist/program-types.js +14 -0
- package/dist/programs.d.ts +2 -0
- package/dist/programs.js +44 -0
- package/dist/project-roots.d.ts +3 -0
- package/dist/project-roots.js +26 -0
- package/dist/prompt.d.ts +3 -0
- package/dist/prompt.js +61 -0
- package/dist/registry.d.ts +2 -0
- package/dist/registry.js +44 -0
- package/dist/resources/create.d.ts +9 -0
- package/dist/resources/create.js +55 -0
- package/dist/resources/read.d.ts +15 -0
- package/dist/resources/read.js +69 -0
- package/dist/resources/schema.d.ts +177 -0
- package/dist/resources/schema.js +158 -0
- package/dist/text.d.ts +3 -0
- package/dist/text.js +19 -0
- package/dist/update.d.ts +22 -0
- package/dist/update.js +126 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +2 -0
- package/package.json +52 -3
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { EffectOptions, Io } from '../io-types.js';
|
|
3
|
+
declare const projectSchema: z.ZodObject<{
|
|
4
|
+
version: z.ZodLiteral<1>;
|
|
5
|
+
organizationId: z.core.$ZodBranded<z.ZodString, "OrganizationId", "out">;
|
|
6
|
+
workspaceId: z.core.$ZodBranded<z.ZodString, "WorkspaceId", "out">;
|
|
7
|
+
}, z.core.$strict>;
|
|
8
|
+
export type ProjectLink = z.infer<typeof projectSchema>;
|
|
9
|
+
export interface ProjectRepository {
|
|
10
|
+
read(): Promise<(ProjectLink & {
|
|
11
|
+
path: string;
|
|
12
|
+
}) | null>;
|
|
13
|
+
link(value: Omit<ProjectLink, 'version'>, force: boolean): Promise<ProjectLink & {
|
|
14
|
+
path: string;
|
|
15
|
+
}>;
|
|
16
|
+
unlink(): Promise<{
|
|
17
|
+
path: string | null;
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
20
|
+
export declare function createProjectRepository(io: Io, options: EffectOptions): ProjectRepository;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { dirname, join } from 'node:path';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { organizationIdSchema, workspaceIdSchema } from '../context-types.js';
|
|
4
|
+
import { CliError } from '../errors.js';
|
|
5
|
+
import { findProjectRoot } from '../project-roots.js';
|
|
6
|
+
import { parseVersioned } from './schema.js';
|
|
7
|
+
const projectSchema = z.strictObject({
|
|
8
|
+
version: z.literal(1),
|
|
9
|
+
organizationId: organizationIdSchema,
|
|
10
|
+
workspaceId: workspaceIdSchema,
|
|
11
|
+
});
|
|
12
|
+
export function createProjectRepository(io, options) {
|
|
13
|
+
async function read() {
|
|
14
|
+
const root = await findProjectRoot(io, options);
|
|
15
|
+
if (root === null) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
let directory = io.host.cwd;
|
|
19
|
+
while (true) {
|
|
20
|
+
const path = join(directory, '.statemachines', 'project.json');
|
|
21
|
+
const text = await io.files.read(path, options);
|
|
22
|
+
if (text !== null) {
|
|
23
|
+
return { ...parseVersioned(text, projectSchema), path };
|
|
24
|
+
}
|
|
25
|
+
if (directory === root || dirname(directory) === directory) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
directory = dirname(directory);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
read,
|
|
33
|
+
async link(value, force) {
|
|
34
|
+
const root = await findProjectRoot(io, options);
|
|
35
|
+
if (root === null) {
|
|
36
|
+
throw new CliError('cli.not_linked');
|
|
37
|
+
}
|
|
38
|
+
const path = join(root, '.statemachines', 'project.json');
|
|
39
|
+
return io.files.withLock(join(root, '.statemachines', '.lock'), options, async () => {
|
|
40
|
+
const links = [];
|
|
41
|
+
let directory = io.host.cwd;
|
|
42
|
+
while (true) {
|
|
43
|
+
const candidate = join(directory, '.statemachines', 'project.json');
|
|
44
|
+
const text = await io.files.read(candidate, options);
|
|
45
|
+
if (text !== null) {
|
|
46
|
+
links.push({
|
|
47
|
+
...parseVersioned(text, projectSchema),
|
|
48
|
+
path: candidate,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (directory === root || dirname(directory) === directory) {
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
directory = dirname(directory);
|
|
55
|
+
}
|
|
56
|
+
if (!force &&
|
|
57
|
+
links.some((existing) => existing.organizationId !== value.organizationId)) {
|
|
58
|
+
throw new CliError('cli.organization_mismatch');
|
|
59
|
+
}
|
|
60
|
+
if (!force &&
|
|
61
|
+
links.some((existing) => existing.workspaceId !== value.workspaceId)) {
|
|
62
|
+
throw new CliError('cli.workspace_mismatch', {
|
|
63
|
+
message: 'This repository is linked to another workspace in the same organization.',
|
|
64
|
+
next: [
|
|
65
|
+
{
|
|
66
|
+
command: 'statemachines link --force',
|
|
67
|
+
reason: 'Replace the repository link.',
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
const project = { version: 1, ...value };
|
|
73
|
+
const ignorePath = join(root, '.gitignore');
|
|
74
|
+
const ignore = (await io.files.read(ignorePath, options)) ?? '';
|
|
75
|
+
if (!ignore
|
|
76
|
+
.split(/\r?\n/)
|
|
77
|
+
.some((line) => /^(?:\/)?\.statemachines\/?$/.test(line.trim()))) {
|
|
78
|
+
await io.files.atomicWrite(ignorePath, `${ignore}${ignore === '' || ignore.endsWith('\n') ? '' : '\n'}.statemachines\n`, 'public', options);
|
|
79
|
+
}
|
|
80
|
+
await io.files.atomicWrite(path, `${JSON.stringify(project, null, 2)}\n`, 'public', options);
|
|
81
|
+
if (force) {
|
|
82
|
+
for (const existing of links) {
|
|
83
|
+
if (existing.path !== path) {
|
|
84
|
+
await io.files.remove(existing.path, options);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return { ...project, path };
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
async unlink() {
|
|
92
|
+
const root = await findProjectRoot(io, options);
|
|
93
|
+
if (root === null) {
|
|
94
|
+
return { path: null };
|
|
95
|
+
}
|
|
96
|
+
return io.files.withLock(join(root, '.statemachines', '.lock'), options, async () => {
|
|
97
|
+
const link = await read();
|
|
98
|
+
if (link !== null) {
|
|
99
|
+
await io.files.remove(link.path, options);
|
|
100
|
+
}
|
|
101
|
+
return { path: link?.path ?? null };
|
|
102
|
+
});
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|