@twin.org/standards-schema-org 0.0.2-next.9 → 0.0.3-next.1
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/{esm/index.mjs → es/dataTypes/schemaOrgDataTypes.js} +9 -184
- package/dist/es/dataTypes/schemaOrgDataTypes.js.map +1 -0
- package/dist/es/index.js +7 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/models/schemaOrgContexts.js +17 -0
- package/dist/es/models/schemaOrgContexts.js.map +1 -0
- package/dist/es/models/schemaOrgTypes.js +65 -0
- package/dist/es/models/schemaOrgTypes.js.map +1 -0
- package/dist/es/schemas/GeoCoordinates.json +16 -0
- package/dist/es/utils/schemaOrgValidation.js +67 -0
- package/dist/es/utils/schemaOrgValidation.js.map +1 -0
- package/dist/types/index.d.ts +4 -4
- package/docs/changelog.md +66 -0
- package/locales/en.json +0 -14
- package/package.json +23 -8
- package/dist/cjs/index.cjs +0 -299
|
@@ -1,190 +1,16 @@
|
|
|
1
|
-
import { Validation, Is, Coerce, Url } from '@twin.org/core';
|
|
2
|
-
import { DataTypeHandlerFactory } from '@twin.org/data-core';
|
|
3
|
-
import { JsonLdProcessor } from '@twin.org/data-json-ld';
|
|
4
|
-
|
|
5
|
-
// Copyright 2024 IOTA Stiftung.
|
|
6
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
7
|
-
/**
|
|
8
|
-
* The contexts of schema.org data.
|
|
9
|
-
*/
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
11
|
-
const SchemaOrgContexts = {
|
|
12
|
-
/**
|
|
13
|
-
* Context Root.
|
|
14
|
-
*/
|
|
15
|
-
ContextRoot: "https://schema.org",
|
|
16
|
-
/**
|
|
17
|
-
* The redirect for the JSON-LD definition.
|
|
18
|
-
*/
|
|
19
|
-
ContextRedirect: "https://schema.org/docs/jsonldcontext.json"
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// Copyright 2024 IOTA Stiftung.
|
|
23
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
24
|
-
/**
|
|
25
|
-
* The types of schema.org data.
|
|
26
|
-
*/
|
|
27
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
28
|
-
const SchemaOrgTypes = {
|
|
29
|
-
/**
|
|
30
|
-
* Represents text storage.
|
|
31
|
-
*/
|
|
32
|
-
Text: "Text",
|
|
33
|
-
/**
|
|
34
|
-
* Represents integer number values.
|
|
35
|
-
*/
|
|
36
|
-
Integer: "Integer",
|
|
37
|
-
/**
|
|
38
|
-
* Represents floating point numbers.
|
|
39
|
-
*/
|
|
40
|
-
Float: "Float",
|
|
41
|
-
/**
|
|
42
|
-
* Represents a boolean.
|
|
43
|
-
*/
|
|
44
|
-
Boolean: "Boolean",
|
|
45
|
-
/**
|
|
46
|
-
* Represents a url.
|
|
47
|
-
*/
|
|
48
|
-
URL: "URL",
|
|
49
|
-
/**
|
|
50
|
-
* Represents a date as an ISO format string.
|
|
51
|
-
*/
|
|
52
|
-
Date: "Date",
|
|
53
|
-
/**
|
|
54
|
-
* Represents a date time as an ISO format string.
|
|
55
|
-
*/
|
|
56
|
-
DateTime: "DateTime",
|
|
57
|
-
/**
|
|
58
|
-
* Represents a time as an ISO format string.
|
|
59
|
-
*/
|
|
60
|
-
Time: "Time",
|
|
61
|
-
/**
|
|
62
|
-
* Represents a url which points to an image.
|
|
63
|
-
*/
|
|
64
|
-
Image: "image",
|
|
65
|
-
/**
|
|
66
|
-
* Represents a location.
|
|
67
|
-
*/
|
|
68
|
-
GeoCoordinates: "GeoCoordinates",
|
|
69
|
-
/**
|
|
70
|
-
* Represents a structured value.
|
|
71
|
-
*/
|
|
72
|
-
StructuredValue: "StructuredValue",
|
|
73
|
-
/**
|
|
74
|
-
* Represents an item list.
|
|
75
|
-
*/
|
|
76
|
-
ItemList: "ItemList",
|
|
77
|
-
/**
|
|
78
|
-
* Represents an item list element.
|
|
79
|
-
*/
|
|
80
|
-
ItemListElement: "itemListElement",
|
|
81
|
-
/**
|
|
82
|
-
* Represents a next item (can be used as a cursor).
|
|
83
|
-
*/
|
|
84
|
-
NextItem: "nextItem"
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
var type = "object";
|
|
88
|
-
var required = [
|
|
89
|
-
"latitude",
|
|
90
|
-
"longitude"
|
|
91
|
-
];
|
|
92
|
-
var properties = {
|
|
93
|
-
latitude: {
|
|
94
|
-
type: [
|
|
95
|
-
"number",
|
|
96
|
-
"string"
|
|
97
|
-
],
|
|
98
|
-
minimum: -90,
|
|
99
|
-
maximum: 90
|
|
100
|
-
},
|
|
101
|
-
longitude: {
|
|
102
|
-
type: [
|
|
103
|
-
"number",
|
|
104
|
-
"string"
|
|
105
|
-
],
|
|
106
|
-
minimum: -180,
|
|
107
|
-
maximum: 180
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
var GeoCoordinatesSchema = {
|
|
111
|
-
type: type,
|
|
112
|
-
required: required,
|
|
113
|
-
properties: properties
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
// Copyright 2024 IOTA Stiftung.
|
|
117
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
118
|
-
/**
|
|
119
|
-
* Handle validation for schema.org.
|
|
120
|
-
*/
|
|
121
|
-
class SchemaOrgValidation {
|
|
122
|
-
/**
|
|
123
|
-
* Validate if the property is valid geo-coordinates.
|
|
124
|
-
* @param propertyName The name of the property being validated.
|
|
125
|
-
* @param value The value to test.
|
|
126
|
-
* @param failures The list of failures to add to.
|
|
127
|
-
* @returns True if the value is geo-coordinates.
|
|
128
|
-
*/
|
|
129
|
-
static geoCoordinates(propertyName, value, failures) {
|
|
130
|
-
const is = Validation.object(propertyName, value, failures);
|
|
131
|
-
if (is) {
|
|
132
|
-
// This is only a partial validation at the moment we should also support
|
|
133
|
-
// address, addressCountry, elevation, postalCode as alternative
|
|
134
|
-
// to gps coords
|
|
135
|
-
let lat;
|
|
136
|
-
if (Is.number(value.latitude)) {
|
|
137
|
-
lat = value.latitude;
|
|
138
|
-
}
|
|
139
|
-
else if (Is.stringValue(value.latitude)) {
|
|
140
|
-
lat = Coerce.number(value.latitude);
|
|
141
|
-
}
|
|
142
|
-
if (Is.number(lat)) {
|
|
143
|
-
if (lat < -90 || lat > 90) {
|
|
144
|
-
failures.push({
|
|
145
|
-
property: propertyName + ".latitude",
|
|
146
|
-
reason: "validation.geo.coordinatesLatitudeRange"
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
failures.push({
|
|
152
|
-
property: propertyName + ".latitude",
|
|
153
|
-
reason: "validation.geo.coordinatesLatitudeNumber"
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
let lng;
|
|
157
|
-
if (Is.number(value.longitude)) {
|
|
158
|
-
lng = value.longitude;
|
|
159
|
-
}
|
|
160
|
-
else if (Is.stringValue(value.longitude)) {
|
|
161
|
-
lng = Coerce.number(value.longitude);
|
|
162
|
-
}
|
|
163
|
-
if (Is.number(lng)) {
|
|
164
|
-
if (lng < -180 || lng > 180) {
|
|
165
|
-
failures.push({
|
|
166
|
-
property: propertyName + ".longitude",
|
|
167
|
-
reason: "validation.geo.coordinatesLongitudeRange"
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
failures.push({
|
|
173
|
-
property: propertyName + ".longitude",
|
|
174
|
-
reason: "validation.geo.coordinatesLongitudeNumber"
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return is;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
1
|
// Copyright 2024 IOTA Stiftung.
|
|
183
2
|
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { Url, Validation } from "@twin.org/core";
|
|
4
|
+
import { DataTypeHandlerFactory } from "@twin.org/data-core";
|
|
5
|
+
import { JsonLdProcessor } from "@twin.org/data-json-ld";
|
|
6
|
+
import { SchemaOrgContexts } from "../models/schemaOrgContexts.js";
|
|
7
|
+
import { SchemaOrgTypes } from "../models/schemaOrgTypes.js";
|
|
8
|
+
import GeoCoordinatesSchema from "../schemas/GeoCoordinates.json" with { type: "json" };
|
|
9
|
+
import { SchemaOrgValidation } from "../utils/schemaOrgValidation.js";
|
|
184
10
|
/**
|
|
185
11
|
* Handle all the data types for schema.org.
|
|
186
12
|
*/
|
|
187
|
-
class SchemaOrgDataTypes {
|
|
13
|
+
export class SchemaOrgDataTypes {
|
|
188
14
|
/**
|
|
189
15
|
* Register the JSON-LD Redirects.
|
|
190
16
|
*/
|
|
@@ -290,5 +116,4 @@ class SchemaOrgDataTypes {
|
|
|
290
116
|
}));
|
|
291
117
|
}
|
|
292
118
|
}
|
|
293
|
-
|
|
294
|
-
export { SchemaOrgContexts, SchemaOrgDataTypes, SchemaOrgTypes, SchemaOrgValidation };
|
|
119
|
+
//# sourceMappingURL=schemaOrgDataTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaOrgDataTypes.js","sourceRoot":"","sources":["../../../src/dataTypes/schemaOrgDataTypes.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,sBAAsB,EAAoB,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,oBAAoB,MAAM,gCAAgC,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AACxF,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAEtE;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAC9B;;OAEG;IACI,MAAM,CAAC,iB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IAAI,EAAE,CAAC,oBAAmC;YAC3D,QAAQ,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,CAC5D,mBAAmB,CAAC,cAAc,CAAC,YAAY,EAAE,KAAK,EAAE,QAAQ,CAAC;SAClE,CAAC,CACF,CAAC;IACH,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Url, Validation } from \"@twin.org/core\";\nimport { DataTypeHandlerFactory, type IJsonSchema } from \"@twin.org/data-core\";\nimport { JsonLdProcessor } from \"@twin.org/data-json-ld\";\nimport { SchemaOrgContexts } from \"../models/schemaOrgContexts.js\";\nimport { SchemaOrgTypes } from \"../models/schemaOrgTypes.js\";\nimport GeoCoordinatesSchema from \"../schemas/GeoCoordinates.json\" with { type: \"json\" };\nimport { SchemaOrgValidation } from \"../utils/schemaOrgValidation.js\";\n\n/**\n * Handle all the data types for schema.org.\n */\nexport class SchemaOrgDataTypes {\n\t/**\n\t * Register the JSON-LD Redirects.\n\t */\n\tpublic static registerRedirects(): void {\n\t\tJsonLdProcessor.addRedirect(/https?:\\/\\/schema.org\\/?/, SchemaOrgContexts.ContextRedirect);\n\t}\n\n\t/**\n\t * Register all the data types.\n\t */\n\tpublic static registerTypes(): void {\n\t\tDataTypeHandlerFactory.register(\n\t\t\t`${SchemaOrgContexts.ContextRoot}${SchemaOrgTypes.Text}`,\n\t\t\t() => ({\n\t\t\t\tcontext: SchemaOrgContexts.ContextRoot,\n\t\t\t\ttype: SchemaOrgTypes.Text,\n\t\t\t\tdefaultValue: \"\",\n\t\t\t\tjsonSchema: async () => ({\n\t\t\t\t\ttype: \"string\"\n\t\t\t\t}),\n\t\t\t\tvalidate: async (propertyName, value, failures, container) =>\n\t\t\t\t\tValidation.string(propertyName, value, failures)\n\t\t\t})\n\t\t);\n\n\t\tDataTypeHandlerFactory.register(\n\t\t\t`${SchemaOrgContexts.ContextRoot}${SchemaOrgTypes.Integer}`,\n\t\t\t() => ({\n\t\t\t\tcontext: SchemaOrgContexts.ContextRoot,\n\t\t\t\ttype: SchemaOrgTypes.Integer,\n\t\t\t\tdefaultValue: 0,\n\t\t\t\tjsonSchema: async () => ({\n\t\t\t\t\ttype: \"integer\"\n\t\t\t\t}),\n\t\t\t\tvalidate: async (propertyName, value, failures, container) =>\n\t\t\t\t\tValidation.integer(propertyName, value, failures)\n\t\t\t})\n\t\t);\n\n\t\tDataTypeHandlerFactory.register(\n\t\t\t`${SchemaOrgContexts.ContextRoot}${SchemaOrgTypes.Float}`,\n\t\t\t() => ({\n\t\t\t\tcontext: SchemaOrgContexts.ContextRoot,\n\t\t\t\ttype: SchemaOrgTypes.Float,\n\t\t\t\tdefaultValue: 0,\n\t\t\t\tjsonSchema: async () => ({\n\t\t\t\t\ttype: \"number\"\n\t\t\t\t}),\n\t\t\t\tvalidate: async (propertyName, value, failures, container) =>\n\t\t\t\t\tValidation.number(propertyName, value, failures)\n\t\t\t})\n\t\t);\n\n\t\tDataTypeHandlerFactory.register(\n\t\t\t`${SchemaOrgContexts.ContextRoot}${SchemaOrgTypes.Boolean}`,\n\t\t\t() => ({\n\t\t\t\tcontext: SchemaOrgContexts.ContextRoot,\n\t\t\t\ttype: SchemaOrgTypes.Boolean,\n\t\t\t\tdefaultValue: true,\n\t\t\t\tjsonSchema: async () => ({\n\t\t\t\t\ttype: \"boolean\"\n\t\t\t\t}),\n\t\t\t\tvalidate: async (propertyName, value, failures, container) =>\n\t\t\t\t\tValidation.boolean(propertyName, value, failures)\n\t\t\t})\n\t\t);\n\n\t\tDataTypeHandlerFactory.register(\n\t\t\t`${SchemaOrgContexts.ContextRoot}${SchemaOrgTypes.URL}`,\n\t\t\t() => ({\n\t\t\t\tcontext: SchemaOrgContexts.ContextRoot,\n\t\t\t\ttype: SchemaOrgTypes.URL,\n\t\t\t\tdefaultValue: \"\",\n\t\t\t\tjsonSchema: async () => ({\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tformat: \"uri\"\n\t\t\t\t}),\n\t\t\t\tvalidate: async (propertyName, value, failures, container) =>\n\t\t\t\t\tUrl.validate(propertyName, value, failures)\n\t\t\t})\n\t\t);\n\n\t\tDataTypeHandlerFactory.register(\n\t\t\t`${SchemaOrgContexts.ContextRoot}${SchemaOrgTypes.Date}`,\n\t\t\t() => ({\n\t\t\t\tcontext: SchemaOrgContexts.ContextRoot,\n\t\t\t\ttype: SchemaOrgTypes.Date,\n\t\t\t\tdefaultValue: new Date(),\n\t\t\t\tjsonSchema: async () => ({\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tformat: \"date\"\n\t\t\t\t}),\n\t\t\t\tvalidate: async (propertyName, value, failures, container) =>\n\t\t\t\t\tValidation.dateString(propertyName, value, failures)\n\t\t\t})\n\t\t);\n\n\t\tDataTypeHandlerFactory.register(\n\t\t\t`${SchemaOrgContexts.ContextRoot}${SchemaOrgTypes.DateTime}`,\n\t\t\t() => ({\n\t\t\t\tcontext: SchemaOrgContexts.ContextRoot,\n\t\t\t\ttype: SchemaOrgTypes.DateTime,\n\t\t\t\tdefaultValue: new Date(),\n\t\t\t\tjsonSchema: async () => ({\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tformat: \"date-time\"\n\t\t\t\t}),\n\t\t\t\tvalidate: async (propertyName, value, failures, container) =>\n\t\t\t\t\tValidation.dateTimeString(propertyName, value, failures)\n\t\t\t})\n\t\t);\n\n\t\tDataTypeHandlerFactory.register(\n\t\t\t`${SchemaOrgContexts.ContextRoot}${SchemaOrgTypes.Time}`,\n\t\t\t() => ({\n\t\t\t\tcontext: SchemaOrgContexts.ContextRoot,\n\t\t\t\ttype: SchemaOrgTypes.Time,\n\t\t\t\tdefaultValue: new Date(),\n\t\t\t\tjsonSchema: async () => ({\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tformat: \"time\"\n\t\t\t\t}),\n\t\t\t\tvalidate: async (propertyName, value, failures, container) =>\n\t\t\t\t\tValidation.timeString(propertyName, value, failures)\n\t\t\t})\n\t\t);\n\n\t\tDataTypeHandlerFactory.register(\n\t\t\t`${SchemaOrgContexts.ContextRoot}${SchemaOrgTypes.Image}`,\n\t\t\t() => ({\n\t\t\t\tcontext: SchemaOrgContexts.ContextRoot,\n\t\t\t\ttype: SchemaOrgTypes.Image,\n\t\t\t\tdefaultValue: \"\",\n\t\t\t\tjsonSchema: async () => ({\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tformat: \"uri\"\n\t\t\t\t}),\n\t\t\t\tvalidate: async (propertyName, value, failures, container) =>\n\t\t\t\t\tUrl.validate(propertyName, value, failures)\n\t\t\t})\n\t\t);\n\n\t\tDataTypeHandlerFactory.register(\n\t\t\t`${SchemaOrgContexts.ContextRoot}${SchemaOrgTypes.GeoCoordinates}`,\n\t\t\t() => ({\n\t\t\t\tcontext: SchemaOrgContexts.ContextRoot,\n\t\t\t\ttype: SchemaOrgTypes.GeoCoordinates,\n\t\t\t\tdefaultValue: { longitude: 0, latitude: 0 },\n\t\t\t\tjsonSchema: async () => GeoCoordinatesSchema as IJsonSchema,\n\t\t\t\tvalidate: async (propertyName, value, failures, container) =>\n\t\t\t\t\tSchemaOrgValidation.geoCoordinates(propertyName, value, failures)\n\t\t\t})\n\t\t);\n\t}\n}\n"]}
|
package/dist/es/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
export * from "./dataTypes/schemaOrgDataTypes.js";
|
|
4
|
+
export * from "./models/schemaOrgContexts.js";
|
|
5
|
+
export * from "./models/schemaOrgTypes.js";
|
|
6
|
+
export * from "./utils/schemaOrgValidation.js";
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,mCAAmC,CAAC;AAClD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./dataTypes/schemaOrgDataTypes.js\";\nexport * from \"./models/schemaOrgContexts.js\";\nexport * from \"./models/schemaOrgTypes.js\";\nexport * from \"./utils/schemaOrgValidation.js\";\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
/**
|
|
4
|
+
* The contexts of schema.org data.
|
|
5
|
+
*/
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7
|
+
export const SchemaOrgContexts = {
|
|
8
|
+
/**
|
|
9
|
+
* Context Root.
|
|
10
|
+
*/
|
|
11
|
+
ContextRoot: "https://schema.org",
|
|
12
|
+
/**
|
|
13
|
+
* The redirect for the JSON-LD definition.
|
|
14
|
+
*/
|
|
15
|
+
ContextRedirect: "https://schema.org/docs/jsonldcontext.json"
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=schemaOrgContexts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaOrgContexts.js","sourceRoot":"","sources":["../../../src/models/schemaOrgContexts.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AAEvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAChC;;OAEG;IACH,WAAW,EAAE,oBAAoB;IAEjC;;OAEG;IACH,eAAe,EAAE,4CAA4C;CACpD,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * The contexts of schema.org data.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const SchemaOrgContexts = {\n\t/**\n\t * Context Root.\n\t */\n\tContextRoot: \"https://schema.org\",\n\n\t/**\n\t * The redirect for the JSON-LD definition.\n\t */\n\tContextRedirect: \"https://schema.org/docs/jsonldcontext.json\"\n} as const;\n\n/**\n * The contexts of schema.org data.\n */\nexport type SchemaOrgContexts = (typeof SchemaOrgContexts)[keyof typeof SchemaOrgContexts];\n"]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
/**
|
|
4
|
+
* The types of schema.org data.
|
|
5
|
+
*/
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7
|
+
export const SchemaOrgTypes = {
|
|
8
|
+
/**
|
|
9
|
+
* Represents text storage.
|
|
10
|
+
*/
|
|
11
|
+
Text: "Text",
|
|
12
|
+
/**
|
|
13
|
+
* Represents integer number values.
|
|
14
|
+
*/
|
|
15
|
+
Integer: "Integer",
|
|
16
|
+
/**
|
|
17
|
+
* Represents floating point numbers.
|
|
18
|
+
*/
|
|
19
|
+
Float: "Float",
|
|
20
|
+
/**
|
|
21
|
+
* Represents a boolean.
|
|
22
|
+
*/
|
|
23
|
+
Boolean: "Boolean",
|
|
24
|
+
/**
|
|
25
|
+
* Represents a url.
|
|
26
|
+
*/
|
|
27
|
+
URL: "URL",
|
|
28
|
+
/**
|
|
29
|
+
* Represents a date as an ISO format string.
|
|
30
|
+
*/
|
|
31
|
+
Date: "Date",
|
|
32
|
+
/**
|
|
33
|
+
* Represents a date time as an ISO format string.
|
|
34
|
+
*/
|
|
35
|
+
DateTime: "DateTime",
|
|
36
|
+
/**
|
|
37
|
+
* Represents a time as an ISO format string.
|
|
38
|
+
*/
|
|
39
|
+
Time: "Time",
|
|
40
|
+
/**
|
|
41
|
+
* Represents a url which points to an image.
|
|
42
|
+
*/
|
|
43
|
+
Image: "image",
|
|
44
|
+
/**
|
|
45
|
+
* Represents a location.
|
|
46
|
+
*/
|
|
47
|
+
GeoCoordinates: "GeoCoordinates",
|
|
48
|
+
/**
|
|
49
|
+
* Represents a structured value.
|
|
50
|
+
*/
|
|
51
|
+
StructuredValue: "StructuredValue",
|
|
52
|
+
/**
|
|
53
|
+
* Represents an item list.
|
|
54
|
+
*/
|
|
55
|
+
ItemList: "ItemList",
|
|
56
|
+
/**
|
|
57
|
+
* Represents an item list element.
|
|
58
|
+
*/
|
|
59
|
+
ItemListElement: "itemListElement",
|
|
60
|
+
/**
|
|
61
|
+
* Represents a next item (can be used as a cursor).
|
|
62
|
+
*/
|
|
63
|
+
NextItem: "nextItem"
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=schemaOrgTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaOrgTypes.js","sourceRoot":"","sources":["../../../src/models/schemaOrgTypes.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AAEvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,cAAc,GAAG;IAC7B;;OAEG;IACH,IAAI,EAAE,MAAM;IAEZ;;OAEG;IACH,OAAO,EAAE,SAAS;IAElB;;OAEG;IACH,KAAK,EAAE,OAAO;IAEd;;OAEG;IACH,OAAO,EAAE,SAAS;IAElB;;OAEG;IACH,GAAG,EAAE,KAAK;IAEV;;OAEG;IACH,IAAI,EAAE,MAAM;IAEZ;;OAEG;IACH,QAAQ,EAAE,UAAU;IAEpB;;OAEG;IACH,IAAI,EAAE,MAAM;IAEZ;;OAEG;IACH,KAAK,EAAE,OAAO;IAEd;;OAEG;IACH,cAAc,EAAE,gBAAgB;IAEhC;;OAEG;IACH,eAAe,EAAE,iBAAiB;IAElC;;OAEG;IACH,QAAQ,EAAE,UAAU;IAEpB;;OAEG;IACH,eAAe,EAAE,iBAAiB;IAElC;;OAEG;IACH,QAAQ,EAAE,UAAU;CACX,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * The types of schema.org data.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const SchemaOrgTypes = {\n\t/**\n\t * Represents text storage.\n\t */\n\tText: \"Text\",\n\n\t/**\n\t * Represents integer number values.\n\t */\n\tInteger: \"Integer\",\n\n\t/**\n\t * Represents floating point numbers.\n\t */\n\tFloat: \"Float\",\n\n\t/**\n\t * Represents a boolean.\n\t */\n\tBoolean: \"Boolean\",\n\n\t/**\n\t * Represents a url.\n\t */\n\tURL: \"URL\",\n\n\t/**\n\t * Represents a date as an ISO format string.\n\t */\n\tDate: \"Date\",\n\n\t/**\n\t * Represents a date time as an ISO format string.\n\t */\n\tDateTime: \"DateTime\",\n\n\t/**\n\t * Represents a time as an ISO format string.\n\t */\n\tTime: \"Time\",\n\n\t/**\n\t * Represents a url which points to an image.\n\t */\n\tImage: \"image\",\n\n\t/**\n\t * Represents a location.\n\t */\n\tGeoCoordinates: \"GeoCoordinates\",\n\n\t/**\n\t * Represents a structured value.\n\t */\n\tStructuredValue: \"StructuredValue\",\n\n\t/**\n\t * Represents an item list.\n\t */\n\tItemList: \"ItemList\",\n\n\t/**\n\t * Represents an item list element.\n\t */\n\tItemListElement: \"itemListElement\",\n\n\t/**\n\t * Represents a next item (can be used as a cursor).\n\t */\n\tNextItem: \"nextItem\"\n} as const;\n\n/**\n * The types of schema.org data.\n */\nexport type SchemaOrgTypes = (typeof SchemaOrgTypes)[keyof typeof SchemaOrgTypes];\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "object",
|
|
3
|
+
"required": ["latitude", "longitude"],
|
|
4
|
+
"properties": {
|
|
5
|
+
"latitude": {
|
|
6
|
+
"type": ["number", "string"],
|
|
7
|
+
"minimum": -90,
|
|
8
|
+
"maximum": 90
|
|
9
|
+
},
|
|
10
|
+
"longitude": {
|
|
11
|
+
"type": ["number", "string"],
|
|
12
|
+
"minimum": -180,
|
|
13
|
+
"maximum": 180
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { Coerce, Is, Validation } from "@twin.org/core";
|
|
4
|
+
/**
|
|
5
|
+
* Handle validation for schema.org.
|
|
6
|
+
*/
|
|
7
|
+
export class SchemaOrgValidation {
|
|
8
|
+
/**
|
|
9
|
+
* Validate if the property is valid geo-coordinates.
|
|
10
|
+
* @param propertyName The name of the property being validated.
|
|
11
|
+
* @param value The value to test.
|
|
12
|
+
* @param failures The list of failures to add to.
|
|
13
|
+
* @returns True if the value is geo-coordinates.
|
|
14
|
+
*/
|
|
15
|
+
static geoCoordinates(propertyName, value, failures) {
|
|
16
|
+
const is = Validation.object(propertyName, value, failures);
|
|
17
|
+
if (is) {
|
|
18
|
+
// This is only a partial validation at the moment we should also support
|
|
19
|
+
// address, addressCountry, elevation, postalCode as alternative
|
|
20
|
+
// to gps coords
|
|
21
|
+
let lat;
|
|
22
|
+
if (Is.number(value.latitude)) {
|
|
23
|
+
lat = value.latitude;
|
|
24
|
+
}
|
|
25
|
+
else if (Is.stringValue(value.latitude)) {
|
|
26
|
+
lat = Coerce.number(value.latitude);
|
|
27
|
+
}
|
|
28
|
+
if (Is.number(lat)) {
|
|
29
|
+
if (lat < -90 || lat > 90) {
|
|
30
|
+
failures.push({
|
|
31
|
+
property: propertyName + ".latitude",
|
|
32
|
+
reason: "validation.geo.coordinatesLatitudeRange"
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
failures.push({
|
|
38
|
+
property: propertyName + ".latitude",
|
|
39
|
+
reason: "validation.geo.coordinatesLatitudeNumber"
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
let lng;
|
|
43
|
+
if (Is.number(value.longitude)) {
|
|
44
|
+
lng = value.longitude;
|
|
45
|
+
}
|
|
46
|
+
else if (Is.stringValue(value.longitude)) {
|
|
47
|
+
lng = Coerce.number(value.longitude);
|
|
48
|
+
}
|
|
49
|
+
if (Is.number(lng)) {
|
|
50
|
+
if (lng < -180 || lng > 180) {
|
|
51
|
+
failures.push({
|
|
52
|
+
property: propertyName + ".longitude",
|
|
53
|
+
reason: "validation.geo.coordinatesLongitudeRange"
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
failures.push({
|
|
59
|
+
property: propertyName + ".longitude",
|
|
60
|
+
reason: "validation.geo.coordinatesLongitudeNumber"
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return is;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=schemaOrgValidation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaOrgValidation.js","sourceRoot":"","sources":["../../../src/utils/schemaOrgValidation.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAA2B,MAAM,gBAAgB,CAAC;AAIjF;;GAEG;AACH,MAAM,OAAO,mBAAmB;IAC/B;;;;;;OAMG;IACI,MAAM,CAAC,cAAc,CAC3B,YAAoB,EACpB,KAAc,EACd,QAA8B;QAE9B,MAAM,EAAE,GAAG,UAAU,CAAC,MAAM,CAAiB,YAAY,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;QAE5E,IAAI,EAAE,EAAE,CAAC;YACR,yEAAyE;YACzE,gEAAgE;YAChE,gBAAgB;YAChB,IAAI,GAAuB,CAAC;YAC5B,IAAI,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC/B,GAAG,GAAG,KAAK,CAAC,QAAQ,CAAC;YACtB,CAAC;iBAAM,IAAI,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,QA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X,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Coerce, Is, Validation, type IValidationFailure } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { GeoCoordinates } from \"schema-dts\";\n\n/**\n * Handle validation for schema.org.\n */\nexport class SchemaOrgValidation {\n\t/**\n\t * Validate if the property is valid geo-coordinates.\n\t * @param propertyName The name of the property being validated.\n\t * @param value The value to test.\n\t * @param failures The list of failures to add to.\n\t * @returns True if the value is geo-coordinates.\n\t */\n\tpublic static geoCoordinates(\n\t\tpropertyName: string,\n\t\tvalue: unknown,\n\t\tfailures: IValidationFailure[]\n\t): value is GeoCoordinates {\n\t\tconst is = Validation.object<GeoCoordinates>(propertyName, value, failures);\n\n\t\tif (is) {\n\t\t\t// This is only a partial validation at the moment we should also support\n\t\t\t// address, addressCountry, elevation, postalCode as alternative\n\t\t\t// to gps coords\n\t\t\tlet lat: number | undefined;\n\t\t\tif (Is.number(value.latitude)) {\n\t\t\t\tlat = value.latitude;\n\t\t\t} else if (Is.stringValue(value.latitude)) {\n\t\t\t\tlat = Coerce.number(value.latitude);\n\t\t\t}\n\n\t\t\tif (Is.number(lat)) {\n\t\t\t\tif (lat < -90 || lat > 90) {\n\t\t\t\t\tfailures.push({\n\t\t\t\t\t\tproperty: nameof(value.latitude, propertyName),\n\t\t\t\t\t\treason: \"validation.geo.coordinatesLatitudeRange\"\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfailures.push({\n\t\t\t\t\tproperty: nameof(value.latitude, propertyName),\n\t\t\t\t\treason: \"validation.geo.coordinatesLatitudeNumber\"\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tlet lng: number | undefined;\n\t\t\tif (Is.number(value.longitude)) {\n\t\t\t\tlng = value.longitude;\n\t\t\t} else if (Is.stringValue(value.longitude)) {\n\t\t\t\tlng = Coerce.number(value.longitude);\n\t\t\t}\n\n\t\t\tif (Is.number(lng)) {\n\t\t\t\tif (lng < -180 || lng > 180) {\n\t\t\t\t\tfailures.push({\n\t\t\t\t\t\tproperty: nameof(value.longitude, propertyName),\n\t\t\t\t\t\treason: \"validation.geo.coordinatesLongitudeRange\"\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfailures.push({\n\t\t\t\t\tproperty: nameof(value.longitude, propertyName),\n\t\t\t\t\treason: \"validation.geo.coordinatesLongitudeNumber\"\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn is;\n\t}\n}\n"]}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from "./dataTypes/schemaOrgDataTypes";
|
|
2
|
-
export * from "./models/schemaOrgContexts";
|
|
3
|
-
export * from "./models/schemaOrgTypes";
|
|
4
|
-
export * from "./utils/schemaOrgValidation";
|
|
1
|
+
export * from "./dataTypes/schemaOrgDataTypes.js";
|
|
2
|
+
export * from "./models/schemaOrgContexts.js";
|
|
3
|
+
export * from "./models/schemaOrgTypes.js";
|
|
4
|
+
export * from "./utils/schemaOrgValidation.js";
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,71 @@
|
|
|
1
1
|
# @twin.org/standards-schema-org - Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.3-next.1](https://github.com/twinfoundation/standards/compare/standards-schema-org-v0.0.3-next.0...standards-schema-org-v0.0.3-next.1) (2025-11-10)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add context id features ([#64](https://github.com/twinfoundation/standards/issues/64)) ([e68bb87](https://github.com/twinfoundation/standards/commit/e68bb87a215f3c3956cfd6400a5e1e2a16256085))
|
|
9
|
+
* add ItemList, ItemListElement and NextItem types ([19d7baf](https://github.com/twinfoundation/standards/commit/19d7baf31a3e6385c68051da75835d917d134deb))
|
|
10
|
+
* add ItemList, ItemListElement and NextItem types ([fb40e25](https://github.com/twinfoundation/standards/commit/fb40e25bd3552760452cc31d654d3f0596482ae9))
|
|
11
|
+
* add validate-locales ([838389c](https://github.com/twinfoundation/standards/commit/838389c1daf62ed42397d5758d267c3d1a37fa4d))
|
|
12
|
+
* data types registered with full qualified names ([d64bd08](https://github.com/twinfoundation/standards/commit/d64bd082084172da543e9bfaffb78cdc34e6641d))
|
|
13
|
+
* eslint migration to flat config ([648c1a1](https://github.com/twinfoundation/standards/commit/648c1a1e69d99b6b0cf69358ec6bdeecdbe3a5ea))
|
|
14
|
+
* normalise type outputs ([0b3aed7](https://github.com/twinfoundation/standards/commit/0b3aed7df0802cd609423bbd7fda6bde601d3ceb))
|
|
15
|
+
* unused dependencies ([f8bc5bf](https://github.com/twinfoundation/standards/commit/f8bc5bfbccdc6036cbac9a3b3ff91e3de90c8a9b))
|
|
16
|
+
* update framework core ([58c0c3d](https://github.com/twinfoundation/standards/commit/58c0c3dd6cea0e4c2393dc0e3e1eb33a6d06f617))
|
|
17
|
+
* update to latest JSON schema spec ([7a23930](https://github.com/twinfoundation/standards/commit/7a2393032d7f48bfb20d3a484f981fb6dd83a92c))
|
|
18
|
+
* use shared store mechanism ([#11](https://github.com/twinfoundation/standards/issues/11)) ([96fa237](https://github.com/twinfoundation/standards/commit/96fa23735f69c1fc7e3d0019b527634fa0a042d9))
|
|
19
|
+
|
|
20
|
+
## [0.0.2-next.16](https://github.com/twinfoundation/standards/compare/standards-schema-org-v0.0.2-next.15...standards-schema-org-v0.0.2-next.16) (2025-10-09)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Miscellaneous Chores
|
|
24
|
+
|
|
25
|
+
* **standards-schema-org:** Synchronize repo versions
|
|
26
|
+
|
|
27
|
+
## [0.0.2-next.15](https://github.com/twinfoundation/standards/compare/standards-schema-org-v0.0.2-next.14...standards-schema-org-v0.0.2-next.15) (2025-10-09)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Features
|
|
31
|
+
|
|
32
|
+
* add validate-locales ([838389c](https://github.com/twinfoundation/standards/commit/838389c1daf62ed42397d5758d267c3d1a37fa4d))
|
|
33
|
+
|
|
34
|
+
## [0.0.2-next.14](https://github.com/twinfoundation/standards/compare/standards-schema-org-v0.0.2-next.13...standards-schema-org-v0.0.2-next.14) (2025-10-02)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
### Miscellaneous Chores
|
|
38
|
+
|
|
39
|
+
* **standards-schema-org:** Synchronize repo versions
|
|
40
|
+
|
|
41
|
+
## [0.0.2-next.13](https://github.com/twinfoundation/standards/compare/standards-schema-org-v0.0.2-next.12...standards-schema-org-v0.0.2-next.13) (2025-09-22)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
### Miscellaneous Chores
|
|
45
|
+
|
|
46
|
+
* **standards-schema-org:** Synchronize repo versions
|
|
47
|
+
|
|
48
|
+
## [0.0.2-next.12](https://github.com/twinfoundation/standards/compare/standards-schema-org-v0.0.2-next.11...standards-schema-org-v0.0.2-next.12) (2025-09-16)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
### Miscellaneous Chores
|
|
52
|
+
|
|
53
|
+
* **standards-schema-org:** Synchronize repo versions
|
|
54
|
+
|
|
55
|
+
## [0.0.2-next.11](https://github.com/twinfoundation/standards/compare/standards-schema-org-v0.0.2-next.10...standards-schema-org-v0.0.2-next.11) (2025-09-16)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
### Miscellaneous Chores
|
|
59
|
+
|
|
60
|
+
* **standards-schema-org:** Synchronize repo versions
|
|
61
|
+
|
|
62
|
+
## [0.0.2-next.10](https://github.com/twinfoundation/standards/compare/standards-schema-org-v0.0.2-next.9...standards-schema-org-v0.0.2-next.10) (2025-09-16)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
### Miscellaneous Chores
|
|
66
|
+
|
|
67
|
+
* **standards-schema-org:** Synchronize repo versions
|
|
68
|
+
|
|
3
69
|
## [0.0.2-next.9](https://github.com/twinfoundation/standards/compare/standards-schema-org-v0.0.2-next.8...standards-schema-org-v0.0.2-next.9) (2025-09-15)
|
|
4
70
|
|
|
5
71
|
|
package/locales/en.json
CHANGED
|
@@ -1,21 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"data-type-names": {
|
|
3
|
-
"https://schema.org/Text": "Text",
|
|
4
|
-
"https://schema.org/URL": "Url",
|
|
5
|
-
"https://schema.org/Integer": "Integer",
|
|
6
|
-
"https://schema.org/Float": "Float",
|
|
7
|
-
"https://schema.org/Boolean": "Boolean",
|
|
8
|
-
"https://schema.org/Date": "ISO Date",
|
|
9
|
-
"https://schema.org/DateTime": "ISO Date Time",
|
|
10
|
-
"https://schema.org/Time": "ISO Time",
|
|
11
|
-
"https://schema.org/image": "Image",
|
|
12
|
-
"https://schema.org/GeoCoordinates": "Geo Coordinates",
|
|
13
|
-
"https://schema.org/StructuredValue": "Structured Value"
|
|
14
|
-
},
|
|
15
2
|
"error": {
|
|
16
3
|
"validation": {
|
|
17
4
|
"geo": {
|
|
18
|
-
"coordinatesNotObject": "The geo coordinates must be an object",
|
|
19
5
|
"coordinatesLatitudeNumber": "The latitude value must be a number",
|
|
20
6
|
"coordinatesLatitudeRange": "The latitude value must be between -90 and 90",
|
|
21
7
|
"coordinatesLongitudeNumber": "The longitude value must be a number",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/standards-schema-org",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3-next.1",
|
|
4
4
|
"description": "Models which define the structure of schema.org Standard",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,22 +21,37 @@
|
|
|
21
21
|
"@twin.org/nameof": "next",
|
|
22
22
|
"schema-dts": "1.1.5"
|
|
23
23
|
},
|
|
24
|
-
"main": "./dist/
|
|
25
|
-
"module": "./dist/esm/index.mjs",
|
|
24
|
+
"main": "./dist/es/index.js",
|
|
26
25
|
"types": "./dist/types/index.d.ts",
|
|
27
26
|
"exports": {
|
|
28
27
|
".": {
|
|
29
28
|
"types": "./dist/types/index.d.ts",
|
|
30
|
-
"
|
|
31
|
-
"
|
|
29
|
+
"import": "./dist/es/index.js",
|
|
30
|
+
"default": "./dist/es/index.js"
|
|
32
31
|
},
|
|
33
32
|
"./locales/*.json": "./locales/*.json"
|
|
34
33
|
},
|
|
35
34
|
"files": [
|
|
36
|
-
"dist/
|
|
37
|
-
"dist/esm",
|
|
35
|
+
"dist/es",
|
|
38
36
|
"dist/types",
|
|
39
37
|
"locales",
|
|
40
38
|
"docs"
|
|
41
|
-
]
|
|
39
|
+
],
|
|
40
|
+
"keywords": [
|
|
41
|
+
"twin",
|
|
42
|
+
"trade",
|
|
43
|
+
"iota",
|
|
44
|
+
"framework",
|
|
45
|
+
"blockchain",
|
|
46
|
+
"standards",
|
|
47
|
+
"schema",
|
|
48
|
+
"specification",
|
|
49
|
+
"schema.org",
|
|
50
|
+
"linked-data",
|
|
51
|
+
"seo"
|
|
52
|
+
],
|
|
53
|
+
"bugs": {
|
|
54
|
+
"url": "git+https://github.com/twinfoundation/standards/issues"
|
|
55
|
+
},
|
|
56
|
+
"homepage": "https://twindev.org"
|
|
42
57
|
}
|
package/dist/cjs/index.cjs
DELETED
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var core = require('@twin.org/core');
|
|
4
|
-
var dataCore = require('@twin.org/data-core');
|
|
5
|
-
var dataJsonLd = require('@twin.org/data-json-ld');
|
|
6
|
-
|
|
7
|
-
// Copyright 2024 IOTA Stiftung.
|
|
8
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
9
|
-
/**
|
|
10
|
-
* The contexts of schema.org data.
|
|
11
|
-
*/
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
13
|
-
const SchemaOrgContexts = {
|
|
14
|
-
/**
|
|
15
|
-
* Context Root.
|
|
16
|
-
*/
|
|
17
|
-
ContextRoot: "https://schema.org",
|
|
18
|
-
/**
|
|
19
|
-
* The redirect for the JSON-LD definition.
|
|
20
|
-
*/
|
|
21
|
-
ContextRedirect: "https://schema.org/docs/jsonldcontext.json"
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
// Copyright 2024 IOTA Stiftung.
|
|
25
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
26
|
-
/**
|
|
27
|
-
* The types of schema.org data.
|
|
28
|
-
*/
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
30
|
-
const SchemaOrgTypes = {
|
|
31
|
-
/**
|
|
32
|
-
* Represents text storage.
|
|
33
|
-
*/
|
|
34
|
-
Text: "Text",
|
|
35
|
-
/**
|
|
36
|
-
* Represents integer number values.
|
|
37
|
-
*/
|
|
38
|
-
Integer: "Integer",
|
|
39
|
-
/**
|
|
40
|
-
* Represents floating point numbers.
|
|
41
|
-
*/
|
|
42
|
-
Float: "Float",
|
|
43
|
-
/**
|
|
44
|
-
* Represents a boolean.
|
|
45
|
-
*/
|
|
46
|
-
Boolean: "Boolean",
|
|
47
|
-
/**
|
|
48
|
-
* Represents a url.
|
|
49
|
-
*/
|
|
50
|
-
URL: "URL",
|
|
51
|
-
/**
|
|
52
|
-
* Represents a date as an ISO format string.
|
|
53
|
-
*/
|
|
54
|
-
Date: "Date",
|
|
55
|
-
/**
|
|
56
|
-
* Represents a date time as an ISO format string.
|
|
57
|
-
*/
|
|
58
|
-
DateTime: "DateTime",
|
|
59
|
-
/**
|
|
60
|
-
* Represents a time as an ISO format string.
|
|
61
|
-
*/
|
|
62
|
-
Time: "Time",
|
|
63
|
-
/**
|
|
64
|
-
* Represents a url which points to an image.
|
|
65
|
-
*/
|
|
66
|
-
Image: "image",
|
|
67
|
-
/**
|
|
68
|
-
* Represents a location.
|
|
69
|
-
*/
|
|
70
|
-
GeoCoordinates: "GeoCoordinates",
|
|
71
|
-
/**
|
|
72
|
-
* Represents a structured value.
|
|
73
|
-
*/
|
|
74
|
-
StructuredValue: "StructuredValue",
|
|
75
|
-
/**
|
|
76
|
-
* Represents an item list.
|
|
77
|
-
*/
|
|
78
|
-
ItemList: "ItemList",
|
|
79
|
-
/**
|
|
80
|
-
* Represents an item list element.
|
|
81
|
-
*/
|
|
82
|
-
ItemListElement: "itemListElement",
|
|
83
|
-
/**
|
|
84
|
-
* Represents a next item (can be used as a cursor).
|
|
85
|
-
*/
|
|
86
|
-
NextItem: "nextItem"
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
var type = "object";
|
|
90
|
-
var required = [
|
|
91
|
-
"latitude",
|
|
92
|
-
"longitude"
|
|
93
|
-
];
|
|
94
|
-
var properties = {
|
|
95
|
-
latitude: {
|
|
96
|
-
type: [
|
|
97
|
-
"number",
|
|
98
|
-
"string"
|
|
99
|
-
],
|
|
100
|
-
minimum: -90,
|
|
101
|
-
maximum: 90
|
|
102
|
-
},
|
|
103
|
-
longitude: {
|
|
104
|
-
type: [
|
|
105
|
-
"number",
|
|
106
|
-
"string"
|
|
107
|
-
],
|
|
108
|
-
minimum: -180,
|
|
109
|
-
maximum: 180
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
var GeoCoordinatesSchema = {
|
|
113
|
-
type: type,
|
|
114
|
-
required: required,
|
|
115
|
-
properties: properties
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
// Copyright 2024 IOTA Stiftung.
|
|
119
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
120
|
-
/**
|
|
121
|
-
* Handle validation for schema.org.
|
|
122
|
-
*/
|
|
123
|
-
class SchemaOrgValidation {
|
|
124
|
-
/**
|
|
125
|
-
* Validate if the property is valid geo-coordinates.
|
|
126
|
-
* @param propertyName The name of the property being validated.
|
|
127
|
-
* @param value The value to test.
|
|
128
|
-
* @param failures The list of failures to add to.
|
|
129
|
-
* @returns True if the value is geo-coordinates.
|
|
130
|
-
*/
|
|
131
|
-
static geoCoordinates(propertyName, value, failures) {
|
|
132
|
-
const is = core.Validation.object(propertyName, value, failures);
|
|
133
|
-
if (is) {
|
|
134
|
-
// This is only a partial validation at the moment we should also support
|
|
135
|
-
// address, addressCountry, elevation, postalCode as alternative
|
|
136
|
-
// to gps coords
|
|
137
|
-
let lat;
|
|
138
|
-
if (core.Is.number(value.latitude)) {
|
|
139
|
-
lat = value.latitude;
|
|
140
|
-
}
|
|
141
|
-
else if (core.Is.stringValue(value.latitude)) {
|
|
142
|
-
lat = core.Coerce.number(value.latitude);
|
|
143
|
-
}
|
|
144
|
-
if (core.Is.number(lat)) {
|
|
145
|
-
if (lat < -90 || lat > 90) {
|
|
146
|
-
failures.push({
|
|
147
|
-
property: propertyName + ".latitude",
|
|
148
|
-
reason: "validation.geo.coordinatesLatitudeRange"
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
failures.push({
|
|
154
|
-
property: propertyName + ".latitude",
|
|
155
|
-
reason: "validation.geo.coordinatesLatitudeNumber"
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
let lng;
|
|
159
|
-
if (core.Is.number(value.longitude)) {
|
|
160
|
-
lng = value.longitude;
|
|
161
|
-
}
|
|
162
|
-
else if (core.Is.stringValue(value.longitude)) {
|
|
163
|
-
lng = core.Coerce.number(value.longitude);
|
|
164
|
-
}
|
|
165
|
-
if (core.Is.number(lng)) {
|
|
166
|
-
if (lng < -180 || lng > 180) {
|
|
167
|
-
failures.push({
|
|
168
|
-
property: propertyName + ".longitude",
|
|
169
|
-
reason: "validation.geo.coordinatesLongitudeRange"
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
failures.push({
|
|
175
|
-
property: propertyName + ".longitude",
|
|
176
|
-
reason: "validation.geo.coordinatesLongitudeNumber"
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return is;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// Copyright 2024 IOTA Stiftung.
|
|
185
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
186
|
-
/**
|
|
187
|
-
* Handle all the data types for schema.org.
|
|
188
|
-
*/
|
|
189
|
-
class SchemaOrgDataTypes {
|
|
190
|
-
/**
|
|
191
|
-
* Register the JSON-LD Redirects.
|
|
192
|
-
*/
|
|
193
|
-
static registerRedirects() {
|
|
194
|
-
dataJsonLd.JsonLdProcessor.addRedirect(/https?:\/\/schema.org\/?/, SchemaOrgContexts.ContextRedirect);
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Register all the data types.
|
|
198
|
-
*/
|
|
199
|
-
static registerTypes() {
|
|
200
|
-
dataCore.DataTypeHandlerFactory.register(`${SchemaOrgContexts.ContextRoot}${SchemaOrgTypes.Text}`, () => ({
|
|
201
|
-
context: SchemaOrgContexts.ContextRoot,
|
|
202
|
-
type: SchemaOrgTypes.Text,
|
|
203
|
-
defaultValue: "",
|
|
204
|
-
jsonSchema: async () => ({
|
|
205
|
-
type: "string"
|
|
206
|
-
}),
|
|
207
|
-
validate: async (propertyName, value, failures, container) => core.Validation.string(propertyName, value, failures)
|
|
208
|
-
}));
|
|
209
|
-
dataCore.DataTypeHandlerFactory.register(`${SchemaOrgContexts.ContextRoot}${SchemaOrgTypes.Integer}`, () => ({
|
|
210
|
-
context: SchemaOrgContexts.ContextRoot,
|
|
211
|
-
type: SchemaOrgTypes.Integer,
|
|
212
|
-
defaultValue: 0,
|
|
213
|
-
jsonSchema: async () => ({
|
|
214
|
-
type: "integer"
|
|
215
|
-
}),
|
|
216
|
-
validate: async (propertyName, value, failures, container) => core.Validation.integer(propertyName, value, failures)
|
|
217
|
-
}));
|
|
218
|
-
dataCore.DataTypeHandlerFactory.register(`${SchemaOrgContexts.ContextRoot}${SchemaOrgTypes.Float}`, () => ({
|
|
219
|
-
context: SchemaOrgContexts.ContextRoot,
|
|
220
|
-
type: SchemaOrgTypes.Float,
|
|
221
|
-
defaultValue: 0,
|
|
222
|
-
jsonSchema: async () => ({
|
|
223
|
-
type: "number"
|
|
224
|
-
}),
|
|
225
|
-
validate: async (propertyName, value, failures, container) => core.Validation.number(propertyName, value, failures)
|
|
226
|
-
}));
|
|
227
|
-
dataCore.DataTypeHandlerFactory.register(`${SchemaOrgContexts.ContextRoot}${SchemaOrgTypes.Boolean}`, () => ({
|
|
228
|
-
context: SchemaOrgContexts.ContextRoot,
|
|
229
|
-
type: SchemaOrgTypes.Boolean,
|
|
230
|
-
defaultValue: true,
|
|
231
|
-
jsonSchema: async () => ({
|
|
232
|
-
type: "boolean"
|
|
233
|
-
}),
|
|
234
|
-
validate: async (propertyName, value, failures, container) => core.Validation.boolean(propertyName, value, failures)
|
|
235
|
-
}));
|
|
236
|
-
dataCore.DataTypeHandlerFactory.register(`${SchemaOrgContexts.ContextRoot}${SchemaOrgTypes.URL}`, () => ({
|
|
237
|
-
context: SchemaOrgContexts.ContextRoot,
|
|
238
|
-
type: SchemaOrgTypes.URL,
|
|
239
|
-
defaultValue: "",
|
|
240
|
-
jsonSchema: async () => ({
|
|
241
|
-
type: "string",
|
|
242
|
-
format: "uri"
|
|
243
|
-
}),
|
|
244
|
-
validate: async (propertyName, value, failures, container) => core.Url.validate(propertyName, value, failures)
|
|
245
|
-
}));
|
|
246
|
-
dataCore.DataTypeHandlerFactory.register(`${SchemaOrgContexts.ContextRoot}${SchemaOrgTypes.Date}`, () => ({
|
|
247
|
-
context: SchemaOrgContexts.ContextRoot,
|
|
248
|
-
type: SchemaOrgTypes.Date,
|
|
249
|
-
defaultValue: new Date(),
|
|
250
|
-
jsonSchema: async () => ({
|
|
251
|
-
type: "string",
|
|
252
|
-
format: "date"
|
|
253
|
-
}),
|
|
254
|
-
validate: async (propertyName, value, failures, container) => core.Validation.dateString(propertyName, value, failures)
|
|
255
|
-
}));
|
|
256
|
-
dataCore.DataTypeHandlerFactory.register(`${SchemaOrgContexts.ContextRoot}${SchemaOrgTypes.DateTime}`, () => ({
|
|
257
|
-
context: SchemaOrgContexts.ContextRoot,
|
|
258
|
-
type: SchemaOrgTypes.DateTime,
|
|
259
|
-
defaultValue: new Date(),
|
|
260
|
-
jsonSchema: async () => ({
|
|
261
|
-
type: "string",
|
|
262
|
-
format: "date-time"
|
|
263
|
-
}),
|
|
264
|
-
validate: async (propertyName, value, failures, container) => core.Validation.dateTimeString(propertyName, value, failures)
|
|
265
|
-
}));
|
|
266
|
-
dataCore.DataTypeHandlerFactory.register(`${SchemaOrgContexts.ContextRoot}${SchemaOrgTypes.Time}`, () => ({
|
|
267
|
-
context: SchemaOrgContexts.ContextRoot,
|
|
268
|
-
type: SchemaOrgTypes.Time,
|
|
269
|
-
defaultValue: new Date(),
|
|
270
|
-
jsonSchema: async () => ({
|
|
271
|
-
type: "string",
|
|
272
|
-
format: "time"
|
|
273
|
-
}),
|
|
274
|
-
validate: async (propertyName, value, failures, container) => core.Validation.timeString(propertyName, value, failures)
|
|
275
|
-
}));
|
|
276
|
-
dataCore.DataTypeHandlerFactory.register(`${SchemaOrgContexts.ContextRoot}${SchemaOrgTypes.Image}`, () => ({
|
|
277
|
-
context: SchemaOrgContexts.ContextRoot,
|
|
278
|
-
type: SchemaOrgTypes.Image,
|
|
279
|
-
defaultValue: "",
|
|
280
|
-
jsonSchema: async () => ({
|
|
281
|
-
type: "string",
|
|
282
|
-
format: "uri"
|
|
283
|
-
}),
|
|
284
|
-
validate: async (propertyName, value, failures, container) => core.Url.validate(propertyName, value, failures)
|
|
285
|
-
}));
|
|
286
|
-
dataCore.DataTypeHandlerFactory.register(`${SchemaOrgContexts.ContextRoot}${SchemaOrgTypes.GeoCoordinates}`, () => ({
|
|
287
|
-
context: SchemaOrgContexts.ContextRoot,
|
|
288
|
-
type: SchemaOrgTypes.GeoCoordinates,
|
|
289
|
-
defaultValue: { longitude: 0, latitude: 0 },
|
|
290
|
-
jsonSchema: async () => GeoCoordinatesSchema,
|
|
291
|
-
validate: async (propertyName, value, failures, container) => SchemaOrgValidation.geoCoordinates(propertyName, value, failures)
|
|
292
|
-
}));
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
exports.SchemaOrgContexts = SchemaOrgContexts;
|
|
297
|
-
exports.SchemaOrgDataTypes = SchemaOrgDataTypes;
|
|
298
|
-
exports.SchemaOrgTypes = SchemaOrgTypes;
|
|
299
|
-
exports.SchemaOrgValidation = SchemaOrgValidation;
|