UNPKG

6.5 kBJavaScriptView Raw
1
2
3/* eslint-disable global-require */
4
5const factory = require('@graphy/core.data.factory');
6
7const memoize = (s_package) => {
8 delete graphy[s_package];
9 return graphy[s_package] = require('@graphy/'+s_package);
10};
11
12
13
14// ttl package
15const ttl = {
16
17 // read ttl
18 get read() {
19 // memoize
20 delete graphy.content.ttl.read;
21 return (graphy.content.ttl.read = require('@graphy/content.ttl.read'));
22 },
23
24 // write ttl
25 get write() {
26 // memoize
27 delete graphy.content.ttl.write;
28 return (graphy.content.ttl.write = require('@graphy/content.ttl.write'));
29 },
30
31 // scribe ttl
32 get scribe() {
33 // memoize
34 delete graphy.content.ttl.scribe;
35 return (graphy.content.ttl.scribe = require('@graphy/content.ttl.scribe'));
36 },
37
38}; // trig package
39const trig = {
40
41 // read trig
42 get read() {
43 // memoize
44 delete graphy.content.trig.read;
45 return (graphy.content.trig.read = require('@graphy/content.trig.read'));
46 },
47
48 // write trig
49 get write() {
50 // memoize
51 delete graphy.content.trig.write;
52 return (graphy.content.trig.write = require('@graphy/content.trig.write'));
53 },
54
55 // scribe trig
56 get scribe() {
57 // memoize
58 delete graphy.content.trig.scribe;
59 return (graphy.content.trig.scribe = require('@graphy/content.trig.scribe'));
60 },
61
62}; // nt package
63const nt = {
64
65 // read nt
66 get read() {
67 // memoize
68 delete graphy.content.nt.read;
69 return (graphy.content.nt.read = require('@graphy/content.nt.read'));
70 },
71
72 // write nt
73 get write() {
74 // memoize
75 delete graphy.content.nt.write;
76 return (graphy.content.nt.write = require('@graphy/content.nt.write'));
77 },
78
79 // scribe nt
80 get scribe() {
81 // memoize
82 delete graphy.content.nt.scribe;
83 return (graphy.content.nt.scribe = require('@graphy/content.nt.scribe'));
84 },
85
86 // scan nt
87 get scan() {
88 // memoize
89 delete graphy.content.nt.scan;
90 return (graphy.content.nt.scan = require('@graphy/content.nt.scan'));
91 },
92
93}; // nq package
94const nq = {
95
96 // read nq
97 get read() {
98 // memoize
99 delete graphy.content.nq.read;
100 return (graphy.content.nq.read = require('@graphy/content.nq.read'));
101 },
102
103 // write nq
104 get write() {
105 // memoize
106 delete graphy.content.nq.write;
107 return (graphy.content.nq.write = require('@graphy/content.nq.write'));
108 },
109
110 // scribe nq
111 get scribe() {
112 // memoize
113 delete graphy.content.nq.scribe;
114 return (graphy.content.nq.scribe = require('@graphy/content.nq.scribe'));
115 },
116
117 // scan nq
118 get scan() {
119 // memoize
120 delete graphy.content.nq.scan;
121 return (graphy.content.nq.scan = require('@graphy/content.nq.scan'));
122 },
123
124}; // xml package
125const xml = {
126
127 // scribe xml
128 get scribe() {
129 // memoize
130 delete graphy.content.xml.scribe;
131 return (graphy.content.xml.scribe = require('@graphy/content.xml.scribe'));
132 },
133
134};
135
136
137
138// // SPARQL Results package
139// const sparql_results = {
140// // deserialize sparql_results input
141// get deserializer() {
142// // memoize
143// delete sparql_results.deserializer;
144// return (sparql_results.deserializer = require('../sparql-results/deserializer.js'));
145// },
146// };
147
148
149const H_CONTENT_MIMES = {
150 'text/turtle': ttl,
151 'application/trig': trig,
152 'application/n-triples': nt,
153 'application/n-quads': nq,
154 'application/rdf+xml': xml,
155// 'application/sparql-results+json': sparql_results,
156};
157
158const H_CONTENT_TAGS = {
159 nt,
160 ntriples: nt,
161 'n-triples': nt,
162 nq,
163 nquads: nq,
164 'n-quads': nq,
165 ttl,
166 turtle: ttl,
167 trig,
168 xml,
169 'rdf-xml': xml,
170 'rdf/xml': xml,
171// 'sparql-results': sparql_results,
172};
173
174
175
176const R_CONTENT_TYPE = /^((?:application|text)\/[^\0-\x20()<>@,;:\\"\/[\]?.=]+)(;.+)*$/i;
177
178const graphy = module.exports = Object.assign({
179
180 VERSION: '4.3.0',
181
182 content: Object.assign((s_query_in) => {
183 let s_query = s_query_in.toLowerCase();
184
185 if(s_query in H_CONTENT_TAGS) {
186 return H_CONTENT_TAGS[s_query];
187 }
188
189 let m_content_type = R_CONTENT_TYPE.exec(s_query);
190 if(!m_content_type) throw new Error(`invalid content-type string: "${s_query}"`);
191 let [, s_content_type, s_parameters] = m_content_type;
192 let s_content_type_normal = s_content_type.toLowerCase();
193
194 if(s_content_type_normal in H_CONTENT_MIMES) {
195 return H_CONTENT_MIMES[s_content_type_normal];
196 }
197 else {
198 throw new Error(`no content handlers matched query for "${s_content_type_normal}"`);
199 }
200 }, {
201 ttl,
202 trig,
203 nt,
204 nq,
205 xml,
206
207 }),
208
209 core: {
210 data: {
211 get factory() {
212 // memoize
213 delete graphy.core.data.factory;
214 return (graphy.core.data.factory = require('@graphy/core.data.factory'));
215 },
216 },
217 iso: {
218 get stream() {
219 // memoize
220 delete graphy.core.iso.stream;
221 return (graphy.core.iso.stream = require('@graphy/core.iso.stream'));
222 },
223 },
224 },
225
226 get 'core.data.factory'() {
227 return memoize('core.data.factory');
228 },
229
230 get 'core.iso.stream'() {
231 return memoize('core.iso.stream');
232 },
233
234 util: {
235 dataset: {
236 get tree() {
237 // memoize
238 delete graphy.util.dataset.tree;
239 return (graphy.util.dataset.tree = require('@graphy/util.dataset.tree'));
240 },
241 },
242 },
243
244 get 'util.dataset.tree'() {
245 return memoize('util.dataset.tree');
246 },
247
248 memory: {
249 dataset: {
250 get fast() {
251 // memoize
252 delete graphy.memory.dataset.fast;
253 return (graphy.memory.dataset.fast = require('@graphy/memory.dataset.fast'));
254 },
255 },
256 },
257
258 get 'memory.dataset.fast'() {
259 return memoize('memory.dataset.fast');
260 },
261
262
263
264 get 'content.ttl.read'() {
265 return memoize('content.ttl.read');
266 },
267
268 get 'content.ttl.write'() {
269 return memoize('content.ttl.write');
270 },
271
272 get 'content.ttl.scribe'() {
273 return memoize('content.ttl.scribe');
274 },
275
276 get 'content.trig.read'() {
277 return memoize('content.trig.read');
278 },
279
280 get 'content.trig.write'() {
281 return memoize('content.trig.write');
282 },
283
284 get 'content.trig.scribe'() {
285 return memoize('content.trig.scribe');
286 },
287
288 get 'content.nt.read'() {
289 return memoize('content.nt.read');
290 },
291
292 get 'content.nt.write'() {
293 return memoize('content.nt.write');
294 },
295
296 get 'content.nt.scribe'() {
297 return memoize('content.nt.scribe');
298 },
299
300 get 'content.nt.scan'() {
301 return memoize('content.nt.scan');
302 },
303
304 get 'content.nq.read'() {
305 return memoize('content.nq.read');
306 },
307
308 get 'content.nq.write'() {
309 return memoize('content.nq.write');
310 },
311
312 get 'content.nq.scribe'() {
313 return memoize('content.nq.scribe');
314 },
315
316 get 'content.nq.scan'() {
317 return memoize('content.nq.scan');
318 },
319
320 get 'content.xml.scribe'() {
321 return memoize('content.xml.scribe');
322 },
323
324
325
326}, factory);
327
328
329// export graphy to window object if in main thread of browser
330if('undefined' !== typeof window) window.graphy = graphy;