Socket
Socket
Sign inDemoInstall

koa-rtapi

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-rtapi - npm Package Compare versions

Comparing version 1.1.567 to 1.2.0

code-pure/--start--.bat

65

code/api/coder.api.js
'use strict';
/**
* 自动生成代码
* 2019-5-23
*/
// #region [import]
const fs = require('fs');

@@ -6,2 +14,23 @@ const path = require('path');

// #endregion
// 构建配置
const map = [
{ file: '_apiAccess.js', single: true, target: '../api/xf-api/_apiAccess.js' },
{ file: '_dbDoc.md', single: true, target: '../www/xf-view/_dbDoc.md' },
{ file: 'api.js', single: false, target: '../api/xf-api/{TABLE_NAME}.api.js' },
{ file: 'home/home.css', single: true, target: '../www/xf-view/home/home.css' },
{ file: 'home/home.html', single: true, target: '../www/xf-view/home/home.html' },
{ file: 'home/home.js', single: true, target: '../www/xf-view/home/home.js' },
{ file: 'grid/grid.css', single: false, target: '../www/xf-view/{TABLE_NAME}-grid/{TABLE_NAME}-grid.css' },
{ file: 'grid/grid.html', single: false, target: '../www/xf-view/{TABLE_NAME}-grid/{TABLE_NAME}-grid.html' },
{ file: 'grid/grid.js', single: false, target: '../www/xf-view/{TABLE_NAME}-grid/{TABLE_NAME}-grid.js' },
{ file: 'edit/edit.css', single: false, target: '../www/xf-view/{TABLE_NAME}-edit/{TABLE_NAME}-edit.css' },
{ file: 'edit/edit.html', single: false, target: '../www/xf-view/{TABLE_NAME}-edit/{TABLE_NAME}-edit.html' },
{ file: 'edit/edit.js', single: false, target: '../www/xf-view/{TABLE_NAME}-edit/{TABLE_NAME}-edit.js' }
];
module.exports = class {

@@ -16,21 +45,3 @@

// 操作的根路径
this.root = arr.join('/') + '/coder';
// 构建的列表
this.map = [
{ file: '_apiAccess.js', single: true, target: '../api/xf-api/_apiAccess.js' },
{ file: 'api.js', single: false, target: '../api/xf-api/{TABLE_NAME}.api.js' },
{ file: 'home/home.css', single: true, target: '../www/xf-view/home/home.css' },
{ file: 'home/home.html', single: true, target: '../www/xf-view/home/home.html' },
{ file: 'home/home.js', single: true, target: '../www/xf-view/home/home.js' },
{ file: 'grid/grid.css', single: false, target: '../www/xf-view/{TABLE_NAME}-grid/{TABLE_NAME}-grid.css' },
{ file: 'grid/grid.html', single: false, target: '../www/xf-view/{TABLE_NAME}-grid/{TABLE_NAME}-grid.html' },
{ file: 'grid/grid.js', single: false, target: '../www/xf-view/{TABLE_NAME}-grid/{TABLE_NAME}-grid.js' },
{ file: 'edit/edit.css', single: false, target: '../www/xf-view/{TABLE_NAME}-edit/{TABLE_NAME}-edit.css' },
{ file: 'edit/edit.html', single: false, target: '../www/xf-view/{TABLE_NAME}-edit/{TABLE_NAME}-edit.html' },
{ file: 'edit/edit.js', single: false, target: '../www/xf-view/{TABLE_NAME}-edit/{TABLE_NAME}-edit.js' }
];
this.root = arr.join('/') + '/_coder';
}

@@ -58,4 +69,4 @@

// 构建文件
async $build(body) {
// 获取数据库结构
async getSchema(body) {
const t = this;

@@ -80,5 +91,13 @@

return tables;
}
// 构建文件
async $build(body) {
const t = this;
const tables = await t.getSchema(body);
// 获取模板
const dir = t.root + '/';
for (let item of t.map) {
for (let item of map) {
const str = fs.readFileSync(dir + '/' + item.file).toString();

@@ -105,3 +124,3 @@

message: err.message,
stack:err.stack
stack: err.stack
}

@@ -108,0 +127,0 @@ }

'use strict';
// 2019-3-12 by yjf
/**
* 文件读写操作 by yjf
* 2019-5-23
*/
// #region [import]
const fs = require('fs');
const path = require('path');
// #endregion
module.exports = class {
constructor(req, res) {
this.req = req;
this.res = res;
}
// 读取文件

@@ -38,3 +39,3 @@ $readFile(body) {

const path = this.getPath(body);
fs.unlinkSync(path);

@@ -41,0 +42,0 @@ this.clearCache(path);

'use strict';
/**
* DEMO by yjf
* 2019-5-23
*/
module.exports = class {
/* [系统函数]
// 构造函数,ctx:上下文,name:方法名
constructor(ctx, name) {
}
// 前置方法,支持异步,name:方法名,以$开始。如果return false则阻止继续执行
async before(name) {
}
// 后置方法,支持异步,name:方法名
async after(name) {
}
*/
// hello world

@@ -6,0 +27,0 @@ $hello() {

@@ -81,3 +81,3 @@ xf.module({

t.Modal.callback({});
t.Page.close();
t.Page.back();
});

@@ -84,0 +84,0 @@ },

@@ -56,3 +56,3 @@

showMode: 'default', // 显示模式 default-自适应, definded-自定义
tableStyle: 'simple' //simple/classic/fashion
tableStyle: 'classic' //simple/classic/fashion
},

@@ -62,2 +62,8 @@

// 模式
mode: function () {
var para = this.Context.para || {};
return para.mode;
},
// 可见字段

@@ -169,2 +175,3 @@ listFields: function () {

mode: 1,
idField: t.idField,
fields: t.fields,

@@ -184,2 +191,3 @@ metaMap: t.metaMap,

mode: 2,
idField: t.idField,
fields: t.fields,

@@ -395,6 +403,5 @@ metaMap: t.metaMap,

// 字段太多时使用自定义宽度和经典样式
if (List.fields.length > 5) {
// 字段太多时使用自定义宽度
if (List.listFields.length > 5) {
List.showMode = 'definded';
List.tableStyle = 'classic';
}

@@ -461,2 +468,12 @@

return JSON.stringify(row);
},
// 选择并返回
selectBack: function (e) {
var t = this;
var row = t.selectedRow;
if (row) {
t.Modal.callback(row);
t.Page.back();
}
}

@@ -463,0 +480,0 @@ },

@@ -5,5 +5,5 @@ xf.module({

module: function() {
module: function () {
var Builder = function(context, opt) {
var Builder = function (context, opt) {

@@ -56,3 +56,3 @@ var t = this;

// 创建Vue对象
vue: function(name) {
vue: function (name) {

@@ -69,6 +69,6 @@ var t = this;

computed: {
Page: function() { return t.context.page; }, // 页面对象
View: function() { return t.context.view; }, // 视图对象
Context: function() { return t.context; }, // 上下文
Modal: function() { return t; } // 视图控制器
Page: function () { return t.context.page; }, // 页面对象
View: function () { return t.context.view; }, // 视图对象
Context: function () { return t.context; }, // 上下文
Modal: function () { return t; } // 视图控制器
},

@@ -109,3 +109,3 @@ methods: {

// 视图控制器创建就绪
ready: function(fn) {
ready: function (fn) {
var t = this;

@@ -120,3 +120,3 @@ var c = t.context;

// 提交数据
post: function(url, data, option) {
post: function (url, data, option) {
var t = this;

@@ -128,3 +128,3 @@

opt.beforeSend = function() {
opt.beforeSend = function () {
t._postRemain = t._postRemain || 0;

@@ -135,3 +135,3 @@ t._postRemain++;

opt.beforeReady = function() {
opt.beforeReady = function () {
t._postRemain--;

@@ -147,3 +147,3 @@ if (t._postRemain === 0) {

// 检查数据
checker: function(row, rules, opt) {
checker: function (row, rules, opt) {
var t = this;

@@ -153,3 +153,3 @@ opt = opt || {};

// 在元素上显示错误
var tip = function(key, msg) {
var tip = function (key, msg) {
var el = opt.box.querySelector('[data-checker="' + key + '"]');

@@ -163,3 +163,3 @@ if (!el) return false;

el._checker_msg = xf.el('div', { className: 'checker-msg' });
el.addEventListener('click', function(e) {
el.addEventListener('click', function (e) {
e.target.classList.remove('error');

@@ -208,5 +208,20 @@ el._checker_msg.remove();

// 回调函数
callback: function(para) {
callback: function (para) {
xf.log('[#93B983]callback', para);
return this.context.para.callback.call(this, para);
},
// 到其他页面选取信息
goSelect: function (para, map, key) {
var t = this;
var page = t.context.page;
var sec = para.split(/\#|\./g);
var name = '@' + sec[1] + '-grid';
page.go(name, {
mode: 'select',
callback: function (item) {
map[key] = item[sec[2]];
}
});
}

@@ -218,3 +233,3 @@ };

// 在数组中,根据value找key
Builder.findKey = function(arr, val) {
Builder.findKey = function (arr, val) {
arr = arr || [];

@@ -221,0 +236,0 @@ var len = arr.length;

@@ -27,5 +27,7 @@ #!/usr/bin/env node

copyDir(__dirname + '/code', __dirname + '/../..');
const [node, path, ...argv] = process.argv;
const dir = __dirname + '/code' + (argv[0] || '');
copyDir(dir, __dirname + '/../..');
console.log('code copy success');

@@ -82,2 +82,4 @@

const r = await o.search(t.access);
await t.access.buildOuter(r.items);
return t.output(r);

@@ -92,3 +94,6 @@ }

const r = await t.access.select('*', 'id=?').getOne(id);
const pk = t.access.primaryKey;
const r = await t.access.select('*', `${pk}=?`).getOne(id);
await t.access.buildOuter(r);
return t.output(r);

@@ -110,7 +115,8 @@ }

const t = this;
const id = t.value(body.id, 0, '参数id必须为数字');
const pk = t.access.primaryKey;
const id = t.value(body[pk], 0, '参数id必须为数字');
const data = await t.buildData(body, 'update');
if (t.isFailed) { return t.fail(); }
const r = await t.access.update(data, { id: id });
const r = await t.access.update(data, { [pk]: id });
return t.output(r);

@@ -122,6 +128,7 @@ }

const t = this;
const pk = t.access.primaryKey;
const ids = t.value(body.ids, /^\d+(\,\d+)*$/, 'ids格式有误');
if (t.isFailed) { return t.fail(); }
const r = await t.access.delete({ id: ids.split(',') });
const r = await t.access.delete({ [pk]: ids.split(',') });
return t.output(r.affectedRows);

@@ -128,0 +135,0 @@ }

'use strict';
const util = require('util');

@@ -39,3 +40,3 @@ // 返回错误

const Api = require(aPath);
api = new Api(ctx);
api = new Api(ctx, aName);
} catch (e) {

@@ -47,3 +48,3 @@ return outError(ctx, `控制器错误|${e.message}|${e.stack}`, 500);

const method = api[aName];
if (method === undefined) {
if (!util.isFunction(method)) {
return outError(ctx, `没有找到方法|${aName}`, 404);

@@ -56,3 +57,18 @@ }

api.ctx = ctx;
// 前置
const before = api.before;
if (util.isFunction(before)) {
const result = await before.call(api, aName);
if (result === false) { return; }
}
// 执行
ctx.body = await method.call(api, body);
// 后置
const after = api.after;
if (util.isFunction(after)) {
await after.call(api, aName);
}
} catch (e) {

@@ -59,0 +75,0 @@ return outError(ctx, `执行时出错|${e.message}|${e.stack}`, 500);

@@ -17,4 +17,6 @@ 'use strict';

if (i % 2 === 0) {
const lineArr = item.split('\n');
const lineArr = item.split(/\r\n|\n/);
let j = lineArr.length;
for (const lineItem of lineArr) {
j--;
if (next) {

@@ -24,3 +26,4 @@ next = false;

}
lines.push('$b.addStr("' + encodeURI(lineItem) + '");');
lines.push('$b.addStr("' + encodeURIComponent(lineItem) + '");');
if (j > 0) { lines.push('$b.addStr("%0A");'); }
}

@@ -27,0 +30,0 @@ continue;

@@ -84,2 +84,4 @@ import mysql from 'mysql';

/** 构建外部数据 */
buildOuter(rows: Array<any>, keys?: Array<string>): Promise<any>;

@@ -86,0 +88,0 @@ /** 附加数据 */

@@ -9,3 +9,3 @@ const mysql = require('mysql');

t.db_cfg = db_cfg; // 数据库配置
if (acc_cfg) {

@@ -16,2 +16,3 @@ t.sheetName = acc_cfg.sheetName; // 表名

t.filter = acc_cfg.filter; // 查询的默认过滤条件
t.outerExpress = acc_cfg.outerExpress || {}; // 外键描述
}

@@ -151,2 +152,33 @@ }

/** 构建外部数据 */
async buildOuter(rows, keys) {
const t = this;
if (!rows) { return rows; }
const isArray = Array.isArray(rows)
if (!isArray) { rows = [rows]; }
if (rows.length > 0) {
// 如果没有指定key
if (!keys) {
keys = [];
for (const k in t.outerExpress) {
keys.push(k);
}
}
// 构建内容
for (const key of keys) {
const [, sheet, col] = t.outerExpress[key].split(/\#|\./g);
const access = new Access(t.db_cfg, { sheetName: sheet });
for (const row of rows) {
row[key + '__data'] = await access.sysSelect().where(`${col}=?`).getOne(row[key]);
}
}
}
return isArray ? rows : rows[0];
}
// #endregion

@@ -153,0 +185,0 @@

{
"name": "koa-rtapi",
"version": "1.1.567",
"version": "1.2.0",
"description": "koa api in rtworld company",

@@ -5,0 +5,0 @@ "main": "index.js",

# koa-rtapi
**简介**
## 简介
> 填坑工具:一行命令启动一个服务器,如果你有个数据库,点一下还能生成一个系统(还TM的带文档)
- 创建一个http服务器 `(koa2)`
- 简化的基于文件的api路由
- 支持 `request.body(koa-bodyparser)`,`跨域(koa2-cors)`,`静态服务(koa-static)`
- 集成了tkui(填坑UI)和前后台生成工具
- 集成了代码在线编辑工具
- 集成了一些别人的东西
- koa-bodyparser:支持ctx.request.body
- koa2-cors: 支持跨域
- koa-static:静态文件服务
- request:支持发起请求
- mysql:数据库驱动
- 集成了一些自己写的工具
- tkui(填坑UI)
- 代码(前台/API/数据库/文档)生成工具
- 代码在线编辑工具
- power by 村长扫大街
**初始化**
## 初始化
如果安装了npx(windows的node默认安装)
```
npm init -y && npm i koa-rtapi && npx koa-rtapi-init && node index
```
如果没有npx(linux的node好像不默认安装)
```
npm init -y && npm i koa-rtapi && node node_modules/koa-rtapi/init_code && node index
```
纯净安装
**更新**
```
npm init -y && npm i koa-rtapi && npx koa-rtapi-init -pure
```
## 更新
```
npm update koa-rtapi
```
**启动**
## 启动
```

@@ -24,8 +43,8 @@ node index

**文件说明**
- index.js 启动和配置
## 文件说明
- _coder/ 代码生成模板
- api/ api文件
- coder.api.js: 代码生成api
- demo.api.js: 范例api
- coder/ 代码生成模板
- www/ 放静态文件
- www/ 放静态文件
- index.js 启动和配置

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc