dataclasses/columns.js

  1. const { mergeAll } = require('ramda');
  2. const $_type = require('./$_type');
  3. /**
  4. * Target type definition
  5. * @typedef {Object} Target
  6. * @memberof dataclasses
  7. */
  8. /**
  9. * Create a new target
  10. * @param {object} target
  11. * @param {string} target.target_id - unique id for this target
  12. * @param {string} target.label - label that will be displayed for this target
  13. * @param {string} target.type_id - the type_id name this target has
  14. * @return {Target} {@link dataclasses.Target}
  15. * @memberof dataclasses
  16. */
  17. function Target(target) {
  18. // target MUST at least have the attributes bellow
  19. const { target_id, label, type_id } = target;
  20. return mergeAll([$_type('Target'), { target_id, label, type_id }, target]);
  21. }
  22. /**
  23. * A type operator
  24. * @typedef Operator
  25. * @memberof dataclasses
  26. */
  27. /**
  28. * Create a new operator
  29. * @param {object} operator
  30. * @param {string} operator.operator_id - unique id for this operator
  31. * @param {string} operator.label - label that will be displayed for this operator
  32. * @return {Operator} {@link dataclasses.Operator}
  33. * @memberof dataclasses
  34. */
  35. function Operator(operator) {
  36. // operator MUST at least have the attributes bellow
  37. const { operator_id, label } = operator;
  38. return mergeAll([
  39. $_type('Operator'),
  40. {
  41. operator_id,
  42. label,
  43. },
  44. operator,
  45. ]);
  46. }
  47. /**
  48. * Defines a target type
  49. * @typedef Type
  50. * @memberof dataclasses
  51. */
  52. /**
  53. * Create a new type
  54. * @param {Object} type
  55. * @param {string} type.type_id
  56. * @param {string[]} type.operator_ids
  57. * @return {Type} {@link dataclasses.Type}
  58. * @memberof dataclasses
  59. */
  60. function Type(type) {
  61. // operator MUST at least have the attributes bellow
  62. const { type_id, operator_ids } = type;
  63. return mergeAll([
  64. $_type('Type'),
  65. {
  66. type_id,
  67. operator_ids,
  68. },
  69. type,
  70. ]);
  71. }
  72. /**
  73. * Create a new type logical type
  74. * Logical types or used in CompoundPredicates
  75. * @param {Object} logic The predicate logic
  76. * @param {string} type.logicalType_id
  77. * @param {string} type.label
  78. * @memberof dataclasses
  79. */
  80. function LogicalType(logicalType) {
  81. // logicalType MUST at least have the attributes bellow
  82. const { logicalType_id, label } = logicalType;
  83. return mergeAll([
  84. $_type('LogicalType'),
  85. {
  86. logicalType_id,
  87. label,
  88. },
  89. logicalType,
  90. ]);
  91. }
  92. module.exports = { Type, Target, Operator, LogicalType };