mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-10 03:32:52 +00:00
refactor: move es-mapping-generator to monorepo
This commit is contained in:
15
packages/es-mapping-generator/.editorconfig
Normal file
15
packages/es-mapping-generator/.editorconfig
Normal file
@@ -0,0 +1,15 @@
|
||||
# editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
98
packages/es-mapping-generator/.gitignore
vendored
Normal file
98
packages/es-mapping-generator/.gitignore
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
.DS_Store
|
||||
|
||||
# Schema generation data
|
||||
Diagram-*.svg
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# TypeScript v1 declaration files
|
||||
typings/
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
|
||||
# next.js build output
|
||||
.next
|
||||
|
||||
# nuxt.js build output
|
||||
.nuxt
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
#DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
########## end of https://github.com/github/gitignore/blob/master/Node.gitignore
|
||||
|
||||
# ignore ide files
|
||||
.idea
|
||||
.vscode
|
||||
|
||||
# ignore lib directory
|
||||
lib/
|
||||
|
||||
# ignore docs directory
|
||||
docs/
|
||||
|
||||
# ignore openapi resources
|
||||
openapi/
|
||||
71
packages/es-mapping-generator/.gitlab-ci.yml
Normal file
71
packages/es-mapping-generator/.gitlab-ci.yml
Normal file
@@ -0,0 +1,71 @@
|
||||
image: registry.gitlab.com/openstapps/projectmanagement/node
|
||||
|
||||
cache:
|
||||
key: ${CI_COMMIT_REF_SLUG}
|
||||
paths:
|
||||
- node_modules
|
||||
|
||||
before_script:
|
||||
- npm install
|
||||
|
||||
stages:
|
||||
- build
|
||||
- test
|
||||
- audit
|
||||
- deploy
|
||||
|
||||
build:
|
||||
stage: build
|
||||
script:
|
||||
- npm run build
|
||||
artifacts:
|
||||
paths:
|
||||
- lib
|
||||
|
||||
test:
|
||||
tags:
|
||||
- docker
|
||||
stage: test
|
||||
script:
|
||||
- npm test
|
||||
|
||||
audit:
|
||||
stage: audit
|
||||
script:
|
||||
- npm audit
|
||||
allow_failure: true
|
||||
except:
|
||||
- schedules
|
||||
|
||||
scheduled-audit:
|
||||
stage: audit
|
||||
script:
|
||||
- npm audit --audit-level=high
|
||||
only:
|
||||
- schedules
|
||||
|
||||
package:
|
||||
dependencies:
|
||||
- build
|
||||
tags:
|
||||
- secrecy
|
||||
stage: deploy
|
||||
script:
|
||||
- echo "//registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN" > ~/.npmrc
|
||||
- npm publish
|
||||
only:
|
||||
- /^v[0-9]+.[0-9]+.[0-9]+$/
|
||||
artifacts:
|
||||
paths:
|
||||
- lib
|
||||
|
||||
pages:
|
||||
stage: deploy
|
||||
script:
|
||||
- npm run documentation
|
||||
- mv docs public
|
||||
only:
|
||||
- /^v[0-9]+\.[0-9]+\.[0-9]+$/
|
||||
artifacts:
|
||||
paths:
|
||||
- public
|
||||
12
packages/es-mapping-generator/.npmignore
Normal file
12
packages/es-mapping-generator/.npmignore
Normal file
@@ -0,0 +1,12 @@
|
||||
# Ignore all files/folders by default
|
||||
# See https://stackoverflow.com/a/29932318
|
||||
/*
|
||||
# Except these files/folders
|
||||
!lib
|
||||
lib/tsconfig.tsbuildinfo
|
||||
!LICENSE
|
||||
!package.json
|
||||
!package-lock.json
|
||||
!README.md
|
||||
!resources
|
||||
!src
|
||||
48
packages/es-mapping-generator/CHANGELOG.md
Normal file
48
packages/es-mapping-generator/CHANGELOG.md
Normal file
@@ -0,0 +1,48 @@
|
||||
# [0.4.0](https://gitlab.com/openstapps/es-mapping-generator/compare/v0.3.0...v0.4.0) (2023-01-12)
|
||||
|
||||
|
||||
|
||||
# [0.3.0](https://gitlab.com/openstapps/es-mapping-generator/compare/v0.2.0...v0.3.0) (2022-08-17)
|
||||
|
||||
|
||||
|
||||
# [0.2.0](https://gitlab.com/openstapps/es-mapping-generator/compare/v0.1.0...v0.2.0) (2022-06-27)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* marked version with audit issue ([7534744](https://gitlab.com/openstapps/es-mapping-generator/commit/7534744294ec27f1ce3f4bf65424d717b33dd889))
|
||||
|
||||
|
||||
|
||||
# [0.1.0](https://gitlab.com/openstapps/es-mapping-generator/compare/v0.0.4...v0.1.0) (2022-05-27)
|
||||
|
||||
|
||||
|
||||
## [0.0.4](https://gitlab.com/openstapps/es-mapping-generator/compare/v0.0.3...v0.0.4) (2021-12-16)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* filter tags override inherited type tags ([f0401e1](https://gitlab.com/openstapps/es-mapping-generator/commit/f0401e1889f12860d4eaa2dc5a1ee1b08f20ba31))
|
||||
|
||||
|
||||
|
||||
## [0.0.3](https://gitlab.com/openstapps/es-mapping-generator/compare/v0.0.2...v0.0.3) (2021-08-05)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* put es template parsing ([9a88129](https://gitlab.com/openstapps/es-mapping-generator/commit/9a881299dc9d0a6d59b370340880a10bd8b1e2c5))
|
||||
|
||||
|
||||
|
||||
## [0.0.2](https://gitlab.com/openstapps/es-mapping-generator/compare/28334b800c014a9e0b6e980b5365af6fdc1d8950...v0.0.2) (2021-08-05)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* fix unwanted crash when not supplying an error path ([28334b8](https://gitlab.com/openstapps/es-mapping-generator/commit/28334b800c014a9e0b6e980b5365af6fdc1d8950))
|
||||
|
||||
|
||||
|
||||
1
packages/es-mapping-generator/Dockerfile
Normal file
1
packages/es-mapping-generator/Dockerfile
Normal file
@@ -0,0 +1 @@
|
||||
FROM plantuml/plantuml-server:tomcat
|
||||
200
packages/es-mapping-generator/LICENSE
Normal file
200
packages/es-mapping-generator/LICENSE
Normal file
@@ -0,0 +1,200 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright © 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work.
|
||||
A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
|
||||
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
|
||||
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
|
||||
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
|
||||
a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
|
||||
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices".
|
||||
c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
|
||||
d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
|
||||
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
|
||||
a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
|
||||
b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
|
||||
c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
|
||||
d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
|
||||
e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
|
||||
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
"Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
|
||||
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
|
||||
b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
|
||||
c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
|
||||
d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
|
||||
e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
|
||||
f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
|
||||
All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
|
||||
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
|
||||
An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version".
|
||||
A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
|
||||
13. Use with the GNU Affero General Public License.
|
||||
Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such.
|
||||
14. Revised Versions of this License.
|
||||
The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
|
||||
Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
16. Limitation of Liability.
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read <https://www.gnu.org/ licenses/why-not-lgpl.html>.
|
||||
64
packages/es-mapping-generator/README.md
Normal file
64
packages/es-mapping-generator/README.md
Normal file
@@ -0,0 +1,64 @@
|
||||
# @openstapps/es-mapping-generator
|
||||
|
||||
[](https://gitlab.com/openstapps/es-mapping-gen/commits/master)
|
||||
[](https://npmjs.com/package/@openstapps/es-mapping-gen)
|
||||
[](https://www.gnu.org/licenses/gpl-3.0.en.html)
|
||||
[](https://openstapps.gitlab.io/es-mapping-gen)
|
||||
|
||||
Tools to convert and validate StAppsCore
|
||||
|
||||
## What is the ES Mapping Generator for?
|
||||
|
||||
The ES Mapping Generator is for converting TypeScript interfaces to Elasticsearch mappings,
|
||||
with support for Integer and Float types, Dates, etc.
|
||||
|
||||
## Why is this a separate package?
|
||||
|
||||
The ES Mapping Generator relies on an outdated version of TypeDoc, that can't be updated.
|
||||
Because of that, it then also relies on an outdated version of TypeScript, resulting
|
||||
in a cascade effect things that can't be updated. Because of that, we decided to isolate
|
||||
it to the best of our abilities.
|
||||
|
||||
## How to use the Elasticsearch Mapping generator
|
||||
|
||||
The mapping generator is intended to be used by the backend directly, but it can also be used to generate these files
|
||||
manually.
|
||||
|
||||
### Generating the mapping files by hand
|
||||
|
||||
To generate the mapping files by hand, you need a local copy of the core-tools and the core, both need to be built first.
|
||||
After that you can run
|
||||
```
|
||||
node lib/cli.js mapping path/to/core path/to/destination ignoredTag1,ignoredTag2,ignoredTag3
|
||||
```
|
||||
If you don't pass in any ignored tags, you will likely be prompted with errors, despite the core being absolutely correct.
|
||||
This is because there are some tags that are not relevant to Elasticsearch, but the program has no direct way to tell
|
||||
which ones simply lack an implementation and which ones can be ignored. Currently the ignored tags include
|
||||
`minlength`, `pattern` and `see`.
|
||||
|
||||
### Generating the mapping directly from another TypeScript program
|
||||
|
||||
This is the more easy way, and it gives you direct access to the generated mapping as a (mostly typesafe) object. To
|
||||
use it, call `generateTemplate`, However you will first need to generate a ProjectReflection of the core you are working
|
||||
with. If you use the core as a dependency, you can for example use
|
||||
```typescript
|
||||
const map = generateTemplate(getProjectReflection(resolve('node_modules', '@openstapps', 'core', 'src')),
|
||||
ignoredTags, false);
|
||||
```
|
||||
to generate the mappings. Note that the result object contains both a list of errors in `map.errors` and the actual mapping
|
||||
in `map.template`. You can also specify whether you want the generator to show any errors while generating the mappings
|
||||
in the console in the last parameter, `true` (default) being show errors and `false` to suppress them. That said it is very
|
||||
easy to replace all `type: "MISSING_PREMAP"`, `type: "PARSE_ERROR"`, `type: "TYPE_CONFLICT"` with `dynamic: true` (you
|
||||
can take these exactly like written here and run a replace over the file).
|
||||
|
||||
### Fixing a generated mapping by hand
|
||||
|
||||
If you get errors when generating the mappings, the mappings might not work, however they will still be generated to the
|
||||
programs best efforts. Most small issues can be fixed after the mapping was generated as a temporary solution and without
|
||||
changing anything in the mapper's code. This however requires some understanding of how mappings work.
|
||||
|
||||
The output of the program can easily reach 25.000 lines, but you can find errors quickly by searching for `MISSING_PREMAP`,
|
||||
`PARSE_ERROR` and `TYPE_CONFLICT`. When you reach them you can then manually replace them with your code.
|
||||
|
||||
As a last resort you can also replace all errors with dynamic types, this should get the mapping working, but it is NOT
|
||||
RECOMMENDED as a fix other than using it locally.
|
||||
2830
packages/es-mapping-generator/package-lock.json
generated
Normal file
2830
packages/es-mapping-generator/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
50
packages/es-mapping-generator/package.json
Normal file
50
packages/es-mapping-generator/package.json
Normal file
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"name": "@openstapps/es-mapping-generator",
|
||||
"version": "0.4.0",
|
||||
"description": "Tool to convert TypeScript Interfaces to Elasticsearch Mappings",
|
||||
"license": "GPL-3.0-only",
|
||||
"main": "./lib/index.js",
|
||||
"types": "./lib/index.d.ts",
|
||||
"bin": {
|
||||
"openstapps-es-mapping-generator": "./lib/cli.js"
|
||||
},
|
||||
"author": "Wieland Schöbl <wulkanat@gmail.com>",
|
||||
"scripts": {
|
||||
"build": "npm run tslint && npm run compile",
|
||||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md && git commit -m 'docs: update changelog'",
|
||||
"check-configuration": "openstapps-configuration",
|
||||
"compile": "rimraf lib && tsc && prepend lib/cli.js '#!/usr/bin/env node\n'",
|
||||
"documentation": "typedoc --includeDeclarations --mode modules --out docs --readme README.md --listInvalidSymbolLinks src",
|
||||
"postversion": "npm run changelog",
|
||||
"prepublishOnly": "npm ci && npm run build",
|
||||
"preversion": "npm run prepublishOnly",
|
||||
"push": "git push && git push origin \"v$npm_package_version\"",
|
||||
"test": "mocha --require ts-node/register test/*.spec.ts",
|
||||
"tslint": "tslint -p tsconfig.json -c tslint.json 'src/**/*.ts'"
|
||||
},
|
||||
"dependencies": {
|
||||
"@openstapps/logger": "1.1.1",
|
||||
"commander": "9.5.0",
|
||||
"deepmerge": "4.2.2",
|
||||
"flatted": "3.2.7",
|
||||
"got": "11.8.6",
|
||||
"typedoc": "0.18.0",
|
||||
"typescript": "3.8.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@testdeck/mocha": "0.3.3",
|
||||
"@types/chai": "4.3.4",
|
||||
"@types/mocha": "9.1.1",
|
||||
"@types/node": "14.18.36",
|
||||
"@types/rimraf": "3.0.2",
|
||||
"chai": "4.3.7",
|
||||
"conventional-changelog-cli": "2.2.2",
|
||||
"mocha": "9.2.2",
|
||||
"nock": "13.3.0",
|
||||
"prepend-file-cli": "1.0.6",
|
||||
"rimraf": "3.0.2",
|
||||
"ts-node": "10.9.1",
|
||||
"tslint": "6.1.3",
|
||||
"tslint-eslint-rules": "5.4.0"
|
||||
}
|
||||
}
|
||||
122
packages/es-mapping-generator/src/cli.ts
Normal file
122
packages/es-mapping-generator/src/cli.ts
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2021 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Logger} from '@openstapps/logger';
|
||||
import {Command} from 'commander';
|
||||
import {readFileSync, writeFileSync} from 'fs';
|
||||
import got from 'got';
|
||||
import {resolve} from 'path';
|
||||
import {exit} from 'process';
|
||||
import {generateTemplate} from './mapping';
|
||||
import {getProjectReflection} from './project-reflection';
|
||||
import {ElasticsearchTemplateCollection} from './types/mapping';
|
||||
|
||||
// handle unhandled promise rejections
|
||||
process.on('unhandledRejection', async (reason: unknown) => {
|
||||
if (reason instanceof Error) {
|
||||
await Logger.error(reason.message);
|
||||
Logger.info(reason.stack);
|
||||
}
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
const commander = new Command('openstapps-core-tools');
|
||||
|
||||
commander
|
||||
.version(JSON.parse(
|
||||
readFileSync(resolve(__dirname, '..', 'package.json'))
|
||||
.toString(),
|
||||
).version);
|
||||
|
||||
commander
|
||||
.command('mapping <relativeSrcPath>')
|
||||
.option('-m, --mappingPath <relativeMappingPath>', 'Mapping Path')
|
||||
.option('-i, --ignoredTags <ignoredTags>', 'Ignored Tags (comma-separated)')
|
||||
.option('-a, --aggPath <relativeAggregationPath>', 'Aggregations Path')
|
||||
.option('-e, --errorPath <relativeErrorPath>', 'Error Path')
|
||||
.action(async (relativeSrcPath, options) => {
|
||||
// get absolute paths
|
||||
const srcPath = resolve(relativeSrcPath);
|
||||
|
||||
let ignoredTagsList: string[] = [];
|
||||
if (typeof options.ignoredTags === 'string') {
|
||||
ignoredTagsList = options.ignoredTags.split(',');
|
||||
}
|
||||
|
||||
// get project reflection
|
||||
const projectReflection = getProjectReflection(srcPath);
|
||||
|
||||
const result = generateTemplate(projectReflection, ignoredTagsList, true);
|
||||
if (result.errors.length !== 0) {
|
||||
await Logger.error('Mapping generated with errors!');
|
||||
} else {
|
||||
Logger.ok('Mapping generated without errors!');
|
||||
}
|
||||
|
||||
// write documentation to file
|
||||
if (typeof options.aggPath !== 'undefined') {
|
||||
const aggPath = resolve(options.aggPath);
|
||||
// tslint:disable-next-line:no-magic-numbers
|
||||
writeFileSync(aggPath, JSON.stringify(result.aggregations, null, 2));
|
||||
Logger.ok(`Elasticsearch aggregations written to ${aggPath}.`);
|
||||
}
|
||||
if (typeof options.mappingPath !== 'undefined') {
|
||||
const mappingPath = resolve(options.mappingPath);
|
||||
// tslint:disable-next-line:no-magic-numbers
|
||||
writeFileSync(mappingPath, JSON.stringify(result.mappings, null, 2));
|
||||
Logger.ok(`Elasticsearch mappings written to ${mappingPath}.`);
|
||||
}
|
||||
if (typeof options.errorPath !== 'undefined') {
|
||||
const errPath = resolve(options.errorPath);
|
||||
// tslint:disable-next-line:no-magic-numbers
|
||||
writeFileSync(errPath, JSON.stringify(result.errors, null, 2));
|
||||
Logger.ok(`Mapping errors written to ${errPath}.`);
|
||||
} else if (result.errors.length > 0) {
|
||||
for (const error of result.errors) {
|
||||
await Logger.error(error);
|
||||
}
|
||||
|
||||
throw new Error('Mapping generation failed');
|
||||
}
|
||||
});
|
||||
|
||||
commander
|
||||
.command('put-es-templates <srcPath> <esAddress> [ignoredTags]')
|
||||
.action(async (relativeSrcPath, esAddress) => {
|
||||
// get absolute paths
|
||||
const srcPath = resolve(relativeSrcPath);
|
||||
|
||||
// get project reflection
|
||||
const templates = require(srcPath) as ElasticsearchTemplateCollection;
|
||||
|
||||
for (const template in templates) {
|
||||
if (!templates.hasOwnProperty(template)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const response = await got.put(`${esAddress}_template/${template}`, {
|
||||
json: templates[template],
|
||||
});
|
||||
|
||||
const HTTP_STATUS_OK = 200;
|
||||
if (response.statusCode !== HTTP_STATUS_OK) {
|
||||
await Logger.error(`Template for "${template}" failed in Elasticsearch:\n${JSON.stringify(response.body)}`);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
Logger.ok(`Templates accepted by Elasticsearch.`);
|
||||
});
|
||||
|
||||
commander.parse(process.argv);
|
||||
59
packages/es-mapping-generator/src/config/fieldmap.ts
Normal file
59
packages/es-mapping-generator/src/config/fieldmap.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2021 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {ElasticsearchFieldmap, ElasticsearchFilterableMap} from '../types/mapping';
|
||||
import {ElasticsearchDataType} from './typemap';
|
||||
|
||||
export enum analyzers {
|
||||
ducet_sort = 'ducet_sort',
|
||||
search_german = 'search_german',
|
||||
}
|
||||
|
||||
export const fieldmap: ElasticsearchFieldmap = {
|
||||
aggregatable: {
|
||||
default: {
|
||||
raw: {
|
||||
ignore_above: 10000,
|
||||
type: ElasticsearchDataType.keyword,
|
||||
},
|
||||
},
|
||||
ignore: ['global'],
|
||||
},
|
||||
sortable: {
|
||||
default: {
|
||||
sort: {
|
||||
analyzer: analyzers.ducet_sort,
|
||||
fielddata: true,
|
||||
type: ElasticsearchDataType.text,
|
||||
},
|
||||
},
|
||||
ducet: {
|
||||
sort: {
|
||||
analyzer: analyzers.ducet_sort,
|
||||
fielddata: true,
|
||||
type: ElasticsearchDataType.text,
|
||||
},
|
||||
},
|
||||
ignore: ['price'],
|
||||
},
|
||||
};
|
||||
|
||||
export const filterableTagName = 'filterable';
|
||||
|
||||
export const filterableMap: ElasticsearchFilterableMap = {
|
||||
date: ElasticsearchDataType.keyword,
|
||||
keyword: ElasticsearchDataType.keyword,
|
||||
text: ElasticsearchDataType.keyword,
|
||||
integer: ElasticsearchDataType.integer,
|
||||
};
|
||||
69
packages/es-mapping-generator/src/config/premap.ts
Normal file
69
packages/es-mapping-generator/src/config/premap.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2021 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {ElasticsearchPremap} from '../types/mapping';
|
||||
import {ElasticsearchDataType} from './typemap';
|
||||
|
||||
export const premaps: ElasticsearchPremap = {
|
||||
CoordinateReferenceSystem: {
|
||||
dynamic: true,
|
||||
properties: {
|
||||
type: {
|
||||
type: ElasticsearchDataType.keyword,
|
||||
},
|
||||
},
|
||||
},
|
||||
LineString: {
|
||||
precision: '1m',
|
||||
tree: 'quadtree',
|
||||
type: ElasticsearchDataType.geo_shape,
|
||||
},
|
||||
Point: {
|
||||
properties: {
|
||||
type: {
|
||||
type: ElasticsearchDataType.keyword,
|
||||
},
|
||||
coordinates: {
|
||||
type: ElasticsearchDataType.geo_point,
|
||||
},
|
||||
},
|
||||
dynamic: 'strict',
|
||||
},
|
||||
Polygon: {
|
||||
precision: '1m',
|
||||
tree: 'quadtree',
|
||||
type: ElasticsearchDataType.geo_shape,
|
||||
},
|
||||
SCISO8601DateRange: {
|
||||
type: ElasticsearchDataType.date_range,
|
||||
},
|
||||
'jsonpatch.OpPatch': {
|
||||
dynamic: 'strict',
|
||||
properties: {
|
||||
from: {
|
||||
type: ElasticsearchDataType.keyword,
|
||||
},
|
||||
op: {
|
||||
type: ElasticsearchDataType.keyword,
|
||||
},
|
||||
path: {
|
||||
type: ElasticsearchDataType.keyword,
|
||||
},
|
||||
value: {
|
||||
// this is actually an 'any' type, however ES does not really support that.
|
||||
type: ElasticsearchDataType.keyword,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
65
packages/es-mapping-generator/src/config/settings.ts
Normal file
65
packages/es-mapping-generator/src/config/settings.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2021 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {ElasticsearchSettings} from '../types/mapping';
|
||||
|
||||
export const settings: ElasticsearchSettings = {
|
||||
analysis: {
|
||||
analyzer: {
|
||||
ducet_sort: {
|
||||
filter: [
|
||||
'german_phonebook',
|
||||
],
|
||||
tokenizer: 'keyword',
|
||||
type: 'custom',
|
||||
},
|
||||
search_german: {
|
||||
filter: [
|
||||
'lowercase',
|
||||
'german_stop',
|
||||
'german_stemmer',
|
||||
],
|
||||
tokenizer: 'stapps_ngram',
|
||||
type: 'custom',
|
||||
},
|
||||
},
|
||||
filter: {
|
||||
german_phonebook: {
|
||||
country: 'DE',
|
||||
language: 'de',
|
||||
type: 'icu_collation',
|
||||
variant: '@collation=phonebook',
|
||||
},
|
||||
german_stemmer: {
|
||||
language: 'german',
|
||||
type: 'stemmer',
|
||||
},
|
||||
german_stop: {
|
||||
stopwords: '_german_',
|
||||
type: 'stop',
|
||||
},
|
||||
},
|
||||
tokenizer: {
|
||||
stapps_ngram: {
|
||||
max_gram: 7,
|
||||
min_gram: 4,
|
||||
type: 'ngram',
|
||||
},
|
||||
},
|
||||
},
|
||||
'mapping.total_fields.limit': 10000,
|
||||
max_result_window: 30000,
|
||||
number_of_replicas: 0,
|
||||
number_of_shards: 1,
|
||||
};
|
||||
83
packages/es-mapping-generator/src/config/typemap.ts
Normal file
83
packages/es-mapping-generator/src/config/typemap.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2021 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {ElasticsearchTypemap} from '../types/mapping';
|
||||
|
||||
export enum ElasticsearchDataType {
|
||||
missing_premap = 'MISSING_PREMAP',
|
||||
parse_error = 'PARSE_ERROR',
|
||||
type_conflict = 'TYPE_CONFLICT',
|
||||
text = 'text',
|
||||
keyword = 'keyword',
|
||||
date = 'date',
|
||||
// long = 'long',
|
||||
// double = 'double',
|
||||
float = 'float',
|
||||
boolean = 'boolean',
|
||||
ip = 'ip',
|
||||
integer = 'integer',
|
||||
object = 'object',
|
||||
nested = 'nested',
|
||||
geo_point = 'geo_point',
|
||||
geo_shape = 'geo_shape',
|
||||
completion = 'completion',
|
||||
date_range = 'date_range',
|
||||
// integer_range = 'integer_range',
|
||||
// float_range = 'float_range',
|
||||
// long_range = 'long_range',
|
||||
// double_range = 'double_range',
|
||||
// ip_range = 'ip_range',
|
||||
}
|
||||
|
||||
export const typemap: ElasticsearchTypemap = {
|
||||
boolean: {
|
||||
default: ElasticsearchDataType.boolean,
|
||||
},
|
||||
false: {
|
||||
default: ElasticsearchDataType.boolean,
|
||||
},
|
||||
number: {
|
||||
default: ElasticsearchDataType.integer,
|
||||
float: ElasticsearchDataType.float,
|
||||
integer: ElasticsearchDataType.integer,
|
||||
date: ElasticsearchDataType.date,
|
||||
},
|
||||
string: {
|
||||
default: ElasticsearchDataType.text,
|
||||
keyword: ElasticsearchDataType.keyword,
|
||||
text: ElasticsearchDataType.text,
|
||||
date: ElasticsearchDataType.date,
|
||||
},
|
||||
stringLiteral: {
|
||||
default: ElasticsearchDataType.keyword,
|
||||
},
|
||||
true: {
|
||||
default: ElasticsearchDataType.boolean,
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* If the string is a tag type
|
||||
*/
|
||||
export function isTagType(str: string): boolean {
|
||||
for (const key in typemap) {
|
||||
if (typemap.hasOwnProperty(key) && typeof typemap[key][str] !== 'undefined') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export const dynamicTypes = ['any', 'unknown'];
|
||||
814
packages/es-mapping-generator/src/mapping.ts
Normal file
814
packages/es-mapping-generator/src/mapping.ts
Normal file
@@ -0,0 +1,814 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2021 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Logger} from '@openstapps/logger';
|
||||
import merge from 'deepmerge';
|
||||
import {stringify} from 'flatted';
|
||||
import {DeclarationReflection, ProjectReflection, SignatureReflection} from 'typedoc';
|
||||
import {
|
||||
ArrayType,
|
||||
Comment,
|
||||
CommentTag,
|
||||
IntrinsicType,
|
||||
ReferenceType,
|
||||
ReflectionType,
|
||||
StringLiteralType,
|
||||
Type,
|
||||
TypeParameterType,
|
||||
UnionType,
|
||||
} from 'typedoc/dist/lib/models';
|
||||
import {fieldmap, filterableMap, filterableTagName} from './config/fieldmap';
|
||||
import {premaps} from './config/premap';
|
||||
import {settings} from './config/settings';
|
||||
import {dynamicTypes, ElasticsearchDataType, isTagType, typemap} from './config/typemap';
|
||||
import {AggregationSchema, ESNestedAggregation} from './types/aggregation';
|
||||
import {
|
||||
ElasticsearchDynamicTemplate,
|
||||
ElasticsearchObject,
|
||||
ElasticsearchTemplateCollection,
|
||||
ElasticsearchType,
|
||||
ElasticsearchValue, MappingGenTemplate,
|
||||
} from './types/mapping';
|
||||
|
||||
let dynamicTemplates: ElasticsearchDynamicTemplate[] = [];
|
||||
let errors: string[] = [];
|
||||
let showErrors = true;
|
||||
|
||||
let aggregations: AggregationSchema = {};
|
||||
|
||||
const indexableTag = 'indexable';
|
||||
const aggregatableTag = 'aggregatable';
|
||||
const aggregatableTagParameterGlobal = 'global';
|
||||
const inheritTagsName = 'inherittags';
|
||||
|
||||
// clamp printed object to 1000 chars to keep error messages readable
|
||||
const maxErrorObjectChars = 1000;
|
||||
|
||||
let ignoredTagsList = ['indexable', 'validatable', inheritTagsName];
|
||||
let inheritTagsMap: { [path: string]: CommentTag[]; } = {};
|
||||
|
||||
/**
|
||||
* Gets all interfaces that have an @indexable tag
|
||||
*
|
||||
* @param projectReflection the project reflection from which to extract the indexable interfaces
|
||||
*/
|
||||
export function getAllIndexableInterfaces(projectReflection: ProjectReflection): DeclarationReflection[] {
|
||||
|
||||
let indexableInterfaces: DeclarationReflection[] = [];
|
||||
|
||||
if (!Array.isArray(projectReflection.children) || projectReflection.children.length === 0) {
|
||||
throw new Error('No DeclarationReflections found. Please check your input path');
|
||||
}
|
||||
|
||||
// push all declaration reflections into one array
|
||||
projectReflection.children.forEach((declarationReflection) => {
|
||||
if (Array.isArray(declarationReflection.children)) {
|
||||
indexableInterfaces = indexableInterfaces.concat(declarationReflection.children);
|
||||
}
|
||||
});
|
||||
|
||||
// filter all declaration reflections with an @indexable tag
|
||||
indexableInterfaces = indexableInterfaces.filter((declarationReflection) => {
|
||||
if (
|
||||
typeof declarationReflection.comment === 'undefined' ||
|
||||
typeof declarationReflection.comment.tags === 'undefined'
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return typeof declarationReflection.comment.tags.find((commentTag) => {
|
||||
return commentTag.tagName === indexableTag;
|
||||
}) !== 'undefined';
|
||||
});
|
||||
|
||||
return indexableInterfaces;
|
||||
}
|
||||
|
||||
/**
|
||||
* Composes error messages, that are readable and contain a certain minimum of information
|
||||
*
|
||||
* @param path the path where the error took place
|
||||
* @param topTypeName the name of the SCThingType
|
||||
* @param typeName the name of the object, with which something went wrong
|
||||
* @param object the object or name
|
||||
* @param message the error message
|
||||
*/
|
||||
function composeErrorMessage(path: string, topTypeName: string, typeName: string, object: string, message: string) {
|
||||
const error = `At "${topTypeName}::${path.substr(0, path.length - 1)}" for ${typeName} "${trimString(object, maxErrorObjectChars)}": ${message}`;
|
||||
errors.push(error);
|
||||
if (showErrors) {
|
||||
// tslint:disable-next-line:no-floating-promises
|
||||
void Logger.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trims a string to a readable size and appends "..."
|
||||
*
|
||||
* @param value the string to trim
|
||||
* @param maxLength the maximum allowed length before it is clamped
|
||||
*/
|
||||
function trimString(value: string, maxLength: number): string {
|
||||
return value.length > maxLength ?
|
||||
`${value.substring(0, maxLength)}...` :
|
||||
value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Reflections and names for Generics in a ReferenceType of a DeclarationReflection
|
||||
*
|
||||
* Warning to future maintainers: The code for generics doesn't account for depth. when there is a new generic, it will
|
||||
* override the previous one, if there isn't, it will just continue passing it down.
|
||||
*
|
||||
* @param type the ReferenceType of a DeclarationReflection
|
||||
* @param out the previous reflection, it then overrides all parameters or keeps old ones
|
||||
* @param topTypeName the name of the object, with which something went wrong
|
||||
* @param path the current path to the object we are in
|
||||
* @param tags any tags attached to the type
|
||||
*/
|
||||
function getReflectionGeneric(type: ReferenceType,
|
||||
out: Map<string, ElasticsearchValue>,
|
||||
topTypeName: string,
|
||||
path: string,
|
||||
tags: CommentTag[]): Map<string, ElasticsearchValue> {
|
||||
if (typeof type.typeArguments !== 'undefined'
|
||||
&& type.reflection instanceof DeclarationReflection
|
||||
&& typeof type.reflection.typeParameters !== 'undefined') {
|
||||
for (let i = 0; i < type.reflection.typeParameters.length; i++) {
|
||||
if (i < type.typeArguments.length) {
|
||||
out
|
||||
.set(type.reflection.typeParameters[i].name, handleType(type.typeArguments[i], out, topTypeName, path, tags));
|
||||
} else {
|
||||
// this can happen due to a bug in TypeDoc https://github.com/TypeStrong/typedoc/issues/1061
|
||||
// we have no way to know the type here, so we have to use this.
|
||||
out.set(type.reflection.typeParameters[i].name, {
|
||||
dynamic: true,
|
||||
properties: {},
|
||||
});
|
||||
|
||||
Logger.warn(`Type "${type.name}": Defaults of generics (Foo<T = any>) currently don't work due to a bug` +
|
||||
` in TypeDoc. It has been replaced by a dynamic type.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a ReferenceType that has no value
|
||||
*
|
||||
* Most of the times that is an external type.
|
||||
*
|
||||
* @param ref the ReferenceType
|
||||
* @param generics the generics from levels above, so we can use them without having access to the parent
|
||||
* @param path the current path to the object we are in
|
||||
* @param topTypeName the name of the SCThingType
|
||||
* @param tags any tags attached to the type
|
||||
*/
|
||||
function handleExternalType(ref: ReferenceType, generics: Map<string, ElasticsearchValue>,
|
||||
path: string, topTypeName: string, tags: CommentTag[]): ElasticsearchValue {
|
||||
for (const premap of Object.keys(premaps)) {
|
||||
if (premap === ref.name) {
|
||||
return readFieldTags(premaps[premap], path, topTypeName, tags);
|
||||
}
|
||||
}
|
||||
|
||||
if (ref.name === 'Array') { // basically an external type, but Array is quite common, especially with generics
|
||||
if (typeof ref.typeArguments === 'undefined' || typeof ref.typeArguments[0] === 'undefined') {
|
||||
composeErrorMessage(path, topTypeName, 'Array with generics', 'array', 'Failed to parse');
|
||||
|
||||
return {type: ElasticsearchDataType.parse_error};
|
||||
}
|
||||
|
||||
return readFieldTags(
|
||||
handleType(
|
||||
ref.typeArguments[0], getReflectionGeneric(
|
||||
ref, new Map(generics), path, topTypeName, tags),
|
||||
path, topTypeName, tags),
|
||||
path, topTypeName, tags);
|
||||
}
|
||||
if (ref.name === '__type') { // empty object
|
||||
return {
|
||||
dynamic: 'strict',
|
||||
properties: {},
|
||||
};
|
||||
}
|
||||
|
||||
composeErrorMessage(path, topTypeName, 'external type', ref.name, 'Missing pre-map');
|
||||
|
||||
return readFieldTags({type: ElasticsearchDataType.missing_premap}, path, topTypeName, tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles an object
|
||||
*
|
||||
* @param decl the DeclarationReflection of the object
|
||||
* @param generics the generics from levels above, so we can use them without having access to the parent
|
||||
* @param path the current path to the object we are in
|
||||
* @param topTypeName the name of the SCThingType
|
||||
* @param inheritedTags the inherited tags
|
||||
*/
|
||||
function handleDeclarationReflection(decl: DeclarationReflection,
|
||||
generics: Map<string, ElasticsearchValue>,
|
||||
path: string,
|
||||
topTypeName: string,
|
||||
inheritedTags?: CommentTag[]):
|
||||
ElasticsearchValue {
|
||||
// check if we have an object referencing a generic
|
||||
if (generics.has(decl.name)) { // if the object name is the same as the generic name
|
||||
return readFieldTags(generics.get(decl.name) as ElasticsearchObject | ElasticsearchType, path, topTypeName,
|
||||
decl.comment?.tags ?? []);
|
||||
// use the value defined by the generic
|
||||
|
||||
}
|
||||
|
||||
// start the actual handling process
|
||||
const out: ElasticsearchObject = {
|
||||
dynamic: 'strict',
|
||||
properties: {},
|
||||
};
|
||||
|
||||
let empty = true;
|
||||
// first check if there are any index signatures, so for example `[name: string]: Foo`
|
||||
if (typeof decl.indexSignature !== 'undefined') {
|
||||
out.dynamic = true;
|
||||
|
||||
if (typeof decl.indexSignature.type !== 'undefined') {
|
||||
empty = false;
|
||||
const template: ElasticsearchDynamicTemplate = {};
|
||||
template[decl.name] = {
|
||||
mapping: handleType(
|
||||
decl.indexSignature.type,
|
||||
new Map(generics), path, topTypeName,
|
||||
getCommentTags(decl.indexSignature, path, topTypeName),
|
||||
),
|
||||
match: '*',
|
||||
match_mapping_type: '*',
|
||||
path_match: `${path}*`,
|
||||
};
|
||||
dynamicTemplates.push(template);
|
||||
}
|
||||
}
|
||||
|
||||
if (decl.kindString === 'Enumeration') {
|
||||
return readTypeTags('string', path, topTypeName, getCommentTags(decl, path, topTypeName, inheritedTags));
|
||||
}
|
||||
|
||||
// check all the children, so in this case we are dealing with an OBJECT
|
||||
if (typeof decl.children !== 'undefined' && decl.children.length > 0) {
|
||||
for (const child of decl.children) {
|
||||
empty = false;
|
||||
out.properties[child.name] =
|
||||
handleDeclarationReflection(child, new Map(generics), `${path}${child.name}.`, topTypeName);
|
||||
}
|
||||
} else if (decl.type instanceof Type) { // if the object is a type, so we are dealing with a PROPERTY
|
||||
// get inherited tags
|
||||
const tags = (inheritedTags ?? []).length > 0
|
||||
? (typeof inheritedTags!.find(it => isTagType(it.tagName)) !== 'undefined'
|
||||
? inheritedTags!
|
||||
: [...inheritedTags ?? [], ...getCommentTags(decl, path, topTypeName)])
|
||||
: getCommentTags(decl, path, topTypeName);
|
||||
|
||||
return handleType(decl.type, new Map(generics), path, topTypeName, tags);
|
||||
} else if (decl.kindString === 'Enumeration member') {
|
||||
return readTypeTags(typeof decl.defaultValue, path, topTypeName,
|
||||
getCommentTags(decl, path, topTypeName, inheritedTags));
|
||||
}
|
||||
|
||||
if (empty) {
|
||||
composeErrorMessage(path, topTypeName, 'object', decl.name, 'Empty object');
|
||||
}
|
||||
|
||||
return readFieldTags(out, path, topTypeName, getCommentTags(decl, path, topTypeName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads all comment tags, including inherited ones
|
||||
*
|
||||
* @param decl the DeclarationReflection to read the tags from
|
||||
* @param path the path on which the comments lie
|
||||
* @param topTypeName the name of the SCThingType
|
||||
* @param inheritedTags any tags that might have been inherited by a parent
|
||||
* @param breakId the id of the previous reflection to prevent infinite recursion in some cases
|
||||
*/
|
||||
function getCommentTags(
|
||||
decl: DeclarationReflection | SignatureReflection,
|
||||
path: string,
|
||||
topTypeName: string,
|
||||
inheritedTags: CommentTag[] = [],
|
||||
// tslint:disable-next-line:no-unnecessary-initializer
|
||||
breakId: number | undefined = undefined,
|
||||
): CommentTag[] {
|
||||
if (decl.id === breakId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
let out: CommentTag[] = decl.comment instanceof Comment ?
|
||||
typeof decl.comment.tags !== 'undefined' ? decl.comment.tags : inheritedTags : inheritedTags;
|
||||
if (decl.overwrites instanceof ReferenceType && decl.overwrites.reflection instanceof DeclarationReflection) {
|
||||
out = arrayPriorityJoin(
|
||||
getCommentTags(decl.overwrites.reflection, path, topTypeName, inheritedTags, decl.id), out);
|
||||
}
|
||||
if (decl.inheritedFrom instanceof ReferenceType && decl.inheritedFrom.reflection instanceof DeclarationReflection) {
|
||||
out = arrayPriorityJoin(
|
||||
getCommentTags(decl.inheritedFrom.reflection, path, topTypeName, inheritedTags, decl.id), out);
|
||||
}
|
||||
|
||||
saveCommentTags(out, path, topTypeName);
|
||||
const inheritTag = out.find(((value) => value.tagName === inheritTagsName));
|
||||
if (typeof inheritTag !== 'undefined') {
|
||||
out = arrayPriorityJoin(out, retrieveCommentTags(inheritTag.text.trim(), path, topTypeName));
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves all comment tags to the map
|
||||
*
|
||||
* @param tags all tags to be saved (@see and @[inheritTags] will be stripped)
|
||||
* @param path the path of field
|
||||
* @param topTypeName the name of the SCThingType
|
||||
*/
|
||||
function saveCommentTags(tags: CommentTag[], path: string, topTypeName: string) {
|
||||
inheritTagsMap[`${topTypeName}::${path.substr(0, path.length - 1)}`] =
|
||||
tags.filter(((value) => value.tagName !== 'see' && value.tagName !== inheritTagsName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves any saved tags
|
||||
*
|
||||
* @param path the path to the original field
|
||||
* @param currentPath the current path to the object we are in
|
||||
* @param topTypeName the name of the SCThingType
|
||||
*/
|
||||
function retrieveCommentTags(path: string, currentPath: string, topTypeName: string): CommentTag[] {
|
||||
if (!(path in inheritTagsMap)) {
|
||||
composeErrorMessage(currentPath, topTypeName, path, 'Comment', 'Referenced path to tags does not exist!');
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
return inheritTagsMap[path];
|
||||
}
|
||||
|
||||
/**
|
||||
* Joins two arrays of CommentTags, but overrides all original CommentTags with the same tagName
|
||||
*
|
||||
* @param originals the original array
|
||||
* @param overrider the array that should be appended and provide the override values
|
||||
*/
|
||||
function arrayPriorityJoin(originals: CommentTag[], overrider: CommentTag[]): CommentTag[] {
|
||||
const out: CommentTag[] = overrider;
|
||||
|
||||
originals.forEach((original) => {
|
||||
const result = overrider.find((element) => original.tagName === element.tagName);
|
||||
|
||||
// no support for multiple tags with the same name
|
||||
if (!(result instanceof CommentTag)) {
|
||||
out.push(original);
|
||||
}
|
||||
});
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles UnionTypes
|
||||
*
|
||||
* Put into a separate function as it is a little bit more complex
|
||||
* Works fairly reliable, although there are issues with primitive union types, which don't work at all (And never will)
|
||||
*
|
||||
* @param type the type object
|
||||
* @param generics the generics from levels above, so we can use them without having access to the parent
|
||||
* @param path the current path to the object we are in
|
||||
* @param topTypeName the name of the SCThingType
|
||||
* @param tags any tags attached to the type
|
||||
*/
|
||||
function handleUnionType(type: UnionType,
|
||||
generics: Map<string, ElasticsearchValue>,
|
||||
path: string,
|
||||
topTypeName: string,
|
||||
tags: CommentTag[]): ElasticsearchValue {
|
||||
const list: ElasticsearchValue[] = [];
|
||||
|
||||
for (const subType of type.types) {
|
||||
if (subType instanceof IntrinsicType && subType.name === 'undefined') {
|
||||
continue;
|
||||
}
|
||||
list.push(handleType(subType, new Map(generics), path, topTypeName, tags));
|
||||
}
|
||||
|
||||
if (list.length > 0) {
|
||||
let out = list[0];
|
||||
|
||||
for (const item of list) {
|
||||
out = merge<ElasticsearchValue>(out, item);
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
composeErrorMessage(path, topTypeName, 'Union Type', stringify(list),
|
||||
'Empty union type. This is likely not a user error.');
|
||||
|
||||
return {type: ElasticsearchDataType.parse_error};
|
||||
}
|
||||
|
||||
/**
|
||||
* Serves as a kind of distributor for the different types, should not contain any specific code
|
||||
*
|
||||
* @param type the type object
|
||||
* @param generics the generics from levels above, so we can use them without having access to the parent
|
||||
* @param path the current path to the object we are in
|
||||
* @param topTypeName the name of the SCThingType
|
||||
* @param tags any tags attached to the type
|
||||
*/
|
||||
function handleType(type: Type, generics: Map<string, ElasticsearchValue>, path: string, topTypeName: string,
|
||||
tags: CommentTag[]):
|
||||
ElasticsearchValue {
|
||||
// logger.log((type as any).name);
|
||||
if (type instanceof ArrayType) { // array is irrelevant in Elasticsearch, so just go with the element type
|
||||
const esType = handleType(type.elementType, new Map(generics), path, topTypeName, tags);
|
||||
// also merge tags of the array to the element type
|
||||
// filter out the type tags lazily, this can lead to double messages for "Not implemented tag"
|
||||
let newTags = tags;
|
||||
if ('type' in esType) {
|
||||
newTags = tags.filter((tag) => {
|
||||
return !(tag.tagName === esType.type);
|
||||
});
|
||||
}
|
||||
|
||||
return readFieldTags(esType, path, topTypeName, newTags);
|
||||
}
|
||||
if (type.type === 'stringLiteral') { // a string literal, usually for type
|
||||
return readTypeTags(type.type, path, topTypeName, tags);
|
||||
}
|
||||
if (type instanceof IntrinsicType) { // the absolute default type, like strings
|
||||
return readTypeTags(type.name, path, topTypeName, tags);
|
||||
}
|
||||
if (type instanceof UnionType) { // the union type...
|
||||
return handleUnionType(type, new Map(generics), path, topTypeName, tags);
|
||||
}
|
||||
if (type instanceof ReferenceType) {
|
||||
if (typeof premaps[type.name] === 'undefined' && typeof type.reflection !== 'undefined') {
|
||||
// there is really no way to make this typesafe, every element in DeclarationReflection is optional.
|
||||
return handleDeclarationReflection(type.reflection as DeclarationReflection,
|
||||
getReflectionGeneric(type, new Map(generics), path, topTypeName, tags), path, topTypeName, tags);
|
||||
}
|
||||
|
||||
return handleExternalType(type, new Map(generics), path, topTypeName, tags);
|
||||
}
|
||||
if (type instanceof TypeParameterType) {
|
||||
// check if we have an object referencing a generic
|
||||
if (generics.has(type.name)) {
|
||||
return generics.get(type.name) as ElasticsearchObject | ElasticsearchType;
|
||||
}
|
||||
composeErrorMessage(path, topTypeName, 'Generic', type.name, 'Missing reflection, please report!');
|
||||
|
||||
return {type: ElasticsearchDataType.parse_error};
|
||||
|
||||
}
|
||||
if (type instanceof ReflectionType) {
|
||||
return readFieldTags(handleDeclarationReflection(type.declaration, new Map(generics), path, topTypeName),
|
||||
path, topTypeName, tags);
|
||||
}
|
||||
|
||||
composeErrorMessage(path, topTypeName, 'type', stringify(type), 'Not implemented type');
|
||||
|
||||
return {type: ElasticsearchDataType.parse_error};
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an aggregatable to the aggregations list
|
||||
*
|
||||
* @param path the current path
|
||||
* @param topTypeName the name of the top type
|
||||
* @param global whether the topTypeName will be used
|
||||
*/
|
||||
function addAggregatable(path: string, topTypeName: string, global: boolean) {
|
||||
// push type.path and remove the '.' at the end of the path
|
||||
|
||||
if (global) {
|
||||
const prop = path.slice(0, -1)
|
||||
.split('.')
|
||||
.pop() as string; // cannot be undefined
|
||||
|
||||
return (aggregations['@all'] as ESNestedAggregation).aggs[prop.split('.')
|
||||
.pop() as string] = {
|
||||
terms: {
|
||||
field: `${prop}.raw`,
|
||||
size: 1000,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const property = path.slice(0, -1);
|
||||
|
||||
return (aggregations[topTypeName] as ESNestedAggregation).aggs[property] = {
|
||||
terms: {
|
||||
field: `${property}.raw`,
|
||||
size: 1000,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads all tags related to Elasticsearch fields from the fieldMap
|
||||
*
|
||||
* @param prev the previous ElasticsearchValue, for example and object
|
||||
* @param path the current path to the object we are in
|
||||
* @param topTypeName the name of the SCThingType
|
||||
* @param tags tags attached to the value
|
||||
* @param dataType the ElasticsearchDataType, for checking if a tag is a type tag
|
||||
*/
|
||||
function readFieldTags(prev: ElasticsearchValue,
|
||||
path: string,
|
||||
topTypeName: string,
|
||||
tags: CommentTag[],
|
||||
dataType?: string): ElasticsearchValue {
|
||||
for (const tag of tags) {
|
||||
if (tag.tagName === aggregatableTag) {
|
||||
addAggregatable(path, topTypeName, tag.text.trim() === aggregatableTagParameterGlobal);
|
||||
}
|
||||
|
||||
if (!ignoredTagsList.includes(tag.tagName)) {
|
||||
if (typeof fieldmap[tag.tagName] !== 'undefined') {
|
||||
if (typeof prev.fields === 'undefined') {
|
||||
// create in case it doesn't exist
|
||||
prev.fields = {};
|
||||
}
|
||||
if (tag.text.trim() === '') {
|
||||
// merge fields
|
||||
prev.fields = {...prev.fields, ...fieldmap[tag.tagName].default};
|
||||
} else if (typeof fieldmap[tag.tagName][tag.text.trim()] !== 'undefined') {
|
||||
// merge fields
|
||||
prev.fields = {...prev.fields, ...fieldmap[tag.tagName][tag.text.trim()]};
|
||||
} else if (!fieldmap[tag.tagName].ignore.includes(tag.text.trim())) {
|
||||
// when there is an unidentified tag
|
||||
composeErrorMessage(path, topTypeName, 'tag', tag.tagName, `Not implemented tag param "${tag.text.trim()}"`);
|
||||
}
|
||||
} else if (tag.tagName === filterableTagName) {
|
||||
if (typeof prev.fields === 'undefined') {
|
||||
prev.fields = {};
|
||||
}
|
||||
if ('type' in prev) {
|
||||
const type = filterableMap[prev.type];
|
||||
if (typeof type !== 'undefined') {
|
||||
// merge fields
|
||||
prev.fields = {...prev.fields, ...{raw: {type: type}}};
|
||||
} else {
|
||||
composeErrorMessage(path, topTypeName, 'tag', tag.tagName, `Not implemented for ${prev.type}`);
|
||||
}
|
||||
} else {
|
||||
composeErrorMessage(path, topTypeName, 'tag', tag.tagName, 'Not applicable for object types');
|
||||
}
|
||||
} else if (typeof dataType === 'undefined' || typeof typemap[dataType][tag.tagName] === 'undefined') {
|
||||
composeErrorMessage(path, topTypeName, 'tag', tag.tagName, `Not implemented tag`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return prev;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads all types related to Elasticsearch fields from the fieldMap
|
||||
*
|
||||
* @param type the type of the value
|
||||
* @param path the current path to the object we are in
|
||||
* @param topTypeName the name of the SCThingType
|
||||
* @param tags tags attached to the value
|
||||
*/
|
||||
function readTypeTags(type: string, path: string, topTypeName: string, tags: CommentTag[]): ElasticsearchValue {
|
||||
let out: ElasticsearchValue = {type: ElasticsearchDataType.parse_error};
|
||||
|
||||
if (typeof typemap[type] !== 'undefined') { // first look if the value has a definition in the typemap
|
||||
for (let i = tags.length - 1; i >= 0; i--) {
|
||||
if (!ignoredTagsList.includes(tags[i].tagName) && typeof typemap[type][tags[i].tagName] !== 'undefined') {
|
||||
// if we have a tag that indicates a type
|
||||
if (out.type !== ElasticsearchDataType.parse_error) {
|
||||
composeErrorMessage(path, topTypeName, 'type', type,
|
||||
`Type conflict; "${typemap[type][tags[i].tagName]}" would override "${out.type}"`);
|
||||
out.type = ElasticsearchDataType.type_conflict;
|
||||
continue;
|
||||
}
|
||||
out.type = typemap[type][tags[i].tagName];
|
||||
}
|
||||
}
|
||||
|
||||
if (out.type === ElasticsearchDataType.parse_error) {
|
||||
out.type = typemap[type].default;
|
||||
}
|
||||
|
||||
out = readFieldTags(out, path, topTypeName, tags, type);
|
||||
|
||||
return out;
|
||||
}
|
||||
if (dynamicTypes.includes(type)) { // Elasticsearch dynamic type TODO: doesn't work for direct types
|
||||
return {
|
||||
dynamic: true,
|
||||
properties: {},
|
||||
};
|
||||
}
|
||||
|
||||
composeErrorMessage(path, topTypeName, 'type', type, 'Not implemented type');
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the state
|
||||
*
|
||||
* This is kind of a suboptimal solution and should be changed in the future.
|
||||
* https://gitlab.com/openstapps/core-tools/-/issues/49
|
||||
*
|
||||
* @param resetInheritTags whether inherited tags should be reset as well
|
||||
*/
|
||||
function reset(resetInheritTags = true) {
|
||||
errors = [];
|
||||
dynamicTemplates = [];
|
||||
aggregations = {
|
||||
'@all': {
|
||||
aggs: {},
|
||||
filter: {
|
||||
match_all: {},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
if (resetInheritTags) {
|
||||
inheritTagsMap = {};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a project reflection and generates an ElasticsearchTemplate from it
|
||||
*
|
||||
* Serves as the entry point for getting the mapping, so if you just want to get the mapping files for Elasticsearch,
|
||||
* you can do so by calling this function, `RETURNED_VALUE.template` contains the mapping in a fashion that is directly
|
||||
* readable by Elasticsearch.
|
||||
*
|
||||
* @param projectReflection a reflection of the project you want to get the ES Mappings from
|
||||
* @param ignoredTags the tag names for which the error output should be suppressed
|
||||
* @param showErrorOutput whether to print all errors in the command line or not
|
||||
* @param interfaceFilter only parse specific interfaces, this is for testing purposes
|
||||
*/
|
||||
export function generateTemplate(projectReflection: ProjectReflection,
|
||||
ignoredTags: string[],
|
||||
showErrorOutput = true,
|
||||
interfaceFilter: string[] = []): MappingGenTemplate {
|
||||
reset();
|
||||
|
||||
showErrors = showErrorOutput;
|
||||
|
||||
ignoredTagsList = ['indexable', 'validatable', inheritTagsName];
|
||||
ignoredTagsList.push.apply(ignoredTagsList, ignoredTags);
|
||||
|
||||
const indexableInterfaces = getAllIndexableInterfaces(projectReflection);
|
||||
|
||||
const out: ElasticsearchTemplateCollection = {};
|
||||
|
||||
for (const _interface of indexableInterfaces) {
|
||||
// TODO: lots of duplicate code, this all needs to be changed https://gitlab.com/openstapps/core-tools/-/issues/49
|
||||
if (!Array.isArray(_interface.children) || _interface.children.length === 0) {
|
||||
throw new Error('Interface needs at least some properties to be indexable');
|
||||
}
|
||||
|
||||
const typeObject = _interface.children.find((declarationReflection) => {
|
||||
return declarationReflection.name === 'type';
|
||||
});
|
||||
|
||||
if (typeof typeObject === 'undefined' || typeof typeObject.type === 'undefined') {
|
||||
throw new Error('Interface needs a type to be indexable');
|
||||
}
|
||||
|
||||
let typeName = 'INVALID_TYPE';
|
||||
if (typeObject.type instanceof ReferenceType) {
|
||||
if (typeObject.type.reflection instanceof DeclarationReflection
|
||||
&& typeof typeObject.type.reflection.defaultValue === 'string') {
|
||||
typeName = typeObject.type.reflection.defaultValue.replace('"', '')
|
||||
.replace('"', '');
|
||||
} else {
|
||||
// tslint:disable-next-line:no-floating-promises
|
||||
void Logger.error('Your input files seem to be incorrect, or there is a major bug in the mapping generator.');
|
||||
}
|
||||
} else if (typeObject.type instanceof StringLiteralType) {
|
||||
Logger.warn(`The interface ${_interface.name} uses a string literal as type, please use SCThingType.`);
|
||||
typeName = typeObject.type.value;
|
||||
} else {
|
||||
// tslint:disable-next-line:no-floating-promises
|
||||
void Logger.error(`The interface ${_interface.name} is required to use an SCThingType as a type, please do so.`);
|
||||
}
|
||||
// init aggregation schema for type
|
||||
aggregations[typeName] = {
|
||||
aggs: {},
|
||||
filter: {
|
||||
type: {
|
||||
value: typeName,
|
||||
},
|
||||
},
|
||||
};
|
||||
handleDeclarationReflection(_interface, new Map(), '', typeName);
|
||||
}
|
||||
|
||||
// second traversal
|
||||
reset(false);
|
||||
|
||||
for (const _interface of indexableInterfaces) {
|
||||
if (!Array.isArray(_interface.children) || _interface.children.length === 0) {
|
||||
throw new Error('Interface needs at least some properties to be indexable');
|
||||
}
|
||||
|
||||
const typeObject = _interface.children.find((declarationReflection) => {
|
||||
return declarationReflection.name === 'type';
|
||||
});
|
||||
|
||||
if (typeof typeObject === 'undefined' || typeof typeObject.type === 'undefined') {
|
||||
throw new Error('Interface needs a type to be indexable');
|
||||
}
|
||||
|
||||
let typeName = 'INVALID_TYPE';
|
||||
if (typeObject.type instanceof ReferenceType) {
|
||||
if (typeObject.type.reflection instanceof DeclarationReflection
|
||||
&& typeof typeObject.type.reflection.defaultValue === 'string') {
|
||||
typeName = typeObject.type.reflection.defaultValue.replace('"', '')
|
||||
.replace('"', '');
|
||||
} else {
|
||||
// tslint:disable-next-line:no-floating-promises
|
||||
void Logger.error('Your input files seem to be incorrect, or there is a major bug in the mapping generator.');
|
||||
}
|
||||
} else if (typeObject.type instanceof StringLiteralType) {
|
||||
Logger.warn(`The interface ${_interface.name} uses a string literal as type, please use SCThingType.`);
|
||||
typeName = typeObject.type.value;
|
||||
} else {
|
||||
// tslint:disable-next-line:no-floating-promises
|
||||
void Logger.error(`The interface ${_interface.name} is required to use an SCThingType as a type, please do so.`);
|
||||
}
|
||||
|
||||
// filter out
|
||||
if (interfaceFilter.length !== 0) {
|
||||
if (typeof interfaceFilter.find((it) => it === typeName) === 'undefined') {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// init aggregation schema for type
|
||||
aggregations[typeName] = {
|
||||
aggs: {},
|
||||
filter: {
|
||||
type: {
|
||||
value: typeName,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
let typeNameWithoutSpaces = typeName.toLowerCase();
|
||||
while (typeNameWithoutSpaces.includes(' ')) {
|
||||
typeNameWithoutSpaces = typeNameWithoutSpaces.replace(' ', '_');
|
||||
}
|
||||
const templateName = `template_${typeNameWithoutSpaces}`;
|
||||
|
||||
out[templateName] = {
|
||||
mappings: {
|
||||
[typeName]: handleDeclarationReflection(_interface, new Map(), '', typeName) as ElasticsearchObject,
|
||||
},
|
||||
settings: settings,
|
||||
template: `stapps_${typeNameWithoutSpaces}*`,
|
||||
}
|
||||
;
|
||||
out[templateName].mappings[typeName].properties.creation_date = {
|
||||
type: ElasticsearchDataType.date,
|
||||
};
|
||||
|
||||
out[templateName].mappings[typeName].dynamic_templates = dynamicTemplates;
|
||||
|
||||
// Set some properties
|
||||
out[templateName].mappings[typeName]._source = {
|
||||
excludes: [
|
||||
'creation_date',
|
||||
],
|
||||
};
|
||||
out[templateName].mappings[typeName].date_detection = false;
|
||||
|
||||
dynamicTemplates = [];
|
||||
|
||||
if (Object.keys((aggregations[typeName] as ESNestedAggregation).aggs).length === 0) {
|
||||
delete aggregations[typeName];
|
||||
}
|
||||
}
|
||||
|
||||
return {aggregations, mappings: out, errors};
|
||||
}
|
||||
93
packages/es-mapping-generator/src/project-reflection.ts
Normal file
93
packages/es-mapping-generator/src/project-reflection.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2021 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Logger} from '@openstapps/logger';
|
||||
import {existsSync, PathLike} from 'fs';
|
||||
import {platform} from 'os';
|
||||
import {join, sep} from 'path';
|
||||
import {Application, ProjectReflection} from 'typedoc';
|
||||
import {ModuleKind, ScriptTarget} from 'typescript';
|
||||
|
||||
/**
|
||||
* Get a project reflection from a path
|
||||
*
|
||||
* @param srcPath Path to get reflection from
|
||||
* @param excludeExternals Exclude external dependencies
|
||||
*/
|
||||
export function getProjectReflection(srcPath: PathLike, excludeExternals = true): ProjectReflection {
|
||||
Logger.info(`Generating project reflection for ${srcPath.toString()}.`);
|
||||
|
||||
const tsconfigPath = getTsconfigPath(srcPath.toString());
|
||||
|
||||
// initialize new Typedoc application
|
||||
const app = new Application();
|
||||
|
||||
app.bootstrap({
|
||||
excludeExternals: excludeExternals,
|
||||
ignoreCompilerErrors: false, // TODO: true
|
||||
includeDeclarations: true,
|
||||
module: ModuleKind.CommonJS,
|
||||
target: ScriptTarget.Latest,
|
||||
tsconfig: join(tsconfigPath, 'tsconfig.json'),
|
||||
});
|
||||
|
||||
let inputFilePath = srcPath;
|
||||
if (inputFilePath === tsconfigPath) {
|
||||
inputFilePath = join(tsconfigPath, 'src');
|
||||
}
|
||||
|
||||
// get input files
|
||||
const inputFiles = app.expandInputFiles([inputFilePath.toString()]);
|
||||
|
||||
// get project reflection from input files
|
||||
const result = app.convert(inputFiles);
|
||||
|
||||
if (typeof result === 'undefined') {
|
||||
throw new Error('Project reflection could not be generated.');
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get path that contains a tsconfig.json
|
||||
*
|
||||
* @param startPath Path from where to start searching "upwards"
|
||||
*/
|
||||
export function getTsconfigPath(startPath: string): string {
|
||||
let tsconfigPath = startPath;
|
||||
|
||||
// see https://stackoverflow.com/questions/9652043/identifying-the-file-system-root-with-node-js
|
||||
const root = (platform() === 'win32') ? process
|
||||
.cwd()
|
||||
.split(sep)[0] : '/';
|
||||
|
||||
// repeat until a tsconfig.json is found
|
||||
while (!existsSync(join(tsconfigPath, 'tsconfig.json'))) {
|
||||
if (tsconfigPath === root) {
|
||||
throw new Error(
|
||||
`Reached file system root ${root} while searching for 'tsconfig.json' in ${startPath}!`,
|
||||
);
|
||||
}
|
||||
|
||||
// pop last directory
|
||||
const tsconfigPathParts = tsconfigPath.split(sep);
|
||||
tsconfigPathParts.pop();
|
||||
tsconfigPath = tsconfigPathParts.join(sep);
|
||||
}
|
||||
|
||||
Logger.info(`Using 'tsconfig.json' from ${tsconfigPath}.`);
|
||||
|
||||
return tsconfigPath;
|
||||
}
|
||||
81
packages/es-mapping-generator/src/types/aggregation.d.ts
vendored
Normal file
81
packages/es-mapping-generator/src/types/aggregation.d.ts
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2021 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* An elasticsearch bucket aggregation
|
||||
* @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket.html
|
||||
*/
|
||||
export interface AggregationSchema {
|
||||
[aggregationName: string]: ESTermsFilter | ESNestedAggregation;
|
||||
}
|
||||
|
||||
/**
|
||||
* An elasticsearch terms filter
|
||||
*/
|
||||
export interface ESTermsFilter {
|
||||
/**
|
||||
* Terms filter definition
|
||||
*/
|
||||
terms: {
|
||||
/**
|
||||
* Field to apply filter to
|
||||
*/
|
||||
field: string;
|
||||
|
||||
/**
|
||||
* Number of results
|
||||
*/
|
||||
size?: number;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter that filters by name of the the field type
|
||||
*/
|
||||
export interface ESAggTypeFilter {
|
||||
/**
|
||||
* The type of the object to find
|
||||
*/
|
||||
type: {
|
||||
/**
|
||||
* The name of the type
|
||||
*/
|
||||
value: string;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter that matches everything
|
||||
*/
|
||||
export interface ESAggMatchAllFilter {
|
||||
/**
|
||||
* Filter that matches everything
|
||||
*/
|
||||
match_all: {};
|
||||
}
|
||||
|
||||
/**
|
||||
* For nested aggregations
|
||||
*/
|
||||
export interface ESNestedAggregation {
|
||||
/**
|
||||
* Possible nested Aggregations
|
||||
*/
|
||||
aggs: AggregationSchema;
|
||||
/**
|
||||
* Possible filter for types
|
||||
*/
|
||||
filter: ESAggTypeFilter | ESAggMatchAllFilter;
|
||||
}
|
||||
345
packages/es-mapping-generator/src/types/mapping.d.ts
vendored
Normal file
345
packages/es-mapping-generator/src/types/mapping.d.ts
vendored
Normal file
@@ -0,0 +1,345 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2021 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {ElasticsearchDataType} from '../config/typemap';
|
||||
import {AggregationSchema} from './aggregation';
|
||||
|
||||
// tslint:disable:no-any
|
||||
|
||||
/**
|
||||
* Template output of the mapping generation
|
||||
*/
|
||||
export interface MappingGenTemplate {
|
||||
/**
|
||||
* All generated aggregations
|
||||
*/
|
||||
aggregations: AggregationSchema;
|
||||
|
||||
/**
|
||||
* All errors that occurred
|
||||
*/
|
||||
errors: string[];
|
||||
|
||||
/**
|
||||
* All mappings that were generated
|
||||
*/
|
||||
mappings: ElasticsearchTemplateCollection;
|
||||
}
|
||||
|
||||
/**
|
||||
* ElasticsearchValue can be either a type or an object.
|
||||
*
|
||||
* Both are composed similarly, and can be the value of a property
|
||||
* of an Elasticsearch Object.
|
||||
*/
|
||||
export type ElasticsearchValue = ElasticsearchType | ElasticsearchObject | ElasticsearchGeoShape;
|
||||
|
||||
/**
|
||||
* The Typemap is used to get the corresponding ElasticsearchDataType for a name provided by the ProjectReflection
|
||||
*/
|
||||
export interface ElasticsearchTypemap {
|
||||
/**
|
||||
* The `stringLiteral` type must always be provided
|
||||
*/
|
||||
stringLiteral: {
|
||||
/**
|
||||
* The default can be chosen freely, but must be provided
|
||||
*/
|
||||
default: ElasticsearchDataType;
|
||||
};
|
||||
|
||||
/**
|
||||
* The name of the JS type, so for `number` it would be number
|
||||
*/
|
||||
[name: string]: {
|
||||
/**
|
||||
* The default ElasticsearchDataType that should be used, if no tag or only not implemented tags are found
|
||||
*/
|
||||
default: ElasticsearchDataType;
|
||||
|
||||
/**
|
||||
* The name of the tag, so for `@integer` it would be `integer`
|
||||
*/
|
||||
[name: string]: ElasticsearchDataType;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The representation of a `DynamicTemplate` in Elasticsearch
|
||||
*
|
||||
* https://www.elastic.co/guide/en/elasticsearch/reference/5.6/dynamic-templates.html
|
||||
*/
|
||||
export interface ElasticsearchDynamicTemplate {
|
||||
/**
|
||||
* The name of the dynamicTemplate
|
||||
*/
|
||||
[name: string]: {
|
||||
/**
|
||||
* The mapping of the template
|
||||
*/
|
||||
mapping: ElasticsearchValue;
|
||||
|
||||
/**
|
||||
* With automatic mapping, we use `path_match` more or less out of convenience and because it is least error-prone
|
||||
*
|
||||
* This also means that match should match all ("*") interface names (because we provide the exact path of the
|
||||
* interface)
|
||||
*/
|
||||
match: '*';
|
||||
|
||||
/**
|
||||
* With automatic mapping, we use `path_match` more or less out of convenience and because it is least error-prone
|
||||
*
|
||||
* This also means that match_mapping_type should match all ("*") names (because we provide the exact path of the
|
||||
* interface)
|
||||
*/
|
||||
match_mapping_type: '*';
|
||||
|
||||
/**
|
||||
* With automatic mapping, we use `path_match` more or less out of convenience and because it is least error-prone
|
||||
*/
|
||||
path_match: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface ElasticsearchFilterableMap {
|
||||
[name: string]: ElasticsearchDataType;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Fieldmap contains all tag names for fields and the corresponding fields
|
||||
*
|
||||
* The Fieldmap works in a similar fashion to the Typemap
|
||||
*/
|
||||
export interface ElasticsearchFieldmap {
|
||||
/**
|
||||
* The name of the tag, so for `@sortable` it would be `sortable`
|
||||
*/
|
||||
[name: string]: {
|
||||
/**
|
||||
* The default value if no parameter is provided
|
||||
*/
|
||||
default: {
|
||||
/**
|
||||
* To allow the usage of `prev.fields = {...prev.fields, ...fieldmap[tag.tagName].default}`
|
||||
*
|
||||
* We could also have used `default: any`, but this adds slightly more improved type-safety.
|
||||
*/
|
||||
[name: string]: any;
|
||||
};
|
||||
|
||||
/**
|
||||
* The tag parameters that will be ignored
|
||||
*
|
||||
* Some tag parameters might not be important for your implementation, so you can add their names here to not get
|
||||
* any errors. The `default` will be used in that case.
|
||||
*/
|
||||
ignore: string[];
|
||||
|
||||
/**
|
||||
* The parameters of the tag, so for `@sortable ducet` it would be `ducet`
|
||||
*/
|
||||
[name: string]: {
|
||||
/**
|
||||
* To allow the usage of `prev.fields = {...prev.fields, ...fieldmap[tag.tagName][tag.text.trim()]}`
|
||||
*
|
||||
* We could also have used `default: any`, but this adds slightly more improved type-safety.
|
||||
*/
|
||||
[name: string]: any;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* A primitive data type
|
||||
*
|
||||
* https://www.elastic.co/guide/en/elasticsearch/reference/5.6/mapping-types.html
|
||||
*/
|
||||
export interface ElasticsearchType {
|
||||
/**
|
||||
* Fields for a type
|
||||
*
|
||||
* The fields are optional, they are used for things like sorting, which is not needed for every single type.
|
||||
*/
|
||||
fields?: {
|
||||
[name: string]: any;
|
||||
};
|
||||
|
||||
/**
|
||||
* The type as an ElasticsearchDataType
|
||||
*/
|
||||
type: ElasticsearchDataType;
|
||||
}
|
||||
|
||||
/**
|
||||
* A GeoShape data type
|
||||
*
|
||||
* https://www.elastic.co/guide/en/elasticsearch/reference/5.6/geo-shape.html
|
||||
*/
|
||||
export interface ElasticsearchGeoShape {
|
||||
/**
|
||||
* Does not exist; here for TypeScript compiler
|
||||
*/
|
||||
fields?: undefined;
|
||||
|
||||
/**
|
||||
* This parameter may be used instead of tree_levels to set an appropriate value for the tree_levels parameter.
|
||||
*
|
||||
* The value specifies the desired precision and Elasticsearch will calculate the best tree_levels value to honor
|
||||
* this precision. The value should be a number followed by an optional distance unit. Valid distance units include:
|
||||
* in, inch, yd, yard, mi, miles, km, kilometers, m,meters, cm,centimeters, mm, millimeters.
|
||||
*/
|
||||
precision: string;
|
||||
|
||||
/**
|
||||
* Name of the PrefixTree implementation to be used: geohash for GeohashPrefixTree and quadtree for QuadPrefixTree.
|
||||
*/
|
||||
tree: 'quadtree' | 'geohash';
|
||||
|
||||
/**
|
||||
* The type of the object, obviously geo_shape
|
||||
*/
|
||||
type: ElasticsearchDataType.geo_shape;
|
||||
}
|
||||
|
||||
/**
|
||||
* An object data type
|
||||
*
|
||||
* https://www.elastic.co/guide/en/elasticsearch/reference/5.6/object.html
|
||||
*/
|
||||
export interface ElasticsearchObject {
|
||||
|
||||
/**
|
||||
* Only for the top type
|
||||
*/
|
||||
_source?: {
|
||||
/**
|
||||
* Fields that should be excluded in the _source field
|
||||
*/
|
||||
excludes: [
|
||||
'creation_date'
|
||||
];
|
||||
};
|
||||
|
||||
/**
|
||||
* Whether the creation date should be set automatically
|
||||
*/
|
||||
date_detection?: boolean;
|
||||
|
||||
/**
|
||||
* If the object is a dynamic
|
||||
*
|
||||
* https://www.elastic.co/guide/en/elasticsearch/reference/5.6/dynamic.html
|
||||
* The default should be `'strict'`
|
||||
*/
|
||||
dynamic: true | false | 'strict';
|
||||
|
||||
/**
|
||||
* dynamic_templates for an object
|
||||
*
|
||||
* https://www.elastic.co/guide/en/elasticsearch/reference/5.6/dynamic-templates.html
|
||||
* This is a more complex topic, before touching this you should really know what you are doing.
|
||||
*/
|
||||
dynamic_templates?: ElasticsearchDynamicTemplate[];
|
||||
|
||||
/**
|
||||
* Fields for a type
|
||||
*
|
||||
* The fields are optional, they are used for things like sorting, which is not needed for every single type.
|
||||
*/
|
||||
fields?: {
|
||||
[name: string]: any;
|
||||
};
|
||||
|
||||
/**
|
||||
* Any properties of the object
|
||||
*
|
||||
* https://www.elastic.co/guide/en/elasticsearch/reference/5.6/properties.html
|
||||
*/
|
||||
properties: {
|
||||
/**
|
||||
* Each property can be any Elasticsearch value
|
||||
*
|
||||
* https://www.elastic.co/guide/en/elasticsearch/reference/5.6/mapping-types.html
|
||||
*/
|
||||
[name: string]: ElasticsearchValue;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* A collection of Elasticsearch Templates
|
||||
*/
|
||||
export interface ElasticsearchTemplateCollection {
|
||||
[indexName: string]: ElasticsearchTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* An Elasticsearch template
|
||||
*
|
||||
* https://www.elastic.co/guide/en/elasticsearch/reference/5.6/mapping.html
|
||||
* This is what you pass to Elasticsearch
|
||||
*/
|
||||
export interface ElasticsearchTemplate {
|
||||
/**
|
||||
* This is a pre-defined structure you should use for your mapping
|
||||
*/
|
||||
mappings: {
|
||||
[typeName: string]: ElasticsearchObject;
|
||||
};
|
||||
|
||||
/**
|
||||
* The settings for Elasticsearch
|
||||
*/
|
||||
settings: ElasticsearchSettings;
|
||||
|
||||
/**
|
||||
* The name of the template, for referencing in Elasticsearch
|
||||
*/
|
||||
template: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* A representation of ElasticsearchSettings used in Mappings
|
||||
*/
|
||||
export interface ElasticsearchSettings {
|
||||
/**
|
||||
* The settings
|
||||
*/
|
||||
[name: string]: any;
|
||||
|
||||
/**
|
||||
* This is where any analyzers go
|
||||
*
|
||||
* https://www.elastic.co/guide/en/elasticsearch/reference/5.6/analysis-analyzers.html
|
||||
*/
|
||||
analysis: {
|
||||
[name: string]: any;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* A premap for a specific value in a ProjectReflection
|
||||
*
|
||||
* This is meant to be used for external types. To aid performance, you usually should not include external libs in the
|
||||
* ProjectReflection. This means that there is no way the generator can generate a mapping for it, so you can use the
|
||||
* premaps to map out a type manually.
|
||||
*/
|
||||
export interface ElasticsearchPremap {
|
||||
/**
|
||||
* The name of the type with the corresponding map
|
||||
*
|
||||
* So for `const a: B` the name would be `B`
|
||||
*/
|
||||
[name: string]: ElasticsearchValue;
|
||||
}
|
||||
50
packages/es-mapping-generator/test/aggregations.spec.ts
Normal file
50
packages/es-mapping-generator/test/aggregations.spec.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Logger} from '@openstapps/logger';
|
||||
import {readdirSync, statSync} from 'fs';
|
||||
import path from 'path';
|
||||
import {MapAggTest} from './mapping-model/MapAggTest';
|
||||
import {MapAggTestOptions} from './mapping-model/MapAggTestOptions';
|
||||
|
||||
describe('ES Aggregation Gen', async () => {
|
||||
const magAppInstance = new MapAggTest('aggregations');
|
||||
|
||||
/**
|
||||
* Expand a path to a list of all files deeply contained in it
|
||||
*/
|
||||
function expandPathToFilesSync(sourcePath: string, accept: (fileName: string) => boolean): string[] {
|
||||
const fullPath = path.resolve(sourcePath);
|
||||
const directory = statSync(fullPath);
|
||||
|
||||
return directory.isDirectory()
|
||||
? ([] as string[]).concat(...readdirSync(fullPath).map(fragment =>
|
||||
expandPathToFilesSync(path.resolve(sourcePath, fragment), accept),
|
||||
))
|
||||
: [fullPath].filter(accept);
|
||||
}
|
||||
|
||||
for (const file of expandPathToFilesSync('./test/mapping-model/aggregations/', file => file.endsWith('agg-test.ts'))) {
|
||||
try {
|
||||
const test = (await import(file))['testConfig'] as MapAggTestOptions;
|
||||
|
||||
it(test.testName, function () {
|
||||
magAppInstance.testInterfaceAgainstPath(test);
|
||||
});
|
||||
} catch (error) {
|
||||
await Logger.error('UNHANDLED REJECTION', error.stack);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
}).timeout(20_000).slow(10_000);
|
||||
135
packages/es-mapping-generator/test/mapping-model/MapAggTest.ts
Normal file
135
packages/es-mapping-generator/test/mapping-model/MapAggTest.ts
Normal file
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {ElasticsearchDataType} from '../../src/config/typemap';
|
||||
import {generateTemplate} from '../../src/mapping';
|
||||
import {resolve} from "path";
|
||||
import {expect} from "chai";
|
||||
import {ProjectReflection} from 'typedoc';
|
||||
import {getProjectReflection} from '../../src/project-reflection';
|
||||
import {AggregationSchema, ESNestedAggregation} from '../../src/types/aggregation';
|
||||
import {ElasticsearchTemplateCollection} from '../../src/types/mapping';
|
||||
import {MapAggTestOptions, MinimalMappingDescription} from './MapAggTestOptions';
|
||||
import {settings} from '../../src/config/settings';
|
||||
|
||||
export class MapAggTest {
|
||||
mapping_model_path!: string;
|
||||
reflection!: ProjectReflection;
|
||||
|
||||
constructor(dir: string) {
|
||||
this.mapping_model_path = resolve(__dirname, dir);
|
||||
this.reflection = getProjectReflection(this.mapping_model_path);
|
||||
}
|
||||
|
||||
testInterfaceAgainstPath(options: MapAggTestOptions) {
|
||||
const template = generateTemplate(this.reflection, options.ignoredTags ?? [], false, [options.name]);
|
||||
|
||||
if (typeof options.err !== 'undefined') {
|
||||
for (const error of template.errors) {
|
||||
expect(options.err).to.include(error, "Unexpected Error!")
|
||||
}
|
||||
} else {
|
||||
expect(template.errors).to.be.deep.equal([], 'Unexpected Error!');
|
||||
}
|
||||
|
||||
if (typeof options.agg !== 'undefined') {
|
||||
const expectedAggSchema = MapAggTest.buildAggregation(options.name, options.agg.fields, options.agg.globals)
|
||||
expect(template.aggregations).to.be.deep.equal(expectedAggSchema, 'Aggregation schema not equal!');
|
||||
}
|
||||
|
||||
if (typeof options.map !== 'undefined') {
|
||||
const expectedMappingSchema = MapAggTest.buildMapping(options.name, options.map);
|
||||
expect(template.mappings).to.be.deep.equal(expectedMappingSchema, 'Mapping schema not equal!');
|
||||
}
|
||||
}
|
||||
|
||||
static buildAggregation(name: string, fields?: string[], globals?: string[]): AggregationSchema {
|
||||
const out: AggregationSchema = {
|
||||
'@all': {
|
||||
aggs: {},
|
||||
filter: {
|
||||
match_all: {}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
for (const global of globals ?? []) {
|
||||
(out['@all']! as ESNestedAggregation).aggs[global] = {
|
||||
terms: {
|
||||
field: `${global}.raw`,
|
||||
size: 1000,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof fields === 'undefined' || fields.length === 0) {
|
||||
return out;
|
||||
}
|
||||
|
||||
out[name] = {
|
||||
aggs: {},
|
||||
filter: {
|
||||
type: {
|
||||
value: name,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const field of fields) {
|
||||
(out[name]! as ESNestedAggregation).aggs[field] = {
|
||||
terms: {
|
||||
field: `${field}.raw`,
|
||||
size: 1000,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
static buildMapping(name: string, map: MinimalMappingDescription): ElasticsearchTemplateCollection {
|
||||
let typeNameWithoutSpaces = name.toLowerCase();
|
||||
while (typeNameWithoutSpaces.includes(' ')) {
|
||||
typeNameWithoutSpaces = typeNameWithoutSpaces.replace(' ', '_');
|
||||
}
|
||||
|
||||
const out: ElasticsearchTemplateCollection = {};
|
||||
const templateName = `template_${typeNameWithoutSpaces}`;
|
||||
out[templateName] = {
|
||||
mappings: {},
|
||||
settings: settings,
|
||||
template: `stapps_${typeNameWithoutSpaces}*`,
|
||||
}
|
||||
const maps = map.maps ?? {};
|
||||
maps.type = {
|
||||
type: ElasticsearchDataType.text
|
||||
}
|
||||
maps.creation_date = {
|
||||
type: ElasticsearchDataType.date
|
||||
}
|
||||
out[templateName].mappings[name] = {
|
||||
_source: {
|
||||
excludes: [
|
||||
'creation_date'
|
||||
]
|
||||
},
|
||||
date_detection: false,
|
||||
dynamic: 'strict',
|
||||
properties: maps,
|
||||
dynamic_templates: map.dynamicTemplates ?? [],
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ElasticsearchDynamicTemplate, ElasticsearchValue} from '../../src/types/mapping';
|
||||
|
||||
export interface MapAggTestOptions {
|
||||
testName: string;
|
||||
name: string;
|
||||
agg?: {
|
||||
fields?: string[];
|
||||
globals?: string[];
|
||||
}
|
||||
map?: MinimalMappingDescription;
|
||||
err?: string[];
|
||||
ignoredTags?: string[];
|
||||
}
|
||||
|
||||
export interface MinimalMappingDescription {
|
||||
maps?: {
|
||||
[name: string]: ElasticsearchValue;
|
||||
};
|
||||
dynamicTemplates?: ElasticsearchDynamicTemplate[];
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface AggArray {
|
||||
/**
|
||||
* @aggregatable
|
||||
*/
|
||||
array: Foo[];
|
||||
|
||||
type: ThingType.AggArray;
|
||||
}
|
||||
type Foo = 'A' | 'B' | 'C';
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Aggregation tag should propagate on arrays',
|
||||
name: ThingType.AggArray,
|
||||
agg: {
|
||||
fields: ['array'],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface AggGlobalNested {
|
||||
nested: {
|
||||
/**
|
||||
* @aggregatable global
|
||||
*/
|
||||
foo: string;
|
||||
};
|
||||
|
||||
type: ThingType.AggGlobalNested;
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Global aggregations when nested',
|
||||
name: ThingType.AggGlobalNested,
|
||||
agg: {
|
||||
globals: ['foo'],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface AggGlobal {
|
||||
/**
|
||||
* @aggregatable global
|
||||
*/
|
||||
foo: string;
|
||||
|
||||
type: ThingType.AggGlobal;
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Global option should work',
|
||||
name: ThingType.AggGlobal,
|
||||
agg: {
|
||||
globals: ['foo'],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface AggInheritedGlobal extends Foo {
|
||||
type: ThingType.AggInheritedGlobal;
|
||||
}
|
||||
|
||||
|
||||
interface Foo {
|
||||
/**
|
||||
* @aggregatable global
|
||||
*/
|
||||
bar: string;
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Inherited global aggregations should work',
|
||||
name: ThingType.AggInheritedGlobal,
|
||||
agg: {
|
||||
globals: ['bar'],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface AggInherited extends Foo {
|
||||
/**
|
||||
* No tag here :)
|
||||
*/
|
||||
bar: 'some thing';
|
||||
|
||||
type: ThingType.AggInheritedOverwritten;
|
||||
}
|
||||
|
||||
|
||||
interface Foo {
|
||||
/**
|
||||
* @aggregatable
|
||||
*/
|
||||
bar: string;
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Inherited aggregations should work when overwritten',
|
||||
name: ThingType.AggInherited,
|
||||
agg: {
|
||||
fields: ['bar'],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface AggInherited extends Foo {
|
||||
type: ThingType.AggInherited;
|
||||
}
|
||||
|
||||
|
||||
interface Foo {
|
||||
/**
|
||||
* @aggregatable
|
||||
*/
|
||||
bar: string;
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Inherited aggregations should work',
|
||||
name: ThingType.AggInherited,
|
||||
agg: {
|
||||
fields: ['bar'],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface AggNested {
|
||||
nested: {
|
||||
/**
|
||||
* @aggregatable
|
||||
*/
|
||||
foo: string;
|
||||
};
|
||||
|
||||
type: ThingType.AggNested;
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Should work on nested properties',
|
||||
name: ThingType.AggNested,
|
||||
agg: {
|
||||
fields: ['nested.foo'],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
export enum ThingType {
|
||||
AggArray = 'agg array',
|
||||
AggGlobal = 'agg global',
|
||||
AggGlobalNested = 'agg global nested',
|
||||
AggNested = 'agg nested',
|
||||
AggInherited = 'agg inherited',
|
||||
AggInheritedGlobal = 'agg inherited global',
|
||||
AggInheritedOverwritten = 'agg inherited overwritten',
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "../../../node_modules/@openstapps/configuration/tsconfig.json"
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface AnyUnknown {
|
||||
foo: any;
|
||||
|
||||
bar: unknown;
|
||||
|
||||
type: ThingType.AnyUnknown
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Any or unknown should create a dynamic field',
|
||||
name: ThingType.AnyUnknown,
|
||||
map: {
|
||||
maps: {
|
||||
foo: {
|
||||
dynamic: true,
|
||||
properties: {}
|
||||
},
|
||||
bar: {
|
||||
dynamic: true,
|
||||
properties: {}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ElasticsearchDataType} from '../../../../src/config/typemap';
|
||||
|
||||
/**
|
||||
* @date
|
||||
*/
|
||||
export type SCISO8601Date = string
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface DateAndRange {
|
||||
/**
|
||||
* @date
|
||||
*/
|
||||
directDate: string;
|
||||
|
||||
dateAlias: SCISO8601Date;
|
||||
|
||||
type: ThingType.Date
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Dates and date ranges should have the correct type',
|
||||
name: ThingType.Date,
|
||||
map: {
|
||||
maps: {
|
||||
directDate: {
|
||||
type: ElasticsearchDataType.date,
|
||||
},
|
||||
dateAlias: {
|
||||
type: ElasticsearchDataType.date,
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ElasticsearchDataType} from '../../../../src/config/typemap';
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface DefaultGeneric {
|
||||
foo: InterfaceWithDefaultGeneric;
|
||||
|
||||
type: ThingType.DefaultGeneric;
|
||||
}
|
||||
|
||||
interface InterfaceWithDefaultGeneric<T = number> {
|
||||
bar: T;
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Default generics should fail',
|
||||
name: ThingType.DefaultGeneric,
|
||||
map: {
|
||||
maps: {
|
||||
foo: {
|
||||
dynamic: 'strict',
|
||||
properties: {
|
||||
bar: {
|
||||
type: ElasticsearchDataType.parse_error
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
err: [
|
||||
`At "${ThingType.DefaultGeneric}::foo.bar" for Generic "T": Missing reflection, please report!`
|
||||
]
|
||||
};
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ElasticsearchDataType} from '../../../../src/config/typemap';
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface DoubleTypeConflict {
|
||||
/**
|
||||
* @keyword
|
||||
* @text
|
||||
*/
|
||||
stringDoubleTypeConflict: string;
|
||||
|
||||
/**
|
||||
* @integer
|
||||
* @float
|
||||
*/
|
||||
numberDoubleTypeConflict: number;
|
||||
|
||||
type: ThingType.DoubleTypeConflict;
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Double type annotations should cause an error',
|
||||
name: ThingType.DoubleTypeConflict,
|
||||
map: {
|
||||
maps: {
|
||||
stringDoubleTypeConflict: {
|
||||
type: ElasticsearchDataType.type_conflict
|
||||
},
|
||||
numberDoubleTypeConflict: {
|
||||
type: ElasticsearchDataType.type_conflict
|
||||
}
|
||||
}
|
||||
},
|
||||
err: [
|
||||
`At "${ThingType.DoubleTypeConflict}::stringDoubleTypeConflict" for type "string": Type conflict; "keyword" would override "text"`,
|
||||
`At "${ThingType.DoubleTypeConflict}::numberDoubleTypeConflict" for type "number": Type conflict; "integer" would override "float"`
|
||||
]
|
||||
};
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ElasticsearchDataType} from '../../../../src/config/typemap';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface Enum {
|
||||
foo: Bar,
|
||||
|
||||
bar: Baz,
|
||||
|
||||
type: ThingType.Enum;
|
||||
}
|
||||
|
||||
enum Bar {
|
||||
a,
|
||||
b,
|
||||
c,
|
||||
}
|
||||
|
||||
enum Baz {
|
||||
d = 'd',
|
||||
e = 'e',
|
||||
f = 'f',
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
// Known issue: Enums only use text
|
||||
// https://gitlab.com/openstapps/core-tools/-/issues/46
|
||||
testName: 'Emums should work',
|
||||
name: ThingType.Enum,
|
||||
map: {
|
||||
maps: {
|
||||
foo: {
|
||||
type: ElasticsearchDataType.text
|
||||
},
|
||||
bar: {
|
||||
type: ElasticsearchDataType.text
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ElasticsearchDataType} from '../../../../src/config/typemap';
|
||||
|
||||
export type FilterableEnumType = 'a' | 'b' | 'c';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface FilterableTag {
|
||||
/**
|
||||
* @text
|
||||
* @filterable
|
||||
*/
|
||||
foo: string;
|
||||
|
||||
/**
|
||||
* @keyword
|
||||
* @filterable
|
||||
*/
|
||||
bar: string;
|
||||
|
||||
/**
|
||||
* @filterable
|
||||
*/
|
||||
baz: 'some literal'
|
||||
|
||||
/**
|
||||
* @filterable
|
||||
*/
|
||||
buz: FilterableEnumType
|
||||
|
||||
type: ThingType.FilterableTag
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Filterable tag should add raw field to strings',
|
||||
name: ThingType.FilterableTag,
|
||||
map: {
|
||||
maps: {
|
||||
foo: {
|
||||
type: ElasticsearchDataType.text,
|
||||
fields: {
|
||||
raw: {
|
||||
type: ElasticsearchDataType.keyword
|
||||
}
|
||||
}
|
||||
},
|
||||
bar: {
|
||||
type: ElasticsearchDataType.keyword,
|
||||
fields: {
|
||||
raw: {
|
||||
type: ElasticsearchDataType.keyword
|
||||
}
|
||||
}
|
||||
},
|
||||
baz: {
|
||||
type: ElasticsearchDataType.keyword,
|
||||
fields: {
|
||||
raw: {
|
||||
type: ElasticsearchDataType.keyword
|
||||
}
|
||||
}
|
||||
},
|
||||
buz: {
|
||||
type: ElasticsearchDataType.keyword,
|
||||
fields: {
|
||||
raw: {
|
||||
type: ElasticsearchDataType.keyword
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ElasticsearchDataType} from '../../../../src/config/typemap';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface Generics {
|
||||
foo: InterfaceWithDefaultGeneric<number>;
|
||||
baz: InterfaceWithStringGeneric<string>
|
||||
|
||||
type: ThingType.Generics;
|
||||
}
|
||||
|
||||
interface InterfaceWithDefaultGeneric<T = number> {
|
||||
bar: T;
|
||||
}
|
||||
|
||||
interface InterfaceWithStringGeneric<T> {
|
||||
bar: T;
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Generics should work',
|
||||
name: ThingType.Generics,
|
||||
map: {
|
||||
maps: {
|
||||
foo: {
|
||||
dynamic: 'strict',
|
||||
properties: {
|
||||
bar: {
|
||||
type: ElasticsearchDataType.integer
|
||||
}
|
||||
}
|
||||
},
|
||||
baz: {
|
||||
dynamic: 'strict',
|
||||
properties: {
|
||||
bar: {
|
||||
type: ElasticsearchDataType.text
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ElasticsearchDataType} from '../../../../src/config/typemap';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface ImpossibleUnion {
|
||||
foo: 'a' | 1 | boolean;
|
||||
|
||||
type: ThingType.ImpossibleUnion
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Impossible union should cause an error',
|
||||
name: ThingType.ImpossibleUnion,
|
||||
map: {
|
||||
maps: {
|
||||
foo: {
|
||||
type: ElasticsearchDataType.boolean
|
||||
}
|
||||
}
|
||||
},
|
||||
err: [
|
||||
`At "${ThingType.ImpossibleUnion}::foo" for type "[{"type":"1","name":"2"},"unknown","1"]": Not implemented type`
|
||||
]
|
||||
};
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ElasticsearchDataType} from '../../../../src/config/typemap';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface DoubleTypeConflict {
|
||||
/**
|
||||
* @keyword
|
||||
*/
|
||||
keywordNumber: number;
|
||||
|
||||
/**
|
||||
* @text
|
||||
*/
|
||||
textNumber: number;
|
||||
|
||||
/**
|
||||
* @integer
|
||||
*/
|
||||
integerString: string;
|
||||
|
||||
/**
|
||||
* @float
|
||||
*/
|
||||
floatString: string;
|
||||
|
||||
|
||||
type: ThingType.IncompatibleType;
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Incompatible type annotations should cause an error and use defaults',
|
||||
name: ThingType.IncompatibleType,
|
||||
map: {
|
||||
maps: {
|
||||
keywordNumber: {
|
||||
type: ElasticsearchDataType.integer
|
||||
},
|
||||
textNumber: {
|
||||
type: ElasticsearchDataType.integer
|
||||
},
|
||||
integerString: {
|
||||
type: ElasticsearchDataType.text
|
||||
},
|
||||
floatString: {
|
||||
type: ElasticsearchDataType.text
|
||||
}
|
||||
}
|
||||
},
|
||||
err: [
|
||||
`At "${ThingType.IncompatibleType}::keywordNumber" for tag "keyword": Not implemented tag`,
|
||||
`At "${ThingType.IncompatibleType}::textNumber" for tag "text": Not implemented tag`,
|
||||
`At "${ThingType.IncompatibleType}::floatString" for tag "float": Not implemented tag`,
|
||||
`At "${ThingType.IncompatibleType}::integerString" for tag "integer": Not implemented tag`,
|
||||
]
|
||||
};
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ElasticsearchDataType} from '../../../../src/config/typemap';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface IndexSignature {
|
||||
foo: {
|
||||
[key: string]: {
|
||||
bar: number;
|
||||
baz: string;
|
||||
}
|
||||
}
|
||||
|
||||
type: ThingType.IndexSignature;
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Index Signatures should work',
|
||||
name: ThingType.IndexSignature,
|
||||
map: {
|
||||
maps: {
|
||||
foo: {
|
||||
dynamic: true,
|
||||
properties: {}
|
||||
}
|
||||
},
|
||||
dynamicTemplates: [
|
||||
{
|
||||
__type: {
|
||||
mapping: {
|
||||
dynamic: 'strict',
|
||||
properties: {
|
||||
bar: {
|
||||
type: ElasticsearchDataType.integer
|
||||
},
|
||||
baz: {
|
||||
type: ElasticsearchDataType.text
|
||||
}
|
||||
}
|
||||
},
|
||||
match: '*',
|
||||
match_mapping_type: '*',
|
||||
path_match: 'foo.*'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ElasticsearchDataType} from '../../../../src/config/typemap';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ThingType} from './types';
|
||||
|
||||
/**
|
||||
* @date
|
||||
*/
|
||||
export type SCISO8601Date = string;
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface InferredTypeFilterable {
|
||||
/**
|
||||
* @filterable
|
||||
*/
|
||||
foo: SCISO8601Date;
|
||||
|
||||
/**
|
||||
* // no tag
|
||||
*/
|
||||
bar: SCISO8601Date;
|
||||
|
||||
type: ThingType.InferredTypeFilterable
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'filterable tags should not override inferred tags',
|
||||
name: ThingType.InferredTypeFilterable,
|
||||
map: {
|
||||
maps: {
|
||||
foo: {
|
||||
type: ElasticsearchDataType.date,
|
||||
fields: {
|
||||
raw: {
|
||||
type: ElasticsearchDataType.keyword,
|
||||
}
|
||||
}
|
||||
},
|
||||
bar: {
|
||||
type: ElasticsearchDataType.date,
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ElasticsearchDataType} from '../../../../src/config/typemap';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ThingType} from './types';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface InheritTags {
|
||||
/**
|
||||
* @inheritTags inherit tags::bar.baz
|
||||
*/
|
||||
foo: number,
|
||||
|
||||
bar: {
|
||||
/**
|
||||
* @float
|
||||
*/
|
||||
baz: number
|
||||
}
|
||||
|
||||
type: ThingType.InheritTags;
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Inherit tags tag should work',
|
||||
name: ThingType.InheritTags,
|
||||
map: {
|
||||
maps: {
|
||||
foo: {
|
||||
type: ElasticsearchDataType.float
|
||||
},
|
||||
bar: {
|
||||
dynamic: 'strict',
|
||||
properties: {
|
||||
baz: {
|
||||
type: ElasticsearchDataType.float
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ElasticsearchDataType} from '../../../../src/config/typemap';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface InheritedProperty extends Bar{
|
||||
foo: number,
|
||||
|
||||
type: ThingType.InheritedProperty;
|
||||
}
|
||||
|
||||
interface Bar {
|
||||
/**
|
||||
* @keyword
|
||||
*/
|
||||
bar: string;
|
||||
|
||||
/**
|
||||
* @float
|
||||
*/
|
||||
baz: number;
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Inherited properties should inherit tags',
|
||||
name: ThingType.InheritedProperty,
|
||||
map: {
|
||||
maps: {
|
||||
foo: {
|
||||
type: ElasticsearchDataType.integer
|
||||
},
|
||||
bar: {
|
||||
type: ElasticsearchDataType.keyword
|
||||
},
|
||||
baz: {
|
||||
type: ElasticsearchDataType.float
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ElasticsearchDataType} from '../../../../src/config/typemap';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface InvalidTag {
|
||||
/**
|
||||
* @anInvalidTag
|
||||
*/
|
||||
foo: string;
|
||||
|
||||
type: ThingType.InvalidTag;
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Invalid tags should cause an error',
|
||||
name: ThingType.InvalidTag,
|
||||
map: {
|
||||
maps: {
|
||||
foo: {
|
||||
type: ElasticsearchDataType.text
|
||||
}
|
||||
}
|
||||
},
|
||||
err: [
|
||||
`At "${ThingType.InvalidTag}::foo" for tag "aninvalidtag": Not implemented tag`
|
||||
]
|
||||
};
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ElasticsearchDataType} from '../../../../src/config/typemap';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface MapExplicitTypes {
|
||||
/**
|
||||
* @integer
|
||||
*/
|
||||
esInteger: number;
|
||||
|
||||
/**
|
||||
* @float
|
||||
*/
|
||||
esFloat: number;
|
||||
|
||||
/**
|
||||
* @keyword
|
||||
*/
|
||||
esKeyword: string;
|
||||
|
||||
/**
|
||||
* @text
|
||||
*/
|
||||
esText: string;
|
||||
|
||||
/**
|
||||
* @date
|
||||
*/
|
||||
esEpochMsDate: number
|
||||
|
||||
/**
|
||||
* @date
|
||||
*/
|
||||
esStringDate: string
|
||||
|
||||
type: ThingType.MapExplicitTypes;
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Explicit type annotations should work',
|
||||
name: ThingType.MapExplicitTypes,
|
||||
map: {
|
||||
maps: {
|
||||
esInteger: {
|
||||
type: ElasticsearchDataType.integer
|
||||
},
|
||||
esFloat: {
|
||||
type: ElasticsearchDataType.float
|
||||
},
|
||||
esKeyword: {
|
||||
type: ElasticsearchDataType.keyword
|
||||
},
|
||||
esText: {
|
||||
type: ElasticsearchDataType.text
|
||||
},
|
||||
esEpochMsDate: {
|
||||
type: ElasticsearchDataType.date
|
||||
},
|
||||
esStringDate: {
|
||||
type: ElasticsearchDataType.date
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ElasticsearchDataType} from '../../../../src/config/typemap';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface MissingPremap {
|
||||
// it really doesn't matter what we use here, as long as it is an external dependency
|
||||
// if you get an error here because you removed a dependency, feel free to change it around
|
||||
// to your heart's content
|
||||
foo: HTMLAllCollection;
|
||||
|
||||
type: ThingType.MissingPremap;
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Missing premap should cause an error',
|
||||
name: ThingType.MissingPremap,
|
||||
map: {
|
||||
maps: {
|
||||
foo: {
|
||||
type: ElasticsearchDataType.missing_premap
|
||||
}
|
||||
}
|
||||
},
|
||||
err: [
|
||||
`At "${ThingType.MissingPremap}::foo" for external type "HTMLAllCollection": Missing pre-map`
|
||||
]
|
||||
};
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ElasticsearchDataType} from '../../../../src/config/typemap';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface Nested {
|
||||
foo: {
|
||||
depth1_1: {
|
||||
depth2_1: {
|
||||
depth3_1: number;
|
||||
/**
|
||||
* @keyword
|
||||
*/
|
||||
depth3_2: string;
|
||||
}
|
||||
depth2_2: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
type: ThingType.Nested;
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Nested properties should work',
|
||||
name: ThingType.Nested,
|
||||
map: {
|
||||
maps: {
|
||||
foo: {
|
||||
dynamic: 'strict',
|
||||
properties: {
|
||||
depth1_1: {
|
||||
dynamic: 'strict',
|
||||
properties: {
|
||||
depth2_1: {
|
||||
dynamic: 'strict',
|
||||
properties: {
|
||||
depth3_1: {
|
||||
type: ElasticsearchDataType.integer
|
||||
},
|
||||
depth3_2: {
|
||||
type: ElasticsearchDataType.keyword
|
||||
}
|
||||
}
|
||||
},
|
||||
depth2_2: {
|
||||
type: ElasticsearchDataType.boolean
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ElasticsearchDataType} from '../../../../src/config/typemap';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface ObjectUnion {
|
||||
foo: Boo | Buu;
|
||||
|
||||
type: ThingType.ObjectUnion
|
||||
}
|
||||
|
||||
// we can't name them Bar or Baz, look here for more info:
|
||||
// https://gitlab.com/openstapps/core-tools/-/issues/48
|
||||
// or here
|
||||
// https://github.com/TypeStrong/typedoc/issues/1373
|
||||
interface Boo {
|
||||
a: boolean;
|
||||
intersection: string;
|
||||
}
|
||||
|
||||
interface Buu {
|
||||
b: number;
|
||||
intersection: string;
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Object union types should work',
|
||||
name: ThingType.ObjectUnion,
|
||||
map: {
|
||||
maps: {
|
||||
foo: {
|
||||
dynamic: 'strict',
|
||||
properties: {
|
||||
a: {
|
||||
type: ElasticsearchDataType.boolean
|
||||
},
|
||||
b: {
|
||||
type: ElasticsearchDataType.integer
|
||||
},
|
||||
intersection: {
|
||||
type: ElasticsearchDataType.text
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ElasticsearchDataType} from '../../../../src/config/typemap';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface PairedTags {
|
||||
/**
|
||||
* @keyword
|
||||
* @filterable
|
||||
*/
|
||||
foo: string;
|
||||
|
||||
/**
|
||||
* @text
|
||||
* @filterable
|
||||
* @sortable
|
||||
*/
|
||||
bar: string;
|
||||
|
||||
type: ThingType.PairedTags;
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Tags should be able to be paired',
|
||||
name: ThingType.PairedTags,
|
||||
map: {
|
||||
maps: {
|
||||
foo: {
|
||||
type: ElasticsearchDataType.keyword,
|
||||
fields: {
|
||||
raw: {
|
||||
type: ElasticsearchDataType.keyword
|
||||
}
|
||||
}
|
||||
},
|
||||
bar: {
|
||||
type: ElasticsearchDataType.text,
|
||||
fields: {
|
||||
raw: {
|
||||
type: ElasticsearchDataType.keyword
|
||||
},
|
||||
sort: {
|
||||
analyzer: 'ducet_sort',
|
||||
fielddata: true,
|
||||
type: ElasticsearchDataType.text
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ElasticsearchDataType} from '../../../../src/config/typemap';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface SensibleDefaults {
|
||||
numberDefault: number;
|
||||
stringDefault: string;
|
||||
booleanDefault: boolean;
|
||||
stringLiteralDefault: 'Hey there!';
|
||||
booleanTrueLiteralDefault: true;
|
||||
booleanFalseLiteralDefault: false;
|
||||
|
||||
type: ThingType.SensibleDefaultType;
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Primitive types should have sensible defaults',
|
||||
name: ThingType.SensibleDefaultType,
|
||||
map: {
|
||||
maps: {
|
||||
numberDefault: {
|
||||
type: ElasticsearchDataType.integer
|
||||
},
|
||||
stringDefault: {
|
||||
type: ElasticsearchDataType.text
|
||||
},
|
||||
booleanDefault: {
|
||||
type: ElasticsearchDataType.boolean
|
||||
},
|
||||
stringLiteralDefault: {
|
||||
type: ElasticsearchDataType.keyword
|
||||
},
|
||||
booleanTrueLiteralDefault: {
|
||||
type: ElasticsearchDataType.boolean
|
||||
},
|
||||
booleanFalseLiteralDefault: {
|
||||
type: ElasticsearchDataType.boolean
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ElasticsearchDataType} from '../../../../src/config/typemap';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface SortableTag {
|
||||
/**
|
||||
* @sortable
|
||||
*/
|
||||
foo: string;
|
||||
|
||||
/**
|
||||
* @sortable ducet
|
||||
*/
|
||||
bar: string;
|
||||
|
||||
/**
|
||||
* @sortable
|
||||
*/
|
||||
baz: number;
|
||||
|
||||
type: ThingType.SortableTag
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Sortable tag should work',
|
||||
name: ThingType.SortableTag,
|
||||
map: {
|
||||
maps: {
|
||||
foo: {
|
||||
type: ElasticsearchDataType.text,
|
||||
fields: {
|
||||
sort: {
|
||||
analyzer: 'ducet_sort',
|
||||
fielddata: true,
|
||||
type: 'text'
|
||||
}
|
||||
}
|
||||
},
|
||||
bar: {
|
||||
type: ElasticsearchDataType.text,
|
||||
fields: {
|
||||
sort: {
|
||||
analyzer: 'ducet_sort',
|
||||
fielddata: true,
|
||||
type: 'text'
|
||||
}
|
||||
}
|
||||
},
|
||||
baz: {
|
||||
type: ElasticsearchDataType.integer,
|
||||
fields: {
|
||||
sort: {
|
||||
analyzer: 'ducet_sort',
|
||||
fielddata: true,
|
||||
type: 'text'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ElasticsearchDataType} from '../../../../src/config/typemap';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface TagsIgnoreCase {
|
||||
/**
|
||||
* @inheritTags inherit tags::bar.baz
|
||||
*/
|
||||
camelCase: number,
|
||||
|
||||
/**
|
||||
* @inherittags inherit tags::bar.baz
|
||||
*/
|
||||
lowerCase: number,
|
||||
|
||||
bar: {
|
||||
/**
|
||||
* @float
|
||||
*/
|
||||
baz: number
|
||||
}
|
||||
|
||||
type: ThingType.TagsIgnoreCase;
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Tags should ignore case',
|
||||
name: ThingType.TagsIgnoreCase,
|
||||
map: {
|
||||
maps: {
|
||||
camelCase: {
|
||||
type: ElasticsearchDataType.float
|
||||
},
|
||||
lowerCase: {
|
||||
type: ElasticsearchDataType.float
|
||||
},
|
||||
bar: {
|
||||
dynamic: 'strict',
|
||||
properties: {
|
||||
baz: {
|
||||
type: ElasticsearchDataType.float
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ElasticsearchDataType} from '../../../../src/config/typemap';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface TypeAlias {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
textProperty: ATextAlias,
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
keywordProperty: AKeywordAlias,
|
||||
|
||||
/**
|
||||
* @keyword
|
||||
*/
|
||||
overriddenTextAsKeyword: ATextAlias
|
||||
|
||||
type: ThingType.TypeAlias;
|
||||
}
|
||||
|
||||
/**
|
||||
* @text
|
||||
*/
|
||||
type ATextAlias = string;
|
||||
|
||||
/**
|
||||
* @keyword
|
||||
*/
|
||||
type AKeywordAlias = string;
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Type alias annotations should work',
|
||||
name: ThingType.TypeAlias,
|
||||
map: {
|
||||
maps: {
|
||||
textProperty: {
|
||||
type: ElasticsearchDataType.text,
|
||||
},
|
||||
keywordProperty: {
|
||||
type: ElasticsearchDataType.keyword,
|
||||
},
|
||||
overriddenTextAsKeyword: {
|
||||
type: ElasticsearchDataType.keyword,
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 2021 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ElasticsearchDataType} from '../../../../src/config/typemap';
|
||||
|
||||
export interface SCISO8601DateRange {
|
||||
bar: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface TypeOverrides {
|
||||
foo: SCISO8601DateRange;
|
||||
|
||||
type: ThingType.TypeOverrides
|
||||
}
|
||||
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Premaps should support non-external types',
|
||||
name: ThingType.TypeOverrides,
|
||||
map: {
|
||||
maps: {
|
||||
foo: {
|
||||
type: ElasticsearchDataType.date_range,
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ElasticsearchDataType} from '../../../../src/config/typemap';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface TypeQuery {
|
||||
foo: typeof Bar;
|
||||
|
||||
type: ThingType.TypeQuery;
|
||||
}
|
||||
|
||||
enum Bar {
|
||||
'a',
|
||||
'b',
|
||||
'c'
|
||||
}
|
||||
|
||||
// https://gitlab.com/openstapps/core-tools/-/issues/47
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Type queries should work',
|
||||
name: ThingType.TypeQuery,
|
||||
map: {
|
||||
maps: {
|
||||
foo: {
|
||||
type: ElasticsearchDataType.text
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ElasticsearchDataType} from '../../../../src/config/typemap';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface TypeWrapperInheritance {
|
||||
/**
|
||||
* @float
|
||||
*/
|
||||
numberWrapper: NumberWrapper;
|
||||
|
||||
/**
|
||||
* @keyword
|
||||
*/
|
||||
stringWrapper: StringWrapper;
|
||||
|
||||
/**
|
||||
* @text
|
||||
*/
|
||||
stringLiteralWrapper: StringLiteralWrapper;
|
||||
|
||||
type: ThingType.TypeWrapperInheritance
|
||||
}
|
||||
|
||||
type NumberWrapper = number;
|
||||
type StringWrapper = string;
|
||||
type StringLiteralWrapper = 'foo';
|
||||
|
||||
// https://gitlab.com/openstapps/core-tools/-/merge_requests/29
|
||||
export const testConfig: MapAggTestOptions = {
|
||||
testName: 'Wrapper types should inherit tags',
|
||||
name: ThingType.TypeWrapperInheritance,
|
||||
map: {
|
||||
maps: {
|
||||
foo: {
|
||||
dynamic: 'strict',
|
||||
properties: {
|
||||
numberWrapper: {
|
||||
type: ElasticsearchDataType.float
|
||||
},
|
||||
stringWrapper: {
|
||||
type: ElasticsearchDataType.keyword
|
||||
},
|
||||
stringLiteralWrapper: {
|
||||
type: ElasticsearchDataType.text
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
export enum ThingType {
|
||||
MapExplicitTypes = 'map explicit types',
|
||||
DoubleTypeConflict = 'double type conflict',
|
||||
IncompatibleType = 'incompatible type',
|
||||
SensibleDefaultType = 'sensible default',
|
||||
InvalidTag = 'invalid tag',
|
||||
MissingPremap = 'missing premap',
|
||||
DefaultGeneric = 'default generic',
|
||||
Generics = 'generics',
|
||||
Nested = 'nested',
|
||||
IndexSignature = 'index signature',
|
||||
ImpossibleUnion = 'impossible union',
|
||||
TypeQuery = 'type query',
|
||||
ObjectUnion = 'object union',
|
||||
TypeWrapperInheritance = 'type wrapper inheritance',
|
||||
SortableTag = 'sortable tag',
|
||||
Enum = 'enum',
|
||||
InheritedProperty = 'inherited property',
|
||||
PairedTags = 'paired tags',
|
||||
FilterableTag = 'filterable tag',
|
||||
AnyUnknown = 'any unknown',
|
||||
InferredTypeFilterable = 'inferred type filterable',
|
||||
Date = 'date',
|
||||
InheritTags = 'inherit tags',
|
||||
TagsIgnoreCase = 'tags ignore case',
|
||||
TypeAlias = 'type alias',
|
||||
TypeOverrides = 'type overrides',
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "../../../node_modules/@openstapps/configuration/tsconfig.json"
|
||||
}
|
||||
50
packages/es-mapping-generator/test/mapping.spec.ts
Normal file
50
packages/es-mapping-generator/test/mapping.spec.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Logger} from '@openstapps/logger';
|
||||
import {readdirSync, statSync} from 'fs';
|
||||
import path from 'path';
|
||||
import {MapAggTest} from './mapping-model/MapAggTest';
|
||||
import {MapAggTestOptions} from './mapping-model/MapAggTestOptions';
|
||||
|
||||
describe('ES Mapping Gen', async () => {
|
||||
const magAppInstance = new MapAggTest('mappings');
|
||||
|
||||
/**
|
||||
* Expand a path to a list of all files deeply contained in it
|
||||
*/
|
||||
function expandPathToFilesSync(sourcePath: string, accept: (fileName: string) => boolean): string[] {
|
||||
const fullPath = path.resolve(sourcePath);
|
||||
const directory = statSync(fullPath);
|
||||
|
||||
return directory.isDirectory()
|
||||
? ([] as string[]).concat(...readdirSync(fullPath).map(fragment =>
|
||||
expandPathToFilesSync(path.resolve(sourcePath, fragment), accept),
|
||||
))
|
||||
: [fullPath].filter(accept);
|
||||
}
|
||||
|
||||
for (const file of expandPathToFilesSync('./test/mapping-model/mappings/', file => file.endsWith('mapping-test.ts'))) {
|
||||
try {
|
||||
const test = (await import(file))['testConfig'] as MapAggTestOptions;
|
||||
|
||||
it(test.testName, function () {
|
||||
magAppInstance.testInterfaceAgainstPath(test)
|
||||
})
|
||||
} catch (error) {
|
||||
await Logger.error('UNHANDLED REJECTION', error.stack);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
}).timeout(20_000).slow(10_000);
|
||||
26
packages/es-mapping-generator/tsconfig.json
Normal file
26
packages/es-mapping-generator/tsconfig.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"alwaysStrict": true,
|
||||
"charset": "utf8",
|
||||
"declaration": true,
|
||||
"esModuleInterop": true,
|
||||
"experimentalDecorators": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"inlineSourceMap": true,
|
||||
"module": "CommonJS",
|
||||
"moduleResolution": "node",
|
||||
"noErrorTruncation": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noImplicitAny": true,
|
||||
"noImplicitReturns": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"outDir": "./lib/",
|
||||
"strict": true,
|
||||
"target": "es6"
|
||||
},
|
||||
"exclude": [
|
||||
"./lib/",
|
||||
"./test/"
|
||||
]
|
||||
}
|
||||
143
packages/es-mapping-generator/tslint.json
Normal file
143
packages/es-mapping-generator/tslint.json
Normal file
@@ -0,0 +1,143 @@
|
||||
{
|
||||
"defaultSeverity": "error",
|
||||
"extends": [
|
||||
"tslint:recommended",
|
||||
"tslint-eslint-rules"
|
||||
],
|
||||
"rules": {
|
||||
"array-type": [
|
||||
true,
|
||||
"array-simple"
|
||||
],
|
||||
"arrow-return-shorthand": true,
|
||||
"await-promise": true,
|
||||
"ban-comma-operator": true,
|
||||
"ban-ts-ignore": true,
|
||||
"completed-docs": true,
|
||||
"curly": true,
|
||||
"encoding": true,
|
||||
"file-header": true,
|
||||
"file-name-casing": [
|
||||
true,
|
||||
"kebab-case"
|
||||
],
|
||||
"forin": true,
|
||||
"indent": [
|
||||
true,
|
||||
"spaces",
|
||||
2
|
||||
],
|
||||
"interface-name": [
|
||||
true,
|
||||
"never-prefix"
|
||||
],
|
||||
"linebreak-style": [
|
||||
true,
|
||||
"LF"
|
||||
],
|
||||
"max-classes-per-file": false,
|
||||
"member-access": false,
|
||||
"member-ordering": [
|
||||
true,
|
||||
{
|
||||
"alphabetize": true,
|
||||
"order": [
|
||||
"private-static-field",
|
||||
"protected-static-field",
|
||||
"public-static-field",
|
||||
"private-instance-field",
|
||||
"protected-instance-field",
|
||||
"public-instance-field",
|
||||
"private-static-method",
|
||||
"protected-static-method",
|
||||
"public-static-method",
|
||||
"constructor",
|
||||
"private-instance-method",
|
||||
"protected-instance-method",
|
||||
"public-instance-method"
|
||||
]
|
||||
}
|
||||
],
|
||||
"newline-before-return": true,
|
||||
"newline-per-chained-call": true,
|
||||
"no-angle-bracket-type-assertion": true,
|
||||
"no-any": true,
|
||||
"no-boolean-literal-compare": true,
|
||||
"no-conditional-assignment": true,
|
||||
"no-construct": true,
|
||||
"no-default-export": true,
|
||||
"no-default-import": true,
|
||||
"no-duplicate-super": true,
|
||||
"no-floating-promises": true,
|
||||
"no-implicit-dependencies": true,
|
||||
"no-inferrable-types": true,
|
||||
"no-magic-numbers": true,
|
||||
"no-parameter-reassignment": true,
|
||||
"no-redundant-jsdoc": true,
|
||||
"no-reference": true,
|
||||
"no-return-await": true,
|
||||
"no-shadowed-variable": true,
|
||||
"no-sparse-arrays": true,
|
||||
"no-string-throw": true,
|
||||
"no-trailing-whitespace": [
|
||||
true,
|
||||
"ignore-comments",
|
||||
"ignore-jsdoc"
|
||||
],
|
||||
"object-curly-spacing": [
|
||||
true,
|
||||
"never"
|
||||
],
|
||||
"object-literal-key-quotes": false,
|
||||
"object-literal-shorthand": false,
|
||||
"one-variable-per-declaration": true,
|
||||
"ordered-imports": [
|
||||
true,
|
||||
{
|
||||
"import-sources-order": "case-insensitive",
|
||||
"named-imports-order": "case-insensitive"
|
||||
}
|
||||
],
|
||||
"prefer-const": true,
|
||||
"prefer-for-of": true,
|
||||
"prefer-function-over-method": true,
|
||||
"prefer-object-spread": true,
|
||||
"prefer-readonly": true,
|
||||
"prefer-template": true,
|
||||
"promise-function-async": true,
|
||||
"quotemark": [
|
||||
true,
|
||||
"single",
|
||||
"avoid-escape"
|
||||
],
|
||||
"semicolon": true,
|
||||
"static-this": true,
|
||||
"strict-boolean-expressions": true,
|
||||
"trailing-comma": [
|
||||
true,
|
||||
{
|
||||
"multiline": "always",
|
||||
"singleline": "never"
|
||||
}
|
||||
],
|
||||
"type-literal-delimiter": [
|
||||
true,
|
||||
{
|
||||
"singleLine": "always"
|
||||
}
|
||||
],
|
||||
"unnecessary-bind": true,
|
||||
"unnecessary-else": true,
|
||||
"variable-name": [
|
||||
true,
|
||||
"ban-keywords",
|
||||
"check-format",
|
||||
"allow-leading-underscore"
|
||||
]
|
||||
},
|
||||
"linterOptions": {
|
||||
"exclude": [
|
||||
"../../../test/**"
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user