epos 1.30.0 → 1.31.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 (3) hide show
  1. package/dist/epos.d.ts +31 -11
  2. package/package.json +10 -19
  3. package/src/epos.ts +31 -11
package/dist/epos.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Spec } from 'epos-spec';
1
2
  import * as mobx from 'mobx';
2
3
  import * as mobxReactLite from 'mobx-react-lite';
3
4
  import * as react from 'react';
@@ -15,11 +16,15 @@ type ModelClass = new (...args: any[]) => any;
15
16
  type Model = InstanceType<ModelClass>;
16
17
  type Initial<T extends Obj | Model> = T | (() => T);
17
18
  type Attrs = Record<string, string | number>;
19
+ type Mode = 'development' | 'production';
20
+ type Sources = {
21
+ [path: string]: string;
22
+ };
23
+ type Assets = {
24
+ [path: string]: Blob;
25
+ };
18
26
  type FnArgsOrArr<T> = T extends Fn ? Parameters<T> : Arr;
19
27
  type FnResultOrValue<T> = T extends Fn ? ReturnType<T> : T;
20
- type StateConfig = {
21
- allowMissingModels?: boolean | string[];
22
- };
23
28
  type ReqInit = {
24
29
  body: RequestInit['body'];
25
30
  cache: RequestInit['cache'];
@@ -63,6 +68,12 @@ type Storage = {
63
68
  /** Clear the storage. Deletes all keys and storage itself. */
64
69
  clear(): Promise<void>;
65
70
  };
71
+ type Bundle = {
72
+ mode: Mode;
73
+ spec: Spec;
74
+ sources: Sources;
75
+ assets: Assets;
76
+ };
66
77
  interface Epos {
67
78
  fetch: (url: string | URL, init?: ReqInit) => Promise<Res>;
68
79
  browser: Chrome;
@@ -77,17 +88,17 @@ interface Epos {
77
88
  /** Listen for an event once. */
78
89
  once<T extends Fn>(name: string, callback: T, thisArg?: unknown): void;
79
90
  /** Send an event to all remote listeners (local listeners are ignored). */
80
- send<T = unknown>(name: string, ...args: FnArgsOrArr<T>): Promise<FnResultOrValue<T>>;
91
+ send<T = unknown>(name: string, ...args: FnArgsOrArr<T>): Promise<FnResultOrValue<T> | null>;
81
92
  /** Emit event locally (calls local listeners only). */
82
- emit<T = unknown>(name: string, ...args: FnArgsOrArr<T>): Promise<FnResultOrValue<T>>;
93
+ emit<T = unknown>(name: string, ...args: FnArgsOrArr<T>): Promise<FnResultOrValue<T> | null>;
83
94
  setSignal(name: string, value?: unknown): void;
84
- waitSignal<T = unknown>(name: string, timeout?: number): Promise<T>;
95
+ waitSignal<T = unknown>(name: string, timeout?: number): Promise<T | null>;
85
96
  };
86
97
  state: {
87
98
  /** Connect state. */
88
99
  connect: {
89
- <T extends Obj | Model>(initial?: Initial<T>, versioner?: Versioner): Promise<T>;
90
- <T extends Obj | Model>(name?: string, initial?: Initial<T>, versioner?: Versioner): Promise<T>;
100
+ <T extends Obj | Model = Obj>(initial?: Initial<T>, versioner?: Versioner): Promise<T>;
101
+ <T extends Obj | Model = Obj>(name?: string, initial?: Initial<T>, versioner?: Versioner): Promise<T>;
91
102
  };
92
103
  /** Disconnect state. */
93
104
  disconnect(name?: string): void;
@@ -152,7 +163,7 @@ interface Epos {
152
163
  }[]>;
153
164
  };
154
165
  asset: {
155
- /** Load either all assets to the memory or a specific asset by its path. */
166
+ /** Load specified asset to memory. Load all assets if no path is provided. */
156
167
  load: {
157
168
  /** Load all assets. */
158
169
  (): Promise<void>;
@@ -170,7 +181,7 @@ interface Epos {
170
181
  url(path: string): string;
171
182
  /** Get asset as Blob. */
172
183
  get(path: string): Promise<Blob | null>;
173
- /** Get list of all available asset files. */
184
+ /** Get list of all available assets. */
174
185
  list(filter?: {
175
186
  loaded?: boolean;
176
187
  }): {
@@ -179,6 +190,7 @@ interface Epos {
179
190
  }[];
180
191
  };
181
192
  env: {
193
+ mode: Mode;
182
194
  tabId: number;
183
195
  project: string;
184
196
  isPopup: boolean;
@@ -201,10 +213,18 @@ interface Epos {
201
213
  readonly stateModelStrict: symbol;
202
214
  readonly stateModelVersioner: symbol;
203
215
  };
216
+ installer: {
217
+ install: {
218
+ (url: string, mode?: Mode): Promise<void>;
219
+ (bundle: Bundle): Promise<void>;
220
+ };
221
+ remove(name: string): Promise<void>;
222
+ };
223
+ engine: any;
204
224
  }
205
225
  declare global {
206
226
  var epos: Epos;
207
227
  }
208
228
  declare const _epos: Epos;
209
229
 
210
- export { type Arr, type Attrs, 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 };
230
+ 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 ReqInit, type Res, type Sources, type Storage, type Versioner, _epos as default, _epos as epos };
package/package.json CHANGED
@@ -1,47 +1,38 @@
1
1
  {
2
2
  "name": "epos",
3
- "version": "1.30.0",
3
+ "version": "1.31.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 --dts-resolve",
11
- "build": "tsup --config ../../tsup.config.ts --dts-resolve",
10
+ "dev": "tsup --config ../../tsup.config.ts --watch",
11
+ "build": "tsup --config ../../tsup.config.ts",
12
12
  "lint": "tsc --noEmit",
13
13
  "release": "sh -c 'npm version ${1:-minor} && npm run build && npm publish' --"
14
14
  },
15
15
  "exports": {
16
- ".": {
17
- "source": "./src/epos.ts",
18
- "import": "./dist/epos.js",
19
- "types": "./dist/epos.d.ts"
20
- },
21
- "./vite": {
22
- "source": "./src/epos-vite.ts",
23
- "import": "./dist/epos-vite.js",
24
- "types": "./dist/epos-vite.d.ts"
25
- },
26
- "./vite/ts": {
27
- "import": "./src/epos-vite.ts"
28
- }
16
+ ".": "./dist/epos.js",
17
+ "./vite": "./dist/epos-vite.js",
18
+ "./vite/ts": "./src/epos-vite.ts"
29
19
  },
30
20
  "files": [
31
- "src",
32
- "dist"
21
+ "dist",
22
+ "src"
33
23
  ],
34
24
  "dependencies": {
35
25
  "@parcel/watcher": "^2.5.1",
36
26
  "@types/chrome": "^0.1.32",
37
27
  "@types/react": "^19.2.7",
38
28
  "@types/react-dom": "^19.2.3",
29
+ "epos-spec": "^1.0.0",
39
30
  "mobx": "^6.15.0",
40
31
  "mobx-react-lite": "^4.1.1",
41
32
  "portfinder": "^1.0.38",
42
33
  "react": "^19.2.3",
43
34
  "ws": "^8.18.3",
44
- "yjs": "^13.6.27"
35
+ "yjs": "^13.6.28"
45
36
  },
46
37
  "devDependencies": {
47
38
  "vite": "^7.3.0"
package/src/epos.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Spec } from 'epos-spec'
1
2
  import type * as mobx from 'mobx'
2
3
  import type * as mobxReactLite from 'mobx-react-lite'
3
4
  import type * as react from 'react'
@@ -15,13 +16,12 @@ export type ModelClass = new (...args: any[]) => any
15
16
  export type Model = InstanceType<ModelClass>
16
17
  export type Initial<T extends Obj | Model> = T | (() => T)
17
18
  export type Attrs = Record<string, string | number>
19
+ export type Mode = 'development' | 'production'
20
+ export type Sources = { [path: string]: string }
21
+ export type Assets = { [path: string]: Blob }
18
22
  export type FnArgsOrArr<T> = T extends Fn ? Parameters<T> : Arr
19
23
  export type FnResultOrValue<T> = T extends Fn ? ReturnType<T> : T
20
24
 
21
- export type StateConfig = {
22
- allowMissingModels?: boolean | string[]
23
- }
24
-
25
25
  export type ReqInit = {
26
26
  body: RequestInit['body']
27
27
  cache: RequestInit['cache']
@@ -68,6 +68,13 @@ export type Storage = {
68
68
  clear(): Promise<void>
69
69
  }
70
70
 
71
+ export type Bundle = {
72
+ mode: Mode
73
+ spec: Spec
74
+ sources: Sources
75
+ assets: Assets
76
+ }
77
+
71
78
  export interface Epos {
72
79
  // General
73
80
  fetch: (url: string | URL, init?: ReqInit) => Promise<Res>
@@ -85,19 +92,19 @@ export interface Epos {
85
92
  /** Listen for an event once. */
86
93
  once<T extends Fn>(name: string, callback: T, thisArg?: unknown): void
87
94
  /** Send an event to all remote listeners (local listeners are ignored). */
88
- send<T = unknown>(name: string, ...args: FnArgsOrArr<T>): Promise<FnResultOrValue<T>>
95
+ send<T = unknown>(name: string, ...args: FnArgsOrArr<T>): Promise<FnResultOrValue<T> | null>
89
96
  /** Emit event locally (calls local listeners only). */
90
- emit<T = unknown>(name: string, ...args: FnArgsOrArr<T>): Promise<FnResultOrValue<T>>
97
+ emit<T = unknown>(name: string, ...args: FnArgsOrArr<T>): Promise<FnResultOrValue<T> | null>
91
98
  setSignal(name: string, value?: unknown): void
92
- waitSignal<T = unknown>(name: string, timeout?: number): Promise<T>
99
+ waitSignal<T = unknown>(name: string, timeout?: number): Promise<T | null>
93
100
  }
94
101
 
95
102
  // State
96
103
  state: {
97
104
  /** Connect state. */
98
105
  connect: {
99
- <T extends Obj | Model>(initial?: Initial<T>, versioner?: Versioner): Promise<T>
100
- <T extends Obj | Model>(name?: string, initial?: Initial<T>, versioner?: Versioner): Promise<T>
106
+ <T extends Obj | Model = Obj>(initial?: Initial<T>, versioner?: Versioner): Promise<T>
107
+ <T extends Obj | Model = Obj>(name?: string, initial?: Initial<T>, versioner?: Versioner): Promise<T>
101
108
  }
102
109
  /** Disconnect state. */
103
110
  disconnect(name?: string): void
@@ -159,7 +166,7 @@ export interface Epos {
159
166
 
160
167
  // Asset
161
168
  asset: {
162
- /** Load either all assets to the memory or a specific asset by its path. */
169
+ /** Load specified asset to memory. Load all assets if no path is provided. */
163
170
  load: {
164
171
  /** Load all assets. */
165
172
  (): Promise<void>
@@ -177,12 +184,13 @@ export interface Epos {
177
184
  url(path: string): string
178
185
  /** Get asset as Blob. */
179
186
  get(path: string): Promise<Blob | null>
180
- /** Get list of all available asset files. */
187
+ /** Get list of all available assets. */
181
188
  list(filter?: { loaded?: boolean }): { path: string; loaded: boolean }[]
182
189
  }
183
190
 
184
191
  // Env
185
192
  env: {
193
+ mode: Mode
186
194
  tabId: number
187
195
  project: string
188
196
  isPopup: boolean
@@ -209,6 +217,18 @@ export interface Epos {
209
217
  readonly stateModelStrict: symbol
210
218
  readonly stateModelVersioner: symbol
211
219
  }
220
+
221
+ // Installer
222
+ installer: {
223
+ install: {
224
+ (url: string, mode?: Mode): Promise<void>
225
+ (bundle: Bundle): Promise<void>
226
+ }
227
+ remove(name: string): Promise<void>
228
+ }
229
+
230
+ // Engine
231
+ engine: any
212
232
  }
213
233
 
214
234
  declare global {