structured-fw 1.2.1 → 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 +1 -1
- package/build/system/client/ClientComponent.js +9 -4
- package/build/system/server/Application.js +1 -1
- package/build/system/server/Document.d.ts +2 -1
- package/build/system/server/Document.js +2 -1
- package/build/system/server/Request.js +4 -4
- package/build/system/types/request.types.d.ts +1 -1
- package/package.json +1 -1
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,
|
|
@@ -102,10 +102,15 @@ export class ClientComponent extends EventEmitter {
|
|
|
102
102
|
}
|
|
103
103
|
const initializer = this.app.getInitializer(this.name);
|
|
104
104
|
if (initializer !== null) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
try {
|
|
106
|
+
await initializer.apply(this, [{
|
|
107
|
+
net: this.net,
|
|
108
|
+
isRedraw
|
|
109
|
+
}]);
|
|
110
|
+
}
|
|
111
|
+
catch (e) {
|
|
112
|
+
this.error(`Initializer error: ${e.stack}`);
|
|
113
|
+
}
|
|
109
114
|
this.updateConditionals(false);
|
|
110
115
|
}
|
|
111
116
|
await this.emitterReady();
|
|
@@ -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
|
|
@@ -7,6 +7,7 @@ import { DocumentHead } from './DocumentHead.js';
|
|
|
7
7
|
import { Component } from './Component.js';
|
|
8
8
|
export declare class Document extends Component<{
|
|
9
9
|
'componentCreated': Component;
|
|
10
|
+
'beforeRender': void;
|
|
10
11
|
}> {
|
|
11
12
|
head: DocumentHead;
|
|
12
13
|
language: string;
|
|
@@ -23,7 +24,7 @@ export declare class Document extends Component<{
|
|
|
23
24
|
body(): string;
|
|
24
25
|
initInitializers(): Record<string, string>;
|
|
25
26
|
private initClientConfig;
|
|
26
|
-
toString(): string
|
|
27
|
+
toString(): Promise<string>;
|
|
27
28
|
allocateId(): string;
|
|
28
29
|
loadView(pathRelative: string, data?: LooseObject): Promise<Document>;
|
|
29
30
|
loadComponent(componentName: string, data?: LooseObject): Promise<Document>;
|
|
@@ -59,7 +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() {
|
|
62
|
+
async toString() {
|
|
63
|
+
await this.emit('beforeRender');
|
|
63
64
|
if (!this.initializersInitialized) {
|
|
64
65
|
this.initInitializers();
|
|
65
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.
|
|
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",
|