@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.
@@ -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) if (index !== void 0) output = [];
37
- else output = {};
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;
@@ -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) if (index !== void 0) output = [];
37
- else output = {};
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;
@@ -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) if (firstElement === firstElement.next) firstElement = void 0;
16
- else {
17
- const newFirst = firstElement.next;
18
- const last = firstElement.previous;
19
- newFirst.previous = last;
20
- last.next = newFirst;
21
- firstElement = newFirst;
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 {
@@ -12,13 +12,15 @@ function createQueue(params) {
12
12
  const externalPromise = createExternalPromise();
13
13
  const preparedTask = () => {
14
14
  runningCount++;
15
- if (firstElement?.task === preparedTask) if (firstElement === firstElement.next) firstElement = void 0;
16
- else {
17
- const newFirst = firstElement.next;
18
- const last = firstElement.previous;
19
- newFirst.previous = last;
20
- last.next = newFirst;
21
- firstElement = newFirst;
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
- return callThen(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), (awaitedResult) => {
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
- return callThen(data.reduce((accumulator, value, index) => callThen(accumulator, (awaitedAccumulator) => pathStage?.setCurrentPath(`[array: ${index}]`) ?? callThen(self.definition.element.executeEncode(codecContext, value, errorHandler), (encodedData) => {
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
- })), []), (awaitedEncodedData) => pathStage?.close() ?? (awaitedEncodedData === ErrorSymbol ? ErrorSymbol : callThen(self.executeConstraints(data, errorHandler), (result) => result === ErrorSymbol ? ErrorSymbol : awaitedEncodedData)));
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
- return callThen(data.reduce((accumulator, value, index) => callThen(accumulator, (awaitedAccumulator) => pathStage?.setCurrentPath(`[array: ${index}]`) ?? callThen(self.definition.element.executeDecode(codecContext, value, errorHandler), (decodedData) => {
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
- })), []), (awaitedDecodedData) => pathStage?.close() ?? (awaitedDecodedData === ErrorSymbol ? ErrorSymbol : callThen(self.executeConstraints(awaitedDecodedData, errorHandler), (result) => result === ErrorSymbol ? ErrorSymbol : awaitedDecodedData)));
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
- return callThen(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), (awaitedResult) => {
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
- return callThen(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
+ 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
- })), {}), (awaitedEncodedData) => pathStage?.close() ?? (awaitedEncodedData === ErrorSymbol ? ErrorSymbol : callThen(self.executeConstraints(data, errorHandler), (result) => result === ErrorSymbol ? ErrorSymbol : awaitedEncodedData)));
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
- return callThen(self.definition.shape.value.reduce((accumulator, entry) => callThen(accumulator, (awaitedAccumulator) => pathStage?.setCurrentPath(entry.key) ?? callThen(entry.value.executeDecode(codecContext, data[entry.key], errorHandler), (decodedData) => {
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
- })), {}), (awaitedDecodedData) => pathStage?.close() ?? (awaitedDecodedData === ErrorSymbol ? ErrorSymbol : callThen(self.executeConstraints(awaitedDecodedData, errorHandler), (result) => result === ErrorSymbol ? ErrorSymbol : awaitedDecodedData)));
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
- return callThen((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), (awaitedResult) => {
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
- return callThen((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
+ 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
- }))), {}), (awaitedEncodedData) => pathStage?.close() ?? (awaitedEncodedData === ErrorSymbol ? ErrorSymbol : callThen(self.executeConstraints(data, errorHandler), (result) => result === ErrorSymbol ? ErrorSymbol : awaitedEncodedData)));
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
- return callThen((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) => {
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
- }))), {}), (awaitedDecodedData) => pathStage?.close() ?? (awaitedDecodedData === ErrorSymbol ? ErrorSymbol : callThen(self.executeConstraints(awaitedDecodedData, errorHandler), (result) => result === ErrorSymbol ? ErrorSymbol : awaitedDecodedData)));
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
- return callThen(self.definition.values.reduce((accumulator, value, index) => callThen(accumulator, (awaitedAccumulator) => {
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), (awaitedResult) => {
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
- return callThen(self.definition.values.reduce((accumulator, value, index) => callThen(accumulator, (awaitedAccumulator) => {
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), (awaitedEncodedData) => {
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
- return callThen(self.definition.values.reduce((accumulator, value, index) => callThen(accumulator, (awaitedAccumulator) => {
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), (awaitedDecodedData) => {
64
+ }), ErrorSymbol);
65
+ return callThen(decodedData, (awaitedDecodedData) => {
63
66
  if (awaitedDecodedData === ErrorSymbol) {
64
67
  if (errorHandlers) errorHandler?.().importIssues(errorHandlers);
65
68
  return ErrorSymbol;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duplojs/lang",
3
- "version": "0.0.0",
3
+ "version": "0.0.1-beta.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "author": {