{"id":20926114,"url":"https://github.com/starhoshi/tart","last_synced_at":"2026-03-05T21:06:16.606Z","repository":{"id":54906452,"uuid":"123527683","full_name":"starhoshi/tart","owner":"starhoshi","description":"A thin wrapper for Cloud Functions.","archived":false,"fork":false,"pushed_at":"2021-01-21T13:05:45.000Z","size":157,"stargazers_count":4,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-11T18:46:23.524Z","etag":null,"topics":["cloud-functions","firebase","firestore","npm","tyepscript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/starhoshi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-02T03:53:35.000Z","updated_at":"2020-03-25T05:40:23.000Z","dependencies_parsed_at":"2022-08-14T06:20:14.920Z","dependency_job_id":null,"html_url":"https://github.com/starhoshi/tart","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starhoshi%2Ftart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starhoshi%2Ftart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starhoshi%2Ftart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starhoshi%2Ftart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/starhoshi","download_url":"https://codeload.github.com/starhoshi/tart/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225248915,"owners_count":17444350,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloud-functions","firebase","firestore","npm","tyepscript"],"created_at":"2024-11-18T20:36:54.067Z","updated_at":"2026-03-05T21:06:11.579Z","avatar_url":"https://github.com/starhoshi.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tart\n\n[![npm version](https://badge.fury.io/js/%40star__hoshi%2Ftart.svg)](https://badge.fury.io/js/%40star__hoshi%2Ftart)\n[![Build Status](https://travis-ci.org/starhoshi/tart.svg?branch=master)](https://travis-ci.org/starhoshi/tart)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/4f8b83b6113d4627a57500f993dce372)](https://www.codacy.com/app/kensuke1751/tart?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=starhoshi/tart\u0026amp;utm_campaign=Badge_Grade)\n[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)\n\nTart is a thin wrapper for Cloud Functions.\n\nLet's define the model and write Cloud Functions with TypesScript.\n\n# Sample\n\nYou can write like this.\n\n```ts\nimport * as Tart from '@star__hoshi/tart'\n\nTart.initialize(admin.firestore())\n\ninterface User extends Tart.Timestamps {\n  name: string\n}\n\nexport const updateUser = functions.firestore.document('user/{userId}')\n  .onCreate(async event =\u003e {\n    const user = new Tart.Snapshot\u003cUser\u003e(event.data)\n    console.log(user.data.name) // =\u003e old name\n    console.log(user.ref) // =\u003e DocumentReference\n\n    await user.update({ name: 'new name'})\n    console.log(user.data.name) // =\u003e new name\n\n    return undefined\n})\n```\n\n# Installation\n\n```\nnpm install @star__hoshi/tart --save\nyarn add @star__hoshi/tart\n```\n\n# Usage\n\n## Initialize\n\n```ts\nimport * as Tart from '@star__hoshi/tart'\nimport * as admin from 'firebase-admin'\n\nadmin.initializeApp(\u003cadmin.AppOptions\u003efunctions.config().firebase)\n\n// Tart expects timestampsInSnapshots to be 'true'\nadmin.firestore().settings({ timestampsInSnapshots: true })\n\n// both admin sdk and cloud functions are same interface.\nTart.initialize(admin.firestore())\n```\n\n## Define Interface\n\nYou have to extend `Tart.Timestamps`.\n\n```ts\ninterface User extends Tart.Timestamps {\n  name: string\n}\n\ninterface Game extends Tart.Timestamps {\n  price: string\n}\n```\n\n## Snapshot Type\n\nSnapshot has 2 local variables.\n\n* ref\n    * DocumentReference\n* data\n    * T extends Tart.Timestamps\n\n```ts\nconst user = new Tart.Snapshot\u003cUser\u003e(snapshot)\nconsole.log(user.data) // =\u003e Same as snapshot.data()\nconsole.log(user.ref) // =\u003e Same as snapshot.ref\n```\n\n## Data Management\n\n### Save\n\n```ts\nconst data: User = { name: 'test' }\nconst user = Tart.Snapshot.makeNotSavedSnapshot('user', data)\n\n// Save a document\nawait user.save()\n\n// Batched writes\nconst batch = admin.firestore().batch()\nuser.saveWithBatch(batch)\nawait batch.commit()\n```\n\n### Save Reference Collection\n\n[Reference|Nedted] Collection's description is [here](https://github.com/1amageek/pring#nested-collection--reference-collection).\n\n```ts\nconst user = Tart.Snapshot.makeNotSavedSnapshot\u003cUser\u003e('user', { name: 'test' })\nconst game = Tart.Snapshot.makeNotSavedSnapshot\u003cGame\u003e('game', { price: 1000 })\n\nconst batch = admin.firestore().batch()\nuser.saveWithBatch(batch)\nuser.saveReferenceCollectionWithBatch(batch, 'games', game.ref)\nuser.saveNestedCollectionWithBatch(batch, 'nestedgames', game.ref)\ngame.saveWithBatch(batch)\nawait batch.commit()\n```\n\n### Get\n\nPass path or ref as argument.\n\n```ts\nconst savedUser = await Tart.fetch\u003cUser\u003e('user', 'id')\nconst savedUser = await Tart.fetch\u003cUser\u003e(userDocumentReference)\n```\n\n#### Refresh\n\nReload the data.\n\n```ts\nconst savedUser = await Tart.fetch\u003cUser\u003e(userDocumentReference)\nawait savedUser.refresh()\n```\n\n### Update\n\n```ts\nconst savedUser = await Tart.fetch\u003cUser\u003e('user', 'id')\n\n// Update a document\nawait savedUser.update({ name: 'new name' })\n\n// Batched writes\nsavedUser.saveWithBatch(batch)\nsavedUser.updateWithBatch(batch, { name: 'new name' })\nawait savedUser.commit()\n```\n\n### Delete\n\n```ts\nconst savedUser = await Tart.fetch\u003cUser\u003e('user', 'id')\n\n// Delete a document\nawait savedUser.delete()\n\n// Batched writes\nsavedUser.deleteWithBatch(batch)\nawait savedUser.commit()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstarhoshi%2Ftart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstarhoshi%2Ftart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstarhoshi%2Ftart/lists"}