@eightyfourthousand/data-access 2026.4.0 → 2026.4.2
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/index.js +18 -0
- package/index.js.map +1 -0
- package/lib/auth.d.ts +59 -0
- package/lib/auth.js +134 -0
- package/lib/auth.js.map +1 -0
- package/lib/bibliography.d.ts +9 -0
- package/lib/bibliography.js +30 -0
- package/lib/bibliography.js.map +1 -0
- package/lib/client-browser.d.ts +1 -0
- package/lib/client-browser.js +10 -0
- package/lib/client-browser.js.map +1 -0
- package/lib/client-server.d.ts +4 -0
- package/lib/client-server.js +19 -0
- package/lib/client-server.js.map +1 -0
- package/lib/client-ssr.d.ts +1 -0
- package/lib/client-ssr.js +23 -0
- package/lib/client-ssr.js.map +1 -0
- package/lib/client-token.d.ts +7 -0
- package/lib/client-token.js +21 -0
- package/lib/client-token.js.map +1 -0
- package/lib/feedback.d.ts +6 -0
- package/lib/feedback.js +45 -0
- package/lib/feedback.js.map +1 -0
- package/lib/folio.d.ts +11 -0
- package/lib/folio.js +31 -0
- package/lib/folio.js.map +1 -0
- package/lib/glossary/batch.d.ts +5 -0
- package/lib/glossary/batch.js +22 -0
- package/lib/glossary/batch.js.map +1 -0
- package/lib/glossary/index.js +5 -0
- package/lib/glossary/index.js.map +1 -0
- package/lib/glossary/instance.d.ts +10 -0
- package/lib/glossary/instance.js +28 -0
- package/lib/glossary/instance.js.map +1 -0
- package/lib/glossary/landing.d.ts +5 -0
- package/lib/glossary/landing.js +32 -0
- package/lib/glossary/landing.js.map +1 -0
- package/lib/glossary/pagination.d.ts +55 -0
- package/lib/glossary/pagination.js +254 -0
- package/lib/glossary/pagination.js.map +1 -0
- package/lib/imprint.d.ts +10 -0
- package/lib/imprint.js +23 -0
- package/lib/imprint.js.map +1 -0
- package/lib/library.d.ts +58 -0
- package/lib/library.js +118 -0
- package/lib/library.js.map +1 -0
- package/lib/local-storage.d.ts +10 -0
- package/lib/local-storage.js +25 -0
- package/lib/local-storage.js.map +1 -0
- package/lib/lookup-entity.d.ts +7 -0
- package/lib/lookup-entity.js +93 -0
- package/lib/lookup-entity.js.map +1 -0
- package/lib/panel-url.d.ts +10 -0
- package/lib/panel-url.js +23 -0
- package/lib/panel-url.js.map +1 -0
- package/lib/passage/batch.d.ts +17 -0
- package/lib/passage/batch.js +155 -0
- package/lib/passage/batch.js.map +1 -0
- package/lib/passage/index.js +6 -0
- package/lib/passage/index.js.map +1 -0
- package/lib/passage/pagination.d.ts +43 -0
- package/lib/passage/pagination.js +167 -0
- package/lib/passage/pagination.js.map +1 -0
- package/lib/passage/read.d.ts +15 -0
- package/lib/passage/read.js +59 -0
- package/lib/passage/read.js.map +1 -0
- package/lib/passage/replace-persistence.d.ts +46 -0
- package/lib/passage/replace-persistence.js +93 -0
- package/lib/passage/replace-persistence.js.map +1 -0
- package/lib/passage/save.d.ts +16 -0
- package/lib/passage/save.js +227 -0
- package/lib/passage/save.js.map +1 -0
- package/lib/proxy.d.ts +7 -0
- package/lib/proxy.js +45 -0
- package/lib/proxy.js.map +1 -0
- package/lib/publications.d.ts +86 -0
- package/lib/publications.js +223 -0
- package/lib/publications.js.map +1 -0
- package/lib/replace.d.ts +31 -0
- package/lib/replace.js +151 -0
- package/lib/replace.js.map +1 -0
- package/lib/storage.d.ts +7 -0
- package/lib/storage.js +10 -0
- package/lib/storage.js.map +1 -0
- package/lib/types/alignment.d.ts +18 -0
- package/lib/types/alignment.js +13 -0
- package/lib/types/alignment.js.map +1 -0
- package/lib/types/annotation/abbreviation.d.ts +3 -0
- package/lib/types/annotation/abbreviation.js +20 -0
- package/lib/types/annotation/abbreviation.js.map +1 -0
- package/lib/types/annotation/annotation-type.d.ts +31 -0
- package/lib/types/annotation/annotation-type.js +81 -0
- package/lib/types/annotation/annotation-type.js.map +1 -0
- package/lib/types/annotation/annotation.d.ts +142 -0
- package/lib/types/annotation/annotation.js +23 -0
- package/lib/types/annotation/annotation.js.map +1 -0
- package/lib/types/annotation/audio.d.ts +3 -0
- package/lib/types/annotation/audio.js +24 -0
- package/lib/types/annotation/audio.js.map +1 -0
- package/lib/types/annotation/blockquote.d.ts +3 -0
- package/lib/types/annotation/blockquote.js +8 -0
- package/lib/types/annotation/blockquote.js.map +1 -0
- package/lib/types/annotation/code.d.ts +3 -0
- package/lib/types/annotation/code.js +8 -0
- package/lib/types/annotation/code.js.map +1 -0
- package/lib/types/annotation/deprecated.d.ts +3 -0
- package/lib/types/annotation/deprecated.js +8 -0
- package/lib/types/annotation/deprecated.js.map +1 -0
- package/lib/types/annotation/end-note-link.d.ts +3 -0
- package/lib/types/annotation/end-note-link.js +23 -0
- package/lib/types/annotation/end-note-link.js.map +1 -0
- package/lib/types/annotation/export.d.ts +3 -0
- package/{src/lib/types/annotation/export.ts → lib/types/annotation/export.js} +34 -36
- package/lib/types/annotation/export.js.map +1 -0
- package/lib/types/annotation/glossary-instance.d.ts +3 -0
- package/lib/types/annotation/glossary-instance.js +23 -0
- package/lib/types/annotation/glossary-instance.js.map +1 -0
- package/lib/types/annotation/has-abbreviation.d.ts +3 -0
- package/lib/types/annotation/has-abbreviation.js +20 -0
- package/lib/types/annotation/has-abbreviation.js.map +1 -0
- package/lib/types/annotation/heading.d.ts +3 -0
- package/lib/types/annotation/heading.js +26 -0
- package/lib/types/annotation/heading.js.map +1 -0
- package/lib/types/annotation/image.d.ts +3 -0
- package/lib/types/annotation/image.js +20 -0
- package/lib/types/annotation/image.js.map +1 -0
- package/lib/types/annotation/indent.d.ts +3 -0
- package/lib/types/annotation/indent.js +8 -0
- package/lib/types/annotation/indent.js.map +1 -0
- package/lib/types/annotation/index.js +5 -0
- package/lib/types/annotation/index.js.map +1 -0
- package/lib/types/annotation/inline-title.d.ts +3 -0
- package/lib/types/annotation/inline-title.js +21 -0
- package/lib/types/annotation/inline-title.js.map +1 -0
- package/lib/types/annotation/internal-link.d.ts +3 -0
- package/lib/types/annotation/internal-link.js +62 -0
- package/lib/types/annotation/internal-link.js.map +1 -0
- package/lib/types/annotation/leading-space.d.ts +3 -0
- package/lib/types/annotation/leading-space.js +8 -0
- package/lib/types/annotation/leading-space.js.map +1 -0
- package/lib/types/annotation/line-group.d.ts +3 -0
- package/lib/types/annotation/line-group.js +8 -0
- package/lib/types/annotation/line-group.js.map +1 -0
- package/lib/types/annotation/line.d.ts +3 -0
- package/lib/types/annotation/line.js +8 -0
- package/lib/types/annotation/line.js.map +1 -0
- package/lib/types/annotation/link.d.ts +3 -0
- package/lib/types/annotation/link.js +27 -0
- package/lib/types/annotation/link.js.map +1 -0
- package/lib/types/annotation/list-item.d.ts +3 -0
- package/lib/types/annotation/list-item.js +8 -0
- package/lib/types/annotation/list-item.js.map +1 -0
- package/lib/types/annotation/list.d.ts +3 -0
- package/lib/types/annotation/list.js +31 -0
- package/lib/types/annotation/list.js.map +1 -0
- package/lib/types/annotation/mantra.d.ts +3 -0
- package/lib/types/annotation/mantra.js +21 -0
- package/lib/types/annotation/mantra.js.map +1 -0
- package/lib/types/annotation/mention.d.ts +3 -0
- package/lib/types/annotation/mention.js +50 -0
- package/lib/types/annotation/mention.js.map +1 -0
- package/lib/types/annotation/paragraph.d.ts +3 -0
- package/lib/types/annotation/paragraph.js +8 -0
- package/lib/types/annotation/paragraph.js.map +1 -0
- package/lib/types/annotation/quote.d.ts +3 -0
- package/lib/types/annotation/quote.js +21 -0
- package/lib/types/annotation/quote.js.map +1 -0
- package/lib/types/annotation/quoted.d.ts +3 -0
- package/lib/types/annotation/quoted.js +21 -0
- package/lib/types/annotation/quoted.js.map +1 -0
- package/lib/types/annotation/reference.d.ts +3 -0
- package/lib/types/annotation/reference.js +8 -0
- package/lib/types/annotation/reference.js.map +1 -0
- package/lib/types/annotation/span.d.ts +3 -0
- package/lib/types/annotation/span.js +29 -0
- package/lib/types/annotation/span.js.map +1 -0
- package/lib/types/annotation/table-body-data.d.ts +3 -0
- package/lib/types/annotation/table-body-data.js +8 -0
- package/lib/types/annotation/table-body-data.js.map +1 -0
- package/lib/types/annotation/table-body-header.d.ts +3 -0
- package/lib/types/annotation/table-body-header.js +8 -0
- package/lib/types/annotation/table-body-header.js.map +1 -0
- package/lib/types/annotation/table-body-row.d.ts +3 -0
- package/lib/types/annotation/table-body-row.js +8 -0
- package/lib/types/annotation/table-body-row.js.map +1 -0
- package/lib/types/annotation/table.d.ts +3 -0
- package/lib/types/annotation/table.js +8 -0
- package/lib/types/annotation/table.js.map +1 -0
- package/lib/types/annotation/trailer.d.ts +3 -0
- package/lib/types/annotation/trailer.js +8 -0
- package/lib/types/annotation/trailer.js.map +1 -0
- package/lib/types/annotation/transform.d.ts +6 -0
- package/lib/types/annotation/transform.js +109 -0
- package/lib/types/annotation/transform.js.map +1 -0
- package/lib/types/annotation/unknown.d.ts +3 -0
- package/lib/types/annotation/unknown.js +8 -0
- package/lib/types/annotation/unknown.js.map +1 -0
- package/lib/types/bibliography.d.ts +41 -0
- package/lib/types/bibliography.js +29 -0
- package/lib/types/bibliography.js.map +1 -0
- package/{src/lib/types/client.ts → lib/types/client.d.ts} +0 -1
- package/lib/types/client.js +2 -0
- package/lib/types/client.js.map +1 -0
- package/{src/lib/types/editor-content.ts → lib/types/editor-content.d.ts} +7 -11
- package/lib/types/editor-content.js +2 -0
- package/lib/types/editor-content.js.map +1 -0
- package/lib/types/folio.d.ts +17 -0
- package/lib/types/folio.js +11 -0
- package/lib/types/folio.js.map +1 -0
- package/lib/types/glossary-page.d.ts +48 -0
- package/lib/types/glossary-page.js +21 -0
- package/lib/types/glossary-page.js.map +1 -0
- package/lib/types/glossary.d.ts +76 -0
- package/lib/types/glossary.js +32 -0
- package/lib/types/glossary.js.map +1 -0
- package/lib/types/imprint.d.ts +78 -0
- package/lib/types/imprint.js +78 -0
- package/lib/types/imprint.js.map +1 -0
- package/lib/types/index.js +20 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/language.d.ts +9 -0
- package/lib/types/language.js +41 -0
- package/lib/types/language.js.map +1 -0
- package/lib/types/layout.d.ts +5 -0
- package/lib/types/layout.js +23 -0
- package/lib/types/layout.js.map +1 -0
- package/lib/types/library.d.ts +19 -0
- package/lib/types/library.js +8 -0
- package/lib/types/library.js.map +1 -0
- package/lib/types/passage.d.ts +73 -0
- package/lib/types/passage.js +123 -0
- package/lib/types/passage.js.map +1 -0
- package/lib/types/semver.js +2 -0
- package/lib/types/semver.js.map +1 -0
- package/lib/types/title.d.ts +21 -0
- package/lib/types/title.js +21 -0
- package/lib/types/title.js.map +1 -0
- package/lib/types/toh.js +2 -0
- package/lib/types/toh.js.map +1 -0
- package/{src/lib/types/translation.ts → lib/types/translation.d.ts} +5 -7
- package/lib/types/translation.js +2 -0
- package/lib/types/translation.js.map +1 -0
- package/{src/lib/types/user.ts → lib/types/user.d.ts} +2 -11
- package/lib/types/user.js +9 -0
- package/lib/types/user.js.map +1 -0
- package/lib/types/work.d.ts +37 -0
- package/lib/types/work.js +12 -0
- package/lib/types/work.js.map +1 -0
- package/lib/use-bookmark.d.ts +10 -0
- package/lib/use-bookmark.js +30 -0
- package/lib/use-bookmark.js.map +1 -0
- package/package.json +25 -3
- package/ssr.js +6 -0
- package/ssr.js.map +1 -0
- package/.babelrc +0 -12
- package/.eslintrc.json +0 -18
- package/README.md +0 -9
- package/jest.config.ts +0 -10
- package/project.json +0 -21
- package/src/lib/auth.ts +0 -203
- package/src/lib/bibliography.ts +0 -57
- package/src/lib/client-browser.ts +0 -12
- package/src/lib/client-server.ts +0 -30
- package/src/lib/client-ssr.ts +0 -24
- package/src/lib/client-token.ts +0 -24
- package/src/lib/feedback.ts +0 -71
- package/src/lib/folio.ts +0 -57
- package/src/lib/glossary/batch.ts +0 -35
- package/src/lib/glossary/instance.ts +0 -54
- package/src/lib/glossary/landing.ts +0 -50
- package/src/lib/glossary/pagination.ts +0 -471
- package/src/lib/imprint.ts +0 -42
- package/src/lib/library.ts +0 -209
- package/src/lib/local-storage.ts +0 -33
- package/src/lib/lookup-entity.ts +0 -122
- package/src/lib/panel-url.ts +0 -43
- package/src/lib/passage/batch.ts +0 -229
- package/src/lib/passage/pagination.ts +0 -277
- package/src/lib/passage/read.ts +0 -100
- package/src/lib/passage/replace-persistence.ts +0 -153
- package/src/lib/passage/save.ts +0 -324
- package/src/lib/proxy.ts +0 -68
- package/src/lib/publications.ts +0 -381
- package/src/lib/replace.spec.ts +0 -154
- package/src/lib/replace.ts +0 -244
- package/src/lib/storage.ts +0 -23
- package/src/lib/types/alignment.ts +0 -32
- package/src/lib/types/annotation/abbreviation.ts +0 -30
- package/src/lib/types/annotation/annotation-type.ts +0 -219
- package/src/lib/types/annotation/annotation.ts +0 -244
- package/src/lib/types/annotation/audio.ts +0 -33
- package/src/lib/types/annotation/blockquote.ts +0 -18
- package/src/lib/types/annotation/code.ts +0 -16
- package/src/lib/types/annotation/deprecated.ts +0 -18
- package/src/lib/types/annotation/end-note-link.ts +0 -35
- package/src/lib/types/annotation/glossary-instance.ts +0 -34
- package/src/lib/types/annotation/has-abbreviation.ts +0 -30
- package/src/lib/types/annotation/heading.ts +0 -37
- package/src/lib/types/annotation/image.ts +0 -29
- package/src/lib/types/annotation/indent.ts +0 -16
- package/src/lib/types/annotation/inline-title.ts +0 -34
- package/src/lib/types/annotation/internal-link.ts +0 -86
- package/src/lib/types/annotation/leading-space.ts +0 -18
- package/src/lib/types/annotation/line-group.ts +0 -18
- package/src/lib/types/annotation/line.ts +0 -16
- package/src/lib/types/annotation/link.ts +0 -38
- package/src/lib/types/annotation/list-item.ts +0 -16
- package/src/lib/types/annotation/list.ts +0 -43
- package/src/lib/types/annotation/mantra.ts +0 -31
- package/src/lib/types/annotation/mention.ts +0 -64
- package/src/lib/types/annotation/paragraph.ts +0 -18
- package/src/lib/types/annotation/quote.ts +0 -30
- package/src/lib/types/annotation/quoted.ts +0 -30
- package/src/lib/types/annotation/reference.ts +0 -18
- package/src/lib/types/annotation/span.ts +0 -39
- package/src/lib/types/annotation/table-body-data.ts +0 -18
- package/src/lib/types/annotation/table-body-header.ts +0 -18
- package/src/lib/types/annotation/table-body-row.ts +0 -18
- package/src/lib/types/annotation/table.ts +0 -16
- package/src/lib/types/annotation/trailer.ts +0 -16
- package/src/lib/types/annotation/transform.ts +0 -140
- package/src/lib/types/annotation/unknown.ts +0 -16
- package/src/lib/types/bibliography.ts +0 -86
- package/src/lib/types/folio.ts +0 -28
- package/src/lib/types/glossary-page.ts +0 -86
- package/src/lib/types/glossary.ts +0 -115
- package/src/lib/types/imprint.ts +0 -159
- package/src/lib/types/language.ts +0 -64
- package/src/lib/types/layout.ts +0 -37
- package/src/lib/types/library.ts +0 -29
- package/src/lib/types/passage.ts +0 -220
- package/src/lib/types/title.ts +0 -47
- package/src/lib/types/work.ts +0 -38
- package/src/lib/use-bookmark.ts +0 -45
- package/tsconfig.json +0 -20
- package/tsconfig.lib.json +0 -26
- package/tsconfig.spec.json +0 -22
- /package/{src/index.ts → index.d.ts} +0 -0
- /package/{src/lib/glossary/index.ts → lib/glossary/index.d.ts} +0 -0
- /package/{src/lib/passage/index.ts → lib/passage/index.d.ts} +0 -0
- /package/{src/lib/types/annotation/index.ts → lib/types/annotation/index.d.ts} +0 -0
- /package/{src/lib/types/index.ts → lib/types/index.d.ts} +0 -0
- /package/{src/lib/types/semver.ts → lib/types/semver.d.ts} +0 -0
- /package/{src/lib/types/toh.ts → lib/types/toh.d.ts} +0 -0
- /package/{src/ssr.ts → ssr.d.ts} +0 -0
package/src/lib/publications.ts
DELETED
|
@@ -1,381 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BodyItemType,
|
|
3
|
-
DataClient,
|
|
4
|
-
Title,
|
|
5
|
-
TitlesDTO,
|
|
6
|
-
WorkDTO,
|
|
7
|
-
titlesFromDTO,
|
|
8
|
-
workFromDTO,
|
|
9
|
-
passagesPageFromDTO,
|
|
10
|
-
PassagesPageDTO,
|
|
11
|
-
PassagesPage,
|
|
12
|
-
PaginationDirection,
|
|
13
|
-
passagesPageAroundFromDTO,
|
|
14
|
-
PassagesPageAroundDTO,
|
|
15
|
-
Work,
|
|
16
|
-
} from './types';
|
|
17
|
-
|
|
18
|
-
type WorksPageInfo = {
|
|
19
|
-
nextCursor: string | null;
|
|
20
|
-
prevCursor: string | null;
|
|
21
|
-
hasMoreAfter: boolean;
|
|
22
|
-
hasMoreBefore: boolean;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export type WorksPage = {
|
|
26
|
-
items: Work[];
|
|
27
|
-
pageInfo: WorksPageInfo;
|
|
28
|
-
totalCount: number;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export const getTranslationUuids = async ({
|
|
32
|
-
client,
|
|
33
|
-
}: {
|
|
34
|
-
client: DataClient;
|
|
35
|
-
}): Promise<string[]> => {
|
|
36
|
-
const { data } = await client.rpc('get_static_translation_uuids');
|
|
37
|
-
return data?.map(({ uuid }: { uuid: string }) => uuid) || [];
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export const getWorkUuidByToh = async ({
|
|
41
|
-
client,
|
|
42
|
-
toh,
|
|
43
|
-
}: {
|
|
44
|
-
client: DataClient;
|
|
45
|
-
toh: string;
|
|
46
|
-
}): Promise<string | null> => {
|
|
47
|
-
const { data, error } = await client
|
|
48
|
-
.from('work_toh')
|
|
49
|
-
.select('work_uuid')
|
|
50
|
-
.eq('toh_clean', toh)
|
|
51
|
-
.single();
|
|
52
|
-
|
|
53
|
-
if (error || !data) {
|
|
54
|
-
if (error) {
|
|
55
|
-
console.error('Error fetching work UUID by TOH:', error);
|
|
56
|
-
}
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return data.work_uuid ?? null;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export const getTranslationPassages = async ({
|
|
64
|
-
client,
|
|
65
|
-
uuid,
|
|
66
|
-
type,
|
|
67
|
-
cursor,
|
|
68
|
-
maxPassages,
|
|
69
|
-
maxCharacters,
|
|
70
|
-
direction,
|
|
71
|
-
}: {
|
|
72
|
-
client: DataClient;
|
|
73
|
-
uuid: string;
|
|
74
|
-
type?: BodyItemType;
|
|
75
|
-
cursor?: string;
|
|
76
|
-
maxPassages?: number;
|
|
77
|
-
maxCharacters?: number;
|
|
78
|
-
direction?: PaginationDirection;
|
|
79
|
-
}): Promise<PassagesPage> => {
|
|
80
|
-
const { data, error } = await client.rpc('get_passages_page', {
|
|
81
|
-
uuid_input: uuid,
|
|
82
|
-
passage_type_input: type,
|
|
83
|
-
cursor,
|
|
84
|
-
max_passages: maxPassages,
|
|
85
|
-
char_budget: maxCharacters,
|
|
86
|
-
direction,
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
if (error) {
|
|
90
|
-
console.error('Error fetching translation passages:', error);
|
|
91
|
-
return {
|
|
92
|
-
hasMoreAfter: false,
|
|
93
|
-
hasMoreBefore: false,
|
|
94
|
-
passages: [],
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return passagesPageFromDTO(direction || 'forward', data as PassagesPageDTO);
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
export const getTranslationPassagesAround = async ({
|
|
102
|
-
client,
|
|
103
|
-
uuid,
|
|
104
|
-
passageUuid,
|
|
105
|
-
type,
|
|
106
|
-
maxPassages,
|
|
107
|
-
maxCharacters,
|
|
108
|
-
}: {
|
|
109
|
-
client: DataClient;
|
|
110
|
-
uuid: string;
|
|
111
|
-
passageUuid: string;
|
|
112
|
-
type?: BodyItemType;
|
|
113
|
-
maxPassages?: number;
|
|
114
|
-
maxCharacters?: number;
|
|
115
|
-
}): Promise<PassagesPage> => {
|
|
116
|
-
const { data, error } = await client.rpc('get_passages_page_around', {
|
|
117
|
-
uuid_input: uuid,
|
|
118
|
-
cursor: passageUuid,
|
|
119
|
-
passage_type_input: type,
|
|
120
|
-
max_passages: maxPassages,
|
|
121
|
-
char_budget: maxCharacters,
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
if (error) {
|
|
125
|
-
console.error('Error fetching translation passages around:', error);
|
|
126
|
-
return {
|
|
127
|
-
hasMoreAfter: false,
|
|
128
|
-
hasMoreBefore: false,
|
|
129
|
-
passages: [],
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return passagesPageAroundFromDTO(data as PassagesPageAroundDTO);
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
export const getTranslationTitles = async ({
|
|
137
|
-
client,
|
|
138
|
-
uuid,
|
|
139
|
-
}: {
|
|
140
|
-
client: DataClient;
|
|
141
|
-
uuid: string;
|
|
142
|
-
}) => {
|
|
143
|
-
const { data } = await client.rpc('get_work_titles', {
|
|
144
|
-
work_uuid_input: uuid,
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
return titlesFromDTO(data as TitlesDTO);
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
export const getWorkTitles = async ({
|
|
151
|
-
client,
|
|
152
|
-
uuid,
|
|
153
|
-
}: {
|
|
154
|
-
client: DataClient;
|
|
155
|
-
uuid: string;
|
|
156
|
-
}): Promise<Title[]> => {
|
|
157
|
-
const { data, error } = await client.rpc('get_work_titles', {
|
|
158
|
-
work_uuid_input: uuid,
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
if (error) {
|
|
162
|
-
console.error('Error fetching work titles:', error);
|
|
163
|
-
return [];
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return titlesFromDTO(data as TitlesDTO);
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
export const getWorkTitlesByUuids = async ({
|
|
170
|
-
client,
|
|
171
|
-
uuids,
|
|
172
|
-
}: {
|
|
173
|
-
client: DataClient;
|
|
174
|
-
uuids: readonly string[];
|
|
175
|
-
}): Promise<Map<string, string>> => {
|
|
176
|
-
const titlesByUuid = new Map<string, string>();
|
|
177
|
-
if (uuids.length === 0) return titlesByUuid;
|
|
178
|
-
|
|
179
|
-
const { data, error } = await client
|
|
180
|
-
.from('works')
|
|
181
|
-
.select('uuid, title')
|
|
182
|
-
.in('uuid', uuids as string[]);
|
|
183
|
-
|
|
184
|
-
if (error) {
|
|
185
|
-
console.error('Error batch loading work titles:', error);
|
|
186
|
-
return titlesByUuid;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
for (const work of data ?? []) {
|
|
190
|
-
if (work.title) {
|
|
191
|
-
titlesByUuid.set(work.uuid, work.title);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return titlesByUuid;
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
export const getTranslationMetadataByUuid = async ({
|
|
199
|
-
client,
|
|
200
|
-
uuid,
|
|
201
|
-
}: {
|
|
202
|
-
client: DataClient;
|
|
203
|
-
uuid: string;
|
|
204
|
-
}) => {
|
|
205
|
-
const { data, error } = await client
|
|
206
|
-
.from('works')
|
|
207
|
-
.select(
|
|
208
|
-
`
|
|
209
|
-
uuid,
|
|
210
|
-
title,
|
|
211
|
-
description,
|
|
212
|
-
tohs:work_toh!inner(toh:toh_clean),
|
|
213
|
-
publicationDate,
|
|
214
|
-
publicationVersion,
|
|
215
|
-
pages:source_pages,
|
|
216
|
-
restriction,
|
|
217
|
-
breadcrumb
|
|
218
|
-
`,
|
|
219
|
-
)
|
|
220
|
-
.eq('uuid', uuid)
|
|
221
|
-
.single();
|
|
222
|
-
|
|
223
|
-
if (error) {
|
|
224
|
-
throw new Error(
|
|
225
|
-
`Error fetching translation metadata by UUID: ${error.message}`,
|
|
226
|
-
);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
return workFromDTO(data as WorkDTO);
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
export const getTranslationMetadataByToh = async ({
|
|
233
|
-
client,
|
|
234
|
-
toh,
|
|
235
|
-
}: {
|
|
236
|
-
client: DataClient;
|
|
237
|
-
toh: string;
|
|
238
|
-
}) => {
|
|
239
|
-
const { data, error } = await client
|
|
240
|
-
.from('work_toh')
|
|
241
|
-
.select(
|
|
242
|
-
`
|
|
243
|
-
work_uuid,
|
|
244
|
-
works!inner(
|
|
245
|
-
uuid,
|
|
246
|
-
title,
|
|
247
|
-
description,
|
|
248
|
-
tohs:work_toh!inner(toh:toh_clean),
|
|
249
|
-
publicationDate,
|
|
250
|
-
publicationVersion,
|
|
251
|
-
pages:source_pages,
|
|
252
|
-
restriction,
|
|
253
|
-
breadcrumb
|
|
254
|
-
)
|
|
255
|
-
`,
|
|
256
|
-
)
|
|
257
|
-
.eq('toh_clean', toh)
|
|
258
|
-
.single();
|
|
259
|
-
|
|
260
|
-
// Extract the work data from the joined result
|
|
261
|
-
const workData = data?.works as WorkDTO | undefined;
|
|
262
|
-
if (error || !workData) {
|
|
263
|
-
console.error('Error fetching translation metadata by TOH:', error);
|
|
264
|
-
return null;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
return workFromDTO(workData);
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
export const getTranslationsMetadata = async ({
|
|
271
|
-
client,
|
|
272
|
-
}: {
|
|
273
|
-
client: DataClient;
|
|
274
|
-
}): Promise<Work[]> => {
|
|
275
|
-
const { data, error } = await client
|
|
276
|
-
.from('works')
|
|
277
|
-
.select(
|
|
278
|
-
`
|
|
279
|
-
uuid,
|
|
280
|
-
title,
|
|
281
|
-
description,
|
|
282
|
-
tohs:work_toh!inner(toh:toh_clean),
|
|
283
|
-
publicationDate,
|
|
284
|
-
publicationVersion,
|
|
285
|
-
pages:source_pages,
|
|
286
|
-
restriction,
|
|
287
|
-
breadcrumb
|
|
288
|
-
`,
|
|
289
|
-
)
|
|
290
|
-
.not('toh', 'like', 'toh00%');
|
|
291
|
-
if (error) {
|
|
292
|
-
console.error('Error fetching translations metadata:', error);
|
|
293
|
-
return [];
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
const dto = data as WorkDTO[];
|
|
297
|
-
return dto?.map((work) => workFromDTO(work as WorkDTO)) || [];
|
|
298
|
-
};
|
|
299
|
-
|
|
300
|
-
export const getWorksPage = async ({
|
|
301
|
-
client,
|
|
302
|
-
cursor,
|
|
303
|
-
limit = 50,
|
|
304
|
-
maxPages,
|
|
305
|
-
}: {
|
|
306
|
-
client: DataClient;
|
|
307
|
-
cursor?: string;
|
|
308
|
-
limit?: number;
|
|
309
|
-
maxPages?: number;
|
|
310
|
-
}): Promise<WorksPage> => {
|
|
311
|
-
const clampedLimit = Math.min(limit, 200);
|
|
312
|
-
|
|
313
|
-
let query = client
|
|
314
|
-
.from('works')
|
|
315
|
-
.select(
|
|
316
|
-
`
|
|
317
|
-
uuid,
|
|
318
|
-
title,
|
|
319
|
-
description,
|
|
320
|
-
tohs:work_toh!inner(toh:toh_clean),
|
|
321
|
-
publicationDate,
|
|
322
|
-
publicationVersion,
|
|
323
|
-
pages:source_pages,
|
|
324
|
-
restriction,
|
|
325
|
-
breadcrumb
|
|
326
|
-
`,
|
|
327
|
-
{ count: 'exact' },
|
|
328
|
-
)
|
|
329
|
-
.not('toh', 'like', 'toh00%')
|
|
330
|
-
.order('title', { ascending: true })
|
|
331
|
-
.limit(clampedLimit + 1);
|
|
332
|
-
|
|
333
|
-
if (maxPages) {
|
|
334
|
-
query = query.lt('source_pages', maxPages);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
if (cursor) {
|
|
338
|
-
const { data: cursorWork } = await client
|
|
339
|
-
.from('works')
|
|
340
|
-
.select('title')
|
|
341
|
-
.eq('uuid', cursor)
|
|
342
|
-
.single();
|
|
343
|
-
|
|
344
|
-
if (cursorWork) {
|
|
345
|
-
query = query.gt('title', cursorWork.title);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
const { data, error, count } = await query;
|
|
350
|
-
|
|
351
|
-
if (error) {
|
|
352
|
-
console.error('Error fetching works:', error);
|
|
353
|
-
return {
|
|
354
|
-
items: [],
|
|
355
|
-
pageInfo: {
|
|
356
|
-
nextCursor: null,
|
|
357
|
-
prevCursor: null,
|
|
358
|
-
hasMoreAfter: false,
|
|
359
|
-
hasMoreBefore: false,
|
|
360
|
-
},
|
|
361
|
-
totalCount: 0,
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
const hasMoreAfter = (data ?? []).length > clampedLimit;
|
|
366
|
-
const items = hasMoreAfter
|
|
367
|
-
? (data ?? []).slice(0, clampedLimit)
|
|
368
|
-
: (data ?? []);
|
|
369
|
-
const works = items.map((dto) => workFromDTO(dto as WorkDTO));
|
|
370
|
-
|
|
371
|
-
return {
|
|
372
|
-
items: works,
|
|
373
|
-
pageInfo: {
|
|
374
|
-
nextCursor: hasMoreAfter ? (works[works.length - 1]?.uuid ?? null) : null,
|
|
375
|
-
prevCursor: cursor ?? null,
|
|
376
|
-
hasMoreAfter,
|
|
377
|
-
hasMoreBefore: Boolean(cursor),
|
|
378
|
-
},
|
|
379
|
-
totalCount: count ?? 0,
|
|
380
|
-
};
|
|
381
|
-
};
|
package/src/lib/replace.spec.ts
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import type { Annotation, Passage } from './types';
|
|
2
|
-
import {
|
|
3
|
-
findLiteralOccurrences,
|
|
4
|
-
getPassageOccurrences,
|
|
5
|
-
replacePassageText,
|
|
6
|
-
} from './replace';
|
|
7
|
-
|
|
8
|
-
const createAnnotation = ({
|
|
9
|
-
end,
|
|
10
|
-
start,
|
|
11
|
-
uuid,
|
|
12
|
-
}: {
|
|
13
|
-
end: number;
|
|
14
|
-
start: number;
|
|
15
|
-
uuid: string;
|
|
16
|
-
}): Annotation => ({
|
|
17
|
-
end,
|
|
18
|
-
start,
|
|
19
|
-
passageUuid: 'passage-1',
|
|
20
|
-
type: 'paragraph',
|
|
21
|
-
uuid,
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
const createPassage = (
|
|
25
|
-
content: string,
|
|
26
|
-
annotations: Annotation[] = [],
|
|
27
|
-
): Passage => ({
|
|
28
|
-
annotations,
|
|
29
|
-
content,
|
|
30
|
-
label: '1.1',
|
|
31
|
-
sort: 1,
|
|
32
|
-
type: 'translation',
|
|
33
|
-
uuid: 'passage-1',
|
|
34
|
-
workUuid: 'work-1',
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe('findLiteralOccurrences', () => {
|
|
38
|
-
it('returns non-overlapping matches in order', () => {
|
|
39
|
-
expect(findLiteralOccurrences('aba aba aba', 'aba')).toEqual([
|
|
40
|
-
{ start: 0, end: 3 },
|
|
41
|
-
{ start: 4, end: 7 },
|
|
42
|
-
{ start: 8, end: 11 },
|
|
43
|
-
]);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('returns no matches for an empty search string', () => {
|
|
47
|
-
expect(findLiteralOccurrences('abc', '')).toEqual([]);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
describe('getPassageOccurrences', () => {
|
|
52
|
-
it('flattens matches across passages with stable indices', () => {
|
|
53
|
-
expect(
|
|
54
|
-
getPassageOccurrences(
|
|
55
|
-
[
|
|
56
|
-
{ uuid: 'p1', content: 'foo foo' },
|
|
57
|
-
{ uuid: 'p2', content: 'foo' },
|
|
58
|
-
],
|
|
59
|
-
'foo',
|
|
60
|
-
),
|
|
61
|
-
).toEqual([
|
|
62
|
-
{ passageUuid: 'p1', start: 0, end: 3, index: 0, passageOccurrenceIndex: 0 },
|
|
63
|
-
{ passageUuid: 'p1', start: 4, end: 7, index: 1, passageOccurrenceIndex: 1 },
|
|
64
|
-
{ passageUuid: 'p2', start: 0, end: 3, index: 2, passageOccurrenceIndex: 0 },
|
|
65
|
-
]);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe('replacePassageText', () => {
|
|
70
|
-
it('replaces one indexed occurrence inside a single passage', () => {
|
|
71
|
-
const result = replacePassageText({
|
|
72
|
-
passage: createPassage('foo foo foo'),
|
|
73
|
-
searchText: 'foo',
|
|
74
|
-
replaceText: 'bar',
|
|
75
|
-
occurrenceIndex: 1,
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
expect(result.passage.content).toBe('foo bar foo');
|
|
79
|
-
expect(result.replacementsApplied).toBe(1);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('replaces all occurrences when no occurrence index is provided', () => {
|
|
83
|
-
const result = replacePassageText({
|
|
84
|
-
passage: createPassage('foo foo'),
|
|
85
|
-
searchText: 'foo',
|
|
86
|
-
replaceText: 'x',
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
expect(result.passage.content).toBe('x x');
|
|
90
|
-
expect(result.replacementsApplied).toBe(2);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('preserves an annotation spanning across replaced text', () => {
|
|
94
|
-
const result = replacePassageText({
|
|
95
|
-
passage: createPassage('0123456789', [
|
|
96
|
-
createAnnotation({ uuid: 'a1', start: 1, end: 9 }),
|
|
97
|
-
]),
|
|
98
|
-
searchText: '345',
|
|
99
|
-
replaceText: 'XX',
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
expect(result.passage.annotations[0]).toMatchObject({ start: 1, end: 8 });
|
|
103
|
-
expect(result.updatedAnnotationCount).toBe(1);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('clamps an annotation that overlaps the left edge of the replaced range', () => {
|
|
107
|
-
const result = replacePassageText({
|
|
108
|
-
passage: createPassage('0123456789', [
|
|
109
|
-
createAnnotation({ uuid: 'a1', start: 2, end: 4 }),
|
|
110
|
-
]),
|
|
111
|
-
searchText: '345',
|
|
112
|
-
replaceText: 'XYZ',
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
expect(result.passage.annotations[0]).toMatchObject({ start: 2, end: 6 });
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('shifts annotations that occur entirely after the replaced text', () => {
|
|
119
|
-
const result = replacePassageText({
|
|
120
|
-
passage: createPassage('0123456789', [
|
|
121
|
-
createAnnotation({ uuid: 'a1', start: 8, end: 10 }),
|
|
122
|
-
]),
|
|
123
|
-
searchText: '34',
|
|
124
|
-
replaceText: 'ABCDE',
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
expect(result.passage.annotations[0]).toMatchObject({ start: 11, end: 13 });
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('deletes an annotation that is fully removed by an empty replacement', () => {
|
|
131
|
-
const result = replacePassageText({
|
|
132
|
-
passage: createPassage('abc', [
|
|
133
|
-
createAnnotation({ uuid: 'a1', start: 0, end: 3 }),
|
|
134
|
-
]),
|
|
135
|
-
searchText: 'abc',
|
|
136
|
-
replaceText: '',
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
expect(result.passage.annotations).toEqual([]);
|
|
140
|
-
expect(result.deletedAnnotationCount).toBe(1);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it('maps an annotation contained within the replaced range onto the inserted replacement', () => {
|
|
144
|
-
const result = replacePassageText({
|
|
145
|
-
passage: createPassage('abc def ghi', [
|
|
146
|
-
createAnnotation({ uuid: 'a1', start: 4, end: 7 }),
|
|
147
|
-
]),
|
|
148
|
-
searchText: 'def',
|
|
149
|
-
replaceText: 'uvwxyz',
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
expect(result.passage.annotations[0]).toMatchObject({ start: 4, end: 10 });
|
|
153
|
-
});
|
|
154
|
-
});
|