@adobe/helix-onedrive-support 11.1.3 → 11.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/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [11.3.0](https://github.com/adobe/helix-onedrive-support/compare/v11.2.0...v11.3.0) (2023-12-15)
2
+
3
+
4
+ ### Features
5
+
6
+ * add workbook.application ([#475](https://github.com/adobe/helix-onedrive-support/issues/475)) ([782aa5f](https://github.com/adobe/helix-onedrive-support/commit/782aa5ffae19bfe08a02d7e7fb0218c1ccf09878))
7
+
8
+ # [11.2.0](https://github.com/adobe/helix-onedrive-support/compare/v11.1.3...v11.2.0) (2023-12-15)
9
+
10
+
11
+ ### Features
12
+
13
+ * introduce Range.getRowCount ([#474](https://github.com/adobe/helix-onedrive-support/issues/474)) ([593d3c1](https://github.com/adobe/helix-onedrive-support/commit/593d3c1a685444493fafa78d594e9c1e6bf58f85))
14
+
1
15
  ## [11.1.3](https://github.com/adobe/helix-onedrive-support/compare/v11.1.2...v11.1.3) (2023-12-09)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-onedrive-support",
3
- "version": "11.1.3",
3
+ "version": "11.3.0",
4
4
  "description": "Helix OneDrive Support",
5
5
  "main": "src/index.js",
6
6
  "exports": {
@@ -224,12 +224,17 @@ function handleTable(container, segs, method, body) {
224
224
  * @param {object} range The mock range
225
225
  * @param {string} method Request method
226
226
  * @param {object} body Request body
227
+ * @param {string} query query to select values
227
228
  * @returns {object} The response value
228
229
  */
229
- function handleRange(range, method, body) {
230
+ function handleRange(range, method, body, query) {
230
231
  if (method === 'PATCH') {
231
232
  range.values = body;
232
233
  }
234
+ if (method === 'GET' && query) {
235
+ const property = new URLSearchParams(query).get('$select');
236
+ return { [property]: range[property] };
237
+ }
233
238
  return range;
234
239
  }
235
240
 
@@ -424,11 +429,13 @@ export class OneDriveMock extends OneDrive {
424
429
  const type = segs.shift();
425
430
  switch (type) {
426
431
  case 'usedRange':
427
- return handleRange(sheet.usedRange, method, body);
432
+ return handleRange(sheet.usedRange, method, body, query);
428
433
  case 'tables':
429
434
  return handleTable(sheet, segs, method, body);
430
435
  case 'names':
431
436
  return handleNamedItems(sheet, segs, method, body);
437
+ case 'application':
438
+ return { calculate: () => {} };
432
439
  default:
433
440
  if (type?.startsWith('range(address=') && sheet.usedRange?.values) {
434
441
  const address = type.match(/range\(address='([^)]+)'\)/)[1];
@@ -0,0 +1,22 @@
1
+ /*
2
+ * Copyright 2022 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ /**
14
+ * Excel Workbook Application
15
+ */
16
+ export declare interface Application {
17
+ /**
18
+ * Calculate formulas in the workbook.
19
+ * @param {string} calculationType calculation type
20
+ */
21
+ calculate(calculationType: 'Recalculate' | 'Full' | 'FullRebuild'): Promise<void>;
22
+ }
@@ -0,0 +1,36 @@
1
+ /*
2
+ * Copyright 2022 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+ export class Application {
13
+ /**
14
+ * Create a new instance of this class.
15
+ * @param {import('../GraphAPI.js').GraphAPI} graphAPI graph API
16
+ * @param {string} uri uri for this application
17
+ * @param {any} log logger
18
+ */
19
+ constructor(graphAPI, uri, log) {
20
+ this._graphAPI = graphAPI;
21
+ this._uri = uri;
22
+ this._log = log;
23
+ }
24
+
25
+ async calculate(calculationType) {
26
+ return this._graphAPI.doFetch(`${this.uri}/calculate`, false, {
27
+ method: 'POST',
28
+ body: { calculationType },
29
+ headers: { 'content-type': 'application/json' },
30
+ });
31
+ }
32
+
33
+ get uri() {
34
+ return this._uri;
35
+ }
36
+ }
@@ -48,6 +48,11 @@ export declare interface Range {
48
48
  */
49
49
  getRowsAsObjects(opts?:FormatOptions): Promise<Array<object>>;
50
50
 
51
+ /**
52
+ * Returns the row count.
53
+ */
54
+ getRowCount(): Promise<number>;
55
+
51
56
  /**
52
57
  * Returns the values of the range.
53
58
  */
@@ -63,15 +68,15 @@ export declare interface Range {
63
68
 
64
69
  /**
65
70
  * Deletes the cells associated with the range.
66
- * @param shiftValue Specifies which way to shift the cells.
71
+ * @param shiftValue Specifies which way to shift the cells.
67
72
  * The possible values are: Up, Left.
68
73
  */
69
74
  delete(shiftValue: string): Promise<void>;
70
75
 
71
76
  /**
72
- * Inserts a cell or a range of cells into the worksheet in place of this range,
77
+ * Inserts a cell or a range of cells into the worksheet in place of this range,
73
78
  * and shifts the other cells to make space.
74
- * @param shiftValue Specifies which way to shift the cells.
79
+ * @param shiftValue Specifies which way to shift the cells.
75
80
  * The possible values are: Down, Right.
76
81
  */
77
82
  insert(shiftValue: string): Promise<void>;
@@ -71,6 +71,14 @@ export class Range {
71
71
  return rows;
72
72
  }
73
73
 
74
+ async getRowCount() {
75
+ if (this._data) {
76
+ return this._data.rowCount;
77
+ }
78
+ const { rowCount } = await this._graphAPI.doFetch(`${this.uri}?$select=rowCount`);
79
+ return rowCount;
80
+ }
81
+
74
82
  async getValues() {
75
83
  if (!this._values) {
76
84
  if (this._data) {
@@ -13,6 +13,7 @@ import { Table } from './Table';
13
13
  import { Worksheet } from './Worksheet';
14
14
  import { GraphResult } from '../OneDrive';
15
15
  import { NamedItem } from './NamedItem';
16
+ import { Application } from './Application';
16
17
 
17
18
  /**
18
19
  * Excel Work book
@@ -120,4 +121,9 @@ export declare interface Workbook {
120
121
  * @param {string} sessionId session id
121
122
  */
122
123
  setSessionId(sessionId: string): void;
124
+
125
+ /**
126
+ * Return the workbook application
127
+ */
128
+ application(): Application;
123
129
  }
@@ -13,6 +13,7 @@ import { NamedItemContainer } from './NamedItemContainer.js';
13
13
  import { StatusCodeError } from '../StatusCodeError.js';
14
14
  import { Table } from './Table.js';
15
15
  import { Worksheet } from './Worksheet.js';
16
+ import { Application } from './Application.js';
16
17
 
17
18
  export class Workbook extends NamedItemContainer {
18
19
  /**
@@ -158,6 +159,10 @@ export class Workbook extends NamedItemContainer {
158
159
  return table;
159
160
  }
160
161
 
162
+ application() {
163
+ return new Application(this, `${this._uri}/application`, this._log);
164
+ }
165
+
161
166
  get uri() {
162
167
  return this._uri;
163
168
  }