@pgxsinkit/pgwasm-repl 0.5.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/src/styles.ts ADDED
@@ -0,0 +1,148 @@
1
+ // Began as a copy of `@electric-sql/pglite-repl` (taken under PGlite's PostgreSQL License option,
2
+ // © ElectricSQL — see NOTICE). Owned outright (ADR-0062); compatibility with PGlite is an anti-goal.
3
+
4
+ /**
5
+ * The REPL's stylesheet. It ships as a string, not a `.css` import (which only some bundlers can load):
6
+ * the component renders it as a React-hoisted `<style>`, which React inserts into the document once,
7
+ * however many REPLs are mounted. Every class is prefixed `pgwasm-repl-`. `--pgwasm-repl-font-size`
8
+ * sets the size; the colours and borders follow the editor's theme.
9
+ */
10
+ export const REPL_STYLESHEET_ID = "pgwasm-repl";
11
+
12
+ export const REPL_STYLES = `
13
+ .pgwasm-repl-root {
14
+ --pgwasm-repl-fg: var(--pgwasm-repl-foreground-color);
15
+ --pgwasm-repl-bg: var(--pgwasm-repl-background-color);
16
+ --pgwasm-repl-size: var(--pgwasm-repl-font-size, 12px);
17
+ display: flex;
18
+ flex-direction: column;
19
+ height: 100%;
20
+ width: 100%;
21
+ font-size: var(--pgwasm-repl-size);
22
+ color: var(--pgwasm-repl-fg);
23
+ background-color: var(--pgwasm-repl-bg);
24
+ }
25
+ .pgwasm-repl-loading-msg {
26
+ opacity: 0.5;
27
+ }
28
+ .pgwasm-repl-root table {
29
+ font-size: var(--pgwasm-repl-size);
30
+ }
31
+ .pgwasm-repl-root-border {
32
+ border: var(--pgwasm-repl-border);
33
+ }
34
+ .pgwasm-repl-output {
35
+ flex: 1;
36
+ overflow-y: auto;
37
+ padding: 0.5em 0 0.5em 0.5em;
38
+ border-bottom: var(--pgwasm-repl-border);
39
+ }
40
+ .pgwasm-repl-root hr {
41
+ margin: 0.5em 0;
42
+ border: none;
43
+ border-top: var(--pgwasm-repl-border);
44
+ }
45
+ .pgwasm-repl-input {
46
+ display: flex;
47
+ min-height: 60px;
48
+ max-height: 50%;
49
+ width: 100%;
50
+ }
51
+ .pgwasm-repl-input .cm-editor.cm-focused {
52
+ outline: none;
53
+ }
54
+ .pgwasm-repl-input-loading {
55
+ pointer-events: none;
56
+ }
57
+ .pgwasm-repl-table-scroll {
58
+ overflow-x: auto;
59
+ }
60
+ .pgwasm-repl-table {
61
+ border-collapse: collapse;
62
+ }
63
+ .pgwasm-repl-line {
64
+ margin: 0 0 0 1em;
65
+ position: relative;
66
+ }
67
+ .pgwasm-repl-line::before {
68
+ display: block;
69
+ width: 0.7em;
70
+ text-align: center;
71
+ content: "\\276E";
72
+ margin-right: 0.5em;
73
+ color: var(--pgwasm-repl-border-color);
74
+ position: absolute;
75
+ left: -1em;
76
+ }
77
+ .pgwasm-repl-line + .pgwasm-repl-line {
78
+ margin-top: 0.25em;
79
+ }
80
+ .pgwasm-repl-query {
81
+ margin: 0 0 0.25em 1em;
82
+ }
83
+ .pgwasm-repl-query::before {
84
+ content: "\\276F";
85
+ }
86
+ .pgwasm-repl-table th {
87
+ text-align: center;
88
+ font-weight: 600;
89
+ }
90
+ .pgwasm-repl-table td {
91
+ text-align: left;
92
+ max-width: 400px;
93
+ overflow: hidden;
94
+ text-overflow: ellipsis;
95
+ }
96
+ .pgwasm-repl-table .pgwasm-repl-number {
97
+ text-align: right;
98
+ font-variant-numeric: tabular-nums;
99
+ }
100
+ .pgwasm-repl-table .pgwasm-repl-boolean {
101
+ text-align: center;
102
+ }
103
+ .pgwasm-repl-table th,
104
+ .pgwasm-repl-table td {
105
+ padding: 0 0.2em;
106
+ border: var(--pgwasm-repl-border);
107
+ }
108
+ .pgwasm-repl-divider {
109
+ font-size: 9px;
110
+ display: flex;
111
+ align-items: center;
112
+ color: var(--pgwasm-repl-border-color);
113
+ padding-right: 0.5em;
114
+ }
115
+ .pgwasm-repl-divider hr {
116
+ margin: 0;
117
+ flex-grow: 1;
118
+ }
119
+ .pgwasm-repl-time {
120
+ margin: 0 0.5em;
121
+ }
122
+ .pgwasm-repl-null {
123
+ color: var(--pgwasm-repl-border-color);
124
+ }
125
+ .pgwasm-repl-error {
126
+ color: #c33;
127
+ }
128
+ .pgwasm-repl-error::before {
129
+ content: "!";
130
+ color: #c33;
131
+ font-weight: bold;
132
+ }
133
+ .pgwasm-repl-title {
134
+ font-weight: 600;
135
+ }
136
+ .pgwasm-repl-footers {
137
+ margin: 0.25em 0 0;
138
+ }
139
+ .pgwasm-repl-show-more {
140
+ border: none;
141
+ background: none;
142
+ padding: 0;
143
+ font: inherit;
144
+ color: inherit;
145
+ text-decoration: underline;
146
+ cursor: pointer;
147
+ }
148
+ `;
package/src/types.ts ADDED
@@ -0,0 +1,44 @@
1
+ // Began as a copy of `@electric-sql/pglite-repl` (taken under PGlite's PostgreSQL License option,
2
+ // © ElectricSQL — see NOTICE). Owned outright (ADR-0062); compatibility with PGlite is an anti-goal.
3
+
4
+ /** The rows and fields of one statement's result, as the REPL reads them. */
5
+ export interface ReplResults {
6
+ readonly rows: readonly unknown[];
7
+ readonly fields: readonly { readonly name: string; readonly dataTypeID: number }[];
8
+ }
9
+
10
+ /** How a statement's rows come back: as arrays, or as objects keyed by field name. */
11
+ export interface ReplQueryOptions {
12
+ readonly rowMode?: "array" | "object";
13
+ }
14
+
15
+ /**
16
+ * The database the REPL runs statements on: anything with `query` and `exec` in pgwasm's shapes. A
17
+ * `Pgwasm` is one, and so is `@pgxsinkit/client`'s `replAdapter(client)`. The REPL waits for
18
+ * `waitReady` when there is one.
19
+ */
20
+ export interface ReplDatabase {
21
+ query(sql: string, params?: unknown[], options?: ReplQueryOptions): Promise<ReplResults>;
22
+ exec(sql: string, options?: ReplQueryOptions): Promise<readonly ReplResults[]>;
23
+ readonly waitReady?: Promise<void>;
24
+ }
25
+
26
+ /** One table to show: each row an array of field values (the REPL asks for `rowMode: "array"`). */
27
+ export interface ReplRows {
28
+ readonly rows: readonly (readonly unknown[])[];
29
+ readonly fields: readonly { readonly name: string; readonly dataTypeID: number }[];
30
+ /** A describe command's caption above the table (`Table "public.notes"`). */
31
+ readonly title?: string;
32
+ /** A describe command's lines below the table (`Indexes:` and the indexes). */
33
+ readonly footers?: readonly string[];
34
+ }
35
+
36
+ /** What the REPL shows for one input. */
37
+ export interface ReplResponse {
38
+ readonly query: string;
39
+ readonly text?: string;
40
+ readonly error?: string;
41
+ readonly results?: readonly ReplRows[];
42
+ /** Milliseconds. */
43
+ readonly time: number;
44
+ }