Skip to content

Commit

Permalink
feat: add new encoder option and deprecate old serializer (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Works committed Feb 11, 2024
1 parent a85276f commit fd34f22
Show file tree
Hide file tree
Showing 125 changed files with 3,677 additions and 1,434 deletions.
5 changes: 5 additions & 0 deletions .changeset/five-olives-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'async-call-rpc': minor
---

add new `encoder` option and deprecate old `serializer` option
14 changes: 14 additions & 0 deletions .changeset/grumpy-phones-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'async-call-rpc': minor
---

`hint` added to the `CallbackBasedChannel.setup(jsonRPCHandlerCallback)` and `EventBasedChannel.on(listener)`.

For an isomorphic instance of `AsyncCall` (used as both a server and a client),
when a new message comes, it does not clear if to call `decodeRequest` or `decodeRespones`.

This version introduce a new option `encoder` to replace `serialization`. `serialization` is always working in isomorphic way.

- If `hint` is `"request"`, `(encoder as ServerEncoding).decodeRequest` will be called first, if this method does not exist, `(encoder as IsomorphicEncoder).decode` will be called.
- If `hint` is `"response"`, `(encoder as ClientEncoding).decodeResponse` will be called first, if this method does not exist, `(encoder as IsomorphicEncoder).decode` will be called.
- If `hint` does not present, only `encoder.decode` will be called.
5 changes: 5 additions & 0 deletions .changeset/odd-scissors-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'async-call-rpc': minor
---

`BSON_Serialization` and `Msgpack_Serialization` is now deprecated
5 changes: 5 additions & 0 deletions .changeset/smooth-ties-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"async-call-rpc": patch
---

Add Promise<void> into return signature of EventBasedChannel.send
5 changes: 5 additions & 0 deletions .changeset/strange-readers-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'async-call-rpc': minor
---

expose JSON-RPC interfaces
5 changes: 5 additions & 0 deletions .changeset/tidy-trains-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'async-call-rpc': minor
---

new built-in `JSONEncoder` for the new encode option.
186 changes: 74 additions & 112 deletions README.md

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions __tests__/DOMException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { expect, it } from 'vitest'

it(
'able to serialize DOMException',
withSnapshotDefault('DOMException', async (f) => {
withSnapshotDefault('DOMException', async ({ init }) => {
await reproduceDOMException(false, async () => {
const server = f()
const server = init()
const promise: Promise<never> = server.DOMException()
try {
await promise
Expand All @@ -22,10 +22,10 @@ it(

it(
'able to recover from Error constructor with a bad implementation',
withSnapshotDefault('recover-error-with-bad-implementation', async (f) => {
withSnapshotDefault('recover-error-with-bad-implementation', async ({ init }) => {
await reproduceError(() =>
reproduceDOMException(true, async () => {
const server = f()
const server = init()
const promise = server.DOMException()
await expect(promise).rejects.toThrowError()
}),
Expand Down
4 changes: 2 additions & 2 deletions __tests__/__file_snapshots__/async-call-log-all.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Array [
"",
Promise {},
"color: gray; font-style: italic;",
[Function replay],
[Function anonymous],
]
```

Expand Down Expand Up @@ -79,7 +79,7 @@ Array [
"",
Promise {},
"color: gray; font-style: italic;",
[Function replay],
[Function anonymous],
]
```

Expand Down
90 changes: 90 additions & 0 deletions __tests__/__file_snapshots__/encode-isomorphic-full-hinted.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Timeline

## T=0 Log: testRunner/log

```php
Array [
"encodeRequest",
Object {
"id": 0,
"jsonrpc": "2.0",
"method": "undefined",
"params": Array [],
},
]
```

## T=1 Message: client => server

```php
Object {
"id": 0,
"jsonrpc": "2.0",
"method": "undefined",
"params": Array [],
}
```

## T=2 Log: testRunner/log

```php
Array [
"decodeRequest",
Object {
"id": 0,
"jsonrpc": "2.0",
"method": "undefined",
"params": Array [],
},
]
```

## T=3 Log: server/log

```php
Array [
"rpc.%cundefined%c(%c)
%o %c@0",
"color: #d2c057",
"",
"",
Promise {},
"color: gray; font-style: italic;",
]
```

## T=4 Log: testRunner/log

```php
Array [
"encodeResponse",
Object {
"id": 0,
"jsonrpc": "2.0",
"result": undefined,
},
]
```

## T=5 Message: server => client

```php
Object {
"id": 0,
"jsonrpc": "2.0",
"result": undefined,
}
```

## T=6 Log: testRunner/log

```php
Array [
"decodeResponse",
Object {
"id": 0,
"jsonrpc": "2.0",
"result": undefined,
},
]
```
90 changes: 90 additions & 0 deletions __tests__/__file_snapshots__/encode-isomorphic-full-not-hinted.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Timeline

## T=0 Log: testRunner/log

```php
Array [
"encodeRequest",
Object {
"id": 0,
"jsonrpc": "2.0",
"method": "undefined",
"params": Array [],
},
]
```

## T=1 Message: client => server

```php
Object {
"id": 0,
"jsonrpc": "2.0",
"method": "undefined",
"params": Array [],
}
```

## T=2 Log: testRunner/log

```php
Array [
"decode",
Object {
"id": 0,
"jsonrpc": "2.0",
"method": "undefined",
"params": Array [],
},
]
```

## T=3 Log: server/log

```php
Array [
"rpc.%cundefined%c(%c)
%o %c@0",
"color: #d2c057",
"",
"",
Promise {},
"color: gray; font-style: italic;",
]
```

## T=4 Log: testRunner/log

```php
Array [
"encodeResponse",
Object {
"id": 0,
"jsonrpc": "2.0",
"result": undefined,
},
]
```

## T=5 Message: server => client

```php
Object {
"id": 0,
"jsonrpc": "2.0",
"result": undefined,
}
```

## T=6 Log: testRunner/log

```php
Array [
"decode",
Object {
"id": 0,
"jsonrpc": "2.0",
"result": undefined,
},
]
```
90 changes: 90 additions & 0 deletions __tests__/__file_snapshots__/encode-isomorphic-hinted.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Timeline

## T=0 Log: testRunner/log

```php
Array [
"encode",
Object {
"id": 0,
"jsonrpc": "2.0",
"method": "undefined",
"params": Array [],
},
]
```

## T=1 Message: client => server

```php
Object {
"id": 0,
"jsonrpc": "2.0",
"method": "undefined",
"params": Array [],
}
```

## T=2 Log: testRunner/log

```php
Array [
"decode",
Object {
"id": 0,
"jsonrpc": "2.0",
"method": "undefined",
"params": Array [],
},
]
```

## T=3 Log: server/log

```php
Array [
"rpc.%cundefined%c(%c)
%o %c@0",
"color: #d2c057",
"",
"",
Promise {},
"color: gray; font-style: italic;",
]
```

## T=4 Log: testRunner/log

```php
Array [
"encode",
Object {
"id": 0,
"jsonrpc": "2.0",
"result": undefined,
},
]
```

## T=5 Message: server => client

```php
Object {
"id": 0,
"jsonrpc": "2.0",
"result": undefined,
}
```

## T=6 Log: testRunner/log

```php
Array [
"decode",
Object {
"id": 0,
"jsonrpc": "2.0",
"result": undefined,
},
]
```
Loading

0 comments on commit fd34f22

Please sign in to comment.