2023-10-03 12:16:33 +00:00
|
|
|
import { ObjectValue } from "$sb/types.ts";
|
|
|
|
import { indexObjects } from "./api.ts";
|
|
|
|
import { AttributeObject } from "./attributes.ts";
|
|
|
|
import { TagObject } from "./tags.ts";
|
|
|
|
|
|
|
|
export const builtinPseudoPage = ":builtin:";
|
|
|
|
|
2023-12-21 17:37:50 +00:00
|
|
|
// Types marked with a ! are read-only, they cannot be set by the user
|
2023-10-03 12:16:33 +00:00
|
|
|
export const builtins: Record<string, Record<string, string>> = {
|
|
|
|
page: {
|
2023-12-21 17:37:50 +00:00
|
|
|
ref: "!string",
|
|
|
|
name: "!string",
|
|
|
|
displayName: "string",
|
2024-01-04 19:08:12 +00:00
|
|
|
aliases: "string[]",
|
2023-12-21 17:37:50 +00:00
|
|
|
created: "!date",
|
|
|
|
lastModified: "!date",
|
|
|
|
perm: "!rw|ro",
|
|
|
|
contentType: "!string",
|
|
|
|
size: "!number",
|
2024-01-04 19:08:12 +00:00
|
|
|
tags: "string[]",
|
2023-10-03 12:16:33 +00:00
|
|
|
},
|
|
|
|
task: {
|
2023-12-21 17:37:50 +00:00
|
|
|
ref: "!string",
|
|
|
|
name: "!string",
|
|
|
|
done: "!boolean",
|
|
|
|
page: "!string",
|
|
|
|
state: "!string",
|
2023-10-03 12:16:33 +00:00
|
|
|
deadline: "string",
|
2023-12-21 17:37:50 +00:00
|
|
|
pos: "!number",
|
2024-01-04 19:08:12 +00:00
|
|
|
tags: "string[]",
|
2023-10-03 12:16:33 +00:00
|
|
|
},
|
2024-01-11 12:20:50 +00:00
|
|
|
item: {
|
|
|
|
ref: "!string",
|
|
|
|
name: "!string",
|
|
|
|
page: "!string",
|
|
|
|
tags: "string[]",
|
|
|
|
},
|
2023-10-13 15:10:57 +00:00
|
|
|
taskstate: {
|
2023-12-21 17:37:50 +00:00
|
|
|
ref: "!string",
|
2024-01-04 19:08:12 +00:00
|
|
|
tags: "!string[]",
|
2023-12-21 17:37:50 +00:00
|
|
|
state: "!string",
|
|
|
|
count: "!number",
|
|
|
|
page: "!string",
|
2023-10-13 15:10:57 +00:00
|
|
|
},
|
2023-10-03 12:16:33 +00:00
|
|
|
tag: {
|
2023-12-21 17:37:50 +00:00
|
|
|
ref: "!string",
|
|
|
|
name: "!string",
|
|
|
|
page: "!string",
|
|
|
|
context: "!string",
|
2023-10-03 12:16:33 +00:00
|
|
|
},
|
|
|
|
attribute: {
|
2023-12-21 17:37:50 +00:00
|
|
|
ref: "!string",
|
|
|
|
name: "!string",
|
|
|
|
attributeType: "!string",
|
2024-01-11 12:20:50 +00:00
|
|
|
tagName: "!string",
|
2023-12-21 17:37:50 +00:00
|
|
|
page: "!string",
|
2023-12-22 10:27:07 +00:00
|
|
|
readOnly: "!boolean",
|
2023-10-03 12:16:33 +00:00
|
|
|
},
|
|
|
|
anchor: {
|
2023-12-21 17:37:50 +00:00
|
|
|
ref: "!string",
|
|
|
|
name: "!string",
|
|
|
|
page: "!string",
|
|
|
|
pos: "!number",
|
2023-10-03 12:16:33 +00:00
|
|
|
},
|
|
|
|
link: {
|
2023-12-21 17:37:50 +00:00
|
|
|
ref: "!string",
|
|
|
|
name: "!string",
|
|
|
|
page: "!string",
|
|
|
|
pos: "!number",
|
|
|
|
alias: "!string",
|
|
|
|
asTemplate: "!boolean",
|
2023-10-03 12:16:33 +00:00
|
|
|
},
|
2023-10-12 18:30:47 +00:00
|
|
|
paragraph: {
|
2023-12-21 17:37:50 +00:00
|
|
|
text: "!string",
|
|
|
|
page: "!string",
|
|
|
|
pos: "!number",
|
2023-10-12 18:30:47 +00:00
|
|
|
},
|
2023-11-11 13:28:46 +00:00
|
|
|
template: {
|
2023-12-21 17:37:50 +00:00
|
|
|
ref: "!string",
|
|
|
|
page: "!string",
|
|
|
|
pageName: "string",
|
|
|
|
pos: "!number",
|
|
|
|
type: "string",
|
2023-11-11 13:28:46 +00:00
|
|
|
trigger: "string",
|
2024-01-08 16:08:26 +00:00
|
|
|
where: "string",
|
|
|
|
priority: "number",
|
2024-01-11 13:06:24 +00:00
|
|
|
enabled: "boolean",
|
2023-11-11 13:28:46 +00:00
|
|
|
},
|
2023-10-03 12:16:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export async function loadBuiltinsIntoIndex() {
|
|
|
|
console.log("Loading builtins attributes into index");
|
2024-01-13 16:30:15 +00:00
|
|
|
const allObjects: ObjectValue<any>[] = [];
|
2024-01-11 12:20:50 +00:00
|
|
|
for (const [tagName, attributes] of Object.entries(builtins)) {
|
2024-01-13 16:30:15 +00:00
|
|
|
allObjects.push({
|
2024-01-11 12:20:50 +00:00
|
|
|
ref: tagName,
|
|
|
|
tag: "tag",
|
|
|
|
name: tagName,
|
2023-10-03 12:16:33 +00:00
|
|
|
page: builtinPseudoPage,
|
|
|
|
parent: "builtin",
|
|
|
|
});
|
2024-01-13 16:30:15 +00:00
|
|
|
allObjects.push(
|
|
|
|
...Object.entries(attributes).map(([name, attributeType]) => ({
|
|
|
|
ref: `${tagName}:${name}`,
|
|
|
|
tag: "attribute",
|
|
|
|
tagName,
|
|
|
|
name,
|
|
|
|
attributeType: attributeType.startsWith("!")
|
|
|
|
? attributeType.substring(1)
|
|
|
|
: attributeType,
|
|
|
|
readOnly: attributeType.startsWith("!"),
|
|
|
|
page: builtinPseudoPage,
|
|
|
|
})),
|
2023-10-03 12:16:33 +00:00
|
|
|
);
|
|
|
|
}
|
2024-01-13 16:30:15 +00:00
|
|
|
await indexObjects(builtinPseudoPage, allObjects);
|
2023-10-03 12:16:33 +00:00
|
|
|
}
|