@natlibfi/melinda-rest-api-commons 6.1.0-alpha.0 → 6.2.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/.github/workflows/melinda-node-tests-and-publish.yml +4 -2
  2. package/README.md +211 -14
  3. package/dist/amqp.d.ts +41 -0
  4. package/dist/amqp.d.ts.map +1 -0
  5. package/dist/amqp.js +251 -235
  6. package/dist/amqp.js.map +1 -7
  7. package/dist/constants.d.ts +49 -0
  8. package/dist/constants.d.ts.map +1 -0
  9. package/dist/constants.js +38 -38
  10. package/dist/constants.js.map +1 -7
  11. package/dist/helpers/conversion.d.ts +8 -0
  12. package/dist/helpers/conversion.d.ts.map +1 -0
  13. package/dist/helpers/conversion.js +70 -64
  14. package/dist/helpers/conversion.js.map +1 -7
  15. package/dist/helpers/fix-constants.d.ts +76 -0
  16. package/dist/helpers/fix-constants.d.ts.map +1 -0
  17. package/dist/helpers/fix-constants.js +41 -41
  18. package/dist/helpers/fix-constants.js.map +1 -7
  19. package/dist/helpers/fix-handle-tempurns.d.ts +3 -0
  20. package/dist/helpers/fix-handle-tempurns.d.ts.map +1 -0
  21. package/dist/helpers/fix-handle-tempurns.js +73 -71
  22. package/dist/helpers/fix-handle-tempurns.js.map +1 -7
  23. package/dist/helpers/fix-strip-f884s.d.ts +10 -0
  24. package/dist/helpers/fix-strip-f884s.d.ts.map +1 -0
  25. package/dist/helpers/fix-strip-f884s.js +161 -163
  26. package/dist/helpers/fix-strip-f884s.js.map +1 -7
  27. package/dist/helpers/fix.d.ts +6 -0
  28. package/dist/helpers/fix.d.ts.map +1 -0
  29. package/dist/helpers/fix.js +133 -121
  30. package/dist/helpers/fix.js.map +1 -7
  31. package/dist/helpers/validation.d.ts +9 -0
  32. package/dist/helpers/validation.d.ts.map +1 -0
  33. package/dist/helpers/validation.js +14 -16
  34. package/dist/helpers/validation.js.map +1 -7
  35. package/dist/index.d.ts +13 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +1 -1
  38. package/dist/index.js.map +1 -7
  39. package/dist/mongo.d.ts +165 -0
  40. package/dist/mongo.d.ts.map +1 -0
  41. package/dist/mongo.js +595 -547
  42. package/dist/mongo.js.map +1 -7
  43. package/dist/mongoError.d.ts +2 -0
  44. package/dist/mongoError.d.ts.map +1 -0
  45. package/dist/mongoError.js +19 -0
  46. package/dist/mongoError.js.map +1 -0
  47. package/dist/mongoLog.d.ts +50 -0
  48. package/dist/mongoLog.d.ts.map +1 -0
  49. package/dist/mongoLog.js +274 -242
  50. package/dist/mongoLog.js.map +1 -7
  51. package/dist/utils.d.ts +36 -0
  52. package/dist/utils.d.ts.map +1 -0
  53. package/dist/utils.js +112 -110
  54. package/dist/utils.js.map +1 -7
  55. package/eslint.config.ts +66 -0
  56. package/package.json +17 -11
  57. package/{tests/amqp-error-branches.test.js → test/amqp-error-branches.test.ts} +135 -61
  58. package/{tests/amqp.healthtest.js → test/amqp.healthtest.ts} +19 -11
  59. package/{tests/amqp.tests.localtest.js → test/amqp.tests.localtest.ts} +54 -35
  60. package/{tests/helpers/conversion.test.js → test/helpers/conversion.test.ts} +26 -14
  61. package/{tests/helpers/fix-edge.test.js → test/helpers/fix-edge.test.ts} +16 -12
  62. package/{tests/helpers/fix.test.js → test/helpers/fix.test.ts} +14 -8
  63. package/{tests/helpers/validation.test.js → test/helpers/validation.test.ts} +7 -6
  64. package/{tests/mongo-add-blob-size.test.js → test/mongo-add-blob-size.test.ts} +14 -15
  65. package/{tests/mongo-check-and-check-state.test.js → test/mongo-check-and-check-state.test.ts} +6 -8
  66. package/{tests/mongo-check-and-set-import-job-state.test.js → test/mongo-check-and-set-import-job-state.test.ts} +6 -9
  67. package/{tests/mongo-check-timeout.test.js → test/mongo-check-timeout.test.ts} +6 -9
  68. package/{tests/mongo-create-bulk.test.js → test/mongo-create-bulk.test.ts} +6 -7
  69. package/{tests/mongo-create-prio.test.js → test/mongo-create-prio.test.ts} +6 -6
  70. package/{tests/mongo-error-branches.test.js → test/mongo-error-branches.test.ts} +166 -65
  71. package/{tests/mongo-get-one.test.js → test/mongo-get-one.test.ts} +6 -6
  72. package/{tests/mongo-get-stream.test.js → test/mongo-get-stream.test.ts} +6 -8
  73. package/{tests/mongo-push-ids.test.js → test/mongo-push-ids.test.ts} +6 -6
  74. package/{tests/mongo-push-messages.test.js → test/mongo-push-messages.test.ts} +6 -6
  75. package/{tests/mongo-query-by-id.test.js → test/mongo-query-by-id.test.ts} +6 -9
  76. package/{tests/mongo-query.test.js → test/mongo-query.test.ts} +6 -7
  77. package/{tests/mongo-read-content.test.js → test/mongo-read-content.test.ts} +6 -9
  78. package/{tests/mongo-remove.test.js → test/mongo-remove.test.ts} +6 -8
  79. package/{tests/mongo-set-blob-size.test.js → test/mongo-set-blob-size.test.ts} +6 -6
  80. package/{tests/mongo-set-import-job-state.test.js → test/mongo-set-import-job-state.test.ts} +6 -6
  81. package/{tests/mongo-set-operation.test.js → test/mongo-set-operation.test.ts} +6 -6
  82. package/{tests/mongo-set-operations.test.js → test/mongo-set-operations.test.ts} +6 -6
  83. package/{tests/mongo-set-state.test.js → test/mongo-set-state.test.ts} +6 -6
  84. package/{tests/mongoLog-protect.test.js → test/mongoLog-protect.test.ts} +18 -17
  85. package/{tests/mongoLog.test.js → test/mongoLog.test.ts} +8 -8
  86. package/{tests/testUtils.js → test/testUtils.ts} +49 -15
  87. package/{tests/utils.test.js → test/utils.test.ts} +5 -5
  88. package/tsconfig.json +62 -0
  89. package/tsconfig.test.json +17 -0
  90. package/dist/helpers/fix-utils.js +0 -39
  91. package/dist/helpers/fix-utils.js.map +0 -7
  92. package/eslint.config.js +0 -53
@@ -4,10 +4,10 @@ import mongoFixturesFactory from '@natlibfi/fixura-mongo';
4
4
  import generateTests from '@natlibfi/fixugen';
5
5
  import createDebugLogger from 'debug';
6
6
  //import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils.js';
7
- import {getMongoOperator, handleError, compareToDbEntry, formatQueueItem} from './testUtils.js';
7
+ import {getMongoOperator, handleError, compareToDbEntry, formatQueueItem} from './testUtils.ts';
8
8
 
9
9
 
10
- let mongoFixtures; // eslint-disable-line functional/no-let
10
+ let mongoFixtures: any;
11
11
  const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:query-by-id:test');
12
12
 
13
13
  generateTests({
@@ -41,15 +41,14 @@ generateTests({
41
41
 
42
42
  async function initMongofixtures() {
43
43
  mongoFixtures = await mongoFixturesFactory({
44
- recurse: false,
45
44
  rootPath: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'query-by-id'],
46
45
  gridFS: {bucketName: 'foobar'},
47
46
  useObjectId: true
48
47
  });
49
48
  }
50
49
 
51
- // eslint-disable-next-line max-statements
52
- async function callback({
50
+ async function callback(callbackParams: Record<string, any>) {
51
+ const {
53
52
  getFixture,
54
53
  functionName,
55
54
  params,
@@ -61,14 +60,14 @@ async function callback({
61
60
  expectedOpResult = undefined,
62
61
  updateStateBeforeTest = undefined,
63
62
  resultIndex = undefined
64
- }) {
63
+ } = callbackParams;
65
64
 
66
65
  const mongoOperator = await getMongoOperator(mongoFixtures);
67
66
  const expectedResult = await getFixture('expectedResult.json');
68
67
 
69
68
  await doPreFillDb(preFillDb);
70
69
 
71
- async function doPreFillDb(preFillDb) {
70
+ async function doPreFillDb(preFillDb: boolean) {
72
71
  if (preFillDb) {
73
72
  await mongoFixtures.populate(getFixture('dbContents.json'));
74
73
  return;
@@ -82,14 +81,12 @@ async function callback({
82
81
  debug(`queryById`);
83
82
  debug(JSON.stringify(params));
84
83
  //{correlationId, checkModTime = false}
85
- // eslint-disable-next-line functional/no-conditional-statements
86
84
  if (updateStateBeforeTest && params.correlationId) {
87
85
  debug(`setState to reset modificationTime`);
88
86
  await mongoOperator.setState({correlationId: params.correlationId, state: updateStateBeforeTest});
89
87
  }
90
88
  const opResult = await mongoOperator.queryById(params);
91
89
  debug(`queryById result: ${JSON.stringify(opResult)} (it should be: ${JSON.stringify(expectedOpResult)})}`);
92
- // eslint-disable-next-line functional/no-conditional-statements
93
90
  if (expectedOpResult !== undefined) {
94
91
  assert.deepStrictEqual(formatQueueItem(opResult), formatQueueItem(expectedOpResult));
95
92
  }
@@ -4,9 +4,9 @@ import mongoFixturesFactory from '@natlibfi/fixura-mongo';
4
4
  import generateTests from '@natlibfi/fixugen';
5
5
  import createDebugLogger from 'debug';
6
6
  //import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils.js';
7
- import {getMongoOperator, handleError} from './testUtils.js';
7
+ import {getMongoOperator, handleError} from './testUtils.ts';
8
8
 
9
- let mongoFixtures; // eslint-disable-line functional/no-let
9
+ let mongoFixtures: any;
10
10
  const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:test');
11
11
 
12
12
  generateTests({
@@ -40,14 +40,14 @@ generateTests({
40
40
 
41
41
  async function initMongofixtures() {
42
42
  mongoFixtures = await mongoFixturesFactory({
43
- recurse: false,
44
43
  rootPath: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'query'],
45
44
  gridFS: {bucketName: 'foobar'},
46
45
  useObjectId: true
47
46
  });
48
47
  }
49
48
 
50
- async function callback({
49
+ async function callback(callbackParams: Record<string, any>) {
50
+ const {
51
51
  getFixture,
52
52
  functionName,
53
53
  params,
@@ -56,14 +56,14 @@ async function callback({
56
56
  expectedErrorMessage = '',
57
57
  expectedErrorStatus = '',
58
58
  expectedOpResult = undefined
59
- }) {
59
+ } = callbackParams;
60
60
 
61
61
  const mongoOperator = await getMongoOperator(mongoFixtures);
62
62
  //const expectedResult = await getFixture('expectedResult.json');
63
63
 
64
64
  await doPreFillDb(preFillDb);
65
65
 
66
- async function doPreFillDb(preFillDb) {
66
+ async function doPreFillDb(preFillDb: boolean) {
67
67
  if (preFillDb) {
68
68
  await mongoFixtures.populate(getFixture('dbContents.json'));
69
69
  return;
@@ -83,7 +83,6 @@ async function callback({
83
83
  debug(`${JSON.stringify(params.showParams)}`);
84
84
  const opResult = await mongoOperator.query(params.params, params.showParams);
85
85
  debug(`query result: ${JSON.stringify(opResult)} (it should be: ${JSON.stringify(expectedOpResult)})}`);
86
- // eslint-disable-next-line functional/no-conditional-statements
87
86
  if (expectedOpResult !== undefined) {
88
87
  assert.deepStrictEqual(opResult, expectedOpResult);
89
88
  }
@@ -4,10 +4,10 @@ import mongoFixturesFactory from '@natlibfi/fixura-mongo';
4
4
  import generateTests from '@natlibfi/fixugen';
5
5
  import createDebugLogger from 'debug';
6
6
  //import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils.js';
7
- import {getMongoOperator, handleError, streamToString} from './testUtils.js';
7
+ import {getMongoOperator, handleError, streamToString} from './testUtils.ts';
8
8
 
9
9
 
10
- let mongoFixtures; // eslint-disable-line functional/no-let
10
+ let mongoFixtures: any;
11
11
  const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:read-content:test');
12
12
 
13
13
  generateTests({
@@ -41,15 +41,14 @@ generateTests({
41
41
 
42
42
  async function initMongofixtures() {
43
43
  mongoFixtures = await mongoFixturesFactory({
44
- recurse: false,
45
44
  rootPath: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'read-content'],
46
45
  gridFS: {bucketName: 'foobar'},
47
46
  useObjectId: true
48
47
  });
49
48
  }
50
49
 
51
- // eslint-disable-next-line max-statements
52
- async function callback({
50
+ async function callback(callbackParams: Record<string, any>) {
51
+ const {
53
52
  getFixture,
54
53
  functionName,
55
54
  params,
@@ -59,14 +58,14 @@ async function callback({
59
58
  expectedErrorStatus = '',
60
59
  contentStream = false,
61
60
  createBulkParams = undefined
62
- }) {
61
+ } = callbackParams;
63
62
 
64
63
  const mongoOperator = await getMongoOperator(mongoFixtures);
65
64
  //const expectedResult = await getFixture('expectedResult.json');
66
65
 
67
66
  await doPreFillDb(preFillDb);
68
67
 
69
- async function doPreFillDb(preFillDb) {
68
+ async function doPreFillDb(preFillDb: boolean) {
70
69
  if (preFillDb) {
71
70
  await mongoFixtures.populate(getFixture('dbContents.json'));
72
71
  // optional gridFSFiles.json uploads GridFS files (filename -> content)
@@ -91,7 +90,6 @@ async function callback({
91
90
  debug(JSON.stringify(params));
92
91
  //correlationId
93
92
 
94
- // eslint-disable-next-line functional/no-conditional-statements
95
93
  if (createBulkParams) {
96
94
  const stream = contentStream ? await getFixture({components: ['contentStream'], reader: READERS.STREAM}) : createBulkParams.stream;
97
95
  //debug(stream);
@@ -103,7 +101,6 @@ async function callback({
103
101
  const opResult = await mongoOperator.readContent(params);
104
102
  const opResultString = await streamToString(opResult.readStream);
105
103
 
106
- // eslint-disable-next-line functional/no-conditional-statements
107
104
  if (createBulkParams && createBulkParams.contentType) {
108
105
  assert.equal(opResult.contentType, createBulkParams.contentType);
109
106
  }
@@ -4,10 +4,10 @@ import mongoFixturesFactory from '@natlibfi/fixura-mongo';
4
4
  import generateTests from '@natlibfi/fixugen';
5
5
  import createDebugLogger from 'debug';
6
6
  //import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils.js';
7
- import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.js';
7
+ import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.ts';
8
8
 
9
9
 
10
- let mongoFixtures; // eslint-disable-line functional/no-let
10
+ let mongoFixtures: any;
11
11
  const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:remove:test');
12
12
 
13
13
  generateTests({
@@ -41,15 +41,14 @@ generateTests({
41
41
 
42
42
  async function initMongofixtures() {
43
43
  mongoFixtures = await mongoFixturesFactory({
44
- recurse: false,
45
44
  rootPath: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'remove'],
46
45
  gridFS: {bucketName: 'foobar'},
47
46
  useObjectId: true
48
47
  });
49
48
  }
50
49
 
51
- // eslint-disable-next-line max-statements
52
- async function callback({
50
+ async function callback(callbackParams: Record<string, any>) {
51
+ const {
53
52
  getFixture,
54
53
  functionName,
55
54
  params,
@@ -62,14 +61,14 @@ async function callback({
62
61
  createBulkParams = undefined,
63
62
  expectedFileCount = undefined,
64
63
  expectUndefined = undefined
65
- }) {
64
+ } = callbackParams;
66
65
 
67
66
  const mongoOperator = await getMongoOperator(mongoFixtures);
68
67
  const expectedResult = await getFixture('expectedResult.json');
69
68
 
70
69
  await doPreFillDb(preFillDb);
71
70
 
72
- async function doPreFillDb(preFillDb) {
71
+ async function doPreFillDb(preFillDb: boolean) {
73
72
  if (preFillDb) {
74
73
  await mongoFixtures.populate(getFixture('dbContents.json'));
75
74
  return;
@@ -85,7 +84,6 @@ async function callback({
85
84
  debug(JSON.stringify(params));
86
85
  //params: {correlationId}
87
86
 
88
- // eslint-disable-next-line functional/no-conditional-statements
89
87
  if (createBulkParams) {
90
88
  const stream = contentStream ? await getFixture({components: ['contentStream'], reader: READERS.STREAM}) : createBulkParams.stream;
91
89
  //debug(stream);
@@ -4,9 +4,9 @@ import mongoFixturesFactory from '@natlibfi/fixura-mongo';
4
4
  import generateTests from '@natlibfi/fixugen';
5
5
  import createDebugLogger from 'debug';
6
6
  //import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils.js';
7
- import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.js';
7
+ import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.ts';
8
8
 
9
- let mongoFixtures; // eslint-disable-line functional/no-let
9
+ let mongoFixtures: any;
10
10
  const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:set-blob-size:test');
11
11
 
12
12
  generateTests({
@@ -40,14 +40,14 @@ generateTests({
40
40
 
41
41
  async function initMongofixtures() {
42
42
  mongoFixtures = await mongoFixturesFactory({
43
- recurse: false,
44
43
  rootPath: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'set-blob-size'],
45
44
  gridFS: {bucketName: 'foobar'},
46
45
  useObjectId: true
47
46
  });
48
47
  }
49
48
 
50
- async function callback({
49
+ async function callback(callbackParams: Record<string, any>) {
50
+ const {
51
51
  getFixture,
52
52
  functionName,
53
53
  params,
@@ -56,14 +56,14 @@ async function callback({
56
56
  expectedToThrow = false,
57
57
  expectedErrorMessage = '',
58
58
  expectedErrorStatus = ''
59
- }) {
59
+ } = callbackParams;
60
60
 
61
61
  const mongoOperator = await getMongoOperator(mongoFixtures);
62
62
  const expectedResult = await getFixture('expectedResult.json');
63
63
 
64
64
  await doPreFillDb(preFillDb);
65
65
 
66
- async function doPreFillDb(preFillDb) {
66
+ async function doPreFillDb(preFillDb: boolean) {
67
67
  if (preFillDb) {
68
68
  await mongoFixtures.populate(getFixture('dbContents.json'));
69
69
  return;
@@ -4,10 +4,10 @@ import mongoFixturesFactory from '@natlibfi/fixura-mongo';
4
4
  import generateTests from '@natlibfi/fixugen';
5
5
  import createDebugLogger from 'debug';
6
6
  //import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils.js';
7
- import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.js';
7
+ import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.ts';
8
8
 
9
9
 
10
- let mongoFixtures; // eslint-disable-line functional/no-let
10
+ let mongoFixtures: any;
11
11
  const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:set-import-job-state:test');
12
12
 
13
13
  generateTests({
@@ -41,14 +41,14 @@ generateTests({
41
41
 
42
42
  async function initMongofixtures() {
43
43
  mongoFixtures = await mongoFixturesFactory({
44
- recurse: false,
45
44
  rootPath: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'set-import-job-state'],
46
45
  gridFS: {bucketName: 'foobar'},
47
46
  useObjectId: true
48
47
  });
49
48
  }
50
49
 
51
- async function callback({
50
+ async function callback(callbackParams: Record<string, any>) {
51
+ const {
52
52
  getFixture,
53
53
  functionName,
54
54
  params,
@@ -57,14 +57,14 @@ async function callback({
57
57
  expectedToThrow = false,
58
58
  expectedErrorMessage = '',
59
59
  expectedErrorStatus = ''
60
- }) {
60
+ } = callbackParams;
61
61
 
62
62
  const mongoOperator = await getMongoOperator(mongoFixtures);
63
63
  const expectedResult = await getFixture('expectedResult.json');
64
64
 
65
65
  await doPreFillDb(preFillDb);
66
66
 
67
- async function doPreFillDb(preFillDb) {
67
+ async function doPreFillDb(preFillDb: boolean) {
68
68
  if (preFillDb) {
69
69
  await mongoFixtures.populate(getFixture('dbContents.json'));
70
70
  return;
@@ -4,9 +4,9 @@ import mongoFixturesFactory from '@natlibfi/fixura-mongo';
4
4
  import generateTests from '@natlibfi/fixugen';
5
5
  import createDebugLogger from 'debug';
6
6
  //import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils.js';
7
- import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.js';
7
+ import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.ts';
8
8
 
9
- let mongoFixtures; // eslint-disable-line functional/no-let
9
+ let mongoFixtures: any;
10
10
  const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:set-operation:test');
11
11
 
12
12
  generateTests({
@@ -40,14 +40,14 @@ generateTests({
40
40
 
41
41
  async function initMongofixtures() {
42
42
  mongoFixtures = await mongoFixturesFactory({
43
- recurse: false,
44
43
  rootPath: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'set-operation'],
45
44
  gridFS: {bucketName: 'foobar'},
46
45
  useObjectId: true
47
46
  });
48
47
  }
49
48
 
50
- async function callback({
49
+ async function callback(callbackParams: Record<string, any>) {
50
+ const {
51
51
  getFixture,
52
52
  functionName,
53
53
  params,
@@ -56,14 +56,14 @@ async function callback({
56
56
  expectedToThrow = false,
57
57
  expectedErrorMessage = '',
58
58
  expectedErrorStatus = ''
59
- }) {
59
+ } = callbackParams;
60
60
 
61
61
  const mongoOperator = await getMongoOperator(mongoFixtures);
62
62
  const expectedResult = await getFixture('expectedResult.json');
63
63
 
64
64
  await doPreFillDb(preFillDb);
65
65
 
66
- async function doPreFillDb(preFillDb) {
66
+ async function doPreFillDb(preFillDb: boolean) {
67
67
  if (preFillDb) {
68
68
  await mongoFixtures.populate(getFixture('dbContents.json'));
69
69
  return;
@@ -4,9 +4,9 @@ import mongoFixturesFactory from '@natlibfi/fixura-mongo';
4
4
  import generateTests from '@natlibfi/fixugen';
5
5
  import createDebugLogger from 'debug';
6
6
  //import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils.js';
7
- import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.js';
7
+ import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.ts';
8
8
 
9
- let mongoFixtures; // eslint-disable-line functional/no-let
9
+ let mongoFixtures: any;
10
10
  const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:set-operations:test');
11
11
 
12
12
  generateTests({
@@ -40,14 +40,14 @@ generateTests({
40
40
 
41
41
  async function initMongofixtures() {
42
42
  mongoFixtures = await mongoFixturesFactory({
43
- recurse: false,
44
43
  rootPath: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'set-operations'],
45
44
  gridFS: {bucketName: 'foobar'},
46
45
  useObjectId: true
47
46
  });
48
47
  }
49
48
 
50
- async function callback({
49
+ async function callback(callbackParams: Record<string, any>) {
50
+ const {
51
51
  getFixture,
52
52
  functionName,
53
53
  params,
@@ -56,14 +56,14 @@ async function callback({
56
56
  expectedToThrow = false,
57
57
  expectedErrorMessage = '',
58
58
  expectedErrorStatus = ''
59
- }) {
59
+ } = callbackParams;
60
60
 
61
61
  const mongoOperator = await getMongoOperator(mongoFixtures);
62
62
  const expectedResult = await getFixture('expectedResult.json');
63
63
 
64
64
  await doPreFillDb(preFillDb);
65
65
 
66
- async function doPreFillDb(preFillDb) {
66
+ async function doPreFillDb(preFillDb: boolean) {
67
67
  if (preFillDb) {
68
68
  await mongoFixtures.populate(getFixture('dbContents.json'));
69
69
  return;
@@ -4,10 +4,10 @@ import {READERS} from '@natlibfi/fixura';
4
4
  import mongoFixturesFactory from '@natlibfi/fixura-mongo';
5
5
  import generateTests from '@natlibfi/fixugen';
6
6
  //import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils.js';
7
- import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.js';
7
+ import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.ts';
8
8
 
9
9
 
10
- let mongoFixtures; // eslint-disable-line functional/no-let
10
+ let mongoFixtures: any;
11
11
  const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:set-state:test');
12
12
 
13
13
  generateTests({
@@ -41,14 +41,14 @@ generateTests({
41
41
 
42
42
  async function initMongofixtures() {
43
43
  mongoFixtures = await mongoFixturesFactory({
44
- recurse: false,
45
44
  rootPath: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'set-state'],
46
45
  gridFS: {bucketName: 'foobar'},
47
46
  useObjectId: true
48
47
  });
49
48
  }
50
49
 
51
- async function callback({
50
+ async function callback(callbackParams: Record<string, any>) {
51
+ const {
52
52
  getFixture,
53
53
  functionName,
54
54
  params,
@@ -57,14 +57,14 @@ async function callback({
57
57
  expectedToThrow = false,
58
58
  expectedErrorMessage = '',
59
59
  expectedErrorStatus = ''
60
- }) {
60
+ } = callbackParams;
61
61
 
62
62
  const mongoOperator = await getMongoOperator(mongoFixtures);
63
63
  const expectedResult = await getFixture('expectedResult.json');
64
64
 
65
65
  await doPreFillDb(preFillDb);
66
66
 
67
- async function doPreFillDb(preFillDb) {
67
+ async function doPreFillDb(preFillDb: boolean) {
68
68
  if (preFillDb) {
69
69
  await mongoFixtures.populate(getFixture('dbContents.json'));
70
70
  return;
@@ -2,10 +2,11 @@ import assert from 'node:assert';
2
2
  import {test, before, after} from 'node:test';
3
3
  import mongoFixturesFactory from '@natlibfi/fixura-mongo';
4
4
  import {Error as ApiError} from '@natlibfi/melinda-commons';
5
- import createMongoLogOperator from '../src/mongoLog.js';
5
+ import createMongoLogOperator from '../src/mongoLog.ts';
6
+ import type {MongoLogOperator} from '../src/mongoLog.ts';
6
7
 
7
- let mongoFixtures; // eslint-disable-line functional/no-let
8
- let mongoLogOperator; // eslint-disable-line functional/no-let
8
+ let mongoFixtures: any;
9
+ let mongoLogOperator: MongoLogOperator;
9
10
 
10
11
  async function initMongofixtures() {
11
12
  mongoFixtures = await mongoFixturesFactory({
@@ -14,8 +15,8 @@ async function initMongofixtures() {
14
15
  useObjectId: true,
15
16
  format: {
16
17
  logs: {
17
- creationTime: v => new Date(v),
18
- modificationTime: v => new Date(v)
18
+ creationTime: v => new Date(String(v)),
19
+ modificationTime: v => new Date(String(v))
19
20
  }
20
21
  }
21
22
  });
@@ -51,7 +52,7 @@ test('protect is idempotent: protecting an already protected log keeps it protec
51
52
  await mongoLogOperator.protect(logItem.correlationId, logItem.blobSequence);
52
53
 
53
54
  const {logs} = await mongoFixtures.dump();
54
- const own = logs.filter(doc => doc.correlationId === logItem.correlationId);
55
+ const own = logs.filter((doc: any) => doc.correlationId === logItem.correlationId);
55
56
  assert.equal(own.length, 1);
56
57
  assert.equal(own[0].protected, true);
57
58
  });
@@ -70,7 +71,7 @@ test('unprotect sets protected to false after protect', async () => {
70
71
  assert.equal(result.modifiedCount, 1);
71
72
 
72
73
  const {logs} = await mongoFixtures.dump();
73
- const own = logs.filter(doc => doc.correlationId === logItem.correlationId);
74
+ const own = logs.filter((doc: any) => doc.correlationId === logItem.correlationId);
74
75
  assert.equal(own.length, 1);
75
76
  assert.equal(own[0].protected, false);
76
77
  });
@@ -85,9 +86,9 @@ test('unprotect without blobSequence unprotects all logs of the correlationId',
85
86
  assert.equal(result.modifiedCount, 2);
86
87
 
87
88
  const {logs} = await mongoFixtures.dump();
88
- const own = logs.filter(doc => doc.correlationId === correlationId);
89
+ const own = logs.filter((doc: any) => doc.correlationId === correlationId);
89
90
  assert.equal(own.length, 2);
90
- assert.ok(own.every(doc => doc.protected === false));
91
+ assert.ok(own.every((doc: any) => doc.protected === false));
91
92
  });
92
93
 
93
94
  test('getExpandedListOfLogs throws ApiError when logItemTypes is provided but is not an array', async () => {
@@ -96,7 +97,7 @@ test('getExpandedListOfLogs throws ApiError when logItemTypes is provided but is
96
97
  (error) => {
97
98
  assert.ok(error instanceof ApiError);
98
99
  assert.strictEqual(error.status, 400);
99
- assert.ok(error.payload.includes('logItemTypes must be an array'));
100
+ assert.ok((error.payload as string).includes('logItemTypes must be an array'));
100
101
  return true;
101
102
  }
102
103
  );
@@ -108,7 +109,7 @@ test('getExpandedListOfLogs throws ApiError when logItemTypes contains an unknow
108
109
  (error) => {
109
110
  assert.ok(error instanceof ApiError);
110
111
  assert.strictEqual(error.status, 400);
111
- assert.ok(error.payload.includes('Unknown logItemType'));
112
+ assert.ok((error.payload as string).includes('Unknown logItemType'));
112
113
  return true;
113
114
  }
114
115
  );
@@ -132,7 +133,7 @@ test('getExpandedListOfLogs uses Date instances for dateBefore and dateAfter as-
132
133
  });
133
134
  const own = result.filter(entry => entry.correlationId === logItem.correlationId);
134
135
  assert.equal(own.length, 1);
135
- assert.equal(own[0].logCount, 1);
136
+ assert.equal(own[0]?.logCount, 1);
136
137
  });
137
138
 
138
139
  test('getListOfLogs throws ApiError 500 for an unknown logItemType', async () => {
@@ -141,7 +142,7 @@ test('getListOfLogs throws ApiError 500 for an unknown logItemType', async () =>
141
142
  (error) => {
142
143
  assert.ok(error instanceof ApiError);
143
144
  assert.strictEqual(error.status, 500);
144
- assert.ok(error.payload.includes('Unknown logItemType'));
145
+ assert.ok((error.payload as string).includes('Unknown logItemType'));
145
146
  return true;
146
147
  }
147
148
  );
@@ -159,7 +160,7 @@ test('addLogItem with an unknown logItemType does not throw (warn path)', async
159
160
  await mongoLogOperator.addLogItem(logItem);
160
161
 
161
162
  const {logs} = await mongoFixtures.dump();
162
- const own = logs.filter(doc => doc.correlationId === logItem.correlationId);
163
+ const own = logs.filter((doc: any) => doc.correlationId === logItem.correlationId);
163
164
  assert.equal(own.length, 1);
164
165
  assert.equal(own[0].logItemType, 'BOGUS_LOG');
165
166
  });
@@ -175,7 +176,7 @@ test('getExpandedListOfLogs with a valid logItemTypes array still works', async
175
176
  const result = await mongoLogOperator.getExpandedListOfLogs({logItemTypes: ['MERGE_LOG'], catalogers: ['IMP_TEST1'], dateBefore: new Date(Date.now() + 60 * 60 * 1000)});
176
177
  const own = result.filter(entry => entry.correlationId === logItem.correlationId);
177
178
  assert.equal(own.length, 1);
178
- assert.equal(own[0].logItemType, 'MERGE_LOG');
179
- assert.equal(own[0].cataloger, 'IMP_TEST1');
180
- assert.equal(own[0].logCount, 1);
179
+ assert.equal(own[0]?.logItemType, 'MERGE_LOG');
180
+ assert.equal(own[0]?.cataloger, 'IMP_TEST1');
181
+ assert.equal(own[0]?.logCount, 1);
181
182
  });
@@ -3,9 +3,9 @@ import {READERS} from '@natlibfi/fixura';
3
3
  import {Error as ApiError} from '@natlibfi/melinda-commons';
4
4
  import generateTests from '@natlibfi/fixugen';
5
5
  import mongoFixturesFactory from '@natlibfi/fixura-mongo';
6
- import createMongoLogOperator from '../src/mongoLog.js';
6
+ import createMongoLogOperator from '../src/mongoLog.ts';
7
7
 
8
- let mongoFixtures;
8
+ let mongoFixtures: any;
9
9
 
10
10
  generateTests({
11
11
  callback,
@@ -40,21 +40,22 @@ async function initMongofixtures() {
40
40
  // production shape.
41
41
  format: {
42
42
  logs: {
43
- creationTime: v => new Date(v),
44
- modificationTime: v => new Date(v)
43
+ creationTime: v => new Date(String(v)),
44
+ modificationTime: v => new Date(String(v))
45
45
  }
46
46
  }
47
47
  });
48
48
  }
49
49
 
50
- async function callback({
50
+ async function callback(callbackParams: Record<string, any>) {
51
+ const {
51
52
  getFixture,
52
53
  functionName,
53
54
  params,
54
55
  preFillDb = false,
55
56
  expectError = false,
56
57
  expectedErrorStatus = 500
57
- }) {
58
+ } = callbackParams;
58
59
  const mongoUri = await mongoFixtures.getUri();
59
60
  const mongoLogOperator = await createMongoLogOperator(mongoUri, '');
60
61
  const expectedResult = expectError ? undefined : await getFixture('expectedResult.json');
@@ -175,7 +176,7 @@ async function dumpRemaining() {
175
176
  // Convert BSON Dates in the result to ISO strings and drop _id, so the result
176
177
  // can be compared with the plain strings in expectedResult.json /
177
178
  // expectedRemaining.json (fixura-mongo dump also strips _id)
178
- function normalizeDates(docs) {
179
+ function normalizeDates(docs: any[]): any[] {
179
180
  return docs.map(doc => {
180
181
  const fixed = {...doc};
181
182
  delete fixed._id;
@@ -188,4 +189,3 @@ function normalizeDates(docs) {
188
189
  return fixed;
189
190
  });
190
191
  }
191
-