Generator of Firestore rules and type safe client code.

Overview
Rust CI

Generator of Firestore rules and type safe client code.


Usage [WIP]

Install from npm or curl.

$ npm install -g firegen

Setting your yml.

# firegen.yml
schemaPath: ./schema/**/**.fireSchema
export:
  rulesPath: ./generated/firestore.rules
  clientCodePath: ./generated/firestoreClient.ts

Create firestore schema files.

// User.fireSchema

/**
 * definition schema
 */
Document User {
  username: Text
  mail?: Text
  age: Int
  todos: Todo
}
/**
 * [WIP] Rules schema
 */
//ex1
Document Todo rules TodoRules {
  id: Int
  description: Text
  memo?: Text
}
Rule TodoRules {
 get: request.auth != null
 list: true
 create: request.auth.uid == userKey
 update: request.auth.uid == userKey
 delete: false
}

//ex2 normalization rules
Document Todo rules AllowReadOnlyLoginUser & AllowWriteOriginalUser {
  id: number
  description: string
  memo?: string
}
Rule AllowReadOnlyLoginUser {
  get: request.auth != null
  list: request.auth != null
}
Rule AllowWriteOriginalUser {
  create: request.auth.uid == userId
  update: request.auth.uid == userId
  delete: request.auth.uid == userId
}

Run command to generate files.

$ firegen generate

exort as

// types
export interface User {
  id: number
  username: string
  mail?: string
  age: number
  todos: Todo[]
}
export interface UserCreateInput {
  username: string
  mail?: string
  age: number
  todos: Todo[]
}
export interface UserUpdateInput {
  username?: string
  mail?: string
  age?: number
}
export interface Todo {
  id: number
  description: string
  memo?: string
  createdAt?: string
  isDone: boolean
}
export interface TodoCreateInput {
  description: string
  memo?: string
  createdAt?: string
  isDone: boolean
}
export interface TodoUpdateInput {
  description: string
  memo?: string
  createdAt?: string
  isDone: boolean
}
// client code
import firebase from "firebase"
const db = firebase.firestore()
export const firestoreClient = {
  getUsers: async (): Promise<User[]> =>
    await db.collection('users').get(),

  getUser: async (id: number): Promise<User> =>
    await db.collection('users').doc(id).get(),

  createUser: async (input: UserCreateInput) =>
    await db.collection('users').add(input),

  updateUser: async (userId: number, input: UserUpdateInput) =>
    await db.collection('users').doc(userId).update(input),

  deleteUser: async (id: number) =>
    await db.collection('users').doc(id).delete(),

  getTodosByUser: async (id: number): Promise<Todo[]> =>
    await db.collection('users').doc(id).collection('todos').get(),

  getTodoByUser: async (userId: number, todoId: number): Promise<Todo> =>
    await db.collection('users').doc(userId).collection('todos').doc(todoId).get(),

  createTodo: async (userId: number, input: TodoCreateInput) =>
    await db.collection('users').doc(userId).collection('todos').add(input),

  updateTodo: async (userId: number, todoId: number, input: TodoUpdateInput) =>
    await db.collection('users').doc(userId).collection('todos').doc(todoId).update(input),

  deleteTodo: async (userId: number, todoId: number) =>
    await db.collection('users').doc(userId).collection('todos').doc(todoId).delete()
}
// rules
rules_version = '2';

service cloud.firestore {
    match /databases/{database}/documents {
         match /users/{userId} {
             match /todos/{todoId} {
                 allow get: if request.auth != null
                 allow create: if request.auth.uid == userId
                 allow update: if request.auth.uid == userId
                 allow delete: if request.auth.uid == userId
             }
             
         }
     }
}
/**
 * use in your project!
 */
const userId = store.user.id
const user = await firestoreClient.getUser(userId)
const todos = await firestoreClient.getTodosByUser(userId)

const todoId = 22
await firestoreClient.deleteTodo(userId, todoId)
You might also like...
Rust edit distance routines accelerated using SIMD. Supports fast Hamming, Levenshtein, restricted Damerau-Levenshtein, etc. distance calculations and string search.

triple_accel Rust edit distance routines accelerated using SIMD. Supports fast Hamming, Levenshtein, restricted Damerau-Levenshtein, etc. distance cal

Web 3.0 Realized with Traceless Privacy and Seamless Compatibility

Automata Build On Ubuntu/Debian (or similar distributions on WSL), install the following packages: sudo apt-get update sudo apt-get install -y build-e

Text Expression Runner – Readable and easy to use text expressions
Text Expression Runner – Readable and easy to use text expressions

ter - Text Expression Runner ter is a cli to run text expressions and perform basic text operations such as filtering, ignoring and replacing on the c

💥 Fast State-of-the-Art Tokenizers optimized for Research and Production
💥 Fast State-of-the-Art Tokenizers optimized for Research and Production

Provides an implementation of today's most used tokenizers, with a focus on performance and versatility. Main features: Train new vocabularies and tok

Rust native ready-to-use NLP pipelines and transformer-based models (BERT, DistilBERT, GPT2,...)

rust-bert Rust native Transformer-based models implementation. Port of Hugging Face's Transformers library, using the tch-rs crate and pre-processing

👄 The most accurate natural language detection library in the Rust ecosystem, suitable for long and short text alike
👄 The most accurate natural language detection library in the Rust ecosystem, suitable for long and short text alike

Table of Contents What does this library do? Why does this library exist? Which languages are supported? How good is it? Why is it better than other l

Semantic text segmentation. For sentence boundary detection, compound splitting and more.

NNSplit A tool to split text using a neural network. The main application is sentence boundary detection, but e. g. compound splitting for German is a

A fast, low-resource Natural Language Processing and Text Correction library written in Rust.

nlprule A fast, low-resource Natural Language Processing and Error Correction library written in Rust. nlprule implements a rule- and lookup-based app

Rust-tokenizer offers high-performance tokenizers for modern language models, including WordPiece, Byte-Pair Encoding (BPE) and Unigram (SentencePiece) models

rust-tokenizers Rust-tokenizer offers high-performance tokenizers for modern language models, including WordPiece, Byte-Pair Encoding (BPE) and Unigra

Owner
Ubugeeei
Born in 2000, Tokyo, Japan. Web developer noob.
Ubugeeei
A small random number generator hacked on top of Rust's standard library. An exercise in pointlessness.

attorand from 'atto', meaning smaller than small, and 'rand', short for random. A small random number generator hacked on top of Rust's standard libra

Isaac Clayton 1 Nov 24, 2021
A simple OpenAI (GPT-3) client written in Rust.

A simple OpenAI (GPT-3) client written in Rust. It works by making HTTP requests to OpenAI's API and consuming the results.

Apostolos Kiraleos 3 Oct 28, 2022
Checks all your documentation for spelling and grammar mistakes with hunspell and a nlprule based checker for grammar

cargo-spellcheck Check your spelling with hunspell and/or nlprule. Use Cases Run cargo spellcheck --fix or cargo spellcheck fix to fix all your docume

Bernhard Schuster 274 Nov 5, 2022
A simple and fast linear algebra library for games and graphics

glam A simple and fast 3D math library for games and graphics. Development status glam is in beta stage. Base functionality has been implemented and t

Cameron Hart 953 Jan 3, 2023
A Markdown to HTML compiler and Syntax Highlighter, built using Rust's pulldown-cmark and tree-sitter-highlight crates.

A blazingly fast( possibly the fastest) markdown to html parser and syntax highlighter built using Rust's pulldown-cmark and tree-sitter-highlight crate natively for Node's Foreign Function Interface.

Ben Wishovich 48 Nov 11, 2022
Text calculator with support for units and conversion

cpc calculation + conversion cpc parses and evaluates strings of math, with support for units and conversion. 128-bit decimal floating points are used

Kasper 82 Jan 4, 2023
A command-line tool and library for generating regular expressions from user-provided test cases

Table of Contents What does this tool do? Do I still need to learn to write regexes then? Current features How to install? 4.1 The command-line tool 4

Peter M. Stahl 5.8k Dec 30, 2022
Find and replace text in source files

Ruplacer Find and replace text in source files: $ ruplacer old new src/ Patching src/a_dir/sub/foo.txt -- old is everywhere, old is old ++ new is ever

Tanker 331 Dec 28, 2022
An efficient and powerful Rust library for word wrapping text.

Textwrap Textwrap is a library for wrapping and indenting text. It is most often used by command-line programs to format dynamic output nicely so it l

Martin Geisler 322 Dec 26, 2022
An implementation of regular expressions for Rust. This implementation uses finite automata and guarantees linear time matching on all inputs.

regex A Rust library for parsing, compiling, and executing regular expressions. Its syntax is similar to Perl-style regular expressions, but lacks a f

The Rust Programming Language 2.6k Jan 8, 2023