@kenji71089/evaluation 0.0.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 (209) hide show
  1. package/.release-please-manifest.json +3 -0
  2. package/README.md +9 -0
  3. package/eslint.config.mjs +27 -0
  4. package/lib/clauseEvaluator.d.ts +22 -0
  5. package/lib/clauseEvaluator.js +299 -0
  6. package/lib/clauseEvaluator.mjs +214 -0
  7. package/lib/dependencyEvaluator.d.ts +6 -0
  8. package/lib/dependencyEvaluator.js +46 -0
  9. package/lib/dependencyEvaluator.mjs +19 -0
  10. package/lib/errors.d.ts +9 -0
  11. package/lib/errors.js +15 -0
  12. package/lib/errors.mjs +12 -0
  13. package/lib/evaluation.d.ts +25 -0
  14. package/lib/evaluation.js +503 -0
  15. package/lib/evaluation.mjs +328 -0
  16. package/lib/google/api/annotations_pb.d.ts +8 -0
  17. package/lib/google/api/annotations_pb.js +40 -0
  18. package/lib/google/api/annotations_pb.mjs +54 -0
  19. package/lib/google/api/annotations_pb_service.d.ts +3 -0
  20. package/lib/google/api/annotations_pb_service.js +3 -0
  21. package/lib/google/api/annotations_pb_service.mjs +3 -0
  22. package/lib/google/api/http_pb.d.ts +132 -0
  23. package/lib/google/api/http_pb.js +860 -0
  24. package/lib/google/api/http_pb.mjs +982 -0
  25. package/lib/google/api/http_pb_service.d.ts +3 -0
  26. package/lib/google/api/http_pb_service.js +3 -0
  27. package/lib/google/api/http_pb_service.mjs +3 -0
  28. package/lib/google/rpc/code_pb.d.ts +26 -0
  29. package/lib/google/rpc/code_pb.js +44 -0
  30. package/lib/google/rpc/code_pb.mjs +48 -0
  31. package/lib/google/rpc/code_pb_service.d.ts +3 -0
  32. package/lib/google/rpc/code_pb_service.js +3 -0
  33. package/lib/google/rpc/code_pb_service.mjs +3 -0
  34. package/lib/google/rpc/error_details_pb.d.ts +322 -0
  35. package/lib/google/rpc/error_details_pb.js +2220 -0
  36. package/lib/google/rpc/error_details_pb.mjs +2499 -0
  37. package/lib/google/rpc/error_details_pb_service.d.ts +3 -0
  38. package/lib/google/rpc/error_details_pb_service.js +3 -0
  39. package/lib/google/rpc/error_details_pb_service.mjs +3 -0
  40. package/lib/google/rpc/status_pb.d.ts +36 -0
  41. package/lib/google/rpc/status_pb.js +235 -0
  42. package/lib/google/rpc/status_pb.mjs +268 -0
  43. package/lib/google/rpc/status_pb_service.d.ts +3 -0
  44. package/lib/google/rpc/status_pb_service.js +3 -0
  45. package/lib/google/rpc/status_pb_service.mjs +3 -0
  46. package/lib/index.d.ts +20 -0
  47. package/lib/index.js +199 -0
  48. package/lib/index.mjs +46 -0
  49. package/lib/modelFactory.d.ts +64 -0
  50. package/lib/modelFactory.js +206 -0
  51. package/lib/modelFactory.mjs +176 -0
  52. package/lib/proto/event/client/event_pb.d.ts +761 -0
  53. package/lib/proto/event/client/event_pb.js +5195 -0
  54. package/lib/proto/event/client/event_pb.mjs +5865 -0
  55. package/lib/proto/event/client/event_pb_service.d.ts +3 -0
  56. package/lib/proto/event/client/event_pb_service.js +3 -0
  57. package/lib/proto/event/client/event_pb_service.mjs +3 -0
  58. package/lib/proto/event/domain/event_pb.d.ts +4518 -0
  59. package/lib/proto/event/domain/event_pb.js +10834 -0
  60. package/lib/proto/event/domain/event_pb.mjs +33315 -0
  61. package/lib/proto/event/domain/event_pb_service.d.ts +3 -0
  62. package/lib/proto/event/domain/event_pb_service.js +3 -0
  63. package/lib/proto/event/domain/event_pb_service.mjs +3 -0
  64. package/lib/proto/event/domain/localized_message_pb.d.ts +29 -0
  65. package/lib/proto/event/domain/localized_message_pb.js +183 -0
  66. package/lib/proto/event/domain/localized_message_pb.mjs +206 -0
  67. package/lib/proto/event/domain/localized_message_pb_service.d.ts +3 -0
  68. package/lib/proto/event/domain/localized_message_pb_service.js +3 -0
  69. package/lib/proto/event/domain/localized_message_pb_service.mjs +3 -0
  70. package/lib/proto/event/service/feature_pb.d.ts +44 -0
  71. package/lib/proto/event/service/feature_pb.js +277 -0
  72. package/lib/proto/event/service/feature_pb.mjs +319 -0
  73. package/lib/proto/event/service/feature_pb_service.d.ts +3 -0
  74. package/lib/proto/event/service/feature_pb_service.js +3 -0
  75. package/lib/proto/event/service/feature_pb_service.mjs +3 -0
  76. package/lib/proto/event/service/segment_pb.d.ts +51 -0
  77. package/lib/proto/event/service/segment_pb.js +324 -0
  78. package/lib/proto/event/service/segment_pb.mjs +375 -0
  79. package/lib/proto/event/service/segment_pb_service.d.ts +3 -0
  80. package/lib/proto/event/service/segment_pb_service.js +3 -0
  81. package/lib/proto/event/service/segment_pb_service.mjs +3 -0
  82. package/lib/proto/event/service/user_pb.d.ts +49 -0
  83. package/lib/proto/event/service/user_pb.js +315 -0
  84. package/lib/proto/event/service/user_pb.mjs +362 -0
  85. package/lib/proto/event/service/user_pb_service.d.ts +3 -0
  86. package/lib/proto/event/service/user_pb_service.js +3 -0
  87. package/lib/proto/event/service/user_pb_service.mjs +3 -0
  88. package/lib/proto/feature/clause_pb.d.ts +57 -0
  89. package/lib/proto/feature/clause_pb.js +277 -0
  90. package/lib/proto/feature/clause_pb.mjs +312 -0
  91. package/lib/proto/feature/clause_pb_service.d.ts +3 -0
  92. package/lib/proto/feature/clause_pb_service.js +3 -0
  93. package/lib/proto/feature/clause_pb_service.mjs +3 -0
  94. package/lib/proto/feature/command_pb.d.ts +1213 -0
  95. package/lib/proto/feature/command_pb.js +8260 -0
  96. package/lib/proto/feature/command_pb.mjs +9275 -0
  97. package/lib/proto/feature/command_pb_service.d.ts +3 -0
  98. package/lib/proto/feature/command_pb_service.js +3 -0
  99. package/lib/proto/feature/command_pb_service.mjs +3 -0
  100. package/lib/proto/feature/evaluation_pb.d.ts +111 -0
  101. package/lib/proto/feature/evaluation_pb.js +685 -0
  102. package/lib/proto/feature/evaluation_pb.mjs +793 -0
  103. package/lib/proto/feature/evaluation_pb_service.d.ts +3 -0
  104. package/lib/proto/feature/evaluation_pb_service.js +3 -0
  105. package/lib/proto/feature/evaluation_pb_service.mjs +3 -0
  106. package/lib/proto/feature/feature_last_used_info_pb.d.ts +45 -0
  107. package/lib/proto/feature/feature_last_used_info_pb.js +283 -0
  108. package/lib/proto/feature/feature_last_used_info_pb.mjs +326 -0
  109. package/lib/proto/feature/feature_last_used_info_pb_service.d.ts +3 -0
  110. package/lib/proto/feature/feature_last_used_info_pb_service.js +3 -0
  111. package/lib/proto/feature/feature_last_used_info_pb_service.mjs +3 -0
  112. package/lib/proto/feature/feature_pb.d.ts +192 -0
  113. package/lib/proto/feature/feature_pb.js +1210 -0
  114. package/lib/proto/feature/feature_pb.mjs +1413 -0
  115. package/lib/proto/feature/feature_pb_service.d.ts +3 -0
  116. package/lib/proto/feature/feature_pb_service.js +3 -0
  117. package/lib/proto/feature/feature_pb_service.mjs +3 -0
  118. package/lib/proto/feature/flag_trigger_pb.d.ts +84 -0
  119. package/lib/proto/feature/flag_trigger_pb.js +452 -0
  120. package/lib/proto/feature/flag_trigger_pb.mjs +525 -0
  121. package/lib/proto/feature/flag_trigger_pb_service.d.ts +3 -0
  122. package/lib/proto/feature/flag_trigger_pb_service.js +3 -0
  123. package/lib/proto/feature/flag_trigger_pb_service.mjs +3 -0
  124. package/lib/proto/feature/prerequisite_pb.d.ts +29 -0
  125. package/lib/proto/feature/prerequisite_pb.js +183 -0
  126. package/lib/proto/feature/prerequisite_pb.mjs +206 -0
  127. package/lib/proto/feature/prerequisite_pb_service.d.ts +3 -0
  128. package/lib/proto/feature/prerequisite_pb_service.js +3 -0
  129. package/lib/proto/feature/prerequisite_pb_service.mjs +3 -0
  130. package/lib/proto/feature/reason_pb.d.ts +40 -0
  131. package/lib/proto/feature/reason_pb.js +196 -0
  132. package/lib/proto/feature/reason_pb.mjs +219 -0
  133. package/lib/proto/feature/reason_pb_service.d.ts +3 -0
  134. package/lib/proto/feature/reason_pb_service.js +3 -0
  135. package/lib/proto/feature/reason_pb_service.mjs +3 -0
  136. package/lib/proto/feature/rule_pb.d.ts +39 -0
  137. package/lib/proto/feature/rule_pb.js +254 -0
  138. package/lib/proto/feature/rule_pb.mjs +291 -0
  139. package/lib/proto/feature/rule_pb_service.d.ts +3 -0
  140. package/lib/proto/feature/rule_pb_service.js +3 -0
  141. package/lib/proto/feature/rule_pb_service.mjs +3 -0
  142. package/lib/proto/feature/segment_pb.d.ts +161 -0
  143. package/lib/proto/feature/segment_pb.js +974 -0
  144. package/lib/proto/feature/segment_pb.mjs +1127 -0
  145. package/lib/proto/feature/segment_pb_service.d.ts +3 -0
  146. package/lib/proto/feature/segment_pb_service.js +3 -0
  147. package/lib/proto/feature/segment_pb_service.mjs +3 -0
  148. package/lib/proto/feature/service_pb.d.ts +2158 -0
  149. package/lib/proto/feature/service_pb.js +5363 -0
  150. package/lib/proto/feature/service_pb.mjs +16348 -0
  151. package/lib/proto/feature/service_pb_service.d.ts +747 -0
  152. package/lib/proto/feature/service_pb_service.js +1424 -0
  153. package/lib/proto/feature/service_pb_service.mjs +1501 -0
  154. package/lib/proto/feature/strategy_pb.d.ts +110 -0
  155. package/lib/proto/feature/strategy_pb.js +712 -0
  156. package/lib/proto/feature/strategy_pb.mjs +803 -0
  157. package/lib/proto/feature/strategy_pb_service.d.ts +3 -0
  158. package/lib/proto/feature/strategy_pb_service.js +3 -0
  159. package/lib/proto/feature/strategy_pb_service.mjs +3 -0
  160. package/lib/proto/feature/target_pb.d.ts +31 -0
  161. package/lib/proto/feature/target_pb.js +207 -0
  162. package/lib/proto/feature/target_pb.mjs +232 -0
  163. package/lib/proto/feature/target_pb_service.d.ts +3 -0
  164. package/lib/proto/feature/target_pb_service.js +3 -0
  165. package/lib/proto/feature/target_pb_service.mjs +3 -0
  166. package/lib/proto/feature/variation_pb.d.ts +37 -0
  167. package/lib/proto/feature/variation_pb.js +233 -0
  168. package/lib/proto/feature/variation_pb.mjs +266 -0
  169. package/lib/proto/feature/variation_pb_service.d.ts +3 -0
  170. package/lib/proto/feature/variation_pb_service.js +3 -0
  171. package/lib/proto/feature/variation_pb_service.mjs +3 -0
  172. package/lib/proto/gateway/service_pb.d.ts +772 -0
  173. package/lib/proto/gateway/service_pb.js +5249 -0
  174. package/lib/proto/gateway/service_pb.mjs +6001 -0
  175. package/lib/proto/gateway/service_pb_service.d.ts +253 -0
  176. package/lib/proto/gateway/service_pb_service.js +436 -0
  177. package/lib/proto/gateway/service_pb_service.mjs +461 -0
  178. package/lib/proto/user/user_pb.d.ts +58 -0
  179. package/lib/proto/user/user_pb.js +410 -0
  180. package/lib/proto/user/user_pb.mjs +460 -0
  181. package/lib/proto/user/user_pb_service.d.ts +3 -0
  182. package/lib/proto/user/user_pb_service.js +3 -0
  183. package/lib/proto/user/user_pb_service.mjs +3 -0
  184. package/lib/protoc-gen-openapiv2/options/annotations_pb.d.ts +16 -0
  185. package/lib/protoc-gen-openapiv2/options/annotations_pb.js +100 -0
  186. package/lib/protoc-gen-openapiv2/options/annotations_pb.mjs +158 -0
  187. package/lib/protoc-gen-openapiv2/options/annotations_pb_service.d.ts +3 -0
  188. package/lib/protoc-gen-openapiv2/options/annotations_pb_service.js +3 -0
  189. package/lib/protoc-gen-openapiv2/options/annotations_pb_service.mjs +3 -0
  190. package/lib/protoc-gen-openapiv2/options/openapiv2_pb.d.ts +834 -0
  191. package/lib/protoc-gen-openapiv2/options/openapiv2_pb.js +5456 -0
  192. package/lib/protoc-gen-openapiv2/options/openapiv2_pb.mjs +6256 -0
  193. package/lib/protoc-gen-openapiv2/options/openapiv2_pb_service.d.ts +3 -0
  194. package/lib/protoc-gen-openapiv2/options/openapiv2_pb_service.js +3 -0
  195. package/lib/protoc-gen-openapiv2/options/openapiv2_pb_service.mjs +3 -0
  196. package/lib/ruleEvaluator.d.ts +13 -0
  197. package/lib/ruleEvaluator.js +80 -0
  198. package/lib/ruleEvaluator.mjs +41 -0
  199. package/lib/segmentEvaluator.d.ts +7 -0
  200. package/lib/segmentEvaluator.js +74 -0
  201. package/lib/segmentEvaluator.mjs +34 -0
  202. package/lib/strategyEvaluator.d.ts +10 -0
  203. package/lib/strategyEvaluator.js +135 -0
  204. package/lib/strategyEvaluator.mjs +83 -0
  205. package/lib/userEvaluation.d.ts +8 -0
  206. package/lib/userEvaluation.js +70 -0
  207. package/lib/userEvaluation.mjs +60 -0
  208. package/package.json +46 -0
  209. package/release-please-config.json +22 -0
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createUser = createUser;
4
+ exports.createFeature = createFeature;
5
+ exports.createTarget = createTarget;
6
+ exports.createFixedStrategy = createFixedStrategy;
7
+ exports.createRolloutStrategy = createRolloutStrategy;
8
+ exports.createStrategy = createStrategy;
9
+ exports.createRule = createRule;
10
+ exports.createClause = createClause;
11
+ exports.createSegmentUser = createSegmentUser;
12
+ exports.createPrerequisite = createPrerequisite;
13
+ exports.createVariation = createVariation;
14
+ exports.createEvaluation = createEvaluation;
15
+ exports.createReason = createReason;
16
+ const clause_pb_1 = require("./proto/feature/clause_pb");
17
+ const evaluation_pb_1 = require("./proto/feature/evaluation_pb");
18
+ const feature_pb_1 = require("./proto/feature/feature_pb");
19
+ const prerequisite_pb_1 = require("./proto/feature/prerequisite_pb");
20
+ const reason_pb_1 = require("./proto/feature/reason_pb");
21
+ const rule_pb_1 = require("./proto/feature/rule_pb");
22
+ const segment_pb_1 = require("./proto/feature/segment_pb");
23
+ const strategy_pb_1 = require("./proto/feature/strategy_pb");
24
+ const target_pb_1 = require("./proto/feature/target_pb");
25
+ const variation_pb_1 = require("./proto/feature/variation_pb");
26
+ const user_pb_1 = require("./proto/user/user_pb");
27
+ // Helper function to create a User instance
28
+ function createUser(id, data) {
29
+ const user = new user_pb_1.User();
30
+ user.setId(id);
31
+ let map = user.getDataMap();
32
+ if (data != null) {
33
+ Object.entries(data).forEach(([key, value]) => map.set(key, value));
34
+ }
35
+ return user;
36
+ }
37
+ function createFeature(options = {}) {
38
+ const defaultOptions = {
39
+ id: '',
40
+ name: '',
41
+ version: 0,
42
+ enabled: false,
43
+ createdAt: Date.now(),
44
+ variationType: feature_pb_1.Feature.VariationType.STRING,
45
+ variations: [],
46
+ targets: [],
47
+ rules: [],
48
+ defaultStrategy: undefined,
49
+ prerequisitesList: [],
50
+ tagList: [],
51
+ offVariation: undefined,
52
+ };
53
+ const finalOptions = { ...defaultOptions, ...options };
54
+ const feature = new feature_pb_1.Feature();
55
+ feature.setId(finalOptions.id);
56
+ feature.setName(finalOptions.name);
57
+ feature.setVersion(finalOptions.version);
58
+ feature.setEnabled(finalOptions.enabled);
59
+ feature.setCreatedAt(finalOptions.createdAt);
60
+ feature.setVariationType(finalOptions.variationType);
61
+ // Set variations
62
+ const variationList = finalOptions.variations.map((v) => createVariation(v.id, v.value, v.name, v.description));
63
+ feature.setVariationsList(variationList);
64
+ // Set targets
65
+ const targetList = finalOptions.targets.map((t) => createTarget(t.variation, t.users));
66
+ feature.setTargetsList(targetList);
67
+ // Set rules
68
+ const ruleList = finalOptions.rules.map((r) => createRule(r.id, r.attribute, r.operator, r.values, r.fixedVariation));
69
+ feature.setRulesList(ruleList);
70
+ // Set default strategy
71
+ const defaultStrategy = finalOptions.defaultStrategy;
72
+ if (defaultStrategy !== undefined) {
73
+ const defaultFixedStrategy = createFixedStrategy(defaultStrategy.variation);
74
+ const strategy = createStrategy({
75
+ type: defaultStrategy.type,
76
+ fixedStrategy: defaultFixedStrategy,
77
+ });
78
+ feature.setDefaultStrategy(strategy);
79
+ }
80
+ feature.setPrerequisitesList(finalOptions.prerequisitesList);
81
+ feature.setTagsList(finalOptions.tagList);
82
+ if (finalOptions.offVariation !== undefined) {
83
+ feature.setOffVariation(finalOptions.offVariation);
84
+ }
85
+ return feature;
86
+ }
87
+ function createTarget(variation, users) {
88
+ const target = new target_pb_1.Target();
89
+ target.setVariation(variation);
90
+ target.setUsersList(users);
91
+ return target;
92
+ }
93
+ function createFixedStrategy(variation) {
94
+ const fixedStrategy = new strategy_pb_1.FixedStrategy();
95
+ fixedStrategy.setVariation(variation);
96
+ return fixedStrategy;
97
+ }
98
+ function createRolloutStrategy(options) {
99
+ const rolloutStrategy = new strategy_pb_1.RolloutStrategy();
100
+ const variations = options.variations.map((v) => {
101
+ const variation = new strategy_pb_1.RolloutStrategy.Variation();
102
+ variation.setVariation(v.variation);
103
+ variation.setWeight(v.weight);
104
+ return variation;
105
+ });
106
+ rolloutStrategy.setVariationsList(variations);
107
+ return rolloutStrategy;
108
+ }
109
+ function createStrategy(options) {
110
+ const strategy = new strategy_pb_1.Strategy();
111
+ strategy.setType(options.type);
112
+ strategy.setFixedStrategy(options.fixedStrategy);
113
+ strategy.setRolloutStrategy(options.rolloutStrategy);
114
+ return strategy;
115
+ }
116
+ //TODO: FIX ME - Rule should have a constructor that accepts all the parameters
117
+ //Current is missing many parameters
118
+ function createRule(id, attribute, operator, values, fixedVariation) {
119
+ const rule = new rule_pb_1.Rule();
120
+ rule.setId(id);
121
+ const fixedStrategy = createFixedStrategy(fixedVariation);
122
+ const strategy = createStrategy({ type: strategy_pb_1.Strategy.Type.FIXED, fixedStrategy });
123
+ rule.setStrategy(strategy);
124
+ rule.setClausesList([createClause(id, attribute, operator, values)]);
125
+ return rule;
126
+ }
127
+ function createClause(id, attribute, operator, values) {
128
+ const clause = new clause_pb_1.Clause();
129
+ clause.setId(id);
130
+ clause.setAttribute(attribute);
131
+ clause.setOperator(operator);
132
+ clause.setValuesList(values);
133
+ return clause;
134
+ }
135
+ function createSegmentUser(userId, segmentId, state) {
136
+ const segmentUser = new segment_pb_1.SegmentUser();
137
+ segmentUser.setUserId(userId);
138
+ segmentUser.setSegmentId(segmentId);
139
+ segmentUser.setState(state);
140
+ return segmentUser;
141
+ }
142
+ function createPrerequisite(featureId, variationId) {
143
+ const prerequisite = new prerequisite_pb_1.Prerequisite();
144
+ prerequisite.setFeatureId(featureId);
145
+ prerequisite.setVariationId(variationId);
146
+ return prerequisite;
147
+ }
148
+ // Function to create a Variation instance with the provided parameters
149
+ function createVariation(id, value, name, description) {
150
+ const variation = new variation_pb_1.Variation();
151
+ variation.setId(id);
152
+ variation.setValue(value);
153
+ variation.setName(name);
154
+ variation.setDescription(description);
155
+ return variation;
156
+ }
157
+ function createEvaluation(id, featureId, featureVersion, userId, variationId, variationValue, variationName, reason) {
158
+ const evaluation = new evaluation_pb_1.Evaluation();
159
+ evaluation.setId(id);
160
+ evaluation.setFeatureId(featureId);
161
+ evaluation.setFeatureVersion(featureVersion);
162
+ evaluation.setUserId(userId);
163
+ evaluation.setVariationId(variationId);
164
+ evaluation.setVariationValue(variationValue);
165
+ evaluation.setVariationName(variationName);
166
+ evaluation.setReason(reason);
167
+ return evaluation;
168
+ }
169
+ //TODO: should we set the ruleId to empty string as default?
170
+ //TODO: create optional constructor for Reason
171
+ function createReason(ruleId, type) {
172
+ const reason = new reason_pb_1.Reason();
173
+ reason.setType(type);
174
+ reason.setRuleId(ruleId);
175
+ return reason;
176
+ }