@typed/async-data 1.0.0-beta.3 → 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/README.md +32 -21
- package/dist/index.d.ts +664 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +501 -35
- package/package.json +19 -11
- package/src/__tests__/assert.type-test.ts +4 -0
- package/src/__tests__/flat-map.type-test.ts +29 -0
- package/src/index.ts +807 -41
- package/src/AsyncData.test.ts +0 -444
- package/src/index.test.ts +0 -497
package/package.json
CHANGED
|
@@ -1,33 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typed/async-data",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
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
29
|
"dependencies": {
|
|
23
|
-
"effect": "4.0.0-
|
|
30
|
+
"effect": "4.0.0-rc.112"
|
|
24
31
|
},
|
|
25
32
|
"devDependencies": {
|
|
26
|
-
"typescript": "
|
|
27
|
-
"vitest": "
|
|
33
|
+
"typescript": "7.0.2",
|
|
34
|
+
"vitest": "5.0.0"
|
|
28
35
|
},
|
|
29
36
|
"scripts": {
|
|
30
|
-
"build": "
|
|
31
|
-
"test": "vitest run --
|
|
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,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;
|