Skip to content

Build your personal knowledge base with Trilium Notes

chore(scripting): fail the build on undeclared script API members

Elian Doran294c75f9f7bc
diff --git a/apps/client/src/services/frontend_script_api.ts b/apps/client/src/services/frontend_script_api.ts
index bfbb5f3fd5..5e5b7611bb 100644
--- a/apps/client/src/services/frontend_script_api.ts
+++ b/apps/client/src/services/frontend_script_api.ts
@@ -508,11 +508,17 @@ export default FrontendScriptApi as any as {
// checks fail to compile — naming the offending member — if that public surface
// claims an `api`/`FNote` member that has since been renamed or removed here.
type _MissingApiMembers = Exclude<keyof PublicFrontendApi, keyof Api>;
+// The reverse check: a member added to `api` fails to compile until the public surface declares it,
+// so the editor's completions and the generated references list it. The exceptions are deprecated
+// or private, and left out of the public surface on purpose.
+type _UndeclaredApiMembers = Exclude<keyof Api, keyof PublicFrontendApi | "addButtonToToolbar" | "__runOnBackendInner">;
type _MissingFNoteMembers = Exclude<keyof PublicScriptFNote, keyof FNote>;
type _MissingLinkOptions = Exclude<keyof ScriptLinkOptions, keyof NonNullable<Parameters<typeof linkService.createLink>[1]>>;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _apiDriftGuard: [_MissingApiMembers] extends [never] ? true : _MissingApiMembers = true;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
+const _undeclaredApiGuard: [_UndeclaredApiMembers] extends [never] ? true : _UndeclaredApiMembers = true;
+// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _fnoteDriftGuard: [_MissingFNoteMembers] extends [never] ? true : _MissingFNoteMembers = true;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _linkOptionsDriftGuard: [_MissingLinkOptions] extends [never] ? true : _MissingLinkOptions = true;
diff --git a/packages/trilium-core/src/services/backend_script_api.ts b/packages/trilium-core/src/services/backend_script_api.ts
index fa876a2cea..327ec042c5 100644
--- a/packages/trilium-core/src/services/backend_script_api.ts
+++ b/packages/trilium-core/src/services/backend_script_api.ts
@@ -562,6 +562,10 @@ export default BackendScriptApi as any as {
// that public surface claims a member of `api`, or of a type it returns, that has
// since been renamed or removed here.
type _MissingBackendApiMembers = Exclude<keyof PublicBackendApi, keyof Api>;
+// The reverse check: a member added to `api` fails to compile until the public surface declares it,
+// so the editor's completions and the generated references list it. The exceptions are deprecated
+// or private, and left out of the public surface on purpose.
+type _UndeclaredBackendApiMembers = Exclude<keyof Api, keyof PublicBackendApi | "axios" | "cheerio" | "createNote" | "__private">;
type _MissingBNoteMembers = Exclude<keyof PublicScriptBNote, keyof BNote>;
type _MissingBAttachmentMembers = Exclude<keyof ScriptBAttachment, keyof BAttachment>;
type _MissingBOptionMembers = Exclude<keyof ScriptBOption, keyof BOption>;
@@ -572,6 +576,8 @@ type _MissingSqlMembers = Exclude<keyof ScriptSql, keyof ReturnType<typeof getSq
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _backendApiDriftGuard: [_MissingBackendApiMembers] extends [never] ? true : _MissingBackendApiMembers = true;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
+const _undeclaredBackendApiGuard: [_UndeclaredBackendApiMembers] extends [never] ? true : _UndeclaredBackendApiMembers = true;
+// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _bnoteDriftGuard: [_MissingBNoteMembers] extends [never] ? true : _MissingBNoteMembers = true;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _battachmentDriftGuard: [_MissingBAttachmentMembers] extends [never] ? true : _MissingBAttachmentMembers = true;