@outfoxx/sunday 2.0.0-beta.16 → 2.0.0-beta.17
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/build/util/nullify.js +11 -4
- package/build/util/nullify.js.map +1 -1
- package/package.json +1 -1
package/build/util/nullify.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
|
+
import { z } from 'zod';
|
|
14
15
|
import { Problem } from '../problem.js';
|
|
15
16
|
export async function nullifyNotFound(promise) {
|
|
16
17
|
return await nullifyProblem(promise, [404], []);
|
|
@@ -20,7 +21,8 @@ export async function nullifyProblem(promise, statuses, problemTypes) {
|
|
|
20
21
|
return await promise;
|
|
21
22
|
}
|
|
22
23
|
catch (error) {
|
|
23
|
-
if (error instanceof Problem &&
|
|
24
|
+
if (error instanceof Problem &&
|
|
25
|
+
matchesProblem(error, statuses, problemTypes)) {
|
|
24
26
|
return null;
|
|
25
27
|
}
|
|
26
28
|
throw error;
|
|
@@ -30,8 +32,13 @@ function matchesProblem(error, statuses, problemTypes) {
|
|
|
30
32
|
if (error.status !== undefined && statuses.includes(error.status)) {
|
|
31
33
|
return true;
|
|
32
34
|
}
|
|
33
|
-
return problemTypes.some((matcher) =>
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
return problemTypes.some((matcher) => {
|
|
36
|
+
if (typeof matcher === 'function')
|
|
37
|
+
return matcher(error);
|
|
38
|
+
// A thrown Problem is already decoded; codecs validate it in their output direction.
|
|
39
|
+
return matcher instanceof z.ZodCodec
|
|
40
|
+
? matcher.safeEncode(error).success
|
|
41
|
+
: matcher.safeParse(error).success;
|
|
42
|
+
});
|
|
36
43
|
}
|
|
37
44
|
//# sourceMappingURL=nullify.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nullify.js","sourceRoot":"","sources":["../../src/util/nullify.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,gDAAgD;AAChD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;
|
|
1
|
+
{"version":3,"file":"nullify.js","sourceRoot":"","sources":["../../src/util/nullify.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,gDAAgD;AAChD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAMxC,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,OAAmB;IAEnB,OAAO,MAAM,cAAc,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAAmB,EACnB,QAAkB,EAClB,YAA8B;IAE9B,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC;IACvB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IACE,KAAK,YAAY,OAAO;YACxB,cAAc,CAAC,KAAK,EAAE,QAAQ,EAAE,YAAY,CAAC,EAC7C,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CACrB,KAAc,EACd,QAAkB,EAClB,YAA8B;IAE9B,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,E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