@syncular/core 0.67.3 → 0.69.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/dist/message.d.ts +7 -0
- package/dist/message.js +2 -1
- package/dist/row-codec.js +5 -4
- package/package.json +1 -1
- package/src/message.ts +5 -2
- package/src/row-codec.ts +11 -8
package/dist/message.d.ts
CHANGED
|
@@ -229,6 +229,13 @@ export interface ResponseMessage {
|
|
|
229
229
|
frames: ResponseFrame[];
|
|
230
230
|
}
|
|
231
231
|
export type SyncMessage = RequestMessage | ResponseMessage;
|
|
232
|
+
export type DefinedObject<T> = {
|
|
233
|
+
[K in keyof T as undefined extends T[K] ? never : K]: T[K];
|
|
234
|
+
} & {
|
|
235
|
+
[K in keyof T as undefined extends T[K] ? K : never]?: Exclude<T[K], undefined>;
|
|
236
|
+
};
|
|
237
|
+
/** Drops `undefined` members in place, typed as optional properties. */
|
|
238
|
+
export declare function definedObject<const T extends object>(record: T): DefinedObject<T>;
|
|
232
239
|
/** §1.5: `code` is a legal `ROUND_FAILURE` code (grammar and byte length). */
|
|
233
240
|
export declare function isRoundFailureCode(code: string): boolean;
|
|
234
241
|
export declare function encodeRequest(message: RequestMessage): Uint8Array;
|
package/dist/message.js
CHANGED
|
@@ -19,7 +19,8 @@ import { FrameType, KNOWN_FRAME_TYPES, REQUEST_FRAME_TYPES, RESPONSE_FRAME_TYPES
|
|
|
19
19
|
import { normalizeRejectionDetails, } from './rejection-details.js';
|
|
20
20
|
import { decodeRowsSegment } from './segment.js';
|
|
21
21
|
const MAGIC_BYTES = utf8Encode(SYNC_PACK_MAGIC);
|
|
22
|
-
|
|
22
|
+
/** Drops `undefined` members in place, typed as optional properties. */
|
|
23
|
+
export function definedObject(record) {
|
|
23
24
|
for (const key of Object.keys(record)) {
|
|
24
25
|
if (record[key] === undefined)
|
|
25
26
|
delete record[key];
|
package/dist/row-codec.js
CHANGED
|
@@ -127,9 +127,7 @@ function bitmapBit(bitmap, index) {
|
|
|
127
127
|
* encoder misuse and throws, like a NULL in a non-nullable column.
|
|
128
128
|
*/
|
|
129
129
|
export function encodeSparseRow(columns, primaryKeyIndex, values) {
|
|
130
|
-
|
|
131
|
-
throw new Error(`row value count ${values.length} does not match column count ${columns.length}`);
|
|
132
|
-
}
|
|
130
|
+
requireColumnCount(columns, values);
|
|
133
131
|
const presence = new Uint8Array(Math.ceil(columns.length / 8));
|
|
134
132
|
let presentCount = 0;
|
|
135
133
|
for (let i = 0; i < columns.length; i++) {
|
|
@@ -250,10 +248,13 @@ export function decodeSparseRow(columns, primaryKeyIndex, bytes) {
|
|
|
250
248
|
reader.expectFullyConsumed('sparse row payload');
|
|
251
249
|
return values;
|
|
252
250
|
}
|
|
253
|
-
|
|
251
|
+
function requireColumnCount(columns, values) {
|
|
254
252
|
if (values.length !== columns.length) {
|
|
255
253
|
throw new Error(`row value count ${values.length} does not match column count ${columns.length}`);
|
|
256
254
|
}
|
|
255
|
+
}
|
|
256
|
+
export function writeRow(writer, columns, values) {
|
|
257
|
+
requireColumnCount(columns, values);
|
|
257
258
|
const bitmapLength = Math.ceil(columns.length / 8);
|
|
258
259
|
const bitmap = new Uint8Array(bitmapLength);
|
|
259
260
|
for (let i = 0; i < columns.length; i++) {
|
package/package.json
CHANGED
package/src/message.ts
CHANGED
|
@@ -313,7 +313,7 @@ export interface ResponseMessage {
|
|
|
313
313
|
|
|
314
314
|
export type SyncMessage = RequestMessage | ResponseMessage;
|
|
315
315
|
|
|
316
|
-
type DefinedObject<T> = {
|
|
316
|
+
export type DefinedObject<T> = {
|
|
317
317
|
[K in keyof T as undefined extends T[K] ? never : K]: T[K];
|
|
318
318
|
} & {
|
|
319
319
|
[K in keyof T as undefined extends T[K] ? K : never]?: Exclude<
|
|
@@ -321,7 +321,10 @@ type DefinedObject<T> = {
|
|
|
321
321
|
undefined
|
|
322
322
|
>;
|
|
323
323
|
};
|
|
324
|
-
|
|
324
|
+
/** Drops `undefined` members in place, typed as optional properties. */
|
|
325
|
+
export function definedObject<const T extends object>(
|
|
326
|
+
record: T,
|
|
327
|
+
): DefinedObject<T> {
|
|
325
328
|
for (const key of Object.keys(record) as (keyof T)[]) {
|
|
326
329
|
if (record[key] === undefined) delete record[key];
|
|
327
330
|
}
|
package/src/row-codec.ts
CHANGED
|
@@ -208,11 +208,7 @@ export function encodeSparseRow(
|
|
|
208
208
|
primaryKeyIndex: number,
|
|
209
209
|
values: readonly SparseRowValue[],
|
|
210
210
|
): Uint8Array {
|
|
211
|
-
|
|
212
|
-
throw new Error(
|
|
213
|
-
`row value count ${values.length} does not match column count ${columns.length}`,
|
|
214
|
-
);
|
|
215
|
-
}
|
|
211
|
+
requireColumnCount(columns, values);
|
|
216
212
|
const presence = new Uint8Array(Math.ceil(columns.length / 8));
|
|
217
213
|
let presentCount = 0;
|
|
218
214
|
for (let i = 0; i < columns.length; i++) {
|
|
@@ -365,16 +361,23 @@ export function decodeSparseRow(
|
|
|
365
361
|
return values;
|
|
366
362
|
}
|
|
367
363
|
|
|
368
|
-
|
|
369
|
-
writer: ByteWriter,
|
|
364
|
+
function requireColumnCount(
|
|
370
365
|
columns: readonly RowColumn[],
|
|
371
|
-
values: readonly
|
|
366
|
+
values: readonly unknown[],
|
|
372
367
|
): void {
|
|
373
368
|
if (values.length !== columns.length) {
|
|
374
369
|
throw new Error(
|
|
375
370
|
`row value count ${values.length} does not match column count ${columns.length}`,
|
|
376
371
|
);
|
|
377
372
|
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export function writeRow(
|
|
376
|
+
writer: ByteWriter,
|
|
377
|
+
columns: readonly RowColumn[],
|
|
378
|
+
values: readonly RowValue[],
|
|
379
|
+
): void {
|
|
380
|
+
requireColumnCount(columns, values);
|
|
378
381
|
const bitmapLength = Math.ceil(columns.length / 8);
|
|
379
382
|
const bitmap = new Uint8Array(bitmapLength);
|
|
380
383
|
for (let i = 0; i < columns.length; i++) {
|