@rollrook-ai/sdk 0.0.0-stage → 0.1.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/agents.d.ts +9 -0
- package/dist/agents.d.ts.map +1 -0
- package/dist/agents.js +13 -0
- package/dist/agents.js.map +1 -0
- package/dist/assets.d.ts +35 -0
- package/dist/assets.d.ts.map +1 -0
- package/dist/assets.js +66 -0
- package/dist/assets.js.map +1 -0
- package/dist/assistant.d.ts +76 -0
- package/dist/assistant.d.ts.map +1 -0
- package/dist/assistant.js +161 -0
- package/dist/assistant.js.map +1 -0
- package/dist/audio.d.ts +55 -0
- package/dist/audio.d.ts.map +1 -0
- package/dist/audio.js +82 -0
- package/dist/audio.js.map +1 -0
- package/dist/bridge.d.ts +51 -0
- package/dist/bridge.d.ts.map +1 -0
- package/dist/bridge.js +78 -0
- package/dist/bridge.js.map +1 -0
- package/dist/calendar.d.ts +33 -0
- package/dist/calendar.d.ts.map +1 -0
- package/dist/calendar.js +63 -0
- package/dist/calendar.js.map +1 -0
- package/dist/context.d.ts +19 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +25 -0
- package/dist/context.js.map +1 -0
- package/dist/errors.d.ts +74 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +111 -0
- package/dist/errors.js.map +1 -0
- package/dist/events.d.ts +36 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +81 -0
- package/dist/events.js.map +1 -0
- package/dist/files.d.ts +29 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +43 -0
- package/dist/files.js.map +1 -0
- package/dist/index.d.ts +84 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -0
- package/dist/mock/index.d.ts +4 -0
- package/dist/mock/index.d.ts.map +1 -0
- package/dist/mock/index.js +3 -0
- package/dist/mock/index.js.map +1 -0
- package/dist/mock/mock-host.d.ts +255 -0
- package/dist/mock/mock-host.d.ts.map +1 -0
- package/dist/mock/mock-host.js +1274 -0
- package/dist/mock/mock-host.js.map +1 -0
- package/dist/mock/samples.d.ts +56 -0
- package/dist/mock/samples.d.ts.map +1 -0
- package/dist/mock/samples.js +283 -0
- package/dist/mock/samples.js.map +1 -0
- package/dist/mock/toolbar.d.ts +95 -0
- package/dist/mock/toolbar.d.ts.map +1 -0
- package/dist/mock/toolbar.js +279 -0
- package/dist/mock/toolbar.js.map +1 -0
- package/dist/net.d.ts +13 -0
- package/dist/net.d.ts.map +1 -0
- package/dist/net.js +26 -0
- package/dist/net.js.map +1 -0
- package/dist/plugin.d.ts +11 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +13 -0
- package/dist/plugin.js.map +1 -0
- package/dist/raven.d.ts +51 -0
- package/dist/raven.d.ts.map +1 -0
- package/dist/raven.js +100 -0
- package/dist/raven.js.map +1 -0
- package/dist/segment-display.d.ts +93 -0
- package/dist/segment-display.d.ts.map +1 -0
- package/dist/segment-display.js +324 -0
- package/dist/segment-display.js.map +1 -0
- package/dist/settings.d.ts +19 -0
- package/dist/settings.d.ts.map +1 -0
- package/dist/settings.js +27 -0
- package/dist/settings.js.map +1 -0
- package/dist/storage.d.ts +28 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +54 -0
- package/dist/storage.js.map +1 -0
- package/dist/system.d.ts +19 -0
- package/dist/system.d.ts.map +1 -0
- package/dist/system.js +24 -0
- package/dist/system.js.map +1 -0
- package/dist/theme.d.ts +51 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +85 -0
- package/dist/theme.js.map +1 -0
- package/dist/types.d.ts +278 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/ui.d.ts +57 -0
- package/dist/ui.d.ts.map +1 -0
- package/dist/ui.js +78 -0
- package/dist/ui.js.map +1 -0
- package/dist/usage.d.ts +14 -0
- package/dist/usage.d.ts.map +1 -0
- package/dist/usage.js +19 -0
- package/dist/usage.js.map +1 -0
- package/dist/video.d.ts +11 -0
- package/dist/video.d.ts.map +1 -0
- package/dist/video.js +17 -0
- package/dist/video.js.map +1 -0
- package/dist/wire.d.ts +214 -0
- package/dist/wire.d.ts.map +1 -0
- package/dist/wire.js +538 -0
- package/dist/wire.js.map +1 -0
- package/package.json +39 -4
- package/src/agents.ts +14 -0
- package/src/assets.ts +80 -0
- package/src/assistant.ts +185 -0
- package/src/audio.ts +90 -0
- package/src/bridge.ts +96 -0
- package/src/calendar.ts +68 -0
- package/src/context.ts +28 -0
- package/src/errors.ts +131 -0
- package/src/events.ts +90 -0
- package/src/files.ts +47 -0
- package/src/index.ts +152 -0
- package/src/mock/index.ts +3 -0
- package/src/mock/mock-host.ts +1408 -0
- package/src/mock/samples.ts +300 -0
- package/src/mock/toolbar.ts +321 -0
- package/src/net.ts +27 -0
- package/src/plugin.ts +14 -0
- package/src/raven.ts +116 -0
- package/src/segment-display.ts +377 -0
- package/src/settings.ts +29 -0
- package/src/storage.ts +59 -0
- package/src/system.ts +26 -0
- package/src/theme.ts +97 -0
- package/src/types.ts +327 -0
- package/src/ui.ts +88 -0
- package/src/usage.ts +21 -0
- package/src/video.ts +17 -0
- package/src/wire.ts +608 -0
- package/theme.css +407 -0
- package/README.md +0 -3
package/dist/bridge.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { BridgeUnavailableError, RollRookError } from "./errors.js";
|
|
2
|
+
import { Wire } from "./wire.js";
|
|
3
|
+
/**
|
|
4
|
+
* The one channel between a plugin page and RollRook. Every module of the SDK
|
|
5
|
+
* calls through it; plugins rarely need it directly.
|
|
6
|
+
*/
|
|
7
|
+
export class Bridge {
|
|
8
|
+
/** The name of RollRook's script message handler. */
|
|
9
|
+
static HANDLER_NAME = "rollrook";
|
|
10
|
+
/** The property a mock host sets on its handler, so the SDK can tell it from RollRook. */
|
|
11
|
+
static MOCK_MARKER = "isMock";
|
|
12
|
+
/** The bridge protocol this SDK speaks. */
|
|
13
|
+
static PROTOCOL = 1;
|
|
14
|
+
/**
|
|
15
|
+
* Find RollRook's message handler on the page.
|
|
16
|
+
*
|
|
17
|
+
* @returns the handler, or undefined outside RollRook and without a mock host
|
|
18
|
+
*/
|
|
19
|
+
static handler() {
|
|
20
|
+
const webkit = Reflect.get(globalThis, "webkit");
|
|
21
|
+
if (!Wire.is_record(webkit)) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
const map_handlers = webkit["messageHandlers"];
|
|
25
|
+
if (!Wire.is_record(map_handlers)) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
const handler = map_handlers[Bridge.HANDLER_NAME];
|
|
29
|
+
return Bridge.is_handler(handler) ? handler : undefined;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Whether the page can reach a host, RollRook's or a mock's.
|
|
33
|
+
*
|
|
34
|
+
* @returns true when a handler is installed
|
|
35
|
+
*/
|
|
36
|
+
static is_available() {
|
|
37
|
+
return Bridge.handler() !== undefined;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Whether the page runs inside RollRook itself, not a mock host.
|
|
41
|
+
*
|
|
42
|
+
* @returns true when RollRook's own handler is installed
|
|
43
|
+
*/
|
|
44
|
+
static is_native() {
|
|
45
|
+
const handler = Bridge.handler();
|
|
46
|
+
return handler !== undefined && Reflect.get(handler, Bridge.MOCK_MARKER) !== true;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Call a bridge method.
|
|
50
|
+
*
|
|
51
|
+
* @param method - the method's name, e.g. `storage.get`
|
|
52
|
+
* @param params - the method's parameters
|
|
53
|
+
* @returns the method's result, unchecked
|
|
54
|
+
* @throws RollRookError, of the subclass matching the host's error code
|
|
55
|
+
*/
|
|
56
|
+
static async call(method, params = {}) {
|
|
57
|
+
const handler = Bridge.handler();
|
|
58
|
+
if (handler === undefined) {
|
|
59
|
+
throw new BridgeUnavailableError(method);
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
return await handler.postMessage({
|
|
63
|
+
method,
|
|
64
|
+
params,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
if (err instanceof RollRookError) {
|
|
69
|
+
throw err;
|
|
70
|
+
}
|
|
71
|
+
throw RollRookError.from_rejection(err, method);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
static is_handler(value) {
|
|
75
|
+
return Wire.is_record(value) && typeof value["postMessage"] === "function";
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEpE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAajC;;;GAGG;AACH,MAAM,OAAO,MAAM;IACf,qDAAqD;IACrD,MAAM,CAAU,YAAY,GAAG,UAAU,CAAC;IAE1C,0FAA0F;IAC1F,MAAM,CAAU,WAAW,GAAG,QAAQ,CAAC;IAEvC,2CAA2C;IAC3C,MAAM,CAAU,QAAQ,GAAG,CAAC,CAAC;IAE7B;;;;OAIG;IACH,MAAM,CAAC,OAAO;QACV,MAAM,MAAM,GAAY,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAC1D,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1B,OAAO,SAAS,CAAC;QACrB,CAAC;QACD,MAAM,YAAY,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;QAC/C,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE,CAAC;YAChC,OAAO,SAAS,CAAC;QACrB,CAAC;QACD,MAAM,OAAO,GAAG,YAAY,CAAC,MA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} from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* The plugin's items in RollRook's calendar. The manifest declares
|
|
4
|
+
* `contributes.calendar`; each publish replaces every item the plugin showed
|
|
5
|
+
* before. A click on an item arrives as `calendar.open` in the plugin's first
|
|
6
|
+
* dock view (else its first sidebar view, else its background view), which
|
|
7
|
+
* RollRook shows first; a drag arrives as `calendar.move` in the background
|
|
8
|
+
* view (else every loaded view), after which the plugin updates its own data
|
|
9
|
+
* and publishes again.
|
|
10
|
+
*/
|
|
11
|
+
export declare class CalendarApi {
|
|
12
|
+
/** The most items RollRook takes from one plugin. */
|
|
13
|
+
static readonly ITEM_LIMIT = 2000;
|
|
14
|
+
/** The longest an item's id may be. */
|
|
15
|
+
static readonly ID_MAX_LENGTH = 200;
|
|
16
|
+
/** An item's color: `#rrggbb`. */
|
|
17
|
+
static readonly COLOR_PATTERN: RegExp;
|
|
18
|
+
/**
|
|
19
|
+
* Replace the plugin's calendar items.
|
|
20
|
+
*
|
|
21
|
+
* @param list_items - every item to show, times in ISO 8601
|
|
22
|
+
* @throws InvalidParamsError when there are more than 2000 items, two share an id, or one has a bad id, a color not `#rrggbb`, or neither a start and an end nor a due
|
|
23
|
+
*/
|
|
24
|
+
publish(list_items: readonly CalendarItem[]): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Whether an item has the times RollRook needs to place it.
|
|
27
|
+
*
|
|
28
|
+
* @param item - a calendar item
|
|
29
|
+
* @returns true for a start and an end (a block), or a due (a deadline)
|
|
30
|
+
*/
|
|
31
|
+
static is_placed(item: CalendarItem): boolean;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=calendar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar.d.ts","sourceRoot":"","sources":["../src/calendar.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG/C;;;;;;;;GAQG;AACH,qBAAa,WAAW;IACpB,qDAAqD;IACrD,MAAM,CAAC,QAAQ,CAAC,UAAU,QAAQ;IAElC,uCAAuC;IACvC,MAAM,CAAC,QAAQ,CAAC,aAAa,OAAO;IAEpC,kCAAkC;IAClC,MAAM,CAAC,QAAQ,CAAC,aAAa,SAAuB;IAEpD;;;;;OAKG;IACG,OAAO,CAAC,UAAU,EAAE,SAAS,YAAY,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAuBhE;IAED;;;;;OAKG;IACH,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAK5C;CACJ"}
|
package/dist/calendar.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Bridge } from "./bridge.js";
|
|
2
|
+
import { InvalidParamsError } from "./errors.js";
|
|
3
|
+
import { Wire } from "./wire.js";
|
|
4
|
+
/**
|
|
5
|
+
* The plugin's items in RollRook's calendar. The manifest declares
|
|
6
|
+
* `contributes.calendar`; each publish replaces every item the plugin showed
|
|
7
|
+
* before. A click on an item arrives as `calendar.open` in the plugin's first
|
|
8
|
+
* dock view (else its first sidebar view, else its background view), which
|
|
9
|
+
* RollRook shows first; a drag arrives as `calendar.move` in the background
|
|
10
|
+
* view (else every loaded view), after which the plugin updates its own data
|
|
11
|
+
* and publishes again.
|
|
12
|
+
*/
|
|
13
|
+
export class CalendarApi {
|
|
14
|
+
/** The most items RollRook takes from one plugin. */
|
|
15
|
+
static ITEM_LIMIT = 2000;
|
|
16
|
+
/** The longest an item's id may be. */
|
|
17
|
+
static ID_MAX_LENGTH = 200;
|
|
18
|
+
/** An item's color: `#rrggbb`. */
|
|
19
|
+
static COLOR_PATTERN = /^#[0-9a-fA-F]{6}$/;
|
|
20
|
+
/**
|
|
21
|
+
* Replace the plugin's calendar items.
|
|
22
|
+
*
|
|
23
|
+
* @param list_items - every item to show, times in ISO 8601
|
|
24
|
+
* @throws InvalidParamsError when there are more than 2000 items, two share an id, or one has a bad id, a color not `#rrggbb`, or neither a start and an end nor a due
|
|
25
|
+
*/
|
|
26
|
+
async publish(list_items) {
|
|
27
|
+
if (list_items.length > CalendarApi.ITEM_LIMIT) {
|
|
28
|
+
throw new InvalidParamsError(`at most ${CalendarApi.ITEM_LIMIT} calendar items`, "calendar.publish");
|
|
29
|
+
}
|
|
30
|
+
const set_ids = new Set();
|
|
31
|
+
for (const item of list_items) {
|
|
32
|
+
if (item.id === "" || item.id.length > CalendarApi.ID_MAX_LENGTH) {
|
|
33
|
+
throw new InvalidParamsError(`a calendar item's id is 1 to ${CalendarApi.ID_MAX_LENGTH} characters`, "calendar.publish");
|
|
34
|
+
}
|
|
35
|
+
if (item.color !== undefined && !CalendarApi.COLOR_PATTERN.test(item.color)) {
|
|
36
|
+
throw new InvalidParamsError(`the calendar item ${item.id}'s color is not #rrggbb`, "calendar.publish");
|
|
37
|
+
}
|
|
38
|
+
if (set_ids.has(item.id)) {
|
|
39
|
+
throw new InvalidParamsError(`two calendar items have the id ${item.id}`, "calendar.publish");
|
|
40
|
+
}
|
|
41
|
+
set_ids.add(item.id);
|
|
42
|
+
if (!CalendarApi.is_placed(item)) {
|
|
43
|
+
throw new InvalidParamsError(`the calendar item ${item.id} needs a start and an end, or a due`, "calendar.publish");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
await Bridge.call("calendar.publish", {
|
|
47
|
+
items: list_items.map((item) => Wire.calendar_item_to_wire(item)),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Whether an item has the times RollRook needs to place it.
|
|
52
|
+
*
|
|
53
|
+
* @param item - a calendar item
|
|
54
|
+
* @returns true for a start and an end (a block), or a due (a deadline)
|
|
55
|
+
*/
|
|
56
|
+
static is_placed(item) {
|
|
57
|
+
if ((item.start === undefined) !== (item.end === undefined)) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
return item.start !== undefined || item.due !== undefined;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=calendar.js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YAC5G,CAAC;YACD,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;gBACvB,MAAM,IAAI,kBAAkB,CAAC,kCAAkC,IAAI,CAAC,EAAE,EAAE,EAAE,kBAAkB,CAAC,CAAC;YAClG,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACrB,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC/B,MAAM,IAAI,kBAAkB,CAAC,qBAAqB,IAAI,CAAC,EAAE,qCAAqC,EAAE,kBAAkB,CAAC,CAAC;YACxH,CAAC;QACL,CAAC;QACD,MAAM,MAAM,CAAC,IAAI,CAAC,kBAAkB,EAAE;YAClC,KAAK,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,IAAkB,EAAE,EAAE,CAAC,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC;SAClF,CAAC,CAAC;IACP,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,SAAS,CAAC,IAAkB;QAC/B,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,SAAS,CAAC,EAAE,CAAC;YAC1D,OAAO,KAAK,CAAC;QACjB,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,GAAG,KAAK,SAAS,CAAC;IAC9D,CAAC;CACJ"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { PluginContext } from "./types.js";
|
|
2
|
+
/** The plugin's own identity and the app it runs in. */
|
|
3
|
+
export declare class ContextApi {
|
|
4
|
+
/** The global RollRook sets before the page's scripts run. */
|
|
5
|
+
static readonly GLOBAL_NAME = "__rollrook";
|
|
6
|
+
/**
|
|
7
|
+
* Ask RollRook for the current context.
|
|
8
|
+
*
|
|
9
|
+
* @returns the plugin's id and version, the app's version, the protocol and the theme
|
|
10
|
+
*/
|
|
11
|
+
get(): Promise<PluginContext>;
|
|
12
|
+
/**
|
|
13
|
+
* Read the context RollRook set on the page at load, without a call.
|
|
14
|
+
*
|
|
15
|
+
* @returns the context, or undefined outside RollRook
|
|
16
|
+
*/
|
|
17
|
+
current(): PluginContext | undefined;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,wDAAwD;AACxD,qBAAa,UAAU;IACnB,8DAA8D;IAC9D,MAAM,CAAC,QAAQ,CAAC,WAAW,gBAAgB;IAE3C;;;;OAIG;IACG,GAAG,IAAI,OAAO,CAAC,aAAa,CAAC,CAElC;IAED;;;;OAIG;IACH,OAAO,IAAI,aAAa,GAAG,SAAS,CAGnC;CACJ"}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Bridge } from "./bridge.js";
|
|
2
|
+
import { Wire } from "./wire.js";
|
|
3
|
+
/** The plugin's own identity and the app it runs in. */
|
|
4
|
+
export class ContextApi {
|
|
5
|
+
/** The global RollRook sets before the page's scripts run. */
|
|
6
|
+
static GLOBAL_NAME = "__rollrook";
|
|
7
|
+
/**
|
|
8
|
+
* Ask RollRook for the current context.
|
|
9
|
+
*
|
|
10
|
+
* @returns the plugin's id and version, the app's version, the protocol and the theme
|
|
11
|
+
*/
|
|
12
|
+
async get() {
|
|
13
|
+
return Wire.context(await Bridge.call("context.get"));
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Read the context RollRook set on the page at load, without a call.
|
|
17
|
+
*
|
|
18
|
+
* @returns the context, or undefined outside RollRook
|
|
19
|
+
*/
|
|
20
|
+
current() {
|
|
21
|
+
const raw = Reflect.get(globalThis, ContextApi.GLOBAL_NAME);
|
|
22
|
+
return raw === undefined ? undefined : Wire.context(raw);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,wDAAwD;AACxD,MAAM,OAAO,UAAU;IACnB,8DAA8D;IAC9D,MAAM,CAAU,WAAW,GAAG,YAAY,CAAC;IAE3C;;;;OAIG;IACH,KAAK,CAAC,GAAG;QACL,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED;;;;OAIG;IACH,OAAO;QACH,MAAM,GAAG,GAAY,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;QACrE,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC7D,CAAC;CACJ"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The kind of failure a bridge call reports, taken from the code that begins
|
|
3
|
+
* the host's error message. `unavailable` is the SDK's own: the page is not
|
|
4
|
+
* running inside RollRook and no mock host is installed.
|
|
5
|
+
*/
|
|
6
|
+
export type ErrorCode = "permission" | "invalid" | "unknown" | "failed" | "unavailable";
|
|
7
|
+
/**
|
|
8
|
+
* A failed call to RollRook. Every error the SDK throws is one of its
|
|
9
|
+
* subclasses, so a `catch` can narrow on the class or on `code`.
|
|
10
|
+
*/
|
|
11
|
+
export declare class RollRookError extends Error {
|
|
12
|
+
/** The failure's code, as the host reported it. */
|
|
13
|
+
readonly code: ErrorCode;
|
|
14
|
+
/** The bridge method that failed, or undefined when the failure is not a call's. */
|
|
15
|
+
readonly method: string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* @param code - the failure's code
|
|
18
|
+
* @param message - the host's message, without the code
|
|
19
|
+
* @param method - the bridge method that failed
|
|
20
|
+
*/
|
|
21
|
+
constructor(code: ErrorCode, message: string, method?: string);
|
|
22
|
+
/**
|
|
23
|
+
* Turn whatever a rejected bridge call delivered into the matching error.
|
|
24
|
+
* The host rejects with a message that begins with `permission:`,
|
|
25
|
+
* `invalid:`, `unknown:` or `failed:`; anything else counts as `failed`.
|
|
26
|
+
*
|
|
27
|
+
* @param reason - the rejection value
|
|
28
|
+
* @param method - the method that was called
|
|
29
|
+
* @returns the typed error
|
|
30
|
+
*/
|
|
31
|
+
static from_rejection(reason: unknown, method: string): RollRookError;
|
|
32
|
+
private static readonly CODE_PATTERN;
|
|
33
|
+
private static text_of;
|
|
34
|
+
}
|
|
35
|
+
/** The plugin's manifest does not hold the permission the method needs. */
|
|
36
|
+
export declare class PermissionError extends RollRookError {
|
|
37
|
+
/**
|
|
38
|
+
* @param message - the host's message
|
|
39
|
+
* @param method - the method that was refused
|
|
40
|
+
*/
|
|
41
|
+
constructor(message: string, method?: string);
|
|
42
|
+
}
|
|
43
|
+
/** The parameters were wrong: a missing field, a bad path, a key too long. */
|
|
44
|
+
export declare class InvalidParamsError extends RollRookError {
|
|
45
|
+
/**
|
|
46
|
+
* @param message - the host's message
|
|
47
|
+
* @param method - the method that was called
|
|
48
|
+
*/
|
|
49
|
+
constructor(message: string, method?: string);
|
|
50
|
+
}
|
|
51
|
+
/** The host does not know the method, usually because it is older than the SDK. */
|
|
52
|
+
export declare class UnknownMethodError extends RollRookError {
|
|
53
|
+
/**
|
|
54
|
+
* @param message - the host's message
|
|
55
|
+
* @param method - the method that was called
|
|
56
|
+
*/
|
|
57
|
+
constructor(message: string, method?: string);
|
|
58
|
+
}
|
|
59
|
+
/** The call was valid but could not be done, or the host's reply was malformed. */
|
|
60
|
+
export declare class FailedError extends RollRookError {
|
|
61
|
+
/**
|
|
62
|
+
* @param message - the host's message
|
|
63
|
+
* @param method - the method that was called
|
|
64
|
+
*/
|
|
65
|
+
constructor(message: string, method?: string);
|
|
66
|
+
}
|
|
67
|
+
/** The page runs outside RollRook and no mock host is installed. */
|
|
68
|
+
export declare class BridgeUnavailableError extends RollRookError {
|
|
69
|
+
/**
|
|
70
|
+
* @param method - the method that could not be called
|
|
71
|
+
*/
|
|
72
|
+
constructor(method: string);
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,YAAY,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,aAAa,CAAC;AAExF;;;GAGG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACpC,mDAAmD;IACnD,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAEzB,oFAAoF;IACpF,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAEpC;;;;OAIG;IACH,YAAY,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAK5D;IAED;;;;;;;;OAQG;IACH,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,CAepE;IAED,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAA2D;IAE/F,OAAO,CAAC,MAAM,CAAC,OAAO;CASzB;AAED,2EAA2E;AAC3E,qBAAa,eAAgB,SAAQ,aAAa;IAC9C;;;OAGG;IACH,YAAY,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAG3C;CACJ;AAED,8EAA8E;AAC9E,qBAAa,kBAAmB,SAAQ,aAAa;IACjD;;;OAGG;IACH,YAAY,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAG3C;CACJ;AAED,mFAAmF;AACnF,qBAAa,kBAAmB,SAAQ,aAAa;IACjD;;;OAGG;IACH,YAAY,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAG3C;CACJ;AAED,mFAAmF;AACnF,qBAAa,WAAY,SAAQ,aAAa;IAC1C;;;OAGG;IACH,YAAY,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAG3C;CACJ;AAED,oEAAoE;AACpE,qBAAa,sBAAuB,SAAQ,aAAa;IACrD;;OAEG;IACH,YAAY,MAAM,EAAE,MAAM,EAOzB;CACJ"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A failed call to RollRook. Every error the SDK throws is one of its
|
|
3
|
+
* subclasses, so a `catch` can narrow on the class or on `code`.
|
|
4
|
+
*/
|
|
5
|
+
export class RollRookError extends Error {
|
|
6
|
+
/** The failure's code, as the host reported it. */
|
|
7
|
+
code;
|
|
8
|
+
/** The bridge method that failed, or undefined when the failure is not a call's. */
|
|
9
|
+
method;
|
|
10
|
+
/**
|
|
11
|
+
* @param code - the failure's code
|
|
12
|
+
* @param message - the host's message, without the code
|
|
13
|
+
* @param method - the bridge method that failed
|
|
14
|
+
*/
|
|
15
|
+
constructor(code, message, method) {
|
|
16
|
+
super(message);
|
|
17
|
+
this.name = "RollRookError";
|
|
18
|
+
this.code = code;
|
|
19
|
+
this.method = method;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Turn whatever a rejected bridge call delivered into the matching error.
|
|
23
|
+
* The host rejects with a message that begins with `permission:`,
|
|
24
|
+
* `invalid:`, `unknown:` or `failed:`; anything else counts as `failed`.
|
|
25
|
+
*
|
|
26
|
+
* @param reason - the rejection value
|
|
27
|
+
* @param method - the method that was called
|
|
28
|
+
* @returns the typed error
|
|
29
|
+
*/
|
|
30
|
+
static from_rejection(reason, method) {
|
|
31
|
+
const text = RollRookError.text_of(reason);
|
|
32
|
+
const match = RollRookError.CODE_PATTERN.exec(text);
|
|
33
|
+
const code = match?.[1];
|
|
34
|
+
const detail = (match?.[2] ?? text).trim();
|
|
35
|
+
switch (code) {
|
|
36
|
+
case "permission":
|
|
37
|
+
return new PermissionError(detail, method);
|
|
38
|
+
case "invalid":
|
|
39
|
+
return new InvalidParamsError(detail, method);
|
|
40
|
+
case "unknown":
|
|
41
|
+
return new UnknownMethodError(detail, method);
|
|
42
|
+
default:
|
|
43
|
+
return new FailedError(detail, method);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
static CODE_PATTERN = /^\s*(permission|invalid|unknown|failed):\s*([\s\S]*)$/;
|
|
47
|
+
static text_of(reason) {
|
|
48
|
+
if (reason instanceof Error) {
|
|
49
|
+
return reason.message;
|
|
50
|
+
}
|
|
51
|
+
if (typeof reason === "string") {
|
|
52
|
+
return reason;
|
|
53
|
+
}
|
|
54
|
+
return String(reason);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** The plugin's manifest does not hold the permission the method needs. */
|
|
58
|
+
export class PermissionError extends RollRookError {
|
|
59
|
+
/**
|
|
60
|
+
* @param message - the host's message
|
|
61
|
+
* @param method - the method that was refused
|
|
62
|
+
*/
|
|
63
|
+
constructor(message, method) {
|
|
64
|
+
super("permission", message, method);
|
|
65
|
+
this.name = "PermissionError";
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** The parameters were wrong: a missing field, a bad path, a key too long. */
|
|
69
|
+
export class InvalidParamsError extends RollRookError {
|
|
70
|
+
/**
|
|
71
|
+
* @param message - the host's message
|
|
72
|
+
* @param method - the method that was called
|
|
73
|
+
*/
|
|
74
|
+
constructor(message, method) {
|
|
75
|
+
super("invalid", message, method);
|
|
76
|
+
this.name = "InvalidParamsError";
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** The host does not know the method, usually because it is older than the SDK. */
|
|
80
|
+
export class UnknownMethodError extends RollRookError {
|
|
81
|
+
/**
|
|
82
|
+
* @param message - the host's message
|
|
83
|
+
* @param method - the method that was called
|
|
84
|
+
*/
|
|
85
|
+
constructor(message, method) {
|
|
86
|
+
super("unknown", message, method);
|
|
87
|
+
this.name = "UnknownMethodError";
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/** The call was valid but could not be done, or the host's reply was malformed. */
|
|
91
|
+
export class FailedError extends RollRookError {
|
|
92
|
+
/**
|
|
93
|
+
* @param message - the host's message
|
|
94
|
+
* @param method - the method that was called
|
|
95
|
+
*/
|
|
96
|
+
constructor(message, method) {
|
|
97
|
+
super("failed", message, method);
|
|
98
|
+
this.name = "FailedError";
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** The page runs outside RollRook and no mock host is installed. */
|
|
102
|
+
export class BridgeUnavailableError extends RollRookError {
|
|
103
|
+
/**
|
|
104
|
+
* @param method - the method that could not be called
|
|
105
|
+
*/
|
|
106
|
+
constructor(method) {
|
|
107
|
+
super("unavailable", "not running inside RollRook; install the mock host from @rollrook-ai/sdk/mock to develop in a browser", method);
|
|
108
|
+
this.name = "BridgeUnavailableError";
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAOA;;;GAGG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IACpC,mDAAmD;IAC1C,IAAI,CAAY;IAEzB,oFAAoF;IAC3E,MAAM,CAAqB;IAEpC;;;;OAIG;IACH,YAAY,IAAe,EAAE,OAAe,EAAE,MAAe;QACzD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC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;QACxC,KAAK,CAAC,YAAY,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QACrC,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAClC,CAAC;CACJ;AAED,8EAA8E;AAC9E,MAAM,OAAO,kBAAmB,SAAQ,aAAa;IACjD;;;OAGG;IACH,YAAY,OAAe,EAAE,MAAe;QACxC,KAAK,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAClC,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACrC,CAAC;CACJ;AAED,mFAAmF;AACnF,MAAM,OAAO,kBAAmB,SAAQ,aAAa;IACjD;;;OAGG;IACH,YAAY,OAAe,EAAE,MAAe;QACxC,KAAK,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAClC,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACrC,CAAC;CACJ;AAED,mFAAmF;AACnF,MAAM,OAAO,WAAY,SAAQ,aAAa;IAC1C;;;OAGG;IACH,YAAY,OAAe,EAAE,MAAe;QACxC,KAAK,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QACjC,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC9B,CAAC;CACJ;AAED,oEAAoE;AACpE,MAAM,OAAO,sBAAuB,SAAQ,aAAa;IACrD;;OAEG;IACH,YAAY,MAAc;QACtB,KAAK,CACD,aAAa,EACb,uGAAuG,EACvG,MAAM,CACT,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACzC,CAAC;CACJ"}
|
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { EventMap, EventName } from "./types.js";
|
|
2
|
+
/** A function that removes the handler it was returned for. */
|
|
3
|
+
export type Unsubscribe = () => void;
|
|
4
|
+
/**
|
|
5
|
+
* The events RollRook delivers by calling `window.__rollrookEvent(name, payload)`.
|
|
6
|
+
* The SDK installs the receiver as it loads, since RollRook sends events only
|
|
7
|
+
* after the page has loaded.
|
|
8
|
+
*/
|
|
9
|
+
export declare class Events {
|
|
10
|
+
/** The global function RollRook calls to deliver an event. */
|
|
11
|
+
static readonly RECEIVER_NAME = "__rollrookEvent";
|
|
12
|
+
private static readonly map_parsers;
|
|
13
|
+
private readonly map_listeners;
|
|
14
|
+
private readonly receiver;
|
|
15
|
+
/**
|
|
16
|
+
* Subscribe to an event.
|
|
17
|
+
*
|
|
18
|
+
* @param name - the event's name
|
|
19
|
+
* @param handler - called with each delivery's payload
|
|
20
|
+
* @returns a function that unsubscribes the handler
|
|
21
|
+
*/
|
|
22
|
+
on<K extends EventName>(name: K, handler: (payload: EventMap[K]) => void): Unsubscribe;
|
|
23
|
+
/**
|
|
24
|
+
* Deliver an event to its handlers, as RollRook does through
|
|
25
|
+
* `window.__rollrookEvent`. Events the SDK does not know are ignored. A
|
|
26
|
+
* handler that throws does not stop the others; its error is reported as
|
|
27
|
+
* uncaught.
|
|
28
|
+
*
|
|
29
|
+
* @param name - the event's name
|
|
30
|
+
* @param payload - the payload in wire form
|
|
31
|
+
*/
|
|
32
|
+
dispatch(name: string, payload: unknown): void;
|
|
33
|
+
/** Define `window.__rollrookEvent` so RollRook's deliveries reach this object. */
|
|
34
|
+
install(): void;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGtD,+DAA+D;AAC/D,MAAM,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC;AAErC;;;;GAIG;AACH,qBAAa,MAAM;IACf,8DAA8D;IAC9D,MAAM,CAAC,QAAQ,CAAC,aAAa,qBAAqB;IAElD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAWjC;IAEF,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAkD;IAEhF,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAIvB;IAEF;;;;;;OAMG;IACH,EAAE,CAAC,CAAC,SAAS,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,WAAW,CAarF;IAED;;;;;;;;OAQG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAc7C;IAED,kFAAkF;IAClF,OAAO,IAAI,IAAI,CAId;CACJ"}
|
package/dist/events.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Wire } from "./wire.js";
|
|
2
|
+
/**
|
|
3
|
+
* The events RollRook delivers by calling `window.__rollrookEvent(name, payload)`.
|
|
4
|
+
* The SDK installs the receiver as it loads, since RollRook sends events only
|
|
5
|
+
* after the page has loaded.
|
|
6
|
+
*/
|
|
7
|
+
export class Events {
|
|
8
|
+
/** The global function RollRook calls to deliver an event. */
|
|
9
|
+
static RECEIVER_NAME = "__rollrookEvent";
|
|
10
|
+
static map_parsers = {
|
|
11
|
+
"theme": (raw) => Wire.theme(raw),
|
|
12
|
+
"visibility": (raw) => Wire.visibility(raw),
|
|
13
|
+
"settings.changed": (raw) => Wire.setting_values(raw),
|
|
14
|
+
"message": (raw) => Wire.plugin_message(raw),
|
|
15
|
+
"raven.turn": (raw) => Wire.raven_turn(raw),
|
|
16
|
+
"usage.changed": (raw) => Wire.usage_snapshot(raw),
|
|
17
|
+
"audio.tracks": (raw) => Wire.audio_tracks(raw),
|
|
18
|
+
"audio.levels": (raw) => Wire.audio_levels(raw),
|
|
19
|
+
"calendar.open": (raw) => Wire.calendar_open(raw),
|
|
20
|
+
"calendar.move": (raw) => Wire.calendar_move(raw),
|
|
21
|
+
};
|
|
22
|
+
map_listeners = new Map();
|
|
23
|
+
receiver = (name, payload) => {
|
|
24
|
+
if (typeof name === "string") {
|
|
25
|
+
this.dispatch(name, payload);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Subscribe to an event.
|
|
30
|
+
*
|
|
31
|
+
* @param name - the event's name
|
|
32
|
+
* @param handler - called with each delivery's payload
|
|
33
|
+
* @returns a function that unsubscribes the handler
|
|
34
|
+
*/
|
|
35
|
+
on(name, handler) {
|
|
36
|
+
this.install();
|
|
37
|
+
const parse = Events.map_parsers[name];
|
|
38
|
+
const listener = (raw) => handler(parse(raw));
|
|
39
|
+
let set_listeners = this.map_listeners.get(name);
|
|
40
|
+
if (set_listeners === undefined) {
|
|
41
|
+
set_listeners = new Set();
|
|
42
|
+
this.map_listeners.set(name, set_listeners);
|
|
43
|
+
}
|
|
44
|
+
set_listeners.add(listener);
|
|
45
|
+
return () => {
|
|
46
|
+
this.map_listeners.get(name)?.delete(listener);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Deliver an event to its handlers, as RollRook does through
|
|
51
|
+
* `window.__rollrookEvent`. Events the SDK does not know are ignored. A
|
|
52
|
+
* handler that throws does not stop the others; its error is reported as
|
|
53
|
+
* uncaught.
|
|
54
|
+
*
|
|
55
|
+
* @param name - the event's name
|
|
56
|
+
* @param payload - the payload in wire form
|
|
57
|
+
*/
|
|
58
|
+
dispatch(name, payload) {
|
|
59
|
+
const set_listeners = this.map_listeners.get(name);
|
|
60
|
+
if (set_listeners === undefined) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
for (const listener of [...set_listeners]) {
|
|
64
|
+
try {
|
|
65
|
+
listener(payload);
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
queueMicrotask(() => {
|
|
69
|
+
throw err;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/** Define `window.__rollrookEvent` so RollRook's deliveries reach this object. */
|
|
75
|
+
install() {
|
|
76
|
+
if (Reflect.get(globalThis, Events.RECEIVER_NAME) !== this.receiver) {
|
|
77
|
+
Reflect.set(globalThis, Events.RECEIVER_NAME, this.receiver);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAKjC;;;;GAIG;AACH,MAAM,OAAO,MAAM;IACf,8DAA8D;IAC9D,MAAM,CAAU,aAAa,GAAG,iBAAiB,CAAC;IAE1C,MAAM,CAAU,WAAW,GAAwD;QACvF,OAAO,EAAE,CAAC,GAAY,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;QAC1C,YAAY,EAAE,CAAC,GAAY,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;QACpD,kBAAkB,EAAE,CAAC,GAAY,EAAE,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC;QAC9D,SAAS,EAAE,CAAC,GAAY,EAAE,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC;QACrD,YAAY,EAAE,CAAC,GAAY,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;QACpD,eAAe,EAAE,CAAC,GAAY,EAAE,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC;QAC3D,cAAc,EAAE,CAAC,GAAY,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC;QACxD,cAAc,EAAE,CAAC,GAAY,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC;QACxD,eAAe,EAAE,CAAC,GAAY,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC;QAC1D,eAA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AC;QACD,KAAK,MAAM,QAAQ,IAAI,CAAC,GAAG,aAAa,CAAC,EAAE,CAAC;YACxC,IAAI,CAAC;gBACD,QAAQ,CAAC,OAAO,CAAC,CAAC;YACtB,CAAC;YAAC,OAAO,GAAY,EAAE,CAAC;gBACpB,cAAc,CAAC,GAAG,EAAE;oBAChB,MAAM,GAAG,CAAC;gBACd,CAAC,CAAC,CAAC;YACP,CAAC;QACL,CAAC;IACL,CAAC;IAED,kFAAkF;IAClF,OAAO;QACH,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,aAAa,CAAC,KAAK,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClE,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QACjE,CAAC;IACL,CAAC;CACJ"}
|
package/dist/files.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { FileEntry } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Text files in the plugin's own data folder. Paths are relative to that
|
|
4
|
+
* folder; `..`, absolute paths and links out of it are refused.
|
|
5
|
+
*/
|
|
6
|
+
export declare class FilesApi {
|
|
7
|
+
/**
|
|
8
|
+
* @param path - the file's path
|
|
9
|
+
* @returns the file's text
|
|
10
|
+
*/
|
|
11
|
+
read(path: string): Promise<string>;
|
|
12
|
+
/**
|
|
13
|
+
* Write a file, replacing what it held.
|
|
14
|
+
*
|
|
15
|
+
* @param path - the file's path
|
|
16
|
+
* @param text - the file's new text
|
|
17
|
+
*/
|
|
18
|
+
write(path: string, text: string): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* @param path - the folder's path, `""` for the data folder itself
|
|
21
|
+
* @returns the folder's entries
|
|
22
|
+
*/
|
|
23
|
+
list(path?: string): Promise<FileEntry[]>;
|
|
24
|
+
/**
|
|
25
|
+
* @param path - the path to delete
|
|
26
|
+
*/
|
|
27
|
+
delete(path: string): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG5C;;;GAGG;AACH,qBAAa,QAAQ;IACjB;;;OAGG;IACG,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAGxC;IAED;;;;;OAKG;IACG,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAKrD;IAED;;;OAGG;IACG,IAAI,CAAC,IAAI,SAAK,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAG1C;IAED;;OAEG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAExC;CACJ"}
|
package/dist/files.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Bridge } from "./bridge.js";
|
|
2
|
+
import { Wire } from "./wire.js";
|
|
3
|
+
/**
|
|
4
|
+
* Text files in the plugin's own data folder. Paths are relative to that
|
|
5
|
+
* folder; `..`, absolute paths and links out of it are refused.
|
|
6
|
+
*/
|
|
7
|
+
export class FilesApi {
|
|
8
|
+
/**
|
|
9
|
+
* @param path - the file's path
|
|
10
|
+
* @returns the file's text
|
|
11
|
+
*/
|
|
12
|
+
async read(path) {
|
|
13
|
+
const record = Wire.record(await Bridge.call("files.read", { path }), "files.read reply");
|
|
14
|
+
return Wire.string(record, "text", "files.read reply");
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Write a file, replacing what it held.
|
|
18
|
+
*
|
|
19
|
+
* @param path - the file's path
|
|
20
|
+
* @param text - the file's new text
|
|
21
|
+
*/
|
|
22
|
+
async write(path, text) {
|
|
23
|
+
await Bridge.call("files.write", {
|
|
24
|
+
path,
|
|
25
|
+
text,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @param path - the folder's path, `""` for the data folder itself
|
|
30
|
+
* @returns the folder's entries
|
|
31
|
+
*/
|
|
32
|
+
async list(path = "") {
|
|
33
|
+
const record = Wire.record(await Bridge.call("files.list", { path }), "files.list reply");
|
|
34
|
+
return Wire.array(record, "entries", "files.list reply").map((entry) => Wire.file_entry(entry));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @param path - the path to delete
|
|
38
|
+
*/
|
|
39
|
+
async delete(path) {
|
|
40
|
+
await Bridge.call("files.delete", { path });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.js","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC;;;GAGG;AACH,MAAM,OAAO,QAAQ;IACjB;;;OAGG;IACH,KAAK,CAAC,IAAI,CAAC,IAAY;QACnB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,kBAAkB,CAAC,CAAC;QAC1F,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAC3D,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,KAAK,CAAC,IAAY,EAAE,IAAY;QAClC,MAAM,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE;YAC7B,IAAI;YACJ,IAAI;SACP,CAAC,CAAC;IACP,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,EAAE;QAChB,MAAM,M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