typia 5.2.0 → 5.2.1-dev.20231011
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/lib/executable/TypiaSetupWizard.js +13 -13
- package/lib/executable/TypiaSetupWizard.js.map +1 -1
- package/package.json +1 -1
- package/src/executable/TypiaSetupWizard.ts +15 -13
- package/src/factories/internal/metadata/emplace_metadata_object.ts +150 -150
- package/src/functional/$clone.ts +4 -4
- package/src/http.ts +1149 -1149
- package/src/json.ts +648 -648
- package/src/misc.ts +651 -651
- package/src/programmers/IsProgrammer.ts +252 -252
- package/src/programmers/TypiaProgrammer.ts +169 -169
- package/src/programmers/helpers/OptionPredicator.ts +15 -15
- package/src/programmers/json/JsonStringifyProgrammer.ts +964 -964
- package/src/protobuf.ts +887 -887
- package/src/transformers/ITransformOptions.ts +62 -62
|
@@ -86,27 +86,27 @@ var TypiaSetupWizard;
|
|
|
86
86
|
return [4, pack.save(function (data) {
|
|
87
87
|
var _a;
|
|
88
88
|
(_a = data.scripts) !== null && _a !== void 0 ? _a : (data.scripts = {});
|
|
89
|
-
if (typeof data.scripts.postinstall === "string"
|
|
90
|
-
data.scripts.postinstall.
|
|
91
|
-
if (data.scripts.postinstall.indexOf("ts-patch install") === -1)
|
|
92
|
-
data.scripts.postinstall =
|
|
93
|
-
"ts-patch install && " + data.scripts.postinstall;
|
|
94
|
-
}
|
|
95
|
-
else
|
|
96
|
-
data.scripts.postinstall = "ts-patch install";
|
|
97
|
-
if (typeof data.scripts.prepare === "string") {
|
|
98
|
-
data.scripts.prepare = data.scripts.prepare
|
|
89
|
+
if (typeof data.scripts.postinstall === "string") {
|
|
90
|
+
data.scripts.postinstall = data.scripts.postinstall
|
|
99
91
|
.split("&&")
|
|
100
92
|
.map(function (str) { return str.trim(); })
|
|
101
93
|
.filter(function (str) { return str.indexOf("ts-patch install") === -1; })
|
|
102
94
|
.join(" && ");
|
|
103
|
-
if (data.scripts.
|
|
104
|
-
delete data.scripts.
|
|
95
|
+
if (data.scripts.postinstall.length === 0)
|
|
96
|
+
delete data.scripts.postinstall;
|
|
105
97
|
}
|
|
98
|
+
if (typeof data.scripts.prepare === "string" &&
|
|
99
|
+
data.scripts.prepare.trim().length) {
|
|
100
|
+
if (data.scripts.prepare.indexOf("ts-patch install") === -1)
|
|
101
|
+
data.scripts.prepare =
|
|
102
|
+
"ts-patch install && " + data.scripts.prepare;
|
|
103
|
+
}
|
|
104
|
+
else
|
|
105
|
+
data.scripts.prepare = "ts-patch install";
|
|
106
106
|
})];
|
|
107
107
|
case 3:
|
|
108
108
|
_b.sent();
|
|
109
|
-
CommandExecutor_1.CommandExecutor.run("".concat(pack.manager, " run
|
|
109
|
+
CommandExecutor_1.CommandExecutor.run("".concat(pack.manager, " run prepare"));
|
|
110
110
|
return [4, PluginConfigurator_1.PluginConfigurator.configure(args)];
|
|
111
111
|
case 4:
|
|
112
112
|
_b.sent();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypiaSetupWizard.js","sourceRoot":"","sources":["../../src/executable/TypiaSetupWizard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAAoB;AAEpB,yDAAwD;AACxD,2DAA0D;AAC1D,yDAAwD;AACxD,iEAAgE;AAEhE,IAAiB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"TypiaSetupWizard.js","sourceRoot":"","sources":["../../src/executable/TypiaSetupWizard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAAoB;AAEpB,yDAAwD;AACxD,2DAA0D;AAC1D,yDAAwD;AACxD,iEAAgE;AAEhE,IAAiB,gBAAgB,CAwIhC;AAxID,WAAiB,gBAAgB;;IAM7B,SAAsB,KAAK;;;;;;;wBACvB,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAC;wBACxD,OAA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KAAK,CAAC,EAAE;gCACvB,IAAI,OAAO,CAAC,GAAG,EAAE,KAAK,IAAI,CAAC,SAAS;oCAChC,MAAM,IAAI,QAAQ,CAAC,wCAAsC,CAAC,CAAC;gCAC/D,WAAO,IAAI,EAAC;6BACf;iCAAM,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;gCAAE,WAAO,QAAQ,CAAC,CAAC,CAAE,EAAC;4BACtD,WAAO,MAAM,CAAC,UAAU,CAAC,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,EAAC;;;iBACzD,CAAC;YAGF,WAAO,MAAM,CAAC,UAAO,OAAO;;;;;;gCACxB,KAAA,IAAI,CAAA;4CAAW,OAAO,CAAC,OAAO;;;;gCAAf,KAAA,OAAO,CAAA;gCAAa,WAAM,MAAM,CAAC,SAAS,CAAC,CACtD,iBAAiB,CACpB,CACG;wCACI,KAAc;wCACd,MAAe;wCACf,+BAAyC;qCAC5C,EACD,UAAC,KAAK,IAAK,OAAA,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAW,EAA7B,CAA6B,CAC3C,EAAA;;yCATsB,OAAO,GAAK,SASlC;;;gCATD,GAAK,OAAO,KASX,CAAC;4CACF,OAAO,CAAC,OAAO;;;;gCAAf,KAAA,OAAO,CAAA;gCAAa,WAAM,SAAS,EAAE,EAAA;;yCAA7B,OAAO,GAAK,SAAiB;;;gCAArC,GAAsC;gCAEtC,IAAI,UAAU,CAAC,KAAK;oCAAE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;gCACtC,WAAO,OAAqB,EAAC;;;qBAChC,CAAC,EAAC;;SACN,CAAC;AACN,CAAC,EAxIgB,gBAAgB,gCAAhB,gBAAgB,QAwIhC"}
|
package/package.json
CHANGED
|
@@ -35,27 +35,29 @@ export namespace TypiaSetupWizard {
|
|
|
35
35
|
await pack.save((data) => {
|
|
36
36
|
// COMPOSE POSTINSTALL COMMAND
|
|
37
37
|
data.scripts ??= {};
|
|
38
|
-
if (
|
|
39
|
-
typeof data.scripts.postinstall === "string" &&
|
|
40
|
-
data.scripts.postinstall.trim().length
|
|
41
|
-
) {
|
|
42
|
-
if (data.scripts.postinstall.indexOf("ts-patch install") === -1)
|
|
43
|
-
data.scripts.postinstall =
|
|
44
|
-
"ts-patch install && " + data.scripts.postinstall;
|
|
45
|
-
} else data.scripts.postinstall = "ts-patch install";
|
|
46
38
|
|
|
47
39
|
// FOR OLDER VERSIONS
|
|
48
|
-
if (typeof data.scripts.
|
|
49
|
-
data.scripts.
|
|
40
|
+
if (typeof data.scripts.postinstall === "string") {
|
|
41
|
+
data.scripts.postinstall = data.scripts.postinstall
|
|
50
42
|
.split("&&")
|
|
51
43
|
.map((str) => str.trim())
|
|
52
44
|
.filter((str) => str.indexOf("ts-patch install") === -1)
|
|
53
45
|
.join(" && ");
|
|
54
|
-
if (data.scripts.
|
|
55
|
-
delete data.scripts.
|
|
46
|
+
if (data.scripts.postinstall.length === 0)
|
|
47
|
+
delete data.scripts.postinstall;
|
|
56
48
|
}
|
|
49
|
+
|
|
50
|
+
// THE PREPARE SCRIPT
|
|
51
|
+
if (
|
|
52
|
+
typeof data.scripts.prepare === "string" &&
|
|
53
|
+
data.scripts.prepare.trim().length
|
|
54
|
+
) {
|
|
55
|
+
if (data.scripts.prepare.indexOf("ts-patch install") === -1)
|
|
56
|
+
data.scripts.prepare =
|
|
57
|
+
"ts-patch install && " + data.scripts.prepare;
|
|
58
|
+
} else data.scripts.prepare = "ts-patch install";
|
|
57
59
|
});
|
|
58
|
-
CommandExecutor.run(`${pack.manager} run
|
|
60
|
+
CommandExecutor.run(`${pack.manager} run prepare`);
|
|
59
61
|
|
|
60
62
|
// CONFIGURE TYPIA
|
|
61
63
|
await PluginConfigurator.configure(args);
|
|
@@ -1,150 +1,150 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Metadata } from "../../../schemas/metadata/Metadata";
|
|
4
|
-
import { MetadataObject } from "../../../schemas/metadata/MetadataObject";
|
|
5
|
-
import { MetadataProperty } from "../../../schemas/metadata/MetadataProperty";
|
|
6
|
-
|
|
7
|
-
import { Writable } from "../../../typings/Writable";
|
|
8
|
-
|
|
9
|
-
import { ArrayUtil } from "../../../utils/ArrayUtil";
|
|
10
|
-
|
|
11
|
-
import { CommentFactory } from "../../CommentFactory";
|
|
12
|
-
import { MetadataCollection } from "../../MetadataCollection";
|
|
13
|
-
import { MetadataFactory } from "../../MetadataFactory";
|
|
14
|
-
import { MetadataHelper } from "./MetadataHelper";
|
|
15
|
-
import { explore_metadata } from "./explore_metadata";
|
|
16
|
-
import { iterate_metadata_coalesce } from "./iterate_metadata_coalesce";
|
|
17
|
-
|
|
18
|
-
export const emplace_metadata_object =
|
|
19
|
-
(checker: ts.TypeChecker) =>
|
|
20
|
-
(options: MetadataFactory.IOptions) =>
|
|
21
|
-
(collection: MetadataCollection) =>
|
|
22
|
-
(errors: MetadataFactory.IError[]) =>
|
|
23
|
-
(parent: ts.Type, nullable: boolean): MetadataObject => {
|
|
24
|
-
// EMPLACE OBJECT
|
|
25
|
-
const [obj, newbie] = collection.emplace(checker, parent);
|
|
26
|
-
ArrayUtil.add(obj.nullables, nullable, (elem) => elem === nullable);
|
|
27
|
-
|
|
28
|
-
if (newbie === false) return obj;
|
|
29
|
-
|
|
30
|
-
// PREPARE ASSETS
|
|
31
|
-
const isClass: boolean = parent.isClass();
|
|
32
|
-
const pred: (node: ts.Declaration) => boolean = isClass
|
|
33
|
-
? (node) => {
|
|
34
|
-
const kind: ts.SyntaxKind | undefined = node
|
|
35
|
-
.getChildren()[0]
|
|
36
|
-
?.getChildren()[0]?.kind;
|
|
37
|
-
return (
|
|
38
|
-
kind !== ts.SyntaxKind.PrivateKeyword &&
|
|
39
|
-
kind !== ts.SyntaxKind.ProtectedKeyword &&
|
|
40
|
-
(ts.isParameter(node) || isProperty(node))
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
: (node) => isProperty(node);
|
|
44
|
-
|
|
45
|
-
const insert =
|
|
46
|
-
(key: Metadata) =>
|
|
47
|
-
(value: Metadata) =>
|
|
48
|
-
(
|
|
49
|
-
symbol: ts.Symbol | undefined,
|
|
50
|
-
filter?: (doc: ts.JSDocTagInfo) => boolean,
|
|
51
|
-
): MetadataProperty => {
|
|
52
|
-
// COMMENTS AND TAGS
|
|
53
|
-
const description: string | null = symbol
|
|
54
|
-
? CommentFactory.description(symbol) ?? null
|
|
55
|
-
: null;
|
|
56
|
-
const jsDocTags: ts.JSDocTagInfo[] = (
|
|
57
|
-
symbol?.getJsDocTags() ?? []
|
|
58
|
-
).filter(filter ?? (() => true));
|
|
59
|
-
|
|
60
|
-
// THE PROPERTY
|
|
61
|
-
const property = MetadataProperty.create({
|
|
62
|
-
key,
|
|
63
|
-
value,
|
|
64
|
-
description,
|
|
65
|
-
jsDocTags,
|
|
66
|
-
});
|
|
67
|
-
obj.properties.push(property);
|
|
68
|
-
return property;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
//----
|
|
72
|
-
// REGULAR PROPERTIES
|
|
73
|
-
//----
|
|
74
|
-
for (const prop of parent.getApparentProperties()) {
|
|
75
|
-
// CHECK INTERNAL TAG
|
|
76
|
-
if (
|
|
77
|
-
(prop.getJsDocTags(checker) ?? []).find(
|
|
78
|
-
(tag) => tag.name === "internal",
|
|
79
|
-
) !== undefined
|
|
80
|
-
)
|
|
81
|
-
continue;
|
|
82
|
-
|
|
83
|
-
// CHECK NODE IS A FORMAL PROPERTY
|
|
84
|
-
const [node, type] = (() => {
|
|
85
|
-
const node = prop.getDeclarations()?.[0] as
|
|
86
|
-
| ts.PropertyDeclaration
|
|
87
|
-
| undefined;
|
|
88
|
-
const type: ts.Type | undefined = node
|
|
89
|
-
? checker.getTypeOfSymbolAtLocation(prop, node)
|
|
90
|
-
: checker.getTypeOfPropertyOfType(parent, prop.name);
|
|
91
|
-
return [node, type];
|
|
92
|
-
})();
|
|
93
|
-
if ((node && pred(node) === false) || type === undefined) continue;
|
|
94
|
-
|
|
95
|
-
// GET EXACT TYPE
|
|
96
|
-
const key: Metadata = MetadataHelper.literal_to_metadata(prop.name);
|
|
97
|
-
const value: Metadata = explore_metadata(checker)(options)(
|
|
98
|
-
collection,
|
|
99
|
-
)(errors)(type, {
|
|
100
|
-
top: false,
|
|
101
|
-
object: obj,
|
|
102
|
-
property: prop.name,
|
|
103
|
-
nested: null,
|
|
104
|
-
escaped: false,
|
|
105
|
-
aliased: false,
|
|
106
|
-
});
|
|
107
|
-
Writable(value).optional =
|
|
108
|
-
(prop.flags & ts.SymbolFlags.Optional) !== 0;
|
|
109
|
-
insert(key)(value)(prop);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
//----
|
|
113
|
-
// DYNAMIC PROPERTIES
|
|
114
|
-
//----
|
|
115
|
-
for (const index of checker.getIndexInfosOfType(parent)) {
|
|
116
|
-
// GET EXACT TYPE
|
|
117
|
-
const analyzer = (type: ts.Type) => (property: {} | null) =>
|
|
118
|
-
explore_metadata(checker)(options)(collection)(errors)(type, {
|
|
119
|
-
top: false,
|
|
120
|
-
object: obj,
|
|
121
|
-
property,
|
|
122
|
-
nested: null,
|
|
123
|
-
escaped: false,
|
|
124
|
-
aliased: false,
|
|
125
|
-
});
|
|
126
|
-
const key: Metadata = analyzer(index.keyType)(null);
|
|
127
|
-
const value: Metadata = analyzer(index.type)({});
|
|
128
|
-
|
|
129
|
-
// INSERT WITH REQUIRED CONFIGURATION
|
|
130
|
-
insert(key)(value)(
|
|
131
|
-
index.declaration?.parent
|
|
132
|
-
? checker.getSymbolAtLocation(index.declaration.parent)
|
|
133
|
-
: undefined,
|
|
134
|
-
(doc) => doc.name !== "default",
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
return obj;
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const isProperty = (node: ts.Declaration) =>
|
|
141
|
-
ts.isPropertyDeclaration(node) ||
|
|
142
|
-
ts.isPropertyAssignment(node) ||
|
|
143
|
-
ts.isPropertySignature(node) ||
|
|
144
|
-
ts.isTypeLiteralNode(node);
|
|
145
|
-
|
|
146
|
-
const iterate_optional_coalesce = (meta: Metadata, type: ts.Type): void => {
|
|
147
|
-
if (type.isUnionOrIntersection())
|
|
148
|
-
type.types.forEach((child) => iterate_optional_coalesce(meta, child));
|
|
149
|
-
else iterate_metadata_coalesce(meta, type);
|
|
150
|
-
};
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../../../schemas/metadata/Metadata";
|
|
4
|
+
import { MetadataObject } from "../../../schemas/metadata/MetadataObject";
|
|
5
|
+
import { MetadataProperty } from "../../../schemas/metadata/MetadataProperty";
|
|
6
|
+
|
|
7
|
+
import { Writable } from "../../../typings/Writable";
|
|
8
|
+
|
|
9
|
+
import { ArrayUtil } from "../../../utils/ArrayUtil";
|
|
10
|
+
|
|
11
|
+
import { CommentFactory } from "../../CommentFactory";
|
|
12
|
+
import { MetadataCollection } from "../../MetadataCollection";
|
|
13
|
+
import { MetadataFactory } from "../../MetadataFactory";
|
|
14
|
+
import { MetadataHelper } from "./MetadataHelper";
|
|
15
|
+
import { explore_metadata } from "./explore_metadata";
|
|
16
|
+
import { iterate_metadata_coalesce } from "./iterate_metadata_coalesce";
|
|
17
|
+
|
|
18
|
+
export const emplace_metadata_object =
|
|
19
|
+
(checker: ts.TypeChecker) =>
|
|
20
|
+
(options: MetadataFactory.IOptions) =>
|
|
21
|
+
(collection: MetadataCollection) =>
|
|
22
|
+
(errors: MetadataFactory.IError[]) =>
|
|
23
|
+
(parent: ts.Type, nullable: boolean): MetadataObject => {
|
|
24
|
+
// EMPLACE OBJECT
|
|
25
|
+
const [obj, newbie] = collection.emplace(checker, parent);
|
|
26
|
+
ArrayUtil.add(obj.nullables, nullable, (elem) => elem === nullable);
|
|
27
|
+
|
|
28
|
+
if (newbie === false) return obj;
|
|
29
|
+
|
|
30
|
+
// PREPARE ASSETS
|
|
31
|
+
const isClass: boolean = parent.isClass();
|
|
32
|
+
const pred: (node: ts.Declaration) => boolean = isClass
|
|
33
|
+
? (node) => {
|
|
34
|
+
const kind: ts.SyntaxKind | undefined = node
|
|
35
|
+
.getChildren()[0]
|
|
36
|
+
?.getChildren()[0]?.kind;
|
|
37
|
+
return (
|
|
38
|
+
kind !== ts.SyntaxKind.PrivateKeyword &&
|
|
39
|
+
kind !== ts.SyntaxKind.ProtectedKeyword &&
|
|
40
|
+
(ts.isParameter(node) || isProperty(node))
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
: (node) => isProperty(node);
|
|
44
|
+
|
|
45
|
+
const insert =
|
|
46
|
+
(key: Metadata) =>
|
|
47
|
+
(value: Metadata) =>
|
|
48
|
+
(
|
|
49
|
+
symbol: ts.Symbol | undefined,
|
|
50
|
+
filter?: (doc: ts.JSDocTagInfo) => boolean,
|
|
51
|
+
): MetadataProperty => {
|
|
52
|
+
// COMMENTS AND TAGS
|
|
53
|
+
const description: string | null = symbol
|
|
54
|
+
? CommentFactory.description(symbol) ?? null
|
|
55
|
+
: null;
|
|
56
|
+
const jsDocTags: ts.JSDocTagInfo[] = (
|
|
57
|
+
symbol?.getJsDocTags() ?? []
|
|
58
|
+
).filter(filter ?? (() => true));
|
|
59
|
+
|
|
60
|
+
// THE PROPERTY
|
|
61
|
+
const property = MetadataProperty.create({
|
|
62
|
+
key,
|
|
63
|
+
value,
|
|
64
|
+
description,
|
|
65
|
+
jsDocTags,
|
|
66
|
+
});
|
|
67
|
+
obj.properties.push(property);
|
|
68
|
+
return property;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
//----
|
|
72
|
+
// REGULAR PROPERTIES
|
|
73
|
+
//----
|
|
74
|
+
for (const prop of parent.getApparentProperties()) {
|
|
75
|
+
// CHECK INTERNAL TAG
|
|
76
|
+
if (
|
|
77
|
+
(prop.getJsDocTags(checker) ?? []).find(
|
|
78
|
+
(tag) => tag.name === "internal",
|
|
79
|
+
) !== undefined
|
|
80
|
+
)
|
|
81
|
+
continue;
|
|
82
|
+
|
|
83
|
+
// CHECK NODE IS A FORMAL PROPERTY
|
|
84
|
+
const [node, type] = (() => {
|
|
85
|
+
const node = prop.getDeclarations()?.[0] as
|
|
86
|
+
| ts.PropertyDeclaration
|
|
87
|
+
| undefined;
|
|
88
|
+
const type: ts.Type | undefined = node
|
|
89
|
+
? checker.getTypeOfSymbolAtLocation(prop, node)
|
|
90
|
+
: checker.getTypeOfPropertyOfType(parent, prop.name);
|
|
91
|
+
return [node, type];
|
|
92
|
+
})();
|
|
93
|
+
if ((node && pred(node) === false) || type === undefined) continue;
|
|
94
|
+
|
|
95
|
+
// GET EXACT TYPE
|
|
96
|
+
const key: Metadata = MetadataHelper.literal_to_metadata(prop.name);
|
|
97
|
+
const value: Metadata = explore_metadata(checker)(options)(
|
|
98
|
+
collection,
|
|
99
|
+
)(errors)(type, {
|
|
100
|
+
top: false,
|
|
101
|
+
object: obj,
|
|
102
|
+
property: prop.name,
|
|
103
|
+
nested: null,
|
|
104
|
+
escaped: false,
|
|
105
|
+
aliased: false,
|
|
106
|
+
});
|
|
107
|
+
Writable(value).optional =
|
|
108
|
+
(prop.flags & ts.SymbolFlags.Optional) !== 0;
|
|
109
|
+
insert(key)(value)(prop);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
//----
|
|
113
|
+
// DYNAMIC PROPERTIES
|
|
114
|
+
//----
|
|
115
|
+
for (const index of checker.getIndexInfosOfType(parent)) {
|
|
116
|
+
// GET EXACT TYPE
|
|
117
|
+
const analyzer = (type: ts.Type) => (property: {} | null) =>
|
|
118
|
+
explore_metadata(checker)(options)(collection)(errors)(type, {
|
|
119
|
+
top: false,
|
|
120
|
+
object: obj,
|
|
121
|
+
property,
|
|
122
|
+
nested: null,
|
|
123
|
+
escaped: false,
|
|
124
|
+
aliased: false,
|
|
125
|
+
});
|
|
126
|
+
const key: Metadata = analyzer(index.keyType)(null);
|
|
127
|
+
const value: Metadata = analyzer(index.type)({});
|
|
128
|
+
|
|
129
|
+
// INSERT WITH REQUIRED CONFIGURATION
|
|
130
|
+
insert(key)(value)(
|
|
131
|
+
index.declaration?.parent
|
|
132
|
+
? checker.getSymbolAtLocation(index.declaration.parent)
|
|
133
|
+
: undefined,
|
|
134
|
+
(doc) => doc.name !== "default",
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
return obj;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const isProperty = (node: ts.Declaration) =>
|
|
141
|
+
ts.isPropertyDeclaration(node) ||
|
|
142
|
+
ts.isPropertyAssignment(node) ||
|
|
143
|
+
ts.isPropertySignature(node) ||
|
|
144
|
+
ts.isTypeLiteralNode(node);
|
|
145
|
+
|
|
146
|
+
const iterate_optional_coalesce = (meta: Metadata, type: ts.Type): void => {
|
|
147
|
+
if (type.isUnionOrIntersection())
|
|
148
|
+
type.types.forEach((child) => iterate_optional_coalesce(meta, child));
|
|
149
|
+
else iterate_metadata_coalesce(meta, type);
|
|
150
|
+
};
|
package/src/functional/$clone.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Primitive } from "../Primitive";
|
|
2
|
-
|
|
3
|
-
export const $clone = <T>(value: T): Primitive<T> =>
|
|
4
|
-
JSON.parse(JSON.stringify(value));
|
|
1
|
+
import { Primitive } from "../Primitive";
|
|
2
|
+
|
|
3
|
+
export const $clone = <T>(value: T): Primitive<T> =>
|
|
4
|
+
JSON.parse(JSON.stringify(value));
|