@monimesl/dot-dash 0.1.0-alpha.2 → 0.1.0-alpha.3

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/index.d.ts CHANGED
@@ -1,4 +1,159 @@
1
1
  import { HostCallOptions, HostError, HostErrorCode, HostRequest } from "@monimesl/dot-core";
2
+ //#region src/files.d.ts
3
+ interface DotFile {
4
+ id: string;
5
+ name: string;
6
+ size: number;
7
+ contentType: string;
8
+ url: string;
9
+ }
10
+ declare namespace http_d_exports {
11
+ export { HttpDownloadRequest, HttpDownloadResponse, HttpMethod, HttpMethods, HttpReadOptions, HttpRequest, HttpRequestBody, HttpResponse, HttpUploadFile, HttpUploadRequest, download, request, upload };
12
+ }
13
+ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
14
+ type HttpRequestBody = string | object;
15
+ interface HttpRequest<Body extends HttpRequestBody = HttpRequestBody> {
16
+ url: string;
17
+ method?: HttpMethod;
18
+ headers?: Record<string, string>;
19
+ body?: Body;
20
+ }
21
+ interface HttpResponse<Body = string> {
22
+ ok: boolean;
23
+ status: number;
24
+ statusText: string;
25
+ headers: Record<string, string>;
26
+ body: Body;
27
+ }
28
+ type HttpReadOptions<Body> = [Body] extends [string] ? {
29
+ as?: 'text';
30
+ } : {
31
+ as: 'json';
32
+ };
33
+ interface HttpDownloadRequest extends HttpRequest {
34
+ name?: string;
35
+ }
36
+ type HttpDownloadResponse = (Omit<HttpResponse, 'ok' | 'body'> & {
37
+ ok: true;
38
+ file: DotFile;
39
+ }) | (Omit<HttpResponse, 'ok'> & {
40
+ ok: false;
41
+ });
42
+ interface HttpUploadFile {
43
+ field: string;
44
+ file: DotFile | string;
45
+ name?: string;
46
+ }
47
+ interface HttpUploadRequest {
48
+ url: string;
49
+ method?: 'POST' | 'PUT' | 'PATCH';
50
+ headers?: Record<string, string>;
51
+ fields?: Record<string, string>;
52
+ files: HttpUploadFile[];
53
+ }
54
+ type WireRequest<Request extends HttpRequest> = Omit<Request, 'headers' | 'body'> & {
55
+ headers?: Record<string, string> | undefined;
56
+ body?: string | undefined;
57
+ };
58
+ interface HttpMethods {
59
+ 'dash.network.http.request': {
60
+ params: WireRequest<HttpRequest>;
61
+ result: HttpResponse;
62
+ };
63
+ 'dash.network.http.download': {
64
+ params: WireRequest<HttpDownloadRequest>;
65
+ result: HttpDownloadResponse;
66
+ };
67
+ 'dash.network.http.upload': {
68
+ params: Omit<HttpUploadRequest, 'files'> & {
69
+ files: {
70
+ field: string;
71
+ file: string;
72
+ name?: string;
73
+ }[];
74
+ };
75
+ result: HttpResponse;
76
+ };
77
+ }
78
+ declare function request<ResponseBody = string, RequestBody extends HttpRequestBody = HttpRequestBody>(options: HttpRequest<RequestBody> & HttpReadOptions<ResponseBody>, callOptions?: CallOptions): DashRequest<HttpResponse<ResponseBody>>;
79
+ declare function download(options: HttpDownloadRequest, callOptions?: CallOptions): DashRequest<HttpDownloadResponse>;
80
+ declare function upload<ResponseBody = string>(options: HttpUploadRequest & HttpReadOptions<ResponseBody>, callOptions?: CallOptions): DashRequest<HttpResponse<ResponseBody>>;
81
+ declare namespace index_d_exports$3 {
82
+ export { HttpDownloadRequest, HttpDownloadResponse, HttpMethod, HttpReadOptions, HttpRequest, HttpRequestBody, HttpResponse, HttpUploadFile, HttpUploadRequest, NetworkMethods, http_d_exports as http };
83
+ }
84
+ type NetworkMethods = HttpMethods;
85
+ //#endregion
86
+ //#region src/system/clipboard.d.ts
87
+ interface ClipboardMethods {
88
+ 'dash.system.copyText': {
89
+ params: {
90
+ text: string;
91
+ };
92
+ result: void;
93
+ };
94
+ }
95
+ declare function copyText(text: string, callOptions?: CallOptions): DashRequest<void>;
96
+ //#endregion
97
+ //#region src/system/delay.d.ts
98
+ interface DelayMethods {
99
+ 'dash.system.delay': {
100
+ params: {
101
+ milliseconds: number;
102
+ };
103
+ result: void;
104
+ };
105
+ }
106
+ declare function delay(milliseconds: number, callOptions?: CallOptions): DashRequest<void>;
107
+ //#endregion
108
+ //#region src/system/haptics.d.ts
109
+ type VibrationStyle = 'light' | 'medium' | 'heavy' | 'success' | 'warning' | 'error';
110
+ interface VibrateOptions {
111
+ style?: VibrationStyle | undefined;
112
+ }
113
+ interface HapticsMethods {
114
+ 'dash.system.vibrate': {
115
+ params: VibrateOptions;
116
+ result: void;
117
+ };
118
+ }
119
+ declare function vibrate(options?: VibrateOptions, callOptions?: CallOptions): DashRequest<void>;
120
+ //#endregion
121
+ //#region src/system/share.d.ts
122
+ interface ShareOptions {
123
+ title?: string;
124
+ text?: string;
125
+ url?: string;
126
+ file?: DotFile | string;
127
+ }
128
+ interface ShareMethods {
129
+ 'dash.system.share': {
130
+ params: {
131
+ title?: string;
132
+ text?: string;
133
+ url?: string;
134
+ file?: string;
135
+ };
136
+ result: void;
137
+ };
138
+ }
139
+ declare function share(options: ShareOptions, callOptions?: CallOptions): DashRequest<void>;
140
+ //#endregion
141
+ //#region src/system/torch.d.ts
142
+ type TorchState = 'on' | 'off';
143
+ interface TorchMethods {
144
+ 'dash.system.torch': {
145
+ params: {
146
+ state: TorchState;
147
+ };
148
+ result: void;
149
+ };
150
+ }
151
+ declare function torch(state: TorchState, callOptions?: CallOptions): DashRequest<void>;
152
+ declare namespace index_d_exports$2 {
153
+ export { ShareOptions, SystemMethods, TorchState, VibrateOptions, VibrationStyle, copyText, delay, share, torch, vibrate };
154
+ }
155
+ type SystemMethods = ClipboardMethods & DelayMethods & HapticsMethods & ShareMethods & TorchMethods;
156
+ //#endregion
2
157
  //#region src/ui/dialogs.d.ts
3
158
  interface AlertAction {
4
159
  id: string;
@@ -26,47 +181,143 @@ declare namespace index_d_exports$1 {
26
181
  type UIMethods = DialogMethods;
27
182
  //#endregion
28
183
  //#region src/methods.d.ts
29
- type DashMethods = UIMethods & SystemMethods;
184
+ type DashMethods = UIMethods & SystemMethods & NetworkMethods & FileMethods;
30
185
  type DashMethod = keyof DashMethods;
31
186
  //#endregion
32
187
  //#region src/call.d.ts
33
188
  type CallOptions = HostCallOptions;
34
189
  type DashRequest<Result> = HostRequest<Result>;
35
- //#endregion
36
- //#region src/system/haptics.d.ts
37
- type VibrationStyle = 'light' | 'medium' | 'heavy' | 'success' | 'warning' | 'error';
38
- interface VibrateOptions {
39
- style?: VibrationStyle | undefined;
190
+ declare namespace index_d_exports {
191
+ export { FileEncoding, FileEntry, FileMethods, ReadOptions, ReplaceOptions, StorageUsage, WriteOptions, copy, createFolder, list, move, open, read, remove, save, stat, usage, write };
40
192
  }
41
- interface HapticsMethods {
42
- 'dash.system.vibrate': {
43
- params: VibrateOptions;
44
- result: void;
45
- };
193
+ interface FileEntry {
194
+ name: string;
195
+ path: string;
196
+ size: number;
197
+ kind: 'file' | 'folder';
198
+ modifiedAt: number;
199
+ contentType?: string;
46
200
  }
47
- declare function vibrate(options?: VibrateOptions, callOptions?: CallOptions): DashRequest<void>;
48
- //#endregion
49
- //#region src/system/torch.d.ts
50
- type TorchState = 'on' | 'off';
51
- interface TorchMethods {
52
- 'dash.system.torch': {
201
+ type FileEncoding = 'text' | 'base64';
202
+ interface StorageUsage {
203
+ used: number;
204
+ quota: number;
205
+ }
206
+ interface FileMethods {
207
+ 'dash.file.read': {
53
208
  params: {
54
- state: TorchState;
209
+ path: string;
210
+ as?: FileEncoding;
211
+ };
212
+ result: string;
213
+ };
214
+ 'dash.file.write': {
215
+ params: {
216
+ path: string;
217
+ data: string;
218
+ as?: FileEncoding;
219
+ append?: boolean;
220
+ };
221
+ result: FileEntry;
222
+ };
223
+ 'dash.file.stat': {
224
+ params: {
225
+ path: string;
226
+ };
227
+ result: FileEntry | null;
228
+ };
229
+ 'dash.file.list': {
230
+ params: {
231
+ path: string;
232
+ recursive?: boolean;
233
+ };
234
+ result: FileEntry[];
235
+ };
236
+ 'dash.file.createFolder': {
237
+ params: {
238
+ path: string;
239
+ };
240
+ result: FileEntry;
241
+ };
242
+ 'dash.file.move': {
243
+ params: {
244
+ from: string;
245
+ to: string;
246
+ overwrite?: boolean;
247
+ };
248
+ result: FileEntry;
249
+ };
250
+ 'dash.file.copy': {
251
+ params: {
252
+ from: string;
253
+ to: string;
254
+ overwrite?: boolean;
255
+ };
256
+ result: FileEntry;
257
+ };
258
+ 'dash.file.remove': {
259
+ params: {
260
+ path: string;
261
+ recursive?: boolean;
55
262
  };
56
263
  result: void;
57
264
  };
265
+ 'dash.file.save': {
266
+ params: {
267
+ file: string;
268
+ path: string;
269
+ overwrite?: boolean;
270
+ };
271
+ result: FileEntry;
272
+ };
273
+ 'dash.file.open': {
274
+ params: {
275
+ path: string;
276
+ };
277
+ result: DotFile;
278
+ };
279
+ 'dash.file.usage': {
280
+ params: Record<string, never>;
281
+ result: StorageUsage;
282
+ };
58
283
  }
59
- declare function torch(state: TorchState, callOptions?: CallOptions): DashRequest<void>;
60
- declare namespace index_d_exports {
61
- export { SystemMethods, TorchState, VibrateOptions, VibrationStyle, torch, vibrate };
284
+ interface ReadOptions {
285
+ as?: FileEncoding;
62
286
  }
63
- type SystemMethods = HapticsMethods & TorchMethods;
287
+ interface WriteOptions {
288
+ as?: FileEncoding;
289
+ append?: boolean;
290
+ }
291
+ interface ReplaceOptions {
292
+ overwrite?: boolean;
293
+ }
294
+ declare function read(path: string, options?: ReadOptions, callOptions?: CallOptions): DashRequest<string>;
295
+ declare function write(path: string, data: string, options?: WriteOptions, callOptions?: CallOptions): DashRequest<FileEntry>;
296
+ declare function stat(path: string, callOptions?: CallOptions): DashRequest<FileEntry | null>;
297
+ declare function list(path?: string, options?: {
298
+ recursive?: boolean;
299
+ }, callOptions?: CallOptions): DashRequest<FileEntry[]>;
300
+ declare function createFolder(path: string, callOptions?: CallOptions): DashRequest<FileEntry>;
301
+ declare function move(from: string, to: string, options?: ReplaceOptions, callOptions?: CallOptions): DashRequest<FileEntry>;
302
+ declare function copy(from: string, to: string, options?: ReplaceOptions, callOptions?: CallOptions): DashRequest<FileEntry>;
303
+ declare function remove(path: string, options?: {
304
+ recursive?: boolean;
305
+ }, callOptions?: CallOptions): DashRequest<void>;
306
+ declare function save(file: DotFile | string, path: string, options?: ReplaceOptions, callOptions?: CallOptions): DashRequest<FileEntry>;
307
+ declare function open(path: string, callOptions?: CallOptions): DashRequest<DotFile>;
308
+ declare function usage(callOptions?: CallOptions): DashRequest<StorageUsage>;
309
+ //#endregion
310
+ //#region src/tracked.d.ts
311
+ export declare function tracked<Group extends object>(group: Group, track: (request: DashRequest<unknown>) => void): Group;
64
312
  //#endregion
65
313
  //#region src/index.d.ts
66
314
  export declare const dash: {
67
315
  ui: typeof index_d_exports$1;
68
- system: typeof index_d_exports;
316
+ system: typeof index_d_exports$2;
317
+ network: typeof index_d_exports$3;
318
+ file: typeof index_d_exports;
69
319
  };
320
+ export type Dash = typeof dash;
70
321
  //#endregion
71
- export { type AlertAction, type AlertOptions, type AlertResult, type CallOptions, type DashMethod, type DashMethods, type DashRequest, HostError, type HostErrorCode, type SystemMethods, type TorchState, type UIMethods, type VibrateOptions, type VibrationStyle };
322
+ export { type AlertAction, type AlertOptions, type AlertResult, type CallOptions, type DashMethod, type DashMethods, type DashRequest, type DotFile, type FileEncoding, type FileEntry, type FileMethods, HostError, type HostErrorCode, type HttpDownloadRequest, type HttpDownloadResponse, type HttpMethod, type HttpReadOptions, type HttpRequest, type HttpRequestBody, type HttpResponse, type HttpUploadFile, type HttpUploadRequest, type NetworkMethods, type ReadOptions, type ReplaceOptions, type ShareOptions, type StorageUsage, type SystemMethods, type TorchState, type UIMethods, type VibrateOptions, type VibrationStyle, type WriteOptions };
72
323
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/ui/dialogs.ts","../src/ui/index.ts","../src/methods.ts","../src/call.ts","../src/system/haptics.ts","../src/system/torch.ts","../src/system/index.ts","../src/index.ts"],"mappings":";;UAGiB;EACf;EACA;EAEA;;UAGe;EACf;EACA;EAEA,UAAU;;UAGK;EAEf;;UAGe;EACf;IAAmB,QAAQ;IAAc,QAAQ;;;iBAInC,MAAM,SAAS,cAAc,cAAc,cAAc,YAAY;;;;KCtBzE,YAAY;;;KCAZ,cAAc,YAAY;KAE1B,mBAAmB;;;KCFnB,cAAc;KAGd,YAAY,UAAU,YAAY;;;KCLlC;UAEK;EAEf,QAAQ;;UAGO;EACf;IAAyB,QAAQ;IAAgB;;;iBAInC,QACd,UAAS,gBACT,cAAc,cACb;;;KCfS;UAEK;EACf;IAAuB;MAAU,OAAO;;IAAc;;;iBAIxC,MAAM,OAAO,YAAY,cAAc,cAAc;;;;KCFzD,gBAAgB,iBAAiB;;;qBCJhC;aAAA;iBAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/files.ts","../src/network/http.ts","../src/network/index.ts","../src/system/clipboard.ts","../src/system/delay.ts","../src/system/haptics.ts","../src/system/share.ts","../src/system/torch.ts","../src/system/index.ts","../src/ui/dialogs.ts","../src/ui/index.ts","../src/methods.ts","../src/call.ts","../src/file/index.ts","../src/tracked.ts","../src/index.ts"],"mappings":";;UACiB;EACf;EACA;EACA;EACA;EACA;;;;;KCAU;KAEA;UAEK,YAAY,aAAa,kBAAkB;EAC1D;EACA,SAAS;EACT,UAAU;EACV,OAAO;;UAGQ,aAAa;EAC5B;EACA;EACA;EACA,SAAS;EACT,MAAM;;KAII,gBAAgB,SAAS;EAA2B;;EAAkB;;UAEjE,4BAA4B;EAC3C;;KAGU,wBACP,KAAK;EAAiC;EAAU,MAAM;MACtD,KAAK;EAAwB;;UAEjB;EACf;EACA,MAAM;EACN;;UAGe;EACf;EAEA;EACA,UAAU;EACV,SAAS;EACT,OAAO;;KAGJ,YAAY,gBAAgB,eAAe,KAAK;EACnD,UAAU;EACV;;UAKe;EACf;IAA+B,QAAQ,YAAY;IAAc,QAAQ;;EACzE;IACE,QAAQ,YAAY;IACpB,QAAQ;;EAEV;IACE,QAAQ,KAAK;MACX;QAAS;QAAe;QAAc;;;IAExC,QAAQ;;;iBAKI,QACd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EAC3E;IAA4B;MAAU;;IAAgB,QAAQ;;EAC9D;IACE;MAAU;MAAc;MAAY;;IACpC,QAAQ;;EAEV;IACE;MAAU;MAAc;MAAY;;IACpC,QAAQ;;EAEV;IAAsB;MAAU;MAAc;;IAAuB;;EACrE;IACE;MAAU;MAAc;MAAc;;IACtC,QAAQ;;EAEV;IAAoB;MAAU;;IAAgB,QAAQ;;EACtD;IAAqB,QAAQ;IAAuB,QAAQ;;;UAG7C;EACf,KAAK;;UAGU;EACf,KAAK;EACL;;UAGe;EACf;;iBAIc,KACd,cACA,UAAS,aACT,cAAc,cACb;iBAKa,MACd,cACA,cACA,UAAS,cACT,cAAc,cACb,YAAY;iBAIC,KAAK,cAAc,cAAc,cAAc,YAAY;iBAK3D,KACd,eACA;EAAW;GACX,cAAc,cACb,YAAY;iBAIC,aAAa,cAAc,cAAc,cAAc,YAAY;iBAInE,KACd,cACA,YACA,UAAS,gBACT,cAAc,cACb,YAAY;iBAIC,KACd,cACA,YACA,UAAS,gBACT,cAAc,cACb,YAAY;iBAKC,OACd,cACA;EAAW;GACX,cAAc,cACb;iBAKa,KACd,MAAM,kBACN,cACA,UAAS,gBACT,cAAc,cACb,YAAY;iBAMC,KAAK,cAAc,cAAc,cAAc,YAAY;iBAI3D,MAAM,cAAc,cAAc,YAAY;;;wBCzI9C,QAAQ,sBACtB,OAAO,OACP,QAAQ,SAAS,gCAChB;;;qBCAU;;;;;;YAED,cAAc"}
package/dist/index.js CHANGED
@@ -1,15 +1,178 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
2
- import { HostError, callHost } from "@monimesl/dot-core";
2
+ import { HostError, HostError as HostError$1, callHost, createHostRequest } from "@monimesl/dot-core";
3
3
  //#region src/call.ts
4
4
  function call(method, params, options = {}) {
5
5
  return callHost(method, params, options);
6
6
  }
7
7
  //#endregion
8
+ //#region src/file/index.ts
9
+ var file_exports = /* @__PURE__ */ __exportAll({
10
+ copy: () => copy,
11
+ createFolder: () => createFolder,
12
+ list: () => list,
13
+ move: () => move,
14
+ open: () => open,
15
+ read: () => read,
16
+ remove: () => remove,
17
+ save: () => save,
18
+ stat: () => stat,
19
+ usage: () => usage,
20
+ write: () => write
21
+ });
22
+ function read(path, options = {}, callOptions) {
23
+ return call("dash.file.read", {
24
+ path,
25
+ ...options
26
+ }, callOptions);
27
+ }
28
+ function write(path, data, options = {}, callOptions) {
29
+ return call("dash.file.write", {
30
+ path,
31
+ data,
32
+ ...options
33
+ }, callOptions);
34
+ }
35
+ function stat(path, callOptions) {
36
+ return call("dash.file.stat", { path }, callOptions);
37
+ }
38
+ function list(path = "", options = {}, callOptions) {
39
+ return call("dash.file.list", {
40
+ path,
41
+ ...options
42
+ }, callOptions);
43
+ }
44
+ function createFolder(path, callOptions) {
45
+ return call("dash.file.createFolder", { path }, callOptions);
46
+ }
47
+ function move(from, to, options = {}, callOptions) {
48
+ return call("dash.file.move", {
49
+ from,
50
+ to,
51
+ ...options
52
+ }, callOptions);
53
+ }
54
+ function copy(from, to, options = {}, callOptions) {
55
+ return call("dash.file.copy", {
56
+ from,
57
+ to,
58
+ ...options
59
+ }, callOptions);
60
+ }
61
+ function remove(path, options = {}, callOptions) {
62
+ return call("dash.file.remove", {
63
+ path,
64
+ ...options
65
+ }, callOptions);
66
+ }
67
+ function save(file, path, options = {}, callOptions) {
68
+ return call("dash.file.save", {
69
+ file: typeof file === "string" ? file : file.id,
70
+ path,
71
+ ...options
72
+ }, callOptions);
73
+ }
74
+ function open(path, callOptions) {
75
+ return call("dash.file.open", { path }, callOptions);
76
+ }
77
+ function usage(callOptions) {
78
+ return call("dash.file.usage", {}, callOptions);
79
+ }
80
+ //#endregion
81
+ //#region src/network/http.ts
82
+ var http_exports = /* @__PURE__ */ __exportAll({
83
+ download: () => download,
84
+ request: () => request,
85
+ upload: () => upload
86
+ });
87
+ function request(options, callOptions) {
88
+ const { as, ...request } = options;
89
+ return readBody(call("dash.network.http.request", wireRequest(request, as), callOptions), as);
90
+ }
91
+ function download(options, callOptions) {
92
+ return call("dash.network.http.download", wireRequest(options), callOptions);
93
+ }
94
+ function upload(options, callOptions) {
95
+ const { as, ...request } = options;
96
+ const files = request.files.map(({ file, ...rest }) => ({
97
+ ...rest,
98
+ file: typeof file === "string" ? file : file.id
99
+ }));
100
+ const params = {
101
+ ...request,
102
+ files
103
+ };
104
+ if (as === "json") params.headers = withDefaultHeader(request.headers, "Accept", "application/json");
105
+ return readBody(call("dash.network.http.upload", params, callOptions), as);
106
+ }
107
+ function wireRequest(request, as) {
108
+ let headers = request.headers;
109
+ let body;
110
+ if (as === "json") headers = withDefaultHeader(headers, "Accept", "application/json");
111
+ if (typeof request.body === "string") body = request.body;
112
+ else if (request.body !== void 0) {
113
+ headers = withDefaultHeader(headers, "Content-Type", "application/json");
114
+ body = JSON.stringify(request.body);
115
+ }
116
+ return {
117
+ ...request,
118
+ headers,
119
+ body
120
+ };
121
+ }
122
+ function withDefaultHeader(headers, name, value) {
123
+ const lowerName = name.toLowerCase();
124
+ if (headers && Object.keys(headers).some((existing) => existing.toLowerCase() === lowerName)) return headers;
125
+ return {
126
+ ...headers,
127
+ [name]: value
128
+ };
129
+ }
130
+ function readBody(response, as) {
131
+ if (as !== "json") return response;
132
+ const parsed = response.then((result) => ({
133
+ ...result,
134
+ body: parseJson(result)
135
+ }));
136
+ return createHostRequest(parsed, () => response.cancel());
137
+ }
138
+ function parseJson({ status, statusText, body }) {
139
+ try {
140
+ return JSON.parse(body);
141
+ } catch (error) {
142
+ const message = error instanceof Error ? error.message : String(error);
143
+ throw new HostError$1("failed", `The response (${status} ${statusText}) isn't JSON: ${message}`);
144
+ }
145
+ }
146
+ //#endregion
147
+ //#region src/network/index.ts
148
+ var network_exports = /* @__PURE__ */ __exportAll({ http: () => http_exports });
149
+ //#endregion
150
+ //#region src/system/clipboard.ts
151
+ function copyText(text, callOptions) {
152
+ return call("dash.system.copyText", { text }, callOptions);
153
+ }
154
+ //#endregion
155
+ //#region src/system/delay.ts
156
+ function delay(milliseconds, callOptions) {
157
+ return call("dash.system.delay", { milliseconds }, callOptions);
158
+ }
159
+ //#endregion
8
160
  //#region src/system/haptics.ts
9
161
  function vibrate(options = {}, callOptions) {
10
162
  return call("dash.system.vibrate", { style: options.style ?? "medium" }, callOptions);
11
163
  }
12
164
  //#endregion
165
+ //#region src/system/share.ts
166
+ function share(options, callOptions) {
167
+ const { file, ...rest } = options;
168
+ if (file === void 0) return call("dash.system.share", rest, callOptions);
169
+ const id = typeof file === "string" ? file : file.id;
170
+ return call("dash.system.share", {
171
+ ...rest,
172
+ file: id
173
+ }, callOptions);
174
+ }
175
+ //#endregion
13
176
  //#region src/system/torch.ts
14
177
  function torch(state, callOptions) {
15
178
  return call("dash.system.torch", { state }, callOptions);
@@ -17,6 +180,9 @@ function torch(state, callOptions) {
17
180
  //#endregion
18
181
  //#region src/system/index.ts
19
182
  var system_exports = /* @__PURE__ */ __exportAll({
183
+ copyText: () => copyText,
184
+ delay: () => delay,
185
+ share: () => share,
20
186
  torch: () => torch,
21
187
  vibrate: () => vibrate
22
188
  });
@@ -33,12 +199,31 @@ function alert(options, callOptions) {
33
199
  }, callOptions);
34
200
  }
35
201
  //#endregion
202
+ //#region src/ui/index.ts
203
+ var ui_exports = /* @__PURE__ */ __exportAll({ alert: () => alert });
204
+ //#endregion
205
+ //#region src/tracked.ts
206
+ function tracked(group, track) {
207
+ const copy = {};
208
+ for (const [name, member] of Object.entries(group)) if (typeof member === "function") {
209
+ const start = member;
210
+ copy[name] = (...args) => {
211
+ const request = start(...args);
212
+ track(request);
213
+ return request;
214
+ };
215
+ } else copy[name] = tracked(member, track);
216
+ return copy;
217
+ }
218
+ //#endregion
36
219
  //#region src/index.ts
37
220
  const dash = {
38
- ui: /* @__PURE__ */ __exportAll({ alert: () => alert }),
39
- system: system_exports
221
+ ui: ui_exports,
222
+ system: system_exports,
223
+ network: network_exports,
224
+ file: file_exports
40
225
  };
41
226
  //#endregion
42
- export { HostError, dash };
227
+ export { HostError, dash, tracked };
43
228
 
44
229
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/call.ts","../src/system/haptics.ts","../src/system/torch.ts","../src/system/index.ts","../src/ui/dialogs.ts","../src/ui/index.ts","../src/index.ts"],"sourcesContent":["import type { HostCallOptions, HostRequest } from '@monimesl/dot-core';\nimport { callHost } from '@monimesl/dot-core';\n\nimport type { DashMethod, DashMethods } from './methods';\n\nexport type CallOptions = HostCallOptions;\n\n// A Dash call in flight: await it for the result, or cancel it.\nexport type DashRequest<Result> = HostRequest<Result>;\n\nexport function call<Method extends DashMethod>(\n method: Method,\n params: DashMethods[Method]['params'],\n options: CallOptions = {},\n): DashRequest<DashMethods[Method]['result']> {\n return callHost(method, params, options);\n}\n","import type { CallOptions, DashRequest } from '../call';\nimport { call } from '../call';\n\nexport type VibrationStyle = 'light' | 'medium' | 'heavy' | 'success' | 'warning' | 'error';\n\nexport interface VibrateOptions {\n // Defaults to `medium`.\n style?: VibrationStyle | undefined;\n}\n\nexport interface HapticsMethods {\n 'dash.system.vibrate': { params: VibrateOptions; result: void };\n}\n\n// Plays a short vibration, and resolves once it has.\nexport function vibrate(\n options: VibrateOptions = {},\n callOptions?: CallOptions,\n): DashRequest<void> {\n return call('dash.system.vibrate', { style: options.style ?? 'medium' }, callOptions);\n}\n","import type { CallOptions, DashRequest } from '../call';\nimport { call } from '../call';\n\nexport type TorchState = 'on' | 'off';\n\nexport interface TorchMethods {\n 'dash.system.torch': { params: { state: TorchState }; result: void };\n}\n\n// Turns the torch on or off. Rejects with `unsupported` on a device without one.\nexport function torch(state: TorchState, callOptions?: CallOptions): DashRequest<void> {\n return call('dash.system.torch', { state }, callOptions);\n}\n","import type { HapticsMethods } from './haptics';\nimport type { TorchMethods } from './torch';\n\nexport { vibrate } from './haptics';\nexport { torch } from './torch';\nexport type { VibrateOptions, VibrationStyle } from './haptics';\nexport type { TorchState } from './torch';\n\nexport type SystemMethods = HapticsMethods & TorchMethods;\n","import type { CallOptions, DashRequest } from '../call';\nimport { call } from '../call';\n\nexport interface AlertAction {\n id: string;\n label: string;\n // `cancel` dismisses the alert; `destructive` marks something that cannot be undone.\n role?: 'default' | 'cancel' | 'destructive' | undefined;\n}\n\nexport interface AlertOptions {\n title: string;\n message?: string | undefined;\n // Defaults to a single OK.\n actions?: AlertAction[] | undefined;\n}\n\nexport interface AlertResult {\n // The `id` of the action the user chose.\n action: string;\n}\n\nexport interface DialogMethods {\n 'dash.ui.alert': { params: AlertOptions; result: AlertResult };\n}\n\n// Shows a native alert, and resolves with the action the user chose.\nexport function alert(options: AlertOptions, callOptions?: CallOptions): DashRequest<AlertResult> {\n const actions = options.actions ?? [{ id: 'ok', label: 'OK' }];\n return call('dash.ui.alert', { ...options, actions }, callOptions);\n}\n","import type { DialogMethods } from './dialogs';\n\nexport { alert } from './dialogs';\nexport type { AlertAction, AlertOptions, AlertResult } from './dialogs';\n\nexport type UIMethods = DialogMethods;\n","import * as system from './system';\nimport * as ui from './ui';\n\n// Dash's features for a dot's service, grouped by use: `dash.ui.alert(...)`, `dash.system.torch(...)`.\nexport const dash = { ui, system };\n\nexport { HostError } from '@monimesl/dot-core';\nexport type { HostErrorCode } from '@monimesl/dot-core';\nexport type { CallOptions, DashRequest } from './call';\nexport type { DashMethod, DashMethods } from './methods';\nexport type { SystemMethods, TorchState, VibrateOptions, VibrationStyle } from './system';\nexport type { AlertAction, AlertOptions, AlertResult, UIMethods } from './ui';\n"],"mappings":";;;AAUA,SAAgB,KACd,QACA,QACA,UAAuB,CAAC,GACoB;CAC5C,OAAO,SAAS,QAAQ,QAAQ,OAAO;AACzC;;;ACDA,SAAgB,QACd,UAA0B,CAAC,GAC3B,aACmB;CACnB,OAAO,KAAK,uBAAuB,EAAE,OAAO,QAAQ,SAAS,SAAS,GAAG,WAAW;AACtF;;;ACVA,SAAgB,MAAM,OAAmB,aAA8C;CACrF,OAAO,KAAK,qBAAqB,EAAE,MAAM,GAAG,WAAW;AACzD;;;;;;;;;AEeA,SAAgB,MAAM,SAAuB,aAAqD;CAChG,MAAM,UAAU,QAAQ,WAAW,CAAC;EAAE,IAAI;EAAM,OAAO;CAAK,CAAC;CAC7D,OAAO,KAAK,iBAAiB;EAAE,GAAG;EAAS;CAAQ,GAAG,WAAW;AACnE;;;AE1BA,MAAa,OAAO;CAAE,IAAA,kDAAA;CAAI,QAAA;AAAO"}
1
+ {"version":3,"file":"index.js","names":["HostError"],"sources":["../src/call.ts","../src/file/index.ts","../src/network/http.ts","../src/network/index.ts","../src/system/clipboard.ts","../src/system/delay.ts","../src/system/haptics.ts","../src/system/share.ts","../src/system/torch.ts","../src/system/index.ts","../src/ui/dialogs.ts","../src/ui/index.ts","../src/tracked.ts","../src/index.ts"],"sourcesContent":["import type { HostCallOptions, HostRequest } from '@monimesl/dot-core';\nimport { callHost } from '@monimesl/dot-core';\n\nimport type { DashMethod, DashMethods } from './methods';\n\nexport type CallOptions = HostCallOptions;\n\n// A Dash call in flight: await it for the result, or cancel it.\nexport type DashRequest<Result> = HostRequest<Result>;\n\nexport function call<Method extends DashMethod>(\n method: Method,\n params: DashMethods[Method]['params'],\n options: CallOptions = {},\n): DashRequest<DashMethods[Method]['result']> {\n return callHost(method, params, options);\n}\n","import type { CallOptions, DashRequest } from '../call';\nimport { call } from '../call';\nimport type { DotFile } from '../files';\n\n// A dot's own files, in a folder no other dot sees. Paths are relative to it, such as\n// \"receipts/42.pdf\"; '' is the folder itself.\n\nexport interface FileEntry {\n name: string;\n path: string;\n size: number;\n kind: 'file' | 'folder';\n modifiedAt: number;\n contentType?: string;\n}\n\nexport type FileEncoding = 'text' | 'base64';\n\nexport interface StorageUsage {\n used: number;\n quota: number;\n}\n\nexport interface FileMethods {\n 'dash.file.read': { params: { path: string; as?: FileEncoding }; result: string };\n 'dash.file.write': {\n params: { path: string; data: string; as?: FileEncoding; append?: boolean };\n result: FileEntry;\n };\n 'dash.file.stat': { params: { path: string }; result: FileEntry | null };\n 'dash.file.list': { params: { path: string; recursive?: boolean }; result: FileEntry[] };\n 'dash.file.createFolder': { params: { path: string }; result: FileEntry };\n 'dash.file.move': {\n params: { from: string; to: string; overwrite?: boolean };\n result: FileEntry;\n };\n 'dash.file.copy': {\n params: { from: string; to: string; overwrite?: boolean };\n result: FileEntry;\n };\n 'dash.file.remove': { params: { path: string; recursive?: boolean }; result: void };\n 'dash.file.save': {\n params: { file: string; path: string; overwrite?: boolean };\n result: FileEntry;\n };\n 'dash.file.open': { params: { path: string }; result: DotFile };\n 'dash.file.usage': { params: Record<string, never>; result: StorageUsage };\n}\n\nexport interface ReadOptions {\n as?: FileEncoding;\n}\n\nexport interface WriteOptions {\n as?: FileEncoding;\n append?: boolean;\n}\n\nexport interface ReplaceOptions {\n overwrite?: boolean;\n}\n\n// Up to 5 MB.\nexport function read(\n path: string,\n options: ReadOptions = {},\n callOptions?: CallOptions,\n): DashRequest<string> {\n return call('dash.file.read', { path, ...options }, callOptions);\n}\n\n// Creates any missing folders above the file.\nexport function write(\n path: string,\n data: string,\n options: WriteOptions = {},\n callOptions?: CallOptions,\n): DashRequest<FileEntry> {\n return call('dash.file.write', { path, data, ...options }, callOptions);\n}\n\nexport function stat(path: string, callOptions?: CallOptions): DashRequest<FileEntry | null> {\n return call('dash.file.stat', { path }, callOptions);\n}\n\n// Sorted by path.\nexport function list(\n path = '',\n options: { recursive?: boolean } = {},\n callOptions?: CallOptions,\n): DashRequest<FileEntry[]> {\n return call('dash.file.list', { path, ...options }, callOptions);\n}\n\nexport function createFolder(path: string, callOptions?: CallOptions): DashRequest<FileEntry> {\n return call('dash.file.createFolder', { path }, callOptions);\n}\n\nexport function move(\n from: string,\n to: string,\n options: ReplaceOptions = {},\n callOptions?: CallOptions,\n): DashRequest<FileEntry> {\n return call('dash.file.move', { from, to, ...options }, callOptions);\n}\n\nexport function copy(\n from: string,\n to: string,\n options: ReplaceOptions = {},\n callOptions?: CallOptions,\n): DashRequest<FileEntry> {\n return call('dash.file.copy', { from, to, ...options }, callOptions);\n}\n\n// A folder with anything in it needs `recursive`.\nexport function remove(\n path: string,\n options: { recursive?: boolean } = {},\n callOptions?: CallOptions,\n): DashRequest<void> {\n return call('dash.file.remove', { path, ...options }, callOptions);\n}\n\n// Keeps a temporary file, such as a download.\nexport function save(\n file: DotFile | string,\n path: string,\n options: ReplaceOptions = {},\n callOptions?: CallOptions,\n): DashRequest<FileEntry> {\n const id = typeof file === 'string' ? file : file.id;\n return call('dash.file.save', { file: id, path, ...options }, callOptions);\n}\n\n// A stored file as a DotFile, to show with its `url` or send with `http.upload`.\nexport function open(path: string, callOptions?: CallOptions): DashRequest<DotFile> {\n return call('dash.file.open', { path }, callOptions);\n}\n\nexport function usage(callOptions?: CallOptions): DashRequest<StorageUsage> {\n return call('dash.file.usage', {}, callOptions);\n}\n","import { HostError, createHostRequest } from '@monimesl/dot-core';\n\nimport type { CallOptions, DashRequest } from '../call';\nimport type { DotFile } from '../files';\nimport { call } from '../call';\n\nexport type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';\n\nexport type HttpRequestBody = string | object;\n\nexport interface HttpRequest<Body extends HttpRequestBody = HttpRequestBody> {\n url: string;\n method?: HttpMethod;\n headers?: Record<string, string>;\n body?: Body;\n}\n\nexport interface HttpResponse<Body = string> {\n ok: boolean;\n status: number;\n statusText: string;\n headers: Record<string, string>;\n body: Body;\n}\n\n// A body of any type but string needs `as: 'json'`.\nexport type HttpReadOptions<Body> = [Body] extends [string] ? { as?: 'text' } : { as: 'json' };\n\nexport interface HttpDownloadRequest extends HttpRequest {\n name?: string;\n}\n\nexport type HttpDownloadResponse =\n | (Omit<HttpResponse, 'ok' | 'body'> & { ok: true; file: DotFile })\n | (Omit<HttpResponse, 'ok'> & { ok: false });\n\nexport interface HttpUploadFile {\n field: string;\n file: DotFile | string;\n name?: string;\n}\n\nexport interface HttpUploadRequest {\n url: string;\n // POST by default.\n method?: 'POST' | 'PUT' | 'PATCH';\n headers?: Record<string, string>;\n fields?: Record<string, string>;\n files: HttpUploadFile[];\n}\n\ntype WireRequest<Request extends HttpRequest> = Omit<Request, 'headers' | 'body'> & {\n headers?: Record<string, string> | undefined;\n body?: string | undefined;\n};\n\ntype ReadAs = 'text' | 'json';\n\nexport interface HttpMethods {\n 'dash.network.http.request': { params: WireRequest<HttpRequest>; result: HttpResponse };\n 'dash.network.http.download': {\n params: WireRequest<HttpDownloadRequest>;\n result: HttpDownloadResponse;\n };\n 'dash.network.http.upload': {\n params: Omit<HttpUploadRequest, 'files'> & {\n files: { field: string; file: string; name?: string }[];\n };\n result: HttpResponse;\n };\n}\n\n// Like fetch: resolves with any response, even a 404. An object body goes as JSON.\nexport function request<\n ResponseBody = string,\n RequestBody extends HttpRequestBody = HttpRequestBody,\n>(\n options: HttpRequest<RequestBody> & HttpReadOptions<ResponseBody>,\n callOptions?: CallOptions,\n): DashRequest<HttpResponse<ResponseBody>> {\n const { as, ...request } = options as HttpRequest & { as?: ReadAs };\n const response = call('dash.network.http.request', wireRequest(request, as), callOptions);\n return readBody(response, as);\n}\n\n// Saves a 2xx response's body, up to 100 MB, to a temporary file.\nexport function download(\n options: HttpDownloadRequest,\n callOptions?: CallOptions,\n): DashRequest<HttpDownloadResponse> {\n return call('dash.network.http.download', wireRequest(options), callOptions);\n}\n\n// Sends files the dot has as a multipart form.\nexport function upload<ResponseBody = string>(\n options: HttpUploadRequest & HttpReadOptions<ResponseBody>,\n callOptions?: CallOptions,\n): DashRequest<HttpResponse<ResponseBody>> {\n const { as, ...request } = options as HttpUploadRequest & { as?: ReadAs };\n const files = request.files.map(({ file, ...rest }) => ({\n ...rest,\n file: typeof file === 'string' ? file : file.id,\n }));\n const params = { ...request, files };\n if (as === 'json') {\n params.headers = withDefaultHeader(request.headers, 'Accept', 'application/json');\n }\n const response = call('dash.network.http.upload', params, callOptions);\n return readBody(response, as);\n}\n\nfunction wireRequest<Request extends HttpRequest>(\n request: Request,\n as?: ReadAs,\n): WireRequest<Request> {\n let headers = request.headers;\n let body: string | undefined;\n if (as === 'json') {\n headers = withDefaultHeader(headers, 'Accept', 'application/json');\n }\n if (typeof request.body === 'string') {\n body = request.body;\n } else if (request.body !== undefined) {\n headers = withDefaultHeader(headers, 'Content-Type', 'application/json');\n body = JSON.stringify(request.body);\n }\n return { ...request, headers, body };\n}\n\nfunction withDefaultHeader(\n headers: Record<string, string> | undefined,\n name: string,\n value: string,\n): Record<string, string> {\n const lowerName = name.toLowerCase();\n if (headers && Object.keys(headers).some((existing) => existing.toLowerCase() === lowerName)) {\n return headers;\n }\n return { ...headers, [name]: value };\n}\n\nfunction readBody<Body>(\n response: DashRequest<HttpResponse>,\n as: ReadAs | undefined,\n): DashRequest<HttpResponse<Body>> {\n if (as !== 'json') {\n return response as DashRequest<HttpResponse<Body>>;\n }\n const parsed = response.then((result) => ({ ...result, body: parseJson<Body>(result) }));\n return createHostRequest(parsed, () => response.cancel());\n}\n\nfunction parseJson<Body>({ status, statusText, body }: HttpResponse): Body {\n try {\n return JSON.parse(body) as Body;\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n throw new HostError('failed', `The response (${status} ${statusText}) isn't JSON: ${message}`);\n }\n}\n","import type { HttpMethods } from './http';\nimport * as http from './http';\n\nexport { http };\nexport type {\n HttpDownloadRequest,\n HttpDownloadResponse,\n HttpMethod,\n HttpReadOptions,\n HttpRequest,\n HttpRequestBody,\n HttpResponse,\n HttpUploadFile,\n HttpUploadRequest,\n} from './http';\n\nexport type NetworkMethods = HttpMethods;\n","import type { CallOptions, DashRequest } from '../call';\nimport { call } from '../call';\n\nexport interface ClipboardMethods {\n 'dash.system.copyText': { params: { text: string }; result: void };\n}\n\nexport function copyText(text: string, callOptions?: CallOptions): DashRequest<void> {\n return call('dash.system.copyText', { text }, callOptions);\n}\n","import type { CallOptions, DashRequest } from '../call';\nimport { call } from '../call';\n\nexport interface DelayMethods {\n 'dash.system.delay': { params: { milliseconds: number }; result: void };\n}\n\n// Resolves after `milliseconds`, which the host counts, since the service has no timers.\nexport function delay(milliseconds: number, callOptions?: CallOptions): DashRequest<void> {\n return call('dash.system.delay', { milliseconds }, callOptions);\n}\n","import type { CallOptions, DashRequest } from '../call';\nimport { call } from '../call';\n\nexport type VibrationStyle = 'light' | 'medium' | 'heavy' | 'success' | 'warning' | 'error';\n\nexport interface VibrateOptions {\n // Defaults to `medium`.\n style?: VibrationStyle | undefined;\n}\n\nexport interface HapticsMethods {\n 'dash.system.vibrate': { params: VibrateOptions; result: void };\n}\n\n// Plays a short vibration, and resolves once it has.\nexport function vibrate(\n options: VibrateOptions = {},\n callOptions?: CallOptions,\n): DashRequest<void> {\n return call('dash.system.vibrate', { style: options.style ?? 'medium' }, callOptions);\n}\n","import type { CallOptions, DashRequest } from '../call';\nimport { call } from '../call';\nimport type { DotFile } from '../files';\n\n// Give at least one of `text`, `url` and `file`.\nexport interface ShareOptions {\n // A subject, where the app shared to has one, such as an email.\n title?: string;\n text?: string;\n url?: string;\n file?: DotFile | string;\n}\n\nexport interface ShareMethods {\n 'dash.system.share': {\n params: { title?: string; text?: string; url?: string; file?: string };\n result: void;\n };\n}\n\n// Opens the device's share sheet, and resolves once it shows.\nexport function share(options: ShareOptions, callOptions?: CallOptions): DashRequest<void> {\n const { file, ...rest } = options;\n if (file === undefined) {\n return call('dash.system.share', rest, callOptions);\n }\n const id = typeof file === 'string' ? file : file.id;\n return call('dash.system.share', { ...rest, file: id }, callOptions);\n}\n","import type { CallOptions, DashRequest } from '../call';\nimport { call } from '../call';\n\nexport type TorchState = 'on' | 'off';\n\nexport interface TorchMethods {\n 'dash.system.torch': { params: { state: TorchState }; result: void };\n}\n\n// Turns the torch on or off. Rejects with `unsupported` on a device without one.\nexport function torch(state: TorchState, callOptions?: CallOptions): DashRequest<void> {\n return call('dash.system.torch', { state }, callOptions);\n}\n","import type { ClipboardMethods } from './clipboard';\nimport type { DelayMethods } from './delay';\nimport type { HapticsMethods } from './haptics';\nimport type { ShareMethods } from './share';\nimport type { TorchMethods } from './torch';\n\nexport { copyText } from './clipboard';\nexport { delay } from './delay';\nexport { vibrate } from './haptics';\nexport { share } from './share';\nexport { torch } from './torch';\nexport type { VibrateOptions, VibrationStyle } from './haptics';\nexport type { ShareOptions } from './share';\nexport type { TorchState } from './torch';\n\nexport type SystemMethods = ClipboardMethods &\n DelayMethods &\n HapticsMethods &\n ShareMethods &\n TorchMethods;\n","import type { CallOptions, DashRequest } from '../call';\nimport { call } from '../call';\n\nexport interface AlertAction {\n id: string;\n label: string;\n // `cancel` dismisses the alert; `destructive` marks something that cannot be undone.\n role?: 'default' | 'cancel' | 'destructive' | undefined;\n}\n\nexport interface AlertOptions {\n title: string;\n message?: string | undefined;\n // Defaults to a single OK.\n actions?: AlertAction[] | undefined;\n}\n\nexport interface AlertResult {\n // The `id` of the action the user chose.\n action: string;\n}\n\nexport interface DialogMethods {\n 'dash.ui.alert': { params: AlertOptions; result: AlertResult };\n}\n\n// Shows a native alert, and resolves with the action the user chose.\nexport function alert(options: AlertOptions, callOptions?: CallOptions): DashRequest<AlertResult> {\n const actions = options.actions ?? [{ id: 'ok', label: 'OK' }];\n return call('dash.ui.alert', { ...options, actions }, callOptions);\n}\n","import type { DialogMethods } from './dialogs';\n\nexport { alert } from './dialogs';\nexport type { AlertAction, AlertOptions, AlertResult } from './dialogs';\n\nexport type UIMethods = DialogMethods;\n","import type { DashRequest } from './call';\n\n// A copy of `group`, such as `dash` itself, whose functions pass each request they start to\n// `track`.\nexport function tracked<Group extends object>(\n group: Group,\n track: (request: DashRequest<unknown>) => void,\n): Group {\n const copy: Record<string, unknown> = {};\n for (const [name, member] of Object.entries(group)) {\n if (typeof member === 'function') {\n const start = member as (...args: unknown[]) => DashRequest<unknown>;\n copy[name] = (...args: unknown[]) => {\n const request = start(...args);\n track(request);\n return request;\n };\n } else {\n copy[name] = tracked(member as object, track);\n }\n }\n return copy as Group;\n}\n","import * as file from './file';\nimport * as network from './network';\nimport * as system from './system';\nimport * as ui from './ui';\n\n// Dash's features for a dot's service, grouped by use: `dash.ui.alert(...)`, `dash.system.torch(...)`,\n// `dash.network.http.request(...)`.\nexport const dash = { ui, system, network, file };\n\nexport type Dash = typeof dash;\n\nexport { tracked } from './tracked';\n\nexport { HostError } from '@monimesl/dot-core';\nexport type { HostErrorCode } from '@monimesl/dot-core';\nexport type { CallOptions, DashRequest } from './call';\nexport type { DashMethod, DashMethods } from './methods';\nexport type {\n FileEncoding,\n FileEntry,\n FileMethods,\n ReadOptions,\n ReplaceOptions,\n StorageUsage,\n WriteOptions,\n} from './file';\nexport type { DotFile } from './files';\nexport type {\n HttpDownloadRequest,\n HttpDownloadResponse,\n HttpMethod,\n HttpReadOptions,\n HttpRequest,\n HttpRequestBody,\n HttpResponse,\n HttpUploadFile,\n HttpUploadRequest,\n NetworkMethods,\n} from './network';\nexport type {\n ShareOptions,\n SystemMethods,\n TorchState,\n VibrateOptions,\n VibrationStyle,\n} from './system';\nexport type { AlertAction, AlertOptions, AlertResult, UIMethods } from './ui';\n"],"mappings":";;;AAUA,SAAgB,KACd,QACA,QACA,UAAuB,CAAC,GACoB;CAC5C,OAAO,SAAS,QAAQ,QAAQ,OAAO;AACzC;;;;;;;;;;;;;;;;AC+CA,SAAgB,KACd,MACA,UAAuB,CAAC,GACxB,aACqB;CACrB,OAAO,KAAK,kBAAkB;EAAE;EAAM,GAAG;CAAQ,GAAG,WAAW;AACjE;AAGA,SAAgB,MACd,MACA,MACA,UAAwB,CAAC,GACzB,aACwB;CACxB,OAAO,KAAK,mBAAmB;EAAE;EAAM;EAAM,GAAG;CAAQ,GAAG,WAAW;AACxE;AAEA,SAAgB,KAAK,MAAc,aAA0D;CAC3F,OAAO,KAAK,kBAAkB,EAAE,KAAK,GAAG,WAAW;AACrD;AAGA,SAAgB,KACd,OAAO,IACP,UAAmC,CAAC,GACpC,aAC0B;CAC1B,OAAO,KAAK,kBAAkB;EAAE;EAAM,GAAG;CAAQ,GAAG,WAAW;AACjE;AAE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
1
1
  {
2
2
  "name": "@monimesl/dot-dash",
3
- "version": "0.1.0-alpha.2",
3
+ "version": "0.1.0-alpha.3",
4
4
  "description": "Dash features for dots: native UI, system and more, called from the service",
5
5
  "type": "module",
6
6
  "repository": {
@@ -24,7 +24,7 @@
24
24
  "main": "./dist/index.js",
25
25
  "types": "./dist/index.d.ts",
26
26
  "dependencies": {
27
- "@monimesl/dot-core": "0.1.0-alpha.2"
27
+ "@monimesl/dot-core": "0.1.0-alpha.3"
28
28
  },
29
29
  "devDependencies": {
30
30
  "publint": "^0.3.24",