jinaga-server 2.3.1 → 2.3.3
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/authentication/authentication-device.d.ts +2 -1
- package/dist/authentication/authentication-device.js +12 -3
- package/dist/authentication/authentication-device.js.map +1 -1
- package/dist/http/router.js +13 -1
- package/dist/http/router.js.map +1 -1
- package/dist/postgres/postgres-store.d.ts +2 -2
- package/dist/postgres/postgres-store.js +19 -4
- package/dist/postgres/postgres-store.js.map +1 -1
- package/dist/postgres/specification-result-sql.d.ts +23 -4
- package/dist/postgres/specification-result-sql.js +103 -32
- package/dist/postgres/specification-result-sql.js.map +1 -1
- package/dist/postgres/specification-sql.js +1 -5
- package/dist/postgres/specification-sql.js.map +1 -1
- package/docs/sql/SQL Generation.ipynb +2427 -0
- package/package.json +2 -2
- package/src/authentication/authentication-device.ts +11 -3
- package/src/http/router.ts +18 -1
- package/src/postgres/postgres-store.ts +28 -6
- package/src/postgres/specification-result-sql.ts +149 -37
- package/src/postgres/specification-sql.ts +1 -10
- package/test/postgres/postgresReadSpec.ts +63 -3
- package/docs/registrations.sql +0 -22
- package/docs/sql/example.sql +0 -49
- package/docs/sql-generator.gv +0 -25
|
@@ -74,7 +74,9 @@ describe("Postgres read", () => {
|
|
|
74
74
|
|
|
75
75
|
const sql = composer.getSqlQueries().sqlQuery.sql;
|
|
76
76
|
expect(sql).toEqual(
|
|
77
|
-
`SELECT
|
|
77
|
+
`SELECT ` +
|
|
78
|
+
`f1.hash as hash1, f1.fact_id as id1, f1.data as data1, ` +
|
|
79
|
+
`f2.hash as hash2, f2.fact_id as id2, f2.data as data2 ` +
|
|
78
80
|
`FROM public.fact f1 ` +
|
|
79
81
|
`JOIN public.edge e1 ` +
|
|
80
82
|
`ON e1.predecessor_fact_id = f1.fact_id ` +
|
|
@@ -103,7 +105,9 @@ describe("Postgres read", () => {
|
|
|
103
105
|
const tree = composer.getSqlQueries();
|
|
104
106
|
const sql = tree.sqlQuery.sql;
|
|
105
107
|
expect(sql).toEqual(
|
|
106
|
-
`SELECT
|
|
108
|
+
`SELECT ` +
|
|
109
|
+
`f1.hash as hash1, f1.fact_id as id1, f1.data as data1, ` +
|
|
110
|
+
`f3.hash as hash3, f3.fact_id as id3, f3.data as data3 ` +
|
|
107
111
|
`FROM public.fact f1 ` +
|
|
108
112
|
`JOIN public.edge e1 ` +
|
|
109
113
|
`ON e1.predecessor_fact_id = f1.fact_id ` +
|
|
@@ -152,7 +156,9 @@ describe("Postgres read", () => {
|
|
|
152
156
|
const tree = composer.getSqlQueries();
|
|
153
157
|
const sql = tree.sqlQuery.sql;
|
|
154
158
|
expect(sql).toEqual(
|
|
155
|
-
`SELECT
|
|
159
|
+
`SELECT ` +
|
|
160
|
+
`f1.hash as hash1, f1.fact_id as id1, f1.data as data1, ` +
|
|
161
|
+
`f3.hash as hash3, f3.fact_id as id3, f3.data as data3 ` +
|
|
156
162
|
`FROM public.fact f1 ` +
|
|
157
163
|
`JOIN public.edge e1 ` +
|
|
158
164
|
`ON e1.predecessor_fact_id = f1.fact_id ` +
|
|
@@ -184,6 +190,59 @@ describe("Postgres read", () => {
|
|
|
184
190
|
]);
|
|
185
191
|
});
|
|
186
192
|
|
|
193
|
+
it("should read nested existential conditions", () => {
|
|
194
|
+
const { composer, factTypes, roleMap } = sqlFor(`
|
|
195
|
+
(company: Company) {
|
|
196
|
+
project: Project [
|
|
197
|
+
project->company: Company = company
|
|
198
|
+
!E {
|
|
199
|
+
deleted: Project.Deleted [
|
|
200
|
+
deleted->project: Project = project
|
|
201
|
+
!E {
|
|
202
|
+
restored: Project.Restored [
|
|
203
|
+
restored->deleted: Project.Deleted = deleted
|
|
204
|
+
]
|
|
205
|
+
}
|
|
206
|
+
]
|
|
207
|
+
}
|
|
208
|
+
]
|
|
209
|
+
} => project
|
|
210
|
+
`);
|
|
211
|
+
|
|
212
|
+
const tree = composer.getSqlQueries();
|
|
213
|
+
const sql = tree.sqlQuery.sql;
|
|
214
|
+
expect(sql).toEqual(
|
|
215
|
+
`SELECT ` +
|
|
216
|
+
`f1.hash as hash1, f1.fact_id as id1, f1.data as data1, ` +
|
|
217
|
+
`f2.hash as hash2, f2.fact_id as id2, f2.data as data2 ` +
|
|
218
|
+
`FROM public.fact f1 ` +
|
|
219
|
+
`JOIN public.edge e1 ` +
|
|
220
|
+
`ON e1.predecessor_fact_id = f1.fact_id ` +
|
|
221
|
+
`AND e1.role_id = $3 ` +
|
|
222
|
+
`JOIN public.fact f2 ` +
|
|
223
|
+
`ON f2.fact_id = e1.successor_fact_id ` +
|
|
224
|
+
`WHERE f1.fact_type_id = $1 AND f1.hash = $2 ` +
|
|
225
|
+
`AND NOT EXISTS (` +
|
|
226
|
+
`SELECT 1 ` +
|
|
227
|
+
`FROM public.edge e2 ` +
|
|
228
|
+
`JOIN public.fact f3 ` +
|
|
229
|
+
`ON f3.fact_id = e2.successor_fact_id ` +
|
|
230
|
+
`WHERE e2.predecessor_fact_id = f2.fact_id ` +
|
|
231
|
+
`AND e2.role_id = $4 ` +
|
|
232
|
+
`AND NOT EXISTS (` +
|
|
233
|
+
`SELECT 1 ` +
|
|
234
|
+
`FROM public.edge e3 ` +
|
|
235
|
+
`JOIN public.fact f4 ` +
|
|
236
|
+
`ON f4.fact_id = e3.successor_fact_id ` +
|
|
237
|
+
`WHERE e3.predecessor_fact_id = f3.fact_id ` +
|
|
238
|
+
`AND e3.role_id = $5` +
|
|
239
|
+
`)` +
|
|
240
|
+
`) ` +
|
|
241
|
+
`ORDER BY f2.fact_id ASC`
|
|
242
|
+
);
|
|
243
|
+
expect(tree.sqlQuery.parameters).toEqual
|
|
244
|
+
});
|
|
245
|
+
|
|
187
246
|
it("should read complex specifications", () => {
|
|
188
247
|
const { composer, factTypes, roleMap } = sqlFor(`
|
|
189
248
|
(company: Company, user: Jinaga.User) {
|
|
@@ -234,6 +293,7 @@ describe("Postgres read", () => {
|
|
|
234
293
|
const queries = composer.getSqlQueries();
|
|
235
294
|
expect(queries.sqlQuery.sql).toEqual(
|
|
236
295
|
`SELECT ` +
|
|
296
|
+
`f1.hash as hash1, f1.fact_id as id1, f1.data as data1, ` +
|
|
237
297
|
`f3.hash as hash3, f3.fact_id as id3, f3.data as data3, ` +
|
|
238
298
|
`f9.hash as hash9, f9.fact_id as id9, f9.data as data9 ` +
|
|
239
299
|
`FROM public.fact f1 ` +
|
package/docs/registrations.sql
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
SELECT F3.HASH AS HASH3,
|
|
2
|
-
F4.HASH AS HASH4,
|
|
3
|
-
F6.HASH AS HASH6,
|
|
4
|
-
sort(array[F3.FACT_ID, F4.FACT_ID, F6.FACT_ID], 'desc') as bookmark
|
|
5
|
-
FROM PUBLIC.FACT F1
|
|
6
|
-
JOIN PUBLIC.EDGE E1 ON E1.PREDECESSOR_FACT_ID = F1.FACT_ID
|
|
7
|
-
AND E1.ROLE_ID = 44
|
|
8
|
-
JOIN PUBLIC.FACT F3 ON F3.FACT_ID = E1.SUCCESSOR_FACT_ID
|
|
9
|
-
JOIN PUBLIC.EDGE E2 ON E2.PREDECESSOR_FACT_ID = F3.FACT_ID
|
|
10
|
-
AND e2.ROLE_ID = 46
|
|
11
|
-
JOIN PUBLIC.FACT F4 ON F4.FACT_ID = E2.SUCCESSOR_FACT_ID
|
|
12
|
-
JOIN PUBLIC.EDGE E4 ON E4.PREDECESSOR_FACT_ID = F4.FACT_ID
|
|
13
|
-
AND E4.ROLE_ID = 18
|
|
14
|
-
JOIN PUBLIC.FACT F6 ON F6.FACT_ID = E4.SUCCESSOR_FACT_ID
|
|
15
|
-
JOIN PUBLIC.EDGE E5 ON E5.SUCCESSOR_FACT_ID = F6.FACT_ID
|
|
16
|
-
AND E5.ROLE_ID = 23
|
|
17
|
-
JOIN PUBLIC.FACT F2 ON F2.FACT_ID = E5.PREDECESSOR_FACT_ID
|
|
18
|
-
WHERE F1.FACT_TYPE_ID = 35
|
|
19
|
-
AND F1.HASH = '5kIRDvVO/wP4v7G9vhDAPMVi2q0cXsZtp9YuyAjan7yyDUhFFPiwwNnzTor6jFdkC11CYnDmoZueMAqxF9MPTQ=='
|
|
20
|
-
AND F2.FACT_TYPE_ID = 24
|
|
21
|
-
AND F2.HASH = '0WWlFbZH+gMoP3QGXO7/mf6hIQC/2iN7wd0peEQKFVvnJMp3gTVvi4eXfVd3DSa81MSzAVp7zVxXIiRnJTF0Kw=='
|
|
22
|
-
ORDER BY bookmark ASC
|
package/docs/sql/example.sql
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
SELECT f4.hash AS hash4, f4.fact_id AS id4, f4.data AS data4
|
|
2
|
-
, f7.hash AS hash7, f7.fact_id AS id7, f7.data AS data7
|
|
3
|
-
, f9.hash AS hash9, f9.fact_id AS id9, f9.data AS data9
|
|
4
|
-
FROM public.fact f1
|
|
5
|
-
JOIN public.edge e1
|
|
6
|
-
ON e1.predecessor_fact_id = f1.fact_id
|
|
7
|
-
AND e1.role_id = $3
|
|
8
|
-
JOIN public.fact f3
|
|
9
|
-
ON f3.fact_id = e1.successor_fact_id
|
|
10
|
-
JOIN public.edge e2
|
|
11
|
-
ON e2.predecessor_fact_id = f3.fact_id
|
|
12
|
-
AND e2.role_id = $4
|
|
13
|
-
JOIN public.fact f4
|
|
14
|
-
ON f4.fact_id = e2.successor_fact_id
|
|
15
|
-
JOIN public.edge e5
|
|
16
|
-
ON e5.predecessor_fact_id = f4.fact_id
|
|
17
|
-
AND e5.role_id = $7
|
|
18
|
-
JOIN public.fact f7
|
|
19
|
-
ON f7.fact_id = e5.successor_fact_id
|
|
20
|
-
JOIN public.edge e6
|
|
21
|
-
ON e6.successor_fact_id = f7.fact_id
|
|
22
|
-
AND e6.role_id = $10
|
|
23
|
-
JOIN public.fact f2
|
|
24
|
-
ON f2.fact_id = e6.predecessor_fact_id
|
|
25
|
-
JOIN public.edge e8
|
|
26
|
-
ON e8.predecessor_fact_id = f4.fact_id
|
|
27
|
-
AND e8.role_id = $12
|
|
28
|
-
JOIN public.fact f9
|
|
29
|
-
ON f9.fact_id = e8.successor_fact_id
|
|
30
|
-
WHERE 1=1
|
|
31
|
-
AND f1.fact_type_id = $1
|
|
32
|
-
AND f1.hash = $2
|
|
33
|
-
AND f2.fact_type_id = $8
|
|
34
|
-
AND f2.hash = $9
|
|
35
|
-
AND NOT EXISTS (SELECT 1
|
|
36
|
-
FROM public.edge e3
|
|
37
|
-
JOIN public.fact f5
|
|
38
|
-
ON f5.fact_id = e3.successor_fact_id
|
|
39
|
-
WHERE 1=1
|
|
40
|
-
AND e3.predecessor_fact_id = f4.fact_id
|
|
41
|
-
AND e3.role_id = $5)
|
|
42
|
-
AND NOT EXISTS (SELECT 1
|
|
43
|
-
FROM public.edge e7
|
|
44
|
-
JOIN public.fact f8
|
|
45
|
-
ON f8.fact_id = e7.successor_fact_id
|
|
46
|
-
WHERE 1=1
|
|
47
|
-
AND e7.predecessor_fact_id = f7.fact_id
|
|
48
|
-
AND e7.role_id = $11)
|
|
49
|
-
ORDER BY f4.fact_id ASC, f7.fact_id ASC, f9.fact_id ASC
|
package/docs/sql-generator.gv
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
digraph {
|
|
2
|
-
subgraph cluster_states {
|
|
3
|
-
color=transparent
|
|
4
|
-
PredecessorType -> PredecessorJoin [label="Predecessor\nemit edge"]
|
|
5
|
-
PredecessorJoin -> PredecessorType [label="Type"]
|
|
6
|
-
PredecessorType -> SuccessorJoin [label="Successor" constraint=false]
|
|
7
|
-
|
|
8
|
-
SuccessorType -> SuccessorJoin [label="Successor"]
|
|
9
|
-
SuccessorJoin -> SuccessorType [label="Type\nemit edge"]
|
|
10
|
-
SuccessorType -> PredecessorJoin [label="Predecessor\nemit fact\nemit edge" constraint=false]
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
subgraph cluster_terminal {
|
|
14
|
-
color=transparent
|
|
15
|
-
success
|
|
16
|
-
error
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
SuccessorJoin -> error [label="end"]
|
|
20
|
-
SuccessorType -> success [label="end\nemit fact"]
|
|
21
|
-
PredecessorType -> success [label="end\nemit fact"]
|
|
22
|
-
PredecessorJoin -> success [label="end\nemit fact"]
|
|
23
|
-
|
|
24
|
-
// {rank=same; SuccessorType; success }
|
|
25
|
-
}
|