-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
5818 lines (5789 loc) · 230 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __decorateClass = (decorators, target, key, kind) => {
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
for (var i = decorators.length - 1, decorator; i >= 0; i--)
if (decorator = decorators[i])
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
if (kind && result)
__defProp(target, key, result);
return result;
};
// src/index.ts
var src_exports = {};
__export(src_exports, {
BUDAResourceSelector: () => BUDAResourceSelector_default,
BottomBarContainer: () => BottomBarContainer,
EntityCreationContainer: () => EntityCreationContainer_default,
EntityCreationContainerRoute: () => EntityCreationContainerRoute,
EntityEditContainer: () => EntityEditContainer_default,
EntityEditContainerMayUpdate: () => EntityEditContainerMayUpdate,
EntityGraph: () => EntityGraph,
EntitySelectorContainer: () => EntitySelectorContainer_default,
EntityShapeChooserContainer: () => EntityShapeChooserContainer_default,
ExtRDFResourceWithLabel: () => ExtRDFResourceWithLabel,
HttpError: () => HttpError,
LangSelect: () => LangSelect,
LiteralWithId: () => LiteralWithId,
NewEntityContainer: () => NewEntityContainer_default,
NodeShape: () => NodeShape,
RDFResource: () => RDFResource,
RDFResourceWithLabel: () => RDFResourceWithLabel,
Subject: () => Subject,
ValueByLangToStrPrefLang: () => ValueByLangToStrPrefLang,
atoms: () => common_exports,
enTranslations: () => en_default,
fetchTtl: () => fetchTtl,
generateSubnodes: () => generateSubnodes,
getHistoryStatus: () => getHistoryStatus,
history: () => history,
ns: () => ns_exports,
rdf: () => rdf10,
shapes: () => shapes_exports,
updateHistory: () => updateHistory
});
module.exports = __toCommonJS(src_exports);
// src/helpers/rdf/ns.ts
var ns_exports = {};
__export(ns_exports, {
DASH: () => DASH,
DASH_uri: () => DASH_uri,
FOAF: () => FOAF,
FOAF_uri: () => FOAF_uri,
OWL: () => OWL,
OWL_uri: () => OWL_uri,
PrefixMap: () => PrefixMap,
RDE: () => RDE,
RDE_uri: () => RDE_uri,
RDF: () => RDF,
RDFS: () => RDFS,
RDFS_uri: () => RDFS_uri,
RDF_uri: () => RDF_uri,
SH: () => SH,
SH_uri: () => SH_uri,
SKOS: () => SKOS,
SKOS_uri: () => SKOS_uri,
XSD: () => XSD,
XSD_uri: () => XSD_uri,
dashEditor: () => dashEditor,
dashEnumSelectEditor: () => dashEnumSelectEditor,
dashListShape: () => dashListShape,
dashSingleLine: () => dashSingleLine,
defaultDescriptionProperties: () => defaultDescriptionProperties,
defaultLabelProperties: () => defaultLabelProperties,
defaultPrefixMap: () => defaultPrefixMap,
prefLabel: () => prefLabel,
rdeAllowBatchManagement: () => rdeAllowBatchManagement,
rdeAllowMarkDown: () => rdeAllowMarkDown,
rdeAllowPushToTopLevelLabel: () => rdeAllowPushToTopLevelLabel,
rdeClassIn: () => rdeClassIn,
rdeConnectIDs: () => rdeConnectIDs,
rdeCopyObjectsOfProperty: () => rdeCopyObjectsOfProperty,
rdeDefaultLanguage: () => rdeDefaultLanguage,
rdeDefaultValue: () => rdeDefaultValue,
rdeDisplayPriority: () => rdeDisplayPriority,
rdeExternalShape: () => rdeExternalShape,
rdeIdentifierPrefix: () => rdeIdentifierPrefix,
rdeIgnoreShape: () => rdeIgnoreShape,
rdeIndependentIdentifiers: () => rdeIndependentIdentifiers,
rdeInternalShape: () => rdeInternalShape,
rdePropertyShapeType: () => rdePropertyShapeType,
rdeReadOnly: () => rdeReadOnly,
rdeSortOnProperty: () => rdeSortOnProperty,
rdeSpecialPattern: () => rdeSpecialPattern,
rdeUniqueValueAmongSiblings: () => rdeUniqueValueAmongSiblings,
rdfFirst: () => rdfFirst,
rdfLangString: () => rdfLangString,
rdfNil: () => rdfNil,
rdfRest: () => rdfRest,
rdfType: () => rdfType,
rdfsComment: () => rdfsComment,
rdfsLabel: () => rdfsLabel,
shClass: () => shClass,
shDatatype: () => shDatatype,
shDescription: () => shDescription,
shGroup: () => shGroup,
shIn: () => shIn,
shInversePath: () => shInversePath,
shLanguageIn: () => shLanguageIn,
shMaxCount: () => shMaxCount,
shMaxExclusive: () => shMaxExclusive,
shMaxInclusive: () => shMaxInclusive,
shMessage: () => shMessage,
shMinCount: () => shMinCount,
shMinExclusive: () => shMinExclusive,
shMinInclusive: () => shMinInclusive,
shName: () => shName,
shNamespace: () => shNamespace,
shNode: () => shNode,
shOrder: () => shOrder,
shPath: () => shPath,
shPattern: () => shPattern,
shProperty: () => shProperty,
shTargetClass: () => shTargetClass,
shTargetObjectsOf: () => shTargetObjectsOf,
shTargetSubjectsOf: () => shTargetSubjectsOf,
shUniqueLang: () => shUniqueLang,
skosDefinition: () => skosDefinition
});
var rdf = __toESM(require("rdflib"));
var import_debug = require("debug");
var DASH_uri = "http://datashapes.org/dash#";
var DASH = rdf.Namespace(DASH_uri);
var OWL_uri = "http://www.w3.org/2002/07/owl#";
var OWL = rdf.Namespace(OWL_uri);
var RDFS_uri = "http://www.w3.org/2000/01/rdf-schema#";
var RDFS = rdf.Namespace(RDFS_uri);
var SH_uri = "http://www.w3.org/ns/shacl#";
var SH = rdf.Namespace(SH_uri);
var RDF_uri = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
var RDF = rdf.Namespace(RDF_uri);
var SKOS_uri = "http://www.w3.org/2004/02/skos/core#";
var SKOS = rdf.Namespace(SKOS_uri);
var XSD_uri = "http://www.w3.org/2001/XMLSchema#";
var XSD = rdf.Namespace(XSD_uri);
var FOAF_uri = "http://xmlns.com/foaf/0.1/";
var FOAF = rdf.Namespace(FOAF_uri);
var RDE_uri = "https://github.com/buda-base/rdf-document-editor/";
var RDE = rdf.Namespace(RDE_uri);
var debug = (0, import_debug.debug)("rde:rdf:ns");
var defaultPrefixToURI = {
dash: DASH_uri,
owl: OWL_uri,
rde: RDE_uri,
rdfs: RDFS_uri,
sh: SH_uri,
rdf: RDF_uri,
skos: SKOS_uri,
xsd: XSD_uri,
foaf: FOAF_uri
};
var PrefixMap = class {
prefixToURI;
URItoPrefix;
constructor(prefixToURI) {
this.prefixToURI = { ...defaultPrefixToURI, ...prefixToURI };
this.URItoPrefix = {};
for (const [prefix, uri] of Object.entries(this.prefixToURI)) {
this.URItoPrefix[uri] = prefix;
}
}
setDefaultPrefixes = (s) => {
for (const [prefix, uri] of Object.entries(this.prefixToURI)) {
s.setPrefixForURI(prefix, uri);
}
};
qnameFromUri = (uri = "") => {
if (uri.match(/^[^:/#]+:[^:/#]+$/))
return uri;
let j = uri.indexOf("#");
if (j < 0)
j = uri.lastIndexOf("/");
if (j < 0) {
debug("Cannot make qname out of <" + uri + ">");
return uri;
}
const localid = uri.slice(j + 1);
const namesp = uri.slice(0, j + 1);
const prefix = this.URItoPrefix[namesp];
if (!prefix) {
debug("Cannot make qname out of <" + uri + "> (can't find appropriate prefix)");
return uri;
}
return prefix + ":" + localid;
};
lnameFromUri = (uri) => {
let j = uri.indexOf("#");
if (j < 0)
j = uri.lastIndexOf("/");
if (j < 0)
throw new Error("Cannot make lname out of <" + uri + ">");
return uri.slice(j + 1);
};
namespaceFromUri = (uri) => {
let j = uri.indexOf("#");
if (j < 0)
j = uri.lastIndexOf("/");
if (j < 0)
throw new Error("Cannot get namespace from <" + uri + ">");
return uri.slice(0, j + 1);
};
uriFromQname = (qname = "") => {
if (!qname)
return "";
const j = qname.indexOf(":");
if (j < 0)
throw new Error("Cannot make uri out of <" + qname + ">");
const localid = qname.slice(j + 1);
const prefix = qname.slice(0, j);
const uri_base = this.prefixToURI[prefix];
if (!uri_base)
throw new Error("Cannot make uri out of <" + qname + ">");
return uri_base + localid;
};
lnameFromQname = (qname = "") => {
const j = qname.indexOf(":");
if (j < 0)
throw new Error("Cannot make lname out of <" + qname + ">");
return qname.slice(j + 1);
};
};
var rdfType = RDF("type");
var shProperty = SH("property");
var shGroup = SH("group");
var shOrder = SH("order");
var rdfsLabel = RDFS("label");
var prefLabel = SKOS("prefLabel");
var shName = SH("name");
var shPath = SH("path");
var dashEditor = DASH("editor");
var shNode = SH("node");
var dashListShape = DASH("ListShape");
var dashEnumSelectEditor = DASH("EnumSelectEditor");
var shMessage = SH("message");
var rdeDisplayPriority = RDE("displayPriority");
var shMinCount = SH("minCount");
var shMinInclusive = SH("minInclusive");
var shMinExclusive = SH("minExclusive");
var shClass = SH("class");
var shMaxCount = SH("maxCount");
var shMaxInclusive = SH("maxInclusive");
var shMaxExclusive = SH("maxExclusive");
var shDatatype = SH("datatype");
var dashSingleLine = DASH("singleLine");
var shTargetClass = SH("targetClass");
var shTargetObjectsOf = SH("targetObjectsOf");
var shTargetSubjectsOf = SH("targetSubjectsOf");
var rdePropertyShapeType = RDE("propertyShapeType");
var rdeInternalShape = RDE("InternalShape");
var rdeExternalShape = RDE("ExternalShape");
var rdeIgnoreShape = RDE("IgnoreShape");
var rdeClassIn = RDE("classIn");
var shIn = SH("in");
var shInversePath = SH("inversePath");
var shUniqueLang = SH("uniqueLang");
var rdeReadOnly = RDE("readOnly");
var rdeIdentifierPrefix = RDE("identifierPrefix");
var rdeAllowMarkDown = RDE("allowMarkDown");
var shNamespace = SH("namespace");
var rdeDefaultLanguage = RDE("defaultLanguage");
var rdeDefaultValue = RDE("defaultValue");
var shLanguageIn = SH("languageIn");
var shPattern = SH("pattern");
var rdeSortOnProperty = RDE("sortOnProperty");
var rdeAllowPushToTopLevelLabel = RDE("allowPushToTopLevelLabel");
var rdeIndependentIdentifiers = RDE("independentIdentifiers");
var rdeSpecialPattern = RDE("specialPattern");
var rdeConnectIDs = RDE("connectIDs");
var rdeAllowBatchManagement = RDE("allowBatchManagement");
var rdeCopyObjectsOfProperty = RDE("copyObjectsOfProperty");
var rdeUniqueValueAmongSiblings = RDE("uniqueValueAmongSiblings");
var rdfLangString = RDF("langString");
var skosDefinition = SKOS("definition");
var rdfsComment = RDFS("comment");
var shDescription = SH("description");
var rdfFirst = RDF("first");
var rdfRest = RDF("rest");
var rdfNil = RDF("nil");
var defaultLabelProperties = [prefLabel, rdfsLabel, shName];
var defaultDescriptionProperties = [skosDefinition, rdfsComment, shDescription];
var defaultPrefixMap = new PrefixMap({});
// src/helpers/rdf/shapes.ts
var shapes_exports = {};
__export(shapes_exports, {
NodeShape: () => NodeShape,
PropertyGroup: () => PropertyGroup,
PropertyShape: () => PropertyShape,
generateSubnodes: () => generateSubnodes,
sortByPropValue: () => sortByPropValue
});
var rdf3 = __toESM(require("rdflib"));
// src/helpers/rdf/types.ts
var rdf2 = __toESM(require("rdflib"));
var import_typescript_memoize = require("typescript-memoize");
var import_recoil = require("recoil");
var import_nanoid = require("nanoid");
var import_debug2 = require("debug");
var debug2 = (0, import_debug2.debug)("rde:rdf:types");
var defaultGraphNode = rdf2.sym(rdf2.Store.defaultGraphURI);
var errors = {};
var history = {};
var updateHistory = (entity, qname, prop, val, noHisto = true) => {
if (!history[entity])
history[entity] = [];
else {
while (history[entity].length && history[entity][history[entity].length - 1]["tmp:undone"]) {
history[entity].pop();
}
}
const newVal = {
[qname]: { [prop]: val },
...entity != qname ? { "tmp:parentPath": getParentPath(entity, qname) } : {}
};
if (val?.length === 1 && !(val[0] instanceof LiteralWithId) && (val[0].uri === "tmp:uri" || val[0].value === ""))
return;
if (noHisto === -1) {
const first = history[entity].findIndex((h) => h["tmp:allValuesLoaded"]);
if (first > 0)
history[entity].splice(first, 0, newVal);
else
history[entity].push(newVal);
} else
history[entity].push(newVal);
};
var getHistoryStatus = (entityUri) => {
if (!history[entityUri])
return { top: -1, current: -1, first: -1 };
const top = history[entityUri].length - 1;
let first = -1, current = -1;
for (const [i, h] of history[entityUri].entries()) {
if (h["tmp:allValuesLoaded"])
first = i;
else if (h["tmp:undone"])
current = i - 1;
if (first != -1 && current != -1)
break;
}
return { top, first, current };
};
function getParentPath(entityUri, sub) {
let parentPath = [];
for (const h of history[entityUri]) {
const subSubj = Object.keys(h).filter((k) => !["tmp:parent", "tmp:undone"].includes(k));
for (const s of subSubj) {
const subprop = Object.keys(h[s]).filter((k) => !["tmp:parent", "tmp:undone"].includes(k));
for (const p of subprop) {
if (typeof h[s][p] !== "string")
for (const v of h[s][p]) {
if (v instanceof Subject && v.uri === sub) {
if (parentPath.length > 1 && parentPath[1] !== p)
throw new Error("multiple property (" + parentPath + "," + p + ") for node " + sub);
if (s !== entityUri)
parentPath = getParentPath(entityUri, s);
parentPath.push(s);
parentPath.push(p);
}
}
}
}
}
return parentPath;
}
var rdfLitAsNumber = (lit) => {
const n = Number(lit.value);
if (!isNaN(n)) {
return +n;
}
return null;
};
var Path = class {
sparqlString;
directPathNode = null;
inversePathNode = null;
constructor(node, graph3, listMode) {
const invpaths = graph3.store.each(node, shInversePath, null);
if (invpaths.length > 1) {
throw "too many inverse path in shacl path:" + invpaths;
}
if (invpaths.length == 1) {
const invpath = invpaths[0];
this.sparqlString = "^" + invpath.value;
this.inversePathNode = invpath;
} else {
if (listMode) {
this.sparqlString = node.value + "[]";
} else {
this.sparqlString = node.value;
}
this.directPathNode = node;
}
}
};
var EntityGraphValues = class {
oldSubjectProps = {};
newSubjectProps = {};
subjectUri = "";
/* eslint-disable no-magic-numbers */
idHash = Date.now();
//getRandomIntInclusive(1000, 9999).toString()
noHisto = false;
constructor(subjectUri) {
this.subjectUri = subjectUri;
}
onGetInitialValues = (subjectUri, pathString, values) => {
if (!(subjectUri in this.oldSubjectProps))
this.oldSubjectProps[subjectUri] = {};
if (!(subjectUri in this.newSubjectProps))
this.newSubjectProps[subjectUri] = {};
this.oldSubjectProps[subjectUri][pathString] = values;
this.newSubjectProps[subjectUri][pathString] = values;
};
onUpdateValues = (subjectUri, pathString, values) => {
if (!(subjectUri in this.newSubjectProps))
this.newSubjectProps[subjectUri] = {};
this.newSubjectProps[subjectUri][pathString] = values;
if (this.noHisto === true) {
this.noHisto = false;
return;
}
updateHistory(this.subjectUri, subjectUri, pathString, values, this.noHisto);
if (this.noHisto === 1)
this.noHisto = -1;
};
isInitialized = (subjectUri, pathString) => {
return subjectUri in this.oldSubjectProps && pathString in this.oldSubjectProps[subjectUri];
};
addNewValuestoStore(store, subjectUri) {
if (!(subjectUri in this.newSubjectProps))
return;
const subject = rdf2.sym(subjectUri);
for (const pathString in this.newSubjectProps[subjectUri]) {
if (pathString.startsWith("^")) {
const property = rdf2.sym(pathString.substring(1));
const values = this.newSubjectProps[subjectUri][pathString];
for (const val of values) {
if (val instanceof LiteralWithId) {
throw "can't add literals in inverse path, something's wrong with the data!";
} else {
if (val.node?.value == "tmp:uri" || val.node?.value == "tmp:none")
continue;
store.add(val.node, property, subject, defaultGraphNode);
if (val instanceof Subject) {
this.addNewValuestoStore(store, val.uri);
}
}
}
} else {
const listMode = pathString.endsWith("[]");
const property = rdf2.sym(listMode ? pathString.substring(0, pathString.length - 2) : pathString);
const values = this.newSubjectProps[subjectUri][pathString];
const collection = new rdf2.Collection();
for (const val of values) {
if (val instanceof LiteralWithId) {
if (val.value == "")
continue;
if (listMode)
collection.append(val);
else
store.add(subject, property, val, defaultGraphNode);
} else {
if (val.node?.value == "tmp:uri" || val.node?.value == "tmp:none")
continue;
if (listMode) {
if (val.node) {
collection.append(val.node);
} else if (val instanceof rdf2.Literal) {
collection.append(val);
} else
throw "could not add " + val + " to collection " + collection;
} else
store.add(subject, property, val.node, defaultGraphNode);
if (val instanceof Subject) {
this.addNewValuestoStore(store, val.uri);
}
}
}
if (listMode && collection.elements.length) {
collection.close();
store.add(subject, property, collection, defaultGraphNode);
}
}
}
}
propsUpdateEffect = (subjectUri, pathString) => ({ setSelf, onSet }) => {
onSet((newValues) => {
if (!(newValues instanceof import_recoil.DefaultValue)) {
this.onUpdateValues(subjectUri, pathString, newValues);
}
});
};
getAtomForSubjectProperty(pathString, subjectUri) {
return (0, import_recoil.atom)({
key: this.idHash + subjectUri + pathString,
default: [],
// effects_UNSTABLE no more, see https://github.com/facebookexperimental/Recoil/blob/main/CHANGELOG-recoil.md#breaking-changes-1
effects: [
/*debugAtomEffect,*/
this.propsUpdateEffect(subjectUri, pathString)
],
// disable immutability in production
dangerouslyAllowMutability: true
});
}
hasSubject(subjectUri) {
return subjectUri in this.newSubjectProps;
}
};
__decorateClass([
(0, import_typescript_memoize.Memoize)((pathString, subjectUri) => {
return subjectUri + pathString;
})
], EntityGraphValues.prototype, "getAtomForSubjectProperty", 1);
var EntityGraph = class _EntityGraph {
onGetInitialValues;
getAtomForSubjectProperty;
getValues;
get values() {
return this.getValues();
}
// where to start when reconstructing the tree
topSubjectUri;
store;
// connexGraph is the store that contains the labels of associated resources
// (ex: students, teachers, etc.), it's not present in all circumstances
connexGraph;
prefixMap;
labelProperties;
descriptionProperties;
constructor(store, topSubjectUri, prefixMap = defaultPrefixMap, connexGraph = rdf2.graph(), labelProperties = defaultLabelProperties, descriptionProperties = defaultDescriptionProperties) {
this.store = store;
this.prefixMap = prefixMap;
this.descriptionProperties = descriptionProperties;
this.labelProperties = labelProperties;
const values = new EntityGraphValues(topSubjectUri);
this.topSubjectUri = topSubjectUri;
this.onGetInitialValues = values.onGetInitialValues;
this.getAtomForSubjectProperty = (pathString, subjectUri) => values.getAtomForSubjectProperty(pathString, subjectUri);
this.connexGraph = connexGraph;
this.getValues = () => {
return values;
};
}
addNewValuestoStore(store) {
this.values.addNewValuestoStore(store, this.topSubjectUri);
}
static addIdToLitList = (litList) => {
return litList.map((lit) => {
return new LiteralWithId(lit.value, lit.language, lit.datatype);
});
};
static addLabelsFromGraph = (resList, graph3) => {
return resList.map((res) => {
return new RDFResourceWithLabel(res, graph3);
});
};
static addExtDataFromGraph = (resList, graph3) => {
return resList.map((res) => {
if (!graph3.connexGraph) {
throw "trying to access inexistant associatedStore";
}
const perLang = {};
for (const p of graph3.labelProperties) {
const lits = graph3.connexGraph.each(res, p, null);
for (const lit of lits) {
if (lit.language in perLang)
continue;
perLang[lit.language] = lit.value;
}
}
debug2("connex:", res.uri, perLang);
return new ExtRDFResourceWithLabel(res.uri, perLang, void 0, void 0, graph3.prefixMap);
});
};
hasSubject(subjectUri) {
if (this.values.hasSubject(subjectUri))
return true;
return this.store.any(rdf2.sym(subjectUri), null, null) != null;
}
static subjectify = (resList, graph3) => {
return resList.map((res) => {
return new Subject(res, graph3);
});
};
// only returns the values that were not initalized before
getUnitializedValues(s, p) {
const path = p.path;
if (!path)
return null;
if (this.values.isInitialized(s.uri, path.sparqlString)) {
return null;
}
return this.getPropValuesFromStore(s, p);
}
getPropValuesFromStore(s, p) {
if (!p.path) {
throw "can't find path of " + p.uri;
}
switch (p.objectType) {
case 3 /* ResExt */:
if (!p.path.directPathNode) {
throw "can't have non-direct path for property " + p.uri;
}
const fromRDFResExt = s.getPropResValuesFromPath(p.path);
const fromRDFResExtwData = _EntityGraph.addExtDataFromGraph(fromRDFResExt, s.graph);
this.onGetInitialValues(s.uri, p.path.sparqlString, fromRDFResExtwData);
return fromRDFResExtwData;
break;
case 1 /* Internal */:
const fromRDFSubNode = s.getPropResValuesFromPath(p.path);
const fromRDFSubs = _EntityGraph.subjectify(fromRDFSubNode, s.graph);
this.onGetInitialValues(s.uri, p.path.sparqlString, fromRDFSubs);
return fromRDFSubs;
break;
case 2 /* ResInList */:
if (!p.path.directPathNode) {
throw "can't have non-direct path for property " + p.uri;
}
const fromRDFResList = s.getPropResValues(p.path.directPathNode);
const fromRDFReswLabels = _EntityGraph.addLabelsFromGraph(fromRDFResList, p.graph);
this.onGetInitialValues(s.uri, p.path.sparqlString, fromRDFReswLabels);
return fromRDFReswLabels;
break;
case 0 /* Literal */:
case 5 /* LitInList */:
default:
if (!p.path.directPathNode) {
throw "can't have non-direct path for property " + p.uri;
}
let fromRDFLits;
if (p.hasListAsObject) {
const fromRDFLitsList = s.getPropLitValuesFromList(p.path.directPathNode);
fromRDFLits = fromRDFLitsList === null ? [] : fromRDFLitsList;
} else {
fromRDFLits = s.getPropLitValues(p.path.directPathNode);
}
const fromRDFLitIDs = _EntityGraph.addIdToLitList(fromRDFLits);
this.onGetInitialValues(s.uri, p.path.sparqlString, fromRDFLitIDs);
return fromRDFLitIDs;
break;
}
}
};
var RDFResource = class {
node;
graph;
isCollection;
constructor(node, graph3) {
this.node = node;
this.graph = graph3;
this.isCollection = node instanceof rdf2.Collection;
}
get id() {
return this.node.value;
}
get value() {
return this.node.value;
}
get lname() {
return this.graph.prefixMap.lnameFromUri(this.node.value);
}
get namespace() {
return this.graph.prefixMap.namespaceFromUri(this.node.value);
}
get qname() {
return this.graph.prefixMap.qnameFromUri(this.node.value);
}
get uri() {
return this.node.value;
}
static valuesByLang(values) {
const res = {};
for (const value of values) {
if (value instanceof LiteralWithId) {
res[value.language] = value.value;
}
}
return res;
}
getPropValueByLang(p) {
if (this.node instanceof rdf2.Collection)
return {};
const lits = this.graph.store.each(this.node, p, null);
const res = {};
for (const lit of lits) {
res[lit.language] = lit.value;
}
return res;
}
getPropValueOrNullByLang(p) {
if (this.node instanceof rdf2.Collection)
return {};
const lits = this.graph.store.each(this.node, p, null);
const res = {};
let i = 0;
for (const lit of lits) {
i += 1;
res[lit.language] = lit.value;
}
if (i == 0)
return null;
return res;
}
getPropLitValues(p) {
if (this.node instanceof rdf2.Collection)
return [];
return this.graph.store.each(this.node, p, null);
}
getPropResValues(p) {
if (this.node instanceof rdf2.Collection)
return [];
return this.graph.store.each(this.node, p, null);
}
fillElements(s, current) {
if (!s || s instanceof rdf2.NamedNode && s.uri == rdfNil.uri)
return;
const first = this.graph.store.any(s, rdfFirst, null);
current.push(first);
this.fillElements(this.graph.store.any(s, rdfRest, null), current);
}
getPropResValuesFromList(p) {
if (this.node instanceof rdf2.Collection)
return null;
const colls = this.graph.store.each(this.node, p, null);
for (const coll of colls) {
if (coll instanceof rdf2.Collection) {
return coll.elements;
}
const res = [];
this.fillElements(coll, res);
return res;
}
return null;
}
getPropLitValuesFromList(p) {
if (this.node instanceof rdf2.Collection)
return null;
const colls = this.graph.store.each(this.node, p, null);
for (const coll of colls) {
if (coll instanceof rdf2.Collection) {
return coll.elements;
}
const res = [];
this.fillElements(coll, res);
return res;
}
return null;
}
getPropIntValue(p) {
if (this.node instanceof rdf2.Collection)
return null;
const lit = this.graph.store.any(this.node, p, null);
if (lit === null)
return null;
return rdfLitAsNumber(lit);
}
getPropStringValue(p) {
if (this.node instanceof rdf2.Collection)
return null;
const lit = this.graph.store.any(this.node, p, null);
if (lit === null)
return null;
return lit.value;
}
getPropResValue(p) {
if (this.node instanceof rdf2.Collection)
return null;
const res = this.graph.store.any(this.node, p, null);
return res;
}
getPropResValuesFromPath(p) {
if (this.node instanceof rdf2.Collection)
return [];
if (p.directPathNode) {
return this.graph.store.each(this.node, p.directPathNode, null);
}
return this.graph.store.each(null, p.inversePathNode, this.node);
}
getPropResValueFromPath(p) {
if (this.node instanceof rdf2.Collection)
return null;
if (p.directPathNode) {
return this.graph.store.any(this.node, p.directPathNode, null);
}
return this.graph.store.any(this.node, p.inversePathNode, null);
}
getPropBooleanValue(p, dflt = false) {
if (this.node instanceof rdf2.Collection)
return dflt;
const lit = this.graph.store.any(this.node, p, null);
if (!lit)
return dflt;
const n = Boolean(lit.value);
if (n) {
return n;
}
return dflt;
}
};
var RDFResourceWithLabel = class extends RDFResource {
node;
constructor(node, graph3, labelProp) {
super(node, graph3);
this.node = node;
}
get prefLabels() {
for (const p of this.graph.labelProperties) {
const res = this.getPropValueOrNullByLang(p);
if (res != null)
return res;
}
return { en: this.node.value };
}
get description() {
for (const p of this.graph.descriptionProperties) {
const res = this.getPropValueOrNullByLang(p);
if (res != null)
return res;
}
return null;
}
};
__decorateClass([
(0, import_typescript_memoize.Memoize)()
], RDFResourceWithLabel.prototype, "prefLabels", 1);
__decorateClass([
(0, import_typescript_memoize.Memoize)()
], RDFResourceWithLabel.prototype, "description", 1);
var ExtRDFResourceWithLabel = class _ExtRDFResourceWithLabel extends RDFResourceWithLabel {
_prefLabels;
_description;
_otherData;
get prefLabels() {
return this._prefLabels;
}
get description() {
return this._description;
}
get otherData() {
return this._otherData;
}
constructor(uri, prefLabels, data = {}, description = null, prefixMap) {
super(rdf2.sym(uri), new EntityGraph(new rdf2.Store(), uri, prefixMap));
this._prefLabels = prefLabels;
this._description = description;
this._otherData = data;
}
addOtherData(key, value) {
return new _ExtRDFResourceWithLabel(this.uri, this._prefLabels, { ...this._otherData, [key]: value });
}
};
var LiteralWithId = class _LiteralWithId extends rdf2.Literal {
id;
constructor(value, language, datatype, id) {
super(value, language, datatype);
if (id) {
this.id = id;
} else {
this.id = (0, import_nanoid.nanoid)();
}
}
copy() {
return new _LiteralWithId(this.value, this.language, this.datatype, this.id);
}
copyWithUpdatedValue(value) {
return new _LiteralWithId(value, this.language, this.datatype, this.id);
}
copyWithUpdatedLanguage(language) {
return new _LiteralWithId(this.value, language, this.datatype, this.id);
}
};
var Subject = class _Subject extends RDFResource {
node;
constructor(node, graph3) {
super(node, graph3);
this.node = node;
}
getUnitializedValues(property) {
return this.graph.getUnitializedValues(this, property);
}
getAtomForProperty(pathString) {
return this.graph.getAtomForSubjectProperty(pathString, this.uri);
}
/*
// sets the flag to store to history or not according to the case,
// allows to store value modification not on top of history,
//
// ex: noHisto(false, -1) // put empty subnodes in history before tmp:allValuesLoaded
// noHisto(false, 1) // allow parent node in history but default empty subnodes before tmp:allValuesLoaded
// noHisto(false, false) // history back to normal => not exactly... must also use resetNoHisto()
// noHisto(true) // disable value storing when doing undo/redo
*/
noHisto(force = false, start = true) {
const current = this.graph.getValues().noHisto;
if (!force && current === -1)
return;
if (start !== true)
this.graph.getValues().noHisto = start;
else if (force || history[this.uri] && history[this.uri].some((h) => h["tmp:allValuesLoaded"]))
this.graph.getValues().noHisto = true;
}
resetNoHisto() {
this.graph.getValues().noHisto = false;
}
static createEmpty() {
return new _Subject(rdf2.sym("tmp:uri"), new EntityGraph(new rdf2.Store(), "tmp:uri"));
}
isEmpty() {
return this.node.uri == "tmp:uri";
}
};
var noneSelected = new ExtRDFResourceWithLabel("tmp:none", { en: "\u2013" }, {}, { en: "none provided" });
var emptyLiteral = new LiteralWithId("");
var sameLanguage = (lang1, lang2) => {
return lang1 == lang2;
};
// src/helpers/rdf/shapes.ts
var import_typescript_memoize2 = require("typescript-memoize");
var import_nanoid2 = require("nanoid");
var import_debug3 = require("debug");
var debug3 = (0, import_debug3.debug)("rde:rdf:shapes");
var sortByPropValue = (nodelist, property, store) => {
const nodeUriToPropValue = {};
for (const node of nodelist) {
const ordern = store.any(node, property, null);
if (!ordern) {
nodeUriToPropValue[node.uri] = 0;
continue;
}
const asnum = rdfLitAsNumber(ordern);
nodeUriToPropValue[node.uri] = asnum == null ? 0 : asnum;
}
const res = [...nodelist].sort((a, b) => {
return nodeUriToPropValue[a.uri] - nodeUriToPropValue[b.uri];
});
return res;
};
var _PropertyShape = class _PropertyShape extends RDFResourceWithLabel {
constructor(node, graph3) {
super(node, graph3, rdfsLabel);
}
get prefLabels() {
let res = {};
if (this.path && (this.path.directPathNode || this.path.inversePathNode)) {
const pathNode = this.path.directPathNode || this.path.inversePathNode;
if (pathNode) {
const propInOntology = new RDFResourceWithLabel(pathNode, this.graph);
res = propInOntology.prefLabels;
}
}
const resFromShape = this.getPropValueByLang(shName);
res = { ...res, ...resFromShape };
return res;
}
get helpMessage() {
let res = this.description;
if (res == null && this.path && (this.path.directPathNode || this.path.inversePathNode)) {
const pathNode = this.path.directPathNode || this.path.inversePathNode;
if (pathNode) {
const propInOntology = new RDFResourceWithLabel(pathNode, this.graph);
res = propInOntology.description;