1
0
silverbullet/plugs/index/builtins.ts

120 lines
2.6 KiB
TypeScript
Raw Normal View History

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
export const builtins: Record<string, Record<string, string>> = {
page: {
2023-12-21 17:37:50 +00:00
ref: "!string",
name: "!string",
displayName: "string",
aliases: "string[]",
2023-12-21 17:37:50 +00:00
created: "!date",
lastModified: "!date",
perm: "!rw|ro",
contentType: "!string",
size: "!number",
tags: "string[]",
},
task: {
2023-12-21 17:37:50 +00:00
ref: "!string",
name: "!string",
done: "!boolean",
page: "!string",
state: "!string",
deadline: "string",
2023-12-21 17:37:50 +00:00
pos: "!number",
tags: "string[]",
},
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",
tags: "!string[]",
2023-12-21 17:37:50 +00:00
state: "!string",
count: "!number",
page: "!string",
2023-10-13 15:10:57 +00:00
},
tag: {
2023-12-21 17:37:50 +00:00
ref: "!string",
name: "!string",
page: "!string",
context: "!string",
},
attribute: {
2023-12-21 17:37:50 +00:00
ref: "!string",
name: "!string",
attributeType: "!string",
tagName: "!string",
2023-12-21 17:37:50 +00:00
page: "!string",
readOnly: "!boolean",
},
anchor: {
2023-12-21 17:37:50 +00:00
ref: "!string",
name: "!string",
page: "!string",
pos: "!number",
},
link: {
2023-12-21 17:37:50 +00:00
ref: "!string",
name: "!string",
page: "!string",
pos: "!number",
alias: "!string",
asTemplate: "!boolean",
},
paragraph: {
2023-12-21 17:37:50 +00:00
text: "!string",
page: "!string",
pos: "!number",
},
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",
where: "string",
priority: "number",
2023-11-11 13:28:46 +00:00
},
};
export async function loadBuiltinsIntoIndex() {
console.log("Loading builtins attributes into index");
const allTags: ObjectValue<TagObject>[] = [];
for (const [tagName, attributes] of Object.entries(builtins)) {
allTags.push({
ref: tagName,
tag: "tag",
name: tagName,
page: builtinPseudoPage,
parent: "builtin",
});
await indexObjects<AttributeObject>(
builtinPseudoPage,
Object.entries(attributes).map(([name, attributeType]) => {
return {
ref: `${tagName}:${name}`,
tag: "attribute",
tagName,
name,
2023-12-21 17:37:50 +00:00
attributeType: attributeType.startsWith("!")
? attributeType.substring(1)
: attributeType,
readOnly: attributeType.startsWith("!"),
page: builtinPseudoPage,
};
}),
);
}
await indexObjects(builtinPseudoPage, allTags);
}