@univerjs-pro/exchange-node 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +151 -3
- package/lib/cjs/index.cjs +156 -29
- package/lib/cjs/pdf.cjs +190 -0
- package/lib/es/index.js +1 -391
- package/lib/es/pdf.js +1 -0
- package/lib/shared/runtime.cjs +93 -0
- package/lib/types/index.d.ts +14 -249
- package/lib/types/pdf.d.ts +23 -0
- package/lib/types/types.d.ts +299 -0
- package/package.json +26 -6
package/lib/types/index.d.ts
CHANGED
|
@@ -1,256 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { IBaseSnapshot, IDocumentData, IWorkbookData, UniverInstanceType } from "@univerjs/core";
|
|
1
|
+
import { BaseAttachmentPolicy, BaseExportMode, BaseFormulaPolicy, BaseHeaderPolicy, BaseImagePolicy, BaseImportMode, BaseTypeInference, BufferImportOptions, ConversionDiagnosticOptions, CsvFormulaMode, CsvLineEnding, CsvQuoteStyle, CsvTypeInferenceMode, CsvValueMode, DocxCompatibilityMode, ExchangeDiagnostic, ExchangeError, ExchangeErrorCode, ExchangeExportOptionsMap, ExchangeFormat, ExchangeImportOptionsMap, ExchangeUnitDataMap, ExportOptions, ExportQuota, ExportUnitType, FormulaCalculationMode, IBaseExportMapping, IBaseExportOptions, IBaseFieldMapping, IBaseImportMapping, IBaseImportOptions, IBaseTableMapping, ICsvExportOptions, ICsvExportSelector, ICsvImportOptions, IDocExportOptions, IDocImportOptions, IExchangeConfig, IExportOptionsBase, IExportQuotaOptions, IGridImportOptions, IImportOptionsBase, ISheetExportOptions, ISheetImportOptions, ISlideExportOptions, ISlideImportOptions, ISnapshotWithBlocks, ImportOptions } from "./types.js";
|
|
3
2
|
import { Buffer } from "node:buffer";
|
|
4
|
-
import { ISheetBlock, ISnapshot } from "@univerjs/protocol";
|
|
5
|
-
//#region src/types.d.ts
|
|
6
|
-
declare enum ExchangeFormat {
|
|
7
|
-
XLS = "xls",
|
|
8
|
-
XLSX = "xlsx",
|
|
9
|
-
CSV = "csv",
|
|
10
|
-
TSV = "tsv",
|
|
11
|
-
DOC = "doc",
|
|
12
|
-
DOCX = "docx",
|
|
13
|
-
PPT = "ppt",
|
|
14
|
-
PPTX = "pptx"
|
|
15
|
-
}
|
|
16
|
-
declare enum FormulaCalculationMode {
|
|
17
|
-
FORCED = "forced",
|
|
18
|
-
WHEN_EMPTY = "when_empty",
|
|
19
|
-
NO = "no"
|
|
20
|
-
}
|
|
21
|
-
declare enum CsvTypeInferenceMode {
|
|
22
|
-
OFF = "off",
|
|
23
|
-
SAFE = "safe",
|
|
24
|
-
AGGRESSIVE = "aggressive"
|
|
25
|
-
}
|
|
26
|
-
declare enum CsvQuoteStyle {
|
|
27
|
-
MINIMAL = "minimal",
|
|
28
|
-
ALWAYS = "always"
|
|
29
|
-
}
|
|
30
|
-
declare enum CsvLineEnding {
|
|
31
|
-
LF = "lf",
|
|
32
|
-
CRLF = "cr_lf"
|
|
33
|
-
}
|
|
34
|
-
declare enum CsvValueMode {
|
|
35
|
-
DISPLAY = "display",
|
|
36
|
-
RAW = "raw"
|
|
37
|
-
}
|
|
38
|
-
declare enum CsvFormulaMode {
|
|
39
|
-
CACHED = "cached",
|
|
40
|
-
EXPRESSION = "expression"
|
|
41
|
-
}
|
|
42
|
-
declare enum BaseImportMode {
|
|
43
|
-
TABLES = "tables",
|
|
44
|
-
SHEETS = "sheets",
|
|
45
|
-
HYBRID = "hybrid",
|
|
46
|
-
AUTO = "auto"
|
|
47
|
-
}
|
|
48
|
-
declare enum BaseTypeInference {
|
|
49
|
-
NONE = "none",
|
|
50
|
-
SAFE = "safe",
|
|
51
|
-
AGGRESSIVE = "aggressive"
|
|
52
|
-
}
|
|
53
|
-
declare enum BaseFormulaPolicy {
|
|
54
|
-
VALUES = "values",
|
|
55
|
-
TEXT = "text",
|
|
56
|
-
FAIL = "fail",
|
|
57
|
-
CONVERT_THEN_VALUES = "convertThenValues"
|
|
58
|
-
}
|
|
59
|
-
declare enum BaseImagePolicy {
|
|
60
|
-
SAFE = "safe",
|
|
61
|
-
CELL_ONLY = "cell-only",
|
|
62
|
-
MEDIA_TABLE = "media-table",
|
|
63
|
-
NONE = "none"
|
|
64
|
-
}
|
|
65
|
-
declare enum BaseHeaderPolicy {
|
|
66
|
-
FIRST_ROW = "firstRow",
|
|
67
|
-
NONE = "none"
|
|
68
|
-
}
|
|
69
|
-
declare enum BaseExportMode {
|
|
70
|
-
TABLES = "tables",
|
|
71
|
-
RANGES = "ranges"
|
|
72
|
-
}
|
|
73
|
-
declare enum BaseAttachmentPolicy {
|
|
74
|
-
HYBRID = "hybrid",
|
|
75
|
-
MANIFEST = "manifest",
|
|
76
|
-
LINKS = "links",
|
|
77
|
-
NONE = "none"
|
|
78
|
-
}
|
|
79
|
-
declare enum DocxCompatibilityMode {
|
|
80
|
-
TRADITIONAL = "traditional",
|
|
81
|
-
MODERN = "modern"
|
|
82
|
-
}
|
|
83
|
-
interface IBaseFieldMapping {
|
|
84
|
-
name?: string;
|
|
85
|
-
type?: string;
|
|
86
|
-
config?: unknown;
|
|
87
|
-
formulaPolicy?: BaseFormulaPolicy;
|
|
88
|
-
}
|
|
89
|
-
interface IBaseTableMapping {
|
|
90
|
-
include?: boolean;
|
|
91
|
-
name?: string;
|
|
92
|
-
primaryField?: string;
|
|
93
|
-
header?: BaseHeaderPolicy;
|
|
94
|
-
formulaPolicy?: BaseFormulaPolicy;
|
|
95
|
-
fields?: Record<string, IBaseFieldMapping>;
|
|
96
|
-
}
|
|
97
|
-
interface IBaseImportMapping {
|
|
98
|
-
selectedOnly?: boolean;
|
|
99
|
-
tables?: Record<string, IBaseTableMapping>;
|
|
100
|
-
sheets?: Record<string, IBaseTableMapping>;
|
|
101
|
-
}
|
|
102
|
-
interface IBaseExportMapping {
|
|
103
|
-
tables?: Record<string, {
|
|
104
|
-
name?: string;
|
|
105
|
-
fields?: Record<string, {
|
|
106
|
-
name?: string;
|
|
107
|
-
}>;
|
|
108
|
-
}>;
|
|
109
|
-
}
|
|
110
|
-
interface ICsvImportOptions {
|
|
111
|
-
delimiter?: 'auto' | 'comma' | 'tab' | 'semicolon' | 'pipe' | 'space' | string;
|
|
112
|
-
quote?: 'auto' | 'none' | 'double' | 'single' | string;
|
|
113
|
-
encoding?: string;
|
|
114
|
-
inferTypes?: CsvTypeInferenceMode;
|
|
115
|
-
}
|
|
116
|
-
type ICsvExportSelector = {
|
|
117
|
-
worksheetId: string;
|
|
118
|
-
worksheetName?: never;
|
|
119
|
-
tableId?: never;
|
|
120
|
-
tableName?: never;
|
|
121
|
-
} | {
|
|
122
|
-
worksheetId?: never;
|
|
123
|
-
worksheetName: string;
|
|
124
|
-
tableId?: never;
|
|
125
|
-
tableName?: never;
|
|
126
|
-
} | {
|
|
127
|
-
worksheetId?: never;
|
|
128
|
-
worksheetName?: never;
|
|
129
|
-
tableId: string;
|
|
130
|
-
tableName?: never;
|
|
131
|
-
} | {
|
|
132
|
-
worksheetId?: never;
|
|
133
|
-
worksheetName?: never;
|
|
134
|
-
tableId?: never;
|
|
135
|
-
tableName: string;
|
|
136
|
-
};
|
|
137
|
-
type ICsvExportOptions = ICsvExportSelector & {
|
|
138
|
-
delimiter?: 'comma' | 'tab' | 'semicolon' | 'pipe' | 'space' | string;
|
|
139
|
-
quoteStyle?: CsvQuoteStyle;
|
|
140
|
-
lineEnding?: CsvLineEnding;
|
|
141
|
-
encoding?: string;
|
|
142
|
-
valueMode?: CsvValueMode;
|
|
143
|
-
formulaMode?: CsvFormulaMode;
|
|
144
|
-
};
|
|
145
|
-
interface IImportOptionsBase<TType extends UniverInstanceType, TFormat extends ExchangeFormat> {
|
|
146
|
-
type: TType;
|
|
147
|
-
format?: TFormat;
|
|
148
|
-
fileName?: string;
|
|
149
|
-
unitId?: string;
|
|
150
|
-
}
|
|
151
|
-
interface IGridImportOptions {
|
|
152
|
-
minSheetRowCount?: number;
|
|
153
|
-
minSheetColumnCount?: number;
|
|
154
|
-
}
|
|
155
|
-
type ISheetImportOptions = IGridImportOptions & ((IImportOptionsBase<UniverInstanceType.UNIVER_SHEET, ExchangeFormat.XLS> & {
|
|
156
|
-
csv?: never;
|
|
157
|
-
formulaCalculation?: never;
|
|
158
|
-
}) | (IImportOptionsBase<UniverInstanceType.UNIVER_SHEET, ExchangeFormat.XLSX> & {
|
|
159
|
-
csv?: never;
|
|
160
|
-
formulaCalculation?: FormulaCalculationMode;
|
|
161
|
-
}) | (IImportOptionsBase<UniverInstanceType.UNIVER_SHEET, ExchangeFormat.CSV | ExchangeFormat.TSV> & {
|
|
162
|
-
csv?: ICsvImportOptions;
|
|
163
|
-
formulaCalculation?: never;
|
|
164
|
-
}));
|
|
165
|
-
interface IBaseImportConfig extends IGridImportOptions {
|
|
166
|
-
mode?: BaseImportMode;
|
|
167
|
-
typeInference?: BaseTypeInference;
|
|
168
|
-
formulaPolicy?: BaseFormulaPolicy;
|
|
169
|
-
imagePolicy?: BaseImagePolicy;
|
|
170
|
-
maxCells?: number | null;
|
|
171
|
-
mapping?: IBaseImportMapping;
|
|
172
|
-
}
|
|
173
|
-
type IBaseImportOptions = IBaseImportConfig & ((IImportOptionsBase<UniverInstanceType.UNIVER_BASE, ExchangeFormat.XLS | ExchangeFormat.XLSX> & {
|
|
174
|
-
csv?: never;
|
|
175
|
-
}) | (IImportOptionsBase<UniverInstanceType.UNIVER_BASE, ExchangeFormat.CSV | ExchangeFormat.TSV> & {
|
|
176
|
-
csv?: ICsvImportOptions;
|
|
177
|
-
}));
|
|
178
|
-
interface IDocImportOptions extends IImportOptionsBase<UniverInstanceType.UNIVER_DOC, ExchangeFormat.DOC | ExchangeFormat.DOCX> {
|
|
179
|
-
compatibilityMode?: DocxCompatibilityMode;
|
|
180
|
-
}
|
|
181
|
-
interface ISlideImportOptions extends IImportOptionsBase<UniverInstanceType.UNIVER_SLIDE, ExchangeFormat.PPT | ExchangeFormat.PPTX> {}
|
|
182
|
-
type ImportOptions = ISheetImportOptions | IBaseImportOptions | IDocImportOptions | ISlideImportOptions;
|
|
183
|
-
type BufferImportOptions<T extends ImportOptions = ImportOptions> = T & {
|
|
184
|
-
fileName: string;
|
|
185
|
-
};
|
|
186
|
-
interface IExportOptionsBase<TType extends UniverInstanceType, TFormat extends ExchangeFormat> {
|
|
187
|
-
type: TType;
|
|
188
|
-
format: TFormat;
|
|
189
|
-
}
|
|
190
|
-
interface ISheetExportConfig {
|
|
191
|
-
/** @default FormulaCalculationMode.WHEN_EMPTY */
|
|
192
|
-
formulaCalculation?: FormulaCalculationMode;
|
|
193
|
-
}
|
|
194
|
-
type ISheetExportOptions = ISheetExportConfig & ((IExportOptionsBase<UniverInstanceType.UNIVER_SHEET, ExchangeFormat.XLSX> & {
|
|
195
|
-
csv?: never;
|
|
196
|
-
}) | (IExportOptionsBase<UniverInstanceType.UNIVER_SHEET, ExchangeFormat.CSV | ExchangeFormat.TSV> & {
|
|
197
|
-
csv: ICsvExportOptions;
|
|
198
|
-
}));
|
|
199
|
-
interface IBaseXlsxExportConfig {
|
|
200
|
-
mode?: BaseExportMode;
|
|
201
|
-
formulaPolicy?: BaseFormulaPolicy;
|
|
202
|
-
attachmentPolicy?: BaseAttachmentPolicy;
|
|
203
|
-
mapping?: IBaseExportMapping;
|
|
204
|
-
}
|
|
205
|
-
type IBaseExportOptions = (IExportOptionsBase<UniverInstanceType.UNIVER_BASE, ExchangeFormat.XLSX> & IBaseXlsxExportConfig & {
|
|
206
|
-
csv?: never;
|
|
207
|
-
}) | (IExportOptionsBase<UniverInstanceType.UNIVER_BASE, ExchangeFormat.CSV | ExchangeFormat.TSV> & {
|
|
208
|
-
csv: ICsvExportOptions;
|
|
209
|
-
});
|
|
210
|
-
interface IDocExportOptions extends IExportOptionsBase<UniverInstanceType.UNIVER_DOC, ExchangeFormat.DOCX> {}
|
|
211
|
-
interface ISlideExportOptions extends IExportOptionsBase<UniverInstanceType.UNIVER_SLIDE, ExchangeFormat.PPTX> {}
|
|
212
|
-
type ExportOptions = ISheetExportOptions | IBaseExportOptions | IDocExportOptions | ISlideExportOptions;
|
|
213
|
-
interface ISnapshotWithBlocks {
|
|
214
|
-
snapshot: ISnapshot;
|
|
215
|
-
sheetBlocks: ISheetBlock[];
|
|
216
|
-
}
|
|
217
|
-
declare enum ExchangeErrorCode {
|
|
218
|
-
INVALID_ARGUMENT = "INVALID_ARGUMENT",
|
|
219
|
-
UNSUPPORTED_FORMAT = "UNSUPPORTED_FORMAT",
|
|
220
|
-
INVALID_FILE = "INVALID_FILE",
|
|
221
|
-
INCOMPLETE_SNAPSHOT = "INCOMPLETE_SNAPSHOT",
|
|
222
|
-
IO_ERROR = "IO_ERROR",
|
|
223
|
-
NATIVE_LOAD_FAILED = "NATIVE_LOAD_FAILED",
|
|
224
|
-
CONVERSION_FAILED = "CONVERSION_FAILED"
|
|
225
|
-
}
|
|
226
|
-
declare class ExchangeError extends Error {
|
|
227
|
-
readonly code: ExchangeErrorCode;
|
|
228
|
-
readonly name = "ExchangeError";
|
|
229
|
-
constructor(code: ExchangeErrorCode, message: string, options?: {
|
|
230
|
-
cause?: unknown;
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
//#endregion
|
|
234
3
|
//#region src/index.d.ts
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
declare function
|
|
241
|
-
|
|
242
|
-
declare function
|
|
4
|
+
type ImportResult<T extends ImportOptions> = ExchangeUnitDataMap[T['type']];
|
|
5
|
+
/**
|
|
6
|
+
* Configure authorization in this JS context. Each Worker configures itself.
|
|
7
|
+
* Pass {} to select Free. Await before starting exports with the new credentials.
|
|
8
|
+
*/
|
|
9
|
+
declare function configureExchange(config: IExchangeConfig): Promise<void>;
|
|
10
|
+
/** Query shared quota without consuming/reserving it or checking export eligibility. */
|
|
11
|
+
declare function getExportQuota(options?: IExportQuotaOptions): Promise<ExportQuota>;
|
|
12
|
+
declare function importFile<T extends ImportOptions>(path: string, options: T): Promise<ImportResult<T>>;
|
|
13
|
+
declare function importBuffer<T extends ImportOptions>(input: Buffer, options: BufferImportOptions<T>): Promise<ImportResult<T>>;
|
|
243
14
|
declare function importFileToSnapshot(path: string, options: ImportOptions): Promise<ISnapshotWithBlocks>;
|
|
244
15
|
declare function importBufferToSnapshot<T extends ImportOptions>(input: Buffer, options: BufferImportOptions<T>): Promise<ISnapshotWithBlocks>;
|
|
245
|
-
declare function exportToBuffer(data:
|
|
246
|
-
declare function
|
|
247
|
-
declare function exportToBuffer(data: IDocumentData, options: IDocExportOptions): Promise<Buffer>;
|
|
248
|
-
declare function exportToBuffer(data: ISlideData, options: ISlideExportOptions): Promise<Buffer>;
|
|
249
|
-
declare function exportToFile(data: IWorkbookData, path: string, options: ISheetExportOptions): Promise<void>;
|
|
250
|
-
declare function exportToFile(data: IBaseSnapshot, path: string, options: IBaseExportOptions): Promise<void>;
|
|
251
|
-
declare function exportToFile(data: IDocumentData, path: string, options: IDocExportOptions): Promise<void>;
|
|
252
|
-
declare function exportToFile(data: ISlideData, path: string, options: ISlideExportOptions): Promise<void>;
|
|
16
|
+
declare function exportToBuffer<T extends ExportOptions>(data: NoInfer<ExchangeUnitDataMap[T['type']]>, options: T): Promise<Buffer>;
|
|
17
|
+
declare function exportToFile<T extends ExportOptions>(data: NoInfer<ExchangeUnitDataMap[T['type']]>, path: string, options: T): Promise<void>;
|
|
253
18
|
declare function exportSnapshotToBuffer(snapshot: ISnapshotWithBlocks, options: ExportOptions): Promise<Buffer>;
|
|
254
19
|
declare function exportSnapshotToFile(snapshot: ISnapshotWithBlocks, path: string, options: ExportOptions): Promise<void>;
|
|
255
20
|
//#endregion
|
|
256
|
-
export { BaseAttachmentPolicy, BaseExportMode, BaseFormulaPolicy, BaseHeaderPolicy, BaseImagePolicy, BaseImportMode, BaseTypeInference, BufferImportOptions, CsvFormulaMode, CsvLineEnding, CsvQuoteStyle, CsvTypeInferenceMode, CsvValueMode, DocxCompatibilityMode, ExchangeError, ExchangeErrorCode, ExchangeFormat, ExportOptions, FormulaCalculationMode, IBaseExportMapping, IBaseExportOptions, IBaseFieldMapping, IBaseImportMapping, IBaseImportOptions, IBaseTableMapping, ICsvExportOptions, ICsvExportSelector, ICsvImportOptions, IDocExportOptions, IDocImportOptions, IExportOptionsBase, IGridImportOptions, IImportOptionsBase, ISheetExportOptions, ISheetImportOptions, ISlideExportOptions, ISlideImportOptions, ISnapshotWithBlocks, ImportOptions, exportSnapshotToBuffer, exportSnapshotToFile, exportToBuffer, exportToFile, importBuffer, importBufferToSnapshot, importFile, importFileToSnapshot };
|
|
21
|
+
export { BaseAttachmentPolicy, BaseExportMode, BaseFormulaPolicy, BaseHeaderPolicy, BaseImagePolicy, BaseImportMode, BaseTypeInference, BufferImportOptions, ConversionDiagnosticOptions, CsvFormulaMode, CsvLineEnding, CsvQuoteStyle, CsvTypeInferenceMode, CsvValueMode, DocxCompatibilityMode, ExchangeDiagnostic, ExchangeError, ExchangeErrorCode, ExchangeExportOptionsMap, ExchangeFormat, ExchangeImportOptionsMap, ExchangeUnitDataMap, ExportOptions, ExportQuota, ExportUnitType, FormulaCalculationMode, IBaseExportMapping, IBaseExportOptions, IBaseFieldMapping, IBaseImportMapping, IBaseImportOptions, IBaseTableMapping, ICsvExportOptions, ICsvExportSelector, ICsvImportOptions, IDocExportOptions, IDocImportOptions, IExchangeConfig, IExportOptionsBase, IExportQuotaOptions, IGridImportOptions, IImportOptionsBase, ISheetExportOptions, ISheetImportOptions, ISlideExportOptions, ISlideImportOptions, ISnapshotWithBlocks, ImportOptions, configureExchange, exportSnapshotToBuffer, exportSnapshotToFile, exportToBuffer, exportToFile, getExportQuota, importBuffer, importBufferToSnapshot, importFile, importFileToSnapshot };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ExchangeFormat, IExportOptionsBase, IImportOptionsBase } from "./types.js";
|
|
2
|
+
import "./index.js";
|
|
3
|
+
import { UniverInstanceType } from "@univerjs/core";
|
|
4
|
+
import { IPdfUnitData } from "@univerjs-pro/pdfs";
|
|
5
|
+
//#region src/pdf.d.ts
|
|
6
|
+
interface IPdfImportOptions extends IImportOptionsBase<UniverInstanceType.UNIVER_PDF, ExchangeFormat.PDF> {}
|
|
7
|
+
interface IPdfExportOptions extends IExportOptionsBase<UniverInstanceType.UNIVER_PDF, ExchangeFormat.PDF> {
|
|
8
|
+
/** Missing or undecodable required images fail by default. False explicitly permits their omission. */
|
|
9
|
+
strictResources?: boolean;
|
|
10
|
+
}
|
|
11
|
+
declare module './types.js' {
|
|
12
|
+
interface ExchangeImportOptionsMap {
|
|
13
|
+
[UniverInstanceType.UNIVER_PDF]: IPdfImportOptions;
|
|
14
|
+
}
|
|
15
|
+
interface ExchangeExportOptionsMap {
|
|
16
|
+
[UniverInstanceType.UNIVER_PDF]: IPdfExportOptions;
|
|
17
|
+
}
|
|
18
|
+
interface ExchangeUnitDataMap {
|
|
19
|
+
[UniverInstanceType.UNIVER_PDF]: IPdfUnitData;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { IPdfExportOptions, IPdfImportOptions };
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { IBaseSnapshot, IDocumentData, IWorkbookData, UniverInstanceType } from "@univerjs/core";
|
|
2
|
+
import { ISlideData } from "@univerjs-pro/slides";
|
|
3
|
+
import { ISheetBlock, ISnapshot } from "@univerjs/protocol";
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
declare enum ExchangeFormat {
|
|
6
|
+
XLS = "xls",
|
|
7
|
+
XLSX = "xlsx",
|
|
8
|
+
CSV = "csv",
|
|
9
|
+
TSV = "tsv",
|
|
10
|
+
DOC = "doc",
|
|
11
|
+
DOCX = "docx",
|
|
12
|
+
PPT = "ppt",
|
|
13
|
+
PPTX = "pptx",
|
|
14
|
+
PDF = "pdf"
|
|
15
|
+
}
|
|
16
|
+
declare enum FormulaCalculationMode {
|
|
17
|
+
FORCED = "forced",
|
|
18
|
+
WHEN_EMPTY = "when_empty",
|
|
19
|
+
NO = "no"
|
|
20
|
+
}
|
|
21
|
+
declare enum CsvTypeInferenceMode {
|
|
22
|
+
OFF = "off",
|
|
23
|
+
SAFE = "safe",
|
|
24
|
+
AGGRESSIVE = "aggressive"
|
|
25
|
+
}
|
|
26
|
+
declare enum CsvQuoteStyle {
|
|
27
|
+
MINIMAL = "minimal",
|
|
28
|
+
ALWAYS = "always"
|
|
29
|
+
}
|
|
30
|
+
declare enum CsvLineEnding {
|
|
31
|
+
LF = "lf",
|
|
32
|
+
CRLF = "cr_lf"
|
|
33
|
+
}
|
|
34
|
+
declare enum CsvValueMode {
|
|
35
|
+
DISPLAY = "display",
|
|
36
|
+
RAW = "raw"
|
|
37
|
+
}
|
|
38
|
+
declare enum CsvFormulaMode {
|
|
39
|
+
CACHED = "cached",
|
|
40
|
+
EXPRESSION = "expression"
|
|
41
|
+
}
|
|
42
|
+
declare enum BaseImportMode {
|
|
43
|
+
TABLES = "tables",
|
|
44
|
+
SHEETS = "sheets",
|
|
45
|
+
HYBRID = "hybrid",
|
|
46
|
+
AUTO = "auto"
|
|
47
|
+
}
|
|
48
|
+
declare enum BaseTypeInference {
|
|
49
|
+
NONE = "none",
|
|
50
|
+
SAFE = "safe",
|
|
51
|
+
AGGRESSIVE = "aggressive"
|
|
52
|
+
}
|
|
53
|
+
declare enum BaseFormulaPolicy {
|
|
54
|
+
VALUES = "values",
|
|
55
|
+
TEXT = "text",
|
|
56
|
+
FAIL = "fail",
|
|
57
|
+
CONVERT_THEN_VALUES = "convertThenValues"
|
|
58
|
+
}
|
|
59
|
+
declare enum BaseImagePolicy {
|
|
60
|
+
SAFE = "safe",
|
|
61
|
+
CELL_ONLY = "cell-only",
|
|
62
|
+
MEDIA_TABLE = "media-table",
|
|
63
|
+
NONE = "none"
|
|
64
|
+
}
|
|
65
|
+
declare enum BaseHeaderPolicy {
|
|
66
|
+
FIRST_ROW = "firstRow",
|
|
67
|
+
NONE = "none"
|
|
68
|
+
}
|
|
69
|
+
declare enum BaseExportMode {
|
|
70
|
+
TABLES = "tables",
|
|
71
|
+
RANGES = "ranges"
|
|
72
|
+
}
|
|
73
|
+
declare enum BaseAttachmentPolicy {
|
|
74
|
+
HYBRID = "hybrid",
|
|
75
|
+
MANIFEST = "manifest",
|
|
76
|
+
LINKS = "links",
|
|
77
|
+
NONE = "none"
|
|
78
|
+
}
|
|
79
|
+
declare enum DocxCompatibilityMode {
|
|
80
|
+
TRADITIONAL = "traditional",
|
|
81
|
+
MODERN = "modern"
|
|
82
|
+
}
|
|
83
|
+
interface IBaseFieldMapping {
|
|
84
|
+
name?: string;
|
|
85
|
+
type?: string;
|
|
86
|
+
config?: unknown;
|
|
87
|
+
formulaPolicy?: BaseFormulaPolicy;
|
|
88
|
+
}
|
|
89
|
+
interface IBaseTableMapping {
|
|
90
|
+
include?: boolean;
|
|
91
|
+
name?: string;
|
|
92
|
+
primaryField?: string;
|
|
93
|
+
header?: BaseHeaderPolicy;
|
|
94
|
+
formulaPolicy?: BaseFormulaPolicy;
|
|
95
|
+
fields?: Record<string, IBaseFieldMapping>;
|
|
96
|
+
}
|
|
97
|
+
interface IBaseImportMapping {
|
|
98
|
+
selectedOnly?: boolean;
|
|
99
|
+
tables?: Record<string, IBaseTableMapping>;
|
|
100
|
+
sheets?: Record<string, IBaseTableMapping>;
|
|
101
|
+
}
|
|
102
|
+
interface IBaseExportMapping {
|
|
103
|
+
tables?: Record<string, {
|
|
104
|
+
name?: string;
|
|
105
|
+
fields?: Record<string, {
|
|
106
|
+
name?: string;
|
|
107
|
+
}>;
|
|
108
|
+
}>;
|
|
109
|
+
}
|
|
110
|
+
interface ICsvImportOptions {
|
|
111
|
+
delimiter?: 'auto' | 'comma' | 'tab' | 'semicolon' | 'pipe' | 'space' | string;
|
|
112
|
+
quote?: 'auto' | 'none' | 'double' | 'single' | string;
|
|
113
|
+
encoding?: string;
|
|
114
|
+
inferTypes?: CsvTypeInferenceMode;
|
|
115
|
+
}
|
|
116
|
+
type ICsvExportSelector = {
|
|
117
|
+
worksheetId: string;
|
|
118
|
+
worksheetName?: never;
|
|
119
|
+
tableId?: never;
|
|
120
|
+
tableName?: never;
|
|
121
|
+
} | {
|
|
122
|
+
worksheetId?: never;
|
|
123
|
+
worksheetName: string;
|
|
124
|
+
tableId?: never;
|
|
125
|
+
tableName?: never;
|
|
126
|
+
} | {
|
|
127
|
+
worksheetId?: never;
|
|
128
|
+
worksheetName?: never;
|
|
129
|
+
tableId: string;
|
|
130
|
+
tableName?: never;
|
|
131
|
+
} | {
|
|
132
|
+
worksheetId?: never;
|
|
133
|
+
worksheetName?: never;
|
|
134
|
+
tableId?: never;
|
|
135
|
+
tableName: string;
|
|
136
|
+
};
|
|
137
|
+
type ICsvExportOptions = ICsvExportSelector & {
|
|
138
|
+
delimiter?: 'comma' | 'tab' | 'semicolon' | 'pipe' | 'space' | string;
|
|
139
|
+
quoteStyle?: CsvQuoteStyle;
|
|
140
|
+
lineEnding?: CsvLineEnding;
|
|
141
|
+
encoding?: string;
|
|
142
|
+
valueMode?: CsvValueMode;
|
|
143
|
+
formulaMode?: CsvFormulaMode;
|
|
144
|
+
};
|
|
145
|
+
interface ExchangeDiagnostic {
|
|
146
|
+
code: string;
|
|
147
|
+
message: string;
|
|
148
|
+
details: Record<string, unknown>;
|
|
149
|
+
}
|
|
150
|
+
interface ConversionDiagnosticOptions {
|
|
151
|
+
onDiagnostics?: (items: readonly ExchangeDiagnostic[]) => void | Promise<void>;
|
|
152
|
+
}
|
|
153
|
+
interface IImportOptionsBase<TType extends UniverInstanceType, TFormat extends ExchangeFormat> extends ConversionDiagnosticOptions {
|
|
154
|
+
type: TType;
|
|
155
|
+
format?: TFormat;
|
|
156
|
+
fileName?: string;
|
|
157
|
+
unitId?: string;
|
|
158
|
+
}
|
|
159
|
+
interface IGridImportOptions {
|
|
160
|
+
minSheetRowCount?: number;
|
|
161
|
+
minSheetColumnCount?: number;
|
|
162
|
+
}
|
|
163
|
+
type ISheetImportOptions = IGridImportOptions & ((IImportOptionsBase<UniverInstanceType.UNIVER_SHEET, ExchangeFormat.XLS> & {
|
|
164
|
+
csv?: never;
|
|
165
|
+
formulaCalculation?: never;
|
|
166
|
+
}) | (IImportOptionsBase<UniverInstanceType.UNIVER_SHEET, ExchangeFormat.XLSX> & {
|
|
167
|
+
csv?: never;
|
|
168
|
+
formulaCalculation?: FormulaCalculationMode;
|
|
169
|
+
}) | (IImportOptionsBase<UniverInstanceType.UNIVER_SHEET, ExchangeFormat.CSV | ExchangeFormat.TSV> & {
|
|
170
|
+
csv?: ICsvImportOptions;
|
|
171
|
+
formulaCalculation?: never;
|
|
172
|
+
}));
|
|
173
|
+
interface IBaseImportConfig extends IGridImportOptions {
|
|
174
|
+
mode?: BaseImportMode;
|
|
175
|
+
typeInference?: BaseTypeInference;
|
|
176
|
+
formulaPolicy?: BaseFormulaPolicy;
|
|
177
|
+
imagePolicy?: BaseImagePolicy;
|
|
178
|
+
maxCells?: number | null;
|
|
179
|
+
mapping?: IBaseImportMapping;
|
|
180
|
+
}
|
|
181
|
+
type IBaseImportOptions = IBaseImportConfig & ((IImportOptionsBase<UniverInstanceType.UNIVER_BASE, ExchangeFormat.XLS | ExchangeFormat.XLSX> & {
|
|
182
|
+
csv?: never;
|
|
183
|
+
}) | (IImportOptionsBase<UniverInstanceType.UNIVER_BASE, ExchangeFormat.CSV | ExchangeFormat.TSV> & {
|
|
184
|
+
csv?: ICsvImportOptions;
|
|
185
|
+
}));
|
|
186
|
+
interface IDocImportOptions extends IImportOptionsBase<UniverInstanceType.UNIVER_DOC, ExchangeFormat.DOC | ExchangeFormat.DOCX> {
|
|
187
|
+
compatibilityMode?: DocxCompatibilityMode;
|
|
188
|
+
}
|
|
189
|
+
interface ISlideImportOptions extends IImportOptionsBase<UniverInstanceType.UNIVER_SLIDE, ExchangeFormat.PPT | ExchangeFormat.PPTX> {}
|
|
190
|
+
/** Capability maps are extended by optional format entries such as /pdf. */
|
|
191
|
+
interface ExchangeImportOptionsMap {
|
|
192
|
+
[UniverInstanceType.UNIVER_SHEET]: ISheetImportOptions;
|
|
193
|
+
[UniverInstanceType.UNIVER_BASE]: IBaseImportOptions;
|
|
194
|
+
[UniverInstanceType.UNIVER_DOC]: IDocImportOptions;
|
|
195
|
+
[UniverInstanceType.UNIVER_SLIDE]: ISlideImportOptions;
|
|
196
|
+
}
|
|
197
|
+
interface ExchangeUnitDataMap {
|
|
198
|
+
[UniverInstanceType.UNIVER_SHEET]: IWorkbookData;
|
|
199
|
+
[UniverInstanceType.UNIVER_BASE]: IBaseSnapshot;
|
|
200
|
+
[UniverInstanceType.UNIVER_DOC]: IDocumentData;
|
|
201
|
+
[UniverInstanceType.UNIVER_SLIDE]: ISlideData;
|
|
202
|
+
}
|
|
203
|
+
type ImportOptions = ExchangeImportOptionsMap[keyof ExchangeImportOptionsMap];
|
|
204
|
+
type BufferImportOptions<T extends ImportOptions = ImportOptions> = T & {
|
|
205
|
+
fileName: string;
|
|
206
|
+
};
|
|
207
|
+
interface IExportOptionsBase<TType extends UniverInstanceType, TFormat extends ExchangeFormat> extends ConversionDiagnosticOptions, IExchangeConfig {
|
|
208
|
+
type: TType;
|
|
209
|
+
format: TFormat;
|
|
210
|
+
}
|
|
211
|
+
interface ISheetExportConfig {
|
|
212
|
+
/** @default FormulaCalculationMode.WHEN_EMPTY */
|
|
213
|
+
formulaCalculation?: FormulaCalculationMode;
|
|
214
|
+
}
|
|
215
|
+
type ISheetExportOptions = ISheetExportConfig & ((IExportOptionsBase<UniverInstanceType.UNIVER_SHEET, ExchangeFormat.XLSX> & {
|
|
216
|
+
csv?: never;
|
|
217
|
+
}) | (IExportOptionsBase<UniverInstanceType.UNIVER_SHEET, ExchangeFormat.CSV | ExchangeFormat.TSV> & {
|
|
218
|
+
csv: ICsvExportOptions;
|
|
219
|
+
}));
|
|
220
|
+
interface IBaseXlsxExportConfig {
|
|
221
|
+
mode?: BaseExportMode;
|
|
222
|
+
formulaPolicy?: BaseFormulaPolicy;
|
|
223
|
+
attachmentPolicy?: BaseAttachmentPolicy;
|
|
224
|
+
mapping?: IBaseExportMapping;
|
|
225
|
+
}
|
|
226
|
+
type IBaseExportOptions = (IExportOptionsBase<UniverInstanceType.UNIVER_BASE, ExchangeFormat.XLSX> & IBaseXlsxExportConfig & {
|
|
227
|
+
csv?: never;
|
|
228
|
+
}) | (IExportOptionsBase<UniverInstanceType.UNIVER_BASE, ExchangeFormat.CSV | ExchangeFormat.TSV> & {
|
|
229
|
+
csv: ICsvExportOptions;
|
|
230
|
+
});
|
|
231
|
+
interface IDocExportOptions extends IExportOptionsBase<UniverInstanceType.UNIVER_DOC, ExchangeFormat.DOCX> {}
|
|
232
|
+
interface ISlideExportOptions extends IExportOptionsBase<UniverInstanceType.UNIVER_SLIDE, ExchangeFormat.PPTX> {}
|
|
233
|
+
interface ExchangeExportOptionsMap {
|
|
234
|
+
[UniverInstanceType.UNIVER_SHEET]: ISheetExportOptions;
|
|
235
|
+
[UniverInstanceType.UNIVER_BASE]: IBaseExportOptions;
|
|
236
|
+
[UniverInstanceType.UNIVER_DOC]: IDocExportOptions;
|
|
237
|
+
[UniverInstanceType.UNIVER_SLIDE]: ISlideExportOptions;
|
|
238
|
+
}
|
|
239
|
+
type ExportOptions = ExchangeExportOptionsMap[keyof ExchangeExportOptionsMap];
|
|
240
|
+
interface ISnapshotWithBlocks {
|
|
241
|
+
snapshot: ISnapshot;
|
|
242
|
+
sheetBlocks: ISheetBlock[];
|
|
243
|
+
}
|
|
244
|
+
declare enum ExchangeErrorCode {
|
|
245
|
+
INVALID_ARGUMENT = "INVALID_ARGUMENT",
|
|
246
|
+
UNSUPPORTED_FORMAT = "UNSUPPORTED_FORMAT",
|
|
247
|
+
INVALID_FILE = "INVALID_FILE",
|
|
248
|
+
INCOMPLETE_SNAPSHOT = "INCOMPLETE_SNAPSHOT",
|
|
249
|
+
IO_ERROR = "IO_ERROR",
|
|
250
|
+
NATIVE_LOAD_FAILED = "NATIVE_LOAD_FAILED",
|
|
251
|
+
CONVERSION_FAILED = "CONVERSION_FAILED",
|
|
252
|
+
LICENSE_EXPORT_QUOTA_EXCEEDED = "LICENSE_EXPORT_QUOTA_EXCEEDED",
|
|
253
|
+
LICENSE_INVALID = "LICENSE_INVALID",
|
|
254
|
+
LICENSE_POLICY_INVALID = "LICENSE_POLICY_INVALID",
|
|
255
|
+
LICENSE_NOT_YET_EFFECTIVE = "LICENSE_NOT_YET_EFFECTIVE",
|
|
256
|
+
LICENSE_UNIT_TYPE_REJECTED = "LICENSE_UNIT_TYPE_REJECTED",
|
|
257
|
+
LICENSE_VERSION_NOT_ALLOWED = "LICENSE_VERSION_NOT_ALLOWED",
|
|
258
|
+
LICENSE_CONCURRENCY_TIMEOUT = "LICENSE_CONCURRENCY_TIMEOUT",
|
|
259
|
+
LICENSE_USAGE_STATE_INVALID = "LICENSE_USAGE_STATE_INVALID",
|
|
260
|
+
LICENSE_USAGE_STORAGE_ERROR = "LICENSE_USAGE_STORAGE_ERROR"
|
|
261
|
+
}
|
|
262
|
+
declare class ExchangeError extends Error {
|
|
263
|
+
readonly code: ExchangeErrorCode;
|
|
264
|
+
readonly name = "ExchangeError";
|
|
265
|
+
constructor(code: ExchangeErrorCode, message: string, options?: {
|
|
266
|
+
cause?: unknown;
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Complete authorization credentials. configureExchange sets defaults for this JS context;
|
|
271
|
+
* export and quota-query options override them for that operation only.
|
|
272
|
+
* Provide both credentials together. configureExchange({}) explicitly selects Free.
|
|
273
|
+
*/
|
|
274
|
+
interface IExchangeConfig {
|
|
275
|
+
license?: string;
|
|
276
|
+
licenseKey?: string;
|
|
277
|
+
}
|
|
278
|
+
/** Per-call credentials override defaults only for this export or quota query.
|
|
279
|
+
* Supply the complete pair; omitting both uses the configured or environment credentials.
|
|
280
|
+
*/
|
|
281
|
+
type IExportQuotaOptions = IExchangeConfig;
|
|
282
|
+
type ExportUnitType = 'sheet' | 'doc' | 'slide' | 'base' | 'pdf';
|
|
283
|
+
/** Shared quota snapshot, not export permission. Querying neither reserves nor consumes quota.
|
|
284
|
+
* Version, activation and unit-type restrictions are enforced only during export.
|
|
285
|
+
* Before activation, a limited quota describes the first period (periodStart is in the future).
|
|
286
|
+
*/
|
|
287
|
+
interface ExportQuota {
|
|
288
|
+
licenseStatus: 'not_configured' | 'expired' | 'valid';
|
|
289
|
+
expiresAt: string | null;
|
|
290
|
+
observedAt: string;
|
|
291
|
+
limit: number | null;
|
|
292
|
+
used: number | null;
|
|
293
|
+
reserved: number | null;
|
|
294
|
+
remaining: number | null;
|
|
295
|
+
periodStart: string | null;
|
|
296
|
+
periodEnd: string | null;
|
|
297
|
+
}
|
|
298
|
+
//#endregion
|
|
299
|
+
export { BaseAttachmentPolicy, BaseExportMode, BaseFormulaPolicy, BaseHeaderPolicy, BaseImagePolicy, BaseImportMode, BaseTypeInference, BufferImportOptions, ConversionDiagnosticOptions, CsvFormulaMode, CsvLineEnding, CsvQuoteStyle, CsvTypeInferenceMode, CsvValueMode, DocxCompatibilityMode, ExchangeDiagnostic, ExchangeError, ExchangeErrorCode, ExchangeExportOptionsMap, ExchangeFormat, ExchangeImportOptionsMap, ExchangeUnitDataMap, ExportOptions, ExportQuota, ExportUnitType, FormulaCalculationMode, IBaseExportMapping, IBaseExportOptions, IBaseFieldMapping, IBaseImportMapping, IBaseImportOptions, IBaseTableMapping, ICsvExportOptions, ICsvExportSelector, ICsvImportOptions, IDocExportOptions, IDocImportOptions, IExchangeConfig, IExportOptionsBase, IExportQuotaOptions, IGridImportOptions, IImportOptionsBase, ISheetExportOptions, ISheetImportOptions, ISlideExportOptions, ISlideImportOptions, ISnapshotWithBlocks, ImportOptions };
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "DreamNum Co., Ltd. <developer@univer.ai>",
|
|
3
3
|
"dependencies": {
|
|
4
|
-
"@univerjs-pro/collaboration": "1.
|
|
5
|
-
"@univerjs-pro/exchange-node-binding": "1.0.
|
|
6
|
-
"@univerjs-pro/slides": "1.
|
|
7
|
-
"@univerjs/core": "1.
|
|
8
|
-
"@univerjs/protocol": "1.
|
|
4
|
+
"@univerjs-pro/collaboration": "1.3.0",
|
|
5
|
+
"@univerjs-pro/exchange-node-binding": "1.0.5",
|
|
6
|
+
"@univerjs-pro/slides": "1.3.0",
|
|
7
|
+
"@univerjs/core": "1.3.0",
|
|
8
|
+
"@univerjs/protocol": "1.3.0",
|
|
9
|
+
"@univerjs-pro/pdfs": "1.3.0"
|
|
9
10
|
},
|
|
10
11
|
"description": "Node.js SDK for converting between Office formats, Univer unit data, and snapshots",
|
|
11
12
|
"files": [
|
|
@@ -13,8 +14,21 @@
|
|
|
13
14
|
"README.md"
|
|
14
15
|
],
|
|
15
16
|
"name": "@univerjs-pro/exchange-node",
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"@univerjs-pro/exchange-pdf-node-binding": "1.0.0"
|
|
19
|
+
},
|
|
20
|
+
"peerDependenciesMeta": {
|
|
21
|
+
"@univerjs-pro/exchange-pdf-node-binding": {
|
|
22
|
+
"optional": true
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"sideEffects": [
|
|
26
|
+
"./src/pdf.ts",
|
|
27
|
+
"./lib/es/pdf.js",
|
|
28
|
+
"./lib/cjs/pdf.cjs"
|
|
29
|
+
],
|
|
16
30
|
"type": "module",
|
|
17
|
-
"version": "1.
|
|
31
|
+
"version": "1.3.0",
|
|
18
32
|
"main": "./lib/cjs/index.cjs",
|
|
19
33
|
"module": "./lib/es/index.js",
|
|
20
34
|
"types": "./lib/types/index.d.ts",
|
|
@@ -24,6 +38,12 @@
|
|
|
24
38
|
"import": "./lib/es/index.js",
|
|
25
39
|
"require": "./lib/cjs/index.cjs",
|
|
26
40
|
"default": "./lib/es/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./pdf": {
|
|
43
|
+
"types": "./lib/types/pdf.d.ts",
|
|
44
|
+
"import": "./lib/es/pdf.js",
|
|
45
|
+
"require": "./lib/cjs/pdf.cjs",
|
|
46
|
+
"default": "./lib/es/pdf.js"
|
|
27
47
|
}
|
|
28
48
|
},
|
|
29
49
|
"publishConfig": {
|