@teable/next-cli 0.0.0-stage → 1.0.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 +47 -2
- package/dist/checkout.d.ts +22 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +1246 -0
- package/dist/config.d.ts +34 -0
- package/dist/errors.d.ts +11 -0
- package/dist/git.d.ts +64 -0
- package/dist/platform.d.ts +38 -0
- package/dist/programs.d.ts +51 -0
- package/dist/publish.d.ts +63 -0
- package/dist/repository.d.ts +59 -0
- package/dist/runtime.d.ts +51 -0
- package/package.json +23 -4
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface Teable {
|
|
2
|
+
/** The old platform's address, without a trailing slash. */
|
|
3
|
+
endpoint: string;
|
|
4
|
+
/** Where teable-next is served: the runtime's API under APPS_PATH, the builder under /apps. */
|
|
5
|
+
nextEndpoint: string;
|
|
6
|
+
token: string;
|
|
7
|
+
/** Where the token came from, said back when Teable refuses it. */
|
|
8
|
+
tokenFrom: "--token" | "TEABLE_TOKEN" | "teable-next login";
|
|
9
|
+
}
|
|
10
|
+
/** What `teable-next login` saves. */
|
|
11
|
+
interface Login {
|
|
12
|
+
endpoint: string;
|
|
13
|
+
token: string;
|
|
14
|
+
}
|
|
15
|
+
/** The Teable a command talks to: flags first, then the environment, then the saved login. */
|
|
16
|
+
export declare function resolveTeable(flags: {
|
|
17
|
+
token?: string;
|
|
18
|
+
endpoint?: string;
|
|
19
|
+
}): Teable;
|
|
20
|
+
/**
|
|
21
|
+
* The Teable `teable-next login` signs in to: `--endpoint`, TEABLE_ENDPOINT
|
|
22
|
+
* or the cloud, with the token it was given. What was saved before plays no
|
|
23
|
+
* part: a login replaces it.
|
|
24
|
+
*/
|
|
25
|
+
export declare function loginTeable(flags: {
|
|
26
|
+
token: string;
|
|
27
|
+
endpoint?: string;
|
|
28
|
+
}): Teable;
|
|
29
|
+
/**
|
|
30
|
+
* Save a token and the address it is for, replacing what was saved: written
|
|
31
|
+
* to a new file only its owner can read, then moved into place.
|
|
32
|
+
*/
|
|
33
|
+
export declare function saveLogin(login: Login): string;
|
|
34
|
+
export {};
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why a command stopped, with what helps act on it: the checkout, the step
|
|
3
|
+
* that failed, what a program printed. The command line prints it as the
|
|
4
|
+
* command's result, with `success: false`, and exits with 1.
|
|
5
|
+
*/
|
|
6
|
+
export declare class CommandError extends Error {
|
|
7
|
+
readonly details: Record<string, unknown>;
|
|
8
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
9
|
+
}
|
|
10
|
+
/** What an error says, whatever was thrown, with its cause (Node's fetch puts the reason there). */
|
|
11
|
+
export declare function messageOf(error: unknown): string;
|
package/dist/git.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { GitCredentials } from "./platform.js";
|
|
2
|
+
/** The checkout's remote for the app repository, and its branch. */
|
|
3
|
+
export declare const REMOTE = "teable";
|
|
4
|
+
export declare const BRANCH = "main";
|
|
5
|
+
/**
|
|
6
|
+
* Files that hold secrets, as git pathspecs: env files anywhere in the tree,
|
|
7
|
+
* and wrangler's `.dev.vars`. Their values belong outside the repository; a
|
|
8
|
+
* push uploads them to everyone who can clone it.
|
|
9
|
+
*/
|
|
10
|
+
export declare const SECRET_PATHSPECS: string[];
|
|
11
|
+
interface GitRun {
|
|
12
|
+
stdout: string;
|
|
13
|
+
stderr: string;
|
|
14
|
+
code: number;
|
|
15
|
+
}
|
|
16
|
+
/** Run git in `cwd`; a failure throws, saying what git said, unless `allowFailure`. */
|
|
17
|
+
export declare function git(args: string[], options: {
|
|
18
|
+
cwd: string;
|
|
19
|
+
auth?: GitCredentials;
|
|
20
|
+
allowFailure?: boolean;
|
|
21
|
+
}): Promise<GitRun>;
|
|
22
|
+
/** The commit HEAD names; null before the first commit. */
|
|
23
|
+
export declare function head(root: string): Promise<string | null>;
|
|
24
|
+
/** The repository's `main`, asked without a checkout; null while the repository is empty. */
|
|
25
|
+
export declare function remoteMain(auth: GitCredentials, cwd: string): Promise<string | null>;
|
|
26
|
+
/** Point the checkout's `teable` remote at the repository: its URL only, never the credentials. */
|
|
27
|
+
export declare function setRemote(root: string, gitUrl: string): Promise<void>;
|
|
28
|
+
/** Clone the repository's `main` into `root`, its remote named `teable`; the commit checked out. */
|
|
29
|
+
export declare function cloneRepository(root: string, auth: GitCredentials, cwd: string): Promise<string>;
|
|
30
|
+
/** Fetch the repository's `main`: its commit, or null while the repository is empty. */
|
|
31
|
+
export declare function fetchMain(root: string, auth: GitCredentials): Promise<string | null>;
|
|
32
|
+
/** Whether `ancestor` is `of` or comes before it. */
|
|
33
|
+
export declare function isAncestor(root: string, ancestor: string, of: string): Promise<boolean>;
|
|
34
|
+
/**
|
|
35
|
+
* Bring HEAD to the fetched `main`, or say why that is not a fast-forward.
|
|
36
|
+
* A checkout ahead of it, with commits not pushed yet, stays as it is.
|
|
37
|
+
*/
|
|
38
|
+
export declare function fastForward(root: string, remoteHead: string): Promise<"fast-forward" | "up-to-date" | "ahead">;
|
|
39
|
+
/**
|
|
40
|
+
* Stage every change except `excluded` (git pathspecs), which keep their
|
|
41
|
+
* committed state. Not `git add -A -- . ':!<path>'`: since git 2.54 an
|
|
42
|
+
* exclude naming an ignored path makes `git add` exit 1 after staging
|
|
43
|
+
* everything. A plain `git add -A` skips ignored files, and `git reset` puts
|
|
44
|
+
* the excluded paths back (before the first commit too).
|
|
45
|
+
*/
|
|
46
|
+
export declare function stageAllExcept(root: string, excluded: readonly string[]): Promise<void>;
|
|
47
|
+
/** Whether the working tree has changes to commit, secret files aside. */
|
|
48
|
+
export declare function hasChanges(root: string): Promise<boolean>;
|
|
49
|
+
/**
|
|
50
|
+
* Commit the working tree with `message`, secret files left out, or require
|
|
51
|
+
* it to be clean. Whether a commit was made.
|
|
52
|
+
*/
|
|
53
|
+
export declare function commitChanges(root: string, message: string | undefined): Promise<boolean>;
|
|
54
|
+
/**
|
|
55
|
+
* Refuse a push that would publish a secret file: one tracked now, or one a
|
|
56
|
+
* commit about to be pushed touched. A push uploads every outgoing commit
|
|
57
|
+
* with its content, so untracking the file afterwards is not enough.
|
|
58
|
+
* `base` is the repository's `main`; one this history lacks makes every
|
|
59
|
+
* commit outgoing.
|
|
60
|
+
*/
|
|
61
|
+
export declare function assertNoSecrets(root: string, base: string | null): Promise<void>;
|
|
62
|
+
/** The subject of a commit: its message's first line. */
|
|
63
|
+
export declare function subjectOf(root: string, commit: string): Promise<string>;
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The old platform's routes the CLI calls (ADR 0006), with the person's own
|
|
3
|
+
* token as a bearer: a personal access token, an OAuth token, or a sandbox's
|
|
4
|
+
* TEABLE_TOKEN. The teable-next routes refuse project-scoped tokens.
|
|
5
|
+
*
|
|
6
|
+
* - `GET /api/auth/user`: who the token belongs to.
|
|
7
|
+
* - `GET /api/base/:projectId`: the project; `runtime: "next"` when it runs in teable-next.
|
|
8
|
+
* - `POST /api/base/:projectId/teable-next/identity` with `{"delivery":"token"}`:
|
|
9
|
+
* a 15-minute identity token for the runtime, good for every app of the project's space.
|
|
10
|
+
* - `POST /api/base/:projectId/teable-next/git/credentials` with `{"ops":"fetch"|"push"}`:
|
|
11
|
+
* short-lived credentials for the project's repository, `apps/<projectId>.git`
|
|
12
|
+
* in the old platform's git registry, created on first use.
|
|
13
|
+
*/
|
|
14
|
+
import type { Teable } from "./config.js";
|
|
15
|
+
/** Who the token belongs to. The email is there when the token may read it. */
|
|
16
|
+
export declare function currentUser(teable: Teable): Promise<{
|
|
17
|
+
id: string;
|
|
18
|
+
name: string | null;
|
|
19
|
+
email?: string | undefined;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* A project that runs in teable-next, where it is its own app: the app's id
|
|
23
|
+
* is the project's. A classic project's apps are App Builder apps, which are
|
|
24
|
+
* the `teable` CLI's.
|
|
25
|
+
*/
|
|
26
|
+
export declare function teableNextProject(teable: Teable, projectId: string): Promise<{
|
|
27
|
+
id: string;
|
|
28
|
+
name: string;
|
|
29
|
+
}>;
|
|
30
|
+
/** A 15-minute identity token for the runtime, for the space of the project. */
|
|
31
|
+
export declare function identityToken(teable: Teable, projectId: string): Promise<string>;
|
|
32
|
+
/** Credentials for the project's repository; never stored, never printed. */
|
|
33
|
+
export interface GitCredentials {
|
|
34
|
+
gitUrl: string;
|
|
35
|
+
token: string;
|
|
36
|
+
}
|
|
37
|
+
/** Credentials to fetch (clone, pull) or to push the project's repository: its owners and creators only. */
|
|
38
|
+
export declare function gitCredentials(teable: Teable, projectId: string, ops: "fetch" | "push"): Promise<GitCredentials>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
interface ProgramRun {
|
|
2
|
+
/** Null when the program was stopped (timeout) or never started. */
|
|
3
|
+
exitCode: number | null;
|
|
4
|
+
/** The program is not on PATH. */
|
|
5
|
+
missing?: boolean;
|
|
6
|
+
timedOut?: boolean;
|
|
7
|
+
/** The last of what it printed, stdout and stderr together. */
|
|
8
|
+
tail: string;
|
|
9
|
+
}
|
|
10
|
+
/** A program to start, and its arguments. */
|
|
11
|
+
interface Program {
|
|
12
|
+
command: string;
|
|
13
|
+
args: string[];
|
|
14
|
+
}
|
|
15
|
+
/** What starting a program takes on this machine. */
|
|
16
|
+
export interface ProgramHost {
|
|
17
|
+
platform: NodeJS.Platform;
|
|
18
|
+
/** The running Node (or Bun). */
|
|
19
|
+
execPath: string;
|
|
20
|
+
env: NodeJS.ProcessEnv;
|
|
21
|
+
exists: (path: string) => boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The environment of the programs the CLI starts, git among them: the
|
|
25
|
+
* person's token stays with the CLI. A scaffolder fetched from npm, an app's
|
|
26
|
+
* checks and their dependencies, git hooks: none needs it.
|
|
27
|
+
*/
|
|
28
|
+
export declare function childEnv(): NodeJS.ProcessEnv;
|
|
29
|
+
/**
|
|
30
|
+
* How `<bunx|npx> <packageArgs>` starts here, in the order to try: Bun first
|
|
31
|
+
* (the app's own scripts run with it), npm's npx otherwise.
|
|
32
|
+
*/
|
|
33
|
+
export declare function packageRunners(host: ProgramHost, packageArgs: string[]): Program[];
|
|
34
|
+
/** `bun run <script>`. */
|
|
35
|
+
export declare function bunScript(host: ProgramHost, script: string): Program;
|
|
36
|
+
/**
|
|
37
|
+
* Write a blank app into `root` with
|
|
38
|
+
* `<bunx|npx> @teable/create-app@<version> <root> --app-id <appId>`: bunx
|
|
39
|
+
* when Bun is installed, npx otherwise. The command that ran, and how.
|
|
40
|
+
*/
|
|
41
|
+
export declare function runCreateApp(input: {
|
|
42
|
+
root: string;
|
|
43
|
+
appId: string;
|
|
44
|
+
version: string;
|
|
45
|
+
}): Promise<{
|
|
46
|
+
command: string;
|
|
47
|
+
run: ProgramRun;
|
|
48
|
+
}>;
|
|
49
|
+
/** `bun run <script>` in the checkout. */
|
|
50
|
+
export declare function runBunScript(root: string, script: string): Promise<ProgramRun>;
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Teable } from "./config.js";
|
|
2
|
+
/**
|
|
3
|
+
* `publish`: deploy the pushed commit as the app's next version. The
|
|
4
|
+
* checkout must be clean and pushed, so a version is exactly a commit of the
|
|
5
|
+
* app repository; then the app's own checks and build run (`bun run check`,
|
|
6
|
+
* `bun run build`), and the server bundle goes to the runtime with the
|
|
7
|
+
* commit's id and subject, as the person.
|
|
8
|
+
*/
|
|
9
|
+
export declare function publish(teable: Teable, cwd: string): Promise<{
|
|
10
|
+
success: boolean;
|
|
11
|
+
appId: string;
|
|
12
|
+
dir: string;
|
|
13
|
+
version: number;
|
|
14
|
+
commitSha: string;
|
|
15
|
+
commitMessage: string;
|
|
16
|
+
urls: {
|
|
17
|
+
builder: string;
|
|
18
|
+
api: string;
|
|
19
|
+
openapi: string;
|
|
20
|
+
mcp: string;
|
|
21
|
+
};
|
|
22
|
+
deployed?: {
|
|
23
|
+
protocol: number;
|
|
24
|
+
methods: {
|
|
25
|
+
name: string;
|
|
26
|
+
kind: import("@teable/app/protocol").MethodKind;
|
|
27
|
+
access: import("@teable/app/protocol").Access;
|
|
28
|
+
}[];
|
|
29
|
+
tables: string[];
|
|
30
|
+
capabilities?: (keyof import("@teable/app/protocol").Capabilities)[] | undefined;
|
|
31
|
+
} | undefined;
|
|
32
|
+
message: string;
|
|
33
|
+
}>;
|
|
34
|
+
/** `versions`: what the runtime deployed, newest first. */
|
|
35
|
+
export declare function versions(teable: Teable, appId: string, limit: number): Promise<{
|
|
36
|
+
success: boolean;
|
|
37
|
+
appId: string;
|
|
38
|
+
total: number;
|
|
39
|
+
live: number | null;
|
|
40
|
+
versions: {
|
|
41
|
+
version: number;
|
|
42
|
+
deployedBy: string | null;
|
|
43
|
+
commit: string | null;
|
|
44
|
+
message: string | null;
|
|
45
|
+
protocol: number;
|
|
46
|
+
live: boolean;
|
|
47
|
+
createdAt: string;
|
|
48
|
+
}[];
|
|
49
|
+
}>;
|
|
50
|
+
/** `rollback --version <n>`: an earlier version's code, deployed again as the next version. */
|
|
51
|
+
export declare function rollBack(teable: Teable, appId: string, to: number): Promise<{
|
|
52
|
+
success: boolean;
|
|
53
|
+
appId: string;
|
|
54
|
+
version: number;
|
|
55
|
+
rolledBackFrom: number;
|
|
56
|
+
urls: {
|
|
57
|
+
builder: string;
|
|
58
|
+
api: string;
|
|
59
|
+
openapi: string;
|
|
60
|
+
mcp: string;
|
|
61
|
+
};
|
|
62
|
+
message: string;
|
|
63
|
+
}>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { Teable } from "./config.js";
|
|
2
|
+
/** The `@teable/create-app` a new app is made with, unless the command names one. */
|
|
3
|
+
export declare const DEFAULT_CREATE_APP_VERSION = "latest";
|
|
4
|
+
/**
|
|
5
|
+
* `init <dir> --project <projectId>`: write a blank app with
|
|
6
|
+
* `@teable/create-app`, commit it on `main` and push it to the project's new
|
|
7
|
+
* repository. The directory must be absent or empty; a project whose
|
|
8
|
+
* repository has code is cloned, not made again. Stopped after the scaffold
|
|
9
|
+
* (git has no identity, a push failed), the same command goes on from there.
|
|
10
|
+
*/
|
|
11
|
+
export declare function init(teable: Teable, input: {
|
|
12
|
+
dir: string;
|
|
13
|
+
projectId: string;
|
|
14
|
+
createAppVersion: string;
|
|
15
|
+
}): Promise<{
|
|
16
|
+
success: boolean;
|
|
17
|
+
appId: string;
|
|
18
|
+
appName: string;
|
|
19
|
+
dir: string;
|
|
20
|
+
commitSha: string;
|
|
21
|
+
createApp: string;
|
|
22
|
+
nextSteps: string[];
|
|
23
|
+
message: string;
|
|
24
|
+
}>;
|
|
25
|
+
/** `clone <projectId> [dir]`: the project's repository, checked out with its remote named `teable`. */
|
|
26
|
+
export declare function clone(teable: Teable, input: {
|
|
27
|
+
projectId: string;
|
|
28
|
+
dir?: string;
|
|
29
|
+
}): Promise<{
|
|
30
|
+
success: boolean;
|
|
31
|
+
appId: string;
|
|
32
|
+
appName: string;
|
|
33
|
+
dir: string;
|
|
34
|
+
commitSha: string;
|
|
35
|
+
nextSteps: string[];
|
|
36
|
+
message: string;
|
|
37
|
+
}>;
|
|
38
|
+
/** `pull`: fast-forward the checkout to the repository's `main`. */
|
|
39
|
+
export declare function pull(teable: Teable, cwd: string): Promise<{
|
|
40
|
+
success: boolean;
|
|
41
|
+
appId: string;
|
|
42
|
+
dir: string;
|
|
43
|
+
commitSha: string | null;
|
|
44
|
+
git: string;
|
|
45
|
+
message: string;
|
|
46
|
+
}>;
|
|
47
|
+
/**
|
|
48
|
+
* `push [-m <message>]`: commit the working tree (with a message), then push
|
|
49
|
+
* to the repository's `main`, refusing env files and work someone else pushed
|
|
50
|
+
* since the last pull. Nothing is deployed: that is `teable-next publish`.
|
|
51
|
+
*/
|
|
52
|
+
export declare function push(teable: Teable, cwd: string, message: string | undefined): Promise<{
|
|
53
|
+
success: boolean;
|
|
54
|
+
appId: string;
|
|
55
|
+
dir: string;
|
|
56
|
+
commitSha: string;
|
|
57
|
+
pushedCommits: number;
|
|
58
|
+
message: string;
|
|
59
|
+
}>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The runtime's publishing API (ADR 0003), called with the person's identity
|
|
3
|
+
* token, which the old platform issues: the creators and owners of the
|
|
4
|
+
* project's space deploy its app, list its versions and roll it back.
|
|
5
|
+
*/
|
|
6
|
+
import { type VersionInfo } from "@teable/app/protocol";
|
|
7
|
+
import type { Teable } from "./config.js";
|
|
8
|
+
/** Where an app is found: its builder, and its API, OpenAPI and MCP on the runtime. */
|
|
9
|
+
export declare function appUrls(teable: Teable, appId: string): {
|
|
10
|
+
builder: string;
|
|
11
|
+
api: string;
|
|
12
|
+
openapi: string;
|
|
13
|
+
mcp: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Deploy a server bundle as the app's next version, naming the commit it was
|
|
17
|
+
* built from. The runtime answers once the version is live.
|
|
18
|
+
*/
|
|
19
|
+
export declare function deploy(teable: Teable, appId: string, bundle: string, built: {
|
|
20
|
+
commit: string;
|
|
21
|
+
message: string;
|
|
22
|
+
}): Promise<{
|
|
23
|
+
version: number;
|
|
24
|
+
manifest: {
|
|
25
|
+
protocol: number;
|
|
26
|
+
methods: {
|
|
27
|
+
name: string;
|
|
28
|
+
kind: import("@teable/app/protocol").MethodKind;
|
|
29
|
+
access: import("@teable/app/protocol").Access;
|
|
30
|
+
}[];
|
|
31
|
+
tables: string[];
|
|
32
|
+
capabilities?: (keyof import("@teable/app/protocol").Capabilities)[] | undefined;
|
|
33
|
+
} | undefined;
|
|
34
|
+
}>;
|
|
35
|
+
/** Every version of the app, newest first. */
|
|
36
|
+
export declare function listVersions(teable: Teable, appId: string): Promise<VersionInfo[]>;
|
|
37
|
+
/** Deploy an earlier version's code again, as a new version. */
|
|
38
|
+
export declare function rollback(teable: Teable, appId: string, to: number): Promise<{
|
|
39
|
+
version: number;
|
|
40
|
+
from: number;
|
|
41
|
+
manifest: {
|
|
42
|
+
protocol: number;
|
|
43
|
+
methods: {
|
|
44
|
+
name: string;
|
|
45
|
+
kind: import("@teable/app/protocol").MethodKind;
|
|
46
|
+
access: import("@teable/app/protocol").Access;
|
|
47
|
+
}[];
|
|
48
|
+
tables: string[];
|
|
49
|
+
capabilities?: (keyof import("@teable/app/protocol").Capabilities)[] | undefined;
|
|
50
|
+
} | undefined;
|
|
51
|
+
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teable/next-cli",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "teable-next: start, check out, push and publish Teable apps (teable-next) from their repositories",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/teableio/teable-next.git",
|
|
9
|
+
"directory": "packages/cli"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"bin": {
|
|
13
|
+
"teable-next": "./dist/cli.js"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=20"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public",
|
|
23
|
+
"provenance": true
|
|
24
|
+
}
|
|
25
|
+
}
|