@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,212 +1,39 @@
1
- import type { IBaseCommandService, IBasePermissionService, IBaseProjectionService, IBaseTableSearchResult } from '@univerjs-pro/bases';
2
- import type { BaseDataModel, FieldId, IBaseSnapshot, ICommandInfo, ICommandService, IDisposable, IUndoRedoService, IUniverInstanceService } from '@univerjs/core';
3
- import type { IBaseEventMap } from './f-event';
4
- import { BaseEventName } from './f-event';
5
- import { FBasePermission } from './f-permission';
6
- import { FTable } from './f-table';
7
- import { BaseTransactionContext } from './transaction';
8
- export interface ICreateTableInput {
9
- /** Optional table id. A random id is generated when omitted. */
10
- id?: string;
11
- /** Table display name. */
12
- name: string;
13
- /** Primary text field display name. */
14
- primaryFieldName?: string;
15
- /** Optional insertion index in the Base table order. */
16
- index?: number;
17
- }
18
- export interface ISearchTableInput {
19
- /** Search text. Blank queries return no matches. */
20
- query: string;
21
- /** Optional view id. When provided, records are searched in the view projection. */
22
- viewId?: string;
23
- /** Optional field ids to search. Defaults to visible/searchable fields. */
24
- fieldIds?: ReadonlyArray<FieldId>;
25
- /** Optional maximum number of matches. */
26
- limit?: number;
27
- }
28
- export interface ICopyTableInput {
29
- /** Optional table id for the copied table. A random id is generated when omitted. */
30
- id?: string;
31
- /** Optional copied table name. Defaults to `<source name> Copy`. */
32
- name?: string;
33
- /** Whether records and record resources should be copied. Defaults to false. */
34
- includeRecords?: boolean;
35
- /** Optional insertion index in the Base table order. */
36
- index?: number;
37
- }
1
+ import type { BaseDataModel, IBaseSnapshot, ITableSnapshot } from '@univerjs/core';
2
+ import type { IBaseTableSchemaSnapshot } from './f-table';
3
+ import { Injector } from '@univerjs/core';
4
+ import { FBaseTable } from './f-table';
38
5
  export interface IBaseSchemaSnapshot {
39
6
  id: string;
40
7
  name: string;
41
- tables: Array<{
42
- id: string;
43
- name: string;
44
- primaryFieldId: string;
45
- fieldIds: string[];
46
- viewIds: string[];
47
- recordCount: number;
48
- }>;
8
+ tables: IBaseTableSchemaSnapshot[];
49
9
  }
50
10
  /**
51
11
  * Facade API object bound to a Base unit.
52
- *
53
- * A Base contains multiple tables. In spreadsheet terms this is similar to a workbook,
54
- * while a Base table is similar to a worksheet.
55
- *
56
- * Use `FBase` for runtime edits and use `getSnapshot()` / `save()` only at the
57
- * persistence boundary. Facade writes execute commands, so Base events,
58
- * permissions, undo/redo, formula dirty ranges, and collaboration adapters see
59
- * the same operations as UI edits.
60
- *
61
- * @example Load a server snapshot, edit it, and save it back
62
- * ```ts
63
- * const base = univerAPI.createBase(serverSnapshot);
64
- * const table = base.createTable({
65
- * id: 'tasks',
66
- * name: 'Tasks',
67
- * primaryFieldName: 'Title',
68
- * });
69
- * const status = table.addField({
70
- * id: 'status',
71
- * name: 'Status',
72
- * type: 'singleSelect',
73
- * config: { options: [{ id: 'todo', name: 'Todo', color: 'blue' }] },
74
- * });
75
- * table.addRecord({
76
- * id: 'task-1',
77
- * values: { [table.getPrimaryFieldId()]: 'Review protocol', [status.getId()]: 'todo' },
78
- * });
79
- * await saveBaseSnapshotToServer(base.save());
80
- * ```
81
12
  */
82
13
  export declare class FBase {
83
14
  private readonly _base;
84
- private readonly _commandService;
85
- private readonly _projectionService;
86
- private readonly _permissionService;
87
- private readonly _undoRedoService?;
88
- private readonly _baseCommandService?;
89
- private readonly _univerInstanceService?;
90
- private readonly _transactionContext?;
91
- constructor(_base: BaseDataModel, _commandService: ICommandService, _projectionService: IBaseProjectionService, _permissionService: IBasePermissionService, _undoRedoService?: IUndoRedoService | undefined, _baseCommandService?: IBaseCommandService | undefined, _univerInstanceService?: IUniverInstanceService | undefined, _transactionContext?: BaseTransactionContext | undefined);
15
+ protected readonly _injector: Injector;
16
+ constructor(_base: BaseDataModel, _injector: Injector);
92
17
  /**
93
18
  * Get the underlying Base data model.
94
- * @returns The Base data model.
19
+ * @returns {BaseDataModel} The underlying Base data model.
95
20
  * @example
96
21
  * ```ts
97
- * const model = base.getBase();
98
- * ```
99
- *
100
- * @example Browser console
101
- * ```ts
102
- * console.log((() => {
103
- * const unitId = `facade_example_${Date.now()}`;
104
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
105
- * try {
106
- * return base.getBase().getUnitId();
107
- * } finally {
108
- * univerAPI.disposeUnit(unitId);
109
- * }
110
- * })());
22
+ * const fBase = univerAPI.getActiveBase();
23
+ * console.log(fBase.getBase());
111
24
  * ```
112
25
  */
113
26
  getBase(): BaseDataModel;
114
27
  /**
115
28
  * Get the Base unit id.
116
- * @returns The Base id.
29
+ * @returns {string} The Base unit id.
117
30
  * @example
118
31
  * ```ts
119
- * console.log(base.getId());
120
- * ```
121
- *
122
- * @example Browser console
123
- * ```ts
124
- * console.log((() => {
125
- * const unitId = `facade_example_${Date.now()}`;
126
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
127
- * try {
128
- * return base.getId();
129
- * } finally {
130
- * univerAPI.disposeUnit(unitId);
131
- * }
132
- * })());
32
+ * const fBase = univerAPI.getActiveBase();
33
+ * console.log(fBase.getId());
133
34
  * ```
134
35
  */
135
36
  getId(): string;
136
- /**
137
- * Get the Base name.
138
- * @returns The Base name.
139
- * @example
140
- * ```ts
141
- * console.log(base.getName());
142
- * ```
143
- *
144
- * @example Browser console
145
- * ```ts
146
- * console.log((() => {
147
- * const unitId = `facade_example_${Date.now()}`;
148
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
149
- * try {
150
- * return base.getName();
151
- * } finally {
152
- * univerAPI.disposeUnit(unitId);
153
- * }
154
- * })());
155
- * ```
156
- */
157
- getName(): string;
158
- /**
159
- * Get all non-deleted tables in this Base.
160
- * @returns Table facade objects ordered by the Base table order.
161
- * @example
162
- * ```ts
163
- * const tables = base.getTables();
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 base.getTables().map((table) => table.getName());
174
- * } finally {
175
- * univerAPI.disposeUnit(unitId);
176
- * }
177
- * })());
178
- * ```
179
- */
180
- getTables(): FTable[];
181
- /**
182
- * Get the current Base snapshot.
183
- *
184
- * The returned object is the persisted model shape. Use it for protocol
185
- * payloads, storage, and snapshot comparison. Use facade mutation methods
186
- * instead of mutating this object directly.
187
- *
188
- * @returns The current Base snapshot.
189
- * @example
190
- * ```ts
191
- * const snapshot = base.getSnapshot();
192
- * await request('/api/base/save', { method: 'POST', body: JSON.stringify(snapshot) });
193
- * ```
194
- *
195
- * @example Browser console
196
- * ```ts
197
- * console.log((() => {
198
- * const unitId = `facade_example_${Date.now()}`;
199
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
200
- * try {
201
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
202
- * return Object.keys(base.getSnapshot().tables);
203
- * } finally {
204
- * univerAPI.disposeUnit(unitId);
205
- * }
206
- * })());
207
- * ```
208
- */
209
- getSnapshot(): IBaseSnapshot;
210
37
  /**
211
38
  * Save and return the current complete Base snapshot.
212
39
  *
@@ -216,348 +43,174 @@ export declare class FBase {
216
43
  * decides how to persist it, for example by sending it to the server-side
217
44
  * protocol adapter.
218
45
  *
219
- * @returns The current complete Base snapshot.
46
+ * @returns {IBaseSnapshot} The current complete Base snapshot.
220
47
  * @example
221
48
  * ```ts
222
- * const base = univerAPI.getActiveBase();
223
- * if (!base) throw new Error('No active Base.');
224
- * const snapshot = base.save();
225
- * console.log(snapshot.tables, snapshot.tableOrder);
226
- * ```
227
- *
228
- * @example Browser console
229
- * ```ts
230
- * console.log((() => {
231
- * const unitId = `facade_example_${Date.now()}`;
232
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
233
- * try {
234
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
235
- * return { tables: Object.keys(base.save().tables), tableOrder: base.save().tableOrder };
236
- * } finally {
237
- * univerAPI.disposeUnit(unitId);
238
- * }
239
- * })());
49
+ * const fBase = univerAPI.getActiveBase();
50
+ * console.log(fBase.save());
240
51
  * ```
241
52
  */
242
53
  save(): IBaseSnapshot;
243
54
  /**
244
- * Set the Base name.
245
- * @param name The new Base name.
55
+ * Get the Base name.
56
+ * @returns {string} The Base name.
246
57
  * @example
247
58
  * ```ts
248
- * base.setName('Product Roadmap');
249
- * ```
250
- *
251
- * @example Browser console
252
- * ```ts
253
- * console.log((() => {
254
- * const unitId = `facade_example_${Date.now()}`;
255
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
256
- * try {
257
- * base.setName('Renamed Facade Example');
258
- * return base.getName();
259
- * } finally {
260
- * univerAPI.disposeUnit(unitId);
261
- * }
262
- * })());
59
+ * const fBase = univerAPI.getActiveBase();
60
+ * console.log(fBase.getName());
263
61
  * ```
264
62
  */
265
- setName(name: string): void;
63
+ getName(): string;
266
64
  /**
267
- * Get a table by id.
268
- * @param tableId The table id.
269
- * @returns The table facade, or null if the table does not exist.
65
+ * Set the Base name.
66
+ * @param {string} name The new Base name.
270
67
  * @example
271
68
  * ```ts
272
- * const table = base.getTable('table-1');
273
- * ```
274
- *
275
- * @example Browser console
276
- * ```ts
277
- * console.log((() => {
278
- * const unitId = `facade_example_${Date.now()}`;
279
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
280
- * try {
281
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
282
- * return base.getTable(table.getId())?.getName() ?? null;
283
- * } finally {
284
- * univerAPI.disposeUnit(unitId);
285
- * }
286
- * })());
69
+ * const fBase = univerAPI.getActiveBase();
70
+ * fBase.setName('Product Roadmap');
71
+ * console.log(fBase.getName());
287
72
  * ```
288
73
  */
289
- getTable(tableId: string): FTable | null;
74
+ setName(name: string): void;
290
75
  /**
291
- * Get a table by id.
292
- * @param tableId The table id.
293
- * @returns The table facade, or null if the table does not exist.
76
+ * Get all existing tables in this Base.
77
+ * @returns {FBaseTable[]} The table facade instances.
294
78
  * @example
295
79
  * ```ts
296
- * const table = base.getTableById('table-1');
297
- * ```
298
- *
299
- * @example Browser console
300
- * ```ts
301
- * console.log((() => {
302
- * const unitId = `facade_example_${Date.now()}`;
303
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
304
- * try {
305
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
306
- * return base.getTableById(table.getId())?.getName() ?? null;
307
- * } finally {
308
- * univerAPI.disposeUnit(unitId);
309
- * }
310
- * })());
80
+ * const fBase = univerAPI.getActiveBase();
81
+ * const fBaseTables = fBase.getTables();
82
+ * console.log(fBaseTables);
311
83
  * ```
312
84
  */
313
- getTableById(tableId: string): FTable | null;
85
+ getTables(): FBaseTable[];
314
86
  /**
315
- * Get the first table matching a table name.
316
- * @param name The table name.
317
- * @returns The table facade, or null if no table matches.
87
+ * Get a table by id.
88
+ * @param {string} tableId The table id.
89
+ * @returns {FBaseTable | null} The table facade, or null if the table does not exist.
318
90
  * @example
319
91
  * ```ts
320
- * const table = base.getTableByName('Tasks');
321
- * ```
322
- *
323
- * @example Browser console
324
- * ```ts
325
- * console.log((() => {
326
- * const unitId = `facade_example_${Date.now()}`;
327
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
328
- * try {
329
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
330
- * return base.getTableByName('Tasks')?.getId() ?? null;
331
- * } finally {
332
- * univerAPI.disposeUnit(unitId);
333
- * }
334
- * })());
92
+ * const fBase = univerAPI.getActiveBase();
93
+ * const fBaseTable = fBase.getTableById('table-1');
94
+ * console.log(fBaseTable);
335
95
  * ```
336
96
  */
337
- getTableByName(name: string): FTable | null;
97
+ getTableById(tableId: string): FBaseTable | null;
338
98
  /**
339
- * Create a table in this Base.
340
- *
341
- * The created table includes a primary text field. Provide `id` when the
342
- * server or fixture needs deterministic ids; otherwise a random table id is
343
- * generated.
344
- *
345
- * @param input Table creation options.
346
- * `input.name` is required. `input.primaryFieldName` names the generated
347
- * primary field. `input.index` inserts the table at a zero-based position in
348
- * the Base table order.
349
- * @returns The created table facade.
99
+ * Get a table by name.
100
+ * @param {string} tableName The table name.
101
+ * @returns {FBaseTable | null} The table facade, or null if the table does not exist.
350
102
  * @example
351
103
  * ```ts
352
- * const table = base.createTable({
353
- * id: 'tasks',
354
- * name: 'Tasks',
355
- * primaryFieldName: 'Title',
356
- * });
357
- * ```
358
- * @example Full table creation flow
359
- * ```ts
360
- * const table = base.createTable({ id: 'tasks', name: 'Tasks', primaryFieldName: 'Title' });
361
- * const status = table.addField({ id: 'status', name: 'Status', type: 'text', config: {} });
362
- * table.addRecord({
363
- * id: 'task-1',
364
- * values: { [table.getPrimaryFieldId()]: 'Ship beta', [status.getId()]: 'todo' },
365
- * });
366
- * console.log(base.save().tables.tasks.records['task-1']);
367
- * ```
368
- *
369
- * @example Browser console
370
- * ```ts
371
- * console.log((() => {
372
- * const unitId = `facade_example_${Date.now()}`;
373
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
374
- * try {
375
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
376
- * return { id: table.getId(), name: table.getName() };
377
- * } finally {
378
- * univerAPI.disposeUnit(unitId);
379
- * }
380
- * })());
104
+ * const fBase = univerAPI.getActiveBase();
105
+ * const fBaseTable = fBase.getTableByName('Tasks');
106
+ * console.log(fBaseTable);
381
107
  * ```
382
108
  */
383
- createTable(input: ICreateTableInput): FTable;
109
+ getTableByName(tableName: string): FBaseTable | null;
384
110
  /**
385
- * Insert a table in this Base.
386
- * @param input Table creation options. Use `index` to control the table order.
387
- * @returns The inserted table facade.
388
- * @example
389
- * ```ts
390
- * const table = base.insertTable({ name: 'Archive', index: 1 });
391
- * ```
111
+ * Insert a new table into the Base.
112
+ * @param {string} name The table name.
113
+ * @param {object} [options] Optional parameters for table creation.
114
+ * @param {number} [options.index] Optional insertion index in the Base table order.
115
+ * @param {string} [options.primaryFieldName] Optional name for the primary field of the new table.
116
+ * @param {Partial<ITableSnapshot>} [options.table] Optional partial table snapshot to override default values.
117
+ * @returns {FBaseTable} The newly created table facade.
392
118
  *
393
- * @example Browser console
394
- * ```ts
395
- * console.log((() => {
396
- * const unitId = `facade_example_${Date.now()}`;
397
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
398
- * try {
399
- * const inserted = base.insertTable({ id: `${unitId}_inserted`, name: 'Inserted', primaryFieldName: 'Title', index: 0 });
400
- * return base.getTables().map((table) => table.getId()).includes(inserted.getId());
401
- * } finally {
402
- * univerAPI.disposeUnit(unitId);
403
- * }
404
- * })());
405
- * ```
406
- */
407
- insertTable(input: ICreateTableInput): FTable;
408
- /**
409
- * Rename a table.
410
- * @param tableId The target table id.
411
- * @param name The new table name.
412
119
  * @example
413
120
  * ```ts
414
- * base.renameTable('tasks', 'Roadmap');
121
+ * const fBase = univerAPI.getActiveBase();
122
+ * const fBaseTable = fBase.insertTable('Tasks');
123
+ * console.log(fBaseTable);
415
124
  * ```
416
125
  *
417
- * @example Browser console
126
+ * @example Full table creation flow
418
127
  * ```ts
419
- * console.log((() => {
420
- * const unitId = `facade_example_${Date.now()}`;
421
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
422
- * try {
423
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
424
- * base.renameTable(table.getId(), 'Renamed Tasks');
425
- * return base.getTable(table.getId())?.getName();
426
- * } finally {
427
- * univerAPI.disposeUnit(unitId);
128
+ * const fBase = univerAPI.getActiveBase();
129
+ * const fBaseTable = fBase.insertTable(
130
+ * 'Tasks',
131
+ * {
132
+ * index: 0,
133
+ * primaryFieldName: 'Title'
428
134
  * }
429
- * })());
430
- * ```
431
- */
432
- renameTable(tableId: string, name: string): void;
433
- /**
434
- * Delete a table.
435
- * @param tableId The target table id.
436
- * @example
437
- * ```ts
438
- * base.deleteTable('archive');
439
- * ```
135
+ * );
440
136
  *
441
- * @example Browser console
442
- * ```ts
443
- * console.log((() => {
444
- * const unitId = `facade_example_${Date.now()}`;
445
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
446
- * try {
447
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
448
- * const tableId = table.getId();
449
- * base.deleteTable(tableId);
450
- * return base.getTable(tableId);
451
- * } finally {
452
- * univerAPI.disposeUnit(unitId);
137
+ * const field = fBaseTable.addField(
138
+ * 'Status',
139
+ * univerAPI.Enum.BaseFieldType.SingleSelect,
140
+ * {
141
+ * index: 1,
142
+ * field: {
143
+ * config: {
144
+ * options: [
145
+ * { id: 'todo', name: 'Todo', color: 'blue' },
146
+ * { id: 'done', name: 'Done', color: 'green' },
147
+ * ],
148
+ * }
149
+ * }
453
150
  * }
454
- * })());
455
- * ```
456
- */
457
- deleteTable(tableId: string): void;
458
- /**
459
- * Copy a table. By default this copies fields and views only.
151
+ * );
152
+ * const progress = fBaseTable.addField('Progress', univerAPI.Enum.BaseFieldType.Progress);
460
153
  *
461
- * This is useful for template flows. Pass `includeRecords: true` when the
462
- * copied table should also keep record ids, values, and resources from the
463
- * source table.
154
+ * const record = fBaseTable.addRecord(
155
+ * {
156
+ * Status: 'todo',
157
+ * Progress: 10
158
+ * },
159
+ * univerAPI.Enum.BaseFieldKeyEnum.Name
160
+ * );
464
161
  *
465
- * @param tableId Source table id.
466
- * @param input Optional copied table id, name, records mode, and insertion index. `id`
467
- * defaults to a generated table id, `name` defaults to
468
- * `"<source name> Copy"`, `includeRecords` defaults to false, and `index` controls table order.
469
- * @returns The copied table facade.
470
- * @example
471
- * ```ts
472
- * const copied = base.copyTable('tasks', { name: 'Tasks Template' });
473
- * ```
474
- *
475
- * @example Browser console
476
- * ```ts
477
- * console.log((() => {
478
- * const unitId = `facade_example_${Date.now()}`;
479
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
480
- * try {
481
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
482
- * const copy = base.copyTable(table.getId(), { id: `${unitId}_copy`, name: 'Tasks Copy', includeRecords: true });
483
- * return { source: table.getId(), copy: copy.getId() };
484
- * } finally {
485
- * univerAPI.disposeUnit(unitId);
486
- * }
487
- * })());
162
+ * console.log(fBaseTable.getTable());
488
163
  * ```
489
164
  */
490
- copyTable(tableId: string, input?: ICopyTableInput): FTable;
165
+ insertTable(name: string, options?: {
166
+ index?: number;
167
+ table?: Partial<Omit<ITableSnapshot, 'id'>>;
168
+ primaryFieldName?: string;
169
+ }): FBaseTable;
491
170
  /**
492
- * Run multiple facade operations in a callback.
493
- * @param fn A callback that receives this Base facade.
494
- * @returns The callback result.
171
+ * Delete a table from this Base.
172
+ * @param {FBaseTable | string} table The table facade instance or table id to delete.
173
+ * @returns {boolean} True if the table was deleted, false if it did not exist.
495
174
  * @example
496
175
  * ```ts
497
- * base.batch((tx) => {
498
- * tx.createTable({ name: 'Tasks' });
499
- * });
176
+ * const fBase = univerAPI.getActiveBase();
177
+ * const fBaseTable = fBase.getTables()[1];
178
+ * if (fBaseTable) {
179
+ * const result = fBase.deleteTable(fBaseTable);
180
+ * console.log(result);
181
+ * }
500
182
  * ```
501
183
  *
502
- * @example Browser console
184
+ * @example
503
185
  * ```ts
504
- * console.log((() => {
505
- * const unitId = `facade_example_${Date.now()}`;
506
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
507
- * try {
508
- * let tableId = '';
509
- * const result = base.batch((tx) => {
510
- * const table = tx.createTable({ id: `${unitId}_batch`, name: 'Batch Tasks', primaryFieldName: 'Title' });
511
- * tableId = table.getId();
512
- * return tx.getTable(tableId)?.getName();
513
- * });
514
- * return { result, existsAfterCommit: Boolean(base.getTable(tableId)) };
515
- * } finally {
516
- * univerAPI.disposeUnit(unitId);
517
- * }
518
- * })());
186
+ * const fBase = univerAPI.getActiveBase();
187
+ * const result = fBase.deleteTable('table-1');
188
+ * console.log(result);
519
189
  * ```
520
190
  */
521
- batch<T>(fn: (tx: FBase) => T): T;
191
+ deleteTable(table: FBaseTable | string): boolean;
522
192
  /**
523
- * Search records in a table.
524
- *
525
- * Search reads the current table snapshot. When `viewId` is provided, the
526
- * search space follows that view projection, including hidden fields and
527
- * projected row order.
193
+ * Duplicate a table in this Base.
194
+ * @param {FBaseTable | string} table The table facade instance or table id to duplicate.
195
+ * @param {object} [options] Optional parameters for table duplication.
196
+ * @param {boolean} [options.includeRecords] Whether to include records in the duplicated table.
197
+ * @param {boolean} [options.regenerateViewIds] Whether to regenerate view ids in the duplicated table.
198
+ * @returns {FBaseTable} The newly duplicated table facade.
528
199
  *
529
- * @param tableId The table id to search.
530
- * @param input Search options. `query` is trimmed and blank queries return
531
- * no matches. `viewId` searches in a view projection. `fieldIds` limits the
532
- * searched fields. `limit` caps the number of matches.
533
- * @returns Search result with the normalized query, total count, matched
534
- * records, and matched field/cell information.
535
200
  * @example
536
201
  * ```ts
537
- * const result = base.searchTable('tasks', {
538
- * query: 'release',
539
- * fieldIds: ['title', 'status'],
540
- * limit: 20,
541
- * });
542
- * ```
543
- *
544
- * @example Browser console
545
- * ```ts
546
- * console.log((() => {
547
- * const unitId = `facade_example_${Date.now()}`;
548
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
549
- * try {
550
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
551
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
552
- * const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
553
- * return base.searchTable(table.getId(), { query: 'Alpha', limit: 5 });
554
- * } finally {
555
- * univerAPI.disposeUnit(unitId);
556
- * }
557
- * })());
202
+ * const fBase = univerAPI.getActiveBase();
203
+ * const fBaseTable = fBase.getTables()[0];
204
+ * if (fBaseTable) {
205
+ * const fBaseTableCopy = fBase.duplicateTable(fBaseTable, { includeRecords: true });
206
+ * console.log(fBaseTableCopy);
207
+ * }
558
208
  * ```
559
209
  */
560
- searchTable(tableId: string, input: ISearchTableInput): IBaseTableSearchResult;
210
+ duplicateTable(table: FBaseTable | string, options?: {
211
+ includeRecords?: boolean;
212
+ regenerateViewIds?: boolean;
213
+ }): FBaseTable;
561
214
  /**
562
215
  * Get a compact schema snapshot for agent/tooling use.
563
216
  *
@@ -565,116 +218,12 @@ export declare class FBase {
565
218
  * server route, or prompt needs structure and ids without transferring the
566
219
  * full data payload.
567
220
  *
568
- * @returns The Base schema without row values.
221
+ * @returns {IBaseSchemaSnapshot} The compact Base schema snapshot.
569
222
  * @example
570
223
  * ```ts
571
- * console.log(base.getSchema().tables.map((table) => table.name));
572
- * ```
573
- *
574
- * @example Browser console
575
- * ```ts
576
- * console.log((() => {
577
- * const unitId = `facade_example_${Date.now()}`;
578
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
579
- * try {
580
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
581
- * return base.getSchema();
582
- * } finally {
583
- * univerAPI.disposeUnit(unitId);
584
- * }
585
- * })());
224
+ * const fBase = univerAPI.getActiveBase();
225
+ * console.log(fBase.getSchema());
586
226
  * ```
587
227
  */
588
228
  getSchema(): IBaseSchemaSnapshot;
589
- /**
590
- * Get the permission facade for this Base.
591
- *
592
- * Permission changes affect Base command permission checks and can be
593
- * hydrated from server-side authorization data.
594
- *
595
- * @returns The Base permission facade.
596
- * @example
597
- * ```ts
598
- * base.getPermission().setTablePermission('tasks', { createRecord: false });
599
- * ```
600
- *
601
- * @example Browser console
602
- * ```ts
603
- * console.log((() => {
604
- * const unitId = `facade_example_${Date.now()}`;
605
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
606
- * try {
607
- * const table = base.createTable({ id: `${unitId}_table`, name: 'Tasks', primaryFieldName: 'Title' });
608
- * const field = table.addField({ id: `${unitId}_status`, name: 'Status', type: 'singleSelect', config: { options: [{ id: 'todo', name: 'Todo' }, { id: 'done', name: 'Done' }] }, defaultValue: 'todo' });
609
- * const record = table.addRecord({ id: `${unitId}_record`, values: { [table.getPrimaryFieldId()]: 'Alpha', [field.getId()]: 'todo' } });
610
- * const view = table.createView({ id: `${unitId}_view`, name: 'Grid', type: 'grid' });
611
- * const permission = base.getPermission();
612
- * return permission.canCreateTable();
613
- * } finally {
614
- * univerAPI.disposeUnit(unitId);
615
- * }
616
- * })());
617
- * ```
618
- */
619
- getPermission(): FBasePermission;
620
- /**
621
- * Add a Base event listener.
622
- *
623
- * Events are derived from executed Base commands. They are useful for
624
- * server sync indicators, audit logs, demos, and agent tools that need to
625
- * observe facade writes.
626
- *
627
- * @param event Base event name. Use `BaseEventName.TableChanged`,
628
- * `FieldChanged`, `RecordChanged`, `CellValueChanged`, or `ViewChanged`.
629
- * @param listener Event callback. The payload shape depends on the event
630
- * name and includes ids, facade wrappers for live objects when available,
631
- * and the original command payload.
632
- * @returns A disposable listener handle.
633
- * @example
634
- * ```ts
635
- * const disposable = base.addEvent(BaseEventName.RecordChanged, (event) => {
636
- * console.log(event.type, event.recordIds);
637
- * });
638
- * table.addRecord({ values: { title: 'Observed row' } });
639
- * disposable.dispose();
640
- * ```
641
- *
642
- * @example Browser console
643
- * ```ts
644
- * console.log((() => {
645
- * const unitId = `facade_example_${Date.now()}`;
646
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
647
- * try {
648
- * const disposable = base.addEvent(univerAPI.Event.BaseTableChanged, (event) => console.log('Base table changed', event.tableId));
649
- * disposable.dispose();
650
- * return 'disposed';
651
- * } finally {
652
- * univerAPI.disposeUnit(unitId);
653
- * }
654
- * })());
655
- * ```
656
- */
657
- addEvent<T extends BaseEventName>(event: T, listener: (params: IBaseEventMap[T]) => void): IDisposable;
658
- /**
659
- *
660
- * @example Browser console
661
- * ```ts
662
- * console.log((() => {
663
- * const unitId = `facade_example_${Date.now()}`;
664
- * const base = univerAPI.createBase({ id: unitId, name: 'Facade Example', schemaVersion: 1, createdAt: Date.now(), updatedAt: Date.now(), tables: {}, tableOrder: [] }, { makeCurrent: false });
665
- * try {
666
- * return base.resolveCommandEvent(univerAPI.Event.BaseTableChanged, { id: 'unknown.command', params: {} });
667
- * } finally {
668
- * univerAPI.disposeUnit(unitId);
669
- * }
670
- * })());
671
- * ```
672
- */
673
- resolveCommandEvent<T extends BaseEventName>(event: T, commandInfo: Readonly<ICommandInfo>): IBaseEventMap[T] | null;
674
- private _wrapTable;
675
- private _resolveEvent;
676
229
  }
677
- export type CreateTableInput = ICreateTableInput;
678
- export type SearchTableInput = ISearchTableInput;
679
- export type CopyTableInput = ICopyTableInput;
680
- export type BaseSchemaSnapshot = IBaseSchemaSnapshot;