@adobe/helix-onedrive-support 8.2.8 → 8.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,10 @@
1
+ # [8.3.0](https://github.com/adobe/helix-onedrive-support/compare/v8.2.8...v8.3.0) (2022-09-10)
2
+
3
+
4
+ ### Features
5
+
6
+ * support delete column ([#298](https://github.com/adobe/helix-onedrive-support/issues/298)) ([9e41fbd](https://github.com/adobe/helix-onedrive-support/commit/9e41fbdb091f372314bb2311a1c912315c108111))
7
+
1
8
  ## [8.2.8](https://github.com/adobe/helix-onedrive-support/compare/v8.2.7...v8.2.8) (2022-09-03)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-onedrive-support",
3
- "version": "8.2.8",
3
+ "version": "8.3.0",
4
4
  "description": "Helix OneDrive Support",
5
5
  "main": "src/index.js",
6
6
  "exports": {
@@ -96,6 +96,7 @@ function handleTable(container, segs, method, body) {
96
96
  }
97
97
  let command;
98
98
  let name;
99
+ let index;
99
100
  if (segs[0]) {
100
101
  [, command, , name] = segs.shift().match(/([^?(]+)(\('([^)]+)'\))?(\?(.+))?/);
101
102
  }
@@ -113,7 +114,7 @@ function handleTable(container, segs, method, body) {
113
114
  table.rows.push(...body.values);
114
115
  return { index: table.rows.length - 1 };
115
116
  }
116
- const index = parseInt(subCommand.replace(/itemAt\(index=([0-9]+)\)/, '$1'), 10);
117
+ index = parseInt(subCommand.replace(/itemAt\(index=([0-9]+)\)/, '$1'), 10);
117
118
  if (index < 0 || index >= table.rows.length) {
118
119
  throw new StatusCodeError(`Index out of range: ${index}`, 400);
119
120
  }
@@ -127,7 +128,27 @@ function handleTable(container, segs, method, body) {
127
128
  return { values: [table.rows[index]] };
128
129
  }
129
130
  case 'columns': {
131
+ if (method === 'DELETE') {
132
+ const headerName = segs.shift();
133
+ index = table.headerNames.indexOf(headerName);
134
+ if (index === -1) {
135
+ throw new StatusCodeError(`Column name not found: ${headerName}`, 400);
136
+ }
137
+ table.headerNames.splice(index, 1);
138
+ table.rows.forEach((row) => {
139
+ row.splice(index, 1);
140
+ });
141
+ return null;
142
+ }
143
+ if (body) {
144
+ ({ name, index = table.headerNames.length } = body);
145
+ table.headerNames.splice(index, 0, name);
146
+ table.rows.forEach((row) => {
147
+ row.splice(index, 0, '');
148
+ });
149
+ }
130
150
  if (!name) {
151
+ // return all columns and their data
131
152
  const cols = table.headerNames.map((n) => ({
132
153
  name: n,
133
154
  values: [[n]],
@@ -142,7 +163,7 @@ function handleTable(container, segs, method, body) {
142
163
  };
143
164
  }
144
165
  const columnName = name;
145
- const index = table.headerNames.findIndex((n) => n === columnName);
166
+ index = table.headerNames.findIndex((n) => n === columnName);
146
167
  if (index === -1) {
147
168
  throw new StatusCodeError(`Column name not found: ${columnName}`, 400);
148
169
  }
@@ -86,11 +86,17 @@ export declare interface Table {
86
86
  */
87
87
  getColumn(name: string): Promise<string[]>;
88
88
 
89
- /**
89
+ /**
90
90
  * Add a column to an existing table
91
91
  * @param name name of new column
92
92
  * @param index zero-based index or missing to add at end
93
93
  * @returns new column
94
94
  */
95
- addColumn(name:string, index?:number): Promise<DriveItem>;
95
+ addColumn(name:string, index?:number): Promise<DriveItem>;
96
+
97
+ /**
98
+ * Delete a column from the table
99
+ * @param name column name
100
+ */
101
+ deleteColumn(name: string): Promise<void>;
96
102
  }
@@ -116,7 +116,7 @@ export class Table {
116
116
  const body = {
117
117
  name,
118
118
  };
119
- if (index) {
119
+ if (index !== undefined) {
120
120
  body.index = index;
121
121
  }
122
122
  return this._oneDrive.doFetch(`${this.uri}/columns`, false, {
@@ -125,6 +125,12 @@ export class Table {
125
125
  });
126
126
  }
127
127
 
128
+ async deleteColumn(name) {
129
+ return this._oneDrive.doFetch(`${this.uri}/columns/${name}`, true, {
130
+ method: 'DELETE',
131
+ });
132
+ }
133
+
128
134
  get name() {
129
135
  return this._name;
130
136
  }
@@ -51,7 +51,7 @@ export declare interface Workbook {
51
51
  * @param hasHeaders whether the table has headers
52
52
  * @param name optional name
53
53
  */
54
- addTable(address: string, hasHeaders: boolean, name?: string): Promise<Table>;
54
+ addTable(address: string, hasHeaders: boolean, name?: string): Promise<Table>;
55
55
 
56
56
  /**
57
57
  * Return the named items in a work book
@@ -82,5 +82,5 @@ export declare interface Worksheet {
82
82
  * Returns a new range object that spans the address given
83
83
  * @param address address, e.g. A1:C2
84
84
  */
85
- range(address): Range;
85
+ range(address): Range;
86
86
  }