epos 1.25.0 → 1.28.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,4 @@
1
+ /// <reference types="chrome" />
2
+ type Chrome = typeof chrome
3
+
4
+ export type { Chrome };
package/dist/epos.d.ts CHANGED
@@ -5,14 +5,17 @@ import * as reactDom from 'react-dom';
5
5
  import * as reactDomClient from 'react-dom/client';
6
6
  import * as reactJsxRuntime from 'react/jsx-runtime';
7
7
  import * as yjs from 'yjs';
8
+ import { Chrome } from './chrome.d.js';
8
9
 
9
10
  type Fn<T = any> = (...args: any[]) => T;
10
11
  type Obj = Record<string, unknown>;
12
+ type Arr = unknown[];
11
13
  type Versioner = Record<number, (this: any, state: any) => void>;
12
- type ClassName = string | null | boolean | undefined | ClassName[];
13
14
  type ModelClass = new (...args: any[]) => any;
14
15
  type Model = InstanceType<ModelClass>;
15
16
  type Initial<T extends Obj | Model> = T | (() => T);
17
+ type FnArgsOrArr<T> = T extends Fn ? Parameters<T> : Arr;
18
+ type FnResultOrValue<T> = T extends Fn ? ReturnType<T> : T;
16
19
  type StateConfig = {
17
20
  allowMissingModels?: boolean | string[];
18
21
  };
@@ -43,14 +46,15 @@ type Res = {
43
46
  headers: {
44
47
  get: Response['headers']['get'];
45
48
  has: Response['headers']['has'];
49
+ /** Get list of all header keys. */
46
50
  keys: () => string[];
47
51
  };
48
52
  };
49
53
  type Storage = {
50
54
  /** Get value from the storage. */
51
- get<T = unknown>(key: string): Promise<T>;
55
+ get<T = unknown>(key: string): Promise<T | null>;
52
56
  /** Set value in the storage. */
53
- set<T = unknown>(key: string, value: T): Promise<void>;
57
+ set(key: string, value: unknown): Promise<void>;
54
58
  /** Delete value from the storage. */
55
59
  delete(key: string): Promise<void>;
56
60
  /** Get all keys from the storage. */
@@ -60,23 +64,23 @@ type Storage = {
60
64
  };
61
65
  interface Epos {
62
66
  fetch: (url: string | URL, init?: ReqInit) => Promise<Res>;
63
- browser: typeof chrome;
64
- element: HTMLDivElement;
67
+ browser: Chrome;
65
68
  render(node: react.ReactNode, container?: reactDomClient.Container): void;
66
69
  component<T>(Component: react.FC<T>): typeof Component;
70
+ element: HTMLDivElement;
67
71
  bus: {
68
72
  /** Listen for an event. */
69
- on(eventName: string, callback: Fn, thisValue?: unknown): void;
73
+ on<T extends Fn>(name: string, callback: T, thisArg?: unknown): void;
70
74
  /** Remove event listener. */
71
- off(eventName: string, callback?: Fn): void;
75
+ off<T extends Fn>(name: string, callback?: T): void;
72
76
  /** Listen for an event once. */
73
- once(eventName: string, callback: Fn, thisValue?: unknown): void;
77
+ once<T extends Fn>(name: string, callback: T, thisArg?: unknown): void;
74
78
  /** Send an event to all remote listeners (local listeners are ignored). */
75
- send<T = unknown>(eventName: string, ...args: unknown[]): Promise<T>;
79
+ send<T = unknown>(name: string, ...args: FnArgsOrArr<T>): Promise<FnResultOrValue<T>>;
76
80
  /** Emit event locally (calls local listeners only). */
77
- emit<T = unknown>(eventName: string, ...args: unknown[]): Promise<T>;
81
+ emit<T = unknown>(name: string, ...args: FnArgsOrArr<T>): Promise<FnResultOrValue<T>>;
78
82
  setSignal(name: string, value?: unknown): void;
79
- waitSignal<T>(name: string, timeout?: number): Promise<T>;
83
+ waitSignal<T = unknown>(name: string, timeout?: number): Promise<T>;
80
84
  };
81
85
  state: {
82
86
  /** Connect state. */
@@ -90,8 +94,6 @@ interface Epos {
90
94
  transaction: (fn: () => void) => void;
91
95
  /** Create local state (no sync). */
92
96
  local<T extends Obj = {}>(state?: T): T;
93
- /** Configure state. */
94
- configure: (config: StateConfig) => void;
95
97
  /** Get the list of all state names. */
96
98
  list(filter?: {
97
99
  connected?: boolean;
@@ -99,30 +101,32 @@ interface Epos {
99
101
  name: string | null;
100
102
  }[]>;
101
103
  /** Remove state and all its data. */
102
- destroy(name?: string): Promise<void>;
103
- /** Register models for all states. */
104
- registerModels(models: Record<string, ModelClass>): void;
105
- symbols: {
106
- readonly parent: unique symbol;
107
- readonly modelInit: unique symbol;
108
- readonly modelCleanup: unique symbol;
109
- readonly modelStrict: unique symbol;
110
- readonly modelVersioner: unique symbol;
111
- };
104
+ remove(name?: string): Promise<void>;
105
+ /** Register models to be used by all states. */
106
+ register(models: Record<string, ModelClass>): void;
112
107
  };
113
108
  storage: {
114
109
  /** Get value from the storage. */
115
- get<T = unknown>(key: string, storageName?: string): Promise<T>;
110
+ get: {
111
+ <T = unknown>(key: string): Promise<T | null>;
112
+ <T = unknown>(name: string, key: string): Promise<T | null>;
113
+ };
116
114
  /** Set value in the storage. */
117
- set<T = unknown>(key: string, value: T, storageName?: string): Promise<void>;
115
+ set: {
116
+ <T = unknown>(key: string, value: T): Promise<void>;
117
+ <T = unknown>(name: string, key: string, value: T): Promise<void>;
118
+ };
118
119
  /** Delete value from the storage. */
119
- delete(key: string, storageName?: string): Promise<void>;
120
+ delete: {
121
+ (key: string): Promise<void>;
122
+ (name: string, key: string): Promise<void>;
123
+ };
120
124
  /** Get all keys from the storage. */
121
- keys(storageName?: string): Promise<string[]>;
125
+ keys(name?: string): Promise<string[]>;
122
126
  /** Clear storage. Removes all keys and storage itself. */
123
- clear(storageName?: string): Promise<void>;
127
+ clear(name?: string): Promise<void>;
124
128
  /** Get storage API for a specific storage. */
125
- use(storageName: string): Promise<Storage>;
129
+ use(name?: string): Storage;
126
130
  /** Get this list of all storages. */
127
131
  list(): Promise<{
128
132
  name: string | null;
@@ -141,23 +145,25 @@ interface Epos {
141
145
  url: string;
142
146
  }[]>;
143
147
  };
144
- assets: {
145
- /** Get asset URL. The asset must be loaded first via `epos.assets.load`. */
146
- url(path: string): string;
147
- /** Load either all assets or a specific asset by its path. */
148
+ asset: {
149
+ /** Load either all assets to the memory or a specific asset by its path. */
148
150
  load: {
149
151
  /** Load all assets. */
150
152
  (): Promise<void>;
151
153
  /** Load asset by path. */
152
- (path: string): Promise<Blob>;
154
+ (path: string): Promise<void>;
153
155
  };
154
- /** Unload either all assets from memory or a specific asset by its path. */
156
+ /** Unload either all assets from the memory or a specific asset by its path. */
155
157
  unload: {
156
- /** Unload all assets from memory. */
158
+ /** Unload all assets. */
157
159
  (): void;
158
160
  /** Unload asset by path. */
159
161
  (path: string): void;
160
162
  };
163
+ /** Get asset URL. The asset must be loaded first via `epos.asset.load`. */
164
+ url(path: string): string;
165
+ /** Get asset as Blob. */
166
+ get(path: string): Promise<Blob | null>;
161
167
  /** Get list of all available asset files. */
162
168
  list(filter?: {
163
169
  loaded?: boolean;
@@ -168,7 +174,7 @@ interface Epos {
168
174
  };
169
175
  env: {
170
176
  tabId: number;
171
- isWeb: boolean;
177
+ project: string;
172
178
  isPopup: boolean;
173
179
  isSidePanel: boolean;
174
180
  isBackground: boolean;
@@ -182,15 +188,17 @@ interface Epos {
182
188
  reactJsxRuntime: typeof reactJsxRuntime;
183
189
  yjs: typeof yjs;
184
190
  };
191
+ symbols: {
192
+ readonly stateParent: symbol;
193
+ readonly stateModelInit: symbol;
194
+ readonly stateModelDispose: symbol;
195
+ readonly stateModelStrict: symbol;
196
+ readonly stateModelVersioner: symbol;
197
+ };
185
198
  }
186
199
  declare global {
187
200
  var epos: Epos;
188
- namespace React {
189
- interface HTMLAttributes<T> {
190
- class?: ClassName;
191
- }
192
- }
193
201
  }
194
202
  declare const _epos: Epos;
195
203
 
196
- export { type ClassName, type Epos, type Fn, type Initial, type Model, type ModelClass, type Obj, type ReqInit, type Res, type StateConfig, type Storage, type Versioner, _epos as default, _epos as epos };
204
+ export { type Arr, type Epos, type Fn, type FnArgsOrArr, type FnResultOrValue, type Initial, type Model, type ModelClass, type Obj, type ReqInit, type Res, type StateConfig, type Storage, type Versioner, _epos as default, _epos as epos };
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "epos",
3
- "version": "1.25.0",
3
+ "version": "1.28.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "imkost",
7
7
  "description": "",
8
8
  "keywords": [],
9
9
  "scripts": {
10
- "dev": "tsup --config ../tsup.config.ts --watch",
11
- "build": "tsup --config ../tsup.config.ts",
10
+ "dev": "tsup --config ../../tsup.config.ts --watch --dts-resolve",
11
+ "build": "tsup --config ../../tsup.config.ts --dts-resolve",
12
12
  "lint": "tsc --noEmit",
13
13
  "release": "sh -c 'npm version ${1:-minor} && npm run build && npm publish' --"
14
14
  },
@@ -33,20 +33,20 @@
33
33
  ],
34
34
  "dependencies": {
35
35
  "@parcel/watcher": "^2.5.1",
36
- "@types/chrome": "^0.1.24",
37
- "@types/react": "^19.2.2",
38
- "@types/react-dom": "^19.2.2",
36
+ "@types/chrome": "^0.1.32",
37
+ "@types/react": "^19.2.7",
38
+ "@types/react-dom": "^19.2.3",
39
39
  "mobx": "^6.15.0",
40
40
  "mobx-react-lite": "^4.1.1",
41
41
  "portfinder": "^1.0.38",
42
- "react": "^19.2.0",
42
+ "react": "^19.2.3",
43
43
  "ws": "^8.18.3",
44
44
  "yjs": "^13.6.27"
45
45
  },
46
46
  "devDependencies": {
47
- "vite": "^7.1.12"
47
+ "vite": "^7.3.0"
48
48
  },
49
49
  "peerDependencies": {
50
- "vite": "^7.1.9"
50
+ "vite": "^7.3.0"
51
51
  }
52
52
  }
@@ -0,0 +1,3 @@
1
+ /// <reference types="chrome"/>
2
+
3
+ export type Chrome = typeof chrome
package/src/epos.ts CHANGED
@@ -5,15 +5,17 @@ import type * as reactDom from 'react-dom'
5
5
  import type * as reactDomClient from 'react-dom/client'
6
6
  import type * as reactJsxRuntime from 'react/jsx-runtime'
7
7
  import type * as yjs from 'yjs'
8
- import './chrome-types.d.ts'
8
+ import type { Chrome } from './chrome.ts'
9
9
 
10
10
  export type Fn<T = any> = (...args: any[]) => T
11
11
  export type Obj = Record<string, unknown>
12
+ export type Arr = unknown[]
12
13
  export type Versioner = Record<number, (this: any, state: any) => void>
13
- export type ClassName = string | null | boolean | undefined | ClassName[]
14
14
  export type ModelClass = new (...args: any[]) => any
15
15
  export type Model = InstanceType<ModelClass>
16
16
  export type Initial<T extends Obj | Model> = T | (() => T)
17
+ export type FnArgsOrArr<T> = T extends Fn ? Parameters<T> : Arr
18
+ export type FnResultOrValue<T> = T extends Fn ? ReturnType<T> : T
17
19
 
18
20
  export type StateConfig = {
19
21
  allowMissingModels?: boolean | string[]
@@ -47,15 +49,16 @@ export type Res = {
47
49
  headers: {
48
50
  get: Response['headers']['get']
49
51
  has: Response['headers']['has']
52
+ /** Get list of all header keys. */
50
53
  keys: () => string[]
51
54
  }
52
55
  }
53
56
 
54
57
  export type Storage = {
55
58
  /** Get value from the storage. */
56
- get<T = unknown>(key: string): Promise<T>
59
+ get<T = unknown>(key: string): Promise<T | null>
57
60
  /** Set value in the storage. */
58
- set<T = unknown>(key: string, value: T): Promise<void>
61
+ set(key: string, value: unknown): Promise<void>
59
62
  /** Delete value from the storage. */
60
63
  delete(key: string): Promise<void>
61
64
  /** Get all keys from the storage. */
@@ -67,25 +70,25 @@ export type Storage = {
67
70
  export interface Epos {
68
71
  // General
69
72
  fetch: (url: string | URL, init?: ReqInit) => Promise<Res>
70
- browser: typeof chrome
71
- element: HTMLDivElement
73
+ browser: Chrome
72
74
  render(node: react.ReactNode, container?: reactDomClient.Container): void
73
75
  component<T>(Component: react.FC<T>): typeof Component
76
+ element: HTMLDivElement
74
77
 
75
78
  // Bus
76
79
  bus: {
77
80
  /** Listen for an event. */
78
- on(eventName: string, callback: Fn, thisValue?: unknown): void
81
+ on<T extends Fn>(name: string, callback: T, thisArg?: unknown): void
79
82
  /** Remove event listener. */
80
- off(eventName: string, callback?: Fn): void
83
+ off<T extends Fn>(name: string, callback?: T): void
81
84
  /** Listen for an event once. */
82
- once(eventName: string, callback: Fn, thisValue?: unknown): void
85
+ once<T extends Fn>(name: string, callback: T, thisArg?: unknown): void
83
86
  /** Send an event to all remote listeners (local listeners are ignored). */
84
- send<T = unknown>(eventName: string, ...args: unknown[]): Promise<T>
87
+ send<T = unknown>(name: string, ...args: FnArgsOrArr<T>): Promise<FnResultOrValue<T>>
85
88
  /** Emit event locally (calls local listeners only). */
86
- emit<T = unknown>(eventName: string, ...args: unknown[]): Promise<T>
89
+ emit<T = unknown>(name: string, ...args: FnArgsOrArr<T>): Promise<FnResultOrValue<T>>
87
90
  setSignal(name: string, value?: unknown): void
88
- waitSignal<T>(name: string, timeout?: number): Promise<T>
91
+ waitSignal<T = unknown>(name: string, timeout?: number): Promise<T>
89
92
  }
90
93
 
91
94
  // State
@@ -101,37 +104,37 @@ export interface Epos {
101
104
  transaction: (fn: () => void) => void
102
105
  /** Create local state (no sync). */
103
106
  local<T extends Obj = {}>(state?: T): T
104
- /** Configure state. */
105
- configure: (config: StateConfig) => void
106
107
  /** Get the list of all state names. */
107
108
  list(filter?: { connected?: boolean }): Promise<{ name: string | null }[]>
108
109
  /** Remove state and all its data. */
109
- destroy(name?: string): Promise<void>
110
- /** Register models for all states. */
111
- registerModels(models: Record<string, ModelClass>): void
112
- symbols: {
113
- readonly parent: unique symbol
114
- readonly modelInit: unique symbol
115
- readonly modelCleanup: unique symbol
116
- readonly modelStrict: unique symbol
117
- readonly modelVersioner: unique symbol
118
- }
110
+ remove(name?: string): Promise<void>
111
+ /** Register models to be used by all states. */
112
+ register(models: Record<string, ModelClass>): void
119
113
  }
120
114
 
121
115
  // Storage
122
116
  storage: {
123
117
  /** Get value from the storage. */
124
- get<T = unknown>(key: string, storageName?: string): Promise<T>
118
+ get: {
119
+ <T = unknown>(key: string): Promise<T | null>
120
+ <T = unknown>(name: string, key: string): Promise<T | null>
121
+ }
125
122
  /** Set value in the storage. */
126
- set<T = unknown>(key: string, value: T, storageName?: string): Promise<void>
123
+ set: {
124
+ <T = unknown>(key: string, value: T): Promise<void>
125
+ <T = unknown>(name: string, key: string, value: T): Promise<void>
126
+ }
127
127
  /** Delete value from the storage. */
128
- delete(key: string, storageName?: string): Promise<void>
128
+ delete: {
129
+ (key: string): Promise<void>
130
+ (name: string, key: string): Promise<void>
131
+ }
129
132
  /** Get all keys from the storage. */
130
- keys(storageName?: string): Promise<string[]>
133
+ keys(name?: string): Promise<string[]>
131
134
  /** Clear storage. Removes all keys and storage itself. */
132
- clear(storageName?: string): Promise<void>
135
+ clear(name?: string): Promise<void>
133
136
  /** Get storage API for a specific storage. */
134
- use(storageName: string): Promise<Storage>
137
+ use(name?: string): Storage
135
138
  /** Get this list of all storages. */
136
139
  list(): Promise<{ name: string | null }[]>
137
140
  }
@@ -148,24 +151,26 @@ export interface Epos {
148
151
  list(): Promise<{ name: string | null; url: string }[]>
149
152
  }
150
153
 
151
- // Assets
152
- assets: {
153
- /** Get asset URL. The asset must be loaded first via `epos.assets.load`. */
154
- url(path: string): string
155
- /** Load either all assets or a specific asset by its path. */
154
+ // Asset
155
+ asset: {
156
+ /** Load either all assets to the memory or a specific asset by its path. */
156
157
  load: {
157
158
  /** Load all assets. */
158
159
  (): Promise<void>
159
160
  /** Load asset by path. */
160
- (path: string): Promise<Blob>
161
+ (path: string): Promise<void>
161
162
  }
162
- /** Unload either all assets from memory or a specific asset by its path. */
163
+ /** Unload either all assets from the memory or a specific asset by its path. */
163
164
  unload: {
164
- /** Unload all assets from memory. */
165
+ /** Unload all assets. */
165
166
  (): void
166
167
  /** Unload asset by path. */
167
168
  (path: string): void
168
169
  }
170
+ /** Get asset URL. The asset must be loaded first via `epos.asset.load`. */
171
+ url(path: string): string
172
+ /** Get asset as Blob. */
173
+ get(path: string): Promise<Blob | null>
169
174
  /** Get list of all available asset files. */
170
175
  list(filter?: { loaded?: boolean }): { path: string; loaded: boolean }[]
171
176
  }
@@ -173,7 +178,7 @@ export interface Epos {
173
178
  // Env
174
179
  env: {
175
180
  tabId: number
176
- isWeb: boolean
181
+ project: string
177
182
  isPopup: boolean
178
183
  isSidePanel: boolean
179
184
  isBackground: boolean
@@ -189,16 +194,19 @@ export interface Epos {
189
194
  reactJsxRuntime: typeof reactJsxRuntime
190
195
  yjs: typeof yjs
191
196
  }
197
+
198
+ // Internal symbols
199
+ symbols: {
200
+ readonly stateParent: symbol
201
+ readonly stateModelInit: symbol
202
+ readonly stateModelDispose: symbol
203
+ readonly stateModelStrict: symbol
204
+ readonly stateModelVersioner: symbol
205
+ }
192
206
  }
193
207
 
194
208
  declare global {
195
209
  var epos: Epos
196
-
197
- namespace React {
198
- interface HTMLAttributes<T> {
199
- class?: ClassName
200
- }
201
- }
202
210
  }
203
211
 
204
212
  const _epos = epos
@@ -1 +0,0 @@
1
- /// <reference types="chrome" />
@@ -1,2 +0,0 @@
1
- /// <reference types="chrome" />
2
- export {}
File without changes