@lightdash/common 2.415.8 → 2.417.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/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/ee/AiAgent/schemas/tools/mcpDocumentContent.d.ts +244 -288
- package/dist/cjs/ee/AiAgent/schemas/tools/mcpDocumentContent.d.ts.map +1 -1
- package/dist/cjs/ee/AiAgent/schemas/tools/mcpDocumentContent.js +19 -24
- package/dist/cjs/ee/AiAgent/schemas/tools/mcpDocumentContent.js.map +1 -1
- package/dist/cjs/ee/AiAgent/schemas/tools/toolDefinitions.d.ts +238 -274
- package/dist/cjs/ee/AiAgent/schemas/tools/toolDefinitions.d.ts.map +1 -1
- package/dist/cjs/ee/AiAgent/schemas/tools/toolDefinitions.js +3 -3
- package/dist/cjs/ee/AiAgent/schemas/tools/toolDefinitions.js.map +1 -1
- package/dist/cjs/ee/AiAgent/schemas/tools/toolReadContentArgs.js +1 -1
- package/dist/cjs/ee/externalConnections/types.d.ts +2 -2
- package/dist/cjs/ee/externalConnections/types.d.ts.map +1 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/document.d.ts +16 -18
- package/dist/cjs/types/document.d.ts.map +1 -1
- package/dist/cjs/utils/document.d.ts +5 -1
- package/dist/cjs/utils/document.d.ts.map +1 -1
- package/dist/cjs/utils/document.js +56 -77
- package/dist/cjs/utils/document.js.map +1 -1
- package/dist/cjs/utils/documentMarkdown.d.ts +65 -0
- package/dist/cjs/utils/documentMarkdown.d.ts.map +1 -0
- package/dist/cjs/utils/documentMarkdown.js +221 -0
- package/dist/cjs/utils/documentMarkdown.js.map +1 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/ee/AiAgent/schemas/tools/mcpDocumentContent.d.ts +244 -288
- package/dist/esm/ee/AiAgent/schemas/tools/mcpDocumentContent.d.ts.map +1 -1
- package/dist/esm/ee/AiAgent/schemas/tools/mcpDocumentContent.js +18 -23
- package/dist/esm/ee/AiAgent/schemas/tools/mcpDocumentContent.js.map +1 -1
- package/dist/esm/ee/AiAgent/schemas/tools/toolDefinitions.d.ts +238 -274
- package/dist/esm/ee/AiAgent/schemas/tools/toolDefinitions.d.ts.map +1 -1
- package/dist/esm/ee/AiAgent/schemas/tools/toolDefinitions.js +3 -3
- package/dist/esm/ee/AiAgent/schemas/tools/toolDefinitions.js.map +1 -1
- package/dist/esm/ee/AiAgent/schemas/tools/toolReadContentArgs.js +1 -1
- package/dist/esm/ee/externalConnections/types.d.ts +2 -2
- package/dist/esm/ee/externalConnections/types.d.ts.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/document.d.ts +16 -18
- package/dist/esm/types/document.d.ts.map +1 -1
- package/dist/esm/utils/document.d.ts +5 -1
- package/dist/esm/utils/document.d.ts.map +1 -1
- package/dist/esm/utils/document.js +56 -77
- package/dist/esm/utils/document.js.map +1 -1
- package/dist/esm/utils/documentMarkdown.d.ts +65 -0
- package/dist/esm/utils/documentMarkdown.d.ts.map +1 -0
- package/dist/esm/utils/documentMarkdown.js +206 -0
- package/dist/esm/utils/documentMarkdown.js.map +1 -0
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/ee/AiAgent/schemas/tools/mcpDocumentContent.d.ts +244 -288
- package/dist/types/ee/AiAgent/schemas/tools/mcpDocumentContent.d.ts.map +1 -1
- package/dist/types/ee/AiAgent/schemas/tools/mcpDocumentContent.js +18 -23
- package/dist/types/ee/AiAgent/schemas/tools/mcpDocumentContent.js.map +1 -1
- package/dist/types/ee/AiAgent/schemas/tools/toolDefinitions.d.ts +238 -274
- package/dist/types/ee/AiAgent/schemas/tools/toolDefinitions.d.ts.map +1 -1
- package/dist/types/ee/AiAgent/schemas/tools/toolDefinitions.js +3 -3
- package/dist/types/ee/AiAgent/schemas/tools/toolDefinitions.js.map +1 -1
- package/dist/types/ee/AiAgent/schemas/tools/toolReadContentArgs.js +1 -1
- package/dist/types/ee/externalConnections/types.d.ts +2 -2
- package/dist/types/ee/externalConnections/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/types/document.d.ts +16 -18
- package/dist/types/types/document.d.ts.map +1 -1
- package/dist/types/utils/document.d.ts +5 -1
- package/dist/types/utils/document.d.ts.map +1 -1
- package/dist/types/utils/document.js +56 -77
- package/dist/types/utils/document.js.map +1 -1
- package/dist/types/utils/documentMarkdown.d.ts +65 -0
- package/dist/types/utils/documentMarkdown.d.ts.map +1 -0
- package/dist/types/utils/documentMarkdown.js +206 -0
- package/dist/types/utils/documentMarkdown.js.map +1 -0
- package/package.json +1 -1
|
@@ -4,7 +4,8 @@ import chartAsCodeSchema from '../schemas/json/chart-as-code-1.0.json';
|
|
|
4
4
|
import { ParameterError } from '../types/errors';
|
|
5
5
|
import { parseSavedMergeQuery } from '../types/mergeQuery';
|
|
6
6
|
import { ChartType } from '../types/savedCharts';
|
|
7
|
-
|
|
7
|
+
import { fromDocumentChartBlocks, getDocumentChartBlocks, } from './documentMarkdown';
|
|
8
|
+
export const DOCUMENT_SCHEMA_VERSION = 2;
|
|
8
9
|
export const getDocumentUrl = (projectUuidOrSlug, documentUuidOrSlug, documentSlug) => `/projects/${encodeURIComponent(projectUuidOrSlug)}/documents/${encodeURIComponent(documentSlug && !isUuid(documentSlug)
|
|
9
10
|
? documentSlug
|
|
10
11
|
: documentUuidOrSlug)}`;
|
|
@@ -42,57 +43,55 @@ const createValidator = () => new Ajv({
|
|
|
42
43
|
$defs: chartAsCodeSchema.$defs,
|
|
43
44
|
type: 'object',
|
|
44
45
|
additionalProperties: false,
|
|
45
|
-
required: ['
|
|
46
|
+
required: ['markdown', 'charts'],
|
|
46
47
|
properties: {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
{
|
|
59
|
-
properties: {
|
|
60
|
-
type: { const: 'markdown' },
|
|
61
|
-
content: {
|
|
62
|
-
type: 'object',
|
|
63
|
-
additionalProperties: false,
|
|
64
|
-
required: ['markdown'],
|
|
65
|
-
properties: {
|
|
66
|
-
markdown: { type: 'string' },
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
},
|
|
48
|
+
markdown: { type: 'string' },
|
|
49
|
+
charts: {
|
|
50
|
+
type: 'object',
|
|
51
|
+
additionalProperties: {
|
|
52
|
+
oneOf: [false, true].map((merge) => ({
|
|
53
|
+
type: 'object',
|
|
54
|
+
additionalProperties: false,
|
|
55
|
+
required: ['source', 'chart'],
|
|
56
|
+
properties: {
|
|
57
|
+
source: { const: merge ? 'merge' : 'semantic' },
|
|
58
|
+
chart: chartSchema(merge),
|
|
70
59
|
},
|
|
71
|
-
|
|
72
|
-
properties: {
|
|
73
|
-
type: { const: 'chart' },
|
|
74
|
-
content: {
|
|
75
|
-
oneOf: [false, true].map((merge) => ({
|
|
76
|
-
type: 'object',
|
|
77
|
-
additionalProperties: false,
|
|
78
|
-
required: ['source', 'chart'],
|
|
79
|
-
properties: {
|
|
80
|
-
source: {
|
|
81
|
-
const: merge
|
|
82
|
-
? 'merge'
|
|
83
|
-
: 'semantic',
|
|
84
|
-
},
|
|
85
|
-
chart: chartSchema(merge),
|
|
86
|
-
},
|
|
87
|
-
})),
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
],
|
|
60
|
+
})),
|
|
92
61
|
},
|
|
93
62
|
},
|
|
94
63
|
},
|
|
95
64
|
});
|
|
65
|
+
const validateChart = (id, content) => {
|
|
66
|
+
const { chart } = content;
|
|
67
|
+
const queries = [
|
|
68
|
+
chart.metricQuery,
|
|
69
|
+
...(content.source === 'merge'
|
|
70
|
+
? content.chart.merge.sources
|
|
71
|
+
.filter((source) => source.kind === 'query')
|
|
72
|
+
.map((source) => source.metricQuery)
|
|
73
|
+
: []),
|
|
74
|
+
];
|
|
75
|
+
if (queries.some((query) => ['queryUuid', 'results', 'rows'].some((key) => key in query))) {
|
|
76
|
+
throw new ParameterError('Document charts must contain durable queries, not query UUIDs or results');
|
|
77
|
+
}
|
|
78
|
+
if (chart.chartConfig.type === ChartType.DATA_APP_VIZ &&
|
|
79
|
+
chart.chartConfig.config === undefined) {
|
|
80
|
+
throw new ParameterError(`Custom chart "${id}" must reference a chart type`);
|
|
81
|
+
}
|
|
82
|
+
if (content.source === 'merge') {
|
|
83
|
+
const { merge } = content.chart;
|
|
84
|
+
if (merge.sources.some((source) => 'queryUuid' in source) ||
|
|
85
|
+
merge.sources.length !== 2 ||
|
|
86
|
+
!parseSavedMergeQuery(merge)) {
|
|
87
|
+
throw new ParameterError(`Invalid merge sources or join keys in chart "${id}"`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Validate Document content and return its canonical form: chart tags carry
|
|
93
|
+
* only their id and charts that are not placed in the markdown are dropped.
|
|
94
|
+
*/
|
|
96
95
|
export const parseDocumentContent = (schemaVersion, raw) => {
|
|
97
96
|
if (schemaVersion !== DOCUMENT_SCHEMA_VERSION) {
|
|
98
97
|
throw new ParameterError(`Unsupported Document schema version: ${schemaVersion}`);
|
|
@@ -101,36 +100,12 @@ export const parseDocumentContent = (schemaVersion, raw) => {
|
|
|
101
100
|
if (!contentValidator(raw)) {
|
|
102
101
|
throw new ParameterError(`Invalid Document content: ${contentValidator.errors?.map((error) => `${error.instancePath} ${error.message}`).join('; ')}`);
|
|
103
102
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const { chart } = cell.content;
|
|
109
|
-
const queries = [
|
|
110
|
-
chart.metricQuery,
|
|
111
|
-
...(cell.content.source === 'merge'
|
|
112
|
-
? cell.content.chart.merge.sources
|
|
113
|
-
.filter((source) => source.kind === 'query')
|
|
114
|
-
.map((source) => source.metricQuery)
|
|
115
|
-
: []),
|
|
116
|
-
];
|
|
117
|
-
if (queries.some((query) => ['queryUuid', 'results', 'rows'].some((key) => key in query))) {
|
|
118
|
-
throw new ParameterError('Document charts must contain durable queries, not query UUIDs or results');
|
|
119
|
-
}
|
|
120
|
-
if (chart.chartConfig.type === ChartType.DATA_APP_VIZ &&
|
|
121
|
-
chart.chartConfig.config === undefined) {
|
|
122
|
-
throw new ParameterError(`Custom chart in cell ${cellIndex} must reference a chart type`);
|
|
123
|
-
}
|
|
124
|
-
if (cell.content.source === 'merge') {
|
|
125
|
-
const { merge } = cell.content.chart;
|
|
126
|
-
if (merge.sources.some((source) => 'queryUuid' in source) ||
|
|
127
|
-
merge.sources.length !== 2 ||
|
|
128
|
-
!parseSavedMergeQuery(merge)) {
|
|
129
|
-
throw new ParameterError(`Invalid merge sources or join keys in cell ${cellIndex}`);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
103
|
+
const blocks = getDocumentChartBlocks(raw);
|
|
104
|
+
blocks.forEach((block) => {
|
|
105
|
+
if (block.type === 'chart')
|
|
106
|
+
validateChart(block.id, block.chart);
|
|
132
107
|
});
|
|
133
|
-
return
|
|
108
|
+
return fromDocumentChartBlocks(blocks);
|
|
134
109
|
};
|
|
135
110
|
const DOCUMENT_AS_CODE_KEYS = [
|
|
136
111
|
'name',
|
|
@@ -138,7 +113,8 @@ const DOCUMENT_AS_CODE_KEYS = [
|
|
|
138
113
|
'description',
|
|
139
114
|
'spaceSlug',
|
|
140
115
|
'schemaVersion',
|
|
141
|
-
'
|
|
116
|
+
'markdown',
|
|
117
|
+
'charts',
|
|
142
118
|
];
|
|
143
119
|
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
144
120
|
const isNonBlankString = (value) => typeof value === 'string' && value.trim() !== '';
|
|
@@ -169,7 +145,10 @@ export const parseDocumentAsCode = (raw) => {
|
|
|
169
145
|
description,
|
|
170
146
|
spaceSlug,
|
|
171
147
|
schemaVersion,
|
|
172
|
-
|
|
148
|
+
...parseDocumentContent(schemaVersion, {
|
|
149
|
+
markdown: raw.markdown,
|
|
150
|
+
charts: raw.charts ?? {},
|
|
151
|
+
}),
|
|
173
152
|
};
|
|
174
153
|
};
|
|
175
154
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document.js","sourceRoot":"","sources":["../../../src/utils/document.ts"],"names":[],"mappings":"AAAA,OAAO,GAA8B,MAAM,KAAK,CAAC;AACjD,OAAO,EAAE,QAAQ,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAC1C,OAAO,iBAAiB,MAAM,wCAAwC,CAAC;
|
|
1
|
+
{"version":3,"file":"document.js","sourceRoot":"","sources":["../../../src/utils/document.ts"],"names":[],"mappings":"AAAA,OAAO,GAA8B,MAAM,KAAK,CAAC;AACjD,OAAO,EAAE,QAAQ,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAC1C,OAAO,iBAAiB,MAAM,wCAAwC,CAAC;AAQvE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAoB,MAAM,sBAAsB,CAAC;AACnE,OAAO,EACH,uBAAuB,EACvB,sBAAsB,GACzB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC;AAEzC,MAAM,CAAC,MAAM,cAAc,GAAG,CAC1B,iBAA6B,EAC7B,kBAA8B,EAC9B,YAAqB,EACf,EAAE,CACR,aAAa,kBAAkB,CAAC,iBAAiB,CAAC,cAAc,kBAAkB,CAC9E,YAAY,IAAI,CAAC,M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AAW,CAAC,MAAM,CAAC;IACzE,OAAO;QACH,IAAI,EAAE,SAAS,CAAC,YAAY;QAC5B,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,cAAc,EAAE;KACxC,CAAC;AACN,CAAC,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { DocumentChartContent, DocumentContent } from '../types/document';
|
|
2
|
+
/**
|
|
3
|
+
* Document markdown places charts and other references as block tags: an
|
|
4
|
+
* HTML-like tag alone on an unindented line, outside code fences, e.g.
|
|
5
|
+
* `<document-chart id="c1">`.
|
|
6
|
+
*/
|
|
7
|
+
export type DocumentTag = {
|
|
8
|
+
name: string;
|
|
9
|
+
attributes: Record<string, string>;
|
|
10
|
+
};
|
|
11
|
+
export type DocumentBlock = {
|
|
12
|
+
type: 'markdown';
|
|
13
|
+
markdown: string;
|
|
14
|
+
} | {
|
|
15
|
+
type: 'tag';
|
|
16
|
+
tag: DocumentTag;
|
|
17
|
+
};
|
|
18
|
+
export declare const DOCUMENT_CHART_TAG = "document-chart";
|
|
19
|
+
export declare const parseDocumentBlocks: (markdown: string, tagNames: readonly string[]) => DocumentBlock[];
|
|
20
|
+
export declare const formatDocumentTag: ({ name, attributes }: DocumentTag) => string;
|
|
21
|
+
export declare const joinDocumentBlocks: (blocks: DocumentBlock[]) => string;
|
|
22
|
+
export declare const getDocumentChartTag: (id: string) => string;
|
|
23
|
+
/** The number of a stored chart id (`c3` → 3), or undefined for a temporary key. */
|
|
24
|
+
export declare const getDocumentChartNumber: (id: string) => number | undefined;
|
|
25
|
+
export type DocumentChartBlock = {
|
|
26
|
+
type: 'markdown';
|
|
27
|
+
markdown: string;
|
|
28
|
+
} | {
|
|
29
|
+
type: 'chart';
|
|
30
|
+
id: string;
|
|
31
|
+
chart: DocumentChartContent;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* The Document in reading order. Chart tags must reference an entry in
|
|
35
|
+
* `charts`, once each; other tags stay markdown.
|
|
36
|
+
*/
|
|
37
|
+
export declare const getDocumentChartBlocks: (content: DocumentContent) => DocumentChartBlock[];
|
|
38
|
+
/** Canonical content: chart tags carry only their id, unplaced charts are dropped. */
|
|
39
|
+
export declare const fromDocumentChartBlocks: (blocks: DocumentChartBlock[]) => DocumentContent;
|
|
40
|
+
export declare const mapDocumentCharts: (content: DocumentContent, map: (chart: DocumentChartContent, id: string) => DocumentChartContent) => DocumentContent;
|
|
41
|
+
/**
|
|
42
|
+
* Replace temporary chart keys with stored ids. Keys already shaped like
|
|
43
|
+
* `c<n>` are kept; the others get the next free numbers in reading order, so
|
|
44
|
+
* an id is never handed out twice for one Document.
|
|
45
|
+
*/
|
|
46
|
+
export declare const assignDocumentChartIds: (content: DocumentContent, nextChartNumber: number) => {
|
|
47
|
+
content: DocumentContent;
|
|
48
|
+
nextChartNumber: number;
|
|
49
|
+
};
|
|
50
|
+
export declare const getDocumentChartList: (content: DocumentContent) => Array<{
|
|
51
|
+
id: string;
|
|
52
|
+
chart: DocumentChartContent;
|
|
53
|
+
}>;
|
|
54
|
+
/**
|
|
55
|
+
* The Document with each chart tag expanded into a short description (id,
|
|
56
|
+
* title, type, explore), for readers that should not receive full charts.
|
|
57
|
+
*/
|
|
58
|
+
export declare const getDocumentSummaryMarkdown: (content: DocumentContent) => string;
|
|
59
|
+
/**
|
|
60
|
+
* Give a temporary chart key the stored id of an identical, otherwise unplaced
|
|
61
|
+
* chart in the previous version, so re-sending an unchanged chart under a
|
|
62
|
+
* temporary key (e.g. re-uploading a file) does not copy it.
|
|
63
|
+
*/
|
|
64
|
+
export declare const matchDocumentChartKeys: (content: DocumentContent, previous: DocumentContent) => DocumentContent;
|
|
65
|
+
//# sourceMappingURL=documentMarkdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documentMarkdown.d.ts","sourceRoot":"","sources":["../../../src/utils/documentMarkdown.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,eAAe,EAAE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,eAQD,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,YACtB,eAAe,mBACP,MAAM,KACxB;IAAE,OAAO,EAAE,eAAe,CAAC;IAAC,eAAe,EAAE,MAAM,CAAA;CAyBrD,CAAC;AAEF,eAAO,MAAM,oBAAoB,YACpB,eAAe,KACzB,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,oBAAoB,CAAA;CAAE,CAG/C,CAAC;AASN;;;GAGG;AACH,eAAO,MAAM,0BAA0B,YAAa,eAAe,KAAG,MAmBjE,CAAC;AAEN;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,YACtB,eAAe,YACd,eAAe,KAC1B,eA0BF,CAAC"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { isEqual } from 'lodash';
|
|
2
|
+
import { ParameterError } from '../types/errors';
|
|
3
|
+
import { ChartType } from '../types/savedCharts';
|
|
4
|
+
export const DOCUMENT_CHART_TAG = 'document-chart';
|
|
5
|
+
const TAG_LINE_RE = /^<([a-z][a-z-]*)((?:\s+[a-z][a-z-]*="[^"]*")*)\s*\/?>(?:<\/\1>)?$/;
|
|
6
|
+
const ATTRIBUTE_RE = /([a-z][a-z-]*)="([^"]*)"/g;
|
|
7
|
+
const FENCE_RE = /^(`{3,}|~{3,})/;
|
|
8
|
+
const DOCUMENT_CHART_ID_RE = /^c([1-9]\d*)$/;
|
|
9
|
+
const decodeAttribute = (value) => value
|
|
10
|
+
.replaceAll('"', '"')
|
|
11
|
+
.replaceAll('<', '<')
|
|
12
|
+
.replaceAll('>', '>')
|
|
13
|
+
.replaceAll('&', '&');
|
|
14
|
+
const encodeAttribute = (value) => value
|
|
15
|
+
.replaceAll('&', '&')
|
|
16
|
+
.replaceAll('"', '"')
|
|
17
|
+
.replaceAll('<', '<')
|
|
18
|
+
.replaceAll('>', '>');
|
|
19
|
+
/** Drop surrounding blank lines, keeping the first line's indentation. */
|
|
20
|
+
const trimBlankLines = (lines) => {
|
|
21
|
+
const start = lines.findIndex((line) => line.trim() !== '');
|
|
22
|
+
if (start === -1)
|
|
23
|
+
return '';
|
|
24
|
+
const end = lines.findLastIndex((line) => line.trim() !== '');
|
|
25
|
+
return lines
|
|
26
|
+
.slice(start, end + 1)
|
|
27
|
+
.join('\n')
|
|
28
|
+
.trimEnd();
|
|
29
|
+
};
|
|
30
|
+
export const parseDocumentBlocks = (markdown, tagNames) => {
|
|
31
|
+
const blocks = [];
|
|
32
|
+
let lines = [];
|
|
33
|
+
let fence = null;
|
|
34
|
+
const flush = () => {
|
|
35
|
+
const text = trimBlankLines(lines);
|
|
36
|
+
if (text)
|
|
37
|
+
blocks.push({ type: 'markdown', markdown: text });
|
|
38
|
+
lines = [];
|
|
39
|
+
};
|
|
40
|
+
markdown.split(/\r?\n/).forEach((line) => {
|
|
41
|
+
const fenceMatch = FENCE_RE.exec(line.trim());
|
|
42
|
+
if (fence !== null) {
|
|
43
|
+
if (fenceMatch && fenceMatch[1].startsWith(fence))
|
|
44
|
+
fence = null;
|
|
45
|
+
lines.push(line);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (fenceMatch) {
|
|
49
|
+
[, fence] = fenceMatch;
|
|
50
|
+
lines.push(line);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const tagMatch = TAG_LINE_RE.exec(line.trimEnd());
|
|
54
|
+
if (tagMatch && tagNames.includes(tagMatch[1])) {
|
|
55
|
+
flush();
|
|
56
|
+
blocks.push({
|
|
57
|
+
type: 'tag',
|
|
58
|
+
tag: {
|
|
59
|
+
name: tagMatch[1],
|
|
60
|
+
attributes: Object.fromEntries([...tagMatch[2].matchAll(ATTRIBUTE_RE)].map(([, key, value]) => [key, decodeAttribute(value)])),
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
lines.push(line);
|
|
66
|
+
});
|
|
67
|
+
flush();
|
|
68
|
+
return blocks;
|
|
69
|
+
};
|
|
70
|
+
export const formatDocumentTag = ({ name, attributes }) => `<${name}${Object.entries(attributes)
|
|
71
|
+
.map(([key, value]) => ` ${key}="${encodeAttribute(value)}"`)
|
|
72
|
+
.join('')}>`;
|
|
73
|
+
export const joinDocumentBlocks = (blocks) => blocks
|
|
74
|
+
.map((block) => block.type === 'markdown'
|
|
75
|
+
? block.markdown
|
|
76
|
+
: formatDocumentTag(block.tag))
|
|
77
|
+
.join('\n\n');
|
|
78
|
+
export const getDocumentChartTag = (id) => formatDocumentTag({ name: DOCUMENT_CHART_TAG, attributes: { id } });
|
|
79
|
+
/** The number of a stored chart id (`c3` → 3), or undefined for a temporary key. */
|
|
80
|
+
export const getDocumentChartNumber = (id) => {
|
|
81
|
+
const match = DOCUMENT_CHART_ID_RE.exec(id);
|
|
82
|
+
return match ? Number(match[1]) : undefined;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* The Document in reading order. Chart tags must reference an entry in
|
|
86
|
+
* `charts`, once each; other tags stay markdown.
|
|
87
|
+
*/
|
|
88
|
+
export const getDocumentChartBlocks = (content) => {
|
|
89
|
+
const seen = new Set();
|
|
90
|
+
return parseDocumentBlocks(content.markdown, [DOCUMENT_CHART_TAG]).map((block) => {
|
|
91
|
+
if (block.type === 'markdown')
|
|
92
|
+
return block;
|
|
93
|
+
const { id } = block.tag.attributes;
|
|
94
|
+
if (!id) {
|
|
95
|
+
throw new ParameterError(`Every <${DOCUMENT_CHART_TAG}> tag needs an id`);
|
|
96
|
+
}
|
|
97
|
+
if (seen.has(id)) {
|
|
98
|
+
throw new ParameterError(`Chart "${id}" is placed more than once`);
|
|
99
|
+
}
|
|
100
|
+
seen.add(id);
|
|
101
|
+
const chart = Object.hasOwn(content.charts, id)
|
|
102
|
+
? content.charts[id]
|
|
103
|
+
: undefined;
|
|
104
|
+
if (chart === undefined) {
|
|
105
|
+
throw new ParameterError(`Chart "${id}" is placed in the markdown but missing from charts`);
|
|
106
|
+
}
|
|
107
|
+
return { type: 'chart', id, chart };
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
/** Canonical content: chart tags carry only their id, unplaced charts are dropped. */
|
|
111
|
+
export const fromDocumentChartBlocks = (blocks) => ({
|
|
112
|
+
markdown: joinDocumentBlocks(blocks.map((block) => block.type === 'markdown'
|
|
113
|
+
? block
|
|
114
|
+
: {
|
|
115
|
+
type: 'tag',
|
|
116
|
+
tag: {
|
|
117
|
+
name: DOCUMENT_CHART_TAG,
|
|
118
|
+
attributes: { id: block.id },
|
|
119
|
+
},
|
|
120
|
+
})),
|
|
121
|
+
charts: Object.fromEntries(blocks.flatMap((block) => block.type === 'chart' ? [[block.id, block.chart]] : [])),
|
|
122
|
+
});
|
|
123
|
+
export const mapDocumentCharts = (content, map) => ({
|
|
124
|
+
...content,
|
|
125
|
+
charts: Object.fromEntries(Object.entries(content.charts).map(([id, chart]) => [
|
|
126
|
+
id,
|
|
127
|
+
map(chart, id),
|
|
128
|
+
])),
|
|
129
|
+
});
|
|
130
|
+
/**
|
|
131
|
+
* Replace temporary chart keys with stored ids. Keys already shaped like
|
|
132
|
+
* `c<n>` are kept; the others get the next free numbers in reading order, so
|
|
133
|
+
* an id is never handed out twice for one Document.
|
|
134
|
+
*/
|
|
135
|
+
export const assignDocumentChartIds = (content, nextChartNumber) => {
|
|
136
|
+
const blocks = getDocumentChartBlocks(content);
|
|
137
|
+
let next = Math.max(nextChartNumber, ...blocks.map((block) => block.type === 'chart'
|
|
138
|
+
? (getDocumentChartNumber(block.id) ?? 0) + 1
|
|
139
|
+
: 1));
|
|
140
|
+
const assigned = blocks.map((block) => {
|
|
141
|
+
if (block.type === 'markdown' ||
|
|
142
|
+
getDocumentChartNumber(block.id) !== undefined) {
|
|
143
|
+
return block;
|
|
144
|
+
}
|
|
145
|
+
const id = `c${next}`;
|
|
146
|
+
next += 1;
|
|
147
|
+
return { ...block, id };
|
|
148
|
+
});
|
|
149
|
+
return {
|
|
150
|
+
content: fromDocumentChartBlocks(assigned),
|
|
151
|
+
nextChartNumber: next,
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
export const getDocumentChartList = (content) => getDocumentChartBlocks(content).flatMap((block) => block.type === 'chart' ? [{ id: block.id, chart: block.chart }] : []);
|
|
155
|
+
const getChartTypeLabel = ({ chart }) => {
|
|
156
|
+
if (chart.chartConfig.type !== ChartType.CARTESIAN) {
|
|
157
|
+
return chart.chartConfig.type;
|
|
158
|
+
}
|
|
159
|
+
return chart.chartConfig.config?.eChartsConfig.series?.[0]?.type ?? 'bar';
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* The Document with each chart tag expanded into a short description (id,
|
|
163
|
+
* title, type, explore), for readers that should not receive full charts.
|
|
164
|
+
*/
|
|
165
|
+
export const getDocumentSummaryMarkdown = (content) => joinDocumentBlocks(getDocumentChartBlocks(content).map((block) => {
|
|
166
|
+
if (block.type === 'markdown')
|
|
167
|
+
return block;
|
|
168
|
+
const { chart, source } = block.chart;
|
|
169
|
+
return {
|
|
170
|
+
type: 'tag',
|
|
171
|
+
tag: {
|
|
172
|
+
name: DOCUMENT_CHART_TAG,
|
|
173
|
+
attributes: {
|
|
174
|
+
id: block.id,
|
|
175
|
+
title: chart.name,
|
|
176
|
+
type: getChartTypeLabel(block.chart),
|
|
177
|
+
explore: chart.tableName,
|
|
178
|
+
...(source === 'merge' ? { source } : {}),
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}));
|
|
183
|
+
/**
|
|
184
|
+
* Give a temporary chart key the stored id of an identical, otherwise unplaced
|
|
185
|
+
* chart in the previous version, so re-sending an unchanged chart under a
|
|
186
|
+
* temporary key (e.g. re-uploading a file) does not copy it.
|
|
187
|
+
*/
|
|
188
|
+
export const matchDocumentChartKeys = (content, previous) => {
|
|
189
|
+
const blocks = getDocumentChartBlocks(content);
|
|
190
|
+
const used = new Set(blocks.flatMap((block) => block.type === 'chart' &&
|
|
191
|
+
getDocumentChartNumber(block.id) !== undefined
|
|
192
|
+
? [block.id]
|
|
193
|
+
: []));
|
|
194
|
+
return fromDocumentChartBlocks(blocks.map((block) => {
|
|
195
|
+
if (block.type === 'markdown' ||
|
|
196
|
+
getDocumentChartNumber(block.id) !== undefined) {
|
|
197
|
+
return block;
|
|
198
|
+
}
|
|
199
|
+
const match = Object.entries(previous.charts).find(([id, chart]) => !used.has(id) && isEqual(chart, block.chart));
|
|
200
|
+
if (!match)
|
|
201
|
+
return block;
|
|
202
|
+
used.add(match[0]);
|
|
203
|
+
return { ...block, id: match[0] };
|
|
204
|
+
}));
|
|
205
|
+
};
|
|
206
|
+
//# sourceMappingURL=documentMarkdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documentMarkdown.js","sourceRoot":"","sources":["../../../src/utils/documentMarkdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAgBjD,MAAM,CAAC,MAAM,kBAAkB,GAAG,gBAAgB,CAAC;AAEnD,MAAM,WAAW,GACb,mEAAmE,CAAC;AACxE,MAAM,YAAY,GAAG,2BAA2B,CAAC;AACjD,MAAM,QAAQ,GAAG,gBAAgB,CAAC;AAClC,MAAM,oBAAoB,GAAG,eAAe,CAAC;AAE7C,MAAM,eAAe,GAAG,CAAC,KAAa,EAAU,EAAE,CAC9C,KAAK;KACA,UAAU,CAAC,QAAQ,EAAE,GAAG,CAAC;KACzB,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC;KACvB,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC;KACvB,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AAElC,MAAM,eAAe,GAAG,CAAC,KAAa,EAAU,EAAE,CAC9C,KAAK;KACA,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC;KACxB,UAA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