test1.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* the key is to do it in one line. Client just pass 2 arguments, one is the location of the data, which could be file, sql or mongodb, and also
  2. pass in the conditions of their search enquiries. We will aslo have to cater to different file storage location to determine how to prep the
  3. data to be filtered
  4. */
  5. import { Observable } from "rxjs"
  6. import { queryService } from "../services/query.service"
  7. import { Conditions, Storage } from "../services/query.service"
  8. import { _, isObject } from 'lodash'
  9. let query = new queryService()
  10. //For now just local file storage. More will be preapred in the design phase later.
  11. let storageAddress: Storage = {
  12. type: "File",
  13. address: "payload.json"
  14. }
  15. // Array inquiry: should return mutiple data
  16. let conditions1: Conditions[] = [
  17. { 'msgTag': ['free'] }
  18. ]
  19. // Basic inquiry, but with multi search: should return one data
  20. let conditions2: Conditions[] = [
  21. { "msgId": "4f710c4b-a258-4c7e-a4b6-6095bb7028e9" },
  22. { "msgLogDateTime": "2023-01-14T21:50:19.917Z" },
  23. ]
  24. // Value only argument! : should return one data
  25. let conditions3: Conditions[] = [
  26. { "regex": "cum incidunt maxime voluptatibus" }
  27. ]
  28. // Date Range inquiry: Should return multiple data
  29. let conditions4: Conditions[] = [
  30. {
  31. "dateRange": {
  32. "startDate": "2023-04-09T21:00:00.000Z",
  33. 'endDate': "2023-04-10T00:00:00.000Z"
  34. }
  35. }
  36. ]
  37. // Multi conditions except for regex search: Should return at least 1 data
  38. let conditions5: Conditions[] = [
  39. {
  40. "dateRange": {
  41. "startDate": "2023-04-09T21:00:00.000Z",
  42. 'endDate': "2023-04-10T00:00:00.000Z"
  43. }
  44. },
  45. { 'msgTag': ['basic'] },
  46. { "msgId": "4f710c4b-a258-4c7e-a4b6-6095bb7028e9" },
  47. { "msgLogDateTime": "2023-01-14T21:50:19.917Z" }
  48. ]
  49. // Ultimate search. With all conditions piling at once: Should at least returns 1 data
  50. let conditions6: Conditions[] = [
  51. {
  52. "dateRange": {
  53. "startDate": "2023-04-09T21:00:00.000Z",
  54. 'endDate': "2023-04-10T00:00:00.000Z"
  55. }
  56. },
  57. { "regex": "maxime voluptatibus ad quasi eveniet" },
  58. { 'msgTag': ['basic'] },
  59. { "msgId": "4f710c4b-a258-4c7e-a4b6-6095bb7028e9" },
  60. { "msgLogDateTime": "2023-01-14T21:50:19.917Z" }
  61. ]
  62. query.query(storageAddress, ...conditions4).subscribe((element) => { console.log(`${element.header.messageName} is matched`) })
  63. query.query(storageAddress, ...conditions6).subscribe((element) => { console.log(`${element.header.messageName} is matched`) })