@tiddlywiki/mws 0.0.21 → 0.1.1

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 (202) hide show
  1. package/README.md +42 -9
  2. package/dist/metafile-esm.json +1 -0
  3. package/dist/mws.d.ts +1 -0
  4. package/dist/mws.js +34710 -0
  5. package/dist/mws.js.map +1 -0
  6. package/editions/mws-docs/tiddlers/$__StoryList.tid +1 -2
  7. package/editions/mws-docs/tiddlers/2025-02-18 - User Management.md.meta +2 -2
  8. package/editions/mws-docs/tiddlers/2025-04-14 - client plugins /342/234/224/357/270/217.md" +31 -0
  9. package/editions/mws-docs/tiddlers/2025-04-14 - client plugins /342/234/224/357/270/217.md.meta" +5 -0
  10. package/editions/mws-docs/tiddlers/{2025-05-04.md → 2025-05-04 - event hooks /342/234/224/357/270/217.md" } +7 -1
  11. package/editions/mws-docs/tiddlers/2025-05-04 - event hooks /342/234/224/357/270/217.md.meta" +5 -0
  12. package/editions/mws-docs/tiddlers/{2025-05-06.md → 2025-05-06 - syncer design.md } +0 -4
  13. package/editions/mws-docs/tiddlers/2025-05-06 - syncer design.md.meta +5 -0
  14. package/editions/mws-docs/tiddlers/Allowed Methods.tid +8 -0
  15. package/editions/mws-docs/tiddlers/Application Access & Security.md +14 -84
  16. package/editions/mws-docs/tiddlers/Application Access & Security.md.meta +1 -1
  17. package/editions/mws-docs/tiddlers/Body Format.md +19 -0
  18. package/editions/mws-docs/tiddlers/Body Format.md.meta +4 -0
  19. package/editions/mws-docs/tiddlers/Checklists and Features.md +0 -3
  20. package/editions/mws-docs/tiddlers/Checklists and Features.md.meta +1 -1
  21. package/editions/mws-docs/tiddlers/Client Plugins.md +17 -0
  22. package/editions/mws-docs/tiddlers/Client Plugins.md.meta +5 -0
  23. package/editions/mws-docs/tiddlers/HTTP API.md +4 -3
  24. package/editions/mws-docs/tiddlers/HTTP API.md.meta +1 -1
  25. package/editions/mws-docs/tiddlers/HelloThere.tid +2 -2
  26. package/editions/mws-docs/tiddlers/Installation.tid +2 -3
  27. package/editions/mws-docs/tiddlers/MWS Architecture.tid +6 -1
  28. package/editions/mws-docs/tiddlers/Multi-user Trust.md +12 -0
  29. package/editions/mws-docs/tiddlers/Multi-user Trust.md.meta +5 -0
  30. package/editions/mws-docs/tiddlers/Notes.tid +5 -3
  31. package/editions/mws-docs/tiddlers/Oracle Attacks.md +29 -0
  32. package/editions/mws-docs/tiddlers/Oracle Attacks.md.meta +5 -0
  33. package/editions/mws-docs/tiddlers/Reference.md +1 -0
  34. package/editions/mws-docs/tiddlers/Reference.md.meta +1 -1
  35. package/editions/mws-docs/tiddlers/Request Handling.md +53 -0
  36. package/editions/mws-docs/tiddlers/Request Handling.md.meta +5 -0
  37. package/editions/mws-docs/tiddlers/Roadmap.tid +7 -0
  38. package/editions/mws-docs/tiddlers/Route Definers.md +206 -0
  39. package/editions/mws-docs/tiddlers/Route Definers.md.meta +5 -0
  40. package/editions/mws-docs/tiddlers/Security.md +75 -0
  41. package/editions/mws-docs/tiddlers/Security.md.meta +5 -0
  42. package/editions/mws-docs/tiddlers/Server Plugins.md +7 -0
  43. package/editions/mws-docs/tiddlers/Server Plugins.md.meta +5 -0
  44. package/editions/mws-docs/tiddlers/Startup Cache.md +28 -0
  45. package/editions/mws-docs/tiddlers/Startup Cache.md.meta +5 -0
  46. package/editions/mws-docs/tiddlers/TiddlerFields.md +5 -0
  47. package/editions/mws-docs/tiddlers/TiddlerFields.md.meta +4 -0
  48. package/editions/mws-docs/tiddlers/Usage.tid +2 -2
  49. package/editions/mws-docs/tiddlers/system/$__mws_cssvar-macro.tid +10 -0
  50. package/editions/mws-docs/tiddlers/system/$__palettes_MUI +143 -0
  51. package/editions/mws-docs/tiddlers/system/$__palettes_MUI.meta +7 -0
  52. package/editions/mws-docs/tiddlers/system/$__palettes_MUI_styles.css +567 -0
  53. package/editions/mws-docs/tiddlers/system/$__palettes_MUI_styles.css.meta +6 -0
  54. package/editions/mws-docs/tiddlers/system/$__theme.tid +6 -0
  55. package/editions/mws-docs/tiddlers/system/SplashScreen.tid +21 -0
  56. package/editions/mws-docs/tiddlers/system/StaticBanner.tid +1 -1
  57. package/editions/mws-docs/tiddlers/system/Styles.tid +13 -0
  58. package/editions/mws-docs/tiddlers/system/palette.tid +4 -1
  59. package/editions/mws-docs/tiddlers/system/sidebarlayout.tid +4 -1
  60. package/editions/mws-docs/tiddlers/x-mws-tiddler.md +35 -0
  61. package/editions/mws-docs/tiddlers/x-mws-tiddler.md.meta +5 -0
  62. package/mws.run.mjs +30 -0
  63. package/package.json +47 -36
  64. package/plugins/client/package-lock.json +46 -83
  65. package/plugins/client/package.json +1 -6
  66. package/plugins/client/plugin.info +2 -2
  67. package/plugins/client/src/fflate.d.ts +1501 -0
  68. package/plugins/client/src/multiwikiclientadaptor.ts +768 -317
  69. package/plugins/client/src/mws.d.ts +4 -0
  70. package/plugins/client/src/types.d.ts +3928 -0
  71. package/plugins/client/tiddlers/en-US.multids +3 -0
  72. package/plugins/client/tiddlers/status/SaveWikiButtonTemplate.tid +3 -0
  73. package/plugins/client/tiddlers/status/icon-cloud.tid +4 -0
  74. package/plugins/client/tiddlers/status/info-segment.tid +8 -0
  75. package/plugins/client/tiddlers/status/readonly-styles.tid +27 -0
  76. package/plugins/client/tiddlers/status/save-offline.tid +7 -0
  77. package/plugins/client/tiddlers/status/save-wiki-button.tid +26 -0
  78. package/plugins/client/tiddlers/status/styles.tid +44 -0
  79. package/plugins/client/tiddlers/status/syncer-actions-copy-logs.tid +6 -0
  80. package/plugins/client/tiddlers/status/syncer-actions-login-status.tid +9 -0
  81. package/plugins/client/tiddlers/status/syncer-actions-login.tid +8 -0
  82. package/plugins/client/tiddlers/status/syncer-actions-logout.tid +8 -0
  83. package/plugins/client/tiddlers/status/syncer-actions-refresh.tid +9 -0
  84. package/plugins/client/tiddlers/status/syncer-actions-save-snapshot.tid +9 -0
  85. package/plugins/client/tiddlers/status/tags-syncerdropdown.tid +2 -0
  86. package/plugins/client/tiddlers/syncer/multiwikiclientadaptor.js +640 -0
  87. package/plugins/client/tiddlers/syncer/syncer.js +831 -0
  88. package/plugins/client/tsconfig.json +19 -16
  89. package/plugins/filter-ast-to-sql/example-run-series.ts +146 -0
  90. package/plugins/server/SplashScreen.tid +150 -0
  91. package/plugins/server/fflate.js +9 -0
  92. package/plugins/server/plugin.info +8 -0
  93. package/plugins/server/readme +1 -0
  94. package/plugins/server/url-polyfill.js +294 -0
  95. package/prisma/client/client.d.ts +1 -0
  96. package/prisma/client/client.js +3 -0
  97. package/prisma/client/default.d.ts +1 -0
  98. package/prisma/client/default.js +3 -0
  99. package/prisma/client/edge.d.ts +1 -0
  100. package/prisma/client/edge.js +297 -0
  101. package/prisma/client/index-browser.js +275 -0
  102. package/prisma/client/index.d.ts +17770 -0
  103. package/prisma/client/index.js +324 -0
  104. package/prisma/client/package.json +173 -0
  105. package/prisma/client/query_engine_bg.js +811 -0
  106. package/prisma/client/query_engine_bg.wasm +0 -0
  107. package/prisma/client/runtime/edge-esm.js +10000 -0
  108. package/prisma/client/runtime/edge.js +10036 -0
  109. package/prisma/client/runtime/index-browser.d.ts +370 -0
  110. package/prisma/client/runtime/index-browser.js +2300 -0
  111. package/prisma/client/runtime/library.d.ts +3681 -0
  112. package/prisma/client/runtime/library.js +10604 -0
  113. package/prisma/client/runtime/react-native.js +10629 -0
  114. package/prisma/client/runtime/wasm-compiler-edge.js +11238 -0
  115. package/prisma/client/runtime/wasm-engine-edge.js +7801 -0
  116. package/prisma/client/schema.prisma +156 -0
  117. package/prisma/client/wasm-edge-light-loader.mjs +4 -0
  118. package/prisma/client/wasm-worker-loader.mjs +4 -0
  119. package/prisma/client/wasm.d.ts +1 -0
  120. package/prisma/client/wasm.js +304 -0
  121. package/prisma/global.ts +53 -0
  122. package/prisma/migrations/{20250406213424_init → 20250606001949_init}/migration.sql +46 -48
  123. package/prisma/migrations/20250613000526_remove_group/migration.sql +22 -0
  124. package/prisma/migrations/20250620014502_settings/migration.sql +5 -0
  125. package/prisma/migrations/20250707205229_recipes/migration.sql +20 -0
  126. package/prisma/migrations/migration_lock.toml +1 -1
  127. package/prisma/notes.md +1 -2
  128. package/prisma/schema.prisma +52 -49
  129. package/prisma/test.sqlite +0 -0
  130. package/prisma/test.sqlite-journal +0 -0
  131. package/public/react-admin/android-chrome-192x192.png +0 -0
  132. package/public/react-admin/android-chrome-512x512.png +0 -0
  133. package/public/react-admin/apple-touch-icon.png +0 -0
  134. package/{react-user-mgmt/public/esm-QKDFEP3B.js → public/react-admin/esm-L4WLVWJN.js} +1 -1
  135. package/public/react-admin/esm-L4WLVWJN.js.map +7 -0
  136. package/public/react-admin/esm-QMNGI3LF.js +3 -0
  137. package/public/react-admin/favicon-16x16.png +0 -0
  138. package/public/react-admin/favicon-32x32.png +0 -0
  139. package/public/react-admin/favicon.ico +0 -0
  140. package/public/react-admin/index.html +36 -0
  141. package/public/react-admin/main.js +268 -0
  142. package/public/react-admin/main.js.map +7 -0
  143. package/public/react-admin/site.webmanifest +20 -0
  144. package/public/react-admin/stats.json +1 -0
  145. package/scripts.mjs +134 -25
  146. package/dist/server.d.ts +0 -945
  147. package/dist/server.js +0 -20775
  148. package/dist/server.js.map +0 -1
  149. package/editions/mws-docs/tiddlers/2025-04-03 - Phases of Development.md +0 -64
  150. package/editions/mws-docs/tiddlers/2025-04-03 - Phases of Development.md.meta +0 -5
  151. package/editions/mws-docs/tiddlers/2025-04-13 - Plugins.md +0 -18
  152. package/editions/mws-docs/tiddlers/2025-04-13 - Plugins.md.meta +0 -5
  153. package/editions/mws-docs/tiddlers/2025-05-04.md.meta +0 -5
  154. package/editions/mws-docs/tiddlers/2025-05-06.md.meta +0 -5
  155. package/editions/mws-docs/tiddlers/Moduler Design.md +0 -29
  156. package/editions/mws-docs/tiddlers/Moduler Design.md.meta +0 -5
  157. package/editions/mws-docs/tiddlers/Request Server.md +0 -20
  158. package/editions/mws-docs/tiddlers/Request Server.md.meta +0 -5
  159. package/editions/mws-docs/tiddlers/system/$__palettes_MUI-Dark +0 -173
  160. package/editions/mws-docs/tiddlers/system/$__palettes_MUI-Dark.meta +0 -6
  161. package/editions/mws-docs/tiddlers/system/$__palettes_MUI-Light +0 -172
  162. package/editions/mws-docs/tiddlers/system/$__palettes_MUI-Light.meta +0 -6
  163. package/plugins/client/tiddlers/config-tiddlers-filter.tid +0 -2
  164. package/plugins/client/tiddlers/config-use-server-sent-events.tid +0 -2
  165. package/plugins/client/tiddlers/info-segment.tid +0 -8
  166. package/plugins/client/tiddlers/multiwikiclientadaptor.js +0 -444
  167. package/prisma/migrations/20250407002306_disconnect_user_tables/migration.sql +0 -52
  168. package/prisma/old-db.sql +0 -144
  169. package/react-user-mgmt/README.md +0 -50
  170. package/react-user-mgmt/eslint.config.js +0 -28
  171. package/react-user-mgmt/package-lock.json +0 -2738
  172. package/react-user-mgmt/package.json +0 -31
  173. package/react-user-mgmt/public/index.html +0 -1
  174. package/react-user-mgmt/public/main.js +0 -295
  175. package/react-user-mgmt/public/main.js.map +0 -7
  176. package/react-user-mgmt/public/stats.json +0 -1
  177. package/react-user-mgmt/tsconfig.json +0 -40
  178. package/react-user-mgmt/types.d.ts +0 -2
  179. package/tiddlywiki-types/boot/boot.d.ts +0 -378
  180. package/tiddlywiki-types/boot/bootprefix.d.ts +0 -110
  181. package/tiddlywiki-types/core/modules/filters.d.ts +0 -107
  182. package/tiddlywiki-types/core/modules/tiddler.d.ts +0 -47
  183. package/tiddlywiki-types/core/modules/wiki-bulkops.d.ts +0 -36
  184. package/tiddlywiki-types/core/modules/wiki.d.ts +0 -208
  185. package/tiddlywiki-types/index.d.ts +0 -7
  186. package/tiddlywiki-types/package.json +0 -3
  187. /package/plugins/client/tiddlers/{sidebarsegment.tid → status/sidebarsegment.tid} +0 -0
  188. /package/plugins/client/tiddlers/{GettingStarted.tid → syncer/GettingStarted.tid} +0 -0
  189. /package/plugins/client/tiddlers/{config-incoming-updates-filter.tid → syncer/config-incoming-updates-filter.tid} +0 -0
  190. /package/plugins/client/tiddlers/{readme.tid → syncer/readme.tid} +0 -0
  191. /package/{react-user-mgmt/public → public/react-admin}/chunk-YALWN5OT.js +0 -0
  192. /package/{react-user-mgmt/public → public/react-admin}/chunk-YALWN5OT.js.map +0 -0
  193. /package/{react-user-mgmt/public/esm-QKDFEP3B.js.map → public/react-admin/esm-QMNGI3LF.js.map} +0 -0
  194. /package/{react-user-mgmt/public → public/react-admin}/favicon.png +0 -0
  195. /package/{react-user-mgmt/public → public/react-admin}/missing-favicon.png +0 -0
  196. /package/{react-user-mgmt/public → public/react-admin}/motovun-jack.jpg +0 -0
  197. /package/{react-user-mgmt/public → public/react-admin}/mws-icon.png +0 -0
  198. /package/{react-user-mgmt/public → public/react-admin}/stats.css +0 -0
  199. /package/{react-user-mgmt/public → public/react-admin}/stats.html +0 -0
  200. /package/{react-user-mgmt/public → public/react-admin}/stats.js +0 -0
  201. /package/{react-user-mgmt/public → public/react-admin}/stats.svg +0 -0
  202. /package/{react-user-mgmt/public → public/react-admin}/vite.svg +0 -0
package/dist/server.d.ts DELETED
@@ -1,945 +0,0 @@
1
- import * as http from 'http';
2
- import { Server, IncomingMessage, ServerResponse } from 'http';
3
- import { Readable } from 'stream';
4
- import { PassThrough, Writable } from 'node:stream';
5
- import * as z from 'zod';
6
- import { z as z$1, ZodEffects } from 'zod';
7
- import { PrismaClient, Prisma } from '@prisma/client';
8
- import * as fs from 'fs';
9
- import * as tiddlywiki from 'tiddlywiki';
10
- import { TW, TiddlerFieldModule } from 'tiddlywiki';
11
- import { ITXClientDenyList, Types } from '@prisma/client/runtime/library';
12
- import * as commander from 'commander';
13
- import { SqlMigrationAwareDriverAdapterFactory, SqlDriverAdapter } from '@prisma/driver-adapter-utils';
14
- import * as http2 from 'node:http2';
15
- import * as http2$1 from 'http2';
16
- import { OutgoingHttpHeaders, IncomingHttpHeaders as IncomingHttpHeaders$1, IncomingMessage as IncomingMessage$1, ServerResponse as ServerResponse$1 } from 'node:http';
17
-
18
- interface AuthUser {
19
- /** User ID. 0 if the user is not logged in. */
20
- user_id: PrismaField<"Users", "user_id">;
21
- /** User role_ids. This may have length even if the user isn't logged in, to allow ACL for anon. */
22
- role_ids: PrismaField<"Roles", "role_id">[];
23
- /** Username passed to the client */
24
- username: PrismaField<"Users", "username">;
25
- /** A session_id isn't guarenteed. There may be a session even if the user isn't logged in, and may not be even if they are, depending on the the situation. */
26
- sessionId: PrismaField<"Sessions", "session_id"> | undefined;
27
- /** Is this user considered a site-admin. This is determined by the auth service, not MWS. */
28
- isAdmin: boolean;
29
- /** Is the user logged in? This also means that user_id should be 0. role_ids may still be specified. */
30
- isLoggedIn: boolean;
31
- }
32
- declare const SessionKeyMap: RouterKeyMap<SessionManager, true>;
33
- /**
34
- *
35
- * @param path path starting with a forward slash
36
- * @param zodRequest the zod for state.data
37
- * @param inner the handler to call
38
- * @returns the ZodRoute
39
- */
40
- declare function zodSession<P extends string, T extends z$1.ZodTypeAny, R extends JsonValue>(path: P, zodRequest: (z: Z2<"JSON">) => T, inner: (state: ZodState<"POST", "json", Record<string, z$1.ZodTypeAny>, T>, prisma: PrismaTxnClient) => Promise<R>): ZodSessionRoute<P, T, R>;
41
- interface ZodSessionRoute<P extends string, T extends z$1.ZodTypeAny, R extends JsonValue> extends ZodAction<T, R> {
42
- path: P;
43
- inner: (state: ZodState<"POST", "json", {}, T>) => Promise<R>;
44
- }
45
- type RouterPathRouteMap<T> = {
46
- [K in keyof T as T[K] extends ZodSessionRoute<any, any, any> ? K : never]: T[K] extends {
47
- path: infer P;
48
- zodRequest: (z: any) => infer REQ extends z$1.ZodTypeAny;
49
- zodResponse?: (z: any) => infer RES extends z$1.ZodType<JsonValue>;
50
- } ? {
51
- (data: z$1.input<REQ>): Promise<jsonify<z$1.output<RES>>>;
52
- path: P;
53
- key: K;
54
- } : never;
55
- };
56
- type SessionManagerMap = RouterPathRouteMap<SessionManager>;
57
- declare class SessionManager {
58
- static defineRoutes(root: rootRoute): Promise<void>;
59
- static parseIncomingRequest(streamer: Streamer, router: Router): Promise<AuthUser>;
60
- login1: ZodSessionRoute<"/login/1", z$1.ZodObject<{
61
- username: z$1.ZodEffects<any, string & {
62
- __prisma_table: "Users";
63
- __prisma_field: "username";
64
- }, string>;
65
- startLoginRequest: z$1.ZodString;
66
- }, "strip", z$1.ZodTypeAny, {
67
- username: string & {
68
- __prisma_table: "Users";
69
- __prisma_field: "username";
70
- };
71
- startLoginRequest: string;
72
- }, {
73
- username: string;
74
- startLoginRequest: string;
75
- }>, {
76
- loginResponse: string;
77
- loginSession: string;
78
- }>;
79
- login2: ZodSessionRoute<"/login/2", z$1.ZodObject<{
80
- finishLoginRequest: z$1.ZodString;
81
- loginSession: z$1.ZodString;
82
- skipCookie: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodBoolean>>;
83
- }, "strip", z$1.ZodTypeAny, {
84
- loginSession: string;
85
- finishLoginRequest: string;
86
- skipCookie: boolean;
87
- }, {
88
- loginSession: string;
89
- finishLoginRequest: string;
90
- skipCookie?: boolean | undefined;
91
- }>, {
92
- user_id: number & {
93
- __prisma_table: "Users";
94
- __prisma_field: "user_id";
95
- };
96
- session_id: string & {
97
- __prisma_table: "Sessions";
98
- __prisma_field: "session_id";
99
- };
100
- }>;
101
- logout: ZodSessionRoute<"/logout", z$1.ZodOptional<z$1.ZodObject<{
102
- session_id: z$1.ZodString;
103
- signature: z$1.ZodString;
104
- skipCookie: z$1.ZodEffects<z$1.ZodBoolean, boolean, boolean>;
105
- }, "strip", z$1.ZodTypeAny, {
106
- session_id: string;
107
- skipCookie: boolean;
108
- signature: string;
109
- }, {
110
- session_id: string;
111
- skipCookie: boolean;
112
- signature: string;
113
- }>>, null>;
114
- }
115
- declare function assertSignature({ session_id, signature, session_key }: {
116
- session_id: string;
117
- signature: string;
118
- session_key: string;
119
- }): void;
120
-
121
- declare function setupDevServer<T extends StateObject>(enableDevServer: boolean, pathPrefix: string): Promise<(state: T) => Promise<symbol>>;
122
-
123
- interface TiddlerFields extends Record<string, any> {
124
- title: PrismaField<"Tiddlers", "title">;
125
- }
126
- declare class AttachmentService {
127
- protected config: SiteConfig;
128
- protected prisma: PrismaTxnClient;
129
- constructor(config: SiteConfig, prisma: PrismaTxnClient);
130
- makeCanonicalUri(bag_name: string, title: string): string;
131
- processOutgoingTiddler({ tiddler, tiddler_id, bag_name, attachment_hash }: {
132
- tiddler: TiddlerFields;
133
- tiddler_id: any;
134
- bag_name: PrismaField<"Bags", "bag_name">;
135
- attachment_hash: PrismaField<"Tiddlers", "attachment_hash">;
136
- }): TiddlerFields;
137
- processIncomingTiddler({ tiddlerFields, existing_attachment_hash, existing_canonical_uri }: {
138
- tiddlerFields: TiddlerFields;
139
- existing_attachment_hash: PrismaField<"Tiddlers", "attachment_hash">;
140
- existing_canonical_uri: any;
141
- }): Promise<{
142
- tiddlerFields: TiddlerFields;
143
- attachment_hash: PrismaField<"Tiddlers", "attachment_hash">;
144
- }>;
145
- isValidAttachmentName(content_hash: string): boolean;
146
- saveAttachment(options: {
147
- text: string;
148
- type: string;
149
- reference: string;
150
- _canonical_uri: string;
151
- }): Promise<PrismaField<"Tiddlers", "attachment_hash">>;
152
- private writeMetaFile;
153
- adoptAttachment({ incomingFilepath, type, hash, _canonical_uri }: {
154
- incomingFilepath: any;
155
- type: string | number;
156
- hash: any;
157
- _canonical_uri: any;
158
- }): Promise<any>;
159
- getAttachmentStream(content_hash: string): Promise<{
160
- stream: fs.ReadStream;
161
- type: any;
162
- } | null>;
163
- getAttachmentFileSize(content_hash: PrismaField<"Tiddlers", "attachment_hash"> & {}): Promise<number | null>;
164
- getAttachmentMetadata(content_hash: PrismaField<"Tiddlers", "attachment_hash"> & {}): Promise<any>;
165
- }
166
-
167
- type PasswordService = Awaited<ReturnType<typeof createPasswordService>>;
168
- declare function createPasswordService(serverSetup: string): Promise<{
169
- serverState: Map<string, TypedGenerator<LoginGeneratorStates>>;
170
- LoginGenerator: (args_0: {
171
- user_id: PrismaField<"Users", "user_id">;
172
- startLoginRequest: string;
173
- registrationRecord: string;
174
- }) => TypedGenerator<LoginGeneratorStates>;
175
- PasswordCreation: (userID: string, password: string) => Promise<string & {
176
- __prisma_table: "Users";
177
- __prisma_field: "password";
178
- }>;
179
- createRegistrationResponse: ({ userID, registrationRequest }: {
180
- userID: PrismaField<"Users", "user_id">;
181
- registrationRequest: string;
182
- }) => Promise<string>;
183
- startLoginSession: (stater: TypedGenerator<LoginGeneratorStates>) => Promise<string>;
184
- finishLoginSession: (loginSession: string) => Promise<TypedGenerator<LoginGeneratorStates> | undefined>;
185
- }>;
186
- type LoginGeneratorStates = [
187
- [
188
- void,
189
- loginResponse: string
190
- ],
191
- [
192
- finishLoginRequest: string,
193
- {
194
- user_id: PrismaField<"Users", "user_id">;
195
- session: {
196
- sessionKey: string;
197
- } | undefined;
198
- }
199
- ]
200
- ];
201
-
202
- declare class ListenerBase {
203
- server: http2.Http2SecureServer | Server;
204
- router: Router;
205
- bindInfo: string;
206
- constructor(server: http2.Http2SecureServer | Server, router: Router, bindInfo: string);
207
- handleRequest(req: IncomingMessage | http2.Http2ServerRequest, res: ServerResponse | http2.Http2ServerResponse): void;
208
- }
209
- declare class Command {
210
- params: string[];
211
- commander: Commander;
212
- execute: () => Promise<void>;
213
- get $tw(): tiddlywiki.TW;
214
- constructor(params: string[], commander: Commander, listenConfig: MWSConfig["listeners"], onListenersCreated: MWSConfig["onListenersCreated"]);
215
- }
216
-
217
- declare class SqliteAdapter {
218
- private databasePath;
219
- constructor(databasePath: string);
220
- adapter: SqlMigrationAwareDriverAdapterFactory;
221
- init(): Promise<void>;
222
- createMigrationsTable(libsql: SqlDriverAdapter): Promise<void>;
223
- checkMigrationsTable(libsql: SqlDriverAdapter, migrateExisting: boolean): Promise<void>;
224
- }
225
-
226
- declare class StartupCommander {
227
- config: MWSConfig;
228
- $tw: TW;
229
- PasswordService: PasswordService;
230
- fieldModules: Record<string, TiddlerFieldModule>;
231
- versions: {
232
- tiddlywiki: any;
233
- mws: string;
234
- };
235
- constructor(config: MWSConfig, $tw: TW, PasswordService: PasswordService);
236
- init(): Promise<void>;
237
- wikiPath: string;
238
- storePath: string;
239
- databasePath: string;
240
- cachePath: string;
241
- adapter: SqliteAdapter;
242
- engine: PrismaClient<Prisma.PrismaClientOptions, never, {
243
- result: {
244
- [T in Uncapitalize<Prisma.ModelName>]: {
245
- [K in keyof PrismaPayloadScalars<Capitalize<T>>]: () => {
246
- compute: () => PrismaField<Capitalize<T>, K>;
247
- };
248
- };
249
- };
250
- client: {};
251
- model: {};
252
- query: {};
253
- }>;
254
- $transaction<R>(fn: (prisma: Omit<Commander["engine"], ITXClientDenyList>) => Promise<R>, options?: {
255
- maxWait?: number;
256
- timeout?: number;
257
- isolationLevel?: Prisma.TransactionIsolationLevel;
258
- }): Promise<R>;
259
- siteConfig: SiteConfig;
260
- SessionManager: typeof SessionManager;
261
- AttachmentService: typeof AttachmentService;
262
- /** Signals that database setup is required. May be set to false by any qualified setup command. */
263
- setupRequired: boolean;
264
- outputPath: string;
265
- }
266
- /**
267
- Parse a sequence of commands
268
- commandTokens: an array of command string tokens
269
- wiki: reference to the wiki store object
270
- streams: {output:, error:}, each of which has a write(string) method
271
- callback: a callback invoked as callback(err) where err is null if there was no error
272
- */
273
- declare class Commander extends StartupCommander {
274
- constructor(config: MWSConfig, $tw: TW, PasswordService: PasswordService);
275
- program: commander.Command;
276
- init(): Promise<void>;
277
- create_mws_listen: (params: string[]) => Command;
278
- /**
279
- * The promise of the current execution.
280
- * It is created and returned by execute,
281
- * but also accessible here.
282
- *
283
- * After the promise is resolved, it will
284
- * be available until execute is called again.
285
- */
286
- promise: Promise<void>;
287
- private callback;
288
- commandTokens: string[];
289
- nextToken: number;
290
- verbose: boolean;
291
- static initCommands(moduleType?: string): void;
292
- addCommandTokens(params: string[]): void;
293
- execute(commandTokens: string[]): Promise<void>;
294
- executeInternal(commandTokens: string[]): Promise<void>;
295
- setPromise(): void;
296
- executeNextCommand(): void;
297
- extractNamedParameters(params: string[], mandatoryParameters?: string[]): any;
298
- }
299
-
300
- declare class StateObject<B extends BodyFormat = BodyFormat, M extends AllowedMethod = AllowedMethod, RoutePathParams extends string[][] = string[][], D = unknown> extends StreamerState {
301
- /** The array of Route tree nodes the request matched. */
302
- private routePath;
303
- /** The bodyformat that ended up taking precedence. This should be correctly typed. */
304
- bodyFormat: B;
305
- user: AuthUser;
306
- router: Router;
307
- tiddlerCache: Router["tiddlerCache"];
308
- z: typeof z;
309
- STREAM_ENDED: typeof STREAM_ENDED;
310
- get method(): M;
311
- readMultipartData: (options: {
312
- cbPartStart: (headers: http.IncomingHttpHeaders, name: string | null, filename: string | null) => void;
313
- cbPartChunk: (chunk: Buffer) => void;
314
- cbPartEnd: () => void;
315
- cbFinished: (err: Error | string | null) => void;
316
- }) => Promise<void>;
317
- sendResponse: (statusCode: number, headers: http.OutgoingHttpHeaders, data: string | Buffer<ArrayBufferLike>, encoding?: BufferEncoding | undefined) => Promise<symbol>;
318
- /** This is set in makeRouter */
319
- sendDevServer: () => ReturnType<Awaited<ReturnType<typeof setupDevServer>>>;
320
- data: B extends "string" ? string : B extends "buffer" ? Buffer : B extends "www-form-urlencoded-urlsearchparams" ? URLSearchParams : B extends "stream" ? Readable : B extends "ignore" ? undefined : D;
321
- /**
322
- * an *object from entries* of all the pathParams in the tree mapped to the path regex matches from that route.
323
- *
324
- * Object.fromEntries takes the last value if there are duplicates, so conflicting names will have the last value in the path.
325
- *
326
- * Conflicting names would be defined on the route definitions, so just change the name there if there is a conflict.
327
- */
328
- pathParams: Record<RoutePathParams extends (infer X extends string)[][] ? X : never, string | undefined>;
329
- /**
330
- * The query params. Because these aren't checked anywhere,
331
- * the value includes undefined since it will be that if
332
- * the key is not specified at all.
333
- *
334
- * This will always satisfy the zod schema: `z.record(z.array(z.string()))`
335
- */
336
- queryParams: Record<string, string[] | undefined>;
337
- private engine;
338
- config: SiteConfig;
339
- PasswordService: PasswordService;
340
- get pathPrefix(): string;
341
- constructor(streamer: Streamer,
342
- /** The array of Route tree nodes the request matched. */
343
- routePath: RouteMatch[],
344
- /** The bodyformat that ended up taking precedence. This should be correctly typed. */
345
- bodyFormat: B, user: AuthUser, router: Router, tiddlerCache: Router["tiddlerCache"]);
346
- okUser(): void;
347
- okAdmin(): void;
348
- $transaction: <T>(fn: (prisma: PrismaTxnClient) => Promise<T>) => Promise<T>;
349
- $transactionTuple<P extends Prisma.PrismaPromise<any>[]>(arg: (prisma: Commander["engine"]) => [...P], options?: {
350
- isolationLevel?: Prisma.TransactionIsolationLevel;
351
- }): Promise<Types.Utils.UnwrapTuple<P>>;
352
- makeTiddlerEtag(options: {
353
- bag_name: string;
354
- tiddler_id: string | number;
355
- }): string;
356
- /** type-narrowing helper function. This affects anywhere T is used. */
357
- isBodyFormat<T extends B, S extends {
358
- [K in B]: StateObject<K, M, RoutePathParams, D>;
359
- }[T]>(format: T): this is S;
360
- /**
361
- *
362
- * Sends a **302** status code and **Location** header to the client.
363
- *
364
- *
365
- * - **301 Moved Permanently:** The resource has been permanently moved to a new URL.
366
- * - **302 Found:** The resource is temporarily located at a different URL.
367
- * - **303 See Other:** Fetch the resource from another URI using a GET request.
368
- * - **307 Temporary Redirect:** The resource is temporarily located at a different URL; the same HTTP method should be used.
369
- * - **308 Permanent Redirect:** The resource has permanently moved; the client should use the new URL in future requests.
370
- */
371
- redirect(location: string, pushLocation?: boolean): typeof STREAM_ENDED;
372
- sendSSE(retryMilliseconds?: number): {
373
- /** Emit an SSE event */
374
- emitEvent: (eventName: string, eventData: any, eventId: string) => void;
375
- emitComment: (comment: string) => boolean;
376
- close: () => PassThrough;
377
- onClose: (callback: () => void) => PassThrough;
378
- };
379
- checkACL(entityType: EntityType, entityName: string, permissionName: ACLPermissionName): Promise<void>;
380
- getRecipeACL(recipe_name: PrismaField<"Recipes", "recipe_name">, needWrite: boolean): Promise<{
381
- recipe: {
382
- recipe_id: number & {
383
- __prisma_table: "Recipes";
384
- __prisma_field: "recipe_id";
385
- };
386
- } | null;
387
- canRead: unknown;
388
- canWrite: unknown;
389
- }>;
390
- assertRecipeACL(recipe_name: PrismaField<"Recipes", "recipe_name">, needWrite: boolean): Promise<void>;
391
- getBagACL(bag_name: PrismaField<"Bags", "bag_name">, needWrite: boolean): Promise<{
392
- bag: {
393
- bag_id: number & {
394
- __prisma_table: "Bags";
395
- __prisma_field: "bag_id";
396
- };
397
- owner_id: PrismaField<"Bags", "owner_id">;
398
- is_plugin: PrismaField<"Bags", "is_plugin">;
399
- } | null;
400
- canRead: unknown;
401
- canWrite: unknown;
402
- }>;
403
- assertBagACL(bag_name: PrismaField<"Bags", "bag_name">, needWrite: boolean): Promise<{
404
- bag_id: number & {
405
- __prisma_table: "Bags";
406
- __prisma_field: "bag_id";
407
- };
408
- owner_id: PrismaField<"Bags", "owner_id">;
409
- is_plugin: PrismaField<"Bags", "is_plugin">;
410
- }>;
411
- }
412
-
413
- declare class TypedGenerator<T extends [any, any][]> {
414
- private inner;
415
- private index;
416
- static checker<T extends [any, any][]>(): {
417
- /** `const value1 = asV(1, yield asY(0, value0))` */
418
- asV<I extends number>(index: I, args: T[I][0]): T[I][0];
419
- /** `const value1 = asV(1, yield asY(0, value0))` */
420
- asY<I extends number>(index: I, ret: T[I][1]): T[I][1];
421
- };
422
- static wrapper<T extends [any, any][]>(): <A extends any[]>(factory: (...args: A) => Generator<any, any, any>) => (...args: A) => TypedGenerator<T>;
423
- constructor(inner: Generator<any, any, any>, index?: number);
424
- next<I extends number>(index: I, ...args: T[I][0] extends void ? [] : [T[I][0]]): Promise<(T extends [...any[], T[I]] ? IteratorReturnResult<T[I][1]> : IteratorYieldResult<T[I][1]>)>;
425
- return(value: any): any;
426
- throw(e: any): any;
427
- }
428
- declare interface JsonArray extends Array<JsonValue> {
429
- }
430
- declare type JsonObject = {
431
- [Key in string]?: JsonValue;
432
- };
433
- declare type JsonValue = string | number | boolean | JsonObject | JsonArray | null | Date;
434
-
435
- interface Route extends RouteDef<ParentTuple, string[]> {
436
- }
437
- interface rootRoute$1 extends RouteDef<[
438
- undefined,
439
- AllowedMethod[],
440
- StateObject<BodyFormat, AllowedMethod>,
441
- [
442
- []
443
- ]
444
- ], []> {
445
- }
446
- interface RouteMatch {
447
- route: Route;
448
- params: (string | undefined)[];
449
- remainingPath: string;
450
- }
451
- type DetermineRouteOptions<P extends ParentTuple, PA extends string[]> = P extends [BodyFormat, AllowedMethod[], any, any] ? RouteOptBase<P[0], P[1], PA> & {
452
- bodyFormat?: undefined;
453
- } : P extends [undefined, AllowedMethod[], any, any] ? {
454
- [K in BodyFormat]: RouteOptBase<K, P[1], PA> & {
455
- bodyFormat: K;
456
- };
457
- }[BodyFormat] | RouteOptBase<BodyFormat, P[1], PA> & {
458
- bodyFormat?: undefined;
459
- } : never;
460
- type ParentTuple = [BodyFormat | undefined, AllowedMethod[], any, string[][]];
461
- interface RouteOptBase<B extends BodyFormat, M extends AllowedMethod[], PA extends string[]> {
462
- /**
463
- * Regex to test the pathname on. It must start with `^`. If this is a child route,
464
- * it will be tested against the remaining portion of the parent route.
465
- */
466
- path: RegExp;
467
- pathParams?: PA;
468
- /** The uppercase method names to match this route */
469
- method: M;
470
- /**
471
- * The highest bodyformat in the chain always takes precedent. Type-wise, only one is allowed,
472
- * but at runtime the first one found is the one used.
473
- *
474
- * Note that bodyFormat is completely ignored for GET and HEAD requests.
475
- */
476
- bodyFormat?: B;
477
- /** If this route is the last one matched, it will NOT be called, and a 404 will be returned. */
478
- denyFinal?: boolean;
479
- }
480
- interface RouteDef<P extends ParentTuple, PA extends string[]> extends RouteOptBase<P[0] & {}, P[1], PA> {
481
- /**
482
- * If this route's handler sends headers, the matched child route will not be called.
483
- */
484
- handler: (state: StateObject<P[0] extends undefined ? BodyFormat : (P[0] & {}), P[1][number], [...P[3], [...PA]], unknown>) => Promise<P[2]>;
485
- /**
486
- * ### ROUTING
487
- *
488
- * @param route The route definition.
489
- *
490
- * If the parent route sends headers, or returns the STREAM_ENDED symbol,
491
- * this route will not be called.
492
- *
493
- * Inner routes are matched on the remaining portion of the parent route
494
- * using `pathname.slice(match[0].length)`. If the parent route entirely
495
- * matches the pathname, this route will be matched on "/".
496
- *
497
- * If the body format is "stream", "buffer", "ignore" or not yet defined at this level in the tree,
498
- * then zod cannot be used.
499
- *
500
- * Note that GET and HEAD are always bodyFormat: "ignore", regardless of what is set here.
501
- */
502
- defineRoute: <R, PA extends string[], T extends (P extends [BodyFormat, AllowedMethod[], any, any] ? RouteOptBase<P[0], P[1], [...PA]> & {
503
- bodyFormat?: undefined;
504
- } : P extends [undefined, AllowedMethod[], any, any] ? {
505
- [K in BodyFormat]: RouteOptBase<K, P[1], [...PA]> & {
506
- bodyFormat: K;
507
- };
508
- }[BodyFormat] | RouteOptBase<BodyFormat, P[1], [...PA]> & {
509
- bodyFormat?: undefined;
510
- } : never)>(route: T, handler: (
511
- /**
512
- * The state object for this route.
513
- *
514
- * If the route only specifies "GET" and/or "HEAD", then the bodyFormat can only be "ignore"
515
- *
516
- * Otherwise, the bodyFormat is determined by the first parent route that specifies it.
517
- *
518
- * The state object is wrapped in a proxy which throws if methods return a promise that
519
- * doesn't get awaited before the next property access. It only enforces the first layer
520
- * of properties, so if you have a nested object, you will need to wrap it in a proxy as well.
521
- *
522
- * store and store.sql will probably also be wrapped in this proxy.
523
- */
524
- state: StateObject<(Exclude<T["method"][number], "GET" | "HEAD"> extends never ? never : (P[0] extends BodyFormat ? P[0] : T["bodyFormat"] extends BodyFormat ? T["bodyFormat"] : BodyFormat)) | (T["method"][number] extends "GET" | "HEAD" ? "ignore" : never), T["method"][number], getPA<P, T>, unknown>) => Promise<R>) => P[0] extends BodyFormat ? RouteDef<[P[0], T["method"], R, P[3]], [...PA]> : T["bodyFormat"] extends BodyFormat ? RouteDef<[T["bodyFormat"], T["method"], R, P[3]], [...PA]> : RouteDef<[undefined, T["method"], R, P[3]], [...PA]>;
525
- $o?: P;
526
- }
527
- type getPA<P extends ParentTuple, T extends DetermineRouteOptions<P, any>> = [
528
- ...P[3],
529
- ...T["pathParams"] extends string[] ? [T["pathParams"]] : []
530
- ];
531
-
532
- type _zod = typeof z$1;
533
- type FieldTypeGroups = "STRING" | "JSON";
534
- type FieldTypeStringSelector<T extends FieldTypeGroups> = T extends "STRING" ? "string" : "string";
535
- type FieldTypeNumberSelector<T extends FieldTypeGroups> = T extends "STRING" ? "parse-number" : "number";
536
- type FieldTypeBooleanSelector<T extends FieldTypeGroups> = T extends "STRING" ? "parse-boolean" : "boolean";
537
- interface Z2<T extends FieldTypeGroups> extends _zod {
538
- /**
539
- * Tags the resulting value as being from the specified table field.
540
- *
541
- * The third argument is a string literal that specifies the field type based on the selected field.
542
- *
543
- * "string" and "parse-number"
544
- * - will use decodeURIComponent on the value.
545
- * - Require a string length at least one
546
- *
547
- * You can use .optional(), .nullable(), .nulish() after this to make the field optional.
548
- */
549
- prismaField<Table extends Prisma.ModelName, Field extends keyof PrismaPayloadScalars<Table>>(table: Table, field: Field, fieldtype: string extends (PrismaPayloadScalars<Table>[Field]) ? FieldTypeStringSelector<T> : number extends (PrismaPayloadScalars<Table>[Field]) ? FieldTypeNumberSelector<T> : boolean extends (PrismaPayloadScalars<Table>[Field]) ? FieldTypeBooleanSelector<T> : never, nullable?: null extends PrismaPayloadScalars<Table>[Field] ? true : false): ZodEffects<any, PrismaField<Table, Field>, PrismaPayloadScalars<Table>[Field]>;
550
- authUser(): z$1.ZodNullable<z$1.ZodObject<{
551
- user_id: z$1.ZodNumber;
552
- isAdmin: z$1.ZodBoolean;
553
- username: z$1.ZodString;
554
- sessionId: z$1.ZodNumber;
555
- }>>;
556
- }
557
- declare const Z2: Z2<FieldTypeGroups>;
558
-
559
- declare global {
560
- type PrismaTxnClient = Omit<Commander["engine"], "$connect" | "$disconnect" | "$on" | "$transaction" | "$use" | "$extends">;
561
- type ART<T extends (...args: any) => any> = Awaited<ReturnType<T>>;
562
- type Complete<T> = {
563
- [K in keyof T]-?: T[K];
564
- };
565
- /**
566
- * This primarily makes sure that positional arguments are used correctly
567
- * (so you can't switch a title and bag_name around).
568
- *
569
- * If you assign the wrong value (like `5 as PrismaField<"Bags", "bag_name">`),
570
- * this will result in a type error on the as keyword, allowing you to catch incorrect types quickly.
571
- */
572
- type PrismaField<T extends Prisma.ModelName, K extends keyof PrismaPayloadScalars<T>> = ([
573
- T,
574
- K
575
- ] extends ["Tiddlers", "bag_id"] ? PrismaField<"Bags", "bag_id"> : [
576
- T,
577
- K
578
- ] extends ["Sessions", "user_id"] ? PrismaField<"Users", "user_id"> : [
579
- T,
580
- K
581
- ] extends ["Recipe_bags", "bag_id"] ? PrismaField<"Bags", "bag_id"> : [
582
- T,
583
- K
584
- ] extends ["Recipe_bags", "recipe_id"] ? PrismaField<"Recipes", "recipe_id"> : [
585
- T,
586
- K
587
- ] extends ["Recipes", "owner_id"] ? PrismaField<"Users", "user_id"> : [
588
- T,
589
- K
590
- ] extends ["Bags", "owner_id"] ? PrismaField<"Users", "user_id"> : (PrismaPayloadScalars<T>[K] & {
591
- __prisma_table: T;
592
- __prisma_field: K;
593
- })) | (null extends PrismaPayloadScalars<T>[K] ? null : never);
594
- type PrismaPayloadScalars<T extends Prisma.ModelName> = Prisma.TypeMap["model"][T]["payload"]["scalars"];
595
- type EntityName<T extends EntityType> = T extends "bag" ? PrismaField<"Bags", "bag_name"> : T extends "recipe" ? PrismaField<"Recipes", "recipe_name"> : never;
596
- type EntityType = "recipe" | "bag";
597
- type ACLPermissionName = "READ" | "WRITE" | "ADMIN";
598
- type rootRoute = rootRoute$1;
599
- type ZodAssert = typeof ZodAssert;
600
- }
601
- declare global {
602
- function hop(object: any, property: any): boolean;
603
- function each<T>(object: T[], callback: (value: T, index: number, object: T[]) => void): void;
604
- function each<T>(object: Record<string, T>, callback: (value: T, key: string, object: Record<string, T>) => void): void;
605
- function eachAsync<T>(object: T[], callback: (value: T, index: number, object: T[]) => void): Promise<void>;
606
- function eachAsync<T>(object: Record<string, T>, callback: (value: T, key: string, object: Record<string, T>) => void): Promise<void>;
607
- function createDirectory(dirPath: string): void;
608
- function deleteDirectory(dirPath: string): void;
609
- function encodeURIComponentExtended(s: string): string;
610
- }
611
- declare class _Result<OK extends boolean, T> {
612
- ok: OK;
613
- error: OK extends true ? undefined : unknown;
614
- value: OK extends true ? T : undefined;
615
- constructor(ok: OK, error: OK extends true ? undefined : unknown, value: OK extends true ? T : undefined);
616
- get [Symbol.iterator](): (OK | (OK extends true ? undefined : unknown) | (OK extends true ? T : undefined))[];
617
- static ok<T>(value: T): _Result<true, T>;
618
- static error(error: unknown): _Result<false, undefined>;
619
- /**
620
- * @example
621
- * // const result = try something();
622
- * const result = Result.try_(() => {
623
- * something();
624
- * });
625
- */
626
- static try_<T, This>(callback: (this: This) => T, thisarg: This): _Result<false, undefined> | _Result<true, T>;
627
- }
628
- declare global {
629
- const TryResult: typeof _Result;
630
- interface Promise<T> {
631
- try: () => Promise<_Result<true, T> | _Result<false, T>>;
632
- }
633
- }
634
-
635
- declare module 'node:net' {
636
- interface Socket {
637
- /** Not defined on net.Socket instances.
638
- *
639
- * On tls.Socket instances, */
640
- encrypted?: boolean;
641
- }
642
- }
643
- interface IncomingHttpHeaders extends IncomingHttpHeaders$1 {
644
- "accept-encoding"?: string;
645
- }
646
- declare const STREAM_ENDED: unique symbol;
647
- /**
648
- * The HTTP2 shims used in the request handler are only used for HTTP2 requests.
649
- * The NodeJS HTTP2 server actually calls the HTTP1 parser for all HTTP1 requests.
650
- */
651
- declare class Streamer {
652
- private req;
653
- private res;
654
- private router;
655
- host: string;
656
- method: AllowedMethod;
657
- urlInfo: URL;
658
- url: string;
659
- headers: IncomingHttpHeaders;
660
- isSecure: boolean;
661
- cookies: URLSearchParams;
662
- constructor(req: IncomingMessage$1 | http2.Http2ServerRequest, res: ServerResponse$1 | http2.Http2ServerResponse, router: Router);
663
- parseCookieString(cookieString: string): URLSearchParams;
664
- get reader(): Readable;
665
- get writer(): Writable;
666
- throw(statusCode: number): void;
667
- catcher: (error: unknown) => void;
668
- checkHeadersSentBy(setError: boolean): void;
669
- toHeadersMap(headers: {
670
- [x: string]: string | string[] | number | undefined;
671
- }): Map<string, string[]>;
672
- readBody: () => Promise<Buffer<ArrayBufferLike>>;
673
- sendEmpty(status: number, headers?: OutgoingHttpHeaders): typeof STREAM_ENDED;
674
- sendString(status: number, headers: OutgoingHttpHeaders, data: string, encoding: NodeJS.BufferEncoding): typeof STREAM_ENDED;
675
- sendBuffer(status: number, headers: OutgoingHttpHeaders, data: Buffer): typeof STREAM_ENDED;
676
- /** If this is a HEAD request, the stream will be ignored AND LEFT OPEN. */
677
- sendStream(status: number, headers: OutgoingHttpHeaders, stream: Readable): typeof STREAM_ENDED;
678
- private sendFD;
679
- /**
680
- * Sends a file with the appropriate cache headers, using the `send` npm module.
681
- *
682
- * Think of it like a static file server where you are serving files from a directory.
683
- *
684
- * @param options.root The directory to serve files from.
685
- * @param options.reqpath The path to the file relative to the `root` directory.
686
- * @param options.offset The offset in bytes to start reading the file from.
687
- * @param options.length The number of bytes to read from the file.
688
- * @param options.index "index.html" by default, to disable this set false or
689
- * to supply a new index pass a string or an array in preferred order.
690
- *
691
- * If an index.html file is not found, `send` will NOT generate a directory listing.
692
- *
693
- * The `send` method will automatically set the `Content-Type` header based on the file extension.
694
- *
695
- * If the file is not found, the `send` method will automatically send a 404 response.
696
- *
697
-
698
- * @returns STREAM_ENDED
699
- */
700
- sendFile(status: number, headers: OutgoingHttpHeaders, options: {
701
- root: string;
702
- reqpath: string;
703
- offset?: number;
704
- length?: number;
705
- index?: string | boolean | string[] | undefined;
706
- on404?: () => Promise<typeof STREAM_ENDED>;
707
- onDir?: () => Promise<typeof STREAM_ENDED>;
708
- }): Promise<typeof STREAM_ENDED>;
709
- setCookie(name: string, value: string, options: {
710
- domain?: string;
711
- path?: string;
712
- expires?: Date;
713
- maxAge?: number;
714
- secure?: boolean;
715
- httpOnly?: boolean;
716
- sameSite?: "Strict" | "Lax" | "None";
717
- }): void;
718
- appendHeader(name: string, value: string): void;
719
- setHeader(name: string, value: string): void;
720
- writeHead(status: number, headers?: OutgoingHttpHeaders): void;
721
- write(chunk: Buffer | string, encoding?: NodeJS.BufferEncoding): void;
722
- end(): typeof STREAM_ENDED;
723
- get headersSent(): boolean;
724
- headersSentBy: Error | undefined;
725
- }
726
- declare class StreamerState {
727
- private streamer;
728
- readBody: () => Promise<Buffer<ArrayBufferLike>>;
729
- sendEmpty: (status: number, headers?: OutgoingHttpHeaders) => typeof STREAM_ENDED;
730
- sendString: (status: number, headers: OutgoingHttpHeaders, data: string, encoding: NodeJS.BufferEncoding) => typeof STREAM_ENDED;
731
- sendBuffer: (status: number, headers: OutgoingHttpHeaders, data: Buffer) => typeof STREAM_ENDED;
732
- sendStream: (status: number, headers: OutgoingHttpHeaders, stream: Readable) => typeof STREAM_ENDED;
733
- sendFile: (status: number, headers: OutgoingHttpHeaders, options: {
734
- root: string;
735
- reqpath: string;
736
- offset?: number;
737
- length?: number;
738
- index?: string | boolean | string[] | undefined;
739
- on404?: () => Promise<typeof STREAM_ENDED>;
740
- onDir?: () => Promise<typeof STREAM_ENDED>;
741
- }) => Promise<typeof STREAM_ENDED>;
742
- setCookie: (name: string, value: string, options: {
743
- domain?: string;
744
- path?: string;
745
- expires?: Date;
746
- maxAge?: number;
747
- secure?: boolean;
748
- httpOnly?: boolean;
749
- sameSite?: "Strict" | "Lax" | "None";
750
- }) => void;
751
- /**
752
- *
753
- * Sets a single header value. If the header already exists in the to-be-sent
754
- * headers, its value will be replaced. Use an array of strings to send multiple
755
- * headers with the same name
756
- *
757
- * When headers have been set with `response.setHeader()`, they will be merged
758
- * with any headers passed to `response.writeHead()`, with the headers passed
759
- * to `response.writeHead()` given precedence.
760
- *
761
- */
762
- setHeader: (name: string, value: string) => void;
763
- writeHead: (status: number, headers?: OutgoingHttpHeaders) => void;
764
- write: (chunk: Buffer | string, encoding?: NodeJS.BufferEncoding) => void;
765
- end: () => typeof STREAM_ENDED;
766
- /** sends a status and plain text string body */
767
- sendSimple(status: number, msg: string): typeof STREAM_ENDED;
768
- /** Stringify the value (unconditionally) and send it with content-type `application/json` */
769
- sendJSON<T>(status: number, obj: T): typeof STREAM_ENDED;
770
- STREAM_ENDED: typeof STREAM_ENDED;
771
- constructor(streamer: Streamer);
772
- get url(): string;
773
- get method(): AllowedMethod;
774
- get headers(): IncomingHttpHeaders;
775
- get host(): string;
776
- get urlInfo(): URL;
777
- get headersSent(): boolean;
778
- get reader(): Readable;
779
- /** Currently this is based on whether the socket is secure, so a proxy will cause problems. */
780
- get isSecure(): boolean;
781
- get cookies(): URLSearchParams;
782
- }
783
-
784
- declare function startupCache(rootRoute: rootRoute, commander: Commander): Promise<{
785
- tiddlerFiles: Map<any, any>;
786
- tiddlerHashes: Map<any, any>;
787
- }>;
788
- type CacheState = ART<typeof startupCache>;
789
-
790
- declare const AllowedMethods: ("POST" | "GET" | "HEAD" | "OPTIONS" | "PUT" | "DELETE")[];
791
- type AllowedMethod = typeof AllowedMethods[number];
792
- declare const BodyFormats: readonly ["stream", "string", "json", "buffer", "www-form-urlencoded", "www-form-urlencoded-urlsearchparams", "ignore"];
793
- type BodyFormat = typeof BodyFormats[number];
794
- declare class Router {
795
- private rootRoute;
796
- private tiddlerCache;
797
- static makeRouter(commander: Commander, enableDevServer: boolean): Promise<Router>;
798
- enableBrowserCache: boolean;
799
- enableGzip: boolean;
800
- csrfDisable: boolean;
801
- siteConfig: SiteConfig;
802
- get pathPrefix(): string;
803
- engine: Commander["engine"];
804
- private SessionManager;
805
- PasswordService: Commander["PasswordService"];
806
- versions: {
807
- tiddlywiki: any;
808
- mws: string;
809
- };
810
- fieldModules: Commander["$tw"]["Tiddler"]["fieldModules"];
811
- AttachmentService: Commander["AttachmentService"];
812
- constructor(rootRoute: rootRoute$1, commander: Commander, tiddlerCache: CacheState);
813
- handleIncomingRequest(req: http.IncomingMessage | http2$1.Http2ServerRequest, res: http.ServerResponse | http2$1.Http2ServerResponse): void;
814
- handle(streamer: Streamer): Promise<void | typeof STREAM_ENDED>;
815
- handleRoute(state: StateObject<BodyFormat>, route: RouteMatch[]): Promise<void>;
816
- findRouteRecursive(routes: Route[], testPath: string, method: AllowedMethod): RouteMatch[];
817
- /**
818
- *
819
- * Top-level function that starts matching from the root routes.
820
- * Notice that the pathPrefix is assumed to have been handled beforehand.
821
- *
822
- * @param streamer
823
- * @returns The tree path matched
824
- */
825
- findRoute(streamer: Streamer): RouteMatch[];
826
- }
827
- interface ZodAction<T extends z.ZodTypeAny, R extends JsonValue> {
828
- inner: (route: z.output<T>) => Promise<R>;
829
- zodRequest: (z: Z2<"JSON">) => T;
830
- zodResponse?: (z: Z2<"JSON">) => z.ZodType<R>;
831
- }
832
- declare class ZodState<M extends AllowedMethod, B extends BodyFormat, P extends Record<string, z.ZodTypeAny>, T extends z.ZodTypeAny> extends StateObject<B, M, string[][], z.output<T>> {
833
- pathParams: z.output<z.ZodObject<P>>;
834
- }
835
- type jsonify<T> = T extends void ? null : T extends Promise<any> ? unknown : T extends Date ? string : T extends string | number | boolean | null | undefined ? T : T extends [...any[]] ? number extends T["length"] ? jsonify<T[number]>[] : [...jsonifyTuple<T>] : T extends Array<infer U> ? jsonify<U>[] : T extends object ? {
836
- [K in keyof T]: jsonify<T[K]>;
837
- } : unknown;
838
- type jsonifyTuple<T> = T extends [infer A, ...infer B] ? [jsonify<A>, ...jsonifyTuple<B>] : T extends [infer A] ? [jsonify<A>] : [];
839
- type RouterKeyMap<T, V> = {
840
- [K in keyof T as T[K] extends ZodAction<any, any> ? K : never]: V;
841
- };
842
-
843
- interface MWSConfig {
844
- /**
845
- * Listener config for the mws-listen command.
846
- * This is extracted from the config early and passed directly to mws-listen.
847
- */
848
- listeners: {
849
- /** The key file for the HTTPS server. If either key or cert are set, both are required, and HTTPS is enforced. */
850
- key?: string;
851
- /** The cert file for the HTTPS server. If either key or cert are set, both are required, and HTTPS is enforced. */
852
- cert?: string;
853
- /** The port to listen on. If not specified, listen will not be called. */
854
- port?: number;
855
- /** The hostname to listen on. If this is specified, then port is required. */
856
- host?: string;
857
- }[];
858
- /**
859
- * Called and awaited by the mws-listen command.
860
- * This is extracted from the config early and passed directly to mws-listen.
861
- */
862
- onListenersCreated?: (listeners: ListenerBase[]) => Promise<void>;
863
- /**
864
- * Enables the dev configuration of the server.
865
- */
866
- enableDevServer?: boolean;
867
- /**
868
- * Path or file descriptor to the password master key.
869
- * If this key changes, all passwords will be invalid and need to be changed.
870
- */
871
- passwordMasterKeyFile: string | number;
872
- onPasswordKeyFileRead?: () => void;
873
- /** Path to the datafolder. */
874
- wikiPath: string;
875
- /** MWS site configuration */
876
- config?: MWSConfigConfig;
877
- /**
878
- * The session manager class registers the login handler routes and sets the auth user
879
- */
880
- SessionManager?: typeof SessionManager;
881
- /**
882
- * The attachment service class is used by routes to handle attachments
883
- */
884
- AttachmentService?: typeof AttachmentService;
885
- }
886
- interface MWSConfigConfig {
887
- /** If true, allow users that aren't logged in to read. */
888
- readonly allowAnonReads?: boolean;
889
- /** If true, allow users that aren't logged in to write. */
890
- readonly allowAnonWrites?: boolean;
891
- /** If true, recipes will allow access to a user who does not have read access to all its bags. */
892
- readonly allowUnreadableBags?: boolean;
893
- /** If true, files larger than `this * 1024` will be saved to disk alongside the database instead of in the database. */
894
- readonly saveLargeTextToFileSystem?: number;
895
- readonly enableGzip?: boolean;
896
- readonly enableBrowserCache?: boolean;
897
- /** The path prefix must start with a slash, and end without a slash */
898
- readonly pathPrefix?: string;
899
- readonly enablePluginCache?: boolean;
900
- }
901
- interface SiteConfig extends Complete<MWSConfigConfig> {
902
- wikiPath: string;
903
- attachmentSizeLimit: number;
904
- attachmentsEnabled: boolean;
905
- contentTypeInfo: Record<string, any>;
906
- saveLargeTextToFileSystem: never;
907
- storePath: string;
908
- /**
909
- * The path prefix is a essentially folder mount point.
910
- *
911
- * It starts with a slash, and ends without a slash (`"/dev"`).
912
- *
913
- * If there is not a prefix, it is an empty string (`""`).
914
- */
915
- pathPrefix: string;
916
- }
917
- /**
918
- *
919
- * The promise returned will resolve once the commander has completed.
920
- * It will reject if the commander or anything else throws an error.
921
- *
922
- ```
923
- import startServer from "./src/server.ts";
924
-
925
- startServer({
926
- // enableDevServer: true,
927
- passwordMasterKey: "./localpass.key",
928
- listeners: [{
929
- key: "./localhost.key",
930
- cert: "./localhost.crt",
931
- port: 5000,
932
- }],
933
- config: {
934
- wikiPath: "./editions/mws",
935
- allowAnonReads: false,
936
- allowAnonWrites: false,
937
- allowUnreadableBags: false,
938
- },
939
- });
940
-
941
- ```
942
- */
943
- declare function startServer(config: MWSConfig): Promise<void>;
944
-
945
- export { type AuthUser, type MWSConfig, type MWSConfigConfig, type RouterPathRouteMap, SessionKeyMap, SessionManager, type SessionManagerMap, type SiteConfig, type ZodSessionRoute, assertSignature, startServer as default, zodSession };