A lexicon-driven AppView for ATProto.
Something went wrong. Try again.
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667export const LEXICON_TEMPLATE = JSON.stringify( { $type: "com.atproto.lexicon.schema", lexicon: 1, id: "", defs: { main: { type: "record", key: "tid", record: { type: "object", required: [], properties: {}, }, }, }, }, null, 2,)
export function procedureScript(collection: string): string { const target = collection || "COLLECTION" return `function handle()\tlocal r = Record("${target}", input)\tr:save()\treturn { uri = r._uri, cid = r._cid }end`}
export function indexHookScript(): string { return `function handle()\tif action == "delete" then\t\t-- record was deleted\t\tlog("deleted " .. uri)\telse\t\t-- record was created or updated\t\tlog(action .. " " .. uri)\tendend`}
export function queryScript(collection: string): string { const target = collection || "COLLECTION" return `collection = "${target}"
function handle()\tif params.uri then\t\tlocal record = db.get(params.uri)\t\tif not record then\t\t\terror("record not found")\t\tend\t\treturn { record = record }\tend
\treturn db.query({\t\tcollection = collection,\t\tdid = params.did,\t\tlimit = params.limit,\t\tcursor = params.cursor,\t})end`}