@defold-typescript/types 0.17.1 → 0.18.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/api-doc.ts +37 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defold-typescript/types",
3
- "version": "0.17.1",
3
+ "version": "0.18.1",
4
4
  "description": "TypeScript types for the Defold engine's Lua APIs.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/api-doc.ts CHANGED
@@ -18,6 +18,8 @@ export interface ApiProperty {
18
18
 
19
19
  export interface ApiTypedef {
20
20
  name: string;
21
+ functions?: ApiFunction[];
22
+ properties?: ApiVariable[];
21
23
  }
22
24
 
23
25
  export interface ApiConstant {
@@ -40,6 +42,11 @@ export interface ApiParameter {
40
42
  doc: string;
41
43
  types: string[];
42
44
  isOptional: boolean;
45
+ /**
46
+ * Per-member docs for an object-literal type, extracted as a tree alongside
47
+ * the flat `types` token (never inside it). Absent for plain-typed params.
48
+ */
49
+ fields?: ApiParameter[];
43
50
  }
44
51
 
45
52
  export interface ApiVariable {
@@ -85,13 +92,23 @@ export function parseDefoldApiDoc(input: unknown): ApiModule {
85
92
  } else if (type === "PROPERTY") {
86
93
  properties.push(parseProperty(element));
87
94
  } else if (type === "TYPEDEF") {
88
- typedefs.push({ name: stringOr(element.name, "") });
95
+ typedefs.push(parseTypedef(element));
89
96
  }
90
97
  }
91
98
 
92
99
  return { namespace, brief, description, functions, variables, constants, properties, typedefs };
93
100
  }
94
101
 
102
+ function parseTypedef(element: Record<string, unknown>): ApiTypedef {
103
+ const functions = parseFunctionList(element.functions);
104
+ const properties = parseVariableList(element.properties);
105
+ return {
106
+ name: stringOr(element.name, ""),
107
+ ...(functions.length > 0 ? { functions } : {}),
108
+ ...(properties.length > 0 ? { properties } : {}),
109
+ };
110
+ }
111
+
95
112
  function parseProperty(element: Record<string, unknown>): ApiProperty {
96
113
  const brief = stringOr(element.brief, "");
97
114
  const span = /<span class="type">([^<]+)<\/span>/.exec(brief);
@@ -138,6 +155,24 @@ function parseVariable(element: Record<string, unknown>): ApiVariable {
138
155
  };
139
156
  }
140
157
 
158
+ function parseFunctionList(raw: unknown): ApiFunction[] {
159
+ if (!Array.isArray(raw)) return [];
160
+ const out: ApiFunction[] = [];
161
+ for (const item of raw) {
162
+ if (isRecord(item)) out.push(parseFunction(item));
163
+ }
164
+ return out;
165
+ }
166
+
167
+ function parseVariableList(raw: unknown): ApiVariable[] {
168
+ if (!Array.isArray(raw)) return [];
169
+ const out: ApiVariable[] = [];
170
+ for (const item of raw) {
171
+ if (isRecord(item)) out.push(parseVariable(item));
172
+ }
173
+ return out;
174
+ }
175
+
141
176
  function parseParameterList(raw: unknown): ApiParameter[] {
142
177
  if (!Array.isArray(raw)) return [];
143
178
  const out: ApiParameter[] = [];
@@ -148,6 +183,7 @@ function parseParameterList(raw: unknown): ApiParameter[] {
148
183
  doc: stringOr(item.doc, ""),
149
184
  types: parseStringArray(item.types),
150
185
  isOptional: item.is_optional === "True",
186
+ ...(Array.isArray(item.fields) ? { fields: parseParameterList(item.fields) } : {}),
151
187
  });
152
188
  }
153
189
  return out;