prostgles-server 4.2.179 → 4.2.181

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 (227) hide show
  1. package/.vscode/settings.json +10 -1
  2. package/README.md +48 -52
  3. package/dist/DBSchemaBuilder.d.ts +2 -2
  4. package/dist/DBSchemaBuilder.d.ts.map +1 -1
  5. package/dist/DBSchemaBuilder.js +34 -26
  6. package/dist/DBSchemaBuilder.js.map +1 -1
  7. package/dist/DboBuilder/TableHandler/DataValidator.d.ts +1 -1
  8. package/dist/DboBuilder/TableHandler/DataValidator.d.ts.map +1 -1
  9. package/dist/DboBuilder/TableHandler/DataValidator.js +4 -4
  10. package/dist/DboBuilder/TableHandler/DataValidator.js.map +1 -1
  11. package/dist/DboBuilder/TableHandler/TableHandler.d.ts +1 -1
  12. package/dist/DboBuilder/TableHandler/TableHandler.d.ts.map +1 -1
  13. package/dist/DboBuilder/TableHandler/insert.js +3 -3
  14. package/dist/DboBuilder/TableHandler/insert.js.map +1 -1
  15. package/dist/DboBuilder/TableHandler/update.d.ts.map +1 -1
  16. package/dist/DboBuilder/TableHandler/update.js +45 -19
  17. package/dist/DboBuilder/TableHandler/update.js.map +1 -1
  18. package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts +1 -1
  19. package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts.map +1 -1
  20. package/dist/DboBuilder/ViewHandler/ViewHandler.js +2 -2
  21. package/dist/DboBuilder/ViewHandler/ViewHandler.js.map +1 -1
  22. package/dist/DboBuilder/getColumns.d.ts.map +1 -1
  23. package/dist/DboBuilder/getColumns.js +41 -16
  24. package/dist/DboBuilder/getColumns.js.map +1 -1
  25. package/dist/DboBuilder/parseUpdateRules.js +1 -1
  26. package/dist/DboBuilder/parseUpdateRules.js.map +1 -1
  27. package/dist/Prostgles.d.ts +2 -2
  28. package/dist/Prostgles.d.ts.map +1 -1
  29. package/dist/Prostgles.js +117 -54
  30. package/dist/Prostgles.js.map +1 -1
  31. package/dist/ProstglesTypes.d.ts +81 -25
  32. package/dist/ProstglesTypes.d.ts.map +1 -1
  33. package/dist/ProstglesTypes.js.map +1 -1
  34. package/dist/SyncReplication.js +2 -2
  35. package/dist/SyncReplication.js.map +1 -1
  36. package/dist/initProstgles.d.ts +9 -2
  37. package/dist/initProstgles.d.ts.map +1 -1
  38. package/dist/initProstgles.js +68 -60
  39. package/dist/initProstgles.js.map +1 -1
  40. package/dist/typeTests/dboTypeCheck.d.ts.map +1 -1
  41. package/dist/typeTests/dboTypeCheck.js +11 -11
  42. package/dist/typeTests/dboTypeCheck.js.map +1 -1
  43. package/dist/utils.d.ts.map +1 -1
  44. package/dist/utils.js.map +1 -1
  45. package/documentation/METHODS.md +1467 -0
  46. package/documentation/SERVER.md +103 -0
  47. package/documentation/utils/clientTypes.ts +14415 -0
  48. package/documentation/utils/dist/clientTypes.d.ts +13211 -0
  49. package/documentation/utils/dist/clientTypes.d.ts.map +1 -0
  50. package/documentation/utils/dist/clientTypes.js +14417 -0
  51. package/documentation/utils/dist/definitions.d.ts +7705 -0
  52. package/documentation/utils/dist/definitions.d.ts.map +1 -0
  53. package/documentation/utils/dist/definitions.js +8438 -0
  54. package/documentation/utils/dist/generateClientDocs.d.ts +2 -0
  55. package/documentation/utils/dist/generateClientDocs.d.ts.map +1 -0
  56. package/documentation/utils/dist/generateClientDocs.js +165 -0
  57. package/documentation/utils/dist/generateDocs.d.ts +2 -0
  58. package/documentation/utils/dist/generateDocs.d.ts.map +1 -0
  59. package/documentation/utils/dist/generateDocs.js +6 -0
  60. package/documentation/utils/dist/generateMarkdown.d.ts +2 -0
  61. package/documentation/utils/dist/generateMarkdown.d.ts.map +1 -0
  62. package/documentation/utils/dist/generateMarkdown.js +68 -0
  63. package/documentation/utils/dist/generateServerDocs.d.ts +2 -0
  64. package/documentation/utils/dist/generateServerDocs.d.ts.map +1 -0
  65. package/documentation/utils/dist/generateServerDocs.js +81 -0
  66. package/documentation/utils/dist/getResolvedTypes.d.ts +15 -0
  67. package/documentation/utils/dist/getResolvedTypes.d.ts.map +1 -0
  68. package/documentation/utils/dist/getResolvedTypes.js +29 -0
  69. package/documentation/utils/dist/getSerializableType.d.ts +69 -0
  70. package/documentation/utils/dist/getSerializableType.d.ts.map +1 -0
  71. package/documentation/utils/dist/getSerializableType.js +279 -0
  72. package/documentation/utils/dist/getSymbolComments.d.ts +11 -0
  73. package/documentation/utils/dist/getSymbolComments.d.ts.map +1 -0
  74. package/documentation/utils/dist/getSymbolComments.js +60 -0
  75. package/documentation/utils/dist/loadTsFile.d.ts +7 -0
  76. package/documentation/utils/dist/loadTsFile.d.ts.map +1 -0
  77. package/documentation/utils/dist/loadTsFile.js +29 -0
  78. package/documentation/utils/dist/moduleResolver.d.ts +9 -0
  79. package/documentation/utils/dist/moduleResolver.d.ts.map +1 -0
  80. package/documentation/utils/dist/moduleResolver.js +27 -0
  81. package/documentation/utils/dist/serverTypes.d.ts +301 -0
  82. package/documentation/utils/dist/serverTypes.d.ts.map +1 -0
  83. package/documentation/utils/dist/serverTypes.js +341 -0
  84. package/documentation/utils/generateClientDocs.ts +210 -0
  85. package/documentation/utils/generateDocs.ts +4 -0
  86. package/documentation/utils/generateServerDocs.ts +84 -0
  87. package/documentation/utils/getResolvedTypes.ts +45 -0
  88. package/documentation/utils/getSerializableType.ts +489 -0
  89. package/documentation/utils/loadTsFile.ts +41 -0
  90. package/documentation/utils/moduleResolver.ts +31 -0
  91. package/documentation/utils/node_modules/.package-lock.json +67 -0
  92. package/documentation/utils/node_modules/@types/node/LICENSE +21 -0
  93. package/documentation/utils/node_modules/@types/node/README.md +15 -0
  94. package/documentation/utils/node_modules/@types/node/assert/strict.d.ts +8 -0
  95. package/documentation/utils/node_modules/@types/node/assert.d.ts +1040 -0
  96. package/documentation/utils/node_modules/@types/node/async_hooks.d.ts +541 -0
  97. package/documentation/utils/node_modules/@types/node/buffer.buffer.d.ts +385 -0
  98. package/documentation/utils/node_modules/@types/node/buffer.d.ts +1934 -0
  99. package/documentation/utils/node_modules/@types/node/child_process.d.ts +1548 -0
  100. package/documentation/utils/node_modules/@types/node/cluster.d.ts +578 -0
  101. package/documentation/utils/node_modules/@types/node/compatibility/disposable.d.ts +16 -0
  102. package/documentation/utils/node_modules/@types/node/compatibility/index.d.ts +9 -0
  103. package/documentation/utils/node_modules/@types/node/compatibility/indexable.d.ts +20 -0
  104. package/documentation/utils/node_modules/@types/node/compatibility/iterators.d.ts +21 -0
  105. package/documentation/utils/node_modules/@types/node/console.d.ts +452 -0
  106. package/documentation/utils/node_modules/@types/node/constants.d.ts +19 -0
  107. package/documentation/utils/node_modules/@types/node/crypto.d.ts +4519 -0
  108. package/documentation/utils/node_modules/@types/node/dgram.d.ts +596 -0
  109. package/documentation/utils/node_modules/@types/node/diagnostics_channel.d.ts +554 -0
  110. package/documentation/utils/node_modules/@types/node/dns/promises.d.ts +477 -0
  111. package/documentation/utils/node_modules/@types/node/dns.d.ts +864 -0
  112. package/documentation/utils/node_modules/@types/node/dom-events.d.ts +124 -0
  113. package/documentation/utils/node_modules/@types/node/domain.d.ts +170 -0
  114. package/documentation/utils/node_modules/@types/node/events.d.ts +931 -0
  115. package/documentation/utils/node_modules/@types/node/fs/promises.d.ts +1245 -0
  116. package/documentation/utils/node_modules/@types/node/fs.d.ts +4317 -0
  117. package/documentation/utils/node_modules/@types/node/globals.d.ts +468 -0
  118. package/documentation/utils/node_modules/@types/node/globals.typedarray.d.ts +21 -0
  119. package/documentation/utils/node_modules/@types/node/http.d.ts +1944 -0
  120. package/documentation/utils/node_modules/@types/node/http2.d.ts +2555 -0
  121. package/documentation/utils/node_modules/@types/node/https.d.ts +544 -0
  122. package/documentation/utils/node_modules/@types/node/index.d.ts +91 -0
  123. package/documentation/utils/node_modules/@types/node/inspector.d.ts +3696 -0
  124. package/documentation/utils/node_modules/@types/node/module.d.ts +315 -0
  125. package/documentation/utils/node_modules/@types/node/net.d.ts +1005 -0
  126. package/documentation/utils/node_modules/@types/node/os.d.ts +495 -0
  127. package/documentation/utils/node_modules/@types/node/package.json +220 -0
  128. package/documentation/utils/node_modules/@types/node/path.d.ts +200 -0
  129. package/documentation/utils/node_modules/@types/node/perf_hooks.d.ts +934 -0
  130. package/documentation/utils/node_modules/@types/node/process.d.ts +1879 -0
  131. package/documentation/utils/node_modules/@types/node/punycode.d.ts +117 -0
  132. package/documentation/utils/node_modules/@types/node/querystring.d.ts +153 -0
  133. package/documentation/utils/node_modules/@types/node/readline/promises.d.ts +162 -0
  134. package/documentation/utils/node_modules/@types/node/readline.d.ts +589 -0
  135. package/documentation/utils/node_modules/@types/node/repl.d.ts +430 -0
  136. package/documentation/utils/node_modules/@types/node/sea.d.ts +153 -0
  137. package/documentation/utils/node_modules/@types/node/stream/consumers.d.ts +12 -0
  138. package/documentation/utils/node_modules/@types/node/stream/promises.d.ts +90 -0
  139. package/documentation/utils/node_modules/@types/node/stream/web.d.ts +524 -0
  140. package/documentation/utils/node_modules/@types/node/stream.d.ts +1726 -0
  141. package/documentation/utils/node_modules/@types/node/string_decoder.d.ts +67 -0
  142. package/documentation/utils/node_modules/@types/node/test.d.ts +1938 -0
  143. package/documentation/utils/node_modules/@types/node/timers/promises.d.ts +97 -0
  144. package/documentation/utils/node_modules/@types/node/timers.d.ts +240 -0
  145. package/documentation/utils/node_modules/@types/node/tls.d.ts +1217 -0
  146. package/documentation/utils/node_modules/@types/node/trace_events.d.ts +197 -0
  147. package/documentation/utils/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +385 -0
  148. package/documentation/utils/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +19 -0
  149. package/documentation/utils/node_modules/@types/node/ts5.6/index.d.ts +91 -0
  150. package/documentation/utils/node_modules/@types/node/tty.d.ts +208 -0
  151. package/documentation/utils/node_modules/@types/node/url.d.ts +955 -0
  152. package/documentation/utils/node_modules/@types/node/util.d.ts +2306 -0
  153. package/documentation/utils/node_modules/@types/node/v8.d.ts +808 -0
  154. package/documentation/utils/node_modules/@types/node/vm.d.ts +922 -0
  155. package/documentation/utils/node_modules/@types/node/wasi.d.ts +181 -0
  156. package/documentation/utils/node_modules/@types/node/worker_threads.d.ts +694 -0
  157. package/documentation/utils/node_modules/@types/node/zlib.d.ts +539 -0
  158. package/documentation/utils/node_modules/undici-types/LICENSE +21 -0
  159. package/documentation/utils/node_modules/undici-types/README.md +6 -0
  160. package/documentation/utils/node_modules/undici-types/agent.d.ts +31 -0
  161. package/documentation/utils/node_modules/undici-types/api.d.ts +43 -0
  162. package/documentation/utils/node_modules/undici-types/balanced-pool.d.ts +29 -0
  163. package/documentation/utils/node_modules/undici-types/cache.d.ts +36 -0
  164. package/documentation/utils/node_modules/undici-types/client.d.ts +108 -0
  165. package/documentation/utils/node_modules/undici-types/connector.d.ts +34 -0
  166. package/documentation/utils/node_modules/undici-types/content-type.d.ts +21 -0
  167. package/documentation/utils/node_modules/undici-types/cookies.d.ts +28 -0
  168. package/documentation/utils/node_modules/undici-types/diagnostics-channel.d.ts +66 -0
  169. package/documentation/utils/node_modules/undici-types/dispatcher.d.ts +255 -0
  170. package/documentation/utils/node_modules/undici-types/env-http-proxy-agent.d.ts +21 -0
  171. package/documentation/utils/node_modules/undici-types/errors.d.ts +149 -0
  172. package/documentation/utils/node_modules/undici-types/eventsource.d.ts +63 -0
  173. package/documentation/utils/node_modules/undici-types/fetch.d.ts +209 -0
  174. package/documentation/utils/node_modules/undici-types/file.d.ts +39 -0
  175. package/documentation/utils/node_modules/undici-types/filereader.d.ts +54 -0
  176. package/documentation/utils/node_modules/undici-types/formdata.d.ts +108 -0
  177. package/documentation/utils/node_modules/undici-types/global-dispatcher.d.ts +9 -0
  178. package/documentation/utils/node_modules/undici-types/global-origin.d.ts +7 -0
  179. package/documentation/utils/node_modules/undici-types/handlers.d.ts +15 -0
  180. package/documentation/utils/node_modules/undici-types/header.d.ts +4 -0
  181. package/documentation/utils/node_modules/undici-types/index.d.ts +71 -0
  182. package/documentation/utils/node_modules/undici-types/interceptors.d.ts +15 -0
  183. package/documentation/utils/node_modules/undici-types/mock-agent.d.ts +50 -0
  184. package/documentation/utils/node_modules/undici-types/mock-client.d.ts +25 -0
  185. package/documentation/utils/node_modules/undici-types/mock-errors.d.ts +12 -0
  186. package/documentation/utils/node_modules/undici-types/mock-interceptor.d.ts +93 -0
  187. package/documentation/utils/node_modules/undici-types/mock-pool.d.ts +25 -0
  188. package/documentation/utils/node_modules/undici-types/package.json +55 -0
  189. package/documentation/utils/node_modules/undici-types/patch.d.ts +71 -0
  190. package/documentation/utils/node_modules/undici-types/pool-stats.d.ts +19 -0
  191. package/documentation/utils/node_modules/undici-types/pool.d.ts +39 -0
  192. package/documentation/utils/node_modules/undici-types/proxy-agent.d.ts +28 -0
  193. package/documentation/utils/node_modules/undici-types/readable.d.ts +60 -0
  194. package/documentation/utils/node_modules/undici-types/retry-agent.d.ts +8 -0
  195. package/documentation/utils/node_modules/undici-types/retry-handler.d.ts +116 -0
  196. package/documentation/utils/node_modules/undici-types/util.d.ts +18 -0
  197. package/documentation/utils/node_modules/undici-types/webidl.d.ts +222 -0
  198. package/documentation/utils/node_modules/undici-types/websocket.d.ts +152 -0
  199. package/documentation/utils/package-lock.json +75 -0
  200. package/documentation/utils/package.json +14 -0
  201. package/documentation/utils/serverTypes.ts +339 -0
  202. package/documentation/utils/tsconfig.json +28 -0
  203. package/examples/full-example-typescript/DBoGenerated.d.ts +2 -2
  204. package/examples/full-example-typescript/DBoGenerated.ts +2 -2
  205. package/examples/full-example-typescript/index.ts +39 -45
  206. package/examples/full-example-vanilla/index.js +51 -53
  207. package/examples/server/typescript/index.ts +24 -30
  208. package/lib/DBSchemaBuilder.ts +148 -118
  209. package/lib/DboBuilder/TableHandler/DataValidator.ts +5 -5
  210. package/lib/DboBuilder/TableHandler/TableHandler.ts +1 -1
  211. package/lib/DboBuilder/TableHandler/insert.ts +3 -3
  212. package/lib/DboBuilder/TableHandler/update.ts +106 -48
  213. package/lib/DboBuilder/ViewHandler/ViewHandler.ts +2 -2
  214. package/lib/DboBuilder/getColumns.ts +63 -31
  215. package/lib/DboBuilder/parseUpdateRules.ts +1 -1
  216. package/lib/Prostgles.ts +208 -143
  217. package/lib/ProstglesTypes.ts +134 -52
  218. package/lib/SyncReplication.ts +2 -2
  219. package/lib/initProstgles.ts +151 -118
  220. package/lib/typeTests/DBoGenerated.d.ts +23 -19
  221. package/lib/typeTests/dboTypeCheck.ts +49 -35
  222. package/lib/utils.ts +4 -5
  223. package/package.json +5 -3
  224. package/examples/server/typescript/index.d.ts +0 -2
  225. package/examples/server/typescript/index.d.ts.map +0 -1
  226. package/examples/server/typescript/index.js +0 -54
  227. 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,73 @@ 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);
272
- } else {
273
- console.log("notice: %j", msg?.message);
274
- }
275
- });
276
- }
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);
283
- }
284
- });
261
+ };
262
+
263
+ type GetDbConnectionArgs = Pick<
264
+ ProstglesInitOptions,
265
+ "DEBUG_MODE" | "onQuery" | "dbConnection" | "onNotice"
266
+ >;
267
+ const getDbConnection = function ({
268
+ dbConnection,
269
+ onQuery,
270
+ DEBUG_MODE,
271
+ onNotice,
272
+ }: GetDbConnectionArgs): { db: DB; pgp: PGP } {
273
+ const onQueryOrError:
274
+ | undefined
275
+ | ((error: any, ctx: pgPromise.IEventContext<pg.IClient>) => void) =
276
+ !onQuery && !DEBUG_MODE ?
277
+ undefined
278
+ : (error, ctx) => {
279
+ if (onQuery) {
280
+ onQuery(error, ctx);
281
+ } else if (DEBUG_MODE) {
282
+ if (error) {
283
+ console.error(error, ctx);
284
+ } else {
285
+ console.log(ctx);
286
+ }
285
287
  }
286
- },
287
- } : {})
288
+ };
289
+
290
+ const pgp: PGP = pgPromise({
291
+ ...(onQueryOrError ?
292
+ {
293
+ query: (ctx) => onQueryOrError(undefined, ctx),
294
+ error: onQueryOrError,
295
+ }
296
+ : {}),
297
+ ...(onNotice || DEBUG_MODE ?
298
+ {
299
+ connect: function ({ client, useCount }) {
300
+ const isFresh = !useCount;
301
+ if (isFresh && !client.listeners("notice").length) {
302
+ client.on("notice", function (msg) {
303
+ if (onNotice) {
304
+ onNotice(msg, msg?.message);
305
+ } else {
306
+ console.log("notice: %j", msg?.message);
307
+ }
308
+ });
309
+ }
310
+ if (isFresh && !client.listeners("error").length) {
311
+ client.on("error", function (msg) {
312
+ if (onNotice) {
313
+ onNotice(msg, msg?.message);
314
+ } else {
315
+ console.log("error: %j", msg?.message);
316
+ }
317
+ });
318
+ }
319
+ },
320
+ }
321
+ : {}),
288
322
  });
289
323
  // pgp.pg.defaults.max = 70;
290
324
 
@@ -301,17 +335,16 @@ const getDbConnection = function({ dbConnection, onQuery, DEBUG_MODE, dbOptions,
301
335
  // pgp.pg.types.setTypeParser(1114, v => v); // timestamp without time zone
302
336
  // pgp.pg.types.setTypeParser(1184, v => v); // timestamp with time zone
303
337
  // 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
-
338
+ pgp.pg.types.setTypeParser(pgp.pg.types.builtins.TIMESTAMP, (v) => v); // timestamp without time zone
339
+ pgp.pg.types.setTypeParser(pgp.pg.types.builtins.TIMESTAMPTZ, (v) => v); // timestamp with time zone
340
+ pgp.pg.types.setTypeParser(pgp.pg.types.builtins.DATE, (v) => v); // date
308
341
 
309
- if (dbOptions) {
310
- Object.assign(pgp.pg.defaults, dbOptions);
311
- }
342
+ // if (dbOptions) {
343
+ // Object.assign(pgp.pg.defaults, dbOptions);
344
+ // }
312
345
 
313
346
  return {
314
347
  db: pgp(dbConnection),
315
- pgp
348
+ pgp,
316
349
  };
317
- }
350
+ };
@@ -1,4 +1,4 @@
1
- export type DBSchemaGenerated = {
1
+ export type DBGeneratedSchema = {
2
2
  items: {
3
3
  is_view: false;
4
4
  select: true;
@@ -188,20 +188,25 @@ export type DBSchemaGenerated = {
188
188
  update: true;
189
189
  delete: true;
190
190
  columns: {
191
- colOneOf: "a" | "b" | "c"
192
- json: { a: boolean; arr: '1' | '2' | '3'; arr1: 1 | 2 | 3; arr2: number[]; arrStr?: null | string[]; o?: | null
193
- | { o1: number; }
194
- | { o2: boolean; }; };
195
- jsonOneOf?:
196
- | null
197
- | { command: 'a'; }
198
- | { command: 'b'; option: number[]; }
199
- status?:
200
- | null
201
- | { ok: string; }
202
- | { err: string; }
203
- | { loading: { loaded: number; total: number; }; }
204
- table_config?: null | { referencedTables?: ( { name: string; minFiles: number; } )[]; recType?: null | Record<'a' | 'b', { bools: boolean[]; }>; };
191
+ colOneOf: "a" | "b" | "c";
192
+ json: {
193
+ a: boolean;
194
+ arr: "1" | "2" | "3";
195
+ arr1: 1 | 2 | 3;
196
+ arr2: number[];
197
+ arrStr?: null | string[];
198
+ o?: null | { o1: number } | { o2: boolean };
199
+ };
200
+ jsonOneOf?: null | { command: "a" } | { command: "b"; option: number[] };
201
+ status?:
202
+ | null
203
+ | { ok: string }
204
+ | { err: string }
205
+ | { loading: { loaded: number; total: number } };
206
+ table_config?: null | {
207
+ referencedTables?: { name: string; minFiles: number }[];
208
+ recType?: null | Record<"a" | "b", { bools: boolean[] }>;
209
+ };
205
210
  };
206
211
  };
207
212
  tr1: {
@@ -261,8 +266,8 @@ export type DBSchemaGenerated = {
261
266
  columns: {
262
267
  email: string;
263
268
  id?: number;
264
- preferences: { showIntro?: boolean; theme?: 'light' | 'dark' | 'auto'; others: any[]; };
265
- status: "active" | "disabled" | "pending"
269
+ preferences: { showIntro?: boolean; theme?: "light" | "dark" | "auto"; others: any[] };
270
+ status: "active" | "disabled" | "pending";
266
271
  };
267
272
  };
268
273
  users_public_info: {
@@ -316,5 +321,4 @@ export type DBSchemaGenerated = {
316
321
  tsv?: null | string;
317
322
  };
318
323
  };
319
-
320
- }
324
+ };
@@ -2,7 +2,7 @@ import { ViewHandler } from "prostgles-types";
2
2
  import type { DBOFullyTyped } from "../DBSchemaBuilder";
3
3
  import type { DBHandlerServer } from "../DboBuilder/DboBuilder";
4
4
  import { Publish } from "../PublishParser/PublishParser";
5
- import { DBSchemaGenerated } from "./DBoGenerated";
5
+ import { DBGeneratedSchema } from "./DBoGenerated";
6
6
 
7
7
  type DBSchema2 = {
8
8
  tr2: {
@@ -18,24 +18,27 @@ type DBSchema2 = {
18
18
  tr1_id?: null | number;
19
19
  };
20
20
  };
21
- }
22
- export const testDboTypes = () => {
23
- (async () => {
21
+ };
22
+ export const testDboTypes = () => {
23
+ async () => {
24
24
  const dbo = {} as DBOFullyTyped;
25
25
  dbo.someTable?.find;
26
26
 
27
27
  const dbo1 = {} as DBHandlerServer;
28
28
  dbo1.w?.find;
29
29
 
30
- const db = {} as DBOFullyTyped<DBSchemaGenerated>;
30
+ const db = {} as DBOFullyTyped<DBGeneratedSchema>;
31
31
  db.items2.find;
32
32
 
33
- const r = await db.items2.find({ }, {
34
- select: { id: 1 },
35
- orderBy: {
36
- id: 1,
37
- }
38
- });
33
+ const r = await db.items2.find(
34
+ {},
35
+ {
36
+ select: { id: 1 },
37
+ orderBy: {
38
+ id: 1,
39
+ },
40
+ }
41
+ );
39
42
 
40
43
  r[0]?.id;
41
44
 
@@ -43,39 +46,50 @@ export const testDboTypes = () => {
43
46
  r[0]?.bad_col;
44
47
 
45
48
  const tr2 = {} as ViewHandler<DBSchema2["tr2"]["columns"], DBSchema2>;
46
- tr2.find({}, {
47
- select: { id: 1 },
48
- orderBy: { tr1_id: 1 }
49
- });
49
+ tr2.find(
50
+ {},
51
+ {
52
+ select: { id: 1 },
53
+ orderBy: { tr1_id: 1 },
54
+ }
55
+ );
50
56
 
51
- tr2.find({}, {
52
- //@ts-expect-error
53
- select: { bad_col: 1 }
54
- });
57
+ tr2.find(
58
+ {},
59
+ {
60
+ //@ts-expect-error
61
+ select: { bad_col: 1 },
62
+ }
63
+ );
55
64
 
56
- tr2.find({}, {
57
- //@ts-expect-error
58
- orderBy: { bad_col: 1 }
59
- });
65
+ tr2.find(
66
+ {},
67
+ {
68
+ //@ts-expect-error
69
+ orderBy: { bad_col: 1 },
70
+ }
71
+ );
60
72
 
61
- (await db.items2.find({}, { select: { items_id: 1 }, returnType: "values" })) satisfies (number | null)[];
62
-
73
+ (await db.items2.find({}, { select: { items_id: 1 }, returnType: "values" })) satisfies (
74
+ | number
75
+ | null
76
+ )[];
63
77
 
64
- const publish: Publish<DBSchemaGenerated> = {
78
+ const publish: Publish<DBGeneratedSchema> = {
65
79
  items: {
66
80
  insert: {
67
- fields: {
68
- name: 1,
81
+ fields: {
82
+ name: 1,
69
83
  //@ts-expect-error
70
- bad_col: 1
84
+ bad_col: 1,
71
85
  },
72
86
  validate: async (row) => ({
73
87
  ...row,
74
- h: [""]
75
- })
76
- }
77
- }
88
+ h: [""],
89
+ }),
90
+ },
91
+ },
78
92
  };
79
93
  publish;
80
- })
81
- }
94
+ };
95
+ };
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.179",
3
+ "version": "4.2.181",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,7 +15,8 @@
15
15
  "test-only": "cd tests/ && ./test.sh",
16
16
  "test-quick": "cd tests/ && ./test.sh -quick",
17
17
  "test": "rm -rf ./node_modules/* && rm -rf ./dist/* && npm i && npm run lint && npm run test-only",
18
- "pushpublish": "npm version patch --git-tag-version false && git push && npm publish"
18
+ "generate-docs": "rm -f ./documentation/*.md && cd documentation/utils && npm start",
19
+ "pushpublish": "npm run generate-docs && npm version patch --git-tag-version false && git push && npm publish"
19
20
  },
20
21
  "repository": {
21
22
  "type": "git",
@@ -54,7 +55,7 @@
54
55
  "pg": "^8.11.5",
55
56
  "pg-cursor": "^2.11.0",
56
57
  "pg-promise": "^11.9.1",
57
- "prostgles-types": "^4.0.112"
58
+ "prostgles-types": "^4.0.119"
58
59
  },
59
60
  "devDependencies": {
60
61
  "@types/express": "^4.17.21",
@@ -67,6 +68,7 @@
67
68
  "@typescript-eslint/eslint-plugin": "^8.15.0",
68
69
  "@typescript-eslint/parser": "^8.15.0",
69
70
  "eslint": "^8.51.0",
71
+ "prettier": "^3.4.2",
70
72
  "socket.io": "^4.8.1",
71
73
  "typescript": "^5.3.3"
72
74
  }
@@ -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":""}