@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
package/src/api-doc.ts
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
export interface ApiModule {
|
|
2
|
+
namespace: string;
|
|
3
|
+
brief: string;
|
|
4
|
+
description: string;
|
|
5
|
+
functions: ApiFunction[];
|
|
6
|
+
variables: ApiVariable[];
|
|
7
|
+
constants: ApiConstant[];
|
|
8
|
+
properties: ApiProperty[];
|
|
9
|
+
typedefs: ApiTypedef[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ApiProperty {
|
|
13
|
+
name: string;
|
|
14
|
+
types: string[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ApiTypedef {
|
|
18
|
+
name: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ApiConstant {
|
|
22
|
+
name: string;
|
|
23
|
+
brief: string;
|
|
24
|
+
description: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface ApiFunction {
|
|
28
|
+
name: string;
|
|
29
|
+
brief: string;
|
|
30
|
+
description: string;
|
|
31
|
+
parameters: ApiParameter[];
|
|
32
|
+
returnValues: ApiParameter[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ApiParameter {
|
|
36
|
+
name: string;
|
|
37
|
+
doc: string;
|
|
38
|
+
types: string[];
|
|
39
|
+
isOptional: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface ApiVariable {
|
|
43
|
+
name: string;
|
|
44
|
+
brief: string;
|
|
45
|
+
description: string;
|
|
46
|
+
types: string[];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function parseDefoldApiDoc(input: unknown): ApiModule {
|
|
50
|
+
if (!isRecord(input)) {
|
|
51
|
+
throw new Error(`parseDefoldApiDoc: expected object, got ${describeKind(input)}`);
|
|
52
|
+
}
|
|
53
|
+
const info = input.info;
|
|
54
|
+
if (!isRecord(info)) {
|
|
55
|
+
throw new Error(`parseDefoldApiDoc: missing or invalid "info" field`);
|
|
56
|
+
}
|
|
57
|
+
const namespace = info.namespace;
|
|
58
|
+
if (typeof namespace !== "string" || namespace.length === 0) {
|
|
59
|
+
throw new Error(`parseDefoldApiDoc: missing or invalid "info.namespace"`);
|
|
60
|
+
}
|
|
61
|
+
const brief = stringOr(info.brief, "");
|
|
62
|
+
const description = stringOr(info.description, "");
|
|
63
|
+
|
|
64
|
+
const rawElements = input.elements;
|
|
65
|
+
const elements = Array.isArray(rawElements) ? rawElements : [];
|
|
66
|
+
|
|
67
|
+
const functions: ApiFunction[] = [];
|
|
68
|
+
const variables: ApiVariable[] = [];
|
|
69
|
+
const constants: ApiConstant[] = [];
|
|
70
|
+
const properties: ApiProperty[] = [];
|
|
71
|
+
const typedefs: ApiTypedef[] = [];
|
|
72
|
+
|
|
73
|
+
for (const element of elements) {
|
|
74
|
+
if (!isRecord(element)) continue;
|
|
75
|
+
const type = element.type;
|
|
76
|
+
if (type === "FUNCTION") {
|
|
77
|
+
functions.push(parseFunction(element));
|
|
78
|
+
} else if (type === "VARIABLE") {
|
|
79
|
+
variables.push(parseVariable(element));
|
|
80
|
+
} else if (type === "CONSTANT") {
|
|
81
|
+
constants.push(parseConstant(element));
|
|
82
|
+
} else if (type === "PROPERTY") {
|
|
83
|
+
properties.push(parseProperty(element));
|
|
84
|
+
} else if (type === "TYPEDEF") {
|
|
85
|
+
typedefs.push({ name: stringOr(element.name, "") });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return { namespace, brief, description, functions, variables, constants, properties, typedefs };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function parseProperty(element: Record<string, unknown>): ApiProperty {
|
|
93
|
+
const brief = stringOr(element.brief, "");
|
|
94
|
+
const span = /<span class="type">([^<]+)<\/span>/.exec(brief);
|
|
95
|
+
const types =
|
|
96
|
+
span && span[1] !== undefined
|
|
97
|
+
? span[1]
|
|
98
|
+
.split("|")
|
|
99
|
+
.map((t) => t.trim())
|
|
100
|
+
.filter((t) => t.length > 0)
|
|
101
|
+
: [];
|
|
102
|
+
return { name: stringOr(element.name, ""), types };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function parseConstant(element: Record<string, unknown>): ApiConstant {
|
|
106
|
+
return {
|
|
107
|
+
name: stringOr(element.name, ""),
|
|
108
|
+
brief: stringOr(element.brief, ""),
|
|
109
|
+
description: stringOr(element.description, ""),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function parseFunction(element: Record<string, unknown>): ApiFunction {
|
|
114
|
+
return {
|
|
115
|
+
name: stringOr(element.name, ""),
|
|
116
|
+
brief: stringOr(element.brief, ""),
|
|
117
|
+
description: stringOr(element.description, ""),
|
|
118
|
+
parameters: parseParameterList(element.parameters),
|
|
119
|
+
returnValues: parseParameterList(element.returnvalues),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function parseVariable(element: Record<string, unknown>): ApiVariable {
|
|
124
|
+
return {
|
|
125
|
+
name: stringOr(element.name, ""),
|
|
126
|
+
brief: stringOr(element.brief, ""),
|
|
127
|
+
description: stringOr(element.description, ""),
|
|
128
|
+
types: parseStringArray(element.types),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function parseParameterList(raw: unknown): ApiParameter[] {
|
|
133
|
+
if (!Array.isArray(raw)) return [];
|
|
134
|
+
const out: ApiParameter[] = [];
|
|
135
|
+
for (const item of raw) {
|
|
136
|
+
if (!isRecord(item)) continue;
|
|
137
|
+
out.push({
|
|
138
|
+
name: stringOr(item.name, ""),
|
|
139
|
+
doc: stringOr(item.doc, ""),
|
|
140
|
+
types: parseStringArray(item.types),
|
|
141
|
+
isOptional: item.is_optional === "True",
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
return out;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function parseStringArray(raw: unknown): string[] {
|
|
148
|
+
if (!Array.isArray(raw)) return [];
|
|
149
|
+
const out: string[] = [];
|
|
150
|
+
for (const item of raw) {
|
|
151
|
+
if (typeof item === "string") out.push(item);
|
|
152
|
+
}
|
|
153
|
+
return out;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
157
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function stringOr(value: unknown, fallback: string): string {
|
|
161
|
+
return typeof value === "string" ? value : fallback;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function describeKind(value: unknown): string {
|
|
165
|
+
if (value === null) return "null";
|
|
166
|
+
if (Array.isArray(value)) return "array";
|
|
167
|
+
return typeof value;
|
|
168
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/// <reference types="@typescript-to-lua/language-extensions" />
|
|
2
|
+
|
|
3
|
+
export interface Vector {
|
|
4
|
+
readonly [index: number]: number;
|
|
5
|
+
readonly length: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface Vector3 {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
z: number;
|
|
12
|
+
add: LuaAdditionMethod<Vector3, Vector3>;
|
|
13
|
+
sub: LuaSubtractionMethod<Vector3, Vector3>;
|
|
14
|
+
mul: LuaMultiplicationMethod<number, Vector3>;
|
|
15
|
+
div: LuaDivisionMethod<number, Vector3>;
|
|
16
|
+
/**
|
|
17
|
+
* @remarks
|
|
18
|
+
* Prefer `v.unm()` over `-v` — TypeScript does not flag unary `-` on object
|
|
19
|
+
* types and silently produces `number`. See
|
|
20
|
+
* `docs/guide/typescript-gotchas.md` for the full story.
|
|
21
|
+
*/
|
|
22
|
+
unm: LuaNegationMethod<Vector3>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface Vector4 {
|
|
26
|
+
x: number;
|
|
27
|
+
y: number;
|
|
28
|
+
z: number;
|
|
29
|
+
w: number;
|
|
30
|
+
add: LuaAdditionMethod<Vector4, Vector4>;
|
|
31
|
+
sub: LuaSubtractionMethod<Vector4, Vector4>;
|
|
32
|
+
mul: LuaMultiplicationMethod<number, Vector4>;
|
|
33
|
+
div: LuaDivisionMethod<number, Vector4>;
|
|
34
|
+
/**
|
|
35
|
+
* @remarks
|
|
36
|
+
* Prefer `v.unm()` over `-v` — TypeScript does not flag unary `-` on object
|
|
37
|
+
* types and silently produces `number`. See
|
|
38
|
+
* `docs/guide/typescript-gotchas.md` for the full story.
|
|
39
|
+
*/
|
|
40
|
+
unm: LuaNegationMethod<Vector4>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface Quaternion {
|
|
44
|
+
x: number;
|
|
45
|
+
y: number;
|
|
46
|
+
z: number;
|
|
47
|
+
w: number;
|
|
48
|
+
mul: LuaMultiplicationMethod<Quaternion, Quaternion>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface Matrix4 {
|
|
52
|
+
m00: number;
|
|
53
|
+
m01: number;
|
|
54
|
+
m02: number;
|
|
55
|
+
m03: number;
|
|
56
|
+
m10: number;
|
|
57
|
+
m11: number;
|
|
58
|
+
m12: number;
|
|
59
|
+
m13: number;
|
|
60
|
+
m20: number;
|
|
61
|
+
m21: number;
|
|
62
|
+
m22: number;
|
|
63
|
+
m23: number;
|
|
64
|
+
m30: number;
|
|
65
|
+
m31: number;
|
|
66
|
+
m32: number;
|
|
67
|
+
m33: number;
|
|
68
|
+
c0: Vector4;
|
|
69
|
+
c1: Vector4;
|
|
70
|
+
c2: Vector4;
|
|
71
|
+
c3: Vector4;
|
|
72
|
+
mul: LuaMultiplicationMethod<Matrix4, Matrix4> & LuaMultiplicationMethod<Vector4, Vector4>;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
declare const HashBrand: unique symbol;
|
|
76
|
+
export interface Hash {
|
|
77
|
+
readonly [HashBrand]: "Hash";
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
declare const OpaqueBrand: unique symbol;
|
|
81
|
+
export interface Opaque<Name extends string> {
|
|
82
|
+
readonly [OpaqueBrand]: Name;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface Url {
|
|
86
|
+
readonly socket: Hash;
|
|
87
|
+
readonly path: Hash;
|
|
88
|
+
readonly fragment: Hash | undefined;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export const DEFOLD_TYPE_MAP: Readonly<Record<string, string>> = {
|
|
92
|
+
number: "number",
|
|
93
|
+
int: "number",
|
|
94
|
+
integer: "number",
|
|
95
|
+
string: "string",
|
|
96
|
+
boolean: "boolean",
|
|
97
|
+
table: "Record<string | number, unknown>",
|
|
98
|
+
function: "(...args: unknown[]) => unknown",
|
|
99
|
+
vector: "Vector",
|
|
100
|
+
vector3: "Vector3",
|
|
101
|
+
vector4: "Vector4",
|
|
102
|
+
quaternion: "Quaternion",
|
|
103
|
+
matrix4: "Matrix4",
|
|
104
|
+
hash: "Hash",
|
|
105
|
+
url: "Url",
|
|
106
|
+
node: 'Opaque<"node">',
|
|
107
|
+
texture: 'Opaque<"texture">',
|
|
108
|
+
render_target: 'Opaque<"render_target">',
|
|
109
|
+
constant: 'Opaque<"constant">',
|
|
110
|
+
constant_buffer: 'Opaque<"constant_buffer">',
|
|
111
|
+
buffer: 'Opaque<"buffer">',
|
|
112
|
+
bufferstream: 'Opaque<"bufferstream">',
|
|
113
|
+
userdata: 'Opaque<"userdata">',
|
|
114
|
+
resource: 'Opaque<"resource">',
|
|
115
|
+
b2World: 'Opaque<"b2World">',
|
|
116
|
+
b2Body: 'Opaque<"b2Body">',
|
|
117
|
+
client: 'Opaque<"client">',
|
|
118
|
+
master: 'Opaque<"master">',
|
|
119
|
+
unconnected: 'Opaque<"unconnected">',
|
|
120
|
+
any: "unknown",
|
|
121
|
+
} as const;
|