Skip to content

Commit

Permalink
upgrade by darabonba v2
Browse files Browse the repository at this point in the history
  • Loading branch information
page authored and peze committed Jun 21, 2024
1 parent a3b08b8 commit a5386d1
Show file tree
Hide file tree
Showing 116 changed files with 8,151 additions and 8,244 deletions.
799 changes: 799 additions & 0 deletions lib/builtin.js

Large diffs are not rendered by default.

2,145 changes: 2,145 additions & 0 deletions lib/generator.js

Large diffs are not rendered by default.

101 changes: 101 additions & 0 deletions lib/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
'use strict';

const keywords = [
// https://www.php.net/manual/zh/reserved.keywords.php
'__halt_compiler', 'abstract', 'and', 'array', 'as',
'break', 'callable', 'case', 'catch', 'class',
'clone', 'const', 'continue', 'declare', 'default',
'die', 'do', 'echo', 'else', 'elseif',
'empty', 'enddeclare', 'endfor', 'endforeach', 'endif',
'endswitch', 'endwhile', 'eval', 'exit', 'extends',
'final', 'for', 'foreach', 'function',
'global', 'goto', 'if', 'implements', 'include',
'include_once', 'instanceof', 'insteadof', 'interface', 'isset',
'list', 'namespace', 'new', 'or', 'print',
'private', 'protected', 'public', 'require', 'require_once',
'return', 'static', 'switch', 'throw', 'trait',
'try', 'unset', 'use', 'var', 'while', 'xor'
];

const builtinModels = ['$Request', '$Response', '$Error', '$SSEEvent', '$Model'];
const NAMESPACE = 'AlibabaCloud\\Dara';
const CORE = 'AlibabaCloud\\Dara\\Dara';
const REQUEST = 'AlibabaCloud\\Dara\\Request';
const RESPONSE = 'AlibabaCloud\\Dara\\Response';
const MODEL = 'AlibabaCloud\\Dara\\Model';
const ERROR = 'AlibabaCloud\\Dara\\Exception\\DaraException';
const UNRETRY_ERROR = 'AlibabaCloud\\Dara\\Exception\\DaraUnableRetryException';
const RESP_ERROR = 'AlibabaCloud\\Dara\\Exception\\DaraRespException';
const RETRY_CONTEXT = 'AlibabaCloud\\Dara\\RetryPolicy\\RetryPolicyContext';
const SSE_EVENT = 'AlibabaCloud\\Dara\\SSE\\Event';
const STREAM = 'GuzzleHttp\\Psr7\\Stream';


function _name(str) {
if (str.lexeme === '__request') {
return '_reqeust';
}

if (str.lexeme === '__response') {
return '_response';
}

return str.lexeme || str.name;
}

function _upperFirst(str) {
return str[0].toUpperCase() + str.substring(1);
}

function _subModelName(name) {
return name.split('.').map((name) => _upperFirst(name)).join('');
}

function _avoidKeywords(str) {
if (keywords.indexOf(str.toLowerCase()) > -1) {
return str + '_';
}
return str;
}

function _modelName(str) {
if (keywords.indexOf(str.toLowerCase()) > -1 || str.toLowerCase() === 'model') {
return str + '_';
}
return str;
}


function _string(str) {
if (str.string === '\'\'') {
return '\\\'\\\'';
}
return str.string.replace(/([^\\])'+|^'/g, function(str){
return str.replace(/'/g, '\\\'');
});
}

function _isBinaryOp(type){
const op = [
'or', 'eq', 'neq',
'gt', 'gte', 'lt',
'lte', 'add', 'subtract',
'div', 'multi', 'and'
];
return op.includes(type);
}

function _vid(vid) {
return `_${_name(vid).substr(1)}`;
}

function _isBuiltinModel(name){
return builtinModels.includes(name);
}

module.exports = {
_name, _string, _subModelName, _vid, _upperFirst, _isBuiltinModel,
_isBinaryOp, _modelName, _avoidKeywords, RETRY_CONTEXT,
REQUEST, RESPONSE, MODEL, NAMESPACE, ERROR, STREAM, UNRETRY_ERROR,
CORE, SSE_EVENT, RESP_ERROR
};
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"lib": "src"
},
"scripts": {
"lint": "eslint --fix src/ tests/",
"test": "mocha --reporter spec --timeout 3000 tests/*.tests.js",
"lint": "eslint --fix lib/ tests/",
"test": "mocha --reporter spec --timeout 3000 tests/*.test.js",
"test-cov": "nyc -r=lcov -r=html -r=text -r=json mocha -t 3000 -R spec tests/*.tests.js",
"ci": "npm run lint && npm run test-cov && codecov"
},
Expand All @@ -19,7 +19,8 @@
"author": "Alibaba Cloud OpenAPI Team",
"license": "Apache-2.0",
"dependencies": {
"@darabonba/parser": "^1.2.7",
"@darabonba/annotation-parser": "^1.0.0",
"@darabonba/parser": "^2.0.5",
"camelcase": "^6.0",
"enum": "^3.0"
},
Expand Down
245 changes: 0 additions & 245 deletions src/generator.js

This file was deleted.

Loading

0 comments on commit a5386d1

Please sign in to comment.