@typed/async-data 1.0.0-beta.4 → 1.0.0-beta.5

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/package.json CHANGED
@@ -1,33 +1,41 @@
1
1
  {
2
2
  "name": "@typed/async-data",
3
- "version": "1.0.0-beta.4",
3
+ "version": "1.0.0-beta.5",
4
+ "description": "Async data states for Typed applications.",
5
+ "license": "MIT",
6
+ "homepage": "https://github.com/TylorS/typed-smol/tree/main/packages/async-data#readme",
7
+ "bugs": "https://github.com/TylorS/typed-smol/issues",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/TylorS/typed-smol.git",
11
+ "directory": "packages/async-data"
12
+ },
4
13
  "files": [
5
14
  "dist",
6
- "src"
15
+ "src",
16
+ "!dist/**/*.test.*",
17
+ "!src/**/*.test.*"
7
18
  ],
8
19
  "type": "module",
9
20
  "exports": {
10
21
  ".": {
11
22
  "types": "./dist/index.d.ts",
12
23
  "import": "./dist/index.js"
13
- },
14
- "./*": {
15
- "types": "./dist/*.d.ts",
16
- "import": "./dist/*.js"
17
24
  }
18
25
  },
19
26
  "publishConfig": {
20
27
  "access": "public"
21
28
  },
22
- "scripts": {
23
- "build": "[ -d dist ] || rm -f tsconfig.tsbuildinfo; tsc",
24
- "test": "vitest run --passWithNoTests"
25
- },
26
29
  "dependencies": {
27
- "effect": "catalog:"
30
+ "effect": "4.0.0-rc.112"
28
31
  },
29
32
  "devDependencies": {
30
- "typescript": "catalog:",
31
- "vitest": "catalog:"
33
+ "typescript": "7.0.2",
34
+ "vitest": "5.0.0"
35
+ },
36
+ "scripts": {
37
+ "build": "node -e \"const fs=require('node:fs'); fs.rmSync('dist',{recursive:true,force:true}); fs.rmSync('tsconfig.tsbuildinfo',{force:true})\" && tsc",
38
+ "test": "vitest run --config vitest.config.ts",
39
+ "test:types": "pnpm run build && tsc -p tsconfig.type-tests.json && tsc -p tsconfig.tests.json"
32
40
  }
33
- }
41
+ }
@@ -0,0 +1,4 @@
1
+ export type Equal<A, B> =
2
+ (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? true : false;
3
+
4
+ export type Assert<T extends true> = T;
@@ -0,0 +1,29 @@
1
+ import { flatMap, type AsyncData, type Optimistic, type Success } from "@typed/async-data";
2
+ import type { Assert, Equal } from "./assert.type-test.js";
3
+
4
+ type ExistingError = { readonly _tag: "ExistingError" };
5
+ type NextError = { readonly _tag: "NextError" };
6
+
7
+ declare const input: AsyncData<number, ExistingError>;
8
+ declare const next: AsyncData<string, NextError>;
9
+
10
+ const direct = flatMap(input, (value, data) => {
11
+ type _Value = Assert<Equal<typeof value, number>>;
12
+ type _Context = Assert<Equal<typeof data, Success<number> | Optimistic<number, ExistingError>>>;
13
+ return next;
14
+ });
15
+
16
+ const curried = flatMap((value: number, data) => {
17
+ type _Value = Assert<Equal<typeof value, number>>;
18
+ type _Context = Assert<Equal<typeof data, Success<number> | Optimistic<number, unknown>>>;
19
+ return next;
20
+ })(input);
21
+
22
+ type Expected = AsyncData<string, ExistingError | NextError>;
23
+ type _Direct = Assert<Equal<typeof direct, Expected>>;
24
+ type _Curried = Assert<Equal<typeof curried, Expected>>;
25
+
26
+ // @ts-expect-error flatMap must retain the callback's error channel
27
+ const _directWithoutNextError: AsyncData<string, ExistingError> = direct;
28
+ // @ts-expect-error flatMap must retain the input's error channel
29
+ const _curriedWithoutExistingError: AsyncData<string, NextError> = curried;