@simplysm/service-common 13.0.76 → 13.0.78
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 +43 -6
- package/dist/protocol/create-service-protocol.d.ts.map +1 -1
- package/dist/protocol/create-service-protocol.js +7 -8
- package/dist/protocol/create-service-protocol.js.map +1 -1
- package/dist/service-types/smtp-client-service.types.d.ts +1 -1
- package/dist/service-types/smtp-client-service.types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/protocol/create-service-protocol.ts +6 -7
- package/src/service-types/smtp-client-service.types.ts +1 -1
- package/tests/protocol/service-protocol.spec.ts +13 -13
package/README.md
CHANGED
|
@@ -104,10 +104,20 @@ const msg: ServiceErrorMessage = {
|
|
|
104
104
|
code: "NOT_FOUND",
|
|
105
105
|
stack: "...",
|
|
106
106
|
detail: { id: 42 },
|
|
107
|
+
cause: undefined,
|
|
107
108
|
},
|
|
108
109
|
};
|
|
109
110
|
```
|
|
110
111
|
|
|
112
|
+
| Field | Required | Description |
|
|
113
|
+
|---|---|---|
|
|
114
|
+
| `name` | yes | Error class name |
|
|
115
|
+
| `message` | yes | Error message |
|
|
116
|
+
| `code` | yes | Error code string |
|
|
117
|
+
| `stack` | no | Stack trace |
|
|
118
|
+
| `detail` | no | Additional context |
|
|
119
|
+
| `cause` | no | Underlying cause |
|
|
120
|
+
|
|
111
121
|
#### `ServiceAuthMessage`
|
|
112
122
|
|
|
113
123
|
Client-sent authentication message carrying a token.
|
|
@@ -301,8 +311,8 @@ import type { OrmService } from "@simplysm/service-common";
|
|
|
301
311
|
|
|
302
312
|
| Method | Description |
|
|
303
313
|
|---|---|
|
|
304
|
-
| `getInfo(opt)` | Returns dialect, database, and schema for a connection config |
|
|
305
|
-
| `connect(opt)` | Opens a connection and returns a connection ID |
|
|
314
|
+
| `getInfo(opt)` | Returns dialect, database, and schema for a named connection config |
|
|
315
|
+
| `connect(opt)` | Opens a connection using an inline config object and returns a connection ID |
|
|
306
316
|
| `close(connId)` | Closes the connection |
|
|
307
317
|
| `beginTransaction(connId, isolationLevel?)` | Begins a transaction |
|
|
308
318
|
| `commitTransaction(connId)` | Commits the current transaction |
|
|
@@ -311,6 +321,33 @@ import type { OrmService } from "@simplysm/service-common";
|
|
|
311
321
|
| `executeDefs(connId, defs, options?)` | Executes a list of `QueryDef` objects |
|
|
312
322
|
| `bulkInsert(connId, tableName, columnDefs, records)` | Performs a bulk insert |
|
|
313
323
|
|
|
324
|
+
**Signatures**
|
|
325
|
+
|
|
326
|
+
```ts
|
|
327
|
+
getInfo(opt: DbConnOptions & { configName: string }): Promise<{
|
|
328
|
+
dialect: Dialect;
|
|
329
|
+
database?: string;
|
|
330
|
+
schema?: string;
|
|
331
|
+
}>;
|
|
332
|
+
|
|
333
|
+
connect(opt: Record<string, unknown>): Promise<number>;
|
|
334
|
+
|
|
335
|
+
executeParametrized(connId: number, query: string, params?: unknown[]): Promise<unknown[][]>;
|
|
336
|
+
|
|
337
|
+
executeDefs(
|
|
338
|
+
connId: number,
|
|
339
|
+
defs: QueryDef[],
|
|
340
|
+
options?: (ResultMeta | undefined)[],
|
|
341
|
+
): Promise<unknown[][]>;
|
|
342
|
+
|
|
343
|
+
bulkInsert(
|
|
344
|
+
connId: number,
|
|
345
|
+
tableName: string,
|
|
346
|
+
columnDefs: Record<string, ColumnMeta>,
|
|
347
|
+
records: Record<string, unknown>[],
|
|
348
|
+
): Promise<void>;
|
|
349
|
+
```
|
|
350
|
+
|
|
314
351
|
---
|
|
315
352
|
|
|
316
353
|
### `DbConnOptions`
|
|
@@ -321,7 +358,7 @@ Options for selecting a database connection configuration.
|
|
|
321
358
|
import type { DbConnOptions } from "@simplysm/service-common";
|
|
322
359
|
|
|
323
360
|
type DbConnOptions = {
|
|
324
|
-
configName?: string;
|
|
361
|
+
configName?: string; // Named config key
|
|
325
362
|
config?: Record<string, unknown>; // Inline config object
|
|
326
363
|
};
|
|
327
364
|
```
|
|
@@ -414,14 +451,14 @@ interface SmtpClientSendOption {
|
|
|
414
451
|
|
|
415
452
|
---
|
|
416
453
|
|
|
417
|
-
### `
|
|
454
|
+
### `SmtpClientDefaultOptions`
|
|
418
455
|
|
|
419
456
|
Configuration for a default SMTP sender used server-side.
|
|
420
457
|
|
|
421
458
|
```ts
|
|
422
|
-
import type {
|
|
459
|
+
import type { SmtpClientDefaultOptions } from "@simplysm/service-common";
|
|
423
460
|
|
|
424
|
-
interface
|
|
461
|
+
interface SmtpClientDefaultOptions {
|
|
425
462
|
senderName: string;
|
|
426
463
|
senderEmail?: string;
|
|
427
464
|
user?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-service-protocol.d.ts","sourceRoot":"","sources":["..\\..\\src\\protocol\\create-service-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"create-service-protocol.d.ts","sourceRoot":"","sources":["..\\..\\src\\protocol\\create-service-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,uBAAuB,CAAC;AAQ/B,OAAO,EAAmB,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAExE;;;;;;;;GAQG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG;QAAE,MAAM,EAAE,KAAK,EAAE,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAEtF;;OAEG;IACH,MAAM,CAAC,CAAC,SAAS,cAAc,EAAE,KAAK,EAAE,KAAK,GAAG,0BAA0B,CAAC,CAAC,CAAC,CAAC;IAE9E;;;;;OAKG;IACH,OAAO,IAAI,IAAI,CAAC;CACjB;AAED;;;;;GAKG;AACH,MAAM,MAAM,0BAA0B,CAAC,QAAQ,SAAS,cAAc,IAClE;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,QAAQ,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjF;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,IAAI,eAAe,CA6KvD"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import "@simplysm/core-common";
|
|
2
2
|
import {
|
|
3
3
|
ArgumentError,
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
bytes as bytesU,
|
|
5
|
+
json,
|
|
6
6
|
LazyGcMap,
|
|
7
|
-
Uuid
|
|
8
|
-
bytesConcat
|
|
7
|
+
Uuid
|
|
9
8
|
} from "@simplysm/core-common";
|
|
10
9
|
import { PROTOCOL_CONFIG } from "./protocol.types.js";
|
|
11
10
|
function createServiceProtocol() {
|
|
@@ -24,11 +23,11 @@ function createServiceProtocol() {
|
|
|
24
23
|
);
|
|
25
24
|
headerView.setBigUint64(16, BigInt(header.totalSize), false);
|
|
26
25
|
headerView.setUint32(24, header.index, false);
|
|
27
|
-
return
|
|
26
|
+
return bytesU.concat([headerBytes, ...bodyBytes ? [bodyBytes] : []]);
|
|
28
27
|
}
|
|
29
28
|
return {
|
|
30
29
|
encode(uuid, message) {
|
|
31
|
-
const msgJson =
|
|
30
|
+
const msgJson = json.stringify([message.name, ..."body" in message ? [message.body] : []]);
|
|
32
31
|
const msgBytes = new TextEncoder().encode(msgJson);
|
|
33
32
|
const totalSize = msgBytes.length;
|
|
34
33
|
if (totalSize > PROTOCOL_CONFIG.MAX_TOTAL_SIZE) {
|
|
@@ -89,10 +88,10 @@ function createServiceProtocol() {
|
|
|
89
88
|
};
|
|
90
89
|
} else {
|
|
91
90
|
accumulator.delete(uuid);
|
|
92
|
-
const resultBytes =
|
|
91
|
+
const resultBytes = bytesU.concat(accItem.chunks.filterExists());
|
|
93
92
|
let messageArr;
|
|
94
93
|
try {
|
|
95
|
-
messageArr =
|
|
94
|
+
messageArr = json.parse(new TextDecoder().decode(resultBytes));
|
|
96
95
|
} catch (err) {
|
|
97
96
|
throw new ArgumentError("Failed to decode message.", { uuid, cause: err });
|
|
98
97
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/protocol/create-service-protocol.ts"],
|
|
4
|
-
"mappings": "AACA,OAAO;AACP;AAAA,EACE;AAAA,EACA
|
|
4
|
+
"mappings": "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",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
|
@@ -26,7 +26,7 @@ export interface SmtpClientSendOption {
|
|
|
26
26
|
html: string;
|
|
27
27
|
attachments?: SmtpClientSendAttachment[];
|
|
28
28
|
}
|
|
29
|
-
export interface
|
|
29
|
+
export interface SmtpClientDefaultOptions {
|
|
30
30
|
senderName: string;
|
|
31
31
|
senderEmail?: string;
|
|
32
32
|
user?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"smtp-client-service.types.d.ts","sourceRoot":"","sources":["..\\..\\src\\service-types\\smtp-client-service.types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IAC9B,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,6BAA6B;IAC5C,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,wBAAwB,EAAE,CAAC;CAC1C;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,wBAAwB,EAAE,CAAC;CAC1C;AAED,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"smtp-client-service.types.d.ts","sourceRoot":"","sources":["..\\..\\src\\service-types\\smtp-client-service.types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IAC9B,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,6BAA6B;IAC5C,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,wBAAwB,EAAE,CAAC;CAC1C;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,wBAAwB,EAAE,CAAC;CAC1C;AAED,MAAM,WAAW,wBAAwB;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplysm/service-common",
|
|
3
|
-
"version": "13.0.
|
|
3
|
+
"version": "13.0.78",
|
|
4
4
|
"description": "Simplysm package - Service module (common)",
|
|
5
5
|
"author": "simplysm",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
],
|
|
20
20
|
"sideEffects": false,
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@simplysm/core-common": "13.0.
|
|
23
|
-
"@simplysm/orm-common": "13.0.
|
|
22
|
+
"@simplysm/core-common": "13.0.78",
|
|
23
|
+
"@simplysm/orm-common": "13.0.78"
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -2,11 +2,10 @@ import type { Bytes } from "@simplysm/core-common";
|
|
|
2
2
|
import "@simplysm/core-common";
|
|
3
3
|
import {
|
|
4
4
|
ArgumentError,
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
bytes as bytesU,
|
|
6
|
+
json,
|
|
7
7
|
LazyGcMap,
|
|
8
8
|
Uuid,
|
|
9
|
-
bytesConcat,
|
|
10
9
|
} from "@simplysm/core-common";
|
|
11
10
|
import { PROTOCOL_CONFIG, type ServiceMessage } from "./protocol.types";
|
|
12
11
|
|
|
@@ -114,7 +113,7 @@ export function createServiceProtocol(): ServiceProtocol {
|
|
|
114
113
|
headerView.setBigUint64(16, BigInt(header.totalSize), false);
|
|
115
114
|
headerView.setUint32(24, header.index, false);
|
|
116
115
|
|
|
117
|
-
return
|
|
116
|
+
return bytesU.concat([headerBytes, ...(bodyBytes ? [bodyBytes] : [])]);
|
|
118
117
|
}
|
|
119
118
|
|
|
120
119
|
// -------------------------------------------------------------------
|
|
@@ -123,7 +122,7 @@ export function createServiceProtocol(): ServiceProtocol {
|
|
|
123
122
|
|
|
124
123
|
return {
|
|
125
124
|
encode(uuid: string, message: ServiceMessage): { chunks: Bytes[]; totalSize: number } {
|
|
126
|
-
const msgJson =
|
|
125
|
+
const msgJson = json.stringify([message.name, ...("body" in message ? [message.body] : [])]);
|
|
127
126
|
const msgBytes = new TextEncoder().encode(msgJson);
|
|
128
127
|
|
|
129
128
|
const totalSize = msgBytes.length;
|
|
@@ -209,10 +208,10 @@ export function createServiceProtocol(): ServiceProtocol {
|
|
|
209
208
|
} else {
|
|
210
209
|
accumulator.delete(uuid); // Free memory
|
|
211
210
|
|
|
212
|
-
const resultBytes =
|
|
211
|
+
const resultBytes = bytesU.concat(accItem.chunks.filterExists());
|
|
213
212
|
let messageArr: [string, unknown];
|
|
214
213
|
try {
|
|
215
|
-
messageArr =
|
|
214
|
+
messageArr = json.parse<[string, unknown]>(new TextDecoder().decode(resultBytes));
|
|
216
215
|
} catch (err) {
|
|
217
216
|
throw new ArgumentError("Failed to decode message.", { uuid, cause: err });
|
|
218
217
|
}
|
|
@@ -16,7 +16,7 @@ describe("ServiceProtocol", () => {
|
|
|
16
16
|
|
|
17
17
|
describe("Encoding", () => {
|
|
18
18
|
it("encode single message", () => {
|
|
19
|
-
const uuid = Uuid.
|
|
19
|
+
const uuid = Uuid.generate().toString();
|
|
20
20
|
const message: ServiceMessage = { name: "test.method", body: [{ test: "data" }] };
|
|
21
21
|
|
|
22
22
|
const result = protocol.encode(uuid, message);
|
|
@@ -26,7 +26,7 @@ describe("ServiceProtocol", () => {
|
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
it("throw error when message exceeds 100MB", () => {
|
|
29
|
-
const uuid = Uuid.
|
|
29
|
+
const uuid = Uuid.generate().toString();
|
|
30
30
|
// Generate data larger than 100MB
|
|
31
31
|
const largeData = "x".repeat(101 * 1024 * 1024);
|
|
32
32
|
const message: ServiceMessage = { name: "test.method", body: [largeData] };
|
|
@@ -37,7 +37,7 @@ describe("ServiceProtocol", () => {
|
|
|
37
37
|
|
|
38
38
|
describe("Decoding", () => {
|
|
39
39
|
it("decode single message", () => {
|
|
40
|
-
const uuid = Uuid.
|
|
40
|
+
const uuid = Uuid.generate().toString();
|
|
41
41
|
const message: ServiceMessage = { name: "test.method", body: [{ value: 123 }] };
|
|
42
42
|
|
|
43
43
|
const encoded = protocol.encode(uuid, message);
|
|
@@ -59,7 +59,7 @@ describe("ServiceProtocol", () => {
|
|
|
59
59
|
it("throw error when decoded message exceeds 100MB", () => {
|
|
60
60
|
// Manually create header with totalSize exceeding 100MB
|
|
61
61
|
const headerBytes = new Uint8Array(28);
|
|
62
|
-
const uuidBytes = new Uuid(Uuid.
|
|
62
|
+
const uuidBytes = new Uuid(Uuid.generate().toString()).toBytes();
|
|
63
63
|
headerBytes.set(uuidBytes, 0);
|
|
64
64
|
|
|
65
65
|
const headerView = new DataView(
|
|
@@ -76,7 +76,7 @@ describe("ServiceProtocol", () => {
|
|
|
76
76
|
|
|
77
77
|
describe("Chunking", () => {
|
|
78
78
|
it("chunk message larger than 3MB", () => {
|
|
79
|
-
const uuid = Uuid.
|
|
79
|
+
const uuid = Uuid.generate().toString();
|
|
80
80
|
// Create 4MB data
|
|
81
81
|
const largeData = "x".repeat(4 * 1024 * 1024);
|
|
82
82
|
const message: ServiceMessage = { name: "test.method", body: [largeData] };
|
|
@@ -87,7 +87,7 @@ describe("ServiceProtocol", () => {
|
|
|
87
87
|
});
|
|
88
88
|
|
|
89
89
|
it("assemble chunked message in order", () => {
|
|
90
|
-
const uuid = Uuid.
|
|
90
|
+
const uuid = Uuid.generate().toString();
|
|
91
91
|
// 4MB data
|
|
92
92
|
const largeData = "x".repeat(4 * 1024 * 1024);
|
|
93
93
|
const message: ServiceMessage = { name: "test.method", body: [largeData] };
|
|
@@ -111,7 +111,7 @@ describe("ServiceProtocol", () => {
|
|
|
111
111
|
});
|
|
112
112
|
|
|
113
113
|
it("assemble chunked message in reverse order", () => {
|
|
114
|
-
const uuid = Uuid.
|
|
114
|
+
const uuid = Uuid.generate().toString();
|
|
115
115
|
// 4MB data
|
|
116
116
|
const largeData = "x".repeat(4 * 1024 * 1024);
|
|
117
117
|
const message: ServiceMessage = { name: "test.method", body: [largeData] };
|
|
@@ -133,7 +133,7 @@ describe("ServiceProtocol", () => {
|
|
|
133
133
|
});
|
|
134
134
|
|
|
135
135
|
it("prevent duplicate packets", () => {
|
|
136
|
-
const uuid = Uuid.
|
|
136
|
+
const uuid = Uuid.generate().toString();
|
|
137
137
|
// 4MB data
|
|
138
138
|
const largeData = "x".repeat(4 * 1024 * 1024);
|
|
139
139
|
const message: ServiceMessage = { name: "test.method", body: [largeData] };
|
|
@@ -162,8 +162,8 @@ describe("ServiceProtocol", () => {
|
|
|
162
162
|
|
|
163
163
|
describe("UUID interleaving", () => {
|
|
164
164
|
it("receive chunks from multiple UUIDs in interleaved order", () => {
|
|
165
|
-
const uuid1 = Uuid.
|
|
166
|
-
const uuid2 = Uuid.
|
|
165
|
+
const uuid1 = Uuid.generate().toString();
|
|
166
|
+
const uuid2 = Uuid.generate().toString();
|
|
167
167
|
|
|
168
168
|
// Each with 4MB data to trigger chunking
|
|
169
169
|
const largeData1 = "A".repeat(4 * 1024 * 1024);
|
|
@@ -207,7 +207,7 @@ describe("ServiceProtocol", () => {
|
|
|
207
207
|
|
|
208
208
|
describe("Edge cases", () => {
|
|
209
209
|
it("handle null body", () => {
|
|
210
|
-
const uuid = Uuid.
|
|
210
|
+
const uuid = Uuid.generate().toString();
|
|
211
211
|
const message: ServiceMessage = { name: "test.method", body: [null] };
|
|
212
212
|
|
|
213
213
|
const encoded = protocol.encode(uuid, message);
|
|
@@ -221,7 +221,7 @@ describe("ServiceProtocol", () => {
|
|
|
221
221
|
});
|
|
222
222
|
|
|
223
223
|
it("handle message at exactly 3MB boundary", () => {
|
|
224
|
-
const uuid = Uuid.
|
|
224
|
+
const uuid = Uuid.generate().toString();
|
|
225
225
|
// Exactly 3MB
|
|
226
226
|
const data = "x".repeat(3 * 1024 * 1024 - 50); // Account for some JSON overhead
|
|
227
227
|
const message: ServiceMessage = { name: "test.method", body: [data] };
|
|
@@ -232,7 +232,7 @@ describe("ServiceProtocol", () => {
|
|
|
232
232
|
});
|
|
233
233
|
|
|
234
234
|
it("include correct information in progress response", () => {
|
|
235
|
-
const uuid = Uuid.
|
|
235
|
+
const uuid = Uuid.generate().toString();
|
|
236
236
|
const largeData = "x".repeat(4 * 1024 * 1024);
|
|
237
237
|
const message: ServiceMessage = { name: "test.method", body: [largeData] };
|
|
238
238
|
|