@defold-typescript/types 0.23.0 → 0.25.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.
Files changed (38) hide show
  1. package/api-signatures.json +44 -44
  2. package/api-targets.json +57 -0
  3. package/generated/editor-vm/http.d.ts +56 -0
  4. package/generated/editor-vm/json.d.ts +10 -0
  5. package/generated/editor-vm/localization.d.ts +42 -0
  6. package/generated/editor-vm/tilemap_tiles.d.ts +80 -0
  7. package/generated/editor-vm/zip.d.ts +10 -0
  8. package/generated/editor-vm/zlib.d.ts +24 -0
  9. package/generated/editor.d.ts +1092 -0
  10. package/generated/go.d.ts +22 -22
  11. package/generated/kinds/editor-script.d.ts +13 -0
  12. package/generated/kinds/gui-script.d.ts +1 -0
  13. package/generated/kinds/render-script.d.ts +1 -0
  14. package/generated/kinds/script.d.ts +1 -0
  15. package/generated/versions/defold-1.12.4/go.d.ts +22 -22
  16. package/index.d.ts +6 -0
  17. package/package.json +9 -1
  18. package/scripts/materialize-version.ts +54 -13
  19. package/scripts/regen.ts +425 -42
  20. package/scripts/signature-store-fs.ts +2 -0
  21. package/scripts/sync-api-docs.ts +82 -6
  22. package/src/api-doc.ts +58 -0
  23. package/src/core-types.ts +18 -1
  24. package/src/doc-comment.ts +21 -3
  25. package/src/editor-overloads.d.ts +33 -0
  26. package/src/editor-vm-globals.d.ts +200 -0
  27. package/src/editor-vm-types.ts +44 -0
  28. package/src/editor.ts +117 -16
  29. package/src/emit-dts.ts +292 -79
  30. package/src/engine-globals.d.ts +2 -2
  31. package/src/go-overloads.d.ts +6 -6
  32. package/src/index.ts +12 -0
  33. package/src/library-signature.ts +11 -3
  34. package/src/msg-overloads.d.ts +3 -3
  35. package/src/scene-addresses.d.ts +62 -0
  36. package/src/script-api.ts +12 -2
  37. package/src/url-parameters.ts +174 -0
  38. package/url-parameters.json +285 -0
@@ -0,0 +1,62 @@
1
+ declare global {
2
+ /**
3
+ * Game-object addresses found in the project's scenes — `"/player"`,
4
+ * `"/level/enemy"`, and every other runtime path a `.collection` composes.
5
+ *
6
+ * @remarks
7
+ * The interface ships **empty** and is open: a generator augments it with one
8
+ * key per address it discovered, and editors then offer those keys as
9
+ * completions on every slot typed {@link SceneGameObjectAddress}. With no
10
+ * generator run the interface stays empty, which is exactly today's
11
+ * behavior — the alias is always widened, so nothing is ever rejected.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * declare global {
16
+ * interface SceneGameObjectAddresses {
17
+ * "/player": true;
18
+ * }
19
+ * }
20
+ * ```
21
+ */
22
+ interface SceneGameObjectAddresses {}
23
+
24
+ /**
25
+ * Component addresses found in the project's scenes — `"#sprite"`,
26
+ * `"/player#collisionobject"`, and every other component a game object owns.
27
+ *
28
+ * @remarks
29
+ * Open and empty by default, exactly like {@link SceneGameObjectAddresses};
30
+ * a generator fills it and {@link SceneComponentAddress} reads it. Kept
31
+ * separate from the game-object interface so a slot that can only address a
32
+ * component never suggests a bare game-object path.
33
+ */
34
+ interface SceneComponentAddresses {}
35
+
36
+ /**
37
+ * A game-object address: the scene-derived ids as completions, plus every
38
+ * other string.
39
+ *
40
+ * @remarks
41
+ * The trailing `(string & {})` term is load-bearing. It keeps the alias
42
+ * assignable from — and to — an arbitrary `string`, so an address computed at
43
+ * runtime type-checks unchanged while the literal keys still surface as
44
+ * suggestions. A scene-derived type must never turn into a compile error.
45
+ */
46
+ type SceneGameObjectAddress = (keyof SceneGameObjectAddresses & string) | (string & {});
47
+
48
+ /**
49
+ * A component address: the scene-derived ids as completions, plus every other
50
+ * string. Never rejects, for the same reason as
51
+ * {@link SceneGameObjectAddress}.
52
+ */
53
+ type SceneComponentAddress = (keyof SceneComponentAddresses & string) | (string & {});
54
+
55
+ /**
56
+ * Either kind of address, for a slot that accepts a game object *or* one of
57
+ * its components — `msg.post`'s receiver, `go.get`'s url. Never rejects.
58
+ */
59
+ type SceneAddress = SceneGameObjectAddress | SceneComponentAddress;
60
+ }
61
+
62
+ export {};
package/src/script-api.ts CHANGED
@@ -27,6 +27,17 @@ function stringOr(value: unknown, fallback: string): string {
27
27
  return typeof value === "string" ? value : fallback;
28
28
  }
29
29
 
30
+ // A `.script_api` `type:` may spell a union inline (`string | nil`), where the
31
+ // core ref-doc format carries one token per alternative. Splitting here keeps the
32
+ // downstream emitter and fidelity resolver working in single tokens.
33
+ function splitTypeTokens(type: unknown): string[] {
34
+ if (typeof type !== "string") return [];
35
+ return type
36
+ .split("|")
37
+ .map((token) => token.trim())
38
+ .filter((token) => token.length > 0);
39
+ }
40
+
30
41
  function mapParameters(raw: unknown): RefDocParameter[] {
31
42
  if (!Array.isArray(raw)) return [];
32
43
  const out: RefDocParameter[] = [];
@@ -36,11 +47,10 @@ function mapParameters(raw: unknown): RefDocParameter[] {
36
47
  // The script_api lists the implicit `self` the engine passes; the emitter
37
48
  // stamps @noSelfInFile, so generated signatures must not declare it.
38
49
  if (name === "self") continue;
39
- const type = item.type;
40
50
  out.push({
41
51
  name,
42
52
  doc: stringOr(item.desc, ""),
43
- types: typeof type === "string" ? [type] : [],
53
+ types: splitTypeTokens(item.type),
44
54
  });
45
55
  }
46
56
  return out;
@@ -0,0 +1,174 @@
1
+ import type { ApiModule } from "./api-doc";
2
+
3
+ // How a parameter names something the project declares. `none` is the default
4
+ // and the only non-affirmative value: a type shape is necessary but not
5
+ // sufficient (`model.get_mesh_enabled#mesh_id` carries the address triple while
6
+ // naming a mesh inside the model asset), so a slot is classified only
7
+ // deliberately. The first three address the scene graph; `gui-node` names a node
8
+ // inside the one `.gui` that owns the script, which is not an address at all;
9
+ // `animation` names a block inside the atlas of a component a *sibling*
10
+ // argument addresses, which is why it is the one class needing a companion;
11
+ // `resource-path` names a project file outright, so it is scoped by the
12
+ // extensions its entry declares rather than by anything in the scene graph;
13
+ // `config-key` names a `<section>.<key>` entry in the project's own
14
+ // `game.project`, so its universe is one file the project declares rather than
15
+ // anything in the scene graph or on disk beside it; `action-id` names an action
16
+ // the project's `.input_binding` files declare, and is the one class whose slot
17
+ // is a parameter of a prefixless global rather than of a Defold module function
18
+ // — `hash("jump")` — so it is scoped by the comparison the call sits in rather
19
+ // than by a sibling argument.
20
+ export type UrlParameterClass =
21
+ | "none"
22
+ | "game-object"
23
+ | "component"
24
+ | "either"
25
+ | "gui-node"
26
+ | "animation"
27
+ | "resource-path"
28
+ | "config-key"
29
+ | "action-id";
30
+
31
+ export interface UrlParameterEntry {
32
+ fqn: string;
33
+ parameter: string;
34
+ class: UrlParameterClass;
35
+ // The parameter of the *same* function whose literal names the component the
36
+ // candidates are scoped to. Required for `animation` and absent otherwise —
37
+ // enforced by the drift guard rather than the type, because a per-class entry
38
+ // shape would fan the table's one interface out into a union for a single
39
+ // optional field.
40
+ addressParameter?: string;
41
+ // The file extensions this slot's literal may name, each written with its
42
+ // leading dot. Required for `resource-path` and absent otherwise — enforced by
43
+ // the drift guard for the same reason `addressParameter` is. Recorded per
44
+ // entry rather than per class because the six constructors sharing the class
45
+ // each accept a different one.
46
+ resourceExtensions?: readonly string[];
47
+ // The parameter this slot's *call* must be compared against for the class to
48
+ // apply — `action_id` for `hash("…")`, whose bare global would otherwise match
49
+ // every hashed name a project writes. Required for `action-id` and absent
50
+ // otherwise, enforced by the drift guard for the same reason `addressParameter`
51
+ // is. Unlike `addressParameter` this names a parameter of the surrounding
52
+ // *hook*, not of the classified function.
53
+ comparedParameter?: string;
54
+ // `"generated"` for a slot the emitter derives from the ref-doc, otherwise a
55
+ // package-relative path to the hand-authored `.d.ts` that declares it,
56
+ // resolved against the `packages/types` package root. Not repo-relative: the
57
+ // table ships inside `@defold-typescript/types`, so a published consumer has
58
+ // no repo root to resolve a `packages/types/` prefix against.
59
+ source: string;
60
+ // A verbatim phrase from the ref-doc `doc` the classification was judged from;
61
+ // required whenever `source` is `"generated"`, absent for hand-authored slots
62
+ // that have no ref-doc prose to pin against.
63
+ evidence?: string;
64
+ }
65
+
66
+ export type UrlParameterTable = UrlParameterEntry[];
67
+
68
+ export interface UrlParameterSource {
69
+ module: ApiModule;
70
+ skipFunctions?: readonly string[];
71
+ }
72
+
73
+ export interface UrlParameterSlot {
74
+ fqn: string;
75
+ parameter: string;
76
+ module: string;
77
+ doc: string;
78
+ types: readonly string[];
79
+ // The declaring function's ref-doc examples, verbatim. The parameter prose
80
+ // alone cannot refute a `resource-path` extension — every one of the six reads
81
+ // "optional resource path string to the resource" — so the example is the only
82
+ // place the claim is checkable.
83
+ examples: string;
84
+ }
85
+
86
+ const ADDRESS_TYPES = ["string", "hash", "url"] as const;
87
+
88
+ // The type shape a class needs its slot to carry. A classification is a judgment
89
+ // about prose, but it is still refutable by the signature: nothing that cannot
90
+ // hold a `url` can be an address, and nothing that cannot hold a `string` can
91
+ // name a node.
92
+ export const REQUIRED_TYPES: Record<Exclude<UrlParameterClass, "none">, readonly string[]> = {
93
+ "game-object": ADDRESS_TYPES,
94
+ component: ADDRESS_TYPES,
95
+ either: ADDRESS_TYPES,
96
+ "gui-node": ["string", "hash"],
97
+ animation: ["string", "hash"],
98
+ "resource-path": ["string"],
99
+ "config-key": ["string"],
100
+ "action-id": ["string"],
101
+ };
102
+
103
+ function bareName(fqn: string): string {
104
+ const lastDot = fqn.lastIndexOf(".");
105
+ return lastDot === -1 ? fqn : fqn.slice(lastDot + 1);
106
+ }
107
+
108
+ function carriesAll(types: readonly string[], required: readonly string[]): boolean {
109
+ const lowered = new Set(types.map((token) => token.toLowerCase()));
110
+ return required.every((token) => lowered.has(token));
111
+ }
112
+
113
+ function carriesAddressTriple(types: readonly string[]): boolean {
114
+ return carriesAll(types, ADDRESS_TYPES);
115
+ }
116
+
117
+ // Whether a slot declaring `types` could carry `parameterClass`. A superset is
118
+ // fine — the shape is a floor, not an equality — and `none` is always satisfied
119
+ // because it asserts nothing.
120
+ export function parameterTypesSatisfyClass(
121
+ types: readonly string[],
122
+ parameterClass: UrlParameterClass,
123
+ ): boolean {
124
+ if (parameterClass === "none") return true;
125
+ return carriesAll(types, REQUIRED_TYPES[parameterClass]);
126
+ }
127
+
128
+ // The generated surface's whole parameter universe. Functions named in a
129
+ // module's `skipFunctions` contribute nothing: the emitter suppresses them in
130
+ // favour of hand-authored overloads, so counting them here would conflate the
131
+ // two surfaces.
132
+ export function collectParameterSlots(sources: readonly UrlParameterSource[]): UrlParameterSlot[] {
133
+ const slots: UrlParameterSlot[] = [];
134
+ for (const { module, skipFunctions } of sources) {
135
+ const skipped = new Set(skipFunctions ?? []);
136
+ for (const fn of module.functions) {
137
+ if (skipped.has(bareName(fn.name))) continue;
138
+ for (const parameter of fn.parameters) {
139
+ slots.push({
140
+ fqn: fn.name,
141
+ parameter: parameter.name,
142
+ module: module.namespace,
143
+ doc: parameter.doc,
144
+ types: parameter.types,
145
+ examples: fn.examples ?? "",
146
+ });
147
+ }
148
+ }
149
+ }
150
+ return slots;
151
+ }
152
+
153
+ // The address-triple subset of the above — the universe a classification survey
154
+ // of `msg.post`-shaped slots walks.
155
+ export function collectUrlParameterSlots(
156
+ sources: readonly UrlParameterSource[],
157
+ ): UrlParameterSlot[] {
158
+ return collectParameterSlots(sources).filter((slot) => carriesAddressTriple(slot.types));
159
+ }
160
+
161
+ // Pure lookup, dependency-free like `signature-store.ts`: this module is
162
+ // reachable from `index.ts`, so a `node:fs`/ambient-`Bun` reference here would
163
+ // fail type-checking in every downstream consumer that compiles the shipped
164
+ // `src/` graph.
165
+ export function classifyUrlParameter(
166
+ table: UrlParameterTable,
167
+ fqn: string,
168
+ parameter: string,
169
+ ): UrlParameterClass {
170
+ for (const entry of table) {
171
+ if (entry.fqn === fqn && entry.parameter === parameter) return entry.class;
172
+ }
173
+ return "none";
174
+ }
@@ -0,0 +1,285 @@
1
+ [
2
+ {
3
+ "fqn": "go.get_position",
4
+ "parameter": "id",
5
+ "class": "game-object",
6
+ "source": "generated",
7
+ "evidence": "id of the game object instance to get the position for"
8
+ },
9
+ {
10
+ "fqn": "go.get_rotation",
11
+ "parameter": "id",
12
+ "class": "game-object",
13
+ "source": "generated",
14
+ "evidence": "id of the game object instance to get the rotation for"
15
+ },
16
+ {
17
+ "fqn": "go.get_scale",
18
+ "parameter": "id",
19
+ "class": "game-object",
20
+ "source": "generated",
21
+ "evidence": "id of the game object instance to get the scale for"
22
+ },
23
+ {
24
+ "fqn": "go.get_scale_uniform",
25
+ "parameter": "id",
26
+ "class": "game-object",
27
+ "source": "generated",
28
+ "evidence": "id of the game object instance to get the uniform scale for"
29
+ },
30
+ {
31
+ "fqn": "go.set_position",
32
+ "parameter": "id",
33
+ "class": "game-object",
34
+ "source": "generated",
35
+ "evidence": "id of the game object instance to set the position for"
36
+ },
37
+ {
38
+ "fqn": "go.set_rotation",
39
+ "parameter": "id",
40
+ "class": "game-object",
41
+ "source": "generated",
42
+ "evidence": "id of the game object instance to get the rotation for"
43
+ },
44
+ {
45
+ "fqn": "go.set_scale",
46
+ "parameter": "id",
47
+ "class": "game-object",
48
+ "source": "generated",
49
+ "evidence": "id of the game object instance to get the scale for"
50
+ },
51
+ {
52
+ "fqn": "go.set_scale_xy",
53
+ "parameter": "id",
54
+ "class": "game-object",
55
+ "source": "generated",
56
+ "evidence": "id of the game object instance to get the scale for"
57
+ },
58
+ {
59
+ "fqn": "go.set_parent",
60
+ "parameter": "id",
61
+ "class": "game-object",
62
+ "source": "generated",
63
+ "evidence": "id of the game object instance to set parent for"
64
+ },
65
+ {
66
+ "fqn": "go.set_parent",
67
+ "parameter": "parent_id",
68
+ "class": "game-object",
69
+ "source": "generated",
70
+ "evidence": "id of the new parent game object"
71
+ },
72
+ {
73
+ "fqn": "go.get_parent",
74
+ "parameter": "id",
75
+ "class": "game-object",
76
+ "source": "generated",
77
+ "evidence": "id of the game object instance to get parent for"
78
+ },
79
+ {
80
+ "fqn": "go.get_world_position",
81
+ "parameter": "id",
82
+ "class": "game-object",
83
+ "source": "generated",
84
+ "evidence": "id of the game object instance to get the world position for"
85
+ },
86
+ {
87
+ "fqn": "go.get_world_rotation",
88
+ "parameter": "id",
89
+ "class": "game-object",
90
+ "source": "generated",
91
+ "evidence": "id of the game object instance to get the world rotation for"
92
+ },
93
+ {
94
+ "fqn": "go.get_world_scale",
95
+ "parameter": "id",
96
+ "class": "game-object",
97
+ "source": "generated",
98
+ "evidence": "id of the game object instance to get the world scale for"
99
+ },
100
+ {
101
+ "fqn": "go.get_world_scale_uniform",
102
+ "parameter": "id",
103
+ "class": "game-object",
104
+ "source": "generated",
105
+ "evidence": "id of the game object instance to get the world scale for"
106
+ },
107
+ {
108
+ "fqn": "go.get_world_transform",
109
+ "parameter": "id",
110
+ "class": "game-object",
111
+ "source": "generated",
112
+ "evidence": "id of the game object instance to get the world transform for"
113
+ },
114
+ {
115
+ "fqn": "go.update_world_transform",
116
+ "parameter": "id",
117
+ "class": "game-object",
118
+ "source": "generated",
119
+ "evidence": "id of the game object instance to update"
120
+ },
121
+ {
122
+ "fqn": "go.delete",
123
+ "parameter": "id",
124
+ "class": "game-object",
125
+ "source": "generated",
126
+ "evidence": "id or table of id's of the instance(s) to delete"
127
+ },
128
+ {
129
+ "fqn": "go.exists",
130
+ "parameter": "url",
131
+ "class": "game-object",
132
+ "source": "generated",
133
+ "evidence": "url of the game object to check"
134
+ },
135
+ {
136
+ "fqn": "go.world_to_local_position",
137
+ "parameter": "url",
138
+ "class": "game-object",
139
+ "source": "generated",
140
+ "evidence": "url of the game object which coordinate system convert to"
141
+ },
142
+ {
143
+ "fqn": "go.world_to_local_transform",
144
+ "parameter": "url",
145
+ "class": "game-object",
146
+ "source": "generated",
147
+ "evidence": "url of the game object which coordinate system convert to"
148
+ },
149
+ {
150
+ "fqn": "go.animate",
151
+ "parameter": "url",
152
+ "class": "either",
153
+ "source": "generated",
154
+ "evidence": "url of the game object or component having the property"
155
+ },
156
+ {
157
+ "fqn": "go.cancel_animations",
158
+ "parameter": "url",
159
+ "class": "either",
160
+ "source": "generated",
161
+ "evidence": "url of the game object or component"
162
+ },
163
+ {
164
+ "fqn": "go.get",
165
+ "parameter": "url",
166
+ "class": "either",
167
+ "source": "src/go-overloads.d.ts"
168
+ },
169
+ {
170
+ "fqn": "go.set",
171
+ "parameter": "url",
172
+ "class": "either",
173
+ "source": "src/go-overloads.d.ts"
174
+ },
175
+ {
176
+ "fqn": "msg.post",
177
+ "parameter": "receiver",
178
+ "class": "either",
179
+ "source": "src/msg-overloads.d.ts"
180
+ },
181
+ {
182
+ "fqn": "msg.url",
183
+ "parameter": "urlstring",
184
+ "class": "either",
185
+ "source": "src/msg-overloads.d.ts"
186
+ },
187
+ {
188
+ "fqn": "gui.get_node",
189
+ "parameter": "id",
190
+ "class": "gui-node",
191
+ "source": "generated",
192
+ "evidence": "id of the node to retrieve"
193
+ },
194
+ {
195
+ "fqn": "sprite.play_flipbook",
196
+ "parameter": "id",
197
+ "class": "animation",
198
+ "addressParameter": "url",
199
+ "source": "generated",
200
+ "evidence": "hashed id of the animation to play"
201
+ },
202
+ {
203
+ "fqn": "resource.atlas",
204
+ "parameter": "path",
205
+ "class": "resource-path",
206
+ "resourceExtensions": [".atlas"],
207
+ "source": "generated",
208
+ "evidence": "optional resource path string to the resource"
209
+ },
210
+ {
211
+ "fqn": "resource.buffer",
212
+ "parameter": "path",
213
+ "class": "resource-path",
214
+ "resourceExtensions": [".buffer"],
215
+ "source": "generated",
216
+ "evidence": "optional resource path string to the resource"
217
+ },
218
+ {
219
+ "fqn": "resource.font",
220
+ "parameter": "path",
221
+ "class": "resource-path",
222
+ "resourceExtensions": [".font"],
223
+ "source": "generated",
224
+ "evidence": "optional resource path string to the resource"
225
+ },
226
+ {
227
+ "fqn": "resource.material",
228
+ "parameter": "path",
229
+ "class": "resource-path",
230
+ "resourceExtensions": [".material"],
231
+ "source": "generated",
232
+ "evidence": "optional resource path string to the resource"
233
+ },
234
+ {
235
+ "fqn": "resource.texture",
236
+ "parameter": "path",
237
+ "class": "resource-path",
238
+ "resourceExtensions": [".png"],
239
+ "source": "generated",
240
+ "evidence": "optional resource path string to the resource"
241
+ },
242
+ {
243
+ "fqn": "resource.tile_source",
244
+ "parameter": "path",
245
+ "class": "resource-path",
246
+ "resourceExtensions": [".tilesource"],
247
+ "source": "generated",
248
+ "evidence": "optional resource path string to the resource"
249
+ },
250
+ {
251
+ "fqn": "sys.get_config_boolean",
252
+ "parameter": "key",
253
+ "class": "config-key",
254
+ "source": "generated",
255
+ "evidence": "The syntax is SECTION.KEY"
256
+ },
257
+ {
258
+ "fqn": "sys.get_config_int",
259
+ "parameter": "key",
260
+ "class": "config-key",
261
+ "source": "generated",
262
+ "evidence": "The syntax is SECTION.KEY"
263
+ },
264
+ {
265
+ "fqn": "sys.get_config_number",
266
+ "parameter": "key",
267
+ "class": "config-key",
268
+ "source": "generated",
269
+ "evidence": "The syntax is SECTION.KEY"
270
+ },
271
+ {
272
+ "fqn": "sys.get_config_string",
273
+ "parameter": "key",
274
+ "class": "config-key",
275
+ "source": "generated",
276
+ "evidence": "The syntax is SECTION.KEY"
277
+ },
278
+ {
279
+ "fqn": "hash",
280
+ "parameter": "s",
281
+ "class": "action-id",
282
+ "comparedParameter": "action_id",
283
+ "source": "src/engine-globals.d.ts"
284
+ }
285
+ ]