prostgles-server 3.0.87 → 3.0.89

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 (212) hide show
  1. package/.eslintignore +5 -0
  2. package/.eslintrc.json +30 -0
  3. package/dist/DBEventsManager.js +1 -1
  4. package/dist/DBEventsManager.js.map +1 -1
  5. package/dist/DBSchemaBuilder.d.ts.map +1 -1
  6. package/dist/DBSchemaBuilder.js +6 -6
  7. package/dist/DBSchemaBuilder.js.map +1 -1
  8. package/dist/DboBuilder/QueryBuilder/Functions.js +9 -9
  9. package/dist/DboBuilder/QueryBuilder/Functions.js.map +1 -1
  10. package/dist/DboBuilder/QueryBuilder/QueryBuilder.d.ts.map +1 -1
  11. package/dist/DboBuilder/QueryBuilder/QueryBuilder.js +8 -7
  12. package/dist/DboBuilder/QueryBuilder/QueryBuilder.js.map +1 -1
  13. package/dist/DboBuilder/QueryBuilder/makeSelectQuery.d.ts.map +1 -1
  14. package/dist/DboBuilder/QueryBuilder/makeSelectQuery.js +4 -4
  15. package/dist/DboBuilder/QueryBuilder/makeSelectQuery.js.map +1 -1
  16. package/dist/DboBuilder/TableHandler.d.ts.map +1 -1
  17. package/dist/DboBuilder/TableHandler.js +18 -20
  18. package/dist/DboBuilder/TableHandler.js.map +1 -1
  19. package/dist/DboBuilder/ViewHandler.d.ts +0 -10
  20. package/dist/DboBuilder/ViewHandler.d.ts.map +1 -1
  21. package/dist/DboBuilder/ViewHandler.js +50 -63
  22. package/dist/DboBuilder/ViewHandler.js.map +1 -1
  23. package/dist/DboBuilder/delete.js +0 -1
  24. package/dist/DboBuilder/delete.js.map +1 -1
  25. package/dist/DboBuilder/getColumns.js +5 -4
  26. package/dist/DboBuilder/getColumns.js.map +1 -1
  27. package/dist/DboBuilder/getCondition.d.ts.map +1 -1
  28. package/dist/DboBuilder/getCondition.js +6 -6
  29. package/dist/DboBuilder/getCondition.js.map +1 -1
  30. package/dist/DboBuilder/insert.js +15 -16
  31. package/dist/DboBuilder/insert.js.map +1 -1
  32. package/dist/DboBuilder/insertDataParse.d.ts.map +1 -1
  33. package/dist/DboBuilder/insertDataParse.js +9 -10
  34. package/dist/DboBuilder/insertDataParse.js.map +1 -1
  35. package/dist/DboBuilder/parseUpdateRules.js +2 -2
  36. package/dist/DboBuilder/parseUpdateRules.js.map +1 -1
  37. package/dist/DboBuilder/runSQL.d.ts.map +1 -1
  38. package/dist/DboBuilder/runSQL.js +5 -5
  39. package/dist/DboBuilder/runSQL.js.map +1 -1
  40. package/dist/DboBuilder/subscribe.js +3 -3
  41. package/dist/DboBuilder/subscribe.js.map +1 -1
  42. package/dist/DboBuilder/update.js +5 -6
  43. package/dist/DboBuilder/update.js.map +1 -1
  44. package/dist/DboBuilder/uploadFile.d.ts.map +1 -1
  45. package/dist/DboBuilder/uploadFile.js +1 -1
  46. package/dist/DboBuilder/uploadFile.js.map +1 -1
  47. package/dist/DboBuilder.d.ts.map +1 -1
  48. package/dist/DboBuilder.js +13 -14
  49. package/dist/DboBuilder.js.map +1 -1
  50. package/dist/FileManager.d.ts.map +1 -1
  51. package/dist/FileManager.js +3 -5
  52. package/dist/FileManager.js.map +1 -1
  53. package/dist/Filtering.js +7 -7
  54. package/dist/Filtering.js.map +1 -1
  55. package/dist/JSONBValidation/validate_jsonb_schema_sql.d.ts +3 -0
  56. package/dist/JSONBValidation/validate_jsonb_schema_sql.d.ts.map +1 -0
  57. package/dist/JSONBValidation/validate_jsonb_schema_sql.js +295 -0
  58. package/dist/JSONBValidation/validate_jsonb_schema_sql.js.map +1 -0
  59. package/dist/JSONBValidation/validation.d.ts +108 -0
  60. package/dist/JSONBValidation/validation.d.ts.map +1 -0
  61. package/dist/JSONBValidation/validation.js +222 -0
  62. package/dist/JSONBValidation/validation.js.map +1 -0
  63. package/dist/PostgresNotifListenManager.js +1 -1
  64. package/dist/PostgresNotifListenManager.js.map +1 -1
  65. package/dist/Prostgles.d.ts.map +1 -1
  66. package/dist/Prostgles.js +20 -20
  67. package/dist/Prostgles.js.map +1 -1
  68. package/dist/PubSubManager/initPubSubManager.d.ts.map +1 -1
  69. package/dist/PubSubManager/initPubSubManager.js +10 -7
  70. package/dist/PubSubManager/initPubSubManager.js.map +1 -1
  71. package/dist/PublishParser.d.ts.map +1 -1
  72. package/dist/PublishParser.js +122 -125
  73. package/dist/PublishParser.js.map +1 -1
  74. package/dist/SyncReplication.d.ts.map +1 -1
  75. package/dist/SyncReplication.js +19 -16
  76. package/dist/SyncReplication.js.map +1 -1
  77. package/dist/TableConfig.d.ts +9 -5
  78. package/dist/TableConfig.d.ts.map +1 -1
  79. package/dist/TableConfig.js +33 -12
  80. package/dist/TableConfig.js.map +1 -1
  81. package/dist/index.js +1 -1
  82. package/dist/index.js.map +1 -1
  83. package/dist/shortestPath.js +11 -11
  84. package/dist/shortestPath.js.map +1 -1
  85. package/dist/validation.d.ts +50 -24
  86. package/dist/validation.d.ts.map +1 -1
  87. package/dist/validation.js +177 -53
  88. package/dist/validation.js.map +1 -1
  89. package/lib/AuthHandler.d.ts +11 -11
  90. package/lib/AuthHandler.d.ts.map +1 -1
  91. package/lib/DBEventsManager.js +1 -1
  92. package/lib/DBEventsManager.ts +1 -1
  93. package/lib/DBSchemaBuilder.d.ts +3 -3
  94. package/lib/DBSchemaBuilder.d.ts.map +1 -1
  95. package/lib/DBSchemaBuilder.js +6 -6
  96. package/lib/DBSchemaBuilder.ts +10 -12
  97. package/lib/DboBuilder/QueryBuilder/Functions.d.ts +3 -3
  98. package/lib/DboBuilder/QueryBuilder/Functions.d.ts.map +1 -1
  99. package/lib/DboBuilder/QueryBuilder/Functions.js +9 -9
  100. package/lib/DboBuilder/QueryBuilder/Functions.ts +13 -13
  101. package/lib/DboBuilder/QueryBuilder/QueryBuilder.d.ts +3 -3
  102. package/lib/DboBuilder/QueryBuilder/QueryBuilder.d.ts.map +1 -1
  103. package/lib/DboBuilder/QueryBuilder/QueryBuilder.js +8 -7
  104. package/lib/DboBuilder/QueryBuilder/QueryBuilder.ts +12 -12
  105. package/lib/DboBuilder/QueryBuilder/makeSelectQuery.d.ts.map +1 -1
  106. package/lib/DboBuilder/QueryBuilder/makeSelectQuery.js +4 -4
  107. package/lib/DboBuilder/QueryBuilder/makeSelectQuery.ts +5 -5
  108. package/lib/DboBuilder/TableHandler.d.ts +1 -1
  109. package/lib/DboBuilder/TableHandler.d.ts.map +1 -1
  110. package/lib/DboBuilder/TableHandler.js +18 -20
  111. package/lib/DboBuilder/TableHandler.ts +21 -20
  112. package/lib/DboBuilder/ViewHandler.d.ts +1 -11
  113. package/lib/DboBuilder/ViewHandler.d.ts.map +1 -1
  114. package/lib/DboBuilder/ViewHandler.js +50 -63
  115. package/lib/DboBuilder/ViewHandler.ts +68 -97
  116. package/lib/DboBuilder/delete.js +0 -1
  117. package/lib/DboBuilder/delete.ts +1 -1
  118. package/lib/DboBuilder/getColumns.js +5 -4
  119. package/lib/DboBuilder/getColumns.ts +5 -5
  120. package/lib/DboBuilder/getCondition.d.ts.map +1 -1
  121. package/lib/DboBuilder/getCondition.js +6 -6
  122. package/lib/DboBuilder/getCondition.ts +7 -7
  123. package/lib/DboBuilder/insert.js +15 -16
  124. package/lib/DboBuilder/insert.ts +18 -18
  125. package/lib/DboBuilder/insertDataParse.d.ts.map +1 -1
  126. package/lib/DboBuilder/insertDataParse.js +9 -10
  127. package/lib/DboBuilder/insertDataParse.ts +42 -43
  128. package/lib/DboBuilder/parseUpdateRules.js +2 -2
  129. package/lib/DboBuilder/parseUpdateRules.ts +2 -2
  130. package/lib/DboBuilder/runSQL.d.ts.map +1 -1
  131. package/lib/DboBuilder/runSQL.js +5 -5
  132. package/lib/DboBuilder/runSQL.ts +6 -6
  133. package/lib/DboBuilder/subscribe.d.ts +1 -1
  134. package/lib/DboBuilder/subscribe.d.ts.map +1 -1
  135. package/lib/DboBuilder/subscribe.js +3 -3
  136. package/lib/DboBuilder/subscribe.ts +3 -3
  137. package/lib/DboBuilder/update.js +5 -6
  138. package/lib/DboBuilder/update.ts +6 -6
  139. package/lib/DboBuilder/uploadFile.d.ts.map +1 -1
  140. package/lib/DboBuilder/uploadFile.js +1 -1
  141. package/lib/DboBuilder/uploadFile.ts +2 -2
  142. package/lib/DboBuilder.d.ts +22 -22
  143. package/lib/DboBuilder.d.ts.map +1 -1
  144. package/lib/DboBuilder.js +13 -14
  145. package/lib/DboBuilder.ts +19 -19
  146. package/lib/FileManager.d.ts +6 -6
  147. package/lib/FileManager.d.ts.map +1 -1
  148. package/lib/FileManager.js +3 -5
  149. package/lib/FileManager.ts +7 -6
  150. package/lib/Filtering.d.ts +1 -1
  151. package/lib/Filtering.d.ts.map +1 -1
  152. package/lib/Filtering.js +7 -7
  153. package/lib/Filtering.ts +7 -7
  154. package/lib/JSONBValidation/validate_jsonb_schema_sql.d.ts +3 -0
  155. package/lib/JSONBValidation/validate_jsonb_schema_sql.d.ts.map +1 -0
  156. package/lib/JSONBValidation/validate_jsonb_schema_sql.js +294 -0
  157. package/lib/JSONBValidation/validate_jsonb_schema_sql.ts +293 -0
  158. package/lib/JSONBValidation/validation.d.ts +108 -0
  159. package/lib/JSONBValidation/validation.d.ts.map +1 -0
  160. package/lib/JSONBValidation/validation.js +221 -0
  161. package/lib/JSONBValidation/validation.ts +332 -0
  162. package/lib/PostgresNotifListenManager.d.ts +1 -1
  163. package/lib/PostgresNotifListenManager.d.ts.map +1 -1
  164. package/lib/PostgresNotifListenManager.js +1 -1
  165. package/lib/PostgresNotifListenManager.ts +1 -1
  166. package/lib/Prostgles.d.ts +14 -14
  167. package/lib/Prostgles.d.ts.map +1 -1
  168. package/lib/Prostgles.js +20 -20
  169. package/lib/Prostgles.ts +22 -21
  170. package/lib/PubSubManager/PubSubManager.d.ts +7 -7
  171. package/lib/PubSubManager/PubSubManager.d.ts.map +1 -1
  172. package/lib/PubSubManager/initPubSubManager.d.ts.map +1 -1
  173. package/lib/PubSubManager/initPubSubManager.js +10 -7
  174. package/lib/PubSubManager/initPubSubManager.ts +12 -7
  175. package/lib/PublishParser.d.ts +32 -32
  176. package/lib/PublishParser.d.ts.map +1 -1
  177. package/lib/PublishParser.js +121 -124
  178. package/lib/PublishParser.ts +125 -127
  179. package/lib/SchemaWatch.d.ts +1 -1
  180. package/lib/SchemaWatch.d.ts.map +1 -1
  181. package/lib/SyncReplication.d.ts +5 -5
  182. package/lib/SyncReplication.d.ts.map +1 -1
  183. package/lib/SyncReplication.js +19 -16
  184. package/lib/SyncReplication.ts +470 -471
  185. package/lib/TableConfig.d.ts +28 -24
  186. package/lib/TableConfig.d.ts.map +1 -1
  187. package/lib/TableConfig.js +33 -12
  188. package/lib/TableConfig.ts +55 -21
  189. package/lib/index.js +1 -1
  190. package/lib/index.ts +1 -1
  191. package/lib/shortestPath.d.ts +1 -1
  192. package/lib/shortestPath.d.ts.map +1 -1
  193. package/lib/shortestPath.js +11 -11
  194. package/lib/shortestPath.ts +11 -11
  195. package/package.json +10 -6
  196. package/tests/client/PID.txt +1 -1
  197. package/tests/client/package-lock.json +53 -31
  198. package/tests/client/package.json +4 -1
  199. package/tests/isomorphic_queries.d.ts +4 -1
  200. package/tests/isomorphic_queries.d.ts.map +1 -1
  201. package/tests/isomorphic_queries.js +38 -30
  202. package/tests/isomorphic_queries.ts +40 -33
  203. package/tests/server/DBoGenerated.d.ts +1 -1
  204. package/tests/server/index.js +8 -7
  205. package/tests/server/index.ts +10 -8
  206. package/tests/server/package-lock.json +76 -58
  207. package/tests/server/package.json +2 -2
  208. package/tests/server/server.ts +2 -3
  209. package/lib/validation.d.ts +0 -100
  210. package/lib/validation.d.ts.map +0 -1
  211. package/lib/validation.js +0 -280
  212. package/lib/validation.ts +0 -360
@@ -10,7 +10,7 @@ async function insert(rowOrRows, param2, param3_unused, tableRules, localParams)
10
10
  try {
11
11
  const { onConflictDoNothing, fixIssues = false } = param2 || {};
12
12
  const { testRule = false, returnQuery = false } = localParams || {};
13
- let { returning } = param2 || {};
13
+ const { returning } = param2 || {};
14
14
  const finalDBtx = localParams?.tx?.dbTX || this.dbTX;
15
15
  if (tableRules?.[ACTION]?.postValidate) {
16
16
  if (!finalDBtx) {
@@ -72,19 +72,19 @@ async function insert(rowOrRows, param2, param3_unused, tableRules, localParams)
72
72
  rowOrRows = {}; //throw "Provide data in param1";
73
73
  /** TODO: use WITH inserted as (query) SELECT jsonb_agg(inserted.*) as validateReturn, userReturning */
74
74
  const originalReturning = await this.prepareReturning(returning, this.parseFieldFilter(returningFields));
75
- let fullReturning = await this.prepareReturning(returning, this.parseFieldFilter("*"));
75
+ const fullReturning = await this.prepareReturning(returning, this.parseFieldFilter("*"));
76
76
  /** Used for postValidate. Add any missing computed returning from original query */
77
77
  fullReturning.concat(originalReturning.filter(s => !fullReturning.some(f => f.alias === s.alias)));
78
78
  const finalSelect = tableRules?.[ACTION]?.postValidate ? fullReturning : originalReturning;
79
- let returningSelect = this.makeReturnQuery(finalSelect);
79
+ const returningSelect = this.makeReturnQuery(finalSelect);
80
80
  const makeQuery = async (_row, isOne = false) => {
81
- let row = { ..._row };
81
+ const row = { ..._row };
82
82
  if (!(0, prostgles_types_1.isObject)(row)) {
83
83
  console.trace(row);
84
84
  throw "\ninvalid insert data provided -> " + JSON.stringify(row);
85
85
  }
86
86
  const { data, allowedCols } = this.validateNewData({ row, forcedData, allowedFields: fields, tableRules, fixIssues });
87
- let _data = { ...data };
87
+ const _data = { ...data };
88
88
  let insertQ = "";
89
89
  if (!Array.isArray(_data) && !(0, prostgles_types_1.getKeys)(_data).length || Array.isArray(_data) && !_data.length) {
90
90
  await tableRules?.[ACTION]?.validate?.(_data, this.dbTX || this.dboBuilder.dbo);
@@ -107,7 +107,7 @@ async function insert(rowOrRows, param2, param3_unused, tableRules, localParams)
107
107
  return insertResult;
108
108
  }
109
109
  if (Array.isArray(data)) {
110
- let queries = await Promise.all(data.map(async (p) => {
110
+ const queries = await Promise.all(data.map(async (p) => {
111
111
  const q = await makeQuery(p);
112
112
  return q;
113
113
  }));
@@ -163,13 +163,12 @@ async function insert(rowOrRows, param2, param3_unused, tableRules, localParams)
163
163
  }
164
164
  }
165
165
  exports.insert = insert;
166
- ;
167
- const removeBuffers = (o) => {
168
- if ((0, DboBuilder_1.isPlainObject)(o)) {
169
- return JSON.stringify((0, prostgles_types_1.getKeys)(o).reduce((a, k) => {
170
- const value = o[k];
171
- return { ...a, [k]: Buffer.isBuffer(value) ? `Buffer[${value.byteLength}][...REMOVED]` : value
172
- };
173
- }, {}));
174
- }
175
- };
166
+ // const removeBuffers = (o: any) => {
167
+ // if(isPlainObject(o)){
168
+ // return JSON.stringify(getKeys(o).reduce((a, k) => {
169
+ // const value = o[k]
170
+ // return { ...a, [k]: Buffer.isBuffer(value)? `Buffer[${value.byteLength}][...REMOVED]` : value
171
+ // }
172
+ // }, {}));
173
+ // }
174
+ // }
@@ -14,7 +14,7 @@ export async function insert(this: TableHandler, rowOrRows: (AnyObject | AnyObje
14
14
  const { onConflictDoNothing, fixIssues = false } = param2 || {};
15
15
  const { testRule = false, returnQuery = false } = localParams || {};
16
16
 
17
- let { returning } = param2 || {};
17
+ const { returning } = param2 || {};
18
18
  const finalDBtx = localParams?.tx?.dbTX || this.dbTX;
19
19
  if(tableRules?.[ACTION]?.postValidate ){
20
20
  if(!finalDBtx){
@@ -83,16 +83,16 @@ export async function insert(this: TableHandler, rowOrRows: (AnyObject | AnyObje
83
83
 
84
84
  /** TODO: use WITH inserted as (query) SELECT jsonb_agg(inserted.*) as validateReturn, userReturning */
85
85
  const originalReturning = await this.prepareReturning(returning, this.parseFieldFilter(returningFields))
86
- let fullReturning = await this.prepareReturning(returning, this.parseFieldFilter("*"));
86
+ const fullReturning = await this.prepareReturning(returning, this.parseFieldFilter("*"));
87
87
 
88
88
  /** Used for postValidate. Add any missing computed returning from original query */
89
89
  fullReturning.concat(originalReturning.filter(s => !fullReturning.some(f => f.alias === s.alias)));
90
90
 
91
91
  const finalSelect = tableRules?.[ACTION]?.postValidate? fullReturning : originalReturning;
92
- let returningSelect = this.makeReturnQuery(finalSelect);
92
+ const returningSelect = this.makeReturnQuery(finalSelect);
93
93
 
94
94
  const makeQuery = async (_row: AnyObject | undefined, isOne = false) => {
95
- let row = { ..._row };
95
+ const row = { ..._row };
96
96
 
97
97
  if (!isObject(row)) {
98
98
  console.trace(row)
@@ -100,7 +100,7 @@ export async function insert(this: TableHandler, rowOrRows: (AnyObject | AnyObje
100
100
  }
101
101
 
102
102
  const { data, allowedCols } = this.validateNewData({ row, forcedData, allowedFields: fields, tableRules, fixIssues });
103
- let _data = { ...data };
103
+ const _data = { ...data };
104
104
 
105
105
  let insertQ = "";
106
106
  if (!Array.isArray(_data) && !getKeys(_data).length || Array.isArray(_data) && !_data.length) {
@@ -126,7 +126,7 @@ export async function insert(this: TableHandler, rowOrRows: (AnyObject | AnyObje
126
126
  }
127
127
 
128
128
  if (Array.isArray(data)) {
129
- let queries = await Promise.all(data.map(async p => {
129
+ const queries = await Promise.all(data.map(async p => {
130
130
  const q = await makeQuery(p);
131
131
  return q;
132
132
  }));
@@ -182,15 +182,15 @@ export async function insert(this: TableHandler, rowOrRows: (AnyObject | AnyObje
182
182
  // ${JSON.stringify(param2 || {}, null, 2)}
183
183
  throw parseError(e, `dbo.${this.name}.${ACTION}()`)
184
184
  }
185
- };
186
-
187
-
188
- const removeBuffers = (o: any) => {
189
- if(isPlainObject(o)){
190
- return JSON.stringify(getKeys(o).reduce((a, k) => {
191
- const value = o[k]
192
- return { ...a, [k]: Buffer.isBuffer(value)? `Buffer[${value.byteLength}][...REMOVED]` : value
193
- }
194
- }, {}));
195
- }
196
- }
185
+ }
186
+
187
+
188
+ // const removeBuffers = (o: any) => {
189
+ // if(isPlainObject(o)){
190
+ // return JSON.stringify(getKeys(o).reduce((a, k) => {
191
+ // const value = o[k]
192
+ // return { ...a, [k]: Buffer.isBuffer(value)? `Buffer[${value.byteLength}][...REMOVED]` : value
193
+ // }
194
+ // }, {}));
195
+ // }
196
+ // }
@@ -1 +1 @@
1
- {"version":3,"file":"insertDataParse.d.ts","sourceRoot":"","sources":["insertDataParse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAW,YAAY,EAAgD,MAAM,iBAAiB,CAAC;AACjH,OAAO,EAAE,WAAW,EAAiB,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C;;GAEG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,YAAY,EAClB,IAAI,EAAE,CAAC,SAAS,GAAG,SAAS,EAAE,CAAC,EAC/B,MAAM,CAAC,EAAE,YAAY,EACrB,aAAa,CAAC,EAAE,SAAS,EACzB,UAAU,CAAC,EAAE,SAAS,EACtB,YAAY,CAAC,EAAE,WAAW,GACzB,OAAO,CAAC;IACT,IAAI,CAAC,EAAE,SAAS,GAAG,SAAS,EAAE,CAAC;IAC/B,YAAY,CAAC,EAAE,SAAS,GAAG,SAAS,EAAE,CAAC;CACxC,CAAC,CAoQD"}
1
+ {"version":3,"file":"insertDataParse.d.ts","sourceRoot":"","sources":["insertDataParse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAW,YAAY,EAAgD,MAAM,iBAAiB,CAAC;AACjH,OAAO,EAAE,WAAW,EAAiB,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C;;GAEG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,YAAY,EAClB,IAAI,EAAE,CAAC,SAAS,GAAG,SAAS,EAAE,CAAC,EAC/B,MAAM,CAAC,EAAE,YAAY,EACrB,aAAa,CAAC,EAAE,SAAS,EACzB,UAAU,CAAC,EAAE,SAAS,EACtB,YAAY,CAAC,EAAE,WAAW,GACzB,OAAO,CAAC;IACT,IAAI,CAAC,EAAE,SAAS,GAAG,SAAS,EAAE,CAAC;IAC/B,YAAY,CAAC,EAAE,SAAS,GAAG,SAAS,EAAE,CAAC;CACxC,CAAC,CAmQD"}
@@ -72,9 +72,8 @@ async function insertDataParse(data, param2, param3_unused, tableRules, _localPa
72
72
  insertResult: await this.dboBuilder.getTX((dbTX, _t) => dbTX[this.name].insert(data, param2, param3_unused, tableRules, { tx: { dbTX, t: _t }, ...localParams }))
73
73
  };
74
74
  }
75
- // if(!dbTX && this.t) dbTX = this.d;
76
75
  const preValidate = tableRules?.insert?.preValidate, validate = tableRules?.insert?.validate;
77
- let _data = await Promise.all((isMultiInsert ? data : [data]).map(async (row) => {
76
+ const _data = await Promise.all((isMultiInsert ? data : [data]).map(async (row) => {
78
77
  if (preValidate) {
79
78
  row = await preValidate(row, this.dbTX || this.dboBuilder.dbo);
80
79
  }
@@ -90,7 +89,7 @@ async function insertDataParse(data, param2, param3_unused, tableRules, _localPa
90
89
  const _this = this.t ? this : dbTX[this.name];
91
90
  const omitedKeys = extraKeys.concat(colInserts.map(c => c.col));
92
91
  // let rootData = isMultiInsert? data.map(d => omitKeys(d, omitedKeys)) : omitKeys(data, omitedKeys);
93
- let rootData = (0, PubSubManager_1.omitKeys)(row, omitedKeys);
92
+ const rootData = (0, PubSubManager_1.omitKeys)(row, omitedKeys);
94
93
  let insertedChildren;
95
94
  let targetTableRules;
96
95
  /** Insert referenced first and then populate root data with referenced keys */
@@ -146,7 +145,7 @@ async function insertDataParse(data, param2, param3_unused, tableRules, _localPa
146
145
  throw `Target table ${tbl2} does not reference any columns from the root table ${this.name}. Cannot do nested insert`;
147
146
  // console.log(childDataItems, JSON.stringify(colsRefT1, null, 2))
148
147
  insertedChildren = await childInsert(childDataItems.map((d) => {
149
- let result = { ...d };
148
+ const result = { ...d };
150
149
  colsRefT1.map(col => {
151
150
  result[col.references[0].cols[0]] = fullRootResult[col.references[0].fcols[0]];
152
151
  });
@@ -173,7 +172,7 @@ async function insertDataParse(data, param2, param3_unused, tableRules, _localPa
173
172
  insertedChildren = await childInsert(childDataItems, targetTable);
174
173
  /* Insert in key_lookup table */
175
174
  await Promise.all(insertedChildren.map(async (t3Child) => {
176
- let tbl2Row = {};
175
+ const tbl2Row = {};
177
176
  colsRefT3.map(col => {
178
177
  tbl2Row[col.name] = t3Child[col.references[0].fcols[0]];
179
178
  });
@@ -192,9 +191,9 @@ async function insertDataParse(data, param2, param3_unused, tableRules, _localPa
192
191
  if (targetTableRules && insertedChildren?.length && returning) {
193
192
  const targetTableHandler = dbTX[targetTable];
194
193
  const targetReturning = await targetTableHandler.prepareReturning("*", targetTableHandler.parseFieldFilter(targetTableRules?.insert?.returningFields));
195
- let clientTargetInserts = insertedChildren.map(d => {
196
- let _d = { ...d };
197
- let res = {};
194
+ const clientTargetInserts = insertedChildren.map(d => {
195
+ const _d = { ...d };
196
+ const res = {};
198
197
  targetReturning.map(r => {
199
198
  res[r.alias] = _d[r.alias];
200
199
  });
@@ -207,11 +206,11 @@ async function insertDataParse(data, param2, param3_unused, tableRules, _localPa
207
206
  }
208
207
  return row;
209
208
  }));
210
- let result = isMultiInsert ? _data : _data[0];
209
+ const result = isMultiInsert ? _data : _data[0];
211
210
  // if(validate && !isNestedInsert){
212
211
  // result = isMultiInsert? await Promise.all(_data.map(async d => await validate({ ...d }))) : await validate({ ..._data[0] });
213
212
  // }
214
- let res = isNestedInsert ?
213
+ const res = isNestedInsert ?
215
214
  { insertResult: result } :
216
215
  { data: result };
217
216
  return res;
@@ -9,11 +9,11 @@ import { uploadFile } from "./uploadFile";
9
9
  * Used for doing referenced inserts within a single transaction
10
10
  */
11
11
  export async function insertDataParse(
12
- this: TableHandler,
13
- data: (AnyObject | AnyObject[]),
14
- param2?: InsertParams,
15
- param3_unused?: undefined,
16
- tableRules?: TableRule,
12
+ this: TableHandler,
13
+ data: (AnyObject | AnyObject[]),
14
+ param2?: InsertParams,
15
+ param3_unused?: undefined,
16
+ tableRules?: TableRule,
17
17
  _localParams?: LocalParams
18
18
  ): Promise<{
19
19
  data?: AnyObject | AnyObject[];
@@ -25,12 +25,12 @@ export async function insertDataParse(
25
25
  const isMultiInsert = Array.isArray(data);
26
26
  const getExtraKeys = (d: AnyObject) => getKeys(d).filter(k => {
27
27
  /* If media then use file insert columns */
28
- if(this.is_media){
28
+ if (this.is_media) {
29
29
  return !this.column_names.concat(MEDIA_COL_NAMES).includes(k)
30
- } else if(!this.columns.find(c => c.name === k)){
31
- if(!isObject(d[k]) && !Array.isArray(d[k])){
30
+ } else if (!this.columns.find(c => c.name === k)) {
31
+ if (!isObject(d[k]) && !Array.isArray(d[k])) {
32
32
  throw new Error("Invalid/Dissalowed field in data: " + k)
33
- } else if(!this.dboBuilder.dbo[k]){
33
+ } else if (!this.dboBuilder.dbo[k]) {
34
34
  throw new Error("Invalid/Dissalowed nested insert table name in data: " + k)
35
35
  }
36
36
  return true;
@@ -41,29 +41,29 @@ export async function insertDataParse(
41
41
  const getColumnInserts = (d: AnyObject) => getKeys(d)
42
42
  .filter(k => d[k] && isObject(d[k]))
43
43
  .map(k => {
44
- const insertedCol = this.columns.find(c =>
45
- c.name === k &&
44
+ const insertedCol = this.columns.find(c =>
45
+ c.name === k &&
46
46
  ALLOWED_COL_TYPES.includes(c.udt_name)
47
47
  );
48
48
  const referencesMultipleTables = insertedCol?.references?.length !== 1;
49
49
  const referencesMultipleColumns = insertedCol?.references?.some(refs => refs.fcols.length !== 1);
50
- if(insertedCol && (
51
- referencesMultipleTables ||
52
- referencesMultipleColumns ||
53
- this.columns.some(c =>
54
- // c.name !== insertedCol.name && // a bit reduntant: Cannot have one col reference two columns
55
- c.references?.some(({ ftable, fcols }) =>
56
- insertedCol.references?.some(inserted =>
57
- ftable === inserted.ftable && // same ftable
58
- fcols[0] !== inserted.fcols[0] // different fcols
59
- )
60
- )
50
+ if (insertedCol && (
51
+ referencesMultipleTables ||
52
+ referencesMultipleColumns ||
53
+ this.columns.some(c =>
54
+ // c.name !== insertedCol.name && // a bit reduntant: Cannot have one col reference two columns
55
+ c.references?.some(({ ftable, fcols }) =>
56
+ insertedCol.references?.some(inserted =>
57
+ ftable === inserted.ftable && // same ftable
58
+ fcols[0] !== inserted.fcols[0] // different fcols
59
+ )
61
60
  )
62
61
  )
63
- ){
62
+ )
63
+ ) {
64
64
  throw "A reference column insert is not possible for multiple column relationships ";
65
65
  }
66
- if(insertedCol){
66
+ if (insertedCol) {
67
67
  return {
68
68
  tableName: insertedCol.references![0].ftable!,
69
69
  col: insertedCol.name,
@@ -73,7 +73,7 @@ export async function insertDataParse(
73
73
  return undefined;
74
74
  }).filter(isDefined);
75
75
 
76
-
76
+
77
77
  /**
78
78
  * True when: nested table data is provided within
79
79
  * [nestedTable] property key
@@ -102,12 +102,11 @@ export async function insertDataParse(
102
102
  )
103
103
  }
104
104
  }
105
- // if(!dbTX && this.t) dbTX = this.d;
106
105
 
107
106
  const preValidate = tableRules?.insert?.preValidate,
108
107
  validate = tableRules?.insert?.validate;
109
108
 
110
- let _data = await Promise.all((isMultiInsert? data : [data]).map(async row => {
109
+ const _data = await Promise.all((isMultiInsert ? data : [data]).map(async row => {
111
110
  if (preValidate) {
112
111
  row = await preValidate(row, this.dbTX || this.dboBuilder.dbo);
113
112
  }
@@ -128,14 +127,14 @@ export async function insertDataParse(
128
127
  const omitedKeys = extraKeys.concat(colInserts.map(c => c.col));
129
128
 
130
129
  // let rootData = isMultiInsert? data.map(d => omitKeys(d, omitedKeys)) : omitKeys(data, omitedKeys);
131
- let rootData: AnyObject = omitKeys(row, omitedKeys);
130
+ const rootData: AnyObject = omitKeys(row, omitedKeys);
132
131
 
133
132
  let insertedChildren: AnyObject[];
134
133
  let targetTableRules: TableRule;
135
134
 
136
135
  /** Insert referenced first and then populate root data with referenced keys */
137
- if(colInserts.length){
138
- for await(const colInsert of colInserts){
136
+ if (colInserts.length) {
137
+ for await (const colInsert of colInserts) {
139
138
  const newLocalParams: LocalParams = {
140
139
  ...(localParams ?? {}),
141
140
  nestedInsert: {
@@ -146,10 +145,10 @@ export async function insertDataParse(
146
145
  }
147
146
  }
148
147
  const colRows = await referencedInsert(_this, dbTX, newLocalParams, colInsert.tableName, row[colInsert.col]);
149
- if(!Array.isArray(colRows) || colRows.length !== 1 || [null, undefined].includes(colRows[0][colInsert.fcol])){
148
+ if (!Array.isArray(colRows) || colRows.length !== 1 || [null, undefined].includes(colRows[0][colInsert.fcol])) {
150
149
  throw new Error("Could not do nested column insert: Unexpected return " + JSON.stringify(colRows))
151
150
  }
152
-
151
+
153
152
  const foreignKey = colRows[0][colInsert.fcol];
154
153
  rootData[colInsert.col] = foreignKey;
155
154
  }
@@ -195,7 +194,7 @@ export async function insertDataParse(
195
194
  // console.log(childDataItems, JSON.stringify(colsRefT1, null, 2))
196
195
  insertedChildren = await childInsert(
197
196
  childDataItems.map((d: AnyObject) => {
198
- let result = { ...d };
197
+ const result = { ...d };
199
198
  colsRefT1.map(col => {
200
199
  result[col.references![0].cols[0]] = fullRootResult[col.references![0].fcols[0]]
201
200
  })
@@ -219,7 +218,7 @@ export async function insertDataParse(
219
218
  if (!cols2 || !(
220
219
  cols2.filter(c => c.references?.[0].ftable === fileTable).length === 1 &&
221
220
  cols2.filter(c => c.references?.[0].ftable === _this.name).length === 1
222
- )){
221
+ )) {
223
222
  console.log({ tbl1, tbl2, tbl3, name: _this.name, tthisName: this.name })
224
223
  throw "Second joining table (" + tbl2 + ") not of expected format. Must contain exactly one reference column for each table (file table and target table) ";
225
224
  }
@@ -228,7 +227,7 @@ export async function insertDataParse(
228
227
 
229
228
  /* Insert in key_lookup table */
230
229
  await Promise.all(insertedChildren.map(async t3Child => {
231
- let tbl2Row: AnyObject = {};
230
+ const tbl2Row: AnyObject = {};
232
231
 
233
232
  colsRefT3.map(col => {
234
233
  tbl2Row[col.name] = t3Child[col.references![0].fcols[0]];
@@ -250,9 +249,9 @@ export async function insertDataParse(
250
249
  if (targetTableRules && insertedChildren?.length && returning) {
251
250
  const targetTableHandler = dbTX![targetTable] as TableHandler;
252
251
  const targetReturning = await targetTableHandler.prepareReturning("*", targetTableHandler.parseFieldFilter(targetTableRules?.insert?.returningFields));
253
- let clientTargetInserts = insertedChildren.map(d => {
254
- let _d = { ...d };
255
- let res: AnyObject = {};
252
+ const clientTargetInserts = insertedChildren.map(d => {
253
+ const _d = { ...d };
254
+ const res: AnyObject = {};
256
255
  targetReturning.map(r => {
257
256
  res[r.alias] = _d[r.alias]
258
257
  });
@@ -269,11 +268,11 @@ export async function insertDataParse(
269
268
  return row;
270
269
  }));
271
270
 
272
- let result = isMultiInsert ? _data : _data[0];
271
+ const result = isMultiInsert ? _data : _data[0];
273
272
  // if(validate && !isNestedInsert){
274
273
  // result = isMultiInsert? await Promise.all(_data.map(async d => await validate({ ...d }))) : await validate({ ..._data[0] });
275
274
  // }
276
- let res = isNestedInsert ?
275
+ const res = isNestedInsert ?
277
276
  { insertResult: result } :
278
277
  { data: result };
279
278
 
@@ -296,7 +295,7 @@ const getJoinPath = async (tableHandler: TableHandler, targetTable: string): Pro
296
295
  const jp = tableHandler.dboBuilder.joinPaths.find(jp => jp.t1 === tableHandler.name && jp.t2 === targetTable);
297
296
  if (!jp) {
298
297
  console.trace(tableHandler.dboBuilder.joinPaths)
299
- const pref = tableHandler.dboBuilder.prostgles.opts.joins !== "inferred"? "Joins are not inferred! " : ""
298
+ const pref = tableHandler.dboBuilder.prostgles.opts.joins !== "inferred" ? "Joins are not inferred! " : ""
300
299
  throw new Error(`${pref}Could not find a single join path for the nested data ( sourceTable: ${tableHandler.name} targetTable: ${targetTable} ) `);
301
300
  }
302
301
  return jp;
@@ -307,7 +306,7 @@ const referencedInsert = async (tableHandler: TableHandler, dbTX: TableHandlers
307
306
 
308
307
  const thisInfo = await tableHandler.getInfo();
309
308
  await getJoinPath(tableHandler, targetTable);
310
-
309
+
311
310
  if (!targetData || !dbTX?.[targetTable] || !("insert" in dbTX[targetTable])) throw new Error("childInsertErr: Table handler missing for referenced table: " + targetTable);
312
311
 
313
312
  const childRules = await canInsert(tableHandler, targetTable, localParams);
@@ -326,5 +325,5 @@ const referencedInsert = async (tableHandler: TableHandler, dbTX: TableHandlers
326
325
  })
327
326
  )
328
327
  );
329
-
328
+
330
329
  }
@@ -87,7 +87,7 @@ async function parseUpdateRules(filter, newData, params, tableRules, localParams
87
87
  try {
88
88
  const { data, allowedCols } = this.validateNewData({ row: forcedData, forcedData: undefined, allowedFields: "*", tableRules, fixIssues: false });
89
89
  const updateQ = await this.colSet.getUpdateQuery(data, allowedCols, this.dbTX || this.dboBuilder.dbo, validate ? ((row) => validate({ update: row, filter: {} }, this.dbTX || this.dboBuilder.dbo)) : undefined); //pgp.helpers.update(data, columnSet)
90
- let query = updateQ + " WHERE FALSE ";
90
+ const query = updateQ + " WHERE FALSE ";
91
91
  await this.db.any("EXPLAIN " + query);
92
92
  }
93
93
  catch (e) {
@@ -98,7 +98,7 @@ async function parseUpdateRules(filter, newData, params, tableRules, localParams
98
98
  }
99
99
  }
100
100
  /* Update all allowed fields (fields) except the forcedFilter (so that the user cannot change the forced filter values) */
101
- let _fields = this.parseFieldFilter(fields);
101
+ const _fields = this.parseFieldFilter(fields);
102
102
  /**
103
103
  * A forced filter must be basic
104
104
  */
@@ -127,7 +127,7 @@ export async function parseUpdateRules(
127
127
  this.dbTX || this.dboBuilder.dbo,
128
128
  validate ? ((row) => validate!({ update: row, filter: {} }, this.dbTX || this.dboBuilder.dbo)) : undefined
129
129
  ) //pgp.helpers.update(data, columnSet)
130
- let query = updateQ + " WHERE FALSE ";
130
+ const query = updateQ + " WHERE FALSE ";
131
131
  await this.db.any("EXPLAIN " + query);
132
132
  } catch (e) {
133
133
  throw " issue with forcedData: \nVALUE: " + JSON.stringify(forcedData, null, 2) + "\nERROR: " + e;
@@ -139,7 +139,7 @@ export async function parseUpdateRules(
139
139
  }
140
140
 
141
141
  /* Update all allowed fields (fields) except the forcedFilter (so that the user cannot change the forced filter values) */
142
- let _fields = this.parseFieldFilter(fields);
142
+ const _fields = this.parseFieldFilter(fields);
143
143
 
144
144
  /**
145
145
  * A forced filter must be basic
@@ -1 +1 @@
1
- {"version":3,"file":"runSQL.d.ts","sourceRoot":"","sources":["runSQL.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,UAAU,EAAa,MAAM,iBAAiB,CAAC;AAC7F,OAAO,EAAE,UAAU,EAAE,WAAW,EAAyB,MAAM,eAAe,CAAC;AAC/E,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAK7C,wBAAsB,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,UAAU,GAAG,SAAS,EAAE,WAAW,CAAC,EAAE,WAAW,gBAuHpI;AAED,eAAO,MAAM,SAAS,cAAqB,SAAS,gBAAgB,WAAW,KAAG,QAAQ,OAAO,CAOhG,CAAA;AAED,eAAO,MAAM,eAAe,cAAmB,QAAQ,OAAO,CAE7D,CAAA"}
1
+ {"version":3,"file":"runSQL.d.ts","sourceRoot":"","sources":["runSQL.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,UAAU,EAAa,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAyB,MAAM,eAAe,CAAC;AAC/E,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAK7C,wBAAsB,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,UAAU,GAAG,SAAS,EAAE,WAAW,CAAC,EAAE,WAAW,gBAuHpI;AAED,eAAO,MAAM,SAAS,cAAqB,SAAS,gBAAgB,WAAW,KAAG,QAAQ,OAAO,CAOhG,CAAA;AAED,eAAO,MAAM,eAAe,cAAmB,QAAQ,OAAO,CAE7D,CAAA"}
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.canCreateTables = exports.canRunSQL = exports.runSQL = void 0;
4
4
  const DboBuilder_1 = require("../DboBuilder");
5
5
  const PubSubManager_1 = require("../PubSubManager/PubSubManager");
6
- const { ParameterizedQuery: PQ } = require('pg-promise');
6
+ const pg_promise_1 = require("pg-promise");
7
7
  async function runSQL(query, params, options, localParams) {
8
8
  if (query?.replace(/\s\s+/g, ' ').toLowerCase().includes("create extension pg_stat_statements")) {
9
9
  const { shared_preload_libraries } = await this.db.oneOrNone('SHOW shared_preload_libraries');
@@ -54,9 +54,9 @@ async function runSQL(query, params, options, localParams) {
54
54
  else if (db) {
55
55
  let finalQuery = query + "";
56
56
  if (returnType === "arrayMode" && !["listen ", "notify "].find(c => query.toLowerCase().trim().startsWith(c))) {
57
- finalQuery = new PQ({ text: hasParams ? DboBuilder_1.pgp.as.format(query, params) : query, rowMode: "array" });
57
+ finalQuery = (new pg_promise_1.ParameterizedQuery({ text: hasParams ? DboBuilder_1.pgp.as.format(query, params) : query, rowMode: "array" }));
58
58
  }
59
- let _qres = await db.result(finalQuery, hasParams ? params : undefined);
59
+ const _qres = await db.result(finalQuery, hasParams ? params : undefined);
60
60
  const { fields, rows, command } = _qres;
61
61
  /**
62
62
  * Fallback for watchSchema in case not superuser and cannot add db event listener
@@ -94,7 +94,7 @@ async function runSQL(query, params, options, localParams) {
94
94
  return rows.map(r => Object.values(r[0]));
95
95
  }
96
96
  else {
97
- let qres = {
97
+ const qres = {
98
98
  duration: 0,
99
99
  ..._qres,
100
100
  fields: fields?.map(f => {
@@ -122,7 +122,7 @@ const canRunSQL = async (prostgles, localParams) => {
122
122
  return true;
123
123
  const { socket } = localParams;
124
124
  const publishParams = await prostgles.publishParser.getPublishParams({ socket });
125
- let res = await prostgles.opts.publishRawSQL?.(publishParams);
125
+ const res = await prostgles.opts.publishRawSQL?.(publishParams);
126
126
  return Boolean(res && typeof res === "boolean" || res === "*");
127
127
  };
128
128
  exports.canRunSQL = canRunSQL;
@@ -1,8 +1,8 @@
1
- import { PG_COLUMN_UDT_DATA_TYPE, SQLHandler, SQLOptions, SQLResult } from "prostgles-types";
1
+ import { AnyObject, SQLOptions, SQLResult } from "prostgles-types";
2
2
  import { DboBuilder, LocalParams, pgp, postgresToTsType } from "../DboBuilder";
3
3
  import { DB, Prostgles } from "../Prostgles";
4
4
  import { PubSubManager } from "../PubSubManager/PubSubManager";
5
- const { ParameterizedQuery: PQ } = require('pg-promise');
5
+ import { ParameterizedQuery as PQ } from 'pg-promise';
6
6
 
7
7
 
8
8
  export async function runSQL(this: DboBuilder, query: string, params: any, options: SQLOptions | undefined, localParams?: LocalParams) {
@@ -56,10 +56,10 @@ export async function runSQL(this: DboBuilder, query: string, params: any, optio
56
56
 
57
57
  let finalQuery = query + "";
58
58
  if (returnType === "arrayMode" && !["listen ", "notify "].find(c => query.toLowerCase().trim().startsWith(c))) {
59
- finalQuery = new PQ({ text: hasParams ? pgp.as.format(query, params) : query, rowMode: "array" });
59
+ finalQuery = (new PQ({ text: hasParams ? pgp.as.format(query, params) : query, rowMode: "array" })) as any;
60
60
  }
61
61
 
62
- let _qres = await db.result(finalQuery, hasParams ? params : undefined)
62
+ const _qres = await db.result<AnyObject>(finalQuery, hasParams ? params : undefined)
63
63
  const { fields, rows, command } = _qres;
64
64
 
65
65
  /**
@@ -100,7 +100,7 @@ export async function runSQL(this: DboBuilder, query: string, params: any, optio
100
100
 
101
101
  } else {
102
102
 
103
- let qres: SQLResult<typeof returnType> = {
103
+ const qres: SQLResult<typeof returnType> = {
104
104
  duration: 0,
105
105
  ..._qres,
106
106
  fields: fields?.map(f => {
@@ -131,7 +131,7 @@ export const canRunSQL = async (prostgles: Prostgles, localParams?: LocalParams)
131
131
 
132
132
  const { socket } = localParams;
133
133
  const publishParams = await prostgles.publishParser!.getPublishParams({ socket });
134
- let res = await prostgles.opts.publishRawSQL?.(publishParams);
134
+ const res = await prostgles.opts.publishRawSQL?.(publishParams);
135
135
  return Boolean(res && typeof res === "boolean" || res === "*");
136
136
  }
137
137
 
@@ -2,7 +2,7 @@ import { AnyObject, SubscribeParams } from "prostgles-types";
2
2
  import { Filter, LocalParams } from "../DboBuilder";
3
3
  import { TableRule } from "../PublishParser";
4
4
  import { ViewHandler } from "./ViewHandler";
5
- export declare type LocalFunc = (items: AnyObject[]) => any;
5
+ export type LocalFunc = (items: AnyObject[]) => any;
6
6
  declare function subscribe(this: ViewHandler, filter: Filter, params: SubscribeParams, localFunc: LocalFunc): Promise<{
7
7
  unsubscribe: () => any;
8
8
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"subscribe.d.ts","sourceRoot":"","sources":["subscribe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAU,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAoC,MAAM,eAAe,CAAC;AACtF,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,oBAAY,SAAS,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,GAAG,CAAC;AAEpD,iBAAe,SAAS,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC;IAAE,WAAW,EAAE,MAAM,GAAG,CAAA;CAAE,CAAC,CAAA;AAC/I,iBAAe,SAAS,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,GAAG,SAAS,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AA4NzL,OAAO,EAAE,SAAS,EAAE,CAAA"}
1
+ {"version":3,"file":"subscribe.d.ts","sourceRoot":"","sources":["subscribe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAU,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAoC,MAAM,eAAe,CAAC;AACtF,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,GAAG,CAAC;AAEpD,iBAAe,SAAS,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC;IAAE,WAAW,EAAE,MAAM,GAAG,CAAA;CAAE,CAAC,CAAA;AAC/I,iBAAe,SAAS,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,GAAG,SAAS,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AA4NzL,OAAO,EAAE,SAAS,EAAE,CAAA"}
@@ -55,7 +55,7 @@ async function subscribe(filter, params, localFunc, table_rules, localParams) {
55
55
  relatedTables: []
56
56
  };
57
57
  viewOptions.relatedTables = await Promise.all(tableIds.map(async (tableID) => {
58
- const table = this.dboBuilder.USER_TABLES?.find(t => t.relid === +tableID);
58
+ const table = this.dboBuilder.USER_TABLES.find(t => t.relid === +tableID);
59
59
  let tableCols = tableColumns.filter(tc => tc.tableID.toString() === tableID);
60
60
  /** If table has primary keys and they are all in this view then use only primary keys */
61
61
  if (table?.pkey_columns?.every(pkey => tableCols.some(c => c.columnName === pkey))) {
@@ -101,7 +101,7 @@ async function subscribe(filter, params, localFunc, table_rules, localParams) {
101
101
  }
102
102
  }
103
103
  return {
104
- tableName: tableName,
104
+ tableName,
105
105
  tableNameEscaped: JSON.stringify(tableName),
106
106
  condition: "TRUE"
107
107
  };
@@ -159,7 +159,7 @@ async function subscribe(filter, params, localFunc, table_rules, localParams) {
159
159
  const pubSubManager = await this.dboBuilder.getPubSubManager();
160
160
  pubSubManager.removeLocalSub(this.name, condition, localFunc);
161
161
  };
162
- let res = Object.freeze({ unsubscribe });
162
+ const res = Object.freeze({ unsubscribe });
163
163
  return res;
164
164
  }
165
165
  }
@@ -75,7 +75,7 @@ async function subscribe(this: ViewHandler, filter: Filter, params: SubscribePar
75
75
  relatedTables: []
76
76
  }
77
77
  viewOptions.relatedTables = await Promise.all(tableIds.map(async tableID => {
78
- const table = this.dboBuilder.USER_TABLES?.find(t => t.relid === +tableID)!;
78
+ const table = this.dboBuilder.USER_TABLES!.find(t => t.relid === +tableID)!;
79
79
  let tableCols = tableColumns.filter(tc => tc.tableID!.toString() === tableID);
80
80
 
81
81
  /** If table has primary keys and they are all in this view then use only primary keys */
@@ -128,7 +128,7 @@ async function subscribe(this: ViewHandler, filter: Filter, params: SubscribePar
128
128
  }
129
129
 
130
130
  return {
131
- tableName: tableName,
131
+ tableName,
132
132
  tableNameEscaped: JSON.stringify(tableName),// [table.schemaname, table.relname].map(v => JSON.stringify(v)).join("."),
133
133
  condition: "TRUE"
134
134
  }
@@ -193,7 +193,7 @@ async function subscribe(this: ViewHandler, filter: Filter, params: SubscribePar
193
193
  const pubSubManager = await this.dboBuilder.getPubSubManager();
194
194
  pubSubManager.removeLocalSub(this.name, condition, localFunc)
195
195
  };
196
- let res: { unsubscribe: () => any } = Object.freeze({ unsubscribe })
196
+ const res: { unsubscribe: () => any } = Object.freeze({ unsubscribe })
197
197
  return res;
198
198
  }
199
199
  } catch (e) {