MCPcopy Create free account
hub / github.com/apitable/apitable / TableBundle

Class TableBundle

packages/core/src/tablebundle/table_bundle.ts:6–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4import { TableBundleSnapshot } from './table_bundle_snapshot';
5
6export class TableBundle {
7 public manifest: TableBundleManifest;
8 private _nodeMap: Map<string, TableBundleDataSheet>;
9 private _saver!: ITableBundleSaver;
10 private _loader!: ITableBundleLoader;
11 private constructor() {
12 this.manifest = new TableBundleManifest();
13 this._nodeMap = new Map<string, TableBundleDataSheet>();
14 }
15
16 public static new(options: ITableBundleInitOptions): TableBundle {
17 const { loader, saver } = options;
18 const tableBundle = new TableBundle();
19 tableBundle.setTableBundleSaver(saver);
20 tableBundle.setTableBundleLoader(loader);
21 return tableBundle;
22 }
23
24 setTableBundleSaver(provider: ITableBundleSaver): void {
25 this._saver = provider;
26 }
27
28 setTableBundleLoader(loader: ITableBundleLoader): void {
29 this._loader = loader;
30 }
31
32 public nodeMap(): Map<string, TableBundleDataSheet> {
33 return this._nodeMap;
34 }
35
36 public apply(sheet: TableBundleDataSheet, id: string = 'dst001', name: string = 'datasheet'): void {
37 this._nodeMap.set(id, sheet);
38 this.manifest.addDataSheetNode(id, name);
39 }
40
41 public getDataSheet(id: string): TableBundleDataSheet {
42 return <TableBundleDataSheet>this._nodeMap.get(id);
43 }
44
45 save(path: string) {
46 if (this._saver === undefined) {
47 return;
48 }
49 const sheetData = {};
50 this.nodeMap().forEach((value: TableBundleDataSheet, key: string) => {
51 sheetData[key + '.json'] = fflate.strToU8(JSON.stringify(value.snapshot));
52 if (value.extras !== undefined) {
53 sheetData[key + '.extras.json'] = fflate.strToU8(value.extras);
54 }
55 });
56 const zipped = fflate.zipSync({
57 data: sheetData,
58 'manifest.json': fflate.strToU8(JSON.stringify(this.manifest))
59 }, {
60 level: 1,
61 mtime: new Date()
62 });
63 this._saver.save(zipped, path);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected