@confect/foldkit 10.0.0-next.19

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.
@@ -0,0 +1,227 @@
1
+ import * as PaginationError from "@confect/core/PaginationError";
2
+ import * as Ref from "@confect/core/Ref";
3
+ import * as Data from "effect/Data";
4
+ import * as Option from "effect/Option";
5
+ import * as Result from "effect/Result";
6
+ import * as Schema from "effect/Schema";
7
+ import * as Client from "./Client";
8
+ /** Identifies the cursor range fetched for one page. */
9
+ export interface PageDescriptor {
10
+ readonly cursor: string | null;
11
+ readonly endCursor: Option.Option<string>;
12
+ }
13
+ export declare const PageDescriptor: Schema.Struct<{
14
+ readonly cursor: Schema.Union<readonly [Schema.String, Schema.Null]>;
15
+ readonly endCursor: Schema.Option<Schema.String>;
16
+ }>;
17
+ /** Options that remain fixed for one pagination session. */
18
+ export interface Options {
19
+ readonly initialNumItems: number;
20
+ readonly maximumRowsRead?: number;
21
+ readonly maximumBytesRead?: number;
22
+ }
23
+ export declare const Options: Schema.Struct<{
24
+ readonly initialNumItems: Schema.Int;
25
+ readonly maximumRowsRead: Schema.optionalKey<Schema.Int>;
26
+ readonly maximumBytesRead: Schema.optionalKey<Schema.Int>;
27
+ }>;
28
+ /** Why the machine is fetching its current target. */
29
+ export type Direction = "Initial" | "Next" | "Previous" | "First" | "Split" | "Reset";
30
+ /** A complete page that can remain on screen while another page is fetched. */
31
+ export interface Page<Item_> {
32
+ readonly descriptor: PageDescriptor;
33
+ readonly number: number;
34
+ readonly items: ReadonlyArray<Item_>;
35
+ readonly continueCursor: string;
36
+ readonly isDone: boolean;
37
+ }
38
+ export type Loading = Data.TaggedEnum<{
39
+ Loading: {
40
+ readonly direction: Direction;
41
+ };
42
+ }>;
43
+ export type Refreshing<Item_> = Data.TaggedEnum<{
44
+ Refreshing: {
45
+ readonly data: Page<Item_>;
46
+ readonly direction: Direction;
47
+ };
48
+ }>;
49
+ export type Success<Item_> = Data.TaggedEnum<{
50
+ Success: {
51
+ readonly data: Page<Item_>;
52
+ };
53
+ }>;
54
+ export type Failure<Error_> = Data.TaggedEnum<{
55
+ Failure: {
56
+ readonly error: Error_;
57
+ };
58
+ }>;
59
+ export type Stale<Item_, Error_> = Data.TaggedEnum<{
60
+ Stale: {
61
+ readonly data: Page<Item_>;
62
+ readonly error: Error_;
63
+ };
64
+ }>;
65
+ export type Phase<Item_, Error_> = Loading | Refreshing<Item_> | Success<Item_> | Failure<Error_> | Stale<Item_, Error_>;
66
+ /** A closed machine that retains its generation for stale-result rejection. */
67
+ export type Idle = Data.TaggedEnum<{
68
+ Idle: {
69
+ readonly generation: number;
70
+ };
71
+ }>;
72
+ /** A live cursor-pagination session. */
73
+ export type Active<Item_, UserArgs_, Error_> = Data.TaggedEnum<{
74
+ Active: {
75
+ readonly generation: number;
76
+ readonly args: UserArgs_;
77
+ readonly options: Options;
78
+ readonly paginationId: Option.Option<number>;
79
+ readonly requestId: number;
80
+ readonly current: PageDescriptor;
81
+ readonly prevStack: ReadonlyArray<PageDescriptor>;
82
+ readonly phase: Phase<Item_, Error_>;
83
+ };
84
+ }>;
85
+ /** A schema-backed cursor-pagination machine. */
86
+ export type State<Item_, UserArgs_, Error_> = Idle | Active<Item_, UserArgs_, Error_>;
87
+ /** The logical request from which a subscription allocates a session id. */
88
+ export interface SubscriptionRequest<UserArgs_> {
89
+ readonly generation: number;
90
+ readonly args: UserArgs_;
91
+ readonly options: Options;
92
+ readonly paginationId: Option.Option<number>;
93
+ readonly requestId: number;
94
+ readonly descriptor: PageDescriptor;
95
+ }
96
+ /** The complete identity and arguments of a subscribed page request. */
97
+ export interface Request<UserArgs_> {
98
+ readonly generation: number;
99
+ readonly args: UserArgs_;
100
+ readonly options: Options;
101
+ readonly paginationId: number;
102
+ readonly requestId: number;
103
+ readonly descriptor: PageDescriptor;
104
+ }
105
+ /** The successful payload returned by a Convex paginated query. */
106
+ export interface PageResult<Item_> {
107
+ readonly page: ReadonlyArray<Item_>;
108
+ readonly isDone: boolean;
109
+ readonly continueCursor: string;
110
+ readonly splitCursor?: string | null;
111
+ readonly pageStatus?: "SplitRecommended" | "SplitRequired" | null;
112
+ }
113
+ /**
114
+ * One correlated subscription outcome. Both success and failure travel
115
+ * through this value so `settle` can mirror `AsyncData.settle`.
116
+ */
117
+ export interface Settlement<Item_, UserArgs_, Error_> {
118
+ readonly request: Request<UserArgs_>;
119
+ readonly result: Result.Result<PageResult<Item_>, Error_>;
120
+ }
121
+ export type Item<Query extends Ref.AnyConfectPublicPaginatedQuery> = Ref.Returns<Query>["page"][number];
122
+ export type UserArgs<Query extends Ref.AnyConfectPublicPaginatedQuery> = Omit<Ref.Args<Query>, "paginationOpts">;
123
+ type TaggedFunctionError<Error_> = Data.TaggedEnum<{
124
+ FunctionError: {
125
+ readonly error: Error_;
126
+ };
127
+ }>;
128
+ /** Constructs a declared function or middleware failure envelope. */
129
+ export declare const FunctionError: <A>(args: {
130
+ readonly error: A;
131
+ }) => {
132
+ readonly _tag: "FunctionError";
133
+ readonly error: A;
134
+ };
135
+ /** A declared function or middleware failure, kept distinct from client errors. */
136
+ export type FunctionError<Query extends Ref.AnyConfectPublicPaginatedQuery> = [
137
+ Ref.Error<Query>
138
+ ] extends [never] ? never : TaggedFunctionError<Ref.Error<Query>>;
139
+ /** Every failure a paginated query subscription can settle with. */
140
+ export type Error<Query extends Ref.AnyConfectPublicPaginatedQuery> = FunctionError<Query> | PaginationError.InvalidCursor | Client.WebSocketClientError | Schema.SchemaError;
141
+ export { InvalidCursor } from "@confect/core/PaginationError";
142
+ type MachineState<Query extends Ref.AnyConfectPublicPaginatedQuery> = State<Item<Query>, UserArgs<Query>, Error<Query>>;
143
+ type MachineActive<Query extends Ref.AnyConfectPublicPaginatedQuery> = Active<Item<Query>, UserArgs<Query>, Error<Query>>;
144
+ /** The schema-and-constructor bundle returned by `make`. */
145
+ export interface PaginatedQuery<Query extends Ref.AnyConfectPublicPaginatedQuery> {
146
+ readonly ref: Query;
147
+ readonly schema: Schema.Codec<MachineState<Query>, unknown>;
148
+ readonly idle: Idle;
149
+ readonly subscriptionRequestSchema: Schema.Codec<SubscriptionRequest<UserArgs<Query>>, unknown>;
150
+ readonly requestSchema: Schema.Codec<Request<UserArgs<Query>>, unknown>;
151
+ readonly settlement: Schema.Codec<Settlement<Item<Query>, UserArgs<Query>, Error<Query>>, unknown>;
152
+ readonly init: keyof UserArgs<Query> extends never ? (state: Idle, options: Options) => MachineActive<Query> : (state: Idle, args: UserArgs<Query>, options: Options) => MachineActive<Query>;
153
+ readonly reinitialize: keyof UserArgs<Query> extends never ? (state: MachineActive<Query>, options?: Options) => MachineActive<Query> : (state: MachineActive<Query>, args: UserArgs<Query>, options?: Options) => MachineActive<Query>;
154
+ }
155
+ export type Any = PaginatedQuery<Ref.AnyConfectPublicPaginatedQuery>;
156
+ /** Builds a page machine from a paginated ref. */
157
+ export declare const make: <Query extends Ref.AnyConfectPublicPaginatedQuery>(ref: Query) => PaginatedQuery<Query>;
158
+ /** Returns the logical request currently driving the subscription. */
159
+ export declare const getSubscriptionRequest: <Item_, UserArgs_, Error_>(state: Active<Item_, UserArgs_, Error_>) => SubscriptionRequest<UserArgs_>;
160
+ /** Attaches the client-allocated pagination id to a logical request. */
161
+ export declare const allocateRequest: <UserArgs_>(request: SubscriptionRequest<UserArgs_>, paginationId: number) => Request<UserArgs_>;
162
+ /** Close the subscription while retaining its generation tombstone. */
163
+ export declare const close: <Item_, UserArgs_, Error_>(state: Active<Item_, UserArgs_, Error_>) => Idle;
164
+ /** Start a fresh pagination session at page one while retaining visible data. */
165
+ export declare const reset: <Item_, UserArgs_, Error_>(state: Active<Item_, UserArgs_, Error_>) => Active<Item_, UserArgs_, Error_>;
166
+ /** Navigate to the next page, retaining the current page while it loads. */
167
+ export declare const next: <Item_, UserArgs_, Error_>(state: Active<Item_, UserArgs_, Error_>) => Option.Option<Active<Item_, UserArgs_, Error_>>;
168
+ /** Navigate to the previous page, retaining the current page while it loads. */
169
+ export declare const prev: <Item_, UserArgs_, Error_>(state: Active<Item_, UserArgs_, Error_>) => Option.Option<Active<Item_, UserArgs_, Error_>>;
170
+ /** Navigate to page one without invalidating the current pagination session. */
171
+ export declare const first: <Item_, UserArgs_, Error_>(state: Active<Item_, UserArgs_, Error_>) => Option.Option<Active<Item_, UserArgs_, Error_>>;
172
+ /** Whether a request still names the machine's live pagination session/page. */
173
+ export declare const isCurrentRequest: <Item_, UserArgs_, Error_>(state: State<Item_, UserArgs_, Error_>, candidate: Request<UserArgs_>) => boolean;
174
+ /**
175
+ * Fold a correlated `Result` into the machine. Like `AsyncData.settle`, a
176
+ * success becomes `Success`; a failure becomes `Stale` when a page is held,
177
+ * otherwise `Failure`. Outcomes from superseded requests and outcomes that
178
+ * arrive after the subscription closed are ignored.
179
+ */
180
+ export declare const settle: {
181
+ <Item_, UserArgs_, Error_>(settlement: Settlement<Item_, UserArgs_, Error_>): (state: State<Item_, UserArgs_, Error_>) => State<Item_, UserArgs_, Error_>;
182
+ <Item_, UserArgs_, Error_>(state: State<Item_, UserArgs_, Error_>, settlement: Settlement<Item_, UserArgs_, Error_>): State<Item_, UserArgs_, Error_>;
183
+ };
184
+ /** The complete page currently available to render. */
185
+ export declare const getPage: <Item_, UserArgs_, Error_>(state: State<Item_, UserArgs_, Error_>) => Option.Option<Page<Item_>>;
186
+ /** The items currently available to render. */
187
+ export declare const getItems: <Item_, UserArgs_, Error_>(state: State<Item_, UserArgs_, Error_>) => Option.Option<ReadonlyArray<Item_>>;
188
+ /** The error from the most recent failed request, if any. */
189
+ export declare const getError: <Item_, UserArgs_, Error_>(state: State<Item_, UserArgs_, Error_>) => Option.Option<Error_>;
190
+ /** The 1-indexed page number currently targeted by the subscription. */
191
+ export declare const targetPageNumber: <Item_, UserArgs_, Error_>(state: Active<Item_, UserArgs_, Error_>) => number;
192
+ export declare const hasPage: <Item_, UserArgs_, Error_>(state: State<Item_, UserArgs_, Error_>) => boolean;
193
+ export declare const hasError: <Item_, UserArgs_, Error_>(state: State<Item_, UserArgs_, Error_>) => boolean;
194
+ export declare const isFirst: <Item_, UserArgs_, Error_>(state: State<Item_, UserArgs_, Error_>) => boolean;
195
+ export declare const isLast: <Item_, UserArgs_, Error_>(state: State<Item_, UserArgs_, Error_>) => boolean;
196
+ type WithPhase<State_, Phase_> = Omit<State_, "phase"> & {
197
+ readonly phase: Phase_;
198
+ };
199
+ export declare const isIdle: <Item_, UserArgs_, Error_>(state: State<Item_, UserArgs_, Error_>) => state is Idle;
200
+ export declare const isLoading: <Item_, UserArgs_, Error_>(state: State<Item_, UserArgs_, Error_>) => state is WithPhase<Active<Item_, UserArgs_, Error_>, Loading>;
201
+ export declare const isRefreshing: <Item_, UserArgs_, Error_>(state: State<Item_, UserArgs_, Error_>) => state is WithPhase<Active<Item_, UserArgs_, Error_>, Refreshing<Item_>>;
202
+ export declare const isSuccess: <Item_, UserArgs_, Error_>(state: State<Item_, UserArgs_, Error_>) => state is WithPhase<Active<Item_, UserArgs_, Error_>, Success<Item_>>;
203
+ export declare const isFailure: <Item_, UserArgs_, Error_>(state: State<Item_, UserArgs_, Error_>) => state is WithPhase<Active<Item_, UserArgs_, Error_>, Failure<Error_>>;
204
+ export declare const isStale: <Item_, UserArgs_, Error_>(state: State<Item_, UserArgs_, Error_>) => state is WithPhase<Active<Item_, UserArgs_, Error_>, Stale<Item_, Error_>>;
205
+ export declare const isPending: <Item_, UserArgs_, Error_>(state: State<Item_, UserArgs_, Error_>) => boolean;
206
+ export declare const canNext: <Item_, UserArgs_, Error_>(state: State<Item_, UserArgs_, Error_>) => boolean;
207
+ export declare const canPrev: <Item_, UserArgs_, Error_>(state: State<Item_, UserArgs_, Error_>) => boolean;
208
+ /** Pattern-match exhaustively on the machine's AsyncData-style state. */
209
+ export declare const match: {
210
+ <Item_, Error_, A, B, C, D, E, F>(handlers: {
211
+ readonly onIdle: (idle: Idle) => A;
212
+ readonly onLoading: (loading: Loading) => B;
213
+ readonly onRefreshing: (refreshing: Refreshing<Item_>) => C;
214
+ readonly onFailure: (failure: Failure<Error_>) => D;
215
+ readonly onStale: (stale: Stale<Item_, Error_>) => E;
216
+ readonly onSuccess: (success: Success<Item_>) => F;
217
+ }): <UserArgs_>(state: State<Item_, UserArgs_, Error_>) => A | B | C | D | E | F;
218
+ <Item_, UserArgs_, Error_, A, B, C, D, E, F>(state: State<Item_, UserArgs_, Error_>, handlers: {
219
+ readonly onIdle: (idle: Idle) => A;
220
+ readonly onLoading: (loading: Loading) => B;
221
+ readonly onRefreshing: (refreshing: Refreshing<Item_>) => C;
222
+ readonly onFailure: (failure: Failure<Error_>) => D;
223
+ readonly onStale: (stale: Stale<Item_, Error_>) => E;
224
+ readonly onSuccess: (success: Success<Item_>) => F;
225
+ }): A | B | C | D | E | F;
226
+ };
227
+ //# sourceMappingURL=PaginatedQuery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PaginatedQuery.d.ts","sourceRoot":"","sources":["../src/PaginatedQuery.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,eAAe,MAAM,+BAA+B,CAAC;AACjE,OAAO,KAAK,GAAG,MAAM,mBAAmB,CAAC;AACzC,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AAGpC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAGxC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AAEnC,wDAAwD;AACxD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;CAC3C;AAED,eAAO,MAAM,cAAc;;;EAGzB,CAAC;AAEH,4DAA4D;AAC5D,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,e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@
1
+ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
+ import { WebSocketClientError } from "./Client.js";
3
+ import * as Option from "effect/Option";
4
+ import * as Match from "effect/Match";
5
+ import * as MiddlewareSpec from "@confect/core/MiddlewareSpec";
6
+ import * as PaginationError from "@confect/core/PaginationError";
7
+ import { InvalidCursor } from "@confect/core/PaginationError";
8
+ import * as Ref from "@confect/core/Ref";
9
+ import * as Data from "effect/Data";
10
+ import * as Function from "effect/Function";
11
+ import * as Result from "effect/Result";
12
+ import * as Schema from "effect/Schema";
13
+ import * as SchemaGetter from "effect/SchemaGetter";
14
+ import * as SchemaIssue from "effect/SchemaIssue";
15
+ //#region src/PaginatedQuery.ts
16
+ var PaginatedQuery_exports = /* @__PURE__ */ __exportAll({
17
+ FunctionError: () => FunctionError,
18
+ InvalidCursor: () => InvalidCursor,
19
+ Options: () => Options,
20
+ PageDescriptor: () => PageDescriptor,
21
+ allocateRequest: () => allocateRequest,
22
+ canNext: () => canNext,
23
+ canPrev: () => canPrev,
24
+ close: () => close,
25
+ first: () => first,
26
+ getError: () => getError,
27
+ getItems: () => getItems,
28
+ getPage: () => getPage,
29
+ getSubscriptionRequest: () => getSubscriptionRequest,
30
+ hasError: () => hasError,
31
+ hasPage: () => hasPage,
32
+ isCurrentRequest: () => isCurrentRequest,
33
+ isFailure: () => isFailure,
34
+ isFirst: () => isFirst,
35
+ isIdle: () => isIdle,
36
+ isLast: () => isLast,
37
+ isLoading: () => isLoading,
38
+ isPending: () => isPending,
39
+ isRefreshing: () => isRefreshing,
40
+ isStale: () => isStale,
41
+ isSuccess: () => isSuccess,
42
+ make: () => make,
43
+ match: () => match,
44
+ next: () => next,
45
+ prev: () => prev,
46
+ reset: () => reset,
47
+ settle: () => settle,
48
+ targetPageNumber: () => targetPageNumber
49
+ });
50
+ const PageDescriptor = Schema.Struct({
51
+ cursor: Schema.Union([Schema.String, Schema.Null]),
52
+ endCursor: Schema.Option(Schema.String)
53
+ });
54
+ const PositiveInt = Schema.Int.check(Schema.isGreaterThan(0));
55
+ const NonNegativeInt = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));
56
+ const Options = Schema.Struct({
57
+ initialNumItems: PositiveInt,
58
+ maximumRowsRead: Schema.optionalKey(PositiveInt),
59
+ maximumBytesRead: Schema.optionalKey(PositiveInt)
60
+ });
61
+ const Phase = Data.taggedEnum();
62
+ const State = Data.taggedEnum();
63
+ /** Constructs a declared function or middleware failure envelope. */
64
+ const FunctionError = Data.taggedEnum().FunctionError;
65
+ const firstDescriptor = () => ({
66
+ cursor: null,
67
+ endCursor: Option.none()
68
+ });
69
+ const decodeOptions = Schema.decodeUnknownSync(Options);
70
+ const initialState = (generation, args, options) => State.Active({
71
+ generation,
72
+ args,
73
+ options: decodeOptions(options),
74
+ paginationId: Option.none(),
75
+ requestId: 1,
76
+ current: firstDescriptor(),
77
+ prevStack: [],
78
+ phase: Phase.Loading({ direction: "Initial" })
79
+ });
80
+ const missingPaginatedProvenanceError = (ref) => new globalThis.Error(`Paginated query ref "${Ref.getConvexFunctionName(ref)}" was not built with \`FunctionSpec.publicPaginatedQuery\`. \`PaginatedQuery.make\` requires the user-args and item schemas that constructor stores.`);
81
+ const paginatedKindOrThrow = (ref) => Match.value(ref.kind).pipe(Match.tag("Paginated", (kind) => kind), Match.tag("Standard", () => {
82
+ throw missingPaginatedProvenanceError(ref);
83
+ }), Match.exhaustive);
84
+ const SchemaErrorJson = Schema.TaggedStruct("SchemaError", { message: Schema.String });
85
+ const SerializableSchemaError = Schema.instanceOf(Schema.SchemaError, { toCodecJson: () => Schema.link()(SchemaErrorJson, {
86
+ decode: SchemaGetter.transform(({ message }) => new Schema.SchemaError(new SchemaIssue.InvalidValue({ message }))),
87
+ encode: SchemaGetter.transform((error) => SchemaErrorJson.make({ message: error.message }))
88
+ }) });
89
+ /** Builds a page machine from a paginated ref. */
90
+ const make = (ref) => {
91
+ const kind = paginatedKindOrThrow(ref);
92
+ const hasUserArgs = globalThis.Object.keys(kind.userArgs.fields).length > 0;
93
+ const functionErrorSchemas = [..."error" in ref && ref.error !== void 0 ? [ref.error] : [], ...MiddlewareSpec.errorSchemas(ref.middlewareSpecs)];
94
+ const errorSchema = Schema.Union([
95
+ PaginationError.InvalidCursor,
96
+ WebSocketClientError,
97
+ SerializableSchemaError,
98
+ ...functionErrorSchemas.length === 0 ? [] : [Schema.TaggedStruct("FunctionError", { error: functionErrorSchemas.length === 1 ? functionErrorSchemas[0] : Schema.Union(functionErrorSchemas) })]
99
+ ]);
100
+ const directions = Schema.Literals([
101
+ "Initial",
102
+ "Next",
103
+ "Previous",
104
+ "First",
105
+ "Split",
106
+ "Reset"
107
+ ]);
108
+ const page = Schema.Struct({
109
+ descriptor: PageDescriptor,
110
+ number: PositiveInt,
111
+ items: kind.page,
112
+ continueCursor: Schema.String,
113
+ isDone: Schema.Boolean
114
+ });
115
+ const phase = Schema.TaggedUnion({
116
+ Loading: { direction: directions },
117
+ Refreshing: {
118
+ data: page,
119
+ direction: directions
120
+ },
121
+ Success: { data: page },
122
+ Failure: { error: errorSchema },
123
+ Stale: {
124
+ data: page,
125
+ error: errorSchema
126
+ }
127
+ });
128
+ const subscriptionRequestSchema = Schema.Struct({
129
+ generation: PositiveInt,
130
+ args: kind.userArgs,
131
+ options: Options,
132
+ paginationId: Schema.Option(PositiveInt),
133
+ requestId: PositiveInt,
134
+ descriptor: PageDescriptor
135
+ });
136
+ const requestSchema = Schema.Struct({
137
+ generation: PositiveInt,
138
+ args: kind.userArgs,
139
+ options: Options,
140
+ paginationId: PositiveInt,
141
+ requestId: PositiveInt,
142
+ descriptor: PageDescriptor
143
+ });
144
+ const pageResult = Schema.Struct({
145
+ page: kind.page,
146
+ isDone: Schema.Boolean,
147
+ continueCursor: Schema.String,
148
+ splitCursor: Schema.optionalKey(Schema.Union([Schema.String, Schema.Null])),
149
+ pageStatus: Schema.optionalKey(Schema.Union([
150
+ Schema.Literal("SplitRecommended"),
151
+ Schema.Literal("SplitRequired"),
152
+ Schema.Null
153
+ ]))
154
+ });
155
+ const schema = Schema.TaggedUnion({
156
+ Idle: { generation: NonNegativeInt },
157
+ Active: {
158
+ generation: PositiveInt,
159
+ args: kind.userArgs,
160
+ options: Options,
161
+ paginationId: Schema.Option(PositiveInt),
162
+ requestId: PositiveInt,
163
+ current: PageDescriptor,
164
+ prevStack: Schema.Array(PageDescriptor),
165
+ phase
166
+ }
167
+ });
168
+ const settlement = Schema.Struct({
169
+ request: requestSchema,
170
+ result: Schema.Result(pageResult, errorSchema)
171
+ });
172
+ const init = (state, argsOrOptions, options) => Match.value(options).pipe(Match.withReturnType(), Match.when(void 0, () => initialState(state.generation + 1, {}, argsOrOptions)), Match.when(Match.defined, (definedOptions) => initialState(state.generation + 1, argsOrOptions, definedOptions)), Match.exhaustive);
173
+ const reinitialize = (state, argsOrOptions, options) => Match.value(options).pipe(Match.withReturnType(), Match.when(Match.defined, (definedOptions) => initialState(state.generation + 1, argsOrOptions, definedOptions)), Match.when(void 0, () => Match.value(argsOrOptions).pipe(Match.withReturnType(), Match.when(void 0, () => initialState(state.generation + 1, state.args, state.options)), Match.when(Match.defined, (definedArgsOrOptions) => Match.value(hasUserArgs).pipe(Match.withReturnType(), Match.when(true, () => initialState(state.generation + 1, definedArgsOrOptions, state.options)), Match.when(false, () => initialState(state.generation + 1, state.args, definedArgsOrOptions)), Match.exhaustive)), Match.exhaustive)), Match.exhaustive);
174
+ return {
175
+ ref,
176
+ schema,
177
+ idle: State.Idle({ generation: 0 }),
178
+ subscriptionRequestSchema,
179
+ requestSchema,
180
+ settlement,
181
+ init,
182
+ reinitialize
183
+ };
184
+ };
185
+ const descriptorEquals = (a, b) => a.cursor === b.cursor && Option.match(a.endCursor, {
186
+ onNone: () => Option.isNone(b.endCursor),
187
+ onSome: (aEnd) => Option.match(b.endCursor, {
188
+ onNone: () => false,
189
+ onSome: (bEnd) => aEnd === bEnd
190
+ })
191
+ });
192
+ /** Returns the logical request currently driving the subscription. */
193
+ const getSubscriptionRequest = (state) => ({
194
+ generation: state.generation,
195
+ args: state.args,
196
+ options: state.options,
197
+ paginationId: state.paginationId,
198
+ requestId: state.requestId,
199
+ descriptor: state.current
200
+ });
201
+ /** Attaches the client-allocated pagination id to a logical request. */
202
+ const allocateRequest = (request, paginationId) => ({
203
+ ...request,
204
+ paginationId
205
+ });
206
+ const phaseData = (phase) => Match.value(phase).pipe(Match.withReturnType(), Match.tag("Refreshing", "Success", "Stale", (dataPhase) => Option.some(dataPhase.data)), Match.tag("Loading", "Failure", () => Option.none()), Match.exhaustive);
207
+ const pendingPhase = (data, direction) => Option.match(data, {
208
+ onNone: () => Phase.Loading({ direction }),
209
+ onSome: (page) => Phase.Refreshing({
210
+ data: page,
211
+ direction
212
+ })
213
+ });
214
+ /** Close the subscription while retaining its generation tombstone. */
215
+ const close = (state) => State.Idle({ generation: state.generation });
216
+ /** Start a fresh pagination session at page one while retaining visible data. */
217
+ const reset = (state) => ({
218
+ ...state,
219
+ generation: state.generation + 1,
220
+ paginationId: Option.none(),
221
+ requestId: 1,
222
+ current: firstDescriptor(),
223
+ prevStack: [],
224
+ phase: pendingPhase(phaseData(state.phase), "Reset")
225
+ });
226
+ /** Navigate to the next page, retaining the current page while it loads. */
227
+ const next = (state) => Match.value(state.phase).pipe(Match.withReturnType(), Match.tag("Success", ({ data }) => Match.value(data.isDone).pipe(Match.withReturnType(), Match.when(true, () => Option.none()), Match.when(false, () => Option.some({
228
+ ...state,
229
+ requestId: state.requestId + 1,
230
+ current: {
231
+ cursor: Option.getOrElse(data.descriptor.endCursor, () => data.continueCursor),
232
+ endCursor: Option.none()
233
+ },
234
+ prevStack: [...state.prevStack, data.descriptor],
235
+ phase: Phase.Refreshing({
236
+ data,
237
+ direction: "Next"
238
+ })
239
+ })), Match.exhaustive)), Match.tag("Loading", "Refreshing", "Failure", "Stale", () => Option.none()), Match.exhaustive);
240
+ /** Navigate to the previous page, retaining the current page while it loads. */
241
+ const prev = (state) => Match.value(state.phase).pipe(Match.withReturnType(), Match.tag("Success", ({ data }) => {
242
+ const current = state.prevStack.at(-1);
243
+ return Match.value(current).pipe(Match.withReturnType(), Match.when(void 0, () => Option.none()), Match.when(Match.defined, (previous) => Option.some({
244
+ ...state,
245
+ requestId: state.requestId + 1,
246
+ current: previous,
247
+ prevStack: state.prevStack.slice(0, -1),
248
+ phase: Phase.Refreshing({
249
+ data,
250
+ direction: "Previous"
251
+ })
252
+ })), Match.exhaustive);
253
+ }), Match.tag("Loading", "Refreshing", "Failure", "Stale", () => Option.none()), Match.exhaustive);
254
+ /** Navigate to page one without invalidating the current pagination session. */
255
+ const first = (state) => Match.value(state.prevStack.length === 0 && descriptorEquals(state.current, firstDescriptor())).pipe(Match.withReturnType(), Match.when(true, () => Option.none()), Match.when(false, () => Option.some({
256
+ ...state,
257
+ requestId: state.requestId + 1,
258
+ current: firstDescriptor(),
259
+ prevStack: [],
260
+ phase: pendingPhase(phaseData(state.phase), "First")
261
+ })), Match.exhaustive);
262
+ /** Whether a request still names the machine's live pagination session/page. */
263
+ const isCurrentRequest = (state, candidate) => Match.value(state).pipe(Match.tag("Idle", () => false), Match.tag("Active", (active) => Match.value(active.paginationId).pipe(Match.tag("None", () => Match.value(active.generation === candidate.generation && active.requestId === candidate.requestId && descriptorEquals(active.current, candidate.descriptor)).pipe(Match.when(true, () => true), Match.when(false, () => false), Match.exhaustive)), Match.tag("Some", ({ value }) => active.generation === candidate.generation && value === candidate.paginationId && active.requestId === candidate.requestId && descriptorEquals(active.current, candidate.descriptor)), Match.exhaustive)), Match.exhaustive);
264
+ const pageFromResult = (state, result) => ({
265
+ descriptor: state.current,
266
+ number: state.prevStack.length + 1,
267
+ items: result.page,
268
+ continueCursor: result.continueCursor,
269
+ isDone: result.isDone
270
+ });
271
+ const settleSuccess = (state, result) => {
272
+ const splitCursor = result.splitCursor;
273
+ const splitSignaled = Match.value(result.pageStatus).pipe(Match.whenOr("SplitRecommended", "SplitRequired", () => true), Match.whenOr(null, void 0, () => false), Match.exhaustive);
274
+ const shouldSplit = typeof splitCursor === "string" && (splitSignaled || result.page.length > 2 * state.options.initialNumItems);
275
+ const shouldRetreat = result.page.length === 0 && result.isDone && state.prevStack.length > 0;
276
+ return Match.value(shouldSplit).pipe(Match.withReturnType(), Match.when(true, () => {
277
+ const deliveredPage = pageFromResult(state, result);
278
+ const previous = Match.value(result.pageStatus).pipe(Match.withReturnType(), Match.when("SplitRequired", () => phaseData(state.phase)), Match.whenOr("SplitRecommended", null, void 0, () => Option.some(deliveredPage)), Match.exhaustive);
279
+ return {
280
+ ...state,
281
+ requestId: state.requestId + 1,
282
+ current: {
283
+ cursor: state.current.cursor,
284
+ endCursor: Option.fromNullishOr(splitCursor)
285
+ },
286
+ phase: pendingPhase(previous, "Split")
287
+ };
288
+ }), Match.when(false, () => Match.value(shouldRetreat).pipe(Match.withReturnType(), Match.when(true, () => ({
289
+ ...state,
290
+ requestId: state.requestId + 1,
291
+ current: state.prevStack[state.prevStack.length - 1],
292
+ prevStack: state.prevStack.slice(0, -1),
293
+ phase: pendingPhase(phaseData(state.phase), "Previous")
294
+ })), Match.when(false, () => ({
295
+ ...state,
296
+ phase: Phase.Success({ data: pageFromResult(state, result) })
297
+ })), Match.exhaustive)), Match.exhaustive);
298
+ };
299
+ const settleFailure = (state, error) => ({
300
+ ...state,
301
+ phase: Option.match(phaseData(state.phase), {
302
+ onNone: () => Phase.Failure({ error }),
303
+ onSome: (data) => Phase.Stale({
304
+ error,
305
+ data
306
+ })
307
+ })
308
+ });
309
+ /**
310
+ * Fold a correlated `Result` into the machine. Like `AsyncData.settle`, a
311
+ * success becomes `Success`; a failure becomes `Stale` when a page is held,
312
+ * otherwise `Failure`. Outcomes from superseded requests and outcomes that
313
+ * arrive after the subscription closed are ignored.
314
+ */
315
+ const settle = Function.dual(2, (state, settlement) => Match.value(state).pipe(Match.withReturnType(), Match.tag("Idle", () => state), Match.tag("Active", (active) => Match.value(isCurrentRequest(active, settlement.request)).pipe(Match.when(false, () => active), Match.when(true, () => {
316
+ const allocated = {
317
+ ...active,
318
+ paginationId: Option.some(settlement.request.paginationId)
319
+ };
320
+ return Result.match(settlement.result, {
321
+ onSuccess: (result) => settleSuccess(allocated, result),
322
+ onFailure: (error) => Match.value(error).pipe(Match.when(Match.instanceOf(PaginationError.InvalidCursor), () => reset(allocated)), Match.orElse((other) => settleFailure(allocated, other)))
323
+ });
324
+ }), Match.exhaustive)), Match.exhaustive));
325
+ /** The complete page currently available to render. */
326
+ const getPage = (state) => Match.value(state).pipe(Match.tag("Idle", () => Option.none()), Match.tag("Active", ({ phase }) => phaseData(phase)), Match.exhaustive);
327
+ /** The items currently available to render. */
328
+ const getItems = (state) => Option.map(getPage(state), (page) => page.items);
329
+ /** The error from the most recent failed request, if any. */
330
+ const getError = (state) => Match.value(state).pipe(Match.withReturnType(), Match.tag("Idle", () => Option.none()), Match.tag("Active", ({ phase }) => Match.value(phase).pipe(Match.withReturnType(), Match.tag("Failure", "Stale", ({ error }) => Option.some(error)), Match.tag("Loading", "Refreshing", "Success", () => Option.none()), Match.exhaustive)), Match.exhaustive);
331
+ /** The 1-indexed page number currently targeted by the subscription. */
332
+ const targetPageNumber = (state) => state.prevStack.length + 1;
333
+ const hasPage = (state) => Option.isSome(getPage(state));
334
+ const hasError = (state) => Option.isSome(getError(state));
335
+ const isFirst = (state) => Match.value(state).pipe(Match.tag("Idle", () => false), Match.tag("Active", ({ prevStack }) => prevStack.length === 0), Match.exhaustive);
336
+ const isLast = (state) => Match.value(state).pipe(Match.tag("Idle", () => false), Match.tag("Active", ({ phase }) => Match.value(phase).pipe(Match.tag("Success", ({ data }) => data.isDone), Match.tag("Loading", "Refreshing", "Failure", "Stale", () => false), Match.exhaustive)), Match.exhaustive);
337
+ const isIdle = (state) => state._tag === "Idle";
338
+ const isLoading = (state) => state._tag === "Active" && state.phase._tag === "Loading";
339
+ const isRefreshing = (state) => state._tag === "Active" && state.phase._tag === "Refreshing";
340
+ const isSuccess = (state) => state._tag === "Active" && state.phase._tag === "Success";
341
+ const isFailure = (state) => state._tag === "Active" && state.phase._tag === "Failure";
342
+ const isStale = (state) => state._tag === "Active" && state.phase._tag === "Stale";
343
+ const isPending = (state) => Match.value(state).pipe(Match.tag("Idle", () => false), Match.tag("Active", ({ phase }) => Match.value(phase).pipe(Match.tag("Loading", "Refreshing", () => true), Match.tag("Success", "Failure", "Stale", () => false), Match.exhaustive)), Match.exhaustive);
344
+ const canNext = (state) => Match.value(state).pipe(Match.tag("Idle", () => false), Match.tag("Active", ({ phase }) => Match.value(phase).pipe(Match.tag("Success", ({ data }) => !data.isDone), Match.tag("Loading", "Refreshing", "Failure", "Stale", () => false), Match.exhaustive)), Match.exhaustive);
345
+ const canPrev = (state) => Match.value(state).pipe(Match.tag("Idle", () => false), Match.tag("Active", ({ phase, prevStack }) => Match.value(phase).pipe(Match.tag("Success", () => prevStack.length > 0), Match.tag("Loading", "Refreshing", "Failure", "Stale", () => false), Match.exhaustive)), Match.exhaustive);
346
+ /** Pattern-match exhaustively on the machine's AsyncData-style state. */
347
+ const match = Function.dual(2, (state, handlers) => Match.value(state).pipe(Match.tag("Idle", handlers.onIdle), Match.tag("Active", ({ phase }) => Match.value(phase).pipe(Match.tag("Loading", handlers.onLoading), Match.tag("Refreshing", handlers.onRefreshing), Match.tag("Failure", handlers.onFailure), Match.tag("Stale", handlers.onStale), Match.tag("Success", handlers.onSuccess), Match.exhaustive)), Match.exhaustive));
348
+ //#endregion
349
+ export { FunctionError, InvalidCursor, Options, PageDescriptor, PaginatedQuery_exports, allocateRequest, canNext, canPrev, close, first, getError, getItems, getPage, getSubscriptionRequest, hasError, hasPage, isCurrentRequest, isFailure, isFirst, isIdle, isLast, isLoading, isPending, isRefreshing, isStale, isSuccess, make, match, next, prev, reset, settle, targetPageNumber };
350
+
351
+ //# sourceMappingURL=PaginatedQuery.js.map