@tapi-dev/sdk 0.1.40 → 0.1.45
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 +36 -41
- package/dist/cli.d.ts +1 -6
- package/dist/cli.js +164 -245
- package/dist/runner-dev.d.ts +1 -0
- package/dist/runner-dev.js +270 -0
- package/dist/studio-dev.d.ts +1 -0
- package/dist/studio-dev.js +312 -0
- package/dist/workspace.d.ts +0 -2
- package/dist/workspace.js +7 -100
- package/package.json +1 -1
package/dist/workspace.js
CHANGED
|
@@ -1,98 +1,17 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
-
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
|
-
import { dirname, join, resolve } from "node:path";
|
|
4
|
-
export const TAPI_WORKSPACE_DIR = ".tapi";
|
|
5
|
-
export const TAPI_WORKSPACE_CONFIG = "project.json";
|
|
6
|
-
const RETIRED_SERVICE_HELPER_CONFIG_KEY = "gener" + "ated";
|
|
7
1
|
export function findWorkspaceConfigPath(startDir = process.cwd()) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const candidate = join(current, TAPI_WORKSPACE_DIR, TAPI_WORKSPACE_CONFIG);
|
|
11
|
-
if (existsSync(candidate)) {
|
|
12
|
-
return candidate;
|
|
13
|
-
}
|
|
14
|
-
const parent = dirname(current);
|
|
15
|
-
if (parent === current) {
|
|
16
|
-
return undefined;
|
|
17
|
-
}
|
|
18
|
-
current = parent;
|
|
19
|
-
}
|
|
2
|
+
void startDir;
|
|
3
|
+
return undefined;
|
|
20
4
|
}
|
|
21
5
|
export function loadWorkspace(startDir = process.cwd()) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return undefined;
|
|
25
|
-
}
|
|
26
|
-
const config = readWorkspaceConfig(configPath);
|
|
27
|
-
const root = dirname(dirname(configPath));
|
|
28
|
-
return {
|
|
29
|
-
root,
|
|
30
|
-
configPath,
|
|
31
|
-
config,
|
|
32
|
-
projectId: config.projectId,
|
|
33
|
-
projectSlug: config.projectSlug,
|
|
34
|
-
apiBaseUrl: config.apiBaseUrl,
|
|
35
|
-
};
|
|
6
|
+
void startDir;
|
|
7
|
+
return undefined;
|
|
36
8
|
}
|
|
37
9
|
export function readWorkspaceConfig(configPath) {
|
|
38
|
-
|
|
39
|
-
try {
|
|
40
|
-
parsed = JSON.parse(readFileSync(configPath, "utf8"));
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
throw new Error(`Could not read Tapi workspace config at ${configPath}: ${formatError(error)}`);
|
|
44
|
-
}
|
|
45
|
-
if (!isRecord(parsed)) {
|
|
46
|
-
throw new Error(`Tapi workspace config at ${configPath} must be a JSON object.`);
|
|
47
|
-
}
|
|
48
|
-
const version = parsed.version;
|
|
49
|
-
if (version !== 1) {
|
|
50
|
-
throw new Error(`Tapi workspace config at ${configPath} has unsupported version '${String(version)}'.`);
|
|
51
|
-
}
|
|
52
|
-
const projectId = normalizeProjectValue(parsed.projectId, "projectId");
|
|
53
|
-
const projectSlug = optionalProjectValue(parsed.projectSlug, "projectSlug");
|
|
54
|
-
const apiBaseUrl = typeof parsed.apiBaseUrl === "string" && parsed.apiBaseUrl.trim() ? parsed.apiBaseUrl.trim() : undefined;
|
|
55
|
-
const services = isRecord(parsed.services) ? { ...parsed.services } : undefined;
|
|
56
|
-
if (Object.prototype.hasOwnProperty.call(parsed, RETIRED_SERVICE_HELPER_CONFIG_KEY)) {
|
|
57
|
-
throw new Error(`Tapi workspace config at ${configPath} uses retired service helper config. Remove '${RETIRED_SERVICE_HELPER_CONFIG_KEY}' and use 'services' instead.`);
|
|
58
|
-
}
|
|
59
|
-
const config = { ...parsed };
|
|
60
|
-
return {
|
|
61
|
-
...config,
|
|
62
|
-
version: 1,
|
|
63
|
-
projectId,
|
|
64
|
-
...(projectSlug ? { projectSlug } : {}),
|
|
65
|
-
...(apiBaseUrl ? { apiBaseUrl } : {}),
|
|
66
|
-
...(services ? { services } : {}),
|
|
67
|
-
};
|
|
10
|
+
throw new Error(`Tapi workspace configs are retired and are no longer read: ${configPath}`);
|
|
68
11
|
}
|
|
69
12
|
export async function writeWorkspaceConfig(options) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const projectSlug = optionalProjectValue(options.projectSlug, "projectSlug") ?? projectId;
|
|
73
|
-
const configPath = join(root, TAPI_WORKSPACE_DIR, TAPI_WORKSPACE_CONFIG);
|
|
74
|
-
if (!options.force && existsSync(configPath)) {
|
|
75
|
-
throw new Error(`Tapi workspace config already exists at ${configPath}. Use --force to overwrite.`);
|
|
76
|
-
}
|
|
77
|
-
const config = {
|
|
78
|
-
version: 1,
|
|
79
|
-
projectId,
|
|
80
|
-
projectSlug,
|
|
81
|
-
...(options.apiBaseUrl ? { apiBaseUrl: options.apiBaseUrl } : {}),
|
|
82
|
-
services: {
|
|
83
|
-
catalog: ".tapi/services/catalog.json",
|
|
84
|
-
},
|
|
85
|
-
};
|
|
86
|
-
await mkdir(dirname(configPath), { recursive: true });
|
|
87
|
-
await writeFile(configPath, `${JSON.stringify(config, null, 2)}\n`, "utf8");
|
|
88
|
-
return {
|
|
89
|
-
root,
|
|
90
|
-
configPath,
|
|
91
|
-
config,
|
|
92
|
-
projectId,
|
|
93
|
-
projectSlug,
|
|
94
|
-
apiBaseUrl: config.apiBaseUrl,
|
|
95
|
-
};
|
|
13
|
+
void options;
|
|
14
|
+
throw new Error("tapi init/link are retired. Use `tapi tapp create`, `tapi login`, and `tapi studio <tapp>`.");
|
|
96
15
|
}
|
|
97
16
|
export function normalizeProjectValue(value, fieldName = "project") {
|
|
98
17
|
if (typeof value !== "string") {
|
|
@@ -107,15 +26,3 @@ export function normalizeProjectValue(value, fieldName = "project") {
|
|
|
107
26
|
}
|
|
108
27
|
return project;
|
|
109
28
|
}
|
|
110
|
-
function optionalProjectValue(value, fieldName) {
|
|
111
|
-
if (value === undefined || value === null || value === "") {
|
|
112
|
-
return undefined;
|
|
113
|
-
}
|
|
114
|
-
return normalizeProjectValue(value, fieldName);
|
|
115
|
-
}
|
|
116
|
-
function isRecord(value) {
|
|
117
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
118
|
-
}
|
|
119
|
-
function formatError(error) {
|
|
120
|
-
return error instanceof Error ? error.message : String(error);
|
|
121
|
-
}
|