@entity-access/server-pages 1.1.348 → 1.1.350

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 (83) hide show
  1. package/dist/Content.d.ts +17 -31
  2. package/dist/Content.d.ts.map +1 -1
  3. package/dist/Content.js +117 -97
  4. package/dist/Content.js.map +1 -1
  5. package/dist/Page.d.ts +2 -4
  6. package/dist/Page.d.ts.map +1 -1
  7. package/dist/Page.js +32 -24
  8. package/dist/Page.js.map +1 -1
  9. package/dist/ServerPages.d.ts.map +1 -1
  10. package/dist/ServerPages.js +9 -3
  11. package/dist/ServerPages.js.map +1 -1
  12. package/dist/core/Compression.d.ts +5 -2
  13. package/dist/core/Compression.d.ts.map +1 -1
  14. package/dist/core/Compression.js +11 -3
  15. package/dist/core/Compression.js.map +1 -1
  16. package/dist/core/Executor.d.ts +1 -1
  17. package/dist/core/RouteTree.js +1 -2
  18. package/dist/core/RouteTree.js.map +1 -1
  19. package/dist/core/Utf8Readable.d.ts +6 -0
  20. package/dist/core/Utf8Readable.d.ts.map +1 -0
  21. package/dist/core/Utf8Readable.js +12 -0
  22. package/dist/core/Utf8Readable.js.map +1 -0
  23. package/dist/core/Wrapped.d.ts +2 -4
  24. package/dist/core/Wrapped.d.ts.map +1 -1
  25. package/dist/core/Wrapped.js +115 -108
  26. package/dist/core/Wrapped.js.map +1 -1
  27. package/dist/html/HtmlComment.d.ts +1 -0
  28. package/dist/html/HtmlComment.d.ts.map +1 -1
  29. package/dist/html/HtmlComment.js +9 -0
  30. package/dist/html/HtmlComment.js.map +1 -1
  31. package/dist/html/HtmlDocument.d.ts.map +1 -1
  32. package/dist/html/HtmlDocument.js +4 -0
  33. package/dist/html/HtmlDocument.js.map +1 -1
  34. package/dist/html/XNode.d.ts +1 -0
  35. package/dist/html/XNode.d.ts.map +1 -1
  36. package/dist/html/XNode.js +38 -0
  37. package/dist/html/XNode.js.map +1 -1
  38. package/dist/routes/api/entity/expand/[entity]/[property]/[keys]/get.js +2 -2
  39. package/dist/routes/api/entity/expand/[entity]/[property]/[keys]/get.js.map +1 -1
  40. package/dist/routes/api/entity/index.d.ts +1 -1
  41. package/dist/routes/api/entity/invoke/[entityName]/[methodName]/post.d.ts +2 -2
  42. package/dist/routes/api/entity/invoke/[entityName]/[methodName]/post.d.ts.map +1 -1
  43. package/dist/routes/api/entity/invoke/[entityName]/[methodName]/post.js +9 -3
  44. package/dist/routes/api/entity/invoke/[entityName]/[methodName]/post.js.map +1 -1
  45. package/dist/routes/api/entity/model.ts/get.d.ts +2 -1
  46. package/dist/routes/api/entity/model.ts/get.d.ts.map +1 -1
  47. package/dist/routes/api/entity/model.ts/get.js +6 -1
  48. package/dist/routes/api/entity/model.ts/get.js.map +1 -1
  49. package/dist/routes/api/entity/query/[entity]/get.js +2 -2
  50. package/dist/routes/api/entity/query/[entity]/get.js.map +1 -1
  51. package/dist/routes/api/entity/run/[entity]/[methodName]/index.d.ts +2 -2
  52. package/dist/routes/api/entity/run/[entity]/[methodName]/index.d.ts.map +1 -1
  53. package/dist/routes/api/entity/run/[entity]/[methodName]/index.js +7 -3
  54. package/dist/routes/api/entity/run/[entity]/[methodName]/index.js.map +1 -1
  55. package/dist/services/DbJsonService.d.ts +5 -5
  56. package/dist/services/DbJsonService.d.ts.map +1 -1
  57. package/dist/services/DbJsonService.js +13 -7
  58. package/dist/services/DbJsonService.js.map +1 -1
  59. package/dist/services/EntityAccessServer.d.ts +1 -2
  60. package/dist/services/EntityAccessServer.d.ts.map +1 -1
  61. package/dist/services/EntityAccessServer.js +1 -8
  62. package/dist/services/EntityAccessServer.js.map +1 -1
  63. package/dist/tests/logger/index.js +1 -1
  64. package/dist/tsconfig.tsbuildinfo +1 -1
  65. package/package.json +2 -2
  66. package/src/Content.tsx +149 -120
  67. package/src/Page.tsx +34 -24
  68. package/src/ServerPages.ts +15 -6
  69. package/src/core/Compression.ts +14 -3
  70. package/src/core/RouteTree.ts +1 -1
  71. package/src/core/Utf8Readable.ts +15 -0
  72. package/src/core/Wrapped.ts +121 -111
  73. package/src/html/HtmlComment.ts +10 -0
  74. package/src/html/HtmlDocument.tsx +5 -0
  75. package/src/html/XNode.ts +58 -0
  76. package/src/routes/api/entity/expand/[entity]/[property]/[keys]/get.ts +2 -2
  77. package/src/routes/api/entity/invoke/[entityName]/[methodName]/post.tsx +9 -3
  78. package/src/routes/api/entity/model.ts/get.tsx +7 -1
  79. package/src/routes/api/entity/query/[entity]/get.ts +2 -2
  80. package/src/routes/api/entity/run/[entity]/[methodName]/index.ts +7 -5
  81. package/src/services/DbJsonService.ts +13 -8
  82. package/src/services/EntityAccessServer.ts +1 -10
  83. package/src/tests/logger/index.tsx +1 -1
@@ -58,6 +58,8 @@ export interface IWrappedRequest {
58
58
 
59
59
  accepts(): string[];
60
60
  accepts(... types: string[]): boolean;
61
+
62
+ get acceptEncodings(): string[];
61
63
  }
62
64
 
63
65
 
@@ -69,16 +71,14 @@ export interface IWrappedResponse {
69
71
 
70
72
  asyncEnd();
71
73
 
72
- asyncWrite(buffer: Buffer): Promise<void>;
73
-
74
- // setHeader(name: string, value: string);
75
74
 
75
+ sendReader(status: number, headers: OutgoingHttpHeaders, readable: Readable): Promise<void>;
76
76
 
77
- asyncPipe(status: number, headers: OutgoingHttpHeaders, readable: Readable): Promise<void>;
77
+ // sendGenerator(data: Iterable<Buffer> | AsyncIterable<Buffer>, status: number, headers?: OutgoingHttpHeaders): Promise<void>;
78
78
 
79
- send(data: Buffer | string | Blob, status?: number): Promise<void>;
79
+ // send(data: Buffer | string | Blob, status?: number): Promise<void>;
80
80
 
81
- sendStatus(status?: number, headers?: OutgoingHttpHeaders): Promise<void>;
81
+ // sendStatus(status?: number, headers?: OutgoingHttpHeaders): Promise<void>;
82
82
 
83
83
  sendRedirect(url: string, status?: number, headers?: OutgoingHttpHeaders): void;
84
84
 
@@ -119,6 +119,13 @@ const extendRequest = (A: typeof IncomingMessage | typeof Http2ServerRequest) =>
119
119
  return CacheProperty.value(this, "hostName", host);
120
120
  }
121
121
 
122
+ get acceptEncodings(): string[] {
123
+ const r = this as any as (Http2ServerRequest | IncomingMessage);
124
+ const acceptEncoding = ((r as Http2ServerRequest).authority || r.headers["accept-encoding"] || null).toString();
125
+ const encodings = acceptEncoding.split(/[\,\;]/);
126
+ return encodings;
127
+ }
128
+
122
129
  get host(): string {
123
130
  const r = this as any as (Http2ServerRequest | IncomingMessage);
124
131
  const host = (r as Http2ServerRequest).authority || r.headers[":authority"] || r.headers.host || null;
@@ -221,16 +228,19 @@ const extendResponse = (A: typeof ServerResponse | typeof Http2ServerResponse) =
221
228
  asyncEnd(this: UnwrappedResponse) {
222
229
  return new Promise<void>((resolve) => this.end(resolve));
223
230
  }
224
-
225
- asyncWrite(this: UnwrappedResponse, buffer: Buffer, start?: number, length?: number) {
226
- return new Promise<void>((resolve, reject) =>
227
- this.write(buffer, (error) => error ? reject(error) : resolve())
228
- );
229
- }
230
231
 
231
- asyncPipe(this: UnwrappedResponse, status: number, headers: OutgoingHttpHeaders, readable: Readable, signal?: AbortSignal) {
232
+ sendReader(this: UnwrappedResponse, status: number, headers: OutgoingHttpHeaders, readable: Readable, signal?: AbortSignal) {
233
+ let input = readable as any;
234
+ const encodings = (this.req as WrappedRequest).acceptEncodings;
235
+ if (encodings.includes("gzip")) {
236
+ headers["accept-encoding"] = "gzip";
237
+ input = Compression.gzip(readable);
238
+ } else if (encodings.includes("deflate")) {
239
+ headers["accept-encoding"] = "deflate";
240
+ input = Compression.deflate(readable);
241
+ }
232
242
  this.writeHead(status, headers);
233
- return pipeline(readable, this, { signal, end: true });
243
+ return pipeline(input, this, { signal, end: true });
234
244
  }
235
245
 
236
246
  cookie(this: UnwrappedResponse, name: string, value: string, options: SerializeOptions = {}) {
@@ -250,105 +260,105 @@ const extendResponse = (A: typeof ServerResponse | typeof Http2ServerResponse) =
250
260
  // headers[name] = value;
251
261
  // }
252
262
 
253
- async sendStatus(this: UnwrappedResponse, status?: number, headers?: OutgoingHttpHeaders): Promise<void> {
254
- const wrapped = (this as any as WrappedResponse);
255
- this.statusCode = status;
256
- let sent = false;
257
- try {
258
- this.writeHead(this.statusCode, headers);
259
- sent = true;
260
- return (wrapped as any).asyncEnd();
261
- } catch (error) {
262
- console.error(error);
263
- if (sent) {
264
- return (this as any).asyncEnd();
265
- }
266
- return (this as any).send(error.stack ?? error.toString(), 500);
267
- }
268
- }
263
+ // async sendStatus(this: UnwrappedResponse, status?: number, headers?: OutgoingHttpHeaders): Promise<void> {
264
+ // const wrapped = (this as any as WrappedResponse);
265
+ // this.statusCode = status;
266
+ // let sent = false;
267
+ // try {
268
+ // this.writeHead(this.statusCode, headers);
269
+ // sent = true;
270
+ // return (wrapped as any).asyncEnd();
271
+ // } catch (error) {
272
+ // console.error(error);
273
+ // if (sent) {
274
+ // return (this as any).asyncEnd();
275
+ // }
276
+ // return (this as any).send(error.stack ?? error.toString(), 500);
277
+ // }
278
+ // }
269
279
 
270
- async send(this: UnwrappedResponse, data: Buffer | string, status: number = this.statusCode || 200) {
271
- let sent = false;
272
- const wrapped = (this as any as WrappedResponse);
273
- try {
274
- wrapped.statusCode = status;
275
- const headers = this.getHeaders();
276
- headers["content-type"] ??= "text/html";
277
- if (typeof data === "string") {
278
- data = Buffer.from(data, "utf-8");
279
- let ct = headers["content-type"];
280
- if (Array.isArray(ct)) {
281
- ct = ct.join(";");
282
- } else {
283
- ct = ct.toString();
284
- }
285
- const index = ct.indexOf(";");
286
- if (index !== -1) {
287
- ct = ct.substring(0, index);
288
- }
289
- ct += "; charset=utf-8";
290
- }
291
- // compress if required...
292
- if (data === null || data === void 0) {
293
- throw new Error("Data cannot be null or undefined.");
294
- }
295
- data = wrapped.compressData(data, headers);
296
- headers["content-length"] = data.length.toString();
297
- this.writeHead(status, headers);
298
- sent = true;
299
- await StreamHelper.write(this, data);
300
- return (this as any).asyncEnd();
301
- } catch (error) {
302
- console.error(error);
303
- if (sent) {
304
- return (this as any).asyncEnd();
305
- }
306
- if (this.statusCode === 500) {
307
- // recursive...
308
- try {
309
- await StreamHelper.write(this, Buffer.from("", "utf-8"))
310
- return (this as any).asyncEnd();
311
- } catch (er) {
312
- console.error(er);
313
- return (this as any).asyncEnd();
314
- }
315
- }
316
- return (this as any).send(error.stack ?? error.toString(), 500);
317
- }
318
- }
280
+ // async send(this: UnwrappedResponse, data: Buffer | string, status: number = this.statusCode || 200) {
281
+ // let sent = false;
282
+ // const wrapped = (this as any as WrappedResponse);
283
+ // try {
284
+ // wrapped.statusCode = status;
285
+ // const headers = this.getHeaders();
286
+ // headers["content-type"] ??= "text/html";
287
+ // if (typeof data === "string") {
288
+ // data = Buffer.from(data, "utf-8");
289
+ // let ct = headers["content-type"];
290
+ // if (Array.isArray(ct)) {
291
+ // ct = ct.join(";");
292
+ // } else {
293
+ // ct = ct.toString();
294
+ // }
295
+ // const index = ct.indexOf(";");
296
+ // if (index !== -1) {
297
+ // ct = ct.substring(0, index);
298
+ // }
299
+ // ct += "; charset=utf-8";
300
+ // }
301
+ // // compress if required...
302
+ // if (data === null || data === void 0) {
303
+ // throw new Error("Data cannot be null or undefined.");
304
+ // }
305
+ // data = wrapped.compressData(data, headers);
306
+ // headers["content-length"] = data.length.toString();
307
+ // this.writeHead(status, headers);
308
+ // sent = true;
309
+ // await StreamHelper.write(this, data);
310
+ // return (this as any).asyncEnd();
311
+ // } catch (error) {
312
+ // console.error(error);
313
+ // if (sent) {
314
+ // return (this as any).asyncEnd();
315
+ // }
316
+ // if (this.statusCode === 500) {
317
+ // // recursive...
318
+ // try {
319
+ // await StreamHelper.write(this, Buffer.from("", "utf-8"))
320
+ // return (this as any).asyncEnd();
321
+ // } catch (er) {
322
+ // console.error(er);
323
+ // return (this as any).asyncEnd();
324
+ // }
325
+ // }
326
+ // return (this as any).send(error.stack ?? error.toString(), 500);
327
+ // }
328
+ // }
319
329
 
320
- private compressData(data: string | Buffer, headers: OutgoingHttpHeaders) {
321
- const { compress } = this;
322
- if (!compress) {
323
- return data;
324
- }
325
- let { "accept-encoding": accept } = (this as IWrappedResponse).request?.headers;
326
- if (!accept) {
327
- return data;
328
- }
329
- if (typeof accept === "string") {
330
- accept = accept.split(",");
331
- } else {
332
- if (!Array.isArray(accept)) {
333
- return data;
334
- }
335
- accept = accept.flatMap((x) => x.split(","));
336
- }
337
- if (!accept.includes(compress)) {
338
- return data;
339
- }
340
- switch (compress) {
341
- case "deflate":
342
- data = Compression.deflate(data);
343
- headers["content-encoding"] = compress;
344
- break;
345
- case "gzip":
346
- data = Compression.gzip(data);
347
- headers["content-encoding"] = compress;
348
- break;
349
- }
350
- return data;
351
- }
330
+ // private compressData(data: string | Buffer, headers: OutgoingHttpHeaders) {
331
+ // const { compress } = this;
332
+ // if (!compress) {
333
+ // return data;
334
+ // }
335
+ // let { "accept-encoding": accept } = (this as IWrappedResponse).request?.headers;
336
+ // if (!accept) {
337
+ // return data;
338
+ // }
339
+ // if (typeof accept === "string") {
340
+ // accept = accept.split(",");
341
+ // } else {
342
+ // if (!Array.isArray(accept)) {
343
+ // return data;
344
+ // }
345
+ // accept = accept.flatMap((x) => x.split(","));
346
+ // }
347
+ // if (!accept.includes(compress)) {
348
+ // return data;
349
+ // }
350
+ // switch (compress) {
351
+ // case "deflate":
352
+ // data = Compression.deflateSync(data);
353
+ // headers["content-encoding"] = compress;
354
+ // break;
355
+ // case "gzip":
356
+ // data = Compression.gzipSync(data);
357
+ // headers["content-encoding"] = compress;
358
+ // break;
359
+ // }
360
+ // return data;
361
+ // }
352
362
 
353
363
  async sendRedirect(this: UnwrappedResponse, location: string, status = 301, headers: OutgoingHttpHeaders = {}) {
354
364
  this.statusCode = status;
@@ -15,6 +15,16 @@ class Comment extends XNode {
15
15
  return `<!--${comments}-->`
16
16
  }
17
17
 
18
+ public *readable(nest?: string) {
19
+ nest ??= "";
20
+ yield "<!--";
21
+ for (const element of this.nodes) {
22
+ yield nest;
23
+ yield element;
24
+ yield "\n";
25
+ }
26
+ }
27
+
18
28
  }
19
29
 
20
30
  export default function HtmlComment({}, ... nodes: string[]) {
@@ -9,6 +9,11 @@ class DocumentNode extends XNode {
9
9
  public render(nest?: string): string {
10
10
  return `<!DOCTYPE html>\n${super.render(nest)}`;
11
11
  }
12
+
13
+ public * readable(nest?: string) {
14
+ yield `<!DOCTYPE html>\n`;
15
+ yield * super.readable(nest);
16
+ }
12
17
  }
13
18
 
14
19
  export default function HtmlDocument({ lang = "en"}, ... nodes: (XNode | string)[]): XNode {
package/src/html/XNode.ts CHANGED
@@ -1,6 +1,14 @@
1
1
  // use parse5 to serialize html correctly
2
2
  import { escapeText, escapeAttribute } from "entities";
3
3
 
4
+ type INodeToken = {
5
+ target: XNode;
6
+ token?: never;
7
+ } | {
8
+ token: string;
9
+ target?: never;
10
+ }
11
+
4
12
  export default class XNode {
5
13
 
6
14
  public static create(
@@ -55,4 +63,54 @@ export default class XNode {
55
63
  return `${nest}<${name}${a}>\n${nest}\t${children.join("\n\t")}\n${nest}</${name}>`;
56
64
  }
57
65
 
66
+ public *readable(nest = "") {
67
+
68
+ const { name, attributes, children } = this;
69
+
70
+ if (nest) {
71
+ yield nest;
72
+ }
73
+
74
+ yield `<${name}`;
75
+
76
+ if (attributes) {
77
+ for (const key in attributes) {
78
+ if (Object.hasOwn(attributes, key)) {
79
+ const element = attributes[key];
80
+
81
+ if (nest) {
82
+ yield nest + "\t";
83
+ }
84
+ yield `${escapeAttribute(key)}="${escapeAttribute(element)}"\n`;
85
+ }
86
+ }
87
+ }
88
+
89
+ if (nest) {
90
+ yield nest;
91
+ }
92
+
93
+ yield ">\n";
94
+
95
+ if (children) {
96
+ for (const child of children) {
97
+ if (typeof child === "string") {
98
+ yield escapeText(child);
99
+ continue;
100
+ }
101
+ if (!child) {
102
+ continue;
103
+ }
104
+ yield * child.readable(nest + "\t");
105
+ }
106
+ }
107
+
108
+ if (nest) {
109
+ yield nest;
110
+ }
111
+
112
+ yield `</${name}>`;
113
+
114
+ }
115
+
58
116
  }
@@ -42,13 +42,13 @@ export default class extends Page {
42
42
  this.cacheControl = `public, max-age=${cache}`;
43
43
  }
44
44
 
45
- return this.json(await EntityAccessServer.query(this.db, {
45
+ return await EntityAccessServer.query(this.db, {
46
46
  entity,
47
47
  expand,
48
48
  expandKeys,
49
49
  ... this.query,
50
50
  ... this.body
51
- }, this.sessionUser));
51
+ });
52
52
  }
53
53
 
54
54
  }
@@ -6,7 +6,8 @@ import SchemaRegistry from "@entity-access/entity-access/dist/decorators/SchemaR
6
6
  import EntityAccessError from "@entity-access/entity-access/dist/common/EntityAccessError.js";
7
7
  import ExternalInvoke from "../../../../../../decorators/ExternalInvoke.js";
8
8
  import { Route } from "../../../../../../core/Route.js";
9
- import Content, { PageResult } from "../../../../../../Content.js";
9
+ import Content from "../../../../../../Content.js";
10
+ import DbJsonReadable from "../../../../../../services/DbJsonService.js";
10
11
 
11
12
  export default class extends Page {
12
13
 
@@ -62,7 +63,7 @@ export default class extends Page {
62
63
  // now execute external method
63
64
  const result = await events[methodName](e, ... args);
64
65
 
65
- if (result instanceof PageResult) {
66
+ if (result instanceof Content) {
66
67
  return result;
67
68
  }
68
69
 
@@ -71,9 +72,14 @@ export default class extends Page {
71
72
  // ? GraphService.prepareGraph(result, this.sessionUser)
72
73
  // : {});
73
74
  if (!result) {
74
- return this.content({ body:"{}", contentType: "application/json"});
75
+ return Content.text("{}", {
76
+ headers: {
77
+ "content-type": "application/json; charset=utf8"
78
+ }
79
+ });
75
80
  }
76
81
 
82
+ return DbJsonReadable.toJson(this.db, result);
77
83
 
78
84
  }
79
85
  }
@@ -2,6 +2,7 @@ import Inject from "@entity-access/entity-access/dist/di/di.js";
2
2
  import EntityContext from "@entity-access/entity-access/dist/model/EntityContext.js";
3
3
  import Page from "../../../../Page.js";
4
4
  import ModelService from "../../../../services/ModelService.js";
5
+ import Content from "../../../../Content.js";
5
6
 
6
7
  export default class extends Page {
7
8
 
@@ -10,7 +11,12 @@ export default class extends Page {
10
11
 
11
12
  run() {
12
13
 
13
- return this.content(ModelService.getModelDeclaration(this.db), 200, "text/typescript");
14
+ return Content.text(
15
+ ModelService.getModelDeclaration(this.db), {
16
+ headers: {
17
+ "content-type": "text/typescript; charset=utf8"
18
+ }
19
+ });
14
20
  }
15
21
 
16
22
  }
@@ -25,11 +25,11 @@ export default class extends Page {
25
25
  this.cacheControl = `public, max-age=${cache}`;
26
26
  }
27
27
 
28
- return this.json(await EntityAccessServer.query(this.db, {
28
+ return await EntityAccessServer.query(this.db, {
29
29
  entity,
30
30
  ... this.query,
31
31
  ... this.body
32
- }, this.sessionUser));
32
+ });
33
33
  }
34
34
 
35
35
  }
@@ -3,14 +3,12 @@ import EntityContext from "@entity-access/entity-access/dist/model/EntityContext
3
3
  import Page from "../../../../../../Page.js";
4
4
  import { Route } from "../../../../../../core/Route.js";
5
5
  import { Prepare } from "../../../../../../decorators/Prepare.js";
6
- import EntityAccessServer from "../../../../../../services/EntityAccessServer.js";
7
- import SessionEncryption from "../../../../../../services/SessionEncryption.js";
8
6
  import EntityAccessError from "@entity-access/entity-access/dist/common/EntityAccessError.js";
9
7
  import SchemaRegistry from "@entity-access/entity-access/dist/decorators/SchemaRegistry.js";
10
- import { PageResult } from "../../../../../../Content.js";
11
8
  import ExternalInvoke from "../../../../../../decorators/ExternalInvoke.js";
12
9
  import JsonService from "../../../../../../services/DbJsonService.js";
13
10
  import SessionSecurity from "../../../../../../services/SessionSecurity.js";
11
+ import Content from "../../../../../../Content.js";
14
12
 
15
13
  @Prepare.authorize
16
14
  @Prepare.parseJsonBody
@@ -63,12 +61,16 @@ export default class extends Page {
63
61
  // now execute external method
64
62
  const result = await events[methodName](entity, ... args);
65
63
 
66
- if (result instanceof PageResult) {
64
+ if (result instanceof Content) {
67
65
  return result;
68
66
  }
69
67
 
70
68
  if (!result) {
71
- return this.content({ body: "{}", contentType: "application/json"});
69
+ return Content.text("{}", {
70
+ headers: {
71
+ "content-type": "application/json; charset=utf8"
72
+ }
73
+ });
72
74
  }
73
75
 
74
76
  return JsonService.toJson(this.db, result);
@@ -1,18 +1,23 @@
1
- import JsonReadable from "@entity-access/entity-access/dist/common/JsonReadable.js";
2
- import { JsonReaderResult } from "../Content.js";
1
+ import JsonGenerator from "@entity-access/entity-access/dist/common/JsonGenerator.js";
3
2
  import EntityContext from "@entity-access/entity-access/dist/model/EntityContext.js";
3
+ import Content from "../Content.js";
4
4
 
5
- export default class DbJsonReadable extends JsonReadable {
5
+ export default class DbJsonReadable extends JsonGenerator {
6
6
 
7
7
  static toJson(db: EntityContext, item: any) {
8
- const js = new DbJsonReadable(db, item);
9
- return new JsonReaderResult(js);
8
+ const js = new DbJsonReadable(db);
9
+ const reader = js.reader(item);
10
+ return new Content({
11
+ reader,
12
+ headers: {
13
+ "content-type": "application/json; charset=utf8"
14
+ }
15
+ });
10
16
  }
11
17
 
12
18
  constructor(
13
- private readonly db: EntityContext,
14
- model: any) {
15
- super(model, db)
19
+ private readonly db: EntityContext) {
20
+ super(db)
16
21
  }
17
22
 
18
23
  preJSON(item: any) {
@@ -43,8 +43,7 @@ export default class EntityAccessServer {
43
43
 
44
44
  public static async query(
45
45
  db: EntityContext,
46
- options: IEntityQueryOptions,
47
- user: SessionUser) {
46
+ options: IEntityQueryOptions) {
48
47
 
49
48
  db.verifyFilters = true;
50
49
  db.raiseEvents = true;
@@ -133,8 +132,6 @@ export default class EntityAccessServer {
133
132
 
134
133
  let items;
135
134
 
136
- const beforeSerialize = (events as any).beforeSerialize as Function;
137
-
138
135
 
139
136
  if (count) {
140
137
  const total = await oq.count();
@@ -142,9 +139,6 @@ export default class EntityAccessServer {
142
139
  q = q.trace(console.log);
143
140
  }
144
141
  items = await q.toArray();
145
- if (beforeSerialize) {
146
- await beforeSerialize.call(events, items);
147
- }
148
142
  return DbJsonService.toJson(db, {
149
143
  total,
150
144
  items
@@ -155,9 +149,6 @@ export default class EntityAccessServer {
155
149
  q = q.trace(console.log);
156
150
  }
157
151
  items = await q.toArray();
158
- if (beforeSerialize) {
159
- await beforeSerialize.call(events, items);
160
- }
161
152
  return DbJsonService.toJson(db, {
162
153
  total: 0,
163
154
  items
@@ -12,7 +12,7 @@ export default function(this: Page) {
12
12
  }
13
13
  }
14
14
 
15
- return Content.html(<HtmlDocument>
15
+ return Content.text(<HtmlDocument>
16
16
  <body>
17
17
  Test 1
18
18
  </body>