libmodulor 0.4.0 â 0.5.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/CHANGELOG.md +18 -1
- package/README.md +3 -3
- package/dist/esm/app/workers/AppSrcFilePathBuilder.d.ts +16 -0
- package/dist/esm/app/workers/AppSrcFilePathBuilder.js +6 -4
- package/dist/esm/apps/Helper/index.js +1 -0
- package/dist/esm/apps/Helper/src/ucds/GenerateAppsTestsUCD.js +3 -2
- package/dist/esm/bundlers/vite/StripUCDLifecycleServerPlugin.js +3 -0
- package/dist/esm/convention.d.ts +1 -0
- package/dist/esm/convention.js +17 -4
- package/dist/esm/dt/Validation.d.ts +8 -0
- package/dist/esm/dt/Validation.js +8 -0
- package/dist/esm/dt/base/TBase.d.ts +2 -1
- package/dist/esm/dt/base/TBoolean.js +2 -0
- package/dist/esm/dt/base/TInt.js +3 -0
- package/dist/esm/dt/base/TNumber.js +2 -0
- package/dist/esm/dt/base/TObject.d.ts +15 -0
- package/dist/esm/dt/base/TObject.js +14 -0
- package/dist/esm/dt/base/TString.js +1 -1
- package/dist/esm/dt/final/TAmount.js +1 -0
- package/dist/esm/dt/final/TCountryISO3166Alpha2.js +1 -0
- package/dist/esm/dt/final/TCurrencyISO4217.js +1 -0
- package/dist/esm/dt/final/TDateTimeFormat.js +1 -0
- package/dist/esm/dt/final/TEmail.js +2 -0
- package/dist/esm/dt/final/TEmoji.js +4 -0
- package/dist/esm/dt/final/TFile.js +3 -0
- package/dist/esm/dt/final/THostAddress.js +2 -0
- package/dist/esm/dt/final/TIPv6.js +1 -0
- package/dist/esm/dt/final/TJWT.js +8 -0
- package/dist/esm/dt/final/TPercentage.js +5 -0
- package/dist/esm/dt/final/TSQLQuery.js +1 -0
- package/dist/esm/dt/final/TSSHPrivateKey.js +3 -1
- package/dist/esm/dt/final/TSemVerVersion.js +1 -0
- package/dist/esm/dt/final/TShellCommand.js +1 -0
- package/dist/esm/dt/final/TURL.js +2 -0
- package/dist/esm/dt/final/TUUID.js +1 -0
- package/dist/esm/dt/final/TYesNo.js +1 -1
- package/dist/esm/i18n/WordingManager.d.ts +16 -0
- package/dist/esm/i18n/types.d.ts +5 -0
- package/dist/esm/icon/Icon.d.ts +7 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/product/manifest.d.ts +15 -0
- package/dist/esm/products/Helper/index.js +3 -0
- package/dist/esm/products/Helper/manifest.d.ts +6 -1
- package/dist/esm/std/BufferManager.d.ts +18 -0
- package/dist/esm/std/ClockManager.d.ts +5 -0
- package/dist/esm/std/EnvironmentManager.d.ts +10 -0
- package/dist/esm/std/HTTPAPICaller.d.ts +6 -0
- package/dist/esm/std/I18nManager.d.ts +26 -0
- package/dist/esm/std/JWTManager.d.ts +26 -0
- package/dist/esm/std/JobManager.d.ts +6 -0
- package/dist/esm/std/LLMManager.d.ts +25 -0
- package/dist/esm/std/LLMManager.js +1 -0
- package/dist/esm/std/PromptManager.d.ts +8 -0
- package/dist/esm/std/SettingsManager.d.ts +19 -0
- package/dist/esm/std/SettingsManager.js +9 -0
- package/dist/esm/std/impl/ConsoleLogger.js +7 -1
- package/dist/esm/std/impl/FakeEmailManager.js +1 -0
- package/dist/esm/std/impl/FakeJobManager.js +1 -0
- package/dist/esm/std/impl/FetchHTTPAPICallExecutor.d.ts +9 -0
- package/dist/esm/std/impl/FetchHTTPAPICallExecutor.js +11 -0
- package/dist/esm/std/impl/MistralAILLMManager.d.ts +17 -0
- package/dist/esm/std/impl/MistralAILLMManager.js +56 -0
- package/dist/esm/std/impl/NodeCryptoManager.js +6 -1
- package/dist/esm/std/impl/NodeDeterministicCryptoManager.d.ts +14 -0
- package/dist/esm/std/impl/NodeDeterministicCryptoManager.js +17 -3
- package/dist/esm/std/impl/NodeFSManager.js +10 -0
- package/dist/esm/std/impl/NodeHTTPAPICallExecutorAgentBuilder.js +2 -0
- package/dist/esm/std/impl/NodePromptManager.js +3 -0
- package/dist/esm/std/impl/OllamaLLMManager.d.ts +20 -0
- package/dist/esm/std/impl/OllamaLLMManager.js +56 -0
- package/dist/esm/std/impl/OpenAILLMManager.d.ts +17 -0
- package/dist/esm/std/impl/OpenAILLMManager.js +51 -0
- package/dist/esm/std/impl/SimpleHTTPAPICaller.js +14 -0
- package/dist/esm/std/impl/SimpleMapI18nManager.js +4 -2
- package/dist/esm/std/impl/StdDateClockManager.js +3 -0
- package/dist/esm/std/impl/UCDataStoreExternalResourceManager.js +3 -0
- package/dist/esm/std/impl/WebCryptoManager.js +9 -0
- package/dist/esm/std/index.d.ts +1 -0
- package/dist/esm/std/index.js +1 -0
- package/dist/esm/target/lib/cli/renderer.js +3 -0
- package/dist/esm/target/lib/client/consts.d.ts +3 -0
- package/dist/esm/target/lib/client/consts.js +3 -0
- package/dist/esm/target/lib/mcp-server/MCPServerBooter.js +1 -0
- package/dist/esm/target/lib/react/UCContainer.js +1 -0
- package/dist/esm/target/lib/react/UCPanel.js +4 -0
- package/dist/esm/target/lib/react/useUC.d.ts +8 -0
- package/dist/esm/target/lib/react/useUC.js +22 -0
- package/dist/esm/target/lib/react/useUCOR.d.ts +15 -0
- package/dist/esm/target/lib/react/useUCOR.js +45 -0
- package/dist/esm/target/lib/rn/input.d.ts +7 -0
- package/dist/esm/target/lib/rn/input.js +2 -0
- package/dist/esm/target/lib/server/AuthenticationChecker.js +2 -1
- package/dist/esm/target/lib/server/BasicAuthenticationChecker.js +1 -0
- package/dist/esm/target/lib/server/CSPDirectivesBuilder.js +13 -0
- package/dist/esm/target/lib/server/CustomerFacingErrorBuilder.js +3 -0
- package/dist/esm/target/lib/server/PrivateApiKeyAuthenticationChecker.js +1 -0
- package/dist/esm/target/lib/server/PublicApiKeyChecker.js +1 -1
- package/dist/esm/target/lib/server/RequestChecker.js +5 -4
- package/dist/esm/target/lib/server/RequestHandler.d.ts +5 -0
- package/dist/esm/target/lib/server/RequestLogger.js +5 -0
- package/dist/esm/target/lib/server/ServerManager.d.ts +19 -0
- package/dist/esm/target/lib/server/consts.d.ts +3 -0
- package/dist/esm/target/lib/server/consts.js +3 -0
- package/dist/esm/target/lib/web/input.d.ts +21 -0
- package/dist/esm/target/lib/web/input.js +4 -0
- package/dist/esm/target/node-core-cli/NodeCoreCLIManager.js +2 -2
- package/dist/esm/target/node-express-server/NodeExpressServerManager.js +5 -0
- package/dist/esm/target/node-express-server/lib/AuthCookieCreator.js +1 -1
- package/dist/esm/target/node-express-server/middlewares/AuthenticationCheckerMiddlewareBuilder.js +1 -0
- package/dist/esm/target/node-express-server/middlewares/PublicApiKeyCheckerMiddlewareBuilder.js +1 -0
- package/dist/esm/target/node-express-server/middlewares/RequestCheckerMiddlewareBuilder.js +1 -0
- package/dist/esm/target/node-express-server/middlewares/RequestHandlerMiddlewareBuilder.js +8 -0
- package/dist/esm/target/node-express-server/middlewares/RequestLoggerMiddlewareBuilder.js +1 -0
- package/dist/esm/target/node-mcp-server/NodeLocalStdioMCPServerManager.d.ts +10 -0
- package/dist/esm/target/node-mcp-server/NodeLocalStdioMCPServerManager.js +14 -0
- package/dist/esm/target/react-native-pure/UCFormFieldControl.js +1 -0
- package/dist/esm/testing/AppTester.d.ts +4 -0
- package/dist/esm/testing/AppTester.js +16 -0
- package/dist/esm/testing/AppTesterConfigurator.d.ts +68 -0
- package/dist/esm/testing/UCDataStoreTester.d.ts +9 -0
- package/dist/esm/testing/UCDataStoreTester.js +13 -0
- package/dist/esm/testing/impl/SimpleAppDocsEmitter.js +22 -2
- package/dist/esm/testing/impl/SimpleAppTesterConfigurator.js +1 -0
- package/dist/esm/testing/impl/SimpleHTMLAppTestReportEmitter.js +9 -3
- package/dist/esm/testing/impl/TypeScriptLibUCDefASTParser.js +12 -4
- package/dist/esm/testing/impl/VitestAppTestSuiteEmitter.js +6 -0
- package/dist/esm/testing/opts.d.ts +38 -0
- package/dist/esm/testing/opts.js +1 -1
- package/dist/esm/testing/uc-input.js +2 -0
- package/dist/esm/testing/workers/AppTesterCtxInitializer.js +7 -0
- package/dist/esm/testing/workers/UCExecutor.js +1 -0
- package/dist/esm/testing/workers/checkers/AppIndexChecker.js +1 -0
- package/dist/esm/testing/workers/checkers/UCDefSourcesChecker.js +4 -0
- package/dist/esm/uc/UC.js +19 -1
- package/dist/esm/uc/UCInputField.d.ts +28 -0
- package/dist/esm/uc/UCInputField.js +42 -0
- package/dist/esm/uc/data.d.ts +3 -0
- package/dist/esm/uc/def.d.ts +7 -0
- package/dist/esm/uc/exec.d.ts +39 -0
- package/dist/esm/uc/exec.js +29 -0
- package/dist/esm/uc/ext.d.ts +30 -1
- package/dist/esm/uc/helpers/UCOutputBuilder.js +5 -0
- package/dist/esm/uc/helpers/UCOutputReader.js +3 -1
- package/dist/esm/uc/impl/HTTPUCTransporter.js +4 -0
- package/dist/esm/uc/impl/InMemoryUCDataStore.js +7 -0
- package/dist/esm/uc/impl/KnexUCDataStore.d.ts +4 -0
- package/dist/esm/uc/impl/KnexUCDataStore.js +14 -0
- package/dist/esm/uc/impl/SimpleUCManager.js +6 -0
- package/dist/esm/uc/input-field.d.ts +60 -0
- package/dist/esm/uc/input-field.js +33 -0
- package/dist/esm/uc/input.d.ts +24 -0
- package/dist/esm/uc/lifecycle/client/IdleClientMain.js +1 -0
- package/dist/esm/uc/lifecycle/server/IdleServerMain.js +2 -0
- package/dist/esm/uc/manager.d.ts +11 -0
- package/dist/esm/uc/metadata.d.ts +10 -0
- package/dist/esm/uc/opi-layout.d.ts +3 -0
- package/dist/esm/uc/opi.d.ts +8 -0
- package/dist/esm/uc/output-field.d.ts +9 -0
- package/dist/esm/uc/output-part.d.ts +22 -0
- package/dist/esm/uc/output.d.ts +3 -0
- package/dist/esm/uc/policies/RoleRegularUCPolicy.js +1 -0
- package/dist/esm/uc/policies/funcs.js +1 -0
- package/dist/esm/uc/policy.d.ts +22 -0
- package/dist/esm/uc/sec.d.ts +9 -0
- package/dist/esm/uc/server.d.ts +10 -0
- package/dist/esm/uc/settings.d.ts +25 -0
- package/dist/esm/uc/side-effect.d.ts +16 -0
- package/dist/esm/uc/side-effect.js +16 -0
- package/dist/esm/uc/utils/rInput.d.ts +12 -0
- package/dist/esm/uc/utils/rInput.js +2 -0
- package/dist/esm/uc/utils/rVal.d.ts +25 -0
- package/dist/esm/uc/utils/rVal.js +27 -0
- package/dist/esm/uc/utils/recIs.d.ts +9 -0
- package/dist/esm/uc/utils/recIs.js +12 -1
- package/dist/esm/uc/utils/stripUCDLifecycleServer.d.ts +13 -0
- package/dist/esm/uc/utils/stripUCDLifecycleServer.js +17 -0
- package/dist/esm/uc/utils/ucifcoIsForArray.d.ts +6 -0
- package/dist/esm/uc/utils/ucifcoIsForArray.js +6 -0
- package/dist/esm/uc/workers/SimpleAggregateFinder.d.ts +12 -0
- package/dist/esm/uc/workers/SimpleAggregateFinder.js +12 -0
- package/dist/esm/uc/workers/UCBuilder.d.ts +7 -0
- package/dist/esm/uc/workers/UCBuilder.js +7 -0
- package/dist/esm/uc/workers/UCExecChecker.js +2 -0
- package/dist/esm/uc/workers/UCInputFilesProcessor.js +10 -4
- package/dist/esm/uc/workers/UCOutputFilesProcessor.js +6 -2
- package/dist/esm/utils/async/sleep.d.ts +10 -0
- package/dist/esm/utils/async/sleep.js +10 -0
- package/dist/esm/utils/http/appendData.js +5 -1
- package/dist/esm/utils/ioc/ContainerPrinter.js +2 -0
- package/dist/esm/utils/ioc/bindCommon.js +4 -0
- package/dist/esm/utils/ioc/bindNodeCLI.js +2 -0
- package/dist/esm/utils/ioc/bindNodeCore.js +1 -0
- package/dist/esm/utils/ioc/bindProduct.js +2 -0
- package/dist/esm/utils/ioc/bindRN.js +1 -0
- package/dist/esm/utils/ioc/bindServer.js +1 -0
- package/dist/esm/utils/ioc/bindWeb.js +2 -0
- package/dist/esm/utils/ioc/container.js +6 -0
- package/dist/esm/utils/numbers/units.js +3 -0
- package/dist/esm/utils/types/funcs.d.ts +35 -0
- package/dist/esm/utils/types/funcs.js +35 -0
- package/dist/esm/utils/types/utility-types.d.ts +17 -0
- package/dist/esm/utils/types/utility-types.js +1 -0
- package/package.json +9 -9
|
@@ -27,10 +27,10 @@ let RequestChecker = class RequestChecker {
|
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
exec({ secure, url, xForwardedProtoHeader }) {
|
|
30
|
-
const isSecure = secure;
|
|
31
|
-
const isSecureForwarded = xForwardedProtoHeader === 'https';
|
|
32
|
-
const isNotProd = !this.environmentManager.isProd();
|
|
33
|
-
const isSSLCertificateCheck = !!url.match(/^\/\.well-known\/acme-challenge\/(.*)/);
|
|
30
|
+
const isSecure = secure; // https://localhost:8443
|
|
31
|
+
const isSecureForwarded = xForwardedProtoHeader === 'https'; // https://domain.com => http://localhost:8080
|
|
32
|
+
const isNotProd = !this.environmentManager.isProd(); // http://localhost:8443
|
|
33
|
+
const isSSLCertificateCheck = !!url.match(/^\/\.well-known\/acme-challenge\/(.*)/); // http://localhost:8443/.well-known/acme-challenge/ywml7k8e8qxdjwFf1pN4hIKWJ1Jrc0CvAP3t9PSmnzw
|
|
34
34
|
this.logger.trace('Request checker', {
|
|
35
35
|
isNotProd,
|
|
36
36
|
isSSLCertificateCheck,
|
|
@@ -39,6 +39,7 @@ let RequestChecker = class RequestChecker {
|
|
|
39
39
|
});
|
|
40
40
|
const allowed = isSecure || isSecureForwarded || isNotProd || isSSLCertificateCheck;
|
|
41
41
|
if (!allowed) {
|
|
42
|
+
// Not sure it's the right HTTP status to send in these cases but not a big deal for now
|
|
42
43
|
throw new ForbiddenError();
|
|
43
44
|
}
|
|
44
45
|
}
|
|
@@ -5,5 +5,10 @@ export interface RequestHandlerInputRaw<I extends UCInput | undefined = undefine
|
|
|
5
5
|
appManifest: AppManifest;
|
|
6
6
|
envelope: HTTPDataEnvelope;
|
|
7
7
|
ucd: UCDef<I, OPI0, OPI1>;
|
|
8
|
+
/**
|
|
9
|
+
* It is not injected in the handler constructor because it must be the same as the one used in ServerManager.
|
|
10
|
+
*
|
|
11
|
+
* And in some cases, this latter is specific to a context : for instance in automated tests.
|
|
12
|
+
*/
|
|
8
13
|
ucManager: UCManager;
|
|
9
14
|
}
|
|
@@ -20,6 +20,11 @@ let RequestLogger = class RequestLogger {
|
|
|
20
20
|
}
|
|
21
21
|
exec({ body, method, url }) {
|
|
22
22
|
const prefix = [method, url].join(' ');
|
|
23
|
+
// By security, we don't log the body in production, in case it contains sensitive info (e.g. password when authenticating).
|
|
24
|
+
// That being said, in some cases, it can be handy to investigate issues.
|
|
25
|
+
// Let's think about it and how we can do it properly.
|
|
26
|
+
// One way is to this.logger.trace the body, considering it will never be the default in production since it produces too many logs.
|
|
27
|
+
// TODO : Consider logging request body even in production
|
|
23
28
|
if (this.environmentManager.isProd()) {
|
|
24
29
|
this.logger.debug(prefix);
|
|
25
30
|
return;
|
|
@@ -31,9 +31,28 @@ export interface ServerManagerSettings extends ServerManagerAuthSettings, Settin
|
|
|
31
31
|
}
|
|
32
32
|
export interface ServerManager extends Initializable {
|
|
33
33
|
overrideUCManager(ucManager: UCManager): void;
|
|
34
|
+
/**
|
|
35
|
+
* Mount the use case as an endpoint
|
|
36
|
+
* @param appManifest
|
|
37
|
+
* @param ucd
|
|
38
|
+
* @param contract
|
|
39
|
+
*/
|
|
34
40
|
mount<I extends UCInput | undefined = undefined, OPI0 extends UCOPIBase | undefined = undefined, OPI1 extends UCOPIBase | undefined = undefined>(appManifest: AppManifest, ucd: UCDef<I, OPI0, OPI1>, contract: UCHTTPContract): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Mount the static directory at `/`
|
|
43
|
+
* @param dirPath
|
|
44
|
+
*/
|
|
35
45
|
mountStaticDir(dirPath: DirPath): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Start listening on the specific host and port
|
|
48
|
+
*/
|
|
36
49
|
start(): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Stop listening
|
|
52
|
+
*/
|
|
37
53
|
stop(): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Warm up with things that must be done after the routes have been defined (e.g. error middleware, etc.)
|
|
56
|
+
*/
|
|
38
57
|
warmUp(): Promise<void>;
|
|
39
58
|
}
|
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
import { type DataType, type ErrorMessage, type HTMLInputType } from '../../../dt/index.js';
|
|
2
2
|
import { type UCExecState, type UCInputField } from '../../../uc/index.js';
|
|
3
3
|
export interface HTMLInputDef {
|
|
4
|
+
/**
|
|
5
|
+
* Internal types that are not part of the W3C spec
|
|
6
|
+
*
|
|
7
|
+
* @see node_modules/@types/react/index.d.ts#InputHTMLAttributes
|
|
8
|
+
*/
|
|
4
9
|
internal?: {
|
|
10
|
+
/**
|
|
11
|
+
* When a fiels is `multiline`, you should probably render a `<textarea />` in place of an `<input />`.
|
|
12
|
+
*/
|
|
5
13
|
multiline?: boolean | undefined;
|
|
6
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* Fields that are part of the W3C spec
|
|
17
|
+
*
|
|
18
|
+
* These are safe to destructure directly in an `<input />` component.
|
|
19
|
+
*
|
|
20
|
+
* Note that they come with their camel case form, Ã la React.
|
|
21
|
+
* The reason is that it's easier to transform this to the original spec (`maxLength` => `maxlength`) vs doing the opposite (`maxlength` > `maxLength`).
|
|
22
|
+
* In the first case, we can simply call `.toLowerCase()` on the keys, while in the second, we'd need a dedicated function that "camel-cases" a string.
|
|
23
|
+
*
|
|
24
|
+
* @example `<input {...attrs.spec} />`
|
|
25
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attributes
|
|
26
|
+
* @see node_modules/@types/react/index.d.ts `InputHTMLAttributes`
|
|
27
|
+
*/
|
|
7
28
|
spec?: {
|
|
8
29
|
'aria-errormessage'?: string | undefined;
|
|
9
30
|
'aria-invalid'?: boolean | undefined;
|
|
@@ -6,6 +6,7 @@ export function htmlInputDef(field, execState, errMsg) {
|
|
|
6
6
|
spec: {},
|
|
7
7
|
};
|
|
8
8
|
if (!def.internal || !def.spec) {
|
|
9
|
+
// Just a guard to safely type the rest of the function without using !
|
|
9
10
|
return def;
|
|
10
11
|
}
|
|
11
12
|
const { key, def: fDef } = field;
|
|
@@ -13,11 +14,14 @@ export function htmlInputDef(field, execState, errMsg) {
|
|
|
13
14
|
def.spec.disabled = ucIsDisabled(execState);
|
|
14
15
|
def.spec.id = ucifId(key);
|
|
15
16
|
def.spec.name = key;
|
|
17
|
+
// Testing the types by usage probability to make the if/else evaluation stop ideally earlier
|
|
16
18
|
if (fType instanceof TString) {
|
|
17
19
|
const constraints = fType.getConstraints();
|
|
18
20
|
if (constraints) {
|
|
19
21
|
def.spec.maxLength = constraints.maxLength;
|
|
20
22
|
def.spec.minLength = constraints.minLength;
|
|
23
|
+
// https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/pattern
|
|
24
|
+
// > No forward slashes should be specified around the pattern text
|
|
21
25
|
def.spec.pattern = constraints.format?.regexp?.source;
|
|
22
26
|
}
|
|
23
27
|
def.internal.multiline = fType.isPotentiallyLong();
|
|
@@ -57,7 +57,7 @@ let NodeCoreCLIManager = class NodeCoreCLIManager {
|
|
|
57
57
|
}
|
|
58
58
|
parseArgsConfig(uc) {
|
|
59
59
|
const config = {
|
|
60
|
-
allowPositionals: true,
|
|
60
|
+
allowPositionals: true, // For the command name
|
|
61
61
|
strict: true,
|
|
62
62
|
};
|
|
63
63
|
if (uc.inputFields.length === 0) {
|
|
@@ -68,7 +68,7 @@ let NodeCoreCLIManager = class NodeCoreCLIManager {
|
|
|
68
68
|
const { def } = f;
|
|
69
69
|
let defaultValue = def.type.getDefaultValue();
|
|
70
70
|
if (typeof defaultValue === 'number') {
|
|
71
|
-
defaultValue = defaultValue.toString();
|
|
71
|
+
defaultValue = defaultValue.toString(); // parseArgs does not accept numbers as default value
|
|
72
72
|
}
|
|
73
73
|
const [isRepeatable, _max] = ucifRepeatability(def);
|
|
74
74
|
const type = def.type instanceof TBoolean ? 'boolean' : 'string';
|
|
@@ -77,6 +77,8 @@ let NodeExpressServerManager = class NodeExpressServerManager {
|
|
|
77
77
|
async init() {
|
|
78
78
|
this.runtime = express();
|
|
79
79
|
this.runtime.use(this.helmetMB.exec({}));
|
|
80
|
+
// TODO : Add FileStorageManager (Local, S3, FSBucket)
|
|
81
|
+
// Right now, the files are only stored locally. We need more flexibility. Maybe we can also install https://imgproxy.net.
|
|
80
82
|
this.runtime.use(fileUpload({
|
|
81
83
|
createParentPath: true,
|
|
82
84
|
debug: this.s().logger_level === 'trace',
|
|
@@ -125,6 +127,8 @@ let NodeExpressServerManager = class NodeExpressServerManager {
|
|
|
125
127
|
if (!this.server?.listening) {
|
|
126
128
|
return;
|
|
127
129
|
}
|
|
130
|
+
// As stated in the docs of `close`, only awaiting `.close` is not enough to make sure all the connections are closed.
|
|
131
|
+
// Hence the wrapping in a promise, where the callback is called when the 'close' event is emitted.
|
|
128
132
|
return new Promise((resolve, reject) => {
|
|
129
133
|
if (!this.server) {
|
|
130
134
|
return resolve();
|
|
@@ -138,6 +142,7 @@ let NodeExpressServerManager = class NodeExpressServerManager {
|
|
|
138
142
|
});
|
|
139
143
|
}
|
|
140
144
|
async warmUp() {
|
|
145
|
+
// Always at the "almost" last position to handle all the errors (from other middlewares and request handlers)
|
|
141
146
|
this.runtime.use(this.errorMB.exec({}));
|
|
142
147
|
}
|
|
143
148
|
async createServer() {
|
|
@@ -35,7 +35,7 @@ let AuthCookieCreator = class AuthCookieCreator {
|
|
|
35
35
|
httpOnly: this.s().server_cookies_http_only,
|
|
36
36
|
sameSite: this.s().server_cookies_same_site,
|
|
37
37
|
secure: this.s().server_cookies_secure,
|
|
38
|
-
signed: false,
|
|
38
|
+
signed: false, // Not signing to keep it simple and btw, the JWT is already signed
|
|
39
39
|
},
|
|
40
40
|
val: jwt,
|
|
41
41
|
};
|
|
@@ -49,6 +49,8 @@ let RequestHandlerMiddlewareBuilder = class RequestHandlerMiddlewareBuilder {
|
|
|
49
49
|
if (ucor.canItem00()) {
|
|
50
50
|
item = ucor.item00().item;
|
|
51
51
|
}
|
|
52
|
+
// Be careful with this, as some are incompatible.
|
|
53
|
+
// For instance, if there is a REDIRECT and then a CLEAR_AUTH, the latter won't be executed as we return after the redirect.
|
|
52
54
|
for (const se of sideEffects) {
|
|
53
55
|
const { type } = se;
|
|
54
56
|
switch (type) {
|
|
@@ -74,6 +76,7 @@ let RequestHandlerMiddlewareBuilder = class RequestHandlerMiddlewareBuilder {
|
|
|
74
76
|
res.send(output && transform ? transform(output) : output);
|
|
75
77
|
}
|
|
76
78
|
catch (err) {
|
|
79
|
+
// Always catch otherwise it breaks the middleware chain and hangs forever
|
|
77
80
|
nextFn(err);
|
|
78
81
|
}
|
|
79
82
|
};
|
|
@@ -82,6 +85,7 @@ let RequestHandlerMiddlewareBuilder = class RequestHandlerMiddlewareBuilder {
|
|
|
82
85
|
switch (envelope) {
|
|
83
86
|
case 'form-data': {
|
|
84
87
|
const input = req.body;
|
|
88
|
+
// files is present when using express-fileupload
|
|
85
89
|
if ('files' in req && req.files) {
|
|
86
90
|
for (const [field, value] of Object.entries(req.files)) {
|
|
87
91
|
input[field] = Array.isArray(value)
|
|
@@ -89,6 +93,8 @@ let RequestHandlerMiddlewareBuilder = class RequestHandlerMiddlewareBuilder {
|
|
|
89
93
|
: this.toFile(value);
|
|
90
94
|
}
|
|
91
95
|
}
|
|
96
|
+
// TODO : Change this ugly code
|
|
97
|
+
// When a field has multiple values, they key is `field[]` and not `field`
|
|
92
98
|
const sanitized = {};
|
|
93
99
|
for (const [k, v] of Object.entries(input)) {
|
|
94
100
|
const sanitizedKey = k.split('[')[0];
|
|
@@ -96,6 +102,8 @@ let RequestHandlerMiddlewareBuilder = class RequestHandlerMiddlewareBuilder {
|
|
|
96
102
|
continue;
|
|
97
103
|
}
|
|
98
104
|
sanitized[sanitizedKey] = v;
|
|
105
|
+
// For some reason, when there is only one value, it is received as scalar and not as an array
|
|
106
|
+
// Even if there is only one, we want an array
|
|
99
107
|
if (k.includes('[') && !Array.isArray(v)) {
|
|
100
108
|
sanitized[sanitizedKey] = [v];
|
|
101
109
|
}
|
|
@@ -7,6 +7,16 @@ import type { Configurable, LoggerSettings, SettingsManager } from '../../std/in
|
|
|
7
7
|
import { UCBuilder, type UCDef, type UCHTTPContract, type UCInput, type UCManager, type UCOPIBase } from '../../uc/index.js';
|
|
8
8
|
import type { ServerManager } from '../lib/server/ServerManager.js';
|
|
9
9
|
type S = Pick<LoggerSettings, 'logger_level'>;
|
|
10
|
+
/**
|
|
11
|
+
* A simple MCP Server implementation
|
|
12
|
+
*
|
|
13
|
+
* Although it implements {@link ServerManager}, this implementation is not necessarily a "server".
|
|
14
|
+
* Indeed, it uses a local `Transport` so it must be considered the same as a {@link NodeCoreCLIManager}.
|
|
15
|
+
* Therefore, it calls `execClient` and not `execServer`.
|
|
16
|
+
* This way, Claude AI, or any other client is just a wrapper on top of it.
|
|
17
|
+
*
|
|
18
|
+
* @alpha This implementation still has lots of TODOs and has not been tested in real conditions. It needs to be stabilized before usage.
|
|
19
|
+
*/
|
|
10
20
|
export declare class NodeLocalStdioMCPServerManager implements Configurable<S>, ServerManager {
|
|
11
21
|
private productManifest;
|
|
12
22
|
private settingsManager;
|
|
@@ -17,6 +17,16 @@ import { inject, injectable } from 'inversify';
|
|
|
17
17
|
import { WordingManager } from '../../i18n/index.js';
|
|
18
18
|
import { UCBuilder, ucMountingPoint, ucifIsMandatory, } from '../../uc/index.js';
|
|
19
19
|
import { propertyType, resError, resObj } from './funcs.js';
|
|
20
|
+
/**
|
|
21
|
+
* A simple MCP Server implementation
|
|
22
|
+
*
|
|
23
|
+
* Although it implements {@link ServerManager}, this implementation is not necessarily a "server".
|
|
24
|
+
* Indeed, it uses a local `Transport` so it must be considered the same as a {@link NodeCoreCLIManager}.
|
|
25
|
+
* Therefore, it calls `execClient` and not `execServer`.
|
|
26
|
+
* This way, Claude AI, or any other client is just a wrapper on top of it.
|
|
27
|
+
*
|
|
28
|
+
* @alpha This implementation still has lots of TODOs and has not been tested in real conditions. It needs to be stabilized before usage.
|
|
29
|
+
*/
|
|
20
30
|
let NodeLocalStdioMCPServerManager = class NodeLocalStdioMCPServerManager {
|
|
21
31
|
productManifest;
|
|
22
32
|
settingsManager;
|
|
@@ -55,6 +65,9 @@ let NodeLocalStdioMCPServerManager = class NodeLocalStdioMCPServerManager {
|
|
|
55
65
|
});
|
|
56
66
|
if (this.s().logger_level !== 'error') {
|
|
57
67
|
const message = 'Set the logging_level to "error" as MCP does not want the server to log to stdout (see https://modelcontextprotocol.io/docs/tools/debugging#implementing-logging)';
|
|
68
|
+
// Depending on the `Logger` implementation, this.logger.error() might not write to stderr (e.g. can write to a file).
|
|
69
|
+
// That's why we explicitly write to stdout by calling console.error().
|
|
70
|
+
// biome-ignore lint/suspicious/noConsole: we want it
|
|
58
71
|
console.error(new Error(message));
|
|
59
72
|
}
|
|
60
73
|
}
|
|
@@ -112,6 +125,7 @@ let NodeLocalStdioMCPServerManager = class NodeLocalStdioMCPServerManager {
|
|
|
112
125
|
}
|
|
113
126
|
async execRequest(request) {
|
|
114
127
|
const { name, arguments: args } = request.params;
|
|
128
|
+
// TODO : Check authentication in some way (see if MCP handles it)
|
|
115
129
|
const auth = null;
|
|
116
130
|
try {
|
|
117
131
|
const route = this.tools.get(name);
|
|
@@ -6,6 +6,7 @@ import { rnInputDef } from '../lib/rn/input.js';
|
|
|
6
6
|
const MULTIPLE_VALUES_SEPARATOR = ',';
|
|
7
7
|
export function UCFormFieldControl({ errMsg = null, execState, field, onChange: onChangeBase, }) {
|
|
8
8
|
const [internalValue, setInternalValue] = useState(field.getValue());
|
|
9
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: false positive : It is actually necessary (only `field` does not trigger the effect)
|
|
9
10
|
useEffect(() => {
|
|
10
11
|
setInternalValue(field.getValue());
|
|
11
12
|
}, [field.getValue()]);
|
|
@@ -43,6 +43,10 @@ export declare class AppTester {
|
|
|
43
43
|
private ucExecutor;
|
|
44
44
|
private configurator;
|
|
45
45
|
private ctx;
|
|
46
|
+
/**
|
|
47
|
+
* We use a "safe" one to avoid any "infinite loop" while trying to import/resolve a file.
|
|
48
|
+
* This can happen in case of circular dependencies for example.
|
|
49
|
+
*/
|
|
46
50
|
private safeSrcImporter;
|
|
47
51
|
private testResults;
|
|
48
52
|
private testSummary;
|
|
@@ -14,6 +14,8 @@ import { inject, injectable } from 'inversify';
|
|
|
14
14
|
import { I18nEN } from '../i18n/locales/en.js';
|
|
15
15
|
import { I18nFR } from '../i18n/locales/fr.js';
|
|
16
16
|
import { FAKE_USER_ADMIN, UCBuilder, UCInputFieldChangeOperator, ucHTTPContract, } from '../uc/index.js';
|
|
17
|
+
// We inject directly the implementation because we'll generate all the reports and not only the one that is bound to the interface.
|
|
18
|
+
// We can plan a setting à la Vitest where we specify the types of reports to generate though.
|
|
17
19
|
import { SimpleHTMLAppTestReportEmitter } from './impl/SimpleHTMLAppTestReportEmitter.js';
|
|
18
20
|
import { optsAllSet } from './opts.js';
|
|
19
21
|
import { defaultUCAuthSetters } from './uc-auth.js';
|
|
@@ -40,7 +42,12 @@ let AppTester = class AppTester {
|
|
|
40
42
|
ucExecutor;
|
|
41
43
|
configurator;
|
|
42
44
|
ctx;
|
|
45
|
+
/**
|
|
46
|
+
* We use a "safe" one to avoid any "infinite loop" while trying to import/resolve a file.
|
|
47
|
+
* This can happen in case of circular dependencies for example.
|
|
48
|
+
*/
|
|
43
49
|
safeSrcImporter;
|
|
50
|
+
// biome-ignore lint/suspicious/noExplicitAny: can be anything
|
|
44
51
|
testResults;
|
|
45
52
|
testSummary;
|
|
46
53
|
ucDefSourcesCheckerOutput;
|
|
@@ -134,7 +141,9 @@ let AppTester = class AppTester {
|
|
|
134
141
|
const inputFiller = (uc) => {
|
|
135
142
|
uc.fill(input);
|
|
136
143
|
};
|
|
144
|
+
// biome-ignore lint/suspicious/noExplicitAny: can be anything
|
|
137
145
|
const { out } = await this.execUC({
|
|
146
|
+
// TODO : Pass the appropriate one so we test the real flow and not the auth
|
|
138
147
|
auth: FAKE_USER_ADMIN,
|
|
139
148
|
authName: 'ADMIN',
|
|
140
149
|
inputFiller,
|
|
@@ -148,6 +157,7 @@ let AppTester = class AppTester {
|
|
|
148
157
|
...input,
|
|
149
158
|
appManifest: this.ctx.appManifest,
|
|
150
159
|
});
|
|
160
|
+
// TODO : Add errors mapping to configurator so the developer can override this default behavior
|
|
151
161
|
let status = 'warning';
|
|
152
162
|
if (!out.err) {
|
|
153
163
|
status = 'success';
|
|
@@ -169,6 +179,9 @@ let AppTester = class AppTester {
|
|
|
169
179
|
let sideEffects = await this.configurator.sideEffects(this.ctx);
|
|
170
180
|
if (flow) {
|
|
171
181
|
name = `${flow.name} > ${name}`;
|
|
182
|
+
// For regular uc tests, side effects are cleared between each execution
|
|
183
|
+
// But it's not the case for a flow, thus each flow uc test shares the same side effects ref
|
|
184
|
+
// To have the side effects at each stage, we take a snapshot (to be improved as this is not performant at all)
|
|
172
185
|
if (sideEffects) {
|
|
173
186
|
const snapshot = JSON.parse(JSON.stringify(Array.from(sideEffects.entries())));
|
|
174
187
|
sideEffects = new Map(snapshot);
|
|
@@ -205,6 +218,7 @@ let AppTester = class AppTester {
|
|
|
205
218
|
async init({ appPath, configurator, serverClientSettings, srcImporter, }) {
|
|
206
219
|
this.configurator = configurator;
|
|
207
220
|
this.safeSrcImporter = (path) => Promise.race([
|
|
221
|
+
// We can cast because it fails or looses the race.
|
|
208
222
|
awaitForSrcImport(path),
|
|
209
223
|
srcImporter(path),
|
|
210
224
|
]);
|
|
@@ -222,6 +236,7 @@ let AppTester = class AppTester {
|
|
|
222
236
|
await this.initServer();
|
|
223
237
|
}
|
|
224
238
|
async ucTestData(ucdRef) {
|
|
239
|
+
// Auth setters
|
|
225
240
|
const defaultASs = defaultUCAuthSetters();
|
|
226
241
|
let asEntries = Object.entries(defaultASs);
|
|
227
242
|
const asConfig = await this.configurator.authSettersConfig();
|
|
@@ -236,6 +251,7 @@ let AppTester = class AppTester {
|
|
|
236
251
|
asEntries.push(...Object.entries(add));
|
|
237
252
|
}
|
|
238
253
|
}
|
|
254
|
+
// Input fillers
|
|
239
255
|
const defaultIFs = defaultUCInputFillers();
|
|
240
256
|
const ifEntries = Object.entries(defaultIFs);
|
|
241
257
|
const specificIFs = await this.configurator.inputFillers();
|
|
@@ -6,21 +6,89 @@ import type { DefaultUCAuthSetter, UCAuthSetterSet } from './uc-auth.js';
|
|
|
6
6
|
import type { CustomUCInputFiller, UCInputFillerSet } from './uc-input.js';
|
|
7
7
|
import type { UCExecutorAssertion } from './workers/UCExecutor.js';
|
|
8
8
|
export type AppTesterConfiguratorAuthSettersConfig = {
|
|
9
|
+
/**
|
|
10
|
+
* Specific auth setters to add to the default ones
|
|
11
|
+
*/
|
|
9
12
|
add?: UCAuthSetterSet;
|
|
13
|
+
/**
|
|
14
|
+
* Default auth setters to exclude
|
|
15
|
+
*
|
|
16
|
+
* For instance, if your app does not care about auth (e.g. only client side app), you can safely exclude everything except {@link ANONYMOUS}
|
|
17
|
+
*/
|
|
10
18
|
exclude?: Set<DefaultUCAuthSetter>;
|
|
11
19
|
};
|
|
12
20
|
export type AppTesterConfiguratorInputFillers<I extends UCInput = any, OPI0 extends UCOPIBase = any, OPI1 extends UCOPIBase = any> = Map<UCName, UCInputFillerSet<CustomUCInputFiller, I, OPI0, OPI1>>;
|
|
13
21
|
export type AppTesterConfiguratorSideEffects = Map<string, any>;
|
|
14
22
|
export type AppTesterConfiguratorSideEffectsSerialized = [string, any][];
|
|
15
23
|
export type AppTesterConfiguratorSpecificAssertions<I extends UCInput | undefined = undefined, OPI0 extends UCOPIBase | undefined = undefined, OPI1 extends UCOPIBase | undefined = undefined> = Map<CryptoManagerHash, UCExecutorAssertion<I, OPI0, OPI1>>;
|
|
24
|
+
/**
|
|
25
|
+
* Configure the tester for a specific app
|
|
26
|
+
*
|
|
27
|
+
* @defaultValue See {@link SimpleAppTesterConfigurator}
|
|
28
|
+
*/
|
|
16
29
|
export interface AppTesterConfigurator {
|
|
30
|
+
/**
|
|
31
|
+
* Auth setters config to add some or exclude default ones
|
|
32
|
+
*/
|
|
17
33
|
authSettersConfig(): Promise<AppTesterConfiguratorAuthSettersConfig | undefined>;
|
|
34
|
+
/**
|
|
35
|
+
* Override the implementations needed by the use cases, in `ctx.container`
|
|
36
|
+
*
|
|
37
|
+
* @param ctx
|
|
38
|
+
*/
|
|
18
39
|
bindImplementations(ctx: AppTesterCtx): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Clear what needs to be cleared after a use case execution
|
|
42
|
+
*
|
|
43
|
+
* For instance, this includes the data store, some fake queue processor checked in side effects, etc.
|
|
44
|
+
*
|
|
45
|
+
* @param ctx
|
|
46
|
+
*/
|
|
19
47
|
clearExecution(ctx: AppTesterCtx): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Define specific flows to test multiple use cases sequentially
|
|
50
|
+
*
|
|
51
|
+
* For example : SignUp > SignIn > SignOut > ResetPassword, etc.
|
|
52
|
+
*/
|
|
20
53
|
flows(): Promise<AppTesterFlow[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Define specific input fillers, per use case, in addition to the default ones
|
|
56
|
+
*
|
|
57
|
+
* @see defaultInputFillers
|
|
58
|
+
*/
|
|
21
59
|
inputFillers(): Promise<AppTesterConfiguratorInputFillers | undefined>;
|
|
60
|
+
/**
|
|
61
|
+
* Override the `ctx.opts()`, in case the app has some specificities
|
|
62
|
+
*/
|
|
22
63
|
opts(): Promise<AppTesterCtx['opts']>;
|
|
64
|
+
/**
|
|
65
|
+
* Seed some data in any data store needed by the use cases
|
|
66
|
+
*
|
|
67
|
+
* @param ctx
|
|
68
|
+
*/
|
|
23
69
|
seed(ctx: AppTesterCtx): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Register the side effects that need to be tracked
|
|
72
|
+
*
|
|
73
|
+
* For instance, this is where you register {@link FakeEmailManager.entries} to check the emails sent by use cases.
|
|
74
|
+
*
|
|
75
|
+
* Or it can also be the entries of some fake job processor to check the jobs dispatched by use cases.
|
|
76
|
+
*
|
|
77
|
+
* Note that it works only if there are no `specificAssertions` for the given use case.
|
|
78
|
+
*
|
|
79
|
+
* Otherwise, you need to assert side effects manually.
|
|
80
|
+
*
|
|
81
|
+
* @param ctx
|
|
82
|
+
*/
|
|
24
83
|
sideEffects(ctx: AppTesterCtx): Promise<AppTesterConfiguratorSideEffects | undefined>;
|
|
84
|
+
/**
|
|
85
|
+
* Define specific assertions for a specific use case
|
|
86
|
+
*
|
|
87
|
+
* Otherwise, it matches the snapshot.
|
|
88
|
+
*
|
|
89
|
+
* For instance, you can use this if a specific use case performs some random processing (e.g. generating random data).
|
|
90
|
+
*
|
|
91
|
+
* Generally speaking, it's always better to have deterministic tests, so it's usually better to bind deterministic implementations in the tests.
|
|
92
|
+
*/
|
|
25
93
|
specificAssertions(): Promise<AppTesterConfiguratorSpecificAssertions | undefined>;
|
|
26
94
|
}
|
|
@@ -3,6 +3,15 @@ import { type UCDataStore } from '../uc/index.js';
|
|
|
3
3
|
interface Input {
|
|
4
4
|
ucDataStore: UCDataStore;
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* Test that a {@link UCDataStore} conforms to the spec
|
|
8
|
+
*
|
|
9
|
+
* By default it runs tests on the projection mechanism.
|
|
10
|
+
* Therefore, you need to create one in your implementation when creating your test suite.
|
|
11
|
+
* See `src/uc/impl/KnexUCDataStore.test.ts` for an example.
|
|
12
|
+
*
|
|
13
|
+
* Otherwise you can just `skipProjectionTesting`, although it's not recommended.
|
|
14
|
+
*/
|
|
6
15
|
export declare class UCDataStoreTester implements Worker<Input, Promise<void>> {
|
|
7
16
|
private clockManager;
|
|
8
17
|
private cryptoManager;
|
|
@@ -18,6 +18,15 @@ import { UCExecMode, } from '../uc/index.js';
|
|
|
18
18
|
const ERR_SHOULD_NOT_EXIST_AFTER_DESTROY = 'It should not exist after destroy';
|
|
19
19
|
const ERR_SHOULD_EXIST_AFTER_INSTALL = 'It should exist after install';
|
|
20
20
|
const ERR_SHOULD_RETURN_X_RECORDS = (n) => `It should return ${n} record(s)`;
|
|
21
|
+
/**
|
|
22
|
+
* Test that a {@link UCDataStore} conforms to the spec
|
|
23
|
+
*
|
|
24
|
+
* By default it runs tests on the projection mechanism.
|
|
25
|
+
* Therefore, you need to create one in your implementation when creating your test suite.
|
|
26
|
+
* See `src/uc/impl/KnexUCDataStore.test.ts` for an example.
|
|
27
|
+
*
|
|
28
|
+
* Otherwise you can just `skipProjectionTesting`, although it's not recommended.
|
|
29
|
+
*/
|
|
21
30
|
let UCDataStoreTester = class UCDataStoreTester {
|
|
22
31
|
static { UCDataStoreTester_1 = this; }
|
|
23
32
|
clockManager;
|
|
@@ -60,6 +69,7 @@ let UCDataStoreTester = class UCDataStoreTester {
|
|
|
60
69
|
await ucDataStore.clear();
|
|
61
70
|
this.readRes = await ucDataStore.read();
|
|
62
71
|
this.expectXRecords(0);
|
|
72
|
+
// Write a last one in case need to watch data in the DB
|
|
63
73
|
await this.ucDataStore.write({
|
|
64
74
|
aggregateId: this.cryptoManager.randomUUID(),
|
|
65
75
|
appName: APP_NAME_PLACEHOLDER,
|
|
@@ -116,9 +126,12 @@ let UCDataStoreTester = class UCDataStoreTester {
|
|
|
116
126
|
];
|
|
117
127
|
}
|
|
118
128
|
buildFiltersTestData() {
|
|
129
|
+
// biome-ignore lint/style/noNonNullAssertion: we're in a test
|
|
119
130
|
const entry = this.entries[0];
|
|
120
131
|
const [aggregateId, appName, ucNames, organizationId, userId] = entry;
|
|
132
|
+
// biome-ignore lint/style/noNonNullAssertion: we're in a test
|
|
121
133
|
const name = ucNames[0];
|
|
134
|
+
// TODO : Enhance these with a combination of filters
|
|
122
135
|
return [
|
|
123
136
|
[{ aggregateId }, 2],
|
|
124
137
|
[{ aggregateId: [aggregateId] }, 2],
|
|
@@ -33,6 +33,13 @@ SimpleAppDocsEmitter = __decorate([
|
|
|
33
33
|
__metadata("design:paramtypes", [Object])
|
|
34
34
|
], SimpleAppDocsEmitter);
|
|
35
35
|
export { SimpleAppDocsEmitter };
|
|
36
|
+
// For now, we can have it here. When it becomes harder to maintain, we can introduce some kind of template engine.
|
|
37
|
+
// Be aware that this will introduce complexities on building the lib.
|
|
38
|
+
// We'll need to include these templates in the build and make them accessible via package.json "exports" or any other mechanism.
|
|
39
|
+
// Hence the choice to keep it simple for now.
|
|
40
|
+
// Defined it as function in case we need to pass args.
|
|
41
|
+
// Using --- for the comment to make it compatible with pandoc
|
|
42
|
+
// See https://stackoverflow.com/a/4829998/1259118
|
|
36
43
|
const template = (cols, items) => `<!---
|
|
37
44
|
All this code has been auto generated.
|
|
38
45
|
DO NOT EDIT.
|
|
@@ -55,6 +62,9 @@ ${diagram(item)}`)
|
|
|
55
62
|
|---|${cols.map((_c) => '---').join('|')}|
|
|
56
63
|
${items.map((item, idx) => ['', idx + 1, ...cols.map((c) => fmtTechSummaryField(item[c])), ''].join('|')).join('\n')}
|
|
57
64
|
`;
|
|
65
|
+
/*
|
|
66
|
+
* Diagram
|
|
67
|
+
*/
|
|
58
68
|
const CHECK_POLICY = 'đ Check policy';
|
|
59
69
|
const CHECK_POLICY_COND = 'when any validation fails';
|
|
60
70
|
const CHECK_POLICY_COND_ACTION = 'show failure';
|
|
@@ -69,6 +79,8 @@ const SEND = 'đ¤ Send';
|
|
|
69
79
|
const SUBMIT = 'âŠī¸ Submit';
|
|
70
80
|
const TRIGGER = 'â¤´ī¸ Trigger';
|
|
71
81
|
function diagram(item) {
|
|
82
|
+
// Debugger : https://mermaid.live/edit
|
|
83
|
+
// Messages : https://mermaid.js.org/syntax/sequenceDiagram.html#messages
|
|
72
84
|
const client = 'Client';
|
|
73
85
|
const server = 'Server';
|
|
74
86
|
const user = 'User';
|
|
@@ -76,6 +88,8 @@ function diagram(item) {
|
|
|
76
88
|
const { ioIFields, ioOPI0Fields, ioOPI1Fields, lifecycleClientPolicy, lifecycleClientSteps, lifecycleServerPolicy, lifecycleServerSteps, metadataSensitive, } = item;
|
|
77
89
|
let req = TRIGGER;
|
|
78
90
|
if (ioIFields && ioIFields.length > 0) {
|
|
91
|
+
// TODO : Include only fields to fill manually
|
|
92
|
+
// Not sure though, as for CLI for example (i.e. noContext), one needs to provide all of them
|
|
79
93
|
req = `${FILL}${LB}${diagramUCFields(item.ioIFields)}`;
|
|
80
94
|
}
|
|
81
95
|
lines.push(`${user}->>+${client}: ${req}`);
|
|
@@ -89,6 +103,7 @@ function diagram(item) {
|
|
|
89
103
|
if (lifecycleClientSteps) {
|
|
90
104
|
lines.push(...diagramUCMainSteps(client, lifecycleClientSteps));
|
|
91
105
|
}
|
|
106
|
+
// This is an approximation. Might need to improve it.
|
|
92
107
|
const hasServer = item.lifecycleServerPolicy?.value;
|
|
93
108
|
if (hasServer) {
|
|
94
109
|
req = SEND;
|
|
@@ -142,11 +157,16 @@ function diagramUCPolicy(participant, caller, lifecyclePolicyField) {
|
|
|
142
157
|
'end',
|
|
143
158
|
];
|
|
144
159
|
}
|
|
160
|
+
/*
|
|
161
|
+
* Technical Summary
|
|
162
|
+
*/
|
|
145
163
|
function fmtTechSummaryField(field) {
|
|
146
164
|
if (!field) {
|
|
147
165
|
return '';
|
|
148
166
|
}
|
|
149
167
|
const values = Array.isArray(field) ? field : [field];
|
|
168
|
+
// NOTE : <br> won't work for every markdown renderer.
|
|
169
|
+
// See https://stackoverflow.com/questions/11700487/how-do-i-add-a-newline-in-a-markdown-table
|
|
150
170
|
return values.map(fmtTechSummaryFieldVal).join('<br>');
|
|
151
171
|
}
|
|
152
172
|
function fmtTechSummaryFieldVal(field) {
|
|
@@ -155,7 +175,7 @@ function fmtTechSummaryFieldVal(field) {
|
|
|
155
175
|
if (err) {
|
|
156
176
|
res += `â ${err}`;
|
|
157
177
|
}
|
|
158
|
-
res = res.replace(/[\u00A0-\u9999<>\&]/g, (i) => `&#${i.charCodeAt(0)};`);
|
|
159
|
-
res = res.replaceAll('|', '\\|');
|
|
178
|
+
res = res.replace(/[\u00A0-\u9999<>\&]/g, (i) => `&#${i.charCodeAt(0)};`); // TS generics considered as HTML
|
|
179
|
+
res = res.replaceAll('|', '\\|'); // TS intersection vs Markdown table column
|
|
160
180
|
return res;
|
|
161
181
|
}
|