@defold-typescript/types 0.42.0 → 0.43.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.
@@ -0,0 +1,9 @@
1
+ // Generated from packages/hsm/src/defold.ts by `bun run --cwd packages/hsm declarations`; do not edit.
2
+ export type MessageEvent<K extends MessageId> = K extends MessageId ? {
3
+ readonly type: K;
4
+ } & Omit<MessagePayload<K>, "type"> : never;
5
+ /** @noSelf */
6
+ export interface MessageEventMapper<K extends MessageId> {
7
+ readonly toEvent: (message_id: Hash, message: Record<string | number, unknown>) => MessageEvent<K> | undefined;
8
+ }
9
+ export declare function messageEvents<const K extends MessageId>(ids: readonly K[]): MessageEventMapper<K>;
package/hsm/index.d.ts ADDED
@@ -0,0 +1,102 @@
1
+ // Generated from packages/hsm/src/index.ts by `bun run --cwd packages/hsm declarations`; do not edit.
2
+ export interface EventObject {
3
+ readonly type: string;
4
+ }
5
+ /** @noSelf */
6
+ export interface MachineInstance<Ctx, E extends EventObject, P extends string = string> {
7
+ readonly ctx: Ctx;
8
+ readonly path: P | undefined;
9
+ readonly matches: (path: P) => boolean;
10
+ readonly send: (event: E) => void;
11
+ readonly update: (dt: number) => void;
12
+ readonly stop: () => void;
13
+ }
14
+ export type TransitionAction<Ctx, E extends EventObject, V extends E = E> = (ctx: Ctx, event: V, m: MachineInstance<Ctx, E>) => void;
15
+ /** @noSelf */
16
+ export interface TransitionConfig<Ctx, E extends EventObject, V extends E = E> {
17
+ readonly target?: string;
18
+ readonly guard?: (ctx: Ctx, event: V) => boolean;
19
+ readonly actions?: TransitionAction<Ctx, E, V> | readonly TransitionAction<Ctx, E, V>[];
20
+ readonly reenter?: boolean;
21
+ }
22
+ export type TransitionSpec<Ctx, E extends EventObject, V extends E = E> = string | TransitionConfig<Ctx, E, V> | readonly [TransitionConfig<Ctx, E, V>, ...TransitionConfig<Ctx, E, V>[]];
23
+ export type OnConfig<Ctx, E extends EventObject> = {
24
+ readonly [K in E["type"]]?: TransitionSpec<Ctx, E, Extract<E, {
25
+ type: K;
26
+ }>>;
27
+ };
28
+ export type StateHook<Ctx, E extends EventObject> = (ctx: Ctx, m: MachineInstance<Ctx, E>) => void;
29
+ export type UpdateHook<Ctx, E extends EventObject> = (ctx: Ctx, dt: number, m: MachineInstance<Ctx, E>) => string | undefined;
30
+ /** @noSelf */
31
+ export type InvokeStart<Ctx, E extends EventObject> = (ctx: Ctx, settle: (event: E) => void, m: MachineInstance<Ctx, E>) => void;
32
+ /** @noSelf */
33
+ export interface StateConfig<Ctx, E extends EventObject> {
34
+ readonly initial?: string;
35
+ readonly states?: {
36
+ readonly [name: string]: StateConfig<Ctx, E>;
37
+ };
38
+ readonly on?: OnConfig<Ctx, E>;
39
+ readonly after?: {
40
+ readonly [seconds: number]: string;
41
+ };
42
+ readonly enter?: StateHook<Ctx, E>;
43
+ readonly exit?: StateHook<Ctx, E>;
44
+ readonly update?: UpdateHook<Ctx, E>;
45
+ readonly invoke?: InvokeStart<Ctx, E>;
46
+ }
47
+ export interface MachineConfig<Ctx, E extends EventObject> extends StateConfig<Ctx, E> {
48
+ readonly initial: string;
49
+ readonly states: {
50
+ readonly [name: string]: StateConfig<Ctx, E>;
51
+ };
52
+ }
53
+ /** @noSelf */
54
+ export interface Machine<Ctx, E extends EventObject, P extends string = string> {
55
+ readonly start: (ctx: Ctx) => MachineInstance<Ctx, E, P>;
56
+ }
57
+ type PathDepth = [never, 0, 1, 2, 3];
58
+ type PathsBelow<S, D extends number> = S extends {
59
+ readonly states: infer Children;
60
+ } ? {
61
+ [K in keyof Children & string]: K | `${K}/${D extends 1 ? Children[K] extends {
62
+ readonly states: object;
63
+ } ? string : never : PathsBelow<Children[K], PathDepth[D]>}`;
64
+ }[keyof Children & string] : never;
65
+ export type StatePath<C> = `/${PathsBelow<C, 4>}`;
66
+ interface TransitionCheck<T> {
67
+ readonly target?: T;
68
+ readonly guard?: unknown;
69
+ readonly actions?: unknown;
70
+ readonly reenter?: unknown;
71
+ }
72
+ type SpecCheck<T> = T | TransitionCheck<T> | readonly TransitionCheck<T>[];
73
+ type PathCheck<S, Self extends string, All extends string, Ev extends string> = {
74
+ readonly initial?: S extends {
75
+ readonly states: infer Children;
76
+ } ? `${Self}/${keyof Children & string}` : never;
77
+ readonly states?: S extends {
78
+ readonly states: infer Children;
79
+ } ? {
80
+ readonly [K in keyof Children]: PathCheck<Children[K], `${Self}/${K & string}`, All, Ev>;
81
+ } : unknown;
82
+ readonly on?: S extends {
83
+ readonly on: infer On;
84
+ } ? {
85
+ readonly [K in keyof On]: K extends Ev ? SpecCheck<All> : never;
86
+ } : unknown;
87
+ readonly after?: S extends {
88
+ readonly after: infer After;
89
+ } ? {
90
+ readonly [K in keyof After]: All;
91
+ } : unknown;
92
+ readonly enter?: unknown;
93
+ readonly exit?: unknown;
94
+ readonly update?: unknown;
95
+ readonly invoke?: unknown;
96
+ };
97
+ export interface MachineConfigError {
98
+ readonly "hsm: an initial or target names an unknown state path, or an on key an unknown event": never;
99
+ }
100
+ export type DefinedMachine<Ctx, E extends EventObject, C> = C extends PathCheck<C, "", StatePath<C>, E["type"]> ? Machine<Ctx, E, StatePath<C>> : MachineConfigError;
101
+ export declare function defineMachine<Ctx, E extends EventObject>(): <const C extends MachineConfig<Ctx, E>>(config: C) => DefinedMachine<Ctx, E, C>;
102
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defold-typescript/types",
3
- "version": "0.42.0",
3
+ "version": "0.43.0",
4
4
  "description": "TypeScript types for the Defold engine's Lua APIs.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -45,6 +45,12 @@
45
45
  "./timers": {
46
46
  "types": "./src/timers.d.ts"
47
47
  },
48
+ "./hsm": {
49
+ "types": "./hsm/index.d.ts"
50
+ },
51
+ "./hsm/defold": {
52
+ "types": "./hsm/defold.d.ts"
53
+ },
48
54
  "./api-availability.json": "./api-availability.json",
49
55
  "./api-signatures.json": "./api-signatures.json",
50
56
  "./url-parameters.json": "./url-parameters.json",
@@ -53,6 +59,7 @@
53
59
  "files": [
54
60
  "src",
55
61
  "generated",
62
+ "hsm",
56
63
  "scripts",
57
64
  "api-targets.json",
58
65
  "api-migrations.json",