jinaga-server 3.1.0 → 3.1.1

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 (37) hide show
  1. package/dist/http/line-reader.d.ts +2 -0
  2. package/dist/http/line-reader.js +68 -0
  3. package/dist/http/line-reader.js.map +1 -0
  4. package/dist/http/router.d.ts +4 -1
  5. package/dist/http/router.js +119 -15
  6. package/dist/http/router.js.map +1 -1
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.js +3 -1
  9. package/dist/index.js.map +1 -1
  10. package/dist/jinaga-server.d.ts +1 -0
  11. package/dist/jinaga-server.js +1 -1
  12. package/dist/jinaga-server.js.map +1 -1
  13. package/http/sans-auth/Feeds options.http +1 -0
  14. package/http/sans-auth/Save graph.http +6 -0
  15. package/http/sans-auth/Save json.http +13 -0
  16. package/http/with-auth/Create post with auth.http +24 -0
  17. package/http/with-auth/Define authorization rules.http +25 -0
  18. package/http/with-auth/Define distribution rules.http +30 -0
  19. package/http/with-auth/Feed sites.http +3 -0
  20. package/http/with-auth/Feeds options.http +1 -0
  21. package/http/with-auth/Feeds sites.http +32 -0
  22. package/http/with-auth/Get posts with auth.http +32 -0
  23. package/http/with-auth/Load titles.http +21 -0
  24. package/integration-test/jinaga-test/Dockerfile +1 -1
  25. package/package.json +2 -2
  26. package/replicator/index.ts +0 -2
  27. package/replicator/package-lock.json +12 -43
  28. package/replicator/package.json +1 -3
  29. package/src/http/line-reader.ts +69 -0
  30. package/src/http/router.ts +147 -19
  31. package/src/index.ts +1 -0
  32. package/src/jinaga-server.ts +2 -1
  33. package/dist/http/serializer.d.ts +0 -11
  34. package/dist/http/serializer.js +0 -68
  35. package/dist/http/serializer.js.map +0 -1
  36. package/src/http/serializer.ts +0 -81
  37. package/test/http/serializerSpec.ts +0 -140
@@ -1,81 +0,0 @@
1
- import { FactEnvelope, FactReference, PredecessorCollection } from "jinaga";
2
-
3
- type IndexPredecessorCollection = {
4
- [role: string]: number | number[];
5
- };
6
-
7
- export class GraphSerializer
8
- {
9
- private index = 0;
10
- private indexByFactReference: { [key: string]: number } = {};
11
- private publicKeys: string[] = [];
12
-
13
- constructor(
14
- private readonly write: (chunk: string) => void
15
- ) {}
16
-
17
- serialize(result: FactEnvelope[]) {
18
- // Write the facts
19
- for (const fact of result) {
20
- // Skip facts that have already been written
21
- const key = fact.fact.type + ":" + fact.fact.hash;
22
- if (this.indexByFactReference.hasOwnProperty(key)) {
23
- continue;
24
- }
25
-
26
- // Write any new public keys
27
- for (const signature of fact.signatures) {
28
- if (!this.publicKeys.includes(signature.publicKey)) {
29
- const pkIndex = this.publicKeys.length;
30
- const publicKey = JSON.stringify(signature.publicKey);
31
- this.write(`PK${pkIndex.toString()}\n${publicKey}\n\n`);
32
- this.publicKeys.push(signature.publicKey);
33
- }
34
- }
35
-
36
- // Write the fact
37
- const factType = JSON.stringify(fact.fact.type);
38
- const predecessorIndexes = JSON.stringify(this.getPredecessorIndexes(fact.fact.predecessors));
39
- const factFields = JSON.stringify(fact.fact.fields);
40
-
41
- let output = `${factType}\n${predecessorIndexes}\n${factFields}`;
42
-
43
- // Write the signatures
44
- for (const signature of fact.signatures) {
45
- const publicKeyIndex = this.publicKeys.indexOf(signature.publicKey);
46
- const publicKey = `PK${publicKeyIndex.toString()}`;
47
- const signatureString = JSON.stringify(signature.signature);
48
-
49
- output += `\n${publicKey}\n${signatureString}`;
50
- }
51
-
52
- output += "\n\n";
53
-
54
- this.write(output);
55
-
56
- this.indexByFactReference[key] = this.index;
57
- this.index++;
58
- }
59
- }
60
-
61
- private getPredecessorIndexes(predecessors: PredecessorCollection): IndexPredecessorCollection {
62
- const result: IndexPredecessorCollection = {};
63
- for (const role in predecessors) {
64
- const reference = predecessors[role];
65
- if (Array.isArray(reference)) {
66
- result[role] = reference.map(r => this.getFactIndex(r));
67
- } else {
68
- result[role] = this.getFactIndex(reference);
69
- }
70
- }
71
- return result;
72
- }
73
-
74
- private getFactIndex(reference: FactReference): number {
75
- const key = reference.type + ":" + reference.hash;
76
- if (!this.indexByFactReference.hasOwnProperty(key)) {
77
- throw new Error(`Fact reference not found in graph: ${key}`);
78
- }
79
- return this.indexByFactReference[key];
80
- }
81
- }
@@ -1,140 +0,0 @@
1
- import { GraphSerializer } from "../../src/http/serializer";
2
-
3
- describe("GraphSerializer", () => {
4
- it("should write an empty graph", () => {
5
- let output = "";
6
- const serializer = new GraphSerializer(chunk => {
7
- output += chunk;
8
- });
9
-
10
- serializer.serialize([]);
11
-
12
- expect(output).toBe("");
13
- });
14
-
15
- it("should write a graph with one fact without signatures", () => {
16
- let output = "";
17
- const serializer = new GraphSerializer(chunk => {
18
- output += chunk;
19
- });
20
-
21
- serializer.serialize([{
22
- fact: {
23
- type: "MyApp.Root",
24
- hash: "roothash",
25
- fields: {
26
- identifier: "root"
27
- },
28
- predecessors: {}
29
- },
30
- signatures: []
31
- }]);
32
-
33
- expect(output).toBe("\"MyApp.Root\"\n{}\n{\"identifier\":\"root\"}\n\n");
34
- });
35
-
36
- it("should write a graph with two facts without signatures", () => {
37
- let output = "";
38
- const serializer = new GraphSerializer(chunk => {
39
- output += chunk;
40
- });
41
-
42
- serializer.serialize([{
43
- fact: {
44
- type: "MyApp.Root",
45
- hash: "roothash",
46
- fields: {},
47
- predecessors: {}
48
- },
49
- signatures: []
50
- }, {
51
- fact: {
52
- type: "MyApp.Child",
53
- hash: "childhash",
54
- fields: {},
55
- predecessors: {
56
- root: {
57
- type: "MyApp.Root",
58
- hash: "roothash"
59
- }
60
- }
61
- },
62
- signatures: []
63
- }]);
64
-
65
- expect(output).toBe("\"MyApp.Root\"\n{}\n{}\n\n\"MyApp.Child\"\n{\"root\":0}\n{}\n\n");
66
- });
67
-
68
- it("should not repeat a fact", () => {
69
- let output = "";
70
- const serializer = new GraphSerializer(chunk => {
71
- output += chunk;
72
- });
73
-
74
- serializer.serialize([{
75
- fact: {
76
- type: "MyApp.Root",
77
- hash: "roothash",
78
- fields: {},
79
- predecessors: {}
80
- },
81
- signatures: []
82
- }, {
83
- fact: {
84
- type: "MyApp.Root",
85
- hash: "roothash",
86
- fields: {},
87
- predecessors: {}
88
- },
89
- signatures: []
90
- }]);
91
-
92
- expect(output).toBe("\"MyApp.Root\"\n{}\n{}\n\n");
93
- });
94
-
95
- it("should write a graph with two facts with signatures", () => {
96
- let output = "";
97
- const serializer = new GraphSerializer(chunk => {
98
- output += chunk;
99
- });
100
-
101
- serializer.serialize([{
102
- fact: {
103
- type: "MyApp.Root",
104
- hash: "roothash",
105
- fields: {},
106
- predecessors: {}
107
- },
108
- signatures: [{
109
- publicKey: "public",
110
- signature: "signature"
111
- }]
112
- }, {
113
- fact: {
114
- type: "MyApp.Child",
115
- hash: "childhash",
116
- fields: {},
117
- predecessors: {
118
- root: {
119
- type: "MyApp.Root",
120
- hash: "roothash"
121
- }
122
- }
123
- },
124
- signatures: [{
125
- publicKey: "public",
126
- signature: "signature1"
127
- }, {
128
- publicKey: "public2",
129
- signature: "signature2"
130
- }]
131
- }]);
132
-
133
- expect(output).toBe(
134
- "PK0\n\"public\"\n\n" +
135
- "\"MyApp.Root\"\n{}\n{}\nPK0\n\"signature\"\n\n" +
136
- "PK1\n\"public2\"\n\n" +
137
- "\"MyApp.Child\"\n{\"root\":0}\n{}\nPK0\n\"signature1\"\nPK1\n\"signature2\"\n\n"
138
- );
139
- });
140
- });