jinaga-server 2.1.4 → 2.1.6
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/dist/postgres/connection.d.ts +1 -0
- package/dist/postgres/connection.js +27 -3
- package/dist/postgres/connection.js.map +1 -1
- package/docs/distribution-rules.txt +32 -0
- package/integration-test/jinaga-test/package-lock.json +3 -3
- package/package.json +2 -2
- package/src/postgres/connection.ts +32 -3
|
@@ -16,7 +16,30 @@ const promise_1 = require("../util/promise");
|
|
|
16
16
|
class ConnectionFactory {
|
|
17
17
|
constructor(postgresUri) {
|
|
18
18
|
this.postgresPool = new pg_1.Pool({
|
|
19
|
-
connectionString: postgresUri
|
|
19
|
+
connectionString: postgresUri,
|
|
20
|
+
log(...messages) {
|
|
21
|
+
jinaga_1.Trace.info(messages.join(' '));
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
// Parse the Postgres URI to find the host name.
|
|
25
|
+
if (postgresUri.startsWith('postgres://')) {
|
|
26
|
+
const host = postgresUri.split('@')[1].split(':')[0];
|
|
27
|
+
this.server = host;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
this.server = 'localhost';
|
|
31
|
+
}
|
|
32
|
+
let connectionCount = 0;
|
|
33
|
+
this.postgresPool.on('connect', (client) => {
|
|
34
|
+
connectionCount++;
|
|
35
|
+
jinaga_1.Trace.metric(`Postgres connected ${this.server}`, { connections: connectionCount });
|
|
36
|
+
});
|
|
37
|
+
this.postgresPool.on('remove', (client) => {
|
|
38
|
+
connectionCount--;
|
|
39
|
+
jinaga_1.Trace.metric(`Postgres disconnected ${this.server}`, { connections: connectionCount });
|
|
40
|
+
});
|
|
41
|
+
this.postgresPool.on('error', (err, client) => {
|
|
42
|
+
jinaga_1.Trace.error(err);
|
|
20
43
|
});
|
|
21
44
|
}
|
|
22
45
|
close() {
|
|
@@ -79,6 +102,7 @@ class ConnectionFactory {
|
|
|
79
102
|
}
|
|
80
103
|
}
|
|
81
104
|
if (pause[attempt] > 0) {
|
|
105
|
+
jinaga_1.Trace.warn("Postgres retrying in " + pause[attempt] + "ms");
|
|
82
106
|
yield (0, promise_1.delay)(pause[attempt]);
|
|
83
107
|
}
|
|
84
108
|
}
|
|
@@ -86,8 +110,8 @@ class ConnectionFactory {
|
|
|
86
110
|
});
|
|
87
111
|
}
|
|
88
112
|
createClient() {
|
|
89
|
-
return
|
|
90
|
-
return
|
|
113
|
+
return jinaga_1.Trace.dependency('Postgres client', this.server, () => {
|
|
114
|
+
return this.postgresPool.connect();
|
|
91
115
|
});
|
|
92
116
|
}
|
|
93
117
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/postgres/connection.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAA+B;AAC/B,2BAAqD;AACrD,6CAAwC;AAIxC,MAAa,iBAAiB;
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/postgres/connection.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAA+B;AAC/B,2BAAqD;AACrD,6CAAwC;AAIxC,MAAa,iBAAiB;IAI1B,YAAa,WAAmB;QAC5B,IAAI,CAAC,YAAY,GAAG,IAAI,SAAI,CAAC;YACzB,gBAAgB,EAAE,WAAW;YAC7B,GAAG,CAAC,GAAG,QAAQ;gBACX,cAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;YACnC,CAAC;SACJ,CAAC,CAAC;QAEH,gDAAgD;QAChD,IAAI,WAAW,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE;YACvC,MAAM,IAAI,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YACrD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;SACtB;aACI;YACD,IAAI,CAAC,M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;qBACX;iBACJ;gBACD,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;oBACpB,cAAK,CAAC,IAAI,CAAC,uBAAuB,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;oBAC5D,MAAM,IAAA,eAAK,EAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;iBAC/B;aACJ;YACD,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACnD,CAAC;KAAA;IAEO,YAAY;QAChB,OAAO,cAAK,CAAC,UAAU,CAAC,iBAAiB,EAAE,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE;YACzD,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;QACvC,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AA1GD,8CA0GC;AAED,SAAS,gBAAgB,CAAC,CAAM;IAC5B,IAAI,CAAC,CAAC,IAAI,KAAK,cAAc,EAAE;QAC3B,OAAO,IAAI,CAAC;KACf;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,SAAS,aAAa,CAAC,CAAM;IACzB,MAAM,KAAK,GAAG;QACV,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,OAAO,EAAE,CAAC,CAAC,OAAO;KACrB,CAAC;IACF,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Anybody can read approved comments
|
|
2
|
+
|
|
3
|
+
(site: Blog.Site) {
|
|
4
|
+
post: Blog.Post [
|
|
5
|
+
post->site: Blog.Site = site
|
|
6
|
+
!E {
|
|
7
|
+
deleted: Blog.Post.Deleted [
|
|
8
|
+
deleted->post: Blog.Post = post
|
|
9
|
+
]
|
|
10
|
+
}
|
|
11
|
+
]
|
|
12
|
+
comment: Blog.Comment [
|
|
13
|
+
comment->post: Blog.Post = post
|
|
14
|
+
E {
|
|
15
|
+
approved: Blog.Comment.Approved [
|
|
16
|
+
approved->comment: Blog.Comment = comment
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// The site owner can read all posts and comments
|
|
23
|
+
|
|
24
|
+
(site: Blog.Site, user: Jinaga.User) {
|
|
25
|
+
post: Blog.Post [
|
|
26
|
+
post->site: Blog.Site = site
|
|
27
|
+
post->owner: Jinaga.User = user
|
|
28
|
+
]
|
|
29
|
+
comment: Blog.Comment [
|
|
30
|
+
comment->post: Blog.Post = post
|
|
31
|
+
]
|
|
32
|
+
}
|
|
@@ -2737,9 +2737,9 @@
|
|
|
2737
2737
|
}
|
|
2738
2738
|
},
|
|
2739
2739
|
"node_modules/jinaga": {
|
|
2740
|
-
"version": "5.1.
|
|
2741
|
-
"resolved": "https://registry.npmjs.org/jinaga/-/jinaga-5.1.
|
|
2742
|
-
"integrity": "sha512-
|
|
2740
|
+
"version": "5.1.3",
|
|
2741
|
+
"resolved": "https://registry.npmjs.org/jinaga/-/jinaga-5.1.3.tgz",
|
|
2742
|
+
"integrity": "sha512-XCIyFbO0YFjGgbbf50qVa0DgbOkNPyYiOo1033pQRQPOOAp2Eov5DmA4Eaxf9RpiHRaF+ZOrjrleBaxbMd5l2A==",
|
|
2743
2743
|
"dependencies": {
|
|
2744
2744
|
"@stablelib/base64": "^1.0.1",
|
|
2745
2745
|
"@stablelib/sha512": "^1.0.1",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jinaga-server",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.6",
|
|
4
4
|
"description": "Application-agnostic back end for web applications",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"express": "^4.18.1",
|
|
46
|
-
"jinaga": "^5.1.
|
|
46
|
+
"jinaga": "^5.1.4",
|
|
47
47
|
"node-forge": "^1.3.1",
|
|
48
48
|
"passport": "^0.6.0",
|
|
49
49
|
"pg": "^8.7.1"
|
|
@@ -6,10 +6,36 @@ export type Row = { [key: string]: any };
|
|
|
6
6
|
|
|
7
7
|
export class ConnectionFactory {
|
|
8
8
|
private postgresPool: Pool;
|
|
9
|
+
private server: string;
|
|
9
10
|
|
|
10
11
|
constructor (postgresUri: string) {
|
|
11
12
|
this.postgresPool = new Pool({
|
|
12
|
-
connectionString: postgresUri
|
|
13
|
+
connectionString: postgresUri,
|
|
14
|
+
log(...messages) {
|
|
15
|
+
Trace.info(messages.join(' '));
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// Parse the Postgres URI to find the host name.
|
|
20
|
+
if (postgresUri.startsWith('postgres://')) {
|
|
21
|
+
const host = postgresUri.split('@')[1].split(':')[0];
|
|
22
|
+
this.server = host;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
this.server = 'localhost';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let connectionCount = 0;
|
|
29
|
+
this.postgresPool.on('connect', (client) => {
|
|
30
|
+
connectionCount++;
|
|
31
|
+
Trace.metric(`Postgres connected ${this.server}`, { connections: connectionCount });
|
|
32
|
+
});
|
|
33
|
+
this.postgresPool.on('remove', (client) => {
|
|
34
|
+
connectionCount--;
|
|
35
|
+
Trace.metric(`Postgres disconnected ${this.server}`, { connections: connectionCount });
|
|
36
|
+
});
|
|
37
|
+
this.postgresPool.on('error', (err, client) => {
|
|
38
|
+
Trace.error(err);
|
|
13
39
|
});
|
|
14
40
|
}
|
|
15
41
|
|
|
@@ -72,14 +98,17 @@ export class ConnectionFactory {
|
|
|
72
98
|
}
|
|
73
99
|
}
|
|
74
100
|
if (pause[attempt] > 0) {
|
|
101
|
+
Trace.warn("Postgres retrying in " + pause[attempt] + "ms");
|
|
75
102
|
await delay(pause[attempt]);
|
|
76
103
|
}
|
|
77
104
|
}
|
|
78
105
|
throw new Error("Number of attempts exceeded");
|
|
79
106
|
}
|
|
80
107
|
|
|
81
|
-
private
|
|
82
|
-
return
|
|
108
|
+
private createClient() {
|
|
109
|
+
return Trace.dependency('Postgres client', this.server, () => {
|
|
110
|
+
return this.postgresPool.connect();
|
|
111
|
+
});
|
|
83
112
|
}
|
|
84
113
|
}
|
|
85
114
|
|