kozz-module-maker 0.1.21 → 0.2.0

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 (125) hide show
  1. package/.babelrc +24 -0
  2. package/bun.lock +617 -0
  3. package/dist/InlineCommands/index.js +19 -11
  4. package/dist/Instance/Basic/index.d.ts +40 -0
  5. package/dist/Instance/Basic/index.js +43 -0
  6. package/dist/Instance/Basic/index.js.map +1 -0
  7. package/dist/Instance/BasicController/index.d.ts +40 -0
  8. package/dist/Instance/BasicController/index.js +43 -0
  9. package/dist/Instance/BasicController/index.js.map +1 -0
  10. package/dist/Instance/CommandHandler/index.d.ts +20 -0
  11. package/dist/Instance/CommandHandler/index.js +26 -0
  12. package/dist/Instance/CommandHandler/index.js.map +1 -0
  13. package/dist/Instance/Common/ResourceMap/index.js +17 -15
  14. package/dist/Instance/Common/UseFns/index.js +24 -19
  15. package/dist/Instance/Common/index.js +31 -9
  16. package/dist/Instance/Common/onEvent/index.js +82 -76
  17. package/dist/Instance/Common/onEvent/index.js.map +1 -1
  18. package/dist/Instance/GeneralHandler/index.d.ts +19 -0
  19. package/dist/Instance/GeneralHandler/index.js +49 -0
  20. package/dist/Instance/GeneralHandler/index.js.map +1 -0
  21. package/dist/Instance/GeneralModule/index.d.ts +1 -2
  22. package/dist/Instance/GeneralModule/index.js +83 -58
  23. package/dist/Instance/GeneralModule/index.js.map +1 -1
  24. package/dist/Instance/Handler/index.d.ts +23 -0
  25. package/dist/Instance/Handler/index.js +26 -0
  26. package/dist/Instance/Handler/index.js.map +1 -0
  27. package/dist/Instance/Proxy/index.d.ts +22 -0
  28. package/dist/Instance/Proxy/index.js +36 -0
  29. package/dist/Instance/Proxy/index.js.map +1 -0
  30. package/dist/Instance/index.d.ts +14 -0
  31. package/dist/Instance/index.js +20 -0
  32. package/dist/Instance/index.js.map +1 -0
  33. package/dist/Message/FromTemplate/index.js +53 -46
  34. package/dist/Message/PayloadCreation/Media.js +40 -36
  35. package/dist/Message/PayloadCreation/Media.js.map +1 -1
  36. package/dist/Message/PayloadCreation/React.js +11 -9
  37. package/dist/Message/PayloadCreation/Reply.js +37 -35
  38. package/dist/Message/PayloadCreation/Reply.js.map +1 -1
  39. package/dist/Message/PayloadCreation/ReplyWithSticker.d.ts +0 -0
  40. package/dist/Message/PayloadCreation/ReplyWithSticker.js +1 -0
  41. package/dist/Message/PayloadCreation/ReplyWithText.d.ts +2 -0
  42. package/dist/Message/PayloadCreation/ReplyWithText.js +15 -0
  43. package/dist/Message/PayloadCreation/deleteMessage.js +10 -8
  44. package/dist/Message/PayloadCreation/index.js +25 -17
  45. package/dist/Message/PayloadCreation/sendMessage.js +23 -21
  46. package/dist/Message/PayloadCreation/sendMessage.js.map +1 -1
  47. package/dist/Message/ProxiedMessage/index.d.ts +1 -1
  48. package/dist/Message/ProxiedMessage/index.js +17 -11
  49. package/dist/Message/RoutineCreation/AskResource/AskResourceApi/index.js +21 -16
  50. package/dist/Message/RoutineCreation/AskResource/index.js +58 -56
  51. package/dist/Message/RoutineCreation/DeleteMessage/index.js +18 -14
  52. package/dist/Message/RoutineCreation/Reply/WithMedia.js +32 -30
  53. package/dist/Message/RoutineCreation/Reply/WithSticke.d.ts +3 -0
  54. package/dist/Message/RoutineCreation/Reply/WithSticke.js +9 -0
  55. package/dist/Message/RoutineCreation/Reply/WithSticke.js.map +1 -0
  56. package/dist/Message/RoutineCreation/Reply/WithSticker.js +14 -8
  57. package/dist/Message/RoutineCreation/Reply/WithTemplate.js +15 -15
  58. package/dist/Message/RoutineCreation/Reply/index.js +25 -9
  59. package/dist/Message/RoutineCreation/SendMessage/index.js +25 -23
  60. package/dist/Message/RoutineCreation/SendMessage/index.js.map +1 -1
  61. package/dist/Message/RoutineCreation/reply.js +16 -14
  62. package/dist/Message/index.d.ts +1 -1
  63. package/dist/Message/index.js +49 -46
  64. package/dist/Message/kozz-md.parser/index.js +42 -92
  65. package/dist/Message/zap-md.parser/index.d.ts +1 -0
  66. package/dist/Message/zap-md.parser/index.js +2 -0
  67. package/dist/MessageTemplate/h.d.ts +3 -0
  68. package/dist/MessageTemplate/h.js +24 -0
  69. package/dist/MessageTemplate/h.js.map +1 -0
  70. package/dist/MessageTemplate/htm.d.ts +1 -0
  71. package/dist/MessageTemplate/htm.js +10 -0
  72. package/dist/MessageTemplate/htm.js.map +1 -0
  73. package/dist/MessageTemplate/renderer.d.ts +13 -0
  74. package/dist/MessageTemplate/renderer.js +62 -0
  75. package/dist/MessageTemplate/renderer.js.map +1 -0
  76. package/dist/MessageTemplate/types.d.ts +12 -0
  77. package/dist/MessageTemplate/types.js +5 -0
  78. package/dist/MessageTemplate/types.js.map +1 -0
  79. package/dist/Schema/index.js +11 -9
  80. package/dist/Socket/Events/Command.d.ts +3 -0
  81. package/dist/Socket/Events/Command.js +19 -0
  82. package/dist/Socket/Events/Command.js.map +1 -0
  83. package/dist/Socket/Events/Emit/ForwardEvent.js +19 -17
  84. package/dist/Socket/Events/Emit/Introduction.js +12 -10
  85. package/dist/Socket/Events/Emit/ProxyRequest.d.ts +0 -0
  86. package/dist/Socket/Events/Emit/ProxyRequest.js +2 -0
  87. package/dist/Socket/Events/Emit/ProxyRequest.js.map +1 -0
  88. package/dist/Socket/Events/Emit/RequestProxy.js +13 -10
  89. package/dist/Socket/Events/Emit/RevokeProxy.js +9 -7
  90. package/dist/Socket/Events/Handle/AskResource.js +27 -25
  91. package/dist/Socket/Events/Handle/Command.js +35 -38
  92. package/dist/Socket/Events/Handle/ProxiedMessage.js +11 -9
  93. package/dist/Socket/Events/Introduction.d.ts +3 -0
  94. package/dist/Socket/Events/Introduction.js +15 -0
  95. package/dist/Socket/Events/Introduction.js.map +1 -0
  96. package/dist/Socket/Events/ProxiedMessage.d.ts +2 -0
  97. package/dist/Socket/Events/ProxiedMessage.js +10 -0
  98. package/dist/Socket/Events/ProxiedMessage.js.map +1 -0
  99. package/dist/Socket/Messages/Command.d.ts +2 -0
  100. package/dist/Socket/Messages/Command.js +6 -0
  101. package/dist/Socket/Messages/Command.js.map +1 -0
  102. package/dist/Socket/Messages/Introduction.d.ts +3 -0
  103. package/dist/Socket/Messages/Introduction.js +15 -0
  104. package/dist/Socket/Messages/Introduction.js.map +1 -0
  105. package/dist/Socket/index.js +17 -15
  106. package/dist/StateMachine/index.js +44 -38
  107. package/dist/Validator/index.js +41 -38
  108. package/dist/debugIndex.d.ts +1 -0
  109. package/dist/debugIndex.js +73 -0
  110. package/dist/debugIndex.js.map +1 -0
  111. package/dist/index.d.ts +1 -0
  112. package/dist/index.js +36 -18
  113. package/dist/index.js.map +1 -1
  114. package/dist/jsx-runtime/MessageTemplating.js +51 -0
  115. package/dist/jsx-runtime/index.js +83 -0
  116. package/dist/messages.kozz.md +52 -0
  117. package/dist/util/index.js +63 -59
  118. package/dist/util/index.js.map +1 -1
  119. package/dist/util.d.ts +8 -0
  120. package/dist/util.js +36 -0
  121. package/dist/util.js.map +1 -0
  122. package/package.json +21 -17
  123. package/tsconfig.json +26 -97
  124. package/jest.config.ts +0 -196
  125. package/test.kozz.md +0 -81
@@ -1,5 +1,8 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.createMethod = void 0;
4
7
  /**
5
8
  * Creates a command that can be inserted in any command Handler
@@ -10,12 +13,11 @@ exports.createMethod = void 0;
10
13
  */
11
14
  //@ts-ignore
12
15
  const createMethod = (name, callback, args = {}) => {
13
- return {
14
- [name]: {
15
- args,
16
- func: callback,
17
- },
18
- };
16
+ return {
17
+ [name]: {
18
+ args,
19
+ func: callback
20
+ }
21
+ };
19
22
  };
20
- exports.createMethod = createMethod;
21
- //# sourceMappingURL=index.js.map
23
+ exports.createMethod = createMethod;
@@ -0,0 +1,3 @@
1
+ import { Socket } from 'socket.io-client';
2
+ import { Method, UseFn } from '../..';
3
+ export declare const onCommand: <T extends Record<string, Method<Record<string, any>>>>(socket: Socket, methods: T, moduleUseFns: UseFn[], templatePath: string) => void;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.onCommand = void 0;
4
+ const Message_1 = require("../../Message");
5
+ const Validator_1 = require("../../Validator");
6
+ const util_1 = require("../../util");
7
+ const onCommand = (socket, methods, moduleUseFns, templatePath) => {
8
+ socket.on('command', (command) => {
9
+ if (Object.keys(methods).includes(command.method)) {
10
+ const actualMethod = methods[command.method];
11
+ if ((0, Validator_1.isArgsObjectValid)(command.namedArgs, actualMethod.args)) {
12
+ const message = (0, Message_1.createMessageObject)(socket, (0, util_1.runUse)(moduleUseFns, command), templatePath);
13
+ actualMethod.func(message, command.namedArgs);
14
+ }
15
+ }
16
+ });
17
+ };
18
+ exports.onCommand = onCommand;
19
+ //# sourceMappingURL=Command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Command.js","sourceRoot":"","sources":["../../../src/Socket/Events/Command.ts"],"names":[],"mappings":";;;AAGA,2CAAoD;AACpD,+CAAoD;AACpD,qCAAoC;AAE7B,MAAM,SAAS,GAAG,CAGxB,MAAc,EACd,OAAU,EACV,YAAqB,EACrB,YAAoB,EACnB,EAAE;IACH,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,OAAgB,EAAE,EAAE;QACzC,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YAClD,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAC7C,IAAI,IAAA,6BAAiB,EAAC,OAAO,CAAC,SAAS,EAAE,YAAY,CAAC,IAAI,CAAC,EAAE;gBAC5D,MAAM,OAAO,GAAG,IAAA,6BAAmB,EAClC,MAAM,EACN,IAAA,aAAM,EAAC,YAAY,EAAE,OAAO,CAAC,EAC7B,YAAY,CACZ,CAAC;gBACF,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;aAC9C;SACD;IACF,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC;AArBW,QAAA,SAAS,aAqBpB"}
@@ -1,21 +1,23 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.listenBoundary = void 0;
4
- const listenBoundary = (gatewaySocket, instanceName) => (boundaryId) => {
5
- return {
6
- when: (eventName, callback) => {
7
- const payload = {
8
- destination: {
9
- id: instanceName,
10
- type: 'Handler',
11
- },
12
- eventName,
13
- sourceId: boundaryId,
14
- };
15
- gatewaySocket.emit('event_forward_request', payload);
16
- gatewaySocket.on(eventName, callback);
7
+ const listenBoundary = (gatewaySocket, instanceName) => boundaryId => {
8
+ return {
9
+ when: (eventName, callback) => {
10
+ const payload = {
11
+ destination: {
12
+ id: instanceName,
13
+ type: 'Handler'
17
14
  },
18
- };
15
+ eventName,
16
+ sourceId: boundaryId
17
+ };
18
+ gatewaySocket.emit('event_forward_request', payload);
19
+ gatewaySocket.on(eventName, callback);
20
+ }
21
+ };
19
22
  };
20
- exports.listenBoundary = listenBoundary;
21
- //# sourceMappingURL=ForwardEvent.js.map
23
+ exports.listenBoundary = listenBoundary;
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.introduce = void 0;
4
- const util_1 = require("../../../util");
7
+ var _util = require("../../../util");
5
8
  /**
6
9
  * Emits the introduction payload to the gateway
7
10
  * @param socket
@@ -10,12 +13,11 @@ const util_1 = require("../../../util");
10
13
  * @param signature
11
14
  */
12
15
  const introduce = async (socket, handlerName, methods, signature) => {
13
- const payload = {
14
- methods: Object.keys(methods),
15
- name: handlerName,
16
- role: 'handler',
17
- };
18
- socket.emit('introduction', await (0, util_1.signPayload)(payload, signature));
16
+ const payload = {
17
+ methods: Object.keys(methods),
18
+ name: handlerName,
19
+ role: 'handler'
20
+ };
21
+ socket.emit('introduction', await (0, _util.signPayload)(payload, signature));
19
22
  };
20
- exports.introduce = introduce;
21
- //# sourceMappingURL=Introduction.js.map
23
+ exports.introduce = introduce;
File without changes
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=ProxyRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProxyRequest.js","sourceRoot":"","sources":["../../../../src/Socket/Events/Emit/ProxyRequest.ts"],"names":[],"mappings":""}
@@ -1,20 +1,23 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.requestProxy = void 0;
4
- const createProxyRequestPayload = (proxyInitParams) => {
5
- return {
6
- source: proxyInitParams.source,
7
- keepAlive: proxyInitParams.keepProxyAlive,
8
- destination: proxyInitParams.destinationOverride || proxyInitParams.name,
9
- };
7
+ const createProxyRequestPayload = proxyInitParams => {
8
+ return {
9
+ source: proxyInitParams.source,
10
+ keepAlive: proxyInitParams.keepProxyAlive,
11
+ destination: proxyInitParams.destinationOverride || proxyInitParams.name
12
+ };
10
13
  };
14
+
11
15
  /**
12
16
  * Request proxy for a given
13
17
  * @param socket
14
18
  * @param proxyInitParams
15
19
  */
16
20
  const requestProxy = (socket, proxyInitParams) => {
17
- socket.emit('request_proxy', createProxyRequestPayload(proxyInitParams));
21
+ socket.emit('request_proxy', createProxyRequestPayload(proxyInitParams));
18
22
  };
19
- exports.requestProxy = requestProxy;
20
- //# sourceMappingURL=RequestProxy.js.map
23
+ exports.requestProxy = requestProxy;
@@ -1,5 +1,8 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.revokeProxy = void 0;
4
7
  /**
5
8
  * Request the revoking of a proxy
@@ -7,10 +10,9 @@ exports.revokeProxy = void 0;
7
10
  * @param source
8
11
  */
9
12
  const revokeProxy = (socket, source) => {
10
- const payload = {
11
- source: source,
12
- };
13
- socket.emit('revoke_proxy', payload);
13
+ const payload = {
14
+ source: source
15
+ };
16
+ socket.emit('revoke_proxy', payload);
14
17
  };
15
- exports.revokeProxy = revokeProxy;
16
- //# sourceMappingURL=RevokeProxy.js.map
18
+ exports.revokeProxy = revokeProxy;
@@ -1,36 +1,38 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.onAskResource = void 0;
7
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
8
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
9
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
10
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
11
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
12
  /**
5
13
  * Provide the resource asked
6
14
  * @param socket
7
15
  * @param resourceMap
8
16
  */
9
17
  const onAskResource = (socket, resourceMap) => {
10
- socket.on('ask_resource', (payload) => {
11
- const resourceGetter = resourceMap[payload.request.resource];
12
- if (!resourceGetter)
13
- return socket.emit('reply_resource', {
14
- ...payload,
15
- });
16
- promisify(resourceGetter(payload.request.data)).then(resource => {
17
- const responsePayload = {
18
- ...payload,
19
- response: resource,
20
- };
21
- socket.emit('reply_resource', responsePayload);
22
- });
18
+ socket.on('ask_resource', payload => {
19
+ const resourceGetter = resourceMap[payload.request.resource];
20
+ if (!resourceGetter) return socket.emit('reply_resource', _objectSpread({}, payload));
21
+ promisify(resourceGetter(payload.request.data)).then(resource => {
22
+ const responsePayload = _objectSpread(_objectSpread({}, payload), {}, {
23
+ response: resource
24
+ });
25
+ socket.emit('reply_resource', responsePayload);
23
26
  });
27
+ });
24
28
  };
25
29
  exports.onAskResource = onAskResource;
26
- const promisify = (resource) => {
27
- return new Promise(resolve => {
28
- if (resource instanceof Promise) {
29
- resource.then(resp => resolve(resp));
30
- }
31
- else {
32
- resolve(resource);
33
- }
34
- });
35
- };
36
- //# sourceMappingURL=AskResource.js.map
30
+ const promisify = resource => {
31
+ return new Promise(resolve => {
32
+ if (resource instanceof Promise) {
33
+ resource.then(resp => resolve(resp));
34
+ } else {
35
+ resolve(resource);
36
+ }
37
+ });
38
+ };
@@ -1,9 +1,12 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.onCommand = void 0;
4
- const Message_1 = require("../../../Message");
5
- const Validator_1 = require("../../../Validator");
6
- const util_1 = require("../../../util");
7
+ var _Message = require("../../../Message");
8
+ var _Validator = require("../../../Validator");
9
+ var _util = require("../../../util");
7
10
  /**
8
11
  * Handles the command received. It will check if the boundary should have it's command handled,
9
12
  * find the correct method, parse, typecheck the args, run the middlewares and try to run the method
@@ -15,38 +18,32 @@ const util_1 = require("../../../util");
15
18
  * @param boundariesToHandle
16
19
  */
17
20
  const onCommand = (socket, methods, moduleUseFns, handlerName, templatePath, boundariesToHandle) => {
18
- socket.on('command', (command) => {
19
- var _a;
20
- // If the handler doesnt want to handle commands for the provided boundary
21
- if (!boundariesToHandle.includes(command.boundaryName) &&
22
- !boundariesToHandle.includes('*')) {
23
- return;
24
- }
25
- const actualMethod = methods[(0, util_1.normalizeString)((0, util_1.normalizeString)(command.method))] ||
26
- methods['fallback'];
27
- if (!actualMethod)
28
- return;
29
- if ((0, Validator_1.isArgsObjectValid)(command.namedArgs || {}, actualMethod.args)) {
30
- const updatedCommand = (0, util_1.runUse)(moduleUseFns, command);
31
- if ('abort' in ((_a = updatedCommand.namedArgs) !== null && _a !== void 0 ? _a : {})) {
32
- return;
33
- }
34
- const message = (0, Message_1.createMessageObject)(socket, command.message, handlerName, templatePath, command);
35
- socket.emit('react_message', {
36
- messageId: command.message.id,
37
- boundaryId: command.boundaryId,
38
- emote: '',
39
- });
40
- actualMethod.func(message, updatedCommand.namedArgs || {});
41
- }
42
- else {
43
- socket.emit('react_message', {
44
- messageId: command.message.id,
45
- boundaryId: command.boundaryId,
46
- emote: '❌',
47
- });
48
- }
49
- });
21
+ socket.on('command', command => {
22
+ // If the handler doesnt want to handle commands for the provided boundary
23
+ if (!boundariesToHandle.includes(command.boundaryName) && !boundariesToHandle.includes('*')) {
24
+ return;
25
+ }
26
+ const actualMethod = methods[(0, _util.normalizeString)((0, _util.normalizeString)(command.method))] || methods['fallback'];
27
+ if (!actualMethod) return;
28
+ if ((0, _Validator.isArgsObjectValid)(command.namedArgs || {}, actualMethod.args)) {
29
+ const updatedCommand = (0, _util.runUse)(moduleUseFns, command);
30
+ if ('abort' in (updatedCommand.namedArgs ?? {})) {
31
+ return;
32
+ }
33
+ const message = (0, _Message.createMessageObject)(socket, command.message, handlerName, templatePath, command);
34
+ socket.emit('react_message', {
35
+ messageId: command.message.id,
36
+ boundaryId: command.boundaryId,
37
+ emote: '✔'
38
+ });
39
+ actualMethod.func(message, updatedCommand.namedArgs || {});
40
+ } else {
41
+ socket.emit('react_message', {
42
+ messageId: command.message.id,
43
+ boundaryId: command.boundaryId,
44
+ emote: '❌'
45
+ });
46
+ }
47
+ });
50
48
  };
51
- exports.onCommand = onCommand;
52
- //# sourceMappingURL=Command.js.map
49
+ exports.onCommand = onCommand;
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.onProxiedMessage = void 0;
4
- const ProxiedMessage_1 = require("../../../Message/ProxiedMessage");
7
+ var _ProxiedMessage = require("../../../Message/ProxiedMessage");
5
8
  /**
6
9
  * Handles the message proxied to the handler
7
10
  * @param socket
@@ -9,11 +12,10 @@ const ProxiedMessage_1 = require("../../../Message/ProxiedMessage");
9
12
  * @param cb
10
13
  */
11
14
  const onProxiedMessage = (socket, source, cb) => {
12
- socket.removeAllListeners('proxied_message');
13
- socket.on('proxied_message', payload => {
14
- const proxiedMessageObject = (0, ProxiedMessage_1.createProxiedMessageOject)(socket, source, payload, source.split('/')[0]);
15
- cb(proxiedMessageObject);
16
- });
15
+ socket.removeAllListeners('proxied_message');
16
+ socket.on('proxied_message', payload => {
17
+ const proxiedMessageObject = (0, _ProxiedMessage.createProxiedMessageOject)(socket, source, payload, source.split('/')[0]);
18
+ cb(proxiedMessageObject);
19
+ });
17
20
  };
18
- exports.onProxiedMessage = onProxiedMessage;
19
- //# sourceMappingURL=ProxiedMessage.js.map
21
+ exports.onProxiedMessage = onProxiedMessage;
@@ -0,0 +1,3 @@
1
+ import { Socket } from 'socket.io-client';
2
+ import { Method, TypeString } from '../../Schema';
3
+ export declare const introduce: <T extends Record<string, Method<Record<string, TypeString>>>>(socket: Socket, handlerName: string, methods: T) => void;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.introduce = void 0;
4
+ const util_1 = require("src/util");
5
+ const introduce = (socket, handlerName, methods) => {
6
+ const payload = {
7
+ methods: Object.keys(methods),
8
+ name: handlerName,
9
+ role: 'handler',
10
+ timestamp: new Date().getTime(),
11
+ };
12
+ socket.emit('introduction', (0, util_1.signPayload)(payload));
13
+ };
14
+ exports.introduce = introduce;
15
+ //# sourceMappingURL=Introduction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Introduction.js","sourceRoot":"","sources":["../../../src/Socket/Events/Introduction.ts"],"names":[],"mappings":";;;AAGA,mCAAuC;AAEhC,MAAM,SAAS,GAAG,CAGxB,MAAc,EACd,WAAmB,EACnB,OAAU,EACT,EAAE;IACH,MAAM,OAAO,GAA8C;QAC1D,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;QAC7B,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,SAAS;QACf,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;KAC/B,CAAC;IAEF,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,IAAA,kBAAW,EAAC,OAAO,CAAC,CAAC,CAAC;AACnD,CAAC,CAAC;AAfW,QAAA,SAAS,aAepB"}
@@ -0,0 +1,2 @@
1
+ import { Socket } from 'socket.io-client';
2
+ export declare const onProxiedMessage: (socket: Socket) => void;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.onProxiedMessage = void 0;
4
+ const onProxiedMessage = (socket) => {
5
+ socket.on('proxied_message', payload => {
6
+ console.log(payload.body);
7
+ });
8
+ };
9
+ exports.onProxiedMessage = onProxiedMessage;
10
+ //# sourceMappingURL=ProxiedMessage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProxiedMessage.js","sourceRoot":"","sources":["../../../src/Socket/Events/ProxiedMessage.ts"],"names":[],"mappings":";;;AAEO,MAAM,gBAAgB,GAAG,CAAC,MAAc,EAAE,EAAE;IAClD,MAAM,CAAC,EAAE,CAAC,iBAAiB,EAAE,OAAO,CAAC,EAAE;QACtC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC;AAJW,QAAA,gBAAgB,oBAI3B"}
@@ -0,0 +1,2 @@
1
+ import { Socket } from 'socket.io-client';
2
+ export declare const onCommand: (socket: Socket, callback: Function) => void;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.onCommand = void 0;
4
+ const onCommand = (socket, callback) => { };
5
+ exports.onCommand = onCommand;
6
+ //# sourceMappingURL=Command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Command.js","sourceRoot":"","sources":["../../../src/Socket/Messages/Command.ts"],"names":[],"mappings":";;;AAEO,MAAM,SAAS,GAAG,CAAC,MAAc,EAAE,QAAkB,EAAE,EAAE,GAAE,CAAC,CAAC;AAAvD,QAAA,SAAS,aAA8C"}
@@ -0,0 +1,3 @@
1
+ import { Socket } from 'socket.io-client';
2
+ import { Method, TypeString } from '../../Schema';
3
+ export declare const introduce: <T extends Record<string, Method<Record<string, TypeString>>>>(socket: Socket, handlerName: string, methods: T) => void;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.introduce = void 0;
4
+ const util_1 = require("src/util");
5
+ const introduce = (socket, handlerName, methods) => {
6
+ const payload = {
7
+ methods: Object.keys(methods),
8
+ name: handlerName,
9
+ role: 'handler',
10
+ timestamp: new Date().getTime(),
11
+ };
12
+ socket.emit('introduction', (0, util_1.signPayload)(payload));
13
+ };
14
+ exports.introduce = introduce;
15
+ //# sourceMappingURL=Introduction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Introduction.js","sourceRoot":"","sources":["../../../src/Socket/Messages/Introduction.ts"],"names":[],"mappings":";;;AAKA,mCAAuC;AAEhC,MAAM,SAAS,GAAG,CAGxB,MAAc,EACd,WAAmB,EACnB,OAAU,EACT,EAAE;IACH,MAAM,OAAO,GAA8C;QAC1D,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;QAC7B,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,SAAS;QACf,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;KAC/B,CAAC;IAEF,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,IAAA,kBAAW,EAAC,OAAO,CAAC,CAAC,CAAC;AACnD,CAAC,CAAC;AAfW,QAAA,SAAS,aAepB"}
@@ -1,19 +1,21 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.connect = void 0;
4
- const socket_io_client_1 = require("socket.io-client");
5
- const Command_1 = require("./Events/Handle/Command");
7
+ var _socket = require("socket.io-client");
8
+ var _Command = require("./Events/Handle/Command");
6
9
  const connect = (onConnect, address, moduleUseFns, templatePath, handlerName, boundariesToHandle, socketPath = '/socket.io/') => {
7
- const connectionObj = {
8
- path: socketPath,
9
- };
10
- const socket = (0, socket_io_client_1.io)(address, connectionObj);
11
- socket.on('connect', onConnect);
12
- const registerMethods = (methods) => (0, Command_1.onCommand)(socket, methods, moduleUseFns, handlerName, templatePath, boundariesToHandle);
13
- return {
14
- socket,
15
- registerMethods,
16
- };
10
+ const connectionObj = {
11
+ path: socketPath
12
+ };
13
+ const socket = (0, _socket.io)(address, connectionObj);
14
+ socket.on('connect', onConnect);
15
+ const registerMethods = methods => (0, _Command.onCommand)(socket, methods, moduleUseFns, handlerName, templatePath, boundariesToHandle);
16
+ return {
17
+ socket,
18
+ registerMethods
19
+ };
17
20
  };
18
- exports.connect = connect;
19
- //# sourceMappingURL=index.js.map
21
+ exports.connect = connect;
@@ -1,43 +1,49 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.createStateMachine = exports.createNewStateMachineInstance = void 0;
4
- const createNewStateMachineInstance = (stateMachineDescriptor) => {
5
- const stateMachine = {
6
- ...stateMachineDescriptor,
7
- currentState: stateMachineDescriptor.initialState,
8
- setState: (newState) => {
9
- stateMachine.currentState = newState;
10
- },
11
- reset: () => stateMachine.setState(stateMachine.initialState),
12
- };
13
- return stateMachine;
7
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
8
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
9
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
10
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
11
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
12
+ const createNewStateMachineInstance = stateMachineDescriptor => {
13
+ const stateMachine = _objectSpread(_objectSpread({}, stateMachineDescriptor), {}, {
14
+ currentState: stateMachineDescriptor.initialState,
15
+ setState: newState => {
16
+ stateMachine.currentState = newState;
17
+ },
18
+ reset: () => stateMachine.setState(stateMachine.initialState)
19
+ });
20
+ return stateMachine;
14
21
  };
15
22
  exports.createNewStateMachineInstance = createNewStateMachineInstance;
16
- const createStateMachine = (stateMachineDescriptor) => {
17
- const userStateMap = new Map();
18
- /**
19
- * One single instance per contact.
20
- * @param contactId
21
- * @returns
22
- */
23
- const getStateMachine = (contactId) => {
24
- if (!userStateMap.get(contactId)) {
25
- userStateMap.set(contactId,
26
- // @ts-ignore
27
- (0, exports.createNewStateMachineInstance)(stateMachineDescriptor));
28
- }
29
- return userStateMap.get(contactId);
30
- };
31
- return (requester) => {
32
- var _a, _b;
33
- const stateMachine = getStateMachine(requester.message.contact.id);
34
- const oldState = stateMachine.currentState;
35
- stateMachine.states[stateMachine.currentState].onMessage(requester, stateMachine);
36
- const newState = stateMachine.currentState;
37
- if (newState !== oldState) {
38
- (_b = (_a = stateMachine.states[stateMachine.currentState]).onStateEnable) === null || _b === void 0 ? void 0 : _b.call(_a, requester, stateMachine);
39
- }
40
- };
23
+ const createStateMachine = stateMachineDescriptor => {
24
+ const userStateMap = new Map();
25
+
26
+ /**
27
+ * One single instance per contact.
28
+ * @param contactId
29
+ * @returns
30
+ */
31
+ const getStateMachine = contactId => {
32
+ if (!userStateMap.get(contactId)) {
33
+ userStateMap.set(contactId,
34
+ // @ts-ignore
35
+ createNewStateMachineInstance(stateMachineDescriptor));
36
+ }
37
+ return userStateMap.get(contactId);
38
+ };
39
+ return requester => {
40
+ const stateMachine = getStateMachine(requester.message.contact.id);
41
+ const oldState = stateMachine.currentState;
42
+ stateMachine.states[stateMachine.currentState].onMessage(requester, stateMachine);
43
+ const newState = stateMachine.currentState;
44
+ if (newState !== oldState) {
45
+ stateMachine.states[stateMachine.currentState].onStateEnable?.(requester, stateMachine);
46
+ }
47
+ };
41
48
  };
42
- exports.createStateMachine = createStateMachine;
43
- //# sourceMappingURL=index.js.map
49
+ exports.createStateMachine = createStateMachine;