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
@@ -0,0 +1,104 @@
1
+ # Overview
2
+ Our Isomorphic Typescript API allows connecting to a PostgreSQL database to get a realtime view of the data and schema. Interact with the data with full end-to-end type safety.
3
+ ### Installation
4
+ To install the package, run:
5
+ ```bash
6
+ npm install prostgles-server
7
+ ```
8
+ ### Configuration
9
+ To get started, you need to provide a configuration object to the server.
10
+
11
+ Basic example:
12
+ ```typescript
13
+ import prostgles from "prostgles-server";
14
+ import { DBSchemaGenerated } from "./DBSchemaGenerated";
15
+ prostgles<DBSchemaGenerated>({
16
+ dbConnection: {
17
+ host: "localhost",
18
+ port: 5432,
19
+ database: "postgres"
20
+ user: process.env.PRGL_USER,
21
+ password: process.env.PRGL_PWD
22
+ },
23
+ tsGeneratedTypesDir: __dirname,
24
+ onReady: async ({ dbo }) => {
25
+ try {
26
+ await dbo.items.insert({ name: "a" });
27
+ console.log(await dbo.items.find());
28
+ } catch(err) {
29
+ console.error(err)
30
+ }
31
+ },
32
+ });
33
+ ```
34
+ ### Configuration options
35
+ - <strong>dbConnection</strong> `DbConnection`
36
+ Database connection details
37
+ - <strong>onReady</strong> `OnReadyCallback`
38
+ Called when the prostgles server is ready to accept connections.
39
+ It waits for auth, tableConfig and other async configurations to complete before executing
40
+ - <strong>dbOptions</strong> `IDefaults`
41
+ - <strong>tsGeneratedTypesDir</strong> `string | undefined`
42
+ If defined then a `DBSchemaGenerated.d.ts` file will be created in the provided directory.
43
+ This file exports a `DBSchemaGenerated` type which contains types for the database tables and
44
+ can be used as a generic type input for the prostgles instances to ensure type safety
45
+ - <strong>disableRealtime</strong> `boolean | undefined`
46
+ If true then schema watch, subscriptions and syncs will be disabled.
47
+ No `prostgles` schema will be created which is needed for the realtime features.
48
+ This is useful when you want to connect to a database and prevent any changes to the schema
49
+ - <strong>io</strong> `Server<DefaultEventsMap, DefaultEventsMap, DefaultEventsMap, any>`
50
+ Socket.IO server instance object
51
+ - <strong>publish</strong> `Publish<S, SUser> | undefined`
52
+ Data access rules applied to clients.
53
+ By default, nothing is allowed.
54
+ - <strong>testRulesOnConnect</strong> `boolean | undefined`
55
+ If true then will test all table methods on each socket connect.
56
+ Not recommended for production
57
+ - <strong>publishMethods</strong> `PublishMethods`
58
+ Custom methods that can be called from the client
59
+ - <strong>publishRawSQL</strong> `(params: PublishParams<S, SUser>) => boolean | "*" | Promise<boolean | "*">`
60
+ If defined and resolves to true then the connected client can run SQL queries
61
+ - <strong>joins</strong> `Joins | undefined`
62
+ Allows defining joins between tables:
63
+ - `infered` - uses the foreign keys to infer the joins
64
+ - `Join[]` - specifies the joins manually
65
+ - <strong>schema</strong> `Record<string, 1> | Record<string, 0> | undefined`
66
+ If defined then the specified schemas are included/excluded from the prostgles schema.
67
+ By default the `public` schema is included.
68
+ - <strong>sqlFilePath</strong> `string | undefined`
69
+ Path to a SQL file that will be executed on startup (but before onReady)
70
+ - <strong>transactions</strong> `string | boolean | undefined`
71
+ - <strong>wsChannelNamePrefix</strong> `string | undefined`
72
+ - <strong>onSocketConnect</strong> `(args: AuthRequestParams<S, SUser> & { socket: PRGLIOSocket; }) => void | Promise<void>`
73
+ Called when a socket connects
74
+ Use for connection verification. Will disconnect socket on any errors
75
+ - <strong>onSocketDisconnect</strong> `(args: AuthRequestParams<S, SUser> & { socket: PRGLIOSocket; }) => void | Promise<void>`
76
+ Called when a socket disconnects
77
+ - <strong>auth</strong> `Auth`
78
+ Auth configuration.
79
+ Supports email and OAuth strategies
80
+ - <strong>DEBUG_MODE</strong> `boolean | undefined`
81
+ - <strong>onQuery</strong> `(error: any, ctx: IEventContext<IClient>) => void`
82
+ Callback called when a query is executed.
83
+ Useful for logging or debugging
84
+ - <strong>watchSchemaType</strong> `"DDL_trigger" | "prostgles_queries" | undefined`
85
+ - <strong>watchSchema</strong> `boolean | EventTriggerTagFilter | "hotReloadMode" | OnSchemaChangeCallback | undefined`
86
+ If truthy then DBSchemaGenerated.d.ts will be updated
87
+ and "onReady" will be called with new schema on both client and server
88
+ - <strong>keywords</strong> `Keywords`
89
+ - <strong>onNotice</strong> `(notice: AnyObject, message?: string | undefined) => void`
90
+ - <strong>fileTable</strong> `FileTableConfig`
91
+ Enables file storage and serving.
92
+ Currently supports saving files locally or to AWS S3
93
+ - <strong>restApi</strong> `RestApiConfig`
94
+ Rest API configuration.
95
+ The REST API allows interacting with the database similarly to the socket connection
96
+ with the exception of subscriptions and realtime features
97
+ - <strong>tableConfig</strong> `TableConfig`
98
+ A simple way of defining tables through a JSON-schema like object.
99
+ Allowes adding runtime JSONB validation and type safety.
100
+ Should be used with caution because it tends to revert any changes
101
+ made to the database schema through SQL queries
102
+ - <strong>tableConfigMigrations</strong> `{ silentFail?: boolean | undefined; version: number; versionTableName?: string | undefined; onMigrate: (args: { db: DB; oldVersion: number | undefined; getConstraints: (table: string, column?: string | undefined, types?: ("c" | ... 2 more ... | "f")[] | undefined) => Promise<...>; }) => void; }`
103
+ - <strong>onLog</strong> `(evt: EventInfo) => Promise<void>`
104
+ Usefull for logging or debugging