Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@electric-sql/client

Package Overview
Dependencies
Maintainers
3
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@electric-sql/client - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

35

dist/index.d.ts

@@ -22,43 +22,44 @@ type Value = string | number | boolean | bigint | null | Value[] | {

}> = ControlMessage | ChangeMessage<T>;
/**
* Common properties for all columns.
* `dims` is the number of dimensions of the column. Only provided if the column is an array.
* `not_null` is true if the column has a `NOT NULL` constraint and is omitted otherwise.
*/
type CommonColumnProps = {
dims?: number;
not_null?: boolean;
};
type RegularColumn = {
type: string;
dims: number;
};
} & CommonColumnProps;
type VarcharColumn = {
type: `varchar`;
dims: number;
max_length?: number;
};
} & CommonColumnProps;
type BpcharColumn = {
type: `bpchar`;
dims: number;
length?: number;
};
} & CommonColumnProps;
type TimeColumn = {
type: `time` | `timetz` | `timestamp` | `timestamptz`;
dims: number;
precision?: number;
};
} & CommonColumnProps;
type IntervalColumn = {
type: `interval`;
dims: number;
fields?: `YEAR` | `MONTH` | `DAY` | `HOUR` | `MINUTE` | `YEAR TO MONTH` | `DAY TO HOUR` | `DAY TO MINUTE` | `DAY TO SECOND` | `HOUR TO MINUTE` | `HOUR TO SECOND` | `MINUTE TO SECOND`;
};
} & CommonColumnProps;
type IntervalColumnWithPrecision = {
type: `interval`;
dims: number;
precision?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
fields?: `SECOND`;
};
} & CommonColumnProps;
type BitColumn = {
type: `bit`;
dims: number;
length: number;
};
} & CommonColumnProps;
type NumericColumn = {
type: `numeric`;
dims: number;
precision?: number;
scale?: number;
};
} & CommonColumnProps;
type ColumnInfo = RegularColumn | VarcharColumn | BpcharColumn | TimeColumn | IntervalColumn | IntervalColumnWithPrecision | BitColumn | NumericColumn;

@@ -244,2 +245,2 @@ type Schema = {

export { BackoffDefaults, type BackoffOptions, type BitColumn, type BpcharColumn, type ChangeMessage, type ColumnInfo, type ControlMessage, FetchError, type IntervalColumn, type IntervalColumnWithPrecision, type Message, type NumericColumn, type Offset, type RegularColumn, type Schema, Shape, type ShapeChangedCallback, type ShapeData, ShapeStream, type ShapeStreamOptions, type TimeColumn, type TypedMessages, type Value, type VarcharColumn };
export { BackoffDefaults, type BackoffOptions, type BitColumn, type BpcharColumn, type ChangeMessage, type ColumnInfo, type CommonColumnProps, type ControlMessage, FetchError, type IntervalColumn, type IntervalColumnWithPrecision, type Message, type NumericColumn, type Offset, type RegularColumn, type Schema, Shape, type ShapeChangedCallback, type ShapeData, ShapeStream, type ShapeStreamOptions, type TimeColumn, type TypedMessages, type Value, type VarcharColumn };

@@ -105,2 +105,3 @@ var __defProp = Object.defineProperty;

parseRow(key, value, schema) {
var _b;
const columnInfo = schema[key];

@@ -110,14 +111,19 @@ if (!columnInfo) {

}
const parser = this.parser[columnInfo.type];
const _a = columnInfo, { type: _typ, dims: dimensions } = _a, additionalInfo = __objRest(_a, ["type", "dims"]);
if (dimensions > 0) {
const identityParser = (v) => v;
return pgArrayParser(value, parser != null ? parser : identityParser);
const _a = columnInfo, { type: typ, dims: dimensions } = _a, additionalInfo = __objRest(_a, ["type", "dims"]);
const identityParser = (v) => v;
const typParser = (_b = this.parser[typ]) != null ? _b : identityParser;
const parser = makeNullableParser(typParser, columnInfo.not_null);
if (dimensions && dimensions > 0) {
return pgArrayParser(value, parser);
}
if (!parser) {
return value;
}
return parser(value, additionalInfo);
}
};
function makeNullableParser(parser, notNullable) {
const isNullable = !(notNullable != null ? notNullable : false);
if (isNullable) {
return (value) => value === null || value === `NULL` ? null : parser(value);
}
return parser;
}

@@ -124,0 +130,0 @@ // src/client.ts

{
"name": "@electric-sql/client",
"version": "0.3.0",
"version": "0.3.1",
"description": "Postgres everywhere - your data, in sync, wherever you need it.",

@@ -5,0 +5,0 @@ "type": "module",

@@ -111,21 +111,34 @@ import { ColumnInfo, Message, Schema, Value } from './types'

// Copy the object but don't include `dimensions` and `type`
const { type: typ, dims: dimensions, ...additionalInfo } = columnInfo
// Pick the right parser for the type
const parser = this.parser[columnInfo.type]
// and support parsing null values if needed
// if no parser is provided for the given type, just return the value as is
const identityParser = (v: string) => v
const typParser = this.parser[typ] ?? identityParser
const parser = makeNullableParser(typParser, columnInfo.not_null)
// Copy the object but don't include `dimensions` and `type`
const { type: _typ, dims: dimensions, ...additionalInfo } = columnInfo
if (dimensions > 0) {
if (dimensions && dimensions > 0) {
// It's an array
const identityParser = (v: string) => v
return pgArrayParser(value, parser ?? identityParser)
return pgArrayParser(value, parser)
}
if (!parser) {
// No parser was provided for this type of values
return value
}
return parser(value, additionalInfo)
}
}
function makeNullableParser(
parser: ParseFunction,
notNullable?: boolean
): ParseFunction {
const isNullable = !(notNullable ?? false)
if (isNullable) {
// The sync service contains `null` value for a column whose value is NULL
// but if the column value is an array that contains a NULL value
// then it will be included in the array string as `NULL`, e.g.: `"{1,NULL,3}"`
return (value: string) =>
value === null || value === `NULL` ? null : parser(value)
}
return parser
}

@@ -32,28 +32,33 @@ export type Value =

/**
* Common properties for all columns.
* `dims` is the number of dimensions of the column. Only provided if the column is an array.
* `not_null` is true if the column has a `NOT NULL` constraint and is omitted otherwise.
*/
export type CommonColumnProps = {
dims?: number
not_null?: boolean
}
export type RegularColumn = {
type: string
dims: number
}
} & CommonColumnProps
export type VarcharColumn = {
type: `varchar`
dims: number
max_length?: number
}
} & CommonColumnProps
export type BpcharColumn = {
type: `bpchar`
dims: number
length?: number
}
} & CommonColumnProps
export type TimeColumn = {
type: `time` | `timetz` | `timestamp` | `timestamptz`
dims: number
precision?: number
}
} & CommonColumnProps
export type IntervalColumn = {
type: `interval`
dims: number
fields?:

@@ -72,23 +77,20 @@ | `YEAR`

| `MINUTE TO SECOND`
}
} & CommonColumnProps
export type IntervalColumnWithPrecision = {
type: `interval`
dims: number
precision?: 0 | 1 | 2 | 3 | 4 | 5 | 6
fields?: `SECOND`
}
} & CommonColumnProps
export type BitColumn = {
type: `bit`
dims: number
length: number
}
} & CommonColumnProps
export type NumericColumn = {
type: `numeric`
dims: number
precision?: number
scale?: number
}
} & CommonColumnProps

@@ -95,0 +97,0 @@ export type ColumnInfo =

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc