jinaga-server 2.1.8 → 2.3.0
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/authorization/authorization-keystore.d.ts +2 -2
- package/dist/authorization/authorization-keystore.js +10 -10
- package/dist/authorization/authorization-keystore.js.map +1 -1
- package/dist/jinaga-server.d.ts +2 -2
- package/dist/jinaga-server.js +17 -29
- package/dist/jinaga-server.js.map +1 -1
- package/dist/postgres/postgres-keystore.d.ts +2 -1
- package/dist/postgres/postgres-keystore.js +5 -4
- package/dist/postgres/postgres-keystore.js.map +1 -1
- package/dist/postgres/postgres-store.d.ts +4 -1
- package/dist/postgres/postgres-store.js +60 -53
- package/dist/postgres/postgres-store.js.map +1 -1
- package/dist/postgres/specification-result-sql.d.ts +1 -1
- package/dist/postgres/specification-result-sql.js +21 -21
- package/dist/postgres/specification-result-sql.js.map +1 -1
- package/dist/postgres/specification-sql.d.ts +2 -2
- package/dist/postgres/specification-sql.js +19 -19
- package/dist/postgres/specification-sql.js.map +1 -1
- package/dist/postgres/sql.d.ts +1 -1
- package/dist/postgres/sql.js +14 -14
- package/dist/postgres/sql.js.map +1 -1
- package/package.json +2 -2
- package/src/authorization/authorization-keystore.ts +11 -11
- package/src/jinaga-server.ts +26 -40
- package/src/postgres/postgres-keystore.ts +4 -4
- package/src/postgres/postgres-store.ts +61 -53
- package/src/postgres/specification-result-sql.ts +21 -21
- package/src/postgres/specification-sql.ts +19 -19
- package/src/postgres/sql.ts +14 -14
- package/test/postgres/postgresReadSpec.ts +1 -1
- package/test/postgres/postgresSpec.ts +1 -1
- package/test/postgres/postgresSpecificationSpec.ts +1 -1
- package/dist/http/node-http.d.ts +0 -7
- package/dist/http/node-http.js +0 -135
- package/dist/http/node-http.js.map +0 -1
- package/src/http/node-http.ts +0 -115
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Authorization, AuthorizationRules, FactFeed, FactRecord, FactReference, Feed, Query, Specification, Storage, UserIdentity } from "jinaga";
|
|
2
2
|
import { Keystore } from "../keystore";
|
|
3
3
|
export declare class AuthorizationKeystore implements Authorization {
|
|
4
|
-
private
|
|
4
|
+
private store;
|
|
5
5
|
private keystore;
|
|
6
6
|
private authorizationEngine;
|
|
7
|
-
constructor(
|
|
7
|
+
constructor(store: Storage, keystore: Keystore, authorizationRules: AuthorizationRules | null);
|
|
8
8
|
getOrCreateUserFact(userIdentity: UserIdentity): Promise<FactRecord>;
|
|
9
9
|
query(userIdentity: UserIdentity, start: FactReference, query: Query): Promise<import("jinaga").FactPath[]>;
|
|
10
10
|
read(userIdentity: UserIdentity, start: FactReference[], specification: Specification): Promise<import("jinaga").ProjectedResult[]>;
|
|
@@ -12,11 +12,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.AuthorizationKeystore = void 0;
|
|
13
13
|
const jinaga_1 = require("jinaga");
|
|
14
14
|
class AuthorizationKeystore {
|
|
15
|
-
constructor(
|
|
16
|
-
this.
|
|
15
|
+
constructor(store, keystore, authorizationRules) {
|
|
16
|
+
this.store = store;
|
|
17
17
|
this.keystore = keystore;
|
|
18
18
|
this.authorizationEngine = authorizationRules &&
|
|
19
|
-
new jinaga_1.AuthorizationEngine(authorizationRules,
|
|
19
|
+
new jinaga_1.AuthorizationEngine(authorizationRules, store);
|
|
20
20
|
}
|
|
21
21
|
getOrCreateUserFact(userIdentity) {
|
|
22
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -27,26 +27,26 @@ class AuthorizationKeystore {
|
|
|
27
27
|
signatures: []
|
|
28
28
|
}
|
|
29
29
|
];
|
|
30
|
-
yield this.
|
|
30
|
+
yield this.store.save(envelopes);
|
|
31
31
|
return userFact;
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
query(userIdentity, start, query) {
|
|
35
|
-
return this.
|
|
35
|
+
return this.store.query(start, query);
|
|
36
36
|
}
|
|
37
37
|
read(userIdentity, start, specification) {
|
|
38
|
-
return this.
|
|
38
|
+
return this.store.read(start, specification);
|
|
39
39
|
}
|
|
40
40
|
feed(userIdentity, feed, bookmark) {
|
|
41
|
-
return this.
|
|
41
|
+
return this.store.feed(feed, bookmark);
|
|
42
42
|
}
|
|
43
43
|
load(userIdentity, references) {
|
|
44
|
-
return this.
|
|
44
|
+
return this.store.load(references);
|
|
45
45
|
}
|
|
46
46
|
save(userIdentity, facts) {
|
|
47
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
48
|
if (!this.authorizationEngine) {
|
|
49
|
-
const envelopes = yield this.
|
|
49
|
+
const envelopes = yield this.store.save(facts.map(fact => ({
|
|
50
50
|
fact,
|
|
51
51
|
signatures: []
|
|
52
52
|
})));
|
|
@@ -56,7 +56,7 @@ class AuthorizationKeystore {
|
|
|
56
56
|
const authorizedFacts = yield this.authorizationEngine.authorizeFacts(facts, userFact);
|
|
57
57
|
if (userIdentity) {
|
|
58
58
|
const signedFacts = yield this.keystore.signFacts(userIdentity, authorizedFacts);
|
|
59
|
-
const envelopes = yield this.
|
|
59
|
+
const envelopes = yield this.store.save(signedFacts);
|
|
60
60
|
return envelopes.map(envelope => envelope.fact);
|
|
61
61
|
}
|
|
62
62
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorization-keystore.js","sourceRoot":"","sources":["../../src/authorization/authorization-keystore.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAagB;AAIhB,MAAa,qBAAqB;IAG9B,YACY,
|
|
1
|
+
{"version":3,"file":"authorization-keystore.js","sourceRoot":"","sources":["../../src/authorization/authorization-keystore.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAagB;AAIhB,MAAa,qBAAqB;IAG9B,YACY,KAAc,EACd,QAAkB,EAC1B,kBAA6C;QAFrC,UAAK,GAAL,KAAK,CAAS;QACd,aAAQ,GAAR,QAAQ,CAAU;QAG1B,IAAI,CAAC,mBAAmB,GAAG,kBAAkB;YACzC,IAAI,4BAAmB,CAAC,kBAAkB,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E,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;aACnD;YAED,MAAM,QAAQ,GAAG,YAAY,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YACrF,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,cAAc,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YACvF,IAAI,YAAY,EAAE;gBACd,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC;gBACjF,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;gBACrD,OAAO,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;aACnD;iBACI;gBACD,OAAO,eAAe,CAAC;aAC1B;QACL,CAAC;KAAA;CACJ;AA5DD,sDA4DC"}
|
package/dist/jinaga-server.d.ts
CHANGED
|
@@ -3,11 +3,11 @@ import { AuthorizationRules, Jinaga, Model } from "jinaga";
|
|
|
3
3
|
import { Pool } from "pg";
|
|
4
4
|
export declare type JinagaServerConfig = {
|
|
5
5
|
pgStore?: string | Pool;
|
|
6
|
+
pgStoreSchema?: string;
|
|
6
7
|
pgKeystore?: string | Pool;
|
|
7
|
-
|
|
8
|
+
pgKeystoreSchema?: string;
|
|
8
9
|
model?: Model;
|
|
9
10
|
authorization?: (a: AuthorizationRules) => AuthorizationRules;
|
|
10
|
-
httpTimeoutSeconds?: number;
|
|
11
11
|
};
|
|
12
12
|
export declare type JinagaServerInstance = {
|
|
13
13
|
handler: Handler;
|
package/dist/jinaga-server.js
CHANGED
|
@@ -15,7 +15,6 @@ const pg_1 = require("pg");
|
|
|
15
15
|
const authentication_device_1 = require("./authentication/authentication-device");
|
|
16
16
|
const authentication_session_1 = require("./authentication/authentication-session");
|
|
17
17
|
const authorization_keystore_1 = require("./authorization/authorization-keystore");
|
|
18
|
-
const node_http_1 = require("./http/node-http");
|
|
19
18
|
const router_1 = require("./http/router");
|
|
20
19
|
const memory_feed_cache_1 = require("./memory/memory-feed-cache");
|
|
21
20
|
const postgres_keystore_1 = require("./postgres/postgres-keystore");
|
|
@@ -30,14 +29,14 @@ class JinagaServer {
|
|
|
30
29
|
const pools = {};
|
|
31
30
|
const store = createStore(config, pools);
|
|
32
31
|
const source = new jinaga_1.ObservableSourceImpl(store);
|
|
33
|
-
const fork =
|
|
32
|
+
const fork = new jinaga_1.PassThroughFork(store);
|
|
34
33
|
const keystore = createKeystore(config, pools);
|
|
35
34
|
const authorizationRules = config.authorization ? config.authorization(new jinaga_1.AuthorizationRules(config.model)) : null;
|
|
36
35
|
const authorization = createAuthorization(authorizationRules, store, keystore);
|
|
37
36
|
const feedCache = new memory_feed_cache_1.MemoryFeedCache();
|
|
38
37
|
const router = new router_1.HttpRouter(authorization, feedCache);
|
|
39
38
|
const authentication = createAuthentication(store, keystore, authorizationRules);
|
|
40
|
-
const network =
|
|
39
|
+
const network = new jinaga_1.NetworkNoOp();
|
|
41
40
|
const factManager = new jinaga_1.FactManager(authentication, fork, source, store, network);
|
|
42
41
|
const j = new jinaga_1.Jinaga(factManager, syncStatusNotifier);
|
|
43
42
|
function close() {
|
|
@@ -61,7 +60,7 @@ exports.JinagaServer = JinagaServer;
|
|
|
61
60
|
function createStore(config, pools) {
|
|
62
61
|
if (config.pgStore) {
|
|
63
62
|
const pool = getPool(config.pgStore, pools);
|
|
64
|
-
const store = new postgres_store_1.PostgresStore(pool);
|
|
63
|
+
const store = new postgres_store_1.PostgresStore(pool, validateSchema(config.pgStoreSchema));
|
|
65
64
|
return store;
|
|
66
65
|
}
|
|
67
66
|
else {
|
|
@@ -69,24 +68,13 @@ function createStore(config, pools) {
|
|
|
69
68
|
}
|
|
70
69
|
}
|
|
71
70
|
function createFork(config, store, syncStatusNotifier) {
|
|
72
|
-
|
|
73
|
-
const httpConnection = new node_http_1.NodeHttpConnection(config.httpEndpoint);
|
|
74
|
-
const httpTimeoutSeconds = config.httpTimeoutSeconds || 5;
|
|
75
|
-
const webClient = new jinaga_1.WebClient(httpConnection, syncStatusNotifier, {
|
|
76
|
-
timeoutSeconds: httpTimeoutSeconds
|
|
77
|
-
});
|
|
78
|
-
const fork = new jinaga_1.TransientFork(store, webClient);
|
|
79
|
-
return fork;
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
return new jinaga_1.PassThroughFork(store);
|
|
83
|
-
}
|
|
71
|
+
return new jinaga_1.PassThroughFork(store);
|
|
84
72
|
}
|
|
85
73
|
function createKeystore(config, pools) {
|
|
86
74
|
const uriOrPool = config.pgKeystore;
|
|
87
75
|
if (uriOrPool) {
|
|
88
76
|
const pool = getPool(uriOrPool, pools);
|
|
89
|
-
const keystore = new postgres_keystore_1.PostgresKeystore(pool);
|
|
77
|
+
const keystore = new postgres_keystore_1.PostgresKeystore(pool, validateSchema(config.pgKeystoreSchema));
|
|
90
78
|
return keystore;
|
|
91
79
|
}
|
|
92
80
|
else {
|
|
@@ -106,18 +94,7 @@ function createAuthentication(store, keystore, authorizationRules) {
|
|
|
106
94
|
return keystore ? new authentication_device_1.AuthenticationDevice(store, keystore, authorizationRules, localDeviceIdentity) : new jinaga_1.AuthenticationNoOp();
|
|
107
95
|
}
|
|
108
96
|
function createNetwork(config) {
|
|
109
|
-
|
|
110
|
-
const httpConnection = new node_http_1.NodeHttpConnection(config.httpEndpoint);
|
|
111
|
-
const httpTimeoutSeconds = config.httpTimeoutSeconds || 5;
|
|
112
|
-
const syncStatusNotifier = new jinaga_1.SyncStatusNotifier();
|
|
113
|
-
const webClient = new jinaga_1.WebClient(httpConnection, syncStatusNotifier, {
|
|
114
|
-
timeoutSeconds: httpTimeoutSeconds
|
|
115
|
-
});
|
|
116
|
-
return new jinaga_1.HttpNetwork(webClient);
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
return new jinaga_1.NetworkNoOp();
|
|
120
|
-
}
|
|
97
|
+
return new jinaga_1.NetworkNoOp();
|
|
121
98
|
}
|
|
122
99
|
function getPool(uriOrPool, pools) {
|
|
123
100
|
if (typeof uriOrPool === 'string') {
|
|
@@ -183,4 +160,15 @@ function withSession(store, keystore, authorizationRules, req, callback) {
|
|
|
183
160
|
yield callback(j);
|
|
184
161
|
});
|
|
185
162
|
}
|
|
163
|
+
function validateSchema(schema) {
|
|
164
|
+
if (!schema) {
|
|
165
|
+
return "public";
|
|
166
|
+
}
|
|
167
|
+
// Verify that the schema is a valid Postgres schema name.
|
|
168
|
+
// https://www.postgresql.org/docs/9.1/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
|
|
169
|
+
if (!/^[a-z_][a-z0-9_$]*$/.test(schema)) {
|
|
170
|
+
throw new Error(`Invalid schema name: ${schema}. Schema names must start with a letter or underscore, and contain only letters, numbers, and underscores.`);
|
|
171
|
+
}
|
|
172
|
+
return schema;
|
|
173
|
+
}
|
|
186
174
|
//# sourceMappingURL=jinaga-server.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jinaga-server.js","sourceRoot":"","sources":["../src/jinaga-server.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,
|
|
1
|
+
{"version":3,"file":"jinaga-server.js","sourceRoot":"","sources":["../src/jinaga-server.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,mCAiBgB;AAChB,2BAA0B;AAE1B,kFAA8E;AAC9E,oFAAgF;AAChF,mFAA+E;AAC/E,0CAAwD;AAExD,kEAA6D;AAC7D,oEAAgE;AAChE,8DAA0D;AAmB1D,MAAM,mBAAmB,GAAG;IACxB,QAAQ,EAAE,QAAQ;IAClB,EAAE,EAAE,OAAO;CACd,CAAC;AAEF,MAAa,YAAY;IACrB,MAAM,CAAC,MAAM,CAAC,MAA0B;QACpC,MAAM,kBAAkB,GAAG,IAAI,2BAAkB,EAAE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AI,2BAAkB,EAAE,CAAC;QACzL,MAAM,kBAAkB,GAAG,IAAI,2BAAkB,EAAE,CAAC;QACpD,MAAM,IAAI,GAAG,IAAI,wBAAe,CAAC,KAAK,CAAC,CAAC;QACxC,MAAM,gBAAgB,GAAG,IAAI,yBAAgB,CAAC,KAAK,CAAC,CAAC;QACrD,MAAM,OAAO,GAAG,IAAI,oBAAW,EAAE,CAAC;QAClC,MAAM,WAAW,GAAG,IAAI,oBAAW,CAAC,cAAc,EAAE,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QAC5F,MAAM,CAAC,GAAG,IAAI,eAAM,CAAC,WAAW,EAAE,kBAAkB,CAAC,CAAC;QACtD,MAAM,QAAQ,CAAC,CAAC,CAAC,CAAC;IACtB,CAAC;CAAA;AAED,SAAS,cAAc,CAAC,MAA0B;IAC9C,IAAI,CAAC,MAAM,EAAE;QACT,OAAO,QAAQ,CAAC;KACnB;IAED,0DAA0D;IAC1D,qFAAqF;IACrF,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;QACrC,MAAM,IAAI,KAAK,CAAC,wBAAwB,MAAM,4GAA4G,CAAC,CAAC;KAC/J;IAED,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
|
@@ -2,9 +2,10 @@ import { FactEnvelope, FactRecord, UserIdentity } from "jinaga";
|
|
|
2
2
|
import { Pool } from "pg";
|
|
3
3
|
import { Keystore } from "../keystore";
|
|
4
4
|
export declare class PostgresKeystore implements Keystore {
|
|
5
|
+
private schema;
|
|
5
6
|
private connectionFactory;
|
|
6
7
|
private cache;
|
|
7
|
-
constructor(pool: Pool);
|
|
8
|
+
constructor(pool: Pool, schema: string);
|
|
8
9
|
getOrCreateUserFact(userIdentity: UserIdentity): Promise<FactRecord>;
|
|
9
10
|
getOrCreateDeviceFact(deviceIdentity: UserIdentity): Promise<FactRecord>;
|
|
10
11
|
getUserFact(userIdentity: UserIdentity): Promise<FactRecord>;
|
|
@@ -15,7 +15,8 @@ const node_forge_1 = require("node-forge");
|
|
|
15
15
|
const connection_1 = require("./connection");
|
|
16
16
|
;
|
|
17
17
|
class PostgresKeystore {
|
|
18
|
-
constructor(pool) {
|
|
18
|
+
constructor(pool, schema) {
|
|
19
|
+
this.schema = schema;
|
|
19
20
|
this.cache = new Map();
|
|
20
21
|
this.connectionFactory = new connection_1.ConnectionFactory(pool);
|
|
21
22
|
}
|
|
@@ -77,7 +78,7 @@ class PostgresKeystore {
|
|
|
77
78
|
}
|
|
78
79
|
selectKeyPair(connection, userIdentity) {
|
|
79
80
|
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
-
const { rows } = yield connection.query(
|
|
81
|
+
const { rows } = yield connection.query(`SELECT public_key, private_key FROM ${this.schema}.user WHERE provider = $1 AND user_identifier = $2`, [userIdentity.provider, userIdentity.id]);
|
|
81
82
|
if (rows.length > 1) {
|
|
82
83
|
throw new Error('Duplicate entries found in the keystore');
|
|
83
84
|
}
|
|
@@ -104,7 +105,7 @@ class PostgresKeystore {
|
|
|
104
105
|
}
|
|
105
106
|
selectOrInsertKeyPair(connection, userIdentity) {
|
|
106
107
|
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
-
const { rows } = yield connection.query(
|
|
108
|
+
const { rows } = yield connection.query(`SELECT public_key, private_key FROM ${this.schema}.user WHERE provider = $1 AND user_identifier = $2`, [userIdentity.provider, userIdentity.id]);
|
|
108
109
|
if (rows.length > 1) {
|
|
109
110
|
throw new Error('Duplicate entries found in the keystore');
|
|
110
111
|
}
|
|
@@ -124,7 +125,7 @@ class PostgresKeystore {
|
|
|
124
125
|
const keypair = node_forge_1.pki.rsa.generateKeyPair({ bits: 2048 });
|
|
125
126
|
const privatePem = node_forge_1.pki.privateKeyToPem(keypair.privateKey);
|
|
126
127
|
const publicPem = node_forge_1.pki.publicKeyToPem(keypair.publicKey);
|
|
127
|
-
yield connection.query(
|
|
128
|
+
yield connection.query(`INSERT INTO ${this.schema}.user (provider, user_identifier, private_key, public_key) VALUES ($1, $2, $3, $4)`, [userIdentity.provider, userIdentity.id, privatePem, publicPem]);
|
|
128
129
|
return { publicPem, privatePem };
|
|
129
130
|
});
|
|
130
131
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-keystore.js","sourceRoot":"","sources":["../../src/postgres/postgres-keystore.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAA6H;AAC7H,2CAA2C;AAI3C,6CAAiD;AAKhD,CAAC;AAEF,MAAa,gBAAgB;IAIzB,YAAa,IAAU;
|
|
1
|
+
{"version":3,"file":"postgres-keystore.js","sourceRoot":"","sources":["../../src/postgres/postgres-keystore.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAA6H;AAC7H,2CAA2C;AAI3C,6CAAiD;AAKhD,CAAC;AAEF,MAAa,gBAAgB;IAIzB,YAAa,IAAU,EAAU,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;QAFvC,UAAK,GAAyB,IAAI,GAAG,EAAE,CAAC;QAG5C,IAAI,CAAC,iBAAiB,GAAG,IAAI,8BAAiB,CAAC,IAAI,CAAC,CAAC;IACzD,CAAC;IAED,mBAAmB,CAAC,YAA0B;QAC1C,OAAO,IAAI,CAAC,uBAAuB,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC;IACrE,CAAC;IAED,qBAAqB,CAAC,cAA4B;QAC9C,OAAO,IAAI,CAAC,uBAAuB,CAAC,eAAe,EAAE,cAAc,CAAC,CAAC;IACzE,CAAC;IAED,WAAW,CAAC,YAA0B;QAClC,OAAO,IAAI,CAAC,eAAe,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC;IAC7D,CAAC;IAED,aAAa,CAAC,cAA4B;QACtC,OAAO,IAAI,CAAC,eAAe,CAAC,eAAe,EAAE,cAAc,CAAC,CAAC;IACjE,CAAC;IAEK,SAAS,CAAC,YAA0B,EAAE,KAAmB;;YAC3D,IAAI,CAAC,YAAY,EAAE;gBACf,O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,MAAM,SAAS,GAAG,iBAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IACzD,OAAO;QACH,IAAI;QACJ,UAAU,EAAE,CAAC;gBACT,SAAS;gBACT,SAAS,EAAE,SAAS;aACvB,CAAC;KACL,CAAC;AACN,CAAC"}
|
|
@@ -2,10 +2,11 @@ import { FactEnvelope, FactFeed, FactPath, FactRecord, FactReference, Feed, Quer
|
|
|
2
2
|
import { Pool } from "pg";
|
|
3
3
|
import { FactTypeMap, RoleMap } from "./maps";
|
|
4
4
|
export declare class PostgresStore implements Storage {
|
|
5
|
+
private schema;
|
|
5
6
|
private connectionFactory;
|
|
6
7
|
private factTypeMap;
|
|
7
8
|
private roleMap;
|
|
8
|
-
constructor(pool: Pool);
|
|
9
|
+
constructor(pool: Pool, schema: string);
|
|
9
10
|
close(): Promise<void>;
|
|
10
11
|
save(envelopes: FactEnvelope[]): Promise<FactEnvelope[]>;
|
|
11
12
|
query(start: FactReference, query: Query): Promise<FactPath[]>;
|
|
@@ -22,4 +23,6 @@ export declare class PostgresStore implements Storage {
|
|
|
22
23
|
private loadFactTypesFromReferences;
|
|
23
24
|
loadBookmark(feed: string): Promise<string>;
|
|
24
25
|
saveBookmark(feed: string, bookmark: string): Promise<void>;
|
|
26
|
+
getMruDate(specificationHash: string): Promise<Date | null>;
|
|
27
|
+
setMruDate(specificationHash: string, mruDate: Date): Promise<void>;
|
|
25
28
|
}
|