feat(variables): introduce variable management system
- Added a new module for managing variables, including creation, retrieval, updating, and deletion functionalities. - Implemented a new API endpoint for variable operations, allowing users to interact with variables through HTTP requests. - Enhanced the configuration reference system to support variable references, replacing the previous KV reference system. - Updated existing workflows and scripts to utilize the new variable management features, improving flexibility in configuration handling. - Introduced smoke tests to validate the functionality of the variable system, ensuring reliability and robustness. This update significantly enhances the ability to manage dynamic variables within workflows, improving overall usability and maintainability.
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import * as fsStore from "../../fs-store.js";
|
||||
import {
|
||||
assertVariableName,
|
||||
assertVariableType,
|
||||
deleteVariable,
|
||||
getVariableById,
|
||||
listVariables,
|
||||
upsertVariable,
|
||||
} from "../../variables-store.js";
|
||||
|
||||
/**
|
||||
* @param {import("fastify").FastifyInstance} fastify
|
||||
*/
|
||||
export default async function variablesPlugin(fastify) {
|
||||
fastify.get("/variables", async (req, reply) => {
|
||||
const q = /** @type {{ owner?: string }} */ (req.query ?? {});
|
||||
try {
|
||||
const owner = q.owner ? fsStore.assertOwner(q.owner) : undefined;
|
||||
const variables = await listVariables({ owner });
|
||||
return { variables };
|
||||
} catch (err) {
|
||||
return reply.code(err.statusCode ?? 500).send({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
fastify.put("/variables", async (req, reply) => {
|
||||
const body = /** @type {{ owner?: string, name?: string, type?: unknown, value?: unknown }} */ (
|
||||
req.body ?? {}
|
||||
);
|
||||
try {
|
||||
fsStore.assertOwner(String(body.owner ?? ""));
|
||||
assertVariableName(String(body.name ?? ""));
|
||||
assertVariableType(body.type);
|
||||
const variable = await upsertVariable({
|
||||
owner: String(body.owner),
|
||||
name: String(body.name),
|
||||
type: body.type,
|
||||
value: body.value,
|
||||
});
|
||||
return reply.send({ variable });
|
||||
} catch (err) {
|
||||
return reply.code(err.statusCode ?? 400).send({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
fastify.delete("/variables/:id", async (req, reply) => {
|
||||
const { id } = /** @type {{ id: string }} */ (req.params);
|
||||
const existing = await getVariableById(id);
|
||||
if (!existing) {
|
||||
return reply.code(404).send({ error: "variable not found" });
|
||||
}
|
||||
await deleteVariable(id);
|
||||
return { ok: true };
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user