@sera4/essentia 1.1.65 → 3.0.6

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 (112) hide show
  1. package/README.md +352 -8
  2. package/dist/ts/cache/index.d.ts +33 -0
  3. package/dist/ts/cache/index.js +171 -0
  4. package/dist/ts/cache/index.js.map +1 -0
  5. package/dist/ts/configurations/server-config.d.ts +4 -0
  6. package/dist/ts/configurations/server-config.js +2 -0
  7. package/dist/ts/configurations/server-config.js.map +1 -0
  8. package/dist/ts/constants/index.d.ts +7 -0
  9. package/{constants → dist/ts/constants}/index.js +5 -6
  10. package/dist/ts/constants/index.js.map +1 -0
  11. package/dist/ts/cycle/index.d.ts +53 -0
  12. package/dist/ts/cycle/index.js +169 -0
  13. package/dist/ts/cycle/index.js.map +1 -0
  14. package/dist/ts/dns/DnsCache.d.ts +50 -0
  15. package/dist/ts/dns/DnsCache.js +137 -0
  16. package/dist/ts/dns/DnsCache.js.map +1 -0
  17. package/dist/ts/dns/index.d.ts +4 -0
  18. package/dist/ts/dns/index.js +4 -0
  19. package/dist/ts/dns/index.js.map +1 -0
  20. package/dist/ts/formatter/index.d.ts +44 -0
  21. package/dist/ts/formatter/index.js +76 -0
  22. package/dist/ts/formatter/index.js.map +1 -0
  23. package/dist/ts/hal/index.d.ts +26 -0
  24. package/dist/ts/hal/index.js +70 -0
  25. package/dist/ts/hal/index.js.map +1 -0
  26. package/dist/ts/health/index.d.ts +53 -0
  27. package/dist/ts/health/index.js +165 -0
  28. package/dist/ts/health/index.js.map +1 -0
  29. package/dist/ts/helpers/index.d.ts +1 -0
  30. package/dist/ts/helpers/index.js +2 -0
  31. package/dist/ts/helpers/index.js.map +1 -0
  32. package/dist/ts/helpers/test-server-wrapper.d.ts +56 -0
  33. package/dist/ts/helpers/test-server-wrapper.js +144 -0
  34. package/dist/ts/helpers/test-server-wrapper.js.map +1 -0
  35. package/dist/ts/index.d.ts +21 -0
  36. package/dist/ts/index.js +25 -0
  37. package/dist/ts/index.js.map +1 -0
  38. package/dist/ts/last-commit/index.d.ts +12 -0
  39. package/dist/ts/last-commit/index.js +82 -0
  40. package/dist/ts/last-commit/index.js.map +1 -0
  41. package/dist/ts/logger/index.d.ts +3 -0
  42. package/dist/ts/logger/index.js +4 -0
  43. package/dist/ts/logger/index.js.map +1 -0
  44. package/dist/ts/logger/s4-logger.d.ts +23 -0
  45. package/dist/ts/logger/s4-logger.js +103 -0
  46. package/dist/ts/logger/s4-logger.js.map +1 -0
  47. package/dist/ts/paginator/index.d.ts +2 -0
  48. package/dist/ts/paginator/index.js +3 -0
  49. package/dist/ts/paginator/index.js.map +1 -0
  50. package/dist/ts/paginator/s4-pagination.d.ts +26 -0
  51. package/dist/ts/paginator/s4-pagination.js +49 -0
  52. package/dist/ts/paginator/s4-pagination.js.map +1 -0
  53. package/dist/ts/paginator/sql-pagination.d.ts +52 -0
  54. package/dist/ts/paginator/sql-pagination.js +157 -0
  55. package/dist/ts/paginator/sql-pagination.js.map +1 -0
  56. package/dist/ts/paper-trail/helpers.d.ts +14 -0
  57. package/dist/ts/paper-trail/helpers.js +74 -0
  58. package/dist/ts/paper-trail/helpers.js.map +1 -0
  59. package/dist/ts/paper-trail/index.d.ts +54 -0
  60. package/dist/ts/paper-trail/index.js +236 -0
  61. package/dist/ts/paper-trail/index.js.map +1 -0
  62. package/dist/ts/prompts/index.d.ts +21 -0
  63. package/dist/ts/prompts/index.js +68 -0
  64. package/dist/ts/prompts/index.js.map +1 -0
  65. package/dist/ts/queue/index.d.ts +196 -0
  66. package/dist/ts/queue/index.js +371 -0
  67. package/dist/ts/queue/index.js.map +1 -0
  68. package/dist/ts/queue/publisher.d.ts +41 -0
  69. package/dist/ts/queue/publisher.js +84 -0
  70. package/dist/ts/queue/publisher.js.map +1 -0
  71. package/dist/ts/queue/queue-logger.d.ts +10 -0
  72. package/dist/ts/queue/queue-logger.js +35 -0
  73. package/dist/ts/queue/queue-logger.js.map +1 -0
  74. package/dist/ts/queue/subscriber.d.ts +55 -0
  75. package/dist/ts/queue/subscriber.js +98 -0
  76. package/dist/ts/queue/subscriber.js.map +1 -0
  77. package/dist/ts/safe-proxy/index.d.ts +35 -0
  78. package/dist/ts/safe-proxy/index.js +54 -0
  79. package/dist/ts/safe-proxy/index.js.map +1 -0
  80. package/dist/ts/serializer/index.d.ts +52 -0
  81. package/dist/ts/serializer/index.js +83 -0
  82. package/dist/ts/serializer/index.js.map +1 -0
  83. package/dist/ts/utils/index.d.ts +49 -0
  84. package/dist/ts/utils/index.js +157 -0
  85. package/dist/ts/utils/index.js.map +1 -0
  86. package/package.json +52 -11
  87. package/package.tar.gz +0 -0
  88. package/cache/index.js +0 -188
  89. package/formatter/index.js +0 -81
  90. package/hal/README.md +0 -54
  91. package/hal/index.js +0 -75
  92. package/health/health-logger.js +0 -40
  93. package/health/index.js +0 -188
  94. package/helpers/index.js +0 -1
  95. package/helpers/test-server-wrapper.js +0 -196
  96. package/last-commit.js +0 -12
  97. package/last_commit/index.js +0 -82
  98. package/logger/s4-logger.js +0 -128
  99. package/paginator/README.md +0 -183
  100. package/paginator/s4-pagination.js +0 -51
  101. package/paginator/sql-pagination.js +0 -178
  102. package/paper-trail/README.md +0 -68
  103. package/paper-trail/helpers.js +0 -99
  104. package/paper-trail/index.js +0 -842
  105. package/prompts/index.js +0 -78
  106. package/queue/index.js +0 -414
  107. package/queue/publisher.js +0 -96
  108. package/queue/queue-logger.js +0 -40
  109. package/queue/subscriber.js +0 -107
  110. package/safe_proxy/index.js +0 -61
  111. package/serializer/index.js +0 -90
  112. package/utils/index.js +0 -74
@@ -1,178 +0,0 @@
1
- "use strict"
2
-
3
- class SequelizePaginator {
4
-
5
- constructor() {
6
- this.paginateIn = {
7
- size: "page_size",
8
- index: "page_index"
9
- };
10
- this.paginateOut = {
11
- current_page: "current_page",
12
- first_page: "first_page",
13
- last_page: "last_page",
14
- next_page: "next_page",
15
- out_of_bounds: "out_of_bounds",
16
- page_size: "page_size",
17
- previous_page: "previous_page",
18
- total_pages: "total_pages",
19
- total_size: "total_size",
20
- links: "",
21
- };
22
- this.zeroBasedOffset = true;
23
- this.paginationHeader = "tws-pagination";
24
- this.headersOnly = false;
25
- this.paginationTag = "_pagination";
26
- this.collectionTag = "_collection";
27
- }
28
-
29
- paginate(Model, resource="") {
30
- const model = Model.instance || Model;
31
- const DEFAULT_PAGINATION = {limit : 15, offset: 0}
32
- var pagination = {limit : 15, offset: 0}
33
- var response = null;
34
- var resource = resource;
35
-
36
- const using = (options, resp) => {
37
- response = resp;
38
- var limit = DEFAULT_PAGINATION.limit;
39
- var offset = DEFAULT_PAGINATION.offset;
40
-
41
- if (options && options[this.paginateIn.size]) {
42
- limit = parseInt(options[this.paginateIn.size]);
43
- }
44
- if (options && options[this.paginateIn.index]) {
45
- offset = parseInt(options[this.paginateIn.index]);
46
- }
47
- if (!Number.isInteger(limit) || limit < 1) {
48
- limit = 1;
49
- }
50
- if (!Number.isInteger(offset) || offset < 0) {
51
- offset = 0;
52
- }
53
- if (!this.zeroBasedOffset) {
54
- offset = offset <= 1 ? 0 : offset - 1;
55
- }
56
-
57
- pagination.limit = limit;
58
- pagination.offset = offset;
59
- return model;
60
- }
61
-
62
- const paginate = (options) => {
63
- if (!options) {
64
- options = {};
65
- }
66
- options.limit = pagination.limit;
67
- options.offset = pagination.limit * pagination.offset;
68
-
69
- return new Promise((resolve, reject) => {
70
- model.findAndCountAll(options)
71
- .then(r => {
72
- var paginationData = getPaginationData(r);
73
- if (response) {
74
- response.set(this.paginationHeader, JSON.stringify(paginationData));
75
- }
76
- var data = {};
77
- if (this.headersOnly) {
78
- data = r.rows
79
- } else {
80
- data[this.paginationTag] = addLinks(paginationData);
81
- data[this.collectionTag] = r.rows;
82
- }
83
- resolve(data);
84
- }).catch(e => reject(e));
85
- });
86
- }
87
-
88
- const addLinks = (data) => {
89
- var linksKey = null;
90
- if (this.paginateOut.links === true) {
91
- linksKey = "links"
92
- } else if (this.paginateOut.links) {
93
- linksKey = this.paginateOut.links;
94
- }
95
- if (data && linksKey && !data[this.paginateOut["out_of_bounds"]]) {
96
- var links = {}
97
- var firstPageIndex = this.zeroBasedOffset ? 0 : 1;
98
- var lastPageIndex = this.zeroBasedOffset ? data[this.paginateOut["total_pages"]] - 1 : data[this.paginateOut["total_pages"]];
99
- links[this.paginateOut["first_page"]] = `${resource}?${this.paginateIn["index"]}=${firstPageIndex}&${this.paginateIn["size"]}=${data[this.paginateOut["page_size"]]}`;
100
- links[this.paginateOut["last_page"]] = `${resource}?${this.paginateIn["index"]}=${lastPageIndex}&${this.paginateIn["size"]}=${data[this.paginateOut["page_size"]]}`;
101
- if (!data[this.paginateOut["first_page"]]) {
102
- links[this.paginateOut["previous_page"]] =
103
- `${resource}?${this.paginateIn["index"]}=${data[this.paginateOut["previous_page"]]}&${this.paginateIn["size"]}=${data[this.paginateOut["page_size"]]}`;
104
- }
105
- if (!data[this.paginateOut["last_page"]]) {
106
- links[this.paginateOut["next_page"]] =
107
- `${resource}?${this.paginateIn["index"]}=${data[this.paginateOut["next_page"]]}&${this.paginateIn["size"]}=${data[this.paginateOut["page_size"]]}`;
108
- }
109
- data[linksKey] = links;
110
- }
111
- return data;
112
- }
113
-
114
- const getPaginationData = (result) => {
115
- var currentPage = this.zeroBasedOffset ? pagination.offset : pagination.offset + 1;
116
- var outOfBounds = result.rows.length === 0;
117
-
118
- // For queries with aggregation (Group By, Count), sequelize findAndCountAll returns an array of objects instead of just an integer
119
- // To avoid implementing a custom findAndCountAll, we just use the array's Length
120
- if (Array.isArray(result.count)) {
121
- result.count = result.count.length;
122
- }
123
-
124
- var totalPages = Math.ceil(result.count / pagination.limit);
125
- var data = {};
126
- data[this.paginateOut["current_page"]] = currentPage;
127
- data[this.paginateOut["first_page"]] = outOfBounds ? false : pagination.offset === 0;
128
- data[this.paginateOut["last_page"]] = outOfBounds ? false : (pagination.offset * pagination.limit) + pagination.limit >= result.count;
129
- data[this.paginateOut["page_size"]] = pagination.limit;
130
- data[this.paginateOut["total_pages"]] = totalPages;
131
- data[this.paginateOut["total_size"]] = result.count;
132
- data[this.paginateOut["out_of_bounds"]] = outOfBounds;
133
- if (!outOfBounds) {
134
- if ((this.zeroBasedOffset && currentPage > 0) || (!this.zeroBasedOffset && currentPage > 1)) {
135
- data[this.paginateOut["previous_page"]] = currentPage - 1;
136
- }
137
- if ((this.zeroBasedOffset && currentPage + 1 < totalPages) || (!this.zeroBasedOffset && currentPage < totalPages)) {
138
- data[this.paginateOut["next_page"]] = currentPage + 1;
139
- }
140
- }
141
- return data;
142
- }
143
-
144
- model.using = using;
145
- model.paginate = paginate;
146
- }
147
-
148
- configure(options) {
149
- // Parse the object options
150
- if (options.paginateIn) {
151
- var x = options.paginateIn;
152
- for (var key in this.paginateIn) {
153
- if (this.paginateIn.hasOwnProperty(key) && x.hasOwnProperty(key)) {
154
- this.paginateIn[key] = x[key];
155
- }
156
- }
157
- }
158
- if (options.paginateOut) {
159
- var x = options.paginateOut;
160
- for (var key in this.paginateOut) {
161
- if (this.paginateOut.hasOwnProperty(key) && x.hasOwnProperty(key)) {
162
- this.paginateOut[key] = x[key];
163
- }
164
- }
165
- }
166
- // Parse the simple options
167
- for(var key in this) {
168
- if (!["paginateIn", "paginateOut"].includes(key)) {
169
- if (this.hasOwnProperty(key) && options.hasOwnProperty(key)) {
170
- this[key] = options[key];
171
- }
172
- }
173
- }
174
- }
175
- }
176
-
177
- const sqlPaginator = new SequelizePaginator();
178
- export default sqlPaginator;
@@ -1,68 +0,0 @@
1
- # Sequelize Paper Trail
2
-
3
- A paper trail/sequelize hook plugin. This plugin has been modified to use the node14 CLS API called AsyncLocalStorage as well as fix some of the postgres related bugs. We have kept our own implemnetation and various changes were needed to support the express framework and pushing this to the public would hinder the general usability of this library for all.
4
-
5
- ## Usage
6
-
7
- In your database setup, setup your models and then attach the paperTrail to them. Many default options need to be changed to support underscore notation and the use of Account instead of User as the default table, thus suggestions options for TWS projects are shown below.
8
-
9
- ```
10
- import { paperTrail } from "@sera4/essentia"
11
- import Sequelize from 'sequelize';
12
-
13
- ...
14
-
15
- const sequelize = new Sequelize(...);
16
-
17
- PaperTrail.init(sequelize, Sequelize, { UUID: true,
18
- underscored: true, enableMigration: true, underscoredAttributes: true,
19
- debug: false, userModel: 'Account', enableCompression: true });
20
- };
21
-
22
- const db = {};
23
- // for any model you want enabled
24
- db["Tenant"] = TenantModel(sequelize, Sequelize);
25
-
26
- db.PaperTrail = PaperTrail.init(sequelize, Sequelize, { UUID: true, underscored: true,
27
- enableMigration: true, underscoredAttributes: true, continuationKey: "accountId",
28
- debug: false, userModel: 'Account', userModelAttribute: 'account_id',
29
- enableCompression: true });
30
-
31
- // sending in DB will allow you to access this using db['Revision'] later.
32
- db.PaperTrail.defineModels(db);
33
-
34
- .. and for any model that needs a papertrail, call hasPaperTrail() on it ..
35
- db["Tenant"].hasPaperTrail();
36
- db["TenantLicense"].hasPaperTrail();
37
- ```
38
-
39
- and similarly, to use the automatic ALS (asyncLocalStorage) for automatic setting of the account/userID - add this into your middleware
40
-
41
- ```
42
- import db from "../database/models/index.js";
43
-
44
- let alsEnabled = db.PaperTrail.alsEnabled();
45
-
46
- const localStorageMiddleware = async (req, res, next) => {
47
- await asyncLocalStorage.run(new Map(), () => {
48
- if (!alsEnabled) {
49
- alsEnabled = true;
50
- db.PaperTrail.setupALS(asyncLocalStorage);
51
- }
52
-
53
- next();
54
- });
55
- };
56
- ```
57
- as this will ensure that the ALS context is initialized AFTER the first `run()` invocation.
58
-
59
- `Please note`: For automatic accountId fetching, it is imperitive that you add
60
-
61
- ```
62
- asyncLocalStorage.getStore().set("accountId", accountId);
63
- ```
64
- somewhere into your express middleware so the database hooks can pickup the accountId when changes are made.
65
-
66
- ## History
67
-
68
- This is a private fork/implementation of https://github.com/nielsgl/sequelize-paper-trail which has been released under MIT license. This was privitized due to the number of commented out items/untested in their project as well as the change from CLS (continuation-local-storage) which is experimental to the supported AsyncLocalStorage which was stabilized in Node 14 as the CLS API 101.
@@ -1,99 +0,0 @@
1
- import pkg from 'deep-diff';
2
- import _ from 'lodash';
3
-
4
- const { diff } = pkg;
5
- const capitalizeFirstLetter = string =>
6
- string.charAt(0).toUpperCase() + string.slice(1);
7
-
8
- const toUnderscored = obj => {
9
- _.forEach(obj, (k, v) => {
10
- obj[k] = v
11
- .replace(/(?:^|\.?)([A-Z])/g, (x, y) => `_${y.toLowerCase()}`)
12
- .replace(/^_/, '');
13
- });
14
- return obj;
15
- };
16
-
17
- const calcDelta = (current, next, exclude, strict, DEBUG = false) => {
18
- if (DEBUG) {
19
- console.log('current', current);
20
- console.log('next', next);
21
- console.log('exclude', exclude);
22
- }
23
-
24
- const di = diff(current, next);
25
-
26
- if (DEBUG) {
27
- console.log('di', di);
28
-
29
- let diffs2 = [];
30
- if (di) {
31
- diffs2 = di.map(i =>
32
- JSON.parse(JSON.stringify(i).replace('"__data",', '')),
33
- );
34
- }
35
-
36
- console.log('diffs2', diffs2);
37
-
38
- console.log(
39
- 'filter1',
40
- diffs2.filter(i => i.path.join(',').indexOf('_') === -1),
41
- );
42
-
43
- console.log(
44
- 'filter2',
45
- diffs2.filter(i => exclude.every(x => i.path.indexOf(x) === -1)),
46
- );
47
- }
48
-
49
- let diffs = [];
50
- if (di) {
51
- diffs = di
52
- .map(i => JSON.parse(JSON.stringify(i).replace('"__data",', '')))
53
- .filter(i => {
54
- if (!strict && i.kind === 'E') {
55
- // eslint-disable-next-line eqeqeq
56
- if (i.lhs != i.rhs) return i;
57
- } else return i;
58
- return false;
59
- })
60
- .filter(i => exclude.every(x => i.path.indexOf(x) === -1));
61
- }
62
-
63
- if (diffs.length > 0) {
64
- return diffs;
65
- }
66
- return null;
67
- };
68
-
69
- const diffToString = val => {
70
- if (typeof val === 'undefined' || val === null)
71
- return '';
72
-
73
- if (val === true)
74
- return '1';
75
-
76
- if (val === false)
77
- return '0';
78
-
79
- if (typeof val === 'string')
80
- return val;
81
-
82
- if (!Number.isNaN(Number(val)))
83
- return `${String(val)}`;
84
-
85
- if ((typeof val === 'undefined' ? 'undefined' : typeof val) === 'object')
86
- return `${JSON.stringify(val)}`;
87
-
88
- if (Array.isArray(val))
89
- return `${JSON.stringify(val)}`;
90
-
91
- return '';
92
- };
93
-
94
- export default {
95
- capitalizeFirstLetter,
96
- toUnderscored,
97
- calcDelta,
98
- diffToString
99
- };