@duplojs/lang 0.0.0 → 0.0.1-beta.1
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/dist/common/formData.cjs +4 -2
- package/dist/common/formData.mjs +4 -2
- package/dist/common/queue.cjs +9 -7
- package/dist/common/queue.mjs +9 -7
- package/dist/dataStructure/structure/defaults/array.mjs +8 -5
- package/dist/dataStructure/structure/defaults/object.mjs +8 -5
- package/dist/dataStructure/structure/defaults/record.mjs +8 -5
- package/dist/dataStructure/structure/defaults/union.mjs +9 -6
- package/package.json +1 -1
package/dist/common/formData.cjs
CHANGED
|
@@ -33,8 +33,10 @@ var TheFormData = class TheFormData extends FormData {
|
|
|
33
33
|
const index = firstElement.match(getIndexRegex)?.[1];
|
|
34
34
|
if (index && Number(index) > arrayMaxIndex) return input;
|
|
35
35
|
let output = input;
|
|
36
|
-
if (output === void 0)
|
|
37
|
-
|
|
36
|
+
if (output === void 0) {
|
|
37
|
+
if (index !== void 0) output = [];
|
|
38
|
+
else output = {};
|
|
39
|
+
}
|
|
38
40
|
if (firstElement === path) {
|
|
39
41
|
output[index ?? firstElement] = value;
|
|
40
42
|
return output;
|
package/dist/common/formData.mjs
CHANGED
|
@@ -33,8 +33,10 @@ var TheFormData = class TheFormData extends FormData {
|
|
|
33
33
|
const index = firstElement.match(getIndexRegex)?.[1];
|
|
34
34
|
if (index && Number(index) > arrayMaxIndex) return input;
|
|
35
35
|
let output = input;
|
|
36
|
-
if (output === void 0)
|
|
37
|
-
|
|
36
|
+
if (output === void 0) {
|
|
37
|
+
if (index !== void 0) output = [];
|
|
38
|
+
else output = {};
|
|
39
|
+
}
|
|
38
40
|
if (firstElement === path) {
|
|
39
41
|
output[index ?? firstElement] = value;
|
|
40
42
|
return output;
|
package/dist/common/queue.cjs
CHANGED
|
@@ -12,13 +12,15 @@ function createQueue(params) {
|
|
|
12
12
|
const externalPromise = require_externalPromise.createExternalPromise();
|
|
13
13
|
const preparedTask = () => {
|
|
14
14
|
runningCount++;
|
|
15
|
-
if (firstElement?.task === preparedTask)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
if (firstElement?.task === preparedTask) {
|
|
16
|
+
if (firstElement === firstElement.next) firstElement = void 0;
|
|
17
|
+
else {
|
|
18
|
+
const newFirst = firstElement.next;
|
|
19
|
+
const last = firstElement.previous;
|
|
20
|
+
newFirst.previous = last;
|
|
21
|
+
last.next = newFirst;
|
|
22
|
+
firstElement = newFirst;
|
|
23
|
+
}
|
|
22
24
|
}
|
|
23
25
|
let taskResult = void 0;
|
|
24
26
|
try {
|
package/dist/common/queue.mjs
CHANGED
|
@@ -12,13 +12,15 @@ function createQueue(params) {
|
|
|
12
12
|
const externalPromise = createExternalPromise();
|
|
13
13
|
const preparedTask = () => {
|
|
14
14
|
runningCount++;
|
|
15
|
-
if (firstElement?.task === preparedTask)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
if (firstElement?.task === preparedTask) {
|
|
16
|
+
if (firstElement === firstElement.next) firstElement = void 0;
|
|
17
|
+
else {
|
|
18
|
+
const newFirst = firstElement.next;
|
|
19
|
+
const last = firstElement.previous;
|
|
20
|
+
newFirst.previous = last;
|
|
21
|
+
last.next = newFirst;
|
|
22
|
+
firstElement = newFirst;
|
|
23
|
+
}
|
|
22
24
|
}
|
|
23
25
|
let taskResult = void 0;
|
|
24
26
|
try {
|
|
@@ -11,7 +11,8 @@ const ArrayStructure = createStructure(arrayStructureKind, ({ init }) => (elemen
|
|
|
11
11
|
executeCheck: (self, data, errorHandler) => {
|
|
12
12
|
if (!Array.isArray(data)) return errorHandler?.().addIssue(self, data) ?? ErrorSymbol;
|
|
13
13
|
const pathStage = errorHandler?.().createPathStage();
|
|
14
|
-
|
|
14
|
+
const result = data.reduce((accumulator, value, index) => callThen(accumulator, (awaitedAccumulator) => pathStage?.setCurrentPath(`[array: ${index}]`) ?? callThen(self.definition.element.executeCheck(value, errorHandler), (result) => result === ErrorSymbol || awaitedAccumulator === ErrorSymbol ? ErrorSymbol : SuccessSymbol)), SuccessSymbol);
|
|
15
|
+
return callThen(result, (awaitedResult) => {
|
|
15
16
|
pathStage?.close();
|
|
16
17
|
return awaitedResult;
|
|
17
18
|
});
|
|
@@ -19,20 +20,22 @@ const ArrayStructure = createStructure(arrayStructureKind, ({ init }) => (elemen
|
|
|
19
20
|
executeEncode: (self, codecContext, data, errorHandler) => {
|
|
20
21
|
if (!Array.isArray(data)) return errorHandler?.().addIssue(self, data) ?? ErrorSymbol;
|
|
21
22
|
const pathStage = errorHandler?.().createPathStage();
|
|
22
|
-
|
|
23
|
+
const encodedData = data.reduce((accumulator, value, index) => callThen(accumulator, (awaitedAccumulator) => pathStage?.setCurrentPath(`[array: ${index}]`) ?? callThen(self.definition.element.executeEncode(codecContext, value, errorHandler), (encodedData) => {
|
|
23
24
|
if (encodedData === ErrorSymbol || awaitedAccumulator === ErrorSymbol) return ErrorSymbol;
|
|
24
25
|
awaitedAccumulator[index] = encodedData;
|
|
25
26
|
return awaitedAccumulator;
|
|
26
|
-
})), [])
|
|
27
|
+
})), []);
|
|
28
|
+
return callThen(encodedData, (awaitedEncodedData) => pathStage?.close() ?? (awaitedEncodedData === ErrorSymbol ? ErrorSymbol : callThen(self.executeConstraints(data, errorHandler), (result) => result === ErrorSymbol ? ErrorSymbol : awaitedEncodedData)));
|
|
27
29
|
},
|
|
28
30
|
executeDecode: (self, codecContext, data, errorHandler) => {
|
|
29
31
|
if (!Array.isArray(data)) return errorHandler?.().addIssue(self, data) ?? ErrorSymbol;
|
|
30
32
|
const pathStage = errorHandler?.().createPathStage();
|
|
31
|
-
|
|
33
|
+
const decodedData = data.reduce((accumulator, value, index) => callThen(accumulator, (awaitedAccumulator) => pathStage?.setCurrentPath(`[array: ${index}]`) ?? callThen(self.definition.element.executeDecode(codecContext, value, errorHandler), (decodedData) => {
|
|
32
34
|
if (decodedData === ErrorSymbol || awaitedAccumulator === ErrorSymbol) return ErrorSymbol;
|
|
33
35
|
awaitedAccumulator[index] = decodedData;
|
|
34
36
|
return awaitedAccumulator;
|
|
35
|
-
})), [])
|
|
37
|
+
})), []);
|
|
38
|
+
return callThen(decodedData, (awaitedDecodedData) => pathStage?.close() ?? (awaitedDecodedData === ErrorSymbol ? ErrorSymbol : callThen(self.executeConstraints(awaitedDecodedData, errorHandler), (result) => result === ErrorSymbol ? ErrorSymbol : awaitedDecodedData)));
|
|
36
39
|
},
|
|
37
40
|
isAsynchronous: (self) => self.definition.element.isAsynchronous()
|
|
38
41
|
}));
|
|
@@ -18,7 +18,8 @@ const ObjectStructure = createStructure(objectStructureKind, ({ init }) => (shap
|
|
|
18
18
|
if (!isSimple(data) || Object.getOwnPropertySymbols(data).length !== 0) return errorHandler?.().addIssue(self, data) ?? ErrorSymbol;
|
|
19
19
|
if (Object.keys(data).some((value) => !self.definition.keys.includes(value))) return errorHandler?.().addIssue(self, data) ?? ErrorSymbol;
|
|
20
20
|
const pathStage = errorHandler?.().createPathStage();
|
|
21
|
-
|
|
21
|
+
const result = self.definition.shape.value.reduce((accumulator, entry) => callThen(accumulator, (awaitedAccumulator) => pathStage?.setCurrentPath(entry.key) ?? callThen(entry.value.executeCheck(data[entry.key], errorHandler), (result) => result === ErrorSymbol || awaitedAccumulator === ErrorSymbol ? ErrorSymbol : SuccessSymbol)), SuccessSymbol);
|
|
22
|
+
return callThen(result, (awaitedResult) => {
|
|
22
23
|
pathStage?.close();
|
|
23
24
|
return awaitedResult;
|
|
24
25
|
});
|
|
@@ -27,21 +28,23 @@ const ObjectStructure = createStructure(objectStructureKind, ({ init }) => (shap
|
|
|
27
28
|
if (!isSimple(data) || Object.getOwnPropertySymbols(data).length !== 0) return errorHandler?.().addIssue(self, data) ?? ErrorSymbol;
|
|
28
29
|
if (Object.keys(data).some((value) => !self.definition.keys.includes(value))) return errorHandler?.().addIssue(self, data) ?? ErrorSymbol;
|
|
29
30
|
const pathStage = errorHandler?.().createPathStage();
|
|
30
|
-
|
|
31
|
+
const encodedData = self.definition.shape.value.reduce((accumulator, entry) => callThen(accumulator, (awaitedAccumulator) => pathStage?.setCurrentPath(entry.key) ?? callThen(entry.value.executeEncode(codecContext, data[entry.key], errorHandler), (encodedData) => {
|
|
31
32
|
if (encodedData === ErrorSymbol || awaitedAccumulator === ErrorSymbol) return ErrorSymbol;
|
|
32
33
|
awaitedAccumulator[entry.key] = encodedData;
|
|
33
34
|
return awaitedAccumulator;
|
|
34
|
-
})), {})
|
|
35
|
+
})), {});
|
|
36
|
+
return callThen(encodedData, (awaitedEncodedData) => pathStage?.close() ?? (awaitedEncodedData === ErrorSymbol ? ErrorSymbol : callThen(self.executeConstraints(data, errorHandler), (result) => result === ErrorSymbol ? ErrorSymbol : awaitedEncodedData)));
|
|
35
37
|
},
|
|
36
38
|
executeDecode: (self, codecContext, data, errorHandler) => {
|
|
37
39
|
if (!isSimple(data) || Object.getOwnPropertySymbols(data).length !== 0) return errorHandler?.().addIssue(self, data) ?? ErrorSymbol;
|
|
38
40
|
if (Object.keys(data).some((value) => !self.definition.keys.includes(value))) return errorHandler?.().addIssue(self, data) ?? ErrorSymbol;
|
|
39
41
|
const pathStage = errorHandler?.().createPathStage();
|
|
40
|
-
|
|
42
|
+
const decodedData = self.definition.shape.value.reduce((accumulator, entry) => callThen(accumulator, (awaitedAccumulator) => pathStage?.setCurrentPath(entry.key) ?? callThen(entry.value.executeDecode(codecContext, data[entry.key], errorHandler), (decodedData) => {
|
|
41
43
|
if (decodedData === ErrorSymbol || awaitedAccumulator === ErrorSymbol) return ErrorSymbol;
|
|
42
44
|
awaitedAccumulator[entry.key] = decodedData;
|
|
43
45
|
return awaitedAccumulator;
|
|
44
|
-
})), {})
|
|
46
|
+
})), {});
|
|
47
|
+
return callThen(decodedData, (awaitedDecodedData) => pathStage?.close() ?? (awaitedDecodedData === ErrorSymbol ? ErrorSymbol : callThen(self.executeConstraints(awaitedDecodedData, errorHandler), (result) => result === ErrorSymbol ? ErrorSymbol : awaitedDecodedData)));
|
|
45
48
|
},
|
|
46
49
|
isAsynchronous: (self) => self.definition.shape.value.some((entry) => entry.value.isAsynchronous())
|
|
47
50
|
}));
|
|
@@ -31,7 +31,8 @@ const RecordStructure = createStructure(recordStructureKind, ({ init }) => (key,
|
|
|
31
31
|
const requiredKeys = self.definition.requiredKeys;
|
|
32
32
|
if (requiredKeys && keyData.some((value) => !requiredKeys.includes(value))) return errorHandler?.().addIssue(self, data) ?? ErrorSymbol;
|
|
33
33
|
const pathStage = errorHandler?.().createPathStage();
|
|
34
|
-
|
|
34
|
+
const result = (requiredKeys ?? keyData).reduce((accumulator, key) => callThen(accumulator, (awaitedAccumulator) => pathStage?.setCurrentPath(`{record key: ${key}}`) ?? callThen(self.definition.key.executeCheck(key, errorHandler), (resultKey) => pathStage?.setCurrentPath(`{record value: ${key}}`) ?? callThen(self.definition.value.executeCheck(data[key], errorHandler), (resultValue) => resultValue === ErrorSymbol || resultKey === ErrorSymbol || awaitedAccumulator === ErrorSymbol ? ErrorSymbol : SuccessSymbol))), SuccessSymbol);
|
|
35
|
+
return callThen(result, (awaitedResult) => {
|
|
35
36
|
pathStage?.close();
|
|
36
37
|
return awaitedResult;
|
|
37
38
|
});
|
|
@@ -42,11 +43,12 @@ const RecordStructure = createStructure(recordStructureKind, ({ init }) => (key,
|
|
|
42
43
|
const requiredKeys = self.definition.requiredKeys;
|
|
43
44
|
if (requiredKeys && keyData.some((value) => !requiredKeys.includes(value))) return errorHandler?.().addIssue(self, data) ?? ErrorSymbol;
|
|
44
45
|
const pathStage = errorHandler?.().createPathStage();
|
|
45
|
-
|
|
46
|
+
const encodedData = (requiredKeys ?? keyData).reduce((accumulator, key) => callThen(accumulator, (awaitedAccumulator) => pathStage?.setCurrentPath(`{record key: ${key}}`) ?? callThen(self.definition.key.executeCheck(key, errorHandler), (keyResult) => pathStage?.setCurrentPath(`{record value: ${key}}`) ?? callThen(self.definition.value.executeEncode(codecContext, data[key], errorHandler), (encodedValue) => {
|
|
46
47
|
if (keyResult === ErrorSymbol || encodedValue === ErrorSymbol || awaitedAccumulator === ErrorSymbol) return ErrorSymbol;
|
|
47
48
|
awaitedAccumulator[key] = encodedValue;
|
|
48
49
|
return awaitedAccumulator;
|
|
49
|
-
}))), {})
|
|
50
|
+
}))), {});
|
|
51
|
+
return callThen(encodedData, (awaitedEncodedData) => pathStage?.close() ?? (awaitedEncodedData === ErrorSymbol ? ErrorSymbol : callThen(self.executeConstraints(data, errorHandler), (result) => result === ErrorSymbol ? ErrorSymbol : awaitedEncodedData)));
|
|
50
52
|
},
|
|
51
53
|
executeDecode: (self, codecContext, data, errorHandler) => {
|
|
52
54
|
if (typeof data !== "object" || data === null || data.constructor !== void 0 && data.constructor.name !== "Object" || Object.getOwnPropertySymbols(data).length !== 0) return errorHandler?.().addIssue(self, data) ?? ErrorSymbol;
|
|
@@ -54,11 +56,12 @@ const RecordStructure = createStructure(recordStructureKind, ({ init }) => (key,
|
|
|
54
56
|
const requiredKeys = self.definition.requiredKeys;
|
|
55
57
|
if (requiredKeys && keyData.some((value) => !requiredKeys.includes(value))) return errorHandler?.().addIssue(self, data) ?? ErrorSymbol;
|
|
56
58
|
const pathStage = errorHandler?.().createPathStage();
|
|
57
|
-
|
|
59
|
+
const decodedData = (requiredKeys ?? keyData).reduce((accumulator, key) => callThen(accumulator, (awaitedAccumulator) => pathStage?.setCurrentPath(`{record key: ${key}}`) ?? callThen(self.definition.key.executeCheck(key, errorHandler), (keyResult) => pathStage?.setCurrentPath(`{record value: ${key}}`) ?? callThen(self.definition.value.executeDecode(codecContext, data[key], errorHandler), (decodedValue) => {
|
|
58
60
|
if (keyResult === ErrorSymbol || decodedValue === ErrorSymbol || awaitedAccumulator === ErrorSymbol) return ErrorSymbol;
|
|
59
61
|
awaitedAccumulator[key] = decodedValue;
|
|
60
62
|
return awaitedAccumulator;
|
|
61
|
-
}))), {})
|
|
63
|
+
}))), {});
|
|
64
|
+
return callThen(decodedData, (awaitedDecodedData) => pathStage?.close() ?? (awaitedDecodedData === ErrorSymbol ? ErrorSymbol : callThen(self.executeConstraints(awaitedDecodedData, errorHandler), (result) => result === ErrorSymbol ? ErrorSymbol : awaitedDecodedData)));
|
|
62
65
|
},
|
|
63
66
|
isAsynchronous: (self) => self.definition.key.isAsynchronous() || self.definition.value.isAsynchronous()
|
|
64
67
|
}));
|
|
@@ -12,7 +12,7 @@ const UnionStructure = createStructure(unionStructureKind, ({ init }) => (values
|
|
|
12
12
|
}, {
|
|
13
13
|
executeCheck: (self, data, errorHandler) => {
|
|
14
14
|
const errorHandlers = errorHandler ? [] : void 0;
|
|
15
|
-
|
|
15
|
+
const result = self.definition.values.reduce((accumulator, value, index) => callThen(accumulator, (awaitedAccumulator) => {
|
|
16
16
|
if (awaitedAccumulator === SuccessSymbol) return awaitedAccumulator;
|
|
17
17
|
const subErrorHandler = errorHandler === void 0 ? void 0 : createGetErrorHandler();
|
|
18
18
|
if (errorHandler && errorHandlers && subErrorHandler) {
|
|
@@ -21,7 +21,8 @@ const UnionStructure = createStructure(unionStructureKind, ({ init }) => (values
|
|
|
21
21
|
errorHandlers.push(subErrorHandler);
|
|
22
22
|
}
|
|
23
23
|
return value.executeCheck(data, subErrorHandler);
|
|
24
|
-
}), ErrorSymbol)
|
|
24
|
+
}), ErrorSymbol);
|
|
25
|
+
return callThen(result, (awaitedResult) => {
|
|
25
26
|
if (awaitedResult === ErrorSymbol) {
|
|
26
27
|
if (errorHandlers) errorHandler?.().importIssues(errorHandlers);
|
|
27
28
|
return ErrorSymbol;
|
|
@@ -31,7 +32,7 @@ const UnionStructure = createStructure(unionStructureKind, ({ init }) => (values
|
|
|
31
32
|
},
|
|
32
33
|
executeEncode: (self, codec, data, errorHandler) => {
|
|
33
34
|
const errorHandlers = errorHandler ? [] : void 0;
|
|
34
|
-
|
|
35
|
+
const encodedData = self.definition.values.reduce((accumulator, value, index) => callThen(accumulator, (awaitedAccumulator) => {
|
|
35
36
|
if (awaitedAccumulator !== ErrorSymbol) return awaitedAccumulator;
|
|
36
37
|
const subErrorHandler = errorHandler === void 0 ? void 0 : createGetErrorHandler();
|
|
37
38
|
if (errorHandler && errorHandlers && subErrorHandler) {
|
|
@@ -40,7 +41,8 @@ const UnionStructure = createStructure(unionStructureKind, ({ init }) => (values
|
|
|
40
41
|
errorHandlers.push(subErrorHandler);
|
|
41
42
|
}
|
|
42
43
|
return value.executeEncode(codec, data, subErrorHandler);
|
|
43
|
-
}), ErrorSymbol)
|
|
44
|
+
}), ErrorSymbol);
|
|
45
|
+
return callThen(encodedData, (awaitedEncodedData) => {
|
|
44
46
|
if (awaitedEncodedData === ErrorSymbol) {
|
|
45
47
|
if (errorHandlers) errorHandler?.().importIssues(errorHandlers);
|
|
46
48
|
return ErrorSymbol;
|
|
@@ -50,7 +52,7 @@ const UnionStructure = createStructure(unionStructureKind, ({ init }) => (values
|
|
|
50
52
|
},
|
|
51
53
|
executeDecode: (self, codec, data, errorHandler) => {
|
|
52
54
|
const errorHandlers = errorHandler ? [] : void 0;
|
|
53
|
-
|
|
55
|
+
const decodedData = self.definition.values.reduce((accumulator, value, index) => callThen(accumulator, (awaitedAccumulator) => {
|
|
54
56
|
if (awaitedAccumulator !== ErrorSymbol) return awaitedAccumulator;
|
|
55
57
|
const subErrorHandler = errorHandler === void 0 ? void 0 : createGetErrorHandler();
|
|
56
58
|
if (errorHandler && errorHandlers && subErrorHandler) {
|
|
@@ -59,7 +61,8 @@ const UnionStructure = createStructure(unionStructureKind, ({ init }) => (values
|
|
|
59
61
|
errorHandlers.push(subErrorHandler);
|
|
60
62
|
}
|
|
61
63
|
return value.executeDecode(codec, data, subErrorHandler);
|
|
62
|
-
}), ErrorSymbol)
|
|
64
|
+
}), ErrorSymbol);
|
|
65
|
+
return callThen(decodedData, (awaitedDecodedData) => {
|
|
63
66
|
if (awaitedDecodedData === ErrorSymbol) {
|
|
64
67
|
if (errorHandlers) errorHandler?.().importIssues(errorHandlers);
|
|
65
68
|
return ErrorSymbol;
|