@willwade/aac-processors 0.0.21 → 0.0.23
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/README.md +19 -27
- package/dist/core/treeStructure.d.ts +2 -2
- package/dist/core/treeStructure.js +4 -1
- package/dist/processors/applePanelsProcessor.js +166 -123
- package/dist/processors/astericsGridProcessor.js +121 -105
- package/dist/processors/dotProcessor.js +83 -65
- package/dist/processors/gridsetProcessor.js +2 -0
- package/dist/processors/obfProcessor.js +11 -4
- package/dist/processors/opmlProcessor.js +82 -44
- package/dist/processors/snapProcessor.js +19 -9
- package/dist/processors/touchchatProcessor.js +72 -21
- package/dist/utilities/analytics/metrics/core.d.ts +1 -1
- package/dist/utilities/analytics/metrics/core.js +191 -212
- package/dist/validation/applePanelsValidator.d.ts +10 -0
- package/dist/validation/applePanelsValidator.js +124 -0
- package/dist/validation/astericsValidator.d.ts +16 -0
- package/dist/validation/astericsValidator.js +115 -0
- package/dist/validation/dotValidator.d.ts +10 -0
- package/dist/validation/dotValidator.js +113 -0
- package/dist/validation/excelValidator.d.ts +10 -0
- package/dist/validation/excelValidator.js +89 -0
- package/dist/validation/index.d.ts +14 -1
- package/dist/validation/index.js +104 -1
- package/dist/validation/obfsetValidator.d.ts +10 -0
- package/dist/validation/obfsetValidator.js +103 -0
- package/dist/validation/opmlValidator.d.ts +10 -0
- package/dist/validation/opmlValidator.js +107 -0
- package/dist/validation/validationTypes.d.ts +22 -0
- package/dist/validation/validationTypes.js +38 -1
- package/dist/validation.d.ts +8 -2
- package/dist/validation.js +16 -1
- package/package.json +1 -1
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.OpmlValidator = void 0;
|
|
27
|
+
/* eslint-disable @typescript-eslint/require-await */
|
|
28
|
+
const fs = __importStar(require("fs"));
|
|
29
|
+
const path = __importStar(require("path"));
|
|
30
|
+
const fast_xml_parser_1 = require("fast-xml-parser");
|
|
31
|
+
const baseValidator_1 = require("./baseValidator");
|
|
32
|
+
/**
|
|
33
|
+
* Validator for OPML files
|
|
34
|
+
*/
|
|
35
|
+
class OpmlValidator extends baseValidator_1.BaseValidator {
|
|
36
|
+
static async validateFile(filePath) {
|
|
37
|
+
const validator = new OpmlValidator();
|
|
38
|
+
const content = fs.readFileSync(filePath);
|
|
39
|
+
const stats = fs.statSync(filePath);
|
|
40
|
+
return validator.validate(content, path.basename(filePath), stats.size);
|
|
41
|
+
}
|
|
42
|
+
static async identifyFormat(content, filename) {
|
|
43
|
+
const name = filename.toLowerCase();
|
|
44
|
+
if (name.endsWith('.opml')) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const str = Buffer.isBuffer(content) ? content.toString('utf-8') : String(content);
|
|
49
|
+
const validation = fast_xml_parser_1.XMLValidator.validate(str);
|
|
50
|
+
if (validation !== true) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
const parser = new fast_xml_parser_1.XMLParser({ ignoreAttributes: false });
|
|
54
|
+
const parsed = parser.parse(str);
|
|
55
|
+
return Boolean(parsed?.opml?.body?.outline);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async validate(content, filename, filesize) {
|
|
62
|
+
this.reset();
|
|
63
|
+
const parser = new fast_xml_parser_1.XMLParser({ ignoreAttributes: false });
|
|
64
|
+
await this.add_check('filename', 'file extension', async () => {
|
|
65
|
+
if (!filename.toLowerCase().endsWith('.opml')) {
|
|
66
|
+
this.warn('filename should end with .opml');
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
let text = '';
|
|
70
|
+
await this.add_check('content', 'non-empty content', async () => {
|
|
71
|
+
text = Buffer.isBuffer(content) ? content.toString('utf-8') : String(content);
|
|
72
|
+
if (!text.trim()) {
|
|
73
|
+
this.err('OPML file is empty', true);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
await this.add_check('xml', 'valid XML', async () => {
|
|
77
|
+
const validation = fast_xml_parser_1.XMLValidator.validate(text);
|
|
78
|
+
if (validation !== true) {
|
|
79
|
+
const msg = String(validation?.err?.msg || 'Invalid OPML XML');
|
|
80
|
+
this.err(msg, true);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
let parsed = null;
|
|
84
|
+
await this.add_check('structure', 'outline structure', async () => {
|
|
85
|
+
parsed = parser.parse(text);
|
|
86
|
+
if (!parsed?.opml?.body?.outline) {
|
|
87
|
+
this.err('missing body.outline', true);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
if (parsed?.opml?.body?.outline) {
|
|
91
|
+
const outlines = Array.isArray(parsed.opml.body.outline)
|
|
92
|
+
? parsed.opml.body.outline
|
|
93
|
+
: [parsed.opml.body.outline];
|
|
94
|
+
await this.add_check('outline_nodes', 'outline nodes', async () => {
|
|
95
|
+
const hasText = outlines.some((node) => {
|
|
96
|
+
const textValue = node?.['@_text'] || node?._attributes?.text || node?.text || node?.['@_title'];
|
|
97
|
+
return typeof textValue === 'string' && textValue.trim().length > 0;
|
|
98
|
+
});
|
|
99
|
+
if (!hasText) {
|
|
100
|
+
this.err('outline nodes missing text attributes');
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return this.buildResult(filename, filesize, 'opml');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.OpmlValidator = OpmlValidator;
|
|
@@ -62,3 +62,25 @@ export interface ValidationRule {
|
|
|
62
62
|
check: (data: any) => Promise<boolean> | boolean;
|
|
63
63
|
errorMessage?: string;
|
|
64
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Error wrapper that carries a structured ValidationResult so callers
|
|
67
|
+
* can surface actionable details instead of generic exceptions.
|
|
68
|
+
*/
|
|
69
|
+
export declare class ValidationFailureError extends Error {
|
|
70
|
+
validationResult: ValidationResult;
|
|
71
|
+
originalError?: unknown;
|
|
72
|
+
constructor(message: string, validationResult: ValidationResult, originalError?: unknown);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Build a minimal ValidationResult for situations where we cannot run
|
|
76
|
+
* the full validator (e.g., early parse failure) but still want
|
|
77
|
+
* structured feedback for the caller.
|
|
78
|
+
*/
|
|
79
|
+
export declare function buildValidationResultFromMessage(params: {
|
|
80
|
+
filename: string;
|
|
81
|
+
filesize: number;
|
|
82
|
+
format: string;
|
|
83
|
+
message: string;
|
|
84
|
+
type?: string;
|
|
85
|
+
description?: string;
|
|
86
|
+
}): ValidationResult;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ValidationError = void 0;
|
|
3
|
+
exports.ValidationFailureError = exports.ValidationError = void 0;
|
|
4
|
+
exports.buildValidationResultFromMessage = buildValidationResultFromMessage;
|
|
4
5
|
/**
|
|
5
6
|
* Custom error class for validation errors
|
|
6
7
|
* Can be marked as a blocker to stop validation immediately
|
|
@@ -13,3 +14,39 @@ class ValidationError extends Error {
|
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
16
|
exports.ValidationError = ValidationError;
|
|
17
|
+
/**
|
|
18
|
+
* Error wrapper that carries a structured ValidationResult so callers
|
|
19
|
+
* can surface actionable details instead of generic exceptions.
|
|
20
|
+
*/
|
|
21
|
+
class ValidationFailureError extends Error {
|
|
22
|
+
constructor(message, validationResult, originalError) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = 'ValidationFailureError';
|
|
25
|
+
this.validationResult = validationResult;
|
|
26
|
+
this.originalError = originalError;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.ValidationFailureError = ValidationFailureError;
|
|
30
|
+
/**
|
|
31
|
+
* Build a minimal ValidationResult for situations where we cannot run
|
|
32
|
+
* the full validator (e.g., early parse failure) but still want
|
|
33
|
+
* structured feedback for the caller.
|
|
34
|
+
*/
|
|
35
|
+
function buildValidationResultFromMessage(params) {
|
|
36
|
+
return {
|
|
37
|
+
filename: params.filename,
|
|
38
|
+
filesize: params.filesize,
|
|
39
|
+
format: params.format,
|
|
40
|
+
valid: false,
|
|
41
|
+
errors: 1,
|
|
42
|
+
warnings: 0,
|
|
43
|
+
results: [
|
|
44
|
+
{
|
|
45
|
+
type: params.type || 'parse',
|
|
46
|
+
description: params.description || 'parse',
|
|
47
|
+
valid: false,
|
|
48
|
+
error: params.message,
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
}
|
package/dist/validation.d.ts
CHANGED
|
@@ -4,10 +4,16 @@
|
|
|
4
4
|
* All validation functionality for AAC processors.
|
|
5
5
|
* Provides consistent validation across all supported formats.
|
|
6
6
|
*/
|
|
7
|
-
export { ValidationError, ValidationCheck, ValidationResult, ValidationOptions, ValidationRule, } from './validation/validationTypes';
|
|
7
|
+
export { ValidationError, ValidationCheck, ValidationResult, ValidationOptions, ValidationRule, ValidationFailureError, buildValidationResultFromMessage, } from './validation/validationTypes';
|
|
8
8
|
export { BaseValidator } from './validation/baseValidator';
|
|
9
9
|
export { ObfValidator } from './validation/obfValidator';
|
|
10
10
|
export { GridsetValidator } from './validation/gridsetValidator';
|
|
11
11
|
export { SnapValidator } from './validation/snapValidator';
|
|
12
12
|
export { TouchChatValidator } from './validation/touchChatValidator';
|
|
13
|
-
export {
|
|
13
|
+
export { AstericsGridValidator } from './validation/astericsValidator';
|
|
14
|
+
export { ExcelValidator } from './validation/excelValidator';
|
|
15
|
+
export { OpmlValidator } from './validation/opmlValidator';
|
|
16
|
+
export { DotValidator } from './validation/dotValidator';
|
|
17
|
+
export { ApplePanelsValidator } from './validation/applePanelsValidator';
|
|
18
|
+
export { ObfsetValidator } from './validation/obfsetValidator';
|
|
19
|
+
export { getValidatorForFormat, getValidatorForFile, validateFileOrBuffer, } from './validation/index';
|
package/dist/validation.js
CHANGED
|
@@ -6,10 +6,12 @@
|
|
|
6
6
|
* Provides consistent validation across all supported formats.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.getValidatorForFile = exports.getValidatorForFormat = exports.TouchChatValidator = exports.SnapValidator = exports.GridsetValidator = exports.ObfValidator = exports.BaseValidator = exports.ValidationError = void 0;
|
|
9
|
+
exports.validateFileOrBuffer = exports.getValidatorForFile = exports.getValidatorForFormat = exports.ObfsetValidator = exports.ApplePanelsValidator = exports.DotValidator = exports.OpmlValidator = exports.ExcelValidator = exports.AstericsGridValidator = exports.TouchChatValidator = exports.SnapValidator = exports.GridsetValidator = exports.ObfValidator = exports.BaseValidator = exports.buildValidationResultFromMessage = exports.ValidationFailureError = exports.ValidationError = void 0;
|
|
10
10
|
// Validation types and interfaces
|
|
11
11
|
var validationTypes_1 = require("./validation/validationTypes");
|
|
12
12
|
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return validationTypes_1.ValidationError; } });
|
|
13
|
+
Object.defineProperty(exports, "ValidationFailureError", { enumerable: true, get: function () { return validationTypes_1.ValidationFailureError; } });
|
|
14
|
+
Object.defineProperty(exports, "buildValidationResultFromMessage", { enumerable: true, get: function () { return validationTypes_1.buildValidationResultFromMessage; } });
|
|
13
15
|
// Base validator
|
|
14
16
|
var baseValidator_1 = require("./validation/baseValidator");
|
|
15
17
|
Object.defineProperty(exports, "BaseValidator", { enumerable: true, get: function () { return baseValidator_1.BaseValidator; } });
|
|
@@ -22,7 +24,20 @@ var snapValidator_1 = require("./validation/snapValidator");
|
|
|
22
24
|
Object.defineProperty(exports, "SnapValidator", { enumerable: true, get: function () { return snapValidator_1.SnapValidator; } });
|
|
23
25
|
var touchChatValidator_1 = require("./validation/touchChatValidator");
|
|
24
26
|
Object.defineProperty(exports, "TouchChatValidator", { enumerable: true, get: function () { return touchChatValidator_1.TouchChatValidator; } });
|
|
27
|
+
var astericsValidator_1 = require("./validation/astericsValidator");
|
|
28
|
+
Object.defineProperty(exports, "AstericsGridValidator", { enumerable: true, get: function () { return astericsValidator_1.AstericsGridValidator; } });
|
|
29
|
+
var excelValidator_1 = require("./validation/excelValidator");
|
|
30
|
+
Object.defineProperty(exports, "ExcelValidator", { enumerable: true, get: function () { return excelValidator_1.ExcelValidator; } });
|
|
31
|
+
var opmlValidator_1 = require("./validation/opmlValidator");
|
|
32
|
+
Object.defineProperty(exports, "OpmlValidator", { enumerable: true, get: function () { return opmlValidator_1.OpmlValidator; } });
|
|
33
|
+
var dotValidator_1 = require("./validation/dotValidator");
|
|
34
|
+
Object.defineProperty(exports, "DotValidator", { enumerable: true, get: function () { return dotValidator_1.DotValidator; } });
|
|
35
|
+
var applePanelsValidator_1 = require("./validation/applePanelsValidator");
|
|
36
|
+
Object.defineProperty(exports, "ApplePanelsValidator", { enumerable: true, get: function () { return applePanelsValidator_1.ApplePanelsValidator; } });
|
|
37
|
+
var obfsetValidator_1 = require("./validation/obfsetValidator");
|
|
38
|
+
Object.defineProperty(exports, "ObfsetValidator", { enumerable: true, get: function () { return obfsetValidator_1.ObfsetValidator; } });
|
|
25
39
|
// Validator factory functions
|
|
26
40
|
var index_1 = require("./validation/index");
|
|
27
41
|
Object.defineProperty(exports, "getValidatorForFormat", { enumerable: true, get: function () { return index_1.getValidatorForFormat; } });
|
|
28
42
|
Object.defineProperty(exports, "getValidatorForFile", { enumerable: true, get: function () { return index_1.getValidatorForFile; } });
|
|
43
|
+
Object.defineProperty(exports, "validateFileOrBuffer", { enumerable: true, get: function () { return index_1.validateFileOrBuffer; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willwade/aac-processors",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23",
|
|
4
4
|
"description": "A comprehensive TypeScript library for processing AAC (Augmentative and Alternative Communication) file formats with translation support",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|