polfan-server-js-client 0.0.5 → 0.0.6

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 (235) hide show
  1. package/.idea/deployment.xml +21 -0
  2. package/.idea/modules.xml +8 -0
  3. package/.idea/polfan-server-js-client.iml +8 -0
  4. package/.idea/vcs.xml +7 -0
  5. package/CODE_OF_CONDUCT.md +76 -0
  6. package/CONTRIBUTING.md +15 -0
  7. package/LICENSE +21 -0
  8. package/build/index.js +2 -0
  9. package/build/index.js.map +1 -0
  10. package/build/types/Client.d.ts +76 -0
  11. package/build/types/ObservableInterface.d.ts +9 -0
  12. package/{dist → build/types}/Token.d.ts +0 -0
  13. package/{dist → build/types}/connections/ConnectionInterface.d.ts +0 -0
  14. package/{dist → build/types}/connections/WebApiConnection.d.ts +0 -0
  15. package/{dist → build/types}/connections/WebSocketConnection.d.ts +0 -0
  16. package/build/types/dtos/Dto.d.ts +16 -0
  17. package/{dist → build/types}/dtos/Message.d.ts +0 -0
  18. package/{dist → build/types}/dtos/Permission.d.ts +0 -0
  19. package/{dist → build/types}/dtos/Role.d.ts +0 -0
  20. package/{dist → build/types}/dtos/Room.d.ts +0 -0
  21. package/{dist → build/types}/dtos/RoomMember.d.ts +0 -0
  22. package/{dist → build/types}/dtos/RoomSummary.d.ts +0 -0
  23. package/{dist → build/types}/dtos/Space.d.ts +0 -0
  24. package/{dist → build/types}/dtos/SpaceMember.d.ts +0 -0
  25. package/{dist → build/types}/dtos/Topic.d.ts +0 -0
  26. package/build/types/dtos/User.d.ts +9 -0
  27. package/{dist → build/types}/dtos/UserState.d.ts +0 -0
  28. package/{dist → build/types}/dtos/protocol/Envelope.d.ts +0 -0
  29. package/{dist → build/types}/dtos/protocol/EnvelopeMeta.d.ts +0 -0
  30. package/{dist → build/types}/dtos/protocol/commands/AssignRole.d.ts +0 -0
  31. package/{dist → build/types}/dtos/protocol/commands/CreateMessage.d.ts +0 -0
  32. package/{dist → build/types}/dtos/protocol/commands/CreateRole.d.ts +0 -0
  33. package/{dist → build/types}/dtos/protocol/commands/CreateRoom.d.ts +0 -0
  34. package/{dist → build/types}/dtos/protocol/commands/CreateSpace.d.ts +0 -0
  35. package/{dist → build/types}/dtos/protocol/commands/CreateTopic.d.ts +0 -0
  36. package/{dist → build/types}/dtos/protocol/commands/DeassignRole.d.ts +0 -0
  37. package/{dist → build/types}/dtos/protocol/commands/DeleteRole.d.ts +0 -0
  38. package/{dist → build/types}/dtos/protocol/commands/DeleteRoom.d.ts +0 -0
  39. package/{dist → build/types}/dtos/protocol/commands/DeleteSpace.d.ts +0 -0
  40. package/{dist → build/types}/dtos/protocol/commands/DeleteTopic.d.ts +0 -0
  41. package/{dist → build/types}/dtos/protocol/commands/GetComputedPermissions.d.ts +0 -0
  42. package/{dist → build/types}/dtos/protocol/commands/GetRolePermissions.d.ts +0 -0
  43. package/{dist → build/types}/dtos/protocol/commands/GetRoomMembers.d.ts +0 -0
  44. package/{dist → build/types}/dtos/protocol/commands/GetSession.d.ts +0 -0
  45. package/{dist → build/types}/dtos/protocol/commands/GetSpaceMembers.d.ts +0 -0
  46. package/{dist → build/types}/dtos/protocol/commands/GetSpaceRooms.d.ts +0 -0
  47. package/{dist → build/types}/dtos/protocol/commands/GetUserPermissions.d.ts +0 -0
  48. package/{dist → build/types}/dtos/protocol/commands/JoinRoom.d.ts +0 -0
  49. package/{dist → build/types}/dtos/protocol/commands/JoinSpace.d.ts +0 -0
  50. package/{dist → build/types}/dtos/protocol/commands/LeaveRoom.d.ts +0 -0
  51. package/{dist → build/types}/dtos/protocol/commands/LeaveSpace.d.ts +0 -0
  52. package/{dist → build/types}/dtos/protocol/commands/SetRolePermissions.d.ts +0 -0
  53. package/{dist → build/types}/dtos/protocol/commands/SetUserPermissions.d.ts +0 -0
  54. package/{dist → build/types}/dtos/protocol/events/Bye.d.ts +0 -0
  55. package/{dist → build/types}/dtos/protocol/events/Error.d.ts +0 -0
  56. package/{dist → build/types}/dtos/protocol/events/NewMessage.d.ts +0 -0
  57. package/{dist → build/types}/dtos/protocol/events/NewRole.d.ts +0 -0
  58. package/{dist → build/types}/dtos/protocol/events/NewRoom.d.ts +0 -0
  59. package/{dist → build/types}/dtos/protocol/events/NewTopic.d.ts +0 -0
  60. package/{dist → build/types}/dtos/protocol/events/Ok.d.ts +0 -0
  61. package/{dist → build/types}/dtos/protocol/events/Permissions.d.ts +0 -0
  62. package/{dist → build/types}/dtos/protocol/events/RoleDeleted.d.ts +0 -0
  63. package/{dist → build/types}/dtos/protocol/events/RoomDeleted.d.ts +0 -0
  64. package/{dist → build/types}/dtos/protocol/events/RoomJoined.d.ts +0 -0
  65. package/{dist → build/types}/dtos/protocol/events/RoomLeft.d.ts +0 -0
  66. package/{dist → build/types}/dtos/protocol/events/RoomMemberJoined.d.ts +0 -0
  67. package/{dist → build/types}/dtos/protocol/events/RoomMemberLeft.d.ts +0 -0
  68. package/{dist → build/types}/dtos/protocol/events/RoomMembers.d.ts +0 -0
  69. package/{dist → build/types}/dtos/protocol/events/Session.d.ts +0 -0
  70. package/{dist → build/types}/dtos/protocol/events/SpaceDeleted.d.ts +0 -0
  71. package/{dist → build/types}/dtos/protocol/events/SpaceJoined.d.ts +0 -0
  72. package/{dist → build/types}/dtos/protocol/events/SpaceLeft.d.ts +0 -0
  73. package/{dist → build/types}/dtos/protocol/events/SpaceMemberJoined.d.ts +0 -0
  74. package/{dist → build/types}/dtos/protocol/events/SpaceMemberLeft.d.ts +0 -0
  75. package/{dist → build/types}/dtos/protocol/events/SpaceMemberUpdate.d.ts +0 -0
  76. package/{dist → build/types}/dtos/protocol/events/SpaceMembers.d.ts +0 -0
  77. package/{dist → build/types}/dtos/protocol/events/SpaceRooms.d.ts +0 -0
  78. package/{dist → build/types}/dtos/protocol/events/TopicDeleted.d.ts +0 -0
  79. package/build/types/index.d.ts +23 -0
  80. package/{dist → build/types}/protocol.d.ts +0 -0
  81. package/{dist → old/dist}/Client.d.ts +0 -0
  82. package/{dist → old/dist}/ObservableInterface.d.ts +0 -0
  83. package/old/dist/Token.d.ts +5 -0
  84. package/old/dist/connections/ConnectionInterface.d.ts +17 -0
  85. package/old/dist/connections/WebApiConnection.d.ts +15 -0
  86. package/old/dist/connections/WebSocketConnection.d.ts +19 -0
  87. package/{dist → old/dist}/dtos/Dto.d.ts +0 -0
  88. package/old/dist/dtos/Message.d.ts +9 -0
  89. package/old/dist/dtos/Permission.d.ts +7 -0
  90. package/old/dist/dtos/Role.d.ts +7 -0
  91. package/old/dist/dtos/Room.d.ts +8 -0
  92. package/old/dist/dtos/RoomMember.d.ts +6 -0
  93. package/old/dist/dtos/RoomSummary.d.ts +7 -0
  94. package/old/dist/dtos/Space.d.ts +8 -0
  95. package/old/dist/dtos/SpaceMember.d.ts +7 -0
  96. package/old/dist/dtos/Topic.d.ts +7 -0
  97. package/{dist → old/dist}/dtos/User.d.ts +0 -0
  98. package/old/dist/dtos/UserState.d.ts +8 -0
  99. package/old/dist/dtos/protocol/Envelope.d.ts +7 -0
  100. package/old/dist/dtos/protocol/EnvelopeMeta.d.ts +6 -0
  101. package/{dist → old/dist}/dtos/protocol/ProtocolMessage.d.ts +0 -0
  102. package/{dist → old/dist}/dtos/protocol/ProtocolMetaData.d.ts +0 -0
  103. package/old/dist/dtos/protocol/commands/AssignRole.d.ts +7 -0
  104. package/old/dist/dtos/protocol/commands/CreateMessage.d.ts +7 -0
  105. package/old/dist/dtos/protocol/commands/CreateRole.d.ts +7 -0
  106. package/old/dist/dtos/protocol/commands/CreateRoom.d.ts +7 -0
  107. package/old/dist/dtos/protocol/commands/CreateSpace.d.ts +5 -0
  108. package/old/dist/dtos/protocol/commands/CreateTopic.d.ts +7 -0
  109. package/old/dist/dtos/protocol/commands/DeassignRole.d.ts +7 -0
  110. package/old/dist/dtos/protocol/commands/DeleteRole.d.ts +6 -0
  111. package/old/dist/dtos/protocol/commands/DeleteRoom.d.ts +5 -0
  112. package/old/dist/dtos/protocol/commands/DeleteSpace.d.ts +5 -0
  113. package/old/dist/dtos/protocol/commands/DeleteTopic.d.ts +5 -0
  114. package/old/dist/dtos/protocol/commands/GetComputedPermissions.d.ts +8 -0
  115. package/old/dist/dtos/protocol/commands/GetRolePermissions.d.ts +8 -0
  116. package/old/dist/dtos/protocol/commands/GetRoomMembers.d.ts +5 -0
  117. package/old/dist/dtos/protocol/commands/GetSession.d.ts +4 -0
  118. package/old/dist/dtos/protocol/commands/GetSpaceMembers.d.ts +5 -0
  119. package/old/dist/dtos/protocol/commands/GetSpaceRooms.d.ts +5 -0
  120. package/old/dist/dtos/protocol/commands/GetUserPermissions.d.ts +8 -0
  121. package/old/dist/dtos/protocol/commands/JoinRoom.d.ts +5 -0
  122. package/old/dist/dtos/protocol/commands/JoinSpace.d.ts +5 -0
  123. package/old/dist/dtos/protocol/commands/LeaveRoom.d.ts +5 -0
  124. package/old/dist/dtos/protocol/commands/LeaveSpace.d.ts +5 -0
  125. package/old/dist/dtos/protocol/commands/SetRolePermissions.d.ts +9 -0
  126. package/old/dist/dtos/protocol/commands/SetUserPermissions.d.ts +9 -0
  127. package/old/dist/dtos/protocol/events/Bye.d.ts +5 -0
  128. package/old/dist/dtos/protocol/events/Error.d.ts +6 -0
  129. package/old/dist/dtos/protocol/events/NewMessage.d.ts +6 -0
  130. package/old/dist/dtos/protocol/events/NewRole.d.ts +7 -0
  131. package/old/dist/dtos/protocol/events/NewRoom.d.ts +7 -0
  132. package/old/dist/dtos/protocol/events/NewTopic.d.ts +7 -0
  133. package/old/dist/dtos/protocol/events/Ok.d.ts +4 -0
  134. package/old/dist/dtos/protocol/events/Permissions.d.ts +6 -0
  135. package/old/dist/dtos/protocol/events/RoleDeleted.d.ts +6 -0
  136. package/old/dist/dtos/protocol/events/RoomDeleted.d.ts +5 -0
  137. package/old/dist/dtos/protocol/events/RoomJoined.d.ts +6 -0
  138. package/old/dist/dtos/protocol/events/RoomLeft.d.ts +5 -0
  139. package/old/dist/dtos/protocol/events/RoomMemberJoined.d.ts +6 -0
  140. package/old/dist/dtos/protocol/events/RoomMemberLeft.d.ts +5 -0
  141. package/old/dist/dtos/protocol/events/RoomMembers.d.ts +6 -0
  142. package/old/dist/dtos/protocol/events/Session.d.ts +9 -0
  143. package/old/dist/dtos/protocol/events/SpaceDeleted.d.ts +5 -0
  144. package/old/dist/dtos/protocol/events/SpaceJoined.d.ts +6 -0
  145. package/old/dist/dtos/protocol/events/SpaceLeft.d.ts +5 -0
  146. package/old/dist/dtos/protocol/events/SpaceMemberJoined.d.ts +6 -0
  147. package/old/dist/dtos/protocol/events/SpaceMemberLeft.d.ts +5 -0
  148. package/old/dist/dtos/protocol/events/SpaceMemberUpdate.d.ts +6 -0
  149. package/old/dist/dtos/protocol/events/SpaceMembers.d.ts +6 -0
  150. package/old/dist/dtos/protocol/events/SpaceRooms.d.ts +6 -0
  151. package/old/dist/dtos/protocol/events/TopicDeleted.d.ts +5 -0
  152. package/{dist → old/dist}/index.d.ts +0 -0
  153. package/{dist → old/dist}/index.js +0 -0
  154. package/{dist → old/dist}/index.js.map +0 -0
  155. package/old/dist/protocol.d.ts +7 -0
  156. package/{dist → old/dist}/pserv-js-client.js +0 -0
  157. package/{dist → old/dist}/pserv-js-client.js.map +0 -0
  158. package/old/package-lock.json +2654 -0
  159. package/old/package.json +22 -0
  160. package/old/tsconfig.json +12 -0
  161. package/package.json +55 -13
  162. package/tsconfig.json +15 -10
  163. package/webpack.config.demo.js +47 -0
  164. package/src/Client.ts +0 -166
  165. package/src/ObservableInterface.ts +0 -22
  166. package/src/Token.ts +0 -21
  167. package/src/connections/ConnectionInterface.ts +0 -20
  168. package/src/connections/WebApiConnection.ts +0 -43
  169. package/src/connections/WebSocketConnection.ts +0 -47
  170. package/src/dtos/Dto.ts +0 -45
  171. package/src/dtos/Message.ts +0 -16
  172. package/src/dtos/Permission.ts +0 -12
  173. package/src/dtos/Role.ts +0 -12
  174. package/src/dtos/Room.ts +0 -15
  175. package/src/dtos/RoomMember.ts +0 -13
  176. package/src/dtos/RoomSummary.ts +0 -12
  177. package/src/dtos/Space.ts +0 -15
  178. package/src/dtos/SpaceMember.ts +0 -14
  179. package/src/dtos/Topic.ts +0 -12
  180. package/src/dtos/User.ts +0 -15
  181. package/src/dtos/UserState.ts +0 -16
  182. package/src/dtos/protocol/Envelope.ts +0 -14
  183. package/src/dtos/protocol/EnvelopeMeta.ts +0 -11
  184. package/src/dtos/protocol/commands/AssignRole.ts +0 -12
  185. package/src/dtos/protocol/commands/CreateMessage.ts +0 -12
  186. package/src/dtos/protocol/commands/CreateRole.ts +0 -12
  187. package/src/dtos/protocol/commands/CreateRoom.ts +0 -12
  188. package/src/dtos/protocol/commands/CreateSpace.ts +0 -10
  189. package/src/dtos/protocol/commands/CreateTopic.ts +0 -12
  190. package/src/dtos/protocol/commands/DeassignRole.ts +0 -12
  191. package/src/dtos/protocol/commands/DeleteRole.ts +0 -11
  192. package/src/dtos/protocol/commands/DeleteRoom.ts +0 -10
  193. package/src/dtos/protocol/commands/DeleteSpace.ts +0 -10
  194. package/src/dtos/protocol/commands/DeleteTopic.ts +0 -10
  195. package/src/dtos/protocol/commands/GetComputedPermissions.ts +0 -13
  196. package/src/dtos/protocol/commands/GetRolePermissions.ts +0 -13
  197. package/src/dtos/protocol/commands/GetRoomMembers.ts +0 -10
  198. package/src/dtos/protocol/commands/GetSession.ts +0 -8
  199. package/src/dtos/protocol/commands/GetSpaceMembers.ts +0 -10
  200. package/src/dtos/protocol/commands/GetSpaceRooms.ts +0 -10
  201. package/src/dtos/protocol/commands/GetUserPermissions.ts +0 -13
  202. package/src/dtos/protocol/commands/JoinRoom.ts +0 -10
  203. package/src/dtos/protocol/commands/JoinSpace.ts +0 -10
  204. package/src/dtos/protocol/commands/LeaveRoom.ts +0 -10
  205. package/src/dtos/protocol/commands/LeaveSpace.ts +0 -10
  206. package/src/dtos/protocol/commands/SetRolePermissions.ts +0 -16
  207. package/src/dtos/protocol/commands/SetUserPermissions.ts +0 -16
  208. package/src/dtos/protocol/events/Bye.ts +0 -10
  209. package/src/dtos/protocol/events/Error.ts +0 -11
  210. package/src/dtos/protocol/events/NewMessage.ts +0 -13
  211. package/src/dtos/protocol/events/NewRole.ts +0 -14
  212. package/src/dtos/protocol/events/NewRoom.ts +0 -14
  213. package/src/dtos/protocol/events/NewTopic.ts +0 -14
  214. package/src/dtos/protocol/events/Ok.ts +0 -8
  215. package/src/dtos/protocol/events/Permissions.ts +0 -13
  216. package/src/dtos/protocol/events/RoleDeleted.ts +0 -11
  217. package/src/dtos/protocol/events/RoomDeleted.ts +0 -10
  218. package/src/dtos/protocol/events/RoomJoined.ts +0 -13
  219. package/src/dtos/protocol/events/RoomLeft.ts +0 -10
  220. package/src/dtos/protocol/events/RoomMemberJoined.ts +0 -13
  221. package/src/dtos/protocol/events/RoomMemberLeft.ts +0 -10
  222. package/src/dtos/protocol/events/RoomMembers.ts +0 -13
  223. package/src/dtos/protocol/events/Session.ts +0 -17
  224. package/src/dtos/protocol/events/SpaceDeleted.ts +0 -10
  225. package/src/dtos/protocol/events/SpaceJoined.ts +0 -13
  226. package/src/dtos/protocol/events/SpaceLeft.ts +0 -10
  227. package/src/dtos/protocol/events/SpaceMemberJoined.ts +0 -13
  228. package/src/dtos/protocol/events/SpaceMemberLeft.ts +0 -10
  229. package/src/dtos/protocol/events/SpaceMemberUpdate.ts +0 -13
  230. package/src/dtos/protocol/events/SpaceMembers.ts +0 -13
  231. package/src/dtos/protocol/events/SpaceRooms.ts +0 -13
  232. package/src/dtos/protocol/events/TopicDeleted.ts +0 -10
  233. package/src/index.ts +0 -26
  234. package/src/protocol.ts +0 -113
  235. package/webpack.config.js +0 -24
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "polfan-server-js-client",
3
+ "version": "0.0.5",
4
+ "description": "JavaScript client library for handling communication with Polfan chat server.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1",
9
+ "build": "webpack"
10
+ },
11
+ "author": "Jarosław Żak",
12
+ "license": "ISC",
13
+ "devDependencies": {
14
+ "typescript": "^4.6.3",
15
+ "webpack-cli": "^4.9.2"
16
+ },
17
+ "dependencies": {
18
+ "@types/uuid": "^8.3.4",
19
+ "ts-loader": "^9.2.8",
20
+ "uuid": "^8.3.2"
21
+ }
22
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES6",
4
+ "module": "commonjs",
5
+ "declaration": true,
6
+ "outDir": "./dist",
7
+ "strict": true,
8
+ "strictPropertyInitialization": false,
9
+ },
10
+ "include": ["src"],
11
+ "exclude": ["node_modules", "**/__tests__/*"]
12
+ }
package/package.json CHANGED
@@ -1,22 +1,64 @@
1
1
  {
2
2
  "name": "polfan-server-js-client",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "JavaScript client library for handling communication with Polfan chat server.",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
5
+ "author": "Jarosław Żak",
6
+ "license": "MIT",
7
+ "main": "build/index.js",
8
+ "types": "build/types/index.d.ts",
7
9
  "scripts": {
8
- "test": "echo \"Error: no test specified\" && exit 1",
9
- "build": "webpack"
10
+ "start": "webpack serve --config webpack.config.demo.js",
11
+ "build": "webpack && tsc",
12
+ "build:demo": "webpack --config webpack.config.demo.js",
13
+ "test": "jest --silent",
14
+ "coverage": "npm run test -- --coverage",
15
+ "prepare": "npm run build",
16
+ "trypublish": "npm publish || true"
10
17
  },
11
- "author": "Jarosław Żak",
12
- "license": "ISC",
13
18
  "devDependencies": {
14
- "typescript": "^4.6.3",
15
- "webpack-cli": "^4.9.2"
19
+ "@babel/cli": "^7.20.7",
20
+ "@babel/core": "^7.20.12",
21
+ "@babel/plugin-proposal-class-properties": "^7.16.0",
22
+ "@babel/plugin-transform-typescript": "^7.20.2",
23
+ "@babel/polyfill": "^7.12.1",
24
+ "@babel/preset-env": "^7.20.2",
25
+ "@types/jest": "^29.2.5",
26
+ "@typescript-eslint/eslint-plugin": "^4.33.0",
27
+ "@typescript-eslint/parser": "^4.33.0",
28
+ "babel-eslint": "^10.1.0",
29
+ "babel-loader": "^9.1.2",
30
+ "babel-preset-minify": "^0.5.2",
31
+ "css-loader": "^6.7.3",
32
+ "css-minimizer-webpack-plugin": "^4.2.2",
33
+ "eslint": "^7.32.0",
34
+ "file-loader": "^6.2.0",
35
+ "html-webpack-plugin": "^5.5.0",
36
+ "jest": "^29.3.1",
37
+ "mini-css-extract-plugin": "^2.7.2",
38
+ "style-loader": "^3.3.1",
39
+ "terser-webpack-plugin": "^5.3.5",
40
+ "typescript": "^4.9.4",
41
+ "url-loader": "^4.1.1",
42
+ "webpack": "^5.75.0",
43
+ "webpack-cli": "^5.0.1",
44
+ "webpack-dev-server": "4.11.1"
16
45
  },
17
- "dependencies": {
18
- "@types/uuid": "^8.3.4",
19
- "ts-loader": "^9.2.8",
20
- "uuid": "^8.3.2"
46
+ "jest": {
47
+ "moduleNameMapper": {
48
+ "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/scripts/testMock.js",
49
+ "\\.(css|less)$": "<rootDir>/scripts/testMock.js"
50
+ },
51
+ "moduleFileExtensions": [
52
+ "web.js",
53
+ "js",
54
+ "web.ts",
55
+ "ts",
56
+ "web.tsx",
57
+ "tsx",
58
+ "json",
59
+ "web.jsx",
60
+ "jsx",
61
+ "node"
62
+ ]
21
63
  }
22
64
  }
package/tsconfig.json CHANGED
@@ -1,12 +1,17 @@
1
1
  {
2
- "compilerOptions": {
3
- "target": "ES6",
4
- "module": "commonjs",
5
- "declaration": true,
6
- "outDir": "./dist",
7
- "strict": true,
8
- "strictPropertyInitialization": false,
9
- },
10
- "include": ["src"],
11
- "exclude": ["node_modules", "**/__tests__/*"]
2
+ "compilerOptions": {
3
+ "noImplicitAny": true,
4
+ "outDir": "build/types",
5
+ "module": "esnext",
6
+ "target": "es5",
7
+ "allowJs": true,
8
+ "sourceMap": true,
9
+ "declaration": true,
10
+ "emitDeclarationOnly": true,
11
+ "suppressImplicitAnyIndexErrors": true,
12
+ "lib": ["es2018", "dom"],
13
+ "moduleResolution": "node",
14
+ },
15
+ "include": ["src/lib"],
16
+ "exclude": ["src/lib/**/tests"],
12
17
  }
@@ -0,0 +1,47 @@
1
+ const MiniCssExtractPlugin = require("mini-css-extract-plugin");
2
+ const HtmlWebpackPlugin = require('html-webpack-plugin');
3
+
4
+ module.exports = {
5
+ mode: "development",
6
+ devtool: 'cheap-module-source-map',
7
+ entry: './src/demo/index.ts',
8
+ output: {
9
+ filename: 'index.js'
10
+ },
11
+ optimization: {
12
+ minimize: false,
13
+ },
14
+ devServer: {
15
+ open: true,
16
+ hot: true,
17
+ host: "localhost",
18
+ port: 9000
19
+ },
20
+ module: {
21
+ rules: [
22
+ {
23
+ test: /\.(m|j|t)s$/,
24
+ exclude: /(node_modules|bower_components)/,
25
+ use: {
26
+ loader: 'babel-loader'
27
+ }
28
+ },
29
+ {
30
+ test: /\.(sa|sc|c)ss$/,
31
+ use: [
32
+ MiniCssExtractPlugin.loader,
33
+ { loader: "css-loader", options: { sourceMap: true } },
34
+ ],
35
+ }
36
+ ]
37
+ },
38
+ plugins: [
39
+ new MiniCssExtractPlugin({
40
+ filename: 'css/index.css'
41
+ }),
42
+ new HtmlWebpackPlugin(),
43
+ ],
44
+ resolve: {
45
+ extensions: ['.ts', '.js', '.json']
46
+ }
47
+ };
package/src/Client.ts DELETED
@@ -1,166 +0,0 @@
1
- import {ConnectionEvent, ConnectionInterface} from "./connections/ConnectionInterface";
2
- import {EventTarget} from "./ObservableInterface";
3
- import {Envelope} from "./dtos/protocol/Envelope";
4
- import {JoinRoom} from "./dtos/protocol/commands/JoinRoom";
5
- import {Dto} from "./dtos/Dto";
6
- import {RoomJoined} from "./dtos/protocol/events/RoomJoined";
7
- import {LeaveRoom} from "./dtos/protocol/commands/LeaveRoom";
8
- import {RoomLeft} from "./dtos/protocol/events/RoomLeft";
9
- import {CreateRoom} from "./dtos/protocol/commands/CreateRoom";
10
- import {Error} from "./dtos/protocol/events/Error";
11
- import {SpaceRooms} from "./dtos/protocol/events/SpaceRooms";
12
- import {DeleteRoom} from "./dtos/protocol/commands/DeleteRoom";
13
- import {RoomDeleted} from "./dtos/protocol/events/RoomDeleted";
14
- import {GetRoomMembers} from "./dtos/protocol/commands/GetRoomMembers";
15
- import {RoomMembers} from "./dtos/protocol/events/RoomMembers";
16
- import {JoinSpace} from "./dtos/protocol/commands/JoinSpace";
17
- import {SpaceJoined} from "./dtos/protocol/events/SpaceJoined";
18
- import {LeaveSpace} from "./dtos/protocol/commands/LeaveSpace";
19
- import {SpaceLeft} from "./dtos/protocol/events/SpaceLeft";
20
- import {CreateSpace} from "./dtos/protocol/commands/CreateSpace";
21
- import {DeleteSpace} from "./dtos/protocol/commands/DeleteSpace";
22
- import {SpaceDeleted} from "./dtos/protocol/events/SpaceDeleted";
23
- import {GetSpaceMembers} from "./dtos/protocol/commands/GetSpaceMembers";
24
- import {SpaceMembers} from "./dtos/protocol/events/SpaceMembers";
25
- import {GetSpaceRooms} from "./dtos/protocol/commands/GetSpaceRooms";
26
- import {GetSession} from "./dtos/protocol/commands/GetSession";
27
- import {Session} from "./dtos/protocol/events/Session";
28
- import {AssignRole} from "./dtos/protocol/commands/AssignRole";
29
- import {SpaceMemberUpdate} from "./dtos/protocol/events/SpaceMemberUpdate";
30
- import {DeassignRole} from "./dtos/protocol/commands/DeassignRole";
31
- import {CreateRole} from "./dtos/protocol/commands/CreateRole";
32
- import {NewRole} from "./dtos/protocol/events/NewRole";
33
- import {DeleteRole} from "./dtos/protocol/commands/DeleteRole";
34
- import {RoleDeleted} from "./dtos/protocol/events/RoleDeleted";
35
- import {SetRolePermissions} from "./dtos/protocol/commands/SetRolePermissions";
36
- import {Permissions} from "./dtos/protocol/events/Permissions";
37
- import {SetUserPermissions} from "./dtos/protocol/commands/SetUserPermissions";
38
- import {CreateTopic} from "./dtos/protocol/commands/CreateTopic";
39
- import {NewTopic} from "./dtos/protocol/events/NewTopic";
40
- import {DeleteTopic} from "./dtos/protocol/commands/DeleteTopic";
41
- import {TopicDeleted} from "./dtos/protocol/events/TopicDeleted";
42
- import {CreateMessage} from "./dtos/protocol/commands/CreateMessage";
43
- import {NewMessage} from "./dtos/protocol/events/NewMessage";
44
- import {GetComputedPermissions} from "./dtos/protocol/commands/GetComputedPermissions";
45
- import {GetRolePermissions} from "./dtos/protocol/commands/GetRolePermissions";
46
- import {GetUserPermissions} from "./dtos/protocol/commands/GetUserPermissions";
47
- import {commands, events} from "./protocol";
48
-
49
- type ArrayOfPromiseResolvers = [(value: any) => void, (reason?: any) => void];
50
- type CmdResult<EventDto> = EventDto | Error;
51
- type CommandsToEventsType<CommandT> =
52
- // General commands
53
- CommandT extends GetSession ? CmdResult<Session> :
54
- CommandT extends SetUserPermissions ? CmdResult<Permissions> :
55
- CommandT extends GetUserPermissions ? CmdResult<Permissions> :
56
- CommandT extends GetComputedPermissions ? CmdResult<Permissions> :
57
- // Space commands
58
- CommandT extends JoinSpace ? CmdResult<SpaceJoined> :
59
- CommandT extends LeaveSpace ? CmdResult<SpaceLeft> :
60
- CommandT extends CreateSpace ? CmdResult<SpaceJoined> :
61
- CommandT extends DeleteSpace ? CmdResult<SpaceDeleted> :
62
- CommandT extends GetSpaceMembers ? CmdResult<SpaceMembers> :
63
- CommandT extends GetSpaceRooms ? CmdResult<SpaceRooms> :
64
- CommandT extends CreateRole ? CmdResult<NewRole> :
65
- CommandT extends DeleteRole ? CmdResult<RoleDeleted> :
66
- CommandT extends AssignRole ? CmdResult<SpaceMemberUpdate> :
67
- CommandT extends DeassignRole ? CmdResult<SpaceMemberUpdate> :
68
- CommandT extends SetRolePermissions ? CmdResult<Permissions> :
69
- CommandT extends GetRolePermissions ? CmdResult<Permissions> :
70
- // Room commands
71
- CommandT extends JoinRoom ? CmdResult<RoomJoined> :
72
- CommandT extends LeaveRoom ? CmdResult<RoomLeft> :
73
- CommandT extends CreateRoom ? CmdResult<RoomJoined> :
74
- CommandT extends DeleteRoom ? CmdResult<RoomDeleted> :
75
- CommandT extends GetRoomMembers ? CmdResult<RoomMembers> :
76
- // Topic commands
77
- CommandT extends CreateTopic ? CmdResult<NewTopic> :
78
- CommandT extends DeleteTopic ? CmdResult<TopicDeleted> :
79
- CommandT extends CreateMessage ? CmdResult<NewMessage> :
80
- any;
81
-
82
- function guessCommandType(obj: any): string {
83
- for (const type in commands) {
84
- if (obj instanceof commands[type]) {
85
- return type;
86
- }
87
- }
88
- return Object.getPrototypeOf(obj).constructor.name;
89
- }
90
-
91
- export class Client extends EventTarget {
92
- protected commandsCount = 0;
93
- protected awaitingResponse: Map<string, ArrayOfPromiseResolvers> = new Map<string, ArrayOfPromiseResolvers>();
94
- protected eventsMap: {[x: string]: typeof Dto};
95
-
96
- public constructor(private connection: ConnectionInterface) {
97
- super();
98
- this.setCustomEventMap({}); // Set default event map.
99
- this.connection.on(ConnectionEvent.message, payload => this.onMessage(payload));
100
- this.connection.on(ConnectionEvent.disconnect, () => this.onDisconnect());
101
- }
102
-
103
- /**
104
- * Send command to server.
105
- * @param commandPayload Command payload object.
106
- * @param commandType Command type; if not specified, it will be guessed from the command payload class name.
107
- * @return Promise which resolves to the event returned by server (including `Error`)
108
- * in response to command and rejects with connection error.
109
- */
110
- public async exec<CommandT extends Dto = any>(
111
- commandPayload: CommandT,
112
- commandType?: string
113
- ): Promise<CommandsToEventsType<CommandT>> {
114
- const message = this.createEnvelope(commandType ?? guessCommandType(commandPayload), commandPayload);
115
- this.connection.send(message.toJson());
116
- return new Promise(
117
- (...args) => this.awaitingResponse.set(message.meta.ref as string, args)
118
- );
119
- }
120
-
121
- /**
122
- * Set custom DTO classes for events.
123
- */
124
- public setCustomEventMap(customMap: {[x: string]: typeof Dto}): this {
125
- this.eventsMap = {...events, ...customMap};
126
- return this;
127
- }
128
-
129
- private onMessage(payload: string) {
130
- const message: Envelope = JSON.parse(payload);
131
- const dto = this.createEventByEnvelope(message);
132
-
133
- const [resolve] = this.awaitingResponse.get(message.meta.ref ?? '') ?? [];
134
- if (resolve) {
135
- resolve(dto ?? message.data);
136
- this.awaitingResponse.delete(message.meta.ref as string);
137
- }
138
-
139
- this.emit('message', message);
140
- this.emit(message.meta.type ?? 'unknown', message, dto);
141
- }
142
-
143
- private onDisconnect(): void {
144
- this.awaitingResponse.forEach(([resolve, reject], key: string) => {
145
- reject('Disconnected');
146
- this.awaitingResponse.delete(key);
147
- });
148
- }
149
-
150
- private createEnvelope(commandType: string, dto: Dto): Envelope {
151
- return new Envelope({
152
- meta: {
153
- type: commandType,
154
- ref: (++this.commandsCount).toString()
155
- },
156
- data: dto
157
- });
158
- }
159
-
160
- private createEventByEnvelope(message: Envelope): Dto | null {
161
- if ((message.meta.type ?? false) && this.eventsMap.hasOwnProperty(message.meta.type)) {
162
- return new (this.eventsMap[message.meta.type] as any)(message.data);
163
- }
164
- return null;
165
- }
166
- }
@@ -1,22 +0,0 @@
1
- export type EventHandler<T = any> = (...args: T[]) => void;
2
-
3
- export interface ObservableInterface {
4
- on(eventName: string, handler: EventHandler): ObservableInterface;
5
- }
6
-
7
- export abstract class EventTarget implements ObservableInterface {
8
- protected events: Map<string, EventHandler[]> = new Map<string, EventHandler[]>();
9
-
10
- public on(eventName: string, handler: EventHandler): EventTarget {
11
- const handlers = this.events.get(eventName) ?? [];
12
- handlers.push(handler);
13
- this.events.set(eventName, handlers);
14
- return this;
15
- }
16
-
17
- public emit(eventName: string, ...args: any): EventTarget
18
- {
19
- this.events.get(eventName)?.forEach(callback => callback(...args));
20
- return this;
21
- }
22
- }
package/src/Token.ts DELETED
@@ -1,21 +0,0 @@
1
- const apiUrl = 'https://polfan.pl/webservice/api/auth/token';
2
- const defaultClientName = 'Polfan JS Library';
3
-
4
- export interface TokenInterface {
5
- token: string,
6
- expiration: string
7
- }
8
-
9
- export async function getToken(login: string, password: string, clientName: string = defaultClientName): Promise<TokenInterface> {
10
- const response = await fetch(apiUrl, {
11
- method: 'POST',
12
- headers: {
13
- 'Content-Type': 'application/json',
14
- Accept: 'application/json'
15
- },
16
- body: JSON.stringify({
17
- login, password, client_name: clientName
18
- })
19
- });
20
- return response.json();
21
- }
@@ -1,20 +0,0 @@
1
- import {ObservableInterface} from "../ObservableInterface";
2
-
3
- export enum ConnectionState {
4
- pending,
5
- ready,
6
- disconnected
7
- }
8
-
9
- export enum ConnectionEvent {
10
- message = 'message',
11
- connect = 'connect',
12
- disconnect = 'disconnect'
13
- }
14
-
15
- export interface ConnectionInterface extends ObservableInterface {
16
- state: ConnectionState,
17
- connect(): void;
18
- disconnect(): void;
19
- send(data: string): void;
20
- }
@@ -1,43 +0,0 @@
1
- import {ConnectionEvent, ConnectionInterface, ConnectionState} from "./ConnectionInterface";
2
- import {EventTarget} from "../ObservableInterface";
3
-
4
- export interface WebApiConnectionConfig {
5
- token: string;
6
- url: string;
7
- }
8
-
9
- export class WebApiConnection extends EventTarget implements ConnectionInterface {
10
- public state: ConnectionState = ConnectionState.ready;
11
-
12
- public constructor(
13
- private readonly config: WebApiConnectionConfig
14
- ) {
15
- super();
16
- }
17
-
18
- public connect(): void {
19
- this.emit(ConnectionEvent.connect);
20
- }
21
-
22
- public disconnect(): void {
23
- this.emit(ConnectionEvent.disconnect);
24
- }
25
-
26
- public send(data: string): void {
27
- fetch(this.config.url, {
28
- method: 'POST',
29
- headers: {
30
- Authorization: `Bearer ${this.config.token}`,
31
- ContentType: 'application/json',
32
- Accept: 'application/json'
33
- },
34
- body: JSON.stringify(data)
35
- })
36
- .then((response: Response) => response.text())
37
- .then(this.onMessage);
38
- }
39
-
40
- private onMessage(message: string): void {
41
- this.emit(ConnectionEvent.message, message);
42
- }
43
- }
@@ -1,47 +0,0 @@
1
- import {EventTarget} from "../ObservableInterface";
2
- import {ConnectionEvent, ConnectionInterface, ConnectionState} from "./ConnectionInterface";
3
-
4
- interface WebSocketConnectionConfig {
5
- url: string;
6
- token: string;
7
- }
8
-
9
- export class WebSocketConnection extends EventTarget implements ConnectionInterface {
10
- public state: ConnectionState = ConnectionState.disconnected;
11
-
12
- private ws: WebSocket|null = null;
13
-
14
- public constructor(private config: WebSocketConnectionConfig) {
15
- super();
16
- }
17
-
18
- public connect(): void {
19
- this.ws = new WebSocket(`${this.config.url}?token=${this.config.token}`);
20
- this.ws.onopen = () => this.onOpen();
21
- this.ws.onclose = () => this.onClose();
22
- this.ws.onerror = () => this.onClose();
23
- this.ws.onmessage = ev => this.onMessage(ev);
24
- }
25
-
26
- public disconnect(): void {
27
- this.ws?.close();
28
- }
29
-
30
- public send(data: string): void {
31
- this.ws?.send(data);
32
- }
33
-
34
- private onMessage(event: MessageEvent): void {
35
- this.emit(ConnectionEvent.message, event.data);
36
- }
37
-
38
- private onClose(): void {
39
- this.state = ConnectionState.disconnected;
40
- this.emit(ConnectionEvent.disconnect);
41
- }
42
-
43
- private onOpen(): void {
44
- this.state = ConnectionState.ready;
45
- this.emit(ConnectionEvent.connect);
46
- }
47
- }
package/src/dtos/Dto.ts DELETED
@@ -1,45 +0,0 @@
1
- export function cast<T extends typeof Dto>(data: any, dto: T): T {
2
- if (data instanceof dto) {
3
- return data as any;
4
- }
5
- return new (dto as any)(data);
6
- }
7
-
8
- export function castArray<T extends typeof Dto>(data: any[], dto: T): T[] {
9
- if (!Array.isArray(data)) throw new Error(`Passed data is not an array of ${dto.name}`);
10
- return data.map(item => cast(item, dto));
11
- }
12
-
13
- type ExcludeMethods<T> = Pick<T, { [K in keyof T]: T[K] extends Function ? never : K }[keyof T]>;
14
- export type DtoData<T> = { [K in keyof ExcludeMethods<T>]: any };
15
-
16
- export abstract class Dto {
17
- public constructor(...args: any[]) {
18
- }
19
-
20
- public toJson(overrideBy: any = {}): string {
21
- return JSON.stringify(this.toRaw(overrideBy));
22
- }
23
-
24
- public toRaw(overrideBy: any = {}): DtoData<this> {
25
- const object: {[key: string]: any} = {};
26
- Object.keys(this).forEach(key => {
27
- if (overrideBy.hasOwnProperty(key)) {
28
- object[key] = overrideBy[key];
29
- } else if ((this as any)[key] instanceof Dto) {
30
- object[key] = (this as any)[key].toRaw();
31
- } else {
32
- object[key] = (this as any)[key]
33
- }
34
- });
35
- return object as DtoData<this>;
36
- }
37
-
38
- public clone(overrideBy: any = {}): this {
39
- return new (this.constructor as any)(this.toRaw(overrideBy));
40
- }
41
-
42
- protected fill(data: any, overrideBy: any = {}) {
43
- Object.assign(this, {...data, ...overrideBy});
44
- }
45
- }
@@ -1,16 +0,0 @@
1
- import {cast, Dto, DtoData} from "./Dto";
2
- import {User} from "./User";
3
-
4
- export class Message extends Dto {
5
- public readonly id: string;
6
- public readonly author: User;
7
- public readonly topicId: string;
8
- public readonly content: string;
9
-
10
- public constructor(data: DtoData<Message>) {
11
- super();
12
- this.fill(data, {
13
- author: cast(data.author, User),
14
- });
15
- }
16
- }
@@ -1,12 +0,0 @@
1
- import {Dto, DtoData} from "./Dto";
2
-
3
- export class Permission extends Dto {
4
- public readonly name: string;
5
- public readonly value: boolean;
6
- public readonly skip: boolean;
7
-
8
- public constructor(data: DtoData<Permission>) {
9
- super(data);
10
- this.fill(data);
11
- }
12
- }
package/src/dtos/Role.ts DELETED
@@ -1,12 +0,0 @@
1
- import {Dto, DtoData} from "./Dto";
2
-
3
- export class Role extends Dto {
4
- public readonly id: string;
5
- public readonly name: string;
6
- public readonly color?: string;
7
-
8
- public constructor(data: DtoData<Role>) {
9
- super();
10
- this.fill(data);
11
- }
12
- }
package/src/dtos/Room.ts DELETED
@@ -1,15 +0,0 @@
1
- import {castArray, Dto, DtoData} from "./Dto";
2
- import {Topic} from "./Topic";
3
-
4
- export class Room extends Dto {
5
- public readonly id: string;
6
- public readonly name: string;
7
- public readonly topics: Topic[];
8
-
9
- public constructor(data: DtoData<Room>) {
10
- super();
11
- this.fill(data, {
12
- topics: castArray(data.topics, Topic),
13
- });
14
- }
15
- }
@@ -1,13 +0,0 @@
1
- import {cast, Dto, DtoData} from "./Dto";
2
- import {User} from "./User";
3
-
4
- export class RoomMember extends Dto {
5
- public readonly user: User;
6
-
7
- public constructor(data: DtoData<RoomMember>) {
8
- super();
9
- this.fill(data, {
10
- user: cast(data.user, User),
11
- });
12
- }
13
- }
@@ -1,12 +0,0 @@
1
- import {Dto, DtoData} from "./Dto";
2
-
3
- export class RoomSummary extends Dto {
4
- public readonly id: string;
5
- public readonly name: string;
6
- public readonly description: string;
7
-
8
- public constructor(data: DtoData<RoomSummary>) {
9
- super();
10
- this.fill(data);
11
- }
12
- }
package/src/dtos/Space.ts DELETED
@@ -1,15 +0,0 @@
1
- import {castArray, Dto, DtoData} from "./Dto";
2
- import {Role} from "./Role";
3
-
4
- export class Space extends Dto {
5
- public readonly id: string;
6
- public readonly name: string;
7
- public readonly roles: Role[];
8
-
9
- public constructor(data: DtoData<Space>) {
10
- super();
11
- this.fill(data, {
12
- roles: castArray(data.roles, Role)
13
- });
14
- }
15
- }