Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

fix: make promise deserialization less flaky #21

Merged
merged 11 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ module.exports = {
extends: ["plugin:markdown/recommended"],
files: ["**/*.md"],
processor: "markdown/markdown",
rules: {
"eslint-comments/disable-enable-pair": "off",
},
},
{
extends: [
Expand Down Expand Up @@ -55,7 +58,10 @@ module.exports = {
},
rules: {
// These off-by-default rules work well for this repo and we like them on.
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"deprecation/deprecation": "error",
"eslint-comments/disable-enable-pair": "off",
},
},
{
Expand Down Expand Up @@ -119,10 +125,12 @@ module.exports = {
rules: {
// These off/less-strict-by-default rules work well for this repo and we like them on.

"@typescript-eslint/no-unused-vars": ["error", { caughtErrors: "all" }],
"@typescript-eslint/no-unused-vars": "off",
"eslint-comments/disable-enable-pair": "off",
"no-only-tests/no-only-tests": "error",

// These on-by-default rules don't work well for this repo and we like them off.
"@typescript-eslint/no-explicit-any": "off",
KATT marked this conversation as resolved.
Show resolved Hide resolved
"@typescript-eslint/padding-line-between-statements": [
"error",
{ blankLine: "always", next: "*", prev: "block-like" },
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Serialize exactly what you want; no more, no less.
### Example

```ts
/* eslint-disable eslint-comments/disable-enable-pair, @typescript-eslint/no-unused-vars, n/no-missing-import */
/* eslint-disable @typescript-eslint/no-unused-vars, n/no-missing-import */

import {
// Create serializer / deserializer
Expand Down Expand Up @@ -113,7 +113,7 @@ type Obj = typeof obj;
> See test reference in [`./src/extend/temporal.test.ts`](./src/extend/temporal.test.ts)

```ts
/* eslint-disable eslint-comments/disable-enable-pair, @typescript-eslint/no-unused-vars, n/no-missing-import, n/no-unpublished-import */
/* eslint-disable @typescript-eslint/no-unused-vars, n/no-missing-import, n/no-unpublished-import */
import { Temporal } from "@js-temporal/polyfill";
import { TsonType, createTson } from "tupleson";

Expand Down Expand Up @@ -141,7 +141,7 @@ const tson = createTson({
> See test reference in [`./src/extend/decimal.test.ts`](./src/extend/decimal.test.ts)

```ts
/* eslint-disable eslint-comments/disable-enable-pair, @typescript-eslint/no-unused-vars, n/no-missing-import, n/no-unpublished-import */
/* eslint-disable @typescript-eslint/no-unused-vars, n/no-missing-import, n/no-unpublished-import */
import { Decimal } from "decimal.js";

const decimalJs: TsonType<Decimal, string> = {
Expand Down
2 changes: 0 additions & 2 deletions src/async/asyncTypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// eslint-disable-next-line eslint-comments/disable-enable-pair
/* eslint-disable @typescript-eslint/no-explicit-any */
import { TsonError } from "../errors.js";
import { TsonType } from "../types.js";
import { TsonBranded, TsonTypeTesterCustom } from "../types.js";
Expand Down
1 change: 0 additions & 1 deletion src/async/deserializeAsync.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-explicit-any, eslint-comments/disable-enable-pair */
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-unsafe-argument */
import { TsonError } from "../errors.js";
Expand Down
2 changes: 0 additions & 2 deletions src/handlers/tsonPromise.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,6 @@ test("stringify and parse promise with a promise over a network connection", asy
});
});

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
const port = (server.address() as any).port as number;

// ----- client --------
Expand Down Expand Up @@ -460,7 +459,6 @@ test("stringify and parse promise with a promise over a network connection", asy
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
const err = await firstPromise.rejectedPromise.catch((err) => err);

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
expect(err.cause).toMatchInlineSnapshot(`
{
"name": "TsonPromiseRejectionError",
Expand Down
3 changes: 0 additions & 3 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// eslint-disable-next-line eslint-comments/disable-enable-pair
/* eslint-disable @typescript-eslint/no-explicit-any */
import { expect, test, vitest } from "vitest";

import {
Expand Down Expand Up @@ -179,7 +177,6 @@ test("async: bad values", async () => {
expect(onErrorSpy).toHaveBeenCalledTimes(1);
});

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
expect(onErrorSpy.mock.calls[0][0]).toMatchInlineSnapshot(
"[TsonError: Stream interrupted: Stream ended with 1 pending promises]",
);
Expand Down
2 changes: 0 additions & 2 deletions src/internals/getNonce.crypto.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// eslint-disable-next-line eslint-comments/disable-enable-pair
/* eslint-disable @typescript-eslint/no-explicit-any */
import { expect, test } from "vitest";

test("with crypto", async () => {
Expand Down
2 changes: 0 additions & 2 deletions src/internals/getNonce.nocrypto.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// eslint-disable-next-line eslint-comments/disable-enable-pair
/* eslint-disable @typescript-eslint/no-explicit-any */
import { expect, test } from "vitest";

test("without crypto", async () => {
Expand Down
2 changes: 0 additions & 2 deletions src/sync/createTson.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable eslint-comments/disable-enable-pair */

import { TsonOptions } from "../types.js";
import { createTsonDeserialize, createTsonParser } from "./deserialize.js";
import { createTsonSerialize, createTsonStringify } from "./serialize.js";
Expand Down
2 changes: 0 additions & 2 deletions src/sync/deserialize.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/no-explicit-any, eslint-comments/disable-enable-pair */

import { isTsonTuple } from "../internals/isTsonTuple.js";
import { mapOrReturn } from "../internals/mapOrReturn.js";
import {
Expand Down
1 change: 0 additions & 1 deletion src/sync/serialize.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-explicit-any, eslint-comments/disable-enable-pair */
import { TsonCircularReferenceError } from "../errors.js";
import { GetNonce, getNonce } from "../internals/getNonce.js";
import { mapOrReturn } from "../internals/mapOrReturn.js";
Expand Down
2 changes: 0 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// eslint-disable-next-line eslint-comments/disable-enable-pair
/* eslint-disable @typescript-eslint/no-explicit-any */
const brand = Symbol("branded");

export type TsonBranded<TType, TBrand> = TType & { [brand]: TBrand };
Expand Down
Loading