@openfn/language-googlesheets 4.1.1 → 5.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.
package/ast.json CHANGED
@@ -3,11 +3,13 @@
3
3
  {
4
4
  "name": "appendValues",
5
5
  "params": [
6
- "params",
7
- "callback"
6
+ "spreadsheetId",
7
+ "range",
8
+ "values",
9
+ "options"
8
10
  ],
9
11
  "docs": {
10
- "description": "Add an array of rows to the spreadsheet.\nhttps://developers.google.com/sheets/api/samples/writing#append_values",
12
+ "description": "Append one or more rows to a spreadsheet range.\nhttps://developers.google.com/sheets/api/samples/writing#append_values",
11
13
  "tags": [
12
14
  {
13
15
  "title": "public",
@@ -16,7 +18,7 @@
16
18
  },
17
19
  {
18
20
  "title": "example",
19
- "description": "appendValues({\n spreadsheetId: '1O-a4_RgPF_p8W3I6b5M9wobA3-CBW8hLClZfUik5sos',\n range: 'Sheet1!A1:E1',\n values: [\n ['From expression', '$15', '2', '3/15/2016'],\n ['Really now!', '$100', '1', '3/20/2016'],\n ],\n})"
21
+ "description": "appendValues(\n '1O-a4_RgPF_p8W3I6b5M9wobA3-CBW8hLClZfUik5sos',\n 'Sheet1!A1:E1',\n [['From expression', '$15', '2', '3/15/2016'], ['Really now!', '$100', '1', '3/20/2016']]\n)"
20
22
  },
21
23
  {
22
24
  "title": "function",
@@ -25,57 +27,54 @@
25
27
  },
26
28
  {
27
29
  "title": "param",
28
- "description": "Data object to add to the spreadsheet.",
30
+ "description": "The spreadsheet ID.",
29
31
  "type": {
30
32
  "type": "NameExpression",
31
- "name": "Object"
33
+ "name": "string"
32
34
  },
33
- "name": "params"
35
+ "name": "spreadsheetId"
34
36
  },
35
37
  {
36
38
  "title": "param",
37
- "description": "The spreadsheet ID.",
39
+ "description": "The sheet range.",
38
40
  "type": {
39
- "type": "OptionalType",
40
- "expression": {
41
- "type": "NameExpression",
42
- "name": "string"
43
- }
41
+ "type": "NameExpression",
42
+ "name": "string"
44
43
  },
45
- "name": "params.spreadsheetId"
44
+ "name": "range"
46
45
  },
47
46
  {
48
47
  "title": "param",
49
- "description": "The range of values to update.",
48
+ "description": "The values to append.",
50
49
  "type": {
51
- "type": "OptionalType",
52
- "expression": {
53
- "type": "NameExpression",
54
- "name": "string"
55
- }
50
+ "type": "NameExpression",
51
+ "name": "array"
56
52
  },
57
- "name": "params.range"
53
+ "name": "values"
58
54
  },
59
55
  {
60
56
  "title": "param",
61
- "description": "A 2d array of values to update.",
57
+ "description": "Optional settings.",
62
58
  "type": {
63
59
  "type": "OptionalType",
64
60
  "expression": {
65
61
  "type": "NameExpression",
66
- "name": "array"
62
+ "name": "Object"
67
63
  }
68
64
  },
69
- "name": "params.values"
65
+ "name": "options"
70
66
  },
71
67
  {
72
68
  "title": "param",
73
- "description": "(Optional) Callback function",
69
+ "description": "Defaults to 'USER_ENTERED'.",
74
70
  "type": {
75
- "type": "NameExpression",
76
- "name": "function"
71
+ "type": "OptionalType",
72
+ "expression": {
73
+ "type": "NameExpression",
74
+ "name": "string"
75
+ }
77
76
  },
78
- "name": "callback"
77
+ "name": "options.valueInputOption"
79
78
  },
80
79
  {
81
80
  "title": "returns",
@@ -92,15 +91,17 @@
92
91
  {
93
92
  "name": "batchUpdateValues",
94
93
  "params": [
95
- "params",
96
- "callback"
94
+ "spreadsheetId",
95
+ "data",
96
+ "options"
97
97
  ],
98
98
  "docs": {
99
99
  "description": "Batch update values in a Spreadsheet.",
100
100
  "tags": [
101
101
  {
102
102
  "title": "example",
103
- "description": "batchUpdateValues({\n spreadsheetId: '1O-a4_RgPF_p8W3I6b5M9wobA3-CBW8hLClZfUik5sos',\n range: 'Sheet1!A1:E1',\n values: [\n ['From expression', '$15', '2', '3/15/2016'],\n ['Really now!', '$100', '1', '3/20/2016'],\n ],\n})"
103
+ "description": "batchUpdateValues(\n '1O-a4_RgPF_p8W3I6b5M9wobA3-CBW8hLClZfUik5sos',\n [\n { range: 'Sheet1!A1', values: [['value1']] },\n { range: 'Sheet1!B5', values: [['value2']] },\n { range: 'Sheet1!D10:E11', values: [['a', 'b'], ['c', 'd']] },\n ],\n { valueInputOption: 'RAW' }\n)",
104
+ "caption": "Update multiple separate ranges"
104
105
  },
105
106
  {
106
107
  "title": "function",
@@ -114,40 +115,63 @@
114
115
  },
115
116
  {
116
117
  "title": "param",
117
- "description": "Data object to add to the spreadsheet.",
118
+ "description": "The spreadsheet ID.",
118
119
  "type": {
119
120
  "type": "NameExpression",
120
- "name": "Object"
121
+ "name": "string"
121
122
  },
122
- "name": "params"
123
+ "name": "spreadsheetId"
123
124
  },
124
125
  {
125
126
  "title": "param",
126
- "description": "The spreadsheet ID.",
127
+ "description": "Array of range/values objects to update.",
127
128
  "type": {
128
- "type": "OptionalType",
129
+ "type": "TypeApplication",
129
130
  "expression": {
130
131
  "type": "NameExpression",
131
- "name": "string"
132
- }
133
- },
134
- "name": "params.spreadsheetId"
135
- },
136
- {
137
- "title": "param",
138
- "description": "The range of values to update.",
132
+ "name": "Array"
133
+ },
134
+ "applications": [
135
+ {
136
+ "type": "RecordType",
137
+ "fields": [
138
+ {
139
+ "type": "FieldType",
140
+ "key": "range",
141
+ "value": {
142
+ "type": "NameExpression",
143
+ "name": "string"
144
+ }
145
+ },
146
+ {
147
+ "type": "FieldType",
148
+ "key": "values",
149
+ "value": {
150
+ "type": "NameExpression",
151
+ "name": "array"
152
+ }
153
+ }
154
+ ]
155
+ }
156
+ ]
157
+ },
158
+ "name": "data"
159
+ },
160
+ {
161
+ "title": "param",
162
+ "description": "Optional settings.",
139
163
  "type": {
140
164
  "type": "OptionalType",
141
165
  "expression": {
142
166
  "type": "NameExpression",
143
- "name": "string"
167
+ "name": "Object"
144
168
  }
145
169
  },
146
- "name": "params.range"
170
+ "name": "options"
147
171
  },
148
172
  {
149
173
  "title": "param",
150
- "description": "(Optional) Value update options. Defaults to 'USER_ENTERED'",
174
+ "description": "Defaults to 'USER_ENTERED'.",
151
175
  "type": {
152
176
  "type": "OptionalType",
153
177
  "expression": {
@@ -155,28 +179,7 @@
155
179
  "name": "string"
156
180
  }
157
181
  },
158
- "name": "params.valueInputOption"
159
- },
160
- {
161
- "title": "param",
162
- "description": "A 2d array of values to update.",
163
- "type": {
164
- "type": "OptionalType",
165
- "expression": {
166
- "type": "NameExpression",
167
- "name": "array"
168
- }
169
- },
170
- "name": "params.values"
171
- },
172
- {
173
- "title": "param",
174
- "description": "(Optional) callback function",
175
- "type": {
176
- "type": "NameExpression",
177
- "name": "function"
178
- },
179
- "name": "callback"
182
+ "name": "options.valueInputOption"
180
183
  },
181
184
  {
182
185
  "title": "returns",
@@ -194,8 +197,7 @@
194
197
  "name": "getValues",
195
198
  "params": [
196
199
  "spreadsheetId",
197
- "range",
198
- "callback"
200
+ "range"
199
201
  ],
200
202
  "docs": {
201
203
  "description": "Gets cell values from a Spreadsheet.",
@@ -232,15 +234,6 @@
232
234
  },
233
235
  "name": "range"
234
236
  },
235
- {
236
- "title": "param",
237
- "description": "(Optional) callback function",
238
- "type": {
239
- "type": "NameExpression",
240
- "name": "function"
241
- },
242
- "name": "callback"
243
- },
244
237
  {
245
238
  "title": "returns",
246
239
  "description": "spreadsheet information",
package/dist/index.cjs CHANGED
@@ -107,24 +107,29 @@ function execute(...operations) {
107
107
  });
108
108
  };
109
109
  }
110
- function appendValues(params, callback = (s) => s) {
110
+ function appendValues(spreadsheetId, range, values, options = {}) {
111
111
  return (state) => {
112
- const [resolvedParams] = (0, import_util.expandReferences)(state, params);
113
- const { spreadsheetId, range, values } = resolvedParams;
114
- if (!values || values.length === 0) {
112
+ const [
113
+ resolvedSpreadsheetId,
114
+ resolvedRange,
115
+ resolvedValues,
116
+ resolvedOptions
117
+ ] = (0, import_util.expandReferences)(state, spreadsheetId, range, values, options);
118
+ const { valueInputOption = "USER_ENTERED" } = resolvedOptions;
119
+ if (!resolvedValues || resolvedValues.length === 0) {
115
120
  console.log("Warning: empty values array");
116
121
  return state;
117
122
  }
118
123
  return new Promise((resolve, reject) => {
119
124
  client.spreadsheets.values.append(
120
125
  {
121
- spreadsheetId,
122
- range,
123
- valueInputOption: "USER_ENTERED",
126
+ spreadsheetId: resolvedSpreadsheetId,
127
+ range: resolvedRange,
128
+ valueInputOption,
124
129
  resource: {
125
- range,
130
+ range: resolvedRange,
126
131
  majorDimension: "ROWS",
127
- values
132
+ values: resolvedValues
128
133
  }
129
134
  },
130
135
  function(err, response) {
@@ -134,54 +139,42 @@ function appendValues(params, callback = (s) => s) {
134
139
  } else {
135
140
  console.log("Success! Here is the response from Google:");
136
141
  console.log(response.data);
137
- resolve(
138
- callback({
139
- ...(0, import_language_common.composeNextState)(state, response.data),
140
- response
141
- })
142
- );
142
+ resolve({
143
+ ...(0, import_language_common.composeNextState)(state, response.data),
144
+ response
145
+ });
143
146
  }
144
147
  }
145
148
  );
146
149
  });
147
150
  };
148
151
  }
149
- function batchUpdateValues(params, callback = (s) => s) {
152
+ function batchUpdateValues(spreadsheetId, data, options = {}) {
150
153
  return async (state) => {
151
- const [resolvedParams] = (0, import_util.expandReferences)(state, params);
152
- const {
153
- spreadsheetId,
154
- range,
155
- valueInputOption = "USER_ENTERED",
156
- values
157
- } = resolvedParams;
158
- if (!values || values.length === 0) {
159
- console.log("Warning: empty values array");
154
+ const [resolvedSpreadsheetId, resolvedData, resolvedOptions] = (0, import_util.expandReferences)(state, spreadsheetId, data, options);
155
+ const { valueInputOption = "USER_ENTERED" } = resolvedOptions;
156
+ if (!resolvedData || resolvedData.length === 0) {
157
+ console.log("Warning: empty data array");
160
158
  return state;
161
159
  }
162
160
  const resource = {
163
- data: [
164
- {
165
- range,
166
- values
167
- }
168
- ],
161
+ data: resolvedData,
169
162
  valueInputOption
170
163
  };
171
164
  try {
172
165
  const response = await client.spreadsheets.values.batchUpdate({
173
- spreadsheetId,
166
+ spreadsheetId: resolvedSpreadsheetId,
174
167
  resource
175
168
  });
176
169
  console.log("%d cells updated.", response.data.totalUpdatedCells);
177
- return callback({ ...(0, import_language_common.composeNextState)(state, response.data), response });
170
+ return { ...(0, import_language_common.composeNextState)(state, response.data), response };
178
171
  } catch (err) {
179
172
  logError(err);
180
173
  throw err;
181
174
  }
182
175
  };
183
176
  }
184
- function getValues(spreadsheetId, range, callback = (s) => s) {
177
+ function getValues(spreadsheetId, range) {
185
178
  return async (state) => {
186
179
  var _a;
187
180
  const [resolvedSheetId, resolvedRange] = (0, import_util.expandReferences)(
@@ -197,7 +190,7 @@ function getValues(spreadsheetId, range, callback = (s) => s) {
197
190
  const numRows = ((_a = response == null ? void 0 : response.data) == null ? void 0 : _a.values.length) ?? 0;
198
191
  console.log(`${numRows} rows retrieved.`);
199
192
  const nextState = { ...(0, import_language_common.composeNextState)(state, response.data), response };
200
- return callback(nextState);
193
+ return nextState;
201
194
  } catch (err) {
202
195
  logError(err);
203
196
  throw err;
package/dist/index.js CHANGED
@@ -91,24 +91,29 @@ function execute(...operations) {
91
91
  });
92
92
  };
93
93
  }
94
- function appendValues(params, callback = (s) => s) {
94
+ function appendValues(spreadsheetId, range, values, options = {}) {
95
95
  return (state) => {
96
- const [resolvedParams] = expandReferences(state, params);
97
- const { spreadsheetId, range, values } = resolvedParams;
98
- if (!values || values.length === 0) {
96
+ const [
97
+ resolvedSpreadsheetId,
98
+ resolvedRange,
99
+ resolvedValues,
100
+ resolvedOptions
101
+ ] = expandReferences(state, spreadsheetId, range, values, options);
102
+ const { valueInputOption = "USER_ENTERED" } = resolvedOptions;
103
+ if (!resolvedValues || resolvedValues.length === 0) {
99
104
  console.log("Warning: empty values array");
100
105
  return state;
101
106
  }
102
107
  return new Promise((resolve, reject) => {
103
108
  client.spreadsheets.values.append(
104
109
  {
105
- spreadsheetId,
106
- range,
107
- valueInputOption: "USER_ENTERED",
110
+ spreadsheetId: resolvedSpreadsheetId,
111
+ range: resolvedRange,
112
+ valueInputOption,
108
113
  resource: {
109
- range,
114
+ range: resolvedRange,
110
115
  majorDimension: "ROWS",
111
- values
116
+ values: resolvedValues
112
117
  }
113
118
  },
114
119
  function(err, response) {
@@ -118,54 +123,42 @@ function appendValues(params, callback = (s) => s) {
118
123
  } else {
119
124
  console.log("Success! Here is the response from Google:");
120
125
  console.log(response.data);
121
- resolve(
122
- callback({
123
- ...composeNextState(state, response.data),
124
- response
125
- })
126
- );
126
+ resolve({
127
+ ...composeNextState(state, response.data),
128
+ response
129
+ });
127
130
  }
128
131
  }
129
132
  );
130
133
  });
131
134
  };
132
135
  }
133
- function batchUpdateValues(params, callback = (s) => s) {
136
+ function batchUpdateValues(spreadsheetId, data, options = {}) {
134
137
  return async (state) => {
135
- const [resolvedParams] = expandReferences(state, params);
136
- const {
137
- spreadsheetId,
138
- range,
139
- valueInputOption = "USER_ENTERED",
140
- values
141
- } = resolvedParams;
142
- if (!values || values.length === 0) {
143
- console.log("Warning: empty values array");
138
+ const [resolvedSpreadsheetId, resolvedData, resolvedOptions] = expandReferences(state, spreadsheetId, data, options);
139
+ const { valueInputOption = "USER_ENTERED" } = resolvedOptions;
140
+ if (!resolvedData || resolvedData.length === 0) {
141
+ console.log("Warning: empty data array");
144
142
  return state;
145
143
  }
146
144
  const resource = {
147
- data: [
148
- {
149
- range,
150
- values
151
- }
152
- ],
145
+ data: resolvedData,
153
146
  valueInputOption
154
147
  };
155
148
  try {
156
149
  const response = await client.spreadsheets.values.batchUpdate({
157
- spreadsheetId,
150
+ spreadsheetId: resolvedSpreadsheetId,
158
151
  resource
159
152
  });
160
153
  console.log("%d cells updated.", response.data.totalUpdatedCells);
161
- return callback({ ...composeNextState(state, response.data), response });
154
+ return { ...composeNextState(state, response.data), response };
162
155
  } catch (err) {
163
156
  logError(err);
164
157
  throw err;
165
158
  }
166
159
  };
167
160
  }
168
- function getValues(spreadsheetId, range, callback = (s) => s) {
161
+ function getValues(spreadsheetId, range) {
169
162
  return async (state) => {
170
163
  var _a;
171
164
  const [resolvedSheetId, resolvedRange] = expandReferences(
@@ -181,7 +174,7 @@ function getValues(spreadsheetId, range, callback = (s) => s) {
181
174
  const numRows = ((_a = response == null ? void 0 : response.data) == null ? void 0 : _a.values.length) ?? 0;
182
175
  console.log(`${numRows} rows retrieved.`);
183
176
  const nextState = { ...composeNextState(state, response.data), response };
184
- return callback(nextState);
177
+ return nextState;
185
178
  } catch (err) {
186
179
  logError(err);
187
180
  throw err;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@openfn/language-googlesheets",
3
3
  "label": "Google Sheets",
4
- "version": "4.1.1",
4
+ "version": "5.0.0",
5
5
  "description": "A Google Sheets Language Pack for OpenFn",
6
6
  "homepage": "https://docs.openfn.org",
7
7
  "repository": {
@@ -26,14 +26,15 @@
26
26
  ],
27
27
  "dependencies": {
28
28
  "googleapis": "171.4.0",
29
- "@openfn/language-common": "3.3.3"
29
+ "@openfn/language-common": "3.3.4"
30
30
  },
31
31
  "devDependencies": {
32
32
  "assertion-error": "1.1.0",
33
33
  "chai": "4.3.6",
34
34
  "deep-eql": "4.1.1",
35
35
  "nock": "13.2.9",
36
- "rimraf": "3.0.2"
36
+ "rimraf": "3.0.2",
37
+ "sinon": "^21.1.2"
37
38
  },
38
39
  "type": "module",
39
40
  "types": "types/index.d.ts",
@@ -12,58 +12,53 @@
12
12
  */
13
13
  export function execute(...operations: Operations): Operation;
14
14
  /**
15
- * Add an array of rows to the spreadsheet.
15
+ * Append one or more rows to a spreadsheet range.
16
16
  * https://developers.google.com/sheets/api/samples/writing#append_values
17
17
  * @public
18
18
  * @example
19
- * appendValues({
20
- * spreadsheetId: '1O-a4_RgPF_p8W3I6b5M9wobA3-CBW8hLClZfUik5sos',
21
- * range: 'Sheet1!A1:E1',
22
- * values: [
23
- * ['From expression', '$15', '2', '3/15/2016'],
24
- * ['Really now!', '$100', '1', '3/20/2016'],
25
- * ],
26
- * })
19
+ * appendValues(
20
+ * '1O-a4_RgPF_p8W3I6b5M9wobA3-CBW8hLClZfUik5sos',
21
+ * 'Sheet1!A1:E1',
22
+ * [['From expression', '$15', '2', '3/15/2016'], ['Really now!', '$100', '1', '3/20/2016']]
23
+ * )
27
24
  * @function
28
- * @param {Object} params - Data object to add to the spreadsheet.
29
- * @param {string} [params.spreadsheetId] The spreadsheet ID.
30
- * @param {string} [params.range] The range of values to update.
31
- * @param {array} [params.values] A 2d array of values to update.
32
- * @param {function} callback - (Optional) Callback function
25
+ * @param {string} spreadsheetId - The spreadsheet ID.
26
+ * @param {string} range - The sheet range.
27
+ * @param {array} values - The values to append.
28
+ * @param {Object} [options] - Optional settings.
29
+ * @param {string} [options.valueInputOption] - Defaults to 'USER_ENTERED'.
33
30
  * @returns {Operation}
34
31
  */
35
- export function appendValues(params: {
36
- spreadsheetId?: string;
37
- range?: string;
38
- values?: any[];
39
- }, callback?: Function): Operation;
32
+ export function appendValues(spreadsheetId: string, range: string, values: any[], options?: {
33
+ valueInputOption?: string;
34
+ }): Operation;
40
35
  /**
41
36
  * Batch update values in a Spreadsheet.
42
37
  * @example
43
- * batchUpdateValues({
44
- * spreadsheetId: '1O-a4_RgPF_p8W3I6b5M9wobA3-CBW8hLClZfUik5sos',
45
- * range: 'Sheet1!A1:E1',
46
- * values: [
47
- * ['From expression', '$15', '2', '3/15/2016'],
48
- * ['Really now!', '$100', '1', '3/20/2016'],
38
+ * <caption>Update multiple separate ranges</caption>
39
+ * batchUpdateValues(
40
+ * '1O-a4_RgPF_p8W3I6b5M9wobA3-CBW8hLClZfUik5sos',
41
+ * [
42
+ * { range: 'Sheet1!A1', values: [['value1']] },
43
+ * { range: 'Sheet1!B5', values: [['value2']] },
44
+ * { range: 'Sheet1!D10:E11', values: [['a', 'b'], ['c', 'd']] },
49
45
  * ],
50
- * })
46
+ * { valueInputOption: 'RAW' }
47
+ * )
51
48
  * @function
52
49
  * @public
53
- * @param {Object} params - Data object to add to the spreadsheet.
54
- * @param {string} [params.spreadsheetId] The spreadsheet ID.
55
- * @param {string} [params.range] The range of values to update.
56
- * @param {string} [params.valueInputOption] (Optional) Value update options. Defaults to 'USER_ENTERED'
57
- * @param {array} [params.values] A 2d array of values to update.
58
- * @param {function} callback - (Optional) callback function
50
+ * @param {string} spreadsheetId - The spreadsheet ID.
51
+ * @param {Array<{range: string, values: array}>} data - Array of range/values objects to update.
52
+ * @param {Object} [options] - Optional settings.
53
+ * @param {string} [options.valueInputOption] - Defaults to 'USER_ENTERED'.
59
54
  * @returns {Operation} spreadsheet information
60
55
  */
61
- export function batchUpdateValues(params: {
62
- spreadsheetId?: string;
63
- range?: string;
56
+ export function batchUpdateValues(spreadsheetId: string, data: Array<{
57
+ range: string;
58
+ values: any[];
59
+ }>, options?: {
64
60
  valueInputOption?: string;
65
- values?: any[];
66
- }, callback?: Function): Operation;
61
+ }): Operation;
67
62
  /**
68
63
  * Gets cell values from a Spreadsheet.
69
64
  * @public
@@ -72,8 +67,7 @@ export function batchUpdateValues(params: {
72
67
  * @function
73
68
  * @param {string} spreadsheetId The spreadsheet ID.
74
69
  * @param {string} range The sheet range.
75
- * @param {function} callback - (Optional) callback function
76
70
  * @returns {Operation} spreadsheet information
77
71
  */
78
- export function getValues(spreadsheetId: string, range: string, callback?: Function): Operation;
72
+ export function getValues(spreadsheetId: string, range: string): Operation;
79
73
  export { alterState, combine, cursor, dataPath, dataValue, each, field, fields, fn, fnIf, lastReferenceValue, log, merge, sourceValue } from "@openfn/language-common";