@eleven-am/pondsocket 0.1.11 → 0.1.13

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 (90) hide show
  1. package/dist/client/channel.js +200 -0
  2. package/dist/client/index.d.ts +122 -0
  3. package/{pondClient/socket.js → dist/client/index.js} +30 -44
  4. package/dist/express/index.d.ts +36 -0
  5. package/dist/express/index.js +16 -0
  6. package/dist/index.d.ts +340 -0
  7. package/dist/index.js +4 -0
  8. package/dist/server/abstracts/abstractRequest.js +40 -0
  9. package/dist/server/abstracts/abstractRequest.test.js +41 -0
  10. package/dist/server/abstracts/abstractResponse.js +6 -0
  11. package/dist/server/abstracts/middleware.js +38 -0
  12. package/dist/server/abstracts/middleware.test.js +70 -0
  13. package/dist/server/channel/channelEngine.js +279 -0
  14. package/dist/server/channel/channelEngine.test.js +377 -0
  15. package/dist/server/channel/channelRequest.test.js +29 -0
  16. package/dist/server/channel/channelResponse.test.js +134 -0
  17. package/dist/server/channel/eventRequest.js +18 -0
  18. package/dist/server/channel/eventResponse.js +141 -0
  19. package/dist/server/endpoint/connectionResponse.js +50 -0
  20. package/dist/server/endpoint/endpoint.js +269 -0
  21. package/dist/server/endpoint/endpoint.test.js +406 -0
  22. package/dist/server/endpoint/endpointResponse.test.js +43 -0
  23. package/dist/server/pondChannel/joinRequest.js +29 -0
  24. package/dist/server/pondChannel/joinResponse.js +96 -0
  25. package/dist/server/pondChannel/pondChannel.js +161 -0
  26. package/dist/server/pondChannel/pondChannelResponse.test.js +108 -0
  27. package/dist/server/presence/presenceEngine.js +112 -0
  28. package/dist/server/presence/presenceEngine.test.js +104 -0
  29. package/dist/server/server/pondSocket.js +122 -0
  30. package/{pondSocket → dist/server/server}/server.test.js +7 -21
  31. package/{pondBase/baseClass.js → dist/server/utils/matchPattern.js} +33 -43
  32. package/{pondBase/baseClass.test.js → dist/server/utils/matchPattern.test.js} +16 -25
  33. package/dist/server/utils/subjectUtils.js +68 -0
  34. package/package.json +31 -12
  35. package/.eslintrc.js +0 -28
  36. package/base.d.ts +0 -1
  37. package/base.js +0 -17
  38. package/client.d.ts +0 -1
  39. package/client.js +0 -17
  40. package/index.d.ts +0 -1
  41. package/index.js +0 -17
  42. package/jest.config.js +0 -11
  43. package/pondBase/baseClass.d.ts +0 -55
  44. package/pondBase/enums.d.ts +0 -9
  45. package/pondBase/enums.js +0 -14
  46. package/pondBase/index.d.ts +0 -6
  47. package/pondBase/index.js +0 -22
  48. package/pondBase/pondBase.d.ts +0 -41
  49. package/pondBase/pondBase.js +0 -60
  50. package/pondBase/pondBase.test.js +0 -101
  51. package/pondBase/pubSub.d.ts +0 -82
  52. package/pondBase/pubSub.js +0 -158
  53. package/pondBase/pubSub.test.js +0 -332
  54. package/pondBase/simpleBase.d.ts +0 -126
  55. package/pondBase/simpleBase.js +0 -211
  56. package/pondBase/simpleBase.test.js +0 -153
  57. package/pondBase/types.d.ts +0 -2
  58. package/pondBase/types.js +0 -2
  59. package/pondClient/channel.d.ts +0 -77
  60. package/pondClient/channel.js +0 -167
  61. package/pondClient/index.d.ts +0 -2
  62. package/pondClient/index.js +0 -18
  63. package/pondClient/socket.d.ts +0 -41
  64. package/pondSocket/channel.d.ts +0 -129
  65. package/pondSocket/channel.js +0 -287
  66. package/pondSocket/channel.test.js +0 -377
  67. package/pondSocket/channelMiddleWare.d.ts +0 -28
  68. package/pondSocket/channelMiddleWare.js +0 -36
  69. package/pondSocket/endpoint.d.ts +0 -90
  70. package/pondSocket/endpoint.js +0 -320
  71. package/pondSocket/endpoint.test.js +0 -490
  72. package/pondSocket/enums.d.ts +0 -19
  73. package/pondSocket/enums.js +0 -25
  74. package/pondSocket/index.d.ts +0 -7
  75. package/pondSocket/index.js +0 -23
  76. package/pondSocket/pondChannel.d.ts +0 -79
  77. package/pondSocket/pondChannel.js +0 -211
  78. package/pondSocket/pondChannel.test.js +0 -430
  79. package/pondSocket/pondResponse.d.ts +0 -25
  80. package/pondSocket/pondResponse.js +0 -120
  81. package/pondSocket/pondSocket.d.ts +0 -47
  82. package/pondSocket/pondSocket.js +0 -94
  83. package/pondSocket/socketMiddleWare.d.ts +0 -6
  84. package/pondSocket/socketMiddleWare.js +0 -32
  85. package/pondSocket/types.d.ts +0 -74
  86. package/pondSocket/types.js +0 -2
  87. package/socket.d.ts +0 -1
  88. package/socket.js +0 -17
  89. package/tsconfig.eslint.json +0 -5
  90. package/tsconfig.json +0 -90
@@ -1,53 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseClass = void 0;
4
- class BaseClass {
5
- /**
6
- * @desc checks if the pattern is matchable
7
- * @param pattern - the pattern to check
8
- */
9
- static isPatternMatchable(pattern) {
10
- return typeof pattern === 'string' && pattern.includes(':');
11
- }
12
- /**
13
- * @desc compares string to string | regex
14
- * @param string - the string to compare to the pattern
15
- * @param pattern - the pattern to compare to the string
16
- */
17
- compareStringToPattern(string, pattern) {
18
- if (typeof pattern === 'string')
19
- return string.split('?')[0] === pattern;
20
- else
21
- return pattern.test(string);
22
- }
23
- /**
24
- * @desc Checks if the given object is empty
25
- * @param obj - the object to check
26
- */
27
- isObjectEmpty(obj) {
28
- return Object.keys(obj).length === 0;
29
- }
3
+ exports.MatchPattern = void 0;
4
+ class MatchPattern {
30
5
  /**
31
6
  * @desc Generates a pond request resolver object
32
7
  * @param path - the path to resolve
33
8
  * @param address - the address to resolve
34
9
  */
35
- generateEventRequest(path, address) {
10
+ parseEvent(path, address) {
36
11
  const match = this._matchStringToPattern(address, path);
37
- if (match)
12
+ if (match) {
38
13
  return {
39
- params: match, query: this._parseQueries(address), address: address
14
+ params: match,
15
+ address,
16
+ query: this._parseQueries(address),
40
17
  };
18
+ }
41
19
  return null;
42
20
  }
43
- /**
44
- * @desc Compares if two objects are equal
45
- * @param obj1 - the first object
46
- * @param obj2 - the second object
47
- */
48
- areEqual(obj1, obj2) {
49
- return JSON.stringify(obj1) === JSON.stringify(obj2);
50
- }
51
21
  /**
52
22
  * @desc Creates an object from the params of a path
53
23
  * @param path - the path to create the object from
@@ -60,13 +30,31 @@ class BaseClass {
60
30
  const obj = {};
61
31
  const params = path.split('?')[1];
62
32
  if (params) {
63
- params.split('&').forEach(param => {
33
+ params.split('&').forEach((param) => {
64
34
  const [key, value] = param.split('=');
65
35
  obj[key] = value;
66
36
  });
67
37
  }
68
38
  return obj;
69
39
  }
40
+ /**
41
+ * @desc checks if the pattern is matchable
42
+ * @param pattern - the pattern to check
43
+ */
44
+ _isPatternMatchable(pattern) {
45
+ return typeof pattern === 'string' && pattern.includes(':');
46
+ }
47
+ /**
48
+ * @desc compares string to string | regex
49
+ * @param string - the string to compare to the pattern
50
+ * @param pattern - the pattern to compare to the string
51
+ */
52
+ _compareStringToPattern(string, pattern) {
53
+ if (typeof pattern === 'string') {
54
+ return string.split('?')[0] === pattern;
55
+ }
56
+ return pattern.test(string);
57
+ }
70
58
  /**
71
59
  * @desc Returns the {key: value} matches of a string
72
60
  * @param string - the string to create the regex from
@@ -100,12 +88,14 @@ class BaseClass {
100
88
  * @param pattern - the pattern to match to
101
89
  */
102
90
  _matchStringToPattern(string, pattern) {
103
- if (BaseClass.isPatternMatchable(pattern))
91
+ if (this._isPatternMatchable(pattern)) {
104
92
  return this._matchString(string, pattern);
105
- const valid = this.compareStringToPattern(string, pattern);
106
- if (valid)
93
+ }
94
+ const valid = this._compareStringToPattern(string, pattern);
95
+ if (valid) {
107
96
  return {};
97
+ }
108
98
  return null;
109
99
  }
110
100
  }
111
- exports.BaseClass = BaseClass;
101
+ exports.MatchPattern = MatchPattern;
@@ -1,25 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const baseClass_1 = require("./baseClass");
3
+ const matchPattern_1 = require("./matchPattern");
4
4
  describe('BaseClass', () => {
5
- const baseClass = new baseClass_1.BaseClass();
6
- it('should return true when object is empty', () => {
7
- expect(baseClass.isObjectEmpty({})).toBe(true);
8
- });
9
- it('should return false when object is not empty', () => {
10
- expect(baseClass.isObjectEmpty({ test: 5 })).toBe(false);
11
- });
5
+ const baseClass = new matchPattern_1.MatchPattern();
12
6
  it('should return true if a string matches a regex | string', () => {
13
7
  const regex = new RegExp(/^test/);
14
- expect(baseClass.compareStringToPattern('test', regex)).toBe(true);
8
+ expect(baseClass['_compareStringToPattern']('test', regex)).toBe(true);
15
9
  const string = 'test';
16
- expect(baseClass.compareStringToPattern('test', string)).toBe(true);
10
+ expect(baseClass['_compareStringToPattern']('test', string)).toBe(true);
17
11
  });
18
12
  it('should return false if a string does not match a regex | string', () => {
19
13
  const regex = new RegExp(/^test$/);
20
- expect(baseClass.compareStringToPattern('test2', regex)).toBe(false);
14
+ expect(baseClass['_compareStringToPattern']('test2', regex)).toBe(false);
21
15
  const string = 'test';
22
- expect(baseClass.compareStringToPattern('test2', string)).toBe(false);
16
+ expect(baseClass['_compareStringToPattern']('test2', string)).toBe(false);
23
17
  });
24
18
  it('should return the params of a string matching the pattern', () => {
25
19
  const pattern = '/test/:id';
@@ -27,12 +21,13 @@ describe('BaseClass', () => {
27
21
  const string = '/test/5';
28
22
  const secondString = '/test/5/6';
29
23
  expect(baseClass['_matchString'](string, pattern)).toEqual({ id: '5' });
30
- expect(baseClass['_matchString'](secondString, secondPattern)).toEqual({ id: '5', id2: '6' });
24
+ expect(baseClass['_matchString'](secondString, secondPattern)).toEqual({ id: '5',
25
+ id2: '6' });
31
26
  // this function fails if the pattern is not a string or regex
32
27
  expect(baseClass['_matchString'](secondString, pattern)).toEqual(null);
33
28
  // But will return null if the string is smaller than the pattern
34
29
  expect(baseClass['_matchString'](string, secondPattern)).toEqual(null);
35
- //it should also match patterns without the slash
30
+ // it should also match patterns without the slash
36
31
  const thirdPattern = 'test:id';
37
32
  const thirdString = 'test5';
38
33
  expect(baseClass['_matchString'](thirdString, thirdPattern)).toEqual({ id: '5' });
@@ -41,13 +36,8 @@ describe('BaseClass', () => {
41
36
  const string = '/test/5?test=5';
42
37
  const secondString = '/test/5?test=5&test2=6';
43
38
  expect(baseClass['_parseQueries'](string)).toEqual({ test: '5' });
44
- expect(baseClass['_parseQueries'](secondString)).toEqual({ test: '5', test2: '6' });
45
- });
46
- it('should return true if an object matches another object', () => {
47
- const object = { test: 5 };
48
- const secondObject = { test: 5, test2: 6 };
49
- expect(baseClass.areEqual(object, object)).toBe(true);
50
- expect(baseClass.areEqual(object, secondObject)).toBe(false);
39
+ expect(baseClass['_parseQueries'](secondString)).toEqual({ test: '5',
40
+ test2: '6' });
51
41
  });
52
42
  it('should return null if the string does not match the pattern', () => {
53
43
  const pattern = 'pondSocket';
@@ -62,12 +52,13 @@ describe('BaseClass', () => {
62
52
  it('should generateEventRequest', () => {
63
53
  const pattern = 'pondSocket:test';
64
54
  const string = 'pondSockethello?test=5&test2=6';
65
- expect(baseClass.generateEventRequest(pattern, string)).toEqual({
55
+ expect(baseClass.parseEvent(pattern, string)).toEqual({
66
56
  address: string,
67
57
  params: { test: 'hello' },
68
- query: { test: '5', test2: '6' }
58
+ query: { test: '5',
59
+ test2: '6' },
69
60
  });
70
- const unMatchingString = 'pondXocket2hello?test=5&test2=6';
71
- expect(baseClass.generateEventRequest(pattern, unMatchingString)).toEqual(null);
61
+ const unMatchingString = 'pondocket2hello?test=5&test2=6';
62
+ expect(baseClass.parseEvent(pattern, unMatchingString)).toEqual(null);
72
63
  });
73
64
  });
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ // A Subject CLASS that sends a message to all subscribers
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.SimpleBehaviorSubject = exports.SimpleSubject = exports.BehaviorSubject = exports.Subject = void 0;
5
+ class Subject {
6
+ constructor() {
7
+ this._observers = new Map();
8
+ }
9
+ subscribe(identifier, observer) {
10
+ this._observers.set(identifier, observer);
11
+ }
12
+ next(message) {
13
+ this._observers.forEach((observer) => observer(message));
14
+ }
15
+ unsubscribe(identifier) {
16
+ this._observers.delete(identifier);
17
+ }
18
+ }
19
+ exports.Subject = Subject;
20
+ // A behavior subject CLASS that sends the last message to new subscribers
21
+ class BehaviorSubject extends Subject {
22
+ next(message) {
23
+ this._lastMessage = message;
24
+ super.next(message);
25
+ }
26
+ subscribe(identifier, observer) {
27
+ if (this._lastMessage) {
28
+ observer(this._lastMessage);
29
+ }
30
+ return super.subscribe(identifier, observer);
31
+ }
32
+ }
33
+ exports.BehaviorSubject = BehaviorSubject;
34
+ // Simple Subject CLASS
35
+ class SimpleSubject {
36
+ constructor() {
37
+ this._observers = new Set();
38
+ }
39
+ subscribe(observer) {
40
+ this._observers.add(observer);
41
+ return () => this._observers.delete(observer);
42
+ }
43
+ publish(message) {
44
+ this._observers.forEach((observer) => observer(message));
45
+ }
46
+ }
47
+ exports.SimpleSubject = SimpleSubject;
48
+ // Simple BehaviorSubject CLASS
49
+ class SimpleBehaviorSubject extends SimpleSubject {
50
+ constructor(initialValue) {
51
+ super();
52
+ this._lastMessage = initialValue;
53
+ }
54
+ get value() {
55
+ return this._lastMessage;
56
+ }
57
+ publish(message) {
58
+ this._lastMessage = message;
59
+ super.publish(message);
60
+ }
61
+ subscribe(observer) {
62
+ if (this._lastMessage) {
63
+ observer(this._lastMessage);
64
+ }
65
+ return super.subscribe(observer);
66
+ }
67
+ }
68
+ exports.SimpleBehaviorSubject = SimpleBehaviorSubject;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eleven-am/pondsocket",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "PondSocket is a fast simple socket server",
5
5
  "keywords": [
6
6
  "socket",
@@ -16,32 +16,51 @@
16
16
  "access": "public"
17
17
  },
18
18
  "scripts": {
19
- "test": "jest --coverage",
19
+ "test": "jest --coverage --verbose --watchAll",
20
20
  "build": "tsc"
21
21
  },
22
22
  "author": "Roy OSSAI",
23
23
  "license": "GPL-3.0",
24
- "main": "./index.js",
25
- "types": "./index.d.ts",
24
+ "main": "dist/index.js",
25
+ "types": "dist/index.d.ts",
26
+ "files": [
27
+ "dist/**/*"
28
+ ],
26
29
  "repository": {
27
30
  "type": "git",
28
31
  "url": "git+https://github.com/Eleven-am/pondSocket.git"
29
32
  },
30
33
  "dependencies": {
31
- "ws": "^8.8.1"
34
+ "ws": "^8.12.0"
35
+ },
36
+ "exports": {
37
+ ".": "./dist/index.js",
38
+ "./express": "./dist/express/index.js",
39
+ "./client": "./dist/client/index.js"
40
+ },
41
+ "typesVersions": {
42
+ "*": {
43
+ "express/*": [
44
+ "dist/express/*"
45
+ ],
46
+ "client/*": [
47
+ "dist/client/*"
48
+ ]
49
+ }
32
50
  },
33
51
  "devDependencies": {
34
- "@types/jest": "^29.1.2",
52
+ "@types/express": "^4.17.14",
53
+ "@types/jest": "^29.5.0",
35
54
  "@types/node": "^16.10.3",
36
55
  "@types/ws": "^8.5.3",
37
- "@typescript-eslint/eslint-plugin": "^5.40.1",
38
- "@typescript-eslint/parser": "^5.40.1",
39
- "eslint": "^8.25.0",
56
+ "@typescript-eslint/eslint-plugin": "^5.58.0",
57
+ "eslint": "^8.38.0",
58
+ "eslint-plugin-file-progress": "^1.3.0",
59
+ "eslint-plugin-import": "^2.27.5",
40
60
  "jest": "^29.0.1",
41
- "process": "^0.11.10",
42
61
  "superwstest": "^2.0.3",
43
- "ts-jest": "^29.0.3",
62
+ "ts-jest": "^29.1.0",
44
63
  "ts-node": "^10.9.1",
45
- "typescript": "^4.8.4"
64
+ "typescript": "^4.9.4"
46
65
  }
47
66
  }
package/.eslintrc.js DELETED
@@ -1,28 +0,0 @@
1
- module.exports = {
2
- extends: [
3
- 'eslint:recommended',
4
- 'plugin:@typescript-eslint/recommended',
5
- 'plugin:@typescript-eslint/recommended-requiring-type-checking',
6
- ],
7
- parser: '@typescript-eslint/parser',
8
- parserOptions: {
9
- sourceType: "module",
10
- tsconfigRootDir: __dirname,
11
- project: ["./tsconfig.json"],
12
- },
13
- plugins: ['@typescript-eslint'],
14
- root: true,
15
- env: {
16
- node: true
17
- },
18
- rules: {
19
- '@typescript-eslint/no-explicit-any': 'off',
20
- '@typescript-eslint/no-unsafe-assignment': 'off',
21
- '@typescript-eslint/no-unsafe-argument': 'off',
22
- '@typescript-eslint/no-unsafe-call': 'off',
23
- '@typescript-eslint/no-unsafe-member-access': 'off',
24
- '@typescript-eslint/restrict-template-expressions': 'off',
25
- '@typescript-eslint/no-misused-promises': 'off',
26
- 'no-case-declarations': 'off',
27
- }
28
- };
package/base.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './pondBase';
package/base.js DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./pondBase"), exports);
package/client.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './pondClient';
package/client.js DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./pondClient"), exports);
package/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './pondSocket';
package/index.js DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./pondSocket"), exports);
package/jest.config.js DELETED
@@ -1,11 +0,0 @@
1
- module.exports = {
2
- transform: {
3
- '^.+\\.ts?$': 'ts-jest',
4
- },
5
- moduleFileExtensions: ['ts', 'js', 'json', 'node', 'd.ts'],
6
- collectCoverage: true,
7
- collectCoverageFrom: [
8
- "src/**/*.{js,jsx,ts,tsx}",
9
- "!src/**/*.d.ts"
10
- ],
11
- };
@@ -1,55 +0,0 @@
1
- import {default_t, PondPath} from "./types";
2
-
3
- export interface Resolver {
4
- params: default_t<string>;
5
- query: default_t<string>;
6
- address: string;
7
- }
8
-
9
- export declare class BaseClass {
10
-
11
- /**
12
- * @desc checks if the pattern is matchable
13
- * @param pattern - the pattern to check
14
- */
15
- protected static isPatternMatchable(pattern: string | RegExp): boolean;
16
-
17
- /**
18
- * @desc compares string to string | regex
19
- * @param string - the string to compare to the pattern
20
- * @param pattern - the pattern to compare to the string
21
- */
22
- compareStringToPattern(string: string, pattern: string | RegExp): boolean;
23
-
24
- /**
25
- * @desc Checks if the given object is empty
26
- * @param obj - the object to check
27
- */
28
- isObjectEmpty(obj: object): boolean;
29
-
30
- /**
31
- * @desc Generates a pond request resolver object
32
- * @param path - the path to resolve
33
- * @param address - the address to resolve
34
- */
35
- generateEventRequest(path: PondPath, address: string): Resolver | null;
36
-
37
- /**
38
- * @desc Compares if two objects are equal
39
- * @param obj1 - the first object
40
- * @param obj2 - the second object
41
- */
42
- areEqual<T>(obj1: T, obj2: T): boolean;
43
-
44
- /**
45
- * @desc Creates an object from the params of a path
46
- * @param path - the path to create the object from
47
- *
48
- * @example
49
- * /api/id?name=abc should return { name: 'abc' }
50
- * /api/id?name=abc&age=123 should return { name: 'abc', age: '123' }
51
- */
52
- protected _parseQueries(path: string): {
53
- [p: string]: string;
54
- };
55
- }
@@ -1,9 +0,0 @@
1
- export declare enum ResponsePicker {
2
- POND = "POND",
3
- CHANNEL = "CHANNEL"
4
- }
5
- export declare enum PondBaseActions {
6
- ADD_TO_POND = "ADD_TO_POND",
7
- REMOVE_FROM_POND = "REMOVE_FROM_POND",
8
- UPDATE_IN_POND = "UPDATE_IN_POND"
9
- }
package/pondBase/enums.js DELETED
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PondBaseActions = exports.ResponsePicker = void 0;
4
- var ResponsePicker;
5
- (function (ResponsePicker) {
6
- ResponsePicker["POND"] = "POND";
7
- ResponsePicker["CHANNEL"] = "CHANNEL";
8
- })(ResponsePicker = exports.ResponsePicker || (exports.ResponsePicker = {}));
9
- var PondBaseActions;
10
- (function (PondBaseActions) {
11
- PondBaseActions["ADD_TO_POND"] = "ADD_TO_POND";
12
- PondBaseActions["REMOVE_FROM_POND"] = "REMOVE_FROM_POND";
13
- PondBaseActions["UPDATE_IN_POND"] = "UPDATE_IN_POND";
14
- })(PondBaseActions = exports.PondBaseActions || (exports.PondBaseActions = {}));
@@ -1,6 +0,0 @@
1
- export * from './baseClass';
2
- export * from './pondBase';
3
- export * from './pubSub';
4
- export * from './types';
5
- export * from './enums';
6
- export * from './simpleBase';
package/pondBase/index.js DELETED
@@ -1,22 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./baseClass"), exports);
18
- __exportStar(require("./pondBase"), exports);
19
- __exportStar(require("./pubSub"), exports);
20
- __exportStar(require("./types"), exports);
21
- __exportStar(require("./enums"), exports);
22
- __exportStar(require("./simpleBase"), exports);
@@ -1,41 +0,0 @@
1
- import {Subscription} from "./pubSub";
2
- import {SimpleBase} from "./simpleBase";
3
- import {PondBaseActions} from "./enums";
4
-
5
- declare type ExtractSameValueType<A, B, C extends keyof A> = {
6
- [K in keyof B]: B[K] extends A[C] ? A[C] extends B[K] ? K : never : never;
7
- }[keyof B];
8
-
9
- export declare class PondBase<T> extends SimpleBase<T> {
10
-
11
- constructor();
12
-
13
- /**
14
- * @des Generate a key for a new document
15
- */
16
- private get _nanoid();
17
-
18
- /**
19
- * @desc Subscribe to the database
20
- * @param handler - The handler to call when the database is updated
21
- */
22
- subscribe(handler: (docs: T[], change: T | null, action: PondBaseActions) => void): Subscription;
23
-
24
- /**
25
- * @desc Add a document to the database
26
- * @param doc - The document to add
27
- */
28
- addDoc(doc: T): import("./simpleBase").PondDocument<T>;
29
-
30
- /**
31
- * @desc Left join two ponds on a key on this pond and a foreign key on the other pond
32
- * @param pond - The pond to join with
33
- * @param key - The key to join on
34
- * @param foreignKey - The foreign key to join on
35
- */
36
- leftJoin<U, A extends keyof T, B extends ExtractSameValueType<T, U, A>>(pond: PondBase<U>, key: A, foreignKey: B): PondBase<T & {
37
- [K in A]: U | null;
38
- }>;
39
- }
40
-
41
- export {};
@@ -1,60 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PondBase = void 0;
4
- const pubSub_1 = require("./pubSub");
5
- const simpleBase_1 = require("./simpleBase");
6
- const enums_1 = require("./enums");
7
- class PondBase extends simpleBase_1.SimpleBase {
8
- constructor() {
9
- const broadcast = new pubSub_1.Broadcast();
10
- super((data) => broadcast.publish(data));
11
- this._broadcast = broadcast;
12
- }
13
- /**
14
- * @des Generate a key for a new document
15
- */
16
- get _nanoid() {
17
- let id = '';
18
- const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
19
- for (let i = 0; i < 21; i++) {
20
- id += chars.charAt(Math.floor(Math.random() * chars.length));
21
- }
22
- return id;
23
- }
24
- /**
25
- * @desc Subscribe to the database
26
- * @param handler - The handler to call when the database is updated
27
- */
28
- subscribe(handler) {
29
- return this._broadcast.subscribe((data) => {
30
- let change = enums_1.PondBaseActions.UPDATE_IN_POND;
31
- if (data.oldValue === null)
32
- change = enums_1.PondBaseActions.ADD_TO_POND;
33
- else if (data.currentValue === null)
34
- change = enums_1.PondBaseActions.REMOVE_FROM_POND;
35
- handler(Object.values(this._getDB()), data.currentValue || data.oldValue, change);
36
- });
37
- }
38
- /**
39
- * @desc Add a document to the database
40
- * @param doc - The document to add
41
- */
42
- addDoc(doc) {
43
- return super.set(this._nanoid, doc);
44
- }
45
- /**
46
- * @desc Left join two ponds on a key on this pond and a foreign key on the other pond
47
- * @param pond - The pond to join with
48
- * @param key - The key to join on
49
- * @param foreignKey - The foreign key to join on
50
- */
51
- leftJoin(pond, key, foreignKey) {
52
- const newPond = new PondBase();
53
- for (const doc of this) {
54
- const foreignDoc = pond.find((d) => d[foreignKey] === doc.doc[key]);
55
- newPond.set(doc.id, Object.assign(Object.assign({}, doc.doc), { [key]: (foreignDoc === null || foreignDoc === void 0 ? void 0 : foreignDoc.doc) || null }));
56
- }
57
- return newPond;
58
- }
59
- }
60
- exports.PondBase = PondBase;