@defold-typescript/types 0.35.0 → 0.36.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.
@@ -206,7 +206,7 @@
206
206
  "factory.create": [
207
207
  {
208
208
  "sourceHash": "d2cd2037a9127ec6",
209
- "ts": "// How to create a new game object:\nexport default defineScript({\n init(self) {\n // create a new game object and provide property values\n self.my_created_object = factory.create(\"#factory\", undefined, undefined, { my_value: 1 });\n // communicate with the object\n msg.post(self.my_created_object, \"hello\");\n },\n});\n\n// And then let the new game object have a script attached:\ngo.property(\"my_value\", 0);\n\nexport default defineScript({\n init(self) {\n // do something with self.my_value which is now one\n },\n});"
209
+ "ts": "// How to create a new game object:\nexport default defineScript({\n init(self) {\n // create a new game object and provide property values\n const created = factory.create(\"#factory\", undefined, undefined, { my_value: 1 });\n // communicate with the object\n msg.post(created, \"hello\");\n },\n});\n\n// And then let the new game object have a script attached, in its own file:\n//\n// go.property(\"my_value\", 0);\n//\n// export default defineScript({\n// init(self) {\n// // do something with self.my_value which is now one\n// },\n// });"
210
210
  }
211
211
  ],
212
212
  "factory.load": [
@@ -320,7 +320,7 @@
320
320
  "go.get_world_position": [
321
321
  {
322
322
  "sourceHash": "ab804a5cdcfd4f7d",
323
- "ts": "// Get the world position of the game object the script is attached to:\nconst p = go.get_world_position();\n\n// Reach a sibling game object by its id \u2014 relative addressing, no socket prefix:\nconst p2 = go.get_world_position(\"x\");"
323
+ "ts": "// Get the world position of the game object the script is attached to:\nconst p = go.get_world_position();\n\n// Reach a sibling game object by its id — relative addressing, no socket prefix:\nconst p2 = go.get_world_position(\"x\");"
324
324
  }
325
325
  ],
326
326
  "go.get_world_rotation": [
@@ -368,7 +368,7 @@
368
368
  "go.set_position": [
369
369
  {
370
370
  "sourceHash": "ad83d0274d776e8f",
371
- "ts": "// `p` is the desired position (a Vector3).\nconst p = vmath.vector3();\n\n// Set the position of the game object the script is attached to:\ngo.set_position(p);\n\n// Reach a sibling game object by its id \u2014 relative addressing, no socket prefix:\ngo.set_position(p, \"x\");"
371
+ "ts": "// `p` is the desired position (a Vector3).\nconst p = vmath.vector3();\n\n// Set the position of the game object the script is attached to:\ngo.set_position(p);\n\n// Reach a sibling game object by its id — relative addressing, no socket prefix:\ngo.set_position(p, \"x\");"
372
372
  }
373
373
  ],
374
374
  "go.set_rotation": [
@@ -770,7 +770,7 @@
770
770
  "on_message": [
771
771
  {
772
772
  "sourceHash": "bfed6bd72e3242e2",
773
- "ts": "// This example demonstrates how a game object instance, called \"a\", can communicate with another instance, called \"b\". It\n// is assumed that both script components of the instances has id \"script\".\n\n// a.script \u2014 Script of instance \"a\":\nexport default defineScript({\n init() {\n // let b know about some important data\n msg.post(\"b#script\", \"my_data\", { important_value: 1 });\n },\n});\n\n// b.script \u2014 Script of instance \"b\":\nexport default defineScript({\n init() {\n // store the url of instance \"a\" for later use, by specifying undefined as socket we\n // automatically use our own socket\n return { a_url: msg.url(undefined, go.get_id(\"a\"), \"script\") };\n },\n\n on_message(self, message_id, message, sender) {\n // check message and sender\n if (message_id === hash(\"my_data\") && sender === self.a_url) {\n // use the data in some way\n self.important_value = message.important_value;\n }\n },\n});"
773
+ "ts": "// This example demonstrates how a game object instance, called \"a\", can communicate with another instance, called \"b\". It\n// is assumed that both script components of the instances has id \"script\".\n\n// a.script — Script of instance \"a\":\nexport default defineScript({\n init() {\n // let b know about some important data\n msg.post(\"b#script\", \"my_data\", { important_value: 1 });\n },\n});\n\n// b.script — Script of instance \"b\":\nexport default defineScript({\n init() {\n // store the url of instance \"a\" for later use, by specifying undefined as socket we\n // automatically use our own socket\n return { a_url: msg.url(undefined, go.get_id(\"a\"), \"script\") };\n },\n\n on_message(self, message_id, message, sender) {\n // check message and sender\n if (message_id === hash(\"my_data\") && sender === self.a_url) {\n // use the data in some way\n self.important_value = message.important_value;\n }\n },\n});"
774
774
  }
775
775
  ],
776
776
  "on_reload": [
@@ -928,7 +928,7 @@
928
928
  "render.clear": [
929
929
  {
930
930
  "sourceHash": "70406f065fc91216",
931
- "ts": "// Clear the color buffer and the depth buffer.\nrender.clear({\n [graphics.BUFFER_TYPE_COLOR0_BIT]: vmath.vector4(0, 0, 0, 0),\n [graphics.BUFFER_TYPE_DEPTH_BIT]: 1,\n});"
931
+ "ts": "// Clear the color buffer and the depth buffer.\nconst buffers = new LuaMap<render.ClearBufferKey, number | Vector4>();\nbuffers.set(graphics.BUFFER_TYPE_COLOR0_BIT, vmath.vector4(0, 0, 0, 0));\nbuffers.set(graphics.BUFFER_TYPE_DEPTH_BIT, 1);\nrender.clear(buffers);"
932
932
  }
933
933
  ],
934
934
  "render.constant_buffer": [
@@ -1978,7 +1978,7 @@
1978
1978
  "zlib.inflate": [
1979
1979
  {
1980
1980
  "sourceHash": "6b8b8cc6d9afe679",
1981
- "ts": "const data = \"\\120\\94\\11\\201\\200\\44\\86\\0\\162\\68\\133\\226\\146\\162\\204\\188\\116\\133\\242\\204\\146\\12\\133\\210\\188\\228\\252\\220\\130\\162\\212\\226\\226\\212\\20\\133\\148\\196\\146\\68\\61\\0\\44\\67\\14\\201\";\nconst uncompressed_data = zlib.inflate(data);\nprint(uncompressed_data); //> This is a string with uncompressed data."
1981
+ "ts": "const data =\n \"\\x78\\x5e\\x0b\\xc9\\xc8\\x2c\\x56\\x00\\xa2\\x44\\x85\\xe2\\x92\\xa2\\xcc\\xbc\\x74\\x85\\xf2\\xcc\\x92\\x0c\\x85\\xd2\\xbc\\xe4\\xfc\\xdc\\x82\\xa2\\xd4\\xe2\\xe2\\xd4\\x14\\x85\\x94\\xc4\\x92\\x44\\x3d\\x00\\x2c\\x43\\x0e\\xc9\";\nconst uncompressed_data = zlib.inflate(data);\nprint(uncompressed_data); //> This is a string with uncompressed data."
1982
1982
  }
1983
1983
  ]
1984
1984
  }
@@ -39,20 +39,21 @@ declare global {
39
39
  * export default defineScript({
40
40
  * init(self) {
41
41
  * // create a new game object and provide property values
42
- * self.my_created_object = factory.create("#factory", undefined, undefined, { my_value: 1 });
42
+ * const created = factory.create("#factory", undefined, undefined, { my_value: 1 });
43
43
  * // communicate with the object
44
- * msg.post(self.my_created_object, "hello");
44
+ * msg.post(created, "hello");
45
45
  * },
46
46
  * });
47
47
  *
48
- * // And then let the new game object have a script attached:
49
- * go.property("my_value", 0);
50
- *
51
- * export default defineScript({
52
- * init(self) {
53
- * // do something with self.my_value which is now one
54
- * },
55
- * });
48
+ * // And then let the new game object have a script attached, in its own file:
49
+ * //
50
+ * // go.property("my_value", 0);
51
+ * //
52
+ * // export default defineScript({
53
+ * // init(self) {
54
+ * // // do something with self.my_value which is now one
55
+ * // },
56
+ * // });
56
57
  * ```
57
58
  */
58
59
  function create(url: string | Hash | Url, position?: Vector3, rotation?: Quaternion, properties?: Record<string | number, unknown>, scale?: number | Vector3): Hash;
@@ -38,13 +38,13 @@ declare global {
38
38
  * @example
39
39
  * ```ts
40
40
  * // Clear the color buffer and the depth buffer.
41
- * render.clear({
42
- * [graphics.BUFFER_TYPE_COLOR0_BIT]: vmath.vector4(0, 0, 0, 0),
43
- * [graphics.BUFFER_TYPE_DEPTH_BIT]: 1,
44
- * });
41
+ * const buffers = new LuaMap<render.ClearBufferKey, number | Vector4>();
42
+ * buffers.set(graphics.BUFFER_TYPE_COLOR0_BIT, vmath.vector4(0, 0, 0, 0));
43
+ * buffers.set(graphics.BUFFER_TYPE_DEPTH_BIT, 1);
44
+ * render.clear(buffers);
45
45
  * ```
46
46
  */
47
- function clear(buffers: LuaMap<number, number | Vector4>): void;
47
+ function clear(buffers: LuaMap<number & { readonly __brand: "graphics.BUFFER_TYPE_COLOR0_BIT" } | number & { readonly __brand: "graphics.BUFFER_TYPE_DEPTH_BIT" } | number & { readonly __brand: "graphics.BUFFER_TYPE_STENCIL_BIT" }, number | Vector4>): void;
48
48
  /**
49
49
  * Constant buffers are used to set shader program variables and are optionally passed to the `render.draw()` function.
50
50
  * The buffer's constant elements can be indexed like an ordinary Lua table, but you can't iterate over them with pairs() or ipairs().
@@ -39,20 +39,21 @@ declare global {
39
39
  * export default defineScript({
40
40
  * init(self) {
41
41
  * // create a new game object and provide property values
42
- * self.my_created_object = factory.create("#factory", undefined, undefined, { my_value: 1 });
42
+ * const created = factory.create("#factory", undefined, undefined, { my_value: 1 });
43
43
  * // communicate with the object
44
- * msg.post(self.my_created_object, "hello");
44
+ * msg.post(created, "hello");
45
45
  * },
46
46
  * });
47
47
  *
48
- * // And then let the new game object have a script attached:
49
- * go.property("my_value", 0);
50
- *
51
- * export default defineScript({
52
- * init(self) {
53
- * // do something with self.my_value which is now one
54
- * },
55
- * });
48
+ * // And then let the new game object have a script attached, in its own file:
49
+ * //
50
+ * // go.property("my_value", 0);
51
+ * //
52
+ * // export default defineScript({
53
+ * // init(self) {
54
+ * // // do something with self.my_value which is now one
55
+ * // },
56
+ * // });
56
57
  * ```
57
58
  */
58
59
  function create(url: string | Hash | Url, position?: Vector3, rotation?: Quaternion, properties?: Record<string | number, unknown>, scale?: number | Vector3): Hash;
@@ -46,13 +46,13 @@ declare global {
46
46
  * @example
47
47
  * ```ts
48
48
  * // Clear the color buffer and the depth buffer.
49
- * render.clear({
50
- * [graphics.BUFFER_TYPE_COLOR0_BIT]: vmath.vector4(0, 0, 0, 0),
51
- * [graphics.BUFFER_TYPE_DEPTH_BIT]: 1,
52
- * });
49
+ * const buffers = new LuaMap<render.ClearBufferKey, number | Vector4>();
50
+ * buffers.set(graphics.BUFFER_TYPE_COLOR0_BIT, vmath.vector4(0, 0, 0, 0));
51
+ * buffers.set(graphics.BUFFER_TYPE_DEPTH_BIT, 1);
52
+ * render.clear(buffers);
53
53
  * ```
54
54
  */
55
- function clear(buffers: LuaMap<number, number | Vector4>): void;
55
+ function clear(buffers: LuaMap<number & { readonly __brand: "graphics.BUFFER_TYPE_COLOR0_BIT" } | number & { readonly __brand: "graphics.BUFFER_TYPE_DEPTH_BIT" } | number & { readonly __brand: "graphics.BUFFER_TYPE_STENCIL_BIT" }, number | Vector4>): void;
56
56
  /**
57
57
  * Constant buffers are used to set shader program variables and are optionally passed to the `render.draw()` function.
58
58
  * The buffer's constant elements can be indexed like an ordinary Lua table, but you can't iterate over them with pairs() or ipairs().
@@ -28,7 +28,8 @@ declare global {
28
28
  * @returns inflated buffer
29
29
  * @example
30
30
  * ```ts
31
- * const data = "\120\94\11\201\200\44\86\0\162\68\133\226\146\162\204\188\116\133\242\204\146\12\133\210\188\228\252\220\130\162\212\226\226\212\20\133\148\196\146\68\61\0\44\67\14\201";
31
+ * const data =
32
+ * "\x78\x5e\x0b\xc9\xc8\x2c\x56\x00\xa2\x44\x85\xe2\x92\xa2\xcc\xbc\x74\x85\xf2\xcc\x92\x0c\x85\xd2\xbc\xe4\xfc\xdc\x82\xa2\xd4\xe2\xe2\xd4\x14\x85\x94\xc4\x92\x44\x3d\x00\x2c\x43\x0e\xc9";
32
33
  * const uncompressed_data = zlib.inflate(data);
33
34
  * print(uncompressed_data); //> This is a string with uncompressed data.
34
35
  * ```
@@ -39,20 +39,21 @@ declare global {
39
39
  * export default defineScript({
40
40
  * init(self) {
41
41
  * // create a new game object and provide property values
42
- * self.my_created_object = factory.create("#factory", undefined, undefined, { my_value: 1 });
42
+ * const created = factory.create("#factory", undefined, undefined, { my_value: 1 });
43
43
  * // communicate with the object
44
- * msg.post(self.my_created_object, "hello");
44
+ * msg.post(created, "hello");
45
45
  * },
46
46
  * });
47
47
  *
48
- * // And then let the new game object have a script attached:
49
- * go.property("my_value", 0);
50
- *
51
- * export default defineScript({
52
- * init(self) {
53
- * // do something with self.my_value which is now one
54
- * },
55
- * });
48
+ * // And then let the new game object have a script attached, in its own file:
49
+ * //
50
+ * // go.property("my_value", 0);
51
+ * //
52
+ * // export default defineScript({
53
+ * // init(self) {
54
+ * // // do something with self.my_value which is now one
55
+ * // },
56
+ * // });
56
57
  * ```
57
58
  */
58
59
  function create(url: string | Hash | Url, position?: Vector3, rotation?: Quaternion, properties?: Record<string | number, unknown>, scale?: number | Vector3): Hash;
@@ -38,13 +38,13 @@ declare global {
38
38
  * @example
39
39
  * ```ts
40
40
  * // Clear the color buffer and the depth buffer.
41
- * render.clear({
42
- * [graphics.BUFFER_TYPE_COLOR0_BIT]: vmath.vector4(0, 0, 0, 0),
43
- * [graphics.BUFFER_TYPE_DEPTH_BIT]: 1,
44
- * });
41
+ * const buffers = new LuaMap<render.ClearBufferKey, number | Vector4>();
42
+ * buffers.set(graphics.BUFFER_TYPE_COLOR0_BIT, vmath.vector4(0, 0, 0, 0));
43
+ * buffers.set(graphics.BUFFER_TYPE_DEPTH_BIT, 1);
44
+ * render.clear(buffers);
45
45
  * ```
46
46
  */
47
- function clear(buffers: LuaMap<number, number | Vector4>): void;
47
+ function clear(buffers: LuaMap<number & { readonly __brand: "graphics.BUFFER_TYPE_COLOR0_BIT" } | number & { readonly __brand: "graphics.BUFFER_TYPE_DEPTH_BIT" } | number & { readonly __brand: "graphics.BUFFER_TYPE_STENCIL_BIT" }, number | Vector4>): void;
48
48
  /**
49
49
  * Constant buffers are used to set shader program variables and are optionally passed to the `render.draw()` function.
50
50
  * The buffer's constant elements can be indexed like an ordinary Lua table, but you can't iterate over them with pairs() or ipairs().
@@ -28,7 +28,8 @@ declare global {
28
28
  * @returns inflated buffer
29
29
  * @example
30
30
  * ```ts
31
- * const data = "\120\94\11\201\200\44\86\0\162\68\133\226\146\162\204\188\116\133\242\204\146\12\133\210\188\228\252\220\130\162\212\226\226\212\20\133\148\196\146\68\61\0\44\67\14\201";
31
+ * const data =
32
+ * "\x78\x5e\x0b\xc9\xc8\x2c\x56\x00\xa2\x44\x85\xe2\x92\xa2\xcc\xbc\x74\x85\xf2\xcc\x92\x0c\x85\xd2\xbc\xe4\xfc\xdc\x82\xa2\xd4\xe2\xe2\xd4\x14\x85\x94\xc4\x92\x44\x3d\x00\x2c\x43\x0e\xc9";
32
33
  * const uncompressed_data = zlib.inflate(data);
33
34
  * print(uncompressed_data); //> This is a string with uncompressed data.
34
35
  * ```
@@ -28,7 +28,8 @@ declare global {
28
28
  * @returns inflated buffer
29
29
  * @example
30
30
  * ```ts
31
- * const data = "\120\94\11\201\200\44\86\0\162\68\133\226\146\162\204\188\116\133\242\204\146\12\133\210\188\228\252\220\130\162\212\226\226\212\20\133\148\196\146\68\61\0\44\67\14\201";
31
+ * const data =
32
+ * "\x78\x5e\x0b\xc9\xc8\x2c\x56\x00\xa2\x44\x85\xe2\x92\xa2\xcc\xbc\x74\x85\xf2\xcc\x92\x0c\x85\xd2\xbc\xe4\xfc\xdc\x82\xa2\xd4\xe2\xe2\xd4\x14\x85\x94\xc4\x92\x44\x3d\x00\x2c\x43\x0e\xc9";
32
33
  * const uncompressed_data = zlib.inflate(data);
33
34
  * print(uncompressed_data); //> This is a string with uncompressed data.
34
35
  * ```
package/index.d.ts CHANGED
@@ -22,6 +22,7 @@ import "./generated/collectionproxy";
22
22
  import "./generated/compute";
23
23
  import "./generated/crash";
24
24
  import "./generated/factory";
25
+ import "./generated/font";
25
26
  import "./generated/go";
26
27
  import "./src/go-overloads";
27
28
  import "./generated/graphics";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defold-typescript/types",
3
- "version": "0.35.0",
3
+ "version": "0.36.0",
4
4
  "description": "TypeScript types for the Defold engine's Lua APIs.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -68,7 +68,10 @@
68
68
  "!src/**/__snapshots__",
69
69
  "!scripts/lua-types-signature-index.ts",
70
70
  "!scripts/fidelity-audit.ts",
71
- "!scripts/augmentation-namespaces.ts"
71
+ "!scripts/augmentation-namespaces.ts",
72
+ "!scripts/example-pins.ts",
73
+ "!scripts/example-surfaces.ts",
74
+ "!scripts/example-typecheck.ts"
72
75
  ],
73
76
  "publishConfig": {
74
77
  "access": "public"
@@ -1,5 +1,6 @@
1
1
  import { resolve } from "node:path";
2
2
  import { symbolIdentityKey } from "../src/api-availability";
3
+ import type { SlotTypes } from "../src/emit-dts";
3
4
  import { selectCompleteVersionSurfaces, versionOf } from "./generate-api-availability";
4
5
  import {
5
6
  generateModuleSignatures,
@@ -15,6 +16,11 @@ const SIGNATURES_PATH = resolve(PACKAGE_ROOT, "api-signatures.json");
15
16
  export interface SignaturesArtifact {
16
17
  // version -> symbolIdentityKey -> authoritative TS signature text
17
18
  readonly versions: Record<string, Record<string, string>>;
19
+ // The same axis and keys, carrying each documented slot's rendered type. Kept
20
+ // parallel rather than folded into `versions` because three consumers
21
+ // (`api-surface-loader`, `combined-surface`, `version-window`) type that map's
22
+ // value as a string; a symbol documenting no slot is absent here.
23
+ readonly slotTypes: Record<string, Record<string, SlotTypes>>;
18
24
  }
19
25
 
20
26
  export interface BuildSignaturesOptions {
@@ -51,9 +57,9 @@ export function withheldSymbols(entry: ModuleManifestEntry): { key: string; fqn:
51
57
  return withheld;
52
58
  }
53
59
 
54
- function sortObjectKeys(record: Record<string, string>): Record<string, string> {
55
- const sorted: Record<string, string> = {};
56
- for (const key of Object.keys(record).sort()) sorted[key] = record[key] as string;
60
+ function sortObjectKeys<T>(record: Record<string, T>): Record<string, T> {
61
+ const sorted: Record<string, T> = {};
62
+ for (const key of Object.keys(record).sort()) sorted[key] = record[key] as T;
57
63
  return sorted;
58
64
  }
59
65
 
@@ -62,21 +68,33 @@ export function buildSignaturesArtifact(options: BuildSignaturesOptions = {}): S
62
68
  const registryPath = options.registryPath ?? resolve(packageRoot, "api-targets.json");
63
69
  const targets = selectCompleteVersionSurfaces(loadApiTargets(registryPath));
64
70
  const versions: Record<string, Record<string, string>> = {};
71
+ const slotTypes: Record<string, Record<string, SlotTypes>> = {};
65
72
  for (const target of targets) {
66
73
  const version = versionOf(target);
67
74
  const perSymbol: Record<string, string> = {};
75
+ const perSymbolSlots: Record<string, SlotTypes> = {};
68
76
  for (const entry of loadTargetModules(target, packageRoot)) {
69
- for (const { identity, tsSignature } of generateModuleSignatures(entry)) {
70
- perSymbol[symbolIdentityKey(identity)] = tsSignature;
77
+ for (const signature of generateModuleSignatures(entry)) {
78
+ const key = symbolIdentityKey(signature.identity);
79
+ perSymbol[key] = signature.tsSignature;
80
+ if (Object.keys(signature.slotTypes).length > 0) {
81
+ perSymbolSlots[key] = sortObjectKeys({ ...signature.slotTypes });
82
+ }
71
83
  }
84
+ // An authored fold replaces the declaration text wholesale, so whatever
85
+ // slots the generated emit had recorded no longer describe it.
72
86
  for (const { key, fqn } of withheldSymbols(entry)) {
73
87
  const authored = authoredSignature(packageRoot, entry.namespace, fqn);
74
- if (authored !== null) perSymbol[key] = authored;
88
+ if (authored !== null) {
89
+ perSymbol[key] = authored;
90
+ delete perSymbolSlots[key];
91
+ }
75
92
  }
76
93
  }
77
94
  versions[version] = sortObjectKeys(perSymbol);
95
+ slotTypes[version] = sortObjectKeys(perSymbolSlots);
78
96
  }
79
- return { versions };
97
+ return { versions, slotTypes };
80
98
  }
81
99
 
82
100
  function biomeFormatJson(raw: string): string {
@@ -86,7 +104,14 @@ function biomeFormatJson(raw: string): string {
86
104
  if (out.exitCode !== 0) {
87
105
  throw new Error(`biome format failed: ${out.stderr.toString()}`);
88
106
  }
89
- return out.stdout.toString();
107
+ const formatted = out.stdout.toString();
108
+ // Biome exits 0 and emits nothing for input it declined to read (a payload over
109
+ // `files.maxSize` is reported only on stderr), which would otherwise serialize
110
+ // the artifact as an empty file.
111
+ if (formatted.length === 0) {
112
+ throw new Error(`biome format produced no output: ${out.stderr.toString()}`);
113
+ }
114
+ return formatted;
90
115
  }
91
116
 
92
117
  export function serializeSignaturesArtifact(artifact: SignaturesArtifact): string {