@jointhedots/gear 1.1.18 → 1.2.2
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/esm/builder/build-app-bundle.d.ts +28 -0
- package/esm/builder/build-app-bundle.js +4 -7
- package/esm/builder/build-app-host.d.ts +28 -0
- package/esm/builder/build-app-host.js +0 -1
- package/esm/builder/build-application.d.ts +47 -0
- package/esm/builder/build-application.js +3 -5
- package/esm/builder/build-library.d.ts +20 -0
- package/esm/builder/build-library.js +1 -2
- package/esm/builder/build-target.d.ts +27 -0
- package/esm/builder/build-target.js +3 -4
- package/esm/builder/helpers/emit-bundle-manifest.d.ts +9 -0
- package/esm/builder/helpers/emit-bundle-manifest.js +1 -2
- package/esm/builder/helpers/emit-components-dts.d.ts +9 -0
- package/esm/builder/helpers/emit-components-dts.js +1 -2
- package/esm/builder/helpers/emit-esmodules.d.ts +61 -0
- package/esm/builder/helpers/emit-esmodules.js +5 -6
- package/esm/builder/helpers/emit-package-manifest.d.ts +9 -0
- package/esm/builder/helpers/emit-package-manifest.js +0 -1
- package/esm/builder/helpers/emit-static-assets.d.ts +14 -0
- package/esm/builder/helpers/emit-static-assets.js +1 -2
- package/esm/builder/helpers/emit-typescript-definition.d.ts +35 -0
- package/esm/builder/helpers/emit-typescript-definition.js +6 -7
- package/esm/builder/helpers/path-helpers.d.ts +9 -0
- package/esm/builder/helpers/path-helpers.js +0 -1
- package/esm/builder/helpers/task.d.ts +8 -0
- package/esm/builder/helpers/task.js +0 -1
- package/esm/cli.d.ts +2 -0
- package/esm/cli.js +1 -4
- package/esm/commands/init.d.ts +2 -0
- package/esm/commands/init.js +0 -1
- package/esm/commands/install.d.ts +5 -0
- package/esm/commands/install.js +4 -5
- package/esm/commands/make.d.ts +16 -0
- package/esm/commands/make.js +5 -5
- package/esm/commands/run.d.ts +8 -0
- package/esm/commands/run.js +6 -7
- package/esm/commands/serve.d.ts +9 -0
- package/esm/commands/serve.js +3 -4
- package/esm/core/commands/interface.d.ts +26 -0
- package/esm/core/commands/interface.js +21 -0
- package/esm/core/components/components.d.ts +73 -0
- package/esm/core/components/components.js +2 -0
- package/esm/core/components/helpers.d.ts +7 -0
- package/esm/core/components/helpers.js +68 -0
- package/esm/core/components/manifold.d.ts +77 -0
- package/esm/core/components/manifold.js +442 -0
- package/esm/core/components/mod.d.ts +4 -0
- package/esm/core/components/mod.js +4 -0
- package/esm/core/components/provider.d.ts +42 -0
- package/esm/core/components/provider.js +127 -0
- package/esm/core/logging/mod.d.ts +53 -0
- package/esm/core/logging/mod.js +142 -0
- package/esm/core/logging/trace.d.ts +51 -0
- package/esm/core/logging/trace.js +17 -0
- package/esm/core/mod-browser.d.ts +1 -0
- package/esm/core/mod-browser.js +1 -0
- package/esm/core/mod-node.d.ts +1 -0
- package/esm/core/mod-node.js +1 -0
- package/esm/core/mod.d.ts +5 -0
- package/esm/core/mod.js +5 -0
- package/esm/core/schema/helpers.d.ts +36 -0
- package/esm/core/schema/helpers.js +163 -0
- package/esm/core/schema/mod.d.ts +3 -0
- package/esm/core/schema/mod.js +3 -0
- package/esm/core/schema/schema.d.ts +376 -0
- package/esm/core/schema/schema.js +234 -0
- package/esm/core/schema/zod.d.ts +44 -0
- package/esm/core/schema/zod.js +127 -0
- package/esm/core/services/mod.d.ts +5 -0
- package/esm/core/services/mod.js +5 -0
- package/esm/core/services/service-accessor.d.ts +17 -0
- package/esm/core/services/service-accessor.js +20 -0
- package/esm/core/services/service-definitions.d.ts +37 -0
- package/esm/core/services/service-definitions.js +44 -0
- package/esm/core/services/service-points.d.ts +40 -0
- package/esm/core/services/service-points.js +164 -0
- package/esm/core/services/service-specification.d.ts +52 -0
- package/esm/core/services/service-specification.js +59 -0
- package/esm/core/services/settings.d.ts +29 -0
- package/esm/core/services/settings.js +123 -0
- package/esm/utils/file.d.ts +39 -0
- package/esm/utils/file.js +3 -4
- package/esm/utils/graph-ordering.d.ts +21 -0
- package/esm/utils/graph-ordering.js +0 -1
- package/esm/utils/normalized-name.d.ts +17 -0
- package/esm/utils/normalized-name.js +0 -1
- package/esm/workspace/component.d.ts +70 -0
- package/esm/workspace/component.js +0 -1
- package/esm/workspace/helpers/config-loader.d.ts +37 -0
- package/esm/workspace/helpers/config-loader.js +4 -5
- package/esm/workspace/helpers/create-manifests.d.ts +13 -0
- package/esm/workspace/helpers/create-manifests.js +1 -2
- package/esm/workspace/helpers/discover-workspace.d.ts +4 -0
- package/esm/workspace/helpers/discover-workspace.js +130 -134
- package/esm/workspace/helpers/lockfile.d.ts +5 -0
- package/esm/workspace/helpers/lockfile.js +0 -1
- package/esm/workspace/helpers/logger.d.ts +65 -0
- package/esm/workspace/helpers/logger.js +0 -1
- package/esm/workspace/helpers/package-npm.d.ts +1 -0
- package/esm/workspace/helpers/package-npm.js +0 -1
- package/esm/workspace/mod.d.ts +1 -0
- package/esm/workspace/mod.js +1 -0
- package/esm/workspace/packager.d.ts +5 -0
- package/esm/workspace/packager.js +1 -2
- package/esm/workspace/packagers/packager-standard.d.ts +7 -0
- package/esm/workspace/packagers/packager-standard.js +48 -24
- package/esm/workspace/storage.d.ts +59 -0
- package/esm/workspace/storage.js +19 -15
- package/esm/workspace/workspace.d.ts +161 -0
- package/esm/workspace/workspace.js +25 -17
- package/package.json +25 -18
- package/esm/commands/publish.js +0 -36
- package/esm/publish/publish_aws_s3.js +0 -67
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { getComponentFromData } from "../components/manifold.js";
|
|
2
|
+
export { print } from "./trace.js";
|
|
3
|
+
class ConsoleLog {
|
|
4
|
+
notifyError(error, target) {
|
|
5
|
+
console.error(error);
|
|
6
|
+
this.notifyObject(createLogFromError(error, target));
|
|
7
|
+
}
|
|
8
|
+
notifyObject(object) {
|
|
9
|
+
log_objects.push(object);
|
|
10
|
+
console.log(object);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const log_dispatchers = new Set();
|
|
14
|
+
const log_objects = [];
|
|
15
|
+
let log_object_ids = 0;
|
|
16
|
+
const default_log = new ConsoleLog();
|
|
17
|
+
registerLogCollector(default_log);
|
|
18
|
+
function generateLogId() {
|
|
19
|
+
log_object_ids++;
|
|
20
|
+
return 'id-' + Date.now().toString(36) + '-' + log_object_ids.toString(2);
|
|
21
|
+
}
|
|
22
|
+
export function registerLogCollector(collector) {
|
|
23
|
+
log_dispatchers.add(collector);
|
|
24
|
+
}
|
|
25
|
+
export function unregisterLogCollector(collector) {
|
|
26
|
+
log_dispatchers.delete(collector);
|
|
27
|
+
}
|
|
28
|
+
export function queryLogCount() {
|
|
29
|
+
return log_objects.length;
|
|
30
|
+
}
|
|
31
|
+
export function queryLogObjects(count, component_id) {
|
|
32
|
+
const objects = [];
|
|
33
|
+
for (const obj of log_objects) {
|
|
34
|
+
if (component_id === undefined || component_id === obj.component_id) {
|
|
35
|
+
if (objects.length >= count) {
|
|
36
|
+
return { objects, hasMore: true };
|
|
37
|
+
}
|
|
38
|
+
objects.push(obj);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return { objects, hasMore: false };
|
|
42
|
+
}
|
|
43
|
+
export function queryLogInfos(component_id) {
|
|
44
|
+
return log_objects.reduce((info, obj) => {
|
|
45
|
+
if (component_id === undefined || component_id === obj.component_id) {
|
|
46
|
+
switch (obj.status) {
|
|
47
|
+
case "error":
|
|
48
|
+
info.error_count++;
|
|
49
|
+
info.warn_count++;
|
|
50
|
+
info.notify_count++;
|
|
51
|
+
info.info_count++;
|
|
52
|
+
break;
|
|
53
|
+
case "warn":
|
|
54
|
+
info.warn_count++;
|
|
55
|
+
info.notify_count++;
|
|
56
|
+
info.info_count++;
|
|
57
|
+
break;
|
|
58
|
+
case "notify":
|
|
59
|
+
info.notify_count++;
|
|
60
|
+
info.info_count++;
|
|
61
|
+
break;
|
|
62
|
+
case "info":
|
|
63
|
+
info.info_count++;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return info;
|
|
68
|
+
}, {
|
|
69
|
+
action_expected_count: 0,
|
|
70
|
+
error_count: 0,
|
|
71
|
+
warn_count: 0,
|
|
72
|
+
notify_count: 0,
|
|
73
|
+
info_count: 0,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
export const Log = {
|
|
77
|
+
send(object) {
|
|
78
|
+
setTimeout(() => {
|
|
79
|
+
for (const collector of log_dispatchers) {
|
|
80
|
+
collector.notifyObject(object);
|
|
81
|
+
}
|
|
82
|
+
}, 0);
|
|
83
|
+
},
|
|
84
|
+
error(error, target) {
|
|
85
|
+
setTimeout(() => {
|
|
86
|
+
for (const collector of log_dispatchers) {
|
|
87
|
+
collector.notifyError(error, target);
|
|
88
|
+
}
|
|
89
|
+
}, 0);
|
|
90
|
+
},
|
|
91
|
+
event(target, options) {
|
|
92
|
+
const entry = getComponentFromData(target);
|
|
93
|
+
const id = generateLogId();
|
|
94
|
+
Log.send({
|
|
95
|
+
...options,
|
|
96
|
+
kind: "event",
|
|
97
|
+
status: options.status || "error",
|
|
98
|
+
message: options.message || `Issue with component: ${id}`,
|
|
99
|
+
component_id: entry.id,
|
|
100
|
+
id,
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
openTicket(target, name, options) {
|
|
104
|
+
const entry = getComponentFromData(target);
|
|
105
|
+
const id = `${entry.id}/${name}`;
|
|
106
|
+
Log.send({
|
|
107
|
+
...options,
|
|
108
|
+
kind: "ticket",
|
|
109
|
+
status: options.status || "error",
|
|
110
|
+
message: options.message || `Issue with component: ${id}`,
|
|
111
|
+
component_id: entry.id,
|
|
112
|
+
id,
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
closeTicket(target, name) {
|
|
116
|
+
const entry = getComponentFromData(target);
|
|
117
|
+
const id = `${entry.id}/${name}`;
|
|
118
|
+
const index = log_objects.findIndex(x => x.id === id);
|
|
119
|
+
if (index >= 0) {
|
|
120
|
+
const ticket = log_objects[index];
|
|
121
|
+
log_objects.splice(index, 1);
|
|
122
|
+
Log.event(target, {
|
|
123
|
+
...ticket,
|
|
124
|
+
kind: "event",
|
|
125
|
+
status: "info",
|
|
126
|
+
icon: "[success]bi:check-circle",
|
|
127
|
+
message: `[closed] ${ticket.message}`,
|
|
128
|
+
actions: undefined,
|
|
129
|
+
doc_uri: undefined,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
export function createLogFromError(error, target) {
|
|
135
|
+
return {
|
|
136
|
+
id: generateLogId(),
|
|
137
|
+
kind: "event",
|
|
138
|
+
status: "error",
|
|
139
|
+
component_id: getComponentFromData(target).id,
|
|
140
|
+
message: error.message,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export declare const originalConsole: {
|
|
2
|
+
assert(condition?: boolean, ...data: any[]): void;
|
|
3
|
+
assert(value: any, message?: string, ...optionalParams: any[]): void;
|
|
4
|
+
clear(): void;
|
|
5
|
+
clear(): void;
|
|
6
|
+
count(label?: string): void;
|
|
7
|
+
count(label?: string): void;
|
|
8
|
+
countReset(label?: string): void;
|
|
9
|
+
countReset(label?: string): void;
|
|
10
|
+
debug(...data: any[]): void;
|
|
11
|
+
debug(message?: any, ...optionalParams: any[]): void;
|
|
12
|
+
dir(item?: any, options?: any): void;
|
|
13
|
+
dir(obj: any, options?: import("util").InspectOptions): void;
|
|
14
|
+
dirxml(...data: any[]): void;
|
|
15
|
+
dirxml(...data: any[]): void;
|
|
16
|
+
error(...data: any[]): void;
|
|
17
|
+
error(message?: any, ...optionalParams: any[]): void;
|
|
18
|
+
group(...data: any[]): void;
|
|
19
|
+
group(...label: any[]): void;
|
|
20
|
+
groupCollapsed(...data: any[]): void;
|
|
21
|
+
groupCollapsed(...label: any[]): void;
|
|
22
|
+
groupEnd(): void;
|
|
23
|
+
groupEnd(): void;
|
|
24
|
+
info(...data: any[]): void;
|
|
25
|
+
info(message?: any, ...optionalParams: any[]): void;
|
|
26
|
+
log(...data: any[]): void;
|
|
27
|
+
log(message?: any, ...optionalParams: any[]): void;
|
|
28
|
+
table(tabularData?: any, properties?: string[]): void;
|
|
29
|
+
table(tabularData: any, properties?: readonly string[]): void;
|
|
30
|
+
time(label?: string): void;
|
|
31
|
+
time(label?: string): void;
|
|
32
|
+
timeEnd(label?: string): void;
|
|
33
|
+
timeEnd(label?: string): void;
|
|
34
|
+
timeLog(label?: string, ...data: any[]): void;
|
|
35
|
+
timeLog(label?: string, ...data: any[]): void;
|
|
36
|
+
timeStamp(label?: string): void;
|
|
37
|
+
timeStamp(label?: string): void;
|
|
38
|
+
trace(...data: any[]): void;
|
|
39
|
+
trace(message?: any, ...optionalParams: any[]): void;
|
|
40
|
+
warn(...data: any[]): void;
|
|
41
|
+
warn(message?: any, ...optionalParams: any[]): void;
|
|
42
|
+
Console: console.ConsoleConstructor;
|
|
43
|
+
profile(label?: string): void;
|
|
44
|
+
profileEnd(label?: string): void;
|
|
45
|
+
};
|
|
46
|
+
export declare const logError: (...args: any[]) => void;
|
|
47
|
+
export declare const logWarning: (...args: any[]) => void;
|
|
48
|
+
export declare const logInfo: (...args: any[]) => void;
|
|
49
|
+
export declare const logTrace: (...args: any[]) => void;
|
|
50
|
+
export declare const logDebug: (...args: any[]) => void;
|
|
51
|
+
export declare const print: Console;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const originalConsole = { ...console };
|
|
2
|
+
export const logError = console.error = (...args) => {
|
|
3
|
+
originalConsole.error(...args.map(arg => typeof arg === "string" ? `\x1b[31m${arg}\x1b[0m` : arg));
|
|
4
|
+
};
|
|
5
|
+
export const logWarning = console.warn = (...args) => {
|
|
6
|
+
originalConsole.warn(...args.map(arg => typeof arg === "string" ? `\x1b[35m${arg}\x1b[0m` : arg));
|
|
7
|
+
};
|
|
8
|
+
export const logInfo = console.info = (...args) => {
|
|
9
|
+
originalConsole.info(...args.map(arg => typeof arg === "string" ? `\x1b[36m${arg}\x1b[0m` : arg));
|
|
10
|
+
};
|
|
11
|
+
export const logTrace = console.trace = (...args) => {
|
|
12
|
+
originalConsole.trace(...args.map(arg => typeof arg === "string" ? `\x1b[34m${arg}\x1b[0m` : arg));
|
|
13
|
+
};
|
|
14
|
+
export const logDebug = console.debug = (...args) => {
|
|
15
|
+
originalConsole.debug(...args.map(arg => typeof arg === "string" ? `\x1b[32m${arg}\x1b[0m` : arg));
|
|
16
|
+
};
|
|
17
|
+
export const print = console;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./mod.ts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./mod.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./mod.ts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./mod.js";
|
package/esm/core/mod.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type JSONSchema } from "./schema.ts";
|
|
2
|
+
export declare const CommonTypes: {
|
|
3
|
+
boolean: JSONSchema;
|
|
4
|
+
string: JSONSchema;
|
|
5
|
+
number: JSONSchema;
|
|
6
|
+
object: JSONSchema;
|
|
7
|
+
view: JSONSchema;
|
|
8
|
+
display: JSONSchema;
|
|
9
|
+
function: JSONSchema;
|
|
10
|
+
null: JSONSchema;
|
|
11
|
+
unknown: JSONSchema;
|
|
12
|
+
any: JSONSchema;
|
|
13
|
+
};
|
|
14
|
+
export declare const CommonMakers: {
|
|
15
|
+
enums(base: JSONSchema, ...values: string[]): JSONSchema;
|
|
16
|
+
array(base: JSONSchema): JSONSchema;
|
|
17
|
+
record(fields: Record<string, JSONSchema>): JSONSchema;
|
|
18
|
+
collection(items: JSONSchema): JSONSchema;
|
|
19
|
+
event_fn(event?: JSONSchema): JSONSchema;
|
|
20
|
+
};
|
|
21
|
+
export declare const ErrorTypes: Record<string, JSONSchema>;
|
|
22
|
+
declare function getPropertyTyping(propertyName: string, schema: JSONSchema): JSONSchema;
|
|
23
|
+
declare function getItemTyping(index: number, schema: JSONSchema): JSONSchema;
|
|
24
|
+
declare function getValueTyping(value: any): JSONSchema;
|
|
25
|
+
declare function isType(typing: JSONSchema, kind: string): boolean;
|
|
26
|
+
declare function typeAsString(type: JSONSchema["type"]): string;
|
|
27
|
+
declare function generateTypescript(schema: JSONSchema): string;
|
|
28
|
+
export declare const Schema: {
|
|
29
|
+
getPropertyTyping: typeof getPropertyTyping;
|
|
30
|
+
getItemTyping: typeof getItemTyping;
|
|
31
|
+
getValueTyping: typeof getValueTyping;
|
|
32
|
+
isType: typeof isType;
|
|
33
|
+
typeAsString: typeof typeAsString;
|
|
34
|
+
generateTypescript: typeof generateTypescript;
|
|
35
|
+
};
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import {} from "./schema.js";
|
|
2
|
+
export const CommonTypes = {
|
|
3
|
+
boolean: {
|
|
4
|
+
type: "boolean"
|
|
5
|
+
},
|
|
6
|
+
string: {
|
|
7
|
+
type: "string"
|
|
8
|
+
},
|
|
9
|
+
number: {
|
|
10
|
+
type: "number"
|
|
11
|
+
},
|
|
12
|
+
object: {
|
|
13
|
+
type: "object"
|
|
14
|
+
},
|
|
15
|
+
view: {
|
|
16
|
+
type: "view"
|
|
17
|
+
},
|
|
18
|
+
display: {
|
|
19
|
+
type: "display"
|
|
20
|
+
},
|
|
21
|
+
function: {
|
|
22
|
+
type: "function"
|
|
23
|
+
},
|
|
24
|
+
null: {
|
|
25
|
+
type: "null"
|
|
26
|
+
},
|
|
27
|
+
unknown: {
|
|
28
|
+
type: "null"
|
|
29
|
+
},
|
|
30
|
+
any: {},
|
|
31
|
+
};
|
|
32
|
+
export const CommonMakers = {
|
|
33
|
+
enums(base, ...values) {
|
|
34
|
+
return { ...base, enum: values };
|
|
35
|
+
},
|
|
36
|
+
array(base) {
|
|
37
|
+
return { type: "array", items: base };
|
|
38
|
+
},
|
|
39
|
+
record(fields) {
|
|
40
|
+
return { type: "object", properties: fields };
|
|
41
|
+
},
|
|
42
|
+
collection(items) {
|
|
43
|
+
return { type: "object", additionalProperties: items };
|
|
44
|
+
},
|
|
45
|
+
event_fn(event) {
|
|
46
|
+
return { type: "function", args: [event || CommonTypes.any] };
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
export const ErrorTypes = {
|
|
50
|
+
invalid: {
|
|
51
|
+
$error: "Cannot determine the type"
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
function getPropertyTyping(propertyName, schema) {
|
|
55
|
+
if (!schema)
|
|
56
|
+
return ErrorTypes.invalid;
|
|
57
|
+
// Search as standard property
|
|
58
|
+
let typing = schema.properties?.[propertyName];
|
|
59
|
+
if (typing)
|
|
60
|
+
return typing;
|
|
61
|
+
// Search as pattern property
|
|
62
|
+
const { patternProperties } = schema;
|
|
63
|
+
for (const pattern in patternProperties) {
|
|
64
|
+
if (propertyName.match(pattern)) {
|
|
65
|
+
return patternProperties[pattern];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Check error
|
|
69
|
+
if (schema["$error"]) {
|
|
70
|
+
return ErrorTypes.invalid;
|
|
71
|
+
}
|
|
72
|
+
return schema.additionalProperties || CommonTypes.any;
|
|
73
|
+
}
|
|
74
|
+
function getItemTyping(index, schema) {
|
|
75
|
+
if (!schema)
|
|
76
|
+
return ErrorTypes.invalid;
|
|
77
|
+
// Search as standard property
|
|
78
|
+
if (Array.isArray(schema.items)) {
|
|
79
|
+
return schema.items?.[index] || ErrorTypes.invalid;
|
|
80
|
+
}
|
|
81
|
+
else if (schema.items) {
|
|
82
|
+
return schema.items;
|
|
83
|
+
}
|
|
84
|
+
else if (schema.type === "element") {
|
|
85
|
+
return schema;
|
|
86
|
+
}
|
|
87
|
+
// Check error
|
|
88
|
+
if (schema["$error"]) {
|
|
89
|
+
return ErrorTypes.invalid;
|
|
90
|
+
}
|
|
91
|
+
return schema.additionalProperties || CommonTypes.any;
|
|
92
|
+
}
|
|
93
|
+
function getValueTyping(value) {
|
|
94
|
+
switch (typeof value) {
|
|
95
|
+
case "undefined":
|
|
96
|
+
return CommonTypes.null;
|
|
97
|
+
case "boolean":
|
|
98
|
+
return CommonTypes.boolean;
|
|
99
|
+
case "symbol":
|
|
100
|
+
case "string":
|
|
101
|
+
return CommonTypes.string;
|
|
102
|
+
case "bigint":
|
|
103
|
+
case "number":
|
|
104
|
+
return CommonTypes.number;
|
|
105
|
+
case "function":
|
|
106
|
+
return CommonTypes.function;
|
|
107
|
+
case "object": {
|
|
108
|
+
if (Array.isArray(value)) {
|
|
109
|
+
return {
|
|
110
|
+
type: "array",
|
|
111
|
+
items: value.map(getValueTyping)
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
else if (value !== null) {
|
|
115
|
+
const properties = {};
|
|
116
|
+
for (const key in properties) {
|
|
117
|
+
properties[key] = getValueTyping(properties[key]);
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
type: "array",
|
|
121
|
+
properties,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
return CommonTypes.null;
|
|
125
|
+
}
|
|
126
|
+
default:
|
|
127
|
+
return ErrorTypes.invalid;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function isType(typing, kind) {
|
|
131
|
+
const { type } = typing;
|
|
132
|
+
return Array.isArray(type) ? type.includes(kind) : type === kind;
|
|
133
|
+
}
|
|
134
|
+
function typeAsString(type) {
|
|
135
|
+
return Array.isArray(type) ? type.join(',') : type;
|
|
136
|
+
}
|
|
137
|
+
function generateTypescript(schema) {
|
|
138
|
+
if (schema.type === "object") {
|
|
139
|
+
const ln = [];
|
|
140
|
+
for (const key in schema.properties) {
|
|
141
|
+
ln.push(`${key}: ${generateTypescript(schema.properties[key])}`);
|
|
142
|
+
}
|
|
143
|
+
for (const key in schema.additionalProperties) {
|
|
144
|
+
ln.push(`${key}?: ${generateTypescript(schema.additionalProperties[key])}`);
|
|
145
|
+
}
|
|
146
|
+
for (const key in schema.patternProperties) {
|
|
147
|
+
ln.push(`[${key}: ${generateTypescript(schema.patternProperties[key])}]`);
|
|
148
|
+
}
|
|
149
|
+
return ln.join("\n");
|
|
150
|
+
}
|
|
151
|
+
else if (schema.type) {
|
|
152
|
+
return schema.type;
|
|
153
|
+
}
|
|
154
|
+
return "any";
|
|
155
|
+
}
|
|
156
|
+
export const Schema = {
|
|
157
|
+
getPropertyTyping,
|
|
158
|
+
getItemTyping,
|
|
159
|
+
getValueTyping,
|
|
160
|
+
isType,
|
|
161
|
+
typeAsString,
|
|
162
|
+
generateTypescript,
|
|
163
|
+
};
|