Bootstrap ProjectRuntime package
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
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.state<string>("port:project-search:name").get(),
|
||||
context.edge("port:project-search:tasks").resolve(),
|
||||
]);
|
||||
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