@univerjs-pro/bases 1.0.0-alpha.2 → 1.0.0-alpha.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.
Files changed (127) hide show
  1. package/README.md +8 -5
  2. package/lib/cjs/facade.js +1 -1
  3. package/lib/cjs/index.js +1 -1
  4. package/lib/cjs/locale/ar-SA.js +1 -1
  5. package/lib/cjs/locale/ca-ES.js +1 -1
  6. package/lib/cjs/locale/de-DE.js +1 -1
  7. package/lib/cjs/locale/en-US.js +1 -1
  8. package/lib/cjs/locale/es-ES.js +1 -1
  9. package/lib/cjs/locale/fa-IR.js +1 -1
  10. package/lib/cjs/locale/fr-FR.js +1 -1
  11. package/lib/cjs/locale/id-ID.js +1 -1
  12. package/lib/cjs/locale/it-IT.js +1 -1
  13. package/lib/cjs/locale/ja-JP.js +1 -1
  14. package/lib/cjs/locale/ko-KR.js +1 -1
  15. package/lib/cjs/locale/pl-PL.js +1 -1
  16. package/lib/cjs/locale/pt-BR.js +1 -1
  17. package/lib/cjs/locale/ru-RU.js +1 -1
  18. package/lib/cjs/locale/sk-SK.js +1 -1
  19. package/lib/cjs/locale/vi-VN.js +1 -1
  20. package/lib/cjs/locale/zh-CN.js +1 -1
  21. package/lib/cjs/locale/zh-HK.js +1 -1
  22. package/lib/cjs/locale/zh-TW.js +1 -1
  23. package/lib/es/facade.js +1 -1
  24. package/lib/es/index.js +1 -1
  25. package/lib/es/locale/ar-SA.js +1 -1
  26. package/lib/es/locale/ca-ES.js +1 -1
  27. package/lib/es/locale/de-DE.js +1 -1
  28. package/lib/es/locale/en-US.js +1 -1
  29. package/lib/es/locale/es-ES.js +1 -1
  30. package/lib/es/locale/fa-IR.js +1 -1
  31. package/lib/es/locale/fr-FR.js +1 -1
  32. package/lib/es/locale/id-ID.js +1 -1
  33. package/lib/es/locale/it-IT.js +1 -1
  34. package/lib/es/locale/ja-JP.js +1 -1
  35. package/lib/es/locale/ko-KR.js +1 -1
  36. package/lib/es/locale/pl-PL.js +1 -1
  37. package/lib/es/locale/pt-BR.js +1 -1
  38. package/lib/es/locale/ru-RU.js +1 -1
  39. package/lib/es/locale/sk-SK.js +1 -1
  40. package/lib/es/locale/vi-VN.js +1 -1
  41. package/lib/es/locale/zh-CN.js +1 -1
  42. package/lib/es/locale/zh-HK.js +1 -1
  43. package/lib/es/locale/zh-TW.js +1 -1
  44. package/lib/facade.js +1 -1
  45. package/lib/index.js +1 -1
  46. package/lib/locale/ar-SA.js +1 -1
  47. package/lib/locale/ca-ES.js +1 -1
  48. package/lib/locale/de-DE.js +1 -1
  49. package/lib/locale/en-US.js +1 -1
  50. package/lib/locale/es-ES.js +1 -1
  51. package/lib/locale/fa-IR.js +1 -1
  52. package/lib/locale/fr-FR.js +1 -1
  53. package/lib/locale/id-ID.js +1 -1
  54. package/lib/locale/it-IT.js +1 -1
  55. package/lib/locale/ja-JP.js +1 -1
  56. package/lib/locale/ko-KR.js +1 -1
  57. package/lib/locale/pl-PL.js +1 -1
  58. package/lib/locale/pt-BR.js +1 -1
  59. package/lib/locale/ru-RU.js +1 -1
  60. package/lib/locale/sk-SK.js +1 -1
  61. package/lib/locale/vi-VN.js +1 -1
  62. package/lib/locale/zh-CN.js +1 -1
  63. package/lib/locale/zh-HK.js +1 -1
  64. package/lib/locale/zh-TW.js +1 -1
  65. package/lib/types/commands/commands/set-base-view-filter.command.d.ts +2 -2
  66. package/lib/types/commands/commands/set-base-view-group.command.d.ts +2 -2
  67. package/lib/types/commands/commands/set-base-view-sort.command.d.ts +2 -2
  68. package/lib/types/commands/utils/base-validation.d.ts +6 -0
  69. package/lib/types/config/config.d.ts +1 -0
  70. package/lib/types/controllers/base-active-dirty.controller.d.ts +5 -6
  71. package/lib/types/controllers/base-formula-calculation.controller.d.ts +8 -14
  72. package/lib/types/embed-host-anchor.d.ts +46 -0
  73. package/lib/types/facade/f-base.d.ts +126 -577
  74. package/lib/types/facade/f-enum.d.ts +117 -89
  75. package/lib/types/facade/f-event.d.ts +255 -132
  76. package/lib/types/facade/f-field.d.ts +137 -313
  77. package/lib/types/facade/f-range.d.ts +86 -326
  78. package/lib/types/facade/f-record.d.ts +93 -216
  79. package/lib/types/facade/f-table.d.ts +473 -1317
  80. package/lib/types/facade/f-types.d.ts +1 -0
  81. package/lib/types/facade/f-univer.d.ts +27 -154
  82. package/lib/types/facade/f-view.d.ts +207 -484
  83. package/lib/types/facade/field-key.d.ts +6 -6
  84. package/lib/types/facade/index.d.ts +10 -20
  85. package/lib/types/fields/field-core-plugin.d.ts +9 -8
  86. package/lib/types/index.d.ts +10 -8
  87. package/lib/types/models/base-cell-data.d.ts +6 -6
  88. package/lib/types/models/default-table.d.ts +13 -0
  89. package/lib/types/ot/json1-adapter.d.ts +3 -3
  90. package/lib/types/ot/json1-invalidation.d.ts +2 -2
  91. package/lib/types/ot/json1-op-applier.d.ts +2 -2
  92. package/lib/types/ot/json1-op-factory.d.ts +9 -8
  93. package/lib/types/plugin.d.ts +0 -1
  94. package/lib/types/search/base-search.d.ts +4 -3
  95. package/lib/types/services/base-active-dirty.service.d.ts +2 -2
  96. package/lib/types/services/base-command.service.d.ts +16 -16
  97. package/lib/types/services/base-compression.service.d.ts +3 -3
  98. package/lib/types/services/base-field-registry.service.d.ts +5 -5
  99. package/lib/types/services/base-formula.service.d.ts +11 -20
  100. package/lib/types/services/base-view-registry.service.d.ts +3 -3
  101. package/lib/types/views/view-core-plugin.d.ts +4 -3
  102. package/lib/umd/facade.js +1 -1
  103. package/lib/umd/index.js +1 -1
  104. package/lib/umd/locale/ar-SA.js +1 -1
  105. package/lib/umd/locale/ca-ES.js +1 -1
  106. package/lib/umd/locale/de-DE.js +1 -1
  107. package/lib/umd/locale/en-US.js +1 -1
  108. package/lib/umd/locale/es-ES.js +1 -1
  109. package/lib/umd/locale/fa-IR.js +1 -1
  110. package/lib/umd/locale/fr-FR.js +1 -1
  111. package/lib/umd/locale/id-ID.js +1 -1
  112. package/lib/umd/locale/it-IT.js +1 -1
  113. package/lib/umd/locale/ja-JP.js +1 -1
  114. package/lib/umd/locale/ko-KR.js +1 -1
  115. package/lib/umd/locale/pl-PL.js +1 -1
  116. package/lib/umd/locale/pt-BR.js +1 -1
  117. package/lib/umd/locale/ru-RU.js +1 -1
  118. package/lib/umd/locale/sk-SK.js +1 -1
  119. package/lib/umd/locale/vi-VN.js +1 -1
  120. package/lib/umd/locale/zh-CN.js +1 -1
  121. package/lib/umd/locale/zh-HK.js +1 -1
  122. package/lib/umd/locale/zh-TW.js +1 -1
  123. package/package.json +7 -8
  124. package/lib/types/controllers/base-remote-formula.controller.d.ts +0 -13
  125. package/lib/types/facade/f-error.d.ts +0 -30
  126. package/lib/types/facade/f-permission.d.ts +0 -749
  127. package/lib/types/facade/transaction.d.ts +0 -19
@@ -1,85 +1,36 @@
1
- import type { IBasePermissionService, IBaseProjectionService } from '@univerjs-pro/bases';
2
- import type { BaseCellValue, BaseDataModel, ICommandService, IFieldSnapshot, ITableSnapshot, IViewSnapshot, SortConfig, ViewType } from '@univerjs/core';
3
- import type { BaseFieldKey, IBaseFieldKeyOptions } from './field-key';
4
- import { FField } from './f-field';
5
- import { FTablePermission } from './f-permission';
6
- import { FBaseRange } from './f-range';
7
- import { FRecord } from './f-record';
8
- import { FView } from './f-view';
9
- export interface IAddFieldInput {
10
- /** Field display name. */
11
- name: string;
12
- /** Field type, such as `text`, `number`, `singleSelect`, or `formula`. */
13
- type: IFieldSnapshot['type'];
14
- /** Field type configuration. Formula fields use `config.formula`. */
15
- config?: IFieldSnapshot['config'];
16
- /** Default value applied to new records when supported by the field type. */
17
- defaultValue?: IFieldSnapshot['defaultValue'];
18
- /** Optional field description. */
19
- description?: string;
20
- /** Optional field id. A random id is generated when omitted. */
21
- id?: string;
22
- /** Optional insertion index in the table field order. */
23
- index?: number;
24
- /** Whether this field should be readonly. Formula fields are usually readonly. */
25
- readonly?: boolean;
26
- }
27
- export interface IAddRecordInput {
28
- /** Optional record id. A random id is generated when omitted. */
29
- id?: string;
30
- /** Initial values. Defaults to field-id keys unless `fieldKey` is provided. */
31
- values?: Record<string, BaseCellValue>;
32
- /** Initial field values. Defaults to field-name keys. */
33
- fields?: Record<string, BaseCellValue>;
34
- /** How `values` and `fields` keys are resolved. */
35
- fieldKey?: BaseFieldKey;
36
- /** Optional order key used to position the record. */
37
- orderKey?: string;
38
- /** Optional creation timestamp. */
39
- createdAt?: number;
40
- /** Optional update timestamp. */
41
- updatedAt?: number;
42
- /** Optional creator user id. */
43
- createdBy?: string;
44
- /** Optional updater user id. */
45
- updatedBy?: string;
46
- }
47
- export interface IUpdateRecordOptions extends IBaseFieldKeyOptions {
48
- }
49
- export interface ICreateViewInput {
50
- /** Optional view id. A random id is generated when omitted. */
51
- id?: string;
52
- /** View display name. */
53
- name: string;
54
- /** View type, such as `grid`, `kanban`, `calendar`, `gantt`, or `gallery`. */
55
- type: ViewType;
56
- /** View-specific configuration. */
57
- config?: IViewSnapshot['config'];
58
- /** Optional insertion index in the table view order. */
59
- index?: number;
60
- }
1
+ import type { IBaseTableSearchRequest, IBaseTableSearchResult } from '@univerjs-pro/bases';
2
+ import type { BaseCellValue, BaseDataModel, BaseFilterOperator, FieldId, IFieldSnapshot, Injector, IRecordSnapshot, ISortConfig, ITableSnapshot, IViewSnapshot } from '@univerjs/core';
3
+ import type { FBase } from './f-base';
4
+ import { BaseFieldType, BaseFilterConjunction, BaseViewType } from '@univerjs/core';
5
+ import { FBaseTableField } from './f-field';
6
+ import { FBaseTableRange } from './f-range';
7
+ import { FBaseTableRecord } from './f-record';
8
+ import { FBaseTableView } from './f-view';
9
+ import { BaseFieldKeyEnum } from './field-key';
61
10
  export interface IListRecordOptions {
62
11
  /** Optional view id. When provided, records are returned in the view projection order. */
63
12
  viewId?: string;
64
13
  /** Optional field filter. */
65
14
  filter?: IBaseRecordFilter;
66
15
  /** Optional sort rules applied after view ordering. */
67
- sort?: SortConfig[];
16
+ sort?: ISortConfig[];
68
17
  /** Optional zero-based offset. */
69
18
  offset?: number;
70
19
  /** Optional maximum number of records to return. */
71
20
  limit?: number;
72
21
  }
73
22
  export interface IBaseRecordFilter {
74
- fieldId?: string;
75
- operator?: 'is' | 'isNot' | 'contains' | 'doesNotContain' | 'isEmpty' | 'isNotEmpty' | 'greaterThan' | 'greaterThanOrEqual' | 'lessThan' | 'lessThanOrEqual' | 'matches' | 'notMatches';
23
+ conjunction?: BaseFilterConjunction;
24
+ conditions: IBaseRecordFilterCondition[];
25
+ }
26
+ export interface IBaseRecordFilterCondition {
27
+ fieldId: string;
28
+ operator: BaseFilterOperator | 'matches' | 'notMatches';
76
29
  value?: BaseCellValue;
77
30
  caseSensitive?: boolean;
78
- conjunction?: 'and' | 'or';
79
- conditions?: IBaseRecordFilter[];
80
31
  }
81
32
  export interface IQueryRecordsResult {
82
- records: FRecord[];
33
+ records: FBaseTableRecord[];
83
34
  total: number;
84
35
  offset: number;
85
36
  limit: number | null;
@@ -108,1077 +59,477 @@ export interface IBaseTableSchemaSnapshot {
108
59
  *
109
60
  * @example Create fields, records, a view, and a query
110
61
  * ```ts
111
- * const table = base.createTable({ id: 'tasks', name: 'Tasks', primaryFieldName: 'Title' });
112
- * const status = table.addField({
113
- * id: 'status',
114
- * name: 'Status',
115
- * type: 'singleSelect',
116
- * config: { options: [{ id: 'todo', name: 'Todo', color: 'blue' }, { id: 'done', name: 'Done', color: 'green' }] },
117
- * });
118
- * const progress = table.addField({ id: 'progress', name: 'Progress', type: 'progress', config: {} });
119
- * table.addRecords([
120
- * { id: 'task-1', values: { [table.getPrimaryFieldId()]: 'Design protocol', [status.getId()]: 'todo', [progress.getId()]: 20 } },
121
- * { id: 'task-2', values: { [table.getPrimaryFieldId()]: 'Wire server load', [status.getId()]: 'done', [progress.getId()]: 100 } },
62
+ * const fBase = univerAPI.getActiveBase();
63
+ * const fBaseTable = fBase.insertTable(
64
+ * 'Tasks',
65
+ * {
66
+ * index: 0,
67
+ * primaryFieldName: 'Title'
68
+ * }
69
+ * );
70
+ *
71
+ * const name = fBaseTable.addField('Name', univerAPI.Enum.BaseFieldType.Text);
72
+ * const status = fBaseTable.addField(
73
+ * 'Status',
74
+ * univerAPI.Enum.BaseFieldType.SingleSelect,
75
+ * {
76
+ * field: {
77
+ * config: {
78
+ * options: [
79
+ * { id: 'todo', name: 'Todo', color: 'blue' },
80
+ * { id: 'done', name: 'Done', color: 'green' },
81
+ * ],
82
+ * }
83
+ * }
84
+ * }
85
+ * );
86
+ * const progress = fBaseTable.addField('Progress', univerAPI.Enum.BaseFieldType.Progress);
87
+ *
88
+ * fBaseTable.addRecord(
89
+ * {
90
+ * [fBaseTable.getPrimaryFieldId()]: 'Review protocol',
91
+ * [name.getId()]: 'Review protocol',
92
+ * [status.getId()]: 'todo',
93
+ * [progress.getId()]: 0
94
+ * }
95
+ * );
96
+ * fBaseTable.addRecords([
97
+ * {
98
+ * values: {
99
+ * [fBaseTable.getPrimaryFieldId()]: 'Design protocol',
100
+ * [status.getId()]: 'todo',
101
+ * [progress.getId()]: 20
102
+ * }
103
+ * },
104
+ * {
105
+ * values: {
106
+ * [fBaseTable.getPrimaryFieldId()]: 'Wire server load',
107
+ * [status.getId()]: 'done',
108
+ * [progress.getId()]: 100
109
+ * }
110
+ * },
122
111
  * ]);
123
- * const grid = table.createView({ id: 'grid-main', name: 'Main Grid', type: 'grid' });
124
- * grid.setSort([{ fieldId: progress.getId(), direction: 'desc' }]);
125
- * const done = table.queryRecords({ filter: { fieldId: status.getId(), operator: 'is', value: 'done' } });
112
+ *
113
+ * const grid = fBaseTable.createView(
114
+ * 'Main Grid',
115
+ * univerAPI.Enum.BaseViewType.Grid,
116
+ * {
117
+ * view: {
118
+ * config: {
119
+ * frozenFieldCount: 1
120
+ * },
121
+ * },
122
+ * }
123
+ * );
124
+ *
125
+ * const done = fBaseTable.queryRecords({
126
+ * filter: {
127
+ * conditions: [{
128
+ * fieldId: status.getId(),
129
+ * operator: univerAPI.Enum.BaseFilterOperator.IS,
130
+ * value: 'done'
131
+ * }]
132
+ * }
133
+ * });
134
+ * console.log(done);
126
135
  * ```
127
136
  */
128
- export declare class FTable {
137
+ export declare class FBaseTable {
129
138
  private readonly _base;
130
139
  private readonly _tableId;
131
- private readonly _commandService;
132
- private readonly _projectionService;
133
- private readonly _permissionService;
134
- constructor(_base: BaseDataModel, _tableId: string, _commandService: ICommandService, _projectionService: IBaseProjectionService, _permissionService: IBasePermissionService);
140
+ private readonly _injector;
141
+ constructor(_base: FBase, _tableId: string, _injector: Injector);
135
142
  /**
136
- * Get the underlying Base data model.
137
- * @returns The Base data model.
143
+ * Get the table's parent Base data model.
144
+ * @returns {BaseDataModel} The Base data model.
138
145
  * @example
139
146
  * ```ts
140
- * const baseModel = table.getBase();
141
- * ```
142
- *
143
- * @example Browser console
144
- * ```ts
145
- * console.log((() => {
146
- * const unitId = `facade_example_${Date.now()}`;
147
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
148
- * try {
149
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
150
- * return table.getBase().getUnitId();
151
- * } finally {
152
- * univerAPI.disposeUnit(unitId);
153
- * }
154
- * })());
147
+ * const fBase = univerAPI.getActiveBase();
148
+ * const fBaseTable = fBase.getTableById('table-1');
149
+ * console.log(fBaseTable.getBase());
155
150
  * ```
156
151
  */
157
152
  getBase(): BaseDataModel;
158
153
  /**
159
154
  * Get the table snapshot.
160
- * @returns The table snapshot.
155
+ * @returns {ITableSnapshot} The table snapshot.
161
156
  * @example
162
157
  * ```ts
163
- * const rawTable = table.getTable();
164
- * ```
165
- *
166
- * @example Browser console
167
- * ```ts
168
- * console.log((() => {
169
- * const unitId = `facade_example_${Date.now()}`;
170
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
171
- * try {
172
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
173
- * return table.getTable().name;
174
- * } finally {
175
- * univerAPI.disposeUnit(unitId);
176
- * }
177
- * })());
158
+ * const fBase = univerAPI.getActiveBase();
159
+ * const fBaseTable = fBase.getTableById('table-1');
160
+ * console.log(fBaseTable.getTable());
178
161
  * ```
179
162
  */
180
163
  getTable(): ITableSnapshot;
181
- /**
182
- * Get the table snapshot.
183
- * @returns The table snapshot.
184
- * @example
185
- * ```ts
186
- * const snapshot = table.getSnapshot();
187
- * ```
188
- *
189
- * @example Browser console
190
- * ```ts
191
- * console.log((() => {
192
- * const unitId = `facade_example_${Date.now()}`;
193
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
194
- * try {
195
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
196
- * return table.getSnapshot().id;
197
- * } finally {
198
- * univerAPI.disposeUnit(unitId);
199
- * }
200
- * })());
201
- * ```
202
- */
203
- getSnapshot(): ITableSnapshot;
204
164
  /**
205
165
  * Get the table id.
206
- * @returns The table id.
166
+ * @returns {string} The table id.
207
167
  * @example
208
168
  * ```ts
209
- * console.log(table.getId());
210
- * ```
211
- *
212
- * @example Browser console
213
- * ```ts
214
- * console.log((() => {
215
- * const unitId = `facade_example_${Date.now()}`;
216
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
217
- * try {
218
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
219
- * return table.getId();
220
- * } finally {
221
- * univerAPI.disposeUnit(unitId);
222
- * }
223
- * })());
169
+ * const fBase = univerAPI.getActiveBase();
170
+ * const fBaseTable = fBase.getTableById('table-1');
171
+ * console.log(fBaseTable.getId()); // 'table-1'
224
172
  * ```
225
173
  */
226
174
  getId(): string;
227
175
  /**
228
176
  * Get the table name.
229
- * @returns The table name.
177
+ * @returns {string} The table name.
230
178
  * @example
231
179
  * ```ts
232
- * console.log(table.getName());
233
- * ```
234
- *
235
- * @example Browser console
236
- * ```ts
237
- * console.log((() => {
238
- * const unitId = `facade_example_${Date.now()}`;
239
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
240
- * try {
241
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
242
- * return table.getName();
243
- * } finally {
244
- * univerAPI.disposeUnit(unitId);
245
- * }
246
- * })());
180
+ * const fBase = univerAPI.getActiveBase();
181
+ * const fBaseTable = fBase.getTableById('table-1');
182
+ * console.log(fBaseTable.getName());
247
183
  * ```
248
184
  */
249
185
  getName(): string;
250
- /**
251
- * Get the primary field id.
252
- * @returns The primary field id.
253
- * @example
254
- * ```ts
255
- * const primaryFieldId = table.getPrimaryFieldId();
256
- * ```
257
- *
258
- * @example Browser console
259
- * ```ts
260
- * console.log((() => {
261
- * const unitId = `facade_example_${Date.now()}`;
262
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
263
- * try {
264
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
265
- * return table.getPrimaryFieldId();
266
- * } finally {
267
- * univerAPI.disposeUnit(unitId);
268
- * }
269
- * })());
270
- * ```
271
- */
272
- getPrimaryFieldId(): string;
273
186
  /**
274
187
  * Rename this table.
275
- * @param name The new table name.
188
+ * @param {string} name The new table name.
276
189
  * @example
277
190
  * ```ts
278
- * table.setName('Roadmap');
279
- * ```
280
- *
281
- * @example Browser console
282
- * ```ts
283
- * console.log((() => {
284
- * const unitId = `facade_example_${Date.now()}`;
285
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
286
- * try {
287
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
288
- * table.setName('Renamed Tasks');
289
- * return table.getName();
290
- * } finally {
291
- * univerAPI.disposeUnit(unitId);
292
- * }
293
- * })());
191
+ * const fBase = univerAPI.getActiveBase();
192
+ * const fBaseTable = fBase.getTableById('table-1');
193
+ * const success = fBaseTable.setName('Roadmap');
194
+ * console.log(success);
294
195
  * ```
295
196
  */
296
- setName(name: string): void;
197
+ setName(name: string): boolean;
297
198
  /**
298
- * Get all non-deleted fields in this table.
299
- * @returns Field facades ordered by the table field order.
300
- * @example
301
- * ```ts
302
- * const fields = table.getFields();
303
- * fields.forEach((field) => console.log(field.getName()));
304
- * ```
199
+ * Search records in this table.
200
+ *
201
+ * Search reads the current table snapshot. When `viewId` is provided, the
202
+ * search space follows that view projection, including hidden fields and
203
+ * projected row order.
305
204
  *
306
- * @example Browser console
205
+ * @param {Omit<IBaseTableSearchRequest, 'table' | 'rows'>} request The search request parameters, excluding `table` and `rows`.
206
+ * @param {string} [viewId] Optional view id to search within a specific view projection.
207
+ * @returns {IBaseTableSearchResult} The search result with matching records and total count.
208
+ * @example
307
209
  * ```ts
308
- * console.log((() => {
309
- * const unitId = `facade_example_${Date.now()}`;
310
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
311
- * try {
312
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
313
- * return table.getFields().map((field) => field.getName());
314
- * } finally {
315
- * univerAPI.disposeUnit(unitId);
316
- * }
317
- * })());
210
+ * const fBase = univerAPI.getActiveBase();
211
+ * const fBaseTable = fBase.getTableById('table-1');
212
+ * const result = fBaseTable.search({
213
+ * query: 'release',
214
+ * fieldIds: ['title', 'status'],
215
+ * limit: 20,
216
+ * });
217
+ * console.log(result);
318
218
  * ```
319
219
  */
320
- getFields(): FField[];
220
+ search(request: Omit<IBaseTableSearchRequest, 'table' | 'rows'>, viewId?: string): IBaseTableSearchResult;
321
221
  /**
322
- * List all non-deleted fields in this table.
323
- * @returns Field facades ordered by the table field order.
222
+ * Get the primary field id.
223
+ * @returns {string} The primary field id.
324
224
  * @example
325
225
  * ```ts
326
- * const fields = table.listFields();
327
- * ```
328
- *
329
- * @example Browser console
330
- * ```ts
331
- * console.log((() => {
332
- * const unitId = `facade_example_${Date.now()}`;
333
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
334
- * try {
335
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
336
- * return table.listFields().map((field) => field.getName());
337
- * } finally {
338
- * univerAPI.disposeUnit(unitId);
339
- * }
340
- * })());
226
+ * const fBase = univerAPI.getActiveBase();
227
+ * const fBaseTable = fBase.getTableById('table-1');
228
+ * console.log(fBaseTable.getPrimaryFieldId());
341
229
  * ```
342
230
  */
343
- listFields(): FField[];
231
+ getPrimaryFieldId(): string;
344
232
  /**
345
- * Get a field by id.
346
- * @param fieldId The field id.
347
- * @returns The field facade, or null if the field does not exist.
233
+ * Get all existing fields in this table.
234
+ * @returns {FBaseTableField[]} An array of field facades ordered by the table field order.
348
235
  * @example
349
236
  * ```ts
350
- * const field = table.getField('status');
351
- * ```
352
- *
353
- * @example Browser console
354
- * ```ts
355
- * console.log((() => {
356
- * const unitId = `facade_example_${Date.now()}`;
357
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
358
- * try {
359
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
360
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
361
- * return table.getField(field.getId())?.getName() ?? null;
362
- * } finally {
363
- * univerAPI.disposeUnit(unitId);
364
- * }
365
- * })());
237
+ * const fBase = univerAPI.getActiveBase();
238
+ * const fBaseTable = fBase.getTableById('table-1');
239
+ * const fields = fBaseTable.getFields();
240
+ * console.log(fields);
366
241
  * ```
367
242
  */
368
- getField(fieldId: string): FField | null;
243
+ getFields(): FBaseTableField[];
369
244
  /**
370
245
  * Get a field by id.
371
- * @param fieldId The field id.
372
- * @returns The field facade, or null if the field does not exist.
246
+ * @param {string} fieldId The field id.
247
+ * @returns {FBaseTableField | null} The field facade, or null if the field does not exist.
373
248
  * @example
374
249
  * ```ts
375
- * const field = table.getFieldById('status');
376
- * ```
377
- *
378
- * @example Browser console
379
- * ```ts
380
- * console.log((() => {
381
- * const unitId = `facade_example_${Date.now()}`;
382
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
383
- * try {
384
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
385
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
386
- * return table.getFieldById(field.getId())?.getName() ?? null;
387
- * } finally {
388
- * univerAPI.disposeUnit(unitId);
389
- * }
390
- * })());
250
+ * const fBase = univerAPI.getActiveBase();
251
+ * const fBaseTable = fBase.getTableById('table-1');
252
+ * const field = fBaseTable.getFieldById('status');
253
+ * console.log(field);
391
254
  * ```
392
255
  */
393
- getFieldById(fieldId: string): FField | null;
256
+ getFieldById(fieldId: string): FBaseTableField | null;
394
257
  /**
395
- * Get the first field matching a field name.
396
- * @param name The field name.
397
- * @returns The field facade, or null if no field matches.
258
+ * Get a field by name.
259
+ * @param {string} fieldName The field name.
260
+ * @returns {FBaseTableField | null} The field facade, or null if the field does not exist.
398
261
  * @example
399
262
  * ```ts
400
- * const field = table.getFieldByName('Status');
401
- * ```
402
- *
403
- * @example Browser console
404
- * ```ts
405
- * console.log((() => {
406
- * const unitId = `facade_example_${Date.now()}`;
407
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
408
- * try {
409
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
410
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
411
- * return table.getFieldByName('Status')?.getId() ?? null;
412
- * } finally {
413
- * univerAPI.disposeUnit(unitId);
414
- * }
415
- * })());
263
+ * const fBase = univerAPI.getActiveBase();
264
+ * const fBaseTable = fBase.getTableById('table-1');
265
+ * const field = fBaseTable.getFieldByName('Status');
266
+ * console.log(field);
416
267
  * ```
417
268
  */
418
- getFieldByName(name: string): FField | null;
269
+ getFieldByName(fieldName: string): FBaseTableField | null;
419
270
  /**
420
271
  * Get the primary field.
421
- * @returns The primary field facade.
272
+ * @returns {FBaseTableField} The primary field facade.
422
273
  * @example
423
274
  * ```ts
424
- * const titleField = table.getPrimaryField();
425
- * ```
426
- *
427
- * @example Browser console
428
- * ```ts
429
- * console.log((() => {
430
- * const unitId = `facade_example_${Date.now()}`;
431
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
432
- * try {
433
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
434
- * return table.getPrimaryField().getName();
435
- * } finally {
436
- * univerAPI.disposeUnit(unitId);
437
- * }
438
- * })());
275
+ * const fBase = univerAPI.getActiveBase();
276
+ * const fBaseTable = fBase.getTableById('table-1');
277
+ * const primaryField = fBaseTable.getPrimaryField();
278
+ * console.log(primaryField);
439
279
  * ```
440
280
  */
441
- getPrimaryField(): FField;
281
+ getPrimaryField(): FBaseTableField;
442
282
  /**
443
283
  * Add a field to this table.
284
+ * @param {string} name The field display name.
285
+ * @param {BaseFieldType} type The field type, such as `text`, `number`, `singleSelect`, or `formula`.
286
+ * @param {object} [options] Optional field parameters.
287
+ * @param {number} [options.index] Optional insertion index in the table field order.
288
+ * @param {Partial<Omit<IFieldSnapshot, 'id'>>} [options.field] Optional partial field snapshot to merge into the new field.
289
+ * @returns {FBaseTableField} The new field facade.
444
290
  *
445
- * Field type belongs to the field snapshot, not to each cell. Cell payloads
446
- * may carry typed metadata for compact storage, but formula calculation and
447
- * value interpretation should read the field definition from the table.
448
- *
449
- * @param input Field creation options. `name` and `type` are required.
450
- * `config` is type-specific and is where options, attachment settings,
451
- * formula expressions, number/date formatting, and view-specific field
452
- * metadata should live. `defaultValue` is applied by callers when creating
453
- * records. `readonly` is appropriate for calculated fields.
454
- * @returns The created field facade.
455
- * @example
456
- * ```ts
457
- * const status = table.addField({
458
- * id: 'status',
459
- * name: 'Status',
460
- * type: 'singleSelect',
461
- * config: {
462
- * options: [
463
- * { id: 'todo', name: 'Todo', color: 'blue' },
464
- * { id: 'done', name: 'Done', color: 'green' },
465
- * ],
466
- * },
467
- * });
468
- * ```
469
- * @example Formula field
470
- * ```ts
471
- * const amount = table.addField({ id: 'amount', name: 'Amount', type: 'number', config: { decimalPlaces: 2 } });
472
- * const tax = table.addField({ id: 'tax', name: 'Tax', type: 'number', config: { decimalPlaces: 2 } });
473
- * const total = table.addField({
474
- * id: 'total',
475
- * name: 'Total',
476
- * type: 'formula',
477
- * readonly: true,
478
- * config: { formula: '=SUM(table[Amount], table[Tax])' },
479
- * });
480
- * ```
481
- * @example
482
- * ```ts
483
- * const total = table.addField({
484
- * id: 'total',
485
- * name: 'Total',
486
- * type: 'formula',
487
- * readonly: true,
488
- * config: {
489
- * formula: '=SUM(table[Progress], Pricing[Amount])',
490
- * numberFormat: { type: 'currency', pattern: '"$"#,##0.00' },
491
- * },
492
- * });
493
- * ```
494
- *
495
- * @example Browser console
496
- * ```ts
497
- * console.log((() => {
498
- * const unitId = `facade_example_${Date.now()}`;
499
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
500
- * try {
501
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
502
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
503
- * return { id: field.getId(), type: field.getType() };
504
- * } finally {
505
- * univerAPI.disposeUnit(unitId);
506
- * }
507
- * })());
508
- * ```
509
- */
510
- addField(input: IAddFieldInput): FField;
511
- /**
512
- * Create a field in this table.
513
- * @param input Field creation options.
514
- * @returns The created field facade.
515
- * @example
516
- * ```ts
517
- * const numberField = table.createField({
518
- * name: 'Cost',
519
- * type: 'number',
520
- * config: { decimalPlaces: 2 },
521
- * });
522
- * ```
523
- *
524
- * @example Browser console
525
- * ```ts
526
- * console.log((() => {
527
- * const unitId = `facade_example_${Date.now()}`;
528
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
529
- * try {
530
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
531
- * const created = table.createField({ id: `${unitId}_field`, name: 'Score', type: 'number', config: { decimalPlaces: 0 } });
532
- * return { id: created.getId(), type: created.getType() };
533
- * } finally {
534
- * univerAPI.disposeUnit(unitId);
535
- * }
536
- * })());
537
- * ```
538
- */
539
- createField(input: IAddFieldInput): FField;
540
- /**
541
- * Update a field by id.
542
- * @param fieldId The field id.
543
- * @param patch Partial field snapshot to merge into the field.
544
- * @example
545
- * ```ts
546
- * table.updateField('total', {
547
- * config: { formula: '=SUM(table[Amount], table[Tax])' },
548
- * });
549
- * ```
550
- *
551
- * @example Browser console
552
- * ```ts
553
- * console.log((() => {
554
- * const unitId = `facade_example_${Date.now()}`;
555
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
556
- * try {
557
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
558
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
559
- * table.updateField(field.getId(), { description: 'Visible in examples' });
560
- * return table.getField(field.getId())?.getDescription();
561
- * } finally {
562
- * univerAPI.disposeUnit(unitId);
563
- * }
564
- * })());
565
- * ```
566
- */
567
- updateField(fieldId: string, patch: Partial<IFieldSnapshot>): void;
568
- /**
569
- * Change a field type.
570
- * @param fieldId The field id.
571
- * @param input The target type and config.
572
291
  * @example
573
292
  * ```ts
574
- * table.changeFieldType('score', { type: 'number', config: { decimalPlaces: 0 } });
293
+ * const fBase = univerAPI.getActiveBase();
294
+ * const fBaseTable = fBase.getTableById('table-1');
295
+ * const field = fBaseTable.addField('Name', univerAPI.Enum.BaseFieldType.Text);
296
+ * console.log(field);
575
297
  * ```
576
298
  *
577
- * @example Browser console
578
- * ```ts
579
- * console.log((() => {
580
- * const unitId = `facade_example_${Date.now()}`;
581
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
582
- * try {
583
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
584
- * const score = table.addField({ id: `${unitId}_score`, name: 'Score', type: 'text', config: {} });
585
- * table.changeFieldType(score.getId(), { type: 'number', config: { decimalPlaces: 0 } });
586
- * return table.getField(score.getId())?.getType();
587
- * } finally {
588
- * univerAPI.disposeUnit(unitId);
589
- * }
590
- * })());
591
- * ```
592
- */
593
- changeFieldType(fieldId: string, input: Pick<IFieldSnapshot, 'type' | 'config'>): void;
594
- /**
595
- * Delete a field by id.
596
- * @param fieldId The field id.
597
- * @example
598
- * ```ts
599
- * table.deleteField('deprecated');
600
- * ```
601
- *
602
- * @example Browser console
603
- * ```ts
604
- * console.log((() => {
605
- * const unitId = `facade_example_${Date.now()}`;
606
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
607
- * try {
608
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
609
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
610
- * const fieldId = field.getId();
611
- * table.deleteField(fieldId);
612
- * return table.getField(fieldId);
613
- * } finally {
614
- * univerAPI.disposeUnit(unitId);
615
- * }
616
- * })());
617
- * ```
618
- */
619
- deleteField(fieldId: string): void;
620
- /**
621
- * Move a field relative to another field.
622
- * @param fieldId The field id.
623
- * @param target Target position descriptor.
624
- * @param target.beforeFieldId Optional field id to move this field before.
625
- * @param target.afterFieldId Optional field id to move this field after.
626
299
  * @example
627
300
  * ```ts
628
- * table.moveField('status', { afterFieldId: 'title' });
629
- * ```
630
- *
631
- * @example Browser console
632
- * ```ts
633
- * console.log((() => {
634
- * const unitId = `facade_example_${Date.now()}`;
635
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
636
- * try {
637
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
638
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
639
- * const next = table.addField({ id: `${unitId}_next`, name: 'Next', type: 'text', config: {} });
640
- * table.moveField(next.getId(), { afterFieldId: field.getId() });
641
- * return table.getFields().map((field) => field.getName());
642
- * } finally {
643
- * univerAPI.disposeUnit(unitId);
301
+ * const fBase = univerAPI.getActiveBase();
302
+ * const fBaseTable = fBase.getTableById('table-1');
303
+ * const field = fBaseTable.addField(
304
+ * 'Status',
305
+ * univerAPI.Enum.BaseFieldType.SingleSelect,
306
+ * {
307
+ * index: 1,
308
+ * field: {
309
+ * id: 'status',
310
+ * config: {
311
+ * options: [
312
+ * { id: 'todo', name: 'Todo', color: 'blue' },
313
+ * { id: 'done', name: 'Done', color: 'green' },
314
+ * ],
315
+ * }
316
+ * }
644
317
  * }
645
- * })());
646
- * ```
647
- */
648
- moveField(fieldId: string, target: {
649
- beforeFieldId?: string;
650
- afterFieldId?: string;
651
- }): void;
652
- /**
653
- * Get a record by id.
654
- * @param recordId The record id.
655
- * @returns The record facade, or null if the record does not exist.
656
- * @example
657
- * ```ts
658
- * const record = table.getRecord('record-1');
318
+ * );
319
+ * console.log(field);
659
320
  * ```
660
321
  *
661
- * @example Browser console
322
+ * @example Formula field
662
323
  * ```ts
663
- * console.log((() => {
664
- * const unitId = `facade_example_${Date.now()}`;
665
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
666
- * try {
667
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
668
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
669
- * const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
670
- * return table.getRecord(record.getId())?.getValues() ?? null;
671
- * } finally {
672
- * univerAPI.disposeUnit(unitId);
673
- * }
674
- * })());
675
- * ```
676
- */
677
- getRecord(recordId: string): FRecord | null;
324
+ * const fBase = univerAPI.getActiveBase();
325
+ * const fBaseTable = fBase.getTableById('table-1');
326
+ * const amount = fBaseTable.addField(
327
+ * 'Amount',
328
+ * univerAPI.Enum.BaseFieldType.Number,
329
+ * {
330
+ * field: {
331
+ * config: {
332
+ * decimalPlaces: 2
333
+ * }
334
+ * }
335
+ * }
336
+ * );
337
+ * const tax = fBaseTable.addField(
338
+ * 'Tax',
339
+ * univerAPI.Enum.BaseFieldType.Number,
340
+ * {
341
+ * field: {
342
+ * config: {
343
+ * decimalPlaces: 2
344
+ * }
345
+ * }
346
+ * }
347
+ * );
348
+ * const total = fBaseTable.addField(
349
+ * 'Total',
350
+ * univerAPI.Enum.BaseFieldType.Formula,
351
+ * {
352
+ * field: {
353
+ * config: {
354
+ * formula: '=SUM([Amount],[Tax])'
355
+ * }
356
+ * }
357
+ * }
358
+ * );
359
+ * ```
360
+ *
361
+ * @example
362
+ * ```ts
363
+ * const fBase = univerAPI.getActiveBase();
364
+ * const fBaseTable = fBase.getTableById('table-1');
365
+ * const total = fBaseTable.addField(
366
+ * 'Total',
367
+ * univerAPI.Enum.BaseFieldType.Formula,
368
+ * {
369
+ * field: {
370
+ * config: {
371
+ * formula: '=SUM([Progress],[Amount])',
372
+ * numberFormat: {
373
+ * type: 'currency',
374
+ * pattern: '"$"#,##0.00'
375
+ * },
376
+ * },
377
+ * readonly: true,
378
+ * }
379
+ * }
380
+ * );
381
+ * ```
382
+ */
383
+ addField(name: string, type: BaseFieldType, options?: {
384
+ index?: number;
385
+ field?: Partial<Omit<IFieldSnapshot, 'id'>>;
386
+ }): FBaseTableField;
387
+ /**
388
+ * Get all records in this table, optionally filtered, sorted, and paginated.
389
+ * @returns {FBaseTableRecord[]} An array of record facades ordered by the table record order.
390
+ * @example
391
+ * ```ts
392
+ * const fBase = univerAPI.getActiveBase();
393
+ * const fBaseTable = fBase.getTableById('table-1');
394
+ * const records = fBaseTable.getRecords();
395
+ * console.log(records);
396
+ * ```
397
+ */
398
+ getRecords(): FBaseTableRecord[];
678
399
  /**
679
400
  * Get a record by id.
680
- * @param recordId The record id.
681
- * @returns The record facade, or null if the record does not exist.
682
- * @example
683
- * ```ts
684
- * const record = table.getRecordById('record-1');
685
- * ```
686
- *
687
- * @example Browser console
688
- * ```ts
689
- * console.log((() => {
690
- * const unitId = `facade_example_${Date.now()}`;
691
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
692
- * try {
693
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
694
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
695
- * const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
696
- * return table.getRecordById(record.getId())?.getValues() ?? null;
697
- * } finally {
698
- * univerAPI.disposeUnit(unitId);
699
- * }
700
- * })());
701
- * ```
702
- */
703
- getRecordById(recordId: string): FRecord | null;
704
- /**
705
- * Get records in this table.
706
- *
707
- * Records are returned in table order by default. Passing `viewId` first
708
- * projects the records through the view, then optional filter, sort,
709
- * offset, and limit are applied.
710
- *
711
- * @param options Optional list options. `viewId` selects a view projection.
712
- * `filter` supports simple and nested conditions. `sort` applies field-id
713
- * keyed sort rules. `offset` and `limit` page the returned facade objects.
714
- * @returns Record facades.
401
+ * @param {string} recordId The record id.
402
+ * @returns {FBaseTableRecord | null} The record facade, or null if the record does not exist.
715
403
  * @example
716
404
  * ```ts
717
- * const records = table.getRecords();
718
- * const visibleRecords = table.getRecords({ viewId: 'grid' });
719
- * ```
720
- *
721
- * @example Browser console
722
- * ```ts
723
- * console.log((() => {
724
- * const unitId = `facade_example_${Date.now()}`;
725
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
726
- * try {
727
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
728
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
729
- * const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
730
- * return table.getRecords().map((record) => record.getId());
731
- * } finally {
732
- * univerAPI.disposeUnit(unitId);
733
- * }
734
- * })());
405
+ * const fBase = univerAPI.getActiveBase();
406
+ * const fBaseTable = fBase.getTableById('table-1');
407
+ * const record = fBaseTable.getRecordById('record-1');
408
+ * console.log(record);
735
409
  * ```
736
410
  */
737
- getRecords(options?: IListRecordOptions): FRecord[];
411
+ getRecordById(recordId: string): FBaseTableRecord | null;
738
412
  /**
739
413
  * Query records with filter, sort, and pagination metadata.
740
- *
741
- * Prefer this over `getRecords()` when an API response needs `total`,
742
- * `offset`, `limit`, or `hasMore`.
743
- *
744
- * @param options Query options. `filter` uses field ids and operators such
745
- * as `is`, `contains`, `isEmpty`, and numeric comparisons. `sort` is applied
746
- * after filtering. `offset` is zero-based and `limit` is nullable.
747
- * @returns Records and pagination metadata.
748
- * @example
749
- * ```ts
750
- * const page = table.queryRecords({
751
- * filter: { fieldId: 'status', operator: 'is', value: 'done' },
752
- * sort: [{ fieldId: 'progress', direction: 'desc' }],
414
+ * @param {IListRecordOptions} [options] Optional query options.
415
+ * @returns {IQueryRecordsResult} The query result with records, total count, offset, limit, and hasMore flag.
416
+ * @example
417
+ * ```ts
418
+ * const fBase = univerAPI.getActiveBase();
419
+ * const fBaseTable = fBase.getTableById('table-1');
420
+ * const page = fBaseTable.queryRecords({
421
+ * filter: {
422
+ * conditions: [{
423
+ * fieldId: 'status',
424
+ * operator: univerAPI.Enum.BaseFilterOperator.IS,
425
+ * value: 'done'
426
+ * }]
427
+ * },
428
+ * sort: [{
429
+ * fieldId: 'progress',
430
+ * direction: univerAPI.Enum.BaseSortDirection.DESC
431
+ * }],
753
432
  * limit: 20,
754
433
  * });
755
- * ```
756
- *
757
- * @example Browser console
758
- * ```ts
759
- * console.log((() => {
760
- * const unitId = `facade_example_${Date.now()}`;
761
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
762
- * try {
763
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
764
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
765
- * const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
766
- * return table.queryRecords({ filter: { fieldId: field.getId(), operator: 'is', value: 'todo' } });
767
- * } finally {
768
- * univerAPI.disposeUnit(unitId);
769
- * }
770
- * })());
434
+ * console.log(page);
771
435
  * ```
772
436
  */
773
437
  queryRecords(options?: IListRecordOptions): IQueryRecordsResult;
774
- private _resolveRecordIds;
775
438
  /**
776
- * List records in this table.
777
- * @param options Optional list options. Use `viewId` to return records in view projection order.
778
- * @returns Record facades.
779
- * @example
780
- * ```ts
781
- * const records = table.listRecords({ viewId: 'grid' });
782
- * ```
439
+ * Add a record to this table.
440
+ * @param {Record<FieldId, BaseCellValue>} values The record field values, keyed by field id or name.
441
+ * @param {BaseFieldKeyEnum} [fieldKey] Optional field key type for the values. Defaults to `id`.
442
+ * @param {Partial<Omit<IRecordSnapshot, 'id'>>} [record] Optional partial record snapshot to merge into the new record.
443
+ * @returns {FBaseTableRecord} The new record facade.
783
444
  *
784
- * @example Browser console
445
+ * @example
785
446
  * ```ts
786
- * console.log((() => {
787
- * const unitId = `facade_example_${Date.now()}`;
788
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
789
- * try {
790
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
791
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
792
- * const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
793
- * return table.listRecords().map((record) => record.getId());
794
- * } finally {
795
- * univerAPI.disposeUnit(unitId);
447
+ * const fBase = univerAPI.getActiveBase();
448
+ * const fBaseTable = fBase.getTableById('table-1');
449
+ * const record = fBaseTable.addRecord(
450
+ * {
451
+ * title: 'Ship beta',
452
+ * status: 'todo'
796
453
  * }
797
- * })());
454
+ * );
455
+ * console.log(record);
798
456
  * ```
799
- */
800
- listRecords(options?: IListRecordOptions): FRecord[];
801
- /**
802
- * Add a record to this table.
803
- *
804
- * Values are keyed by field id, not by field name. Use
805
- * `table.getPrimaryFieldId()` or field facade ids to avoid name collisions
806
- * and localization issues.
807
457
  *
808
- * @param input Record creation options. `id` is optional and should be
809
- * supplied when the server owns ids. `values` is a field-id keyed map.
810
- * `orderKey` controls row order and the command keeps the table
811
- * `recordOrder` in sync. `createdAt`, `updatedAt`, `createdBy`, and
812
- * `updatedBy` are optional metadata.
813
- * @returns The created record facade.
814
458
  * @example
815
459
  * ```ts
816
- * const record = table.addRecord({
817
- * id: 'record-1',
818
- * values: { title: 'Ship beta', status: 'todo' },
819
- * });
820
- * ```
821
- * @example Using field ids from facades
822
- * ```ts
823
- * const record = table.addRecord({
824
- * id: 'task-1',
825
- * values: {
826
- * [table.getPrimaryFieldId()]: 'Ship Base adapter',
827
- * [statusField.getId()]: 'todo',
460
+ * const fBase = univerAPI.getActiveBase();
461
+ * const fBaseTable = fBase.getTableById('table-1');
462
+ * const record = fBaseTable.addRecord(
463
+ * {
464
+ * Title: 'Ship beta',
465
+ * Status: 'todo'
828
466
  * },
829
- * });
467
+ * univerAPI.Enum.BaseFieldKeyEnum.Name
468
+ * );
469
+ * console.log(record);
830
470
  * ```
831
471
  *
832
- * @example Browser console
833
- * ```ts
834
- * console.log((() => {
835
- * const unitId = `facade_example_${Date.now()}`;
836
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
837
- * try {
838
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
839
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
840
- * const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
841
- * return { id: record.getId(), values: record.getValues() };
842
- * } finally {
843
- * univerAPI.disposeUnit(unitId);
844
- * }
845
- * })());
846
- * ```
847
- */
848
- addRecord(input?: IAddRecordInput): FRecord;
849
- /**
850
- * Create a record in this table.
851
- * @param input Record creation options.
852
- * @returns The created record facade.
853
472
  * @example
854
473
  * ```ts
855
- * const record = table.createRecord({ values: { title: 'New task' } });
856
- * ```
474
+ * const fBase = univerAPI.getActiveBase();
475
+ * const fBaseTable = fBase.getTableById('table-1');
857
476
  *
858
- * @example Browser console
859
- * ```ts
860
- * console.log((() => {
861
- * const unitId = `facade_example_${Date.now()}`;
862
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
863
- * try {
864
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
865
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
866
- * const created = table.createRecord({ id: `${unitId}_created`, fields: { Title: 'Created', Status: 'done' }, fieldKey: univerAPI.Enum.BaseFieldKeyEnum.Name });
867
- * return created.getValues();
868
- * } finally {
869
- * univerAPI.disposeUnit(unitId);
477
+ * const fields = fBaseTable.getFields();
478
+ * const values: Record<FieldId, BaseCellValue> = {};
479
+ *
480
+ * for (const field of fields) {
481
+ * if (field.getName() === 'Title') {
482
+ * values[field.getId()] = 'Ship Base adapter';
483
+ * } else if (field.getName() === 'Status') {
484
+ * values[field.getId()] = 'todo';
870
485
  * }
871
- * })());
486
+ * }
487
+ *
488
+ * const record = fBaseTable.addRecord(values);
489
+ * console.log(record);
872
490
  * ```
873
491
  */
874
- createRecord(input?: IAddRecordInput): FRecord;
492
+ addRecord(values: Record<FieldId, BaseCellValue>, fieldKey?: BaseFieldKeyEnum, record?: Partial<Omit<IRecordSnapshot, 'id'>>): FBaseTableRecord;
875
493
  /**
876
494
  * Add multiple records to this table.
877
- *
878
- * This executes one batch command, so undo/redo, collaboration,
879
- * `recordOrder`, and events see a single multi-record operation.
880
- *
881
- * @param inputs Record creation options. Each input has the same shape as
882
- * `addRecord()`. Empty arrays are ignored and return `[]`.
883
- * @returns Created record facades.
495
+ * @param {Array<{
496
+ * values: Record<FieldId, BaseCellValue>;
497
+ * fieldKey?: BaseFieldKeyEnum;
498
+ * record?: Partial<Omit<IRecordSnapshot, 'id'>>;
499
+ * }>} records An array of record values, optional field key types, and optional partial record snapshots.
500
+ * @returns {FBaseTableRecord[]} An array of created record facades.
884
501
  * @example
885
502
  * ```ts
886
- * const records = table.addRecords([
503
+ * const fBase = univerAPI.getActiveBase();
504
+ * const fBaseTable = fBase.getTableById('table-1');
505
+ * const records = fBaseTable.addRecords([
887
506
  * { values: { title: 'Task A' } },
888
507
  * { values: { title: 'Task B' } },
889
508
  * ]);
890
- * ```
891
- *
892
- * @example Browser console
893
- * ```ts
894
- * console.log((() => {
895
- * const unitId = `facade_example_${Date.now()}`;
896
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
897
- * try {
898
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
899
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
900
- * const records = table.addRecords([{ id: `${unitId}_a`, fields: { Title: 'A', Status: 'todo' }, fieldKey: univerAPI.Enum.BaseFieldKeyEnum.Name }, { id: `${unitId}_b`, fields: { Title: 'B', Status: 'done' }, fieldKey: univerAPI.Enum.BaseFieldKeyEnum.Name }]);
901
- * return records.map((record) => record.getId());
902
- * } finally {
903
- * univerAPI.disposeUnit(unitId);
904
- * }
905
- * })());
509
+ * console.log(records);
906
510
  * ```
907
511
  */
908
- addRecords(inputs: IAddRecordInput[]): FRecord[];
512
+ addRecords(records: Array<{
513
+ values: Record<FieldId, BaseCellValue>;
514
+ fieldKey?: BaseFieldKeyEnum;
515
+ record?: Partial<Omit<IRecordSnapshot, 'id'>>;
516
+ }>): FBaseTableRecord[];
909
517
  /**
910
- * Set values for multiple records.
911
- *
912
- * This is the preferred API for server-side or agent-side bulk updates
913
- * where each record may update different fields.
914
- *
915
- * @param patches Record value patches. `recordId` identifies the target row
916
- * and `values` is a field-id keyed partial value map.
518
+ * Delete multiple records from this table.
519
+ * @param {string[]} recordIds An array of record ids to delete.
917
520
  * @example
918
521
  * ```ts
919
- * table.setRecordValues([
920
- * { recordId: 'record-1', values: { status: 'done' } },
921
- * { recordId: 'record-2', values: { status: 'todo' } },
522
+ * const fBase = univerAPI.getActiveBase();
523
+ * const fBaseTable = fBase.getTableById('table-1');
524
+ * const records = fBaseTable.getRecords();
525
+ * const success = fBaseTable.deleteRecords([
526
+ * records[0].getId(),
527
+ * records[2].getId(),
922
528
  * ]);
923
- * ```
924
- *
925
- * @example Browser console
926
- * ```ts
927
- * console.log((() => {
928
- * const unitId = `facade_example_${Date.now()}`;
929
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
930
- * try {
931
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
932
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
933
- * const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
934
- * table.setRecordValues([{ recordId: record.getId(), fields: { Title: 'Updated', Status: 'done' }, fieldKey: univerAPI.Enum.BaseFieldKeyEnum.Name }]);
935
- * return record.getValues();
936
- * } finally {
937
- * univerAPI.disposeUnit(unitId);
938
- * }
939
- * })());
940
- * ```
941
- */
942
- setRecordValues(patches: Array<{
943
- recordId: string;
944
- values?: Record<string, BaseCellValue>;
945
- fields?: Record<string, BaseCellValue>;
946
- fieldKey?: BaseFieldKey;
947
- }>, options?: IUpdateRecordOptions): void;
948
- /**
949
- * Update one record by id.
950
- * @param recordId The record id.
951
- * @param values Field-id keyed values to write.
952
- * @example
953
- * ```ts
954
- * table.updateRecord('record-1', { title: 'Updated task', status: 'done' });
955
- * ```
956
- *
957
- * @example Browser console
958
- * ```ts
959
- * console.log((() => {
960
- * const unitId = `facade_example_${Date.now()}`;
961
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
962
- * try {
963
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
964
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
965
- * const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
966
- * table.updateRecord(record.getId(), { Title: 'Updated by name', Status: 'done' }, { fieldKey: univerAPI.Enum.BaseFieldKeyEnum.Name });
967
- * return record.getValues();
968
- * } finally {
969
- * univerAPI.disposeUnit(unitId);
970
- * }
971
- * })());
972
- * ```
973
- */
974
- updateRecord(recordId: string, values: Record<string, BaseCellValue>, options?: IUpdateRecordOptions): void;
975
- /**
976
- * Delete a record by id.
977
- * @param recordId The record id.
978
- * @example
979
- * ```ts
980
- * table.deleteRecord('record-1');
981
- * ```
982
- *
983
- * @example Browser console
984
- * ```ts
985
- * console.log((() => {
986
- * const unitId = `facade_example_${Date.now()}`;
987
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
988
- * try {
989
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
990
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
991
- * const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
992
- * const recordId = record.getId();
993
- * table.deleteRecord(recordId);
994
- * return table.getRecord(recordId);
995
- * } finally {
996
- * univerAPI.disposeUnit(unitId);
997
- * }
998
- * })());
529
+ * console.log(success);
999
530
  * ```
1000
531
  */
1001
- deleteRecord(recordId: string): void;
1002
- /**
1003
- * Delete multiple records as one undoable command.
1004
- * @param recordIds Record ids to delete.
1005
- * @example
1006
- * ```ts
1007
- * table.deleteRecords(['record-1', 'record-2']);
1008
- * ```
1009
- *
1010
- * @example Browser console
1011
- * ```ts
1012
- * console.log((() => {
1013
- * const unitId = `facade_example_${Date.now()}`;
1014
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
1015
- * try {
1016
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
1017
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
1018
- * const records = table.addRecords([{ id: `${unitId}_a`, fields: { Title: 'A' }, fieldKey: univerAPI.Enum.BaseFieldKeyEnum.Name }, { id: `${unitId}_b`, fields: { Title: 'B' }, fieldKey: univerAPI.Enum.BaseFieldKeyEnum.Name }]);
1019
- * table.deleteRecords(records.map((record) => record.getId()));
1020
- * return records.map((record) => table.getRecord(record.getId()));
1021
- * } finally {
1022
- * univerAPI.disposeUnit(unitId);
1023
- * }
1024
- * })());
1025
- * ```
1026
- */
1027
- deleteRecords(recordIds: string[]): void;
1028
- /**
1029
- * Duplicate a record by id.
1030
- * @param recordId The source record id.
1031
- * The duplicated record starts with the source record values, then applies
1032
- * `input.values` as field-id keyed overrides.
1033
- *
1034
- * @param input Optional record id, values, and metadata overrides.
1035
- * @param input.id Optional id for the duplicated record.
1036
- * @param input.values Optional field-id keyed values for the duplicated record.
1037
- * @param input.orderKey Optional order key for the duplicated record.
1038
- * @param input.createdAt Optional creation timestamp override.
1039
- * @param input.updatedAt Optional update timestamp override.
1040
- * @param input.createdBy Optional creator user id override.
1041
- * @param input.updatedBy Optional updater user id override.
1042
- * @returns The duplicated record facade.
1043
- * @example
1044
- * ```ts
1045
- * const copy = table.duplicateRecord('record-1', {
1046
- * values: { title: 'Copied task' },
1047
- * });
1048
- * ```
1049
- *
1050
- * @example Browser console
1051
- * ```ts
1052
- * console.log((() => {
1053
- * const unitId = `facade_example_${Date.now()}`;
1054
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
1055
- * try {
1056
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
1057
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
1058
- * const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
1059
- * const duplicated = table.duplicateRecord(record.getId(), { id: `${unitId}_copy`, fields: { Title: 'Copy' }, fieldKey: univerAPI.Enum.BaseFieldKeyEnum.Name });
1060
- * return { original: record.getId(), duplicated: duplicated.getId() };
1061
- * } finally {
1062
- * univerAPI.disposeUnit(unitId);
1063
- * }
1064
- * })());
1065
- * ```
1066
- */
1067
- duplicateRecord(recordId: string, input?: IAddRecordInput): FRecord;
1068
- /**
1069
- * Update one cell value.
1070
- * @param recordId The record id.
1071
- * @param fieldId The field id.
1072
- * @param value The new cell value.
1073
- * @example
1074
- * ```ts
1075
- * table.updateCell('record-1', 'status', 'done');
1076
- * ```
1077
- *
1078
- * @example Browser console
1079
- * ```ts
1080
- * console.log((() => {
1081
- * const unitId = `facade_example_${Date.now()}`;
1082
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
1083
- * try {
1084
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
1085
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
1086
- * const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
1087
- * table.updateCell(record.getId(), field.getId(), 'done');
1088
- * return table.getCellValue(record.getId(), field.getId());
1089
- * } finally {
1090
- * univerAPI.disposeUnit(unitId);
1091
- * }
1092
- * })());
1093
- * ```
1094
- */
1095
- updateCell(recordId: string, fieldId: string, value: BaseCellValue): void;
1096
- /**
1097
- * Set one cell value.
1098
- * @param recordId The record id.
1099
- * @param fieldId The field id.
1100
- * @param value The new cell value.
1101
- * @example
1102
- * ```ts
1103
- * table.setCellValue('record-1', 'status', 'done');
1104
- * ```
1105
- *
1106
- * @example Browser console
1107
- * ```ts
1108
- * console.log((() => {
1109
- * const unitId = `facade_example_${Date.now()}`;
1110
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
1111
- * try {
1112
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
1113
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
1114
- * const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
1115
- * table.setCellValue(record.getId(), field.getId(), 'done');
1116
- * return table.getCellValue(record.getId(), field.getId());
1117
- * } finally {
1118
- * univerAPI.disposeUnit(unitId);
1119
- * }
1120
- * })());
1121
- * ```
1122
- */
1123
- setCellValue(recordId: string, fieldId: string, value: BaseCellValue): void;
1124
- /**
1125
- * Get one cell value.
1126
- * @param recordId The record id.
1127
- * @param fieldId The field id.
1128
- * @returns The cell value, or null when empty.
1129
- * @example
1130
- * ```ts
1131
- * const value = table.getCellValue('record-1', 'status');
1132
- * ```
1133
- *
1134
- * @example Browser console
1135
- * ```ts
1136
- * console.log((() => {
1137
- * const unitId = `facade_example_${Date.now()}`;
1138
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
1139
- * try {
1140
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
1141
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
1142
- * const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
1143
- * return table.getCellValue(record.getId(), field.getId());
1144
- * } finally {
1145
- * univerAPI.disposeUnit(unitId);
1146
- * }
1147
- * })());
1148
- * ```
1149
- */
1150
- getCellValue(recordId: string, fieldId: string): BaseCellValue;
1151
- /**
1152
- * Update a record order key.
1153
- * @param recordId The record id.
1154
- * @param target The target order key.
1155
- * @param target.orderKey Optional replacement order key. Existing order key
1156
- * is kept when omitted.
1157
- * @example
1158
- * ```ts
1159
- * table.updateRecordOrder('record-1', { orderKey: 'a1' });
1160
- * ```
1161
- *
1162
- * @example Browser console
1163
- * ```ts
1164
- * console.log((() => {
1165
- * const unitId = `facade_example_${Date.now()}`;
1166
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
1167
- * try {
1168
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
1169
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
1170
- * const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
1171
- * table.updateRecordOrder(record.getId(), { orderKey: 'z' });
1172
- * return table.getRecord(record.getId())?.getRecord().orderKey;
1173
- * } finally {
1174
- * univerAPI.disposeUnit(unitId);
1175
- * }
1176
- * })());
1177
- * ```
1178
- */
1179
- updateRecordOrder(recordId: string, target: {
1180
- orderKey?: string;
1181
- }): void;
532
+ deleteRecords(recordIds: string[]): boolean;
1182
533
  /**
1183
534
  * Get a rectangular range by row and column indexes.
1184
535
  *
@@ -1186,352 +537,157 @@ export declare class FTable {
1186
537
  * This mirrors Sheet-style row/column addressing while still writing Base
1187
538
  * record/field values under the hood.
1188
539
  *
1189
- * @param row The zero-based start row index.
1190
- * @param column The zero-based start column index.
1191
- * @param numRows Number of rows. Defaults to `1`.
1192
- * @param numColumns Number of columns. Defaults to `1`.
1193
- * @returns A Base range facade.
540
+ * @param {number} row The zero-based row index.
541
+ * @param {number} column The zero-based column index.
542
+ * @param {number} [numRows] Optional number of rows in the range. Defaults to 1.
543
+ * @param {number} [numColumns] Optional number of columns in the range. Defaults to 1.
544
+ * @returns {FBaseTableRange} The range facade.
1194
545
  * @example
1195
546
  * ```ts
1196
- * const range = table.getRange(0, 0, 2, 3);
1197
- * const values = range.getValues();
1198
- * ```
1199
- * @example Write a 2 by 2 block
1200
- * ```ts
1201
- * table.getRange(0, 0, 2, 2).setValues([
547
+ * const fBase = univerAPI.getActiveBase();
548
+ * const fBaseTable = fBase.getTableById('table-1');
549
+ *
550
+ * const range = fBaseTable.getRange(0, 0, 2, 3);
551
+ * console.log(range.getValues());
552
+ *
553
+ * fBaseTable.getRange(0, 0, 2, 2).setValues([
1202
554
  * ['Task A', 'todo'],
1203
555
  * ['Task B', 'done'],
1204
556
  * ]);
1205
557
  * ```
1206
- *
1207
- * @example Browser console
1208
- * ```ts
1209
- * console.log((() => {
1210
- * const unitId = `facade_example_${Date.now()}`;
1211
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
1212
- * try {
1213
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
1214
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
1215
- * table.addRecords([
1216
- * { id: `${unitId}_a`, values: { [table.getPrimaryFieldId()]: 'A', [field.getId()]: 'todo' } },
1217
- * { id: `${unitId}_b`, values: { [table.getPrimaryFieldId()]: 'B', [field.getId()]: 'done' } },
1218
- * ]);
1219
- * const range = table.getRange(0, 0, 2, 1);
1220
- * return table.getRange(0, 0, 1, 1).getValues();
1221
- * } finally {
1222
- * univerAPI.disposeUnit(unitId);
1223
- * }
1224
- * })());
1225
- * ```
1226
558
  */
1227
- getRange(row: number, column: number, numRows?: number, numColumns?: number): FBaseRange;
559
+ getRange(row: number, column: number, numRows?: number, numColumns?: number): FBaseTableRange;
1228
560
  /**
1229
561
  * Get a range that covers the current table data area.
1230
- * @returns The data range facade.
1231
- * @example
1232
- * ```ts
1233
- * const values = table.getDataRange().getValues();
1234
- * ```
1235
- *
1236
- * @example Browser console
1237
- * ```ts
1238
- * console.log((() => {
1239
- * const unitId = `facade_example_${Date.now()}`;
1240
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
1241
- * try {
1242
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
1243
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
1244
- * table.addRecords([
1245
- * { id: `${unitId}_a`, values: { [table.getPrimaryFieldId()]: 'A', [field.getId()]: 'todo' } },
1246
- * { id: `${unitId}_b`, values: { [table.getPrimaryFieldId()]: 'B', [field.getId()]: 'done' } },
1247
- * ]);
1248
- * const range = table.getRange(0, 0, 2, 1);
1249
- * return table.getDataRange().getValues();
1250
- * } finally {
1251
- * univerAPI.disposeUnit(unitId);
1252
- * }
1253
- * })());
1254
- * ```
1255
- */
1256
- getDataRange(): FBaseRange;
1257
- /**
1258
- * Get all non-deleted views in this table.
1259
- * @returns View facades ordered by the table view order.
562
+ * @returns {FBaseTableRange} The range facade covering the table data area.
1260
563
  * @example
1261
564
  * ```ts
1262
- * const views = table.getViews();
1263
- * ```
1264
- *
1265
- * @example Browser console
1266
- * ```ts
1267
- * console.log((() => {
1268
- * const unitId = `facade_example_${Date.now()}`;
1269
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
1270
- * try {
1271
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
1272
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
1273
- * const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
1274
- * const view = table.createView({ id: `${unitId}_view`, name: 'Grid', type: 'grid' });
1275
- * return table.getViews().map((view) => view.getName());
1276
- * } finally {
1277
- * univerAPI.disposeUnit(unitId);
1278
- * }
1279
- * })());
565
+ * const fBase = univerAPI.getActiveBase();
566
+ * const fBaseTable = fBase.getTableById('table-1');
567
+ * const values = fBaseTable.getDataRange().getValues();
568
+ * console.log(values);
1280
569
  * ```
1281
570
  */
1282
- getViews(): FView[];
571
+ getDataRange(): FBaseTableRange;
1283
572
  /**
1284
- * List all non-deleted views in this table.
1285
- * @returns View facades ordered by the table view order.
573
+ * Get all existing views in this table.
574
+ * @returns {FBaseTableView[]} An array of view facades ordered by the table view order.
1286
575
  * @example
1287
576
  * ```ts
1288
- * const views = table.listViews();
1289
- * ```
1290
- *
1291
- * @example Browser console
1292
- * ```ts
1293
- * console.log((() => {
1294
- * const unitId = `facade_example_${Date.now()}`;
1295
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
1296
- * try {
1297
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
1298
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
1299
- * const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
1300
- * const view = table.createView({ id: `${unitId}_view`, name: 'Grid', type: 'grid' });
1301
- * return table.listViews().map((view) => view.getName());
1302
- * } finally {
1303
- * univerAPI.disposeUnit(unitId);
1304
- * }
1305
- * })());
577
+ * const fBase = univerAPI.getActiveBase();
578
+ * const fBaseTable = fBase.getTableById('table-1');
579
+ * const views = fBaseTable.getViews();
580
+ * console.log(views);
1306
581
  * ```
1307
582
  */
1308
- listViews(): FView[];
583
+ getViews(): FBaseTableView[];
1309
584
  /**
1310
585
  * Get a view by id.
1311
- * @param viewId The view id.
1312
- * @returns The view facade, or null if the view does not exist.
586
+ * @param {string} viewId The view id.
587
+ * @returns {FBaseTableView | null} The view facade, or null if the view does not exist.
1313
588
  * @example
1314
589
  * ```ts
1315
- * const view = table.getView('grid');
1316
- * ```
1317
- *
1318
- * @example Browser console
1319
- * ```ts
1320
- * console.log((() => {
1321
- * const unitId = `facade_example_${Date.now()}`;
1322
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
1323
- * try {
1324
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
1325
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
1326
- * const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
1327
- * const view = table.createView({ id: `${unitId}_view`, name: 'Grid', type: 'grid' });
1328
- * return table.getView(view.getId())?.getName() ?? null;
1329
- * } finally {
1330
- * univerAPI.disposeUnit(unitId);
1331
- * }
1332
- * })());
590
+ * const fBase = univerAPI.getActiveBase();
591
+ * const fBaseTable = fBase.getTableById('table-1');
592
+ * const view = fBaseTable.getViewById('grid');
593
+ * console.log(view);
1333
594
  * ```
1334
595
  */
1335
- getView(viewId: string): FView | null;
596
+ getViewById(viewId: string): FBaseTableView | null;
1336
597
  /**
1337
- * Get a view by id.
1338
- * @param viewId The view id.
1339
- * @returns The view facade, or null if the view does not exist.
598
+ * Get a view by name.
599
+ * @param {string} viewName The view name.
600
+ * @returns {FBaseTableView | null} The view facade, or null if the view does not exist.
1340
601
  * @example
1341
602
  * ```ts
1342
- * const view = table.getViewById('grid');
1343
- * ```
1344
- *
1345
- * @example Browser console
1346
- * ```ts
1347
- * console.log((() => {
1348
- * const unitId = `facade_example_${Date.now()}`;
1349
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
1350
- * try {
1351
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
1352
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
1353
- * const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
1354
- * const view = table.createView({ id: `${unitId}_view`, name: 'Grid', type: 'grid' });
1355
- * return table.getViewById(view.getId())?.getName() ?? null;
1356
- * } finally {
1357
- * univerAPI.disposeUnit(unitId);
1358
- * }
1359
- * })());
603
+ * const fBase = univerAPI.getActiveBase();
604
+ * const fBaseTable = fBase.getTableById('table-1');
605
+ * const view = fBaseTable.getViewByName('Grid');
606
+ * console.log(view);
1360
607
  * ```
1361
608
  */
1362
- getViewById(viewId: string): FView | null;
1363
- /**
1364
- * Get the first view matching a view name.
1365
- * @param name The view name.
1366
- * @returns The view facade, or null if no view matches.
1367
- * @example
1368
- * ```ts
1369
- * const view = table.getViewByName('Grid');
1370
- * ```
1371
- *
1372
- * @example Browser console
1373
- * ```ts
1374
- * console.log((() => {
1375
- * const unitId = `facade_example_${Date.now()}`;
1376
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
1377
- * try {
1378
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
1379
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
1380
- * const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
1381
- * const view = table.createView({ id: `${unitId}_view`, name: 'Grid', type: 'grid' });
1382
- * return table.getViewByName('Grid')?.getId() ?? null;
1383
- * } finally {
1384
- * univerAPI.disposeUnit(unitId);
1385
- * }
1386
- * })());
1387
- * ```
1388
- */
1389
- getViewByName(name: string): FView | null;
609
+ getViewByName(viewName: string): FBaseTableView | null;
1390
610
  /**
1391
611
  * Create a view in this table.
1392
- *
1393
- * The view starts with the table's current field order and empty field
1394
- * settings. Configure filters, sort, grouping, field visibility, and field
1395
- * widths through the returned `FView`.
1396
- *
1397
- * @param input View creation options. `name` and `type` are required.
1398
- * `config` is view-type specific, for example grid frozen fields, calendar
1399
- * date fields, or gantt start/end/progress fields. `index` controls view
1400
- * order.
1401
- * @returns The created view facade.
1402
- * @example
1403
- * ```ts
1404
- * const view = table.createView({
1405
- * id: 'grid-api',
1406
- * name: 'API Grid',
1407
- * type: 'grid',
1408
- * config: { frozenFieldCount: 1 },
1409
- * });
1410
- * ```
1411
- * @example Calendar and gantt views
1412
- * ```ts
1413
- * const calendar = table.createView({
1414
- * id: 'calendar-main',
1415
- * name: 'Calendar',
1416
- * type: 'calendar',
1417
- * config: { startFieldId: 'start', endFieldId: 'end' },
1418
- * });
1419
- * const gantt = table.createView({
1420
- * id: 'gantt-main',
1421
- * name: 'Gantt',
1422
- * type: 'gantt',
1423
- * config: { startFieldId: 'start', endFieldId: 'end', progressFieldId: 'progress' },
1424
- * });
1425
- * ```
1426
- *
1427
- * @example Browser console
1428
- * ```ts
1429
- * console.log((() => {
1430
- * const unitId = `facade_example_${Date.now()}`;
1431
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
1432
- * try {
1433
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
1434
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
1435
- * const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
1436
- * const view = table.createView({ id: `${unitId}_view`, name: 'Grid', type: 'grid' });
1437
- * return { id: view.getId(), type: view.getType() };
1438
- * } finally {
1439
- * univerAPI.disposeUnit(unitId);
1440
- * }
1441
- * })());
1442
- * ```
1443
- */
1444
- createView(input: ICreateViewInput): FView;
1445
- /**
1446
- * Delete a view by id.
1447
- * @param viewId The view id.
1448
- * @example
1449
- * ```ts
1450
- * table.deleteView('grid-api');
1451
- * ```
1452
- *
1453
- * @example Browser console
1454
- * ```ts
1455
- * console.log((() => {
1456
- * const unitId = `facade_example_${Date.now()}`;
1457
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
1458
- * try {
1459
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
1460
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
1461
- * const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
1462
- * const view = table.createView({ id: `${unitId}_view`, name: 'Grid', type: 'grid' });
1463
- * const viewId = view.getId();
1464
- * table.deleteView(viewId);
1465
- * return table.getView(viewId);
1466
- * } finally {
1467
- * univerAPI.disposeUnit(unitId);
1468
- * }
1469
- * })());
1470
- * ```
1471
- */
1472
- deleteView(viewId: string): void;
612
+ * @param {string} name The view display name.
613
+ * @param {BaseViewType} type The view type, such as `grid`, `calendar`, or `gantt`.
614
+ * @param {object} [options] Optional view parameters.
615
+ * @param {number} [options.index] Optional insertion index in the table view order.
616
+ * @param {Partial<Omit<IViewSnapshot, 'id'>>} [options.view] Optional partial view snapshot to merge into the new view.
617
+ * @returns {FBaseTableView} The new view facade.
618
+ *
619
+ * @example
620
+ * ```ts
621
+ * const fBase = univerAPI.getActiveBase();
622
+ * const fBaseTable = fBase.getTableById('table-1');
623
+ * const view = fBaseTable.createView(
624
+ * 'API Grid',
625
+ * univerAPI.Enum.BaseViewType.Grid,
626
+ * {
627
+ * view: {
628
+ * id: 'grid-api',
629
+ * config: {
630
+ * frozenFieldCount: 1
631
+ * },
632
+ * },
633
+ * }
634
+ * );
635
+ * console.log(view);
636
+ * ```
637
+ *
638
+ * @example
639
+ * ```ts
640
+ * const fBase = univerAPI.getActiveBase();
641
+ * const fBaseTable = fBase.getTableById('table-1');
642
+ *
643
+ * const calendar = fBaseTable.createView(
644
+ * 'Calendar',
645
+ * univerAPI.Enum.BaseViewType.Calendar,
646
+ * {
647
+ * view: {
648
+ * id: 'calendar-main',
649
+ * config: {
650
+ * startFieldId: 'start',
651
+ * endFieldId: 'end'
652
+ * },
653
+ * }
654
+ * }
655
+ * );
656
+ * console.log(calendar);
657
+ *
658
+ * const gantt = fBaseTable.createView(
659
+ * 'Gantt',
660
+ * univerAPI.Enum.BaseViewType.Gantt,
661
+ * {
662
+ * view: {
663
+ * id: 'gantt-main',
664
+ * config: {
665
+ * startFieldId: 'start',
666
+ * endFieldId: 'end',
667
+ * progressFieldId: 'progress'
668
+ * },
669
+ * }
670
+ * }
671
+ * );
672
+ * console.log(gantt);
673
+ * ```
674
+ */
675
+ createView(name: string, type: BaseViewType, options?: {
676
+ index?: number;
677
+ view?: Partial<Omit<IViewSnapshot, 'id'>>;
678
+ }): FBaseTableView;
1473
679
  /**
1474
680
  * Get a compact schema snapshot for this table.
1475
681
  * @returns Table schema without row values.
1476
682
  * @example
1477
683
  * ```ts
1478
- * console.log(table.getSchema().fields.map((field) => field.name));
1479
- * ```
1480
- *
1481
- * @example Browser console
1482
- * ```ts
1483
- * console.log((() => {
1484
- * const unitId = `facade_example_${Date.now()}`;
1485
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
1486
- * try {
1487
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
1488
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
1489
- * const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
1490
- * const view = table.createView({ id: `${unitId}_view`, name: 'Grid', type: 'grid' });
1491
- * return table.getSchema();
1492
- * } finally {
1493
- * univerAPI.disposeUnit(unitId);
1494
- * }
1495
- * })());
684
+ * const fBase = univerAPI.getActiveBase();
685
+ * const fBaseTable = fBase.getTableById('table-1');
686
+ * const schema = fBaseTable.getSchema();
687
+ * console.log(schema);
1496
688
  * ```
1497
689
  */
1498
690
  getSchema(): IBaseTableSchemaSnapshot;
1499
- /**
1500
- * Get the table permission facade.
1501
- * @returns Table permission facade.
1502
- * @example
1503
- * ```ts
1504
- * table.getPermission().setPermission({ createRecord: false });
1505
- * ```
1506
- *
1507
- * @example Browser console
1508
- * ```ts
1509
- * console.log((() => {
1510
- * const unitId = `facade_example_${Date.now()}`;
1511
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
1512
- * try {
1513
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
1514
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
1515
- * const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
1516
- * const view = table.createView({ id: `${unitId}_view`, name: 'Grid', type: 'grid' });
1517
- * const permission = table.getPermission();
1518
- * return permission.canCreateRecord();
1519
- * } finally {
1520
- * univerAPI.disposeUnit(unitId);
1521
- * }
1522
- * })());
1523
- * ```
1524
- */
1525
- getPermission(): FTablePermission;
1526
691
  private _getTable;
1527
- private _wrapField;
1528
- private _wrapRecord;
1529
- private _wrapView;
692
+ private _resolveRecordIds;
1530
693
  }
1531
- export type AddFieldInput = IAddFieldInput;
1532
- export type AddRecordInput = IAddRecordInput;
1533
- export type CreateViewInput = ICreateViewInput;
1534
- export type ListRecordOptions = IListRecordOptions;
1535
- export type BaseRecordFilter = IBaseRecordFilter;
1536
- export type QueryRecordsResult = IQueryRecordsResult;
1537
- export type BaseTableSchemaSnapshot = IBaseTableSchemaSnapshot;