prostgles-server 4.0.57 → 4.0.59

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 (221) hide show
  1. package/dist/DboBuilder/getColumns.d.ts.map +1 -1
  2. package/dist/DboBuilder/getColumns.js +1 -13
  3. package/dist/DboBuilder/getColumns.js.map +1 -1
  4. package/dist/DboBuilder/runSQL.js +2 -2
  5. package/dist/DboBuilder/runSQL.js.map +1 -1
  6. package/dist/Prostgles.d.ts.map +1 -1
  7. package/dist/PubSubManager/PubSubManager.d.ts +1 -1
  8. package/dist/PubSubManager/PubSubManager.d.ts.map +1 -1
  9. package/dist/PubSubManager/PubSubManager.js +14 -1
  10. package/dist/PubSubManager/PubSubManager.js.map +1 -1
  11. package/lib/DboBuilder/getColumns.ts +1 -18
  12. package/lib/DboBuilder/runSQL.ts +2 -2
  13. package/lib/Prostgles.ts +3 -3
  14. package/lib/PubSubManager/PubSubManager.ts +14 -1
  15. package/package.json +2 -2
  16. package/tests/client/PID.txt +1 -1
  17. package/tests/client/package.json +2 -2
  18. package/tests/client/tsconfig.json +2 -1
  19. package/tests/isomorphic_queries.ts +11 -9
  20. package/tests/server/DBoGenerated.d.ts +1 -1
  21. package/tests/server/dboTypeCheck.ts +3 -3
  22. package/tests/server/index.ts +7 -6
  23. package/tests/server/package-lock.json +1 -1
  24. package/tests/server/package.json +3 -3
  25. package/tests/server/publishTypeCheck.ts +1 -1
  26. package/tests/server/tsconfig.json +3 -2
  27. package/tests/test.sh +2 -0
  28. package/dist/FileManager.d.ts +0 -143
  29. package/dist/FileManager.d.ts.map +0 -1
  30. package/dist/FileManager.js +0 -646
  31. package/dist/FileManager.js.map +0 -1
  32. package/dist/TableConfig.d.ts +0 -267
  33. package/dist/TableConfig.d.ts.map +0 -1
  34. package/dist/TableConfig.js +0 -463
  35. package/dist/TableConfig.js.map +0 -1
  36. package/dist/validation.d.ts +0 -126
  37. package/dist/validation.d.ts.map +0 -1
  38. package/dist/validation.js +0 -405
  39. package/dist/validation.js.map +0 -1
  40. package/lib/AuthHandler.d.ts +0 -187
  41. package/lib/AuthHandler.d.ts.map +0 -1
  42. package/lib/AuthHandler.js +0 -478
  43. package/lib/DBEventsManager.d.ts +0 -38
  44. package/lib/DBEventsManager.d.ts.map +0 -1
  45. package/lib/DBEventsManager.js +0 -140
  46. package/lib/DBSchemaBuilder.d.ts +0 -13
  47. package/lib/DBSchemaBuilder.d.ts.map +0 -1
  48. package/lib/DBSchemaBuilder.js +0 -145
  49. package/lib/DboBuilder/QueryBuilder/Functions.d.ts +0 -64
  50. package/lib/DboBuilder/QueryBuilder/Functions.d.ts.map +0 -1
  51. package/lib/DboBuilder/QueryBuilder/Functions.js +0 -984
  52. package/lib/DboBuilder/QueryBuilder/QueryBuilder.d.ts +0 -73
  53. package/lib/DboBuilder/QueryBuilder/QueryBuilder.d.ts.map +0 -1
  54. package/lib/DboBuilder/QueryBuilder/QueryBuilder.js +0 -335
  55. package/lib/DboBuilder/QueryBuilder/makeSelectQuery.d.ts +0 -8
  56. package/lib/DboBuilder/QueryBuilder/makeSelectQuery.d.ts.map +0 -1
  57. package/lib/DboBuilder/QueryBuilder/makeSelectQuery.js +0 -227
  58. package/lib/DboBuilder/TableHandler.d.ts +0 -37
  59. package/lib/DboBuilder/TableHandler.d.ts.map +0 -1
  60. package/lib/DboBuilder/TableHandler.js +0 -213
  61. package/lib/DboBuilder/ViewHandler.d.ts +0 -119
  62. package/lib/DboBuilder/ViewHandler.d.ts.map +0 -1
  63. package/lib/DboBuilder/ViewHandler.js +0 -1023
  64. package/lib/DboBuilder/delete.d.ts +0 -6
  65. package/lib/DboBuilder/delete.d.ts.map +0 -1
  66. package/lib/DboBuilder/delete.js +0 -128
  67. package/lib/DboBuilder/find.d.ts +0 -8
  68. package/lib/DboBuilder/find.d.ts.map +0 -1
  69. package/lib/DboBuilder/find.js +0 -91
  70. package/lib/DboBuilder/getColumns.d.ts +0 -12
  71. package/lib/DboBuilder/getColumns.d.ts.map +0 -1
  72. package/lib/DboBuilder/getColumns.js +0 -92
  73. package/lib/DboBuilder/getCondition.d.ts +0 -22
  74. package/lib/DboBuilder/getCondition.d.ts.map +0 -1
  75. package/lib/DboBuilder/getCondition.js +0 -236
  76. package/lib/DboBuilder/getSubscribeRelatedTables.d.ts +0 -20
  77. package/lib/DboBuilder/getSubscribeRelatedTables.d.ts.map +0 -1
  78. package/lib/DboBuilder/getSubscribeRelatedTables.js +0 -152
  79. package/lib/DboBuilder/getTablesForSchemaPostgresSQL.d.ts +0 -3
  80. package/lib/DboBuilder/getTablesForSchemaPostgresSQL.d.ts.map +0 -1
  81. package/lib/DboBuilder/getTablesForSchemaPostgresSQL.js +0 -207
  82. package/lib/DboBuilder/insert.d.ts +0 -6
  83. package/lib/DboBuilder/insert.d.ts.map +0 -1
  84. package/lib/DboBuilder/insert.js +0 -180
  85. package/lib/DboBuilder/insertDataParse.d.ts +0 -12
  86. package/lib/DboBuilder/insertDataParse.d.ts.map +0 -1
  87. package/lib/DboBuilder/insertDataParse.js +0 -253
  88. package/lib/DboBuilder/parseUpdateRules.d.ts +0 -18
  89. package/lib/DboBuilder/parseUpdateRules.d.ts.map +0 -1
  90. package/lib/DboBuilder/parseUpdateRules.js +0 -123
  91. package/lib/DboBuilder/runSQL.d.ts +0 -7
  92. package/lib/DboBuilder/runSQL.d.ts.map +0 -1
  93. package/lib/DboBuilder/runSQL.js +0 -135
  94. package/lib/DboBuilder/subscribe.d.ts +0 -20
  95. package/lib/DboBuilder/subscribe.d.ts.map +0 -1
  96. package/lib/DboBuilder/subscribe.js +0 -90
  97. package/lib/DboBuilder/update.d.ts +0 -6
  98. package/lib/DboBuilder/update.d.ts.map +0 -1
  99. package/lib/DboBuilder/update.js +0 -151
  100. package/lib/DboBuilder/uploadFile.d.ts +0 -7
  101. package/lib/DboBuilder/uploadFile.d.ts.map +0 -1
  102. package/lib/DboBuilder/uploadFile.js +0 -53
  103. package/lib/DboBuilder.d.ts +0 -306
  104. package/lib/DboBuilder.d.ts.map +0 -1
  105. package/lib/DboBuilder.js +0 -745
  106. package/lib/Event_Trigger_Tags.d.ts +0 -4
  107. package/lib/Event_Trigger_Tags.d.ts.map +0 -1
  108. package/lib/Event_Trigger_Tags.js +0 -116
  109. package/lib/FileManager/FileManager.d.ts +0 -135
  110. package/lib/FileManager/FileManager.d.ts.map +0 -1
  111. package/lib/FileManager/FileManager.js +0 -303
  112. package/lib/FileManager/initFileManager.d.ts +0 -4
  113. package/lib/FileManager/initFileManager.d.ts.map +0 -1
  114. package/lib/FileManager/initFileManager.js +0 -231
  115. package/lib/FileManager/parseFile.d.ts +0 -15
  116. package/lib/FileManager/parseFile.d.ts.map +0 -1
  117. package/lib/FileManager/parseFile.js +0 -58
  118. package/lib/FileManager/upload.d.ts +0 -6
  119. package/lib/FileManager/upload.d.ts.map +0 -1
  120. package/lib/FileManager/upload.js +0 -98
  121. package/lib/FileManager/uploadStream.d.ts +0 -5
  122. package/lib/FileManager/uploadStream.d.ts.map +0 -1
  123. package/lib/FileManager/uploadStream.js +0 -92
  124. package/lib/Filtering.d.ts +0 -15
  125. package/lib/Filtering.d.ts.map +0 -1
  126. package/lib/Filtering.js +0 -336
  127. package/lib/JSONBValidation/validate_jsonb_schema_sql.d.ts +0 -4
  128. package/lib/JSONBValidation/validate_jsonb_schema_sql.d.ts.map +0 -1
  129. package/lib/JSONBValidation/validate_jsonb_schema_sql.js +0 -500
  130. package/lib/JSONBValidation/validation.d.ts +0 -9
  131. package/lib/JSONBValidation/validation.d.ts.map +0 -1
  132. package/lib/JSONBValidation/validation.js +0 -131
  133. package/lib/PostgresNotifListenManager.d.ts +0 -28
  134. package/lib/PostgresNotifListenManager.d.ts.map +0 -1
  135. package/lib/PostgresNotifListenManager.js +0 -134
  136. package/lib/Prostgles.d.ts +0 -289
  137. package/lib/Prostgles.d.ts.map +0 -1
  138. package/lib/Prostgles.js +0 -685
  139. package/lib/PubSubManager/PubSubManager.d.ts +0 -175
  140. package/lib/PubSubManager/PubSubManager.d.ts.map +0 -1
  141. package/lib/PubSubManager/PubSubManager.js +0 -452
  142. package/lib/PubSubManager/addSub.d.ts +0 -8
  143. package/lib/PubSubManager/addSub.d.ts.map +0 -1
  144. package/lib/PubSubManager/addSub.js +0 -166
  145. package/lib/PubSubManager/addSync.d.ts +0 -8
  146. package/lib/PubSubManager/addSync.d.ts.map +0 -1
  147. package/lib/PubSubManager/addSync.js +0 -109
  148. package/lib/PubSubManager/getInitQuery.d.ts +0 -9
  149. package/lib/PubSubManager/getInitQuery.d.ts.map +0 -1
  150. package/lib/PubSubManager/getInitQuery.js +0 -552
  151. package/lib/PubSubManager/initPubSubManager.d.ts +0 -3
  152. package/lib/PubSubManager/initPubSubManager.d.ts.map +0 -1
  153. package/lib/PubSubManager/initPubSubManager.js +0 -116
  154. package/lib/PubSubManager/notifListener.d.ts +0 -5
  155. package/lib/PubSubManager/notifListener.d.ts.map +0 -1
  156. package/lib/PubSubManager/notifListener.js +0 -100
  157. package/lib/PubSubManager/pushSubData.d.ts +0 -3
  158. package/lib/PubSubManager/pushSubData.d.ts.map +0 -1
  159. package/lib/PubSubManager/pushSubData.js +0 -51
  160. package/lib/PublishParser.d.ts +0 -284
  161. package/lib/PublishParser.d.ts.map +0 -1
  162. package/lib/PublishParser.js +0 -421
  163. package/lib/SchemaWatch.d.ts +0 -13
  164. package/lib/SchemaWatch.d.ts.map +0 -1
  165. package/lib/SchemaWatch.js +0 -35
  166. package/lib/SyncReplication.d.ts +0 -34
  167. package/lib/SyncReplication.d.ts.map +0 -1
  168. package/lib/SyncReplication.js +0 -412
  169. package/lib/TableConfig/TableConfig.d.ts +0 -284
  170. package/lib/TableConfig/TableConfig.d.ts.map +0 -1
  171. package/lib/TableConfig/TableConfig.js +0 -437
  172. package/lib/TableConfig/getColumnDefinitionQuery.d.ts +0 -27
  173. package/lib/TableConfig/getColumnDefinitionQuery.d.ts.map +0 -1
  174. package/lib/TableConfig/getColumnDefinitionQuery.js +0 -87
  175. package/lib/TableConfig/getConstraintDefinitionQueries.d.ts +0 -34
  176. package/lib/TableConfig/getConstraintDefinitionQueries.d.ts.map +0 -1
  177. package/lib/TableConfig/getConstraintDefinitionQueries.js +0 -65
  178. package/lib/TableConfig/getFutureTableSchema.d.ts +0 -15
  179. package/lib/TableConfig/getFutureTableSchema.d.ts.map +0 -1
  180. package/lib/TableConfig/getFutureTableSchema.js +0 -43
  181. package/lib/TableConfig/getTableColumnQueries.d.ts +0 -16
  182. package/lib/TableConfig/getTableColumnQueries.d.ts.map +0 -1
  183. package/lib/TableConfig/getTableColumnQueries.js +0 -107
  184. package/lib/index.d.ts +0 -5
  185. package/lib/index.d.ts.map +0 -1
  186. package/lib/index.js +0 -7
  187. package/lib/shortestPath.d.ts +0 -10
  188. package/lib/shortestPath.d.ts.map +0 -1
  189. package/lib/shortestPath.js +0 -111
  190. package/lib/utils.d.ts +0 -3
  191. package/lib/utils.d.ts.map +0 -1
  192. package/lib/utils.js +0 -12
  193. package/tests/client/index.d.ts +0 -2
  194. package/tests/client/index.d.ts.map +0 -1
  195. package/tests/client/index.js +0 -80
  196. package/tests/client/index.js.map +0 -1
  197. package/tests/client_only_queries.d.ts +0 -4
  198. package/tests/client_only_queries.d.ts.map +0 -1
  199. package/tests/client_only_queries.js +0 -282
  200. package/tests/config_test/DBoGenerated.d.ts +0 -388
  201. package/tests/config_test/index.js +0 -174
  202. package/tests/config_test/index.js.map +0 -1
  203. package/tests/isomorphic_queries.d.ts +0 -9
  204. package/tests/isomorphic_queries.d.ts.map +0 -1
  205. package/tests/isomorphic_queries.js +0 -773
  206. package/tests/manual_test/DBoGenerated.d.ts +0 -398
  207. package/tests/manual_test/index.d.ts +0 -2
  208. package/tests/manual_test/index.d.ts.map +0 -1
  209. package/tests/manual_test/index.js +0 -65
  210. package/tests/server/dboTypeCheck.d.ts +0 -2
  211. package/tests/server/dboTypeCheck.d.ts.map +0 -1
  212. package/tests/server/dboTypeCheck.js +0 -27
  213. package/tests/server/index.d.ts +0 -2
  214. package/tests/server/index.d.ts.map +0 -1
  215. package/tests/server/index.js +0 -507
  216. package/tests/server/publishTypeCheck.d.ts +0 -2
  217. package/tests/server/publishTypeCheck.d.ts.map +0 -1
  218. package/tests/server/publishTypeCheck.js +0 -130
  219. package/tests/server_only_queries.d.ts +0 -2
  220. package/tests/server_only_queries.d.ts.map +0 -1
  221. package/tests/server_only_queries.js +0 -19
@@ -1,421 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PublishParser = void 0;
4
- const prostgles_types_1 = require("prostgles-types");
5
- const DboBuilder_1 = require("./DboBuilder");
6
- const Prostgles_1 = require("./Prostgles");
7
- const RULE_TO_METHODS = [
8
- {
9
- rule: "getColumns",
10
- sqlRule: "select",
11
- methods: prostgles_types_1.RULE_METHODS.getColumns,
12
- no_limits: true,
13
- allowed_params: [],
14
- table_only: false,
15
- hint: ` expecting false | true | undefined`
16
- },
17
- {
18
- rule: "getInfo",
19
- sqlRule: "select",
20
- methods: prostgles_types_1.RULE_METHODS.getInfo,
21
- no_limits: true,
22
- allowed_params: [],
23
- table_only: false,
24
- hint: ` expecting false | true | undefined`
25
- },
26
- {
27
- rule: "insert",
28
- sqlRule: "insert",
29
- methods: prostgles_types_1.RULE_METHODS.insert,
30
- no_limits: { fields: "*" },
31
- table_only: true,
32
- allowed_params: ["fields", "forcedData", "returningFields", "validate", "preValidate", "postValidate"],
33
- hint: ` expecting "*" | true | { fields: string | string[] | {} }`
34
- },
35
- {
36
- rule: "update",
37
- sqlRule: "update",
38
- methods: prostgles_types_1.RULE_METHODS.update,
39
- no_limits: { fields: "*", filterFields: "*", returningFields: "*" },
40
- table_only: true,
41
- allowed_params: ["fields", "filterFields", "forcedFilter", "forcedData", "returningFields", "validate", "postValidate", "dynamicFields"],
42
- hint: ` expecting "*" | true | { fields: string | string[] | {} }`
43
- },
44
- {
45
- rule: "select",
46
- sqlRule: "select",
47
- methods: prostgles_types_1.RULE_METHODS.select,
48
- no_limits: { fields: "*", filterFields: "*" },
49
- table_only: false,
50
- allowed_params: ["fields", "filterFields", "forcedFilter", "validate", "maxLimit", "orderByFields"],
51
- hint: ` expecting "*" | true | { fields: ( string | string[] | {} ) }`
52
- },
53
- {
54
- rule: "delete",
55
- sqlRule: "delete",
56
- methods: prostgles_types_1.RULE_METHODS.delete,
57
- no_limits: { filterFields: "*" },
58
- table_only: true,
59
- allowed_params: ["filterFields", "forcedFilter", "returningFields", "validate"],
60
- hint: ` expecting "*" | true | { filterFields: ( string | string[] | {} ) } \n Will use "select", "update", "delete" and "insert" rules`
61
- },
62
- {
63
- rule: "sync",
64
- sqlRule: "select",
65
- methods: prostgles_types_1.RULE_METHODS.sync,
66
- no_limits: null,
67
- table_only: true,
68
- allowed_params: ["id_fields", "synced_field", "sync_type", "allow_delete", "throttle", "batch_size"],
69
- hint: ` expecting "*" | true | { id_fields: string[], synced_field: string }`
70
- },
71
- {
72
- rule: "subscribe",
73
- sqlRule: "select",
74
- methods: prostgles_types_1.RULE_METHODS.subscribe,
75
- no_limits: { throttle: 0 },
76
- table_only: false,
77
- allowed_params: ["throttle", "throttleOpts"],
78
- hint: ` expecting "*" | true | { throttle: number; throttleOpts?: { skipFirst?: boolean; } } \n Will use "select" rules`
79
- }
80
- ];
81
- const PubSubManager_1 = require("./PubSubManager/PubSubManager");
82
- class PublishParser {
83
- publish;
84
- publishMethods;
85
- publishRawSQL;
86
- dbo;
87
- db;
88
- prostgles;
89
- constructor(publish, publishMethods, publishRawSQL, dbo, db, prostgles) {
90
- this.publish = publish;
91
- this.publishMethods = publishMethods;
92
- this.publishRawSQL = publishRawSQL;
93
- this.dbo = dbo;
94
- this.db = db;
95
- this.prostgles = prostgles;
96
- if (!this.dbo || !this.publish)
97
- throw "INTERNAL ERROR: dbo and/or publish missing";
98
- }
99
- async getPublishParams(localParams, clientInfo) {
100
- if (!this.dbo)
101
- throw "dbo missing";
102
- return {
103
- ...(clientInfo || await this.prostgles.authHandler?.getClientInfo(localParams)),
104
- dbo: this.dbo,
105
- db: this.db,
106
- socket: localParams.socket,
107
- tables: (this.prostgles.dboBuilder.tablesOrViews ?? []).map(({ name, columns }) => ({
108
- name,
109
- columns,
110
- info: this.dbo[name].tableOrViewInfo
111
- }))
112
- };
113
- }
114
- async getAllowedMethods(socket, userData) {
115
- const methods = {};
116
- const publishParams = await this.getPublishParams({ socket }, userData);
117
- const _methods = await applyParamsIfFunc(this.publishMethods, publishParams);
118
- if (_methods && Object.keys(_methods).length) {
119
- (0, prostgles_types_1.getKeys)(_methods).map(key => {
120
- const isFuncLike = (maybeFunc) => (typeof maybeFunc === "function" || maybeFunc && typeof maybeFunc.then === "function");
121
- const method = _methods[key];
122
- if (method && (isFuncLike(method) || (0, prostgles_types_1.isObject)(method) && isFuncLike(method.run))) {
123
- methods[key] = _methods[key];
124
- }
125
- else {
126
- throw `invalid publishMethods item -> ${key} \n Expecting a function or promise`;
127
- }
128
- });
129
- }
130
- return methods;
131
- }
132
- /**
133
- * Parses the first level of publish. (If false then nothing if * then all tables and views)
134
- * @param socket
135
- * @param user
136
- */
137
- async getPublish(localParams, clientInfo) {
138
- const publishParams = await this.getPublishParams(localParams, clientInfo);
139
- const _publish = await applyParamsIfFunc(this.publish, publishParams);
140
- if (_publish === "*") {
141
- const publish = {};
142
- this.prostgles.dboBuilder.tablesOrViews?.map(tov => {
143
- publish[tov.name] = "*";
144
- });
145
- return publish;
146
- }
147
- return _publish;
148
- }
149
- async getValidatedRequestRuleWusr({ tableName, command, localParams }) {
150
- const clientInfo = await this.prostgles.authHandler.getClientInfo(localParams);
151
- return await this.getValidatedRequestRule({ tableName, command, localParams }, clientInfo);
152
- }
153
- async getValidatedRequestRule({ tableName, command, localParams }, clientInfo) {
154
- if (!this.dbo)
155
- throw "INTERNAL ERROR: dbo is missing";
156
- if (!command || !tableName)
157
- throw "command OR tableName are missing";
158
- //@ts-ignore
159
- const rtm = RULE_TO_METHODS.find(rtms => rtms.methods.includes(command));
160
- if (!rtm) {
161
- throw "Invalid command: " + command;
162
- }
163
- /* Must be local request -> allow everything */
164
- if (!localParams || (!localParams.socket && !localParams.httpReq)) {
165
- return RULE_TO_METHODS.reduce((a, v) => ({
166
- ...a,
167
- [v.rule]: v.no_limits
168
- }), {});
169
- }
170
- /* Must be from socket. Must have a publish */
171
- if (!this.publish)
172
- throw "publish is missing";
173
- /* Get any publish errors for socket */
174
- const schm = localParams?.socket?.prostgles?.schema?.[tableName]?.[command];
175
- if (schm && schm.err)
176
- throw schm.err;
177
- const table_rule = await this.getTableRules({ tableName, localParams }, clientInfo);
178
- if (!table_rule)
179
- throw { stack: ["getValidatedRequestRule()"], message: "Invalid or disallowed table: " + tableName };
180
- if (command === "upsert") {
181
- if (!table_rule.update || !table_rule.insert) {
182
- throw { stack: ["getValidatedRequestRule()"], message: `Invalid or disallowed command: upsert` };
183
- }
184
- }
185
- if (rtm && table_rule && table_rule[rtm.rule]) {
186
- return table_rule;
187
- }
188
- else
189
- throw { stack: ["getValidatedRequestRule()"], message: `Invalid or disallowed command: ${tableName}.${command}` };
190
- }
191
- async getTableRules({ tableName, localParams }, clientInfo) {
192
- if (!localParams || !tableName)
193
- throw { stack: ["getTableRules()"], message: "publish OR socket OR dbo OR tableName are missing" };
194
- const _publish = await this.getPublish(localParams, clientInfo);
195
- const raw_table_rules = _publish[tableName];
196
- if (!raw_table_rules || (0, prostgles_types_1.isObject)(raw_table_rules) && Object.values(raw_table_rules).every(v => !v)) {
197
- return undefined;
198
- }
199
- let parsed_table = {};
200
- /* Get view or table specific rules */
201
- const tHandler = this.dbo[tableName];
202
- const is_view = tHandler.is_view;
203
- const canSubscribe = (!is_view || tHandler.columns.some(c => c.references));
204
- if (!tHandler) {
205
- throw { stack: ["getTableRules()"], message: `${tableName} could not be found in dbo` };
206
- }
207
- //@ts-ignore
208
- const MY_RULES = RULE_TO_METHODS.filter(r => {
209
- /** Check PG User privileges */
210
- const pgUserIsAllowedThis = tHandler.tableOrViewInfo.privileges[r.sqlRule];
211
- let result = (!is_view || !r.table_only) && pgUserIsAllowedThis;
212
- if (!pgUserIsAllowedThis && (0, DboBuilder_1.isPlainObject)(raw_table_rules) && raw_table_rules[r.sqlRule]) {
213
- throw `Your postgres user is not allowed ${r.sqlRule} on table ${tableName}`;
214
- }
215
- if ((r.rule === "subscribe" || r.rule === "sync") && !this.prostgles.isSuperUser) {
216
- result = false;
217
- if ((0, DboBuilder_1.isPlainObject)(raw_table_rules) && raw_table_rules[r.rule]) {
218
- throw `Cannot publish realtime rule ${tableName}.${r.rule}. Superuser is required for this`;
219
- }
220
- }
221
- if (r.rule === "subscribe" && !canSubscribe) {
222
- result = false;
223
- }
224
- return result;
225
- });
226
- /* All methods allowed. Add no limits for table rules */
227
- if ([true, "*"].includes(raw_table_rules)) {
228
- parsed_table = {};
229
- MY_RULES.filter(r => r.no_limits).forEach(r => {
230
- parsed_table[r.rule] = { ...r.no_limits };
231
- });
232
- /** Specific rules allowed */
233
- }
234
- else if ((0, DboBuilder_1.isPlainObject)(raw_table_rules) && (0, prostgles_types_1.getKeys)(raw_table_rules).length) {
235
- const allRuleKeys = (0, prostgles_types_1.getKeys)(raw_table_rules);
236
- const dissallowedRuleKeys = allRuleKeys.filter(m => !raw_table_rules[m]);
237
- MY_RULES.map(r => {
238
- /** Unless specifically disabled these are allowed */
239
- if (["getInfo", "getColumns"].includes(r.rule) && !dissallowedRuleKeys.includes(r.rule)) {
240
- parsed_table[r.rule] = r.no_limits;
241
- return;
242
- }
243
- /** Add no_limit values for implied/ fully allowed methods */
244
- if ([true, "*"].includes(raw_table_rules[r.rule]) && r.no_limits) {
245
- parsed_table[r.rule] = Object.assign({}, r.no_limits);
246
- /** Carry over detailed config */
247
- }
248
- else if ((0, DboBuilder_1.isPlainObject)(raw_table_rules[r.rule])) {
249
- parsed_table[r.rule] = raw_table_rules[r.rule];
250
- }
251
- });
252
- allRuleKeys.filter(m => parsed_table[m])
253
- .forEach((method) => {
254
- const rule = parsed_table[method];
255
- const rm = MY_RULES.find(r => r.rule === method || r.methods.includes(method));
256
- if (!rm) {
257
- let extraInfo = "";
258
- if (is_view && RULE_TO_METHODS.find(r => !is_view && r.rule === method || r.methods.includes(method))) {
259
- extraInfo = "You've specified table rules to a view\n";
260
- }
261
- throw `Invalid rule in publish.${tableName} -> ${method} \n${extraInfo}Expecting any of: ${MY_RULES.flatMap(r => [r.rule, ...r.methods]).join(", ")}`;
262
- }
263
- /* Check RULES for invalid params */
264
- /* Methods do not have params -> They use them from rules */
265
- if (method === rm.rule && (0, prostgles_types_1.isObject)(rule)) {
266
- const method_params = (0, prostgles_types_1.getKeys)(rule);
267
- const iparam = method_params.find(p => !rm?.allowed_params.includes(p));
268
- if (iparam) {
269
- throw `Invalid setting in publish.${tableName}.${method} -> ${iparam}. \n Expecting any of: ${rm.allowed_params.join(", ")}`;
270
- }
271
- }
272
- /* Add default params (if missing) */
273
- if (method === "sync") {
274
- if ([true, "*"].includes(parsed_table[method])) {
275
- throw "Invalid sync rule. Expecting { id_fields: string[], synced_field: string } ";
276
- }
277
- if (typeof parsed_table[method]?.throttle !== "number") {
278
- parsed_table[method].throttle = 100;
279
- }
280
- if (typeof parsed_table[method]?.batch_size !== "number") {
281
- parsed_table[method].batch_size = PubSubManager_1.DEFAULT_SYNC_BATCH_SIZE;
282
- }
283
- }
284
- /* Enable subscribe if not explicitly disabled OR if VIEW with referenced tables */
285
- const subKey = "subscribe";
286
- if (method === "select" && !dissallowedRuleKeys.includes(subKey)) {
287
- const sr = MY_RULES.find(r => r.rule === subKey);
288
- if (sr && canSubscribe) {
289
- parsed_table[subKey] = { ...sr.no_limits };
290
- parsed_table.subscribeOne = { ...sr.no_limits };
291
- }
292
- }
293
- });
294
- }
295
- else {
296
- throw "Unexpected publish";
297
- }
298
- const getImpliedMethods = (tableRules) => {
299
- const res = { ...tableRules };
300
- /* Add implied methods if not specifically dissallowed */
301
- MY_RULES.map(r => {
302
- /** THIS IS A MESS -> some methods cannot be dissallowed (unsync, unsubscribe...) */
303
- r.methods.forEach(method => {
304
- const isAllowed = tableRules[r.rule] && tableRules[method] === undefined;
305
- if (isAllowed) {
306
- if (method === "updateBatch" && !tableRules.update) {
307
- // not allowed
308
- }
309
- else if (method === "upsert" && (!tableRules.update || !tableRules.insert)) {
310
- // not allowed
311
- }
312
- else {
313
- res[method] ??= true;
314
- }
315
- }
316
- });
317
- });
318
- return res;
319
- };
320
- parsed_table = getImpliedMethods(parsed_table);
321
- return parsed_table;
322
- }
323
- /* Prepares schema for client. Only allowed views and commands will be present */
324
- async getSchemaFromPublish(socket, userData) {
325
- const schema = {};
326
- const tables = [];
327
- try {
328
- /* Publish tables and views based on socket */
329
- const clientInfo = userData ?? await this.prostgles.authHandler?.getClientInfo({ socket });
330
- let _publish;
331
- try {
332
- _publish = await this.getPublish(socket, clientInfo);
333
- }
334
- catch (err) {
335
- console.error("Error within then Publish function ", err);
336
- throw err;
337
- }
338
- if (_publish && Object.keys(_publish).length) {
339
- let txKey = "tx";
340
- if (!this.prostgles.opts.transactions)
341
- txKey = "";
342
- if (typeof this.prostgles.opts.transactions === "string")
343
- txKey = this.prostgles.opts.transactions;
344
- const tableNames = Object.keys(_publish).filter(k => !txKey || txKey !== k);
345
- await Promise.all(tableNames
346
- .map(async (tableName) => {
347
- if (!this.dbo[tableName]) {
348
- throw `Table ${tableName} does not exist
349
- Expecting one of: ${this.prostgles.dboBuilder.tablesOrViews?.map(tov => tov.name).join(", ")}
350
- DBO tables: ${Object.keys(this.dbo).filter(k => this.dbo[k].find).join(", ")}
351
- `;
352
- }
353
- const table_rules = await this.getTableRules({ localParams: { socket }, tableName }, clientInfo);
354
- if (table_rules && Object.keys(table_rules).length) {
355
- schema[tableName] = {};
356
- const tableSchema = schema[tableName];
357
- let methods = [];
358
- let tableInfo;
359
- let tableColumns;
360
- if (typeof table_rules === "object") {
361
- methods = (0, prostgles_types_1.getKeys)(table_rules);
362
- }
363
- await Promise.all(methods.filter(m => m !== "select").map(async (method) => {
364
- if (method === "sync" && table_rules[method]) {
365
- /* Pass sync info */
366
- tableSchema[method] = table_rules[method];
367
- }
368
- else if (table_rules[method]) {
369
- tableSchema[method] = {};
370
- /* Test for issues with the common table CRUD methods () */
371
- if (Prostgles_1.TABLE_METHODS.includes(method)) {
372
- let err = null;
373
- try {
374
- const valid_table_command_rules = await this.getValidatedRequestRule({ tableName, command: method, localParams: { socket } }, clientInfo);
375
- await this.dbo[tableName][method]({}, {}, {}, valid_table_command_rules, { socket, isRemoteRequest: true, testRule: true });
376
- }
377
- catch (e) {
378
- err = "INTERNAL PUBLISH ERROR";
379
- tableSchema[method] = { err };
380
- throw `publish.${tableName}.${method}: \n -> ${e}`;
381
- }
382
- }
383
- if (method === "getInfo" || method === "getColumns") {
384
- const tableRules = await this.getValidatedRequestRule({ tableName, command: method, localParams: { socket } }, clientInfo);
385
- const res = await this.dbo[tableName][method](undefined, undefined, undefined, tableRules, { socket, isRemoteRequest: true });
386
- if (method === "getInfo") {
387
- tableInfo = res;
388
- }
389
- else if (method === "getColumns") {
390
- tableColumns = res;
391
- }
392
- }
393
- }
394
- }));
395
- if (tableInfo && tableColumns) {
396
- tables.push({
397
- name: tableName,
398
- info: tableInfo,
399
- columns: tableColumns
400
- });
401
- }
402
- }
403
- return true;
404
- }));
405
- }
406
- }
407
- catch (e) {
408
- console.error("Prostgles \nERRORS IN PUBLISH: ", JSON.stringify(e));
409
- throw e;
410
- }
411
- return { schema, tables };
412
- }
413
- }
414
- exports.PublishParser = PublishParser;
415
- function applyParamsIfFunc(maybeFunc, ...params) {
416
- if ((maybeFunc !== null && maybeFunc !== undefined) &&
417
- (typeof maybeFunc === "function" || typeof maybeFunc.then === "function")) {
418
- return maybeFunc(...params);
419
- }
420
- return maybeFunc;
421
- }
@@ -1,13 +0,0 @@
1
- /// <reference types="node" />
2
- import { DboBuilder } from "./DboBuilder";
3
- import { ProstglesInitOptions } from "./Prostgles";
4
- export type VoidFunction = () => void;
5
- export declare class SchemaWatch {
6
- schema_checkIntervalMillis?: NodeJS.Timeout;
7
- loaded: boolean;
8
- constructor({ watchSchema, watchSchemaType, tsGeneratedTypesDir, currDbuilder, onSchemaChanged }: ProstglesInitOptions & {
9
- currDbuilder: DboBuilder;
10
- onSchemaChanged: VoidFunction;
11
- });
12
- }
13
- //# sourceMappingURL=SchemaWatch.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SchemaWatch.d.ts","sourceRoot":"","sources":["SchemaWatch.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,MAAM,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC;AAEtC,qBAAa,WAAW;IACtB,0BAA0B,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC;IAC5C,MAAM,UAAS;gBAEH,EAAE,WAAW,EAAE,eAAe,EAAE,mBAAmB,EAAE,YAAY,EAAE,eAAe,EAAE,EAAE,oBAAoB,GAAG;QAAE,YAAY,EAAE,UAAU,CAAC;QAAC,eAAe,EAAE,YAAY,CAAA;KAAE;CA8BrL"}
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SchemaWatch = void 0;
4
- const prostgles_types_1 = require("prostgles-types");
5
- const DboBuilder_1 = require("./DboBuilder");
6
- class SchemaWatch {
7
- schema_checkIntervalMillis;
8
- loaded = false;
9
- constructor({ watchSchema, watchSchemaType, tsGeneratedTypesDir, currDbuilder, onSchemaChanged }) {
10
- if (!watchSchema)
11
- return;
12
- if (watchSchema === "hotReloadMode" && !tsGeneratedTypesDir) {
13
- throw "tsGeneratedTypesDir option is needed for watchSchema: hotReloadMode to work ";
14
- }
15
- else if ((0, prostgles_types_1.isObject)(watchSchemaType) &&
16
- "checkIntervalMillis" in watchSchemaType &&
17
- typeof watchSchemaType.checkIntervalMillis === "number") {
18
- if (this.schema_checkIntervalMillis) {
19
- clearInterval(this.schema_checkIntervalMillis);
20
- }
21
- this.schema_checkIntervalMillis = setInterval(async () => {
22
- if (!this.loaded)
23
- return;
24
- const dbuilder = await DboBuilder_1.DboBuilder.create(this);
25
- if (dbuilder.tsTypesDefinition !== currDbuilder.tsTypesDefinition) {
26
- onSchemaChanged();
27
- }
28
- }, watchSchemaType.checkIntervalMillis);
29
- }
30
- else if (watchSchemaType === "DDL_trigger") {
31
- /** Do nothing */
32
- }
33
- }
34
- }
35
- exports.SchemaWatch = SchemaWatch;
@@ -1,34 +0,0 @@
1
- import { PubSubManager, SyncParams } from "./PubSubManager/PubSubManager";
2
- import { AnyObject } from "prostgles-types";
3
- export type ClientSyncInfo = Partial<{
4
- c_fr: AnyObject;
5
- c_lr: AnyObject;
6
- /**
7
- * PG count is ussually string due to bigint
8
- */
9
- c_count: number | string;
10
- }>;
11
- export type ServerSyncInfo = Partial<{
12
- s_fr: AnyObject;
13
- s_lr: AnyObject;
14
- /**
15
- * PG count is ussually string due to bigint
16
- */
17
- s_count: number | string;
18
- }>;
19
- export type SyncBatchInfo = Partial<{
20
- from_synced: number | null;
21
- to_synced: number | null;
22
- end_offset: number | null;
23
- }>;
24
- export type onSyncRequestResponse = {
25
- onSyncRequest?: ClientSyncInfo;
26
- } | {
27
- err: AnyObject | string;
28
- };
29
- export type ClientExpressData = ClientSyncInfo & {
30
- data?: AnyObject[];
31
- deleted?: AnyObject[];
32
- };
33
- export declare const syncData: (_this: PubSubManager, sync: SyncParams, clientData: ClientExpressData | undefined, source: "trigger" | "client") => Promise<void>;
34
- //# sourceMappingURL=SyncReplication.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SyncReplication.d.ts","sourceRoot":"","sources":["SyncReplication.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,UAAU,EAA2B,MAAM,+BAA+B,CAAC;AACnG,OAAO,EAAgB,SAAS,EAAmB,MAAM,iBAAiB,CAAC;AAG3E,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC;IACnC,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,SAAS,CAAC;IAChB;;OAEG;IACH,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;CAC1B,CAAC,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC;IACnC,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,SAAS,CAAC;IAChB;;OAEG;IACH,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;CAC1B,CAAC,CAAA;AAEF,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC;IAClC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B,CAAC,CAAC;AAEH,MAAM,MAAM,qBAAqB,GAAG;IAClC,aAAa,CAAC,EAAE,cAAc,CAAA;CAC/B,GAAG;IACF,GAAG,EAAE,SAAS,GAAG,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,cAAc,GAAG;IAC/C,IAAI,CAAC,EAAE,SAAS,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC;CACvB,CAAA;AAMD,eAAO,MAAM,QAAQ,UAAiB,aAAa,QAAQ,UAAU,cAAc,iBAAiB,GAAG,SAAS,UAAU,SAAS,GAAG,QAAQ,kBA0d7I,CAAA"}