From b2d17c4b79e4efdc629fc4d79c1fea0812cfa6da Mon Sep 17 00:00:00 2001 From: Jack Works Date: Wed, 6 Mar 2024 02:54:02 +0800 Subject: [PATCH] chore: publish on jsr registry --- .github/publish.mjs | 7 + .github/workflows/release.yml | 2 +- CHANGELOG.md | 128 +++++++++--------- api/base.api.md | 18 +++ api/full.api.md | 18 +++ .../async-call-rpc.abortsignallike.aborted.md | 11 ++ ...ll-rpc.abortsignallike.addeventlistener.md | 26 ++++ docs/async-call-rpc.abortsignallike.md | 33 +++++ docs/async-call-rpc.abortsignallike.reason.md | 11 ++ ...rpc.abortsignallike.removeeventlistener.md | 23 ++++ ...call-rpc.abortsignallike.throwifaborted.md | 15 ++ ...c-call-rpc.asynccalloptions.forcesignal.md | 18 +++ docs/async-call-rpc.asynccalloptions.md | 2 + .../async-call-rpc.asynccalloptions.signal.md | 18 +++ docs/async-call-rpc.md | 1 + jsr.json | 25 ++++ package.json | 5 +- src/Async-Call-Generator.ts | 14 +- src/Async-Call.ts | 28 ++-- src/core/batch.ts | 6 +- src/core/notify.ts | 4 +- src/index.ts | 4 +- src/tsconfig.json | 5 +- src/utils/encoder.ts | 6 +- src/utils/error.ts | 2 +- src/utils/jsonrpc.ts | 16 ++- src/utils/normalizeOptions.ts | 4 +- src/utils/serialization.ts | 4 +- 28 files changed, 347 insertions(+), 107 deletions(-) create mode 100644 .github/publish.mjs create mode 100644 docs/async-call-rpc.abortsignallike.aborted.md create mode 100644 docs/async-call-rpc.abortsignallike.addeventlistener.md create mode 100644 docs/async-call-rpc.abortsignallike.md create mode 100644 docs/async-call-rpc.abortsignallike.reason.md create mode 100644 docs/async-call-rpc.abortsignallike.removeeventlistener.md create mode 100644 docs/async-call-rpc.abortsignallike.throwifaborted.md create mode 100644 docs/async-call-rpc.asynccalloptions.forcesignal.md create mode 100644 docs/async-call-rpc.asynccalloptions.signal.md create mode 100644 jsr.json diff --git a/.github/publish.mjs b/.github/publish.mjs new file mode 100644 index 0000000..4131654 --- /dev/null +++ b/.github/publish.mjs @@ -0,0 +1,7 @@ +import { readFile, writeFile } from 'node:fs/promises' + +const jsr_path = new URL('../jsr.json', import.meta.url) +const jsr = await readFile(jsr_path, 'utf8') +const { version } = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8')) + +await writeFile(jsr_path, jsr.replace('{{version}}', version), 'utf8') diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7062019..5042240 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,7 +30,7 @@ jobs: - run: pnpm run doc:api - uses: changesets/action@v1 with: - publish: npx changeset publish + publish: pnpm run ci:release env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/CHANGELOG.md b/CHANGELOG.md index b48c7e5..7168f09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,88 +1,94 @@ # Changelog +## 6.4.1 + +### Patch Changes + +- 609bfed: publish on jsr registry + ## 6.4.0 ### Minor Changes -- fd34f22: add a new `encoder` option and deprecate the old `serializer` option - - how to migrate: - - ```ts - // before - const options = { - channel, - serializer: { - serialization(data) { return ... }, - deserialization(data) { return ... }, - }, - } - - // after - const options = { - channel, - encoder: { - encode(data) { return ... }, - decode(data) { return ... }, - }, - } - ``` - - ```ts - // before - const options = { - channel, - serializer: NoSerialization, - }; +- fd34f22: add a new `encoder` option and deprecate the old `serializer` option - // after - const options = { - channel, - }; - ``` + how to migrate: - ```ts - // before - const options = { + ```ts + // before + const options = { channel, - serializer: JSONSerialization(), - }; - - // after - const options = { + serializer: { + serialization(data) { return ... }, + deserialization(data) { return ... }, + }, + } + + // after + const options = { channel, - encoder: JSONEncoder(), - }; - ``` + encoder: { + encode(data) { return ... }, + decode(data) { return ... }, + }, + } + ``` + + ```ts + // before + const options = { + channel, + serializer: NoSerialization, + }; + + // after + const options = { + channel, + }; + ``` + + ```ts + // before + const options = { + channel, + serializer: JSONSerialization(), + }; + + // after + const options = { + channel, + encoder: JSONEncoder(), + }; + ``` -- fd34f22: `hint` added to the `CallbackBasedChannel.setup(jsonRPCHandlerCallback)` and `EventBasedChannel.on(listener)`. +- fd34f22: `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`. + 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 introduces a new option `encoder` to replace `serialization`. `serialization` is always working in isomorphic way. + This version introduces 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` is not present, only `encoder.decode` will be called. + - 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` is not present, only `encoder.decode` will be called. -- 0d0900b: rename "key" to "name" +- 0d0900b: rename "key" to "name" -- fd34f22: `BSON_Serialization` and `Msgpack_Serialization` is now deprecated +- fd34f22: `BSON_Serialization` and `Msgpack_Serialization` is now deprecated -- 0431c15: rename `AsyncCallStrictJSONRPC` to `AsyncCallStrictOptions` +- 0431c15: rename `AsyncCallStrictJSONRPC` to `AsyncCallStrictOptions` -- 8a38d8b: add `signal` and `forceSignal` to stop the instance +- 8a38d8b: add `signal` and `forceSignal` to stop the instance -- c9bbbd2: rename `parameterStructures` to `parameterStructure` +- c9bbbd2: rename `parameterStructures` to `parameterStructure` -- fd34f22: expose JSON-RPC interfaces +- fd34f22: expose JSON-RPC interfaces -- fd34f22: new built-in `JSONEncoder` for the new encode option. +- fd34f22: new built-in `JSONEncoder` for the new encode option. ### Patch Changes -- fd34f22: Add `Promise` into return signature of `EventBasedChannel.send` +- fd34f22: Add `Promise` into return signature of `EventBasedChannel.send` ## 6.3.1 diff --git a/api/base.api.md b/api/base.api.md index cbd6cc7..8fdd6cb 100644 --- a/api/base.api.md +++ b/api/base.api.md @@ -4,6 +4,22 @@ ```ts +// @public +export interface AbortSignalLike { + // (undocumented) + readonly aborted: boolean; + // (undocumented) + addEventListener(type: 'abort', listener: () => void, options: { + once: boolean; + }): void; + // (undocumented) + reason: any; + // (undocumented) + removeEventListener(type: 'abort', listener: () => void): void; + // (undocumented) + throwIfAborted(): void; +} + // @public export function AsyncCall(thisSideImplementation: null | undefined | object | Promise, options: AsyncCallOptions): AsyncVersionOf; @@ -21,6 +37,7 @@ export interface AsyncCallLogLevel { export interface AsyncCallOptions { channel: CallbackBasedChannel | EventBasedChannel | Promise | EventBasedChannel>; encoder?: IsomorphicEncoder | IsomorphicEncoderFull; + forceSignal?: AbortSignalLike; idGenerator?(): string | number; // @deprecated key?: string; @@ -34,6 +51,7 @@ export interface AsyncCallOptions void, options: { + once: boolean; + }): void; + // (undocumented) + reason: any; + // (undocumented) + removeEventListener(type: 'abort', listener: () => void): void; + // (undocumented) + throwIfAborted(): void; +} + // @public export function AsyncCall(thisSideImplementation: null | undefined | object | Promise, options: AsyncCallOptions): AsyncVersionOf; @@ -21,6 +37,7 @@ export interface AsyncCallLogLevel { export interface AsyncCallOptions { channel: CallbackBasedChannel | EventBasedChannel | Promise | EventBasedChannel>; encoder?: IsomorphicEncoder | IsomorphicEncoderFull; + forceSignal?: AbortSignalLike; idGenerator?(): string | number; // @deprecated key?: string; @@ -34,6 +51,7 @@ export interface AsyncCallOptions + +[Home](./index.md) > [async-call-rpc](./async-call-rpc.md) > [AbortSignalLike](./async-call-rpc.abortsignallike.md) > [aborted](./async-call-rpc.abortsignallike.aborted.md) + +## AbortSignalLike.aborted property + +**Signature:** + +```typescript +readonly aborted: boolean; +``` diff --git a/docs/async-call-rpc.abortsignallike.addeventlistener.md b/docs/async-call-rpc.abortsignallike.addeventlistener.md new file mode 100644 index 0000000..9f0eb95 --- /dev/null +++ b/docs/async-call-rpc.abortsignallike.addeventlistener.md @@ -0,0 +1,26 @@ + + +[Home](./index.md) > [async-call-rpc](./async-call-rpc.md) > [AbortSignalLike](./async-call-rpc.abortsignallike.md) > [addEventListener](./async-call-rpc.abortsignallike.addeventlistener.md) + +## AbortSignalLike.addEventListener() method + +**Signature:** + +```typescript +addEventListener(type: 'abort', listener: () => void, options: { + once: boolean; + }): void; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| type | 'abort' | | +| listener | () => void | | +| options | { once: boolean; } | | + +**Returns:** + +void + diff --git a/docs/async-call-rpc.abortsignallike.md b/docs/async-call-rpc.abortsignallike.md new file mode 100644 index 0000000..61d37ba --- /dev/null +++ b/docs/async-call-rpc.abortsignallike.md @@ -0,0 +1,33 @@ + + +[Home](./index.md) > [async-call-rpc](./async-call-rpc.md) > [AbortSignalLike](./async-call-rpc.abortsignallike.md) + +## AbortSignalLike interface + +AbortSignal + +**Signature:** + +```typescript +export interface AbortSignalLike +``` + +## Remarks + +This is a subset of the AbortSignal interface defined in the \[WinterCG\](https://wintercg.org/). + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [aborted](./async-call-rpc.abortsignallike.aborted.md) | readonly | boolean | | +| [reason](./async-call-rpc.abortsignallike.reason.md) | | any | | + +## Methods + +| Method | Description | +| --- | --- | +| [addEventListener(type, listener, options)](./async-call-rpc.abortsignallike.addeventlistener.md) | | +| [removeEventListener(type, listener)](./async-call-rpc.abortsignallike.removeeventlistener.md) | | +| [throwIfAborted()](./async-call-rpc.abortsignallike.throwifaborted.md) | | + diff --git a/docs/async-call-rpc.abortsignallike.reason.md b/docs/async-call-rpc.abortsignallike.reason.md new file mode 100644 index 0000000..5a9bddf --- /dev/null +++ b/docs/async-call-rpc.abortsignallike.reason.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [async-call-rpc](./async-call-rpc.md) > [AbortSignalLike](./async-call-rpc.abortsignallike.md) > [reason](./async-call-rpc.abortsignallike.reason.md) + +## AbortSignalLike.reason property + +**Signature:** + +```typescript +reason: any; +``` diff --git a/docs/async-call-rpc.abortsignallike.removeeventlistener.md b/docs/async-call-rpc.abortsignallike.removeeventlistener.md new file mode 100644 index 0000000..d6a7b80 --- /dev/null +++ b/docs/async-call-rpc.abortsignallike.removeeventlistener.md @@ -0,0 +1,23 @@ + + +[Home](./index.md) > [async-call-rpc](./async-call-rpc.md) > [AbortSignalLike](./async-call-rpc.abortsignallike.md) > [removeEventListener](./async-call-rpc.abortsignallike.removeeventlistener.md) + +## AbortSignalLike.removeEventListener() method + +**Signature:** + +```typescript +removeEventListener(type: 'abort', listener: () => void): void; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| type | 'abort' | | +| listener | () => void | | + +**Returns:** + +void + diff --git a/docs/async-call-rpc.abortsignallike.throwifaborted.md b/docs/async-call-rpc.abortsignallike.throwifaborted.md new file mode 100644 index 0000000..af531db --- /dev/null +++ b/docs/async-call-rpc.abortsignallike.throwifaborted.md @@ -0,0 +1,15 @@ + + +[Home](./index.md) > [async-call-rpc](./async-call-rpc.md) > [AbortSignalLike](./async-call-rpc.abortsignallike.md) > [throwIfAborted](./async-call-rpc.abortsignallike.throwifaborted.md) + +## AbortSignalLike.throwIfAborted() method + +**Signature:** + +```typescript +throwIfAborted(): void; +``` +**Returns:** + +void + diff --git a/docs/async-call-rpc.asynccalloptions.forcesignal.md b/docs/async-call-rpc.asynccalloptions.forcesignal.md new file mode 100644 index 0000000..64da681 --- /dev/null +++ b/docs/async-call-rpc.asynccalloptions.forcesignal.md @@ -0,0 +1,18 @@ + + +[Home](./index.md) > [async-call-rpc](./async-call-rpc.md) > [AsyncCallOptions](./async-call-rpc.asynccalloptions.md) > [forceSignal](./async-call-rpc.asynccalloptions.forcesignal.md) + +## AsyncCallOptions.forceSignal property + +AbortSignal to force stop the instance. + +**Signature:** + +```typescript +forceSignal?: AbortSignalLike; +``` + +## Remarks + +`signal` is used to stop the instance. If the `signal` is aborted, then all new requests will be rejected, and the pending requests will be forcibly rejected and pending results will be ignored. + diff --git a/docs/async-call-rpc.asynccalloptions.md b/docs/async-call-rpc.asynccalloptions.md index 54363af..dd0ccd6 100644 --- a/docs/async-call-rpc.asynccalloptions.md +++ b/docs/async-call-rpc.asynccalloptions.md @@ -18,6 +18,7 @@ export interface AsyncCallOptions<EncodedRequest \| EncodedResponse> \| [EventBasedChannel](./async-call-rpc.eventbasedchannel.md)<EncodedRequest \| EncodedResponse> \| Promise<[CallbackBasedChannel](./async-call-rpc.callbackbasedchannel.md)<EncodedRequest \| EncodedResponse> \| [EventBasedChannel](./async-call-rpc.eventbasedchannel.md)<EncodedRequest \| EncodedResponse>> | The message channel to exchange messages between server and client | | [encoder?](./async-call-rpc.asynccalloptions.encoder.md) | | [IsomorphicEncoder](./async-call-rpc.isomorphicencoder.md)<EncodedRequest, EncodedResponse> \| [IsomorphicEncoderFull](./async-call-rpc.isomorphicencoderfull.md)<EncodedRequest, EncodedResponse> | _(Optional)_ Encoder of requests and responses. | +| [forceSignal?](./async-call-rpc.asynccalloptions.forcesignal.md) | | [AbortSignalLike](./async-call-rpc.abortsignallike.md) | _(Optional)_ AbortSignal to force stop the instance. | | [key?](./async-call-rpc.asynccalloptions.key.md) | | string | _(Optional)_ Name used when pretty log is enabled. | | [log?](./async-call-rpc.asynccalloptions.log.md) | | [AsyncCallLogLevel](./async-call-rpc.asynccallloglevel.md) \| boolean \| 'all' | _(Optional)_ Choose log level. | | [logger?](./async-call-rpc.asynccalloptions.logger.md) | | [ConsoleInterface](./async-call-rpc.consoleinterface.md) | _(Optional)_ Provide the logger | @@ -27,6 +28,7 @@ export interface AsyncCallOptions + +[Home](./index.md) > [async-call-rpc](./async-call-rpc.md) > [AsyncCallOptions](./async-call-rpc.asynccalloptions.md) > [signal](./async-call-rpc.asynccalloptions.signal.md) + +## AsyncCallOptions.signal property + +AbortSignal to stop the instance. + +**Signature:** + +```typescript +signal?: AbortSignalLike; +``` + +## Remarks + +`signal` is used to stop the instance. If the `signal` is aborted, then all new requests will be rejected, except for the pending ones. + diff --git a/docs/async-call-rpc.md b/docs/async-call-rpc.md index bbdf795..3a540a9 100644 --- a/docs/async-call-rpc.md +++ b/docs/async-call-rpc.md @@ -25,6 +25,7 @@ See the introduction at [Github](https://github.com/Jack-Works/async-call) | Interface | Description | | --- | --- | +| [AbortSignalLike](./async-call-rpc.abortsignallike.md) | AbortSignal | | [AsyncCallLogLevel](./async-call-rpc.asynccallloglevel.md) | Log options | | [AsyncCallOptions](./async-call-rpc.asynccalloptions.md) | Options for [AsyncCall()](./async-call-rpc.asynccall.md) | | [AsyncCallStrictJSONRPC](./async-call-rpc.asynccallstrictjsonrpc.md) | Strict options | diff --git a/jsr.json b/jsr.json new file mode 100644 index 0000000..f69bc87 --- /dev/null +++ b/jsr.json @@ -0,0 +1,25 @@ +{ + "name": "@works/json-rpc", + "version": "{{version}}", + "exports": { + ".": "./src/Async-Call.ts", + "./full": "./src/index.ts" + }, + "include": ["src/**"], + // https://github.com/jsr-io/jsr/issues/194 + "exclude": [ + "__tests__", + "docs", + "*.json", + "src/*.json", + "api", + "examples", + "utils-src", + "vite.config.ts", + "index.html", + "*.yaml", + "rollup.config.mjs", + "utils", + "next-docs" + ] +} diff --git a/package.json b/package.json index aab63c7..e05c511 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "async-call-rpc", "packageManager": "pnpm@8.15.1", - "version": "6.4.0", + "version": "6.4.1", "description": "A lightweight JSON RPC server & client", "main": "out/base.js", "module": "out/base.mjs", @@ -87,7 +87,8 @@ "doc:post": "git checkout HEAD -- ./docs/index.html ./docs/_config.yml", "doc": "run-s doc:api doc:md doc:post", "start": "run-p watch:rollup watch:tsc watch:test", - "test": "vitest --coverage" + "test": "vitest --coverage", + "ci:release": "node ./.github/publish.mjs && npx jsr publish && npx changeset publish" }, "repository": { "type": "git", diff --git a/src/Async-Call-Generator.ts b/src/Async-Call-Generator.ts index 54094e0..c342047 100644 --- a/src/Async-Call-Generator.ts +++ b/src/Async-Call-Generator.ts @@ -1,17 +1,17 @@ /** * See the document at https://github.com/Jack-Works/async-call/ */ -import type { AsyncCallOptions } from './types.js' -import { AsyncCall } from './Async-Call.js' -import { AsyncCallIgnoreResponse } from './utils/internalSymbol.js' -import { normalizeStrictOptions } from './utils/normalizeOptions.js' -import { generateRandomID } from './utils/generateRandomID.js' -import { isFunction, isString, setPrototypeOf } from './utils/constants.js' +import type { AsyncCallOptions } from './types.ts' +import { AsyncCall } from './Async-Call.ts' +import { AsyncCallIgnoreResponse } from './utils/internalSymbol.ts' +import { normalizeStrictOptions } from './utils/normalizeOptions.ts' +import { generateRandomID } from './utils/generateRandomID.ts' +import { isFunction, isString, setPrototypeOf } from './utils/constants.ts' import { Err_Cannot_find_a_running_iterator_with_given_ID, Err_Only_string_can_be_the_RPC_method_name, makeHostedMessage, -} from './utils/error.js' +} from './utils/error.ts' const i = 'rpc.async-iterator.' // ! side effect diff --git a/src/Async-Call.ts b/src/Async-Call.ts index 81c61a4..aab2983 100644 --- a/src/Async-Call.ts +++ b/src/Async-Call.ts @@ -1,9 +1,9 @@ -export * from './types.js' -export type { _IgnoreResponse } from './core/notify.js' -export { JSONSerialization, NoSerialization } from './utils/serialization.js' -export { JSONEncoder, type JSONEncoderOptions } from './utils/encoder.js' -export { notify } from './core/notify.js' -export { batch } from './core/batch.js' +export type * from './types.ts' +export type { _IgnoreResponse } from './core/notify.ts' +export { JSONSerialization, NoSerialization } from './utils/serialization.ts' +export { JSONEncoder, type JSONEncoderOptions } from './utils/encoder.ts' +export { notify } from './core/notify.ts' +export { batch } from './core/batch.ts' import { makeRequest, @@ -14,7 +14,7 @@ import { ErrorResponseMethodNotFound, ErrorResponseInvalidRequest, ErrorResponseParseError, -} from './utils/jsonrpc.js' +} from './utils/jsonrpc.ts' import { removeStackHeader, RecoverError, @@ -22,11 +22,11 @@ import { Err_Cannot_call_method_starts_with_rpc_dot_directly, Err_Then_is_accessed_on_local_implementation_Please_explicitly_mark_if_it_is_thenable_in_the_options, onAbort, -} from './utils/error.js' -import { generateRandomID } from './utils/generateRandomID.js' -import { normalizeStrictOptions, normalizeLogOptions } from './utils/normalizeOptions.js' -import { AsyncCallIgnoreResponse, AsyncCallNotify, AsyncCallBatch } from './utils/internalSymbol.js' -import type { BatchQueue } from './core/batch.js' +} from './utils/error.ts' +import { generateRandomID } from './utils/generateRandomID.ts' +import { normalizeStrictOptions, normalizeLogOptions } from './utils/normalizeOptions.ts' +import { AsyncCallIgnoreResponse, AsyncCallNotify, AsyncCallBatch } from './utils/internalSymbol.ts' +import type { BatchQueue } from './core/batch.ts' import type { CallbackBasedChannel, EventBasedChannel, @@ -41,8 +41,8 @@ import type { IsomorphicEncoder, Requests, Responses, -} from './types.js' -import { apply, ERROR, isArray, isFunction, isObject, isString, Promise_resolve, undefined } from './utils/constants.js' +} from './types.ts' +import { apply, ERROR, isArray, isFunction, isObject, isString, Promise_resolve, undefined } from './utils/constants.ts' /** * Create a RPC server & client. diff --git a/src/core/batch.ts b/src/core/batch.ts index fdfbba4..7686a9c 100644 --- a/src/core/batch.ts +++ b/src/core/batch.ts @@ -1,6 +1,6 @@ -import { isString } from '../utils/constants.js' -import { AsyncCallBatch, AsyncCallNotify } from '../utils/internalSymbol.js' -import type { Request } from '../types.js' +import { isString } from '../utils/constants.ts' +import { AsyncCallBatch, AsyncCallNotify } from '../utils/internalSymbol.ts' +import type { Request } from '../types.ts' /** * Wrap the AsyncCall instance to use batch call. * @param asyncCallInstance - The AsyncCall instance diff --git a/src/core/notify.ts b/src/core/notify.ts index c87441c..1c534a6 100644 --- a/src/core/notify.ts +++ b/src/core/notify.ts @@ -1,5 +1,5 @@ -import { AsyncCallNotify } from '../utils/internalSymbol.js' -import { isFunction } from '../utils/constants.js' +import { AsyncCallNotify } from '../utils/internalSymbol.ts' +import { isFunction } from '../utils/constants.ts' /** * Make the returning type to `Promise` diff --git a/src/index.ts b/src/index.ts index 1376486..d1a4128 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,5 +5,5 @@ * See the introduction at {@link https://github.com/Jack-Works/async-call | Github} */ -export * from './Async-Call.js' -export * from './Async-Call-Generator.js' +export * from './Async-Call.ts' +export * from './Async-Call-Generator.ts' diff --git a/src/tsconfig.json b/src/tsconfig.json index 5a42692..3c8f932 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -1,7 +1,10 @@ { "extends": "../tsconfig.json", "compilerOptions": { - "module": "NodeNext", + "module": "ESNext", + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "emitDeclarationOnly": true, "rootDir": "./", "outDir": "../dist/core/", // This lib does not require any external libs diff --git a/src/utils/encoder.ts b/src/utils/encoder.ts index 6396f7a..428389e 100644 --- a/src/utils/encoder.ts +++ b/src/utils/encoder.ts @@ -1,5 +1,5 @@ -import type { IsomorphicEncoder, Request, Requests, Response, Responses, SuccessResponse } from '../types.js' -import { isArray, undefined } from './constants.js' +import type { IsomorphicEncoder, Request, Requests, Response, Responses, SuccessResponse } from '../types.ts' +import { isArray, undefined } from './constants.ts' /** * @public @@ -62,5 +62,5 @@ const undefinedEncode = (i: Response | Request) => { /** @public */ export namespace JSONEncoder { - export const Default = JSONEncoder() + export const Default: IsomorphicEncoder = JSONEncoder() } diff --git a/src/utils/error.ts b/src/utils/error.ts index 0e3545b..414f526 100644 --- a/src/utils/error.ts +++ b/src/utils/error.ts @@ -1,4 +1,4 @@ -import type { AbortSignalLike } from '../types.js' +import type { AbortSignalLike } from '../types.ts' class CustomError extends Error { // TODO: support cause diff --git a/src/utils/jsonrpc.ts b/src/utils/jsonrpc.ts index dce9e73..f3181dc 100644 --- a/src/utils/jsonrpc.ts +++ b/src/utils/jsonrpc.ts @@ -1,10 +1,15 @@ -import { globalDOMException as DOMException, DOMExceptionHeader } from './error.js' -import type { ErrorMapFunction } from '../Async-Call.js' -import { ERROR, isArray, isFunction, isObject, undefined } from './constants.js' -import type { Request, SuccessResponse, ErrorResponse, ID, Response } from '../types.js' +import { globalDOMException as DOMException, DOMExceptionHeader } from './error.ts' +import type { ErrorMapFunction } from '../Async-Call.ts' +import { ERROR, isArray, isFunction, isObject, undefined } from './constants.ts' +import type { Request, SuccessResponse, ErrorResponse, ID, Response } from '../types.ts' export const jsonrpc = '2.0' -export const makeRequest = (id: ID, method: string, params: readonly unknown[] | object, remoteStack?: string): Request => { +export const makeRequest = ( + id: ID, + method: string, + params: readonly unknown[] | object, + remoteStack?: string, +): Request => { const x: Request = { jsonrpc, id, method, params, remoteStack } deleteUndefined(x, 'id') deleteFalsy(x, 'remoteStack') @@ -65,7 +70,6 @@ export const defaultErrorMapper = return { code, message, data } } - export const isJSONRPCObject = (data: any): data is Response | Request => { if (!isObject(data)) return false if (!('jsonrpc' in data)) return false diff --git a/src/utils/normalizeOptions.ts b/src/utils/normalizeOptions.ts index 6ceca70..f8ecbd7 100644 --- a/src/utils/normalizeOptions.ts +++ b/src/utils/normalizeOptions.ts @@ -1,5 +1,5 @@ -import type { AsyncCallOptions } from '../Async-Call.js' -import { isBoolean } from './constants.js' +import type { AsyncCallOptions } from '../Async-Call.ts' +import { isBoolean } from './constants.ts' const undefinedToTrue = (x: undefined | boolean) => (x === void 0 ? true : x) type NormalizedLogOptions = readonly [ beCalled: boolean, diff --git a/src/utils/serialization.ts b/src/utils/serialization.ts index 4c07ceb..9c7fe12 100644 --- a/src/utils/serialization.ts +++ b/src/utils/serialization.ts @@ -1,5 +1,5 @@ -import { isObject, undefined } from './constants.js' -import type { Serialization } from '../types.js' +import { isObject, undefined } from './constants.ts' +import type { Serialization } from '../types.ts' /** * Serialization implementation that do nothing