@supabase/postgrest-js
Advanced tools
Comparing version 1.11.0 to 1.12.0
@@ -27,8 +27,18 @@ import { GenericSchema, Prettify } from './types'; | ||
/** | ||
* Creates a new {@link ParserError} if the given input is not already a parser error. | ||
*/ | ||
declare type CreateParserErrorIfRequired<Input, Message extends string> = Input extends ParserError<string> ? Input : ParserError<Message>; | ||
/** | ||
* Trims whitespace from the left of the input. | ||
*/ | ||
declare type EatWhitespace<Input extends string> = string extends Input ? GenericStringError : Input extends `${Whitespace}${infer Remainder}` ? EatWhitespace<Remainder> : Input; | ||
/** | ||
* Returns a boolean representing whether there is a foreign key with the given name. | ||
*/ | ||
declare type HasFKey<FKeyName, Relationships> = Relationships extends [infer R] ? R extends { | ||
foreignKeyName: FKeyName; | ||
} ? true : false : Relationships extends [infer R, ...infer Rest] ? HasFKey<FKeyName, [R]> extends true ? true : HasFKey<FKeyName, Rest> : false; | ||
/** | ||
* Returns a boolean representing whether there the foreign key has a unique constraint. | ||
*/ | ||
declare type HasUniqueFKey<FKeyName, Relationships> = Relationships extends [infer R] ? R extends { | ||
@@ -38,2 +48,6 @@ foreignKeyName: FKeyName; | ||
} ? true : false : Relationships extends [infer R, ...infer Rest] ? HasUniqueFKey<FKeyName, [R]> extends true ? true : HasUniqueFKey<FKeyName, Rest> : false; | ||
/** | ||
* Returns a boolean representing whether there is a foreign key referencing | ||
* a given relation. | ||
*/ | ||
declare type HasFKeyToFRel<FRelName, Relationships> = Relationships extends [infer R] ? R extends { | ||
@@ -49,4 +63,5 @@ referencedRelation: FRelName; | ||
* | ||
* @param Definitions Record of definitions, possibly generated from PostgREST's OpenAPI spec. | ||
* @param Name Name of the table being queried. | ||
* @param Schema Database schema. | ||
* @param Row Type of a row in the given table. | ||
* @param Relationships Relationships between different tables in the database. | ||
* @param Field Single field parsed by `ParseQuery`. | ||
@@ -57,2 +72,10 @@ */ | ||
} ? Row : Field extends { | ||
spread: true; | ||
original: string; | ||
children: unknown[]; | ||
} ? GetResultHelper<Schema, (Schema['Tables'] & Schema['Views'])[Field['original']]['Row'], Field['original'], (Schema['Tables'] & Schema['Views'])[Field['original']] extends { | ||
Relationships: infer R; | ||
} ? R : unknown, Field['children'], unknown> : Field extends { | ||
children: []; | ||
} ? {} : Field extends { | ||
name: string; | ||
@@ -80,11 +103,11 @@ original: string; | ||
name: string; | ||
type: infer T; | ||
} ? { | ||
[K in Field['name']]: T; | ||
} : Field extends { | ||
name: string; | ||
original: string; | ||
} ? Field['original'] extends keyof Row ? { | ||
[K in Field['name']]: Row[Field['original']]; | ||
} : SelectQueryError<`Referencing missing column \`${Field['original']}\``> : Field extends { | ||
name: string; | ||
type: infer T; | ||
} ? { | ||
[K in Field['name']]: T; | ||
} : Record<string, unknown>; | ||
} : SelectQueryError<`Referencing missing column \`${Field['original']}\``> : Record<string, unknown>; | ||
/** | ||
@@ -96,4 +119,3 @@ * Notes: all `Parse*` types assume that their input strings have their whitespace | ||
/** | ||
* Reads a consecutive sequence of more than 1 letter, | ||
* where letters are `[0-9a-zA-Z_]`. | ||
* Reads a consecutive sequence of 1 or more letter, where letters are `[0-9a-zA-Z_]`. | ||
*/ | ||
@@ -103,3 +125,3 @@ declare type ReadLetters<Input extends string> = string extends Input ? GenericStringError : ReadLettersHelper<Input, ''> extends [`${infer Letters}`, `${infer Remainder}`] ? Letters extends '' ? ParserError<`Expected letter at \`${Input}\``> : [Letters, Remainder] : ReadLettersHelper<Input, ''>; | ||
/** | ||
* Reads a consecutive sequence of more than 1 double-quoted letters, | ||
* Reads a consecutive sequence of 1 or more double-quoted letters, | ||
* where letters are `[^"]`. | ||
@@ -111,3 +133,3 @@ */ | ||
* Parses a (possibly double-quoted) identifier. | ||
* For now, identifiers are just sequences of more than 1 letter. | ||
* Identifiers are sequences of 1 or more letters. | ||
*/ | ||
@@ -119,5 +141,4 @@ declare type ParseIdentifier<Input extends string> = ReadLetters<Input> extends [ | ||
/** | ||
* Parses a node. | ||
* A node is one of the following: | ||
* - `*` | ||
* Parses a field without preceding field renaming. | ||
* A field is one of the following: | ||
* - `field` | ||
@@ -130,18 +151,6 @@ * - `field::type` | ||
* - `field!hint!inner(nodes)` | ||
* - `renamed_field:field` | ||
* - `renamed_field:field::type` | ||
* - `renamed_field:field->json...` | ||
* - `renamed_field:field(nodes)` | ||
* - `renamed_field:field!hint(nodes)` | ||
* - `renamed_field:field!inner(nodes)` | ||
* - `renamed_field:field!hint!inner(nodes)` | ||
* | ||
* TODO: more support for JSON operators `->`, `->>`. | ||
* TODO: support type casting of JSON operators `a->b::type`, `a->>b::type`. | ||
*/ | ||
declare type ParseNode<Input extends string> = Input extends '' ? ParserError<'Empty string'> : Input extends `*${infer Remainder}` ? [{ | ||
star: true; | ||
}, EatWhitespace<Remainder>] : ParseIdentifier<Input> extends [infer Name, `${infer Remainder}`] ? EatWhitespace<Remainder> extends `::${infer Remainder}` ? ParseIdentifier<Remainder> extends [infer CastType, `${infer Remainder}`] ? CastType extends PostgreSQLTypes ? [{ | ||
name: Name; | ||
type: TypeScriptTypes<CastType>; | ||
}, EatWhitespace<Remainder>] : never : ParserError<`Unexpected type cast at \`${Input}\``> : EatWhitespace<Remainder> extends `!inner${infer Remainder}` ? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [infer Fields, `${infer Remainder}`] ? [ | ||
declare type ParseField<Input extends string> = Input extends '' ? ParserError<'Empty string'> : ParseIdentifier<Input> extends [infer Name, `${infer Remainder}`] ? EatWhitespace<Remainder> extends `!inner${infer Remainder}` ? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [infer Fields, `${infer Remainder}`] ? [ | ||
{ | ||
@@ -153,3 +162,3 @@ name: Name; | ||
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 [ | ||
] : CreateParserErrorIfRequired<ParseEmbeddedResource<EatWhitespace<Remainder>>, '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, | ||
@@ -165,3 +174,3 @@ `${infer Remainder}` | ||
EatWhitespace<Remainder> | ||
] : ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string> ? ParseEmbeddedResource<EatWhitespace<Remainder>> : ParserError<'Expected embedded resource after `!inner`'> : ParseEmbeddedResource<EatWhitespace<Remainder>> extends [ | ||
] : CreateParserErrorIfRequired<ParseEmbeddedResource<EatWhitespace<Remainder>>, 'Expected embedded resource after `!inner`'> : ParseEmbeddedResource<EatWhitespace<Remainder>> extends [ | ||
infer Fields, | ||
@@ -177,66 +186,5 @@ `${infer Remainder}` | ||
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 `::${infer Remainder}` ? ParseIdentifier<Remainder> extends [infer CastType, `${infer Remainder}`] ? CastType extends PostgreSQLTypes ? [{ | ||
name: Name; | ||
type: TypeScriptTypes<CastType>; | ||
}, EatWhitespace<Remainder>] : never : ParserError<`Unexpected type cast at \`${Input}\``> : EatWhitespace<Remainder> extends `!inner${infer Remainder}` ? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [ | ||
infer Fields, | ||
`${infer Remainder}` | ||
] ? [ | ||
] : CreateParserErrorIfRequired<ParseEmbeddedResource<EatWhitespace<Remainder>>, 'Expected embedded resource after `!hint`'> : ParserError<'Expected identifier after `!`'> : ParseEmbeddedResource<EatWhitespace<Remainder>> extends [infer Fields, `${infer Remainder}`] ? [ | ||
{ | ||
name: Name; | ||
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 Remainder}` | ||
] ? [ | ||
{ | ||
name: Name; | ||
original: OriginalName; | ||
hint: Hint; | ||
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 Remainder}` | ||
] ? [ | ||
{ | ||
name: Name; | ||
original: OriginalName; | ||
hint: Hint; | ||
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 Remainder}` | ||
] ? [ | ||
{ | ||
name: Name; | ||
original: OriginalName; | ||
children: Fields; | ||
}, | ||
EatWhitespace<Remainder> | ||
] : ParseJsonAccessor<EatWhitespace<Remainder>> extends [ | ||
infer _PropertyName, | ||
infer PropertyType, | ||
`${infer Remainder}` | ||
] ? [ | ||
{ | ||
name: Name; | ||
type: PropertyType; | ||
}, | ||
EatWhitespace<Remainder> | ||
] : ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string> ? ParseEmbeddedResource<EatWhitespace<Remainder>> : [ | ||
{ | ||
name: Name; | ||
original: OriginalName; | ||
}, | ||
EatWhitespace<Remainder> | ||
] : ParseIdentifier<EatWhitespace<Remainder>> : ParseEmbeddedResource<EatWhitespace<Remainder>> extends [infer Fields, `${infer Remainder}`] ? [ | ||
{ | ||
name: Name; | ||
original: Name; | ||
@@ -253,6 +201,10 @@ children: Fields; | ||
name: PropertyName; | ||
original: PropertyName; | ||
type: PropertyType; | ||
}, | ||
EatWhitespace<Remainder> | ||
] : ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string> ? ParseEmbeddedResource<EatWhitespace<Remainder>> : [ | ||
] : ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string> ? ParseEmbeddedResource<EatWhitespace<Remainder>> : EatWhitespace<Remainder> extends `::${infer Remainder}` ? ParseIdentifier<Remainder> extends [`${infer CastType}`, `${infer Remainder}`] ? CastType extends PostgreSQLTypes ? [{ | ||
name: Name; | ||
type: TypeScriptTypes<CastType>; | ||
}, EatWhitespace<Remainder>] : ParserError<`Invalid type for \`::\` operator \`${CastType}\``> : ParserError<`Invalid type for \`::\` operator at \`${Remainder}\``> : [ | ||
{ | ||
@@ -265,2 +217,21 @@ name: Name; | ||
/** | ||
* Parses a node. | ||
* A node is one of the following: | ||
* - `*` | ||
* - a field, as defined above | ||
* - a renamed field, `renamed_field:field` | ||
* - a spread field, `...field` | ||
*/ | ||
declare type ParseNode<Input extends string> = Input extends '' ? ParserError<'Empty string'> : Input extends `*${infer Remainder}` ? [{ | ||
star: true; | ||
}, EatWhitespace<Remainder>] : Input extends `...${infer Remainder}` ? ParseField<EatWhitespace<Remainder>> extends [infer Field, `${infer Remainder}`] ? Field extends { | ||
children: unknown[]; | ||
} ? [Prettify<{ | ||
spread: true; | ||
} & Field>, EatWhitespace<Remainder>] : ParserError<'Unable to parse spread resource'> : ParserError<'Unable to parse spread resource'> : ParseIdentifier<Input> extends [infer Name, `${infer Remainder}`] ? EatWhitespace<Remainder> extends `::${infer _Remainder}` ? ParseField<Input> : EatWhitespace<Remainder> extends `:${infer Remainder}` ? ParseField<EatWhitespace<Remainder>> extends [infer Field, `${infer Remainder}`] ? Field extends { | ||
name: string; | ||
} ? [Prettify<Omit<Field, 'name'> & { | ||
name: Name; | ||
}>, EatWhitespace<Remainder>] : ParserError<`Unable to parse renamed field`> : ParserError<`Unable to parse renamed field`> : ParseField<Input> : ParserError<`Expected identifier at \`${Input}\``>; | ||
/** | ||
* Parses a JSON property accessor of the shape `->a->b->c`. The last accessor in | ||
@@ -279,3 +250,3 @@ * the series may convert to text by using the ->> operator instead of ->. | ||
* Parses an embedded resource, which is an opening `(`, followed by a sequence of | ||
* nodes, separated by `,`, then a closing `)`. | ||
* 0 or more nodes separated by `,`, then a closing `)`. | ||
* | ||
@@ -285,3 +256,3 @@ * Returns a tuple of ["Parsed fields", "Remainder of text"], an error, | ||
*/ | ||
declare type ParseEmbeddedResource<Input extends string> = Input extends `(${infer Remainder}` ? ParseNodes<EatWhitespace<Remainder>> extends [infer Fields, `${infer Remainder}`] ? EatWhitespace<Remainder> extends `)${infer Remainder}` ? Fields extends [] ? ParserError<'Expected fields after `(`'> : [Fields, EatWhitespace<Remainder>] : ParserError<`Expected ")"`> : ParseNodes<EatWhitespace<Remainder>> : Input; | ||
declare type ParseEmbeddedResource<Input extends string> = Input extends `(${infer Remainder}` ? ParseNodes<EatWhitespace<Remainder>> extends [infer Fields, `${infer Remainder}`] ? EatWhitespace<Remainder> extends `)${infer Remainder}` ? [Fields, EatWhitespace<Remainder>] : ParserError<`Expected ")"`> : ParseNodes<EatWhitespace<Remainder>> extends ParserError<string> ? EatWhitespace<Remainder> extends `)${infer Remainder}` ? [[], EatWhitespace<Remainder>] : ParseNodes<EatWhitespace<Remainder>> : ParserError<'Expected embedded resource fields or `)`'> : Input; | ||
/** | ||
@@ -310,3 +281,5 @@ * Parses a sequence of nodes, separated by `,`. | ||
* | ||
* @param Row Record<string, unknown>. | ||
* @param Schema Database schema. | ||
* @param Row Type of a row in the given table. | ||
* @param Relationships Relationships between different tables in the database. | ||
* @param Query Select query string literal to parse. | ||
@@ -313,0 +286,0 @@ */ |
@@ -1,2 +0,2 @@ | ||
export declare const version = "1.11.0"; | ||
export declare const version = "1.12.0"; | ||
//# sourceMappingURL=version.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.version = void 0; | ||
exports.version = '1.11.0'; | ||
exports.version = '1.12.0'; | ||
//# sourceMappingURL=version.js.map |
@@ -27,8 +27,18 @@ import { GenericSchema, Prettify } from './types'; | ||
/** | ||
* Creates a new {@link ParserError} if the given input is not already a parser error. | ||
*/ | ||
declare type CreateParserErrorIfRequired<Input, Message extends string> = Input extends ParserError<string> ? Input : ParserError<Message>; | ||
/** | ||
* Trims whitespace from the left of the input. | ||
*/ | ||
declare type EatWhitespace<Input extends string> = string extends Input ? GenericStringError : Input extends `${Whitespace}${infer Remainder}` ? EatWhitespace<Remainder> : Input; | ||
/** | ||
* Returns a boolean representing whether there is a foreign key with the given name. | ||
*/ | ||
declare type HasFKey<FKeyName, Relationships> = Relationships extends [infer R] ? R extends { | ||
foreignKeyName: FKeyName; | ||
} ? true : false : Relationships extends [infer R, ...infer Rest] ? HasFKey<FKeyName, [R]> extends true ? true : HasFKey<FKeyName, Rest> : false; | ||
/** | ||
* Returns a boolean representing whether there the foreign key has a unique constraint. | ||
*/ | ||
declare type HasUniqueFKey<FKeyName, Relationships> = Relationships extends [infer R] ? R extends { | ||
@@ -38,2 +48,6 @@ foreignKeyName: FKeyName; | ||
} ? true : false : Relationships extends [infer R, ...infer Rest] ? HasUniqueFKey<FKeyName, [R]> extends true ? true : HasUniqueFKey<FKeyName, Rest> : false; | ||
/** | ||
* Returns a boolean representing whether there is a foreign key referencing | ||
* a given relation. | ||
*/ | ||
declare type HasFKeyToFRel<FRelName, Relationships> = Relationships extends [infer R] ? R extends { | ||
@@ -49,4 +63,5 @@ referencedRelation: FRelName; | ||
* | ||
* @param Definitions Record of definitions, possibly generated from PostgREST's OpenAPI spec. | ||
* @param Name Name of the table being queried. | ||
* @param Schema Database schema. | ||
* @param Row Type of a row in the given table. | ||
* @param Relationships Relationships between different tables in the database. | ||
* @param Field Single field parsed by `ParseQuery`. | ||
@@ -57,2 +72,10 @@ */ | ||
} ? Row : Field extends { | ||
spread: true; | ||
original: string; | ||
children: unknown[]; | ||
} ? GetResultHelper<Schema, (Schema['Tables'] & Schema['Views'])[Field['original']]['Row'], Field['original'], (Schema['Tables'] & Schema['Views'])[Field['original']] extends { | ||
Relationships: infer R; | ||
} ? R : unknown, Field['children'], unknown> : Field extends { | ||
children: []; | ||
} ? {} : Field extends { | ||
name: string; | ||
@@ -80,11 +103,11 @@ original: string; | ||
name: string; | ||
type: infer T; | ||
} ? { | ||
[K in Field['name']]: T; | ||
} : Field extends { | ||
name: string; | ||
original: string; | ||
} ? Field['original'] extends keyof Row ? { | ||
[K in Field['name']]: Row[Field['original']]; | ||
} : SelectQueryError<`Referencing missing column \`${Field['original']}\``> : Field extends { | ||
name: string; | ||
type: infer T; | ||
} ? { | ||
[K in Field['name']]: T; | ||
} : Record<string, unknown>; | ||
} : SelectQueryError<`Referencing missing column \`${Field['original']}\``> : Record<string, unknown>; | ||
/** | ||
@@ -96,4 +119,3 @@ * Notes: all `Parse*` types assume that their input strings have their whitespace | ||
/** | ||
* Reads a consecutive sequence of more than 1 letter, | ||
* where letters are `[0-9a-zA-Z_]`. | ||
* Reads a consecutive sequence of 1 or more letter, where letters are `[0-9a-zA-Z_]`. | ||
*/ | ||
@@ -103,3 +125,3 @@ declare type ReadLetters<Input extends string> = string extends Input ? GenericStringError : ReadLettersHelper<Input, ''> extends [`${infer Letters}`, `${infer Remainder}`] ? Letters extends '' ? ParserError<`Expected letter at \`${Input}\``> : [Letters, Remainder] : ReadLettersHelper<Input, ''>; | ||
/** | ||
* Reads a consecutive sequence of more than 1 double-quoted letters, | ||
* Reads a consecutive sequence of 1 or more double-quoted letters, | ||
* where letters are `[^"]`. | ||
@@ -111,3 +133,3 @@ */ | ||
* Parses a (possibly double-quoted) identifier. | ||
* For now, identifiers are just sequences of more than 1 letter. | ||
* Identifiers are sequences of 1 or more letters. | ||
*/ | ||
@@ -119,5 +141,4 @@ declare type ParseIdentifier<Input extends string> = ReadLetters<Input> extends [ | ||
/** | ||
* Parses a node. | ||
* A node is one of the following: | ||
* - `*` | ||
* Parses a field without preceding field renaming. | ||
* A field is one of the following: | ||
* - `field` | ||
@@ -130,18 +151,6 @@ * - `field::type` | ||
* - `field!hint!inner(nodes)` | ||
* - `renamed_field:field` | ||
* - `renamed_field:field::type` | ||
* - `renamed_field:field->json...` | ||
* - `renamed_field:field(nodes)` | ||
* - `renamed_field:field!hint(nodes)` | ||
* - `renamed_field:field!inner(nodes)` | ||
* - `renamed_field:field!hint!inner(nodes)` | ||
* | ||
* TODO: more support for JSON operators `->`, `->>`. | ||
* TODO: support type casting of JSON operators `a->b::type`, `a->>b::type`. | ||
*/ | ||
declare type ParseNode<Input extends string> = Input extends '' ? ParserError<'Empty string'> : Input extends `*${infer Remainder}` ? [{ | ||
star: true; | ||
}, EatWhitespace<Remainder>] : ParseIdentifier<Input> extends [infer Name, `${infer Remainder}`] ? EatWhitespace<Remainder> extends `::${infer Remainder}` ? ParseIdentifier<Remainder> extends [infer CastType, `${infer Remainder}`] ? CastType extends PostgreSQLTypes ? [{ | ||
name: Name; | ||
type: TypeScriptTypes<CastType>; | ||
}, EatWhitespace<Remainder>] : never : ParserError<`Unexpected type cast at \`${Input}\``> : EatWhitespace<Remainder> extends `!inner${infer Remainder}` ? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [infer Fields, `${infer Remainder}`] ? [ | ||
declare type ParseField<Input extends string> = Input extends '' ? ParserError<'Empty string'> : ParseIdentifier<Input> extends [infer Name, `${infer Remainder}`] ? EatWhitespace<Remainder> extends `!inner${infer Remainder}` ? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [infer Fields, `${infer Remainder}`] ? [ | ||
{ | ||
@@ -153,3 +162,3 @@ name: Name; | ||
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 [ | ||
] : CreateParserErrorIfRequired<ParseEmbeddedResource<EatWhitespace<Remainder>>, '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, | ||
@@ -165,3 +174,3 @@ `${infer Remainder}` | ||
EatWhitespace<Remainder> | ||
] : ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string> ? ParseEmbeddedResource<EatWhitespace<Remainder>> : ParserError<'Expected embedded resource after `!inner`'> : ParseEmbeddedResource<EatWhitespace<Remainder>> extends [ | ||
] : CreateParserErrorIfRequired<ParseEmbeddedResource<EatWhitespace<Remainder>>, 'Expected embedded resource after `!inner`'> : ParseEmbeddedResource<EatWhitespace<Remainder>> extends [ | ||
infer Fields, | ||
@@ -177,66 +186,5 @@ `${infer Remainder}` | ||
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 `::${infer Remainder}` ? ParseIdentifier<Remainder> extends [infer CastType, `${infer Remainder}`] ? CastType extends PostgreSQLTypes ? [{ | ||
name: Name; | ||
type: TypeScriptTypes<CastType>; | ||
}, EatWhitespace<Remainder>] : never : ParserError<`Unexpected type cast at \`${Input}\``> : EatWhitespace<Remainder> extends `!inner${infer Remainder}` ? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [ | ||
infer Fields, | ||
`${infer Remainder}` | ||
] ? [ | ||
] : CreateParserErrorIfRequired<ParseEmbeddedResource<EatWhitespace<Remainder>>, 'Expected embedded resource after `!hint`'> : ParserError<'Expected identifier after `!`'> : ParseEmbeddedResource<EatWhitespace<Remainder>> extends [infer Fields, `${infer Remainder}`] ? [ | ||
{ | ||
name: Name; | ||
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 Remainder}` | ||
] ? [ | ||
{ | ||
name: Name; | ||
original: OriginalName; | ||
hint: Hint; | ||
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 Remainder}` | ||
] ? [ | ||
{ | ||
name: Name; | ||
original: OriginalName; | ||
hint: Hint; | ||
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 Remainder}` | ||
] ? [ | ||
{ | ||
name: Name; | ||
original: OriginalName; | ||
children: Fields; | ||
}, | ||
EatWhitespace<Remainder> | ||
] : ParseJsonAccessor<EatWhitespace<Remainder>> extends [ | ||
infer _PropertyName, | ||
infer PropertyType, | ||
`${infer Remainder}` | ||
] ? [ | ||
{ | ||
name: Name; | ||
type: PropertyType; | ||
}, | ||
EatWhitespace<Remainder> | ||
] : ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string> ? ParseEmbeddedResource<EatWhitespace<Remainder>> : [ | ||
{ | ||
name: Name; | ||
original: OriginalName; | ||
}, | ||
EatWhitespace<Remainder> | ||
] : ParseIdentifier<EatWhitespace<Remainder>> : ParseEmbeddedResource<EatWhitespace<Remainder>> extends [infer Fields, `${infer Remainder}`] ? [ | ||
{ | ||
name: Name; | ||
original: Name; | ||
@@ -253,6 +201,10 @@ children: Fields; | ||
name: PropertyName; | ||
original: PropertyName; | ||
type: PropertyType; | ||
}, | ||
EatWhitespace<Remainder> | ||
] : ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string> ? ParseEmbeddedResource<EatWhitespace<Remainder>> : [ | ||
] : ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string> ? ParseEmbeddedResource<EatWhitespace<Remainder>> : EatWhitespace<Remainder> extends `::${infer Remainder}` ? ParseIdentifier<Remainder> extends [`${infer CastType}`, `${infer Remainder}`] ? CastType extends PostgreSQLTypes ? [{ | ||
name: Name; | ||
type: TypeScriptTypes<CastType>; | ||
}, EatWhitespace<Remainder>] : ParserError<`Invalid type for \`::\` operator \`${CastType}\``> : ParserError<`Invalid type for \`::\` operator at \`${Remainder}\``> : [ | ||
{ | ||
@@ -265,2 +217,21 @@ name: Name; | ||
/** | ||
* Parses a node. | ||
* A node is one of the following: | ||
* - `*` | ||
* - a field, as defined above | ||
* - a renamed field, `renamed_field:field` | ||
* - a spread field, `...field` | ||
*/ | ||
declare type ParseNode<Input extends string> = Input extends '' ? ParserError<'Empty string'> : Input extends `*${infer Remainder}` ? [{ | ||
star: true; | ||
}, EatWhitespace<Remainder>] : Input extends `...${infer Remainder}` ? ParseField<EatWhitespace<Remainder>> extends [infer Field, `${infer Remainder}`] ? Field extends { | ||
children: unknown[]; | ||
} ? [Prettify<{ | ||
spread: true; | ||
} & Field>, EatWhitespace<Remainder>] : ParserError<'Unable to parse spread resource'> : ParserError<'Unable to parse spread resource'> : ParseIdentifier<Input> extends [infer Name, `${infer Remainder}`] ? EatWhitespace<Remainder> extends `::${infer _Remainder}` ? ParseField<Input> : EatWhitespace<Remainder> extends `:${infer Remainder}` ? ParseField<EatWhitespace<Remainder>> extends [infer Field, `${infer Remainder}`] ? Field extends { | ||
name: string; | ||
} ? [Prettify<Omit<Field, 'name'> & { | ||
name: Name; | ||
}>, EatWhitespace<Remainder>] : ParserError<`Unable to parse renamed field`> : ParserError<`Unable to parse renamed field`> : ParseField<Input> : ParserError<`Expected identifier at \`${Input}\``>; | ||
/** | ||
* Parses a JSON property accessor of the shape `->a->b->c`. The last accessor in | ||
@@ -279,3 +250,3 @@ * the series may convert to text by using the ->> operator instead of ->. | ||
* Parses an embedded resource, which is an opening `(`, followed by a sequence of | ||
* nodes, separated by `,`, then a closing `)`. | ||
* 0 or more nodes separated by `,`, then a closing `)`. | ||
* | ||
@@ -285,3 +256,3 @@ * Returns a tuple of ["Parsed fields", "Remainder of text"], an error, | ||
*/ | ||
declare type ParseEmbeddedResource<Input extends string> = Input extends `(${infer Remainder}` ? ParseNodes<EatWhitespace<Remainder>> extends [infer Fields, `${infer Remainder}`] ? EatWhitespace<Remainder> extends `)${infer Remainder}` ? Fields extends [] ? ParserError<'Expected fields after `(`'> : [Fields, EatWhitespace<Remainder>] : ParserError<`Expected ")"`> : ParseNodes<EatWhitespace<Remainder>> : Input; | ||
declare type ParseEmbeddedResource<Input extends string> = Input extends `(${infer Remainder}` ? ParseNodes<EatWhitespace<Remainder>> extends [infer Fields, `${infer Remainder}`] ? EatWhitespace<Remainder> extends `)${infer Remainder}` ? [Fields, EatWhitespace<Remainder>] : ParserError<`Expected ")"`> : ParseNodes<EatWhitespace<Remainder>> extends ParserError<string> ? EatWhitespace<Remainder> extends `)${infer Remainder}` ? [[], EatWhitespace<Remainder>] : ParseNodes<EatWhitespace<Remainder>> : ParserError<'Expected embedded resource fields or `)`'> : Input; | ||
/** | ||
@@ -310,3 +281,5 @@ * Parses a sequence of nodes, separated by `,`. | ||
* | ||
* @param Row Record<string, unknown>. | ||
* @param Schema Database schema. | ||
* @param Row Type of a row in the given table. | ||
* @param Relationships Relationships between different tables in the database. | ||
* @param Query Select query string literal to parse. | ||
@@ -313,0 +286,0 @@ */ |
@@ -1,2 +0,2 @@ | ||
export declare const version = "1.11.0"; | ||
export declare const version = "1.12.0"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -1,2 +0,2 @@ | ||
export const version = '1.11.0'; | ||
export const version = '1.12.0'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@supabase/postgrest-js", | ||
"version": "1.11.0", | ||
"version": "1.12.0", | ||
"description": "Isomorphic PostgREST client", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -113,2 +113,9 @@ // Credits to @bnjmnt4n (https://www.npmjs.com/package/postgrest-query) | ||
/** | ||
* Creates a new {@link ParserError} if the given input is not already a parser error. | ||
*/ | ||
type CreateParserErrorIfRequired<Input, Message extends string> = Input extends ParserError<string> | ||
? Input | ||
: ParserError<Message> | ||
/** | ||
* Trims whitespace from the left of the input. | ||
@@ -122,2 +129,5 @@ */ | ||
/** | ||
* Returns a boolean representing whether there is a foreign key with the given name. | ||
*/ | ||
type HasFKey<FKeyName, Relationships> = Relationships extends [infer R] | ||
@@ -133,2 +143,5 @@ ? R extends { foreignKeyName: FKeyName } | ||
/** | ||
* Returns a boolean representing whether there the foreign key has a unique constraint. | ||
*/ | ||
type HasUniqueFKey<FKeyName, Relationships> = Relationships extends [infer R] | ||
@@ -144,2 +157,6 @@ ? R extends { foreignKeyName: FKeyName; isOneToOne: true } | ||
/** | ||
* Returns a boolean representing whether there is a foreign key referencing | ||
* a given relation. | ||
*/ | ||
type HasFKeyToFRel<FRelName, Relationships> = Relationships extends [infer R] | ||
@@ -168,4 +185,5 @@ ? R extends { referencedRelation: FRelName } | ||
* | ||
* @param Definitions Record of definitions, possibly generated from PostgREST's OpenAPI spec. | ||
* @param Name Name of the table being queried. | ||
* @param Schema Database schema. | ||
* @param Row Type of a row in the given table. | ||
* @param Relationships Relationships between different tables in the database. | ||
* @param Field Single field parsed by `ParseQuery`. | ||
@@ -181,2 +199,15 @@ */ | ||
? Row | ||
: Field extends { spread: true; original: string; children: unknown[] } | ||
? GetResultHelper< | ||
Schema, | ||
(Schema['Tables'] & Schema['Views'])[Field['original']]['Row'], | ||
Field['original'], | ||
(Schema['Tables'] & Schema['Views'])[Field['original']] extends { Relationships: infer R } | ||
? R | ||
: unknown, | ||
Field['children'], | ||
unknown | ||
> | ||
: Field extends { children: [] } | ||
? {} | ||
: Field extends { name: string; original: string; hint: string; children: unknown[] } | ||
@@ -240,2 +271,4 @@ ? { | ||
} | ||
: Field extends { name: string; type: infer T } | ||
? { [K in Field['name']]: T } | ||
: Field extends { name: string; original: string } | ||
@@ -245,4 +278,2 @@ ? Field['original'] extends keyof Row | ||
: SelectQueryError<`Referencing missing column \`${Field['original']}\``> | ||
: Field extends { name: string; type: infer T } | ||
? { [K in Field['name']]: T } | ||
: Record<string, unknown> | ||
@@ -257,4 +288,3 @@ | ||
/** | ||
* Reads a consecutive sequence of more than 1 letter, | ||
* where letters are `[0-9a-zA-Z_]`. | ||
* Reads a consecutive sequence of 1 or more letter, where letters are `[0-9a-zA-Z_]`. | ||
*/ | ||
@@ -278,3 +308,3 @@ type ReadLetters<Input extends string> = string extends Input | ||
/** | ||
* Reads a consecutive sequence of more than 1 double-quoted letters, | ||
* Reads a consecutive sequence of 1 or more double-quoted letters, | ||
* where letters are `[^"]`. | ||
@@ -302,3 +332,3 @@ */ | ||
* Parses a (possibly double-quoted) identifier. | ||
* For now, identifiers are just sequences of more than 1 letter. | ||
* Identifiers are sequences of 1 or more letters. | ||
*/ | ||
@@ -315,5 +345,4 @@ type ParseIdentifier<Input extends string> = ReadLetters<Input> extends [ | ||
/** | ||
* Parses a node. | ||
* A node is one of the following: | ||
* - `*` | ||
* Parses a field without preceding field renaming. | ||
* A field is one of the following: | ||
* - `field` | ||
@@ -326,32 +355,16 @@ * - `field::type` | ||
* - `field!hint!inner(nodes)` | ||
* - `renamed_field:field` | ||
* - `renamed_field:field::type` | ||
* - `renamed_field:field->json...` | ||
* - `renamed_field:field(nodes)` | ||
* - `renamed_field:field!hint(nodes)` | ||
* - `renamed_field:field!inner(nodes)` | ||
* - `renamed_field:field!hint!inner(nodes)` | ||
* | ||
* TODO: more support for JSON operators `->`, `->>`. | ||
* TODO: support type casting of JSON operators `a->b::type`, `a->>b::type`. | ||
*/ | ||
type ParseNode<Input extends string> = Input extends '' | ||
type ParseField<Input extends string> = Input extends '' | ||
? ParserError<'Empty string'> | ||
: // `*` | ||
Input extends `*${infer Remainder}` | ||
? [{ star: true }, EatWhitespace<Remainder>] | ||
: ParseIdentifier<Input> extends [infer Name, `${infer Remainder}`] | ||
? EatWhitespace<Remainder> extends `::${infer Remainder}` | ||
? ParseIdentifier<Remainder> extends [infer CastType, `${infer Remainder}`] | ||
? // `field::type` | ||
CastType extends PostgreSQLTypes | ||
? [{ name: Name; type: TypeScriptTypes<CastType> }, EatWhitespace<Remainder>] | ||
: never | ||
: ParserError<`Unexpected type cast at \`${Input}\``> | ||
: EatWhitespace<Remainder> extends `!inner${infer Remainder}` | ||
? EatWhitespace<Remainder> extends `!inner${infer Remainder}` | ||
? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [infer Fields, `${infer Remainder}`] | ||
? // `field!inner(nodes)` | ||
[{ name: Name; original: Name; children: Fields }, EatWhitespace<Remainder>] | ||
: ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string> | ||
? ParseEmbeddedResource<EatWhitespace<Remainder>> | ||
: ParserError<'Expected embedded resource after `!inner`'> | ||
: CreateParserErrorIfRequired< | ||
ParseEmbeddedResource<EatWhitespace<Remainder>>, | ||
'Expected embedded resource after `!inner`' | ||
> | ||
: EatWhitespace<Remainder> extends `!${infer Remainder}` | ||
@@ -366,5 +379,6 @@ ? ParseIdentifier<EatWhitespace<Remainder>> extends [infer Hint, `${infer Remainder}`] | ||
[{ name: Name; original: Name; hint: Hint; children: Fields }, EatWhitespace<Remainder>] | ||
: ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string> | ||
? ParseEmbeddedResource<EatWhitespace<Remainder>> | ||
: ParserError<'Expected embedded resource after `!inner`'> | ||
: CreateParserErrorIfRequired< | ||
ParseEmbeddedResource<EatWhitespace<Remainder>>, | ||
'Expected embedded resource after `!inner`' | ||
> | ||
: ParseEmbeddedResource<EatWhitespace<Remainder>> extends [ | ||
@@ -376,76 +390,7 @@ infer Fields, | ||
[{ name: Name; original: Name; hint: Hint; children: Fields }, EatWhitespace<Remainder>] | ||
: ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string> | ||
? ParseEmbeddedResource<EatWhitespace<Remainder>> | ||
: ParserError<'Expected embedded resource after `!hint`'> | ||
: CreateParserErrorIfRequired< | ||
ParseEmbeddedResource<EatWhitespace<Remainder>>, | ||
'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 `::${infer Remainder}` | ||
? ParseIdentifier<Remainder> extends [infer CastType, `${infer Remainder}`] | ||
? // `renamed_field:field::type` | ||
CastType extends PostgreSQLTypes | ||
? [{ name: Name; type: TypeScriptTypes<CastType> }, EatWhitespace<Remainder>] | ||
: never | ||
: ParserError<`Unexpected type cast at \`${Input}\``> | ||
: EatWhitespace<Remainder> extends `!inner${infer Remainder}` | ||
? ParseEmbeddedResource<EatWhitespace<Remainder>> extends [ | ||
infer Fields, | ||
`${infer Remainder}` | ||
] | ||
? // `renamed_field:field!inner(nodes)` | ||
[{ name: Name; 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 Remainder}` | ||
] | ||
? // `renamed_field:field!hint!inner(nodes)` | ||
[ | ||
{ name: Name; original: OriginalName; hint: Hint; 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 Remainder}` | ||
] | ||
? // `renamed_field:field!hint(nodes)` | ||
[ | ||
{ | ||
name: Name | ||
original: OriginalName | ||
hint: Hint | ||
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 Remainder}` | ||
] | ||
? // `renamed_field:field(nodes)` | ||
[{ name: Name; original: OriginalName; children: Fields }, EatWhitespace<Remainder>] | ||
: ParseJsonAccessor<EatWhitespace<Remainder>> extends [ | ||
infer _PropertyName, | ||
infer PropertyType, | ||
`${infer Remainder}` | ||
] | ||
? // `renamed_field:field->json...` | ||
[{ name: Name; type: PropertyType }, EatWhitespace<Remainder>] | ||
: ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string> | ||
? ParseEmbeddedResource<EatWhitespace<Remainder>> | ||
: // `renamed_field:field` | ||
[{ name: Name; original: OriginalName }, EatWhitespace<Remainder>] | ||
: ParseIdentifier<EatWhitespace<Remainder>> | ||
: ParseEmbeddedResource<EatWhitespace<Remainder>> extends [infer Fields, `${infer Remainder}`] | ||
@@ -460,5 +405,12 @@ ? // `field(nodes)` | ||
? // `field->json...` | ||
[{ name: PropertyName; type: PropertyType }, EatWhitespace<Remainder>] | ||
[{ name: PropertyName; original: PropertyName; type: PropertyType }, EatWhitespace<Remainder>] | ||
: ParseEmbeddedResource<EatWhitespace<Remainder>> extends ParserError<string> | ||
? ParseEmbeddedResource<EatWhitespace<Remainder>> | ||
: EatWhitespace<Remainder> extends `::${infer Remainder}` | ||
? ParseIdentifier<Remainder> extends [`${infer CastType}`, `${infer Remainder}`] | ||
? // `field::type` | ||
CastType extends PostgreSQLTypes | ||
? [{ name: Name; type: TypeScriptTypes<CastType> }, EatWhitespace<Remainder>] | ||
: ParserError<`Invalid type for \`::\` operator \`${CastType}\``> | ||
: ParserError<`Invalid type for \`::\` operator at \`${Remainder}\``> | ||
: // `field` | ||
@@ -469,2 +421,38 @@ [{ name: Name; original: Name }, EatWhitespace<Remainder>] | ||
/** | ||
* Parses a node. | ||
* A node is one of the following: | ||
* - `*` | ||
* - a field, as defined above | ||
* - a renamed field, `renamed_field:field` | ||
* - a spread field, `...field` | ||
*/ | ||
type ParseNode<Input extends string> = Input extends '' | ||
? ParserError<'Empty string'> | ||
: // `*` | ||
Input extends `*${infer Remainder}` | ||
? [{ star: true }, EatWhitespace<Remainder>] | ||
: // `...field` | ||
Input extends `...${infer Remainder}` | ||
? ParseField<EatWhitespace<Remainder>> extends [infer Field, `${infer Remainder}`] | ||
? Field extends { children: unknown[] } | ||
? [Prettify<{ spread: true } & Field>, EatWhitespace<Remainder>] | ||
: ParserError<'Unable to parse spread resource'> | ||
: ParserError<'Unable to parse spread resource'> | ||
: ParseIdentifier<Input> extends [infer Name, `${infer Remainder}`] | ||
? EatWhitespace<Remainder> extends `::${infer _Remainder}` | ||
? // `field::` | ||
// Special case to detect type-casting before renaming. | ||
ParseField<Input> | ||
: EatWhitespace<Remainder> extends `:${infer Remainder}` | ||
? // `renamed_field:` | ||
ParseField<EatWhitespace<Remainder>> extends [infer Field, `${infer Remainder}`] | ||
? Field extends { name: string } | ||
? [Prettify<Omit<Field, 'name'> & { name: Name }>, EatWhitespace<Remainder>] | ||
: ParserError<`Unable to parse renamed field`> | ||
: ParserError<`Unable to parse renamed field`> | ||
: // Otherwise, just parse it as a field without renaming. | ||
ParseField<Input> | ||
: ParserError<`Expected identifier at \`${Input}\``> | ||
/** | ||
* Parses a JSON property accessor of the shape `->a->b->c`. The last accessor in | ||
@@ -494,3 +482,3 @@ * the series may convert to text by using the ->> operator instead of ->. | ||
* Parses an embedded resource, which is an opening `(`, followed by a sequence of | ||
* nodes, separated by `,`, then a closing `)`. | ||
* 0 or more nodes separated by `,`, then a closing `)`. | ||
* | ||
@@ -503,7 +491,10 @@ * Returns a tuple of ["Parsed fields", "Remainder of text"], an error, | ||
? EatWhitespace<Remainder> extends `)${infer Remainder}` | ||
? Fields extends [] | ||
? ParserError<'Expected fields after `(`'> | ||
: [Fields, EatWhitespace<Remainder>] | ||
? [Fields, EatWhitespace<Remainder>] | ||
: ParserError<`Expected ")"`> | ||
: ParseNodes<EatWhitespace<Remainder>> | ||
: // If no nodes were detected, check for `)` for empty embedded resources `()`. | ||
ParseNodes<EatWhitespace<Remainder>> extends ParserError<string> | ||
? EatWhitespace<Remainder> extends `)${infer Remainder}` | ||
? [[], EatWhitespace<Remainder>] | ||
: ParseNodes<EatWhitespace<Remainder>> | ||
: ParserError<'Expected embedded resource fields or `)`'> | ||
: Input | ||
@@ -582,3 +573,5 @@ | ||
* | ||
* @param Row Record<string, unknown>. | ||
* @param Schema Database schema. | ||
* @param Row Type of a row in the given table. | ||
* @param Relationships Relationships between different tables in the database. | ||
* @param Query Select query string literal to parse. | ||
@@ -585,0 +578,0 @@ */ |
@@ -1,1 +0,1 @@ | ||
export const version = '1.11.0' | ||
export const version = '1.12.0' |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
366030
6094