@genesislcap/mock-server 15.74.0 → 15.75.0

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 (100) hide show
  1. package/README.md +296 -58
  2. package/dist/db/schema.d.ts +9 -1
  3. package/dist/db/schema.js +40 -11
  4. package/dist/db/store.d.ts +1 -0
  5. package/dist/db/store.js +4 -0
  6. package/dist/handlers/auth.d.ts +15 -6
  7. package/dist/handlers/auth.js +152 -33
  8. package/dist/handlers/commitEvent.js +43 -20
  9. package/dist/handlers/crudEvents.d.ts +3 -1
  10. package/dist/handlers/crudEvents.js +3 -2
  11. package/dist/handlers/eventValidation.js +6 -3
  12. package/dist/handlers/http.d.ts +2 -2
  13. package/dist/handlers/http.js +66 -43
  14. package/dist/handlers/jsonSchema.d.ts +1 -0
  15. package/dist/handlers/jsonSchema.js +72 -21
  16. package/dist/handlers/meta.d.ts +1 -1
  17. package/dist/handlers/meta.js +59 -10
  18. package/dist/handlers/requestReply.js +36 -9
  19. package/dist/index.d.ts +1 -1
  20. package/dist/presets/auth.d.ts +25 -0
  21. package/dist/presets/auth.js +855 -0
  22. package/dist/presets/cronExpression.d.ts +1 -0
  23. package/dist/presets/cronExpression.js +429 -0
  24. package/dist/presets/fileServer.d.ts +13 -0
  25. package/dist/presets/fileServer.js +399 -0
  26. package/dist/presets/gsf.d.ts +24 -0
  27. package/dist/presets/gsf.js +450 -0
  28. package/dist/presets/index.d.ts +1 -0
  29. package/dist/presets/index.js +1 -0
  30. package/dist/presets/javaTime.d.ts +7 -0
  31. package/dist/presets/javaTime.js +322 -0
  32. package/dist/presets/multipart.d.ts +14 -0
  33. package/dist/presets/multipart.js +91 -0
  34. package/dist/presets/notify.d.ts +27 -0
  35. package/dist/presets/notify.js +250 -0
  36. package/dist/presets/notifyDispatch.d.ts +28 -0
  37. package/dist/presets/notifyDispatch.js +570 -0
  38. package/dist/presets/notifyRules.d.ts +9 -0
  39. package/dist/presets/notifyRules.js +754 -0
  40. package/dist/presets/platform/backing.json +8058 -217
  41. package/dist/presets/platform/criteria-model.json +362 -0
  42. package/dist/presets/platform/time-zones.json +608 -0
  43. package/dist/presets/platform.d.ts +7 -0
  44. package/dist/presets/platform.js +145 -103
  45. package/dist/presets/products.d.ts +9 -7
  46. package/dist/presets/products.js +89 -21
  47. package/dist/presets/reconciliation.d.ts +18 -0
  48. package/dist/presets/reconciliation.js +721 -0
  49. package/dist/presets/reporting.d.ts +14 -0
  50. package/dist/presets/reporting.js +862 -0
  51. package/dist/protocol/connection.d.ts +2 -0
  52. package/dist/protocol/connection.js +4 -0
  53. package/dist/protocol/dtoTypes.d.ts +30 -0
  54. package/dist/protocol/dtoTypes.js +250 -0
  55. package/dist/protocol/errors.d.ts +3 -1
  56. package/dist/protocol/errors.js +2 -0
  57. package/dist/protocol/fieldTypes.js +5 -0
  58. package/dist/protocol/router.d.ts +1 -0
  59. package/dist/protocol/router.js +3 -3
  60. package/dist/protocol/schemaValidation.d.ts +1 -1
  61. package/dist/protocol/schemaValidation.js +53 -8
  62. package/dist/server.js +34 -2
  63. package/dist/types.d.ts +50 -2
  64. package/package.json +1 -1
  65. package/src/db/schema.ts +56 -13
  66. package/src/db/store.ts +5 -0
  67. package/src/handlers/auth.ts +211 -37
  68. package/src/handlers/commitEvent.ts +44 -19
  69. package/src/handlers/crudEvents.ts +9 -2
  70. package/src/handlers/eventValidation.ts +6 -3
  71. package/src/handlers/http.ts +83 -42
  72. package/src/handlers/jsonSchema.ts +86 -23
  73. package/src/handlers/meta.ts +77 -9
  74. package/src/handlers/requestReply.ts +42 -6
  75. package/src/index.ts +7 -0
  76. package/src/presets/auth.ts +961 -0
  77. package/src/presets/cronExpression.ts +445 -0
  78. package/src/presets/fileServer.ts +475 -0
  79. package/src/presets/gsf.ts +475 -0
  80. package/src/presets/index.ts +5 -0
  81. package/src/presets/javaTime.ts +354 -0
  82. package/src/presets/multipart.ts +110 -0
  83. package/src/presets/notify.ts +312 -0
  84. package/src/presets/notifyDispatch.ts +685 -0
  85. package/src/presets/notifyRules.ts +866 -0
  86. package/src/presets/platform/backing.json +8058 -217
  87. package/src/presets/platform/criteria-model.json +362 -0
  88. package/src/presets/platform/time-zones.json +608 -0
  89. package/src/presets/platform.ts +204 -115
  90. package/src/presets/products.ts +125 -19
  91. package/src/presets/reconciliation.ts +824 -0
  92. package/src/presets/reporting.ts +953 -0
  93. package/src/protocol/connection.ts +4 -0
  94. package/src/protocol/dtoTypes.ts +310 -0
  95. package/src/protocol/errors.ts +13 -1
  96. package/src/protocol/fieldTypes.ts +5 -0
  97. package/src/protocol/router.ts +3 -3
  98. package/src/protocol/schemaValidation.ts +61 -8
  99. package/src/server.ts +38 -2
  100. package/src/types.ts +147 -3
@@ -0,0 +1,399 @@
1
+ // The file-server product: its two events and ASSETS_FOR_TEMPLATE
2
+ // (file-server v8.15.9, scripts/platform-preset/seeds/file-server@8.15.9/
3
+ // scripts: file-server-eventhandler.kts below as EH, file-server-reqrep.kts as
4
+ // RR), and the HTTP endpoints its router script serves (file-server-web-
5
+ // handler.kts in file-server-app, which uploads, replaces, downloads and
6
+ // deletes files). A file's bytes are kept in memory, by FILE_STORAGE_ID.
7
+ import { randomUUID } from 'node:crypto';
8
+ import { checkUnique } from "../handlers/crudEvents.js";
9
+ import { NackError } from "../protocol/errors.js";
10
+ import { BodyTooLarge, boundaryOf, declaredTooLarge, parseMultipart, readBody, } from "./multipart.js";
11
+ import { dto } from "./notify.js";
12
+ const SCHEMAS = {
13
+ EVENT_FILE_STORAGE_DELETE: {
14
+ table: 'FILE_STORAGE',
15
+ pkOnly: true,
16
+ className: 'global.genesis.gen.dao.FileStorage.ById',
17
+ },
18
+ EVENT_LINK_TEMPLATE_ASSETS: {
19
+ className: 'global.genesis.file.messages.EventLinkTemplateAssets',
20
+ fields: [
21
+ dto('TEMPLATE_ID', 'STRING'),
22
+ dto('ASSET_IDS', 'ARRAY', { items: { type: 'STRING' } }),
23
+ ],
24
+ },
25
+ };
26
+ // A FILE_STORAGE_ID as the uuid strategy builds one: a UUID, the sequence
27
+ // (FF), the location (LO) and 1.
28
+ export const newFileStorageId = () => `${randomUUID()}FFLO1`;
29
+ // The sysdef's ALLOWED_FILE_EXTENSIONS default.
30
+ const ALLOWED_EXTENSIONS = [
31
+ 'html',
32
+ 'pdf',
33
+ 'csv',
34
+ 'txt',
35
+ 'jpeg',
36
+ 'jpg',
37
+ 'xlsx',
38
+ 'png',
39
+ 'svg',
40
+ 'css',
41
+ 'ftl',
42
+ 'xml',
43
+ ];
44
+ const MAX_FILE_NAME = 128;
45
+ // The largest upload body taken. GSF's MultiPartConfig.maxFileSize is 1 GiB
46
+ // (HttpConfig.kt:88 @v8.15.29), which it spools to disk; the mock keeps
47
+ // files in memory.
48
+ const BYTES_PER_MIB = 1_048_576;
49
+ const MAX_UPLOAD_MIB = 100;
50
+ export const MAX_UPLOAD_BYTES = MAX_UPLOAD_MIB * BYTES_PER_MIB;
51
+ const FILE_TYPES = ['USER_DOCUMENT', 'DOCUMENT_TEMPLATE', 'TEMPLATE_ASSET'];
52
+ // MimetypesFileTypeMap's types for the allowed extensions; the rest are
53
+ // application/octet-stream.
54
+ const CONTENT_TYPES = {
55
+ html: 'text/html',
56
+ txt: 'text/plain',
57
+ jpeg: 'image/jpeg',
58
+ jpg: 'image/jpeg',
59
+ png: 'image/png',
60
+ };
61
+ const STATUS_TEXT = {
62
+ 400: 'Bad Request',
63
+ 401: 'Unauthorized',
64
+ 404: 'Not Found',
65
+ 406: 'Not Acceptable',
66
+ 422: 'Unprocessable Entity',
67
+ 500: 'Internal Server Error',
68
+ };
69
+ const OK = 200;
70
+ const BAD_REQUEST = 400;
71
+ const UNAUTHORIZED = 401;
72
+ const NOT_FOUND = 404;
73
+ const NOT_ACCEPTABLE = 406;
74
+ const UNPROCESSABLE = 422;
75
+ const SERVER_ERROR = 500;
76
+ // The router's error reply (HttpHandler): an IllegalArgumentException's
77
+ // message as 422, anything else 500 "Error while processing request", in a
78
+ // MSG_NACK.
79
+ function sendNack(res, status, text) {
80
+ const STATUS_CODE = `${status} ${STATUS_TEXT[status]}`;
81
+ sendJson(res, status, {
82
+ MESSAGE_TYPE: 'MSG_NACK',
83
+ // What the router mints for a request with none.
84
+ SOURCE_REF: `AUTO_${randomUUID()}`,
85
+ ERROR: [{ CODE: status, TEXT: text, STATUS_CODE }],
86
+ DETAILS: { ERROR: text, STATUS_CODE },
87
+ });
88
+ }
89
+ function sendJson(res, status, body) {
90
+ res.writeHead(status, { 'Content-Type': 'application/json' });
91
+ res.end(JSON.stringify(body));
92
+ }
93
+ // An endpoint's own exceptionHandler: its text as it is.
94
+ function sendText(res, status, text) {
95
+ res.writeHead(status, { 'Content-Type': 'application/json' });
96
+ res.end(text);
97
+ }
98
+ // The file name after its last /, as File.separator splits it.
99
+ const baseName = (name) => name.slice(name.lastIndexOf('/') + 1);
100
+ const extensionOf = (name) => name.slice(name.lastIndexOf('.') + 1);
101
+ // FileStorageContentValidator.performValidationChecks: empty content, then
102
+ // the extension, the length and the characters. Its content-type sniffing
103
+ // (Tika) isn't modelled. The empty file is an IOException: a 500.
104
+ function contentError(part, name) {
105
+ if (part.data.length <= 0)
106
+ return [SERVER_ERROR, 'Error while processing request'];
107
+ const extension = extensionOf(name);
108
+ if (!ALLOWED_EXTENSIONS.includes(extension)) {
109
+ return [UNPROCESSABLE, `File extension ${extension} is not on the list of allowed file types`];
110
+ }
111
+ if (name.length > MAX_FILE_NAME)
112
+ return [UNPROCESSABLE, 'File name must be 128 characters or fewer'];
113
+ if (/[/\\:*?"<>|\0\n\r]|\.\./.test(name)) {
114
+ return [UNPROCESSABLE, 'File name must not contain special characters'];
115
+ }
116
+ return undefined;
117
+ }
118
+ const IDENTITY_HASH = 0xffffffff;
119
+ const HEX = 16;
120
+ // FILE_MANAGER has no file of that id: what DataSourceFactory reports. Its
121
+ // FileContentRequest has no toString(), so it prints as Object does.
122
+ const fileContent = (store, id) => {
123
+ const file = store.getRow('FILE_STORAGE', id);
124
+ if (file)
125
+ return { fileName: String(file.FILE_NAME) };
126
+ const hash = Math.floor(Math.random() * IDENTITY_HASH).toString(HEX);
127
+ return {
128
+ error: `Exception caught while attempting to request file contents from FILE_MANAGER with request global.genesis.file.message.request.FileContentRequest@${hash}`,
129
+ };
130
+ };
131
+ export function fileServerBacking() {
132
+ const contents = new Map();
133
+ const eventHandlers = {
134
+ // EH :5-38: the template's links replaced by those sent.
135
+ EVENT_LINK_TEMPLATE_ASSETS: (details, ctx) => {
136
+ const template = ctx.store.getRow('FILE_STORAGE', details.TEMPLATE_ID);
137
+ if (!template) {
138
+ throw new NackError(`Template for ID ${details.TEMPLATE_ID} does not exist in FILE_STORAGE!`);
139
+ }
140
+ if (template.FILE_TYPE !== 'DOCUMENT_TEMPLATE') {
141
+ throw new NackError(`File for ID ${details.TEMPLATE_ID} has not been marked as template!`);
142
+ }
143
+ for (const assetId of details.ASSET_IDS) {
144
+ if (!ctx.store.getRow('FILE_STORAGE', assetId)) {
145
+ throw new NackError(`Asset for ID ${assetId} does not exist in FILE_STORAGE!`);
146
+ }
147
+ }
148
+ if (ctx.validate)
149
+ return {};
150
+ for (const link of linksOf(ctx, details.TEMPLATE_ID)) {
151
+ const key = ctx.store.rowKey('TEMPLATE_ASSET', link);
152
+ ctx.store.deleteRow('TEMPLATE_ASSET', key);
153
+ ctx.broadcastTableChange('TEMPLATE_ASSET', 'DELETE', key);
154
+ }
155
+ for (const ASSET_ID of details.ASSET_IDS) {
156
+ const row = { TEMPLATE_ID: details.TEMPLATE_ID, ASSET_ID };
157
+ checkUnique('TEMPLATE_ASSET', ctx.config.tables.TEMPLATE_ASSET, row, ctx.store);
158
+ ctx.store.insertRow('TEMPLATE_ASSET', row);
159
+ ctx.broadcastTableChange('TEMPLATE_ASSET', 'INSERT', ctx.store.rowKey('TEMPLATE_ASSET', row));
160
+ }
161
+ return {};
162
+ },
163
+ // EH :41-57: verify { hasEntry }, then the file manager's delete.
164
+ EVENT_FILE_STORAGE_DELETE: (details, ctx) => {
165
+ const id = details.FILE_STORAGE_ID;
166
+ if (!ctx.store.getRow('FILE_STORAGE', id)) {
167
+ throw new NackError(`FILE_STORAGE ById(fileStorageId=${id}) not found in database`);
168
+ }
169
+ if (ctx.validate)
170
+ return {};
171
+ deleteFile(ctx, id);
172
+ return {};
173
+ },
174
+ };
175
+ // AbstractFileStorageManager.deleteFile: the row and the bytes; the
176
+ // template links to it are left.
177
+ function deleteFile(ctx, id) {
178
+ if (ctx.store.deleteRow('FILE_STORAGE', id))
179
+ ctx.broadcastTableChange('FILE_STORAGE', 'DELETE', id);
180
+ contents.delete(id);
181
+ }
182
+ const linksOf = (ctx, templateId) => ctx.store.getAllRows('TEMPLATE_ASSET').filter((link) => link.TEMPLATE_ID === templateId);
183
+ return {
184
+ contents,
185
+ fileContent,
186
+ eventHandlers,
187
+ eventSchemas: SCHEMAS,
188
+ requestReplies: {
189
+ // RR :69-80: the template's assets that still exist.
190
+ ASSETS_FOR_TEMPLATE: {
191
+ source: 'FILE_STORAGE',
192
+ requestFields: ['FILE_STORAGE_ID'],
193
+ resolver: ({ request, store }) => linksOf({ store }, request.FILE_STORAGE_ID).flatMap((link) => {
194
+ const file = store.getRow('FILE_STORAGE', link.ASSET_ID);
195
+ return file ? [file] : [];
196
+ }),
197
+ },
198
+ },
199
+ httpRoutes: httpRoutes(contents, deleteFile),
200
+ };
201
+ }
202
+ // file-server-web-handler.kts (file-server-app): the router's file-server/
203
+ // endpoints, each for a logged-in user only.
204
+ function httpRoutes(contents, deleteFile) {
205
+ const endpoint = (name) => new RegExp(`/file-server/${name}/?$`);
206
+ const queryOf = (url) => new URL(url ?? '', 'http://mock').searchParams;
207
+ const loggedOut = (res) => sendNack(res, UNAUTHORIZED, 'This request needs the user to be logged in, but the current authentication status is logged out');
208
+ // A required query parameter missing: no endpoint matches (406), before
209
+ // any auth.
210
+ const missingId = (res, name) => sendNack(res, NOT_ACCEPTABLE, `Resource file-server/${name} does not accept your request, acceptable requests are:\n- Required query parameter "fileStorageId"`);
211
+ // A body over MAX_UPLOAD_BYTES: the router's refusal, before the endpoint
212
+ // runs; the connection closes rather than read the rest.
213
+ const tooLarge = (res) => {
214
+ res.setHeader('Connection', 'close');
215
+ sendNack(res, BAD_REQUEST, new BodyTooLarge(MAX_UPLOAD_BYTES).message);
216
+ };
217
+ // The multipart body's files and fields; undefined once a body that grew
218
+ // past MAX_UPLOAD_BYTES has been refused.
219
+ const formOf = async (req, res) => {
220
+ const boundary = boundaryOf(req.headers['content-type']);
221
+ let parts = [];
222
+ try {
223
+ parts = boundary ? parseMultipart(await readBody(req, MAX_UPLOAD_BYTES), boundary) : [];
224
+ }
225
+ catch (error) {
226
+ if (!(error instanceof BodyTooLarge))
227
+ throw error;
228
+ tooLarge(res);
229
+ return undefined;
230
+ }
231
+ const fields = new Map(parts
232
+ .filter((part) => part.fileName === undefined)
233
+ .map((part) => [part.name, part.data.toString('utf8')]));
234
+ return { files: parts.filter((part) => part.fileName !== undefined), fields };
235
+ };
236
+ // Where LocalFileStorageManager keeps a file: SUB_DIR/name, relative to
237
+ // its root, with (1), (2)... before the extension when that's taken; it
238
+ // then counts as taken.
239
+ const locationOf = (taken, subDir, name) => {
240
+ const path = (subDir ? `${subDir}/${name}` : name).replace(/\/+/g, '/').replace(/^\//, '');
241
+ const dot = path.lastIndexOf('.');
242
+ const [stem, extension] = dot > path.lastIndexOf('/') ? [path.slice(0, dot), path.slice(dot)] : [path, ''];
243
+ let location = path;
244
+ for (let attempt = 1; taken.has(location); attempt += 1)
245
+ location = `${stem}(${attempt})${extension}`;
246
+ taken.add(location);
247
+ return location;
248
+ };
249
+ // The bytes of files whose rows are gone some other way than the two
250
+ // deletes (the store, setTable).
251
+ const prune = (store) => {
252
+ for (const id of contents.keys())
253
+ if (!store.getRow('FILE_STORAGE', id))
254
+ contents.delete(id);
255
+ };
256
+ return [
257
+ {
258
+ method: 'POST',
259
+ path: endpoint('upload'),
260
+ handler: async (req, res, ctx) => {
261
+ if (declaredTooLarge(req, MAX_UPLOAD_BYTES))
262
+ return tooLarge(res);
263
+ if (!ctx.userName)
264
+ return loggedOut(res);
265
+ const form = await formOf(req, res);
266
+ if (!form)
267
+ return undefined;
268
+ const { files, fields } = form;
269
+ if (!files.length)
270
+ return sendNack(res, UNPROCESSABLE, 'No files uploaded');
271
+ const fileType = fields.get('FILE_TYPE') ?? 'USER_DOCUMENT';
272
+ if (!FILE_TYPES.includes(fileType)) {
273
+ return sendNack(res, UNPROCESSABLE, `No enum constant global.genesis.gen.dao.enums.FileType.${fileType}`);
274
+ }
275
+ prune(ctx.store);
276
+ const subDir = fields.get('SUB_DIR')?.trim() ? fields.get('SUB_DIR') : undefined;
277
+ const taken = new Set(ctx.store.getAllRows('FILE_STORAGE').map((row) => row.LOCATION_DETAILS));
278
+ const now = Date.now();
279
+ const ids = [];
280
+ // One file after another, each checked as it is saved
281
+ // (HttpFileServerExtension saveFile): the files before a refused one
282
+ // are kept.
283
+ for (const part of files) {
284
+ const name = baseName(part.fileName);
285
+ const error = contentError(part, name);
286
+ if (error)
287
+ return sendNack(res, ...error);
288
+ const row = ctx.store.insertRow('FILE_STORAGE', {
289
+ FILE_STORAGE_ID: newFileStorageId(),
290
+ STORAGE_MANAGER: 'LOCAL_STORAGE',
291
+ FILE_NAME: name,
292
+ FILE_SIZE: part.data.length,
293
+ MODIFIED_AT: now,
294
+ MODIFIED_BY: ctx.userName,
295
+ CREATED_BY: ctx.userName,
296
+ CREATED_AT: now,
297
+ LOCATION_DETAILS: locationOf(taken, subDir, name),
298
+ FILE_TYPE: fileType,
299
+ });
300
+ contents.set(row.FILE_STORAGE_ID, part.data);
301
+ ctx.broadcastTableChange('FILE_STORAGE', 'INSERT', row.FILE_STORAGE_ID);
302
+ ids.push({ FILE_STORAGE_ID: row.FILE_STORAGE_ID });
303
+ }
304
+ return sendJson(res, OK, ids);
305
+ },
306
+ },
307
+ {
308
+ method: 'POST',
309
+ path: endpoint('replace'),
310
+ handler: async (req, res, ctx) => {
311
+ if (declaredTooLarge(req, MAX_UPLOAD_BYTES))
312
+ return tooLarge(res);
313
+ if (!ctx.userName)
314
+ return loggedOut(res);
315
+ const form = await formOf(req, res);
316
+ if (!form)
317
+ return undefined;
318
+ const { files, fields } = form;
319
+ if (!files.length)
320
+ return sendNack(res, UNPROCESSABLE, 'No files uploaded');
321
+ if (files.length > 1)
322
+ return sendNack(res, UNPROCESSABLE, 'Only one file can be replaced at a time');
323
+ const id = fields.get('FILE_STORAGE_ID');
324
+ if (!id)
325
+ return sendNack(res, UNPROCESSABLE, 'FILE_STORAGE_ID of file to replace content must be provided');
326
+ // modifyFile checks the content before it reads the row.
327
+ const [file] = files;
328
+ if (!file.data.length) {
329
+ return sendText(res, BAD_REQUEST, 'Invalid file content. Please check that the uploaded file has content and is valid.');
330
+ }
331
+ if (!ctx.store.getRow('FILE_STORAGE', id)) {
332
+ return sendText(res, NOT_FOUND, 'File not found. Please check the FILE_STORAGE_ID parameter provided in the request body.');
333
+ }
334
+ // modifyFile: the content, its size and who changed it, under the
335
+ // same name and location.
336
+ ctx.store.updateRow('FILE_STORAGE', id, {
337
+ MODIFIED_AT: Date.now(),
338
+ MODIFIED_BY: ctx.userName,
339
+ FILE_SIZE: file.data.length,
340
+ });
341
+ contents.set(id, file.data);
342
+ ctx.broadcastTableChange('FILE_STORAGE', 'MODIFY', id);
343
+ return sendJson(res, OK, { FILE_STORAGE_ID: id });
344
+ },
345
+ },
346
+ {
347
+ method: 'GET',
348
+ path: endpoint('download'),
349
+ handler: (req, res, ctx) => {
350
+ const id = queryOf(req.url).get('fileStorageId');
351
+ if (id === null)
352
+ return missingId(res, 'download');
353
+ if (!ctx.userName)
354
+ return loggedOut(res);
355
+ const file = ctx.store.getRow('FILE_STORAGE', id);
356
+ const data = contents.get(id);
357
+ if (!file || !data) {
358
+ return sendText(res, NOT_FOUND, 'File not found. Please check correct FILE_STORAGE_ID parameter provided in the request body.');
359
+ }
360
+ res.writeHead(OK, {
361
+ 'Content-Type': CONTENT_TYPES[extensionOf(file.FILE_NAME)] ?? 'application/octet-stream',
362
+ // Unencoded, as FileResponseComposer.kt:90 writes it; Netty puts
363
+ // each UTF-16 unit above U+00FF on the wire as '?'
364
+ // (AsciiString.c2b), and Node writes the rest as Latin-1.
365
+ 'Content-disposition': `attachment; filename=${String(file.FILE_NAME).replace(/[^\u0000-\u00ff]/g, '?')}`,
366
+ 'Access-Control-Expose-Headers': 'Content-disposition, Content-Type, Accept, X-Requested-With',
367
+ 'Content-Length': data.length,
368
+ });
369
+ res.end(data);
370
+ return undefined;
371
+ },
372
+ },
373
+ {
374
+ method: 'GET',
375
+ path: endpoint('all-files'),
376
+ handler: (_req, res, ctx) => {
377
+ if (!ctx.userName)
378
+ return loggedOut(res);
379
+ return sendJson(res, OK, ctx.store.getAllRows('FILE_STORAGE').map(({ RECORD_ID, TIMESTAMP, ...row }) => row));
380
+ },
381
+ },
382
+ {
383
+ method: 'DELETE',
384
+ path: endpoint('delete'),
385
+ handler: (req, res, ctx) => {
386
+ const id = queryOf(req.url).get('fileStorageId');
387
+ if (id === null)
388
+ return missingId(res, 'delete');
389
+ if (!ctx.userName)
390
+ return loggedOut(res);
391
+ if (!id.trim())
392
+ return sendNack(res, UNPROCESSABLE, "Mandatory query parameter is missing: 'fileStorageId'");
393
+ // deleteFile: nothing to do for an unknown id.
394
+ deleteFile(ctx, id);
395
+ return sendJson(res, OK, { FILE_STORAGE_ID: id });
396
+ },
397
+ },
398
+ ];
399
+ }
@@ -0,0 +1,24 @@
1
+ import type { MockServerConfig, QueryDef, RequestReplyDef, TypedRequestReply, ViewDef } from '../types.ts';
2
+ export declare const SERVING_VIEWS: Set<string>;
3
+ /**
4
+ * GSF's getAllEntityNames (DbReflectionUtils.kt:116-123): the dictionary's
5
+ * tables, each audit table right after its table, then the views. GSF lists
6
+ * the tables by product, in its dictionary files' HashMap order (which the
7
+ * app's own file names decide), then declaration order: here, in the
8
+ * config's order.
9
+ */
10
+ export declare function entityNames(config: MockServerConfig): string[];
11
+ export declare function javaPattern(pattern: string): RegExp;
12
+ export declare function matchingNames(pattern: RegExp, names: string[]): string[];
13
+ export declare const SYSTEM_ENTITY_TYPES: TypedRequestReply;
14
+ /** system-info-reqrep.kts's two request servers. */
15
+ export declare function systemInfoRequestReplies(): Record<string, RequestReplyDef>;
16
+ export declare const SYSTEM_STATUS_BYTES: ViewDef;
17
+ /**
18
+ * StatusDataserver.java's two dataservers, on GSF's older engine (no INDEXES
19
+ * in their META), their fields in the order its HashSet of fields gives
20
+ * them. Only GSF's Resource Daemon fills GENESIS_PROCESS and SYSTEM_STATUS,
21
+ * and Genesis Start and Create's preview don't run it, so both stream no
22
+ * rows, as there.
23
+ */
24
+ export declare function statusQueries(): Record<string, QueryDef>;