prostgles-server 4.2.180 → 4.2.182

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 (53) hide show
  1. package/README.md +48 -52
  2. package/dist/DBSchemaBuilder.d.ts +2 -2
  3. package/dist/DBSchemaBuilder.d.ts.map +1 -1
  4. package/dist/DBSchemaBuilder.js +34 -26
  5. package/dist/DBSchemaBuilder.js.map +1 -1
  6. package/dist/DboBuilder/getColumns.d.ts.map +1 -1
  7. package/dist/DboBuilder/getColumns.js +41 -16
  8. package/dist/DboBuilder/getColumns.js.map +1 -1
  9. package/dist/Prostgles.d.ts.map +1 -1
  10. package/dist/Prostgles.js +1 -2
  11. package/dist/Prostgles.js.map +1 -1
  12. package/dist/ProstglesTypes.d.ts +7 -5
  13. package/dist/ProstglesTypes.d.ts.map +1 -1
  14. package/dist/initProstgles.js +12 -12
  15. package/dist/initProstgles.js.map +1 -1
  16. package/dist/typeTests/dboTypeCheck.d.ts.map +1 -1
  17. package/dist/typeTests/dboTypeCheck.js +11 -11
  18. package/dist/typeTests/dboTypeCheck.js.map +1 -1
  19. package/documentation/METHODS.md +1467 -0
  20. package/documentation/SERVER.md +6 -7
  21. package/documentation/utils/clientTypes.ts +8602 -2623
  22. package/documentation/utils/dist/clientTypes.d.ts +7307 -1801
  23. package/documentation/utils/dist/clientTypes.d.ts.map +1 -1
  24. package/documentation/utils/dist/clientTypes.js +8602 -2623
  25. package/documentation/utils/dist/generateClientDocs.d.ts +0 -1
  26. package/documentation/utils/dist/generateClientDocs.d.ts.map +1 -1
  27. package/documentation/utils/dist/generateClientDocs.js +85 -35
  28. package/documentation/utils/dist/generateServerDocs.d.ts.map +1 -1
  29. package/documentation/utils/dist/generateServerDocs.js +11 -10
  30. package/documentation/utils/dist/getResolvedTypes.js +1 -1
  31. package/documentation/utils/dist/getSerializableType.d.ts +1 -1
  32. package/documentation/utils/dist/getSerializableType.d.ts.map +1 -1
  33. package/documentation/utils/dist/getSerializableType.js +29 -23
  34. package/documentation/utils/dist/loadTsFile.d.ts.map +1 -1
  35. package/documentation/utils/dist/loadTsFile.js +0 -4
  36. package/documentation/utils/dist/serverTypes.d.ts +3 -9
  37. package/documentation/utils/dist/serverTypes.d.ts.map +1 -1
  38. package/documentation/utils/dist/serverTypes.js +3 -9
  39. package/documentation/utils/generateClientDocs.ts +99 -31
  40. package/documentation/utils/generateServerDocs.ts +12 -10
  41. package/documentation/utils/getSerializableType.ts +13 -3
  42. package/documentation/utils/loadTsFile.ts +0 -4
  43. package/documentation/utils/serverTypes.ts +3 -9
  44. package/documentation/utils/tsconfig.json +2 -2
  45. package/lib/DBSchemaBuilder.ts +148 -118
  46. package/lib/DboBuilder/getColumns.ts +63 -31
  47. package/lib/Prostgles.ts +1 -2
  48. package/lib/ProstglesTypes.ts +7 -4
  49. package/lib/initProstgles.ts +50 -51
  50. package/lib/typeTests/DBoGenerated.d.ts +23 -19
  51. package/lib/typeTests/dboTypeCheck.ts +49 -35
  52. package/package.json +4 -3
  53. package/documentation/CLIENT.md +0 -542
@@ -1,3 +1,2 @@
1
1
  export declare const generateClientDocs: () => void;
2
- export declare const generateMDX: (filePath: string) => void;
3
2
  //# sourceMappingURL=generateClientDocs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"generateClientDocs.d.ts","sourceRoot":"","sources":["../generateClientDocs.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,kBAAkB,YAkD9B,CAAC;AAOF,eAAO,MAAM,WAAW,aAAc,MAAM,SA4B3C,CAAC"}
1
+ {"version":3,"file":"generateClientDocs.d.ts","sourceRoot":"","sources":["../generateClientDocs.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,kBAAkB,YA0F9B,CAAC"}
@@ -1,19 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateMDX = exports.generateClientDocs = void 0;
3
+ exports.generateClientDocs = void 0;
4
4
  const fs = require("fs");
5
5
  const path = require("path");
6
6
  const prostgles_types_1 = require("prostgles-types");
7
- const getResolvedTypes_1 = require("./getResolvedTypes");
8
- const prostgles_types_2 = require("prostgles-types");
9
7
  const clientTypes_1 = require("./clientTypes");
8
+ const getResolvedTypes_1 = require("./getResolvedTypes");
10
9
  const testFolderPath = `${__dirname}/../../../tests/`;
11
10
  const docsFolder = `${__dirname}/../../`;
12
11
  const generateClientDocs = () => {
13
12
  const clientFilePath = path.resolve(`${testFolderPath}/client/node_modules/prostgles-client/dist/prostgles.d.ts`);
14
13
  const excludedTypes = [
15
- "FullFilter",
16
- "FullFilter<T, S> | undefined",
14
+ // "FullFilter",
15
+ // "FullFilter<T, S> | undefined",
17
16
  "FieldFilter | undefined",
18
17
  "SyncOptions",
19
18
  "SyncOneOptions",
@@ -22,17 +21,14 @@ const generateClientDocs = () => {
22
21
  const { resolvedTypes, visitedMaps } = (0, getResolvedTypes_1.getResolvedTypes)({
23
22
  filePath: clientFilePath,
24
23
  filter: {
25
- nodeNames: [
26
- // "ViewHandlerClient",
27
- "TableHandlerClient",
28
- ],
24
+ nodeNames: ["TableHandlerClient"],
29
25
  excludedTypes,
30
26
  },
31
27
  });
32
28
  const jsonTypes = JSON.stringify([
33
29
  ...resolvedTypes,
34
30
  ...visitedMaps
35
- .flatMap((m) => Array.from(m.values()).map((v) => { var _a; return excludedTypes.includes((_a = v.resolvedType.alias) !== null && _a !== void 0 ? _a : "") ? v.resolvedType : undefined; }))
31
+ .flatMap((m) => Array.from(m.values()).map((v) => excludedTypes.includes(v.resolvedType.alias ?? "") ? v.resolvedType : undefined))
36
32
  .filter(prostgles_types_1.isDefined),
37
33
  ], null, 2);
38
34
  fs.writeFileSync(`${__dirname}/../clientTypes.ts`, [
@@ -41,8 +37,38 @@ const generateClientDocs = () => {
41
37
  ].join("\n"), {
42
38
  encoding: "utf-8",
43
39
  });
44
- const docPath = `${docsFolder}CLIENT.md`;
45
- (0, exports.generateMDX)(docPath);
40
+ const docPath = `${docsFolder}METHODS.md`;
41
+ const tableHandler = clientTypes_1.definitions[0];
42
+ const isomotphicMethodNames = {
43
+ count: 1,
44
+ delete: 1,
45
+ find: 1,
46
+ insert: 1,
47
+ update: 1,
48
+ findOne: 1,
49
+ getColumns: 1,
50
+ getInfo: 1,
51
+ size: 1,
52
+ subscribe: 1,
53
+ subscribeOne: 1,
54
+ updateBatch: 1,
55
+ upsert: 1,
56
+ };
57
+ const isomorphicMd = getMethodsDocs((0, prostgles_types_1.getObjectEntries)(tableHandler.properties).filter(([methodName]) => isomotphicMethodNames[methodName]));
58
+ const clientMd = getMethodsDocs((0, prostgles_types_1.getObjectEntries)(tableHandler.properties).filter(([methodName]) => !isomotphicMethodNames[methodName]));
59
+ const result = [
60
+ `# Isomorphic Methods`,
61
+ ``,
62
+ `The following methods are available on the client and server.`,
63
+ ``,
64
+ isomorphicMd.join("\n\n"),
65
+ `# Client Methods`,
66
+ ``,
67
+ `The following methods are available on the client.`,
68
+ ``,
69
+ clientMd.join("\n\n"),
70
+ ].join("\n");
71
+ fs.writeFileSync(docPath, result, { encoding: "utf-8" });
46
72
  };
47
73
  exports.generateClientDocs = generateClientDocs;
48
74
  const getAliasWithoutGenerics = (type) => {
@@ -50,47 +76,64 @@ const getAliasWithoutGenerics = (type) => {
50
76
  return type.types.map(getAliasWithoutGenerics).join(" | ");
51
77
  return type.aliasSymbolescapedName || type.alias;
52
78
  };
53
- const generateMDX = (filePath) => {
54
- const tableHandler = clientTypes_1.definitions[0];
55
- const mdxContent = (0, prostgles_types_2.getObjectEntries)(tableHandler.properties).map(([methodName, _methodInfo]) => {
56
- var _a;
79
+ const getMethodsDocs = (methods) => {
80
+ return methods.map(([methodName, _methodInfo]) => {
57
81
  const methodInfo = (_methodInfo.type === "function" ?
58
82
  _methodInfo
59
83
  // : _methodInfo.type === "union" ? _methodInfo.types.find((t) => t.type === "function")
60
84
  : undefined);
61
85
  if (!methodInfo)
62
86
  return "";
87
+ const args = `${methodInfo.arguments
88
+ .map((arg) => `${arg.name}${arg.optional ? "?" : ""}: ${getAliasWithoutGenerics(arg)}`)
89
+ .join(", ")}`;
90
+ const rType = `${methodInfo.returnType.aliasSymbolescapedName || methodInfo.returnType.alias}`
91
+ .replaceAll("<", "&lt;")
92
+ .replaceAll(">", "&gt;");
63
93
  return [
64
- `## ${methodName}()`,
65
- (_a = methodInfo.comments) !== null && _a !== void 0 ? _a : "",
66
- `\`\`\`typescript
67
- ${methodName}: (${methodInfo.arguments
68
- .map((arg) => `${arg.name}${arg.optional ? "?" : ""}: ${getAliasWithoutGenerics(arg)}`)
69
- .join(", ")}): ${methodInfo.returnType.aliasSymbolescapedName || methodInfo.returnType.alias}
70
- \`\`\``,
71
- `#### Arguments`,
94
+ `## ${methodName}<span style="opacity: 0.6;">(${args}): ${rType}</span>`,
95
+ methodInfo.comments ?? "",
96
+ `\`\`\`typescript`,
97
+ `${methodName}: (): `,
98
+ `\`\`\``,
99
+ `#### Parameters`,
72
100
  ``,
73
101
  ...methodInfo.arguments.map((arg) => {
74
102
  return renderType(arg, 2, { name: arg.name, optional: arg.optional });
75
103
  }),
76
- `#### Return type`,
77
- renderType(methodInfo.returnType, 0, undefined),
104
+ // `#### Return type`,
105
+ `#### ` + renderType(methodInfo.returnType, 0, undefined),
78
106
  ].join("\n");
79
107
  });
80
- const result = mdxContent.join("\n\n");
81
- fs.writeFileSync(filePath, result, { encoding: "utf-8" });
82
108
  };
83
- exports.generateMDX = generateMDX;
109
+ const renderedAliases = new Set();
84
110
  const renderType = (type, indent = 2, argOrProp) => {
85
111
  const indentText = " ".repeat(indent);
86
- const title = `${indentText}${(argOrProp === null || argOrProp === void 0 ? void 0 : argOrProp.name) ? `- **${argOrProp.name}**: ` : ""}\`${type.aliasSymbolescapedName || type.alias}\` ${type.comments ? ` - ${removeLineBreaks(type.comments)}` : ""}`;
112
+ const typeAlias = `\`${type.aliasSymbolescapedName || type.alias}\``;
113
+ const typeText = type.aliasSymbolescapedName && type.type === "object" ?
114
+ `<span style="color: green;">${type.aliasSymbolescapedName}</span>`
115
+ : typeAlias;
116
+ const title = [
117
+ `${indentText}${argOrProp?.name ? `- **${argOrProp.name}**: ` : ""}${typeAlias}`,
118
+ `${type.comments ? `${removeLineBreaks(type.comments, indentText + " ")}` : ""}`,
119
+ ].join("\n\n");
120
+ if (typeAlias?.includes("FullFilter")) {
121
+ // debugger;
122
+ }
123
+ /**
124
+ * Re-use rendered types by linking them through an anchor tag
125
+ */
126
+ if (type.aliasSymbolescapedName && argOrProp?.name) {
127
+ renderedAliases.add(type.aliasSymbolescapedName);
128
+ console.log(type.aliasSymbolescapedName);
129
+ }
87
130
  if (type.type === "primitive" || type.type === "literal") {
88
131
  return title;
89
132
  }
90
133
  if (type.type === "object") {
91
134
  return (title +
92
135
  `\n` +
93
- (0, prostgles_types_2.getObjectEntries)(type.properties)
136
+ (0, prostgles_types_1.getObjectEntries)(type.properties)
94
137
  .map(([name, p]) => renderType(p, indent + 2, { name, optional: p.optional }))
95
138
  .join("\n"));
96
139
  }
@@ -106,10 +149,17 @@ const renderType = (type, indent = 2, argOrProp) => {
106
149
  }
107
150
  return title;
108
151
  };
109
- const removeLineBreaks = (str = "") => str
152
+ const removeLineBreaks = (str, indent) => str
110
153
  .split("\n")
111
154
  .map((line) => {
112
- if (!line.trim().endsWith("."))
113
- return `${line}.`;
155
+ return `${indent}${line.trimStart()}`;
114
156
  })
115
- .join(" ");
157
+ .join("\n");
158
+ const renderTypeAlias = (type) => {
159
+ const typeAlias = type.aliasSymbolescapedName || type.alias;
160
+ const style = type.aliasSymbolescapedName ? `style="color: green;"` : "";
161
+ // if (renderedAliases.has(typeAlias)) {
162
+ // return `<a ${style} href="#${typeAlias}">${typeAlias}</a>`;
163
+ // }
164
+ return `<span ${style}>${typeAlias}</span>`;
165
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"generateServerDocs.d.ts","sourceRoot":"","sources":["../generateServerDocs.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,kBAAkB,YAuE9B,CAAC"}
1
+ {"version":3,"file":"generateServerDocs.d.ts","sourceRoot":"","sources":["../generateServerDocs.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,kBAAkB,YAyE9B,CAAC"}
@@ -13,7 +13,7 @@ const generateServerDocs = () => {
13
13
  // `${testFolderPath}/server/node_modules/prostgles-server/dist/DBSchemaBuilder.d.ts` // "DBOFullyTyped",
14
14
  `${testFolderPath}/server/node_modules/prostgles-server/dist/ProstglesTypes.d.ts` // "ProstglesInitOptions",
15
15
  );
16
- const { resolvedTypes: [ProstglesInitOptions], visitedMaps, } = (0, getResolvedTypes_1.getResolvedTypes)({
16
+ const { resolvedTypes: [ProstglesInitOptions], } = (0, getResolvedTypes_1.getResolvedTypes)({
17
17
  filePath: serverFilePath,
18
18
  filter: {
19
19
  nodeNames: [
@@ -24,9 +24,14 @@ const generateServerDocs = () => {
24
24
  maxDepth: 2,
25
25
  },
26
26
  });
27
- if (!ProstglesInitOptions)
28
- throw new Error("ProstglesInitOptions not found");
27
+ const serverTypesStr = [
28
+ `import type { TS_Type } from "./getSerializableType";`,
29
+ `export const definitions = ${JSON.stringify([ProstglesInitOptions], null, 2)} as const satisfies TS_Type[];`,
30
+ ].join("\n");
31
+ fs.writeFileSync(`${docsFolder}/utils/serverTypes.ts`, serverTypesStr, { encoding: "utf-8" });
29
32
  const prostglesInitOpts = serverTypes_1.definitions[0];
33
+ if (!ProstglesInitOptions || !prostglesInitOpts)
34
+ throw new Error("ProstglesInitOptions not found");
30
35
  const docs = [
31
36
  `# Overview`,
32
37
  `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.`,
@@ -41,8 +46,8 @@ const generateServerDocs = () => {
41
46
  `Basic example:`,
42
47
  `\`\`\`typescript`,
43
48
  `import prostgles from "prostgles-server";`,
44
- `import { DBSchemaGenerated } from "./DBSchemaGenerated";`,
45
- `prostgles<DBSchemaGenerated>({`,
49
+ `import { DBGeneratedSchema } from "./DBGeneratedSchema";`,
50
+ `prostgles<DBGeneratedSchema>({`,
46
51
  ` dbConnection: {`,
47
52
  ` host: "localhost",`,
48
53
  ` port: 5432,`,
@@ -63,6 +68,7 @@ const generateServerDocs = () => {
63
68
  `\`\`\``,
64
69
  `### Configuration options`,
65
70
  ...(0, prostgles_types_1.getObjectEntries)(prostglesInitOpts.properties).map(([propName, prop]) => {
71
+ //@ts-ignore
66
72
  const title = ` - <strong>${propName}</strong> \`${prop.aliasSymbolescapedName || prop.alias}\``;
67
73
  const comments = prop.comments || "";
68
74
  if (!comments)
@@ -70,11 +76,6 @@ const generateServerDocs = () => {
70
76
  return [title, ` ` + comments + " "].join("\n");
71
77
  }),
72
78
  ].join("\n");
73
- const serverTypesStr = [
74
- `import type { TS_Type } from "./getSerializableType";`,
75
- `export const definitions = ${JSON.stringify([ProstglesInitOptions], null, 2)} as const satisfies TS_Type[];`,
76
- ].join("\n");
77
- fs.writeFileSync(`${docsFolder}/utils/serverTypes.ts`, serverTypesStr, { encoding: "utf-8" });
78
79
  fs.writeFileSync(`${docsFolder}SERVER.md`, docs, { encoding: "utf-8" });
79
80
  };
80
81
  exports.generateServerDocs = generateServerDocs;
@@ -14,7 +14,7 @@ const getResolvedTypes = ({ filePath, filter }) => {
14
14
  // console.log("node.name.text", node.getText());
15
15
  // }
16
16
  if (ts.isTypeAliasDeclaration(node)) {
17
- if (!filter || (filter === null || filter === void 0 ? void 0 : filter.nodeNames.includes(node.name.text))) {
17
+ if (!filter || filter?.nodeNames.includes(node.name.text)) {
18
18
  const type1 = checker.getTypeAtLocation(node.type);
19
19
  const { resolvedType, visited } = (0, getSerializableType_1.getSerializableType)(type1, checker, undefined, [], filter, 0);
20
20
  results.push(resolvedType);
@@ -2,8 +2,8 @@ import * as ts from "typescript";
2
2
  type TS_Base = {
3
3
  alias?: string;
4
4
  aliasSymbolescapedName?: string;
5
- intersectionParent?: string;
6
5
  comments?: string;
6
+ intersectionParent?: string;
7
7
  };
8
8
  export type TS_Literal = TS_Base & {
9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AAO,EAAE,UAAU,CAAC,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG;IAC/B,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,OAAO,EAAE,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG;IACnC,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,OAAO,GACf,YAAY,GACZ,UAAU,GACV,SAAS,GACT,QAAQ,GACR,QAAQ,GACR,WAAW,GACX,QAAQ,GACR,UAAU,GACV,YAAY,CAAC;AAEjB,MAAM,MAAM,eAAe,GAAG,GAAG,CAC/B,MAAM,EACN;IAAE,YAAY,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC;IAAC,aAAa,CAAC,EAAE,OAAO,CAAA;CAAE,CAClE,CAAC;AAEF,eAAO,MAAM,mBAAmB,WACtB,GAAG,IAAI,WACN,GAAG,WAAW,uDAER,MAAM,EAAE,QACjB,kBAAkB,GAAG,SAAS,SAC7B,MAAM;kBACI,OAAO;;CA8UzB,CAAC;AAEF,KAAK,kBAAkB,GAAG;IACxB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AACF,eAAO,MAAM,WAAW,WACd,GAAG,IAAI,WACN,GAAG,WAAW,QACjB,kBAAkB;kBACP,OAAO;;CAMzB,CAAC"}
@@ -4,11 +4,10 @@ exports.resolveType = exports.getSerializableType = void 0;
4
4
  const ts = require("typescript");
5
5
  const prostgles_types_1 = require("prostgles-types");
6
6
  const getSerializableType = (myType, checker, visited = new Map(), parentAliases, opts, depth) => {
7
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
8
7
  let alias = "unknown";
9
- const { escapedName } = (_a = myType.aliasSymbol) !== null && _a !== void 0 ? _a : {};
10
- const aliasSymbolescapedName = escapedName === null || escapedName === void 0 ? void 0 : escapedName.toString();
11
- const symbol = (_b = myType.aliasSymbol) !== null && _b !== void 0 ? _b : myType.symbol;
8
+ const { escapedName } = myType.aliasSymbol ?? {};
9
+ const aliasSymbolescapedName = escapedName?.toString();
10
+ const symbol = myType.aliasSymbol ?? myType.symbol;
12
11
  const comments = symbol ? getSymbolComments(symbol, checker) : undefined;
13
12
  try {
14
13
  alias = checker.typeToString(myType);
@@ -19,21 +18,20 @@ const getSerializableType = (myType, checker, visited = new Map(), parentAliases
19
18
  /* Circular resolved type */
20
19
  const visitedType = visited.get(alias);
21
20
  if (visitedType) {
22
- return { resolvedType: (_c = visitedType.referenceType) !== null && _c !== void 0 ? _c : visitedType.resolvedType, visited };
21
+ return { resolvedType: visitedType.referenceType ?? visitedType.resolvedType, visited };
23
22
  }
24
23
  const withAlias = (_type) => {
25
- var _a;
26
24
  const finalComments = _type.comments || comments;
27
25
  const resolvedType = sortObjectsByKeyOrder({
28
- alias: (_a = _type.alias) !== null && _a !== void 0 ? _a : alias,
26
+ alias: _type.alias ?? alias,
29
27
  aliasSymbolescapedName,
30
28
  ..._type,
31
29
  ...(finalComments && { comments: finalComments }),
32
30
  }, ["type", "alias", "aliasSymbolescapedName", "comments"]);
33
31
  let referenceType;
34
- if ((opts === null || opts === void 0 ? void 0 : opts.excludedTypes.includes(alias)) ||
35
- (escapedName && (opts === null || opts === void 0 ? void 0 : opts.excludedTypes.includes(escapedName))) ||
36
- ((opts === null || opts === void 0 ? void 0 : opts.maxDepth) !== undefined && depth >= opts.maxDepth)) {
32
+ if (opts?.excludedTypes.includes(alias) ||
33
+ (escapedName && opts?.excludedTypes.includes(escapedName)) ||
34
+ (opts?.maxDepth !== undefined && depth >= opts.maxDepth)) {
37
35
  referenceType =
38
36
  resolvedType.type === "primitive" ?
39
37
  resolvedType
@@ -45,9 +43,9 @@ const getSerializableType = (myType, checker, visited = new Map(), parentAliases
45
43
  };
46
44
  }
47
45
  visited.set(alias, { resolvedType, referenceType, type: myType });
48
- return { resolvedType: referenceType !== null && referenceType !== void 0 ? referenceType : resolvedType, visited };
46
+ return { resolvedType: referenceType ?? resolvedType, visited };
49
47
  };
50
- const unresolvedParentAliases = (_d = parentAliases === null || parentAliases === void 0 ? void 0 : parentAliases.filter((a) => !visited.get(a))) !== null && _d !== void 0 ? _d : [];
48
+ const unresolvedParentAliases = parentAliases?.filter((a) => !visited.get(a)) ?? [];
51
49
  /* Circular unresolved type */
52
50
  if (unresolvedParentAliases.includes(alias)) {
53
51
  return withAlias({
@@ -99,9 +97,9 @@ const getSerializableType = (myType, checker, visited = new Map(), parentAliases
99
97
  if (checker.isArrayType(myType)) {
100
98
  const itemType = checker.getTypeArguments(myType)[0];
101
99
  if (itemType && checker.isTupleType(itemType)) {
102
- const tupleTypes = (_e = itemType.resolvedTypeArguments.map((d) => {
100
+ const tupleTypes = itemType.resolvedTypeArguments.map((d) => {
103
101
  return (0, exports.getSerializableType)(d, checker, visited, nextUnresolvedParentAliases, opts, depth + 1).resolvedType;
104
- })) !== null && _e !== void 0 ? _e : [];
102
+ }) ?? [];
105
103
  return withAlias({
106
104
  type: "tuple",
107
105
  itemTypes: tupleTypes,
@@ -149,12 +147,12 @@ const getSerializableType = (myType, checker, visited = new Map(), parentAliases
149
147
  if (objectType.objectFlags & ts.ObjectFlags.Reference) {
150
148
  const typeReference = objectType;
151
149
  const target = typeReference.target;
152
- if (((_f = target.symbol) === null || _f === void 0 ? void 0 : _f.escapedName) === "Promise") {
150
+ if (target.symbol?.escapedName === "Promise") {
153
151
  const _innerType = checker.getTypeArguments(typeReference)[0];
154
152
  const defaultType = { type: "primitive", subType: "any" };
155
153
  const resolvedInnerType = _innerType &&
156
154
  (0, exports.getSerializableType)(_innerType, checker, visited, nextUnresolvedParentAliases, opts, depth + 1).resolvedType;
157
- const innerType = (resolvedInnerType === null || resolvedInnerType === void 0 ? void 0 : resolvedInnerType.type) === "promise" ? defaultType : (resolvedInnerType !== null && resolvedInnerType !== void 0 ? resolvedInnerType : defaultType);
155
+ const innerType = resolvedInnerType?.type === "promise" ? defaultType : (resolvedInnerType ?? defaultType);
158
156
  return withAlias({
159
157
  type: "promise",
160
158
  innerType,
@@ -173,8 +171,11 @@ const getSerializableType = (myType, checker, visited = new Map(), parentAliases
173
171
  comments: propertyComments || undefined,
174
172
  };
175
173
  });
176
- const comments = ((_g = myType.aliasSymbol) === null || _g === void 0 ? void 0 : _g.declarations) &&
177
- ((_j = getNonInternalTSDeclarations((_h = myType.aliasSymbol) === null || _h === void 0 ? void 0 : _h.declarations)) === null || _j === void 0 ? void 0 : _j.flatMap((d) => (!d.jsDoc ? [] : d.jsDoc.map((jd) => jd.comment))).join("\n"));
174
+ const comments = myType.aliasSymbol?.declarations &&
175
+ getNonInternalTSDeclarations(myType.aliasSymbol?.declarations)
176
+ //@ts-ignore
177
+ ?.flatMap((d) => (!d.jsDoc ? [] : d.jsDoc.map((jd) => jd.comment)))
178
+ .join("\n");
178
179
  return withAlias({
179
180
  type: "object",
180
181
  properties,
@@ -187,12 +188,18 @@ const getSerializableType = (myType, checker, visited = new Map(), parentAliases
187
188
  if (myType.isIntersection()) {
188
189
  const intersectionTypes = myType.types.map((t) => {
189
190
  const { resolvedType: intersectionType } = (0, exports.getSerializableType)(t, checker, visited, nextUnresolvedParentAliases, opts, depth + 1);
190
- intersectionType.intersectionParent = aliasSymbolescapedName || alias;
191
+ if (intersectionType.type === "object") {
192
+ intersectionType.intersectionParent = aliasSymbolescapedName;
193
+ }
191
194
  return intersectionType;
192
195
  });
193
196
  if (intersectionTypes.every((t) => t.type === "object")) {
194
197
  const properties = intersectionTypes.reduce((acc, t) => {
195
- return { ...acc, ...t.properties };
198
+ const propertiesWithParentObject = Object.entries(t.properties).reduce((acc, [k, v]) => ({
199
+ ...acc,
200
+ [k]: { ...v, intersectionParent: t.aliasSymbolescapedName },
201
+ }), {});
202
+ return { ...acc, ...propertiesWithParentObject };
196
203
  }, {});
197
204
  return withAlias({
198
205
  type: "object",
@@ -244,9 +251,8 @@ const sortObjectsByKeyOrder = (obj, keyOrder) => {
244
251
  const arraySort = (arrayToSort, keyOrder) => {
245
252
  const keyOrderMap = new Map(keyOrder.map((value, index) => [value, index]));
246
253
  return arrayToSort.sort((a, b) => {
247
- var _a, _b;
248
- const aIndex = (_a = keyOrderMap.get(a)) !== null && _a !== void 0 ? _a : Infinity;
249
- const bIndex = (_b = keyOrderMap.get(b)) !== null && _b !== void 0 ? _b : Infinity;
254
+ const aIndex = keyOrderMap.get(a) ?? Infinity;
255
+ const bIndex = keyOrderMap.get(b) ?? Infinity;
250
256
  return aIndex - bIndex;
251
257
  });
252
258
  };
@@ -1 +1 @@
1
- {"version":3,"file":"loadTsFile.d.ts","sourceRoot":"","sources":["../loadTsFile.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,eAAO,MAAM,UAAU,aAAc,MAAM;;;;CAyC1C,CAAC"}
1
+ {"version":3,"file":"loadTsFile.d.ts","sourceRoot":"","sources":["../loadTsFile.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,eAAO,MAAM,UAAU,aAAc,MAAM;;;;CAqC1C,CAAC"}
@@ -4,17 +4,13 @@ exports.loadTsFile = void 0;
4
4
  const path = require("path");
5
5
  const ts = require("typescript");
6
6
  const loadTsFile = (filePath) => {
7
- // Normalize file path
8
7
  const absolutePath = path.resolve(filePath);
9
- // Create compiler host and program
10
8
  const configPath = ts.findConfigFile(path.dirname(absolutePath), ts.sys.fileExists, "tsconfig.json");
11
9
  if (!configPath) {
12
10
  throw new Error("Could not find a valid 'tsconfig.json'.");
13
11
  }
14
- // Parse the config file
15
12
  const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
16
13
  const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(configPath));
17
- // Create program
18
14
  const program = ts.createProgram({
19
15
  rootNames: [absolutePath],
20
16
  options: parsedConfig.options,
@@ -39,15 +39,10 @@ export declare const definitions: [{
39
39
  readonly optional: false;
40
40
  readonly comments: "Called when the prostgles server is ready to accept connections.\nIt waits for auth, tableConfig and other async configurations to complete before executing";
41
41
  };
42
- readonly dbOptions: {
43
- readonly type: "reference";
44
- readonly alias: "IDefaults";
45
- readonly optional: true;
46
- };
47
42
  readonly tsGeneratedTypesDir: {
48
43
  readonly type: "reference";
49
44
  readonly alias: "string | undefined";
50
- readonly comments: "If defined then a `DBSchemaGenerated.d.ts` file will be created in the provided directory.\nThis file exports a `DBSchemaGenerated` type which contains types for the database tables and\ncan be used as a generic type input for the prostgles instances to ensure type safety";
45
+ readonly comments: "If defined then a `DBGeneratedSchema.d.ts` file will be created in the provided directory.\nThis file exports a `DBGeneratedSchema` type which contains types for the database tables and\ncan be used as a generic type input for the prostgles instances to ensure type safety";
51
46
  readonly optional: true;
52
47
  };
53
48
  readonly disableRealtime: {
@@ -257,7 +252,7 @@ export declare const definitions: [{
257
252
  readonly subType: "boolean";
258
253
  }];
259
254
  readonly optional: true;
260
- readonly comments: "If truthy then DBSchemaGenerated.d.ts will be updated\nand \"onReady\" will be called with new schema on both client and server";
255
+ readonly comments: "If truthy then DBGeneratedSchema.d.ts will be updated\nand \"onReady\" will be called with new schema on both client and server";
261
256
  };
262
257
  readonly keywords: {
263
258
  readonly type: "reference";
@@ -272,8 +267,7 @@ export declare const definitions: [{
272
267
  };
273
268
  readonly fileTable: {
274
269
  readonly type: "reference";
275
- readonly alias: "FileTableConfig";
276
- readonly aliasSymbolescapedName: "FileTableConfig";
270
+ readonly alias: "FileTableConfig | undefined";
277
271
  readonly comments: "Enables file storage and serving.\nCurrently supports saving files locally or to AWS S3";
278
272
  readonly optional: true;
279
273
  };
@@ -1 +1 @@
1
- {"version":3,"file":"serverTypes.d.ts","sourceRoot":"","sources":["../serverTypes.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuVM,CAAC"}
1
+ {"version":3,"file":"serverTypes.d.ts","sourceRoot":"","sources":["../serverTypes.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiVM,CAAC"}
@@ -48,15 +48,10 @@ exports.definitions = [
48
48
  "optional": false,
49
49
  "comments": "Called when the prostgles server is ready to accept connections.\nIt waits for auth, tableConfig and other async configurations to complete before executing"
50
50
  },
51
- "dbOptions": {
52
- "type": "reference",
53
- "alias": "IDefaults",
54
- "optional": true
55
- },
56
51
  "tsGeneratedTypesDir": {
57
52
  "type": "reference",
58
53
  "alias": "string | undefined",
59
- "comments": "If defined then a `DBSchemaGenerated.d.ts` file will be created in the provided directory.\nThis file exports a `DBSchemaGenerated` type which contains types for the database tables and\ncan be used as a generic type input for the prostgles instances to ensure type safety",
54
+ "comments": "If defined then a `DBGeneratedSchema.d.ts` file will be created in the provided directory.\nThis file exports a `DBGeneratedSchema` type which contains types for the database tables and\ncan be used as a generic type input for the prostgles instances to ensure type safety",
60
55
  "optional": true
61
56
  },
62
57
  "disableRealtime": {
@@ -297,7 +292,7 @@ exports.definitions = [
297
292
  }
298
293
  ],
299
294
  "optional": true,
300
- "comments": "If truthy then DBSchemaGenerated.d.ts will be updated\nand \"onReady\" will be called with new schema on both client and server"
295
+ "comments": "If truthy then DBGeneratedSchema.d.ts will be updated\nand \"onReady\" will be called with new schema on both client and server"
301
296
  },
302
297
  "keywords": {
303
298
  "type": "reference",
@@ -312,8 +307,7 @@ exports.definitions = [
312
307
  },
313
308
  "fileTable": {
314
309
  "type": "reference",
315
- "alias": "FileTableConfig",
316
- "aliasSymbolescapedName": "FileTableConfig",
310
+ "alias": "FileTableConfig | undefined",
317
311
  "comments": "Enables file storage and serving.\nCurrently supports saving files locally or to AWS S3",
318
312
  "optional": true
319
313
  },