libmodulor 0.4.0 → 0.6.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/.github/dependabot.yml +19 -0
- package/CHANGELOG.md +35 -1
- package/README.md +10 -4
- 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/i18n.js +4 -0
- package/dist/esm/apps/Helper/src/lib/project.d.ts +2 -0
- package/dist/esm/apps/Helper/src/lib/project.js +120 -0
- package/dist/esm/apps/Helper/src/manifest.d.ts +5 -0
- package/dist/esm/apps/Helper/src/manifest.js +5 -0
- package/dist/esm/apps/Helper/src/ucds/CreateProjectUCD.d.ts +15 -0
- package/dist/esm/apps/Helper/src/ucds/CreateProjectUCD.js +118 -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/dt/index.d.ts +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/index.node.d.ts +1 -0
- package/dist/esm/index.node.js +1 -0
- package/dist/esm/index.react.d.ts +1 -1
- package/dist/esm/product/manifest.d.ts +15 -0
- package/dist/esm/products/Helper/container.js +4 -0
- package/dist/esm/products/Helper/index.js +5 -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/ShellCommandExecutor.d.ts +19 -0
- package/dist/esm/std/ShellCommandExecutor.js +1 -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/NodeSpawnShellCommandExecutor.d.ts +4 -0
- package/dist/esm/std/impl/NodeSpawnShellCommandExecutor.js +41 -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 +2 -0
- package/dist/esm/std/index.js +2 -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/form.d.ts +26 -2
- package/dist/esm/target/lib/react/form.js +18 -1
- 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/UCForm.js +2 -2
- package/dist/esm/target/react-native-pure/UCFormField.d.ts +2 -9
- package/dist/esm/target/react-native-pure/UCFormField.js +9 -20
- package/dist/esm/target/react-native-pure/UCFormFieldControl.d.ts +3 -10
- package/dist/esm/target/react-native-pure/UCFormFieldControl.js +9 -8
- package/dist/esm/target/react-native-pure/UCFormFieldDesc.d.ts +2 -5
- package/dist/esm/target/react-native-pure/UCFormFieldDesc.js +2 -2
- package/dist/esm/target/react-native-pure/UCFormFieldErr.d.ts +2 -6
- package/dist/esm/target/react-native-pure/UCFormFieldLabel.d.ts +2 -5
- package/dist/esm/target/react-native-pure/UCFormFieldLabel.js +2 -2
- package/dist/esm/target/react-native-pure/UCFormSubmitControl.d.ts +2 -7
- package/dist/esm/target/react-native-pure/UCFormSubmitControl.js +1 -1
- package/dist/esm/target/react-web-pure/UCForm.js +1 -1
- package/dist/esm/target/react-web-pure/UCFormField.d.ts +2 -9
- package/dist/esm/target/react-web-pure/UCFormField.js +9 -20
- package/dist/esm/target/react-web-pure/UCFormFieldControl.d.ts +3 -10
- package/dist/esm/target/react-web-pure/UCFormFieldControl.js +20 -5
- package/dist/esm/target/react-web-pure/UCFormFieldDesc.d.ts +2 -5
- package/dist/esm/target/react-web-pure/UCFormFieldDesc.js +2 -2
- package/dist/esm/target/react-web-pure/UCFormFieldErr.d.ts +2 -6
- package/dist/esm/target/react-web-pure/UCFormFieldLabel.d.ts +2 -5
- package/dist/esm/target/react-web-pure/UCFormFieldLabel.js +3 -3
- package/dist/esm/target/react-web-pure/UCFormSubmitControl.d.ts +2 -4
- package/dist/esm/target/react-web-pure/UCFormSubmitControl.js +1 -1
- 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 +13 -14
|
@@ -2,30 +2,90 @@ import type { DataType, TBase, UIntQuantity } from '../dt/index.js';
|
|
|
2
2
|
import type { UCFieldKey } from './def.js';
|
|
3
3
|
import type { Value } from './value.js';
|
|
4
4
|
export declare enum UCInputFieldChangeOperator {
|
|
5
|
+
/**
|
|
6
|
+
* Considering the cardinality of the field (min > 1), add a new value
|
|
7
|
+
*/
|
|
5
8
|
ADD = "ADD",
|
|
9
|
+
/**
|
|
10
|
+
* Considering the cardinality of the field (min > 1), remove a value
|
|
11
|
+
*/
|
|
6
12
|
REMOVE = "REMOVE",
|
|
13
|
+
/**
|
|
14
|
+
* Reset the value of the field
|
|
15
|
+
*/
|
|
7
16
|
RESET = "RESET",
|
|
17
|
+
/**
|
|
18
|
+
* Considering the cardinality of the field (max <= 1), set the value
|
|
19
|
+
*/
|
|
8
20
|
SET = "SET"
|
|
9
21
|
}
|
|
10
22
|
export declare enum UCInputFieldFillingMode {
|
|
23
|
+
/**
|
|
24
|
+
* Set programmatically on behalf of the user (e.g. a foreign key id for a given object)
|
|
25
|
+
*/
|
|
11
26
|
AUTO_PRE = "AUTO_PRE",
|
|
27
|
+
/**
|
|
28
|
+
* Set manually by the user (e.g. a form field, a cli flag, etc.)
|
|
29
|
+
*/
|
|
12
30
|
MANUAL = "MANUAL"
|
|
13
31
|
}
|
|
14
32
|
export interface UCInputFieldDefCardinality {
|
|
15
33
|
max?: UIntQuantity;
|
|
16
34
|
min?: UIntQuantity;
|
|
17
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Definition of a use case input field
|
|
38
|
+
*/
|
|
18
39
|
export interface UCInputFieldDef<T extends DataType> {
|
|
40
|
+
/**
|
|
41
|
+
* A field can have 0, 1 or n values. This field defines the rules.
|
|
42
|
+
*
|
|
43
|
+
* @defaultValue { max: 1, min: 1 } => the user must absolutely provide one value only
|
|
44
|
+
*
|
|
45
|
+
* @example { max: 5, min: 0 } => the user must provide at most 5 values or none
|
|
46
|
+
* @example { min: 0 } => the user must provide 0 values or none
|
|
47
|
+
*/
|
|
19
48
|
cardinality?: UCInputFieldDefCardinality;
|
|
49
|
+
/**
|
|
50
|
+
* @defaultValue {@link UCInputFieldFillingMode.MANUAL}
|
|
51
|
+
*/
|
|
20
52
|
fillingMode?: UCInputFieldFillingMode;
|
|
53
|
+
/**
|
|
54
|
+
* @defaultValue false
|
|
55
|
+
*/
|
|
21
56
|
readOnly?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Some types are automatically considered sensitive (e.g. {@link Password}).
|
|
59
|
+
*
|
|
60
|
+
* But you can force the behavior with this setting for any other type of field.
|
|
61
|
+
*
|
|
62
|
+
* @defaultValue false
|
|
63
|
+
*/
|
|
22
64
|
sensitive?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* When you persist a use case, all the input fields are automatically persisted as well.
|
|
67
|
+
*
|
|
68
|
+
* Sometimes this is not wanted. Setting the field as transient will exclude it from being persisted.
|
|
69
|
+
*
|
|
70
|
+
* @defaultValue false
|
|
71
|
+
*/
|
|
23
72
|
transient?: boolean;
|
|
24
73
|
type: TBase<T>;
|
|
25
74
|
}
|
|
26
75
|
export type UCInputFieldValue<T extends DataType> = Value<T>;
|
|
27
76
|
export declare function ucifExamples<T extends DataType>(def: UCInputFieldDef<T>): T[] | undefined;
|
|
28
77
|
export declare function ucifHint<T extends DataType>(def: UCInputFieldDef<T>): string | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* The unique id associated to this field
|
|
80
|
+
*
|
|
81
|
+
* By default it would return `inputfield-myField`.
|
|
82
|
+
* If you have the same field multiple times in one context (e.g. a web page), pass a unique element to the `prefix`.
|
|
83
|
+
* For example `uc1-inputfield-myField` and `uc2-inputfield-myField`
|
|
84
|
+
*
|
|
85
|
+
* @param prefix
|
|
86
|
+
* @param separator
|
|
87
|
+
* @returns
|
|
88
|
+
*/
|
|
29
89
|
export declare function ucifId(key: UCFieldKey, prefix?: string, separator?: string): string;
|
|
30
90
|
export declare function ucifIsMandatory<T extends DataType>(def: UCInputFieldDef<T>): boolean;
|
|
31
91
|
export declare function ucifRepeatability<T extends DataType>(def: UCInputFieldDef<T>): [boolean, UIntQuantity];
|
|
@@ -1,21 +1,41 @@
|
|
|
1
1
|
export var UCInputFieldChangeOperator;
|
|
2
2
|
(function (UCInputFieldChangeOperator) {
|
|
3
|
+
/**
|
|
4
|
+
* Considering the cardinality of the field (min > 1), add a new value
|
|
5
|
+
*/
|
|
3
6
|
UCInputFieldChangeOperator["ADD"] = "ADD";
|
|
7
|
+
/**
|
|
8
|
+
* Considering the cardinality of the field (min > 1), remove a value
|
|
9
|
+
*/
|
|
4
10
|
UCInputFieldChangeOperator["REMOVE"] = "REMOVE";
|
|
11
|
+
/**
|
|
12
|
+
* Reset the value of the field
|
|
13
|
+
*/
|
|
5
14
|
UCInputFieldChangeOperator["RESET"] = "RESET";
|
|
15
|
+
/**
|
|
16
|
+
* Considering the cardinality of the field (max <= 1), set the value
|
|
17
|
+
*/
|
|
6
18
|
UCInputFieldChangeOperator["SET"] = "SET";
|
|
7
19
|
})(UCInputFieldChangeOperator || (UCInputFieldChangeOperator = {}));
|
|
8
20
|
export var UCInputFieldFillingMode;
|
|
9
21
|
(function (UCInputFieldFillingMode) {
|
|
22
|
+
/**
|
|
23
|
+
* Set programmatically on behalf of the user (e.g. a foreign key id for a given object)
|
|
24
|
+
*/
|
|
10
25
|
UCInputFieldFillingMode["AUTO_PRE"] = "AUTO_PRE";
|
|
26
|
+
/**
|
|
27
|
+
* Set manually by the user (e.g. a form field, a cli flag, etc.)
|
|
28
|
+
*/
|
|
11
29
|
UCInputFieldFillingMode["MANUAL"] = "MANUAL";
|
|
12
30
|
})(UCInputFieldFillingMode || (UCInputFieldFillingMode = {}));
|
|
13
31
|
export function ucifExamples(def) {
|
|
14
32
|
const { type } = def;
|
|
15
33
|
const examples = type.getExamples();
|
|
34
|
+
// Leaving the value `undefined` means you want the default value
|
|
16
35
|
if (examples === undefined) {
|
|
17
36
|
return [type.example()];
|
|
18
37
|
}
|
|
38
|
+
// Setting the examples to `[]` means you don't want them
|
|
19
39
|
if (examples.length === 0) {
|
|
20
40
|
return undefined;
|
|
21
41
|
}
|
|
@@ -37,6 +57,17 @@ export function ucifHint(def) {
|
|
|
37
57
|
}
|
|
38
58
|
return examples.join(', ');
|
|
39
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* The unique id associated to this field
|
|
62
|
+
*
|
|
63
|
+
* By default it would return `inputfield-myField`.
|
|
64
|
+
* If you have the same field multiple times in one context (e.g. a web page), pass a unique element to the `prefix`.
|
|
65
|
+
* For example `uc1-inputfield-myField` and `uc2-inputfield-myField`
|
|
66
|
+
*
|
|
67
|
+
* @param prefix
|
|
68
|
+
* @param separator
|
|
69
|
+
* @returns
|
|
70
|
+
*/
|
|
40
71
|
export function ucifId(key, prefix = 'inputfield', separator = '-') {
|
|
41
72
|
return `${prefix}${separator}${key}`;
|
|
42
73
|
}
|
|
@@ -60,12 +91,14 @@ export function ucifIsSensitive(def) {
|
|
|
60
91
|
}
|
|
61
92
|
export function ucifMustBeFilledManually(def, opts) {
|
|
62
93
|
const { fillingMode } = def;
|
|
94
|
+
// If there is no mode, we consider it as UCInputFieldFillingMode.MANUAL
|
|
63
95
|
if (!fillingMode) {
|
|
64
96
|
return true;
|
|
65
97
|
}
|
|
66
98
|
const fillingModes = [
|
|
67
99
|
UCInputFieldFillingMode.MANUAL,
|
|
68
100
|
];
|
|
101
|
+
// If there is no context, it means that the field cannot be set via UCInputFieldFillingMode.AUTO_PRE (e.g. in CLI target)
|
|
69
102
|
if (opts?.noContext) {
|
|
70
103
|
fillingModes.push(UCInputFieldFillingMode.AUTO_PRE);
|
|
71
104
|
}
|
package/dist/esm/uc/input.d.ts
CHANGED
|
@@ -1,11 +1,35 @@
|
|
|
1
1
|
import type { StringKeys } from '../utils/index.js';
|
|
2
2
|
import type { UCInputFieldDef } from './input-field.js';
|
|
3
|
+
/**
|
|
4
|
+
* Base interface all the use case input interfaces must extend
|
|
5
|
+
*/
|
|
3
6
|
export interface UCInput {
|
|
4
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Definition of a use case input
|
|
10
|
+
*/
|
|
5
11
|
export interface UCInputDef<I extends UCInput> {
|
|
12
|
+
/**
|
|
13
|
+
* This is useful when you want to render a given field only after its dependent fields have been set.
|
|
14
|
+
*/
|
|
6
15
|
dependencies?: Partial<Record<StringKeys<I>, StringKeys<I>[]>>;
|
|
16
|
+
/**
|
|
17
|
+
* It must follow strictly the shape of the corresponding {@link UCInput} with fields sorted alphabetically.
|
|
18
|
+
*/
|
|
7
19
|
fields: Record<StringKeys<I>, UCInputFieldDef<any>>;
|
|
20
|
+
/**
|
|
21
|
+
* By default, the fields are displayed in the same order as in {@link fields} (i.e. alphabetically).
|
|
22
|
+
*
|
|
23
|
+
* You can customize this by specifying the desired order here.
|
|
24
|
+
*
|
|
25
|
+
* For example, when rendering a form, this is used.
|
|
26
|
+
*/
|
|
8
27
|
order?: StringKeys<I>[];
|
|
28
|
+
/**
|
|
29
|
+
* Cross-field validation rules
|
|
30
|
+
*
|
|
31
|
+
* For example, if you want the user to provide `a` OR `b` but not both.
|
|
32
|
+
*/
|
|
9
33
|
validation?: {
|
|
10
34
|
or?: StringKeys<I>[];
|
|
11
35
|
};
|
|
@@ -7,6 +7,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
import { injectable } from 'inversify';
|
|
8
8
|
let IdleServerMain = class IdleServerMain {
|
|
9
9
|
async exec(_props) {
|
|
10
|
+
// Right now it's the same as IdleClientMain, but it's better to have 2 impls in case they need to diverge
|
|
11
|
+
// NOOP
|
|
10
12
|
}
|
|
11
13
|
};
|
|
12
14
|
IdleServerMain = __decorate([
|
package/dist/esm/uc/manager.d.ts
CHANGED
|
@@ -8,8 +8,19 @@ import type { UCInput } from './input.js';
|
|
|
8
8
|
import type { UCOPIBase } from './opi.js';
|
|
9
9
|
import type { UCOutputOrNothing } from './output.js';
|
|
10
10
|
export interface UCManagerPersistOpts {
|
|
11
|
+
/**
|
|
12
|
+
* In case the use case relates to an existing aggregate, pass its `aggregateId` in this field.
|
|
13
|
+
* This is typically used in a `Delete` use case in order to link it to the `Create` one executed in the past.
|
|
14
|
+
*/
|
|
11
15
|
aggregateId?: UUID;
|
|
16
|
+
/**
|
|
17
|
+
* @defaultValue {@link UCExecMode.USER}
|
|
18
|
+
*/
|
|
12
19
|
executionMode?: UCExecMode;
|
|
20
|
+
/**
|
|
21
|
+
* In case the use case is performed by an anonymous user or a user outside the organization, pass the actual `organizationId` in this field.
|
|
22
|
+
* This is typically used in a use case where someone anonymous posts something for a specific organization in a multi-tenant architecture.
|
|
23
|
+
*/
|
|
13
24
|
organizationId?: UUID;
|
|
14
25
|
}
|
|
15
26
|
export interface UCManager {
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import type { AppName } from '../app/index.js';
|
|
2
2
|
import type { IconCode } from '../icon/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* The type of action the use case performs
|
|
5
|
+
*
|
|
6
|
+
* This impacts the HTTP verb used in the transport layer for example.
|
|
7
|
+
*/
|
|
3
8
|
export type UCAction = 'Create' | 'Delete' | 'List' | 'Search' | 'Update' | 'View';
|
|
4
9
|
export type UCName = Capitalize<string>;
|
|
5
10
|
export type FQUCNameSeparator = '_';
|
|
11
|
+
/**
|
|
12
|
+
* Fully qualified use case name
|
|
13
|
+
*
|
|
14
|
+
* It's made with the {@link AppName} and the {@link UCName} linked by {@link FQUCNameSeparator}.
|
|
15
|
+
*/
|
|
6
16
|
export type FQUCName = `${AppName}${FQUCNameSeparator}${UCName}`;
|
|
7
17
|
export interface UCMetadata {
|
|
8
18
|
action: UCAction;
|
|
@@ -7,6 +7,9 @@ export interface UCOPILayoutContext {
|
|
|
7
7
|
availableWidthInPx: UIntQuantity;
|
|
8
8
|
target: 'cli' | 'mobile' | 'web';
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* @alpha This feature is not fully ready yet.
|
|
12
|
+
*/
|
|
10
13
|
export type UCOPILayout<OPI extends UCOPIBase, LT extends UCOPILayoutType = UCOPILayoutType, LI extends UCOPILayoutInput = UCOPILayoutInput> = {
|
|
11
14
|
get: (item: OPI, context: UCOPILayoutContext) => LI;
|
|
12
15
|
type: LT;
|
package/dist/esm/uc/opi.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import type { DataType, UUID } from '../dt/index.js';
|
|
2
2
|
import type { Value } from './value.js';
|
|
3
|
+
/**
|
|
4
|
+
* Base interface all the use case OPI interfaces must extend
|
|
5
|
+
*/
|
|
3
6
|
export interface UCOPIBase {
|
|
4
7
|
id: UUID;
|
|
5
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* A value returned as part of an OPI
|
|
11
|
+
*
|
|
12
|
+
* Unlike {@link UCInputFieldValue}, it cannot be `undefined` because it is not serializable in JSON.
|
|
13
|
+
*/
|
|
6
14
|
export type UCOPIValue<T extends DataType> = Exclude<Value<T>, undefined>;
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import type { DataType, TBase } from '../dt/index.js';
|
|
2
2
|
import type { StringKeys } from '../utils/index.js';
|
|
3
3
|
import type { UCOPIBase } from './opi.js';
|
|
4
|
+
/**
|
|
5
|
+
* Definition of a use case output field
|
|
6
|
+
*/
|
|
4
7
|
export interface UCOutputFieldDef<OPI extends UCOPIBase, T extends DataType> {
|
|
8
|
+
/**
|
|
9
|
+
* Indicates another field of the output this field can potentially link to (in the `<a></a>` way).
|
|
10
|
+
*/
|
|
5
11
|
linksTo?: StringKeys<OPI>;
|
|
12
|
+
/**
|
|
13
|
+
* The aggregation method to use to present the summary of this field across all the corresponding items.
|
|
14
|
+
*/
|
|
6
15
|
totalType?: 'sum';
|
|
7
16
|
type: TBase<T>;
|
|
8
17
|
}
|
|
@@ -6,14 +6,36 @@ import type { UCOPILayout } from './opi-layout.js';
|
|
|
6
6
|
import type { UCOPIBase } from './opi.js';
|
|
7
7
|
import type { UCOutputFieldDef } from './output-field.js';
|
|
8
8
|
export interface UCOutputPart<OPI extends UCOPIBase> {
|
|
9
|
+
/**
|
|
10
|
+
* The items making the part
|
|
11
|
+
*/
|
|
9
12
|
items: OPI[];
|
|
13
|
+
/**
|
|
14
|
+
* Pagination to pass to the next call of the use case.
|
|
15
|
+
*/
|
|
10
16
|
pagination?: ListInput;
|
|
17
|
+
/**
|
|
18
|
+
* The total number of items regardless pagination.
|
|
19
|
+
*/
|
|
11
20
|
total: UIntQuantity;
|
|
12
21
|
}
|
|
13
22
|
export type UCOutputPartDefFields<OPI extends UCOPIBase> = Record<StringKeys<OPI>, UCOutputFieldDef<OPI, any>>;
|
|
23
|
+
/**
|
|
24
|
+
* Definition of a use case output part
|
|
25
|
+
*/
|
|
14
26
|
export interface UCOutputPartDef<OPI extends UCOPIBase> {
|
|
27
|
+
/**
|
|
28
|
+
* It must follow strictly the shape of the corresponding {@link UCOPIBase} with fields sorted alphabetically.
|
|
29
|
+
*/
|
|
15
30
|
fields: Omit<UCOutputPartDefFields<OPI>, 'id'>;
|
|
16
31
|
layout?: UCOPILayout<OPI>;
|
|
32
|
+
/**
|
|
33
|
+
* By default, the fields are displayed in the same order as in {@link fields} (i.e. alphabetically).
|
|
34
|
+
*
|
|
35
|
+
* You can customize this by specifying the desired order here.
|
|
36
|
+
*
|
|
37
|
+
* For example, when rendering a card with the data, this is used.
|
|
38
|
+
*/
|
|
17
39
|
order?: StringKeys<OPI>[];
|
|
18
40
|
related?: {
|
|
19
41
|
global: UCDef<any, any, any>[];
|
package/dist/esm/uc/output.d.ts
CHANGED
|
@@ -10,6 +10,9 @@ export interface UCOutput<OPI0 extends UCOPIBase | undefined = undefined, OPI1 e
|
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
12
|
export type UCOutputOrNothing<OPI0 extends UCOPIBase | undefined = undefined, OPI1 extends UCOPIBase | undefined = undefined> = UCOutput<OPI0, OPI1> | void;
|
|
13
|
+
/**
|
|
14
|
+
* Definition of a use case output
|
|
15
|
+
*/
|
|
13
16
|
export interface UCOutputDef<OPI0 extends UCOPIBase | undefined = undefined, OPI1 extends UCOPIBase | undefined = undefined> {
|
|
14
17
|
parts?: {
|
|
15
18
|
_0: UCOutputPartDef<NonNullable<OPI0>>;
|
package/dist/esm/uc/policy.d.ts
CHANGED
|
@@ -8,6 +8,28 @@ export interface UCPolicyInput<I extends UCInput | undefined = undefined, OPI0 e
|
|
|
8
8
|
export interface UCPolicyOutput {
|
|
9
9
|
allowed: boolean;
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* The policy defines the type(s) of user(s) who can perform the use case
|
|
13
|
+
*
|
|
14
|
+
* It corresponds more or less to RBAC (Resource Based Access Control).
|
|
15
|
+
*
|
|
16
|
+
* At this moment, for simplicity, ABAC (Attribute Based Access Control) must be done in the `main` of a use case.
|
|
17
|
+
* For example, if you have to check that a user must be the owner of a resource.
|
|
18
|
+
*
|
|
19
|
+
* The main reason for this choice at this moment, is to avoid "double-fetching" in the `policy` and in `main`.
|
|
20
|
+
* 1. Fetch the resource (e.g. by id) to check if the user is the owner => Accept
|
|
21
|
+
* 2. Fetch the resource again to perform actions on it
|
|
22
|
+
*
|
|
23
|
+
* A good solution for this would be to pass the resources fetched from the `policy` to `main` but that is,
|
|
24
|
+
* at least for the moment, out of scope.
|
|
25
|
+
*/
|
|
11
26
|
export interface UCPolicy<I extends UCInput | undefined = undefined, OPI0 extends UCOPIBase | undefined = undefined, OPI1 extends UCOPIBase | undefined = undefined> extends Worker<UCPolicyInput<I, OPI0, OPI1>, Promise<UCPolicyOutput>> {
|
|
27
|
+
/**
|
|
28
|
+
* Determines whether the policy check can be executed before checking the auth
|
|
29
|
+
*
|
|
30
|
+
* For example, for {@link NobodyUCPolicy}, we know that there is no need to check the auth,
|
|
31
|
+
* as the policy will always return false. The same goes for {@link EverybodyUCPolicy} but
|
|
32
|
+
* in the opposite way.
|
|
33
|
+
*/
|
|
12
34
|
canBeExecutedPreAuth(): Promise<boolean>;
|
|
13
35
|
}
|
package/dist/esm/uc/sec.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
export type UCSecAuthType = 'apiKey' | 'basic' | 'jwt';
|
|
2
2
|
export type UCSecPublicApiKeyCheckType = 'off' | 'on';
|
|
3
|
+
/**
|
|
4
|
+
* Definition of the security scheme of a use case
|
|
5
|
+
*/
|
|
3
6
|
export interface UCSec {
|
|
7
|
+
/**
|
|
8
|
+
* @defaultValue {@link DEFAULT_UC_SEC_AT}
|
|
9
|
+
*/
|
|
4
10
|
authType?: UCSecAuthType;
|
|
11
|
+
/**
|
|
12
|
+
* @defaultValue {@link DEFAULT_UC_SEC_PAKCT}
|
|
13
|
+
*/
|
|
5
14
|
publicApiKeyCheckType?: UCSecPublicApiKeyCheckType;
|
|
6
15
|
}
|
package/dist/esm/uc/server.d.ts
CHANGED
|
@@ -6,7 +6,17 @@ import type { UCMain } from './main.js';
|
|
|
6
6
|
import type { UCOPIBase } from './opi.js';
|
|
7
7
|
import type { UCPolicy } from './policy.js';
|
|
8
8
|
export interface UCServerDef<I extends UCInput | undefined = undefined, OPI0 extends UCOPIBase | undefined = undefined, OPI1 extends UCOPIBase | undefined = undefined> {
|
|
9
|
+
/**
|
|
10
|
+
* Define how the use case can be executed
|
|
11
|
+
*
|
|
12
|
+
* When set to {@link UCExecMode.AUTO}, the use case is not mounted on the target (i.e. no endpoint on a server).
|
|
13
|
+
*
|
|
14
|
+
* @defaultValue {@link UCExecMode.USER}
|
|
15
|
+
*/
|
|
9
16
|
execMode?: UCExecMode;
|
|
17
|
+
/**
|
|
18
|
+
* Routine to run when mounting the use case in a {@link ServerManager}
|
|
19
|
+
*/
|
|
10
20
|
init?: Class<UCInit>;
|
|
11
21
|
main: Class<UCMain<I, OPI0, OPI1>>;
|
|
12
22
|
policy: Class<UCPolicy<I, OPI0, OPI1>>;
|
|
@@ -4,8 +4,33 @@ import type { UCDataStoreDatasetName } from './data-store.js';
|
|
|
4
4
|
import type { UCFileInputFieldRefPrefix } from './file.js';
|
|
5
5
|
import type { UCName } from './metadata.js';
|
|
6
6
|
export interface UCSettings extends Settings {
|
|
7
|
+
/**
|
|
8
|
+
* The name of the collection/table storing the persisted use cases in the data store
|
|
9
|
+
*
|
|
10
|
+
* @default UC_DEFAULT_SETTINGS.uc_data_store_ucs_dataset_name
|
|
11
|
+
*/
|
|
7
12
|
uc_data_store_ucs_dataset_name: UCDataStoreDatasetName;
|
|
13
|
+
/**
|
|
14
|
+
* The list of disabled use cases (see {@link UCExecChecker})
|
|
15
|
+
*
|
|
16
|
+
* This should be used only in specific cases (e.g. disabling in emergency a use case in production).
|
|
17
|
+
*
|
|
18
|
+
* If you want a feature-flag like mechanism, chances are you need a dedicated setting, "wrapping" multiple use cases.
|
|
19
|
+
*
|
|
20
|
+
* @default UC_DEFAULT_SETTINGS.uc_disabled_use_cases
|
|
21
|
+
*/
|
|
8
22
|
uc_disabled_use_cases: UCName[];
|
|
23
|
+
/**
|
|
24
|
+
* The prefix of the file path when the use case has been processed, before storing
|
|
25
|
+
* @default UC_DEFAULT_SETTINGS.uc_file_ref_prefix
|
|
26
|
+
*/
|
|
9
27
|
uc_file_ref_prefix: UCFileInputFieldRefPrefix;
|
|
28
|
+
/**
|
|
29
|
+
* The directory path where the use case input files are copied after being processed
|
|
30
|
+
*
|
|
31
|
+
* In the future, we can imagine storing in other types of storage (e.g. S3-like).
|
|
32
|
+
*
|
|
33
|
+
* @default UC_DEFAULT_SETTINGS.uc_files_directory_path
|
|
34
|
+
*/
|
|
10
35
|
uc_files_directory_path: FilePath;
|
|
11
36
|
}
|
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
export declare enum UCOutputSideEffectType {
|
|
2
|
+
/**
|
|
3
|
+
* Trigger a clearing of the auth on the calling system (e.g. `SignOut`).
|
|
4
|
+
*/
|
|
2
5
|
CLEAR_AUTH = "CLEAR_AUTH",
|
|
6
|
+
/**
|
|
7
|
+
* Trigger a redirect on the calling system (e.g. after the final round of an OAuth1 flow)
|
|
8
|
+
*
|
|
9
|
+
* NOTE : This is a "final" side effects, which means it must be the last one in the array of side effects.
|
|
10
|
+
* Indeed, in most servers, once you redirect, you cannot do more with the `req`/`res` (e.g. on `express`).
|
|
11
|
+
*
|
|
12
|
+
* It expects a field `redirect: URL` in `output.parts._0.items[0]`.
|
|
13
|
+
*/
|
|
3
14
|
REDIRECT = "REDIRECT",
|
|
15
|
+
/**
|
|
16
|
+
* Trigger a setting of the auth on the calling system (e.g. `SignIn` / `SignUp`).
|
|
17
|
+
*
|
|
18
|
+
* It expects a field `jwt: JWT` in `output.parts._0.items[0]`.
|
|
19
|
+
*/
|
|
4
20
|
SET_AUTH = "SET_AUTH"
|
|
5
21
|
}
|
|
6
22
|
export type UCOutputSideEffect = {
|
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
export var UCOutputSideEffectType;
|
|
2
2
|
(function (UCOutputSideEffectType) {
|
|
3
|
+
/**
|
|
4
|
+
* Trigger a clearing of the auth on the calling system (e.g. `SignOut`).
|
|
5
|
+
*/
|
|
3
6
|
UCOutputSideEffectType["CLEAR_AUTH"] = "CLEAR_AUTH";
|
|
7
|
+
/**
|
|
8
|
+
* Trigger a redirect on the calling system (e.g. after the final round of an OAuth1 flow)
|
|
9
|
+
*
|
|
10
|
+
* NOTE : This is a "final" side effects, which means it must be the last one in the array of side effects.
|
|
11
|
+
* Indeed, in most servers, once you redirect, you cannot do more with the `req`/`res` (e.g. on `express`).
|
|
12
|
+
*
|
|
13
|
+
* It expects a field `redirect: URL` in `output.parts._0.items[0]`.
|
|
14
|
+
*/
|
|
4
15
|
UCOutputSideEffectType["REDIRECT"] = "REDIRECT";
|
|
16
|
+
/**
|
|
17
|
+
* Trigger a setting of the auth on the calling system (e.g. `SignIn` / `SignUp`).
|
|
18
|
+
*
|
|
19
|
+
* It expects a field `jwt: JWT` in `output.parts._0.items[0]`.
|
|
20
|
+
*/
|
|
5
21
|
UCOutputSideEffectType["SET_AUTH"] = "SET_AUTH";
|
|
6
22
|
})(UCOutputSideEffectType || (UCOutputSideEffectType = {}));
|
|
@@ -2,9 +2,21 @@ import type { UC } from '../UC.js';
|
|
|
2
2
|
import type { UCInput } from '../input.js';
|
|
3
3
|
import type { UCOPIBase } from '../opi.js';
|
|
4
4
|
interface Opts {
|
|
5
|
+
/**
|
|
6
|
+
* @defaultValue false
|
|
7
|
+
*/
|
|
5
8
|
forceArrayAsEmpty?: boolean | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* @defaultValue true
|
|
11
|
+
*/
|
|
6
12
|
forceBooleanAsFalse?: boolean | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* @defaultValue false
|
|
15
|
+
*/
|
|
7
16
|
ignoreTransient?: boolean | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* @defaultValue false
|
|
19
|
+
*/
|
|
8
20
|
ignoreUndefined?: boolean | undefined;
|
|
9
21
|
}
|
|
10
22
|
export declare function rInput<I extends UCInput | undefined = undefined, OPI0 extends UCOPIBase | undefined = undefined, OPI1 extends UCOPIBase | undefined = undefined>(uc: UC<I, OPI0, OPI1>, opts?: Opts): NonNullable<I>;
|
|
@@ -32,6 +32,8 @@ export function rInput(uc, opts) {
|
|
|
32
32
|
value = [];
|
|
33
33
|
}
|
|
34
34
|
if (!ignoreUndefined || (ignoreUndefined && value !== undefined)) {
|
|
35
|
+
// Useful when we get the input before persisting for example.
|
|
36
|
+
// Otherwise it will persist `undefined` as a string in the database, for nothing.
|
|
35
37
|
input[f.key] = value;
|
|
36
38
|
}
|
|
37
39
|
}
|
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
import type { DataType } from '../../dt/index.js';
|
|
2
2
|
import type { Value } from '../value.js';
|
|
3
|
+
/**
|
|
4
|
+
* Read the value as a primitive
|
|
5
|
+
*
|
|
6
|
+
* To be used when the field has a 0..1 cardinality.
|
|
7
|
+
*
|
|
8
|
+
* @param value
|
|
9
|
+
* @param or
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
3
12
|
export declare function rVal0<T extends DataType>(value: Value<T>, or?: T): T | null;
|
|
13
|
+
/**
|
|
14
|
+
* Require the value as a primitive
|
|
15
|
+
*
|
|
16
|
+
* To be used when the field has a 1..1 cardinality.
|
|
17
|
+
*
|
|
18
|
+
* @param value
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
4
21
|
export declare function reqVal0<T extends DataType>(value: Value<T>): T;
|
|
22
|
+
/**
|
|
23
|
+
* Get the value as an array
|
|
24
|
+
*
|
|
25
|
+
* To be used when the field has a 0..* cardinality.
|
|
26
|
+
*
|
|
27
|
+
* @param value
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
5
30
|
export declare function rValArr<T extends DataType>(value: Value<T>): T[];
|
|
@@ -1,10 +1,29 @@
|
|
|
1
1
|
import { isBlank } from '../../utils/index.js';
|
|
2
|
+
// NOTE : the "r" prefix stands for "read" and the "req" prefix stands for "require"
|
|
3
|
+
/**
|
|
4
|
+
* Read the value as a primitive
|
|
5
|
+
*
|
|
6
|
+
* To be used when the field has a 0..1 cardinality.
|
|
7
|
+
*
|
|
8
|
+
* @param value
|
|
9
|
+
* @param or
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
// TODO : Find a way to return `T` when `or` is set (function override does not work)
|
|
2
13
|
export function rVal0(value, or) {
|
|
3
14
|
if (isBlank(value)) {
|
|
4
15
|
return or ?? null;
|
|
5
16
|
}
|
|
6
17
|
return Array.isArray(value) ? (value[0] ?? null) : value;
|
|
7
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Require the value as a primitive
|
|
21
|
+
*
|
|
22
|
+
* To be used when the field has a 1..1 cardinality.
|
|
23
|
+
*
|
|
24
|
+
* @param value
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
8
27
|
export function reqVal0(value) {
|
|
9
28
|
const val = rVal0(value);
|
|
10
29
|
if (isBlank(val)) {
|
|
@@ -12,6 +31,14 @@ export function reqVal0(value) {
|
|
|
12
31
|
}
|
|
13
32
|
return val;
|
|
14
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Get the value as an array
|
|
36
|
+
*
|
|
37
|
+
* To be used when the field has a 0..* cardinality.
|
|
38
|
+
*
|
|
39
|
+
* @param value
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
15
42
|
export function rValArr(value) {
|
|
16
43
|
if (isBlank(value)) {
|
|
17
44
|
return [];
|
|
@@ -2,4 +2,13 @@ import type { UCDataStoreRecord } from '../data-store.js';
|
|
|
2
2
|
import type { UCData } from '../data.js';
|
|
3
3
|
import type { UCInput } from '../input.js';
|
|
4
4
|
import type { UCName } from '../metadata.js';
|
|
5
|
+
/**
|
|
6
|
+
* Check whether a data store records corresponds to the passed type
|
|
7
|
+
*
|
|
8
|
+
* Useful when fetching multiple records at once and looping over them to build an aggregate
|
|
9
|
+
*
|
|
10
|
+
* @param rec
|
|
11
|
+
* @param name
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
5
14
|
export declare const recIs: <I extends UCInput | undefined = undefined, D extends UCData | null = null>(rec: UCDataStoreRecord<any, any>, name: UCName) => rec is UCDataStoreRecord<I, D>;
|
|
@@ -1 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Check whether a data store records corresponds to the passed type
|
|
3
|
+
*
|
|
4
|
+
* Useful when fetching multiple records at once and looping over them to build an aggregate
|
|
5
|
+
*
|
|
6
|
+
* @param rec
|
|
7
|
+
* @param name
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export const recIs = (
|
|
11
|
+
// biome-ignore lint/suspicious/noExplicitAny: can be anything
|
|
12
|
+
rec, name) => rec.name === name;
|