New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

litdb

Package Overview
Dependencies
Maintainers
0
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

litdb - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

348

dist/index.d.ts
// Generated by dts-bundle-generator v9.5.1
export type ConstructorsToRefs<T extends Constructor<any>[]> = {
[K in keyof T]: TypeRef<InstanceType<T[K]>>;
};
export type First<T extends readonly any[]> = T extends [
infer F,
...any[]
] ? F extends Constructor<any> ? F : never : never;
export type Last<T extends readonly any[]> = T extends [
...any[],
infer L
] ? L extends Constructor<any> ? L : never : never;
export type ScalarValue = string | bigint | number | boolean | null | symbol;
export type DbBinding = string | bigint | NodeJS.TypedArray | number | boolean | null | Record<string, string | bigint | NodeJS.TypedArray | number | boolean | null>;
export interface ReflectMeta {
name: string;
$id: symbol;
$type: {
name: string;
table?: TableDefinition;
};
$props: [
{
name: string;
column?: ColumnDefinition;
}
];
}
export type Constructor<T = any> = new (...args: any[]) => T;
export type ClassParam = ReflectMeta | {
constructor: ReflectMeta;
} | Constructor<any>;
export type ClassInstance = {
constructor: ReflectMeta;
} & Record<string, any> | Record<string, any>;
export interface TableDefinition {
name: string;
alias?: string;
}
export interface ColumnDefinition {
name: string;
alias?: string;
type: string;
primaryKey?: boolean;
autoIncrement?: boolean;
required?: boolean;
precision?: number;
scale?: number;
unique?: boolean;
index?: boolean;
defaultValue?: string;
}
export interface Statement<ReturnType, ParamsType extends DbBinding[]> {
get native(): any;
all(...params: ParamsType): Promise<ReturnType[]>;
allSync(...params: ParamsType): ReturnType[];
first(...params: ParamsType): Promise<ReturnType | null>;
firstSync(...params: ParamsType): ReturnType | null;
column<ReturnValue>(...params: ParamsType): Promise<ReturnValue[]>;
columnSync<ReturnValue>(...params: ParamsType): ReturnValue[];
scalar<ReturnValue>(...params: ParamsType): Promise<ReturnValue | null>;
scalarSync<ReturnValue>(...params: ParamsType): ReturnValue | null;
arrays(...params: ParamsType): Promise<any[][]>;
arraysSync(...params: ParamsType): any[][];
array(...params: ParamsType): Promise<any[] | null>;
arraySync(...params: ParamsType): any[] | null;
exec(...params: ParamsType): Promise<{
changes: number;
lastInsertRowid: number | bigint;
}>;
execSync(...params: ParamsType): {
changes: number;
lastInsertRowid: number | bigint;
};
}
export interface TypeConverter {
toDb(value: any): any;
fromDb(value: any): any;
}
export interface Driver {
get $(): any;
get name(): string;
get async(): Connection;
get sync(): SyncConnection | undefined;
get converters(): {
[key: string]: TypeConverter;
};
quote(name: string): string;
quoteTable(name: string): string;
quoteColumn(name: string): string;
sqlColumnDefinition(column: ColumnDefinition): string;
sqlIndexDefinition(table: TableDefinition, column: ColumnDefinition): string;
sqlTableNames(schema?: string): string;
sqlLimit(skip?: number, take?: number): string;
prepareRaw<ReturnType, ParamsType extends DbBinding[]>(sql: String): Statement<ReturnType, ParamsType extends any[] ? ParamsType : [
ParamsType
]>;
prepare<ReturnType, ParamsType extends DbBinding[]>(strings: TemplateStringsArray, ...params: DbBinding[]): Statement<ReturnType, ParamsType extends any[] ? ParamsType : [
ParamsType
]>;
}
export type Fragment = {
sql: string;
params?: Record<string, any>;
};
export interface SqlBuilder {
build(): {
sql: string;
params: Record<string, any>;
};
}
export type WhereOptions = {
equals?: Record<string, ScalarValue>;
notEquals?: Record<string, ScalarValue>;
like?: Record<string, ScalarValue>;
notLike?: Record<string, ScalarValue>;
startsWith?: Record<string, ScalarValue>;
endsWith?: Record<string, ScalarValue>;
contains?: Record<string, ScalarValue>;
in?: Record<string, ScalarValue[]>;
notIn?: Record<string, ScalarValue[]>;
isNull?: string[];
notNull?: string[];
op?: [
string,
Record<string, any>
];
sql?: Fragment | Fragment[];
rawSql?: string | string[];
params?: Record<string, any>;
};
export type TypeRef<T> = T & {
$ref: {
cls: Constructor<T>;
as?: string;
};
};
export type ConstructorToTypeRef<T extends readonly any[]> = {
[K in keyof T]: T[K] extends new (...args: any[]) => infer R ? TypeRef<R> : never;
};
export type JoinType = "JOIN" | "INNER JOIN" | "LEFT JOIN" | "RIGHT JOIN" | "OUTER JOIN" | "FULL JOIN" | "CROSS JOIN";
export type TypeRefs<Tables extends Constructor<any>[]> = {
[K in keyof Tables]: TypeRef<InstanceType<Tables[K]>>;
};
export type JoinDefinition = {
type: JoinType;
table: string;
on?: string;
as?: string;
params?: Record<string, any>;
};
export interface JoinBuilder<Table extends Constructor<any>> {
get table(): Table;
get tables(): Constructor<any>[];
build(refs: ConstructorsToRefs<any>, type: JoinType): JoinDefinition;
}
export declare class Sql {

@@ -456,2 +301,158 @@ static ops: {

}
export type ConstructorsToRefs<T extends Constructor<any>[]> = {
[K in keyof T]: TypeRef<InstanceType<T[K]>>;
};
export type First<T extends readonly any[]> = T extends [
infer F,
...any[]
] ? F extends Constructor<any> ? F : never : never;
export type Last<T extends readonly any[]> = T extends [
...any[],
infer L
] ? L extends Constructor<any> ? L : never : never;
export type ScalarValue = string | bigint | number | boolean | null | symbol;
export type DbBinding = string | bigint | NodeJS.TypedArray | number | boolean | null | Record<string, string | bigint | NodeJS.TypedArray | number | boolean | null>;
export interface ReflectMeta {
name: string;
$id: symbol;
$type: {
name: string;
table?: TableDefinition;
};
$props: [
{
name: string;
column?: ColumnDefinition;
}
];
}
export type ColumnType = "INTEGER" | "SMALLINT" | "BIGINT" | "DECIMAL" | "NUMERIC" | "REAL" | "FLOAT" | "DOUBLE" | "MONEY" | "DATE" | "DATETIME" | "TIME" | "TIMEZ" | "TIMESTAMP" | "TIMESTAMPZ" | "INTERVAL" | "BOOLEAN" | "UUID" | "BLOB" | "BYTES" | "BIT" | "TEXT" | "VARCHAR" | "NVARCHAR" | "CHAR" | "NCHAR" | "JSON" | "JSONB" | "XML";
export type Constructor<T = any> = new (...args: any[]) => T;
export type ClassParam = ReflectMeta | {
constructor: ReflectMeta;
} | Constructor<any>;
export type ClassInstance = {
constructor: ReflectMeta;
} & Record<string, any> | Record<string, any>;
export interface TableDefinition {
name: string;
alias?: string;
}
export interface ColumnDefinition {
name: string;
alias?: string;
type: string;
primaryKey?: boolean;
autoIncrement?: boolean;
required?: boolean;
precision?: number;
scale?: number;
unique?: boolean;
index?: boolean;
defaultValue?: string;
}
export interface Statement<ReturnType, ParamsType extends DbBinding[]> {
get native(): any;
all(...params: ParamsType): Promise<ReturnType[]>;
allSync(...params: ParamsType): ReturnType[];
first(...params: ParamsType): Promise<ReturnType | null>;
firstSync(...params: ParamsType): ReturnType | null;
column<ReturnValue>(...params: ParamsType): Promise<ReturnValue[]>;
columnSync<ReturnValue>(...params: ParamsType): ReturnValue[];
scalar<ReturnValue>(...params: ParamsType): Promise<ReturnValue | null>;
scalarSync<ReturnValue>(...params: ParamsType): ReturnValue | null;
arrays(...params: ParamsType): Promise<any[][]>;
arraysSync(...params: ParamsType): any[][];
array(...params: ParamsType): Promise<any[] | null>;
arraySync(...params: ParamsType): any[] | null;
exec(...params: ParamsType): Promise<{
changes: number;
lastInsertRowid: number | bigint;
}>;
execSync(...params: ParamsType): {
changes: number;
lastInsertRowid: number | bigint;
};
}
export interface TypeConverter {
toDb(value: any): any;
fromDb(value: any): any;
}
export interface Driver {
get $(): any;
get name(): string;
get async(): Connection;
get sync(): SyncConnection | undefined;
get converters(): {
[key: string]: TypeConverter;
};
quote(name: string): string;
quoteTable(name: string): string;
quoteColumn(name: string): string;
sqlColumnDefinition(column: ColumnDefinition): string;
sqlIndexDefinition(table: TableDefinition, column: ColumnDefinition): string;
sqlTableNames(schema?: string): string;
sqlLimit(skip?: number, take?: number): string;
prepareRaw<ReturnType, ParamsType extends DbBinding[]>(sql: String): Statement<ReturnType, ParamsType extends any[] ? ParamsType : [
ParamsType
]>;
prepare<ReturnType, ParamsType extends DbBinding[]>(strings: TemplateStringsArray, ...params: DbBinding[]): Statement<ReturnType, ParamsType extends any[] ? ParamsType : [
ParamsType
]>;
}
export type Fragment = {
sql: string;
params?: Record<string, any>;
};
export interface SqlBuilder {
build(): {
sql: string;
params: Record<string, any>;
};
}
export type WhereOptions = {
equals?: Record<string, ScalarValue>;
notEquals?: Record<string, ScalarValue>;
like?: Record<string, ScalarValue>;
notLike?: Record<string, ScalarValue>;
startsWith?: Record<string, ScalarValue>;
endsWith?: Record<string, ScalarValue>;
contains?: Record<string, ScalarValue>;
in?: Record<string, ScalarValue[]>;
notIn?: Record<string, ScalarValue[]>;
isNull?: string[];
notNull?: string[];
op?: [
string,
Record<string, any>
];
sql?: Fragment | Fragment[];
rawSql?: string | string[];
params?: Record<string, any>;
};
export type TypeRef<T> = T & {
$ref: {
cls: Constructor<T>;
as?: string;
};
};
export type ConstructorToTypeRef<T extends readonly any[]> = {
[K in keyof T]: T[K] extends new (...args: any[]) => infer R ? TypeRef<R> : never;
};
export type JoinType = "JOIN" | "INNER JOIN" | "LEFT JOIN" | "RIGHT JOIN" | "OUTER JOIN" | "FULL JOIN" | "CROSS JOIN";
export type TypeRefs<Tables extends Constructor<any>[]> = {
[K in keyof Tables]: TypeRef<InstanceType<Tables[K]>>;
};
export type JoinDefinition = {
type: JoinType;
table: string;
on?: string;
as?: string;
params?: Record<string, any>;
};
export interface JoinBuilder<Table extends Constructor<any>> {
get table(): Table;
get tables(): Constructor<any>[];
build(refs: ConstructorsToRefs<any>, type: JoinType): JoinDefinition;
}
export declare class Inspect {

@@ -471,2 +472,39 @@ static dump(obj: any): string;

}
export declare function table(options?: {
alias?: string;
}): (target: any) => void;
export declare function column(type: ColumnType | symbol, options?: {
alias?: string;
primaryKey?: boolean;
autoIncrement?: boolean;
required?: boolean;
precision?: number;
scale?: number;
unique?: boolean;
index?: boolean;
defaultValue?: string;
}): (target: any, propertyKey: string) => void;
export declare function Table<T extends Constructor<any>>(cls: new () => T, definition: TableDefinition$1<T>): new () => T;
interface TableDefinition$1<T> {
table?: TableConfig;
columns: ColumnsConfig<T>;
}
export interface TableConfig {
alias?: string;
}
export interface ColumnConfig {
alias?: string;
type: ColumnType | symbol;
primaryKey?: boolean;
autoIncrement?: boolean;
required?: boolean;
precision?: number;
scale?: number;
unique?: boolean;
index?: boolean;
defaultValue?: string;
}
export type ColumnsConfig<T> = {
[K in keyof Partial<T>]: ColumnConfig;
};
export declare enum DataType {

@@ -473,0 +511,0 @@ INTEGER = "INTEGER",

@@ -1045,2 +1045,59 @@ // src/query.ts

// src/model.ts
function table(options) {
return function(target) {
const table2 = Object.assign({}, options, { name: options?.alias ?? target.name });
if (!target.$id)
target.$id = Symbol(target.name);
target.$type ??= { name: target.name };
target.$type.table = table2;
};
}
function column(type, options) {
return function(target, propertyKey) {
const column2 = Object.assign({}, options, { type, name: options?.alias ?? propertyKey });
if (propertyKey === "id")
column2.primaryKey = true;
if (!target.constructor.$id)
target.constructor.$id = Symbol(target.constructor.name);
const props = target.constructor.$props ?? (target.constructor.$props = []);
let prop = props.find((x) => x.name === propertyKey);
if (!prop) {
prop = { name: propertyKey };
props.push(prop);
}
prop.column = column2;
if (typeof prop.column.type == "symbol") {
prop.column.type = prop.column.type.description;
}
};
}
function Table(cls, definition) {
if (!definition)
throw new Error("Table definition is required");
const meta = cls;
if (!meta.$id)
meta.$id = Symbol(cls.name);
meta.$type ??= { name: cls.name };
meta.$type.table = definition.table ?? {};
meta.$type.table.name ??= cls.name;
const props = meta.$props ?? (meta.$props = []);
Object.keys(definition.columns).forEach((name) => {
const column2 = definition.columns[name];
if (!column2)
throw new Error(`Column definition for ${name} is missing`);
if (!column2.type)
throw new Error(`Column type for ${name} is missing`);
let prop = props.find((x) => x.name === name);
if (!prop) {
prop = { name };
props.push(prop);
}
prop.column = column2;
prop.column.name ??= column2.alias ?? name;
if (typeof prop.column.type == "symbol") {
prop.column.type = prop.column.type.description;
}
});
return cls;
}
var DataType;

@@ -1086,4 +1143,7 @@ (function(DataType2) {

export {
table,
converterFor,
column,
WhereQuery,
Table,
SyncConnection,

@@ -1090,0 +1150,0 @@ Sql,

{
"name": "litdb",
"type": "module",
"version": "0.0.2",
"version": "0.0.3",
"main": "./dist/index.cjs",

@@ -30,8 +30,8 @@ "module": "./dist/index.js",

"license": "BSD-3-Clause",
"homepage": "https://github.com/litdb/db",
"homepage": "https://github.com/litdb/litdb",
"repository": {
"type": "git",
"url": "git+https://github.com/litdb/db.git"
"url": "git+https://github.com/litdb/litdb.git"
},
"bugs": "https://github.com/litdb/db/issues",
"bugs": "https://github.com/litdb/litdb/issues",
"author": "Demis Bellot <https://github.com/mythz>",

@@ -38,0 +38,0 @@ "devDependencies": {

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