Export template source from 1a4fa8f940f1ce3bd18662c28f1e9e9ca452e6cd:quixos-instance/packages/project-runtime
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import {
|
||||
derived,
|
||||
objectRef,
|
||||
type RuntimeContext,
|
||||
} from "@quixos/camino-package-runtime";
|
||||
|
||||
export const createProject = (context: RuntimeContext) => context.objectId;
|
||||
|
||||
export const addTask = async (context: RuntimeContext) => {
|
||||
const requestedTitle = typeof context.input.value === "string"
|
||||
? context.input.value.trim()
|
||||
: "";
|
||||
const taskId = await context
|
||||
.constructor("port:project-actions:task-constructor")
|
||||
.construct({ value: requestedTitle || "Untitled task" });
|
||||
await context.edge("port:project-actions:tasks").connect(taskId);
|
||||
return objectRef(taskId);
|
||||
};
|
||||
|
||||
export const taskCount = derived(async (context) =>
|
||||
(await context.edge("port:project-count:tasks").resolve()).length,
|
||||
);
|
||||
|
||||
export const searchDocument = derived(async (context) => {
|
||||
const [name, tasks] = await Promise.all([
|
||||
context.interface("port:project-search:named")
|
||||
.invoke("operation:named:name:get"),
|
||||
context.interface("port:project-search:tasks")
|
||||
.invoke("operation:project-tasks:tasks:resolve"),
|
||||
]);
|
||||
if (typeof name !== "string" || !Array.isArray(tasks)) {
|
||||
throw new Error("Project search dependencies returned invalid values");
|
||||
}
|
||||
const count = tasks.length;
|
||||
return {
|
||||
title: name || "Untitled project",
|
||||
subtitle: `Project · ${count} ${count === 1 ? "task" : "tasks"}`,
|
||||
keywords: ["project", "workspace", count === 0 ? "empty" : "tasks"],
|
||||
};
|
||||
});
|
||||
|
||||
export const stopWatch = () => null;
|
||||
@@ -0,0 +1,22 @@
|
||||
import { servePackageRuntime } from "@quixos/camino-package-runtime";
|
||||
import {
|
||||
addTask,
|
||||
createProject,
|
||||
searchDocument,
|
||||
stopWatch,
|
||||
taskCount,
|
||||
} from "./project.impl.js";
|
||||
|
||||
servePackageRuntime({
|
||||
packageRevisionId: "package:project-runtime@1",
|
||||
exports: {
|
||||
"export:project-runtime:create-project": createProject,
|
||||
"export:project-runtime:add-task": addTask,
|
||||
"export:project-runtime:task-count-get": taskCount,
|
||||
"export:project-runtime:task-count-watch": taskCount,
|
||||
"export:project-runtime:task-count-watch-stop": stopWatch,
|
||||
"export:project-runtime:search-document-get": searchDocument,
|
||||
"export:project-runtime:search-document-watch": searchDocument,
|
||||
"export:project-runtime:search-document-watch-stop": stopWatch,
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user