@jskit-ai/crud-core 0.1.26 → 0.1.28
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/package.descriptor.mjs +2 -2
- package/package.json +17 -7
- package/src/client/composables/crudClientSupportHelpers.js +5 -17
- package/src/server/createCrudRepositoryFromResource.js +57 -0
- package/src/server/createCrudServiceFromResource.js +101 -0
- package/src/server/crudModuleConfig.js +13 -21
- package/src/server/fieldAccess.js +316 -0
- package/src/server/listQueryValidators.js +87 -0
- package/src/server/lookupHydration.js +546 -0
- package/src/server/lookupPathSupport.js +45 -0
- package/src/server/lookupProviders.js +43 -0
- package/src/server/repositoryMethods.js +381 -0
- package/src/server/repositorySupport.js +205 -0
- package/src/server/serviceEvents.js +53 -0
- package/src/shared/crudFieldMetaSupport.js +54 -0
- package/src/shared/crudNamespaceSupport.js +31 -0
- package/test/createCrudRepositoryFromResource.test.js +731 -0
- package/test/createCrudServiceFromResource.test.js +263 -0
- package/test/crudFieldMetaSupport.test.js +47 -0
- package/test/fieldAccess.test.js +86 -0
- package/test/listQueryValidators.test.js +162 -0
- package/test/lookupProviders.test.js +103 -0
- package/test/repositorySupport.test.js +282 -1
- package/test/serviceEvents.test.js +28 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { normalizeText } from "@jskit-ai/kernel/shared/support/normalize";
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_CRUD_LOOKUP_CONTAINER_KEY,
|
|
4
|
+
normalizeCrudLookupContainerKey
|
|
5
|
+
} from "@jskit-ai/kernel/shared/support/crudLookup";
|
|
6
|
+
|
|
7
|
+
const CRUD_RUNTIME_LOOKUPS_FIELD_KEY = DEFAULT_CRUD_LOOKUP_CONTAINER_KEY;
|
|
8
|
+
const CRUD_LOOKUP_FORM_CONTROL_AUTOCOMPLETE = "autocomplete";
|
|
9
|
+
const CRUD_LOOKUP_FORM_CONTROL_SELECT = "select";
|
|
10
|
+
|
|
11
|
+
function checkCrudLookupFormControl(
|
|
12
|
+
value,
|
|
13
|
+
{
|
|
14
|
+
context = "crud fieldMeta ui.formControl",
|
|
15
|
+
defaultValue = CRUD_LOOKUP_FORM_CONTROL_AUTOCOMPLETE
|
|
16
|
+
} = {}
|
|
17
|
+
) {
|
|
18
|
+
const resolvedValue = value === undefined || value === null || value === "" ? defaultValue : value;
|
|
19
|
+
if (resolvedValue === "") {
|
|
20
|
+
return "";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (
|
|
24
|
+
resolvedValue === CRUD_LOOKUP_FORM_CONTROL_AUTOCOMPLETE ||
|
|
25
|
+
resolvedValue === CRUD_LOOKUP_FORM_CONTROL_SELECT
|
|
26
|
+
) {
|
|
27
|
+
return resolvedValue;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
throw new Error(
|
|
31
|
+
`${context} must be "${CRUD_LOOKUP_FORM_CONTROL_AUTOCOMPLETE}" or "${CRUD_LOOKUP_FORM_CONTROL_SELECT}". ` +
|
|
32
|
+
`Received: ${JSON.stringify(resolvedValue)}.`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function isCrudRuntimeOutputOnlyFieldKey(
|
|
37
|
+
value = "",
|
|
38
|
+
{
|
|
39
|
+
lookupContainerKey = CRUD_RUNTIME_LOOKUPS_FIELD_KEY
|
|
40
|
+
} = {}
|
|
41
|
+
) {
|
|
42
|
+
const resolvedLookupContainerKey = normalizeCrudLookupContainerKey(lookupContainerKey, {
|
|
43
|
+
context: "crud runtime lookup container key"
|
|
44
|
+
});
|
|
45
|
+
return normalizeText(value) === resolvedLookupContainerKey;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export {
|
|
49
|
+
CRUD_LOOKUP_FORM_CONTROL_AUTOCOMPLETE,
|
|
50
|
+
CRUD_LOOKUP_FORM_CONTROL_SELECT,
|
|
51
|
+
CRUD_RUNTIME_LOOKUPS_FIELD_KEY,
|
|
52
|
+
checkCrudLookupFormControl,
|
|
53
|
+
isCrudRuntimeOutputOnlyFieldKey
|
|
54
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { normalizeText } from "@jskit-ai/kernel/shared/support/normalize";
|
|
2
|
+
|
|
3
|
+
function normalizeCrudNamespace(value = "") {
|
|
4
|
+
return normalizeText(value)
|
|
5
|
+
.toLowerCase()
|
|
6
|
+
.replace(/[^a-z0-9-]+/g, "-")
|
|
7
|
+
.replace(/-+/g, "-")
|
|
8
|
+
.replace(/^-+|-+$/g, "");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function requireCrudNamespace(namespace, { context = "requireCrudNamespace" } = {}) {
|
|
12
|
+
const normalizedNamespace = normalizeCrudNamespace(namespace);
|
|
13
|
+
if (!normalizedNamespace) {
|
|
14
|
+
throw new TypeError(`${context} requires a non-empty namespace.`);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return normalizedNamespace;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function resolveCrudRecordChangedEvent(namespace = "") {
|
|
21
|
+
const normalizedNamespace = requireCrudNamespace(namespace, {
|
|
22
|
+
context: "resolveCrudRecordChangedEvent"
|
|
23
|
+
});
|
|
24
|
+
return `${normalizedNamespace.replace(/-/g, "_")}.record.changed`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
normalizeCrudNamespace,
|
|
29
|
+
requireCrudNamespace,
|
|
30
|
+
resolveCrudRecordChangedEvent
|
|
31
|
+
};
|