@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.
Files changed (211) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +21 -0
  3. package/README.md +7 -0
  4. package/jest.config.js +8 -0
  5. package/lib/benchmark/index.d.ts +2 -0
  6. package/lib/benchmark/index.js +417 -0
  7. package/lib/benchmark/index.js.map +1 -0
  8. package/lib/builder/index.d.ts +70 -0
  9. package/lib/builder/index.js +831 -0
  10. package/lib/builder/index.js.map +1 -0
  11. package/lib/cli/index.d.ts +28 -0
  12. package/lib/cli/index.js +182 -0
  13. package/lib/cli/index.js.map +1 -0
  14. package/lib/config/index.d.ts +61 -0
  15. package/lib/config/index.js +255 -0
  16. package/lib/config/index.js.map +1 -0
  17. package/lib/create/index.d.ts +2 -0
  18. package/lib/create/index.js +405 -0
  19. package/lib/create/index.js.map +1 -0
  20. package/lib/datasource/filesystemAdapter.d.ts +44 -0
  21. package/lib/datasource/filesystemAdapter.js +424 -0
  22. package/lib/datasource/filesystemAdapter.js.map +1 -0
  23. package/lib/datasource/index.d.ts +39 -0
  24. package/lib/datasource/index.js +96 -0
  25. package/lib/datasource/index.js.map +1 -0
  26. package/lib/error.d.ts +6 -0
  27. package/lib/error.js +49 -0
  28. package/lib/error.js.map +1 -0
  29. package/lib/evaluate/cli.d.ts +8 -0
  30. package/lib/evaluate/cli.js +179 -0
  31. package/lib/evaluate/cli.js.map +1 -0
  32. package/lib/evaluate/index.d.ts +10 -0
  33. package/lib/evaluate/index.js +131 -0
  34. package/lib/evaluate/index.js.map +1 -0
  35. package/lib/examples/coerceExampleIsoDates.d.ts +12 -0
  36. package/lib/examples/coerceExampleIsoDates.js +81 -0
  37. package/lib/examples/coerceExampleIsoDates.js.map +1 -0
  38. package/lib/examples/index.d.ts +63 -0
  39. package/lib/examples/index.js +713 -0
  40. package/lib/examples/index.js.map +1 -0
  41. package/lib/exporter/index.d.ts +60 -0
  42. package/lib/exporter/index.js +610 -0
  43. package/lib/exporter/index.js.map +1 -0
  44. package/lib/find-duplicates/index.d.ts +41 -0
  45. package/lib/find-duplicates/index.js +297 -0
  46. package/lib/find-duplicates/index.js.map +1 -0
  47. package/lib/generate-code/index.d.ts +11 -0
  48. package/lib/generate-code/index.js +157 -0
  49. package/lib/generate-code/index.js.map +1 -0
  50. package/lib/generate-code/typescript.d.ts +14 -0
  51. package/lib/generate-code/typescript.js +307 -0
  52. package/lib/generate-code/typescript.js.map +1 -0
  53. package/lib/importer/index.d.ts +64 -0
  54. package/lib/importer/index.js +1092 -0
  55. package/lib/importer/index.js.map +1 -0
  56. package/lib/index.d.ts +18 -0
  57. package/lib/index.js +35 -0
  58. package/lib/index.js.map +1 -0
  59. package/lib/info/index.d.ts +17 -0
  60. package/lib/info/index.js +132 -0
  61. package/lib/info/index.js.map +1 -0
  62. package/lib/init/index.d.ts +30 -0
  63. package/lib/init/index.js +348 -0
  64. package/lib/init/index.js.map +1 -0
  65. package/lib/lint/index.d.ts +1 -0
  66. package/lib/lint/index.js +6 -0
  67. package/lib/lint/index.js.map +1 -0
  68. package/lib/linter/attributeSchema.d.ts +7 -0
  69. package/lib/linter/attributeSchema.js +36 -0
  70. package/lib/linter/attributeSchema.js.map +1 -0
  71. package/lib/linter/checkLocaleCircularDependency.d.ts +7 -0
  72. package/lib/linter/checkLocaleCircularDependency.js +42 -0
  73. package/lib/linter/checkLocaleCircularDependency.js.map +1 -0
  74. package/lib/linter/conditionSchema.d.ts +3 -0
  75. package/lib/linter/conditionSchema.js +283 -0
  76. package/lib/linter/conditionSchema.js.map +1 -0
  77. package/lib/linter/formatSchema.d.ts +325 -0
  78. package/lib/linter/formatSchema.js +165 -0
  79. package/lib/linter/formatSchema.js.map +1 -0
  80. package/lib/linter/icuStyleLint.d.ts +6 -0
  81. package/lib/linter/icuStyleLint.js +226 -0
  82. package/lib/linter/icuStyleLint.js.map +1 -0
  83. package/lib/linter/index.d.ts +34 -0
  84. package/lib/linter/index.js +557 -0
  85. package/lib/linter/index.js.map +1 -0
  86. package/lib/linter/localeSchema.d.ts +672 -0
  87. package/lib/linter/localeSchema.js +50 -0
  88. package/lib/linter/localeSchema.js.map +1 -0
  89. package/lib/linter/messageSchema.d.ts +35 -0
  90. package/lib/linter/messageSchema.js +115 -0
  91. package/lib/linter/messageSchema.js.map +1 -0
  92. package/lib/linter/printError.d.ts +8 -0
  93. package/lib/linter/printError.js +41 -0
  94. package/lib/linter/printError.js.map +1 -0
  95. package/lib/linter/schema.d.ts +33 -0
  96. package/lib/linter/schema.js +192 -0
  97. package/lib/linter/schema.js.map +1 -0
  98. package/lib/linter/segmentSchema.d.ts +8 -0
  99. package/lib/linter/segmentSchema.js +18 -0
  100. package/lib/linter/segmentSchema.js.map +1 -0
  101. package/lib/linter/targetSchema.d.ts +337 -0
  102. package/lib/linter/targetSchema.js +39 -0
  103. package/lib/linter/targetSchema.js.map +1 -0
  104. package/lib/linter/testSchema.d.ts +71 -0
  105. package/lib/linter/testSchema.js +165 -0
  106. package/lib/linter/testSchema.js.map +1 -0
  107. package/lib/linter/zodHelpers.d.ts +2 -0
  108. package/lib/linter/zodHelpers.js +15 -0
  109. package/lib/linter/zodHelpers.js.map +1 -0
  110. package/lib/list/index.d.ts +8 -0
  111. package/lib/list/index.js +524 -0
  112. package/lib/list/index.js.map +1 -0
  113. package/lib/matrix.d.ts +4 -0
  114. package/lib/matrix.js +66 -0
  115. package/lib/matrix.js.map +1 -0
  116. package/lib/promoter/index.d.ts +65 -0
  117. package/lib/promoter/index.js +1208 -0
  118. package/lib/promoter/index.js.map +1 -0
  119. package/lib/prune/index.d.ts +37 -0
  120. package/lib/prune/index.js +673 -0
  121. package/lib/prune/index.js.map +1 -0
  122. package/lib/sets.d.ts +10 -0
  123. package/lib/sets.js +120 -0
  124. package/lib/sets.js.map +1 -0
  125. package/lib/tester/cliFormat.d.ts +8 -0
  126. package/lib/tester/cliFormat.js +15 -0
  127. package/lib/tester/cliFormat.js.map +1 -0
  128. package/lib/tester/index.d.ts +35 -0
  129. package/lib/tester/index.js +713 -0
  130. package/lib/tester/index.js.map +1 -0
  131. package/lib/tester/matrix.d.ts +14 -0
  132. package/lib/tester/matrix.js +76 -0
  133. package/lib/tester/matrix.js.map +1 -0
  134. package/lib/tester/prettyDuration.d.ts +1 -0
  135. package/lib/tester/prettyDuration.js +30 -0
  136. package/lib/tester/prettyDuration.js.map +1 -0
  137. package/lib/tester/printTestResult.d.ts +2 -0
  138. package/lib/tester/printTestResult.js +32 -0
  139. package/lib/tester/printTestResult.js.map +1 -0
  140. package/lib/tester/types.d.ts +29 -0
  141. package/lib/tester/types.js +3 -0
  142. package/lib/tester/types.js.map +1 -0
  143. package/package.json +41 -13
  144. package/src/benchmark/index.spec.ts +375 -0
  145. package/src/benchmark/index.ts +433 -0
  146. package/src/builder/index.spec.ts +822 -0
  147. package/src/builder/index.ts +920 -0
  148. package/src/cli/index.spec.ts +54 -0
  149. package/src/cli/index.ts +150 -0
  150. package/src/config/index.spec.ts +70 -0
  151. package/src/config/index.ts +259 -0
  152. package/src/create/index.spec.ts +272 -0
  153. package/src/create/index.ts +295 -0
  154. package/src/datasource/filesystemAdapter.ts +313 -0
  155. package/src/datasource/index.ts +135 -0
  156. package/src/error.ts +33 -0
  157. package/src/evaluate/cli.spec.ts +368 -0
  158. package/src/evaluate/cli.ts +130 -0
  159. package/src/evaluate/index.ts +161 -0
  160. package/src/examples/coerceExampleIsoDates.spec.ts +81 -0
  161. package/src/examples/coerceExampleIsoDates.ts +98 -0
  162. package/src/examples/index.spec.ts +453 -0
  163. package/src/examples/index.ts +854 -0
  164. package/src/exporter/index.spec.ts +443 -0
  165. package/src/exporter/index.ts +643 -0
  166. package/src/find-duplicates/index.spec.ts +289 -0
  167. package/src/find-duplicates/index.ts +314 -0
  168. package/src/generate-code/index.ts +92 -0
  169. package/src/generate-code/typescript.spec.ts +241 -0
  170. package/src/generate-code/typescript.ts +284 -0
  171. package/src/importer/index.spec.ts +1101 -0
  172. package/src/importer/index.ts +1190 -0
  173. package/src/index.ts +18 -0
  174. package/src/info/index.ts +67 -0
  175. package/src/init/index.spec.ts +279 -0
  176. package/src/init/index.ts +292 -0
  177. package/src/lint/index.ts +1 -0
  178. package/src/linter/attributeSchema.ts +38 -0
  179. package/src/linter/checkLocaleCircularDependency.ts +51 -0
  180. package/src/linter/conditionSchema.ts +386 -0
  181. package/src/linter/formatSchema.ts +170 -0
  182. package/src/linter/icuStyleLint.ts +312 -0
  183. package/src/linter/index.spec.ts +824 -0
  184. package/src/linter/index.ts +460 -0
  185. package/src/linter/localeSchema.ts +70 -0
  186. package/src/linter/messageSchema.ts +152 -0
  187. package/src/linter/printError.ts +52 -0
  188. package/src/linter/schema.ts +230 -0
  189. package/src/linter/segmentSchema.ts +15 -0
  190. package/src/linter/targetSchema.ts +50 -0
  191. package/src/linter/testSchema.spec.ts +405 -0
  192. package/src/linter/testSchema.ts +239 -0
  193. package/src/linter/zodHelpers.ts +16 -0
  194. package/src/list/index.spec.ts +431 -0
  195. package/src/list/index.ts +463 -0
  196. package/src/matrix.ts +69 -0
  197. package/src/promoter/index.spec.ts +584 -0
  198. package/src/promoter/index.ts +1267 -0
  199. package/src/prune/index.spec.ts +418 -0
  200. package/src/prune/index.ts +693 -0
  201. package/src/sets.ts +74 -0
  202. package/src/tester/cliFormat.ts +11 -0
  203. package/src/tester/featurevisorIntegration.spec.ts +101 -0
  204. package/src/tester/index.spec.ts +577 -0
  205. package/src/tester/index.ts +679 -0
  206. package/src/tester/matrix.ts +106 -0
  207. package/src/tester/prettyDuration.ts +34 -0
  208. package/src/tester/printTestResult.ts +40 -0
  209. package/src/tester/types.ts +32 -0
  210. package/tsconfig.cjs.json +11 -0
  211. 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
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "../../tsconfig.cjs.json",
3
+ "compilerOptions": {
4
+ "outDir": "./lib",
5
+ "rootDir": "./src",
6
+ "moduleResolution": "node",
7
+ "esModuleInterop": true
8
+ },
9
+ "include": ["./src/**/*.ts"],
10
+ "exclude": ["./src/**/*.spec.ts"]
11
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "./tsconfig.cjs.json",
3
+ "exclude": []
4
+ }