@dogfood-lab/findings 1.2.2 → 1.2.3

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.
@@ -1,63 +1,63 @@
1
- /**
2
- * Write derived candidate findings to disk as YAML files.
3
- */
4
-
5
- import { mkdirSync, existsSync } from 'node:fs';
6
- import { resolve, dirname } from 'node:path';
7
- import yaml from 'js-yaml';
8
-
9
- import { atomicWriteFileSync } from '../lib/atomic-write.js';
10
-
11
- /**
12
- * Write a candidate finding to its canonical location.
13
- *
14
- * findings/<org>/<repo>/<finding_id>.yaml
15
- *
16
- * @param {string} rootDir - dogfood-labs repo root.
17
- * @param {object} finding - Schema-valid candidate finding object.
18
- * @returns {string} - Path written.
19
- */
20
- export function writeFinding(rootDir, finding) {
21
- const [org, repo] = (finding.repo || '').split('/');
22
- if (!org || !repo) throw new Error(`Invalid repo in finding: ${finding.repo}`);
23
-
24
- const dir = resolve(rootDir, 'findings', org, repo);
25
- mkdirSync(dir, { recursive: true });
26
-
27
- const filePath = resolve(dir, `${finding.finding_id}.yaml`);
28
-
29
- // Strip undefined values for clean YAML
30
- const clean = JSON.parse(JSON.stringify(finding));
31
- const yamlStr = yaml.dump(clean, {
32
- lineWidth: 120,
33
- noRefs: true,
34
- quotingType: '"',
35
- forceQuotes: false
36
- });
37
-
38
- atomicWriteFileSync(filePath, yamlStr);
39
- return filePath;
40
- }
41
-
42
- /**
43
- * Write multiple findings and return write stats.
44
- *
45
- * @param {string} rootDir
46
- * @param {Array} findings
47
- * @returns {{ written: string[], errors: Array<{ findingId: string, error: string }> }}
48
- */
49
- export function writeFindings(rootDir, findings) {
50
- const written = [];
51
- const errors = [];
52
-
53
- for (const f of findings) {
54
- try {
55
- const path = writeFinding(rootDir, f);
56
- written.push(path);
57
- } catch (err) {
58
- errors.push({ findingId: f.finding_id, error: err.message });
59
- }
60
- }
61
-
62
- return { written, errors };
63
- }
1
+ /**
2
+ * Write derived candidate findings to disk as YAML files.
3
+ */
4
+
5
+ import { mkdirSync, existsSync } from 'node:fs';
6
+ import { resolve, dirname } from 'node:path';
7
+ import yaml from 'js-yaml';
8
+
9
+ import { atomicWriteFileSync } from '../lib/atomic-write.js';
10
+
11
+ /**
12
+ * Write a candidate finding to its canonical location.
13
+ *
14
+ * findings/<org>/<repo>/<finding_id>.yaml
15
+ *
16
+ * @param {string} rootDir - dogfood-labs repo root.
17
+ * @param {object} finding - Schema-valid candidate finding object.
18
+ * @returns {string} - Path written.
19
+ */
20
+ export function writeFinding(rootDir, finding) {
21
+ const [org, repo] = (finding.repo || '').split('/');
22
+ if (!org || !repo) throw new Error(`Invalid repo in finding: ${finding.repo}`);
23
+
24
+ const dir = resolve(rootDir, 'findings', org, repo);
25
+ mkdirSync(dir, { recursive: true });
26
+
27
+ const filePath = resolve(dir, `${finding.finding_id}.yaml`);
28
+
29
+ // Strip undefined values for clean YAML
30
+ const clean = JSON.parse(JSON.stringify(finding));
31
+ const yamlStr = yaml.dump(clean, {
32
+ lineWidth: 120,
33
+ noRefs: true,
34
+ quotingType: '"',
35
+ forceQuotes: false
36
+ });
37
+
38
+ atomicWriteFileSync(filePath, yamlStr);
39
+ return filePath;
40
+ }
41
+
42
+ /**
43
+ * Write multiple findings and return write stats.
44
+ *
45
+ * @param {string} rootDir
46
+ * @param {Array} findings
47
+ * @returns {{ written: string[], errors: Array<{ findingId: string, error: string }> }}
48
+ */
49
+ export function writeFindings(rootDir, findings) {
50
+ const written = [];
51
+ const errors = [];
52
+
53
+ for (const f of findings) {
54
+ try {
55
+ const path = writeFinding(rootDir, f);
56
+ written.push(path);
57
+ } catch (err) {
58
+ errors.push({ findingId: f.finding_id, error: err.message });
59
+ }
60
+ }
61
+
62
+ return { written, errors };
63
+ }
package/index.js CHANGED
@@ -1,11 +1,11 @@
1
- /**
2
- * @dogfood-labs/findings
3
- *
4
- * Finding contract spine for dogfood-labs.
5
- * The fourth contract alongside record, scenario, and policy.
6
- *
7
- * Exports: validation, reading, listing, filtering, duplicate detection.
8
- */
9
-
10
- export { parseFinding, validateFinding, validateFindingFile } from './validate.js';
11
- export { discoverFindings, discoverFixtures, loadFindings, findById, filterFindings, findDuplicates } from './reader.js';
1
+ /**
2
+ * @dogfood-labs/findings
3
+ *
4
+ * Finding contract spine for dogfood-labs.
5
+ * The fourth contract alongside record, scenario, and policy.
6
+ *
7
+ * Exports: validation, reading, listing, filtering, duplicate detection.
8
+ */
9
+
10
+ export { parseFinding, validateFinding, validateFindingFile } from './validate.js';
11
+ export { discoverFindings, discoverFixtures, loadFindings, findById, filterFindings, findDuplicates } from './reader.js';