@dcl-regenesislabs/js-runtime 0.0.0-stage → 7.0.0-42707159203.commit-ff138cd

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/index.d.ts ADDED
@@ -0,0 +1,97 @@
1
+ /// --- FETCH ---
2
+ /// <reference path="./apis.d.ts" />
3
+ /// <reference path="./sdk.d.ts" />
4
+
5
+ type RequestRedirect = 'follow' | 'error' | 'manual'
6
+ type ResponseType = 'basic' | 'cors' | 'default' | 'error' | 'opaque' | 'opaqueredirect'
7
+
8
+ interface RequestInit {
9
+ // whatwg/fetch standard options
10
+ body?: string
11
+ headers?: { [index: string]: string }
12
+ method?: string
13
+ redirect?: RequestRedirect
14
+
15
+ // custom DCL property
16
+ timeout?: number
17
+ }
18
+
19
+ interface ReadOnlyHeaders {
20
+ get(name: string): string | null
21
+ has(name: string): boolean
22
+ forEach(callbackfn: (value: string, key: string, parent: ReadOnlyHeaders) => void, thisArg?: any): void
23
+ }
24
+
25
+ interface Response {
26
+ readonly headers: ReadOnlyHeaders
27
+ readonly ok: boolean
28
+ readonly redirected: boolean
29
+ readonly status: number
30
+ readonly statusText: string
31
+ readonly type: ResponseType
32
+ readonly url: string
33
+
34
+ json(): Promise<any>
35
+ text(): Promise<string>
36
+ }
37
+
38
+ declare function fetch(url: string, init?: RequestInit): Promise<Response>
39
+
40
+ /// --- WebSocket ---
41
+
42
+ interface Event {
43
+ readonly type: string
44
+ }
45
+
46
+ interface MessageEvent extends Event {
47
+ /**
48
+ * Returns the data of the message.
49
+ */
50
+ readonly data: any
51
+ }
52
+
53
+ interface CloseEvent extends Event {
54
+ readonly code: number
55
+ readonly reason: string
56
+ readonly wasClean: boolean
57
+ }
58
+
59
+ interface WebSocket {
60
+ readonly bufferedAmount: number
61
+ readonly extensions: string
62
+ onclose: ((this: WebSocket, ev: CloseEvent) => any) | null
63
+ onerror: ((this: WebSocket, ev: Event) => any) | null
64
+ onmessage: ((this: WebSocket, ev: MessageEvent) => any) | null
65
+ onopen: ((this: WebSocket, ev: Event) => any) | null
66
+ readonly protocol: string
67
+ readonly readyState: number
68
+ readonly url: string
69
+ close(code?: number, reason?: string): void
70
+ send(data: string): void
71
+ readonly CLOSED: number
72
+ readonly CLOSING: number
73
+ readonly CONNECTING: number
74
+ readonly OPEN: number
75
+ }
76
+
77
+ declare var WebSocket: {
78
+ prototype: WebSocket
79
+ new (url: string, protocols?: string | string[]): WebSocket
80
+ readonly CLOSED: number
81
+ readonly CLOSING: number
82
+ readonly CONNECTING: number
83
+ readonly OPEN: number
84
+ }
85
+
86
+ declare var console: {
87
+ log(message?: any, ...optionalParams: any[]): void
88
+ error(message?: any, ...optionalParams: any[]): void
89
+ }
90
+
91
+ /// --- Timers ---
92
+ declare function setTimeout(callback: () => void, ms: number): number
93
+ declare function clearTimeout(timerId: number): void
94
+ declare function setInterval(callback: () => void, ms: number): number
95
+ declare function clearInterval(timerId: number): void
96
+
97
+ declare const DEBUG: boolean
package/package.json CHANGED
@@ -1,6 +1,24 @@
1
1
  {
2
2
  "name": "@dcl-regenesislabs/js-runtime",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "description": "JavaScript runtime definitions for Decentraland environments",
4
+ "version": "7.0.0-42707159203.commit-ff138cd",
5
+ "author": "",
6
+ "files": [
7
+ "index.d.ts",
8
+ "apis.d.ts",
9
+ "sdk.d.ts",
10
+ "tsconfig.json"
11
+ ],
12
+ "keywords": [],
13
+ "license": "Apache-2.0",
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/decentraland/dcl-one.git",
20
+ "directory": "library/js-sdk-toolchain/packages/@dcl/js-runtime"
21
+ },
22
+ "types": "./index.d.ts",
23
+ "typings": "./index.d.ts"
24
+ }
package/sdk.d.ts ADDED
@@ -0,0 +1,92 @@
1
+ // @internal
2
+ declare module '~sdk/all-composites' {
3
+ export const compositeFromLoader: Record<string, Uint8Array | string>
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
+ export function _initializeAssetPacks(): void
58
+
59
+ /**
60
+ * Get a specific script instance by entity and script path.
61
+ * TypeScript will automatically infer the return type based on the script path.
62
+ */
63
+ export function getScriptInstance<K extends keyof ScriptRegistry>(entity: Entity, scriptPath: K): ScriptRegistry[K] | null
64
+ export function getScriptInstance<T = any>(entity: Entity, scriptPath: string): T | null
65
+
66
+ /**
67
+ * Get all instances of a specific script (across all entities).
68
+ * TypeScript will automatically infer the instance type based on the script path.
69
+ */
70
+ export function getScriptInstancesByPath<K extends keyof ScriptRegistry>(scriptPath: K): Array<{ entity: Entity; instance: ScriptRegistry[K] }>
71
+ export function getScriptInstancesByPath<T = any>(scriptPath: string): Array<{ entity: Entity; instance: T }>
72
+
73
+ /**
74
+ * Get all script instances attached to a specific entity
75
+ */
76
+ export function getAllScriptInstances(entity: Entity): Array<{ path: string; instance: any }>
77
+
78
+ /**
79
+ * Call a method on a script instance (with safety checks).
80
+ * TypeScript will automatically infer method names, parameter types, and return types.
81
+ */
82
+ export function callScriptMethod<
83
+ K extends keyof ScriptRegistry,
84
+ M extends keyof ScriptRegistry[K]
85
+ >(
86
+ entity: Entity,
87
+ scriptPath: K,
88
+ methodName: M,
89
+ ...args: ScriptRegistry[K][M] extends (...args: infer P) => any ? P : never
90
+ ): ScriptRegistry[K][M] extends (...args: any[]) => infer R ? R : never
91
+ export function callScriptMethod(entity: Entity, scriptPath: string, methodName: string, ...args: any[]): any
92
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2020",
4
+ "module": "ESNext",
5
+ "strict": true,
6
+ "declarationDir": "dist",
7
+ "outDir": "dist",
8
+ "strictNullChecks": true,
9
+ "inlineSourceMap": true,
10
+ "inlineSources": true,
11
+ "declaration": true,
12
+ "stripInternal": true,
13
+ "moduleResolution": "Node",
14
+ "pretty": true,
15
+ "forceConsistentCasingInFileNames": true,
16
+ "allowSyntheticDefaultImports": true,
17
+ "experimentalDecorators": true,
18
+ "emitDecoratorMetadata": false,
19
+ "downlevelIteration": true,
20
+ "noUnusedLocals": true,
21
+ "lib": ["ES2020"],
22
+ "types": []
23
+ }
24
+ }