diff --git a/javascript/package.json b/javascript/package.json index 0b0e56e7..90289f3e 100644 --- a/javascript/package.json +++ b/javascript/package.json @@ -14,16 +14,12 @@ "bdd" ], "license": "MIT", - "exports": { - ".": { - "import": "./dist/es/index.js", - "default": "./dist/lib/index.js" - } + "type": "module", + "exports": "./dist/src/index.js", + "engines": { + "node": ">=16" }, - "main": "./dist/lib/index.js", - "jsnext:main": "./dist/es/index.js", - "module": "./dist/es/index.js", - "types": "./dist/es/index.d.ts", + "types": "./dist/src/index.d.ts", "sideEffects": false, "repository": { "type": "git", @@ -33,10 +29,9 @@ "prepublish": "npm run build", "lint": "tslint --project .", "lint:fix": "tslint --project . --fix", - "transpile": "tsc -p ./ --module commonjs && echo '# transpile es5 (require) sucess!'", - "transpile:es": "tsc -p ./ --outDir ./dist/es && echo '# transpile es (modules) sucess!'", + "transpile": "tsc -p ./ && echo '# transpile es (modules) sucess!'", "transpile:removegen": "rimraf -r ./dist/lib/truth-table-generator && rimraf -r ./dist/es/truth-table-generator", - "build": "rimraf -r ./dist && npm run transpile && npm run transpile:es && npm run transpile:removegen", + "build": "rimraf -r ./dist && npm run transpile && npm run transpile:removegen", "dry": "npm pack --dry-run", "test": "mocha -r ts-node/register test/unit/index.test.ts --timeout 50000 --bail", "dev": "mocha -r ts-node/register test/unit/index.test.ts --watch --watch-extensions ts", @@ -59,7 +54,7 @@ "clone": "2.1.2", "deep-equal": "2.2.2", "faker": "5.5.3", - "minimongo": "6.8.3", + "minimongo": "6.15.1", "mocha": "10.2.0", "pouchdb-selector-core": "8.0.1", "read-last-lines": "1.8.0", diff --git a/javascript/src/truth-table-generator/binary-state.ts b/javascript/src/truth-table-generator/binary-state.ts index 194d65bb..cfe7e8c2 100644 --- a/javascript/src/truth-table-generator/binary-state.ts +++ b/javascript/src/truth-table-generator/binary-state.ts @@ -48,7 +48,7 @@ export function oppositeBinary(i: string): string { } export function stateSetToObject(stateSet: StateSet): any { - const ret = {}; + const ret: any = {}; let i = 0; orderedStateList.forEach(s => { ret[s] = stateSet[i]; diff --git a/javascript/src/truth-table-generator/data-generator.ts b/javascript/src/truth-table-generator/data-generator.ts index 0437d9e1..b6704aff 100644 --- a/javascript/src/truth-table-generator/data-generator.ts +++ b/javascript/src/truth-table-generator/data-generator.ts @@ -34,7 +34,7 @@ export function randomHuman(partial?: Partial): Human { }; if (partial) { Object.entries(partial).forEach(([k, v]) => { - ret[k] = v; + (ret as any)[k] = v; }); } @@ -59,7 +59,7 @@ export function randomChangeHuman(input: Human): Human { const cloned: Human = Object.assign({}, input); const field = fakerDatatype.number({ min: 1, max: 3 }); - keyToChangeFn[field](cloned); + (keyToChangeFn as any)[field](cloned); return cloned; } @@ -84,7 +84,7 @@ export function randomChangeEvent( const randomOp = randomOfArray(ops); const operation = allDocs.length === 0 ? 'INSERT' : randomOp; - let ret; + let ret: any; switch (operation) { case 'INSERT': const newDoc = randomHuman(); diff --git a/javascript/src/truth-table-generator/minimongo-helper.ts b/javascript/src/truth-table-generator/minimongo-helper.ts index 2c4d3d71..94ec6f2c 100644 --- a/javascript/src/truth-table-generator/minimongo-helper.ts +++ b/javascript/src/truth-table-generator/minimongo-helper.ts @@ -5,11 +5,11 @@ import { import { compileDocumentSelector, compileSort -} from 'minimongo/src/selector'; +} from 'minimongo/lib/selector.js'; export { compileDocumentSelector, compileSort -} from 'minimongo/src/selector'; +} from 'minimongo/lib/selector.js'; import { randomString } from 'async-test-util'; diff --git a/javascript/src/util.ts b/javascript/src/util.ts index 74377bd3..b5f65bc6 100644 --- a/javascript/src/util.ts +++ b/javascript/src/util.ts @@ -40,7 +40,7 @@ export function tryToFillPreviousDoc( input.changeEvent.previous = doc; } } else { - const found = input.previousResults.find(item => item[primary] === id); + const found = input.previousResults.find(item => (item as any)[primary] === id); if (found) { input.changeEvent.previous = found; } @@ -68,7 +68,7 @@ export function getSortFieldsOfQuery(query: MongoQuery): string[] { } return query.sort.map(maybeArray => { if (Array.isArray(maybeArray)) { - return maybeArray[0].map(field => normalizeSortField(field)); + return maybeArray[0].map((field: any) => normalizeSortField(field)); } else { return normalizeSortField(maybeArray); } @@ -85,7 +85,7 @@ export function replaceCharAt(str: string, index: number, replacement: string) { export function mapToObject(map: Map): { [k: string]: V } { - const ret = {}; + const ret: any = {}; map.forEach( (value: V, key: K) => { ret[key as any] = value; @@ -105,7 +105,7 @@ export function objectToMap(object: { } export function cloneMap(map: Map): Map { - const ret = new Map(); + const ret: any = new Map(); map.forEach( (value: V, key: K) => { ret[key as any] = value; diff --git a/javascript/test/helper/input.ts b/javascript/test/helper/input.ts index 144c6bd7..c866110e 100644 --- a/javascript/test/helper/input.ts +++ b/javascript/test/helper/input.ts @@ -1,10 +1,10 @@ import { StateResolveFunctionInput, QueryParams -} from '../../src/types'; -import { Human } from '../../src/truth-table-generator/types'; -import { getQueryParamsByMongoQuery } from '../../src/truth-table-generator/minimongo-helper'; -import { randomChangeEvent } from '../../src/truth-table-generator/data-generator'; +} from '../../src/types/index.js'; +import { Human } from '../../src/truth-table-generator/types.js'; +import { getQueryParamsByMongoQuery } from '../../src/truth-table-generator/minimongo-helper.js'; +import { randomChangeEvent } from '../../src/truth-table-generator/data-generator.js'; export function getExampleStateResolveFunctionInput(): StateResolveFunctionInput { const queryParams: QueryParams = getQueryParamsByMongoQuery({ @@ -17,4 +17,4 @@ export function getExampleStateResolveFunctionInput(): StateResolveFunctionInput queryParams }; -} \ No newline at end of file +} diff --git a/javascript/test/unit/actions.test.ts b/javascript/test/unit/actions.test.ts index c519513e..f05fe7c8 100644 --- a/javascript/test/unit/actions.test.ts +++ b/javascript/test/unit/actions.test.ts @@ -2,17 +2,17 @@ import * as assert from 'assert'; import { orderedActionList, actionFunctions -} from '../../src/actions'; +} from '../../src/actions/index.js'; import { ActionFunction, ActionName, ActionFunctionInput, ResultKeyDocumentMap -} from '../../src/types'; -import { randomChangeEvent, randomHuman, randomHumans } from '../../src/truth-table-generator/data-generator'; -import { getQueryParamsByMongoQuery } from '../../src/truth-table-generator/minimongo-helper'; -import { Human } from '../../src/truth-table-generator/types'; -import { insertFirst, insertLast, removeExisting, insertAtSortPosition } from '../../src/actions/action-functions'; +} from '../../src/types/index.js'; +import { randomChangeEvent, randomHuman, randomHumans } from '../../src/truth-table-generator/data-generator.js'; +import { getQueryParamsByMongoQuery } from '../../src/truth-table-generator/minimongo-helper.js'; +import { Human } from '../../src/truth-table-generator/types.js'; +import { insertFirst, insertLast, removeExisting, insertAtSortPosition } from '../../src/actions/action-functions.js'; export function docsToMap( primary: string, @@ -20,7 +20,7 @@ export function docsToMap( ): ResultKeyDocumentMap { const map: ResultKeyDocumentMap = new Map(); docs.forEach(doc => { - map.set(doc[primary], doc); + map.set((doc as any)[primary], doc); }); return map; } @@ -48,7 +48,7 @@ export function runCheckedAction( // ensure correct all docs are also in key-doc-map input.previousResults.forEach(doc => { - const mapDoc = (input.keyDocumentMap as ResultKeyDocumentMap).get(doc[primary]); + const mapDoc = (input.keyDocumentMap as ResultKeyDocumentMap).get((doc as any)[primary]); assert.ok(mapDoc); assert.deepStrictEqual(doc, mapDoc); }); diff --git a/javascript/test/unit/binary-state.test.ts b/javascript/test/unit/binary-state.test.ts index 9125da0a..06b34105 100644 --- a/javascript/test/unit/binary-state.test.ts +++ b/javascript/test/unit/binary-state.test.ts @@ -5,11 +5,11 @@ import { decimalToPaddedBinary, binaryToDecimal, LAST_STATE_SET -} from '../../src/truth-table-generator/binary-state'; +} from '../../src/truth-table-generator/binary-state.js'; import { orderedStateList -} from '../../src/states'; -import { StateSet } from '../../src/types'; +} from '../../src/states/index.js'; +import { StateSet } from '../../src/types/index.js'; describe('binary-state.test.ts', () => { diff --git a/javascript/test/unit/calculate-bdd-quality.test.ts b/javascript/test/unit/calculate-bdd-quality.test.ts index 84879af0..95c17653 100644 --- a/javascript/test/unit/calculate-bdd-quality.test.ts +++ b/javascript/test/unit/calculate-bdd-quality.test.ts @@ -8,21 +8,21 @@ import { measurePerformanceOfStateFunctions, countFunctionUsages, getQualityOfBdd -} from '../../src/truth-table-generator/calculate-bdd-quality'; +} from '../../src/truth-table-generator/calculate-bdd-quality.js'; import { orderedStateList -} from '../../src/states'; -import { StateActionIdMap } from '../../src/truth-table-generator/types'; -import { OUTPUT_TRUTH_TABLE_PATH } from '../../src/truth-table-generator/config'; -import { readJsonFile } from '../../src/truth-table-generator/util'; -import { objectToMap } from '../../src'; -import { orderedActionList } from '../../src/actions'; +} from '../../src/states/index.js'; +import { StateActionIdMap } from '../../src/truth-table-generator/types.js'; +import { OUTPUT_TRUTH_TABLE_PATH } from '../../src/truth-table-generator/config.js'; +import { readJsonFile } from '../../src/truth-table-generator/util.js'; +import { objectToMap } from '../../src/index.js'; +import { orderedActionList } from '../../src/actions/index.js'; import { DEFAULT_EXAMPLE_QUERY -} from '../../src/truth-table-generator/queries'; +} from '../../src/truth-table-generator/queries.js'; import { insertFiveSorted -} from '../../src/truth-table-generator/procedures'; +} from '../../src/truth-table-generator/procedures.js'; describe('calculate-bdd-quality.test.ts', () => { const unknownValueActionId: number = 42; diff --git a/javascript/test/unit/fuzzing.test.ts b/javascript/test/unit/fuzzing.test.ts index a83d9b4a..17651182 100644 --- a/javascript/test/unit/fuzzing.test.ts +++ b/javascript/test/unit/fuzzing.test.ts @@ -1,8 +1,8 @@ import * as assert from 'assert'; -import { fuzzing } from '../../src/truth-table-generator/fuzzing'; -import { orderedActionList } from '../../src/actions'; -import { StateActionIdMap } from '../../src/truth-table-generator/types'; +import { fuzzing } from '../../src/truth-table-generator/fuzzing.js'; +import { orderedActionList } from '../../src/actions/index.js'; +import { StateActionIdMap } from '../../src/truth-table-generator/types.js'; describe('fuzzing.test.ts', () => { diff --git a/javascript/test/unit/generated-stuff.test.ts b/javascript/test/unit/generated-stuff.test.ts index 50b8c0cc..688560d5 100644 --- a/javascript/test/unit/generated-stuff.test.ts +++ b/javascript/test/unit/generated-stuff.test.ts @@ -10,35 +10,35 @@ import { import { orderedStateList, stateResolveFunctions -} from '../../src/states'; +} from '../../src/states/index.js'; import { objectToMap -} from '../../src/util'; +} from '../../src/util.js'; import { readJsonFile -} from '../../src/truth-table-generator/util'; -import { OUTPUT_TRUTH_TABLE_PATH } from '../../src/truth-table-generator/config'; -import { StateActionIdMap, Human } from '../../src/truth-table-generator/types'; -import { getSimpleBdd } from '../../src/bdd/bdd.generated'; +} from '../../src/truth-table-generator/util.js'; +import { OUTPUT_TRUTH_TABLE_PATH } from '../../src/truth-table-generator/config.js'; +import { StateActionIdMap, Human } from '../../src/truth-table-generator/types.js'; +import { getSimpleBdd } from '../../src/bdd/bdd.generated.js'; import { StateResolveFunctionInput, QueryParams, MongoQuery, ChangeEvent -} from '../../src/types'; +} from '../../src/types/index.js'; import { getQueryParamsByMongoQuery, getMinimongoCollection, applyChangeEvent, minimongoFind, minimongoUpsert -} from '../../src/truth-table-generator/minimongo-helper'; -import { randomHuman } from '../../src/truth-table-generator/data-generator'; -import { calculateActionName, calculateActionFromMap, runAction } from '../../src/index'; -import { getQueryVariations } from '../../src/truth-table-generator/queries'; -import { getTestProcedures, oneThatWasCrashing } from '../../src/truth-table-generator/procedures'; +} from '../../src/truth-table-generator/minimongo-helper.js'; +import { randomHuman } from '../../src/truth-table-generator/data-generator.js'; +import { calculateActionName, calculateActionFromMap, runAction } from '../../src/index.js'; +import { getQueryVariations } from '../../src/truth-table-generator/queries.js'; +import { getTestProcedures, oneThatWasCrashing } from '../../src/truth-table-generator/procedures.js'; import deepEqual = require('deep-equal'); -import { orderedActionList } from '../../src/actions'; +import { orderedActionList } from '../../src/actions/index.js'; describe('generated-stuff.test.ts', () => { @@ -113,7 +113,7 @@ describe('generated-stuff.test.ts', () => { const sortedResolvers = {}; orderedStateList.forEach((stateName, index) => { const fn = stateResolveFunctions[stateName]; - sortedResolvers[index] = (i: any) => { + (sortedResolvers as any)[index] = (i: any) => { const ret = fn(i); // console.log('resolve: ' + index + ' returned ' + ret); return ret; diff --git a/javascript/test/unit/index.test.ts b/javascript/test/unit/index.test.ts index 8d630499..2c37245d 100644 --- a/javascript/test/unit/index.test.ts +++ b/javascript/test/unit/index.test.ts @@ -1,12 +1,12 @@ console.log('### starting unit-tests ###'); -import './minimongo.test'; -import './actions.test'; -import './states.test'; -import './binary-state.test'; -import './queries.test'; -import './fuzzing.test'; -import './calculate-bdd-quality.test'; -import './truth-table-generator.test'; +import './minimongo.test.js'; +import './actions.test.js'; +import './states.test.js'; +import './binary-state.test.js'; +import './queries.test.js'; +import './fuzzing.test.js'; +import './calculate-bdd-quality.test.js'; +import './truth-table-generator.test.js'; // should be last -import './generated-stuff.test'; +import './generated-stuff.test.js'; diff --git a/javascript/test/unit/minimongo.test.ts b/javascript/test/unit/minimongo.test.ts index 066ffd4d..0eec04af 100644 --- a/javascript/test/unit/minimongo.test.ts +++ b/javascript/test/unit/minimongo.test.ts @@ -2,16 +2,16 @@ import * as assert from 'assert'; import { randomHuman, randomHumans -} from '../../src/truth-table-generator/data-generator'; +} from '../../src/truth-table-generator/data-generator.js'; import { getMinimongoCollection, minimongoUpsert, minimongoFind, compileSort -} from '../../src/truth-table-generator/minimongo-helper'; +} from '../../src/truth-table-generator/minimongo-helper.js'; import { clone } from 'async-test-util'; -import { MongoQuery } from '../../src'; +import { MongoQuery } from '../../src/index.js'; /** * sometimes we think stuff is wrong with minimongo diff --git a/javascript/test/unit/queries.test.ts b/javascript/test/unit/queries.test.ts index e873a68e..d65fa2b4 100644 --- a/javascript/test/unit/queries.test.ts +++ b/javascript/test/unit/queries.test.ts @@ -5,7 +5,7 @@ import { SKIP_VARIATIONS, LIMIT_VARIATIONS, SORT_VARIATION -} from '../../src/truth-table-generator/queries'; +} from '../../src/truth-table-generator/queries.js'; describe('queries-state.test.ts', () => { it('should have all query variations', () => { diff --git a/javascript/test/unit/states.test.ts b/javascript/test/unit/states.test.ts index d7ca8d99..72defc82 100644 --- a/javascript/test/unit/states.test.ts +++ b/javascript/test/unit/states.test.ts @@ -4,9 +4,9 @@ import { stateResolveFunctions, getStateSet, stateResolveFunctionByIndex -} from '../../src/states'; -import { getExampleStateResolveFunctionInput } from '../helper/input'; -import { StateResolveFunctionInput } from '../../src/types'; +} from '../../src/states/index.js'; +import { getExampleStateResolveFunctionInput } from '../helper/input.js'; +import { StateResolveFunctionInput } from '../../src/types/index.js'; import { clone } from 'async-test-util'; import { wasSortedAfterLast, @@ -16,10 +16,10 @@ import { wasLimitReached, wasMatching, isSortedBeforeFirst -} from '../../src/states/state-resolver'; -import { randomHuman } from '../../src/truth-table-generator/data-generator'; -import { getQueryParamsByMongoQuery } from '../../src/truth-table-generator/minimongo-helper'; -import { Human } from '../../src/truth-table-generator/types'; +} from '../../src/states/state-resolver.js'; +import { randomHuman } from '../../src/truth-table-generator/data-generator.js'; +import { getQueryParamsByMongoQuery } from '../../src/truth-table-generator/minimongo-helper.js'; +import { Human } from '../../src/truth-table-generator/types.js'; describe('states.test.ts', () => { describe('basic', () => { diff --git a/javascript/test/unit/truth-table-generator.test.ts b/javascript/test/unit/truth-table-generator.test.ts index 1f545de4..99df985a 100644 --- a/javascript/test/unit/truth-table-generator.test.ts +++ b/javascript/test/unit/truth-table-generator.test.ts @@ -1,16 +1,15 @@ import * as assert from 'assert'; -import { Human } from '../../src/truth-table-generator/types'; -import { clone } from 'async-test-util'; -import { oneThatWasCrashing } from '../../src/truth-table-generator/procedures'; -import { generateTruthTable } from '../../src/truth-table-generator'; +import { Human } from '../../src/truth-table-generator/types.js'; +import { oneThatWasCrashing } from '../../src/truth-table-generator/procedures.js'; +import { generateTruthTable } from '../../src/truth-table-generator/index.js'; import { getMinimongoCollection, minimongoFind, applyChangeEvent, getQueryParamsByMongoQuery -} from '../../src/truth-table-generator/minimongo-helper'; -import { StateResolveFunctionInput, MongoQuery } from '../../src/types'; -import { calculateActionFromMap } from '../../src'; +} from '../../src/truth-table-generator/minimongo-helper.js'; +import { StateResolveFunctionInput, MongoQuery } from '../../src/types/index.js'; +import { calculateActionFromMap } from '../../src/index.js'; /** * sometimes we think stuff is wrong with minimongo diff --git a/javascript/tsconfig.json b/javascript/tsconfig.json index b10fa0af..af77cf14 100644 --- a/javascript/tsconfig.json +++ b/javascript/tsconfig.json @@ -1,19 +1,20 @@ { "compilerOptions": { + "module": "NodeNext", + "moduleResolution": "NodeNext", + "target": "ES2022", "removeComments": false, "preserveConstEnums": true, "sourceMap": true, "strictNullChecks": true, - "noImplicitAny": false, + "noImplicitAny": true, "strict": true, "noImplicitReturns": true, "noImplicitThis": true, "downlevelIteration": true, - "declaration": true, - "moduleResolution": "node", "esModuleInterop": true, - "target": "ES2017", - "outDir": "./dist/lib", + "declaration": true, + "outDir": "./dist", "lib": [ "es7", "dom" @@ -24,7 +25,8 @@ "tabSize": 2 }, "include": [ - "src" + "src", + "test" ], "exclude": [ "node_modules",