@prisma-next/sql-lane-query-builder 0.3.0-dev.135 → 0.3.0-dev.147
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +12 -12
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/ref.ts +9 -6
- package/src/root.ts +8 -5
- package/src/select-builder.ts +5 -4
- package/src/selection.ts +4 -7
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Brand, StorageHashBase } from "@prisma-next/contract/types";
|
|
2
|
-
import { ExtractCodecTypes,
|
|
1
|
+
import { Brand, Contract, StorageHashBase } from "@prisma-next/contract/types";
|
|
2
|
+
import { ExtractCodecTypes, SqlStorage, StorageColumn } from "@prisma-next/sql-contract/types";
|
|
3
3
|
|
|
4
4
|
//#region src/type-errors.d.ts
|
|
5
5
|
|
|
@@ -85,8 +85,8 @@ type TableReferenceTooWideError<TMessage extends ErrorMessage> = Brand<TMessage>
|
|
|
85
85
|
*
|
|
86
86
|
* @template TContract The contract that describes the database.
|
|
87
87
|
*/
|
|
88
|
-
type Ref<TContract extends
|
|
89
|
-
readonly ['*']: TableAsterisk<TableName, TContract['storageHash']>;
|
|
88
|
+
type Ref<TContract extends Contract<SqlStorage>> = { readonly [TableName in keyof TContract['storage']['tables'] & string]: TableReference<TableName, TContract['storage']['storageHash']> & { readonly [ColumnName in Exclude<keyof TContract['storage']['tables'][TableName]['columns'], keyof TableReference> & string]: ColumnReference<ColumnName, TableName, TContract['storage']['storageHash']> } & {
|
|
89
|
+
readonly ['*']: TableAsterisk<TableName, TContract['storage']['storageHash']>;
|
|
90
90
|
} & Record<PropertyKey, ColumnReferenceOutOfContractError<`[error] reference to a non-existing column in the '${TableName}' table`>> } & {
|
|
91
91
|
readonly ['*']: Asterisk;
|
|
92
92
|
} & Record<PropertyKey, TableReferenceOutOfContractError<`[error] reference to a non-existing table in the contract`>>;
|
|
@@ -95,7 +95,7 @@ type Ref<TContract extends SqlContract> = { readonly [TableName in keyof TContra
|
|
|
95
95
|
*
|
|
96
96
|
* @template TContract The contract that describes the database.
|
|
97
97
|
*/
|
|
98
|
-
declare function createRef<TContract extends
|
|
98
|
+
declare function createRef<TContract extends Contract<SqlStorage>>(_contract: TContract): Ref<TContract>;
|
|
99
99
|
//#endregion
|
|
100
100
|
//#region src/type-atoms.d.ts
|
|
101
101
|
/**
|
|
@@ -139,7 +139,7 @@ type Simplify<TObject extends object> = DrainOuterGeneric<{ [K in keyof TObject]
|
|
|
139
139
|
* @template TTableName The name of the table containing the column.
|
|
140
140
|
* @template TColumnName The name of the column whose output type is to be extracted.
|
|
141
141
|
*/
|
|
142
|
-
type ExtractOutputType<TContract extends
|
|
142
|
+
type ExtractOutputType<TContract extends Contract<SqlStorage>, TTableName extends keyof TContract['storage']['tables'] & string, TColumnName extends keyof TContract['storage']['tables'][TTableName]['columns'] & string, _TColumn = TContract['storage']['tables'][TTableName]['columns'][TColumnName]> = _TColumn extends StorageColumn ? (_TColumn['nullable'] extends true ? null : never) | ExtractCodecTypes<TContract>[_TColumn['codecId']]['output'] : never;
|
|
143
143
|
/**
|
|
144
144
|
* A type representing a selection of columns in a SQL `select` query in the
|
|
145
145
|
* most generic form.
|
|
@@ -161,7 +161,7 @@ interface SelectionValue<TOutput, TDatatype extends string | unknown = unknown>
|
|
|
161
161
|
* @template TContract The contract that describes the database.
|
|
162
162
|
* @template TTableName The name of the table whose columns will be included in the selection.
|
|
163
163
|
*/
|
|
164
|
-
type TableToSelection<TContract extends
|
|
164
|
+
type TableToSelection<TContract extends Contract<SqlStorage>, TTableName extends keyof TContract['storage']['tables'] & string> = DrainOuterGeneric<{ readonly [ColumnName in keyof TContract['storage']['tables'][TTableName]['columns'] & string]: SelectionValue<ExtractOutputType<TContract, TTableName, ColumnName>, TContract['storage']['tables'][TTableName]['columns'][ColumnName]['nativeType']> }>;
|
|
165
165
|
//#endregion
|
|
166
166
|
//#region src/select-builder.d.ts
|
|
167
167
|
/**
|
|
@@ -171,11 +171,11 @@ type TableToSelection<TContract extends SqlContract, TTableName extends keyof TC
|
|
|
171
171
|
* @template TTables The tables involved in the current `select` query.
|
|
172
172
|
* @template TSelection The current selection of the `select` query.
|
|
173
173
|
*/
|
|
174
|
-
declare class SelectBuilder<TContract extends
|
|
174
|
+
declare class SelectBuilder<TContract extends Contract<SqlStorage>, TTables extends Contract<SqlStorage>['storage']['tables'], TSelection extends Selection = never> {
|
|
175
175
|
#private;
|
|
176
176
|
constructor(contract: TContract);
|
|
177
177
|
select(asterisk: Asterisk): ExactlyOneProperty<TTables> extends true ? SelectBuilder<TContract, TTables, MergeObjects<TSelection, TableToSelection<TContract, keyof TTables & string>>> : PreviousFunctionReceivedBadInputError<'[error] selecting all columns via `*` results in ambiguity when multiple tables are involved in the query'>;
|
|
178
|
-
select<TTableName extends keyof TTables & string>(asterisk: TableAsterisk<TTableName, TContract['storageHash']>): SelectBuilder<TContract, TTables, MergeObjects<TSelection, TableToSelection<TContract, TTableName>>>;
|
|
178
|
+
select<TTableName extends keyof TTables & string>(asterisk: TableAsterisk<TTableName, TContract['storage']['storageHash']>): SelectBuilder<TContract, TTables, MergeObjects<TSelection, TableToSelection<TContract, TTableName>>>;
|
|
179
179
|
select(arg: never): PreviousFunctionReceivedBadInputError<'[error] invalid input in previous `select()` call'>;
|
|
180
180
|
build(): IsNever<TSelection> extends true ? never : Simplify<TSelection>;
|
|
181
181
|
}
|
|
@@ -186,7 +186,7 @@ declare class SelectBuilder<TContract extends SqlContract, TTables extends SqlCo
|
|
|
186
186
|
*
|
|
187
187
|
* @template TContract The contract that describes the database.
|
|
188
188
|
*/
|
|
189
|
-
declare class Root<TContract extends
|
|
189
|
+
declare class Root<TContract extends Contract<SqlStorage>> {
|
|
190
190
|
#private;
|
|
191
191
|
constructor(contract: TContract);
|
|
192
192
|
/**
|
|
@@ -198,7 +198,7 @@ declare class Root<TContract extends SqlContract> {
|
|
|
198
198
|
/**
|
|
199
199
|
* @template TName The name of the table to select from.
|
|
200
200
|
*/
|
|
201
|
-
from<TName extends string>(table: string extends TName ? TableReferenceTooWideError<'[error] `root.from()` call received a table reference without a specific table name'> : TableReference<TName, TContract['storageHash']>): TName extends string ? SelectBuilder<TContract, Pick<TContract['storage']['tables'], TName>> : PreviousFunctionReceivedBadInputError<'[error] invalid table reference in previous `root.from()` call will probably cause runtime errors'>;
|
|
201
|
+
from<TName extends string>(table: string extends TName ? TableReferenceTooWideError<'[error] `root.from()` call received a table reference without a specific table name'> : TableReference<TName, TContract['storage']['storageHash']>): TName extends string ? SelectBuilder<TContract, Pick<TContract['storage']['tables'], TName>> : PreviousFunctionReceivedBadInputError<'[error] invalid table reference in previous `root.from()` call will probably cause runtime errors'>;
|
|
202
202
|
from(table: TableReferenceTooWideError<'[error] `root.from()` call received a table reference without a specific table name'>): PreviousFunctionReceivedBadInputError<'[error] invalid table reference in previous `root.from()` call will probably cause runtime errors'>;
|
|
203
203
|
}
|
|
204
204
|
/**
|
|
@@ -208,7 +208,7 @@ declare function createRoot(contract: never): PreviousFunctionReceivedBadInputEr
|
|
|
208
208
|
/**
|
|
209
209
|
* @template TContract The contract that describes the database.
|
|
210
210
|
*/
|
|
211
|
-
declare function createRoot<TContract extends
|
|
211
|
+
declare function createRoot<TContract extends Contract<SqlStorage>>(contract: TContract): Root<TContract>;
|
|
212
212
|
//#endregion
|
|
213
213
|
export { type Asterisk, type ColumnReference, type ColumnReferenceOutOfContractError, type DrainOuterGeneric, type ErrorMessage, type ExactlyOneProperty, type ExtractOutputType, type IsNever, type MergeObjects, type PreviousFunctionReceivedBadInputError, type Ref, type Root, type SelectBuilder, type Selection, type SelectionValue, type Simplify, type TableAsterisk, type TableReference, type TableReferenceOutOfContractError, type TableReferenceTooWideError, type TableToSelection, createRef, createRoot };
|
|
214
214
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/type-errors.ts","../src/column-reference.ts","../src/table-reference.ts","../src/ref.ts","../src/type-atoms.ts","../src/selection.ts","../src/select-builder.ts","../src/root.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAOA;AAQA;AAAmE,KARvD,YAAA,GAQuD,WAAA,MAAA,EAAA;;;;;;;ACLvD,KDKA,qCCLe,CAAA,iBDKwC,YCLxC,CAAA,GDKwD,KCLxD,CDK8D,QCL9D,CAAA;;;;;ADH3B;AAQA;;;;AAAwF,KCL5E,eDK4E,CAAA,oBAAA,MAAA,GAAA,MAAA,EAAA,mBAAA,MAAA,GAAA,MAAA,EAAA,cCFxE,eDEwE,CAAA,MAAA,CAAA,GCF9C,eDE8C,CAAA,MAAA,CAAA,CAAA,GAAA;oBCApE;qBACC;IACjB,mFAEC,cAAc;AATnB;;;;;;AASmB,KASP,iCATO,CAAA,iBAS4C,YAT5C,CAAA,GAS4D,KAT5D,CASkE,QATlE,CAAA;;;AASnB;AAA+D,KAKnD,QAAA,GALmD;EAAsB,SAAA,OAAA,EAAA,GAAA;EAAN,SAAA,QAAA,EAAA,IAAA;CAAK,GAQhF,KARgF,CAAA,6DAAA,CAAA;AAKpF;AAWA;;;;;AAQmB,KARP,aAQO,CAAA,mBAAA,MAAA,GAAA,MAAA,EAAA,cANH,eAMG,CAAA,MAAA,CAAA,GANuB,eAMvB,CAAA,MAAA,CAAA,CAAA,GAAA;EAFf,SAAA,OAAA,EAAA,GAAA;EAAK,SAAA,QAAA,EADY,UACZ;IAAL,yFAEC,cAAc;;;;;AD7CnB;AAQA;;;AAAmF,KENvE,cFMuE,CAAA,cAAA,MAAA,GAAA,MAAA,EAAA,cEJnE,eFImE,CAAA,MAAA,CAAA,GEJzC,eFIyC,CAAA,MAAA,CAAA,CAAA,GAAA;EAAK,SAAA,OAAA,EEFpE,KFEoE;IEDpF,8FAEF;;;ADNF;;;;AAMqB,KCST,gCDTS,CAAA,iBCSyC,YDTzC,CAAA,GCSyD,KDTzD,CCS+D,QDT/D,CAAA;;;;;AAYrB;;AAAqF,KCKzE,0BDLyE,CAAA,iBCK7B,YDL6B,CAAA,GCKb,KDLa,CCKP,QDLO,CAAA
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/type-errors.ts","../src/column-reference.ts","../src/table-reference.ts","../src/ref.ts","../src/type-atoms.ts","../src/selection.ts","../src/select-builder.ts","../src/root.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAOA;AAQA;AAAmE,KARvD,YAAA,GAQuD,WAAA,MAAA,EAAA;;;;;;;ACLvD,KDKA,qCCLe,CAAA,iBDKwC,YCLxC,CAAA,GDKwD,KCLxD,CDK8D,QCL9D,CAAA;;;;;ADH3B;AAQA;;;;AAAwF,KCL5E,eDK4E,CAAA,oBAAA,MAAA,GAAA,MAAA,EAAA,mBAAA,MAAA,GAAA,MAAA,EAAA,cCFxE,eDEwE,CAAA,MAAA,CAAA,GCF9C,eDE8C,CAAA,MAAA,CAAA,CAAA,GAAA;oBCApE;qBACC;IACjB,mFAEC,cAAc;AATnB;;;;;;AASmB,KASP,iCATO,CAAA,iBAS4C,YAT5C,CAAA,GAS4D,KAT5D,CASkE,QATlE,CAAA;;;AASnB;AAA+D,KAKnD,QAAA,GALmD;EAAsB,SAAA,OAAA,EAAA,GAAA;EAAN,SAAA,QAAA,EAAA,IAAA;CAAK,GAQhF,KARgF,CAAA,6DAAA,CAAA;AAKpF;AAWA;;;;;AAQmB,KARP,aAQO,CAAA,mBAAA,MAAA,GAAA,MAAA,EAAA,cANH,eAMG,CAAA,MAAA,CAAA,GANuB,eAMvB,CAAA,MAAA,CAAA,CAAA,GAAA;EAFf,SAAA,OAAA,EAAA,GAAA;EAAK,SAAA,QAAA,EADY,UACZ;IAAL,yFAEC,cAAc;;;;;AD7CnB;AAQA;;;AAAmF,KENvE,cFMuE,CAAA,cAAA,MAAA,GAAA,MAAA,EAAA,cEJnE,eFImE,CAAA,MAAA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;ADJnB;;;;;cOJa,uBAAuB,SAAS;;wBAGrB;ENJZ;;;;;EASP,IAAA,CAAA,KAAA,EMKM,cNLN,CAAA,KAAA,CAAA,CAAA,EMMA,qCNNA,CAAA,mGAAA,CAAA;EAAc;;;EASP,IAAA,CAAA,cAAA,MAAA,CAAA,CAAA,KAAA,EAAA,MAAiC,SMEnB,KNFmB,GMGrC,0BNHqC,CAAA,qFAAA,CAAA,GMIrC,cNJqC,CMItB,KNJsB,EMIf,SNJe,CAAA,SAAA,CAAA,CAAA,aAAA,CAAA,CAAA,CAAA,EMKxC,KNLwC,SAAA,MAAA,GMMvC,aNNuC,CMMzB,SNNyB,EMMd,INNc,CMMT,SNNS,CAAA,SAAA,CAAA,CAAA,QAAA,CAAA,EMMuB,KNNvB,CAAA,CAAA,GMOvC,qCNPuC,CAAA,mGAAA,CAAA;EAAkB,IAAA,CAAA,KAAA,EMSpD,0BNToD,CAAA,qFAAA,CAAA,CAAA,EMU1D,qCNV0D,CAAA,mGAAA,CAAA;;;;AAK/D;AAWY,iBMOI,UAAA,CNPS,QAAA,EAAA,KAAA,CAAA,EMStB,qCNTsB,CAAA,sGAAA,CAAA;;;;AAQpB,iBMKW,UNLX,CAAA,kBMKwC,QNLxC,CMKiD,UNLjD,CAAA,CAAA,CAAA,QAAA,EMMO,SNNP,CAAA,EMOF,INPE,CMOG,SNPH,CAAA"}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["#contract","#contract"],"sources":["../src/ref.ts","../src/select-builder.ts","../src/root.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["#contract","#contract"],"sources":["../src/ref.ts","../src/select-builder.ts","../src/root.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport type {\n Asterisk,\n ColumnReference,\n ColumnReferenceOutOfContractError,\n TableAsterisk,\n} from './column-reference';\nimport type { TableReference, TableReferenceOutOfContractError } from './table-reference';\n\n/**\n * A fluent API representing references to tables and columns in a SQL contract.\n *\n * @template TContract The contract that describes the database.\n */\nexport type Ref<TContract extends Contract<SqlStorage>> = {\n readonly [TableName in keyof TContract['storage']['tables'] & string]: TableReference<\n TableName,\n TContract['storage']['storageHash']\n > & {\n readonly [ColumnName in Exclude<\n keyof TContract['storage']['tables'][TableName]['columns'],\n keyof TableReference\n > &\n string]: ColumnReference<ColumnName, TableName, TContract['storage']['storageHash']>;\n } & {\n readonly ['*']: TableAsterisk<TableName, TContract['storage']['storageHash']>;\n } & Record<\n PropertyKey,\n ColumnReferenceOutOfContractError<`[error] reference to a non-existing column in the '${TableName}' table`>\n >;\n} & {\n readonly ['*']: Asterisk;\n} & Record<\n PropertyKey,\n TableReferenceOutOfContractError<`[error] reference to a non-existing table in the contract`>\n >;\n\n/**\n * Creates a reference object for the given SQL contract.\n *\n * @template TContract The contract that describes the database.\n */\nexport function createRef<TContract extends Contract<SqlStorage>>(\n _contract: TContract,\n): Ref<TContract> {\n return new Proxy({} as Ref<TContract>, {\n get(_target, tableName) {\n if (tableName === '*') {\n return Object.freeze({\n '~name': tableName,\n '~table': null,\n });\n }\n\n return new Proxy(\n {},\n {\n get(_target, columnName) {\n if (columnName === '~name') {\n return tableName;\n }\n\n return Object.freeze({\n '~name': columnName,\n '~table': tableName,\n });\n },\n },\n );\n },\n });\n}\n","import type { Contract } from '@prisma-next/contract/types';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { Asterisk, TableAsterisk } from './column-reference';\nimport type { Selection, TableToSelection } from './selection';\nimport type { ExactlyOneProperty, IsNever, MergeObjects, Simplify } from './type-atoms';\nimport type { PreviousFunctionReceivedBadInputError } from './type-errors';\n\n/**\n * A builder for SQL `select` queries.\n *\n * @template TContract The contract that describes the database.\n * @template TTables The tables involved in the current `select` query.\n * @template TSelection The current selection of the `select` query.\n */\nexport class SelectBuilder<\n TContract extends Contract<SqlStorage>,\n TTables extends Contract<SqlStorage>['storage']['tables'],\n TSelection extends Selection = never,\n> {\n // @ts-expect-error\n // biome-ignore lint/correctness/noUnusedPrivateClassMembers: will be used soon.\n readonly #contract: TContract;\n\n constructor(contract: TContract) {\n this.#contract = contract;\n }\n\n select(\n asterisk: Asterisk,\n ): ExactlyOneProperty<TTables> extends true\n ? SelectBuilder<\n TContract,\n TTables,\n MergeObjects<TSelection, TableToSelection<TContract, keyof TTables & string>>\n >\n : PreviousFunctionReceivedBadInputError<'[error] selecting all columns via `*` results in ambiguity when multiple tables are involved in the query'>;\n select<TTableName extends keyof TTables & string>(\n asterisk: TableAsterisk<TTableName, TContract['storage']['storageHash']>,\n ): SelectBuilder<\n TContract,\n TTables,\n MergeObjects<TSelection, TableToSelection<TContract, TTableName>>\n >;\n select(\n arg: never,\n ): PreviousFunctionReceivedBadInputError<'[error] invalid input in previous `select()` call'>;\n select(..._args: unknown[]): unknown {\n // TODO: do runtime stuff.\n return this;\n }\n\n // TODO: the return type here is not the real one we'll use eventually.\n // I'm using something to test the selection stuff.\n build(): IsNever<TSelection> extends true\n ? // TODO: either split to two builders or provide a type-level error here.\n never\n : Simplify<TSelection> {\n // TODO: do runtime stuff.\n return {} as never;\n }\n}\n","import type { Contract } from '@prisma-next/contract/types';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport { SelectBuilder } from './select-builder';\nimport type { TableReference, TableReferenceTooWideError } from './table-reference';\nimport type { PreviousFunctionReceivedBadInputError } from './type-errors';\n\n/**\n * The root of all builder.\n *\n * @template TContract The contract that describes the database.\n */\nexport class Root<TContract extends Contract<SqlStorage>> {\n readonly #contract: TContract;\n\n constructor(contract: TContract) {\n this.#contract = contract;\n }\n\n /**\n * SQL's `from` clause, where all `select` queries actually start from.\n *\n * @param table The table to select from.\n */\n from(\n table: TableReference<never>,\n ): PreviousFunctionReceivedBadInputError<'[error] invalid table reference in previous `root.from()` call will probably cause runtime errors'>;\n /**\n * @template TName The name of the table to select from.\n */\n from<TName extends string>(\n table: string extends TName\n ? TableReferenceTooWideError<'[error] `root.from()` call received a table reference without a specific table name'>\n : TableReference<TName, TContract['storage']['storageHash']>,\n ): TName extends string\n ? SelectBuilder<TContract, Pick<TContract['storage']['tables'], TName>>\n : PreviousFunctionReceivedBadInputError<'[error] invalid table reference in previous `root.from()` call will probably cause runtime errors'>;\n from(\n table: TableReferenceTooWideError<'[error] `root.from()` call received a table reference without a specific table name'>,\n ): PreviousFunctionReceivedBadInputError<'[error] invalid table reference in previous `root.from()` call will probably cause runtime errors'>;\n /**\n * @internal\n */\n from(_table: unknown): unknown {\n // TODO: use runtime table reference value to do something \"AST\"-related.\n return new SelectBuilder(this.#contract);\n }\n}\n\n/**\n * Creates a new `Root` instance.\n */\nexport function createRoot(\n contract: never,\n): PreviousFunctionReceivedBadInputError<'[error] root creation will likely fail at runtime given the passed contract is not valid or verified'>;\n/**\n * @template TContract The contract that describes the database.\n */\nexport function createRoot<TContract extends Contract<SqlStorage>>(\n contract: TContract,\n): Root<TContract>;\n/**\n * @internal\n */\nexport function createRoot(contract: unknown): unknown {\n return new Root(contract as Contract<SqlStorage>);\n}\n"],"mappings":";;;;;;AA2CA,SAAgB,UACd,WACgB;AAChB,QAAO,IAAI,MAAM,EAAE,EAAoB,EACrC,IAAI,SAAS,WAAW;AACtB,MAAI,cAAc,IAChB,QAAO,OAAO,OAAO;GACnB,SAAS;GACT,UAAU;GACX,CAAC;AAGJ,SAAO,IAAI,MACT,EAAE,EACF,EACE,IAAI,WAAS,YAAY;AACvB,OAAI,eAAe,QACjB,QAAO;AAGT,UAAO,OAAO,OAAO;IACnB,SAAS;IACT,UAAU;IACX,CAAC;KAEL,CACF;IAEJ,CAAC;;;;;;;;;;;;ACzDJ,IAAa,gBAAb,MAIE;CAGA,CAASA;CAET,YAAY,UAAqB;AAC/B,QAAKA,WAAY;;CAsBnB,OAAO,GAAG,OAA2B;AAEnC,SAAO;;CAKT,QAGyB;AAEvB,SAAO,EAAE;;;;;;;;;;;AC/Cb,IAAa,OAAb,MAA0D;CACxD,CAASC;CAET,YAAY,UAAqB;AAC/B,QAAKA,WAAY;;;;;CA2BnB,KAAK,QAA0B;AAE7B,SAAO,IAAI,cAAc,MAAKA,SAAU;;;;;;AAmB5C,SAAgB,WAAW,UAA4B;AACrD,QAAO,IAAI,KAAK,SAAiC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/sql-lane-query-builder",
|
|
3
|
-
"version": "0.3.0-dev.
|
|
3
|
+
"version": "0.3.0-dev.147",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "SQL query builder lane for Prisma Next",
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
"tsdown": "0.18.4",
|
|
9
9
|
"typescript": "5.9.3",
|
|
10
10
|
"vitest": "4.0.17",
|
|
11
|
-
"@prisma-next/contract": "0.3.0-dev.
|
|
12
|
-
"@prisma-next/sql-contract": "0.3.0-dev.135",
|
|
11
|
+
"@prisma-next/contract": "0.3.0-dev.147",
|
|
13
12
|
"@prisma-next/tsconfig": "0.0.0",
|
|
13
|
+
"@prisma-next/sql-contract": "0.3.0-dev.147",
|
|
14
14
|
"@prisma-next/tsdown": "0.0.0"
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
package/src/ref.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Contract } from '@prisma-next/contract/types';
|
|
2
|
+
import type { SqlStorage } from '@prisma-next/sql-contract/types';
|
|
2
3
|
import type {
|
|
3
4
|
Asterisk,
|
|
4
5
|
ColumnReference,
|
|
@@ -12,18 +13,18 @@ import type { TableReference, TableReferenceOutOfContractError } from './table-r
|
|
|
12
13
|
*
|
|
13
14
|
* @template TContract The contract that describes the database.
|
|
14
15
|
*/
|
|
15
|
-
export type Ref<TContract extends
|
|
16
|
+
export type Ref<TContract extends Contract<SqlStorage>> = {
|
|
16
17
|
readonly [TableName in keyof TContract['storage']['tables'] & string]: TableReference<
|
|
17
18
|
TableName,
|
|
18
|
-
TContract['storageHash']
|
|
19
|
+
TContract['storage']['storageHash']
|
|
19
20
|
> & {
|
|
20
21
|
readonly [ColumnName in Exclude<
|
|
21
22
|
keyof TContract['storage']['tables'][TableName]['columns'],
|
|
22
23
|
keyof TableReference
|
|
23
24
|
> &
|
|
24
|
-
string]: ColumnReference<ColumnName, TableName, TContract['storageHash']>;
|
|
25
|
+
string]: ColumnReference<ColumnName, TableName, TContract['storage']['storageHash']>;
|
|
25
26
|
} & {
|
|
26
|
-
readonly ['*']: TableAsterisk<TableName, TContract['storageHash']>;
|
|
27
|
+
readonly ['*']: TableAsterisk<TableName, TContract['storage']['storageHash']>;
|
|
27
28
|
} & Record<
|
|
28
29
|
PropertyKey,
|
|
29
30
|
ColumnReferenceOutOfContractError<`[error] reference to a non-existing column in the '${TableName}' table`>
|
|
@@ -40,7 +41,9 @@ export type Ref<TContract extends SqlContract> = {
|
|
|
40
41
|
*
|
|
41
42
|
* @template TContract The contract that describes the database.
|
|
42
43
|
*/
|
|
43
|
-
export function createRef<TContract extends
|
|
44
|
+
export function createRef<TContract extends Contract<SqlStorage>>(
|
|
45
|
+
_contract: TContract,
|
|
46
|
+
): Ref<TContract> {
|
|
44
47
|
return new Proxy({} as Ref<TContract>, {
|
|
45
48
|
get(_target, tableName) {
|
|
46
49
|
if (tableName === '*') {
|
package/src/root.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Contract } from '@prisma-next/contract/types';
|
|
2
|
+
import type { SqlStorage } from '@prisma-next/sql-contract/types';
|
|
2
3
|
import { SelectBuilder } from './select-builder';
|
|
3
4
|
import type { TableReference, TableReferenceTooWideError } from './table-reference';
|
|
4
5
|
import type { PreviousFunctionReceivedBadInputError } from './type-errors';
|
|
@@ -8,7 +9,7 @@ import type { PreviousFunctionReceivedBadInputError } from './type-errors';
|
|
|
8
9
|
*
|
|
9
10
|
* @template TContract The contract that describes the database.
|
|
10
11
|
*/
|
|
11
|
-
export class Root<TContract extends
|
|
12
|
+
export class Root<TContract extends Contract<SqlStorage>> {
|
|
12
13
|
readonly #contract: TContract;
|
|
13
14
|
|
|
14
15
|
constructor(contract: TContract) {
|
|
@@ -29,7 +30,7 @@ export class Root<TContract extends SqlContract> {
|
|
|
29
30
|
from<TName extends string>(
|
|
30
31
|
table: string extends TName
|
|
31
32
|
? TableReferenceTooWideError<'[error] `root.from()` call received a table reference without a specific table name'>
|
|
32
|
-
: TableReference<TName, TContract['storageHash']>,
|
|
33
|
+
: TableReference<TName, TContract['storage']['storageHash']>,
|
|
33
34
|
): TName extends string
|
|
34
35
|
? SelectBuilder<TContract, Pick<TContract['storage']['tables'], TName>>
|
|
35
36
|
: PreviousFunctionReceivedBadInputError<'[error] invalid table reference in previous `root.from()` call will probably cause runtime errors'>;
|
|
@@ -54,10 +55,12 @@ export function createRoot(
|
|
|
54
55
|
/**
|
|
55
56
|
* @template TContract The contract that describes the database.
|
|
56
57
|
*/
|
|
57
|
-
export function createRoot<TContract extends
|
|
58
|
+
export function createRoot<TContract extends Contract<SqlStorage>>(
|
|
59
|
+
contract: TContract,
|
|
60
|
+
): Root<TContract>;
|
|
58
61
|
/**
|
|
59
62
|
* @internal
|
|
60
63
|
*/
|
|
61
64
|
export function createRoot(contract: unknown): unknown {
|
|
62
|
-
return new Root(contract as
|
|
65
|
+
return new Root(contract as Contract<SqlStorage>);
|
|
63
66
|
}
|
package/src/select-builder.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Contract } from '@prisma-next/contract/types';
|
|
2
|
+
import type { SqlStorage } from '@prisma-next/sql-contract/types';
|
|
2
3
|
import type { Asterisk, TableAsterisk } from './column-reference';
|
|
3
4
|
import type { Selection, TableToSelection } from './selection';
|
|
4
5
|
import type { ExactlyOneProperty, IsNever, MergeObjects, Simplify } from './type-atoms';
|
|
@@ -12,8 +13,8 @@ import type { PreviousFunctionReceivedBadInputError } from './type-errors';
|
|
|
12
13
|
* @template TSelection The current selection of the `select` query.
|
|
13
14
|
*/
|
|
14
15
|
export class SelectBuilder<
|
|
15
|
-
TContract extends
|
|
16
|
-
TTables extends
|
|
16
|
+
TContract extends Contract<SqlStorage>,
|
|
17
|
+
TTables extends Contract<SqlStorage>['storage']['tables'],
|
|
17
18
|
TSelection extends Selection = never,
|
|
18
19
|
> {
|
|
19
20
|
// @ts-expect-error
|
|
@@ -34,7 +35,7 @@ export class SelectBuilder<
|
|
|
34
35
|
>
|
|
35
36
|
: PreviousFunctionReceivedBadInputError<'[error] selecting all columns via `*` results in ambiguity when multiple tables are involved in the query'>;
|
|
36
37
|
select<TTableName extends keyof TTables & string>(
|
|
37
|
-
asterisk: TableAsterisk<TTableName, TContract['storageHash']>,
|
|
38
|
+
asterisk: TableAsterisk<TTableName, TContract['storage']['storageHash']>,
|
|
38
39
|
): SelectBuilder<
|
|
39
40
|
TContract,
|
|
40
41
|
TTables,
|
package/src/selection.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
SqlContract,
|
|
4
|
-
StorageColumn,
|
|
5
|
-
} from '@prisma-next/sql-contract/types';
|
|
1
|
+
import type { Contract } from '@prisma-next/contract/types';
|
|
2
|
+
import type { ExtractCodecTypes, SqlStorage, StorageColumn } from '@prisma-next/sql-contract/types';
|
|
6
3
|
import type { DrainOuterGeneric } from './type-atoms';
|
|
7
4
|
|
|
8
5
|
/**
|
|
@@ -14,7 +11,7 @@ import type { DrainOuterGeneric } from './type-atoms';
|
|
|
14
11
|
* @template TColumnName The name of the column whose output type is to be extracted.
|
|
15
12
|
*/
|
|
16
13
|
export type ExtractOutputType<
|
|
17
|
-
TContract extends
|
|
14
|
+
TContract extends Contract<SqlStorage>,
|
|
18
15
|
TTableName extends keyof TContract['storage']['tables'] & string,
|
|
19
16
|
TColumnName extends keyof TContract['storage']['tables'][TTableName]['columns'] & string,
|
|
20
17
|
_TColumn = TContract['storage']['tables'][TTableName]['columns'][TColumnName],
|
|
@@ -48,7 +45,7 @@ export interface SelectionValue<TOutput, TDatatype extends string | unknown = un
|
|
|
48
45
|
* @template TTableName The name of the table whose columns will be included in the selection.
|
|
49
46
|
*/
|
|
50
47
|
export type TableToSelection<
|
|
51
|
-
TContract extends
|
|
48
|
+
TContract extends Contract<SqlStorage>,
|
|
52
49
|
TTableName extends keyof TContract['storage']['tables'] & string,
|
|
53
50
|
> = DrainOuterGeneric<{
|
|
54
51
|
readonly [ColumnName in keyof TContract['storage']['tables'][TTableName]['columns'] &
|