1 |
|
2 |
|
3 |
|
4 |
|
5 | const factory = require('@graphy-dev/core.data.factory');
|
6 |
|
7 | const memoize = (s_package) => {
|
8 | delete graphy[s_package];
|
9 | return graphy[s_package] = require('@graphy-dev/'+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-dev/content.ttl.read'));
|
21 | },
|
22 |
|
23 |
|
24 | get write() {
|
25 |
|
26 | delete graphy.content.ttl.write;
|
27 | return (graphy.content.ttl.write = require('@graphy-dev/content.ttl.write'));
|
28 | },
|
29 |
|
30 | get scribe() {
|
31 |
|
32 | delete graphy.content.ttl.scribe;
|
33 | return (graphy.content.ttl.scribe = require('@graphy-dev/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-dev/content.trig.read'));
|
43 | },
|
44 |
|
45 |
|
46 | get write() {
|
47 |
|
48 | delete graphy.content.trig.write;
|
49 | return (graphy.content.trig.write = require('@graphy-dev/content.trig.write'));
|
50 | },
|
51 |
|
52 | get scribe() {
|
53 |
|
54 | delete graphy.content.trig.scribe;
|
55 | return (graphy.content.trig.scribe = require('@graphy-dev/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-dev/content.nt.read'));
|
65 | },
|
66 |
|
67 |
|
68 | get write() {
|
69 |
|
70 | delete graphy.content.nt.write;
|
71 | return (graphy.content.nt.write = require('@graphy-dev/content.nt.write'));
|
72 | },
|
73 |
|
74 | get scribe() {
|
75 |
|
76 | delete graphy.content.nt.scribe;
|
77 | return (graphy.content.nt.scribe = require('@graphy-dev/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-dev/content.nq.read'));
|
87 | },
|
88 |
|
89 |
|
90 | get write() {
|
91 |
|
92 | delete graphy.content.nq.write;
|
93 | return (graphy.content.nq.write = require('@graphy-dev/content.nq.write'));
|
94 | },
|
95 |
|
96 | get scribe() {
|
97 |
|
98 | delete graphy.content.nq.scribe;
|
99 | return (graphy.content.nq.scribe = require('@graphy-dev/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 | 'n-triples': nt,
|
126 | ntriples: nt,
|
127 | nq,
|
128 | 'n-quads': nq,
|
129 | nquads: 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) => {
|
145 | if(s_query.toLowerCase() in H_CONTENT_TAGS) {
|
146 | return H_CONTENT_TAGS[s_query.toLowerCase()];
|
147 | }
|
148 |
|
149 | let m_content_type = R_CONTENT_TYPE.exec(s_query);
|
150 | if(!m_content_type) throw new Error(`invalid content-type string: "${s_query}"`);
|
151 | let [, s_content_type, s_parameters] = m_content_type;
|
152 | let s_content_type_normal = s_content_type.toLowerCase();
|
153 |
|
154 | if(s_content_type_normal in H_CONTENT_MIMES) {
|
155 | return H_CONTENT_MIMES[s_content_type_normal];
|
156 | }
|
157 | else {
|
158 | throw new Error(`no content handlers matched query for "${s_content_type_normal}"`);
|
159 | }
|
160 | }, {
|
161 | ttl,
|
162 | trig,
|
163 | nt,
|
164 | nq,
|
165 |
|
166 | }),
|
167 |
|
168 | core: {
|
169 | data: {
|
170 | get factory() {
|
171 |
|
172 | delete graphy.core.data.factory;
|
173 | return (graphy.core.data.factory = require('@graphy-dev/core.data.factory'));
|
174 | },
|
175 | },
|
176 | iso: {
|
177 | get stream() {
|
178 |
|
179 | delete graphy.core.iso.stream;
|
180 | return (graphy.core.iso.stream = require('@graphy-dev/core.iso.stream'));
|
181 | },
|
182 | },
|
183 | },
|
184 |
|
185 | get 'core.data.factory'() {
|
186 | return memoize('core.data.factory');
|
187 | },
|
188 |
|
189 | get 'core.iso.stream'() {
|
190 | return memoize('core.iso.stream');
|
191 | },
|
192 |
|
193 | util: {
|
194 | dataset: {
|
195 | get tree() {
|
196 |
|
197 | delete graphy.util.dataset.tree;
|
198 | return (graphy.util.dataset.tree = require('@graphy-dev/util.dataset.tree'));
|
199 | },
|
200 | },
|
201 | },
|
202 |
|
203 | get 'util.dataset.tree'() {
|
204 | return memoize('util.dataset.tree');
|
205 | },
|
206 |
|
207 | memory: {
|
208 | dataset: {
|
209 | get fast() {
|
210 |
|
211 | delete graphy.memory.dataset.fast;
|
212 | return (graphy.memory.dataset.fast = require('@graphy-dev/memory.dataset.fast'));
|
213 | },
|
214 | },
|
215 | },
|
216 |
|
217 | get 'memory.dataset.fast'() {
|
218 | return memoize('memory.dataset.fast');
|
219 | },
|
220 |
|
221 |
|
222 |
|
223 | get 'content.ttl.read'() {
|
224 | return memoize('content.ttl.read');
|
225 | },
|
226 |
|
227 | get 'content.ttl.write'() {
|
228 | return memoize('content.ttl.write');
|
229 | },
|
230 |
|
231 | get 'content.ttl.scribe'() {
|
232 | return memoize('content.ttl.scribe');
|
233 | },
|
234 |
|
235 | get 'content.trig.read'() {
|
236 | return memoize('content.trig.read');
|
237 | },
|
238 |
|
239 | get 'content.trig.write'() {
|
240 | return memoize('content.trig.write');
|
241 | },
|
242 |
|
243 | get 'content.trig.scribe'() {
|
244 | return memoize('content.trig.scribe');
|
245 | },
|
246 |
|
247 | get 'content.nt.read'() {
|
248 | return memoize('content.nt.read');
|
249 | },
|
250 |
|
251 | get 'content.nt.write'() {
|
252 | return memoize('content.nt.write');
|
253 | },
|
254 |
|
255 | get 'content.nt.scribe'() {
|
256 | return memoize('content.nt.scribe');
|
257 | },
|
258 |
|
259 | get 'content.nq.read'() {
|
260 | return memoize('content.nq.read');
|
261 | },
|
262 |
|
263 | get 'content.nq.write'() {
|
264 | return memoize('content.nq.write');
|
265 | },
|
266 |
|
267 | get 'content.nq.scribe'() {
|
268 | return memoize('content.nq.scribe');
|
269 | },
|
270 |
|
271 |
|
272 |
|
273 | }, factory);
|
274 |
|
275 |
|
276 |
|
277 | if('undefined' !== typeof window) window.graphy = graphy;
|