@mcpher/gas-fakes 1.0.10 → 1.0.11

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.
Files changed (40) hide show
  1. package/README.md +469 -138
  2. package/package.json +5 -1
  3. package/src/services/advsheets/fakeadvsheetsdevelopermetadata.js +65 -0
  4. package/src/services/advsheets/fakeadvsheetsspreadsheets.js +5 -2
  5. package/src/services/commonclasses/fakerichtextvalue.js +131 -0
  6. package/src/services/commonclasses/fakerun.js +38 -0
  7. package/src/services/commonclasses/faketextstyle.js +5 -2
  8. package/src/services/commonclasses/faketextstylebuilder.js +1 -4
  9. package/src/services/spreadsheetapp/fakebanding.js +350 -0
  10. package/src/services/spreadsheetapp/fakebigquerydatasourcespec.js +52 -0
  11. package/src/services/spreadsheetapp/fakebigquerydatasourcespecbuilder.js +62 -0
  12. package/src/services/spreadsheetapp/fakedatasource.js +172 -0
  13. package/src/services/spreadsheetapp/fakedatasourcecolumn.js +162 -0
  14. package/src/services/spreadsheetapp/fakedatasourcecolumnreference.js +25 -0
  15. package/src/services/spreadsheetapp/fakedatasourceparameter.js +40 -0
  16. package/src/services/spreadsheetapp/fakedatasourcespec.js +78 -0
  17. package/src/services/spreadsheetapp/fakedatasourcespecbuilder.js +102 -0
  18. package/src/services/spreadsheetapp/fakedatatable.js +69 -0
  19. package/src/services/spreadsheetapp/fakedevelopermetadata.js +112 -0
  20. package/src/services/spreadsheetapp/fakedevelopermetadatafinder.js +185 -0
  21. package/src/services/spreadsheetapp/fakedevelopermetadatalocation.js +54 -0
  22. package/src/services/spreadsheetapp/fakefilter.js +169 -0
  23. package/src/services/spreadsheetapp/fakefiltercriteria.js +100 -0
  24. package/src/services/spreadsheetapp/fakefiltercriteriabuilder.js +224 -0
  25. package/src/services/spreadsheetapp/fakepivotfilter.js +131 -0
  26. package/src/services/spreadsheetapp/fakepivotgroup.js +185 -0
  27. package/src/services/spreadsheetapp/fakepivottable.js +260 -0
  28. package/src/services/spreadsheetapp/fakepivotvalue.js +170 -0
  29. package/src/services/spreadsheetapp/fakerun.js +38 -0
  30. package/src/services/spreadsheetapp/fakesheet.js +331 -369
  31. package/src/services/spreadsheetapp/fakesheetrange.js +1231 -157
  32. package/src/services/spreadsheetapp/fakesheetrangelist.js +10 -2
  33. package/src/services/spreadsheetapp/fakesortspec.js +69 -0
  34. package/src/services/spreadsheetapp/fakespreadsheet.js +94 -15
  35. package/src/services/spreadsheetapp/fakespreadsheetapp.js +49 -10
  36. package/src/services/spreadsheetapp/sheetrangehelpers.js +99 -12
  37. package/src/services/spreadsheetapp/sheetrangemakers.js +174 -14
  38. package/src/support/helpers.js +2 -2
  39. package/src/support/sheetutils.js +120 -5
  40. package/src/support/utils.js +94 -15
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  I use clasp/vscode to develop Google Apps Script (GAS) applications, but when using GAS native services, there's way too much back and fowards to the GAS IDE going while testing. I set myself the ambition of implementing fake version of the GAS runtime environment on Node so I could at least do some testing locally.
4
4
 
5
- This is just a proof of concept so I've implemented a subset of number of services and methods, but the tricky parts are all in place so all that's left is a load of busy work (to which I heartily invite any interested collaborators).
5
+ This is a proof of concept so I've implemented a subset of number of services and methods, but the tricky parts are all in place so all that's left is a load of busy work (to which I heartily invite any interested collaborators).
6
6
 
7
7
  ## progress
8
8
 
@@ -20,26 +20,106 @@ The idea is that you can run GAS services (so far implemented) locally on Node,
20
20
 
21
21
  Just as on Apps Script, everything is executed synchronously so you don't need to bother with handling Promises/async/await. Note that the intended audience is Apps Script developers who want to run the same code and access the same services in both Node and Apps Script.
22
22
 
23
- If you don't plan on using Apps Script at all, the Node Workspace APIs (which I use in the background for all these services in any case) will be more efficient if operating in their normal asynchronous mode.
23
+ If you don't plan on using Apps Script at all, the Node Workspace APIs (which I use in the background for all these services in any case) will be more efficient when operating in their normal asynchronous mode. On the other hand, if you only casually want to access workspace resources from Node, and can't be bothered digging into how the Node Workspace APIs work, you could still use this as part of your node project. Apps Script services are much simpler than the full API. Apps Script advanced services are also available via gas-fakes if you want a hybrid solution.
24
24
 
25
25
  ### Cloud project
26
26
 
27
- You don't have access to the GAS maintained cloud project, so you'll need to create a GCP project to use locally. In order to duplicate the OAuth management handled by GAS, we'll use Application Default Caredentials. There re some scripts in this repo to set up and test these. Once you've set up a cloud project go to the shells folder and add your `project id` to `setaccount.sh` and
27
+ You don't have access to the GAS maintained cloud project, so you'll need to create a GCP project to use locally. In order to duplicate the OAuth management handled by GAS, we'll use Application Default Credentials.
28
28
 
29
- ### Testing
29
+ There are some scripts in this repo in the ./shells folder to set up and test these, but first you'll need to add some stuff to the .env file. First copy the .env.template to .env. More info on this is availble in the setup-env.MD file.
30
30
 
31
- I recommend you use the test project included in the repo to make sure all is set up correctly. It uses a Fake DriveApp service to excercise Auth etc. Just change the fixtures in your own environments by following the instructions in [setup-env.md](https://github.com/brucemcpherson/gas-fakes/blob/main/setup-env.MD), then `npm i && npm test`.
31
+ This is the template - at the very least you need to add the gcp project id you'll be using for testing, plus the id of some file you have access to - this'll be used to check that you have set up ADC properly.
32
32
 
33
- Note that I use a [unit tester](https://ramblings.mcpher.com/apps-script-test-runner-library-ported-to-node/) that runs in both GAS and Node, so the exact same tests will run in both environments. There are some example tests in the repo. Each test has been proved on both Node and GAS. There's also a shell (togas.sh) which will use clasp to push the test code to Apps Script.
33
+ If you want to run the test suite, there are some other things required in the .env file as below - you may need to request access to some of the resources mentions, or you could replace with your own. If you just want to get going using gas-fakes on Node, you can just ignore all that.
34
34
 
35
- Each test can be run individually (for example `npm run testdrive`) or all with `npm test`
35
+ ```
36
+ # for testing authentication
37
+ GCP_PROJECT_ID="add your gcp project id here"
38
+ DRIVE_TEST_FILE_ID="add the id of some test file you have access to here"
39
+
40
+ # we'll use the default config for application default credentials
41
+ AC=default
42
+ # these are the scopes set by default - take some of these out if you want to minimize access
43
+ DEFAULT_SCOPES="https://www.googleapis.com/auth/userinfo.email,openid,https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/sqlservice.login"
44
+ EXTRA_SCOPES=",https://www.googleapis.com/auth/drive,https://www.googleapis.com/auth/spreadsheets"
45
+
46
+ # everything below here is required for the test suite if you are using it otherwise you can ignore everything below here
47
+ # you can ask me for access to the shared files if you are running the test suite, or you can create your own versions
48
+
49
+ # set your email address to test various apis
50
+ SHARED_FILE_OWNER="bruce@mcpher.com"
51
+ EMAIL="bruce@mcpher.com"
52
+ TIMEZONE="Europe/London"
53
+ TEST_LOCALE="en"
54
+ OWNER_NAME="Bruce Mcpherson"
55
+
56
+ # these are files that are used to test some drive features
57
+ TEST_BORDERS_ID="1hRGdrYHEPixXTuQLeL3Z0qGRZVs_8ojMIm6D4KrCh1o"
58
+ TEST_AIRPORTS_ID="1h9IGIShgVBVUrUjjawk5MaCEQte_7t32XeEP1Z5jXKQ"
59
+ TEST_AIRPORTS_NAME="airport list"
60
+ TEST_FOLDER_NAME="math"
61
+ TEST_FOLDER_FILES=3
62
+ TEST_FOLDER_ID="1Zww9oCTFR7zYcUYXxd70yQr3sw6VdLG-"
63
+ TEXT_FILE_NAME="fake.txt"
64
+ TEXT_FILE_ID="1142Vn7W-pGl5nWLpUSkpOB82JDiz9R6p"
65
+ TEXT_FILE_TYPE="text/plain"
66
+ TEXT_FILE_CONTENT="foo is not bar"
67
+ BLOB_NAME="foo.txt"
68
+ BLOB_TYPE="text/plain"
69
+ TEST_SHEET_ID="1DlKpVVYCrCPNfRbGsz6N_K3oPTgdC9gQIKi0aNb42uI"
70
+ TEST_SHEET_NAME="sharedlibraries"
71
+ PUBLIC_SHARE_FILE_ID="1OFJk38kW9TRrEf-B9F1gTZk2uLV-ZSpR"
72
+ SHARED_FILE_ID="1uz4cxEDxtQzu0cBb1B4h6fsjgWy7hNFf"
73
+ PDF_ID="1v5kJ5SOY2nu3DI1LKwALb3seaBpF3kWu"
74
+
75
+ # these are parameters for testing
76
+ MIN_ROOT_PDFS=20
77
+ MIN_PDFS=400
78
+ MIN_FOLDERS_ROOT=110
79
+ SKIP_SINGLE_PARENT=1
80
+
81
+ ZIP_TYPE="application/zip"
82
+ KIND_DRIVE="drive#file"
83
+
84
+ RANDOM_IMAGE="https://picsum.photos/200"
85
+ API_URL="http://suggestqueries.google.com/complete/search?client=chrome&hl=en&q=trump"
86
+ API_TYPE="text/javascript"
87
+ CLEAN=1
88
+ ```
89
+
90
+ ### OAuth
91
+
92
+ There's 2 pieces to this solution.
93
+
94
+ #### Application default credentials (ADC)
36
95
 
37
- Test settings and fixtures are in the .env file. Some readonly files are publicly shared and can be left with the example value in .env-template. Most files which are written are created and deleted afterwards on successful completion. They will be named something starting with --.
96
+ In order to avoid a bunch of Node specific code and credentials, yet still handle OAuth, I figured that we could simply rely on ADC. This is a problem I already wrote about here [Application Default Credentials with Google Cloud and Workspace APIs](https://ramblings.mcpher.com/application-default-credentials-with-google-cloud-and-workspace-apis/)
97
+
98
+ This section in your env file controls which scopes you plan to use.
99
+
100
+ ```
101
+ we'll use the default config for application default credentials
102
+ AC=default
103
+ # these are the scopes set by default - take some of these out if you want to minimize access
104
+ DEFAULT_SCOPES="https://www.googleapis.com/auth/userinfo.email,openid,https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/sqlservice.login"
105
+ EXTRA_SCOPES=",https://www.googleapis.com/auth/drive,https://www.googleapis.com/auth/spreadsheets"
106
+
107
+ .....etc
108
+ ```
109
+
110
+ #### Manifest file
38
111
 
112
+ **gas-fakes** reads the manifest file to see which scopes you need in your project, uses the Google Auth library to attempt to authorizes them and has `ScriptApp.getOauthToken()` return a sufficiently specced token, just as the GAS environment does. Just make sure you have an `appsscript.json` in the same folder as your main script.
113
+
114
+ Now you can execute this and it will set up your ADC to be able to run any services that require the scopes you add.
115
+
116
+ ##### note
117
+
118
+ Although you may be tempted to add `https://www.googleapis.com/auth/script.external_request`, it's not necessary for the ADC and in fact will generate an error. You will of course need it in your Apps script manifest.
39
119
 
40
120
  ### Settings
41
121
 
42
- gasfakes.json holds various location and behavior parameters to inform about your Node environment. It's not required on GAS as you can't change anything over there. If you don't have one, it'll create one for you and use some sensible defaults. Here's an example of one with the defaults. It should be in the same folder as your main script.
122
+ Optionally, gasfakes.json holds various location and behavior parameters to inform about your Node environment. It's not required on GAS as you can't change anything over there. If you don't have one or need one, it'll create one for you and use some sensible defaults. Here's an example of one with the defaults. It should be in the same folder as your main script.
43
123
 
44
124
  ```
45
125
  {
@@ -63,19 +143,6 @@ gasfakes.json holds various location and behavior parameters to inform about you
63
143
 
64
144
  More on all this later.
65
145
 
66
- ### Pushing to GAS
67
-
68
- The script togas.sh will move your files to GAS - just set the `SOURCE` and `TARGET` folders in the script. Make sure you have an `appsscript.json` manifest in the `SOURCE` folder, as **gas-fakes** reads that to handle OAuth on Node.
69
-
70
- You can write your project to run on Node and call GAS services, and it will also run on the GAS environment with no code changes, except on the Node side you have this one import
71
-
72
- ```sh
73
- // all the fake services are here
74
- import '@mcpher/gas-fakes/main.js'
75
- ```
76
-
77
- togas.sh will remove imports and exports on the way to apps script, which doesnt support them.
78
-
79
146
  ## Approach
80
147
 
81
148
  Google have not made details about the GAS run time public (as far as I know). What we do know is that it used to run on a Java based JavaScript emulator [Rhino](https://ramblings.mcpher.com/gassnippets2/what-javascript-engine-is-apps-script-running-on/) but a few years ago moved to a V8 runtime. Beyond that, we don't know anything much other than it runs on Google Servers somewhere.
@@ -95,58 +162,7 @@ Although Apps Script supports async/await/promise syntax, it operates in blockin
95
162
 
96
163
  Since asynchonicity is fundamental to Node, there's no real simple way to convert async to sync. However, there is such a thing as a [child-process](https://nodejs.org/api/child_process.html#child-process) which you can start up to run things, and it features an [execSync](https://nodejs.org/api/child_process.html#child_processexecsynccommand-options) method which delays the return from the child process until the promise queue is all settled. So the simplest solution is to run an async method in a child process, wait till it's done, and return the results synchronously. I found that [Sindre Sorhus](https://github.com/sindresorhus) uses this approach with [make-synchronous](https://github.com/sindresorhus/make-synchronous), so I'm using that.
97
164
 
98
- Runnng up a child process in Node is pretty expensive and slow (especially of you're running in debug mode in vscode), so I'll be looking for ways to speed that up when I get to it.
99
-
100
- ### OAuth
101
-
102
- There's 2 pieces to this solution.
103
-
104
- #### Application default credentials (ADC)
105
-
106
- In order to avoid a bunch of Node specific code and credentials, yet still handle OAuth, I figured that we could simply rely on ADC. This is a problem I already wrote about here [Application Default Credentials with Google Cloud and Workspace APIs](https://ramblings.mcpher.com/application-default-credentials-with-google-cloud-and-workspace-apis/)
107
-
108
- To set this up, set your GCP project ID and the extra scopes you'll need in `shells/setaccount.sh`. In this example I'm retaining the usual ADC scopes, and adding an extra scope to be able to access Drive.
109
-
110
- ```sh
111
- # project ID
112
- P=YOUR_GCP_PROJECT_ID
113
-
114
- # config to activate - multiple configs can each be named
115
- # here we're working on the default project configuration
116
- AC=default
117
-
118
- # these are the ones it sets by default - take some of these out if you want to minimize access
119
- DEFAULT_SCOPES="https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/drive,openid,https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/sqlservice.login"
120
-
121
- # these are the ones we want to add (note comma at beginning)
122
- EXTRA_SCOPES=",https://www.googleapis.com/auth/drive"
123
-
124
- .....etc
125
- ```
126
-
127
- Now you can execute this and it will set up your ADC to be able to run any services that require the scopes you add.
128
-
129
- ##### note
130
-
131
- Although you may be tempted to add `https://www.googleapis.com/auth/script.external_request`, it's not necessary for the ADC and in fact will generate an error. You will of course need it in your Apps script manifest.
132
-
133
- ##### testing ADC
134
-
135
- `shells/testtoken.sh` can test that you can generate a token with sufficient scope. In this example, I'm checking that I can access a file I own. Change the id to one of your own.
136
-
137
- ```js
138
- # check tokens have scopes required for DRIVE access
139
- # set below to a fileid on drive you have access to
140
- FILE_ID=SOME_FILE_ID
141
-
142
- ....etc
143
- ```
144
-
145
- I recommend you do this to make sure Auth it's all good before you start coding up your app.
146
-
147
- #### Manifest file
148
-
149
- **gas-fakes** reads the manifest file to see which scopes you need in your project, uses the Google Auth library to attempt to authorizes them and has `ScriptApp.getOauthToken()` return a sufficiently specced token, just as the GAS environment does. Just make sure you have an `appsscript.json` in the same folder as your main script.
165
+ Runnng up a child process in Node is pretty expensive and slow, so I'll be looking for ways to speed that up when I get to it.
150
166
 
151
167
  ### Global intialization
152
168
 
@@ -154,7 +170,7 @@ This was a little problematic to sequence, but I wanted to make sure that any GA
154
170
 
155
171
  Only a subset of methods are currently available for some of them - the rest are work in progress. My approach is to start with a little bit of each service to prove feasibility and provide a base to build on.
156
172
 
157
- v1.0.8
173
+ v1.0.10
158
174
 
159
175
  - `DriveApp` - 50%
160
176
  - `ScriptApp` - almost all
@@ -168,10 +184,11 @@ v1.0.8
168
184
  - `Blob` - all
169
185
  - `User` - all
170
186
  - `Drive (Advanced Service)` - 40%
187
+ - `Sheets (Advanced Service)` - 40%
171
188
 
172
189
  ### Testing coverage
173
190
 
174
- Tests for all methods are added as we go to the cumulative unit tests and run on both Apps Script and Node. The goal is to try to get the behavior as exactly equivalent as possible. See/updated the issues section for detected anomalies. There are currently 1182 active tests.
191
+ Tests for all methods are added as we go to the cumulative unit tests and run on both Apps Script and Node. The goal is to try to get the behavior as exactly equivalent as possible. There are currently almost 4000 active tests.
175
192
 
176
193
  #### Proxies and globalThis
177
194
 
@@ -195,7 +212,7 @@ All 3 are supported for both properties and cache.
195
212
 
196
213
  ##### scriptId
197
214
 
198
- The local version may have no knowledge of the Apps ScriptId. If you are using clasp, it's picked up from the .clasp.json file. However if you are not using clasp, or want to use something else, you can set the scriptId in `gasfakes.json`, otherwise it'll create a fake id use that. All property and cache stores use the scriptId to partition data.
215
+ The local version may have no knowledge of the Apps ScriptId. If you are using clasp, it's picked up from the .clasp.json file. However if you are not using clasp, or want to use something else, you can set the scriptId in `gasfakes.json`, otherwise it'll create a fake id use that - but that means that each store will be different each time you run it, so the best approach is to add a value unique to the group of scripts that want to share the same stores in gas-fakes.json. All property and cache stores use the scriptId to partition data.
199
216
 
200
217
  ##### userId
201
218
 
@@ -211,34 +228,218 @@ As you will have noticed, there are various local support files for props/cachin
211
228
 
212
229
  ## Debugging
213
230
 
214
- For conversion of async to sync, I'm spawing a subprocess using [make-synchronous](https://github.com/sindresorhus/make-synchronous). Out of the box it inherits the Node Options from the main process, so that means it'll try to run each subprocess in debug mode also. Bringing up and down the debugger each time takes forever, so I've temporaily modified my local version of make-synchronous to drop the debug inheritance.
231
+ For conversion of async to sync, I'm spawing a subprocess using [make-synchronous](https://github.com/sindresorhus/make-synchronous). Out of the box it inherits the Node Options from the main process, so that means it'll try to run each subprocess in debug mode also. Bringing up and down the debugger each time takes forever, so I've temporaily modified my local version of make-synchronous to drop the debug inheritance.
215
232
 
216
233
  If this makes it to the repo we can start to use it from there - see issue https://github.com/sindresorhus/make-synchronous/issues/14
217
234
 
218
235
  ## Noticed differences
219
236
 
220
- I'll make a note in thre repos issues on implementation differences. In the main will be slight differences in error message text, which I'll normalize over time, or where Apps Script has a fundamental obstacle. Please report any differences in behavior you find in the repo issues.
237
+ In the main, these will be slight differences in error message text, which I'll normalize over time, or where Apps Script has a fundamental obstacle. Please report any differences in behavior you find in the repo issues.
221
238
 
222
239
  ### Tradeoffs
223
240
 
224
- I've come across various Apps Script bugs/issues as I work through this which I've reported to the GAS team, and added workarounds in the gas fakes code - not sure at this point whether to duplicate the buggy behavior or simulate what would seem to be the correct one. Again - any things you come across please use the issues in the repo to report.
241
+ I've come across various Apps Script bugs/issues as I work through this which I've reported to the GAS team, and added workarounds in the gas fakes code - not sure at this point whether to duplicate the buggy behavior or simulate what would seem to be the correct one. This is not a complete list, so any things you come across please use the issues in the repo to report.
225
242
 
226
243
  ## Oddities
227
244
 
228
245
  Just a few things I've come across when digging into the differences between what the sheets API and Apps Script do. Whether or not you use gas fakes, some of this stuff might be useful if you are using the Sheets API directly, or indeed the Sheets Advanced service. I'll just make a growing list of stuff I've found, in no particular order.
229
246
 
230
-
231
247
  ### Note to collaborators
232
- If you are tempted to use Gemini as a shortcut to avoid reading the docs, I've found that it's pretty inaccurate and you can waste a huge amount of time taking what it says as gospel. You'll get used to seeing this apology from Gemini -
233
- ````
234
- You are absolutely correct! My sincerest apologies for that significant error.
235
248
 
236
- You've hit on a crucial detail that I completely missed, and I deeply appreciate you pointing it out and providing the correct documentation link.
237
- ````
238
-
239
- And you eventually have to dig into the docs yourself to track down why something Gemini advised isn't working.
240
-
241
- I'm just not bothering with at all now. It wastes more time than it saves.
249
+ Gemini code assist can be a very helpful for the busy work, but there a huge number of inconsistencies between what it believes to be the documentation and the actual real world, so if Gemini starts flailing take over early.
250
+
251
+ You eventually have to dig into the docs yourself to track down why something Gemini advised isn't working.
252
+
253
+ Gemini can also write test cases, but it tends to miss adding edge cases, so don't rely on Gemini completely for that, and always get the tests working Apps Script side first to ensure it is behaving as expected (often it's not) - after all that's what we're trying to emulate.
254
+
255
+ ### Colors
256
+
257
+ #### Named Colors
258
+
259
+ In addition to CSS hex notation (e.g., `#ff0000`), Apps Script methods like `Range.setBackground()` and `Range.setFontColor()` also accept standard CSS color names. The fake environment supports all 147 standard names, which are treated case-insensitively.
260
+
261
+ | Name | Hex Value |
262
+ | ---------------------- | --------- |
263
+ | `aliceblue` | `#f0f8ff` |
264
+ | `antiquewhite` | `#faebd7` |
265
+ | `aqua` | `#00ffff` |
266
+ | `aquamarine` | `#7fffd4` |
267
+ | `azure` | `#f0ffff` |
268
+ | `beige` | `#f5f5dc` |
269
+ | `bisque` | `#ffe4c4` |
270
+ | `black` | `#000000` |
271
+ | `blanchedalmond` | `#ffebcd` |
272
+ | `blue` | `#0000ff` |
273
+ | `blueviolet` | `#8a2be2` |
274
+ | `brown` | `#a52a2a` |
275
+ | `burlywood` | `#deb887` |
276
+ | `cadetblue` | `#5f9ea0` |
277
+ | `chartreuse` | `#7fff00` |
278
+ | `chocolate` | `#d2691e` |
279
+ | `coral` | `#ff7f50` |
280
+ | `cornflowerblue` | `#6495ed` |
281
+ | `cornsilk` | `#fff8dc` |
282
+ | `crimson` | `#dc143c` |
283
+ | `cyan` | `#00ffff` |
284
+ | `darkblue` | `#00008b` |
285
+ | `darkcyan` | `#008b8b` |
286
+ | `darkgoldenrod` | `#b8860b` |
287
+ | `darkgray` | `#a9a9a9` |
288
+ | `darkgreen` | `#006400` |
289
+ | `darkgrey` | `#a9a9a9` |
290
+ | `darkkhaki` | `#bdb76b` |
291
+ | `darkmagenta` | `#8b008b` |
292
+ | `darkolivegreen` | `#556b2f` |
293
+ | `darkorange` | `#ff8c00` |
294
+ | `darkorchid` | `#9932cc` |
295
+ | `darkred` | `#8b0000` |
296
+ | `darksalmon` | `#e9967a` |
297
+ | `darkseagreen` | `#8fbc8f` |
298
+ | `darkslateblue` | `#483d8b` |
299
+ | `darkslategray` | `#2f4f4f` |
300
+ | `darkslategrey` | `#2f4f4f` |
301
+ | `darkturquoise` | `#00ced1` |
302
+ | `darkviolet` | `#9400d3` |
303
+ | `deeppink` | `#ff1493` |
304
+ | `deepskyblue` | `#00bfff` |
305
+ | `dimgray` | `#696969` |
306
+ | `dimgrey` | `#696969` |
307
+ | `dodgerblue` | `#1e90ff` |
308
+ | `firebrick` | `#b22222` |
309
+ | `floralwhite` | `#fffaf0` |
310
+ | `forestgreen` | `#228b22` |
311
+ | `fuchsia` | `#ff00ff` |
312
+ | `gainsboro` | `#dcdcdc` |
313
+ | `ghostwhite` | `#f8f8ff` |
314
+ | `gold` | `#ffd700` |
315
+ | `goldenrod` | `#daa520` |
316
+ | `gray` | `#808080` |
317
+ | `green` | `#008000` |
318
+ | `greenyellow` | `#adff2f` |
319
+ | `grey` | `#808080` |
320
+ | `honeydew` | `#f0fff0` |
321
+ | `hotpink` | `#ff69b4` |
322
+ | `indianred` | `#cd5c5c` |
323
+ | `indigo` | `#4b0082` |
324
+ | `ivory` | `#fffff0` |
325
+ | `khaki` | `#f0e68c` |
326
+ | `lavender` | `#e6e6fa` |
327
+ | `lavenderblush` | `#fff0f5` |
328
+ | `lawngreen` | `#7cfc00` |
329
+ | `lemonchiffon` | `#fffacd` |
330
+ | `lightblue` | `#add8e6` |
331
+ | `lightcoral` | `#f08080` |
332
+ | `lightcyan` | `#e0ffff` |
333
+ | `lightgoldenrodyellow` | `#fafad2` |
334
+ | `lightgray` | `#d3d3d3` |
335
+ | `lightgreen` | `#90ee90` |
336
+ | `lightgrey` | `#d3d3d3` |
337
+ | `lightpink` | `#ffb6c1` |
338
+ | `lightsalmon` | `#ffa07a` |
339
+ | `lightseagreen` | `#20b2aa` |
340
+ | `lightskyblue` | `#87cefa` |
341
+ | `lightslategray` | `#778899` |
342
+ | `lightslategrey` | `#778899` |
343
+ | `lightsteelblue` | `#b0c4de` |
344
+ | `lightyellow` | `#ffffe0` |
345
+ | `lime` | `#00ff00` |
346
+ | `limegreen` | `#32cd32` |
347
+ | `linen` | `#faf0e6` |
348
+ | `magenta` | `#ff00ff` |
349
+ | `maroon` | `#800000` |
350
+ | `mediumaquamarine` | `#66cdaa` |
351
+ | `mediumblue` | `#0000cd` |
352
+ | `mediumorchid` | `#ba55d3` |
353
+ | `mediumpurple` | `#9370db` |
354
+ | `mediumseagreen` | `#3cb371` |
355
+ | `mediumslateblue` | `#7b68ee` |
356
+ | `mediumspringgreen` | `#00fa9a` |
357
+ | `mediumturquoise` | `#48d1cc` |
358
+ | `mediumvioletred` | `#c71585` |
359
+ | `midnightblue` | `#191970` |
360
+ | `mintcream` | `#f5fffa` |
361
+ | `mistyrose` | `#ffe4e1` |
362
+ | `moccasin` | `#ffe4b5` |
363
+ | `navajowhite` | `#ffdead` |
364
+ | `navy` | `#000080` |
365
+ | `oldlace` | `#fdf5e6` |
366
+ | `olive` | `#808000` |
367
+ | `olivedrab` | `#6b8e23` |
368
+ | `orange` | `#ffa500` |
369
+ | `orangered` | `#ff4500` |
370
+ | `orchid` | `#da70d6` |
371
+ | `palegoldenrod` | `#eee8aa` |
372
+ | `palegreen` | `#98fb98` |
373
+ | `paleturquoise` | `#afeeee` |
374
+ | `palevioletred` | `#db7093` |
375
+ | `papayawhip` | `#ffefd5` |
376
+ | `peachpuff` | `#ffdab9` |
377
+ | `peru` | `#cd853f` |
378
+ | `pink` | `#ffc0cb` |
379
+ | `plum` | `#dda0dd` |
380
+ | `powderblue` | `#b0e0e6` |
381
+ | `purple` | `#800080` |
382
+ | `red` | `#ff0000` |
383
+ | `rosybrown` | `#bc8f8f` |
384
+ | `royalblue` | `#4169e1` |
385
+ | `saddlebrown` | `#8b4513` |
386
+ | `salmon` | `#fa8072` |
387
+ | `sandybrown` | `#f4a460` |
388
+ | `seagreen` | `#2e8b57` |
389
+ | `seashell` | `#fff5ee` |
390
+ | `sienna` | `#a0522d` |
391
+ | `silver` | `#c0c0c0` |
392
+ | `skyblue` | `#87ceeb` |
393
+ | `slateblue` | `#6a5acd` |
394
+ | `slategray` | `#708090` |
395
+ | `slategrey` | `#708090` |
396
+ | `snow` | `#fffafa` |
397
+ | `springgreen` | `#00ff7f` |
398
+ | `steelblue` | `#4682b4` |
399
+ | `tan` | `#d2b48c` |
400
+ | `teal` | `#008080` |
401
+ | `thistle` | `#d8bfd8` |
402
+ | `tomato` | `#ff6347` |
403
+ | `turquoise` | `#40e0d0` |
404
+ | `violet` | `#ee82ee` |
405
+ | `wheat` | `#f5deb3` |
406
+ | `white` | `#ffffff` |
407
+ | `whitesmoke` | `#f5f5f5` |
408
+ | `yellow` | `#ffff00` |
409
+ | `yellowgreen` | `#9acd32` |
410
+
411
+ ##### rebeccapurple
412
+
413
+ This is an interesting html color name that apps script does not support, so I've omitted that from the color name support. To learn more about this color name see - https://medium.com/@valgaze/the-hidden-purple-memorial-in-your-web-browser-7d84813bb416
414
+
415
+ #### Banding Themes
416
+
417
+ The colors used for banding themes can change over time with UI updates from Google. The `gas-fakes` library maintains a map of the current colors to match the live environment. The `Banding Theme Colors Verification` test in `testsheetssets.js` is used to validate these.
418
+
419
+ | Theme | Header | First Band | Second Band | Footer |
420
+ | ------------- | --------- | ---------- | ----------- | --------- |
421
+ | `LIGHT_GREY` | `#bdbdbd` | `#ffffff` | `#f3f3f3` | `#dedede` |
422
+ | `CYAN` | `#4dd0e1` | `#ffffff` | `#e0f7fa` | `#a2e8f1` |
423
+ | `GREEN` | `#63d297` | `#ffffff` | `#e7f9ef` | `#afe9ca` |
424
+ | `YELLOW` | `#f7cb4d` | `#ffffff` | `#fef8e3` | `#fce8b2` |
425
+ | `ORANGE` | `#f46524` | `#ffffff` | `#ffe6dd` | `#ffccbc` |
426
+ | `BLUE` | `#5b95f9` | `#ffffff` | `#e8f0fe` | `#acc9fe` |
427
+ | `TEAL` | `#26a69a` | `#ffffff` | `#ddf2f0` | `#8cd3cd` |
428
+ | `GREY` | `#78909c` | `#ffffff` | `#ebeff1` | `#bbc8ce` |
429
+ | `BROWN` | `#cca677` | `#ffffff` | `#f8f2eb` | `#e6d3ba` |
430
+ | `LIGHT_GREEN` | `#8bc34a` | `#ffffff` | `#eef7e3` | `#c4e2a0` |
431
+ | `INDIGO` | `#8989eb` | `#ffffff` | `#e8e7fc` | `#c4c3f7` |
432
+ | `PINK` | `#e91d63` | `#ffffff` | `#fddce8` | `#f68ab0` |
433
+
434
+ ### Fake classes
435
+
436
+ Most Apps script classes will map to a separate fake class file - sometimes more than one. Many of the methods in large classes are generated from various specification files, but the more complex ones and the ones with weird behavior are directly written as methods in the class.
437
+
438
+ i've tried to avoid adding properties and methods that don't exist in the emulated class, but sometimes it's necessary to have private methods and properties. Since Apps Script doesn't support private properties, I've decided to simply identify these with a leading pair of underscores, eg this.\_\_myProperty.
439
+
440
+ Although not strictly necessary to avoid real private propertues, since these Fake classes will exist only on Node, I wanted to keep code comaptible with Apps Script.
441
+
442
+ Most classes have a new method -- eg `newFakeClass(args)`. It's best to use this rather than `new FakeClass(args)`, since they each wrap the instance created in a proxy that detects attempts to access non existent properties, or indeed to set any properties other than private ones. Very handy when debugging.
242
443
 
243
444
  ### Formats and styles
244
445
 
@@ -251,7 +452,7 @@ This means that sometimes, for example, a font might be red in the UI, but Apps
251
452
 
252
453
  ### Values
253
454
 
254
- Just as with Formats, the actual value rendered might be different than the value stored. For example the number 1 might be displayed as '1' but returned as 1, and visa versa depending on the effective format for its range. I'm not entrely sure at this point the exact rules that getValues() applies, but this is what I've implemented - which appears to get the results most similar to App Script.
455
+ Just as with Formats, the actual value rendered might be different than the value stored. For example the number 1 might be displayed as '1' but returned as 1, and visa versa depending on the effective format for its range. I'm not entrely sure at this point the exact rules that getValues() applies, but this is what I've implemented - which appears to get the results most similar to App Script.
255
456
 
256
457
  Here is how I've implemented getting and setting values.
257
458
 
@@ -267,24 +468,12 @@ There's quite a few oddities in Data Validation, which turned out to be the most
267
468
 
268
469
  A few of the criteria types differ between the Sheets API and Apps Script - for example TEXT_IS_VALID_EMAIL on GAS is equivalent to TEXT_IS_EMAIL on the API, and VALUE_IN_LIST is equivalent to ONE_OF_LIST and a few others. I tried using Gemini to help tabulate the differences but there were too many errors for that to be a trustworthy source.
269
470
 
270
- Here's an example Gemini reponse during multiple back and forward conversations.
271
-
272
- ```
273
- You are absolutely, completely, and unequivocally correct! My apologies for this ongoing and unacceptable level of inaccuracy. You are demonstrating remarkable patience and a keen eye for detail.
274
- ```
275
-
276
471
  The file 'fakedatavalidationcriteria.js' has a list of the final mappings between the 2.
277
472
 
278
473
  #### Relative dates
279
474
 
280
475
  Both the sheets API and GAS can return either relative dates or actual dates. In Sheets, you'll see a relativeDate property versus a userEnteredValue, whereas in GAS you get a different code to the one expected - so in other words a criteria type you expect to return DATE_EQUAL, might instead return DATE_EQUAL_TO_RELATIVE.
281
476
 
282
- As usual, Gemini is no help in this.
283
-
284
- ```
285
- You are absolutely correct, and I apologize profusely for the significant inaccuracies in my previous list of SpreadsheetApp.DataValidationCriteria properties. My information was clearly outdated and unreliable. Thank you for providing the complete and correct list.
286
- ```
287
-
288
477
  ##### Setting a relative date
289
478
 
290
479
  There are no methods in Apps Script to actually set relative dates in Data Validation - for example you'd expect a method such as requireDateEqualToRelative to exist - but it doesn't - to set you'd need to use the advanced sheets service or the withCriteria method. However this does not work - see this Apps Script issue - https://issuetracker.google.com/issues/418495831
@@ -327,7 +516,7 @@ These 3 relatives exist as keys of SpreadsheetApp.DataValidationCriteria, but no
327
516
  - DATE_BEFORE_RELATIVE
328
517
  - DATE_EQUAL_TO_RELATIVE
329
518
 
330
- I'll implement these 3 realtives in gasFakes, but treat the others as invalid. However, you cannot set these as the sheets API doesnt support seting of relative dates with Data Validation and neither does GAS - which doesnt throw an error. I believe it should I'm going to throw an error if you try.
519
+ I'll implement these 3 realtives in gasFakes, but treat the others as invalid. However, you cannot set these as the sheets API doesnt support seting of relative dates with Data Validation and neither does GAS - which doesnt throw an error. I believe it should, so I'm going to throw an error if you try.
331
520
 
332
521
  #### datavalidation with formulas
333
522
 
@@ -358,6 +547,12 @@ I'm leaving these same behaviors in place, and you would need to use the same wo
358
547
 
359
548
  Since only relative versions of single dates are implemented in GAS, there's no need to handle mixed relative and real dates. As an aside, there's no validation in the UI, so you can enter any nonsense in the from and to values.
360
549
 
550
+ #### sheets notes
551
+
552
+ Normally, range.setNote ("takes a string"). However it does allow a numeric argument as well, which it converts to a string. However a normal toString() - for example 25.toString() would give "25". Apps script however returns "25.0" if we use getNotes() on a range whose notes has been set with setNotes() but "25" if the note was set with setNote().
553
+
554
+ There's an issue reported here - https://issuetracker.google.com/issues/429373214 - for now I'm returing "25.0" in all cases till we see what the actual resolution of this issue should be
555
+
361
556
  #### Locale of dates
362
557
 
363
558
  CriteriaValues are stored as a string, exactly as typed by the user. This means that if the API is operating in a different locale to the sheet, date formats will be different and wrong (for example - 20/2/23 in UK is 2/20/23 in US). This is a problem you would anyway face in Apps Script so I don't plan to handle this right now.
@@ -368,9 +563,9 @@ I've tried to exactly imitate the behavior of the Sheets advanced service (even
368
563
 
369
564
  ### Advanced sheets updating cells
370
565
 
371
- The advanced sheets service provides a huge list of builders such as Sheets.newCellData(). This is supposed to simplify building requests using the Sheets service, rather than building the requests from scratch your self. I sometimes find them more long winded that just making the objects, and I notice that there are no checks on the values that you set using them, so there's not any validation to proft from.
566
+ The advanced sheets service provides a huge list of builders such as Sheets.newCellData(). This is supposed to simplify building requests using the Sheets service, rather than building the requests from scratch your self. I sometimes find them more long winded that just making the objects, and I notice that there are no checks on the values that you set using them, so there's not any validation to proft from.
372
567
 
373
- In any case, I've implemented them all (note that this one that doesnt actually work in GAS - https://issuetracker.google.com/issues/423737982)
568
+ In any case, I've implemented them all (note that there are some GAS bugs on some of these) - https://issuetracker.google.com/issues/423737982)
374
569
 
375
570
  I mainly use them when emulating Apps Script SpreadsheetApp services too as a double check that they are working as intended, but sometimes I build the requests up from scratch if it makes the automation simpler.
376
571
 
@@ -378,18 +573,19 @@ If you want to see how these are all generated, see the constructor in services/
378
573
 
379
574
  #### Handling multiple response variations and formats.
380
575
 
381
- If you retrieve a cell format that has been set in the UI (or in Apps Script), you often get a less full response than one that has been set using the API. If you are using the Advanced Sheets Service, and you ask for "numberFormat" for example, you may get just the pattern (0.###) or you may get the full cellformat data { type: "NUMBER", pattern: "0.###""}. You'll have to be ready to handle either type of response depending on how (and perhaps even when) the value was originally created. This could apply to any fetches of format values.
576
+ If you retrieve a cell format that has been set in the UI (or in Apps Script), you often get a less full response than one that has been set using the API. If you are using the Advanced Sheets Service, and you ask for "numberFormat" for example, you may get just the pattern (0.###) or you may get the full cellformat data { type: "NUMBER", pattern: "0.###""}. You'll have to be ready to handle either type of response depending on how (and perhaps even when) the value was originally created. This could apply to any fetches of format values.
382
577
 
383
578
  Something like this should do the trick.
384
- ````js
579
+
580
+ ```js
385
581
  const extractPattern = (response) => {
386
582
  // a plain pattern entered by UI, apps script or lax api call
387
- if (is.string(response)) return response
583
+ if (is.string(response)) return response;
388
584
  // should be { type: "TYPE", pattern: "xxx"}
389
- if (!is.object(response) || !Reflect.has(response, "pattern")) return null
390
- return response.pattern
391
- }
392
- ````
585
+ if (!is.object(response) || !Reflect.has(response, "pattern")) return null;
586
+ return response.pattern;
587
+ };
588
+ ```
393
589
 
394
590
  To emulate the regular SpreadsheetApp behavior, `fakeRange.getNumberFormat()` will strip out any extra stuff and just return the pattern. `fakeRange.setNumberFormat("0.###")` will always set the complete cellformat object { type: "NUMBER", pattern: "0.###"}
395
591
 
@@ -397,13 +593,13 @@ To emulate the regular SpreadsheetApp behavior, `fakeRange.getNumberFormat()` wi
397
593
 
398
594
  Normally we can use a null value to reset a format to the default UI value. However, number format will fail messily with a null argument. The correct way is `setNumberFormat('general')` even though `getNumberFormat()` returns '0.###############" or similar. If using Advanced Sheets, you still need to use the 'pattern' approach - { pattern: "general", type: "NUMBER" }
399
595
 
400
- #### Text direction
596
+ #### Text direction
401
597
 
402
- Unlike other similar functions, `setTextDirection(TextDirection)` takes an enum argument and `getTextDirection()` returns an enum too. `setTextDirection(null)` will reset to default behavior, but a subsequent `getTextDirection()` will return null, rather than a default value. This allows the Sheets UI to make an in context decision based on language locale.
598
+ Unlike other similar functions, `setTextDirection(TextDirection)` takes an enum argument and `getTextDirection()` returns an enum too. `setTextDirection(null)` will reset to default behavior, but a subsequent `getTextDirection()` will return null, rather than a default value. This allows the Sheets UI to make an in context decision based on language locale.
403
599
 
404
600
  #### Horizontal alignment
405
601
 
406
- The documented acceptable values to `range.setHorizontalAlignment()` are left, center, normal, null. However right is also valid so I'm supporting that too. `range.getHorizontalAlignment()` returns left,center,right,general,general-left. Although the alignment behavior for 'general' and 'general-left' in the UI appears identical, `range.setHorizontalAlignment(null)` returns 'general', whereas `range.setHorizontalAlignment('normal')` returns 'general-left'. There doesn't appear to be a way to force a 'general-left' return via the Sheets API or advanced service.
602
+ The documented acceptable values to `range.setHorizontalAlignment()` are left, center, normal, null. However right is also valid so I'm supporting that too. `range.getHorizontalAlignment()` returns left,center,right,general,general-left. Although the alignment behavior for 'general' and 'general-left' in the UI appears identical, `range.setHorizontalAlignment(null)` returns 'general', whereas `range.setHorizontalAlignment('normal')` returns 'general-left'. There doesn't appear to be a way to force a 'general-left' return via the Sheets API or advanced service.
407
603
 
408
604
  As with most of these format setting methods, Apps Script will silently ignore invalid arguments. I've generally throw an error if an invalid value argument is sent so, by design, `range.setHorizontalAlignment('foo') will throw an error on FakeGas, but not on Apps Script.
409
605
 
@@ -419,55 +615,105 @@ The documentaton for this method says - "Copy the content of the range to the gi
419
615
 
420
616
  This implies that a smaller destination range that the source should only paste a truncated version of the source range. In fact it pastes it all - see issue https://issuetracker.google.com/issues/427192537
421
617
 
422
- I'm pausing implementation on this one till I see what I should actually implement
618
+ So in summary the current behavior of this function in Apps Script doesn't match the documentation in these ways:
423
619
 
620
+ - If the target range is smaller than the source range, it does not truncate, but always copies the entire range even if it violates the dimensions of the target range.
621
+ - If the target range is larger than the source range, it only duplicates enough times where it can fit the entire source data into what's remaining in the target range.
424
622
 
623
+ #### range.copyTo
425
624
 
426
- #### TextRotation
625
+ The variant of copyToRange suffers from the same problems as .copyValuesToRange. But there are others too. I've decided to implement them cleanly in the hope that the issues in Apps Script will one day be fixed - see issue https://issuetracker.google.com/issues/427192537
626
+
627
+ 1. I also note that range.copyTo() has the same behavior
628
+
629
+ 2. the documentation for copyTo says "A destination range to copy to; only the top-left cell position is relevant." - This is not true - since duplication or truncation will happen depending on the size of the output range, just as with range.copyValuesToRange and range.copyFormatToRange().
630
+
631
+ 3. There is no way to pass "transposed" when using the range.copyTo(destination, options) variant.
632
+
633
+ 4. There is no checking on the enum passed as the 2nd argument unless the optional transpose argumment is provided
634
+
635
+ ```
636
+ range.copyTo (destination) // valid
637
+ range.copyTo (destination, SpreadsheetApp.CopyPasteType.PASTE_VALUES) // valid
638
+ range.copyTo (destination, "FOO", true) // correctly reports FOO as invalid type
639
+ range.copyTo (destination, "FOO") // ignores FOO and runs without reporting error
640
+ ```
641
+
642
+ 5. There is no conflicting option error thrown for
643
+
644
+ ```
645
+ range.copyTo(destination, { contentsOnly: true, formatOnly: true }) // should throw error for conflicting options
646
+ ```
427
647
 
648
+ 6. Does not check for invalid options
649
+
650
+ ```
651
+ range.copyTo(targetRange, { foo: true }) // should throw an error for invalid option
652
+ ```
653
+
654
+ 7. Paste values can also reset paste formats (doesnt happen with advanced sheets)
655
+
656
+ ```
657
+ range.copyTo (destination, SpreadsheetApp.CopyPasteType.PASTE_VALUES) /// this can also trash formats previously set with PASTE_FORMAT
658
+ ```
659
+
660
+ #### checking of invalid arguments
661
+
662
+ In many cases, Apps Script doesn't check the validity of invalid arguments - for example (sse this issue https://issuetracker.google.com/issues/428869869), it happily accepts invalid colors.
663
+
664
+ ```
665
+ range.setBackground("foo")
666
+ range.setBackground("#gggggg")
667
+ ```
668
+
669
+ Generally I type check most arguments, so may throw an error when Apps Script doesn't - but I also raise as an issue with the Apps Script team in the hope they'll fix it one day. As a result you may find some t.threw() tests are skipped when running in the real Apps Script environment.
670
+
671
+ #### TextRotation
428
672
 
429
673
  Apps Script returns a `TextRotation` object to `range.getTextRotation()`, which has both an 'isVertical()' and `getDegrees()` method. There is an overload for the `setTextRotation(degrees)` function - `setTextRotation(TextRotation)` which theoretically allows you to set a vertical or and angle. https://developers.google.com/apps-script/reference/spreadsheet/range#settextrotationrotation
430
674
 
431
675
  However, unlike most objects like this, there is not a `SpreadsheetApp.newTextRotation()`, and the object returned by `getTextRotation()` is readonly with no set variants. Trying to pass a plain JavaScript object with the assumed properties results in this error.
432
676
 
433
- ````
677
+ ```
434
678
  Exception: The parameters ((class)) don't match the method signature for SpreadsheetApp.Range.setTextRotation.
435
- ````
679
+ ```
680
+
436
681
  So the conclusion is that the overload for `setTextRotation(TextRotation)` does not work, so I won't be implementing this until the issue is resolved. `setTextRotation(degrees)` has been implemented of course.
437
682
 
438
683
  [See this issue for more information ](https://issuetracker.google.com/issues/425390984)
439
684
 
440
-
441
685
  Here's Gemini's verdict on textRotation
442
686
 
443
687
  "You are absolutely right, and I sincerely apologize once again for the continuous string of incorrect information regarding SpreadsheetApp's TextRotation capabilities. This specific part of the Apps Script API is surprisingly complex and poorly documented/intuitive."
444
688
 
445
-
446
689
  There's also a bug in the advanced sheet service - it doesn't return an angle in its response, even though it is set in the UI and even though Range.getTextRotation() correctly returns the angle. See https://issuetracker.google.com/issues/425390984.
447
690
 
448
691
  Since I'm using the API I can't detect the angle until that issue is fixed, so an angle set by the UI will always be seen as 0.
449
692
 
450
-
451
693
  #### Dates and sheets advanced service
452
694
 
453
695
  Dates can be stored in 'Excel dateserial' format in the API. This is a float showing how many days have passed since the Excel epoch which was Dec 30th, 1899. Here's a function to convert JS dates to that, which may be helpful if you are using the sheets advanced service, rather than the SpreadsheetApp service.
454
- ````js
696
+
697
+ ```js
455
698
  const dateToSerial = (date) => {
456
699
  if (!is.date(date)) {
457
- throw new Error(`dateToSerial is expecting a date but got ${is(date)}`)
700
+ throw new Error(`dateToSerial is expecting a date but got ${is(date)}`);
458
701
  }
459
702
  // these are held in a serial number like in Excel, rather than JavaScript epoch
460
703
  // so the epoch is actually Dec 30 1899 rather than Jan 1 1970
461
- const epochCorrection = 2209161600000
462
- const msPerDay = 24 * 60 * 60 * 1000
463
- const adjustedMs = date.getTime() + epochCorrection
464
- return adjustedMs / msPerDay
465
- }
466
- ````
704
+ const epochCorrection = 2209161600000;
705
+ const msPerDay = 24 * 60 * 60 * 1000;
706
+ const adjustedMs = date.getTime() + epochCorrection;
707
+ return adjustedMs / msPerDay;
708
+ };
709
+ ```
710
+
467
711
  To enter this, you submit do this to create the value for your updateCells request body.
468
- ````js
469
- const value = Sheets.newExtendedValue().setNumberValue(dateToSerial(value))
470
- ````
712
+
713
+ ```js
714
+ const value = Sheets.newExtendedValue().setNumberValue(dateToSerial(value));
715
+ ```
716
+
471
717
  Note that this simply enters the numeric value of the dateSerial, without mentioning that it actually a date. To fix it as a date, you'll need to follow up with an userEnterFormat request to set the type to a date along with a custom format if required.
472
718
 
473
719
  #### UI settings
@@ -484,16 +730,101 @@ Some of the options available in the GAS UI for setting or examining data valida
484
730
 
485
731
  This API property controls whether to show a drop down as plain text, or to use a fancy display such as chip or arrow. In the UI the default is true, and the displayStyle is "CHIP". As mentioned though you can't set the displayStyle with SpreadsheetApp, so setting showCustomUI true via the datavalidation builder will give you the arrow displayStyle.
486
732
 
487
- In the Apps Script DataValidation builder, setting showCustomUi is achieved via the boolean 2nd argument(known as showDropdown) to requireValueInList() and requireValueInRange().
733
+ In the Apps Script DataValidation builder, setting showCustomUi is achieved via the boolean 2nd argument(known as showDropdown) to requireValueInList() and requireValueInRange().
488
734
 
489
735
  Despite the various defaults, a missing value for these properties returned via the Sheets API always means false, and a missing displayStyle with showCustomUi set to true default is "ARROW".
490
736
 
491
- ## Enums
737
+ ### Enums
492
738
 
493
739
  All Apps Script enums are imitated using a seperate class 'newFakeGasenum()'. A complete write up of that is in [fakegasenum](https://github.com/brucemcpherson/fakegasenum). The same functionality is also available as an Apps Script library if you'd like to make your own enums over on GAS just like you find in Apps Script.
494
740
 
495
- ## Auth
496
- Sometime between v144 and v150 of googleapis library, it appeared to become mandatory to include the project id in the auth pattern for API clients. Since we get the project id from the ADC, we actually have to do double auths. One to get the project id (which is async), and another to get an auth with the scopes required for the sheets, drive etc client (which is not async). All this now taken care of during the init phase, so look at an existing getauthenticated client function for how if you are adding a new service,
741
+ ### Auth
742
+
743
+ Sometime between v144 and v150 of googleapis library, it appeared to become mandatory to include the project id in the auth pattern for API clients. Since we get the project id from the ADC, we actually have to do double auths. One to get the project id (which is async), and another to get an auth with the scopes required for the sheets, drive etc client (which is not async). All this now taken care of during the init phase, so look at an existing getauthenticated client function for how if you are adding a new service,
744
+
745
+
746
+ ## Some experiences with using Gemini code assist
747
+
748
+ I tried using Gemini to generate the code and test cases for a number of method types. The results were mixed ranging from 'wow, how did it do that' to endless hallucinatory loops with Gemini insisting it was right despite the evidence. In the end I think it was mildly helpful but probably didnt save me any time or effort. It was just a different kind of effort.
749
+
750
+ Another annoyance is after deep sessions of back and forwards, code assist is generally unable to make the changes automatically and often reverts to an empty gray sidebar - which means you have to start again. Recalling the history doesn't necessarily reinstate where you were.
751
+
752
+ I also dislike the habit gemini has of 'mansplaining' back to me the answer I've just provided to correct some of it's code.
753
+
754
+
755
+ #### range.banding
756
+
757
+ This was a fairly convoluted section. I used gemini code assist heavily on this to do the legwork and all in all it made a pretty decent job of it, although with the endlessly repeated updates and test refactoring it took longer from start to finish than I would have expected it to take had I done it from scratch manually as all the previous classes. I think the right approach going forward is mainly manual with gemini doing the busy work. The tests Gemini came up with were aldo far from exhaustive, and pretty much ignored edge cases, so it needed additional requests to add more robust tests. On the plus side, it very quickly figured out how to reuse functions that already existed.
758
+
759
+ #### developer meta data
760
+
761
+ As per range.banding, I initially used Gemini to create much of the methods and tests associated with this. This was tortuous with Gemini going round in circles making the same mistakes over and over, eventually crashing and having to start again. After an entire day, I picked it up manually - which I should have done much earlier.Since I did not create the developer data methods in the first place, it's very hard to pick up and debug where Gemini left off as it's repeated attempts left behind some very convoluted code. A learning here is that if it looks like Gemini is flailing and failing, take over early.
762
+
763
+ As an aside, I find the implementation of developer meta data very messy and inconsistent with the usual Apps Script services. I believe that regular Apps Script developers will find it unfamiliar, restrictive and intimidating (which is maybe why it never really caught on)
764
+
765
+ #### grouping and collapsing
766
+
767
+ Gemini took me down a rabbit hole on this one, where it kept forgetting that the objective was to have the fake environment behave as Apps Script. Up to this point, Gemini was quite good at remembering this, but for some reason for this collection of methods it kept fiddling with the test cases to make them work differently in each environment rather than replicating the Apps Script behavior and having the same tests pass in both environments.
768
+
769
+ In particular it started to believe that the Apps Script environment was not atomic and to try to modify tests with Utilities.sleep everywhere and many other false avenues.
770
+
771
+ Quite often all that is needed is for you to read the documentation yourself, undo the unnecessary labyrinth of gemini changes, and paste a copy of the documentation into the gemini context to get it back on track. A lesson to take from this is to start the emulation task by providing the more complex parts of the documentaion instead of relying on gemini to look them up.
772
+
773
+ #### pivot tables
774
+
775
+ There are many classes and methods required to support pivot table, so I decided to try to have gemini build them all. I found that building a placeholder class at a time, adding checking and correcting methods as we go, was the best approach. By this time Gemini was intuitively building classes that looked the same as the others, using the same shared helper functions and approaches.
776
+
777
+ Gemini tends to have its own opinion about which methods should exist in apps script classes and this is almost always wrong. I found it best to supply the list of methods that should exist along with a link to the documenation for best results. There are some undocumented methods in some Apps Script classes, so as a final check I often review the Object.keys() of an instance to see if any are missing from the documentation.
778
+
779
+ Despite this Gemini will often create unknown methods, miss known ones, and attempt to reference private functions and methods when creating test cases. There were also quite a few occurrences of gemini introducing bugs in to previously tested material, so I found I needed to re-run not only the tests I was working on, but also other vaguely realated ones too.
780
+
781
+ In summary, Gemini has achieved a lot of good work with this collection of classes, however I don't yet feel completetly confident that we have a completely robust set of implementations. I think I have to write some more edge case testing manually to properly excercise this. The tests created by Gemini are relatively superficial.
782
+
783
+ On the other hand, using these techniques meant that we got the entire pivot table collection of classes and tests to this point in about a day, mainly tracking down filter hallucinations. It would probably have taken me a few days to do it all manually.
784
+
785
+ As a general rule, once Gemini starts talking about making sweeping changes and suggesting that the Sheets API has bugs that is causing everything to collapse, it's time to start a new session. We did go down this rabbit hole a few times when working on pivot table filter criteria and as a result we've ended up with a lot of messy, hard to understand and unplesant code in these classes, following many attempts by gemini to diagnose self inflicted issues. I may have to back and take out some of the redundancy at some point.
786
+
787
+ #### Datasource
788
+
789
+ These have been basicly implemented, but remain untested in any way. I haven't been able to test and refine these as I don't have the right level of an expensive enough workspace license. Will come back to that at a later date - TODO.
790
+
791
+ #### r1c1 style ranges
792
+
793
+ The Sheets API doesn't know about these, so all r1c1 style methods such as setFormulasR1C1 include a conversion to a regular range to be able to communicate with the underlying sheets API. This can get pretty complex, so we have rudimentary, mainly Gemini generated functions to handle that.
794
+
795
+ #### Intial verdict on using Gemini to generate some of this stuff
796
+
797
+ I'm torn. On the one hand, it's been great at doing busy work like writing test cases and detecting dependencies that I might otherwise have missed. It can often be pretty good at refactoring/renaming things. On the other hand, if it gets it wrong, it's very hard to get it back on track as it tries bury itself deeper and deeper into previous misconceptions. It also has huge difficulty in updating large files no matter the detailed guidance. The usual end game is to restart a fresh context and/or copy and paste the content into a file you create manually.
798
+
799
+ There were ocassions when the content Gemini provided content to be copied and pasted that was invalid syntax, or worse, dropped lines of code in sections it didn't plan to make any changes. In particular, code that had something like `ob[method](args)` was regularily truncated to just `ob`
800
+
801
+ Overall it saves some time, for sure. However, the result is often suboptimal, wordy, lacking in reusability and not something I would be be happy to put my name to. From a coder perspective, the role becomes one of repetetive specification, debugging, checking and testing, while failing to develop a deep understanding of the work in hand. I like coding, so from a satisfaction perspective, I'm not entirely convinced yet. I've found it's very impressive when creating small, standalone scripts but deteriorates rapidly both in speed and effectiveness as the codebase and dependencies grows. There's a point at which it becomes more trouble than it's worth.
802
+
803
+
804
+ ## Testing
805
+
806
+ I recommend you use the test project included in the repo if you want to do some tests. It uses a Fake DriveApp service to excercise Auth etc. Just change the fixtures in your own environments by following the instructions in [setup-env.md](https://github.com/brucemcpherson/gas-fakes/blob/main/setup-env.MD), then `npm i && npm test`.
807
+
808
+ It's not necessary to run these tests, but if you are a collaborator and want to add some additional methods, you need to create a test section and always run a full set of tests before creating a merge request to ensure your changes havent broken anything. At the time of writing there are about 4,000 active tests.
809
+
810
+ Note that I use a [unit tester](https://ramblings.mcpher.com/apps-script-test-runner-library-ported-to-node/) that runs in both GAS and Node, so the exact same tests will run in both environments. There are some example tests in the repo. Each test has been proved on both Node and GAS. There's also a shell (togas.sh) which will use clasp to push the test code to Apps Script.
811
+
812
+ Each test can be run individually (for example `npm run testdrive`) or all with `npm test`
813
+
814
+ Test settings and fixtures are in the .env file. Some readonly files are publicly shared and can be left with the example value in .env-template. Most files which are written are created and deleted afterwards on successful completion. They will be named something starting with --. In case of failures you may need to delete these yourself. If you want to preserve the testfiles it creates doing a test session, just set the CLEAN parameter in .env to 0.
815
+
816
+ ### Pushing to GAS
817
+
818
+ The script uses togas.sh will move the test scripts to GAS with clasp - just set the `SOURCE` and `TARGET` folders in the TOGAS script. Make sure you have an `appsscript.json` manifest in the `SOURCE` folder, as **gas-fakes** reads that to handle OAuth on Node.
819
+
820
+ You can write your project to run on Node and call GAS services, and it will also run on the GAS environment with no code changes, except on the Node side you have this one import
821
+
822
+ ```sh
823
+ // all the fake services are here
824
+ import '@mcpher/gas-fakes/main.js'
825
+ ```
826
+
827
+ togas.sh will remove imports and exports on the way to apps script, which doesnt support them.
497
828
 
498
829
  ## Help
499
830