• Stars
    star
    109
  • Rank 317,187 (Top 7 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 7 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Cloud Firestore model framework for TypeScript - Google

pring.ts

Firebase Cloud Firestore model framework for TypeScript.

Installation โš™

npm install pring --save

Usage

TypeScript

required

  "devDependencies": {
    "@types/node": "^10.9.2",
    "typescript": "^3.0.3"
  },

tsconfig.json

{
  "compilerOptions": {
    "target": "es6",
    "module": "esnext",
    "strict": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "baseUrl": ".",
    "types": [
      "node"
    ],
    "paths": {
      "@/*": [
        "src/*"
      ]
    },
    "lib": [
      "esnext",
      "dom",
      "dom.iterable",
      "scripthost"
    ]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "tests/**/*.ts",
    "tests/**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}

webpack.config.js

const alias = require('pring/webpack-alias')

module.exports = {
  // ...
  resolve: {
    alias
  },
}

Initialize

When using Pring in Vue please include it in main.ts.

For Web

import * as Pring from "pring"
import { config } from "./config"
import firebase from "firebase"
import "firebase/firestore"

const app = firebase.initializeApp(config)
Pring.initialize(app.firestore())

Scheme

  • Please add @property for property declaration.
  • SubCollection can not be optional. Please initialize here.
import * as Pring from "pring"
const property = Pring.property

class Group extends Pring.Base {
    @property name: string
    @property users: NestedCollection<User> = NestedCollection(this)
}

class User extends Pring.Base {
    @property name: string
    @property groups: ReferenceCollection<Group> = ReferenceCollection(this)
}

Manage data

Initialize

// auto generate ID
let user = new User()

// any ID
let user = new User("YOUR_ID")

// any ID, Handle already saved users
let user = new User("YOUR_ID", {})

memo

The developer is responsible for managing the Document being saved. In Pring it is prohibited to save the already saved Document again.

Please use explicitly by the initialization method. new User("YOUR_ID", {}) let user = new User("YOUR_ID")

Save

let user = new User()
user.name = "hoge"
await user.save()

Get

let user: User = await User.get("USER_ID", User)

Update

let user: User = await User.get("USER_ID", User)
user.name = "UPDATE NAME"
await user.update()
let user: User = new User("USER_ID", {})
user.name = "UPDATE NAME"
await user.update()

Delete

let user: User = await User.get("USER_ID", User)
await user.delete()

SubCollection

You can use ReferenceCollection and NestedCollection. The inserted Object is saved simultaneously with the save of the parent.

let user = new User()
let group = new Group()
user.groups.insert(group)
await user.save()

If you insert the parent after it is saved, you need to use await to guarantee the count of SubCollection.

let user = new User()
await user.save()

let group0 = new Group()
let group1 = new Group()
try {
  await user.groups.insert(group0)
  await user.groups.insert(group1)
} catch(error) {
  console.log(error)
}

DataSource

DataSource is a class that controls Collection of Firestore.

export default class Home extends Vue {

  public async addUser() {
    const user: User = new User()
    user.name = "@1amageek"
    await user.save()
  }

  public created() {
    const dataSource = User.query().dataSource(User)
    dataSource.on((snapshot, changes) => {

      switch (changes.type) {
        case "initial": {
          console.log(dataSource.documents)
          break
        }
        case "update": {
          console.log("insert", changes.insertions)
          console.log("change", changes.modifications)
          console.log("delete", changes.deletions)
          break
        }
        case "error": {
          break
        }
      }
    }).listen()
  }
}

Test

https://facebook.github.io/jest/

npm install -g jest
jest

More Repositories

1

Bleu

BLE (Bluetooth LE) for U๐ŸŽ Bleu is the best in the Bluetooth library.
Swift
489
star
2

Toolbar

Awesome autolayout Toolbar. Toolbar is a library for iOS. You can easily create chat InputBar.
Swift
456
star
3

Pring

Cloud Firestore model framework for iOS - Google
Swift
259
star
4

Sumo

Sumo is a library that prepares for fast upload for iOS. It is effective when uploading by selecting images continuously.
Swift
241
star
5

Ballcap-iOS

Firebase Cloud Firestore support library for iOS. ๐Ÿงข
Swift
228
star
6

Salada

Firebase model framework Salada. Salada is the best Firebase framework.
Swift
225
star
7

PaperKit

PaperKit is like Paper app of Facebook
Objective-C
155
star
8

ballcap.ts

Cloud Firestore support library for admin. ๐Ÿงข
TypeScript
107
star
9

Demae

TypeScript
77
star
10

Router

Router is a library that assists with SwiftUI view transitions.
Swift
73
star
11

AssemblyLine

AssemblyLine is a library for easily writing workflows.
Swift
40
star
12

Injectable

Dependency Injection for Swift
Ruby
31
star
13

Deck

Deck is a library that provides a UI to reproduce stacked cards for SwiftUI.
Swift
25
star
14

Muni

Chat with Cloud Firestore
Swift
23
star
15

TimeRangePicker

Swift
21
star
16

firestore-commerce

firestore-commerce is a framework that links Firestore and Stripe. By manipulating the Ballcap data model, you can sell immediately.
TypeScript
16
star
17

pring-admin.ts

Cloud Firestore model framework for TypeScript - Google
TypeScript
13
star
18

FirebaseAdmin

Firebase admin for Swift is a Swift package that provides a simple interface to interact with the Firebase admin SDK.
Swift
12
star
19

schedule.ts

TypeScript
9
star
20

SwiftWebUI-WASM-CFs

JavaScript
9
star
21

Messagestore

Swift
8
star
22

DocumentID

FirebaseFirestoreSwift's library for lightweight use of DocumentIDs in SwiftUI.
Swift
8
star
23

Flow

Swift
8
star
24

jp-zipcode

TypeScript
7
star
25

passkit.ts

Apple Pay, Wallet Development. passkit.ts is a library for issuing pass with typescript.
TypeScript
7
star
26

PickerGroup

Multi-picker for iOS and Mac available in SwiftUI
Swift
6
star
27

scenario

The scenario is the Cloud Functions support library. It is possible to clarify the dependency and limit the side effects.
TypeScript
6
star
28

tradable.ts

tradable.ts is a basic protocol to implement EC in Firebase.
TypeScript
5
star
29

Msg

Msg is a chat library based on FirebaseFirestore.
Swift
5
star
30

AdvancedTableViewSample

Advanced TableView Design Sample
Swift
5
star
31

OnTheKeyboard

Toolbar on the keyboard
Swift
5
star
32

PaperKit-Camera

PaperKit + Camera is a super cool user interface that has integrated the camera to the UI of Paper.
Objective-C
5
star
33

StripeAPI

StripeAPI is a Framework that can handle Stripe type-safely.
Swift
4
star
34

FirestoreSwift

Swift
4
star
35

CameraUI

Swift
4
star
36

FirebaseAPI

Lightweight Cloud Firestore Client API using googleapis gRPC.
Swift
4
star
37

CalendarUI

Swift
4
star
38

classy

classy provides getter / setter to typescript.
TypeScript
3
star
39

vue-pring-sample

Vue + Cloud Firestore +TypeScript
Vue
3
star
40

Antenna

A simple BLE sample code
Swift
3
star
41

Chart

Swift
3
star
42

SaladaSample

Salada sample code. Using Firebase Realtime Database
Swift
3
star
43

flow.ts

Flow enables coding of structured scripts.
JavaScript
2
star
44

ReactionToolbar

ReactionToolbar is the UI, such as the Facebook of Ractions.
Swift
2
star
45

Tradable

Swift
2
star
46

reaf

Host Next.js SSR app on Firebase Cloud Functions with Firebase Hosting redirects. Built with typescript.
TypeScript
2
star
47

ChatUI

Swift
2
star
48

MsgBox

MsgBox can build Chat by linking Firestore and Realm.
Swift
2
star
49

STPScrollView

STPScrollView is a Custom ScrollView
Objective-C
2
star
50

FirebaseInterface

Swift
2
star
51

tradestore.ts

TypeScript
2
star
52

RecurrenceRule

Swift
2
star
53

Socialbase

Socialbase is a framework for building SNS in Cloud Firestore.
Swift
2
star
54

STPPressGestureRecognizer

This is GestureRecognizer for iOS. It works like Force Touch.
Objective-C
2
star
55

ClockFace

Swift
2
star
56

ReactUI

JavaScript
2
star
57

FirebaseDemo

Firebase meetup #4
Ruby
2
star
58

Chat

Swift
1
star
59

MultiListener

Swift
1
star
60

FileSystemNavigator

Swift
1
star
61

SwiftUICell

SwiftUICell runs SwiftUI as CollectionView Cell
Swift
1
star
62

EventStack

Swift
1
star
63

Tong

Tong is library for using ElasticSearch with Swift.
Swift
1
star
64

Timeline

Swift
1
star
65

Calendar

Swift
1
star
66

Paym

Swift
1
star
67

document-propagator.ts

TypeScript
1
star
68

dressing

Dressing provides the functionality of CloudFunctions to connect Firebase and ElasticSearch. You need to use Salada for clients.
JavaScript
1
star
69

PHFetchedResultsController

A fetchedResultsController for PhotoKit. It can be divided into sections by date PhotoKit
Objective-C
1
star
70

NSMutableURLRequestMultipart

NSMutableURLRequestMultipart is a category of NSMutableURLRequest for sending a simple POST request.
Objective-C
1
star