@xnetjs/data 0.0.2 → 0.0.3
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/README.md +112 -0
- package/dist/account-BZHETMC4.js +12 -0
- package/dist/auth/index.d.ts +413 -0
- package/dist/auth/index.js +102 -0
- package/dist/budget-WR2Q4YH3.js +12 -0
- package/dist/canvas-HFMMVQLD.js +10 -0
- package/dist/channel-DXDYJ3ZH.js +12 -0
- package/dist/chat-message-QUUQGXEW.js +10 -0
- package/dist/chunk-2DSDH2ZH.js +52 -0
- package/dist/chunk-337E3ZOB.js +54 -0
- package/dist/chunk-37267RSF.js +41 -0
- package/dist/chunk-3JKW6TDE.js +66 -0
- package/dist/chunk-3RB2FMMO.js +148 -0
- package/dist/{chunk-BQBPA5HS.js → chunk-4U4KBCDN.js} +16 -2
- package/dist/chunk-4UQTURCD.js +722 -0
- package/dist/chunk-54Y7QRZN.js +109 -0
- package/dist/chunk-5FHJE7RC.js +46 -0
- package/dist/chunk-64AM6JPM.js +40 -0
- package/dist/chunk-6CN53PON.js +143 -0
- package/dist/chunk-6GB7PBCR.js +40 -0
- package/dist/chunk-6OPZJ7MG.js +78 -0
- package/dist/{chunk-IDMBCRUC.js → chunk-77UDLVQY.js} +1 -1
- package/dist/chunk-7GMJOAPF.js +52 -0
- package/dist/chunk-7PDRDSFH.js +69 -0
- package/dist/chunk-C5IRSEEZ.js +69 -0
- package/dist/chunk-CHZUSBSB.js +45 -0
- package/dist/chunk-DOZJXPQ6.js +232 -0
- package/dist/chunk-DTPSTMUD.js +105 -0
- package/dist/chunk-E6S557NC.js +402 -0
- package/dist/chunk-EIQX7INF.js +45 -0
- package/dist/chunk-ENTHVNOC.js +57 -0
- package/dist/chunk-EZA5UT4Y.js +5543 -0
- package/dist/chunk-GR3NDMBY.js +76 -0
- package/dist/chunk-GWYVY2K4.js +63 -0
- package/dist/chunk-IJ675GJR.js +42 -0
- package/dist/chunk-IP4BEVVD.js +57 -0
- package/dist/chunk-J4IVJA5M.js +102 -0
- package/dist/chunk-J6EDPPH4.js +84 -0
- package/dist/{chunk-SZC345Z2.js → chunk-JESSJ5CZ.js} +1015 -1110
- package/dist/chunk-JO6Y4E5V.js +73 -0
- package/dist/chunk-KPVBKKZS.js +47 -0
- package/dist/chunk-KTJLFJEQ.js +43 -0
- package/dist/chunk-L66WXPTW.js +32 -0
- package/dist/chunk-LGD72FVD.js +48 -0
- package/dist/chunk-O64EK5FK.js +887 -0
- package/dist/chunk-PMUQACPY.js +33 -0
- package/dist/chunk-PSUJEKVV.js +1722 -0
- package/dist/chunk-QVZXXJSP.js +6122 -0
- package/dist/chunk-QWFTRZQT.js +142 -0
- package/dist/chunk-RSSZXCLL.js +51 -0
- package/dist/chunk-S4B5OPZU.js +415 -0
- package/dist/{chunk-VYR5GPJP.js → chunk-SPFKSTPT.js} +9 -3
- package/dist/chunk-U6CBYDVZ.js +50 -0
- package/dist/chunk-UDUPQKRB.js +49 -0
- package/dist/chunk-V6HZ3LF3.js +380 -0
- package/dist/chunk-WMSCEBFH.js +64 -0
- package/dist/chunk-WUR3WWQM.js +65 -0
- package/dist/chunk-XHEA5UER.js +75 -0
- package/dist/chunk-XTUGZSYQ.js +75 -0
- package/dist/chunk-XWA3CJQ6.js +45 -0
- package/dist/chunk-YEQ6LLUY.js +49 -0
- package/dist/chunk-YWN27MLD.js +47 -0
- package/dist/chunk-YXZGYLKV.js +65 -0
- package/dist/chunk-ZICIXDEE.js +54 -0
- package/dist/chunk-ZMCO3O2Z.js +70 -0
- package/dist/clone-DpbVKLUu.d.ts +2205 -0
- package/dist/comment-Y2Y3QYYI.js +10 -0
- package/dist/crm-AAJXYIJY.js +68 -0
- package/dist/dashboard-3DC6B4BJ.js +10 -0
- package/dist/database/index.d.ts +882 -0
- package/dist/database/index.js +523 -0
- package/dist/database-DRGL5UYS.js +10 -0
- package/dist/database-field-F47FY3XX.js +10 -0
- package/dist/database-row-77OXW2NF.js +10 -0
- package/dist/database-select-option-6S3TTA7A.js +10 -0
- package/dist/database-view-YW7DQG5X.js +10 -0
- package/dist/experiment-TJOAL3OH.js +10 -0
- package/dist/external-item-D654PKLI.js +14 -0
- package/dist/external-reference-K5SUJIQN.js +8 -0
- package/dist/feed-L23XTNDI.js +12 -0
- package/dist/feed-item-GSO242J6.js +12 -0
- package/dist/folder-ONKSWHUT.js +21 -0
- package/dist/game-BF7DP5JU.js +50 -0
- package/dist/grant-NNKMWXPX.js +8 -0
- package/dist/grant-expiration-cleaner-DBiNTWbD.d.ts +249 -0
- package/dist/import-batch-JMESZ4VI.js +12 -0
- package/dist/inbox-state-AN6FPCIY.js +12 -0
- package/dist/index.d.ts +224 -4548
- package/dist/index.js +2206 -4754
- package/dist/map-AUV65YS3.js +10 -0
- package/dist/media-asset-4I5YPR4R.js +8 -0
- package/dist/memory-NV6EVJBE.js +12 -0
- package/dist/metric-X7W55DLC.js +10 -0
- package/dist/milestone-JJGOGK4R.js +12 -0
- package/dist/moderation-QSUVBCNS.js +30 -0
- package/dist/observation-UZSXXGBC.js +10 -0
- package/dist/page-NI7XODS6.js +10 -0
- package/dist/posting-FZOYVGH2.js +12 -0
- package/dist/profile-42A43GES.js +8 -0
- package/dist/project-G2CTLDXY.js +10 -0
- package/dist/query-ast-CWo6_30h.d.ts +226 -0
- package/dist/reaction-VAQBVDUD.js +10 -0
- package/dist/registry-CQoN_p8U.d.ts +99 -0
- package/dist/saved-view-AOQHGHNM.js +10 -0
- package/dist/schema/index.d.ts +6182 -0
- package/dist/schema/index.js +631 -0
- package/dist/schema-extension-5BUXRDPB.js +18 -0
- package/dist/space-PZ737CIS.js +42 -0
- package/dist/space-membership-N35NRX6F.js +14 -0
- package/dist/store/index.d.ts +391 -0
- package/dist/store/index.js +135 -0
- package/dist/store-CvgiydME.d.ts +338 -0
- package/dist/sync/awareness.d.ts +69 -0
- package/dist/sync/awareness.js +20 -0
- package/dist/system-Q5I6STDC.js +38 -0
- package/dist/tag-C677GKQW.js +16 -0
- package/dist/task-WQLMPN5U.js +16 -0
- package/dist/task-view-T5S32V4L.js +10 -0
- package/dist/transaction-U3ITRGJP.js +12 -0
- package/dist/transcription-F3T23LLO.js +12 -0
- package/dist/types-Def-5Nka.d.ts +1525 -0
- package/dist/updates.d.ts +44 -0
- package/dist/updates.js +16 -0
- package/dist/user-widget-4SJJFPG5.js +8 -0
- package/dist/view-types-DSde-uT_.d.ts +316 -0
- package/package.json +32 -9
- package/dist/canvas-HSIKIQFK.js +0 -7
- package/dist/chunk-2L5ZUGG5.js +0 -53
- package/dist/chunk-4MTS5KAQ.js +0 -22
- package/dist/chunk-GZHARFKC.js +0 -25
- package/dist/chunk-WKIKJTI2.js +0 -45
- package/dist/comment-277JD7DV.js +0 -7
- package/dist/database-W3KEHLI3.js +0 -7
- package/dist/database-row-3O2QSNZN.js +0 -7
- package/dist/grant-QVZ454YC.js +0 -7
- package/dist/page-O4WTOIEO.js +0 -7
- package/dist/task-SEKAYJH7.js +0 -7
|
@@ -0,0 +1,882 @@
|
|
|
1
|
+
export { a as CELL_PREFIX, C as CellValue, d2 as CloneSchemaOptions, d3 as CloneSchemaResult, d4 as CloneSourceData, aY as ConvertContext, aZ as ConvertedCell, cY as CreateDatabaseSchemaResolverOptions, ag as CreateExtensionFieldOptions, a0 as CreateFieldOptions, h as CreateRowOptions, a2 as CreateSelectOptionOptions, ao as CreateViewOptions, bz as CsvExportOptions, bk as CsvParseOptions, cN as DATABASE_SCHEMA_NAMESPACE, cO as DATABASE_SCHEMA_PREFIX, aH as DEFAULT_DATABASE_SCHEMA_VERSION, aV as DatabaseDocumentModel, k as DatabaseRowNode, cQ as DatabaseSchemaMetadata, D as DateRange, cX as DocFetcher, af as EnsureExtensionOptions, by as ExportRow, bC as ExportedColumn, bB as ExportedJSON, O as FIELD_TYPES, L as FieldConfig, N as FieldNode, K as FieldType, F as FileRef, cf as FilterableRow, b6 as FormulaRow, b4 as FormulaService, b7 as FormulaValidationResult, ct as GroupAggregates, cr as GroupConfig, cq as GroupableRow, bm as InferredColumn, bA as JsonExportOptions, bn as JsonParseOptions, M as MAX_KEY_LENGTH, cP as MAX_VERSION_HISTORY, c4 as OPERATORS_BY_TYPE, c5 as OPERATOR_LABELS, bj as ParsedCSV, bl as ParsedJSON, cB as QueryOptions, cC as QueryResult, Q as QueryRowsOptions, j as QueryRowsResult, cA as QueryableRow, R as RICHTEXT_PREFIX, b3 as RollupContext, b2 as RollupRow, cs as RowGroup, P as SELECT_COLORS, cS as SchemaVersionEntry, S as SelectOptionNode, aG as SetupDatabaseResult, cl as SortableRow, cR as StoredColumn, a1 as UpdateFieldOptions, ap as UpdateViewOptions, cT as VersionBumpType, an as ViewNode, aP as addDefaultTableView, aO as addDefaultTitleColumn, cj as addOrToggleSort, bW as addViewSort, a_ as aggregate, V as autoColor, b0 as batchComputeRollups, cJ as buildDatabaseSchema, aJ as buildSchemaFromFields, cD as buildSchemaIRI, cH as bumpSchemaVersion, c as cellKey, aX as cellValueToText, s as checkNeedsRebalancing, bU as clearViewFilters, bY as clearViewSorts, c_ as cloneColumns, c$ as cloneSampleRows, cZ as cloneSchema, cp as collapseAllGroups, b as columnIdFromKey, cd as combineFiltersAnd, ce as combineFiltersOr, y as compareSortKeys, a$ as computeRollup, aW as convertCellValue, cc as createAnyOfFilter, bH as createColumn, br as createCsvBlob, cU as createDatabaseSchemaResolver, cb as createEqualsFilter, ac as createExtensionField, a6 as createField, cv as createFilterQuery, b5 as createFormulaService, cI as createInitialSchemaMetadata, bw as createJsonBlob, aL as createNodeDatabaseSchemaResolver, cx as createPaginatedQuery, l as createRow, aj as createSelectOption, ch as createSort, cw as createSortQuery, cK as createVersionEntry, bP as createView, as as createViewNode, bJ as deleteColumn, ae as deleteExtensionField, a8 as deleteField, aT as deleteMeta, I as deleteRichTextCell, n as deleteRow, al as deleteSelectOption, bR as deleteView, au as deleteViewNode, bs as downloadCsv, bx as downloadJson, bL as duplicateColumn, aa as duplicateField, bS as duplicateView, av as duplicateViewNode, aE as effectiveFieldSortKey, ab as ensureSchemaExtension, bp as escapeCSV, cu as executeQuery, co as expandAllGroups, bo as exportToCsv, bt as exportToJson, bu as exportToJsonArray, bv as exportToNdjson, cV as extractSchemaFromDoc, aI as fieldsToStoredColumns, ca as filterRows, cy as flattenGroups, bq as formatValue, f as fromCellProperties, d0 as generateColumnIdMap, v as generateSortKey, w as generateSortKeyWithJitter, d7 as getAggregationResultType, bE as getColumn, bF as getColumnIndex, bD as getColumns, aU as getDatabaseDocumentModel, aK as getDatabaseSchemaIRI, ai as getDatabaseSelectOptions, d5 as getEmptyValue, a4 as getField, a3 as getFields, aR as getMeta, c8 as getOperatorLabel, c6 as getOperatorsForType, B as getRichTextCell, H as getRichTextColumnIds, J as getRichTextPlainText, o as getRow, cW as getSchemaIRIFromDoc, ah as getSelectOptions, bG as getTitleColumn, a5 as getTitleField, cz as getTotalFromGroups, cM as getVersionBumpType, bN as getView, bO as getViewByType, ar as getViewNode, aq as getViewNodes, bM as getViews, cm as groupRows, ba as guessColumnType, G as hasRichTextColumns, E as hasRichTextContent, c1 as hideColumn, bd as inferColumnTypes, bf as inferColumnsFromRows, bg as inferTypeFromValues, aM as initializeDatabaseDoc, Y as isAutoFieldType, i as isCellKey, g as isCellValue, X as isComputedFieldType, aN as isDatabaseDocInitialized, cF as isDatabaseSchemaIRI, d as isDateRange, T as isFieldType, e as isFileRef, W as isNodeStoreFieldType, d6 as isNumericAggregation, U as isSelectColor, c7 as isValidOperator, x as isValidSortKey, Z as isYDocFieldType, a9 as moveField, p as moveRow, am as moveSelectOption, aw as moveView, A as needsRebalancing, c9 as operatorRequiresValue, b8 as parseCSV, b9 as parseCSVLine, cE as parseDatabaseSchemaIRI, be as parseJSON, bc as parseRow, bb as parseValue, cG as parseVersion, cL as pruneVersionHistory, q as queryRows, r as rebalanceDatabase, z as rebalanceSortKeys, d1 as remapViewColumnIds, ck as removeSort, bX as removeViewSort, ad as renameExtensionField, bK as reorderColumn, c2 as reorderViewColumns, c3 as setColumnWidth, aB as setFieldHidden, aS as setMeta, aD as setViewFieldOrder, aC as setViewFieldWidth, bT as setViewFilters, bZ as setViewGroupBy, ax as setViewNodeFilters, az as setViewNodeGroupBy, ay as setViewNodeSorts, bV as setViewSorts, b$ as setVisibleColumns, aF as setupDatabase, aQ as setupNewDatabase, c0 as showColumn, cg as sortRows, t as toCellProperties, bh as toColumnDefinitions, _ as toFieldNode, $ as toSelectOptionNode, b_ as toggleGroupCollapsed, cn as toggleGroupCollapsedState, ci as toggleSortDirection, aA as toggleViewGroupCollapsed, u as updateCell, m as updateCells, bI as updateColumn, a7 as updateField, ak as updateSelectOption, bQ as updateView, at as updateViewNode, bi as validateJsonData, b1 as validateRollupConfig } from '../clone-DpbVKLUu.js';
|
|
2
|
+
import { m as FilterGroup, c as ColumnDefinition, C as ColumnType, V as ViewType, p as SortConfig } from '../view-types-DSde-uT_.js';
|
|
3
|
+
export { d as ColumnConfig, B as ColumnSummaryResult, I as DEFAULT_ROW_HEIGHT, D as DateColumnConfig, D as DateFieldConfig, E as EmptyConfig, b as FileColumnConfig, b as FileFieldConfig, n as FilterCondition, o as FilterOperator, F as FormulaColumnConfig, F as FormulaFieldConfig, N as NumberColumnConfig, N as NumberFieldConfig, H as ROW_HEIGHTS, G as ROW_HEIGHT_PX, R as RelationColumnConfig, R as RelationFieldConfig, g as RollupAggregation, a as RollupColumnConfig, a as RollupFieldConfig, M as RowHeight, u as SUMMARY_FUNCTIONS_BY_TYPE, f as SelectColor, S as SelectColumnConfig, e as SelectOption, A as SummaryColumnLike, y as SummaryFunction, z as SummaryRow, T as TextColumnConfig, T as TextFieldConfig, l as ViewConfig, L as asRowHeight, x as computeColumnSummary, j as isAutoColumnType, h as isComputedColumnType, w as isFilledValue, r as isFilterCondition, q as isFilterGroup, i as isNodeStoreColumnType, k as isYDocColumnType, t as requiresDateColumn, K as resolveRowHeightPx, J as rowHeightLabel, v as summaryFunctionLabel, s as supportsGrouping } from '../view-types-DSde-uT_.js';
|
|
4
|
+
import '../types-Def-5Nka.js';
|
|
5
|
+
import '@xnetjs/core';
|
|
6
|
+
import '@xnetjs/crypto';
|
|
7
|
+
import '@xnetjs/sqlite';
|
|
8
|
+
import '@xnetjs/sync';
|
|
9
|
+
import '../store-CvgiydME.js';
|
|
10
|
+
import 'yjs';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @xnetjs/data - Query router for automatic local/hub query routing.
|
|
14
|
+
*
|
|
15
|
+
* Determines whether to execute queries locally (in-memory) or on the hub
|
|
16
|
+
* server based on dataset size and query complexity.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Query source: where the query will be executed.
|
|
21
|
+
*/
|
|
22
|
+
type QuerySource = 'local' | 'hub' | 'hybrid';
|
|
23
|
+
/**
|
|
24
|
+
* Configuration for the query router.
|
|
25
|
+
*/
|
|
26
|
+
type QueryRouterConfig = {
|
|
27
|
+
/** Max rows for local queries (default: 10,000) */
|
|
28
|
+
localThreshold: number;
|
|
29
|
+
/** Max rows for hybrid queries (default: 100,000) */
|
|
30
|
+
hybridThreshold: number;
|
|
31
|
+
/** Force hub for complex filters (default: true) */
|
|
32
|
+
complexFilterToHub: boolean;
|
|
33
|
+
/** Force hub for full-text search (default: true) */
|
|
34
|
+
searchToHub: boolean;
|
|
35
|
+
/** Max conditions before filter is considered complex (default: 5) */
|
|
36
|
+
complexFilterThreshold: number;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Result of routing decision.
|
|
40
|
+
*/
|
|
41
|
+
type QueryRouterResult = {
|
|
42
|
+
source: QuerySource;
|
|
43
|
+
reason: string;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Options for routing decision.
|
|
47
|
+
*/
|
|
48
|
+
type RouteOptions = {
|
|
49
|
+
rowCount: number;
|
|
50
|
+
filters?: FilterGroup;
|
|
51
|
+
search?: string;
|
|
52
|
+
hasHubConnection: boolean;
|
|
53
|
+
};
|
|
54
|
+
declare const DEFAULT_ROUTER_CONFIG: QueryRouterConfig;
|
|
55
|
+
/**
|
|
56
|
+
* Query router that determines optimal query execution location.
|
|
57
|
+
*
|
|
58
|
+
* Routing logic:
|
|
59
|
+
* 1. Full-text search always goes to hub (FTS5)
|
|
60
|
+
* 2. Complex filters go to hub for SQL efficiency
|
|
61
|
+
* 3. Small datasets (< 10K) stay local
|
|
62
|
+
* 4. Medium datasets (10K-100K) use hybrid approach
|
|
63
|
+
* 5. Large datasets (> 100K) go to hub
|
|
64
|
+
* 6. Falls back to local if no hub connection
|
|
65
|
+
*/
|
|
66
|
+
declare class QueryRouter {
|
|
67
|
+
private config;
|
|
68
|
+
constructor(config?: Partial<QueryRouterConfig>);
|
|
69
|
+
/**
|
|
70
|
+
* Determine where to execute a query.
|
|
71
|
+
*/
|
|
72
|
+
route(options: RouteOptions): QueryRouterResult;
|
|
73
|
+
/**
|
|
74
|
+
* Check if a filter is complex enough to warrant hub execution.
|
|
75
|
+
*
|
|
76
|
+
* A filter is considered complex if:
|
|
77
|
+
* - It has more than N conditions (default: 5)
|
|
78
|
+
* - It has nested groups
|
|
79
|
+
*/
|
|
80
|
+
isComplexFilter(filter: FilterGroup): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Get the current configuration.
|
|
83
|
+
*/
|
|
84
|
+
getConfig(): QueryRouterConfig;
|
|
85
|
+
/**
|
|
86
|
+
* Update configuration.
|
|
87
|
+
*/
|
|
88
|
+
setConfig(config: Partial<QueryRouterConfig>): void;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Create a query router with optional configuration.
|
|
92
|
+
*/
|
|
93
|
+
declare function createQueryRouter(config?: Partial<QueryRouterConfig>): QueryRouter;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @xnetjs/data - LRU row cache for hybrid queries.
|
|
97
|
+
*
|
|
98
|
+
* Caches recently fetched rows to avoid re-fetching from the hub.
|
|
99
|
+
* Uses LRU (Least Recently Used) eviction policy.
|
|
100
|
+
*/
|
|
101
|
+
/**
|
|
102
|
+
* A cached database row.
|
|
103
|
+
*/
|
|
104
|
+
type CachedRow<T = Record<string, unknown>> = {
|
|
105
|
+
id: string;
|
|
106
|
+
databaseId: string;
|
|
107
|
+
sortKey: string;
|
|
108
|
+
cells: T;
|
|
109
|
+
createdAt: number;
|
|
110
|
+
createdBy: string;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Configuration for the row cache.
|
|
114
|
+
*/
|
|
115
|
+
type RowCacheConfig = {
|
|
116
|
+
/** Maximum number of rows to cache (default: 10,000) */
|
|
117
|
+
maxSize: number;
|
|
118
|
+
/** Maximum age of cached rows in ms (default: 5 minutes) */
|
|
119
|
+
maxAge: number;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Cache statistics.
|
|
123
|
+
*/
|
|
124
|
+
type CacheStats = {
|
|
125
|
+
size: number;
|
|
126
|
+
hits: number;
|
|
127
|
+
misses: number;
|
|
128
|
+
evictions: number;
|
|
129
|
+
};
|
|
130
|
+
declare const DEFAULT_CACHE_CONFIG: RowCacheConfig;
|
|
131
|
+
/**
|
|
132
|
+
* LRU cache for database rows.
|
|
133
|
+
*
|
|
134
|
+
* Features:
|
|
135
|
+
* - LRU eviction when at capacity
|
|
136
|
+
* - TTL-based expiration
|
|
137
|
+
* - Per-database invalidation
|
|
138
|
+
* - Cache statistics
|
|
139
|
+
*/
|
|
140
|
+
declare class RowCache<T = Record<string, unknown>> {
|
|
141
|
+
private cache;
|
|
142
|
+
private config;
|
|
143
|
+
private stats;
|
|
144
|
+
constructor(config?: Partial<RowCacheConfig>);
|
|
145
|
+
/**
|
|
146
|
+
* Get a row from the cache.
|
|
147
|
+
* Returns undefined if not found or expired.
|
|
148
|
+
*/
|
|
149
|
+
get(id: string): CachedRow<T> | undefined;
|
|
150
|
+
/**
|
|
151
|
+
* Get multiple rows from the cache.
|
|
152
|
+
* Returns only the rows that are found and not expired.
|
|
153
|
+
*/
|
|
154
|
+
getMany(ids: string[]): Map<string, CachedRow<T>>;
|
|
155
|
+
/**
|
|
156
|
+
* Add a row to the cache.
|
|
157
|
+
*/
|
|
158
|
+
set(id: string, row: CachedRow<T>): void;
|
|
159
|
+
/**
|
|
160
|
+
* Add multiple rows to the cache.
|
|
161
|
+
*/
|
|
162
|
+
setMany(rows: CachedRow<T>[]): void;
|
|
163
|
+
/**
|
|
164
|
+
* Check if a row is in the cache (and not expired).
|
|
165
|
+
*/
|
|
166
|
+
has(id: string): boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Invalidate a single row.
|
|
169
|
+
*/
|
|
170
|
+
invalidate(id: string): void;
|
|
171
|
+
/**
|
|
172
|
+
* Invalidate multiple rows.
|
|
173
|
+
*/
|
|
174
|
+
invalidateMany(ids: string[]): void;
|
|
175
|
+
/**
|
|
176
|
+
* Invalidate all rows for a database.
|
|
177
|
+
*/
|
|
178
|
+
invalidateDatabase(databaseId: string): void;
|
|
179
|
+
/**
|
|
180
|
+
* Clear all cached rows.
|
|
181
|
+
*/
|
|
182
|
+
clear(): void;
|
|
183
|
+
/**
|
|
184
|
+
* Get cache statistics.
|
|
185
|
+
*/
|
|
186
|
+
getStats(): CacheStats;
|
|
187
|
+
/**
|
|
188
|
+
* Reset statistics.
|
|
189
|
+
*/
|
|
190
|
+
resetStats(): void;
|
|
191
|
+
/**
|
|
192
|
+
* Get the current size of the cache.
|
|
193
|
+
*/
|
|
194
|
+
get size(): number;
|
|
195
|
+
/**
|
|
196
|
+
* Get the hit rate (hits / total requests).
|
|
197
|
+
*/
|
|
198
|
+
get hitRate(): number;
|
|
199
|
+
/**
|
|
200
|
+
* Prune expired entries.
|
|
201
|
+
* Call periodically to free memory.
|
|
202
|
+
*/
|
|
203
|
+
prune(): number;
|
|
204
|
+
/**
|
|
205
|
+
* Get all cached row IDs for a database.
|
|
206
|
+
*/
|
|
207
|
+
getIdsForDatabase(databaseId: string): string[];
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Create a row cache with optional configuration.
|
|
211
|
+
*/
|
|
212
|
+
declare function createRowCache<T = Record<string, unknown>>(config?: Partial<RowCacheConfig>): RowCache<T>;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Formula expression parser.
|
|
216
|
+
*
|
|
217
|
+
* Parses formula expressions into an AST for evaluation.
|
|
218
|
+
* Supports arithmetic, comparison, logical operators, function calls,
|
|
219
|
+
* and column references using {{columnId}} syntax.
|
|
220
|
+
*/
|
|
221
|
+
type ASTNode = LiteralNode | ReferenceNode | BinaryNode | UnaryNode | CallNode | ConditionalNode;
|
|
222
|
+
interface LiteralNode {
|
|
223
|
+
type: 'literal';
|
|
224
|
+
value: unknown;
|
|
225
|
+
}
|
|
226
|
+
interface ReferenceNode {
|
|
227
|
+
type: 'reference';
|
|
228
|
+
columnId: string;
|
|
229
|
+
property?: string;
|
|
230
|
+
}
|
|
231
|
+
interface BinaryNode {
|
|
232
|
+
type: 'binary';
|
|
233
|
+
operator: string;
|
|
234
|
+
left: ASTNode;
|
|
235
|
+
right: ASTNode;
|
|
236
|
+
}
|
|
237
|
+
interface UnaryNode {
|
|
238
|
+
type: 'unary';
|
|
239
|
+
operator: string;
|
|
240
|
+
operand: ASTNode;
|
|
241
|
+
}
|
|
242
|
+
interface CallNode {
|
|
243
|
+
type: 'call';
|
|
244
|
+
name: string;
|
|
245
|
+
args: ASTNode[];
|
|
246
|
+
}
|
|
247
|
+
interface ConditionalNode {
|
|
248
|
+
type: 'conditional';
|
|
249
|
+
condition: ASTNode;
|
|
250
|
+
then: ASTNode;
|
|
251
|
+
else: ASTNode;
|
|
252
|
+
}
|
|
253
|
+
declare class FormulaParser {
|
|
254
|
+
private pos;
|
|
255
|
+
private expr;
|
|
256
|
+
private lastMatch;
|
|
257
|
+
/**
|
|
258
|
+
* Parse a formula expression into an AST.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```typescript
|
|
262
|
+
* const parser = new FormulaParser()
|
|
263
|
+
* const ast = parser.parse('{{price}} * {{quantity}}')
|
|
264
|
+
* ```
|
|
265
|
+
*/
|
|
266
|
+
parse(expression: string): ASTNode;
|
|
267
|
+
private parseExpression;
|
|
268
|
+
private parseOr;
|
|
269
|
+
private parseAnd;
|
|
270
|
+
private parseEquality;
|
|
271
|
+
private parseComparison;
|
|
272
|
+
private parseAdditive;
|
|
273
|
+
/**
|
|
274
|
+
* Match a single '&' but not '&&'.
|
|
275
|
+
*/
|
|
276
|
+
private matchSingleAmpersand;
|
|
277
|
+
private parseMultiplicative;
|
|
278
|
+
private parseUnary;
|
|
279
|
+
private parsePrimary;
|
|
280
|
+
private parseNumber;
|
|
281
|
+
private parseString;
|
|
282
|
+
private parseIdentifier;
|
|
283
|
+
private peek;
|
|
284
|
+
private peekNext;
|
|
285
|
+
private check;
|
|
286
|
+
private match;
|
|
287
|
+
private matchAny;
|
|
288
|
+
private expect;
|
|
289
|
+
private skipWhitespace;
|
|
290
|
+
private isDigit;
|
|
291
|
+
private isAlpha;
|
|
292
|
+
private isAlphaNumeric;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Formula expression evaluator.
|
|
297
|
+
*
|
|
298
|
+
* Evaluates an AST against a row context to produce a value.
|
|
299
|
+
*/
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Context for evaluating a formula.
|
|
303
|
+
*/
|
|
304
|
+
interface EvalContext {
|
|
305
|
+
/** Get column value for current row */
|
|
306
|
+
getValue: (columnId: string) => unknown;
|
|
307
|
+
/** Get column definition */
|
|
308
|
+
getColumn: (columnId: string) => ColumnDefinition | undefined;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Evaluate an AST node against a context.
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
* ```typescript
|
|
315
|
+
* const context = {
|
|
316
|
+
* getValue: (id) => row.cells[id],
|
|
317
|
+
* getColumn: (id) => columns.find(c => c.id === id)
|
|
318
|
+
* }
|
|
319
|
+
* const result = evaluate(ast, context)
|
|
320
|
+
* ```
|
|
321
|
+
*/
|
|
322
|
+
declare function evaluate(node: ASTNode, context: EvalContext): unknown;
|
|
323
|
+
/**
|
|
324
|
+
* Safely evaluate a formula, catching errors.
|
|
325
|
+
*/
|
|
326
|
+
declare function safeEvaluate(node: ASTNode, context: EvalContext): {
|
|
327
|
+
value: unknown;
|
|
328
|
+
error?: string;
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Built-in formula functions.
|
|
333
|
+
*
|
|
334
|
+
* Provides a library of functions for use in formula expressions:
|
|
335
|
+
* - Math: ABS, ROUND, FLOOR, CEIL, MIN, MAX, SUM, AVG, POW, SQRT
|
|
336
|
+
* - Text: CONCAT, UPPER, LOWER, TRIM, LENGTH, SUBSTRING, REPLACE, LEFT, RIGHT
|
|
337
|
+
* - Logic: IF, AND, OR, NOT, COALESCE, ISBLANK
|
|
338
|
+
* - Date: NOW, TODAY, DATE, YEAR, MONTH, DAY, DATEADD, DATEDIFF
|
|
339
|
+
* - Array: CONTAINS, COUNT, FIRST, LAST, JOIN, UNIQUE
|
|
340
|
+
*/
|
|
341
|
+
type FormulaFunction = (...args: unknown[]) => unknown;
|
|
342
|
+
declare const FUNCTIONS: Record<string, FormulaFunction>;
|
|
343
|
+
/**
|
|
344
|
+
* Check if a function name is valid.
|
|
345
|
+
*/
|
|
346
|
+
declare function isValidFunction(name: string): boolean;
|
|
347
|
+
/**
|
|
348
|
+
* Get a function by name.
|
|
349
|
+
*/
|
|
350
|
+
declare function getFunction(name: string): FormulaFunction | undefined;
|
|
351
|
+
/**
|
|
352
|
+
* Get all available function names.
|
|
353
|
+
*/
|
|
354
|
+
declare function getFunctionNames(): string[];
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Formula dependency tracking and circular detection.
|
|
358
|
+
*
|
|
359
|
+
* Extracts column dependencies from formulas and detects circular references.
|
|
360
|
+
*/
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Extract column dependencies from a formula expression.
|
|
364
|
+
*
|
|
365
|
+
* @example
|
|
366
|
+
* ```typescript
|
|
367
|
+
* const deps = extractDependencies('{{price}} * {{quantity}}')
|
|
368
|
+
* // ['price', 'quantity']
|
|
369
|
+
* ```
|
|
370
|
+
*/
|
|
371
|
+
declare function extractDependencies(expression: string): string[];
|
|
372
|
+
interface CircularCheckResult {
|
|
373
|
+
hasCircular: boolean;
|
|
374
|
+
cycle?: string[];
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Check for circular dependencies between formula columns.
|
|
378
|
+
*
|
|
379
|
+
* @example
|
|
380
|
+
* ```typescript
|
|
381
|
+
* const result = detectCircularDependencies(columns)
|
|
382
|
+
* if (result.hasCircular) {
|
|
383
|
+
* console.log('Circular dependency:', result.cycle)
|
|
384
|
+
* }
|
|
385
|
+
* ```
|
|
386
|
+
*/
|
|
387
|
+
declare function detectCircularDependencies(columns: ColumnDefinition[]): CircularCheckResult;
|
|
388
|
+
/**
|
|
389
|
+
* Check if adding a formula would create a circular dependency.
|
|
390
|
+
*
|
|
391
|
+
* @example
|
|
392
|
+
* ```typescript
|
|
393
|
+
* const wouldCycle = wouldCreateCircular('total', '{{subtotal}} + {{tax}}', columns)
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
396
|
+
declare function wouldCreateCircular(columnId: string, expression: string, columns: ColumnDefinition[]): boolean;
|
|
397
|
+
interface DependencyGraph {
|
|
398
|
+
/** columnId -> column IDs it depends on */
|
|
399
|
+
columnDeps: Map<string, string[]>;
|
|
400
|
+
/** columnId -> column IDs that depend on it */
|
|
401
|
+
reverseDeps: Map<string, string[]>;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Build a dependency graph for all columns.
|
|
405
|
+
*
|
|
406
|
+
* @example
|
|
407
|
+
* ```typescript
|
|
408
|
+
* const graph = buildDependencyGraph(columns)
|
|
409
|
+
* const affectedColumns = graph.reverseDeps.get('price') // Columns that depend on price
|
|
410
|
+
* ```
|
|
411
|
+
*/
|
|
412
|
+
declare function buildDependencyGraph(columns: ColumnDefinition[]): DependencyGraph;
|
|
413
|
+
/**
|
|
414
|
+
* Get all columns that need recomputing when a column changes.
|
|
415
|
+
* Traverses the dependency graph to find all affected columns.
|
|
416
|
+
*
|
|
417
|
+
* @example
|
|
418
|
+
* ```typescript
|
|
419
|
+
* const affected = getAffectedColumns('price', graph)
|
|
420
|
+
* // Returns all columns that depend on 'price' (directly or indirectly)
|
|
421
|
+
* ```
|
|
422
|
+
*/
|
|
423
|
+
declare function getAffectedColumns(changedColumnId: string, graph: DependencyGraph): string[];
|
|
424
|
+
/**
|
|
425
|
+
* Get the evaluation order for formula columns.
|
|
426
|
+
* Returns columns in topological order (dependencies first).
|
|
427
|
+
*
|
|
428
|
+
* @example
|
|
429
|
+
* ```typescript
|
|
430
|
+
* const order = getEvaluationOrder(columns)
|
|
431
|
+
* // Evaluate formulas in this order to ensure dependencies are computed first
|
|
432
|
+
* ```
|
|
433
|
+
*/
|
|
434
|
+
declare function getEvaluationOrder(columns: ColumnDefinition[]): ColumnDefinition[];
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Computed value cache for rollups and formulas.
|
|
438
|
+
*
|
|
439
|
+
* Provides efficient caching with LRU eviction, TTL expiration,
|
|
440
|
+
* and dependency-based invalidation.
|
|
441
|
+
*/
|
|
442
|
+
/**
|
|
443
|
+
* A cached computed value entry.
|
|
444
|
+
*/
|
|
445
|
+
interface ComputedCacheEntry {
|
|
446
|
+
/** The computed value */
|
|
447
|
+
value: unknown;
|
|
448
|
+
/** When the value was computed (timestamp) */
|
|
449
|
+
computedAt: number;
|
|
450
|
+
/** Hash of inputs used to compute (for validation) */
|
|
451
|
+
inputHash: string;
|
|
452
|
+
/** Row IDs this value depends on */
|
|
453
|
+
dependencies: string[];
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Configuration for the computed cache.
|
|
457
|
+
*/
|
|
458
|
+
interface ComputedCacheConfig {
|
|
459
|
+
/** Maximum entries in memory cache */
|
|
460
|
+
maxSize: number;
|
|
461
|
+
/** Maximum age before recompute (ms) */
|
|
462
|
+
maxAge: number;
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Cache statistics.
|
|
466
|
+
*/
|
|
467
|
+
interface ComputedCacheStats {
|
|
468
|
+
/** Number of entries in cache */
|
|
469
|
+
size: number;
|
|
470
|
+
/** Number of cache hits */
|
|
471
|
+
hits: number;
|
|
472
|
+
/** Number of cache misses */
|
|
473
|
+
misses: number;
|
|
474
|
+
/** Hit rate (0-1) */
|
|
475
|
+
hitRate: number;
|
|
476
|
+
/** Number of evictions */
|
|
477
|
+
evictions: number;
|
|
478
|
+
/** Number of invalidations */
|
|
479
|
+
invalidations: number;
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Default cache configuration.
|
|
483
|
+
*/
|
|
484
|
+
declare const DEFAULT_COMPUTED_CACHE_CONFIG: ComputedCacheConfig;
|
|
485
|
+
/**
|
|
486
|
+
* In-memory cache for computed column values.
|
|
487
|
+
*
|
|
488
|
+
* Features:
|
|
489
|
+
* - LRU eviction when at capacity
|
|
490
|
+
* - TTL-based expiration
|
|
491
|
+
* - Dependency-based invalidation
|
|
492
|
+
* - Cache statistics
|
|
493
|
+
*
|
|
494
|
+
* @example
|
|
495
|
+
* ```typescript
|
|
496
|
+
* const cache = new ComputedCache()
|
|
497
|
+
*
|
|
498
|
+
* // Store a computed value
|
|
499
|
+
* cache.set('row-1', 'total', {
|
|
500
|
+
* value: 100,
|
|
501
|
+
* computedAt: Date.now(),
|
|
502
|
+
* inputHash: 'abc123',
|
|
503
|
+
* dependencies: ['row-2', 'row-3']
|
|
504
|
+
* })
|
|
505
|
+
*
|
|
506
|
+
* // Retrieve
|
|
507
|
+
* const entry = cache.get('row-1', 'total')
|
|
508
|
+
*
|
|
509
|
+
* // Invalidate when a dependency changes
|
|
510
|
+
* cache.invalidate('row-2')
|
|
511
|
+
* ```
|
|
512
|
+
*/
|
|
513
|
+
declare class ComputedCache {
|
|
514
|
+
private config;
|
|
515
|
+
private memory;
|
|
516
|
+
private dependencyIndex;
|
|
517
|
+
private accessOrder;
|
|
518
|
+
private stats;
|
|
519
|
+
constructor(config?: ComputedCacheConfig);
|
|
520
|
+
/**
|
|
521
|
+
* Get a cached computed value.
|
|
522
|
+
* Returns null if not found or expired.
|
|
523
|
+
*/
|
|
524
|
+
get(rowId: string, columnId: string): ComputedCacheEntry | null;
|
|
525
|
+
/**
|
|
526
|
+
* Store a computed value.
|
|
527
|
+
*/
|
|
528
|
+
set(rowId: string, columnId: string, entry: ComputedCacheEntry): void;
|
|
529
|
+
/**
|
|
530
|
+
* Check if a value exists and is valid.
|
|
531
|
+
*/
|
|
532
|
+
has(rowId: string, columnId: string): boolean;
|
|
533
|
+
/**
|
|
534
|
+
* Invalidate all computed values that depend on a row.
|
|
535
|
+
*/
|
|
536
|
+
invalidate(rowId: string): void;
|
|
537
|
+
/**
|
|
538
|
+
* Invalidate a specific computed value.
|
|
539
|
+
*/
|
|
540
|
+
invalidateCell(rowId: string, columnId: string): void;
|
|
541
|
+
/**
|
|
542
|
+
* Invalidate all computed values for a database.
|
|
543
|
+
*/
|
|
544
|
+
invalidateDatabase(_databaseId: string): void;
|
|
545
|
+
/**
|
|
546
|
+
* Clear all cached values.
|
|
547
|
+
*/
|
|
548
|
+
clear(): void;
|
|
549
|
+
/**
|
|
550
|
+
* Get cache statistics.
|
|
551
|
+
*/
|
|
552
|
+
getStats(): ComputedCacheStats;
|
|
553
|
+
/**
|
|
554
|
+
* Reset statistics.
|
|
555
|
+
*/
|
|
556
|
+
resetStats(): void;
|
|
557
|
+
private cacheKey;
|
|
558
|
+
private isExpired;
|
|
559
|
+
private evictOldest;
|
|
560
|
+
private updateAccessOrder;
|
|
561
|
+
private removeFromAccessOrder;
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Create a new ComputedCache instance.
|
|
565
|
+
*/
|
|
566
|
+
declare function createComputedCache(config?: Partial<ComputedCacheConfig>): ComputedCache;
|
|
567
|
+
/**
|
|
568
|
+
* Batch invalidate for bulk operations.
|
|
569
|
+
*/
|
|
570
|
+
declare function batchInvalidate(cache: ComputedCache, rowIds: string[]): void;
|
|
571
|
+
/**
|
|
572
|
+
* Compute a hash for input values.
|
|
573
|
+
* Used to detect when cached values are stale.
|
|
574
|
+
*/
|
|
575
|
+
declare function computeInputHash(values: Record<string, unknown>): string;
|
|
576
|
+
/**
|
|
577
|
+
* Check if a cached entry is still valid based on current inputs.
|
|
578
|
+
*/
|
|
579
|
+
declare function isEntryValid(entry: ComputedCacheEntry, currentInputs: Record<string, unknown>): boolean;
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* Template type definitions for database templates.
|
|
583
|
+
*
|
|
584
|
+
* Templates provide pre-built database structures that can be
|
|
585
|
+
* instantiated to create new databases.
|
|
586
|
+
*/
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* A database template definition.
|
|
590
|
+
*/
|
|
591
|
+
interface DatabaseTemplate {
|
|
592
|
+
/** Unique template ID */
|
|
593
|
+
id: string;
|
|
594
|
+
/** Human-readable name */
|
|
595
|
+
name: string;
|
|
596
|
+
/** Short description */
|
|
597
|
+
description: string;
|
|
598
|
+
/** Icon (emoji or icon name) */
|
|
599
|
+
icon: string;
|
|
600
|
+
/** Category for organization */
|
|
601
|
+
category: TemplateCategory;
|
|
602
|
+
/** Column definitions */
|
|
603
|
+
columns: TemplateColumn[];
|
|
604
|
+
/** View definitions */
|
|
605
|
+
views: TemplateView[];
|
|
606
|
+
/** Optional sample data rows */
|
|
607
|
+
sampleData?: TemplateSampleRow[];
|
|
608
|
+
/** Template metadata */
|
|
609
|
+
metadata: TemplateMetadata;
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* Template categories for organization.
|
|
613
|
+
*/
|
|
614
|
+
type TemplateCategory = 'project-management' | 'crm' | 'inventory' | 'content' | 'personal' | 'education' | 'finance' | 'custom';
|
|
615
|
+
/**
|
|
616
|
+
* Column definition within a template.
|
|
617
|
+
* Uses placeholder IDs that are remapped on instantiation.
|
|
618
|
+
*/
|
|
619
|
+
interface TemplateColumn {
|
|
620
|
+
/** Placeholder ID (will be remapped on instantiation) */
|
|
621
|
+
id: string;
|
|
622
|
+
/** Column name */
|
|
623
|
+
name: string;
|
|
624
|
+
/** Column type */
|
|
625
|
+
type: ColumnType;
|
|
626
|
+
/** Type-specific configuration */
|
|
627
|
+
config: Record<string, unknown>;
|
|
628
|
+
/** Whether this is the title column */
|
|
629
|
+
isTitle?: boolean;
|
|
630
|
+
/** Default width in pixels */
|
|
631
|
+
width?: number;
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* View definition within a template.
|
|
635
|
+
*/
|
|
636
|
+
interface TemplateView {
|
|
637
|
+
/** Placeholder ID */
|
|
638
|
+
id: string;
|
|
639
|
+
/** View name */
|
|
640
|
+
name: string;
|
|
641
|
+
/** View type */
|
|
642
|
+
type: ViewType;
|
|
643
|
+
/** Visible column IDs (placeholders) */
|
|
644
|
+
visibleColumns: string[];
|
|
645
|
+
/** Filter configuration */
|
|
646
|
+
filters?: FilterGroup;
|
|
647
|
+
/** Sort configuration */
|
|
648
|
+
sorts?: SortConfig[];
|
|
649
|
+
/** Group by column ID (placeholder) */
|
|
650
|
+
groupBy?: string;
|
|
651
|
+
/** Column widths */
|
|
652
|
+
columnWidths?: Record<string, number>;
|
|
653
|
+
}
|
|
654
|
+
/**
|
|
655
|
+
* Sample data row within a template.
|
|
656
|
+
*/
|
|
657
|
+
interface TemplateSampleRow {
|
|
658
|
+
/** Cell values keyed by column placeholder ID */
|
|
659
|
+
cells: Record<string, unknown>;
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Template metadata.
|
|
663
|
+
*/
|
|
664
|
+
interface TemplateMetadata {
|
|
665
|
+
/** Template version */
|
|
666
|
+
version: string;
|
|
667
|
+
/** Author DID (for user templates) */
|
|
668
|
+
author?: string;
|
|
669
|
+
/** Creation timestamp */
|
|
670
|
+
createdAt: string;
|
|
671
|
+
/** Last updated timestamp */
|
|
672
|
+
updatedAt: string;
|
|
673
|
+
/** Usage count (for popularity sorting) */
|
|
674
|
+
usageCount?: number;
|
|
675
|
+
/** Tags for search */
|
|
676
|
+
tags: string[];
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* Options for instantiating a template.
|
|
680
|
+
*/
|
|
681
|
+
interface InstantiateOptions {
|
|
682
|
+
/** Include sample data rows (default: true) */
|
|
683
|
+
includeSampleData?: boolean;
|
|
684
|
+
/** Override database name */
|
|
685
|
+
name?: string;
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* Result of instantiating a template.
|
|
689
|
+
*/
|
|
690
|
+
interface InstantiatedDatabase {
|
|
691
|
+
/** New database ID */
|
|
692
|
+
id: string;
|
|
693
|
+
/** Database name */
|
|
694
|
+
name: string;
|
|
695
|
+
/** Column definitions with real IDs */
|
|
696
|
+
columns: InstantiatedColumn[];
|
|
697
|
+
/** View definitions with real IDs */
|
|
698
|
+
views: InstantiatedView[];
|
|
699
|
+
/** Sample data rows with real IDs */
|
|
700
|
+
rows: InstantiatedRow[];
|
|
701
|
+
/** Mapping from template column IDs to real IDs */
|
|
702
|
+
columnIdMap: Map<string, string>;
|
|
703
|
+
/** Mapping from template view IDs to real IDs */
|
|
704
|
+
viewIdMap: Map<string, string>;
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Instantiated column with real ID.
|
|
708
|
+
*/
|
|
709
|
+
interface InstantiatedColumn {
|
|
710
|
+
id: string;
|
|
711
|
+
name: string;
|
|
712
|
+
type: ColumnType;
|
|
713
|
+
config: Record<string, unknown>;
|
|
714
|
+
isTitle?: boolean;
|
|
715
|
+
width?: number;
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* Instantiated view with real ID.
|
|
719
|
+
*/
|
|
720
|
+
interface InstantiatedView {
|
|
721
|
+
id: string;
|
|
722
|
+
name: string;
|
|
723
|
+
type: ViewType;
|
|
724
|
+
visibleColumns: string[];
|
|
725
|
+
filters?: FilterGroup;
|
|
726
|
+
sorts?: SortConfig[];
|
|
727
|
+
groupBy?: string;
|
|
728
|
+
columnWidths?: Record<string, number>;
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* Instantiated row with real ID.
|
|
732
|
+
*/
|
|
733
|
+
interface InstantiatedRow {
|
|
734
|
+
id: string;
|
|
735
|
+
sortKey: string;
|
|
736
|
+
cells: Record<string, unknown>;
|
|
737
|
+
}
|
|
738
|
+
/**
|
|
739
|
+
* Options for saving a database as a template.
|
|
740
|
+
*/
|
|
741
|
+
interface SaveTemplateOptions {
|
|
742
|
+
/** Template name */
|
|
743
|
+
name: string;
|
|
744
|
+
/** Template description */
|
|
745
|
+
description: string;
|
|
746
|
+
/** Template icon (default: clipboard emoji) */
|
|
747
|
+
icon?: string;
|
|
748
|
+
/** Template category (default: custom) */
|
|
749
|
+
category?: TemplateCategory;
|
|
750
|
+
/** Include current data as sample data (default: false) */
|
|
751
|
+
includeSampleData?: boolean;
|
|
752
|
+
/** Maximum sample rows to include (default: 5) */
|
|
753
|
+
maxSampleRows?: number;
|
|
754
|
+
/** Tags for search */
|
|
755
|
+
tags?: string[];
|
|
756
|
+
/** Author DID */
|
|
757
|
+
authorDid?: string;
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* Database structure for creating a template.
|
|
761
|
+
*/
|
|
762
|
+
interface DatabaseForTemplate {
|
|
763
|
+
name: string;
|
|
764
|
+
columns: Array<{
|
|
765
|
+
id: string;
|
|
766
|
+
name: string;
|
|
767
|
+
type: ColumnType;
|
|
768
|
+
config: Record<string, unknown>;
|
|
769
|
+
isTitle?: boolean;
|
|
770
|
+
width?: number;
|
|
771
|
+
}>;
|
|
772
|
+
views: Array<{
|
|
773
|
+
id: string;
|
|
774
|
+
name: string;
|
|
775
|
+
type: ViewType;
|
|
776
|
+
visibleColumns: string[];
|
|
777
|
+
filters?: FilterGroup;
|
|
778
|
+
sorts?: SortConfig[];
|
|
779
|
+
groupBy?: string;
|
|
780
|
+
columnWidths?: Record<string, number>;
|
|
781
|
+
}>;
|
|
782
|
+
rows: Array<{
|
|
783
|
+
id: string;
|
|
784
|
+
sortKey: string;
|
|
785
|
+
cells: Record<string, unknown>;
|
|
786
|
+
}>;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
/**
|
|
790
|
+
* Built-in database templates.
|
|
791
|
+
*
|
|
792
|
+
* Provides ready-to-use templates for common use cases:
|
|
793
|
+
* - Project Tracker
|
|
794
|
+
* - Task List
|
|
795
|
+
* - CRM Contacts
|
|
796
|
+
* - Inventory Tracker
|
|
797
|
+
* - Content Calendar
|
|
798
|
+
* - Reading List
|
|
799
|
+
* - Expense Tracker
|
|
800
|
+
* - Course Planner
|
|
801
|
+
*/
|
|
802
|
+
|
|
803
|
+
declare const BUILTIN_TEMPLATES: DatabaseTemplate[];
|
|
804
|
+
/**
|
|
805
|
+
* Get templates by category.
|
|
806
|
+
*/
|
|
807
|
+
declare function getTemplatesByCategory(category: TemplateCategory): DatabaseTemplate[];
|
|
808
|
+
/**
|
|
809
|
+
* Search templates by name, description, or tags.
|
|
810
|
+
*/
|
|
811
|
+
declare function searchTemplates(query: string): DatabaseTemplate[];
|
|
812
|
+
/**
|
|
813
|
+
* Get a template by ID.
|
|
814
|
+
*/
|
|
815
|
+
declare function getTemplateById(id: string): DatabaseTemplate | undefined;
|
|
816
|
+
/**
|
|
817
|
+
* Get all template categories with counts.
|
|
818
|
+
*/
|
|
819
|
+
declare function getTemplateCategoryCounts(): Record<TemplateCategory, number>;
|
|
820
|
+
|
|
821
|
+
/**
|
|
822
|
+
* Template instantiation - create a new database from a template.
|
|
823
|
+
*
|
|
824
|
+
* Handles:
|
|
825
|
+
* - Remapping placeholder IDs to real IDs
|
|
826
|
+
* - Creating column definitions
|
|
827
|
+
* - Creating view definitions
|
|
828
|
+
* - Optionally including sample data
|
|
829
|
+
*/
|
|
830
|
+
|
|
831
|
+
/**
|
|
832
|
+
* Create a new database from a template.
|
|
833
|
+
*
|
|
834
|
+
* @example
|
|
835
|
+
* const template = getTemplateById('project-tracker')
|
|
836
|
+
* const db = instantiateTemplate(template, { includeSampleData: true })
|
|
837
|
+
*/
|
|
838
|
+
declare function instantiateTemplate(template: DatabaseTemplate, options?: InstantiateOptions): InstantiatedDatabase;
|
|
839
|
+
/**
|
|
840
|
+
* Create an empty database template.
|
|
841
|
+
* Useful for "start from scratch" option.
|
|
842
|
+
*/
|
|
843
|
+
declare function createEmptyTemplate(): DatabaseTemplate;
|
|
844
|
+
/**
|
|
845
|
+
* Create an empty database (instantiated).
|
|
846
|
+
*/
|
|
847
|
+
declare function createEmptyDatabase(name?: string): InstantiatedDatabase;
|
|
848
|
+
|
|
849
|
+
/**
|
|
850
|
+
* Save database as template.
|
|
851
|
+
*
|
|
852
|
+
* Converts an existing database structure into a reusable template.
|
|
853
|
+
* Handles:
|
|
854
|
+
* - Converting real IDs to stable placeholder IDs
|
|
855
|
+
* - Optionally including sample data
|
|
856
|
+
* - Sanitizing sensitive values
|
|
857
|
+
*/
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* Create a template from an existing database.
|
|
861
|
+
*
|
|
862
|
+
* @example
|
|
863
|
+
* const template = createTemplateFromDatabase(database, {
|
|
864
|
+
* name: 'My Template',
|
|
865
|
+
* description: 'A custom template',
|
|
866
|
+
* tags: ['custom', 'project']
|
|
867
|
+
* })
|
|
868
|
+
*/
|
|
869
|
+
declare function createTemplateFromDatabase(database: DatabaseForTemplate, options: SaveTemplateOptions): DatabaseTemplate;
|
|
870
|
+
/**
|
|
871
|
+
* Remove sensitive data from values for template sample data.
|
|
872
|
+
*/
|
|
873
|
+
declare function sanitizeValueForTemplate(value: unknown): unknown;
|
|
874
|
+
/**
|
|
875
|
+
* Validate a template structure.
|
|
876
|
+
*/
|
|
877
|
+
declare function validateTemplate(template: DatabaseTemplate): {
|
|
878
|
+
valid: boolean;
|
|
879
|
+
errors: string[];
|
|
880
|
+
};
|
|
881
|
+
|
|
882
|
+
export { type ASTNode, BUILTIN_TEMPLATES, type CacheStats, type CachedRow, type CircularCheckResult, ColumnDefinition, ColumnType, ComputedCache, type ComputedCacheConfig, type ComputedCacheEntry, type ComputedCacheStats, DEFAULT_CACHE_CONFIG, DEFAULT_COMPUTED_CACHE_CONFIG, DEFAULT_ROUTER_CONFIG, type DatabaseForTemplate, type DatabaseTemplate, type DependencyGraph, type EvalContext, FUNCTIONS, FilterGroup, type FormulaFunction, FormulaParser, type InstantiateOptions, type InstantiatedColumn, type InstantiatedDatabase, type InstantiatedRow, type InstantiatedView, QueryRouter, type QueryRouterConfig, type QueryRouterResult, type QuerySource, type RouteOptions, RowCache, type RowCacheConfig, type SaveTemplateOptions, SortConfig, type TemplateCategory, type TemplateColumn, type TemplateMetadata, type TemplateSampleRow, type TemplateView, ViewType, batchInvalidate, buildDependencyGraph, computeInputHash, createComputedCache, createEmptyDatabase, createEmptyTemplate, createQueryRouter, createRowCache, createTemplateFromDatabase, detectCircularDependencies, evaluate, extractDependencies, getAffectedColumns, getEvaluationOrder, getFunction, getFunctionNames, getTemplateById, getTemplateCategoryCounts, getTemplatesByCategory, instantiateTemplate, isEntryValid, isValidFunction, safeEvaluate, sanitizeValueForTemplate, searchTemplates, validateTemplate, wouldCreateCircular };
|