prostgles-server 4.2.9 → 4.2.12
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/package.json +1 -1
- package/tests/client/index.ts +8 -8
- package/tests/client/package-lock.json +23 -7
- package/tests/client/package.json +2 -2
- package/tests/clientFileTests.spec.ts +103 -0
- package/tests/clientOnlyQueries.spec.ts +609 -0
- package/tests/clientRestApi.spec.ts +81 -0
- package/tests/isomorphicQueries.spec.ts +1199 -0
- package/tests/server/index.ts +20 -17
- package/tests/server/package-lock.json +1 -1
- package/tests/server/package.json +2 -2
- package/tests/serverOnlyQueries.spec.ts +31 -0
- package/tests/client_files.ts +0 -98
- package/tests/client_only_queries.ts +0 -581
- package/tests/client_rest_api.ts +0 -79
- package/tests/isomorphic_queries.ts +0 -1194
- package/tests/server_only_queries.ts +0 -26
package/package.json
CHANGED
package/tests/client/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import prostgles from "prostgles-client";
|
|
2
2
|
import io from "socket.io-client";
|
|
3
3
|
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
4
|
+
import { isomorphicQueries } from "../isomorphicQueries.spec";
|
|
5
|
+
import { clientOnlyQueries } from "../clientOnlyQueries.spec";
|
|
6
|
+
import { clientRestApi } from "../clientRestApi.spec";
|
|
7
|
+
import { clientFileTests } from "../clientFileTests.spec";
|
|
8
8
|
import { InitOptions } from "prostgles-client/dist/prostgles";
|
|
9
9
|
export { DBHandlerClient, Auth } from "prostgles-client/dist/prostgles";
|
|
10
10
|
|
|
@@ -24,19 +24,19 @@ type ClientTestSpec = {
|
|
|
24
24
|
const tests: Record<string, ClientTestSpec> = {
|
|
25
25
|
main: {
|
|
26
26
|
onRun: async (db, methods, tableSchema, auth) => {
|
|
27
|
-
await
|
|
28
|
-
await
|
|
27
|
+
await isomorphicQueries(db, log);
|
|
28
|
+
await clientOnlyQueries(db, auth, log, methods, tableSchema, TEST_NAME);
|
|
29
29
|
},
|
|
30
30
|
},
|
|
31
31
|
files: {
|
|
32
32
|
onRun: async (db, methods, tableSchema, auth) => {
|
|
33
|
-
await
|
|
33
|
+
await clientFileTests(db, auth, log, methods, tableSchema)
|
|
34
34
|
},
|
|
35
35
|
|
|
36
36
|
},
|
|
37
37
|
rest_api: {
|
|
38
38
|
onRun: async (db, methods, tableSchema, auth) => {
|
|
39
|
-
await
|
|
39
|
+
await clientRestApi(db, auth, log, methods, tableSchema, TEST_NAME);
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
42
|
};
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"version": "1.0.0",
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@types/node": "^
|
|
12
|
+
"@types/node": "^20.9.2",
|
|
13
13
|
"prostgles-client": "^4.0.69",
|
|
14
14
|
"prostgles-types": "^4.0.51",
|
|
15
15
|
"socket.io-client": "^4.7.1"
|
|
@@ -24,9 +24,12 @@
|
|
|
24
24
|
"integrity": "sha512-+9jVqKhRSpsc591z5vX+X5Yyw+he/HCB4iQ/RYxw35CEPaY1gnsNE43nf9n9AaYjAQrTiI/mOwKUKdUs9vf7Xg=="
|
|
25
25
|
},
|
|
26
26
|
"node_modules/@types/node": {
|
|
27
|
-
"version": "
|
|
28
|
-
"resolved": "https://registry.npmjs.org/@types/node/-/node-
|
|
29
|
-
"integrity": "sha512-
|
|
27
|
+
"version": "20.11.5",
|
|
28
|
+
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.5.tgz",
|
|
29
|
+
"integrity": "sha512-g557vgQjUUfN76MZAN/dt1z3dzcUsimuysco0KeluHgrPdJXkP/XdAURgyO2W9fZWHRtRBiVKzKn8vyOAwlG+w==",
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"undici-types": "~5.26.4"
|
|
32
|
+
}
|
|
30
33
|
},
|
|
31
34
|
"node_modules/debug": {
|
|
32
35
|
"version": "4.3.4",
|
|
@@ -137,6 +140,11 @@
|
|
|
137
140
|
"node": ">=14.17"
|
|
138
141
|
}
|
|
139
142
|
},
|
|
143
|
+
"node_modules/undici-types": {
|
|
144
|
+
"version": "5.26.5",
|
|
145
|
+
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
|
|
146
|
+
"integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA=="
|
|
147
|
+
},
|
|
140
148
|
"node_modules/ws": {
|
|
141
149
|
"version": "8.11.0",
|
|
142
150
|
"resolved": "https://registry.npmjs.org/ws/-/ws-8.11.0.tgz",
|
|
@@ -173,9 +181,12 @@
|
|
|
173
181
|
"integrity": "sha512-+9jVqKhRSpsc591z5vX+X5Yyw+he/HCB4iQ/RYxw35CEPaY1gnsNE43nf9n9AaYjAQrTiI/mOwKUKdUs9vf7Xg=="
|
|
174
182
|
},
|
|
175
183
|
"@types/node": {
|
|
176
|
-
"version": "
|
|
177
|
-
"resolved": "https://registry.npmjs.org/@types/node/-/node-
|
|
178
|
-
"integrity": "sha512-
|
|
184
|
+
"version": "20.11.5",
|
|
185
|
+
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.5.tgz",
|
|
186
|
+
"integrity": "sha512-g557vgQjUUfN76MZAN/dt1z3dzcUsimuysco0KeluHgrPdJXkP/XdAURgyO2W9fZWHRtRBiVKzKn8vyOAwlG+w==",
|
|
187
|
+
"requires": {
|
|
188
|
+
"undici-types": "~5.26.4"
|
|
189
|
+
}
|
|
179
190
|
},
|
|
180
191
|
"debug": {
|
|
181
192
|
"version": "4.3.4",
|
|
@@ -254,6 +265,11 @@
|
|
|
254
265
|
"integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==",
|
|
255
266
|
"dev": true
|
|
256
267
|
},
|
|
268
|
+
"undici-types": {
|
|
269
|
+
"version": "5.26.5",
|
|
270
|
+
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
|
|
271
|
+
"integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA=="
|
|
272
|
+
},
|
|
257
273
|
"ws": {
|
|
258
274
|
"version": "8.11.0",
|
|
259
275
|
"resolved": "https://registry.npmjs.org/ws/-/ws-8.11.0.tgz",
|
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
"start": "tsc-watch --onSuccess \"node dist/client/index.js\"",
|
|
8
8
|
"dev": "NOSTOP=true npm start",
|
|
9
9
|
"build": "rm -rf ./node_modules/* && rm -rf ./dist/* && npm i && tsc",
|
|
10
|
-
"test": "node
|
|
10
|
+
"test": "node --test --experimental-test-coverage dist/client/index.js"
|
|
11
11
|
},
|
|
12
12
|
"author": "",
|
|
13
13
|
"license": "ISC",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@types/node": "^
|
|
15
|
+
"@types/node": "^20.9.2",
|
|
16
16
|
"prostgles-client": "^4.0.69",
|
|
17
17
|
"prostgles-types": "^4.0.51",
|
|
18
18
|
"socket.io-client": "^4.7.1"
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
|
|
2
|
+
import { DBSchemaTable } from "prostgles-types";
|
|
3
|
+
import type { Auth, DBHandlerClient } from "./client/index";
|
|
4
|
+
import { tryRun } from './isomorphicQueries.spec';
|
|
5
|
+
import { strict as assert } from 'assert';
|
|
6
|
+
import fs from "fs";
|
|
7
|
+
import { describe, test } from "node:test";
|
|
8
|
+
|
|
9
|
+
export const clientFileTests = async (db: DBHandlerClient, auth: Auth, log: (...args: any[]) => any, methods, tableSchema: DBSchemaTable[]) => {
|
|
10
|
+
|
|
11
|
+
await describe("clientFileTests", async () => {
|
|
12
|
+
|
|
13
|
+
const fileFolder = `${__dirname}/../../server/dist/server/media/`;
|
|
14
|
+
const getFiles = () => db.sql("SELECT id, original_name FROM files", { }, { returnType: "rows" })
|
|
15
|
+
await db.sql(`
|
|
16
|
+
ALTER TABLE users_public_info
|
|
17
|
+
DROP CONSTRAINT "users_public_info_avatar_fkey";
|
|
18
|
+
|
|
19
|
+
ALTER TABLE "users_public_info"
|
|
20
|
+
ADD FOREIGN KEY ("avatar")
|
|
21
|
+
REFERENCES "files" ("id")
|
|
22
|
+
ON DELETE SET NULL
|
|
23
|
+
`, { })
|
|
24
|
+
const initialFiles = await getFiles();
|
|
25
|
+
|
|
26
|
+
await test("Files table is present", async () => {
|
|
27
|
+
const files = await db.files.find!();
|
|
28
|
+
assert.deepStrictEqual(files, []);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
const file = {
|
|
33
|
+
data: Buffer.from("This is a string", "utf-8"),
|
|
34
|
+
name: "sample_file.txt"
|
|
35
|
+
};
|
|
36
|
+
let insertedFile;
|
|
37
|
+
await test("Insert file from nested insert", async () => {
|
|
38
|
+
const nestedInsert = await db.users_public_info.insert!({ name: "somename.txt", avatar: file }, { returning: "*" });
|
|
39
|
+
const files = await db.files.find!();
|
|
40
|
+
assert.equal(files.length, 1);
|
|
41
|
+
assert.equal(files[0].id, nestedInsert.avatar.id);
|
|
42
|
+
assert.equal(files[0].original_name, file.name);
|
|
43
|
+
const initialFileStr = fs.readFileSync(fileFolder + files[0].name).toString('utf8');
|
|
44
|
+
assert.equal(file.data.toString(), initialFileStr);
|
|
45
|
+
insertedFile = files[0]
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
await test("Cannot Insert file directly", async () => {
|
|
49
|
+
try {
|
|
50
|
+
await db.files.insert!(file, { returning: "*" });
|
|
51
|
+
throw "Should not be able to insert files directly"
|
|
52
|
+
} catch (err){
|
|
53
|
+
assert.equal(err.message.startsWith("Direct inserts not allowed"), true);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
await test("Can update allowed files directly", async () => {
|
|
58
|
+
const newData = {
|
|
59
|
+
data: Buffer.from("aa", "utf-8"),
|
|
60
|
+
name: "a.txt"
|
|
61
|
+
}
|
|
62
|
+
await db.files.update!({ id: insertedFile.id }, newData);
|
|
63
|
+
const newFiles = await db.files.find!();
|
|
64
|
+
assert.equal(newFiles.length, 1);
|
|
65
|
+
const [newFile] = newFiles;
|
|
66
|
+
assert.equal(newFile?.original_name, newData.name);
|
|
67
|
+
assert.equal(newFile.id, insertedFile.id);
|
|
68
|
+
assert.equal(
|
|
69
|
+
fs.readFileSync(fileFolder + newFile.name).toString('utf8').toString(),
|
|
70
|
+
newData.data.toString()
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
await test("Can insert allowed files through a nested update", async () => {
|
|
75
|
+
|
|
76
|
+
await db.files.delete!();
|
|
77
|
+
const user = await db.users_public_info.findOne!();
|
|
78
|
+
const newData = {
|
|
79
|
+
data: Buffer.from("nestedupdate", "utf-8"),
|
|
80
|
+
name: "nestedupdate.txt"
|
|
81
|
+
}
|
|
82
|
+
const d = await db.users_public_info.update!({ id: user?.id }, { avatar: newData }, { returning: "*" });
|
|
83
|
+
const avatarFile = await db.files.findOne!({ id: d?.at(0).avatar.id });
|
|
84
|
+
const initialFileStr = fs.readFileSync(fileFolder + avatarFile!.name).toString('utf8');
|
|
85
|
+
assert.equal(newData.data.toString(), initialFileStr);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
await test("Can delete only allowed files directly", async () => {
|
|
89
|
+
const users = await db.users_public_info.find!();
|
|
90
|
+
for await(const user of users){
|
|
91
|
+
await db.files.delete!({ id: user.avatar.id });
|
|
92
|
+
await db.users_public_info.delete!({ id: user.id });
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
await db.users_public_info.delete!();
|
|
96
|
+
const files = await db.files.find!();
|
|
97
|
+
assert.deepStrictEqual(files, []);
|
|
98
|
+
const latestFiles = await getFiles()
|
|
99
|
+
assert.equal(initialFiles.length, latestFiles.length);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
});
|
|
103
|
+
}
|