@jjlmoya/utils-textiles 1.25.0 → 1.26.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": "@jjlmoya/utils-textiles",
3
- "version": "1.25.0",
3
+ "version": "1.26.0",
4
4
  "type": "module",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
package/src/entries.ts CHANGED
@@ -39,4 +39,5 @@ import { shoeSizeConverter } from './tool/shoeSizeConverter/entry';
39
39
  import { stainChemistry } from './tool/stainChemistry/entry';
40
40
  import { yarnCalculator } from './tool/yarnCalculator/entry';
41
41
  import { embroideryStitchPricingEstimator } from './tool/embroideryStitchPricingEstimator/entry';
42
- export const ALL_ENTRIES = [burnTest, clothingSizeConverter, fabricProjectCalculator, fabricTruth, fiberPrep, knittingGauge, laundryGuide, needleConverter, sewingPatternScaler, shoeSizeConverter, stainChemistry, yarnCalculator, embroideryStitchPricingEstimator];
42
+ import { quiltBindingCalculator } from './tool/quiltBindingCalculator/entry';
43
+ export const ALL_ENTRIES = [burnTest, clothingSizeConverter, fabricProjectCalculator, fabricTruth, fiberPrep, knittingGauge, laundryGuide, needleConverter, sewingPatternScaler, shoeSizeConverter, stainChemistry, yarnCalculator, embroideryStitchPricingEstimator, quiltBindingCalculator];
@@ -0,0 +1,67 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { readdirSync } from 'fs';
3
+ import { join } from 'path';
4
+ import { pathToFileURL } from 'url';
5
+ import { ALL_ENTRIES } from '../entries';
6
+ import { ALL_TOOLS } from '../tools';
7
+ import type { ToolDefinition } from '../types';
8
+
9
+ function isToolDefinition(value: unknown): value is ToolDefinition {
10
+ if (!value || typeof value !== 'object') return false;
11
+
12
+ const candidate = value as Record<string, unknown>;
13
+ return Boolean(
14
+ candidate.entry &&
15
+ typeof candidate.entry === 'object' &&
16
+ typeof candidate.Component === 'function' &&
17
+ typeof candidate.SEOComponent === 'function' &&
18
+ typeof candidate.BibliographyComponent === 'function',
19
+ );
20
+ }
21
+
22
+ const toolRoot = join(process.cwd(), 'src', 'tool');
23
+ const toolDirectories = readdirSync(toolRoot, { withFileTypes: true })
24
+ .filter((entry) => entry.isDirectory())
25
+ .map((entry) => entry.name)
26
+ .sort();
27
+
28
+ describe('Library registry contract', () => {
29
+ it('keeps ALL_ENTRIES and ALL_TOOLS synchronized by identity and id', () => {
30
+ const entryIds = ALL_ENTRIES.map((entry) => entry.id);
31
+ const toolIds = ALL_TOOLS.map((tool) => tool.entry.id);
32
+
33
+ expect(new Set(entryIds).size).toBe(entryIds.length);
34
+ expect(new Set(toolIds).size).toBe(toolIds.length);
35
+ expect([...toolIds].sort()).toEqual([...entryIds].sort());
36
+
37
+ for (const tool of ALL_TOOLS) {
38
+ expect(ALL_ENTRIES.find((entry) => entry.id === tool.entry.id)).toBe(tool.entry);
39
+ }
40
+ });
41
+
42
+ it('registers every tool runtime index in both public registries', async () => {
43
+ const failures: string[] = [];
44
+
45
+ for (const directory of toolDirectories) {
46
+ const runtimeModule = await import(
47
+ pathToFileURL(join(toolRoot, directory, 'index.ts')).href,
48
+ );
49
+ const definitions = Object.values(runtimeModule).filter(isToolDefinition);
50
+
51
+ if (definitions.length !== 1) {
52
+ failures.push(`${directory}: expected exactly one ToolDefinition export, found ${definitions.length}`);
53
+ continue;
54
+ }
55
+
56
+ const [definition] = definitions;
57
+ if (!ALL_TOOLS.includes(definition)) {
58
+ failures.push(`${directory}: runtime definition is missing from ALL_TOOLS`);
59
+ }
60
+ if (!ALL_ENTRIES.includes(definition.entry)) {
61
+ failures.push(`${directory}: runtime entry is missing from ALL_ENTRIES`);
62
+ }
63
+ }
64
+
65
+ expect(failures).toEqual([]);
66
+ });
67
+ });