@tiddlywiki/mws 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +3 -1
  2. package/dist/server.d.ts +923 -0
  3. package/dist/server.js +1763 -1415
  4. package/dist/server.js.map +1 -1
  5. package/editions/mws-docs/tiddlers/$__StoryList.tid +3 -3
  6. package/editions/mws-docs/tiddlers/MWS and SQLite.md +11 -0
  7. package/editions/mws-docs/tiddlers/Request Server.md +20 -0
  8. package/editions/mws-docs/tiddlers/Request Server.md.meta +5 -0
  9. package/package.json +16 -10
  10. package/prisma/schema.prisma +1 -0
  11. package/react-user-mgmt/package-lock.json +76 -321
  12. package/react-user-mgmt/package.json +2 -5
  13. package/react-user-mgmt/public/chunk-YALWN5OT.js +2 -0
  14. package/react-user-mgmt/public/chunk-YALWN5OT.js.map +7 -0
  15. package/react-user-mgmt/public/esm-QKDFEP3B.js +3 -0
  16. package/react-user-mgmt/public/esm-QKDFEP3B.js.map +7 -0
  17. package/react-user-mgmt/public/index.html +1 -26
  18. package/react-user-mgmt/public/main.js +68 -109
  19. package/react-user-mgmt/public/main.js.map +4 -4
  20. package/react-user-mgmt/public/stats.css +597 -0
  21. package/react-user-mgmt/public/stats.html +59 -0
  22. package/react-user-mgmt/public/stats.js +2013 -0
  23. package/react-user-mgmt/public/stats.json +1 -0
  24. package/react-user-mgmt/public/stats.svg +4 -0
  25. package/react-user-mgmt/tsconfig.json +3 -0
  26. package/dist/server.cjs +0 -16677
  27. package/dist/server.cjs.map +0 -1
  28. package/src/StateObject.ts +0 -316
  29. package/src/commander.ts +0 -417
  30. package/src/commands/divider.ts +0 -20
  31. package/src/commands/index.ts +0 -24
  32. package/src/commands/mws-init-store.ts +0 -77
  33. package/src/commands/mws-listen.ts +0 -136
  34. package/src/commands/mws-load-archive.ts +0 -281
  35. package/src/commands/mws-load-plugin-bags.ts +0 -151
  36. package/src/commands/mws-load-tiddlers.ts +0 -37
  37. package/src/commands/mws-load-wiki-folder.ts +0 -124
  38. package/src/commands/mws-render-tiddlywiki5.ts +0 -55
  39. package/src/commands/mws-save-archive.ts +0 -111
  40. package/src/commands/mws-save-tiddler-text.ts +0 -33
  41. package/src/commands/tests-complete.ts +0 -21
  42. package/src/global.ts +0 -247
  43. package/src/routes/TiddlerStore.ts +0 -722
  44. package/src/routes/bag-file-server.ts +0 -340
  45. package/src/routes/cache.ts +0 -25
  46. package/src/routes/index.ts +0 -138
  47. package/src/routes/managers/index.ts +0 -17
  48. package/src/routes/managers/manager-recipes.ts +0 -438
  49. package/src/routes/managers/manager-users.ts +0 -201
  50. package/src/routes/managers/router-tiddlers.ts +0 -313
  51. package/src/routes/router.ts +0 -429
  52. package/src/routes/services/PasswordService.ts +0 -178
  53. package/src/routes/services/attachments.ts +0 -259
  54. package/src/routes/services/sessions.ts +0 -166
  55. package/src/routes/tw-test.ts +0 -65
  56. package/src/server.ts +0 -151
  57. package/src/setupDevServer.ts +0 -71
  58. package/src/streamer.ts +0 -430
  59. package/src/tiddlywiki.ts +0 -94
  60. package/src/utils/data-checks.ts +0 -172
  61. package/src/utils/index.ts +0 -4
  62. package/src/utils/rootRoute.ts +0 -237
  63. package/src/utils/utils.ts +0 -403
  64. package/src/utils/zodAssert.ts +0 -269
  65. /package/prisma/{migrations/notes.md → notes.md} +0 -0
@@ -1,111 +0,0 @@
1
- /*\
2
- title: $:/plugins/tiddlywiki/multiwikiserver/commands/mws-save-archive.js
3
- type: application/javascript
4
- module-type: command
5
-
6
- Command to load an archive of recipes, bags and tiddlers to a directory
7
-
8
- \*/
9
-
10
- import { writeFileSync } from "fs";
11
- import { Commander, CommandInfo } from "../commander";
12
- import { TiddlerStore } from "../routes/TiddlerStore";
13
- import { resolve } from "path";
14
- import * as _fsp from "fs/promises";
15
- import { createStrictAwaitProxy } from "../utils";
16
- const fsp = createStrictAwaitProxy(_fsp);
17
-
18
- export const info: CommandInfo = {
19
- name: "mws-save-archive",
20
- synchronous: true
21
- };
22
- export class Command {
23
- get $tw() { return this.commander.$tw as { utils: any }; }
24
- get archivePath() { return this.params[0] as string; }
25
- store?: TiddlerStore;
26
- constructor(
27
- public params: string[],
28
- public commander: Commander,
29
- public callback: (err?: any) => void
30
- ) {
31
-
32
- }
33
- async execute() {
34
- // Check parameters
35
- if (this.params.length < 1) throw "Missing pathname";
36
- await this.commander.$transaction(async (prisma) => {
37
- this.store = new TiddlerStore(this.commander, prisma);
38
- await this.saveArchive();
39
- this.store = undefined;
40
- });
41
- console.log(info.name, "complete:", this.params[0])
42
- return null;
43
- }
44
-
45
- async getRecipes() {
46
- return await this.store!.prisma.recipes.findMany({
47
- include: { recipe_bags: true, acl: true },
48
- });
49
- }
50
- async getBags() {
51
- const bags = await this.store!.prisma.bags.findMany({
52
- include: { tiddlers: { include: { fields: true } }, acl: true }
53
- });
54
- return bags.map(e => ({
55
- ...e,
56
- tiddlers: e.tiddlers.map(t => ({
57
- ...t,
58
- fields: Object.fromEntries(t.fields.map(f => [f.field_name, f.field_value]))
59
- }))
60
- }));
61
- }
62
- async getUsers() {
63
- return await this.store!.prisma.users.findMany({ include: { roles: true, sessions: true, groups: true } });
64
- }
65
- async getGroups() {
66
- return await this.store!.prisma.groups.findMany({ include: { roles: true } });
67
- }
68
- async getRoles() {
69
- return await this.store!.prisma.roles.findMany({});
70
- }
71
-
72
- async saveArchive() {
73
- if (!this.store) throw new Error("Store not initialized");
74
- const uriC = encodeURIComponent;
75
- await fsp.mkdir(resolve(this.archivePath, "recipes"), { recursive: true });
76
- const recipes = await this.getRecipes();
77
- for (const recipeInfo of recipes) {
78
- // console.log(`Recipe ${recipeInfo.recipe_name}`);
79
- const recipeFile = `recipes/${uriC(recipeInfo.recipe_name)}.json`;
80
- await fsp.writeFile(resolve(this.archivePath, recipeFile), JSON.stringify(recipeInfo, null, "\t"));
81
- }
82
- await fsp.mkdir(resolve(this.archivePath, "bags"), { recursive: true });
83
- const bags = await this.getBags();
84
- await Promise.all(bags.map(async bagInfo => {
85
- const tiddlersFolder = `bags/${uriC(bagInfo.bag_name)}/tiddlers`;
86
- await fsp.mkdir(resolve(this.archivePath, tiddlersFolder), { recursive: true });
87
- // console.log(`Bag ${bagInfo.bag_name}`);
88
- const bagFile = `bags/${uriC(bagInfo.bag_name)}/meta.json`;
89
- await fsp.writeFile(resolve(this.archivePath, bagFile), JSON.stringify({ ...bagInfo, tiddlers: undefined, }, null, "\t"));
90
- for (const tiddler of bagInfo.tiddlers) {
91
- // console.log(bagInfo.bag_name, tiddler.title, tiddler.tiddler_id);
92
- const tiddlerFile = `bags/${uriC(bagInfo.bag_name)}/tiddlers/${tiddler.tiddler_id}.json`;
93
- await fsp.writeFile(resolve(this.archivePath, tiddlerFile), JSON.stringify(tiddler, null, "\t"));
94
- }
95
- }));
96
- const users = await this.getUsers();
97
- await fsp.writeFile(resolve(this.archivePath, "users.json"), JSON.stringify(users, null, "\t"));
98
- const groups = await this.getGroups();
99
- await fsp.writeFile(resolve(this.archivePath, "groups.json"), JSON.stringify(groups, null, "\t"));
100
- const roles = await this.getRoles();
101
- await fsp.writeFile(resolve(this.archivePath, "roles.json"), JSON.stringify(roles, null, "\t"));
102
-
103
- await fsp.writeFile(resolve(this.archivePath, "index.json"), JSON.stringify({
104
- version: 2,
105
- comment: "The version is an internal identifier for the archive format. It is not the same as the version of TiddlyWiki or MWS.",
106
- }, null, "\t"));
107
- // Version 1:
108
- // is_plugin did not exist. A bag_name starting with $:/ was a plugin.
109
- }
110
-
111
- }
@@ -1,33 +0,0 @@
1
- import { Commander, CommandInfo } from "../commander";
2
- import { TiddlerStore } from "../routes/TiddlerStore";
3
-
4
- export const info: CommandInfo = {
5
- name: "mws-save-tiddler-text",
6
- synchronous: true
7
- };
8
-
9
- export class Command {
10
-
11
- constructor(
12
- public params: string[],
13
- public commander: Commander,
14
- public callback: (err?: any) => void
15
- ) {
16
-
17
- }
18
- async execute() {
19
-
20
- if (this.params.length < 3) throw "Missing parameters";
21
-
22
- var bagName = this.params[0] as PrismaField<"Bags", "bag_name">,
23
- tiddlerTitle = this.params[1] as PrismaField<"Tiddlers", "title">,
24
- tiddlerText = this.params[2] as string;
25
-
26
- await this.commander.$transaction(async (prisma) => {
27
- const store = new TiddlerStore(this.commander, prisma);
28
- await store.saveBagTiddler({ title: tiddlerTitle, text: tiddlerText }, bagName);
29
- });
30
-
31
- }
32
- }
33
-
@@ -1,21 +0,0 @@
1
- import { Commander, CommandInfo } from "../commander";
2
-
3
- export const info: CommandInfo = {
4
- name: "tests-complete",
5
- synchronous: true,
6
- };
7
-
8
-
9
- export class Command {
10
-
11
- constructor(
12
- public params: string[],
13
- public commander: Commander,
14
- ) {
15
- // if (this.params.length) throw `${info.name}: No parameters allowed. This is a no-op command.`;
16
- }
17
- execute() {
18
- console.log("Tests completed successfully.");
19
- process.exit(0);
20
- }
21
- }
package/src/global.ts DELETED
@@ -1,247 +0,0 @@
1
- import type { rootRoute as _rootRoute, Router } from "./routes/router";
2
- import * as path from "path";
3
- import * as fs from "fs";
4
- import type { Prisma } from "@prisma/client";
5
- import type { ZodAssert } from "./utils";
6
- import { Tiddler, Wiki } from "tiddlywiki";
7
- import { Commander } from "./commander";
8
- import { createRequire } from "node:module";
9
- import { dirname, resolve } from "node:path";
10
-
11
-
12
- declare global {
13
- type PrismaTxnClient = Omit<Commander["engine"], "$connect" | "$disconnect" | "$on" | "$transaction" | "$use" | "$extends">
14
- type ART<T extends (...args: any) => any> = Awaited<ReturnType<T>>
15
- /**
16
- * This primarily makes sure that positional arguments are used correctly
17
- * (so you can't switch a title and bag_name around).
18
- *
19
- * If you assign the wrong value (like `5 as PrismaField<"Bags", "bag_name">`),
20
- * this will result in a type error on the as keyword, allowing you to catch incorrect types quickly.
21
- */
22
- type PrismaField<T extends Prisma.ModelName, K extends keyof PrismaPayloadScalars<T>> =
23
- // manually map foriegn keys to their corresponding primary key so comparisons work
24
- // this should remove the need for any global helper functions to convert between types
25
- (
26
- // [T, K] extends ["Acl", "role_id"] ? PrismaField<"Roles", "role_id"> :
27
- // [T, K] extends ["", "role_id"] ? PrismaField<"Roles", "role_id"> :
28
- [T, K] extends ["Tiddlers", "bag_id"] ? PrismaField<"Bags", "bag_id"> :
29
- [T, K] extends ["Sessions", "user_id"] ? PrismaField<"Users", "user_id"> :
30
- [T, K] extends ["Recipe_bags", "bag_id"] ? PrismaField<"Bags", "bag_id"> :
31
- [T, K] extends ["Recipe_bags", "recipe_id"] ? PrismaField<"Recipes", "recipe_id"> :
32
- [T, K] extends ["Recipes", "owner_id"] ? PrismaField<"Users", "user_id"> :
33
- [T, K] extends ["Bags", "owner_id"] ? PrismaField<"Users", "user_id"> :
34
- (PrismaPayloadScalars<T>[K] & { __prisma_table: T, __prisma_field: K })
35
- ) | (null extends PrismaPayloadScalars<T>[K] ? null : never);
36
-
37
- type PrismaPayloadScalars<T extends Prisma.ModelName>
38
- = Prisma.TypeMap["model"][T]["payload"]["scalars"]
39
-
40
- type EntityName<T extends EntityType> =
41
- T extends "bag" ? PrismaField<"Bags", "bag_name"> :
42
- T extends "recipe" ? PrismaField<"Recipes", "recipe_name"> :
43
- never;
44
-
45
- type EntityType = "recipe" | "bag";
46
-
47
- type ACLPermissionName = "READ" | "WRITE" | "ADMIN";
48
-
49
- type rootRoute = _rootRoute;
50
- type ZodAssert = typeof ZodAssert;
51
-
52
- }
53
-
54
-
55
- // declare global { const ok: typeof assert.ok; }
56
- // (global as any).ok = assert.ok;
57
-
58
- // these are some $tw.utils functions that seemed important enough to just copy across
59
- declare global {
60
- function hop(object: any, property: any): boolean;
61
- function each<T>(object: T[], callback: (value: T, index: number, object: T[]) => void): void;
62
- function each<T>(object: Record<string, T>, callback: (value: T, key: string, object: Record<string, T>) => void): void;
63
- function eachAsync<T>(object: T[], callback: (value: T, index: number, object: T[]) => void): Promise<void>;
64
- function eachAsync<T>(object: Record<string, T>, callback: (value: T, key: string, object: Record<string, T>) => void): Promise<void>;
65
- function createDirectory(dirPath: string): void;
66
- function deleteDirectory(dirPath: string): void;
67
- function encodeURIComponentExtended(s: string): string;
68
- }
69
-
70
- (global as any).hop = function (object: any, property: any) {
71
- return object ? Object.prototype.hasOwnProperty.call(object, property) : false;
72
- };
73
-
74
- (global as any).eachAsync = async function (object: any, callback: any) {
75
- var next, f, length;
76
- if (object) {
77
- if (Object.prototype.toString.call(object) == "[object Array]") {
78
- for (f = 0, length = object.length; f < length; f++) {
79
- next = await callback(object[f], f, object);
80
- if (next === false) {
81
- break;
82
- }
83
- }
84
- } else {
85
- var keys = Object.keys(object);
86
- for (f = 0, length = keys.length; f < length; f++) {
87
- var key = keys[f];
88
- next = await callback(object[key as string], key, object);
89
- if (next === false) {
90
- break;
91
- }
92
- }
93
- }
94
- }
95
- };
96
-
97
- (global as any).each = function (object: any, callback: any) {
98
- var next, f, length;
99
- if (object) {
100
- if (Object.prototype.toString.call(object) == "[object Array]") {
101
- for (f = 0, length = object.length; f < length; f++) {
102
- next = callback(object[f], f, object);
103
- if (next === false) {
104
- break;
105
- }
106
- }
107
- } else {
108
- var keys = Object.keys(object);
109
- for (f = 0, length = keys.length; f < length; f++) {
110
- var key = keys[f];
111
- next = callback(object[key as string], key, object);
112
- if (next === false) {
113
- break;
114
- }
115
- }
116
- }
117
- }
118
- };
119
-
120
- (global as any).createDirectory = function (dirPath: string) {
121
- if (dirPath.substr(dirPath.length - 1, 1) !== path.sep) {
122
- dirPath = dirPath + path.sep;
123
- }
124
- var pos = 1;
125
- pos = dirPath.indexOf(path.sep, pos);
126
- while (pos !== -1) {
127
- var subDirPath = dirPath.substr(0, pos);
128
- if (!(fs.existsSync(subDirPath) && fs.statSync(subDirPath).isDirectory())) {
129
- try {
130
- fs.mkdirSync(subDirPath);
131
- } catch (e) {
132
- return "Error creating directory '" + subDirPath + "'";
133
- }
134
- }
135
- pos = dirPath.indexOf(path.sep, pos + 1);
136
- }
137
- return null;
138
- };
139
-
140
- (global as any).deleteDirectory = function deleteDirectory(dirPath: string) {
141
- if (fs.existsSync(dirPath)) {
142
- var entries = fs.readdirSync(dirPath);
143
- for (var entryIndex = 0; entryIndex < entries.length; entryIndex++) {
144
- var currPath = dirPath + path.sep + entries[entryIndex];
145
- if (fs.lstatSync(currPath).isDirectory()) {
146
- deleteDirectory(currPath);
147
- } else {
148
- fs.unlinkSync(currPath);
149
- }
150
- }
151
- fs.rmdirSync(dirPath);
152
- }
153
- return null;
154
- };
155
-
156
- (global as any).encodeURIComponentExtended = function (s: string) {
157
- return encodeURIComponent(s).replace(/[!'()*]/g, function (c) {
158
- return "%" + c.charCodeAt(0).toString(16).toUpperCase();
159
- });
160
- };
161
-
162
-
163
- class _Result<OK extends boolean, T> {
164
- constructor(
165
- public ok: OK,
166
- public error: OK extends true ? undefined : unknown,
167
- public value: OK extends true ? T : undefined
168
- ) { }
169
- get [Symbol.iterator]() { return [this.ok, this.error, this.value] }
170
- static ok<T>(value: T) {
171
- return new _Result(true, undefined, value)
172
- }
173
- static error(error: unknown) {
174
- return new _Result(false, error, undefined)
175
- }
176
-
177
- /**
178
- * @example
179
- * // const result = try something();
180
- * const result = Result.try_(() => {
181
- * something();
182
- * });
183
- */
184
- static try_<T, This>(callback: (this: This) => T, thisarg: This) {
185
- try {
186
- return _Result.ok(callback.apply(thisarg));
187
- } catch (e) {
188
- return _Result.error(e);
189
- }
190
- }
191
-
192
- }
193
- //https://github.com/arthurfiorette/proposal-try-operator
194
- declare global {
195
- const TryResult: typeof _Result;
196
- interface Promise<T> {
197
- try: () => Promise<_Result<true, T> | _Result<false, T>>;
198
- }
199
- }
200
- (global as any).Result = _Result;
201
- Promise.prototype.try = function <T>(this: Promise<T>) {
202
- return this.then(_Result.ok, _Result.error);
203
- }
204
-
205
- interface $TW {
206
- loadTiddlersFromPath: any;
207
- loadPluginFolder: any;
208
- getLibraryItemSearchPaths: any;
209
- wiki: never;
210
- utils: {
211
- // [x: string]: any;
212
- /** Use Object.assign instead */
213
- extend: never
214
- /** Use Array.isArray instead */
215
- isArray: never
216
- /** use prismaField with a parse- option or z.uriComponent if possible */
217
- decodeURIComponentSafe: never;
218
- /**
219
- *
220
- ```js
221
- $tw.utils.stringifyDate = function(value) {
222
- return value.getUTCFullYear() +
223
- $tw.utils.pad(value.getUTCMonth() + 1) +
224
- $tw.utils.pad(value.getUTCDate()) +
225
- $tw.utils.pad(value.getUTCHours()) +
226
- $tw.utils.pad(value.getUTCMinutes()) +
227
- $tw.utils.pad(value.getUTCSeconds()) +
228
- $tw.utils.pad(value.getUTCMilliseconds(),3);
229
- };
230
- ```
231
- */
232
- stringifyDate: never;
233
- // parseJSONSafe(str: string, defaultJSON?: any): any;
234
- // /** `return parseFloat(str) || 0;` */
235
- // parseNumber(string: string): number;
236
- // /** `return parseFloat(str) || 0;` */
237
- // parseNumber(string: string | null): number;
238
- };
239
- boot: any;
240
- config: any;
241
- node: any;
242
- hooks: any;
243
- sjcl: any;
244
- Wiki: { new(): Wiki };
245
- Tiddler: { new(fields: Record<string, any>): Tiddler };
246
-
247
- }