epos 1.34.0 → 1.35.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/epos.d.ts CHANGED
@@ -9,13 +9,13 @@ import * as yjs from 'yjs';
9
9
  import { Chrome } from './chrome.d.js';
10
10
 
11
11
  type Fn<T = any> = (...args: any[]) => T;
12
+ type Cls<T = any> = new (...args: any[]) => T;
12
13
  type Obj = Record<string, unknown>;
13
14
  type Arr = unknown[];
14
- type Versioner = Record<number, (this: any, state: any) => void>;
15
- type ModelClass = new (...args: any[]) => any;
16
- type Model = InstanceType<ModelClass>;
17
- type Initial<T extends Obj | Model> = T | (() => T);
18
- type Attrs = Record<string, string | number>;
15
+ type Model<T> = T extends object ? Exclude<T, Obj | Arr | Fn> : never;
16
+ type ObjModel<T> = T extends Obj ? T : Model<T>;
17
+ type ObjArrModel<T> = T extends Obj | Arr ? T : Model<T>;
18
+ type Versioner<T> = Record<number, (this: T, state: T) => void>;
19
19
  type Mode = 'development' | 'production';
20
20
  type Sources = {
21
21
  [path: string]: string;
@@ -23,6 +23,7 @@ type Sources = {
23
23
  type Assets = {
24
24
  [path: string]: Blob;
25
25
  };
26
+ type Attrs = Record<string, string | number>;
26
27
  type FnArgsOrArr<T> = T extends Fn ? Parameters<T> : Arr;
27
28
  type FnResultOrValue<T> = T extends Fn ? ReturnType<T> : T;
28
29
  type Project = {
@@ -102,17 +103,17 @@ interface Epos {
102
103
  state: {
103
104
  /** Connect state. */
104
105
  connect: {
105
- <T extends Obj | Model = Obj>(initial?: Initial<T>, versioner?: Versioner): Promise<T>;
106
- <T extends Obj | Model = Obj>(name?: string, initial?: Initial<T>, versioner?: Versioner): Promise<T>;
106
+ <T = Obj>(initial?: ObjModel<T>, versioner?: Versioner<T>): Promise<T>;
107
+ <T = Obj>(initial?: () => ObjModel<T>, versioner?: Versioner<T>): Promise<T>;
108
+ <T = Obj>(name?: string, initial?: ObjModel<T>, versioner?: Versioner<T>): Promise<T>;
109
+ <T = Obj>(name?: string, initial?: () => ObjModel<T>, versioner?: Versioner<T>): Promise<T>;
107
110
  };
108
111
  /** Disconnect state. */
109
112
  disconnect(name?: string): void;
110
113
  /** Run any state changes in a batch. */
111
114
  transaction: (fn: () => void) => void;
112
115
  /** Create local state (no sync). */
113
- local<T extends Obj = {}>(value?: T, opts?: {
114
- deep: boolean;
115
- }): T;
116
+ local<T = Obj>(state?: ObjArrModel<T>): T;
116
117
  /** Get the list of all state names. */
117
118
  list(filter?: {
118
119
  connected?: boolean;
@@ -121,8 +122,8 @@ interface Epos {
121
122
  }[]>;
122
123
  /** Remove state and all its data. */
123
124
  remove(name?: string): Promise<void>;
124
- /** Register models to be used by all states. */
125
- register(models: Record<string, ModelClass>): void;
125
+ /** Register models that can be used by all states. */
126
+ register(models: Record<string, Cls>): void;
126
127
  PARENT: symbol;
127
128
  ATTACH: symbol;
128
129
  DETACH: symbol;
@@ -143,7 +144,7 @@ interface Epos {
143
144
  (key: string): Promise<void>;
144
145
  (name: string, key: string): Promise<void>;
145
146
  };
146
- /** Get all keys from the storage. */
147
+ /** Get all storage keys. */
147
148
  keys(name?: string): Promise<string[]>;
148
149
  /** Remove storage. Removes all keys and storage itself. */
149
150
  remove(name?: string): Promise<void>;
@@ -235,4 +236,4 @@ declare global {
235
236
  }
236
237
  declare const _epos: Epos;
237
238
 
238
- export { type Arr, type Assets, type Attrs, type Bundle, type Epos, type Fn, type FnArgsOrArr, type FnResultOrValue, type Initial, type Mode, type Model, type ModelClass, type Obj, type Project, type ReqInit, type Res, type Sources, type Storage, type Versioner, _epos as default, _epos as epos };
239
+ export { type Arr, type Assets, type Attrs, type Bundle, type Cls, type Epos, type Fn, type FnArgsOrArr, type FnResultOrValue, type Mode, type Model, type Obj, type ObjArrModel, type ObjModel, type Project, type ReqInit, type Res, type Sources, type Storage, type Versioner, _epos as default, _epos as epos };
package/dist/epos.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/epos.ts"],"sourcesContent":["import { Spec } from 'epos-spec'\nimport type * as mobx from 'mobx'\nimport type * as mobxReactLite from 'mobx-react-lite'\nimport type * as react from 'react'\nimport type * as reactDom from 'react-dom'\nimport type * as reactDomClient from 'react-dom/client'\nimport type * as reactJsxRuntime from 'react/jsx-runtime'\nimport type * as yjs from 'yjs'\nimport type { Chrome } from './chrome.ts'\n\nexport type Fn<T = any> = (...args: any[]) => T\nexport type Obj = Record<string, unknown>\nexport type Arr = unknown[]\nexport type Versioner = Record<number, (this: any, state: any) => void>\nexport type ModelClass = new (...args: any[]) => any\nexport type Model = InstanceType<ModelClass>\nexport type Initial<T extends Obj | Model> = T | (() => T)\nexport type Attrs = Record<string, string | number>\nexport type Mode = 'development' | 'production'\nexport type Sources = { [path: string]: string }\nexport type Assets = { [path: string]: Blob }\nexport type FnArgsOrArr<T> = T extends Fn ? Parameters<T> : Arr\nexport type FnResultOrValue<T> = T extends Fn ? ReturnType<T> : T\nexport type Project = { id: string; mode: Mode; spec: Spec }\n\nexport type ReqInit = {\n body: RequestInit['body']\n cache: RequestInit['cache']\n credentials: RequestInit['credentials']\n headers: RequestInit['headers']\n integrity: RequestInit['integrity']\n keepalive: RequestInit['keepalive']\n method: RequestInit['method']\n mode: RequestInit['mode']\n priority: RequestInit['priority']\n redirect: RequestInit['redirect']\n referrer: RequestInit['referrer']\n referrerPolicy: RequestInit['referrerPolicy']\n}\n\nexport type Res = {\n ok: Response['ok']\n url: Response['url']\n type: Response['type']\n status: Response['status']\n statusText: Response['statusText']\n redirected: Response['redirected']\n text: Response['text']\n json: Response['json']\n blob: Response['blob']\n headers: {\n get: Response['headers']['get']\n has: Response['headers']['has']\n /** Get all header keys. */\n keys: () => string[]\n }\n}\n\nexport type Storage = {\n /** Get value from the storage. */\n get<T = unknown>(key: string): Promise<T | null>\n /** Set value in the storage. */\n set(key: string, value: unknown): Promise<void>\n /** Delete key from the storage. */\n delete(key: string): Promise<void>\n /** Get all keys from the storage. */\n keys(): Promise<string[]>\n /** Remove the storage. Removes all keys and storage itself. */\n remove(): Promise<void>\n}\n\nexport type Bundle = {\n mode: Mode\n spec: Spec\n sources: Sources\n assets: Assets\n}\n\nexport interface Epos {\n // General\n fetch: (url: string | URL, init?: ReqInit) => Promise<Res>\n browser: Chrome\n render(node: react.ReactNode, container?: reactDomClient.Container): void\n component<T>(Component: react.FC<T>): typeof Component\n element: HTMLDivElement\n\n // Bus\n bus: {\n /** Listen for an event. */\n on<T extends Fn>(name: string, callback: T, thisArg?: unknown): void\n /** Remove event listener. */\n off<T extends Fn>(name: string, callback?: T): void\n /** Listen for an event once. */\n once<T extends Fn>(name: string, callback: T, thisArg?: unknown): void\n /** Send an event to all remote listeners (local listeners are ignored). */\n send<T = unknown>(name: string, ...args: FnArgsOrArr<T>): Promise<FnResultOrValue<T> | null>\n /** Emit event locally (calls local listeners only). */\n emit<T = unknown>(name: string, ...args: FnArgsOrArr<T>): Promise<FnResultOrValue<T> | null>\n setSignal(name: string, value?: unknown): void\n waitSignal<T = unknown>(name: string, timeout?: number): Promise<T | null>\n }\n\n // State\n state: {\n /** Connect state. */\n connect: {\n <T extends Obj | Model = Obj>(initial?: Initial<T>, versioner?: Versioner): Promise<T>\n <T extends Obj | Model = Obj>(name?: string, initial?: Initial<T>, versioner?: Versioner): Promise<T>\n }\n /** Disconnect state. */\n disconnect(name?: string): void\n /** Run any state changes in a batch. */\n transaction: (fn: () => void) => void\n /** Create local state (no sync). */\n local<T extends Obj = {}>(value?: T, opts?: { deep: boolean }): T\n /** Get the list of all state names. */\n list(filter?: { connected?: boolean }): Promise<{ name: string | null }[]>\n /** Remove state and all its data. */\n remove(name?: string): Promise<void>\n /** Register models to be used by all states. */\n register(models: Record<string, ModelClass>): void\n PARENT: symbol\n ATTACH: symbol\n DETACH: symbol\n }\n\n // Storage\n storage: {\n /** Get value from the storage. */\n get: {\n <T = unknown>(key: string): Promise<T | null>\n <T = unknown>(name: string, key: string): Promise<T | null>\n }\n /** Set value in the storage. */\n set: {\n <T = unknown>(key: string, value: T): Promise<void>\n <T = unknown>(name: string, key: string, value: T): Promise<void>\n }\n /** Delete key from the storage. */\n delete: {\n (key: string): Promise<void>\n (name: string, key: string): Promise<void>\n }\n /** Get all keys from the storage. */\n keys(name?: string): Promise<string[]>\n /** Remove storage. Removes all keys and storage itself. */\n remove(name?: string): Promise<void>\n /** Get storage API for a specific storage. */\n use(name?: string): Storage\n /** Get this list of all storages. */\n list(): Promise<{ name: string | null }[]>\n }\n\n // Frame\n frame: {\n /** Open background frame. */\n open: {\n (url: string): Promise<void>\n (url: string, attrs: Attrs): Promise<void>\n (name: string, url: string): Promise<void>\n (name: string, url: string, attrs: Attrs): Promise<void>\n }\n /** Close background frame. */\n close(name?: string): Promise<void>\n /** Check if background frame with the given name exists. */\n exists(name?: string): Promise<boolean>\n /** Get list of all open background frames. */\n list(): Promise<{ name: string | null; url: string }[]>\n }\n\n // Asset\n asset: {\n /** Load specified asset to memory. Load all assets if no path is provided. */\n load: {\n /** Load all assets. */\n (): Promise<void>\n /** Load asset by path. */\n (path: string): Promise<void>\n }\n /** Unload either all assets from the memory or a specific asset by its path. */\n unload: {\n /** Unload all assets. */\n (): void\n /** Unload asset by path. */\n (path: string): void\n }\n /** Get asset URL. The asset must be loaded first via `epos.asset.load`. */\n url(path: string): string\n /** Get asset as Blob. */\n get(path: string): Promise<Blob | null>\n /** Get list of all available assets. */\n list(filter?: { loaded?: boolean }): { path: string; loaded: boolean }[]\n }\n\n // Env\n env: {\n tabId: number\n project: { id: string; mode: Mode; spec: Spec }\n isPopup: boolean\n isSidePanel: boolean\n isBackground: boolean\n }\n\n // Libs\n libs: {\n mobx: typeof mobx\n mobxReactLite: typeof mobxReactLite\n react: typeof react\n reactDom: typeof reactDom\n reactDomClient: typeof reactDomClient\n reactJsxRuntime: typeof reactJsxRuntime\n yjs: typeof yjs\n }\n\n // Installer\n installer: {\n install: {\n (id: string, url: string, mode?: Mode): Promise<void>\n (id: string, bundle: Bundle): Promise<void>\n }\n remove(name: string): Promise<void>\n watch(handler: (projects: Project[]) => void): void\n list(): Promise<Project[]>\n }\n\n // Engine\n engine: any\n}\n\ndeclare global {\n var epos: Epos\n}\n\nconst _epos = epos\nexport { _epos as epos }\nexport default _epos\n"],"mappings":";AAyOA,IAAM,QAAQ;AAEd,IAAO,eAAQ;","names":[]}
1
+ {"version":3,"sources":["../src/epos.ts"],"sourcesContent":["import { Spec } from 'epos-spec'\nimport type * as mobx from 'mobx'\nimport type * as mobxReactLite from 'mobx-react-lite'\nimport type * as react from 'react'\nimport type * as reactDom from 'react-dom'\nimport type * as reactDomClient from 'react-dom/client'\nimport type * as reactJsxRuntime from 'react/jsx-runtime'\nimport type * as yjs from 'yjs'\nimport type { Chrome } from './chrome.ts'\n\nexport type Fn<T = any> = (...args: any[]) => T\nexport type Cls<T = any> = new (...args: any[]) => T\nexport type Obj = Record<string, unknown>\nexport type Arr = unknown[]\nexport type Model<T> = T extends object ? Exclude<T, Obj | Arr | Fn> : never\nexport type ObjModel<T> = T extends Obj ? T : Model<T>\nexport type ObjArrModel<T> = T extends Obj | Arr ? T : Model<T>\nexport type Versioner<T> = Record<number, (this: T, state: T) => void>\nexport type Mode = 'development' | 'production'\nexport type Sources = { [path: string]: string }\nexport type Assets = { [path: string]: Blob }\nexport type Attrs = Record<string, string | number>\nexport type FnArgsOrArr<T> = T extends Fn ? Parameters<T> : Arr\nexport type FnResultOrValue<T> = T extends Fn ? ReturnType<T> : T\nexport type Project = { id: string; mode: Mode; spec: Spec }\n\nexport type ReqInit = {\n body: RequestInit['body']\n cache: RequestInit['cache']\n credentials: RequestInit['credentials']\n headers: RequestInit['headers']\n integrity: RequestInit['integrity']\n keepalive: RequestInit['keepalive']\n method: RequestInit['method']\n mode: RequestInit['mode']\n priority: RequestInit['priority']\n redirect: RequestInit['redirect']\n referrer: RequestInit['referrer']\n referrerPolicy: RequestInit['referrerPolicy']\n}\n\nexport type Res = {\n ok: Response['ok']\n url: Response['url']\n type: Response['type']\n status: Response['status']\n statusText: Response['statusText']\n redirected: Response['redirected']\n text: Response['text']\n json: Response['json']\n blob: Response['blob']\n headers: {\n get: Response['headers']['get']\n has: Response['headers']['has']\n /** Get all header keys. */\n keys: () => string[]\n }\n}\n\nexport type Storage = {\n /** Get value from the storage. */\n get<T = unknown>(key: string): Promise<T | null>\n /** Set value in the storage. */\n set(key: string, value: unknown): Promise<void>\n /** Delete key from the storage. */\n delete(key: string): Promise<void>\n /** Get all keys from the storage. */\n keys(): Promise<string[]>\n /** Remove the storage. Removes all keys and storage itself. */\n remove(): Promise<void>\n}\n\nexport type Bundle = {\n mode: Mode\n spec: Spec\n sources: Sources\n assets: Assets\n}\n\nexport interface Epos {\n // General\n fetch: (url: string | URL, init?: ReqInit) => Promise<Res>\n browser: Chrome\n render(node: react.ReactNode, container?: reactDomClient.Container): void\n component<T>(Component: react.FC<T>): typeof Component\n element: HTMLDivElement\n\n // Bus\n bus: {\n /** Listen for an event. */\n on<T extends Fn>(name: string, callback: T, thisArg?: unknown): void\n /** Remove event listener. */\n off<T extends Fn>(name: string, callback?: T): void\n /** Listen for an event once. */\n once<T extends Fn>(name: string, callback: T, thisArg?: unknown): void\n /** Send an event to all remote listeners (local listeners are ignored). */\n send<T = unknown>(name: string, ...args: FnArgsOrArr<T>): Promise<FnResultOrValue<T> | null>\n /** Emit event locally (calls local listeners only). */\n emit<T = unknown>(name: string, ...args: FnArgsOrArr<T>): Promise<FnResultOrValue<T> | null>\n setSignal(name: string, value?: unknown): void\n waitSignal<T = unknown>(name: string, timeout?: number): Promise<T | null>\n }\n\n // State\n state: {\n /** Connect state. */\n connect: {\n <T = Obj>(initial?: ObjModel<T>, versioner?: Versioner<T>): Promise<T>\n <T = Obj>(initial?: () => ObjModel<T>, versioner?: Versioner<T>): Promise<T>\n <T = Obj>(name?: string, initial?: ObjModel<T>, versioner?: Versioner<T>): Promise<T>\n <T = Obj>(name?: string, initial?: () => ObjModel<T>, versioner?: Versioner<T>): Promise<T>\n }\n /** Disconnect state. */\n disconnect(name?: string): void\n /** Run any state changes in a batch. */\n transaction: (fn: () => void) => void\n /** Create local state (no sync). */\n local<T = Obj>(state?: ObjArrModel<T>): T\n /** Get the list of all state names. */\n list(filter?: { connected?: boolean }): Promise<{ name: string | null }[]>\n /** Remove state and all its data. */\n remove(name?: string): Promise<void>\n /** Register models that can be used by all states. */\n register(models: Record<string, Cls>): void\n PARENT: symbol\n ATTACH: symbol\n DETACH: symbol\n }\n\n // Storage\n storage: {\n /** Get value from the storage. */\n get: {\n <T = unknown>(key: string): Promise<T | null>\n <T = unknown>(name: string, key: string): Promise<T | null>\n }\n /** Set value in the storage. */\n set: {\n <T = unknown>(key: string, value: T): Promise<void>\n <T = unknown>(name: string, key: string, value: T): Promise<void>\n }\n /** Delete key from the storage. */\n delete: {\n (key: string): Promise<void>\n (name: string, key: string): Promise<void>\n }\n /** Get all storage keys. */\n keys(name?: string): Promise<string[]>\n /** Remove storage. Removes all keys and storage itself. */\n remove(name?: string): Promise<void>\n /** Get storage API for a specific storage. */\n use(name?: string): Storage\n /** Get this list of all storages. */\n list(): Promise<{ name: string | null }[]>\n }\n\n // Frame\n frame: {\n /** Open background frame. */\n open: {\n (url: string): Promise<void>\n (url: string, attrs: Attrs): Promise<void>\n (name: string, url: string): Promise<void>\n (name: string, url: string, attrs: Attrs): Promise<void>\n }\n /** Close background frame. */\n close(name?: string): Promise<void>\n /** Check if background frame with the given name exists. */\n exists(name?: string): Promise<boolean>\n /** Get list of all open background frames. */\n list(): Promise<{ name: string | null; url: string }[]>\n }\n\n // Asset\n asset: {\n /** Load specified asset to memory. Load all assets if no path is provided. */\n load: {\n /** Load all assets. */\n (): Promise<void>\n /** Load asset by path. */\n (path: string): Promise<void>\n }\n /** Unload either all assets from the memory or a specific asset by its path. */\n unload: {\n /** Unload all assets. */\n (): void\n /** Unload asset by path. */\n (path: string): void\n }\n /** Get asset URL. The asset must be loaded first via `epos.asset.load`. */\n url(path: string): string\n /** Get asset as Blob. */\n get(path: string): Promise<Blob | null>\n /** Get list of all available assets. */\n list(filter?: { loaded?: boolean }): { path: string; loaded: boolean }[]\n }\n\n // Env\n env: {\n tabId: number\n project: { id: string; mode: Mode; spec: Spec }\n isPopup: boolean\n isSidePanel: boolean\n isBackground: boolean\n }\n\n // Libs\n libs: {\n mobx: typeof mobx\n mobxReactLite: typeof mobxReactLite\n react: typeof react\n reactDom: typeof reactDom\n reactDomClient: typeof reactDomClient\n reactJsxRuntime: typeof reactJsxRuntime\n yjs: typeof yjs\n }\n\n // Installer\n installer: {\n install: {\n (id: string, url: string, mode?: Mode): Promise<void>\n (id: string, bundle: Bundle): Promise<void>\n }\n remove(name: string): Promise<void>\n watch(handler: (projects: Project[]) => void): void\n list(): Promise<Project[]>\n }\n\n // Engine\n engine: any\n}\n\ndeclare global {\n var epos: Epos\n}\n\nconst _epos = epos\nexport { _epos as epos }\nexport default _epos\n"],"mappings":";AA4OA,IAAM,QAAQ;AAEd,IAAO,eAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "epos",
3
- "version": "1.34.0",
3
+ "version": "1.35.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "imkost",
@@ -24,12 +24,12 @@
24
24
  "@types/chrome": "^0.1.32",
25
25
  "@types/react": "^19.2.7",
26
26
  "@types/react-dom": "^19.2.3",
27
- "epos-spec": "^1.4.0",
27
+ "epos-spec": "^1.5.0",
28
28
  "mobx": "^6.15.0",
29
29
  "mobx-react-lite": "^4.1.1",
30
30
  "portfinder": "^1.0.38",
31
31
  "react": "^19.2.3",
32
- "ws": "^8.18.3",
32
+ "ws": "^8.19.0",
33
33
  "yjs": "^13.6.29"
34
34
  },
35
35
  "devDependencies": {