@defold-typescript/types 0.41.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.41.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",
@@ -64,6 +71,7 @@
64
71
  "fixtures/messages_doc.json",
65
72
  "fixtures/defold-*",
66
73
  "!fixtures/defold-*/engine-bindings",
74
+ "!fixtures/defold-*/annotations",
67
75
  "examples/translations.json",
68
76
  "!src/**/*.test.ts",
69
77
  "!scripts/**/*.test.ts",
@@ -82,7 +90,11 @@
82
90
  "!scripts/engine-binding-verdicts.ts",
83
91
  "!scripts/engine-binding-verdicts.json",
84
92
  "!scripts/lua-kind.ts",
85
- "!scripts/index-slot-scan.ts"
93
+ "!scripts/index-slot-scan.ts",
94
+ "!scripts/lua-annotations.ts",
95
+ "!scripts/lua-annotation-diff.ts",
96
+ "!scripts/lua-annotation-verdicts.ts",
97
+ "!scripts/lua-annotation-verdicts.json"
86
98
  ],
87
99
  "publishConfig": {
88
100
  "access": "public"
@@ -5,6 +5,8 @@ import { refDocCacheDir, resolveRefDoc } from "./doc-source";
5
5
  import {
6
6
  apiElementIdentity,
7
7
  EDITOR_MANIFEST,
8
+ type ExtractedFixture,
9
+ extractAnnotationFixtures,
8
10
  IGNORED_UPSTREAM,
9
11
  mergeApiDocs,
10
12
  readZip,
@@ -153,6 +155,9 @@ export interface ReleaseImportManifest {
153
155
  readonly unknownTypes: UnknownTypeBlocker[];
154
156
  readonly unmappedFunctionNamespaces: UnmappedNamespaceBlocker[];
155
157
  };
158
+ // The file names vendored under `annotations/`, which `loadAnnotations` holds
159
+ // the directory to. Empty before 1.13.2; absent from manifests written earlier.
160
+ readonly annotationFiles: readonly string[];
156
161
  readonly snapshots: Array<{
157
162
  readonly namespace: string;
158
163
  readonly fixture: string;
@@ -164,6 +169,8 @@ export interface ReleaseImportManifest {
164
169
  export type ReleaseImportPlan = Omit<ReleaseImportManifest, "snapshots"> & {
165
170
  readonly manifest: ReleaseImportManifest;
166
171
  readonly snapshots: ReleaseImportSnapshot[];
172
+ // The release's LuaLS annotation files, vendored verbatim. Empty before 1.13.2.
173
+ readonly annotations: ExtractedFixture[];
167
174
  };
168
175
 
169
176
  function isRecord(value: unknown): value is Record<string, unknown> {
@@ -259,7 +266,9 @@ function unknownTypeBlockers(
259
266
  return out;
260
267
  }
261
268
 
262
- function reportWithoutSnapshots(plan: Omit<ReleaseImportPlan, "manifest">): ReleaseImportManifest {
269
+ function reportWithoutSnapshots(
270
+ plan: Omit<ReleaseImportPlan, "manifest" | "annotations">,
271
+ ): ReleaseImportManifest {
263
272
  return {
264
273
  version: plan.version,
265
274
  baseline: plan.baseline,
@@ -269,6 +278,7 @@ function reportWithoutSnapshots(plan: Omit<ReleaseImportPlan, "manifest">): Rele
269
278
  moved: plan.moved,
270
279
  symbols: plan.symbols,
271
280
  blockers: plan.blockers,
281
+ annotationFiles: plan.annotationFiles,
272
282
  snapshots: plan.snapshots.map(({ namespace, fixture, sourceEntries, symbolSources }) => ({
273
283
  namespace,
274
284
  fixture,
@@ -417,6 +427,7 @@ export function buildReleaseImportPlan(input: {
417
427
  (a, b) => a.namespace.localeCompare(b.namespace) || a.symbol.localeCompare(b.symbol),
418
428
  );
419
429
  const ready = unknownTypes.length === 0 && unmappedFunctionNamespaces.length === 0;
430
+ const annotations = extractAnnotationFixtures(input.zip);
420
431
  const planBase = {
421
432
  version: input.version,
422
433
  baseline: input.baseline.id,
@@ -426,10 +437,11 @@ export function buildReleaseImportPlan(input: {
426
437
  moved,
427
438
  symbols,
428
439
  blockers: { unknownTypes, unmappedFunctionNamespaces },
440
+ annotationFiles: annotations.map((annotation) => annotation.namespace).sort(),
429
441
  snapshots,
430
442
  };
431
443
  const manifest = reportWithoutSnapshots(planBase);
432
- return { ...planBase, manifest };
444
+ return { ...planBase, manifest, annotations };
433
445
  }
434
446
 
435
447
  export function releaseImportReportJson(plan: ReleaseImportPlan): string {
@@ -448,6 +460,13 @@ export function applyReleaseImport(plan: ReleaseImportPlan, packageRoot = PACKAG
448
460
  writeFileSync(path, `${JSON.stringify(snapshot.doc, null, 2)}\n`);
449
461
  written.push(relative);
450
462
  }
463
+ for (const annotation of plan.annotations) {
464
+ const relative = `${relativeRoot}/${annotation.fixture}`;
465
+ const path = resolve(packageRoot, relative);
466
+ mkdirSync(dirname(path), { recursive: true });
467
+ writeFileSync(path, annotation.contents);
468
+ written.push(relative);
469
+ }
451
470
  // The prefixless builtins (`hash`, `pprint`, ...) are hand-vendored rather than
452
471
  // generated, so no upstream snapshot carries them. Seeding the canonical copy
453
472
  // here is what keeps a newly imported target from being born without a globals
@@ -1,6 +1,6 @@
1
- import { mkdtempSync, readFileSync, writeFileSync } from "node:fs";
1
+ import { mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
2
2
  import { tmpdir } from "node:os";
3
- import { join, resolve } from "node:path";
3
+ import { dirname, join, resolve } from "node:path";
4
4
  import { type ApiModule, parseDefoldApiDoc } from "../src/api-doc";
5
5
  import { DEFOLD_TYPE_MAP } from "../src/core-types";
6
6
  import { parseScriptApi } from "../src/script-api";
@@ -404,6 +404,21 @@ export function extractFixtures(
404
404
  });
405
405
  }
406
406
 
407
+ // Since 1.13.2 the ref-doc zip ships LuaLS annotation files beside the JSON:
408
+ // `doc/<namespace>.lua` for the game runtime and `doc/<namespace>.editor_script`
409
+ // for the editor VM. They are vendored verbatim, never parsed at sync time.
410
+ const ANNOTATION_ENTRY = /^doc\/([^/]+\.(?:lua|editor_script))$/;
411
+
412
+ export function extractAnnotationFixtures(zip: ZipAccessor): ExtractedFixture[] {
413
+ const out: ExtractedFixture[] = [];
414
+ for (const zipEntry of [...zip.entries()].sort()) {
415
+ const file = ANNOTATION_ENTRY.exec(zipEntry)?.[1];
416
+ if (file === undefined) continue;
417
+ out.push({ namespace: file, fixture: `annotations/${file}`, contents: zip.read(zipEntry) });
418
+ }
419
+ return out;
420
+ }
421
+
407
422
  export type FixtureSyncStatus = "clean" | "drift" | "created";
408
423
 
409
424
  export interface FixtureSyncResult {
@@ -442,7 +457,8 @@ export function syncFixtures(zip: ZipAccessor, options: SyncOptions = {}): Fixtu
442
457
 
443
458
  // Compare/write a set of already-extracted fixtures against disk. Shared by
444
459
  // the core (zip) and extension (`.script_api`) sync paths so both honor the
445
- // identical created/clean/drift + format-on-write semantics.
460
+ // identical created/clean/drift + format-on-write semantics. A non-JSON fixture
461
+ // (a vendored annotation file) compares and writes byte-for-byte.
446
462
  export function syncExtractedFixtures(
447
463
  items: readonly ExtractedFixture[],
448
464
  options: Omit<SyncOptions, "manifest"> = {},
@@ -453,15 +469,21 @@ export function syncExtractedFixtures(
453
469
  const results: FixtureSyncResult[] = [];
454
470
  for (const item of items) {
455
471
  const path = resolve(root, item.fixture);
472
+ const json = item.fixture.endsWith(".json");
456
473
  const existing = readFixtureOrNull(path);
457
474
  const status: FixtureSyncStatus =
458
475
  existing === null
459
476
  ? "created"
460
- : canonicalJson(existing) === canonicalJson(item.contents)
477
+ : (
478
+ json
479
+ ? canonicalJson(existing) === canonicalJson(item.contents)
480
+ : existing === item.contents
481
+ )
461
482
  ? "clean"
462
483
  : "drift";
463
484
  if (!check && status !== "clean") {
464
- writeFileSync(path, format(item.contents));
485
+ mkdirSync(dirname(path), { recursive: true });
486
+ writeFileSync(path, json ? format(item.contents) : item.contents);
465
487
  }
466
488
  results.push({ namespace: item.namespace, fixture: item.fixture, status });
467
489
  }
@@ -641,11 +663,16 @@ if (import.meta.main) {
641
663
  const luaStdlibFixtures = extractFixtures(zip, LUA_STDLIB_MANIFEST);
642
664
  const editorFixtures = extractFixtures(zip, EDITOR_MANIFEST);
643
665
  const editorVmFixtures = extractFixtures(zip, EDITOR_VM_MANIFEST);
666
+ const annotationFixtures = extractAnnotationFixtures(zip);
644
667
  const results = [
645
668
  ...syncExtractedFixtures(coreFixtures, { check }),
646
669
  ...syncExtractedFixtures(luaStdlibFixtures, { check }),
647
670
  ...syncExtractedFixtures(editorFixtures, { check }),
648
671
  ...syncExtractedFixtures(editorVmFixtures, { check }),
672
+ ...syncExtractedFixtures(annotationFixtures, {
673
+ check,
674
+ fixturesRoot: resolve(PACKAGE_ROOT, `fixtures/defold-${DEFOLD_VERSION}`),
675
+ }),
649
676
  ];
650
677
  const syncedDocs = coreFixtures.map((f) => ({
651
678
  namespace: f.namespace,