1
0
silverbullet/plug-api/types.ts

143 lines
3.2 KiB
TypeScript
Raw Normal View History

export type FileMeta = {
name: string;
created: number;
lastModified: number;
contentType: string;
size: number;
perm: "ro" | "rw";
noSync?: boolean;
};
2023-11-06 08:14:16 +00:00
export type PageMeta = ObjectValue<
{
name: string;
created: string; // indexing it as a string
lastModified: string; // indexing it as a string
lastOpened?: number;
perm: "ro" | "rw";
} & Record<string, any>
>;
export type AttachmentMeta = {
name: string;
contentType: string;
created: number;
lastModified: number;
size: number;
perm: "ro" | "rw";
};
// Message Queue related types
2023-08-28 15:12:15 +00:00
export type MQMessage = {
2023-08-10 16:32:41 +00:00
id: string;
queue: string;
body: any;
retries?: number;
};
2023-08-11 18:37:13 +00:00
2023-08-28 15:12:15 +00:00
export type MQStats = {
2023-08-11 18:37:13 +00:00
queued: number;
processing: number;
dlq: number;
};
2023-08-20 15:51:00 +00:00
2023-08-28 15:12:15 +00:00
export type MQSubscribeOptions = {
batchSize?: number;
pollInterval?: number;
};
// Key-Value Store related types
export type KvKey = string[];
export type KV<T = any> = {
key: KvKey;
value: T;
};
export type OrderBy = {
expr: QueryExpression;
desc: boolean;
};
export type Select = {
2023-08-20 15:51:00 +00:00
name: string;
expr?: QueryExpression;
};
export type Query = {
querySource?: string;
filter?: QueryExpression;
orderBy?: OrderBy[];
select?: Select[];
limit?: QueryExpression;
render?: string;
2023-10-30 13:15:12 +00:00
renderAll?: boolean;
2023-10-03 13:24:07 +00:00
distinct?: boolean;
};
export type KvQuery = Omit<Query, "querySource"> & {
prefix?: KvKey;
};
export type QueryExpression =
| ["and", QueryExpression, QueryExpression]
| ["or", QueryExpression, QueryExpression]
| ["=", QueryExpression, QueryExpression]
| ["!=", QueryExpression, QueryExpression]
| ["=~", QueryExpression, QueryExpression]
| ["!=~", QueryExpression, QueryExpression]
| ["<", QueryExpression, QueryExpression]
| ["<=", QueryExpression, QueryExpression]
| [">", QueryExpression, QueryExpression]
| [">=", QueryExpression, QueryExpression]
| ["in", QueryExpression, QueryExpression]
| ["attr", QueryExpression, string]
| ["attr", string]
| ["number", number]
| ["string", string]
| ["boolean", boolean]
| ["null"]
| ["array", QueryExpression[]]
| ["object", Record<string, any>]
| ["regexp", string, string] // regex, modifier
| ["+", QueryExpression, QueryExpression]
| ["-", QueryExpression, QueryExpression]
| ["*", QueryExpression, QueryExpression]
| ["%", QueryExpression, QueryExpression]
| ["/", QueryExpression, QueryExpression]
| ["call", string, QueryExpression[]];
export type FunctionMap = Record<string, (...args: any[]) => any>;
/**
* An ObjectValue that can be indexed by the `index` plug, needs to have a minimum of
* of two fields:
* - ref: a unique reference (id) for the object, ideally a page reference
* - tags: a list of tags that the object belongs to
*/
export type ObjectValue<T> = {
ref: string;
tags: string[];
} & T;
export type ObjectQuery = Omit<Query, "prefix">;
2023-10-29 09:02:50 +00:00
// Code widget stuff
export type CodeWidgetCallback = (
bodyText: string,
2023-10-31 09:33:38 +00:00
pageName: string,
2023-10-29 09:02:50 +00:00
) => Promise<CodeWidgetContent>;
export type CodeWidgetContent = {
html?: string;
markdown?: string;
script?: string;
};
export type LintDiagnostic = {
from: number;
to: number;
severity: "error" | "warning" | "info" | "hint";
message: string;
};