@lingxia/types 0.15.0 → 0.16.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.
Files changed (47) hide show
  1. package/dist/automation/index.d.ts +15 -1
  2. package/dist/automation/index.d.ts.map +1 -1
  3. package/dist/error.d.ts +4 -3
  4. package/dist/error.d.ts.map +1 -1
  5. package/dist/error.js +2 -2
  6. package/dist/error.js.map +1 -1
  7. package/dist/esm/automation/index.js +12 -0
  8. package/dist/esm/automation/index.js.map +1 -0
  9. package/dist/esm/error.js +148 -0
  10. package/dist/esm/error.js.map +1 -0
  11. package/dist/esm/generated/error.js +44 -0
  12. package/dist/esm/generated/error.js.map +1 -0
  13. package/dist/esm/generated/i18n.js +167 -0
  14. package/dist/esm/generated/i18n.js.map +1 -0
  15. package/dist/esm/generated/logic.js +4 -0
  16. package/dist/esm/generated/logic.js.map +1 -0
  17. package/dist/esm/index.js +11 -0
  18. package/dist/esm/index.js.map +1 -0
  19. package/dist/esm/package.json +4 -0
  20. package/dist/esm/process.js +9 -0
  21. package/dist/esm/process.js.map +1 -0
  22. package/dist/{testing/public-api.mjs → esm/testing/public-api.js} +79 -20
  23. package/dist/esm/testing/public-api.js.map +1 -0
  24. package/dist/generated/error.d.ts +1 -1
  25. package/dist/generated/error.d.ts.map +1 -1
  26. package/dist/generated/logic-web.d.ts +124 -0
  27. package/dist/generated/logic.d.ts +320 -142
  28. package/dist/generated/logic.d.ts.map +1 -1
  29. package/dist/index.d.ts +20 -10
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +5 -6
  32. package/dist/index.js.map +1 -1
  33. package/dist/process.d.ts +2 -2
  34. package/dist/process.js +2 -2
  35. package/dist/testing/public-api.d.ts +66 -15
  36. package/dist/testing/public-api.d.ts.map +1 -1
  37. package/dist/testing/public-api.js +78 -20
  38. package/dist/testing/public-api.js.map +1 -1
  39. package/package.json +9 -93
  40. package/src/automation/index.ts +17 -1
  41. package/src/error.ts +4 -3
  42. package/src/generated/error.ts +1 -1
  43. package/src/generated/logic-web.d.ts +124 -0
  44. package/src/generated/logic.ts +348 -150
  45. package/src/index.ts +32 -11
  46. package/src/process.ts +2 -2
  47. package/src/testing/public-api.ts +90 -20
package/src/index.ts CHANGED
@@ -4,23 +4,26 @@
4
4
  * Type declarations for the LingXia JS API, driven by Rust implementation.
5
5
  */
6
6
 
7
- export * from './generated/logic';
8
- export * from './automation';
9
- export * from './error';
10
- export * from './generated/error';
11
- export * from './generated/i18n';
7
+ export * from './generated/logic.js';
8
+ export type { Automation } from './automation/index.js';
9
+ export * from './error.js';
10
+ export * from './generated/error.js';
11
+ export * from './generated/i18n.js';
12
12
 
13
- import './generated/logic';
13
+ import './generated/logic.js';
14
14
 
15
15
  import type {
16
16
  AppConfig,
17
17
  AppInstance,
18
+ AppLifecycleName,
18
19
  BinaryFileData,
19
20
  FsWriteOptions,
21
+ NoLifecycleTypos,
20
22
  PageConfig,
21
23
  PageInstance,
22
- } from './generated/logic';
23
- import type { Automation } from './automation';
24
+ PageLifecycleName,
25
+ } from './generated/logic.js';
26
+ import type { Automation } from './automation/index.js';
24
27
 
25
28
  export type Lx = globalThis.Lx;
26
29
 
@@ -52,10 +55,28 @@ declare global {
52
55
 
53
56
  const lx: Lx;
54
57
 
55
- function App(config: AppConfig): AppInstance;
58
+ /**
59
+ * `TCustom` is inferred from the members you write beside the lifecycle
60
+ * hooks, so `this.myMethod()` resolves inside the config and a key that is
61
+ * only a case away from a hook is rejected.
62
+ */
63
+ function App<TCustom>(
64
+ config: AppConfig &
65
+ TCustom &
66
+ NoLifecycleTypos<TCustom, AppLifecycleName> &
67
+ ThisType<AppInstance & TCustom>
68
+ ): AppInstance & TCustom;
56
69
  function getApp<T extends AppInstance = AppInstance>(): T | null;
57
- function Page<TData extends Record<string, unknown> = Record<string, unknown>>(
58
- config: PageConfig<TData> & ThisType<PageInstance<TData> & PageConfig<TData>>
70
+ /**
71
+ * `TData` comes from `data`, `TCustom` from everything else you declare, so
72
+ * `this.data` is typed, `this.myMethod()` resolves, and `setData` checks
73
+ * top-level keys against `data`.
74
+ */
75
+ function Page<TData extends Record<string, unknown>, TCustom>(
76
+ config: PageConfig<TData> &
77
+ TCustom &
78
+ NoLifecycleTypos<TCustom, PageLifecycleName> &
79
+ ThisType<PageInstance<TData> & TCustom>
59
80
  ): void;
60
81
  function getCurrentPages<T extends PageInstance = PageInstance>(): T[];
61
82
  }
package/src/process.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
- * OS process capability for trusted LingXia home lxapps.
2
+ * OS process capability for the Control app.
3
3
  *
4
4
  * Add `@lingxia/types/process` to the Logic tsconfig only when the host sets
5
- * `capabilities.process: true` and the home lxapp declares the `process`
5
+ * `capabilities.process: true` and the Control app declares the `process`
6
6
  * security privilege. These declarations have no runtime payload.
7
7
  */
8
8
 
@@ -23,8 +23,13 @@ import type {
23
23
  } from '../automation/index.js';
24
24
  import type {
25
25
  AppearanceApi,
26
+ AppCacheApi,
26
27
  AutostartApi,
27
28
  CompressVideoTask,
29
+ ControlApi,
30
+ ControlAppearanceApi,
31
+ ControlDisplayLanguageApi,
32
+ DisplayLanguageApi,
28
33
  DownloadTask,
29
34
  FileSystemApi,
30
35
  HostAppApi,
@@ -53,7 +58,6 @@ import type {
53
58
 
54
59
  export const LX_API_NAMES = [
55
60
  'app',
56
- 'appearance',
57
61
  'automation',
58
62
  'chooseDirectory',
59
63
  'chooseFile',
@@ -121,19 +125,38 @@ export const LX_API_NAMES = [
121
125
  ] as const;
122
126
 
123
127
  const HOST_APP_API = [
128
+ 'appearance',
124
129
  'autostart',
130
+ 'cache',
125
131
  'checkUpdate',
126
- 'envVersion',
132
+ 'control',
133
+ 'displayLanguage',
134
+ 'env',
127
135
  'exit',
128
136
  'getBaseInfo',
129
- 'onDisplayLanguageChange',
130
137
  'screenshot',
131
138
  'setBadge',
132
- 'setDisplayLanguage',
133
139
  ] as const;
134
- const HOST_APP_RUNTIME_API = HOST_APP_API.filter((name) => name !== 'autostart');
140
+ // `autostart`, `control`, and `cache` are injected only where they apply, so a
141
+ // runtime walk of `lx.app` must not require them.
142
+ const HOST_APP_RUNTIME_API = HOST_APP_API.filter(
143
+ (name) => name !== 'autostart' && name !== 'control' && name !== 'cache',
144
+ );
135
145
  const AUTOSTART_API = ['isEnabled', 'setEnabled'] as const;
136
- const APPEARANCE_API = ['get', 'set'] as const;
146
+ const APP_CACHE_API = ['clear', 'size'] as const;
147
+ const DISPLAY_LANGUAGE_API = ['get', 'watch'] as const;
148
+ const CONTROL_API = ['appearance', 'displayLanguage'] as const;
149
+ const CONTROL_DISPLAY_LANGUAGE_API = [
150
+ 'getPreference',
151
+ 'setPreference',
152
+ 'watchPreference',
153
+ ] as const;
154
+ const APPEARANCE_API = ['get', 'watch'] as const;
155
+ const CONTROL_APPEARANCE_API = [
156
+ 'getPreference',
157
+ 'setPreference',
158
+ 'watchPreference',
159
+ ] as const;
137
160
  const NAVIGATION_BAR_API = ['update'] as const;
138
161
  const TAB_BAR_API = ['update'] as const;
139
162
  const TERMINAL_API = ['colorSchemes', 'fonts', 'settings', 'windows'] as const;
@@ -168,7 +191,7 @@ const LX_FILE_API = [
168
191
  'stat',
169
192
  'text',
170
193
  ] as const;
171
- const STORAGE_API = ['clear', 'delete', 'get', 'info', 'list', 'set'] as const;
194
+ const STORAGE_API = ['clear', 'delete', 'get', 'has', 'info', 'list', 'set'] as const;
172
195
  const UPDATE_MANAGER_API = ['applyUpdate', 'onUpdateFailed', 'onUpdateReady'] as const;
173
196
  const VIDEO_CONTEXT_API = [
174
197
  'exitFullScreen',
@@ -193,6 +216,7 @@ const SHELL_DRIVER_API = ['pins', 'setPin'] as const;
193
216
  const TERMINAL_DRIVER_API = ['input', 'newTab', 'setMaximized', 'snapshot', 'split'] as const;
194
217
  const LXAPP_DRIVER_API = ['eval', 'info', 'nav', 'page', 'pages', 'surfaceLayout'] as const;
195
218
  const LXAPP_MANAGER_API = [
219
+ 'applink',
196
220
  'close',
197
221
  'current',
198
222
  'list',
@@ -310,7 +334,6 @@ export const LX_RUNTIME_SURFACES = [
310
334
  optionalMembers: ['terminal'],
311
335
  properties: [
312
336
  'app',
313
- 'appearance',
314
337
  'env',
315
338
  'fs',
316
339
  'navigationBar',
@@ -326,7 +349,7 @@ export const LX_RUNTIME_SURFACES = [
326
349
  layer: 'logic',
327
350
  expression: 'lx.app',
328
351
  members: HOST_APP_RUNTIME_API,
329
- properties: ['envVersion'],
352
+ properties: ['appearance', 'displayLanguage', 'env'],
330
353
  },
331
354
  {
332
355
  name: 'lx.app.autostart',
@@ -336,11 +359,46 @@ export const LX_RUNTIME_SURFACES = [
336
359
  optional: true,
337
360
  },
338
361
  {
339
- name: 'lx.appearance',
362
+ name: 'lx.app.cache',
340
363
  layer: 'logic',
341
- expression: 'lx.appearance',
364
+ expression: 'lx.app.cache',
365
+ members: APP_CACHE_API,
366
+ optional: true,
367
+ },
368
+ {
369
+ name: 'lx.app.displayLanguage',
370
+ layer: 'logic',
371
+ expression: 'lx.app.displayLanguage',
372
+ members: DISPLAY_LANGUAGE_API,
373
+ },
374
+ {
375
+ name: 'lx.app.control',
376
+ layer: 'logic',
377
+ expression: 'lx.app.control',
378
+ members: CONTROL_API,
379
+ properties: CONTROL_API,
380
+ optional: true,
381
+ },
382
+ {
383
+ name: 'lx.app.control.displayLanguage',
384
+ layer: 'logic',
385
+ expression: 'lx.app.control?.displayLanguage',
386
+ members: CONTROL_DISPLAY_LANGUAGE_API,
387
+ optional: true,
388
+ },
389
+ {
390
+ name: 'lx.app.appearance',
391
+ layer: 'logic',
392
+ expression: 'lx.app.appearance',
342
393
  members: APPEARANCE_API,
343
394
  },
395
+ {
396
+ name: 'lx.app.control.appearance',
397
+ layer: 'logic',
398
+ expression: 'lx.app.control?.appearance',
399
+ members: CONTROL_APPEARANCE_API,
400
+ optional: true,
401
+ },
344
402
  {
345
403
  name: 'lx.navigationBar',
346
404
  layer: 'logic',
@@ -359,6 +417,7 @@ export const LX_RUNTIME_SURFACES = [
359
417
  expression: 'lx.terminal',
360
418
  members: TERMINAL_API,
361
419
  properties: TERMINAL_API,
420
+ optionalMembers: ['windows'],
362
421
  optional: true,
363
422
  },
364
423
  {
@@ -424,6 +483,10 @@ export const LX_RUNTIME_SURFACES = [
424
483
  layer: 'automation',
425
484
  expression: 'lx.automation()',
426
485
  members: AUTOMATION_API,
486
+ // The desktop tier is deliberately absent on mobile hosts. Keep the
487
+ // portable shape contract honest while the desktop entry covers it on
488
+ // Windows and macOS.
489
+ optionalMembers: ['desktop'],
427
490
  properties: ['browser', 'desktop', 'device', 'lxapps', 'shell', 'terminal'],
428
491
  },
429
492
  { name: 'ShellDriver', layer: 'automation', expression: 'lx.automation().shell', members: SHELL_DRIVER_API },
@@ -465,16 +528,17 @@ export const LX_RUNTIME_SURFACES = [
465
528
  layer: 'automation',
466
529
  expression: 'lx.automation().desktop',
467
530
  members: DESKTOP_DRIVER_API,
531
+ optional: true,
468
532
  properties: ['app', 'ax', 'clipboard', 'key', 'pointer', 'process', 'wait', 'window'],
469
533
  },
470
- { name: 'DesktopPointer', layer: 'automation', expression: 'lx.automation().desktop.pointer', members: DESKTOP_POINTER_API },
471
- { name: 'DesktopKey', layer: 'automation', expression: 'lx.automation().desktop.key', members: DESKTOP_KEY_API },
472
- { name: 'DesktopWindow', layer: 'automation', expression: 'lx.automation().desktop.window', members: DESKTOP_WINDOW_API },
473
- { name: 'DesktopClipboard', layer: 'automation', expression: 'lx.automation().desktop.clipboard', members: DESKTOP_CLIPBOARD_API },
474
- { name: 'DesktopAx', layer: 'automation', expression: 'lx.automation().desktop.ax', members: DESKTOP_AX_API },
475
- { name: 'DesktopWait', layer: 'automation', expression: 'lx.automation().desktop.wait', members: DESKTOP_WAIT_API },
476
- { name: 'DesktopApp', layer: 'automation', expression: 'lx.automation().desktop.app', members: DESKTOP_APP_API },
477
- { name: 'DesktopProcess', layer: 'automation', expression: 'lx.automation().desktop.process', members: DESKTOP_PROCESS_API },
534
+ { name: 'DesktopPointer', layer: 'automation', expression: 'lx.automation().desktop.pointer', members: DESKTOP_POINTER_API, optional: true },
535
+ { name: 'DesktopKey', layer: 'automation', expression: 'lx.automation().desktop.key', members: DESKTOP_KEY_API, optional: true },
536
+ { name: 'DesktopWindow', layer: 'automation', expression: 'lx.automation().desktop.window', members: DESKTOP_WINDOW_API, optional: true },
537
+ { name: 'DesktopClipboard', layer: 'automation', expression: 'lx.automation().desktop.clipboard', members: DESKTOP_CLIPBOARD_API, optional: true },
538
+ { name: 'DesktopAx', layer: 'automation', expression: 'lx.automation().desktop.ax', members: DESKTOP_AX_API, optional: true },
539
+ { name: 'DesktopWait', layer: 'automation', expression: 'lx.automation().desktop.wait', members: DESKTOP_WAIT_API, optional: true },
540
+ { name: 'DesktopApp', layer: 'automation', expression: 'lx.automation().desktop.app', members: DESKTOP_APP_API, optional: true },
541
+ { name: 'DesktopProcess', layer: 'automation', expression: 'lx.automation().desktop.process', members: DESKTOP_PROCESS_API, optional: true },
478
542
  ] as const;
479
543
 
480
544
  /** Canonical identifiers used by behavioral automation coverage. */
@@ -647,7 +711,8 @@ export const LX_REQUIRED_RUNTIME_SHAPE_NAMES = [
647
711
  .map((member) => `shape:${surface.name}.${member}`);
648
712
  }),
649
713
  ...LX_RETURNED_OBJECT_SURFACES
650
- .filter(({ fixture }) => fixture === 'runtime-safe')
714
+ .filter((surface) => surface.fixture === 'runtime-safe'
715
+ && !('optional' in surface && surface.optional))
651
716
  .flatMap(({ name, members }) => members.map((member) => `shape:${name}.${member}`)),
652
717
  ];
653
718
 
@@ -666,6 +731,11 @@ export type LxApiManifestGate = [
666
731
  AssertTrue<Exact<PublishedLx, typeof LX_API_NAMES>>,
667
732
  AssertTrue<Exact<HostAppApi, typeof HOST_APP_API>>,
668
733
  AssertTrue<Exact<AutostartApi, typeof AUTOSTART_API>>,
734
+ AssertTrue<Exact<AppCacheApi, typeof APP_CACHE_API>>,
735
+ AssertTrue<Exact<DisplayLanguageApi, typeof DISPLAY_LANGUAGE_API>>,
736
+ AssertTrue<Exact<ControlApi, typeof CONTROL_API>>,
737
+ AssertTrue<Exact<ControlDisplayLanguageApi, typeof CONTROL_DISPLAY_LANGUAGE_API>>,
738
+ AssertTrue<Exact<ControlAppearanceApi, typeof CONTROL_APPEARANCE_API>>,
669
739
  AssertTrue<Exact<AppearanceApi, typeof APPEARANCE_API>>,
670
740
  AssertTrue<Exact<NavigationBarApi, typeof NAVIGATION_BAR_API>>,
671
741
  AssertTrue<Exact<TabBarApi, typeof TAB_BAR_API>>,