forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaseline-parse.ts
More file actions
169 lines (141 loc) · 4.98 KB
/
Copy pathbaseline-parse.ts
File metadata and controls
169 lines (141 loc) · 4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/* baseline-parse.ts — Parse Notion cell values into baseline data */
import type { BaselineStatus, BaselineTag } from "./baseline-types";
/* ------------------------------------------------------------------ */
/* Tag pattern mapping */
/* ------------------------------------------------------------------ */
const TAG_MAP: Record<string, BaselineTag> = {
ALL: "all",
CPK: "cpk",
"AG-UI": "agui",
INT: "int",
DEMO: "demo",
DOCS: "docs",
TEST: "tests",
TESTS: "tests",
};
/* ------------------------------------------------------------------ */
/* parseNotionCell */
/* ------------------------------------------------------------------ */
export interface ParsedCell {
status: BaselineStatus;
tags: BaselineTag[];
}
/**
* Parses a raw Notion cell string into a status + tag set.
*
* Emoji prefix determines status:
* ✅ → works
* ❌ → impossible
* ❓ → unknown
* 🛠️/🛠 → possible (defaults to ["all"] if no tags found)
* empty → unknown
* free text → unknown (console.warn)
*/
export function parseNotionCell(raw: string): ParsedCell {
const trimmed = raw.trim();
if (trimmed === "") {
return { status: "unknown", tags: [] };
}
if (trimmed.startsWith("✅")) {
return { status: "works", tags: [] };
}
if (trimmed.startsWith("❌")) {
const tags = extractTags(trimmed);
return { status: "impossible", tags };
}
if (trimmed.startsWith("❓")) {
return { status: "unknown", tags: [] };
}
// 🛠️ (U+1F6E0 U+FE0F) or 🛠 (U+1F6E0 without variation selector)
if (trimmed.startsWith("🛠️") || trimmed.startsWith("🛠")) {
const tags = extractTags(trimmed);
return { status: "possible", tags: tags.length === 0 ? ["all"] : tags };
}
// Free text — no recognized emoji prefix
console.warn(`Unrecognized Notion cell value: ${JSON.stringify(raw)}`);
return { status: "unknown", tags: [] };
}
/* ------------------------------------------------------------------ */
/* extractTags */
/* ------------------------------------------------------------------ */
function extractTags(text: string): BaselineTag[] {
const tags: BaselineTag[] = [];
const pattern = /\[([A-Z-]+)\]/g;
let match: RegExpExecArray | null;
while ((match = pattern.exec(text)) !== null) {
const mapped = TAG_MAP[match[1]];
if (mapped && !tags.includes(mapped)) {
tags.push(mapped);
}
}
return tags;
}
/* ------------------------------------------------------------------ */
/* toSlug */
/* ------------------------------------------------------------------ */
const SLUG_OVERRIDES: Record<string, string> = {
"MAF - .Net": "maf-dotnet",
"MAF - Python": "maf-python",
};
/**
* Convert a display name to a kebab-case slug.
*
* Special overrides for known names, otherwise:
* - Replace em dashes (—) with hyphens
* - Strip parens, plus, ampersand, dots
* - Collapse spaces/hyphens
* - Lowercase
*/
export function toSlug(name: string): string {
if (SLUG_OVERRIDES[name]) {
return SLUG_OVERRIDES[name];
}
return name
.replace(/—/g, "-") // em dash → hyphen
.replace(/[()+'&.]/g, "") // strip parens, plus, ampersand, dots, apostrophes
.replace(/[\s-]+/g, "-") // collapse whitespace & hyphens
.replace(/^-|-$/g, "") // trim leading/trailing hyphens
.toLowerCase();
}
/* ------------------------------------------------------------------ */
/* SeedEntry */
/* ------------------------------------------------------------------ */
export interface SeedEntry {
partnerSlug: string;
featureSlug: string;
status: BaselineStatus;
tags: BaselineTag[];
}
/* ------------------------------------------------------------------ */
/* parseNotionData */
/* ------------------------------------------------------------------ */
/**
* Iterates rows x partner columns, parsing each Notion cell.
*
* @param rows - Array of objects, each with a "Feature / Capability" key
* and one key per partner name containing the raw cell string.
* @param partnerNames - Ordered list of partner column names.
* @returns Flat array of SeedEntry objects.
*/
export function parseNotionData(
rows: Record<string, string>[],
partnerNames: string[],
): SeedEntry[] {
const entries: SeedEntry[] = [];
for (const row of rows) {
const featureName = row["Feature / Capability"];
if (!featureName) continue;
const featureSlug = toSlug(featureName);
for (const partner of partnerNames) {
const cellValue = row[partner] ?? "";
const parsed = parseNotionCell(cellValue);
entries.push({
partnerSlug: toSlug(partner),
featureSlug,
status: parsed.status,
tags: parsed.tags,
});
}
}
return entries;
}