@lakutata/entrypoint 3.0.0-beta.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.
- package/LICENSE +23 -0
- package/README.md +183 -0
- package/THIRD_PARTY_NOTICES.md +206 -0
- package/dist/cjs/Entrypoint.d.ts +868 -0
- package/dist/cjs/Entrypoint.js +998 -0
- package/dist/cjs/adapter/commander/CommanderCLIEntrypoint.d.ts +192 -0
- package/dist/cjs/adapter/commander/CommanderCLIEntrypoint.js +439 -0
- package/dist/cjs/adapter/commander/Prompt.d.ts +22 -0
- package/dist/cjs/adapter/commander/Prompt.js +164 -0
- package/dist/cjs/adapter/commander/Width.d.ts +12 -0
- package/dist/cjs/adapter/commander/Width.js +67 -0
- package/dist/cjs/adapter/electron/ElectronIPCServiceEntrypoint.d.ts +203 -0
- package/dist/cjs/adapter/electron/ElectronIPCServiceEntrypoint.js +249 -0
- package/dist/cjs/adapter/express/ExpressHTTPEntrypoint.d.ts +172 -0
- package/dist/cjs/adapter/express/ExpressHTTPEntrypoint.js +301 -0
- package/dist/cjs/adapter/express/Responders.d.ts +89 -0
- package/dist/cjs/adapter/express/Responders.js +71 -0
- package/dist/cjs/adapter/express/StaticUI.d.ts +83 -0
- package/dist/cjs/adapter/express/StaticUI.js +104 -0
- package/dist/cjs/adapter/fastify/FastifyHTTPEntrypoint.d.ts +156 -0
- package/dist/cjs/adapter/fastify/FastifyHTTPEntrypoint.js +339 -0
- package/dist/cjs/adapter/fastify/Responders.d.ts +88 -0
- package/dist/cjs/adapter/fastify/Responders.js +77 -0
- package/dist/cjs/adapter/http/HTTPServiceEntrypoint.d.ts +117 -0
- package/dist/cjs/adapter/http/HTTPServiceEntrypoint.js +257 -0
- package/dist/cjs/adapter/jsonrpc/JSONRPCProtocol.d.ts +194 -0
- package/dist/cjs/adapter/jsonrpc/JSONRPCProtocol.js +187 -0
- package/dist/cjs/adapter/jsonrpc/JSONRPCServiceEntrypoint.d.ts +154 -0
- package/dist/cjs/adapter/jsonrpc/JSONRPCServiceEntrypoint.js +397 -0
- package/dist/cjs/adapter/schedule/ScheduleEntrypoint.d.ts +86 -0
- package/dist/cjs/adapter/schedule/ScheduleEntrypoint.js +275 -0
- package/dist/cjs/adapter/socket.io/SocketIOServiceEntrypoint.d.ts +138 -0
- package/dist/cjs/adapter/socket.io/SocketIOServiceEntrypoint.js +216 -0
- package/dist/cjs/channel/BuiltinChannels.d.ts +18 -0
- package/dist/cjs/channel/BuiltinChannels.js +128 -0
- package/dist/cjs/channel/Channel.d.ts +196 -0
- package/dist/cjs/channel/Channel.js +106 -0
- package/dist/cjs/channel/EntrypointAdapter.d.ts +195 -0
- package/dist/cjs/channel/EntrypointAdapter.js +43 -0
- package/dist/cjs/context/BaseContext.d.ts +75 -0
- package/dist/cjs/context/BaseContext.js +90 -0
- package/dist/cjs/context/CLIContext.d.ts +38 -0
- package/dist/cjs/context/CLIContext.js +53 -0
- package/dist/cjs/context/HTTPContext.d.ts +52 -0
- package/dist/cjs/context/HTTPContext.js +78 -0
- package/dist/cjs/context/ScheduleContext.d.ts +47 -0
- package/dist/cjs/context/ScheduleContext.js +65 -0
- package/dist/cjs/context/ServiceContext.d.ts +47 -0
- package/dist/cjs/context/ServiceContext.js +62 -0
- package/dist/cjs/decorators/CLIAction.d.ts +120 -0
- package/dist/cjs/decorators/CLIAction.js +13 -0
- package/dist/cjs/decorators/HTTPAction.d.ts +178 -0
- package/dist/cjs/decorators/HTTPAction.js +14 -0
- package/dist/cjs/decorators/Prefix.d.ts +44 -0
- package/dist/cjs/decorators/Prefix.js +48 -0
- package/dist/cjs/decorators/Schedule.d.ts +120 -0
- package/dist/cjs/decorators/Schedule.js +64 -0
- package/dist/cjs/decorators/ServiceAction.d.ts +116 -0
- package/dist/cjs/decorators/ServiceAction.js +12 -0
- package/dist/cjs/decorators/UseMiddlewares.d.ts +52 -0
- package/dist/cjs/decorators/UseMiddlewares.js +58 -0
- package/dist/cjs/decorators/http/DELETE.d.ts +87 -0
- package/dist/cjs/decorators/http/DELETE.js +7 -0
- package/dist/cjs/decorators/http/GET.d.ts +89 -0
- package/dist/cjs/decorators/http/GET.js +7 -0
- package/dist/cjs/decorators/http/HEAD.d.ts +84 -0
- package/dist/cjs/decorators/http/HEAD.js +7 -0
- package/dist/cjs/decorators/http/OPTIONS.d.ts +80 -0
- package/dist/cjs/decorators/http/OPTIONS.js +7 -0
- package/dist/cjs/decorators/http/PATCH.d.ts +90 -0
- package/dist/cjs/decorators/http/PATCH.js +7 -0
- package/dist/cjs/decorators/http/POST.d.ts +91 -0
- package/dist/cjs/decorators/http/POST.js +7 -0
- package/dist/cjs/decorators/http/PUT.d.ts +92 -0
- package/dist/cjs/decorators/http/PUT.js +7 -0
- package/dist/cjs/exceptions/AccessDeniedException.d.ts +10 -0
- package/dist/cjs/exceptions/AccessDeniedException.js +17 -0
- package/dist/cjs/exceptions/ControllerActionNotFoundException.d.ts +9 -0
- package/dist/cjs/exceptions/ControllerActionNotFoundException.js +16 -0
- package/dist/cjs/exceptions/DuplicateActionNameException.d.ts +8 -0
- package/dist/cjs/exceptions/DuplicateActionNameException.js +15 -0
- package/dist/cjs/exceptions/EntrypointStoppedException.d.ts +9 -0
- package/dist/cjs/exceptions/EntrypointStoppedException.js +16 -0
- package/dist/cjs/exceptions/InvalidActionGroupException.d.ts +4 -0
- package/dist/cjs/exceptions/InvalidActionGroupException.js +11 -0
- package/dist/cjs/exceptions/InvalidChannelException.d.ts +8 -0
- package/dist/cjs/exceptions/InvalidChannelException.js +15 -0
- package/dist/cjs/exceptions/InvalidEntrypointAdapterException.d.ts +9 -0
- package/dist/cjs/exceptions/InvalidEntrypointAdapterException.js +16 -0
- package/dist/cjs/exceptions/InvalidMiddlewareException.d.ts +8 -0
- package/dist/cjs/exceptions/InvalidMiddlewareException.js +15 -0
- package/dist/cjs/exceptions/InvalidPrefixException.d.ts +8 -0
- package/dist/cjs/exceptions/InvalidPrefixException.js +15 -0
- package/dist/cjs/exceptions/MiddlewareNextCalledException.d.ts +8 -0
- package/dist/cjs/exceptions/MiddlewareNextCalledException.js +15 -0
- package/dist/cjs/exceptions/RouteNotFoundException.d.ts +9 -0
- package/dist/cjs/exceptions/RouteNotFoundException.js +16 -0
- package/dist/cjs/exceptions/ServiceInvokeException.d.ts +11 -0
- package/dist/cjs/exceptions/ServiceInvokeException.js +14 -0
- package/dist/cjs/exports/CTRLDecorators.d.ts +13 -0
- package/dist/cjs/exports/CTRLDecorators.js +38 -0
- package/dist/cjs/exports/Channel.d.ts +14 -0
- package/dist/cjs/exports/Channel.js +33 -0
- package/dist/cjs/exports/CommanderAdapter.d.ts +1 -0
- package/dist/cjs/exports/CommanderAdapter.js +8 -0
- package/dist/cjs/exports/ElectronAdapter.d.ts +1 -0
- package/dist/cjs/exports/ElectronAdapter.js +9 -0
- package/dist/cjs/exports/Entrypoint.d.ts +24 -0
- package/dist/cjs/exports/Entrypoint.js +55 -0
- package/dist/cjs/exports/ExpressAdapter.d.ts +4 -0
- package/dist/cjs/exports/ExpressAdapter.js +15 -0
- package/dist/cjs/exports/FastifyAdapter.d.ts +4 -0
- package/dist/cjs/exports/FastifyAdapter.js +14 -0
- package/dist/cjs/exports/JSONRPCAdapter.d.ts +2 -0
- package/dist/cjs/exports/JSONRPCAdapter.js +11 -0
- package/dist/cjs/exports/SocketIOAdapter.d.ts +1 -0
- package/dist/cjs/exports/SocketIOAdapter.js +9 -0
- package/dist/cjs/lib/AccessControl.d.ts +118 -0
- package/dist/cjs/lib/AccessControl.js +208 -0
- package/dist/cjs/lib/AccessControlRule.d.ts +91 -0
- package/dist/cjs/lib/AccessControlRule.js +76 -0
- package/dist/cjs/lib/ActionOptions.d.ts +67 -0
- package/dist/cjs/lib/ActionOptions.js +67 -0
- package/dist/cjs/lib/ActionResult.d.ts +28 -0
- package/dist/cjs/lib/ActionResult.js +28 -0
- package/dist/cjs/lib/ApplicationOf.d.ts +6 -0
- package/dist/cjs/lib/ApplicationOf.js +14 -0
- package/dist/cjs/lib/Controller.d.ts +59 -0
- package/dist/cjs/lib/Controller.js +64 -0
- package/dist/cjs/lib/ControllerEntrypoint.d.ts +168 -0
- package/dist/cjs/lib/ControllerEntrypoint.js +239 -0
- package/dist/cjs/lib/GetActionDTOAndOptions.d.ts +29 -0
- package/dist/cjs/lib/GetActionDTOAndOptions.js +49 -0
- package/dist/cjs/lib/HTTPErrors.d.ts +55 -0
- package/dist/cjs/lib/HTTPErrors.js +52 -0
- package/dist/cjs/lib/Middleware.d.ts +146 -0
- package/dist/cjs/lib/Middleware.js +144 -0
- package/dist/cjs/lib/Prefix.d.ts +98 -0
- package/dist/cjs/lib/Prefix.js +151 -0
- package/dist/cjs/lib/Result.d.ts +173 -0
- package/dist/cjs/lib/Result.js +153 -0
- package/dist/cjs/lib/ServiceResponseCodec.d.ts +82 -0
- package/dist/cjs/lib/ServiceResponseCodec.js +117 -0
- package/dist/cjs/lib/StringifyPattern.d.ts +7 -0
- package/dist/cjs/lib/StringifyPattern.js +58 -0
- package/dist/cjs/lib/UnsetValue.d.ts +12 -0
- package/dist/cjs/lib/UnsetValue.js +216 -0
- package/dist/cjs/lib/pattern/GlobPattern.d.ts +34 -0
- package/dist/cjs/lib/pattern/GlobPattern.js +68 -0
- package/dist/cjs/lib/pattern/PatternManager.d.ts +103 -0
- package/dist/cjs/lib/pattern/PatternManager.js +233 -0
- package/dist/cjs/lib/schedule/Cron.d.ts +56 -0
- package/dist/cjs/lib/schedule/Cron.js +282 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/types/CLIContextParams.d.ts +14 -0
- package/dist/cjs/types/CLIContextParams.js +2 -0
- package/dist/cjs/types/ErrorDescription.d.ts +14 -0
- package/dist/cjs/types/ErrorDescription.js +2 -0
- package/dist/cjs/types/HTTPContextParams.d.ts +27 -0
- package/dist/cjs/types/HTTPContextParams.js +2 -0
- package/dist/cjs/types/ScheduleContextParams.d.ts +21 -0
- package/dist/cjs/types/ScheduleContextParams.js +2 -0
- package/dist/cjs/types/ServiceContextParams.d.ts +16 -0
- package/dist/cjs/types/ServiceContextParams.js +2 -0
- package/dist/esm/Entrypoint.js +985 -0
- package/dist/esm/adapter/commander/CommanderCLIEntrypoint.js +433 -0
- package/dist/esm/adapter/commander/Prompt.js +127 -0
- package/dist/esm/adapter/commander/Width.js +63 -0
- package/dist/esm/adapter/electron/ElectronIPCServiceEntrypoint.js +212 -0
- package/dist/esm/adapter/express/ExpressHTTPEntrypoint.js +295 -0
- package/dist/esm/adapter/express/Responders.js +66 -0
- package/dist/esm/adapter/express/StaticUI.js +96 -0
- package/dist/esm/adapter/fastify/FastifyHTTPEntrypoint.js +333 -0
- package/dist/esm/adapter/fastify/Responders.js +73 -0
- package/dist/esm/adapter/http/HTTPServiceEntrypoint.js +253 -0
- package/dist/esm/adapter/jsonrpc/JSONRPCProtocol.js +182 -0
- package/dist/esm/adapter/jsonrpc/JSONRPCServiceEntrypoint.js +361 -0
- package/dist/esm/adapter/schedule/ScheduleEntrypoint.js +272 -0
- package/dist/esm/adapter/socket.io/SocketIOServiceEntrypoint.js +212 -0
- package/dist/esm/channel/BuiltinChannels.js +125 -0
- package/dist/esm/channel/Channel.js +100 -0
- package/dist/esm/channel/EntrypointAdapter.js +39 -0
- package/dist/esm/context/BaseContext.js +87 -0
- package/dist/esm/context/CLIContext.js +49 -0
- package/dist/esm/context/HTTPContext.js +74 -0
- package/dist/esm/context/ScheduleContext.js +61 -0
- package/dist/esm/context/ServiceContext.js +58 -0
- package/dist/esm/decorators/CLIAction.js +10 -0
- package/dist/esm/decorators/HTTPAction.js +11 -0
- package/dist/esm/decorators/Prefix.js +45 -0
- package/dist/esm/decorators/Schedule.js +61 -0
- package/dist/esm/decorators/ServiceAction.js +9 -0
- package/dist/esm/decorators/UseMiddlewares.js +55 -0
- package/dist/esm/decorators/http/DELETE.js +4 -0
- package/dist/esm/decorators/http/GET.js +4 -0
- package/dist/esm/decorators/http/HEAD.js +4 -0
- package/dist/esm/decorators/http/OPTIONS.js +4 -0
- package/dist/esm/decorators/http/PATCH.js +4 -0
- package/dist/esm/decorators/http/POST.js +4 -0
- package/dist/esm/decorators/http/PUT.js +4 -0
- package/dist/esm/exceptions/AccessDeniedException.js +13 -0
- package/dist/esm/exceptions/ControllerActionNotFoundException.js +12 -0
- package/dist/esm/exceptions/DuplicateActionNameException.js +11 -0
- package/dist/esm/exceptions/EntrypointStoppedException.js +12 -0
- package/dist/esm/exceptions/InvalidActionGroupException.js +7 -0
- package/dist/esm/exceptions/InvalidChannelException.js +11 -0
- package/dist/esm/exceptions/InvalidEntrypointAdapterException.js +12 -0
- package/dist/esm/exceptions/InvalidMiddlewareException.js +11 -0
- package/dist/esm/exceptions/InvalidPrefixException.js +11 -0
- package/dist/esm/exceptions/MiddlewareNextCalledException.js +11 -0
- package/dist/esm/exceptions/RouteNotFoundException.js +12 -0
- package/dist/esm/exceptions/ServiceInvokeException.js +10 -0
- package/dist/esm/exports/CTRLDecorators.js +19 -0
- package/dist/esm/exports/Channel.js +11 -0
- package/dist/esm/exports/CommanderAdapter.js +1 -0
- package/dist/esm/exports/ElectronAdapter.js +1 -0
- package/dist/esm/exports/Entrypoint.js +22 -0
- package/dist/esm/exports/ExpressAdapter.js +3 -0
- package/dist/esm/exports/FastifyAdapter.js +3 -0
- package/dist/esm/exports/JSONRPCAdapter.js +2 -0
- package/dist/esm/exports/SocketIOAdapter.js +1 -0
- package/dist/esm/lib/AccessControl.js +204 -0
- package/dist/esm/lib/AccessControlRule.js +72 -0
- package/dist/esm/lib/ActionOptions.js +63 -0
- package/dist/esm/lib/ActionResult.js +24 -0
- package/dist/esm/lib/ApplicationOf.js +11 -0
- package/dist/esm/lib/Controller.js +61 -0
- package/dist/esm/lib/ControllerEntrypoint.js +229 -0
- package/dist/esm/lib/GetActionDTOAndOptions.js +46 -0
- package/dist/esm/lib/HTTPErrors.js +48 -0
- package/dist/esm/lib/Middleware.js +134 -0
- package/dist/esm/lib/Prefix.js +143 -0
- package/dist/esm/lib/Result.js +147 -0
- package/dist/esm/lib/ServiceResponseCodec.js +113 -0
- package/dist/esm/lib/StringifyPattern.js +55 -0
- package/dist/esm/lib/UnsetValue.js +213 -0
- package/dist/esm/lib/pattern/GlobPattern.js +64 -0
- package/dist/esm/lib/pattern/PatternManager.js +229 -0
- package/dist/esm/lib/schedule/Cron.js +277 -0
- package/dist/esm/types/CLIContextParams.js +1 -0
- package/dist/esm/types/ErrorDescription.js +1 -0
- package/dist/esm/types/HTTPContextParams.js +1 -0
- package/dist/esm/types/ScheduleContextParams.js +1 -0
- package/dist/esm/types/ServiceContextParams.js +1 -0
- package/dist/types/Entrypoint.d.ts +868 -0
- package/dist/types/adapter/commander/CommanderCLIEntrypoint.d.ts +192 -0
- package/dist/types/adapter/commander/Prompt.d.ts +22 -0
- package/dist/types/adapter/commander/Width.d.ts +12 -0
- package/dist/types/adapter/electron/ElectronIPCServiceEntrypoint.d.ts +203 -0
- package/dist/types/adapter/express/ExpressHTTPEntrypoint.d.ts +172 -0
- package/dist/types/adapter/express/Responders.d.ts +89 -0
- package/dist/types/adapter/express/StaticUI.d.ts +83 -0
- package/dist/types/adapter/fastify/FastifyHTTPEntrypoint.d.ts +156 -0
- package/dist/types/adapter/fastify/Responders.d.ts +88 -0
- package/dist/types/adapter/http/HTTPServiceEntrypoint.d.ts +117 -0
- package/dist/types/adapter/jsonrpc/JSONRPCProtocol.d.ts +194 -0
- package/dist/types/adapter/jsonrpc/JSONRPCServiceEntrypoint.d.ts +154 -0
- package/dist/types/adapter/schedule/ScheduleEntrypoint.d.ts +86 -0
- package/dist/types/adapter/socket.io/SocketIOServiceEntrypoint.d.ts +138 -0
- package/dist/types/channel/BuiltinChannels.d.ts +18 -0
- package/dist/types/channel/Channel.d.ts +196 -0
- package/dist/types/channel/EntrypointAdapter.d.ts +195 -0
- package/dist/types/context/BaseContext.d.ts +75 -0
- package/dist/types/context/CLIContext.d.ts +38 -0
- package/dist/types/context/HTTPContext.d.ts +52 -0
- package/dist/types/context/ScheduleContext.d.ts +47 -0
- package/dist/types/context/ServiceContext.d.ts +47 -0
- package/dist/types/decorators/CLIAction.d.ts +120 -0
- package/dist/types/decorators/HTTPAction.d.ts +178 -0
- package/dist/types/decorators/Prefix.d.ts +44 -0
- package/dist/types/decorators/Schedule.d.ts +120 -0
- package/dist/types/decorators/ServiceAction.d.ts +116 -0
- package/dist/types/decorators/UseMiddlewares.d.ts +52 -0
- package/dist/types/decorators/http/DELETE.d.ts +87 -0
- package/dist/types/decorators/http/GET.d.ts +89 -0
- package/dist/types/decorators/http/HEAD.d.ts +84 -0
- package/dist/types/decorators/http/OPTIONS.d.ts +80 -0
- package/dist/types/decorators/http/PATCH.d.ts +90 -0
- package/dist/types/decorators/http/POST.d.ts +91 -0
- package/dist/types/decorators/http/PUT.d.ts +92 -0
- package/dist/types/exceptions/AccessDeniedException.d.ts +10 -0
- package/dist/types/exceptions/ControllerActionNotFoundException.d.ts +9 -0
- package/dist/types/exceptions/DuplicateActionNameException.d.ts +8 -0
- package/dist/types/exceptions/EntrypointStoppedException.d.ts +9 -0
- package/dist/types/exceptions/InvalidActionGroupException.d.ts +4 -0
- package/dist/types/exceptions/InvalidChannelException.d.ts +8 -0
- package/dist/types/exceptions/InvalidEntrypointAdapterException.d.ts +9 -0
- package/dist/types/exceptions/InvalidMiddlewareException.d.ts +8 -0
- package/dist/types/exceptions/InvalidPrefixException.d.ts +8 -0
- package/dist/types/exceptions/MiddlewareNextCalledException.d.ts +8 -0
- package/dist/types/exceptions/RouteNotFoundException.d.ts +9 -0
- package/dist/types/exceptions/ServiceInvokeException.d.ts +11 -0
- package/dist/types/exports/CTRLDecorators.d.ts +13 -0
- package/dist/types/exports/Channel.d.ts +14 -0
- package/dist/types/exports/CommanderAdapter.d.ts +1 -0
- package/dist/types/exports/ElectronAdapter.d.ts +1 -0
- package/dist/types/exports/Entrypoint.d.ts +24 -0
- package/dist/types/exports/ExpressAdapter.d.ts +4 -0
- package/dist/types/exports/FastifyAdapter.d.ts +4 -0
- package/dist/types/exports/JSONRPCAdapter.d.ts +2 -0
- package/dist/types/exports/SocketIOAdapter.d.ts +1 -0
- package/dist/types/lib/AccessControl.d.ts +118 -0
- package/dist/types/lib/AccessControlRule.d.ts +91 -0
- package/dist/types/lib/ActionOptions.d.ts +67 -0
- package/dist/types/lib/ActionResult.d.ts +28 -0
- package/dist/types/lib/ApplicationOf.d.ts +6 -0
- package/dist/types/lib/Controller.d.ts +59 -0
- package/dist/types/lib/ControllerEntrypoint.d.ts +168 -0
- package/dist/types/lib/GetActionDTOAndOptions.d.ts +29 -0
- package/dist/types/lib/HTTPErrors.d.ts +55 -0
- package/dist/types/lib/Middleware.d.ts +146 -0
- package/dist/types/lib/Prefix.d.ts +98 -0
- package/dist/types/lib/Result.d.ts +173 -0
- package/dist/types/lib/ServiceResponseCodec.d.ts +82 -0
- package/dist/types/lib/StringifyPattern.d.ts +7 -0
- package/dist/types/lib/UnsetValue.d.ts +12 -0
- package/dist/types/lib/pattern/GlobPattern.d.ts +34 -0
- package/dist/types/lib/pattern/PatternManager.d.ts +103 -0
- package/dist/types/lib/schedule/Cron.d.ts +56 -0
- package/dist/types/types/CLIContextParams.d.ts +14 -0
- package/dist/types/types/ErrorDescription.d.ts +14 -0
- package/dist/types/types/HTTPContextParams.d.ts +27 -0
- package/dist/types/types/ScheduleContextParams.d.ts +21 -0
- package/dist/types/types/ServiceContextParams.d.ts +16 -0
- package/package.json +152 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Derived from index.js of unset-value 2.0.1, has-value 2.0.2, get-value 3.0.1, has-values 2.0.1, kind-of 6.0.3 and
|
|
4
|
+
* isobject 4.1.1 (MIT, see THIRD_PARTY_NOTICES.md): the removal of the properties of the patterns from the inputs of
|
|
5
|
+
* the actions, as 2.x
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.unsetValue = unsetValue;
|
|
9
|
+
function isObjectValue(val) {
|
|
10
|
+
return val != null && typeof val === 'object' && !Array.isArray(val);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The type of a value (kind-of)
|
|
14
|
+
* @param val
|
|
15
|
+
*/
|
|
16
|
+
function kindOf(val) {
|
|
17
|
+
if (val === undefined)
|
|
18
|
+
return 'undefined';
|
|
19
|
+
if (val === null)
|
|
20
|
+
return 'null';
|
|
21
|
+
const type = typeof val;
|
|
22
|
+
if (type === 'boolean' || type === 'string' || type === 'number' || type === 'symbol')
|
|
23
|
+
return type;
|
|
24
|
+
if (type === 'function')
|
|
25
|
+
return ctorName(val) === 'GeneratorFunction' ? 'generatorfunction' : 'function';
|
|
26
|
+
if (Array.isArray(val))
|
|
27
|
+
return 'array';
|
|
28
|
+
if (val.constructor && typeof val.constructor.isBuffer === 'function' && val.constructor.isBuffer(val))
|
|
29
|
+
return 'buffer';
|
|
30
|
+
if (isArguments(val))
|
|
31
|
+
return 'arguments';
|
|
32
|
+
if (val instanceof Date || (typeof val.toDateString === 'function' && typeof val.getDate === 'function' && typeof val.setDate === 'function'))
|
|
33
|
+
return 'date';
|
|
34
|
+
if (val instanceof Error || (typeof val.message === 'string' && val.constructor && typeof val.constructor.stackTraceLimit === 'number'))
|
|
35
|
+
return 'error';
|
|
36
|
+
if (val instanceof RegExp || (typeof val.flags === 'string' && typeof val.ignoreCase === 'boolean' && typeof val.multiline === 'boolean' && typeof val.global === 'boolean'))
|
|
37
|
+
return 'regexp';
|
|
38
|
+
switch (ctorName(val)) {
|
|
39
|
+
case 'Symbol':
|
|
40
|
+
return 'symbol';
|
|
41
|
+
case 'Promise':
|
|
42
|
+
return 'promise';
|
|
43
|
+
case 'WeakMap':
|
|
44
|
+
return 'weakmap';
|
|
45
|
+
case 'WeakSet':
|
|
46
|
+
return 'weakset';
|
|
47
|
+
case 'Map':
|
|
48
|
+
return 'map';
|
|
49
|
+
case 'Set':
|
|
50
|
+
return 'set';
|
|
51
|
+
case 'Int8Array':
|
|
52
|
+
case 'Uint8Array':
|
|
53
|
+
case 'Uint8ClampedArray':
|
|
54
|
+
case 'Int16Array':
|
|
55
|
+
case 'Uint16Array':
|
|
56
|
+
case 'Int32Array':
|
|
57
|
+
case 'Uint32Array':
|
|
58
|
+
case 'Float32Array':
|
|
59
|
+
case 'Float64Array':
|
|
60
|
+
return ctorName(val).toLowerCase();
|
|
61
|
+
}
|
|
62
|
+
if (typeof val.throw === 'function' && typeof val.return === 'function' && typeof val.next === 'function')
|
|
63
|
+
return 'generator';
|
|
64
|
+
const tag = Object.prototype.toString.call(val);
|
|
65
|
+
switch (tag) {
|
|
66
|
+
case '[object Object]':
|
|
67
|
+
return 'object';
|
|
68
|
+
case '[object Map Iterator]':
|
|
69
|
+
return 'mapiterator';
|
|
70
|
+
case '[object Set Iterator]':
|
|
71
|
+
return 'setiterator';
|
|
72
|
+
case '[object String Iterator]':
|
|
73
|
+
return 'stringiterator';
|
|
74
|
+
case '[object Array Iterator]':
|
|
75
|
+
return 'arrayiterator';
|
|
76
|
+
}
|
|
77
|
+
return tag.slice(8, -1).toLowerCase().replace(/\s/g, '');
|
|
78
|
+
}
|
|
79
|
+
function ctorName(val) {
|
|
80
|
+
return typeof val.constructor === 'function' ? val.constructor.name : null;
|
|
81
|
+
}
|
|
82
|
+
function isArguments(val) {
|
|
83
|
+
try {
|
|
84
|
+
if (typeof val.length === 'number' && typeof val.callee === 'function')
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
if (error.message.indexOf('callee') !== -1)
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Whether a value has a value (has-values): not undefined, an empty string, array, object, map or set, an empty
|
|
95
|
+
* regular expression, buffer or error message
|
|
96
|
+
* @param val
|
|
97
|
+
*/
|
|
98
|
+
function hasValues(val) {
|
|
99
|
+
switch (kindOf(val)) {
|
|
100
|
+
case 'boolean':
|
|
101
|
+
case 'date':
|
|
102
|
+
case 'function':
|
|
103
|
+
case 'null':
|
|
104
|
+
case 'number':
|
|
105
|
+
return true;
|
|
106
|
+
case 'undefined':
|
|
107
|
+
return false;
|
|
108
|
+
case 'regexp':
|
|
109
|
+
return val.source !== '(?:)' && val.source !== '';
|
|
110
|
+
case 'buffer':
|
|
111
|
+
return val.toString() !== '';
|
|
112
|
+
case 'error':
|
|
113
|
+
return val.message !== '';
|
|
114
|
+
case 'string':
|
|
115
|
+
case 'arguments':
|
|
116
|
+
return val.length !== 0;
|
|
117
|
+
case 'file':
|
|
118
|
+
case 'map':
|
|
119
|
+
case 'set':
|
|
120
|
+
return val.size !== 0;
|
|
121
|
+
case 'array':
|
|
122
|
+
case 'object':
|
|
123
|
+
for (const key of Object.keys(val))
|
|
124
|
+
if (hasValues(val[key]))
|
|
125
|
+
return true;
|
|
126
|
+
return false;
|
|
127
|
+
default:
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function isValidObject(val) {
|
|
132
|
+
return isObjectValue(val) || Array.isArray(val) || typeof val === 'function';
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* The value of a path (get-value): a key holding the whole path first, the keys escaping their dots ("a\.b"), the keys
|
|
136
|
+
* containing dots
|
|
137
|
+
* @param target
|
|
138
|
+
* @param path
|
|
139
|
+
*/
|
|
140
|
+
function getValue(target, path) {
|
|
141
|
+
if (!isValidObject(target))
|
|
142
|
+
return target;
|
|
143
|
+
const isArray = Array.isArray(path);
|
|
144
|
+
if (typeof path !== 'string' && !isArray)
|
|
145
|
+
return target;
|
|
146
|
+
if (typeof path === 'string' && path in target)
|
|
147
|
+
return target[path];
|
|
148
|
+
const segs = isArray ? path : path.split('.');
|
|
149
|
+
const len = segs.length;
|
|
150
|
+
let idx = 0;
|
|
151
|
+
do {
|
|
152
|
+
let prop = segs[idx];
|
|
153
|
+
if (typeof prop === 'number')
|
|
154
|
+
prop = String(prop);
|
|
155
|
+
while (prop && prop.slice(-1) === '\\')
|
|
156
|
+
prop = prop.slice(0, -1) + '.' + (segs[++idx] || '');
|
|
157
|
+
if (prop in target) {
|
|
158
|
+
target = target[prop];
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
let hasProp = false;
|
|
162
|
+
let n = idx + 1;
|
|
163
|
+
while (n < len) {
|
|
164
|
+
prop = prop + '.' + segs[n++];
|
|
165
|
+
if ((hasProp = prop in target)) {
|
|
166
|
+
target = target[prop];
|
|
167
|
+
idx = n - 1;
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (!hasProp)
|
|
172
|
+
return undefined;
|
|
173
|
+
}
|
|
174
|
+
} while (++idx < len && isValidObject(target));
|
|
175
|
+
return idx === len ? target : undefined;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Whether a path has a value (has-value)
|
|
179
|
+
* @param obj
|
|
180
|
+
* @param path
|
|
181
|
+
*/
|
|
182
|
+
function hasValue(obj, path) {
|
|
183
|
+
const isObject = obj != null && (typeof obj === 'object' || typeof obj === 'function');
|
|
184
|
+
if (isObject && (typeof path === 'string' || Array.isArray(path)))
|
|
185
|
+
return hasValues(getValue(obj, path));
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Remove a property of an object by its path (unset-value): a key holding the whole path first, the keys escaping
|
|
190
|
+
* their dots ("a\.b"); a property without value (has-value) is kept
|
|
191
|
+
* @param obj
|
|
192
|
+
* @param prop
|
|
193
|
+
*/
|
|
194
|
+
function unsetValue(obj, prop) {
|
|
195
|
+
if (!isObjectValue(obj))
|
|
196
|
+
throw new TypeError('expected an object.');
|
|
197
|
+
const isArray = Array.isArray(prop);
|
|
198
|
+
if (!isArray && Object.prototype.hasOwnProperty.call(obj, prop)) {
|
|
199
|
+
delete obj[prop];
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
if (hasValue(obj, prop)) {
|
|
203
|
+
const segs = isArray ? prop.slice() : prop.split('.');
|
|
204
|
+
let last = segs.pop();
|
|
205
|
+
while (segs.length && segs[segs.length - 1].slice(-1) === '\\')
|
|
206
|
+
last = segs.pop().slice(0, -1) + '.' + last;
|
|
207
|
+
while (segs.length) {
|
|
208
|
+
const key = segs.shift();
|
|
209
|
+
if (key === '__proto__' || key === 'constructor' || key === 'prototype')
|
|
210
|
+
throw new Error(`Cannot set unsafe key: "${key}"`);
|
|
211
|
+
obj = obj[key];
|
|
212
|
+
}
|
|
213
|
+
return delete obj[last];
|
|
214
|
+
}
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A glob of the value of a pattern: "*" matches any characters, "?" one character, "**" is a literal "*" and "*?" a
|
|
3
|
+
* literal "?". It matches a whole value, converted to a string
|
|
4
|
+
*/
|
|
5
|
+
export declare class GlobPattern {
|
|
6
|
+
#private;
|
|
7
|
+
readonly glob: unknown;
|
|
8
|
+
/**
|
|
9
|
+
* Whether a value of a pattern is a glob
|
|
10
|
+
* @param value
|
|
11
|
+
*/
|
|
12
|
+
static isGlob(value: string): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* @param glob the glob, nothing is matched without it
|
|
15
|
+
*/
|
|
16
|
+
constructor(glob: unknown);
|
|
17
|
+
/**
|
|
18
|
+
* The regular expression of a glob
|
|
19
|
+
* @param glob
|
|
20
|
+
*/
|
|
21
|
+
protected static expression(glob: string): RegExp;
|
|
22
|
+
/**
|
|
23
|
+
* Whether the glob matches a value converted to a string
|
|
24
|
+
* @param value
|
|
25
|
+
*/
|
|
26
|
+
test(value: unknown): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Whether the glob matches the value of a subject: a missing value is not matched, a primitive value (a date, a
|
|
29
|
+
* regular expression) is matched as a string. An array or an object is always matched, as gex does (it gives back
|
|
30
|
+
* the collection of its matching elements, which is never null): the routing of the actions is the one of 2.x
|
|
31
|
+
* @param value
|
|
32
|
+
*/
|
|
33
|
+
matches(value: unknown): boolean;
|
|
34
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* The glob matching of the values of the patterns, rewritten from gex (Copyright (c) 2011-2020 Richard Rodger, MIT
|
|
4
|
+
* License, see THIRD_PARTY_NOTICES.md)
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.GlobPattern = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* A glob of the value of a pattern: "*" matches any characters, "?" one character, "**" is a literal "*" and "*?" a
|
|
10
|
+
* literal "?". It matches a whole value, converted to a string
|
|
11
|
+
*/
|
|
12
|
+
class GlobPattern {
|
|
13
|
+
/**
|
|
14
|
+
* The expression of the glob, undefined when it matches nothing (no glob)
|
|
15
|
+
*/
|
|
16
|
+
#expression;
|
|
17
|
+
/**
|
|
18
|
+
* Whether a value of a pattern is a glob
|
|
19
|
+
* @param value
|
|
20
|
+
*/
|
|
21
|
+
static isGlob(value) {
|
|
22
|
+
return /[*?]/.test(value);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @param glob the glob, nothing is matched without it
|
|
26
|
+
*/
|
|
27
|
+
constructor(glob) {
|
|
28
|
+
this.glob = glob;
|
|
29
|
+
//NaN is the empty glob, as gex cleans it
|
|
30
|
+
this.#expression = glob === null || glob === undefined ? undefined : GlobPattern.expression(Number.isNaN(glob) ? '' : String(glob));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The regular expression of a glob
|
|
34
|
+
* @param glob
|
|
35
|
+
*/
|
|
36
|
+
static expression(glob) {
|
|
37
|
+
let source = glob.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
|
|
38
|
+
//[\s\S] matches the line feeds too
|
|
39
|
+
source = source.replace(/\\\*/g, '[\\s\\S]*');
|
|
40
|
+
source = source.replace(/\\\?/g, '[\\s\\S]');
|
|
41
|
+
//"**" and "*?" are the literal "*" and "?"
|
|
42
|
+
source = source.replace(/\[\\s\\S\]\*\[\\s\\S\]\*/g, '\\*');
|
|
43
|
+
source = source.replace(/\[\\s\\S\]\*\[\\s\\S\]/g, '\\?');
|
|
44
|
+
return new RegExp(`^${source}$`);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Whether the glob matches a value converted to a string
|
|
48
|
+
* @param value
|
|
49
|
+
*/
|
|
50
|
+
test(value) {
|
|
51
|
+
return !!this.#expression && this.#expression.test(String(value));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Whether the glob matches the value of a subject: a missing value is not matched, a primitive value (a date, a
|
|
55
|
+
* regular expression) is matched as a string. An array or an object is always matched, as gex does (it gives back
|
|
56
|
+
* the collection of its matching elements, which is never null): the routing of the actions is the one of 2.x
|
|
57
|
+
* @param value
|
|
58
|
+
*/
|
|
59
|
+
matches(value) {
|
|
60
|
+
if (value === null || value === undefined)
|
|
61
|
+
return false;
|
|
62
|
+
const type = typeof value;
|
|
63
|
+
if (type === 'string' || type === 'number' || type === 'boolean' || value instanceof Date || value instanceof RegExp)
|
|
64
|
+
return this.test(value);
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.GlobPattern = GlobPattern;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { GlobPattern } from './GlobPattern.js';
|
|
2
|
+
/**
|
|
3
|
+
* A pattern: its values are compared as strings
|
|
4
|
+
*/
|
|
5
|
+
export type Pattern = Record<string, any>;
|
|
6
|
+
/**
|
|
7
|
+
* A glob of a key of a node, and the node of the patterns it matches
|
|
8
|
+
*/
|
|
9
|
+
type GlobBranch = {
|
|
10
|
+
glob: GlobPattern;
|
|
11
|
+
node: PatternNode;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A node of the decision tree: the patterns having its key are found by its value (or by a glob of it), the patterns
|
|
15
|
+
* without it are in its "star" node. The keys are ordered along the tree, as the keys of the patterns
|
|
16
|
+
*/
|
|
17
|
+
type PatternNode = {
|
|
18
|
+
/**
|
|
19
|
+
* The key the node decides on
|
|
20
|
+
*/
|
|
21
|
+
key?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The nodes of the values of the key
|
|
24
|
+
*/
|
|
25
|
+
values?: Record<string, PatternNode>;
|
|
26
|
+
/**
|
|
27
|
+
* The nodes of the globs of the key
|
|
28
|
+
*/
|
|
29
|
+
globs?: Record<string, GlobBranch[]>;
|
|
30
|
+
/**
|
|
31
|
+
* The node of the patterns without the key
|
|
32
|
+
*/
|
|
33
|
+
star?: PatternNode;
|
|
34
|
+
/**
|
|
35
|
+
* The object of the pattern ending at the node
|
|
36
|
+
*/
|
|
37
|
+
data?: unknown;
|
|
38
|
+
hasData?: boolean;
|
|
39
|
+
};
|
|
40
|
+
export type PatternManagerOptions = {
|
|
41
|
+
/**
|
|
42
|
+
* The values of the patterns having "*" or "?" are globs, true by default
|
|
43
|
+
*/
|
|
44
|
+
globMatch?: boolean;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* The patterns of the actions and the objects they give: a subject is matched by the most specific pattern whose
|
|
48
|
+
* properties it has (the unknown properties of the subject are ignored)
|
|
49
|
+
*/
|
|
50
|
+
export declare class PatternManager {
|
|
51
|
+
#private;
|
|
52
|
+
constructor(options?: PatternManagerOptions);
|
|
53
|
+
/**
|
|
54
|
+
* The glob of a value of a pattern, undefined when it is not one
|
|
55
|
+
* @param value
|
|
56
|
+
*/
|
|
57
|
+
protected glob(value: string): GlobPattern | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* The node of a glob of a key of a node, added once
|
|
60
|
+
* @param node
|
|
61
|
+
* @param key
|
|
62
|
+
* @param glob
|
|
63
|
+
*/
|
|
64
|
+
protected globNode(node: PatternNode, key: string, glob: GlobPattern): PatternNode;
|
|
65
|
+
/**
|
|
66
|
+
* Register a pattern, and the object that will be returned if an input matches.
|
|
67
|
+
* Both keys and values are considered to be strings.
|
|
68
|
+
* Other types are converted to strings.
|
|
69
|
+
* @param pattern
|
|
70
|
+
* @param obj
|
|
71
|
+
*/
|
|
72
|
+
add(pattern: Pattern, obj: any): this;
|
|
73
|
+
/**
|
|
74
|
+
* Remove this pattern, and it's object, from the matcher.
|
|
75
|
+
* @param pattern
|
|
76
|
+
*/
|
|
77
|
+
remove(pattern: Pattern): this;
|
|
78
|
+
/**
|
|
79
|
+
* Return the unique match for this subject, or null if not found.
|
|
80
|
+
* The properties of the subject are matched against the patterns previously added, and the most specifc pattern wins.
|
|
81
|
+
* Unknown properties in the subject are ignored.
|
|
82
|
+
* If exact is true, then all properties of the subject must match.
|
|
83
|
+
* @param subject
|
|
84
|
+
* @param exact
|
|
85
|
+
*/
|
|
86
|
+
find(subject: Pattern, exact?: boolean): any;
|
|
87
|
+
/**
|
|
88
|
+
* Return the list of registered patterns that contain this partial pattern.
|
|
89
|
+
* You can use wildcards for property values.
|
|
90
|
+
* Omitted values are not equivalent to a wildcard of "*", you must specify each property explicitly.
|
|
91
|
+
* @param partialPattern
|
|
92
|
+
* @param exact the omitted properties match nothing
|
|
93
|
+
*/
|
|
94
|
+
list(partialPattern?: Pattern, exact?: boolean): {
|
|
95
|
+
match: Record<string, any>;
|
|
96
|
+
data: any;
|
|
97
|
+
}[];
|
|
98
|
+
/**
|
|
99
|
+
* Generate a string representation of the decision tree for debugging.
|
|
100
|
+
*/
|
|
101
|
+
toJSON(): string;
|
|
102
|
+
}
|
|
103
|
+
export {};
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PatternManager = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* The matching of the patterns, rewritten from patrun (Copyright (c) 2013-2022 Richard Rodger, MIT License, see
|
|
6
|
+
* THIRD_PARTY_NOTICES.md): the same decision tree, the same results
|
|
7
|
+
*/
|
|
8
|
+
const GlobPattern_js_1 = require("./GlobPattern.js");
|
|
9
|
+
/**
|
|
10
|
+
* A dictionary without prototype: the values of the subjects are never the properties of Object ("constructor"…)
|
|
11
|
+
*/
|
|
12
|
+
function dictionary() {
|
|
13
|
+
return Object.create(null);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The patterns of the actions and the objects they give: a subject is matched by the most specific pattern whose
|
|
17
|
+
* properties it has (the unknown properties of the subject are ignored)
|
|
18
|
+
*/
|
|
19
|
+
class PatternManager {
|
|
20
|
+
#globMatch;
|
|
21
|
+
#top = {};
|
|
22
|
+
constructor(options = { globMatch: true }) {
|
|
23
|
+
this.#globMatch = !!options.globMatch;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The glob of a value of a pattern, undefined when it is not one
|
|
27
|
+
* @param value
|
|
28
|
+
*/
|
|
29
|
+
glob(value) {
|
|
30
|
+
return this.#globMatch && GlobPattern_js_1.GlobPattern.isGlob(value) ? new GlobPattern_js_1.GlobPattern(value) : undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The node of a glob of a key of a node, added once
|
|
34
|
+
* @param node
|
|
35
|
+
* @param key
|
|
36
|
+
* @param glob
|
|
37
|
+
*/
|
|
38
|
+
globNode(node, key, glob) {
|
|
39
|
+
const globs = node.globs ??= dictionary();
|
|
40
|
+
const branches = globs[key] ??= [];
|
|
41
|
+
let branch = branches.find((candidate) => candidate.glob.glob === glob.glob);
|
|
42
|
+
if (!branch)
|
|
43
|
+
branches.push(branch = { glob: glob, node: {} });
|
|
44
|
+
return branch.node;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Register a pattern, and the object that will be returned if an input matches.
|
|
48
|
+
* Both keys and values are considered to be strings.
|
|
49
|
+
* Other types are converted to strings.
|
|
50
|
+
* @param pattern
|
|
51
|
+
* @param obj
|
|
52
|
+
*/
|
|
53
|
+
add(pattern, obj) {
|
|
54
|
+
const keys = Object.keys(pattern).filter((key) => pattern[key] !== null && pattern[key] !== undefined).sort();
|
|
55
|
+
const values = Object.fromEntries(keys.map((key) => [key, String(pattern[key])]));
|
|
56
|
+
let node = this.#top;
|
|
57
|
+
//The keys of the path are ordered: a key is inserted before the next key of the path, or follows the star nodes
|
|
58
|
+
for (let index = 0; index < keys.length; index++) {
|
|
59
|
+
const key = keys[index];
|
|
60
|
+
const value = values[key];
|
|
61
|
+
const glob = this.glob(value);
|
|
62
|
+
if (node.values && node.key === key) {
|
|
63
|
+
//The key of the node
|
|
64
|
+
node = glob ? this.globNode(node, key, glob) : node.values[value] ??= {};
|
|
65
|
+
}
|
|
66
|
+
else if (!node.key) {
|
|
67
|
+
//The end of the path: the key is the last one
|
|
68
|
+
node.key = key;
|
|
69
|
+
node.values = dictionary();
|
|
70
|
+
node = glob ? this.globNode(node, key, glob) : node.values[value] = {};
|
|
71
|
+
}
|
|
72
|
+
else if (key < node.key) {
|
|
73
|
+
//The key orders before the key of the node: the node moves to the star node of the key
|
|
74
|
+
const { star, globs } = node;
|
|
75
|
+
node.star = { key: node.key, values: node.values };
|
|
76
|
+
if (star)
|
|
77
|
+
node.star.star = star;
|
|
78
|
+
if (globs)
|
|
79
|
+
node.star.globs = globs;
|
|
80
|
+
if (node.globs)
|
|
81
|
+
node.globs = dictionary();
|
|
82
|
+
node.key = key;
|
|
83
|
+
node.values = dictionary();
|
|
84
|
+
node = glob ? this.globNode(node, key, glob) : node.values[value] = {};
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
//The key orders after the key of the node: it is in the path of the patterns without the key of the node
|
|
88
|
+
node = node.star ??= {};
|
|
89
|
+
index--;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (obj !== undefined) {
|
|
93
|
+
node.data = obj;
|
|
94
|
+
node.hasData = true;
|
|
95
|
+
}
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Remove this pattern, and it's object, from the matcher.
|
|
100
|
+
* @param pattern
|
|
101
|
+
*/
|
|
102
|
+
remove(pattern) {
|
|
103
|
+
let node = this.#top;
|
|
104
|
+
let data = undefined;
|
|
105
|
+
let hasData = false;
|
|
106
|
+
let last = undefined;
|
|
107
|
+
do {
|
|
108
|
+
const key = node.key;
|
|
109
|
+
if (node.values || node.globs) {
|
|
110
|
+
let next = node.values?.[pattern[key]];
|
|
111
|
+
if (next)
|
|
112
|
+
last = next;
|
|
113
|
+
if (!next && node.globs) {
|
|
114
|
+
const branch = (node.globs[key] ?? []).find((candidate) => candidate.glob.glob === pattern[key]);
|
|
115
|
+
if (branch)
|
|
116
|
+
last = next = branch.node;
|
|
117
|
+
}
|
|
118
|
+
if (next) {
|
|
119
|
+
data = next.data;
|
|
120
|
+
hasData = !!next.hasData;
|
|
121
|
+
node = next;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
node = node.star;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
node = undefined;
|
|
129
|
+
}
|
|
130
|
+
} while (node);
|
|
131
|
+
if (hasData && data !== undefined && last) {
|
|
132
|
+
delete last.data;
|
|
133
|
+
delete last.hasData;
|
|
134
|
+
}
|
|
135
|
+
return this;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Return the unique match for this subject, or null if not found.
|
|
139
|
+
* The properties of the subject are matched against the patterns previously added, and the most specifc pattern wins.
|
|
140
|
+
* Unknown properties in the subject are ignored.
|
|
141
|
+
* If exact is true, then all properties of the subject must match.
|
|
142
|
+
* @param subject
|
|
143
|
+
* @param exact
|
|
144
|
+
*/
|
|
145
|
+
find(subject, exact = false) {
|
|
146
|
+
if (subject === null || subject === undefined)
|
|
147
|
+
return null;
|
|
148
|
+
const top = this.#top;
|
|
149
|
+
let node = top;
|
|
150
|
+
let data = top.hasData ? top.data : null;
|
|
151
|
+
const stars = [];
|
|
152
|
+
const found = exact ? new Set() : undefined;
|
|
153
|
+
do {
|
|
154
|
+
const key = node.key;
|
|
155
|
+
if (node.values) {
|
|
156
|
+
const value = subject[key];
|
|
157
|
+
//The value itself (converted to a string, as the key of a dictionary), else a glob of it
|
|
158
|
+
let next = node.values[value];
|
|
159
|
+
if (!next && node.globs?.[key])
|
|
160
|
+
next = node.globs[key].find((branch) => branch.glob.matches(value))?.node;
|
|
161
|
+
if (next) {
|
|
162
|
+
found?.add(key);
|
|
163
|
+
if (node.star)
|
|
164
|
+
stars.push(node.star);
|
|
165
|
+
data = next.hasData ? next.data : (exact ? null : data);
|
|
166
|
+
node = next;
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
//The patterns without the key
|
|
170
|
+
node = node.star;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
node = undefined;
|
|
175
|
+
}
|
|
176
|
+
//The wider patterns, when the narrower ones gave nothing
|
|
177
|
+
if (!node && stars.length && (data === null || data === undefined))
|
|
178
|
+
node = stars.pop();
|
|
179
|
+
} while (node);
|
|
180
|
+
if (exact) {
|
|
181
|
+
if (found.size !== Object.keys(subject).length)
|
|
182
|
+
data = null;
|
|
183
|
+
}
|
|
184
|
+
else if ((data === null || data === undefined) && top.hasData) {
|
|
185
|
+
//The object of the empty pattern matches everything
|
|
186
|
+
data = top.data;
|
|
187
|
+
}
|
|
188
|
+
return data;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Return the list of registered patterns that contain this partial pattern.
|
|
192
|
+
* You can use wildcards for property values.
|
|
193
|
+
* Omitted values are not equivalent to a wildcard of "*", you must specify each property explicitly.
|
|
194
|
+
* @param partialPattern
|
|
195
|
+
* @param exact the omitted properties match nothing
|
|
196
|
+
*/
|
|
197
|
+
list(partialPattern, exact = false) {
|
|
198
|
+
const pattern = partialPattern ?? {};
|
|
199
|
+
const results = [];
|
|
200
|
+
const descend = (node, match, missing) => {
|
|
201
|
+
if (!node.values)
|
|
202
|
+
return;
|
|
203
|
+
const key = node.key;
|
|
204
|
+
const glob = new GlobPattern_js_1.GlobPattern(pattern[key] === null || pattern[key] === undefined ? (exact ? null : '*') : pattern[key]);
|
|
205
|
+
for (const value in node.values) {
|
|
206
|
+
//The empty value is not matched by a glob (gex gives back the matched value, which is falsy)
|
|
207
|
+
if (value === pattern[key] || (!exact && (pattern[key] === null || pattern[key] === undefined)) || (value !== '' && glob.test(value))) {
|
|
208
|
+
const valueMatch = { ...match, [key]: value };
|
|
209
|
+
const valueMissing = { ...missing };
|
|
210
|
+
delete valueMissing[key];
|
|
211
|
+
const next = node.values[value];
|
|
212
|
+
if (!Object.keys(valueMissing).length && next.hasData && next.data)
|
|
213
|
+
results.push({ match: valueMatch, data: next.data });
|
|
214
|
+
if (next.values)
|
|
215
|
+
descend(next, { ...valueMatch }, { ...valueMissing });
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (node.star)
|
|
219
|
+
descend(node.star, { ...match }, { ...missing });
|
|
220
|
+
};
|
|
221
|
+
if (this.#top.hasData && this.#top.data)
|
|
222
|
+
results.push({ match: {}, data: this.#top.data });
|
|
223
|
+
descend(this.#top, {}, { ...pattern });
|
|
224
|
+
return results;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Generate a string representation of the decision tree for debugging.
|
|
228
|
+
*/
|
|
229
|
+
toJSON() {
|
|
230
|
+
return JSON.stringify(this.#top, (key, value) => value instanceof GlobPattern_js_1.GlobPattern ? String(value.glob) : (key === 'hasData' ? undefined : value));
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
exports.PatternManager = PatternManager;
|