@yamato-daiwa/es-extensions 1.9.0-alpha.2 → 1.9.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.
Files changed (25) hide show
  1. package/Distributable/cjs/AJAX/AJAX_Service.js +1 -1
  2. package/Distributable/cjs/DataMocking/LocalizableMocking/LocalizableEntitiesByIDsMap.js +20 -5
  3. package/Distributable/cjs/DataMocking/LocalizableMocking/LocalizableSampleDataRepository.js +4 -6
  4. package/Distributable/cjs/Numbers/isStringifiedNonNegativeIntegerOfRegularNotation.js +1 -1
  5. package/Distributable/cjs/Objects/getObjectPropertySafely.js +26 -23
  6. package/Distributable/cjs/Objects/setObjectProperties.js +51 -0
  7. package/Distributable/cjs/RawObjectDataProcessor/RawObjectDataProcessor.js +166 -70
  8. package/Distributable/cjs/RawObjectDataProcessor/RawObjectDataProcessorLocalization.english.js +36 -51
  9. package/Distributable/cjs/index.js +7 -5
  10. package/Distributable/esm/AJAX/AJAX_Service.js +1 -1
  11. package/Distributable/esm/DataMocking/LocalizableMocking/LocalizableEntitiesByIDsMap.d.ts +7 -2
  12. package/Distributable/esm/DataMocking/LocalizableMocking/LocalizableEntitiesByIDsMap.js +20 -5
  13. package/Distributable/esm/DataMocking/LocalizableMocking/LocalizableSampleDataRepository.js +4 -6
  14. package/Distributable/esm/Numbers/isStringifiedNonNegativeIntegerOfRegularNotation.js +1 -1
  15. package/Distributable/esm/Objects/getObjectPropertySafely.d.ts +1 -1
  16. package/Distributable/esm/Objects/getObjectPropertySafely.js +26 -23
  17. package/Distributable/esm/Objects/setObjectProperties.d.ts +5 -0
  18. package/Distributable/esm/Objects/setObjectProperties.js +45 -0
  19. package/Distributable/esm/RawObjectDataProcessor/RawObjectDataProcessor.d.ts +6 -3
  20. package/Distributable/esm/RawObjectDataProcessor/RawObjectDataProcessor.js +166 -70
  21. package/Distributable/esm/RawObjectDataProcessor/RawObjectDataProcessorLocalization.english.js +36 -51
  22. package/Distributable/esm/index.d.ts +2 -1
  23. package/Distributable/esm/index.js +2 -1
  24. package/README.md +235 -364
  25. package/package.json +7 -7
@@ -139,7 +139,7 @@ class AJAX_Service {
139
139
  Logger_1.default.throwErrorWithFormattedMessage({
140
140
  errorInstance: new InvalidConfigError_1.default({
141
141
  customMessage: "The \"alternatingURI_PathPart\" has been specified while the static field " +
142
- "\"API_SERVER_URI_CONSTANT_PART\" has not been set."
142
+ "\"API_SERVER_URI_CONSTANT_PART__WITHOUT_TRAILING_SLASH\" has not been set."
143
143
  }),
144
144
  title: InvalidConfigError_1.default.localization.defaultTitle,
145
145
  occurrenceLocation: "AJAX_Service.normalizeURI_UntilPath(URI_PathRawDefinition)"
@@ -1,12 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  class LocalizableEntitiesByIDsMap extends Map {
4
- constructor(entries) {
5
- super(entries);
4
+ getEntityID;
5
+ constructor({ initialEntitiesWithLocalizations, getEntityID }) {
6
+ super((initialEntitiesWithLocalizations ?? []).
7
+ map(({ entity, localizations }) => [
8
+ getEntityID(entity),
9
+ {
10
+ entity,
11
+ localizations
12
+ }
13
+ ]));
14
+ this.getEntityID = getEntityID;
6
15
  }
7
- addEntries(entries) {
8
- for (const [key, value] of entries) {
9
- this.set(key, value);
16
+ addEntityWithLocalization({ entity, localizations }) {
17
+ super.set(this.getEntityID(entity), {
18
+ entity,
19
+ localizations
20
+ });
21
+ }
22
+ addEntitiesWithLocalizations(entitiesWithLocalization) {
23
+ for (const { entity, localizations } of entitiesWithLocalization) {
24
+ this.set(this.getEntityID(entity), { entity, localizations });
10
25
  }
11
26
  }
12
27
  }
@@ -31,12 +31,10 @@ class LocalizableSampleDataRepository {
31
31
  if (mustCacheGeneratedSamples) {
32
32
  this.cachedSamplesWithLocalizationsByHumanFriendlyIDs = samplesWithLocalizationsByHumanFriendlyIDs;
33
33
  }
34
- return new LocalizableEntitiesByIDsMap_1.default(Object.
35
- values(samplesWithLocalizationsByHumanFriendlyIDs).
36
- map((entityWithLocalization) => [
37
- this.getEntityID(entityWithLocalization.entity),
38
- entityWithLocalization
39
- ]));
34
+ return new LocalizableEntitiesByIDsMap_1.default({
35
+ getEntityID: this.getEntityID.bind(this),
36
+ initialEntitiesWithLocalizations: Object.values(samplesWithLocalizationsByHumanFriendlyIDs)
37
+ });
40
38
  }
41
39
  getExpectedBeInitializedSamplesWithLocalizationsByHumanFriendlyIDs() {
42
40
  return this.cachedSamplesWithLocalizationsByHumanFriendlyIDs ??
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = isStringifiedNonNegativeIntegerOfRegularNotation;
4
4
  function isStringifiedNonNegativeIntegerOfRegularNotation(value) {
5
- return (/^[1-9]\d*$/u).test(value);
5
+ return (/^(?:0|^[1-9]\d*)$/u).test(value);
6
6
  }
@@ -9,44 +9,47 @@ const Logger_1 = __importDefault(require("../Logging/Logger"));
9
9
  const InvalidParameterValueError_1 = __importDefault(require("../Errors/InvalidParameterValue/InvalidParameterValueError"));
10
10
  const isNonEmptyString_1 = __importDefault(require("../TypeGuards/Strings/isNonEmptyString"));
11
11
  const isArbitraryObject_1 = __importDefault(require("../TypeGuards/Objects/isArbitraryObject"));
12
+ const isNaturalNumberOrZero_1 = __importDefault(require("../TypeGuards/Numbers/isNaturalNumberOrZero"));
12
13
  function getObjectPropertySafely(targetObject, dotSeparatedOrArrayedPathToTargetProperty) {
13
- if (!(0, isNonEmptyString_1.default)(dotSeparatedOrArrayedPathToTargetProperty) &&
14
- (!Array.isArray(dotSeparatedOrArrayedPathToTargetProperty) ||
15
- dotSeparatedOrArrayedPathToTargetProperty.some((key) => !(0, isNonEmptyString_1.default)(key)))) {
14
+ if (!(0, isArbitraryObject_1.default)(targetObject)) {
15
+ return;
16
+ }
17
+ let targetPropertyPathSegments;
18
+ if (Array.isArray(dotSeparatedOrArrayedPathToTargetProperty) &&
19
+ dotSeparatedOrArrayedPathToTargetProperty.length > 0 &&
20
+ dotSeparatedOrArrayedPathToTargetProperty.
21
+ every((key) => (0, isNonEmptyString_1.default)(key) || (0, isNaturalNumberOrZero_1.default)(key))) {
22
+ targetPropertyPathSegments = dotSeparatedOrArrayedPathToTargetProperty;
23
+ }
24
+ else if ((0, isNaturalNumberOrZero_1.default)(dotSeparatedOrArrayedPathToTargetProperty)) {
25
+ targetPropertyPathSegments = [String(dotSeparatedOrArrayedPathToTargetProperty)];
26
+ }
27
+ else if ((0, isNonEmptyString_1.default)(dotSeparatedOrArrayedPathToTargetProperty)) {
28
+ targetPropertyPathSegments = (0, splitString_1.default)(dotSeparatedOrArrayedPathToTargetProperty, ".");
29
+ }
30
+ else {
16
31
  Logger_1.default.logError({
17
32
  errorType: InvalidParameterValueError_1.default.NAME,
18
33
  title: InvalidParameterValueError_1.default.localization.defaultTitle,
19
34
  description: InvalidParameterValueError_1.default.localization.generateDescription({
20
35
  parameterNumber: 2,
21
36
  parameterName: "dotSeparatedOrArrayedPathToTargetProperty",
22
- messageSpecificPart: "This parameter must be either non-empty string or array of non-empty strings."
37
+ messageSpecificPart: "This parameter must be either a non-empty string, or a non-negative integer, or a non-empty array " +
38
+ "of strings and/or non-negative integers."
23
39
  }),
24
40
  occurrenceLocation: "getObjectPropertySafely(targetObject, dotSeparatedOrArrayedPathToTargetProperty)"
25
41
  });
26
42
  return;
27
43
  }
28
- if (!(0, isArbitraryObject_1.default)(targetObject)) {
29
- return;
30
- }
31
- let targetPropertyPathSegments;
32
- if (Array.isArray(dotSeparatedOrArrayedPathToTargetProperty)) {
33
- targetPropertyPathSegments = dotSeparatedOrArrayedPathToTargetProperty;
34
- }
35
- else {
36
- targetPropertyPathSegments = (0, splitString_1.default)(dotSeparatedOrArrayedPathToTargetProperty, ".");
37
- }
38
- if (targetPropertyPathSegments.length === 0) {
39
- return;
40
- }
41
44
  let objectOfCurrentDepthLevel = targetObject;
42
- for (let depthLevel = 1; depthLevel <= targetPropertyPathSegments.length; depthLevel++) {
43
- const isLastDepthLevel = depthLevel === targetPropertyPathSegments.length;
44
- const valueOfNextDepthLevel = objectOfCurrentDepthLevel[targetPropertyPathSegments[depthLevel - 1]];
45
+ for (let depthLevel__numerationFrom1 = 1; depthLevel__numerationFrom1 <= targetPropertyPathSegments.length; depthLevel__numerationFrom1++) {
46
+ const isLastDepthLevel = depthLevel__numerationFrom1 === targetPropertyPathSegments.length;
47
+ const valueOfCurrentDepthLevel = objectOfCurrentDepthLevel[targetPropertyPathSegments[depthLevel__numerationFrom1 - 1]];
45
48
  if (isLastDepthLevel) {
46
- return valueOfNextDepthLevel;
49
+ return valueOfCurrentDepthLevel;
47
50
  }
48
- else if ((0, isArbitraryObject_1.default)(valueOfNextDepthLevel)) {
49
- objectOfCurrentDepthLevel = valueOfNextDepthLevel;
51
+ else if ((0, isArbitraryObject_1.default)(valueOfCurrentDepthLevel)) {
52
+ objectOfCurrentDepthLevel = valueOfCurrentDepthLevel;
50
53
  }
51
54
  else {
52
55
  return;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = setObjectProperties;
7
+ const splitString_1 = __importDefault(require("../Strings/splitString"));
8
+ const isNonNullObject_1 = __importDefault(require("../TypeGuards/Objects/isNonNullObject"));
9
+ const isUndefined_1 = __importDefault(require("../TypeGuards/EmptyTypes/isUndefined"));
10
+ const isStringifiedNonNegativeIntegerOfRegularNotation_1 = __importDefault(require("../Numbers/isStringifiedNonNegativeIntegerOfRegularNotation"));
11
+ function setObjectProperties(targetObject, order) {
12
+ for (const [fullyQualifiedName, propertyDescriptor] of Object.entries(order)) {
13
+ const targetPropertyPathSegments = (0, splitString_1.default)(fullyQualifiedName, ".");
14
+ let objectOfCurrentDepthLevel = targetObject;
15
+ for (let depthLevel__numerationFrom1 = 1; depthLevel__numerationFrom1 <= targetPropertyPathSegments.length; depthLevel__numerationFrom1++) {
16
+ const isLastDepthLevel = depthLevel__numerationFrom1 === targetPropertyPathSegments.length;
17
+ const propertyKeyForCurrentDepthLevel = targetPropertyPathSegments[depthLevel__numerationFrom1 - 1];
18
+ let valueOfNextDepthLevel = Reflect.get(objectOfCurrentDepthLevel, propertyKeyForCurrentDepthLevel);
19
+ if (isLastDepthLevel) {
20
+ if ((0, isNonNullObject_1.default)(objectOfCurrentDepthLevel)) {
21
+ Object.defineProperty(objectOfCurrentDepthLevel, propertyKeyForCurrentDepthLevel, {
22
+ value: propertyDescriptor.value,
23
+ enumerable: propertyDescriptor.enumerable ?? true,
24
+ configurable: propertyDescriptor.configurable ?? true,
25
+ writable: propertyDescriptor.writable ?? true
26
+ });
27
+ }
28
+ else {
29
+ return;
30
+ }
31
+ }
32
+ else if ((0, isNonNullObject_1.default)(valueOfNextDepthLevel)) {
33
+ objectOfCurrentDepthLevel = valueOfNextDepthLevel;
34
+ }
35
+ else if ((0, isUndefined_1.default)(valueOfNextDepthLevel) && propertyDescriptor.mustCreateParentsObjectsIfNotPresent === true) {
36
+ const propertyKeyForNextDepthLevel = targetPropertyPathSegments[depthLevel__numerationFrom1];
37
+ valueOfNextDepthLevel = (0, isStringifiedNonNegativeIntegerOfRegularNotation_1.default)(propertyKeyForNextDepthLevel) ? [] : {};
38
+ Object.defineProperty(objectOfCurrentDepthLevel, propertyKeyForCurrentDepthLevel, {
39
+ value: valueOfNextDepthLevel,
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true
43
+ });
44
+ objectOfCurrentDepthLevel = valueOfNextDepthLevel;
45
+ }
46
+ else {
47
+ return;
48
+ }
49
+ }
50
+ }
51
+ }