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

@supabase/postgrest-js

Package Overview
Dependencies
Maintainers
5
Versions
135
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@supabase/postgrest-js - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

8

dist/main/PostgrestClient.d.ts

@@ -38,5 +38,5 @@ import PostgrestQueryBuilder from './PostgrestQueryBuilder';

*/
from<TableName extends string & keyof Schema['Tables'], Table extends Schema['Tables'][TableName]>(relation: TableName): PostgrestQueryBuilder<Table>;
from<ViewName extends string & keyof Schema['Views'], View extends Schema['Views'][ViewName]>(relation: ViewName): PostgrestQueryBuilder<View>;
from(relation: string): PostgrestQueryBuilder<any>;
from<TableName extends string & keyof Schema['Tables'], Table extends Schema['Tables'][TableName]>(relation: TableName): PostgrestQueryBuilder<Schema, Table>;
from<ViewName extends string & keyof Schema['Views'], View extends Schema['Views'][ViewName]>(relation: ViewName): PostgrestQueryBuilder<Schema, View>;
from(relation: string): PostgrestQueryBuilder<Schema, any>;
/**

@@ -66,4 +66,4 @@ * Perform a function call.

count?: 'exact' | 'planned' | 'estimated';
}): PostgrestFilterBuilder<Function_['Returns'] extends any[] ? Function_['Returns'][number] extends Record<string, unknown> ? Function_['Returns'][number] : never : never, Function_['Returns']>;
}): PostgrestFilterBuilder<Schema, Function_['Returns'] extends any[] ? Function_['Returns'][number] extends Record<string, unknown> ? Function_['Returns'][number] : never : never, Function_['Returns']>;
}
//# sourceMappingURL=PostgrestClient.d.ts.map
import PostgrestTransformBuilder from './PostgrestTransformBuilder';
import { GenericSchema } from './types';
declare type FilterOperator = 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'like' | 'ilike' | 'is' | 'in' | 'cs' | 'cd' | 'sl' | 'sr' | 'nxl' | 'nxr' | 'adj' | 'ov' | 'fts' | 'plfts' | 'phfts' | 'wfts';
export default class PostgrestFilterBuilder<Row extends Record<string, unknown>, Result> extends PostgrestTransformBuilder<Row, Result> {
export default class PostgrestFilterBuilder<Schema extends GenericSchema, Row extends Record<string, unknown>, Result> extends PostgrestTransformBuilder<Schema, Row, Result> {
/**

@@ -5,0 +6,0 @@ * Match only rows where `column` is equal to `value`.

import PostgrestFilterBuilder from './PostgrestFilterBuilder';
import { GetResult } from './select-query-parser';
import { Fetch, GenericTable, GenericView } from './types';
export default class PostgrestQueryBuilder<Relation extends GenericTable | GenericView> {
import { Fetch, GenericSchema, GenericTable, GenericView } from './types';
export default class PostgrestQueryBuilder<Schema extends GenericSchema, Relation extends GenericTable | GenericView> {
url: URL;

@@ -36,6 +36,6 @@ headers: Record<string, string>;

*/
select<Query extends string = '*', Result = GetResult<Relation['Row'], Query extends '*' ? '*' : Query>>(columns?: Query, { head, count, }?: {
select<Query extends string = '*', Result = GetResult<Schema, Relation['Row'], Query>>(columns?: Query, { head, count, }?: {
head?: boolean;
count?: 'exact' | 'planned' | 'estimated';
}): PostgrestFilterBuilder<Relation['Row'], Result>;
}): PostgrestFilterBuilder<Schema, Relation['Row'], Result>;
/**

@@ -67,3 +67,3 @@ * Perform an INSERT into the table or view.

count?: 'exact' | 'planned' | 'estimated';
}): PostgrestFilterBuilder<Relation['Row'], undefined>;
}): PostgrestFilterBuilder<Schema, Relation['Row'], undefined>;
/**

@@ -108,3 +108,3 @@ * Perform an UPSERT on the table or view. Depending on the column(s) passed

count?: 'exact' | 'planned' | 'estimated';
}): PostgrestFilterBuilder<Relation['Row'], undefined>;
}): PostgrestFilterBuilder<Schema, Relation['Row'], undefined>;
/**

@@ -135,3 +135,3 @@ * Perform an UPDATE on the table or view.

count?: 'exact' | 'planned' | 'estimated';
}): PostgrestFilterBuilder<Relation['Row'], undefined>;
}): PostgrestFilterBuilder<Schema, Relation['Row'], undefined>;
/**

@@ -158,4 +158,4 @@ * Perform a DELETE on the table or view.

count?: 'exact' | 'planned' | 'estimated';
}): PostgrestFilterBuilder<Relation['Row'], undefined>;
}): PostgrestFilterBuilder<Schema, Relation['Row'], undefined>;
}
//# sourceMappingURL=PostgrestQueryBuilder.d.ts.map
import PostgrestBuilder from './PostgrestBuilder';
import { GetResult } from './select-query-parser';
import { PostgrestMaybeSingleResponse, PostgrestResponse, PostgrestSingleResponse } from './types';
export default class PostgrestTransformBuilder<Row extends Record<string, unknown>, Result> extends PostgrestBuilder<Result> {
import { GenericSchema, PostgrestMaybeSingleResponse, PostgrestResponse, PostgrestSingleResponse } from './types';
export default class PostgrestTransformBuilder<Schema extends GenericSchema, Row extends Record<string, unknown>, Result> extends PostgrestBuilder<Result> {
/**

@@ -14,3 +14,3 @@ * Perform a SELECT on the query result.

*/
select<Query extends string = '*', NewResult = GetResult<Row, Query extends '*' ? '*' : Query>>(columns?: Query): PostgrestTransformBuilder<Row, NewResult>;
select<Query extends string = '*', NewResult = GetResult<Schema, Row, Query>>(columns?: Query): PostgrestTransformBuilder<Schema, Row, NewResult>;
/**

@@ -128,3 +128,9 @@ * Order the query result by `column`.

rollback(): this;
/**
* Override the type of the returned `data`.
*
* @typeParam NewResult - The new result type to override with
*/
returns<NewResult>(): PostgrestTransformBuilder<Schema, Row, NewResult>;
}
//# sourceMappingURL=PostgrestTransformBuilder.d.ts.map

@@ -173,4 +173,12 @@ "use strict";

}
/**
* Override the type of the returned `data`.
*
* @typeParam NewResult - The new result type to override with
*/
returns() {
return this;
}
}
exports.default = PostgrestTransformBuilder;
//# sourceMappingURL=PostgrestTransformBuilder.js.map

@@ -0,1 +1,2 @@

import { GenericSchema } from './types';
declare type Whitespace = ' ' | '\n' | '\t';

@@ -24,9 +25,10 @@ declare type LowerAlphabet = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z';

*/
declare type ConstructFieldDefinition<Row extends Record<string, unknown>, Field> = Field extends {
declare type ConstructFieldDefinition<Schema extends GenericSchema, Row extends Record<string, unknown>, Field> = Field extends {
star: true;
} ? Row : Field extends {
name: string;
foreignTable: true;
original: string;
children: unknown[];
} ? {
[K in Field['name']]: unknown;
[_ in Field['name']]: GetResultHelper<Schema, (Schema['Tables'] & Schema['Views'])[Field['original']]['Row'], Field['children'], unknown> extends infer Child ? Child | Child[] | null : never;
} : Field extends {

@@ -75,10 +77,11 @@ name: string;

star: true;
}, EatWhitespace<Remainder>] : ParseIdentifier<Input> extends [infer Name, `${infer Remainder}`] ? EatWhitespace<Remainder> extends `!inner${infer Remainder}` ? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [infer _Fields, `${infer Remainder}`] ? [
}, EatWhitespace<Remainder>] : ParseIdentifier<Input> extends [infer Name, `${infer Remainder}`] ? EatWhitespace<Remainder> extends `!inner${infer Remainder}` ? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [infer Fields, `${infer Remainder}`] ? [
{
name: Name;
foreignTable: true;
original: Name;
children: Fields;
},
EatWhitespace<Remainder>
] : ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string> ? ParseEmbeddedResource<EatWhitespace<Remainder>> : ParserError<'Expected embedded resource after `!inner`'> : EatWhitespace<Remainder> extends `!${infer Remainder}` ? ParseIdentifier<EatWhitespace<Remainder>> extends [infer _Hint, `${infer Remainder}`] ? EatWhitespace<Remainder> extends `!inner${infer Remainder}` ? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [
infer _Fields,
infer Fields,
`${infer Remainder}`

@@ -88,7 +91,8 @@ ] ? [

name: Name;
foreignTable: true;
original: Name;
children: Fields;
},
EatWhitespace<Remainder>
] : ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string> ? ParseEmbeddedResource<EatWhitespace<Remainder>> : ParserError<'Expected embedded resource after `!inner`'> : ParseEmbeddedResource<EatWhitespace<Remainder>> extends [
infer _Fields,
infer Fields,
`${infer Remainder}`

@@ -98,7 +102,8 @@ ] ? [

name: Name;
foreignTable: true;
original: Name;
children: Fields;
},
EatWhitespace<Remainder>
] : ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string> ? ParseEmbeddedResource<EatWhitespace<Remainder>> : ParserError<'Expected embedded resource after `!hint`'> : ParserError<'Expected identifier after `!`'> : EatWhitespace<Remainder> extends `:${infer Remainder}` ? ParseIdentifier<EatWhitespace<Remainder>> extends [infer OriginalName, `${infer Remainder}`] ? EatWhitespace<Remainder> extends `!inner${infer Remainder}` ? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [
infer _Fields,
infer Fields,
`${infer Remainder}`

@@ -108,7 +113,8 @@ ] ? [

name: Name;
foreignTable: true;
original: OriginalName;
children: Fields;
},
EatWhitespace<Remainder>
] : ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string> ? ParseEmbeddedResource<EatWhitespace<Remainder>> : ParserError<'Expected embedded resource after `!inner`'> : EatWhitespace<Remainder> extends `!${infer Remainder}` ? ParseIdentifier<EatWhitespace<Remainder>> extends [infer _Hint, `${infer Remainder}`] ? EatWhitespace<Remainder> extends `!inner${infer Remainder}` ? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [
infer _Fields,
infer Fields,
`${infer Remainder}`

@@ -118,7 +124,8 @@ ] ? [

name: Name;
foreignTable: true;
original: OriginalName;
children: Fields;
},
EatWhitespace<Remainder>
] : ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string> ? ParseEmbeddedResource<EatWhitespace<Remainder>> : ParserError<'Expected embedded resource after `!inner`'> : ParseEmbeddedResource<EatWhitespace<Remainder>> extends [
infer _Fields,
infer Fields,
`${infer Remainder}`

@@ -128,7 +135,8 @@ ] ? [

name: Name;
foreignTable: true;
original: OriginalName;
children: Fields;
},
EatWhitespace<Remainder>
] : ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string> ? ParseEmbeddedResource<EatWhitespace<Remainder>> : ParserError<'Expected embedded resource after `!hint`'> : ParserError<'Expected identifier after `!`'> : ParseEmbeddedResource<EatWhitespace<Remainder>> extends [
infer _Fields,
infer Fields,
`${infer Remainder}`

@@ -138,3 +146,4 @@ ] ? [

name: Name;
foreignTable: true;
original: OriginalName;
children: Fields;
},

@@ -148,6 +157,7 @@ EatWhitespace<Remainder>

EatWhitespace<Remainder>
] : ParseIdentifier<EatWhitespace<Remainder>> : ParseEmbeddedResource<EatWhitespace<Remainder>> extends [infer _Fields, `${infer Remainder}`] ? [
] : ParseIdentifier<EatWhitespace<Remainder>> : ParseEmbeddedResource<EatWhitespace<Remainder>> extends [infer Fields, `${infer Remainder}`] ? [
{
name: Name;
foreignTable: true;
original: Name;
children: Fields;
},

@@ -188,3 +198,3 @@ EatWhitespace<Remainder>

declare type ParseQuery<Query extends string> = string extends Query ? GenericStringError : ParseNodes<EatWhitespace<Query>> extends [infer Fields, `${infer Remainder}`] ? EatWhitespace<Remainder> extends '' ? Fields : ParserError<`Unexpected input: ${Remainder}`> : ParseNodes<EatWhitespace<Query>>;
declare type GetResultHelper<Row extends Record<string, unknown>, Fields extends unknown[], Acc> = Fields extends [infer R] ? GetResultHelper<Row, [], ConstructFieldDefinition<Row, R> & Acc> : Fields extends [infer R, ...infer Rest] ? GetResultHelper<Row, Rest, ConstructFieldDefinition<Row, R> & Acc> : Acc;
declare type GetResultHelper<Schema extends GenericSchema, Row extends Record<string, unknown>, Fields extends unknown[], Acc> = Fields extends [infer R] ? GetResultHelper<Schema, Row, [], ConstructFieldDefinition<Schema, Row, R> & Acc> : Fields extends [infer R, ...infer Rest] ? GetResultHelper<Schema, Row, Rest, ConstructFieldDefinition<Schema, Row, R> & Acc> : Acc;
/**

@@ -196,4 +206,4 @@ * Constructs a type definition for an object based on a given PostgREST query.

*/
export declare type GetResult<Row extends Record<string, unknown>, Query extends string> = ParseQuery<Query> extends unknown[] ? GetResultHelper<Row, ParseQuery<Query>, unknown> : ParseQuery<Query>;
export declare type GetResult<Schema extends GenericSchema, Row extends Record<string, unknown>, Query extends string> = ParseQuery<Query> extends unknown[] ? GetResultHelper<Schema, Row, ParseQuery<Query>, unknown> : ParseQuery<Query>;
export {};
//# sourceMappingURL=select-query-parser.d.ts.map

@@ -1,2 +0,2 @@

export declare const version = "1.0.0";
export declare const version = "1.1.0";
//# sourceMappingURL=version.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.version = void 0;
exports.version = '1.0.0';
exports.version = '1.1.0';
//# sourceMappingURL=version.js.map

@@ -38,5 +38,5 @@ import PostgrestQueryBuilder from './PostgrestQueryBuilder';

*/
from<TableName extends string & keyof Schema['Tables'], Table extends Schema['Tables'][TableName]>(relation: TableName): PostgrestQueryBuilder<Table>;
from<ViewName extends string & keyof Schema['Views'], View extends Schema['Views'][ViewName]>(relation: ViewName): PostgrestQueryBuilder<View>;
from(relation: string): PostgrestQueryBuilder<any>;
from<TableName extends string & keyof Schema['Tables'], Table extends Schema['Tables'][TableName]>(relation: TableName): PostgrestQueryBuilder<Schema, Table>;
from<ViewName extends string & keyof Schema['Views'], View extends Schema['Views'][ViewName]>(relation: ViewName): PostgrestQueryBuilder<Schema, View>;
from(relation: string): PostgrestQueryBuilder<Schema, any>;
/**

@@ -66,4 +66,4 @@ * Perform a function call.

count?: 'exact' | 'planned' | 'estimated';
}): PostgrestFilterBuilder<Function_['Returns'] extends any[] ? Function_['Returns'][number] extends Record<string, unknown> ? Function_['Returns'][number] : never : never, Function_['Returns']>;
}): PostgrestFilterBuilder<Schema, Function_['Returns'] extends any[] ? Function_['Returns'][number] extends Record<string, unknown> ? Function_['Returns'][number] : never : never, Function_['Returns']>;
}
//# sourceMappingURL=PostgrestClient.d.ts.map
import PostgrestTransformBuilder from './PostgrestTransformBuilder';
import { GenericSchema } from './types';
declare type FilterOperator = 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'like' | 'ilike' | 'is' | 'in' | 'cs' | 'cd' | 'sl' | 'sr' | 'nxl' | 'nxr' | 'adj' | 'ov' | 'fts' | 'plfts' | 'phfts' | 'wfts';
export default class PostgrestFilterBuilder<Row extends Record<string, unknown>, Result> extends PostgrestTransformBuilder<Row, Result> {
export default class PostgrestFilterBuilder<Schema extends GenericSchema, Row extends Record<string, unknown>, Result> extends PostgrestTransformBuilder<Schema, Row, Result> {
/**

@@ -5,0 +6,0 @@ * Match only rows where `column` is equal to `value`.

import PostgrestFilterBuilder from './PostgrestFilterBuilder';
import { GetResult } from './select-query-parser';
import { Fetch, GenericTable, GenericView } from './types';
export default class PostgrestQueryBuilder<Relation extends GenericTable | GenericView> {
import { Fetch, GenericSchema, GenericTable, GenericView } from './types';
export default class PostgrestQueryBuilder<Schema extends GenericSchema, Relation extends GenericTable | GenericView> {
url: URL;

@@ -36,6 +36,6 @@ headers: Record<string, string>;

*/
select<Query extends string = '*', Result = GetResult<Relation['Row'], Query extends '*' ? '*' : Query>>(columns?: Query, { head, count, }?: {
select<Query extends string = '*', Result = GetResult<Schema, Relation['Row'], Query>>(columns?: Query, { head, count, }?: {
head?: boolean;
count?: 'exact' | 'planned' | 'estimated';
}): PostgrestFilterBuilder<Relation['Row'], Result>;
}): PostgrestFilterBuilder<Schema, Relation['Row'], Result>;
/**

@@ -67,3 +67,3 @@ * Perform an INSERT into the table or view.

count?: 'exact' | 'planned' | 'estimated';
}): PostgrestFilterBuilder<Relation['Row'], undefined>;
}): PostgrestFilterBuilder<Schema, Relation['Row'], undefined>;
/**

@@ -108,3 +108,3 @@ * Perform an UPSERT on the table or view. Depending on the column(s) passed

count?: 'exact' | 'planned' | 'estimated';
}): PostgrestFilterBuilder<Relation['Row'], undefined>;
}): PostgrestFilterBuilder<Schema, Relation['Row'], undefined>;
/**

@@ -135,3 +135,3 @@ * Perform an UPDATE on the table or view.

count?: 'exact' | 'planned' | 'estimated';
}): PostgrestFilterBuilder<Relation['Row'], undefined>;
}): PostgrestFilterBuilder<Schema, Relation['Row'], undefined>;
/**

@@ -158,4 +158,4 @@ * Perform a DELETE on the table or view.

count?: 'exact' | 'planned' | 'estimated';
}): PostgrestFilterBuilder<Relation['Row'], undefined>;
}): PostgrestFilterBuilder<Schema, Relation['Row'], undefined>;
}
//# sourceMappingURL=PostgrestQueryBuilder.d.ts.map
import PostgrestBuilder from './PostgrestBuilder';
import { GetResult } from './select-query-parser';
import { PostgrestMaybeSingleResponse, PostgrestResponse, PostgrestSingleResponse } from './types';
export default class PostgrestTransformBuilder<Row extends Record<string, unknown>, Result> extends PostgrestBuilder<Result> {
import { GenericSchema, PostgrestMaybeSingleResponse, PostgrestResponse, PostgrestSingleResponse } from './types';
export default class PostgrestTransformBuilder<Schema extends GenericSchema, Row extends Record<string, unknown>, Result> extends PostgrestBuilder<Result> {
/**

@@ -14,3 +14,3 @@ * Perform a SELECT on the query result.

*/
select<Query extends string = '*', NewResult = GetResult<Row, Query extends '*' ? '*' : Query>>(columns?: Query): PostgrestTransformBuilder<Row, NewResult>;
select<Query extends string = '*', NewResult = GetResult<Schema, Row, Query>>(columns?: Query): PostgrestTransformBuilder<Schema, Row, NewResult>;
/**

@@ -128,3 +128,9 @@ * Order the query result by `column`.

rollback(): this;
/**
* Override the type of the returned `data`.
*
* @typeParam NewResult - The new result type to override with
*/
returns<NewResult>(): PostgrestTransformBuilder<Schema, Row, NewResult>;
}
//# sourceMappingURL=PostgrestTransformBuilder.d.ts.map

@@ -168,3 +168,11 @@ import PostgrestBuilder from './PostgrestBuilder';

}
/**
* Override the type of the returned `data`.
*
* @typeParam NewResult - The new result type to override with
*/
returns() {
return this;
}
}
//# sourceMappingURL=PostgrestTransformBuilder.js.map

@@ -0,1 +1,2 @@

import { GenericSchema } from './types';
declare type Whitespace = ' ' | '\n' | '\t';

@@ -24,9 +25,10 @@ declare type LowerAlphabet = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z';

*/
declare type ConstructFieldDefinition<Row extends Record<string, unknown>, Field> = Field extends {
declare type ConstructFieldDefinition<Schema extends GenericSchema, Row extends Record<string, unknown>, Field> = Field extends {
star: true;
} ? Row : Field extends {
name: string;
foreignTable: true;
original: string;
children: unknown[];
} ? {
[K in Field['name']]: unknown;
[_ in Field['name']]: GetResultHelper<Schema, (Schema['Tables'] & Schema['Views'])[Field['original']]['Row'], Field['children'], unknown> extends infer Child ? Child | Child[] | null : never;
} : Field extends {

@@ -75,10 +77,11 @@ name: string;

star: true;
}, EatWhitespace<Remainder>] : ParseIdentifier<Input> extends [infer Name, `${infer Remainder}`] ? EatWhitespace<Remainder> extends `!inner${infer Remainder}` ? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [infer _Fields, `${infer Remainder}`] ? [
}, EatWhitespace<Remainder>] : ParseIdentifier<Input> extends [infer Name, `${infer Remainder}`] ? EatWhitespace<Remainder> extends `!inner${infer Remainder}` ? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [infer Fields, `${infer Remainder}`] ? [
{
name: Name;
foreignTable: true;
original: Name;
children: Fields;
},
EatWhitespace<Remainder>
] : ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string> ? ParseEmbeddedResource<EatWhitespace<Remainder>> : ParserError<'Expected embedded resource after `!inner`'> : EatWhitespace<Remainder> extends `!${infer Remainder}` ? ParseIdentifier<EatWhitespace<Remainder>> extends [infer _Hint, `${infer Remainder}`] ? EatWhitespace<Remainder> extends `!inner${infer Remainder}` ? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [
infer _Fields,
infer Fields,
`${infer Remainder}`

@@ -88,7 +91,8 @@ ] ? [

name: Name;
foreignTable: true;
original: Name;
children: Fields;
},
EatWhitespace<Remainder>
] : ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string> ? ParseEmbeddedResource<EatWhitespace<Remainder>> : ParserError<'Expected embedded resource after `!inner`'> : ParseEmbeddedResource<EatWhitespace<Remainder>> extends [
infer _Fields,
infer Fields,
`${infer Remainder}`

@@ -98,7 +102,8 @@ ] ? [

name: Name;
foreignTable: true;
original: Name;
children: Fields;
},
EatWhitespace<Remainder>
] : ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string> ? ParseEmbeddedResource<EatWhitespace<Remainder>> : ParserError<'Expected embedded resource after `!hint`'> : ParserError<'Expected identifier after `!`'> : EatWhitespace<Remainder> extends `:${infer Remainder}` ? ParseIdentifier<EatWhitespace<Remainder>> extends [infer OriginalName, `${infer Remainder}`] ? EatWhitespace<Remainder> extends `!inner${infer Remainder}` ? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [
infer _Fields,
infer Fields,
`${infer Remainder}`

@@ -108,7 +113,8 @@ ] ? [

name: Name;
foreignTable: true;
original: OriginalName;
children: Fields;
},
EatWhitespace<Remainder>
] : ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string> ? ParseEmbeddedResource<EatWhitespace<Remainder>> : ParserError<'Expected embedded resource after `!inner`'> : EatWhitespace<Remainder> extends `!${infer Remainder}` ? ParseIdentifier<EatWhitespace<Remainder>> extends [infer _Hint, `${infer Remainder}`] ? EatWhitespace<Remainder> extends `!inner${infer Remainder}` ? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [
infer _Fields,
infer Fields,
`${infer Remainder}`

@@ -118,7 +124,8 @@ ] ? [

name: Name;
foreignTable: true;
original: OriginalName;
children: Fields;
},
EatWhitespace<Remainder>
] : ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string> ? ParseEmbeddedResource<EatWhitespace<Remainder>> : ParserError<'Expected embedded resource after `!inner`'> : ParseEmbeddedResource<EatWhitespace<Remainder>> extends [
infer _Fields,
infer Fields,
`${infer Remainder}`

@@ -128,7 +135,8 @@ ] ? [

name: Name;
foreignTable: true;
original: OriginalName;
children: Fields;
},
EatWhitespace<Remainder>
] : ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string> ? ParseEmbeddedResource<EatWhitespace<Remainder>> : ParserError<'Expected embedded resource after `!hint`'> : ParserError<'Expected identifier after `!`'> : ParseEmbeddedResource<EatWhitespace<Remainder>> extends [
infer _Fields,
infer Fields,
`${infer Remainder}`

@@ -138,3 +146,4 @@ ] ? [

name: Name;
foreignTable: true;
original: OriginalName;
children: Fields;
},

@@ -148,6 +157,7 @@ EatWhitespace<Remainder>

EatWhitespace<Remainder>
] : ParseIdentifier<EatWhitespace<Remainder>> : ParseEmbeddedResource<EatWhitespace<Remainder>> extends [infer _Fields, `${infer Remainder}`] ? [
] : ParseIdentifier<EatWhitespace<Remainder>> : ParseEmbeddedResource<EatWhitespace<Remainder>> extends [infer Fields, `${infer Remainder}`] ? [
{
name: Name;
foreignTable: true;
original: Name;
children: Fields;
},

@@ -188,3 +198,3 @@ EatWhitespace<Remainder>

declare type ParseQuery<Query extends string> = string extends Query ? GenericStringError : ParseNodes<EatWhitespace<Query>> extends [infer Fields, `${infer Remainder}`] ? EatWhitespace<Remainder> extends '' ? Fields : ParserError<`Unexpected input: ${Remainder}`> : ParseNodes<EatWhitespace<Query>>;
declare type GetResultHelper<Row extends Record<string, unknown>, Fields extends unknown[], Acc> = Fields extends [infer R] ? GetResultHelper<Row, [], ConstructFieldDefinition<Row, R> & Acc> : Fields extends [infer R, ...infer Rest] ? GetResultHelper<Row, Rest, ConstructFieldDefinition<Row, R> & Acc> : Acc;
declare type GetResultHelper<Schema extends GenericSchema, Row extends Record<string, unknown>, Fields extends unknown[], Acc> = Fields extends [infer R] ? GetResultHelper<Schema, Row, [], ConstructFieldDefinition<Schema, Row, R> & Acc> : Fields extends [infer R, ...infer Rest] ? GetResultHelper<Schema, Row, Rest, ConstructFieldDefinition<Schema, Row, R> & Acc> : Acc;
/**

@@ -196,4 +206,4 @@ * Constructs a type definition for an object based on a given PostgREST query.

*/
export declare type GetResult<Row extends Record<string, unknown>, Query extends string> = ParseQuery<Query> extends unknown[] ? GetResultHelper<Row, ParseQuery<Query>, unknown> : ParseQuery<Query>;
export declare type GetResult<Schema extends GenericSchema, Row extends Record<string, unknown>, Query extends string> = ParseQuery<Query> extends unknown[] ? GetResultHelper<Schema, Row, ParseQuery<Query>, unknown> : ParseQuery<Query>;
export {};
//# sourceMappingURL=select-query-parser.d.ts.map

@@ -1,2 +0,2 @@

export declare const version = "1.0.0";
export declare const version = "1.1.0";
//# sourceMappingURL=version.d.ts.map

@@ -1,2 +0,2 @@

export const version = '1.0.0';
export const version = '1.1.0';
//# sourceMappingURL=version.js.map
{
"name": "@supabase/postgrest-js",
"version": "1.0.0",
"version": "1.1.0",
"description": "Isomorphic PostgREST client",

@@ -29,5 +29,8 @@ "keywords": [

"docs:json": "typedoc --json docs/v2/spec.json --excludeExternals src/index.ts",
"test": "run-s test:db && jest --runInBand",
"test:clean": "cd test/db && docker-compose down",
"test:db": "cd test/db && docker-compose down && docker-compose up -d && wait-for-localhost 3000"
"test": "run-s test:types db:clean db:run test:run db:clean",
"test:run": "jest --runInBand",
"test:update": "run-s db:clean db:run && jest --runInBand --updateSnapshot && run-s db:clean",
"test:types": "run-s build:module && tsd --files test/*.test-d.ts",
"db:clean": "cd test/db && docker-compose down --volumes",
"db:run": "cd test/db && docker-compose up --detach && wait-for-localhost 3000"
},

@@ -46,6 +49,7 @@ "dependencies": {

"ts-jest": "^28.0.3",
"typedoc": "^0.22.16",
"typescript": "~4.7",
"tsd": "^0.24.1",
"typedoc": "^0.23.17",
"typescript": "~4.8",
"wait-for-localhost-cli": "^3.0.0"
}
}

@@ -9,3 +9,3 @@ # `postgrest-js`

Full documentation can be found [here](https://supabase.github.io/postgrest-js/).
Full documentation can be found [here](https://supabase.github.io/postgrest-js/v2).

@@ -12,0 +12,0 @@ ### Quick start

@@ -67,10 +67,10 @@ import PostgrestQueryBuilder from './PostgrestQueryBuilder'

Table extends Schema['Tables'][TableName]
>(relation: TableName): PostgrestQueryBuilder<Table>
>(relation: TableName): PostgrestQueryBuilder<Schema, Table>
from<ViewName extends string & keyof Schema['Views'], View extends Schema['Views'][ViewName]>(
relation: ViewName
): PostgrestQueryBuilder<View>
from(relation: string): PostgrestQueryBuilder<any>
from(relation: string): PostgrestQueryBuilder<any> {
): PostgrestQueryBuilder<Schema, View>
from(relation: string): PostgrestQueryBuilder<Schema, any>
from(relation: string): PostgrestQueryBuilder<Schema, any> {
const url = new URL(`${this.url}/${relation}`)
return new PostgrestQueryBuilder<any>(url, {
return new PostgrestQueryBuilder<Schema, any>(url, {
headers: { ...this.headers },

@@ -117,2 +117,3 @@ schema: this.schema,

): PostgrestFilterBuilder<
Schema,
Function_['Returns'] extends any[]

@@ -119,0 +120,0 @@ ? Function_['Returns'][number] extends Record<string, unknown>

import PostgrestTransformBuilder from './PostgrestTransformBuilder'
import { GenericSchema } from './types'

@@ -28,5 +29,6 @@ type FilterOperator =

export default class PostgrestFilterBuilder<
Schema extends GenericSchema,
Row extends Record<string, unknown>,
Result
> extends PostgrestTransformBuilder<Row, Result> {
> extends PostgrestTransformBuilder<Schema, Row, Result> {
/**

@@ -33,0 +35,0 @@ * Match only rows where `column` is equal to `value`.

import PostgrestBuilder from './PostgrestBuilder'
import PostgrestFilterBuilder from './PostgrestFilterBuilder'
import { GetResult } from './select-query-parser'
import { Fetch, GenericTable, GenericView } from './types'
import { Fetch, GenericSchema, GenericTable, GenericView } from './types'
export default class PostgrestQueryBuilder<Relation extends GenericTable | GenericView> {
export default class PostgrestQueryBuilder<
Schema extends GenericSchema,
Relation extends GenericTable | GenericView
> {
url: URL

@@ -52,6 +55,3 @@ headers: Record<string, string>

*/
select<
Query extends string = '*',
Result = GetResult<Relation['Row'], Query extends '*' ? '*' : Query>
>(
select<Query extends string = '*', Result = GetResult<Schema, Relation['Row'], Query>>(
columns?: Query,

@@ -65,3 +65,3 @@ {

} = {}
): PostgrestFilterBuilder<Relation['Row'], Result> {
): PostgrestFilterBuilder<Schema, Relation['Row'], Result> {
const method = head ? 'HEAD' : 'GET'

@@ -126,3 +126,3 @@ // Remove whitespaces except when quoted

} = {}
): PostgrestFilterBuilder<Relation['Row'], undefined> {
): PostgrestFilterBuilder<Schema, Relation['Row'], undefined> {
const method = 'POST'

@@ -203,3 +203,3 @@

} = {}
): PostgrestFilterBuilder<Relation['Row'], undefined> {
): PostgrestFilterBuilder<Schema, Relation['Row'], undefined> {
const method = 'POST'

@@ -258,3 +258,3 @@

} = {}
): PostgrestFilterBuilder<Relation['Row'], undefined> {
): PostgrestFilterBuilder<Schema, Relation['Row'], undefined> {
const method = 'PATCH'

@@ -305,3 +305,3 @@ const prefersHeaders = []

count?: 'exact' | 'planned' | 'estimated'
} = {}): PostgrestFilterBuilder<Relation['Row'], undefined> {
} = {}): PostgrestFilterBuilder<Schema, Relation['Row'], undefined> {
const method = 'DELETE'

@@ -308,0 +308,0 @@ const prefersHeaders = []

import PostgrestBuilder from './PostgrestBuilder'
import { GetResult } from './select-query-parser'
import { PostgrestMaybeSingleResponse, PostgrestResponse, PostgrestSingleResponse } from './types'
import {
GenericSchema,
PostgrestMaybeSingleResponse,
PostgrestResponse,
PostgrestSingleResponse,
} from './types'
export default class PostgrestTransformBuilder<
Schema extends GenericSchema,
Row extends Record<string, unknown>,

@@ -18,5 +24,5 @@ Result

*/
select<Query extends string = '*', NewResult = GetResult<Row, Query extends '*' ? '*' : Query>>(
select<Query extends string = '*', NewResult = GetResult<Schema, Row, Query>>(
columns?: Query
): PostgrestTransformBuilder<Row, NewResult> {
): PostgrestTransformBuilder<Schema, Row, NewResult> {
// Remove whitespaces except when quoted

@@ -41,3 +47,3 @@ let quoted = false

this.headers['Prefer'] += 'return=representation'
return this as unknown as PostgrestTransformBuilder<Row, NewResult>
return this as unknown as PostgrestTransformBuilder<Schema, Row, NewResult>
}

@@ -239,2 +245,11 @@

}
/**
* Override the type of the returned `data`.
*
* @typeParam NewResult - The new result type to override with
*/
returns<NewResult>(): PostgrestTransformBuilder<Schema, Row, NewResult> {
return this as unknown as PostgrestTransformBuilder<Schema, Row, NewResult>
}
}
// Credits to @bnjmnt4n (https://www.npmjs.com/package/postgrest-query)
import { GenericSchema } from './types'
type Whitespace = ' ' | '\n' | '\t'

@@ -70,8 +72,21 @@

*/
type ConstructFieldDefinition<Row extends Record<string, unknown>, Field> = Field extends {
type ConstructFieldDefinition<
Schema extends GenericSchema,
Row extends Record<string, unknown>,
Field
> = Field extends {
star: true
}
? Row
: Field extends { name: string; foreignTable: true }
? { [K in Field['name']]: unknown }
: Field extends { name: string; original: string; children: unknown[] }
? {
[_ in Field['name']]: GetResultHelper<
Schema,
(Schema['Tables'] & Schema['Views'])[Field['original']]['Row'],
Field['children'],
unknown
> extends infer Child
? Child | Child[] | null
: never
}
: Field extends { name: string; original: string }

@@ -139,5 +154,5 @@ ? { [K in Field['name']]: Row[Field['original']] }

? EatWhitespace<Remainder> extends `!inner${infer Remainder}`
? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [infer _Fields, `${infer Remainder}`]
? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [infer Fields, `${infer Remainder}`]
? // `field!inner(nodes)`
[{ name: Name; foreignTable: true }, EatWhitespace<Remainder>]
[{ name: Name; original: Name; children: Fields }, EatWhitespace<Remainder>]
: ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string>

@@ -150,7 +165,7 @@ ? ParseEmbeddedResource<EatWhitespace<Remainder>>

? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [
infer _Fields,
infer Fields,
`${infer Remainder}`
]
? // `field!hint!inner(nodes)`
[{ name: Name; foreignTable: true }, EatWhitespace<Remainder>]
[{ name: Name; original: Name; children: Fields }, EatWhitespace<Remainder>]
: ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string>

@@ -160,7 +175,7 @@ ? ParseEmbeddedResource<EatWhitespace<Remainder>>

: ParseEmbeddedResource<EatWhitespace<Remainder>> extends [
infer _Fields,
infer Fields,
`${infer Remainder}`
]
? // `field!hint(nodes)`
[{ name: Name; foreignTable: true }, EatWhitespace<Remainder>]
[{ name: Name; original: Name; children: Fields }, EatWhitespace<Remainder>]
: ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string>

@@ -174,7 +189,7 @@ ? ParseEmbeddedResource<EatWhitespace<Remainder>>

? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [
infer _Fields,
infer Fields,
`${infer Remainder}`
]
? // `renamed_field:field!inner(nodes)`
[{ name: Name; foreignTable: true }, EatWhitespace<Remainder>]
[{ name: Name; original: OriginalName; children: Fields }, EatWhitespace<Remainder>]
: ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string>

@@ -187,7 +202,7 @@ ? ParseEmbeddedResource<EatWhitespace<Remainder>>

? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [
infer _Fields,
infer Fields,
`${infer Remainder}`
]
? // `renamed_field:field!hint!inner(nodes)`
[{ name: Name; foreignTable: true }, EatWhitespace<Remainder>]
[{ name: Name; original: OriginalName; children: Fields }, EatWhitespace<Remainder>]
: ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string>

@@ -197,3 +212,3 @@ ? ParseEmbeddedResource<EatWhitespace<Remainder>>

: ParseEmbeddedResource<EatWhitespace<Remainder>> extends [
infer _Fields,
infer Fields,
`${infer Remainder}`

@@ -205,3 +220,4 @@ ]

name: Name
foreignTable: true
original: OriginalName
children: Fields
},

@@ -215,7 +231,7 @@ EatWhitespace<Remainder>

: ParseEmbeddedResource<EatWhitespace<Remainder>> extends [
infer _Fields,
infer Fields,
`${infer Remainder}`
]
? // `renamed_field:field(nodes)`
[{ name: Name; foreignTable: true }, EatWhitespace<Remainder>]
[{ name: Name; original: OriginalName; children: Fields }, EatWhitespace<Remainder>]
: ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string>

@@ -226,5 +242,5 @@ ? ParseEmbeddedResource<EatWhitespace<Remainder>>

: ParseIdentifier<EatWhitespace<Remainder>>
: ParseEmbeddedResource<EatWhitespace<Remainder>> extends [infer _Fields, `${infer Remainder}`]
: ParseEmbeddedResource<EatWhitespace<Remainder>> extends [infer Fields, `${infer Remainder}`]
? // `field(nodes)`
[{ name: Name; foreignTable: true }, EatWhitespace<Remainder>]
[{ name: Name; original: Name; children: Fields }, EatWhitespace<Remainder>]
: ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string>

@@ -287,2 +303,3 @@ ? ParseEmbeddedResource<EatWhitespace<Remainder>>

type GetResultHelper<
Schema extends GenericSchema,
Row extends Record<string, unknown>,

@@ -292,5 +309,5 @@ Fields extends unknown[],

> = Fields extends [infer R]
? GetResultHelper<Row, [], ConstructFieldDefinition<Row, R> & Acc>
? GetResultHelper<Schema, Row, [], ConstructFieldDefinition<Schema, Row, R> & Acc>
: Fields extends [infer R, ...infer Rest]
? GetResultHelper<Row, Rest, ConstructFieldDefinition<Row, R> & Acc>
? GetResultHelper<Schema, Row, Rest, ConstructFieldDefinition<Schema, Row, R> & Acc>
: Acc

@@ -305,6 +322,7 @@

export type GetResult<
Schema extends GenericSchema,
Row extends Record<string, unknown>,
Query extends string
> = ParseQuery<Query> extends unknown[]
? GetResultHelper<Row, ParseQuery<Query>, unknown>
? GetResultHelper<Schema, Row, ParseQuery<Query>, unknown>
: ParseQuery<Query>

@@ -1,1 +0,1 @@

export const version = '1.0.0'
export const version = '1.1.0'

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

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

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