@toolpath/tool-scraper 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 (73) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +98 -0
  3. package/dist/conventions.d.ts +124 -0
  4. package/dist/conventions.js +143 -0
  5. package/dist/errors.d.ts +46 -0
  6. package/dist/errors.js +53 -0
  7. package/dist/families/destinytool.d.ts +49 -0
  8. package/dist/families/destinytool.js +55 -0
  9. package/dist/families/index.d.ts +59 -0
  10. package/dist/families/index.js +91 -0
  11. package/dist/families/kennametal.d.ts +757 -0
  12. package/dist/families/kennametal.js +660 -0
  13. package/dist/families/regofix.d.ts +185 -0
  14. package/dist/families/regofix.js +250 -0
  15. package/dist/family.d.ts +130 -0
  16. package/dist/family.js +38 -0
  17. package/dist/fetch.d.ts +98 -0
  18. package/dist/fetch.js +116 -0
  19. package/dist/identity.d.ts +133 -0
  20. package/dist/identity.js +118 -0
  21. package/dist/index.d.ts +31 -0
  22. package/dist/index.js +31 -0
  23. package/dist/node/cad-mirror.d.ts +55 -0
  24. package/dist/node/cad-mirror.js +89 -0
  25. package/dist/node/cli.d.ts +35 -0
  26. package/dist/node/cli.js +340 -0
  27. package/dist/node/csv.d.ts +47 -0
  28. package/dist/node/csv.js +123 -0
  29. package/dist/node/index.d.ts +16 -0
  30. package/dist/node/index.js +16 -0
  31. package/dist/node/main.d.ts +13 -0
  32. package/dist/node/main.js +14 -0
  33. package/dist/node/paths.d.ts +60 -0
  34. package/dist/node/paths.js +80 -0
  35. package/dist/node/receipts.d.ts +100 -0
  36. package/dist/node/receipts.js +107 -0
  37. package/dist/order.d.ts +10 -0
  38. package/dist/order.js +12 -0
  39. package/dist/provenance.d.ts +125 -0
  40. package/dist/provenance.js +133 -0
  41. package/dist/records.d.ts +305 -0
  42. package/dist/records.js +297 -0
  43. package/dist/registry.d.ts +63 -0
  44. package/dist/registry.js +145 -0
  45. package/dist/scrape.d.ts +70 -0
  46. package/dist/scrape.js +37 -0
  47. package/dist/thread.d.ts +48 -0
  48. package/dist/thread.js +98 -0
  49. package/dist/uuid5.d.ts +31 -0
  50. package/dist/uuid5.js +64 -0
  51. package/dist/vendors/destinytool/index.d.ts +11 -0
  52. package/dist/vendors/destinytool/index.js +11 -0
  53. package/dist/vendors/destinytool/records.d.ts +118 -0
  54. package/dist/vendors/destinytool/records.js +266 -0
  55. package/dist/vendors/destinytool/scrape.d.ts +108 -0
  56. package/dist/vendors/destinytool/scrape.js +192 -0
  57. package/dist/vendors/kennametal/cad.d.ts +87 -0
  58. package/dist/vendors/kennametal/cad.js +119 -0
  59. package/dist/vendors/kennametal/index.d.ts +21 -0
  60. package/dist/vendors/kennametal/index.js +21 -0
  61. package/dist/vendors/kennametal/materials.d.ts +143 -0
  62. package/dist/vendors/kennametal/materials.js +200 -0
  63. package/dist/vendors/kennametal/records.d.ts +88 -0
  64. package/dist/vendors/kennametal/records.js +241 -0
  65. package/dist/vendors/kennametal/scrape.d.ts +111 -0
  66. package/dist/vendors/kennametal/scrape.js +226 -0
  67. package/dist/vendors/kennametal/thread-column.d.ts +28 -0
  68. package/dist/vendors/kennametal/thread-column.js +41 -0
  69. package/dist/vendors/regofix/index.d.ts +8 -0
  70. package/dist/vendors/regofix/index.js +8 -0
  71. package/dist/vendors/regofix/scrape.d.ts +237 -0
  72. package/dist/vendors/regofix/scrape.js +521 -0
  73. package/package.json +76 -0
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Per-family scrape config: what to fetch, and how its columns are labelled.
3
+ *
4
+ * One module per vendor, merged here. The split is the point: a REGO-FIX
5
+ * family is named whatever REGO-FIX calls it without anybody checking
6
+ * Kennametal's list first, and adding a vendor is a new file rather than an
7
+ * edit to a table three other vendors depend on.
8
+ *
9
+ * **Config, not code.** Nothing here imports an adapter — `registry` is the
10
+ * one module that knows both, and `tests/vendor-boundary.test.ts` refuses the
11
+ * alternative. In the source package this table briefly did the binding
12
+ * itself, which made the config import a manufacturer; the table is read by
13
+ * every test, and none of them should drag a vendor's scraper in behind it.
14
+ *
15
+ * Three kinds of key, and they are worth telling apart:
16
+ *
17
+ * - **Scrape targets** — `familyCode`, and whatever else names the thing to
18
+ * fetch. This is what makes a scrape re-runnable without going back to the
19
+ * browser to find the family page again.
20
+ * - **`columns`** — the vendor's own column labels, keyed by canonical ISO
21
+ * 13399 name, *without* a unit suffix. `registry.bindFamilies` runs each
22
+ * through `records.checkColumnMap`, so a typo fails when the registry binds,
23
+ * naming the family.
24
+ * - **`facts`** — the per-family constants no vendor table states, each
25
+ * carrying its provenance. The registry checks and projects them, so readers
26
+ * say `family.unit` and never learn about provenance.
27
+ *
28
+ * **Where a scrape lands is not here.** Resolving a data root needs `fs` and
29
+ * `process.env`, which would make this table unimportable in anything that
30
+ * never writes a file. It is `node/paths.ts`.
31
+ */
32
+ import { ScraperConfigError } from '../errors.js';
33
+ import { FAMILIES as DESTINYTOOL } from './destinytool.js';
34
+ import { COLLET_FAMILIES as KM_COLLETS, FAMILIES as KENNAMETAL, HOLDER_FAMILIES as KM_HOLDERS, } from './kennametal.js';
35
+ import { COLLET_FAMILIES as RF_COLLETS, HOLDER_FAMILIES as RF_HOLDERS } from './regofix.js';
36
+ /**
37
+ * One flat table, refusing a CSV name two vendors both claim.
38
+ *
39
+ * A flat object is what every reader wants, and a spread is how it would
40
+ * normally be built — which is exactly the problem: the second vendor's entry
41
+ * would silently replace the first's, and the collision would surface as a
42
+ * family that scrapes into a file already holding someone else's rows. Two
43
+ * vendors shipping `end_mills_inch.csv` is not far-fetched; it is the first
44
+ * name either of them would pick.
45
+ */
46
+ function merge(...tables) {
47
+ const merged = {};
48
+ for (const table of tables) {
49
+ for (const [name, cfg] of Object.entries(table)) {
50
+ if (Object.hasOwn(merged, name)) {
51
+ throw new ScraperConfigError(name, 'claimed by two vendors — a CSV name is the key of this table and ' +
52
+ 'has to be unique across all of them');
53
+ }
54
+ merged[name] = cfg;
55
+ }
56
+ }
57
+ return merged;
58
+ }
59
+ /** Every cutting-tool family, keyed by the CSV it is scraped into. */
60
+ export const FAMILIES = merge(KENNAMETAL, DESTINYTOOL);
61
+ /**
62
+ * Every toolholding family — holders, and the collets that go in them.
63
+ *
64
+ * Separate tables rather than a `kind` on one, because a holder and a collet
65
+ * are not variants of a thing: they carry different discriminants (a holder
66
+ * states a taper and a clamping mode; a collet states a series and a capacity
67
+ * band) and a scrape of one is not a scrape of the other.
68
+ */
69
+ export const HOLDER_FAMILIES = merge(KM_HOLDERS, RF_HOLDERS);
70
+ export const COLLET_FAMILIES = merge(KM_COLLETS, RF_COLLETS);
71
+ /**
72
+ * Every family this package knows, by CSV name — tools and toolholding alike.
73
+ *
74
+ * Built once rather than searched per call, so a lookup can refuse an unknown
75
+ * name by listing what it does know.
76
+ *
77
+ * Through {@link merge} and not a spread, for the reason {@link merge} exists:
78
+ * a spread here would let a name claimed by two of the three tables resolve
79
+ * silently to whichever was spread last, and this is the table `familyConfig`
80
+ * — and therefore `familyBrand`, and therefore where a CSV is written — reads.
81
+ */
82
+ export const ALL_FAMILIES = merge(FAMILIES, HOLDER_FAMILIES, COLLET_FAMILIES);
83
+ /** One family's config by CSV name, refusing a name nothing declares. */
84
+ export function familyConfig(name) {
85
+ const cfg = ALL_FAMILIES[name];
86
+ if (cfg === undefined) {
87
+ throw new ScraperConfigError(name, `unknown family CSV (known: ${Object.keys(ALL_FAMILIES).sort().join(', ')})`);
88
+ }
89
+ return cfg;
90
+ }
91
+ export { familyBrand, familyId } from '../family.js';