Google Apps Script as a Backend.
First iteration of the library.
Features:
Google Spreadsheet ORM
Annotate your models and tables with the information about the spreadsheet information, and save/load your entities with one line of code.
import StorageService from 'apps-script-backend/src/storage/StorageService'
import Entity from 'apps-script-backend/src/storage/Entity'
import Table from 'apps-script-backend/src/storage/Table'
import { tableColumns, tableName, tableType } from 'apps-script-backend/src/storage/decorators'
@tableColumns([
['name'],
['age', { type: Number }]
])
class CatEntity extends Entity {
name: string
age: number
}
@tableName('Cats')
@tableType(CatEntity)
class CatsTable extends Table<CatEntity> {
}
let cat = new CatEntity();
cat.name = 'Barsik';
cat.age = 10;
let storage = new StorageService('my_spreadsheet_id');
let table = new CatsTable(storage);
table.upsert(cat);
You can implement your own IStorageService
to support storage other then google spreadsheets
Google Web App HTTP Router
For now, there is an action based routing
import Application from 'apps-script-backend/src/Application';
import { IAction } from 'apps-script-backend/src/Router';
import { sendJson } from 'apps-script-backend/src/helpers/http';
export default <IAction> {
process (request, app: Application) {
const foo = request.parameter.foo;
return { echoFoo: foo };
}
};
import options from './options';
import GetEchoAction from './actions/GetEchoAction';
import Application from 'apps-script-backend/src/Application';
import Router from 'apps-script-backend/src/Router';
let app = new Application({
secure: options.secure,
routes: {
'$get /echo': GetEchoAction
},
spreadsheetId: options.spreadsheetId,
shouldMeaserTimings: options.shouldMeaserTimings,
logLevel: 'warn'
});
function doPost(request) {
return app.process('post', request);
}
function doGet(request) {
return app.process('get', request);
}
Google Mocks
We have created some Google apps script API mocks, so that you can create and test your application even without uploading it to google scripts. See the test
folder.
:copyright: 2017 MIT