prostgles-server 2.0.136 → 2.0.140
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/AuthHandler.d.ts.map +1 -1
- package/dist/AuthHandler.js +5 -1
- package/dist/AuthHandler.js.map +1 -1
- package/dist/Filtering.d.ts.map +1 -1
- package/dist/Filtering.js +12 -4
- package/dist/Filtering.js.map +1 -1
- package/examples/client/react-typescript/README.md +44 -0
- package/examples/client/react-typescript/package-lock.json +13909 -0
- package/examples/client/react-typescript/package.json +39 -0
- package/examples/client/react-typescript/public/favicon.ico +0 -0
- package/examples/client/react-typescript/public/index.html +43 -0
- package/examples/client/react-typescript/public/logo192.png +0 -0
- package/examples/client/react-typescript/public/logo512.png +0 -0
- package/examples/client/react-typescript/public/manifest.json +25 -0
- package/examples/client/react-typescript/public/robots.txt +3 -0
- package/examples/client/react-typescript/src/App.css +38 -0
- package/examples/client/react-typescript/src/App.test.tsx +9 -0
- package/examples/client/react-typescript/src/App.tsx +26 -0
- package/examples/client/react-typescript/src/index.css +13 -0
- package/examples/client/react-typescript/src/index.tsx +17 -0
- package/examples/client/react-typescript/src/logo.svg +7 -0
- package/examples/client/react-typescript/src/react-app-env.d.ts +1 -0
- package/examples/client/react-typescript/src/serviceWorker.ts +149 -0
- package/examples/client/react-typescript/src/setupTests.ts +5 -0
- package/examples/client/react-typescript/tsconfig.json +25 -0
- package/examples/client/vanilla-js/index.html +21 -0
- package/examples/full-example-react/client/README.md +68 -0
- package/examples/full-example-react/client/package-lock.json +14134 -0
- package/examples/full-example-react/client/package.json +36 -0
- package/examples/full-example-react/client/public/favicon.ico +0 -0
- package/examples/full-example-react/client/public/index.html +43 -0
- package/examples/full-example-react/client/public/logo192.png +0 -0
- package/examples/full-example-react/client/public/logo512.png +0 -0
- package/examples/full-example-react/client/public/manifest.json +25 -0
- package/examples/full-example-react/client/public/robots.txt +3 -0
- package/examples/full-example-react/client/src/App.css +14 -0
- package/examples/full-example-react/client/src/App.js +58 -0
- package/examples/full-example-react/client/src/App.test.js +9 -0
- package/examples/full-example-react/client/src/index.css +13 -0
- package/examples/full-example-react/client/src/index.js +17 -0
- package/examples/full-example-react/client/src/logo.svg +7 -0
- package/examples/full-example-react/client/src/serviceWorker.js +141 -0
- package/examples/full-example-react/client/src/setupTests.js +5 -0
- package/examples/full-example-react/client/src/sssetupProxy.js +6 -0
- package/examples/full-example-react/server/index.js +42 -0
- package/examples/full-example-react/server/init.sql +7 -0
- package/examples/full-example-react/server/package.json +18 -0
- package/examples/full-example-typescript/DBoGenerated.d.ts +74 -0
- package/examples/full-example-typescript/DBoGenerated.d.ts.map +1 -0
- package/examples/full-example-typescript/DBoGenerated.js +6 -0
- package/examples/full-example-typescript/DBoGenerated.js.map +1 -0
- package/examples/full-example-typescript/DBoGenerated.ts +67 -0
- package/examples/full-example-typescript/home.html +30 -0
- package/examples/full-example-typescript/index.d.ts +2 -0
- package/examples/full-example-typescript/index.d.ts.map +1 -0
- package/examples/full-example-typescript/index.js +66 -0
- package/examples/full-example-typescript/index.js.map +1 -0
- package/examples/full-example-typescript/index.ts +74 -0
- package/examples/full-example-typescript/init.sql +17 -0
- package/examples/full-example-typescript/package copy.json +16 -0
- package/examples/full-example-typescript/package.json +19 -0
- package/examples/full-example-typescript/tsconfig.json +24 -0
- package/examples/full-example-vanilla/home.html +131 -0
- package/examples/full-example-vanilla/index.js +108 -0
- package/examples/full-example-vanilla/init.sql +69 -0
- package/examples/full-example-vanilla/package.json +18 -0
- package/examples/server/javascript/index.js +27 -0
- package/examples/server/javascript/init.sql +5 -0
- package/examples/server/javascript/package.json +16 -0
- package/examples/server/typescript/DBoGenerated.d.ts +168 -0
- package/examples/server/typescript/DBoGenerated.d.ts.map +1 -0
- package/examples/server/typescript/DBoGenerated.js +5 -0
- package/examples/server/typescript/DBoGenerated.js.map +1 -0
- package/examples/server/typescript/DBoGenerated.ts +125 -0
- package/examples/server/typescript/index.d.ts +2 -0
- package/examples/server/typescript/index.d.ts.map +1 -0
- package/examples/server/typescript/index.js +54 -0
- package/examples/server/typescript/index.js.map +1 -0
- package/examples/server/typescript/index.ts +52 -0
- package/examples/server/typescript/init.sql +20 -0
- package/examples/server/typescript/package.json +17 -0
- package/examples/server/typescript/tsconfig.json +17 -0
- package/lib/AuthHandler.ts +5 -2
- package/lib/Filtering.ts +12 -2
- package/package.json +4 -5
- package/tests/client/PID.txt +1 -1
- package/tests/server/DBoGenerated.d.ts +0 -190
- package/tests/server/package-lock.json +7 -9
- package/tests/server/media/7b46d3c8-67f7-457c-b194-50bc815a1fa9.txt +0 -1
- package/tests/server/media/807b5037-8b8a-4871-bf68-4c0bf6cfcf19.txt +0 -1
- package/tests/server/media/e474c32f-8cf2-4678-9049-1bce3a17c2e5.txt +0 -1
- package/tests/server/media/fa20ecbf-935a-4ca2-b48d-a4aebc00fff8.txt +0 -1
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
<!DOCTYPE html>
|
|
4
|
+
<html>
|
|
5
|
+
<head>
|
|
6
|
+
<title> Prostgles </title>
|
|
7
|
+
|
|
8
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
9
|
+
<script src="https://unpkg.com/socket.io-client@2.3.0/dist/socket.io.slim.js" type="text/javascript"></script>
|
|
10
|
+
<script src="https://unpkg.com/prostgles-client@latest/dist/index.js" type="text/javascript"></script>
|
|
11
|
+
</head>
|
|
12
|
+
<body>
|
|
13
|
+
|
|
14
|
+
<script>
|
|
15
|
+
|
|
16
|
+
const socket = io();
|
|
17
|
+
socket.on("home", console.log)
|
|
18
|
+
|
|
19
|
+
prostgles({
|
|
20
|
+
socket,
|
|
21
|
+
isReady: (db, methods) => {
|
|
22
|
+
db.planes.find().then(console.log)
|
|
23
|
+
},
|
|
24
|
+
onDisconnect: (err, res) => {
|
|
25
|
+
// location.reload();
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
</script>
|
|
29
|
+
</body>
|
|
30
|
+
</html>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const express_1 = __importDefault(require("express"));
|
|
16
|
+
const app = express_1.default();
|
|
17
|
+
const path_1 = __importDefault(require("path"));
|
|
18
|
+
var http = require('http').createServer(app);
|
|
19
|
+
var io = require("socket.io")(http);
|
|
20
|
+
http.listen(30009);
|
|
21
|
+
var prostgles = require("../../dist/index");
|
|
22
|
+
prostgles({
|
|
23
|
+
dbConnection: {
|
|
24
|
+
host: "localhost",
|
|
25
|
+
port: 5432,
|
|
26
|
+
database: "example",
|
|
27
|
+
user: process.env.PRGL_USER,
|
|
28
|
+
password: process.env.PRGL_PWD
|
|
29
|
+
},
|
|
30
|
+
// dbOptions: {
|
|
31
|
+
// application_name: "prostgles_api",
|
|
32
|
+
// max: 100,
|
|
33
|
+
// poolIdleTimeout: 10000
|
|
34
|
+
// },
|
|
35
|
+
sqlFilePath: path_1.default.join(__dirname + '/init.sql'),
|
|
36
|
+
io,
|
|
37
|
+
tsGeneratedTypesDir: path_1.default.join(__dirname + '/'),
|
|
38
|
+
publish: (socket, dbo) => {
|
|
39
|
+
// if(!socket || !socket._user.admin && !socket._user.id){
|
|
40
|
+
// return false;
|
|
41
|
+
// }
|
|
42
|
+
return {
|
|
43
|
+
planes: "*"
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
// publishMethods: (socket, dbo: DBObj) => {
|
|
47
|
+
// return {
|
|
48
|
+
// insertPlanes: async (data) => {
|
|
49
|
+
// // let tl = Date.now();
|
|
50
|
+
// let res = await (dbo.planes).insert(data);
|
|
51
|
+
// // console.log(Date.now() - tl, "ms");
|
|
52
|
+
// return res;
|
|
53
|
+
// }
|
|
54
|
+
// }
|
|
55
|
+
// },
|
|
56
|
+
onReady: (dbo) => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
+
let plane = yield dboo.planes.findOne();
|
|
58
|
+
app.get('/', (req, res) => {
|
|
59
|
+
res.sendFile(path_1.default.join(__dirname + '/home.html'));
|
|
60
|
+
});
|
|
61
|
+
app.get('*', function (req, res) {
|
|
62
|
+
res.status(404).send('Page not found');
|
|
63
|
+
});
|
|
64
|
+
}),
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,sDAA8B;AAC9B,MAAM,GAAG,GAAG,iBAAO,EAAE,CAAC;AACtB,gDAAwB;AACxB,IAAI,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;AAC7C,IAAI,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC;AACpC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACnB,IAAI,SAAS,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAK5C,SAAS,CAAC;IACN,YAAY,EAAE;QACV,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,SAAS;QACnB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS;QAC3B,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ;KACjC;IACD,eAAe;IACf,yCAAyC;IACzC,gBAAgB;IAChB,6BAA6B;IAC7B,KAAK;IACL,WAAW,EAAE,cAAI,CAAC,IAAI,CAAC,SAAS,GAAC,WAAW,CAAC;IAC7C,EAAE;IACF,mBAAmB,EAAE,cAAI,CAAC,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC;IAClD,OAAO,EAAE,CAAC,MAAM,EAAE,GAAG,EAAG,EAAE;QACzB,0DAA0D;QAC1D,iBAAiB;QACX,IAAI;QAGJ,OAAO;YACH,MAAM,EAAE,GAAG;SACd,CAAA;IACL,CAAC;IACD,6CAA6C;IAC7C,eAAe;IACf,0CAA0C;IAC1C,uCAAuC;IACvC,yDAAyD;IACzD,qDAAqD;IACrD,0BAA0B;IAC1B,YAAY;IACZ,QAAQ;IACR,KAAK;IAEL,OAAO,EAAE,CAAO,GAAU,EAAE,EAAE;QAE1B,IAAI,KAAK,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QAG9C,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACzB,GAAG,CAAC,QAAQ,CAAC,cAAI,CAAC,IAAI,CAAC,SAAS,GAAC,YAAY,CAAC,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,UAAS,GAAG,EAAE,GAAG;YACnC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;IACD,CAAC,CAAA;CAaJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
const app = express();
|
|
3
|
+
import path from 'path';
|
|
4
|
+
var http = require('http').createServer(app);
|
|
5
|
+
var io = require("socket.io")(http);
|
|
6
|
+
http.listen(30009);
|
|
7
|
+
var prostgles = require("../../dist/index");
|
|
8
|
+
|
|
9
|
+
import { DBObj } from "./DBoGenerated";
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
prostgles({
|
|
13
|
+
dbConnection: {
|
|
14
|
+
host: "localhost",
|
|
15
|
+
port: 5432,
|
|
16
|
+
database: "example",
|
|
17
|
+
user: process.env.PRGL_USER,
|
|
18
|
+
password: process.env.PRGL_PWD
|
|
19
|
+
},
|
|
20
|
+
// dbOptions: {
|
|
21
|
+
// application_name: "prostgles_api",
|
|
22
|
+
// max: 100,
|
|
23
|
+
// poolIdleTimeout: 10000
|
|
24
|
+
// },
|
|
25
|
+
sqlFilePath: path.join(__dirname+'/init.sql'),
|
|
26
|
+
io,
|
|
27
|
+
tsGeneratedTypesDir: path.join(__dirname + '/'),
|
|
28
|
+
publish: (socket, dbo ) => {
|
|
29
|
+
// if(!socket || !socket._user.admin && !socket._user.id){
|
|
30
|
+
// return false;
|
|
31
|
+
// }
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
planes: "*"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
// publishMethods: (socket, dbo: DBObj) => {
|
|
39
|
+
// return {
|
|
40
|
+
// insertPlanes: async (data) => {
|
|
41
|
+
// // let tl = Date.now();
|
|
42
|
+
// let res = await (dbo.planes).insert(data);
|
|
43
|
+
// // console.log(Date.now() - tl, "ms");
|
|
44
|
+
// return res;
|
|
45
|
+
// }
|
|
46
|
+
// }
|
|
47
|
+
// },
|
|
48
|
+
|
|
49
|
+
onReady: async (dbo: DBObj) => {
|
|
50
|
+
|
|
51
|
+
let plane = await dbo.planes.findOne();
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
app.get('/', (req, res) => {
|
|
55
|
+
res.sendFile(path.join(__dirname+'/home.html'));
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
app.get('*', function(req, res){
|
|
59
|
+
res.status(404).send('Page not found');
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
// onSocketConnect: async ({ socket, dbo }) => {
|
|
63
|
+
// return true;
|
|
64
|
+
// },
|
|
65
|
+
// onSocketDisconnect: async ({ socket, dbo }) => {
|
|
66
|
+
// return true;
|
|
67
|
+
// },
|
|
68
|
+
// auth: {
|
|
69
|
+
// login: (data, { socket, dbo }) => {},
|
|
70
|
+
// register: (data, { socket, dbo }) => {},
|
|
71
|
+
// logout: (data, { socket, dbo }) => {},
|
|
72
|
+
// onChange: (state, { socket, dbo }) => {},
|
|
73
|
+
// },
|
|
74
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
DROP TABLE IF EXISTS airports CASCADE;
|
|
3
|
+
|
|
4
|
+
CREATE TABLE IF NOT EXISTS airports (
|
|
5
|
+
id SERIAL PRIMARY KEY,
|
|
6
|
+
last_updated BIGINT
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
DROP TABLE IF EXISTS planes CASCADE;
|
|
11
|
+
|
|
12
|
+
CREATE TABLE IF NOT EXISTS planes (
|
|
13
|
+
id SERIAL PRIMARY KEY,
|
|
14
|
+
model TEXT,
|
|
15
|
+
manufacturer TEXT,
|
|
16
|
+
last_updated BIGINT
|
|
17
|
+
);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "example",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"start": "node index.js"
|
|
8
|
+
},
|
|
9
|
+
"author": "",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"bluebird": "^3.7.2",
|
|
13
|
+
"express": "^4.17.1",
|
|
14
|
+
"socket.io": "^2.3.0"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "example-typescript",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"start": "tsc && node index.js"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"express": "^4.17.1",
|
|
12
|
+
"prostgles-client": "^1.5.60",
|
|
13
|
+
"prostgles-server": "^1.5.39",
|
|
14
|
+
"socket.io": "^4.0.1"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/socket.io": "^2.1.12"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"files": ["./index.ts"],
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "es6",
|
|
5
|
+
"lib": [
|
|
6
|
+
"es2019"
|
|
7
|
+
],
|
|
8
|
+
// "strict": true,
|
|
9
|
+
"esModuleInterop" : true,
|
|
10
|
+
"module": "commonjs",
|
|
11
|
+
// "removeComments": true,
|
|
12
|
+
"sourceMap": true,
|
|
13
|
+
"rootDir": ".",
|
|
14
|
+
// "outDir": "dist",
|
|
15
|
+
// "outFile": "bundle.js",
|
|
16
|
+
// "moduleResolution": "node"
|
|
17
|
+
"declaration": true,
|
|
18
|
+
"declarationMap": true
|
|
19
|
+
},
|
|
20
|
+
"exclude": [
|
|
21
|
+
"dist",
|
|
22
|
+
"DBoGenerated.ts"
|
|
23
|
+
]
|
|
24
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
<!DOCTYPE html>
|
|
4
|
+
<html>
|
|
5
|
+
<head>
|
|
6
|
+
<title> Prostgles </title>
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
8
|
+
<script src="https://unpkg.com/socket.io-client@latest/dist/socket.io.min.js" type="text/javascript"></script>
|
|
9
|
+
<script src="https://unpkg.com/prostgles-client@latest/dist/index.js" type="text/javascript"></script>
|
|
10
|
+
</head>
|
|
11
|
+
<body style="margin: 0;">
|
|
12
|
+
<style>
|
|
13
|
+
html, body {
|
|
14
|
+
margin: 0;
|
|
15
|
+
padding: 0;
|
|
16
|
+
width: 100%;
|
|
17
|
+
height: 100%;
|
|
18
|
+
overflow: hidden;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
* {
|
|
22
|
+
box-sizing: border-box;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
canvas {
|
|
26
|
+
cursor: pointer;
|
|
27
|
+
border: 1px solid #cacaca;
|
|
28
|
+
margin: auto;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
p {
|
|
32
|
+
margin: 1em;
|
|
33
|
+
}
|
|
34
|
+
</style>
|
|
35
|
+
<p></p>
|
|
36
|
+
<canvas id="canvas" width="100%" height="100%"></canvas>
|
|
37
|
+
<script>
|
|
38
|
+
const p = document.querySelector("p");
|
|
39
|
+
|
|
40
|
+
const socket = io({ path: "/teztz/s" });
|
|
41
|
+
|
|
42
|
+
prostgles({
|
|
43
|
+
socket,
|
|
44
|
+
onReconnect: () => {
|
|
45
|
+
location.reload();
|
|
46
|
+
},
|
|
47
|
+
onReady: async (db, methods) => {
|
|
48
|
+
window.db = db;
|
|
49
|
+
initCanvas(db);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
async function initCanvas(dbo){
|
|
54
|
+
var canvas = document.getElementById('canvas');
|
|
55
|
+
var ctx = canvas.getContext('2d');
|
|
56
|
+
|
|
57
|
+
await dbo.Points.delete({});
|
|
58
|
+
|
|
59
|
+
const ps = await dbo.Points.sync({}, {}, draw);
|
|
60
|
+
// ps.subscribeAll(draw);
|
|
61
|
+
// dbo.points.subscribe({}, { orderBy: "id", select: ["x", "y", "color", "id"] }, draw)
|
|
62
|
+
|
|
63
|
+
var grad = ctx.createLinearGradient(50, 50, window.innerWidth, window.innerHeight);
|
|
64
|
+
grad.addColorStop(0, "red");
|
|
65
|
+
grad.addColorStop(0.3, "green");
|
|
66
|
+
grad.addColorStop(0.6, "cyan");
|
|
67
|
+
grad.addColorStop(1, "violet");
|
|
68
|
+
|
|
69
|
+
function draw(points){
|
|
70
|
+
p.innerText = `${points.length} Points`;
|
|
71
|
+
if(points && points.length > 1){
|
|
72
|
+
ctx.beginPath();
|
|
73
|
+
ctx.moveTo(points[0].x, [points[0].y]);
|
|
74
|
+
ctx.lineCap = 'round';
|
|
75
|
+
ctx.lineWidth = 3;
|
|
76
|
+
|
|
77
|
+
points.map(({ x, y }, i) => {
|
|
78
|
+
if(i){
|
|
79
|
+
ctx.lineTo(x, y);
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
ctx.strokeStyle = grad;//"red";
|
|
84
|
+
ctx.stroke();
|
|
85
|
+
} else {
|
|
86
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
var width = document.body.offsetWidth;
|
|
92
|
+
var height = document.body.offsetHeight;
|
|
93
|
+
canvas.height = height;
|
|
94
|
+
canvas.width = width;
|
|
95
|
+
canvas.addEventListener('mousedown', function(e) {
|
|
96
|
+
this.down = true;
|
|
97
|
+
this.X = e.offsetX ;
|
|
98
|
+
this.Y = e.offsetY ;
|
|
99
|
+
this.color = rgb();
|
|
100
|
+
this.line_id = null;
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
// dbo.points.insert({ id: Date.now(), color: this.color, x: this.X, y: this.Y, line_id: this.line_id })
|
|
104
|
+
// ps.upsert([{ id: Date.now(), color: this.color, x: this.X, y: this.Y, line_id: this.line_id}])
|
|
105
|
+
}, 0);
|
|
106
|
+
canvas.addEventListener('mouseup', function() {
|
|
107
|
+
this.down = false;
|
|
108
|
+
}, 0);
|
|
109
|
+
canvas.addEventListener('mousemove', function(e) {
|
|
110
|
+
this.style.cursor = 'pointer';
|
|
111
|
+
if(this.down) {
|
|
112
|
+
|
|
113
|
+
ps.upsert([{ id: Date.now(), color: null, x: e.offsetX, y: e.offsetY, line_id: this.line_id }])
|
|
114
|
+
|
|
115
|
+
this.X = e.offsetX ;
|
|
116
|
+
this.Y = e.offsetY ;
|
|
117
|
+
}
|
|
118
|
+
}, 0);
|
|
119
|
+
|
|
120
|
+
function rgb() {
|
|
121
|
+
color = 'rgb(';
|
|
122
|
+
for(var i = 0; i< 3; i++) {
|
|
123
|
+
color += Math.floor(Math.random() * 255)+',';
|
|
124
|
+
}
|
|
125
|
+
return color.replace(/\,$/,')');
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
</script>
|
|
130
|
+
</body>
|
|
131
|
+
</html>
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
const express = require('express');
|
|
2
|
+
const app = express();
|
|
3
|
+
const path = require('path');
|
|
4
|
+
var http = require('http').createServer(app);
|
|
5
|
+
var io = require('socket.io')(http, { path: "/s" });
|
|
6
|
+
http.listen(3001);
|
|
7
|
+
|
|
8
|
+
let prostgles = require('../../dist/index.js');
|
|
9
|
+
// let prostgles = require('prostgles-server');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
prostgles({
|
|
13
|
+
dbConnection: {
|
|
14
|
+
host: "localhost",
|
|
15
|
+
port: "5432",
|
|
16
|
+
user: process.env.PRGL_USER,
|
|
17
|
+
password: process.env.PRGL_PWD
|
|
18
|
+
},
|
|
19
|
+
dbOptions: {
|
|
20
|
+
application_name: "prostgles_api",
|
|
21
|
+
max: 100,
|
|
22
|
+
poolIdleTimeout: 10000
|
|
23
|
+
},
|
|
24
|
+
sqlFilePath: path.join(__dirname+'/init.sql'),
|
|
25
|
+
|
|
26
|
+
io,
|
|
27
|
+
|
|
28
|
+
onReady: async (dbo, db) => {
|
|
29
|
+
try {
|
|
30
|
+
// dbo.Events.subscribe({}, {}, console.log)
|
|
31
|
+
// setTimeout(async ()=>{
|
|
32
|
+
// try {
|
|
33
|
+
// await dbo.Events.insert({ Id: 1 });
|
|
34
|
+
// await dbo.Events.insert({ Id: 21 });
|
|
35
|
+
// await dbo.Events.update({ Id: { $lt: 4 }}, { Id: 12 });
|
|
36
|
+
// await dbo.Events.delete({});
|
|
37
|
+
|
|
38
|
+
// } catch(err) {
|
|
39
|
+
// console.error(err)
|
|
40
|
+
// }
|
|
41
|
+
// }, 1000);
|
|
42
|
+
|
|
43
|
+
} catch(err) {
|
|
44
|
+
console.error(err)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
app.get('*', function(req, res){
|
|
48
|
+
console.log(req.originalUrl)
|
|
49
|
+
res.sendFile(path.join(__dirname+'/home.html'));
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
publish: (socket, dbo) => {
|
|
54
|
+
return {
|
|
55
|
+
|
|
56
|
+
Points: {
|
|
57
|
+
select: "*",
|
|
58
|
+
insert: "*",
|
|
59
|
+
update: "*",
|
|
60
|
+
delete: "*",
|
|
61
|
+
sync: {
|
|
62
|
+
synced_field: "Synced",
|
|
63
|
+
id_fields: ["id"]
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
lines: {
|
|
67
|
+
select: "*",
|
|
68
|
+
insert: "*",
|
|
69
|
+
update: "*",
|
|
70
|
+
delete: "*",
|
|
71
|
+
sync: {
|
|
72
|
+
synced_field: "Synced",
|
|
73
|
+
id_fields: ["id"]
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
// publishMethods: ( socket, dbo) => {
|
|
80
|
+
|
|
81
|
+
// return {
|
|
82
|
+
// upload: async (data) => {
|
|
83
|
+
// // let tl = Date.now();
|
|
84
|
+
// //let res = await dbo.pixels.insert(data);
|
|
85
|
+
// // console.log(Date.now() - tl, "ms");
|
|
86
|
+
// console.log(data)// res;
|
|
87
|
+
// dbo.pixels.insert({ blb: data })
|
|
88
|
+
// }
|
|
89
|
+
// }
|
|
90
|
+
// },
|
|
91
|
+
// onSocketConnect: async ({ socket, dbo }) => {
|
|
92
|
+
// /* Sending file */
|
|
93
|
+
// fs.readFile('home.html', function(err, buf){
|
|
94
|
+
// socket.emit('home', { image: true, buffer: buf });
|
|
95
|
+
// });
|
|
96
|
+
|
|
97
|
+
// return true;
|
|
98
|
+
// },
|
|
99
|
+
// onSocketDisconnect: async ({ socket, dbo }) => {
|
|
100
|
+
// return true;
|
|
101
|
+
// },
|
|
102
|
+
// auth: {
|
|
103
|
+
// login: (data, { socket, dbo }) => {},
|
|
104
|
+
// register: (data, { socket, dbo }) => {},
|
|
105
|
+
// logout: (data, { socket, dbo }) => {},
|
|
106
|
+
// onChange: (state, { socket, dbo }) => {},
|
|
107
|
+
// },
|
|
108
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
-- DROP TABLE IF EXISTS drawings CASCADE;
|
|
4
|
+
-- CREATE TABLE IF NOT EXISTS drawings (
|
|
5
|
+
-- id bigint primary key generated always as identity,
|
|
6
|
+
-- pixel_id bigint
|
|
7
|
+
-- );
|
|
8
|
+
|
|
9
|
+
-- DROP TABLE IF EXISTS pixels CASCADE;
|
|
10
|
+
-- CREATE TABLE IF NOT EXISTS pixels (
|
|
11
|
+
-- id bigint primary key generated always as identity,
|
|
12
|
+
-- color_id bigint,
|
|
13
|
+
-- rgb TEXT,
|
|
14
|
+
-- xy TEXT,
|
|
15
|
+
-- last_updated BIGINT,
|
|
16
|
+
-- drawn BOOLEAN,
|
|
17
|
+
-- blb BYTEA
|
|
18
|
+
-- );
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
-- DROP TABLE IF EXISTS colors CASCADE;
|
|
22
|
+
-- CREATE TABLE IF NOT EXISTS colors (
|
|
23
|
+
-- id bigint primary key generated always as identity,
|
|
24
|
+
-- rgb TEXT
|
|
25
|
+
-- );
|
|
26
|
+
|
|
27
|
+
DROP TABLE IF EXISTS lines CASCADE;
|
|
28
|
+
CREATE TABLE IF NOT EXISTS lines (
|
|
29
|
+
id SERIAL,
|
|
30
|
+
color TEXT,
|
|
31
|
+
"Synced" BIGINT
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
DROP TABLE IF EXISTS "Points" CASCADE;
|
|
35
|
+
CREATE TABLE IF NOT EXISTS "Points" (
|
|
36
|
+
id NUMERIC,
|
|
37
|
+
color TEXT,
|
|
38
|
+
x NUMERIC,
|
|
39
|
+
y NUMERIC,
|
|
40
|
+
line_id TEXT,
|
|
41
|
+
"Synced" BIGINT
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
-- DROP TABLE IF EXISTS users CASCADE;
|
|
46
|
+
-- CREATE TABLE IF NOT EXISTS users (
|
|
47
|
+
-- id bigint primary key generated always as identity,
|
|
48
|
+
-- username TEXT
|
|
49
|
+
-- );
|
|
50
|
+
|
|
51
|
+
-- DROP TABLE IF EXISTS posts CASCADE;
|
|
52
|
+
-- CREATE TABLE IF NOT EXISTS posts (
|
|
53
|
+
-- id bigint primary key generated always as identity,
|
|
54
|
+
-- user_id bigint,
|
|
55
|
+
-- title TEXT
|
|
56
|
+
-- );
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
-- DROP TABLE IF EXISTS comments CASCADE;
|
|
60
|
+
-- CREATE TABLE IF NOT EXISTS comments (
|
|
61
|
+
-- id bigint primary key generated always as identity,
|
|
62
|
+
-- post_id bigint,
|
|
63
|
+
-- user_id bigint,
|
|
64
|
+
-- content TEXT
|
|
65
|
+
-- );
|
|
66
|
+
|
|
67
|
+
-- CREATE OR REPLACE VIEW v_c AS
|
|
68
|
+
-- SELECT users.id, comments.content
|
|
69
|
+
-- FROM users LEFT JOIN comments ON users.id = comments.user_id;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "example",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"start": "node index.js"
|
|
8
|
+
},
|
|
9
|
+
"author": "",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"bluebird": "^3.7.2",
|
|
13
|
+
"express": "^4.17.1",
|
|
14
|
+
"mongodb": "^3.6.3",
|
|
15
|
+
"prostgles-server": "^1.5.39",
|
|
16
|
+
"socket.io": "^3.1.2"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const express = require('express');
|
|
2
|
+
const app = express();
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const { join } = require('path');
|
|
5
|
+
var http = require('http').createServer(app);
|
|
6
|
+
var io = require('socket.io')(http);
|
|
7
|
+
http.listen(3001);
|
|
8
|
+
|
|
9
|
+
const prostgles = require('prostgles-server');
|
|
10
|
+
|
|
11
|
+
prostgles({
|
|
12
|
+
dbConnection: {
|
|
13
|
+
host: "localhost",
|
|
14
|
+
port: "5432",
|
|
15
|
+
user: process.env.PRGL_USER,
|
|
16
|
+
password: process.env.PRGL_PWD
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
// Optional sql file to be run on each reload
|
|
20
|
+
sqlFilePath: path.join(__dirname+'/init.sql'),
|
|
21
|
+
|
|
22
|
+
publish: (socket, dbo) => "*",
|
|
23
|
+
io,
|
|
24
|
+
onReady: async (db, _db) => {
|
|
25
|
+
|
|
26
|
+
},
|
|
27
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "javascript",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"start": "node index.js"
|
|
8
|
+
},
|
|
9
|
+
"author": "",
|
|
10
|
+
"license": "ISC",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"express": "^4.17.1",
|
|
13
|
+
"prostgles-server": "^1.5.39",
|
|
14
|
+
"socket.io": "^4.0.1"
|
|
15
|
+
}
|
|
16
|
+
}
|