Skip to content

Commit

Permalink
Merge pull request #414 from pubkey/feature/esm
Browse files Browse the repository at this point in the history
esm module
  • Loading branch information
pubkey authored Oct 9, 2023
2 parents 697f648 + e17d24a commit c46e6db
Show file tree
Hide file tree
Showing 38 changed files with 218 additions and 208 deletions.
2 changes: 2 additions & 0 deletions javascript/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/node_modules
/src/logic-generator/logic-map-output/
*.out
/dist/cjs/test/
/dist/esm/test/
2 changes: 2 additions & 0 deletions javascript/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
perf.md
tsconfig.json
tslint.json
dist/esm/test/
dist/cjs/test/
40 changes: 22 additions & 18 deletions javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion javascript/src/actions/action-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> = (_input) => { };

Expand Down
4 changes: 2 additions & 2 deletions javascript/src/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {
ActionName,
ActionFunction
} from '../types';
} from '../types/index.js';

import {
doNothing,
Expand All @@ -20,7 +20,7 @@ import {
unknownAction,
removeFirstInsertFirst,
removeLastInsertLast
} from './action-functions';
} from './action-functions.js';

/**
* all actions ordered by performance-cost
Expand Down
4 changes: 2 additions & 2 deletions javascript/src/bdd/bdd.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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*ÿĀ.';

Expand Down
4 changes: 2 additions & 2 deletions javascript/src/bdd/bdd.template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}';

Expand Down
2 changes: 1 addition & 1 deletion javascript/src/bdd/write-bdd-template.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 2 additions & 0 deletions javascript/src/index.es5.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import * as pkg from './index.js';
module.exports = pkg;
14 changes: 7 additions & 7 deletions javascript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<DocType>(
stateSetToActionMap: StateSetToActionMap,
Expand Down
6 changes: 3 additions & 3 deletions javascript/src/states/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
StateResolveFunction,
StateSet,
StateResolveFunctionInput
} from '../types';
} from '../types/index.js';

import {
hasLimit,
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions javascript/src/states/state-resolver.ts
Original file line number Diff line number Diff line change
@@ -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<any> = (input) => {
return !!input.queryParams.limit;
Expand Down
6 changes: 3 additions & 3 deletions javascript/src/truth-table-generator/binary-state.ts
Original file line number Diff line number Diff line change
@@ -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('');
Expand Down Expand Up @@ -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];
Expand Down
12 changes: 6 additions & 6 deletions javascript/src/truth-table-generator/calculate-bdd-quality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions javascript/src/truth-table-generator/config.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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/', '');



Expand Down
45 changes: 21 additions & 24 deletions javascript/src/truth-table-generator/data-generator.ts
Original file line number Diff line number Diff line change
@@ -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>): 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;
});
}

Expand All @@ -50,16 +47,16 @@ export function randomHumans(amount = 0, partial?: Partial<Human>): 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;
}
Expand All @@ -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();
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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;
}

Expand Down
Loading

0 comments on commit c46e6db

Please sign in to comment.