macoolka-type-model
Version:
`macoolka-type-model` is a library for define model in TypeScript. It easily build a type contain field and method to your Application. It provide a generation model for type and validition
128 lines • 4.9 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getScalarTypeName = exports.foreach = void 0;
/**
* Type Model helper
* @desczh
* Type Model帮助函数
* @file
*/
var pipeable_1 = require("fp-ts/pipeable");
var array = __importStar(require("fp-ts/Array"));
var macoolka_predicate_1 = require("macoolka-predicate");
var O = __importStar(require("fp-ts/Option"));
/**
* Foreach on MModule
* @desczh
* 遍历MModule
* @since 0.2.0
*/
var foreach = function (schema, option) {
(0, pipeable_1.pipe)(option.schema, O.fromNullable, O.map(function (f) { return f(schema); }));
(0, pipeable_1.pipe)(schema.interfaces, array.map(function (model) {
(0, pipeable_1.pipe)(option.model, O.fromNullable, O.map(function (f) { return f(model, schema); }));
(0, pipeable_1.pipe)(model.fields, array.map(function (field) {
(0, pipeable_1.pipe)(option.field, O.fromNullable, O.map(function (f) { return f(field, model, schema); }));
(0, pipeable_1.pipe)(option.type, O.fromNullable, O.map(function (f) { return f(field.type, field, model, schema); }));
}));
(0, pipeable_1.pipe)(model.implements, O.fromNullable, O.map(function (names) {
return (0, pipeable_1.pipe)(names, array.map(function (name) {
(0, pipeable_1.pipe)(option.implement, O.fromNullable, O.map(function (f) { return f(name, model, schema); }));
}));
}));
(0, pipeable_1.pipe)(model.methods, O.fromNullable, O.map(function (methods) {
(0, pipeable_1.pipe)(methods, array.map(function (method) {
(0, pipeable_1.pipe)(option.method, O.fromNullable, O.map(function (f) { return f(method, model, schema); }));
(0, pipeable_1.pipe)(method.params, O.fromNullable, O.map(function (params) {
return (0, pipeable_1.pipe)(params, array.map(function (param) {
(0, pipeable_1.pipe)(option.param, O.fromNullable, O.map(function (f) { return f(param, method, model, schema); }));
}));
}));
}));
}));
}));
(0, pipeable_1.pipe)(schema.typealiases, O.fromNullable, O.map(function (types) {
(0, pipeable_1.pipe)(types, array.map(function (a) {
(0, pipeable_1.pipe)(option.typealiases, O.fromNullable, O.map(function (f) { return f(a, schema); }));
}));
}));
};
exports.foreach = foreach;
/**
* Get a scalar type name
* @desczh
* 得到标量类型名称
* @since 0.2.0
*/
var getScalarTypeName = function (type) {
return (0, macoolka_predicate_1.isString)(type) ? type : type._kind;
};
exports.getScalarTypeName = getScalarTypeName;
/**
* Map table about Modle Type and Compare Type
* @desczh
* ScalarTypeName到BasicCompareType映射表
* @since 0.2.0
*/
/* const TypeMap: Record<ScalarTypeName, BasicCompareType | 'unknow'> = {
string: 'string',
number: 'number',
boolean: 'boolean',
enum: 'enum',
int: 'number',
datetime: 'date',
kind: 'unknow',
type: 'boolean',
typeUnion: 'unknow',
typeIntersection: 'unknow',
json: 'unknow'
} */
/**
* Get CompareObjectModelDefinition with MInterface
* @desczh
* MInterface到CompareObjectModelDefinition
* @since 0.2.0
*/
/* export const getCompareModelDefinition = (a: MInterface): CompareObjectModelDefinition => {
const definition: Record<BasicCompareType, Array<string>> = {
string: [],
number: [],
enum: [],
date: [],
boolean: []
}
pipe(
a.fields,
array.map(a => {
const scalarType = TypeMap[getScalarTypeName(a.type)]
if (scalarType !== 'unknow') {
definition[scalarType].push(a.name)
}
})
)
return definition
} */
//# sourceMappingURL=helper.js.map