@mintlify/common 1.0.1329 → 1.0.1331

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.
@@ -28,6 +28,7 @@ const KINDS = {
28
28
  url: 'text',
29
29
  email: 'text',
30
30
  person: 'text',
31
+ page: 'text',
31
32
  number: 'number',
32
33
  boolean: 'boolean',
33
34
  date: 'date',
@@ -6,6 +6,7 @@ const STORED_TYPES = {
6
6
  text: STRING,
7
7
  url: STRING,
8
8
  email: STRING,
9
+ page: STRING,
9
10
  select: STRING,
10
11
  multi_select: STRING,
11
12
  json: STRING,
@@ -1,4 +1,4 @@
1
- import { normalizeDate } from '../query/values.js';
1
+ import { normalizeDate, pageTitle } from '../query/values.js';
2
2
  import { isFormulaError } from './errors.js';
3
3
  const isValidDate = (value) => value instanceof Date && !Number.isNaN(value.getTime());
4
4
  const formatNumber = (value) => {
@@ -85,6 +85,8 @@ export const cellReader = (column, options) => {
85
85
  case 'email':
86
86
  case 'person':
87
87
  return toText;
88
+ case 'page':
89
+ return pageTitle;
88
90
  default:
89
91
  return (raw) => raw instanceof Date
90
92
  ? isValidDate(raw)
@@ -1,11 +1,12 @@
1
1
  import { CLIENT_ONLY, QUERY_LIMITS, } from './types.js';
2
2
  import { validateQueryExpr, validateQueryRequest } from './validate.js';
3
- import { asciiLower, compareCodePoints, normalizeDate } from './values.js';
3
+ import { asciiLower, compareCodePoints, normalizeDate, pageTitle } from './values.js';
4
4
  const KINDS = {
5
5
  text: 'text',
6
6
  url: 'text',
7
7
  email: 'text',
8
8
  person: 'text',
9
+ page: 'text',
9
10
  number: 'number',
10
11
  boolean: 'boolean',
11
12
  date: 'date',
@@ -253,7 +254,9 @@ class Compiler {
253
254
  id: column.id,
254
255
  type: column.type,
255
256
  kind,
256
- read: (row) => readScalar(kind, row.columns[column.id]),
257
+ read: column.type === 'page'
258
+ ? (row) => readScalar(kind, pageTitle(row.columns[column.id]))
259
+ : (row) => readScalar(kind, row.columns[column.id]),
257
260
  };
258
261
  }
259
262
  operand(expr, path) {
@@ -1,4 +1,4 @@
1
1
  export { compensatedSum, compileQueryFilter, evaluateQuery, type EvaluateQueryOptions, measureQuery, type QueryError, type QueryResult, type RowPredicate, } from './evaluate.js';
2
2
  export * from './types.js';
3
3
  export { isValidQueryRequest, validateQueryExpr, validateQueryRequest } from './validate.js';
4
- export { asciiLower, compareCodePoints, isEmptyValue, normalizeDate } from './values.js';
4
+ export { asciiLower, compareCodePoints, isEmptyValue, normalizeDate, pageTitle } from './values.js';
@@ -1,4 +1,4 @@
1
1
  export { compensatedSum, compileQueryFilter, evaluateQuery, measureQuery, } from './evaluate.js';
2
2
  export * from './types.js';
3
3
  export { isValidQueryRequest, validateQueryExpr, validateQueryRequest } from './validate.js';
4
- export { asciiLower, compareCodePoints, isEmptyValue, normalizeDate } from './values.js';
4
+ export { asciiLower, compareCodePoints, isEmptyValue, normalizeDate, pageTitle } from './values.js';
@@ -1,4 +1,5 @@
1
1
  export declare const normalizeDate: (value: unknown) => string | null;
2
+ export declare const pageTitle: (value: unknown) => string | null;
2
3
  export declare const isEmptyValue: (value: unknown) => boolean;
3
4
  export declare const asciiLower: (value: string) => string;
4
5
  export declare const compareCodePoints: (a: string, b: string) => -1 | 0 | 1;
@@ -13,6 +13,10 @@ export const normalizeDate = (value) => {
13
13
  const time = Date.parse(value);
14
14
  return valid && !Number.isNaN(time) ? new Date(time).toISOString() : null;
15
15
  };
16
+ // A page cell is stored as { pageId, title, href }; filters, sorts and formulas read its title.
17
+ export const pageTitle = (value) => typeof value === 'object' && value !== null && 'title' in value && typeof value.title === 'string'
18
+ ? value.title
19
+ : null;
16
20
  export const isEmptyValue = (value) => value === null ||
17
21
  value === undefined ||
18
22
  value === '' ||
@@ -1,14 +1,15 @@
1
1
  import { type QuerySort } from './query/types.js';
2
2
  export { columnReference } from './formula/format.js';
3
- export declare const DATABASE_VIEWS: readonly ['table', 'board'];
3
+ export declare const DATABASE_VIEWS: readonly ['table', 'board', 'calendar'];
4
4
  export type DatabaseView = (typeof DATABASE_VIEWS)[number];
5
5
  export type DatabaseViewProps = {
6
6
  view?: string | null;
7
7
  sort?: string | null;
8
8
  filter?: string | null;
9
9
  groupBy?: string | null;
10
+ calendarBy?: string | null;
10
11
  };
11
- export type DatabaseViewPropChanges = Pick<DatabaseViewProps, 'view' | 'sort' | 'filter' | 'groupBy'>;
12
+ export type DatabaseViewPropChanges = Pick<DatabaseViewProps, 'view' | 'sort' | 'filter' | 'groupBy' | 'calendarBy'>;
12
13
  export type DatabaseViewColumn = {
13
14
  id: string;
14
15
  name: string;
@@ -79,13 +80,18 @@ export type DatabaseViewWarning = {
79
80
  kind: 'group_by_unsupported';
80
81
  column: string;
81
82
  type: string;
83
+ } | {
84
+ kind: 'calendar_by_unsupported';
85
+ column: string;
86
+ type: string;
82
87
  };
83
- export type DatabaseViewPropName = 'sort' | 'filter' | 'groupBy';
88
+ export type DatabaseViewPropName = 'sort' | 'filter' | 'groupBy' | 'calendarBy';
84
89
  export type DatabaseFilterKind = 'text' | 'number' | 'select' | 'multi' | 'checkbox' | 'date';
85
90
  export declare const filterKindOf: (type: string) => DatabaseFilterKind | null;
86
91
  export declare const isViewableColumn: (column: Pick<DatabaseViewColumn, 'type'>) => boolean;
87
92
  export declare const isSortableColumn: (column: Pick<DatabaseViewColumn, 'type'>) => boolean;
88
93
  export declare const isGroupableColumn: (column: Pick<DatabaseViewColumn, 'type'>) => boolean;
94
+ export declare const isCalendarColumn: (column: Pick<DatabaseViewColumn, 'type'>) => boolean;
89
95
  export declare const filterOpsFor: (type: string) => readonly DatabaseFilterOp[];
90
96
  export declare const isKnownView: (value: unknown) => value is DatabaseView;
91
97
  export declare const resolveView: (value: unknown) => DatabaseView;
@@ -119,11 +125,13 @@ export declare const renameColumnsInViewProps: (props: DatabaseViewProps, rename
119
125
  export declare const renameColumnInViewProps: (props: DatabaseViewProps, from: string, to: string) => DatabaseViewPropChanges;
120
126
  export declare const aliasRenames: (columns: readonly DatabaseViewColumn[]) => DatabaseColumnRenames;
121
127
  export declare const ambiguousAliases: (columns: readonly DatabaseViewColumn[]) => ReadonlySet<string>;
122
- export type ResolvedGroupBy = {
128
+ export type ResolvedColumnProp = {
123
129
  column: DatabaseViewColumn | null;
124
130
  warnings: DatabaseViewWarning[];
125
131
  };
132
+ export type ResolvedGroupBy = ResolvedColumnProp;
126
133
  export declare const resolveGroupBy: (written: string | null | undefined, columns: readonly DatabaseViewColumn[]) => ResolvedGroupBy;
134
+ export declare const resolveCalendarBy: (written: string | null | undefined, columns: readonly DatabaseViewColumn[]) => ResolvedColumnProp;
127
135
  export type DatabaseInvalidFilter = 'show-all' | 'hide-all';
128
136
  export type ResolveViewOptions = {
129
137
  onInvalidFilter?: DatabaseInvalidFilter;
@@ -133,6 +141,7 @@ export type ResolvedDatabaseView = {
133
141
  sort: DatabaseSortRule[];
134
142
  filter: DatabaseFilter;
135
143
  groupBy: string | null;
144
+ calendarBy: string | null;
136
145
  warnings: DatabaseViewWarning[];
137
146
  healed: DatabaseViewPropChanges;
138
147
  filterSource: string | null;
@@ -9,7 +9,7 @@ import { evaluateQuery } from './query/evaluate.js';
9
9
  import { QUERY_LIMITS } from './query/types.js';
10
10
  import { normalizeDate } from './query/values.js';
11
11
  export { columnReference } from './formula/format.js';
12
- export const DATABASE_VIEWS = ['table', 'board'];
12
+ export const DATABASE_VIEWS = ['table', 'board', 'calendar'];
13
13
  export const DATABASE_FILTER_OPS = [
14
14
  'eq',
15
15
  'neq',
@@ -29,6 +29,7 @@ const FILTER_KINDS = {
29
29
  url: 'text',
30
30
  email: 'text',
31
31
  person: 'text',
32
+ page: 'text',
32
33
  number: 'number',
33
34
  select: 'select',
34
35
  multi_select: 'multi',
@@ -39,6 +40,7 @@ export const filterKindOf = (type) => { var _a; return (_a = FILTER_KINDS[type])
39
40
  export const isViewableColumn = (column) => filterKindOf(column.type) !== null;
40
41
  export const isSortableColumn = (column) => isViewableColumn(column) && column.type !== 'multi_select';
41
42
  export const isGroupableColumn = (column) => column.type === 'select';
43
+ export const isCalendarColumn = (column) => column.type === 'date';
42
44
  const OPS_BY_KIND = {
43
45
  text: ['contains', 'not_contains', 'eq', 'neq', 'empty', 'not_empty'],
44
46
  number: ['eq', 'neq', 'lt', 'lte', 'gt', 'gte', 'empty', 'not_empty'],
@@ -362,7 +364,7 @@ export const resolveColumnName = (written, candidates) => {
362
364
  return { column: null, reason: loose.length > 1 ? 'ambiguous' : 'unknown' };
363
365
  };
364
366
  export const matchColumnName = (written, candidates) => { var _a; return (_a = resolveColumnName(written, candidates).column) !== null && _a !== void 0 ? _a : undefined; };
365
- const renamedGroupBy = (written, renames) => { var _a; return (_a = matchColumnName(written, [...renames].map(([name, to]) => ({ name, to })))) === null || _a === void 0 ? void 0 : _a.to; };
367
+ const renamedColumnProp = (written, renames) => { var _a; return (_a = matchColumnName(written, [...renames].map(([name, to]) => ({ name, to })))) === null || _a === void 0 ? void 0 : _a.to; };
366
368
  export const renameColumnsInViewProps = (props, renames) => {
367
369
  const changes = {};
368
370
  if (renames.size === 0)
@@ -374,7 +376,10 @@ export const renameColumnsInViewProps = (props, renames) => {
374
376
  };
375
377
  const filter = props.filter ? renameFormula(props.filter, renames) : props.filter;
376
378
  const groupBy = props.groupBy
377
- ? renamedGroupBy(normalizeColumnName(props.groupBy), renames)
379
+ ? renamedColumnProp(normalizeColumnName(props.groupBy), renames)
380
+ : undefined;
381
+ const calendarBy = props.calendarBy
382
+ ? renamedColumnProp(normalizeColumnName(props.calendarBy), renames)
378
383
  : undefined;
379
384
  if (keys.some(({ rule }) => rule && renames.has(rule.column))) {
380
385
  changes.sort = keys.map(renamedKey).join(', ');
@@ -383,6 +388,8 @@ export const renameColumnsInViewProps = (props, renames) => {
383
388
  changes.filter = filter;
384
389
  if (groupBy !== undefined)
385
390
  changes.groupBy = groupBy;
391
+ if (calendarBy !== undefined)
392
+ changes.calendarBy = calendarBy;
386
393
  return changes;
387
394
  };
388
395
  export const renameColumnInViewProps = (props, from, to) => renameColumnsInViewProps(props, new Map([[from, to]]));
@@ -413,24 +420,26 @@ export const ambiguousAliases = (columns) => new Set([...aliasTargets(columns)].
413
420
  const nameWarning = (prop, column, reason, columns) => reason === 'ambiguous' || ambiguousAliases(columns).has(column)
414
421
  ? { kind: 'ambiguous_column', prop, column }
415
422
  : { kind: 'unknown_column', prop, column };
416
- export const resolveGroupBy = (written, columns) => {
423
+ const resolveColumnProp = (prop, written, columns, accepts, unsupported) => {
417
424
  var _a;
418
425
  const name = written ? normalizeColumnName(written) : '';
419
426
  if (!name)
420
- return { column: (_a = columns.find(isGroupableColumn)) !== null && _a !== void 0 ? _a : null, warnings: [] };
427
+ return { column: (_a = columns.find(accepts)) !== null && _a !== void 0 ? _a : null, warnings: [] };
421
428
  const match = resolveColumnName(name, columns);
422
429
  if (!match.column) {
423
- return { column: null, warnings: [nameWarning('groupBy', name, match.reason, columns)] };
430
+ return { column: null, warnings: [nameWarning(prop, name, match.reason, columns)] };
424
431
  }
425
432
  const { column } = match;
426
- if (!isGroupableColumn(column)) {
433
+ if (!accepts(column)) {
427
434
  return {
428
435
  column: null,
429
- warnings: [{ kind: 'group_by_unsupported', column: column.name, type: column.type }],
436
+ warnings: [{ kind: unsupported, column: column.name, type: column.type }],
430
437
  };
431
438
  }
432
439
  return { column, warnings: [] };
433
440
  };
441
+ export const resolveGroupBy = (written, columns) => resolveColumnProp('groupBy', written, columns, isGroupableColumn, 'group_by_unsupported');
442
+ export const resolveCalendarBy = (written, columns) => resolveColumnProp('calendarBy', written, columns, isCalendarColumn, 'calendar_by_unsupported');
434
443
  const ALL_ROWS = () => true;
435
444
  const NO_ROWS = () => false;
436
445
  const canonicalNames = (source, columns, warn) => {
@@ -451,11 +460,13 @@ const canonicalNames = (source, columns, warn) => {
451
460
  return canonical;
452
461
  };
453
462
  export const resolveViewProps = (written, columns, { onInvalidFilter = 'show-all' } = {}) => {
454
- var _a, _b;
455
- var _c, _d;
463
+ var _a, _b, _c;
464
+ var _d, _e, _f;
456
465
  const healed = renameColumnsInViewProps(written, aliasRenames(columns));
457
466
  if (written.groupBy && matchColumnName(written.groupBy, columns))
458
467
  delete healed.groupBy;
468
+ if (written.calendarBy && matchColumnName(written.calendarBy, columns))
469
+ delete healed.calendarBy;
459
470
  const props = Object.assign(Object.assign({}, written), healed);
460
471
  const warnings = [];
461
472
  let filterInvalid = false;
@@ -479,7 +490,7 @@ export const resolveViewProps = (written, columns, { onInvalidFilter = 'show-all
479
490
  continue;
480
491
  }
481
492
  const column = known('sort', key.rule.column);
482
- const rule = { column: (_c = column === null || column === void 0 ? void 0 : column.name) !== null && _c !== void 0 ? _c : key.rule.column, direction: key.rule.direction };
493
+ const rule = { column: (_d = column === null || column === void 0 ? void 0 : column.name) !== null && _d !== void 0 ? _d : key.rule.column, direction: key.rule.direction };
483
494
  sort.push(rule);
484
495
  if (!column)
485
496
  continue;
@@ -542,11 +553,14 @@ export const resolveViewProps = (written, columns, { onInvalidFilter = 'show-all
542
553
  const stored = filterSource ? toStoredFormula(filterSource, columns) : null;
543
554
  const group = resolveGroupBy(props.groupBy, columns);
544
555
  warnings.push(...group.warnings);
556
+ const calendar = resolveCalendarBy(props.calendarBy, columns);
557
+ warnings.push(...calendar.warnings);
545
558
  return {
546
559
  view: resolveView(rawView),
547
560
  sort,
548
561
  filter,
549
- groupBy: (_d = (_b = group.column) === null || _b === void 0 ? void 0 : _b.name) !== null && _d !== void 0 ? _d : null,
562
+ groupBy: (_e = (_b = group.column) === null || _b === void 0 ? void 0 : _b.name) !== null && _e !== void 0 ? _e : null,
563
+ calendarBy: (_f = (_c = calendar.column) === null || _c === void 0 ? void 0 : _c.name) !== null && _f !== void 0 ? _f : null,
550
564
  warnings,
551
565
  healed,
552
566
  filterSource: matches === ALL_ROWS || matches === NO_ROWS ? null : filterSource,
@@ -6,6 +6,7 @@ import remarkMdx from 'remark-mdx';
6
6
  import remarkStringify from 'remark-stringify';
7
7
  import { preprocessCustomHeadingIds } from './preprocessCustomHeadingIds.js';
8
8
  import { preprocessMdxFragmentCode } from './preprocessMdxFragmentCode.js';
9
+ import { remarkMdasticParse } from './remarkMdasticParse.js';
9
10
  import { getJsxEsmTree } from './snippets/getJsxEsmTree.js';
10
11
  import { isJsxOrTsx } from './snippets/isJsxOrTsx.js';
11
12
  export const coreRemarkMdxPlugins = [
@@ -13,6 +14,7 @@ export const coreRemarkMdxPlugins = [
13
14
  remarkGfm,
14
15
  [remarkFrontmatter, ['yaml', 'toml']],
15
16
  remarkMath,
17
+ remarkMdasticParse,
16
18
  ];
17
19
  export const coreRemark = remark().use(coreRemarkMdxPlugins).freeze();
18
20
  const agentRemarkMdxPlugins = [
@@ -0,0 +1,2 @@
1
+ import type { Processor } from 'unified';
2
+ export declare function remarkMdasticParse(this: Processor): void;
@@ -0,0 +1,37 @@
1
+ import { parse } from 'mdastic';
2
+ import { frontmatter } from 'mdastic/frontmatter';
3
+ import { gfm } from 'mdastic/gfm';
4
+ import { math } from 'mdastic/math';
5
+ import { mdx } from 'mdastic/mdx';
6
+ import { visit } from 'unist-util-visit';
7
+ const syntax = [
8
+ gfm({ singleTilde: true }),
9
+ mdx({ estree: true }),
10
+ math({ singleDollarTextMath: true }),
11
+ frontmatter(['yaml', 'toml']),
12
+ ];
13
+ export function remarkMdasticParse() {
14
+ var _a;
15
+ var _b;
16
+ const fallback = this.parser;
17
+ const extensions = (_b = (_a = this.data('micromarkExtensions')) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
18
+ if (!fallback)
19
+ return;
20
+ this.parser = (document, file) => {
21
+ var _a;
22
+ var _b;
23
+ if (((_b = (_a = this.data('micromarkExtensions')) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) === extensions) {
24
+ const tree = parse(document, { syntax });
25
+ if (!(tree instanceof Error)) {
26
+ const root = tree;
27
+ visit(root, ['mdxJsxFlowElement', 'mdxJsxTextElement'], (node) => {
28
+ if ('attributes' in node)
29
+ for (const attribute of node.attributes)
30
+ delete attribute.position;
31
+ });
32
+ return root;
33
+ }
34
+ }
35
+ return fallback(document, file);
36
+ };
37
+ }
@@ -12,6 +12,7 @@ export * from './groupAccess.js';
12
12
  export * from './filterDivisions.js';
13
13
  export * from './updateFirstHrefInDivision.js';
14
14
  export * from './scopeNavToPath.js';
15
+ export { trimNavPagesToClientFields } from './trimScopedNavPages.js';
15
16
  export * from './getVersionOrLanguageFromPath.js';
16
17
  export * from './isCommonPage.js';
17
18
  export * from './getFirstPageFromNavConfig.js';
@@ -12,6 +12,7 @@ export * from './groupAccess.js';
12
12
  export * from './filterDivisions.js';
13
13
  export * from './updateFirstHrefInDivision.js';
14
14
  export * from './scopeNavToPath.js';
15
+ export { trimNavPagesToClientFields } from './trimScopedNavPages.js';
15
16
  export * from './getVersionOrLanguageFromPath.js';
16
17
  export * from './isCommonPage.js';
17
18
  export * from './getFirstPageFromNavConfig.js';
@@ -1,3 +1,4 @@
1
1
  type NavNode = Record<string, unknown>;
2
2
  export declare function trimScopedNavPages(nav: NavNode, currentPath: string): NavNode;
3
+ export declare function trimNavPagesToClientFields(nav: NavNode): NavNode;
3
4
  export {};
@@ -95,7 +95,7 @@ function trimNode(node, keepDescription) {
95
95
  if (!isNavNode(node))
96
96
  return node;
97
97
  if (isPageNode(node))
98
- return trimPage(node, keepDescription.has(node));
98
+ return trimPage(node, keepDescription(node));
99
99
  const trimmed = {};
100
100
  for (const [key, value] of Object.entries(node)) {
101
101
  trimmed[key] = key === 'global' ? value : trimNode(value, keepDescription);
@@ -107,6 +107,13 @@ export function trimScopedNavPages(nav, currentPath) {
107
107
  const target = normalizeComparablePath(replaceSlashIndex(currentPath));
108
108
  addPaginationNeighbors(nav, target, keepDescription);
109
109
  addDirectoryChildren(nav, target, keepDescription);
110
- const trimmed = trimNode(nav, keepDescription);
110
+ const trimmed = trimNode(nav, (page) => keepDescription.has(page));
111
+ return isNavNode(trimmed) ? trimmed : nav;
112
+ }
113
+ // static export renders one layout nav into every page, so it can't know which
114
+ // pages need descriptions; keep them all and drop everything else the client
115
+ // doesn't read (keywords, custom frontmatter)
116
+ export function trimNavPagesToClientFields(nav) {
117
+ const trimmed = trimNode(nav, () => true);
111
118
  return isNavNode(trimmed) ? trimmed : nav;
112
119
  }
@@ -1,4 +1,4 @@
1
- import { trimScopedNavPages } from './trimScopedNavPages.js';
1
+ import { trimNavPagesToClientFields, trimScopedNavPages } from './trimScopedNavPages.js';
2
2
  const page = (slug, extra = {}) => (Object.assign({ title: slug, href: `/${slug}`, description: `${slug} description` }, extra));
3
3
  function descriptions(nav) {
4
4
  const out = {};
@@ -192,3 +192,28 @@ describe('trimScopedNavPages', () => {
192
192
  expect(nav).toEqual(before);
193
193
  });
194
194
  });
195
+ describe('trimNavPagesToClientFields', () => {
196
+ it('keeps client fields and every description', () => {
197
+ const nav = {
198
+ groups: [
199
+ {
200
+ group: 'G',
201
+ root: page('g', { keywords: ['k'] }),
202
+ pages: [page('a', { icon: 'book', customFrontmatter: 'x' }), page('b', { tag: 'New' })],
203
+ },
204
+ ],
205
+ };
206
+ expect(trimNavPagesToClientFields(nav)).toEqual({
207
+ groups: [
208
+ {
209
+ group: 'G',
210
+ root: { title: 'g', href: '/g', description: 'g description' },
211
+ pages: [
212
+ { title: 'a', href: '/a', description: 'a description', icon: 'book' },
213
+ { title: 'b', href: '/b', description: 'b description', tag: 'New' },
214
+ ],
215
+ },
216
+ ],
217
+ });
218
+ });
219
+ });