@wabot-dev/framework 0.1.0-beta.9 → 0.2.0-beta.1

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 (212) hide show
  1. package/dist/src/addon/async/pg/PgJobRepository.js +26 -0
  2. package/dist/src/addon/auth/api-key/@apiKeyConnectionGuard.js +16 -0
  3. package/dist/src/addon/auth/api-key/@apiKeyGuard.js +17 -0
  4. package/dist/src/addon/auth/api-key/ApiKey.js +45 -0
  5. package/dist/src/addon/auth/api-key/ApiKeyConnectionGuardMiddleware.js +57 -0
  6. package/dist/src/addon/auth/api-key/ApiKeyGuardMiddleware.js +45 -0
  7. package/dist/src/addon/auth/api-key/ApiKeyRepository.js +22 -0
  8. package/dist/src/addon/auth/api-key/PgApiKeyRepository.js +53 -0
  9. package/dist/src/addon/auth/api-key/RemoteApiKeyRepository.js +62 -0
  10. package/dist/src/addon/auth/jwt/@jwtConnectionGuard.js +16 -0
  11. package/dist/src/addon/auth/jwt/@jwtGuard.js +17 -0
  12. package/dist/src/addon/auth/jwt/Jwt.js +53 -0
  13. package/dist/src/addon/auth/jwt/JwtAccessAndRefreshTokenDto.js +20 -0
  14. package/dist/src/addon/auth/jwt/JwtConfig.js +28 -0
  15. package/dist/src/addon/auth/jwt/JwtConnectionGuardMiddleware.js +57 -0
  16. package/dist/src/addon/auth/jwt/JwtGuardMiddleware.js +45 -0
  17. package/dist/src/addon/auth/jwt/JwtRefreshToken.js +56 -0
  18. package/dist/src/addon/auth/jwt/JwtRefreshTokenRepository.js +25 -0
  19. package/dist/src/addon/auth/jwt/JwtSigner.js +36 -0
  20. package/dist/src/addon/auth/jwt/JwtTokenDto.js +22 -0
  21. package/dist/src/addon/auth/jwt/PgJwtRefreshTokenRepository.js +21 -0
  22. package/dist/src/addon/chat-bot/anthropic/AnthropicChatAdapter.js +135 -0
  23. package/dist/src/addon/chat-bot/deepseek/DeepSeekChatAdapter.js +137 -0
  24. package/dist/src/addon/chat-bot/google/GoogleChatAdapter.js +128 -0
  25. package/dist/src/addon/chat-bot/openia/OpenaiChatAdapter.js +117 -0
  26. package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatMemory.js +6 -4
  27. package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatRepository.js +6 -5
  28. package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatRepository.js +2 -2
  29. package/dist/src/addon/chat-bot/wabot/WabotChatAdapter.js +41 -0
  30. package/dist/src/addon/chat-controller/cmd/@cmd.js +24 -0
  31. package/dist/src/addon/chat-controller/cmd/CmdChannel.js +91 -0
  32. package/dist/src/{channels → addon/chat-controller}/socket/@socket.js +10 -4
  33. package/dist/src/{channels → addon/chat-controller}/socket/SocketChannel.js +9 -23
  34. package/dist/src/{channels → addon/chat-controller}/socket/SocketChannelConfig.js +1 -1
  35. package/dist/src/{channels → addon/chat-controller}/telegram/@telegram.js +10 -4
  36. package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannel.js +4 -22
  37. package/dist/src/addon/chat-controller/whatsapp/@whatsApp.js +26 -0
  38. package/dist/src/{channels → addon/chat-controller}/whatsapp/EnvWhatsAppRepository.js +3 -3
  39. package/dist/src/{channels → addon/chat-controller}/whatsapp/PgWhatsAppRepository.js +2 -2
  40. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsApp.js +2 -4
  41. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannel.js +6 -18
  42. package/dist/src/addon/chat-controller/whatsapp/WhatsAppReceiver.js +10 -0
  43. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppSender.js +15 -39
  44. package/dist/src/addon/chat-controller/whatsapp/cloud-api/WhatsAppReceiverByCloudApi.js +97 -0
  45. package/dist/src/{channels/whatsapp → addon/chat-controller/whatsapp/cloud-api}/WhatsAppSenderByCloudApi.js +27 -20
  46. package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppProxyContracts.js +5 -0
  47. package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppReceiverByWabotProxy.js +65 -0
  48. package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppSenderByWabotProxy.js +61 -0
  49. package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppWabotProxyConnection.js +45 -0
  50. package/dist/src/{pre-made/module → addon/mindset}/html/HtmlModule.js +7 -7
  51. package/dist/src/core/auth/Auth.js +33 -0
  52. package/dist/src/core/{Persistent.js → entity/Entity.js} +24 -12
  53. package/dist/src/core/env/Env.js +39 -0
  54. package/dist/src/core/error/CustomError.js +15 -0
  55. package/dist/src/core/injection/index.js +4 -0
  56. package/dist/src/core/mapper/Mapper.js +42 -0
  57. package/dist/src/core/password/Password.js +30 -0
  58. package/dist/src/core/random/Random.js +65 -0
  59. package/dist/src/core/storable/Storable.js +8 -0
  60. package/dist/src/core/validation/core/validateArray.js +51 -0
  61. package/dist/src/core/validation/core/validateModel.js +36 -0
  62. package/dist/src/{validation/metadata/@isNumber.js → core/validation/metadata/@isArray.js} +5 -4
  63. package/dist/src/{validation/metadata/@isDate.js → core/validation/metadata/@isModel.js} +5 -4
  64. package/dist/src/{validation → core/validation}/metadata/@isOptional.js +1 -1
  65. package/dist/src/core/validation/metadata/ValidationMetadataStore.js +98 -0
  66. package/dist/src/core/validation/modelInfo.js +9 -0
  67. package/dist/src/{validation/validateModel2.js → core/validation/validate.js} +3 -3
  68. package/dist/src/{validation/metadata → core/validation/validators/is-boolean}/@isBoolean.js +3 -3
  69. package/dist/src/core/validation/validators/is-date/@isDate.js +17 -0
  70. package/dist/src/core/validation/validators/is-in/@isIn.js +18 -0
  71. package/dist/src/core/validation/validators/is-in/validateIsIn.js +12 -0
  72. package/dist/src/{validation/metadata → core/validation/validators/is-not-empty}/@isNotEmpty.js +3 -3
  73. package/dist/src/core/validation/validators/is-number/@isNumber.js +17 -0
  74. package/dist/src/{validation/metadata → core/validation/validators/is-present}/@isPresent.js +3 -3
  75. package/dist/src/{validation/metadata → core/validation/validators/is-string}/@isString.js +3 -3
  76. package/dist/src/{validation/metadata → core/validation/validators/max}/@max.js +3 -3
  77. package/dist/src/{validation/metadata → core/validation/validators/min}/@min.js +3 -3
  78. package/dist/src/feature/async/@command.js +11 -0
  79. package/dist/src/feature/async/@commandHandler.js +12 -0
  80. package/dist/src/feature/async/Async.js +38 -0
  81. package/dist/src/feature/async/Command.js +9 -0
  82. package/dist/src/feature/async/CommandMetadataStore.js +38 -0
  83. package/dist/src/feature/async/Job.js +27 -0
  84. package/dist/src/feature/async/JobRepository.js +31 -0
  85. package/dist/src/feature/async/JobRunner.js +48 -0
  86. package/dist/src/feature/async/JobsEventsHub.js +36 -0
  87. package/dist/src/feature/async/runCommandHandlers.js +29 -0
  88. package/dist/src/{core/chat → feature/chat-bot}/Chat.js +2 -2
  89. package/dist/src/feature/chat-bot/ChatAdapter.js +7 -0
  90. package/dist/src/feature/chat-bot/ChatBot.js +73 -0
  91. package/dist/src/feature/chat-bot/ChatItem.js +24 -0
  92. package/dist/src/feature/chat-bot/ChatMemory.js +10 -0
  93. package/dist/src/{core/chat/repository/IChatRepository.js → feature/chat-bot/ChatRepository.js} +2 -8
  94. package/dist/src/feature/chat-bot/IChatItem.js +3 -0
  95. package/dist/src/{chatbot → feature/chat-bot}/metadata/@chatBot.js +1 -1
  96. package/dist/src/{chatbot → feature/chat-bot}/metadata/ChatBotMetadataStore.js +1 -1
  97. package/dist/src/{controller/channel → feature/chat-controller}/ChatResolver.js +6 -4
  98. package/dist/src/{controller → feature/chat-controller}/metadata/ControllerMetadataStore.js +1 -1
  99. package/dist/src/{controller → feature/chat-controller}/metadata/controller/@chatController.js +1 -1
  100. package/dist/src/feature/chat-controller/runChatControllers.js +83 -0
  101. package/dist/src/{channels → feature}/express/ExpressProvider.js +2 -4
  102. package/dist/src/{channels → feature}/http/HttpServerProvider.js +2 -2
  103. package/dist/src/{mindset → feature/mindset}/IMindset.js +6 -0
  104. package/dist/src/feature/mindset/MindsetOperator.js +180 -0
  105. package/dist/src/{mindset → feature/mindset}/metadata/MindsetMetadataStore.js +1 -1
  106. package/dist/src/{mindset → feature/mindset}/metadata/functions/@mindsetFunction.js +1 -1
  107. package/dist/src/{mindset → feature/mindset}/metadata/mindsets/@mindset.js +1 -1
  108. package/dist/src/{mindset → feature/mindset}/metadata/modules/@mindsetModule.js +1 -2
  109. package/dist/src/{mindset → feature/mindset}/metadata/params/@param.js +1 -1
  110. package/dist/src/feature/money/Money.js +61 -0
  111. package/dist/src/feature/money/MoneyDto.js +22 -0
  112. package/dist/src/{repository → feature}/pg/PgCrudRepository.js +24 -10
  113. package/dist/src/{repository → feature}/pg/PgRepositoryBase.js +2 -2
  114. package/dist/src/feature/rest-controller/injection-tokens.js +4 -0
  115. package/dist/src/{rest-controller/metadata/@post.js → feature/rest-controller/metadata/@middleware.js} +5 -8
  116. package/dist/src/feature/rest-controller/metadata/@onDelete.js +7 -0
  117. package/dist/src/feature/rest-controller/metadata/@onGet.js +7 -0
  118. package/dist/src/feature/rest-controller/metadata/@onPost.js +7 -0
  119. package/dist/src/feature/rest-controller/metadata/@onPut.js +7 -0
  120. package/dist/src/{rest-controller → feature/rest-controller}/metadata/@restController.js +2 -2
  121. package/dist/src/{rest-controller → feature/rest-controller}/metadata/RestControllerMetadataStore.js +14 -1
  122. package/dist/src/{rest-controller/metadata/@get.js → feature/rest-controller/metadata/methodDecorator.js} +5 -5
  123. package/dist/src/feature/rest-controller/runRestControllers.js +103 -0
  124. package/dist/src/{channels → feature}/socket/SocketServerProvider.js +2 -2
  125. package/dist/src/feature/socket-controller/metadata/@connectionMiddleware.js +16 -0
  126. package/dist/src/feature/socket-controller/metadata/@socketConnection.js +18 -0
  127. package/dist/src/feature/socket-controller/metadata/@socketController.js +15 -0
  128. package/dist/src/feature/socket-controller/metadata/@socketEvent.js +18 -0
  129. package/dist/src/feature/socket-controller/metadata/SocketControllerMetadataStore.js +65 -0
  130. package/dist/src/feature/socket-controller/runSocketControllers.js +99 -0
  131. package/dist/src/index.d.ts +1219 -718
  132. package/dist/src/index.js +147 -102
  133. package/package.json +8 -2
  134. package/dist/src/_virtual/_commonjsHelpers.js +0 -5
  135. package/dist/src/_virtual/cjs.js +0 -7
  136. package/dist/src/ai/deepseek/DeepSeekChatBotAdapter.js +0 -107
  137. package/dist/src/ai/openia/OpenaiChatBotAdapter.js +0 -88
  138. package/dist/src/channels/cmd/@cmd.js +0 -18
  139. package/dist/src/channels/cmd/CmdChannel.js +0 -73
  140. package/dist/src/channels/wabot/WabotDevConnection.js +0 -57
  141. package/dist/src/channels/wabot/WabotDevSocketContracts.js +0 -10
  142. package/dist/src/channels/whatsapp/@whatsapp.js +0 -20
  143. package/dist/src/channels/whatsapp/WhatsAppReceiver.js +0 -59
  144. package/dist/src/channels/whatsapp/WhatsAppReceiverByDevConnection.js +0 -32
  145. package/dist/src/channels/whatsapp/WhatsAppReceiverByWebHook.js +0 -63
  146. package/dist/src/channels/whatsapp/WhatsAppSenderByDevConnection.js +0 -61
  147. package/dist/src/chatbot/ChatBot.js +0 -51
  148. package/dist/src/chatbot/ChatBotAdapter.js +0 -72
  149. package/dist/src/controller/channel/UserResolver.js +0 -21
  150. package/dist/src/core/IMessageContext.js +0 -12
  151. package/dist/src/core/chat/ChatItem.js +0 -15
  152. package/dist/src/core/chat/repository/IChatMemory.js +0 -10
  153. package/dist/src/core/user/IUserRepository.js +0 -19
  154. package/dist/src/core/user/User.js +0 -26
  155. package/dist/src/env/WabotEnv.js +0 -27
  156. package/dist/src/injection/index.js +0 -4
  157. package/dist/src/mindset/MindsetOperator.js +0 -101
  158. package/dist/src/node_modules/@selderee/plugin-htmlparser2/lib/hp2-builder.js +0 -90
  159. package/dist/src/node_modules/deepmerge/dist/cjs.js +0 -142
  160. package/dist/src/node_modules/dom-serializer/lib/esm/foreignNames.js +0 -102
  161. package/dist/src/node_modules/dom-serializer/lib/esm/index.js +0 -186
  162. package/dist/src/node_modules/domelementtype/lib/esm/index.js +0 -53
  163. package/dist/src/node_modules/domhandler/lib/esm/index.js +0 -148
  164. package/dist/src/node_modules/domhandler/lib/esm/node.js +0 -334
  165. package/dist/src/node_modules/entities/lib/esm/decode.js +0 -458
  166. package/dist/src/node_modules/entities/lib/esm/decode_codepoint.js +0 -62
  167. package/dist/src/node_modules/entities/lib/esm/escape.js +0 -99
  168. package/dist/src/node_modules/entities/lib/esm/generated/decode-data-html.js +0 -8
  169. package/dist/src/node_modules/entities/lib/esm/generated/decode-data-xml.js +0 -8
  170. package/dist/src/node_modules/html-to-text/lib/html-to-text.js +0 -2147
  171. package/dist/src/node_modules/htmlparser2/lib/esm/Parser.js +0 -491
  172. package/dist/src/node_modules/htmlparser2/lib/esm/Tokenizer.js +0 -928
  173. package/dist/src/node_modules/htmlparser2/lib/esm/index.js +0 -18
  174. package/dist/src/node_modules/leac/lib/leac.js +0 -3
  175. package/dist/src/node_modules/parseley/lib/parseley.js +0 -270
  176. package/dist/src/node_modules/peberminta/lib/core.js +0 -171
  177. package/dist/src/node_modules/selderee/lib/selderee.js +0 -380
  178. package/dist/src/pre-made/module/authentication/AuthenticationModule.js +0 -97
  179. package/dist/src/pre-made/module/authentication/requests/SendOneTimePasswordRequest.js +0 -25
  180. package/dist/src/pre-made/module/authentication/requests/ValidateOneTimePasswordRequest.js +0 -25
  181. package/dist/src/pre-made/module/register-user/RegisterUserModule.js +0 -56
  182. package/dist/src/pre-made/module/register-user/requests/RegisterUserWithEmailRequest.js +0 -25
  183. package/dist/src/pre-made/repository/user/pg/PgUserRepository.js +0 -33
  184. package/dist/src/pre-made/repository/user/ram/RamUserRepository.js +0 -27
  185. package/dist/src/pre-made/service/EmailService.js +0 -13
  186. package/dist/src/pre-made/service/OtpService.js +0 -14
  187. package/dist/src/rest-controller/runRestControllers.js +0 -74
  188. package/dist/src/server/prepareChatContainer.js +0 -43
  189. package/dist/src/server/runChannel.js +0 -27
  190. package/dist/src/server/runServer.js +0 -40
  191. package/dist/src/validation/metadata/@validable.js +0 -14
  192. package/dist/src/validation/metadata/ValidationMetadataStore.js +0 -55
  193. package/dist/src/validation/validators/validateModel.js +0 -47
  194. /package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatMemory.js +0 -0
  195. /package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannelConfig.js +0 -0
  196. /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannelConfig.js +0 -0
  197. /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppRepository.js +0 -0
  198. /package/dist/src/{injection → core/injection}/Container.js +0 -0
  199. /package/dist/src/{logger → core/logger}/Logger.js +0 -0
  200. /package/dist/src/{validation/validators → core/validation/core}/validateIsOptional.js +0 -0
  201. /package/dist/src/{validation/validators → core/validation/validators/is-boolean}/validateIsBoolean.js +0 -0
  202. /package/dist/src/{validation/validators → core/validation/validators/is-date}/validateIsDate.js +0 -0
  203. /package/dist/src/{validation/validators → core/validation/validators/is-not-empty}/validateIsNotEmpty.js +0 -0
  204. /package/dist/src/{validation/validators → core/validation/validators/is-number}/validateIsNumber.js +0 -0
  205. /package/dist/src/{validation/validators → core/validation/validators/is-present}/validateIsPresent.js +0 -0
  206. /package/dist/src/{validation/validators → core/validation/validators/is-string}/validateIsString.js +0 -0
  207. /package/dist/src/{validation/validators → core/validation/validators/max}/validateMax.js +0 -0
  208. /package/dist/src/{validation/validators → core/validation/validators/min}/validateMin.js +0 -0
  209. /package/dist/src/{mindset → feature/mindset}/metadata/functions/decoratorNames.js +0 -0
  210. /package/dist/src/{mindset → feature/mindset}/metadata/mindsets/decoratorNames.js +0 -0
  211. /package/dist/src/{mindset → feature/mindset}/metadata/modules/decoratorNames.js +0 -0
  212. /package/dist/src/{mindset → feature/mindset}/metadata/params/decoratorNames.js +0 -0
@@ -1,148 +0,0 @@
1
- import { ElementType } from '../../../domelementtype/lib/esm/index.js';
2
- import { Document, Element, Text, Comment, CDATA, ProcessingInstruction } from './node.js';
3
- export { DataNode, Node, NodeWithChildren, cloneNode, isCDATA, isComment, isDirective, isDocument, isTag, isText } from './node.js';
4
-
5
- // Default options
6
- const defaultOpts = {
7
- withStartIndices: false,
8
- withEndIndices: false,
9
- xmlMode: false,
10
- };
11
- class DomHandler {
12
- /**
13
- * @param callback Called once parsing has completed.
14
- * @param options Settings for the handler.
15
- * @param elementCB Callback whenever a tag is closed.
16
- */
17
- constructor(callback, options, elementCB) {
18
- /** The elements of the DOM */
19
- this.dom = [];
20
- /** The root element for the DOM */
21
- this.root = new Document(this.dom);
22
- /** Indicated whether parsing has been completed. */
23
- this.done = false;
24
- /** Stack of open tags. */
25
- this.tagStack = [this.root];
26
- /** A data node that is still being written to. */
27
- this.lastNode = null;
28
- /** Reference to the parser instance. Used for location information. */
29
- this.parser = null;
30
- // Make it possible to skip arguments, for backwards-compatibility
31
- if (typeof options === "function") {
32
- elementCB = options;
33
- options = defaultOpts;
34
- }
35
- if (typeof callback === "object") {
36
- options = callback;
37
- callback = undefined;
38
- }
39
- this.callback = callback !== null && callback !== void 0 ? callback : null;
40
- this.options = options !== null && options !== void 0 ? options : defaultOpts;
41
- this.elementCB = elementCB !== null && elementCB !== void 0 ? elementCB : null;
42
- }
43
- onparserinit(parser) {
44
- this.parser = parser;
45
- }
46
- // Resets the handler back to starting state
47
- onreset() {
48
- this.dom = [];
49
- this.root = new Document(this.dom);
50
- this.done = false;
51
- this.tagStack = [this.root];
52
- this.lastNode = null;
53
- this.parser = null;
54
- }
55
- // Signals the handler that parsing is done
56
- onend() {
57
- if (this.done)
58
- return;
59
- this.done = true;
60
- this.parser = null;
61
- this.handleCallback(null);
62
- }
63
- onerror(error) {
64
- this.handleCallback(error);
65
- }
66
- onclosetag() {
67
- this.lastNode = null;
68
- const elem = this.tagStack.pop();
69
- if (this.options.withEndIndices) {
70
- elem.endIndex = this.parser.endIndex;
71
- }
72
- if (this.elementCB)
73
- this.elementCB(elem);
74
- }
75
- onopentag(name, attribs) {
76
- const type = this.options.xmlMode ? ElementType.Tag : undefined;
77
- const element = new Element(name, attribs, undefined, type);
78
- this.addNode(element);
79
- this.tagStack.push(element);
80
- }
81
- ontext(data) {
82
- const { lastNode } = this;
83
- if (lastNode && lastNode.type === ElementType.Text) {
84
- lastNode.data += data;
85
- if (this.options.withEndIndices) {
86
- lastNode.endIndex = this.parser.endIndex;
87
- }
88
- }
89
- else {
90
- const node = new Text(data);
91
- this.addNode(node);
92
- this.lastNode = node;
93
- }
94
- }
95
- oncomment(data) {
96
- if (this.lastNode && this.lastNode.type === ElementType.Comment) {
97
- this.lastNode.data += data;
98
- return;
99
- }
100
- const node = new Comment(data);
101
- this.addNode(node);
102
- this.lastNode = node;
103
- }
104
- oncommentend() {
105
- this.lastNode = null;
106
- }
107
- oncdatastart() {
108
- const text = new Text("");
109
- const node = new CDATA([text]);
110
- this.addNode(node);
111
- text.parent = node;
112
- this.lastNode = text;
113
- }
114
- oncdataend() {
115
- this.lastNode = null;
116
- }
117
- onprocessinginstruction(name, data) {
118
- const node = new ProcessingInstruction(name, data);
119
- this.addNode(node);
120
- }
121
- handleCallback(error) {
122
- if (typeof this.callback === "function") {
123
- this.callback(error, this.dom);
124
- }
125
- else if (error) {
126
- throw error;
127
- }
128
- }
129
- addNode(node) {
130
- const parent = this.tagStack[this.tagStack.length - 1];
131
- const previousSibling = parent.children[parent.children.length - 1];
132
- if (this.options.withStartIndices) {
133
- node.startIndex = this.parser.startIndex;
134
- }
135
- if (this.options.withEndIndices) {
136
- node.endIndex = this.parser.endIndex;
137
- }
138
- parent.children.push(node);
139
- if (previousSibling) {
140
- node.prev = previousSibling;
141
- previousSibling.next = node;
142
- }
143
- node.parent = parent;
144
- this.lastNode = null;
145
- }
146
- }
147
-
148
- export { CDATA, Comment, Document, DomHandler, Element, ProcessingInstruction, Text, DomHandler as default };
@@ -1,334 +0,0 @@
1
- import { ElementType, isTag as isTag$1 } from '../../../domelementtype/lib/esm/index.js';
2
-
3
- /**
4
- * This object will be used as the prototype for Nodes when creating a
5
- * DOM-Level-1-compliant structure.
6
- */
7
- class Node {
8
- constructor() {
9
- /** Parent of the node */
10
- this.parent = null;
11
- /** Previous sibling */
12
- this.prev = null;
13
- /** Next sibling */
14
- this.next = null;
15
- /** The start index of the node. Requires `withStartIndices` on the handler to be `true. */
16
- this.startIndex = null;
17
- /** The end index of the node. Requires `withEndIndices` on the handler to be `true. */
18
- this.endIndex = null;
19
- }
20
- // Read-write aliases for properties
21
- /**
22
- * Same as {@link parent}.
23
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
24
- */
25
- get parentNode() {
26
- return this.parent;
27
- }
28
- set parentNode(parent) {
29
- this.parent = parent;
30
- }
31
- /**
32
- * Same as {@link prev}.
33
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
34
- */
35
- get previousSibling() {
36
- return this.prev;
37
- }
38
- set previousSibling(prev) {
39
- this.prev = prev;
40
- }
41
- /**
42
- * Same as {@link next}.
43
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
44
- */
45
- get nextSibling() {
46
- return this.next;
47
- }
48
- set nextSibling(next) {
49
- this.next = next;
50
- }
51
- /**
52
- * Clone this node, and optionally its children.
53
- *
54
- * @param recursive Clone child nodes as well.
55
- * @returns A clone of the node.
56
- */
57
- cloneNode(recursive = false) {
58
- return cloneNode(this, recursive);
59
- }
60
- }
61
- /**
62
- * A node that contains some data.
63
- */
64
- class DataNode extends Node {
65
- /**
66
- * @param data The content of the data node
67
- */
68
- constructor(data) {
69
- super();
70
- this.data = data;
71
- }
72
- /**
73
- * Same as {@link data}.
74
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
75
- */
76
- get nodeValue() {
77
- return this.data;
78
- }
79
- set nodeValue(data) {
80
- this.data = data;
81
- }
82
- }
83
- /**
84
- * Text within the document.
85
- */
86
- class Text extends DataNode {
87
- constructor() {
88
- super(...arguments);
89
- this.type = ElementType.Text;
90
- }
91
- get nodeType() {
92
- return 3;
93
- }
94
- }
95
- /**
96
- * Comments within the document.
97
- */
98
- class Comment extends DataNode {
99
- constructor() {
100
- super(...arguments);
101
- this.type = ElementType.Comment;
102
- }
103
- get nodeType() {
104
- return 8;
105
- }
106
- }
107
- /**
108
- * Processing instructions, including doc types.
109
- */
110
- class ProcessingInstruction extends DataNode {
111
- constructor(name, data) {
112
- super(data);
113
- this.name = name;
114
- this.type = ElementType.Directive;
115
- }
116
- get nodeType() {
117
- return 1;
118
- }
119
- }
120
- /**
121
- * A `Node` that can have children.
122
- */
123
- class NodeWithChildren extends Node {
124
- /**
125
- * @param children Children of the node. Only certain node types can have children.
126
- */
127
- constructor(children) {
128
- super();
129
- this.children = children;
130
- }
131
- // Aliases
132
- /** First child of the node. */
133
- get firstChild() {
134
- var _a;
135
- return (_a = this.children[0]) !== null && _a !== void 0 ? _a : null;
136
- }
137
- /** Last child of the node. */
138
- get lastChild() {
139
- return this.children.length > 0
140
- ? this.children[this.children.length - 1]
141
- : null;
142
- }
143
- /**
144
- * Same as {@link children}.
145
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
146
- */
147
- get childNodes() {
148
- return this.children;
149
- }
150
- set childNodes(children) {
151
- this.children = children;
152
- }
153
- }
154
- class CDATA extends NodeWithChildren {
155
- constructor() {
156
- super(...arguments);
157
- this.type = ElementType.CDATA;
158
- }
159
- get nodeType() {
160
- return 4;
161
- }
162
- }
163
- /**
164
- * The root node of the document.
165
- */
166
- class Document extends NodeWithChildren {
167
- constructor() {
168
- super(...arguments);
169
- this.type = ElementType.Root;
170
- }
171
- get nodeType() {
172
- return 9;
173
- }
174
- }
175
- /**
176
- * An element within the DOM.
177
- */
178
- class Element extends NodeWithChildren {
179
- /**
180
- * @param name Name of the tag, eg. `div`, `span`.
181
- * @param attribs Object mapping attribute names to attribute values.
182
- * @param children Children of the node.
183
- */
184
- constructor(name, attribs, children = [], type = name === "script"
185
- ? ElementType.Script
186
- : name === "style"
187
- ? ElementType.Style
188
- : ElementType.Tag) {
189
- super(children);
190
- this.name = name;
191
- this.attribs = attribs;
192
- this.type = type;
193
- }
194
- get nodeType() {
195
- return 1;
196
- }
197
- // DOM Level 1 aliases
198
- /**
199
- * Same as {@link name}.
200
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
201
- */
202
- get tagName() {
203
- return this.name;
204
- }
205
- set tagName(name) {
206
- this.name = name;
207
- }
208
- get attributes() {
209
- return Object.keys(this.attribs).map((name) => {
210
- var _a, _b;
211
- return ({
212
- name,
213
- value: this.attribs[name],
214
- namespace: (_a = this["x-attribsNamespace"]) === null || _a === void 0 ? void 0 : _a[name],
215
- prefix: (_b = this["x-attribsPrefix"]) === null || _b === void 0 ? void 0 : _b[name],
216
- });
217
- });
218
- }
219
- }
220
- /**
221
- * @param node Node to check.
222
- * @returns `true` if the node is a `Element`, `false` otherwise.
223
- */
224
- function isTag(node) {
225
- return isTag$1(node);
226
- }
227
- /**
228
- * @param node Node to check.
229
- * @returns `true` if the node has the type `CDATA`, `false` otherwise.
230
- */
231
- function isCDATA(node) {
232
- return node.type === ElementType.CDATA;
233
- }
234
- /**
235
- * @param node Node to check.
236
- * @returns `true` if the node has the type `Text`, `false` otherwise.
237
- */
238
- function isText(node) {
239
- return node.type === ElementType.Text;
240
- }
241
- /**
242
- * @param node Node to check.
243
- * @returns `true` if the node has the type `Comment`, `false` otherwise.
244
- */
245
- function isComment(node) {
246
- return node.type === ElementType.Comment;
247
- }
248
- /**
249
- * @param node Node to check.
250
- * @returns `true` if the node has the type `ProcessingInstruction`, `false` otherwise.
251
- */
252
- function isDirective(node) {
253
- return node.type === ElementType.Directive;
254
- }
255
- /**
256
- * @param node Node to check.
257
- * @returns `true` if the node has the type `ProcessingInstruction`, `false` otherwise.
258
- */
259
- function isDocument(node) {
260
- return node.type === ElementType.Root;
261
- }
262
- /**
263
- * Clone a node, and optionally its children.
264
- *
265
- * @param recursive Clone child nodes as well.
266
- * @returns A clone of the node.
267
- */
268
- function cloneNode(node, recursive = false) {
269
- let result;
270
- if (isText(node)) {
271
- result = new Text(node.data);
272
- }
273
- else if (isComment(node)) {
274
- result = new Comment(node.data);
275
- }
276
- else if (isTag(node)) {
277
- const children = recursive ? cloneChildren(node.children) : [];
278
- const clone = new Element(node.name, { ...node.attribs }, children);
279
- children.forEach((child) => (child.parent = clone));
280
- if (node.namespace != null) {
281
- clone.namespace = node.namespace;
282
- }
283
- if (node["x-attribsNamespace"]) {
284
- clone["x-attribsNamespace"] = { ...node["x-attribsNamespace"] };
285
- }
286
- if (node["x-attribsPrefix"]) {
287
- clone["x-attribsPrefix"] = { ...node["x-attribsPrefix"] };
288
- }
289
- result = clone;
290
- }
291
- else if (isCDATA(node)) {
292
- const children = recursive ? cloneChildren(node.children) : [];
293
- const clone = new CDATA(children);
294
- children.forEach((child) => (child.parent = clone));
295
- result = clone;
296
- }
297
- else if (isDocument(node)) {
298
- const children = recursive ? cloneChildren(node.children) : [];
299
- const clone = new Document(children);
300
- children.forEach((child) => (child.parent = clone));
301
- if (node["x-mode"]) {
302
- clone["x-mode"] = node["x-mode"];
303
- }
304
- result = clone;
305
- }
306
- else if (isDirective(node)) {
307
- const instruction = new ProcessingInstruction(node.name, node.data);
308
- if (node["x-name"] != null) {
309
- instruction["x-name"] = node["x-name"];
310
- instruction["x-publicId"] = node["x-publicId"];
311
- instruction["x-systemId"] = node["x-systemId"];
312
- }
313
- result = instruction;
314
- }
315
- else {
316
- throw new Error(`Not implemented yet: ${node.type}`);
317
- }
318
- result.startIndex = node.startIndex;
319
- result.endIndex = node.endIndex;
320
- if (node.sourceCodeLocation != null) {
321
- result.sourceCodeLocation = node.sourceCodeLocation;
322
- }
323
- return result;
324
- }
325
- function cloneChildren(childs) {
326
- const children = childs.map((child) => cloneNode(child, true));
327
- for (let i = 1; i < children.length; i++) {
328
- children[i].prev = children[i - 1];
329
- children[i - 1].next = children[i];
330
- }
331
- return children;
332
- }
333
-
334
- export { CDATA, Comment, DataNode, Document, Element, Node, NodeWithChildren, ProcessingInstruction, Text, cloneNode, isCDATA, isComment, isDirective, isDocument, isTag, isText };