@krantho/seo 0.0.0-stage → 1.0.0
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/LICENSE +21 -0
- package/dist/archetypes/define-archetype.d.ts +23 -0
- package/dist/archetypes/define-archetype.d.ts.map +1 -0
- package/dist/archetypes/define-archetype.js +51 -0
- package/dist/archetypes/define-archetype.js.map +1 -0
- package/dist/archetypes/index.d.ts +4 -0
- package/dist/archetypes/index.d.ts.map +1 -0
- package/dist/archetypes/index.js +3 -0
- package/dist/archetypes/index.js.map +1 -0
- package/dist/archetypes/presets.d.ts +21 -0
- package/dist/archetypes/presets.d.ts.map +1 -0
- package/dist/archetypes/presets.js +42 -0
- package/dist/archetypes/presets.js.map +1 -0
- package/dist/archetypes/types.d.ts +20 -0
- package/dist/archetypes/types.d.ts.map +1 -0
- package/dist/archetypes/types.js +2 -0
- package/dist/archetypes/types.js.map +1 -0
- package/dist/catalog/auto-mappings.d.ts +39 -0
- package/dist/catalog/auto-mappings.d.ts.map +1 -0
- package/dist/catalog/auto-mappings.js +64 -0
- package/dist/catalog/auto-mappings.js.map +1 -0
- package/dist/catalog/index.d.ts +7 -0
- package/dist/catalog/index.d.ts.map +1 -0
- package/dist/catalog/index.js +4 -0
- package/dist/catalog/index.js.map +1 -0
- package/dist/catalog/properties.d.ts +9 -0
- package/dist/catalog/properties.d.ts.map +1 -0
- package/dist/catalog/properties.js +630 -0
- package/dist/catalog/properties.js.map +1 -0
- package/dist/catalog/property-atoms.d.ts +53 -0
- package/dist/catalog/property-atoms.d.ts.map +1 -0
- package/dist/catalog/property-atoms.js +170 -0
- package/dist/catalog/property-atoms.js.map +1 -0
- package/dist/catalog/types.d.ts +53 -0
- package/dist/catalog/types.d.ts.map +1 -0
- package/dist/catalog/types.js +423 -0
- package/dist/catalog/types.js.map +1 -0
- package/dist/create-seo.d.ts +70 -0
- package/dist/create-seo.d.ts.map +1 -0
- package/dist/create-seo.js +137 -0
- package/dist/create-seo.js.map +1 -0
- package/dist/decorators/breadcrumb.d.ts +12 -0
- package/dist/decorators/breadcrumb.d.ts.map +1 -0
- package/dist/decorators/breadcrumb.js +36 -0
- package/dist/decorators/breadcrumb.js.map +1 -0
- package/dist/decorators/index.d.ts +8 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +13 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/nodes.d.ts +12 -0
- package/dist/decorators/nodes.d.ts.map +1 -0
- package/dist/decorators/nodes.js +29 -0
- package/dist/decorators/nodes.js.map +1 -0
- package/dist/decorators/page.d.ts +13 -0
- package/dist/decorators/page.d.ts.map +1 -0
- package/dist/decorators/page.js +68 -0
- package/dist/decorators/page.js.map +1 -0
- package/dist/decorators/registry.d.ts +11 -0
- package/dist/decorators/registry.d.ts.map +1 -0
- package/dist/decorators/registry.js +29 -0
- package/dist/decorators/registry.js.map +1 -0
- package/dist/decorators/sequence.d.ts +8 -0
- package/dist/decorators/sequence.d.ts.map +1 -0
- package/dist/decorators/sequence.js +22 -0
- package/dist/decorators/sequence.js.map +1 -0
- package/dist/decorators/types.d.ts +30 -0
- package/dist/decorators/types.d.ts.map +1 -0
- package/dist/decorators/types.js +2 -0
- package/dist/decorators/types.js.map +1 -0
- package/dist/define-seo.d.ts +21 -0
- package/dist/define-seo.d.ts.map +1 -0
- package/dist/define-seo.js +31 -0
- package/dist/define-seo.js.map +1 -0
- package/dist/graph/build-entity.d.ts +47 -0
- package/dist/graph/build-entity.d.ts.map +1 -0
- package/dist/graph/build-entity.js +69 -0
- package/dist/graph/build-entity.js.map +1 -0
- package/dist/graph/compose-from-config.d.ts +89 -0
- package/dist/graph/compose-from-config.d.ts.map +1 -0
- package/dist/graph/compose-from-config.js +189 -0
- package/dist/graph/compose-from-config.js.map +1 -0
- package/dist/graph/compose-graph.d.ts +40 -0
- package/dist/graph/compose-graph.d.ts.map +1 -0
- package/dist/graph/compose-graph.js +30 -0
- package/dist/graph/compose-graph.js.map +1 -0
- package/dist/graph/effective-config.d.ts +36 -0
- package/dist/graph/effective-config.d.ts.map +1 -0
- package/dist/graph/effective-config.js +84 -0
- package/dist/graph/effective-config.js.map +1 -0
- package/dist/graph/id-conventions.d.ts +47 -0
- package/dist/graph/id-conventions.d.ts.map +1 -0
- package/dist/graph/id-conventions.js +78 -0
- package/dist/graph/id-conventions.js.map +1 -0
- package/dist/graph/index.d.ts +9 -0
- package/dist/graph/index.d.ts.map +1 -0
- package/dist/graph/index.js +4 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph/resolve-properties.d.ts +36 -0
- package/dist/graph/resolve-properties.d.ts.map +1 -0
- package/dist/graph/resolve-properties.js +141 -0
- package/dist/graph/resolve-properties.js.map +1 -0
- package/dist/graph/resolve-references.d.ts +14 -0
- package/dist/graph/resolve-references.d.ts.map +1 -0
- package/dist/graph/resolve-references.js +49 -0
- package/dist/graph/resolve-references.js.map +1 -0
- package/dist/graph/typed-value.d.ts +7 -0
- package/dist/graph/typed-value.d.ts.map +1 -0
- package/dist/graph/typed-value.js +43 -0
- package/dist/graph/typed-value.js.map +1 -0
- package/dist/graph/types.d.ts +34 -0
- package/dist/graph/types.d.ts.map +1 -0
- package/dist/graph/types.js +2 -0
- package/dist/graph/types.js.map +1 -0
- package/dist/graph/value-scope.d.ts +19 -0
- package/dist/graph/value-scope.d.ts.map +1 -0
- package/dist/graph/value-scope.js +30 -0
- package/dist/graph/value-scope.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/json-ld.d.ts +24 -0
- package/dist/json-ld.d.ts.map +1 -0
- package/dist/json-ld.js +24 -0
- package/dist/json-ld.js.map +1 -0
- package/dist/profiles/bing.d.ts +10 -0
- package/dist/profiles/bing.d.ts.map +1 -0
- package/dist/profiles/bing.js +13 -0
- package/dist/profiles/bing.js.map +1 -0
- package/dist/profiles/check.d.ts +11 -0
- package/dist/profiles/check.d.ts.map +1 -0
- package/dist/profiles/check.js +66 -0
- package/dist/profiles/check.js.map +1 -0
- package/dist/profiles/eligibility.d.ts +26 -0
- package/dist/profiles/eligibility.d.ts.map +1 -0
- package/dist/profiles/eligibility.js +49 -0
- package/dist/profiles/eligibility.js.map +1 -0
- package/dist/profiles/google.d.ts +4 -0
- package/dist/profiles/google.d.ts.map +1 -0
- package/dist/profiles/google.js +387 -0
- package/dist/profiles/google.js.map +1 -0
- package/dist/profiles/index.d.ts +10 -0
- package/dist/profiles/index.d.ts.map +1 -0
- package/dist/profiles/index.js +13 -0
- package/dist/profiles/index.js.map +1 -0
- package/dist/profiles/registry.d.ts +16 -0
- package/dist/profiles/registry.d.ts.map +1 -0
- package/dist/profiles/registry.js +66 -0
- package/dist/profiles/registry.js.map +1 -0
- package/dist/profiles/types.d.ts +29 -0
- package/dist/profiles/types.d.ts.map +1 -0
- package/dist/profiles/types.js +2 -0
- package/dist/profiles/types.js.map +1 -0
- package/dist/seo-graph.d.ts +39 -0
- package/dist/seo-graph.d.ts.map +1 -0
- package/dist/seo-graph.js +34 -0
- package/dist/seo-graph.js.map +1 -0
- package/dist/types/built-in/content.d.ts +12 -0
- package/dist/types/built-in/content.d.ts.map +1 -0
- package/dist/types/built-in/content.js +79 -0
- package/dist/types/built-in/content.js.map +1 -0
- package/dist/types/built-in/events.d.ts +23 -0
- package/dist/types/built-in/events.d.ts.map +1 -0
- package/dist/types/built-in/events.js +93 -0
- package/dist/types/built-in/events.js.map +1 -0
- package/dist/types/built-in/index.d.ts +4 -0
- package/dist/types/built-in/index.d.ts.map +1 -0
- package/dist/types/built-in/index.js +26 -0
- package/dist/types/built-in/index.js.map +1 -0
- package/dist/types/built-in/media.d.ts +21 -0
- package/dist/types/built-in/media.d.ts.map +1 -0
- package/dist/types/built-in/media.js +104 -0
- package/dist/types/built-in/media.js.map +1 -0
- package/dist/types/built-in/site.d.ts +14 -0
- package/dist/types/built-in/site.d.ts.map +1 -0
- package/dist/types/built-in/site.js +35 -0
- package/dist/types/built-in/site.js.map +1 -0
- package/dist/types/context.d.ts +26 -0
- package/dist/types/context.d.ts.map +1 -0
- package/dist/types/context.js +44 -0
- package/dist/types/context.js.map +1 -0
- package/dist/types/definition.d.ts +58 -0
- package/dist/types/definition.d.ts.map +1 -0
- package/dist/types/definition.js +2 -0
- package/dist/types/definition.js.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/registry.d.ts +14 -0
- package/dist/types/registry.d.ts.map +1 -0
- package/dist/types/registry.js +37 -0
- package/dist/types/registry.js.map +1 -0
- package/dist/types/values.d.ts +23 -0
- package/dist/types/values.d.ts.map +1 -0
- package/dist/types/values.js +52 -0
- package/dist/types/values.js.map +1 -0
- package/dist/validate/check-terms.d.ts +15 -0
- package/dist/validate/check-terms.d.ts.map +1 -0
- package/dist/validate/check-terms.js +42 -0
- package/dist/validate/check-terms.js.map +1 -0
- package/dist/validate/check-value.d.ts +19 -0
- package/dist/validate/check-value.d.ts.map +1 -0
- package/dist/validate/check-value.js +77 -0
- package/dist/validate/check-value.js.map +1 -0
- package/dist/validate/graph-nodes.d.ts +22 -0
- package/dist/validate/graph-nodes.d.ts.map +1 -0
- package/dist/validate/graph-nodes.js +50 -0
- package/dist/validate/graph-nodes.js.map +1 -0
- package/dist/validate/index.d.ts +4 -0
- package/dist/validate/index.d.ts.map +1 -0
- package/dist/validate/index.js +2 -0
- package/dist/validate/index.js.map +1 -0
- package/dist/validate/types.d.ts +22 -0
- package/dist/validate/types.d.ts.map +1 -0
- package/dist/validate/types.js +2 -0
- package/dist/validate/types.js.map +1 -0
- package/dist/validate/validate-graph.d.ts +18 -0
- package/dist/validate/validate-graph.d.ts.map +1 -0
- package/dist/validate/validate-graph.js +109 -0
- package/dist/validate/validate-graph.js.map +1 -0
- package/dist/vocabulary/datatypes.d.ts +7 -0
- package/dist/vocabulary/datatypes.d.ts.map +1 -0
- package/dist/vocabulary/datatypes.js +46 -0
- package/dist/vocabulary/datatypes.js.map +1 -0
- package/dist/vocabulary/index.d.ts +5 -0
- package/dist/vocabulary/index.d.ts.map +1 -0
- package/dist/vocabulary/index.js +4 -0
- package/dist/vocabulary/index.js.map +1 -0
- package/dist/vocabulary/schemaorg.generated.d.ts +4 -0
- package/dist/vocabulary/schemaorg.generated.d.ts.map +1 -0
- package/dist/vocabulary/schemaorg.generated.js +3038 -0
- package/dist/vocabulary/schemaorg.generated.js.map +1 -0
- package/dist/vocabulary/types.d.ts +38 -0
- package/dist/vocabulary/types.d.ts.map +1 -0
- package/dist/vocabulary/types.js +2 -0
- package/dist/vocabulary/types.js.map +1 -0
- package/dist/vocabulary/vocabulary.d.ts +28 -0
- package/dist/vocabulary/vocabulary.d.ts.map +1 -0
- package/dist/vocabulary/vocabulary.js +89 -0
- package/dist/vocabulary/vocabulary.js.map +1 -0
- package/package.json +40 -3
- package/README.md +0 -3
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ORGANIZATION_RULE, siteOrganization } from '../context.js';
|
|
2
|
+
/**
|
|
3
|
+
* The site's organization. Its identity — name, address, logo, description,
|
|
4
|
+
* profiles — comes from the site configuration and is carried by the
|
|
5
|
+
* composer; the builder only places it.
|
|
6
|
+
*/
|
|
7
|
+
export const organizationType = {
|
|
8
|
+
type: 'Organization',
|
|
9
|
+
scope: 'site',
|
|
10
|
+
idFragment: 'business',
|
|
11
|
+
build: (context) => ({ '@type': context.type, '@id': context.id }),
|
|
12
|
+
};
|
|
13
|
+
/** A business with a physical location, identified like the Organization */
|
|
14
|
+
export const localBusinessType = { ...organizationType, type: 'LocalBusiness' };
|
|
15
|
+
/** The website, published by the site's organization */
|
|
16
|
+
export const webSiteType = {
|
|
17
|
+
type: 'WebSite',
|
|
18
|
+
scope: 'site',
|
|
19
|
+
idFragment: 'website',
|
|
20
|
+
references: { publisher: ORGANIZATION_RULE },
|
|
21
|
+
build: (context) => ({
|
|
22
|
+
'@type': context.type,
|
|
23
|
+
'@id': context.id,
|
|
24
|
+
publisher: siteOrganization(context),
|
|
25
|
+
}),
|
|
26
|
+
};
|
|
27
|
+
/** The person behind the site, named by the content's author when a page describes them */
|
|
28
|
+
export const personType = {
|
|
29
|
+
type: 'Person',
|
|
30
|
+
scope: 'site',
|
|
31
|
+
idFragment: 'person',
|
|
32
|
+
fields: { name: ['author'] },
|
|
33
|
+
build: (context) => ({ '@type': context.type, '@id': context.id }),
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=site.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site.js","sourceRoot":"","sources":["../../../src/types/built-in/site.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAGnE;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAmB;IAC9C,IAAI,EAAE,cAAc;IACpB,KAAK,EAAE,MAAM;IACb,UAAU,EAAE,UAAU;IACtB,KAAK,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC;CACnE,CAAA;AAED,4EAA4E;AAC5E,MAAM,CAAC,MAAM,iBAAiB,GAAmB,EAAE,GAAG,gBAAgB,EAAE,IAAI,EAAE,eAAe,EAAE,CAAA;AAE/F,wDAAwD;AACxD,MAAM,CAAC,MAAM,WAAW,GAAmB;IACzC,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,MAAM;IACb,UAAU,EAAE,SAAS;IACrB,UAAU,EAAE,EAAE,SAAS,EAAE,iBAAiB,EAAE;IAC5C,KAAK,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACnB,OAAO,EAAE,OAAO,CAAC,IAAI;QACrB,KAAK,EAAE,OAAO,CAAC,EAAE;QACjB,SAAS,EAAE,gBAAgB,CAAC,OAAO,CAAC;KACrC,CAAC;CACH,CAAA;AAED,2FAA2F;AAC3F,MAAM,CAAC,MAAM,UAAU,GAAmB;IACxC,IAAI,EAAE,QAAQ;IACd,KAAK,EAAE,MAAM;IACb,UAAU,EAAE,QAAQ;IACpB,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,QAAQ,CAAC,EAAE;IAC5B,KAAK,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC;CACnE,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { BuildContext, ReferenceRule } from './definition.js';
|
|
2
|
+
/** A property's resolved value */
|
|
3
|
+
export declare function propertyValue(context: BuildContext, property: string): unknown;
|
|
4
|
+
/** A property's resolved value as a string, '' when absent or not text */
|
|
5
|
+
export declare function textOf(context: BuildContext, property: string): string;
|
|
6
|
+
/** The site's organization, which publishes, provides and organizes on the site's behalf */
|
|
7
|
+
export declare function siteOrganization(context: BuildContext): {
|
|
8
|
+
'@id': string;
|
|
9
|
+
};
|
|
10
|
+
/** The site entity a WebSite reference points at */
|
|
11
|
+
export declare function siteWebsite(context: BuildContext): {
|
|
12
|
+
'@id': string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The author: the content's own (a name becomes a Person; a node is kept as
|
|
16
|
+
* it is), else a reference to the site's Person, which the composer
|
|
17
|
+
* resolves by `AUTHOR_RULE`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function authorOf(context: BuildContext): unknown;
|
|
20
|
+
/** An author is the configured Person, else the publishing Organization */
|
|
21
|
+
export declare const AUTHOR_RULE: ReferenceRule;
|
|
22
|
+
/** Publisher, provider, organizer, hiring organization: the site's Organization */
|
|
23
|
+
export declare const ORGANIZATION_RULE: ReferenceRule;
|
|
24
|
+
/** The WebSite a page belongs to, when the site configures one */
|
|
25
|
+
export declare const WEBSITE_RULE: ReferenceRule;
|
|
26
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/types/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAGlE,kCAAkC;AAClC,wBAAgB,aAAa,CAAC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAE9E;AAED,0EAA0E;AAC1E,wBAAgB,MAAM,CAAC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED,4FAA4F;AAC5F,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,YAAY,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAEzE;AAED,oDAAoD;AACpD,wBAAgB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAEpE;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAKvD;AAED,2EAA2E;AAC3E,eAAO,MAAM,WAAW,EAAE,aAGzB,CAAA;AAED,mFAAmF;AACnF,eAAO,MAAM,iBAAiB,EAAE,aAG/B,CAAA;AAED,kEAAkE;AAClE,eAAO,MAAM,YAAY,EAAE,aAAuD,CAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { businessId, personId, websiteId } from '../graph/id-conventions.js';
|
|
2
|
+
import { asString, ref } from './values.js';
|
|
3
|
+
/** A property's resolved value */
|
|
4
|
+
export function propertyValue(context, property) {
|
|
5
|
+
return context.values.get(property)?.value;
|
|
6
|
+
}
|
|
7
|
+
/** A property's resolved value as a string, '' when absent or not text */
|
|
8
|
+
export function textOf(context, property) {
|
|
9
|
+
return asString(propertyValue(context, property));
|
|
10
|
+
}
|
|
11
|
+
/** The site's organization, which publishes, provides and organizes on the site's behalf */
|
|
12
|
+
export function siteOrganization(context) {
|
|
13
|
+
return ref(businessId(context.site.baseUrl));
|
|
14
|
+
}
|
|
15
|
+
/** The site entity a WebSite reference points at */
|
|
16
|
+
export function siteWebsite(context) {
|
|
17
|
+
return ref(websiteId(context.site.baseUrl));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The author: the content's own (a name becomes a Person; a node is kept as
|
|
21
|
+
* it is), else a reference to the site's Person, which the composer
|
|
22
|
+
* resolves by `AUTHOR_RULE`.
|
|
23
|
+
*/
|
|
24
|
+
export function authorOf(context) {
|
|
25
|
+
const author = propertyValue(context, 'author');
|
|
26
|
+
if (typeof author === 'string' && author.length > 0)
|
|
27
|
+
return { '@type': 'Person', name: author };
|
|
28
|
+
if (author && typeof author === 'object')
|
|
29
|
+
return author;
|
|
30
|
+
return ref(personId(context.site.baseUrl));
|
|
31
|
+
}
|
|
32
|
+
/** An author is the configured Person, else the publishing Organization */
|
|
33
|
+
export const AUTHOR_RULE = {
|
|
34
|
+
types: ['Person', 'Organization'],
|
|
35
|
+
resolve: 'site-entity',
|
|
36
|
+
};
|
|
37
|
+
/** Publisher, provider, organizer, hiring organization: the site's Organization */
|
|
38
|
+
export const ORGANIZATION_RULE = {
|
|
39
|
+
types: ['Organization', 'Person'],
|
|
40
|
+
resolve: 'site-entity',
|
|
41
|
+
};
|
|
42
|
+
/** The WebSite a page belongs to, when the site configures one */
|
|
43
|
+
export const WEBSITE_RULE = { types: ['WebSite'], resolve: 'omit' };
|
|
44
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/types/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAE5E,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAE3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GAAkB;IAC9C,KAAK,EAAE,CAAC,cAAc,EAAE,QAAQ,CAAC;IACjC,OAAO,EAAE,aAAa;CACvB,CAAA;AAED,kEAAkE;AAClE,MAAM,CAAC,MAAM,YAAY,GAAkB,EAAE,KAAK,EAAE,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAA"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { TrailItem } from '@krantho/core';
|
|
2
|
+
import type { PropertySource } from '../catalog/property-atoms.js';
|
|
3
|
+
import type { SchemaEntity, SeoGraphConfig } from '../graph/types.js';
|
|
4
|
+
/** A property's effective value and where it comes from */
|
|
5
|
+
export interface ResolvedProperty {
|
|
6
|
+
readonly value: unknown;
|
|
7
|
+
readonly source: PropertySource;
|
|
8
|
+
/** Where the value was read: a content field, a configuration setting, or how it was computed */
|
|
9
|
+
readonly origin: string;
|
|
10
|
+
}
|
|
11
|
+
/** Whether an entity describes the site as a whole or the page being rendered */
|
|
12
|
+
export type EntityLevel = 'site' | 'document';
|
|
13
|
+
/** What a type definition builds an entity from */
|
|
14
|
+
export interface BuildContext {
|
|
15
|
+
/** The Schema.org type being built — the definition's own, or a configured subtype */
|
|
16
|
+
readonly type: string;
|
|
17
|
+
readonly id: string;
|
|
18
|
+
readonly level: EntityLevel;
|
|
19
|
+
readonly site: SeoGraphConfig;
|
|
20
|
+
/** The page path, `/` for site entities */
|
|
21
|
+
readonly path: string;
|
|
22
|
+
/** Every property's resolved value, by Schema.org property name */
|
|
23
|
+
readonly values: ReadonlyMap<string, ResolvedProperty>;
|
|
24
|
+
/** The page's title, as its content states it */
|
|
25
|
+
readonly title?: string | undefined;
|
|
26
|
+
/** Question and answer pairs the page renders */
|
|
27
|
+
readonly faq?: ReadonlyArray<{
|
|
28
|
+
question: string;
|
|
29
|
+
answer: string;
|
|
30
|
+
}> | undefined;
|
|
31
|
+
/** The trail the page renders, root first, with absolute URLs */
|
|
32
|
+
readonly trail?: readonly TrailItem[] | undefined;
|
|
33
|
+
}
|
|
34
|
+
/** How the composer satisfies a reference whose target is not in the graph */
|
|
35
|
+
export interface ReferenceRule {
|
|
36
|
+
/** Acceptable target types, in order of preference */
|
|
37
|
+
readonly types: readonly string[];
|
|
38
|
+
/** `site-entity`: point it at a site entity of an acceptable type; `omit`: remove it */
|
|
39
|
+
readonly resolve: 'site-entity' | 'omit';
|
|
40
|
+
}
|
|
41
|
+
/** How krantho builds one Schema.org type */
|
|
42
|
+
export interface TypeDefinition {
|
|
43
|
+
/** The Schema.org type; it must exist in the vocabulary and be current */
|
|
44
|
+
readonly type: string;
|
|
45
|
+
/** `site`: one entity for the whole site, whose `@id` does not depend on the page */
|
|
46
|
+
readonly scope: 'site' | 'document';
|
|
47
|
+
/** The `@id` fragment: `#article`, `#business` … */
|
|
48
|
+
readonly idFragment: string;
|
|
49
|
+
/** Content fields, besides one named after the property, that hold a property's value */
|
|
50
|
+
readonly fields?: Readonly<Record<string, readonly string[]>> | undefined;
|
|
51
|
+
/** Computed page properties the entity carries; all of them when absent */
|
|
52
|
+
readonly computed?: readonly string[] | undefined;
|
|
53
|
+
/** Properties whose values are references the composer must resolve */
|
|
54
|
+
readonly references?: Readonly<Record<string, ReferenceRule>> | undefined;
|
|
55
|
+
/** The entity's structure; values the builder leaves out are carried by the composer */
|
|
56
|
+
build(context: BuildContext): SchemaEntity;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=definition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["../../src/types/definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAErE,2DAA2D;AAC3D,MAAM,WAAW,gBAAgB;IAC/B,QAAQ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KAAK,EAAE,MAAM,GAAG,UAAU,CAAA;IACnC,oDAAoD;IACpD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,yFAAyF;IACzF,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,GAAG,SAAS,CAAA;IACzE,2EAA2E;IAC3E,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAA;IACjD,uEAAuE;IACvE,QAAQ,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,GAAG,SAAS,CAAA;IACzE,wFAAwF;IACxF,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,YAAY,CAAA;CAC3C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definition.js","sourceRoot":"","sources":["../../src/types/definition.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { BUILT_IN_TYPES } from './built-in/index.js';
|
|
2
|
+
export type { BuildContext, EntityLevel, ReferenceRule, ResolvedProperty, TypeDefinition, } from './definition.js';
|
|
3
|
+
export { getTypeDefinition, registeredTypes, registerType } from './registry.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,YAAY,EACV,YAAY,EACZ,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,cAAc,GACf,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAQpD,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { TypeDefinition } from './definition.js';
|
|
2
|
+
/**
|
|
3
|
+
* Register how a Schema.org type is built. A site registers its own types the
|
|
4
|
+
* same way krantho registers its built-ins; a later registration for a type
|
|
5
|
+
* replaces the earlier one. Throws for a type the vocabulary does not have, or
|
|
6
|
+
* one Schema.org has superseded or retired. Returns a function that restores
|
|
7
|
+
* the previous registration.
|
|
8
|
+
*/
|
|
9
|
+
export declare function registerType(definition: TypeDefinition): () => void;
|
|
10
|
+
/** The definition registered for the type; undefined builds it generically */
|
|
11
|
+
export declare function getTypeDefinition(type: string): TypeDefinition | undefined;
|
|
12
|
+
/** The types with a registered definition */
|
|
13
|
+
export declare function registeredTypes(): readonly string[];
|
|
14
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/types/registry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAIrD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,cAAc,GAAG,MAAM,IAAI,CAenE;AAED,8EAA8E;AAC9E,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAE1E;AAED,6CAA6C;AAC7C,wBAAgB,eAAe,IAAI,SAAS,MAAM,EAAE,CAEnD"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { getVocabularyType, lifecycleOf } from '../vocabulary/index.js';
|
|
2
|
+
const definitions = new Map();
|
|
3
|
+
/**
|
|
4
|
+
* Register how a Schema.org type is built. A site registers its own types the
|
|
5
|
+
* same way krantho registers its built-ins; a later registration for a type
|
|
6
|
+
* replaces the earlier one. Throws for a type the vocabulary does not have, or
|
|
7
|
+
* one Schema.org has superseded or retired. Returns a function that restores
|
|
8
|
+
* the previous registration.
|
|
9
|
+
*/
|
|
10
|
+
export function registerType(definition) {
|
|
11
|
+
if (!getVocabularyType(definition.type)) {
|
|
12
|
+
throw new Error(`registerType: "${definition.type}" is not a Schema.org type.`);
|
|
13
|
+
}
|
|
14
|
+
const lifecycle = lifecycleOf(definition.type);
|
|
15
|
+
if (lifecycle?.status === 'superseded' || lifecycle?.status === 'retired') {
|
|
16
|
+
throw new Error(`registerType: "${definition.type}" is ${lifecycle.status} in Schema.org.`);
|
|
17
|
+
}
|
|
18
|
+
const previous = definitions.get(definition.type);
|
|
19
|
+
definitions.set(definition.type, definition);
|
|
20
|
+
return () => {
|
|
21
|
+
if (definitions.get(definition.type) !== definition)
|
|
22
|
+
return;
|
|
23
|
+
if (previous)
|
|
24
|
+
definitions.set(definition.type, previous);
|
|
25
|
+
else
|
|
26
|
+
definitions.delete(definition.type);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** The definition registered for the type; undefined builds it generically */
|
|
30
|
+
export function getTypeDefinition(type) {
|
|
31
|
+
return definitions.get(type);
|
|
32
|
+
}
|
|
33
|
+
/** The types with a registered definition */
|
|
34
|
+
export function registeredTypes() {
|
|
35
|
+
return [...definitions.keys()];
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/types/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAGvE,MAAM,WAAW,GAAG,IAAI,GAAG,EAA0B,CAAA;AAErD;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,UAA0B;IACrD,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,kBAAkB,UAAU,CAAC,IAAI,6BAA6B,CAAC,CAAA;IACjF,CAAC;IACD,MAAM,SAAS,GAAG,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;IAC9C,IAAI,SAAS,EAAE,MAAM,KAAK,YAAY,IAAI,SAAS,EAAE,MAAM,KAAK,SAAS,EAAE,CAAC;QAC1E,MAAM,IAAI,KAAK,CAAC,kBAAkB,UAAU,CAAC,IAAI,QAAQ,SAAS,CAAC,MAAM,iBAAiB,CAAC,CAAA;IAC7F,CAAC;IACD,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;IACjD,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;IAC5C,OAAO,GAAG,EAAE;QACV,IAAI,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,UAAU;YAAE,OAAM;QAC3D,IAAI,QAAQ;YAAE,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;;YACnD,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;IAC1C,CAAC,CAAA;AACH,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,OAAO,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;AAC9B,CAAC;AAED,6CAA6C;AAC7C,MAAM,UAAU,eAAe;IAC7B,OAAO,CAAC,GAAG,WAAW,CAAC,IAAI,EAAE,CAAC,CAAA;AAChC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SchemaEntity } from '../graph/types.js';
|
|
2
|
+
/** Whether a value carries nothing: undefined, null, an empty string or an empty array */
|
|
3
|
+
export declare function isEmpty(value: unknown): boolean;
|
|
4
|
+
/** A string value, or '' when the value is not a string */
|
|
5
|
+
export declare function asString(value: unknown): string;
|
|
6
|
+
/**
|
|
7
|
+
* A list of strings: an array's string entries, a comma-separated string
|
|
8
|
+
* split, or a single string. Empty entries are dropped.
|
|
9
|
+
*/
|
|
10
|
+
export declare function asStringList(value: unknown): string[];
|
|
11
|
+
/** The entity without empty properties, so JSON-LD output stays clean */
|
|
12
|
+
export declare function compact(entity: SchemaEntity): SchemaEntity;
|
|
13
|
+
/**
|
|
14
|
+
* A sub-entity from a value that is either an object (its properties, typed)
|
|
15
|
+
* or a string (wrapped as `{ '@type': type, [stringKey]: value }`); undefined
|
|
16
|
+
* when there is nothing to wrap.
|
|
17
|
+
*/
|
|
18
|
+
export declare function asSubEntity(value: unknown, type: string, stringKey: string): SchemaEntity | undefined;
|
|
19
|
+
/** A reference to the node with that `@id` */
|
|
20
|
+
export declare function ref(id: string): {
|
|
21
|
+
'@id': string;
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=values.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"values.d.ts","sourceRoot":"","sources":["../../src/types/values.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,0FAA0F;AAC1F,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAI/C;AAED,2DAA2D;AAC3D,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAE/C;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,EAAE,CAOrD;AAED,yEAAyE;AACzE,wBAAgB,OAAO,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAM1D;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,GAChB,YAAY,GAAG,SAAS,CAQ1B;AAED,8CAA8C;AAC9C,wBAAgB,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAEjD"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** Whether a value carries nothing: undefined, null, an empty string or an empty array */
|
|
2
|
+
export function isEmpty(value) {
|
|
3
|
+
if (value === undefined || value === null)
|
|
4
|
+
return true;
|
|
5
|
+
if (typeof value === 'string')
|
|
6
|
+
return value.length === 0;
|
|
7
|
+
return Array.isArray(value) && value.length === 0;
|
|
8
|
+
}
|
|
9
|
+
/** A string value, or '' when the value is not a string */
|
|
10
|
+
export function asString(value) {
|
|
11
|
+
return typeof value === 'string' ? value : '';
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A list of strings: an array's string entries, a comma-separated string
|
|
15
|
+
* split, or a single string. Empty entries are dropped.
|
|
16
|
+
*/
|
|
17
|
+
export function asStringList(value) {
|
|
18
|
+
const items = Array.isArray(value)
|
|
19
|
+
? value.filter((v) => typeof v === 'string')
|
|
20
|
+
: typeof value === 'string'
|
|
21
|
+
? value.split(',')
|
|
22
|
+
: [];
|
|
23
|
+
return items.map((s) => s.trim()).filter((s) => s.length > 0);
|
|
24
|
+
}
|
|
25
|
+
/** The entity without empty properties, so JSON-LD output stays clean */
|
|
26
|
+
export function compact(entity) {
|
|
27
|
+
const result = { '@type': entity['@type'] };
|
|
28
|
+
for (const [key, value] of Object.entries(entity)) {
|
|
29
|
+
if (!isEmpty(value))
|
|
30
|
+
result[key] = value;
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A sub-entity from a value that is either an object (its properties, typed)
|
|
36
|
+
* or a string (wrapped as `{ '@type': type, [stringKey]: value }`); undefined
|
|
37
|
+
* when there is nothing to wrap.
|
|
38
|
+
*/
|
|
39
|
+
export function asSubEntity(value, type, stringKey) {
|
|
40
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
41
|
+
return compact({ '@type': type, ...value });
|
|
42
|
+
}
|
|
43
|
+
if (typeof value === 'string' && value.length > 0) {
|
|
44
|
+
return compact({ '@type': type, [stringKey]: value });
|
|
45
|
+
}
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
/** A reference to the node with that `@id` */
|
|
49
|
+
export function ref(id) {
|
|
50
|
+
return { '@id': id };
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=values.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"values.js","sourceRoot":"","sources":["../../src/types/values.ts"],"names":[],"mappings":"AAEA,0FAA0F;AAC1F,MAAM,UAAU,OAAO,CAAC,KAAc;IACpC,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAA;IACtD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,CAAA;IACxD,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,CAAA;AACnD,CAAC;AAED,2DAA2D;AAC3D,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;AAC/C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAChC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC;QACzD,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ;YACzB,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC;YAClB,CAAC,CAAC,EAAE,CAAA;IACR,O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import type { Finding } from './types.js';
|
|
2
|
+
/** What kind of term is checked, for the message */
|
|
3
|
+
export type TermKind = 'Type' | 'Property' | 'Value';
|
|
4
|
+
/** Where the term appears */
|
|
5
|
+
export interface TermContext {
|
|
6
|
+
nodeId?: string | undefined;
|
|
7
|
+
type?: string | undefined;
|
|
8
|
+
property?: string | undefined;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Life-cycle findings for a Schema.org term: superseded and retired terms are
|
|
12
|
+
* errors (the message names the replacement), a pending term is information.
|
|
13
|
+
*/
|
|
14
|
+
export declare function termFindings(kind: TermKind, term: string, context: TermContext): Finding[];
|
|
15
|
+
//# sourceMappingURL=check-terms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-terms.d.ts","sourceRoot":"","sources":["../../src/validate/check-terms.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEzC,oDAAoD;AACpD,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,UAAU,GAAG,OAAO,CAAA;AAEpD,6BAA6B;AAC7B,MAAM,WAAW,WAAW;IAC1B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC9B;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,EAAE,CAkC1F"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { lifecycleOf, termName } from '../vocabulary/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Life-cycle findings for a Schema.org term: superseded and retired terms are
|
|
4
|
+
* errors (the message names the replacement), a pending term is information.
|
|
5
|
+
*/
|
|
6
|
+
export function termFindings(kind, term, context) {
|
|
7
|
+
const lifecycle = lifecycleOf(term);
|
|
8
|
+
if (!lifecycle)
|
|
9
|
+
return [];
|
|
10
|
+
const name = termName(term);
|
|
11
|
+
const base = { profile: 'schema.org', ...context };
|
|
12
|
+
switch (lifecycle.status) {
|
|
13
|
+
case 'superseded':
|
|
14
|
+
return [
|
|
15
|
+
{
|
|
16
|
+
...base,
|
|
17
|
+
severity: 'error',
|
|
18
|
+
code: 'superseded-term',
|
|
19
|
+
message: `${kind} "${name}" is superseded by "${lifecycle.by}" in Schema.org.`,
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
case 'retired':
|
|
23
|
+
return [
|
|
24
|
+
{
|
|
25
|
+
...base,
|
|
26
|
+
severity: 'error',
|
|
27
|
+
code: 'retired-term',
|
|
28
|
+
message: `${kind} "${name}" is retired from Schema.org.`,
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
case 'pending':
|
|
32
|
+
return [
|
|
33
|
+
{
|
|
34
|
+
...base,
|
|
35
|
+
severity: 'info',
|
|
36
|
+
code: 'pending-term',
|
|
37
|
+
message: `${kind} "${name}" is a pending Schema.org term, not yet part of the core vocabulary.`,
|
|
38
|
+
},
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=check-terms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-terms.js","sourceRoot":"","sources":["../../src/validate/check-terms.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AAa9D;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,IAAc,EAAE,IAAY,EAAE,OAAoB;IAC7E,MAAM,SAAS,GAAG,WAAW,CAAC,IAAI,CAAC,CAAA;IACnC,IAAI,CAAC,SAAS;QAAE,OAAO,EAAE,CAAA;IACzB,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAA;IAC3B,MAAM,IAAI,GAAG,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,OAAO,EAAE,CAAA;IAClD,QAAQ,SAAS,CAAC,MAAM,EAAE,CAAC;QACzB,KAAK,YAAY;YACf,OAAO;gBACL;oBACE,GAAG,IAAI;oBACP,QAAQ,EAAE,OAAO;oBACjB,IAAI,EAAE,iBAAiB;oBACvB,OAAO,EAAE,GAAG,IAAI,KAAK,IAAI,uBAAuB,SAAS,CAAC,EAAE,kBAAkB;iBAC/E;aACF,CAAA;QACH,KAAK,SAAS;YACZ,OAAO;gBACL;oBACE,GAAG,IAAI;oBACP,QAAQ,EAAE,OAAO;oBACjB,IAAI,EAAE,cAAc;oBACpB,OAAO,EAAE,GAAG,IAAI,KAAK,IAAI,+BAA+B;iBACzD;aACF,CAAA;QACH,KAAK,SAAS;YACZ,OAAO;gBACL;oBACE,GAAG,IAAI;oBACP,QAAQ,EAAE,MAAM;oBAChB,IAAI,EAAE,cAAc;oBACpB,OAAO,EAAE,GAAG,IAAI,KAAK,IAAI,sEAAsE;iBAChG;aACF,CAAA;IACL,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Finding, GraphNode } from './types.js';
|
|
2
|
+
/** Where a value appears */
|
|
3
|
+
export interface ValuePlace {
|
|
4
|
+
nodeId?: string | undefined;
|
|
5
|
+
type?: string | undefined;
|
|
6
|
+
property: string;
|
|
7
|
+
}
|
|
8
|
+
/** The value's place, and the graph's node definitions by `@id` */
|
|
9
|
+
export interface ValueContext {
|
|
10
|
+
where: ValuePlace;
|
|
11
|
+
definitions: ReadonlyMap<string, GraphNode>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Findings for one value of a property: a reference must resolve to a node of
|
|
15
|
+
* a type in the property's range, a nested node must have such a type, and a
|
|
16
|
+
* literal must fit a data type or enumeration in range.
|
|
17
|
+
*/
|
|
18
|
+
export declare function valueFindings(value: unknown, context: ValueContext): Finding[];
|
|
19
|
+
//# sourceMappingURL=check-value.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-value.d.ts","sourceRoot":"","sources":["../../src/validate/check-value.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEpD,4BAA4B;AAC5B,MAAM,WAAW,UAAU;IACzB,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,mEAAmE;AACnE,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,UAAU,CAAA;IACjB,WAAW,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;CAC5C;AA8DD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,EAAE,CAW9E"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { enumerationsOf, getVocabularyProperty, isDatatype, isEnumeration, isSubtypeOf, matchesDatatype, rangeAcceptsType, } from '../vocabulary/index.js';
|
|
2
|
+
import { termFindings } from './check-terms.js';
|
|
3
|
+
import { idOf, isObject, isReference, typesOf } from './graph-nodes.js';
|
|
4
|
+
function display(value) {
|
|
5
|
+
const text = JSON.stringify(value) ?? String(value);
|
|
6
|
+
return text.length > 60 ? `${text.slice(0, 57)}…` : text;
|
|
7
|
+
}
|
|
8
|
+
function expected(range) {
|
|
9
|
+
return range.length <= 1
|
|
10
|
+
? (range[0] ?? '')
|
|
11
|
+
: `${range.slice(0, -1).join(', ')} or ${range.at(-1)}`;
|
|
12
|
+
}
|
|
13
|
+
function outOfRange(where, range, got) {
|
|
14
|
+
return {
|
|
15
|
+
...where,
|
|
16
|
+
severity: 'error',
|
|
17
|
+
code: 'value-out-of-range',
|
|
18
|
+
profile: 'schema.org',
|
|
19
|
+
message: `"${where.property}" expects ${expected(range)}; got ${got}.`,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** Findings for a literal: it must match a data type, or name an enumeration member, in range */
|
|
23
|
+
function literalFindings(value, range, where) {
|
|
24
|
+
if (range.some((type) => isDatatype(type) && matchesDatatype(type, value)))
|
|
25
|
+
return [];
|
|
26
|
+
if (typeof value === 'string') {
|
|
27
|
+
const enumerations = range.filter(isEnumeration);
|
|
28
|
+
const memberOf = enumerationsOf(value);
|
|
29
|
+
if (memberOf.some((member) => enumerations.some((type) => isSubtypeOf(member, type)))) {
|
|
30
|
+
return termFindings('Value', value, where);
|
|
31
|
+
}
|
|
32
|
+
// Schema.org accepts text where a thing is expected ("some data is better than none").
|
|
33
|
+
if (range.some((type) => !isDatatype(type) && !isEnumeration(type)))
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
return [outOfRange(where, range, display(value))];
|
|
37
|
+
}
|
|
38
|
+
/** Findings for a reference: its target must exist and have a type in range */
|
|
39
|
+
function referenceFindings(id, range, context) {
|
|
40
|
+
const target = context.definitions.get(id);
|
|
41
|
+
const { where } = context;
|
|
42
|
+
if (!target) {
|
|
43
|
+
const message = `"${where.property}" refers to "${id}", which no node in the graph defines.`;
|
|
44
|
+
return [
|
|
45
|
+
{ ...where, severity: 'error', code: 'unresolved-reference', profile: 'schema.org', message },
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
return nodeTypeFindings(target, range, where, `"${id}" (${typesOf(target).join(', ')})`);
|
|
49
|
+
}
|
|
50
|
+
function nodeTypeFindings(node, range, where, got) {
|
|
51
|
+
const types = typesOf(node);
|
|
52
|
+
if (types.length === 0 || types.some((type) => rangeAcceptsType(where.property, type)))
|
|
53
|
+
return [];
|
|
54
|
+
return [outOfRange(where, range, got)];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Findings for one value of a property: a reference must resolve to a node of
|
|
58
|
+
* a type in the property's range, a nested node must have such a type, and a
|
|
59
|
+
* literal must fit a data type or enumeration in range.
|
|
60
|
+
*/
|
|
61
|
+
export function valueFindings(value, context) {
|
|
62
|
+
if (value === null || value === undefined)
|
|
63
|
+
return [];
|
|
64
|
+
const { where } = context;
|
|
65
|
+
const range = getVocabularyProperty(where.property)?.range ?? [];
|
|
66
|
+
if (range.length === 0)
|
|
67
|
+
return [];
|
|
68
|
+
if (isReference(value))
|
|
69
|
+
return referenceFindings(idOf(value) ?? '', range, context);
|
|
70
|
+
if (isObject(value)) {
|
|
71
|
+
if ('@value' in value)
|
|
72
|
+
return literalFindings(value['@value'], range, where);
|
|
73
|
+
return nodeTypeFindings(value, range, where, `a ${typesOf(value).join(', ')}`);
|
|
74
|
+
}
|
|
75
|
+
return literalFindings(value, range, where);
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=check-value.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-value.js","sourceRoot":"","sources":["../../src/validate/check-value.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,UAAU,EACV,aAAa,EACb,WAAW,EACX,eAAe,EACf,gBAAgB,GACjB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAgBvE,SAAS,OAAO,CAAC,KAAc;IAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,CAAA;IACnD,OAAO,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAA;AAC1D,CAAC;AAED,SAAS,QAAQ,CAAC,KAAwB;IACxC,OAAO,KAAK,CAAC,MAAM,IAAI,CAA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,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC,CAAA;AACxC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc,EAAE,OAAqB;IACjE,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,EAAE,CAAA;IACpD,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAA;IACzB,MAAM,KAAK,GAAG,qBAAqB,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,KAAK,IAAI,EAAE,CAAA;IAChE,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAA;IACjC,IAAI,WAAW,CAAC,KAAK,CAAC;QAAE,OAAO,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,CAAA;IACnF,IAAI,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACpB,IAAI,QAAQ,IAAI,KAAK;YAAE,OAAO,eAAe,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;QAC5E,OAAO,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAChF,CAAC;IACD,OAAO,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;AAC7C,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { GraphNode } from './types.js';
|
|
2
|
+
/** Whether a value is a JSON object (not an array, not null) */
|
|
3
|
+
export declare function isObject(value: unknown): value is GraphNode;
|
|
4
|
+
/** A value as a list: arrays as they are, anything else as one element */
|
|
5
|
+
export declare function asList(value: unknown): readonly unknown[];
|
|
6
|
+
/** The node's types; empty when it has none */
|
|
7
|
+
export declare function typesOf(node: GraphNode): readonly string[];
|
|
8
|
+
/** The node's `@id`, when it has one */
|
|
9
|
+
export declare function idOf(node: GraphNode): string | undefined;
|
|
10
|
+
/** A reference: an object holding only `@id`, pointing at a node defined elsewhere */
|
|
11
|
+
export declare function isReference(value: unknown): value is GraphNode;
|
|
12
|
+
/** The top-level nodes of a graph: its `@graph` entries, or the root node itself */
|
|
13
|
+
export declare function topLevelNodes(graph: GraphNode): readonly GraphNode[];
|
|
14
|
+
/** The node's properties: every key that is not a JSON-LD keyword */
|
|
15
|
+
export declare function propertyEntries(node: GraphNode): ReadonlyArray<readonly [string, unknown]>;
|
|
16
|
+
/**
|
|
17
|
+
* Every node definition in the graph, top-level and nested, in document
|
|
18
|
+
* order. References are not definitions; a value object (`@value`) is not a
|
|
19
|
+
* node.
|
|
20
|
+
*/
|
|
21
|
+
export declare function allNodes(graph: GraphNode): readonly GraphNode[];
|
|
22
|
+
//# sourceMappingURL=graph-nodes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-nodes.d.ts","sourceRoot":"","sources":["../../src/validate/graph-nodes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAE3C,gEAAgE;AAChE,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAE3D;AAED,0EAA0E;AAC1E,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,OAAO,EAAE,CAEzD;AAED,+CAA+C;AAC/C,wBAAgB,OAAO,CAAC,IAAI,EAAE,SAAS,GAAG,SAAS,MAAM,EAAE,CAE1D;AAED,wCAAwC;AACxC,wBAAgB,IAAI,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,CAGxD;AAED,sFAAsF;AACtF,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAE9D;AAED,oFAAoF;AACpF,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,SAAS,EAAE,CAGpE;AAED,qEAAqE;AACrE,wBAAgB,eAAe,CAAC,IAAI,EAAE,SAAS,GAAG,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAE1F;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,SAAS,EAAE,CAW/D"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** Whether a value is a JSON object (not an array, not null) */
|
|
2
|
+
export function isObject(value) {
|
|
3
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
4
|
+
}
|
|
5
|
+
/** A value as a list: arrays as they are, anything else as one element */
|
|
6
|
+
export function asList(value) {
|
|
7
|
+
return Array.isArray(value) ? value : [value];
|
|
8
|
+
}
|
|
9
|
+
/** The node's types; empty when it has none */
|
|
10
|
+
export function typesOf(node) {
|
|
11
|
+
return asList(node['@type']).filter((type) => typeof type === 'string');
|
|
12
|
+
}
|
|
13
|
+
/** The node's `@id`, when it has one */
|
|
14
|
+
export function idOf(node) {
|
|
15
|
+
const id = node['@id'];
|
|
16
|
+
return typeof id === 'string' ? id : undefined;
|
|
17
|
+
}
|
|
18
|
+
/** A reference: an object holding only `@id`, pointing at a node defined elsewhere */
|
|
19
|
+
export function isReference(value) {
|
|
20
|
+
return isObject(value) && idOf(value) !== undefined && Object.keys(value).length === 1;
|
|
21
|
+
}
|
|
22
|
+
/** The top-level nodes of a graph: its `@graph` entries, or the root node itself */
|
|
23
|
+
export function topLevelNodes(graph) {
|
|
24
|
+
const nodes = '@graph' in graph ? asList(graph['@graph']) : [graph];
|
|
25
|
+
return nodes.filter(isObject);
|
|
26
|
+
}
|
|
27
|
+
/** The node's properties: every key that is not a JSON-LD keyword */
|
|
28
|
+
export function propertyEntries(node) {
|
|
29
|
+
return Object.entries(node).filter(([key]) => !key.startsWith('@'));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Every node definition in the graph, top-level and nested, in document
|
|
33
|
+
* order. References are not definitions; a value object (`@value`) is not a
|
|
34
|
+
* node.
|
|
35
|
+
*/
|
|
36
|
+
export function allNodes(graph) {
|
|
37
|
+
const found = [];
|
|
38
|
+
const visit = (value) => {
|
|
39
|
+
for (const item of asList(value)) {
|
|
40
|
+
if (!isObject(item) || isReference(item) || '@value' in item)
|
|
41
|
+
continue;
|
|
42
|
+
found.push(item);
|
|
43
|
+
for (const [, child] of propertyEntries(item))
|
|
44
|
+
visit(child);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
visit(topLevelNodes(graph));
|
|
48
|
+
return found;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=graph-nodes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-nodes.js","sourceRoot":"","sources":["../../src/validate/graph-nodes.ts"],"names":[],"mappings":"AAEA,gEAAgE;AAChE,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAC7E,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,MAAM,CAAC,KAAc;IACnC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;AAC/C,CAAC;AAED,+CAA+C;AAC/C,MAAM,UAAU,OAAO,CAAC,IAAe;IACrC,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAA;AACzF,CAAC;AAED,wCAAwC;AACxC,MAAM,UAAU,IAAI,CAAC,IAAe;IAClC,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,C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