@xnetjs/data 0.3.0 → 0.5.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.
@@ -1,316 +0,0 @@
1
- /**
2
- * Column type definitions for database columns.
3
- *
4
- * Columns are stored in the database's Y.Doc as a Y.Array of Y.Maps,
5
- * enabling CRDT-based ordering and real-time schema sync.
6
- */
7
- /**
8
- * All supported column types.
9
- */
10
- type ColumnType = 'text' | 'number' | 'checkbox' | 'date' | 'dateRange' | 'select' | 'multiSelect' | 'person' | 'url' | 'email' | 'phone' | 'file' | 'relation' | 'tasks' | 'rollup' | 'formula' | 'richText' | 'created' | 'createdBy' | 'updated' | 'updatedBy';
11
- /**
12
- * Column definition stored in the database's Y.Doc.
13
- */
14
- interface ColumnDefinition {
15
- /** Unique column ID (nanoid) */
16
- id: string;
17
- /** Display name */
18
- name: string;
19
- /** Column type */
20
- type: ColumnType;
21
- /** Type-specific configuration */
22
- config: ColumnConfig;
23
- /** Width in pixels (for table view) */
24
- width?: number;
25
- /** Whether this is the title column */
26
- isTitle?: boolean;
27
- }
28
- /**
29
- * Union of all column configuration types.
30
- */
31
- type ColumnConfig = TextColumnConfig | NumberColumnConfig | SelectColumnConfig | RelationColumnConfig | RollupColumnConfig | FormulaColumnConfig | DateColumnConfig | FileColumnConfig | EmptyConfig;
32
- /**
33
- * Empty config for simple types with no configuration.
34
- */
35
- type EmptyConfig = Record<string, never>;
36
- /**
37
- * Text column configuration.
38
- */
39
- interface TextColumnConfig {
40
- /** Maximum length (optional) */
41
- maxLength?: number;
42
- }
43
- /**
44
- * Number column configuration.
45
- */
46
- interface NumberColumnConfig {
47
- /** Number format */
48
- format?: 'number' | 'percent' | 'currency';
49
- /** Currency code (if format is currency) */
50
- currency?: string;
51
- /** Decimal places */
52
- precision?: number;
53
- }
54
- /**
55
- * Select/MultiSelect column configuration.
56
- */
57
- interface SelectColumnConfig {
58
- /** Available options */
59
- options: SelectOption[];
60
- /** Allow creating new options inline */
61
- allowCreate?: boolean;
62
- }
63
- /**
64
- * A single select option.
65
- */
66
- interface SelectOption {
67
- id: string;
68
- name: string;
69
- color?: SelectColor;
70
- }
71
- /**
72
- * Available colors for select options.
73
- */
74
- type SelectColor = 'gray' | 'brown' | 'orange' | 'yellow' | 'green' | 'blue' | 'purple' | 'pink' | 'red';
75
- /**
76
- * Relation column configuration.
77
- */
78
- interface RelationColumnConfig {
79
- /** Target database ID */
80
- targetDatabase: string;
81
- /** Allow multiple relations */
82
- allowMultiple?: boolean;
83
- }
84
- /**
85
- * Rollup column configuration.
86
- */
87
- interface RollupColumnConfig {
88
- /** Column ID of the relation to aggregate */
89
- relationColumn: string;
90
- /** Column ID on related rows to aggregate */
91
- targetColumn: string;
92
- /** Aggregation function */
93
- aggregation: RollupAggregation;
94
- }
95
- /**
96
- * Available rollup aggregation functions.
97
- */
98
- type RollupAggregation = 'sum' | 'avg' | 'count' | 'min' | 'max' | 'concat' | 'unique' | 'empty' | 'notEmpty' | 'percentEmpty' | 'percentNotEmpty';
99
- /**
100
- * Formula column configuration.
101
- */
102
- interface FormulaColumnConfig {
103
- /** Formula expression with {{columnId}} references */
104
- expression: string;
105
- /** Result type */
106
- resultType: 'text' | 'number' | 'date' | 'checkbox';
107
- /** Cached dependencies (auto-computed from expression) */
108
- dependencies?: string[];
109
- }
110
- /**
111
- * Date column configuration.
112
- */
113
- interface DateColumnConfig {
114
- /** Include time */
115
- includeTime?: boolean;
116
- /** Date format */
117
- format?: 'full' | 'short' | 'relative';
118
- }
119
- /**
120
- * File column configuration.
121
- */
122
- interface FileColumnConfig {
123
- /** Accepted MIME types */
124
- accept?: string[];
125
- /** Allow multiple files */
126
- allowMultiple?: boolean;
127
- }
128
- /**
129
- * Check if a column type stores data in NodeStore (vs Y.Doc).
130
- */
131
- declare function isNodeStoreColumnType(type: ColumnType): boolean;
132
- /**
133
- * Check if a column type is computed (formula/rollup).
134
- */
135
- declare function isComputedColumnType(type: ColumnType): boolean;
136
- /**
137
- * Check if a column type is auto-populated.
138
- */
139
- declare function isAutoColumnType(type: ColumnType): boolean;
140
- /**
141
- * Check if a column type uses Y.Doc for storage.
142
- */
143
- declare function isYDocColumnType(type: ColumnType): boolean;
144
-
145
- /**
146
- * Summary engine for the database grid's footer bar (Airtable parity).
147
- *
148
- * Pure, store-agnostic per-column aggregations: given the rows currently in
149
- * view, a column, and a chosen {@link SummaryFunction}, compute one footer
150
- * value. Type-aware — `SUMMARY_FUNCTIONS_BY_TYPE` lists which functions a
151
- * given column type may offer. Numbers add sum/average/min/max/range/median;
152
- * checkboxes add checked/unchecked; dates add earliest/latest; every type
153
- * offers the count family (filled/empty/unique and their percentages).
154
- *
155
- * Kept deliberately free of React/Y.Doc/NodeStore so it is trivially unit
156
- * tested and shared by `GridSummaryBar` and any future query-result footer.
157
- */
158
-
159
- /** A row reduced to the cells the summary bar reads. */
160
- interface SummaryRow {
161
- cells: Record<string, unknown>;
162
- }
163
- /** The minimum a summary needs to know about a column. */
164
- interface SummaryColumnLike {
165
- id: string;
166
- type: ColumnType;
167
- }
168
- /** A footer aggregation. `none` renders nothing. */
169
- type SummaryFunction = 'none' | 'filled' | 'empty' | 'percentFilled' | 'percentEmpty' | 'unique' | 'sum' | 'average' | 'min' | 'max' | 'range' | 'median' | 'checked' | 'unchecked' | 'percentChecked' | 'percentUnchecked' | 'earliest' | 'latest';
170
- /** The result of computing one column summary. */
171
- interface ColumnSummaryResult {
172
- fn: SummaryFunction;
173
- /** Numeric value where meaningful (percentages are 0–100); else null. */
174
- value: number | null;
175
- /** Formatted display string (`''` for `none`, `'—'` for empty/N-A). */
176
- display: string;
177
- }
178
- /** Which summary functions each column type offers, in menu order. */
179
- declare const SUMMARY_FUNCTIONS_BY_TYPE: Record<ColumnType, SummaryFunction[]>;
180
- /** Human label for a summary function (for menus and footer captions). */
181
- declare function summaryFunctionLabel(fn: SummaryFunction): string;
182
- /** A cell counts as filled unless it is null/undefined, '', or an empty array. */
183
- declare function isFilledValue(value: unknown): boolean;
184
- /**
185
- * Compute a single column summary over the in-view rows.
186
- *
187
- * @param rows - rows currently displayed (already filtered)
188
- * @param column - the column being summarised
189
- * @param fn - the chosen aggregation
190
- */
191
- declare function computeColumnSummary(rows: readonly SummaryRow[], column: SummaryColumnLike, fn: SummaryFunction): ColumnSummaryResult;
192
-
193
- /**
194
- * Row-height density tiers for the database grid (Airtable parity).
195
- *
196
- * A view persists a named tier; the grid resolves it to a pixel height that
197
- * `GridSurface` uses for virtualization and row layout. Pure + tiny so the
198
- * toolbar control, the schema default, and the grid all agree on one mapping.
199
- */
200
- /** Named row-height tiers, densest first. */
201
- type RowHeight = 'short' | 'medium' | 'tall' | 'extraTall';
202
- /** Pixel height per tier (approximating Airtable's Short/Medium/Tall/Extra). */
203
- declare const ROW_HEIGHT_PX: Record<RowHeight, number>;
204
- /** Tier order for cycling / menu rendering. */
205
- declare const ROW_HEIGHTS: RowHeight[];
206
- /** Human label for a tier. */
207
- declare function rowHeightLabel(height: RowHeight): string;
208
- /** The default tier (densest, matching the prior fixed look). */
209
- declare const DEFAULT_ROW_HEIGHT: RowHeight;
210
- /**
211
- * Resolve a persisted value (possibly undefined or an unknown string) to a
212
- * pixel height, falling back to the default tier.
213
- */
214
- declare function resolveRowHeightPx(height: string | null | undefined): number;
215
- /** Narrow an arbitrary string to a `RowHeight`, or the default. */
216
- declare function asRowHeight(height: string | null | undefined): RowHeight;
217
-
218
- /**
219
- * View type definitions for database views.
220
- *
221
- * Views are stored in the database's Y.Doc as a Y.Map of view configs,
222
- * enabling collaborative view editing and real-time sync.
223
- */
224
-
225
- /**
226
- * Available view types.
227
- */
228
- type ViewType = 'table' | 'board' | 'list' | 'gallery' | 'calendar' | 'timeline';
229
- /**
230
- * View configuration stored in the database's Y.Doc.
231
- */
232
- interface ViewConfig {
233
- /** Unique view ID */
234
- id: string;
235
- /** Display name */
236
- name: string;
237
- /** View type */
238
- type: ViewType;
239
- /** Column visibility and order */
240
- visibleColumns: string[];
241
- /** Per-column widths (overrides column.width) */
242
- columnWidths?: Record<string, number>;
243
- /** Filter configuration */
244
- filters?: FilterGroup | null;
245
- /** Sort configuration */
246
- sorts?: SortConfig[];
247
- /** Group by column ID */
248
- groupBy?: string | null;
249
- /** Group sort direction */
250
- groupSort?: 'asc' | 'desc';
251
- /** Collapsed group IDs */
252
- collapsedGroups?: string[];
253
- /** Row-height density tier */
254
- rowHeight?: RowHeight;
255
- /** Per-column footer summary functions: columnId -> SummaryFunction */
256
- columnSummaries?: Record<string, SummaryFunction>;
257
- /** Cover image column ID */
258
- coverColumn?: string;
259
- /** Card size */
260
- cardSize?: 'small' | 'medium' | 'large';
261
- /** Start date column ID */
262
- dateColumn?: string;
263
- /** End date column ID */
264
- endDateColumn?: string;
265
- }
266
- /**
267
- * A group of filter conditions combined with AND/OR.
268
- */
269
- interface FilterGroup {
270
- /** Logical operator */
271
- operator: 'and' | 'or';
272
- /** Conditions or nested groups */
273
- conditions: Array<FilterCondition | FilterGroup>;
274
- }
275
- /**
276
- * A single filter condition.
277
- */
278
- interface FilterCondition {
279
- /** Column ID to filter on */
280
- columnId: string;
281
- /** Filter operator */
282
- operator: FilterOperator;
283
- /** Filter value (type depends on column type and operator) */
284
- value: unknown;
285
- }
286
- /**
287
- * Available filter operators.
288
- */
289
- type FilterOperator = 'equals' | 'notEquals' | 'contains' | 'notContains' | 'startsWith' | 'endsWith' | 'isEmpty' | 'isNotEmpty' | 'greaterThan' | 'lessThan' | 'greaterOrEqual' | 'lessOrEqual' | 'before' | 'after' | 'between' | 'hasAny' | 'hasAll' | 'hasNone';
290
- /**
291
- * Sort configuration for a column.
292
- */
293
- interface SortConfig {
294
- /** Column ID to sort by */
295
- columnId: string;
296
- /** Sort direction */
297
- direction: 'asc' | 'desc';
298
- }
299
- /**
300
- * Check if a filter item is a group (vs a condition).
301
- */
302
- declare function isFilterGroup(item: FilterCondition | FilterGroup): item is FilterGroup;
303
- /**
304
- * Check if a filter item is a condition (vs a group).
305
- */
306
- declare function isFilterCondition(item: FilterCondition | FilterGroup): item is FilterCondition;
307
- /**
308
- * Check if a view type supports grouping.
309
- */
310
- declare function supportsGrouping(type: ViewType): boolean;
311
- /**
312
- * Check if a view type requires a date column.
313
- */
314
- declare function requiresDateColumn(type: ViewType): boolean;
315
-
316
- export { type SummaryColumnLike as A, type ColumnSummaryResult as B, type ColumnType as C, type DateColumnConfig as D, type EmptyConfig as E, type FormulaColumnConfig as F, ROW_HEIGHT_PX as G, ROW_HEIGHTS as H, DEFAULT_ROW_HEIGHT as I, rowHeightLabel as J, resolveRowHeightPx as K, asRowHeight as L, type RowHeight as M, type NumberColumnConfig as N, type RelationColumnConfig as R, type SelectColumnConfig as S, type TextColumnConfig as T, type ViewType as V, type RollupColumnConfig as a, type FileColumnConfig as b, type ColumnDefinition as c, type ColumnConfig as d, type SelectOption as e, type SelectColor as f, type RollupAggregation as g, isComputedColumnType as h, isNodeStoreColumnType as i, isAutoColumnType as j, isYDocColumnType as k, type ViewConfig as l, type FilterGroup as m, type FilterCondition as n, type FilterOperator as o, type SortConfig as p, isFilterGroup as q, isFilterCondition as r, supportsGrouping as s, requiresDateColumn as t, SUMMARY_FUNCTIONS_BY_TYPE as u, summaryFunctionLabel as v, isFilledValue as w, computeColumnSummary as x, type SummaryFunction as y, type SummaryRow as z };