@wae/open-excel 0.0.0-stage → 0.0.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.
@@ -0,0 +1,225 @@
1
+ /**
2
+ * `new OpenExcel(options?)` workbook session.
3
+ *
4
+ * The constructor is synchronous and opens nothing: no network, no disk scan,
5
+ * no window, no file. Native initialisation and imports happen inside the async
6
+ * methods, so a failure is always awaited and always carries a stable code.
7
+ */
8
+ import { OpenExcelError } from './errors.js';
9
+ import { formatFromPath } from './formats.js';
10
+ import * as service from './service.js';
11
+ /** Workbook session. One instance may open several workbooks. */
12
+ export class OpenExcel {
13
+ /** BCP-47 tag used for diagnostics and default copy. */
14
+ locale;
15
+ closed = false;
16
+ handles = new Set();
17
+ workbookHandles = new Map();
18
+ constructor(options = {}) {
19
+ this.locale = options.locale ?? 'en';
20
+ }
21
+ /** Whether {@link dispose} has run. */
22
+ get disposed() {
23
+ return this.closed;
24
+ }
25
+ /**
26
+ * Format, checker, renderer and export disclosure for the installed engine.
27
+ * Read this instead of treating a method name as a capability.
28
+ */
29
+ async capabilities() {
30
+ this.assertActive();
31
+ return service.capabilities();
32
+ }
33
+ /** Creates an empty workbook and returns its committed summary. */
34
+ async create(options = {}) {
35
+ this.assertActive();
36
+ if (options.title !== undefined && (typeof options.title !== 'string' || options.title.length === 0)) {
37
+ throw new OpenExcelError('session/argument-invalid', '`title` must be a non-empty string');
38
+ }
39
+ if (options.template !== undefined && (typeof options.template !== 'string' || options.template.length === 0)) {
40
+ throw new OpenExcelError('session/argument-invalid', '`template` must be a non-empty string');
41
+ }
42
+ const created = service.create({
43
+ title: options.title,
44
+ template: options.template,
45
+ locale: options.locale ?? this.locale,
46
+ });
47
+ this.track(created.handle, created.workbook);
48
+ return created.workbook;
49
+ }
50
+ /** Opens a project file, spreadsheet file or in-memory package. */
51
+ async open(input) {
52
+ this.assertActive();
53
+ assertWorkbookInput(input);
54
+ if (!('path' in input)) {
55
+ const key = 'bytes' in input ? 'bytes' : 'input';
56
+ throw new OpenExcelError('format/unsupported', `opening \`${key}\` needs the package importer; write the project to a path and pass \`path\``, { details: { feature: `open.${key}` } });
57
+ }
58
+ const intent = input.intent ?? 'edit';
59
+ if (intent !== 'edit') {
60
+ throw new OpenExcelError('format/unsupported', `native projects open for editing; \`${intent}\` needs the data pipeline`, { details: { feature: `open.intent.${intent}`, format: this.formatOf(input.path) } });
61
+ }
62
+ const opened = service.open(input.path);
63
+ this.track(opened.handle, opened.workbook);
64
+ return opened.workbook;
65
+ }
66
+ /** Inspects an input without keeping a workbook handle. */
67
+ async inspect(input, options) {
68
+ this.assertActive();
69
+ const opened = service.open(assertProjectPath(input));
70
+ try {
71
+ return service.inspect(opened.handle, options?.checks);
72
+ }
73
+ finally {
74
+ service.close(opened.handle);
75
+ }
76
+ }
77
+ /** Writes one tracked workbook to a native project path. */
78
+ async save(workbook, options) {
79
+ this.assertActive();
80
+ if (options === undefined || typeof options.target !== 'string' || options.target.length === 0) {
81
+ throw new OpenExcelError('session/argument-invalid', '`save` needs a non-empty `target` path');
82
+ }
83
+ return service.save(this.handleOf(workbook), options.target, options.overwrite ?? false);
84
+ }
85
+ /** Reads the current summary of one tracked workbook. */
86
+ async summary(workbook) {
87
+ this.assertActive();
88
+ return service.summary(this.handleOf(workbook));
89
+ }
90
+ /** Applies one edit request and returns the committed revision and summary. */
91
+ async edit(workbook, request) {
92
+ this.assertActive();
93
+ assertEditRequest(request);
94
+ return service.edit(this.handleOf(workbook), request);
95
+ }
96
+ /** Reads one cell of a tracked workbook with its evaluated value. */
97
+ async cell(workbook, query) {
98
+ this.assertActive();
99
+ assertCellQuery(query);
100
+ return service.cell(this.handleOf(workbook), query);
101
+ }
102
+ /** Reads a rectangle of a tracked workbook, row by row. */
103
+ async range(workbook, query) {
104
+ this.assertActive();
105
+ if (query === undefined || typeof query.range !== 'string' || query.range.trim().length === 0) {
106
+ throw new OpenExcelError('session/argument-invalid', '`range` needs a non-empty A1 range such as `A1:C4`');
107
+ }
108
+ return service.range(this.handleOf(workbook), query);
109
+ }
110
+ /** Recomputes every formula of a tracked workbook. */
111
+ async recalc(workbook) {
112
+ this.assertActive();
113
+ return service.recalc(this.handleOf(workbook));
114
+ }
115
+ /** Searches evaluated values and formula sources of a tracked workbook. */
116
+ async find(workbook, request) {
117
+ this.assertActive();
118
+ if (request === undefined || typeof request.query !== 'string' || request.query.length === 0) {
119
+ throw new OpenExcelError('session/argument-invalid', '`find` needs a non-empty `query`');
120
+ }
121
+ return service.find(this.handleOf(workbook), request);
122
+ }
123
+ /** Writes one tracked workbook to an exchange format. */
124
+ async export(workbook, options) {
125
+ this.assertActive();
126
+ if (options === undefined || typeof options.target !== 'string' || options.target.length === 0) {
127
+ throw new OpenExcelError('session/argument-invalid', '`export` needs a non-empty `target` path');
128
+ }
129
+ return service.exportWorkbook(this.handleOf(workbook), options.format, options.target, options.overwrite ?? false);
130
+ }
131
+ /** Renders one sheet of a tracked workbook as SVG. */
132
+ async render(workbook, options = {}) {
133
+ this.assertActive();
134
+ const format = options.format ?? 'svg';
135
+ if (format !== 'svg') {
136
+ throw new OpenExcelError('format/unsupported', `\`${format}\` rendering is not available in this build`, {
137
+ details: { feature: `render.${format}` },
138
+ });
139
+ }
140
+ return service.render(this.handleOf(workbook), options);
141
+ }
142
+ /** Releases the session and every workbook handle it still tracks. Idempotent. */
143
+ async dispose() {
144
+ if (this.closed) {
145
+ return;
146
+ }
147
+ this.closed = true;
148
+ for (const handle of this.handles) {
149
+ try {
150
+ service.close(handle);
151
+ }
152
+ catch {
153
+ // The addon may already be gone; dispose still resolves.
154
+ }
155
+ }
156
+ this.handles.clear();
157
+ this.workbookHandles.clear();
158
+ }
159
+ track(handle, workbook) {
160
+ this.handles.add(handle);
161
+ this.workbookHandles.set(workbook.id, handle);
162
+ }
163
+ handleOf(workbook) {
164
+ const id = typeof workbook === 'string' ? workbook : workbook.id;
165
+ const handle = this.workbookHandles.get(id);
166
+ if (handle === undefined) {
167
+ throw new OpenExcelError('workbook/not-found', `workbook \`${id}\` is not open in this session`);
168
+ }
169
+ return handle;
170
+ }
171
+ /** @internal Throws once the session is gone. */
172
+ assertActive() {
173
+ if (this.closed) {
174
+ throw new OpenExcelError('session/disposed', 'the OpenExcel session has been disposed; create a new instance');
175
+ }
176
+ }
177
+ formatOf(path) {
178
+ return formatFromPath(path);
179
+ }
180
+ }
181
+ function assertProjectPath(input) {
182
+ assertWorkbookInput(input);
183
+ if (!('path' in input)) {
184
+ throw new OpenExcelError('format/unsupported', 'inspection needs a project path; in-memory packages are not supported yet', {
185
+ details: { feature: 'inspect.bytes' },
186
+ });
187
+ }
188
+ return input.path;
189
+ }
190
+ function assertCellQuery(query) {
191
+ if (query === undefined || typeof query.address !== 'string' || query.address.trim().length === 0) {
192
+ throw new OpenExcelError('session/argument-invalid', '`cell` needs a non-empty A1 `address` such as `B4`');
193
+ }
194
+ }
195
+ function assertEditRequest(request) {
196
+ if (request === undefined || !Array.isArray(request.operations) || request.operations.length === 0) {
197
+ throw new OpenExcelError('session/argument-invalid', '`edit` needs a non-empty `operations` array');
198
+ }
199
+ if (request.expectedRevision !== undefined &&
200
+ (!Number.isInteger(request.expectedRevision) || request.expectedRevision < 0)) {
201
+ throw new OpenExcelError('session/argument-invalid', '`expectedRevision` must be a non-negative integer');
202
+ }
203
+ for (const operation of request.operations) {
204
+ if (typeof operation !== 'object' || operation === null || typeof operation.op !== 'string') {
205
+ throw new OpenExcelError('session/argument-invalid', 'each edit operation needs a string `op`');
206
+ }
207
+ }
208
+ }
209
+ function assertWorkbookInput(input) {
210
+ const candidate = input;
211
+ const present = ['path', 'bytes'].filter((key) => candidate[key] !== undefined);
212
+ if (present.length !== 1) {
213
+ throw new OpenExcelError('session/argument-invalid', 'WorkbookInput must contain exactly one of `path` or `bytes`');
214
+ }
215
+ const value = candidate[present[0]];
216
+ if (present[0] === 'bytes') {
217
+ if (!(value instanceof Uint8Array)) {
218
+ throw new OpenExcelError('session/argument-invalid', '`bytes` must be a Uint8Array');
219
+ }
220
+ return;
221
+ }
222
+ if (typeof value !== 'string' || value.length === 0) {
223
+ throw new OpenExcelError('session/argument-invalid', `\`${present[0]}\` must be a non-empty string`);
224
+ }
225
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Orthogonal native operations.
3
+ *
4
+ * One function performs one operation and returns data; argument parsing, help
5
+ * text and exit codes belong to `cli.ts` and to the session surface. Nothing
6
+ * here knows about a command line.
7
+ */
8
+ import type { CellDetail, CellQuery, EditRequest, EditResult, ExportFormat, ExportReport, FindRequest, FindResult, InspectCheck, InspectReport, OpenExcelCapabilities, RangeMatrix, RangeQuery, RecalcReport, SaveReport, SvgRender, Workbook, WorkbookRenderOptions } from './types.js';
9
+ /** Result of creating or opening a workbook. */
10
+ export interface WorkbookHandle {
11
+ readonly handle: number;
12
+ readonly workbook: Workbook;
13
+ }
14
+ /** Arguments of {@link create}. */
15
+ export interface CreateWorkbookRequest {
16
+ readonly title?: string;
17
+ readonly template?: string;
18
+ readonly locale?: string;
19
+ }
20
+ /** Reads the capability matrix of the installed addon. */
21
+ export declare function capabilities(): OpenExcelCapabilities;
22
+ /** Creates a workbook and returns its handle. */
23
+ export declare function create(request: CreateWorkbookRequest): WorkbookHandle;
24
+ /** Opens a project file and returns its handle. */
25
+ export declare function open(path: string): WorkbookHandle;
26
+ /** Writes one open workbook to a project path. */
27
+ export declare function save(handle: number, target: string, overwrite: boolean): SaveReport;
28
+ /** Runs the rule checks of one open workbook. */
29
+ export declare function inspect(handle: number, checks?: readonly InspectCheck[]): InspectReport;
30
+ /** Returns the summary of one open workbook. */
31
+ export declare function summary(handle: number): Workbook;
32
+ /** Applies an edit request to one open workbook. */
33
+ export declare function edit(handle: number, request: EditRequest): EditResult;
34
+ /** Reads one cell with its evaluated value. */
35
+ export declare function cell(handle: number, query: CellQuery): CellDetail;
36
+ /** Reads a rectangle of cells with their evaluated values. */
37
+ export declare function range(handle: number, query: RangeQuery): RangeMatrix;
38
+ /** Recomputes every formula of one open workbook. */
39
+ export declare function recalc(handle: number): RecalcReport;
40
+ /** Searches evaluated values and formula sources of one open workbook. */
41
+ export declare function find(handle: number, request: FindRequest): FindResult;
42
+ /** Renders one sheet of an open workbook as SVG. */
43
+ export declare function render(handle: number, options?: WorkbookRenderOptions): SvgRender;
44
+ /** Writes one open workbook to an export target. */
45
+ export declare function exportWorkbook(handle: number, format: ExportFormat, target: string, overwrite: boolean): ExportReport;
46
+ /** Releases one open workbook handle. */
47
+ export declare function close(handle: number): void;
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Orthogonal native operations.
3
+ *
4
+ * One function performs one operation and returns data; argument parsing, help
5
+ * text and exit codes belong to `cli.ts` and to the session surface. Nothing
6
+ * here knows about a command line.
7
+ */
8
+ import { NotImplementedError, OpenExcelError, errorCodes } from './errors.js';
9
+ import { nativeBinding } from './native.js';
10
+ const knownCodes = new Set(errorCodes);
11
+ function binding(feature) {
12
+ const native = nativeBinding();
13
+ if (!native) {
14
+ throw new NotImplementedError(feature);
15
+ }
16
+ return native;
17
+ }
18
+ function decode(work) {
19
+ try {
20
+ return JSON.parse(work());
21
+ }
22
+ catch (error) {
23
+ throw translate(error);
24
+ }
25
+ }
26
+ function translate(error) {
27
+ if (error instanceof OpenExcelError) {
28
+ return error;
29
+ }
30
+ const message = error instanceof Error ? error.message : String(error);
31
+ const separator = message.indexOf(': ');
32
+ const code = separator > 0 ? message.slice(0, separator) : '';
33
+ if (knownCodes.has(code)) {
34
+ return new OpenExcelError(code, message.slice(separator + 2), { details: { feature: code } });
35
+ }
36
+ return new OpenExcelError('format/invalid', message, { cause: error });
37
+ }
38
+ /** Reads the capability matrix of the installed addon. */
39
+ export function capabilities() {
40
+ return decode(() => binding('capabilities').capabilities());
41
+ }
42
+ /** Creates a workbook and returns its handle. */
43
+ export function create(request) {
44
+ return decode(() => binding('create').workbook_create(JSON.stringify({ title: request.title, template: request.template, locale: request.locale })));
45
+ }
46
+ /** Opens a project file and returns its handle. */
47
+ export function open(path) {
48
+ return decode(() => binding('open').workbook_open(path));
49
+ }
50
+ /** Writes one open workbook to a project path. */
51
+ export function save(handle, target, overwrite) {
52
+ return decode(() => binding('workbook.save').workbook_save(handle, target, overwrite));
53
+ }
54
+ /** Runs the rule checks of one open workbook. */
55
+ export function inspect(handle, checks) {
56
+ return decode(() => checks === undefined
57
+ ? binding('workbook.inspect').workbook_inspect(handle)
58
+ : binding('workbook.inspect').workbook_inspect(handle, JSON.stringify(checks)));
59
+ }
60
+ /** Returns the summary of one open workbook. */
61
+ export function summary(handle) {
62
+ return decode(() => binding('workbook.summary').workbook_summary(handle));
63
+ }
64
+ /** Applies an edit request to one open workbook. */
65
+ export function edit(handle, request) {
66
+ return decode(() => binding('workbook.edit').workbook_edit(handle, JSON.stringify(request)));
67
+ }
68
+ /** Reads one cell with its evaluated value. */
69
+ export function cell(handle, query) {
70
+ return decode(() => binding('workbook.cell').workbook_cell(handle, JSON.stringify(query)));
71
+ }
72
+ /** Reads a rectangle of cells with their evaluated values. */
73
+ export function range(handle, query) {
74
+ return decode(() => binding('workbook.range').workbook_range(handle, JSON.stringify(query)));
75
+ }
76
+ /** Recomputes every formula of one open workbook. */
77
+ export function recalc(handle) {
78
+ return decode(() => binding('workbook.recalc').workbook_recalc(handle));
79
+ }
80
+ /** Searches evaluated values and formula sources of one open workbook. */
81
+ export function find(handle, request) {
82
+ return decode(() => binding('workbook.find').workbook_find(handle, JSON.stringify(request)));
83
+ }
84
+ /** Renders one sheet of an open workbook as SVG. */
85
+ export function render(handle, options = {}) {
86
+ return decode(() => binding('workbook.render').workbook_render(handle, JSON.stringify(options)));
87
+ }
88
+ /** Writes one open workbook to an export target. */
89
+ export function exportWorkbook(handle, format, target, overwrite) {
90
+ return decode(() => binding('workbook.export').workbook_export(handle, format, target, overwrite));
91
+ }
92
+ /** Releases one open workbook handle. */
93
+ export function close(handle) {
94
+ binding('workbook.close').workbook_close(handle);
95
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Smoke tests for the declared workbook surface.
3
+ *
4
+ * They assert shell semantics only: one stable error code for unimplemented
5
+ * capabilities, a session that closes idempotently, synchronous argument
6
+ * validation, a format registry that classifies the whole family, and one
7
+ * structural edit that needs the native engine. No renderer or import behaviour
8
+ * is claimed here.
9
+ */
10
+ export {};
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Smoke tests for the declared workbook surface.
3
+ *
4
+ * They assert shell semantics only: one stable error code for unimplemented
5
+ * capabilities, a session that closes idempotently, synchronous argument
6
+ * validation, a format registry that classifies the whole family, and one
7
+ * structural edit that needs the native engine. No renderer or import behaviour
8
+ * is claimed here.
9
+ */
10
+ import assert from 'node:assert/strict';
11
+ import test from 'node:test';
12
+ import { formatFromPath, formatInfo, OpenExcel, OpenExcelError, workbookFormats } from './index.js';
13
+ import { nativeBinding } from './native.js';
14
+ const installed = (() => {
15
+ try {
16
+ return nativeBinding() !== undefined;
17
+ }
18
+ catch {
19
+ return false;
20
+ }
21
+ })();
22
+ const withAddon = installed ? 'a built addon is installed' : false;
23
+ test('session construction is synchronous and side-effect free', async () => {
24
+ const excel = new OpenExcel();
25
+ assert.equal(excel.locale, 'en');
26
+ assert.equal(excel.disposed, false);
27
+ await excel.dispose();
28
+ assert.equal(excel.disposed, true);
29
+ });
30
+ test('without an installed addon engine calls keep capability/not-implemented', { skip: withAddon }, async () => {
31
+ const excel = new OpenExcel({ locale: 'zh-CN' });
32
+ assert.equal(excel.locale, 'zh-CN');
33
+ const calls = [
34
+ () => excel.capabilities(),
35
+ () => excel.create({ title: 'Ledger', template: 'blank' }),
36
+ () => excel.open({ path: 'ledger.oexcel' }),
37
+ () => excel.inspect({ path: 'ledger.xlsx' }),
38
+ ];
39
+ for (const call of calls) {
40
+ await assert.rejects(call, (error) => {
41
+ assert.ok(error instanceof OpenExcelError);
42
+ assert.equal(error.code, 'capability/not-implemented');
43
+ assert.ok(error.details.feature);
44
+ return true;
45
+ });
46
+ }
47
+ await excel.dispose();
48
+ });
49
+ test('dispose is idempotent and closes the session', async () => {
50
+ const excel = new OpenExcel();
51
+ await excel.dispose();
52
+ await excel.dispose();
53
+ await assert.rejects(excel.capabilities(), (error) => error instanceof OpenExcelError && error.code === 'session/disposed');
54
+ });
55
+ test('dispose resolves after a rejected create and open', { skip: withAddon }, async () => {
56
+ const excel = new OpenExcel();
57
+ await assert.rejects(excel.create({ title: 'Ledger' }));
58
+ await assert.rejects(excel.open({ path: 'ledger.oexcel' }));
59
+ await excel.dispose();
60
+ await excel.dispose();
61
+ assert.equal(excel.disposed, true);
62
+ });
63
+ test('open rejects ambiguous input before reaching the engine', async () => {
64
+ const excel = new OpenExcel();
65
+ const inputs = [
66
+ {},
67
+ { path: 'a.oexcel', bytes: new Uint8Array() },
68
+ { bytes: 'not bytes' },
69
+ { path: '' },
70
+ ];
71
+ for (const input of inputs) {
72
+ await assert.rejects(excel.open(input), (error) => error instanceof OpenExcelError && error.code === 'session/argument-invalid');
73
+ }
74
+ await excel.dispose();
75
+ });
76
+ test('create rejects empty titles synchronously', async () => {
77
+ const excel = new OpenExcel();
78
+ await assert.rejects(excel.create({ title: '' }), (error) => error instanceof OpenExcelError && error.code === 'session/argument-invalid');
79
+ await assert.rejects(excel.create({ template: '' }), (error) => error instanceof OpenExcelError && error.code === 'session/argument-invalid');
80
+ await excel.dispose();
81
+ });
82
+ test('save, edit, export and render validate arguments before reaching the engine', async () => {
83
+ const excel = new OpenExcel();
84
+ const workbook = { id: 'workbook-0', revision: 0, title: 'Fixture', sheets: [], cells: 0 };
85
+ const invalid = (error) => error instanceof OpenExcelError && error.code === 'session/argument-invalid';
86
+ await assert.rejects(excel.save(workbook, { target: '' }), invalid);
87
+ await assert.rejects(excel.edit(workbook, { operations: [] }), invalid);
88
+ await assert.rejects(excel.edit(workbook, { expectedRevision: -1, operations: [{ op: 'sheet.add', name: 'Second' }] }), invalid);
89
+ await assert.rejects(excel.edit(workbook, { operations: [{}] }), invalid);
90
+ await assert.rejects(excel.export(workbook, { format: 'csv', target: '' }), invalid);
91
+ await assert.rejects(excel.cell(workbook, { address: ' ' }), invalid);
92
+ await assert.rejects(excel.range(workbook, { range: '' }), invalid);
93
+ await assert.rejects(excel.render(workbook, { format: 'png' }), (error) => error instanceof OpenExcelError && error.code === 'format/unsupported');
94
+ await excel.dispose();
95
+ });
96
+ test('tracked reads reject unknown workbooks before reaching the engine', async () => {
97
+ const excel = new OpenExcel();
98
+ const workbook = { id: 'workbook-404', revision: 0, title: 'Fixture', sheets: [], cells: 0 };
99
+ const missing = (error) => error instanceof OpenExcelError && error.code === 'workbook/not-found';
100
+ await assert.rejects(excel.cell(workbook, { address: 'A1' }), missing);
101
+ await assert.rejects(excel.range(workbook, { range: 'A1:B2' }), missing);
102
+ await assert.rejects(excel.recalc(workbook), missing);
103
+ await excel.dispose();
104
+ });
105
+ test('tracked operations reject unknown workbooks before reaching the engine', async () => {
106
+ const excel = new OpenExcel();
107
+ const workbook = { id: 'workbook-404', revision: 0, title: 'Fixture', sheets: [], cells: 0 };
108
+ const missing = (error) => error instanceof OpenExcelError && error.code === 'workbook/not-found';
109
+ await assert.rejects(excel.summary(workbook), missing);
110
+ await assert.rejects(excel.save(workbook, { target: 'fixture.oexcel' }), missing);
111
+ await assert.rejects(excel.export(workbook, { format: 'csv', target: 'fixture.csv' }), missing);
112
+ await excel.dispose();
113
+ });
114
+ test('format registry classifies the workbook format family', () => {
115
+ const expected = ['xlsx', 'xlsm', 'xltx', 'xls', 'csv', 'tsv', 'ods', 'json', 'xml', 'pdf'];
116
+ assert.deepEqual([...workbookFormats].sort(), [...expected].sort());
117
+ assert.equal(formatInfo('xlsx').defaultIntent, 'edit');
118
+ assert.equal(formatInfo('xltx').defaultIntent, 'template');
119
+ assert.equal(formatInfo('csv').defaultIntent, 'data');
120
+ assert.equal(formatInfo('csv').opensAs, 'data');
121
+ assert.equal(formatInfo('xlsm').macroEnabled, true);
122
+ assert.equal(formatInfo('xltx').family, 'template');
123
+ assert.equal(formatInfo('xls').family, 'legacy');
124
+ assert.equal(formatInfo('ods').markup, 'odf');
125
+ assert.equal(formatInfo('pdf').opensAs, 'none');
126
+ assert.equal(formatInfo('pdf').defaultIntent, null);
127
+ assert.equal(formatFromPath('Ledger.XLSX'), 'xlsx');
128
+ assert.equal(formatFromPath('sheet.numbers'), undefined);
129
+ assert.equal(formatFromPath('no-extension'), undefined);
130
+ });
131
+ test('a native addon can insert a row and move its references', { skip: installed ? false : 'a built addon is not installed' }, async (context) => {
132
+ const excel = new OpenExcel();
133
+ const created = await excel.create({ title: 'Structure' });
134
+ const seeded = await excel.edit(created, {
135
+ operations: [
136
+ { op: 'cell.set', sheet: 'Sheet1', reference: 'A1', value: 1 },
137
+ { op: 'cell.set', sheet: 'Sheet1', reference: 'A2', value: 2 },
138
+ { op: 'cell.set', sheet: 'Sheet1', reference: 'B2', formula: '=A2' },
139
+ ],
140
+ });
141
+ let edited;
142
+ try {
143
+ edited = await excel.edit(seeded.workbook, { operations: [{ op: 'row.insert', sheet: 'Sheet1', row: 2 }] });
144
+ }
145
+ catch (error) {
146
+ if (error instanceof OpenExcelError && error.code === 'object/unsupported' && error.message.includes('row.insert')) {
147
+ context.skip('the installed addon predates `row.insert`');
148
+ await excel.dispose();
149
+ return;
150
+ }
151
+ throw error;
152
+ }
153
+ assert.equal(edited.revision, 2);
154
+ const moved = await excel.cell(edited.workbook, { sheet: 'Sheet1', address: 'A3' });
155
+ assert.equal(moved.value, 2);
156
+ const formula = await excel.cell(edited.workbook, { sheet: 'Sheet1', address: 'B3' });
157
+ assert.equal(formula.formula, '=A3');
158
+ await excel.dispose();
159
+ });