diff --git a/javascript/.gitignore b/javascript/.gitignore index a8457d44..cf1ccd09 100644 --- a/javascript/.gitignore +++ b/javascript/.gitignore @@ -1,3 +1,5 @@ /node_modules /src/logic-generator/logic-map-output/ *.out +/dist/cjs/test/ +/dist/esm/test/ diff --git a/javascript/.npmignore b/javascript/.npmignore index 08f7c9d1..5cd08ffb 100644 --- a/javascript/.npmignore +++ b/javascript/.npmignore @@ -2,3 +2,5 @@ perf.md tsconfig.json tslint.json +dist/esm/test/ +dist/cjs/test/ diff --git a/javascript/package.json b/javascript/package.json index 3d2f4e38..29489828 100644 --- a/javascript/package.json +++ b/javascript/package.json @@ -14,33 +14,38 @@ "bdd" ], "license": "MIT", - "exports": { - ".": { - "import": "./dist/es/index.js", - "default": "./dist/lib/index.js" - } - }, - "main": "./dist/lib/index.js", - "jsnext:main": "./dist/es/index.js", - "module": "./dist/es/index.js", - "types": "./dist/es/index.d.ts", "sideEffects": false, "repository": { "type": "git", "url": "https://github.com/pubkey/event-reduce" }, + "exports": { + ".": { + "default": { + "types": "./dist/esm/src/index.d.ts", + "import": "./dist/esm/src/index.js", + "default": "./dist/cjs/src/index.es5.js" + } + }, + "./package.json": "./package.json" + }, + "main": "./dist/cjs/src/index.es5.js", + "module": "./dist/esm/src/index.js", + "engines": { + "node": ">=16" + }, + "types": "./dist/esm/src/index.d.ts", "scripts": { "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: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", + "transpile:es": "tsc -p ./ --outDir ./dist/esm && echo '{ \"type\": \"module\" }' > dist/esm/src/package.json && echo '# transpile esm (modules) sucess!'", + "build": "rimraf -r ./dist && npm run transpile && npm run transpile:es", "dry": "npm pack --dry-run", - "test": "mocha -r ts-node/register test/unit/index.test.ts --timeout 50000 --bail", + "test": "npm run build && mocha ./dist/cjs/test/unit/index.test.js --timeout 40000 --bail", "dev": "mocha -r ts-node/register test/unit/index.test.ts --watch --watch-extensions ts", - "generate-truth-table": "ts-node ./src/truth-table-generator/runner.node.ts generate-truth-table && npm run create-bdd", + "generate-truth-table": "ts-node-esm ./src/truth-table-generator/runner.node.ts generate-truth-table && npm run create-bdd", "test-fuzzing": "ts-node ./src/truth-table-generator/runner.node.ts fuzzing", "iterative-fuzzing": "ts-node ./src/truth-table-generator/runner.node.ts iterative-fuzzing", "create-bdd": "ts-node ./src/truth-table-generator/runner.node.ts create-bdd", @@ -49,7 +54,7 @@ "author": "pubkey", "devDependencies": { "@types/deep-equal": "1.0.2", - "@types/faker": "5.5.9", + "@faker-js/faker": "8.1.0", "@types/mocha": "10.0.2", "@types/node": "18.18.4", "array-shuffle": "3.0.0", @@ -58,8 +63,7 @@ "child-process-promise": "2.2.1", "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/actions/action-functions.ts b/javascript/src/actions/action-functions.ts index d537cacb..1fb57b82 100644 --- a/javascript/src/actions/action-functions.ts +++ b/javascript/src/actions/action-functions.ts @@ -2,7 +2,7 @@ import { pushAtSortPosition } from 'array-push-at-sort-position'; -import type { ActionFunction } from '../types'; +import type { ActionFunction } from '../types/index.js'; export const doNothing: ActionFunction = (_input) => { }; diff --git a/javascript/src/actions/index.ts b/javascript/src/actions/index.ts index 9fc4548c..ea89901e 100644 --- a/javascript/src/actions/index.ts +++ b/javascript/src/actions/index.ts @@ -1,7 +1,7 @@ import type { ActionName, ActionFunction -} from '../types'; +} from '../types/index.js'; import { doNothing, @@ -20,7 +20,7 @@ import { unknownAction, removeFirstInsertFirst, removeLastInsertLast -} from './action-functions'; +} from './action-functions.js'; /** * all actions ordered by performance-cost diff --git a/javascript/src/bdd/bdd.generated.ts b/javascript/src/bdd/bdd.generated.ts index 2db01812..0bcc4a39 100644 --- a/javascript/src/bdd/bdd.generated.ts +++ b/javascript/src/bdd/bdd.generated.ts @@ -4,8 +4,8 @@ import { resolveWithSimpleBdd } from 'binary-decision-diagram'; -import type { StateResolveFunctionInput } from '../types'; -import { stateResolveFunctionByIndex } from '../states'; +import type { StateResolveFunctionInput } from '../types/index.js'; +import { stateResolveFunctionByIndex } from '../states/index.js'; export const minimalBddString = '14a2b0c/d1e,f+g5h.i4j*k-l)m(n6ohk1pdf1qef1rin-sjn-ton-ugn-vmn-whn-xkn-yln-zdf5{ef5|wx5}df7~dz7ef7¡bk7¢e{7£g|7¤ry7¥dp7¦gk7§eq7¨gt7©ac7ªmv7«gu7¬nm7­iy7®nw7¯¤s8°«¦8±¬k8²ªm8³®v8´«n8µ¬n8¶vm8·xv8¸mn8¹­j8º®m8»xm8¼­¹3½}~3¾©°3¿¢3À¡£3Ám±3®º3Ãmº3Ä©´3Åb®3Æmµ3Çm»3Èx»3Ékn3Êm¸3˼j6ÌÂm6ÍÆÃ6ÎÈm6Ïnm6ÐÊÇ6ÑÌÎ,ÒÍÐ,ÓÅÉ,Ô²¶,Õ³·,Ö®n,׺»,Ømf9ÙËÁ9Úym9ÛmÏ9ÜÑÒ9Ýz{2Þpq2ß½¿2à¾À2ᥧ2â°¨2ãÄÓ2ä´Ö2åÝn0æÞn0çØÛ0èÙÜ0éßn0êàã0ë²Ô0ì¯Õ0íán0îâä0ï¹×0ðçv/ñåæ/òçë/óèì/ôéí/õêî/öÚy/÷òm(øóï(ùöy(ú÷ø:ûôõ:ümù:ýðñ4þúû4ÿþý*Āüm*ÿĀ.'; diff --git a/javascript/src/bdd/bdd.template.ts b/javascript/src/bdd/bdd.template.ts index 23c8e078..eb0d6a07 100644 --- a/javascript/src/bdd/bdd.template.ts +++ b/javascript/src/bdd/bdd.template.ts @@ -4,8 +4,8 @@ import { resolveWithSimpleBdd } from 'binary-decision-diagram'; -import type { StateResolveFunctionInput } from '../types'; -import { stateResolveFunctionByIndex } from '../states'; +import type { StateResolveFunctionInput } from '../types/index.js'; +import { stateResolveFunctionByIndex } from '../states/index.js'; export const minimalBddString = '${minimalBddString}'; diff --git a/javascript/src/bdd/write-bdd-template.ts b/javascript/src/bdd/write-bdd-template.ts index e53c2dcf..41c2e02e 100644 --- a/javascript/src/bdd/write-bdd-template.ts +++ b/javascript/src/bdd/write-bdd-template.ts @@ -1,5 +1,5 @@ import * as fs from 'fs'; -import * as path from 'path'; +import path from 'path'; export const BDD_TEMPLATE_LOCATION = path.join( __dirname, diff --git a/javascript/src/index.es5.ts b/javascript/src/index.es5.ts new file mode 100644 index 00000000..cd39f88e --- /dev/null +++ b/javascript/src/index.es5.ts @@ -0,0 +1,2 @@ +import * as pkg from './index.js'; +module.exports = pkg; diff --git a/javascript/src/index.ts b/javascript/src/index.ts index 4779b486..19c5b403 100644 --- a/javascript/src/index.ts +++ b/javascript/src/index.ts @@ -7,10 +7,10 @@ import type { StateSet, ActionFunction, StateResolveFunctionInput -} from './types/'; -import { getStateSet } from './states'; -import { actionFunctions, orderedActionList } from './actions'; -import { resolveInput } from './bdd/bdd.generated'; +} from './types/index.js'; +import { getStateSet } from './states/index.js'; +import { actionFunctions, orderedActionList } from './actions/index.js'; +import { resolveInput } from './bdd/bdd.generated.js'; /** * Export as type to ensure we do not @@ -38,10 +38,10 @@ export type { StateSetToActionMap, UNKNOWN, WriteOperation -} from './types'; +} from './types/index.js'; -export * from './states'; -export * from './util'; +export * from './states/index.js'; +export * from './util.js'; export function calculateActionFromMap( stateSetToActionMap: StateSetToActionMap, diff --git a/javascript/src/states/index.ts b/javascript/src/states/index.ts index da676adc..c216c662 100644 --- a/javascript/src/states/index.ts +++ b/javascript/src/states/index.ts @@ -5,7 +5,7 @@ import type { StateResolveFunction, StateSet, StateResolveFunctionInput -} from '../types'; +} from '../types/index.js'; import { hasLimit, @@ -27,9 +27,9 @@ import { isSortedAfterLast, wasMatching, doesMatchNow -} from './state-resolver'; +} from './state-resolver.js'; -export * from './state-resolver'; +export * from './state-resolver.js'; /** * all states ordered by performance-cost diff --git a/javascript/src/states/state-resolver.ts b/javascript/src/states/state-resolver.ts index bdec38ff..2bdc0fe9 100644 --- a/javascript/src/states/state-resolver.ts +++ b/javascript/src/states/state-resolver.ts @@ -1,5 +1,5 @@ -import type { StateResolveFunction } from '../types'; -import { getProperty, lastOfArray, UNKNOWN_VALUE } from '../util'; +import type { StateResolveFunction } from '../types/index.js'; +import { getProperty, lastOfArray, UNKNOWN_VALUE } from '../util.js'; export const hasLimit: StateResolveFunction = (input) => { return !!input.queryParams.limit; diff --git a/javascript/src/truth-table-generator/binary-state.ts b/javascript/src/truth-table-generator/binary-state.ts index 34913a23..cfe7e8c2 100644 --- a/javascript/src/truth-table-generator/binary-state.ts +++ b/javascript/src/truth-table-generator/binary-state.ts @@ -1,5 +1,5 @@ -import type { StateSet } from '../types'; -import { orderedStateList } from '../states'; +import type { StateSet } from '../types/index.js'; +import { orderedStateList } from '../states/index.js'; export const STATE_SET_LENGTH = orderedStateList.length; export const FIRST_STATE_SET: StateSet = new Array(STATE_SET_LENGTH).fill(0).map(() => '0').join(''); @@ -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/calculate-bdd-quality.ts b/javascript/src/truth-table-generator/calculate-bdd-quality.ts index 496348b6..a1596059 100644 --- a/javascript/src/truth-table-generator/calculate-bdd-quality.ts +++ b/javascript/src/truth-table-generator/calculate-bdd-quality.ts @@ -14,22 +14,22 @@ import type { QueryParams, StateName, ActionFunctionInput -} from '../types'; +} from '../types/index.js'; import { orderedStateList, stateResolveFunctions, stateResolveFunctionByIndex -} from '../states'; +} from '../states/index.js'; import { getMinimongoCollection, minimongoUpsert, minimongoFind, getQueryParamsByMongoQuery, applyChangeEvent -} from './minimongo-helper'; -import { randomHuman } from './data-generator'; -import { Human, Procedure } from './types'; -import { flatClone, shuffleArray } from '../util'; +} from './minimongo-helper.js'; +import { randomHuman } from './data-generator.js'; +import type { Human, Procedure } from './types.d.ts'; +import { flatClone, shuffleArray } from '../util.js'; export type PerformanceMeasurement = { [k in StateName]: number // avg runtime in ms diff --git a/javascript/src/truth-table-generator/config.ts b/javascript/src/truth-table-generator/config.ts index cc5c9424..faa6688f 100644 --- a/javascript/src/truth-table-generator/config.ts +++ b/javascript/src/truth-table-generator/config.ts @@ -1,5 +1,5 @@ -import * as path from 'path'; -import type { UNKNOWN } from '../types'; +import type { UNKNOWN } from '../types/index.js'; +import path from 'path'; export const OUTPUT_FOLDER_PATH = path.join( __dirname, @@ -9,17 +9,17 @@ export const OUTPUT_FOLDER_PATH = path.join( export const OUTPUT_TRUTH_TABLE_PATH = path.join( OUTPUT_FOLDER_PATH, 'truth-table.json' -); +).replace('dist/cjs/', ''); export const FUZZING_QUERIES_PATH = path.join( OUTPUT_FOLDER_PATH, 'queries.json' -); +).replace('dist/cjs/', ''); export const FUZZING_PROCEDURES_PATH = path.join( OUTPUT_FOLDER_PATH, 'procedures.json' -); +).replace('dist/cjs/', ''); diff --git a/javascript/src/truth-table-generator/data-generator.ts b/javascript/src/truth-table-generator/data-generator.ts index bfe0bc92..8e9a8e18 100644 --- a/javascript/src/truth-table-generator/data-generator.ts +++ b/javascript/src/truth-table-generator/data-generator.ts @@ -1,40 +1,37 @@ -import Faker from 'faker'; +import { faker } from '@faker-js/faker'; -import { - datatype as fakerDatatype -} from 'faker'; import type { Human, Procedure -} from './types'; +} from './types.js'; import type { ChangeEvent -} from '../../src/types'; +} from '../../src/types/index.js'; import { getMinimongoCollection, minimongoFind, applyChangeEvent -} from './minimongo-helper'; -import { UNKNOWN_VALUE } from './config'; -import { randomOfArray } from '../util'; +} from './minimongo-helper.js'; +import { UNKNOWN_VALUE } from './config.js'; +import { randomOfArray } from '../util.js'; /** * Set a seed to ensure we create deterministic and testable * test data. */ -Faker.seed(2345); +faker.seed(2345); export function randomHuman(partial?: Partial): Human { const ret: Human = { - _id: Faker.random.alphaNumeric(10), - name: Faker.name.firstName().toLowerCase(), - gender: fakerDatatype.boolean() ? 'f' : 'm', - age: fakerDatatype.number({ min: 1, max: 100 }) + _id: (faker.number.int(1000) + '').padStart(5, '0'), + name: faker.person.firstName().toLowerCase(), + gender: faker.datatype.boolean() ? 'f' : 'm', + age: faker.number.int({ min: 1, max: 100 }) }; if (partial) { Object.entries(partial).forEach(([k, v]) => { - ret[k] = v; + (ret as any)[k] = v; }); } @@ -50,16 +47,16 @@ export function randomHumans(amount = 0, partial?: Partial): Human[] { const keyToChangeFn = { - 1: (i: Human) => i.name = Faker.name.firstName().toLowerCase(), - 2: (i: Human) => i.gender = fakerDatatype.boolean() ? 'f' : 'm', - 3: (i: Human) => i.age = fakerDatatype.number({ min: 1, max: 100 }) + 1: (i: Human) => i.name = faker.person.firstName().toLowerCase(), + 2: (i: Human) => i.gender = faker.datatype.boolean() ? 'f' : 'm', + 3: (i: Human) => i.age = faker.number.int({ min: 1, max: 100 }) }; export function randomChangeHuman(input: Human): Human { const cloned: Human = Object.assign({}, input); - const field = fakerDatatype.number({ min: 1, max: 3 }); - keyToChangeFn[field](cloned); + const field = faker.number.int({ min: 1, max: 3 }); + (keyToChangeFn as any)[field](cloned); return cloned; } @@ -84,7 +81,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(); @@ -96,7 +93,7 @@ export function randomChangeEvent( }; break; case 'UPDATE': - const oldDoc = Faker.random.arrayElement(allDocs); + const oldDoc = faker.helpers.arrayElement(allDocs); const changedDoc = randomChangeHuman(oldDoc); ret = { operation, @@ -106,7 +103,7 @@ export function randomChangeEvent( }; break; case 'DELETE': - const docToDelete: Human = Faker.random.arrayElement(allDocs); + const docToDelete: Human = faker.helpers.arrayElement(allDocs); ret = { operation, id: docToDelete._id, @@ -117,7 +114,7 @@ export function randomChangeEvent( } // randomly set previous to UNKNOWN - if (ret.previous && fakerDatatype.boolean()) { + if (ret.previous && faker.datatype.boolean()) { ret.previous = UNKNOWN_VALUE; } diff --git a/javascript/src/truth-table-generator/fuzzing.ts b/javascript/src/truth-table-generator/fuzzing.ts index 2562f871..4c98db8c 100644 --- a/javascript/src/truth-table-generator/fuzzing.ts +++ b/javascript/src/truth-table-generator/fuzzing.ts @@ -4,23 +4,23 @@ import type { ChangeEvent, ActionName, MongoQuery -} from '../types'; +} from '../types/index.js'; import type { Procedure, StateActionIdMap, Human -} from './types'; -import { randomQuery } from './queries'; -import { getRandomChangeEvents } from './data-generator'; +} from './types.js'; +import { randomQuery } from './queries.js'; +import { getRandomChangeEvents } from './data-generator.js'; import { getMinimongoCollection, getQueryParamsByMongoQuery, minimongoFind, applyChangeEvent -} from './minimongo-helper'; -import { getStateSet } from '../states'; -import { doesActionWork } from '.'; -import { orderedActionList } from '../actions'; +} from './minimongo-helper.js'; +import { getStateSet } from '../states/index.js'; +import { orderedActionList } from '../actions/index.js'; +import { doesActionWork } from './index.js'; export type FuzzingReturn = { ok: boolean, diff --git a/javascript/src/truth-table-generator/index.ts b/javascript/src/truth-table-generator/index.ts index fb954dec..c2fbd898 100644 --- a/javascript/src/truth-table-generator/index.ts +++ b/javascript/src/truth-table-generator/index.ts @@ -4,22 +4,22 @@ import type { StateActionIdMap, Procedure, Human -} from './types'; +} from './types.js'; import type { QueryParams, ActionName, ActionFunctionInput, MongoQuery -} from '../types'; +} from '../types/index.js'; import { getMinimongoCollection, minimongoFind, applyChangeEvent, getQueryParamsByMongoQuery -} from './minimongo-helper'; -import { runAction } from '../'; -import { orderedActionList } from '../actions'; -import { getStateSet } from '../states'; +} from './minimongo-helper.js'; +import { runAction } from '../index.js'; +import { orderedActionList } from '../actions/index.js'; +import { getStateSet } from '../states/index.js'; export interface GenerateTruthTableInput { queries: MongoQuery[]; diff --git a/javascript/src/truth-table-generator/minimongo-helper.ts b/javascript/src/truth-table-generator/minimongo-helper.ts index 1c439c7e..94ec6f2c 100644 --- a/javascript/src/truth-table-generator/minimongo-helper.ts +++ b/javascript/src/truth-table-generator/minimongo-helper.ts @@ -5,23 +5,23 @@ 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'; -import type { Human } from './types'; +import type { Human } from './types.js'; import type { ChangeEvent, QueryParams, MongoQuery, DeterministicSortComparator -} from '../types'; -import { getSortFieldsOfQuery } from '../util'; +} from '../types/index.js'; +import { getSortFieldsOfQuery } from '../util.js'; export function getMinimongoCollection(): MinimongoCollection { const db: MemoryDb = new MemoryDb(); diff --git a/javascript/src/truth-table-generator/procedures.ts b/javascript/src/truth-table-generator/procedures.ts index 38d78ff3..65685e64 100644 --- a/javascript/src/truth-table-generator/procedures.ts +++ b/javascript/src/truth-table-generator/procedures.ts @@ -1,14 +1,14 @@ -import Faker, { datatype as fakerDatatype } from 'faker'; +import { faker } from '@faker-js/faker'; -import type { ChangeEvent } from '../types'; -import type { Human, Procedure } from './types'; +import type { ChangeEvent } from '../types/index.js'; +import type { Human, Procedure } from './types.js'; import { randomHumans, randomChangeHuman -} from './data-generator'; -import { UNKNOWN_VALUE } from './config'; -import { compileSort } from './minimongo-helper'; -import { ensureNotFalsy, flatClone } from '../util'; +} from './data-generator.js'; +import { UNKNOWN_VALUE } from './config.js'; +import { compileSort } from './minimongo-helper.js'; +import { ensureNotFalsy, flatClone } from '../util.js'; export function insertChangeAndCleanup( unknownPrevious: boolean = false @@ -27,7 +27,7 @@ export function insertChangeAndCleanup( ret.push(insertEvent); // do a random update - const updateDoc = Faker.random.arrayElement(docs); + const updateDoc = faker.helpers.arrayElement(docs); const after = randomChangeHuman(updateDoc); docs = docs.filter(d => d._id !== updateDoc._id); @@ -43,7 +43,7 @@ export function insertChangeAndCleanup( }); // update all to big age - const shuffled = Faker.helpers.shuffle(docs); + const shuffled = faker.helpers.shuffle(docs); while (shuffled.length > 0) { const changeMe = shuffled.pop() as Human; const changeMeAfter = randomChangeHuman(changeMe); @@ -51,7 +51,7 @@ export function insertChangeAndCleanup( docs = docs.filter(d => d._id !== changeMe._id); docs.push(changeMeAfter); - changeMeAfter.age = 1000 + fakerDatatype.number({ + changeMeAfter.age = 1000 + faker.number.int({ min: 10, max: 100 }); @@ -65,7 +65,7 @@ export function insertChangeAndCleanup( } // cleanup - const shuffled2 = Faker.helpers.shuffle(docs); + const shuffled2 = faker.helpers.shuffle(docs); while (shuffled2.length > 0) { const deleteMe = shuffled2.pop() as Human; const deleteEvent: ChangeEvent = { diff --git a/javascript/src/truth-table-generator/queries.ts b/javascript/src/truth-table-generator/queries.ts index 30d924f3..61699aee 100644 --- a/javascript/src/truth-table-generator/queries.ts +++ b/javascript/src/truth-table-generator/queries.ts @@ -5,8 +5,8 @@ import { import type { MongoQuery -} from '../types'; -import { randomOfArray } from '../util'; +} from '../types/index.js'; +import { randomOfArray } from '../util.js'; export const DEFAULT_EXAMPLE_QUERY: MongoQuery = { selector: {}, diff --git a/javascript/src/truth-table-generator/runner.node.ts b/javascript/src/truth-table-generator/runner.node.ts index 0fa414ab..111bcc41 100644 --- a/javascript/src/truth-table-generator/runner.node.ts +++ b/javascript/src/truth-table-generator/runner.node.ts @@ -1,5 +1,5 @@ import * as fs from 'fs'; -import Faker from 'faker'; +import { faker } from '@faker-js/faker'; import { createBddFromTruthTable, TruthTable, @@ -10,30 +10,30 @@ import { RootNode } from 'binary-decision-diagram'; -import type { StateActionIdMap } from './types'; +import type { StateActionIdMap } from './types.js'; import { OUTPUT_FOLDER_PATH, OUTPUT_TRUTH_TABLE_PATH -} from './config'; -import { getQueryVariations } from './queries'; -import { getTestProcedures } from './procedures'; -import { generateTruthTable } from './'; +} from './config.js'; +import { getQueryVariations } from './queries.js'; +import { getTestProcedures } from './procedures.js'; +import { generateTruthTable } from './index.js'; import { mapToObject, objectToMap, roundToTwoDecimals -} from '../util'; +} from '../util.js'; import { readJsonFile, writeJsonFile -} from './util'; -import { fuzzing } from './fuzzing'; -import { writeBddTemplate } from '../bdd/write-bdd-template'; +} from './util.js'; +import { fuzzing } from './fuzzing.js'; +import { writeBddTemplate } from '../bdd/write-bdd-template.js'; import { measurePerformanceOfStateFunctions, getBetterBdd, QUALITY_BY_BDD_CACHE -} from './calculate-bdd-quality'; +} from './calculate-bdd-quality.js'; /** * sort object attributes @@ -110,7 +110,7 @@ async function run() { * When we restart the generating processes, * we do not want up to run with the same dataset again. */ - Faker.seed(new Date().getTime()); + faker.seed(new Date().getTime()); const truthTable: StateActionIdMap = objectToMap( readJsonFile(OUTPUT_TRUTH_TABLE_PATH) diff --git a/javascript/src/truth-table-generator/types.d.ts b/javascript/src/truth-table-generator/types.d.ts index 60ca3fd3..a796aa3c 100644 --- a/javascript/src/truth-table-generator/types.d.ts +++ b/javascript/src/truth-table-generator/types.d.ts @@ -1,4 +1,4 @@ -import type { ChangeEvent, StateSet } from '../types'; +import type { ChangeEvent, StateSet } from '../types/index.js'; export interface Human { _id: string; // primary diff --git a/javascript/src/types/change-event.ts b/javascript/src/types/change-event.ts index 2ccba113..cba71f5a 100644 --- a/javascript/src/types/change-event.ts +++ b/javascript/src/types/change-event.ts @@ -1,7 +1,7 @@ import type { WriteOperation, UNKNOWN -} from './index'; +} from './index.js'; export interface ChangeEventBase { operation: WriteOperation; diff --git a/javascript/src/types/index.ts b/javascript/src/types/index.ts index 4c2d9b67..bd50a64c 100644 --- a/javascript/src/types/index.ts +++ b/javascript/src/types/index.ts @@ -1,6 +1,6 @@ -import { ChangeEvent } from './change-event'; -export * from './change-event'; -export * from './mongo'; +import { ChangeEvent } from './change-event.js'; +export * from './change-event.js'; +export * from './mongo.js'; export type WriteOperation = 'INSERT' | 'UPDATE' | 'DELETE'; export type UNKNOWN = 'UNKNOWN'; diff --git a/javascript/src/util.ts b/javascript/src/util.ts index a7e8267d..b5f65bc6 100644 --- a/javascript/src/util.ts +++ b/javascript/src/util.ts @@ -3,7 +3,7 @@ import type { UNKNOWN, MongoQuery, DeepReadonlyObject -} from './types'; +} from './types/index.js'; export const UNKNOWN_VALUE: UNKNOWN = 'UNKNOWN'; @@ -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..ccdeeff7 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'; -import deepEqual = require('deep-equal'); -import { orderedActionList } from '../../src/actions'; +} 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 from 'deep-equal'; +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..d6e50e8e 100644 --- a/javascript/test/unit/minimongo.test.ts +++ b/javascript/test/unit/minimongo.test.ts @@ -1,17 +1,18 @@ import * as assert from 'assert'; import { - randomHuman, randomHumans -} from '../../src/truth-table-generator/data-generator'; + randomHuman, + randomHumans +} 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 @@ -38,7 +39,7 @@ describe('minimongo.test.ts', () => { collection, query ); - assert.ok(results[0].age < results[1].age); + assert.ok(results[0].age <= results[1].age); // change one const changeHuman = clone(results[2]); @@ -83,6 +84,7 @@ describe('minimongo.test.ts', () => { collection, query ); + assert.deepStrictEqual(sortedDocs, results); }); }); 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..c8076498 100644 --- a/javascript/tsconfig.json +++ b/javascript/tsconfig.json @@ -1,19 +1,20 @@ { "compilerOptions": { + "moduleResolution": "node", + "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, + "resolveJsonModule": true, + "outDir": "./dist/cjs", "lib": [ "es7", "dom" @@ -24,7 +25,8 @@ "tabSize": 2 }, "include": [ - "src" + "src", + "test" ], "exclude": [ "node_modules",