@duplojs/data-parser-tools 0.2.3 → 0.2.4
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/toJsonSchema/override.cjs +5 -4
- package/dist/toJsonSchema/override.mjs +5 -4
- package/dist/toJsonSchema/transformer/create.d.ts +3 -3
- package/dist/toJsonSchema/transformer/defaults/literal.cjs +59 -23
- package/dist/toJsonSchema/transformer/defaults/literal.d.ts +12 -4
- package/dist/toJsonSchema/transformer/defaults/literal.mjs +60 -24
- package/dist/toJsonSchema/transformer/defaults/nullable.cjs +11 -2
- package/dist/toJsonSchema/transformer/defaults/nullable.mjs +11 -2
- package/dist/toJsonSchema/transformer/defaults/object.cjs +1 -1
- package/dist/toJsonSchema/transformer/defaults/object.mjs +1 -1
- package/dist/toJsonSchema/transformer/defaults/optional.cjs +10 -1
- package/dist/toJsonSchema/transformer/defaults/optional.mjs +10 -1
- package/dist/toJsonSchema/transformer/defaults/union.cjs +3 -3
- package/dist/toJsonSchema/transformer/defaults/union.mjs +3 -3
- package/dist/toJsonSchema/transformer/transformer.cjs +7 -7
- package/dist/toJsonSchema/transformer/transformer.d.ts +1 -1
- package/dist/toJsonSchema/transformer/transformer.mjs +7 -7
- package/dist/toTypescript/index.cjs +2 -0
- package/dist/toTypescript/index.mjs +1 -0
- package/dist/toTypescript/override.cjs +5 -7
- package/dist/toTypescript/override.mjs +5 -7
- package/dist/toTypescript/transformer/defaults/nullable.cjs +11 -2
- package/dist/toTypescript/transformer/defaults/nullable.mjs +11 -2
- package/dist/toTypescript/transformer/defaults/object.cjs +2 -10
- package/dist/toTypescript/transformer/defaults/object.mjs +2 -10
- package/dist/toTypescript/transformer/defaults/optional.cjs +11 -2
- package/dist/toTypescript/transformer/defaults/optional.mjs +11 -2
- package/dist/toTypescript/transformer/defaults/record.cjs +2 -1
- package/dist/toTypescript/transformer/defaults/record.mjs +3 -2
- package/dist/toTypescript/transformer/includesUndefinedTypeNode.cjs +16 -0
- package/dist/toTypescript/transformer/includesUndefinedTypeNode.d.ts +2 -0
- package/dist/toTypescript/transformer/includesUndefinedTypeNode.mjs +14 -0
- package/dist/toTypescript/transformer/index.cjs +2 -0
- package/dist/toTypescript/transformer/index.d.ts +1 -0
- package/dist/toTypescript/transformer/index.mjs +1 -0
- package/package.json +2 -2
|
@@ -6,7 +6,8 @@ dataParser.dataParserInit.overrideHandler.setMethod("setIdentifier", (schema, id
|
|
|
6
6
|
schema.definition.identifier = identifier;
|
|
7
7
|
return schema;
|
|
8
8
|
});
|
|
9
|
-
dataParser.dataParserInit.overrideHandler.setMethod("addIdentifier", (schema, identifier) =>
|
|
10
|
-
|
|
11
|
-
identifier
|
|
12
|
-
|
|
9
|
+
dataParser.dataParserInit.overrideHandler.setMethod("addIdentifier", (schema, identifier) => {
|
|
10
|
+
const newSchema = schema.clone();
|
|
11
|
+
newSchema.setIdentifier(identifier);
|
|
12
|
+
return newSchema;
|
|
13
|
+
});
|
|
@@ -4,7 +4,8 @@ dataParserInit.overrideHandler.setMethod("setIdentifier", (schema, identifier) =
|
|
|
4
4
|
schema.definition.identifier = identifier;
|
|
5
5
|
return schema;
|
|
6
6
|
});
|
|
7
|
-
dataParserInit.overrideHandler.setMethod("addIdentifier", (schema, identifier) =>
|
|
8
|
-
|
|
9
|
-
identifier
|
|
10
|
-
|
|
7
|
+
dataParserInit.overrideHandler.setMethod("addIdentifier", (schema, identifier) => {
|
|
8
|
+
const newSchema = schema.clone();
|
|
9
|
+
newSchema.setIdentifier(identifier);
|
|
10
|
+
return newSchema;
|
|
11
|
+
});
|
|
@@ -9,7 +9,7 @@ export interface JsonSchemaAnyOf {
|
|
|
9
9
|
export type JsonSchema = JsonSchemaRef | JsonSchemaAnyOf | JsonSchemaArray | JsonSchemaBigInt | JsonSchemaBoolean | JsonSchemaDate | JsonSchemaEmpty | JsonSchemaLiteral | JsonSchemaNil | JsonSchemaNullableAnyOf | JsonSchemaNumber | JsonSchemaObject | JsonSchemaRecord | JsonSchemaString | JsonSchemaTemplateLiteral | JsonSchemaTuple | JsonSchemaUnion | JsonSchemaUnknown | JsonSchemaTime;
|
|
10
10
|
export interface TransformerSuccess {
|
|
11
11
|
readonly schema: JsonSchema;
|
|
12
|
-
readonly
|
|
12
|
+
readonly isOptional: boolean;
|
|
13
13
|
}
|
|
14
14
|
export type TransformerSuccessEither = E.EitherRight<"buildSuccess", TransformerSuccess>;
|
|
15
15
|
export type DataParserNotSupportedEither = E.EitherLeft<"dataParserNotSupport", DP.DataParser>;
|
|
@@ -17,7 +17,7 @@ export type DataParserErrorEither = E.EitherLeft<"buildDataParserError", DP.Data
|
|
|
17
17
|
export interface MapContextValue {
|
|
18
18
|
readonly name: string;
|
|
19
19
|
readonly schema?: JsonSchema;
|
|
20
|
-
readonly
|
|
20
|
+
readonly isOptional: boolean;
|
|
21
21
|
}
|
|
22
22
|
export type MapContext = Map<DP.DataParsers, MapContextValue>;
|
|
23
23
|
export type MaybeTransformerEither = TransformerSuccessEither | DataParserNotSupportedEither | DataParserErrorEither;
|
|
@@ -36,7 +36,7 @@ export interface TransformerParams {
|
|
|
36
36
|
readonly context: MapContext;
|
|
37
37
|
readonly version: SupportedVersionsUrl;
|
|
38
38
|
transformer(schema: DP.DataParser): MaybeTransformerEither;
|
|
39
|
-
success(result: JsonSchema,
|
|
39
|
+
success(result: JsonSchema, isOptional?: boolean): TransformerSuccessEither;
|
|
40
40
|
buildError(): DataParserErrorEither;
|
|
41
41
|
}
|
|
42
42
|
export declare function createTransformer<GenericDataParser extends DP.DataParsers>(support: (schema: DP.DataParsers) => schema is GenericDataParser, builder: (schema: GenericDataParser, params: TransformerParams) => MaybeTransformerEither): (schema: DP.DataParsers, params: TransformerParams) => MaybeTransformerEither;
|
|
@@ -3,45 +3,81 @@
|
|
|
3
3
|
var utils = require('@duplojs/utils');
|
|
4
4
|
var create = require('../create.cjs');
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
function isOldVersion(version) {
|
|
7
|
+
return (version === "http://json-schema.org/draft-04/schema#"
|
|
8
|
+
|| version === "https://spec.openapis.org/oas/3.0.3");
|
|
9
|
+
}
|
|
10
|
+
const literalTransformer = create.createTransformer(utils.DP.literalKind.has, (schema, { success, version, }) => {
|
|
7
11
|
const reduced = utils.A.reduce(schema.definition.value, utils.A.reduceFrom({
|
|
8
12
|
literals: [],
|
|
9
|
-
|
|
13
|
+
isOptional: false,
|
|
10
14
|
}), ({ element, lastValue, next, nextWithObject, }) => utils.P.match(element)
|
|
11
|
-
.when(utils.isType("undefined"), () => nextWithObject(lastValue, {
|
|
15
|
+
.when(utils.isType("undefined"), () => nextWithObject(lastValue, { isOptional: true }))
|
|
12
16
|
.when(utils.isType("bigint"), (value) => nextWithObject(lastValue, {
|
|
13
|
-
literals: utils.A.push(lastValue.literals,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
literals: utils.A.push(lastValue.literals, isOldVersion(version)
|
|
18
|
+
? {
|
|
19
|
+
enum: [value.toString()],
|
|
20
|
+
type: "string",
|
|
21
|
+
}
|
|
22
|
+
: {
|
|
23
|
+
const: value.toString(),
|
|
24
|
+
type: "string",
|
|
25
|
+
}),
|
|
17
26
|
}))
|
|
18
27
|
.when(utils.isType("string"), (value) => nextWithObject(lastValue, {
|
|
19
|
-
literals: utils.A.push(lastValue.literals,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
28
|
+
literals: utils.A.push(lastValue.literals, isOldVersion(version)
|
|
29
|
+
? {
|
|
30
|
+
enum: [value],
|
|
31
|
+
type: "string",
|
|
32
|
+
}
|
|
33
|
+
: {
|
|
34
|
+
const: value,
|
|
35
|
+
type: "string",
|
|
36
|
+
}),
|
|
23
37
|
}))
|
|
24
38
|
.when(utils.isType("number"), (value) => nextWithObject(lastValue, {
|
|
25
|
-
literals: utils.A.push(lastValue.literals,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
39
|
+
literals: utils.A.push(lastValue.literals, isOldVersion(version)
|
|
40
|
+
? {
|
|
41
|
+
enum: [value],
|
|
42
|
+
type: Number.isInteger(value)
|
|
43
|
+
? "integer"
|
|
44
|
+
: "number",
|
|
45
|
+
}
|
|
46
|
+
: {
|
|
47
|
+
const: value,
|
|
48
|
+
type: Number.isInteger(value)
|
|
49
|
+
? "integer"
|
|
50
|
+
: "number",
|
|
51
|
+
}),
|
|
29
52
|
}))
|
|
30
53
|
.when(utils.isType("boolean"), (value) => nextWithObject(lastValue, {
|
|
31
|
-
literals: utils.A.push(lastValue.literals,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
54
|
+
literals: utils.A.push(lastValue.literals, isOldVersion(version)
|
|
55
|
+
? {
|
|
56
|
+
enum: [value],
|
|
57
|
+
type: "boolean",
|
|
58
|
+
}
|
|
59
|
+
: {
|
|
60
|
+
const: value,
|
|
61
|
+
type: "boolean",
|
|
62
|
+
}),
|
|
35
63
|
}))
|
|
36
64
|
.when(utils.isType("null"), () => nextWithObject(lastValue, {
|
|
37
|
-
literals: utils.A.push(lastValue.literals,
|
|
38
|
-
|
|
65
|
+
literals: utils.A.push(lastValue.literals, utils.P.match(version)
|
|
66
|
+
.with("https://spec.openapis.org/oas/3.0.3", utils.justReturn({
|
|
67
|
+
enum: [null],
|
|
68
|
+
}))
|
|
69
|
+
.with("http://json-schema.org/draft-04/schema#", utils.justReturn({
|
|
70
|
+
type: "null",
|
|
71
|
+
enum: [null],
|
|
72
|
+
}))
|
|
73
|
+
.otherwise(utils.justReturn({
|
|
39
74
|
type: "null",
|
|
40
|
-
|
|
75
|
+
const: null,
|
|
76
|
+
}))),
|
|
41
77
|
}))
|
|
42
78
|
.otherwise(() => next(lastValue)));
|
|
43
79
|
const schemaDefinition = utils.pipe(reduced.literals, utils.P.when(utils.A.lengthEqual(0), () => ({})), utils.P.when(utils.A.lengthEqual(1), utils.A.first), utils.P.otherwise((value) => ({ anyOf: value })));
|
|
44
|
-
return success(schemaDefinition, reduced.
|
|
80
|
+
return success(schemaDefinition, reduced.isOptional);
|
|
45
81
|
});
|
|
46
82
|
|
|
47
83
|
exports.literalTransformer = literalTransformer;
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { DP } from "@duplojs/utils";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
type JsonPrimitive = string | number | boolean | null;
|
|
3
|
+
type JsonType = "string" | "number" | "integer" | "boolean" | "null";
|
|
4
|
+
export type JsonSchemaLiteral = {
|
|
5
|
+
const: JsonPrimitive;
|
|
6
|
+
type: JsonType;
|
|
7
|
+
} | {
|
|
8
|
+
enum: readonly [JsonPrimitive];
|
|
9
|
+
type: JsonType;
|
|
10
|
+
} | {
|
|
11
|
+
enum: readonly [null];
|
|
12
|
+
};
|
|
6
13
|
export declare const literalTransformer: (schema: DP.DataParsers, params: import("..").TransformerParams) => import("..").MaybeTransformerEither;
|
|
14
|
+
export {};
|
|
@@ -1,45 +1,81 @@
|
|
|
1
|
-
import { DP, A, P, isType, pipe } from '@duplojs/utils';
|
|
1
|
+
import { DP, A, P, isType, justReturn, pipe } from '@duplojs/utils';
|
|
2
2
|
import { createTransformer } from '../create.mjs';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
function isOldVersion(version) {
|
|
5
|
+
return (version === "http://json-schema.org/draft-04/schema#"
|
|
6
|
+
|| version === "https://spec.openapis.org/oas/3.0.3");
|
|
7
|
+
}
|
|
8
|
+
const literalTransformer = createTransformer(DP.literalKind.has, (schema, { success, version, }) => {
|
|
5
9
|
const reduced = A.reduce(schema.definition.value, A.reduceFrom({
|
|
6
10
|
literals: [],
|
|
7
|
-
|
|
11
|
+
isOptional: false,
|
|
8
12
|
}), ({ element, lastValue, next, nextWithObject, }) => P.match(element)
|
|
9
|
-
.when(isType("undefined"), () => nextWithObject(lastValue, {
|
|
13
|
+
.when(isType("undefined"), () => nextWithObject(lastValue, { isOptional: true }))
|
|
10
14
|
.when(isType("bigint"), (value) => nextWithObject(lastValue, {
|
|
11
|
-
literals: A.push(lastValue.literals,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
literals: A.push(lastValue.literals, isOldVersion(version)
|
|
16
|
+
? {
|
|
17
|
+
enum: [value.toString()],
|
|
18
|
+
type: "string",
|
|
19
|
+
}
|
|
20
|
+
: {
|
|
21
|
+
const: value.toString(),
|
|
22
|
+
type: "string",
|
|
23
|
+
}),
|
|
15
24
|
}))
|
|
16
25
|
.when(isType("string"), (value) => nextWithObject(lastValue, {
|
|
17
|
-
literals: A.push(lastValue.literals,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
26
|
+
literals: A.push(lastValue.literals, isOldVersion(version)
|
|
27
|
+
? {
|
|
28
|
+
enum: [value],
|
|
29
|
+
type: "string",
|
|
30
|
+
}
|
|
31
|
+
: {
|
|
32
|
+
const: value,
|
|
33
|
+
type: "string",
|
|
34
|
+
}),
|
|
21
35
|
}))
|
|
22
36
|
.when(isType("number"), (value) => nextWithObject(lastValue, {
|
|
23
|
-
literals: A.push(lastValue.literals,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
37
|
+
literals: A.push(lastValue.literals, isOldVersion(version)
|
|
38
|
+
? {
|
|
39
|
+
enum: [value],
|
|
40
|
+
type: Number.isInteger(value)
|
|
41
|
+
? "integer"
|
|
42
|
+
: "number",
|
|
43
|
+
}
|
|
44
|
+
: {
|
|
45
|
+
const: value,
|
|
46
|
+
type: Number.isInteger(value)
|
|
47
|
+
? "integer"
|
|
48
|
+
: "number",
|
|
49
|
+
}),
|
|
27
50
|
}))
|
|
28
51
|
.when(isType("boolean"), (value) => nextWithObject(lastValue, {
|
|
29
|
-
literals: A.push(lastValue.literals,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
52
|
+
literals: A.push(lastValue.literals, isOldVersion(version)
|
|
53
|
+
? {
|
|
54
|
+
enum: [value],
|
|
55
|
+
type: "boolean",
|
|
56
|
+
}
|
|
57
|
+
: {
|
|
58
|
+
const: value,
|
|
59
|
+
type: "boolean",
|
|
60
|
+
}),
|
|
33
61
|
}))
|
|
34
62
|
.when(isType("null"), () => nextWithObject(lastValue, {
|
|
35
|
-
literals: A.push(lastValue.literals,
|
|
36
|
-
|
|
63
|
+
literals: A.push(lastValue.literals, P.match(version)
|
|
64
|
+
.with("https://spec.openapis.org/oas/3.0.3", justReturn({
|
|
65
|
+
enum: [null],
|
|
66
|
+
}))
|
|
67
|
+
.with("http://json-schema.org/draft-04/schema#", justReturn({
|
|
68
|
+
type: "null",
|
|
69
|
+
enum: [null],
|
|
70
|
+
}))
|
|
71
|
+
.otherwise(justReturn({
|
|
37
72
|
type: "null",
|
|
38
|
-
|
|
73
|
+
const: null,
|
|
74
|
+
}))),
|
|
39
75
|
}))
|
|
40
76
|
.otherwise(() => next(lastValue)));
|
|
41
77
|
const schemaDefinition = pipe(reduced.literals, P.when(A.lengthEqual(0), () => ({})), P.when(A.lengthEqual(1), A.first), P.otherwise((value) => ({ anyOf: value })));
|
|
42
|
-
return success(schemaDefinition, reduced.
|
|
78
|
+
return success(schemaDefinition, reduced.isOptional);
|
|
43
79
|
});
|
|
44
80
|
|
|
45
81
|
export { literalTransformer };
|
|
@@ -9,12 +9,21 @@ const nullableTransformer = create.createTransformer(utils.DP.nullableKind.has,
|
|
|
9
9
|
return innerResult;
|
|
10
10
|
}
|
|
11
11
|
const inner = utils.unwrap(innerResult);
|
|
12
|
-
return utils.pipe(
|
|
12
|
+
return utils.pipe({
|
|
13
|
+
mode,
|
|
14
|
+
coalescingValue: schema.definition.coalescingValue,
|
|
15
|
+
}, (value) => utils.P.match(value)
|
|
16
|
+
.with(utils.P.union({ mode: "in" }, {
|
|
17
|
+
mode: "out",
|
|
18
|
+
coalescingValue: undefined,
|
|
19
|
+
}), () => ({
|
|
13
20
|
anyOf: [
|
|
14
21
|
inner.schema,
|
|
15
22
|
{ type: "null" },
|
|
16
23
|
],
|
|
17
|
-
}))
|
|
24
|
+
}))
|
|
25
|
+
.with({ mode: "out" }, () => inner.schema)
|
|
26
|
+
.exhaustive(), (schema) => success(schema, inner.isOptional));
|
|
18
27
|
});
|
|
19
28
|
|
|
20
29
|
exports.nullableTransformer = nullableTransformer;
|
|
@@ -7,12 +7,21 @@ const nullableTransformer = createTransformer(DP.nullableKind.has, (schema, { tr
|
|
|
7
7
|
return innerResult;
|
|
8
8
|
}
|
|
9
9
|
const inner = unwrap(innerResult);
|
|
10
|
-
return pipe(
|
|
10
|
+
return pipe({
|
|
11
|
+
mode,
|
|
12
|
+
coalescingValue: schema.definition.coalescingValue,
|
|
13
|
+
}, (value) => P.match(value)
|
|
14
|
+
.with(P.union({ mode: "in" }, {
|
|
15
|
+
mode: "out",
|
|
16
|
+
coalescingValue: undefined,
|
|
17
|
+
}), () => ({
|
|
11
18
|
anyOf: [
|
|
12
19
|
inner.schema,
|
|
13
20
|
{ type: "null" },
|
|
14
21
|
],
|
|
15
|
-
}))
|
|
22
|
+
}))
|
|
23
|
+
.with({ mode: "out" }, () => inner.schema)
|
|
24
|
+
.exhaustive(), (schema) => success(schema, inner.isOptional));
|
|
16
25
|
});
|
|
17
26
|
|
|
18
27
|
export { nullableTransformer };
|
|
@@ -14,7 +14,7 @@ const objectTransformer = create.createTransformer(utils.DP.objectKind.has, (sch
|
|
|
14
14
|
...lastValue.properties,
|
|
15
15
|
[key]: inner.schema,
|
|
16
16
|
},
|
|
17
|
-
required: inner.
|
|
17
|
+
required: inner.isOptional
|
|
18
18
|
? lastValue.required
|
|
19
19
|
: utils.A.push(lastValue.required ?? [], key),
|
|
20
20
|
})))));
|
|
@@ -12,7 +12,7 @@ const objectTransformer = createTransformer(DP.objectKind.has, (schema, { transf
|
|
|
12
12
|
...lastValue.properties,
|
|
13
13
|
[key]: inner.schema,
|
|
14
14
|
},
|
|
15
|
-
required: inner.
|
|
15
|
+
required: inner.isOptional
|
|
16
16
|
? lastValue.required
|
|
17
17
|
: A.push(lastValue.required ?? [], key),
|
|
18
18
|
})))));
|
|
@@ -3,6 +3,15 @@
|
|
|
3
3
|
var utils = require('@duplojs/utils');
|
|
4
4
|
var create = require('../create.cjs');
|
|
5
5
|
|
|
6
|
-
const optionalTransformer = create.createTransformer(utils.DP.optionalKind.has, (schema, { transformer, success, mode, }) => utils.pipe(schema.definition.inner, transformer, utils.E.whenIsRight((inner) => utils.pipe(
|
|
6
|
+
const optionalTransformer = create.createTransformer(utils.DP.optionalKind.has, (schema, { transformer, success, mode, }) => utils.pipe(schema.definition.inner, transformer, utils.E.whenIsRight((inner) => utils.pipe({
|
|
7
|
+
mode,
|
|
8
|
+
coalescingValue: schema.definition.coalescingValue,
|
|
9
|
+
}, (value) => utils.P.match(value)
|
|
10
|
+
.with(utils.P.union({ mode: "in" }, {
|
|
11
|
+
mode: "out",
|
|
12
|
+
coalescingValue: undefined,
|
|
13
|
+
}), () => true)
|
|
14
|
+
.with({ mode: "out" }, () => inner.isOptional)
|
|
15
|
+
.exhaustive(), (isOptional) => success(inner.schema, isOptional)))));
|
|
7
16
|
|
|
8
17
|
exports.optionalTransformer = optionalTransformer;
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { DP, pipe, E, P } from '@duplojs/utils';
|
|
2
2
|
import { createTransformer } from '../create.mjs';
|
|
3
3
|
|
|
4
|
-
const optionalTransformer = createTransformer(DP.optionalKind.has, (schema, { transformer, success, mode, }) => pipe(schema.definition.inner, transformer, E.whenIsRight((inner) => pipe(
|
|
4
|
+
const optionalTransformer = createTransformer(DP.optionalKind.has, (schema, { transformer, success, mode, }) => pipe(schema.definition.inner, transformer, E.whenIsRight((inner) => pipe({
|
|
5
|
+
mode,
|
|
6
|
+
coalescingValue: schema.definition.coalescingValue,
|
|
7
|
+
}, (value) => P.match(value)
|
|
8
|
+
.with(P.union({ mode: "in" }, {
|
|
9
|
+
mode: "out",
|
|
10
|
+
coalescingValue: undefined,
|
|
11
|
+
}), () => true)
|
|
12
|
+
.with({ mode: "out" }, () => inner.isOptional)
|
|
13
|
+
.exhaustive(), (isOptional) => success(inner.schema, isOptional)))));
|
|
5
14
|
|
|
6
15
|
export { optionalTransformer };
|
|
@@ -4,9 +4,9 @@ var utils = require('@duplojs/utils');
|
|
|
4
4
|
var create = require('../create.cjs');
|
|
5
5
|
|
|
6
6
|
const unionTransformer = create.createTransformer(utils.DP.unionKind.has, (schema, { transformer, success, }) => {
|
|
7
|
-
let
|
|
7
|
+
let isOptional = false;
|
|
8
8
|
const optionsResult = utils.A.reduce(schema.definition.options, utils.A.reduceFrom([]), ({ element, lastValue, nextPush, exit }) => utils.pipe(transformer(element), utils.when(utils.E.isLeft, exit), utils.E.whenIsRight((option) => {
|
|
9
|
-
|
|
9
|
+
isOptional ||= option.isOptional;
|
|
10
10
|
return nextPush(lastValue, option.schema);
|
|
11
11
|
})));
|
|
12
12
|
if (utils.E.isLeft(optionsResult)) {
|
|
@@ -14,7 +14,7 @@ const unionTransformer = create.createTransformer(utils.DP.unionKind.has, (schem
|
|
|
14
14
|
}
|
|
15
15
|
return success({
|
|
16
16
|
anyOf: optionsResult,
|
|
17
|
-
},
|
|
17
|
+
}, isOptional);
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
exports.unionTransformer = unionTransformer;
|
|
@@ -2,9 +2,9 @@ import { DP, A, pipe, when, E } from '@duplojs/utils';
|
|
|
2
2
|
import { createTransformer } from '../create.mjs';
|
|
3
3
|
|
|
4
4
|
const unionTransformer = createTransformer(DP.unionKind.has, (schema, { transformer, success, }) => {
|
|
5
|
-
let
|
|
5
|
+
let isOptional = false;
|
|
6
6
|
const optionsResult = A.reduce(schema.definition.options, A.reduceFrom([]), ({ element, lastValue, nextPush, exit }) => pipe(transformer(element), when(E.isLeft, exit), E.whenIsRight((option) => {
|
|
7
|
-
|
|
7
|
+
isOptional ||= option.isOptional;
|
|
8
8
|
return nextPush(lastValue, option.schema);
|
|
9
9
|
})));
|
|
10
10
|
if (E.isLeft(optionsResult)) {
|
|
@@ -12,7 +12,7 @@ const unionTransformer = createTransformer(DP.unionKind.has, (schema, { transfor
|
|
|
12
12
|
}
|
|
13
13
|
return success({
|
|
14
14
|
anyOf: optionsResult,
|
|
15
|
-
},
|
|
15
|
+
}, isOptional);
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
export { unionTransformer };
|
|
@@ -33,22 +33,22 @@ function transformer(schema, params) {
|
|
|
33
33
|
if (currentDeclaration) {
|
|
34
34
|
return utils.E.right("buildSuccess", {
|
|
35
35
|
schema: { $ref: buildRef(currentDeclaration.name, params.version) },
|
|
36
|
-
|
|
36
|
+
isOptional: currentDeclaration.isOptional,
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
const currentIdentifier = utils.whenElse(params.recursiveDataParsers, utils.A.includes(currentSchema), () => {
|
|
40
40
|
const identifier = currentSchema.definition.identifier ?? `RecursiveType${params.context.size}`;
|
|
41
41
|
params.context.set(currentSchema, {
|
|
42
42
|
name: identifier,
|
|
43
|
-
|
|
43
|
+
isOptional: false,
|
|
44
44
|
});
|
|
45
45
|
return identifier;
|
|
46
46
|
}, utils.justReturn(currentSchema.definition.identifier));
|
|
47
47
|
const functionParams = {
|
|
48
|
-
success(result,
|
|
48
|
+
success(result, isOptional = false) {
|
|
49
49
|
return utils.E.right("buildSuccess", {
|
|
50
50
|
schema: result,
|
|
51
|
-
|
|
51
|
+
isOptional,
|
|
52
52
|
});
|
|
53
53
|
},
|
|
54
54
|
transformer(schema) {
|
|
@@ -75,13 +75,13 @@ function transformer(schema, params) {
|
|
|
75
75
|
return result;
|
|
76
76
|
}
|
|
77
77
|
if (currentIdentifier) {
|
|
78
|
-
const { schema: builtSchema,
|
|
78
|
+
const { schema: builtSchema, isOptional } = utils.unwrap(result);
|
|
79
79
|
params.context.set(currentSchema, {
|
|
80
80
|
name: currentIdentifier,
|
|
81
81
|
schema: builtSchema,
|
|
82
|
-
|
|
82
|
+
isOptional,
|
|
83
83
|
});
|
|
84
|
-
return functionParams.success({ $ref: buildRef(currentIdentifier, params.version) },
|
|
84
|
+
return functionParams.success({ $ref: buildRef(currentIdentifier, params.version) }, isOptional);
|
|
85
85
|
}
|
|
86
86
|
return result;
|
|
87
87
|
}
|
|
@@ -31,22 +31,22 @@ function transformer(schema, params) {
|
|
|
31
31
|
if (currentDeclaration) {
|
|
32
32
|
return E.right("buildSuccess", {
|
|
33
33
|
schema: { $ref: buildRef(currentDeclaration.name, params.version) },
|
|
34
|
-
|
|
34
|
+
isOptional: currentDeclaration.isOptional,
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
const currentIdentifier = whenElse(params.recursiveDataParsers, A.includes(currentSchema), () => {
|
|
38
38
|
const identifier = currentSchema.definition.identifier ?? `RecursiveType${params.context.size}`;
|
|
39
39
|
params.context.set(currentSchema, {
|
|
40
40
|
name: identifier,
|
|
41
|
-
|
|
41
|
+
isOptional: false,
|
|
42
42
|
});
|
|
43
43
|
return identifier;
|
|
44
44
|
}, justReturn(currentSchema.definition.identifier));
|
|
45
45
|
const functionParams = {
|
|
46
|
-
success(result,
|
|
46
|
+
success(result, isOptional = false) {
|
|
47
47
|
return E.right("buildSuccess", {
|
|
48
48
|
schema: result,
|
|
49
|
-
|
|
49
|
+
isOptional,
|
|
50
50
|
});
|
|
51
51
|
},
|
|
52
52
|
transformer(schema) {
|
|
@@ -73,13 +73,13 @@ function transformer(schema, params) {
|
|
|
73
73
|
return result;
|
|
74
74
|
}
|
|
75
75
|
if (currentIdentifier) {
|
|
76
|
-
const { schema: builtSchema,
|
|
76
|
+
const { schema: builtSchema, isOptional } = unwrap(result);
|
|
77
77
|
params.context.set(currentSchema, {
|
|
78
78
|
name: currentIdentifier,
|
|
79
79
|
schema: builtSchema,
|
|
80
|
-
|
|
80
|
+
isOptional,
|
|
81
81
|
});
|
|
82
|
-
return functionParams.success({ $ref: buildRef(currentIdentifier, params.version) },
|
|
82
|
+
return functionParams.success({ $ref: buildRef(currentIdentifier, params.version) }, isOptional);
|
|
83
83
|
}
|
|
84
84
|
return result;
|
|
85
85
|
}
|
|
@@ -29,6 +29,7 @@ var union = require('./transformer/defaults/union.cjs');
|
|
|
29
29
|
var unknown = require('./transformer/defaults/unknown.cjs');
|
|
30
30
|
var date = require('./transformer/defaults/date.cjs');
|
|
31
31
|
var time = require('./transformer/defaults/time.cjs');
|
|
32
|
+
var includesUndefinedTypeNode = require('./transformer/includesUndefinedTypeNode.cjs');
|
|
32
33
|
|
|
33
34
|
|
|
34
35
|
|
|
@@ -60,3 +61,4 @@ exports.unionTransformer = union.unionTransformer;
|
|
|
60
61
|
exports.unknownTransformer = unknown.unknownTransformer;
|
|
61
62
|
exports.dateTransformer = date.dateTransformer;
|
|
62
63
|
exports.timeTransformer = time.timeTransformer;
|
|
64
|
+
exports.includesUndefinedTypeNode = includesUndefinedTypeNode.includesUndefinedTypeNode;
|
|
@@ -27,3 +27,4 @@ export { unionTransformer } from './transformer/defaults/union.mjs';
|
|
|
27
27
|
export { unknownTransformer } from './transformer/defaults/unknown.mjs';
|
|
28
28
|
export { dateTransformer } from './transformer/defaults/date.mjs';
|
|
29
29
|
export { timeTransformer } from './transformer/defaults/time.mjs';
|
|
30
|
+
export { includesUndefinedTypeNode } from './transformer/includesUndefinedTypeNode.mjs';
|
|
@@ -6,10 +6,8 @@ dataParser.dataParserInit.overrideHandler.setMethod("setIdentifier", (schema, id
|
|
|
6
6
|
schema.definition.identifier = identifier;
|
|
7
7
|
return schema;
|
|
8
8
|
});
|
|
9
|
-
dataParser.dataParserInit.overrideHandler.setMethod("addIdentifier", (schema, identifier) =>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
},
|
|
15
|
-
}));
|
|
9
|
+
dataParser.dataParserInit.overrideHandler.setMethod("addIdentifier", (schema, identifier) => {
|
|
10
|
+
const newSchema = schema.clone();
|
|
11
|
+
newSchema.setIdentifier(identifier);
|
|
12
|
+
return newSchema;
|
|
13
|
+
});
|
|
@@ -4,10 +4,8 @@ dataParserInit.overrideHandler.setMethod("setIdentifier", (schema, identifier) =
|
|
|
4
4
|
schema.definition.identifier = identifier;
|
|
5
5
|
return schema;
|
|
6
6
|
});
|
|
7
|
-
dataParserInit.overrideHandler.setMethod("addIdentifier", (schema, identifier) =>
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
},
|
|
13
|
-
}));
|
|
7
|
+
dataParserInit.overrideHandler.setMethod("addIdentifier", (schema, identifier) => {
|
|
8
|
+
const newSchema = schema.clone();
|
|
9
|
+
newSchema.setIdentifier(identifier);
|
|
10
|
+
return newSchema;
|
|
11
|
+
});
|
|
@@ -10,10 +10,19 @@ const nullableTransformer = create.createTransformer(utils.DP.nullableKind.has,
|
|
|
10
10
|
return innerResult;
|
|
11
11
|
}
|
|
12
12
|
const innerType = utils.unwrap(innerResult);
|
|
13
|
-
return utils.pipe(
|
|
13
|
+
return utils.pipe({
|
|
14
|
+
mode,
|
|
15
|
+
coalescingValue: schema.definition.coalescingValue,
|
|
16
|
+
}, (value) => utils.P.match(value)
|
|
17
|
+
.with(utils.P.union({ mode: "in" }, {
|
|
18
|
+
mode: "out",
|
|
19
|
+
coalescingValue: undefined,
|
|
20
|
+
}), () => utils.pipe(typescript.factory.createNull(), typescript.factory.createLiteralTypeNode, (value) => typescript.factory.createUnionTypeNode([
|
|
14
21
|
innerType,
|
|
15
22
|
value,
|
|
16
|
-
])))
|
|
23
|
+
])))
|
|
24
|
+
.with({ mode: "out" }, () => innerType)
|
|
25
|
+
.exhaustive(), success);
|
|
17
26
|
});
|
|
18
27
|
|
|
19
28
|
exports.nullableTransformer = nullableTransformer;
|
|
@@ -8,10 +8,19 @@ const nullableTransformer = createTransformer(DP.nullableKind.has, (schema, { tr
|
|
|
8
8
|
return innerResult;
|
|
9
9
|
}
|
|
10
10
|
const innerType = unwrap(innerResult);
|
|
11
|
-
return pipe(
|
|
11
|
+
return pipe({
|
|
12
|
+
mode,
|
|
13
|
+
coalescingValue: schema.definition.coalescingValue,
|
|
14
|
+
}, (value) => P.match(value)
|
|
15
|
+
.with(P.union({ mode: "in" }, {
|
|
16
|
+
mode: "out",
|
|
17
|
+
coalescingValue: undefined,
|
|
18
|
+
}), () => pipe(factory.createNull(), factory.createLiteralTypeNode, (value) => factory.createUnionTypeNode([
|
|
12
19
|
innerType,
|
|
13
20
|
value,
|
|
14
|
-
])))
|
|
21
|
+
])))
|
|
22
|
+
.with({ mode: "out" }, () => innerType)
|
|
23
|
+
.exhaustive(), success);
|
|
15
24
|
});
|
|
16
25
|
|
|
17
26
|
export { nullableTransformer };
|
|
@@ -3,17 +3,9 @@
|
|
|
3
3
|
var utils = require('@duplojs/utils');
|
|
4
4
|
var typescript = require('typescript');
|
|
5
5
|
var create = require('../create.cjs');
|
|
6
|
+
var includesUndefinedTypeNode = require('../includesUndefinedTypeNode.cjs');
|
|
6
7
|
|
|
7
|
-
function includesUndefinedTypeNode(typeNode) {
|
|
8
|
-
if (typeNode.kind === typescript.SyntaxKind.UndefinedKeyword) {
|
|
9
|
-
return true;
|
|
10
|
-
}
|
|
11
|
-
if (typescript.isUnionTypeNode(typeNode)) {
|
|
12
|
-
return typeNode.types.some((subTypeNode) => includesUndefinedTypeNode(subTypeNode));
|
|
13
|
-
}
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
8
|
const regexIdentifier = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
17
|
-
const objectTransformer = create.createTransformer(utils.DP.objectKind.has, (schema, { transformer, success, }) => utils.pipe(schema.definition.shape, utils.O.entries, utils.A.reduce(utils.A.reduceFrom([]), ({ element: [key, value], lastValue, next, exit }) => utils.pipe(transformer(value), utils.when(utils.E.isLeft, exit), utils.E.whenIsRight((typeNode) => utils.pipe(includesUndefinedTypeNode(typeNode), utils.P.match(true, () => typescript.factory.createToken(typescript.SyntaxKind.QuestionToken)), utils.P.match(false, () => undefined), utils.P.exhaustive, (optional) => utils.pipe(key, utils.whenElse(utils.S.test(regexIdentifier), typescript.factory.createIdentifier, typescript.factory.createStringLiteral), (propertyName) => typescript.factory.createPropertySignature(undefined, propertyName, optional, typeNode), (typeElement) => utils.A.push(lastValue, typeElement), next))))), utils.when(utils.isType("array"), utils.innerPipe(typescript.factory.createTypeLiteralNode, success))));
|
|
9
|
+
const objectTransformer = create.createTransformer(utils.DP.objectKind.has, (schema, { transformer, success, }) => utils.pipe(schema.definition.shape, utils.O.entries, utils.A.reduce(utils.A.reduceFrom([]), ({ element: [key, value], lastValue, next, exit }) => utils.pipe(transformer(value), utils.when(utils.E.isLeft, exit), utils.E.whenIsRight((typeNode) => utils.pipe(includesUndefinedTypeNode.includesUndefinedTypeNode(typeNode), utils.P.match(true, () => typescript.factory.createToken(typescript.SyntaxKind.QuestionToken)), utils.P.match(false, () => undefined), utils.P.exhaustive, (optional) => utils.pipe(key, utils.whenElse(utils.S.test(regexIdentifier), typescript.factory.createIdentifier, typescript.factory.createStringLiteral), (propertyName) => typescript.factory.createPropertySignature(undefined, propertyName, optional, typeNode), (typeElement) => utils.A.push(lastValue, typeElement), next))))), utils.when(utils.isType("array"), utils.innerPipe(typescript.factory.createTypeLiteralNode, success))));
|
|
18
10
|
|
|
19
11
|
exports.objectTransformer = objectTransformer;
|
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
import { DP, pipe, O, A, when, E, P, whenElse, S, isType, innerPipe } from '@duplojs/utils';
|
|
2
|
-
import {
|
|
2
|
+
import { factory, SyntaxKind } from 'typescript';
|
|
3
3
|
import { createTransformer } from '../create.mjs';
|
|
4
|
+
import { includesUndefinedTypeNode } from '../includesUndefinedTypeNode.mjs';
|
|
4
5
|
|
|
5
|
-
function includesUndefinedTypeNode(typeNode) {
|
|
6
|
-
if (typeNode.kind === SyntaxKind.UndefinedKeyword) {
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
9
|
-
if (isUnionTypeNode(typeNode)) {
|
|
10
|
-
return typeNode.types.some((subTypeNode) => includesUndefinedTypeNode(subTypeNode));
|
|
11
|
-
}
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
6
|
const regexIdentifier = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
15
7
|
const objectTransformer = createTransformer(DP.objectKind.has, (schema, { transformer, success, }) => pipe(schema.definition.shape, O.entries, A.reduce(A.reduceFrom([]), ({ element: [key, value], lastValue, next, exit }) => pipe(transformer(value), when(E.isLeft, exit), E.whenIsRight((typeNode) => pipe(includesUndefinedTypeNode(typeNode), P.match(true, () => factory.createToken(SyntaxKind.QuestionToken)), P.match(false, () => undefined), P.exhaustive, (optional) => pipe(key, whenElse(S.test(regexIdentifier), factory.createIdentifier, factory.createStringLiteral), (propertyName) => factory.createPropertySignature(undefined, propertyName, optional, typeNode), (typeElement) => A.push(lastValue, typeElement), next))))), when(isType("array"), innerPipe(factory.createTypeLiteralNode, success))));
|
|
16
8
|
|
|
@@ -4,9 +4,18 @@ var utils = require('@duplojs/utils');
|
|
|
4
4
|
var typescript = require('typescript');
|
|
5
5
|
var create = require('../create.cjs');
|
|
6
6
|
|
|
7
|
-
const optionalTransformer = create.createTransformer(utils.DP.optionalKind.has, (schema, { transformer, mode, success, }) => utils.pipe(schema.definition.inner, transformer, utils.E.whenIsRight((innerType) => utils.pipe(
|
|
7
|
+
const optionalTransformer = create.createTransformer(utils.DP.optionalKind.has, (schema, { transformer, mode, success, }) => utils.pipe(schema.definition.inner, transformer, utils.E.whenIsRight((innerType) => utils.pipe({
|
|
8
|
+
mode,
|
|
9
|
+
coalescingValue: schema.definition.coalescingValue,
|
|
10
|
+
}, (value) => utils.P.match(value)
|
|
11
|
+
.with(utils.P.union({ mode: "in" }, {
|
|
12
|
+
mode: "out",
|
|
13
|
+
coalescingValue: undefined,
|
|
14
|
+
}), () => typescript.factory.createUnionTypeNode([
|
|
8
15
|
innerType,
|
|
9
16
|
typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.UndefinedKeyword),
|
|
10
|
-
]))
|
|
17
|
+
]))
|
|
18
|
+
.with({ mode: "out" }, () => innerType)
|
|
19
|
+
.exhaustive(), success))));
|
|
11
20
|
|
|
12
21
|
exports.optionalTransformer = optionalTransformer;
|
|
@@ -2,9 +2,18 @@ import { DP, pipe, E, P } from '@duplojs/utils';
|
|
|
2
2
|
import { factory, SyntaxKind } from 'typescript';
|
|
3
3
|
import { createTransformer } from '../create.mjs';
|
|
4
4
|
|
|
5
|
-
const optionalTransformer = createTransformer(DP.optionalKind.has, (schema, { transformer, mode, success, }) => pipe(schema.definition.inner, transformer, E.whenIsRight((innerType) => pipe(
|
|
5
|
+
const optionalTransformer = createTransformer(DP.optionalKind.has, (schema, { transformer, mode, success, }) => pipe(schema.definition.inner, transformer, E.whenIsRight((innerType) => pipe({
|
|
6
|
+
mode,
|
|
7
|
+
coalescingValue: schema.definition.coalescingValue,
|
|
8
|
+
}, (value) => P.match(value)
|
|
9
|
+
.with(P.union({ mode: "in" }, {
|
|
10
|
+
mode: "out",
|
|
11
|
+
coalescingValue: undefined,
|
|
12
|
+
}), () => factory.createUnionTypeNode([
|
|
6
13
|
innerType,
|
|
7
14
|
factory.createKeywordTypeNode(SyntaxKind.UndefinedKeyword),
|
|
8
|
-
]))
|
|
15
|
+
]))
|
|
16
|
+
.with({ mode: "out" }, () => innerType)
|
|
17
|
+
.exhaustive(), success))));
|
|
9
18
|
|
|
10
19
|
export { optionalTransformer };
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var utils = require('@duplojs/utils');
|
|
4
4
|
var typescript = require('typescript');
|
|
5
5
|
var create = require('../create.cjs');
|
|
6
|
+
var includesUndefinedTypeNode = require('../includesUndefinedTypeNode.cjs');
|
|
6
7
|
|
|
7
8
|
const recordTransformer = create.createTransformer(utils.DP.recordKind.has, ({ definition: { key, value } }, { transformer, success, }) => {
|
|
8
9
|
const keyResult = transformer(key);
|
|
@@ -15,7 +16,7 @@ const recordTransformer = create.createTransformer(utils.DP.recordKind.has, ({ d
|
|
|
15
16
|
}
|
|
16
17
|
const keyType = utils.unwrap(keyResult);
|
|
17
18
|
const valueType = utils.unwrap(valueResult);
|
|
18
|
-
const recordType = typescript.factory.createTypeReferenceNode("Record", [keyType, valueType]);
|
|
19
|
+
const recordType = utils.pipe(typescript.factory.createTypeReferenceNode("Record", [keyType, valueType]), utils.when(() => includesUndefinedTypeNode.includesUndefinedTypeNode(valueType), (recodeTypeNode) => typescript.factory.createTypeReferenceNode("Partial", [recodeTypeNode])));
|
|
19
20
|
return success(recordType);
|
|
20
21
|
});
|
|
21
22
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { DP, E, unwrap } from '@duplojs/utils';
|
|
1
|
+
import { DP, E, unwrap, pipe, when } from '@duplojs/utils';
|
|
2
2
|
import { factory } from 'typescript';
|
|
3
3
|
import { createTransformer } from '../create.mjs';
|
|
4
|
+
import { includesUndefinedTypeNode } from '../includesUndefinedTypeNode.mjs';
|
|
4
5
|
|
|
5
6
|
const recordTransformer = createTransformer(DP.recordKind.has, ({ definition: { key, value } }, { transformer, success, }) => {
|
|
6
7
|
const keyResult = transformer(key);
|
|
@@ -13,7 +14,7 @@ const recordTransformer = createTransformer(DP.recordKind.has, ({ definition: {
|
|
|
13
14
|
}
|
|
14
15
|
const keyType = unwrap(keyResult);
|
|
15
16
|
const valueType = unwrap(valueResult);
|
|
16
|
-
const recordType = factory.createTypeReferenceNode("Record", [keyType, valueType]);
|
|
17
|
+
const recordType = pipe(factory.createTypeReferenceNode("Record", [keyType, valueType]), when(() => includesUndefinedTypeNode(valueType), (recodeTypeNode) => factory.createTypeReferenceNode("Partial", [recodeTypeNode])));
|
|
17
18
|
return success(recordType);
|
|
18
19
|
});
|
|
19
20
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('@duplojs/utils');
|
|
4
|
+
var typescript = require('typescript');
|
|
5
|
+
|
|
6
|
+
function includesUndefinedTypeNode(typeNode) {
|
|
7
|
+
if (typeNode.kind === typescript.SyntaxKind.UndefinedKeyword) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
if (typescript.isUnionTypeNode(typeNode)) {
|
|
11
|
+
return utils.A.some(typeNode.types, (subTypeNode) => includesUndefinedTypeNode(subTypeNode));
|
|
12
|
+
}
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.includesUndefinedTypeNode = includesUndefinedTypeNode;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { A } from '@duplojs/utils';
|
|
2
|
+
import { SyntaxKind, isUnionTypeNode } from 'typescript';
|
|
3
|
+
|
|
4
|
+
function includesUndefinedTypeNode(typeNode) {
|
|
5
|
+
if (typeNode.kind === SyntaxKind.UndefinedKeyword) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
if (isUnionTypeNode(typeNode)) {
|
|
9
|
+
return A.some(typeNode.types, (subTypeNode) => includesUndefinedTypeNode(subTypeNode));
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { includesUndefinedTypeNode };
|
|
@@ -4,9 +4,11 @@ var create = require('./create.cjs');
|
|
|
4
4
|
var transformer = require('./transformer.cjs');
|
|
5
5
|
require('./hook.cjs');
|
|
6
6
|
var index = require('./defaults/index.cjs');
|
|
7
|
+
var includesUndefinedTypeNode = require('./includesUndefinedTypeNode.cjs');
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
exports.createTransformer = create.createTransformer;
|
|
11
12
|
exports.transformer = transformer.transformer;
|
|
12
13
|
exports.defaultTransformers = index.defaultTransformers;
|
|
14
|
+
exports.includesUndefinedTypeNode = includesUndefinedTypeNode.includesUndefinedTypeNode;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@duplojs/data-parser-tools",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "duplojs",
|
|
6
6
|
"contributors": [
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"vitest": "3.2.4"
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
74
|
-
"@duplojs/utils": ">=1.
|
|
74
|
+
"@duplojs/utils": ">=1.4.36 <2.0.0"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
77
|
"typescript": "5.9.2"
|