@baqhub/cli
Version:
The official command line interface for the BAQ federated app platform.
74 lines (73 loc) • 1.84 kB
JavaScript
import { IO } from "@baqhub/sdk";
//
// Model.
//
const RProjectRecordTypeScope = IO.union([
IO.literal("read"),
IO.literal("write"),
IO.literal("subscribe"),
]);
const RLocalProjectRecordType = IO.object({
path: IO.string,
recordId: IO.string,
versionHash: IO.optional(IO.string),
contentHash: IO.optional(IO.string),
});
const RRemoteProjectRecordType = IO.object({
entity: IO.string,
recordId: IO.string,
versionHash: IO.string,
});
const RProjectRecordType = IO.intersection([
IO.union([RLocalProjectRecordType, RRemoteProjectRecordType]),
IO.partialObject({
scopes: IO.optional(IO.readonlyArray(RProjectRecordTypeScope)),
}),
]);
export var ProjectType;
(function (ProjectType) {
ProjectType["JS"] = "js";
ProjectType["JS_REACT"] = "js-react";
ProjectType["TS"] = "ts";
ProjectType["TS_REACT"] = "ts-react";
})(ProjectType || (ProjectType = {}));
const RProjectRaw = IO.intersection([
IO.object({
name: IO.string,
type: IO.enumeration(ProjectType),
path: IO.string,
recordTypes: IO.record(IO.string, RProjectRecordType),
}),
IO.partialObject({
description: IO.string,
websiteUrl: IO.string,
}),
]);
export const RProject = IO.clean(RProjectRaw);
//
// I/O.
//
export function buildProject(name, type, path) {
return {
name,
type,
path,
recordTypes: {},
};
}
export function addTypeToProject(project, name, projectRecordType) {
return {
...project,
recordTypes: {
...project.recordTypes,
[name]: projectRecordType,
},
};
}
export function removeTypeFromProject(project, name) {
const { [name]: _, ...recordTypes } = project.recordTypes;
return {
...project,
recordTypes,
};
}