Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MWS: Async rewrite #8888

Open
wants to merge 26 commits into
base: multi-wiki-support
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 93 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@
"lint": "eslint ."
},
"dependencies": {
"@prisma/client": "^6.2.1",
"@types/node": "^22.10.5",
"better-sqlite3": "^11.5.0",
"node-sqlite3-wasm": "^0.8.25"
"node-sqlite3-wasm": "^0.8.25",
"prisma": "^6.2.1"
}
}
112 changes: 71 additions & 41 deletions plugins/tiddlywiki/multiwikiserver/globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,102 @@
import { SqlTiddlerDatabase } from "./modules/store/sql-tiddler-database";
import { IncomingMessage as HTTPIncomingMessage } from "http";
import { IncomingMessage as HTTPIncomingMessage, ServerResponse as HTTPServerResponse } from "http";
import { Server as _Server } from "./src/server";
import { Router } from "./src/router";
import { SqlTiddlerStore as _SqlTiddlerStore } from "./modules/store/sql-tiddler-store";
import { SqlTiddlerDatabase as _SqlTiddlerDatabase } from "./modules/store/sql-tiddler-database";
import { Authenticator as _Authenticator } from "./auth/authentication";
import { Prisma, PrismaClient } from "@prisma/client";
import { DefaultArgs } from "@prisma/client/runtime/library";
import "./src/startup";

declare global {
const $tw: {
const $tw: $TW;

namespace $TW {
interface Wiki extends Record<string, any> {

}
interface Boot {

}
interface Tiddler {

}
}

interface $TW {
loadTiddlersFromPath: any;
loadPluginFolder: any;
getLibraryItemSearchPaths: any;
wiki: $TW.Wiki;
utils: any;
utils: {
[x: string]: any;
decodeURIComponentSafe(str: string): string;
each<T>(object: T[], callback: (value: T, index: number, object: T[]) => void): void;
each<T>(object: Record<string, T>, callback: (value: T, key: string, object: Record<string, T>) => void): void;
parseJSONSafe(str: string, defaultJSON?: any): any;
};
modules: {
[x: string]: any;
forEachModuleOfType: (moduleType: string, callback: (title: string, module: any) => void) => void;
}
boot: any;
config: any;
node: any;
modules: any;
hooks: any;
sjcl: any;
Wiki: { new(): $TW.Wiki };
Tiddler: { new(fields: Record<string, any>): $TW.Tiddler };
mws: {
serverManager: ServerManager;
store: SqlTiddlerStore
}

}

namespace $TW {
interface Wiki extends Record<string, any> {
type Server = _Server;
type SqlTiddlerStore = _SqlTiddlerStore;
type SqlTiddlerDatabase = _SqlTiddlerDatabase;
type Authenticator = _Authenticator;

}
interface Boot {
type HTTPVerb = "GET" | "OPTIONS" | "HEAD" | "PUT" | "POST" | "DELETE";

interface IncomingMessage extends HTTPIncomingMessage {
url: string;
method: string;
headers: {
"set-cookie"?: string[];
[x: string]: string | undefined;
}
interface Tiddler {
}

}
interface ServerResponse extends HTTPServerResponse { }

type InnerState = Awaited<ReturnType<Router["makeRequestState"]>>;
interface ServerState<P extends number, F extends ServerRouteBodyFormat> extends InnerState {
params: string[] & { length: P };
data:
F extends "json" ? any :
F extends "www-form-urlencoded" ? URLSearchParams :
F extends "buffer" ? Buffer :
F extends "stream" ? undefined :
string;
}
type SqlTiddlerDatabase = import("./modules/store/sql-tiddler-database").SqlTiddlerDatabase;
type SqlTiddlerStore = import("./modules/store/sql-tiddler-store").SqlTiddlerStore;
type Server = import("./modules/mws-server.js").Server;
type ServerState = Awaited<ReturnType<Server["makeRequestState"]>>;
interface IncomingMessage extends HTTPIncomingMessage {
url: string
};
type ServerResponse = import("http").ServerResponse;

type PrismaTxnClient = Omit<PrismaClient<Prisma.PrismaClientOptions, never, DefaultArgs>, "$connect" | "$disconnect" | "$on" | "$transaction" | "$use" | "$extends">
interface ServerRoute {
path: RegExp;
handler: ServerRouteHandler;
handler: ServerRouteHandler<number>;
method?: string;
useACL?: boolean;
/** this is required if useACL is true */
entityName?: string;
csrfDisable?: boolean;
bodyFormat?: string;
bodyFormat?: ServerRouteBodyFormat;
}
interface ServerOptions {
sqlTiddlerDatabase?: SqlTiddlerDatabase;
variables?: Server["defaultVariables"];
authenticators?: unknown[];
routes?: [];
wiki?: any;
boot?: any;
}

interface ServerRouteHandler {
(this: ServerRoute, req: IncomingMessage, res: ServerResponse, state: ServerState): Promise<void>;
type ServerRouteBodyFormat = "string" | "www-form-urlencoded" | "buffer" | "stream";
interface ServerRouteHandler<P extends number, F extends ServerRouteBodyFormat = "string"> {
(this: ServerRoute, req: IncomingMessage, res: ServerResponse, state: ServerState<P, F>): Promise<void>;
}

}
class ServerManager {
constructor();
createServer(options: ServerOptions);
}

export { };

export { };


11 changes: 7 additions & 4 deletions plugins/tiddlywiki/multiwikiserver/jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@
"./auth/*"
],
"$:/plugins/tiddlywiki/multiwikiserver/*": [
"./modules/*"
"./src/*",
"./modules/*",
],
},
"checkJs": true,
"strictNullChecks": true,

"strict": true,
},
"include": [
"./**/*.js",
"./modules/routes/handlers/*.js",
"./modules/commands/*.js",
"./globals.d.ts"
]
],

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@ Command.prototype.execute = function() {
if(!$tw.boot.wikiTiddlersPath) {
$tw.utils.warning("Warning: Wiki folder '" + $tw.boot.wikiPath + "' does not exist or is missing a tiddlywiki.info file");
}
const {Router} = require("$:/plugins/tiddlywiki/multiwikiserver/router.js");
const router = new Router({wiki: $tw.wiki, variables: self.params});


// Set up server
this.server = $tw.mws.serverManager.createServer({
wiki: $tw.wiki,
variables: self.params
});
this.server = $tw.mws.serverManager.listenCommand(self.params);

this.server.listen(null,null,null,{
callback: function() {
self.callback();
}
});

return null;
};

Expand Down
Loading
Loading