@defold-typescript/types 0.1.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/api-targets.json +84 -0
- package/generated/b2d.d.ts +13 -0
- package/generated/buffer.d.ts +25 -0
- package/generated/builtin-messages.d.ts +42 -0
- package/generated/camera.d.ts +7 -0
- package/generated/collectionfactory.d.ts +17 -0
- package/generated/collectionproxy.d.ts +14 -0
- package/generated/crash.d.ts +31 -0
- package/generated/factory.d.ts +17 -0
- package/generated/go.d.ts +96 -0
- package/generated/graphics.d.ts +115 -0
- package/generated/gui.d.ts +245 -0
- package/generated/http.d.ts +8 -0
- package/generated/iac.d.ts +8 -0
- package/generated/iap.d.ts +16 -0
- package/generated/image.d.ts +16 -0
- package/generated/json.d.ts +11 -0
- package/generated/kinds/gui-script.d.ts +39 -0
- package/generated/kinds/render-script.d.ts +39 -0
- package/generated/kinds/script.d.ts +38 -0
- package/generated/label.d.ts +23 -0
- package/generated/liveupdate.d.ts +23 -0
- package/generated/model.d.ts +23 -0
- package/generated/msg.d.ts +12 -0
- package/generated/particlefx.d.ts +22 -0
- package/generated/physics.d.ts +47 -0
- package/generated/profiler.d.ts +28 -0
- package/generated/push.d.ts +15 -0
- package/generated/render.d.ts +55 -0
- package/generated/resource.d.ts +33 -0
- package/generated/socket.d.ts +25 -0
- package/generated/sound.d.ts +28 -0
- package/generated/sprite.d.ts +23 -0
- package/generated/sys.d.ts +37 -0
- package/generated/tilemap.d.ts +24 -0
- package/generated/timer.d.ts +12 -0
- package/generated/vmath.d.ts +63 -0
- package/generated/webview.d.ts +15 -0
- package/generated/window.d.ts +28 -0
- package/generated/zlib.d.ts +9 -0
- package/index.d.ts +63 -0
- package/package.json +46 -0
- package/scripts/doc-source.ts +100 -0
- package/scripts/fidelity-audit.ts +311 -0
- package/scripts/fidelity-baseline.json +282 -0
- package/scripts/materialize-version.ts +51 -0
- package/scripts/regen.ts +294 -0
- package/scripts/sync-api-docs.ts +375 -0
- package/src/api-doc.ts +168 -0
- package/src/core-types.ts +121 -0
- package/src/emit-dts.ts +754 -0
- package/src/emit-messages.ts +148 -0
- package/src/go-overloads.d.ts +35 -0
- package/src/index.ts +24 -0
- package/src/lifecycle.ts +81 -0
- package/src/msg-overloads.d.ts +21 -0
- package/src/publish-dts.ts +33 -0
- package/src/script-api.ts +95 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { DEFOLD_TYPE_MAP } from "./core-types";
|
|
2
|
+
|
|
3
|
+
export interface MessageField {
|
|
4
|
+
name: string;
|
|
5
|
+
types: string[];
|
|
6
|
+
optional: boolean;
|
|
7
|
+
doc: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface MessageEntry {
|
|
11
|
+
name: string;
|
|
12
|
+
origin: string;
|
|
13
|
+
description: string;
|
|
14
|
+
payload: MessageField[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface MessageCatalog {
|
|
18
|
+
entries: MessageEntry[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const TS_IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
22
|
+
const ENGINE_TYPES = [
|
|
23
|
+
"Hash",
|
|
24
|
+
"Matrix4",
|
|
25
|
+
"Quaternion",
|
|
26
|
+
"Url",
|
|
27
|
+
"Vector",
|
|
28
|
+
"Vector3",
|
|
29
|
+
"Vector4",
|
|
30
|
+
] as const;
|
|
31
|
+
|
|
32
|
+
export function parseMessagesDoc(raw: unknown): MessageCatalog {
|
|
33
|
+
if (!isRecord(raw)) {
|
|
34
|
+
throw new Error(`parseMessagesDoc: expected object, got ${describeKind(raw)}`);
|
|
35
|
+
}
|
|
36
|
+
const rawMessages = raw.messages;
|
|
37
|
+
if (!Array.isArray(rawMessages)) {
|
|
38
|
+
throw new Error(`parseMessagesDoc: missing or invalid "messages" array`);
|
|
39
|
+
}
|
|
40
|
+
const entries: MessageEntry[] = [];
|
|
41
|
+
for (const item of rawMessages) {
|
|
42
|
+
if (!isRecord(item)) continue;
|
|
43
|
+
const name = stringOr(item.name, "");
|
|
44
|
+
if (name === "") continue;
|
|
45
|
+
entries.push({
|
|
46
|
+
name,
|
|
47
|
+
origin: stringOr(item.origin, ""),
|
|
48
|
+
description: stringOr(item.description, ""),
|
|
49
|
+
payload: parsePayload(item.payload),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return { entries };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function parsePayload(raw: unknown): MessageField[] {
|
|
56
|
+
if (!Array.isArray(raw)) return [];
|
|
57
|
+
const fields: MessageField[] = [];
|
|
58
|
+
for (const item of raw) {
|
|
59
|
+
if (!isRecord(item)) continue;
|
|
60
|
+
const name = stringOr(item.name, "");
|
|
61
|
+
if (name === "") continue;
|
|
62
|
+
const typesRaw = item.types;
|
|
63
|
+
const types = Array.isArray(typesRaw)
|
|
64
|
+
? typesRaw.filter((t): t is string => typeof t === "string")
|
|
65
|
+
: [];
|
|
66
|
+
fields.push({
|
|
67
|
+
name,
|
|
68
|
+
types,
|
|
69
|
+
optional: item.optional === true,
|
|
70
|
+
doc: stringOr(item.doc, ""),
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return fields;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function emitBuiltinMessages(catalog: MessageCatalog): string {
|
|
77
|
+
const entries = [...catalog.entries].sort((a, b) => a.name.localeCompare(b.name));
|
|
78
|
+
const body = entries.map(emitEntry).join("\n");
|
|
79
|
+
const inner = [
|
|
80
|
+
"declare global {",
|
|
81
|
+
" interface BuiltinMessages {",
|
|
82
|
+
body,
|
|
83
|
+
" }",
|
|
84
|
+
" type BuiltinMessageId = keyof BuiltinMessages;",
|
|
85
|
+
"}",
|
|
86
|
+
"",
|
|
87
|
+
"export {};",
|
|
88
|
+
"",
|
|
89
|
+
].join("\n");
|
|
90
|
+
const used = collectEngineTypes(inner);
|
|
91
|
+
const importLine =
|
|
92
|
+
used.length === 0 ? "" : `import type { ${used.join(", ")} } from "../src/core-types";\n\n`;
|
|
93
|
+
return `${importLine}${inner}`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function emitEntry(entry: MessageEntry): string {
|
|
97
|
+
const key = TS_IDENTIFIER.test(entry.name) ? entry.name : JSON.stringify(entry.name);
|
|
98
|
+
if (entry.payload.length === 0) {
|
|
99
|
+
return ` ${key}: Record<string, never>;`;
|
|
100
|
+
}
|
|
101
|
+
const fields = entry.payload.map(emitField).join("; ");
|
|
102
|
+
return ` ${key}: { ${fields} };`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function emitField(field: MessageField): string {
|
|
106
|
+
const name = TS_IDENTIFIER.test(field.name) ? field.name : JSON.stringify(field.name);
|
|
107
|
+
const optional = field.optional ? "?" : "";
|
|
108
|
+
const ts = field.types.length === 0 ? "unknown" : unionFromTokens(field.types);
|
|
109
|
+
return `${name}${optional}: ${ts}`;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function unionFromTokens(tokens: readonly string[]): string {
|
|
113
|
+
const seen = new Set<string>();
|
|
114
|
+
const mapped: string[] = [];
|
|
115
|
+
for (const token of tokens) {
|
|
116
|
+
const ts = mapToken(token);
|
|
117
|
+
if (seen.has(ts)) continue;
|
|
118
|
+
seen.add(ts);
|
|
119
|
+
mapped.push(ts);
|
|
120
|
+
}
|
|
121
|
+
return mapped.join(" | ");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function mapToken(token: string): string {
|
|
125
|
+
if (Object.hasOwn(DEFOLD_TYPE_MAP, token)) {
|
|
126
|
+
const mapped = DEFOLD_TYPE_MAP[token];
|
|
127
|
+
if (typeof mapped === "string") return mapped;
|
|
128
|
+
}
|
|
129
|
+
return token;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function collectEngineTypes(emitted: string): string[] {
|
|
133
|
+
return ENGINE_TYPES.filter((t) => new RegExp(`\\b${t}\\b`).test(emitted));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
137
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function stringOr(value: unknown, fallback: string): string {
|
|
141
|
+
return typeof value === "string" ? value : fallback;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function describeKind(value: unknown): string {
|
|
145
|
+
if (value === null) return "null";
|
|
146
|
+
if (Array.isArray(value)) return "array";
|
|
147
|
+
return typeof value;
|
|
148
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** @noSelfInFile */
|
|
2
|
+
import type { Hash, Opaque, Quaternion, Url, Vector3, Vector4 } from "./core-types";
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
namespace go {
|
|
6
|
+
interface GoPropertyOptions {
|
|
7
|
+
index?: number;
|
|
8
|
+
key?: Hash;
|
|
9
|
+
keys?: Record<string | number, unknown>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function get<K extends keyof go.properties>(
|
|
13
|
+
url: string | Hash | Url,
|
|
14
|
+
property: K,
|
|
15
|
+
options?: GoPropertyOptions,
|
|
16
|
+
): go.properties[K];
|
|
17
|
+
function get(
|
|
18
|
+
url: string | Hash | Url,
|
|
19
|
+
property: string | Hash,
|
|
20
|
+
options?: GoPropertyOptions,
|
|
21
|
+
): number | boolean | Hash | Url | Vector3 | Vector4 | Quaternion | Opaque<"resource">;
|
|
22
|
+
function set<K extends keyof go.properties>(
|
|
23
|
+
url: string | Hash | Url,
|
|
24
|
+
property: K,
|
|
25
|
+
value: go.properties[K],
|
|
26
|
+
options?: GoPropertyOptions,
|
|
27
|
+
): void;
|
|
28
|
+
function set(
|
|
29
|
+
url: string | Hash | Url,
|
|
30
|
+
property: string | Hash,
|
|
31
|
+
value: number | boolean | Hash | Url | Vector3 | Vector4 | Quaternion | Opaque<"resource">,
|
|
32
|
+
options?: GoPropertyOptions,
|
|
33
|
+
): void;
|
|
34
|
+
}
|
|
35
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type { ApiFunction, ApiModule, ApiParameter, ApiVariable } from "./api-doc";
|
|
2
|
+
export { parseDefoldApiDoc } from "./api-doc";
|
|
3
|
+
export {
|
|
4
|
+
DEFOLD_TYPE_MAP,
|
|
5
|
+
type Hash,
|
|
6
|
+
type Matrix4,
|
|
7
|
+
type Quaternion,
|
|
8
|
+
type Url,
|
|
9
|
+
type Vector,
|
|
10
|
+
type Vector3,
|
|
11
|
+
type Vector4,
|
|
12
|
+
} from "./core-types";
|
|
13
|
+
export { type EmitOptions, emitDeclarations } from "./emit-dts";
|
|
14
|
+
export {
|
|
15
|
+
defineGuiScript,
|
|
16
|
+
defineRenderScript,
|
|
17
|
+
defineScript,
|
|
18
|
+
type GuiScriptHooks,
|
|
19
|
+
type InputAction,
|
|
20
|
+
type InputTouch,
|
|
21
|
+
type RenderScriptHooks,
|
|
22
|
+
type ScriptHooks,
|
|
23
|
+
} from "./lifecycle";
|
|
24
|
+
export { type WrapOptions, wrapAsAmbientGlobal } from "./publish-dts";
|
package/src/lifecycle.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { Hash, Url } from "./core-types";
|
|
2
|
+
|
|
3
|
+
type OnMessagePayload<K> = K extends BuiltinMessageId
|
|
4
|
+
? BuiltinMessages[K]
|
|
5
|
+
: Record<string | number, unknown>;
|
|
6
|
+
|
|
7
|
+
export interface InputTouch {
|
|
8
|
+
id?: number;
|
|
9
|
+
pressed?: boolean;
|
|
10
|
+
released?: boolean;
|
|
11
|
+
tap_count?: number;
|
|
12
|
+
x?: number;
|
|
13
|
+
y?: number;
|
|
14
|
+
dx?: number;
|
|
15
|
+
dy?: number;
|
|
16
|
+
acc_x?: number;
|
|
17
|
+
acc_y?: number;
|
|
18
|
+
acc_z?: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface InputAction {
|
|
22
|
+
value?: number;
|
|
23
|
+
pressed?: boolean;
|
|
24
|
+
released?: boolean;
|
|
25
|
+
repeated?: boolean;
|
|
26
|
+
x?: number;
|
|
27
|
+
y?: number;
|
|
28
|
+
screen_x?: number;
|
|
29
|
+
screen_y?: number;
|
|
30
|
+
dx?: number;
|
|
31
|
+
dy?: number;
|
|
32
|
+
screen_dx?: number;
|
|
33
|
+
screen_dy?: number;
|
|
34
|
+
gamepad?: number;
|
|
35
|
+
userid?: number;
|
|
36
|
+
gamepad_unknown?: boolean;
|
|
37
|
+
gamepad_name?: string;
|
|
38
|
+
gamepad_axis?: number[];
|
|
39
|
+
gamepadhats?: number[];
|
|
40
|
+
gamepad_buttons?: number[];
|
|
41
|
+
touch?: InputTouch[];
|
|
42
|
+
text?: string;
|
|
43
|
+
marked_text?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface ScriptHooks<TSelf> {
|
|
47
|
+
init?(self: TSelf): void;
|
|
48
|
+
update?(self: TSelf, dt: number): void;
|
|
49
|
+
on_message?<K extends string>(
|
|
50
|
+
self: TSelf,
|
|
51
|
+
message_id: K,
|
|
52
|
+
message: OnMessagePayload<K>,
|
|
53
|
+
sender: Url,
|
|
54
|
+
): void;
|
|
55
|
+
on_input?(
|
|
56
|
+
self: TSelf,
|
|
57
|
+
action_id: Hash | undefined,
|
|
58
|
+
action: InputAction,
|
|
59
|
+
// biome-ignore lint/suspicious/noConfusingVoidType: Defold lets handlers omit the return; `void` is the right shape for "may return boolean or nothing".
|
|
60
|
+
): boolean | void;
|
|
61
|
+
final?(self: TSelf): void;
|
|
62
|
+
on_reload?(self: TSelf): void;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type GuiScriptHooks<TSelf> = ScriptHooks<TSelf>;
|
|
66
|
+
|
|
67
|
+
export type RenderScriptHooks<TSelf> = Omit<ScriptHooks<TSelf>, "on_input">;
|
|
68
|
+
|
|
69
|
+
export function defineScript<TSelf>(hooks: ScriptHooks<TSelf>): ScriptHooks<TSelf> {
|
|
70
|
+
return hooks;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function defineGuiScript<TSelf>(hooks: GuiScriptHooks<TSelf>): GuiScriptHooks<TSelf> {
|
|
74
|
+
return hooks;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function defineRenderScript<TSelf>(
|
|
78
|
+
hooks: RenderScriptHooks<TSelf>,
|
|
79
|
+
): RenderScriptHooks<TSelf> {
|
|
80
|
+
return hooks;
|
|
81
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** @noSelfInFile */
|
|
2
|
+
import type { Hash, Url } from "./core-types";
|
|
3
|
+
|
|
4
|
+
type MsgPostPayload<K> = K extends BuiltinMessageId
|
|
5
|
+
? BuiltinMessages[K]
|
|
6
|
+
: Record<string | number, unknown>;
|
|
7
|
+
|
|
8
|
+
declare global {
|
|
9
|
+
namespace msg {
|
|
10
|
+
function post<K extends string>(
|
|
11
|
+
receiver: string | Url | Hash,
|
|
12
|
+
message_id: K,
|
|
13
|
+
message?: MsgPostPayload<K>,
|
|
14
|
+
): void;
|
|
15
|
+
function post(
|
|
16
|
+
receiver: string | Url | Hash,
|
|
17
|
+
message_id: Hash,
|
|
18
|
+
message?: Record<string | number, unknown>,
|
|
19
|
+
): void;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const ENGINE_TYPES = [
|
|
2
|
+
"Hash",
|
|
3
|
+
"Matrix4",
|
|
4
|
+
"Opaque",
|
|
5
|
+
"Quaternion",
|
|
6
|
+
"Url",
|
|
7
|
+
"Vector",
|
|
8
|
+
"Vector3",
|
|
9
|
+
"Vector4",
|
|
10
|
+
] as const;
|
|
11
|
+
type EngineType = (typeof ENGINE_TYPES)[number];
|
|
12
|
+
|
|
13
|
+
export interface WrapOptions {
|
|
14
|
+
namespace: string;
|
|
15
|
+
emitted: string;
|
|
16
|
+
importsFrom: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function wrapAsAmbientGlobal(opts: WrapOptions): string {
|
|
20
|
+
const used = collectEngineTypes(opts.emitted);
|
|
21
|
+
const importLine =
|
|
22
|
+
used.length === 0 ? "" : `import type { ${used.join(", ")} } from "${opts.importsFrom}";\n\n`;
|
|
23
|
+
const inner = opts.emitted.replace(/^declare\s+namespace\s+/, "namespace ").trimEnd();
|
|
24
|
+
const indented = inner
|
|
25
|
+
.split("\n")
|
|
26
|
+
.map((l) => (l.length === 0 ? l : ` ${l}`))
|
|
27
|
+
.join("\n");
|
|
28
|
+
return `/** @noSelfInFile */\n${importLine}declare global {\n${indented}\n}\n\nexport {};\n`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function collectEngineTypes(emitted: string): EngineType[] {
|
|
32
|
+
return ENGINE_TYPES.filter((t) => new RegExp(`\\b${t}\\b`).test(emitted));
|
|
33
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { parse } from "yaml";
|
|
2
|
+
|
|
3
|
+
export interface RefDocParameter {
|
|
4
|
+
name: string;
|
|
5
|
+
doc: string;
|
|
6
|
+
types: string[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface RefDocElement {
|
|
10
|
+
type: "FUNCTION";
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
parameters: RefDocParameter[];
|
|
14
|
+
returnvalues: RefDocParameter[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface RefDoc {
|
|
18
|
+
info: { namespace: string; brief: string; description: string };
|
|
19
|
+
elements: RefDocElement[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
23
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function stringOr(value: unknown, fallback: string): string {
|
|
27
|
+
return typeof value === "string" ? value : fallback;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function mapParameters(raw: unknown): RefDocParameter[] {
|
|
31
|
+
if (!Array.isArray(raw)) return [];
|
|
32
|
+
const out: RefDocParameter[] = [];
|
|
33
|
+
for (const item of raw) {
|
|
34
|
+
if (!isRecord(item)) continue;
|
|
35
|
+
const name = stringOr(item.name, "");
|
|
36
|
+
// The script_api lists the implicit `self` the engine passes; the emitter
|
|
37
|
+
// stamps @noSelfInFile, so generated signatures must not declare it.
|
|
38
|
+
if (name === "self") continue;
|
|
39
|
+
const type = item.type;
|
|
40
|
+
out.push({
|
|
41
|
+
name,
|
|
42
|
+
doc: stringOr(item.desc, ""),
|
|
43
|
+
types: typeof type === "string" ? [type] : [],
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Convert a parsed Defold extension `.script_api` document into the core
|
|
51
|
+
* ref-doc JSON object shape that `parseDefoldApiDoc` consumes. Only
|
|
52
|
+
* `type: function` members are carried; scalar members (constants) are
|
|
53
|
+
* dropped, matching the core ref-doc pipeline where non-function elements
|
|
54
|
+
* never reach the emitter.
|
|
55
|
+
*/
|
|
56
|
+
export function scriptApiToRefDoc(parsed: unknown): RefDoc {
|
|
57
|
+
if (!Array.isArray(parsed)) {
|
|
58
|
+
throw new Error("scriptApiToRefDoc: expected a top-level YAML list");
|
|
59
|
+
}
|
|
60
|
+
const tables = parsed.filter(
|
|
61
|
+
(e): e is Record<string, unknown> => isRecord(e) && e.type === "table",
|
|
62
|
+
);
|
|
63
|
+
if (tables.length === 0) {
|
|
64
|
+
throw new Error("scriptApiToRefDoc: no top-level `type: table` namespace entry found");
|
|
65
|
+
}
|
|
66
|
+
if (tables.length > 1) {
|
|
67
|
+
throw new Error("scriptApiToRefDoc: expected exactly one top-level table, found multiple");
|
|
68
|
+
}
|
|
69
|
+
const table = tables[0] as Record<string, unknown>;
|
|
70
|
+
const namespace = stringOr(table.name, "");
|
|
71
|
+
if (namespace.length === 0) {
|
|
72
|
+
throw new Error("scriptApiToRefDoc: top-level table is missing a `name`");
|
|
73
|
+
}
|
|
74
|
+
const members = Array.isArray(table.members) ? table.members : [];
|
|
75
|
+
const elements: RefDocElement[] = [];
|
|
76
|
+
for (const member of members) {
|
|
77
|
+
if (!isRecord(member) || member.type !== "function") continue;
|
|
78
|
+
elements.push({
|
|
79
|
+
type: "FUNCTION",
|
|
80
|
+
name: `${namespace}.${stringOr(member.name, "")}`,
|
|
81
|
+
description: stringOr(member.desc, ""),
|
|
82
|
+
parameters: mapParameters(member.parameters),
|
|
83
|
+
returnvalues: mapParameters(member.returns),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
const doc: RefDoc = {
|
|
87
|
+
info: { namespace, brief: stringOr(table.desc, ""), description: stringOr(table.desc, "") },
|
|
88
|
+
elements,
|
|
89
|
+
};
|
|
90
|
+
return doc;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function parseScriptApi(yamlText: string): RefDoc {
|
|
94
|
+
return scriptApiToRefDoc(parse(yamlText));
|
|
95
|
+
}
|