@confect/react 10.0.0-next.0 → 10.0.0-next.10
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/CHANGELOG.md +123 -0
- package/dist/OptimisticLocalStore.js +1 -2
- package/dist/OptimisticLocalStore.js.map +1 -1
- package/dist/PaginatedQueryResult.d.ts +118 -0
- package/dist/PaginatedQueryResult.d.ts.map +1 -0
- package/dist/PaginatedQueryResult.js +95 -0
- package/dist/PaginatedQueryResult.js.map +1 -0
- package/dist/QueryResult.d.ts.map +1 -1
- package/dist/QueryResult.js +9 -22
- package/dist/QueryResult.js.map +1 -1
- package/dist/_virtual/_rolldown/runtime.js +6 -11
- package/dist/index.d.ts +46 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +75 -5
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.src.tsbuildinfo +1 -1
- package/package.json +17 -16
- package/src/PaginatedQueryResult.ts +322 -0
- package/src/QueryResult.ts +38 -29
- package/src/index.ts +238 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,63 @@
|
|
|
1
1
|
# @confect/react
|
|
2
2
|
|
|
3
|
+
## 10.0.0-next.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Sync with `main`: this prerelease line now includes all changes released in `@confect/*` 9.3.0 — see that version's changelog entries.
|
|
8
|
+
|
|
9
|
+
## 10.0.0-next.9
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 0dcc0fb: Raise the required `effect` peer version to `^4.0.0-beta.102` (from `^4.0.0-beta.101`), and `@confect/server`'s optional `@effect/platform-node` peer version likewise.
|
|
14
|
+
- 25e8d19: Sync with `main`: this prerelease line now includes all changes released in `@confect/*` 9.2.5 — see that version's changelog entries.
|
|
15
|
+
|
|
16
|
+
## 10.0.0-next.8
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- 913d0e5: Raise the required `effect` peer version to `^4.0.0-beta.101` (from `^4.0.0-beta.100`).
|
|
21
|
+
|
|
22
|
+
This is a peer-range-only change with no consumer-visible API consequences. The `beta.101` release only touches fiber/concurrency internals (interrupt handling in concurrent traversal, stack frame annotations, `awaitAllChildren` linearization, `interruptibleMask` interrupt delivery), a `MutableList.filter` fix for empty buckets, a `Schema.Struct` required-readonly-field type display simplification, and an `HttpRouter.toWebHandler` middleware type-inference tightening that Confect doesn't need to accommodate.
|
|
23
|
+
|
|
24
|
+
## 10.0.0-next.7
|
|
25
|
+
|
|
26
|
+
## 10.0.0-next.6
|
|
27
|
+
|
|
28
|
+
## 10.0.0-next.5
|
|
29
|
+
|
|
30
|
+
## 10.0.0-next.4
|
|
31
|
+
|
|
32
|
+
## 10.0.0-next.3
|
|
33
|
+
|
|
34
|
+
### Patch Changes
|
|
35
|
+
|
|
36
|
+
- 5b63546: Raise the required `effect` peer version to `^4.0.0-beta.100` (from `^4.0.0-beta.99`).
|
|
37
|
+
|
|
38
|
+
This is a peer-range-only change with no consumer-visible API consequences. The `beta.100` release only touches `Cron` internals (month/weekday alias normalization, day/weekday rollover, and equality/hashing), CLI error message formatting (`InvalidValue` prefixes), and `Schema.toTaggedUnion` discriminants that Confect doesn't use.
|
|
39
|
+
|
|
40
|
+
## 10.0.0-next.2
|
|
41
|
+
|
|
42
|
+
### Patch Changes
|
|
43
|
+
|
|
44
|
+
- 35f7515: Raise the required `effect` peer version to `^4.0.0-beta.99` (from `^4.0.0-beta.98`).
|
|
45
|
+
|
|
46
|
+
This is a peer-range-only change with no consumer-visible API consequences. The `beta.99` release only touches `Graph`, CLI (`Command`/`CliConfig`/wizard mode), `Tool` cloning, Redis script eval, and multipart parser internals that Confect doesn't use.
|
|
47
|
+
|
|
48
|
+
- 2aa7541: Sync with `main`: this prerelease line now includes all changes released in `@confect/*` 9.2.2–9.2.4 — see those versions' changelog entries.
|
|
49
|
+
|
|
50
|
+
## 10.0.0-next.1
|
|
51
|
+
|
|
52
|
+
### Patch Changes
|
|
53
|
+
|
|
54
|
+
- 4d98ea8: Raise the required `effect` peer version to `^4.0.0-beta.98` (from `^4.0.0-beta.97`).
|
|
55
|
+
|
|
56
|
+
`effect`'s `SchemaError` is now exposed as its own public module (`effect/SchemaError`), which changes the import path TypeScript picks when Confect emits `.d.ts` declarations that reference `Schema.SchemaError` (for example in generated `services.d.ts`). Existing `Schema.SchemaError` / `Schema.isSchemaError` usage is unaffected — this is purely a declaration-emit detail that consumers relying on generated types may notice.
|
|
57
|
+
|
|
58
|
+
- Updated dependencies [4d98ea8]
|
|
59
|
+
- @confect/core@10.0.0-next.1
|
|
60
|
+
|
|
3
61
|
## 10.0.0-next.0
|
|
4
62
|
|
|
5
63
|
### Major Changes
|
|
@@ -22,6 +80,71 @@
|
|
|
22
80
|
- Updated dependencies [70e313e]
|
|
23
81
|
- @confect/core@10.0.0-next.0
|
|
24
82
|
|
|
83
|
+
## 9.3.0
|
|
84
|
+
|
|
85
|
+
### Minor Changes
|
|
86
|
+
|
|
87
|
+
- 16b5ad6: Add first-class paginated queries: declare one with `FunctionSpec.publicPaginatedQuery` (or `internalPaginatedQuery`) and read it with the new `usePaginatedQuery` hook from `@confect/react`.
|
|
88
|
+
|
|
89
|
+
Pass an `item` schema — the type of one element in a page — in place of `returns`, plus an optional `args` struct for your own arguments. The handler receives `paginationOpts` alongside them and forwards it to `paginate`.
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
// confect/notes.spec.ts
|
|
93
|
+
FunctionSpec.publicPaginatedQuery({
|
|
94
|
+
name: "listByAuthor",
|
|
95
|
+
args: () => Schema.Struct({ author: Schema.String }),
|
|
96
|
+
item: () => notes.Doc,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// confect/notes.impl.ts
|
|
100
|
+
({ author, paginationOpts }) =>
|
|
101
|
+
Effect.gen(function* () {
|
|
102
|
+
const reader = yield* DatabaseReader;
|
|
103
|
+
|
|
104
|
+
return yield* reader
|
|
105
|
+
.table("notes")
|
|
106
|
+
.index("by_creation_time", "desc")
|
|
107
|
+
.paginate(paginationOpts, (q) => q.eq(q.field("author"), author));
|
|
108
|
+
}).pipe(Effect.orDie);
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Declaring `paginationOpts` in `args` yourself is a type and runtime error.
|
|
112
|
+
|
|
113
|
+
```tsx
|
|
114
|
+
import { PaginatedQueryResult, usePaginatedQuery } from "@confect/react";
|
|
115
|
+
|
|
116
|
+
const notes = usePaginatedQuery(
|
|
117
|
+
refs.public.notes.listByAuthor,
|
|
118
|
+
{ author },
|
|
119
|
+
{ initialNumItems: 10 },
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
// `notes.results` holds the pages decoded through `item`.
|
|
123
|
+
if (PaginatedQueryResult.isCanLoadMore(notes)) {
|
|
124
|
+
notes.loadMore(10);
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
The hook returns a `PaginatedQueryResult<Item, E>`. `LoadingFirstPage`, `LoadingMore`, `CanLoadMore`, and `Exhausted` all carry `results` and `isLoading`; `loadMore` lives only on `CanLoadMore`, the one state it can make progress from. A declared `error` schema surfaces as a `Failure` variant carrying the decoded error instead of throwing during render, and `Failure` carries `results` too, so the pages loaded before it can still be rendered. Without an `error` schema, `Failure` is absent from the type entirely.
|
|
129
|
+
|
|
130
|
+
`paginate` in `@confect/server` now accepts Convex's full `PaginationOptions`, so a handler's `paginationOpts` passes straight through. `@confect/react` now requires `convex` >= 1.36.0.
|
|
131
|
+
|
|
132
|
+
## 9.2.5
|
|
133
|
+
|
|
134
|
+
## 9.2.4
|
|
135
|
+
|
|
136
|
+
## 9.2.3
|
|
137
|
+
|
|
138
|
+
### Patch Changes
|
|
139
|
+
|
|
140
|
+
- @confect/core@9.2.3
|
|
141
|
+
|
|
142
|
+
## 9.2.2
|
|
143
|
+
|
|
144
|
+
### Patch Changes
|
|
145
|
+
|
|
146
|
+
- @confect/core@9.2.2
|
|
147
|
+
|
|
25
148
|
## 9.2.1
|
|
26
149
|
|
|
27
150
|
### Patch Changes
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { Ref } from "@confect/core";
|
|
3
3
|
import * as Option from "effect/Option";
|
|
4
|
-
|
|
5
4
|
//#region src/OptimisticLocalStore.ts
|
|
6
5
|
var OptimisticLocalStore_exports = /* @__PURE__ */ __exportAll({ make: () => make });
|
|
7
6
|
/**
|
|
@@ -33,7 +32,7 @@ const make = (convexLocalStore) => ({
|
|
|
33
32
|
convexLocalStore.setQuery(functionReference, encodedArgs, encodedValue);
|
|
34
33
|
}
|
|
35
34
|
});
|
|
36
|
-
|
|
37
35
|
//#endregion
|
|
38
36
|
export { OptimisticLocalStore_exports, make };
|
|
37
|
+
|
|
39
38
|
//# sourceMappingURL=OptimisticLocalStore.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OptimisticLocalStore.js","names":[],"sources":["../src/OptimisticLocalStore.ts"],"sourcesContent":["import { Ref } from \"@confect/core\";\nimport type { OptimisticLocalStore as ConvexOptimisticLocalStore } from \"convex/browser\";\nimport * as Option from \"effect/Option\";\n\n/**\n * The Confect counterpart to Convex's `OptimisticLocalStore`.\n *\n * Its methods accept Confect query `Ref`s and operate on decoded (Effect\n * Schema) values rather than the encoded values stored by Convex. Query values\n * are wrapped in `Option`: `Option.none()` represents a query that is not\n * present in the store, and `Option.some(value)` carries the decoded value.\n */\nexport interface OptimisticLocalStore {\n getQuery<Query extends Ref.AnyPublicQuery>(\n queryRef: Query,\n ...args: Ref.OptionalArgs<Query>\n ): Option.Option<Ref.Returns<Query>>;\n\n getAllQueries<Query extends Ref.AnyPublicQuery>(\n queryRef: Query,\n ): Array<{\n args: Ref.Args<Query>;\n value: Option.Option<Ref.Returns<Query>>;\n }>;\n\n setQuery<Query extends Ref.AnyPublicQuery>(\n queryRef: Query,\n args: Ref.Args<Query>,\n value: Option.Option<Ref.Returns<Query>>,\n ): void;\n}\n\n/**\n * Wraps Convex's `OptimisticLocalStore` so that it accepts Confect query `Ref`s\n * and decoded values, handling the encoding/decoding against Convex's store.\n */\nexport const make = (\n convexLocalStore: ConvexOptimisticLocalStore,\n): OptimisticLocalStore => ({\n getQuery: (queryRef, ...rest) => {\n const functionReference = Ref.getFunctionReference(queryRef);\n const args = (rest[0] ?? {}) as Ref.Args<typeof queryRef>;\n const encodedArgs = Ref.encodeArgsSync(queryRef, args);\n const encoded = convexLocalStore.getQuery(functionReference, encodedArgs);\n return encoded === undefined\n ? Option.none()\n : Option.some(Ref.decodeReturnsSync(queryRef, encoded));\n },\n getAllQueries: (queryRef) => {\n const functionReference = Ref.getFunctionReference(queryRef);\n return convexLocalStore\n .getAllQueries(functionReference)\n .map(({ args, value }) => ({\n args: Ref.decodeArgsSync(queryRef, args),\n value:\n value === undefined\n ? Option.none()\n : Option.some(Ref.decodeReturnsSync(queryRef, value)),\n }));\n },\n setQuery: (queryRef, args, value) => {\n const functionReference = Ref.getFunctionReference(queryRef);\n const encodedArgs = Ref.encodeArgsSync(queryRef, args);\n const encodedValue = Option.match(value, {\n onNone: () => undefined,\n onSome: (decoded) => Ref.encodeReturnsSync(queryRef, decoded),\n });\n convexLocalStore.setQuery(functionReference, encodedArgs, encodedValue);\n },\n});\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"OptimisticLocalStore.js","names":[],"sources":["../src/OptimisticLocalStore.ts"],"sourcesContent":["import { Ref } from \"@confect/core\";\nimport type { OptimisticLocalStore as ConvexOptimisticLocalStore } from \"convex/browser\";\nimport * as Option from \"effect/Option\";\n\n/**\n * The Confect counterpart to Convex's `OptimisticLocalStore`.\n *\n * Its methods accept Confect query `Ref`s and operate on decoded (Effect\n * Schema) values rather than the encoded values stored by Convex. Query values\n * are wrapped in `Option`: `Option.none()` represents a query that is not\n * present in the store, and `Option.some(value)` carries the decoded value.\n */\nexport interface OptimisticLocalStore {\n getQuery<Query extends Ref.AnyPublicQuery>(\n queryRef: Query,\n ...args: Ref.OptionalArgs<Query>\n ): Option.Option<Ref.Returns<Query>>;\n\n getAllQueries<Query extends Ref.AnyPublicQuery>(\n queryRef: Query,\n ): Array<{\n args: Ref.Args<Query>;\n value: Option.Option<Ref.Returns<Query>>;\n }>;\n\n setQuery<Query extends Ref.AnyPublicQuery>(\n queryRef: Query,\n args: Ref.Args<Query>,\n value: Option.Option<Ref.Returns<Query>>,\n ): void;\n}\n\n/**\n * Wraps Convex's `OptimisticLocalStore` so that it accepts Confect query `Ref`s\n * and decoded values, handling the encoding/decoding against Convex's store.\n */\nexport const make = (\n convexLocalStore: ConvexOptimisticLocalStore,\n): OptimisticLocalStore => ({\n getQuery: (queryRef, ...rest) => {\n const functionReference = Ref.getFunctionReference(queryRef);\n const args = (rest[0] ?? {}) as Ref.Args<typeof queryRef>;\n const encodedArgs = Ref.encodeArgsSync(queryRef, args);\n const encoded = convexLocalStore.getQuery(functionReference, encodedArgs);\n return encoded === undefined\n ? Option.none()\n : Option.some(Ref.decodeReturnsSync(queryRef, encoded));\n },\n getAllQueries: (queryRef) => {\n const functionReference = Ref.getFunctionReference(queryRef);\n return convexLocalStore\n .getAllQueries(functionReference)\n .map(({ args, value }) => ({\n args: Ref.decodeArgsSync(queryRef, args),\n value:\n value === undefined\n ? Option.none()\n : Option.some(Ref.decodeReturnsSync(queryRef, value)),\n }));\n },\n setQuery: (queryRef, args, value) => {\n const functionReference = Ref.getFunctionReference(queryRef);\n const encodedArgs = Ref.encodeArgsSync(queryRef, args);\n const encodedValue = Option.match(value, {\n onNone: () => undefined,\n onSome: (decoded) => Ref.encodeReturnsSync(queryRef, decoded),\n });\n convexLocalStore.setQuery(functionReference, encodedArgs, encodedValue);\n },\n});\n"],"mappings":";;;;;;;;;AAoCA,MAAa,QACX,sBAC0B;CAC1B,WAAW,UAAU,GAAG,SAAS;EAC/B,MAAM,oBAAoB,IAAI,qBAAqB,QAAQ;EAC3D,MAAM,OAAQ,KAAK,MAAM,CAAC;EAC1B,MAAM,cAAc,IAAI,eAAe,UAAU,IAAI;EACrD,MAAM,UAAU,iBAAiB,SAAS,mBAAmB,WAAW;EACxE,OAAO,YAAY,KAAA,IACf,OAAO,KAAK,IACZ,OAAO,KAAK,IAAI,kBAAkB,UAAU,OAAO,CAAC;CAC1D;CACA,gBAAgB,aAAa;EAC3B,MAAM,oBAAoB,IAAI,qBAAqB,QAAQ;EAC3D,OAAO,iBACJ,cAAc,iBAAiB,CAAC,CAChC,KAAK,EAAE,MAAM,aAAa;GACzB,MAAM,IAAI,eAAe,UAAU,IAAI;GACvC,OACE,UAAU,KAAA,IACN,OAAO,KAAK,IACZ,OAAO,KAAK,IAAI,kBAAkB,UAAU,KAAK,CAAC;EAC1D,EAAE;CACN;CACA,WAAW,UAAU,MAAM,UAAU;EACnC,MAAM,oBAAoB,IAAI,qBAAqB,QAAQ;EAC3D,MAAM,cAAc,IAAI,eAAe,UAAU,IAAI;EACrD,MAAM,eAAe,OAAO,MAAM,OAAO;GACvC,cAAc,KAAA;GACd,SAAS,YAAY,IAAI,kBAAkB,UAAU,OAAO;EAC9D,CAAC;EACD,iBAAiB,SAAS,mBAAmB,aAAa,YAAY;CACxE;AACF"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import * as Pipeable from "effect/Pipeable";
|
|
2
|
+
declare const TypeId = "@confect/react/PaginatedQueryResult";
|
|
3
|
+
type TypeId = typeof TypeId;
|
|
4
|
+
/**
|
|
5
|
+
* A `PaginatedQueryResult` represents the result of a Confect paginated query.
|
|
6
|
+
* The non-`Failure` variants mirror the statuses of `usePaginatedQuery` from
|
|
7
|
+
* `convex/react` and all carry `results` and `isLoading`, so the common UI
|
|
8
|
+
* shape — render the list, show a spinner while loading — needs only an
|
|
9
|
+
* {@link isFailure} early-out and plain field access.
|
|
10
|
+
*
|
|
11
|
+
* Every variant carries `results`, including `Failure`: when a later page
|
|
12
|
+
* fails, the pages already loaded are still worth rendering alongside the
|
|
13
|
+
* error, so they are not discarded. `Failure` additionally carries the
|
|
14
|
+
* query's decoded typed error.
|
|
15
|
+
*
|
|
16
|
+
* `loadMore` appears only on `CanLoadMore`, the one state it can make
|
|
17
|
+
* progress from. The underlying Convex hook exposes it on every status, but
|
|
18
|
+
* calling it while a page is in flight, once the list is exhausted, or after
|
|
19
|
+
* a failure is an intentional no-op there; narrowing to `CanLoadMore` — via
|
|
20
|
+
* {@link isCanLoadMore} or {@link match} — makes that statically apparent
|
|
21
|
+
* instead of silently dropping the call.
|
|
22
|
+
*
|
|
23
|
+
* When the query declares no `error` schema (`E` is `never`), the `Failure`
|
|
24
|
+
* variant is excluded from the type entirely, so `isLoading` is accessible
|
|
25
|
+
* without any narrowing.
|
|
26
|
+
*
|
|
27
|
+
* @typeParam Item - The type of a decoded page item.
|
|
28
|
+
* @typeParam E - The type of the decoded typed error in the `Failure` variant.
|
|
29
|
+
*/
|
|
30
|
+
export type PaginatedQueryResult<Item, E = never> = [E] extends [never] ? LoadingFirstPage<Item, E> | LoadingMore<Item, E> | CanLoadMore<Item, E> | Exhausted<Item, E> : LoadingFirstPage<Item, E> | LoadingMore<Item, E> | CanLoadMore<Item, E> | Exhausted<Item, E> | Failure<Item, E>;
|
|
31
|
+
/**
|
|
32
|
+
* Every variant regardless of `E` — the parameter type for guards and
|
|
33
|
+
* {@link match}, since `PaginatedQueryResult` itself excludes `Failure` when
|
|
34
|
+
* `E` is `never`.
|
|
35
|
+
*/
|
|
36
|
+
export type Variants<Item, E = never> = LoadingFirstPage<Item, E> | LoadingMore<Item, E> | CanLoadMore<Item, E> | Exhausted<Item, E> | Failure<Item, E>;
|
|
37
|
+
export declare namespace PaginatedQueryResult {
|
|
38
|
+
interface Proto<Item, E> extends Pipeable.Pipeable {
|
|
39
|
+
readonly [TypeId]: {
|
|
40
|
+
readonly E: (_: never) => E;
|
|
41
|
+
readonly Item: (_: never) => Item;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
type Item<R> = R extends Proto<infer Item_, infer _E> ? Item_ : never;
|
|
45
|
+
type Failure<R> = R extends Proto<infer _Item, infer E> ? E : never;
|
|
46
|
+
}
|
|
47
|
+
export interface LoadingFirstPage<Item, E = never> extends PaginatedQueryResult.Proto<Item, E> {
|
|
48
|
+
readonly _tag: "LoadingFirstPage";
|
|
49
|
+
readonly skipped: boolean;
|
|
50
|
+
readonly results: ReadonlyArray<Item>;
|
|
51
|
+
readonly isLoading: true;
|
|
52
|
+
}
|
|
53
|
+
export interface LoadingMore<Item, E = never> extends PaginatedQueryResult.Proto<Item, E> {
|
|
54
|
+
readonly _tag: "LoadingMore";
|
|
55
|
+
readonly results: ReadonlyArray<Item>;
|
|
56
|
+
readonly isLoading: true;
|
|
57
|
+
}
|
|
58
|
+
export interface CanLoadMore<Item, E = never> extends PaginatedQueryResult.Proto<Item, E> {
|
|
59
|
+
readonly _tag: "CanLoadMore";
|
|
60
|
+
readonly results: ReadonlyArray<Item>;
|
|
61
|
+
readonly isLoading: false;
|
|
62
|
+
readonly loadMore: (numItems: number) => void;
|
|
63
|
+
}
|
|
64
|
+
export interface Exhausted<Item, E = never> extends PaginatedQueryResult.Proto<Item, E> {
|
|
65
|
+
readonly _tag: "Exhausted";
|
|
66
|
+
readonly results: ReadonlyArray<Item>;
|
|
67
|
+
readonly isLoading: false;
|
|
68
|
+
}
|
|
69
|
+
export interface Failure<Item, E = never> extends PaginatedQueryResult.Proto<Item, E> {
|
|
70
|
+
readonly _tag: "Failure";
|
|
71
|
+
readonly error: E;
|
|
72
|
+
/** The pages loaded before the failure. */
|
|
73
|
+
readonly results: ReadonlyArray<Item>;
|
|
74
|
+
}
|
|
75
|
+
export declare const isPaginatedQueryResult: (u: unknown) => u is Variants<unknown, unknown>;
|
|
76
|
+
export declare const loadingFirstPage: <Item = never, E = never>(options: {
|
|
77
|
+
skipped: boolean;
|
|
78
|
+
}) => LoadingFirstPage<Item, E>;
|
|
79
|
+
export declare const loadingMore: <Item, E = never>(options: {
|
|
80
|
+
results: ReadonlyArray<Item>;
|
|
81
|
+
}) => LoadingMore<Item, E>;
|
|
82
|
+
export declare const canLoadMore: <Item, E = never>(options: {
|
|
83
|
+
results: ReadonlyArray<Item>;
|
|
84
|
+
loadMore: (numItems: number) => void;
|
|
85
|
+
}) => CanLoadMore<Item, E>;
|
|
86
|
+
export declare const exhausted: <Item, E = never>(options: {
|
|
87
|
+
results: ReadonlyArray<Item>;
|
|
88
|
+
}) => Exhausted<Item, E>;
|
|
89
|
+
export declare const failure: <E, Item = never>(options: {
|
|
90
|
+
error: E;
|
|
91
|
+
results: ReadonlyArray<Item>;
|
|
92
|
+
}) => Failure<Item, E>;
|
|
93
|
+
export declare const isLoadingFirstPage: <Item, E>(result: Variants<Item, E>) => result is LoadingFirstPage<Item, E>;
|
|
94
|
+
export declare const isLoadingMore: <Item, E>(result: Variants<Item, E>) => result is LoadingMore<Item, E>;
|
|
95
|
+
export declare const isCanLoadMore: <Item, E>(result: Variants<Item, E>) => result is CanLoadMore<Item, E>;
|
|
96
|
+
export declare const isExhausted: <Item, E>(result: Variants<Item, E>) => result is Exhausted<Item, E>;
|
|
97
|
+
export declare const isFailure: <Item, E>(result: Variants<Item, E>) => result is Failure<Item, E>;
|
|
98
|
+
export declare const isLoading: <Item, E>(result: Variants<Item, E>) => result is LoadingFirstPage<Item, E> | LoadingMore<Item, E>;
|
|
99
|
+
type MatchOptions<Item, E, V, W, X, Y, Z> = {
|
|
100
|
+
readonly onLoadingFirstPage: (skipped: boolean) => V;
|
|
101
|
+
readonly onLoadingMore: (results: ReadonlyArray<Item>) => W;
|
|
102
|
+
readonly onCanLoadMore: (results: ReadonlyArray<Item>, loadMore: (numItems: number) => void) => X;
|
|
103
|
+
readonly onExhausted: (results: ReadonlyArray<Item>) => Y;
|
|
104
|
+
} & ([E] extends [never] ? {} : {
|
|
105
|
+
readonly onFailure: (error: E, results: ReadonlyArray<Item>) => Z;
|
|
106
|
+
});
|
|
107
|
+
type MatchReturns<E, V, W, X, Y, Z> = [E] extends [never] ? V | W | X | Y : V | W | X | Y | Z;
|
|
108
|
+
/**
|
|
109
|
+
* Matches a {@link PaginatedQueryResult} to the appropriate handler based on
|
|
110
|
+
* its tag. If the provided result cannot fail (i.e. `E` is `never`),
|
|
111
|
+
* `onFailure` is not required.
|
|
112
|
+
*/
|
|
113
|
+
export declare const match: {
|
|
114
|
+
<Item, E, V, W, X, Y, Z = never>(options: MatchOptions<Item, E, V, W, X, Y, Z>): (self: Variants<Item, E>) => MatchReturns<E, V, W, X, Y, Z>;
|
|
115
|
+
<Item, E, V, W, X, Y, Z = never>(self: Variants<Item, E>, options: MatchOptions<Item, E, V, W, X, Y, Z>): MatchReturns<E, V, W, X, Y, Z>;
|
|
116
|
+
};
|
|
117
|
+
export {};
|
|
118
|
+
//# sourceMappingURL=PaginatedQueryResult.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PaginatedQueryResult.d.ts","sourceRoot":"","sources":["../src/PaginatedQueryResult.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAG5C,QAAA,MAAM,MAAM,wCAAwC,CAAC;AACrD,KAAK,MAAM,GAAG,OAAO,MAAM,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,MAAM,oBAAoB,CAAC,IAAI,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAE/D,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC,GACzB,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,GACpB,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,GACpB,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,GAElB,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC,GACzB,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,GACpB,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,GACpB,SAAS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ACvB,OAAO,EAAE,YAAY,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAC5C,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;CA8BnC,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
import * as Match from "effect/Match";
|
|
3
|
+
import * as Function from "effect/Function";
|
|
4
|
+
import { identity } from "effect/Function";
|
|
5
|
+
import * as Equal from "effect/Equal";
|
|
6
|
+
import * as Hash from "effect/Hash";
|
|
7
|
+
import * as Pipeable from "effect/Pipeable";
|
|
8
|
+
import * as Predicate from "effect/Predicate";
|
|
9
|
+
//#region src/PaginatedQueryResult.ts
|
|
10
|
+
var PaginatedQueryResult_exports = /* @__PURE__ */ __exportAll({
|
|
11
|
+
canLoadMore: () => canLoadMore,
|
|
12
|
+
exhausted: () => exhausted,
|
|
13
|
+
failure: () => failure,
|
|
14
|
+
isCanLoadMore: () => isCanLoadMore,
|
|
15
|
+
isExhausted: () => isExhausted,
|
|
16
|
+
isFailure: () => isFailure,
|
|
17
|
+
isLoading: () => isLoading,
|
|
18
|
+
isLoadingFirstPage: () => isLoadingFirstPage,
|
|
19
|
+
isLoadingMore: () => isLoadingMore,
|
|
20
|
+
isPaginatedQueryResult: () => isPaginatedQueryResult,
|
|
21
|
+
loadingFirstPage: () => loadingFirstPage,
|
|
22
|
+
loadingMore: () => loadingMore,
|
|
23
|
+
match: () => match
|
|
24
|
+
});
|
|
25
|
+
const TypeId = "@confect/react/PaginatedQueryResult";
|
|
26
|
+
const isPaginatedQueryResult = (u) => Predicate.hasProperty(u, TypeId);
|
|
27
|
+
const PaginatedQueryResultProto = {
|
|
28
|
+
[TypeId]: {
|
|
29
|
+
E: identity,
|
|
30
|
+
Item: identity
|
|
31
|
+
},
|
|
32
|
+
pipe(...args) {
|
|
33
|
+
return Pipeable.pipeArguments(this, args);
|
|
34
|
+
},
|
|
35
|
+
/**
|
|
36
|
+
* `CanLoadMore`'s `loadMore` is excluded from equality and hashing, like
|
|
37
|
+
* function fields generally: two results that render identically are equal
|
|
38
|
+
* even though their callbacks differ by identity.
|
|
39
|
+
*/
|
|
40
|
+
[Equal.symbol](that) {
|
|
41
|
+
if (this._tag !== that._tag) return false;
|
|
42
|
+
return Match.value(this).pipe(Match.tag("LoadingFirstPage", (self) => self.skipped === that.skipped), Match.tag("LoadingMore", "CanLoadMore", "Exhausted", (self) => Equal.equals(self.results, that.results)), Match.tag("Failure", (self) => Equal.equals(self.error, that.error) && Equal.equals(self.results, that.results)), Match.exhaustive);
|
|
43
|
+
},
|
|
44
|
+
[Hash.symbol]() {
|
|
45
|
+
const tagHash = Hash.string(this._tag);
|
|
46
|
+
return Match.value(this).pipe(Match.tag("LoadingFirstPage", (self) => Hash.combine(tagHash)(Hash.hash(self.skipped))), Match.tag("LoadingMore", "CanLoadMore", "Exhausted", (self) => Hash.combine(tagHash)(Hash.hash(self.results))), Match.tag("Failure", (self) => Hash.combine(tagHash)(Hash.combine(Hash.hash(self.error))(Hash.hash(self.results)))), Match.exhaustive);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const noResults = [];
|
|
50
|
+
const loadingFirstPage = (options) => Object.assign(Object.create(PaginatedQueryResultProto), {
|
|
51
|
+
_tag: "LoadingFirstPage",
|
|
52
|
+
skipped: options.skipped,
|
|
53
|
+
results: noResults,
|
|
54
|
+
isLoading: true
|
|
55
|
+
});
|
|
56
|
+
const loadingMore = (options) => Object.assign(Object.create(PaginatedQueryResultProto), {
|
|
57
|
+
_tag: "LoadingMore",
|
|
58
|
+
results: options.results,
|
|
59
|
+
isLoading: true
|
|
60
|
+
});
|
|
61
|
+
const canLoadMore = (options) => Object.assign(Object.create(PaginatedQueryResultProto), {
|
|
62
|
+
_tag: "CanLoadMore",
|
|
63
|
+
results: options.results,
|
|
64
|
+
isLoading: false,
|
|
65
|
+
loadMore: options.loadMore
|
|
66
|
+
});
|
|
67
|
+
const exhausted = (options) => Object.assign(Object.create(PaginatedQueryResultProto), {
|
|
68
|
+
_tag: "Exhausted",
|
|
69
|
+
results: options.results,
|
|
70
|
+
isLoading: false
|
|
71
|
+
});
|
|
72
|
+
const failure = (options) => Object.assign(Object.create(PaginatedQueryResultProto), {
|
|
73
|
+
_tag: "Failure",
|
|
74
|
+
error: options.error,
|
|
75
|
+
results: options.results
|
|
76
|
+
});
|
|
77
|
+
const isLoadingFirstPage = (result) => result._tag === "LoadingFirstPage";
|
|
78
|
+
const isLoadingMore = (result) => result._tag === "LoadingMore";
|
|
79
|
+
const isCanLoadMore = (result) => result._tag === "CanLoadMore";
|
|
80
|
+
const isExhausted = (result) => result._tag === "Exhausted";
|
|
81
|
+
const isFailure = (result) => result._tag === "Failure";
|
|
82
|
+
const isLoading = (result) => result._tag === "LoadingFirstPage" || result._tag === "LoadingMore";
|
|
83
|
+
/**
|
|
84
|
+
* Matches a {@link PaginatedQueryResult} to the appropriate handler based on
|
|
85
|
+
* its tag. If the provided result cannot fail (i.e. `E` is `never`),
|
|
86
|
+
* `onFailure` is not required.
|
|
87
|
+
*/
|
|
88
|
+
const match = Function.dual(2, (self, options) => Match.value(self).pipe(Match.tag("LoadingFirstPage", (loadingFirstPage_) => options.onLoadingFirstPage(loadingFirstPage_.skipped)), Match.tag("LoadingMore", (loadingMore_) => options.onLoadingMore(loadingMore_.results)), Match.tag("CanLoadMore", (canLoadMore_) => options.onCanLoadMore(canLoadMore_.results, canLoadMore_.loadMore)), Match.tag("Exhausted", (exhausted_) => options.onExhausted(exhausted_.results)), Match.tag("Failure", (failure_) => {
|
|
89
|
+
if (Predicate.hasProperty(options, "onFailure")) return options.onFailure(failure_.error, failure_.results);
|
|
90
|
+
throw new Error("`onFailure` is required when error schema is provided");
|
|
91
|
+
}), Match.exhaustive));
|
|
92
|
+
//#endregion
|
|
93
|
+
export { PaginatedQueryResult_exports, canLoadMore, exhausted, failure, isCanLoadMore, isExhausted, isFailure, isLoading, isLoadingFirstPage, isLoadingMore, isPaginatedQueryResult, loadingFirstPage, loadingMore, match };
|
|
94
|
+
|
|
95
|
+
//# sourceMappingURL=PaginatedQueryResult.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PaginatedQueryResult.js","names":[],"sources":["../src/PaginatedQueryResult.ts"],"sourcesContent":["import { identity } from \"effect/Function\";\nimport * as Equal from \"effect/Equal\";\nimport * as Function from \"effect/Function\";\nimport * as Hash from \"effect/Hash\";\nimport * as Match from \"effect/Match\";\nimport * as Pipeable from \"effect/Pipeable\";\nimport * as Predicate from \"effect/Predicate\";\n\nconst TypeId = \"@confect/react/PaginatedQueryResult\";\ntype TypeId = typeof TypeId;\n\n/**\n * A `PaginatedQueryResult` represents the result of a Confect paginated query.\n * The non-`Failure` variants mirror the statuses of `usePaginatedQuery` from\n * `convex/react` and all carry `results` and `isLoading`, so the common UI\n * shape — render the list, show a spinner while loading — needs only an\n * {@link isFailure} early-out and plain field access.\n *\n * Every variant carries `results`, including `Failure`: when a later page\n * fails, the pages already loaded are still worth rendering alongside the\n * error, so they are not discarded. `Failure` additionally carries the\n * query's decoded typed error.\n *\n * `loadMore` appears only on `CanLoadMore`, the one state it can make\n * progress from. The underlying Convex hook exposes it on every status, but\n * calling it while a page is in flight, once the list is exhausted, or after\n * a failure is an intentional no-op there; narrowing to `CanLoadMore` — via\n * {@link isCanLoadMore} or {@link match} — makes that statically apparent\n * instead of silently dropping the call.\n *\n * When the query declares no `error` schema (`E` is `never`), the `Failure`\n * variant is excluded from the type entirely, so `isLoading` is accessible\n * without any narrowing.\n *\n * @typeParam Item - The type of a decoded page item.\n * @typeParam E - The type of the decoded typed error in the `Failure` variant.\n */\nexport type PaginatedQueryResult<Item, E = never> = [E] extends [never]\n ?\n | LoadingFirstPage<Item, E>\n | LoadingMore<Item, E>\n | CanLoadMore<Item, E>\n | Exhausted<Item, E>\n :\n | LoadingFirstPage<Item, E>\n | LoadingMore<Item, E>\n | CanLoadMore<Item, E>\n | Exhausted<Item, E>\n | Failure<Item, E>;\n\n/**\n * Every variant regardless of `E` — the parameter type for guards and\n * {@link match}, since `PaginatedQueryResult` itself excludes `Failure` when\n * `E` is `never`.\n */\nexport type Variants<Item, E = never> =\n | LoadingFirstPage<Item, E>\n | LoadingMore<Item, E>\n | CanLoadMore<Item, E>\n | Exhausted<Item, E>\n | Failure<Item, E>;\n\nexport declare namespace PaginatedQueryResult {\n // eslint-disable-next-line @typescript-eslint/no-shadow, import/namespace -- oxlint's namespace resolution misses type-only exports, and `Pipeable` is an interface\n export interface Proto<Item, E> extends Pipeable.Pipeable {\n readonly [TypeId]: {\n readonly E: (_: never) => E;\n readonly Item: (_: never) => Item;\n };\n }\n\n export type Item<R> = R extends Proto<infer Item_, infer _E> ? Item_ : never;\n\n // eslint-disable-next-line @typescript-eslint/no-shadow\n export type Failure<R> = R extends Proto<infer _Item, infer E> ? E : never;\n}\n\nexport interface LoadingFirstPage<\n Item,\n E = never,\n> extends PaginatedQueryResult.Proto<Item, E> {\n readonly _tag: \"LoadingFirstPage\";\n readonly skipped: boolean;\n readonly results: ReadonlyArray<Item>;\n readonly isLoading: true;\n}\n\nexport interface LoadingMore<\n Item,\n E = never,\n> extends PaginatedQueryResult.Proto<Item, E> {\n readonly _tag: \"LoadingMore\";\n readonly results: ReadonlyArray<Item>;\n readonly isLoading: true;\n}\n\nexport interface CanLoadMore<\n Item,\n E = never,\n> extends PaginatedQueryResult.Proto<Item, E> {\n readonly _tag: \"CanLoadMore\";\n readonly results: ReadonlyArray<Item>;\n readonly isLoading: false;\n readonly loadMore: (numItems: number) => void;\n}\n\nexport interface Exhausted<Item, E = never> extends PaginatedQueryResult.Proto<\n Item,\n E\n> {\n readonly _tag: \"Exhausted\";\n readonly results: ReadonlyArray<Item>;\n readonly isLoading: false;\n}\n\nexport interface Failure<Item, E = never> extends PaginatedQueryResult.Proto<\n Item,\n E\n> {\n readonly _tag: \"Failure\";\n readonly error: E;\n /** The pages loaded before the failure. */\n readonly results: ReadonlyArray<Item>;\n}\n\nexport const isPaginatedQueryResult = (\n u: unknown,\n): u is Variants<unknown, unknown> => Predicate.hasProperty(u, TypeId);\n\nconst PaginatedQueryResultProto = {\n [TypeId]: {\n E: identity,\n Item: identity,\n },\n pipe(this: Variants<any, any>, ...args: ReadonlyArray<unknown>) {\n return Pipeable.pipeArguments(\n this,\n args as unknown as Parameters<typeof Pipeable.pipeArguments>[1],\n );\n },\n /**\n * `CanLoadMore`'s `loadMore` is excluded from equality and hashing, like\n * function fields generally: two results that render identically are equal\n * even though their callbacks differ by identity.\n */\n [Equal.symbol](this: Variants<any, any>, that: Variants<any, any>): boolean {\n if (this._tag !== that._tag) {\n return false;\n }\n return Match.value(this).pipe(\n Match.tag(\n \"LoadingFirstPage\",\n (self) => self.skipped === (that as LoadingFirstPage<any, any>).skipped,\n ),\n Match.tag(\"LoadingMore\", \"CanLoadMore\", \"Exhausted\", (self) =>\n Equal.equals(self.results, that.results),\n ),\n Match.tag(\n \"Failure\",\n (self) =>\n Equal.equals(self.error, (that as Failure<any, any>).error) &&\n Equal.equals(self.results, (that as Failure<any, any>).results),\n ),\n Match.exhaustive,\n );\n },\n [Hash.symbol](this: Variants<any, any>): number {\n const tagHash = Hash.string(this._tag);\n return Match.value(this).pipe(\n Match.tag(\"LoadingFirstPage\", (self) =>\n Hash.combine(tagHash)(Hash.hash(self.skipped)),\n ),\n Match.tag(\"LoadingMore\", \"CanLoadMore\", \"Exhausted\", (self) =>\n Hash.combine(tagHash)(Hash.hash(self.results)),\n ),\n Match.tag(\"Failure\", (self) =>\n Hash.combine(tagHash)(\n Hash.combine(Hash.hash(self.error))(Hash.hash(self.results)),\n ),\n ),\n Match.exhaustive,\n );\n },\n};\n\nconst noResults: ReadonlyArray<never> = [];\n\nexport const loadingFirstPage = <Item = never, E = never>(options: {\n skipped: boolean;\n}): LoadingFirstPage<Item, E> =>\n Object.assign(Object.create(PaginatedQueryResultProto), {\n _tag: \"LoadingFirstPage\" as const,\n skipped: options.skipped,\n results: noResults,\n isLoading: true as const,\n });\n\nexport const loadingMore = <Item, E = never>(options: {\n results: ReadonlyArray<Item>;\n}): LoadingMore<Item, E> =>\n Object.assign(Object.create(PaginatedQueryResultProto), {\n _tag: \"LoadingMore\" as const,\n results: options.results,\n isLoading: true as const,\n });\n\nexport const canLoadMore = <Item, E = never>(options: {\n results: ReadonlyArray<Item>;\n loadMore: (numItems: number) => void;\n}): CanLoadMore<Item, E> =>\n Object.assign(Object.create(PaginatedQueryResultProto), {\n _tag: \"CanLoadMore\" as const,\n results: options.results,\n isLoading: false as const,\n loadMore: options.loadMore,\n });\n\nexport const exhausted = <Item, E = never>(options: {\n results: ReadonlyArray<Item>;\n}): Exhausted<Item, E> =>\n Object.assign(Object.create(PaginatedQueryResultProto), {\n _tag: \"Exhausted\" as const,\n results: options.results,\n isLoading: false as const,\n });\n\nexport const failure = <E, Item = never>(options: {\n error: E;\n results: ReadonlyArray<Item>;\n}): Failure<Item, E> =>\n Object.assign(Object.create(PaginatedQueryResultProto), {\n _tag: \"Failure\" as const,\n error: options.error,\n results: options.results,\n });\n\nexport const isLoadingFirstPage = <Item, E>(\n result: Variants<Item, E>,\n): result is LoadingFirstPage<Item, E> => result._tag === \"LoadingFirstPage\";\n\nexport const isLoadingMore = <Item, E>(\n result: Variants<Item, E>,\n): result is LoadingMore<Item, E> => result._tag === \"LoadingMore\";\n\nexport const isCanLoadMore = <Item, E>(\n result: Variants<Item, E>,\n): result is CanLoadMore<Item, E> => result._tag === \"CanLoadMore\";\n\nexport const isExhausted = <Item, E>(\n result: Variants<Item, E>,\n): result is Exhausted<Item, E> => result._tag === \"Exhausted\";\n\nexport const isFailure = <Item, E>(\n result: Variants<Item, E>,\n): result is Failure<Item, E> => result._tag === \"Failure\";\n\nexport const isLoading = <Item, E>(\n result: Variants<Item, E>,\n): result is LoadingFirstPage<Item, E> | LoadingMore<Item, E> =>\n result._tag === \"LoadingFirstPage\" || result._tag === \"LoadingMore\";\n\ntype MatchOptions<Item, E, V, W, X, Y, Z> = {\n readonly onLoadingFirstPage: (skipped: boolean) => V;\n readonly onLoadingMore: (results: ReadonlyArray<Item>) => W;\n readonly onCanLoadMore: (\n results: ReadonlyArray<Item>,\n loadMore: (numItems: number) => void,\n ) => X;\n readonly onExhausted: (results: ReadonlyArray<Item>) => Y;\n} & ([E] extends [never]\n ? {}\n : {\n readonly onFailure: (error: E, results: ReadonlyArray<Item>) => Z;\n });\n\ntype MatchReturns<E, V, W, X, Y, Z> = [E] extends [never]\n ? V | W | X | Y\n : V | W | X | Y | Z;\n\n/**\n * Matches a {@link PaginatedQueryResult} to the appropriate handler based on\n * its tag. If the provided result cannot fail (i.e. `E` is `never`),\n * `onFailure` is not required.\n */\nexport const match: {\n <Item, E, V, W, X, Y, Z = never>(\n options: MatchOptions<Item, E, V, W, X, Y, Z>,\n ): (self: Variants<Item, E>) => MatchReturns<E, V, W, X, Y, Z>;\n <Item, E, V, W, X, Y, Z = never>(\n self: Variants<Item, E>,\n options: MatchOptions<Item, E, V, W, X, Y, Z>,\n ): MatchReturns<E, V, W, X, Y, Z>;\n} = Function.dual(\n 2,\n <Item, E, V, W, X, Y, Z = never>(\n self: Variants<Item, E>,\n options: MatchOptions<Item, E, V, W, X, Y, Z>,\n ): MatchReturns<E, V, W, X, Y, Z> =>\n Match.value(self).pipe(\n Match.tag(\"LoadingFirstPage\", (loadingFirstPage_) =>\n options.onLoadingFirstPage(loadingFirstPage_.skipped),\n ),\n Match.tag(\"LoadingMore\", (loadingMore_) =>\n options.onLoadingMore(loadingMore_.results),\n ),\n Match.tag(\"CanLoadMore\", (canLoadMore_) =>\n options.onCanLoadMore(canLoadMore_.results, canLoadMore_.loadMore),\n ),\n Match.tag(\"Exhausted\", (exhausted_) =>\n options.onExhausted(exhausted_.results),\n ),\n Match.tag(\"Failure\", (failure_) => {\n if (Predicate.hasProperty(options, \"onFailure\")) {\n return options.onFailure(failure_.error, failure_.results);\n }\n throw new Error(\n \"`onFailure` is required when error schema is provided\",\n );\n }),\n Match.exhaustive,\n ) as MatchReturns<E, V, W, X, Y, Z>,\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAQA,MAAM,SAAS;AAqHf,MAAa,0BACX,MACoC,UAAU,YAAY,GAAG,MAAM;AAErE,MAAM,4BAA4B;EAC/B,SAAS;EACR,GAAG;EACH,MAAM;CACR;CACA,KAA+B,GAAG,MAA8B;EAC9D,OAAO,SAAS,cACd,MACA,IACF;CACF;;;;;;CAMA,CAAC,MAAM,QAAkC,MAAmC;EAC1E,IAAI,KAAK,SAAS,KAAK,MACrB,OAAO;EAET,OAAO,MAAM,MAAM,IAAI,CAAC,CAAC,KACvB,MAAM,IACJ,qBACC,SAAS,KAAK,YAAa,KAAoC,OAClE,GACA,MAAM,IAAI,eAAe,eAAe,cAAc,SACpD,MAAM,OAAO,KAAK,SAAS,KAAK,OAAO,CACzC,GACA,MAAM,IACJ,YACC,SACC,MAAM,OAAO,KAAK,OAAQ,KAA2B,KAAK,KAC1D,MAAM,OAAO,KAAK,SAAU,KAA2B,OAAO,CAClE,GACA,MAAM,UACR;CACF;CACA,CAAC,KAAK,UAA0C;EAC9C,MAAM,UAAU,KAAK,OAAO,KAAK,IAAI;EACrC,OAAO,MAAM,MAAM,IAAI,CAAC,CAAC,KACvB,MAAM,IAAI,qBAAqB,SAC7B,KAAK,QAAQ,OAAO,CAAC,CAAC,KAAK,KAAK,KAAK,OAAO,CAAC,CAC/C,GACA,MAAM,IAAI,eAAe,eAAe,cAAc,SACpD,KAAK,QAAQ,OAAO,CAAC,CAAC,KAAK,KAAK,KAAK,OAAO,CAAC,CAC/C,GACA,MAAM,IAAI,YAAY,SACpB,KAAK,QAAQ,OAAO,CAAC,CACnB,KAAK,QAAQ,KAAK,KAAK,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,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aAAa,QAAQ,CACnE,GACA,MAAM,IAAI,cAAc,eACtB,QAAQ,YAAY,WAAW,OAAO,CACxC,GACA,MAAM,IAAI,YAAY,aAAa;CACjC,IAAI,UAAU,YAAY,SAAS,WAAW,GAC5C,OAAO,QAAQ,UAAU,SAAS,OAAO,SAAS,OAAO;CAE3D,MAAM,IAAI,MACR,uDACF;AACF,CAAC,GACD,MAAM,UACR,CACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryResult.d.ts","sourceRoot":"","sources":["../src/QueryResult.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"QueryResult.d.ts","sourceRoot":"","sources":["../src/QueryResult.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAG5C,QAAA,MAAM,MAAM,+BAA+B,CAAC;AAC5C,KAAK,MAAM,GAAG,OAAO,MAAM,CAAC;AAE5B;;;;;GAKG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAChC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,GACb,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,GACb,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAElB,MAAM,CAAC,OAAO,WAAW,WAAW,CAAC;IAEnC,UAAiB,KAAK,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,QAAQ,CAAC,QAAQ;QACpD,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE;YACjB,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC;YAC5B,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC;SAC7B,CAAC;KACH;IAGD,KAAY,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG,KAAK,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AG,KAAK,EACpB,OAAO,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GACnC,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACzD,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,KAAK,EACpB,IAAI,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EACvB,OAAO,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GACnC,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;CAoB7B,CAAC"}
|
package/dist/QueryResult.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
import * as Match from "effect/Match";
|
|
2
3
|
import * as Function from "effect/Function";
|
|
3
4
|
import { identity } from "effect/Function";
|
|
4
5
|
import * as Equal from "effect/Equal";
|
|
5
6
|
import * as Hash from "effect/Hash";
|
|
6
7
|
import * as Pipeable from "effect/Pipeable";
|
|
7
8
|
import * as Predicate from "effect/Predicate";
|
|
8
|
-
|
|
9
9
|
//#region src/QueryResult.ts
|
|
10
10
|
var QueryResult_exports = /* @__PURE__ */ __exportAll({
|
|
11
11
|
fail: () => fail,
|
|
@@ -29,19 +29,11 @@ const QueryResultProto = {
|
|
|
29
29
|
},
|
|
30
30
|
[Equal.symbol](that) {
|
|
31
31
|
if (this._tag !== that._tag) return false;
|
|
32
|
-
|
|
33
|
-
case "Loading": return this.skipped === that.skipped;
|
|
34
|
-
case "Success": return Equal.equals(this.value, that.value);
|
|
35
|
-
case "Failure": return Equal.equals(this.error, that.error);
|
|
36
|
-
}
|
|
32
|
+
return Match.value(this).pipe(Match.tag("Loading", (self) => self.skipped === that.skipped), Match.tag("Success", (self) => Equal.equals(self.value, that.value)), Match.tag("Failure", (self) => Equal.equals(self.error, that.error)), Match.exhaustive);
|
|
37
33
|
},
|
|
38
34
|
[Hash.symbol]() {
|
|
39
35
|
const tagHash = Hash.string(this._tag);
|
|
40
|
-
|
|
41
|
-
case "Loading": return Hash.combine(tagHash)(Hash.hash(this.skipped));
|
|
42
|
-
case "Success": return Hash.combine(tagHash)(Hash.hash(this.value));
|
|
43
|
-
case "Failure": return Hash.combine(tagHash)(Hash.hash(this.error));
|
|
44
|
-
}
|
|
36
|
+
return Match.value(this).pipe(Match.tag("Loading", (self) => Hash.combine(tagHash)(Hash.hash(self.skipped))), Match.tag("Success", (self) => Hash.combine(tagHash)(Hash.hash(self.value))), Match.tag("Failure", (self) => Hash.combine(tagHash)(Hash.hash(self.error))), Match.exhaustive);
|
|
45
37
|
}
|
|
46
38
|
};
|
|
47
39
|
const load = (skipped) => Object.assign(Object.create(QueryResultProto), {
|
|
@@ -72,16 +64,11 @@ const isFailure = (queryResult) => queryResult._tag === "Failure";
|
|
|
72
64
|
* onFailure: (error) => <p>Error: {error.message}</p>,
|
|
73
65
|
* });
|
|
74
66
|
*/
|
|
75
|
-
const match = Function.dual(2, (self, options) => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
case "Failure":
|
|
80
|
-
if (Predicate.hasProperty(options, "onFailure")) return options.onFailure(self.error);
|
|
81
|
-
throw new Error("`onFailure` is required when error schema is provided");
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
|
|
67
|
+
const match = Function.dual(2, (self, options) => Match.value(self).pipe(Match.tag("Loading", (loading) => options.onLoading(loading.skipped)), Match.tag("Success", (success) => options.onSuccess(success.value)), Match.tag("Failure", (failure) => {
|
|
68
|
+
if (Predicate.hasProperty(options, "onFailure")) return options.onFailure(failure.error);
|
|
69
|
+
throw new Error("`onFailure` is required when error schema is provided");
|
|
70
|
+
}), Match.exhaustive));
|
|
85
71
|
//#endregion
|
|
86
|
-
export { QueryResult_exports, fail, load, succeed };
|
|
72
|
+
export { QueryResult_exports, fail, isFailure, isLoading, isQueryResult, isSuccess, load, match, succeed };
|
|
73
|
+
|
|
87
74
|
//# sourceMappingURL=QueryResult.js.map
|
package/dist/QueryResult.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryResult.js","names":[],"sources":["../src/QueryResult.ts"],"sourcesContent":["import { identity } from \"effect/Function\";\nimport * as Equal from \"effect/Equal\";\nimport * as Function from \"effect/Function\";\nimport * as Hash from \"effect/Hash\";\nimport * as Pipeable from \"effect/Pipeable\";\nimport * as Predicate from \"effect/Predicate\";\n\nconst TypeId = \"@confect/react/QueryResult\";\ntype TypeId = typeof TypeId;\n\n/**\n * A `QueryResult` represents the result of a Confect query.\n *\n * @typeParam A - The type of the decoded `returns` value in the `Success` variant.\n * @typeParam E - The type of the decoded typed error in the `Failure` variant.\n */\nexport type QueryResult<A, E = never> =\n | Loading<A, E>\n | Success<A, E>\n | Failure<A, E>;\n\nexport declare namespace QueryResult {\n export interface Proto<A, E> extends Pipeable.Pipeable {\n readonly [TypeId]: {\n readonly E: (_: never) => E;\n readonly A: (_: never) => A;\n };\n }\n\n //
|
|
1
|
+
{"version":3,"file":"QueryResult.js","names":[],"sources":["../src/QueryResult.ts"],"sourcesContent":["import { identity } from \"effect/Function\";\nimport * as Equal from \"effect/Equal\";\nimport * as Function from \"effect/Function\";\nimport * as Hash from \"effect/Hash\";\nimport * as Match from \"effect/Match\";\nimport * as Pipeable from \"effect/Pipeable\";\nimport * as Predicate from \"effect/Predicate\";\n\nconst TypeId = \"@confect/react/QueryResult\";\ntype TypeId = typeof TypeId;\n\n/**\n * A `QueryResult` represents the result of a Confect query.\n *\n * @typeParam A - The type of the decoded `returns` value in the `Success` variant.\n * @typeParam E - The type of the decoded typed error in the `Failure` variant.\n */\nexport type QueryResult<A, E = never> =\n | Loading<A, E>\n | Success<A, E>\n | Failure<A, E>;\n\nexport declare namespace QueryResult {\n // eslint-disable-next-line import/namespace -- oxlint's namespace resolution misses type-only exports, and `Pipeable` is an interface\n export interface Proto<A, E> extends Pipeable.Pipeable {\n readonly [TypeId]: {\n readonly E: (_: never) => E;\n readonly A: (_: never) => A;\n };\n }\n\n // eslint-disable-next-line @typescript-eslint/no-shadow\n export type Success<R> = R extends QueryResult<infer A, infer _E> ? A : never;\n\n // eslint-disable-next-line @typescript-eslint/no-shadow\n export type Failure<R> = R extends QueryResult<infer _A, infer E> ? E : never;\n}\n\nexport interface Loading<A, E = never> extends QueryResult.Proto<A, E> {\n readonly _tag: \"Loading\";\n readonly skipped: boolean;\n}\n\nexport interface Success<A, E = never> extends QueryResult.Proto<A, E> {\n readonly _tag: \"Success\";\n readonly value: A;\n}\n\nexport interface Failure<A, E = never> extends QueryResult.Proto<A, E> {\n readonly _tag: \"Failure\";\n readonly error: E;\n}\n\nexport const isQueryResult = (u: unknown): u is QueryResult<unknown, unknown> =>\n Predicate.hasProperty(u, TypeId);\n\nconst QueryResultProto = {\n [TypeId]: {\n E: identity,\n A: identity,\n },\n pipe(this: QueryResult<any, any>, ...args: ReadonlyArray<unknown>) {\n return Pipeable.pipeArguments(\n this,\n args as unknown as Parameters<typeof Pipeable.pipeArguments>[1],\n );\n },\n [Equal.symbol](\n this: QueryResult<any, any>,\n that: QueryResult<any, any>,\n ): boolean {\n if (this._tag !== that._tag) {\n return false;\n }\n return Match.value(this).pipe(\n Match.tag(\n \"Loading\",\n (self) => self.skipped === (that as Loading<any, any>).skipped,\n ),\n Match.tag(\"Success\", (self) =>\n Equal.equals(self.value, (that as Success<any, any>).value),\n ),\n Match.tag(\"Failure\", (self) =>\n Equal.equals(self.error, (that as Failure<any, any>).error),\n ),\n Match.exhaustive,\n );\n },\n [Hash.symbol](this: QueryResult<any, any>): number {\n const tagHash = Hash.string(this._tag);\n return Match.value(this).pipe(\n Match.tag(\"Loading\", (self) =>\n Hash.combine(tagHash)(Hash.hash(self.skipped)),\n ),\n Match.tag(\"Success\", (self) =>\n Hash.combine(tagHash)(Hash.hash(self.value)),\n ),\n Match.tag(\"Failure\", (self) =>\n Hash.combine(tagHash)(Hash.hash(self.error)),\n ),\n Match.exhaustive,\n );\n },\n};\n\nexport const load = <A = never, E = never>(skipped: boolean): Loading<A, E> =>\n Object.assign(Object.create(QueryResultProto), {\n _tag: \"Loading\" as const,\n skipped,\n });\n\nexport const succeed = <A, E = never>(value: A): Success<A, E> =>\n Object.assign(Object.create(QueryResultProto), {\n _tag: \"Success\" as const,\n value,\n });\n\nexport const fail = <E, A = never>(error: E): Failure<A, E> =>\n Object.assign(Object.create(QueryResultProto), {\n _tag: \"Failure\" as const,\n error,\n });\n\nexport const isLoading = <A, E>(\n queryResult: QueryResult<A, E>,\n): queryResult is Loading<A, E> => queryResult._tag === \"Loading\";\n\nexport const isSuccess = <A, E>(\n queryResult: QueryResult<A, E>,\n): queryResult is Success<A, E> => queryResult._tag === \"Success\";\n\nexport const isFailure = <A, E>(\n queryResult: QueryResult<A, E>,\n): queryResult is Failure<A, E> => queryResult._tag === \"Failure\";\n\ntype MatchOptions<A, E, X, Y, Z> = {\n readonly onLoading: (skipped: boolean) => X;\n readonly onSuccess: (value: A) => Y;\n} & ([E] extends [never] ? {} : { readonly onFailure: (error: E) => Z });\n\ntype MatchReturns<E, X, Y, Z> = [E] extends [never] ? X | Y : X | Y | Z;\n\n/**\n * Matches a {@link QueryResult} to the appropriate handler based on its tag. If\n * the provided `QueryResult` cannot fail (i.e. `E` is `never`), `onFailure` is\n * not required.\n *\n * @example\n * ```tsx\n * const result = QueryResult.match(queryResult, {\n * onLoading: (skipped) => skipped ? null : <p>Loading…</p>,\n * onSuccess: (value) => <p>{value.text}</p>,\n * onFailure: (error) => <p>Error: {error.message}</p>,\n * });\n */\nexport const match: {\n <A, E, X, Y, Z = never>(\n options: MatchOptions<A, E, X, Y, Z>,\n ): (self: QueryResult<A, E>) => MatchReturns<E, X, Y, Z>;\n <A, E, X, Y, Z = never>(\n self: QueryResult<A, E>,\n options: MatchOptions<A, E, X, Y, Z>,\n ): MatchReturns<E, X, Y, Z>;\n} = Function.dual(\n 2,\n <A, E, X, Y, Z = never>(\n self: QueryResult<A, E>,\n options: MatchOptions<A, E, X, Y, Z>,\n ): MatchReturns<E, X, Y, Z> =>\n Match.value(self).pipe(\n Match.tag(\"Loading\", (loading) => options.onLoading(loading.skipped)),\n Match.tag(\"Success\", (success) => options.onSuccess(success.value)),\n Match.tag(\"Failure\", (failure) => {\n if (Predicate.hasProperty(options, \"onFailure\")) {\n return options.onFailure(failure.error);\n }\n throw new Error(\n \"`onFailure` is required when error schema is provided\",\n );\n }),\n Match.exhaustive,\n ) as MatchReturns<E, X, Y, Z>,\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAQA,MAAM,SAAS;AA6Cf,MAAa,iBAAiB,MAC5B,UAAU,YAAY,GAAG,MAAM;AAEjC,MAAM,mBAAmB;EACtB,SAAS;EACR,GAAG;EACH,GAAG;CACL;CACA,KAAkC,GAAG,MAA8B;EACjE,OAAO,SAAS,cACd,MACA,IACF;CACF;CACA,CAAC,MAAM,QAEL,MACS;EACT,IAAI,KAAK,SAAS,KAAK,MACrB,OAAO;EAET,OAAO,MAAM,MAAM,IAAI,CAAC,CAAC,KACvB,MAAM,IACJ,YACC,SAAS,KAAK,YAAa,KAA2B,OACzD,GACA,MAAM,IAAI,YAAY,SACpB,MAAM,OAAO,KAAK,OAAQ,KAA2B,KAAK,CAC5D,GACA,MAAM,IAAI,YAAY,SACpB,MAAM,OAAO,KAAK,OAAQ,KAA2B,KAAK,CAC5D,GACA,MAAM,UACR;CACF;CACA,CAAC,KAAK,UAA6C;EACjD,MAAM,UAAU,KAAK,OAAO,KAAK,IAAI;EACrC,OAAO,MAAM,MAAM,IAAI,CAAC,CAAC,KACvB,MAAM,IAAI,YAAY,SACpB,KAAK,QAAQ,OAAO,CAAC,CAAC,KAAK,KAAK,KAAK,OAAO,CAAC,CAC/C,GACA,MAAM,IAAI,YAAY,SACpB,KAAK,QAAQ,OAAO,CAAC,CAAC,KAAK,KAAK,KAAK,KAAK,CAAC,CAC7C,GACA,MAAM,IAAI,YAAY,SACpB,KAAK,QAAQ,OAAO,CAAC,CAAC,KAAK,KAAK,KAAK,KAAK,CAAC,CAC7C,GACA,MAAM,UACR;CACF;AACF;AAEA,MAAa,QAA8B,YACzC,OAAO,OAAO,OAAO,OAAO,gBAAgB,GAAG;CAC7C,MAAM;CACN;AACF,CAAC;AAEH,MAAa,WAAyB,UACpC,OAAO,OAAO,OAAO,OAAO,gBAAgB,GAAG;CAC7C,MAAM;CACN;AACF,CAAC;AAEH,MAAa,QAAsB,UACjC,OAAO,OAAO,OAAO,OAAO,gBAAgB,GAAG;CAC7C,MAAM;CACN;AACF,CAAC;AAEH,MAAa,aACX,gBACiC,YAAY,SAAS;AAExD,MAAa,aACX,gBACiC,YAAY,SAAS;AAExD,MAAa,aACX,gBACiC,YAAY,SAAS;;;;;;;;;;;;;;AAsBxD,MAAa,QAQT,SAAS,KACX,IAEE,MACA,YAEA,MAAM,MAAM,IAAI,CAAC,CAAC,KAChB,MAAM,IAAI,YAAY,YAAY,QAAQ,UAAU,QAAQ,OAAO,CAAC,GACpE,MAAM,IAAI,YAAY,YAAY,QAAQ,UAAU,QAAQ,KAAK,CAAC,GAClE,MAAM,IAAI,YAAY,YAAY;CAChC,IAAI,UAAU,YAAY,SAAS,WAAW,GAC5C,OAAO,QAAQ,UAAU,QAAQ,KAAK;CAExC,MAAM,IAAI,MACR,uDACF;AACF,CAAC,GACD,MAAM,UACR,CACJ"}
|
|
@@ -2,17 +2,12 @@
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __exportAll = (all, no_symbols) => {
|
|
4
4
|
let target = {};
|
|
5
|
-
for (var name in all) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
if (!no_symbols) {
|
|
12
|
-
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
13
|
-
}
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
14
10
|
return target;
|
|
15
11
|
};
|
|
16
|
-
|
|
17
12
|
//#endregion
|
|
18
|
-
export { __exportAll };
|
|
13
|
+
export { __exportAll };
|