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