@rebasepro/client 0.17.3 → 0.18.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 (63) hide show
  1. package/README.md +4 -0
  2. package/dist/auth.d.ts +80 -0
  3. package/dist/functions.d.ts +6 -1
  4. package/dist/index.d.ts +8 -0
  5. package/dist/index.es.js +471 -94
  6. package/dist/index.es.js.map +1 -1
  7. package/dist/offline-connectivity.d.ts +12 -1
  8. package/dist/offline.d.ts +23 -1
  9. package/dist/query-contract.types.d.ts +30 -0
  10. package/dist/realtime-channel.d.ts +29 -1
  11. package/dist/sdk_query_builder.d.ts +21 -2
  12. package/dist/transport.d.ts +24 -0
  13. package/package.json +28 -15
  14. package/src/admin.ts +0 -90
  15. package/src/anonymous-client-guard.test.ts +0 -190
  16. package/src/api-keys.ts +0 -87
  17. package/src/auth-listener-errors.test.ts +0 -57
  18. package/src/auth-refresh-overflow.test.ts +0 -89
  19. package/src/auth.ts +0 -982
  20. package/src/backups.ts +0 -40
  21. package/src/client-close.test.ts +0 -80
  22. package/src/collection-listen-meta.test.ts +0 -105
  23. package/src/collection-observe.test.ts +0 -138
  24. package/src/collection.test.ts +0 -293
  25. package/src/collection.ts +0 -525
  26. package/src/cron.test.ts +0 -164
  27. package/src/cron.ts +0 -62
  28. package/src/data-proxy.test.ts +0 -183
  29. package/src/errors.ts +0 -9
  30. package/src/functions.ts +0 -82
  31. package/src/index.ts +0 -639
  32. package/src/like-pattern-redos.test.ts +0 -61
  33. package/src/offline-codec.ts +0 -79
  34. package/src/offline-connectivity.test.ts +0 -191
  35. package/src/offline-connectivity.ts +0 -255
  36. package/src/offline-idb-store.test.ts +0 -340
  37. package/src/offline-integration.test.ts +0 -180
  38. package/src/offline-query.test.ts +0 -431
  39. package/src/offline-query.ts +0 -529
  40. package/src/offline-store.ts +0 -357
  41. package/src/offline-sync-engine.test.ts +0 -857
  42. package/src/offline.test.ts +0 -897
  43. package/src/offline.ts +0 -1928
  44. package/src/query-contract.types.ts +0 -206
  45. package/src/query_builder.ts +0 -1
  46. package/src/realtime-channel.test.ts +0 -542
  47. package/src/realtime-channel.ts +0 -539
  48. package/src/realtime-concurrent-subscribe.test.ts +0 -102
  49. package/src/realtime-error-surfacing.test.ts +0 -105
  50. package/src/realtime-optout.test.ts +0 -279
  51. package/src/realtime-row-identity.test.ts +0 -254
  52. package/src/realtime-subscription-key.test.ts +0 -92
  53. package/src/reviver.ts +0 -39
  54. package/src/sdk_query_builder.ts +0 -206
  55. package/src/storage-key-encoding.test.ts +0 -65
  56. package/src/storage-registry.ts +0 -102
  57. package/src/storage.ts +0 -253
  58. package/src/transport-baseurl.test.ts +0 -101
  59. package/src/transport.ts +0 -505
  60. package/src/vector-search-listen.test.ts +0 -42
  61. package/src/vector-search-query.test.ts +0 -55
  62. package/src/websocket-url.test.ts +0 -97
  63. package/src/websocket.ts +0 -1837
@@ -1,206 +0,0 @@
1
- /**
2
- * Compile-time assertions about the query surface.
3
- *
4
- * ## Read this before adding a `.test.ts` for a type
5
- *
6
- * These assertions are **not** in a test file, on purpose. In this repo a jest
7
- * test cannot check a type at all:
8
- *
9
- * - `ts-jest` is configured transpile-only. Verified: a test containing
10
- * `const n: number = "nope"` passes. `@ts-expect-error` in a `.test.ts` is
11
- * therefore inert — it asserts nothing and never fails.
12
- * - `tsconfig.typecheck.json` — the gate CI runs as `pnpm run typecheck` —
13
- * covers every package's `src` directory but **excludes every `*.test.ts`**.
14
- *
15
- * So a type assertion written as a test is checked by nothing, twice over. This
16
- * file is a plain module under `src`, which is exactly what the gate does read.
17
- * It is imported by nothing and emits no runtime code.
18
- *
19
- * ## What went wrong that this exists to prevent
20
- *
21
- * `_score` was accepted by the runtime, documented in the SDK docs and skills,
22
- * and rejected by `orderBy`'s type, which was `keyof M`. On a project with a
23
- * generated SDK — where `M` is a concrete row type — the documented call was a
24
- * compile error. Nothing in this repo noticed; a downstream application did.
25
- */
26
- import type { FindParams, FindResult, SDKQueryBuilderInterface, WhereFilterOp } from "@rebasepro/types";
27
-
28
- /**
29
- * A row shaped the way a **generated** SDK shapes one: a type alias with a
30
- * finite key set.
31
- *
32
- * This detail is the whole test. An `interface … extends Record<string,
33
- * unknown>` also satisfies the constraint, but its index signature makes
34
- * `keyof M` collapse to `string` — so every assertion below would pass no
35
- * matter what `orderBy` accepted, typos included. That is how the first draft
36
- * of this file was written, and every `@ts-expect-error` in it reported
37
- * "unused directive": the fixture proved nothing.
38
- *
39
- * A generated row type has no index signature, which is exactly why a real
40
- * project caught what this repo did not.
41
- */
42
- type ContractRow = {
43
- id: string;
44
- title: string;
45
- created_at: string;
46
- /** An `array` property, which codegen emits as `Array<X>`. */
47
- tags: string[];
48
- age: number;
49
- deleted_at: string | null;
50
- };
51
-
52
- /** A to-many relation, which codegen emits as `Array<TargetRow>`. */
53
- type TagRow = { id: string; label: string };
54
- type PostRow = { id: string; title: string; tags: TagRow[] };
55
-
56
- // ── orderBy accepts relevance, and still rejects nonsense ───────────────────
57
-
58
- /** The documented relevance sort must compile. */
59
- export const orderByScore: FindParams<ContractRow> = {
60
- searchString: "auditor",
61
- orderBy: ["_score", "desc"]
62
- };
63
-
64
- /** An ordinary column must keep compiling. */
65
- export const orderByColumn: FindParams<ContractRow> = { orderBy: ["created_at", "desc"] };
66
-
67
- /**
68
- * A column that does not exist must still be refused. Widening `orderBy` to
69
- * `string` would have fixed the `_score` error and silently given up this,
70
- * turning every typo into an unsorted 200 in production.
71
- */
72
- // @ts-expect-error - "nope" is neither a column of ContractRow nor computed
73
- export const orderByTypo: FindParams<ContractRow> = { orderBy: ["nope", "desc"] };
74
-
75
- // ── the fluent builder agrees with FindParams ──────────────────────────────
76
-
77
- export const fluentScore = (qb: SDKQueryBuilderInterface<ContractRow>) =>
78
- qb.search("auditor").orderBy("_score", "desc");
79
-
80
- export const fluentColumn = (qb: SDKQueryBuilderInterface<ContractRow>) =>
81
- qb.orderBy("created_at", "asc");
82
-
83
- export const fluentTypo = (qb: SDKQueryBuilderInterface<ContractRow>) =>
84
- // @ts-expect-error - the fluent signature must reject what FindParams rejects
85
- qb.orderBy("_scoer", "desc");
86
-
87
- /** Vector search must be reachable from the builder, and chain. */
88
- export const fluentVector = (qb: SDKQueryBuilderInterface<ContractRow>) =>
89
- qb.vectorSearch("embedding", [0.1, 0.2], { threshold: 0.3 }).limit(10);
90
-
91
- // ── the operator decides what the value is ─────────────────────────────────
92
-
93
- /**
94
- * `array-contains` takes an **element** of the column, not the column.
95
- *
96
- * This was the second `_score`: documented in `docs/sdk/querying.md`, accepted
97
- * by the runtime, and a compile error on a generated SDK — because
98
- * `WhereValue<T> = T | T[] | null` was one value type for all sixteen
99
- * operators, so on `tags: string[]` it wanted a `string[]`. The spelling that
100
- * did compile, `["featured"]`, builds `@> ARRAY[$1]` with the whole array bound
101
- * as the single element and matches nothing, forever, with no error anywhere.
102
- */
103
- export const fluentArrayContains = (qb: SDKQueryBuilderInterface<ContractRow>) =>
104
- qb.where("tags", "array-contains", "featured");
105
-
106
- export const fluentArrayContainsWrapped = (qb: SDKQueryBuilderInterface<ContractRow>) =>
107
- // @ts-expect-error - the column is not one of its own elements
108
- qb.where("tags", "array-contains", ["featured"]);
109
-
110
- /**
111
- * Same defect, and the case the relation compiler was specifically built for:
112
- * a to-many relation is emitted as `Array<TargetRow>`, and the compiler answers
113
- * `array-contains` on it by comparing **ids**. So the id must be accepted even
114
- * though it is not the element type.
115
- */
116
- export const fluentRelationContains = (qb: SDKQueryBuilderInterface<PostRow>, tagId: string) =>
117
- qb.where("tags", "array-contains", tagId);
118
-
119
- export const fluentRelationIn = (qb: SDKQueryBuilderInterface<PostRow>, tagIds: string[]) =>
120
- qb.where("tags", "in", tagIds);
121
-
122
- export const fluentRelationTypo = (qb: SDKQueryBuilderInterface<PostRow>) =>
123
- // @ts-expect-error - neither a `TagRow` nor a `TagRow["id"]`
124
- qb.where("tags", "array-contains", 42);
125
-
126
- /** The list operators take a list of elements — or one, read as a one-element list. */
127
- export const fluentInList = (qb: SDKQueryBuilderInterface<ContractRow>) =>
128
- qb.where("tags", "in", ["featured", "new"]);
129
-
130
- export const fluentInScalar = (qb: SDKQueryBuilderInterface<ContractRow>) =>
131
- qb.where("title", "in", "hello");
132
-
133
- export const fluentInNested = (qb: SDKQueryBuilderInterface<ContractRow>) =>
134
- // @ts-expect-error - a list of lists is not a list of elements
135
- qb.where("tags", "in", [["featured"]]);
136
-
137
- /** A comparison takes one value. `eq(column, ["a","b"])` is not a query anyone meant. */
138
- export const fluentEqArray = (qb: SDKQueryBuilderInterface<ContractRow>) =>
139
- // @ts-expect-error - `==` compares against a value, not a list
140
- qb.where("title", "==", ["a", "b"]);
141
-
142
- /**
143
- * A pattern is a string on every column type. The driver casts, so refusing
144
- * `"%3%"` on a numeric column was the type being stricter than the runtime.
145
- */
146
- export const fluentLikeOnNumber = (qb: SDKQueryBuilderInterface<ContractRow>) =>
147
- qb.where("age", "like", "%3%");
148
-
149
- /** The null operators ignore their value; `null` is the conventional spelling. */
150
- export const fluentIsNull = (qb: SDKQueryBuilderInterface<ContractRow>) =>
151
- qb.where("deleted_at", "is-null", null);
152
-
153
- /**
154
- * A caller holding an unnarrowed operator — a dynamic filter UI — must keep
155
- * compiling. `WhereValueFor` distributes over the operator, so this is the
156
- * union of every branch rather than a `never`.
157
- */
158
- export const fluentDynamicOp = (qb: SDKQueryBuilderInterface<ContractRow>, op: WhereFilterOp) =>
159
- qb.where("title", op, "anything");
160
-
161
- /** Two conditions on one column: the shape the Mongo compiler used to drop. */
162
- export const fluentRange = (qb: SDKQueryBuilderInterface<ContractRow>) =>
163
- qb.where("age", ">=", 18).where("age", "<", 65);
164
-
165
- /** The object form must accept exactly what the fluent form accepts. */
166
- export const paramsArrayContains: FindParams<ContractRow> = {
167
- where: { tags: ["array-contains", "featured"] }
168
- };
169
-
170
- /** …and the array-of-tuples form the builder produces from two `.where()` calls. */
171
- export const paramsRange: FindParams<ContractRow> = {
172
- where: { age: [[">=", 18], ["<", 65]] }
173
- };
174
-
175
- // ── what a query computes is readable off the row ──────────────────────────
176
-
177
- /**
178
- * Sorting by relevance and then being unable to read it was the other half of
179
- * the same bug — the e2e cast around it, which should have been the tell.
180
- */
181
- export const readComputed = (result: FindResult<ContractRow>) => {
182
- const row = result.data[0];
183
- const score: number | undefined = row._score;
184
- const distance: number | undefined = row._distance;
185
- const title: string = row.title;
186
- return { score, distance, title };
187
- };
188
-
189
- /** Widening the row must not have turned it into `any`. */
190
- export const readUnknown = (result: FindResult<ContractRow>) =>
191
- // @ts-expect-error - `nope` is neither a column nor computed
192
- result.data[0].nope;
193
-
194
- /**
195
- * A result row must stay assignable to `Record<string, unknown>`.
196
- *
197
- * Widening the row to `M & QueryComputedFields` broke this in seven places in
198
- * one downstream app, because `QueryComputedFields` was first written as an
199
- * `interface`: TypeScript grants an implicit index signature to a type alias
200
- * and withholds it from an interface, so the intersection stopped overlapping
201
- * with `Record<string, unknown>` and every `as Record<string, unknown>` cast
202
- * became an error. Nothing in this repo casts a row that way, which is why
203
- * nothing here noticed.
204
- */
205
- export const rowStaysIndexable = (result: FindResult<ContractRow>) =>
206
- result.data.map(row => row as Record<string, unknown>);
@@ -1 +0,0 @@
1
- export { QueryBuilder, or, and, cond } from "@rebasepro/common";