prostgles-server 4.2.178 → 4.2.180

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 (215) hide show
  1. package/.vscode/settings.json +10 -1
  2. package/dist/DboBuilder/TableHandler/DataValidator.d.ts +1 -1
  3. package/dist/DboBuilder/TableHandler/DataValidator.d.ts.map +1 -1
  4. package/dist/DboBuilder/TableHandler/DataValidator.js +4 -4
  5. package/dist/DboBuilder/TableHandler/DataValidator.js.map +1 -1
  6. package/dist/DboBuilder/TableHandler/TableHandler.d.ts +1 -1
  7. package/dist/DboBuilder/TableHandler/TableHandler.d.ts.map +1 -1
  8. package/dist/DboBuilder/TableHandler/insert.js +3 -3
  9. package/dist/DboBuilder/TableHandler/insert.js.map +1 -1
  10. package/dist/DboBuilder/TableHandler/update.d.ts.map +1 -1
  11. package/dist/DboBuilder/TableHandler/update.js +45 -19
  12. package/dist/DboBuilder/TableHandler/update.js.map +1 -1
  13. package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts +1 -1
  14. package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts.map +1 -1
  15. package/dist/DboBuilder/ViewHandler/ViewHandler.js +2 -2
  16. package/dist/DboBuilder/ViewHandler/ViewHandler.js.map +1 -1
  17. package/dist/DboBuilder/parseUpdateRules.js +1 -1
  18. package/dist/DboBuilder/parseUpdateRules.js.map +1 -1
  19. package/dist/Logging.d.ts +10 -3
  20. package/dist/Logging.d.ts.map +1 -1
  21. package/dist/Prostgles.d.ts +2 -2
  22. package/dist/Prostgles.d.ts.map +1 -1
  23. package/dist/Prostgles.js +118 -53
  24. package/dist/Prostgles.js.map +1 -1
  25. package/dist/ProstglesTypes.d.ts +77 -23
  26. package/dist/ProstglesTypes.d.ts.map +1 -1
  27. package/dist/ProstglesTypes.js.map +1 -1
  28. package/dist/SyncReplication.js +2 -2
  29. package/dist/SyncReplication.js.map +1 -1
  30. package/dist/initProstgles.d.ts +9 -2
  31. package/dist/initProstgles.d.ts.map +1 -1
  32. package/dist/initProstgles.js +65 -57
  33. package/dist/initProstgles.js.map +1 -1
  34. package/dist/utils.d.ts.map +1 -1
  35. package/dist/utils.js.map +1 -1
  36. package/documentation/CLIENT.md +542 -0
  37. package/documentation/SERVER.md +104 -0
  38. package/documentation/utils/clientTypes.ts +8436 -0
  39. package/documentation/utils/dist/clientTypes.d.ts +7705 -0
  40. package/documentation/utils/dist/clientTypes.d.ts.map +1 -0
  41. package/documentation/utils/dist/clientTypes.js +8438 -0
  42. package/documentation/utils/dist/definitions.d.ts +7705 -0
  43. package/documentation/utils/dist/definitions.d.ts.map +1 -0
  44. package/documentation/utils/dist/definitions.js +8438 -0
  45. package/documentation/utils/dist/generateClientDocs.d.ts +3 -0
  46. package/documentation/utils/dist/generateClientDocs.d.ts.map +1 -0
  47. package/documentation/utils/dist/generateClientDocs.js +115 -0
  48. package/documentation/utils/dist/generateDocs.d.ts +2 -0
  49. package/documentation/utils/dist/generateDocs.d.ts.map +1 -0
  50. package/documentation/utils/dist/generateDocs.js +6 -0
  51. package/documentation/utils/dist/generateMarkdown.d.ts +2 -0
  52. package/documentation/utils/dist/generateMarkdown.d.ts.map +1 -0
  53. package/documentation/utils/dist/generateMarkdown.js +68 -0
  54. package/documentation/utils/dist/generateServerDocs.d.ts +2 -0
  55. package/documentation/utils/dist/generateServerDocs.d.ts.map +1 -0
  56. package/documentation/utils/dist/generateServerDocs.js +80 -0
  57. package/documentation/utils/dist/getResolvedTypes.d.ts +15 -0
  58. package/documentation/utils/dist/getResolvedTypes.d.ts.map +1 -0
  59. package/documentation/utils/dist/getResolvedTypes.js +29 -0
  60. package/documentation/utils/dist/getSerializableType.d.ts +69 -0
  61. package/documentation/utils/dist/getSerializableType.d.ts.map +1 -0
  62. package/documentation/utils/dist/getSerializableType.js +273 -0
  63. package/documentation/utils/dist/getSymbolComments.d.ts +11 -0
  64. package/documentation/utils/dist/getSymbolComments.d.ts.map +1 -0
  65. package/documentation/utils/dist/getSymbolComments.js +60 -0
  66. package/documentation/utils/dist/loadTsFile.d.ts +7 -0
  67. package/documentation/utils/dist/loadTsFile.d.ts.map +1 -0
  68. package/documentation/utils/dist/loadTsFile.js +33 -0
  69. package/documentation/utils/dist/moduleResolver.d.ts +9 -0
  70. package/documentation/utils/dist/moduleResolver.d.ts.map +1 -0
  71. package/documentation/utils/dist/moduleResolver.js +27 -0
  72. package/documentation/utils/dist/serverTypes.d.ts +307 -0
  73. package/documentation/utils/dist/serverTypes.d.ts.map +1 -0
  74. package/documentation/utils/dist/serverTypes.js +347 -0
  75. package/documentation/utils/generateClientDocs.ts +142 -0
  76. package/documentation/utils/generateDocs.ts +4 -0
  77. package/documentation/utils/generateServerDocs.ts +82 -0
  78. package/documentation/utils/getResolvedTypes.ts +45 -0
  79. package/documentation/utils/getSerializableType.ts +479 -0
  80. package/documentation/utils/loadTsFile.ts +45 -0
  81. package/documentation/utils/moduleResolver.ts +31 -0
  82. package/documentation/utils/node_modules/.package-lock.json +67 -0
  83. package/documentation/utils/node_modules/@types/node/LICENSE +21 -0
  84. package/documentation/utils/node_modules/@types/node/README.md +15 -0
  85. package/documentation/utils/node_modules/@types/node/assert/strict.d.ts +8 -0
  86. package/documentation/utils/node_modules/@types/node/assert.d.ts +1040 -0
  87. package/documentation/utils/node_modules/@types/node/async_hooks.d.ts +541 -0
  88. package/documentation/utils/node_modules/@types/node/buffer.buffer.d.ts +385 -0
  89. package/documentation/utils/node_modules/@types/node/buffer.d.ts +1934 -0
  90. package/documentation/utils/node_modules/@types/node/child_process.d.ts +1548 -0
  91. package/documentation/utils/node_modules/@types/node/cluster.d.ts +578 -0
  92. package/documentation/utils/node_modules/@types/node/compatibility/disposable.d.ts +16 -0
  93. package/documentation/utils/node_modules/@types/node/compatibility/index.d.ts +9 -0
  94. package/documentation/utils/node_modules/@types/node/compatibility/indexable.d.ts +20 -0
  95. package/documentation/utils/node_modules/@types/node/compatibility/iterators.d.ts +21 -0
  96. package/documentation/utils/node_modules/@types/node/console.d.ts +452 -0
  97. package/documentation/utils/node_modules/@types/node/constants.d.ts +19 -0
  98. package/documentation/utils/node_modules/@types/node/crypto.d.ts +4519 -0
  99. package/documentation/utils/node_modules/@types/node/dgram.d.ts +596 -0
  100. package/documentation/utils/node_modules/@types/node/diagnostics_channel.d.ts +554 -0
  101. package/documentation/utils/node_modules/@types/node/dns/promises.d.ts +477 -0
  102. package/documentation/utils/node_modules/@types/node/dns.d.ts +864 -0
  103. package/documentation/utils/node_modules/@types/node/dom-events.d.ts +124 -0
  104. package/documentation/utils/node_modules/@types/node/domain.d.ts +170 -0
  105. package/documentation/utils/node_modules/@types/node/events.d.ts +931 -0
  106. package/documentation/utils/node_modules/@types/node/fs/promises.d.ts +1245 -0
  107. package/documentation/utils/node_modules/@types/node/fs.d.ts +4317 -0
  108. package/documentation/utils/node_modules/@types/node/globals.d.ts +468 -0
  109. package/documentation/utils/node_modules/@types/node/globals.typedarray.d.ts +21 -0
  110. package/documentation/utils/node_modules/@types/node/http.d.ts +1944 -0
  111. package/documentation/utils/node_modules/@types/node/http2.d.ts +2555 -0
  112. package/documentation/utils/node_modules/@types/node/https.d.ts +544 -0
  113. package/documentation/utils/node_modules/@types/node/index.d.ts +91 -0
  114. package/documentation/utils/node_modules/@types/node/inspector.d.ts +3696 -0
  115. package/documentation/utils/node_modules/@types/node/module.d.ts +315 -0
  116. package/documentation/utils/node_modules/@types/node/net.d.ts +1005 -0
  117. package/documentation/utils/node_modules/@types/node/os.d.ts +495 -0
  118. package/documentation/utils/node_modules/@types/node/package.json +220 -0
  119. package/documentation/utils/node_modules/@types/node/path.d.ts +200 -0
  120. package/documentation/utils/node_modules/@types/node/perf_hooks.d.ts +934 -0
  121. package/documentation/utils/node_modules/@types/node/process.d.ts +1879 -0
  122. package/documentation/utils/node_modules/@types/node/punycode.d.ts +117 -0
  123. package/documentation/utils/node_modules/@types/node/querystring.d.ts +153 -0
  124. package/documentation/utils/node_modules/@types/node/readline/promises.d.ts +162 -0
  125. package/documentation/utils/node_modules/@types/node/readline.d.ts +589 -0
  126. package/documentation/utils/node_modules/@types/node/repl.d.ts +430 -0
  127. package/documentation/utils/node_modules/@types/node/sea.d.ts +153 -0
  128. package/documentation/utils/node_modules/@types/node/stream/consumers.d.ts +12 -0
  129. package/documentation/utils/node_modules/@types/node/stream/promises.d.ts +90 -0
  130. package/documentation/utils/node_modules/@types/node/stream/web.d.ts +524 -0
  131. package/documentation/utils/node_modules/@types/node/stream.d.ts +1726 -0
  132. package/documentation/utils/node_modules/@types/node/string_decoder.d.ts +67 -0
  133. package/documentation/utils/node_modules/@types/node/test.d.ts +1938 -0
  134. package/documentation/utils/node_modules/@types/node/timers/promises.d.ts +97 -0
  135. package/documentation/utils/node_modules/@types/node/timers.d.ts +240 -0
  136. package/documentation/utils/node_modules/@types/node/tls.d.ts +1217 -0
  137. package/documentation/utils/node_modules/@types/node/trace_events.d.ts +197 -0
  138. package/documentation/utils/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +385 -0
  139. package/documentation/utils/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +19 -0
  140. package/documentation/utils/node_modules/@types/node/ts5.6/index.d.ts +91 -0
  141. package/documentation/utils/node_modules/@types/node/tty.d.ts +208 -0
  142. package/documentation/utils/node_modules/@types/node/url.d.ts +955 -0
  143. package/documentation/utils/node_modules/@types/node/util.d.ts +2306 -0
  144. package/documentation/utils/node_modules/@types/node/v8.d.ts +808 -0
  145. package/documentation/utils/node_modules/@types/node/vm.d.ts +922 -0
  146. package/documentation/utils/node_modules/@types/node/wasi.d.ts +181 -0
  147. package/documentation/utils/node_modules/@types/node/worker_threads.d.ts +694 -0
  148. package/documentation/utils/node_modules/@types/node/zlib.d.ts +539 -0
  149. package/documentation/utils/node_modules/undici-types/LICENSE +21 -0
  150. package/documentation/utils/node_modules/undici-types/README.md +6 -0
  151. package/documentation/utils/node_modules/undici-types/agent.d.ts +31 -0
  152. package/documentation/utils/node_modules/undici-types/api.d.ts +43 -0
  153. package/documentation/utils/node_modules/undici-types/balanced-pool.d.ts +29 -0
  154. package/documentation/utils/node_modules/undici-types/cache.d.ts +36 -0
  155. package/documentation/utils/node_modules/undici-types/client.d.ts +108 -0
  156. package/documentation/utils/node_modules/undici-types/connector.d.ts +34 -0
  157. package/documentation/utils/node_modules/undici-types/content-type.d.ts +21 -0
  158. package/documentation/utils/node_modules/undici-types/cookies.d.ts +28 -0
  159. package/documentation/utils/node_modules/undici-types/diagnostics-channel.d.ts +66 -0
  160. package/documentation/utils/node_modules/undici-types/dispatcher.d.ts +255 -0
  161. package/documentation/utils/node_modules/undici-types/env-http-proxy-agent.d.ts +21 -0
  162. package/documentation/utils/node_modules/undici-types/errors.d.ts +149 -0
  163. package/documentation/utils/node_modules/undici-types/eventsource.d.ts +63 -0
  164. package/documentation/utils/node_modules/undici-types/fetch.d.ts +209 -0
  165. package/documentation/utils/node_modules/undici-types/file.d.ts +39 -0
  166. package/documentation/utils/node_modules/undici-types/filereader.d.ts +54 -0
  167. package/documentation/utils/node_modules/undici-types/formdata.d.ts +108 -0
  168. package/documentation/utils/node_modules/undici-types/global-dispatcher.d.ts +9 -0
  169. package/documentation/utils/node_modules/undici-types/global-origin.d.ts +7 -0
  170. package/documentation/utils/node_modules/undici-types/handlers.d.ts +15 -0
  171. package/documentation/utils/node_modules/undici-types/header.d.ts +4 -0
  172. package/documentation/utils/node_modules/undici-types/index.d.ts +71 -0
  173. package/documentation/utils/node_modules/undici-types/interceptors.d.ts +15 -0
  174. package/documentation/utils/node_modules/undici-types/mock-agent.d.ts +50 -0
  175. package/documentation/utils/node_modules/undici-types/mock-client.d.ts +25 -0
  176. package/documentation/utils/node_modules/undici-types/mock-errors.d.ts +12 -0
  177. package/documentation/utils/node_modules/undici-types/mock-interceptor.d.ts +93 -0
  178. package/documentation/utils/node_modules/undici-types/mock-pool.d.ts +25 -0
  179. package/documentation/utils/node_modules/undici-types/package.json +55 -0
  180. package/documentation/utils/node_modules/undici-types/patch.d.ts +71 -0
  181. package/documentation/utils/node_modules/undici-types/pool-stats.d.ts +19 -0
  182. package/documentation/utils/node_modules/undici-types/pool.d.ts +39 -0
  183. package/documentation/utils/node_modules/undici-types/proxy-agent.d.ts +28 -0
  184. package/documentation/utils/node_modules/undici-types/readable.d.ts +60 -0
  185. package/documentation/utils/node_modules/undici-types/retry-agent.d.ts +8 -0
  186. package/documentation/utils/node_modules/undici-types/retry-handler.d.ts +116 -0
  187. package/documentation/utils/node_modules/undici-types/util.d.ts +18 -0
  188. package/documentation/utils/node_modules/undici-types/webidl.d.ts +222 -0
  189. package/documentation/utils/node_modules/undici-types/websocket.d.ts +152 -0
  190. package/documentation/utils/package-lock.json +75 -0
  191. package/documentation/utils/package.json +14 -0
  192. package/documentation/utils/serverTypes.ts +345 -0
  193. package/documentation/utils/tsconfig.json +28 -0
  194. package/examples/full-example-typescript/DBoGenerated.d.ts +2 -2
  195. package/examples/full-example-typescript/DBoGenerated.ts +2 -2
  196. package/examples/full-example-typescript/index.ts +39 -45
  197. package/examples/full-example-vanilla/index.js +51 -53
  198. package/examples/server/typescript/index.ts +24 -30
  199. package/lib/DboBuilder/TableHandler/DataValidator.ts +5 -5
  200. package/lib/DboBuilder/TableHandler/TableHandler.ts +1 -1
  201. package/lib/DboBuilder/TableHandler/insert.ts +3 -3
  202. package/lib/DboBuilder/TableHandler/update.ts +106 -48
  203. package/lib/DboBuilder/ViewHandler/ViewHandler.ts +2 -2
  204. package/lib/DboBuilder/parseUpdateRules.ts +1 -1
  205. package/lib/Logging.ts +7 -3
  206. package/lib/Prostgles.ts +209 -142
  207. package/lib/ProstglesTypes.ts +130 -51
  208. package/lib/SyncReplication.ts +2 -2
  209. package/lib/initProstgles.ts +145 -111
  210. package/lib/utils.ts +4 -5
  211. package/package.json +3 -2
  212. package/examples/server/typescript/index.d.ts +0 -2
  213. package/examples/server/typescript/index.d.ts.map +0 -1
  214. package/examples/server/typescript/index.js +0 -54
  215. package/examples/server/typescript/index.js.map +0 -1
@@ -1,7 +1,6 @@
1
1
  import * as pgPromise from "pg-promise";
2
2
  import pg from "pg-promise/typescript/pg-subset";
3
3
  import { getKeys, isEmpty } from "prostgles-types";
4
- import { AuthHandler } from "./Auth/AuthHandler";
5
4
  import { DBEventsManager } from "./DBEventsManager";
6
5
  import { DBOFullyTyped } from "./DBSchemaBuilder";
7
6
  import { DBHandlerServer, Prostgles, getIsSuperUser } from "./Prostgles";
@@ -10,38 +9,48 @@ import { DbTableInfo, PublishParser } from "./PublishParser/PublishParser";
10
9
  import { SchemaWatch } from "./SchemaWatch/SchemaWatch";
11
10
  import { sleep } from "./utils";
12
11
 
13
- export type DbConnection = string | pg.IConnectionParameters<pg.IClient>;
12
+ /**
13
+ * Database connection details
14
+ */
15
+ export type DbConnection =
16
+ /**
17
+ * Connection URI
18
+ */
19
+ string | pg.IConnectionParameters<pg.IClient>;
14
20
  export type DbConnectionOpts = pg.IDefaults;
15
21
 
16
22
  export type PGP = pgPromise.IMain<{}, pg.IClient>;
17
23
  export type DB = pgPromise.IDatabase<{}, pg.IClient>;
18
24
 
19
- export type UpdateableOptions = Pick<ProstglesInitOptions, "fileTable" | "restApi" | "tableConfig" | "schema" | "auth">;
20
- export type OnInitReason =
21
- | {
22
- type: "schema change";
23
- query: string;
24
- command: string;
25
- }
25
+ export type UpdateableOptions = Pick<
26
+ ProstglesInitOptions,
27
+ "fileTable" | "restApi" | "tableConfig" | "schema" | "auth"
28
+ >;
29
+ export type OnInitReason =
26
30
  | {
27
- type: "prgl.update";
28
- newOpts: Omit<UpdateableOptions, typeof clientOnlyUpdateKeys[number]>;
29
- }
30
- | {
31
- type: "init" | "prgl.restart" | "TableConfig"
32
- };
31
+ type: "schema change";
32
+ query: string;
33
+ command: string;
34
+ }
35
+ | {
36
+ type: "prgl.update";
37
+ newOpts: Omit<UpdateableOptions, (typeof clientOnlyUpdateKeys)[number]>;
38
+ }
39
+ | {
40
+ type: "init" | "prgl.restart" | "TableConfig";
41
+ };
33
42
 
34
43
  type OnReadyParamsCommon = {
35
44
  db: DB;
36
45
  tables: DbTableInfo[];
37
46
  reason: OnInitReason;
38
- }
47
+ };
39
48
  export type OnReadyParamsBasic = OnReadyParamsCommon & {
40
- dbo: DBHandlerServer;
41
- }
49
+ dbo: DBHandlerServer;
50
+ };
42
51
  export type OnReadyParams<S> = OnReadyParamsCommon & {
43
- dbo: DBOFullyTyped<S>;
44
- }
52
+ dbo: DBOFullyTyped<S>;
53
+ };
45
54
 
46
55
  export type OnReadyCallback<S = void> = (params: OnReadyParams<S>) => any;
47
56
  export type OnReadyCallbackBasic = (params: OnReadyParamsBasic) => any;
@@ -57,48 +66,54 @@ export type InitResult = {
57
66
  */
58
67
  getTSSchema: () => string;
59
68
  update: (newOpts: UpdateableOptions) => Promise<void>;
60
- restart: () => Promise<InitResult>;
69
+ restart: () => Promise<InitResult>;
61
70
  options: ProstglesInitOptions;
62
- }
71
+ };
63
72
 
64
73
  const clientOnlyUpdateKeys = ["auth"] as const satisfies (keyof UpdateableOptions)[];
65
74
 
66
- export const initProstgles = async function(this: Prostgles, onReady: OnReadyCallbackBasic, reason: OnInitReason): Promise<InitResult> {
75
+ export const initProstgles = async function (
76
+ this: Prostgles,
77
+ onReady: OnReadyCallbackBasic,
78
+ reason: OnInitReason
79
+ ): Promise<InitResult> {
67
80
  this.loaded = false;
68
81
 
69
82
  if (!this.db) {
70
83
  let existingAppName = "";
71
84
  let connString = "";
72
- if(typeof this.opts.dbConnection === "string"){
85
+ if (typeof this.opts.dbConnection === "string") {
73
86
  connString = this.opts.dbConnection;
74
- } else if(this.opts.dbConnection.connectionString){
87
+ } else if (this.opts.dbConnection.connectionString) {
75
88
  connString = this.opts.dbConnection.connectionString;
76
89
  } else {
77
90
  existingAppName = this.opts.dbConnection.application_name ?? "";
78
91
  }
79
92
 
80
- if(connString){
93
+ if (connString) {
81
94
  try {
82
95
  const url = new URL(connString);
83
- existingAppName = url.searchParams.get("application_name") ?? url.searchParams.get("ApplicationName") ?? "";
84
- } catch (e) {
85
-
86
- }
96
+ existingAppName =
97
+ url.searchParams.get("application_name") ?? url.searchParams.get("ApplicationName") ?? "";
98
+ } catch (e) {}
87
99
  }
88
100
 
89
- const conObj = typeof this.opts.dbConnection === "string" ? { connectionString: this.opts.dbConnection } : this.opts.dbConnection
101
+ const conObj =
102
+ typeof this.opts.dbConnection === "string"
103
+ ? { connectionString: this.opts.dbConnection }
104
+ : this.opts.dbConnection;
90
105
  const application_name = `prostgles ${this.appId} ${existingAppName}`;
91
106
 
92
107
  /* 1. Connect to db */
93
108
  const { db, pgp } = getDbConnection({
94
109
  ...this.opts,
95
- dbConnection: { ...conObj, application_name },
96
- onNotice: notice => {
110
+ dbConnection: { ...conObj, application_name },
111
+ onNotice: (notice) => {
97
112
  if (this.opts.onNotice) this.opts.onNotice(notice);
98
113
  if (this.dbEventsManager) {
99
- this.dbEventsManager.onNotice(notice)
114
+ this.dbEventsManager.onNotice(notice);
100
115
  }
101
- }
116
+ },
102
117
  });
103
118
  this.db = db;
104
119
  this.pgp = pgp;
@@ -115,7 +130,6 @@ export const initProstgles = async function(this: Prostgles, onReady: OnReadyCal
115
130
  }
116
131
 
117
132
  try {
118
-
119
133
  await this.refreshDBO();
120
134
  await this.initTableConfig(reason);
121
135
  await this.initFileTable();
@@ -124,7 +138,6 @@ export const initProstgles = async function(this: Prostgles, onReady: OnReadyCal
124
138
  this.schemaWatch = await SchemaWatch.create(this.dboBuilder);
125
139
 
126
140
  if (this.opts.publish) {
127
-
128
141
  if (!this.opts.io) {
129
142
  console.warn("IO missing. Publish has no effect without io");
130
143
  }
@@ -132,34 +145,39 @@ export const initProstgles = async function(this: Prostgles, onReady: OnReadyCal
132
145
  /* 3.9 Check auth config */
133
146
  await this.initAuthHandler();
134
147
 
135
- this.publishParser = new PublishParser(this.opts.publish, this.opts.publishMethods as any, this.opts.publishRawSQL, this.dbo!, this.db, this as any);
148
+ this.publishParser = new PublishParser(
149
+ this.opts.publish,
150
+ this.opts.publishMethods as any,
151
+ this.opts.publishRawSQL,
152
+ this.dbo!,
153
+ this.db,
154
+ this as any
155
+ );
136
156
  this.dboBuilder.publishParser = this.publishParser;
137
157
 
138
158
  /* 4. Set publish and auth listeners */
139
159
  await this.setSocketEvents();
140
-
141
160
  } else if (this.opts.auth) {
142
161
  throw "Auth config does not work without publish";
143
162
  }
144
163
 
145
164
  this.dbEventsManager = new DBEventsManager(db, pgp);
146
165
 
147
-
148
166
  this.writeDBSchema();
149
167
 
150
168
  /* 5. Finish init and provide DBO object */
151
169
  try {
152
170
  if (this.destroyed) {
153
- console.trace("Prostgles: Instance is destroyed")
171
+ console.trace("Prostgles: Instance is destroyed");
154
172
  }
155
173
  onReady({
156
- dbo: this.dbo as any,
157
- db: this.db,
174
+ dbo: this.dbo as any,
175
+ db: this.db,
158
176
  tables: this.dboBuilder.tables,
159
- reason
177
+ reason,
160
178
  });
161
179
  } catch (err) {
162
- console.error("Prostgles: Error within onReady: \n", err)
180
+ console.error("Prostgles: Error within onReady: \n", err);
163
181
  }
164
182
 
165
183
  this.loaded = true;
@@ -171,36 +189,36 @@ export const initProstgles = async function(this: Prostgles, onReady: OnReadyCal
171
189
  getTSSchema: this.getTSFileContent,
172
190
  options: this.opts,
173
191
  update: async (newOpts) => {
174
-
175
- getKeys(newOpts).forEach(k => {
192
+ getKeys(newOpts).forEach((k) => {
176
193
  //@ts-ignore
177
194
  this.opts[k] = newOpts[k];
178
195
  });
179
196
 
180
-
181
- if("fileTable" in newOpts){
197
+ if ("fileTable" in newOpts) {
182
198
  await this.initFileTable();
183
199
  }
184
- if("restApi" in newOpts){
200
+ if ("restApi" in newOpts) {
185
201
  await this.initRestApi();
186
202
  }
187
- if("tableConfig" in newOpts){
203
+ if ("tableConfig" in newOpts) {
188
204
  await this.initTableConfig({ type: "prgl.update", newOpts });
189
205
  }
190
- if("schema" in newOpts){
206
+ if ("schema" in newOpts) {
191
207
  await this.refreshDBO();
192
208
  }
193
- if("auth" in newOpts){
209
+ if ("auth" in newOpts) {
194
210
  await this.initAuthHandler();
195
211
  }
196
212
 
197
- if(isEmpty(newOpts)) return;
213
+ if (isEmpty(newOpts)) return;
198
214
 
199
- /**
200
- * Some of these changes require clients to reconnect
215
+ /**
216
+ * Some of these changes require clients to reconnect
201
217
  * While others also affect the server and onReady should be called
202
- */
203
- if(getKeys(newOpts).every(updatedKey => clientOnlyUpdateKeys.includes(updatedKey as any))){
218
+ */
219
+ if (
220
+ getKeys(newOpts).every((updatedKey) => clientOnlyUpdateKeys.includes(updatedKey as any))
221
+ ) {
204
222
  await this.setSocketEvents();
205
223
  } else {
206
224
  await this.init(onReady, { type: "prgl.update", newOpts });
@@ -208,22 +226,22 @@ export const initProstgles = async function(this: Prostgles, onReady: OnReadyCal
208
226
  },
209
227
  restart: () => this.init(onReady, { type: "prgl.restart" }),
210
228
  destroy: async () => {
211
- console.log("destroying prgl instance")
229
+ console.log("destroying prgl instance");
212
230
  this.destroyed = true;
213
231
  if (this.opts.io) {
214
232
  this.opts.io.on("connection", () => {
215
- console.log("Socket connected to destroyed instance")
233
+ console.log("Socket connected to destroyed instance");
216
234
  });
217
235
 
218
236
  /** Try to close IO without stopping http server */
219
- if(this.opts.io.sockets.constructor.name === "Namespace"){
237
+ if (this.opts.io.sockets.constructor.name === "Namespace") {
220
238
  for (const socket of this.opts.io.sockets.sockets.values()) {
221
239
  socket._onclose("server shutting down");
222
240
  }
223
241
  }
224
- if(this.opts.io.engine.constructor.name === 'Server'){
242
+ if (this.opts.io.engine.constructor.name === "Server") {
225
243
  this.opts.io.engine.close();
226
- }
244
+ }
227
245
  }
228
246
  this.fileManager?.destroy();
229
247
  this.dboBuilder?.destroy();
@@ -234,57 +252,74 @@ export const initProstgles = async function(this: Prostgles, onReady: OnReadyCal
234
252
  await db.$pool.end();
235
253
  await sleep(1000);
236
254
  return true;
237
- }
255
+ },
238
256
  };
239
257
  } catch (e: any) {
240
- console.trace(e)
258
+ console.trace(e);
241
259
  throw "init issues: " + e.toString();
242
260
  }
243
- }
244
-
245
- type GetDbConnectionArgs = Pick<ProstglesInitOptions, "DEBUG_MODE" | "onQuery" | "dbConnection" | "dbOptions" | "onNotice">;
246
- const getDbConnection = function({ dbConnection, onQuery, DEBUG_MODE, dbOptions, onNotice }: GetDbConnectionArgs): { db: DB, pgp: PGP } {
247
-
248
- const onQueryOrError: undefined | ((error: any, ctx: pgPromise.IEventContext<pg.IClient>) => void) = !onQuery && !DEBUG_MODE? undefined : (error, ctx) => {
249
- if (onQuery) {
250
- onQuery(error, ctx);
251
- } else if (DEBUG_MODE) {
252
- if(error){
253
- console.error(error, ctx);
254
- } else {
255
- console.log(ctx)
256
- }
257
- }
258
- };
259
-
260
- const pgp: PGP = pgPromise({
261
- ...(onQueryOrError ? {
262
- query: ctx => onQueryOrError(undefined, ctx),
263
- error: onQueryOrError
264
- } : {}),
265
- ...((onNotice || DEBUG_MODE) ? {
266
- connect: function ({ client, useCount }) {
267
- const isFresh = !useCount;
268
- if (isFresh && !client.listeners('notice').length) {
269
- client.on('notice', function (msg) {
270
- if (onNotice) {
271
- onNotice(msg, msg?.message);
261
+ };
262
+
263
+ type GetDbConnectionArgs = Pick<
264
+ ProstglesInitOptions,
265
+ "DEBUG_MODE" | "onQuery" | "dbConnection" | "dbOptions" | "onNotice"
266
+ >;
267
+ const getDbConnection = function ({
268
+ dbConnection,
269
+ onQuery,
270
+ DEBUG_MODE,
271
+ dbOptions,
272
+ onNotice,
273
+ }: GetDbConnectionArgs): { db: DB; pgp: PGP } {
274
+ const onQueryOrError:
275
+ | undefined
276
+ | ((error: any, ctx: pgPromise.IEventContext<pg.IClient>) => void) =
277
+ !onQuery && !DEBUG_MODE
278
+ ? undefined
279
+ : (error, ctx) => {
280
+ if (onQuery) {
281
+ onQuery(error, ctx);
282
+ } else if (DEBUG_MODE) {
283
+ if (error) {
284
+ console.error(error, ctx);
272
285
  } else {
273
- console.log("notice: %j", msg?.message);
286
+ console.log(ctx);
274
287
  }
275
- });
288
+ }
289
+ };
290
+
291
+ const pgp: PGP = pgPromise({
292
+ ...(onQueryOrError
293
+ ? {
294
+ query: (ctx) => onQueryOrError(undefined, ctx),
295
+ error: onQueryOrError,
276
296
  }
277
- if (isFresh && !client.listeners('error').length) {
278
- client.on('error', function (msg) {
279
- if (onNotice) {
280
- onNotice(msg, msg?.message);
281
- } else {
282
- console.log("error: %j", msg?.message);
297
+ : {}),
298
+ ...(onNotice || DEBUG_MODE
299
+ ? {
300
+ connect: function ({ client, useCount }) {
301
+ const isFresh = !useCount;
302
+ if (isFresh && !client.listeners("notice").length) {
303
+ client.on("notice", function (msg) {
304
+ if (onNotice) {
305
+ onNotice(msg, msg?.message);
306
+ } else {
307
+ console.log("notice: %j", msg?.message);
308
+ }
309
+ });
283
310
  }
284
- });
311
+ if (isFresh && !client.listeners("error").length) {
312
+ client.on("error", function (msg) {
313
+ if (onNotice) {
314
+ onNotice(msg, msg?.message);
315
+ } else {
316
+ console.log("error: %j", msg?.message);
317
+ }
318
+ });
319
+ }
320
+ },
285
321
  }
286
- },
287
- } : {})
322
+ : {}),
288
323
  });
289
324
  // pgp.pg.defaults.max = 70;
290
325
 
@@ -301,10 +336,9 @@ const getDbConnection = function({ dbConnection, onQuery, DEBUG_MODE, dbOptions,
301
336
  // pgp.pg.types.setTypeParser(1114, v => v); // timestamp without time zone
302
337
  // pgp.pg.types.setTypeParser(1184, v => v); // timestamp with time zone
303
338
  // pgp.pg.types.setTypeParser(1182, v => v); // date
304
- pgp.pg.types.setTypeParser(pgp.pg.types.builtins.TIMESTAMP, v => v); // timestamp without time zone
305
- pgp.pg.types.setTypeParser(pgp.pg.types.builtins.TIMESTAMPTZ, v => v); // timestamp with time zone
306
- pgp.pg.types.setTypeParser(pgp.pg.types.builtins.DATE, v => v); // date
307
-
339
+ pgp.pg.types.setTypeParser(pgp.pg.types.builtins.TIMESTAMP, (v) => v); // timestamp without time zone
340
+ pgp.pg.types.setTypeParser(pgp.pg.types.builtins.TIMESTAMPTZ, (v) => v); // timestamp with time zone
341
+ pgp.pg.types.setTypeParser(pgp.pg.types.builtins.DATE, (v) => v); // date
308
342
 
309
343
  if (dbOptions) {
310
344
  Object.assign(pgp.pg.defaults, dbOptions);
@@ -312,6 +346,6 @@ const getDbConnection = function({ dbConnection, onQuery, DEBUG_MODE, dbOptions,
312
346
 
313
347
  return {
314
348
  db: pgp(dbConnection),
315
- pgp
349
+ pgp,
316
350
  };
317
- }
351
+ };
package/lib/utils.ts CHANGED
@@ -1,15 +1,14 @@
1
-
2
1
  export { get } from "prostgles-types";
3
2
  export const clone = <T extends any[] | Record<string, any>>(obj: T): T => {
4
- if(typeof structuredClone !== "undefined"){
3
+ if (typeof structuredClone !== "undefined") {
5
4
  return structuredClone(obj);
6
5
  }
7
-
6
+
8
7
  return JSON.parse(JSON.stringify(obj));
9
- }
8
+ };
10
9
 
11
10
  export const sleep = function (ms: number) {
12
11
  return new Promise((resolve) => {
13
12
  setTimeout(resolve, ms);
14
13
  });
15
- }
14
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prostgles-server",
3
- "version": "4.2.178",
3
+ "version": "4.2.180",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -54,7 +54,7 @@
54
54
  "pg": "^8.11.5",
55
55
  "pg-cursor": "^2.11.0",
56
56
  "pg-promise": "^11.9.1",
57
- "prostgles-types": "^4.0.112"
57
+ "prostgles-types": "^4.0.117"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@types/express": "^4.17.21",
@@ -67,6 +67,7 @@
67
67
  "@typescript-eslint/eslint-plugin": "^8.15.0",
68
68
  "@typescript-eslint/parser": "^8.15.0",
69
69
  "eslint": "^8.51.0",
70
+ "prettier": "^3.4.2",
70
71
  "socket.io": "^4.8.1",
71
72
  "typescript": "^5.3.3"
72
73
  }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":""}
@@ -1,54 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const path_1 = __importDefault(require("path"));
7
- const express_1 = __importDefault(require("express"));
8
- // const prostgles = require("prostgles-server");
9
- const index_1 = __importDefault(require("../../../dist/index"));
10
- const app = express_1.default();
11
- const http = require('http').createServer(app);
12
- const io = require("socket.io")(http);
13
- http.listen(3001);
14
- index_1.default({
15
- dbConnection: {
16
- host: "localhost",
17
- port: 5432,
18
- database: "postgres",
19
- user: process.env.PRGL_USER,
20
- password: process.env.PRGL_PWD
21
- },
22
- sqlFilePath: path_1.default.join(__dirname + '/init.sql'),
23
- io,
24
- tsGeneratedTypesDir: path_1.default.join(__dirname + '/'),
25
- transactions: "tt",
26
- publish: (socket, dbo) => {
27
- return "*";
28
- },
29
- joins: [
30
- {
31
- tables: ["items", "items2"],
32
- on: { name: "name" },
33
- type: "many-many"
34
- },
35
- {
36
- tables: ["items2", "items3"],
37
- on: { name: "name" },
38
- type: "many-many"
39
- }
40
- ],
41
- onReady: async (dbo, db) => {
42
- app.get("*", (req, res) => {
43
- console.log(req.originalUrl);
44
- });
45
- try {
46
- await dbo.items.insert([{ name: "a" }, { name: "a" }]);
47
- console.log(await dbo.items.find());
48
- }
49
- catch (err) {
50
- console.error(err);
51
- }
52
- },
53
- });
54
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;AACxB,sDAA8B;AAC9B,iDAAiD;AACjD,gEAA4C;AAC5C,MAAM,GAAG,GAAG,iBAAO,EAAE,CAAC;AACtB,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC;AACtC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAIlB,eAAS,CAAC;IACT,YAAY,EAAE;QACb,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,UAAU;QACpB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS;QAC3B,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ;KAC9B;IACD,WAAW,EAAE,cAAI,CAAC,IAAI,CAAC,SAAS,GAAC,WAAW,CAAC;IAC7C,EAAE;IACF,mBAAmB,EAAE,cAAI,CAAC,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC;IAC/C,YAAY,EAAE,IAAI;IAClB,OAAO,EAAE,CAAC,MAAM,EAAE,GAAU,EAAE,EAAE;QAE/B,OAAO,GAAG,CAAC;IACZ,CAAC;IACD,KAAK,EAAE;QACN;YACC,MAAM,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC;YAC3B,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;YACpB,IAAI,EAAE,WAAW;SACjB;QACD;YACC,MAAM,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC;YAC5B,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;YACpB,IAAI,EAAE,WAAW;SACjB;KACD;IACD,OAAO,EAAE,KAAK,EAAE,GAAU,EAAE,EAAE,EAAE,EAAE;QAEjC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACzB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;QAC7B,CAAC,CAAC,CAAA;QACF,IAAI;YAEH,MAAM,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;YACvD,OAAO,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;SAGpC;QAAC,OAAM,GAAG,EAAE;YACZ,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;SAClB;IACF,CAAC;CACD,CAAC,CAAC"}