structured-fw 1.2.2 → 1.2.3

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.
package/README.md CHANGED
@@ -290,7 +290,7 @@ type RequestContext<Body extends LooseObject | undefined = LooseObject> = {
290
290
  getArgs: PostedDataDecoded,
291
291
 
292
292
  // send given data as a response
293
- respondWith: (data: any) => void,
293
+ respondWith: (data: any) => Promise<void>,
294
294
 
295
295
  // redirect to given url, with given statusCode
296
296
  redirect: (to: string, statusCode?: number) => void,
@@ -158,7 +158,7 @@ export class Application {
158
158
  prev[curr] = document.children[0].data[curr];
159
159
  return prev;
160
160
  }, {}) : {});
161
- ctx.respondWith({
161
+ await ctx.respondWith({
162
162
  html: document.children[0].dom[unwrap ? 'innerHTML' : 'outerHTML'],
163
163
  initializers: document.initInitializers(),
164
164
  data: exportedData
@@ -24,7 +24,7 @@ export declare class Document extends Component<{
24
24
  body(): string;
25
25
  initInitializers(): Record<string, string>;
26
26
  private initClientConfig;
27
- toString(): string;
27
+ toString(): Promise<string>;
28
28
  allocateId(): string;
29
29
  loadView(pathRelative: string, data?: LooseObject): Promise<Document>;
30
30
  loadComponent(componentName: string, data?: LooseObject): Promise<Document>;
@@ -59,8 +59,8 @@ export class Document extends Component {
59
59
  const clientConfString = `<script type="application/javascript">window.structuredClientConfig = ${JSON.stringify(clientConf)}</script>`;
60
60
  this.head.add(clientConfString);
61
61
  }
62
- toString() {
63
- this.emit('beforeRender');
62
+ async toString() {
63
+ await this.emit('beforeRender');
64
64
  if (!this.initializersInitialized) {
65
65
  this.initInitializers();
66
66
  this.initClientConfig();
@@ -107,7 +107,7 @@ export class Request {
107
107
  cookies: this.app.cookies.parse(request),
108
108
  timeStart: new Date().getTime(),
109
109
  isAjax: request.headers['x-requested-with'] == 'xmlhttprequest',
110
- respondWith: function (data) {
110
+ respondWith: async function (data) {
111
111
  if (typeof data === 'string' || Buffer.isBuffer(data)) {
112
112
  response.write(data);
113
113
  }
@@ -116,7 +116,7 @@ export class Request {
116
116
  }
117
117
  else if (data instanceof Document) {
118
118
  response.setHeader('Content-Type', 'text/html');
119
- response.write(data.toString());
119
+ response.write(await data.toString());
120
120
  }
121
121
  else if (data === undefined || data === null) {
122
122
  response.write('');
@@ -134,7 +134,7 @@ export class Request {
134
134
  response.statusCode = 404;
135
135
  const res = await this.pageNotFoundCallback.apply(this.app, [context]);
136
136
  if (res instanceof Document) {
137
- context.respondWith(res);
137
+ await context.respondWith(res);
138
138
  }
139
139
  }
140
140
  };
@@ -157,7 +157,7 @@ export class Request {
157
157
  try {
158
158
  const response = await handler.callback.apply(handler.scope, [context]);
159
159
  if (!context.response.headersSent) {
160
- context.respondWith(response);
160
+ await context.respondWith(response);
161
161
  }
162
162
  }
163
163
  catch (e) {
@@ -24,7 +24,7 @@ export type RequestContext<Body extends LooseObject | undefined = LooseObject> =
24
24
  isAjax: boolean;
25
25
  getArgs: PostedDataDecoded;
26
26
  timeStart: number;
27
- respondWith: (data: any) => void;
27
+ respondWith: (data: any) => Promise<void>;
28
28
  redirect: (to: string, statusCode?: number) => void;
29
29
  show404: () => Promise<void>;
30
30
  };
package/package.json CHANGED
@@ -19,7 +19,7 @@
19
19
  "license": "MIT",
20
20
  "type": "module",
21
21
  "main": "build/index",
22
- "version": "1.2.2",
22
+ "version": "1.2.3",
23
23
  "scripts": {
24
24
  "develop": "tsc --watch",
25
25
  "startDev": "cd build && nodemon --watch '../app/**/*' --watch '../build/**/*' -e js,html,hbs,css index.js",