jinaga-server 3.3.1 → 3.3.2
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/jinaga-server.d.ts +2 -0
- package/dist/jinaga-server.js +64 -8
- package/dist/jinaga-server.js.map +1 -1
- package/dist/postgres/postgres-queue.d.ts +10 -0
- package/dist/postgres/postgres-queue.js +24 -0
- package/dist/postgres/postgres-queue.js.map +1 -0
- package/package.json +2 -2
- package/src/jinaga-server.ts +89 -10
- package/src/postgres/postgres-queue.ts +27 -0
package/dist/jinaga-server.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export declare type JinagaServerConfig = {
|
|
|
6
6
|
pgStoreSchema?: string;
|
|
7
7
|
pgKeystore?: string | Pool;
|
|
8
8
|
pgKeystoreSchema?: string;
|
|
9
|
+
upstreamReplicators?: string[];
|
|
10
|
+
httpTimeoutSeconds?: number;
|
|
9
11
|
model?: Model;
|
|
10
12
|
authorization?: (a: AuthorizationRules) => AuthorizationRules;
|
|
11
13
|
distribution?: (d: DistributionRules) => DistributionRules;
|
package/dist/jinaga-server.js
CHANGED
|
@@ -17,6 +17,7 @@ const authentication_session_1 = require("./authentication/authentication-sessio
|
|
|
17
17
|
const authorization_keystore_1 = require("./authorization/authorization-keystore");
|
|
18
18
|
const router_1 = require("./http/router");
|
|
19
19
|
const postgres_keystore_1 = require("./postgres/postgres-keystore");
|
|
20
|
+
const postgres_queue_1 = require("./postgres/postgres-queue");
|
|
20
21
|
const postgres_store_1 = require("./postgres/postgres-store");
|
|
21
22
|
const localDeviceIdentity = {
|
|
22
23
|
provider: 'jinaga',
|
|
@@ -26,15 +27,18 @@ class JinagaServer {
|
|
|
26
27
|
static create(config) {
|
|
27
28
|
const syncStatusNotifier = new jinaga_1.SyncStatusNotifier();
|
|
28
29
|
const pools = {};
|
|
29
|
-
const
|
|
30
|
+
const pool = makePool(config, pools);
|
|
31
|
+
const schema = validateSchema(config.pgStoreSchema);
|
|
32
|
+
const store = createStore(pool, schema);
|
|
30
33
|
const source = new jinaga_1.ObservableSourceImpl(store);
|
|
31
|
-
const
|
|
34
|
+
const webClient = createWebClient(config, syncStatusNotifier);
|
|
35
|
+
const fork = createFork(webClient, store, pool, schema);
|
|
32
36
|
const keystore = createKeystore(config, pools);
|
|
33
37
|
const authorizationRules = config.authorization ? config.authorization(new jinaga_1.AuthorizationRules(config.model)) : null;
|
|
34
38
|
const distributionRules = config.distribution ? config.distribution(new jinaga_1.DistributionRules([])) : null;
|
|
35
39
|
const feedCache = new jinaga_1.FeedCache();
|
|
36
40
|
const authentication = createAuthentication(store, keystore, authorizationRules);
|
|
37
|
-
const network =
|
|
41
|
+
const network = createNetwork(webClient);
|
|
38
42
|
const purgeConditions = createPurgeConditions(config);
|
|
39
43
|
const factManager = new jinaga_1.FactManager(fork, source, store, network, purgeConditions);
|
|
40
44
|
const authorization = createAuthorization(authorizationRules, distributionRules, factManager, store, keystore);
|
|
@@ -58,16 +62,59 @@ class JinagaServer {
|
|
|
58
62
|
}
|
|
59
63
|
}
|
|
60
64
|
exports.JinagaServer = JinagaServer;
|
|
61
|
-
function
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
function makePool(config, pools) {
|
|
66
|
+
const uri = config.pgStore;
|
|
67
|
+
if (uri) {
|
|
68
|
+
return getPool(uri, pools);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function createStore(pool, schema) {
|
|
75
|
+
if (pool) {
|
|
76
|
+
return new postgres_store_1.PostgresStore(pool, schema);
|
|
66
77
|
}
|
|
67
78
|
else {
|
|
68
79
|
return new jinaga_1.MemoryStore();
|
|
69
80
|
}
|
|
70
81
|
}
|
|
82
|
+
function createWebClient(config, syncStatusNotifier) {
|
|
83
|
+
if (config.upstreamReplicators && config.upstreamReplicators.length > 0) {
|
|
84
|
+
// TODO: Handle multiple upstream replicators
|
|
85
|
+
// TODO: Handle authentication
|
|
86
|
+
const httpEndpoint = config.upstreamReplicators[0];
|
|
87
|
+
const getHeaders = () => Promise.resolve({});
|
|
88
|
+
const reauthenticate = () => Promise.resolve(false);
|
|
89
|
+
const httpConnection = new jinaga_1.FetchConnection(httpEndpoint, getHeaders, reauthenticate);
|
|
90
|
+
const httpTimeoutSeconds = config.httpTimeoutSeconds || 30;
|
|
91
|
+
const webClient = new jinaga_1.WebClient(httpConnection, syncStatusNotifier, {
|
|
92
|
+
timeoutSeconds: httpTimeoutSeconds
|
|
93
|
+
});
|
|
94
|
+
return webClient;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function createFork(webClient, store, pool, schema) {
|
|
101
|
+
if (webClient) {
|
|
102
|
+
if (pool) {
|
|
103
|
+
const queue = new postgres_queue_1.PostgresQueue(pool, schema);
|
|
104
|
+
const fork = new jinaga_1.PersistentFork(store, queue, webClient);
|
|
105
|
+
fork.initialize();
|
|
106
|
+
return fork;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
const fork = new jinaga_1.TransientFork(store, webClient);
|
|
110
|
+
return fork;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
const fork = new jinaga_1.PassThroughFork(store);
|
|
115
|
+
return fork;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
71
118
|
function createKeystore(config, pools) {
|
|
72
119
|
const uriOrPool = config.pgKeystore;
|
|
73
120
|
if (uriOrPool) {
|
|
@@ -179,4 +226,13 @@ function createPurgeConditions(config) {
|
|
|
179
226
|
return [];
|
|
180
227
|
}
|
|
181
228
|
}
|
|
229
|
+
function createNetwork(webClient) {
|
|
230
|
+
if (webClient) {
|
|
231
|
+
const network = new jinaga_1.HttpNetwork(webClient);
|
|
232
|
+
return network;
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
return new jinaga_1.NetworkNoOp();
|
|
236
|
+
}
|
|
237
|
+
}
|
|
182
238
|
//# 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,mCA6BgB;AAChB,2BAA0B;AAE1B,kFAA8E;AAC9E,oFAAgF;AAChF,mFAA+E;AAC/E,0CAAwD;AAExD,oEAAgE;AAChE,8DAA0D;AAC1D,8DAA0D;AAwB1D,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,CAAC;QACpD,MAAM,KAAK,GAA4B,EAAE,CAAC;QAC1C,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QACrC,MAAM,MAAM,GAAG,cAAc,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;QACpD,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACxC,MAAM,MAAM,GAAG,IAAI,6BAAoB,CAAC,KAAK,CAAC,CAAC;QAC/C,MAAM,SAAS,GAAG,eAAe,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;QAC9D,MAAM,IAAI,GAAG,UAAU,CAAC,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QACxD,MAAM,QAAQ,GAAG,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAC/C,MAAM,kBAAkB,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,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,CAAC;KACb;AACL,CAAC;AAED,SAAS,aAAa,CAClB,SAA2B;IAE3B,IAAI,SAAS,EAAE;QACX,MAAM,OAAO,GAAG,IAAI,oBAAW,CAAC,SAAS,CAAC,CAAC;QAC3C,OAAO,OAAO,CAAC;KAClB;SACI;QACD,OAAO,IAAI,oBAAW,EAAE,CAAC;KAC5B;AACL,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FactEnvelope, Queue } from "jinaga";
|
|
2
|
+
import { Pool } from "pg";
|
|
3
|
+
export declare class PostgresQueue implements Queue {
|
|
4
|
+
private schema;
|
|
5
|
+
private connectionFactory;
|
|
6
|
+
constructor(pool: Pool, schema: string);
|
|
7
|
+
peek(): Promise<FactEnvelope[]>;
|
|
8
|
+
enqueue(envelopes: FactEnvelope[]): Promise<void>;
|
|
9
|
+
dequeue(envelopes: FactEnvelope[]): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PostgresQueue = void 0;
|
|
4
|
+
const connection_1 = require("./connection");
|
|
5
|
+
class PostgresQueue {
|
|
6
|
+
constructor(pool, schema) {
|
|
7
|
+
this.schema = schema;
|
|
8
|
+
this.connectionFactory = new connection_1.ConnectionFactory(pool);
|
|
9
|
+
}
|
|
10
|
+
peek() {
|
|
11
|
+
// Not yet implemented
|
|
12
|
+
return Promise.resolve([]);
|
|
13
|
+
}
|
|
14
|
+
enqueue(envelopes) {
|
|
15
|
+
// Not yet implemented
|
|
16
|
+
return Promise.resolve();
|
|
17
|
+
}
|
|
18
|
+
dequeue(envelopes) {
|
|
19
|
+
// Not yet implemented
|
|
20
|
+
return Promise.resolve();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.PostgresQueue = PostgresQueue;
|
|
24
|
+
//# sourceMappingURL=postgres-queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-queue.js","sourceRoot":"","sources":["../../src/postgres/postgres-queue.ts"],"names":[],"mappings":";;;AAEA,6CAAiD;AAEjD,MAAa,aAAa;IAGtB,YAAY,IAAU,EAAU,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;QAC1C,IAAI,CAAC,iBAAiB,GAAG,IAAI,8BAAiB,CAAC,IAAI,CAAC,CAAC;IACzD,CAAC;IAED,IAAI;QACA,sBAAsB;QACtB,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC/B,CAAC;IAED,OAAO,CAAC,SAAyB;QAC7B,sBAAsB;QACtB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;IAED,OAAO,CAAC,SAAyB;QAC7B,sBAAsB;QACtB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;CAEJ;AAtBD,sCAsBC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jinaga-server",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.2",
|
|
4
4
|
"description": "Data management for web and mobile applications.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"express": "^4.21.2",
|
|
51
|
-
"jinaga": "^6.5.
|
|
51
|
+
"jinaga": "^6.5.6",
|
|
52
52
|
"pg": "^8.13.1"
|
|
53
53
|
}
|
|
54
54
|
}
|
package/src/jinaga-server.ts
CHANGED
|
@@ -7,20 +7,27 @@ import {
|
|
|
7
7
|
DistributionRules,
|
|
8
8
|
FactManager,
|
|
9
9
|
FeedCache,
|
|
10
|
+
FetchConnection,
|
|
11
|
+
Fork,
|
|
12
|
+
HttpNetwork,
|
|
10
13
|
Jinaga,
|
|
11
14
|
MemoryStore,
|
|
12
15
|
Model,
|
|
16
|
+
Network,
|
|
13
17
|
NetworkNoOp,
|
|
14
18
|
ObservableSource,
|
|
15
19
|
ObservableSourceImpl,
|
|
16
20
|
PassThroughFork,
|
|
21
|
+
PersistentFork,
|
|
17
22
|
PurgeConditions,
|
|
18
23
|
Specification,
|
|
19
24
|
Storage,
|
|
20
25
|
SyncStatusNotifier,
|
|
21
26
|
Trace,
|
|
27
|
+
TransientFork,
|
|
22
28
|
UserIdentity,
|
|
23
|
-
validatePurgeSpecification
|
|
29
|
+
validatePurgeSpecification,
|
|
30
|
+
WebClient
|
|
24
31
|
} from "jinaga";
|
|
25
32
|
import { Pool } from "pg";
|
|
26
33
|
|
|
@@ -30,6 +37,7 @@ import { AuthorizationKeystore } from "./authorization/authorization-keystore";
|
|
|
30
37
|
import { HttpRouter, RequestUser } from "./http/router";
|
|
31
38
|
import { Keystore } from "./keystore";
|
|
32
39
|
import { PostgresKeystore } from "./postgres/postgres-keystore";
|
|
40
|
+
import { PostgresQueue } from "./postgres/postgres-queue";
|
|
33
41
|
import { PostgresStore } from "./postgres/postgres-store";
|
|
34
42
|
|
|
35
43
|
|
|
@@ -38,6 +46,8 @@ export type JinagaServerConfig = {
|
|
|
38
46
|
pgStoreSchema?: string,
|
|
39
47
|
pgKeystore?: string | Pool,
|
|
40
48
|
pgKeystoreSchema?: string,
|
|
49
|
+
upstreamReplicators?: string[],
|
|
50
|
+
httpTimeoutSeconds?: number,
|
|
41
51
|
model?: Model,
|
|
42
52
|
authorization?: (a: AuthorizationRules) => AuthorizationRules,
|
|
43
53
|
distribution?: (d: DistributionRules) => DistributionRules,
|
|
@@ -61,15 +71,18 @@ export class JinagaServer {
|
|
|
61
71
|
static create(config: JinagaServerConfig): JinagaServerInstance {
|
|
62
72
|
const syncStatusNotifier = new SyncStatusNotifier();
|
|
63
73
|
const pools: { [uri: string]: Pool } = {};
|
|
64
|
-
const
|
|
74
|
+
const pool = makePool(config, pools);
|
|
75
|
+
const schema = validateSchema(config.pgStoreSchema);
|
|
76
|
+
const store = createStore(pool, schema);
|
|
65
77
|
const source = new ObservableSourceImpl(store);
|
|
66
|
-
const
|
|
78
|
+
const webClient = createWebClient(config, syncStatusNotifier);
|
|
79
|
+
const fork = createFork(webClient, store, pool, schema);
|
|
67
80
|
const keystore = createKeystore(config, pools);
|
|
68
81
|
const authorizationRules = config.authorization ? config.authorization(new AuthorizationRules(config.model)) : null;
|
|
69
82
|
const distributionRules = config.distribution ? config.distribution(new DistributionRules([])) : null;
|
|
70
83
|
const feedCache = new FeedCache();
|
|
71
84
|
const authentication = createAuthentication(store, keystore, authorizationRules);
|
|
72
|
-
const network =
|
|
85
|
+
const network = createNetwork(webClient);
|
|
73
86
|
const purgeConditions = createPurgeConditions(config);
|
|
74
87
|
const factManager = new FactManager(fork, source, store, network, purgeConditions);
|
|
75
88
|
const authorization = createAuthorization(authorizationRules, distributionRules, factManager, store, keystore);
|
|
@@ -92,17 +105,71 @@ export class JinagaServer {
|
|
|
92
105
|
}
|
|
93
106
|
}
|
|
94
107
|
|
|
95
|
-
function
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
108
|
+
function makePool(config: JinagaServerConfig, pools: { [uri: string]: Pool }): Pool | undefined {
|
|
109
|
+
const uri = config.pgStore;
|
|
110
|
+
if (uri) {
|
|
111
|
+
return getPool(uri, pools);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function createStore(pool: Pool | undefined, schema: string): Storage {
|
|
119
|
+
if (pool) {
|
|
120
|
+
return new PostgresStore(pool, schema);
|
|
100
121
|
}
|
|
101
122
|
else {
|
|
102
123
|
return new MemoryStore();
|
|
103
124
|
}
|
|
104
125
|
}
|
|
105
126
|
|
|
127
|
+
function createWebClient(
|
|
128
|
+
config: JinagaServerConfig,
|
|
129
|
+
syncStatusNotifier: SyncStatusNotifier
|
|
130
|
+
): WebClient | null {
|
|
131
|
+
if (config.upstreamReplicators && config.upstreamReplicators.length > 0) {
|
|
132
|
+
// TODO: Handle multiple upstream replicators
|
|
133
|
+
// TODO: Handle authentication
|
|
134
|
+
const httpEndpoint = config.upstreamReplicators[0];
|
|
135
|
+
const getHeaders = () => Promise.resolve({});
|
|
136
|
+
const reauthenticate = () => Promise.resolve(false);
|
|
137
|
+
const httpConnection = new FetchConnection(httpEndpoint, getHeaders, reauthenticate);
|
|
138
|
+
const httpTimeoutSeconds = config.httpTimeoutSeconds || 30;
|
|
139
|
+
const webClient = new WebClient(httpConnection, syncStatusNotifier, {
|
|
140
|
+
timeoutSeconds: httpTimeoutSeconds
|
|
141
|
+
});
|
|
142
|
+
return webClient;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function createFork(
|
|
150
|
+
webClient: WebClient | null,
|
|
151
|
+
store: Storage,
|
|
152
|
+
pool: Pool | undefined,
|
|
153
|
+
schema: string
|
|
154
|
+
): Fork {
|
|
155
|
+
if (webClient) {
|
|
156
|
+
if (pool) {
|
|
157
|
+
const queue = new PostgresQueue(pool, schema);
|
|
158
|
+
const fork = new PersistentFork(store, queue, webClient);
|
|
159
|
+
fork.initialize();
|
|
160
|
+
return fork;
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
const fork = new TransientFork(store, webClient);
|
|
164
|
+
return fork;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
const fork = new PassThroughFork(store);
|
|
169
|
+
return fork;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
106
173
|
function createKeystore(config: JinagaServerConfig, pools: { [uri: string]: Pool }): Keystore | null {
|
|
107
174
|
const uriOrPool = config.pgKeystore;
|
|
108
175
|
if (uriOrPool) {
|
|
@@ -226,4 +293,16 @@ function createPurgeConditions(
|
|
|
226
293
|
else {
|
|
227
294
|
return [];
|
|
228
295
|
}
|
|
229
|
-
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function createNetwork(
|
|
299
|
+
webClient: WebClient | null
|
|
300
|
+
): Network {
|
|
301
|
+
if (webClient) {
|
|
302
|
+
const network = new HttpNetwork(webClient);
|
|
303
|
+
return network;
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
return new NetworkNoOp();
|
|
307
|
+
}
|
|
308
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { FactEnvelope, Queue } from "jinaga";
|
|
2
|
+
import { Pool } from "pg";
|
|
3
|
+
import { ConnectionFactory } from "./connection";
|
|
4
|
+
|
|
5
|
+
export class PostgresQueue implements Queue {
|
|
6
|
+
private connectionFactory: ConnectionFactory;
|
|
7
|
+
|
|
8
|
+
constructor(pool: Pool, private schema: string) {
|
|
9
|
+
this.connectionFactory = new ConnectionFactory(pool);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
peek(): Promise<FactEnvelope[]> {
|
|
13
|
+
// Not yet implemented
|
|
14
|
+
return Promise.resolve([]);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
enqueue(envelopes: FactEnvelope[]): Promise<void> {
|
|
18
|
+
// Not yet implemented
|
|
19
|
+
return Promise.resolve();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
dequeue(envelopes: FactEnvelope[]): Promise<void> {
|
|
23
|
+
// Not yet implemented
|
|
24
|
+
return Promise.resolve();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
}
|