@teable/next-cli 1.0.0 → 1.0.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/README.md +1 -1
- package/dist/cli.js +135 -23
- package/dist/publish.d.ts +6 -0
- package/dist/runtime.d.ts +14 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ runs the app's own `bun run check` and `bun run build`, so it needs
|
|
|
22
22
|
| `clone <projectId> [dir]` | Checks out the project's app |
|
|
23
23
|
| `pull` | Fast-forwards the checkout to the app's repository |
|
|
24
24
|
| `push [-m "<what changed>"]` | Commits (with `-m`) and pushes; deploys nothing |
|
|
25
|
-
| `publish` | Runs the app's check and build, then deploys the pushed commit as its next version
|
|
25
|
+
| `publish` | Runs the app's check and build, then deploys the pushed commit, its pages too, as its next version |
|
|
26
26
|
| `versions` | The published versions, newest first: when, by whom, from which commit |
|
|
27
27
|
| `rollback --version <n>` | Deploys version `n`'s code again, as the next version |
|
|
28
28
|
| `whoami` | Who the token belongs to |
|
package/dist/cli.js
CHANGED
|
@@ -526,14 +526,16 @@ function saveLogin(login) {
|
|
|
526
526
|
}
|
|
527
527
|
|
|
528
528
|
// src/publish.ts
|
|
529
|
-
import {
|
|
530
|
-
import {
|
|
529
|
+
import { createHash } from "node:crypto";
|
|
530
|
+
import { existsSync as existsSync3, readdirSync as readdirSync2, readFileSync as readFileSync3, statSync as statSync2 } from "node:fs";
|
|
531
|
+
import { join as join3, relative, sep } from "node:path";
|
|
531
532
|
|
|
532
533
|
// ../app/src/protocol.ts
|
|
533
534
|
var EVERY_CAPABILITY = { files: true, http: true };
|
|
534
535
|
var CAPABILITIES = Object.keys(EVERY_CAPABILITY);
|
|
535
536
|
var APPS_PATH = "/api/v4/apps";
|
|
536
537
|
var DEPLOY_HEADERS = { commit: "X-Teable-Commit", message: "X-Teable-Message" };
|
|
538
|
+
var DEPLOY_PARTS = { server: "server", worker: "worker", pages: "pages" };
|
|
537
539
|
|
|
538
540
|
// src/runtime.ts
|
|
539
541
|
var DEPLOY_TIMEOUT_MS = 10 * 6e4;
|
|
@@ -549,8 +551,18 @@ function appUrls(teable, appId) {
|
|
|
549
551
|
mcp: `${api}/mcp`
|
|
550
552
|
};
|
|
551
553
|
}
|
|
554
|
+
var identities = /* @__PURE__ */ new Map();
|
|
555
|
+
function identityFor(teable, appId) {
|
|
556
|
+
let identity = identities.get(appId);
|
|
557
|
+
if (identity === void 0) {
|
|
558
|
+
identity = identityToken(teable, appId);
|
|
559
|
+
identities.set(appId, identity);
|
|
560
|
+
identity.catch(() => identities.delete(appId));
|
|
561
|
+
}
|
|
562
|
+
return identity;
|
|
563
|
+
}
|
|
552
564
|
async function callRuntime(teable, appId, path, init2) {
|
|
553
|
-
const identity = await
|
|
565
|
+
const identity = await identityFor(teable, appId);
|
|
554
566
|
const url = `${appUrls(teable, appId).api}${path}`;
|
|
555
567
|
let response;
|
|
556
568
|
try {
|
|
@@ -603,18 +615,57 @@ function summary(manifest) {
|
|
|
603
615
|
...manifest.capabilities?.length ? { capabilities: manifest.capabilities } : {}
|
|
604
616
|
};
|
|
605
617
|
}
|
|
606
|
-
async function
|
|
618
|
+
async function missingPages(teable, appId, files) {
|
|
619
|
+
const answer = await callRuntime(teable, appId, "/pages", {
|
|
620
|
+
method: "POST",
|
|
621
|
+
headers: { "Content-Type": "application/json" },
|
|
622
|
+
body: JSON.stringify({ files })
|
|
623
|
+
});
|
|
624
|
+
if (!Array.isArray(answer.missing)) {
|
|
625
|
+
throw new CommandError(
|
|
626
|
+
`The runtime did not say which pages it lacks: ${JSON.stringify(answer).slice(0, 300)}`
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
return answer.missing;
|
|
630
|
+
}
|
|
631
|
+
async function uploadPages(teable, appId, files) {
|
|
632
|
+
const form = new FormData();
|
|
633
|
+
for (const { sha256, bytes } of files) form.append(sha256, new Blob([bytes]), sha256);
|
|
634
|
+
await callRuntime(teable, appId, "/pages/files", {
|
|
635
|
+
method: "POST",
|
|
636
|
+
body: form,
|
|
637
|
+
timeoutMs: DEPLOY_TIMEOUT_MS
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
async function deploy(teable, appId, bundle, built, pages) {
|
|
641
|
+
const commit = {
|
|
642
|
+
[DEPLOY_HEADERS.commit]: built.commit,
|
|
643
|
+
[DEPLOY_HEADERS.message]: encodeURIComponent(built.message)
|
|
644
|
+
};
|
|
645
|
+
let body = bundle;
|
|
646
|
+
if (pages) {
|
|
647
|
+
body = new FormData();
|
|
648
|
+
body.append(DEPLOY_PARTS.server, new Blob([bundle], { type: "text/javascript" }), "server.js");
|
|
649
|
+
if (pages.worker !== null) {
|
|
650
|
+
body.append(
|
|
651
|
+
DEPLOY_PARTS.worker,
|
|
652
|
+
new Blob([pages.worker], { type: "text/javascript" }),
|
|
653
|
+
"worker.js"
|
|
654
|
+
);
|
|
655
|
+
}
|
|
656
|
+
body.append(DEPLOY_PARTS.pages, JSON.stringify({ files: pages.files }));
|
|
657
|
+
}
|
|
607
658
|
const answer = await callRuntime(teable, appId, "/versions", {
|
|
608
659
|
method: "POST",
|
|
609
|
-
headers: {
|
|
610
|
-
|
|
611
|
-
[DEPLOY_HEADERS.commit]: built.commit,
|
|
612
|
-
[DEPLOY_HEADERS.message]: encodeURIComponent(built.message)
|
|
613
|
-
},
|
|
614
|
-
body: bundle,
|
|
660
|
+
headers: pages ? commit : { "Content-Type": "application/javascript", ...commit },
|
|
661
|
+
body,
|
|
615
662
|
timeoutMs: DEPLOY_TIMEOUT_MS
|
|
616
663
|
});
|
|
617
|
-
return {
|
|
664
|
+
return {
|
|
665
|
+
version: versionIn(answer, "version"),
|
|
666
|
+
manifest: summary(answer.manifest),
|
|
667
|
+
pagesUrl: typeof answer.pagesUrl === "string" ? answer.pagesUrl : null
|
|
668
|
+
};
|
|
618
669
|
}
|
|
619
670
|
async function listVersions(teable, appId) {
|
|
620
671
|
const answer = await callRuntime(teable, appId, "/versions", { method: "GET" });
|
|
@@ -641,6 +692,46 @@ async function rollback(teable, appId, to) {
|
|
|
641
692
|
|
|
642
693
|
// src/publish.ts
|
|
643
694
|
var SERVER_BUNDLE = "dist/server.js";
|
|
695
|
+
var WORKER_BUNDLE = "dist/worker.js";
|
|
696
|
+
var PAGES_DIR = "dist/pages";
|
|
697
|
+
var UPLOAD_BATCH_BYTES = 10 * 1024 * 1024;
|
|
698
|
+
var UPLOAD_BATCH_FILES = 100;
|
|
699
|
+
function readPages(root) {
|
|
700
|
+
const dir = join3(root, PAGES_DIR);
|
|
701
|
+
if (!existsSync3(dir)) return null;
|
|
702
|
+
const pages = /* @__PURE__ */ new Map();
|
|
703
|
+
const walk = (at) => {
|
|
704
|
+
for (const entry of readdirSync2(at).sort()) {
|
|
705
|
+
const path = join3(at, entry);
|
|
706
|
+
if (statSync2(path).isDirectory()) walk(path);
|
|
707
|
+
else if (entry !== ".DS_Store") {
|
|
708
|
+
const bytes = new Uint8Array(readFileSync3(path));
|
|
709
|
+
const sha256 = createHash("sha256").update(bytes).digest("hex");
|
|
710
|
+
pages.set(`/${relative(dir, path).split(sep).join("/")}`, { sha256, bytes });
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
walk(dir);
|
|
715
|
+
return pages;
|
|
716
|
+
}
|
|
717
|
+
async function uploadMissing(teable, appId, pages, files) {
|
|
718
|
+
const missing = new Set(await missingPages(teable, appId, files));
|
|
719
|
+
const unique = new Map([...pages.values()].map((file) => [file.sha256, file]));
|
|
720
|
+
const queue = [...missing].flatMap((sha256) => unique.get(sha256) ?? []);
|
|
721
|
+
for (let start = 0; start < queue.length; ) {
|
|
722
|
+
const batch = [];
|
|
723
|
+
let bytes = 0;
|
|
724
|
+
for (const file of queue.slice(start)) {
|
|
725
|
+
if (batch.length > 0 && (bytes + file.bytes.byteLength > UPLOAD_BATCH_BYTES || batch.length >= UPLOAD_BATCH_FILES))
|
|
726
|
+
break;
|
|
727
|
+
batch.push(file);
|
|
728
|
+
bytes += file.bytes.byteLength;
|
|
729
|
+
}
|
|
730
|
+
await uploadPages(teable, appId, batch);
|
|
731
|
+
start += batch.length;
|
|
732
|
+
}
|
|
733
|
+
return queue.length;
|
|
734
|
+
}
|
|
644
735
|
var MESSAGE_MAX_CHARS = 500;
|
|
645
736
|
async function unpushedReason(root, local, remote) {
|
|
646
737
|
if (remote === null) return "Nothing is pushed yet: run `teable-next push`, then publish.";
|
|
@@ -703,9 +794,26 @@ async function publish(teable, cwd) {
|
|
|
703
794
|
}
|
|
704
795
|
const bundle = await checkAndBuild(root, stop);
|
|
705
796
|
const subject = (await subjectOf(root, commit)).slice(0, MESSAGE_MAX_CHARS);
|
|
797
|
+
const pages = readPages(root);
|
|
798
|
+
const worker = existsSync3(join3(root, WORKER_BUNDLE)) ? readFileSync3(join3(root, WORKER_BUNDLE), "utf8") : null;
|
|
706
799
|
let deployed;
|
|
800
|
+
let uploaded = 0;
|
|
707
801
|
try {
|
|
708
|
-
|
|
802
|
+
if (pages === null) {
|
|
803
|
+
deployed = await deploy(teable, appId, bundle, { commit, message: subject });
|
|
804
|
+
} else {
|
|
805
|
+
const files = Object.fromEntries(
|
|
806
|
+
[...pages].map(([path, { sha256, bytes }]) => [path, { sha256, size: bytes.byteLength }])
|
|
807
|
+
);
|
|
808
|
+
uploaded = await uploadMissing(teable, appId, pages, files);
|
|
809
|
+
deployed = await deploy(
|
|
810
|
+
teable,
|
|
811
|
+
appId,
|
|
812
|
+
bundle,
|
|
813
|
+
{ commit, message: subject },
|
|
814
|
+
{ worker, files }
|
|
815
|
+
);
|
|
816
|
+
}
|
|
709
817
|
} catch (error) {
|
|
710
818
|
if (error instanceof CommandError) {
|
|
711
819
|
throw new CommandError(
|
|
@@ -715,6 +823,7 @@ async function publish(teable, cwd) {
|
|
|
715
823
|
}
|
|
716
824
|
throw error;
|
|
717
825
|
}
|
|
826
|
+
const where = deployed.pagesUrl ? ` Its pages are at ${deployed.pagesUrl}.` : "";
|
|
718
827
|
return {
|
|
719
828
|
success: true,
|
|
720
829
|
appId,
|
|
@@ -722,9 +831,10 @@ async function publish(teable, cwd) {
|
|
|
722
831
|
version: deployed.version,
|
|
723
832
|
commitSha: commit,
|
|
724
833
|
commitMessage: subject,
|
|
725
|
-
urls: appUrls(teable, appId),
|
|
834
|
+
urls: { ...appUrls(teable, appId), pages: deployed.pagesUrl },
|
|
835
|
+
...pages && { pages: { files: pages.size, uploaded, worker: worker !== null } },
|
|
726
836
|
...deployed.manifest && { deployed: deployed.manifest },
|
|
727
|
-
message: `Version ${deployed.version} of ${appId} is live, built from ${commit.slice(0, 8)} ("${subject}")
|
|
837
|
+
message: `Version ${deployed.version} of ${appId} is live, built from ${commit.slice(0, 8)} ("${subject}").${where}`
|
|
728
838
|
};
|
|
729
839
|
}
|
|
730
840
|
async function versions(teable, appId, limit) {
|
|
@@ -753,11 +863,11 @@ async function rollBack(teable, appId, to) {
|
|
|
753
863
|
}
|
|
754
864
|
|
|
755
865
|
// src/repository.ts
|
|
756
|
-
import { existsSync as existsSync4, mkdirSync as mkdirSync3, statSync as
|
|
757
|
-
import { dirname as dirname4, join as join4, relative, resolve as resolve2 } from "node:path";
|
|
866
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync3, statSync as statSync3 } from "node:fs";
|
|
867
|
+
import { dirname as dirname4, join as join4, relative as relative2, resolve as resolve2 } from "node:path";
|
|
758
868
|
var DEFAULT_CREATE_APP_VERSION = "latest";
|
|
759
869
|
function shellPath(path) {
|
|
760
|
-
const where =
|
|
870
|
+
const where = relative2(process.cwd(), path) || ".";
|
|
761
871
|
return /^[\w@%+=:,./-]+$/.test(where) ? where : `'${where.replaceAll("'", "'\\''")}'`;
|
|
762
872
|
}
|
|
763
873
|
function workflow(root, pull2) {
|
|
@@ -822,7 +932,7 @@ async function init(teable, input) {
|
|
|
822
932
|
const appId = project.id;
|
|
823
933
|
const root = resolve2(input.dir);
|
|
824
934
|
const version2 = input.createAppVersion;
|
|
825
|
-
if (existsSync4(root) && !
|
|
935
|
+
if (existsSync4(root) && !statSync3(root).isDirectory()) {
|
|
826
936
|
throw new CommandError(`${root} is a file: name an empty or new directory.`);
|
|
827
937
|
}
|
|
828
938
|
const earlier = appIdIn(root);
|
|
@@ -1068,11 +1178,13 @@ pushed since your last pull. Nothing is deployed: \`teable-next publish\` deploy
|
|
|
1068
1178
|
details: `In a checkout: deploys the pushed commit as the app's next version, as you.
|
|
1069
1179
|
1. The checkout must be clean, its HEAD pushed to the app repository's main (\`teable-next push\`).
|
|
1070
1180
|
2. Runs \`bun run check\`, then \`bun run build\`; their output goes to stderr.
|
|
1071
|
-
3. Uploads
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1181
|
+
3. Uploads the pages' files the runtime lacks (dist/pages), then deploys dist/server.js with the
|
|
1182
|
+
pages and the app's own Worker (dist/worker.js, if any), with the commit's id and subject. The
|
|
1183
|
+
runtime runs the version's migrations on a copy of the live data, then on the live data, and
|
|
1184
|
+
makes it live, with its pages, only if both work.
|
|
1185
|
+
Prints the version and the app's URLs (its pages at its own host, builder, API, OpenAPI, MCP).
|
|
1186
|
+
Publish each change once it is checked: no approval is needed. Publishing takes the creator or
|
|
1187
|
+
owner role in the project's space.
|
|
1076
1188
|
TEABLE_NEXT_ENDPOINT points it at another runtime (a local one); by default the runtime is under
|
|
1077
1189
|
Teable's own address.`,
|
|
1078
1190
|
options: {},
|
package/dist/publish.d.ts
CHANGED
|
@@ -18,7 +18,13 @@ export declare function publish(teable: Teable, cwd: string): Promise<{
|
|
|
18
18
|
api: string;
|
|
19
19
|
openapi: string;
|
|
20
20
|
mcp: string;
|
|
21
|
+
pages: string | null;
|
|
21
22
|
};
|
|
23
|
+
pages?: {
|
|
24
|
+
files: number;
|
|
25
|
+
uploaded: number;
|
|
26
|
+
worker: boolean;
|
|
27
|
+
} | undefined;
|
|
22
28
|
deployed?: {
|
|
23
29
|
protocol: number;
|
|
24
30
|
methods: {
|
package/dist/runtime.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* token, which the old platform issues: the creators and owners of the
|
|
4
4
|
* project's space deploy its app, list its versions and roll it back.
|
|
5
5
|
*/
|
|
6
|
-
import { type VersionInfo } from "@teable/app/protocol";
|
|
6
|
+
import { type PageFiles, type VersionInfo } from "@teable/app/protocol";
|
|
7
7
|
import type { Teable } from "./config.js";
|
|
8
8
|
/** Where an app is found: its builder, and its API, OpenAPI and MCP on the runtime. */
|
|
9
9
|
export declare function appUrls(teable: Teable, appId: string): {
|
|
@@ -12,13 +12,24 @@ export declare function appUrls(teable: Teable, appId: string): {
|
|
|
12
12
|
openapi: string;
|
|
13
13
|
mcp: string;
|
|
14
14
|
};
|
|
15
|
+
/** The pages' files the runtime lacks, by SHA-256 (ADR 0014). */
|
|
16
|
+
export declare function missingPages(teable: Teable, appId: string, files: PageFiles): Promise<string[]>;
|
|
17
|
+
/** Upload some of the pages' files, each named by its SHA-256. */
|
|
18
|
+
export declare function uploadPages(teable: Teable, appId: string, files: {
|
|
19
|
+
sha256: string;
|
|
20
|
+
bytes: Uint8Array<ArrayBuffer>;
|
|
21
|
+
}[]): Promise<void>;
|
|
15
22
|
/**
|
|
16
23
|
* Deploy a server bundle as the app's next version, naming the commit it was
|
|
17
|
-
* built from
|
|
24
|
+
* built from, with its pages (the app's Worker, if it has one, and the files
|
|
25
|
+
* already uploaded) or without. The runtime answers once the version is live.
|
|
18
26
|
*/
|
|
19
27
|
export declare function deploy(teable: Teable, appId: string, bundle: string, built: {
|
|
20
28
|
commit: string;
|
|
21
29
|
message: string;
|
|
30
|
+
}, pages?: {
|
|
31
|
+
worker: string | null;
|
|
32
|
+
files: PageFiles;
|
|
22
33
|
}): Promise<{
|
|
23
34
|
version: number;
|
|
24
35
|
manifest: {
|
|
@@ -31,6 +42,7 @@ export declare function deploy(teable: Teable, appId: string, bundle: string, bu
|
|
|
31
42
|
tables: string[];
|
|
32
43
|
capabilities?: (keyof import("@teable/app/protocol").Capabilities)[] | undefined;
|
|
33
44
|
} | undefined;
|
|
45
|
+
pagesUrl: string | null;
|
|
34
46
|
}>;
|
|
35
47
|
/** Every version of the app, newest first. */
|
|
36
48
|
export declare function listVersions(teable: Teable, appId: string): Promise<VersionInfo[]>;
|