Editor refactor: fix plug namespace

This commit is contained in:
Zef Hemel
2023-07-14 16:48:35 +02:00
parent e92ed2c5be
commit f3936f9b2f
6 changed files with 51 additions and 76 deletions
@@ -9,28 +9,28 @@ export type NamespaceOperation =
| "getFileMeta"
| "deleteFile";
export type PageNamespaceDef = {
export type PlugNamespaceDef = {
pattern: string;
operation: NamespaceOperation;
};
export type PageNamespaceHookT = {
pageNamespace?: PageNamespaceDef;
export type PlugNamespaceHookT = {
pageNamespace?: PlugNamespaceDef;
};
type SpaceFunction = {
operation: NamespaceOperation;
pattern: RegExp;
plug: Plug<PageNamespaceHookT>;
plug: Plug<PlugNamespaceHookT>;
name: string;
env?: string;
};
export class PageNamespaceHook implements Hook<PageNamespaceHookT> {
export class PlugNamespaceHook implements Hook<PlugNamespaceHookT> {
spaceFunctions: SpaceFunction[] = [];
constructor() {}
apply(system: System<PageNamespaceHookT>): void {
apply(system: System<PlugNamespaceHookT>): void {
system.on({
plugLoaded: () => {
this.updateCache(system);
@@ -41,7 +41,7 @@ export class PageNamespaceHook implements Hook<PageNamespaceHookT> {
});
}
updateCache(system: System<PageNamespaceHookT>) {
updateCache(system: System<PlugNamespaceHookT>) {
this.spaceFunctions = [];
for (const plug of system.loadedPlugs.values()) {
if (plug.manifest?.functions) {
@@ -64,7 +64,7 @@ export class PageNamespaceHook implements Hook<PageNamespaceHookT> {
}
}
validateManifest(manifest: Manifest<PageNamespaceHookT>): string[] {
validateManifest(manifest: Manifest<PlugNamespaceHookT>): string[] {
const errors: string[] = [];
if (!manifest.functions) {
return [];
+2 -2
View File
@@ -3,7 +3,7 @@ import { CronHookT } from "../plugos/hooks/cron.ts";
import { EventHookT } from "../plugos/hooks/event.ts";
import { CommandHookT } from "../web/hooks/command.ts";
import { SlashCommandHookT } from "../web/hooks/slash_command.ts";
import { PageNamespaceHookT } from "./hooks/page_namespace.ts";
import { PlugNamespaceHookT } from "./hooks/plug_namespace.ts";
import { CodeWidgetT } from "../web/hooks/code_widget.ts";
export type SilverBulletHooks =
@@ -12,7 +12,7 @@ export type SilverBulletHooks =
& CronHookT
& EventHookT
& CodeWidgetT
& PageNamespaceHookT;
& PlugNamespaceHookT;
export type SyntaxExtensions = {
syntax?: { [key: string]: NodeDef };
+3 -3
View File
@@ -2,13 +2,13 @@ import { SpacePrimitives } from "../../common/spaces/space_primitives.ts";
import { FileMeta } from "../../common/types.ts";
import {
NamespaceOperation,
PageNamespaceHook,
} from "../hooks/page_namespace.ts";
PlugNamespaceHook,
} from "../hooks/plug_namespace.ts";
export class PlugSpacePrimitives implements SpacePrimitives {
constructor(
private wrapped: SpacePrimitives,
private hook: PageNamespaceHook,
private hook: PlugNamespaceHook,
private env?: string,
) {}