@gsriram24/structured-data-validator 1.6.2 → 1.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gsriram24/structured-data-validator",
3
- "version": "1.6.2",
3
+ "version": "1.7.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -189,6 +189,11 @@ export default class SchemaOrgValidator {
189
189
  });
190
190
  }
191
191
 
192
+ async validateType(type) {
193
+ const schema = await this.#loadSchema();
194
+ return !!schema[type];
195
+ }
196
+
192
197
  async validate(data) {
193
198
  const issues = [];
194
199
 
@@ -197,6 +202,22 @@ export default class SchemaOrgValidator {
197
202
  return [];
198
203
  }
199
204
 
205
+ const typeId = this.#stripSchema(this.type);
206
+
207
+ // Check if type exists in schema.org
208
+ const typeExists = await this.validateType(typeId);
209
+ if (!typeExists) {
210
+ issues.push({
211
+ issueMessage: `Type "${typeId}" is not a valid schema.org type`,
212
+ severity: 'WARNING',
213
+ path: this.path,
214
+ errorType: 'schemaOrg',
215
+ fieldName: '@type',
216
+ });
217
+ // Skip property validation since type is invalid
218
+ return issues;
219
+ }
220
+
200
221
  // Get list of properties, any other keys which do not start with @
201
222
  const properties = Object.keys(data).filter(
202
223
  (key) => !key.startsWith('@'),
@@ -206,7 +227,6 @@ export default class SchemaOrgValidator {
206
227
  await Promise.all(
207
228
  properties.map(async (property) => {
208
229
  const propertyId = this.#stripSchema(property);
209
- const typeId = this.#stripSchema(this.type);
210
230
 
211
231
  const isValid = await this.validateProperty(typeId, propertyId);
212
232
  if (!isValid) {
package/src/validator.js CHANGED
@@ -179,14 +179,17 @@ export class Validator {
179
179
 
180
180
  // Find supported handlers (check direct mapping first, then parent types)
181
181
  const handlers = await this.#getHandlersForType(type);
182
- if (!handlers || handlers.length === 0) {
182
+ if (handlers.length === 0) {
183
183
  this.debug &&
184
184
  console.warn(
185
185
  `${spacing} WARN: No handlers registered for type: ${type}`,
186
186
  );
187
- return [];
188
187
  }
188
+ // Always run global handlers (e.g., schemaOrg) even if no type-specific handler exists
189
189
  handlers.push(...(this.globalHandlers || []));
190
+ if (handlers.length === 0) {
191
+ return [];
192
+ }
190
193
 
191
194
  const handlerPromises = handlers.map(async (handler) => {
192
195
  const handlerClass = (await handler()).default;