Work on $share

This commit is contained in:
Zef Hemel
2022-11-24 12:04:00 +01:00
parent c5c6cd3af0
commit 5b1ec14891
20 changed files with 528 additions and 163 deletions
+5 -3
View File
@@ -23,6 +23,7 @@ type SpaceFunction = {
pattern: RegExp;
plug: Plug<PageNamespaceHookT>;
name: string;
env?: string;
};
export class PageNamespaceHook implements Hook<PageNamespaceHookT> {
@@ -42,10 +43,10 @@ export class PageNamespaceHook implements Hook<PageNamespaceHookT> {
updateCache(system: System<PageNamespaceHookT>) {
this.spaceFunctions = [];
for (let plug of system.loadedPlugs.values()) {
for (const plug of system.loadedPlugs.values()) {
if (plug.manifest?.functions) {
for (
let [funcName, funcDef] of Object.entries(
const [funcName, funcDef] of Object.entries(
plug.manifest.functions,
)
) {
@@ -55,6 +56,7 @@ export class PageNamespaceHook implements Hook<PageNamespaceHookT> {
pattern: new RegExp(funcDef.pageNamespace.pattern),
plug,
name: funcName,
env: funcDef.env,
});
}
}
@@ -63,7 +65,7 @@ export class PageNamespaceHook implements Hook<PageNamespaceHookT> {
}
validateManifest(manifest: Manifest<PageNamespaceHookT>): string[] {
let errors: string[] = [];
const errors: string[] = [];
if (!manifest.functions) {
return [];
}
+8 -2
View File
@@ -12,6 +12,7 @@ export class PlugSpacePrimitives implements SpacePrimitives {
constructor(
private wrapped: SpacePrimitives,
private hook: PageNamespaceHook,
private env: string,
) {}
performOperation(
@@ -19,8 +20,13 @@ export class PlugSpacePrimitives implements SpacePrimitives {
pageName: string,
...args: any[]
): Promise<any> | false {
for (const { operation, pattern, plug, name } of this.hook.spaceFunctions) {
if (operation === type && pageName.match(pattern)) {
for (
const { operation, pattern, plug, name, env } of this.hook.spaceFunctions
) {
if (
operation === type && pageName.match(pattern) &&
(env ? env === this.env : true)
) {
return plug.invoke(name, [pageName, ...args]);
}
}
+1
View File
@@ -102,6 +102,7 @@ export class HttpServer {
new PlugSpacePrimitives(
new DiskSpacePrimitives(options.pagesPath),
namespaceHook,
"server",
),
this.eventHook,
),