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

@freelog/resource-policy-lang

v1.5.6

Published

policy language compiler for freelog

Downloads

11

Readme

策略结构文档

输入文件:

    for public, 18035541373, [email protected]

    a()=1+2*3^4+self.exhibited

    ab(a,c)=1+2*3^(a-c+e)

    always testActive

    initial:
        ~freelog.SigningEvent("abc/abc") => signed
    signed[active]:
        ~freelog.CycleEndEvent("2","week") => auth
    auth:
        ~freelog.x.y.TransactionEvent("5","self.account") => settlement
    settlement[active]:
        ~freelog.SettlementEvent("001") => auth
        ~freelog.TimeEvent("2021-02-06 14:16") => refund
        ~freelog.RelativeTimeEvent("30","day") => confiscation
    confiscation:
        ~freelog.ViewCountEvent("100") => finish
    refund:
        ~freelog.EscrowExceedAmount("002","888","feather") => finish
    finish[active]:
        terminate

输出文件:

{
    "state_machine": {
        "audiences": [
            {
                "name": "public",
                "type": "public"
            },
            {
                "name": "18035541373",
                "type": "userId"
            },
            {
                "name": "[email protected]",
                "type": "userId"
            }
        ],
        "declarations": {
            "serviceStates": [
                {
                    "name": "active",
                    "type": "authorization"
                },
                {
                    "name": "testActive",
                    "type": "testAuthorization"
                }
            ],
            "serviceStateConstants": [
                {
                    "scope": "always",
                    "state": "testActive"
                }
            ],
            "expressions": [
                {
                    "funcName": "a",
                    "funcArgs": [],
                    "funcBody": "1+2*3^4+self.exhibited"
                },
                {
                    "funcName": "ab",
                    "funcArgs": [
                        "a",
                        "c"
                    ],
                    "funcBody": "1+2*3^(a-c+e)"
                }
            ]
        },
        "states": {
            "initial": {
                "transitions": [
                    {
                        "toState": "signed",
                        "service": "freelog",
                        "name": "SigningEvent",
                        "args": {
                            "resourceName": "abc/abc"
                        },
                        "code": "S101",
                        "description": "acknowledge a resource",
                        "isSingleton": true
                    }
                ],
                "serviceStates": [
                    "testActive"
                ],
                "isInitial": true
            },
            "signed": {
                "transitions": [
                    {
                        "toState": "auth",
                        "service": "freelog",
                        "name": "CycleEndEvent",
                        "args": {
                            "cycleCount": 2,
                            "timeUnit": "week"
                        },
                        "code": "A101",
                        "description": "raise when n cycle ends",
                        "isSingleton": false
                    }
                ],
                "serviceStates": [
                    "testActive",
                    "active"
                ]
            },
            "auth": {
                "transitions": [
                    {
                        "toState": "settlement",
                        "service": "freelog",
                        "path": "x.y",
                        "name": "TransactionEvent",
                        "args": {
                            "amount": 5,
                            "account": "self.account"
                        },
                        "code": "S201",
                        "description": "one time transaction",
                        "isSingleton": true
                    }
                ],
                "serviceStates": [
                    "testActive"
                ]
            },
            "settlement": {
                "transitions": [
                    {
                        "toState": "auth",
                        "service": "freelog",
                        "name": "SettlementEvent",
                        "args": {
                            "account": "001"
                        },
                        "code": "S202",
                        "description": "fired when settlement cleared",
                        "isSingleton": true
                    },
                    {
                        "toState": "refund",
                        "service": "freelog",
                        "name": "TimeEvent",
                        "args": {
                            "dateTime": "2021-02-06 14:16"
                        },
                        "code": "A102",
                        "description": "fired on a pre-determined time",
                        "isSingleton": false
                    },
                    {
                        "toState": "confiscation",
                        "service": "freelog",
                        "name": "RelativeTimeEvent",
                        "args": {
                            "elapsed": 30,
                            "timeUnit": "day"
                        },
                        "code": "A103",
                        "description": "fired when certain amount of time elapsed",
                        "isSingleton": false
                    }
                ],
                "serviceStates": [
                    "testActive",
                    "active"
                ]
            },
            "confiscation": {
                "transitions": [
                    {
                        "toState": "finish",
                        "service": "freelog",
                        "name": "ViewCountEvent",
                        "args": {
                            "amount": 100
                        },
                        "code": "S301",
                        "description": "reserve a target number of authorizations, fires when such number reached",
                        "isSingleton": true
                    }
                ],
                "serviceStates": [
                    "testActive"
                ]
            },
            "refund": {
                "transitions": [
                    {
                        "toState": "finish",
                        "service": "freelog",
                        "name": "EscrowExceedAmount",
                        "args": {
                            "account": "002",
                            "amount": 888,
                            "currencyUnit": "feather"
                        },
                        "code": "S210",
                        "description": "",
                        "isSingleton": true
                    }
                ],
                "serviceStates": [
                    "testActive"
                ]
            },
            "finish": {
                "transitions": [],
                "serviceStates": [
                    "testActive",
                    "active"
                ]
            }
        },
        "description": {
            "symbolArgs": {
                "envArgs": [
                    "self.exhibited",
                    "self.account"
                ]
            }
        }
    },
    "warnings": [],
    "warningObjects": [],
    "errors": [],
    "errorObjects": []
}

结构说明:

// 状态机
export interface StateMachine {
    // 目标用户
    audiences: Audience[];
    // 声明
    declarations: Declarations;
    // 状态机状态
    states: States;
    // 描述
    description: {
        // 标记参数
        symbolArgs: {
            // 策略中使用的环境变量
            envArgs: string[]
        }
    }
}

// 目标用户
export interface Audience {
    // 名称
    name: string;
    // 类型
    type: string;
}

// 声明
export interface Declarations {
    // 系统提供的色块
    serviceStates: ServiceState[];
    // 色块常量
    serviceStateConstants: ServiceStateConstant[];
    // 表达式
    expressions: Expression[];
}

// 色块
export interface ServiceState {
    // 色块名
    name: string;
    // 色块类型
    type: string;
}

// 色块常量
export interface ServiceStateConstant {
    // 作用域
    scope: string;
    // 色块颜色态,可以理解成色块名
    state: string;
}

// 表达式
export interface Expression {
    // 函数名
    functionName: string;
    // 函数参数
    functionArgs: string[];
    // 函数体
    functionBody: string;
}

// 状态机状态
export interface States {
    // 状态名
    state: {
        // 色块集合
        serviceStates: string[];
        // 事件转换集合
        transitions: Transition[];
        // 是否是初始态
        isInitial: boolean;
    }
}

// 事件转换
export interface Transition {
    // 事件名
    name: string;
    // 事件服务
    service: string;
    // 事件路径
    path: string;
    // 转换目标状态
    toState: string;
    // 事件参数
    args: {
        // 参数名,参数值
        argName: string;
    };
    // 事件代码
    code: string;
    // 事件描述
    description: string;
    // 是否是单例
    isSingleton: boolean;
}