@messagevisor/core 0.0.1 → 0.1.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/CHANGELOG.md +16 -0
- package/LICENSE +21 -0
- package/README.md +7 -0
- package/jest.config.js +8 -0
- package/lib/benchmark/index.d.ts +2 -0
- package/lib/benchmark/index.js +417 -0
- package/lib/benchmark/index.js.map +1 -0
- package/lib/builder/index.d.ts +70 -0
- package/lib/builder/index.js +831 -0
- package/lib/builder/index.js.map +1 -0
- package/lib/cli/index.d.ts +28 -0
- package/lib/cli/index.js +182 -0
- package/lib/cli/index.js.map +1 -0
- package/lib/config/index.d.ts +61 -0
- package/lib/config/index.js +255 -0
- package/lib/config/index.js.map +1 -0
- package/lib/create/index.d.ts +2 -0
- package/lib/create/index.js +405 -0
- package/lib/create/index.js.map +1 -0
- package/lib/datasource/filesystemAdapter.d.ts +44 -0
- package/lib/datasource/filesystemAdapter.js +424 -0
- package/lib/datasource/filesystemAdapter.js.map +1 -0
- package/lib/datasource/index.d.ts +39 -0
- package/lib/datasource/index.js +96 -0
- package/lib/datasource/index.js.map +1 -0
- package/lib/error.d.ts +6 -0
- package/lib/error.js +49 -0
- package/lib/error.js.map +1 -0
- package/lib/evaluate/cli.d.ts +8 -0
- package/lib/evaluate/cli.js +179 -0
- package/lib/evaluate/cli.js.map +1 -0
- package/lib/evaluate/index.d.ts +10 -0
- package/lib/evaluate/index.js +131 -0
- package/lib/evaluate/index.js.map +1 -0
- package/lib/examples/coerceExampleIsoDates.d.ts +12 -0
- package/lib/examples/coerceExampleIsoDates.js +81 -0
- package/lib/examples/coerceExampleIsoDates.js.map +1 -0
- package/lib/examples/index.d.ts +63 -0
- package/lib/examples/index.js +713 -0
- package/lib/examples/index.js.map +1 -0
- package/lib/exporter/index.d.ts +60 -0
- package/lib/exporter/index.js +610 -0
- package/lib/exporter/index.js.map +1 -0
- package/lib/find-duplicates/index.d.ts +41 -0
- package/lib/find-duplicates/index.js +297 -0
- package/lib/find-duplicates/index.js.map +1 -0
- package/lib/generate-code/index.d.ts +11 -0
- package/lib/generate-code/index.js +157 -0
- package/lib/generate-code/index.js.map +1 -0
- package/lib/generate-code/typescript.d.ts +14 -0
- package/lib/generate-code/typescript.js +307 -0
- package/lib/generate-code/typescript.js.map +1 -0
- package/lib/importer/index.d.ts +64 -0
- package/lib/importer/index.js +1092 -0
- package/lib/importer/index.js.map +1 -0
- package/lib/index.d.ts +18 -0
- package/lib/index.js +35 -0
- package/lib/index.js.map +1 -0
- package/lib/info/index.d.ts +17 -0
- package/lib/info/index.js +132 -0
- package/lib/info/index.js.map +1 -0
- package/lib/init/index.d.ts +30 -0
- package/lib/init/index.js +348 -0
- package/lib/init/index.js.map +1 -0
- package/lib/lint/index.d.ts +1 -0
- package/lib/lint/index.js +6 -0
- package/lib/lint/index.js.map +1 -0
- package/lib/linter/attributeSchema.d.ts +7 -0
- package/lib/linter/attributeSchema.js +36 -0
- package/lib/linter/attributeSchema.js.map +1 -0
- package/lib/linter/checkLocaleCircularDependency.d.ts +7 -0
- package/lib/linter/checkLocaleCircularDependency.js +42 -0
- package/lib/linter/checkLocaleCircularDependency.js.map +1 -0
- package/lib/linter/conditionSchema.d.ts +3 -0
- package/lib/linter/conditionSchema.js +283 -0
- package/lib/linter/conditionSchema.js.map +1 -0
- package/lib/linter/formatSchema.d.ts +325 -0
- package/lib/linter/formatSchema.js +165 -0
- package/lib/linter/formatSchema.js.map +1 -0
- package/lib/linter/icuStyleLint.d.ts +6 -0
- package/lib/linter/icuStyleLint.js +226 -0
- package/lib/linter/icuStyleLint.js.map +1 -0
- package/lib/linter/index.d.ts +34 -0
- package/lib/linter/index.js +557 -0
- package/lib/linter/index.js.map +1 -0
- package/lib/linter/localeSchema.d.ts +672 -0
- package/lib/linter/localeSchema.js +50 -0
- package/lib/linter/localeSchema.js.map +1 -0
- package/lib/linter/messageSchema.d.ts +35 -0
- package/lib/linter/messageSchema.js +115 -0
- package/lib/linter/messageSchema.js.map +1 -0
- package/lib/linter/printError.d.ts +8 -0
- package/lib/linter/printError.js +41 -0
- package/lib/linter/printError.js.map +1 -0
- package/lib/linter/schema.d.ts +33 -0
- package/lib/linter/schema.js +192 -0
- package/lib/linter/schema.js.map +1 -0
- package/lib/linter/segmentSchema.d.ts +8 -0
- package/lib/linter/segmentSchema.js +18 -0
- package/lib/linter/segmentSchema.js.map +1 -0
- package/lib/linter/targetSchema.d.ts +337 -0
- package/lib/linter/targetSchema.js +39 -0
- package/lib/linter/targetSchema.js.map +1 -0
- package/lib/linter/testSchema.d.ts +71 -0
- package/lib/linter/testSchema.js +165 -0
- package/lib/linter/testSchema.js.map +1 -0
- package/lib/linter/zodHelpers.d.ts +2 -0
- package/lib/linter/zodHelpers.js +15 -0
- package/lib/linter/zodHelpers.js.map +1 -0
- package/lib/list/index.d.ts +8 -0
- package/lib/list/index.js +524 -0
- package/lib/list/index.js.map +1 -0
- package/lib/matrix.d.ts +4 -0
- package/lib/matrix.js +66 -0
- package/lib/matrix.js.map +1 -0
- package/lib/promoter/index.d.ts +65 -0
- package/lib/promoter/index.js +1208 -0
- package/lib/promoter/index.js.map +1 -0
- package/lib/prune/index.d.ts +37 -0
- package/lib/prune/index.js +673 -0
- package/lib/prune/index.js.map +1 -0
- package/lib/sets.d.ts +10 -0
- package/lib/sets.js +120 -0
- package/lib/sets.js.map +1 -0
- package/lib/tester/cliFormat.d.ts +8 -0
- package/lib/tester/cliFormat.js +15 -0
- package/lib/tester/cliFormat.js.map +1 -0
- package/lib/tester/index.d.ts +35 -0
- package/lib/tester/index.js +713 -0
- package/lib/tester/index.js.map +1 -0
- package/lib/tester/matrix.d.ts +14 -0
- package/lib/tester/matrix.js +76 -0
- package/lib/tester/matrix.js.map +1 -0
- package/lib/tester/prettyDuration.d.ts +1 -0
- package/lib/tester/prettyDuration.js +30 -0
- package/lib/tester/prettyDuration.js.map +1 -0
- package/lib/tester/printTestResult.d.ts +2 -0
- package/lib/tester/printTestResult.js +32 -0
- package/lib/tester/printTestResult.js.map +1 -0
- package/lib/tester/types.d.ts +29 -0
- package/lib/tester/types.js +3 -0
- package/lib/tester/types.js.map +1 -0
- package/package.json +41 -13
- package/src/benchmark/index.spec.ts +375 -0
- package/src/benchmark/index.ts +433 -0
- package/src/builder/index.spec.ts +822 -0
- package/src/builder/index.ts +920 -0
- package/src/cli/index.spec.ts +54 -0
- package/src/cli/index.ts +150 -0
- package/src/config/index.spec.ts +70 -0
- package/src/config/index.ts +259 -0
- package/src/create/index.spec.ts +272 -0
- package/src/create/index.ts +295 -0
- package/src/datasource/filesystemAdapter.ts +313 -0
- package/src/datasource/index.ts +135 -0
- package/src/error.ts +33 -0
- package/src/evaluate/cli.spec.ts +368 -0
- package/src/evaluate/cli.ts +130 -0
- package/src/evaluate/index.ts +161 -0
- package/src/examples/coerceExampleIsoDates.spec.ts +81 -0
- package/src/examples/coerceExampleIsoDates.ts +98 -0
- package/src/examples/index.spec.ts +453 -0
- package/src/examples/index.ts +854 -0
- package/src/exporter/index.spec.ts +443 -0
- package/src/exporter/index.ts +643 -0
- package/src/find-duplicates/index.spec.ts +289 -0
- package/src/find-duplicates/index.ts +314 -0
- package/src/generate-code/index.ts +92 -0
- package/src/generate-code/typescript.spec.ts +241 -0
- package/src/generate-code/typescript.ts +284 -0
- package/src/importer/index.spec.ts +1101 -0
- package/src/importer/index.ts +1190 -0
- package/src/index.ts +18 -0
- package/src/info/index.ts +67 -0
- package/src/init/index.spec.ts +279 -0
- package/src/init/index.ts +292 -0
- package/src/lint/index.ts +1 -0
- package/src/linter/attributeSchema.ts +38 -0
- package/src/linter/checkLocaleCircularDependency.ts +51 -0
- package/src/linter/conditionSchema.ts +386 -0
- package/src/linter/formatSchema.ts +170 -0
- package/src/linter/icuStyleLint.ts +312 -0
- package/src/linter/index.spec.ts +824 -0
- package/src/linter/index.ts +460 -0
- package/src/linter/localeSchema.ts +70 -0
- package/src/linter/messageSchema.ts +152 -0
- package/src/linter/printError.ts +52 -0
- package/src/linter/schema.ts +230 -0
- package/src/linter/segmentSchema.ts +15 -0
- package/src/linter/targetSchema.ts +50 -0
- package/src/linter/testSchema.spec.ts +405 -0
- package/src/linter/testSchema.ts +239 -0
- package/src/linter/zodHelpers.ts +16 -0
- package/src/list/index.spec.ts +431 -0
- package/src/list/index.ts +463 -0
- package/src/matrix.ts +69 -0
- package/src/promoter/index.spec.ts +584 -0
- package/src/promoter/index.ts +1267 -0
- package/src/prune/index.spec.ts +418 -0
- package/src/prune/index.ts +693 -0
- package/src/sets.ts +74 -0
- package/src/tester/cliFormat.ts +11 -0
- package/src/tester/featurevisorIntegration.spec.ts +101 -0
- package/src/tester/index.spec.ts +577 -0
- package/src/tester/index.ts +679 -0
- package/src/tester/matrix.ts +106 -0
- package/src/tester/prettyDuration.ts +34 -0
- package/src/tester/printTestResult.ts +40 -0
- package/src/tester/types.ts +32 -0
- package/tsconfig.cjs.json +11 -0
- package/tsconfig.typecheck.json +4 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
LocaleAssertion,
|
|
3
|
+
Matrix,
|
|
4
|
+
MessageAssertion,
|
|
5
|
+
TargetAssertion,
|
|
6
|
+
SegmentAssertion,
|
|
7
|
+
} from "@messagevisor/types";
|
|
8
|
+
|
|
9
|
+
import { applyCombinationToValue, getMatrixCombinations } from "../matrix";
|
|
10
|
+
|
|
11
|
+
interface MatrixEnabledAssertion {
|
|
12
|
+
matrix?: Matrix;
|
|
13
|
+
description?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface ExpandedAssertionMeta {
|
|
17
|
+
assertionIndex: number;
|
|
18
|
+
matrixIndex?: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type ExpandedMessageAssertion = Omit<MessageAssertion, "matrix"> & ExpandedAssertionMeta;
|
|
22
|
+
export type ExpandedSegmentAssertion = Omit<SegmentAssertion, "matrix"> & ExpandedAssertionMeta;
|
|
23
|
+
export type ExpandedLocaleAssertion = Omit<LocaleAssertion, "matrix"> & ExpandedAssertionMeta;
|
|
24
|
+
export type ExpandedTargetAssertion = Omit<TargetAssertion, "matrix"> & ExpandedAssertionMeta;
|
|
25
|
+
|
|
26
|
+
function normalizeBooleanLike(value: unknown): unknown {
|
|
27
|
+
if (value === "true") {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (value === "false") {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function expandAssertions<T extends MatrixEnabledAssertion>(
|
|
39
|
+
assertions: T[],
|
|
40
|
+
normalizer?: (assertion: any) => any,
|
|
41
|
+
): Array<Omit<T, "matrix"> & ExpandedAssertionMeta> {
|
|
42
|
+
const expanded: Array<Omit<T, "matrix"> & ExpandedAssertionMeta> = [];
|
|
43
|
+
|
|
44
|
+
for (let assertionIndex = 0; assertionIndex < assertions.length; assertionIndex++) {
|
|
45
|
+
const rawAssertion = assertions[assertionIndex];
|
|
46
|
+
const { matrix, ...assertionWithoutMatrix } = rawAssertion;
|
|
47
|
+
|
|
48
|
+
if (!matrix) {
|
|
49
|
+
expanded.push({
|
|
50
|
+
...(normalizer ? normalizer({ ...assertionWithoutMatrix }) : assertionWithoutMatrix),
|
|
51
|
+
assertionIndex,
|
|
52
|
+
} as Omit<T, "matrix"> & ExpandedAssertionMeta);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const combinations = getMatrixCombinations(matrix);
|
|
57
|
+
|
|
58
|
+
for (let matrixIndex = 0; matrixIndex < combinations.length; matrixIndex++) {
|
|
59
|
+
const expandedAssertion = applyCombinationToValue(
|
|
60
|
+
assertionWithoutMatrix,
|
|
61
|
+
combinations[matrixIndex],
|
|
62
|
+
) as Omit<T, "matrix">;
|
|
63
|
+
|
|
64
|
+
expanded.push({
|
|
65
|
+
...(normalizer ? normalizer(expandedAssertion) : expandedAssertion),
|
|
66
|
+
assertionIndex,
|
|
67
|
+
matrixIndex,
|
|
68
|
+
} as Omit<T, "matrix"> & ExpandedAssertionMeta);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return expanded;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function expandMessageAssertions(
|
|
76
|
+
assertions: MessageAssertion[],
|
|
77
|
+
): ExpandedMessageAssertion[] {
|
|
78
|
+
return expandAssertions(assertions, (assertion) => ({
|
|
79
|
+
...assertion,
|
|
80
|
+
withFlags: assertion.withFlags
|
|
81
|
+
? Object.fromEntries(
|
|
82
|
+
Object.entries(assertion.withFlags).map(([key, value]) => [
|
|
83
|
+
key,
|
|
84
|
+
normalizeBooleanLike(value),
|
|
85
|
+
]),
|
|
86
|
+
)
|
|
87
|
+
: assertion.withFlags,
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function expandSegmentAssertions(
|
|
92
|
+
assertions: SegmentAssertion[],
|
|
93
|
+
): ExpandedSegmentAssertion[] {
|
|
94
|
+
return expandAssertions(assertions, (assertion) => ({
|
|
95
|
+
...assertion,
|
|
96
|
+
expectedToMatch: normalizeBooleanLike(assertion.expectedToMatch),
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function expandLocaleAssertions(assertions: LocaleAssertion[]): ExpandedLocaleAssertion[] {
|
|
101
|
+
return expandAssertions(assertions);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function expandTargetAssertions(assertions: TargetAssertion[]): ExpandedTargetAssertion[] {
|
|
105
|
+
return expandAssertions(assertions);
|
|
106
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export function prettyDuration(diffInMs: number) {
|
|
2
|
+
let diff = Math.abs(diffInMs);
|
|
3
|
+
|
|
4
|
+
if (diff === 0) {
|
|
5
|
+
return "0ms";
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const ms = diff % 1000;
|
|
9
|
+
diff = (diff - ms) / 1000;
|
|
10
|
+
const secs = diff % 60;
|
|
11
|
+
diff = (diff - secs) / 60;
|
|
12
|
+
const mins = diff % 60;
|
|
13
|
+
const hrs = (diff - mins) / 60;
|
|
14
|
+
|
|
15
|
+
let result = "";
|
|
16
|
+
|
|
17
|
+
if (hrs) {
|
|
18
|
+
result += ` ${hrs}h`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (mins) {
|
|
22
|
+
result += ` ${mins}m`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (secs) {
|
|
26
|
+
result += ` ${secs}s`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (ms) {
|
|
30
|
+
result += ` ${ms}ms`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return result.trim();
|
|
34
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { CLI_FORMAT_BOLD, CLI_FORMAT_RED } from "./cliFormat";
|
|
2
|
+
import { prettyDuration } from "./prettyDuration";
|
|
3
|
+
import type { TestResult } from "./types";
|
|
4
|
+
|
|
5
|
+
export function printTestResult(testResult: TestResult) {
|
|
6
|
+
console.log("");
|
|
7
|
+
console.log(`Testing: ${testResult.key} (${prettyDuration(testResult.duration)})`);
|
|
8
|
+
|
|
9
|
+
console.log(CLI_FORMAT_BOLD, ` ${testResult.type} "${testResult.subject}":`);
|
|
10
|
+
|
|
11
|
+
testResult.assertions.forEach((assertion) => {
|
|
12
|
+
if (assertion.passed) {
|
|
13
|
+
console.log(` ✔ ${assertion.description} (${prettyDuration(assertion.duration)})`);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
console.log(
|
|
18
|
+
CLI_FORMAT_RED,
|
|
19
|
+
` ✘ ${assertion.description} (${prettyDuration(assertion.duration)})`,
|
|
20
|
+
);
|
|
21
|
+
console.log(CLI_FORMAT_RED, ` ${testResult.filePath}`);
|
|
22
|
+
|
|
23
|
+
assertion.errors.forEach((error) => {
|
|
24
|
+
console.log(CLI_FORMAT_RED, ` => ${error.message}`);
|
|
25
|
+
|
|
26
|
+
if (typeof error.expected !== "undefined" || typeof error.actual !== "undefined") {
|
|
27
|
+
console.log(CLI_FORMAT_RED, ` expected: ${formatValue(error.expected)}`);
|
|
28
|
+
console.log(CLI_FORMAT_RED, ` received: ${formatValue(error.actual)}`);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function formatValue(value: unknown) {
|
|
35
|
+
if (typeof value === "string") {
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return JSON.stringify(value);
|
|
40
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface TestAssertionError {
|
|
2
|
+
message: string;
|
|
3
|
+
expected?: unknown;
|
|
4
|
+
actual?: unknown;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface TestResultAssertion {
|
|
8
|
+
description: string;
|
|
9
|
+
duration: number;
|
|
10
|
+
passed: boolean;
|
|
11
|
+
errors: TestAssertionError[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface TestResult {
|
|
15
|
+
key: string;
|
|
16
|
+
filePath: string;
|
|
17
|
+
type: "message" | "segment" | "target" | "locale";
|
|
18
|
+
subject: string;
|
|
19
|
+
duration: number;
|
|
20
|
+
passed: boolean;
|
|
21
|
+
assertions: TestResultAssertion[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface TestProjectOptions {
|
|
25
|
+
keyPattern?: string;
|
|
26
|
+
assertionPattern?: string;
|
|
27
|
+
verbose?: boolean;
|
|
28
|
+
showDatafile?: boolean;
|
|
29
|
+
onlyFailures?: boolean;
|
|
30
|
+
json?: boolean;
|
|
31
|
+
pretty?: boolean;
|
|
32
|
+
}
|