@arpproject/recrate 0.1.7-test3 → 0.1.7-test6
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/app/App.d.ts +2 -0
- package/dist/app/EmbeddedComponent.d.ts +3 -0
- package/dist/app/index.d.ts +0 -0
- package/dist/app/lookup.d.ts +82 -0
- package/dist/crate-builder/CrateManager/contexts.d.ts +6 -0
- package/dist/crate-builder/CrateManager/crate-manager-benchmarking.spec.d.ts +1 -0
- package/dist/crate-builder/CrateManager/crate-manager-loading-exporting.spec.d.ts +1 -0
- package/dist/crate-builder/CrateManager/crate-manager-operations.spec.d.ts +0 -0
- package/dist/crate-builder/CrateManager/crate-manager.d.ts +641 -0
- package/dist/crate-builder/CrateManager/crate-manager.spec.d.ts +1 -0
- package/dist/crate-builder/CrateManager/lib.d.ts +26 -0
- package/dist/crate-builder/CrateManager/lib.spec.d.ts +1 -0
- package/dist/crate-builder/CrateManager/profile-manager.d.ts +143 -0
- package/dist/crate-builder/CrateManager/profile-manager.spec.d.ts +1 -0
- package/{src/crate-builder/CrateManager/schema-type-definitions.json → dist/crate-builder/CrateManager/schema-type-definitions.json.d.ts} +4 -1
- package/dist/crate-builder/CrateManager/validate-identifier.d.ts +10 -0
- package/dist/crate-builder/CrateManager/validate-identifier.spec.d.ts +1 -0
- package/dist/crate-builder/RenderEntity/Add.d.ts +26 -0
- package/dist/crate-builder/RenderEntity/AddControl.d.ts +14 -0
- package/dist/crate-builder/RenderEntity/AddControl.stories.d.ts +29 -0
- package/dist/crate-builder/RenderEntity/AutoComplete.d.ts +12 -0
- package/dist/crate-builder/RenderEntity/BulkAdd.d.ts +10 -0
- package/dist/crate-builder/RenderEntity/DeleteProperty.d.ts +8 -0
- package/dist/crate-builder/RenderEntity/DialogAddProperty.d.ts +9 -0
- package/dist/crate-builder/RenderEntity/DialogBrowseEntities.d.ts +8 -0
- package/dist/crate-builder/RenderEntity/DialogEditContext.d.ts +8 -0
- package/dist/crate-builder/RenderEntity/DialogPreviewCrate.d.ts +7 -0
- package/dist/crate-builder/RenderEntity/DialogSaveCrateAsTemplate.d.ts +13 -0
- package/dist/crate-builder/RenderEntity/DialogSaveEntityTemplate.d.ts +14 -0
- package/dist/crate-builder/RenderEntity/DisplayPropertyName.d.ts +8 -0
- package/dist/crate-builder/RenderEntity/DisplayPropertyName.stories.d.ts +6 -0
- package/dist/crate-builder/RenderEntity/EntityId.d.ts +13 -0
- package/dist/crate-builder/RenderEntity/EntityName.d.ts +13 -0
- package/dist/crate-builder/RenderEntity/EntityProperty.d.ts +19 -0
- package/dist/crate-builder/RenderEntity/EntityPropertyInstance.d.ts +25 -0
- package/dist/crate-builder/RenderEntity/EntityType.d.ts +12 -0
- package/dist/crate-builder/RenderEntity/ItemLink.d.ts +14 -0
- package/dist/crate-builder/RenderEntity/PaginateLinkedEntities.d.ts +23 -0
- package/dist/crate-builder/RenderEntity/PaginateLinkedEntities.stories.d.ts +7 -0
- package/dist/crate-builder/RenderEntity/PropertyHelp.d.ts +6 -0
- package/dist/crate-builder/RenderEntity/RenderControls.d.ts +22 -0
- package/dist/crate-builder/RenderEntity/RenderLinkedItem.d.ts +20 -0
- package/dist/crate-builder/RenderEntity/RenderPropertyHelp.d.ts +6 -0
- package/dist/crate-builder/RenderEntity/RenderReverseConnections.d.ts +16 -0
- package/dist/crate-builder/RenderEntity/RenderTypes.d.ts +6 -0
- package/dist/crate-builder/RenderEntity/Shell2.d.ts +14 -0
- package/dist/crate-builder/RenderEntity/UnlinkEntity.d.ts +14 -0
- package/dist/crate-builder/RenderEntity/auto-complete.lib.d.ts +25 -0
- package/dist/crate-builder/RenderEntity/keys.d.ts +4 -0
- package/dist/crate-builder/RenderEntity/layout.d.ts +14 -0
- package/dist/crate-builder/RenderEntity/layout.spec.d.ts +1 -0
- package/dist/crate-builder/Shell.d.ts +40 -0
- package/dist/crate-builder/editor-state.d.ts +72 -0
- package/dist/crate-builder/emotionCache.d.ts +1 -0
- package/dist/crate-builder/helpers.d.ts +9 -0
- package/dist/crate-builder/i18n.d.ts +2 -0
- package/dist/crate-builder/lib/validate-iri.d.ts +6 -0
- package/dist/crate-builder/locales/en.d.ts +79 -0
- package/dist/crate-builder/locales/hu.d.ts +79 -0
- package/dist/crate-builder/primitives/Boolean.d.ts +11 -0
- package/dist/crate-builder/primitives/Boolean.stories.d.ts +7 -0
- package/dist/crate-builder/primitives/Date.d.ts +11 -0
- package/dist/crate-builder/primitives/Date.stories.d.ts +5 -0
- package/dist/crate-builder/primitives/DateTime.d.ts +11 -0
- package/dist/crate-builder/primitives/DateTime.stories.d.ts +5 -0
- package/dist/crate-builder/primitives/Geo.d.ts +12 -0
- package/dist/crate-builder/primitives/Geo.stories.d.ts +26 -0
- package/dist/crate-builder/primitives/Map.SelectArea.d.ts +9 -0
- package/dist/crate-builder/primitives/Map.d.ts +15 -0
- package/dist/crate-builder/primitives/Map.stories.d.ts +6 -0
- package/dist/crate-builder/primitives/Number.d.ts +16 -0
- package/dist/crate-builder/primitives/Number.stories.d.ts +10 -0
- package/dist/crate-builder/primitives/Select.d.ts +15 -0
- package/dist/crate-builder/primitives/Select.stories.d.ts +9 -0
- package/dist/crate-builder/primitives/SelectObject.d.ts +13 -0
- package/dist/crate-builder/primitives/SelectObject.stories.d.ts +5 -0
- package/dist/crate-builder/primitives/SelectUrl.d.ts +14 -0
- package/dist/crate-builder/primitives/SelectUrl.stories.d.ts +7 -0
- package/dist/crate-builder/primitives/Text.d.ts +19 -0
- package/dist/crate-builder/primitives/Text.stories.d.ts +13 -0
- package/dist/crate-builder/primitives/Time.d.ts +11 -0
- package/dist/crate-builder/primitives/Time.stories.d.ts +7 -0
- package/dist/crate-builder/primitives/Url.d.ts +11 -0
- package/dist/crate-builder/primitives/Url.stories.d.ts +7 -0
- package/dist/crate-builder/primitives/Value.d.ts +7 -0
- package/dist/crate-builder/primitives/Value.stories.d.ts +7 -0
- package/dist/crate-builder/primitives/date-libs.d.ts +1 -0
- package/dist/crate-builder/property-definitions.d.ts +78 -0
- package/dist/crate-builder/store.d.ts +8 -0
- package/dist/index.d.ts +5 -0
- package/dist/recrate.css +1896 -0
- package/dist/recrate.es.js +38508 -0
- package/dist/types.d.ts +42 -0
- package/package.json +31 -28
- package/.eslintrc.json +0 -37
- package/.storybook/main.ts +0 -40
- package/.storybook/preview.tsx +0 -46
- package/babel.config.json +0 -5
- package/docker-compose.yml +0 -30
- package/docs/.nojekyll +0 -1
- package/docs/assets/highlight.css +0 -99
- package/docs/assets/icons.js +0 -18
- package/docs/assets/icons.svg +0 -1
- package/docs/assets/main.js +0 -60
- package/docs/assets/navigation.js +0 -1
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1448
- package/docs/classes/src_crate_builder_CrateManager_crate_manager.CrateManager.html +0 -240
- package/docs/classes/src_crate_builder_CrateManager_profile_manager.ProfileManager.html +0 -42
- package/docs/classes/src_crate_builder_editor_state.EditorState.html +0 -28
- package/docs/classes/src_crate_builder_types.CrateManagerType.html +0 -57
- package/docs/classes/src_crate_builder_types.ProfileManagerType.html +0 -13
- package/docs/functions/src_crate_builder_CrateManager_lib.isURL.html +0 -2
- package/docs/functions/src_crate_builder_CrateManager_lib.mintNewCrate.html +0 -3
- package/docs/functions/src_crate_builder_CrateManager_lib.normalise.html +0 -5
- package/docs/functions/src_crate_builder_CrateManager_lib.normaliseEntityType.html +0 -1
- package/docs/index.html +0 -58
- package/docs/interfaces/src_crate_builder_types.NormalisedCrate.html +0 -3
- package/docs/interfaces/src_crate_builder_types.NormalisedEntityDefinition.html +0 -4
- package/docs/interfaces/src_crate_builder_types.NormalisedProfile.html +0 -9
- package/docs/interfaces/src_crate_builder_types.ProfileLayout.html +0 -2
- package/docs/interfaces/src_crate_builder_types.ProfileLayoutGroup.html +0 -9
- package/docs/interfaces/src_crate_builder_types.UnverifiedCrate.html +0 -3
- package/docs/interfaces/src_crate_builder_types.UnverifiedEntityDefinition.html +0 -4
- package/docs/modules/src_crate_builder_CrateManager_crate_manager.html +0 -2
- package/docs/modules/src_crate_builder_CrateManager_lib.html +0 -6
- package/docs/modules/src_crate_builder_CrateManager_profile_manager.html +0 -2
- package/docs/modules/src_crate_builder_editor_state.html +0 -2
- package/docs/modules/src_crate_builder_types.html +0 -16
- package/docs/types/src_crate_builder_types.EntityReference.html +0 -1
- package/docs/types/src_crate_builder_types.NormalisedContext.html +0 -1
- package/docs/types/src_crate_builder_types.PrimitiveType.html +0 -1
- package/docs/types/src_crate_builder_types.ProfileAssociation.html +0 -1
- package/docs/types/src_crate_builder_types.ProfileInput.html +0 -1
- package/docs/types/src_crate_builder_types.UnverifiedContext.html +0 -1
- package/docs/variables/src_crate_builder_CrateManager_lib.urlProtocols.html +0 -1
- package/index.html +0 -13
- package/load-data-packs.cjs +0 -38
- package/postcss.config.cjs +0 -6
- package/react-app-env.d.ts +0 -1
- package/rollup.config.js +0 -26
- package/src/app/App.tsx +0 -13
- package/src/app/EmbeddedComponent.tsx +0 -432
- package/src/app/index.html +0 -20
- package/src/app/index.tsx +0 -19
- package/src/app/lookup.ts +0 -141
- package/src/app/override-styles.css +0 -96
- package/src/crate-builder/CrateManager/contexts/1.1-context.jsonld +0 -2660
- package/src/crate-builder/CrateManager/contexts/1.2-DRAFT-context.jsonld +0 -2918
- package/src/crate-builder/CrateManager/contexts.ts +0 -42
- package/src/crate-builder/CrateManager/crate-manager-benchmarking.spec.ts +0 -31
- package/src/crate-builder/CrateManager/crate-manager-loading-exporting.spec.ts +0 -431
- package/src/crate-builder/CrateManager/crate-manager-operations.spec.ts +0 -298
- package/src/crate-builder/CrateManager/crate-manager.spec.ts +0 -2336
- package/src/crate-builder/CrateManager/crate-manager.ts +0 -2111
- package/src/crate-builder/CrateManager/lib.spec.ts +0 -133
- package/src/crate-builder/CrateManager/lib.ts +0 -170
- package/src/crate-builder/CrateManager/profile-manager.spec.ts +0 -593
- package/src/crate-builder/CrateManager/profile-manager.ts +0 -367
- package/src/crate-builder/CrateManager/validate-identifier.spec.ts +0 -82
- package/src/crate-builder/CrateManager/validate-identifier.ts +0 -65
- package/src/crate-builder/RenderEntity/Add.tsx +0 -249
- package/src/crate-builder/RenderEntity/AddControl.stories.tsx +0 -126
- package/src/crate-builder/RenderEntity/AddControl.tsx +0 -84
- package/src/crate-builder/RenderEntity/AutoComplete.tsx +0 -215
- package/src/crate-builder/RenderEntity/BulkAdd.tsx +0 -136
- package/src/crate-builder/RenderEntity/DeleteProperty.tsx +0 -33
- package/src/crate-builder/RenderEntity/DialogAddProperty.tsx +0 -83
- package/src/crate-builder/RenderEntity/DialogBrowseEntities.tsx +0 -136
- package/src/crate-builder/RenderEntity/DialogEditContext.tsx +0 -107
- package/src/crate-builder/RenderEntity/DialogPreviewCrate.tsx +0 -54
- package/src/crate-builder/RenderEntity/DialogSaveCrateAsTemplate.tsx +0 -65
- package/src/crate-builder/RenderEntity/DialogSaveEntityTemplate.tsx +0 -87
- package/src/crate-builder/RenderEntity/DisplayPropertyName.stories.tsx +0 -30
- package/src/crate-builder/RenderEntity/DisplayPropertyName.tsx +0 -21
- package/src/crate-builder/RenderEntity/EntityId.tsx +0 -75
- package/src/crate-builder/RenderEntity/EntityName.tsx +0 -49
- package/src/crate-builder/RenderEntity/EntityProperty.tsx +0 -188
- package/src/crate-builder/RenderEntity/EntityPropertyInstance.tsx +0 -255
- package/src/crate-builder/RenderEntity/EntityType.tsx +0 -95
- package/src/crate-builder/RenderEntity/ItemLink.tsx +0 -37
- package/src/crate-builder/RenderEntity/PaginateLinkedEntities.stories.tsx +0 -43
- package/src/crate-builder/RenderEntity/PaginateLinkedEntities.tsx +0 -141
- package/src/crate-builder/RenderEntity/PropertyHelp.tsx +0 -39
- package/src/crate-builder/RenderEntity/RenderControls.tsx +0 -278
- package/src/crate-builder/RenderEntity/RenderLinkedItem.tsx +0 -139
- package/src/crate-builder/RenderEntity/RenderPropertyHelp.tsx +0 -41
- package/src/crate-builder/RenderEntity/RenderReverseConnections.tsx +0 -150
- package/src/crate-builder/RenderEntity/RenderTypes.tsx +0 -102
- package/src/crate-builder/RenderEntity/Shell2.tsx +0 -576
- package/src/crate-builder/RenderEntity/UnlinkEntity.tsx +0 -30
- package/src/crate-builder/RenderEntity/auto-complete.lib.ts +0 -184
- package/src/crate-builder/RenderEntity/keys.ts +0 -4
- package/src/crate-builder/RenderEntity/layout.spec.js +0 -593
- package/src/crate-builder/RenderEntity/layout.ts +0 -220
- package/src/crate-builder/Shell.tsx +0 -337
- package/src/crate-builder/component.css +0 -65
- package/src/crate-builder/editor-state.ts +0 -114
- package/src/crate-builder/emotionCache.ts +0 -8
- package/src/crate-builder/helpers.ts +0 -16
- package/src/crate-builder/i18n.ts +0 -22
- package/src/crate-builder/lib/validate-iri.ts +0 -57
- package/src/crate-builder/locales/en.js +0 -149
- package/src/crate-builder/locales/hu.js +0 -147
- package/src/crate-builder/primitives/Boolean.stories.tsx +0 -33
- package/src/crate-builder/primitives/Boolean.tsx +0 -67
- package/src/crate-builder/primitives/Date.stories.tsx +0 -32
- package/src/crate-builder/primitives/Date.tsx +0 -58
- package/src/crate-builder/primitives/DateTime.stories.tsx +0 -32
- package/src/crate-builder/primitives/DateTime.tsx +0 -64
- package/src/crate-builder/primitives/Geo.stories.tsx +0 -57
- package/src/crate-builder/primitives/Geo.tsx +0 -225
- package/src/crate-builder/primitives/Map.SelectArea.js +0 -359
- package/src/crate-builder/primitives/Map.stories.tsx +0 -61
- package/src/crate-builder/primitives/Map.tsx +0 -124
- package/src/crate-builder/primitives/Number.stories.tsx +0 -74
- package/src/crate-builder/primitives/Number.tsx +0 -166
- package/src/crate-builder/primitives/Select.stories.tsx +0 -66
- package/src/crate-builder/primitives/Select.tsx +0 -121
- package/src/crate-builder/primitives/SelectObject.stories.tsx +0 -29
- package/src/crate-builder/primitives/SelectObject.tsx +0 -105
- package/src/crate-builder/primitives/SelectUrl.stories.tsx +0 -42
- package/src/crate-builder/primitives/SelectUrl.tsx +0 -110
- package/src/crate-builder/primitives/Text.stories.tsx +0 -106
- package/src/crate-builder/primitives/Text.tsx +0 -197
- package/src/crate-builder/primitives/Time.stories.tsx +0 -38
- package/src/crate-builder/primitives/Time.tsx +0 -71
- package/src/crate-builder/primitives/Url.stories.tsx +0 -43
- package/src/crate-builder/primitives/Url.tsx +0 -75
- package/src/crate-builder/primitives/Value.stories.tsx +0 -37
- package/src/crate-builder/primitives/Value.tsx +0 -30
- package/src/crate-builder/primitives/date-libs.ts +0 -12
- package/src/crate-builder/profile-schema.json +0 -145
- package/src/crate-builder/property-definitions.ts +0 -78
- package/src/crate-builder/recrate.css +0 -3
- package/src/crate-builder/store.ts +0 -14
- package/src/crate-builder/tailwind.css +0 -5
- package/src/crate-builder/types.d.ts +0 -318
- package/src/examples/collection/collections-entity-example.json +0 -131
- package/src/examples/collection/crate-builder-entity-example.json +0 -33
- package/src/examples/item/complex-collection/ro-crate-metadata.json +0 -174
- package/src/examples/item/complex-item/ro-crate-metadata.json +0 -769
- package/src/examples/item/crate-with-language.json +0 -38
- package/src/examples/item/empty/ro-crate-metadata.json +0 -20
- package/src/examples/item/item-with-relationship-and-action/ro-crate-metadata.json +0 -66
- package/src/examples/item/large-crate/ro-crate-metadata.json +0 -5762
- package/src/examples/item/multiple-types/ro-crate-metadata.json +0 -20
- package/src/examples/item/ridiculously-big-collection/ro-crate-metadata.json +0 -162977
- package/src/examples/profile/aroma.complex.profile.json +0 -11098
- package/src/examples/profile/aroma.profile.json +0 -9158
- package/src/examples/profile/nyingarn-item-profile.json +0 -426
- package/src/examples/profile/profile-to-test-inverse-associations.json +0 -73
- package/src/examples/profile/profile-to-test-multiple-types.json +0 -31
- package/src/examples/profile/profile-with-all-primitives-and-groups.json +0 -207
- package/src/examples/profile/profile-with-all-primitives.json +0 -244
- package/src/examples/profile/profile-with-constraints.json +0 -446
- package/src/examples/profile/profile-with-resolve.json +0 -57
- package/src/examples/profile/vocabulary-creation-profile.json +0 -231
- package/src/images.d.ts +0 -5
- package/src/index.ts +0 -12
- package/src/types.ts +0 -104
- package/tailwind.config.js +0 -21
- package/tsconfig.app.json +0 -31
- package/tsconfig.json +0 -26
- package/typedoc.json +0 -11
- package/update-deps.sh +0 -4
- package/vite-env.d.ts +0 -1
- package/vite.config.ts +0 -104
- /package/{public → dist}/favicon.ico +0 -0
- /package/{public → dist}/index.html +0 -0
- /package/{public → dist}/logo192.png +0 -0
- /package/{public → dist}/logo512.png +0 -0
- /package/{public → dist}/manifest.json +0 -0
- /package/{public → dist}/marker-icon.png +0 -0
- /package/{public → dist}/marker-shadow.png +0 -0
- /package/{public → dist}/robots.txt +0 -0
|
@@ -1,367 +0,0 @@
|
|
|
1
|
-
import schemaOrgTypeDefinitions from "./schema-type-definitions.json";
|
|
2
|
-
import isArray from "lodash/isArray";
|
|
3
|
-
import isEmpty from "lodash/isEmpty";
|
|
4
|
-
import flattenDeep from "lodash/flattenDeep";
|
|
5
|
-
import cloneDeep from "lodash/cloneDeep";
|
|
6
|
-
import orderBy from "lodash/orderBy";
|
|
7
|
-
import has from "lodash/has";
|
|
8
|
-
import compact from "lodash/compact";
|
|
9
|
-
import uniq from "lodash/uniq";
|
|
10
|
-
import uniqBy from "lodash/uniqBy";
|
|
11
|
-
import intersection from "lodash/intersection";
|
|
12
|
-
import type {
|
|
13
|
-
NormalisedProfile,
|
|
14
|
-
NormalisedEntityDefinition,
|
|
15
|
-
ProfileLayout,
|
|
16
|
-
ProfileInput,
|
|
17
|
-
EntityReference,
|
|
18
|
-
} from "../types";
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @class
|
|
22
|
-
*
|
|
23
|
-
* ProfileManager
|
|
24
|
-
*
|
|
25
|
-
* A class to work with Describo Profiles
|
|
26
|
-
*
|
|
27
|
-
* @param {profile} - profile to handle
|
|
28
|
-
*/
|
|
29
|
-
export class ProfileManager {
|
|
30
|
-
profile?: NormalisedProfile;
|
|
31
|
-
$key?: number;
|
|
32
|
-
context?: any;
|
|
33
|
-
|
|
34
|
-
constructor({ profile }: { profile?: NormalisedProfile }) {
|
|
35
|
-
if (profile) {
|
|
36
|
-
this.profile = profile;
|
|
37
|
-
this.__processInputs();
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Process input definitions for certain types.
|
|
43
|
-
*
|
|
44
|
-
* For now it takes care of setting 'handlesMultipleValues' for input types, which can have multiple values
|
|
45
|
-
* but handle all values themselves and not require a new render property added for each new value. This is the
|
|
46
|
-
* case for checbox style selects. It provides the same functionality as a normal select but all values are
|
|
47
|
-
* visible and selectable at once and not one by one.
|
|
48
|
-
*
|
|
49
|
-
* It also makes sure that for radio style selects "multiple" is always set to "false", as radio input only
|
|
50
|
-
* provides a single value selected form many.
|
|
51
|
-
*
|
|
52
|
-
* @private
|
|
53
|
-
*/
|
|
54
|
-
private __processInputs() {
|
|
55
|
-
if (!this.profile?.classes) return;
|
|
56
|
-
|
|
57
|
-
for (const className in this.profile.classes) {
|
|
58
|
-
const classDefinition = this.profile.classes[className];
|
|
59
|
-
if (!classDefinition.inputs) continue;
|
|
60
|
-
|
|
61
|
-
classDefinition.inputs = classDefinition.inputs.map(input => {
|
|
62
|
-
if (input.type.includes("Select") && input.style === "checkbox") {
|
|
63
|
-
return {
|
|
64
|
-
...input,
|
|
65
|
-
multiple: false, // must set explicitly, otherwise will be set to true implicitly later
|
|
66
|
-
handlesMultipleValues: true
|
|
67
|
-
};
|
|
68
|
-
} else if (input.type.includes("Select") && input.style === "radio") {
|
|
69
|
-
return {
|
|
70
|
-
...input,
|
|
71
|
-
multiple: false, // on case of radio, it must always be false
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return input;
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
*
|
|
82
|
-
* Get the layout for an entity from the profile
|
|
83
|
-
*
|
|
84
|
-
* Returns the first matching layout from the profile
|
|
85
|
-
*
|
|
86
|
-
* @param { Object } options
|
|
87
|
-
* @param { Object } options.entity - the entity whose layout is required
|
|
88
|
-
*
|
|
89
|
-
*/
|
|
90
|
-
getLayout({
|
|
91
|
-
entity,
|
|
92
|
-
}: {
|
|
93
|
-
entity: NormalisedEntityDefinition | EntityReference;
|
|
94
|
-
}): ProfileLayout | null {
|
|
95
|
-
// no layout defined in profile
|
|
96
|
-
if (!this.profile?.layouts || !this.profile.layouts.length) return null;
|
|
97
|
-
let layouts = this.profile.layouts;
|
|
98
|
-
let layout = layouts.filter((layout) => {
|
|
99
|
-
return intersection(layout.appliesTo, (entity as any)["@type"]).length;
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
// no matching layout found
|
|
103
|
-
if (!layout.length) return null;
|
|
104
|
-
|
|
105
|
-
// match found - make sure it has about and overflow placeholders
|
|
106
|
-
let firstMatchingLayout = layout[0];
|
|
107
|
-
if (!firstMatchingLayout.about) {
|
|
108
|
-
firstMatchingLayout.about = {
|
|
109
|
-
name: "about",
|
|
110
|
-
label: "About",
|
|
111
|
-
inputs: [],
|
|
112
|
-
order: 0,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
if (!firstMatchingLayout.overflow) {
|
|
116
|
-
firstMatchingLayout.overflow = {
|
|
117
|
-
name: "overflow",
|
|
118
|
-
label: "...",
|
|
119
|
-
inputs: [],
|
|
120
|
-
order: Object.keys(layout).length,
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// return it
|
|
125
|
-
return firstMatchingLayout;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Get inverse associations from the profile if any are defined
|
|
130
|
-
*/
|
|
131
|
-
getPropertyAssociations(): { [key: string]: { property: string; propertyId: string } } {
|
|
132
|
-
if (!this.profile?.propertyAssociations) return {};
|
|
133
|
-
|
|
134
|
-
// create the associations both ways and return
|
|
135
|
-
const associations: { [key: string]: { property: string; propertyId: string } } = {};
|
|
136
|
-
this.profile.propertyAssociations.forEach((a) => {
|
|
137
|
-
associations[a.property] = a.inverse;
|
|
138
|
-
associations[a.inverse.property] = { property: a.property, propertyId: a.propertyId };
|
|
139
|
-
});
|
|
140
|
-
return associations;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
*
|
|
145
|
-
* Get the available classes
|
|
146
|
-
* if a profile is defined, get those
|
|
147
|
-
*
|
|
148
|
-
* Returns the classes defined in the profile if one is applied
|
|
149
|
-
* or all of the classes built into the base, schema.org profile
|
|
150
|
-
*
|
|
151
|
-
*/
|
|
152
|
-
getClasses() {
|
|
153
|
-
if (this.profile?.classes) {
|
|
154
|
-
return Object.keys(this.profile?.classes).sort();
|
|
155
|
-
} else {
|
|
156
|
-
return Object.keys(schemaOrgTypeDefinitions).sort();
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
*
|
|
162
|
-
* Return the type hierarchy for the given entity
|
|
163
|
-
*
|
|
164
|
-
* @param { Object } options
|
|
165
|
-
* @param { Object } options.entity - the entity whose hierarchy is required
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*/
|
|
169
|
-
getEntityTypeHierarchy({ entity }: { entity: NormalisedEntityDefinition }) {
|
|
170
|
-
let types = entity["@type"];
|
|
171
|
-
types = this.mapTypeHierarchies({ types });
|
|
172
|
-
return types;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
*
|
|
177
|
-
* Given an entity, try to find a definition for the property in the profile or
|
|
178
|
-
* right across the hierarchy
|
|
179
|
-
*
|
|
180
|
-
* @param { Object } options
|
|
181
|
-
* @param { Object } options.property - the property to define
|
|
182
|
-
* @param { Object } options.entity - the entity this property is a part of
|
|
183
|
-
*
|
|
184
|
-
*/
|
|
185
|
-
getPropertyDefinition({
|
|
186
|
-
property,
|
|
187
|
-
entity,
|
|
188
|
-
}: {
|
|
189
|
-
property: string;
|
|
190
|
-
entity: NormalisedEntityDefinition;
|
|
191
|
-
}) {
|
|
192
|
-
let propertyDefinition = {} as ProfileInput;
|
|
193
|
-
let inputs = this.getInputsFromProfile({ entity });
|
|
194
|
-
if (inputs.length) {
|
|
195
|
-
// we found an entity definition in the profile - do we have a property definition?
|
|
196
|
-
let definition = inputs.filter((p) => p.name.toLowerCase() === property.toLowerCase());
|
|
197
|
-
if (definition.length) {
|
|
198
|
-
// console.debug(
|
|
199
|
-
// "PROFILE property definition:",
|
|
200
|
-
// JSON.stringify(propertyDefinition, null, 2)
|
|
201
|
-
// );
|
|
202
|
-
propertyDefinition = cloneDeep(definition[0]);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
// unable to locate a property definition in the profile - look in schema.org
|
|
206
|
-
if (isEmpty(propertyDefinition)) {
|
|
207
|
-
let { inputs } = this.getAllInputs({ entity });
|
|
208
|
-
let definition = inputs.filter((p) => p.name.toLowerCase() === property.toLowerCase());
|
|
209
|
-
if (definition.length) {
|
|
210
|
-
// console.debug(
|
|
211
|
-
// "SCHEMA ORG property definition:",
|
|
212
|
-
// JSON.stringify(propertyDefinition, null, 2)
|
|
213
|
-
// );
|
|
214
|
-
propertyDefinition = cloneDeep(definition[0]);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// unable to locate a property definition in schema.org - create a default one
|
|
219
|
-
if (isEmpty(propertyDefinition)) {
|
|
220
|
-
// console.debug(
|
|
221
|
-
// "DEFAULT property definition:",
|
|
222
|
-
// JSON.stringify(propertyDefinition, null, 2)
|
|
223
|
-
// );
|
|
224
|
-
propertyDefinition = {
|
|
225
|
-
id: "",
|
|
226
|
-
name: "",
|
|
227
|
-
type: ["Text"],
|
|
228
|
-
help: "",
|
|
229
|
-
multiple: true,
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
if (!isArray(propertyDefinition.type)) {
|
|
234
|
-
propertyDefinition.type = [propertyDefinition.type];
|
|
235
|
-
}
|
|
236
|
-
if (!has(propertyDefinition, "multiple")) propertyDefinition.multiple = true;
|
|
237
|
-
|
|
238
|
-
return { propertyDefinition };
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
*
|
|
243
|
-
* Given a set of types, figure out the type hierarchy taking into account
|
|
244
|
-
* the parent types that this is a subClassOf
|
|
245
|
-
*/
|
|
246
|
-
mapTypeHierarchies({ types }: { types: string[] }) {
|
|
247
|
-
types = cloneDeep(types);
|
|
248
|
-
if (!types.includes("Thing")) types.push("Thing");
|
|
249
|
-
|
|
250
|
-
types = flattenDeep(
|
|
251
|
-
types.map((type) => [type, this.profile?.classes?.[type]?.subClassOf ?? []])
|
|
252
|
-
);
|
|
253
|
-
types = compact(types);
|
|
254
|
-
|
|
255
|
-
types = flattenDeep(
|
|
256
|
-
types.map((type) => {
|
|
257
|
-
return [
|
|
258
|
-
type,
|
|
259
|
-
(schemaOrgTypeDefinitions as { [key: string]: { hierarchy: string[] } })[type]
|
|
260
|
-
?.hierarchy ?? ["Thing"],
|
|
261
|
-
];
|
|
262
|
-
})
|
|
263
|
-
);
|
|
264
|
-
types = uniq(types);
|
|
265
|
-
return types;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
*
|
|
270
|
-
* Given an entity, get the inputs defined in the profile
|
|
271
|
-
*
|
|
272
|
-
* @param { Object } options
|
|
273
|
-
* @param { Object } options.entity - the entity
|
|
274
|
-
*
|
|
275
|
-
*/
|
|
276
|
-
getInputsFromProfile({ entity }: { entity: NormalisedEntityDefinition }): ProfileInput[] {
|
|
277
|
-
let types = entity["@type"];
|
|
278
|
-
|
|
279
|
-
let inputs: ProfileInput[] = [];
|
|
280
|
-
for (let type of types) {
|
|
281
|
-
if (this.profile?.classes?.[type]) {
|
|
282
|
-
// yes - get it
|
|
283
|
-
inputs = [...inputs, ...cloneDeep(this.profile?.classes?.[type].inputs)];
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
// if the definition is set to inherit, and this class is a subclass of others,
|
|
287
|
-
// go and get those inputs as well
|
|
288
|
-
if (
|
|
289
|
-
this.profile?.classes?.[type]?.definition === "inherit" &&
|
|
290
|
-
this.profile?.classes?.[type]?.subClassOf
|
|
291
|
-
) {
|
|
292
|
-
for (let parentClass of this.profile?.classes?.[type]?.subClassOf) {
|
|
293
|
-
inputs = [
|
|
294
|
-
...inputs,
|
|
295
|
-
...cloneDeep(this.profile?.classes?.[parentClass]?.inputs ?? []),
|
|
296
|
-
];
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
return uniqBy(inputs, "id");
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
*
|
|
305
|
-
* Given an entity, get all available inputs by joining the profile with schema.org
|
|
306
|
-
*
|
|
307
|
-
* @param { Object } options
|
|
308
|
-
* @param { Object } options.entity - the entity
|
|
309
|
-
*/
|
|
310
|
-
getAllInputs({ entity }: { entity: NormalisedEntityDefinition }): { inputs: ProfileInput[] } {
|
|
311
|
-
// let getInputsFunction = getInputs.bind(this);
|
|
312
|
-
const hierarchy = this.getEntityTypeHierarchy({ entity });
|
|
313
|
-
let inputs = [];
|
|
314
|
-
|
|
315
|
-
const getInputs = (type: string) => {
|
|
316
|
-
let inputs = [];
|
|
317
|
-
if (this.profile?.classes?.[type]) {
|
|
318
|
-
// type defined in profile - get those inputs
|
|
319
|
-
inputs.push(this.profile.classes[type].inputs);
|
|
320
|
-
}
|
|
321
|
-
if (this.profile?.classes?.[type]?.definition === "inherit") {
|
|
322
|
-
// profile type definition set to inherit - collect schema.org inputs
|
|
323
|
-
inputs.push((schemaOrgTypeDefinitions as any)[type].inputs);
|
|
324
|
-
}
|
|
325
|
-
if (!this.profile?.classes?.[type]) {
|
|
326
|
-
// no definition in profile - collect schema.org inputs
|
|
327
|
-
inputs.push((schemaOrgTypeDefinitions as any)?.[type]?.inputs);
|
|
328
|
-
}
|
|
329
|
-
return inputs;
|
|
330
|
-
};
|
|
331
|
-
|
|
332
|
-
for (let type of hierarchy) {
|
|
333
|
-
inputs.push(getInputs(type));
|
|
334
|
-
}
|
|
335
|
-
inputs = flattenDeep(inputs);
|
|
336
|
-
inputs = compact(inputs);
|
|
337
|
-
inputs = uniqBy(inputs, "id");
|
|
338
|
-
inputs = orderBy(inputs, "name");
|
|
339
|
-
return { inputs };
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
/**
|
|
343
|
-
*
|
|
344
|
-
* Try to get a definition from the profile and see if it's override or inherit
|
|
345
|
-
*
|
|
346
|
-
* If there's an override then return override - otherwise inherit. Exclusive rather than inclusive.
|
|
347
|
-
*
|
|
348
|
-
* @param { Object } options
|
|
349
|
-
* @param { Object } options.entity - the entity
|
|
350
|
-
* if there's an override then set to override - otherwise inherit
|
|
351
|
-
* be exclusive rather than inclusive
|
|
352
|
-
*/
|
|
353
|
-
getTypeDefinition({ entity }: { entity: NormalisedEntityDefinition }) {
|
|
354
|
-
let types = entity["@type"];
|
|
355
|
-
let directive = types.map((type) => this.profile?.classes?.[type]?.definition);
|
|
356
|
-
return directive.includes("override") ? "override" : "inherit";
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
/**
|
|
360
|
-
* Get an entity label if defined
|
|
361
|
-
*
|
|
362
|
-
* @property the type name to localise
|
|
363
|
-
*/
|
|
364
|
-
getTypeLabel(type: string) {
|
|
365
|
-
return this.profile?.localisation?.[type] ?? type;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "vitest";
|
|
2
|
-
import { validateId } from "./validate-identifier";
|
|
3
|
-
|
|
4
|
-
describe("Test @id's that should be valid", () => {
|
|
5
|
-
test(`LICENCE.md should be valid`, () => {
|
|
6
|
-
expect(validateId({ id: "LICENCE.md", type: "File" }).isValid).toBeTruthy;
|
|
7
|
-
expect(validateId({ id: "LICENCE.md", type: "File, Licence" }).isValid).toBeTruthy;
|
|
8
|
-
expect(validateId({ id: "LICENCE.md", type: ["File", "Licence"] }).isValid).toBeTruthy;
|
|
9
|
-
});
|
|
10
|
-
test(`/path/to/file should be valid`, () => {
|
|
11
|
-
expect(validateId({ id: "/path/to/file", type: "Dataset" }).isValid).toBeTruthy;
|
|
12
|
-
});
|
|
13
|
-
test(`./ should be valid`, () => {
|
|
14
|
-
expect(validateId({ id: "./", type: "Dataset" }).isValid).toBeTruthy;
|
|
15
|
-
});
|
|
16
|
-
test(`../ should be valid`, () => {
|
|
17
|
-
expect(validateId({ id: "../", type: "Dataset" }).isValid).toBeTruthy;
|
|
18
|
-
});
|
|
19
|
-
test(`_:xxx should be valid`, () => {
|
|
20
|
-
expect(validateId({ id: "_:xxx", type: "Dataset" }).isValid).toBeTruthy;
|
|
21
|
-
});
|
|
22
|
-
test(`#xxx should be valid`, () => {
|
|
23
|
-
expect(validateId({ id: "#xxx", type: "Dataset" }).isValid).toBeTruthy;
|
|
24
|
-
});
|
|
25
|
-
test(`http://schema.org/name should be valid`, () => {
|
|
26
|
-
expect(validateId({ id: "http://schema.org/name", type: "Dataset" }).isValid).toBeTruthy;
|
|
27
|
-
});
|
|
28
|
-
test(`https://schema.org/name should be valid`, () => {
|
|
29
|
-
expect(validateId({ id: "https://schema.org/name", type: "Dataset" }).isValid).toBeTruthy;
|
|
30
|
-
});
|
|
31
|
-
test(`ftp://schema.org/name should be valid`, () => {
|
|
32
|
-
expect(validateId({ id: "ftp://schema.org/name", type: "Dataset" }).isValid).toBeTruthy;
|
|
33
|
-
});
|
|
34
|
-
test(`ftps://schema.org/name should be valid`, () => {
|
|
35
|
-
expect(validateId({ id: "ftps://schema.org/name", type: "Dataset" }).isValid).toBeTruthy;
|
|
36
|
-
});
|
|
37
|
-
test(`arcp://uuid,32a423d6-52ab-47e3-a9cd-54f418a48571/doc.html`, () => {
|
|
38
|
-
expect(
|
|
39
|
-
validateId({
|
|
40
|
-
id: "arcp://uuid,32a423d6-52ab-47e3-a9cd-54f418a48571/doc.html",
|
|
41
|
-
type: "Dataset",
|
|
42
|
-
}).isValid
|
|
43
|
-
).toBeTruthy;
|
|
44
|
-
});
|
|
45
|
-
test(`arcp://uuid,b7749d0b-0e47-5fc4-999d-f154abe68065/pics/`, () => {
|
|
46
|
-
expect(
|
|
47
|
-
validateId({
|
|
48
|
-
id: "arcp://uuid,b7749d0b-0e47-5fc4-999d-f154abe68065/pics/",
|
|
49
|
-
type: "Dataset",
|
|
50
|
-
}).isValid
|
|
51
|
-
).toBeTruthy;
|
|
52
|
-
});
|
|
53
|
-
test(`arcp://ni,sha-256;F-34D4TUeOfG0selz7REKRDo4XePkewPeQYtjL3vQs0/`, () => {
|
|
54
|
-
expect(
|
|
55
|
-
validateId({
|
|
56
|
-
id: "arcp://ni,sha-256;F-34D4TUeOfG0selz7REKRDo4XePkewPeQYtjL3vQs0/",
|
|
57
|
-
type: "Dataset",
|
|
58
|
-
}).isValid
|
|
59
|
-
).toBeTruthy;
|
|
60
|
-
});
|
|
61
|
-
test(`arcp://name,gallery.example.org/`, () => {
|
|
62
|
-
expect(validateId({ id: "arcp://name,gallery.example.org/a", type: "Dataset" }).isValid)
|
|
63
|
-
.toBeTruthy;
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
describe("Test @id's that should NOT be valid", () => {
|
|
67
|
-
test(`no id passed`, () => {
|
|
68
|
-
expect(validateId({ id: "", type: "Dataset" })).toEqual({ isValid: false, message: "No identifier was provided." });
|
|
69
|
-
});
|
|
70
|
-
test(`aaa should not be valid`, () => {
|
|
71
|
-
expect(validateId({ id: "aaa", type: "Person" }).message).toEqual(
|
|
72
|
-
"The identifier is not valid according to the RO Crate spec nor is it a valid IRI."
|
|
73
|
-
);
|
|
74
|
-
});
|
|
75
|
-
test(`32a423d6-52ab-47e3-a9cd-54f418a48571 should not be valid`, () => {
|
|
76
|
-
expect(
|
|
77
|
-
validateId({ id: "32a423d6-52ab-47e3-a9cd-54f418a48571", type: "Person" }).message
|
|
78
|
-
).toEqual(
|
|
79
|
-
`The identifier is not valid according to the RO Crate spec nor is it a valid IRI.`
|
|
80
|
-
);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { validateIri, IriValidationStrategy } from "../lib/validate-iri";
|
|
2
|
-
|
|
3
|
-
type ValidateIdParams = {
|
|
4
|
-
id: string | undefined;
|
|
5
|
-
type: string | string[];
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
type ValidateIdResponse = { isValid: boolean; message?: string };
|
|
9
|
-
|
|
10
|
-
export function validateId({ id, type }: ValidateIdParams): ValidateIdResponse {
|
|
11
|
-
if (!id) {
|
|
12
|
-
return { isValid: false, message: "No identifier was provided." };
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// if it's the root descriptor - it's valid
|
|
16
|
-
if (id === "ro-crate-metadata.json") {
|
|
17
|
-
return { isValid: true };
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (type) {
|
|
21
|
-
// if type matches File or Dataset then whatever is provided is valid
|
|
22
|
-
type = Array.isArray(type) ? type.join(", ") : type;
|
|
23
|
-
if (type.match(/file/i)) return { isValid: true };
|
|
24
|
-
if (type.match(/Dataset/i)) return { isValid: true };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// @id is relative
|
|
28
|
-
if (id.match(/^\/.*/)) return { isValid: true };
|
|
29
|
-
|
|
30
|
-
// @id starting with . is valid
|
|
31
|
-
if (id.match(/^\..*/)) return { isValid: true };
|
|
32
|
-
|
|
33
|
-
// @id starting with # is valid
|
|
34
|
-
if (id.match(/^\#.*/)) return { isValid: true };
|
|
35
|
-
|
|
36
|
-
// @id with blank node is valid
|
|
37
|
-
if (id.match(/^\_:.*/)) return { isValid: true };
|
|
38
|
-
|
|
39
|
-
// arcp URI's are valid
|
|
40
|
-
if (id.match(/arcp:\/\/name,.*/)) return { isValid: true };
|
|
41
|
-
if (id.match(/arcp:\/\/uuid,.*/)) return { isValid: true };
|
|
42
|
-
if (id.match(/arcp:\/\/ni,sha-256;,.*/)) return { isValid: true };
|
|
43
|
-
// return { isValid: true };
|
|
44
|
-
|
|
45
|
-
// otherwise check that the id is a valid IRI
|
|
46
|
-
try {
|
|
47
|
-
let result = validateIri(id, IriValidationStrategy.Strict);
|
|
48
|
-
if (!result) {
|
|
49
|
-
// it's valid
|
|
50
|
-
return { isValid: true };
|
|
51
|
-
}
|
|
52
|
-
} catch (error) {
|
|
53
|
-
return {
|
|
54
|
-
isValid: false,
|
|
55
|
-
message:
|
|
56
|
-
"The identifier is not valid according to the RO Crate spec nor is it a valid IRI.",
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return {
|
|
61
|
-
isValid: false,
|
|
62
|
-
message:
|
|
63
|
-
"The identifier is not valid according to the RO Crate spec nor is it a valid IRI.",
|
|
64
|
-
};
|
|
65
|
-
}
|