-
-
Notifications
You must be signed in to change notification settings - Fork 671
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sys-server): impl im/export apis;
- Loading branch information
Showing
11 changed files
with
408 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
> @Deprecated 此目录中的脚本原为初始化应用,现在多租户版中已废弃,待清理。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { ApplicationStruct } from "../api/application" | ||
import { FunctionStruct } from "../api/function" | ||
import { Constants } from "../constants" | ||
import { DatabaseAgent } from "./db-agent" | ||
|
||
|
||
/** | ||
* Export application definition to json object: | ||
* - cloud functions | ||
* - policies | ||
*/ | ||
export class ApplicationExporter { | ||
readonly app: ApplicationStruct | ||
|
||
constructor(app: ApplicationStruct) { | ||
this.app = app | ||
} | ||
|
||
async build() { | ||
const meta = this.buildMeta() | ||
const functions = await this.buildFunctions() | ||
const policies = await this.buildPolicies() | ||
|
||
return { | ||
meta, | ||
functions, | ||
policies | ||
} | ||
} | ||
|
||
private buildMeta() { | ||
return { | ||
name: this.app.name, | ||
created_at: Date.now() | ||
} | ||
} | ||
|
||
private async buildFunctions() { | ||
const db = DatabaseAgent.sys_db | ||
const r = await db.collection(Constants.cn.functions) | ||
.where({ appid: this.app.appid }) | ||
.limit(999) | ||
.get<FunctionStruct>() | ||
|
||
const functions = r.data | ||
const ret = functions.map(func => { | ||
return { | ||
name: func.name, | ||
label: func.label, | ||
code: func.code, | ||
hash: func.hash, | ||
tags: func.tags, | ||
description: func.description, | ||
enableHTTP: func.enableHTTP, | ||
status: func.status, | ||
triggers: func.triggers, | ||
debugParams: func.debugParams, | ||
version: func.version | ||
} | ||
}) | ||
|
||
return ret | ||
} | ||
|
||
private async buildPolicies() { | ||
const db = DatabaseAgent.sys_db | ||
const r = await db.collection(Constants.cn.policies) | ||
.where({ appid: this.app.appid }) | ||
.get() | ||
|
||
const policies = r.data | ||
const ret = policies.map(po => { | ||
return { | ||
name: po.name, | ||
description: po.description, | ||
status: po.status, | ||
rules: po.rules, | ||
injector: po.injector ?? null, | ||
hash: po.hash, | ||
} | ||
}) | ||
|
||
return ret | ||
} | ||
} |
Oops, something went wrong.