@oimdb/cli 0.0.0-stage → 1.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.
@@ -0,0 +1,168 @@
1
+ import { WebSocket } from 'ws';
2
+
3
+ type TOIMDevBridgeOptions = {
4
+ wsPort: number;
5
+ host: string;
6
+ allowedOrigins: ReadonlySet<string>;
7
+ /** Opens every line this bridge writes to stderr. */
8
+ logPrefix: string;
9
+ /** The command the operator would re-run with a different port. */
10
+ portInUseHint: string;
11
+ requestTimeoutMessage: string;
12
+ };
13
+
14
+ type TOIMDevConnectedBrowser = {
15
+ ws: WebSocket;
16
+ url: string;
17
+ title: string;
18
+ };
19
+
20
+ declare class OIMDevBridge {
21
+ private readonly bridgeOptions;
22
+ private readonly messageReader;
23
+ private readonly pending;
24
+ private webSocketServer;
25
+ private devConnectedBrowser;
26
+ constructor(bridgeOptions: TOIMDevBridgeOptions);
27
+ get connectedBrowser(): TOIMDevConnectedBrowser | null;
28
+ /**
29
+ * May a page use this bridge?
30
+ *
31
+ * From this machine, or named by whoever started the server. An ABSENT
32
+ * origin is a non-browser client — a CLI, a test — and is allowed; the
33
+ * literal `'null'` is not, because a sandboxed iframe on any site can send
34
+ * exactly that.
35
+ */
36
+ isOriginAllowed(origin: string | undefined): boolean;
37
+ request(action: string): Promise<unknown>;
38
+ start(): void;
39
+ private readFrame;
40
+ /**
41
+ * Newest tab wins — a reload is the ordinary reason for a second `hello` —
42
+ * but the tab it displaces is CLOSED and the swap is printed. Overwriting the
43
+ * field in place leaves the displaced socket open for ever and lets a second
44
+ * connection take the bridge over in silence.
45
+ */
46
+ private adoptBrowser;
47
+ private write;
48
+ }
49
+
50
+ type TOIMDevUIServerOptions = {
51
+ wsPort?: number;
52
+ uiPort?: number;
53
+ uiDir: string;
54
+ open?: boolean;
55
+ /**
56
+ * The interface both ports bind to. LOOPBACK BY DEFAULT: a tool that hands
57
+ * out the application's entire data model has no business being reachable
58
+ * from the café Wi-Fi, and `listen` without a host binds every interface.
59
+ *
60
+ * Set it — `'0.0.0.0'` — when the browser genuinely runs somewhere else: a
61
+ * container, a VM, a phone. That is an opt-in to everyone who can route
62
+ * there reading the model.
63
+ */
64
+ host?: string;
65
+ /**
66
+ * Page origins allowed onto the bridge and allowed to read `/api/inspect`,
67
+ * on top of the loopback origins allowed by default.
68
+ *
69
+ * Exact origins (`'http://app.test:3000'`). Never `'*'`: with that on every
70
+ * response, any page in any tab the developer has open can read every entity
71
+ * of every registered collection.
72
+ */
73
+ allowedOrigins?: readonly string[];
74
+ };
75
+
76
+ declare class OIMDevUIServer {
77
+ private readonly uiPort;
78
+ private readonly shouldOpen;
79
+ private readonly host;
80
+ private readonly allowedOrigins;
81
+ private readonly devUIAssetCatalog;
82
+ private readonly bridge;
83
+ constructor(options: TOIMDevUIServerOptions);
84
+ /**
85
+ * While bound to loopback, answer only what was addressed to a loopback
86
+ * name.
87
+ *
88
+ * Without this, a page on any site can point a hostname it controls at
89
+ * 127.0.0.1 and become same-origin with this server. The `Host` header is
90
+ * the part of that a browser cannot forge. Binding elsewhere is an explicit
91
+ * decision, so the check stands down there.
92
+ */
93
+ private isRequestAddressedHere;
94
+ private requestBrowser;
95
+ private setupHTTP;
96
+ private openURL;
97
+ start(): void;
98
+ }
99
+
100
+ interface IOIMDevStateSource {
101
+ readInspect(): Promise<unknown>;
102
+ readDump(): Promise<string>;
103
+ }
104
+
105
+ declare class OIMDevStateReader {
106
+ private readonly devStateSource;
107
+ constructor(devStateSource: IOIMDevStateSource);
108
+ readInspectText(): Promise<string>;
109
+ readDumpText(): Promise<string>;
110
+ readCollectionText(name: string): Promise<string>;
111
+ readComputedText(name: string): Promise<string>;
112
+ private namesOf;
113
+ }
114
+
115
+ interface IOIMDevRegistry {
116
+ inspect(): unknown;
117
+ dumpString(): string;
118
+ }
119
+
120
+ declare class OIMDevRegistryStateSource implements IOIMDevStateSource {
121
+ private readonly devRegistry;
122
+ constructor(devRegistry: IOIMDevRegistry);
123
+ readInspect(): Promise<unknown>;
124
+ readDump(): Promise<string>;
125
+ }
126
+
127
+ declare class OIMDevModuleStateSource implements IOIMDevStateSource {
128
+ private readonly modelModulePath;
129
+ private devRegistry;
130
+ constructor(modelModulePath: string);
131
+ readInspect(): Promise<unknown>;
132
+ readDump(): Promise<string>;
133
+ loadDevRegistry(): Promise<IOIMDevRegistry>;
134
+ private importDevRegistry;
135
+ }
136
+
137
+ declare class OIMDevBridgeStateSource implements IOIMDevStateSource {
138
+ private readonly devBridge;
139
+ private readonly wsPort;
140
+ constructor(devBridge: OIMDevBridge, wsPort: number);
141
+ readInspect(): Promise<unknown>;
142
+ readDump(): Promise<string>;
143
+ private requestBrowser;
144
+ }
145
+
146
+ declare class OIMDevHttpStateSource implements IOIMDevStateSource {
147
+ private readonly serverUrl;
148
+ constructor(serverUrl: string);
149
+ readInspect(): Promise<unknown>;
150
+ readDump(): Promise<string>;
151
+ private readConnected;
152
+ }
153
+
154
+ declare class OIMDevCdpStateSource implements IOIMDevStateSource {
155
+ private readonly cdpUrl;
156
+ constructor(cdpUrl: string);
157
+ readInspect(): Promise<unknown>;
158
+ readDump(): Promise<string>;
159
+ private evaluate;
160
+ private evaluateOnTab;
161
+ }
162
+
163
+ type TOIMDevInspectSnapshot = {
164
+ collections: Record<string, unknown>;
165
+ computeds: Record<string, unknown>;
166
+ };
167
+
168
+ export { type IOIMDevRegistry, type IOIMDevStateSource, OIMDevBridge, OIMDevBridgeStateSource, OIMDevCdpStateSource, OIMDevHttpStateSource, OIMDevModuleStateSource, OIMDevRegistryStateSource, OIMDevStateReader, OIMDevUIServer, type TOIMDevBridgeOptions, type TOIMDevInspectSnapshot, type TOIMDevUIServerOptions };
@@ -0,0 +1,168 @@
1
+ import { WebSocket } from 'ws';
2
+
3
+ type TOIMDevBridgeOptions = {
4
+ wsPort: number;
5
+ host: string;
6
+ allowedOrigins: ReadonlySet<string>;
7
+ /** Opens every line this bridge writes to stderr. */
8
+ logPrefix: string;
9
+ /** The command the operator would re-run with a different port. */
10
+ portInUseHint: string;
11
+ requestTimeoutMessage: string;
12
+ };
13
+
14
+ type TOIMDevConnectedBrowser = {
15
+ ws: WebSocket;
16
+ url: string;
17
+ title: string;
18
+ };
19
+
20
+ declare class OIMDevBridge {
21
+ private readonly bridgeOptions;
22
+ private readonly messageReader;
23
+ private readonly pending;
24
+ private webSocketServer;
25
+ private devConnectedBrowser;
26
+ constructor(bridgeOptions: TOIMDevBridgeOptions);
27
+ get connectedBrowser(): TOIMDevConnectedBrowser | null;
28
+ /**
29
+ * May a page use this bridge?
30
+ *
31
+ * From this machine, or named by whoever started the server. An ABSENT
32
+ * origin is a non-browser client — a CLI, a test — and is allowed; the
33
+ * literal `'null'` is not, because a sandboxed iframe on any site can send
34
+ * exactly that.
35
+ */
36
+ isOriginAllowed(origin: string | undefined): boolean;
37
+ request(action: string): Promise<unknown>;
38
+ start(): void;
39
+ private readFrame;
40
+ /**
41
+ * Newest tab wins — a reload is the ordinary reason for a second `hello` —
42
+ * but the tab it displaces is CLOSED and the swap is printed. Overwriting the
43
+ * field in place leaves the displaced socket open for ever and lets a second
44
+ * connection take the bridge over in silence.
45
+ */
46
+ private adoptBrowser;
47
+ private write;
48
+ }
49
+
50
+ type TOIMDevUIServerOptions = {
51
+ wsPort?: number;
52
+ uiPort?: number;
53
+ uiDir: string;
54
+ open?: boolean;
55
+ /**
56
+ * The interface both ports bind to. LOOPBACK BY DEFAULT: a tool that hands
57
+ * out the application's entire data model has no business being reachable
58
+ * from the café Wi-Fi, and `listen` without a host binds every interface.
59
+ *
60
+ * Set it — `'0.0.0.0'` — when the browser genuinely runs somewhere else: a
61
+ * container, a VM, a phone. That is an opt-in to everyone who can route
62
+ * there reading the model.
63
+ */
64
+ host?: string;
65
+ /**
66
+ * Page origins allowed onto the bridge and allowed to read `/api/inspect`,
67
+ * on top of the loopback origins allowed by default.
68
+ *
69
+ * Exact origins (`'http://app.test:3000'`). Never `'*'`: with that on every
70
+ * response, any page in any tab the developer has open can read every entity
71
+ * of every registered collection.
72
+ */
73
+ allowedOrigins?: readonly string[];
74
+ };
75
+
76
+ declare class OIMDevUIServer {
77
+ private readonly uiPort;
78
+ private readonly shouldOpen;
79
+ private readonly host;
80
+ private readonly allowedOrigins;
81
+ private readonly devUIAssetCatalog;
82
+ private readonly bridge;
83
+ constructor(options: TOIMDevUIServerOptions);
84
+ /**
85
+ * While bound to loopback, answer only what was addressed to a loopback
86
+ * name.
87
+ *
88
+ * Without this, a page on any site can point a hostname it controls at
89
+ * 127.0.0.1 and become same-origin with this server. The `Host` header is
90
+ * the part of that a browser cannot forge. Binding elsewhere is an explicit
91
+ * decision, so the check stands down there.
92
+ */
93
+ private isRequestAddressedHere;
94
+ private requestBrowser;
95
+ private setupHTTP;
96
+ private openURL;
97
+ start(): void;
98
+ }
99
+
100
+ interface IOIMDevStateSource {
101
+ readInspect(): Promise<unknown>;
102
+ readDump(): Promise<string>;
103
+ }
104
+
105
+ declare class OIMDevStateReader {
106
+ private readonly devStateSource;
107
+ constructor(devStateSource: IOIMDevStateSource);
108
+ readInspectText(): Promise<string>;
109
+ readDumpText(): Promise<string>;
110
+ readCollectionText(name: string): Promise<string>;
111
+ readComputedText(name: string): Promise<string>;
112
+ private namesOf;
113
+ }
114
+
115
+ interface IOIMDevRegistry {
116
+ inspect(): unknown;
117
+ dumpString(): string;
118
+ }
119
+
120
+ declare class OIMDevRegistryStateSource implements IOIMDevStateSource {
121
+ private readonly devRegistry;
122
+ constructor(devRegistry: IOIMDevRegistry);
123
+ readInspect(): Promise<unknown>;
124
+ readDump(): Promise<string>;
125
+ }
126
+
127
+ declare class OIMDevModuleStateSource implements IOIMDevStateSource {
128
+ private readonly modelModulePath;
129
+ private devRegistry;
130
+ constructor(modelModulePath: string);
131
+ readInspect(): Promise<unknown>;
132
+ readDump(): Promise<string>;
133
+ loadDevRegistry(): Promise<IOIMDevRegistry>;
134
+ private importDevRegistry;
135
+ }
136
+
137
+ declare class OIMDevBridgeStateSource implements IOIMDevStateSource {
138
+ private readonly devBridge;
139
+ private readonly wsPort;
140
+ constructor(devBridge: OIMDevBridge, wsPort: number);
141
+ readInspect(): Promise<unknown>;
142
+ readDump(): Promise<string>;
143
+ private requestBrowser;
144
+ }
145
+
146
+ declare class OIMDevHttpStateSource implements IOIMDevStateSource {
147
+ private readonly serverUrl;
148
+ constructor(serverUrl: string);
149
+ readInspect(): Promise<unknown>;
150
+ readDump(): Promise<string>;
151
+ private readConnected;
152
+ }
153
+
154
+ declare class OIMDevCdpStateSource implements IOIMDevStateSource {
155
+ private readonly cdpUrl;
156
+ constructor(cdpUrl: string);
157
+ readInspect(): Promise<unknown>;
158
+ readDump(): Promise<string>;
159
+ private evaluate;
160
+ private evaluateOnTab;
161
+ }
162
+
163
+ type TOIMDevInspectSnapshot = {
164
+ collections: Record<string, unknown>;
165
+ computeds: Record<string, unknown>;
166
+ };
167
+
168
+ export { type IOIMDevRegistry, type IOIMDevStateSource, OIMDevBridge, OIMDevBridgeStateSource, OIMDevCdpStateSource, OIMDevHttpStateSource, OIMDevModuleStateSource, OIMDevRegistryStateSource, OIMDevStateReader, OIMDevUIServer, type TOIMDevBridgeOptions, type TOIMDevInspectSnapshot, type TOIMDevUIServerOptions };