@drift-beacon/plugin 0.1.0 → 0.2.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 (43) hide show
  1. package/README.md +95 -11
  2. package/dist/cli.js +0 -8
  3. package/dist/dev.js +0 -7
  4. package/dist/errors.js +0 -1
  5. package/dist/index.js +0 -5
  6. package/dist/internal/collection.js +1 -12
  7. package/dist/internal/compatibility.js +0 -11
  8. package/dist/internal/freeze.js +8 -0
  9. package/dist/internal/json-equal.js +0 -1
  10. package/dist/internal/manifest.js +80 -7
  11. package/dist/internal/models.js +0 -43
  12. package/dist/internal/package-layout.js +0 -7
  13. package/dist/internal/peers.js +55 -0
  14. package/dist/internal/protocol.js +0 -1
  15. package/dist/internal/schema.js +156 -0
  16. package/dist/internal/semver.js +47 -0
  17. package/dist/main.d.ts +98 -1
  18. package/dist/main.js +0 -11
  19. package/dist/pack.js +5 -21
  20. package/dist/prepare.js +52 -25
  21. package/dist/types.d.ts +58 -3
  22. package/dist/types.js +0 -9
  23. package/dist/ui.d.ts +11 -2
  24. package/dist/ui.js +157 -25
  25. package/dist/version.d.ts +1 -1
  26. package/dist/version.js +1 -5
  27. package/dist/vite.js +28 -77
  28. package/package.json +11 -4
  29. package/dist/cli.d.ts +0 -2
  30. package/dist/dev.d.ts +0 -38
  31. package/dist/internal/actions.d.ts +0 -35
  32. package/dist/internal/collection.d.ts +0 -15
  33. package/dist/internal/compatibility.d.ts +0 -26
  34. package/dist/internal/json-equal.d.ts +0 -3
  35. package/dist/internal/manifest.d.ts +0 -51
  36. package/dist/internal/models.d.ts +0 -62
  37. package/dist/internal/package-layout.d.ts +0 -21
  38. package/dist/internal/protocol.d.ts +0 -96
  39. package/dist/internal/rows.d.ts +0 -41
  40. package/dist/internal.d.ts +0 -17
  41. package/dist/internal.js +0 -13
  42. package/dist/pack.d.ts +0 -24
  43. package/dist/prepare.d.ts +0 -28
@@ -1,35 +0,0 @@
1
- /**
2
- * Requests an instance's main code sends to the server through its plugin host. The server runs them
3
- * as the instance's user in the instance's workspace.
4
- */
5
- export type PluginAction = {
6
- readonly name: "startSession";
7
- readonly activityId: string;
8
- } | {
9
- readonly name: "endSession";
10
- readonly sessionId: string;
11
- } | {
12
- readonly name: "markPoint";
13
- readonly activityId: string;
14
- } | {
15
- readonly name: "discardSession";
16
- readonly sessionId: string;
17
- } | {
18
- readonly name: "storageSet";
19
- readonly key: string;
20
- readonly value: unknown;
21
- } | {
22
- readonly name: "storageRemove";
23
- readonly key: string;
24
- } | {
25
- readonly name: "mqttSubscribe";
26
- readonly topic: string;
27
- } | {
28
- readonly name: "mqttUnsubscribe";
29
- readonly topic: string;
30
- } | {
31
- readonly name: "mqttPublish";
32
- readonly topic: string;
33
- readonly payload: string;
34
- };
35
- //# sourceMappingURL=actions.d.ts.map
@@ -1,15 +0,0 @@
1
- import type { RowChange } from "./rows.ts";
2
- /**
3
- * A collection of plain rows keyed by id, frozen as they arrive. `replace` applies a full set of rows, keeps the
4
- * object of every unchanged row (so identity only changes when data does) and reports the changes.
5
- */
6
- export declare class Collection<T extends {
7
- readonly id: string;
8
- }> {
9
- private rows;
10
- private cachedList;
11
- list(): readonly T[];
12
- get(id: string): T | undefined;
13
- replace(incoming: readonly T[]): RowChange<T>[];
14
- }
15
- //# sourceMappingURL=collection.d.ts.map
@@ -1,26 +0,0 @@
1
- /**
2
- * API versions this build of Drift Beacon runs: the newest minor of each supported major.
3
- * Before 1.0 only the current version is listed, because every 0.x minor may break plugins.
4
- * From 1.0, the previous major stays listed for at least six months after its successor ships.
5
- */
6
- export declare const SUPPORTED_API_VERSIONS: readonly string[];
7
- export interface ApiVersion {
8
- readonly major: number;
9
- readonly minor: number;
10
- }
11
- /** Parse a `major.minor` API version; null when malformed. */
12
- export declare function parseApiVersion(value: unknown): ApiVersion | null;
13
- export type ApiCompatibility = {
14
- readonly compatible: true;
15
- } | {
16
- readonly compatible: false;
17
- readonly reason: "invalid" | "needs-newer-app" | "needs-plugin-update";
18
- readonly message: string;
19
- };
20
- /**
21
- * Whether a plugin built for `pluginVersion` runs on a build supporting `supported`.
22
- * Before 1.0 the minor must match exactly; from 1.0 the major must match and the plugin's
23
- * minor must not be newer than the host's.
24
- */
25
- export declare function checkApiCompatibility(pluginVersion: unknown, supported?: readonly string[]): ApiCompatibility;
26
- //# sourceMappingURL=compatibility.d.ts.map
@@ -1,3 +0,0 @@
1
- /** Structural equality for JSON-shaped values such as data rows and storage items. */
2
- export declare function jsonEqual(a: unknown, b: unknown): boolean;
3
- //# sourceMappingURL=json-equal.d.ts.map
@@ -1,51 +0,0 @@
1
- interface ConfigurationItemBase {
2
- name: string;
3
- title: string;
4
- description?: string;
5
- required?: boolean;
6
- }
7
- export interface StringConfigurationItem extends ConfigurationItemBase {
8
- type: "string";
9
- default?: string;
10
- placeholder?: string;
11
- }
12
- export interface NumberConfigurationItem extends ConfigurationItemBase {
13
- type: "number";
14
- default?: number;
15
- minimum?: number;
16
- maximum?: number;
17
- }
18
- export interface BooleanConfigurationItem extends ConfigurationItemBase {
19
- type: "boolean";
20
- default?: boolean;
21
- }
22
- export interface DropdownConfigurationItem extends ConfigurationItemBase {
23
- type: "dropdown";
24
- default?: string;
25
- data: ReadonlyArray<{
26
- readonly title: string;
27
- readonly value: string;
28
- }>;
29
- }
30
- /** One setting declared in `manifest.json`; drives the settings form and config validation. */
31
- export type ConfigurationItem = StringConfigurationItem | NumberConfigurationItem | BooleanConfigurationItem | DropdownConfigurationItem;
32
- export interface PluginManifest {
33
- id: string;
34
- name: string;
35
- version: string;
36
- /** Plugin API version (`major.minor`) the plugin was built for. */
37
- apiVersion: string;
38
- description: string;
39
- author: {
40
- name: string;
41
- email?: string;
42
- };
43
- category: "plugin" | "utility" | "ui";
44
- icon: string;
45
- configuration: readonly ConfigurationItem[];
46
- }
47
- export declare const isStableVersion: (value: unknown) => value is string;
48
- /** Throws a readable error when `manifest` is not a valid plugin manifest. Shared by the server and the pack tool. */
49
- export declare function validateManifest(manifest: unknown): asserts manifest is PluginManifest;
50
- export {};
51
- //# sourceMappingURL=manifest.d.ts.map
@@ -1,62 +0,0 @@
1
- import type { ActivitiesApi, Activity, ActivityFilter, CategoriesApi, Category, Change, Session, SessionData, SessionFilter, SessionsApi } from "../types.ts";
2
- import type { Collection } from "./collection.ts";
3
- import type { ActivityRow, CategoryRow, SessionRow, WorkspaceRowChanges } from "./rows.ts";
4
- export interface WorkspaceCollections {
5
- readonly activities: Collection<ActivityRow>;
6
- readonly categories: Collection<CategoryRow>;
7
- readonly sessions: Collection<SessionRow>;
8
- }
9
- /** Session operations. Each resolves with the session's row once the snapshot containing the result has arrived. */
10
- export interface SessionActions {
11
- start(activityId: string): Promise<unknown>;
12
- end(sessionId: string): Promise<unknown>;
13
- mark(activityId: string): Promise<unknown>;
14
- discard(sessionId: string): Promise<unknown>;
15
- }
16
- export interface ModelChanges {
17
- readonly activities: readonly Change<Activity>[];
18
- readonly categories: readonly Change<Category>[];
19
- readonly sessions: readonly Change<Session>[];
20
- }
21
- /** The reads and actions of `ctx.activities`, `ctx.categories` and `ctx.sessions`. Contexts add the events. */
22
- export interface ModelApis {
23
- readonly activities: Omit<ActivitiesApi, "onChange">;
24
- readonly categories: Omit<CategoriesApi, "onChange">;
25
- readonly sessions: Omit<SessionsApi, "onChange">;
26
- }
27
- export declare class WorkspaceModels {
28
- #private;
29
- readonly userId: string;
30
- readonly rows: WorkspaceCollections;
31
- constructor(options: {
32
- readonly userId: string;
33
- readonly rows: WorkspaceCollections;
34
- readonly actions: SessionActions;
35
- });
36
- /** The reads and actions for `ctx`. */
37
- apis(): ModelApis;
38
- activity(id: string): Activity | undefined;
39
- category(id: string): Category | undefined;
40
- session(id: string): Session | undefined;
41
- /** In the app's order: by category (uncategorized last), then `sortOrder`, then name. */
42
- activities(filter?: ActivityFilter): readonly Activity[];
43
- /** By `sortOrder`, then name. */
44
- categories(): readonly Category[];
45
- /** Newest first. */
46
- sessions(filter?: SessionFilter): readonly Session[];
47
- start(activityId: string): Promise<Session>;
48
- end(sessionId: string): Promise<Session>;
49
- mark(activityId: string): Promise<Session>;
50
- discard(sessionId: string): Promise<void>;
51
- /** Turn the row changes of a snapshot into model changes. Call it after the collections were replaced. */
52
- update(changes: WorkspaceRowChanges): ModelChanges;
53
- /**
54
- * The model for a session the app sent outside a snapshot (a live event or an action result):
55
- * the snapshot's model, or, when the row isn't in the snapshot, a removed model holding these values.
56
- */
57
- sessionFrom(row: SessionRow): Session;
58
- activityRow(id: string): ActivityRow;
59
- categoryRow(id: string): CategoryRow;
60
- sessionData(id: string): SessionData;
61
- }
62
- //# sourceMappingURL=models.d.ts.map
@@ -1,21 +0,0 @@
1
- /**
2
- * The plugin package: `manifest.json`, `package.json`, `main/index.js` (plus chunks) and `ui/index.html`
3
- * (plus assets and the manifest icon). Shared by the pack tool and the server. Pure: the web app bundles
4
- * `/internal`, so no `node:` imports.
5
- */
6
- export declare const PACKAGE_LIMITS: {
7
- readonly entries: 2000;
8
- readonly fileBytes: number;
9
- readonly totalBytes: number;
10
- readonly archiveBytes: number;
11
- readonly manifestBytes: number;
12
- };
13
- /** The `package.json` every package gets: main is ESM. */
14
- export declare const PACKAGE_JSON: {
15
- readonly type: "module";
16
- readonly private: true;
17
- };
18
- export declare const REQUIRED_FILES: readonly ["main/index.js", "ui/index.html"];
19
- /** manifest.json, package.json, main/** and ui/** (directories: main, ui and below). `name` has no trailing slash. */
20
- export declare const isPackagePath: (name: string, directory: boolean) => boolean;
21
- //# sourceMappingURL=package-layout.d.ts.map
@@ -1,96 +0,0 @@
1
- /**
2
- * Messages between a plugin UI (iframe) and the web app hosting it, over `postMessage`.
3
- *
4
- * The UI client ships inside every published UI bundle, so this protocol is frozen into
5
- * them: change it only additively within an API version. The UI opens with `hello`; nothing
6
- * else flows until the host answers `welcome` or `reject`.
7
- */
8
- import type { PluginErrorCode, PluginInfo, UserInfo, WorkspaceInfo } from "../types.ts";
9
- import type { WorkspaceRows } from "./rows.ts";
10
- /** Marks our messages so both sides ignore unrelated `postMessage` traffic (dev tools, HMR). */
11
- export declare const UI_CHANNEL = "drift-beacon-plugin";
12
- /** Workspace data sent to a UI, as rows. */
13
- export type UiData = WorkspaceRows;
14
- export type UiRequest = {
15
- readonly method: "sessions.start";
16
- readonly params: {
17
- readonly activityId: string;
18
- };
19
- } | {
20
- readonly method: "sessions.end";
21
- readonly params: {
22
- readonly sessionId: string;
23
- };
24
- } | {
25
- readonly method: "sessions.mark";
26
- readonly params: {
27
- readonly activityId: string;
28
- };
29
- } | {
30
- readonly method: "sessions.discard";
31
- readonly params: {
32
- readonly sessionId: string;
33
- };
34
- } | {
35
- readonly method: "storage.set";
36
- readonly params: {
37
- readonly key: string;
38
- readonly value: unknown;
39
- };
40
- } | {
41
- readonly method: "storage.remove";
42
- readonly params: {
43
- readonly key: string;
44
- };
45
- };
46
- export type UiToHostMessage = {
47
- readonly channel: typeof UI_CHANNEL;
48
- readonly type: "hello";
49
- readonly apiVersion: string;
50
- } | ({
51
- readonly channel: typeof UI_CHANNEL;
52
- readonly type: "request";
53
- readonly id: string;
54
- } & UiRequest);
55
- export interface UiError {
56
- readonly code: PluginErrorCode;
57
- readonly message: string;
58
- }
59
- export type HostToUiMessage = {
60
- readonly channel: typeof UI_CHANNEL;
61
- readonly type: "welcome";
62
- readonly apiVersion: string;
63
- readonly plugin: PluginInfo;
64
- readonly user: UserInfo;
65
- readonly workspace: WorkspaceInfo;
66
- readonly config: Readonly<Record<string, unknown>>;
67
- readonly data: UiData;
68
- readonly storage: Readonly<Record<string, unknown>>;
69
- } | {
70
- readonly channel: typeof UI_CHANNEL;
71
- readonly type: "reject";
72
- readonly reason: string;
73
- }
74
- /** The app restarted its side of the connection; the UI answers with `hello` and gets a new `welcome`. */
75
- | {
76
- readonly channel: typeof UI_CHANNEL;
77
- readonly type: "reconnect";
78
- } | {
79
- /** Replaces whichever parts are present. */
80
- readonly channel: typeof UI_CHANNEL;
81
- readonly type: "state";
82
- readonly config?: Readonly<Record<string, unknown>>;
83
- readonly data?: UiData;
84
- readonly storage?: Readonly<Record<string, unknown>>;
85
- } | {
86
- readonly channel: typeof UI_CHANNEL;
87
- readonly type: "response";
88
- readonly id: string;
89
- readonly result?: unknown;
90
- readonly error?: UiError;
91
- };
92
- export declare function isUiMessage(value: unknown): value is {
93
- channel: typeof UI_CHANNEL;
94
- type: string;
95
- };
96
- //# sourceMappingURL=protocol.d.ts.map
@@ -1,41 +0,0 @@
1
- /**
2
- * Workspace data as it travels from the app to plugins: to plugin hosts over IPC and to plugin
3
- * UIs over `postMessage`. Plugins never see rows; the model layer (`models.ts`) wraps them.
4
- */
5
- import type { ActivityData, CategoryData } from "../types.ts";
6
- export type ActivityRow = ActivityData;
7
- export type CategoryRow = CategoryData;
8
- export interface SessionRow {
9
- readonly id: string;
10
- readonly activityId: string;
11
- readonly type: "span" | "point";
12
- readonly status: "live" | "completed";
13
- readonly memberIds: readonly string[];
14
- /** ISO timestamp: when a span started, or when a point was marked. */
15
- readonly startedAt: string;
16
- /** ISO timestamp when a span ended; null while live and for points. */
17
- readonly endedAt: string | null;
18
- }
19
- export interface WorkspaceRows {
20
- readonly activities: readonly ActivityRow[];
21
- readonly categories: readonly CategoryRow[];
22
- readonly sessions: readonly SessionRow[];
23
- }
24
- /** One change to a collection of rows. */
25
- export type RowChange<T> = {
26
- readonly type: "added";
27
- readonly item: T;
28
- } | {
29
- readonly type: "updated";
30
- readonly item: T;
31
- readonly previous: T;
32
- } | {
33
- readonly type: "removed";
34
- readonly item: T;
35
- };
36
- export interface WorkspaceRowChanges {
37
- readonly activities: readonly RowChange<ActivityRow>[];
38
- readonly categories: readonly RowChange<CategoryRow>[];
39
- readonly sessions: readonly RowChange<SessionRow>[];
40
- }
41
- //# sourceMappingURL=rows.d.ts.map
@@ -1,17 +0,0 @@
1
- /**
2
- * Platform-only entry used by the plugin host, the web app and the server. Not part of the plugin API.
3
- * Public entries never import this file; SDK modules may import `internal/*` directly. Publishing drops
4
- * only its export key.
5
- */
6
- export * from "./dev.ts";
7
- export type { PluginAction } from "./internal/actions.ts";
8
- export { Collection } from "./internal/collection.ts";
9
- export { type ApiCompatibility, type ApiVersion, checkApiCompatibility, parseApiVersion, SUPPORTED_API_VERSIONS, } from "./internal/compatibility.ts";
10
- export { jsonEqual } from "./internal/json-equal.ts";
11
- export { type BooleanConfigurationItem, type ConfigurationItem, type DropdownConfigurationItem, isStableVersion, type NumberConfigurationItem, type PluginManifest, type StringConfigurationItem, validateManifest, } from "./internal/manifest.ts";
12
- export { type ModelApis, type ModelChanges, type SessionActions, type WorkspaceCollections, WorkspaceModels, } from "./internal/models.ts";
13
- export { isPackagePath, PACKAGE_JSON, PACKAGE_LIMITS, REQUIRED_FILES } from "./internal/package-layout.ts";
14
- export * from "./internal/protocol.ts";
15
- export type { ActivityRow, CategoryRow, RowChange, SessionRow, WorkspaceRowChanges, WorkspaceRows, } from "./internal/rows.ts";
16
- export type { PluginErrorCode } from "./types.ts";
17
- //# sourceMappingURL=internal.d.ts.map
package/dist/internal.js DELETED
@@ -1,13 +0,0 @@
1
- /**
2
- * Platform-only entry used by the plugin host, the web app and the server. Not part of the plugin API.
3
- * Public entries never import this file; SDK modules may import `internal/*` directly. Publishing drops
4
- * only its export key.
5
- */
6
- export * from "./dev.js";
7
- export { Collection } from "./internal/collection.js";
8
- export { checkApiCompatibility, parseApiVersion, SUPPORTED_API_VERSIONS, } from "./internal/compatibility.js";
9
- export { jsonEqual } from "./internal/json-equal.js";
10
- export { isStableVersion, validateManifest, } from "./internal/manifest.js";
11
- export { WorkspaceModels, } from "./internal/models.js";
12
- export { isPackagePath, PACKAGE_JSON, PACKAGE_LIMITS, REQUIRED_FILES } from "./internal/package-layout.js";
13
- export * from "./internal/protocol.js";
package/dist/pack.d.ts DELETED
@@ -1,24 +0,0 @@
1
- export interface PackResult {
2
- readonly id: string;
3
- readonly version: string;
4
- readonly tag: string;
5
- readonly asset: string;
6
- readonly archivePath: string;
7
- }
8
- /**
9
- * Zip the package in `dir` into `<outDir>/<id>.zip`: its manifest, a generated `package.json`, and `main/**`
10
- * and `ui/**`. Anything else in `dir` (the dev marker, its `package.json`) is left out. Never runs plugin code.
11
- */
12
- export declare function packDirectory(dir: string, outDir: string): Promise<PackResult>;
13
- export interface PackOptions {
14
- /** Where the zip goes. Default `<root>/releases`. */
15
- readonly out?: string;
16
- }
17
- /**
18
- * Build a release of the plugin package at `root`: prepare, typecheck main and UI with the package's own
19
- * TypeScript, `vite build` into a fresh temp folder with the package's own Vite, then `packDirectory`. The
20
- * package's `dist/` is never read or written. Everything printed meanwhile goes to stderr, so a caller's
21
- * stdout carries only the result.
22
- */
23
- export declare function pack(root: string, options?: PackOptions): Promise<PackResult>;
24
- //# sourceMappingURL=pack.d.ts.map
package/dist/prepare.d.ts DELETED
@@ -1,28 +0,0 @@
1
- import { type PluginManifest } from "./internal/manifest.ts";
2
- export interface PrepareOptions {
3
- /**
4
- * Throw on manifest problems (dev, build and pack). When false (`dbplugin prepare`, run on install), warn
5
- * and leave `.drift-beacon/` as it was, so a manifest typo never fails `pnpm install`.
6
- */
7
- readonly strict: boolean;
8
- }
9
- /** A package's `manifest.json`: parsed and checked, with its bytes. */
10
- export interface LoadedManifest {
11
- readonly manifest: PluginManifest;
12
- readonly bytes: Buffer;
13
- }
14
- /**
15
- * Generate `<root>/.drift-beacon/` from the manifest, and return the manifest (`loadManifest`). Files are
16
- * rewritten only when their content changes.
17
- */
18
- export declare function prepare(root: string, options: {
19
- readonly strict: true;
20
- }): LoadedManifest;
21
- export declare function prepare(root: string, options: PrepareOptions): LoadedManifest | null;
22
- /**
23
- * `<root>/manifest.json`, the one read of a manifest in the SDK (dev, build, prepare and pack): a regular
24
- * file within the package limit, valid, and for an `apiVersion` this SDK runs (the server's check). The
25
- * error names the file.
26
- */
27
- export declare function loadManifest(root: string): LoadedManifest;
28
- //# sourceMappingURL=prepare.d.ts.map