@conduit-client/pagination 5.67.0-dev1
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/LICENSE.txt +27 -0
- package/README.md +1 -0
- package/dist/index.js +157 -0
- package/dist/index.js.map +1 -0
- package/dist/types/__tests__/cursor-pagination-strategy.spec.d.ts +1 -0
- package/dist/types/__tests__/page-number-page-size-pagination-strategy.spec.d.ts +1 -0
- package/dist/types/__tests__/relay-pagination-strategy.spec.d.ts +1 -0
- package/dist/types/cursor-pagination-strategy.d.ts +51 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/page-number-page-size-pagination-strategy.d.ts +34 -0
- package/dist/types/pagination-strategy.d.ts +10 -0
- package/dist/types/relay-pagination-strategy.d.ts +57 -0
- package/package.json +33 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
*Attorney/Client Privileged + Confidential*
|
|
2
|
+
|
|
3
|
+
Terms of Use for Public Code (Non-OSS)
|
|
4
|
+
|
|
5
|
+
*NOTE:* Before publishing code under this license/these Terms of Use, please review https://salesforce.quip.com/WFfvAMKB18AL and confirm that you’ve completed all prerequisites described therein. *These Terms of Use may not be used or modified without input from IP and Product Legal.*
|
|
6
|
+
|
|
7
|
+
*Terms of Use*
|
|
8
|
+
|
|
9
|
+
Copyright 2022 Salesforce, Inc. All rights reserved.
|
|
10
|
+
|
|
11
|
+
These Terms of Use govern the download, installation, and/or use of this software provided by Salesforce, Inc. (“Salesforce”) (the “Software”), were last updated on April 15, 2022, ** and constitute a legally binding agreement between you and Salesforce. If you do not agree to these Terms of Use, do not install or use the Software.
|
|
12
|
+
|
|
13
|
+
Salesforce grants you a worldwide, non-exclusive, no-charge, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute the Software and derivative works subject to these Terms. These Terms shall be included in all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
Subject to the limited rights expressly granted hereunder, Salesforce reserves all rights, title, and interest in and to all intellectual property subsisting in the Software. No rights are granted to you hereunder other than as expressly set forth herein. Users residing in countries on the United States Office of Foreign Assets Control sanction list, or which are otherwise subject to a US export embargo, may not use the Software.
|
|
16
|
+
|
|
17
|
+
Implementation of the Software may require development work, for which you are responsible. The Software may contain bugs, errors and incompatibilities and is made available on an AS IS basis without support, updates, or service level commitments.
|
|
18
|
+
|
|
19
|
+
Salesforce reserves the right at any time to modify, suspend, or discontinue, the Software (or any part thereof) with or without notice. You agree that Salesforce shall not be liable to you or to any third party for any modification, suspension, or discontinuance.
|
|
20
|
+
|
|
21
|
+
You agree to defend Salesforce against any claim, demand, suit or proceeding made or brought against Salesforce by a third party arising out of or accruing from (a) your use of the Software, and (b) any application you develop with the Software that infringes any copyright, trademark, trade secret, trade dress, patent, or other intellectual property right of any person or defames any person or violates their rights of publicity or privacy (each a “Claim Against Salesforce”), and will indemnify Salesforce from any damages, attorney fees, and costs finally awarded against Salesforce as a result of, or for any amounts paid by Salesforce under a settlement approved by you in writing of, a Claim Against Salesforce, provided Salesforce (x) promptly gives you written notice of the Claim Against Salesforce, (y) gives you sole control of the defense and settlement of the Claim Against Salesforce (except that you may not settle any Claim Against Salesforce unless it unconditionally releases Salesforce of all liability), and (z) gives you all reasonable assistance, at your expense.
|
|
22
|
+
|
|
23
|
+
WITHOUT LIMITING THE GENERALITY OF THE FOREGOING, THE SOFTWARE IS NOT SUPPORTED AND IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. IN NO EVENT SHALL SALESFORCE HAVE ANY LIABILITY FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE, OR CONSEQUENTIAL DAMAGES, OR DAMAGES BASED ON LOST PROFITS, DATA, OR USE, IN CONNECTION WITH THE SOFTWARE, HOWEVER CAUSED AND WHETHER IN CONTRACT, TORT, OR UNDER ANY OTHER THEORY OF LIABILITY, WHETHER OR NOT YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
|
24
|
+
|
|
25
|
+
These Terms of Use shall be governed exclusively by the internal laws of the State of California, without regard to its conflicts of laws rules. Each party hereby consents to the exclusive jurisdiction of the state and federal courts located in San Francisco County, California to adjudicate any dispute arising out of or relating to these Terms of Use and the download, installation, and/or use of the Software. Except as expressly stated herein, these Terms of Use constitute the entire agreement between the parties, and supersede all prior and contemporaneous agreements, proposals, or representations, written or oral, concerning their subject matter. No modification, amendment, or waiver of any provision of these Terms of Use shall be effective unless it is by an update to these Terms of Use that Salesforce makes available, or is in writing and signed by the party against whom the modification, amendment, or waiver is to be asserted.
|
|
26
|
+
|
|
27
|
+
_*Data Privacy*_: Salesforce may collect, process, and store device, system, and other information related to your use of the Software. This information includes, but is not limited to, IP address, user metrics, and other data (“Usage Data”). Salesforce may use Usage Data for analytics, product development, and marketing purposes. You acknowledge that files generated in conjunction with the Software may contain sensitive or confidential data, and you are solely responsible for anonymizing and protecting such data.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
This software is provided as-is with no support provided.
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2022, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
class MissingPaginationMetadataError extends Error {
|
|
7
|
+
constructor(params) {
|
|
8
|
+
super();
|
|
9
|
+
this.params = params;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
class UnknownCursorError extends Error {
|
|
13
|
+
}
|
|
14
|
+
class RelayPaginationStrategy {
|
|
15
|
+
constructor(getCursorFromEdge = (edge) => edge.cursor) {
|
|
16
|
+
this.getCursorFromEdge = getCursorFromEdge;
|
|
17
|
+
}
|
|
18
|
+
// NOTE: Right now, this class only supports one page of continuous data.
|
|
19
|
+
// The construct for multiple "pages" in the RelayPaginationManagedMetadata is to allow
|
|
20
|
+
// for multiple disconnected pages of data to be tracked independently
|
|
21
|
+
merge(params, incoming, maybeExisting) {
|
|
22
|
+
const existing = this.buildInitialMetadata(maybeExisting);
|
|
23
|
+
const existingPage = existing.pages[0];
|
|
24
|
+
const { startIndex, endIndex } = this.getInsertionIndices(params, existingPage, incoming);
|
|
25
|
+
const preIncomingEdges = existingPage.edges.slice(0, startIndex);
|
|
26
|
+
const postIncomingEdges = existingPage.edges.slice(endIndex);
|
|
27
|
+
const newEdges = [...preIncomingEdges, ...incoming.edges, ...postIncomingEdges];
|
|
28
|
+
return {
|
|
29
|
+
pages: [
|
|
30
|
+
{
|
|
31
|
+
edges: newEdges,
|
|
32
|
+
pageInfo: {
|
|
33
|
+
hasNextPage: this.calculateHasNextPageAfterInsertion(
|
|
34
|
+
startIndex + incoming.edges.length,
|
|
35
|
+
newEdges,
|
|
36
|
+
incoming.pageInfo.hasNextPage,
|
|
37
|
+
existingPage.pageInfo.hasNextPage
|
|
38
|
+
),
|
|
39
|
+
hasPreviousPage: this.calculateHasPreviousPageAfterInsertion(
|
|
40
|
+
startIndex,
|
|
41
|
+
incoming.pageInfo.hasPreviousPage,
|
|
42
|
+
existingPage.pageInfo.hasPreviousPage
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
read(params, existing) {
|
|
50
|
+
if (existing === void 0) {
|
|
51
|
+
return new MissingPaginationMetadataError(params);
|
|
52
|
+
}
|
|
53
|
+
const existingPage = existing.pages[0];
|
|
54
|
+
const { startIndex, endIndex } = this.getReadIndices(params, existingPage);
|
|
55
|
+
if (endIndex > existingPage.edges.length && existingPage.pageInfo.hasNextPage) {
|
|
56
|
+
return new MissingPaginationMetadataError({
|
|
57
|
+
first: endIndex - existingPage.edges.length,
|
|
58
|
+
after: this.getCursorFromEdge(existingPage.edges.at(-1))
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
const edges = existingPage.edges.slice(startIndex, endIndex);
|
|
62
|
+
const hasNextPage = endIndex < existingPage.edges.length || existingPage.pageInfo.hasNextPage;
|
|
63
|
+
const hasPreviousPage = startIndex !== 0;
|
|
64
|
+
const startCursor = edges.length > 0 ? this.getCursorFromEdge(edges[0]) : null;
|
|
65
|
+
const endCursor = edges.length > 0 ? this.getCursorFromEdge(edges[edges.length - 1]) : null;
|
|
66
|
+
return {
|
|
67
|
+
edges,
|
|
68
|
+
pageInfo: {
|
|
69
|
+
hasNextPage,
|
|
70
|
+
hasPreviousPage,
|
|
71
|
+
startCursor,
|
|
72
|
+
endCursor
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
buildInitialMetadata(maybeExisting) {
|
|
77
|
+
if (maybeExisting !== void 0) {
|
|
78
|
+
return maybeExisting;
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
pages: [
|
|
82
|
+
{
|
|
83
|
+
edges: [],
|
|
84
|
+
pageInfo: {
|
|
85
|
+
hasPreviousPage: true,
|
|
86
|
+
hasNextPage: true
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
getInsertionIndices(params, existing, incoming) {
|
|
93
|
+
if (!("first" in params)) {
|
|
94
|
+
throw new Error("last/before is currently unsupported for relay pagination");
|
|
95
|
+
}
|
|
96
|
+
let startIndex = 0;
|
|
97
|
+
let endIndex = 0;
|
|
98
|
+
if (incoming.pageInfo.hasPreviousPage) {
|
|
99
|
+
if (params.after === void 0) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
"Got hasPreviousPage true on null after param. Incorrect server behavior."
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
startIndex = this.findStartIndex(params.after, existing.edges);
|
|
105
|
+
}
|
|
106
|
+
if (incoming.pageInfo.hasNextPage) {
|
|
107
|
+
const lastCursor = this.getCursorFromEdge(incoming.edges[incoming.edges.length - 1]);
|
|
108
|
+
const lastCursorIndex = existing.edges.findIndex(
|
|
109
|
+
(edge) => this.getCursorFromEdge(edge) === lastCursor
|
|
110
|
+
);
|
|
111
|
+
if (lastCursorIndex < 0) {
|
|
112
|
+
endIndex = startIndex + incoming.edges.length;
|
|
113
|
+
} else {
|
|
114
|
+
endIndex = lastCursorIndex + 1;
|
|
115
|
+
}
|
|
116
|
+
} else {
|
|
117
|
+
endIndex = existing.edges.length;
|
|
118
|
+
}
|
|
119
|
+
return { startIndex, endIndex };
|
|
120
|
+
}
|
|
121
|
+
calculateHasNextPageAfterInsertion(incomingEndIndex, edges, incomingHasNextPage, existingHasNextPage) {
|
|
122
|
+
const incomingAtEnd = incomingEndIndex === edges.length;
|
|
123
|
+
return incomingAtEnd ? incomingHasNextPage : existingHasNextPage;
|
|
124
|
+
}
|
|
125
|
+
calculateHasPreviousPageAfterInsertion(startIndex, incomingHasPreviousPage, existingHasPreviousPage) {
|
|
126
|
+
const incomingAtBeginning = startIndex === 0;
|
|
127
|
+
return incomingAtBeginning ? incomingHasPreviousPage : existingHasPreviousPage;
|
|
128
|
+
}
|
|
129
|
+
getReadIndices(params, existing) {
|
|
130
|
+
if (!("first" in params)) {
|
|
131
|
+
throw new Error("last/before is currently unsupported for relay pagination");
|
|
132
|
+
}
|
|
133
|
+
let startIndex = 0;
|
|
134
|
+
if (params.after !== void 0) {
|
|
135
|
+
startIndex = this.findStartIndex(params.after, existing.edges);
|
|
136
|
+
}
|
|
137
|
+
let endIndex = startIndex + existing.edges.length;
|
|
138
|
+
if (params.first !== void 0) {
|
|
139
|
+
endIndex = startIndex + params.first;
|
|
140
|
+
}
|
|
141
|
+
return { startIndex, endIndex };
|
|
142
|
+
}
|
|
143
|
+
findStartIndex(after, existingEdges) {
|
|
144
|
+
const afterIndex = existingEdges.findIndex(
|
|
145
|
+
(edge) => this.getCursorFromEdge(edge) === after
|
|
146
|
+
);
|
|
147
|
+
if (afterIndex < 0) {
|
|
148
|
+
throw new UnknownCursorError();
|
|
149
|
+
}
|
|
150
|
+
return afterIndex + 1;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
export {
|
|
154
|
+
MissingPaginationMetadataError,
|
|
155
|
+
RelayPaginationStrategy
|
|
156
|
+
};
|
|
157
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/pagination-strategy.ts","../src/relay-pagination-strategy.ts"],"sourcesContent":["/*\n * An error that contains an optimized set of parameters that represent the missing data in a collection.\n * These parameters can be used to make a server request for the missing pagination metadata.\n */\nexport class MissingPaginationMetadataError<QueryParams> extends Error {\n constructor(public params: QueryParams) {\n super();\n }\n}\n\n/* An error that is thrown when a cursor is trying to be merged or read that we have never seen */\nexport class UnknownCursorError extends Error {}\n\n/*\n * A pagination strategy is an algorithm for managing a client side representation of a paginated\n * collection of data. Pagination strategies have two methods: `merge` and `read`. `merge` is used\n * to update the client side representation of the collection with a new page of data. `read` is used\n * to determine if a request for a particular page of data can be satisfied by our local cache.\n *\n * QueryParams: A generic representing configuration for a client side request for a page of data\n * ManagedPaginationMetadata: A generic representing the client side representation of the collection\n * ResponsePaginationMetadata: A generic representing a specific page of data.\n */\nexport type PaginationStrategy<QueryParams, ManagedPaginationMetadata, ResponsePaginationMetadata> =\n {\n merge(\n params: QueryParams,\n incoming: ResponsePaginationMetadata,\n existing: ManagedPaginationMetadata | undefined\n ): ManagedPaginationMetadata;\n read(\n params: QueryParams,\n existing: ManagedPaginationMetadata\n ): ResponsePaginationMetadata | MissingPaginationMetadataError<QueryParams>;\n };\n","import { MissingPaginationMetadataError, UnknownCursorError } from './pagination-strategy';\nimport type { PaginationStrategy } from './pagination-strategy';\n\nexport type Edge<Node> = {\n cursor: string;\n node: Node;\n};\nexport type QueryParams =\n | {\n first: number | undefined;\n after: string | undefined;\n }\n | {\n last: number | undefined;\n before: string | undefined;\n };\n\nexport type IncomingPageInfo = {\n hasNextPage: boolean;\n hasPreviousPage: boolean;\n startCursor?: string | null;\n endCursor?: string | null;\n};\n\nexport type CompletePageInfo = {\n hasNextPage: boolean;\n hasPreviousPage: boolean;\n startCursor: string | null;\n endCursor: string | null;\n};\n\nexport type IncomingResponsePaginationMetadata<Node> = {\n pageInfo: IncomingPageInfo;\n edges: Edge<Node>[];\n};\n\nexport type ResponsePaginationMetadata<Node> = {\n pageInfo: CompletePageInfo;\n edges: Edge<Node>[];\n};\n\nexport type ManagedPaginationMetadata<Node> = {\n pages: {\n pageInfo: {\n hasNextPage: boolean;\n hasPreviousPage: boolean;\n };\n edges: Edge<Node>[];\n }[];\n};\n\nexport class RelayPaginationStrategy<Node>\n implements\n PaginationStrategy<\n QueryParams,\n ManagedPaginationMetadata<Node>,\n ResponsePaginationMetadata<Node>\n >\n{\n constructor(private getCursorFromEdge: (edge: any) => string = (edge) => edge.cursor) {}\n // NOTE: Right now, this class only supports one page of continuous data.\n // The construct for multiple \"pages\" in the RelayPaginationManagedMetadata is to allow\n // for multiple disconnected pages of data to be tracked independently\n merge(\n params: QueryParams,\n incoming: IncomingResponsePaginationMetadata<Node>,\n maybeExisting: ManagedPaginationMetadata<Node> | undefined\n ): ManagedPaginationMetadata<Node> {\n const existing = this.buildInitialMetadata(maybeExisting);\n const existingPage = existing.pages[0];\n\n const { startIndex, endIndex } = this.getInsertionIndices(params, existingPage, incoming);\n\n const preIncomingEdges = existingPage.edges.slice(0, startIndex);\n const postIncomingEdges = existingPage.edges.slice(endIndex);\n\n const newEdges = [...preIncomingEdges, ...incoming.edges, ...postIncomingEdges];\n\n return {\n pages: [\n {\n edges: newEdges,\n pageInfo: {\n hasNextPage: this.calculateHasNextPageAfterInsertion(\n startIndex + incoming.edges.length,\n newEdges,\n incoming.pageInfo.hasNextPage,\n existingPage.pageInfo.hasNextPage\n ),\n hasPreviousPage: this.calculateHasPreviousPageAfterInsertion(\n startIndex,\n incoming.pageInfo.hasPreviousPage,\n existingPage.pageInfo.hasPreviousPage\n ),\n },\n },\n ],\n };\n }\n\n read(\n params: QueryParams,\n existing: ManagedPaginationMetadata<Node> | undefined\n ): ResponsePaginationMetadata<Node> | MissingPaginationMetadataError<QueryParams> {\n if (existing === undefined) {\n return new MissingPaginationMetadataError(params);\n }\n\n const existingPage = existing.pages[0];\n const { startIndex, endIndex } = this.getReadIndices(params, existingPage);\n\n if (endIndex > existingPage.edges.length && existingPage.pageInfo.hasNextPage) {\n return new MissingPaginationMetadataError({\n first: endIndex - existingPage.edges.length,\n after: this.getCursorFromEdge(existingPage.edges.at(-1)),\n });\n }\n\n const edges = existingPage.edges.slice(startIndex, endIndex);\n\n const hasNextPage =\n endIndex < existingPage.edges.length || existingPage.pageInfo.hasNextPage;\n const hasPreviousPage = startIndex !== 0;\n\n // Calculate startCursor and endCursor based on the actual edges being returned\n const startCursor = edges.length > 0 ? this.getCursorFromEdge(edges[0]) : null;\n const endCursor = edges.length > 0 ? this.getCursorFromEdge(edges[edges.length - 1]) : null;\n\n return {\n edges,\n pageInfo: {\n hasNextPage,\n hasPreviousPage,\n startCursor,\n endCursor,\n },\n };\n }\n\n buildInitialMetadata(\n maybeExisting: ManagedPaginationMetadata<Node> | undefined\n ): ManagedPaginationMetadata<Node> {\n if (maybeExisting !== undefined) {\n return maybeExisting;\n }\n\n return {\n pages: [\n {\n edges: [],\n pageInfo: {\n hasPreviousPage: true,\n hasNextPage: true,\n },\n },\n ],\n };\n }\n\n getInsertionIndices(\n params: QueryParams,\n existing: ManagedPaginationMetadata<Node>['pages'][0],\n incoming: IncomingResponsePaginationMetadata<Node>\n ) {\n if (!('first' in params)) {\n // we don't support last before yet\n throw new Error('last/before is currently unsupported for relay pagination');\n }\n\n let startIndex = 0;\n let endIndex = 0;\n\n if (incoming.pageInfo.hasPreviousPage) {\n if (params.after === undefined) {\n throw new Error(\n 'Got hasPreviousPage true on null after param. Incorrect server behavior.'\n );\n }\n\n startIndex = this.findStartIndex(params.after, existing.edges);\n }\n\n if (incoming.pageInfo.hasNextPage) {\n const lastCursor = this.getCursorFromEdge(incoming.edges[incoming.edges.length - 1]);\n const lastCursorIndex = existing.edges.findIndex(\n (edge) => this.getCursorFromEdge(edge) === lastCursor\n );\n\n if (lastCursorIndex < 0) {\n // Don't know about the last cursor, should calculate end index on length of incoming\n endIndex = startIndex + incoming.edges.length;\n } else {\n endIndex = lastCursorIndex + 1;\n }\n } else {\n endIndex = existing.edges.length;\n }\n\n return { startIndex, endIndex };\n }\n\n private calculateHasNextPageAfterInsertion(\n incomingEndIndex: number,\n edges: Edge<Node>[],\n incomingHasNextPage: boolean,\n existingHasNextPage: boolean\n ): boolean {\n const incomingAtEnd = incomingEndIndex === edges.length;\n\n // If the incoming data is at the end of our known data, use it's hasNextPage as entire collections, otherwise keep old\n return incomingAtEnd ? incomingHasNextPage : existingHasNextPage;\n }\n\n private calculateHasPreviousPageAfterInsertion(\n startIndex: number,\n incomingHasPreviousPage: boolean,\n existingHasPreviousPage: boolean\n ): boolean {\n const incomingAtBeginning = startIndex === 0;\n // If the incoming data is at the beginning of our known data, use it's hasPreviousPage as entire collections, otherwise keep old\n return incomingAtBeginning ? incomingHasPreviousPage : existingHasPreviousPage;\n }\n\n private getReadIndices(\n params: QueryParams,\n existing: ManagedPaginationMetadata<Node>['pages'][0]\n ) {\n if (!('first' in params)) {\n // we don't support last before yet\n throw new Error('last/before is currently unsupported for relay pagination');\n }\n\n let startIndex = 0;\n\n if (params.after !== undefined) {\n startIndex = this.findStartIndex(params.after, existing.edges);\n }\n\n let endIndex = startIndex + existing.edges.length;\n if (params.first !== undefined) {\n endIndex = startIndex + params.first;\n }\n\n return { startIndex, endIndex };\n }\n\n private findStartIndex(after: string, existingEdges: Edge<Node>[]): number {\n const afterIndex = existingEdges.findIndex(\n (edge) => this.getCursorFromEdge(edge) === after\n );\n\n if (afterIndex < 0) {\n throw new UnknownCursorError();\n }\n\n return afterIndex + 1;\n }\n}\n"],"names":[],"mappings":";;;;;AAIO,MAAM,uCAAoD,MAAM;AAAA,EAC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1
|
+
import { MissingPaginationMetadataError } from './pagination-strategy';
|
|
2
|
+
import type { PaginationStrategy } from './pagination-strategy';
|
|
3
|
+
type Cursor = string | null;
|
|
4
|
+
export type QueryParams = {
|
|
5
|
+
cursor: Cursor;
|
|
6
|
+
pageSize: number;
|
|
7
|
+
};
|
|
8
|
+
type PageInfo = {
|
|
9
|
+
nextCursor: Cursor;
|
|
10
|
+
prevCursor: Cursor | undefined;
|
|
11
|
+
};
|
|
12
|
+
type ManagedPageInfo = {
|
|
13
|
+
nextCursor: Cursor | undefined;
|
|
14
|
+
prevCursor: Cursor | undefined;
|
|
15
|
+
};
|
|
16
|
+
type ManagedEdge<Node> = {
|
|
17
|
+
cursor: Cursor | undefined;
|
|
18
|
+
node: Node;
|
|
19
|
+
};
|
|
20
|
+
type Page<Node> = {
|
|
21
|
+
pageInfo: ManagedPageInfo;
|
|
22
|
+
edges: ManagedEdge<Node>[];
|
|
23
|
+
};
|
|
24
|
+
export type ResponsePaginationMetadata<Node> = {
|
|
25
|
+
pageInfo: PageInfo;
|
|
26
|
+
edges: {
|
|
27
|
+
node: Node;
|
|
28
|
+
}[];
|
|
29
|
+
};
|
|
30
|
+
export type ManagedPaginationMetadata<Node> = {
|
|
31
|
+
pages: Page<Node>[];
|
|
32
|
+
};
|
|
33
|
+
export declare const SYNTHETIC_CURSOR_PREFIX = "client:";
|
|
34
|
+
export declare class CursorPaginationStrategy<Node> implements PaginationStrategy<QueryParams, ManagedPaginationMetadata<Node>, ResponsePaginationMetadata<Node>> {
|
|
35
|
+
cursorStrategy: 'server' | 'synthetic';
|
|
36
|
+
constructor(cursorStrategy?: 'server' | 'synthetic');
|
|
37
|
+
merge(params: QueryParams, incoming: ResponsePaginationMetadata<Node>, maybeExisting: ManagedPaginationMetadata<Node> | undefined): ManagedPaginationMetadata<Node>;
|
|
38
|
+
getInsertionIndices(params: QueryParams, existing: Page<Node>, incoming: ResponsePaginationMetadata<Node>): {
|
|
39
|
+
startIndex: number;
|
|
40
|
+
endIndex: number;
|
|
41
|
+
};
|
|
42
|
+
read(params: QueryParams, existing: ManagedPaginationMetadata<Node> | undefined): ResponsePaginationMetadata<Node> | MissingPaginationMetadataError<QueryParams>;
|
|
43
|
+
private calculateReadPageInfo;
|
|
44
|
+
private getClientCursor;
|
|
45
|
+
private getReadIndices;
|
|
46
|
+
private findParamsCursorIndex;
|
|
47
|
+
private encodeClientCursor;
|
|
48
|
+
private decodeClientCursor;
|
|
49
|
+
private buildInitialMetadata;
|
|
50
|
+
}
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { MissingPaginationMetadataError } from './pagination-strategy';
|
|
2
|
+
export * from './relay-pagination-strategy';
|
|
3
|
+
export { MissingPaginationMetadataError };
|
|
4
|
+
export type { IncomingResponsePaginationMetadata, IncomingPageInfo, CompletePageInfo, } from './relay-pagination-strategy';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { MissingPaginationMetadataError } from './pagination-strategy';
|
|
2
|
+
import type { PaginationStrategy } from './pagination-strategy';
|
|
3
|
+
export type QueryParams = {
|
|
4
|
+
pageNumber: number;
|
|
5
|
+
pageSize: number;
|
|
6
|
+
};
|
|
7
|
+
export type Edge<Node> = {
|
|
8
|
+
node: Node;
|
|
9
|
+
};
|
|
10
|
+
export type ResponsePaginationMetadata<Node> = {
|
|
11
|
+
edges: Edge<Node>[];
|
|
12
|
+
};
|
|
13
|
+
export type ManagedPaginationMetadataPage<Node> = {
|
|
14
|
+
edges: (Edge<Node> | undefined)[];
|
|
15
|
+
completed: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type ManagedPaginationMetadata<Node> = {
|
|
18
|
+
pages: ManagedPaginationMetadataPage<Node>[];
|
|
19
|
+
};
|
|
20
|
+
export declare class PageNumberPageSizePaginationStrategy<Node> implements PaginationStrategy<QueryParams, ManagedPaginationMetadata<Node>, ResponsePaginationMetadata<Node>> {
|
|
21
|
+
merge(params: QueryParams, incoming: ResponsePaginationMetadata<Node>, maybeExisting: ManagedPaginationMetadata<Node> | undefined): ManagedPaginationMetadata<Node>;
|
|
22
|
+
read(params: QueryParams, existing: ManagedPaginationMetadata<Node> | undefined): ResponsePaginationMetadata<Node> | MissingPaginationMetadataError<QueryParams>;
|
|
23
|
+
buildInitialMetadata(existing: ManagedPaginationMetadata<Node> | undefined): ManagedPaginationMetadata<Node>;
|
|
24
|
+
getInsertionIndices(params: QueryParams, incoming: ResponsePaginationMetadata<Node>): {
|
|
25
|
+
startIndex: number;
|
|
26
|
+
endIndex: number;
|
|
27
|
+
};
|
|
28
|
+
isLastPage(params: QueryParams, incoming: ResponsePaginationMetadata<Node>): boolean;
|
|
29
|
+
readIsMissingEdges(params: QueryParams, readEdges: (Edge<Node> | undefined)[], existingPage: ManagedPaginationMetadataPage<Node>): boolean;
|
|
30
|
+
getReadIndices(params: QueryParams): {
|
|
31
|
+
startIndex: number;
|
|
32
|
+
endIndex: number;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class MissingPaginationMetadataError<QueryParams> extends Error {
|
|
2
|
+
params: QueryParams;
|
|
3
|
+
constructor(params: QueryParams);
|
|
4
|
+
}
|
|
5
|
+
export declare class UnknownCursorError extends Error {
|
|
6
|
+
}
|
|
7
|
+
export type PaginationStrategy<QueryParams, ManagedPaginationMetadata, ResponsePaginationMetadata> = {
|
|
8
|
+
merge(params: QueryParams, incoming: ResponsePaginationMetadata, existing: ManagedPaginationMetadata | undefined): ManagedPaginationMetadata;
|
|
9
|
+
read(params: QueryParams, existing: ManagedPaginationMetadata): ResponsePaginationMetadata | MissingPaginationMetadataError<QueryParams>;
|
|
10
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { MissingPaginationMetadataError } from './pagination-strategy';
|
|
2
|
+
import type { PaginationStrategy } from './pagination-strategy';
|
|
3
|
+
export type Edge<Node> = {
|
|
4
|
+
cursor: string;
|
|
5
|
+
node: Node;
|
|
6
|
+
};
|
|
7
|
+
export type QueryParams = {
|
|
8
|
+
first: number | undefined;
|
|
9
|
+
after: string | undefined;
|
|
10
|
+
} | {
|
|
11
|
+
last: number | undefined;
|
|
12
|
+
before: string | undefined;
|
|
13
|
+
};
|
|
14
|
+
export type IncomingPageInfo = {
|
|
15
|
+
hasNextPage: boolean;
|
|
16
|
+
hasPreviousPage: boolean;
|
|
17
|
+
startCursor?: string | null;
|
|
18
|
+
endCursor?: string | null;
|
|
19
|
+
};
|
|
20
|
+
export type CompletePageInfo = {
|
|
21
|
+
hasNextPage: boolean;
|
|
22
|
+
hasPreviousPage: boolean;
|
|
23
|
+
startCursor: string | null;
|
|
24
|
+
endCursor: string | null;
|
|
25
|
+
};
|
|
26
|
+
export type IncomingResponsePaginationMetadata<Node> = {
|
|
27
|
+
pageInfo: IncomingPageInfo;
|
|
28
|
+
edges: Edge<Node>[];
|
|
29
|
+
};
|
|
30
|
+
export type ResponsePaginationMetadata<Node> = {
|
|
31
|
+
pageInfo: CompletePageInfo;
|
|
32
|
+
edges: Edge<Node>[];
|
|
33
|
+
};
|
|
34
|
+
export type ManagedPaginationMetadata<Node> = {
|
|
35
|
+
pages: {
|
|
36
|
+
pageInfo: {
|
|
37
|
+
hasNextPage: boolean;
|
|
38
|
+
hasPreviousPage: boolean;
|
|
39
|
+
};
|
|
40
|
+
edges: Edge<Node>[];
|
|
41
|
+
}[];
|
|
42
|
+
};
|
|
43
|
+
export declare class RelayPaginationStrategy<Node> implements PaginationStrategy<QueryParams, ManagedPaginationMetadata<Node>, ResponsePaginationMetadata<Node>> {
|
|
44
|
+
private getCursorFromEdge;
|
|
45
|
+
constructor(getCursorFromEdge?: (edge: any) => string);
|
|
46
|
+
merge(params: QueryParams, incoming: IncomingResponsePaginationMetadata<Node>, maybeExisting: ManagedPaginationMetadata<Node> | undefined): ManagedPaginationMetadata<Node>;
|
|
47
|
+
read(params: QueryParams, existing: ManagedPaginationMetadata<Node> | undefined): ResponsePaginationMetadata<Node> | MissingPaginationMetadataError<QueryParams>;
|
|
48
|
+
buildInitialMetadata(maybeExisting: ManagedPaginationMetadata<Node> | undefined): ManagedPaginationMetadata<Node>;
|
|
49
|
+
getInsertionIndices(params: QueryParams, existing: ManagedPaginationMetadata<Node>['pages'][0], incoming: IncomingResponsePaginationMetadata<Node>): {
|
|
50
|
+
startIndex: number;
|
|
51
|
+
endIndex: number;
|
|
52
|
+
};
|
|
53
|
+
private calculateHasNextPageAfterInsertion;
|
|
54
|
+
private calculateHasPreviousPageAfterInsertion;
|
|
55
|
+
private getReadIndices;
|
|
56
|
+
private findStartIndex;
|
|
57
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@conduit-client/pagination",
|
|
3
|
+
"version": "5.67.0-dev1",
|
|
4
|
+
"description": "OneStore Pagination Utilities",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/salesforce-experience-platform-emu/luvio-next.git",
|
|
9
|
+
"directory": "packages/@conduit-client/pagination"
|
|
10
|
+
},
|
|
11
|
+
"license": "SEE LICENSE IN LICENSE.txt",
|
|
12
|
+
"main": "dist/index.js",
|
|
13
|
+
"types": "dist/types/index.d.ts",
|
|
14
|
+
"files": [
|
|
15
|
+
"dist/"
|
|
16
|
+
],
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@conduit-client/utils": "5.67.0-dev1"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "vite build && tsc --build --emitDeclarationOnly",
|
|
22
|
+
"clean": "rm -rf dist",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"test:size": "size-limit",
|
|
25
|
+
"watch": "npm run build --watch"
|
|
26
|
+
},
|
|
27
|
+
"size-limit": [
|
|
28
|
+
{
|
|
29
|
+
"path": "./dist/index.js",
|
|
30
|
+
"limit": "2 kB"
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|