@startinblox/core 0.17.21-beta.5 → 0.17.21-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/solid-form-search.js.map +1 -1
- package/dist/libs/filter.js +214 -0
- package/dist/libs/filter.js.map +1 -0
- package/dist/libs/interfaces.js.map +1 -1
- package/dist/libs/store/store.js +7 -4
- package/dist/libs/store/store.js.map +1 -1
- package/dist/mixins/filterMixin.js +2 -61
- package/dist/mixins/filterMixin.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["solid-form-search.ts"],"names":["Sib","WidgetMixin","AttributeBinderMixin","ContextMixin","newWidgetFactory","html","render","ifDefined","uniqID","SolidFormSearch","name","use","attributes","defaultWidget","type","String","default","submitButton","callback","newValue","oldValue","noRender","populate","submitWidget","undefined","classSubmitButton","value","initialState","error","created","element","closest","autoRangeValues","rangeId","attachedElements","Set","defaultMultipleWidget","defaultSetWidget","values","widgets","forEach","widget","component","getValue","JSON","parse","list","multiple","getWidget","field","isSet","tagName","hasAttribute","idField","setAttribute","widgetAttribute","getAttribute","customElements","get","startsWith","widgetFromTagName","attach","elm","has","add","updateAutoRanges","detach","delete","attr","replace","getValuesOfField","id","ldpContains","Array","from","map","data","context","sibStore","setLocalData","change","resource","dispatchEvent","CustomEvent","bubbles","detail","inputChange","getSubmitTemplate","empty","replaceAttributesData","addEventListener","e","preventDefault","fields","getFields","widgetTemplates","Promise","all","createWidgetTemplate","template","register"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,GAAT,QAAoB,aAApB;AACA,SAASC,WAAT,QAA4B,uBAA5B;AACA,SAASC,oBAAT,QAAqC,gCAArC;AACA,SAASC,YAAT,QAA6B,wBAA7B;AAEA,SAASC,gBAAT,QAAiC,mCAAjC;AAEA,SAASC,IAAT,EAAeC,MAAf,QAA6B,UAA7B;AACA,SAAS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B,GAAG,CAACoG,QAAJ,CAAa3F,eAAb","sourcesContent":["import { Sib } from '../libs/Sib';\nimport { WidgetMixin } from '../mixins/widgetMixin';\nimport { AttributeBinderMixin } from '../mixins/attributeBinderMixin';\nimport { ContextMixin } from '../mixins/contextMixin';\nimport type { WidgetInterface } from '../mixins/interfaces';\nimport { newWidgetFactory } from '../new-widgets/new-widget-factory';\n\nimport { html, render } from 'lit-html';\nimport { ifDefined } from 'lit-html/directives/if-defined';\nimport { uniqID } from '../libs/helpers';\n\nexport const SolidFormSearch = {\n name: 'solid-form-search',\n use: [WidgetMixin, AttributeBinderMixin, ContextMixin],\n attributes: {\n defaultWidget: {\n type: String,\n default: 'solid-form-label-text',\n },\n submitButton: {\n type: String,\n default: null,\n callback: function (newValue: string, oldValue: string) {\n if (this.noRender == null && newValue !== oldValue) this.populate();\n },\n },\n submitWidget: {\n type: String,\n default: undefined\n },\n classSubmitButton: {\n type: String,\n default: undefined,\n },\n noRender: {\n type: String,\n default: null,\n callback: function (value: boolean) {\n if (value === null) this.populate()\n }\n },\n },\n initialState: {\n error: '',\n },\n created() {\n if (this.element.closest('[no-render]')) this.noRender = ''; // if embedded in no-render, apply no-render to himself\n this.autoRangeValues = {};\n this.rangeId = uniqID();\n this.attachedElements = new Set();\n },\n get defaultMultipleWidget(): string {\n return 'solid-multiple-form';\n },\n get defaultSetWidget(): string {\n return 'solid-set-default';\n },\n\n get value(): object {\n const values = {};\n this.widgets.forEach((widget) => {\n const name = (widget.component || widget).name;\n if (name == null) return;\n let value = widget.component ? widget.component.getValue() : widget.value;\n try {\n value = JSON.parse(value);\n } catch {}\n value = {\n type: widget.component.type,\n list: !!widget.component.multiple,\n value: value,\n }\n values[name] = value;\n });\n return values;\n },\n getWidget(field: string, isSet: boolean = false): WidgetInterface {\n let tagName = '';\n // If auto-range-[field] exists, create range-[field] and sets its value\n if(this.element.hasAttribute('auto-range-' + field) && !this.element.hasAttribute('range-' + field)) {\n const idField = `${this.rangeId}_${field}`;\n this.element.setAttribute('range-' + field, 'store://local.' + idField);\n this.populate();\n }\n \n const widgetAttribute = this.element.getAttribute('widget-' + field);\n // Choose widget\n if (!widgetAttribute && (this.element.hasAttribute('range-' + field) || this.element.hasAttribute('enum-' + field))) {\n tagName = 'solid-form-dropdown'\n } else {\n tagName = widgetAttribute || (!isSet ? this.defaultWidget : this.defaultSetWidget);\n }\n // Create widget\n if (!customElements.get(tagName)) { // component does not exist\n if (tagName.startsWith('solid')) newWidgetFactory(tagName); // solid- -> create it\n }\n\n return this.widgetFromTagName(tagName);\n },\n async attach(elm: any) {\n if(this.attachedElements.has(elm)) return;\n this.attachedElements.add(elm);\n await this.updateAutoRanges();\n },\n async detach(elm: any) {\n if(!this.attachedElements.has(elm)) return;\n this.attachedElements.delete(elm);\n await this.updateAutoRanges();\n },\n async updateAutoRanges() {\n for(const attr of (this.element as Element).attributes) {\n if(!attr['name'].startsWith('auto-range-')) continue;\n const field = attr['name'].replace('auto-range-', '');\n const autoRangeValues = new Set();\n for(const elm of this.attachedElements) {\n for(const value of await elm.getValuesOfField(field)) {\n autoRangeValues.add(value);\n }\n }\n const idField = `${this.rangeId}_${field}`;\n const id = `store://local.${idField}`;\n const ldpContains = Array.from(autoRangeValues).map(id => ({'@id' : id}));\n const data = {\n \"@type\": \"ldp:Container\",\n \"@context\": this.context,\n \"ldp:contains\" : ldpContains,\n };\n sibStore.setLocalData(data, id);\n }\n },\n change(resource: object): void {\n this.element.dispatchEvent(\n new CustomEvent('formChange', {\n bubbles: true,\n detail: { resource },\n }),\n );\n },\n async inputChange(): Promise<void> {\n this.change(this.value);\n },\n getSubmitTemplate() {\n return html`\n <div class=${ifDefined(this.classSubmitButton)}>\n ${this.submitWidget === 'button' ? html`\n <button type=\"submit\">${this.submitButton || ''}</button>\n ` : html`\n <input type=\"submit\" value=${ifDefined(this.submitButton || undefined)}>\n `}\n </div>\n ` \n },\n empty(): void {},\n async populate(): Promise<void> {\n await this.replaceAttributesData();\n if(this.submitButton == null) {\n this.element.addEventListener('input', () => this.inputChange());\n } else {\n this.element.addEventListener('submit', (e: Event) => {\n e.preventDefault();\n this.inputChange();\n });\n }\n const fields = await this.getFields();\n const widgetTemplates = await Promise.all(fields.map((field: string) => this.createWidgetTemplate(field)));\n const template = html`\n <form>\n ${widgetTemplates}\n ${this.submitButton == null ? '' : this.getSubmitTemplate()}\n </form>\n `;\n render(template, this.element);\n }\n};\n\nSib.register(SolidFormSearch);"]}
|
|
1
|
+
{"version":3,"sources":["solid-form-search.ts"],"names":["Sib","WidgetMixin","AttributeBinderMixin","ContextMixin","newWidgetFactory","html","render","ifDefined","uniqID","SolidFormSearch","name","use","attributes","defaultWidget","type","String","default","submitButton","callback","newValue","oldValue","noRender","populate","submitWidget","undefined","classSubmitButton","value","initialState","error","created","element","closest","autoRangeValues","rangeId","attachedElements","Set","defaultMultipleWidget","defaultSetWidget","values","widgets","forEach","widget","component","getValue","JSON","parse","list","multiple","getWidget","field","isSet","tagName","hasAttribute","idField","setAttribute","widgetAttribute","getAttribute","customElements","get","startsWith","widgetFromTagName","attach","elm","has","add","updateAutoRanges","detach","delete","attr","replace","getValuesOfField","id","ldpContains","Array","from","map","data","context","sibStore","setLocalData","change","resource","dispatchEvent","CustomEvent","bubbles","detail","inputChange","getSubmitTemplate","empty","replaceAttributesData","addEventListener","e","preventDefault","fields","getFields","widgetTemplates","Promise","all","createWidgetTemplate","template","register"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,GAAT,QAAoB,aAApB;AACA,SAASC,WAAT,QAA4B,uBAA5B;AACA,SAASC,oBAAT,QAAqC,gCAArC;AACA,SAASC,YAAT,QAA6B,wBAA7B;AAEA,SAASC,gBAAT,QAAiC,mCAAjC;AAEA,SAASC,IAAT,EAAeC,MAAf,QAA6B,UAA7B;AACA,SAASC,SAAT,QAA0B,gCAA1B;AACA,SAASC,MAAT,QAAuB,iBAAvB;AAGA,OAAO,MAAMC,eAAe,GAAG;A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ixins/widgetMixin';\nimport { AttributeBinderMixin } from '../mixins/attributeBinderMixin';\nimport { ContextMixin } from '../mixins/contextMixin';\nimport type { WidgetInterface } from '../mixins/interfaces';\nimport { newWidgetFactory } from '../new-widgets/new-widget-factory';\n\nimport { html, render } from 'lit-html';\nimport { ifDefined } from 'lit-html/directives/if-defined';\nimport { uniqID } from '../libs/helpers';\nimport type { SearchQuery } from '../libs/interfaces';\n\nexport const SolidFormSearch = {\n name: 'solid-form-search',\n use: [WidgetMixin, AttributeBinderMixin, ContextMixin],\n attributes: {\n defaultWidget: {\n type: String,\n default: 'solid-form-label-text',\n },\n submitButton: {\n type: String,\n default: null,\n callback: function (newValue: string, oldValue: string) {\n if (this.noRender == null && newValue !== oldValue) this.populate();\n },\n },\n submitWidget: {\n type: String,\n default: undefined\n },\n classSubmitButton: {\n type: String,\n default: undefined,\n },\n noRender: {\n type: String,\n default: null,\n callback: function (value: boolean) {\n if (value === null) this.populate()\n }\n },\n },\n initialState: {\n error: '',\n },\n created() {\n if (this.element.closest('[no-render]')) this.noRender = ''; // if embedded in no-render, apply no-render to himself\n this.autoRangeValues = {};\n this.rangeId = uniqID();\n this.attachedElements = new Set();\n },\n get defaultMultipleWidget(): string {\n return 'solid-multiple-form';\n },\n get defaultSetWidget(): string {\n return 'solid-set-default';\n },\n\n get value(): SearchQuery {\n const values: SearchQuery = {};\n this.widgets.forEach((widget) => {\n const name = (widget.component || widget).name;\n if (name == null) return;\n let value = widget.component ? widget.component.getValue() : widget.value;\n try {\n value = JSON.parse(value);\n } catch {}\n value = {\n type: widget.component.type,\n list: !!widget.component.multiple,\n value: value,\n }\n values[name] = value;\n });\n return values;\n },\n getWidget(field: string, isSet: boolean = false): WidgetInterface {\n let tagName = '';\n // If auto-range-[field] exists, create range-[field] and sets its value\n if(this.element.hasAttribute('auto-range-' + field) && !this.element.hasAttribute('range-' + field)) {\n const idField = `${this.rangeId}_${field}`;\n this.element.setAttribute('range-' + field, 'store://local.' + idField);\n this.populate();\n }\n \n const widgetAttribute = this.element.getAttribute('widget-' + field);\n // Choose widget\n if (!widgetAttribute && (this.element.hasAttribute('range-' + field) || this.element.hasAttribute('enum-' + field))) {\n tagName = 'solid-form-dropdown'\n } else {\n tagName = widgetAttribute || (!isSet ? this.defaultWidget : this.defaultSetWidget);\n }\n // Create widget\n if (!customElements.get(tagName)) { // component does not exist\n if (tagName.startsWith('solid')) newWidgetFactory(tagName); // solid- -> create it\n }\n\n return this.widgetFromTagName(tagName);\n },\n async attach(elm: any) {\n if(this.attachedElements.has(elm)) return;\n this.attachedElements.add(elm);\n await this.updateAutoRanges();\n },\n async detach(elm: any) {\n if(!this.attachedElements.has(elm)) return;\n this.attachedElements.delete(elm);\n await this.updateAutoRanges();\n },\n async updateAutoRanges() {\n for(const attr of (this.element as Element).attributes) {\n if(!attr['name'].startsWith('auto-range-')) continue;\n const field = attr['name'].replace('auto-range-', '');\n const autoRangeValues = new Set();\n for(const elm of this.attachedElements) {\n for(const value of await elm.getValuesOfField(field)) {\n autoRangeValues.add(value);\n }\n }\n const idField = `${this.rangeId}_${field}`;\n const id = `store://local.${idField}`;\n const ldpContains = Array.from(autoRangeValues).map(id => ({'@id' : id}));\n const data = {\n \"@type\": \"ldp:Container\",\n \"@context\": this.context,\n \"ldp:contains\" : ldpContains,\n };\n sibStore.setLocalData(data, id);\n }\n },\n change(resource: object): void {\n this.element.dispatchEvent(\n new CustomEvent('formChange', {\n bubbles: true,\n detail: { resource },\n }),\n );\n },\n async inputChange(): Promise<void> {\n this.change(this.value);\n },\n getSubmitTemplate() {\n return html`\n <div class=${ifDefined(this.classSubmitButton)}>\n ${this.submitWidget === 'button' ? html`\n <button type=\"submit\">${this.submitButton || ''}</button>\n ` : html`\n <input type=\"submit\" value=${ifDefined(this.submitButton || undefined)}>\n `}\n </div>\n ` \n },\n empty(): void {},\n async populate(): Promise<void> {\n await this.replaceAttributesData();\n if(this.submitButton == null) {\n this.element.addEventListener('input', () => this.inputChange());\n } else {\n this.element.addEventListener('submit', (e: Event) => {\n e.preventDefault();\n this.inputChange();\n });\n }\n const fields = await this.getFields();\n const widgetTemplates = await Promise.all(fields.map((field: string) => this.createWidgetTemplate(field)));\n const template = html`\n <form>\n ${widgetTemplates}\n ${this.submitButton == null ? '' : this.getSubmitTemplate()}\n </form>\n `;\n render(template, this.element);\n }\n};\n\nSib.register(SolidFormSearch);"]}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { parseFieldsString, findClosingBracketMatchIndex, compare, uniqID } from "./helpers.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Check if the field is a set
|
|
5
|
+
* @param field - field to test
|
|
6
|
+
* @param fields - list of fields
|
|
7
|
+
* @returns true if the field is a set, false otherwise
|
|
8
|
+
*/
|
|
9
|
+
const isSet = (field, fields) => {
|
|
10
|
+
if (!fields) return false;
|
|
11
|
+
let foundSets = fields.match(getSetRegexp(field));
|
|
12
|
+
return foundSets ? foundSets.length > 0 : false;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Get the list of fields in the set
|
|
16
|
+
* @param field - set name to get
|
|
17
|
+
* @param fields - list of fields
|
|
18
|
+
* @returns a list of fields in the set
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
const getSet = (field, fields) => {
|
|
23
|
+
const setString = fields.match(getSetRegexp(field));
|
|
24
|
+
if (!setString) return [];
|
|
25
|
+
const firstSetBracket = fields.indexOf(setString[0]) + setString[0].length - 1;
|
|
26
|
+
const lastSetBracket = findClosingBracketMatchIndex(fields, firstSetBracket);
|
|
27
|
+
const set = fields.substring(firstSetBracket + 1, lastSetBracket);
|
|
28
|
+
return parseFieldsString(set);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const getSetRegexp = field => {
|
|
32
|
+
return new RegExp("(^|\\,|\\(|\\s)\\s*".concat(field, "\\s*\\("), 'g');
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Check if the field is a special search field
|
|
36
|
+
* @param field - field to test
|
|
37
|
+
* @param searchForm - current search form
|
|
38
|
+
* @returns true if the field is a special search field
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
const isSearchField = (field, searchForm) => {
|
|
43
|
+
return searchForm.hasAttribute('search-' + field);
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Get the fields targetted by a search field
|
|
47
|
+
* @param field - search field to get
|
|
48
|
+
* @param searchForm - current search form
|
|
49
|
+
* @returns a list of fields targetted by the current search field
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
const getSearchField = (field, searchForm) => {
|
|
54
|
+
return parseFieldsString(searchForm.getAttribute('search-' + field));
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Throw or simply return value
|
|
58
|
+
* @param throwOn - should throw on True or False
|
|
59
|
+
* @param ret - value to return
|
|
60
|
+
* @returns
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
const orThrow = (throwOn, ret) => {
|
|
65
|
+
if (throwOn === true && ret) throw true;
|
|
66
|
+
if (throwOn === false && !ret) throw false;
|
|
67
|
+
return ret;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Compare a value to the query
|
|
71
|
+
* @param val - value to compare
|
|
72
|
+
* @param query - object to know how and what value to compare
|
|
73
|
+
* @param throwOn - should function throw error on True or False
|
|
74
|
+
* @returns true if value matches, throw error otherwise
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
const matchValue = async (val, query, throwOn) => {
|
|
79
|
+
var _subject$isContainer;
|
|
80
|
+
|
|
81
|
+
const subject = await val;
|
|
82
|
+
if (subject == null && query.value === '') return orThrow(throwOn, true); // filter not set and subject not existing -> ignore filter
|
|
83
|
+
|
|
84
|
+
if (subject == null) return orThrow(throwOn, false); // return false; // property does not exist on resource
|
|
85
|
+
|
|
86
|
+
if (query.list) {
|
|
87
|
+
// Filter on a container
|
|
88
|
+
if (query.value.length === 0) return orThrow(throwOn, true);
|
|
89
|
+
|
|
90
|
+
for (const v of query.value) {
|
|
91
|
+
if (await matchValue(subject, {
|
|
92
|
+
type: query.type,
|
|
93
|
+
value: v,
|
|
94
|
+
list: false
|
|
95
|
+
})) {
|
|
96
|
+
// do not throw here, we need the result
|
|
97
|
+
return orThrow(throwOn, true);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return orThrow(throwOn, false);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if ((_subject$isContainer = subject.isContainer) !== null && _subject$isContainer !== void 0 && _subject$isContainer.call(subject)) {
|
|
105
|
+
let ret = Promise.resolve(query.value === ''); // if no query, return a match
|
|
106
|
+
|
|
107
|
+
for (const value of subject['ldp:contains']) {
|
|
108
|
+
ret = (await ret) || (await matchValue(value, query)); // do not throw here, we need the result
|
|
109
|
+
|
|
110
|
+
if (ret) return orThrow(throwOn, true);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return orThrow(throwOn, await ret);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return orThrow(throwOn, compare[query.type](subject, query.value));
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Cache properties of a filter to avoid repeated parsing
|
|
120
|
+
* @param cacheKey - uniq key
|
|
121
|
+
* @param filter - filter to check
|
|
122
|
+
* @param fields - fields attribute of the element
|
|
123
|
+
* @param searchForm - current search form
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
const cacheFieldsProps = (cacheKey, filter, fields, searchForm) => {
|
|
128
|
+
if (!window.cachePropsSearchFilter[cacheKey]) {
|
|
129
|
+
window.cachePropsSearchFilter[cacheKey] = {
|
|
130
|
+
setFields: isSet(filter, fields) ? getSet(filter, fields) : null,
|
|
131
|
+
setSearchFields: isSearchField(filter, searchForm) ? getSearchField(filter, searchForm) : null
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Check if one resource match one filter
|
|
137
|
+
* @param resource - resource to test
|
|
138
|
+
* @param filter - name of the property tested
|
|
139
|
+
* @param query - query object to know how to compare values
|
|
140
|
+
* @param fields - fields attribute of the element
|
|
141
|
+
* @param searchForm - searchForm component
|
|
142
|
+
* @param filterId - uniqId used to fill the cache
|
|
143
|
+
* @param throwOn - should function throw error on True or False
|
|
144
|
+
* @returns return true if the resource matches the filter, throw error otherwise
|
|
145
|
+
*/
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
const matchFilter = async (resource, filter, query, fieldsAttr, searchForm, filterId, throwOn) => {
|
|
149
|
+
let fields = null;
|
|
150
|
+
const cacheKey = "".concat(filter, "_").concat(filterId);
|
|
151
|
+
cacheFieldsProps(cacheKey, filter, fieldsAttr, searchForm);
|
|
152
|
+
|
|
153
|
+
if (window.cachePropsSearchFilter[cacheKey].setFields !== null) {
|
|
154
|
+
fields = window.cachePropsSearchFilter[cacheKey].setFields;
|
|
155
|
+
} else if (window.cachePropsSearchFilter[cacheKey].setSearchFields !== null) {
|
|
156
|
+
fields = window.cachePropsSearchFilter[cacheKey].setSearchFields;
|
|
157
|
+
} else {
|
|
158
|
+
// search on 1 field
|
|
159
|
+
return matchValue(resource[filter], query, throwOn);
|
|
160
|
+
} // search on multiple fields
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
try {
|
|
164
|
+
await Promise.all((fields || []).map(field => matchFilter(resource, field, query, fieldsAttr, searchForm, filterId, true // stop searching when 1 filter is true (= OR)
|
|
165
|
+
)));
|
|
166
|
+
} catch (e) {
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
throw false;
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* Check if one resource match all the filters
|
|
174
|
+
* @param resource - resource to test
|
|
175
|
+
* @param filters - current filters
|
|
176
|
+
* @param filterNames - names of the filters
|
|
177
|
+
* @param fields - fields attribute of the element
|
|
178
|
+
* @param searchForm - searchForm component
|
|
179
|
+
* @param filterId - uniqId used to fill the cache
|
|
180
|
+
* @returns true if resource match, false otherwise
|
|
181
|
+
*/
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
const matchFilters = async (resource, filters, filterNames, fields, searchForm, filterId) => {
|
|
185
|
+
// return true if all filters values are contained in the corresponding field of the resource
|
|
186
|
+
try {
|
|
187
|
+
await Promise.all(filterNames.map(filter => matchFilter(resource, filter, filters[filter], fields, searchForm, filterId, false // stop searching when 1 filter is false (= AND)
|
|
188
|
+
)));
|
|
189
|
+
} catch (e) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return true;
|
|
194
|
+
};
|
|
195
|
+
/**
|
|
196
|
+
* Check which resources match the filters
|
|
197
|
+
* @param resources - list of resources to filter
|
|
198
|
+
* @param filters - current filters
|
|
199
|
+
* @param fields - fields attribute of the element
|
|
200
|
+
* @param searchForm - searchForm component
|
|
201
|
+
* @returns resources filtered
|
|
202
|
+
*/
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
const searchInResources = async (resources, filters, fields, searchForm) => {
|
|
206
|
+
// Optim: use cache to do these things only once
|
|
207
|
+
const filterNames = Object.keys(filters);
|
|
208
|
+
const filterId = uniqID();
|
|
209
|
+
window.cachePropsSearchFilter = {};
|
|
210
|
+
return Promise.all(resources.map(resource => matchFilters(resource, filters, filterNames, fields, searchForm, filterId)));
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
export { searchInResources };
|
|
214
|
+
//# sourceMappingURL=filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["filter.ts"],"names":["parseFieldsString","findClosingBracketMatchIndex","compare","uniqID","isSet","field","fields","foundSets","match","getSetRegexp","length","getSet","setString","firstSetBracket","indexOf","lastSetBracket","set","substring","RegExp","isSearchField","searchForm","hasAttribute","getSearchField","getAttribute","orThrow","throwOn","ret","matchValue","val","query","subject","value","list","v","type","isContainer","Promise","resolve","cacheFieldsProps","cacheKey","filter","window","cachePropsSearchFilter","setFields","setSearchFields","matchFilter","resource","fieldsAttr","filterId","all","map","e","matchFilters","filters","filterNames","searchInResources","resources","Object","keys"],"mappings":"AAAA,SAASA,iBAAT,EAA4BC,4BAA5B,EAA0DC,OAA1D,EAAmEC,MAAnE,QAAiF,WAAjF;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,KAAK,GAAG,CAACC,KAAD,EAAgBC,MAAhB,KAA4C;AACxD,MAAI,CAACA,MAAL,EAAa,OAAO,KAAP;AACb,MAAIC,SAAS,GAAGD,MAAM,CAACE,KAAP,CAAaC,YAAY,CAACJ,KAAD,CAAzB,CAAhB;AACA,SAAOE,SAAS,GAAGA,SAAS,CAACG,MAAV,GAAmB,CAAtB,GAA0B,KAA1C;AACD,CAJD;AAKA;AACA;AACA;AACA;AACA;AACA;;;AACA,MAAMC,MAAM,GAAG,CAACN,KAAD,EAAgBC,MAAhB,KAA6C;AAC1D,QAAMM,SAAS,GAAGN,MAAM,CAACE,KAAP,CAAaC,YAAY,CAACJ,KAAD,CAAzB,CAAlB;AACA,MAAI,CAACO,SAAL,EAAgB,OAAO,EAAP;AAChB,QAAMC,eAAe,GAAGP,MAAM,CAACQ,OAAP,CAAeF,SAAS,CAAC,CAAD,CAAxB,IAAgCA,SAAS,CAAC,CAAD,CAAT,CAAaF,MAA7C,GAAuD,CAA/E;AACA,QAAMK,cAAc,GAAGd,4BAA4B,CAACK,MAAD,EAASO,eAAT,CAAnD;AACA,QAAMG,GAAG,GAAGV,MAAM,CAACW,SAAP,CAAiBJ,eAAe,GAAG,CAAnC,EAAsCE,cAAtC,CAAZ;AACA,SAAOf,iBAAiB,CAACgB,GAAD,CAAxB;AACD,CAPD;;AAQA,MAAMP,YAAY,GAAIJ,KAAD,IAAmB;AACtC,SAAO,IAAIa,MAAJ,8BAAiCb,KAAjC,cAAiD,GAAjD,CAAP;AACD,CAFD;AAGA;AACA;AACA;AACA;AACA;AACA;;;AACA,MAAMc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,UALS,EAMT4B,QANS,EAOT,IAPS,CAOJ;AAPI,KADK,CAAZ,CAAN;AAWD,GAZD,CAYE,OAAOG,CAAP,EAAU;AAAE,WAAO,IAAP;AAAa;;AAC3B,QAAM,KAAN;AACD,CArCD;AAuCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,MAAMC,YAAY,GAAG,OACnBN,QADmB,EAEnBO,OAFmB,EAGnBC,WAHmB,EAInBhD,MAJmB,EAKnBc,UALmB,EAMnB4B,QANmB,KAOE;AACrB;AACA,MAAI;AACF,UAAMZ,OAAO,CAACa,GAAR,CAAYK,WAAW,CAACJ,GAAZ,CAAgBV,MAAM,IACtCK,WAAW,CACTC,QADS,EAETN,MAFS,EAGTa,OAAO,CAACb,MAAD,CAHE,EAITlC,MAJS,EAKTc,UALS,EAMT4B,QANS,EAOT,KAPS,CAOH;AAPG,KADK,CAAZ,CAAN;AAWD,GAZD,CAYE,OAAOG,CAAP,EAAU;AAAE,WAAO,KAAP;AAAc;;AAC5B,SAAO,IAAP;AACD,CAvBD;AAyBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,MAAMI,iBAAiB,GAAG,OACxBC,SADwB,EAExBH,OAFwB,EAGxB/C,MAHwB,EAIxBc,UAJwB,KAKrB;AACH;AACA,QAAMkC,WAAW,GAAGG,MAAM,CAACC,IAAP,CAAYL,OAAZ,CAApB;AACA,QAAML,QAAQ,GAAG7C,MAAM,EAAvB;AACAsC,EAAAA,MAAM,CAACC,sBAAP,GAAgC,EAAhC;AAEA,SAAON,OAAO,CAACa,GAAR,CAAYO,SAAS,CAACN,GAAV,CAAcJ,QAAQ,IACvCM,YAAY,CACVN,QADU,EAEVO,OAFU,EAGVC,WAHU,EAIVhD,MAJU,EAKVc,UALU,EAMV4B,QANU,CADK,CAAZ,CAAP;AAUD,CArBD;;AAuBA,SACEO,iBADF","sourcesContent":["import { parseFieldsString, findClosingBracketMatchIndex, compare, uniqID } from \"./helpers\";\nimport type { Query, SearchQuery } from \"./interfaces\";\n\n/**\n * Check if the field is a set\n * @param field - field to test\n * @param fields - list of fields\n * @returns true if the field is a set, false otherwise\n */\nconst isSet = (field: string, fields: string): boolean => {\n if (!fields) return false;\n let foundSets = fields.match(getSetRegexp(field));\n return foundSets ? foundSets.length > 0 : false;\n}\n/**\n * Get the list of fields in the set\n * @param field - set name to get\n * @param fields - list of fields\n * @returns a list of fields in the set\n */\nconst getSet = (field: string, fields: string): string[] => {\n const setString = fields.match(getSetRegexp(field));\n if (!setString) return [];\n const firstSetBracket = fields.indexOf(setString[0]) + (setString[0].length) - 1;\n const lastSetBracket = findClosingBracketMatchIndex(fields, firstSetBracket);\n const set = fields.substring(firstSetBracket + 1, lastSetBracket);\n return parseFieldsString(set);\n}\nconst getSetRegexp = (field: string) => {\n return new RegExp(`(^|\\\\,|\\\\(|\\\\s)\\\\s*${field}\\\\s*\\\\(`, 'g')\n}\n/**\n * Check if the field is a special search field\n * @param field - field to test\n * @param searchForm - current search form\n * @returns true if the field is a special search field\n */\nconst isSearchField = (field: string, searchForm: any) => {\n return searchForm.hasAttribute('search-' + field);\n}\n/**\n * Get the fields targetted by a search field\n * @param field - search field to get\n * @param searchForm - current search form\n * @returns a list of fields targetted by the current search field\n */\nconst getSearchField = (field: string, searchForm: any): string[] => {\n return parseFieldsString(searchForm.getAttribute('search-' + field));\n}\n\n/**\n * Throw or simply return value\n * @param throwOn - should throw on True or False\n * @param ret - value to return\n * @returns\n */\nconst orThrow = (throwOn: boolean | undefined, ret: boolean) => {\n if (throwOn === true && ret) throw true;\n if (throwOn === false && !ret) throw false;\n return ret;\n}\n\n/**\n * Compare a value to the query\n * @param val - value to compare\n * @param query - object to know how and what value to compare\n * @param throwOn - should function throw error on True or False\n * @returns true if value matches, throw error otherwise\n */\nconst matchValue = async (val: any, query: Query, throwOn?: boolean): Promise<boolean> => {\n const subject = await val;\n if (subject == null && query.value === '') return orThrow(throwOn, true); // filter not set and subject not existing -> ignore filter\n if (subject == null) return orThrow(throwOn, false); // return false; // property does not exist on resource\n if (query.list) { // Filter on a container\n if(query.value.length === 0) return orThrow(throwOn, true);\n for(const v of query.value) {\n if (await matchValue(subject, { type: query.type, value: v, list: false })) { // do not throw here, we need the result\n return orThrow(throwOn, true);\n }\n }\n return orThrow(throwOn, false);\n }\n if (subject.isContainer?.()) {\n let ret: any = Promise.resolve(query.value === ''); // if no query, return a match\n for (const value of subject['ldp:contains']) {\n ret = await ret || await matchValue(value, query); // do not throw here, we need the result\n if (ret) return orThrow(throwOn, true);\n }\n return orThrow(throwOn, await ret);\n }\n\n return orThrow(throwOn, compare[query.type](subject, query.value));\n}\n\n/**\n * Cache properties of a filter to avoid repeated parsing\n * @param cacheKey - uniq key\n * @param filter - filter to check\n * @param fields - fields attribute of the element\n * @param searchForm - current search form\n */\nconst cacheFieldsProps = (\n cacheKey: string,\n filter: string,\n fields: string,\n searchForm: any\n) => {\n if (!window.cachePropsSearchFilter[cacheKey]) {\n window.cachePropsSearchFilter[cacheKey] = {\n setFields: isSet(filter, fields) ? getSet(filter, fields) : null,\n setSearchFields: isSearchField(filter, searchForm) ? getSearchField(filter, searchForm) : null\n }\n }\n}\n\n/**\n * Check if one resource match one filter\n * @param resource - resource to test\n * @param filter - name of the property tested\n * @param query - query object to know how to compare values\n * @param fields - fields attribute of the element\n * @param searchForm - searchForm component\n * @param filterId - uniqId used to fill the cache\n * @param throwOn - should function throw error on True or False\n * @returns return true if the resource matches the filter, throw error otherwise\n */\nconst matchFilter = async (\n resource: object,\n filter: string,\n query: Query,\n fieldsAttr: string,\n searchForm: any,\n filterId: string,\n throwOn: boolean\n) => {\n let fields: string[] | null = null;\n\n const cacheKey = `${filter}_${filterId}`;\n cacheFieldsProps(cacheKey, filter, fieldsAttr, searchForm);\n\n if (window.cachePropsSearchFilter[cacheKey].setFields !== null) {\n fields = window.cachePropsSearchFilter[cacheKey].setFields;\n } else if (window.cachePropsSearchFilter[cacheKey].setSearchFields !== null) {\n fields = window.cachePropsSearchFilter[cacheKey].setSearchFields;\n } else { // search on 1 field\n return matchValue(resource[filter], query, throwOn);\n }\n\n // search on multiple fields\n try {\n await Promise.all((fields || []).map(field =>\n matchFilter(\n resource,\n field,\n query,\n fieldsAttr,\n searchForm,\n filterId,\n true // stop searching when 1 filter is true (= OR)\n )\n ))\n } catch (e) { return true }\n throw false;\n}\n\n/**\n * Check if one resource match all the filters\n * @param resource - resource to test\n * @param filters - current filters\n * @param filterNames - names of the filters\n * @param fields - fields attribute of the element\n * @param searchForm - searchForm component\n * @param filterId - uniqId used to fill the cache\n * @returns true if resource match, false otherwise\n */\nconst matchFilters = async (\n resource: object,\n filters: SearchQuery,\n filterNames: string[],\n fields: string,\n searchForm: any,\n filterId: string\n): Promise<boolean> => {\n // return true if all filters values are contained in the corresponding field of the resource\n try {\n await Promise.all(filterNames.map(filter =>\n matchFilter(\n resource,\n filter,\n filters[filter],\n fields,\n searchForm,\n filterId,\n false // stop searching when 1 filter is false (= AND)\n )\n ));\n } catch (e) { return false }\n return true;\n}\n\n/**\n * Check which resources match the filters\n * @param resources - list of resources to filter\n * @param filters - current filters\n * @param fields - fields attribute of the element\n * @param searchForm - searchForm component\n * @returns resources filtered\n */\nconst searchInResources = async (\n resources: object[],\n filters: SearchQuery,\n fields: string,\n searchForm: any\n) => {\n // Optim: use cache to do these things only once\n const filterNames = Object.keys(filters);\n const filterId = uniqID();\n window.cachePropsSearchFilter = {};\n\n return Promise.all(resources.map(resource =>\n matchFilters(\n resource,\n filters,\n filterNames,\n fields,\n searchForm,\n filterId\n )\n ));\n}\n\nexport {\n searchInResources\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["interfaces.ts"],"names":[],"mappings":"AAKC;AAUA;AA8BA;AAsBA;AAIA","sourcesContent":["export interface AccessorStaticInterface {\n [key: string]: {\n get: Function;\n set: Function;\n }\n};\n\nexport interface ArrayOfHooksInterface {\n created: HookInterface[];\n attached: HookInterface[];\n detached: HookInterface[];\n}\n\nexport interface AttributeChangedCallbackInterface {\n (newValue: any, oldValue: any): void;\n};\n\nexport interface AttributeDefinitionInterface {\n type?: any;\n default?: any;\n required?: boolean;\n callback?: AttributeChangedCallbackInterface;\n}\n\nexport interface AttributesDefinitionInterface {\n [key: string]: AttributeDefinitionInterface;\n}\n\nexport type ComponentConstructorInterface = new (element: HTMLElement) => ComponentInterface;\n\nexport interface ComponentInterface {\n element: HTMLElement;\n created():void;\n attached():void;\n detached():void;\n\n attributesCallback(key: string, value: any, oldValue: any):void;\n}\n\nexport interface ComponentStaticInterface extends HasAttributesDefinitionInterface, HasInitialStateInterface {\n name: String;\n\n hooks: ArrayOfHooksInterface;\n methods: Map<string, Function>;\n accessors: AccessorStaticInterface;\n};\n\nexport interface HasAttributesDefinitionInterface {\n attributes?: AttributesDefinitionInterface | undefined;\n}\n\nexport interface HasHooksInterface {\n created?: HookInterface;\n attached?: HookInterface;\n detached?: HookInterface;\n}\n\nexport interface HasInitialStateInterface {\n initialState?: object | undefined;\n}\n\nexport interface HasMixinsInterface {\n use?: MixinStaticInterface[] | undefined;\n}\n\nexport interface HookInterface {\n (): void;\n};\n\nexport interface MixinStaticInterface extends HasAttributesDefinitionInterface, HasMixinsInterface, HasInitialStateInterface, HasHooksInterface {\n name: String;\n};\n\nexport interface LocationResourceInterface {\n lat?: HookInterface;\n lng?: HookInterface;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["interfaces.ts"],"names":[],"mappings":"AAKC;AAUA;AA8BA;AAsBA;AAIA","sourcesContent":["export interface AccessorStaticInterface {\n [key: string]: {\n get: Function;\n set: Function;\n }\n};\n\nexport interface ArrayOfHooksInterface {\n created: HookInterface[];\n attached: HookInterface[];\n detached: HookInterface[];\n}\n\nexport interface AttributeChangedCallbackInterface {\n (newValue: any, oldValue: any): void;\n};\n\nexport interface AttributeDefinitionInterface {\n type?: any;\n default?: any;\n required?: boolean;\n callback?: AttributeChangedCallbackInterface;\n}\n\nexport interface AttributesDefinitionInterface {\n [key: string]: AttributeDefinitionInterface;\n}\n\nexport type ComponentConstructorInterface = new (element: HTMLElement) => ComponentInterface;\n\nexport interface ComponentInterface {\n element: HTMLElement;\n created():void;\n attached():void;\n detached():void;\n\n attributesCallback(key: string, value: any, oldValue: any):void;\n}\n\nexport interface ComponentStaticInterface extends HasAttributesDefinitionInterface, HasInitialStateInterface {\n name: String;\n\n hooks: ArrayOfHooksInterface;\n methods: Map<string, Function>;\n accessors: AccessorStaticInterface;\n};\n\nexport interface HasAttributesDefinitionInterface {\n attributes?: AttributesDefinitionInterface | undefined;\n}\n\nexport interface HasHooksInterface {\n created?: HookInterface;\n attached?: HookInterface;\n detached?: HookInterface;\n}\n\nexport interface HasInitialStateInterface {\n initialState?: object | undefined;\n}\n\nexport interface HasMixinsInterface {\n use?: MixinStaticInterface[] | undefined;\n}\n\nexport interface HookInterface {\n (): void;\n};\n\nexport interface MixinStaticInterface extends HasAttributesDefinitionInterface, HasMixinsInterface, HasInitialStateInterface, HasHooksInterface {\n name: String;\n};\n\nexport interface LocationResourceInterface {\n lat?: HookInterface;\n lng?: HookInterface;\n}\nexport interface Query {\n value: any\n type: \"boolean\" | \"number\" | \"range\" | \"resource\" | \"string\";\n list: boolean\n}\n\nexport interface SearchQuery {\n [key: string]: Query\n}"]}
|
package/dist/libs/store/store.js
CHANGED
|
@@ -59,7 +59,8 @@ class Store {
|
|
|
59
59
|
this.subscriptionVirtualContainersIndex = new Map();
|
|
60
60
|
this.loadingList = new Set();
|
|
61
61
|
this.headers = {
|
|
62
|
-
'Content-Type': 'application/ld+json'
|
|
62
|
+
'Content-Type': 'application/ld+json',
|
|
63
|
+
'Cache-Control': 'must-revalidate'
|
|
63
64
|
};
|
|
64
65
|
this.fetch = this.storeOptions.fetchMethod;
|
|
65
66
|
this.session = this.storeOptions.session;
|
|
@@ -149,6 +150,7 @@ class Store {
|
|
|
149
150
|
const headers = { ...this.headers,
|
|
150
151
|
'accept-language': this._getLanguage()
|
|
151
152
|
};
|
|
153
|
+
console.log("Request Headers:", headers);
|
|
152
154
|
return this.fetchAuthn(iri, {
|
|
153
155
|
method: 'GET',
|
|
154
156
|
headers: headers,
|
|
@@ -429,7 +431,7 @@ class Store {
|
|
|
429
431
|
try {
|
|
430
432
|
const fullURL = new URL(id);
|
|
431
433
|
var pathArray = fullURL.pathname.split('/');
|
|
432
|
-
var containerUrl = fullURL.origin + '/' + pathArray[1];
|
|
434
|
+
var containerUrl = fullURL.origin + '/' + pathArray[1] + '/';
|
|
433
435
|
const headers = { ...this.headers,
|
|
434
436
|
'X-Cache-Purge-Match': 'startswith'
|
|
435
437
|
};
|
|
@@ -824,8 +826,9 @@ class CustomGetter {
|
|
|
824
826
|
|
|
825
827
|
switch (property) {
|
|
826
828
|
case '@id':
|
|
827
|
-
return this.getCompactedIri(this.resource['@id']);
|
|
828
|
-
|
|
829
|
+
if (this.resource['@id']) return this.getCompactedIri(this.resource['@id']); // Compact @id if possible
|
|
830
|
+
else console.log(this.resource, this.resource['@id']);
|
|
831
|
+
return;
|
|
829
832
|
|
|
830
833
|
case '@type':
|
|
831
834
|
return this.resource['@type'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["store.ts"],"names":["JSONLDContextParser","PubSub","ContextParser","myParser","base_context","rdf","rdfs","ldp","foaf","name","acl","permissions","mode","geo","lat","lng","Store","constructor","storeOptions","id","resolve","handler","event","detail","resource","document","removeEventListener","cache","Map","subscriptionIndex","subscriptionVirtualContainersIndex","loadingList","Set","headers","fetch","fetchMethod","session","getData","context","idParent","localData","forceFetch","has","get","isFullResource","Promise","addEventListener","resolveResource","add","clientContext","parse","_isLocalId","fetchData","error","console","delete","serverContext","resourceProxy","CustomGetter","getProxy","cacheGraph","dispatchEvent","CustomEvent","fetchAuthn","iri","options","authenticated","then","fn","_convertHeaders","response","method","ok","status","err","Error","_getAbsoluteIri","_getLanguage","credentials","json","key","parentContext","parentId","properties","merge","set","getSubObjects","res","newParentContext","getChildren","cacheChildrenPromises","subscribeResourceTo","push","all","match","_fetch","body","JSON","stringify","store","clearCache","_updateResource","includes","expandedId","_getExpandedId","purge","nestedResources","getNestedResources","resourcesToRefresh","resourcesToNotify","refreshResources","resourceIds","notifyResources","filter","resourceWithContexts","map","resourceId","publish","cachedResource","isContainer","nestedProperties","excludeKeys","p","Object","keys","forEach","child","setLocalData","post","put","patch","log","catch","warn","fullURL","URL","pathArray","pathname","split","containerUrl","origin","deleted","headersObject","Headers","value","entries","expandTerm","startsWith","nestedResourceId","existingSubscriptions","subscribeVirtualContainerTo","virtualContainerId","parentIri","location","href","_resourceIsComplete","length","localStorage","getItem","window","navigator","language","slice","selectLanguage","selectedLanguageCode","setItem","sibStore","sibAuth","querySelector","sibAuthDefined","customElements","whenDefined","localName","getFetch","Symbol","toPrimitive","expandProperties","prop","objectReplaceProperty","object","oldProp","newProp","defineProperty","getOwnPropertyDescriptor","path","path1","path2","getResource","getExpandedPredicate","e","lastPath1El","pop","unshift","undefined","join","iriParent","getProperties","getCompactedPredicate","getLdpContains","children","subObjects","property","isFullNestedResource","getResourceData","getPermissions","permissionPredicate","perm","compactIri","getCompactedIri","toString","Proxy","bind"],"mappings":";;;;AAAA,OAAOA,mBAAP,MAAgC,uBAAhC,C,CACA;;AACA,OAAOC,MAAP,MAAmB,mCAAnB;AAGA,MAAMC,aAAa,GAAGF,mBAAmB,CAACE,aAA1C;AACA,MAAMC,QAAQ,GAAG,IAAID,aAAJ,EAAjB;AAEA,OAAO,MAAME,YAAY,GAAG;AAC1B,YAAU,2BADgB;AAE1BC,EAAAA,GAAG,EAAE,6CAFqB;AAG1BC,EAAAA,IAAI,EAAE,uCAHoB;AAI1BC,EAAAA,GAAG,EAAE,2BAJqB;AAK1BC,EAAAA,IAAI,EAAE,4BALoB;AAM1BC,EAAAA,IAAI,EAAE,YANoB;AAO1BC,EAAAA,GAAG,EAAE,gCAPqB;AAQ1BC,EAAAA,WAAW,EAAE,mBARa;AAS1BC,EAAAA,IAAI,EAAE,UAToB;AAU1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AAO,KAAKE,cAAL,EAAP;AAA8B;;AAChC,eAAK,aAAL;AACE,mBAAO,KAAKM,cAAL,EAAP;AAA8B;;AAChC,eAAK,eAAL;AACE,mBAAO,KAAK3J,aAAZ;AAA2B;;AAC7B,eAAK,MAAL;AACE;;AACF;AACE,mBAAOzB,QAAQ,CAACmB,GAAT,CAAa8J,QAAb,CAAP;AAhBJ;AAkBD;AAvBoB,KAAhB,CAAP;AAyBD;;AAnNgB","sourcesContent":["import JSONLDContextParser from 'jsonld-context-parser';\n//@ts-ignore\nimport PubSub from 'https://cdn.skypack.dev/pubsub-js';\nimport type { Resource } from '../../mixins/interfaces';\n\nconst ContextParser = JSONLDContextParser.ContextParser;\nconst myParser = new ContextParser();\n\nexport const base_context = {\n '@vocab': 'http://happy-dev.fr/owl/#',\n rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',\n rdfs: 'http://www.w3.org/2000/01/rdf-schema#',\n ldp: 'http://www.w3.org/ns/ldp#',\n foaf: 'http://xmlns.com/foaf/0.1/',\n name: 'rdfs:label',\n acl: 'http://www.w3.org/ns/auth/acl#',\n permissions: 'acl:accessControl',\n mode: 'acl:mode',\n geo: \"http://www.w3.org/2003/01/geo/wgs84_pos#\",\n lat: \"geo:lat\",\n lng: \"geo:long\"\n};\n\nclass Store {\n cache: Map<string, any>;\n subscriptionIndex: Map<string, any>; // index of all the containers per resource\n subscriptionVirtualContainersIndex: Map<string, any>; // index of all the containers per resource\n loadingList: Set<String>;\n headers: object;\n fetch: Promise<any> | undefined;\n session: Promise<any> | undefined;\n\n constructor(private storeOptions: StoreOptions) {\n this.cache = new Map();\n this.subscriptionIndex = new Map();\n this.subscriptionVirtualContainersIndex = new Map();\n this.loadingList = new Set();\n this.headers = {'Content-Type': 'application/ld+json'};\n this.fetch = this.storeOptions.fetchMethod;\n this.session = this.storeOptions.session;\n }\n\n /**\n * Fetch data and cache it\n * @param id - uri of the resource to fetch\n * @param context - context used to expand id and predicates when accessing the resource\n * @param idParent - uri of the parent caller used to expand uri for local files\n * @param localData - data to put in cache\n * @param forceFetch - force the fetch of data\n *\n * @returns The fetched resource\n *\n * @async\n */\n\n async getData(id: string, context:any = {}, idParent = \"\", localData?: object, forceFetch: boolean = false): Promise<Resource|null> {\n if (localData == null && this.cache.has(id) && !this.loadingList.has(id)) {\n const resource = this.get(id);\n if (resource && resource.isFullResource() && !forceFetch) return resource; // if resource is not complete, re-fetch it\n }\n\n return new Promise(async (resolve) => {\n document.addEventListener('resourceReady', this.resolveResource(id, resolve));\n\n if (this.loadingList.has(id)) return;\n this.loadingList.add(id);\n\n // Generate proxy\n const clientContext = await myParser.parse(context);\n let resource: any = null;\n if(this._isLocalId(id)) {\n if(localData == null) localData = {};\n localData[\"@id\"] = id;\n resource = localData;\n } else try {\n resource = localData || await this.fetchData(id, clientContext, idParent);\n } catch (error) { console.error(error) }\n if (!resource) {\n this.loadingList.delete(id);\n resolve(null);\n return;\n }\n const serverContext = await myParser.parse([resource['@context'] || {}]);\n const resourceProxy = new CustomGetter(id, resource, clientContext, serverContext, idParent).getProxy();\n\n // Cache proxy\n await this.cacheGraph(id, resourceProxy, clientContext, serverContext, idParent || id);\n this.loadingList.delete(id);\n document.dispatchEvent(new CustomEvent('resourceReady', { detail: { id: id, resource: this.get(id) } }));\n });\n }\n\n async fetchAuthn(iri: string, options: any) {\n let authenticated = false;\n if (this.session) authenticated = await this.session;\n\n if (this.fetch && authenticated) { // authenticated\n return this.fetch.then(fn => fn(iri, options))\n } else { // anonymous\n if (options.headers) options.headers = this._convertHeaders(options.headers);\n return fetch(iri, options).then(function(response) {\n if (options.method === \"PURGE\" && !response.ok && response.status === 404) {\n const err = new Error(\"PURGE call is returning 404\");\n throw err;\n }\n return response;\n });\n }\n }\n\n async fetchData(id: string, context = {}, idParent = \"\") {\n const iri = this._getAbsoluteIri(id, context, idParent);\n const headers = { ...this.headers, 'accept-language': this._getLanguage() };\n return this.fetchAuthn(iri, {\n method: 'GET',\n headers: headers,\n credentials: 'include'\n }).then(response => {\n if (!response.ok) return;\n return response.json()\n })\n }\n\n async cacheGraph(key: string, resource: any, clientContext: object, parentContext: object, parentId: string) {\n if (resource.properties) { // if proxy, cache it\n if (this.get(key)) { // if already cached, merge data\n this.cache.get(key).merge(resource);\n } else { // else, put in cache\n this.cache.set(key, resource);\n }\n }\n\n // Cache nested resources\n if (resource.getSubObjects) {\n for (let res of resource.getSubObjects()) {\n let newParentContext = parentContext;\n // If additional context in resource, use it to expand properties\n if (res['@context']) newParentContext = await myParser.parse({ ...parentContext, ...res['@context'] });\n const resourceProxy = new CustomGetter(res['@id'], res, clientContext, newParentContext, parentId).getProxy();\n // this.subscribeResourceTo(resource['@id'], res['@id']); // removed to prevent useless updates\n await this.cacheGraph(res['@id'], resourceProxy, clientContext, parentContext, parentId);\n }\n }\n\n // Cache children of container\n if (resource['@type'] == \"ldp:Container\" && resource.getChildren) {\n const cacheChildrenPromises: Promise<void>[] = [];\n for (let res of resource.getChildren()) {\n this.subscribeResourceTo(resource['@id'], res['@id']);\n cacheChildrenPromises.push(this.cacheGraph(res['@id'], res, clientContext, parentContext, parentId))\n }\n await Promise.all(cacheChildrenPromises);\n return;\n }\n\n // Create proxy, (fetch data) and cache resource\n if (resource['@id'] && !resource.properties) {\n if (resource['@id'].match(/^b\\d+$/)) return; // not anonymous node\n // Fetch data if\n if (resource['@type'] === \"sib:federatedContainer\" && resource['@cache'] !== 'false') { // if object is federated container\n await this.getData(resource['@id'], clientContext, parentId); // then init graph\n return;\n }\n const resourceProxy = new CustomGetter(resource['@id'], resource, clientContext, parentContext, parentId).getProxy();\n await this.cacheGraph(key, resourceProxy, clientContext, parentContext, parentId);\n }\n }\n\n /**\n * Update fetch\n * @param method - 'POST', 'PATCH', 'PUT', '_LOCAL'\n * @param resource - resource to send\n * @param id - uri to update\n * @returns - object\n */\n async _fetch(method: string, resource: object, id: string): Promise<any> {\n if (method !== '_LOCAL')\n return this.fetchAuthn(id, {\n method: method,\n headers: this.headers,\n body: JSON.stringify(resource),\n credentials: 'include'\n });\n\n const resourceProxy = store.get(id);\n const clientContext = resourceProxy ? resourceProxy.clientContext : resource['@context']\n this.clearCache(id);\n await this.getData(id, clientContext, '', resource);\n return {ok: true}\n }\n\n async _updateResource(method: string, resource: object, id: string) {\n if (!['POST', 'PUT', 'PATCH', '_LOCAL'].includes(method)) throw new Error('Error: method not allowed');\n\n const context = await myParser.parse([resource['@context'] || {}]); // parse context before expandTerm\n const expandedId = this._getExpandedId(id, context);\n return this._fetch(method, resource, id).then(async(response) => {\n if (response.ok) {\n if(method !== '_LOCAL') {\n await this.purge(id);\n this.clearCache(expandedId);\n } // clear cache\n this.getData(expandedId, resource['@context']).then(async () => { // re-fetch data\n const nestedResources = await this.getNestedResources(resource, id);\n const resourcesToRefresh = this.subscriptionVirtualContainersIndex.get(expandedId) || [];\n const resourcesToNotify = this.subscriptionIndex.get(expandedId) || [];\n\n return this.refreshResources([...nestedResources, ...resourcesToRefresh]) // refresh related resources\n .then(resourceIds => this.notifyResources([expandedId, ...resourceIds, ...resourcesToNotify])); // notify components\n });\n return response.headers?.get('Location') || null;\n } else {\n throw response;\n }\n });\n }\n\n /**\n * Clear cache and refetch data for a list of ids\n * @param resourceIds -\n * @returns - all the resource ids\n */\n async refreshResources(resourceIds: string[]) {\n resourceIds = [...new Set(resourceIds.filter(id => this.cache.has(id)))]; // remove duplicates and not cached resources\n const resourceWithContexts = resourceIds.map(resourceId => ({ \"id\": resourceId, \"context\": store.get(resourceId)?.clientContext }));\n for (const resource of resourceWithContexts) {\n if (!this._isLocalId(resource.id)) this.clearCache(resource.id);\n }\n await Promise.all(resourceWithContexts.map(({ id, context }) => this.getData(id, context || base_context)))\n return resourceIds;\n }\n /**\n * Notifies all components for a list of ids\n * @param resourceIds -\n */\n async notifyResources(resourceIds: string[]) {\n resourceIds = [...new Set(resourceIds)]; // remove duplicates\n for (const id of resourceIds) PubSub.publish(id);\n }\n\n /**\n * Return id of nested properties of a resource\n * @param resource - object\n * @param id - string\n */\n async getNestedResources(resource: object, id: string) {\n const cachedResource = store.get(id);\n if (!cachedResource || cachedResource.isContainer()) return [];\n let nestedProperties:any[] = [];\n const excludeKeys = ['@context'];\n for (let p of Object.keys(resource)) {\n if (resource[p]\n && typeof resource[p] === 'object'\n && !excludeKeys.includes(p)\n && resource[p]['@id']) {\n nestedProperties.push(resource[p]['@id']);\n }\n }\n return nestedProperties;\n }\n\n /**\n * Returns the resource with id from the cache\n * @param id - id of the resource to retrieve\n *\n * @returns Resource (Proxy) if in the cache, null otherwise\n */\n get(id: string): Resource | null {\n return this.cache.get(id) || null;\n }\n\n\n /**\n * Removes a resource from the cache\n * @param id - id of the resource to remove from the cache\n */\n clearCache(id: string): void {\n if (this.cache.has(id)) {\n // For federation, clear each source\n const resource = this.cache.get(id);\n if (resource['@type'] === 'ldp:Container') {\n resource['ldp:contains'].forEach((child: object) => {\n if (child && child['@type'] === 'ldp:Container') this.cache.delete(child['@id'])\n })\n }\n\n this.cache.delete(id);\n }\n }\n\n /**\n * Send data to create a local resource in a container\n * @param resource - resource to create\n * @param id - uri of the container to add resource. should start with ``\n *\n * @returns id of the posted resource\n */\n async setLocalData(resource: object, id: string): Promise<string | null> {\n return this._updateResource('_LOCAL', resource, id);\n }\n\n /**\n * Send a POST request to create a resource in a container\n * @param resource - resource to create\n * @param id - uri of the container to add resource\n *\n * @returns id of the posted resource\n */\n async post(resource: object, id: string): Promise<string | null> {\n return this._updateResource('POST', resource, id);\n }\n\n /**\n * Send a PUT request to edit a resource\n * @param resource - resource data to send\n * @param id - uri of the resource to edit\n *\n * @returns id of the edited resource\n */\n async put(resource: object, id: string): Promise<string | null> {\n return this._updateResource('PUT', resource, id);\n }\n\n /**\n * Send a PATCH request to edit a resource\n * @param resource - resource data to send\n * @param id - uri of the resource to patch\n *\n * @returns id of the edited resource\n */\n async patch(resource: object, id: string): Promise<string | null> {\n return this._updateResource('PATCH', resource, id);\n }\n\n /**\n * Send a PURGE request to remove a resource from REDIS AD cache\n * @param id - uri of the resource to patch\n *\n * @returns id of the edited resource\n */\n async purge(id: string) {\n console.log('Purging resource ' + id);\n await this.fetchAuthn(id, {\n method: \"PURGE\",\n headers: this.headers\n }).catch(function(error) {\n console.warn('No purge method allowed: ' + error)\n });\n\n try {\n const fullURL = new URL(id);\n var pathArray = fullURL.pathname.split('/');\n var containerUrl = fullURL.origin + '/' + pathArray[1];\n const headers = { ...this.headers, 'X-Cache-Purge-Match': 'startswith' };\n await this.fetchAuthn(containerUrl, {\n method: \"PURGE\",\n headers: headers\n }).catch(function(error) {\n console.warn('No purge method allowed: ' + error)\n });\n } catch (error) {\n console.warn('The resource ID is not a complete URL: ' + error);\n return;\n }\n }\n\n /**\n * Send a DELETE request to delete a resource\n * @param id - uri of the resource to delete\n * @param context - can be used to expand id\n *\n * @returns id of the deleted resource\n */\n async delete(id: string, context: object = {}) {\n const expandedId = this._getExpandedId(id, context);\n const deleted = await this.fetchAuthn(expandedId, {\n method: 'DELETE',\n headers: this.headers,\n credentials: 'include'\n });\n await this.purge(id);\n\n const resourcesToNotify = this.subscriptionIndex.get(expandedId) || [];\n const resourcesToRefresh = this.subscriptionVirtualContainersIndex.get(expandedId) || [];\n\n this.refreshResources([...resourcesToNotify, ...resourcesToRefresh])\n .then(resourceIds => this.notifyResources(resourceIds));\n\n return deleted;\n }\n\n /**\n * Convert headers object to Headers\n * @param headersObject - object\n * @returns {Headers}\n */\n _convertHeaders(headersObject: object): Headers {\n const headers = new Headers();\n for (const [key, value] of Object.entries(headersObject)){\n headers.set(key, value as string);\n }\n return headers;\n }\n\n _getExpandedId(id: string, context: object) {\n return (context && Object.keys(context)) ? ContextParser.expandTerm(id, context) : id;\n }\n\n _isLocalId(id: string) {\n return id.startsWith('store://local.');\n }\n\n /**\n * Make a resource listen changes of another one\n * @param resourceId - id of the resource which needs to be updated\n * @param nestedResourceId - id of the resource which will change\n */\n subscribeResourceTo(resourceId: string, nestedResourceId: string) {\n const existingSubscriptions = this.subscriptionIndex.get(nestedResourceId) || [];\n this.subscriptionIndex.set(nestedResourceId, [...new Set([...existingSubscriptions, resourceId])])\n }\n\n /**\n * Make a virtual container listen for changes of a resource\n * @param virtualContainerId - id of the container which needs to be updated\n * @param nestedResourceId - id of the resource which will change\n */\n subscribeVirtualContainerTo(virtualContainerId: string, nestedResourceId: string) {\n const existingSubscriptions = this.subscriptionVirtualContainersIndex.get(nestedResourceId) || [];\n this.subscriptionVirtualContainersIndex.set(nestedResourceId, [...new Set([...existingSubscriptions, virtualContainerId])])\n }\n\n /**\n * Return absolute IRI of the resource\n * @param id\n * @param context\n * @param parentId\n */\n _getAbsoluteIri(id: string, context: object, parentId: string): string {\n let iri = ContextParser.expandTerm(id, context); // expand if reduced ids\n if (parentId) { // and get full URL from parent caller for local files\n let parentIri = new URL(parentId, document.location.href).href;\n iri = new URL(iri, parentIri).href;\n } else {\n iri = new URL(iri, document.location.href).href;\n }\n return iri;\n }\n\n /**\n * Check if object is a full resource\n * @param resource\n */\n _resourceIsComplete(resource: object) {\n return !!(Object.keys(resource).filter(p => !p.startsWith('@')).length > 0 && resource['@id'])\n }\n\n /**\n * Return language of the users\n */\n _getLanguage() {\n return localStorage.getItem('language') || window.navigator.language.slice(0,2);\n }\n\n /**\n * Save the preferred language of the user\n * @param selectedLanguageCode\n */\n selectLanguage(selectedLanguageCode: string) {\n localStorage.setItem('language', selectedLanguageCode);\n }\n\n resolveResource = function(id: string, resolve) {\n const handler = function(event) {\n if (event.detail.id === id) {\n resolve(event.detail.resource);\n // TODO : callback\n document.removeEventListener('resourceReady', handler);\n }\n };\n return handler;\n };\n}\n\nlet store: Store;\nif (window.sibStore) {\n store = window.sibStore;\n} else {\n const sibAuth = document.querySelector('sib-auth');\n const storeOptions: StoreOptions = {}\n\n if (sibAuth) {\n const sibAuthDefined = customElements.whenDefined(sibAuth.localName);\n storeOptions.session = sibAuthDefined.then(() => (sibAuth as any).session)\n storeOptions.fetchMethod = sibAuthDefined.then(() => (sibAuth as any).getFetch())\n }\n\n store = new Store(storeOptions);\n window.sibStore = store;\n}\n\nexport {\n store\n};\n\n\nclass CustomGetter {\n resource: any; // content of the requested resource\n resourceId: string;\n clientContext: object; // context given by the app\n serverContext: object; // context given by the server\n parentId: string; // id of the parent resource, used to get the absolute url of the current resource\n\n constructor(resourceId: string, resource: object, clientContext: object, serverContext: object = {}, parentId: string = \"\") {\n this.clientContext = clientContext;\n this.serverContext = serverContext;\n this.parentId = parentId;\n this.resource = this.expandProperties({ ...resource }, serverContext);\n this.resourceId = resourceId;\n }\n\n /**\n * Expand all predicates of a resource with a given context\n * @param resource: object\n * @param context: object\n */\n expandProperties(resource: object, context: object | string) {\n for (let prop of Object.keys(resource)) {\n if (!prop) continue;\n this.objectReplaceProperty(resource, prop, ContextParser.expandTerm(prop, context as JSONLDContextParser.IJsonLdContextNormalized, true));\n }\n return resource\n }\n\n /**\n * Change the key of an object\n * @param object: object\n * @param oldProp: string - current key\n * @param newProp: string - new key to set\n */\n objectReplaceProperty(object: object, oldProp: string, newProp: string) {\n if (newProp !== oldProp) {\n Object.defineProperty(\n object,\n newProp,\n Object.getOwnPropertyDescriptor(object, oldProp) || ''\n );\n delete object[oldProp];\n }\n }\n\n /**\n * Get the property of a resource for a given path\n * @param path: string\n */\n async get(path: any) {\n if (!path) return;\n const path1: string[] = path.split('.');\n const path2: string[] = [];\n let value: any;\n if (!this.isFullResource()) { // if resource is not complete, fetch it first\n await this.getResource(this.resourceId, this.clientContext, this.parentId);\n }\n while (true) {\n try {\n value = this.resource[this.getExpandedPredicate(path1[0])];\n } catch (e) { break }\n\n if (path1.length <= 1) break; // no dot path\n const lastPath1El = path1.pop();\n if(lastPath1El) path2.unshift(lastPath1El);\n }\n if (path2.length === 0) { // end of the path\n if (!value || !value['@id']) return value; // no value or not a resource\n return await this.getResource(value['@id'], this.clientContext, this.parentId || this.resourceId); // return complete resource\n }\n if (!value) return undefined;\n let resource = await this.getResource(value['@id'], this.clientContext, this.parentId || this.resourceId);\n\n store.subscribeResourceTo(this.resourceId, value['@id']);\n return resource ? await resource[path2.join('.')] : undefined; // return value\n }\n\n /**\n * Cache resource in the store, and return the created proxy\n * @param id\n * @param context\n * @param iriParent\n * @param forceFetch\n */\n async getResource(id: string, context: object, iriParent: string, forceFetch: boolean = false): Promise<Resource | null> {\n return store.getData(id, context, iriParent, undefined, forceFetch);\n }\n\n /**\n * Return true if the resource is a container\n */\n isContainer(): boolean {\n return this.resource[\"@type\"] == \"ldp:Container\" || this.resource[\"@type\"] == \"sib:federatedContainer\";\n }\n\n /**\n * Get all properties of a resource\n */\n getProperties(): string[] {\n return Object.keys(this.resource).map(prop => this.getCompactedPredicate(prop));\n }\n\n /**\n * Get children of container as objects\n */\n getChildren(): object[] {\n return this.resource[this.getExpandedPredicate(\"ldp:contains\")] || [];\n }\n\n /**\n * Get children of container as Proxys\n */\n getLdpContains(): CustomGetter[] {\n const children = this.resource[this.getExpandedPredicate(\"ldp:contains\")];\n return children ? children.map((res: object) => store.get(res['@id'])) : [];\n }\n\n /**\n * Get all nested resource or containers which contains datas\n */\n getSubObjects() {\n let subObjects: any = [];\n for (let p of Object.keys(this.resource)) {\n let property = this.resource[p];\n if (!this.isFullNestedResource(property)) continue; // if not a resource, stop\n if (property['@type'] == \"ldp:Container\" &&\n (property['ldp:contains'] == undefined ||\n (property['ldp:contains'].length >= 1 && !this.isFullNestedResource(property['ldp:contains'][0])))\n ) continue; // if not a full container\n subObjects.push(property)\n }\n return subObjects;\n }\n\n merge(resource: CustomGetter) {\n this.resource = {...this.getResourceData(), ...resource.getResourceData()}\n }\n\n getResourceData(): object { return this.resource }\n\n /**\n * return true if prop is a resource with an @id and some properties\n * @param prop\n */\n isFullNestedResource(prop: any): boolean {\n return prop &&\n typeof prop == \"object\" &&\n prop['@id'] != undefined &&\n Object.keys(prop).filter(p => !p.startsWith('@')).length > 0;\n }\n /**\n * return true resource seems complete\n * @param prop\n */\n isFullResource(): boolean {\n return Object.keys(this.resource).filter(p => !p.startsWith('@')).length > 0;\n }\n\n async getPermissions(): Promise<string[]> {\n const permissionPredicate = this.getExpandedPredicate(\"permissions\");\n let permissions = this.resource[permissionPredicate];\n if (!permissions) { // if no permission, re-fetch data\n await this.getResource(this.resourceId, this.clientContext, this.parentId, true);\n permissions = this.resource[permissionPredicate];\n }\n return permissions ? permissions.map(perm => ContextParser.expandTerm(perm.mode['@type'], this.serverContext, true)) : [];\n }\n\n /**\n * Remove the resource from the cache\n */\n clearCache(): void {\n store.clearCache(this.resourceId);\n }\n\n getExpandedPredicate(property: string) { return ContextParser.expandTerm(property, this.clientContext, true) }\n getCompactedPredicate(property: string) { return ContextParser.compactIri(property, this.clientContext, true) }\n getCompactedIri(id: string) { return ContextParser.compactIri(id, this.clientContext) }\n toString() { return this.getCompactedIri(this.resource['@id']) }\n [Symbol.toPrimitive]() { return this.getCompactedIri(this.resource['@id']) }\n\n\n /**\n * Returns a Proxy which handles the different get requests\n */\n getProxy() {\n return new Proxy(this, {\n get: (resource, property) => {\n if (!this.resource) return undefined;\n if (typeof resource[property] === 'function') return resource[property].bind(resource)\n\n switch (property) {\n case '@id':\n return this.getCompactedIri(this.resource['@id']); // Compact @id if possible\n case '@type':\n return this.resource['@type']; // return synchronously\n case 'properties':\n return this.getProperties();\n case 'ldp:contains':\n return this.getLdpContains(); // returns standard arrays synchronously\n case 'permissions':\n return this.getPermissions(); // get expanded permissions\n case 'clientContext':\n return this.clientContext; // get saved client context to re-fetch easily a resource\n case 'then':\n return;\n default:\n return resource.get(property);\n }\n }\n })\n }\n}"]}
|
|
1
|
+
{"version":3,"sources":["store.ts"],"names":["JSONLDContextParser","PubSub","ContextParser","myParser","base_context","rdf","rdfs","ldp","foaf","name","acl","permissions","mode","geo","lat","lng","Store","constructor","storeOptions","id","resolve","handler","event","detail","resource","document","removeEventListener","cache","Map","subscriptionIndex","subscriptionVirtualContainersIndex","loadingList","Set","headers","fetch","fetchMethod","session","getData","context","idParent","localData","forceFetch","has","get","isFullResource","Promise","addEventListener","resolveResource","add","clientContext","parse","_isLocalId","fetchData","error","console","delete","serverContext","resourceProxy","CustomGetter","getProxy","cacheGraph","dispatchEvent","CustomEvent","fetchAuthn","iri","options","authenticated","then","fn","_convertHeaders","response","method","ok","status","err","Error","_getAbsoluteIri","_getLanguage","log","credentials","json","key","parentContext","parentId","properties","merge","set","getSubObjects","res","newParentContext","getChildren","cacheChildrenPromises","subscribeResourceTo","push","all","match","_fetch","body","JSON","stringify","store","clearCache","_updateResource","includes","expandedId","_getExpandedId","purge","nestedResources","getNestedResources","resourcesToRefresh","resourcesToNotify","refreshResources","resourceIds","notifyResources","filter","resourceWithContexts","map","resourceId","publish","cachedResource","isContainer","nestedProperties","excludeKeys","p","Object","keys","forEach","child","setLocalData","post","put","patch","catch","warn","fullURL","URL","pathArray","pathname","split","containerUrl","origin","deleted","headersObject","Headers","value","entries","expandTerm","startsWith","nestedResourceId","existingSubscriptions","subscribeVirtualContainerTo","virtualContainerId","parentIri","location","href","_resourceIsComplete","length","localStorage","getItem","window","navigator","language","slice","selectLanguage","selectedLanguageCode","setItem","sibStore","sibAuth","querySelector","sibAuthDefined","customElements","whenDefined","localName","getFetch","Symbol","toPrimitive","expandProperties","prop","objectReplaceProperty","object","oldProp","newProp","defineProperty","getOwnPropertyDescriptor","path","path1","path2","getResource","getExpandedPredicate","e","lastPath1El","pop","unshift","undefined","join","iriParent","getProperties","getCompactedPredicate","getLdpContains","children","subObjects","property","isFullNestedResource","getResourceData","getPermissions","permissionPredicate","perm","compactIri","getCompactedIri","toString","Proxy","bind"],"mappings":";;;;AAAA,OAAOA,mBAAP,MAAgC,uBAAhC,C,CACA;;AACA,OAAOC,MAAP,MAAmB,mCAAnB;AAGA,MAAMC,aAAa,GAAGF,mBAAmB,CAACE,aAA1C;AACA,MAAMC,QAAQ,GAAG,IAAID,aAAJ,EAAjB;AAEA,OAAO,MAAME,YAAY,GAAG;AAC1B,YAAU,2BADgB;AAE1BC,EAAAA,GAAG,EAAE,6CAFqB;AAG1BC,EAAAA,IAA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AOjL,QAAQ,CAACiL,QAAD,CAAR,CAAmBU,IAAnB,CAAwB3L,QAAxB,CAAP;;AAE9C,gBAAQiL,QAAR;AACE,eAAK,KAAL;AACE,gBAAI,KAAKjL,QAAL,CAAc,KAAd,CAAJ,EACE,OAAO,KAAKwL,eAAL,CAAqB,KAAKxL,QAAL,CAAc,KAAd,CAArB,CAAP,CADF,CACqD;AADrD,iBAGE8B,OAAO,CAACwB,GAAR,CAAY,KAAKtD,QAAjB,EAA2B,KAAKA,QAAL,CAAc,KAAd,CAA3B;AACA;;AACJ,eAAK,OAAL;AACE,mBAAO,KAAKA,QAAL,CAAc,OAAd,CAAP;AAA+B;;AACjC,eAAK,YAAL;AACE,mBAAO,KAAK4K,aAAL,EAAP;;AACF,eAAK,cAAL;AACE,mBAAO,KAAKE,cAAL,EAAP;AAA8B;;AAChC,eAAK,aAAL;AACE,mBAAO,KAAKM,cAAL,EAAP;AAA8B;;AAChC,eAAK,eAAL;AACE,mBAAO,KAAK3J,aAAZ;AAA2B;;AAC7B,eAAK,MAAL;AACE;;AACF;AACE,mBAAOzB,QAAQ,CAACmB,GAAT,CAAa8J,QAAb,CAAP;AApBJ;AAsBD;AA3BoB,KAAhB,CAAP;AA6BD;;AAvNgB","sourcesContent":["import JSONLDContextParser from 'jsonld-context-parser';\n//@ts-ignore\nimport PubSub from 'https://cdn.skypack.dev/pubsub-js';\nimport type { Resource } from '../../mixins/interfaces';\n\nconst ContextParser = JSONLDContextParser.ContextParser;\nconst myParser = new ContextParser();\n\nexport const base_context = {\n '@vocab': 'http://happy-dev.fr/owl/#',\n rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',\n rdfs: 'http://www.w3.org/2000/01/rdf-schema#',\n ldp: 'http://www.w3.org/ns/ldp#',\n foaf: 'http://xmlns.com/foaf/0.1/',\n name: 'rdfs:label',\n acl: 'http://www.w3.org/ns/auth/acl#',\n permissions: 'acl:accessControl',\n mode: 'acl:mode',\n geo: \"http://www.w3.org/2003/01/geo/wgs84_pos#\",\n lat: \"geo:lat\",\n lng: \"geo:long\"\n};\n\nclass Store {\n cache: Map<string, any>;\n subscriptionIndex: Map<string, any>; // index of all the containers per resource\n subscriptionVirtualContainersIndex: Map<string, any>; // index of all the containers per resource\n loadingList: Set<String>;\n headers: object;\n fetch: Promise<any> | undefined;\n session: Promise<any> | undefined;\n\n constructor(private storeOptions: StoreOptions) {\n this.cache = new Map();\n this.subscriptionIndex = new Map();\n this.subscriptionVirtualContainersIndex = new Map();\n this.loadingList = new Set();\n this.headers = {'Content-Type': 'application/ld+json', 'Cache-Control': 'must-revalidate'};\n this.fetch = this.storeOptions.fetchMethod;\n this.session = this.storeOptions.session;\n }\n\n /**\n * Fetch data and cache it\n * @param id - uri of the resource to fetch\n * @param context - context used to expand id and predicates when accessing the resource\n * @param idParent - uri of the parent caller used to expand uri for local files\n * @param localData - data to put in cache\n * @param forceFetch - force the fetch of data\n *\n * @returns The fetched resource\n *\n * @async\n */\n\n async getData(id: string, context:any = {}, idParent = \"\", localData?: object, forceFetch: boolean = false): Promise<Resource|null> {\n if (localData == null && this.cache.has(id) && !this.loadingList.has(id)) {\n const resource = this.get(id);\n if (resource && resource.isFullResource() && !forceFetch) return resource; // if resource is not complete, re-fetch it\n }\n\n return new Promise(async (resolve) => {\n document.addEventListener('resourceReady', this.resolveResource(id, resolve));\n\n if (this.loadingList.has(id)) return;\n this.loadingList.add(id);\n\n // Generate proxy\n const clientContext = await myParser.parse(context);\n let resource: any = null;\n if(this._isLocalId(id)) {\n if(localData == null) localData = {};\n localData[\"@id\"] = id;\n resource = localData;\n } else try {\n resource = localData || await this.fetchData(id, clientContext, idParent);\n } catch (error) { console.error(error) }\n if (!resource) {\n this.loadingList.delete(id);\n resolve(null);\n return;\n }\n const serverContext = await myParser.parse([resource['@context'] || {}]);\n const resourceProxy = new CustomGetter(id, resource, clientContext, serverContext, idParent).getProxy();\n\n // Cache proxy\n await this.cacheGraph(id, resourceProxy, clientContext, serverContext, idParent || id);\n this.loadingList.delete(id);\n document.dispatchEvent(new CustomEvent('resourceReady', { detail: { id: id, resource: this.get(id) } }));\n });\n }\n\n async fetchAuthn(iri: string, options: any) {\n let authenticated = false;\n if (this.session) authenticated = await this.session;\n\n if (this.fetch && authenticated) { // authenticated\n return this.fetch.then(fn => fn(iri, options))\n } else { // anonymous\n if (options.headers) options.headers = this._convertHeaders(options.headers);\n return fetch(iri, options).then(function(response) {\n if (options.method === \"PURGE\" && !response.ok && response.status === 404) {\n const err = new Error(\"PURGE call is returning 404\");\n throw err;\n }\n return response;\n });\n }\n }\n\n async fetchData(id: string, context = {}, idParent = \"\") {\n const iri = this._getAbsoluteIri(id, context, idParent);\n const headers = { ...this.headers, 'accept-language': this._getLanguage() };\n console.log(\"Request Headers:\", headers);\n return this.fetchAuthn(iri, {\n method: 'GET',\n headers: headers,\n credentials: 'include'\n }).then(response => {\n if (!response.ok) return;\n return response.json()\n })\n }\n\n async cacheGraph(key: string, resource: any, clientContext: object, parentContext: object, parentId: string) {\n if (resource.properties) { // if proxy, cache it\n if (this.get(key)) { // if already cached, merge data\n this.cache.get(key).merge(resource);\n } else { // else, put in cache\n this.cache.set(key, resource);\n }\n }\n\n // Cache nested resources\n if (resource.getSubObjects) {\n for (let res of resource.getSubObjects()) {\n let newParentContext = parentContext;\n // If additional context in resource, use it to expand properties\n if (res['@context']) newParentContext = await myParser.parse({ ...parentContext, ...res['@context'] });\n const resourceProxy = new CustomGetter(res['@id'], res, clientContext, newParentContext, parentId).getProxy();\n // this.subscribeResourceTo(resource['@id'], res['@id']); // removed to prevent useless updates\n await this.cacheGraph(res['@id'], resourceProxy, clientContext, parentContext, parentId);\n }\n }\n\n // Cache children of container\n if (resource['@type'] == \"ldp:Container\" && resource.getChildren) {\n const cacheChildrenPromises: Promise<void>[] = [];\n for (let res of resource.getChildren()) {\n this.subscribeResourceTo(resource['@id'], res['@id']);\n cacheChildrenPromises.push(this.cacheGraph(res['@id'], res, clientContext, parentContext, parentId))\n }\n await Promise.all(cacheChildrenPromises);\n return;\n }\n\n // Create proxy, (fetch data) and cache resource\n if (resource['@id'] && !resource.properties) {\n if (resource['@id'].match(/^b\\d+$/)) return; // not anonymous node\n // Fetch data if\n if (resource['@type'] === \"sib:federatedContainer\" && resource['@cache'] !== 'false') { // if object is federated container\n await this.getData(resource['@id'], clientContext, parentId); // then init graph\n return;\n }\n const resourceProxy = new CustomGetter(resource['@id'], resource, clientContext, parentContext, parentId).getProxy();\n await this.cacheGraph(key, resourceProxy, clientContext, parentContext, parentId);\n }\n }\n\n /**\n * Update fetch\n * @param method - 'POST', 'PATCH', 'PUT', '_LOCAL'\n * @param resource - resource to send\n * @param id - uri to update\n * @returns - object\n */\n async _fetch(method: string, resource: object, id: string): Promise<any> {\n if (method !== '_LOCAL')\n return this.fetchAuthn(id, {\n method: method,\n headers: this.headers,\n body: JSON.stringify(resource),\n credentials: 'include'\n });\n\n const resourceProxy = store.get(id);\n const clientContext = resourceProxy ? resourceProxy.clientContext : resource['@context']\n this.clearCache(id);\n await this.getData(id, clientContext, '', resource);\n return {ok: true}\n }\n\n async _updateResource(method: string, resource: object, id: string) {\n if (!['POST', 'PUT', 'PATCH', '_LOCAL'].includes(method)) throw new Error('Error: method not allowed');\n\n const context = await myParser.parse([resource['@context'] || {}]); // parse context before expandTerm\n const expandedId = this._getExpandedId(id, context);\n return this._fetch(method, resource, id).then(async(response) => {\n if (response.ok) {\n if(method !== '_LOCAL') {\n await this.purge(id);\n this.clearCache(expandedId);\n } // clear cache\n this.getData(expandedId, resource['@context']).then(async () => { // re-fetch data\n const nestedResources = await this.getNestedResources(resource, id);\n const resourcesToRefresh = this.subscriptionVirtualContainersIndex.get(expandedId) || [];\n const resourcesToNotify = this.subscriptionIndex.get(expandedId) || [];\n\n return this.refreshResources([...nestedResources, ...resourcesToRefresh]) // refresh related resources\n .then(resourceIds => this.notifyResources([expandedId, ...resourceIds, ...resourcesToNotify])); // notify components\n });\n return response.headers?.get('Location') || null;\n } else {\n throw response;\n }\n });\n }\n\n /**\n * Clear cache and refetch data for a list of ids\n * @param resourceIds -\n * @returns - all the resource ids\n */\n async refreshResources(resourceIds: string[]) {\n resourceIds = [...new Set(resourceIds.filter(id => this.cache.has(id)))]; // remove duplicates and not cached resources\n const resourceWithContexts = resourceIds.map(resourceId => ({ \"id\": resourceId, \"context\": store.get(resourceId)?.clientContext }));\n for (const resource of resourceWithContexts) {\n if (!this._isLocalId(resource.id)) this.clearCache(resource.id);\n }\n await Promise.all(resourceWithContexts.map(({ id, context }) => this.getData(id, context || base_context)))\n return resourceIds;\n }\n /**\n * Notifies all components for a list of ids\n * @param resourceIds -\n */\n async notifyResources(resourceIds: string[]) {\n resourceIds = [...new Set(resourceIds)]; // remove duplicates\n for (const id of resourceIds) PubSub.publish(id);\n }\n\n /**\n * Return id of nested properties of a resource\n * @param resource - object\n * @param id - string\n */\n async getNestedResources(resource: object, id: string) {\n const cachedResource = store.get(id);\n if (!cachedResource || cachedResource.isContainer()) return [];\n let nestedProperties:any[] = [];\n const excludeKeys = ['@context'];\n for (let p of Object.keys(resource)) {\n if (resource[p]\n && typeof resource[p] === 'object'\n && !excludeKeys.includes(p)\n && resource[p]['@id']) {\n nestedProperties.push(resource[p]['@id']);\n }\n }\n return nestedProperties;\n }\n\n /**\n * Returns the resource with id from the cache\n * @param id - id of the resource to retrieve\n *\n * @returns Resource (Proxy) if in the cache, null otherwise\n */\n get(id: string): Resource | null {\n return this.cache.get(id) || null;\n }\n\n\n /**\n * Removes a resource from the cache\n * @param id - id of the resource to remove from the cache\n */\n clearCache(id: string): void {\n if (this.cache.has(id)) {\n // For federation, clear each source\n const resource = this.cache.get(id);\n if (resource['@type'] === 'ldp:Container') {\n resource['ldp:contains'].forEach((child: object) => {\n if (child && child['@type'] === 'ldp:Container') this.cache.delete(child['@id'])\n })\n }\n\n this.cache.delete(id);\n }\n }\n\n /**\n * Send data to create a local resource in a container\n * @param resource - resource to create\n * @param id - uri of the container to add resource. should start with ``\n *\n * @returns id of the posted resource\n */\n async setLocalData(resource: object, id: string): Promise<string | null> {\n return this._updateResource('_LOCAL', resource, id);\n }\n\n /**\n * Send a POST request to create a resource in a container\n * @param resource - resource to create\n * @param id - uri of the container to add resource\n *\n * @returns id of the posted resource\n */\n async post(resource: object, id: string): Promise<string | null> {\n return this._updateResource('POST', resource, id);\n }\n\n /**\n * Send a PUT request to edit a resource\n * @param resource - resource data to send\n * @param id - uri of the resource to edit\n *\n * @returns id of the edited resource\n */\n async put(resource: object, id: string): Promise<string | null> {\n return this._updateResource('PUT', resource, id);\n }\n\n /**\n * Send a PATCH request to edit a resource\n * @param resource - resource data to send\n * @param id - uri of the resource to patch\n *\n * @returns id of the edited resource\n */\n async patch(resource: object, id: string): Promise<string | null> {\n return this._updateResource('PATCH', resource, id);\n }\n\n /**\n * Send a PURGE request to remove a resource from REDIS AD cache\n * @param id - uri of the resource to patch\n *\n * @returns id of the edited resource\n */\n async purge(id: string) {\n console.log('Purging resource ' + id);\n await this.fetchAuthn(id, {\n method: \"PURGE\",\n headers: this.headers\n }).catch(function(error) {\n console.warn('No purge method allowed: ' + error)\n });\n\n try {\n const fullURL = new URL(id);\n var pathArray = fullURL.pathname.split('/');\n var containerUrl = fullURL.origin + '/' + pathArray[1] + '/';\n const headers = { ...this.headers, 'X-Cache-Purge-Match': 'startswith' };\n await this.fetchAuthn(containerUrl, {\n method: \"PURGE\",\n headers: headers\n }).catch(function(error) {\n console.warn('No purge method allowed: ' + error)\n });\n } catch (error) {\n console.warn('The resource ID is not a complete URL: ' + error);\n return;\n }\n }\n\n /**\n * Send a DELETE request to delete a resource\n * @param id - uri of the resource to delete\n * @param context - can be used to expand id\n *\n * @returns id of the deleted resource\n */\n async delete(id: string, context: object = {}) {\n const expandedId = this._getExpandedId(id, context);\n const deleted = await this.fetchAuthn(expandedId, {\n method: 'DELETE',\n headers: this.headers,\n credentials: 'include'\n });\n await this.purge(id);\n\n const resourcesToNotify = this.subscriptionIndex.get(expandedId) || [];\n const resourcesToRefresh = this.subscriptionVirtualContainersIndex.get(expandedId) || [];\n\n this.refreshResources([...resourcesToNotify, ...resourcesToRefresh])\n .then(resourceIds => this.notifyResources(resourceIds));\n\n return deleted;\n }\n\n /**\n * Convert headers object to Headers\n * @param headersObject - object\n * @returns {Headers}\n */\n _convertHeaders(headersObject: object): Headers {\n const headers = new Headers();\n for (const [key, value] of Object.entries(headersObject)){\n headers.set(key, value as string);\n }\n return headers;\n }\n\n _getExpandedId(id: string, context: object) {\n return (context && Object.keys(context)) ? ContextParser.expandTerm(id, context) : id;\n }\n\n _isLocalId(id: string) {\n return id.startsWith('store://local.');\n }\n\n /**\n * Make a resource listen changes of another one\n * @param resourceId - id of the resource which needs to be updated\n * @param nestedResourceId - id of the resource which will change\n */\n subscribeResourceTo(resourceId: string, nestedResourceId: string) {\n const existingSubscriptions = this.subscriptionIndex.get(nestedResourceId) || [];\n this.subscriptionIndex.set(nestedResourceId, [...new Set([...existingSubscriptions, resourceId])])\n }\n\n /**\n * Make a virtual container listen for changes of a resource\n * @param virtualContainerId - id of the container which needs to be updated\n * @param nestedResourceId - id of the resource which will change\n */\n subscribeVirtualContainerTo(virtualContainerId: string, nestedResourceId: string) {\n const existingSubscriptions = this.subscriptionVirtualContainersIndex.get(nestedResourceId) || [];\n this.subscriptionVirtualContainersIndex.set(nestedResourceId, [...new Set([...existingSubscriptions, virtualContainerId])])\n }\n\n /**\n * Return absolute IRI of the resource\n * @param id\n * @param context\n * @param parentId\n */\n _getAbsoluteIri(id: string, context: object, parentId: string): string {\n let iri = ContextParser.expandTerm(id, context); // expand if reduced ids\n if (parentId) { // and get full URL from parent caller for local files\n let parentIri = new URL(parentId, document.location.href).href;\n iri = new URL(iri, parentIri).href;\n } else {\n iri = new URL(iri, document.location.href).href;\n }\n return iri;\n }\n\n /**\n * Check if object is a full resource\n * @param resource\n */\n _resourceIsComplete(resource: object) {\n return !!(Object.keys(resource).filter(p => !p.startsWith('@')).length > 0 && resource['@id'])\n }\n\n /**\n * Return language of the users\n */\n _getLanguage() {\n return localStorage.getItem('language') || window.navigator.language.slice(0,2);\n }\n\n /**\n * Save the preferred language of the user\n * @param selectedLanguageCode\n */\n selectLanguage(selectedLanguageCode: string) {\n localStorage.setItem('language', selectedLanguageCode);\n }\n\n resolveResource = function(id: string, resolve) {\n const handler = function(event) {\n if (event.detail.id === id) {\n resolve(event.detail.resource);\n // TODO : callback\n document.removeEventListener('resourceReady', handler);\n }\n };\n return handler;\n };\n}\n\nlet store: Store;\nif (window.sibStore) {\n store = window.sibStore;\n} else {\n const sibAuth = document.querySelector('sib-auth');\n const storeOptions: StoreOptions = {}\n\n if (sibAuth) {\n const sibAuthDefined = customElements.whenDefined(sibAuth.localName);\n storeOptions.session = sibAuthDefined.then(() => (sibAuth as any).session)\n storeOptions.fetchMethod = sibAuthDefined.then(() => (sibAuth as any).getFetch())\n }\n\n store = new Store(storeOptions);\n window.sibStore = store;\n}\n\nexport {\n store\n};\n\n\nclass CustomGetter {\n resource: any; // content of the requested resource\n resourceId: string;\n clientContext: object; // context given by the app\n serverContext: object; // context given by the server\n parentId: string; // id of the parent resource, used to get the absolute url of the current resource\n\n constructor(resourceId: string, resource: object, clientContext: object, serverContext: object = {}, parentId: string = \"\") {\n this.clientContext = clientContext;\n this.serverContext = serverContext;\n this.parentId = parentId;\n this.resource = this.expandProperties({ ...resource }, serverContext);\n this.resourceId = resourceId;\n }\n\n /**\n * Expand all predicates of a resource with a given context\n * @param resource: object\n * @param context: object\n */\n expandProperties(resource: object, context: object | string) {\n for (let prop of Object.keys(resource)) {\n if (!prop) continue;\n this.objectReplaceProperty(resource, prop, ContextParser.expandTerm(prop, context as JSONLDContextParser.IJsonLdContextNormalized, true));\n }\n return resource\n }\n\n /**\n * Change the key of an object\n * @param object: object\n * @param oldProp: string - current key\n * @param newProp: string - new key to set\n */\n objectReplaceProperty(object: object, oldProp: string, newProp: string) {\n if (newProp !== oldProp) {\n Object.defineProperty(\n object,\n newProp,\n Object.getOwnPropertyDescriptor(object, oldProp) || ''\n );\n delete object[oldProp];\n }\n }\n\n /**\n * Get the property of a resource for a given path\n * @param path: string\n */\n async get(path: any) {\n if (!path) return;\n const path1: string[] = path.split('.');\n const path2: string[] = [];\n let value: any;\n if (!this.isFullResource()) { // if resource is not complete, fetch it first\n await this.getResource(this.resourceId, this.clientContext, this.parentId);\n }\n while (true) {\n try {\n value = this.resource[this.getExpandedPredicate(path1[0])];\n } catch (e) { break }\n\n if (path1.length <= 1) break; // no dot path\n const lastPath1El = path1.pop();\n if(lastPath1El) path2.unshift(lastPath1El);\n }\n if (path2.length === 0) { // end of the path\n if (!value || !value['@id']) return value; // no value or not a resource\n return await this.getResource(value['@id'], this.clientContext, this.parentId || this.resourceId); // return complete resource\n }\n if (!value) return undefined;\n let resource = await this.getResource(value['@id'], this.clientContext, this.parentId || this.resourceId);\n\n store.subscribeResourceTo(this.resourceId, value['@id']);\n return resource ? await resource[path2.join('.')] : undefined; // return value\n }\n\n /**\n * Cache resource in the store, and return the created proxy\n * @param id\n * @param context\n * @param iriParent\n * @param forceFetch\n */\n async getResource(id: string, context: object, iriParent: string, forceFetch: boolean = false): Promise<Resource | null> {\n return store.getData(id, context, iriParent, undefined, forceFetch);\n }\n\n /**\n * Return true if the resource is a container\n */\n isContainer(): boolean {\n return this.resource[\"@type\"] == \"ldp:Container\" || this.resource[\"@type\"] == \"sib:federatedContainer\";\n }\n\n /**\n * Get all properties of a resource\n */\n getProperties(): string[] {\n return Object.keys(this.resource).map(prop => this.getCompactedPredicate(prop));\n }\n\n /**\n * Get children of container as objects\n */\n getChildren(): object[] {\n return this.resource[this.getExpandedPredicate(\"ldp:contains\")] || [];\n }\n\n /**\n * Get children of container as Proxys\n */\n getLdpContains(): CustomGetter[] {\n const children = this.resource[this.getExpandedPredicate(\"ldp:contains\")];\n return children ? children.map((res: object) => store.get(res['@id'])) : [];\n }\n\n /**\n * Get all nested resource or containers which contains datas\n */\n getSubObjects() {\n let subObjects: any = [];\n for (let p of Object.keys(this.resource)) {\n let property = this.resource[p];\n if (!this.isFullNestedResource(property)) continue; // if not a resource, stop\n if (property['@type'] == \"ldp:Container\" &&\n (property['ldp:contains'] == undefined ||\n (property['ldp:contains'].length >= 1 && !this.isFullNestedResource(property['ldp:contains'][0])))\n ) continue; // if not a full container\n subObjects.push(property)\n }\n return subObjects;\n }\n\n merge(resource: CustomGetter) {\n this.resource = {...this.getResourceData(), ...resource.getResourceData()}\n }\n\n getResourceData(): object { return this.resource }\n\n /**\n * return true if prop is a resource with an @id and some properties\n * @param prop\n */\n isFullNestedResource(prop: any): boolean {\n return prop &&\n typeof prop == \"object\" &&\n prop['@id'] != undefined &&\n Object.keys(prop).filter(p => !p.startsWith('@')).length > 0;\n }\n /**\n * return true resource seems complete\n * @param prop\n */\n isFullResource(): boolean {\n return Object.keys(this.resource).filter(p => !p.startsWith('@')).length > 0;\n }\n\n async getPermissions(): Promise<string[]> {\n const permissionPredicate = this.getExpandedPredicate(\"permissions\");\n let permissions = this.resource[permissionPredicate];\n if (!permissions) { // if no permission, re-fetch data\n await this.getResource(this.resourceId, this.clientContext, this.parentId, true);\n permissions = this.resource[permissionPredicate];\n }\n return permissions ? permissions.map(perm => ContextParser.expandTerm(perm.mode['@type'], this.serverContext, true)) : [];\n }\n\n /**\n * Remove the resource from the cache\n */\n clearCache(): void {\n store.clearCache(this.resourceId);\n }\n\n getExpandedPredicate(property: string) { return ContextParser.expandTerm(property, this.clientContext, true) }\n getCompactedPredicate(property: string) { return ContextParser.compactIri(property, this.clientContext, true) }\n getCompactedIri(id: string) { return ContextParser.compactIri(id, this.clientContext) }\n toString() { return this.getCompactedIri(this.resource['@id']) }\n [Symbol.toPrimitive]() { return this.getCompactedIri(this.resource['@id']) }\n\n\n /**\n * Returns a Proxy which handles the different get requests\n */\n getProxy() {\n return new Proxy(this, {\n get: (resource, property) => {\n if (!this.resource) return undefined;\n if (typeof resource[property] === 'function') return resource[property].bind(resource)\n\n switch (property) {\n case '@id':\n if (this.resource['@id'])\n return this.getCompactedIri(this.resource['@id']); // Compact @id if possible\n else\n console.log(this.resource, this.resource['@id']);\n return;\n case '@type':\n return this.resource['@type']; // return synchronously\n case 'properties':\n return this.getProperties();\n case 'ldp:contains':\n return this.getLdpContains(); // returns standard arrays synchronously\n case 'permissions':\n return this.getPermissions(); // get expanded permissions\n case 'clientContext':\n return this.clientContext; // get saved client context to re-fetch easily a resource\n case 'then':\n return;\n default:\n return resource.get(property);\n }\n }\n })\n }\n}"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { searchInResources } from '../libs/filter.js';
|
|
2
2
|
const FilterMixin = {
|
|
3
3
|
name: 'filter-mixin',
|
|
4
4
|
use: [],
|
|
@@ -55,7 +55,7 @@ const FilterMixin = {
|
|
|
55
55
|
if (this.filteredBy || this.searchFields) {
|
|
56
56
|
if (!this.searchCount.has(context)) this.searchCount.set(context, 1);
|
|
57
57
|
if (!this.searchForm) await this.createFilter(context);
|
|
58
|
-
const filteredResources = await
|
|
58
|
+
const filteredResources = await searchInResources(resources, this.filters, this.fields, this.searchForm);
|
|
59
59
|
resources = resources.filter((_v, index) => filteredResources[index]);
|
|
60
60
|
}
|
|
61
61
|
|
|
@@ -70,56 +70,6 @@ const FilterMixin = {
|
|
|
70
70
|
await this.populate();
|
|
71
71
|
},
|
|
72
72
|
|
|
73
|
-
async matchValue(subject, query) {
|
|
74
|
-
var _subject$isContainer;
|
|
75
|
-
|
|
76
|
-
if (subject == null && query.value === '') return true; // filter not set and subject not existing -> ignore filter
|
|
77
|
-
|
|
78
|
-
if (subject == null) return false; // property does not exist on resource
|
|
79
|
-
// Filter on a container
|
|
80
|
-
|
|
81
|
-
if (query.list) {
|
|
82
|
-
if (query.value.length === 0) return true;
|
|
83
|
-
|
|
84
|
-
for (const v of query.value) {
|
|
85
|
-
const q = {
|
|
86
|
-
type: query.type,
|
|
87
|
-
value: v
|
|
88
|
-
};
|
|
89
|
-
if (await this.matchValue(subject, q)) return true;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if ((_subject$isContainer = subject.isContainer) !== null && _subject$isContainer !== void 0 && _subject$isContainer.call(subject)) {
|
|
96
|
-
let ret = Promise.resolve(query.value === ''); // if no query, return a match
|
|
97
|
-
|
|
98
|
-
for (const value of subject['ldp:contains']) {
|
|
99
|
-
ret = (await ret) || (await this.matchValue(value, query));
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return ret;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return compare[query.type](subject, query.value);
|
|
106
|
-
},
|
|
107
|
-
|
|
108
|
-
async matchFilter(resource, filter, query) {
|
|
109
|
-
let fields = [];
|
|
110
|
-
if (this.isSet(filter)) fields = this.getSet(filter);else if (this.isSearchField(filter)) fields = this.getSearchField(filter); // search on 1 field
|
|
111
|
-
|
|
112
|
-
if (fields.length == 0) return this.matchValue(await resource[filter], query); // search on multiple fields
|
|
113
|
-
|
|
114
|
-
return fields.reduce( // return true if it matches at least one of the fields
|
|
115
|
-
async (initial, field) => (await initial) || (await this.matchFilter(resource, field, query)), Promise.resolve(false));
|
|
116
|
-
},
|
|
117
|
-
|
|
118
|
-
async matchFilters(resource) {
|
|
119
|
-
//return true if all filters values are contained in the corresponding field of the resource
|
|
120
|
-
return Object.keys(this.filters).reduce(async (initial, filter) => (await initial) && (await this.matchFilter(resource, filter, this.filters[filter])), Promise.resolve(true));
|
|
121
|
-
},
|
|
122
|
-
|
|
123
73
|
async getValuesOfField(field) {
|
|
124
74
|
const arrayOfDataObjects = this.resource['ldp:contains'];
|
|
125
75
|
const arrayOfDataIds = [];
|
|
@@ -179,15 +129,6 @@ const FilterMixin = {
|
|
|
179
129
|
});
|
|
180
130
|
this.element.insertBefore(this.searchForm, this.element.firstChild);
|
|
181
131
|
await this.searchForm.component.populate();
|
|
182
|
-
},
|
|
183
|
-
|
|
184
|
-
// Search fields
|
|
185
|
-
isSearchField(field) {
|
|
186
|
-
return this.searchForm.hasAttribute('search-' + field);
|
|
187
|
-
},
|
|
188
|
-
|
|
189
|
-
getSearchField(field) {
|
|
190
|
-
return parseFieldsString(this.searchForm.getAttribute('search-' + field));
|
|
191
132
|
}
|
|
192
133
|
|
|
193
134
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["filterMixin.ts"],"names":["compare","parseFieldsString","FilterMixin","name","use","initialState","searchCount","attributes","searchFields","type","String","default","filteredBy","callback","newValue","searchForm","getAttribute","component","detach","populate","created","Map","element","addEventListener","window","document","contains","updateAutoRanges","attached","listPostProcessors","push","filterCallback","bind","filters","value","filterList","resources","div","context","has","set","createFilter","filteredResources","Promise","all","map","matchFilters","filter","_v","index","nextProcessor","shift","get","resource","empty","matchValue","subject","query","list","length","v","q","isContainer","ret","resolve","matchFilter","fields","isSet","getSet","isSearchField","getSearchField","reduce","initial","field","Object","keys","getValuesOfField","arrayOfDataObjects","arrayOfDataIds","obj","nextArrayOfObjects","console","warn","nextArrayOfIds","getElementById","createElement","attach","toggleAttribute","searchAttributes","Array","from","attr","startsWith","replace","forEach","setAttribute","insertBefore","firstChild","hasAttribute"],"mappings":"AAAA,SAASA,OAAT,EAAkBC,iBAAlB,QAA2C,iBAA3C;AAEA,MAAMC,WAAW,GAAG;AAClBC,EAAAA,IAAI,EAAE,cADY;AAElBC,EAAAA,GAAG,EAAE,EAFa;AAGlBC,EAAAA,YAAY,EAAE;AACZC,IAAAA,WAAW,EAAE;AADD,GAHI;AAMlBC,EAAAA,UAAU,EAAE;AACVC,IAAAA,YAAY,EAAE;AACZC,MAAAA,IAAI,EAAEC,MADM;AAEZC,MAAAA,OAAO,EAAE;AAFG,KADJ;AAKVC,IAAAA,UAAU,EAAE;AACVH,MAAAA,IAAI,EAAEC,MADI;AAEVC,MAAAA,OAAO,EAAE,IAFC;;AAGVE,MAAAA,QAAQ,CAACC,QAAD,EAAmB;AACzB;AACA,YAAIA,QAAQ,IAAI,KAAKC,U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,OAAjB,CAAyB,CAAC;AAAC3F,MAAAA,IAAD;AAAO+B,MAAAA;AAAP,KAAD,KAAmB;AAC1C,WAAKnB,UAAL,CAAgBgF,YAAhB,CAA6B5F,IAA7B,EAAmC+B,KAAnC;AACD,KAFD;AAIA,SAAKZ,OAAL,CAAa0E,YAAb,CAA0B,KAAKjF,UAA/B,EAA2C,KAAKO,OAAL,CAAa2E,UAAxD;AACA,UAAM,KAAKlF,UAAL,CAAgBE,SAAhB,CAA0BE,QAA1B,EAAN;AACD,GAhKiB;;AAiKlB;AACAkD,EAAAA,aAAa,CAACI,KAAD,EAAgB;AAC3B,WAAO,KAAK1D,UAAL,CAAgBmF,YAAhB,CAA6B,YAAYzB,KAAzC,CAAP;AACD,GApKiB;;AAqKlBH,EAAAA,cAAc,CAACG,KAAD,EAA0B;AACtC,WAAOxE,iBAAiB,CAAC,KAAKc,UAAL,CAAgBC,YAAhB,CAA6B,YAAYyD,KAAzC,CAAD,CAAxB;AACD;;AAvKiB,CAApB;AA0KA,SACEvE,WADF","sourcesContent":["import { compare, parseFieldsString } from '../libs/helpers';\n\nconst FilterMixin = {\n name: 'filter-mixin',\n use: [],\n initialState: {\n searchCount: null,\n },\n attributes: {\n searchFields: {\n type: String,\n default: null\n },\n filteredBy: {\n type: String,\n default: null,\n callback(newValue: string) {\n // if we change search form, re-populate\n if (newValue && this.searchForm && newValue !== this.searchForm.getAttribute('id')) {\n this.searchForm.component.detach(this);\n this.searchForm = null;\n this.populate();\n }\n }\n }\n },\n created() {\n this.searchCount = new Map();\n this.element.addEventListener('populate', () => {\n if (!window.document.contains(this.element)) return;\n this.searchForm?.component.updateAutoRanges();\n })\n },\n attached(): void {\n this.listPostProcessors.push(this.filterCallback.bind(this));\n },\n get filters(): object {\n return this.searchForm?.component.value ?? {};\n },\n set filters(filters) {\n this.searchForm.component.value = filters;\n this.filterList();\n },\n async filterCallback(resources: object[], listPostProcessors: Function[], div: HTMLElement, context: string): Promise<void> {\n if (this.filteredBy || this.searchFields) {\n if (!this.searchCount.has(context)) this.searchCount.set(context, 1);\n if (!this.searchForm) await this.createFilter(context);\n const filteredResources = await Promise.all(resources.map(this.matchFilters.bind(this)));\n resources =\tresources.filter((_v, index) => filteredResources[index]);\n }\n\n const nextProcessor = listPostProcessors.shift();\n if(nextProcessor) await nextProcessor(resources, listPostProcessors, div, context + (this.searchCount.get(context) || ''));\n },\n async filterList(context: string): Promise<void> {\n this.searchCount.set(context, this.searchCount.get(context) + 1);\n if (!this.resource) return;\n this.empty();\n await this.populate();\n },\n async matchValue(subject, query): Promise<boolean> {\n if (subject == null && query.value === '') return true; // filter not set and subject not existing -> ignore filter\n if (subject == null) return false; // property does not exist on resource\n // Filter on a container\n if (query.list) {\n if(query.value.length === 0) return true;\n for(const v of query.value) {\n const q = {\n type: query.type,\n value: v,\n }\n if(await this.matchValue(subject, q)) return true;\n }\n return false;\n }\n if (subject.isContainer?.()) {\n let ret = Promise.resolve(query.value === ''); // if no query, return a match\n for (const value of subject['ldp:contains']) {\n ret = await ret || await this.matchValue(value, query)\n }\n return ret;\n }\n return compare[query.type](subject, query.value);\n },\n async matchFilter(resource: object, filter: string, query: any): Promise<boolean> {\n let fields: string[] = [];\n if (this.isSet(filter)) fields = this.getSet(filter);\n else if (this.isSearchField(filter)) fields = this.getSearchField(filter);\n\n // search on 1 field\n if (fields.length == 0)\n return this.matchValue(await resource[filter], query);\n\n // search on multiple fields\n return fields.reduce( // return true if it matches at least one of the fields\n async (initial, field) => await initial || await this.matchFilter(resource, field, query),\n Promise.resolve(false),\n );\n },\n async matchFilters(resource: object): Promise<boolean> {\n //return true if all filters values are contained in the corresponding field of the resource\n return Object.keys(this.filters).reduce(\n async (initial, filter) =>\n await initial && await this.matchFilter(resource, filter, this.filters[filter]),\n Promise.resolve(true)\n );\n },\n async getValuesOfField(field: string) {\n const arrayOfDataObjects = this.resource['ldp:contains'];\n const arrayOfDataIds: string[] = [];\n for (const obj of arrayOfDataObjects) {\n // for each element, if it's an object, catch all elements in 'ldp:contains' key\n const nextArrayOfObjects = await obj[field];\n if (!nextArrayOfObjects) continue;\n\n if (typeof nextArrayOfObjects !== \"object\") {\n console.warn(`The format value of ${field} is not suitable with auto-range-[field] attribute`);\n continue;\n }\n\n const nextArrayOfIds = nextArrayOfObjects['ldp:contains'];\n for (const obj of nextArrayOfIds) {\n // catch each element id\n arrayOfDataIds.push(obj['@id']);\n }\n if (nextArrayOfObjects['@type'] !== 'ldp:Container') {\n // if no element in 'ldp:contains', catch object id\n arrayOfDataIds.push(nextArrayOfObjects['@id']);\n }\n }\n return arrayOfDataIds;\n },\n async createFilter(context: string): Promise<void> {\n const filteredBy = this.filteredBy;\n if (filteredBy != null) {\n this.searchForm = document.getElementById(filteredBy)\n if (!this.searchForm) throw `#${filteredBy} is not in DOM`;\n } else {\n this.searchForm = document.createElement(`solid-form-search`);\n }\n this.searchForm.component.attach(this);\n this.searchForm.addEventListener('formChange', () => {\n this.filterList(context);\n });\n this.searchForm.toggleAttribute('naked', true);\n\n if (filteredBy) return;\n\n //pass attributes to search form\n const searchAttributes = Array.from((this.element as Element).attributes)\n .filter(attr => attr['name'].startsWith('search-'))\n .map(attr => ({\n name: attr['name'].replace('search-', ''),\n value: attr['value'],\n }));\n\n searchAttributes.forEach(({name, value}) => {\n this.searchForm.setAttribute(name, value);\n });\n\n this.element.insertBefore(this.searchForm, this.element.firstChild);\n await this.searchForm.component.populate();\n },\n // Search fields\n isSearchField(field: string) {\n return this.searchForm.hasAttribute('search-' + field);\n },\n getSearchField(field: string): string[] {\n return parseFieldsString(this.searchForm.getAttribute('search-' + field));\n },\n}\n\nexport {\n FilterMixin\n}"]}
|
|
1
|
+
{"version":3,"sources":["filterMixin.ts"],"names":["searchInResources","FilterMixin","name","use","initialState","searchCount","attributes","searchFields","type","String","default","filteredBy","callback","newValue","searchForm","getAttribute","component","detach","populate","created","Map","element","addEventListener","window","document","contains","updateAutoRanges","attached","listPostProcessors","push","filterCallback","bind","filters","value","filterList","resources","div","context","has","set","createFilter","filteredResources","fields","filter","_v","index","nextProcessor","shift","get","resource","empty","getValuesOfField","field","arrayOfDataObjects","arrayOfDataIds","obj","nextArrayOfObjects","console","warn","nextArrayOfIds","getElementById","createElement","attach","toggleAttribute","searchAttributes","Array","from","attr","startsWith","map","replace","forEach","setAttribute","insertBefore","firstChild"],"mappings":"AACA,SAASA,iBAAT,QAAkC,gBAAlC;AAEA,MAAMC,WAAW,GAAG;AAClBC,EAAAA,IAAI,EAAE,cADY;AAElBC,EAAAA,GAAG,EAAE,EAFa;AAGlBC,EAAAA,YAAY,EAAE;AACZC,IAAAA,WAAW,EAAE;AADD,GAHI;AAMlBC,EAAAA,UAAU,EAAE;AACVC,IAAAA,YAAY,EAAE;AACZC,MAAAA,IAAI,EAAEC,MADM;AAEZC,MAAAA,OAAO,EAAE;AAFG,KADJ;AAKVC,IAAAA,UAAU,EAAE;AACVH,MAAAA,IAAI,EAAEC,MADI;AAEVC,MAAAA,OAAO,EAAE,IAFC;;AAGVE,MAAAA,QAAQ,CAACC,QAAD,EAAmB;AACzB;AACA,YAAIA,QAAQ,IAAI,KAAKC,UAAjB,IAA+BD,QAAQ,KAAK,KAAKC,UAAL,CAAgBC,YAAhB,CAA6B,IAA7B,CAAhD,EAAoF;AAClF,eAAKD,UAAL,CAAgBE,SAAhB,CAA0BC,MAA1B,CAAiC,IAAjC;AACA,eAAKH,UAAL,GAAkB,IAAlB;AACA,eAAKI,QAAL;AACD;AACF;;AAVS;AALF,GANM;;AAwBlBC,EAAAA,OAAO,GAAG;AACR,SAAKd,WAAL,GAAmB,IAAIe,GAAJ,EAAnB;AACA,SAAKC,OAAL,CAAaC,gBAAb,CAA8B,UAA9B,EAA0C,MAAM;AAAA;;AAC9C,UAAI,CAACC,MAAM,CAACC,QAAP,CAAgBC,QAAhB,CAAyB,KAAKJ,OAA9B,CAAL,EAA6C;AAC7C,+BAAKP,UAAL,sEAAiBE,SAAjB,CAA2BU,gBAA3B;AACD,KAHD;AAID,GA9Bi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A,SACEjB,WADF","sourcesContent":["import type { SearchQuery } from '../libs/interfaces';\nimport { searchInResources } from '../libs/filter';\n\nconst FilterMixin = {\n name: 'filter-mixin',\n use: [],\n initialState: {\n searchCount: null,\n },\n attributes: {\n searchFields: {\n type: String,\n default: null\n },\n filteredBy: {\n type: String,\n default: null,\n callback(newValue: string) {\n // if we change search form, re-populate\n if (newValue && this.searchForm && newValue !== this.searchForm.getAttribute('id')) {\n this.searchForm.component.detach(this);\n this.searchForm = null;\n this.populate();\n }\n }\n }\n },\n created() {\n this.searchCount = new Map();\n this.element.addEventListener('populate', () => {\n if (!window.document.contains(this.element)) return;\n this.searchForm?.component.updateAutoRanges();\n })\n },\n attached(): void {\n this.listPostProcessors.push(this.filterCallback.bind(this));\n },\n get filters(): SearchQuery {\n return this.searchForm?.component.value ?? {};\n },\n set filters(filters) {\n this.searchForm.component.value = filters;\n this.filterList();\n },\n async filterCallback(resources: object[], listPostProcessors: Function[], div: HTMLElement, context: string): Promise<void> {\n if (this.filteredBy || this.searchFields) {\n if (!this.searchCount.has(context)) this.searchCount.set(context, 1);\n if (!this.searchForm) await this.createFilter(context);\n const filteredResources = await searchInResources(\n resources,\n this.filters,\n this.fields,\n this.searchForm\n );\n resources =\tresources.filter((_v, index) => filteredResources[index]);\n }\n\n const nextProcessor = listPostProcessors.shift();\n if(nextProcessor) await nextProcessor(resources, listPostProcessors, div, context + (this.searchCount.get(context) || ''));\n },\n async filterList(context: string): Promise<void> {\n this.searchCount.set(context, this.searchCount.get(context) + 1);\n if (!this.resource) return;\n this.empty();\n await this.populate();\n },\n async getValuesOfField(field: string) {\n const arrayOfDataObjects = this.resource['ldp:contains'];\n const arrayOfDataIds: string[] = [];\n for (const obj of arrayOfDataObjects) {\n // for each element, if it's an object, catch all elements in 'ldp:contains' key\n const nextArrayOfObjects = await obj[field];\n if (!nextArrayOfObjects) continue;\n\n if (typeof nextArrayOfObjects !== \"object\") {\n console.warn(`The format value of ${field} is not suitable with auto-range-[field] attribute`);\n continue;\n }\n\n const nextArrayOfIds = nextArrayOfObjects['ldp:contains'];\n for (const obj of nextArrayOfIds) {\n // catch each element id\n arrayOfDataIds.push(obj['@id']);\n }\n if (nextArrayOfObjects['@type'] !== 'ldp:Container') {\n // if no element in 'ldp:contains', catch object id\n arrayOfDataIds.push(nextArrayOfObjects['@id']);\n }\n }\n return arrayOfDataIds;\n },\n async createFilter(context: string): Promise<void> {\n const filteredBy = this.filteredBy;\n if (filteredBy != null) {\n this.searchForm = document.getElementById(filteredBy)\n if (!this.searchForm) throw `#${filteredBy} is not in DOM`;\n } else {\n this.searchForm = document.createElement(`solid-form-search`);\n }\n this.searchForm.component.attach(this);\n this.searchForm.addEventListener('formChange', () => {\n this.filterList(context);\n });\n this.searchForm.toggleAttribute('naked', true);\n\n if (filteredBy) return;\n\n //pass attributes to search form\n const searchAttributes = Array.from((this.element as Element).attributes)\n .filter(attr => attr['name'].startsWith('search-'))\n .map(attr => ({\n name: attr['name'].replace('search-', ''),\n value: attr['value'],\n }));\n\n searchAttributes.forEach(({name, value}) => {\n this.searchForm.setAttribute(name, value);\n });\n\n this.element.insertBefore(this.searchForm, this.element.firstChild);\n await this.searchForm.component.populate();\n },\n}\n\nexport {\n FilterMixin\n}"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startinblox/core",
|
|
3
|
-
"version": "0.17.21-beta.
|
|
3
|
+
"version": "0.17.21-beta.9",
|
|
4
4
|
"description": "This is a series of web component respecting both the web components standards and the Linked Data Platform convention.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|