@need-code/nc-ddd 0.4.0 → 0.5.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.
- package/dist/helpers/effect-map-optional.d.ts +3 -3
- package/dist/helpers/effect-map-optional.d.ts.map +1 -1
- package/dist/helpers/effect-map-optional.js +3 -3
- package/dist/helpers/effect-map-optional.js.map +1 -1
- package/dist/helpers/extract-effect-errors.d.ts +2 -1
- package/dist/helpers/extract-effect-errors.d.ts.map +1 -1
- package/dist/helpers/extract-effect-errors.js +28 -49
- package/dist/helpers/extract-effect-errors.js.map +1 -1
- package/dist/helpers/vo-effect-factory.d.ts +4 -4
- package/dist/helpers/vo-effect-factory.d.ts.map +1 -1
- package/dist/helpers/vo-effect-factory.js +17 -8
- package/dist/helpers/vo-effect-factory.js.map +1 -1
- package/dist/helpers/vo-factory.d.ts +1 -1
- package/dist/helpers/vo-factory.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type MapOptionalResult<V,
|
|
3
|
-
export declare function effectMapOptional<V,
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
type MapOptionalResult<V, E, A> = undefined extends V ? null extends V ? Effect.Effect<A | null | undefined, E> : Effect.Effect<A | undefined, E> : null extends V ? Effect.Effect<A | null, E> : Effect.Effect<A, E>;
|
|
3
|
+
export declare function effectMapOptional<V, E, A>(value: V, factory: (value: NonNullable<V>) => Effect.Effect<A, E>): MapOptionalResult<V, E, A>;
|
|
4
4
|
export {};
|
|
5
5
|
//# sourceMappingURL=effect-map-optional.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"effect-map-optional.d.ts","sourceRoot":"","sources":["../../src/helpers/effect-map-optional.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"effect-map-optional.d.ts","sourceRoot":"","sources":["../../src/helpers/effect-map-optional.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,KAAK,iBAAiB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,SAAS,SAAS,CAAC,GACjD,IAAI,SAAS,CAAC,GACZ,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,EAAE,CAAC,CAAC,GACtC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,CAAC,GACjC,IAAI,SAAS,CAAC,GACZ,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,GAC1B,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAE1B,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EACvC,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GACtD,iBAAiB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAQ5B"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Effect } from "effect";
|
|
2
2
|
export function effectMapOptional(value, factory) {
|
|
3
3
|
if (value === undefined) {
|
|
4
|
-
return
|
|
4
|
+
return Effect.succeed(undefined);
|
|
5
5
|
}
|
|
6
6
|
if (value === null) {
|
|
7
|
-
return
|
|
7
|
+
return Effect.succeed(null);
|
|
8
8
|
}
|
|
9
9
|
return factory(value);
|
|
10
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"effect-map-optional.js","sourceRoot":"","sources":["../../src/helpers/effect-map-optional.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"effect-map-optional.js","sourceRoot":"","sources":["../../src/helpers/effect-map-optional.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAUhC,MAAM,UAAU,iBAAiB,CAC/B,KAAQ,EACR,OAAuD;IAEvD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAA0C,CAAC;IAC5E,CAAC;IACD,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO,MAAM,CAAC,OAAO,CAAC,IAAI,CAA0C,CAAC;IACvE,CAAC;IACD,OAAO,OAAO,CAAC,KAAuB,CAA0C,CAAC;AACnF,CAAC"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import type { FieldErrors } from "./vo-effect-factory";
|
|
2
|
+
export declare function extractEffectErrors(cause: unknown): FieldErrors;
|
|
2
3
|
//# sourceMappingURL=extract-effect-errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract-effect-errors.d.ts","sourceRoot":"","sources":["../../src/helpers/extract-effect-errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"extract-effect-errors.d.ts","sourceRoot":"","sources":["../../src/helpers/extract-effect-errors.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AA4BvD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAU/D"}
|
|
@@ -1,56 +1,35 @@
|
|
|
1
1
|
import { Option } from "effect";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
function mergeInto(result, value) {
|
|
3
|
+
// FieldErrors — плоский объект с массивами строк
|
|
4
|
+
// { "contacts.1.value": ["Invalid email"] }
|
|
5
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
6
|
+
for (const [path, messages] of Object.entries(value)) {
|
|
7
|
+
if (!Array.isArray(messages))
|
|
8
|
+
continue;
|
|
9
|
+
result[path] = result[path]
|
|
10
|
+
? [...result[path], ...messages]
|
|
11
|
+
: messages;
|
|
12
|
+
}
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
// Массив Option-ов — вложенный Effect.all
|
|
16
|
+
if (Array.isArray(value)) {
|
|
17
|
+
for (const item of value) {
|
|
18
|
+
unwrapOption(result, item);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
5
21
|
}
|
|
6
|
-
function
|
|
7
|
-
|
|
22
|
+
function unwrapOption(result, raw) {
|
|
23
|
+
if (!Option.isOption(raw) || Option.isNone(raw))
|
|
24
|
+
return;
|
|
25
|
+
mergeInto(result, raw.value);
|
|
8
26
|
}
|
|
9
|
-
|
|
10
|
-
export function extractEffectErrors(input) {
|
|
27
|
+
export function extractEffectErrors(cause) {
|
|
11
28
|
const result = {};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (Option.isNone(raw))
|
|
17
|
-
continue;
|
|
18
|
-
const value = raw.value;
|
|
19
|
-
if (!value)
|
|
20
|
-
continue;
|
|
21
|
-
// Простой массив строк: { name: Some(["Name can't be empty"]) }
|
|
22
|
-
if (isStringArray(value)) {
|
|
23
|
-
result[key] = value;
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
// Массив Option-ов: { contacts: Some([Some({ "contacts.0": { value: [...] } })]) }
|
|
27
|
-
if (isOptionArray(value)) {
|
|
28
|
-
for (const item of value) {
|
|
29
|
-
if (Option.isNone(item))
|
|
30
|
-
continue;
|
|
31
|
-
const inner = item.value;
|
|
32
|
-
if (typeof inner === "object" && inner !== null) {
|
|
33
|
-
for (const [nestedKey, nestedVal] of Object.entries(inner)) {
|
|
34
|
-
if (typeof nestedVal === "object" && nestedVal !== null) {
|
|
35
|
-
for (const [fieldKey, fieldVal] of Object.entries(nestedVal)) {
|
|
36
|
-
if (isStringArray(fieldVal)) {
|
|
37
|
-
// "contacts.0" + "." + "value" = "contacts.0.value"
|
|
38
|
-
result[`${nestedKey}.${fieldKey}`] = fieldVal;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
// Вложенный объект: рекурсия
|
|
48
|
-
if (typeof value === "object") {
|
|
49
|
-
const nested = extractEffectErrors(value);
|
|
50
|
-
for (const [nestedKey, val] of Object.entries(nested)) {
|
|
51
|
-
result[`${key}.${nestedKey}`] = val;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
29
|
+
if (typeof cause !== "object" || cause === null)
|
|
30
|
+
return result;
|
|
31
|
+
for (const raw of Object.values(cause)) {
|
|
32
|
+
unwrapOption(result, raw);
|
|
54
33
|
}
|
|
55
34
|
return result;
|
|
56
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract-effect-errors.js","sourceRoot":"","sources":["../../src/helpers/extract-effect-errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"extract-effect-errors.js","sourceRoot":"","sources":["../../src/helpers/extract-effect-errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,SAAS,SAAS,CAAC,MAAmB,EAAE,KAAc;IACpD,iDAAiD;IACjD,4CAA4C;IAC5C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzE,KAAK,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACrD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;gBAAE,SAAS;YACvC,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC;gBACzB,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,GAAI,QAAqB,CAAC;gBAC9C,CAAC,CAAE,QAAqB,CAAC;QAC7B,CAAC;QACD,OAAO;IACT,CAAC;IAED,0CAA0C;IAC1C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAS,YAAY,CAAC,MAAmB,EAAE,GAAY;IACrD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC;QAAE,OAAO;IACxD,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,KAAc;IAChD,MAAM,MAAM,GAAgB,EAAE,CAAC;IAE/B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAE/D,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACvC,YAAY,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
1
2
|
import * as v from "valibot";
|
|
2
|
-
import type { VO } from "
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
} | undefined> | import("effect/Either").Either<VO<S>, never>;
|
|
3
|
+
import type { VO } from "../core/vo.js";
|
|
4
|
+
export type FieldErrors = Record<string, string[]>;
|
|
5
|
+
export declare function voEffectFactory<S extends v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>>(value: unknown, schema: S, constructorFn: (props: v.InferOutput<S>) => VO<S>, key: string): Effect.Effect<VO<S>, FieldErrors>;
|
|
6
6
|
//# sourceMappingURL=vo-effect-factory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vo-effect-factory.d.ts","sourceRoot":"","sources":["../../src/helpers/vo-effect-factory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"vo-effect-factory.d.ts","sourceRoot":"","sources":["../../src/helpers/vo-effect-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAC7B,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AAExC,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;AAEnD,wBAAgB,eAAe,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,EAC5F,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,CAAC,EACT,aAAa,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EACjD,GAAG,EAAE,MAAM,GACV,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CA2BnC"}
|
|
@@ -1,16 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Effect } from "effect";
|
|
2
2
|
import * as v from "valibot";
|
|
3
3
|
export function voEffectFactory(value, schema, constructorFn, key) {
|
|
4
4
|
const parseResult = v.safeParse(schema, value);
|
|
5
5
|
if (!parseResult.success) {
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
const flat = v.flatten(parseResult.issues);
|
|
7
|
+
const errors = {};
|
|
8
|
+
const root = flat.root;
|
|
9
|
+
const nested = flat.nested;
|
|
10
|
+
if (root?.length) {
|
|
11
|
+
errors[key] = root;
|
|
12
|
+
}
|
|
13
|
+
if (nested) {
|
|
14
|
+
for (const [nestedPath, messages] of Object.entries(nested)) {
|
|
15
|
+
const msgs = messages;
|
|
16
|
+
if (msgs?.length) {
|
|
17
|
+
errors[`${key}.${nestedPath}`] = msgs;
|
|
18
|
+
}
|
|
11
19
|
}
|
|
12
|
-
|
|
20
|
+
}
|
|
21
|
+
return Effect.fail(errors);
|
|
13
22
|
}
|
|
14
|
-
return
|
|
23
|
+
return Effect.succeed(constructorFn(parseResult.output));
|
|
15
24
|
}
|
|
16
25
|
//# sourceMappingURL=vo-effect-factory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vo-effect-factory.js","sourceRoot":"","sources":["../../src/helpers/vo-effect-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"vo-effect-factory.js","sourceRoot":"","sources":["../../src/helpers/vo-effect-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAK7B,MAAM,UAAU,eAAe,CAC7B,KAAc,EACd,MAAS,EACT,aAAiD,EACjD,GAAW;IAEX,MAAM,WAAW,GAAG,CAAC,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAE/C,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;QACzB,MAAM,IAAI,GAAG,CAAC,CAAC,OAAO,CAAgB,WAAW,CAAC,MAAM,CAAC,CAAC;QAC1D,MAAM,MAAM,GAAgB,EAAE,CAAC;QAE/B,MAAM,IAAI,GAAG,IAAI,CAAC,IAA4B,CAAC;QAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,MAA8C,CAAC;QAEnE,IAAI,IAAI,EAAE,MAAM,EAAE,CAAC;YACjB,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;QACrB,CAAC;QAED,IAAI,MAAM,EAAE,CAAC;YACX,KAAK,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC5D,MAAM,IAAI,GAAG,QAAgC,CAAC;gBAC9C,IAAI,IAAI,EAAE,MAAM,EAAE,CAAC;oBACjB,MAAM,CAAC,GAAG,GAAG,IAAI,UAAU,EAAE,CAAC,GAAG,IAAI,CAAC;gBACxC,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
|
-
import type { VO } from "
|
|
2
|
+
import type { VO } from "../core/vo.js";
|
|
3
3
|
export declare function voFactory<S extends v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>>(value: unknown, schema: S, constructorFn: (props: v.InferOutput<S>) => VO<S>, key?: string): import("@sweet-monads/either").Either<[string, ...string[]] | {
|
|
4
4
|
[key]: [string, ...string[]] | (Readonly<Partial<Record<S extends v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>> ? v.IssueDotPath<S> : string, [string, ...string[]]>>> extends infer T ? { [TKey in keyof T]: T[TKey]; } : never) | undefined;
|
|
5
5
|
} | undefined, never> | import("@sweet-monads/either").Either<never, VO<S>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vo-factory.d.ts","sourceRoot":"","sources":["../../src/helpers/vo-factory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAC7B,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"vo-factory.d.ts","sourceRoot":"","sources":["../../src/helpers/vo-factory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAC7B,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AAExC,wBAAgB,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,EACtF,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,CAAC,EACT,aAAa,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EACjD,GAAG,CAAC,EAAE,MAAM;IASF,CAAC,GAAG,CAAC,4SAAW;4EAM3B"}
|