@openupstream/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/README.md +136 -2
- package/dist/credentials.d.ts +21 -0
- package/dist/credentials.js +34 -0
- package/dist/credentials.js.map +1 -0
- package/dist/databases.d.ts +50 -0
- package/dist/databases.js +69 -0
- package/dist/databases.js.map +1 -0
- package/dist/deploy.d.ts +39 -0
- package/dist/deploy.js +142 -0
- package/dist/deploy.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +772 -0
- package/dist/index.js.map +1 -0
- package/dist/jobs.d.ts +71 -0
- package/dist/jobs.js +95 -0
- package/dist/jobs.js.map +1 -0
- package/dist/json.d.ts +2 -0
- package/dist/json.js +10 -0
- package/dist/json.js.map +1 -0
- package/dist/logs.d.ts +24 -0
- package/dist/logs.js +27 -0
- package/dist/logs.js.map +1 -0
- package/dist/oidc.d.ts +47 -0
- package/dist/oidc.js +127 -0
- package/dist/oidc.js.map +1 -0
- package/dist/project.d.ts +25 -0
- package/dist/project.js +77 -0
- package/dist/project.js.map +1 -0
- package/dist/result.d.ts +10 -0
- package/dist/result.js +3 -0
- package/dist/result.js.map +1 -0
- package/dist/services.d.ts +65 -0
- package/dist/services.js +50 -0
- package/dist/services.js.map +1 -0
- package/dist/session.d.ts +9 -0
- package/dist/session.js +82 -0
- package/dist/session.js.map +1 -0
- package/dist/stdin.d.ts +10 -0
- package/dist/stdin.js +47 -0
- package/dist/stdin.js.map +1 -0
- package/dist/version.d.ts +5 -0
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/dist/wait.d.ts +31 -0
- package/dist/wait.js +30 -0
- package/dist/wait.js.map +1 -0
- package/package.json +39 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project.js","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,QAAQ,EAAE,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
readonly ok: true;
|
|
4
|
+
readonly value: T;
|
|
5
|
+
} | {
|
|
6
|
+
readonly ok: false;
|
|
7
|
+
readonly error: E;
|
|
8
|
+
};
|
|
9
|
+
export declare const ok: <T>(value: T) => Result<T, never>;
|
|
10
|
+
export declare const err: <E>(error: E) => Result<never, E>;
|
package/dist/result.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.js","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,EAAE,GAAG,CAAI,KAAQ,EAAoB,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AAE3E,MAAM,CAAC,MAAM,GAAG,GAAG,CAAI,KAAQ,EAAoB,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `oup service deploy`: one command that brings a Service to what its flags
|
|
3
|
+
* say, whether or not it exists yet (ARCHITECTURE.md, decision 94).
|
|
4
|
+
*
|
|
5
|
+
* `planServiceDeploy` is pure: no Service of that name → create it; one
|
|
6
|
+
* whose settings differ from the flags → change it, with the image always
|
|
7
|
+
* in the change, so its tag is resolved again; the same settings → deploy
|
|
8
|
+
* the tag again (POST …/deploy). Every deploy thus runs what the tag points
|
|
9
|
+
* at now. Flags left out keep what the Service has; on creation they take
|
|
10
|
+
* the defaults below.
|
|
11
|
+
*/
|
|
12
|
+
import type { RegistryAuth, ServiceDetails, ServiceInput, ServicePatch, ServiceState, Site } from '@openupstream/sdk';
|
|
13
|
+
/** What a new Service gets for the flags left out. */
|
|
14
|
+
export declare const DEFAULTS: {
|
|
15
|
+
readonly replicas: 1;
|
|
16
|
+
readonly memoryMb: 256;
|
|
17
|
+
readonly cpuMillicores: 250;
|
|
18
|
+
};
|
|
19
|
+
/** What the flags ask for; `undefined`: keep what the Service has (or the default); `port: null`: a worker. */
|
|
20
|
+
export interface DesiredService {
|
|
21
|
+
readonly name: string;
|
|
22
|
+
readonly image: string;
|
|
23
|
+
readonly port?: number | null;
|
|
24
|
+
readonly replicas?: number;
|
|
25
|
+
readonly memoryMb?: number;
|
|
26
|
+
readonly cpuMillicores?: number;
|
|
27
|
+
readonly homeSite?: Site;
|
|
28
|
+
readonly registryAuth?: RegistryAuth;
|
|
29
|
+
}
|
|
30
|
+
export type DeployPlan = {
|
|
31
|
+
readonly kind: 'create';
|
|
32
|
+
readonly input: ServiceInput;
|
|
33
|
+
} | {
|
|
34
|
+
readonly kind: 'update';
|
|
35
|
+
readonly serviceId: string;
|
|
36
|
+
readonly patch: ServicePatch;
|
|
37
|
+
} | {
|
|
38
|
+
readonly kind: 'redeploy';
|
|
39
|
+
readonly serviceId: string;
|
|
40
|
+
} | {
|
|
41
|
+
readonly kind: 'invalid';
|
|
42
|
+
readonly reason: string;
|
|
43
|
+
};
|
|
44
|
+
export declare function planServiceDeploy(existing: ServiceDetails | undefined, desired: DesiredService): DeployPlan;
|
|
45
|
+
/** One line per Service: name, state, replicas, image and the start of its digest. */
|
|
46
|
+
export declare const formatServices: (services: readonly ServiceDetails[]) => string[];
|
|
47
|
+
/** Until the Service is `running`, or the time is up; every state it passes through is reported once. */
|
|
48
|
+
export declare function waitUntilRunning(read: () => Promise<{
|
|
49
|
+
readonly ok: true;
|
|
50
|
+
readonly value: ServiceDetails;
|
|
51
|
+
} | {
|
|
52
|
+
readonly ok: false;
|
|
53
|
+
readonly error: {
|
|
54
|
+
readonly message: string;
|
|
55
|
+
};
|
|
56
|
+
}>, options: {
|
|
57
|
+
readonly timeoutMs: number;
|
|
58
|
+
readonly intervalMs: number;
|
|
59
|
+
readonly report: (state: ServiceState) => void;
|
|
60
|
+
}): Promise<{
|
|
61
|
+
readonly ok: true;
|
|
62
|
+
} | {
|
|
63
|
+
readonly ok: false;
|
|
64
|
+
readonly error: string;
|
|
65
|
+
}>;
|
package/dist/services.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { waitUntil } from './wait.js';
|
|
2
|
+
/** What a new Service gets for the flags left out. */
|
|
3
|
+
export const DEFAULTS = { replicas: 1, memoryMb: 256, cpuMillicores: 250 };
|
|
4
|
+
export function planServiceDeploy(existing, desired) {
|
|
5
|
+
if (existing === undefined) {
|
|
6
|
+
if (desired.port === undefined) {
|
|
7
|
+
return { kind: 'invalid', reason: `a new Service needs --port, the port its container listens on, or --no-port for a worker` };
|
|
8
|
+
}
|
|
9
|
+
return {
|
|
10
|
+
kind: 'create',
|
|
11
|
+
input: {
|
|
12
|
+
name: desired.name,
|
|
13
|
+
image: desired.image,
|
|
14
|
+
...(desired.port === null ? {} : { port: desired.port }),
|
|
15
|
+
replicas: desired.replicas ?? DEFAULTS.replicas,
|
|
16
|
+
memoryMb: desired.memoryMb ?? DEFAULTS.memoryMb,
|
|
17
|
+
cpuMillicores: desired.cpuMillicores ?? DEFAULTS.cpuMillicores,
|
|
18
|
+
...(desired.homeSite === undefined ? {} : { homeSite: desired.homeSite }),
|
|
19
|
+
...(desired.registryAuth === undefined ? {} : { registryAuth: desired.registryAuth }),
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const changed = Object.entries({
|
|
24
|
+
port: desired.port,
|
|
25
|
+
replicas: desired.replicas,
|
|
26
|
+
memoryMb: desired.memoryMb,
|
|
27
|
+
cpuMillicores: desired.cpuMillicores,
|
|
28
|
+
homeSite: desired.homeSite,
|
|
29
|
+
}).filter(([key, value]) => value !== undefined && existing[key] !== value);
|
|
30
|
+
if (changed.length === 0 && desired.image === existing.image && desired.registryAuth === undefined) {
|
|
31
|
+
return { kind: 'redeploy', serviceId: existing.id };
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
kind: 'update',
|
|
35
|
+
serviceId: existing.id,
|
|
36
|
+
patch: {
|
|
37
|
+
...Object.fromEntries(changed),
|
|
38
|
+
image: desired.image,
|
|
39
|
+
...(desired.registryAuth === undefined ? {} : { registryAuth: desired.registryAuth }),
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** One line per Service: name, state, replicas, image and the start of its digest. */
|
|
44
|
+
export const formatServices = (services) => services.map((service) => `${service.name.padEnd(24)} ${service.state.padEnd(10)} ${String(service.replicas).padStart(2)}× ${service.image} (${service.imageDigest.slice(0, 19)})`);
|
|
45
|
+
/** Until the Service is `running`, or the time is up; every state it passes through is reported once. */
|
|
46
|
+
export async function waitUntilRunning(read, options) {
|
|
47
|
+
const running = await waitUntil(read, (service) => service.state === 'running', options);
|
|
48
|
+
return running.ok ? { ok: true } : running;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=services.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"services.js","sourceRoot":"","sources":["../src/services.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,sDAAsD;AACtD,MAAM,CAAC,MAAM,QAAQ,GAAG,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,aAAa,EAAE,GAAG,EAAW,CAAC;AAoBpF,MAAM,UAAU,iBAAiB,CAAC,QAAoC,EAAE,OAAuB;IAC3F,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QACzB,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC7B,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,0FAA0F,EAAE,CAAC;QACnI,CAAC;QACD,OAAO;YACH,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE;gBACH,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OA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,CAAC,EAAE;QACtB,KAAK,EAAE;YACH,GAAG,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC;YAC9B,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,GAAG,CAAC,OAAO,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC;SACxF;KACJ,CAAC;AACN,CAAC;AAED,sFAAsF;AACtF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,QAAmC,EAAY,EAAE,CAC5E,QAAQ,CAAC,GAAG,CACR,CAAC,OAAO,EAAE,EAAE,CACR,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,OAAO,CAAC,KAAK,KAAK,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAChK,CAAC;AAEN,yGAAyG;AACzG,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAClC,IAAiJ,EACjJ,OAAoH;IAEpH,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,KAAK,SAAS,EAAE,OAAO,CAAC,CAAC;IACzF,OAAO,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type OidcDeps } from './oidc.js';
|
|
2
|
+
import { type Result } from './result.js';
|
|
3
|
+
export interface ApiAccess {
|
|
4
|
+
readonly apiUrl: string;
|
|
5
|
+
readonly token: string;
|
|
6
|
+
}
|
|
7
|
+
type Env = Readonly<Record<string, string | undefined>>;
|
|
8
|
+
export declare function apiAccess(path: string, env?: Env, deps?: OidcDeps): Promise<Result<ApiAccess, string>>;
|
|
9
|
+
export {};
|
package/dist/session.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The token for the next API call: `OUP_API_KEY` if set (CI), else the
|
|
3
|
+
* access token from `oup login`, refreshed when it has less than a minute
|
|
4
|
+
* left. The new refresh token is stored before the access token is used:
|
|
5
|
+
* madAuth ends the whole chain when an old one is used again. For the same
|
|
6
|
+
* reason two `oup` processes never refresh at once: the second waits for a
|
|
7
|
+
* lock file and then finds the tokens the first one stored.
|
|
8
|
+
*/
|
|
9
|
+
import { open, rm, stat } from 'node:fs/promises';
|
|
10
|
+
import { DEFAULT_API_URL } from '@openupstream/sdk';
|
|
11
|
+
import { readCredentials, writeCredentials } from './credentials.js';
|
|
12
|
+
import { discover, refresh } from './oidc.js';
|
|
13
|
+
import { err, ok } from './result.js';
|
|
14
|
+
const MARGIN_MS = 60_000;
|
|
15
|
+
/** A lock older than this was left by a process that died; a refresh takes seconds. */
|
|
16
|
+
const STALE_LOCK_MS = 30_000;
|
|
17
|
+
const LOCK_WAIT_MS = 200;
|
|
18
|
+
/** Runs `work` while holding `<path>.lock`, created exclusively; waits for another holder. */
|
|
19
|
+
async function withLock(path, work, now, sleep) {
|
|
20
|
+
const lock = `${path}.lock`;
|
|
21
|
+
const acquire = async () => {
|
|
22
|
+
const handle = await open(lock, 'wx', 0o600).catch((error) => error.code === 'EEXIST' ? undefined : Promise.reject(error));
|
|
23
|
+
if (handle !== undefined) {
|
|
24
|
+
return handle.close();
|
|
25
|
+
}
|
|
26
|
+
const held = await stat(lock).then((info) => info.mtimeMs, () => undefined);
|
|
27
|
+
if (held !== undefined && now() - held > STALE_LOCK_MS) {
|
|
28
|
+
await rm(lock, { force: true });
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
await sleep(LOCK_WAIT_MS);
|
|
32
|
+
}
|
|
33
|
+
return acquire();
|
|
34
|
+
};
|
|
35
|
+
await acquire();
|
|
36
|
+
return work().finally(() => rm(lock, { force: true }));
|
|
37
|
+
}
|
|
38
|
+
export async function apiAccess(path, env = process.env, deps = {}) {
|
|
39
|
+
const apiKey = env['OUP_API_KEY'];
|
|
40
|
+
if (apiKey !== undefined && apiKey !== '') {
|
|
41
|
+
return ok({ apiUrl: env['OUP_API_URL'] || DEFAULT_API_URL, token: apiKey });
|
|
42
|
+
}
|
|
43
|
+
const credentials = await readCredentials(path);
|
|
44
|
+
if (credentials === undefined) {
|
|
45
|
+
return err('not signed in: run oup login (or set OUP_API_KEY)');
|
|
46
|
+
}
|
|
47
|
+
const now = deps.now ?? Date.now;
|
|
48
|
+
const fresh = (stored) => stored.accessTokenExpiresAt - MARGIN_MS > now();
|
|
49
|
+
if (fresh(credentials)) {
|
|
50
|
+
return ok({ apiUrl: credentials.apiUrl, token: credentials.accessToken });
|
|
51
|
+
}
|
|
52
|
+
const sleep = deps.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
53
|
+
return withLock(path, () => renew(path, deps), Date.now, sleep);
|
|
54
|
+
}
|
|
55
|
+
/** Under the lock: another process may have refreshed meanwhile, so read again first. */
|
|
56
|
+
async function renew(path, deps) {
|
|
57
|
+
const credentials = await readCredentials(path);
|
|
58
|
+
if (credentials === undefined) {
|
|
59
|
+
return err('not signed in: run oup login (or set OUP_API_KEY)');
|
|
60
|
+
}
|
|
61
|
+
if (credentials.accessTokenExpiresAt - MARGIN_MS > (deps.now ?? Date.now)()) {
|
|
62
|
+
return ok({ apiUrl: credentials.apiUrl, token: credentials.accessToken });
|
|
63
|
+
}
|
|
64
|
+
const discovery = await discover(credentials.issuer, deps);
|
|
65
|
+
if (!discovery.ok) {
|
|
66
|
+
return err(`cannot reach madAuth: ${discovery.error}`);
|
|
67
|
+
}
|
|
68
|
+
const tokens = await refresh(discovery.value, credentials.clientId, credentials.refreshToken, deps);
|
|
69
|
+
if (!tokens.ok) {
|
|
70
|
+
return err(tokens.error.message);
|
|
71
|
+
}
|
|
72
|
+
const renewed = {
|
|
73
|
+
...credentials,
|
|
74
|
+
refreshToken: tokens.value.refreshToken,
|
|
75
|
+
accessToken: tokens.value.accessToken,
|
|
76
|
+
accessTokenExpiresAt: tokens.value.expiresAt,
|
|
77
|
+
...(tokens.value.idToken === undefined ? {} : { idToken: tokens.value.idToken }),
|
|
78
|
+
};
|
|
79
|
+
await writeCredentials(path, renewed);
|
|
80
|
+
return ok({ apiUrl: renewed.apiUrl, token: renewed.accessToken });
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAoB,eAAe,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACvF,OAAO,EAAiB,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAe,GAAG,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AASnD,MAAM,SAAS,GAAG,MAAM,CAAC;AACzB,uFAAuF;AACvF,MAAM,aAAa,GAAG,MAAM,CAAC;AAC7B,MAAM,YAAY,GAAG,GAAG,CAAC;AAEzB,8FAA8F;AAC9F,KAAK,UAAU,QAAQ,CAAI,IAAY,EAAE,IAAsB,EAAE,GAAiB,EAAE,KAAoC;IACpH,MAAM,IAAI,GAAG,GAAG,IAAI,OAAO,CAAC;IAC5B,MAAM,OAAO,GAAG,KAAK,IAAmB,EAAE;QACtC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,K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ments, which shells keep in
|
|
3
|
+
* their history and the system shows in its process list (decision 94).
|
|
4
|
+
* Piped input is read to its end; at a terminal, the value is asked for
|
|
5
|
+
* without echoing it.
|
|
6
|
+
*/
|
|
7
|
+
/** One trailing line break goes, as `echo` adds it; everything else is the value. */
|
|
8
|
+
export declare const trimLineBreak: (text: string) => string;
|
|
9
|
+
/** The value from stdin; undefined when the person at the terminal gave up. */
|
|
10
|
+
export declare const readSecretValue: (prompt: string) => Promise<string | undefined>;
|
package/dist/stdin.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Secret values come from stdin, never from arguments, which shells keep in
|
|
3
|
+
* their history and the system shows in its process list (decision 94).
|
|
4
|
+
* Piped input is read to its end; at a terminal, the value is asked for
|
|
5
|
+
* without echoing it.
|
|
6
|
+
*/
|
|
7
|
+
/** One trailing line break goes, as `echo` adds it; everything else is the value. */
|
|
8
|
+
export const trimLineBreak = (text) => text.replace(/\r?\n$/, '');
|
|
9
|
+
async function readPiped() {
|
|
10
|
+
const chunks = [];
|
|
11
|
+
for await (const chunk of process.stdin) {
|
|
12
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk)));
|
|
13
|
+
}
|
|
14
|
+
return trimLineBreak(Buffer.concat(chunks).toString('utf8'));
|
|
15
|
+
}
|
|
16
|
+
/** Reads keys in raw mode until Enter: nothing is echoed; Backspace deletes, Ctrl-C and Ctrl-D give up. */
|
|
17
|
+
function promptHidden(prompt) {
|
|
18
|
+
process.stderr.write(prompt);
|
|
19
|
+
process.stdin.setRawMode(true);
|
|
20
|
+
process.stdin.resume();
|
|
21
|
+
process.stdin.setEncoding('utf8');
|
|
22
|
+
return new Promise((resolve) => {
|
|
23
|
+
let value = '';
|
|
24
|
+
const done = (result) => {
|
|
25
|
+
process.stdin.off('data', onData);
|
|
26
|
+
process.stdin.setRawMode(false);
|
|
27
|
+
process.stdin.pause();
|
|
28
|
+
process.stderr.write('\n');
|
|
29
|
+
resolve(result);
|
|
30
|
+
};
|
|
31
|
+
const onData = (keys) => {
|
|
32
|
+
for (const key of keys) {
|
|
33
|
+
if (key === '\r' || key === '\n') {
|
|
34
|
+
return done(value);
|
|
35
|
+
}
|
|
36
|
+
if (key === '\u0003' || key === '\u0004') {
|
|
37
|
+
return done(undefined);
|
|
38
|
+
}
|
|
39
|
+
value = key === '\u007f' || key === '\b' ? value.slice(0, -1) : value + key;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
process.stdin.on('data', onData);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/** The value from stdin; undefined when the person at the terminal gave up. */
|
|
46
|
+
export const readSecretValue = (prompt) => process.stdin.isTTY ? promptHidden(prompt) : readPiped();
|
|
47
|
+
//# sourceMappingURL=stdin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stdin.js","sourceRoot":"","sources":["../src/stdin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,qFAAqF;AACrF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;AAElF,KAAK,UAAU,SAAS;IACpB,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QACtC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC7E,CAAC;IACD,OAAO,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;AACjE,CAAC;AAED,2GAA2G;AAC3G,SAAS,YAAY,CAAC,MAAc;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AC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;AACP,CAAC;AAED,+EAA+E;AAC/E,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAc,EAA+B,EAAE,CAC3E,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC"}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC"}
|
package/dist/wait.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Polling the API until something is done: a Service running, a Job ready, a run finished. */
|
|
2
|
+
type Read<T> = () => Promise<{
|
|
3
|
+
readonly ok: true;
|
|
4
|
+
readonly value: T;
|
|
5
|
+
} | {
|
|
6
|
+
readonly ok: false;
|
|
7
|
+
readonly error: {
|
|
8
|
+
readonly message: string;
|
|
9
|
+
readonly status?: number;
|
|
10
|
+
};
|
|
11
|
+
}>;
|
|
12
|
+
/**
|
|
13
|
+
* Reads until `done` holds, or the time is up; every state it passes
|
|
14
|
+
* through is reported once. A failed read is retried until the time is up,
|
|
15
|
+
* except a 404: what was waited for is gone (deleted, stopped), and no
|
|
16
|
+
* later read brings it back.
|
|
17
|
+
*/
|
|
18
|
+
export declare function waitUntil<T extends {
|
|
19
|
+
readonly state: string;
|
|
20
|
+
}>(read: Read<T>, done: (value: T) => boolean, options: {
|
|
21
|
+
readonly timeoutMs: number;
|
|
22
|
+
readonly intervalMs: number;
|
|
23
|
+
readonly report: (state: T['state']) => void;
|
|
24
|
+
}): Promise<{
|
|
25
|
+
readonly ok: true;
|
|
26
|
+
readonly value: T;
|
|
27
|
+
} | {
|
|
28
|
+
readonly ok: false;
|
|
29
|
+
readonly error: string;
|
|
30
|
+
}>;
|
|
31
|
+
export {};
|
package/dist/wait.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Polling the API until something is done: a Service running, a Job ready, a run finished. */
|
|
2
|
+
const NOT_FOUND = 404;
|
|
3
|
+
/**
|
|
4
|
+
* Reads until `done` holds, or the time is up; every state it passes
|
|
5
|
+
* through is reported once. A failed read is retried until the time is up,
|
|
6
|
+
* except a 404: what was waited for is gone (deleted, stopped), and no
|
|
7
|
+
* later read brings it back.
|
|
8
|
+
*/
|
|
9
|
+
export async function waitUntil(read, done, options) {
|
|
10
|
+
const deadline = Date.now() + options.timeoutMs;
|
|
11
|
+
let reported;
|
|
12
|
+
for (;;) {
|
|
13
|
+
const current = await read();
|
|
14
|
+
if (current.ok && current.value.state !== reported) {
|
|
15
|
+
reported = current.value.state;
|
|
16
|
+
options.report(reported);
|
|
17
|
+
}
|
|
18
|
+
if (current.ok && done(current.value)) {
|
|
19
|
+
return { ok: true, value: current.value };
|
|
20
|
+
}
|
|
21
|
+
if (!current.ok && current.error.status === NOT_FOUND) {
|
|
22
|
+
return { ok: false, error: `gone: ${current.error.message}` };
|
|
23
|
+
}
|
|
24
|
+
if (Date.now() >= deadline) {
|
|
25
|
+
return { ok: false, error: current.ok ? `still ${current.value.state} after ${options.timeoutMs / 1000} s` : current.error.message };
|
|
26
|
+
}
|
|
27
|
+
await new Promise((resolve) => setTimeout(resolve, options.intervalMs));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=wait.js.map
|
package/dist/wait.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wait.js","sourceRoot":"","sources":["../src/wait.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAM/F,MAAM,SAAS,GAAG,GAAG,CAAC;AAEtB;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC3B,IAAa,EACb,IAA2B,EAC3B,OAAkH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json
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openupstream/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "oup, the openupstream command line tool",
|
|
5
|
+
"license": "AGPL-3.0-only",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/openupstream/openupstream.git",
|
|
9
|
+
"directory": "cli"
|
|
10
|
+
},
|
|
11
|
+
"private": false,
|
|
12
|
+
"type": "module",
|
|
13
|
+
"main": "dist/index.js",
|
|
14
|
+
"types": "dist/index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=24"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc -p tsconfig.json",
|
|
26
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
27
|
+
"test": "node --test --import tsx 'src/**/*.test.ts'"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/node": "^24.0.0",
|
|
31
|
+
"tsx": "^4.19.0",
|
|
32
|
+
"typescript": "^5.7.0"
|
|
33
|
+
},
|
|
34
|
+
"bin": {
|
|
35
|
+
"oup": "dist/index.js"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@aws-sdk/client-s3": "^3.1161.0",
|
|
39
|
+
"@openupstream/sdk": "^0.2.0"
|
|
40
|
+
}
|
|
41
|
+
}
|