@defold-typescript/types 0.58.0 → 0.60.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.
- package/dist/cli-runtime.js +31 -15
- package/dist/src/index.d.ts +1 -2
- package/generated/kinds/editor-script.d.ts +1 -1
- package/generated/versions/defold-1.13.0/kinds/editor-script.d.ts +1 -1
- package/generated/versions/defold-1.13.1/kinds/editor-script.d.ts +1 -1
- package/generated/versions/defold-1.13.2/kinds/editor-script.d.ts +1 -1
- package/hsm/builder.d.ts +194 -0
- package/hsm/index.d.ts +87 -2
- package/package.json +4 -1
- package/scripts/regen.ts +1 -1
- package/src/emit-dts.ts +1 -1
- package/src/index.ts +1 -5
- package/src/script-api.ts +51 -16
package/dist/cli-runtime.js
CHANGED
|
@@ -7672,12 +7672,20 @@ function slotList(value) {
|
|
|
7672
7672
|
return value.filter(isRecord3);
|
|
7673
7673
|
return isRecord3(value) ? [value] : [];
|
|
7674
7674
|
}
|
|
7675
|
+
function slotName(item) {
|
|
7676
|
+
return stringOr3(item.name, "").replace(REQUIRED_SUFFIX, "");
|
|
7677
|
+
}
|
|
7678
|
+
function isBracketed(item) {
|
|
7679
|
+
return BRACKETED_NAME.test(slotName(item));
|
|
7680
|
+
}
|
|
7675
7681
|
function isFunctionName(name) {
|
|
7676
7682
|
return name !== "None" && FUNCTION_NAME.test(name);
|
|
7677
7683
|
}
|
|
7678
7684
|
function mapSlot(item) {
|
|
7685
|
+
const name = slotName(item);
|
|
7686
|
+
const bracketed = BRACKETED_NAME.exec(name);
|
|
7679
7687
|
const slot = {
|
|
7680
|
-
name:
|
|
7688
|
+
name: bracketed ? (bracketed[1] ?? "").trim() : name,
|
|
7681
7689
|
doc: stringOr3(item.desc, ""),
|
|
7682
7690
|
types: splitTypeTokens2(item.type)
|
|
7683
7691
|
};
|
|
@@ -7688,18 +7696,15 @@ function mapSlot(item) {
|
|
|
7688
7696
|
];
|
|
7689
7697
|
if (nested.length > 0)
|
|
7690
7698
|
slot.fields = nested.map(mapSlot);
|
|
7691
|
-
if (item.optional === true)
|
|
7699
|
+
if (item.optional === true || bracketed)
|
|
7692
7700
|
slot.is_optional = "True";
|
|
7693
7701
|
return slot;
|
|
7694
7702
|
}
|
|
7703
|
+
function callSlots(raw) {
|
|
7704
|
+
return slotList(raw).filter((item) => stringOr3(item.name, "") !== "self");
|
|
7705
|
+
}
|
|
7695
7706
|
function mapParameters(raw) {
|
|
7696
|
-
|
|
7697
|
-
for (const item of slotList(raw)) {
|
|
7698
|
-
if (stringOr3(item.name, "") === "self")
|
|
7699
|
-
continue;
|
|
7700
|
-
out.push(mapSlot(item));
|
|
7701
|
-
}
|
|
7702
|
-
return out;
|
|
7707
|
+
return callSlots(raw).map(mapSlot);
|
|
7703
7708
|
}
|
|
7704
7709
|
function escapeHtml(text) {
|
|
7705
7710
|
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
@@ -7750,17 +7755,27 @@ function scriptApiToRefDoc(parsed) {
|
|
|
7750
7755
|
const members = Array.isArray(table.members) ? table.members : [];
|
|
7751
7756
|
const elements = [];
|
|
7752
7757
|
const fnElement = (name, member) => {
|
|
7758
|
+
const raw = callSlots(member.parameters ?? member.params ?? member.members);
|
|
7759
|
+
const parameters = raw.map(mapSlot);
|
|
7753
7760
|
const element = {
|
|
7754
7761
|
type: "FUNCTION",
|
|
7755
7762
|
name,
|
|
7756
7763
|
description: stringOr3(member.desc, ""),
|
|
7757
|
-
parameters
|
|
7764
|
+
parameters,
|
|
7758
7765
|
returnvalues: mapParameters(member.returns ?? member.return)
|
|
7759
7766
|
};
|
|
7760
7767
|
const examples = examplesHtml(member.examples);
|
|
7761
7768
|
if (examples !== "")
|
|
7762
7769
|
element.examples = examples;
|
|
7763
|
-
|
|
7770
|
+
const omissible = new Set(raw.flatMap((item, index) => isBracketed(item) && parameters.slice(index + 1).some((p) => p.is_optional === undefined) ? [index] : []));
|
|
7771
|
+
if (omissible.size === 0)
|
|
7772
|
+
return [element];
|
|
7773
|
+
const { examples: _examples, ...withoutExamples } = element;
|
|
7774
|
+
const omitted = {
|
|
7775
|
+
...withoutExamples,
|
|
7776
|
+
parameters: parameters.filter((_, index) => !omissible.has(index))
|
|
7777
|
+
};
|
|
7778
|
+
return [omitted, element];
|
|
7764
7779
|
};
|
|
7765
7780
|
const constantElement = (name, member) => ({
|
|
7766
7781
|
type: "CONSTANT",
|
|
@@ -7775,7 +7790,7 @@ function scriptApiToRefDoc(parsed) {
|
|
|
7775
7790
|
if (member.type === "function") {
|
|
7776
7791
|
if (!isFunctionName(stringOr3(member.name, "")))
|
|
7777
7792
|
continue;
|
|
7778
|
-
elements.push(fnElement(`${namespace}.${stringOr3(member.name, "")}`, member));
|
|
7793
|
+
elements.push(...fnElement(`${namespace}.${stringOr3(member.name, "")}`, member));
|
|
7779
7794
|
continue;
|
|
7780
7795
|
}
|
|
7781
7796
|
if (isScalar(member)) {
|
|
@@ -7793,7 +7808,7 @@ function scriptApiToRefDoc(parsed) {
|
|
|
7793
7808
|
const name = `${namespace}.${sub}.${stringOr3(subMember.name, "")}`;
|
|
7794
7809
|
if (subMember.type === "function") {
|
|
7795
7810
|
if (isFunctionName(stringOr3(subMember.name, "")))
|
|
7796
|
-
elements.push(fnElement(name, subMember));
|
|
7811
|
+
elements.push(...fnElement(name, subMember));
|
|
7797
7812
|
} else if (isScalar(subMember)) {
|
|
7798
7813
|
elements.push(constantElement(name, subMember));
|
|
7799
7814
|
}
|
|
@@ -7809,10 +7824,11 @@ function scriptApiToRefDoc(parsed) {
|
|
|
7809
7824
|
function parseScriptApi(yamlText) {
|
|
7810
7825
|
return scriptApiToRefDoc(parse(yamlText));
|
|
7811
7826
|
}
|
|
7812
|
-
var TYPE_TOKEN_ALIASES, REQUIRED_SUFFIX, FUNCTION_NAME, FENCED_BLOCK;
|
|
7827
|
+
var TYPE_TOKEN_ALIASES, REQUIRED_SUFFIX, BRACKETED_NAME, FUNCTION_NAME, FENCED_BLOCK;
|
|
7813
7828
|
var init_script_api = __esm(() => {
|
|
7814
7829
|
TYPE_TOKEN_ALIASES = new Map([["enum", "constant"]]);
|
|
7815
7830
|
REQUIRED_SUFFIX = /\s*\(required\)$/i;
|
|
7831
|
+
BRACKETED_NAME = /^\[([^[\]]+)\]$/;
|
|
7816
7832
|
FUNCTION_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
7817
7833
|
FENCED_BLOCK = /^```([\w+#.-]*)[^\n]*\n([\s\S]*?)^```[ \t]*$/gm;
|
|
7818
7834
|
});
|
|
@@ -8891,7 +8907,7 @@ var init_regen = __esm(async () => {
|
|
|
8891
8907
|
extraModules: ["../../src/editor-overloads", "../../src/editor-vm-globals"],
|
|
8892
8908
|
factory: "defineEditorScript",
|
|
8893
8909
|
extraExports: ["defineEditorCommand"],
|
|
8894
|
-
extraTypeExports: ["EditorCommandQuery", "EditorNode"],
|
|
8910
|
+
extraTypeExports: ["EditorCommand", "EditorCommandQuery", "EditorNode", "EditorScriptModule"],
|
|
8895
8911
|
factoryFrom: "../../src/editor",
|
|
8896
8912
|
propertyTypes: false,
|
|
8897
8913
|
jit: false
|
package/dist/src/index.d.ts
CHANGED
|
@@ -3,8 +3,7 @@ export type { ApiFunction, ApiModule, ApiParameter, ApiVariable, SkipOverloadRul
|
|
|
3
3
|
export { parseDefoldApiDoc, withholdOverloads } from "./api-doc";
|
|
4
4
|
export { DEFOLD_TYPE_MAP, type Hash, type Matrix4, type Quaternion, type Url, type Vector, type Vector3, type Vector4, } from "./core-types";
|
|
5
5
|
export { type DocCommentParts, type ExampleSegment, type ExampleSegmentation, examplesHtmlToMarkdown, htmlToCodeText, htmlToDocText, renderDocComment, segmentExampleRegions, splitExampleSources, } from "./doc-comment";
|
|
6
|
-
export {
|
|
7
|
-
export { type EmitOptions, emitDeclarations, emitSymbolSignatures, firstSlotAlternativeOf, routeTypeDeclarations, type SlotType, type SlotTypes, type SymbolSignature, TS_IDENTIFIER, TS_RESERVED_NAMES, } from "./emit-dts";
|
|
6
|
+
export { type EmitOptions, emitDeclarations, emitSymbolSignatures, firstSlotAlternativeOf, isFunctionTypeText, routeTypeDeclarations, type SlotType, type SlotTypes, type SymbolSignature, TS_IDENTIFIER, TS_RESERVED_NAMES, } from "./emit-dts";
|
|
8
7
|
export { ENGINE_TYPE_NAME_OVERRIDES, engineTypeName } from "./engine-type-name";
|
|
9
8
|
export { hashExampleSource, lookupExampleSegments, lookupExampleTranslations, lookupTranslation, proseLuaFences, type Translation, type TranslationStore, translateProseFences, } from "./example-store";
|
|
10
9
|
export { type EngineIndexBaseRow, engineIndexBaseRows, engineIndexBaseTable, } from "./index-base-table";
|
|
@@ -11,4 +11,4 @@ import "../../src/editor-overloads";
|
|
|
11
11
|
import "../../src/editor-vm-globals";
|
|
12
12
|
|
|
13
13
|
export { defineEditorScript, defineEditorCommand } from "../../src/editor";
|
|
14
|
-
export type { EditorCommandQuery, EditorNode } from "../../src/editor";
|
|
14
|
+
export type { EditorCommand, EditorCommandQuery, EditorNode, EditorScriptModule } from "../../src/editor";
|
|
@@ -10,4 +10,4 @@ import "../../../../src/editor-overloads";
|
|
|
10
10
|
import "../../../../src/editor-vm-globals";
|
|
11
11
|
|
|
12
12
|
export { defineEditorScript, defineEditorCommand } from "../../../../src/editor";
|
|
13
|
-
export type { EditorCommandQuery, EditorNode } from "../../../../src/editor";
|
|
13
|
+
export type { EditorCommand, EditorCommandQuery, EditorNode, EditorScriptModule } from "../../../../src/editor";
|
|
@@ -11,4 +11,4 @@ import "../../../../src/editor-overloads";
|
|
|
11
11
|
import "../../../../src/editor-vm-globals";
|
|
12
12
|
|
|
13
13
|
export { defineEditorScript, defineEditorCommand } from "../../../../src/editor";
|
|
14
|
-
export type { EditorCommandQuery, EditorNode } from "../../../../src/editor";
|
|
14
|
+
export type { EditorCommand, EditorCommandQuery, EditorNode, EditorScriptModule } from "../../../../src/editor";
|
|
@@ -11,4 +11,4 @@ import "../../../../src/editor-overloads";
|
|
|
11
11
|
import "../../../../src/editor-vm-globals";
|
|
12
12
|
|
|
13
13
|
export { defineEditorScript, defineEditorCommand } from "../../../../src/editor";
|
|
14
|
-
export type { EditorCommandQuery, EditorNode } from "../../../../src/editor";
|
|
14
|
+
export type { EditorCommand, EditorCommandQuery, EditorNode, EditorScriptModule } from "../../../../src/editor";
|
package/hsm/builder.d.ts
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// Generated from packages/hsm/src/builder.ts by `bun run --cwd packages/transpiler declarations`; do not edit.
|
|
2
|
+
import { type AfterRule, type AlwaysConfig, type EventObject, type Machine, type MachineSkeleton, type MoveAction, type PrivateCtxConfig, type RunAction, type StateHook, type TaskStart, type TransitionConfig, type TreePath, type UnhandledHook, type UpdateHook, type WithPrivate } from "./index";
|
|
3
|
+
type Delay<Ctx> = number | ((ctx: Readonly<Ctx>) => number);
|
|
4
|
+
type EventGuard<Ctx, E extends EventObject, V extends E, P extends string, Tag extends string> = NonNullable<TransitionConfig<Ctx, E, V, P, Tag, P>["when"]>;
|
|
5
|
+
type TimerGuard<Ctx, E extends EventObject, P extends string, Tag extends string> = NonNullable<AfterRule<Ctx, P, E, Tag, P>["when"]>;
|
|
6
|
+
type AlwaysGuard<Ctx, E extends EventObject, P extends string, Tag extends string> = NonNullable<AlwaysConfig<Ctx, P, E, Tag, P>["when"]>;
|
|
7
|
+
/**
|
|
8
|
+
* Adds behavior to a machine whose structure is a skeleton, returned by the second `buildMachine`
|
|
9
|
+
* call. `P` is the union of the skeleton's state paths, and every path a statement takes is one
|
|
10
|
+
* of them.
|
|
11
|
+
* @noSelf
|
|
12
|
+
*/
|
|
13
|
+
export interface MachineBuilder<Ctx, E extends EventObject, P extends string, Tag extends string = never, Priv = never> {
|
|
14
|
+
/**
|
|
15
|
+
* The builder of the state at the full path `path`, such as `/on/bright`. A path the skeleton
|
|
16
|
+
* lacks throws.
|
|
17
|
+
*/
|
|
18
|
+
readonly state: (path: P) => StateBuilder<WithPrivate<Ctx, Priv>, E, P, Tag>;
|
|
19
|
+
/** The builder of the root, whose rules take an event no state below it takes. */
|
|
20
|
+
readonly root: StateBuilder<WithPrivate<Ctx, Priv>, E, P, Tag>;
|
|
21
|
+
/**
|
|
22
|
+
* Writes the statements onto the skeleton's own state objects, in list form, and passes the
|
|
23
|
+
* skeleton and the key to `defineMachine`, returning its machine. It throws, naming the state,
|
|
24
|
+
* on a rule left without its ending, and a second call throws.
|
|
25
|
+
*/
|
|
26
|
+
readonly build: () => Machine<Ctx, E, P, Tag>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Adds behavior to one state. Each `on`, `after`, `every` and `always` call adds one entry, in
|
|
30
|
+
* call order. A state's `on`, `every` and `always` entries are tried in that order, and its
|
|
31
|
+
* `after` timers in delay order, call order breaking ties. `enter`, `exit`, `update`, `task` and
|
|
32
|
+
* `unhandled` each take one function: a second call on the same state throws. Every call throws
|
|
33
|
+
* after `build()`.
|
|
34
|
+
* @noSelf
|
|
35
|
+
*/
|
|
36
|
+
export interface StateBuilder<Ctx, E extends EventObject, P extends string, Tag extends string> {
|
|
37
|
+
/**
|
|
38
|
+
* Adds a rule for events of type `type`, whose `when` and `run` see that variant. End it with
|
|
39
|
+
* `to`, `run` or `ignore`.
|
|
40
|
+
*/
|
|
41
|
+
readonly on: <K extends E["type"]>(type: K) => EventRuleBuilder<Ctx, E, Extract<E, {
|
|
42
|
+
type: K;
|
|
43
|
+
}>, P, Tag>;
|
|
44
|
+
/**
|
|
45
|
+
* Adds a timer that fires once `delay` seconds of game time have passed in the state: a number,
|
|
46
|
+
* or a function of the context read each time the state is entered. A state's timers are tried
|
|
47
|
+
* in delay order, call order breaking ties. End it with `to` or `run`.
|
|
48
|
+
*/
|
|
49
|
+
readonly after: (delay: Delay<Ctx>) => TimerRuleBuilder<Ctx, E, P, Tag>;
|
|
50
|
+
/**
|
|
51
|
+
* Adds functions run each time `delay` seconds of game time pass in the state: a number, or a
|
|
52
|
+
* function of the context read each time the state is entered. End it with `run`.
|
|
53
|
+
*/
|
|
54
|
+
readonly every: (delay: Delay<Ctx>) => RunBuilder<Ctx, E, P, Tag>;
|
|
55
|
+
/** Adds a rule taken right after any move that leaves the state active. End it with `to`. */
|
|
56
|
+
readonly always: () => AlwaysRuleBuilder<Ctx, E, P, Tag>;
|
|
57
|
+
/** Sets the function run each time the state is entered. */
|
|
58
|
+
readonly enter: (hook: StateHook<Ctx, E, Tag, P>) => void;
|
|
59
|
+
/** Sets the function run each time the state is left. */
|
|
60
|
+
readonly exit: (hook: StateHook<Ctx, E, Tag, P>) => void;
|
|
61
|
+
/**
|
|
62
|
+
* Sets the function run on every `update(dt)` while the state is active, which returns a full
|
|
63
|
+
* path to move there, or `undefined` to stay.
|
|
64
|
+
*/
|
|
65
|
+
readonly update: (hook: UpdateHook<Ctx, E, P, Tag, P>) => void;
|
|
66
|
+
/** Sets the work started on each entry; see `TaskStart`. */
|
|
67
|
+
readonly task: (start: TaskStart<Ctx, E, Tag, P>) => void;
|
|
68
|
+
/** Sets the function run when the machine drops an event while the state is active. */
|
|
69
|
+
readonly unhandled: (hook: UnhandledHook<Ctx, E, Tag, P>) => void;
|
|
70
|
+
/** Adds tag names that hold while the state is active, read with `hasTag`. */
|
|
71
|
+
readonly tags: (...names: Tag[]) => void;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The rule an `on` call added, before its ending. `build()` throws on a rule left without `to`,
|
|
75
|
+
* `run` or `ignore`.
|
|
76
|
+
* @noSelf
|
|
77
|
+
*/
|
|
78
|
+
export interface EventRuleBuilder<Ctx, E extends EventObject, V extends E, P extends string, Tag extends string> {
|
|
79
|
+
/**
|
|
80
|
+
* Takes the rule only when `guard` returns `true`. It reads `ctx` and `event` and changes
|
|
81
|
+
* neither.
|
|
82
|
+
*/
|
|
83
|
+
readonly when: (guard: EventGuard<Ctx, E, V, P, Tag>) => GuardedEventRuleBuilder<Ctx, E, V, P, Tag>;
|
|
84
|
+
/** Ends the rule with the full path of the state to move to. */
|
|
85
|
+
readonly to: (path: P) => EventRunBuilder<Ctx, E, V, P, Tag>;
|
|
86
|
+
/** Ends the rule with functions run in order, with no move: no state exits or enters. */
|
|
87
|
+
readonly run: (...actions: MoveAction<Ctx, E, V, Tag, P>[]) => void;
|
|
88
|
+
/**
|
|
89
|
+
* Ends the rule with nothing to do: the state takes the event, so it stops there and no rule
|
|
90
|
+
* of a parent sees it.
|
|
91
|
+
*/
|
|
92
|
+
readonly ignore: () => void;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* An `on` rule after its `when`, before its ending.
|
|
96
|
+
* @noSelf
|
|
97
|
+
*/
|
|
98
|
+
export interface GuardedEventRuleBuilder<Ctx, E extends EventObject, V extends E, P extends string, Tag extends string> {
|
|
99
|
+
/** Ends the rule with the full path of the state to move to. */
|
|
100
|
+
readonly to: (path: P) => EventRunBuilder<Ctx, E, V, P, Tag>;
|
|
101
|
+
/** Ends the rule with functions run in order, with no move: no state exits or enters. */
|
|
102
|
+
readonly run: (...actions: MoveAction<Ctx, E, V, Tag, P>[]) => void;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* An `on` rule after its `to`.
|
|
106
|
+
* @noSelf
|
|
107
|
+
*/
|
|
108
|
+
export interface EventRunBuilder<Ctx, E extends EventObject, V extends E, P extends string, Tag extends string> {
|
|
109
|
+
/** Adds functions run in order during the move, after the `exit` hooks and before `enter`. */
|
|
110
|
+
readonly run: (...actions: MoveAction<Ctx, E, V, Tag, P>[]) => void;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The timer an `after` call added, before its ending. `build()` throws on a timer left without
|
|
114
|
+
* `to` or `run`.
|
|
115
|
+
* @noSelf
|
|
116
|
+
*/
|
|
117
|
+
export interface TimerRuleBuilder<Ctx, E extends EventObject, P extends string, Tag extends string> {
|
|
118
|
+
/**
|
|
119
|
+
* Fires the timer only when `guard` returns `true`, checked once the delay has passed and then
|
|
120
|
+
* on every `update` call until it passes. It reads `ctx` and changes nothing.
|
|
121
|
+
*/
|
|
122
|
+
readonly when: (guard: TimerGuard<Ctx, E, P, Tag>) => GuardedTimerRuleBuilder<Ctx, E, P, Tag>;
|
|
123
|
+
/** Ends the timer with the full path of the state to move to. */
|
|
124
|
+
readonly to: (path: P) => RunBuilder<Ctx, E, P, Tag>;
|
|
125
|
+
/** Ends the timer with functions run in order when it fires, with no move. */
|
|
126
|
+
readonly run: (...actions: RunAction<Ctx, E, Tag, P>[]) => void;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* An `after` timer after its `when`, before its ending.
|
|
130
|
+
* @noSelf
|
|
131
|
+
*/
|
|
132
|
+
export interface GuardedTimerRuleBuilder<Ctx, E extends EventObject, P extends string, Tag extends string> {
|
|
133
|
+
/** Ends the timer with the full path of the state to move to. */
|
|
134
|
+
readonly to: (path: P) => RunBuilder<Ctx, E, P, Tag>;
|
|
135
|
+
/** Ends the timer with functions run in order when it fires, with no move. */
|
|
136
|
+
readonly run: (...actions: RunAction<Ctx, E, Tag, P>[]) => void;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* An `every` entry, or an `after` timer or `always` rule after its `to`.
|
|
140
|
+
* @noSelf
|
|
141
|
+
*/
|
|
142
|
+
export interface RunBuilder<Ctx, E extends EventObject, P extends string, Tag extends string> {
|
|
143
|
+
/**
|
|
144
|
+
* Adds functions run in order: each time the delay passes for an `every` entry, and during the
|
|
145
|
+
* move for a timer or an `always` rule.
|
|
146
|
+
*/
|
|
147
|
+
readonly run: (...actions: RunAction<Ctx, E, Tag, P>[]) => void;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* The rule an `always` call added, before its `to`. `build()` throws on a rule left without one.
|
|
151
|
+
* @noSelf
|
|
152
|
+
*/
|
|
153
|
+
export interface AlwaysRuleBuilder<Ctx, E extends EventObject, P extends string, Tag extends string> {
|
|
154
|
+
/** Takes the rule only when `guard` returns `true`. It reads `ctx` and changes nothing. */
|
|
155
|
+
readonly when: (guard: AlwaysGuard<Ctx, E, P, Tag>) => GuardedAlwaysRuleBuilder<Ctx, E, P, Tag>;
|
|
156
|
+
/** Ends the rule with the full path of the state to move to. */
|
|
157
|
+
readonly to: (path: P) => RunBuilder<Ctx, E, P, Tag>;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* An `always` rule after its `when`, before its `to`.
|
|
161
|
+
* @noSelf
|
|
162
|
+
*/
|
|
163
|
+
export interface GuardedAlwaysRuleBuilder<Ctx, E extends EventObject, P extends string, Tag extends string> {
|
|
164
|
+
/** Ends the rule with the full path of the state to move to. */
|
|
165
|
+
readonly to: (path: P) => RunBuilder<Ctx, E, P, Tag>;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Defines a machine as a skeleton plus statements, in three steps. `buildMachine<Ctx, E>()` fixes
|
|
169
|
+
* the context and event types and takes an optional hot reload key, as `defineMachine` does; a
|
|
170
|
+
* third type argument is the union of tag names. The second call takes the skeleton: the root's
|
|
171
|
+
* `initial` and `states`, an optional `privateCtx`, and on each state only `initial`, `states`,
|
|
172
|
+
* `type` and `restoreDepth`. It returns a `MachineBuilder`, whose `state(path)` and `root` add
|
|
173
|
+
* behavior one statement at a time, and whose `build()` defines the machine.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```ts
|
|
177
|
+
* type LampEvent = { type: "TOGGLE" } | { type: "DIM" };
|
|
178
|
+
*
|
|
179
|
+
* const m = buildMachine<object, LampEvent>("lamp")({
|
|
180
|
+
* initial: "/off",
|
|
181
|
+
* states: {
|
|
182
|
+
* off: {},
|
|
183
|
+
* on: { initial: "/on/bright", states: { bright: {}, dim: {} } },
|
|
184
|
+
* },
|
|
185
|
+
* });
|
|
186
|
+
* m.state("/off").on("TOGGLE").to("/on");
|
|
187
|
+
* m.state("/on").on("TOGGLE").to("/off");
|
|
188
|
+
* m.state("/on/bright").on("DIM").to("/on/dim");
|
|
189
|
+
*
|
|
190
|
+
* export const lamp = m.build();
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
export declare function buildMachine<Ctx, E extends EventObject, Tag extends string = never>(key?: string): <T, Priv extends object = never>(skeleton: MachineSkeleton<T> & PrivateCtxConfig<Ctx, Priv>) => MachineBuilder<Ctx, E, TreePath<T>, Tag, Priv>;
|
|
194
|
+
export {};
|
package/hsm/index.d.ts
CHANGED
|
@@ -345,7 +345,12 @@ type NextCount = [never, 2, 3, 4, 5, 6];
|
|
|
345
345
|
type TreePathsBelow<T, D extends number> = {
|
|
346
346
|
[K in keyof T & string]: K | `${K}/${D extends 1 ? keyof T[K] extends never ? never : string : TreePathsBelow<T[K], PathDepth[D]>}`;
|
|
347
347
|
}[keyof T & string];
|
|
348
|
-
|
|
348
|
+
/**
|
|
349
|
+
* The union of the state paths of the tree `T`, each with its leading `/`: `T` holds one key per
|
|
350
|
+
* state name, and a leaf is `unknown`. Paths are spelled out four levels deep; below that, any
|
|
351
|
+
* string under a fourth-level path is accepted.
|
|
352
|
+
*/
|
|
353
|
+
export type TreePath<T> = `/${TreePathsBelow<T, 4>}`;
|
|
349
354
|
type TreeOf<C> = C extends {
|
|
350
355
|
readonly states: infer Children;
|
|
351
356
|
} ? {
|
|
@@ -515,7 +520,87 @@ export type MachineConfig<Ctx, E extends EventObject, Tag extends string = never
|
|
|
515
520
|
readonly [name: string]: StateConfig<Ctx, E, Tag>;
|
|
516
521
|
};
|
|
517
522
|
};
|
|
518
|
-
|
|
523
|
+
interface SkeletonBehavior {
|
|
524
|
+
/** Not taken in a skeleton: add tags with the state builder's `tags`. */
|
|
525
|
+
readonly tags?: never;
|
|
526
|
+
/** Not taken in a skeleton: add rules with the state builder's `on`. */
|
|
527
|
+
readonly on?: never;
|
|
528
|
+
/** Not taken in a skeleton: add timers with the state builder's `after`. */
|
|
529
|
+
readonly after?: never;
|
|
530
|
+
/** Not taken in a skeleton: add repeated runs with the state builder's `every`. */
|
|
531
|
+
readonly every?: never;
|
|
532
|
+
/** Not taken in a skeleton: add rules with the state builder's `always`. */
|
|
533
|
+
readonly always?: never;
|
|
534
|
+
/** Not taken in a skeleton: add the hook with the state builder's `enter`. */
|
|
535
|
+
readonly enter?: never;
|
|
536
|
+
/** Not taken in a skeleton: add the hook with the state builder's `exit`. */
|
|
537
|
+
readonly exit?: never;
|
|
538
|
+
/** Not taken in a skeleton: add the hook with the state builder's `update`. */
|
|
539
|
+
readonly update?: never;
|
|
540
|
+
/** Not taken in a skeleton: add the task with the state builder's `task`. */
|
|
541
|
+
readonly task?: never;
|
|
542
|
+
/** Not taken in a skeleton: add the hook with the state builder's `unhandled`. */
|
|
543
|
+
readonly unhandled?: never;
|
|
544
|
+
}
|
|
545
|
+
interface SkeletonState<T, Self extends string> extends SkeletonBehavior {
|
|
546
|
+
/** Child states, by name. A name is non-empty and contains no `/`. */
|
|
547
|
+
readonly states?: {
|
|
548
|
+
readonly [K in keyof T]: SkeletonNode<T[K], `${Self}/${K & string}`>;
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
interface CompoundSkeleton<T, Self extends string> extends SkeletonState<T, Self> {
|
|
552
|
+
/**
|
|
553
|
+
* `"parallel"` keeps every child active at once, each as a region with its own active state.
|
|
554
|
+
*/
|
|
555
|
+
readonly type?: never;
|
|
556
|
+
/**
|
|
557
|
+
* The full path of the child entered with this state, such as `/on/bright` inside `on`.
|
|
558
|
+
* Required when `states` is set, unless the state is parallel. Not taken on a leaf.
|
|
559
|
+
*/
|
|
560
|
+
readonly initial?: NoInfer<unknown extends T ? never : `${Self}/${keyof T & string}`>;
|
|
561
|
+
/**
|
|
562
|
+
* Makes the state remember which child was active when it was last left, and enter it again
|
|
563
|
+
* instead of `initial`; see `restoreDepth` on a state config. Not taken on a leaf.
|
|
564
|
+
*/
|
|
565
|
+
readonly restoreDepth?: NoInfer<unknown extends T ? never : TreeDepth<T, 4> | "all">;
|
|
566
|
+
}
|
|
567
|
+
interface ParallelSkeleton<T, Self extends string> extends SkeletonState<T, Self> {
|
|
568
|
+
/**
|
|
569
|
+
* `"parallel"` keeps every child active at once, each as a region with its own active state.
|
|
570
|
+
*/
|
|
571
|
+
readonly type: "parallel";
|
|
572
|
+
/** Not taken on a parallel state: every child is entered. */
|
|
573
|
+
readonly initial?: never;
|
|
574
|
+
/** Not taken on a parallel state: only a compound state resumes a child. */
|
|
575
|
+
readonly restoreDepth?: never;
|
|
576
|
+
}
|
|
577
|
+
type SkeletonNode<T, Self extends string> = CompoundSkeleton<T, Self> | ParallelSkeleton<T, Self>;
|
|
578
|
+
/**
|
|
579
|
+
* The skeleton `buildMachine` takes: the structure of a machine with no behavior. The root holds
|
|
580
|
+
* `initial` and `states`, and each state only `initial`, `states`, `type` and `restoreDepth`, each
|
|
581
|
+
* checked as in a `defineMachine` config. `T` is the state tree read from the `states` keys, and
|
|
582
|
+
* fixes the paths every statement takes.
|
|
583
|
+
*/
|
|
584
|
+
export type MachineSkeleton<T> = SkeletonBehavior & {
|
|
585
|
+
/** The full path of the child entered at `start`, such as `/idle`. */
|
|
586
|
+
readonly initial: NoInfer<`/${keyof T & string}`>;
|
|
587
|
+
/** The machine's states, by name. A name is non-empty and contains no `/`. */
|
|
588
|
+
readonly states: {
|
|
589
|
+
readonly [K in keyof T]: SkeletonNode<T[K], `/${K & string}`>;
|
|
590
|
+
};
|
|
591
|
+
/** Not allowed on the root: put the regions in a child state. */
|
|
592
|
+
readonly type?: never;
|
|
593
|
+
/**
|
|
594
|
+
* Makes every state the count reaches remember its last child; see `restoreDepth` on a state
|
|
595
|
+
* config.
|
|
596
|
+
*/
|
|
597
|
+
readonly restoreDepth?: NoInfer<TreeDepth<T, 4> | "all">;
|
|
598
|
+
};
|
|
599
|
+
/**
|
|
600
|
+
* The context a machine's hooks see: `Ctx` for a machine without `privateCtx`, and `Ctx & Priv`
|
|
601
|
+
* for one whose `privateCtx` returns `Priv`.
|
|
602
|
+
*/
|
|
603
|
+
export type WithPrivate<Ctx, Priv> = [Priv] extends [never] ? Ctx : Ctx & Priv;
|
|
519
604
|
/**
|
|
520
605
|
* Defines a machine in two calls: `defineMachine<Ctx, E>()` fixes the context and event types and
|
|
521
606
|
* takes an optional hot-reload key, and the second call takes the config. The config is checked
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defold-typescript/types",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.60.0",
|
|
4
4
|
"description": "TypeScript types for the Defold engine's Lua APIs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -51,6 +51,9 @@
|
|
|
51
51
|
"./hsm/async": {
|
|
52
52
|
"types": "./hsm/async.d.ts"
|
|
53
53
|
},
|
|
54
|
+
"./hsm/builder": {
|
|
55
|
+
"types": "./hsm/builder.d.ts"
|
|
56
|
+
},
|
|
54
57
|
"./hsm/debug": {
|
|
55
58
|
"types": "./hsm/debug.d.ts"
|
|
56
59
|
},
|
package/scripts/regen.ts
CHANGED
|
@@ -1145,7 +1145,7 @@ export const KIND_MODULE_MANIFEST: readonly KindManifestEntry[] = [
|
|
|
1145
1145
|
extraModules: ["../../src/editor-overloads", "../../src/editor-vm-globals"],
|
|
1146
1146
|
factory: "defineEditorScript",
|
|
1147
1147
|
extraExports: ["defineEditorCommand"],
|
|
1148
|
-
extraTypeExports: ["EditorCommandQuery", "EditorNode"],
|
|
1148
|
+
extraTypeExports: ["EditorCommand", "EditorCommandQuery", "EditorNode", "EditorScriptModule"],
|
|
1149
1149
|
factoryFrom: "../../src/editor",
|
|
1150
1150
|
propertyTypes: false,
|
|
1151
1151
|
jit: false,
|
package/src/emit-dts.ts
CHANGED
|
@@ -6503,7 +6503,7 @@ function parameterType(
|
|
|
6503
6503
|
return added.length === 0 ? kept : `${kept} | ${added.join(" | ")}`;
|
|
6504
6504
|
}
|
|
6505
6505
|
|
|
6506
|
-
function isFunctionTypeText(ts: string): boolean {
|
|
6506
|
+
export function isFunctionTypeText(ts: string): boolean {
|
|
6507
6507
|
let depth = 0;
|
|
6508
6508
|
for (let i = 0; i < ts.length - 1; i++) {
|
|
6509
6509
|
const c = ts[i];
|
package/src/index.ts
CHANGED
|
@@ -50,16 +50,12 @@ export {
|
|
|
50
50
|
segmentExampleRegions,
|
|
51
51
|
splitExampleSources,
|
|
52
52
|
} from "./doc-comment";
|
|
53
|
-
export {
|
|
54
|
-
defineEditorScript,
|
|
55
|
-
type EditorCommand,
|
|
56
|
-
type EditorScriptModule,
|
|
57
|
-
} from "./editor";
|
|
58
53
|
export {
|
|
59
54
|
type EmitOptions,
|
|
60
55
|
emitDeclarations,
|
|
61
56
|
emitSymbolSignatures,
|
|
62
57
|
firstSlotAlternativeOf,
|
|
58
|
+
isFunctionTypeText,
|
|
63
59
|
routeTypeDeclarations,
|
|
64
60
|
type SlotType,
|
|
65
61
|
type SlotTypes,
|
package/src/script-api.ts
CHANGED
|
@@ -71,6 +71,18 @@ function slotList(value: unknown): Record<string, unknown>[] {
|
|
|
71
71
|
// every slot is already required unless flagged optional, so the suffix is noise.
|
|
72
72
|
const REQUIRED_SUFFIX = /\s*\(required\)$/i;
|
|
73
73
|
|
|
74
|
+
// Upstream writes an omissible slot in call-syntax brackets (`[options]`), the
|
|
75
|
+
// same convention its own `desc` prose uses for an optional argument.
|
|
76
|
+
const BRACKETED_NAME = /^\[([^[\]]+)\]$/;
|
|
77
|
+
|
|
78
|
+
function slotName(item: Record<string, unknown>): string {
|
|
79
|
+
return stringOr(item.name, "").replace(REQUIRED_SUFFIX, "");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function isBracketed(item: Record<string, unknown>): boolean {
|
|
83
|
+
return BRACKETED_NAME.test(slotName(item));
|
|
84
|
+
}
|
|
85
|
+
|
|
74
86
|
// Generators emit placeholder or C-signature names (`None`, `int JoinRandomRoom`)
|
|
75
87
|
// that cannot form a Lua member access, so no page or declaration can carry them.
|
|
76
88
|
const FUNCTION_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
@@ -80,8 +92,10 @@ function isFunctionName(name: string): boolean {
|
|
|
80
92
|
}
|
|
81
93
|
|
|
82
94
|
function mapSlot(item: Record<string, unknown>): RefDocParameter {
|
|
95
|
+
const name = slotName(item);
|
|
96
|
+
const bracketed = BRACKETED_NAME.exec(name);
|
|
83
97
|
const slot: RefDocParameter = {
|
|
84
|
-
name:
|
|
98
|
+
name: bracketed ? (bracketed[1] ?? "").trim() : name,
|
|
85
99
|
doc: stringOr(item.desc, ""),
|
|
86
100
|
types: splitTypeTokens(item.type),
|
|
87
101
|
};
|
|
@@ -94,19 +108,18 @@ function mapSlot(item: Record<string, unknown>): RefDocParameter {
|
|
|
94
108
|
...slotList(item.members),
|
|
95
109
|
];
|
|
96
110
|
if (nested.length > 0) slot.fields = nested.map(mapSlot);
|
|
97
|
-
if (item.optional === true) slot.is_optional = "True";
|
|
111
|
+
if (item.optional === true || bracketed) slot.is_optional = "True";
|
|
98
112
|
return slot;
|
|
99
113
|
}
|
|
100
114
|
|
|
115
|
+
// The script_api lists the implicit `self` the engine passes; the emitter
|
|
116
|
+
// stamps @noSelfInFile, so generated signatures must not declare it.
|
|
117
|
+
function callSlots(raw: unknown): Record<string, unknown>[] {
|
|
118
|
+
return slotList(raw).filter((item) => stringOr(item.name, "") !== "self");
|
|
119
|
+
}
|
|
120
|
+
|
|
101
121
|
function mapParameters(raw: unknown): RefDocParameter[] {
|
|
102
|
-
|
|
103
|
-
for (const item of slotList(raw)) {
|
|
104
|
-
// The script_api lists the implicit `self` the engine passes; the emitter
|
|
105
|
-
// stamps @noSelfInFile, so generated signatures must not declare it.
|
|
106
|
-
if (stringOr(item.name, "") === "self") continue;
|
|
107
|
-
out.push(mapSlot(item));
|
|
108
|
-
}
|
|
109
|
-
return out;
|
|
122
|
+
return callSlots(raw).map(mapSlot);
|
|
110
123
|
}
|
|
111
124
|
|
|
112
125
|
function escapeHtml(text: string): string {
|
|
@@ -166,7 +179,11 @@ function isScalar(member: Record<string, unknown>): boolean {
|
|
|
166
179
|
* present of `parameters:`, `params:` or `members:` and its returns from
|
|
167
180
|
* `returns:` or `return:`, any slot list may be a single mapping, a table slot's
|
|
168
181
|
* `members:` nest like `fields:`, a `(REQUIRED)` name suffix is dropped, and a
|
|
169
|
-
* function named `None` or not a Lua identifier is skipped.
|
|
182
|
+
* function named `None` or not a Lua identifier is skipped. A slot or field
|
|
183
|
+
* named in brackets (`[options]`) takes the bare name and `is_optional`, and a
|
|
184
|
+
* function with such a slot before a slot that is not optional is also
|
|
185
|
+
* converted, first and without its examples, as a form that leaves out every
|
|
186
|
+
* such bracketed slot.
|
|
170
187
|
*/
|
|
171
188
|
export function scriptApiToRefDoc(parsed: unknown): RefDoc {
|
|
172
189
|
if (!Array.isArray(parsed)) {
|
|
@@ -188,17 +205,35 @@ export function scriptApiToRefDoc(parsed: unknown): RefDoc {
|
|
|
188
205
|
}
|
|
189
206
|
const members = Array.isArray(table.members) ? table.members : [];
|
|
190
207
|
const elements: RefDocElement[] = [];
|
|
191
|
-
const fnElement = (name: string, member: Record<string, unknown>): RefDocFunctionElement => {
|
|
208
|
+
const fnElement = (name: string, member: Record<string, unknown>): RefDocFunctionElement[] => {
|
|
209
|
+
const raw = callSlots(member.parameters ?? member.params ?? member.members);
|
|
210
|
+
const parameters = raw.map(mapSlot);
|
|
192
211
|
const element: RefDocFunctionElement = {
|
|
193
212
|
type: "FUNCTION",
|
|
194
213
|
name,
|
|
195
214
|
description: stringOr(member.desc, ""),
|
|
196
|
-
parameters
|
|
215
|
+
parameters,
|
|
197
216
|
returnvalues: mapParameters(member.returns ?? member.return),
|
|
198
217
|
};
|
|
199
218
|
const examples = examplesHtml(member.examples);
|
|
200
219
|
if (examples !== "") element.examples = examples;
|
|
201
|
-
|
|
220
|
+
// A bracketed slot a required one follows can only be left out by a call
|
|
221
|
+
// that skips it, so that call gets its own form; an explicit
|
|
222
|
+
// `optional: true` slot reads as passable-nil instead and gets none.
|
|
223
|
+
const omissible = new Set(
|
|
224
|
+
raw.flatMap((item, index) =>
|
|
225
|
+
isBracketed(item) && parameters.slice(index + 1).some((p) => p.is_optional === undefined)
|
|
226
|
+
? [index]
|
|
227
|
+
: [],
|
|
228
|
+
),
|
|
229
|
+
);
|
|
230
|
+
if (omissible.size === 0) return [element];
|
|
231
|
+
const { examples: _examples, ...withoutExamples } = element;
|
|
232
|
+
const omitted: RefDocFunctionElement = {
|
|
233
|
+
...withoutExamples,
|
|
234
|
+
parameters: parameters.filter((_, index) => !omissible.has(index)),
|
|
235
|
+
};
|
|
236
|
+
return [omitted, element];
|
|
202
237
|
};
|
|
203
238
|
const constantElement = (
|
|
204
239
|
name: string,
|
|
@@ -214,7 +249,7 @@ export function scriptApiToRefDoc(parsed: unknown): RefDoc {
|
|
|
214
249
|
if (!isRecord(member)) continue;
|
|
215
250
|
if (member.type === "function") {
|
|
216
251
|
if (!isFunctionName(stringOr(member.name, ""))) continue;
|
|
217
|
-
elements.push(fnElement(`${namespace}.${stringOr(member.name, "")}`, member));
|
|
252
|
+
elements.push(...fnElement(`${namespace}.${stringOr(member.name, "")}`, member));
|
|
218
253
|
continue;
|
|
219
254
|
}
|
|
220
255
|
if (isScalar(member)) {
|
|
@@ -233,7 +268,7 @@ export function scriptApiToRefDoc(parsed: unknown): RefDoc {
|
|
|
233
268
|
const name = `${namespace}.${sub}.${stringOr(subMember.name, "")}`;
|
|
234
269
|
if (subMember.type === "function") {
|
|
235
270
|
if (isFunctionName(stringOr(subMember.name, "")))
|
|
236
|
-
elements.push(fnElement(name, subMember));
|
|
271
|
+
elements.push(...fnElement(name, subMember));
|
|
237
272
|
} else if (isScalar(subMember)) {
|
|
238
273
|
elements.push(constantElement(name, subMember));
|
|
239
274
|
}
|