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,479 @@
1
+ import * as ts from "typescript";
2
+ import { AnyObject, isDefined } from "prostgles-types";
3
+
4
+ type TS_Base = {
5
+ alias?: string;
6
+ aliasSymbolescapedName?: string;
7
+ intersectionParent?: string;
8
+ comments?: string;
9
+ };
10
+
11
+ export type TS_Literal = TS_Base & {
12
+ type: "literal";
13
+ value: string;
14
+ };
15
+
16
+ export type TS_Primitive = TS_Base & {
17
+ type: "primitive";
18
+ subType: "string" | "number" | "boolean" | "any" | "null" | "undefined";
19
+ };
20
+
21
+ export type TS_Object = TS_Base & {
22
+ type: "object";
23
+ properties: Record<string, TS_Type & { optional: boolean }>;
24
+ };
25
+
26
+ export type TS_Array = TS_Base & {
27
+ type: "array";
28
+ itemType: TS_Type;
29
+ };
30
+
31
+ export type TS_Tuple = TS_Base & {
32
+ type: "tuple";
33
+ itemTypes: TS_Type[];
34
+ };
35
+
36
+ export type TS_Function = TS_Base & {
37
+ type: "function";
38
+ arguments: (TS_Type & { name: string; optional: boolean })[];
39
+ returnType: TS_Type;
40
+ };
41
+
42
+ export type TS_Promise = TS_Base & {
43
+ type: "promise";
44
+ innerType: Exclude<TS_Type, TS_Promise>;
45
+ };
46
+
47
+ export type TS_Union = TS_Base & {
48
+ type: "union";
49
+ types: TS_Type[];
50
+ };
51
+
52
+ export type TS_Reference = TS_Base & {
53
+ type: "reference";
54
+ alias: string;
55
+ };
56
+
57
+ export type TS_Type =
58
+ | TS_Primitive
59
+ | TS_Literal
60
+ | TS_Object
61
+ | TS_Array
62
+ | TS_Tuple
63
+ | TS_Function
64
+ | TS_Union
65
+ | TS_Promise
66
+ | TS_Reference;
67
+
68
+ export type VisitedTypesMap = Map<
69
+ string,
70
+ { resolvedType: TS_Type; type: ts.Type; referenceType?: TS_Type }
71
+ >;
72
+
73
+ export const getSerializableType = (
74
+ myType: ts.Type,
75
+ checker: ts.TypeChecker,
76
+ visited: VisitedTypesMap = new Map(),
77
+ parentAliases: string[],
78
+ opts: ResolveTypeOptions | undefined,
79
+ depth: number
80
+ ): { resolvedType: TS_Type; visited: VisitedTypesMap } => {
81
+ let alias = "unknown";
82
+ const { escapedName } = myType.aliasSymbol ?? {};
83
+ const aliasSymbolescapedName = escapedName?.toString();
84
+ const symbol = myType.aliasSymbol ?? myType.symbol;
85
+ const comments = symbol ? getSymbolComments(symbol, checker) : undefined;
86
+ try {
87
+ alias = checker.typeToString(myType);
88
+ } catch (e) {
89
+ console.log("Error resolving type", myType, e);
90
+ }
91
+
92
+ /* Circular resolved type */
93
+ const visitedType = visited.get(alias);
94
+ if (visitedType) {
95
+ return { resolvedType: visitedType.referenceType ?? visitedType.resolvedType, visited };
96
+ }
97
+ const withAlias = (_type: TS_Type) => {
98
+ const finalComments = _type.comments || comments;
99
+ const resolvedType: TS_Type = sortObjectsByKeyOrder(
100
+ {
101
+ alias: _type.alias ?? alias,
102
+ aliasSymbolescapedName,
103
+ ..._type,
104
+ ...(finalComments && { comments: finalComments }),
105
+ },
106
+ ["type", "alias", "aliasSymbolescapedName", "comments"]
107
+ );
108
+
109
+ let referenceType: TS_Type | undefined;
110
+ if (
111
+ opts?.excludedTypes.includes(alias) ||
112
+ (escapedName && opts?.excludedTypes.includes(escapedName)) ||
113
+ (opts?.maxDepth !== undefined && depth >= opts.maxDepth)
114
+ ) {
115
+ referenceType =
116
+ resolvedType.type === "primitive" ?
117
+ resolvedType
118
+ : {
119
+ type: "reference",
120
+ alias,
121
+ aliasSymbolescapedName,
122
+ comments: resolvedType.comments,
123
+ };
124
+ }
125
+
126
+ visited.set(alias, { resolvedType, referenceType, type: myType });
127
+
128
+ return { resolvedType: referenceType ?? resolvedType, visited };
129
+ };
130
+
131
+ const unresolvedParentAliases = parentAliases?.filter((a) => !visited.get(a)) ?? [];
132
+
133
+ /* Circular unresolved type */
134
+ if (unresolvedParentAliases.includes(alias)) {
135
+ return withAlias({
136
+ type: "reference",
137
+ alias,
138
+ });
139
+ }
140
+ const nextUnresolvedParentAliases = unresolvedParentAliases.concat(alias);
141
+
142
+ // if (alias === "[FullFilter<T, S>, Partial<UpsertDataToPGCast<T>>][]") {
143
+ // debugger;
144
+ // }
145
+
146
+ if (myType.isUnion()) {
147
+ const unionTypes = myType.types.map((t) => {
148
+ const resolvedUnionMember = getSerializableType(
149
+ t,
150
+ checker,
151
+ visited,
152
+ nextUnresolvedParentAliases,
153
+ opts,
154
+ depth + 1
155
+ );
156
+ return resolvedUnionMember.resolvedType;
157
+ });
158
+
159
+ /**
160
+ * "boolean | undefined" ends up in types as
161
+ * { intrinsicName: "true" } | { intrinsicName: "false" } | { intrinsicName: "undefined" }
162
+ * So we need to check for "true" and "false" and merge them into "boolean"
163
+ */
164
+ const booleanTypes = unionTypes.filter(
165
+ (t) => t.type === "primitive" && t.subType === "boolean"
166
+ );
167
+ const dedupedTypes =
168
+ booleanTypes.length > 1 ?
169
+ unionTypes
170
+ .filter((t) => t.type !== "primitive" || t.subType !== "boolean")
171
+ .concat(booleanTypes[0]!)
172
+ : unionTypes;
173
+
174
+ const result = withAlias({
175
+ type: "union",
176
+ types: dedupedTypes,
177
+ });
178
+
179
+ return result;
180
+ }
181
+
182
+ if ((myType.flags & ts.TypeFlags.String) !== 0) {
183
+ return withAlias({ type: "primitive", subType: "string" });
184
+ }
185
+
186
+ if ((myType.flags & ts.TypeFlags.NumberLike) !== 0) {
187
+ return withAlias({ type: "primitive", subType: "number" });
188
+ }
189
+
190
+ if ((myType.flags & ts.TypeFlags.BooleanLike) !== 0) {
191
+ return withAlias({ type: "primitive", subType: "boolean" });
192
+ }
193
+
194
+ if ((myType.flags & ts.TypeFlags.Null) !== 0) {
195
+ return withAlias({ type: "primitive", subType: "null" });
196
+ }
197
+
198
+ if ((myType.flags & ts.TypeFlags.Undefined) !== 0) {
199
+ return withAlias({ type: "primitive", subType: "undefined" });
200
+ }
201
+
202
+ if (checker.isArrayType(myType)) {
203
+ const itemType = checker.getTypeArguments(myType as ts.TypeReference)[0];
204
+ if (itemType && checker.isTupleType(itemType)) {
205
+ const tupleTypes =
206
+ (itemType as unknown as { resolvedTypeArguments: ts.Type[] }).resolvedTypeArguments.map(
207
+ (d: ts.Type) => {
208
+ return getSerializableType(
209
+ d,
210
+ checker,
211
+ visited,
212
+ nextUnresolvedParentAliases,
213
+ opts,
214
+ depth + 1
215
+ ).resolvedType;
216
+ }
217
+ ) ?? [];
218
+ return withAlias({
219
+ type: "tuple",
220
+ itemTypes: tupleTypes,
221
+ });
222
+ }
223
+ const resolvedItemType: TS_Type =
224
+ itemType ?
225
+ getSerializableType(
226
+ itemType,
227
+ checker,
228
+ visited,
229
+ nextUnresolvedParentAliases,
230
+ opts,
231
+ depth + 1
232
+ ).resolvedType
233
+ : { type: "primitive", subType: "any" };
234
+
235
+ return withAlias({
236
+ type: "array",
237
+ itemType: resolvedItemType,
238
+ });
239
+ }
240
+
241
+ const [firstSignature] = myType.getCallSignatures();
242
+ if (firstSignature) {
243
+ const parameters = firstSignature.parameters
244
+ .map((param) => {
245
+ const { valueDeclaration } = param;
246
+ if (!valueDeclaration) return undefined;
247
+ const paramType = checker.getTypeOfSymbolAtLocation(param, valueDeclaration);
248
+ const resolvedParamType = getSerializableType(
249
+ paramType,
250
+ checker,
251
+ visited,
252
+ nextUnresolvedParentAliases,
253
+ opts,
254
+ depth + 1
255
+ ).resolvedType;
256
+ const paramComments = getSymbolComments(param, checker);
257
+ const optional = Boolean(
258
+ (ts as any).isParameterDeclaration(param.valueDeclaration) &&
259
+ checker.isOptionalParameter(valueDeclaration as ts.ParameterDeclaration)
260
+ );
261
+ const name = param.escapedName.toString() || param.name;
262
+ const resolvedParam =
263
+ optional ? simplifyUnionForOptionalType(resolvedParamType) : resolvedParamType;
264
+ return {
265
+ name,
266
+ optional,
267
+ ...resolvedParam,
268
+ comments: resolvedParam.comments || paramComments,
269
+ };
270
+ })
271
+ .filter(isDefined);
272
+ const returnType = getSerializableType(
273
+ checker.getReturnTypeOfSignature(firstSignature),
274
+ checker,
275
+ visited,
276
+ nextUnresolvedParentAliases,
277
+ opts,
278
+ depth + 1
279
+ ).resolvedType;
280
+
281
+ return withAlias({
282
+ type: "function",
283
+ arguments: parameters,
284
+ returnType,
285
+ });
286
+ }
287
+
288
+ if ((myType.flags & ts.TypeFlags.Object) !== 0) {
289
+ const objectType = myType as ts.ObjectType;
290
+
291
+ if (objectType.objectFlags & ts.ObjectFlags.Reference) {
292
+ const typeReference = objectType as ts.TypeReference;
293
+ const target = typeReference.target;
294
+
295
+ if (target.symbol?.escapedName === "Promise") {
296
+ const _innerType = checker.getTypeArguments(typeReference)[0];
297
+ const defaultType: TS_Type = { type: "primitive", subType: "any" };
298
+ const resolvedInnerType =
299
+ _innerType &&
300
+ getSerializableType(
301
+ _innerType,
302
+ checker,
303
+ visited,
304
+ nextUnresolvedParentAliases,
305
+ opts,
306
+ depth + 1
307
+ ).resolvedType;
308
+ const innerType: Exclude<TS_Type, TS_Promise> =
309
+ resolvedInnerType?.type === "promise" ? defaultType : (resolvedInnerType ?? defaultType);
310
+ return withAlias({
311
+ type: "promise",
312
+ innerType,
313
+ });
314
+ }
315
+ }
316
+
317
+ const properties: TS_Object["properties"] = {};
318
+ myType.getProperties().forEach((symbol) => {
319
+ const propertyType = checker.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration!);
320
+ const resolvedPropertyType = getSerializableType(
321
+ propertyType,
322
+ checker,
323
+ visited,
324
+ nextUnresolvedParentAliases,
325
+ opts,
326
+ depth + 1
327
+ ).resolvedType;
328
+ const propertyComments = resolvedPropertyType.comments || getSymbolComments(symbol, checker);
329
+ const optional = Boolean(symbol.flags & ts.SymbolFlags.Optional);
330
+ properties[symbol.name] = {
331
+ ...(optional ? simplifyUnionForOptionalType(resolvedPropertyType) : resolvedPropertyType),
332
+ optional,
333
+ comments: propertyComments || undefined,
334
+ };
335
+ });
336
+ const comments =
337
+ myType.aliasSymbol?.declarations &&
338
+ getNonInternalTSDeclarations(myType.aliasSymbol?.declarations)
339
+ //@ts-ignore
340
+ ?.flatMap((d) => (!d.jsDoc ? [] : d.jsDoc.map((jd) => jd.comment)))
341
+ .join("\n");
342
+ return withAlias({
343
+ type: "object",
344
+ properties,
345
+ comments,
346
+ });
347
+ }
348
+
349
+ /**
350
+ * A & B
351
+ */
352
+ if (myType.isIntersection()) {
353
+ const intersectionTypes = myType.types.map((t) => {
354
+ const { resolvedType: intersectionType } = getSerializableType(
355
+ t,
356
+ checker,
357
+ visited,
358
+ nextUnresolvedParentAliases,
359
+ opts,
360
+ depth + 1
361
+ );
362
+ intersectionType.intersectionParent = aliasSymbolescapedName || alias;
363
+ return intersectionType;
364
+ });
365
+ if (intersectionTypes.every((t) => t.type === "object")) {
366
+ const properties = (intersectionTypes as TS_Object[]).reduce((acc, t) => {
367
+ return { ...acc, ...t.properties };
368
+ }, {});
369
+ return withAlias({
370
+ type: "object",
371
+ properties,
372
+ });
373
+ }
374
+ return withAlias({
375
+ type: "union",
376
+ types: intersectionTypes,
377
+ });
378
+ }
379
+
380
+ /**
381
+ * Type parameter. E.g.:
382
+ * function example<T>(arg: T){ }
383
+ */
384
+ if (myType.isTypeParameter()) {
385
+ const extendedType = myType.getConstraint();
386
+ if (extendedType) {
387
+ const { resolvedType: resolvedExtendedType } = getSerializableType(
388
+ extendedType,
389
+ checker,
390
+ visited,
391
+ nextUnresolvedParentAliases,
392
+ opts,
393
+ depth + 1
394
+ );
395
+ return withAlias(resolvedExtendedType);
396
+ }
397
+ }
398
+
399
+ if (myType.isStringLiteral()) {
400
+ return withAlias({ type: "literal", value: myType.value });
401
+ }
402
+
403
+ return withAlias({ type: "primitive", subType: "any" });
404
+ };
405
+
406
+ type ResolveTypeOptions = {
407
+ excludedTypes: string[];
408
+ maxDepth?: number;
409
+ };
410
+ export const resolveType = (
411
+ myType: ts.Type,
412
+ checker: ts.TypeChecker,
413
+ opts: ResolveTypeOptions
414
+ ): { resolvedType: TS_Type; constituentTypes?: TS_Type[] } => {
415
+ const { resolvedType } = getSerializableType(myType, checker, undefined, [], opts, 0);
416
+ if (resolvedType.type === "reference" && opts.excludedTypes.includes(resolvedType.alias)) {
417
+ return { resolvedType: { type: "primitive", subType: "any" } };
418
+ }
419
+ return { resolvedType, constituentTypes: [] };
420
+ };
421
+
422
+ const getNonInternalTSDeclarations = (declarations: ts.Declaration[]): ts.Declaration[] => {
423
+ return declarations.filter((d) => {
424
+ return !d.getSourceFile().fileName.includes("/node_modules/typescript/");
425
+ });
426
+ };
427
+
428
+ const sortObjectsByKeyOrder = <T extends AnyObject, K extends keyof T & string>(
429
+ obj: T,
430
+ keyOrder: K[]
431
+ ): T => {
432
+ const newKeyOrder = arraySort(Object.keys(obj), keyOrder);
433
+
434
+ return newKeyOrder.reduce(
435
+ (acc, key) => ({
436
+ ...acc,
437
+ [key]: obj[key],
438
+ }),
439
+ {} as T
440
+ );
441
+ };
442
+
443
+ const arraySort = (arrayToSort: string[], keyOrder: string[]): string[] => {
444
+ const keyOrderMap = new Map(keyOrder.map((value, index) => [value, index]));
445
+
446
+ return arrayToSort.sort((a, b) => {
447
+ const aIndex = keyOrderMap.get(a) ?? Infinity;
448
+ const bIndex = keyOrderMap.get(b) ?? Infinity;
449
+
450
+ return aIndex - bIndex;
451
+ });
452
+ };
453
+
454
+ const simplifyUnionForOptionalType = (resolvedParamType: TS_Type) => {
455
+ if (resolvedParamType.type === "union" && resolvedParamType.types.length === 2) {
456
+ const indexOfUndefined = resolvedParamType.types.findIndex(
457
+ (t) => t.type === "primitive" && t.subType === "undefined"
458
+ );
459
+ if (indexOfUndefined === -1) return resolvedParamType;
460
+
461
+ const unionTypes = resolvedParamType.types;
462
+ const nonUndefined = unionTypes.find((_, i) => indexOfUndefined !== i);
463
+ if (
464
+ nonUndefined &&
465
+ (nonUndefined.type !== "primitive" || nonUndefined.subType !== "undefined")
466
+ ) {
467
+ return nonUndefined;
468
+ }
469
+ }
470
+ return resolvedParamType;
471
+ };
472
+
473
+ const getSymbolComments = (symbol: ts.Symbol, checker: ts.TypeChecker): string => {
474
+ const comments = symbol.getDocumentationComment(checker);
475
+ return comments
476
+ .map((comment) => comment.text)
477
+ .join(" ")
478
+ .trim();
479
+ };
@@ -0,0 +1,45 @@
1
+ import * as path from "path";
2
+ import * as ts from "typescript";
3
+
4
+ export const loadTsFile = (filePath: string) => {
5
+ // Normalize file path
6
+ const absolutePath = path.resolve(filePath);
7
+
8
+ // Create compiler host and program
9
+ const configPath = ts.findConfigFile(
10
+ path.dirname(absolutePath),
11
+ ts.sys.fileExists,
12
+ "tsconfig.json"
13
+ );
14
+
15
+ if (!configPath) {
16
+ throw new Error("Could not find a valid 'tsconfig.json'.");
17
+ }
18
+
19
+ // Parse the config file
20
+ const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
21
+ const parsedConfig = ts.parseJsonConfigFileContent(
22
+ configFile.config,
23
+ ts.sys,
24
+ path.dirname(configPath)
25
+ );
26
+
27
+ // Create program
28
+ const program = ts.createProgram({
29
+ rootNames: [absolutePath],
30
+ options: parsedConfig.options,
31
+ });
32
+
33
+ const checker = program.getTypeChecker();
34
+ const sourceFile = program.getSourceFile(absolutePath);
35
+
36
+ if (!sourceFile) {
37
+ throw new Error(`Could not find source file: ${absolutePath}`);
38
+ }
39
+
40
+ return {
41
+ program,
42
+ checker,
43
+ sourceFile,
44
+ };
45
+ };
@@ -0,0 +1,31 @@
1
+ import * as ts from "typescript";
2
+
3
+ /**
4
+ * Resolves a moduleSpecifier to its resolved file path using TypeScript's module resolution.
5
+ *
6
+ * @param moduleSpecifier - The module path (e.g., "./Auth").
7
+ * @param currentFilePath - The path of the current file where the module is imported.
8
+ * @returns The resolved file path, or `undefined` if not found.
9
+ */
10
+ export const resolveModuleWithTypescript = (moduleSpecifier: string, currentFilePath: string) => {
11
+ const compilerOptions: ts.CompilerOptions = {
12
+ moduleResolution: ts.ModuleResolutionKind.Node16,
13
+ baseUrl: "./", // Adjust as needed
14
+ };
15
+ const host: ts.ModuleResolutionHost = {
16
+ fileExists: ts.sys.fileExists,
17
+ readFile: ts.sys.readFile,
18
+ directoryExists: ts.sys.directoryExists,
19
+ getCurrentDirectory: ts.sys.getCurrentDirectory,
20
+ getDirectories: ts.sys.getDirectories,
21
+ };
22
+
23
+ const { resolvedModule } = ts.resolveModuleName(
24
+ moduleSpecifier,
25
+ currentFilePath,
26
+ compilerOptions,
27
+ host
28
+ );
29
+
30
+ return resolvedModule?.resolvedFileName;
31
+ };
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "generate-docs",
3
+ "version": "1.0.0",
4
+ "lockfileVersion": 3,
5
+ "requires": true,
6
+ "packages": {
7
+ "..": {
8
+ "name": "prostgles-server",
9
+ "version": "4.2.179",
10
+ "extraneous": true,
11
+ "license": "MIT",
12
+ "dependencies": {
13
+ "@aws-sdk/client-ses": "^3.699.0",
14
+ "@aws-sdk/credential-provider-node": "^3.699.0",
15
+ "@types/passport": "^1.0.17",
16
+ "@types/passport-facebook": "^3.0.3",
17
+ "@types/passport-github2": "^1.2.9",
18
+ "@types/passport-google-oauth20": "^2.0.16",
19
+ "@types/passport-microsoft": "^1.0.3",
20
+ "body-parser": "^1.20.3",
21
+ "check-disk-space": "^3.4.0",
22
+ "file-type": "^18.5.0",
23
+ "nodemailer": "^6.9.16",
24
+ "passport": "^0.7.0",
25
+ "passport-facebook": "^3.0.0",
26
+ "passport-github2": "^0.1.12",
27
+ "passport-google-oauth20": "^2.0.0",
28
+ "passport-microsoft": "^2.1.0",
29
+ "pg": "^8.11.5",
30
+ "pg-cursor": "^2.11.0",
31
+ "pg-promise": "^11.9.1",
32
+ "prostgles-types": "^4.0.115"
33
+ },
34
+ "devDependencies": {
35
+ "@types/express": "^4.17.21",
36
+ "@types/json-schema": "^7.0.15",
37
+ "@types/node": "^22.8.1",
38
+ "@types/nodemailer": "^6.4.17",
39
+ "@types/pg": "^8.11.5",
40
+ "@types/pg-cursor": "^2.7.2",
41
+ "@types/sharp": "^0.30.4",
42
+ "@typescript-eslint/eslint-plugin": "^8.15.0",
43
+ "@typescript-eslint/parser": "^8.15.0",
44
+ "eslint": "^8.51.0",
45
+ "socket.io": "^4.8.1",
46
+ "typescript": "^5.3.3"
47
+ }
48
+ },
49
+ "node_modules/@types/node": {
50
+ "version": "20.17.10",
51
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-20.17.10.tgz",
52
+ "integrity": "sha512-/jrvh5h6NXhEauFFexRin69nA0uHJ5gwk4iDivp/DeoEua3uwCUto6PC86IpRITBOs4+6i2I56K5x5b6WYGXHA==",
53
+ "dev": true,
54
+ "license": "MIT",
55
+ "dependencies": {
56
+ "undici-types": "~6.19.2"
57
+ }
58
+ },
59
+ "node_modules/undici-types": {
60
+ "version": "6.19.8",
61
+ "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz",
62
+ "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==",
63
+ "dev": true,
64
+ "license": "MIT"
65
+ }
66
+ }
67
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Microsoft Corporation.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE
@@ -0,0 +1,15 @@
1
+ # Installation
2
+ > `npm install --save @types/node`
3
+
4
+ # Summary
5
+ This package contains type definitions for node (https://nodejs.org/).
6
+
7
+ # Details
8
+ Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node/v20.
9
+
10
+ ### Additional Details
11
+ * Last updated: Wed, 11 Dec 2024 09:35:14 GMT
12
+ * Dependencies: [undici-types](https://npmjs.com/package/undici-types)
13
+
14
+ # Credits
15
+ These definitions were written by [Microsoft TypeScript](https://github.com/Microsoft), [Alberto Schiabel](https://github.com/jkomyno), [Alvis HT Tang](https://github.com/alvis), [Andrew Makarov](https://github.com/r3nya), [Benjamin Toueg](https://github.com/btoueg), [Chigozirim C.](https://github.com/smac89), [David Junger](https://github.com/touffy), [Deividas Bakanas](https://github.com/DeividasBakanas), [Eugene Y. Q. Shen](https://github.com/eyqs), [Hannes Magnusson](https://github.com/Hannes-Magnusson-CK), [Huw](https://github.com/hoo29), [Kelvin Jin](https://github.com/kjin), [Klaus Meinhardt](https://github.com/ajafff), [Lishude](https://github.com/islishude), [Mariusz Wiktorczyk](https://github.com/mwiktorczyk), [Mohsen Azimi](https://github.com/mohsen1), [Nikita Galkin](https://github.com/galkin), [Parambir Singh](https://github.com/parambirs), [Sebastian Silbermann](https://github.com/eps1lon), [Thomas den Hollander](https://github.com/ThomasdenH), [Wilco Bakker](https://github.com/WilcoBakker), [wwwy3y3](https://github.com/wwwy3y3), [Samuel Ainsworth](https://github.com/samuela), [Kyle Uehlein](https://github.com/kuehlein), [Thanik Bhongbhibhat](https://github.com/bhongy), [Marcin Kopacz](https://github.com/chyzwar), [Trivikram Kamat](https://github.com/trivikr), [Junxiao Shi](https://github.com/yoursunny), [Ilia Baryshnikov](https://github.com/qwelias), [ExE Boss](https://github.com/ExE-Boss), [Piotr Błażejewicz](https://github.com/peterblazejewicz), [Anna Henningsen](https://github.com/addaleax), [Victor Perin](https://github.com/victorperin), [NodeJS Contributors](https://github.com/NodeJS), [Linus Unnebäck](https://github.com/LinusU), [wafuwafu13](https://github.com/wafuwafu13), [Matteo Collina](https://github.com/mcollina), and [Dmitry Semigradsky](https://github.com/Semigradsky).
@@ -0,0 +1,8 @@
1
+ declare module "assert/strict" {
2
+ import { strict } from "node:assert";
3
+ export = strict;
4
+ }
5
+ declare module "node:assert/strict" {
6
+ import { strict } from "node:assert";
7
+ export = strict;
8
+ }