@nitpicker/report-google-sheets 0.21.0 → 0.22.1

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.
@@ -27,7 +27,13 @@ import type { CreateSheet } from '../sheets/types.js';
27
27
  * comment) — replaced by `DOM Path`, a stable structural locator
28
28
  * (e.g. `html/body[1]/main[1]/img[1]`) derived from the same crawl-time
29
29
  * capture.
30
- * @param _reports
31
- * @param accessor
30
+ * `options.urls` (already normalized via `resolvePageListUrlFilter`)
31
+ * restricts both `estimateRowCount` and `run` to images on exactly those
32
+ * pages (matched on the page's URL, not the image's own `src`).
33
+ * @param options - Row-set restriction. Omitted or `urls: undefined` reports every image.
34
+ * @param options.urls - See above.
35
+ * @returns A {@link CreateSheet} factory for the Images sheet.
32
36
  */
33
- export declare const createImageList: CreateSheet;
37
+ export declare function createImageList(options?: {
38
+ urls?: readonly string[];
39
+ }): CreateSheet;
@@ -1,15 +1,18 @@
1
- import { streamAllImages } from '@nitpicker/query';
1
+ import { applyEqualityOrInFilter, streamAllImages } from '@nitpicker/query';
2
2
  import { createCellData } from '../sheets/create-cell-data.js';
3
3
  import { defaultCellFormat } from '../sheets/default-cell-format.js';
4
4
  /**
5
5
  * Counts every `image_items` row, for `estimateRowCount()`.
6
6
  * @param accessor - The archive accessor to query.
7
+ * @param urls - Exact-match page-URL allowlist, already normalized. Omitted or empty counts every row.
7
8
  */
8
- async function countImages(accessor) {
9
+ async function countImages(accessor, urls) {
9
10
  const knex = accessor.getKnex();
10
- const [row] = await knex('image_items').count({
11
- count: '*',
12
- });
11
+ const [row] = await knex('image_items as ii')
12
+ .join('content_items as ci', 'ii.page_id', 'ci.id')
13
+ .join('url_refs as page_ur', 'page_ur.id', 'ci.url_id')
14
+ .modify((qb) => applyEqualityOrInFilter(qb, 'page_ur.url', urls))
15
+ .count({ count: '*' });
13
16
  return Number(row?.count ?? 0);
14
17
  }
15
18
  /**
@@ -40,50 +43,57 @@ async function countImages(accessor) {
40
43
  * comment) — replaced by `DOM Path`, a stable structural locator
41
44
  * (e.g. `html/body[1]/main[1]/img[1]`) derived from the same crawl-time
42
45
  * capture.
43
- * @param _reports
44
- * @param accessor
46
+ * `options.urls` (already normalized via `resolvePageListUrlFilter`)
47
+ * restricts both `estimateRowCount` and `run` to images on exactly those
48
+ * pages (matched on the page's URL, not the image's own `src`).
49
+ * @param options - Row-set restriction. Omitted or `urls: undefined` reports every image.
50
+ * @param options.urls - See above.
51
+ * @returns A {@link CreateSheet} factory for the Images sheet.
45
52
  */
46
- export const createImageList = (_reports, accessor) => {
47
- return {
48
- name: 'Images',
49
- requiresReadModel: true,
50
- createHeaders() {
51
- return [
52
- 'Page URL',
53
- 'Image path (src)',
54
- 'Image Path (currentSrc)',
55
- 'Alternative Text',
56
- 'Displayed Width',
57
- 'Displayed Height',
58
- 'Lazy Loading',
59
- 'DOM Path',
60
- ];
61
- },
62
- estimateRowCount: () => countImages(accessor),
63
- async run({ sheet, maxRows, estimatedTotal, onProgress }) {
64
- let sent = 0;
65
- const total = estimatedTotal;
66
- for await (const chunk of streamAllImages(accessor)) {
67
- for (const item of chunk) {
68
- if (sent >= maxRows) {
69
- await sheet.flush();
70
- return;
53
+ export function createImageList(options) {
54
+ const urls = options?.urls;
55
+ return (_reports, accessor) => {
56
+ return {
57
+ name: 'Images',
58
+ requiresReadModel: true,
59
+ createHeaders() {
60
+ return [
61
+ 'Page URL',
62
+ 'Image path (src)',
63
+ 'Image Path (currentSrc)',
64
+ 'Alternative Text',
65
+ 'Displayed Width',
66
+ 'Displayed Height',
67
+ 'Lazy Loading',
68
+ 'DOM Path',
69
+ ];
70
+ },
71
+ estimateRowCount: () => countImages(accessor, urls),
72
+ async run({ sheet, maxRows, estimatedTotal, onProgress }) {
73
+ let sent = 0;
74
+ const total = estimatedTotal;
75
+ for await (const chunk of streamAllImages(accessor, { urls })) {
76
+ for (const item of chunk) {
77
+ if (sent >= maxRows) {
78
+ await sheet.flush();
79
+ return;
80
+ }
81
+ await sheet.appendRow([
82
+ createCellData({ value: item.pageUrl }, defaultCellFormat),
83
+ createCellData({ value: item.src }, defaultCellFormat),
84
+ createCellData({ value: item.currentSrc }, defaultCellFormat),
85
+ createCellData({ value: item.alt }, defaultCellFormat),
86
+ createCellData({ value: item.width }, defaultCellFormat),
87
+ createCellData({ value: item.height }, defaultCellFormat),
88
+ createCellData({ value: item.isLazy }, defaultCellFormat),
89
+ createCellData({ value: item.domPath }, defaultCellFormat),
90
+ ]);
91
+ sent++;
92
+ onProgress(sent, total);
71
93
  }
72
- await sheet.appendRow([
73
- createCellData({ value: item.pageUrl }, defaultCellFormat),
74
- createCellData({ value: item.src }, defaultCellFormat),
75
- createCellData({ value: item.currentSrc }, defaultCellFormat),
76
- createCellData({ value: item.alt }, defaultCellFormat),
77
- createCellData({ value: item.width }, defaultCellFormat),
78
- createCellData({ value: item.height }, defaultCellFormat),
79
- createCellData({ value: item.isLazy }, defaultCellFormat),
80
- createCellData({ value: item.domPath }, defaultCellFormat),
81
- ]);
82
- sent++;
83
- onProgress(sent, total);
84
94
  }
85
- }
86
- await sheet.flush();
87
- },
95
+ await sheet.flush();
96
+ },
97
+ };
88
98
  };
89
- };
99
+ }
@@ -26,7 +26,15 @@ import type { CreateSheet } from '../sheets/types.js';
26
26
  * - Status codes outside the 200-399 range (non-success)
27
27
  *
28
28
  * The header row and first column are frozen for easier scrolling.
29
- * @param _reports
30
- * @param accessor
29
+ *
30
+ * `options.urls` (already normalized via `resolvePageListUrlFilter`)
31
+ * restricts both `estimateRowCount` and `run` to exactly those
32
+ * `content_items` rows — matched on the joined `url_refs.url` column since
33
+ * `content_items` itself has no `url` column of its own.
34
+ * @param options - Row-set restriction. Omitted or `urls: undefined` reports every page.
35
+ * @param options.urls - See above.
36
+ * @returns A {@link CreateSheet} factory for the Links sheet.
31
37
  */
32
- export declare const createLinks: CreateSheet;
38
+ export declare function createLinks(options?: {
39
+ urls?: readonly string[];
40
+ }): CreateSheet;
@@ -1,4 +1,4 @@
1
- import { getInboundReferrerUrlsByPageIds, streamAllContentItems } from '@nitpicker/query';
1
+ import { applyEqualityOrInFilter, getInboundReferrerUrlsByPageIds, streamAllContentItems, } from '@nitpicker/query';
2
2
  import { pLog } from '../debug.js';
3
3
  import { createCellData } from '../sheets/create-cell-data.js';
4
4
  import { defaultCellFormat } from '../sheets/default-cell-format.js';
@@ -45,101 +45,111 @@ function formatReferrerNoteLine(detail) {
45
45
  * - Status codes outside the 200-399 range (non-success)
46
46
  *
47
47
  * The header row and first column are frozen for easier scrolling.
48
- * @param _reports
49
- * @param accessor
48
+ *
49
+ * `options.urls` (already normalized via `resolvePageListUrlFilter`)
50
+ * restricts both `estimateRowCount` and `run` to exactly those
51
+ * `content_items` rows — matched on the joined `url_refs.url` column since
52
+ * `content_items` itself has no `url` column of its own.
53
+ * @param options - Row-set restriction. Omitted or `urls: undefined` reports every page.
54
+ * @param options.urls - See above.
55
+ * @returns A {@link CreateSheet} factory for the Links sheet.
50
56
  */
51
- export const createLinks = (_reports, accessor) => {
52
- return {
53
- name: 'Links',
54
- requiresReadModel: true,
55
- createHeaders() {
56
- return [
57
- 'URL',
58
- 'Page Title',
59
- 'Status Code',
60
- 'Status Text',
61
- 'Content Type',
62
- 'Redirect From',
63
- 'Referrers',
64
- 'Headers',
65
- 'Remarks',
66
- ];
67
- },
68
- async estimateRowCount() {
69
- const knex = accessor.getKnex();
70
- const [row] = await knex('content_items').count({
71
- count: '*',
72
- });
73
- return Number(row?.count ?? 0);
74
- },
75
- async run({ sheet, maxRows, estimatedTotal, onProgress }) {
76
- let sent = 0;
77
- // No cheap running total from `streamAllContentItems` itself (unlike
78
- // `getViolations`'s `page.total` or `listViewerPages`'s `page.total`)
79
- // — `estimatedTotal` (from `estimateRowCount()`, captured once in
80
- // Phase 1.5) is the progress denominator instead.
81
- const total = estimatedTotal;
82
- for await (const chunk of streamAllContentItems(accessor)) {
83
- const referrerDetailsByPageId = await getInboundReferrerUrlsByPageIds(accessor, chunk.map((row) => row.pageId));
84
- for (const row of chunk) {
85
- if (sent >= maxRows) {
86
- await sheet.flush();
87
- return;
57
+ export function createLinks(options) {
58
+ const urls = options?.urls;
59
+ return (_reports, accessor) => {
60
+ return {
61
+ name: 'Links',
62
+ requiresReadModel: true,
63
+ createHeaders() {
64
+ return [
65
+ 'URL',
66
+ 'Page Title',
67
+ 'Status Code',
68
+ 'Status Text',
69
+ 'Content Type',
70
+ 'Redirect From',
71
+ 'Referrers',
72
+ 'Headers',
73
+ 'Remarks',
74
+ ];
75
+ },
76
+ async estimateRowCount() {
77
+ const knex = accessor.getKnex();
78
+ const [row] = await knex('content_items as ci')
79
+ .join('url_refs as ur', 'ur.id', 'ci.url_id')
80
+ .modify((qb) => applyEqualityOrInFilter(qb, 'ur.url', urls))
81
+ .count({ count: '*' });
82
+ return Number(row?.count ?? 0);
83
+ },
84
+ async run({ sheet, maxRows, estimatedTotal, onProgress }) {
85
+ let sent = 0;
86
+ // No cheap running total from `streamAllContentItems` itself (unlike
87
+ // `getViolations`'s `page.total` or `listViewerPages`'s `page.total`)
88
+ // — `estimatedTotal` (from `estimateRowCount()`, captured once in
89
+ // Phase 1.5) is the progress denominator instead.
90
+ const total = estimatedTotal;
91
+ for await (const chunk of streamAllContentItems(accessor, { urls })) {
92
+ const referrerDetailsByPageId = await getInboundReferrerUrlsByPageIds(accessor, chunk.map((row) => row.pageId));
93
+ for (const row of chunk) {
94
+ if (sent >= maxRows) {
95
+ await sheet.flush();
96
+ return;
97
+ }
98
+ const referrerDetails = referrerDetailsByPageId.get(row.pageId) ?? [];
99
+ // Sum occurrence counts, not `.length`: `referrerDetails` is
100
+ // already deduped to one entry per referring page (see
101
+ // `InboundReferrerDetail.count`'s docs), so counting entries
102
+ // would undercount a page with more than one anchor to the
103
+ // same destination.
104
+ const elementCount = referrerDetails.reduce((sum, d) => sum + d.count, 0);
105
+ await sheet.appendRow([
106
+ createCellData({ value: row.url, textFormat: { link: { uri: row.url } } }, defaultCellFormat),
107
+ createCellData({ value: row.title || '-' }, defaultCellFormat),
108
+ createCellData({ value: row.status ?? -1 }, defaultCellFormat),
109
+ createCellData({ value: row.statusText || '' }, defaultCellFormat),
110
+ createCellData({ value: row.contentType || '' }, defaultCellFormat),
111
+ createCellData({
112
+ value: row.redirectFromUrls.length,
113
+ note: joinUrlsForNote(row.redirectFromUrls),
114
+ }, defaultCellFormat),
115
+ createCellData({
116
+ value: `${elementCount} Elements`,
117
+ note: joinUrlsForNote(referrerDetails.map(formatReferrerNoteLine)),
118
+ }, defaultCellFormat),
119
+ createCellData({
120
+ value: '{}',
121
+ note: truncateNoteText(JSON.stringify(row.responseHeaders, null, 2)),
122
+ }, defaultCellFormat),
123
+ createCellData({ value: row.isSkipped ? row.skipReason || 'skipped' : '' }, defaultCellFormat),
124
+ ]);
125
+ sent++;
126
+ onProgress(sent, total);
88
127
  }
89
- const referrerDetails = referrerDetailsByPageId.get(row.pageId) ?? [];
90
- // Sum occurrence counts, not `.length`: `referrerDetails` is
91
- // already deduped to one entry per referring page (see
92
- // `InboundReferrerDetail.count`'s docs), so counting entries
93
- // would undercount a page with more than one anchor to the
94
- // same destination.
95
- const elementCount = referrerDetails.reduce((sum, d) => sum + d.count, 0);
96
- await sheet.appendRow([
97
- createCellData({ value: row.url, textFormat: { link: { uri: row.url } } }, defaultCellFormat),
98
- createCellData({ value: row.title || '-' }, defaultCellFormat),
99
- createCellData({ value: row.status ?? -1 }, defaultCellFormat),
100
- createCellData({ value: row.statusText || '' }, defaultCellFormat),
101
- createCellData({ value: row.contentType || '' }, defaultCellFormat),
102
- createCellData({
103
- value: row.redirectFromUrls.length,
104
- note: joinUrlsForNote(row.redirectFromUrls),
105
- }, defaultCellFormat),
106
- createCellData({
107
- value: `${elementCount} Elements`,
108
- note: joinUrlsForNote(referrerDetails.map(formatReferrerNoteLine)),
109
- }, defaultCellFormat),
110
- createCellData({
111
- value: '{}',
112
- note: truncateNoteText(JSON.stringify(row.responseHeaders, null, 2)),
113
- }, defaultCellFormat),
114
- createCellData({ value: row.isSkipped ? row.skipReason || 'skipped' : '' }, defaultCellFormat),
115
- ]);
116
- sent++;
117
- onProgress(sent, total);
118
128
  }
119
- }
120
- await sheet.flush();
121
- },
122
- async updateSheet(sheet) {
123
- await sheet.frozen(2, 1);
124
- await sheet.conditionalFormat([sheet.getColNumByHeaderName('Status Code')], {
125
- booleanRule: {
126
- condition: {
127
- type: 'NUMBER_GREATER_THAN_EQ',
128
- values: [{ userEnteredValue: '400' }],
129
+ await sheet.flush();
130
+ },
131
+ async updateSheet(sheet) {
132
+ await sheet.frozen(2, 1);
133
+ await sheet.conditionalFormat([sheet.getColNumByHeaderName('Status Code')], {
134
+ booleanRule: {
135
+ condition: {
136
+ type: 'NUMBER_GREATER_THAN_EQ',
137
+ values: [{ userEnteredValue: '400' }],
138
+ },
139
+ format: booleanFormatError,
129
140
  },
130
- format: booleanFormatError,
131
- },
132
- });
133
- await sheet.conditionalFormat([sheet.getColNumByHeaderName('Status Code')], {
134
- booleanRule: {
135
- condition: {
136
- type: 'NUMBER_NOT_BETWEEN',
137
- values: [{ userEnteredValue: '200' }, { userEnteredValue: '399' }],
141
+ });
142
+ await sheet.conditionalFormat([sheet.getColNumByHeaderName('Status Code')], {
143
+ booleanRule: {
144
+ condition: {
145
+ type: 'NUMBER_NOT_BETWEEN',
146
+ values: [{ userEnteredValue: '200' }, { userEnteredValue: '399' }],
147
+ },
148
+ format: booleanFormatError,
138
149
  },
139
- format: booleanFormatError,
140
- },
141
- });
142
- log('Formatting applied');
143
- },
150
+ });
151
+ log('Formatting applied');
152
+ },
153
+ };
144
154
  };
145
- };
155
+ }
@@ -44,7 +44,20 @@ import type { CreateSheet } from '../sheets/types.js';
44
44
  * precomputed once, for every page, before the read model is queryable at
45
45
  * all (see `build-viewer-read-model.ts`), so every column is known
46
46
  * synchronously from the current row alone.
47
- * @param reports - Analyze plugin reports to extract per-page data columns from
48
- * @param accessor - The archive accessor to query.
47
+ * ## URL-restricted mode (`--urls`)
48
+ *
49
+ * `options.urls` (already normalized via `resolvePageListUrlFilter`)
50
+ * restricts every read below to exactly those pages — both
51
+ * `estimateRowCount` and `run` go through `countPageListRows`/
52
+ * `streamPageListRows`, the same shared filter (`applyPageListRowFilters`)
53
+ * that guarantees the two never disagree about which pages are in scope.
54
+ * @param options - Row-set restriction. Omitted or `urls: undefined` reports every page.
55
+ * @param options.urls - See "URL-restricted mode" above.
56
+ * @returns A {@link CreateSheet} factory for the Page List sheet.
57
+ * @example
58
+ * createSheetList.push(createPageList());
59
+ * createSheetList.push(createPageList({ urls: ['https://example.com/a'] }));
49
60
  */
50
- export declare const createPageList: CreateSheet;
61
+ export declare function createPageList(options?: {
62
+ urls?: readonly string[];
63
+ }): CreateSheet;