npm package: @freelog/freelog-cg-collection
Description: 输入文件：
Latest version: 1.2.8

#### 组合结构文档

输入文件：

```
for public

c1 // 广告已授权
c2 = this.all.range(0,9) // 免费
c3 = this.all.range(10,19) // 广告
c4 = this.all.exclude(c2).exclude(c3) // 付费
c5 // 付费已授权
c6 = c1.unionSet(c5) // 已授权

s1[c2,c6]:
	case in c3 ~freelog.e1() => s2 do c1.set(context.id);c1.unset(context.id);c1.set(context.id); // 看完广告
s2[c2,c6]:
	case in c4 ~freelog.e2() => s2 do c5.set(context.id); // 付费
	/*
	 * 定期清理付费的单品，假设付费的单品是有时间期限的
	 * 定期清理广告的单品，假设广告的单品是有时间期限的
	 */
    ~freelog.CycleEndEvent("4","cycle") => s2 do c1.clean();c5.clean();
    ~freelog.e4() => s3 // 合约终止
s3:
	terminate

```

输出文件：

```
{
    "audiences": [
        {
            "name": "public",
            "type": "public"
        }
    ],
    "serviceStates": [
        {
            "name": "c1"
        },
        {
            "name": "c2",
            "caller": {
                "name": "this.all",
                "type": "variable"
            },
            "functions": [
                {
                    "functionName": "range",
                    "functionArgs": {
                        "index": "0",
                        "limit": "9"
                    }
                }
            ]
        },
        {
            "name": "c3",
            "caller": {
                "name": "this.all",
                "type": "variable"
            },
            "functions": [
                {
                    "functionName": "range",
                    "functionArgs": {
                        "index": "10",
                        "limit": "19"
                    }
                }
            ]
        },
        {
            "name": "c4",
            "caller": {
                "name": "this.all",
                "type": "variable"
            },
            "functions": [
                {
                    "functionName": "exclude",
                    "functionArgs": {
                        "a": "c2"
                    }
                },
                {
                    "functionName": "exclude",
                    "functionArgs": {
                        "a": "c3"
                    }
                }
            ]
        },
        {
            "name": "c5"
        },
        {
            "name": "c6",
            "caller": {
                "name": "c1",
                "type": "serviceState"
            },
            "functions": [
                {
                    "functionName": "unionSet",
                    "functionArgs": {
                        "a": "c5"
                    }
                }
            ]
        }
    ],
    "stateMachine": {
        "s1": {
            "serviceStates": [
                "c2",
                "c6"
            ],
            "transitions": [
                {
                    "toState": "s2",
                    "service": "freelog",
                    "name": "e1",
                    "condition": {
                        "type": "case",
                        "serviceState": "c3"
                    },
                    "actions": [
                        {
                            "caller": {
                                "name": "c1",
                                "type": "serviceState"
                            },
                            "functions": [
                                {
                                    "functionName": "set",
                                    "functionArgs": {
                                        "a": "context.id"
                                    }
                                }
                            ]
                        },
                        {
                            "caller": {
                                "name": "c1",
                                "type": "serviceState"
                            },
                            "functions": [
                                {
                                    "functionName": "unset",
                                    "functionArgs": {
                                        "a": "context.id"
                                    }
                                }
                            ]
                        },
                        {
                            "caller": {
                                "name": "c1",
                                "type": "serviceState"
                            },
                            "functions": [
                                {
                                    "functionName": "set",
                                    "functionArgs": {
                                        "a": "context.id"
                                    }
                                }
                            ]
                        }
                    ]
                }
            ]
        },
        "s2": {
            "serviceStates": [
                "c2",
                "c6"
            ],
            "transitions": [
                {
                    "toState": "s2",
                    "service": "freelog",
                    "name": "e2",
                    "condition": {
                        "type": "case",
                        "serviceState": "c4"
                    },
                    "actions": [
                        {
                            "caller": {
                                "name": "c5",
                                "type": "serviceState"
                            },
                            "functions": [
                                {
                                    "functionName": "set",
                                    "functionArgs": {
                                        "a": "context.id"
                                    }
                                }
                            ]
                        }
                    ]
                },
                {
                    "toState": "s2",
                    "service": "freelog",
                    "name": "CycleEndEvent",
                    "args": {
                        "cycleCount": 4,
                        "timeUnit": "cycle"
                    },
                    "actions": [
                        {
                            "caller": {
                                "name": "c1",
                                "type": "serviceState"
                            },
                            "functions": [
                                {
                                    "functionName": "clean",
                                    "functionArgs": []
                                }
                            ]
                        },
                        {
                            "caller": {
                                "name": "c5",
                                "type": "serviceState"
                            },
                            "functions": [
                                {
                                    "functionName": "clean",
                                    "functionArgs": []
                                }
                            ]
                        }
                    ],
                    "code": "A101",
                    "description": "raise when n cycle ends",
                    "isSingleton": false
                },
                {
                    "toState": "s3",
                    "service": "freelog",
                    "name": "e4"
                }
            ]
        },
        "s3": {
            "serviceStates": [],
            "transitions": [
                {
                    "name": "terminate"
                }
            ]
        }
    },
    "info": {
        "environmentVariables": [
            "this.all",
            "context.id"
        ]
    },
    "warnings": [
        "该事件未定义：{\"toState\":\"s2\",\"service\":\"freelog\",\"name\":\"e1\",\"condition\":{\"type\":\"case\",\"serviceState\":\"c3\"},\"actions\":[{\"caller\":{\"name\":\"c1\",\"type\":\"serviceState\"},\"functions\":[{\"functionName\":\"set\",\"functionArgs\":[\"context.id\"]}]},{\"caller\":{\"name\":\"c1\",\"type\":\"serviceState\"},\"functions\":[{\"functionName\":\"unset\",\"functionArgs\":[\"context.id\"]}]},{\"caller\":{\"name\":\"c1\",\"type\":\"serviceState\"},\"functions\":[{\"functionName\":\"set\",\"functionArgs\":[\"context.id\"]}]}]}",
        "该事件未定义：{\"toState\":\"s2\",\"service\":\"freelog\",\"name\":\"e2\",\"condition\":{\"type\":\"case\",\"serviceState\":\"c4\"},\"actions\":[{\"caller\":{\"name\":\"c5\",\"type\":\"serviceState\"},\"functions\":[{\"functionName\":\"set\",\"functionArgs\":[\"context.id\"]}]}]}",
        "该事件未定义：{\"toState\":\"s3\",\"service\":\"freelog\",\"name\":\"e4\"}"
    ],
    "warningObjects": [
        {
            "msg": "该事件未定义：{\"toState\":\"s2\",\"service\":\"freelog\",\"name\":\"e1\",\"condition\":{\"type\":\"case\",\"serviceState\":\"c3\"},\"actions\":[{\"caller\":{\"name\":\"c1\",\"type\":\"serviceState\"},\"functions\":[{\"functionName\":\"set\",\"functionArgs\":[\"context.id\"]}]},{\"caller\":{\"name\":\"c1\",\"type\":\"serviceState\"},\"functions\":[{\"functionName\":\"unset\",\"functionArgs\":[\"context.id\"]}]},{\"caller\":{\"name\":\"c1\",\"type\":\"serviceState\"},\"functions\":[{\"functionName\":\"set\",\"functionArgs\":[\"context.id\"]}]}]}"
        },
        {
            "msg": "该事件未定义：{\"toState\":\"s2\",\"service\":\"freelog\",\"name\":\"e2\",\"condition\":{\"type\":\"case\",\"serviceState\":\"c4\"},\"actions\":[{\"caller\":{\"name\":\"c5\",\"type\":\"serviceState\"},\"functions\":[{\"functionName\":\"set\",\"functionArgs\":[\"context.id\"]}]}]}"
        },
        {
            "msg": "该事件未定义：{\"toState\":\"s3\",\"service\":\"freelog\",\"name\":\"e4\"}"
        }
    ],
    "errors": [],
    "errorObjects": []
}
```

结构说明：

```typescript
export interface Result {
    // 目标用户
    audiences: Audience[];
    // 色块声明
    serviceStates: ServiceState[];
    // 状态机
    stateMachine: StateMachine;
    // 信息
    info: Info;
}

// 目标用户
export interface Audience {
    // 名称
    name: string;
    // 类型
    type: string;
}

// 色块声明
export interface ServiceState {
    // 色块名
    name: string;
    // 色块赋值调用者
    caller?: Caller;
    // 函数集合，链式调用
    functions?: Function[];
}

// 调用者
export interface Caller {
    // 名称
    name: string;
    // 类型 variable:变量 | serviceState:色块
    type: string;
}

// 函数
export interface Function {
    // 函数名
    functionName: string;
    // 函数参数
    functionArgs: { name: "value" };
}

// 状态机
export interface StateMachine {
    // 状态名
    state: {
        // 色块集合
        serviceStates: string[];
        // 事件转换集合
        transitions: Transition[];
    }
}

// 事件转换
export interface Transition {
    // 条件
    condition?: Condition;
    // 事件名
    name: string;
    // 事件服务
    service: string;
    // 事件路径
    path?: string;
    // 转换目标状态
    toState: string;
    // 事件参数
    args: {
        // 参数名，参数值
        argName: string;
    };
    // 事件代码
    code: string;
    // 事件描述
    description: string;
    // 是否是单例
    isSingleton: boolean;
    // 动作
    actions?: Action[];
}

// 条件
export interface Condition {
    // 类型 case
    type: string;
    // 色块 当类型是case时，有该属性
    serviceState?: string;
}

// 动作
export interface Action {
    // 调用者
    caller?: Caller;
    // 函数集合
    functions: Function[];
}

// 信息
export interface Info {
    // 组合策略中使用到的环境变量
    environmentVariables: string[];
}
```