@supatype/client 0.9.2 → 0.10.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/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-test.log +112 -77
- package/.turbo/turbo-typecheck.log +2 -2
- package/CHANGELOG.md +123 -20
- package/README.md +18 -0
- package/dist/auth.d.ts +4 -0
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +38 -13
- package/dist/auth.js.map +1 -1
- package/dist/bindings.d.ts +3 -0
- package/dist/bindings.d.ts.map +1 -1
- package/dist/bindings.js +1 -0
- package/dist/bindings.js.map +1 -1
- package/dist/channel-watch.d.ts +42 -0
- package/dist/channel-watch.d.ts.map +1 -0
- package/dist/channel-watch.js +59 -0
- package/dist/channel-watch.js.map +1 -0
- package/dist/errors.d.ts +40 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +31 -0
- package/dist/errors.js.map +1 -1
- package/dist/exact-values.d.ts +18 -5
- package/dist/exact-values.d.ts.map +1 -1
- package/dist/exact-values.js +76 -12
- package/dist/exact-values.js.map +1 -1
- package/dist/field-kinds-registry.d.ts +1 -1
- package/dist/field-kinds-registry.d.ts.map +1 -1
- package/dist/field-kinds-registry.js +20 -2
- package/dist/field-kinds-registry.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/public-env.d.ts +13 -0
- package/dist/public-env.d.ts.map +1 -0
- package/dist/public-env.js +23 -0
- package/dist/public-env.js.map +1 -0
- package/dist/query-cache.d.ts +2 -1
- package/dist/query-cache.d.ts.map +1 -1
- package/dist/query-cache.js.map +1 -1
- package/dist/query.js +1 -1
- package/dist/query.js.map +1 -1
- package/dist/realtime-refusals.d.ts +35 -0
- package/dist/realtime-refusals.d.ts.map +1 -0
- package/dist/realtime-refusals.js +73 -0
- package/dist/realtime-refusals.js.map +1 -0
- package/dist/realtime.d.ts +70 -2
- package/dist/realtime.d.ts.map +1 -1
- package/dist/realtime.js +198 -18
- package/dist/realtime.js.map +1 -1
- package/dist/runtime-env.d.ts +2 -0
- package/dist/runtime-env.d.ts.map +1 -1
- package/dist/runtime-env.js +5 -0
- package/dist/runtime-env.js.map +1 -1
- package/dist/table-subscription.d.ts +23 -9
- package/dist/table-subscription.d.ts.map +1 -1
- package/dist/table-subscription.js +155 -23
- package/dist/table-subscription.js.map +1 -1
- package/dist/types.d.ts +29 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
- package/src/auth.ts +40 -12
- package/src/bindings.ts +3 -0
- package/src/channel-watch.ts +86 -0
- package/src/errors.ts +54 -0
- package/src/exact-values.ts +101 -13
- package/src/field-kinds-registry.ts +2 -3
- package/src/index.ts +13 -1
- package/src/public-env.ts +22 -0
- package/src/query-cache.ts +2 -1
- package/src/query.ts +1 -1
- package/src/realtime-refusals.ts +100 -0
- package/src/realtime.ts +256 -20
- package/src/runtime-env.ts +6 -0
- package/src/table-subscription.ts +186 -30
- package/src/types.ts +35 -1
- package/tests/auth-restore-user.test.ts +84 -0
- package/tests/auth.test.ts +11 -0
- package/tests/channel-watch-private.test.ts +105 -0
- package/tests/channel-watch.test.ts +97 -0
- package/tests/exact-response.test.ts +101 -0
- package/tests/exact-values.test.ts +57 -0
- package/tests/field-kinds-registry.test.ts +12 -0
- package/tests/helpers/close-event.ts +12 -0
- package/tests/helpers/fake-client.ts +38 -0
- package/tests/public-env.test.ts +43 -0
- package/tests/query-cache.test.ts +1 -1
- package/tests/realtime-connection.test.ts +228 -0
- package/tests/realtime-exact-values.test.ts +42 -0
- package/tests/realtime-private-channels.test.ts +377 -0
- package/tests/realtime-refusal-error.test.ts +2 -1
- package/tests/realtime-typed-channels.test.ts +49 -0
- package/tests/runtime-env.test.ts +14 -0
- package/tests/table-subscription-rows.test.ts +136 -0
- package/tests/table-subscription.test.ts +4 -3
- package/tsconfig.tsbuildinfo +1 -1
- package/type-tests/declared-channels.ts +30 -0
- package/type-tests/tsconfig.json +4 -0
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { SupatypeError } from "./errors.js";
|
|
1
|
+
import { isRealtimeChannelError, SupatypeError } from "./errors.js";
|
|
2
2
|
import { isJsonObject } from "./json.js";
|
|
3
|
+
import { isRowsOf } from "./caller-types.js";
|
|
4
|
+
import { reportThrown } from "./thrown-error.js";
|
|
3
5
|
/**
|
|
4
6
|
* Makes each table subscription's channel name unique.
|
|
5
7
|
*
|
|
@@ -49,48 +51,178 @@ export function subscriptionViewOf(status, err) {
|
|
|
49
51
|
case "CLOSED":
|
|
50
52
|
return { status: "disconnected", error: null };
|
|
51
53
|
case "CHANNEL_ERROR":
|
|
52
|
-
|
|
54
|
+
// A typed refusal is kept as it is, so the binding's error says which refusal it was.
|
|
55
|
+
return { status: "error", error: isRealtimeChannelError(err) ? err : new SupatypeError({ message: err?.message ?? "Subscription error" }) };
|
|
53
56
|
case "TIMED_OUT":
|
|
54
57
|
return { status: "error", error: new SupatypeError({ message: "Realtime connection timed out" }) };
|
|
55
58
|
}
|
|
56
59
|
}
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
const DEFAULT_KEY = ["id"];
|
|
61
|
+
function keyColumnsOf(key) {
|
|
62
|
+
if (key === undefined)
|
|
63
|
+
return DEFAULT_KEY;
|
|
64
|
+
return typeof key === "string" ? [key] : key;
|
|
65
|
+
}
|
|
66
|
+
/** The row's key as one comparable string, or undefined when a key column is missing or null. */
|
|
67
|
+
function keyOf(row, key) {
|
|
68
|
+
if (!isJsonObject(row))
|
|
69
|
+
return undefined;
|
|
70
|
+
const parts = key.map((column) => row[column]);
|
|
71
|
+
return parts.some((part) => part === undefined || part === null) ? undefined : parts.map(String).join("\u0000");
|
|
72
|
+
}
|
|
73
|
+
/** `rows` with `next` in place of the row sharing its key, or added when none does. */
|
|
74
|
+
function upserted(rows, next, key) {
|
|
75
|
+
const wanted = keyOf(next, key);
|
|
76
|
+
const at = wanted === undefined ? -1 : rows.findIndex((row) => keyOf(row, key) === wanted);
|
|
77
|
+
if (at < 0)
|
|
78
|
+
return [...rows, next];
|
|
79
|
+
return rows.map((row, i) => (i === at ? next : row));
|
|
59
80
|
}
|
|
60
81
|
/**
|
|
61
|
-
* The rows after one change, matched on `id
|
|
82
|
+
* The rows after one change, matched on `key` (the `id` column unless the subscription names others).
|
|
62
83
|
*
|
|
63
|
-
* An
|
|
64
|
-
*
|
|
84
|
+
* An INSERT or UPDATE is an upsert: a row seen twice is listed once, and an update to a row not seen
|
|
85
|
+
* yet adds it. A DELETE removes by key, and one for a key not held leaves the rows as they were.
|
|
86
|
+
* An insert or update without its row (which the service does not send), or one whose row has no
|
|
87
|
+
* key to match, leaves the rows as they were rather than putting a null or a duplicate among them.
|
|
65
88
|
*/
|
|
66
|
-
export function applyRowChange(rows, payload) {
|
|
89
|
+
export function applyRowChange(rows, payload, key = DEFAULT_KEY) {
|
|
67
90
|
const current = rows ?? [];
|
|
68
|
-
const next = payload.new;
|
|
69
91
|
switch (payload.eventType) {
|
|
70
92
|
case "INSERT":
|
|
71
|
-
return next === null ? current : [...current, next];
|
|
72
93
|
case "UPDATE":
|
|
73
|
-
return
|
|
74
|
-
case "DELETE":
|
|
75
|
-
|
|
94
|
+
return payload.new === null || keyOf(payload.new, key) === undefined ? current : upserted(current, payload.new, key);
|
|
95
|
+
case "DELETE": {
|
|
96
|
+
const gone = keyOf(payload.old, key);
|
|
97
|
+
return gone === undefined ? current : current.filter((row) => keyOf(row, key) !== gone);
|
|
98
|
+
}
|
|
76
99
|
default:
|
|
77
100
|
return current;
|
|
78
101
|
}
|
|
79
102
|
}
|
|
103
|
+
const CONDITION = /^([^=]+)=([a-z]+)\.(.*)$/s;
|
|
104
|
+
const OPERATORS = ["eq", "neq", "gt", "gte", "lt", "lte"];
|
|
105
|
+
function isOperator(text) {
|
|
106
|
+
return OPERATORS.some((known) => known === text);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* `query` narrowed by the conditions of a subscription's `filter`, so the rows read are the rows
|
|
110
|
+
* the subscription hears about. A condition the service ignores (an operator it does not know) is
|
|
111
|
+
* ignored here too.
|
|
112
|
+
*/
|
|
113
|
+
function withConditions(query, filter) {
|
|
114
|
+
let narrowed = query;
|
|
115
|
+
for (const text of (filter ?? "").split(",")) {
|
|
116
|
+
const match = CONDITION.exec(text.trim());
|
|
117
|
+
const op = match?.[2];
|
|
118
|
+
if (match === null || !isOperator(op))
|
|
119
|
+
continue;
|
|
120
|
+
narrowed = narrowed[op](match[1] ?? "", match[3] ?? "");
|
|
121
|
+
}
|
|
122
|
+
return narrowed;
|
|
123
|
+
}
|
|
124
|
+
async function readTable(client, table, filter) {
|
|
125
|
+
try {
|
|
126
|
+
const result = await withConditions(client.from(table).select("*"), filter);
|
|
127
|
+
if (result.error !== null)
|
|
128
|
+
return { rows: null, error: result.error };
|
|
129
|
+
return isRowsOf(result.data) ? { rows: result.data, error: null } : { rows: [], error: null };
|
|
130
|
+
}
|
|
131
|
+
catch (e) {
|
|
132
|
+
return { rows: null, error: reportThrown(`watchTable("${table}")`, e) };
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// ─── A watched table ─────────────────────────────────────────────────────────
|
|
136
|
+
/**
|
|
137
|
+
* One subscription's rows.
|
|
138
|
+
*
|
|
139
|
+
* Seeded by a read of the table each time the channel's join is acknowledged: the first join, and
|
|
140
|
+
* every join after a drop or a sign-in swap. Reading after the join, not before it, leaves no gap:
|
|
141
|
+
* a change committed before the join is in the read, and one committed after it is delivered. The
|
|
142
|
+
* read is not the same as the changes a drop missed, so each re-join replaces the rows with a fresh
|
|
143
|
+
* read rather than trying to patch them.
|
|
144
|
+
*
|
|
145
|
+
* Changes that arrive while a read is in flight are replayed over it, in order, so the read
|
|
146
|
+
* cannot undo them. Only the newest read counts.
|
|
147
|
+
*/
|
|
148
|
+
class WatchedRows {
|
|
149
|
+
client;
|
|
150
|
+
table;
|
|
151
|
+
options;
|
|
152
|
+
handlers;
|
|
153
|
+
rows = null;
|
|
154
|
+
replay = null;
|
|
155
|
+
reads = 0;
|
|
156
|
+
joined = false;
|
|
157
|
+
view = { status: "connecting", error: null };
|
|
158
|
+
readFailed = false;
|
|
159
|
+
stopped = false;
|
|
160
|
+
constructor(client, table, options, handlers) {
|
|
161
|
+
this.client = client;
|
|
162
|
+
this.table = table;
|
|
163
|
+
this.options = options;
|
|
164
|
+
this.handlers = handlers;
|
|
165
|
+
}
|
|
166
|
+
change(payload) {
|
|
167
|
+
this.replay?.push(payload);
|
|
168
|
+
this.show(applyRowChange(this.rows, payload, keyColumnsOf(this.options?.key)));
|
|
169
|
+
}
|
|
170
|
+
status(view) {
|
|
171
|
+
const rejoined = view.status === "connected" && !this.joined;
|
|
172
|
+
this.joined = view.status === "connected";
|
|
173
|
+
this.view = view;
|
|
174
|
+
this.handlers.status(view);
|
|
175
|
+
if (rejoined)
|
|
176
|
+
void this.seed();
|
|
177
|
+
}
|
|
178
|
+
stop() {
|
|
179
|
+
this.stopped = true;
|
|
180
|
+
}
|
|
181
|
+
show(rows) {
|
|
182
|
+
if (this.stopped)
|
|
183
|
+
return;
|
|
184
|
+
this.rows = rows;
|
|
185
|
+
this.handlers.rows(rows);
|
|
186
|
+
}
|
|
187
|
+
async seed() {
|
|
188
|
+
const read = ++this.reads;
|
|
189
|
+
this.replay ??= [];
|
|
190
|
+
const answer = await readTable(this.client, this.table, this.options?.filter);
|
|
191
|
+
if (read !== this.reads || this.stopped)
|
|
192
|
+
return;
|
|
193
|
+
const missed = this.replay;
|
|
194
|
+
this.replay = null;
|
|
195
|
+
this.reportRead(answer.error);
|
|
196
|
+
if (answer.rows === null)
|
|
197
|
+
return;
|
|
198
|
+
const key = keyColumnsOf(this.options?.key);
|
|
199
|
+
this.show(missed.reduce((rows, payload) => applyRowChange(rows, payload, key), answer.rows));
|
|
200
|
+
}
|
|
201
|
+
/** A failed read is the subscription's error until a read succeeds; the channel's status stands. */
|
|
202
|
+
reportRead(error) {
|
|
203
|
+
if (error !== null)
|
|
204
|
+
this.handlers.status({ ...this.view, error });
|
|
205
|
+
else if (this.readFailed)
|
|
206
|
+
this.handlers.status(this.view);
|
|
207
|
+
this.readFailed = error !== null;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
80
210
|
/**
|
|
81
211
|
* Subscribe to changes on a `public` table, and return the unsubscribe.
|
|
82
212
|
*
|
|
83
213
|
* The handlers are told the rows and the connection status; the binding decides where they live.
|
|
84
|
-
* The
|
|
85
|
-
*
|
|
214
|
+
* The rows are the table's own: read when the subscription joins and again after each re-join, and
|
|
215
|
+
* kept current by upserting each change by key. `options.filter` narrows both the read and the
|
|
216
|
+
* changes. The status is watched on the channel `subscribeToTable` already joined, which is what
|
|
217
|
+
* its channel's `subscribe(cb)` is for.
|
|
86
218
|
*/
|
|
87
|
-
export function watchTable(
|
|
88
|
-
|
|
89
|
-
const subscription = subscribeToTable(realtime, table, (payload) =>
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
219
|
+
export function watchTable(client, table, options, handlers) {
|
|
220
|
+
const watched = new WatchedRows(client, table, options, handlers);
|
|
221
|
+
const subscription = subscribeToTable(client.realtime, table, (payload) => watched.change(payload), options);
|
|
222
|
+
subscription.channel.subscribe((status, err) => watched.status(subscriptionViewOf(status, err)));
|
|
223
|
+
return () => {
|
|
224
|
+
watched.stop();
|
|
225
|
+
subscription.unsubscribe();
|
|
226
|
+
};
|
|
95
227
|
}
|
|
96
228
|
//# sourceMappingURL=table-subscription.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-subscription.js","sourceRoot":"","sources":["../src/table-subscription.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"table-subscription.js","sourceRoot":"","sources":["../src/table-subscription.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB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AA;QACd,YAAY,CAAC,WAAW,EAAE,CAAA;IAC5B,CAAC,CAAA;AACH,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TableRelationship } from "./select-types.js";
|
|
2
|
+
import type { CacheStatus } from "./query-cache.js";
|
|
2
3
|
import type { SupatypeError } from "./errors.js";
|
|
3
4
|
export interface UserIdentity {
|
|
4
5
|
id: string;
|
|
@@ -197,7 +198,7 @@ export interface QueryResult<TData> {
|
|
|
197
198
|
error: SupatypeError | null;
|
|
198
199
|
count: number | null;
|
|
199
200
|
meta?: {
|
|
200
|
-
cacheStatus?:
|
|
201
|
+
cacheStatus?: CacheStatus | undefined;
|
|
201
202
|
/** Present only when the response named restricted columns. Absent means "not stated". */
|
|
202
203
|
maskedFields?: MaskedField[] | undefined;
|
|
203
204
|
} | undefined;
|
|
@@ -280,6 +281,33 @@ export interface SupatypeModels {
|
|
|
280
281
|
}
|
|
281
282
|
export interface SupatypeBuckets {
|
|
282
283
|
}
|
|
284
|
+
export interface SupatypeChannels {
|
|
285
|
+
}
|
|
286
|
+
/** What one `{param}` of a channel pattern holds: a number for an Integer parameter, else text. */
|
|
287
|
+
type TopicParam<TParams, TName extends string> = TParams extends {
|
|
288
|
+
[K in TName]: number;
|
|
289
|
+
} ? `${number}` : string;
|
|
290
|
+
/** A pattern with every `{param}` and a trailing `*` replaced by the text that can stand there. */
|
|
291
|
+
type TopicOfPattern<TPattern extends string, TParams> = TPattern extends `${infer Head}{${infer Name}}${infer Rest}` ? `${Head}${TopicParam<TParams, Name>}${TopicOfPattern<Rest, TParams>}` : TPattern extends `${infer Head}*` ? `${Head}${string}` : TPattern;
|
|
292
|
+
/**
|
|
293
|
+
* The topics a set of declared channels can name, as template literal types. `{ "lot:{id}": ... }`
|
|
294
|
+
* gives `` `lot:${string}` ``, `"lobby:*"` gives `` `lobby:${string}` ``, and an Integer parameter
|
|
295
|
+
* gives `` `${number}` `` in its place. Generated code fills {@link SupatypeChannels}; this takes the
|
|
296
|
+
* declarations as an argument so it can be checked without augmenting that interface.
|
|
297
|
+
*/
|
|
298
|
+
export type DeclaredTopics<TChannels> = {
|
|
299
|
+
[P in keyof TChannels & string]: TopicOfPattern<P, TChannels[P] extends {
|
|
300
|
+
params: infer R;
|
|
301
|
+
} ? R : never>;
|
|
302
|
+
}[keyof TChannels & string];
|
|
303
|
+
/** The topics the project's schema declares. `never` until `supatype generate` has run. */
|
|
304
|
+
export type DeclaredTopic = DeclaredTopics<SupatypeChannels>;
|
|
305
|
+
/**
|
|
306
|
+
* A channel name: a declared topic, which autocompletes, or any other string, which an `open`
|
|
307
|
+
* realtime server still admits. The `string & {}` keeps the literal suggestions from collapsing
|
|
308
|
+
* into plain `string`.
|
|
309
|
+
*/
|
|
310
|
+
export type ChannelName = DeclaredTopic | (string & {});
|
|
283
311
|
export interface SupatypeFunctions {
|
|
284
312
|
}
|
|
285
313
|
/**
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAIhD,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACrC,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAClC;AAED,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAA;IACV,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CA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AAS,CAAA;QACzC,oFAAoF;QACpF,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QAC/B;;;;WAIG;QACH,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QACjC;;;WAGG;QACH,OAAO,CAAC,EAAE,WAAW,GAAG,SAAS,CAAA;QACjC;;;;;WAKG;QACH,kBAAkB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;KACzC,GAAG,SAAS,CAAA;IACb;;;;;;;;OAQG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IAC3B;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,kBAAkB,EAAE,UAAU,GAAG,SAAS,CAAA;IAC9D;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IACpC;;;;;;;;;;;;;;;OAeG;IACH,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAChC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,SAAS,CAAA;CAC9E"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAkdA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,OAAO,CAAA;AAEnC;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supatype/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Supatype client SDK: typed REST, auth, storage, realtime",
|
|
6
6
|
"type": "module",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"scripts": {
|
|
32
32
|
"build": "tsc --project tsconfig.json",
|
|
33
33
|
"dev": "tsc --project tsconfig.json --watch",
|
|
34
|
-
"typecheck": "tsc --project tests/tsconfig.json --noEmit",
|
|
34
|
+
"typecheck": "tsc --project tests/tsconfig.json --noEmit && tsc --project type-tests/tsconfig.json --noEmit",
|
|
35
35
|
"test": "vitest run --maxWorkers=50%",
|
|
36
36
|
"clean": "rm -rf dist *.tsbuildinfo"
|
|
37
37
|
}
|
package/src/auth.ts
CHANGED
|
@@ -142,17 +142,41 @@ function eitherKey<T>(
|
|
|
142
142
|
return guard(b) ? b : undefined
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
/**
|
|
146
|
-
function
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
if (
|
|
145
|
+
/** `appMetadata` as `app_metadata`: the key `_parseUser` and its helpers read. */
|
|
146
|
+
function snakeCaseKey(key: string): string {
|
|
147
|
+
return key.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** A stored object with each camelCase key also under its snake_case name, unless that is set. Shallow. */
|
|
151
|
+
function withSnakeKeys(stored: Record<string, unknown>): Record<string, unknown> {
|
|
152
|
+
const normalized = { ...stored }
|
|
153
|
+
for (const [key, value] of Object.entries(stored)) {
|
|
154
|
+
const snake = snakeCaseKey(key)
|
|
155
|
+
if (snake !== key && stored[snake] === undefined) normalized[snake] = value
|
|
156
|
+
}
|
|
157
|
+
return normalized
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** The `is_anonymous` claim of an access token, or undefined when it has none. */
|
|
161
|
+
function anonymousClaim(accessToken: string): boolean | undefined {
|
|
162
|
+
const claim = decodeJwtPayload(accessToken.split(".")[1] ?? "")?.["is_anonymous"]
|
|
163
|
+
return typeof claim === "boolean" ? claim : undefined
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* A stored user with its camelCase keys copied to the snake_case ones `_parseUser` reads, so a user
|
|
168
|
+
* this client wrote (`isAnonymous`, `identities[].userId`, ...) survives a restore. A user stored
|
|
169
|
+
* without the anonymous flag takes it from the token's claim.
|
|
170
|
+
*/
|
|
171
|
+
function snakeCaseUser(user: Record<string, unknown>, accessToken: string): Record<string, unknown> {
|
|
172
|
+
const normalized = withSnakeKeys(user)
|
|
173
|
+
for (const list of ["identities", "factors"] as const) {
|
|
174
|
+
const items = user[list]
|
|
175
|
+
if (Array.isArray(items)) normalized[list] = items.map((i) => (isJsonObject(i) ? withSnakeKeys(i) : i))
|
|
176
|
+
}
|
|
177
|
+
if (normalized["is_anonymous"] === undefined) {
|
|
178
|
+
const claim = anonymousClaim(accessToken)
|
|
179
|
+
if (claim !== undefined) normalized["is_anonymous"] = claim
|
|
156
180
|
}
|
|
157
181
|
return normalized
|
|
158
182
|
}
|
|
@@ -440,16 +464,20 @@ export class AuthClient {
|
|
|
440
464
|
async signInWithPassword(credentials: {
|
|
441
465
|
email: string
|
|
442
466
|
password: string
|
|
467
|
+
/** `captchaToken` is the provider widget's answer, which a project with captcha on requires. */
|
|
468
|
+
options?: { captchaToken?: string | undefined } | undefined
|
|
443
469
|
}): Promise<{
|
|
444
470
|
data: { session: Session | null; user: User | null }
|
|
445
471
|
error: SupatypeError | null
|
|
446
472
|
}> {
|
|
473
|
+
const captchaToken = credentials.options?.captchaToken
|
|
447
474
|
const res = await this.send(`${this.url}/token?grant_type=password`, {
|
|
448
475
|
method: "POST",
|
|
449
476
|
headers: this.baseHeaders,
|
|
450
477
|
body: JSON.stringify({
|
|
451
478
|
email: credentials.email,
|
|
452
479
|
password: credentials.password,
|
|
480
|
+
...(captchaToken !== undefined && { supatype_meta_security: { captcha_token: captchaToken } }),
|
|
453
481
|
}),
|
|
454
482
|
})
|
|
455
483
|
return this._parseAuthResponse(res)
|
|
@@ -1413,7 +1441,7 @@ export class AuthClient {
|
|
|
1413
1441
|
refreshToken: eitherKey(raw, "refreshToken", "refresh_token", isString) ?? "",
|
|
1414
1442
|
tokenType: eitherKey(raw, "tokenType", "token_type", isString) ?? "bearer",
|
|
1415
1443
|
expiresIn: eitherKey(raw, "expiresIn", "expires_in", isNumber) ?? 3600,
|
|
1416
|
-
user: this._parseUser(snakeCaseUser(user)),
|
|
1444
|
+
user: this._parseUser(snakeCaseUser(user, accessToken)),
|
|
1417
1445
|
...(expiresAt !== undefined && { expiresAt }),
|
|
1418
1446
|
}
|
|
1419
1447
|
}
|
package/src/bindings.ts
CHANGED
|
@@ -14,6 +14,9 @@ export type {
|
|
|
14
14
|
TableSubscribeOptions,
|
|
15
15
|
TableSubscription,
|
|
16
16
|
} from "./table-subscription.js"
|
|
17
|
+
export { channelSlot, watchChannel, watchConnection } from "./channel-watch.js"
|
|
18
|
+
export type { ChannelSlot } from "./channel-watch.js"
|
|
19
|
+
export type { ChannelOptions, ChannelSubscription, RealtimeConnectionState } from "./realtime.js"
|
|
17
20
|
export { startOAuthRedirect } from "./auth-redirect.js"
|
|
18
21
|
export { isClientFor, isRowsOf, isCallerValue } from "./caller-types.js"
|
|
19
22
|
export { runMutation } from "./mutation-request.js"
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { ChannelOptions, ChannelSubscription, RealtimeClient, RealtimeConnectionState } from "./realtime.js"
|
|
2
|
+
import type { ChannelName } from "./types.js"
|
|
3
|
+
import type { ChannelActionRefusal } from "./realtime-refusals.js"
|
|
4
|
+
import { subscriptionViewOf, type SubscriptionView } from "./table-subscription.js"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* One channel with any number of listeners, and the socket's own state, for the Vue, Svelte and
|
|
8
|
+
* Solid bindings. Each binding is only the adapter between these and its framework's state, as it
|
|
9
|
+
* is for `watchTable`; React's `useChannel` reads the same two client signals directly.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Join the channel `name`, let `setup` add its listeners first, and report each status as the
|
|
14
|
+
* binding's view of it. Returns the unsubscribe.
|
|
15
|
+
*
|
|
16
|
+
* `opts.private` asks for a private channel: see {@link ChannelOptions}. A refusal then shows as a
|
|
17
|
+
* `RealtimeChannelError`, so a binding can read its `reason`.
|
|
18
|
+
*
|
|
19
|
+
* `onRefused` hears a send, track or payload the server refused on the joined channel. The status
|
|
20
|
+
* does not move for it, so it has its own channel to the binding.
|
|
21
|
+
*/
|
|
22
|
+
export function watchChannel<TRow = Record<string, unknown>>(
|
|
23
|
+
realtime: RealtimeClient,
|
|
24
|
+
name: ChannelName,
|
|
25
|
+
setup: (channel: ChannelSubscription<TRow>) => void,
|
|
26
|
+
onStatus: (view: SubscriptionView) => void,
|
|
27
|
+
opts?: ChannelOptions | undefined,
|
|
28
|
+
onRefused?: ((refusal: ChannelActionRefusal) => void) | undefined,
|
|
29
|
+
): () => void {
|
|
30
|
+
const channel = realtime.channel<TRow>(name, opts)
|
|
31
|
+
setup(channel)
|
|
32
|
+
if (onRefused !== undefined) channel.onRefused(onRefused)
|
|
33
|
+
channel.subscribe((status, err) => onStatus(subscriptionViewOf(status, err)))
|
|
34
|
+
return () => channel.unsubscribe()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Report the socket's state now and at each change. Returns the unsubscribe.
|
|
39
|
+
*
|
|
40
|
+
* The state is reported straight away because a binding mounting after the socket opened would
|
|
41
|
+
* otherwise show "disconnected" until the next change.
|
|
42
|
+
*/
|
|
43
|
+
export function watchConnection(
|
|
44
|
+
realtime: RealtimeClient,
|
|
45
|
+
onChange: (state: RealtimeConnectionState) => void,
|
|
46
|
+
): () => void {
|
|
47
|
+
onChange(realtime.connectionState)
|
|
48
|
+
return realtime.onConnectionChange(onChange)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** One channel at a time, which can be moved to another name. */
|
|
52
|
+
export interface ChannelSlot {
|
|
53
|
+
/** Join `name`, leaving the channel held first. Joining the name already held does nothing. */
|
|
54
|
+
join(name: ChannelName): void
|
|
55
|
+
/** Leave the channel held, if any. */
|
|
56
|
+
leave(): void
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* A binding's channel when its name can change: the old channel is left, its listeners go with it,
|
|
61
|
+
* `setup` runs on the new one, and the status reads "connecting" until it joins. A binding calls
|
|
62
|
+
* `join` for the first name and again for each change, and `leave` when it is torn down. `opts` is
|
|
63
|
+
* given to every channel it joins, and `onRefused` hears every refused send on them.
|
|
64
|
+
*/
|
|
65
|
+
export function channelSlot<TRow = Record<string, unknown>>(
|
|
66
|
+
realtime: RealtimeClient,
|
|
67
|
+
setup: (channel: ChannelSubscription<TRow>) => void,
|
|
68
|
+
onStatus: (view: SubscriptionView) => void,
|
|
69
|
+
opts?: ChannelOptions | undefined,
|
|
70
|
+
onRefused?: ((refusal: ChannelActionRefusal) => void) | undefined,
|
|
71
|
+
): ChannelSlot {
|
|
72
|
+
let held: { name: ChannelName; stop: () => void } | null = null
|
|
73
|
+
const leave = (): void => {
|
|
74
|
+
held?.stop()
|
|
75
|
+
held = null
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
join(name) {
|
|
79
|
+
if (held?.name === name) return
|
|
80
|
+
if (held !== null) onStatus({ status: "connecting", error: null })
|
|
81
|
+
leave()
|
|
82
|
+
held = { name, stop: watchChannel<TRow>(realtime, name, setup, onStatus, opts, onRefused) }
|
|
83
|
+
},
|
|
84
|
+
leave,
|
|
85
|
+
}
|
|
86
|
+
}
|
package/src/errors.ts
CHANGED
|
@@ -195,6 +195,60 @@ export class RealtimeError extends SupatypeCodedError {
|
|
|
195
195
|
}
|
|
196
196
|
nameErrors(RealtimeError, "RealtimeError")
|
|
197
197
|
|
|
198
|
+
/** Why a channel's join was refused, or its access taken away. */
|
|
199
|
+
export type RealtimeChannelErrorReason =
|
|
200
|
+
/** The server does not announce private channel support, so a `private: true` join was never sent. */
|
|
201
|
+
| "unsupported_server"
|
|
202
|
+
/** A declaration matched the channel and its `join` rule denied this user. */
|
|
203
|
+
| "join_denied"
|
|
204
|
+
/** The join said `private: true` and no `Channel` declaration matches the name. */
|
|
205
|
+
| "not_declared"
|
|
206
|
+
/** A declaration matches, but the name's parameters do not fit it (`lot:abc` for `lot:{id}`). */
|
|
207
|
+
| "does_not_fit"
|
|
208
|
+
/** The server could not reach the database to check. Retrying may succeed. */
|
|
209
|
+
| "unavailable"
|
|
210
|
+
/** The server is a shared instance, where private channels are not available. */
|
|
211
|
+
| "shared_instance"
|
|
212
|
+
/** A channel the socket held was taken away: the token changed, a re-check ran, or a declaration went. */
|
|
213
|
+
| "withdrawn"
|
|
214
|
+
/** The server refused for a reason this client has no name for; `message` has it. */
|
|
215
|
+
| "refused"
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* A channel the realtime server refused, or took back. Handed to a channel's status callback as the
|
|
219
|
+
* second argument with `CHANNEL_ERROR`: `subscribe((status, err) => ...)`.
|
|
220
|
+
*
|
|
221
|
+
* `reason` says which, so an app can tell a user who may not join from a typo in a channel name,
|
|
222
|
+
* and a withdrawal from either. `retryable` is true only for `unavailable`: every other reason
|
|
223
|
+
* is the server's answer and asking again gets the same one.
|
|
224
|
+
*/
|
|
225
|
+
export class RealtimeChannelError extends RealtimeError {
|
|
226
|
+
readonly channel: string
|
|
227
|
+
readonly reason: RealtimeChannelErrorReason
|
|
228
|
+
|
|
229
|
+
constructor(message: string, channel: string, reason: RealtimeChannelErrorReason) {
|
|
230
|
+
super(message, RealtimeErrorCodes.CHANNEL_ERROR)
|
|
231
|
+
this.channel = channel
|
|
232
|
+
this.reason = reason
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** Whether asking again can succeed: only when the server could not check. */
|
|
236
|
+
get retryable(): boolean {
|
|
237
|
+
return this.reason === "unavailable"
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
nameErrors(RealtimeChannelError, "RealtimeChannelError")
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Whether `value` is a `RealtimeChannelError`.
|
|
244
|
+
*
|
|
245
|
+
* By name rather than `instanceof`, so it holds across two copies of this package in one bundle,
|
|
246
|
+
* which a framework binding and an app can easily have.
|
|
247
|
+
*/
|
|
248
|
+
export function isRealtimeChannelError(value: unknown): value is RealtimeChannelError {
|
|
249
|
+
return value instanceof Error && value.name === "RealtimeChannelError" && "reason" in value && "channel" in value
|
|
250
|
+
}
|
|
251
|
+
|
|
198
252
|
/**
|
|
199
253
|
* Network errors (connection failures, timeouts, DNS).
|
|
200
254
|
*/
|