prostgles-server 3.0.87 → 3.0.89
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.
- package/.eslintignore +5 -0
- package/.eslintrc.json +30 -0
- package/dist/DBEventsManager.js +1 -1
- package/dist/DBEventsManager.js.map +1 -1
- package/dist/DBSchemaBuilder.d.ts.map +1 -1
- package/dist/DBSchemaBuilder.js +6 -6
- package/dist/DBSchemaBuilder.js.map +1 -1
- package/dist/DboBuilder/QueryBuilder/Functions.js +9 -9
- package/dist/DboBuilder/QueryBuilder/Functions.js.map +1 -1
- package/dist/DboBuilder/QueryBuilder/QueryBuilder.d.ts.map +1 -1
- package/dist/DboBuilder/QueryBuilder/QueryBuilder.js +8 -7
- package/dist/DboBuilder/QueryBuilder/QueryBuilder.js.map +1 -1
- package/dist/DboBuilder/QueryBuilder/makeSelectQuery.d.ts.map +1 -1
- package/dist/DboBuilder/QueryBuilder/makeSelectQuery.js +4 -4
- package/dist/DboBuilder/QueryBuilder/makeSelectQuery.js.map +1 -1
- package/dist/DboBuilder/TableHandler.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler.js +18 -20
- package/dist/DboBuilder/TableHandler.js.map +1 -1
- package/dist/DboBuilder/ViewHandler.d.ts +0 -10
- package/dist/DboBuilder/ViewHandler.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler.js +50 -63
- package/dist/DboBuilder/ViewHandler.js.map +1 -1
- package/dist/DboBuilder/delete.js +0 -1
- package/dist/DboBuilder/delete.js.map +1 -1
- package/dist/DboBuilder/getColumns.js +5 -4
- package/dist/DboBuilder/getColumns.js.map +1 -1
- package/dist/DboBuilder/getCondition.d.ts.map +1 -1
- package/dist/DboBuilder/getCondition.js +6 -6
- package/dist/DboBuilder/getCondition.js.map +1 -1
- package/dist/DboBuilder/insert.js +15 -16
- package/dist/DboBuilder/insert.js.map +1 -1
- package/dist/DboBuilder/insertDataParse.d.ts.map +1 -1
- package/dist/DboBuilder/insertDataParse.js +9 -10
- package/dist/DboBuilder/insertDataParse.js.map +1 -1
- package/dist/DboBuilder/parseUpdateRules.js +2 -2
- package/dist/DboBuilder/parseUpdateRules.js.map +1 -1
- package/dist/DboBuilder/runSQL.d.ts.map +1 -1
- package/dist/DboBuilder/runSQL.js +5 -5
- package/dist/DboBuilder/runSQL.js.map +1 -1
- package/dist/DboBuilder/subscribe.js +3 -3
- package/dist/DboBuilder/subscribe.js.map +1 -1
- package/dist/DboBuilder/update.js +5 -6
- package/dist/DboBuilder/update.js.map +1 -1
- package/dist/DboBuilder/uploadFile.d.ts.map +1 -1
- package/dist/DboBuilder/uploadFile.js +1 -1
- package/dist/DboBuilder/uploadFile.js.map +1 -1
- package/dist/DboBuilder.d.ts.map +1 -1
- package/dist/DboBuilder.js +13 -14
- package/dist/DboBuilder.js.map +1 -1
- package/dist/FileManager.d.ts.map +1 -1
- package/dist/FileManager.js +3 -5
- package/dist/FileManager.js.map +1 -1
- package/dist/Filtering.js +7 -7
- package/dist/Filtering.js.map +1 -1
- package/dist/JSONBValidation/validate_jsonb_schema_sql.d.ts +3 -0
- package/dist/JSONBValidation/validate_jsonb_schema_sql.d.ts.map +1 -0
- package/dist/JSONBValidation/validate_jsonb_schema_sql.js +295 -0
- package/dist/JSONBValidation/validate_jsonb_schema_sql.js.map +1 -0
- package/dist/JSONBValidation/validation.d.ts +108 -0
- package/dist/JSONBValidation/validation.d.ts.map +1 -0
- package/dist/JSONBValidation/validation.js +222 -0
- package/dist/JSONBValidation/validation.js.map +1 -0
- package/dist/PostgresNotifListenManager.js +1 -1
- package/dist/PostgresNotifListenManager.js.map +1 -1
- package/dist/Prostgles.d.ts.map +1 -1
- package/dist/Prostgles.js +20 -20
- package/dist/Prostgles.js.map +1 -1
- package/dist/PubSubManager/initPubSubManager.d.ts.map +1 -1
- package/dist/PubSubManager/initPubSubManager.js +10 -7
- package/dist/PubSubManager/initPubSubManager.js.map +1 -1
- package/dist/PublishParser.d.ts.map +1 -1
- package/dist/PublishParser.js +122 -125
- package/dist/PublishParser.js.map +1 -1
- package/dist/SyncReplication.d.ts.map +1 -1
- package/dist/SyncReplication.js +19 -16
- package/dist/SyncReplication.js.map +1 -1
- package/dist/TableConfig.d.ts +9 -5
- package/dist/TableConfig.d.ts.map +1 -1
- package/dist/TableConfig.js +33 -12
- package/dist/TableConfig.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/shortestPath.js +11 -11
- package/dist/shortestPath.js.map +1 -1
- package/dist/validation.d.ts +50 -24
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +177 -53
- package/dist/validation.js.map +1 -1
- package/lib/AuthHandler.d.ts +11 -11
- package/lib/AuthHandler.d.ts.map +1 -1
- package/lib/DBEventsManager.js +1 -1
- package/lib/DBEventsManager.ts +1 -1
- package/lib/DBSchemaBuilder.d.ts +3 -3
- package/lib/DBSchemaBuilder.d.ts.map +1 -1
- package/lib/DBSchemaBuilder.js +6 -6
- package/lib/DBSchemaBuilder.ts +10 -12
- package/lib/DboBuilder/QueryBuilder/Functions.d.ts +3 -3
- package/lib/DboBuilder/QueryBuilder/Functions.d.ts.map +1 -1
- package/lib/DboBuilder/QueryBuilder/Functions.js +9 -9
- package/lib/DboBuilder/QueryBuilder/Functions.ts +13 -13
- package/lib/DboBuilder/QueryBuilder/QueryBuilder.d.ts +3 -3
- package/lib/DboBuilder/QueryBuilder/QueryBuilder.d.ts.map +1 -1
- package/lib/DboBuilder/QueryBuilder/QueryBuilder.js +8 -7
- package/lib/DboBuilder/QueryBuilder/QueryBuilder.ts +12 -12
- package/lib/DboBuilder/QueryBuilder/makeSelectQuery.d.ts.map +1 -1
- package/lib/DboBuilder/QueryBuilder/makeSelectQuery.js +4 -4
- package/lib/DboBuilder/QueryBuilder/makeSelectQuery.ts +5 -5
- package/lib/DboBuilder/TableHandler.d.ts +1 -1
- package/lib/DboBuilder/TableHandler.d.ts.map +1 -1
- package/lib/DboBuilder/TableHandler.js +18 -20
- package/lib/DboBuilder/TableHandler.ts +21 -20
- package/lib/DboBuilder/ViewHandler.d.ts +1 -11
- package/lib/DboBuilder/ViewHandler.d.ts.map +1 -1
- package/lib/DboBuilder/ViewHandler.js +50 -63
- package/lib/DboBuilder/ViewHandler.ts +68 -97
- package/lib/DboBuilder/delete.js +0 -1
- package/lib/DboBuilder/delete.ts +1 -1
- package/lib/DboBuilder/getColumns.js +5 -4
- package/lib/DboBuilder/getColumns.ts +5 -5
- package/lib/DboBuilder/getCondition.d.ts.map +1 -1
- package/lib/DboBuilder/getCondition.js +6 -6
- package/lib/DboBuilder/getCondition.ts +7 -7
- package/lib/DboBuilder/insert.js +15 -16
- package/lib/DboBuilder/insert.ts +18 -18
- package/lib/DboBuilder/insertDataParse.d.ts.map +1 -1
- package/lib/DboBuilder/insertDataParse.js +9 -10
- package/lib/DboBuilder/insertDataParse.ts +42 -43
- package/lib/DboBuilder/parseUpdateRules.js +2 -2
- package/lib/DboBuilder/parseUpdateRules.ts +2 -2
- package/lib/DboBuilder/runSQL.d.ts.map +1 -1
- package/lib/DboBuilder/runSQL.js +5 -5
- package/lib/DboBuilder/runSQL.ts +6 -6
- package/lib/DboBuilder/subscribe.d.ts +1 -1
- package/lib/DboBuilder/subscribe.d.ts.map +1 -1
- package/lib/DboBuilder/subscribe.js +3 -3
- package/lib/DboBuilder/subscribe.ts +3 -3
- package/lib/DboBuilder/update.js +5 -6
- package/lib/DboBuilder/update.ts +6 -6
- package/lib/DboBuilder/uploadFile.d.ts.map +1 -1
- package/lib/DboBuilder/uploadFile.js +1 -1
- package/lib/DboBuilder/uploadFile.ts +2 -2
- package/lib/DboBuilder.d.ts +22 -22
- package/lib/DboBuilder.d.ts.map +1 -1
- package/lib/DboBuilder.js +13 -14
- package/lib/DboBuilder.ts +19 -19
- package/lib/FileManager.d.ts +6 -6
- package/lib/FileManager.d.ts.map +1 -1
- package/lib/FileManager.js +3 -5
- package/lib/FileManager.ts +7 -6
- package/lib/Filtering.d.ts +1 -1
- package/lib/Filtering.d.ts.map +1 -1
- package/lib/Filtering.js +7 -7
- package/lib/Filtering.ts +7 -7
- package/lib/JSONBValidation/validate_jsonb_schema_sql.d.ts +3 -0
- package/lib/JSONBValidation/validate_jsonb_schema_sql.d.ts.map +1 -0
- package/lib/JSONBValidation/validate_jsonb_schema_sql.js +294 -0
- package/lib/JSONBValidation/validate_jsonb_schema_sql.ts +293 -0
- package/lib/JSONBValidation/validation.d.ts +108 -0
- package/lib/JSONBValidation/validation.d.ts.map +1 -0
- package/lib/JSONBValidation/validation.js +221 -0
- package/lib/JSONBValidation/validation.ts +332 -0
- package/lib/PostgresNotifListenManager.d.ts +1 -1
- package/lib/PostgresNotifListenManager.d.ts.map +1 -1
- package/lib/PostgresNotifListenManager.js +1 -1
- package/lib/PostgresNotifListenManager.ts +1 -1
- package/lib/Prostgles.d.ts +14 -14
- package/lib/Prostgles.d.ts.map +1 -1
- package/lib/Prostgles.js +20 -20
- package/lib/Prostgles.ts +22 -21
- package/lib/PubSubManager/PubSubManager.d.ts +7 -7
- package/lib/PubSubManager/PubSubManager.d.ts.map +1 -1
- package/lib/PubSubManager/initPubSubManager.d.ts.map +1 -1
- package/lib/PubSubManager/initPubSubManager.js +10 -7
- package/lib/PubSubManager/initPubSubManager.ts +12 -7
- package/lib/PublishParser.d.ts +32 -32
- package/lib/PublishParser.d.ts.map +1 -1
- package/lib/PublishParser.js +121 -124
- package/lib/PublishParser.ts +125 -127
- package/lib/SchemaWatch.d.ts +1 -1
- package/lib/SchemaWatch.d.ts.map +1 -1
- package/lib/SyncReplication.d.ts +5 -5
- package/lib/SyncReplication.d.ts.map +1 -1
- package/lib/SyncReplication.js +19 -16
- package/lib/SyncReplication.ts +470 -471
- package/lib/TableConfig.d.ts +28 -24
- package/lib/TableConfig.d.ts.map +1 -1
- package/lib/TableConfig.js +33 -12
- package/lib/TableConfig.ts +55 -21
- package/lib/index.js +1 -1
- package/lib/index.ts +1 -1
- package/lib/shortestPath.d.ts +1 -1
- package/lib/shortestPath.d.ts.map +1 -1
- package/lib/shortestPath.js +11 -11
- package/lib/shortestPath.ts +11 -11
- package/package.json +10 -6
- package/tests/client/PID.txt +1 -1
- package/tests/client/package-lock.json +53 -31
- package/tests/client/package.json +4 -1
- package/tests/isomorphic_queries.d.ts +4 -1
- package/tests/isomorphic_queries.d.ts.map +1 -1
- package/tests/isomorphic_queries.js +38 -30
- package/tests/isomorphic_queries.ts +40 -33
- package/tests/server/DBoGenerated.d.ts +1 -1
- package/tests/server/index.js +8 -7
- package/tests/server/index.ts +10 -8
- package/tests/server/package-lock.json +76 -58
- package/tests/server/package.json +2 -2
- package/tests/server/server.ts +2 -3
- package/lib/validation.d.ts +0 -100
- package/lib/validation.d.ts.map +0 -1
- package/lib/validation.js +0 -280
- package/lib/validation.ts +0 -360
package/lib/TableConfig.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { AnyObject, TableInfo, ALLOWED_EXTENSION, ALLOWED_CONTENT_TYPE } from "prostgles-types";
|
|
2
2
|
import { JoinInfo } from "./DboBuilder";
|
|
3
3
|
import { DB, DBHandlerServer, Prostgles } from "./Prostgles";
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import { JSONB } from "./JSONBValidation/validation";
|
|
5
|
+
type ColExtraInfo = {
|
|
6
6
|
min?: string | number;
|
|
7
7
|
max?: string | number;
|
|
8
8
|
hint?: string;
|
|
9
9
|
};
|
|
10
|
-
export
|
|
10
|
+
export type I18N_Config<LANG_IDS> = {
|
|
11
11
|
[lang_id in keyof LANG_IDS]: string;
|
|
12
12
|
};
|
|
13
13
|
export declare const parseI18N: <LANG_IDS, Def extends string>(params: {
|
|
@@ -16,7 +16,7 @@ export declare const parseI18N: <LANG_IDS, Def extends string>(params: {
|
|
|
16
16
|
defaultLang: string | keyof LANG_IDS;
|
|
17
17
|
defaultValue: Def;
|
|
18
18
|
}) => string | Def;
|
|
19
|
-
|
|
19
|
+
type BaseTableDefinition<LANG_IDS = AnyObject> = {
|
|
20
20
|
info?: {
|
|
21
21
|
label?: string | I18N_Config<LANG_IDS>;
|
|
22
22
|
};
|
|
@@ -54,7 +54,7 @@ declare type BaseTableDefinition<LANG_IDS = AnyObject> = {
|
|
|
54
54
|
};
|
|
55
55
|
};
|
|
56
56
|
};
|
|
57
|
-
|
|
57
|
+
type LookupTableDefinition<LANG_IDS> = {
|
|
58
58
|
isLookupTable: {
|
|
59
59
|
values: {
|
|
60
60
|
[id_value: string]: {} | {
|
|
@@ -63,7 +63,7 @@ declare type LookupTableDefinition<LANG_IDS> = {
|
|
|
63
63
|
};
|
|
64
64
|
};
|
|
65
65
|
};
|
|
66
|
-
export
|
|
66
|
+
export type BaseColumn<LANG_IDS> = {
|
|
67
67
|
/**
|
|
68
68
|
* Will add these values to .getColumns() result
|
|
69
69
|
*/
|
|
@@ -72,17 +72,17 @@ export declare type BaseColumn<LANG_IDS> = {
|
|
|
72
72
|
[lang_id in keyof LANG_IDS]: string;
|
|
73
73
|
}>;
|
|
74
74
|
};
|
|
75
|
-
|
|
75
|
+
type SQLDefColumn = {
|
|
76
76
|
/**
|
|
77
77
|
* Raw sql statement used in creating/adding column
|
|
78
78
|
*/
|
|
79
79
|
sqlDefinition?: string;
|
|
80
80
|
};
|
|
81
|
-
|
|
81
|
+
type BaseColumnTypes = {
|
|
82
82
|
defaultValue?: any;
|
|
83
83
|
nullable?: boolean;
|
|
84
84
|
};
|
|
85
|
-
|
|
85
|
+
type TextColumn = BaseColumnTypes & {
|
|
86
86
|
isText: true;
|
|
87
87
|
/**
|
|
88
88
|
* Value will be trimmed before update/insert
|
|
@@ -93,14 +93,18 @@ declare type TextColumn = BaseColumnTypes & {
|
|
|
93
93
|
*/
|
|
94
94
|
lowerCased?: boolean;
|
|
95
95
|
};
|
|
96
|
-
export
|
|
97
|
-
jsonbSchema:
|
|
98
|
-
|
|
96
|
+
export type JSONBColumnDef = (BaseColumnTypes & {}) & ({
|
|
97
|
+
jsonbSchema: JSONB.JSONBSchema;
|
|
98
|
+
jsonbSchemaType?: undefined;
|
|
99
|
+
} | {
|
|
100
|
+
jsonbSchema?: undefined;
|
|
101
|
+
jsonbSchemaType: JSONB.ObjectSchema;
|
|
102
|
+
});
|
|
99
103
|
/**
|
|
100
104
|
* Allows referencing media to this table.
|
|
101
105
|
* Requires this table to have a primary key AND a valid fileTable config
|
|
102
106
|
*/
|
|
103
|
-
|
|
107
|
+
type MediaColumn = ({
|
|
104
108
|
name: string;
|
|
105
109
|
label?: string;
|
|
106
110
|
files: "one" | "many";
|
|
@@ -112,7 +116,7 @@ declare type MediaColumn = ({
|
|
|
112
116
|
} | {
|
|
113
117
|
allowedExtensions?: Record<Partial<ALLOWED_EXTENSION>, 1>;
|
|
114
118
|
}));
|
|
115
|
-
|
|
119
|
+
type ReferencedColumn = {
|
|
116
120
|
/**
|
|
117
121
|
* Will create a lookup table that this column will reference
|
|
118
122
|
*/
|
|
@@ -124,7 +128,7 @@ declare type ReferencedColumn = {
|
|
|
124
128
|
columnName?: string;
|
|
125
129
|
};
|
|
126
130
|
};
|
|
127
|
-
|
|
131
|
+
type JoinDef = {
|
|
128
132
|
sourceTable: string;
|
|
129
133
|
targetTable: string;
|
|
130
134
|
on: JoinInfo["paths"][number]["on"];
|
|
@@ -132,19 +136,19 @@ declare type JoinDef = {
|
|
|
132
136
|
/**
|
|
133
137
|
* Used in specifying a join path to a table. This column name can then be used in select
|
|
134
138
|
*/
|
|
135
|
-
|
|
139
|
+
type NamedJoinColumn = {
|
|
136
140
|
label?: string;
|
|
137
141
|
joinDef: JoinDef[];
|
|
138
142
|
};
|
|
139
|
-
|
|
143
|
+
type Enum<T extends string | number = any> = {
|
|
140
144
|
enum: T[] | readonly T[];
|
|
141
145
|
nullable?: boolean;
|
|
142
146
|
defaultValue?: T;
|
|
143
147
|
};
|
|
144
|
-
export
|
|
148
|
+
export type ColumnConfig<LANG_IDS = {
|
|
145
149
|
en: 1;
|
|
146
150
|
}> = string | StrictUnion<NamedJoinColumn | MediaColumn | (BaseColumn<LANG_IDS> & (SQLDefColumn | ReferencedColumn | TextColumn | JSONBColumnDef | Enum))>;
|
|
147
|
-
export
|
|
151
|
+
export type ColumnConfigs<LANG_IDS = {
|
|
148
152
|
en: 1;
|
|
149
153
|
}> = {
|
|
150
154
|
sql: string | BaseColumn<LANG_IDS> & SQLDefColumn;
|
|
@@ -155,10 +159,10 @@ export declare type ColumnConfigs<LANG_IDS = {
|
|
|
155
159
|
jsonb: BaseColumn<LANG_IDS> & JSONBColumnDef;
|
|
156
160
|
enum: BaseColumn<LANG_IDS> & Enum;
|
|
157
161
|
};
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
+
type UnionKeys<T> = T extends T ? keyof T : never;
|
|
163
|
+
type StrictUnionHelper<T, TAll> = T extends any ? T & Partial<Record<Exclude<UnionKeys<TAll>, keyof T>, never>> : never;
|
|
164
|
+
export type StrictUnion<T> = StrictUnionHelper<T, T>;
|
|
165
|
+
type TableDefinition<LANG_IDS> = {
|
|
162
166
|
columns?: {
|
|
163
167
|
[column_name: string]: ColumnConfig<LANG_IDS>;
|
|
164
168
|
};
|
|
@@ -212,7 +216,7 @@ declare type TableDefinition<LANG_IDS> = {
|
|
|
212
216
|
/**
|
|
213
217
|
* Helper utility to create lookup tables for TEXT columns
|
|
214
218
|
*/
|
|
215
|
-
export
|
|
219
|
+
export type TableConfig<LANG_IDS = {
|
|
216
220
|
en: 1;
|
|
217
221
|
}> = {
|
|
218
222
|
[table_name: string]: BaseTableDefinition<LANG_IDS> & (TableDefinition<LANG_IDS> | LookupTableDefinition<LANG_IDS>);
|
package/lib/TableConfig.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableConfig.d.ts","sourceRoot":"","sources":["TableConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,SAAS,EAAE,SAAS,EAAG,iBAAiB,EAAE,oBAAoB,
|
|
1
|
+
{"version":3,"file":"TableConf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AM,CAAA;KAAE,KAAG,CAAC,YAAY,GAAG;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,SAAS,CAAC;KAAE,CAAC,GAAG,SAAS,CAqC7I;IAED,WAAW,WAAY;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,GAAG,CAAA;KAAE,KAAG,IAAI,CAQvE;IAED,WAAW,gBAAiB,MAAM,eAAe,MAAM,KAAG,QAAQ,GAAG,SAAS,CA4B7E;IAEK,IAAI;IAkTV,GAAG,YAAa,GAAG,EAAE,UAIpB;CAEF"}
|
package/lib/TableConfig.js
CHANGED
|
@@ -4,7 +4,8 @@ exports.parseI18N = void 0;
|
|
|
4
4
|
const prostgles_types_1 = require("prostgles-types");
|
|
5
5
|
const DboBuilder_1 = require("./DboBuilder");
|
|
6
6
|
const PubSubManager_1 = require("./PubSubManager/PubSubManager");
|
|
7
|
-
const validation_1 = require("./validation");
|
|
7
|
+
const validation_1 = require("./JSONBValidation/validation");
|
|
8
|
+
const validate_jsonb_schema_sql_1 = require("./JSONBValidation/validate_jsonb_schema_sql");
|
|
8
9
|
const parseI18N = (params) => {
|
|
9
10
|
const { config, lang, defaultLang, defaultValue } = params;
|
|
10
11
|
if (config) {
|
|
@@ -29,13 +30,11 @@ class TableConfigurator {
|
|
|
29
30
|
throw "this.prostgles.dbo missing";
|
|
30
31
|
return this.prostgles.dbo;
|
|
31
32
|
}
|
|
32
|
-
;
|
|
33
33
|
get db() {
|
|
34
34
|
if (!this.prostgles.db)
|
|
35
35
|
throw "this.prostgles.db missing";
|
|
36
36
|
return this.prostgles.db;
|
|
37
37
|
}
|
|
38
|
-
;
|
|
39
38
|
// sidKeyName: string;
|
|
40
39
|
prostgles;
|
|
41
40
|
constructor(prostgles) {
|
|
@@ -63,7 +62,7 @@ class TableConfigurator {
|
|
|
63
62
|
result = {
|
|
64
63
|
...(result ?? {}),
|
|
65
64
|
...("info" in colConf && colConf?.info),
|
|
66
|
-
...(
|
|
65
|
+
...((colConf?.jsonbSchema || colConf?.jsonbSchemaType) && { jsonSchema: (0, validation_1.getJSONBSchemaAsJSONSchema)(params.table, params.col, colConf) })
|
|
67
66
|
};
|
|
68
67
|
/**
|
|
69
68
|
* Get labels from TableConfig if specified
|
|
@@ -184,6 +183,10 @@ class TableConfigurator {
|
|
|
184
183
|
const { nullable, defaultValue } = colConf;
|
|
185
184
|
return `${pgType} ${!nullable ? " NOT NULL " : ""} ${defaultValue ? ` DEFAULT ${(0, PubSubManager_1.asValue)(defaultValue)} ` : ""}`;
|
|
186
185
|
};
|
|
186
|
+
const jsonbSchema = (0, prostgles_types_1.isObject)(colConf) ? (("jsonbSchema" in colConf && colConf.jsonbSchema) ? { jsonbSchema: colConf.jsonbSchema, jsonbSchemaType: undefined } :
|
|
187
|
+
("jsonbSchemaType" in colConf && colConf.jsonbSchemaType) ? { jsonbSchema: undefined, jsonbSchemaType: colConf.jsonbSchemaType } :
|
|
188
|
+
undefined) :
|
|
189
|
+
undefined;
|
|
187
190
|
if ((0, prostgles_types_1.isObject)(colConf) && "references" in colConf && colConf.references) {
|
|
188
191
|
const { tableName: lookupTable, columnName: lookupCol = "id" } = colConf.references;
|
|
189
192
|
return ` ${colNameEsc} ${getColTypeDef(colConf.references, "TEXT")} REFERENCES ${lookupTable} (${lookupCol}) `;
|
|
@@ -192,7 +195,8 @@ class TableConfigurator {
|
|
|
192
195
|
return ` ${colNameEsc} ${typeof colConf === "string" ? colConf : colConf.sqlDefinition} `;
|
|
193
196
|
}
|
|
194
197
|
else if ((0, prostgles_types_1.isObject)(colConf) && "isText" in colConf && colConf.isText) {
|
|
195
|
-
let checks = ""
|
|
198
|
+
let checks = "";
|
|
199
|
+
const cArr = [];
|
|
196
200
|
if (colConf.lowerCased) {
|
|
197
201
|
cArr.push(`${colNameEsc} = LOWER(${colNameEsc})`);
|
|
198
202
|
}
|
|
@@ -204,20 +208,22 @@ class TableConfigurator {
|
|
|
204
208
|
}
|
|
205
209
|
return ` ${colNameEsc} ${getColTypeDef(colConf, "TEXT")} ${checks}`;
|
|
206
210
|
}
|
|
207
|
-
else if (
|
|
211
|
+
else if (jsonbSchema) {
|
|
212
|
+
const jsonbSchemaStr = (0, PubSubManager_1.asValue)({
|
|
213
|
+
...(0, prostgles_types_1.pickKeys)(colConf, ["enum", "nullable", "info"]),
|
|
214
|
+
...(jsonbSchema.jsonbSchemaType ? { type: jsonbSchema.jsonbSchemaType } : jsonbSchema.jsonbSchema)
|
|
215
|
+
}) + "::TEXT";
|
|
208
216
|
/** Validate default value against jsonbSchema */
|
|
217
|
+
const q = `SELECT ${validate_jsonb_schema_sql_1.VALIDATE_SCHEMA_FUNCNAME}(${jsonbSchemaStr}, ${(0, PubSubManager_1.asValue)(colConf.defaultValue) + "::JSONB"}, ARRAY[${(0, PubSubManager_1.asValue)(name)}]) as v`;
|
|
209
218
|
if (colConf.defaultValue) {
|
|
210
|
-
const checkStatement = (0, validation_1.getPGCheckConstraint)({ schema: colConf.jsonbSchema, escapedFieldName: (0, PubSubManager_1.asValue)(colConf.defaultValue) + "::JSONB", nullable: !!colConf.nullable }, 0);
|
|
211
|
-
const q = `SELECT ${checkStatement} as v`;
|
|
212
219
|
this.log(q);
|
|
213
220
|
this.dbo.sql(q, {}, { returnType: "row" }).then(row => {
|
|
214
221
|
if (!row?.v) {
|
|
215
|
-
console.error(`Default value (${colConf.defaultValue}) for ${tableName}.${name} does not satisfy the jsonb constraint check: ${
|
|
222
|
+
console.error(`Default value (${colConf.defaultValue}) for ${tableName}.${name} does not satisfy the jsonb constraint check: ${q}`);
|
|
216
223
|
}
|
|
217
224
|
});
|
|
218
225
|
}
|
|
219
|
-
|
|
220
|
-
return ` ${colNameEsc} ${getColTypeDef(colConf, "JSONB")} CHECK(${checkStatement})`;
|
|
226
|
+
return ` ${colNameEsc} ${getColTypeDef(colConf, "JSONB")} CHECK(${validate_jsonb_schema_sql_1.VALIDATE_SCHEMA_FUNCNAME}(${jsonbSchemaStr}, ${colNameEsc}, ARRAY[${(0, PubSubManager_1.asValue)(name)}]))`;
|
|
221
227
|
}
|
|
222
228
|
else if ("enum" in colConf) {
|
|
223
229
|
if (!colConf.enum?.length)
|
|
@@ -233,10 +239,25 @@ class TableConfigurator {
|
|
|
233
239
|
const colCreateLines = [];
|
|
234
240
|
const tableHandler = this.dbo[tableName];
|
|
235
241
|
if (tableConf.columns) {
|
|
242
|
+
const hasJSONBValidation = (0, prostgles_types_1.getKeys)(tableConf.columns).some(c => {
|
|
243
|
+
const cConf = tableConf.columns?.[c];
|
|
244
|
+
return cConf && (0, prostgles_types_1.isObject)(cConf) && (cConf.jsonbSchema || cConf.jsonbSchemaType);
|
|
245
|
+
});
|
|
246
|
+
/** Must install validation function */
|
|
247
|
+
if (hasJSONBValidation) {
|
|
248
|
+
try {
|
|
249
|
+
const fileContent = `CREATE SCHEMA IF NOT EXISTS prostgles;\n ${validate_jsonb_schema_sql_1.validate_jsonb_schema_sql}`;
|
|
250
|
+
await this.db.any(fileContent);
|
|
251
|
+
}
|
|
252
|
+
catch (err) {
|
|
253
|
+
console.error("Could not install the jsonb validation function due to error: ", err);
|
|
254
|
+
throw err;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
236
257
|
(0, prostgles_types_1.getKeys)(tableConf.columns).filter(c => {
|
|
237
258
|
const colDef = tableConf.columns[c];
|
|
238
259
|
return typeof colDef === "string" || !("joinDef" in colDef);
|
|
239
|
-
}).
|
|
260
|
+
}).forEach(colName => {
|
|
240
261
|
const colConf = tableConf.columns[colName];
|
|
241
262
|
/* Add columns to create statement */
|
|
242
263
|
if (!tableHandler) {
|
package/lib/TableConfig.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { getKeys, asName as _asName, AnyObject, TableInfo, ALLOWED_EXTENSION, ALLOWED_CONTENT_TYPE, isObject } from "prostgles-types";
|
|
1
|
+
import { getKeys, asName as _asName, AnyObject, TableInfo, ALLOWED_EXTENSION, ALLOWED_CONTENT_TYPE, isObject, pickKeys } from "prostgles-types";
|
|
2
2
|
import { isPlainObject, JoinInfo } from "./DboBuilder";
|
|
3
|
-
import { DB, DBHandlerServer,
|
|
3
|
+
import { DB, DBHandlerServer, Prostgles } from "./Prostgles";
|
|
4
4
|
import { asValue } from "./PubSubManager/PubSubManager";
|
|
5
|
-
import { getJSONBSchemaAsJSONSchema,
|
|
5
|
+
import { getJSONBSchemaAsJSONSchema, JSONB } from "./JSONBValidation/validation";
|
|
6
|
+
import { validate_jsonb_schema_sql, VALIDATE_SCHEMA_FUNCNAME } from "./JSONBValidation/validate_jsonb_schema_sql";
|
|
6
7
|
|
|
7
8
|
type ColExtraInfo = {
|
|
8
9
|
min?: string | number;
|
|
@@ -117,14 +118,18 @@ type TextColumn = BaseColumnTypes & {
|
|
|
117
118
|
lowerCased?: boolean;
|
|
118
119
|
}
|
|
119
120
|
|
|
120
|
-
export type JSONBColumnDef = BaseColumnTypes & {
|
|
121
|
-
jsonbSchema: ValidationSchema | Omit<OneOf, "optional">;
|
|
122
|
-
|
|
121
|
+
export type JSONBColumnDef = (BaseColumnTypes & {
|
|
123
122
|
/**
|
|
124
123
|
* If the new schema CHECK fails old rows the update old rows using this function
|
|
125
124
|
*/
|
|
126
125
|
// onMigrationFail?: <T>(failedRow: T) => AnyObject | Promise<AnyObject>;
|
|
127
|
-
}
|
|
126
|
+
}) & ({
|
|
127
|
+
jsonbSchema: JSONB.JSONBSchema;
|
|
128
|
+
jsonbSchemaType?: undefined;
|
|
129
|
+
} | {
|
|
130
|
+
jsonbSchema?: undefined;
|
|
131
|
+
jsonbSchemaType: JSONB.ObjectSchema;
|
|
132
|
+
})
|
|
128
133
|
|
|
129
134
|
/**
|
|
130
135
|
* Allows referencing media to this table.
|
|
@@ -199,7 +204,7 @@ export type ColumnConfigs<LANG_IDS = { en: 1 }> = {
|
|
|
199
204
|
|
|
200
205
|
type UnionKeys<T> = T extends T ? keyof T : never;
|
|
201
206
|
type StrictUnionHelper<T, TAll> = T extends any ? T & Partial<Record<Exclude<UnionKeys<TAll>, keyof T>, never>> : never;
|
|
202
|
-
type StrictUnion<T> = StrictUnionHelper<T, T>
|
|
207
|
+
export type StrictUnion<T> = StrictUnionHelper<T, T>
|
|
203
208
|
|
|
204
209
|
type TableDefinition<LANG_IDS> = {
|
|
205
210
|
columns?: {
|
|
@@ -278,11 +283,11 @@ export default class TableConfigurator<LANG_IDS = { en: 1 }> {
|
|
|
278
283
|
get dbo(): DBHandlerServer {
|
|
279
284
|
if (!this.prostgles.dbo) throw "this.prostgles.dbo missing"
|
|
280
285
|
return this.prostgles.dbo
|
|
281
|
-
}
|
|
286
|
+
}
|
|
282
287
|
get db(): DB {
|
|
283
288
|
if (!this.prostgles.db) throw "this.prostgles.db missing"
|
|
284
289
|
return this.prostgles.db
|
|
285
|
-
}
|
|
290
|
+
}
|
|
286
291
|
// sidKeyName: string;
|
|
287
292
|
prostgles: Prostgles
|
|
288
293
|
|
|
@@ -317,7 +322,7 @@ export default class TableConfigurator<LANG_IDS = { en: 1 }> {
|
|
|
317
322
|
result = {
|
|
318
323
|
...(result ?? {}),
|
|
319
324
|
...("info" in colConf && colConf?.info),
|
|
320
|
-
...(
|
|
325
|
+
...((colConf?.jsonbSchema || colConf?.jsonbSchemaType) && { jsonSchema: getJSONBSchemaAsJSONSchema(params.table, params.col, colConf) })
|
|
321
326
|
}
|
|
322
327
|
|
|
323
328
|
/**
|
|
@@ -452,6 +457,15 @@ export default class TableConfigurator<LANG_IDS = { en: 1 }> {
|
|
|
452
457
|
const { nullable, defaultValue } = colConf;
|
|
453
458
|
return `${pgType} ${!nullable ? " NOT NULL " : ""} ${defaultValue ? ` DEFAULT ${asValue(defaultValue)} ` : ""}`
|
|
454
459
|
}
|
|
460
|
+
|
|
461
|
+
const jsonbSchema =
|
|
462
|
+
isObject(colConf)? (
|
|
463
|
+
("jsonbSchema" in colConf && colConf.jsonbSchema)? { jsonbSchema: colConf.jsonbSchema, jsonbSchemaType: undefined } :
|
|
464
|
+
("jsonbSchemaType" in colConf && colConf.jsonbSchemaType)? { jsonbSchema: undefined, jsonbSchemaType: colConf.jsonbSchemaType } :
|
|
465
|
+
undefined
|
|
466
|
+
) :
|
|
467
|
+
undefined;
|
|
468
|
+
|
|
455
469
|
if (isObject(colConf) && "references" in colConf && colConf.references) {
|
|
456
470
|
|
|
457
471
|
const { tableName: lookupTable, columnName: lookupCol = "id" } = colConf.references;
|
|
@@ -462,7 +476,8 @@ export default class TableConfigurator<LANG_IDS = { en: 1 }> {
|
|
|
462
476
|
return ` ${colNameEsc} ${typeof colConf === "string"? colConf : colConf.sqlDefinition} `;
|
|
463
477
|
|
|
464
478
|
} else if (isObject(colConf) && "isText" in colConf && colConf.isText) {
|
|
465
|
-
let checks = ""
|
|
479
|
+
let checks = "";
|
|
480
|
+
const cArr = [];
|
|
466
481
|
if (colConf.lowerCased) {
|
|
467
482
|
cArr.push(`${colNameEsc} = LOWER(${colNameEsc})`)
|
|
468
483
|
}
|
|
@@ -474,21 +489,24 @@ export default class TableConfigurator<LANG_IDS = { en: 1 }> {
|
|
|
474
489
|
}
|
|
475
490
|
return ` ${colNameEsc} ${getColTypeDef(colConf, "TEXT")} ${checks}`;
|
|
476
491
|
|
|
477
|
-
} else if (
|
|
492
|
+
} else if (jsonbSchema) {
|
|
493
|
+
|
|
494
|
+
const jsonbSchemaStr = asValue({
|
|
495
|
+
...pickKeys(colConf, ["enum", "nullable", "info"]),
|
|
496
|
+
...(jsonbSchema.jsonbSchemaType? { type: jsonbSchema.jsonbSchemaType } : jsonbSchema.jsonbSchema)
|
|
497
|
+
}) + "::TEXT";
|
|
478
498
|
|
|
479
499
|
/** Validate default value against jsonbSchema */
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
const q = `SELECT ${checkStatement} as v`
|
|
500
|
+
const q = `SELECT ${VALIDATE_SCHEMA_FUNCNAME}(${jsonbSchemaStr}, ${asValue(colConf.defaultValue)+"::JSONB"}, ARRAY[${asValue(name)}]) as v`
|
|
501
|
+
if(colConf.defaultValue){
|
|
483
502
|
this.log(q)
|
|
484
503
|
this.dbo.sql!(q, {}, { returnType: "row" }).then(row => {
|
|
485
504
|
if(!row?.v) {
|
|
486
|
-
console.error(`Default value (${colConf.defaultValue}) for ${tableName}.${name} does not satisfy the jsonb constraint check: ${
|
|
505
|
+
console.error(`Default value (${colConf.defaultValue}) for ${tableName}.${name} does not satisfy the jsonb constraint check: ${q}`);
|
|
487
506
|
}
|
|
488
507
|
})
|
|
489
508
|
}
|
|
490
|
-
|
|
491
|
-
return ` ${colNameEsc} ${getColTypeDef(colConf, "JSONB")} CHECK(${checkStatement})`;
|
|
509
|
+
return ` ${colNameEsc} ${getColTypeDef(colConf, "JSONB")} CHECK(${VALIDATE_SCHEMA_FUNCNAME}(${jsonbSchemaStr}, ${colNameEsc}, ARRAY[${asValue(name)}]))`;
|
|
492
510
|
|
|
493
511
|
} else if("enum" in colConf) {
|
|
494
512
|
if(!colConf.enum?.length) throw new Error("colConf.enum Must not be empty");
|
|
@@ -504,10 +522,27 @@ export default class TableConfigurator<LANG_IDS = { en: 1 }> {
|
|
|
504
522
|
const colCreateLines: string[] = [];
|
|
505
523
|
const tableHandler = this.dbo[tableName];
|
|
506
524
|
if (tableConf.columns) {
|
|
525
|
+
const hasJSONBValidation = getKeys(tableConf.columns).some(c => {
|
|
526
|
+
const cConf = tableConf.columns?.[c];
|
|
527
|
+
return cConf && isObject(cConf) && (cConf.jsonbSchema || cConf.jsonbSchemaType)
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
/** Must install validation function */
|
|
531
|
+
if(hasJSONBValidation){
|
|
532
|
+
try {
|
|
533
|
+
|
|
534
|
+
const fileContent = `CREATE SCHEMA IF NOT EXISTS prostgles;\n ${validate_jsonb_schema_sql}`;
|
|
535
|
+
await this.db.any(fileContent);
|
|
536
|
+
} catch(err: any){
|
|
537
|
+
console.error("Could not install the jsonb validation function due to error: ", err);
|
|
538
|
+
throw err;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
507
542
|
getKeys(tableConf.columns).filter(c => {
|
|
508
543
|
const colDef = tableConf.columns![c];
|
|
509
544
|
return typeof colDef === "string" || !("joinDef" in colDef)
|
|
510
|
-
}).
|
|
545
|
+
}).forEach(colName => {
|
|
511
546
|
const colConf = tableConf.columns![colName];
|
|
512
547
|
|
|
513
548
|
/* Add columns to create statement */
|
|
@@ -516,7 +551,6 @@ export default class TableConfigurator<LANG_IDS = { en: 1 }> {
|
|
|
516
551
|
|
|
517
552
|
} else if (tableHandler && !tableHandler.columns?.find(c => colName === c.name)) {
|
|
518
553
|
|
|
519
|
-
|
|
520
554
|
queries.push(`
|
|
521
555
|
ALTER TABLE ${asName(tableName)}
|
|
522
556
|
ADD COLUMN ${getColDef(colName, colConf)};
|
package/lib/index.js
CHANGED
package/lib/index.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Prostgles, ProstglesInitOptions, InitResult } from "./Prostgles";
|
|
|
3
3
|
|
|
4
4
|
function prostgles<S = void, SUser extends SessionUser = SessionUser>(params: ProstglesInitOptions<S, SUser>){
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
const prgl = new Prostgles(params as any);
|
|
7
7
|
return prgl.init(params.onReady as any);
|
|
8
8
|
}
|
|
9
9
|
export = prostgles;
|
package/lib/shortestPath.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shortestPath.d.ts","sourceRoot":"","sources":["shortestPath.ts"],"names":[],"mappings":"AAcA,
|
|
1
|
+
{"version":3,"file":"shortestPath.d.ts","sourceRoot":"","sources":["shortestPath.ts"],"names":[],"mappings":"AAcA,MAAM,MAAM,KAAK,GAAG;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;CACxC,CAAC;AAEF,eAAO,MAAM,gBAAgB,UAAW,KAAK,aAAa,MAAM,WAAW,MAAM,KAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAgErH,CAAC"}
|
package/lib/shortestPath.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.findShortestPath = void 0;
|
|
4
4
|
const shortestDistanceNode = (distances, visited) => {
|
|
5
5
|
let shortest = null;
|
|
6
|
-
for (
|
|
7
|
-
|
|
6
|
+
for (const node in distances) {
|
|
7
|
+
const currentIsShortest = shortest === null || distances[node] < distances[shortest];
|
|
8
8
|
if (currentIsShortest && !visited.includes(node)) {
|
|
9
9
|
shortest = node;
|
|
10
10
|
}
|
|
@@ -17,28 +17,28 @@ const findShortestPath = (graph, startNode, endNode) => {
|
|
|
17
17
|
distances[endNode] = "Infinity";
|
|
18
18
|
distances = Object.assign(distances, graph[startNode]);
|
|
19
19
|
// track paths
|
|
20
|
-
|
|
21
|
-
for (
|
|
20
|
+
const parents = { endNode: null };
|
|
21
|
+
for (const child in graph[startNode]) {
|
|
22
22
|
parents[child] = startNode;
|
|
23
23
|
}
|
|
24
24
|
// track nodes that have already been visited
|
|
25
|
-
|
|
25
|
+
const visited = [];
|
|
26
26
|
// find the nearest node
|
|
27
27
|
let node = shortestDistanceNode(distances, visited);
|
|
28
28
|
// for that node
|
|
29
29
|
while (node) {
|
|
30
30
|
// find its distance from the start node & its child nodes
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
const distance = distances[node];
|
|
32
|
+
const children = graph[node];
|
|
33
33
|
// for each of those child nodes
|
|
34
|
-
for (
|
|
34
|
+
for (const child in children) {
|
|
35
35
|
// make sure each child node is not the start node
|
|
36
36
|
if (String(child) === String(startNode)) {
|
|
37
37
|
continue;
|
|
38
38
|
}
|
|
39
39
|
else {
|
|
40
40
|
// save the distance from the start node to the child node
|
|
41
|
-
|
|
41
|
+
const newdistance = distance + children[child];
|
|
42
42
|
// if there's no recorded distance from the start node to the child node in the distances object
|
|
43
43
|
// or if the recorded distance is shorter than the previously stored distance from the start node to the child node
|
|
44
44
|
// save the distance to the object
|
|
@@ -56,7 +56,7 @@ const findShortestPath = (graph, startNode, endNode) => {
|
|
|
56
56
|
}
|
|
57
57
|
// using the stored paths from start node to end node
|
|
58
58
|
// record the shortest path
|
|
59
|
-
|
|
59
|
+
const shortestPath = [endNode];
|
|
60
60
|
let parent = parents[endNode];
|
|
61
61
|
while (parent) {
|
|
62
62
|
shortestPath.push(parent);
|
|
@@ -64,7 +64,7 @@ const findShortestPath = (graph, startNode, endNode) => {
|
|
|
64
64
|
}
|
|
65
65
|
shortestPath.reverse();
|
|
66
66
|
// return the shortest path from start node to end node & its distance
|
|
67
|
-
|
|
67
|
+
const results = {
|
|
68
68
|
distance: distances[endNode],
|
|
69
69
|
path: shortestPath,
|
|
70
70
|
};
|
package/lib/shortestPath.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { AnyObject } from "prostgles-types";
|
|
|
3
3
|
const shortestDistanceNode = (distances: AnyObject, visited: AnyObject) => {
|
|
4
4
|
let shortest = null;
|
|
5
5
|
|
|
6
|
-
for (
|
|
7
|
-
|
|
6
|
+
for (const node in distances) {
|
|
7
|
+
const currentIsShortest =
|
|
8
8
|
shortest === null || distances[node] < distances[shortest];
|
|
9
9
|
if (currentIsShortest && !visited.includes(node)) {
|
|
10
10
|
shortest = node;
|
|
@@ -23,13 +23,13 @@ export const findShortestPath = (graph: Graph, startNode: string, endNode: strin
|
|
|
23
23
|
distances = Object.assign(distances, graph[startNode]);
|
|
24
24
|
|
|
25
25
|
// track paths
|
|
26
|
-
|
|
27
|
-
for (
|
|
26
|
+
const parents: AnyObject = { endNode: null };
|
|
27
|
+
for (const child in graph[startNode]) {
|
|
28
28
|
parents[child] = startNode;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// track nodes that have already been visited
|
|
32
|
-
|
|
32
|
+
const visited: AnyObject = [];
|
|
33
33
|
|
|
34
34
|
// find the nearest node
|
|
35
35
|
let node = shortestDistanceNode(distances, visited);
|
|
@@ -37,16 +37,16 @@ export const findShortestPath = (graph: Graph, startNode: string, endNode: strin
|
|
|
37
37
|
// for that node
|
|
38
38
|
while (node) {
|
|
39
39
|
// find its distance from the start node & its child nodes
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
const distance = distances[node];
|
|
41
|
+
const children = graph[node];
|
|
42
42
|
// for each of those child nodes
|
|
43
|
-
for (
|
|
43
|
+
for (const child in children) {
|
|
44
44
|
// make sure each child node is not the start node
|
|
45
45
|
if (String(child) === String(startNode)) {
|
|
46
46
|
continue;
|
|
47
47
|
} else {
|
|
48
48
|
// save the distance from the start node to the child node
|
|
49
|
-
|
|
49
|
+
const newdistance = distance + children[child];
|
|
50
50
|
// if there's no recorded distance from the start node to the child node in the distances object
|
|
51
51
|
// or if the recorded distance is shorter than the previously stored distance from the start node to the child node
|
|
52
52
|
// save the distance to the object
|
|
@@ -65,7 +65,7 @@ export const findShortestPath = (graph: Graph, startNode: string, endNode: strin
|
|
|
65
65
|
|
|
66
66
|
// using the stored paths from start node to end node
|
|
67
67
|
// record the shortest path
|
|
68
|
-
|
|
68
|
+
const shortestPath = [endNode];
|
|
69
69
|
let parent = parents[endNode];
|
|
70
70
|
while (parent) {
|
|
71
71
|
shortestPath.push(parent);
|
|
@@ -74,7 +74,7 @@ export const findShortestPath = (graph: Graph, startNode: string, endNode: strin
|
|
|
74
74
|
shortestPath.reverse();
|
|
75
75
|
|
|
76
76
|
// return the shortest path from start node to end node & its distance
|
|
77
|
-
|
|
77
|
+
const results = {
|
|
78
78
|
distance: distances[endNode],
|
|
79
79
|
path: shortestPath,
|
|
80
80
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prostgles-server",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.89",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"prepare": "npm run build",
|
|
12
12
|
"start": "tsc --watch",
|
|
13
13
|
"build": "tsc",
|
|
14
|
+
"lint": "eslint . --ext .ts",
|
|
14
15
|
"test": "rm -rf ./node_modules/* && npm i && tsc && cd tests/ && ./test.sh"
|
|
15
16
|
},
|
|
16
17
|
"repository": {
|
|
@@ -37,16 +38,19 @@
|
|
|
37
38
|
"bluebird": "^3.7.2",
|
|
38
39
|
"check-disk-space": "^3.3.1",
|
|
39
40
|
"file-type": "^17.1.4",
|
|
40
|
-
"
|
|
41
|
-
"pg-promise": "^10.11.1",
|
|
41
|
+
"pg-promise": "^11.3.0",
|
|
42
42
|
"prostgles-types": "^3.0.24",
|
|
43
|
-
"sharp": "^0.31.0"
|
|
44
|
-
"typescript": "^4.9.5"
|
|
43
|
+
"sharp": "^0.31.0"
|
|
45
44
|
},
|
|
46
45
|
"devDependencies": {
|
|
47
46
|
"@aws-sdk/types": "^3.110.0",
|
|
48
47
|
"@types/bluebird": "^3.5.36",
|
|
48
|
+
"@types/json-schema": "^7.0.11",
|
|
49
49
|
"@types/node": "^18.0.3",
|
|
50
|
-
"@types/sharp": "^0.30.4"
|
|
50
|
+
"@types/sharp": "^0.30.4",
|
|
51
|
+
"@typescript-eslint/eslint-plugin": "^5.53.0",
|
|
52
|
+
"@typescript-eslint/parser": "^5.53.0",
|
|
53
|
+
"eslint": "^8.35.0",
|
|
54
|
+
"typescript": "^4.9.5"
|
|
51
55
|
}
|
|
52
56
|
}
|