@eightyfourthousand/client-graphql 2026.3.1 → 2026.4.1

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.
Files changed (154) hide show
  1. package/index.d.ts +4 -0
  2. package/index.js +7 -0
  3. package/index.js.map +1 -0
  4. package/lib/client-ssr.d.ts +16 -0
  5. package/lib/client-ssr.js +39 -0
  6. package/lib/client-ssr.js.map +1 -0
  7. package/lib/client.d.ts +15 -0
  8. package/lib/client.js +46 -0
  9. package/lib/client.js.map +1 -0
  10. package/lib/config.d.ts +8 -0
  11. package/lib/config.js +19 -0
  12. package/lib/config.js.map +1 -0
  13. package/lib/functions/get-bibliography-entry.d.ts +9 -0
  14. package/lib/functions/get-bibliography-entry.js +27 -0
  15. package/lib/functions/get-bibliography-entry.js.map +1 -0
  16. package/lib/functions/get-glossary-instance.d.ts +9 -0
  17. package/lib/functions/get-glossary-instance.js +36 -0
  18. package/lib/functions/get-glossary-instance.js.map +1 -0
  19. package/lib/functions/get-passage.d.ts +10 -0
  20. package/lib/functions/get-passage.js +68 -0
  21. package/lib/functions/get-passage.js.map +1 -0
  22. package/lib/functions/get-term-passages.d.ts +20 -0
  23. package/lib/functions/get-term-passages.js +32 -0
  24. package/lib/functions/get-term-passages.js.map +1 -0
  25. package/lib/functions/get-translation-blocks-around.d.ts +15 -0
  26. package/lib/functions/get-translation-blocks-around.js +86 -0
  27. package/lib/functions/get-translation-blocks-around.js.map +1 -0
  28. package/lib/functions/get-translation-blocks.d.ts +25 -0
  29. package/lib/functions/get-translation-blocks.js +96 -0
  30. package/lib/functions/get-translation-blocks.js.map +1 -0
  31. package/lib/functions/get-translation-imprint.d.ts +10 -0
  32. package/lib/functions/get-translation-imprint.js +68 -0
  33. package/lib/functions/get-translation-imprint.js.map +1 -0
  34. package/lib/functions/get-translation-metadata.d.ts +16 -0
  35. package/lib/functions/get-translation-metadata.js +72 -0
  36. package/lib/functions/get-translation-metadata.js.map +1 -0
  37. package/lib/functions/get-translation-titles.d.ts +9 -0
  38. package/lib/functions/get-translation-titles.js +34 -0
  39. package/lib/functions/get-translation-titles.js.map +1 -0
  40. package/lib/functions/get-translation-toc.d.ts +9 -0
  41. package/{src/lib/functions/get-translation-toc.ts → lib/functions/get-translation-toc.js} +18 -48
  42. package/lib/functions/get-translation-toc.js.map +1 -0
  43. package/lib/functions/get-translation-uuids.d.ts +16 -0
  44. package/lib/functions/get-translation-uuids.js +40 -0
  45. package/lib/functions/get-translation-uuids.js.map +1 -0
  46. package/lib/functions/get-translations-metadata.d.ts +9 -0
  47. package/lib/functions/get-translations-metadata.js +51 -0
  48. package/lib/functions/get-translations-metadata.js.map +1 -0
  49. package/lib/functions/get-work-bibliography.d.ts +9 -0
  50. package/lib/functions/get-work-bibliography.js +33 -0
  51. package/lib/functions/get-work-bibliography.js.map +1 -0
  52. package/lib/functions/get-work-folios.d.ts +12 -0
  53. package/lib/functions/get-work-folios.js +32 -0
  54. package/lib/functions/get-work-folios.js.map +1 -0
  55. package/lib/functions/get-work-glossary-terms-around.d.ts +13 -0
  56. package/lib/functions/get-work-glossary-terms-around.js +95 -0
  57. package/lib/functions/get-work-glossary-terms-around.js.map +1 -0
  58. package/lib/functions/get-work-glossary-terms.d.ts +24 -0
  59. package/lib/functions/get-work-glossary-terms.js +104 -0
  60. package/lib/functions/get-work-glossary-terms.js.map +1 -0
  61. package/lib/functions/has-permission.d.ts +9 -0
  62. package/lib/functions/has-permission.js +15 -0
  63. package/lib/functions/has-permission.js.map +1 -0
  64. package/{src/lib/functions/index.ts → lib/functions/index.d.ts} +4 -18
  65. package/lib/functions/index.js +20 -0
  66. package/lib/functions/index.js.map +1 -0
  67. package/lib/functions/replace.d.ts +27 -0
  68. package/lib/functions/replace.js +49 -0
  69. package/lib/functions/replace.js.map +1 -0
  70. package/lib/functions/save-passages.d.ts +16 -0
  71. package/lib/functions/save-passages.js +35 -0
  72. package/lib/functions/save-passages.js.map +1 -0
  73. package/lib/generated/graphql.d.ts +1062 -0
  74. package/lib/generated/graphql.js +357 -0
  75. package/lib/generated/graphql.js.map +1 -0
  76. package/lib/mappers/alignment.d.ts +19 -0
  77. package/lib/mappers/alignment.js +19 -0
  78. package/lib/mappers/alignment.js.map +1 -0
  79. package/lib/mappers/annotation.d.ts +19 -0
  80. package/lib/mappers/annotation.js +74 -0
  81. package/lib/mappers/annotation.js.map +1 -0
  82. package/lib/mappers/imprint.d.ts +37 -0
  83. package/lib/mappers/imprint.js +44 -0
  84. package/lib/mappers/imprint.js.map +1 -0
  85. package/lib/mappers/index.js +8 -0
  86. package/lib/mappers/index.js.map +1 -0
  87. package/lib/mappers/passage.d.ts +41 -0
  88. package/lib/mappers/passage.js +39 -0
  89. package/lib/mappers/passage.js.map +1 -0
  90. package/lib/mappers/title.d.ts +18 -0
  91. package/lib/mappers/title.js +18 -0
  92. package/lib/mappers/title.js.map +1 -0
  93. package/lib/mappers/toc.d.ts +25 -0
  94. package/lib/mappers/toc.js +25 -0
  95. package/lib/mappers/toc.js.map +1 -0
  96. package/lib/mappers/work.d.ts +22 -0
  97. package/lib/mappers/work.js +22 -0
  98. package/lib/mappers/work.js.map +1 -0
  99. package/package.json +25 -3
  100. package/ssr.d.ts +4 -0
  101. package/ssr.js +7 -0
  102. package/ssr.js.map +1 -0
  103. package/README.md +0 -9
  104. package/codegen.ts +0 -34
  105. package/project.json +0 -21
  106. package/src/index.ts +0 -79
  107. package/src/lib/client-ssr.ts +0 -44
  108. package/src/lib/client.ts +0 -58
  109. package/src/lib/config.ts +0 -21
  110. package/src/lib/functions/get-bibliography-entry.ts +0 -40
  111. package/src/lib/functions/get-glossary-entry.ts +0 -136
  112. package/src/lib/functions/get-glossary-instance.ts +0 -48
  113. package/src/lib/functions/get-glossary-terms.ts +0 -44
  114. package/src/lib/functions/get-passage.ts +0 -78
  115. package/src/lib/functions/get-term-passages.ts +0 -53
  116. package/src/lib/functions/get-translation-blocks-around.ts +0 -131
  117. package/src/lib/functions/get-translation-blocks.ts +0 -160
  118. package/src/lib/functions/get-translation-imprint.ts +0 -114
  119. package/src/lib/functions/get-translation-metadata.ts +0 -99
  120. package/src/lib/functions/get-translation-passages-around.ts +0 -153
  121. package/src/lib/functions/get-translation-passages.ts +0 -168
  122. package/src/lib/functions/get-translation-titles.ts +0 -55
  123. package/src/lib/functions/get-translation-uuids.ts +0 -63
  124. package/src/lib/functions/get-translations-metadata.ts +0 -81
  125. package/src/lib/functions/get-work-bibliography.ts +0 -47
  126. package/src/lib/functions/get-work-folios.ts +0 -52
  127. package/src/lib/functions/get-work-glossary-terms-around.ts +0 -126
  128. package/src/lib/functions/get-work-glossary-terms.ts +0 -150
  129. package/src/lib/functions/get-work-glossary.ts +0 -54
  130. package/src/lib/functions/get-works.ts +0 -111
  131. package/src/lib/functions/has-permission.ts +0 -38
  132. package/src/lib/functions/save-passages.ts +0 -76
  133. package/src/lib/generated/graphql.ts +0 -1318
  134. package/src/lib/graphql/fragments/alignment.graphql +0 -7
  135. package/src/lib/graphql/fragments/annotation.graphql +0 -7
  136. package/src/lib/graphql/fragments/imprint.graphql +0 -34
  137. package/src/lib/graphql/fragments/passage.graphql +0 -29
  138. package/src/lib/graphql/fragments/title.graphql +0 -6
  139. package/src/lib/graphql/fragments/toc.graphql +0 -40
  140. package/src/lib/graphql/fragments/work.graphql +0 -10
  141. package/src/lib/graphql/queries/passages.graphql +0 -116
  142. package/src/lib/graphql/queries/work.graphql +0 -38
  143. package/src/lib/graphql/queries/works.graphql +0 -23
  144. package/src/lib/mappers/alignment.ts +0 -34
  145. package/src/lib/mappers/annotation.ts +0 -204
  146. package/src/lib/mappers/imprint.ts +0 -79
  147. package/src/lib/mappers/passage.ts +0 -80
  148. package/src/lib/mappers/title.ts +0 -35
  149. package/src/lib/mappers/toc.ts +0 -49
  150. package/src/lib/mappers/work.ts +0 -38
  151. package/src/ssr.ts +0 -73
  152. package/tsconfig.json +0 -17
  153. package/tsconfig.lib.json +0 -14
  154. /package/{src/lib/mappers/index.ts → lib/mappers/index.d.ts} +0 -0
@@ -1,81 +0,0 @@
1
- import type { GraphQLClient } from 'graphql-request';
2
- import { gql } from 'graphql-request';
3
- import type { Work } from '@eightyfourthousand/data-access';
4
- import { worksFromGraphQL } from '../mappers';
5
-
6
- const GET_ALL_WORKS = gql`
7
- query GetAllWorks($cursor: String, $limit: Int) {
8
- works(cursor: $cursor, limit: $limit) {
9
- items {
10
- uuid
11
- title
12
- toh
13
- publicationDate
14
- publicationVersion
15
- pages
16
- restriction
17
- section
18
- }
19
- pageInfo {
20
- nextCursor
21
- hasMoreAfter
22
- }
23
- }
24
- }
25
- `;
26
-
27
- type GraphQLWork = {
28
- uuid: string;
29
- title: string;
30
- toh: string[];
31
- publicationDate: string;
32
- publicationVersion: string;
33
- pages: number;
34
- restriction: boolean;
35
- section: string;
36
- };
37
-
38
- type GetAllWorksResponse = {
39
- works: {
40
- items: GraphQLWork[];
41
- pageInfo: {
42
- nextCursor: string | null;
43
- hasMoreAfter: boolean;
44
- };
45
- };
46
- };
47
-
48
- /**
49
- * Get metadata for all published translation works (fetches all pages).
50
- */
51
- export async function getTranslationsMetadata({
52
- client,
53
- limit = 200,
54
- }: {
55
- client: GraphQLClient;
56
- limit?: number;
57
- }): Promise<Work[]> {
58
- try {
59
- const allWorks: GraphQLWork[] = [];
60
- let cursor: string | null = null;
61
-
62
- // Fetch all pages
63
- do {
64
- const response: GetAllWorksResponse =
65
- await client.request<GetAllWorksResponse>(GET_ALL_WORKS, {
66
- cursor,
67
- limit,
68
- });
69
-
70
- allWorks.push(...response.works.items);
71
- cursor = response.works.pageInfo.hasMoreAfter
72
- ? response.works.pageInfo.nextCursor
73
- : null;
74
- } while (cursor !== null);
75
-
76
- return worksFromGraphQL(allWorks);
77
- } catch (error) {
78
- console.error('Error fetching translations metadata:', error);
79
- return [];
80
- }
81
- }
@@ -1,47 +0,0 @@
1
- import type { GraphQLClient } from 'graphql-request';
2
- import { gql } from 'graphql-request';
3
- import type { BibliographyEntries } from '@eightyfourthousand/data-access';
4
-
5
- const GET_WORK_BIBLIOGRAPHY = gql`
6
- query GetWorkBibliography($uuid: ID!) {
7
- work(uuid: $uuid) {
8
- bibliography {
9
- heading
10
- entries {
11
- uuid
12
- html
13
- workUuid
14
- }
15
- }
16
- }
17
- }
18
- `;
19
-
20
- type GetWorkBibliographyResponse = {
21
- work: {
22
- bibliography: BibliographyEntries;
23
- } | null;
24
- };
25
-
26
- /**
27
- * Get bibliography entries for a specific work.
28
- */
29
- export async function getWorkBibliography({
30
- client,
31
- uuid,
32
- }: {
33
- client: GraphQLClient;
34
- uuid: string;
35
- }): Promise<BibliographyEntries> {
36
- try {
37
- const response = await client.request<GetWorkBibliographyResponse>(
38
- GET_WORK_BIBLIOGRAPHY,
39
- { uuid },
40
- );
41
-
42
- return response.work?.bibliography ?? [];
43
- } catch (error) {
44
- console.error('Error fetching work bibliography:', error);
45
- return [];
46
- }
47
- }
@@ -1,52 +0,0 @@
1
- import type { GraphQLClient } from 'graphql-request';
2
- import { gql } from 'graphql-request';
3
- import type { Folio } from '@eightyfourthousand/data-access';
4
-
5
- const GET_WORK_FOLIOS = gql`
6
- query GetWorkFolios($uuid: ID!, $toh: String!, $page: Int, $size: Int) {
7
- work(uuid: $uuid) {
8
- folios(toh: $toh, page: $page, size: $size) {
9
- uuid
10
- content
11
- volume
12
- folio
13
- side
14
- }
15
- }
16
- }
17
- `;
18
-
19
- type GetWorkFoliosResponse = {
20
- work: {
21
- folios: Folio[];
22
- } | null;
23
- };
24
-
25
- /**
26
- * Get folios for a specific work, filtered by toh and paginated.
27
- */
28
- export async function getWorkFolios({
29
- client,
30
- uuid,
31
- toh,
32
- page = 0,
33
- size = 10,
34
- }: {
35
- client: GraphQLClient;
36
- uuid: string;
37
- toh: string;
38
- page?: number;
39
- size?: number;
40
- }): Promise<Folio[]> {
41
- try {
42
- const response = await client.request<GetWorkFoliosResponse>(
43
- GET_WORK_FOLIOS,
44
- { uuid, toh, page, size },
45
- );
46
-
47
- return response.work?.folios ?? [];
48
- } catch (error) {
49
- console.error('Error fetching work folios:', error);
50
- return [];
51
- }
52
- }
@@ -1,126 +0,0 @@
1
- import type { GraphQLClient } from 'graphql-request';
2
- import { gql } from 'graphql-request';
3
- import type { GlossaryTermInstance } from '@eightyfourthousand/data-access';
4
- import type { GlossaryTermsPage } from './get-work-glossary-terms';
5
-
6
- const GET_WORK_GLOSSARY_TERMS_AROUND = gql`
7
- query GetWorkGlossaryTermsAround(
8
- $uuid: ID!
9
- $cursor: String!
10
- $limit: Int
11
- $withAttestations: Boolean
12
- ) {
13
- work(uuid: $uuid) {
14
- glossaryTerms(
15
- cursor: $cursor
16
- limit: $limit
17
- direction: AROUND
18
- withAttestations: $withAttestations
19
- ) {
20
- nodes {
21
- uuid
22
- authority
23
- definition
24
- termNumber
25
- names {
26
- english
27
- tibetan
28
- sanskrit
29
- pali
30
- chinese
31
- wylie
32
- }
33
- passages(first: 10) {
34
- items {
35
- uuid
36
- type
37
- label
38
- }
39
- nextCursor
40
- hasMore
41
- }
42
- }
43
- pageInfo {
44
- nextCursor
45
- prevCursor
46
- hasMoreAfter
47
- hasMoreBefore
48
- }
49
- totalCount
50
- }
51
- }
52
- }
53
- `;
54
-
55
- type GetWorkGlossaryTermsAroundResponse = {
56
- work: {
57
- glossaryTerms: {
58
- nodes: GlossaryTermInstance[];
59
- pageInfo: {
60
- nextCursor?: string | null;
61
- prevCursor?: string | null;
62
- hasMoreAfter: boolean;
63
- hasMoreBefore: boolean;
64
- };
65
- totalCount: number;
66
- };
67
- } | null;
68
- };
69
-
70
- /**
71
- * Get glossary terms around a specific term UUID.
72
- * Used for navigating to a glossary entry that hasn't been loaded yet.
73
- */
74
- export async function getWorkGlossaryTermsAround({
75
- client,
76
- uuid,
77
- termUuid,
78
- limit,
79
- withAttestations = false,
80
- }: {
81
- client: GraphQLClient;
82
- uuid: string;
83
- termUuid: string;
84
- limit?: number;
85
- withAttestations?: boolean;
86
- }): Promise<GlossaryTermsPage> {
87
- try {
88
- const response = await client.request<GetWorkGlossaryTermsAroundResponse>(
89
- GET_WORK_GLOSSARY_TERMS_AROUND,
90
- {
91
- uuid,
92
- cursor: termUuid,
93
- limit,
94
- withAttestations,
95
- },
96
- );
97
-
98
- if (!response.work) {
99
- return {
100
- terms: [],
101
- hasMoreAfter: false,
102
- hasMoreBefore: false,
103
- totalCount: 0,
104
- };
105
- }
106
-
107
- const { glossaryTerms } = response.work;
108
-
109
- return {
110
- terms: glossaryTerms.nodes,
111
- nextCursor: glossaryTerms.pageInfo.nextCursor ?? undefined,
112
- prevCursor: glossaryTerms.pageInfo.prevCursor ?? undefined,
113
- hasMoreAfter: glossaryTerms.pageInfo.hasMoreAfter,
114
- hasMoreBefore: glossaryTerms.pageInfo.hasMoreBefore,
115
- totalCount: glossaryTerms.totalCount,
116
- };
117
- } catch (error) {
118
- console.error('Error fetching glossary terms around:', error);
119
- return {
120
- terms: [],
121
- hasMoreAfter: false,
122
- hasMoreBefore: false,
123
- totalCount: 0,
124
- };
125
- }
126
- }
@@ -1,150 +0,0 @@
1
- import type { GraphQLClient } from 'graphql-request';
2
- import { gql } from 'graphql-request';
3
- import type { GlossaryTermInstance, PaginationDirection } from '@eightyfourthousand/data-access';
4
-
5
- const GET_WORK_GLOSSARY_TERMS = gql`
6
- query GetWorkGlossaryTerms(
7
- $uuid: ID!
8
- $cursor: String
9
- $limit: Int
10
- $direction: PaginationDirection
11
- $withAttestations: Boolean
12
- ) {
13
- work(uuid: $uuid) {
14
- glossaryTerms(
15
- cursor: $cursor
16
- limit: $limit
17
- direction: $direction
18
- withAttestations: $withAttestations
19
- ) {
20
- nodes {
21
- uuid
22
- authority
23
- definition
24
- termNumber
25
- names {
26
- english
27
- tibetan
28
- sanskrit
29
- pali
30
- chinese
31
- wylie
32
- }
33
- passages(first: 10) {
34
- items {
35
- uuid
36
- type
37
- label
38
- }
39
- nextCursor
40
- hasMore
41
- }
42
- }
43
- pageInfo {
44
- nextCursor
45
- prevCursor
46
- hasMoreAfter
47
- hasMoreBefore
48
- }
49
- totalCount
50
- }
51
- }
52
- }
53
- `;
54
-
55
- type GetWorkGlossaryTermsResponse = {
56
- work: {
57
- glossaryTerms: {
58
- nodes: GlossaryTermInstance[];
59
- pageInfo: {
60
- nextCursor?: string | null;
61
- prevCursor?: string | null;
62
- hasMoreAfter: boolean;
63
- hasMoreBefore: boolean;
64
- };
65
- totalCount: number;
66
- };
67
- } | null;
68
- };
69
-
70
- /**
71
- * Result of fetching glossary terms with pagination info
72
- */
73
- export type GlossaryTermsPage = {
74
- terms: GlossaryTermInstance[];
75
- nextCursor?: string;
76
- prevCursor?: string;
77
- hasMoreAfter: boolean;
78
- hasMoreBefore: boolean;
79
- totalCount: number;
80
- };
81
-
82
- /**
83
- * Map internal pagination direction to GraphQL enum
84
- */
85
- function mapDirection(
86
- direction?: PaginationDirection,
87
- ): 'FORWARD' | 'BACKWARD' | undefined {
88
- if (!direction) return undefined;
89
- return direction === 'forward' ? 'FORWARD' : 'BACKWARD';
90
- }
91
-
92
- /**
93
- * Get paginated glossary terms for a work.
94
- */
95
- export async function getWorkGlossaryTerms({
96
- client,
97
- uuid,
98
- cursor,
99
- limit = 50,
100
- direction,
101
- withAttestations = false,
102
- }: {
103
- client: GraphQLClient;
104
- uuid: string;
105
- cursor?: string;
106
- limit?: number;
107
- direction?: PaginationDirection;
108
- withAttestations?: boolean;
109
- }): Promise<GlossaryTermsPage> {
110
- try {
111
- const response = await client.request<GetWorkGlossaryTermsResponse>(
112
- GET_WORK_GLOSSARY_TERMS,
113
- {
114
- uuid,
115
- cursor,
116
- limit,
117
- direction: mapDirection(direction),
118
- withAttestations,
119
- },
120
- );
121
-
122
- if (!response.work) {
123
- return {
124
- terms: [],
125
- hasMoreAfter: false,
126
- hasMoreBefore: false,
127
- totalCount: 0,
128
- };
129
- }
130
-
131
- const { glossaryTerms } = response.work;
132
-
133
- return {
134
- terms: glossaryTerms.nodes,
135
- nextCursor: glossaryTerms.pageInfo.nextCursor ?? undefined,
136
- prevCursor: glossaryTerms.pageInfo.prevCursor ?? undefined,
137
- hasMoreAfter: glossaryTerms.pageInfo.hasMoreAfter,
138
- hasMoreBefore: glossaryTerms.pageInfo.hasMoreBefore,
139
- totalCount: glossaryTerms.totalCount,
140
- };
141
- } catch (error) {
142
- console.error('Error fetching work glossary terms:', error);
143
- return {
144
- terms: [],
145
- hasMoreAfter: false,
146
- hasMoreBefore: false,
147
- totalCount: 0,
148
- };
149
- }
150
- }
@@ -1,54 +0,0 @@
1
- import type { GraphQLClient } from 'graphql-request';
2
- import { gql } from 'graphql-request';
3
- import type { GlossaryTermInstance } from '@eightyfourthousand/data-access';
4
-
5
- const GET_WORK_GLOSSARY = gql`
6
- query GetWorkGlossary($uuid: ID!, $withAttestations: Boolean) {
7
- work(uuid: $uuid) {
8
- glossary(withAttestations: $withAttestations) {
9
- uuid
10
- authority
11
- definition
12
- names {
13
- english
14
- tibetan
15
- sanskrit
16
- pali
17
- chinese
18
- wylie
19
- }
20
- }
21
- }
22
- }
23
- `;
24
-
25
- type GetWorkGlossaryResponse = {
26
- work: {
27
- glossary: GlossaryTermInstance[];
28
- } | null;
29
- };
30
-
31
- /**
32
- * Get glossary term instances for a specific work.
33
- */
34
- export async function getWorkGlossary({
35
- client,
36
- uuid,
37
- withAttestations = false,
38
- }: {
39
- client: GraphQLClient;
40
- uuid: string;
41
- withAttestations?: boolean;
42
- }): Promise<GlossaryTermInstance[]> {
43
- try {
44
- const response = await client.request<GetWorkGlossaryResponse>(
45
- GET_WORK_GLOSSARY,
46
- { uuid, withAttestations },
47
- );
48
-
49
- return response.work?.glossary ?? [];
50
- } catch (error) {
51
- console.error('Error fetching work glossary:', error);
52
- return [];
53
- }
54
- }
@@ -1,111 +0,0 @@
1
- import type { GraphQLClient } from 'graphql-request';
2
- import { gql } from 'graphql-request';
3
- import type { Work } from '@eightyfourthousand/data-access';
4
-
5
- const GET_WORKS = gql`
6
- query GetWorks($cursor: String, $limit: Int) {
7
- works(cursor: $cursor, limit: $limit) {
8
- items {
9
- uuid
10
- title
11
- toh
12
- publicationDate
13
- publicationVersion
14
- pages
15
- restriction
16
- section
17
- }
18
- pageInfo {
19
- nextCursor
20
- prevCursor
21
- hasMoreAfter
22
- hasMoreBefore
23
- }
24
- totalCount
25
- }
26
- }
27
- `;
28
-
29
- type GraphQLWork = {
30
- uuid: string;
31
- title: string;
32
- toh: string[];
33
- publicationDate: string;
34
- publicationVersion: string;
35
- pages: number;
36
- restriction: boolean;
37
- section: string;
38
- };
39
-
40
- type PageInfo = {
41
- nextCursor: string | null;
42
- prevCursor: string | null;
43
- hasMoreAfter: boolean;
44
- hasMoreBefore: boolean;
45
- };
46
-
47
- type GetWorksResponse = {
48
- works: {
49
- items: GraphQLWork[];
50
- pageInfo: PageInfo;
51
- totalCount: number;
52
- };
53
- };
54
-
55
- export type WorksPage = {
56
- items: Work[];
57
- pageInfo: PageInfo;
58
- totalCount: number;
59
- };
60
-
61
- function workFromGraphQL(gqlWork: GraphQLWork): Work {
62
- return {
63
- uuid: gqlWork.uuid,
64
- title: gqlWork.title,
65
- toh: gqlWork.toh as Work['toh'],
66
- publicationDate: new Date(gqlWork.publicationDate),
67
- publicationVersion:
68
- gqlWork.publicationVersion as Work['publicationVersion'],
69
- pages: gqlWork.pages,
70
- restriction: gqlWork.restriction,
71
- section: gqlWork.section,
72
- };
73
- }
74
-
75
- /**
76
- * Get paginated works.
77
- */
78
- export async function getWorks({
79
- client,
80
- cursor,
81
- limit = 50,
82
- }: {
83
- client: GraphQLClient;
84
- cursor?: string;
85
- limit?: number;
86
- }): Promise<WorksPage> {
87
- try {
88
- const response = await client.request<GetWorksResponse>(GET_WORKS, {
89
- cursor,
90
- limit,
91
- });
92
-
93
- return {
94
- items: response.works.items.map(workFromGraphQL),
95
- pageInfo: response.works.pageInfo,
96
- totalCount: response.works.totalCount,
97
- };
98
- } catch (error) {
99
- console.error('Error fetching works:', error);
100
- return {
101
- items: [],
102
- pageInfo: {
103
- nextCursor: null,
104
- prevCursor: null,
105
- hasMoreAfter: false,
106
- hasMoreBefore: false,
107
- },
108
- totalCount: 0,
109
- };
110
- }
111
- }
@@ -1,38 +0,0 @@
1
- import type { GraphQLClient } from 'graphql-request';
2
- import { gql } from 'graphql-request';
3
-
4
- // Permission enum matching the GraphQL schema
5
- export type Permission =
6
- | 'PROJECTS_READ'
7
- | 'PROJECTS_EDIT'
8
- | 'PROJECTS_ADMIN'
9
- | 'EDITOR_READ'
10
- | 'EDITOR_EDIT'
11
- | 'EDITOR_ADMIN';
12
-
13
- const HAS_PERMISSION_QUERY = gql`
14
- query HasPermission($permission: Permission!) {
15
- hasPermission(permission: $permission)
16
- }
17
- `;
18
-
19
- interface HasPermissionResponse {
20
- hasPermission: boolean;
21
- }
22
-
23
- /**
24
- * Check if the current user has a specific permission
25
- */
26
- export const hasPermission = async ({
27
- client,
28
- permission,
29
- }: {
30
- client: GraphQLClient;
31
- permission: Permission;
32
- }): Promise<boolean> => {
33
- const response = await client.request<HasPermissionResponse>(
34
- HAS_PERMISSION_QUERY,
35
- { permission },
36
- );
37
- return response.hasPermission;
38
- };