@podlite/schema 0.0.85 → 0.0.86

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.
@@ -3,14 +3,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CsvError = void 0;
6
7
  exports.parseCsv = parseCsv;
7
8
  exports.parseTsv = parseTsv;
9
+ exports.headerInEffect = headerInEffect;
8
10
  exports.parseMimeType = parseMimeType;
9
11
  exports.findDataBlockByKey = findDataBlockByKey;
10
12
  exports.extractDataText = extractDataText;
13
+ exports.detectSourceReference = detectSourceReference;
11
14
  exports.csvToTableContent = csvToTableContent;
12
15
  exports.makeTableReport = makeTableReport;
13
16
  exports.normalizeCellCounts = normalizeCellCounts;
17
+ exports.buildCodeFromText = buildCodeFromText;
18
+ exports.reportHeaderOf = reportHeaderOf;
19
+ exports.readTabular = readTabular;
14
20
  /**
15
21
  * Plugin for fill term's for defn. From S26:
16
22
  * The first non-blank line of content is treated as a term being defined,
@@ -23,14 +29,22 @@ const configPropagation_1 = require("./helpers/configPropagation");
23
29
  const code_config_1 = require("./helpers/code-config");
24
30
  const flatten_deep_1 = require("./helpers/flatten-deep");
25
31
  // ─── CSV source for =table (spec §1672) ────────────────────────────────────
26
- // Parse CSV content per RFC 4180: comma delimiter, `"`-quoted fields with
27
- // `""` as embedded-quote escape. Supports LF or CRLF line endings. Leading
28
- // indentation typical of =data block bodies is stripped from each line.
32
+ // Content that cannot be read as CSV. A table then shows the content as a code block.
33
+ class CsvError extends Error {
34
+ }
35
+ exports.CsvError = CsvError;
36
+ // Parse CSV content as the norm reads it: comma delimiter, `"`-quoted fields
37
+ // with `""` as embedded-quote escape, a line ends at LF with or without CR
38
+ // before it. No line is skipped and spaces belong to the field; a final LF
39
+ // starts no row, and empty content has no rows. A `"` inside an unquoted
40
+ // field, text after a closing quote, a CR outside quotes that does not end a
41
+ // line and a quote left open are not CSV.
29
42
  function parseCsv(text) {
30
43
  const rows = [];
31
44
  let field = '';
32
45
  let row = [];
33
46
  let inQuote = false;
47
+ let quoted = false;
34
48
  let i = 0;
35
49
  while (i < text.length) {
36
50
  const c = text[i];
@@ -42,6 +56,7 @@ function parseCsv(text) {
42
56
  }
43
57
  if (c === '"') {
44
58
  inQuote = false;
59
+ quoted = true;
45
60
  i++;
46
61
  continue;
47
62
  }
@@ -49,7 +64,10 @@ function parseCsv(text) {
49
64
  i++;
50
65
  continue;
51
66
  }
52
- if (c === '"' && field === '') {
67
+ if (c === '"') {
68
+ if (field !== '' || quoted) {
69
+ throw new CsvError(quoted ? `text after a closing quote at offset ${i}` : `a quote inside an unquoted field at offset ${i}`);
70
+ }
53
71
  inQuote = true;
54
72
  i++;
55
73
  continue;
@@ -57,10 +75,13 @@ function parseCsv(text) {
57
75
  if (c === ',') {
58
76
  row.push(field);
59
77
  field = '';
78
+ quoted = false;
60
79
  i++;
61
80
  continue;
62
81
  }
63
82
  if (c === '\r') {
83
+ if (text[i + 1] !== '\n')
84
+ throw new CsvError(`a carriage return outside quotes at offset ${i}`);
64
85
  i++;
65
86
  continue;
66
87
  }
@@ -69,26 +90,48 @@ function parseCsv(text) {
69
90
  rows.push(row);
70
91
  row = [];
71
92
  field = '';
93
+ quoted = false;
72
94
  i++;
73
95
  continue;
74
96
  }
97
+ if (quoted)
98
+ throw new CsvError(`text after a closing quote at offset ${i}`);
75
99
  field += c;
76
100
  i++;
77
101
  }
78
- if (field !== '' || row.length > 0) {
102
+ if (inQuote)
103
+ throw new CsvError('an unclosed quote');
104
+ // a quoted empty field at the very end is a record too
105
+ if (field !== '' || row.length > 0 || quoted) {
79
106
  row.push(field);
80
107
  rows.push(row);
81
108
  }
82
- // Drop rows that are entirely blank (empty content after trim).
83
- return rows.filter(r => !(r.length === 1 && r[0].trim() === ''));
109
+ return rows;
84
110
  }
85
111
  // Parse a TSV (tab-separated values) blob. Unlike CSV, TSV has no quoting
86
112
  // mechanism — fields are split strictly on tabs and `"` is a literal
87
- // character. Tabs and newlines inside fields are not representable in TSV.
113
+ // character. A line ends at LF, with or without CR before it; a CR elsewhere
114
+ // belongs to the field. No line is skipped, a final LF starts no row, and
115
+ // empty content has no rows.
88
116
  function parseTsv(text) {
89
- const lines = text.split(/\r?\n/);
90
- const rows = lines.map(line => line.split('\t'));
91
- return rows.filter(r => !(r.length === 1 && r[0].trim() === ''));
117
+ if (text === '')
118
+ return [];
119
+ const parts = text.split('\n');
120
+ const lines = parts.map((line, i) => (i < parts.length - 1 && line.endsWith('\r') ? line.slice(0, -1) : line));
121
+ if (text.endsWith('\n'))
122
+ lines.pop();
123
+ return lines.map(line => line.split('\t'));
124
+ }
125
+ // The `header` in force for CSV or TSV content: present or absent as written,
126
+ // present when the parameter is omitted. Any other value, an empty one as
127
+ // well, is an error, and the content is read with the default.
128
+ function headerInEffect(params) {
129
+ const written = params.header;
130
+ if (written === undefined || written === 'present')
131
+ return { present: true };
132
+ if (written === 'absent')
133
+ return { present: false };
134
+ return { present: true, error: `header=${written} is neither present nor absent` };
92
135
  }
93
136
  // Parse a MIME type value into the bare type and a map of parameters
94
137
  // (RFC 6838 / RFC 7231 §3.1.1.1). Used to recognise the `header` parameter
@@ -108,8 +151,11 @@ function parseMimeType(raw) {
108
151
  if (!p)
109
152
  continue;
110
153
  const eq = p.indexOf('=');
111
- if (eq < 0)
154
+ // a parameter written without a value is written all the same
155
+ if (eq < 0) {
156
+ params[p.toLowerCase()] = '';
112
157
  continue;
158
+ }
113
159
  const key = p.slice(0, eq).trim().toLowerCase();
114
160
  let value = p.slice(eq + 1).trim();
115
161
  if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
@@ -146,11 +192,14 @@ function findDataBlockByKey(tree, key) {
146
192
  walk(tree);
147
193
  return found;
148
194
  }
195
+ // the body of a data block as written: its verbatim text, or the copy kept once :allow read codes in it
149
196
  function extractDataText(dataNode) {
150
197
  if (!dataNode || !Array.isArray(dataNode.content))
151
198
  return '';
152
199
  const verbatim = dataNode.content.find(c => c && c.type === 'verbatim');
153
- return verbatim && typeof verbatim.value === 'string' ? verbatim.value : '';
200
+ if (verbatim && typeof verbatim.value === 'string')
201
+ return verbatim.value;
202
+ return typeof dataNode.dataText === 'string' ? dataNode.dataText : '';
154
203
  }
155
204
  // Detect whether the =table body is a single-line source reference like
156
205
  // `data:key` or `file:path` (spec §1672). Returns the parsed reference or
@@ -207,38 +256,43 @@ function buildRowBlock(cells, isHeader) {
207
256
  return block;
208
257
  }
209
258
  // Convert parsed CSV/TSV rows to plain `=row`/`=cell` blocks. When
210
- // `hasHeader` is true (signalled by the `header=present` MIME parameter on
211
- // the source `=data` block, per RFC 4180 §3), the first row is marked with
212
- // `:header`. Default behaviour leaves all rows unmarked, matching authors
213
- // who use a structured table with explicit `=begin row :header` or a
214
- // Markdown GFM table.
215
- function csvToTableContent(csvRows, hasHeader = false, allow = []) {
259
+ // `hasHeader` is true (the `header` in force, see headerInEffect), the first
260
+ // row is marked with `:header`. A cell keeps its field as read, spaces too.
261
+ function csvToTableContent(csvRows, hasHeader, allow = []) {
216
262
  return csvRows.map((row, i) => {
217
- const cells = row.map(v => buildCellBlock(v.trim(), allow));
263
+ const cells = row.map(v => buildCellBlock(v, allow));
218
264
  return buildRowBlock(cells, hasHeader && i === 0);
219
265
  });
220
266
  }
267
+ const keyOf = (message, offset) => `${offset} ${message}`;
221
268
  function makeTableReport(opt) {
222
269
  const diagnostics = opt && Array.isArray(opt.diagnostics) ? opt.diagnostics : null;
223
- return (code, message, node) => {
270
+ // the reports already in the list, by place and message, so that a table with
271
+ // many uneven rows does not search the whole list for each of them
272
+ const keys = new Set();
273
+ let counted = -1;
274
+ return (code, message, node, severity = 'warning') => {
224
275
  const location = node && node.location;
225
276
  if (!diagnostics || !location)
226
277
  return;
227
- const seen = diagnostics.some(d => d.message === message && d.location.start.offset === location.start.offset);
228
- if (!seen)
229
- diagnostics.push({ severity: 'warning', code, message, location });
278
+ if (counted !== diagnostics.length) {
279
+ keys.clear();
280
+ for (const d of diagnostics)
281
+ if (d && d.location)
282
+ keys.add(keyOf(d.message, d.location.start.offset));
283
+ }
284
+ const key = keyOf(message, location.start.offset);
285
+ // a key seen is confirmed against the list, which another hand may have changed
286
+ const seen = keys.has(key) && diagnostics.some(d => d.message === message && d.location.start.offset === location.start.offset);
287
+ if (!seen) {
288
+ diagnostics.push({ severity, code, message, location });
289
+ keys.add(key);
290
+ }
291
+ counted = diagnostics.length;
230
292
  };
231
293
  }
232
294
  const noReport = () => { };
233
- // Rule 2 — table-level cell count validation. Pad short rows with empty
234
- // cells; truncate long rows. Report whenever a row is changed.
235
- // Expected count is taken from the `:header` row if present, otherwise from
236
- // the row with the maximum cell count.
237
- //
238
- // Skipped when any cell uses `:colspan` or `:rowspan`: a spanning cell
239
- // occupies multiple columns, so naive cell counting would misreport row
240
- // width and drop legitimate spanned cells.
241
- function normalizeCellCounts(tableNode, source = 'table', report = noReport) {
295
+ function normalizeCellCounts(tableNode, source = 'table', report = noReport, mode = 'text') {
242
296
  if (!tableNode || !Array.isArray(tableNode.content))
243
297
  return tableNode;
244
298
  const rows = tableNode.content.filter(c => c && c.type === 'block' && c.name === 'row');
@@ -251,7 +305,9 @@ function normalizeCellCounts(tableNode, source = 'table', report = noReport) {
251
305
  if (rows.some(rowHasSpan))
252
306
  return tableNode;
253
307
  const headerRow = rows.find(isHeaderRow);
254
- const expected = headerRow ? cellsOf(headerRow).length : Math.max(...rows.map(r => cellsOf(r).length));
308
+ const expected = headerRow
309
+ ? cellsOf(headerRow).length
310
+ : rows.reduce((widest, r) => Math.max(widest, cellsOf(r).length), 0);
255
311
  if (expected === 0)
256
312
  return tableNode;
257
313
  let mutated = false;
@@ -268,7 +324,8 @@ function normalizeCellCounts(tableNode, source = 'table', report = noReport) {
268
324
  const padding = [];
269
325
  for (let i = cells.length; i < expected; i++)
270
326
  padding.push(buildCellBlock(''));
271
- report('table-row-cells', `${source} row ${rowNumber} has ${cells.length} of ${expected} cells, padded with ${padding.length} empty. A row continued on the next line needs a blank line before the next row`, tableNode);
327
+ report('table-row-cells', `${source} row ${rowNumber} has ${cells.length} of ${expected} cells, padded with ${padding.length} empty` +
328
+ (mode === 'text' ? '. A row continued on the next line needs a blank line before the next row' : ''), tableNode);
272
329
  mutated = true;
273
330
  return { ...child, content: [...child.content, ...padding] };
274
331
  }
@@ -316,18 +373,45 @@ function detectMixedSeparators(lines, report = noReport, node = null) {
316
373
  report('table-mixed-separators', `table mixes separator styles: ${Array.from(seen).join(', ')}. Keep one`, node);
317
374
  }
318
375
  }
319
- // Rule 4 — replace =table with =code block. Used when a referenced =data
320
- // source has a non-CSV mime type: the spec mandates the source be rendered
321
- // as a code block so the user can still see the underlying content.
322
- function buildCodeFromDataBlock(tableNode, dataBlock) {
376
+ // Content that is not CSV, or not tabular at all, is shown as it is written: a code block in place of
377
+ // the table that read it, keeping the settings of the table, :masked among them,
378
+ // but turned into markup by no :allow of the table or of =config code, since an
379
+ // empty :allow of its own decides first.
380
+ function buildCodeFromText(tableNode, text) {
381
+ const own = (Array.isArray(tableNode.config) ? tableNode.config : []).filter(c => c && c.name !== 'allow');
323
382
  return {
324
383
  type: 'block',
325
384
  name: 'code',
326
385
  margin: tableNode.margin || '',
327
- content: Array.isArray(dataBlock.content) ? dataBlock.content : [],
328
- config: Array.isArray(tableNode.config) ? tableNode.config : [],
386
+ location: tableNode.location,
387
+ content: [{ type: 'verbatim', value: text }],
388
+ config: [...own, { name: 'allow', value: [], type: 'array' }],
329
389
  };
330
390
  }
391
+ // A wrong `header` is an error of the block it is written on, reported there
392
+ // once, whether or not a table reads the block.
393
+ function reportHeaderOf(type, params, where, node, report) {
394
+ if (type !== 'text/csv' && type !== 'text/tab-separated-values')
395
+ return;
396
+ const header = headerInEffect(params);
397
+ if (header.error)
398
+ report('table-header-invalid', `${where}: ${header.error}, read as header=present`, node, 'error');
399
+ }
400
+ // Reads CSV or TSV content for a table with the `header` in force; content that
401
+ // is not CSV comes back as null with its warning reported, so the caller shows
402
+ // it as code.
403
+ function readTabular(isCsv, params, text, where, node, report) {
404
+ const header = headerInEffect(params);
405
+ try {
406
+ return { rows: isCsv ? parseCsv(text) : parseTsv(text), hasHeader: header.present };
407
+ }
408
+ catch (e) {
409
+ if (!(e instanceof CsvError))
410
+ throw e;
411
+ report('table-source-not-csv', `${where} is not CSV (${e.message}), rendered as =code`, node);
412
+ return null;
413
+ }
414
+ }
331
415
  // ─── Markup codes closed on their line (spec §Tables) ──────────────────────
332
416
  // The codes a cell of this table reads, by the scope at the table: the :allow of
333
417
  // a cell, else of a row, else of the table, else every code; the codes read
@@ -583,10 +667,36 @@ exports.default = (opt = {}) => tree => {
583
667
  const report = makeTableReport(opt);
584
668
  // the settings in force where each table stands, as a cell of it will read them
585
669
  const scopes = new Map();
670
+ // a =data block read here has not yet been given what a =config sets on it,
671
+ // and a :masked set so must cover what is built out of it all the same
672
+ const dataScopes = new Map();
586
673
  (0, configPropagation_1.walkConfigScopes)(tree, opt.config || {}, (block, scope) => {
587
674
  if (block.name === 'table')
588
675
  scopes.set(block, { ...scope });
676
+ if (block.name === 'data')
677
+ dataScopes.set(block, { ...scope });
589
678
  });
679
+ // the format of a =data block: its own, one =set gave it, or one =config data gives it
680
+ const mimeOfData = dataBlock => {
681
+ const own = (0, config_1.default)(dataBlock, {});
682
+ if (own.exists('mime-type'))
683
+ return own.getFirstValue('mime-type');
684
+ return (0, config_1.default)({ config: (dataScopes.get(dataBlock) || {}).data || [] }, {}).getFirstValue('mime-type');
685
+ };
686
+ // the header of every =data block, the one a =config gives it as well
687
+ for (const dataBlock of dataScopes.keys()) {
688
+ const own = (0, config_1.default)(dataBlock, {});
689
+ const { type, params } = parseMimeType(mimeOfData(dataBlock));
690
+ const key = own.getFirstValue('key');
691
+ reportHeaderOf(type, params, key ? `=data :key<${key}>` : '=data', dataBlock, report);
692
+ }
693
+ const isMaskedData = dataBlock => {
694
+ const own = (0, config_1.default)(dataBlock, {});
695
+ if (own.exists('masked'))
696
+ return Boolean(own.getFirstValue('masked'));
697
+ const given = (0, config_1.default)({ config: (dataScopes.get(dataBlock) || {}).data || [] }, {});
698
+ return Boolean(given.getFirstValue('masked'));
699
+ };
590
700
  const transformer = (0, makeTransformer_1.default)({
591
701
  table: (node, ctx, visiter) => {
592
702
  // CSV/data source reference (spec §1672):
@@ -607,26 +717,28 @@ exports.default = (opt = {}) => tree => {
607
717
  }
608
718
  // whatever is built out of a covered =data block is covered as well,
609
719
  // otherwise the table is a way to read what the cover hides
610
- const carryCover = built => (0, config_1.default)(dataBlock, {}).getFirstValue('masked') ? { ...built, guarded: true } : built;
611
- const rawMime = (0, config_1.default)(dataBlock, {}).getFirstValue('mime-type');
720
+ const carryCover = built => (isMaskedData(dataBlock) ? { ...built, guarded: true } : built);
721
+ const rawMime = mimeOfData(dataBlock);
612
722
  const { type: mimeType, params: mimeParams } = parseMimeType(rawMime);
613
723
  const isCsv = mimeType === 'text/csv';
614
724
  const isTsv = mimeType === 'text/tab-separated-values';
615
725
  if (isCsv || isTsv) {
616
726
  const text = extractDataText(dataBlock);
617
- const rows = isCsv ? parseCsv(text) : parseTsv(text);
727
+ const read = readTabular(isCsv, mimeParams, text, `data:${ref.target}`, node, report);
728
+ if (!read)
729
+ return carryCover(buildCodeFromText(node, text));
730
+ const { rows, hasHeader } = read;
618
731
  if (rows.length === 0) {
619
732
  report('table-source-empty', `${isCsv ? 'CSV' : 'TSV'} source data:${ref.target} has no rows, table rendered as empty`, node);
620
733
  return { ...node, content: [] };
621
734
  }
622
- const hasHeader = mimeParams.header === 'present';
623
735
  const allow = (0, config_1.default)(node, {}).getAllValues('allow');
624
736
  const filledNode = { ...node, content: csvToTableContent(rows, hasHeader, allow) };
625
- return carryCover(normalizeCellCounts(filledNode, `table data:${ref.target}`, report));
737
+ return carryCover(normalizeCellCounts(filledNode, `table data:${ref.target}`, report, 'data'));
626
738
  }
627
739
  // Rule 4: source not tabular → render as code block so content remains visible
628
740
  report('table-source-unreadable', `=data :key<${ref.target}> has non-tabular mime-type ${rawMime || '(none)'}, rendered as =code`, node);
629
- return carryCover(buildCodeFromDataBlock(node, dataBlock));
741
+ return carryCover(buildCodeFromText(node, extractDataText(dataBlock)));
630
742
  }
631
743
  // structured mode: transform row children (wrap implicit cells), then
632
744
  // apply Rule 2 cell count normalization.
@@ -640,7 +752,7 @@ exports.default = (opt = {}) => tree => {
640
752
  // a matched rule replaces the node without descending, so recurse
641
753
  // here or tables nested inside cells keep their raw text rows
642
754
  const recursed = visiter ? visiter(transformedContent, ctx) : transformedContent;
643
- return normalizeCellCounts({ ...attached, content: recursed }, 'table', report);
755
+ return normalizeCellCounts({ ...attached, content: recursed }, 'table', report, 'row');
644
756
  }
645
757
  const ownScope = scopes.get(node) || {};
646
758
  node = { ...node, content: groupRows(node.content || []) };
@@ -731,7 +843,7 @@ exports.default = (opt = {}) => tree => {
731
843
  },
732
844
  'head:text': head => makeHeaderRow(splitToCells(head.value).map(makeCell)),
733
845
  })(node);
734
- return normalizeCellCounts(res, 'table', report);
846
+ return normalizeCellCounts(res, 'table', report, 'text');
735
847
  },
736
848
  });
737
849
  return transformer(tree, {});
@@ -36,6 +36,7 @@ export type ValueSpec = {
36
36
  kind: 'in';
37
37
  value: string;
38
38
  };
39
+ export declare const dataKeysOfSelector: (selector: string) => string[];
39
40
  export declare const parseSelector: (selector: string) => ParsedSelector | undefined;
40
41
  export declare const readSelector: (selector: string) => ParsedSelector;
41
42
  export declare const outermost: (blocks: PodNode[]) => PodNode[];
package/lib/selectors.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runSelector = exports.SelectorError = exports.getDocIDs = exports.filePathMatches = exports.outermost = exports.readSelector = exports.parseSelector = void 0;
3
+ exports.runSelector = exports.SelectorError = exports.getDocIDs = exports.filePathMatches = exports.outermost = exports.readSelector = exports.parseSelector = exports.dataKeysOfSelector = void 0;
4
4
  const index_1 = require("./index");
5
5
  const parseAttributes_1 = require("./helpers/parseAttributes");
6
6
  const blockName_1 = require("./helpers/blockName");
@@ -137,6 +137,28 @@ const readInOperand = (operands) => {
137
137
  return undefined;
138
138
  return { selector };
139
139
  };
140
+ // The keys of =data blocks a selector reads through `in data:KEY`, at any depth of
141
+ // nested selectors; a literal such as `in 'data:k'` reads no block.
142
+ const dataKeysOfSelector = (selector) => {
143
+ const keys = [];
144
+ const walk = (parsed) => {
145
+ for (const pattern of parsed ? parsed.patterns : [])
146
+ for (const condition of pattern.predicate || []) {
147
+ if (!condition.valueSpec || condition.valueSpec.kind !== 'in')
148
+ continue;
149
+ const operand = readInOperand(condition.valueSpec.value);
150
+ if (!operand || !('selector' in operand))
151
+ continue;
152
+ if (operand.selector.scheme === 'data' && operand.selector.document)
153
+ keys.push(operand.selector.document);
154
+ else
155
+ walk(operand.selector);
156
+ }
157
+ };
158
+ walk((0, exports.parseSelector)(selector));
159
+ return keys;
160
+ };
161
+ exports.dataKeysOfSelector = dataKeysOfSelector;
140
162
  // What follows the opening parenthesis is a value when the declaration grammar
141
163
  // reads it as one, and otherwise the name of an operation.
142
164
  const parenCondition = (modifier, attrName, inner) => {
@@ -648,10 +670,22 @@ const dataValues = (key, address, home) => {
648
670
  throw new SelectorError('format', `the data block ${key} declares no :mime-type: ${source}`);
649
671
  const { type, params } = (0, plugin_tables_1.parseMimeType)(String(mime));
650
672
  const text = (0, plugin_tables_1.extractDataText)(block);
651
- const rows = type === 'text/csv' ? (0, plugin_tables_1.parseCsv)(text) : type === 'text/tab-separated-values' ? (0, plugin_tables_1.parseTsv)(text) : undefined;
652
- if (!rows)
673
+ if (type !== 'text/csv' && type !== 'text/tab-separated-values')
653
674
  throw new SelectorError('address', `${type} content has no columns: ${source}`);
654
- const header = params.header === 'present';
675
+ // a header the norm does not know is an error of the format, not an empty column
676
+ const inEffect = (0, plugin_tables_1.headerInEffect)(params);
677
+ if (inEffect.error)
678
+ throw new SelectorError('format', `the data block ${key}: ${inEffect.error}: ${source}`);
679
+ let rows;
680
+ try {
681
+ rows = type === 'text/csv' ? (0, plugin_tables_1.parseCsv)(text) : (0, plugin_tables_1.parseTsv)(text);
682
+ }
683
+ catch (e) {
684
+ if (e instanceof plugin_tables_1.CsvError)
685
+ throw new SelectorError('format', `the data block ${key} is not CSV (${e.message}): ${source}`);
686
+ throw e;
687
+ }
688
+ const header = inEffect.present;
655
689
  const body = header ? rows.slice(1) : rows;
656
690
  let column = 0;
657
691
  if (address) {
package/lib/types.d.ts CHANGED
@@ -147,8 +147,8 @@ export interface RootBlock extends Omit<Block, 'location'> {
147
147
  diagnostics?: Array<ParseDiagnostic>;
148
148
  }
149
149
  export interface ParseDiagnostic {
150
- severity: 'warning';
151
- code: 'value-unreadable' | 'directive-unreadable' | 'table-row-cells' | 'table-cell-outside-row' | 'table-mixed-separators' | 'table-source-unreadable' | 'table-source-empty' | 'table-source-deferred' | 'markup-code-unclosed' | 'markup-code-longer-run' | 'markup-code-foreign-closer' | 'markup-code-reserved' | 'markup-code-unsupported' | 'markup-code-unreadable' | 'markup-code-too-deep' | 'list-too-deep';
150
+ severity: 'warning' | 'error';
151
+ code: 'value-unreadable' | 'directive-unreadable' | 'table-row-cells' | 'table-cell-outside-row' | 'table-mixed-separators' | 'table-source-unreadable' | 'table-source-empty' | 'table-source-deferred' | 'table-source-not-csv' | 'table-source-conflict' | 'table-header-invalid' | 'markup-code-unclosed' | 'markup-code-longer-run' | 'markup-code-foreign-closer' | 'markup-code-reserved' | 'markup-code-unsupported' | 'markup-code-unreadable' | 'markup-code-too-deep' | 'list-too-deep';
152
152
  message: string;
153
153
  location: Location;
154
154
  }
@@ -374,6 +374,7 @@ export interface BlockPod extends Block {
374
374
  }
375
375
  export interface BlockData extends Block {
376
376
  name: 'data';
377
+ dataText?: string;
377
378
  }
378
379
  export interface BlockComment extends Block {
379
380
  name: 'comment';
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "0.0.85";
1
+ export declare const version = "0.0.86";
package/lib/version.js CHANGED
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
4
  // generated by scripts/inject-version.mjs — do not edit by hand
5
- exports.version = '0.0.85';
5
+ exports.version = '0.0.86';
6
6
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@podlite/schema",
3
- "version": "0.0.85",
3
+ "version": "0.0.86",
4
4
  "description": "Parser and AST schema for Podlite: typed blocks with positions, selectors, validate, traverse, and transform.",
5
5
  "main": "./lib/index.js",
6
6
  "sideEffects": false,
@@ -465,6 +465,9 @@
465
465
  "type": "string",
466
466
  "const": "data"
467
467
  },
468
+ "dataText": {
469
+ "type": "string"
470
+ },
468
471
  "type": {
469
472
  "type": "string",
470
473
  "const": "block"
@@ -2148,8 +2151,11 @@
2148
2151
  "type": "object",
2149
2152
  "properties": {
2150
2153
  "severity": {
2151
- "type": "string",
2152
- "const": "warning"
2154
+ "enum": [
2155
+ "error",
2156
+ "warning"
2157
+ ],
2158
+ "type": "string"
2153
2159
  },
2154
2160
  "code": {
2155
2161
  "enum": [
@@ -2163,10 +2169,13 @@
2163
2169
  "markup-code-unreadable",
2164
2170
  "markup-code-unsupported",
2165
2171
  "table-cell-outside-row",
2172
+ "table-header-invalid",
2166
2173
  "table-mixed-separators",
2167
2174
  "table-row-cells",
2175
+ "table-source-conflict",
2168
2176
  "table-source-deferred",
2169
2177
  "table-source-empty",
2178
+ "table-source-not-csv",
2170
2179
  "table-source-unreadable",
2171
2180
  "value-unreadable"
2172
2181
  ],
@@ -465,6 +465,9 @@
465
465
  "type": "string",
466
466
  "const": "data"
467
467
  },
468
+ "dataText": {
469
+ "type": "string"
470
+ },
468
471
  "type": {
469
472
  "type": "string",
470
473
  "const": "block"
@@ -2148,8 +2151,11 @@
2148
2151
  "type": "object",
2149
2152
  "properties": {
2150
2153
  "severity": {
2151
- "type": "string",
2152
- "const": "warning"
2154
+ "enum": [
2155
+ "error",
2156
+ "warning"
2157
+ ],
2158
+ "type": "string"
2153
2159
  },
2154
2160
  "code": {
2155
2161
  "enum": [
@@ -2163,10 +2169,13 @@
2163
2169
  "markup-code-unreadable",
2164
2170
  "markup-code-unsupported",
2165
2171
  "table-cell-outside-row",
2172
+ "table-header-invalid",
2166
2173
  "table-mixed-separators",
2167
2174
  "table-row-cells",
2175
+ "table-source-conflict",
2168
2176
  "table-source-deferred",
2169
2177
  "table-source-empty",
2178
+ "table-source-not-csv",
2170
2179
  "table-source-unreadable",
2171
2180
  "value-unreadable"
2172
2181
  ],