@jwn-js/common 2.0.36 → 2.0.39
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/ApiError.d.ts +4 -4
- package/docs/assets/search.js +1 -1
- package/docs/classes/ApiError.html +5 -5
- package/docs/classes/AsyncJwt.html +1 -1
- package/docs/classes/Controller.html +4 -4
- package/docs/classes/Jwt.html +1 -1
- package/docs/classes/Memcached.html +1 -1
- package/docs/classes/Model.html +1 -1
- package/docs/classes/Server.html +1 -1
- package/docs/classes/Ssr.html +1 -1
- package/docs/classes/Web.html +2 -2
- package/docs/index.html +2 -2
- package/docs/interfaces/ApiErrorMessage.html +1 -1
- package/docs/interfaces/ContextSsr.html +1 -1
- package/docs/interfaces/ContextWeb.html +1 -1
- package/docs/interfaces/OptionsSsr.html +1 -1
- package/docs/interfaces/OptionsWeb.html +1 -1
- package/docs/interfaces/ResponseOptions.html +1 -1
- package/docs/interfaces/Route.html +1 -1
- package/docs/interfaces/Schema.html +1 -1
- package/docs/interfaces/ServerHandler.html +1 -1
- package/docs/interfaces/ServerOptions.html +1 -1
- package/docs/interfaces/ServerWebsocket.html +1 -1
- package/docs/modules.html +2 -2
- package/index.d.ts +7 -7
- package/index.js +59 -26
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1169,16 +1169,15 @@ class Web {
|
|
|
1169
1169
|
if (["get", "head"].includes(this.contextWeb.method) && this.contextWeb?.stack?.memcached instanceof Memcached) {
|
|
1170
1170
|
const memcached = this.contextWeb.stack.memcached;
|
|
1171
1171
|
if (memcached.isConnectedServers()) {
|
|
1172
|
-
memcached.getPage(this.memcachedKey)
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
});
|
|
1172
|
+
const cache = await memcached.getPage(this.memcachedKey);
|
|
1173
|
+
if (cache) {
|
|
1174
|
+
const { data, headers } = cache;
|
|
1175
|
+
this.success({
|
|
1176
|
+
body: data.toString(),
|
|
1177
|
+
headers,
|
|
1178
|
+
statusCode: 200
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1182
1181
|
}
|
|
1183
1182
|
}
|
|
1184
1183
|
request.controller = request.controller || this.defaultControllerSubaction.controller;
|
|
@@ -1201,6 +1200,13 @@ class Web {
|
|
|
1201
1200
|
const records = xmljs__default["default"].xml2js(raw, { compact: true, cdataKey: "_value", textKey: "_value" });
|
|
1202
1201
|
Object.assign(request, records || {});
|
|
1203
1202
|
} else if (type.indexOf("stream") !== -1) {
|
|
1203
|
+
Object.defineProperty(this.contextWeb, "$stream", {
|
|
1204
|
+
enumerable: false,
|
|
1205
|
+
configurable: false,
|
|
1206
|
+
writable: false,
|
|
1207
|
+
value: streamBody(this.res, this.req, false)
|
|
1208
|
+
});
|
|
1209
|
+
} else if (type.indexOf("binary") !== -1) {
|
|
1204
1210
|
await new Promise((resolve) => {
|
|
1205
1211
|
const stream = streamBody(this.res, this.req);
|
|
1206
1212
|
const temp = os__namespace.tmpdir();
|
|
@@ -1216,13 +1222,6 @@ class Web {
|
|
|
1216
1222
|
});
|
|
1217
1223
|
stream.on("end", () => resolve(true));
|
|
1218
1224
|
});
|
|
1219
|
-
} else if (type.indexOf("binary") !== -1) {
|
|
1220
|
-
Object.defineProperty(this.contextWeb, "$stream", {
|
|
1221
|
-
enumerable: false,
|
|
1222
|
-
configurable: false,
|
|
1223
|
-
writable: false,
|
|
1224
|
-
value: streamBody(this.res, this.req, false)
|
|
1225
|
-
});
|
|
1226
1225
|
} else {
|
|
1227
1226
|
Object.defineProperty(this.contextWeb, "$body", {
|
|
1228
1227
|
enumerable: false,
|
|
@@ -1316,28 +1315,62 @@ class Web {
|
|
|
1316
1315
|
}
|
|
1317
1316
|
}
|
|
1318
1317
|
success(response) {
|
|
1318
|
+
const isStream = response.body instanceof stream$1.Stream;
|
|
1319
1319
|
const code = response.statusCode || 200;
|
|
1320
1320
|
const status = codeToStatus(code);
|
|
1321
|
-
const body = easyAsh.isObject(response.body) ? JSON.stringify(response.body) : response.body;
|
|
1322
|
-
if (["get", "head"].includes(this.contextWeb.method) && code === 200 && response.memcache && this.contextWeb?.stack?.memcached instanceof Memcached) {
|
|
1321
|
+
const body = !isStream && easyAsh.isObject(response.body) ? JSON.stringify(response.body) : response.body;
|
|
1322
|
+
if (!isStream && ["get", "head"].includes(this.contextWeb.method) && code === 200 && response.memcache && this.contextWeb?.stack?.memcached instanceof Memcached) {
|
|
1323
1323
|
const memcached = this.contextWeb.stack.memcached;
|
|
1324
1324
|
memcached.setPage(this.memcachedKey, response.headers, body, response.memcache).then();
|
|
1325
1325
|
}
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1326
|
+
if (!isStream) {
|
|
1327
|
+
this.res.cork(() => {
|
|
1328
|
+
this.res.writeStatus(status);
|
|
1329
|
+
Object.entries(response.headers).map(([key, value]) => this.res.writeHeader(key, value));
|
|
1330
|
+
this.res.end(body);
|
|
1331
|
+
});
|
|
1332
|
+
} else {
|
|
1333
|
+
this.res.cork(() => {
|
|
1334
|
+
this.res.writeStatus(status);
|
|
1335
|
+
Object.entries(response.headers).map(([key, value]) => this.res.writeHeader(key, value));
|
|
1336
|
+
body.on("data", (chunk) => {
|
|
1337
|
+
this.res.write(chunk);
|
|
1338
|
+
}).on("end", () => {
|
|
1339
|
+
this.res.end();
|
|
1340
|
+
});
|
|
1341
|
+
});
|
|
1342
|
+
}
|
|
1329
1343
|
}
|
|
1330
1344
|
error(e) {
|
|
1345
|
+
const isStream = e instanceof ApiError.ApiError && e.getData() instanceof stream$1.Stream;
|
|
1331
1346
|
let status = codeToStatus(404), headers = this.defaultResponse.headers, body = e.message;
|
|
1332
1347
|
if (e instanceof ApiError.ApiError) {
|
|
1333
1348
|
const data = { isError: true, code: e.getCode(), error: e.getMessage() };
|
|
1334
1349
|
status = codeToStatus(e.getStatusCode());
|
|
1335
1350
|
headers = e.getHeaders() || this.defaultResponse.headers;
|
|
1336
|
-
|
|
1351
|
+
if (isStream) {
|
|
1352
|
+
body = e.getData();
|
|
1353
|
+
} else {
|
|
1354
|
+
body = easyAsh.isObject(e.getData()) && Object.keys(e.getData()).length > 0 ? JSON.stringify(e.getData()) : JSON.stringify(data);
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
if (!isStream) {
|
|
1358
|
+
this.res.cork(() => {
|
|
1359
|
+
this.res.writeStatus(status);
|
|
1360
|
+
Object.entries(headers).map(([key, value]) => this.res.writeHeader(key, value));
|
|
1361
|
+
this.res.end(body);
|
|
1362
|
+
});
|
|
1363
|
+
} else {
|
|
1364
|
+
this.res.cork(() => {
|
|
1365
|
+
this.res.writeStatus(status);
|
|
1366
|
+
Object.entries(headers).map(([key, value]) => this.res.writeHeader(key, value));
|
|
1367
|
+
body.on("data", (chunk) => {
|
|
1368
|
+
this.res.write(chunk);
|
|
1369
|
+
}).on("end", () => {
|
|
1370
|
+
this.res.end();
|
|
1371
|
+
});
|
|
1372
|
+
});
|
|
1337
1373
|
}
|
|
1338
|
-
this.res.writeStatus(status);
|
|
1339
|
-
Object.entries(headers).map(([key, value]) => this.res.writeHeader(key, value));
|
|
1340
|
-
this.res.end(body);
|
|
1341
1374
|
}
|
|
1342
1375
|
}
|
|
1343
1376
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jwn-js/common",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.39",
|
|
5
5
|
"description": "@jwn-js/common package",
|
|
6
6
|
"main": "./index.js",
|
|
7
7
|
"types": "./index.d.ts",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"buildmsql": "^1.3.17",
|
|
47
|
-
"easy-ash": "^1.1.
|
|
47
|
+
"easy-ash": "^1.1.8",
|
|
48
48
|
"formidable": "2",
|
|
49
49
|
"memjs": "^1.3.0",
|
|
50
50
|
"reflect-metadata": "^0.1.13",
|