@sera4/essentia 1.1.66-rc.1 → 3.0.8

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 (194) hide show
  1. package/README.md +352 -8
  2. package/dist/ts/index.d.ts +1 -1
  3. package/dist/ts/index.js +1 -1
  4. package/dist/ts/index.js.map +1 -1
  5. package/dist/ts/logger/s4-logger.js +0 -2
  6. package/dist/ts/logger/s4-logger.js.map +1 -1
  7. package/dist/ts/queue/index.d.ts +2 -38
  8. package/dist/ts/queue/index.js +67 -136
  9. package/dist/ts/queue/index.js.map +1 -1
  10. package/package.json +51 -12
  11. package/package.tar.gz +0 -0
  12. package/cache/index.js +0 -188
  13. package/constants/index.js +0 -9
  14. package/coverage/base.css +0 -224
  15. package/coverage/block-navigation.js +0 -87
  16. package/coverage/configurations/index.html +0 -116
  17. package/coverage/configurations/server-config.ts.html +0 -94
  18. package/coverage/dns/DnsCache.ts.html +0 -598
  19. package/coverage/dns/index.html +0 -131
  20. package/coverage/dns/index.ts.html +0 -94
  21. package/coverage/favicon.png +0 -0
  22. package/coverage/health/index.html +0 -116
  23. package/coverage/health/index.ts.html +0 -778
  24. package/coverage/index.html +0 -161
  25. package/coverage/lcov-report/base.css +0 -224
  26. package/coverage/lcov-report/block-navigation.js +0 -87
  27. package/coverage/lcov-report/configurations/index.html +0 -116
  28. package/coverage/lcov-report/configurations/server-config.ts.html +0 -94
  29. package/coverage/lcov-report/dns/DnsCache.ts.html +0 -598
  30. package/coverage/lcov-report/dns/index.html +0 -131
  31. package/coverage/lcov-report/dns/index.ts.html +0 -94
  32. package/coverage/lcov-report/favicon.png +0 -0
  33. package/coverage/lcov-report/health/index.html +0 -116
  34. package/coverage/lcov-report/health/index.ts.html +0 -778
  35. package/coverage/lcov-report/index.html +0 -161
  36. package/coverage/lcov-report/logger/index.html +0 -131
  37. package/coverage/lcov-report/logger/index.ts.html +0 -94
  38. package/coverage/lcov-report/logger/s4-logger.ts.html +0 -514
  39. package/coverage/lcov-report/prettify.css +0 -1
  40. package/coverage/lcov-report/prettify.js +0 -2
  41. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  42. package/coverage/lcov-report/sorter.js +0 -196
  43. package/coverage/lcov.info +0 -747
  44. package/coverage/logger/index.html +0 -131
  45. package/coverage/logger/index.ts.html +0 -94
  46. package/coverage/logger/s4-logger.ts.html +0 -514
  47. package/coverage/prettify.css +0 -1
  48. package/coverage/prettify.js +0 -2
  49. package/coverage/sort-arrow-sprite.png +0 -0
  50. package/coverage/sorter.js +0 -196
  51. package/coverage/tmp/coverage-24302-1746472691313-0.json +0 -1
  52. package/coverage/tmp/coverage-24302-1746472691366-1.json +0 -1
  53. package/dist/cache/index.d.ts +0 -22
  54. package/dist/cache/index.js +0 -166
  55. package/dist/cache/index.js.map +0 -1
  56. package/dist/constants/index.d.ts +0 -6
  57. package/dist/constants/index.js +0 -9
  58. package/dist/constants/index.js.map +0 -1
  59. package/dist/coverage/block-navigation.d.ts +0 -1
  60. package/dist/coverage/block-navigation.js +0 -70
  61. package/dist/coverage/block-navigation.js.map +0 -1
  62. package/dist/coverage/lcov-report/block-navigation.d.ts +0 -1
  63. package/dist/coverage/lcov-report/block-navigation.js +0 -70
  64. package/dist/coverage/lcov-report/block-navigation.js.map +0 -1
  65. package/dist/coverage/lcov-report/prettify.d.ts +0 -0
  66. package/dist/coverage/lcov-report/prettify.js +0 -477
  67. package/dist/coverage/lcov-report/prettify.js.map +0 -1
  68. package/dist/coverage/lcov-report/sorter.d.ts +0 -1
  69. package/dist/coverage/lcov-report/sorter.js +0 -163
  70. package/dist/coverage/lcov-report/sorter.js.map +0 -1
  71. package/dist/coverage/prettify.d.ts +0 -0
  72. package/dist/coverage/prettify.js +0 -477
  73. package/dist/coverage/prettify.js.map +0 -1
  74. package/dist/coverage/sorter.d.ts +0 -1
  75. package/dist/coverage/sorter.js +0 -163
  76. package/dist/coverage/sorter.js.map +0 -1
  77. package/dist/formatter/index.d.ts +0 -37
  78. package/dist/formatter/index.js +0 -75
  79. package/dist/formatter/index.js.map +0 -1
  80. package/dist/hal/index.d.ts +0 -5
  81. package/dist/hal/index.js +0 -69
  82. package/dist/hal/index.js.map +0 -1
  83. package/dist/health/health-logger.d.ts +0 -9
  84. package/dist/health/health-logger.js +0 -34
  85. package/dist/health/health-logger.js.map +0 -1
  86. package/dist/health/index.d.ts +0 -19
  87. package/dist/health/index.js +0 -175
  88. package/dist/health/index.js.map +0 -1
  89. package/dist/helpers/index.d.ts +0 -1
  90. package/dist/helpers/index.js +0 -2
  91. package/dist/helpers/index.js.map +0 -1
  92. package/dist/helpers/test-server-wrapper.d.ts +0 -120
  93. package/dist/helpers/test-server-wrapper.js +0 -165
  94. package/dist/helpers/test-server-wrapper.js.map +0 -1
  95. package/dist/index.d.ts +0 -1
  96. package/dist/index.js +0 -17
  97. package/dist/index.js.map +0 -1
  98. package/dist/last-commit.d.ts +0 -1
  99. package/dist/last-commit.js +0 -12
  100. package/dist/last-commit.js.map +0 -1
  101. package/dist/last_commit/index.d.ts +0 -7
  102. package/dist/last_commit/index.js +0 -83
  103. package/dist/last_commit/index.js.map +0 -1
  104. package/dist/paginator/s4-pagination.d.ts +0 -9
  105. package/dist/paginator/s4-pagination.js +0 -49
  106. package/dist/paginator/s4-pagination.js.map +0 -1
  107. package/dist/paginator/sql-pagination.d.ts +0 -27
  108. package/dist/paginator/sql-pagination.js +0 -166
  109. package/dist/paginator/sql-pagination.js.map +0 -1
  110. package/dist/paper-trail/helpers.d.ts +0 -11
  111. package/dist/paper-trail/helpers.js +0 -74
  112. package/dist/paper-trail/helpers.js.map +0 -1
  113. package/dist/paper-trail/index.d.ts +0 -13
  114. package/dist/paper-trail/index.js +0 -662
  115. package/dist/paper-trail/index.js.map +0 -1
  116. package/dist/prompts/index.d.ts +0 -14
  117. package/dist/prompts/index.js +0 -63
  118. package/dist/prompts/index.js.map +0 -1
  119. package/dist/queue/index.d.ts +0 -166
  120. package/dist/queue/index.js +0 -371
  121. package/dist/queue/index.js.map +0 -1
  122. package/dist/queue/publisher.d.ts +0 -31
  123. package/dist/queue/publisher.js +0 -84
  124. package/dist/queue/publisher.js.map +0 -1
  125. package/dist/queue/queue-logger.d.ts +0 -9
  126. package/dist/queue/queue-logger.js +0 -35
  127. package/dist/queue/queue-logger.js.map +0 -1
  128. package/dist/queue/subscriber.d.ts +0 -39
  129. package/dist/queue/subscriber.js +0 -97
  130. package/dist/queue/subscriber.js.map +0 -1
  131. package/dist/safe_proxy/index.d.ts +0 -13
  132. package/dist/safe_proxy/index.js +0 -54
  133. package/dist/safe_proxy/index.js.map +0 -1
  134. package/dist/serializer/index.d.ts +0 -5
  135. package/dist/serializer/index.js +0 -83
  136. package/dist/serializer/index.js.map +0 -1
  137. package/dist/test/debug-array.d.ts +0 -0
  138. package/dist/test/debug-array.js +0 -1
  139. package/dist/test/debug-array.js.map +0 -1
  140. package/dist/test/debug-setJSONB.d.ts +0 -0
  141. package/dist/test/debug-setJSONB.js +0 -1
  142. package/dist/test/debug-setJSONB.js.map +0 -1
  143. package/dist/test/prompt.test.d.ts +0 -1
  144. package/dist/test/prompt.test.js +0 -74
  145. package/dist/test/prompt.test.js.map +0 -1
  146. package/dist/test/s4-formatter.spec.d.ts +0 -1
  147. package/dist/test/s4-formatter.spec.js +0 -67
  148. package/dist/test/s4-formatter.spec.js.map +0 -1
  149. package/dist/test/s4-pagination.spec.d.ts +0 -1
  150. package/dist/test/s4-pagination.spec.js +0 -170
  151. package/dist/test/s4-pagination.spec.js.map +0 -1
  152. package/dist/test/safe-proxy.spec.d.ts +0 -1
  153. package/dist/test/safe-proxy.spec.js +0 -252
  154. package/dist/test/safe-proxy.spec.js.map +0 -1
  155. package/dist/test/serializer.spec.d.ts +0 -1
  156. package/dist/test/serializer.spec.js +0 -27
  157. package/dist/test/serializer.spec.js.map +0 -1
  158. package/dist/test/utils.spec.d.ts +0 -1
  159. package/dist/test/utils.spec.js +0 -446
  160. package/dist/test/utils.spec.js.map +0 -1
  161. package/dist/ts/task-scheduler/index.d.ts +0 -130
  162. package/dist/ts/task-scheduler/index.js +0 -259
  163. package/dist/ts/task-scheduler/index.js.map +0 -1
  164. package/formatter/index.js +0 -81
  165. package/hal/README.md +0 -54
  166. package/hal/index.js +0 -75
  167. package/health/health-logger.js +0 -40
  168. package/health/index.js +0 -188
  169. package/helpers/index.js +0 -1
  170. package/helpers/test-server-wrapper.js +0 -196
  171. package/last-commit.js +0 -12
  172. package/last_commit/index.js +0 -82
  173. package/logger/s4-logger.js +0 -128
  174. package/paginator/README.md +0 -183
  175. package/paginator/s4-pagination.js +0 -51
  176. package/paginator/sql-pagination.js +0 -178
  177. package/paper-trail/README.md +0 -68
  178. package/paper-trail/helpers.js +0 -99
  179. package/paper-trail/index.js +0 -843
  180. package/prompts/index.js +0 -78
  181. package/queue/index.js +0 -402
  182. package/queue/publisher.js +0 -96
  183. package/queue/queue-logger.js +0 -40
  184. package/queue/subscriber.js +0 -107
  185. package/safe_proxy/index.js +0 -61
  186. package/scripts/publish.sh +0 -46
  187. package/serializer/index.js +0 -90
  188. package/test/health.spec.js +0 -213
  189. package/test/prompt.test.js +0 -91
  190. package/test/s4-formatter.spec.js +0 -80
  191. package/test/s4-pagination.spec.js +0 -196
  192. package/test/serializer.spec.js +0 -34
  193. package/test/utils.spec.js +0 -145
  194. package/utils/index.js +0 -74
@@ -1,259 +0,0 @@
1
- import cron from 'node-cron';
2
- import { S4Logger } from '../logger/index.js';
3
- const logger = new S4Logger();
4
- /**
5
- * TaskScheduler - Singleton class for managing cron-based scheduled tasks
6
- * Provides helper functions around node-cron for easy task scheduling
7
- */
8
- export class TaskScheduler {
9
- constructor() {
10
- this.tasks = new Map();
11
- this.isInitialized = false;
12
- this.options = {};
13
- }
14
- /**
15
- * Get the singleton instance of TaskScheduler
16
- * @returns {TaskScheduler} The singleton instance
17
- */
18
- static getInstance() {
19
- if (!TaskScheduler.instance) {
20
- TaskScheduler.instance = new TaskScheduler();
21
- }
22
- return TaskScheduler.instance;
23
- }
24
- /**
25
- * Initialize the task scheduler
26
- * @param {SchedulerOptions} options - Configuration options
27
- * @param {string} options.timezone - Timezone for cron jobs (default: 'UTC')
28
- * @param {boolean} options.scheduled - Whether to start tasks immediately (default: true)
29
- */
30
- init(options = {}) {
31
- if (this.isInitialized) {
32
- logger.warn('TaskScheduler already initialized');
33
- return;
34
- }
35
- this.options = {
36
- timezone: options.timezone || 'UTC',
37
- scheduled: options.scheduled !== false
38
- };
39
- this.isInitialized = true;
40
- logger.info('TaskScheduler initialized', {
41
- timezone: this.options.timezone,
42
- scheduled: this.options.scheduled
43
- });
44
- }
45
- /**
46
- * Add a scheduled task
47
- * @param {string} name - Unique name for the task
48
- * @param {string} cronExpression - Cron expression (e.g., '0 0 * * *' for daily at midnight)
49
- * @param {TaskFunction} taskFunction - Function to execute
50
- * @param {TaskOptions} options - Additional options
51
- * @param {boolean} options.scheduled - Whether to start the task immediately (default: true)
52
- * @param {string} options.timezone - Timezone override for this task
53
- * @returns {boolean} - Success status
54
- */
55
- addTask(name, cronExpression, taskFunction, options = {}) {
56
- if (!this.isInitialized) {
57
- logger.error('TaskScheduler not initialized. Call init() first.');
58
- return false;
59
- }
60
- if (this.tasks.has(name)) {
61
- logger.warn(`Task '${name}' already exists. Use updateTask() to modify it.`);
62
- return false;
63
- }
64
- if (!cron.validate(cronExpression)) {
65
- logger.error(`Invalid cron expression for task '${name}': ${cronExpression}`);
66
- return false;
67
- }
68
- const taskOptions = {
69
- scheduled: options.scheduled !== false && this.options.scheduled,
70
- timezone: options.timezone || this.options.timezone
71
- };
72
- try {
73
- const task = cron.schedule(cronExpression, async () => {
74
- const startTime = Date.now();
75
- logger.info(`Starting scheduled task: ${name}`);
76
- try {
77
- await taskFunction();
78
- const duration = Date.now() - startTime;
79
- logger.info(`Completed scheduled task: ${name} (${duration}ms)`);
80
- }
81
- catch (error) {
82
- const duration = Date.now() - startTime;
83
- logger.error(`Failed scheduled task: ${name} (${duration}ms)`, error);
84
- }
85
- }, taskOptions);
86
- this.tasks.set(name, {
87
- task,
88
- cronExpression,
89
- taskFunction,
90
- options: taskOptions,
91
- createdAt: new Date()
92
- });
93
- logger.info(`Added scheduled task: ${name}`, {
94
- cronExpression,
95
- scheduled: taskOptions.scheduled,
96
- timezone: taskOptions.timezone
97
- });
98
- return true;
99
- }
100
- catch (error) {
101
- logger.error(`Failed to add scheduled task: ${name}`, error);
102
- return false;
103
- }
104
- }
105
- /**
106
- * Update an existing scheduled task
107
- * @param {string} name - Name of the task to update
108
- * @param {string} cronExpression - New cron expression
109
- * @param {TaskFunction} taskFunction - New function to execute
110
- * @param {TaskOptions} options - Additional options
111
- * @returns {boolean} - Success status
112
- */
113
- updateTask(name, cronExpression, taskFunction, options = {}) {
114
- if (!this.tasks.has(name)) {
115
- logger.error(`Task '${name}' not found. Use addTask() to create it.`);
116
- return false;
117
- }
118
- // Remove existing task
119
- this.removeTask(name);
120
- // Add updated task
121
- return this.addTask(name, cronExpression, taskFunction, options);
122
- }
123
- /**
124
- * Remove a scheduled task
125
- * @param {string} name - Name of the task to remove
126
- * @returns {boolean} - Success status
127
- */
128
- removeTask(name) {
129
- if (!this.tasks.has(name)) {
130
- logger.warn(`Task '${name}' not found`);
131
- return false;
132
- }
133
- const taskInfo = this.tasks.get(name);
134
- taskInfo.task.destroy();
135
- this.tasks.delete(name);
136
- logger.info(`Removed scheduled task: ${name}`);
137
- return true;
138
- }
139
- /**
140
- * Start a specific task
141
- * @param {string} name - Name of the task to start
142
- * @returns {boolean} - Success status
143
- */
144
- startTask(name) {
145
- if (!this.tasks.has(name)) {
146
- logger.error(`Task '${name}' not found`);
147
- return false;
148
- }
149
- const taskInfo = this.tasks.get(name);
150
- taskInfo.task.start();
151
- logger.info(`Started scheduled task: ${name}`);
152
- return true;
153
- }
154
- /**
155
- * Stop a specific task
156
- * @param {string} name - Name of the task to stop
157
- * @returns {boolean} - Success status
158
- */
159
- stopTask(name) {
160
- if (!this.tasks.has(name)) {
161
- logger.error(`Task '${name}' not found`);
162
- return false;
163
- }
164
- const taskInfo = this.tasks.get(name);
165
- taskInfo.task.stop();
166
- logger.info(`Stopped scheduled task: ${name}`);
167
- return true;
168
- }
169
- /**
170
- * Start all tasks
171
- */
172
- startAll() {
173
- this.tasks.forEach((taskInfo, name) => {
174
- taskInfo.task.start();
175
- });
176
- logger.info(`Started all scheduled tasks (${this.tasks.size} tasks)`);
177
- }
178
- /**
179
- * Stop all tasks
180
- */
181
- stopAll() {
182
- this.tasks.forEach((taskInfo, name) => {
183
- taskInfo.task.stop();
184
- });
185
- logger.info(`Stopped all scheduled tasks (${this.tasks.size} tasks)`);
186
- }
187
- /**
188
- * Get information about all scheduled tasks
189
- * @returns {TaskInfo[]} - Array of task information objects
190
- */
191
- getTasks() {
192
- const tasks = [];
193
- this.tasks.forEach((taskInfo, name) => {
194
- tasks.push({
195
- name,
196
- cronExpression: taskInfo.cronExpression,
197
- isRunning: taskInfo.task.running || false,
198
- createdAt: taskInfo.createdAt,
199
- options: taskInfo.options
200
- });
201
- });
202
- return tasks;
203
- }
204
- /**
205
- * Get information about a specific task
206
- * @param {string} name - Name of the task
207
- * @returns {TaskInfo | null} - Task information or null if not found
208
- */
209
- getTask(name) {
210
- if (!this.tasks.has(name)) {
211
- return null;
212
- }
213
- const taskInfo = this.tasks.get(name);
214
- return {
215
- name,
216
- cronExpression: taskInfo.cronExpression,
217
- isRunning: taskInfo.task.running || false,
218
- createdAt: taskInfo.createdAt,
219
- options: taskInfo.options
220
- };
221
- }
222
- /**
223
- * Validate a cron expression
224
- * @param {string} cronExpression - Cron expression to validate
225
- * @returns {boolean} - Whether the expression is valid
226
- */
227
- validateCronExpression(cronExpression) {
228
- return cron.validate(cronExpression);
229
- }
230
- /**
231
- * Check if the scheduler is initialized
232
- * @returns {boolean} - Whether the scheduler is initialized
233
- */
234
- isSchedulerInitialized() {
235
- return this.isInitialized;
236
- }
237
- /**
238
- * Get the number of active tasks
239
- * @returns {number} - Number of active tasks
240
- */
241
- getTaskCount() {
242
- return this.tasks.size;
243
- }
244
- /**
245
- * Shutdown the scheduler and clean up all tasks
246
- */
247
- shutdown() {
248
- logger.info('Shutting down TaskScheduler...');
249
- this.tasks.forEach((taskInfo, name) => {
250
- taskInfo.task.destroy();
251
- });
252
- this.tasks.clear();
253
- this.isInitialized = false;
254
- logger.info('TaskScheduler shutdown complete');
255
- }
256
- }
257
- // Export singleton instance
258
- export default TaskScheduler.getInstance();
259
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/task-scheduler/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,MAAM,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;AA6C9B;;;GAGG;AACH,MAAM,OAAO,aAAa;IAMxB;QAJiB,UAAK,GAAkC,IAAI,GAAG,EAAE,CAAC;QAC1D,kBAAa,GAAY,KAAK,CAAC;QAC/B,YAAO,GAAqB,EAAE,CAAC;IAEhB,CAAC;IAExB;;;OAGG;IACI,MAAM,CAAC,WAAW;QACvB,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC;YAC5B,aAAa,CAAC,QAAQ,GAAG,IAAI,aAAa,EAAE,CAAC;QAC/C,CAAC;QACD,OAAO,aAAa,CAAC,QAAQ,CAAC;IAChC,CAAC;IAED;;;;;OAKG;IACI,IAAI,CAAC,UAA4B,EAAE;QACxC,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACvB,MAAM,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;YACjD,OAAO;QACT,CAAC;QAED,IAAI,CAAC,OAAO,GAAG;YACb,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,KAAK;YACnC,SAAS,EAAE,OAAO,CAAC,SAAS,KAAK,KAAK;SACvC,CAAC;QAEF,IAAI,CAAC,aAAa,GA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ormatError extends Error {
4
- constructor(m) {
5
- super(m);
6
- }
7
- }
8
-
9
- // helps to clean up response formats for services responding to rest requests
10
- class S4Formatter {
11
- constructor() {
12
- this.defaults = {
13
- status: 422,
14
- errors: {}
15
- };
16
- }
17
-
18
- _isArray (value) {
19
- return value && typeof value === 'object' && value.constructor === Array;
20
- }
21
-
22
- _fromHash(error) {
23
- let response = Object.assign({}, this.defaults);
24
-
25
- if (error.status) {
26
- let errorStatus = parseInt(error.status);
27
-
28
- if ((errorStatus >= 200) && (errorStatus < 522)) {
29
- response.status = errorStatus
30
- }
31
- }
32
-
33
- if (error.error && (typeof(error.error) === "string")) {
34
- response.errors["generic"] = { msg: error.error }
35
- } else if (error.errors) {
36
- if (this._isArray(error.errors)) {
37
- // many legacy responses which are errors: ["error_name"]
38
- error.errors.forEach(function(el, index) {
39
- response.errors[`generic_${index}`] = { msg: el }
40
- })
41
- } else if (typeof(error.errors) === "object") {
42
- response.errors = error.errors
43
- }
44
- }
45
-
46
- return response;
47
- }
48
-
49
- /**
50
- * Desired Response format
51
- *{
52
- * "error": {
53
- * "status": 422,
54
- * "errors": {
55
- * "password": {
56
- * "location": "body",
57
- * "param": "password",
58
- * "value": "mypassword",
59
- * "msg": "weak"
60
- * }
61
- * }
62
- * },
63
- * "error_id": "a2ddf895-2aaf-4189-88a2-8e11f6843f91"
64
- *}
65
- */
66
- formatError(error) {
67
- let response;
68
- if (error === null) {
69
- response = this.defaults;
70
- } else if (typeof(error) === "object") {
71
- response = this._fromHash(error);
72
- } else {
73
- return new FormatError("invalid_error_format");
74
- }
75
-
76
- return response;
77
- }
78
- }
79
-
80
- const formatter = new S4Formatter();
81
- export default formatter;
package/hal/README.md DELETED
@@ -1,54 +0,0 @@
1
- # HAL DECORATOR
2
-
3
- A module to add HAL decoration to JSON responses in Sequelize ORM based projects.
4
-
5
- ## Usage
6
-
7
- In your model definition, set decoration on your model
8
-
9
- ```
10
- import { halDecorator as decorator } from "@sera4/essentia"
11
- ...
12
-
13
- module.exports = (sequelize, DataTypes) => {
14
- const Post = sequelize.define('Post', {...}, {...});
15
- // configure the decorator (optional)
16
- const configs = {
17
- links: {
18
- "self" : {
19
- "get": "/:id/post/"
20
- },
21
- "update" : {
22
- "post": "/:id/post/"
23
- }
24
- },
25
- resource: "/posts",
26
- exclude : ["created_at", "updated_at"],
27
- linksTag : "myLinks",
28
- resourceTag: "myResource"
29
- }
30
- decorator.decorate(Post, configs)
31
- return Post;
32
- };
33
- ```
34
-
35
- The above configuration (which is optional) should produce the following JSON for each instance of Post sent out to the client:
36
- ```
37
- {
38
- "myLinks": {
39
- "self": {
40
- "get": "/posts/42801"
41
- },
42
- "update": {
43
- "post": "/posts/42801"
44
- }
45
- },
46
- "myResource": {
47
- "id": 42801,
48
- "title": "LJitZgbNPLpOlnkYdynKlSYnCjuLBYiVHYMfAPlSALeoVTuNKw",
49
- "name": "cvnititqxdPnHdomgxJJVGynNInkScmDlkzAALunYFHNRjffqE",
50
- "content": "LcURropLnJiudElgAVhsBSMRBRNUzHLDiTebZxxpplXdpeGEFa"
51
- }
52
- }
53
- ```
54
- The links use a similar pattern for parameters interpolation like the express route. For example `/posts/:id/by_user/:user_id` becomes `/posts/20/by_user/123`. If no matching attribute is found on the record, the variable is not replaced.
package/hal/index.js DELETED
@@ -1,75 +0,0 @@
1
- "use strict"
2
-
3
- function lastElement(arr) {
4
- if (arr && arr.length) {
5
- return arr[arr.length - 1];
6
- } else {
7
- return null;
8
- }
9
- }
10
-
11
- class HalDecorator {
12
-
13
- decorate(Model, options) {
14
- const model = Model.instance || Model;
15
- const resource = (options && options.resource) ? options.resource : "";
16
- const exclude = (options && options.exclude) ? options.exclude : [];
17
- const links = (options && options.links) ? options.links : {};
18
- const linksTag = (options && options.linksTag) ? options.linksTag : "_links";
19
- const resourceTag = (options && options.resourceTag) ? options.resourceTag : "_resource";
20
-
21
- const link = (name, method, l) => {
22
- if (name && method && l) {
23
- var aLink = {};
24
- alink[method] = l;
25
- links[name] = aLink;
26
- }
27
- return model;
28
- }
29
-
30
- const getLinkData = (values) => {
31
- var linkData = {};
32
- if (links) {
33
- for (const key in links) {
34
- if (links.hasOwnProperty(key)) {
35
- const link = links[key];
36
- const method = lastElement(Object.keys(link));
37
- var url = link[method];
38
- const paramPattern = /\:([a-zA-z_0-9]*)/;
39
- const arr = paramPattern.exec(url);
40
- if (arr) {
41
- // Replace parameters
42
- url = `/${resource}/${url.split(arr[0]).join(values[arr[1]])}`;
43
- // Remove extra slashes that may have been added
44
- url = url.replace(/\/\/*/g, "/");
45
- linkData[key] = {}
46
- linkData[key][method] = url;
47
- }
48
- }
49
- }
50
- }
51
- return Object.keys(linkData).length > 0 ? linkData : null;
52
- }
53
-
54
- model.link = link;
55
- Model.prototype.toJSON = function() {
56
- var values = Object.assign({}, this.get());
57
- if (exclude) {
58
- exclude.forEach(element => {
59
- delete values[element];
60
- });
61
- }
62
- const links = getLinkData(values);
63
- const result = {}
64
- if (links) {
65
- result[linksTag] = links;
66
- }
67
- result[resourceTag] = values;
68
- return result;
69
- };
70
- }
71
- }
72
-
73
-
74
- const halDecorator = new HalDecorator();
75
- export default halDecorator;
@@ -1,40 +0,0 @@
1
- import logger from "../logger/s4-logger.js";
2
- let enabled = false;
3
-
4
- const helpers = {
5
- debug(...args) {
6
- if (enabled) {
7
- logger.debug(":: HealthCheck ::", args);
8
- }
9
- },
10
-
11
- log(...args) {
12
- if (enabled) {
13
- logger.debug(":: HealthCheck ::", args);
14
- }
15
- },
16
-
17
- warn(...args) {
18
- if (enabled) {
19
- logger.warn(":: HealthCheck ::", args);
20
- }
21
- },
22
-
23
- info(...args) {
24
- if (enabled) {
25
- logger.info(":: HealthCheck ::", args);
26
- }
27
- },
28
-
29
- error(...args) {
30
- if (enabled) {
31
- logger.error(":: HealthCheck ::", args);
32
- }
33
- },
34
-
35
- setEnabled(e) {
36
- enabled = e;
37
- }
38
- }
39
-
40
- export default helpers;