@unieojs/unio-generic-adapter 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 +70 -0
- package/dist/config.d.ts +3 -0
- package/dist/config.js +74 -0
- package/dist/config.js.map +1 -0
- package/dist/emit.d.ts +2 -0
- package/dist/emit.js +164 -0
- package/dist/emit.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +149 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +45 -0
- package/src/config.ts +93 -0
- package/src/emit.ts +236 -0
- package/src/index.ts +25 -0
- package/src/types.ts +182 -0
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# @unieojs/unio-generic-adapter
|
|
2
|
+
|
|
3
|
+
Generic Unio adapter for projects that already know their static output,
|
|
4
|
+
server function bundle, routes, middleware, and optional edge bundle.
|
|
5
|
+
|
|
6
|
+
The adapter emits `.unio/output` directly. It keeps route matches exactly as
|
|
7
|
+
provided, so AI Pages wildcard-host deployments should use root-domain paths
|
|
8
|
+
such as `/`, `/api/:path*`, and `/api/_supabase/:path*` instead of
|
|
9
|
+
`/p/{platform}/{platformId}`.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import {
|
|
13
|
+
buildGenericOutput,
|
|
14
|
+
emitGenericUnioOutput,
|
|
15
|
+
loadConfig,
|
|
16
|
+
} from "@unieojs/unio-generic-adapter";
|
|
17
|
+
|
|
18
|
+
await emitGenericUnioOutput({
|
|
19
|
+
cwd: projectRoot,
|
|
20
|
+
build: {
|
|
21
|
+
staticDir: "dist",
|
|
22
|
+
},
|
|
23
|
+
serverFunctions: [
|
|
24
|
+
{
|
|
25
|
+
name: "server",
|
|
26
|
+
sourceDir: "server",
|
|
27
|
+
entry: "index.js",
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
edgeBundles: [
|
|
31
|
+
{
|
|
32
|
+
name: "app",
|
|
33
|
+
sourceDir: "edge",
|
|
34
|
+
entry: "index.js",
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
routes: [
|
|
38
|
+
{ id: "home", match: "/", type: "assets", entry: "static/index.html" },
|
|
39
|
+
{
|
|
40
|
+
id: "api",
|
|
41
|
+
match: "/api/:path*",
|
|
42
|
+
type: "serverFunction",
|
|
43
|
+
serverFunction: "server",
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
middleware: [
|
|
47
|
+
{
|
|
48
|
+
name: "supabase-edge",
|
|
49
|
+
match: ["/api/_supabase/:path*"],
|
|
50
|
+
runtime: "edge",
|
|
51
|
+
entry: "edge/app/index.js",
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`apc build --generic` uses the package-level CLI boundary:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
const loaded = await loadConfig({ projectDir, configPath, outputDir });
|
|
61
|
+
// loaded.build.command is executed by apc, then:
|
|
62
|
+
await buildGenericOutput({ projectDir, configPath, outputDir });
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
`server-functions/<name>/serverFunction.json` is generated for shared
|
|
66
|
+
`unistackfaasruntime` deployment with `handlerProtocol: "nodejs"`.
|
|
67
|
+
|
|
68
|
+
`apc pack` / `apc publish` materializes `uboaMetadata.tgz` from the root
|
|
69
|
+
metadata manifests (`unio.json`, `routes.json`, `middleware.json`,
|
|
70
|
+
`artifacts.json`, `features.json`, and `observability.json`).
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { BuildGenericOutputOptions, GenericConfig, LoadGenericConfigOptions } from "./types.js";
|
|
2
|
+
export declare function loadConfig(options: LoadGenericConfigOptions): Promise<GenericConfig>;
|
|
3
|
+
export declare function buildGenericOutput(options: BuildGenericOutputOptions): Promise<import("./types.js").GeneratedGenericUboa>;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { promises as fs, rmSync } from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
import ts from "typescript";
|
|
6
|
+
import { emitGenericUnioOutput } from "./emit.js";
|
|
7
|
+
const tempConfigDirs = new Set();
|
|
8
|
+
let tempConfigCleanupRegistered = false;
|
|
9
|
+
export async function loadConfig(options) {
|
|
10
|
+
const configPath = path.resolve(options.configPath);
|
|
11
|
+
const loaded = await loadConfigModule(configPath);
|
|
12
|
+
const config = normalizeConfig(loaded);
|
|
13
|
+
return {
|
|
14
|
+
...config,
|
|
15
|
+
cwd: options.projectDir,
|
|
16
|
+
outputDir: options.outputDir,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export async function buildGenericOutput(options) {
|
|
20
|
+
const config = await loadConfig(options);
|
|
21
|
+
return emitGenericUnioOutput({
|
|
22
|
+
...config,
|
|
23
|
+
cwd: options.projectDir,
|
|
24
|
+
outputDir: options.outputDir,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async function loadConfigModule(configPath) {
|
|
28
|
+
if (configPath.endsWith(".json")) {
|
|
29
|
+
return JSON.parse(await fs.readFile(configPath, "utf8"));
|
|
30
|
+
}
|
|
31
|
+
if (configPath.endsWith(".ts")) {
|
|
32
|
+
return loadTypeScriptConfig(configPath);
|
|
33
|
+
}
|
|
34
|
+
return importFresh(configPath);
|
|
35
|
+
}
|
|
36
|
+
async function loadTypeScriptConfig(configPath) {
|
|
37
|
+
const source = await fs.readFile(configPath, "utf8");
|
|
38
|
+
const transpiled = ts.transpileModule(source, {
|
|
39
|
+
compilerOptions: {
|
|
40
|
+
module: ts.ModuleKind.ES2022,
|
|
41
|
+
target: ts.ScriptTarget.ES2022,
|
|
42
|
+
esModuleInterop: true,
|
|
43
|
+
},
|
|
44
|
+
fileName: configPath,
|
|
45
|
+
});
|
|
46
|
+
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "unio-config-"));
|
|
47
|
+
const tempFile = path.join(tempDir, "config.mjs");
|
|
48
|
+
registerTempConfigCleanup(tempDir);
|
|
49
|
+
await fs.writeFile(tempFile, transpiled.outputText, "utf8");
|
|
50
|
+
return importFresh(tempFile);
|
|
51
|
+
}
|
|
52
|
+
async function importFresh(filePath) {
|
|
53
|
+
const mod = await import(`${pathToFileURL(filePath).href}?t=${Date.now()}`);
|
|
54
|
+
return mod.default ?? mod;
|
|
55
|
+
}
|
|
56
|
+
function registerTempConfigCleanup(tempDir) {
|
|
57
|
+
tempConfigDirs.add(tempDir);
|
|
58
|
+
if (tempConfigCleanupRegistered) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
tempConfigCleanupRegistered = true;
|
|
62
|
+
process.once("exit", () => {
|
|
63
|
+
for (const dir of tempConfigDirs) {
|
|
64
|
+
rmSync(dir, { recursive: true, force: true });
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function normalizeConfig(value) {
|
|
69
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
70
|
+
throw new Error("unio config must export an object");
|
|
71
|
+
}
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAOlD,MAAM,cAAc,GA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C;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,eAAe,CAAC,KAAc;IACrC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAChE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,KAAsB,CAAC;AAChC,CAAC"}
|
package/dist/emit.d.ts
ADDED
package/dist/emit.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { promises as fs } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
const ADAPTER_PACKAGE = "@unieojs/unio-generic-adapter";
|
|
4
|
+
const UBOA_VERSION = "1.0.0";
|
|
5
|
+
const SHARED_FUNCTION_APP_NAME = "unistackfaasruntime";
|
|
6
|
+
function toPosix(p) {
|
|
7
|
+
return p.split(path.sep).join("/");
|
|
8
|
+
}
|
|
9
|
+
function outputRoot(cwd, outputDir) {
|
|
10
|
+
return path.resolve(cwd, outputDir ?? ".unio/output");
|
|
11
|
+
}
|
|
12
|
+
function resolveProjectPath(cwd, value) {
|
|
13
|
+
return path.isAbsolute(value) ? value : path.join(cwd, value);
|
|
14
|
+
}
|
|
15
|
+
function relativeSource(cwd, value) {
|
|
16
|
+
const absolutePath = resolveProjectPath(cwd, value);
|
|
17
|
+
const relativePath = path.relative(cwd, absolutePath);
|
|
18
|
+
if (!relativePath || relativePath.startsWith("..") || path.isAbsolute(relativePath)) {
|
|
19
|
+
return toPosix(value);
|
|
20
|
+
}
|
|
21
|
+
return toPosix(relativePath);
|
|
22
|
+
}
|
|
23
|
+
function framework(config) {
|
|
24
|
+
return {
|
|
25
|
+
name: config?.name ?? "generic",
|
|
26
|
+
version: config?.version ?? "unknown",
|
|
27
|
+
adapter: ADAPTER_PACKAGE,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
async function writeJson(filePath, value) {
|
|
31
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
32
|
+
await fs.writeFile(filePath, `${JSON.stringify(value, null, 2)}\n`, "utf8");
|
|
33
|
+
}
|
|
34
|
+
async function copyDirectory(source, dest) {
|
|
35
|
+
await fs.mkdir(path.dirname(dest), { recursive: true });
|
|
36
|
+
await fs.cp(source, dest, { recursive: true });
|
|
37
|
+
}
|
|
38
|
+
async function emitStaticFiles(root, cwd, staticDir) {
|
|
39
|
+
if (!staticDir)
|
|
40
|
+
return [];
|
|
41
|
+
await copyDirectory(resolveProjectPath(cwd, staticDir), path.join(root, "static"));
|
|
42
|
+
return [{ id: "static", resourceKind: "assets", path: "static" }];
|
|
43
|
+
}
|
|
44
|
+
async function emitServerFunction(root, cwd, config, frameworkConfig) {
|
|
45
|
+
const functionDir = path.join(root, "server-functions", config.name);
|
|
46
|
+
await copyDirectory(resolveProjectPath(cwd, config.sourceDir), functionDir);
|
|
47
|
+
const descriptor = {
|
|
48
|
+
name: config.name,
|
|
49
|
+
runtime: config.runtime ?? "nodejs22",
|
|
50
|
+
entry: toPosix(config.entry),
|
|
51
|
+
handler: config.handler ?? "default",
|
|
52
|
+
handlerProtocol: "nodejs",
|
|
53
|
+
memory: config.memory ?? 512,
|
|
54
|
+
maxDuration: config.maxDuration ?? 10,
|
|
55
|
+
environment: config.environment ?? {},
|
|
56
|
+
bindings: config.bindings ?? {},
|
|
57
|
+
framework: framework(frameworkConfig),
|
|
58
|
+
source: {
|
|
59
|
+
sourceDir: relativeSource(cwd, config.sourceDir),
|
|
60
|
+
entry: toPosix(config.entry),
|
|
61
|
+
},
|
|
62
|
+
deployment: {
|
|
63
|
+
mode: "shared",
|
|
64
|
+
functionAppName: SHARED_FUNCTION_APP_NAME,
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
await writeJson(path.join(functionDir, "serverFunction.json"), descriptor);
|
|
68
|
+
return {
|
|
69
|
+
id: config.name,
|
|
70
|
+
resourceKind: "serverFunction",
|
|
71
|
+
path: `server-functions/${config.name}`,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
async function emitEdgeBundle(root, cwd, config, frameworkConfig) {
|
|
75
|
+
const edgeDir = path.join(root, "edge", config.name);
|
|
76
|
+
await copyDirectory(resolveProjectPath(cwd, config.sourceDir), edgeDir);
|
|
77
|
+
const descriptor = {
|
|
78
|
+
name: config.name,
|
|
79
|
+
runtime: config.runtime ?? "edge",
|
|
80
|
+
entry: toPosix(config.entry),
|
|
81
|
+
handler: config.handler ?? "default",
|
|
82
|
+
handlerProtocol: "fetch",
|
|
83
|
+
bindings: config.bindings ?? {},
|
|
84
|
+
framework: framework(frameworkConfig),
|
|
85
|
+
source: {
|
|
86
|
+
sourceDir: relativeSource(cwd, config.sourceDir),
|
|
87
|
+
entry: toPosix(config.entry),
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
await writeJson(path.join(edgeDir, "edge.json"), descriptor);
|
|
91
|
+
return {
|
|
92
|
+
id: config.name,
|
|
93
|
+
resourceKind: "edge",
|
|
94
|
+
path: `edge/${config.name}`,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function buildCapabilities(hasStatic, routes, middleware, serverFunctions, edgeBundles) {
|
|
98
|
+
const hasServerFunction = serverFunctions.length > 0 ||
|
|
99
|
+
routes.some((route) => route.type === "serverFunction") ||
|
|
100
|
+
middleware.some((item) => item.runtime === "serverless");
|
|
101
|
+
const hasEdge = edgeBundles.length > 0 ||
|
|
102
|
+
routes.some((route) => route.type === "edgeFunction") ||
|
|
103
|
+
middleware.some((item) => item.runtime === "edge");
|
|
104
|
+
return {
|
|
105
|
+
static: hasStatic ? "supported" : "unsupported",
|
|
106
|
+
routes: routes.length > 0 ? "supported" : "unsupported",
|
|
107
|
+
serverlessFunction: hasServerFunction ? "supported" : "unsupported",
|
|
108
|
+
serverFunctionIntrospection: hasServerFunction ? "supported" : "unsupported",
|
|
109
|
+
restRouteIntrospection: hasServerFunction ? "supported" : "unsupported",
|
|
110
|
+
edgeMiddleware: hasEdge ? "supported" : "unsupported",
|
|
111
|
+
imageOptimization: "unsupported",
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
export async function emitGenericUnioOutput(options) {
|
|
115
|
+
const cwd = path.resolve(options.cwd ?? process.cwd());
|
|
116
|
+
const root = outputRoot(cwd, options.outputDir);
|
|
117
|
+
const routes = options.routes ?? [];
|
|
118
|
+
const middleware = options.middleware ?? [];
|
|
119
|
+
const serverFunctions = options.serverFunctions ?? [];
|
|
120
|
+
const edgeBundles = options.edgeBundles ?? [];
|
|
121
|
+
await fs.rm(root, { recursive: true, force: true });
|
|
122
|
+
await fs.mkdir(root, { recursive: true });
|
|
123
|
+
const artifacts = [
|
|
124
|
+
...(await emitStaticFiles(root, cwd, options.build?.staticDir)),
|
|
125
|
+
];
|
|
126
|
+
for (const serverFunction of serverFunctions) {
|
|
127
|
+
artifacts.push(await emitServerFunction(root, cwd, serverFunction, options.framework));
|
|
128
|
+
}
|
|
129
|
+
for (const edgeBundle of edgeBundles) {
|
|
130
|
+
artifacts.push(await emitEdgeBundle(root, cwd, edgeBundle, options.framework));
|
|
131
|
+
}
|
|
132
|
+
const warnings = [];
|
|
133
|
+
const capabilities = buildCapabilities(artifacts.some((artifact) => artifact.resourceKind === "assets"), routes, middleware, serverFunctions, edgeBundles);
|
|
134
|
+
const generated = {
|
|
135
|
+
outputDir: root,
|
|
136
|
+
routes,
|
|
137
|
+
middleware,
|
|
138
|
+
artifacts,
|
|
139
|
+
capabilities,
|
|
140
|
+
warnings,
|
|
141
|
+
};
|
|
142
|
+
await writeJson(path.join(root, "unio.json"), {
|
|
143
|
+
version: UBOA_VERSION,
|
|
144
|
+
framework: framework(options.framework),
|
|
145
|
+
build: {
|
|
146
|
+
contentVersion: options.contentVersion ?? "local",
|
|
147
|
+
buildId: options.buildId ?? "local",
|
|
148
|
+
},
|
|
149
|
+
capabilities,
|
|
150
|
+
warnings,
|
|
151
|
+
});
|
|
152
|
+
await writeJson(path.join(root, "routes.json"), routes);
|
|
153
|
+
await writeJson(path.join(root, "middleware.json"), middleware);
|
|
154
|
+
await writeJson(path.join(root, "artifacts.json"), { artifacts });
|
|
155
|
+
await writeJson(path.join(root, "features.json"), { features: [] });
|
|
156
|
+
await writeJson(path.join(root, "observability.json"), {
|
|
157
|
+
adapter: ADAPTER_PACKAGE,
|
|
158
|
+
framework: options.framework?.name ?? "generic",
|
|
159
|
+
buildId: options.buildId ?? "local",
|
|
160
|
+
});
|
|
161
|
+
await options.afterEmit?.(generated);
|
|
162
|
+
return generated;
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=emit.js.map
|
package/dist/emit.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emit.js","sourceRoot":"","sources":["../src/emit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAgB7B,MAAM,eAAe,GAAG,+BAA+B,CAAC;AACxD,MAAM,YAAY,GAAG,OAAO,CAAC;AAC7B,MAAM,wBAAwB,GAAG,qBAAqB,CAAC;AAEvD,SAAS,OAAO,CAAC,CAAS;IACxB,OAAO,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,UAAU,CAAC,GAAW,EAAE,SAAkB;IACjD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,SAAS,IAAI,cAAc,CAAC,CAAC;AACxD,CAAC;AAED,SAAS,kBAAkB,CAAC,GAAW,EAAE,KAAa;IACpD,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,cAAc,CAAC,GAAW,EAAE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AC,OAAO,IAAI,OAAO;KACpC,CAAC,CAAC;IAEH,MAAM,OAAO,CAAC,SAAS,EAAE,CAAC,SAAS,CAAC,CAAC;IAErC,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { buildGenericOutput, loadConfig } from "./config.js";
|
|
2
|
+
export { emitGenericUnioOutput } from "./emit.js";
|
|
3
|
+
export type { BuildGenericOutputOptions, EmitGenericUnioOutputOptions, GeneratedGenericUboa, GenericArtifact, GenericArtifactResourceKind, GenericAssetsRoute, GenericBuildConfig, GenericConfig, GenericCapabilities, GenericEdgeBundleConfig, GenericEdgeBundleDescriptor, GenericEdgeFunctionRoute, GenericEdgeMiddleware, GenericFrameworkConfig, GenericMiddleware, GenericRoute, GenericServerFunctionConfig, GenericServerFunctionDescriptor, GenericServerFunctionRoute, GenericServerlessMiddleware, LoadGenericConfigOptions, } from "./types.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
export type CapabilityStatus = "supported" | "partial" | "degraded" | "unsupported";
|
|
2
|
+
export interface GenericCapabilities {
|
|
3
|
+
static: CapabilityStatus;
|
|
4
|
+
routes: CapabilityStatus;
|
|
5
|
+
serverlessFunction: CapabilityStatus;
|
|
6
|
+
serverFunctionIntrospection: CapabilityStatus;
|
|
7
|
+
restRouteIntrospection: CapabilityStatus;
|
|
8
|
+
edgeMiddleware: CapabilityStatus;
|
|
9
|
+
imageOptimization: CapabilityStatus;
|
|
10
|
+
}
|
|
11
|
+
export interface GenericBuildConfig {
|
|
12
|
+
command?: string;
|
|
13
|
+
staticDir?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface GenericFrameworkConfig {
|
|
16
|
+
name?: string;
|
|
17
|
+
version?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface GenericServerFunctionConfig {
|
|
20
|
+
name: string;
|
|
21
|
+
sourceDir: string;
|
|
22
|
+
entry: string;
|
|
23
|
+
handler?: string;
|
|
24
|
+
runtime?: string;
|
|
25
|
+
memory?: number;
|
|
26
|
+
maxDuration?: number;
|
|
27
|
+
environment?: Record<string, unknown>;
|
|
28
|
+
bindings?: Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
export interface GenericEdgeBundleConfig {
|
|
31
|
+
name: string;
|
|
32
|
+
sourceDir: string;
|
|
33
|
+
entry: string;
|
|
34
|
+
handler?: string;
|
|
35
|
+
runtime?: string;
|
|
36
|
+
bindings?: Record<string, unknown>;
|
|
37
|
+
}
|
|
38
|
+
interface GenericRouteBase {
|
|
39
|
+
id: string;
|
|
40
|
+
match: string;
|
|
41
|
+
}
|
|
42
|
+
export interface GenericAssetsRoute extends GenericRouteBase {
|
|
43
|
+
type: "assets";
|
|
44
|
+
entry: string;
|
|
45
|
+
serverFunction?: never;
|
|
46
|
+
edgeFunction?: never;
|
|
47
|
+
methods?: never;
|
|
48
|
+
}
|
|
49
|
+
export interface GenericServerFunctionRoute extends GenericRouteBase {
|
|
50
|
+
type: "serverFunction";
|
|
51
|
+
serverFunction: string;
|
|
52
|
+
methods?: string[];
|
|
53
|
+
entry?: never;
|
|
54
|
+
edgeFunction?: never;
|
|
55
|
+
}
|
|
56
|
+
export interface GenericEdgeFunctionRoute extends GenericRouteBase {
|
|
57
|
+
type: "edgeFunction";
|
|
58
|
+
edgeFunction: string;
|
|
59
|
+
entry?: never;
|
|
60
|
+
serverFunction?: never;
|
|
61
|
+
methods?: never;
|
|
62
|
+
}
|
|
63
|
+
export type GenericRoute = GenericAssetsRoute | GenericServerFunctionRoute | GenericEdgeFunctionRoute;
|
|
64
|
+
interface GenericMiddlewareBase {
|
|
65
|
+
name: string;
|
|
66
|
+
match: string[];
|
|
67
|
+
}
|
|
68
|
+
export interface GenericEdgeMiddleware extends GenericMiddlewareBase {
|
|
69
|
+
runtime: "edge";
|
|
70
|
+
entry: string;
|
|
71
|
+
serverFunction?: never;
|
|
72
|
+
}
|
|
73
|
+
export interface GenericServerlessMiddleware extends GenericMiddlewareBase {
|
|
74
|
+
runtime: "serverless";
|
|
75
|
+
serverFunction: string;
|
|
76
|
+
entry?: never;
|
|
77
|
+
}
|
|
78
|
+
export type GenericMiddleware = GenericEdgeMiddleware | GenericServerlessMiddleware;
|
|
79
|
+
export type GenericArtifactResourceKind = "assets" | "serverFunction" | "edge" | "apiSchema";
|
|
80
|
+
export interface GenericArtifact {
|
|
81
|
+
id: string;
|
|
82
|
+
resourceKind: GenericArtifactResourceKind;
|
|
83
|
+
path: string;
|
|
84
|
+
schemaFormat?: "oneapi";
|
|
85
|
+
describes?: {
|
|
86
|
+
resourceKind?: GenericArtifactResourceKind;
|
|
87
|
+
id?: string;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
export interface GenericServerFunctionDescriptor {
|
|
91
|
+
name: string;
|
|
92
|
+
runtime: string;
|
|
93
|
+
entry: string;
|
|
94
|
+
handler: string;
|
|
95
|
+
handlerProtocol: "nodejs";
|
|
96
|
+
memory: number;
|
|
97
|
+
maxDuration: number;
|
|
98
|
+
environment: Record<string, unknown>;
|
|
99
|
+
bindings: Record<string, unknown>;
|
|
100
|
+
framework: Record<string, unknown>;
|
|
101
|
+
source: Record<string, unknown>;
|
|
102
|
+
deployment: {
|
|
103
|
+
mode: "shared";
|
|
104
|
+
functionAppName: "unistackfaasruntime";
|
|
105
|
+
};
|
|
106
|
+
[key: string]: unknown;
|
|
107
|
+
}
|
|
108
|
+
export interface GenericEdgeBundleDescriptor {
|
|
109
|
+
name: string;
|
|
110
|
+
runtime: string;
|
|
111
|
+
entry: string;
|
|
112
|
+
handler: string;
|
|
113
|
+
handlerProtocol: "fetch";
|
|
114
|
+
bindings: Record<string, unknown>;
|
|
115
|
+
framework: Record<string, unknown>;
|
|
116
|
+
source: Record<string, unknown>;
|
|
117
|
+
[key: string]: unknown;
|
|
118
|
+
}
|
|
119
|
+
export interface GeneratedGenericUboa {
|
|
120
|
+
outputDir: string;
|
|
121
|
+
routes: GenericRoute[];
|
|
122
|
+
middleware: GenericMiddleware[];
|
|
123
|
+
artifacts: GenericArtifact[];
|
|
124
|
+
capabilities: GenericCapabilities;
|
|
125
|
+
warnings: string[];
|
|
126
|
+
}
|
|
127
|
+
export interface EmitGenericUnioOutputOptions {
|
|
128
|
+
cwd?: string;
|
|
129
|
+
outputDir?: string;
|
|
130
|
+
build?: GenericBuildConfig;
|
|
131
|
+
framework?: GenericFrameworkConfig;
|
|
132
|
+
buildId?: string;
|
|
133
|
+
contentVersion?: string;
|
|
134
|
+
serverFunctions?: GenericServerFunctionConfig[];
|
|
135
|
+
edgeBundles?: GenericEdgeBundleConfig[];
|
|
136
|
+
routes?: GenericRoute[];
|
|
137
|
+
middleware?: GenericMiddleware[];
|
|
138
|
+
afterEmit?: (result: GeneratedGenericUboa) => void | Promise<void>;
|
|
139
|
+
}
|
|
140
|
+
export interface GenericConfig extends EmitGenericUnioOutputOptions {
|
|
141
|
+
}
|
|
142
|
+
export interface LoadGenericConfigOptions {
|
|
143
|
+
projectDir: string;
|
|
144
|
+
configPath: string;
|
|
145
|
+
outputDir?: string;
|
|
146
|
+
}
|
|
147
|
+
export interface BuildGenericOutputOptions extends LoadGenericConfigOptions {
|
|
148
|
+
}
|
|
149
|
+
export {};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@unieojs/unio-generic-adapter",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Generic adapter that emits Unio Build Output API manifests.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/unieojs/unio-adapters.git",
|
|
18
|
+
"directory": "packages/generic"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public",
|
|
22
|
+
"registry": "https://registry.npmjs.org"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"src"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsc -p tsconfig.json",
|
|
30
|
+
"test": "node --import tsx --test \"test/**/*.test.ts\"",
|
|
31
|
+
"typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.test.json --noEmit"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/node": "^22.15.0",
|
|
35
|
+
"tsx": "^4.20.0",
|
|
36
|
+
"typescript": "^5.8.0"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"typescript": "^5.8.0"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=18.19.0"
|
|
43
|
+
},
|
|
44
|
+
"license": "MIT"
|
|
45
|
+
}
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { promises as fs, rmSync } from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
|
|
6
|
+
import ts from "typescript";
|
|
7
|
+
|
|
8
|
+
import { emitGenericUnioOutput } from "./emit.js";
|
|
9
|
+
import type {
|
|
10
|
+
BuildGenericOutputOptions,
|
|
11
|
+
GenericConfig,
|
|
12
|
+
LoadGenericConfigOptions,
|
|
13
|
+
} from "./types.js";
|
|
14
|
+
|
|
15
|
+
const tempConfigDirs = new Set<string>();
|
|
16
|
+
let tempConfigCleanupRegistered = false;
|
|
17
|
+
|
|
18
|
+
export async function loadConfig(
|
|
19
|
+
options: LoadGenericConfigOptions,
|
|
20
|
+
): Promise<GenericConfig> {
|
|
21
|
+
const configPath = path.resolve(options.configPath);
|
|
22
|
+
const loaded = await loadConfigModule(configPath);
|
|
23
|
+
const config = normalizeConfig(loaded);
|
|
24
|
+
return {
|
|
25
|
+
...config,
|
|
26
|
+
cwd: options.projectDir,
|
|
27
|
+
outputDir: options.outputDir,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function buildGenericOutput(options: BuildGenericOutputOptions) {
|
|
32
|
+
const config = await loadConfig(options);
|
|
33
|
+
return emitGenericUnioOutput({
|
|
34
|
+
...config,
|
|
35
|
+
cwd: options.projectDir,
|
|
36
|
+
outputDir: options.outputDir,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function loadConfigModule(configPath: string): Promise<unknown> {
|
|
41
|
+
if (configPath.endsWith(".json")) {
|
|
42
|
+
return JSON.parse(await fs.readFile(configPath, "utf8"));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (configPath.endsWith(".ts")) {
|
|
46
|
+
return loadTypeScriptConfig(configPath);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return importFresh(configPath);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function loadTypeScriptConfig(configPath: string): Promise<unknown> {
|
|
53
|
+
const source = await fs.readFile(configPath, "utf8");
|
|
54
|
+
const transpiled = ts.transpileModule(source, {
|
|
55
|
+
compilerOptions: {
|
|
56
|
+
module: ts.ModuleKind.ES2022,
|
|
57
|
+
target: ts.ScriptTarget.ES2022,
|
|
58
|
+
esModuleInterop: true,
|
|
59
|
+
},
|
|
60
|
+
fileName: configPath,
|
|
61
|
+
});
|
|
62
|
+
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "unio-config-"));
|
|
63
|
+
const tempFile = path.join(tempDir, "config.mjs");
|
|
64
|
+
registerTempConfigCleanup(tempDir);
|
|
65
|
+
await fs.writeFile(tempFile, transpiled.outputText, "utf8");
|
|
66
|
+
return importFresh(tempFile);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function importFresh(filePath: string): Promise<unknown> {
|
|
70
|
+
const mod = await import(`${pathToFileURL(filePath).href}?t=${Date.now()}`);
|
|
71
|
+
return (mod as { default?: unknown }).default ?? mod;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function registerTempConfigCleanup(tempDir: string): void {
|
|
75
|
+
tempConfigDirs.add(tempDir);
|
|
76
|
+
if (tempConfigCleanupRegistered) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
tempConfigCleanupRegistered = true;
|
|
81
|
+
process.once("exit", () => {
|
|
82
|
+
for (const dir of tempConfigDirs) {
|
|
83
|
+
rmSync(dir, { recursive: true, force: true });
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function normalizeConfig(value: unknown): GenericConfig {
|
|
89
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
90
|
+
throw new Error("unio config must export an object");
|
|
91
|
+
}
|
|
92
|
+
return value as GenericConfig;
|
|
93
|
+
}
|
package/src/emit.ts
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { promises as fs } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
EmitGenericUnioOutputOptions,
|
|
6
|
+
GeneratedGenericUboa,
|
|
7
|
+
GenericArtifact,
|
|
8
|
+
GenericCapabilities,
|
|
9
|
+
GenericEdgeBundleConfig,
|
|
10
|
+
GenericEdgeBundleDescriptor,
|
|
11
|
+
GenericFrameworkConfig,
|
|
12
|
+
GenericMiddleware,
|
|
13
|
+
GenericRoute,
|
|
14
|
+
GenericServerFunctionConfig,
|
|
15
|
+
GenericServerFunctionDescriptor,
|
|
16
|
+
} from "./types.js";
|
|
17
|
+
|
|
18
|
+
const ADAPTER_PACKAGE = "@unieojs/unio-generic-adapter";
|
|
19
|
+
const UBOA_VERSION = "1.0.0";
|
|
20
|
+
const SHARED_FUNCTION_APP_NAME = "unistackfaasruntime";
|
|
21
|
+
|
|
22
|
+
function toPosix(p: string): string {
|
|
23
|
+
return p.split(path.sep).join("/");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function outputRoot(cwd: string, outputDir?: string): string {
|
|
27
|
+
return path.resolve(cwd, outputDir ?? ".unio/output");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function resolveProjectPath(cwd: string, value: string): string {
|
|
31
|
+
return path.isAbsolute(value) ? value : path.join(cwd, value);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function relativeSource(cwd: string, value: string): string {
|
|
35
|
+
const absolutePath = resolveProjectPath(cwd, value);
|
|
36
|
+
const relativePath = path.relative(cwd, absolutePath);
|
|
37
|
+
if (!relativePath || relativePath.startsWith("..") || path.isAbsolute(relativePath)) {
|
|
38
|
+
return toPosix(value);
|
|
39
|
+
}
|
|
40
|
+
return toPosix(relativePath);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function framework(config: GenericFrameworkConfig | undefined): Record<string, unknown> {
|
|
44
|
+
return {
|
|
45
|
+
name: config?.name ?? "generic",
|
|
46
|
+
version: config?.version ?? "unknown",
|
|
47
|
+
adapter: ADAPTER_PACKAGE,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function writeJson(filePath: string, value: unknown): Promise<void> {
|
|
52
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
53
|
+
await fs.writeFile(filePath, `${JSON.stringify(value, null, 2)}\n`, "utf8");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function copyDirectory(source: string, dest: string): Promise<void> {
|
|
57
|
+
await fs.mkdir(path.dirname(dest), { recursive: true });
|
|
58
|
+
await fs.cp(source, dest, { recursive: true });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function emitStaticFiles(
|
|
62
|
+
root: string,
|
|
63
|
+
cwd: string,
|
|
64
|
+
staticDir: string | undefined,
|
|
65
|
+
): Promise<GenericArtifact[]> {
|
|
66
|
+
if (!staticDir) return [];
|
|
67
|
+
|
|
68
|
+
await copyDirectory(resolveProjectPath(cwd, staticDir), path.join(root, "static"));
|
|
69
|
+
return [{ id: "static", resourceKind: "assets", path: "static" }];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function emitServerFunction(
|
|
73
|
+
root: string,
|
|
74
|
+
cwd: string,
|
|
75
|
+
config: GenericServerFunctionConfig,
|
|
76
|
+
frameworkConfig: GenericFrameworkConfig | undefined,
|
|
77
|
+
): Promise<GenericArtifact> {
|
|
78
|
+
const functionDir = path.join(root, "server-functions", config.name);
|
|
79
|
+
await copyDirectory(resolveProjectPath(cwd, config.sourceDir), functionDir);
|
|
80
|
+
|
|
81
|
+
const descriptor: GenericServerFunctionDescriptor = {
|
|
82
|
+
name: config.name,
|
|
83
|
+
runtime: config.runtime ?? "nodejs22",
|
|
84
|
+
entry: toPosix(config.entry),
|
|
85
|
+
handler: config.handler ?? "default",
|
|
86
|
+
handlerProtocol: "nodejs",
|
|
87
|
+
memory: config.memory ?? 512,
|
|
88
|
+
maxDuration: config.maxDuration ?? 10,
|
|
89
|
+
environment: config.environment ?? {},
|
|
90
|
+
bindings: config.bindings ?? {},
|
|
91
|
+
framework: framework(frameworkConfig),
|
|
92
|
+
source: {
|
|
93
|
+
sourceDir: relativeSource(cwd, config.sourceDir),
|
|
94
|
+
entry: toPosix(config.entry),
|
|
95
|
+
},
|
|
96
|
+
deployment: {
|
|
97
|
+
mode: "shared",
|
|
98
|
+
functionAppName: SHARED_FUNCTION_APP_NAME,
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
await writeJson(path.join(functionDir, "serverFunction.json"), descriptor);
|
|
103
|
+
return {
|
|
104
|
+
id: config.name,
|
|
105
|
+
resourceKind: "serverFunction",
|
|
106
|
+
path: `server-functions/${config.name}`,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function emitEdgeBundle(
|
|
111
|
+
root: string,
|
|
112
|
+
cwd: string,
|
|
113
|
+
config: GenericEdgeBundleConfig,
|
|
114
|
+
frameworkConfig: GenericFrameworkConfig | undefined,
|
|
115
|
+
): Promise<GenericArtifact> {
|
|
116
|
+
const edgeDir = path.join(root, "edge", config.name);
|
|
117
|
+
await copyDirectory(resolveProjectPath(cwd, config.sourceDir), edgeDir);
|
|
118
|
+
|
|
119
|
+
const descriptor: GenericEdgeBundleDescriptor = {
|
|
120
|
+
name: config.name,
|
|
121
|
+
runtime: config.runtime ?? "edge",
|
|
122
|
+
entry: toPosix(config.entry),
|
|
123
|
+
handler: config.handler ?? "default",
|
|
124
|
+
handlerProtocol: "fetch",
|
|
125
|
+
bindings: config.bindings ?? {},
|
|
126
|
+
framework: framework(frameworkConfig),
|
|
127
|
+
source: {
|
|
128
|
+
sourceDir: relativeSource(cwd, config.sourceDir),
|
|
129
|
+
entry: toPosix(config.entry),
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
await writeJson(path.join(edgeDir, "edge.json"), descriptor);
|
|
134
|
+
return {
|
|
135
|
+
id: config.name,
|
|
136
|
+
resourceKind: "edge",
|
|
137
|
+
path: `edge/${config.name}`,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function buildCapabilities(
|
|
142
|
+
hasStatic: boolean,
|
|
143
|
+
routes: GenericRoute[],
|
|
144
|
+
middleware: GenericMiddleware[],
|
|
145
|
+
serverFunctions: GenericServerFunctionConfig[],
|
|
146
|
+
edgeBundles: GenericEdgeBundleConfig[],
|
|
147
|
+
): GenericCapabilities {
|
|
148
|
+
const hasServerFunction =
|
|
149
|
+
serverFunctions.length > 0 ||
|
|
150
|
+
routes.some((route) => route.type === "serverFunction") ||
|
|
151
|
+
middleware.some((item) => item.runtime === "serverless");
|
|
152
|
+
const hasEdge =
|
|
153
|
+
edgeBundles.length > 0 ||
|
|
154
|
+
routes.some((route) => route.type === "edgeFunction") ||
|
|
155
|
+
middleware.some((item) => item.runtime === "edge");
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
static: hasStatic ? "supported" : "unsupported",
|
|
159
|
+
routes: routes.length > 0 ? "supported" : "unsupported",
|
|
160
|
+
serverlessFunction: hasServerFunction ? "supported" : "unsupported",
|
|
161
|
+
serverFunctionIntrospection: hasServerFunction ? "supported" : "unsupported",
|
|
162
|
+
restRouteIntrospection: hasServerFunction ? "supported" : "unsupported",
|
|
163
|
+
edgeMiddleware: hasEdge ? "supported" : "unsupported",
|
|
164
|
+
imageOptimization: "unsupported",
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export async function emitGenericUnioOutput(
|
|
169
|
+
options: EmitGenericUnioOutputOptions,
|
|
170
|
+
): Promise<GeneratedGenericUboa> {
|
|
171
|
+
const cwd = path.resolve(options.cwd ?? process.cwd());
|
|
172
|
+
const root = outputRoot(cwd, options.outputDir);
|
|
173
|
+
const routes = options.routes ?? [];
|
|
174
|
+
const middleware = options.middleware ?? [];
|
|
175
|
+
const serverFunctions = options.serverFunctions ?? [];
|
|
176
|
+
const edgeBundles = options.edgeBundles ?? [];
|
|
177
|
+
|
|
178
|
+
await fs.rm(root, { recursive: true, force: true });
|
|
179
|
+
await fs.mkdir(root, { recursive: true });
|
|
180
|
+
|
|
181
|
+
const artifacts: GenericArtifact[] = [
|
|
182
|
+
...(await emitStaticFiles(root, cwd, options.build?.staticDir)),
|
|
183
|
+
];
|
|
184
|
+
|
|
185
|
+
for (const serverFunction of serverFunctions) {
|
|
186
|
+
artifacts.push(
|
|
187
|
+
await emitServerFunction(root, cwd, serverFunction, options.framework),
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
for (const edgeBundle of edgeBundles) {
|
|
192
|
+
artifacts.push(await emitEdgeBundle(root, cwd, edgeBundle, options.framework));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const warnings: string[] = [];
|
|
196
|
+
const capabilities = buildCapabilities(
|
|
197
|
+
artifacts.some((artifact) => artifact.resourceKind === "assets"),
|
|
198
|
+
routes,
|
|
199
|
+
middleware,
|
|
200
|
+
serverFunctions,
|
|
201
|
+
edgeBundles,
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
const generated: GeneratedGenericUboa = {
|
|
205
|
+
outputDir: root,
|
|
206
|
+
routes,
|
|
207
|
+
middleware,
|
|
208
|
+
artifacts,
|
|
209
|
+
capabilities,
|
|
210
|
+
warnings,
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
await writeJson(path.join(root, "unio.json"), {
|
|
214
|
+
version: UBOA_VERSION,
|
|
215
|
+
framework: framework(options.framework),
|
|
216
|
+
build: {
|
|
217
|
+
contentVersion: options.contentVersion ?? "local",
|
|
218
|
+
buildId: options.buildId ?? "local",
|
|
219
|
+
},
|
|
220
|
+
capabilities,
|
|
221
|
+
warnings,
|
|
222
|
+
});
|
|
223
|
+
await writeJson(path.join(root, "routes.json"), routes);
|
|
224
|
+
await writeJson(path.join(root, "middleware.json"), middleware);
|
|
225
|
+
await writeJson(path.join(root, "artifacts.json"), { artifacts });
|
|
226
|
+
await writeJson(path.join(root, "features.json"), { features: [] });
|
|
227
|
+
await writeJson(path.join(root, "observability.json"), {
|
|
228
|
+
adapter: ADAPTER_PACKAGE,
|
|
229
|
+
framework: options.framework?.name ?? "generic",
|
|
230
|
+
buildId: options.buildId ?? "local",
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
await options.afterEmit?.(generated);
|
|
234
|
+
|
|
235
|
+
return generated;
|
|
236
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export { buildGenericOutput, loadConfig } from "./config.js";
|
|
2
|
+
export { emitGenericUnioOutput } from "./emit.js";
|
|
3
|
+
export type {
|
|
4
|
+
BuildGenericOutputOptions,
|
|
5
|
+
EmitGenericUnioOutputOptions,
|
|
6
|
+
GeneratedGenericUboa,
|
|
7
|
+
GenericArtifact,
|
|
8
|
+
GenericArtifactResourceKind,
|
|
9
|
+
GenericAssetsRoute,
|
|
10
|
+
GenericBuildConfig,
|
|
11
|
+
GenericConfig,
|
|
12
|
+
GenericCapabilities,
|
|
13
|
+
GenericEdgeBundleConfig,
|
|
14
|
+
GenericEdgeBundleDescriptor,
|
|
15
|
+
GenericEdgeFunctionRoute,
|
|
16
|
+
GenericEdgeMiddleware,
|
|
17
|
+
GenericFrameworkConfig,
|
|
18
|
+
GenericMiddleware,
|
|
19
|
+
GenericRoute,
|
|
20
|
+
GenericServerFunctionConfig,
|
|
21
|
+
GenericServerFunctionDescriptor,
|
|
22
|
+
GenericServerFunctionRoute,
|
|
23
|
+
GenericServerlessMiddleware,
|
|
24
|
+
LoadGenericConfigOptions,
|
|
25
|
+
} from "./types.js";
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
export type CapabilityStatus =
|
|
2
|
+
| "supported"
|
|
3
|
+
| "partial"
|
|
4
|
+
| "degraded"
|
|
5
|
+
| "unsupported";
|
|
6
|
+
|
|
7
|
+
export interface GenericCapabilities {
|
|
8
|
+
static: CapabilityStatus;
|
|
9
|
+
routes: CapabilityStatus;
|
|
10
|
+
serverlessFunction: CapabilityStatus;
|
|
11
|
+
serverFunctionIntrospection: CapabilityStatus;
|
|
12
|
+
restRouteIntrospection: CapabilityStatus;
|
|
13
|
+
edgeMiddleware: CapabilityStatus;
|
|
14
|
+
imageOptimization: CapabilityStatus;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface GenericBuildConfig {
|
|
18
|
+
command?: string;
|
|
19
|
+
staticDir?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface GenericFrameworkConfig {
|
|
23
|
+
name?: string;
|
|
24
|
+
version?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface GenericServerFunctionConfig {
|
|
28
|
+
name: string;
|
|
29
|
+
sourceDir: string;
|
|
30
|
+
entry: string;
|
|
31
|
+
handler?: string;
|
|
32
|
+
runtime?: string;
|
|
33
|
+
memory?: number;
|
|
34
|
+
maxDuration?: number;
|
|
35
|
+
environment?: Record<string, unknown>;
|
|
36
|
+
bindings?: Record<string, unknown>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface GenericEdgeBundleConfig {
|
|
40
|
+
name: string;
|
|
41
|
+
sourceDir: string;
|
|
42
|
+
entry: string;
|
|
43
|
+
handler?: string;
|
|
44
|
+
runtime?: string;
|
|
45
|
+
bindings?: Record<string, unknown>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface GenericRouteBase {
|
|
49
|
+
id: string;
|
|
50
|
+
match: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface GenericAssetsRoute extends GenericRouteBase {
|
|
54
|
+
type: "assets";
|
|
55
|
+
entry: string;
|
|
56
|
+
serverFunction?: never;
|
|
57
|
+
edgeFunction?: never;
|
|
58
|
+
methods?: never;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface GenericServerFunctionRoute extends GenericRouteBase {
|
|
62
|
+
type: "serverFunction";
|
|
63
|
+
serverFunction: string;
|
|
64
|
+
methods?: string[];
|
|
65
|
+
entry?: never;
|
|
66
|
+
edgeFunction?: never;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface GenericEdgeFunctionRoute extends GenericRouteBase {
|
|
70
|
+
type: "edgeFunction";
|
|
71
|
+
edgeFunction: string;
|
|
72
|
+
entry?: never;
|
|
73
|
+
serverFunction?: never;
|
|
74
|
+
methods?: never;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export type GenericRoute =
|
|
78
|
+
| GenericAssetsRoute
|
|
79
|
+
| GenericServerFunctionRoute
|
|
80
|
+
| GenericEdgeFunctionRoute;
|
|
81
|
+
|
|
82
|
+
interface GenericMiddlewareBase {
|
|
83
|
+
name: string;
|
|
84
|
+
match: string[];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface GenericEdgeMiddleware extends GenericMiddlewareBase {
|
|
88
|
+
runtime: "edge";
|
|
89
|
+
entry: string;
|
|
90
|
+
serverFunction?: never;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface GenericServerlessMiddleware extends GenericMiddlewareBase {
|
|
94
|
+
runtime: "serverless";
|
|
95
|
+
serverFunction: string;
|
|
96
|
+
entry?: never;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export type GenericMiddleware =
|
|
100
|
+
| GenericEdgeMiddleware
|
|
101
|
+
| GenericServerlessMiddleware;
|
|
102
|
+
|
|
103
|
+
export type GenericArtifactResourceKind =
|
|
104
|
+
| "assets"
|
|
105
|
+
| "serverFunction"
|
|
106
|
+
| "edge"
|
|
107
|
+
| "apiSchema";
|
|
108
|
+
|
|
109
|
+
export interface GenericArtifact {
|
|
110
|
+
id: string;
|
|
111
|
+
resourceKind: GenericArtifactResourceKind;
|
|
112
|
+
path: string;
|
|
113
|
+
schemaFormat?: "oneapi";
|
|
114
|
+
describes?: {
|
|
115
|
+
resourceKind?: GenericArtifactResourceKind;
|
|
116
|
+
id?: string;
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface GenericServerFunctionDescriptor {
|
|
121
|
+
name: string;
|
|
122
|
+
runtime: string;
|
|
123
|
+
entry: string;
|
|
124
|
+
handler: string;
|
|
125
|
+
handlerProtocol: "nodejs";
|
|
126
|
+
memory: number;
|
|
127
|
+
maxDuration: number;
|
|
128
|
+
environment: Record<string, unknown>;
|
|
129
|
+
bindings: Record<string, unknown>;
|
|
130
|
+
framework: Record<string, unknown>;
|
|
131
|
+
source: Record<string, unknown>;
|
|
132
|
+
deployment: {
|
|
133
|
+
mode: "shared";
|
|
134
|
+
functionAppName: "unistackfaasruntime";
|
|
135
|
+
};
|
|
136
|
+
[key: string]: unknown;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export interface GenericEdgeBundleDescriptor {
|
|
140
|
+
name: string;
|
|
141
|
+
runtime: string;
|
|
142
|
+
entry: string;
|
|
143
|
+
handler: string;
|
|
144
|
+
handlerProtocol: "fetch";
|
|
145
|
+
bindings: Record<string, unknown>;
|
|
146
|
+
framework: Record<string, unknown>;
|
|
147
|
+
source: Record<string, unknown>;
|
|
148
|
+
[key: string]: unknown;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface GeneratedGenericUboa {
|
|
152
|
+
outputDir: string;
|
|
153
|
+
routes: GenericRoute[];
|
|
154
|
+
middleware: GenericMiddleware[];
|
|
155
|
+
artifacts: GenericArtifact[];
|
|
156
|
+
capabilities: GenericCapabilities;
|
|
157
|
+
warnings: string[];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export interface EmitGenericUnioOutputOptions {
|
|
161
|
+
cwd?: string;
|
|
162
|
+
outputDir?: string;
|
|
163
|
+
build?: GenericBuildConfig;
|
|
164
|
+
framework?: GenericFrameworkConfig;
|
|
165
|
+
buildId?: string;
|
|
166
|
+
contentVersion?: string;
|
|
167
|
+
serverFunctions?: GenericServerFunctionConfig[];
|
|
168
|
+
edgeBundles?: GenericEdgeBundleConfig[];
|
|
169
|
+
routes?: GenericRoute[];
|
|
170
|
+
middleware?: GenericMiddleware[];
|
|
171
|
+
afterEmit?: (result: GeneratedGenericUboa) => void | Promise<void>;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export interface GenericConfig extends EmitGenericUnioOutputOptions {}
|
|
175
|
+
|
|
176
|
+
export interface LoadGenericConfigOptions {
|
|
177
|
+
projectDir: string;
|
|
178
|
+
configPath: string;
|
|
179
|
+
outputDir?: string;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export interface BuildGenericOutputOptions extends LoadGenericConfigOptions {}
|