• Stars
    star
    107
  • Rank 323,587 (Top 7 %)
  • Language
    TypeScript
  • Created over 5 years ago
  • Updated 2 months ago

Reviews

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

Repository Details

Cloud Firestore support library for admin. 🧒

ballcap for TypeScript

Ballcap is a database schema design framework for Cloud Firestore. This repository supports the WEB and Admin.

Why Ballcap

Cloud Firestore is a great schema-less and flexible database that can handle data. However, its flexibility can create many bugs in development. Ballcap can assign schemas to Cloud Firestore to visualize data structures. This plays a very important role when developing as a team.

export class User extends Doc {
	@Field name?: string
	@Field thumbnailImage?: File
	@SubCollection items: Collection<Item> = new Collection()
}

Installation

Web

npm add @1amageek/ballcap

Admin(node.js)

npm add @1amageek/ballcap-admin

Get Started

Expo

Create your first project

expo init new-project
cd my-new-project
npm add firebase @1amageek/ballcap

Edit tsconfig.json

{
  "compilerOptions": {
    "noEmit": true,
    "target": "esnext",
    "module": "commonjs",
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "lib": ["dom", "esnext"],
    "jsx": "react-native",
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "skipLibCheck": true
  }
}

Firebase and Ballcap initialize

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import * as firebase from 'firebase'
import '@firebase/firestore'
import * as Ballcap from '@1amageek/ballcap'

const config = { ... }  // apiKey, authDomain, etc. (see above)
const app = firebase.initializeApp(config)
Ballcap.initialize(app)

React

Create your first project

npx create-react-app my-new-project
cd my-new-project
npm add firebase @1amageek/ballcap ts-loader
react-scripts eject

Edit webpack.config.js

https://gist.github.com/1amageek/184a6054f00f1a722d37f7b4cba406a0

Edit tsconfig.json

{
  "compilerOptions": {
    "target": "es2015",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "experimentalDecorators": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "react"
  },
  "include": [
    "src"
  ]
}

Usage

Initialize

To use Ballcap, you need to initialize it.

Ballcap.initialize(app.firestore())

RootReference

Considering the extensibility of DB, it is recommended to provide a method of version control.

Ballcap.initialize(app.firestore(), app.firestore().collection("version").doc("1"))

CRUD

Document

// autoID
const user: User = new User()

// with ID
const user: User = new User("ID")

// with DocumentReference
const user: User = new User(firestore.doc("a/a"))

// save
await user.save()

// update
await user.upate()

// delete
await user.delete()

Get JSON

const data = user.data()

Batch

const user: User = new User()
const batch: Batch = new Batch()

batch.save(user)
await batch.commit()

Retrive document

// with id
const user?: User = await User.get("id")

// with DocumentReference
const user?: User = await User.get(firestore.doc("a/a"))
Convert from DocumentSnapshot
const user: User = User.fromSnapshot(documentSnapshot)

Field

Use Field to represent a field in a document. A Field can have another Document. In that case, use the @Codable decorator.

export class Address extends Model {
  @Field postCode?: string
  @Field country?: string
}

export class Shipping extends Doc {
  @Codable(Address)
  @Field address?: Address
  @Field phone?: string
}

export class User extends Doc {
  @Field name?: string
  @Field thumbnailImage?: File
  @Codable(Address)
  @Field address: Address[] = []
  @Codable(Shipping, true)
  @Field shipping?: Shipping
}

Codable

A Document in Ballcap can have nested Documents and Models. Use Cadable to provide type to Ballcap

@Codable(Address)
@Field address: Address[] = []

If the nested object is a Document, it can have the following structure because the Document contains an ID.

{
  id: "shipping id",
  path: "shipping path",
  data: {
    // shipping data
  }
}

If you want to keep the structure, set the second argument to Codable to true. By default, it is false. If false, only the data is retained.

@Codable(Shipping, true)
@Field shipping?: Shipping

SubCollecion

Use SubCollection and Collection to represent SubCollection.

class Charge extends Doc {
  @Field amount: number = 0
  @Field userID!: string
}
class User extends Doc {
  @SubCollection charges: Collection<Charge> = new Collection()
}

Test

Admin

cd web
jest

Web

firebase setup:emulators:firestore
firebase serve --only firestore
cd web
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

pring.ts

Cloud Firestore model framework for TypeScript - Google
TypeScript
109
star
9

Demae

TypeScript
77
star
10

Router

Router is a library that assists with SwiftUI view transitions.
Swift
74
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

FirebaseAdmin

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

pring-admin.ts

Cloud Firestore model framework for TypeScript - Google
TypeScript
13
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

CalendarUI

Swift
5
star
33

PaperKit-Camera

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

StripeAPI

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

FirestoreSwift

Swift
4
star
36

CameraUI

Swift
4
star
37

FirebaseAPI

Lightweight Cloud Firestore Client API using googleapis gRPC.
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

ReactionToolbar

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

Tradable

Swift
2
star
45

flow.ts

Flow enables coding of structured scripts.
JavaScript
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