@orthograph/cli 0.0.0-stage → 0.1.0-next.1
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 +202 -0
- package/README.md +28 -2
- package/dist/main.d.ts +2 -0
- package/dist/main.js +318 -0
- package/dist/modules/add/internal/journeys.d.ts +3 -0
- package/dist/modules/add/internal/journeys.js +13 -0
- package/dist/modules/add/internal/names.d.ts +8 -0
- package/dist/modules/add/internal/names.js +9 -0
- package/dist/modules/add/internal/templates.d.ts +16 -0
- package/dist/modules/add/internal/templates.js +104 -0
- package/dist/modules/add/service.d.ts +2 -0
- package/dist/modules/add/service.js +27 -0
- package/dist/modules/add/types.d.ts +30 -0
- package/dist/modules/add/types.js +6 -0
- package/dist/modules/brief/service.d.ts +2 -0
- package/dist/modules/brief/service.js +48 -0
- package/dist/modules/brief/types.d.ts +16 -0
- package/dist/modules/brief/types.js +1 -0
- package/dist/modules/check/internal/blanks.d.ts +3 -0
- package/dist/modules/check/internal/blanks.js +11 -0
- package/dist/modules/check/internal/changes.d.ts +8 -0
- package/dist/modules/check/internal/changes.js +16 -0
- package/dist/modules/check/internal/drift.d.ts +4 -0
- package/dist/modules/check/internal/drift.js +25 -0
- package/dist/modules/check/internal/files.d.ts +8 -0
- package/dist/modules/check/internal/files.js +18 -0
- package/dist/modules/check/internal/ratchets.d.ts +7 -0
- package/dist/modules/check/internal/ratchets.js +17 -0
- package/dist/modules/check/internal/tools.d.ts +12 -0
- package/dist/modules/check/internal/tools.js +66 -0
- package/dist/modules/check/service.d.ts +2 -0
- package/dist/modules/check/service.js +37 -0
- package/dist/modules/check/types.d.ts +32 -0
- package/dist/modules/check/types.js +1 -0
- package/dist/modules/generate/service.d.ts +2 -0
- package/dist/modules/generate/service.js +18 -0
- package/dist/modules/generate/types.d.ts +13 -0
- package/dist/modules/generate/types.js +1 -0
- package/dist/modules/handoff/internal/find.d.ts +6 -0
- package/dist/modules/handoff/internal/find.js +29 -0
- package/dist/modules/handoff/service.d.ts +2 -0
- package/dist/modules/handoff/service.js +16 -0
- package/dist/modules/handoff/types.d.ts +17 -0
- package/dist/modules/handoff/types.js +2 -0
- package/dist/modules/model/internal/summary.d.ts +3 -0
- package/dist/modules/model/internal/summary.js +6 -0
- package/dist/modules/model/service.d.ts +2 -0
- package/dist/modules/model/service.js +9 -0
- package/dist/modules/model/types.d.ts +14 -0
- package/dist/modules/model/types.js +1 -0
- package/dist/modules/mounting/internal/age.d.ts +9 -0
- package/dist/modules/mounting/internal/age.js +47 -0
- package/dist/modules/mounting/internal/needs.d.ts +2 -0
- package/dist/modules/mounting/internal/needs.js +26 -0
- package/dist/modules/mounting/internal/scaffold.d.ts +3 -0
- package/dist/modules/mounting/internal/scaffold.js +27 -0
- package/dist/modules/mounting/service.d.ts +7 -0
- package/dist/modules/mounting/service.js +71 -0
- package/dist/modules/mounting/types.d.ts +28 -0
- package/dist/modules/mounting/types.js +6 -0
- package/dist/modules/new/internal/read.d.ts +6 -0
- package/dist/modules/new/internal/read.js +15 -0
- package/dist/modules/new/service.d.ts +2 -0
- package/dist/modules/new/service.js +28 -0
- package/dist/modules/new/types.d.ts +22 -0
- package/dist/modules/new/types.js +5 -0
- package/dist/modules/secrets/internal/argv.d.ts +3 -0
- package/dist/modules/secrets/internal/argv.js +27 -0
- package/dist/modules/secrets/service.d.ts +2 -0
- package/dist/modules/secrets/service.js +26 -0
- package/dist/modules/secrets/types.d.ts +23 -0
- package/dist/modules/secrets/types.js +1 -0
- package/dist/modules/ship/service.d.ts +2 -0
- package/dist/modules/ship/service.js +36 -0
- package/dist/modules/ship/types.d.ts +35 -0
- package/dist/modules/ship/types.js +1 -0
- package/dist/modules/staging/internal/address.d.ts +21 -0
- package/dist/modules/staging/internal/address.js +28 -0
- package/dist/modules/staging/internal/alchemy-bin.d.ts +3 -0
- package/dist/modules/staging/internal/alchemy-bin.js +12 -0
- package/dist/modules/staging/internal/app.d.ts +3 -0
- package/dist/modules/staging/internal/app.js +23 -0
- package/dist/modules/staging/internal/cloudflare.d.ts +2 -0
- package/dist/modules/staging/internal/cloudflare.js +47 -0
- package/dist/modules/staging/internal/config.d.ts +26 -0
- package/dist/modules/staging/internal/config.js +39 -0
- package/dist/modules/staging/internal/deploy.d.ts +3 -0
- package/dist/modules/staging/internal/deploy.js +50 -0
- package/dist/modules/staging/internal/destroy.d.ts +10 -0
- package/dist/modules/staging/internal/destroy.js +29 -0
- package/dist/modules/staging/internal/live.d.ts +2 -0
- package/dist/modules/staging/internal/live.js +33 -0
- package/dist/modules/staging/internal/plan.d.ts +28 -0
- package/dist/modules/staging/internal/plan.js +56 -0
- package/dist/modules/staging/internal/stack.d.ts +15 -0
- package/dist/modules/staging/internal/stack.js +24 -0
- package/dist/modules/staging/service.d.ts +7 -0
- package/dist/modules/staging/service.js +52 -0
- package/dist/modules/staging/types.d.ts +110 -0
- package/dist/modules/staging/types.js +9 -0
- package/dist/modules/telemetry/service.d.ts +2 -0
- package/dist/modules/telemetry/service.js +27 -0
- package/dist/modules/telemetry/types.d.ts +19 -0
- package/dist/modules/telemetry/types.js +1 -0
- package/dist/modules/watch/service.d.ts +2 -0
- package/dist/modules/watch/service.js +17 -0
- package/dist/modules/watch/types.d.ts +23 -0
- package/dist/modules/watch/types.js +1 -0
- package/package.json +36 -3
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { type Effect } from "effect";
|
|
2
|
+
/** What a command prints and how it exits; only `main.ts` writes it out. */
|
|
3
|
+
export interface Said {
|
|
4
|
+
readonly out: string;
|
|
5
|
+
readonly err: string;
|
|
6
|
+
readonly exit: number;
|
|
7
|
+
}
|
|
8
|
+
export type Kind = "worker" | "d1" | "durable-object-namespace";
|
|
9
|
+
export interface Resource {
|
|
10
|
+
readonly kind: Kind;
|
|
11
|
+
/** A Worker's or a database's name, under the run's prefix. */
|
|
12
|
+
readonly name?: string;
|
|
13
|
+
/** A database's binding in the Worker. */
|
|
14
|
+
readonly binding?: string;
|
|
15
|
+
/** A namespace's Worker, under the run's prefix. */
|
|
16
|
+
readonly script?: string;
|
|
17
|
+
/** A namespace's class. */
|
|
18
|
+
readonly class?: string;
|
|
19
|
+
}
|
|
20
|
+
/** The one plan: what a staging deploy makes and what a destroy deletes. Printed as one JSON document. */
|
|
21
|
+
export interface Plan {
|
|
22
|
+
readonly app: string;
|
|
23
|
+
readonly environment: string;
|
|
24
|
+
readonly run: string;
|
|
25
|
+
readonly prefix: string;
|
|
26
|
+
readonly resources: ReadonlyArray<Resource>;
|
|
27
|
+
}
|
|
28
|
+
declare const StagingRefused_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
29
|
+
readonly _tag: "StagingRefused";
|
|
30
|
+
} & Readonly<A>;
|
|
31
|
+
/** A request the plan turns away (a bad run id, a name too long, an environment that is not declared, no credential): exit 2, nothing made. */
|
|
32
|
+
export declare class StagingRefused extends StagingRefused_base<{
|
|
33
|
+
readonly message: string;
|
|
34
|
+
}> {
|
|
35
|
+
}
|
|
36
|
+
declare const StagingFailed_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
37
|
+
readonly _tag: "StagingFailed";
|
|
38
|
+
} & Readonly<A>;
|
|
39
|
+
/** The cloud said no, or answered something unreadable: exit 1. What it says never holds a credential. */
|
|
40
|
+
export declare class StagingFailed extends StagingFailed_base<{
|
|
41
|
+
readonly message: string;
|
|
42
|
+
}> {
|
|
43
|
+
}
|
|
44
|
+
/** What a Cloudflare account is asked, by the REST calls the spike proved (`spikes/staging-pass`): the listings the destroy sweep reads, its deletes, and the address. Every method acts on one account. */
|
|
45
|
+
export interface Account {
|
|
46
|
+
readonly workers: Effect.Effect<ReadonlyArray<string>, StagingFailed>;
|
|
47
|
+
readonly databases: Effect.Effect<ReadonlyArray<{
|
|
48
|
+
readonly id: string;
|
|
49
|
+
readonly name: string;
|
|
50
|
+
}>, StagingFailed>;
|
|
51
|
+
/** Deletes a Worker and, with it, its Durable Object namespaces. */
|
|
52
|
+
readonly deleteWorker: (name: string) => Effect.Effect<void, StagingFailed>;
|
|
53
|
+
readonly deleteDatabase: (id: string) => Effect.Effect<void, StagingFailed>;
|
|
54
|
+
/** The account's `workers.dev` subdomain. */
|
|
55
|
+
readonly subdomain: Effect.Effect<string, StagingFailed>;
|
|
56
|
+
}
|
|
57
|
+
export interface Credentials {
|
|
58
|
+
readonly token: string;
|
|
59
|
+
readonly account: string;
|
|
60
|
+
}
|
|
61
|
+
/** The world `up` and `destroy` act through, handed in: the cloud, Alchemy (which makes and removes what the stack declares), the address's first answers, and waiting. */
|
|
62
|
+
export interface Tools {
|
|
63
|
+
readonly account: (credentials: Credentials) => Account;
|
|
64
|
+
/** Runs the Alchemy CLI in `cwd`, where its state lives, with the credentials and `env` in its environment; only its status and its words come back. */
|
|
65
|
+
readonly alchemy: (options: {
|
|
66
|
+
readonly args: ReadonlyArray<string>;
|
|
67
|
+
readonly cwd: string;
|
|
68
|
+
readonly credentials: Credentials;
|
|
69
|
+
readonly env: Readonly<Record<string, string>>;
|
|
70
|
+
}) => Effect.Effect<{
|
|
71
|
+
readonly status: number;
|
|
72
|
+
readonly output: string;
|
|
73
|
+
}, StagingFailed>;
|
|
74
|
+
/** The HTTP status of one GET, or 0 when nothing answered. */
|
|
75
|
+
readonly probe: (url: string) => Effect.Effect<number>;
|
|
76
|
+
/** Waits; the only place a wait is made. */
|
|
77
|
+
readonly pause: (millis: number) => Effect.Effect<void>;
|
|
78
|
+
/** A fresh random secret for the Worker, never printed. */
|
|
79
|
+
readonly secret: () => string;
|
|
80
|
+
/** The bundle of the revision, once (`Build.build`, with no credential). */
|
|
81
|
+
readonly build: (root: string) => Effect.Effect<{
|
|
82
|
+
readonly main: string;
|
|
83
|
+
readonly revision: string;
|
|
84
|
+
readonly sha256: string;
|
|
85
|
+
}, StagingFailed>;
|
|
86
|
+
}
|
|
87
|
+
export interface Options {
|
|
88
|
+
readonly root: string;
|
|
89
|
+
readonly environment: string;
|
|
90
|
+
/** `--run`, as typed; absent when not given. */
|
|
91
|
+
readonly run: string | undefined;
|
|
92
|
+
/** What `main.ts` read from the process. Absent or empty is "not set". */
|
|
93
|
+
readonly credentials: {
|
|
94
|
+
readonly token: string | undefined;
|
|
95
|
+
readonly account: string | undefined;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export interface StagingApi {
|
|
99
|
+
/** `ortho env up <env> --plan`: the plan as one JSON document, byte for byte the same each time; nothing is written and nothing is read from the cloud. */
|
|
100
|
+
readonly plan: (options: Options) => Effect.Effect<Said>;
|
|
101
|
+
/** `ortho env up <env>`: makes what the plan lists. Without credentials it says so and makes no connection. */
|
|
102
|
+
readonly up: (options: Options) => Effect.Effect<Said>;
|
|
103
|
+
/** `ortho env destroy <env>`: deletes every Worker and database whose name carries the run's prefix, matched at a dash, and nothing else. */
|
|
104
|
+
readonly destroy: (options: Options) => Effect.Effect<Said>;
|
|
105
|
+
/** The prefix every name of a run carries: formed here and nowhere else. */
|
|
106
|
+
readonly prefix: (app: string, short: string, run: string) => string;
|
|
107
|
+
/** The `workers.dev` address of a run's deployed Worker. */
|
|
108
|
+
readonly url: (prefix: string, subdomain: string) => string;
|
|
109
|
+
}
|
|
110
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// `ortho env up staging --run <id>` and `ortho env destroy staging --run <id>`: the infra projection of one environment on Cloudflare (M7.03, M7.04).
|
|
2
|
+
// The plan is what both commands print (`--plan`) and what both then do: one function, made from the model, the app's name and the run.
|
|
3
|
+
import { Data } from "effect";
|
|
4
|
+
/** A request the plan turns away (a bad run id, a name too long, an environment that is not declared, no credential): exit 2, nothing made. */
|
|
5
|
+
export class StagingRefused extends Data.TaggedError("StagingRefused") {
|
|
6
|
+
}
|
|
7
|
+
/** The cloud said no, or answered something unreadable: exit 1. What it says never holds a credential. */
|
|
8
|
+
export class StagingFailed extends Data.TaggedError("StagingFailed") {
|
|
9
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Names } from "orthograph/server";
|
|
2
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { Effect } from "effect";
|
|
5
|
+
import { FileSource, TraceTrees } from "@orthograph/prove";
|
|
6
|
+
const ID = /^[0-9a-f]{32}$/;
|
|
7
|
+
const refused = (err, exit = 2) => ({ out: "", err: `${err.trimEnd()}\n`, exit });
|
|
8
|
+
/** The folders a Collector wrote traces to, for one environment or all: prove's, dev's, and each environment's own. */
|
|
9
|
+
const foldersOf = (root, env) => {
|
|
10
|
+
const own = join(root, Names.folder, "environments");
|
|
11
|
+
const environments = existsSync(own) ? readdirSync(own).map((n) => ({ name: n, dir: join(own, n, "telemetry") })) : [];
|
|
12
|
+
const all = [{ name: "local", dir: join(root, Names.folder, "prove-telemetry") }, { name: "local", dir: join(root, Names.folder, "dev-telemetry") }, ...environments];
|
|
13
|
+
return all.filter((f) => (env === undefined || f.name === env) && existsSync(f.dir)).map((f) => f.dir);
|
|
14
|
+
};
|
|
15
|
+
const checked = (id) => !ID.test(id) ? refused(`"${id}" isn't a trace id: it is 32 hexadecimal characters, in the x-trace-id header of every response`) : undefined;
|
|
16
|
+
export const TelemetryCommand = {
|
|
17
|
+
trace: ({ root, id, env }) => Effect.gen(function* () {
|
|
18
|
+
const bad = checked(id);
|
|
19
|
+
if (bad)
|
|
20
|
+
return bad;
|
|
21
|
+
const dirs = foldersOf(root, env);
|
|
22
|
+
const found = dirs.length === 0 ? undefined : yield* FileSource.open(dirs).find(id);
|
|
23
|
+
return found === undefined
|
|
24
|
+
? refused(`no trace ${id} in ${dirs.length === 0 ? `any telemetry folder of this project${env ? ` for ${env}` : ""} (prove writes .ortho/prove-telemetry)` : dirs.map((d) => d.replace(`${root}/`, "")).join(", ")}`, 1)
|
|
25
|
+
: { out: TraceTrees.render(id, found).join("\n") + "\n", err: "", exit: 0 };
|
|
26
|
+
}),
|
|
27
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Effect } from "effect";
|
|
2
|
+
/** What a command prints and how it exits; only `main.ts` writes it out. */
|
|
3
|
+
export interface Said {
|
|
4
|
+
readonly out: string;
|
|
5
|
+
readonly err: string;
|
|
6
|
+
readonly exit: number;
|
|
7
|
+
}
|
|
8
|
+
export interface TelemetryCommandApi {
|
|
9
|
+
/**
|
|
10
|
+
* Print a trace as a tree with its logs, read from the files the Collector wrote (`TraceSource`): a refusal marked
|
|
11
|
+
* `refused`, a defect marked `✘ defect`. `env` narrows the search to `local` (prove) or an environment's own folder.
|
|
12
|
+
* It needs no viewer and works over SSH.
|
|
13
|
+
*/
|
|
14
|
+
readonly trace: (options: {
|
|
15
|
+
readonly root: string;
|
|
16
|
+
readonly id: string;
|
|
17
|
+
readonly env?: string;
|
|
18
|
+
}) => Effect.Effect<Said>;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { Watch } from "@orthograph/prove";
|
|
3
|
+
const UNITS = { s: 1_000, m: 60_000, h: 3_600_000, d: 86_400_000 };
|
|
4
|
+
/** `30s`, `15m`, `1h`, `2d` as milliseconds; nothing for anything else. */
|
|
5
|
+
const duration = (text) => {
|
|
6
|
+
const [, n, unit] = /^(\d+)([smhd])$/.exec(text) ?? [];
|
|
7
|
+
return n === undefined || unit === undefined || Number(n) === 0 ? undefined : Number(n) * UNITS[unit];
|
|
8
|
+
};
|
|
9
|
+
const refused = (err) => ({ out: "", err: `${err.trimEnd()}\n`, exit: 2 });
|
|
10
|
+
export const WatchCommand = {
|
|
11
|
+
run: ({ root, environment, source, since, env }) => {
|
|
12
|
+
const window = duration(since);
|
|
13
|
+
if (window === undefined)
|
|
14
|
+
return Effect.succeed(refused(`--since "${since}" isn't a duration: a whole number and s, m, h or d, like 30m or 2h`));
|
|
15
|
+
return Watch.run({ root, environment, source, since: window, env }).pipe(Effect.map((watched) => ({ out: watched.lines.join("\n") + "\n", err: "", exit: watched.passed ? 0 : 1 })), Effect.catchTag("WatchFailed", (e) => Effect.succeed(refused(`watch couldn't run: ${e.message}`))));
|
|
16
|
+
},
|
|
17
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Effect } from "effect";
|
|
2
|
+
import type { WatchSource } from "@orthograph/prove";
|
|
3
|
+
/** What a command prints and how it exits; only `main.ts` writes it out. */
|
|
4
|
+
export interface Said {
|
|
5
|
+
readonly out: string;
|
|
6
|
+
readonly err: string;
|
|
7
|
+
readonly exit: number;
|
|
8
|
+
}
|
|
9
|
+
export interface WatchCommandApi {
|
|
10
|
+
/**
|
|
11
|
+
* Exit 0 when no eval failed, drift included (drift is a task, written under `.ortho/tasks/`); 1 when an eval failed on
|
|
12
|
+
* live traffic; 2 when it couldn't run (no telemetry recorded, no Axiom sink named, no query token, a `--since` that isn't a
|
|
13
|
+
* duration). `since` is `30s`, `15m`, `1h` or `2d`.
|
|
14
|
+
*/
|
|
15
|
+
readonly run: (options: {
|
|
16
|
+
readonly root: string;
|
|
17
|
+
readonly environment: string;
|
|
18
|
+
readonly source: WatchSource;
|
|
19
|
+
readonly since: string;
|
|
20
|
+
/** The process environment, for Axiom's query credentials; only `main.ts` reads it. */
|
|
21
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
22
|
+
}) => Effect.Effect<Said>;
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orthograph/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0-next.1",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@effect/platform-node": "4.1.4",
|
|
8
|
+
"effect": "4.1.4",
|
|
9
|
+
"yaml": "2.9.0",
|
|
10
|
+
"nx": "24.0.3",
|
|
11
|
+
"wrangler": "4.156.1",
|
|
12
|
+
"alchemy": "2.0.0-beta.87",
|
|
13
|
+
"@alchemy.run/cloudflare": "2.0.0-beta.87",
|
|
14
|
+
"@orthograph/compiler": "0.1.0-next.1",
|
|
15
|
+
"@orthograph/generators": "0.1.0-next.1",
|
|
16
|
+
"@orthograph/preset": "0.1.0-next.1",
|
|
17
|
+
"orthograph": "0.1.0-next.1",
|
|
18
|
+
"@orthograph/prove": "0.1.0-next.1",
|
|
19
|
+
"@orthograph/lint": "0.1.0-next.1",
|
|
20
|
+
"@orthograph/projections": "0.1.0-next.1"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@orthograph/logbook": "0.1.0-next.1",
|
|
24
|
+
"@orthograph/services": "0.0.0"
|
|
25
|
+
},
|
|
26
|
+
"bin": {
|
|
27
|
+
"ortho": "./dist/main.js"
|
|
28
|
+
},
|
|
29
|
+
"imports": {
|
|
30
|
+
"#modules/*.js": "./dist/modules/*.js"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist"
|
|
34
|
+
],
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public",
|
|
37
|
+
"tag": "next"
|
|
38
|
+
}
|
|
6
39
|
}
|