@dcl/js-runtime 7.17.1-21366395728.commit-ada88b6 → 7.17.1-21371118760.commit-fbf4826

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 +2 -2
  2. package/sdk.d.ts +87 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dcl/js-runtime",
3
3
  "description": "JavaScript runtime definitions for Decentraland environments",
4
- "version": "7.17.1-21366395728.commit-ada88b6",
4
+ "version": "7.17.1-21371118760.commit-fbf4826",
5
5
  "author": "",
6
6
  "files": [
7
7
  "index.d.ts",
@@ -20,5 +20,5 @@
20
20
  },
21
21
  "types": "./index.d.ts",
22
22
  "typings": "./index.d.ts",
23
- "commit": "ada88b6fe8e93150056e0cade4b94e0c1e7dc850"
23
+ "commit": "fbf4826ef686982ca1e60d368186e8e10c02a6e6"
24
24
  }
package/sdk.d.ts CHANGED
@@ -2,3 +2,90 @@
2
2
  declare module '~sdk/all-composites' {
3
3
  export const compositeFromLoader: Record<string, Uint8Array | string>
4
4
  }
5
+
6
+ // @internal
7
+ declare module '~sdk/script-utils' {
8
+ type Entity = number; // this will get replaced with the proper import at scene build time
9
+
10
+ /**
11
+ * Registry interface that maps script paths to their types.
12
+ * This interface is populated at build time with actual script paths.
13
+ * It starts empty and gets augmented during scene builds.
14
+ */
15
+ export interface ScriptRegistry {}
16
+
17
+ /**
18
+ * Type utility to extract the instance type from a script module.
19
+ * For class-based scripts, extracts the class instance type.
20
+ * For functional scripts, returns the module type itself.
21
+ */
22
+ export type ExtractScriptType<T> = T extends Record<string, any>
23
+ ? { [K in keyof T]: T[K] extends new (...args: any[]) => infer Instance ? Instance : never }[keyof T] extends never
24
+ ? T
25
+ : { [K in keyof T]: T[K] extends new (...args: any[]) => infer Instance ? Instance : never }[keyof T]
26
+ : never
27
+
28
+ /**
29
+ * A callback function that triggers an action on an entity.
30
+ * Use this type for script parameters that should trigger actions configured in the editor.
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * import type { ActionCallback } from '~sdk/script-utils'
35
+ *
36
+ * export class Padlock {
37
+ * constructor(
38
+ * public src: string,
39
+ * public entity: Entity,
40
+ * public onUnlock: ActionCallback
41
+ * ) {}
42
+ *
43
+ * solve() {
44
+ * this.onUnlock() // Triggers the action selected in the editor
45
+ * }
46
+ * }
47
+ * ```
48
+ */
49
+ export type ActionCallback = () => void
50
+
51
+ /**
52
+ * @deprecated
53
+ * @internal This function is called automatically by the SDK entry point.
54
+ * Users should not call this function directly.
55
+ */
56
+ export function _initializeScripts(engine: any): void
57
+
58
+ /**
59
+ * Get a specific script instance by entity and script path.
60
+ * TypeScript will automatically infer the return type based on the script path.
61
+ */
62
+ export function getScriptInstance<K extends keyof ScriptRegistry>(entity: Entity, scriptPath: K): ScriptRegistry[K] | null
63
+ export function getScriptInstance<T = any>(entity: Entity, scriptPath: string): T | null
64
+
65
+ /**
66
+ * Get all instances of a specific script (across all entities).
67
+ * TypeScript will automatically infer the instance type based on the script path.
68
+ */
69
+ export function getScriptInstancesByPath<K extends keyof ScriptRegistry>(scriptPath: K): Array<{ entity: Entity; instance: ScriptRegistry[K] }>
70
+ export function getScriptInstancesByPath<T = any>(scriptPath: string): Array<{ entity: Entity; instance: T }>
71
+
72
+ /**
73
+ * Get all script instances attached to a specific entity
74
+ */
75
+ export function getAllScriptInstances(entity: Entity): Array<{ path: string; instance: any }>
76
+
77
+ /**
78
+ * Call a method on a script instance (with safety checks).
79
+ * TypeScript will automatically infer method names, parameter types, and return types.
80
+ */
81
+ export function callScriptMethod<
82
+ K extends keyof ScriptRegistry,
83
+ M extends keyof ScriptRegistry[K]
84
+ >(
85
+ entity: Entity,
86
+ scriptPath: K,
87
+ methodName: M,
88
+ ...args: ScriptRegistry[K][M] extends (...args: infer P) => any ? P : never
89
+ ): ScriptRegistry[K][M] extends (...args: any[]) => infer R ? R : never
90
+ export function callScriptMethod(entity: Entity, scriptPath: string, methodName: string, ...args: any[]): any
91
+ }