@qubit-ltd/common-decorator 3.8.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +1156 -0
- package/README.zh_CN.md +929 -0
- package/dist/common-decorator.cjs +6818 -0
- package/dist/common-decorator.cjs.map +1 -0
- package/dist/common-decorator.min.cjs +1 -0
- package/dist/common-decorator.min.cjs.map +1 -0
- package/dist/common-decorator.min.mjs +1 -0
- package/dist/common-decorator.min.mjs.map +1 -0
- package/dist/common-decorator.mjs +6792 -0
- package/dist/common-decorator.mjs.map +1 -0
- package/doc/api/DefaultAssignmentOptions.html +678 -0
- package/doc/api/DefaultOptions.html +954 -0
- package/doc/api/DefaultToJsonOptions.html +633 -0
- package/doc/api/Enum.html +1848 -0
- package/doc/api/Model.html +3607 -0
- package/doc/api/Page.html +1105 -0
- package/doc/api/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/doc/api/fonts/OpenSans-Bold-webfont.svg +1838 -0
- package/doc/api/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/doc/api/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/doc/api/fonts/OpenSans-BoldItalic-webfont.svg +1838 -0
- package/doc/api/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/doc/api/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/doc/api/fonts/OpenSans-Italic-webfont.svg +1838 -0
- package/doc/api/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/doc/api/fonts/OpenSans-Light-webfont.eot +0 -0
- package/doc/api/fonts/OpenSans-Light-webfont.svg +1839 -0
- package/doc/api/fonts/OpenSans-Light-webfont.woff +0 -0
- package/doc/api/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/doc/api/fonts/OpenSans-LightItalic-webfont.svg +1843 -0
- package/doc/api/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/doc/api/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/doc/api/fonts/OpenSans-Regular-webfont.svg +1839 -0
- package/doc/api/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/doc/api/fonts/OpenSans-Semibold-webfont.eot +0 -0
- package/doc/api/fonts/OpenSans-Semibold-webfont.svg +1838 -0
- package/doc/api/fonts/OpenSans-Semibold-webfont.ttf +0 -0
- package/doc/api/fonts/OpenSans-Semibold-webfont.woff +0 -0
- package/doc/api/fonts/OpenSans-SemiboldItalic-webfont.eot +0 -0
- package/doc/api/fonts/OpenSans-SemiboldItalic-webfont.svg +1838 -0
- package/doc/api/fonts/OpenSans-SemiboldItalic-webfont.ttf +0 -0
- package/doc/api/fonts/OpenSans-SemiboldItalic-webfont.woff +0 -0
- package/doc/api/global.html +6049 -0
- package/doc/api/index.html +1325 -0
- package/doc/api/scripts/linenumber.js +34 -0
- package/doc/api/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/doc/api/scripts/prettify/lang-css.js +2 -0
- package/doc/api/scripts/prettify/prettify.js +28 -0
- package/doc/api/styles/jsdoc-default.css +699 -0
- package/doc/api/styles/prettify-jsdoc.css +120 -0
- package/doc/api/styles/prettify-tomorrow.css +141 -0
- package/doc/common-decorator.min.visualization.html +4949 -0
- package/doc/common-decorator.visualization.html +4949 -0
- package/package.json +107 -0
|
@@ -0,0 +1,1325 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<title>Home - Documentation</title>
|
|
7
|
+
|
|
8
|
+
<script src="scripts/prettify/prettify.js"></script>
|
|
9
|
+
<script src="scripts/prettify/lang-css.js"></script>
|
|
10
|
+
<!--[if lt IE 9]>
|
|
11
|
+
<script src="https://cdn.bootcdn.net/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
|
|
12
|
+
<![endif]-->
|
|
13
|
+
<link type="text/css" rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
|
|
14
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
|
15
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
|
16
|
+
</head>
|
|
17
|
+
<body>
|
|
18
|
+
|
|
19
|
+
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
20
|
+
<label for="nav-trigger" class="navicon-button x">
|
|
21
|
+
<div class="navicon"></div>
|
|
22
|
+
</label>
|
|
23
|
+
|
|
24
|
+
<label for="nav-trigger" class="overlay"></label>
|
|
25
|
+
|
|
26
|
+
<nav>
|
|
27
|
+
<li class="nav-link nav-home-link"><a href="index.html">Home</a></li><li class="nav-heading">Classes</li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="DefaultAssignmentOptions.html">DefaultAssignmentOptions</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="DefaultOptions.html">DefaultOptions</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="DefaultOptions.html#.get">get</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="DefaultOptions.html#.merge">merge</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="DefaultOptions.html#.reset">reset</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="DefaultOptions.html#.set">set</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="DefaultToJsonOptions.html">DefaultToJsonOptions</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Page.html">Page</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Page.html#assign">assign</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Page.html#.getFrom">getFrom</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Page.html#.newEmpty">newEmpty</a></span></li><li class="nav-heading">Namespaces</li><li class="nav-heading"><span class="nav-item-type type-namespace">N</span><span class="nav-item-name"><a href="Enum.html">Enum</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Enum.html#.Class.has">Class.has</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Enum.html#.Class.hasCode">Class.hasCode</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Enum.html#.Class.hasName">Class.hasName</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Enum.html#.Class.hasValue">Class.hasValue</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Enum.html#.Class.of">Class.of</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Enum.html#.Class.ofCode">Class.ofCode</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Enum.html#.Class.ofName">Class.ofName</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Enum.html#.Class.ofValue">Class.ofValue</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Enum.html#.Class.values">Class.values</a></span></li><li class="nav-heading"><span class="nav-item-type type-namespace">N</span><span class="nav-item-name"><a href="Model.html">Model</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Model.html#assign">assign</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Model.html#clear">clear</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Model.html#clone">clone</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Model.html#equals">equals</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Model.html#generateId">generateId</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Model.html#isEmpty">isEmpty</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Model.html#normalize">normalize</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Model.html#normalizeField">normalizeField</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Model.html#toJSON">toJSON</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Model.html#toJsonString">toJsonString</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Model.html#validate">validate</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Model.html#validateField">validateField</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Model.html#.Class.create">Class.create</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Model.html#.Class.createArray">Class.createArray</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Model.html#.Class.createPage">Class.createPage</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Model.html#.Class.isNullishOrEmpty">Class.isNullishOrEmpty</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Model.html#.Class.parseJsonString">Class.parseJsonString</a></span></li><li class="nav-heading"><a href="global.html">Globals</a></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#ElementType">ElementType</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#Enumerable">Enumerable</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#Label">Label</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#NameField">NameField</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#NonEmpty">NonEmpty</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#NonEnumerable">NonEnumerable</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#Normalizable">Normalizable</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#Nullable">Nullable</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#Payload">Payload</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#Readonly">Readonly</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#Timeout">Timeout</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#Type">Type</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#Validatable">Validatable</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#assign">assign</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#create">create</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#createArray">createArray</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#createPage">createPage</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#defaultNormalizer">defaultNormalizer</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#defaultValidator">defaultValidator</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#enumNormalizer">enumNormalizer</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#isEnumClass">isEnumClass</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#isEnumerator">isEnumerator</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#isValidPageSource">isValidPageSource</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#normalize">normalize</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#stringifyId">stringifyId</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#toJSON">toJSON</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#toJsonString">toJsonString</a></span></li>
|
|
28
|
+
</nav>
|
|
29
|
+
|
|
30
|
+
<div id="main">
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
<section class="readme">
|
|
51
|
+
<article><h1>js-common-decorator</h1>
|
|
52
|
+
<p><a href="https://npmjs.com/package/@qubit-ltd/common-decorator"><img src="https://img.shields.io/npm/v/@qubit-ltd/common-decorator.svg" alt="npm package"></a>
|
|
53
|
+
<a href="https://www.apache.org/licenses/LICENSE-2.0"><img src="https://img.shields.io/badge/License-Apache-blue.svg" alt="License"></a>
|
|
54
|
+
<a href="README.zh_CN.md"><img src="https://img.shields.io/badge/%E6%96%87%E6%A1%A3-%E4%B8%AD%E6%96%87%E7%89%88-blue.svg" alt="中文文档"></a>
|
|
55
|
+
<a href="https://dl.circleci.com/status-badge/redirect/gh/Haixing-Hu/js-common-decorator/tree/master"><img src="https://dl.circleci.com/status-badge/img/gh/Haixing-Hu/js-common-decorator/tree/master.svg?style=shield" alt="CircleCI"></a>
|
|
56
|
+
<a href="https://coveralls.io/github/Haixing-Hu/js-common-decorator?branch=master"><img src="https://coveralls.io/repos/github/Haixing-Hu/js-common-decorator/badge.svg?branch=master" alt="Coverage Status"></a></p>
|
|
57
|
+
<p><a href="https://npmjs.com/package/@qubit-ltd/common-decorator">@qubit-ltd/common-decorator</a> is a JavaScript library of common decorators,
|
|
58
|
+
provides decorators to add common methods to domain classes. The library
|
|
59
|
+
supports the most recent (currently May 2023)
|
|
60
|
+
<a href="https://github.com/tc39/proposal-decorators">stage 3 proposal of JavaScript decorators</a>.</p>
|
|
61
|
+
<h2><span id="content">Table of Contents</span></h2>
|
|
62
|
+
<ul>
|
|
63
|
+
<li><a href="#usage">Usage</a>
|
|
64
|
+
<ul>
|
|
65
|
+
<li><a href="#model">@Model Decorator</a>
|
|
66
|
+
<ul>
|
|
67
|
+
<li><a href="#model-assign">Instance method: Class.prototype.assign(obj, options = undefined)</a></li>
|
|
68
|
+
<li><a href="#model-clone">Instance method: Class.prototype.clone()</a></li>
|
|
69
|
+
<li><a href="#model-isEmpty">Instance method: Class.prototype.isEmpty()</a></li>
|
|
70
|
+
<li><a href="#model-clear">Instance method: Class.prototype.clear()</a></li>
|
|
71
|
+
<li><a href="#model-equals">Instance method: Class.prototype.equals(other)</a></li>
|
|
72
|
+
<li><a href="#model-generateId">Instance method: Class.prototype.generateId()</a></li>
|
|
73
|
+
<li><a href="#model-normalizeField">Instance method: Class.prototype.normalizeField(field)</a></li>
|
|
74
|
+
<li><a href="#model-normalize">Instance method: Class.prototype.normalize(fields)</a></li>
|
|
75
|
+
<li><a href="#model-validateField">Instance method: Class.prototype.validateField(field)</a></li>
|
|
76
|
+
<li><a href="#model-validate">Instance method: Class.prototype.validate(fields)</a></li>
|
|
77
|
+
<li><a href="#model-toJSON">Instance method: Class.prototype.toJSON(key, options = undefined)</a></li>
|
|
78
|
+
<li><a href="#model-toJsonString">Instance method: Class.prototype.toJsonString(options = undeinfed)</a></li>
|
|
79
|
+
<li><a href="#model-create">Class method: Class.create(obj, options = undefined)</a></li>
|
|
80
|
+
<li><a href="#model-createArray">Class method: Class.createArray(array, options = undefined)</a></li>
|
|
81
|
+
<li><a href="#model-createPage">Class method: Class.createPage(page, options = undefined)</a></li>
|
|
82
|
+
<li><a href="#model-isNullishOrEmpty">Class method: Class.isNullishOrEmpty()</a></li>
|
|
83
|
+
<li><a href="#model-parseJsonString">Class method: Class.parseJsonString(json, options=undefined)</a></li>
|
|
84
|
+
<li><a href="#model-usage-examples">Usage Examples</a></li>
|
|
85
|
+
</ul>
|
|
86
|
+
</li>
|
|
87
|
+
<li><a href="#enum">@Enum Decorator</a>
|
|
88
|
+
<ul>
|
|
89
|
+
<li><a href="#enum-fields">Enumerator Fields</a></li>
|
|
90
|
+
<li><a href="#enum-toString">Instance method: Class.prototype.toString()</a></li>
|
|
91
|
+
<li><a href="#enum-toJSON">Instance method: Class.prototype.toJSON()</a></li>
|
|
92
|
+
<li><a href="#enum-values">Class method: Class.values()</a></li>
|
|
93
|
+
<li><a href="#enum-ofValue">Class method: Class.ofValue(value)</a></li>
|
|
94
|
+
<li><a href="#enum-hasValue">Class method: Class.hasValue(value)</a></li>
|
|
95
|
+
<li><a href="#enum-ofName">Class method: Class.ofName(name)</a></li>
|
|
96
|
+
<li><a href="#enum-hasName">Class method: Class.hasName(name)</a></li>
|
|
97
|
+
<li><a href="#enum-ofCode">Class method: Class.ofCode(code)</a></li>
|
|
98
|
+
<li><a href="#enum-hasCode">Class method: Class.hasCode(code)</a></li>
|
|
99
|
+
<li><a href="#enum-of">Class method: Class.of(expr)</a></li>
|
|
100
|
+
<li><a href="#enum-has">Class method: Class.has(expr)</a></li>
|
|
101
|
+
<li><a href="#enum-usage-example">Usage Example</a></li>
|
|
102
|
+
</ul>
|
|
103
|
+
</li>
|
|
104
|
+
<li><a href="#default-options">DefaultOptions Class</a>
|
|
105
|
+
<ul>
|
|
106
|
+
<li><a href="#default-options-get">Class method: DefaultOptions.get(name)</a></li>
|
|
107
|
+
<li><a href="#default-options-set">Class method: DefaultOptions.set(name, options)</a></li>
|
|
108
|
+
<li><a href="#default-options-merge">Class method: DefaultOptions.merge(name, options)</a></li>
|
|
109
|
+
</ul>
|
|
110
|
+
</li>
|
|
111
|
+
</ul>
|
|
112
|
+
</li>
|
|
113
|
+
<li><a href="#configuration">Configuration</a>
|
|
114
|
+
<ul>
|
|
115
|
+
<li><a href="#webpack">Bundling with webpack</a></li>
|
|
116
|
+
<li><a href="#vite">Bundling with vite</a></li>
|
|
117
|
+
</ul>
|
|
118
|
+
</li>
|
|
119
|
+
<li><a href="#contributing">Contributing</a></li>
|
|
120
|
+
<li><a href="#license">License</a></li>
|
|
121
|
+
</ul>
|
|
122
|
+
<h2><span id="usage">Usage</span></h2>
|
|
123
|
+
<h3><span id="model">@Model Decorator</span></h3>
|
|
124
|
+
<p>This decorator is used to decorate a domain model class, which adds the
|
|
125
|
+
following instance and class methods to the decorated class.</p>
|
|
126
|
+
<p><strong>NOTE:</strong> If the decorated class already implements any of the following methods,
|
|
127
|
+
this decorator will not override the methods already implemented by the decorated
|
|
128
|
+
class.</p>
|
|
129
|
+
<h4><span id="model-assign">Instance method: Class.prototype.assign(obj, options = undefined)</span></h4>
|
|
130
|
+
<ul>
|
|
131
|
+
<li>Parameters:
|
|
132
|
+
<ul>
|
|
133
|
+
<li><code>obj: object</code>: the object whose fields will be copied to this object,
|
|
134
|
+
which may have a different prototype to this object.</li>
|
|
135
|
+
<li><code>options: null|undefined|object</code>: the additional options for the assignment.
|
|
136
|
+
If this argument is <code>undefined</code> or <code>null</code>, the default options will be used.
|
|
137
|
+
The default options can be retrieved by calling <code>DefaultOptions.get('assign')</code>.
|
|
138
|
+
Available options are:
|
|
139
|
+
<ul>
|
|
140
|
+
<li><code>normalize: boolean</code>, indicates whether to normalize this object
|
|
141
|
+
after the assignment. The default value is <code>true</code>.</li>
|
|
142
|
+
<li><code>convertNaming: boolean</code>, indicates whether to convert the naming
|
|
143
|
+
style of the target object. The default value is <code>false</code>.</li>
|
|
144
|
+
<li><code>sourceNamingStyle: string</code>, the naming style of the source object,
|
|
145
|
+
i.e., the first argument of the <code>assign()</code> method. The default value
|
|
146
|
+
of this argument is <code>'LOWER_UNDERSCORE'</code>.</li>
|
|
147
|
+
<li><code>targetNamingStyle: string</code>, the naming style of the target object,
|
|
148
|
+
i.e., the object calling the <code>assign()</code> method. The default value
|
|
149
|
+
of this argument is <code>'LOWER_CAMEL'</code>.</li>
|
|
150
|
+
<li><code>types: object</code>, the additional information about types of fields of
|
|
151
|
+
classes. The keys of this object are the path of the fields or
|
|
152
|
+
sub-fields of the target object, the values are the type of the
|
|
153
|
+
fields, represented as the constructor function of the type.
|
|
154
|
+
The default value is <code>{}</code>.</li>
|
|
155
|
+
<li><code>elementTypes: object</code>, the additional information about types of
|
|
156
|
+
elements of fields of classes. The keys of this object are the path of
|
|
157
|
+
the fields or sub-fields of the target object, the values are the type
|
|
158
|
+
of the elements, represented as the constructor function of the type.
|
|
159
|
+
The default value is <code>{}</code>.</li>
|
|
160
|
+
</ul>
|
|
161
|
+
</li>
|
|
162
|
+
</ul>
|
|
163
|
+
</li>
|
|
164
|
+
<li>Returns:
|
|
165
|
+
<ul>
|
|
166
|
+
<li><code>object</code>: the calling object itself.</li>
|
|
167
|
+
</ul>
|
|
168
|
+
</li>
|
|
169
|
+
</ul>
|
|
170
|
+
<p>This function copies the fields of the object <code>obj</code> to this object, only copying
|
|
171
|
+
fields defined in this object's class. If a field in the <code>obj</code> object is
|
|
172
|
+
<code>undefined</code> or <code>null</code>, it sets the field's value to the default value. Note that
|
|
173
|
+
<code>obj</code> can have a different prototype to this object.</p>
|
|
174
|
+
<h4><span id="model-clone">Instance method: Class.prototype.clone()</span></h4>
|
|
175
|
+
<ul>
|
|
176
|
+
<li>Parameters: none.</li>
|
|
177
|
+
<li>Returns:
|
|
178
|
+
<ul>
|
|
179
|
+
<li><code>object</code>: a instance of the specified class deep cloned from the calling
|
|
180
|
+
object.</li>
|
|
181
|
+
</ul>
|
|
182
|
+
</li>
|
|
183
|
+
</ul>
|
|
184
|
+
<p>This function deep clones the calling object, returning a new instance of the
|
|
185
|
+
specified class with the same property values as the calling object. Note that
|
|
186
|
+
the returned object has the same prototype as the calling object.</p>
|
|
187
|
+
<h4><span id="model-clear">Instance method: Class.prototype.clear()</span></h4>
|
|
188
|
+
<ul>
|
|
189
|
+
<li>Parameters: none.</li>
|
|
190
|
+
<li>Returns:
|
|
191
|
+
<ul>
|
|
192
|
+
<li><code>object</code>: the calling object itself.</li>
|
|
193
|
+
</ul>
|
|
194
|
+
</li>
|
|
195
|
+
</ul>
|
|
196
|
+
<p>This function sets all the properties of this object to their default values.
|
|
197
|
+
The default value of a field is the value of the field of the default
|
|
198
|
+
constructed instance of the class.</p>
|
|
199
|
+
<h4><span id="model-isEmpty">Instance method: Class.prototype.isEmpty()</span></h4>
|
|
200
|
+
<ul>
|
|
201
|
+
<li>Parameters: none.</li>
|
|
202
|
+
<li>Returns:
|
|
203
|
+
<ul>
|
|
204
|
+
<li><code>boolean</code>: whether this object is empty.</li>
|
|
205
|
+
</ul>
|
|
206
|
+
</li>
|
|
207
|
+
</ul>
|
|
208
|
+
<p>This function checks if this object is empty, meaning that all of its fields
|
|
209
|
+
have default values. The default value of a field is the value of the field of
|
|
210
|
+
the default constructed instance of the class.</p>
|
|
211
|
+
<h4><span id="model-equals">Instance method: Class.prototype.equals(other)</span></h4>
|
|
212
|
+
<ul>
|
|
213
|
+
<li>Parameters:
|
|
214
|
+
<ul>
|
|
215
|
+
<li><code>other: object</code>: the object to be compared with this object.</li>
|
|
216
|
+
</ul>
|
|
217
|
+
</li>
|
|
218
|
+
<li>Returns:
|
|
219
|
+
<ul>
|
|
220
|
+
<li><code>boolean</code>: whether this object is deeply equal to <code>other</code>.</li>
|
|
221
|
+
</ul>
|
|
222
|
+
</li>
|
|
223
|
+
</ul>
|
|
224
|
+
<p>This function checks whether this object is deeply equal to <code>other</code>. Two objects
|
|
225
|
+
are deeply equal if and only if they have the same prototype, and all of their
|
|
226
|
+
fields are deeply equal. Two fields are deeply equal if and only if they have
|
|
227
|
+
the same value, or they are both <code>undefined</code> or <code>null</code>. If a field is an array,
|
|
228
|
+
it is deeply equal to another array if and only if they have the same length,
|
|
229
|
+
and all of their elements are deeply equal. If a field is an object, it is
|
|
230
|
+
deeply equal to another object if and only if they have the same prototype,
|
|
231
|
+
and all of their fields are deeply equal.</p>
|
|
232
|
+
<h4><span id="model-generateId">Instance method: Class.prototype.generateId()</span></h4>
|
|
233
|
+
<ul>
|
|
234
|
+
<li>Parameters: none.</li>
|
|
235
|
+
<li>Returns:
|
|
236
|
+
<ul>
|
|
237
|
+
<li><code>string</code>: the string representation of the generated globally unique ID set
|
|
238
|
+
to the calling object.</li>
|
|
239
|
+
</ul>
|
|
240
|
+
</li>
|
|
241
|
+
</ul>
|
|
242
|
+
<p>If the decorated class defines a property named <code>id</code>, this instance method
|
|
243
|
+
<code>generateId()</code> is automatically added to the decorated class. Each call to this
|
|
244
|
+
method generates a globally unique ID for the current calling object
|
|
245
|
+
(represented as a string of an integer), sets the <code>id</code> field of the calling
|
|
246
|
+
object to the generated ID, and returns the generated ID. Note that if a parent
|
|
247
|
+
class <code>A</code> defines the <code>id</code> field, and a subclass <code>B</code> inherits the <code>id</code> field but
|
|
248
|
+
does not define its own <code>id</code> field, the <code>generateId()</code> method is added only to
|
|
249
|
+
class <code>A</code>, not to class <code>B</code>.</p>
|
|
250
|
+
<h4><span id="model-normalizeField">Instance method: Class.prototype.normalizeField(field)</span></h4>
|
|
251
|
+
<ul>
|
|
252
|
+
<li>Parameters:
|
|
253
|
+
<ul>
|
|
254
|
+
<li><code>field: string</code>: the name of the specified field to be normalized.</li>
|
|
255
|
+
</ul>
|
|
256
|
+
</li>
|
|
257
|
+
<li>Returns:
|
|
258
|
+
<ul>
|
|
259
|
+
<li><code>boolean</code>: whether the specified field was normalized.</li>
|
|
260
|
+
</ul>
|
|
261
|
+
</li>
|
|
262
|
+
</ul>
|
|
263
|
+
<p>This function normalizes the specified field of this object. If the object has
|
|
264
|
+
the specified field and the specified field is normalizable, the function
|
|
265
|
+
normalizes the specified field and returns <code>true</code>; otherwise, the function does
|
|
266
|
+
nothing and returns <code>false</code>. Note that a field is normalizable if and only if it
|
|
267
|
+
is decorated by the <code>@Normalizable</code> decorator.</p>
|
|
268
|
+
<h4><span id="model-normalize">Instance method: Class.prototype.normalize(fields)</span></h4>
|
|
269
|
+
<ul>
|
|
270
|
+
<li>Parameters:
|
|
271
|
+
<ul>
|
|
272
|
+
<li><code>fields: undefined | null | string | string[]</code>: the fields to be normalized.
|
|
273
|
+
It can be one of the following values:
|
|
274
|
+
<ul>
|
|
275
|
+
<li><code>undefined</code>: normalizes all the normalizable fields of this object.</li>
|
|
276
|
+
<li><code>null</code>: normalizes all the normalizable fields of this object.</li>
|
|
277
|
+
<li><code>"*"</code>: normalizes all the normalizable fields of this object.</li>
|
|
278
|
+
<li><code>string[]</code>: normalizes all the normalizable fields whose names are
|
|
279
|
+
specified in this array.</li>
|
|
280
|
+
</ul>
|
|
281
|
+
</li>
|
|
282
|
+
</ul>
|
|
283
|
+
</li>
|
|
284
|
+
<li>Returns:
|
|
285
|
+
<ul>
|
|
286
|
+
<li><code>object</code>: the normalized calling object.</li>
|
|
287
|
+
</ul>
|
|
288
|
+
</li>
|
|
289
|
+
</ul>
|
|
290
|
+
<p>This function normalizes the specified fields of this object. The <code>fields</code>
|
|
291
|
+
parameter specifies the names of fields to be normalized. If <code>fields</code> is
|
|
292
|
+
<code>undefined</code>, <code>null</code>, or the string <code>"*"</code>, it normalizes all the normalizable
|
|
293
|
+
fields of this object. If <code>fields</code> is an array of strings, it normalizes all the
|
|
294
|
+
normalizable fields whose names are specified in the array. Note that a field is
|
|
295
|
+
normalizable if and only if it is decorated by the <code>@Normalizable</code> decorator.</p>
|
|
296
|
+
<h4><span id="model-validateField">Instance method: Class.prototype.validateField(field)</span></h4>
|
|
297
|
+
<ul>
|
|
298
|
+
<li>Parameters:
|
|
299
|
+
<ul>
|
|
300
|
+
<li><code>field: string</code>: the name of the specified field to be validated.</li>
|
|
301
|
+
</ul>
|
|
302
|
+
</li>
|
|
303
|
+
<li>Returns:
|
|
304
|
+
<ul>
|
|
305
|
+
<li><code>ValidationResult | null</code>: the validation result.</li>
|
|
306
|
+
</ul>
|
|
307
|
+
</li>
|
|
308
|
+
</ul>
|
|
309
|
+
<p>This function validates the specified field of this object. If the object has
|
|
310
|
+
the specified field and the specified field is validatable, the function
|
|
311
|
+
validates the specified field and returns the validation result; otherwise, the
|
|
312
|
+
function does nothing and returns <code>null</code>. Note that a field is validatable if
|
|
313
|
+
and only if it is decorated by the <code>@Validatable</code> decorator.</p>
|
|
314
|
+
<h4><span id="model-validate">Instance method: Class.prototype.validate(fields)</span></h4>
|
|
315
|
+
<ul>
|
|
316
|
+
<li>Parameters:
|
|
317
|
+
<ul>
|
|
318
|
+
<li><code>fields: undefined | null | string | string[]</code>: the fields to be validated.
|
|
319
|
+
It can be one of the following values:
|
|
320
|
+
<ul>
|
|
321
|
+
<li><code>undefined</code>: validates all the validatable fields of this object.</li>
|
|
322
|
+
<li><code>null</code>: validates all the validatable fields of this object.</li>
|
|
323
|
+
<li><code>"*"</code>: validates all the validatable fields of this object.</li>
|
|
324
|
+
<li><code>string[]</code>: validates all the validatable fields whose names are
|
|
325
|
+
specified in this array.</li>
|
|
326
|
+
</ul>
|
|
327
|
+
</li>
|
|
328
|
+
</ul>
|
|
329
|
+
</li>
|
|
330
|
+
<li>Returns:
|
|
331
|
+
<ul>
|
|
332
|
+
<li><code>ValidationResult</code>: the validation result.</li>
|
|
333
|
+
</ul>
|
|
334
|
+
</li>
|
|
335
|
+
</ul>
|
|
336
|
+
<p>This function validates the specified fields of this object. The <code>fields</code>
|
|
337
|
+
parameter specifies the names of fields to be validated. If <code>fields</code> is
|
|
338
|
+
<code>undefined</code>, <code>null</code>, or the string <code>"*"</code>, it validates all the validatable
|
|
339
|
+
fields of this object. If <code>fields</code> is an array of strings, it validates all the
|
|
340
|
+
validatable fields whose names are specified in the array. Note that a field is
|
|
341
|
+
validatable if and only if it is decorated by the <code>@Validatable</code>
|
|
342
|
+
decorator.</p>
|
|
343
|
+
<h4><span id="model-toJSON">Instance method: Class.prototype.toJSON(key, options = undefined)</span></h4>
|
|
344
|
+
<ul>
|
|
345
|
+
<li>Parameters:
|
|
346
|
+
<ul>
|
|
347
|
+
<li><code>key: string</code>:<code>JSON.stringify()</code> calls <code>toJSON()</code> with one parameter,
|
|
348
|
+
the <code>key</code>,which takes the following values:
|
|
349
|
+
<ul>
|
|
350
|
+
<li>if this object is a property value, this argument is the property
|
|
351
|
+
name;</li>
|
|
352
|
+
<li>if this object is in an array, this argument is the index in the
|
|
353
|
+
array, as a string;</li>
|
|
354
|
+
<li>if <code>JSON.stringify()</code> was directly called on this object, this
|
|
355
|
+
argument is an empty string.</li>
|
|
356
|
+
</ul>
|
|
357
|
+
</li>
|
|
358
|
+
<li><code>options: null|undefined|object</code>: the additional options for the
|
|
359
|
+
serialization. If this argument is <code>undefined</code> or <code>null</code>, the default
|
|
360
|
+
options will be used. The default options can be retrieved by calling
|
|
361
|
+
<code>DefaultOptions.get('toJSON')</code>. Available options are:
|
|
362
|
+
<ul>
|
|
363
|
+
<li><code>normalize: boolean</code>, indicates whether to normalize this object
|
|
364
|
+
before serializing. The default value is <code>true</code>.</li>
|
|
365
|
+
<li><code>removeEmptyFields: boolean</code>, indicates whether to ignore the empty
|
|
366
|
+
fields of the object. If it is <code>true</code>, the empty fields of the object
|
|
367
|
+
will be removed before serialization. The default value is <code>false</code>.</li>
|
|
368
|
+
<li><code>convertNaming: boolean</code>, indicates whether to convert the naming
|
|
369
|
+
of properties of the object represented by the result JSON string.
|
|
370
|
+
The default value is <code>false</code>.</li>
|
|
371
|
+
<li><code>sourceNamingStyle: string</code>, the naming style of the source object,
|
|
372
|
+
i.e., the object calling the <code>toJSON()</code> method. The default value
|
|
373
|
+
of this argument is <code>'LOWER_CAMEL'</code>.</li>
|
|
374
|
+
<li><code>targetNamingStyle: string</code>, the naming style of the target object,
|
|
375
|
+
i.e., the object represented by the result JSON string of the
|
|
376
|
+
<code>toJSON()</code> method. The default value of this argument is
|
|
377
|
+
<code>'LOWER_UNDERSCORE'</code>.</li>
|
|
378
|
+
<li><code>space: string | number</code>, a string or number that's used to insert
|
|
379
|
+
white space (including indentation, line break characters, etc.) into
|
|
380
|
+
the output JSON string for readability purposes. If this is a number,
|
|
381
|
+
it indicates the number of space characters to be used as indentation,
|
|
382
|
+
clamped to 10 (that is, any number greater than 10 is treated as if
|
|
383
|
+
it were 10). Values less than 1 indicate that no space should be used.
|
|
384
|
+
If this is a string, the string (or the first 10 characters of the
|
|
385
|
+
string, if it's longer than that) is inserted before every nested
|
|
386
|
+
object or array. If this is anything other than a string or number
|
|
387
|
+
(can be either a primitive or a wrapper object) — for example, is
|
|
388
|
+
<code>null</code> or not provided — no white space is used. The default value
|
|
389
|
+
of this option is <code>null</code>.</li>
|
|
390
|
+
</ul>
|
|
391
|
+
</li>
|
|
392
|
+
</ul>
|
|
393
|
+
</li>
|
|
394
|
+
<li>Returns:
|
|
395
|
+
<ul>
|
|
396
|
+
<li><code>object</code>: the object to be serialized by <code>JSON.stringify()</code>, which may be
|
|
397
|
+
a modify copy of this object.</li>
|
|
398
|
+
</ul>
|
|
399
|
+
</li>
|
|
400
|
+
</ul>
|
|
401
|
+
<p>This function gets the object to be serialized by <code>JSON.stringify()</code>.
|
|
402
|
+
If the value has a <code>toJSON()</code> method, it's responsible to define what
|
|
403
|
+
data will be serialized. Instead of the object being serialized, the value
|
|
404
|
+
returned by the <code>toJSON()</code> method when called will be serialized.</p>
|
|
405
|
+
<p><strong>NOTE:</strong> this function returns an object to be serialized by
|
|
406
|
+
<code>JSON.stringify()</code>, instead of a JSON string. Use <code>JSON.stringify()</code>
|
|
407
|
+
or <code>this.toJsonString()</code> methods to serialize this object into a JSON
|
|
408
|
+
string.</p>
|
|
409
|
+
<h4><span id="model-toJsonString">Instance method: Class.prototype.toJsonString(options = undefined)</span></h4>
|
|
410
|
+
<ul>
|
|
411
|
+
<li>Parameters:
|
|
412
|
+
<ul>
|
|
413
|
+
<li><code>options: null|undefined|object</code>: the additional options for the
|
|
414
|
+
serialization. If this argument is <code>undefined</code> or <code>null</code>, the default
|
|
415
|
+
options will be used. The default options can be retrieved by calling
|
|
416
|
+
<code>DefaultOptions.get('toJSON')</code>. Available options are:
|
|
417
|
+
<ul>
|
|
418
|
+
<li><code>normalize: boolean</code>, indicates whether to normalize this object
|
|
419
|
+
before serializing. The default value is <code>true</code>.</li>
|
|
420
|
+
<li><code>removeEmptyFields: boolean</code>, indicates whether to ignore the empty
|
|
421
|
+
fields of the object. If it is <code>true</code>, the empty fields of the object
|
|
422
|
+
will be removed before serialization. The default value is <code>false</code>.</li>
|
|
423
|
+
<li><code>convertNaming: boolean</code>, indicates whether to convert the naming
|
|
424
|
+
of properties of the object represented by the result JSON string.
|
|
425
|
+
The default value is <code>false</code>.</li>
|
|
426
|
+
<li><code>sourceNamingStyle: string</code>, the naming style of the source object,
|
|
427
|
+
i.e., the object calling the <code>toJSON()</code> method. The default value
|
|
428
|
+
of this argument is <code>'LOWER_CAMEL'</code>.</li>
|
|
429
|
+
<li><code>targetNamingStyle: string</code>, the naming style of the target object,
|
|
430
|
+
i.e., the object represented by the result JSON string of the
|
|
431
|
+
<code>toJSON()</code> method. The default value of this argument is
|
|
432
|
+
<code>'LOWER_UNDERSCORE'</code>.</li>
|
|
433
|
+
<li><code>space: string | number</code>, a string or number that's used to insert
|
|
434
|
+
white space (including indentation, line break characters, etc.) into
|
|
435
|
+
the output JSON string for readability purposes. If this is a number,
|
|
436
|
+
it indicates the number of space characters to be used as indentation,
|
|
437
|
+
clamped to 10 (that is, any number greater than 10 is treated as if
|
|
438
|
+
it were 10). Values less than 1 indicate that no space should be used.
|
|
439
|
+
If this is a string, the string (or the first 10 characters of the
|
|
440
|
+
string, if it's longer than that) is inserted before every nested
|
|
441
|
+
object or array. If this is anything other than a string or number
|
|
442
|
+
(can be either a primitive or a wrapper object) — for example, is
|
|
443
|
+
<code>null</code> or not provided — no white space is used. The default value
|
|
444
|
+
of this option is <code>null</code>.</li>
|
|
445
|
+
</ul>
|
|
446
|
+
</li>
|
|
447
|
+
</ul>
|
|
448
|
+
</li>
|
|
449
|
+
<li>Returns:
|
|
450
|
+
<ul>
|
|
451
|
+
<li><code>string</code>: the JSON string serialized from this object, as <code>JSON.stringify()</code>
|
|
452
|
+
does, except that this function provides additional stringification
|
|
453
|
+
options.</li>
|
|
454
|
+
</ul>
|
|
455
|
+
</li>
|
|
456
|
+
</ul>
|
|
457
|
+
<p>This function serializes this object into a JSON string.</p>
|
|
458
|
+
<p><strong>NOTE:</strong> This method supports native <code>bigint</code> value. For example, the
|
|
459
|
+
<code>bigint</code> value <code>9223372036854775807n</code> will be stringify as
|
|
460
|
+
<code>9223372036854775807</code>.</p>
|
|
461
|
+
<h4><span id="model-create">Class method: Class.create(obj, options = undefined)</span></h4>
|
|
462
|
+
<ul>
|
|
463
|
+
<li>Parameters:
|
|
464
|
+
<ul>
|
|
465
|
+
<li><code>obj: object</code>: the data object used to create the new instance.</li>
|
|
466
|
+
<li><code>options: null|undefined|object</code>: the additional options for the creation.
|
|
467
|
+
If this argument is <code>undefined</code> or <code>null</code>, the default options will be used.
|
|
468
|
+
The default options can be retrieved by calling <code>DefaultOptions.get('assign')</code>.
|
|
469
|
+
Available options are:
|
|
470
|
+
<ul>
|
|
471
|
+
<li><code>normalize: boolean</code>, indicates whether to normalize this object
|
|
472
|
+
after the assignment. The default value is <code>true</code>.</li>
|
|
473
|
+
<li><code>convertNaming: boolean</code>, indicates whether to convert the naming
|
|
474
|
+
style of the target object. The default value is <code>false</code>.</li>
|
|
475
|
+
<li><code>sourceNamingStyle: string</code>, the naming style of the source object,
|
|
476
|
+
i.e., the first argument of the <code>create()</code> method. The default
|
|
477
|
+
value of this argument is <code>'LOWER_UNDERSCORE'</code>.</li>
|
|
478
|
+
<li><code>targetNamingStyle: string</code>, the naming style of the target object,
|
|
479
|
+
i.e., the object returned by the <code>create()</code> method. The default
|
|
480
|
+
value of this argument is <code>'LOWER_CAMEL'</code>.</li>
|
|
481
|
+
<li><code>types: object</code>, the additional information about types of
|
|
482
|
+
fields of classes. The keys of this object are the path of the fields
|
|
483
|
+
or sub-fields of the target object, the values are the type of the
|
|
484
|
+
fields, represented as the constructor function of the type.
|
|
485
|
+
The default value is <code>{}</code>.</li>
|
|
486
|
+
<li><code>elementTypes: object</code>, the additional information about types of
|
|
487
|
+
elements of fields of classes. The keys of this object are the path of
|
|
488
|
+
the fields or sub-fields of the target object, the values are the type
|
|
489
|
+
of the elements, represented as the constructor function of the type.
|
|
490
|
+
The default value is <code>{}</code>.</li>
|
|
491
|
+
</ul>
|
|
492
|
+
</li>
|
|
493
|
+
</ul>
|
|
494
|
+
</li>
|
|
495
|
+
<li>Returns:
|
|
496
|
+
<ul>
|
|
497
|
+
<li><code>object | null</code>: if the <code>obj</code> is <code>undefined</code> or <code>null</code>, returns <code>null</code>;
|
|
498
|
+
otherwise, returns a new instance of the model class whose fields are
|
|
499
|
+
initialized with the data in the <code>obj</code>.</li>
|
|
500
|
+
</ul>
|
|
501
|
+
</li>
|
|
502
|
+
</ul>
|
|
503
|
+
<p>This function creates a instance of the specified class from a data object,
|
|
504
|
+
whose fields are recursively initialized with properties in the <code>obj</code>. Note that
|
|
505
|
+
<code>obj</code> can have a different prototype to the specified class.</p>
|
|
506
|
+
<h4><span id="model-createArray">Class method: Class.createArray(array, options = undefined)</span></h4>
|
|
507
|
+
<ul>
|
|
508
|
+
<li>Parameters:
|
|
509
|
+
<ul>
|
|
510
|
+
<li><code>array: object[]</code>: the data object array used to create the new array.</li>
|
|
511
|
+
<li><code>options: null|undefined|object</code>: the additional options for the creation.
|
|
512
|
+
If this argument is <code>undefined</code> or <code>null</code>, the default options will be used.
|
|
513
|
+
The default options can be retrieved by calling <code>DefaultOptions.get('assign')</code>.
|
|
514
|
+
Available options are:
|
|
515
|
+
<ul>
|
|
516
|
+
<li><code>normalize: boolean</code>, indicates whether to normalize this object
|
|
517
|
+
after the assignment. The default value is <code>true</code>.</li>
|
|
518
|
+
<li><code>convertNaming: boolean</code>, indicates whether to convert the naming
|
|
519
|
+
style of the target object. The default value is <code>false</code>.</li>
|
|
520
|
+
<li><code>sourceNamingStyle: string</code>, the naming style of the source object,
|
|
521
|
+
i.e., the elements in the first argument of the <code>createArray()</code>
|
|
522
|
+
method. The default value of this argument is <code>'LOWER_UNDERSCORE'</code>.</li>
|
|
523
|
+
<li><code>targetNamingStyle: string</code>, the naming style of the target object,
|
|
524
|
+
i.e., the elements in the array returned by the <code>createArray()</code>
|
|
525
|
+
method. The default value of this argument is <code>'LOWER_CAMEL'</code>.</li>
|
|
526
|
+
<li><code>types: object</code>, the additional information about types of
|
|
527
|
+
fields of classes. The keys of this object are the path of the fields
|
|
528
|
+
or sub-fields of the target object, the values are the type of the
|
|
529
|
+
fields, represented as the constructor function of the type.
|
|
530
|
+
The default value is <code>{}</code>.</li>
|
|
531
|
+
<li><code>elementTypes: object</code>, the additional information about types of
|
|
532
|
+
elements of fields of classes. The keys of this object are the path of
|
|
533
|
+
the fields or sub-fields of the target object, the values are the type
|
|
534
|
+
of the elements, represented as the constructor function of the type.
|
|
535
|
+
The default value is <code>{}</code>.</li>
|
|
536
|
+
</ul>
|
|
537
|
+
</li>
|
|
538
|
+
</ul>
|
|
539
|
+
</li>
|
|
540
|
+
<li>Returns:
|
|
541
|
+
<ul>
|
|
542
|
+
<li><code>object[] | null</code>: if the <code>array</code> is <code>undefined</code> or <code>null</code>, returns <code>null</code>;
|
|
543
|
+
otherwise, returns a new array of instances of the model class whose
|
|
544
|
+
fields are initialized with corresponding data object in the <code>array</code>.</li>
|
|
545
|
+
</ul>
|
|
546
|
+
</li>
|
|
547
|
+
</ul>
|
|
548
|
+
<p>This function creates an array of instances of the specified class from a data
|
|
549
|
+
object array. The fields of instances in the returned array are recursively
|
|
550
|
+
initialized with corresponding properties of the corresponding data object in
|
|
551
|
+
the <code>array</code>. Note that data objects in <code>array</code> can have different prototypes to
|
|
552
|
+
the specified class.</p>
|
|
553
|
+
<h4><span id="model-createPage">Class method: Class.createPage(page, options = undefined)</span></h4>
|
|
554
|
+
<ul>
|
|
555
|
+
<li>Parameters:
|
|
556
|
+
<ul>
|
|
557
|
+
<li><code>page: object</code>: the pagination data object used to create the new <code>Page</code>
|
|
558
|
+
instance.</li>
|
|
559
|
+
<li><code>options: null|undefined|object</code>: the additional options for the creation.
|
|
560
|
+
If this argument is <code>undefined</code> or <code>null</code>, the default options will be used.
|
|
561
|
+
The default options can be retrieved by calling <code>DefaultOptions.get('assign')</code>.
|
|
562
|
+
Available options are:
|
|
563
|
+
<ul>
|
|
564
|
+
<li><code>normalize: boolean</code>, indicates whether to normalize this object
|
|
565
|
+
after the assignment. The default value is <code>true</code>.</li>
|
|
566
|
+
<li><code>convertNaming: boolean</code>, indicates whether to convert the naming
|
|
567
|
+
style of the target object. The default value is <code>false</code>.</li>
|
|
568
|
+
<li><code>sourceNamingStyle: string</code>, the naming style of the source object,
|
|
569
|
+
i.e., the elements in the <code>content</code> array of the first argument of
|
|
570
|
+
the <code>createPage()</code> method. The default value of this argument is
|
|
571
|
+
<code>'LOWER_UNDERSCORE'</code>.</li>
|
|
572
|
+
<li><code>targetNamingStyle: string</code>, the naming style of the target object,
|
|
573
|
+
i.e., the elements in the <code>content</code> array of the <code>Page</code> object
|
|
574
|
+
returned by the <code>createPage()</code> method. The default value of this
|
|
575
|
+
argument is <code>'LOWER_CAMEL'</code>.</li>
|
|
576
|
+
<li><code>types: object</code>, the additional information about types of
|
|
577
|
+
fields of classes. The keys of this object are the path of the fields
|
|
578
|
+
or sub-fields of the target object, the values are the type of the
|
|
579
|
+
fields, represented as the constructor function of the type.
|
|
580
|
+
The default value is <code>{}</code>.</li>
|
|
581
|
+
<li><code>elementTypes: object</code>, the additional information about types of
|
|
582
|
+
elements of fields of classes. The keys of this object are the path of
|
|
583
|
+
the fields or sub-fields of the target object, the values are the type
|
|
584
|
+
of the elements, represented as the constructor function of the type.
|
|
585
|
+
The default value is <code>{}</code>.</li>
|
|
586
|
+
</ul>
|
|
587
|
+
</li>
|
|
588
|
+
</ul>
|
|
589
|
+
</li>
|
|
590
|
+
<li>Returns:
|
|
591
|
+
<ul>
|
|
592
|
+
<li><code>Page | null</code>: if the <code>page</code> is <code>undefined</code> or <code>null</code>, returns <code>null</code>;
|
|
593
|
+
otherwise, returns a new instance of the <code>Page</code> class whose content are
|
|
594
|
+
initialized with the content of the pagination data object <code>page</code>.</li>
|
|
595
|
+
</ul>
|
|
596
|
+
</li>
|
|
597
|
+
</ul>
|
|
598
|
+
<p>This function creates a <code>Page</code> object, whose content are initialized with the
|
|
599
|
+
content of the specified pagination data object. Typically, <code>page</code> is a list of
|
|
600
|
+
domain objects obtained from a server using the <code>GET</code> method, and the object
|
|
601
|
+
should conform to the <code>Page</code> class definition. This class method returns
|
|
602
|
+
a new <code>Page</code> object, with the <code>content</code> property being the result of
|
|
603
|
+
<code>createArray(page.content, options)</code>, and the other properties matching those of
|
|
604
|
+
the <code>page</code> object. If <code>page</code> is not a valid <code>Page</code> object, it returns <code>null</code>.</p>
|
|
605
|
+
<h4><span id="model-isNullishOrEmpty">Class method: Class.isNullishOrEmpty(obj)</span></h4>
|
|
606
|
+
<ul>
|
|
607
|
+
<li>Parameters:
|
|
608
|
+
<ul>
|
|
609
|
+
<li><code>obj: object</code>: the object to be checked.</li>
|
|
610
|
+
</ul>
|
|
611
|
+
</li>
|
|
612
|
+
<li>Returns:
|
|
613
|
+
<ul>
|
|
614
|
+
<li><code>boolean</code>: whether the specified object is <code>undefined</code>, <code>null</code>, or an
|
|
615
|
+
empty object constructed with default values.</li>
|
|
616
|
+
</ul>
|
|
617
|
+
</li>
|
|
618
|
+
</ul>
|
|
619
|
+
<p>This function checks whether the specified object is <code>undefined</code>, <code>null</code>, or an
|
|
620
|
+
empty object constructed with default values. An object is empty if and only if
|
|
621
|
+
all of its fields have default values. The default value of a field is the value
|
|
622
|
+
of the field of the default constructed instance of the class. This function is
|
|
623
|
+
a convenient method to call <code>Class.prototype.isEmpty()</code>, with the handling of
|
|
624
|
+
nullish values.</p>
|
|
625
|
+
<h4><span id="model-parseJsonString">Class method: Class.parseJsonString(json, options = undefined)</span></h4>
|
|
626
|
+
<ul>
|
|
627
|
+
<li>Parameters:
|
|
628
|
+
<ul>
|
|
629
|
+
<li><code>json: string</code>: the JSON string to be parsed.</li>
|
|
630
|
+
<li><code>options: null|undefined|object</code>: the additional options for the parsing.
|
|
631
|
+
If this argument is <code>undefined</code> or <code>null</code>, the default options will be used.
|
|
632
|
+
The default options can be retrieved by calling <code>DefaultOptions.get('assign')</code>.
|
|
633
|
+
Available options are:
|
|
634
|
+
<ul>
|
|
635
|
+
<li><code>normalize: boolean</code>, indicates whether to normalize this object
|
|
636
|
+
after the assignment. The default value is <code>true</code>.</li>
|
|
637
|
+
<li><code>convertNaming: boolean</code>, indicates whether to convert the naming
|
|
638
|
+
style of properties of the object represented by the JSON string.
|
|
639
|
+
The default value is <code>false</code>.</li>
|
|
640
|
+
<li><code>sourceNamingStyle: string</code>, the naming style of the source object,
|
|
641
|
+
i.e., the object represented by the JSON string. The default value
|
|
642
|
+
of this argument is <code>'LOWER_UNDERSCORE'</code>.</li>
|
|
643
|
+
<li><code>targetNamingStyle: string</code>, the naming style of the target object,
|
|
644
|
+
i.e., the object returned by the <code>parseJsonString()</code> method. The
|
|
645
|
+
default value of this argument is <code>'LOWER_CAMEL'</code>.</li>
|
|
646
|
+
</ul>
|
|
647
|
+
</li>
|
|
648
|
+
</ul>
|
|
649
|
+
</li>
|
|
650
|
+
<li>Returns:
|
|
651
|
+
<ul>
|
|
652
|
+
<li><code>boolean</code>: whether the specified object is <code>undefined</code>, <code>null</code>, or an
|
|
653
|
+
empty object constructed with default values.</li>
|
|
654
|
+
</ul>
|
|
655
|
+
</li>
|
|
656
|
+
</ul>
|
|
657
|
+
<p>This function parses an object of this class from a JSON string.</p>
|
|
658
|
+
<p><strong>NOTE:</strong> This method supports integer values fall out of IEEE 754 integer
|
|
659
|
+
precision. For example, the integer value <code>9223372036854775807</code> will be
|
|
660
|
+
parsed as the native <code>bigint</code> value <code>9223372036854775807n</code>.</p>
|
|
661
|
+
<h4><span id="model-usage-examples">Usage Examples</span></h4>
|
|
662
|
+
<p>The following is the usage example of the <code>@Model</code> decorator.</p>
|
|
663
|
+
<pre class="prettyprint source lang-js"><code>@Model
|
|
664
|
+
class Credential {
|
|
665
|
+
|
|
666
|
+
@Normalizable
|
|
667
|
+
@Validator(validateCredentialTypeField)
|
|
668
|
+
@Type(CredentialType)
|
|
669
|
+
@Label('证件类型')
|
|
670
|
+
type = 'IDENTITY_CARD';
|
|
671
|
+
|
|
672
|
+
@Normalizable(trimUppercaseString)
|
|
673
|
+
@Validator(validateCredentialNumberField)
|
|
674
|
+
@Label('证件号码')
|
|
675
|
+
number = '';
|
|
676
|
+
|
|
677
|
+
constructor(type = CredentialType.DEFAULT.value, number = '') {
|
|
678
|
+
this.type = type;
|
|
679
|
+
this.number = number;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
isIdentityCard() {
|
|
683
|
+
return (this.type === 'IDENTITY_CARD');
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
@Model
|
|
688
|
+
class Person {
|
|
689
|
+
|
|
690
|
+
@Normalizable(trimString)
|
|
691
|
+
@Label('ID')
|
|
692
|
+
id = null;
|
|
693
|
+
|
|
694
|
+
@Normalizable(trimUppercaseString)
|
|
695
|
+
@Validator(validatePersonNameField)
|
|
696
|
+
@Label('姓名')
|
|
697
|
+
name = '';
|
|
698
|
+
|
|
699
|
+
@Normalizable
|
|
700
|
+
@DefaultValidator
|
|
701
|
+
@Type(Credential)
|
|
702
|
+
@Label('证件')
|
|
703
|
+
credential = null;
|
|
704
|
+
|
|
705
|
+
@Normalizable
|
|
706
|
+
@Validator(validatePersonGenderField)
|
|
707
|
+
@Type(Gender)
|
|
708
|
+
@Label('性别')
|
|
709
|
+
gender = '';
|
|
710
|
+
|
|
711
|
+
@Normalizable(trimString)
|
|
712
|
+
@Validator(validatePersonBirthdayField)
|
|
713
|
+
@Label('出生日期')
|
|
714
|
+
birthday = '';
|
|
715
|
+
|
|
716
|
+
@Normalizable(trimUppercaseString)
|
|
717
|
+
@Validator(validateMobileField)
|
|
718
|
+
@Label('手机号码')
|
|
719
|
+
mobile = '';
|
|
720
|
+
|
|
721
|
+
@Normalizable(trimString)
|
|
722
|
+
@Validator(validateEmailField)
|
|
723
|
+
@Label('电子邮件地址')
|
|
724
|
+
@Nullable
|
|
725
|
+
email = '';
|
|
726
|
+
|
|
727
|
+
equals(other) {
|
|
728
|
+
if (!(other instanceof PersonWithEquals)) {
|
|
729
|
+
return false;
|
|
730
|
+
}
|
|
731
|
+
if ((this.credential === null) || (other.credential === null)) {
|
|
732
|
+
// If one of the two people does not have ID inofmation, it is impossible
|
|
733
|
+
// to compare whether they are the same person thus they will be considered
|
|
734
|
+
// different.
|
|
735
|
+
return false;
|
|
736
|
+
}
|
|
737
|
+
// Two persons are logically equals if and only if they have the same
|
|
738
|
+
// credential.
|
|
739
|
+
return (this.credential.type === other.credential.type)
|
|
740
|
+
&& (this.credential.number === other.credential.number);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
</code></pre>
|
|
744
|
+
<p>After applying the <code>@Model</code> decorator, the following methods will be automatically
|
|
745
|
+
added:</p>
|
|
746
|
+
<ul>
|
|
747
|
+
<li><code>Credential.prototype.assign(obj, options = undefined)</code></li>
|
|
748
|
+
<li><code>Credential.prototype.clear()</code></li>
|
|
749
|
+
<li><code>Credential.prototype.clone()</code></li>
|
|
750
|
+
<li><code>Credential.prototype.isEmpty()</code></li>
|
|
751
|
+
<li><code>Credential.prototype.equals(obj)</code></li>
|
|
752
|
+
<li><code>Credential.prototype.normalize(fields)</code></li>
|
|
753
|
+
<li><code>Credential.prototype.validate(fields, options)</code></li>
|
|
754
|
+
<li><code>Credential.prototype.toJSON(key, options = undefined)</code></li>
|
|
755
|
+
<li><code>Credential.prototype.toJsonString(options = undefined)</code></li>
|
|
756
|
+
<li><code>Credential.create(obj, options = undefined)</code></li>
|
|
757
|
+
<li><code>Credential.createArray(array, options = undefined)</code></li>
|
|
758
|
+
<li><code>Credential.createPage(page, options = undefined)</code></li>
|
|
759
|
+
<li><code>Credential.isNullishOrEmpty(obj)</code></li>
|
|
760
|
+
<li><code>Credential.parseJsonString(json, options = undefined)</code></li>
|
|
761
|
+
<li><code>Person.prototype.assign(obj, normalized)</code></li>
|
|
762
|
+
<li><code>Person.prototype.clear()</code></li>
|
|
763
|
+
<li><code>Person.prototype.clone()</code></li>
|
|
764
|
+
<li><code>Person.prototype.isEmpty()</code></li>
|
|
765
|
+
<li><code>Person.prototype.normalize(fields)</code></li>
|
|
766
|
+
<li><code>Person.prototype.validate(fields, options)</code></li>
|
|
767
|
+
<li><code>Person.prototype.generateId()</code></li>
|
|
768
|
+
<li><code>Person.prototype.toJSON(key, options = undefined)</code></li>
|
|
769
|
+
<li><code>Person.prototype.toJsonString(options = undefined)</code></li>
|
|
770
|
+
<li><code>Person.create(obj, options = undefined)</code></li>
|
|
771
|
+
<li><code>Person.createArray(array, options = undefined)</code></li>
|
|
772
|
+
<li><code>Person.createPage(page, options = undefined)</code></li>
|
|
773
|
+
<li><code>Person.isNullishOrEmpty(obj)</code></li>
|
|
774
|
+
<li><code>Person.parseJsonString(json, options = undefined)</code></li>
|
|
775
|
+
<li></li>
|
|
776
|
+
</ul>
|
|
777
|
+
<p><strong>NOTE:</strong></p>
|
|
778
|
+
<ul>
|
|
779
|
+
<li>Because the <code>Credential</code> class does not have an <code>id</code> attribute, the <code>@Model</code>
|
|
780
|
+
decorator does not add a <code>generateId()</code> instance method to it.</li>
|
|
781
|
+
<li>Because <code>Person</code> already implements the <code>Person.prototype.equals()</code> method,
|
|
782
|
+
the <code>@Model</code> decorator will <strong>not</strong> override its own implementation of
|
|
783
|
+
the <code>Person.prototype.equals()</code> method.</li>
|
|
784
|
+
</ul>
|
|
785
|
+
<h3><span id="enum">@Enum Decorator</span></h3>
|
|
786
|
+
<p>This decorator is used to decorate an enumeration class.</p>
|
|
787
|
+
<h4><span id="enum-fields">Enumerator Fields</span></h4>
|
|
788
|
+
<p>An enumeration class is a class whose instances are enumerators. An enumerator
|
|
789
|
+
is an object with the following properties:</p>
|
|
790
|
+
<ul>
|
|
791
|
+
<li><code>value</code>:the value of the enumerator, which is exactly the name of the
|
|
792
|
+
static field of the enumeration class that corresponds to the enumerator.</li>
|
|
793
|
+
<li><code>name</code>: the display name of the enumerator, which could be specified
|
|
794
|
+
by the default string or object value of the static field of the
|
|
795
|
+
enumeration class that corresponds to the enumerator. It the default value
|
|
796
|
+
is not specified, the name of the enumerator is the same as its value.</li>
|
|
797
|
+
<li><code>i18n</code>: the i18n key of the enumerator, which is an optional property. It
|
|
798
|
+
could be specified by the default object value of the static field of the
|
|
799
|
+
enumeration class that corresponds to the enumerator. If this property is
|
|
800
|
+
specified, the <code>name</code> property will be transformed to a <code>getter</code>, which will
|
|
801
|
+
get the i18n value of the enumerator from the i18n resource bundle.</li>
|
|
802
|
+
<li><code>code</code>: the code of the enumerator, which is an optional property. It could
|
|
803
|
+
be specified by the default object value of the static field of the
|
|
804
|
+
enumeration class that corresponds to the enumerator.</li>
|
|
805
|
+
<li>other properties: other properties of the enumerator could be specified
|
|
806
|
+
by the default object value of the static field of the enumeration class
|
|
807
|
+
that corresponds to the enumerator.</li>
|
|
808
|
+
</ul>
|
|
809
|
+
<h4><span id="enum-toString">Instance method: Class.prototype.toString()</span></h4>
|
|
810
|
+
<ul>
|
|
811
|
+
<li>Parameters: none.</li>
|
|
812
|
+
<li>Returns:
|
|
813
|
+
<ul>
|
|
814
|
+
<li><code>string</code>: the string representation of this enumerator, which is the
|
|
815
|
+
<code>value</code> of this enumerator.</li>
|
|
816
|
+
</ul>
|
|
817
|
+
</li>
|
|
818
|
+
</ul>
|
|
819
|
+
<p>This function returns the string representation of this enumerator, which is
|
|
820
|
+
the <code>value</code> of this enumerator.</p>
|
|
821
|
+
<h4><span id="enum-toJSON">Instance method: Class.prototype.toJSON()</span></h4>
|
|
822
|
+
<ul>
|
|
823
|
+
<li>Parameters: none.</li>
|
|
824
|
+
<li>Returns:
|
|
825
|
+
<ul>
|
|
826
|
+
<li><code>string</code>: the JSON representation of this enumerator, which is the JSON
|
|
827
|
+
string representation of the <code>value</code> of this enumerator, i.e., the double
|
|
828
|
+
quoted string of the <code>value</code>.</li>
|
|
829
|
+
</ul>
|
|
830
|
+
</li>
|
|
831
|
+
</ul>
|
|
832
|
+
<p>This function returns the JSON representation of this enumerator.</p>
|
|
833
|
+
<h4><span id="enum-values">Class method: Class.values()</span></h4>
|
|
834
|
+
<ul>
|
|
835
|
+
<li>Parameters: none.</li>
|
|
836
|
+
<li>Returns:
|
|
837
|
+
<ul>
|
|
838
|
+
<li><code>Class[]</code>: the array of all enumerators of this enumeration class.</li>
|
|
839
|
+
</ul>
|
|
840
|
+
</li>
|
|
841
|
+
</ul>
|
|
842
|
+
<p>This function returns the array of all enumerators of this enumeration class.</p>
|
|
843
|
+
<h4><span id="enum-ofValue">Class method: Class.ofValue(value)</span></h4>
|
|
844
|
+
<ul>
|
|
845
|
+
<li>Parameters:
|
|
846
|
+
<ul>
|
|
847
|
+
<li><code>value: string</code>: the value of the enumerator to be returned. Note that this
|
|
848
|
+
argument will be trimmed and uppercased to get the actual value of the
|
|
849
|
+
enumerator.</li>
|
|
850
|
+
</ul>
|
|
851
|
+
</li>
|
|
852
|
+
<li>Returns:
|
|
853
|
+
<ul>
|
|
854
|
+
<li><code>Class</code>: the enumerator in this enumeration class with the specified value,
|
|
855
|
+
or <code>undefined</code> if no such enumerator exists.</li>
|
|
856
|
+
</ul>
|
|
857
|
+
</li>
|
|
858
|
+
</ul>
|
|
859
|
+
<p>This function returns the enumerator with the specified value.</p>
|
|
860
|
+
<h4><span id="enum-hasValue">Class method: Class.hasValue(value)</span></h4>
|
|
861
|
+
<ul>
|
|
862
|
+
<li>Parameters:
|
|
863
|
+
<ul>
|
|
864
|
+
<li><code>value: string</code>: the value of the enumerator to be tested. Note that this
|
|
865
|
+
argument will be trimmed and uppercased to get the actual value of the
|
|
866
|
+
enumerator.</li>
|
|
867
|
+
</ul>
|
|
868
|
+
</li>
|
|
869
|
+
<li>Returns:
|
|
870
|
+
<ul>
|
|
871
|
+
<li><code>boolean</code>: returns <code>true</code> if there is an enumerator in this enumeration
|
|
872
|
+
class with the specified value, or <code>false</code> otherwise.</li>
|
|
873
|
+
</ul>
|
|
874
|
+
</li>
|
|
875
|
+
</ul>
|
|
876
|
+
<p>This function tests whether there is an enumerator with the specified value.</p>
|
|
877
|
+
<h4><span id="enum-ofName">Class method: Class.ofName(name)</span></h4>
|
|
878
|
+
<ul>
|
|
879
|
+
<li>Parameters:
|
|
880
|
+
<ul>
|
|
881
|
+
<li><code>name: string</code>: the name of the enumerator to be returned.</li>
|
|
882
|
+
</ul>
|
|
883
|
+
</li>
|
|
884
|
+
<li>Returns:
|
|
885
|
+
<ul>
|
|
886
|
+
<li><code>Class</code>: the enumerator in this enumeration class with the specified name,
|
|
887
|
+
or <code>undefined</code> if no such enumerator exists.</li>
|
|
888
|
+
</ul>
|
|
889
|
+
</li>
|
|
890
|
+
</ul>
|
|
891
|
+
<p>This function returns the enumerator with the specified name.</p>
|
|
892
|
+
<h4><span id="enum-hasName">Class method: Class.hasName(name)</span></h4>
|
|
893
|
+
<ul>
|
|
894
|
+
<li>Parameters:
|
|
895
|
+
<ul>
|
|
896
|
+
<li><code>name: string</code>: the name of the enumerator to be tested.</li>
|
|
897
|
+
</ul>
|
|
898
|
+
</li>
|
|
899
|
+
<li>Returns:
|
|
900
|
+
<ul>
|
|
901
|
+
<li><code>boolean</code>: returns <code>true</code> if there is an enumerator in this enumeration
|
|
902
|
+
class with the specified name, or <code>false</code> otherwise.</li>
|
|
903
|
+
</ul>
|
|
904
|
+
</li>
|
|
905
|
+
</ul>
|
|
906
|
+
<p>This function tests whether there is an enumerator with the specified name.</p>
|
|
907
|
+
<h4><span id="enum-ofCode">Class method: Class.ofCode(code)</span></h4>
|
|
908
|
+
<ul>
|
|
909
|
+
<li>Parameters:
|
|
910
|
+
<ul>
|
|
911
|
+
<li><code>code: string</code>: the code of the enumerator to be returned.</li>
|
|
912
|
+
</ul>
|
|
913
|
+
</li>
|
|
914
|
+
<li>Returns:
|
|
915
|
+
<ul>
|
|
916
|
+
<li><code>Class</code>: the enumerator in this enumeration class with the specified code,
|
|
917
|
+
or <code>undefined</code> if no such enumerator exists.</li>
|
|
918
|
+
</ul>
|
|
919
|
+
</li>
|
|
920
|
+
</ul>
|
|
921
|
+
<p>This function returns the enumerator with the specified value.</p>
|
|
922
|
+
<h4><span id="enum-hasCode">Class method: Class.hasCode(code)</span></h4>
|
|
923
|
+
<ul>
|
|
924
|
+
<li>Parameters:
|
|
925
|
+
<ul>
|
|
926
|
+
<li><code>code: string</code>: the code of the enumerator to be tested.</li>
|
|
927
|
+
</ul>
|
|
928
|
+
</li>
|
|
929
|
+
<li>Returns:
|
|
930
|
+
<ul>
|
|
931
|
+
<li><code>boolean</code>: returns <code>true</code> if there is an enumerator in this enumeration
|
|
932
|
+
class with the specified code, or <code>false</code> otherwise.</li>
|
|
933
|
+
</ul>
|
|
934
|
+
</li>
|
|
935
|
+
</ul>
|
|
936
|
+
<p>This function tests whether there is an enumerator with the specified code.</p>
|
|
937
|
+
<h4><span id="enum-of">Class method: Class.of(expr)</span></h4>
|
|
938
|
+
<ul>
|
|
939
|
+
<li>Parameters:
|
|
940
|
+
<ul>
|
|
941
|
+
<li><code>expr: object | string</code>: the expression corresponds to the enumerator to
|
|
942
|
+
be returned. The expression could be one of the following:
|
|
943
|
+
<ul>
|
|
944
|
+
<li>an enumerator of this enumeration class;</li>
|
|
945
|
+
<li>or the value of an enumerator of this enumeration class;</li>
|
|
946
|
+
<li>or the name of an enumerator of this enumeration class;</li>
|
|
947
|
+
<li>or the code of an enumerator of this enumeration class.</li>
|
|
948
|
+
</ul>
|
|
949
|
+
</li>
|
|
950
|
+
</ul>
|
|
951
|
+
</li>
|
|
952
|
+
<li>Returns:
|
|
953
|
+
<ul>
|
|
954
|
+
<li><code>Class</code>: the enumerator in this enumeration class corresponds to the
|
|
955
|
+
specified expression, or <code>undefined</code> if no such enumerator exists.</li>
|
|
956
|
+
</ul>
|
|
957
|
+
</li>
|
|
958
|
+
</ul>
|
|
959
|
+
<p>This function returns the enumerator with the specified value.</p>
|
|
960
|
+
<h4><span id="enum-has">Class method: Class.has(expr)</span></h4>
|
|
961
|
+
<ul>
|
|
962
|
+
<li>Parameters:
|
|
963
|
+
<ul>
|
|
964
|
+
<li><code>expr: object | string</code>: the expression corresponds to the enumerator to
|
|
965
|
+
be returned. The expression could be one of the following:
|
|
966
|
+
<ul>
|
|
967
|
+
<li>an enumerator of this enumeration class;</li>
|
|
968
|
+
<li>or the value of an enumerator of this enumeration class;</li>
|
|
969
|
+
<li>or the name of an enumerator of this enumeration class;</li>
|
|
970
|
+
<li>or the code of an enumerator of this enumeration class.</li>
|
|
971
|
+
</ul>
|
|
972
|
+
</li>
|
|
973
|
+
</ul>
|
|
974
|
+
</li>
|
|
975
|
+
<li>Returns:
|
|
976
|
+
<ul>
|
|
977
|
+
<li><code>boolean</code>: returns <code>true</code> if there is an enumerator in this enumeration
|
|
978
|
+
class corresponds to the specified expression, or <code>false</code> otherwise.</li>
|
|
979
|
+
</ul>
|
|
980
|
+
</li>
|
|
981
|
+
</ul>
|
|
982
|
+
<p>This function tests whether there is an enumerator with the specified code.</p>
|
|
983
|
+
<h4><span id="enum-usage-example">Usage Example</span></h4>
|
|
984
|
+
<pre class="prettyprint source lang-js"><code>@Enum
|
|
985
|
+
class Gender {
|
|
986
|
+
static MALE = 'Male';
|
|
987
|
+
static FEMALE = 'Female';
|
|
988
|
+
}
|
|
989
|
+
</code></pre>
|
|
990
|
+
<p>The above code is equivalent to the following code:</p>
|
|
991
|
+
<pre class="prettyprint source lang-js"><code>class Gender {
|
|
992
|
+
static MALE = Object.freeze(new Gender('MALE', 'Male'));
|
|
993
|
+
|
|
994
|
+
static FEMALE = Object.freeze(new Gender('FEMALE', 'Female'));
|
|
995
|
+
|
|
996
|
+
static values() {
|
|
997
|
+
return [ Gender.MALE, Gender.FEMALE ];
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
static ofValue(value) {
|
|
1001
|
+
switch (value) {
|
|
1002
|
+
case 'MALE':
|
|
1003
|
+
return Gender.MALE;
|
|
1004
|
+
case 'FEMALE':
|
|
1005
|
+
return Gender.FEMALE;
|
|
1006
|
+
default:
|
|
1007
|
+
return undefined;
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
static hasValue(value) {
|
|
1012
|
+
return Gender.ofValue(value) !== undefined;
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
static ofName(name) {
|
|
1016
|
+
return Gender.values().find((e) => e.name === name);
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
static hasName(name) {
|
|
1020
|
+
return Gender.ofName(name) !== undefined;
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
static ofCode(code) {
|
|
1024
|
+
return Gender.values().find((e) => e.code === code);
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
static hasCode(code) {
|
|
1028
|
+
return Gender.ofCode(code) !== undefined;
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
static of(expr) {
|
|
1032
|
+
if (expr instanceof Gender) {
|
|
1033
|
+
return expr;
|
|
1034
|
+
} else {
|
|
1035
|
+
return Gender.ofValue(expr) ?? Gender.ofName(expr) ?? Gender.ofCode(expr);
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
static has(expr) {
|
|
1040
|
+
return Gender.of(expr) !== undefined;
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
constructor(value, name) {
|
|
1044
|
+
this.value = value;
|
|
1045
|
+
this.name = name;
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
toString() {
|
|
1049
|
+
return this.value;
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
toJSON() {
|
|
1053
|
+
return this.value;
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
</code></pre>
|
|
1057
|
+
<p>The static fields of the enumeration class could also be specified as objects,
|
|
1058
|
+
which will be used to initialize the enumerators. For example:</p>
|
|
1059
|
+
<pre class="prettyprint source lang-js"><code>@Enum
|
|
1060
|
+
class Gender {
|
|
1061
|
+
static MALE = { name: 'Male', i18n: 'i18n.gender.male', code: '001', data: { value: 0 } };
|
|
1062
|
+
|
|
1063
|
+
static FEMALE = { name: 'Female', i18n: 'i18n.gender.female', code: '002', data: { value: 1 } };
|
|
1064
|
+
}
|
|
1065
|
+
</code></pre>
|
|
1066
|
+
<p>The above code is equivalent to the following code:</p>
|
|
1067
|
+
<pre class="prettyprint source lang-js"><code>class Gender {
|
|
1068
|
+
static MALE = Object.freeze(new Gender('MALE', 'Male',
|
|
1069
|
+
{ i18n: 'i18n.gender.male', code: '001', data: {value: 0 } }));
|
|
1070
|
+
|
|
1071
|
+
static FEMALE = Object.freeze(new Gender('FEMALE', 'Female',
|
|
1072
|
+
{ i18n: 'i18n.gender.female', code: '002', data: {value: 1 } }));
|
|
1073
|
+
|
|
1074
|
+
...
|
|
1075
|
+
|
|
1076
|
+
constructor(value, name, payload) {
|
|
1077
|
+
this.value = value;
|
|
1078
|
+
this.name = name;
|
|
1079
|
+
Object.assign(this, payload);
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
...
|
|
1083
|
+
}
|
|
1084
|
+
</code></pre>
|
|
1085
|
+
<p>Note that the enumerator in the above <code>Gender</code> class has a <code>code</code>, <code>i18n</code>
|
|
1086
|
+
and <code>data</code> properties. Since it has <code>i18n</code> property which specifies the i18n
|
|
1087
|
+
key of the enumerator in the resource bundle, the <code>name</code> property of the
|
|
1088
|
+
enumerator will be transformed to a <code>getter</code> which will get the i18n value
|
|
1089
|
+
corresponding to the i18n key from the i18n resource bundle.</p>
|
|
1090
|
+
<p>The enumerators can also be defined without default values, for example:</p>
|
|
1091
|
+
<pre class="prettyprint source lang-js"><code>@Enum
|
|
1092
|
+
class Gender {
|
|
1093
|
+
static MALE;
|
|
1094
|
+
static FEMALE;
|
|
1095
|
+
}
|
|
1096
|
+
</code></pre>
|
|
1097
|
+
<p>The above code is equivalent to the following code:</p>
|
|
1098
|
+
<pre class="prettyprint source lang-js"><code>class Gender {
|
|
1099
|
+
static MALE = Object.freeze(new Gender('MALE'));
|
|
1100
|
+
|
|
1101
|
+
static FEMALE = Object.freeze(new Gender('FEMALE'));
|
|
1102
|
+
|
|
1103
|
+
...
|
|
1104
|
+
|
|
1105
|
+
constructor(value) {
|
|
1106
|
+
this.value = value;
|
|
1107
|
+
this.name = value;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
...
|
|
1111
|
+
}
|
|
1112
|
+
</code></pre>
|
|
1113
|
+
<p>That is, the name of the enumerator is exactly its value.</p>
|
|
1114
|
+
<h3><span id="default-options"><code>DefaultOptions</code> class</span></h3>
|
|
1115
|
+
<p>The <code>DefaultOptions</code> class is used to get or set the default options of different
|
|
1116
|
+
aspects of this library.</p>
|
|
1117
|
+
<p>The class accesses an internal <code>Map</code> object. The key of the map is the name
|
|
1118
|
+
of aspects, and the value of the map is an object representing the default
|
|
1119
|
+
options of the aspect.</p>
|
|
1120
|
+
<p>For example, the default options of the <code>assign()</code> method of the class
|
|
1121
|
+
decorated by <code>@Model</code> is stored in the key <code>assign</code>. That is,
|
|
1122
|
+
<code>DefaultOption.get('assign')</code> returns the object representing the default
|
|
1123
|
+
options of the <code>assign()</code> method.</p>
|
|
1124
|
+
<p>The program can change the default options with <code>DefaultOptions.set('key', options)</code>
|
|
1125
|
+
method.</p>
|
|
1126
|
+
<p>Currently, the following aspects are supported:</p>
|
|
1127
|
+
<ul>
|
|
1128
|
+
<li><code>assign</code>: the default options of the <code>Class.prototype.assign()</code>,
|
|
1129
|
+
<code>Class.create()</code>, <code>Class.createArray()</code>, <code>Class.createPage()</code>,
|
|
1130
|
+
<code>Class.parseJsonString()</code> methods of the class decorated by <code>@Model</code>.</li>
|
|
1131
|
+
<li><code>toJSON</code>: the default options of the <code>Class.prototype.toJSON()</code>,
|
|
1132
|
+
<code>Class.prototype.toJsonString()</code> methods of the class decorated by <code>@Model</code>.</li>
|
|
1133
|
+
</ul>
|
|
1134
|
+
<h4><span id="default-options-get">Class method: <code>DefaultOptions.get(aspect)</code></span></h4>
|
|
1135
|
+
<p>Gets the default options of the specified aspect.</p>
|
|
1136
|
+
<p>The function returns the object representing the default options of the aspect,
|
|
1137
|
+
or <code>undefined</code>if the aspect does not exist. Note that the returned object is a
|
|
1138
|
+
deep cloned copy of the object stored in the internal map, so that the
|
|
1139
|
+
modification of the returned object will <strong>not</strong> affect the default options
|
|
1140
|
+
stored in the internal map.</p>
|
|
1141
|
+
<pre class="prettyprint source lang-js"><code>import { DefaultOptions } from '@qubit-ltd/common-decorator';
|
|
1142
|
+
|
|
1143
|
+
const opt1 = DefaultOptions.get('assign');
|
|
1144
|
+
expect(opt1.convertNaming).toBe(false);
|
|
1145
|
+
opt1.convertNaming = true;
|
|
1146
|
+
const opt2 = DefaultOptions.get('assign');
|
|
1147
|
+
expect(opt2.convertNaming).toBe(false);
|
|
1148
|
+
</code></pre>
|
|
1149
|
+
<h4><span id="default-options-set">Class method: <code>DefaultOptions.set(aspect, options)</code></span></h4>
|
|
1150
|
+
<p>Sets the default options of the specified aspect.</p>
|
|
1151
|
+
<p>This function will merge the new options into the old default options of the aspect.
|
|
1152
|
+
If the new options have the same property as the old default options stored
|
|
1153
|
+
in the internal map, the value of the new options will override the value of the
|
|
1154
|
+
old default options; otherwise, the new property will be added to the old default
|
|
1155
|
+
options.</p>
|
|
1156
|
+
<pre class="prettyprint source lang-js"><code>import { DefaultOptions } from '@qubit-ltd/common-decorator';
|
|
1157
|
+
|
|
1158
|
+
const opt1 = DefaultOptions.get('assign');
|
|
1159
|
+
expect(opt1.convertNaming).toBe(false);
|
|
1160
|
+
DefaultOptions.set('assign', { convertNaming: true });
|
|
1161
|
+
const opt2 = DefaultOptions.get('assign');
|
|
1162
|
+
expect(opt2.convertNaming).toBe(true);
|
|
1163
|
+
expect(opt1.convertNaming).toBe(false);
|
|
1164
|
+
</code></pre>
|
|
1165
|
+
<h4><span id="default-options-merge">Class method: <code>DefaultOptions.merge(aspect, options)</code></span></h4>
|
|
1166
|
+
<p>Gets the default options of the specified aspect, merging the provided default
|
|
1167
|
+
options into the returned object.</p>
|
|
1168
|
+
<p><strong>NOTE:</strong> This function does <strong>NOT</strong> change the default options stored in the
|
|
1169
|
+
internal map, instead, it returns a new object representing the merged options.</p>
|
|
1170
|
+
<pre class="prettyprint source lang-js"><code>import { DefaultOptions } from '@qubit-ltd/common-decorator';
|
|
1171
|
+
|
|
1172
|
+
const opt1 = DefaultOptions.get('assign');
|
|
1173
|
+
expect(opt1.convertNaming).toBe(false);
|
|
1174
|
+
const opt2 = DefaultOptions.merge('assign', { convertNaming: true });
|
|
1175
|
+
expect(opt2.convertNaming).toBe(true);
|
|
1176
|
+
expect(opt1.convertNaming).toBe(false);
|
|
1177
|
+
const opt3 = DefaultOptions.merge('assign', null);
|
|
1178
|
+
expect(opt3.convertNaming).toBe(false);
|
|
1179
|
+
</code></pre>
|
|
1180
|
+
<h2><span id="configuration">Configuration</span></h2>
|
|
1181
|
+
<p>This library uses the most recent (currently May 2023)
|
|
1182
|
+
<a href="https://github.com/tc39/proposal-decorators">stage 3 proposal of JavaScript decorators</a>. Therefore, you must configure
|
|
1183
|
+
<a href="https://babeljs.io/">Babel</a> with <a href="https://babeljs.io/docs/babel-plugin-transform-class-properties">@babel/plugin-transform-class-properties</a> and the
|
|
1184
|
+
<a href="https://babeljs.io/docs/babel-plugin-proposal-decorators">@babel/plugin-proposal-decorators</a> plugins.</p>
|
|
1185
|
+
<p><strong>NOTE:</strong> To support the <a href="https://github.com/tc39/proposal-decorator-metadata">stage 3 proposal of JavaScript decorator metadata</a>,
|
|
1186
|
+
the version of the <a href="https://babeljs.io/">Babel</a> plugin <a href="https://babeljs.io/docs/babel-plugin-proposal-decorators">@babel/plugin-proposal-decorators</a> must be
|
|
1187
|
+
at least <code>7.23.0</code>.</p>
|
|
1188
|
+
<h3><span id="webpack">Bundling with <a href="https://webpack.js.org/">webpack</a></span></h3>
|
|
1189
|
+
<ol>
|
|
1190
|
+
<li>Install the required dependencies:<pre class="prettyprint source lang-shell"><code>yarn add @qubit-ltd/common-decorator
|
|
1191
|
+
yarn add --dev @babel/core @babel/runtime @babel/preset-env
|
|
1192
|
+
yarn add --dev @babel/plugin-proposal-decorators @babel/plugin-transform-class-properties @babel/plugin-transform-runtime
|
|
1193
|
+
</code></pre>
|
|
1194
|
+
</li>
|
|
1195
|
+
<li>Configure <a href="https://babeljs.io/">Babel</a> by using the <a href="https://babeljs.io/docs/babel-plugin-transform-class-properties">@babel/plugin-transform-class-properties</a>
|
|
1196
|
+
and <a href="https://babeljs.io/docs/babel-plugin-proposal-decorators">@babel/plugin-proposal-decorators</a> plugins. A possible <a href="https://babeljs.io/">Babel</a>
|
|
1197
|
+
configuration file <code>babelrc.json</code> is as follows:<pre class="prettyprint source lang-json"><code>{
|
|
1198
|
+
"presets": [
|
|
1199
|
+
"@babel/preset-env"
|
|
1200
|
+
],
|
|
1201
|
+
"plugins": [
|
|
1202
|
+
"@babel/plugin-transform-runtime",
|
|
1203
|
+
["@babel/plugin-proposal-decorators", { "version": "2023-05" }],
|
|
1204
|
+
"@babel/plugin-transform-class-properties"
|
|
1205
|
+
]
|
|
1206
|
+
}
|
|
1207
|
+
</code></pre>
|
|
1208
|
+
</li>
|
|
1209
|
+
</ol>
|
|
1210
|
+
<h3><span id="vite">Bundling with <a href="https://vitejs.dev/">vite</a></span></h3>
|
|
1211
|
+
<ol>
|
|
1212
|
+
<li>Install the required dependencies:<pre class="prettyprint source lang-shell"><code>yarn add @qubit-ltd/common-decorator
|
|
1213
|
+
yarn add --dev @babel/core @babel/runtime @babel/preset-env
|
|
1214
|
+
yarn add --dev @babel/plugin-proposal-decorators @babel/plugin-transform-class-properties @babel/plugin-transform-runtime
|
|
1215
|
+
</code></pre>
|
|
1216
|
+
</li>
|
|
1217
|
+
<li>Configure <a href="https://babeljs.io/">Babel</a> by using <a href="https://babeljs.io/docs/babel-plugin-transform-class-properties">@babel/plugin-transform-class-properties</a> and
|
|
1218
|
+
<a href="https://babeljs.io/docs/babel-plugin-proposal-decorators">@babel/plugin-proposal-decorators</a> plugins. A possible <a href="https://babeljs.io/">Babel</a> configuration
|
|
1219
|
+
file <code>babelrc.json</code> is as follows:<pre class="prettyprint source lang-json"><code>{
|
|
1220
|
+
"presets": [
|
|
1221
|
+
["@babel/preset-env", { "modules": false }]
|
|
1222
|
+
],
|
|
1223
|
+
"plugins": [
|
|
1224
|
+
"@babel/plugin-transform-runtime",
|
|
1225
|
+
["@babel/plugin-proposal-decorators", { "version": "2023-05" }],
|
|
1226
|
+
"@babel/plugin-transform-class-properties"
|
|
1227
|
+
]
|
|
1228
|
+
}
|
|
1229
|
+
</code></pre>
|
|
1230
|
+
<strong>Note:</strong> When bundling with <a href="https://vitejs.dev/">vite</a>, make sure to set the <code>modules</code> parameter
|
|
1231
|
+
of <code>@babel/preset-env</code> to <code>false</code>.</li>
|
|
1232
|
+
<li>Configure <a href="https://vitejs.dev/">vite</a> by modifying the <code>vite.config.js</code> file to add support for
|
|
1233
|
+
<a href="https://babeljs.io/">Babel</a>. A possible <code>vite.config.js</code> file is as follows:<pre class="prettyprint source lang-js"><code>import { fileURLToPath, URL } from 'node:url';
|
|
1234
|
+
import { defineConfig } from 'vite';
|
|
1235
|
+
import vue from '@vitejs/plugin-vue';
|
|
1236
|
+
import * as babel from '@babel/core';
|
|
1237
|
+
|
|
1238
|
+
// A very simple Vite plugin support babel transpilation
|
|
1239
|
+
const babelPlugin = {
|
|
1240
|
+
name: 'plugin-babel',
|
|
1241
|
+
transform: (src, id) => {
|
|
1242
|
+
if (/\.(jsx?|vue)$/.test(id)) { // the pattern of the file to handle
|
|
1243
|
+
return babel.transform(src, {
|
|
1244
|
+
filename: id,
|
|
1245
|
+
babelrc: true,
|
|
1246
|
+
});
|
|
1247
|
+
}
|
|
1248
|
+
},
|
|
1249
|
+
};
|
|
1250
|
+
// https://vitejs.dev/config/
|
|
1251
|
+
export default defineConfig({
|
|
1252
|
+
plugins: [
|
|
1253
|
+
vue({
|
|
1254
|
+
script: {
|
|
1255
|
+
babelParserPlugins: ['decorators'], // must enable decorators support
|
|
1256
|
+
},
|
|
1257
|
+
}),
|
|
1258
|
+
babelPlugin, // must be after the vue plugin
|
|
1259
|
+
],
|
|
1260
|
+
resolve: {
|
|
1261
|
+
alias: {
|
|
1262
|
+
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
|
1263
|
+
},
|
|
1264
|
+
},
|
|
1265
|
+
});
|
|
1266
|
+
</code></pre>
|
|
1267
|
+
<strong>Note:</strong> In the above configuration file, we've implemented a simple <a href="https://vitejs.dev/">vite</a>
|
|
1268
|
+
plugin to transpile the code processed by the <a href="https://www.npmjs.com/package/@vitejs/plugin-vue">vite-plugin-vue</a> plugin using
|
|
1269
|
+
<a href="https://babeljs.io/">Babel</a>. Although there's a <a href="https://www.npmjs.com/package/vite-plugin-babel">vite-plugin-babel</a> plugin that claims to add
|
|
1270
|
+
<a href="https://babeljs.io/">Babel</a> support to <a href="https://vitejs.dev/">vite</a>, we found it doesn't correctly handle [vue] Single
|
|
1271
|
+
File Components (SFCs). After closely examining its source code, we
|
|
1272
|
+
determined that to achieve correct transpilation, we need to apply <a href="https://babeljs.io/">Babel</a>
|
|
1273
|
+
after <a href="https://www.npmjs.com/package/@vitejs/plugin-vue">vite-plugin-vue</a> processes the source code. Therefore, the very
|
|
1274
|
+
simple plugin function above suffices for our needs. As an alternative,
|
|
1275
|
+
you can use <a href="https://npmjs.com/package/@qubit-ltd/vite-plugin-babel">our version of vite-plugin-babel</a>, and the following is an
|
|
1276
|
+
example configuration:<pre class="prettyprint source lang-js"><code>import { fileURLToPath, URL } from 'node:url';
|
|
1277
|
+
import { defineConfig } from 'vite';
|
|
1278
|
+
import vue from '@vitejs/plugin-vue';
|
|
1279
|
+
import babel from '@qubit-ltd/vite-plugin-babel';
|
|
1280
|
+
|
|
1281
|
+
export default defineConfig({
|
|
1282
|
+
plugins: [
|
|
1283
|
+
vue({
|
|
1284
|
+
script: {
|
|
1285
|
+
babelParserPlugins: ['decorators'], // must enable decorators support
|
|
1286
|
+
},
|
|
1287
|
+
}),
|
|
1288
|
+
babel(),
|
|
1289
|
+
],
|
|
1290
|
+
resolve: {
|
|
1291
|
+
alias: {
|
|
1292
|
+
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
|
1293
|
+
},
|
|
1294
|
+
},
|
|
1295
|
+
});
|
|
1296
|
+
</code></pre>
|
|
1297
|
+
</li>
|
|
1298
|
+
</ol>
|
|
1299
|
+
<h2><span id="contributing">Contributing</span></h2>
|
|
1300
|
+
<p>If you find any issues or have suggestions for improvements, please feel free
|
|
1301
|
+
to open an issue or submit a pull request to the <a href="https://github.com/Haixing-Hu/js-common-decorator">GitHub repository</a>.</p>
|
|
1302
|
+
<h2><span id="license">License</span></h2>
|
|
1303
|
+
<p><a href="https://npmjs.com/package/@qubit-ltd/common-decorator">@qubit-ltd/common-decorator</a> is distributed under the Apache 2.0 license.
|
|
1304
|
+
See the <a href="LICENSE">LICENSE</a> file for more details.</p></article>
|
|
1305
|
+
</section>
|
|
1306
|
+
|
|
1307
|
+
|
|
1308
|
+
|
|
1309
|
+
|
|
1310
|
+
|
|
1311
|
+
|
|
1312
|
+
</div>
|
|
1313
|
+
|
|
1314
|
+
<br class="clear">
|
|
1315
|
+
|
|
1316
|
+
<footer>
|
|
1317
|
+
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.4</a>
|
|
1318
|
+
on Mon Jan 06 2025 12:25:48 GMT+0800 (China Standard Time)
|
|
1319
|
+
using the <a href="https://github.com/Haixing-Hu/jsdoc-minami">customized Minami theme</a>.
|
|
1320
|
+
</footer>
|
|
1321
|
+
|
|
1322
|
+
<script>prettyPrint();</script>
|
|
1323
|
+
<script src="scripts/linenumber.js"></script>
|
|
1324
|
+
</body>
|
|
1325
|
+
</html>
|