@olivia-db/client 0.1.0 → 0.1.2

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/index.ts CHANGED
@@ -211,6 +211,15 @@ export class OliviaDbClient {
211
211
  return (t ? JSON.parse(t) : {}) as T;
212
212
  }
213
213
 
214
+ /**
215
+ * Any route of the network API: `path` from `/v1`, with its query, already encoded. The
216
+ * answer's JSON; a failure throws OliviaDbError after the client's retries and failover.
217
+ * The typed models and queries (`@olivia-db/client/dsl`) send their requests through it.
218
+ */
219
+ request<T = Json>(method: string, path: string, body?: object): Promise<T> {
220
+ return this.json<T>(method, path, body);
221
+ }
222
+
214
223
  remember(a: RememberArgs): Promise<Json> {
215
224
  return this.json("POST", "/v1/memory/remember", a);
216
225
  }
package/src/native.ts CHANGED
@@ -204,6 +204,9 @@ export interface Field {
204
204
  shown: number;
205
205
  /** A variant case's discriminator and values, when the field belongs to one. */
206
206
  caseOf?: { disc: number; values: string[] };
207
+ /** The type as the descriptor writes it (`string(80)`, `decimal(18,2)`, the canonical JSON
208
+ * of an enum or a reference). */
209
+ typeText?: string;
207
210
  }
208
211
 
209
212
  export interface KeyPart {
@@ -265,10 +268,14 @@ export class Desc {
265
268
  }
266
269
 
267
270
  function readField(r: Rd): Field {
271
+ const number = r.varint();
272
+ const name = r.str();
273
+ const typeText = r.str();
268
274
  return {
269
- number: r.varint(),
270
- name: r.str(),
271
- type: parseType(r.str()),
275
+ number,
276
+ name,
277
+ typeText,
278
+ type: parseType(typeText),
272
279
  tail: r.u8() === 1,
273
280
  offset: r.varint(),
274
281
  length: r.varint(),
@@ -915,6 +922,10 @@ export class NativeClient {
915
922
  private streams = new Map<number, Queue<Received>>();
916
923
  private nextStream = 3;
917
924
  private descs: Descs = new Map();
925
+ /** The fields of every writer layout a descriptor of this connection described, by layout
926
+ * id: [number, name, type text] each (typed code reads a node of an older layout by them;
927
+ * never dropped, a few hundred bytes per layout). */
928
+ private layouts = new Map<string, Array<[number, string, string]>>();
918
929
  private buf = new Uint8Array(0);
919
930
  private closedWhy: string | undefined;
920
931
  private handshake: Queue<[number, Uint8Array]> | undefined = new Queue();
@@ -1005,7 +1016,7 @@ export class NativeClient {
1005
1016
  const hello: number[] = [0, 1, 0, 1];
1006
1017
  putVarint(hello, 1);
1007
1018
  putLp(hello, enc.encode("client"));
1008
- putLp(hello, enc.encode("oliviadb-js 0.1.0"));
1019
+ putLp(hello, enc.encode("oliviadb-js 0.1.2"));
1009
1020
  const auth: number[] = [];
1010
1021
  putLp(auth, enc.encode(scheme));
1011
1022
  putLp(auth, enc.encode(credential));
@@ -1063,6 +1074,11 @@ export class NativeClient {
1063
1074
  }
1064
1075
  if (op === OP.DESCRIBE) {
1065
1076
  const [id, d] = describe(body);
1077
+ if (!this.layouts.has(d.layout))
1078
+ this.layouts.set(
1079
+ d.layout,
1080
+ d.fields.map((f): [number, string, string] => [f.number, f.name, f.typeText ?? ""]),
1081
+ );
1066
1082
  const m = new Map(this.descs);
1067
1083
  m.set(id, d);
1068
1084
  this.descs = m;
@@ -1202,6 +1218,12 @@ export class NativeClient {
1202
1218
  }
1203
1219
  }
1204
1220
 
1221
+ /** The fields of a writer layout a descriptor of this connection described: [number, name,
1222
+ * type text] each, the fixed, variant-case and tail fields (spec native-protocol.md 5). */
1223
+ layoutFields(id: string): ReadonlyArray<readonly [number, string, string]> | undefined {
1224
+ return this.layouts.get(id);
1225
+ }
1226
+
1205
1227
  close(): void {
1206
1228
  this.sock.destroy();
1207
1229
  }