0.1.0 • Published 2 years ago

@realm-fun/cli v0.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Realm Fun CLI ⋆ ˚。⋆୨˚✧


ANNOUNCEMENT | The build tool is undergoing active development without a garantee of everything working perfectly.


Install

CLI

npm i @realm-fun/cli@latest -g

Types

npm i @realm-fun/types@latest
import { Context } from '@realm-fun/types'

declare global {
  const context: Context;
}

What is Realm Fun?

Realm Fun is a suite of tools that aim to help with the development of Atlas App Services' backend as a service infrastructure. As its main perk, it makes possible to develop and configure Functions in TypeScript. Moreover, it provides right types for Function's Context, which otherwise are assumed from the MongoDB's documentation.

How does Realm Fun work?

The TypeScript support is achived by analyzing and transpiling code written in TypeScript to JavaScript with a custom Babel transpiler. In contrast to using Webpack, it gives the build tool more control over the transpilation process as well as the endform of the output files.

What does Realm Fun achive?

The tool's main goal is to provide the quality developer experience while reducing the hastle around writing, testing and deploying Realm Applications.

Less checking and more writing :)

Future plans?

  • Build Tool
    • Dead Code Elimination

Specifications & Examples

Simple Function

import type { Context } from "../shared";

// Context Type
declare global {
  const context: SystemContext
}

// Define Configuration Object
export const config: Config = {
  args:{
    logs: true
  },
  exec:{
    priv: false,
    cond: {
      "%%user.type":"normal",
      "%%user.plan.id": "63246b0a67ffbd80f8c81505"
    },
    auth: "system"  
  }
}

// Define Function Body
export default async (args) =>{
  return context.services.get("mongodb-atlas").db("realm").collection("fun").find({
    _id: BSON.ObjectId("some-fun")
  },{
    _id: 0,
    only: 1
  });
}

Endpoint Function

  • in development

Resolver Function

  • in development

Trigger Function

  • in development

Authentication Function

  • in development

Rule Function

  • in development

Build Functions

Directory

realm-fun functions build ./src/functions ./dist/functions [--watch] [--flatten]

Notice: You should use --flatten, if the folder will be deployed via the GitHub Deployments

With Realm Fun - Helpers

If used with helper functions, additional functionality can be achived.

// this is part of the realm fun framework
import { crf } from '@realm-fun/helpers'

// this is the custom extension of the context type
import { Context } from "../shared";

type Args = [boolean];

type Rtrn = "realm fun" | "no fun";

export default crf<Args, Rtrn>(
    {
        arguments:{
            log: false,
            validate(args){
                if (typeof args !== "boolean") throw new Error();
            }
        },
        execution:{
            throw: false,
            private: false,
            condition: {
                "%%user.billing.plan": {
                    "$eq": "standart"
                }
            },
            authorization: "application"
        }
    },
    ({args, ctx}) => { 
        if (args){
            return "realm fun";
        }

        return "no fun";
    }
);

Collaboration

You are welcome to propose new features. You can also complain about the bugs, open all sorts of code related issues.

Licence

MIT