@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.
- package/dist/src/addon/async/pg/PgJobRepository.js +26 -0
- package/dist/src/addon/auth/api-key/@apiKeyConnectionGuard.js +16 -0
- package/dist/src/addon/auth/api-key/@apiKeyGuard.js +17 -0
- package/dist/src/addon/auth/api-key/ApiKey.js +45 -0
- package/dist/src/addon/auth/api-key/ApiKeyConnectionGuardMiddleware.js +57 -0
- package/dist/src/addon/auth/api-key/ApiKeyGuardMiddleware.js +45 -0
- package/dist/src/addon/auth/api-key/ApiKeyRepository.js +22 -0
- package/dist/src/addon/auth/api-key/PgApiKeyRepository.js +53 -0
- package/dist/src/addon/auth/api-key/RemoteApiKeyRepository.js +62 -0
- package/dist/src/addon/auth/jwt/@jwtConnectionGuard.js +16 -0
- package/dist/src/addon/auth/jwt/@jwtGuard.js +17 -0
- package/dist/src/addon/auth/jwt/Jwt.js +53 -0
- package/dist/src/addon/auth/jwt/JwtAccessAndRefreshTokenDto.js +20 -0
- package/dist/src/addon/auth/jwt/JwtConfig.js +28 -0
- package/dist/src/addon/auth/jwt/JwtConnectionGuardMiddleware.js +57 -0
- package/dist/src/addon/auth/jwt/JwtGuardMiddleware.js +45 -0
- package/dist/src/addon/auth/jwt/JwtRefreshToken.js +56 -0
- package/dist/src/addon/auth/jwt/JwtRefreshTokenRepository.js +25 -0
- package/dist/src/addon/auth/jwt/JwtSigner.js +36 -0
- package/dist/src/addon/auth/jwt/JwtTokenDto.js +22 -0
- package/dist/src/addon/auth/jwt/PgJwtRefreshTokenRepository.js +21 -0
- package/dist/src/addon/chat-bot/anthropic/AnthropicChatAdapter.js +135 -0
- package/dist/src/addon/chat-bot/deepseek/DeepSeekChatAdapter.js +137 -0
- package/dist/src/addon/chat-bot/google/GoogleChatAdapter.js +128 -0
- package/dist/src/addon/chat-bot/openia/OpenaiChatAdapter.js +117 -0
- package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatMemory.js +6 -4
- package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatRepository.js +6 -5
- package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatRepository.js +2 -2
- package/dist/src/addon/chat-bot/wabot/WabotChatAdapter.js +41 -0
- package/dist/src/addon/chat-controller/cmd/@cmd.js +24 -0
- package/dist/src/addon/chat-controller/cmd/CmdChannel.js +91 -0
- package/dist/src/{channels → addon/chat-controller}/socket/@socket.js +10 -4
- package/dist/src/{channels → addon/chat-controller}/socket/SocketChannel.js +9 -23
- package/dist/src/{channels → addon/chat-controller}/socket/SocketChannelConfig.js +1 -1
- package/dist/src/{channels → addon/chat-controller}/telegram/@telegram.js +10 -4
- package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannel.js +4 -22
- package/dist/src/addon/chat-controller/whatsapp/@whatsApp.js +26 -0
- package/dist/src/{channels → addon/chat-controller}/whatsapp/EnvWhatsAppRepository.js +3 -3
- package/dist/src/{channels → addon/chat-controller}/whatsapp/PgWhatsAppRepository.js +2 -2
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsApp.js +2 -4
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannel.js +6 -18
- package/dist/src/addon/chat-controller/whatsapp/WhatsAppReceiver.js +10 -0
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppSender.js +15 -39
- package/dist/src/addon/chat-controller/whatsapp/cloud-api/WhatsAppReceiverByCloudApi.js +97 -0
- package/dist/src/{channels/whatsapp → addon/chat-controller/whatsapp/cloud-api}/WhatsAppSenderByCloudApi.js +27 -20
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppProxyContracts.js +5 -0
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppReceiverByWabotProxy.js +65 -0
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppSenderByWabotProxy.js +61 -0
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppWabotProxyConnection.js +45 -0
- package/dist/src/{pre-made/module → addon/mindset}/html/HtmlModule.js +7 -7
- package/dist/src/core/auth/Auth.js +33 -0
- package/dist/src/core/{Persistent.js → entity/Entity.js} +24 -12
- package/dist/src/core/env/Env.js +39 -0
- package/dist/src/core/error/CustomError.js +15 -0
- package/dist/src/core/injection/index.js +4 -0
- package/dist/src/core/mapper/Mapper.js +42 -0
- package/dist/src/core/password/Password.js +30 -0
- package/dist/src/core/random/Random.js +65 -0
- package/dist/src/core/storable/Storable.js +8 -0
- package/dist/src/core/validation/core/validateArray.js +51 -0
- package/dist/src/core/validation/core/validateModel.js +36 -0
- package/dist/src/{validation/metadata/@isNumber.js → core/validation/metadata/@isArray.js} +5 -4
- package/dist/src/{validation/metadata/@isDate.js → core/validation/metadata/@isModel.js} +5 -4
- package/dist/src/{validation → core/validation}/metadata/@isOptional.js +1 -1
- package/dist/src/core/validation/metadata/ValidationMetadataStore.js +98 -0
- package/dist/src/core/validation/modelInfo.js +9 -0
- package/dist/src/{validation/validateModel2.js → core/validation/validate.js} +3 -3
- package/dist/src/{validation/metadata → core/validation/validators/is-boolean}/@isBoolean.js +3 -3
- package/dist/src/core/validation/validators/is-date/@isDate.js +17 -0
- package/dist/src/core/validation/validators/is-in/@isIn.js +18 -0
- package/dist/src/core/validation/validators/is-in/validateIsIn.js +12 -0
- package/dist/src/{validation/metadata → core/validation/validators/is-not-empty}/@isNotEmpty.js +3 -3
- package/dist/src/core/validation/validators/is-number/@isNumber.js +17 -0
- package/dist/src/{validation/metadata → core/validation/validators/is-present}/@isPresent.js +3 -3
- package/dist/src/{validation/metadata → core/validation/validators/is-string}/@isString.js +3 -3
- package/dist/src/{validation/metadata → core/validation/validators/max}/@max.js +3 -3
- package/dist/src/{validation/metadata → core/validation/validators/min}/@min.js +3 -3
- package/dist/src/feature/async/@command.js +11 -0
- package/dist/src/feature/async/@commandHandler.js +12 -0
- package/dist/src/feature/async/Async.js +38 -0
- package/dist/src/feature/async/Command.js +9 -0
- package/dist/src/feature/async/CommandMetadataStore.js +38 -0
- package/dist/src/feature/async/Job.js +27 -0
- package/dist/src/feature/async/JobRepository.js +31 -0
- package/dist/src/feature/async/JobRunner.js +48 -0
- package/dist/src/feature/async/JobsEventsHub.js +36 -0
- package/dist/src/feature/async/runCommandHandlers.js +29 -0
- package/dist/src/{core/chat → feature/chat-bot}/Chat.js +2 -2
- package/dist/src/feature/chat-bot/ChatAdapter.js +7 -0
- package/dist/src/feature/chat-bot/ChatBot.js +73 -0
- package/dist/src/feature/chat-bot/ChatItem.js +24 -0
- package/dist/src/feature/chat-bot/ChatMemory.js +10 -0
- package/dist/src/{core/chat/repository/IChatRepository.js → feature/chat-bot/ChatRepository.js} +2 -8
- package/dist/src/feature/chat-bot/IChatItem.js +3 -0
- package/dist/src/{chatbot → feature/chat-bot}/metadata/@chatBot.js +1 -1
- package/dist/src/{chatbot → feature/chat-bot}/metadata/ChatBotMetadataStore.js +1 -1
- package/dist/src/{controller/channel → feature/chat-controller}/ChatResolver.js +6 -4
- package/dist/src/{controller → feature/chat-controller}/metadata/ControllerMetadataStore.js +1 -1
- package/dist/src/{controller → feature/chat-controller}/metadata/controller/@chatController.js +1 -1
- package/dist/src/feature/chat-controller/runChatControllers.js +83 -0
- package/dist/src/{channels → feature}/express/ExpressProvider.js +2 -4
- package/dist/src/{channels → feature}/http/HttpServerProvider.js +2 -2
- package/dist/src/{mindset → feature/mindset}/IMindset.js +6 -0
- package/dist/src/feature/mindset/MindsetOperator.js +180 -0
- package/dist/src/{mindset → feature/mindset}/metadata/MindsetMetadataStore.js +1 -1
- package/dist/src/{mindset → feature/mindset}/metadata/functions/@mindsetFunction.js +1 -1
- package/dist/src/{mindset → feature/mindset}/metadata/mindsets/@mindset.js +1 -1
- package/dist/src/{mindset → feature/mindset}/metadata/modules/@mindsetModule.js +1 -2
- package/dist/src/{mindset → feature/mindset}/metadata/params/@param.js +1 -1
- package/dist/src/feature/money/Money.js +61 -0
- package/dist/src/feature/money/MoneyDto.js +22 -0
- package/dist/src/{repository → feature}/pg/PgCrudRepository.js +24 -10
- package/dist/src/{repository → feature}/pg/PgRepositoryBase.js +2 -2
- package/dist/src/feature/rest-controller/injection-tokens.js +4 -0
- package/dist/src/{rest-controller/metadata/@post.js → feature/rest-controller/metadata/@middleware.js} +5 -8
- package/dist/src/feature/rest-controller/metadata/@onDelete.js +7 -0
- package/dist/src/feature/rest-controller/metadata/@onGet.js +7 -0
- package/dist/src/feature/rest-controller/metadata/@onPost.js +7 -0
- package/dist/src/feature/rest-controller/metadata/@onPut.js +7 -0
- package/dist/src/{rest-controller → feature/rest-controller}/metadata/@restController.js +2 -2
- package/dist/src/{rest-controller → feature/rest-controller}/metadata/RestControllerMetadataStore.js +14 -1
- package/dist/src/{rest-controller/metadata/@get.js → feature/rest-controller/metadata/methodDecorator.js} +5 -5
- package/dist/src/feature/rest-controller/runRestControllers.js +103 -0
- package/dist/src/{channels → feature}/socket/SocketServerProvider.js +2 -2
- package/dist/src/feature/socket-controller/metadata/@connectionMiddleware.js +16 -0
- package/dist/src/feature/socket-controller/metadata/@socketConnection.js +18 -0
- package/dist/src/feature/socket-controller/metadata/@socketController.js +15 -0
- package/dist/src/feature/socket-controller/metadata/@socketEvent.js +18 -0
- package/dist/src/feature/socket-controller/metadata/SocketControllerMetadataStore.js +65 -0
- package/dist/src/feature/socket-controller/runSocketControllers.js +99 -0
- package/dist/src/index.d.ts +1219 -718
- package/dist/src/index.js +147 -102
- package/package.json +8 -2
- package/dist/src/_virtual/_commonjsHelpers.js +0 -5
- package/dist/src/_virtual/cjs.js +0 -7
- package/dist/src/ai/deepseek/DeepSeekChatBotAdapter.js +0 -107
- package/dist/src/ai/openia/OpenaiChatBotAdapter.js +0 -88
- package/dist/src/channels/cmd/@cmd.js +0 -18
- package/dist/src/channels/cmd/CmdChannel.js +0 -73
- package/dist/src/channels/wabot/WabotDevConnection.js +0 -57
- package/dist/src/channels/wabot/WabotDevSocketContracts.js +0 -10
- package/dist/src/channels/whatsapp/@whatsapp.js +0 -20
- package/dist/src/channels/whatsapp/WhatsAppReceiver.js +0 -59
- package/dist/src/channels/whatsapp/WhatsAppReceiverByDevConnection.js +0 -32
- package/dist/src/channels/whatsapp/WhatsAppReceiverByWebHook.js +0 -63
- package/dist/src/channels/whatsapp/WhatsAppSenderByDevConnection.js +0 -61
- package/dist/src/chatbot/ChatBot.js +0 -51
- package/dist/src/chatbot/ChatBotAdapter.js +0 -72
- package/dist/src/controller/channel/UserResolver.js +0 -21
- package/dist/src/core/IMessageContext.js +0 -12
- package/dist/src/core/chat/ChatItem.js +0 -15
- package/dist/src/core/chat/repository/IChatMemory.js +0 -10
- package/dist/src/core/user/IUserRepository.js +0 -19
- package/dist/src/core/user/User.js +0 -26
- package/dist/src/env/WabotEnv.js +0 -27
- package/dist/src/injection/index.js +0 -4
- package/dist/src/mindset/MindsetOperator.js +0 -101
- package/dist/src/node_modules/@selderee/plugin-htmlparser2/lib/hp2-builder.js +0 -90
- package/dist/src/node_modules/deepmerge/dist/cjs.js +0 -142
- package/dist/src/node_modules/dom-serializer/lib/esm/foreignNames.js +0 -102
- package/dist/src/node_modules/dom-serializer/lib/esm/index.js +0 -186
- package/dist/src/node_modules/domelementtype/lib/esm/index.js +0 -53
- package/dist/src/node_modules/domhandler/lib/esm/index.js +0 -148
- package/dist/src/node_modules/domhandler/lib/esm/node.js +0 -334
- package/dist/src/node_modules/entities/lib/esm/decode.js +0 -458
- package/dist/src/node_modules/entities/lib/esm/decode_codepoint.js +0 -62
- package/dist/src/node_modules/entities/lib/esm/escape.js +0 -99
- package/dist/src/node_modules/entities/lib/esm/generated/decode-data-html.js +0 -8
- package/dist/src/node_modules/entities/lib/esm/generated/decode-data-xml.js +0 -8
- package/dist/src/node_modules/html-to-text/lib/html-to-text.js +0 -2147
- package/dist/src/node_modules/htmlparser2/lib/esm/Parser.js +0 -491
- package/dist/src/node_modules/htmlparser2/lib/esm/Tokenizer.js +0 -928
- package/dist/src/node_modules/htmlparser2/lib/esm/index.js +0 -18
- package/dist/src/node_modules/leac/lib/leac.js +0 -3
- package/dist/src/node_modules/parseley/lib/parseley.js +0 -270
- package/dist/src/node_modules/peberminta/lib/core.js +0 -171
- package/dist/src/node_modules/selderee/lib/selderee.js +0 -380
- package/dist/src/pre-made/module/authentication/AuthenticationModule.js +0 -97
- package/dist/src/pre-made/module/authentication/requests/SendOneTimePasswordRequest.js +0 -25
- package/dist/src/pre-made/module/authentication/requests/ValidateOneTimePasswordRequest.js +0 -25
- package/dist/src/pre-made/module/register-user/RegisterUserModule.js +0 -56
- package/dist/src/pre-made/module/register-user/requests/RegisterUserWithEmailRequest.js +0 -25
- package/dist/src/pre-made/repository/user/pg/PgUserRepository.js +0 -33
- package/dist/src/pre-made/repository/user/ram/RamUserRepository.js +0 -27
- package/dist/src/pre-made/service/EmailService.js +0 -13
- package/dist/src/pre-made/service/OtpService.js +0 -14
- package/dist/src/rest-controller/runRestControllers.js +0 -74
- package/dist/src/server/prepareChatContainer.js +0 -43
- package/dist/src/server/runChannel.js +0 -27
- package/dist/src/server/runServer.js +0 -40
- package/dist/src/validation/metadata/@validable.js +0 -14
- package/dist/src/validation/metadata/ValidationMetadataStore.js +0 -55
- package/dist/src/validation/validators/validateModel.js +0 -47
- /package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatMemory.js +0 -0
- /package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannelConfig.js +0 -0
- /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannelConfig.js +0 -0
- /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppRepository.js +0 -0
- /package/dist/src/{injection → core/injection}/Container.js +0 -0
- /package/dist/src/{logger → core/logger}/Logger.js +0 -0
- /package/dist/src/{validation/validators → core/validation/core}/validateIsOptional.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/is-boolean}/validateIsBoolean.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/is-date}/validateIsDate.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/is-not-empty}/validateIsNotEmpty.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/is-number}/validateIsNumber.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/is-present}/validateIsPresent.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/is-string}/validateIsString.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/max}/validateMax.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/min}/validateMin.js +0 -0
- /package/dist/src/{mindset → feature/mindset}/metadata/functions/decoratorNames.js +0 -0
- /package/dist/src/{mindset → feature/mindset}/metadata/mindsets/decoratorNames.js +0 -0
- /package/dist/src/{mindset → feature/mindset}/metadata/modules/decoratorNames.js +0 -0
- /package/dist/src/{mindset → feature/mindset}/metadata/params/decoratorNames.js +0 -0
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Parser } from './Parser.js';
|
|
2
|
-
import { DomHandler } from '../../../domhandler/lib/esm/index.js';
|
|
3
|
-
export { default as Tokenizer } from './Tokenizer.js';
|
|
4
|
-
|
|
5
|
-
// Helper methods
|
|
6
|
-
/**
|
|
7
|
-
* Parses the data, returns the resulting document.
|
|
8
|
-
*
|
|
9
|
-
* @param data The data that should be parsed.
|
|
10
|
-
* @param options Optional options for the parser and DOM builder.
|
|
11
|
-
*/
|
|
12
|
-
function parseDocument(data, options) {
|
|
13
|
-
const handler = new DomHandler(undefined, options);
|
|
14
|
-
new Parser(handler, options).end(data);
|
|
15
|
-
return handler.root;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { DomHandler as DefaultHandler, DomHandler, Parser, parseDocument };
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
const e=/\n/g;function n(n){const o=[...n.matchAll(e)].map((e=>e.index||0));o.unshift(-1);const s=t(o,0,o.length);return e=>r(s,e)}function t(e,n,r){if(r-n==1)return {offset:e[n],index:n+1};const o=Math.ceil((n+r)/2),s=t(e,n,o),l=t(e,o,r);return {offset:s.offset,low:s,high:l}}function r(e,n){return function(e){return Object.prototype.hasOwnProperty.call(e,"index")}(e)?{line:e.index,column:n-e.offset}:r(e.high.offset<n?e.high:e.low,n)}function o(e,t="",r={}){const o="string"!=typeof t?t:r,l="string"==typeof t?t:"",c=e.map(s),f=!!o.lineNumbers;return function(e,t=0){const r=f?n(e):()=>({line:0,column:0});let o=t;const s=[];e:for(;o<e.length;){let n=false;for(const t of c){t.regex.lastIndex=o;const c=t.regex.exec(e);if(c&&c[0].length>0){if(!t.discard){const e=r(o),n="string"==typeof t.replace?c[0].replace(new RegExp(t.regex.source,t.regex.flags),t.replace):c[0];s.push({state:l,name:t.name,text:n,offset:o,len:c[0].length,line:e.line,column:e.column});}if(o=t.regex.lastIndex,n=true,t.push){const n=t.push(e,o);s.push(...n.tokens),o=n.offset;}if(t.pop)break e;break}}if(!n)break}return {tokens:s,offset:o,complete:e.length<=o}}}function s(e,n){return {...e,regex:l(e,n)}}function l(e,n){if(0===e.name.length)throw new Error(`Rule #${n} has empty name, which is not allowed.`);if(function(e){return Object.prototype.hasOwnProperty.call(e,"regex")}(e))return function(e){if(e.global)throw new Error(`Regular expression /${e.source}/${e.flags} contains the global flag, which is not allowed.`);return e.sticky?e:new RegExp(e.source,e.flags+"y")}(e.regex);if(function(e){return Object.prototype.hasOwnProperty.call(e,"str")}(e)){if(0===e.str.length)throw new Error(`Rule #${n} ("${e.name}") has empty "str" property, which is not allowed.`);return new RegExp(c(e.str),"y")}return new RegExp(c(e.name),"y")}function c(e){return e.replace(/[-[\]{}()*+!<=:?./\\^$|#\s,]/g,"\\$&")}
|
|
2
|
-
|
|
3
|
-
export { o as createLexer };
|
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
import { createLexer as o } from '../../leac/lib/leac.js';
|
|
2
|
-
import { middle, map, many, choice, option, eitherOr as otherwise, flatten, leftAssoc2, token, ab, many1, abc, left, right } from '../../peberminta/lib/core.js';
|
|
3
|
-
|
|
4
|
-
const ws = `(?:[ \\t\\r\\n\\f]*)`;
|
|
5
|
-
const nl = `(?:\\n|\\r\\n|\\r|\\f)`;
|
|
6
|
-
const nonascii = `[^\\x00-\\x7F]`;
|
|
7
|
-
const unicode = `(?:\\\\[0-9a-f]{1,6}(?:\\r\\n|[ \\n\\r\\t\\f])?)`;
|
|
8
|
-
const escape = `(?:\\\\[^\\n\\r\\f0-9a-f])`;
|
|
9
|
-
const nmstart = `(?:[_a-z]|${nonascii}|${unicode}|${escape})`;
|
|
10
|
-
const nmchar = `(?:[_a-z0-9-]|${nonascii}|${unicode}|${escape})`;
|
|
11
|
-
const name = `(?:${nmchar}+)`;
|
|
12
|
-
const ident = `(?:[-]?${nmstart}${nmchar}*)`;
|
|
13
|
-
const string1 = `'([^\\n\\r\\f\\\\']|\\\\${nl}|${nonascii}|${unicode}|${escape})*'`;
|
|
14
|
-
const string2 = `"([^\\n\\r\\f\\\\"]|\\\\${nl}|${nonascii}|${unicode}|${escape})*"`;
|
|
15
|
-
const lexSelector = o([
|
|
16
|
-
{ name: 'ws', regex: new RegExp(ws) },
|
|
17
|
-
{ name: 'hash', regex: new RegExp(`#${name}`, 'i') },
|
|
18
|
-
{ name: 'ident', regex: new RegExp(ident, 'i') },
|
|
19
|
-
{ name: 'str1', regex: new RegExp(string1, 'i') },
|
|
20
|
-
{ name: 'str2', regex: new RegExp(string2, 'i') },
|
|
21
|
-
{ name: '*' },
|
|
22
|
-
{ name: '.' },
|
|
23
|
-
{ name: ',' },
|
|
24
|
-
{ name: '[' },
|
|
25
|
-
{ name: ']' },
|
|
26
|
-
{ name: '=' },
|
|
27
|
-
{ name: '>' },
|
|
28
|
-
{ name: '|' },
|
|
29
|
-
{ name: '+' },
|
|
30
|
-
{ name: '~' },
|
|
31
|
-
{ name: '^' },
|
|
32
|
-
{ name: '$' },
|
|
33
|
-
]);
|
|
34
|
-
const lexEscapedString = o([
|
|
35
|
-
{ name: 'unicode', regex: new RegExp(unicode, 'i') },
|
|
36
|
-
{ name: 'escape', regex: new RegExp(escape, 'i') },
|
|
37
|
-
{ name: 'any', regex: new RegExp('[\\s\\S]', 'i') }
|
|
38
|
-
]);
|
|
39
|
-
function sumSpec([a0, a1, a2], [b0, b1, b2]) {
|
|
40
|
-
return [a0 + b0, a1 + b1, a2 + b2];
|
|
41
|
-
}
|
|
42
|
-
function sumAllSpec(ss) {
|
|
43
|
-
return ss.reduce(sumSpec, [0, 0, 0]);
|
|
44
|
-
}
|
|
45
|
-
const unicodeEscapedSequence_ = token((t) => t.name === 'unicode' ? String.fromCodePoint(parseInt(t.text.slice(1), 16)) : undefined);
|
|
46
|
-
const escapedSequence_ = token((t) => t.name === 'escape' ? t.text.slice(1) : undefined);
|
|
47
|
-
const anyChar_ = token((t) => t.name === 'any' ? t.text : undefined);
|
|
48
|
-
const escapedString_ = map(many(choice(unicodeEscapedSequence_, escapedSequence_, anyChar_)), (cs) => cs.join(''));
|
|
49
|
-
function unescape(escapedString) {
|
|
50
|
-
const lexerResult = lexEscapedString(escapedString);
|
|
51
|
-
const result = escapedString_({ tokens: lexerResult.tokens, options: undefined }, 0);
|
|
52
|
-
return result.value;
|
|
53
|
-
}
|
|
54
|
-
function literal(name) {
|
|
55
|
-
return token((t) => t.name === name ? true : undefined);
|
|
56
|
-
}
|
|
57
|
-
const whitespace_ = token((t) => t.name === 'ws' ? null : undefined);
|
|
58
|
-
const optionalWhitespace_ = option(whitespace_, null);
|
|
59
|
-
function optionallySpaced(parser) {
|
|
60
|
-
return middle(optionalWhitespace_, parser, optionalWhitespace_);
|
|
61
|
-
}
|
|
62
|
-
const identifier_ = token((t) => t.name === 'ident' ? unescape(t.text) : undefined);
|
|
63
|
-
const hashId_ = token((t) => t.name === 'hash' ? unescape(t.text.slice(1)) : undefined);
|
|
64
|
-
const string_ = token((t) => t.name.startsWith('str') ? unescape(t.text.slice(1, -1)) : undefined);
|
|
65
|
-
const namespace_ = left(option(identifier_, ''), literal('|'));
|
|
66
|
-
const qualifiedName_ = otherwise(ab(namespace_, identifier_, (ns, name) => ({ name: name, namespace: ns })), map(identifier_, (name) => ({ name: name, namespace: null })));
|
|
67
|
-
const uniSelector_ = otherwise(ab(namespace_, literal('*'), (ns) => ({ type: 'universal', namespace: ns, specificity: [0, 0, 0] })), map(literal('*'), () => ({ type: 'universal', namespace: null, specificity: [0, 0, 0] })));
|
|
68
|
-
const tagSelector_ = map(qualifiedName_, ({ name, namespace }) => ({
|
|
69
|
-
type: 'tag',
|
|
70
|
-
name: name,
|
|
71
|
-
namespace: namespace,
|
|
72
|
-
specificity: [0, 0, 1]
|
|
73
|
-
}));
|
|
74
|
-
const classSelector_ = ab(literal('.'), identifier_, (fullstop, name) => ({
|
|
75
|
-
type: 'class',
|
|
76
|
-
name: name,
|
|
77
|
-
specificity: [0, 1, 0]
|
|
78
|
-
}));
|
|
79
|
-
const idSelector_ = map(hashId_, (name) => ({
|
|
80
|
-
type: 'id',
|
|
81
|
-
name: name,
|
|
82
|
-
specificity: [1, 0, 0]
|
|
83
|
-
}));
|
|
84
|
-
const attrModifier_ = token((t) => {
|
|
85
|
-
if (t.name === 'ident') {
|
|
86
|
-
if (t.text === 'i' || t.text === 'I') {
|
|
87
|
-
return 'i';
|
|
88
|
-
}
|
|
89
|
-
if (t.text === 's' || t.text === 'S') {
|
|
90
|
-
return 's';
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return undefined;
|
|
94
|
-
});
|
|
95
|
-
const attrValue_ = otherwise(ab(string_, option(right(optionalWhitespace_, attrModifier_), null), (v, mod) => ({ value: v, modifier: mod })), ab(identifier_, option(right(whitespace_, attrModifier_), null), (v, mod) => ({ value: v, modifier: mod })));
|
|
96
|
-
const attrMatcher_ = choice(map(literal('='), () => '='), ab(literal('~'), literal('='), () => '~='), ab(literal('|'), literal('='), () => '|='), ab(literal('^'), literal('='), () => '^='), ab(literal('$'), literal('='), () => '$='), ab(literal('*'), literal('='), () => '*='));
|
|
97
|
-
const attrPresenceSelector_ = abc(literal('['), optionallySpaced(qualifiedName_), literal(']'), (lbr, { name, namespace }) => ({
|
|
98
|
-
type: 'attrPresence',
|
|
99
|
-
name: name,
|
|
100
|
-
namespace: namespace,
|
|
101
|
-
specificity: [0, 1, 0]
|
|
102
|
-
}));
|
|
103
|
-
const attrValueSelector_ = middle(literal('['), abc(optionallySpaced(qualifiedName_), attrMatcher_, optionallySpaced(attrValue_), ({ name, namespace }, matcher, { value, modifier }) => ({
|
|
104
|
-
type: 'attrValue',
|
|
105
|
-
name: name,
|
|
106
|
-
namespace: namespace,
|
|
107
|
-
matcher: matcher,
|
|
108
|
-
value: value,
|
|
109
|
-
modifier: modifier,
|
|
110
|
-
specificity: [0, 1, 0]
|
|
111
|
-
})), literal(']'));
|
|
112
|
-
const attrSelector_ = otherwise(attrPresenceSelector_, attrValueSelector_);
|
|
113
|
-
const typeSelector_ = otherwise(uniSelector_, tagSelector_);
|
|
114
|
-
const subclassSelector_ = choice(idSelector_, classSelector_, attrSelector_);
|
|
115
|
-
const compoundSelector_ = map(otherwise(flatten(typeSelector_, many(subclassSelector_)), many1(subclassSelector_)), (ss) => {
|
|
116
|
-
return {
|
|
117
|
-
type: 'compound',
|
|
118
|
-
list: ss,
|
|
119
|
-
specificity: sumAllSpec(ss.map(s => s.specificity))
|
|
120
|
-
};
|
|
121
|
-
});
|
|
122
|
-
const combinator_ = choice(map(literal('>'), () => '>'), map(literal('+'), () => '+'), map(literal('~'), () => '~'), ab(literal('|'), literal('|'), () => '||'));
|
|
123
|
-
const combinatorSeparator_ = otherwise(optionallySpaced(combinator_), map(whitespace_, () => ' '));
|
|
124
|
-
const complexSelector_ = leftAssoc2(compoundSelector_, map(combinatorSeparator_, (c) => (left, right) => ({
|
|
125
|
-
type: 'compound',
|
|
126
|
-
list: [...right.list, { type: 'combinator', combinator: c, left: left, specificity: left.specificity }],
|
|
127
|
-
specificity: sumSpec(left.specificity, right.specificity)
|
|
128
|
-
})), compoundSelector_);
|
|
129
|
-
function parse_(parser, str) {
|
|
130
|
-
if (!(typeof str === 'string' || str instanceof String)) {
|
|
131
|
-
throw new Error('Expected a selector string. Actual input is not a string!');
|
|
132
|
-
}
|
|
133
|
-
const lexerResult = lexSelector(str);
|
|
134
|
-
if (!lexerResult.complete) {
|
|
135
|
-
throw new Error(`The input "${str}" was only partially tokenized, stopped at offset ${lexerResult.offset}!\n` +
|
|
136
|
-
prettyPrintPosition(str, lexerResult.offset));
|
|
137
|
-
}
|
|
138
|
-
const result = optionallySpaced(parser)({ tokens: lexerResult.tokens, options: undefined }, 0);
|
|
139
|
-
if (!result.matched) {
|
|
140
|
-
throw new Error(`No match for "${str}" input!`);
|
|
141
|
-
}
|
|
142
|
-
if (result.position < lexerResult.tokens.length) {
|
|
143
|
-
const token = lexerResult.tokens[result.position];
|
|
144
|
-
throw new Error(`The input "${str}" was only partially parsed, stopped at offset ${token.offset}!\n` +
|
|
145
|
-
prettyPrintPosition(str, token.offset, token.len));
|
|
146
|
-
}
|
|
147
|
-
return result.value;
|
|
148
|
-
}
|
|
149
|
-
function prettyPrintPosition(str, offset, len = 1) {
|
|
150
|
-
return `${str.replace(/(\t)|(\r)|(\n)/g, (m, t, r) => t ? '\u2409' : r ? '\u240d' : '\u240a')}\n${''.padEnd(offset)}${'^'.repeat(len)}`;
|
|
151
|
-
}
|
|
152
|
-
function parse1(str) {
|
|
153
|
-
return parse_(complexSelector_, str);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function serialize(selector) {
|
|
157
|
-
if (!selector.type) {
|
|
158
|
-
throw new Error('This is not an AST node.');
|
|
159
|
-
}
|
|
160
|
-
switch (selector.type) {
|
|
161
|
-
case 'universal':
|
|
162
|
-
return _serNs(selector.namespace) + '*';
|
|
163
|
-
case 'tag':
|
|
164
|
-
return _serNs(selector.namespace) + _serIdent(selector.name);
|
|
165
|
-
case 'class':
|
|
166
|
-
return '.' + _serIdent(selector.name);
|
|
167
|
-
case 'id':
|
|
168
|
-
return '#' + _serIdent(selector.name);
|
|
169
|
-
case 'attrPresence':
|
|
170
|
-
return `[${_serNs(selector.namespace)}${_serIdent(selector.name)}]`;
|
|
171
|
-
case 'attrValue':
|
|
172
|
-
return `[${_serNs(selector.namespace)}${_serIdent(selector.name)}${selector.matcher}"${_serStr(selector.value)}"${(selector.modifier ? selector.modifier : '')}]`;
|
|
173
|
-
case 'combinator':
|
|
174
|
-
return serialize(selector.left) + selector.combinator;
|
|
175
|
-
case 'compound':
|
|
176
|
-
return selector.list.reduce((acc, node) => {
|
|
177
|
-
if (node.type === 'combinator') {
|
|
178
|
-
return serialize(node) + acc;
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
return acc + serialize(node);
|
|
182
|
-
}
|
|
183
|
-
}, '');
|
|
184
|
-
case 'list':
|
|
185
|
-
return selector.list.map(serialize).join(',');
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
function _serNs(ns) {
|
|
189
|
-
return (ns || ns === '')
|
|
190
|
-
? _serIdent(ns) + '|'
|
|
191
|
-
: '';
|
|
192
|
-
}
|
|
193
|
-
function _codePoint(char) {
|
|
194
|
-
return `\\${char.codePointAt(0).toString(16)} `;
|
|
195
|
-
}
|
|
196
|
-
function _serIdent(str) {
|
|
197
|
-
return str.replace(
|
|
198
|
-
/(^[0-9])|(^-[0-9])|(^-$)|([-0-9a-zA-Z_]|[^\x00-\x7F])|(\x00)|([\x01-\x1f]|\x7f)|([\s\S])/g, (m, d1, d2, hy, safe, nl, ctrl, other) => d1 ? _codePoint(d1) :
|
|
199
|
-
d2 ? '-' + _codePoint(d2.slice(1)) :
|
|
200
|
-
hy ? '\\-' :
|
|
201
|
-
safe ? safe :
|
|
202
|
-
nl ? '\ufffd' :
|
|
203
|
-
ctrl ? _codePoint(ctrl) :
|
|
204
|
-
'\\' + other);
|
|
205
|
-
}
|
|
206
|
-
function _serStr(str) {
|
|
207
|
-
return str.replace(
|
|
208
|
-
/(")|(\\)|(\x00)|([\x01-\x1f]|\x7f)/g, (m, dq, bs, nl, ctrl) => dq ? '\\"' :
|
|
209
|
-
bs ? '\\\\' :
|
|
210
|
-
nl ? '\ufffd' :
|
|
211
|
-
_codePoint(ctrl));
|
|
212
|
-
}
|
|
213
|
-
function normalize(selector) {
|
|
214
|
-
if (!selector.type) {
|
|
215
|
-
throw new Error('This is not an AST node.');
|
|
216
|
-
}
|
|
217
|
-
switch (selector.type) {
|
|
218
|
-
case 'compound': {
|
|
219
|
-
selector.list.forEach(normalize);
|
|
220
|
-
selector.list.sort((a, b) => _compareArrays(_getSelectorPriority(a), _getSelectorPriority(b)));
|
|
221
|
-
break;
|
|
222
|
-
}
|
|
223
|
-
case 'combinator': {
|
|
224
|
-
normalize(selector.left);
|
|
225
|
-
break;
|
|
226
|
-
}
|
|
227
|
-
case 'list': {
|
|
228
|
-
selector.list.forEach(normalize);
|
|
229
|
-
selector.list.sort((a, b) => (serialize(a) < serialize(b)) ? -1 : 1);
|
|
230
|
-
break;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
return selector;
|
|
234
|
-
}
|
|
235
|
-
function _getSelectorPriority(selector) {
|
|
236
|
-
switch (selector.type) {
|
|
237
|
-
case 'universal':
|
|
238
|
-
return [1];
|
|
239
|
-
case 'tag':
|
|
240
|
-
return [1];
|
|
241
|
-
case 'id':
|
|
242
|
-
return [2];
|
|
243
|
-
case 'class':
|
|
244
|
-
return [3, selector.name];
|
|
245
|
-
case 'attrPresence':
|
|
246
|
-
return [4, serialize(selector)];
|
|
247
|
-
case 'attrValue':
|
|
248
|
-
return [5, serialize(selector)];
|
|
249
|
-
case 'combinator':
|
|
250
|
-
return [15, serialize(selector)];
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
function compareSpecificity(a, b) {
|
|
254
|
-
return _compareArrays(a, b);
|
|
255
|
-
}
|
|
256
|
-
function _compareArrays(a, b) {
|
|
257
|
-
if (!Array.isArray(a) || !Array.isArray(b)) {
|
|
258
|
-
throw new Error('Arguments must be arrays.');
|
|
259
|
-
}
|
|
260
|
-
const shorter = (a.length < b.length) ? a.length : b.length;
|
|
261
|
-
for (let i = 0; i < shorter; i++) {
|
|
262
|
-
if (a[i] === b[i]) {
|
|
263
|
-
continue;
|
|
264
|
-
}
|
|
265
|
-
return (a[i] < b[i]) ? -1 : 1;
|
|
266
|
-
}
|
|
267
|
-
return a.length - b.length;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
export { compareSpecificity, normalize, parse1, serialize };
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
function token(
|
|
2
|
-
onToken,
|
|
3
|
-
onEnd) {
|
|
4
|
-
return (data, i) => {
|
|
5
|
-
let position = i;
|
|
6
|
-
let value = undefined;
|
|
7
|
-
if (i < data.tokens.length) {
|
|
8
|
-
value = onToken(data.tokens[i], data, i);
|
|
9
|
-
if (value !== undefined) {
|
|
10
|
-
position++;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return (value === undefined)
|
|
14
|
-
? { matched: false }
|
|
15
|
-
: {
|
|
16
|
-
matched: true,
|
|
17
|
-
position: position,
|
|
18
|
-
value: value
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function mapInner(r, f) {
|
|
23
|
-
return (r.matched) ? ({
|
|
24
|
-
matched: true,
|
|
25
|
-
position: r.position,
|
|
26
|
-
value: f(r.value, r.position)
|
|
27
|
-
}) : r;
|
|
28
|
-
}
|
|
29
|
-
function mapOuter(r, f) {
|
|
30
|
-
return (r.matched) ? f(r) : r;
|
|
31
|
-
}
|
|
32
|
-
function map(p, mapper) {
|
|
33
|
-
return (data, i) => mapInner(p(data, i), (v, j) => mapper(v, data, i, j));
|
|
34
|
-
}
|
|
35
|
-
function option(p, def) {
|
|
36
|
-
return (data, i) => {
|
|
37
|
-
const r = p(data, i);
|
|
38
|
-
return (r.matched)
|
|
39
|
-
? r
|
|
40
|
-
: {
|
|
41
|
-
matched: true,
|
|
42
|
-
position: i,
|
|
43
|
-
value: def
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
function choice(...ps) {
|
|
48
|
-
return (data, i) => {
|
|
49
|
-
for (const p of ps) {
|
|
50
|
-
const result = p(data, i);
|
|
51
|
-
if (result.matched) {
|
|
52
|
-
return result;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return { matched: false };
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
function otherwise(pa, pb) {
|
|
59
|
-
return (data, i) => {
|
|
60
|
-
const r1 = pa(data, i);
|
|
61
|
-
return (r1.matched)
|
|
62
|
-
? r1
|
|
63
|
-
: pb(data, i);
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
function takeWhile(p,
|
|
67
|
-
test) {
|
|
68
|
-
return (data, i) => {
|
|
69
|
-
const values = [];
|
|
70
|
-
let success = true;
|
|
71
|
-
do {
|
|
72
|
-
const r = p(data, i);
|
|
73
|
-
if (r.matched && test(r.value, values.length + 1, data, i, r.position)) {
|
|
74
|
-
values.push(r.value);
|
|
75
|
-
i = r.position;
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
success = false;
|
|
79
|
-
}
|
|
80
|
-
} while (success);
|
|
81
|
-
return {
|
|
82
|
-
matched: true,
|
|
83
|
-
position: i,
|
|
84
|
-
value: values
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
function many(p) {
|
|
89
|
-
return takeWhile(p, () => true);
|
|
90
|
-
}
|
|
91
|
-
function many1(p) {
|
|
92
|
-
return ab(p, many(p), (head, tail) => [head, ...tail]);
|
|
93
|
-
}
|
|
94
|
-
function ab(pa, pb, join) {
|
|
95
|
-
return (data, i) => mapOuter(pa(data, i), (ma) => mapInner(pb(data, ma.position), (vb, j) => join(ma.value, vb, data, i, j)));
|
|
96
|
-
}
|
|
97
|
-
function left(pa, pb) {
|
|
98
|
-
return ab(pa, pb, (va) => va);
|
|
99
|
-
}
|
|
100
|
-
function right(pa, pb) {
|
|
101
|
-
return ab(pa, pb, (va, vb) => vb);
|
|
102
|
-
}
|
|
103
|
-
function abc(pa, pb, pc, join) {
|
|
104
|
-
return (data, i) => mapOuter(pa(data, i), (ma) => mapOuter(pb(data, ma.position), (mb) => mapInner(pc(data, mb.position), (vc, j) => join(ma.value, mb.value, vc, data, i, j))));
|
|
105
|
-
}
|
|
106
|
-
function middle(pa, pb, pc) {
|
|
107
|
-
return abc(pa, pb, pc, (ra, rb) => rb);
|
|
108
|
-
}
|
|
109
|
-
function all(...ps) {
|
|
110
|
-
return (data, i) => {
|
|
111
|
-
const result = [];
|
|
112
|
-
let position = i;
|
|
113
|
-
for (const p of ps) {
|
|
114
|
-
const r1 = p(data, position);
|
|
115
|
-
if (r1.matched) {
|
|
116
|
-
result.push(r1.value);
|
|
117
|
-
position = r1.position;
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
return { matched: false };
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return {
|
|
124
|
-
matched: true,
|
|
125
|
-
position: position,
|
|
126
|
-
value: result
|
|
127
|
-
};
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
function flatten(...ps) {
|
|
131
|
-
return flatten1(all(...ps));
|
|
132
|
-
}
|
|
133
|
-
function flatten1(p) {
|
|
134
|
-
return map(p, (vs) => vs.flatMap((v) => v));
|
|
135
|
-
}
|
|
136
|
-
function chainReduce(acc,
|
|
137
|
-
f) {
|
|
138
|
-
return (data, i) => {
|
|
139
|
-
let loop = true;
|
|
140
|
-
let acc1 = acc;
|
|
141
|
-
let pos = i;
|
|
142
|
-
do {
|
|
143
|
-
const r = f(acc1, data, pos)(data, pos);
|
|
144
|
-
if (r.matched) {
|
|
145
|
-
acc1 = r.value;
|
|
146
|
-
pos = r.position;
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
loop = false;
|
|
150
|
-
}
|
|
151
|
-
} while (loop);
|
|
152
|
-
return {
|
|
153
|
-
matched: true,
|
|
154
|
-
position: pos,
|
|
155
|
-
value: acc1
|
|
156
|
-
};
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
function reduceLeft(acc, p,
|
|
160
|
-
reducer) {
|
|
161
|
-
return chainReduce(acc, (acc) => map(p, (v, data, i, j) => reducer(acc, v, data, i, j)));
|
|
162
|
-
}
|
|
163
|
-
function leftAssoc2(pLeft, pOper, pRight) {
|
|
164
|
-
return chain(pLeft, (v0) => reduceLeft(v0, ab(pOper, pRight, (f, y) => [f, y]), (acc, [f, y]) => f(acc, y)));
|
|
165
|
-
}
|
|
166
|
-
function chain(p,
|
|
167
|
-
f) {
|
|
168
|
-
return (data, i) => mapOuter(p(data, i), (m1) => f(m1.value, data, i, m1.position)(data, m1.position));
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export { ab, abc, all, all as and, chain, chainReduce, choice, otherwise as eitherOr, flatten, flatten1, left, leftAssoc2, many, many1, map, middle, option, choice as or, otherwise, reduceLeft, right, many1 as some, takeWhile, token };
|