Skip to content

Commit b1449c4

Browse files
committed
update deps; update types
1 parent 0663e6e commit b1449c4

File tree

14 files changed

+74
-53
lines changed

14 files changed

+74
-53
lines changed

JsEngine.d.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,10 @@ declare module 'jsEngine/messages/MessageManager' {
158158
}
159159
declare module 'jsEngine/settings/StartupScriptModal' {
160160
import type JsEnginePlugin from 'jsEngine/main';
161-
import StartupScripts from 'jsEngine/settings/StartupScripts.svelte';
162161
import { Modal } from 'obsidian';
163162
export class StartupScriptsModal extends Modal {
164-
plugin: JsEnginePlugin;
165-
component?: ReturnType<typeof StartupScripts>;
163+
private readonly plugin;
164+
private component?;
166165
constructor(plugin: JsEnginePlugin);
167166
onOpen(): void;
168167
onClose(): void;
@@ -194,7 +193,8 @@ declare module 'jsEngine/api/markdown/MarkdownElementType' {
194193
}
195194
declare module 'jsEngine/api/markdown/MarkdownString' {
196195
import type { API } from 'jsEngine/api/API';
197-
import type { App, Component } from 'obsidian';
196+
import type { Component } from 'obsidian';
197+
import { App } from 'obsidian';
198198
/**
199199
* A string that should be rendered as markdown by the plugin.
200200
*/
@@ -689,6 +689,7 @@ declare module 'jsEngine/utils/Validators' {
689689
import { z } from 'zod';
690690
export function schemaForType<T>(): <S extends z.ZodType<T, any, any>>(arg: S) => S;
691691
export function validateAPIArgs<T>(validator: z.ZodType<T>, args: T): void;
692+
export function zodFunction<T extends Function>(): z.ZodCustom<T, T>;
692693
export class Validators {
693694
htmlElement: z.ZodType<HTMLElement, any, any>;
694695
voidFunction: z.ZodType<() => void, any, any>;
@@ -1417,6 +1418,10 @@ declare module 'jsEngine/engine/JsExecution' {
14171418
}
14181419
export interface JSFileExecutionContext {
14191420
executionSource: ExecutionSource.JSFile;
1421+
/**
1422+
* There is no associated markdown file.
1423+
*/
1424+
file: undefined;
14201425
/**
14211426
* The JS that is being executed.
14221427
*/

bun.lockb

25.5 KB
Binary file not shown.

jsEngine/api/Internal.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export class InternalAPI {
7979
return await this.execute({
8080
context: {
8181
executionSource: ExecutionSource.JSFile,
82+
file: undefined,
8283
jsFile: file,
8384
},
8485
...params,
@@ -212,6 +213,7 @@ export class InternalAPI {
212213

213214
return {
214215
executionSource: ExecutionSource.JSFile,
216+
file: undefined,
215217
jsFile: file,
216218
};
217219
}

jsEngine/api/QueryAPI.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { API } from 'jsEngine/api/API';
2-
import { validateAPIArgs } from 'jsEngine/utils/Validators';
2+
import { validateAPIArgs, zodFunction } from 'jsEngine/utils/Validators';
33
import type { CachedMetadata, TFile } from 'obsidian';
44
import { getAllTags } from 'obsidian';
55
import { z } from 'zod';
@@ -27,7 +27,7 @@ export class QueryAPI {
2727
* ```
2828
*/
2929
public files<T>(query: (file: TFile) => T | undefined): T[] {
30-
validateAPIArgs(z.object({ query: z.function().args(this.apiInstance.validators.tFile).returns(z.unknown()) }), { query });
30+
validateAPIArgs(z.object({ query: zodFunction() }), { query });
3131

3232
return this.apiInstance.app.vault
3333
.getMarkdownFiles()
@@ -47,10 +47,7 @@ export class QueryAPI {
4747
public filesWithMetadata<T>(query: (file: TFile, cache: CachedMetadata | undefined, tags: string[], frontmatterTags: string[]) => T | undefined): T[] {
4848
validateAPIArgs(
4949
z.object({
50-
query: z
51-
.function()
52-
.args(this.apiInstance.validators.tFile, this.apiInstance.validators.cachedMetadata.optional(), z.string().array(), z.string().array())
53-
.returns(z.unknown()),
50+
query: zodFunction(),
5451
}),
5552
{ query },
5653
);

jsEngine/api/markdown/MarkdownString.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { API } from 'jsEngine/api/API';
22
import { validateAPIArgs } from 'jsEngine/utils/Validators';
3-
import type { App, Component } from 'obsidian';
3+
import type { Component } from 'obsidian';
4+
import { App } from 'obsidian';
45
import { MarkdownRenderer } from 'obsidian';
56
import { z } from 'zod';
67

@@ -22,7 +23,7 @@ export class MarkdownString {
2223
async render(app: App, element: HTMLElement, sourcePath: string, component: Component): Promise<void> {
2324
validateAPIArgs(
2425
z.object({
25-
app: z.object({}),
26+
app: z.instanceof(App),
2627
element: this.apiInstance.validators.htmlElement,
2728
sourcePath: z.string(),
2829
component: this.apiInstance.validators.component,

jsEngine/api/prompts/SvelteModal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class SvelteModal<Component extends AnySvelteComponent, T> extends Modal
4242
}
4343

4444
if (this.component) {
45-
unmount(this.component);
45+
void unmount(this.component);
4646
}
4747
this.contentEl.empty();
4848
}

jsEngine/engine/ExecutionStatsModal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class ExecutionStatsModal extends Modal {
2626
public onOpen(): void {
2727
this.contentEl.empty();
2828
if (this.component) {
29-
unmount(this.component);
29+
void unmount(this.component);
3030
}
3131

3232
if (!this.contentEl.hasClass('js-engine-execution-stats-modal')) {
@@ -49,7 +49,7 @@ export class ExecutionStatsModal extends Modal {
4949
public onClose(): void {
5050
this.contentEl.empty();
5151
if (this.component) {
52-
unmount(this.component);
52+
void unmount(this.component);
5353
}
5454
}
5555
}

jsEngine/engine/JsExecution.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ export interface MarkdownOtherExecutionContext {
7474

7575
export interface JSFileExecutionContext {
7676
executionSource: ExecutionSource.JSFile;
77+
/**
78+
* There is no associated markdown file.
79+
*/
80+
file: undefined;
7781
/**
7882
* The JS that is being executed.
7983
*/

jsEngine/engine/ResultRenderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class ResultRenderer {
6868
});
6969

7070
this.component.register(() => {
71-
unmount(svelteComponent);
71+
void unmount(svelteComponent);
7272
});
7373
return;
7474
}

jsEngine/messages/MessageDisplay.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class MessageDisplay extends Modal {
2020
public onOpen(): void {
2121
this.contentEl.empty();
2222
if (this.component) {
23-
unmount(this.component);
23+
void unmount(this.component);
2424
}
2525

2626
this.component = mount(MessageDisplayComponent, {
@@ -34,7 +34,7 @@ export class MessageDisplay extends Modal {
3434
public onClose(): void {
3535
this.contentEl.empty();
3636
if (this.component) {
37-
unmount(this.component);
37+
void unmount(this.component);
3838
}
3939
}
4040
}

0 commit comments

Comments
 (0)