📄 src/models/generated-src/workers/ExternalIdCrosswalkWorker.ts
D-OPEN SOVEREIGN
1// AUTO-GENERATED by @the_library/public/models schemaGenerator
2import type { Lang } from "../../interfaces.ts";
3import type { SidecarSet } from "../../worker/libs/initialLoad.ts";
4import { encodePID } from "../../pid.ts";
5
6const derivedToInstance = new Map<string, { wireId: number; instanceIndex: number }>();
7const isniToEntity = new Map<string, { wireId: number }>();
8const orcidToEntity = new Map<string, { wireId: number }>();
9const lccToEntity = new Map<string, { wireId: number }>();
10const ddcToEntity = new Map<string, { wireId: number }>();
11const udcToEntity = new Map<string, { wireId: number }>();
12const clcToEntity = new Map<string, { wireId: number }>();
13const bbkToEntity = new Map<string, { wireId: number }>();
14const tlcToEntity = new Map<string, { wireId: number }>();
15const ccToEntity = new Map<string, { wireId: number }>();
16const isbnToInstance = new Map<string, { wireId: number; instanceIndex: number }>();
17
18export function processSidecarSets(sets: SidecarSet[]) {
19 for (const set of sets) {
20 const lang = set.lang;
21
22 if (set.objectType === 0) {
23 const slim = set.slim;
24 const ext = set.extended;
25
26 // Read parent standards arrays
27
28
29 for (const [id, rowIndex] of set.idIndex) {
30 // Populate parent standards
31
32
33
34 const instances = ext?.instances?.[rowIndex];
35 if (instances) {
36 // 1. Gather all source PIDs for this record
37 const sourcePIDs: string[] = [`${encodePID('BK', id)}`];
38
39
40
41 // Add instance-level Mode S
42 for (let i = 0; i < instances.length; i++) {
43
44 if (instances[i]['isbn']) sourcePIDs.push(`isbn:${instances[i]['isbn']}`);
45
46 }
47
48 // 2. Emit mappings
49 for (let i = 0; i < instances.length; i++) {
50
51 const isbnVal = instances[i]['isbn'];
52 if (isbnVal) {
53 isbnToInstance.set(`${lang}:${isbnVal}`, { wireId: id, instanceIndex: i });
54 }
55
56
57 const identityParts = [instances[i]['language']];
58 if (identityParts.every(p => p != null && p !== "")) {
59 const disc = identityParts.map(p => encodeURIComponent(String(p))).join(':');
60 for (const src of sourcePIDs) {
61 const sfcuid = `DL:C:DERIVED:${src}:${disc}`;
62 derivedToInstance.set(`${lang}:${sfcuid}`, { wireId: id, instanceIndex: i });
63 }
64 }
65 }
66 }
67
68 }
69 }
70
71 if (set.objectType === 1) {
72 const slim = set.slim;
73 const ext = set.extended;
74
75 // Read parent standards arrays
76 const isniCol = slim?.columns.get('isniIds') || ext?.columns.get('isniIds');
77 const orcidCol = slim?.columns.get('orcidIds') || ext?.columns.get('orcidIds');
78
79 for (const [id, rowIndex] of set.idIndex) {
80 // Populate parent standards
81
82 if (isniCol && isniCol[rowIndex]) {
83 isniToEntity.set(`${lang}:${isniCol[rowIndex]}`, { wireId: id });
84 }
85
86 if (orcidCol && orcidCol[rowIndex]) {
87 orcidToEntity.set(`${lang}:${orcidCol[rowIndex]}`, { wireId: id });
88 }
89
90
91
92 }
93 }
94
95 if (set.objectType === 2) {
96 const slim = set.slim;
97 const ext = set.extended;
98
99 // Read parent standards arrays
100 const lccCol = slim?.columns.get('lccNotations') || ext?.columns.get('lccNotations');
101 const ddcCol = slim?.columns.get('ddcNotations') || ext?.columns.get('ddcNotations');
102 const udcCol = slim?.columns.get('udcNotations') || ext?.columns.get('udcNotations');
103 const clcCol = slim?.columns.get('clcNotations') || ext?.columns.get('clcNotations');
104 const bbkCol = slim?.columns.get('bbkNotations') || ext?.columns.get('bbkNotations');
105 const tlcCol = slim?.columns.get('tlcNotations') || ext?.columns.get('tlcNotations');
106 const ccCol = slim?.columns.get('ccNotations') || ext?.columns.get('ccNotations');
107
108 for (const [id, rowIndex] of set.idIndex) {
109 // Populate parent standards
110
111 if (lccCol && lccCol[rowIndex]) {
112 lccToEntity.set(`${lang}:${lccCol[rowIndex]}`, { wireId: id });
113 }
114
115 if (ddcCol && ddcCol[rowIndex]) {
116 ddcToEntity.set(`${lang}:${ddcCol[rowIndex]}`, { wireId: id });
117 }
118
119 if (udcCol && udcCol[rowIndex]) {
120 udcToEntity.set(`${lang}:${udcCol[rowIndex]}`, { wireId: id });
121 }
122
123 if (clcCol && clcCol[rowIndex]) {
124 clcToEntity.set(`${lang}:${clcCol[rowIndex]}`, { wireId: id });
125 }
126
127 if (bbkCol && bbkCol[rowIndex]) {
128 bbkToEntity.set(`${lang}:${bbkCol[rowIndex]}`, { wireId: id });
129 }
130
131 if (tlcCol && tlcCol[rowIndex]) {
132 tlcToEntity.set(`${lang}:${tlcCol[rowIndex]}`, { wireId: id });
133 }
134
135 if (ccCol && ccCol[rowIndex]) {
136 ccToEntity.set(`${lang}:${ccCol[rowIndex]}`, { wireId: id });
137 }
138
139
140
141 }
142 }
143 }
144}
145
146self.onmessage = async (e: MessageEvent) => {
147 const { cmd, payload, msgId } = e.data;
148
149 if (cmd === 'init_crosswalk' || cmd === 'load_lang_crosswalk') {
150 const sets = payload.sidecars as SidecarSet[];
151 processSidecarSets(sets);
152 self.postMessage({ msgId, status: 'registered' });
153 } else if (cmd === 'resolve_derived') {
154 const { sfcuid, lang } = payload;
155 const result = derivedToInstance.get(`${lang}:${sfcuid}`);
156 self.postMessage({ msgId, result: result || null });
157 } else if (cmd === 'resolve_standard') {
158 const { standardId, value, lang } = payload;
159 const key = `${lang}:${value}`;
160 let result: any = null;
161 switch (standardId) {
162 case 'isni': result = isniToEntity.get(key) || null; break;
163 case 'orcid': result = orcidToEntity.get(key) || null; break;
164 case 'lcc': result = lccToEntity.get(key) || null; break;
165 case 'ddc': result = ddcToEntity.get(key) || null; break;
166 case 'udc': result = udcToEntity.get(key) || null; break;
167 case 'clc': result = clcToEntity.get(key) || null; break;
168 case 'bbk': result = bbkToEntity.get(key) || null; break;
169 case 'tlc': result = tlcToEntity.get(key) || null; break;
170 case 'cc': result = ccToEntity.get(key) || null; break;
171 case 'isbn': result = isbnToInstance.get(key) || null; break;
172 }
173 self.postMessage({ msgId, result });
174 }
175};
176