npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ts-firebase-rules

v0.1.12

Published

enjoy using TypeScript power while proggraming firebase *.rules files

Downloads

1

Readme

✨✨TSFR✨✨

TSFR is the lost piece of firebase ".rules" files .
with TSFR you can use power of typescript to overcome firebase rules-engine limitations and scale your app so much easier without worring about your app crashes just for simple typo errors and also better managing/debugging with spliting the .rules file into smaller files.

Features

  • type-checking
    • catch bugs on-the-fly
  • Cli
    • a good cli always makes our life easier (e.g: create, watch, ...)
  • Live reload / watch-mode
    • npx tsfr watch
  • import/export
    • split your project into smaller peaces and have better debugging
  • additional helper types and functions
    • TSFR comes with helpers ,you can import them and use them
  • write additional native modules
    • you can write additinal native helper functions or use other people functions
  • globalVariables
    • e.g: can be used as Configs that are going to be used in many functions ...

Quick Start

npm i -D ts-firebase-rules
npx tsfr create
#use npx tsfr create --help for more complex commands

this will ask you to choose a template and that's it. Just cd to tsfr folder , run build or watch command and start editing tsfr/index.ts!

cd tsfr
npx tsfr watch
#npx tsfr build

note:in case you want to change output file or manipulate paths of source files from your_project/tsfr.config.json


basic-example

lets create a simple todo list:

//index.ts
import { setRuleStructure } from 'ts-firebase-rules'
import { create_todo, update_todo, read_todo } from './functions/todos'

setRuleStructure(() => ({
    'todos': (id) => ({
        create: create_todo(id),
        //other fns e.g update ...
    }),
}))
//functions/todos.ts
import { FrString, request, isString, getReq,  FrBoolean} from "ts-firebase-rules" 

import * as mt from '../../modelsTypes'
export function create_todo(id: FrString): FrBoolean {
    const reqData = getReq<mt.create_todo>()
    return (
        request.auth != null && // user has logged in 
        reqData.createdBy === request.auth.uid &&  
        isString(reqData.comments) && 
        titleIsValid(reqData.title)
    )
} 
//functions/helpers.ts
import { _globalVariables_ } from "../_globalVariables_" 
export function titleIsValid(title: FrString): FrBoolean {
    return (
        title.matches('[A-Za-z][A-Za-z0-9]') &&
        title.size() >= _globalVariables_.minimumCharsInTitle &&
        title.size() <= _globalVariables_.maximumCharsInTitle)
}

compiles to:

match /groups/{id} {
    allow create: if create_groups(id);
    ...
}

//other imported functions will get compiled here 
function create_todo(id) {
    let reqData = getReq();
    return (request.auth != null &&
        titleIsValid(reqData.title) &&
        reqData.createdBy == request.auth.uid &&
        isString(reqData.comments) && 
        );
}

function titleIsValid(title) {
        return (title.matches('[A-Za-z][A-Za-z0-9]') &&
            title.size() >= minimumCharsInTitle()  &&
            title.size() <= maximumCharsInTitle() );
} 

check react-native-todoList-boilerplate for a complete example.


adding-native-modules(optional)

for adding native modules you can simply modify native/functions/nativeFunctions.rules then add a decleration type for it. for example:

//your_project/tsfr/native/functions/nativeFunctions.rules
function docExists2(id, table) {
   return ( 
       exists(/databases/$(database)/documents/$(table)/$(id)) 
   )
}
 //your_project/tsfr/additionalFns.d.ts
import { FrStringAsParam} from 'ts-firebase-rules'
 
 export const docExists2: <tables>(id: FrStringAsParam, table: tables) => FrBoolean

and nowyou can use docExists2 function in your tsfr project.


Notes

⚠️ *Note:this project is still in its first days ,personally i used this for some of my projects(on production) and so far there have been no problem but we use multiple compiler and transitions so unexpected bugs might happen ,so (for now) you should check the final file and do the testing*

Note: we still going to have Firebase rules language limitations like lack of Loops and etc so make sure you have read their documentions.


✨✨✨✨✨✨

Author

License

MIT