@eightyfourthousand/client-graphql 2026.4.0 → 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 (149) 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} +3 -12
  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 -75
  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-instance.ts +0 -49
  112. package/src/lib/functions/get-passage.ts +0 -81
  113. package/src/lib/functions/get-term-passages.ts +0 -53
  114. package/src/lib/functions/get-translation-blocks-around.ts +0 -129
  115. package/src/lib/functions/get-translation-blocks.ts +0 -158
  116. package/src/lib/functions/get-translation-imprint.ts +0 -114
  117. package/src/lib/functions/get-translation-metadata.ts +0 -99
  118. package/src/lib/functions/get-translation-titles.ts +0 -55
  119. package/src/lib/functions/get-translation-uuids.ts +0 -63
  120. package/src/lib/functions/get-translations-metadata.ts +0 -81
  121. package/src/lib/functions/get-work-bibliography.ts +0 -47
  122. package/src/lib/functions/get-work-folios.ts +0 -52
  123. package/src/lib/functions/get-work-glossary-terms-around.ts +0 -127
  124. package/src/lib/functions/get-work-glossary-terms.ts +0 -154
  125. package/src/lib/functions/has-permission.ts +0 -38
  126. package/src/lib/functions/replace.ts +0 -91
  127. package/src/lib/functions/save-passages.ts +0 -76
  128. package/src/lib/generated/graphql.ts +0 -1297
  129. package/src/lib/graphql/fragments/alignment.graphql +0 -7
  130. package/src/lib/graphql/fragments/annotation.graphql +0 -7
  131. package/src/lib/graphql/fragments/imprint.graphql +0 -34
  132. package/src/lib/graphql/fragments/passage.graphql +0 -29
  133. package/src/lib/graphql/fragments/title.graphql +0 -6
  134. package/src/lib/graphql/fragments/toc.graphql +0 -40
  135. package/src/lib/graphql/fragments/work.graphql +0 -10
  136. package/src/lib/graphql/queries/passages.graphql +0 -116
  137. package/src/lib/graphql/queries/work.graphql +0 -38
  138. package/src/lib/graphql/queries/works.graphql +0 -23
  139. package/src/lib/mappers/alignment.ts +0 -34
  140. package/src/lib/mappers/annotation.ts +0 -204
  141. package/src/lib/mappers/imprint.ts +0 -79
  142. package/src/lib/mappers/passage.ts +0 -80
  143. package/src/lib/mappers/title.ts +0 -35
  144. package/src/lib/mappers/toc.ts +0 -49
  145. package/src/lib/mappers/work.ts +0 -38
  146. package/src/ssr.ts +0 -66
  147. package/tsconfig.json +0 -17
  148. package/tsconfig.lib.json +0 -14
  149. /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 { Passage } from '@eightyfourthousand/data-access';
4
- import { passageFromGraphQL, type GraphQLPassage } from '../mappers';
5
-
6
- const GET_PASSAGE = gql`
7
- fragment AnnotationFields on Annotation {
8
- uuid
9
- type
10
- start
11
- end
12
- metadata
13
- }
14
-
15
- fragment AlignmentFields on Alignment {
16
- folioUuid
17
- toh
18
- tibetan
19
- folioNumber
20
- volumeNumber
21
- }
22
-
23
- fragment PassageFields on Passage {
24
- uuid
25
- workUuid
26
- content
27
- label
28
- sort
29
- type
30
- xmlId
31
- }
32
-
33
- fragment PassageWithAnnotations on Passage {
34
- ...PassageFields
35
- annotations {
36
- ...AnnotationFields
37
- }
38
- alignments {
39
- ...AlignmentFields
40
- }
41
- }
42
-
43
- query GetPassage($uuid: ID, $xmlId: String) {
44
- passage(uuid: $uuid, xmlId: $xmlId) {
45
- ...PassageWithAnnotations
46
- }
47
- }
48
- `;
49
-
50
- type GetPassageResponse = {
51
- passage: GraphQLPassage | null;
52
- };
53
-
54
- /**
55
- * Get a single passage by UUID or XML ID.
56
- */
57
- export async function getPassage({
58
- client,
59
- uuid,
60
- xmlId,
61
- }: {
62
- client: GraphQLClient;
63
- uuid?: string;
64
- xmlId?: string;
65
- }): Promise<Passage | undefined> {
66
- try {
67
- const response = await client.request<GetPassageResponse>(GET_PASSAGE, {
68
- uuid,
69
- xmlId,
70
- });
71
-
72
- if (!response.passage) {
73
- return undefined;
74
- }
75
-
76
- return passageFromGraphQL(response.passage);
77
- } catch (error) {
78
- console.error('Error fetching passage:', error);
79
- return undefined;
80
- }
81
- }
@@ -1,53 +0,0 @@
1
- import type { GraphQLClient } from 'graphql-request';
2
- import { gql } from 'graphql-request';
3
-
4
- const GET_TERM_PASSAGES = gql`
5
- query GetTermPassages($uuid: ID!, $first: Int, $after: String) {
6
- glossaryTermPassages(uuid: $uuid, first: $first, after: $after) {
7
- items {
8
- uuid
9
- type
10
- label
11
- sort
12
- }
13
- nextCursor
14
- hasMore
15
- }
16
- }
17
- `;
18
-
19
- export type GlossaryPassagesPage = {
20
- items: Array<{ uuid: string; type: string; label: string; sort: number }>;
21
- nextCursor: string | null;
22
- hasMore: boolean;
23
- };
24
-
25
- type GetTermPassagesResponse = {
26
- glossaryTermPassages: GlossaryPassagesPage;
27
- };
28
-
29
- /**
30
- * Fetch a page of passage references for a single glossary term instance.
31
- */
32
- export async function getTermPassages({
33
- client,
34
- uuid,
35
- first = 10,
36
- after,
37
- }: {
38
- client: GraphQLClient;
39
- uuid: string;
40
- first?: number;
41
- after?: string;
42
- }): Promise<GlossaryPassagesPage> {
43
- try {
44
- const response = await client.request<GetTermPassagesResponse>(
45
- GET_TERM_PASSAGES,
46
- { uuid, first, after },
47
- );
48
- return response.glossaryTermPassages;
49
- } catch (error) {
50
- console.error('Error fetching term passages:', error);
51
- return { items: [], nextCursor: null, hasMore: false };
52
- }
53
- }
@@ -1,129 +0,0 @@
1
- import type { GraphQLClient } from 'graphql-request';
2
- import { gql } from 'graphql-request';
3
- import type { BodyItemType, TranslationEditorContentItem } from '@eightyfourthousand/data-access';
4
- import type { TranslationBlocksPage } from './get-translation-blocks';
5
-
6
- const GET_PASSAGES_AROUND_WITH_JSON = gql`
7
- fragment PassageWithJson on Passage {
8
- uuid
9
- workUuid
10
- label
11
- sort
12
- type
13
- xmlId
14
- json
15
- }
16
-
17
- query GetPassagesAroundWithJson(
18
- $uuid: ID!
19
- $cursor: String!
20
- $limit: Int
21
- $filter: PassageFilter
22
- ) {
23
- work(uuid: $uuid) {
24
- uuid
25
- passages(
26
- cursor: $cursor
27
- limit: $limit
28
- direction: AROUND
29
- filter: $filter
30
- ) {
31
- nodes {
32
- ...PassageWithJson
33
- }
34
- pageInfo {
35
- nextCursor
36
- prevCursor
37
- hasMoreAfter
38
- hasMoreBefore
39
- }
40
- }
41
- }
42
- }
43
- `;
44
-
45
- type PassageWithJson = {
46
- uuid: string;
47
- workUuid: string;
48
- label: string;
49
- sort: number;
50
- type: string;
51
- xmlId?: string | null;
52
- json?: unknown | null;
53
- };
54
-
55
- type GetPassagesAroundWithJsonResponse = {
56
- work: {
57
- uuid: string;
58
- passages: {
59
- nodes: PassageWithJson[];
60
- pageInfo: {
61
- nextCursor?: string | null;
62
- prevCursor?: string | null;
63
- hasMoreAfter: boolean;
64
- hasMoreBefore: boolean;
65
- };
66
- };
67
- } | null;
68
- };
69
-
70
- /**
71
- * Get translation blocks (TipTap JSON) around a specific passage UUID.
72
- *
73
- * Returns pre-transformed TipTap editor blocks ready for rendering.
74
- */
75
- export async function getTranslationBlocksAround({
76
- client,
77
- uuid,
78
- passageUuid,
79
- type,
80
- maxPassages,
81
- }: {
82
- client: GraphQLClient;
83
- uuid: string;
84
- passageUuid: string;
85
- type?: BodyItemType | string;
86
- maxPassages?: number;
87
- }): Promise<TranslationBlocksPage> {
88
- try {
89
- const response = await client.request<GetPassagesAroundWithJsonResponse>(
90
- GET_PASSAGES_AROUND_WITH_JSON,
91
- {
92
- uuid,
93
- cursor: passageUuid,
94
- limit: maxPassages,
95
- filter: type ? { type } : undefined,
96
- },
97
- );
98
-
99
- if (!response.work) {
100
- return {
101
- blocks: [],
102
- hasMoreAfter: false,
103
- hasMoreBefore: false,
104
- };
105
- }
106
-
107
- const { passages } = response.work;
108
-
109
- // Extract the JSON blocks, filtering out any null values
110
- const blocks = passages.nodes
111
- .map((node) => node.json)
112
- .filter((json): json is TranslationEditorContentItem => json != null);
113
-
114
- return {
115
- blocks,
116
- nextCursor: passages.pageInfo.nextCursor ?? undefined,
117
- prevCursor: passages.pageInfo.prevCursor ?? undefined,
118
- hasMoreAfter: passages.pageInfo.hasMoreAfter,
119
- hasMoreBefore: passages.pageInfo.hasMoreBefore,
120
- };
121
- } catch (error) {
122
- console.error('Error fetching translation blocks around:', error);
123
- return {
124
- blocks: [],
125
- hasMoreAfter: false,
126
- hasMoreBefore: false,
127
- };
128
- }
129
- }
@@ -1,158 +0,0 @@
1
- import type { GraphQLClient } from 'graphql-request';
2
- import { gql } from 'graphql-request';
3
- import type {
4
- BodyItemType,
5
- PaginationDirection,
6
- TranslationEditorContent,
7
- TranslationEditorContentItem,
8
- } from '@eightyfourthousand/data-access';
9
-
10
- const GET_PASSAGES_WITH_JSON = gql`
11
- fragment PassageWithJson on Passage {
12
- uuid
13
- workUuid
14
- label
15
- sort
16
- type
17
- xmlId
18
- json
19
- }
20
-
21
- query GetPassagesWithJson(
22
- $uuid: ID!
23
- $cursor: String
24
- $limit: Int
25
- $direction: PaginationDirection
26
- $filter: PassageFilter
27
- ) {
28
- work(uuid: $uuid) {
29
- uuid
30
- passages(
31
- cursor: $cursor
32
- limit: $limit
33
- direction: $direction
34
- filter: $filter
35
- ) {
36
- nodes {
37
- ...PassageWithJson
38
- }
39
- pageInfo {
40
- nextCursor
41
- prevCursor
42
- hasMoreAfter
43
- hasMoreBefore
44
- }
45
- }
46
- }
47
- }
48
- `;
49
-
50
- type PassageWithJson = {
51
- uuid: string;
52
- workUuid: string;
53
- label: string;
54
- sort: number;
55
- type: string;
56
- xmlId?: string | null;
57
- json?: unknown | null;
58
- };
59
-
60
- type GetPassagesWithJsonResponse = {
61
- work: {
62
- uuid: string;
63
- passages: {
64
- nodes: PassageWithJson[];
65
- pageInfo: {
66
- nextCursor?: string | null;
67
- prevCursor?: string | null;
68
- hasMoreAfter: boolean;
69
- hasMoreBefore: boolean;
70
- };
71
- };
72
- } | null;
73
- };
74
-
75
- /**
76
- * Result of fetching translation blocks with pagination info
77
- */
78
- export type TranslationBlocksPage = {
79
- blocks: TranslationEditorContent;
80
- nextCursor?: string;
81
- prevCursor?: string;
82
- hasMoreAfter: boolean;
83
- hasMoreBefore: boolean;
84
- };
85
-
86
- /**
87
- * Map internal pagination direction to GraphQL enum
88
- */
89
- function mapDirection(
90
- direction?: PaginationDirection,
91
- ): 'FORWARD' | 'BACKWARD' | undefined {
92
- if (!direction) return undefined;
93
- return direction === 'forward' ? 'FORWARD' : 'BACKWARD';
94
- }
95
-
96
- /**
97
- * Get paginated translation blocks (TipTap JSON) for a work.
98
- *
99
- * Returns pre-transformed TipTap editor blocks ready for rendering.
100
- */
101
- export async function getTranslationBlocks({
102
- client,
103
- uuid,
104
- type,
105
- cursor,
106
- maxPassages = 100,
107
- direction,
108
- }: {
109
- client: GraphQLClient;
110
- uuid: string;
111
- type?: BodyItemType | string;
112
- cursor?: string;
113
- maxPassages?: number;
114
- direction?: PaginationDirection;
115
- }): Promise<TranslationBlocksPage> {
116
- try {
117
- const response = await client.request<GetPassagesWithJsonResponse>(
118
- GET_PASSAGES_WITH_JSON,
119
- {
120
- uuid,
121
- cursor,
122
- limit: maxPassages,
123
- direction: mapDirection(direction),
124
- filter: type ? { type } : undefined,
125
- },
126
- );
127
-
128
- if (!response.work) {
129
- return {
130
- blocks: [],
131
- hasMoreAfter: false,
132
- hasMoreBefore: false,
133
- };
134
- }
135
-
136
- const { passages } = response.work;
137
-
138
- // Extract the JSON blocks, filtering out any null values
139
- const blocks = passages.nodes
140
- .map((node) => node.json)
141
- .filter((json): json is TranslationEditorContentItem => json != null);
142
-
143
- return {
144
- blocks,
145
- nextCursor: passages.pageInfo.nextCursor ?? undefined,
146
- prevCursor: passages.pageInfo.prevCursor ?? undefined,
147
- hasMoreAfter: passages.pageInfo.hasMoreAfter,
148
- hasMoreBefore: passages.pageInfo.hasMoreBefore,
149
- };
150
- } catch (error) {
151
- console.error('Error fetching translation blocks:', error);
152
- return {
153
- blocks: [],
154
- hasMoreAfter: false,
155
- hasMoreBefore: false,
156
- };
157
- }
158
- }
@@ -1,114 +0,0 @@
1
- import type { GraphQLClient } from 'graphql-request';
2
- import { gql } from 'graphql-request';
3
- import type { Imprint } from '@eightyfourthousand/data-access';
4
- import { imprintFromGraphQL } from '../mappers';
5
-
6
- const GET_WORK_WITH_IMPRINT = gql`
7
- fragment LicenseFields on License {
8
- name
9
- link
10
- description
11
- }
12
-
13
- fragment TitlesByLanguageFields on TitlesByLanguage {
14
- tibetan
15
- english
16
- wylie
17
- sanskrit
18
- }
19
-
20
- fragment ImprintFields on Imprint {
21
- toh
22
- section
23
- version
24
- restriction
25
- publishYear
26
- tibetanAuthors
27
- isAuthorContested
28
- sourceDescription
29
- publisherStatement
30
- tibetanTranslators
31
- license {
32
- ...LicenseFields
33
- }
34
- mainTitles {
35
- ...TitlesByLanguageFields
36
- }
37
- longTitles {
38
- ...TitlesByLanguageFields
39
- }
40
- }
41
-
42
- query GetWorkWithImprint($uuid: ID!, $toh: String) {
43
- work(uuid: $uuid, toh: $toh) {
44
- uuid
45
- imprint {
46
- ...ImprintFields
47
- }
48
- }
49
- }
50
- `;
51
-
52
- type GetWorkWithImprintResponse = {
53
- work: {
54
- uuid: string;
55
- imprint: {
56
- toh: string;
57
- section?: string | null;
58
- version?: string | null;
59
- restriction?: boolean | null;
60
- publishYear?: string | null;
61
- tibetanAuthors?: string[] | null;
62
- isAuthorContested: boolean;
63
- sourceDescription?: string | null;
64
- publisherStatement?: string | null;
65
- tibetanTranslators?: string | null;
66
- license: {
67
- name?: string | null;
68
- link?: string | null;
69
- description?: string | null;
70
- } | null;
71
- mainTitles?: {
72
- tibetan?: string | null;
73
- english?: string | null;
74
- wylie?: string | null;
75
- sanskrit?: string | null;
76
- } | null;
77
- longTitles?: {
78
- tibetan?: string | null;
79
- english?: string | null;
80
- wylie?: string | null;
81
- sanskrit?: string | null;
82
- } | null;
83
- } | null;
84
- } | null;
85
- };
86
-
87
- /**
88
- * Get the imprint for a translation work.
89
- */
90
- export async function getTranslationImprint({
91
- client,
92
- uuid,
93
- toh,
94
- }: {
95
- client: GraphQLClient;
96
- uuid: string;
97
- toh: string;
98
- }): Promise<Imprint | undefined> {
99
- try {
100
- const response = await client.request<GetWorkWithImprintResponse>(
101
- GET_WORK_WITH_IMPRINT,
102
- { uuid, toh },
103
- );
104
-
105
- if (!response.work?.imprint) {
106
- return undefined;
107
- }
108
-
109
- return imprintFromGraphQL(response.work.imprint, response.work.uuid);
110
- } catch (error) {
111
- console.error('Error fetching translation imprint:', error);
112
- return undefined;
113
- }
114
- }
@@ -1,99 +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 { workFromGraphQL } from '../mappers';
5
-
6
- const GET_WORK_BY_UUID = gql`
7
- query GetWorkByUuid($uuid: ID!) {
8
- work(uuid: $uuid) {
9
- uuid
10
- title
11
- toh
12
- publicationDate
13
- publicationVersion
14
- pages
15
- restriction
16
- section
17
- }
18
- }
19
- `;
20
-
21
- const GET_WORK_BY_TOH = gql`
22
- query GetWorkByToh($toh: String!) {
23
- work(toh: $toh) {
24
- uuid
25
- title
26
- toh
27
- publicationDate
28
- publicationVersion
29
- pages
30
- restriction
31
- section
32
- }
33
- }
34
- `;
35
-
36
- type GetWorkResponse = {
37
- work: {
38
- uuid: string;
39
- title: string;
40
- toh: string[];
41
- publicationDate: string;
42
- publicationVersion: string;
43
- pages: number;
44
- restriction: boolean;
45
- section: string;
46
- } | null;
47
- };
48
-
49
- /**
50
- * Get work metadata by UUID.
51
- */
52
- export async function getTranslationMetadataByUuid({
53
- client,
54
- uuid,
55
- }: {
56
- client: GraphQLClient;
57
- uuid: string;
58
- }): Promise<Work | null> {
59
- try {
60
- const response = await client.request<GetWorkResponse>(GET_WORK_BY_UUID, {
61
- uuid,
62
- });
63
-
64
- if (!response.work) {
65
- return null;
66
- }
67
-
68
- return workFromGraphQL(response.work);
69
- } catch (error) {
70
- console.error('Error fetching translation metadata by UUID:', error);
71
- return null;
72
- }
73
- }
74
-
75
- /**
76
- * Get work metadata by Tohoku catalog number.
77
- */
78
- export async function getTranslationMetadataByToh({
79
- client,
80
- toh,
81
- }: {
82
- client: GraphQLClient;
83
- toh: string;
84
- }): Promise<Work | null> {
85
- try {
86
- const response = await client.request<GetWorkResponse>(GET_WORK_BY_TOH, {
87
- toh,
88
- });
89
-
90
- if (!response.work) {
91
- return null;
92
- }
93
-
94
- return workFromGraphQL(response.work);
95
- } catch (error) {
96
- console.error('Error fetching translation metadata by toh:', error);
97
- return null;
98
- }
99
- }
@@ -1,55 +0,0 @@
1
- import type { GraphQLClient } from 'graphql-request';
2
- import { gql } from 'graphql-request';
3
- import type { Titles } from '@eightyfourthousand/data-access';
4
- import { titlesFromGraphQL } from '../mappers';
5
-
6
- const GET_WORK_TITLES = gql`
7
- query GetWorkWithTitles($uuid: ID!) {
8
- work(uuid: $uuid) {
9
- titles {
10
- uuid
11
- content
12
- language
13
- type
14
- }
15
- }
16
- }
17
- `;
18
-
19
- type GetWorkTitlesResponse = {
20
- work: {
21
- titles: Array<{
22
- uuid: string;
23
- content: string;
24
- language: string;
25
- type: string;
26
- }>;
27
- } | null;
28
- };
29
-
30
- /**
31
- * Get all titles for a work.
32
- */
33
- export async function getTranslationTitles({
34
- client,
35
- uuid,
36
- }: {
37
- client: GraphQLClient;
38
- uuid: string;
39
- }): Promise<Titles> {
40
- try {
41
- const response = await client.request<GetWorkTitlesResponse>(
42
- GET_WORK_TITLES,
43
- { uuid },
44
- );
45
-
46
- if (!response.work) {
47
- return [];
48
- }
49
-
50
- return titlesFromGraphQL(response.work.titles);
51
- } catch (error) {
52
- console.error('Error fetching translation titles:', error);
53
- return [];
54
- }
55
- }