gas suite
Six open-source libraries that give Google Apps Script projects the building blocks they otherwise rewrite each time: storage in a spreadsheet, settings, logging, error handling, web routing and locking.
- Google Apps Script
- Google Sheets
- TypeScript
- git subtree
Open source under the MIT licence. Four libraries released, two in testing.
In short
- Problem
- Every Apps Script project rewrites the same plumbing for data, settings, logs, errors and locks, a little differently each time.
- Approach
- Package each piece as its own small library that a project adds with one command and pins to a tagged version.
- Solution
- Six libraries that work alone or together, written in TypeScript and shipped as plain Apps Script files.
At a glance
- libraries in the suite
- 6
- released, with tagged versions
- 4
- in testing, not yet released
- 2
- tagged versions across the four released libraries
- 21
The problem
Google Apps Script projects often start as a small script attached to a spreadsheet. As they grow, each one ends up with its own way of saving rows, keeping settings, writing logs, reporting errors and stopping two runs from overwriting each other.
That code gets rewritten for every project, fixed in one place and not in the others, and the next person to read it has to learn it from scratch.
The solution
The suite is six small libraries, one for each of those jobs, published by Yorsh as open source. Each solves one problem and can be used on its own. A project adds only the ones it needs, and each library keeps its own changelog and tagged versions.
The libraries ship as plain Apps Script files, so a project that uses them needs no build tooling of its own.
| Library | Purpose | Status |
|---|---|---|
gas-sheetdb |
Uses the sheets of a spreadsheet as database tables, with ids, timestamps and locking handled for you. | Released, 1.3.1 |
gas-config |
Settings defined in code and edited in a sheet, with labels, defaults and validation. | Released, 1.2.1 |
gas-logger |
Leveled, structured logging to the execution log and, optionally, to a sheet. | Released, 1.0.2 |
gas-error |
Named errors for expected failures, and one handler that logs them and returns a consistent JSON response. | Released, 1.0.0 |
gas-webapp |
One entry point for web apps, with routes, middleware and a browser client. | In testing |
gas-lock |
Locks that code can request again from inside a lock without waiting on itself. | In testing |
Key features
-
Storage without the spreadsheet plumbing
Rows are read and written as plain objects. New columns are added when a new property appears, every row gets an id and created and updated timestamps, and writes run under a lock. Deleted rows can be restored.
Why it matters: the data stays in a sheet its owner can open and edit, without hand-written range arithmetic in the code.
-
Settings the client can edit
Settings are declared in code with defaults, then appear in a sheet with friendly labels, descriptions and validation. Values are cached in memory after the first read.
Why it matters: non-technical owners can change behaviour without touching the code.
-
Failures that behave predictably
Expected failures, such as invalid input or a missing record, are named errors with a status code. Anything unexpected is logged with its full detail but reaches the user only as a generic server error. The logger writes the same entries to the execution log and, optionally, to a sheet.
Why it matters: users get a clear message, and owners get the detail without it leaking to the browser.
-
One front door for web apps
In testing. A single entry point routes requests through Express-style routes and middleware, with built-in middleware for logging, an authorisation check, rate limiting and delivery acknowledgement.
Why it matters: request handling lives in one table of routes instead of conditionals scattered across the project.
-
Locks that can be nested
In testing. Apps Script locks cannot be requested again by code that already holds them, so a nested request waits until it times out. The library tracks which locks the current run already holds and reuses them.
Why it matters: a function that takes a lock can safely call another that takes the same one, even across libraries.
Under the hood
For technical readers: how the libraries fit together, what they save a project from writing, and how versions reach a project.
Dependencies, code and distribution
How the libraries depend on each other
Only two dependencies are required:
gas-config needs gas-sheetdb, and
gas-webapp needs gas-error. Everything
else is optional and injected. A logger is any object with
info and warn methods, and a lock
service is any object with withLock. Each library
falls back to console or the built-in lock service
when nothing is passed.
| Library | Requires | Optional, injected |
|---|---|---|
gas-sheetdb |
None |
gas-logger, gas-lock
|
gas-config |
gas-sheetdb |
None |
gas-logger |
None | None |
gas-error |
None | gas-logger |
gas-webapp |
gas-error |
gas-logger, gas-lock
|
gas-lock |
None | None |
Before and after
Saving one row without the library means finding the header row, mapping the object onto it and taking a lock by hand. It still has no ids, no timestamps, no handling of new columns and no way to delete and restore.
function addUser(user) {
const lock = LockService.getScriptLock();
lock.waitLock(30000);
try {
const sheet = SpreadsheetApp.getActive().getSheetByName('Users');
const lastCol = sheet.getLastColumn();
const headers = sheet.getRange(1, 1, 1, lastCol).getValues()[0];
sheet.appendRow(headers.map((h) => user[h] ?? ''));
} finally {
lock.releaseLock();
}
}
With gas-sheetdb the same job is three lines, and
the stored entry comes back with its generated fields.
const sheetDb = new GasSheetDb();
const users = sheetDb.table({ sheetName: 'Users' });
users.insert({ name: 'John', role: 'admin' });
Versioning and distribution
Each of the four released libraries has its own release script and follows the same flow.
-
Work happens on git-flow branches. Versions are cut on
release/andhotfix/branches, each with a changelog entry and a version-bump commit, and the release is tagged with its plain version number. -
npm run build:releasechecks formatting, lint and types, compiles the TypeScript to plain global-scope JavaScript with matching type declarations, formats the output, then runs the release script. -
The release script copies only what a consumer needs to a
separate
distbranch with no top-level folder: the compiled files, the README, licence and changelog, and a minimalpackage.json. Type-only files, which compile to empty JavaScript, and internal declarations are left out so they cannot collide with another library's. -
It commits the result as
merge: <version>, tags itdist/<version>and pushes. Thedisthistory is one commit per version, so the 1.3.1 patch togas-sheetdbtouched four files. -
A client project adds a library by pointing
git subtreeat itsdistbranch, as below.
git subtree add \
--prefix=src/lib/gas-sheetdb \
https://github.com/yorsh-co/gas-sheetdb.git \
dist \
--squash
Decisions
- Subtree, not a hosted library. The library's code is copied into the client's own repository, so a project reads, diffs and reviews it like its own code.
-
No build step downstream. Compiled JavaScript
and
.d.tsfiles are published, so a consumer works the same with or without TypeScript. - Optional collaborators are injected. The logger and the lock service are passed in rather than imported, so no library hard-codes another, and reusing a single lock registry across libraries prevents deadlocks.
-
Two branches for web apps.
gas-webapppublishes its server code todistand its browser client todist-web, because a subtree import takes a whole branch. A small installer script adds both, together withgas-errorandgas-logger, in one step.
Links
All six repositories are public on GitHub.
Yorsh is independent and is not affiliated with, endorsed by, or associated with Google LLC.