feat: update tests

feat: update tests

feat: update tests
This commit is contained in:
2023-05-30 16:12:00 +02:00
parent d6d4f6e5c4
commit 0d60b8bfad
87 changed files with 1021 additions and 823 deletions

67
.syncpackrc.cjs Normal file
View File

@@ -0,0 +1,67 @@
// @ts-check
/** @type {import('syncpack').RcFile} */
const config = {
semverRange: '',
source: ['package.json', '**/package.json'],
indent: ' ',
sortFirst: [
'name',
'description',
'version',
'type',
'license',
'repository',
'author',
'contributors',
'keywords',
'main',
'types',
'bin',
'scripts',
'dependencies',
'devDependencies',
'peerDependencies',
'tsup',
'prettier',
'eslintConfig',
'eslintIgnore',
'nyc',
],
versionGroups: [
{
label: 'ES Mapping Generator Special Dependencies',
dependencies: ['typescript', 'typedoc', 'ts-node', '@types/node', 'got'],
packages: ['@openstapps/es-mapping-generator'],
isIgnored: true,
},
/*{
label: 'App Special Dependencies',
dependencies: ['typescript'],
packages: ['@openstapps/app'],
isIgnored: true,
},*/
{
label: 'Should have the same version',
dependencies: ['**'],
dependencyTypes: ['workspace'],
packages: ['**'],
pinVersion: '2.1.0',
},
{
label: 'Packages should use workspace version',
dependencies: ['@openstapps/**'],
dependencyTypes: ['prod', 'dev'],
packages: ['**'],
pinVersion: 'workspace:*',
},
{
label: 'Packages should be synced to app',
dependencies: ['typescript', 'ts-node'],
packages: ['**'],
snapTo: ['@openstapps/app'],
},
],
};
module.exports = config;

View File

@@ -1,97 +0,0 @@
{
"semverRange": "",
"source": [
"package.json",
"**/package.json"
],
"indent": " ",
"sortFirst": [
"name",
"description",
"version",
"type",
"license",
"repository",
"author",
"contributors",
"keywords",
"main",
"types",
"bin",
"scripts",
"dependencies",
"devDependencies",
"peerDependencies",
"tsup",
"prettier",
"eslintConfig",
"eslintIgnore",
"nyc"
],
"versionGroups": [
{
"label": "ES Mapping Generator Special Dependencies",
"dependencies": [
"typescript",
"typedoc",
"ts-node",
"@types/node",
"got"
],
"packages": [
"@openstapps/es-mapping-generator"
],
"isIgnored": true
},
{
"label": "App Special Dependencies",
"dependencies": [
"typescript"
],
"packages": [
"@openstapps/app"
],
"isIgnored": true
},
{
"label": "Should have the same version",
"dependencies": [
"**"
],
"dependencyTypes": [
"workspace"
],
"packages": [
"**"
],
"pinVersion": "2.1.0"
},
{
"label": "Packages should use workspace version",
"dependencies": [
"@openstapps/**"
],
"dependencyTypes": [
"prod",
"dev"
],
"packages": [
"**"
],
"pinVersion": "workspace:*"
},
{
"label": "Packages should be synced to app",
"dependencies": [
"typescript",
"ts-node"
],
"packages": [
"**"
],
"snapTo": [
"@openstapps/app"
]
}
]
}

View File

@@ -10,4 +10,4 @@ RUN npm ci && npm run build
EXPOSE 3000
CMD ["node", "./lib/cli"]
CMD ["node", "app"]

View File

@@ -28,7 +28,7 @@
"start:debug": "cross-env STAPPS_LOG_LEVEL=31 NODE_CONFIG_ENV=elasticsearch ALLOW_NO_TRANSPORT=true node app.js",
"test": "cross-env NODE_CONFIG_ENV=elasticsearch ALLOW_NO_TRANSPORT=true STAPPS_LOG_LEVEL=0 c8 mocha",
"test:integration": "docker-compose -f integration-test.yml pull && docker-compose -f integration-test.yml up --build --abort-on-container-exit --exit-code-from apicli",
"test:unit": "cross-env NODE_CONFIG_ENV=elasticsearch ALLOW_NO_TRANSPORT=true STAPPS_LOG_LEVEL=0 nyc mocha --require ts-node/register --exit 'test/**/*.spec.ts'"
"test:unit": "cross-env NODE_CONFIG_ENV=elasticsearch ALLOW_NO_TRANSPORT=true STAPPS_LOG_LEVEL=0 c8 mocha"
},
"dependencies": {
"@elastic/elasticsearch": "8.4.0",
@@ -36,15 +36,15 @@
"@openstapps/core-tools": "workspace:*",
"@openstapps/logger": "workspace:*",
"body-parser": "1.20.2",
"cosmiconfig": "8.1.3",
"cors": "2.8.5",
"cosmiconfig": "8.1.3",
"express": "4.18.2",
"express-prom-bundle": "6.6.0",
"express-promise-router": "4.1.1",
"got": "12.6.0",
"moment": "2.29.4",
"morgan": "1.10.0",
"nock": "13.3.0",
"nock": "13.3.1",
"node-cache": "5.1.2",
"node-cron": "3.0.2",
"nodemailer": "6.9.1",
@@ -61,7 +61,7 @@
"@openstapps/tsconfig": "workspace:*",
"@testdeck/mocha": "0.3.3",
"@types/body-parser": "1.19.2",
"@types/chai": "4.3.4",
"@types/chai": "4.3.5",
"@types/chai-as-promised": "7.1.5",
"@types/config": "3.3.0",
"@types/cors": "2.8.13",
@@ -77,21 +77,21 @@
"@types/sinon-express-mock": "1.3.9",
"@types/supertest": "2.0.12",
"@types/uuid": "8.3.4",
"c8": "7.13.0",
"chai": "4.3.7",
"chai-as-promised": "7.1.1",
"cross-env": "7.0.3",
"conventional-changelog-cli": "2.2.2",
"cross-env": "7.0.3",
"esmock": "2.2.3",
"get-port": "5.1.1",
"mocha": "10.2.0",
"mocked-env": "1.3.5",
"c8": "7.13.0",
"redoc-cli": "0.13.20",
"sinon": "15.0.4",
"sinon-express-mock": "2.2.1",
"supertest": "6.3.3",
"tsup": "6.7.0",
"typedoc": "0.23.28",
"typescript": "4.8.4"
"typescript": "4.6.4"
},
"tsup": {
"entry": [

View File

@@ -39,6 +39,7 @@ import {virtualPluginRoute} from './routes/virtual-plugin-route.js';
import {BulkStorage} from './storage/bulk-storage.js';
import {DatabaseConstructor} from './storage/database.js';
import {backendConfig} from './config.js';
import {fileURLToPath} from 'url';
/**
* Configure the backend
@@ -143,9 +144,9 @@ export async function configureApp(app: Express, databases: {[name: string]: Dat
});
// validate config file
const directory = path.dirname(fileURLToPath(import.meta.url));
await validator.addSchemas(
// eslint-disable-next-line unicorn/prefer-module
path.join(path.dirname(require.resolve('@openstapps/core/package.json')), 'lib', 'schema'),
path.join(directory, '..', 'node_modules', '@openstapps', 'core', 'lib', 'schema'),
);
// validate the config file

View File

@@ -49,7 +49,7 @@ export async function virtualPluginRoute(request: Request, plugin: SCPluginMetaD
// noinspection ExceptionCaughtLocallyJS
throw new SCValidationErrorResponse(responseValidation.errors, isTestEnvironment);
}
return response;
return responseBody as object;
} catch (error) {
// wrap exact error inside of the internal server error response
throw new SCInternalServerErrorResponse(error, isTestEnvironment);

View File

@@ -150,3 +150,6 @@ export async function setUp(
Logger.log(`Scheduled ${monitoringConfig.watchers.length} watches`);
}
// do this for esm mocking
export default {setUp};

View File

@@ -14,7 +14,7 @@
*/
import {QueryDslFunctionScoreContainer} from '@elastic/elasticsearch/lib/api/types';
import {SCBackendConfigurationSearchBoostingType} from '@openstapps/core';
import {QueryDslSpecificQueryContainer} from '../../types/util';
import {QueryDslSpecificQueryContainer} from '../../types/util.js';
/**
* Creates boost functions for all type boost configurations

View File

@@ -14,7 +14,7 @@
*/
import {QueryDslFunctionScoreContainer} from '@elastic/elasticsearch/lib/api/types';
import {SCBackendConfigurationSearchBoostingContext, SCSearchContext} from '@openstapps/core';
import {buildFunctionsForBoostingTypes} from './boost-functions';
import {buildFunctionsForBoostingTypes} from './boost-functions.js';
/**
* Builds scoring functions from boosting config

View File

@@ -14,13 +14,13 @@
*/
import {QueryDslQueryContainer} from '@elastic/elasticsearch/lib/api/types';
import {SCSearchFilter} from '@openstapps/core';
import {buildBooleanFilter} from './filters/boolean';
import {buildAvailabilityFilter} from './filters/availability';
import {buildDateRangeFilter} from './filters/date-range';
import {buildDistanceFilter} from './filters/distance';
import {buildGeoFilter} from './filters/geo';
import {buildNumericRangeFilter} from './filters/numeric-range';
import {buildValueFilter} from './filters/value';
import {buildBooleanFilter} from './filters/boolean.js';
import {buildAvailabilityFilter} from './filters/availability.js';
import {buildDateRangeFilter} from './filters/date-range.js';
import {buildDistanceFilter} from './filters/distance.js';
import {buildGeoFilter} from './filters/geo.js';
import {buildNumericRangeFilter} from './filters/numeric-range.js';
import {buildValueFilter} from './filters/value.js';
/**
* Converts Array of Filters to elasticsearch query-syntax

View File

@@ -13,7 +13,7 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCSearchAvailabilityFilter} from '@openstapps/core';
import {QueryDslSpecificQueryContainer} from '../../types/util';
import {QueryDslSpecificQueryContainer} from '../../types/util.js';
/**
* Converts an availability filter to elasticsearch syntax

View File

@@ -14,8 +14,8 @@
*/
import {QueryDslBoolQuery} from '@elastic/elasticsearch/lib/api/types';
import {SCSearchBooleanFilter} from '@openstapps/core';
import {QueryDslSpecificQueryContainer} from '../../types/util';
import {buildFilter} from '../filter';
import {QueryDslSpecificQueryContainer} from '../../types/util.js';
import {buildFilter} from '../filter.js';
/**
* Converts a boolean filter to elasticsearch syntax

View File

@@ -14,7 +14,7 @@
*/
import {QueryDslDateRangeQuery} from '@elastic/elasticsearch/lib/api/types';
import {SCSearchDateRangeFilter} from '@openstapps/core';
import {QueryDslSpecificQueryContainer} from '../../types/util';
import {QueryDslSpecificQueryContainer} from '../../types/util.js';
/**
* Converts a date range filter to elasticsearch syntax

View File

@@ -14,7 +14,7 @@
*/
import {QueryDslGeoDistanceQuery} from '@elastic/elasticsearch/lib/api/types';
import {SCSearchDistanceFilter} from '@openstapps/core';
import {QueryDslSpecificQueryContainer} from '../../types/util';
import {QueryDslSpecificQueryContainer} from '../../types/util.js';
/**
* Converts a distance filter to elasticsearch syntax

View File

@@ -13,7 +13,7 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCGeoFilter} from '@openstapps/core';
import {QueryDslSpecificQueryContainer} from '../../types/util';
import {QueryDslSpecificQueryContainer} from '../../types/util.js';
/**
* Converts a geo filter to elasticsearch syntax

View File

@@ -15,7 +15,7 @@
import {QueryDslNumberRangeQuery} from '@elastic/elasticsearch/lib/api/types';
import {SCSearchNumericRangeFilter} from '@openstapps/core';
import {QueryDslSpecificQueryContainer} from '../../types/util';
import {QueryDslSpecificQueryContainer} from '../../types/util.js';
/**
* Converts a numeric range filter to elasticsearch syntax

View File

@@ -13,7 +13,7 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCSearchValueFilter} from '@openstapps/core';
import {QueryDslSpecificQueryContainer} from '../../types/util';
import {QueryDslSpecificQueryContainer} from '../../types/util.js';
/**
* Converts a value filter to elasticsearch syntax

View File

@@ -26,7 +26,7 @@ import {buildScoringFunctions} from './boost/scoring-functions.js';
* @param elasticsearchConfig Elasticsearch configuration
* @returns ElasticsearchQuery (body of a search-request)
*/
export function buildQuery(
export const buildQuery = function buildQuery(
parameters: SCSearchQuery,
defaultConfig: SCConfigFile,
elasticsearchConfig: ElasticsearchConfig,
@@ -111,4 +111,4 @@ export function buildQuery(
}
return functionScoreQuery;
}
};

View File

@@ -25,7 +25,7 @@ import {buildPriceSort} from './sort/price.js';
* @param sorts Sorting rules to apply to the data that is being queried
* @returns an array of sort queries
*/
export function buildSort(sorts: SCSearchSort[]): Sort {
export const buildSort = function buildSort(sorts: SCSearchSort[]): Sort {
return sorts.map(sort => {
switch (sort.type) {
case 'generic': {
@@ -42,4 +42,4 @@ export function buildSort(sorts: SCSearchSort[]): Sort {
}
}
});
}
};

View File

@@ -16,7 +16,6 @@
import {SCConfigFile, SCSearchQuery, SCSearchResponse, SCThings, SCThingType, SCUuid} from '@openstapps/core';
import {Express} from 'express';
import moment from 'moment';
import {getIndexUID} from '../src/storage/elasticsearch/util.js';
import {configureApp} from '../src/app.js';
import express from 'express';
import http from 'http';
@@ -26,6 +25,7 @@ import getPort from 'get-port';
import {Database} from '../src/storage/database.js';
import {v4} from 'uuid';
import {backendConfig} from '../src/config.js';
import {getIndexUID} from '../src/storage/elasticsearch/util/index.js';
/**
* Adds routers and configures an (express) app

View File

@@ -31,8 +31,8 @@ import {buildQuery} from '../../../src/storage/elasticsearch/query/query.js';
import {buildSort} from '../../../src/storage/elasticsearch/query/sort.js';
import {ElasticsearchConfig} from '../../../src/storage/elasticsearch/types/elasticsearch-config.js';
import {QueryDslSpecificQueryContainer} from '../../../src/storage/elasticsearch/types/util.js';
import {configFile} from '../../../src/common.js';
import {SortCombinations} from '@elastic/elasticsearch/lib/api/types';
import {backendConfig} from '../../../src/config.js';
describe('Query', function () {
describe('buildBooleanFilter', function () {
@@ -363,9 +363,7 @@ describe('Query', function () {
const filter = buildFilter(rawFilter) as QueryDslSpecificQueryContainer<'range'>;
expect(filter).to.deep.equal(expectedFilter);
for (const bound of ['g', 'l']) {
// @ts-expect-error implicit any
const inclusiveExists = typeof filter.range.price[`${bound}t`] !== 'undefined';
// @ts-expect-error implicit any
const exclusiveExists = typeof filter.range.price[`${bound}te`] !== 'undefined';
// only one should exist at the same time

View File

@@ -1,7 +1,9 @@
<<<<<<<< HEAD:README.md
# Open StApps Monorepo
========
# Database docker image
[![pipeline status](https://img.shields.io/gitlab/pipeline/openstapps/database.svg?style=flat-square)](https://gitlab.com/openstapps/database/commits/main)
[![license)](https://img.shields.io/badge/license-GPL--3.0--only-lightgrey.svg)](https://www.gnu.org/licenses/gpl-3.0.en.html)
@@ -14,6 +16,7 @@ Additionally the [ICU Analysis Plugin](https://www.elastic.co/guide/en/elasticse
installed to provide unicode collation which is used for sorting.
## Usage for testing purposes:
Run it with this command: `docker run -d -p 9200:9200 registry.gitlab.com/openstapps/database:master`
Currently there is an issue with elasticsearch and java on linux machines that temporarly can be solved by running:
@@ -21,6 +24,5 @@ Currently there is an issue with elasticsearch and java on linux machines that t
To set it permanently, you will have to add it to `/etc/sysctl.conf` on machines that run systemd as a init deamon.
## For production use:
Please set `vm.max_map_count=262144` permanently. It is explained [here](https://www.elastic.co/guide/en/elasticsearch/reference/8.4/docker.html#docker-prod-prerequisites)
>>>>>>>> database/main:backend/database/README.md
Please set `vm.max_map_count=262144` permanently. It is explained [here](https://www.elastic.co/guide/en/elasticsearch/reference/8.4/docker.html#docker-prod-prerequisites)

View File

@@ -27,14 +27,14 @@
"@openstapps/logger": "workspace:*",
"@types/config": "3.3.0",
"@types/dockerode": "3.3.17",
"@types/node": "14.18.36",
"@types/node": "18.15.3",
"@types/sha1": "1.1.3",
"config": "3.3.9",
"dockerode": "3.3.5",
"is-cidr": "4.0.2",
"mustache": "4.2.0",
"semver": "7.3.8",
"typescript": "4.8.4"
"typescript": "4.6.4"
},
"devDependencies": {
"@openstapps/eslint-config": "workspace:*",
@@ -42,24 +42,23 @@
"@openstapps/prettier-config": "workspace:*",
"@openstapps/tsconfig": "workspace:*",
"@types/chai": "4.3.5",
"@types/sinon-chai": "3.2.9",
"@types/config": "3.3.0",
"@types/sinon": "10.0.14",
"@types/dockerode": "3.3.14",
"@types/mustache": "4.2.2",
"@types/dockerode": "3.3.17",
"@types/mocha": "10.0.1",
"@types/mustache": "4.2.2",
"@types/node": "18.15.3",
"@types/proxyquire": "1.3.28",
"@types/semver": "7.3.13",
"@types/sha1": "1.1.3",
"@types/sinon": "10.0.14",
"@types/sinon-chai": "3.2.9",
"c8": "7.13.0",
"chai": "4.3.7",
"mocha": "10.2.0",
"sinon": "15.0.4",
"sinon-chai": "3.7.0",
"mocha": "10.2.0",
"c8": "7.13.0",
"ts-node": "10.9.1",
"tsup": "6.7.0",
"typedoc": "0.23.28"
"tsup": "6.7.0"
},
"tsup": {
"entry": [

View File

@@ -6,12 +6,14 @@
"license": "GPL-3.0-only",
"author": "Thea Schöbl <dev@theaninova.de>",
"devDependencies": {
"@openstapps/tsconfig": "workspace:*",
"@openstapps/eslint-config": "workspace:*",
"@openstapps/prettier-config": "workspace:*",
"@openstapps/eslint-config": "workspace:*"
"@openstapps/tsconfig": "workspace:*"
},
"prettier": "@openstapps/prettier-config",
"eslintConfig": {
"extends": ["@openstapps/eslint-configt"]
"extends": [
"@openstapps/eslint-configt"
]
}
}

View File

@@ -0,0 +1,115 @@
// @ts-check
const fs = require("fs");
const path = require("node:path");
const child_process = require("child_process");
/** @type {import('eslint').Rule.RuleModule} */
const copyrightHeaderRule = {
meta: {
schema: [{
type: 'object',
properties: {
author: {type: 'string'},
license: {type: 'string'},
fixedDate: {type: 'string'},
},
required: ['author', 'license']
}],
type: 'problem',
docs: {
description: 'Files should start with a copyright header'
},
messages: {
missing: 'Missing a copyright header at the start of the file',
invalid: 'Invalid copyright header',
tryThisHeader: 'Use this copyright header:\n\n/*{{expected}}*/'
},
fixable: "code",
hasSuggestions: true,
},
create: function(context) {
const code = context.getSourceCode()
const {author, license, fixedDate} = context.options[0]
const year = fixedDate ? new Date(fixedDate) : getAuthorDate(context.getPhysicalFilename())
if (!year) return {}
const expected = license
.replace('{{year}}', year.getFullYear().toString())
.replace('{{author}}', author)
const comment = code.getAllComments().find(it => it.type === 'Block')
if (!comment) {
context.report({
loc: {
line: 0,
column: 0,
},
messageId: 'missing',
suggest: [
{
messageId: 'tryThisHeader',
data: {expected},
fix(fixer) {
return fixer.insertTextBeforeRange([0, 0], `/*${expected}*/\n`)
}
}
]
})
return {}
}
if (comment.value !== expected && comment.loc && comment.range) {
const range = comment.range
context.report({
loc: comment.loc,
messageId: 'invalid',
suggest: [
{
messageId: 'tryThisHeader',
data: {expected},
fix(fixer) {
return fixer.replaceTextRange(range, `/*${expected}*/`)
}
}
]
})
}
return {}
}
}
/**
* Retrieves the last edited date of a file
*
* Uses git history if available, last modified date otherwise.
*
* @param filePath {string}
* @return {Date | undefined}
*/
function getAuthorDate(filePath) {
// just to be on the safe side
const sanitizedPath = path.resolve(filePath)
try {
const result = child_process.execSync(`git log -1 --pretty="format:%ad" "${sanitizedPath}"`, {
cwd: path.dirname(sanitizedPath),
stdio: 'pipe',
})
const date = new Date(result.toString())
if (!Number.isNaN(date.getTime())) {
return date
}
} catch {}
try {
const stats = fs.statSync(sanitizedPath)
const date = new Date(stats.mtime)
return Number.isNaN(date.getTime()) ? undefined : date
} catch {}
return undefined
}
module.exports = copyrightHeaderRule

View File

@@ -0,0 +1,58 @@
// @ts-check
"use strict"
const rule = require('./copyright-header-rule')
const RuleTester = require('eslint').RuleTester
const ruleTester = new RuleTester()
const options = [{
fixedDate: '2023',
author: 'Me',
license: `*\n * Copyright {{year}} {{author}}\n *\n * contents\n `,
}]
ruleTester.run('copyright-header', rule, {
valid: [
{
code: `/**\n * Copyright 2023 Me\n *\n * contents\n */`,
options,
},
{
code: `// @ts-check\n\n\n/**\n * Copyright 2023 Me\n *\n * contents\n */`,
options,
}
],
invalid: [
{
code: `// bla\n/**\n * Copyright 2022 Me\n *\n * contents\n */\n\nvar s = "abc"`,
options,
errors: [
{
messageId: 'invalid',
suggestions: [
{
messageId: 'tryThisHeader',
output: '// bla\n/**\n * Copyright 2023 Me\n *\n * contents\n */\n\nvar s = "abc"'
}
]
}
],
},
{
code: 'var s = "abc"',
options,
errors: [
{
messageId: 'missing',
suggestions: [
{
messageId: 'tryThisHeader',
output: '/**\n * Copyright 2023 Me\n *\n * contents\n */\nvar s = "abc"'
}
]
}
]
}
]
})

View File

@@ -1,4 +1,7 @@
module.exports = {
// @ts-check
/** @type {import('eslint').Linter.Config} */
const config = {
root: true,
ignorePatterns: ['projects/**/*'],
parserOptions: {
@@ -93,3 +96,5 @@ module.exports = {
},
],
};
module.exports = config

View File

@@ -0,0 +1,14 @@
Copyright (C) {{year}} {{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 <http://www.gnu.org/licenses/>.

View File

@@ -10,6 +10,12 @@
"Rainer Killinger <mail-openstapps@killinger.co>"
],
"main": "index.js",
"devDependencies": {
"@openstapps/tsconfig": "workspace:*",
"@types/node": "18.15.3",
"eslint": "8.33.0",
"typescript": "4.6.4"
},
"peerDependencies": {
"@typescript-eslint/eslint-plugin": "5.49.0",
"@typescript-eslint/parser": "5.49.0",

View File

@@ -0,0 +1,8 @@
{
"extends": "@openstapps/tsconfig",
"compilerOptions": {
"allowJs": true,
"types": ["node"]
},
"include": ["*.js"]
}

View File

@@ -32,27 +32,27 @@
"@slack/web-api": "6.8.1",
"commander": "10.0.0",
"date-fns": "2.29.3",
"glob": "10.2.1",
"glob": "10.2.6",
"mustache": "4.2.0"
},
"devDependencies": {
"@openstapps/eslint-config": "workspace:*",
"@openstapps/prettier-config": "workspace:*",
"@openstapps/tsconfig": "workspace:*",
"@types/chai": "4.3.4",
"@types/chai": "4.3.5",
"@types/chai-as-promised": "7.1.5",
"@types/glob": "8.0.1",
"@types/mocha": "10.0.1",
"@types/mustache": "4.2.2",
"@types/node": "18.15.3",
"@types/tmp": "0.2.3",
"c8": "7.13.0",
"chai": "4.3.7",
"chai-as-promised": "7.1.1",
"mocha": "10.2.0",
"c8": "7.13.0",
"ts-node": "10.9.1",
"tsup": "6.7.0",
"typescript": "4.8.4"
"typescript": "4.6.4"
},
"tsup": {
"entry": [

11
coverage.mjs Executable file
View File

@@ -0,0 +1,11 @@
#!/usr/bin/env node
import {promisify} from 'node:util';
import {glob} from 'glob';
import {exec} from 'node:child_process';
import {mkdir} from 'fs/promises';
const files = await glob('./*/*/coverage/cobertura-coverage.xml');
const args = files.map(it => `${it.split('/', 2)[1]}='${it}'`);
await mkdir('./coverage');
console.log(await promisify(exec)(`cobertura-merge -o ./coverage/cobertura-coverage.xml ${args.join(' ')}`));

View File

@@ -35,7 +35,7 @@
"@openstapps/prettier-config": "workspace:*",
"@openstapps/tsconfig": "workspace:*",
"@testdeck/mocha": "0.3.3",
"@types/chai": "4.3.4",
"@types/chai": "4.3.5",
"@types/chai-as-promised": "7.1.5",
"@types/mocha": "10.0.1",
"@types/node": "18.15.3",
@@ -43,11 +43,11 @@
"chai-as-promised": "7.1.1",
"conventional-changelog-cli": "2.2.2",
"mocha": "10.2.0",
"nock": "13.3.0",
"nock": "13.3.1",
"nyc": "15.1.0",
"ts-node": "10.9.1",
"tsup": "6.7.0",
"typescript": "4.8.4"
"typescript": "4.6.4"
},
"tsup": {
"entry": [

View File

@@ -31,11 +31,10 @@
"@openstapps/eslint-config": "workspace:*",
"@openstapps/prettier-config": "workspace:*",
"@openstapps/tsconfig": "workspace:*",
"@types/express": "4.17.16",
"@types/express": "4.17.17",
"@types/node": "18.15.3",
"tsup": "6.7.0",
"typedoc": "0.23.28",
"typescript": "4.8.4"
"typescript": "4.6.4"
},
"tsup": {
"entry": [

View File

@@ -148,7 +148,7 @@
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-unicorn": "45.0.2",
"fontkit": "2.0.2",
"glob": "10.2.1",
"glob": "10.2.6",
"is-docker": "2.2.1",
"jasmine-core": "4.5.0",
"jasmine-spec-reporter": "7.0.0",

View File

@@ -11,17 +11,19 @@
"lint:fix": "dotenv -c -- turbo run lint:fix",
"publish-packages": "dotenv -c -- turbo run build format lint test && changeset version && changeset publish",
"syncpack": "syncpack list-mismatches && syncpack lint-semver-ranges",
"syncpack:fix": "node sync.mjs && syncpack format && syncpack fix-mismatches",
"test": "dotenv -c -- turbo run test"
"syncpack:fix": "syncpack format && syncpack fix-mismatches",
"test": "dotenv -c -- turbo run test && node coverage.mjs"
},
"devDependencies": {
"@changesets/cli": "2.26.0",
"@changesets/cli": "2.26.1",
"cobertura-merge": "1.0.4",
"deepmerge": "4.3.1",
"dotenv-cli": "7.1.0",
"glob": "10.2.1",
"dotenv-cli": "7.2.1",
"glob": "10.2.6",
"package-sync-cli": "1.3.2",
"syncpack": "9.8.4",
"turbo": "1.8.3",
"typedoc": "0.23.28"
"syncpack": "10.1.0",
"turbo": "1.10.0",
"typedoc": "0.24.7",
"typescript": "4.6.4"
}
}

View File

@@ -36,7 +36,7 @@
"@types/cli-progress": "3.11.0",
"@types/express": "4.17.17",
"@types/morgan": "1.9.4",
"@types/node": "14.18.43",
"@types/node": "18.15.3",
"@types/traverse": "0.6.32",
"@types/uuid": "8.3.4",
"@types/wait-on": "5.3.1",
@@ -63,10 +63,11 @@
"@types/chai-as-promised": "7.1.5",
"@types/chai-spies": "1.0.3",
"@types/cli-progress": "3.11.0",
"@types/express": "4.17.16",
"@types/express": "4.17.17",
"@types/fs-extra": "9.0.13",
"@types/json-schema": "7.0.11",
"@types/mocha": "10.0.1",
"c8": "7.13.0",
"chai": "4.3.7",
"chai-as-promised": "7.1.1",
"chai-spies": "1.0.0",
@@ -74,11 +75,9 @@
"fs-extra": "10.1.0",
"mocha": "10.2.0",
"nock": "13.3.1",
"c8": "7.13.0",
"ts-node": "10.9.1",
"tsup": "6.7.0",
"typedoc": "0.23.28",
"typescript": "4.8.4"
"typescript": "4.6.4"
},
"peerDependencies": {
"@openstapps/core": "workspace:*"
@@ -98,8 +97,5 @@
"extends": [
"@openstapps"
]
},
"nyc": {
"extends": "@openstapps/nyc-config"
}
}

View File

@@ -16,15 +16,15 @@
"@openstapps/eslint-config": "workspace:*",
"@openstapps/prettier-config": "workspace:*",
"@openstapps/tsconfig": "workspace:*",
"@types/node": "18.15.3",
"@types/chai": "4.3.4",
"@types/chai": "4.3.5",
"@types/mocha": "10.0.1",
"@types/node": "18.15.3",
"c8": "7.13.0",
"chai": "4.3.7",
"mocha": "10.2.0",
"ts-node": "10.9.1",
"tsup": "6.7.0",
"typescript": "4.8.4"
"typescript": "4.6.4"
},
"tsup": {
"entry": [

View File

@@ -41,20 +41,20 @@
"@openstapps/easy-ast": "workspace:*",
"@openstapps/logger": "workspace:*",
"ajv": "8.12.0",
"re2": "1.18.0",
"better-ajv-errors": "1.2.0",
"commander": "10.0.0",
"deepmerge": "4.3.1",
"del": "6.1.1",
"flatted": "3.2.7",
"fs-extra": "10.1.0",
"glob": "10.2.1",
"glob": "10.2.6",
"got": "12.6.0",
"humanize-string": "3.0.0",
"json-schema": "0.4.0",
"mustache": "4.2.0",
"openapi-types": "12.1.0",
"plantuml-encoder": "1.4.0",
"re2": "1.18.0",
"toposort": "2.0.2",
"ts-json-schema-generator": "1.2.0"
},
@@ -63,20 +63,20 @@
"@openstapps/nyc-config": "workspace:*",
"@openstapps/prettier-config": "workspace:*",
"@openstapps/tsconfig": "workspace:*",
"@types/chai": "4.3.4",
"@types/chai": "4.3.5",
"@types/fs-extra": "9.0.13",
"@types/glob": "8.0.1",
"@types/json-schema": "7.0.11",
"@types/mocha": "10.0.1",
"@types/mustache": "4.2.2",
"@types/node": "18.15.3",
"c8": "7.13.0",
"chai": "4.3.7",
"mocha": "10.2.0",
"c8": "7.13.0",
"nock": "13.3.0",
"tsup": "6.7.0",
"nock": "13.3.1",
"ts-node": "10.9.1",
"typescript": "4.8.4"
"tsup": "6.7.0",
"typescript": "4.6.4"
},
"tsup": {
"entry": [

View File

@@ -46,28 +46,28 @@
"rfdc": "1.3.0"
},
"devDependencies": {
"@openstapps/easy-ast": "workspace:*",
"@openstapps/es-mapping-generator": "workspace:*",
"@openstapps/eslint-config": "workspace:*",
"@openstapps/logger": "workspace:*",
"@openstapps/prettier-config": "workspace:*",
"@openstapps/tsconfig": "workspace:*",
"@openstapps/easy-ast": "workspace:*",
"@types/chai": "4.3.4",
"@types/chai": "4.3.5",
"@types/json-patch": "0.0.30",
"@types/json-schema": "7.0.11",
"@types/mocha": "10.0.1",
"@types/node": "18.15.3",
"@typescript-eslint/eslint-plugin": "5.49.0",
"@typescript-eslint/parser": "5.49.0",
"c8": "7.13.0",
"chai": "4.3.7",
"conditional-type-checks": "1.0.6",
"mocha": "10.2.0",
"c8": "7.13.0",
"source-map-support": "0.5.21",
"surge": "0.23.1",
"ts-node": "10.9.1",
"tsup": "6.7.0",
"typescript": "4.8.4"
"typescript": "4.6.4"
},
"tsup": {
"entry": [

View File

@@ -19,14 +19,14 @@
"dependencies": {
"@openstapps/collection-utils": "workspace:*",
"@openstapps/logger": "workspace:*",
"glob": "10.2.1",
"typescript": "4.8.4"
"glob": "10.2.6",
"typescript": "4.6.4"
},
"devDependencies": {
"@openstapps/eslint-config": "workspace:*",
"@openstapps/prettier-config": "workspace:*",
"@openstapps/tsconfig": "workspace:*",
"@types/chai": "4.3.4",
"@types/chai": "4.3.5",
"@types/mocha": "10.0.1",
"@types/node": "18.15.3",
"c8": "7.13.0",

View File

@@ -28,17 +28,17 @@
"typescript": "3.8.3"
},
"devDependencies": {
"@openstapps/eslint-config": "workspace:*",
"@openstapps/prettier-config": "workspace:*",
"@testdeck/mocha": "0.3.3",
"@openstapps/eslint-config": "workspace:*",
"@types/chai": "4.3.4",
"@types/chai": "4.3.5",
"@types/mocha": "10.0.1",
"@types/node": "14.18.38",
"@types/rimraf": "3.0.2",
"c8": "7.13.0",
"chai": "4.3.7",
"mocha": "10.2.0",
"c8": "7.13.0",
"nock": "13.3.0",
"nock": "13.3.1",
"rimraf": "5.0.0",
"ts-node": "10.9.1"
},

View File

@@ -12,45 +12,22 @@
* 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 {readdirSync, statSync} from 'fs';
import path from 'path';
import {MapAggTest} from './mapping-model/map-agg-test.js';
import {MapAggTestOptions} from './mapping-model/map-agg-test-options.js';
import {MapAggTest} from './mapping-model/map-agg-test';
import {MapAggTestOptions} from './mapping-model/map-agg-test-options';
import {expandPathToFilesSync} from './common';
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()
? // eslint-disable-next-line unicorn/prefer-spread
([] 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 {
// eslint-disable-next-line unicorn/no-await-expression-member
const test = (await import(file))['testConfig'] as MapAggTestOptions;
// eslint-disable-next-line unicorn/no-await-expression-member
const test = (await import(file))['testConfig'] as MapAggTestOptions;
it(test.testName, function () {
magAppInstance.testInterfaceAgainstPath(test);
});
} catch (error) {
console.error('UNHANDLED REJECTION', (error as any).stack);
process.exit(1);
}
it(test.testName, function () {
magAppInstance.testInterfaceAgainstPath(test);
});
}
})
.timeout(20_000)

View File

@@ -0,0 +1,19 @@
import path from 'path';
import {readdirSync, statSync} from 'fs';
/**
* Expand a path to a list of all files deeply contained in it
*/
export function expandPathToFilesSync(sourcePath: string, accept: (fileName: string) => boolean): string[] {
const fullPath = path.resolve(sourcePath);
const directory = statSync(fullPath);
return directory.isDirectory()
? // eslint-disable-next-line unicorn/prefer-spread
([] as string[]).concat(
...readdirSync(fullPath).map(fragment =>
expandPathToFilesSync(path.resolve(sourcePath, fragment), accept),
),
)
: [fullPath].filter(accept);
}

View File

@@ -13,8 +13,8 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {ThingType} from './types.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable

View File

@@ -13,8 +13,8 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {ThingType} from './types.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable

View File

@@ -13,8 +13,8 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {ThingType} from './types.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable

View File

@@ -13,8 +13,8 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {ThingType} from './types.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable

View File

@@ -13,8 +13,8 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {ThingType} from './types.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable

View File

@@ -13,8 +13,8 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {ThingType} from './types.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable

View File

@@ -13,8 +13,8 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {ThingType} from './types.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable

View File

@@ -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',
}

View File

@@ -0,0 +1,34 @@
/*
* 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 {MappingDynamicTemplate, MappingProperty} from '@elastic/elasticsearch/lib/api/types';
export interface MapAggTestOptions {
testName: string;
name: string;
agg?: {
fields?: string[];
globals?: string[];
};
map?: MinimalMappingDescription;
err?: string[];
ignoredTags?: string[];
}
export interface MinimalMappingDescription {
maps?: {
[name: string]: MappingProperty;
};
dynamicTemplates?: Record<string, MappingDynamicTemplate>[];
}

View File

@@ -0,0 +1,145 @@
/*
* 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 {
generateTemplate,
getProjectReflection,
AggregationSchema,
ESNestedAggregation,
ElasticsearchTemplateCollection,
settings,
} from '../../src';
import path from 'path';
import {expect} from 'chai';
import {ProjectReflection} from 'typedoc';
import {MapAggTestOptions, MinimalMappingDescription} from './map-agg-test-options';
export class MapAggTest {
mapping_model_path!: string;
reflection!: ProjectReflection;
constructor(directory: string) {
// eslint-disable-next-line unicorn/prefer-module
this.mapping_model_path = path.resolve(__dirname, directory);
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') {
expect(template.errors).to.be.deep.equal([], 'Unexpected Error!');
} else {
for (const error of template.errors) {
expect(options.err).to.include(error, '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: {
term: {
type: 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] = {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore empty object
mappings: {},
settings: settings,
index_patterns: [`stapps_${typeNameWithoutSpaces}*`],
};
const maps = map.maps ?? {};
maps.type = {
type: 'text',
};
maps.creation_date = {
type: 'date',
};
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore can be used to index
out[templateName].mappings = {
_source: {
excludes: ['creation_date'],
},
date_detection: false,
dynamic: 'strict',
properties: maps,
dynamic_templates: map.dynamicTemplates ?? [],
};
return out;
}
}

View File

@@ -12,8 +12,8 @@
* 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.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable

View File

@@ -12,8 +12,8 @@
* 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.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @date

View File

@@ -12,9 +12,9 @@
* 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 {PARSE_ERROR} from '../../../../lib/config/typemap.js';
import {ThingType} from './types.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {PARSE_ERROR} from '../../../../lib/config/typemap';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable

View File

@@ -12,9 +12,9 @@
* 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 {TYPE_CONFLICT} from '../../../../lib/config/typemap.js';
import {ThingType} from './types.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {TYPE_CONFLICT} from '../../../../lib/config/typemap';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable

View File

@@ -12,8 +12,8 @@
* 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.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable

View File

@@ -12,8 +12,8 @@
* 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.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
export type FilterableEnumType = 'a' | 'b' | 'c';

View File

@@ -12,8 +12,8 @@
* 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.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable

View File

@@ -12,8 +12,8 @@
* 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.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable

View File

@@ -12,8 +12,8 @@
* 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.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable

View File

@@ -12,8 +12,8 @@
* 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.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable

View File

@@ -12,8 +12,8 @@
* 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 {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types.js';
import {MapAggTestOptions} from '../../map-agg-test-options';
import {ThingType} from './types';
/**
* @date

View File

@@ -12,8 +12,8 @@
* 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 {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types.js';
import {MapAggTestOptions} from '../../map-agg-test-options';
import {ThingType} from './types';
/**
* @indexable

View File

@@ -12,8 +12,8 @@
* 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.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable

View File

@@ -12,8 +12,8 @@
* 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.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable

View File

@@ -12,8 +12,8 @@
* 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.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable

View File

@@ -12,9 +12,9 @@
* 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 {MISSING_PREMAP} from '../../../../lib/config/typemap.js';
import {ThingType} from './types.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {MISSING_PREMAP} from '../../../../lib/config/typemap';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable

View File

@@ -12,8 +12,8 @@
* 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.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable

View File

@@ -12,8 +12,8 @@
* 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.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable

View File

@@ -12,8 +12,8 @@
* 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.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable

View File

@@ -12,8 +12,8 @@
* 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.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable

View File

@@ -12,8 +12,8 @@
* 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.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable

View File

@@ -12,8 +12,8 @@
* 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.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable

View File

@@ -12,8 +12,8 @@
* 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.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable

View File

@@ -12,8 +12,8 @@
* 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.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
export interface SCISO8601DateRange {
bar: string;

View File

@@ -12,8 +12,8 @@
* 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.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable

View File

@@ -12,8 +12,8 @@
* 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.js';
import {MapAggTestOptions} from '../../map-agg-test-options.js';
import {ThingType} from './types';
import {MapAggTestOptions} from '../../map-agg-test-options';
/**
* @indexable

View File

@@ -12,46 +12,22 @@
* 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 {readdirSync, statSync} from 'fs';
import path from 'path';
import {MapAggTest} from './mapping-model/map-agg-test.js';
import {MapAggTestOptions} from './mapping-model/map-agg-test-options.js';
import {MapAggTest} from './mapping-model/map-agg-test';
import {MapAggTestOptions} from './mapping-model/map-agg-test-options';
import {expandPathToFilesSync} from './common';
describe('ES Mapping Gen', async () => {
const magAppInstance = new MapAggTest('mappings');
/**
* Expand a path to a list of all files deeply contained in it
*/
// eslint-disable-next-line unicorn/consistent-function-scoping
function expandPathToFilesSync(sourcePath: string, accept: (fileName: string) => boolean): string[] {
const fullPath = path.resolve(sourcePath);
const directory = statSync(fullPath);
return directory.isDirectory()
? // eslint-disable-next-line unicorn/prefer-spread
([] 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 {
// eslint-disable-next-line unicorn/no-await-expression-member
const test = (await import(file))['testConfig'] as MapAggTestOptions;
// eslint-disable-next-line unicorn/no-await-expression-member
const test = (await import(file))['testConfig'] as MapAggTestOptions;
it(test.testName, function () {
magAppInstance.testInterfaceAgainstPath(test);
});
} catch (error) {
console.error('UNHANDLED REJECTION', (error as any).stack);
process.exit(1);
}
it(test.testName, function () {
magAppInstance.testInterfaceAgainstPath(test);
});
}
})
.timeout(20_000)

View File

@@ -35,8 +35,8 @@
"@typescript-eslint/parser": "5.49.0",
"ts-node": "10.9.1",
"tsup": "6.7.0",
"typedoc": "0.23.28",
"typescript": "4.8.4"
"typedoc": "0.24.7",
"typescript": "4.6.4"
},
"tsup": {
"entry": [

View File

@@ -31,20 +31,20 @@
"@openstapps/eslint-config": "workspace:*",
"@openstapps/prettier-config": "workspace:*",
"@openstapps/tsconfig": "workspace:*",
"@types/chai": "4.3.4",
"@types/chai": "4.3.5",
"@types/chai-as-promised": "7.1.5",
"@types/chai-spies": "1.0.3",
"@types/mocha": "10.0.1",
"@types/node": "18.15.3",
"c8": "7.13.0",
"chai": "4.3.7",
"chai-as-promised": "7.1.1",
"chai-spies": "1.0.0",
"mocha": "10.2.0",
"c8": "7.13.0",
"ts-node": "10.9.1",
"tsup": "6.7.0",
"typedoc": "0.23.28",
"typescript": "4.8.4"
"typedoc": "0.24.7",
"typescript": "4.6.4"
},
"tsup": {
"entry": [

800
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -18,13 +18,11 @@
},
"test": {
"dependsOn": ["^test"],
"outputs": [".coverage"]
"outputs": ["coverage"]
},
"check-configuration": {
"dependsOn": ["^check-configuration"]
},
"docs": {
}
"docs": {}
}
}