@prisma-next/sql-orm-lane 0.3.0-dev.1 → 0.3.0-dev.10
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/README.md +2 -2
- package/dist/exports/orm.d.ts +3 -5
- package/dist/exports/orm.d.ts.map +1 -0
- package/dist/index.d.ts +4 -42
- package/dist/index.d.ts.map +1 -0
- package/dist/mutations/delete-builder.d.ts +9 -0
- package/dist/mutations/delete-builder.d.ts.map +1 -0
- package/dist/mutations/insert-builder.d.ts +7 -0
- package/dist/mutations/insert-builder.d.ts.map +1 -0
- package/dist/mutations/update-builder.d.ts +9 -0
- package/dist/mutations/update-builder.d.ts.map +1 -0
- package/dist/orm/builder.d.ts +38 -0
- package/dist/orm/builder.d.ts.map +1 -0
- package/dist/orm/capabilities.d.ts +3 -0
- package/dist/orm/capabilities.d.ts.map +1 -0
- package/dist/orm/context.d.ts +5 -0
- package/dist/orm/context.d.ts.map +1 -0
- package/dist/orm/state.d.ts +45 -0
- package/dist/orm/state.d.ts.map +1 -0
- package/dist/orm-include-child.d.ts +35 -0
- package/dist/orm-include-child.d.ts.map +1 -0
- package/dist/orm-relation-filter.d.ts +19 -0
- package/dist/orm-relation-filter.d.ts.map +1 -0
- package/dist/{orm-DAnGd7z2.d.ts → orm-types.d.ts} +16 -27
- package/dist/orm-types.d.ts.map +1 -0
- package/dist/orm.d.ts +5 -0
- package/dist/orm.d.ts.map +1 -0
- package/dist/plan/lowering.d.ts +2 -0
- package/dist/plan/lowering.d.ts.map +1 -0
- package/dist/plan/plan-assembly.d.ts +24 -0
- package/dist/plan/plan-assembly.d.ts.map +1 -0
- package/dist/plan/result-typing.d.ts +2 -0
- package/dist/plan/result-typing.d.ts.map +1 -0
- package/dist/relations/include-plan.d.ts +38 -0
- package/dist/relations/include-plan.d.ts.map +1 -0
- package/dist/selection/join.d.ts +3 -0
- package/dist/selection/join.d.ts.map +1 -0
- package/dist/selection/ordering.d.ts +11 -0
- package/dist/selection/ordering.d.ts.map +1 -0
- package/dist/selection/pagination.d.ts +6 -0
- package/dist/selection/pagination.d.ts.map +1 -0
- package/dist/selection/predicates.d.ts +10 -0
- package/dist/selection/predicates.d.ts.map +1 -0
- package/dist/selection/projection.d.ts +28 -0
- package/dist/selection/projection.d.ts.map +1 -0
- package/dist/selection/select-builder.d.ts +22 -0
- package/dist/selection/select-builder.d.ts.map +1 -0
- package/dist/types/internal.d.ts +4 -0
- package/dist/types/internal.d.ts.map +1 -0
- package/dist/utils/ast.d.ts +2 -0
- package/dist/utils/ast.d.ts.map +1 -0
- package/dist/utils/errors.d.ts +29 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/param-descriptor.d.ts +10 -0
- package/dist/utils/param-descriptor.d.ts.map +1 -0
- package/package.json +16 -16
- package/src/exports/orm.ts +12 -0
- package/src/index.ts +11 -0
- package/src/mutations/delete-builder.ts +87 -0
- package/src/mutations/insert-builder.ts +148 -0
- package/src/mutations/update-builder.ts +141 -0
- package/src/orm/builder.ts +744 -0
- package/src/orm/capabilities.ts +14 -0
- package/src/orm/context.ts +10 -0
- package/src/orm/state.ts +52 -0
- package/src/orm-include-child.ts +169 -0
- package/src/orm-relation-filter.ts +93 -0
- package/src/orm-types.ts +271 -0
- package/src/orm.ts +51 -0
- package/src/plan/lowering.ts +1 -0
- package/src/plan/plan-assembly.ts +297 -0
- package/src/plan/result-typing.ts +1 -0
- package/src/relations/include-plan.ts +324 -0
- package/src/selection/join.ts +13 -0
- package/src/selection/ordering.ts +52 -0
- package/src/selection/pagination.ts +11 -0
- package/src/selection/predicates.ts +120 -0
- package/src/selection/projection.ts +136 -0
- package/src/selection/select-builder.ts +82 -0
- package/src/types/internal.ts +3 -0
- package/src/utils/ast.ts +12 -0
- package/src/utils/errors.ts +130 -0
- package/src/utils/param-descriptor.ts +19 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"predicates.d.ts","sourceRoot":"","sources":["../../src/selection/predicates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAiB,MAAM,iCAAiC,CAAC;AAC9F,OAAO,KAAK,EACV,UAAU,EAIX,MAAM,sCAAsC,CAAC;AAE9C,OAAO,KAAK,EAAE,aAAa,EAAoB,MAAM,wCAAwC,CAAC;AAe9F,wBAAgB,cAAc,CAC5B,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE,WAAW,CAAC,UAAU,CAAC,EACjC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,WAAW,EAAE,eAAe,EAAE,EAC9B,MAAM,EAAE,OAAO,EAAE,GAChB;IACD,IAAI,EAAE,UAAU,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,CAqFA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { TableRef } from '@prisma-next/sql-relational-core/ast';
|
|
2
|
+
import type { AnyBinaryBuilder, AnyColumnBuilder, AnyOrderBuilder, JoinOnPredicate, NestedProjection } from '@prisma-next/sql-relational-core/types';
|
|
3
|
+
export interface ProjectionState {
|
|
4
|
+
readonly aliases: string[];
|
|
5
|
+
readonly columns: AnyColumnBuilder[];
|
|
6
|
+
}
|
|
7
|
+
export type ProjectionInput = Record<string, AnyColumnBuilder | boolean | NestedProjection>;
|
|
8
|
+
export declare class AliasTracker {
|
|
9
|
+
private readonly aliases;
|
|
10
|
+
private readonly aliasToPath;
|
|
11
|
+
register(path: string[]): string;
|
|
12
|
+
getPath(alias: string): string[] | undefined;
|
|
13
|
+
has(alias: string): boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function flattenProjection(projection: NestedProjection, tracker: AliasTracker, currentPath?: string[]): {
|
|
16
|
+
aliases: string[];
|
|
17
|
+
columns: AnyColumnBuilder[];
|
|
18
|
+
};
|
|
19
|
+
export declare function buildProjectionState(_table: TableRef, projection: ProjectionInput, includes?: ReadonlyArray<{
|
|
20
|
+
readonly alias: string;
|
|
21
|
+
readonly table: TableRef;
|
|
22
|
+
readonly on: JoinOnPredicate;
|
|
23
|
+
readonly childProjection: ProjectionState;
|
|
24
|
+
readonly childWhere?: AnyBinaryBuilder;
|
|
25
|
+
readonly childOrderBy?: AnyOrderBuilder;
|
|
26
|
+
readonly childLimit?: number;
|
|
27
|
+
}>): ProjectionState;
|
|
28
|
+
//# sourceMappingURL=projection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../../src/selection/projection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sCAAsC,CAAC;AACrE,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,gBAAgB,EACjB,MAAM,wCAAwC,CAAC;AAWhD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,gBAAgB,EAAE,CAAC;CACtC;AAED,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,GAAG,gBAAgB,CAAC,CAAC;AAS5F,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAC7C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA+B;IAE3D,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM;IAWhC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS;IAI5C,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAG5B;AAED,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,gBAAgB,EAC5B,OAAO,EAAE,YAAY,EACrB,WAAW,GAAE,MAAM,EAAO,GACzB;IAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,EAAE,gBAAgB,EAAE,CAAA;CAAE,CAqBpD;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,QAAQ,EAChB,UAAU,EAAE,eAAe,EAC3B,QAAQ,CAAC,EAAE,aAAa,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,QAAQ,CAAC,EAAE,EAAE,eAAe,CAAC;IAC7B,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;IAC1C,QAAQ,CAAC,UAAU,CAAC,EAAE,gBAAgB,CAAC;IACvC,QAAQ,CAAC,YAAY,CAAC,EAAE,eAAe,CAAC;IACxC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC,GACD,eAAe,CAwCjB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { BinaryExpr, ColumnRef, Direction, ExistsExpr, IncludeAst, IncludeRef, OperationExpr, SelectAst, TableRef } from '@prisma-next/sql-relational-core/ast';
|
|
2
|
+
import type { IncludeState } from '../relations/include-plan';
|
|
3
|
+
import type { ProjectionState } from './projection';
|
|
4
|
+
export declare function buildProjectionItems(projectionState: ProjectionState, includesForMeta: ReadonlyArray<IncludeState>): Array<{
|
|
5
|
+
alias: string;
|
|
6
|
+
expr: ColumnRef | IncludeRef | OperationExpr;
|
|
7
|
+
}>;
|
|
8
|
+
export declare function buildSelectAst(params: {
|
|
9
|
+
table: TableRef;
|
|
10
|
+
projectEntries: Array<{
|
|
11
|
+
alias: string;
|
|
12
|
+
expr: ColumnRef | IncludeRef | OperationExpr;
|
|
13
|
+
}>;
|
|
14
|
+
includesAst?: ReadonlyArray<IncludeAst>;
|
|
15
|
+
whereExpr?: BinaryExpr | ExistsExpr;
|
|
16
|
+
orderByClause?: ReadonlyArray<{
|
|
17
|
+
expr: ColumnRef | OperationExpr;
|
|
18
|
+
dir: Direction;
|
|
19
|
+
}>;
|
|
20
|
+
limit?: number;
|
|
21
|
+
}): SelectAst;
|
|
22
|
+
//# sourceMappingURL=select-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select-builder.d.ts","sourceRoot":"","sources":["../../src/selection/select-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EACT,SAAS,EACT,UAAU,EACV,UAAU,EACV,UAAU,EACV,aAAa,EACb,SAAS,EACT,QAAQ,EACT,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAG9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,wBAAgB,oBAAoB,CAClC,eAAe,EAAE,eAAe,EAChC,eAAe,EAAE,aAAa,CAAC,YAAY,CAAC,GAC3C,KAAK,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,SAAS,GAAG,UAAU,GAAG,aAAa,CAAA;CAAE,CAAC,CAwCxE;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE;IACrC,KAAK,EAAE,QAAQ,CAAC;IAChB,cAAc,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,SAAS,GAAG,UAAU,GAAG,aAAa,CAAA;KAAE,CAAC,CAAC;IACvF,WAAW,CAAC,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;IACxC,SAAS,CAAC,EAAE,UAAU,GAAG,UAAU,CAAC;IACpC,aAAa,CAAC,EAAE,aAAa,CAAC;QAC5B,IAAI,EAAE,SAAS,GAAG,aAAa,CAAC;QAChC,GAAG,EAAE,SAAS,CAAC;KAChB,CAAC,CAAC;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,GAAG,SAAS,CAUZ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/types/internal.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACrF,YAAY,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,YAAY,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../../src/utils/ast.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,cAAc,EACd,eAAe,GAChB,MAAM,sCAAsC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { StorageColumn } from '@prisma-next/sql-contract/types';
|
|
2
|
+
export declare function errorModelNotFound(modelName: string): never;
|
|
3
|
+
export declare function errorTableNotFound(tableName: string): never;
|
|
4
|
+
export declare function errorUnknownTable(tableName: string): never;
|
|
5
|
+
export declare function errorUnknownColumn(columnName: string, tableName: string): never;
|
|
6
|
+
export declare function errorMissingParameter(paramName: string): never;
|
|
7
|
+
export declare function errorAliasPathEmpty(): never;
|
|
8
|
+
export declare function errorAliasCollision(path: string[], alias: string, existingPath?: string[]): never;
|
|
9
|
+
export declare function errorInvalidProjectionValue(path: string[]): never;
|
|
10
|
+
export declare function errorIncludeAliasNotFound(alias: string): never;
|
|
11
|
+
export declare function errorInvalidProjectionKey(key: string): never;
|
|
12
|
+
export declare function errorProjectionEmpty(): never;
|
|
13
|
+
export declare function errorCreateRequiresFields(): never;
|
|
14
|
+
export declare function errorUpdateRequiresFields(): never;
|
|
15
|
+
export declare function errorIncludeRequiresCapabilities(): never;
|
|
16
|
+
export declare function errorIncludeCapabilitiesNotTrue(): never;
|
|
17
|
+
export declare function errorMultiColumnJoinsNotSupported(): never;
|
|
18
|
+
export declare function errorJoinColumnsMustBeDefined(): never;
|
|
19
|
+
export declare function errorColumnNotFound(columnName: string, tableName: string): never;
|
|
20
|
+
export declare function errorChildProjectionMustBeSpecified(): never;
|
|
21
|
+
export declare function errorChildProjectionEmpty(): never;
|
|
22
|
+
export declare function errorMissingAlias(index: number): never;
|
|
23
|
+
export declare function errorMissingColumn(alias: string, index: number): never;
|
|
24
|
+
export declare function errorInvalidColumn(alias: string, index: number): never;
|
|
25
|
+
export declare function errorRelationNotFound(relationName: string, modelName: string): never;
|
|
26
|
+
export declare function errorFailedToBuildWhereClause(): never;
|
|
27
|
+
export declare function assertColumnExists(columnMeta: StorageColumn | undefined, columnName: string, tableName: string): asserts columnMeta is StorageColumn;
|
|
28
|
+
export declare function assertParameterExists(paramsMap: Record<string, unknown>, paramName: string): unknown;
|
|
29
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAErE,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,KAAK,CAE3D;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,KAAK,CAE3D;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,KAAK,CAE1D;AAED,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,KAAK,CAE/E;AAED,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,KAAK,CAE9D;AAED,wBAAgB,mBAAmB,IAAI,KAAK,CAE3C;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,EAAE,GAAG,KAAK,CAIjG;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,CAIjE;AAED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,CAI9D;AAED,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAI5D;AAED,wBAAgB,oBAAoB,IAAI,KAAK,CAE5C;AAED,wBAAgB,yBAAyB,IAAI,KAAK,CAEjD;AAED,wBAAgB,yBAAyB,IAAI,KAAK,CAEjD;AAED,wBAAgB,gCAAgC,IAAI,KAAK,CAExD;AAED,wBAAgB,+BAA+B,IAAI,KAAK,CAEvD;AAED,wBAAgB,iCAAiC,IAAI,KAAK,CAEzD;AAED,wBAAgB,6BAA6B,IAAI,KAAK,CAErD;AAED,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,KAAK,CAEhF;AAED,wBAAgB,mCAAmC,IAAI,KAAK,CAE3D;AAED,wBAAgB,yBAAyB,IAAI,KAAK,CAEjD;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,CAEtD;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK,CAEtE;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK,CAEtE;AAED,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,KAAK,CAEpF;AAED,wBAAgB,6BAA6B,IAAI,KAAK,CAErD;AAED,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,aAAa,GAAG,SAAS,EACrC,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,UAAU,IAAI,aAAa,CAIrC;AAED,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,SAAS,EAAE,MAAM,GAChB,OAAO,CAKT"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ParamDescriptor } from '@prisma-next/contract/types';
|
|
2
|
+
export declare function createParamDescriptor(args: {
|
|
3
|
+
name: string;
|
|
4
|
+
table: string;
|
|
5
|
+
column: string;
|
|
6
|
+
codecId?: string;
|
|
7
|
+
nativeType?: string;
|
|
8
|
+
nullable: boolean;
|
|
9
|
+
}): ParamDescriptor;
|
|
10
|
+
//# sourceMappingURL=param-descriptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"param-descriptor.d.ts","sourceRoot":"","sources":["../../src/utils/param-descriptor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAEnE,wBAAgB,qBAAqB,CAAC,IAAI,EAAE;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;CACnB,GAAG,eAAe,CASlB"}
|
package/package.json
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/sql-orm-lane",
|
|
3
|
-
"version": "0.3.0-dev.
|
|
3
|
+
"version": "0.3.0-dev.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "ORM builder, include lowering, and relation filters for Prisma Next",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@prisma-next/
|
|
9
|
-
"@prisma-next/
|
|
10
|
-
"@prisma-next/sql-contract": "0.3.0-dev.
|
|
11
|
-
"@prisma-next/sql-lane": "0.3.0-dev.
|
|
12
|
-
"@prisma-next/sql-relational-core": "0.3.0-dev.
|
|
8
|
+
"@prisma-next/plan": "0.3.0-dev.10",
|
|
9
|
+
"@prisma-next/contract": "0.3.0-dev.10",
|
|
10
|
+
"@prisma-next/sql-contract": "0.3.0-dev.10",
|
|
11
|
+
"@prisma-next/sql-lane": "0.3.0-dev.10",
|
|
12
|
+
"@prisma-next/sql-relational-core": "0.3.0-dev.10"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"@vitest/coverage-v8": "
|
|
16
|
-
"tsup": "
|
|
17
|
-
"typescript": "
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"@prisma-next/
|
|
21
|
-
"@prisma-next/sql-
|
|
22
|
-
"@prisma-next/sql-runtime": "0.3.0-dev.1",
|
|
15
|
+
"@vitest/coverage-v8": "4.0.16",
|
|
16
|
+
"tsup": "8.5.1",
|
|
17
|
+
"typescript": "5.9.3",
|
|
18
|
+
"vitest": "4.0.16",
|
|
19
|
+
"@prisma-next/operations": "0.3.0-dev.10",
|
|
20
|
+
"@prisma-next/sql-contract-ts": "0.3.0-dev.10",
|
|
21
|
+
"@prisma-next/sql-runtime": "0.3.0-dev.10",
|
|
23
22
|
"@prisma-next/test-utils": "0.0.1"
|
|
24
23
|
},
|
|
25
24
|
"files": [
|
|
26
|
-
"dist"
|
|
25
|
+
"dist",
|
|
26
|
+
"src"
|
|
27
27
|
],
|
|
28
28
|
"exports": {
|
|
29
29
|
".": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
|
-
"build": "tsup --config tsup.config.ts",
|
|
39
|
+
"build": "tsup --config tsup.config.ts && tsc --project tsconfig.build.json",
|
|
40
40
|
"test": "vitest run",
|
|
41
41
|
"test:coverage": "vitest run --coverage",
|
|
42
42
|
"typecheck": "tsc --project tsconfig.json --noEmit",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { orm } from '../orm';
|
|
2
|
+
export type {
|
|
3
|
+
IncludeAccumulator,
|
|
4
|
+
ModelColumnAccessor,
|
|
5
|
+
OrmBuilderOptions,
|
|
6
|
+
OrmIncludeAccessor,
|
|
7
|
+
OrmModelBuilder,
|
|
8
|
+
OrmRegistry,
|
|
9
|
+
OrmRelationAccessor,
|
|
10
|
+
OrmRelationFilterBuilder,
|
|
11
|
+
OrmWhereProperty,
|
|
12
|
+
} from '../orm-types';
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { orm } from './orm';
|
|
2
|
+
export { OrmModelBuilderImpl } from './orm/builder';
|
|
3
|
+
export type {
|
|
4
|
+
ModelColumnAccessor,
|
|
5
|
+
OrmBuilderOptions,
|
|
6
|
+
OrmModelBuilder,
|
|
7
|
+
OrmRegistry,
|
|
8
|
+
OrmRelationAccessor,
|
|
9
|
+
OrmRelationFilterBuilder,
|
|
10
|
+
OrmWhereProperty,
|
|
11
|
+
} from './orm-types';
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { ParamDescriptor } from '@prisma-next/contract/types';
|
|
2
|
+
import type { SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';
|
|
3
|
+
import type { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';
|
|
4
|
+
import type { AnyBinaryBuilder, BuildOptions } from '@prisma-next/sql-relational-core/types';
|
|
5
|
+
import type { OrmContext } from '../orm/context';
|
|
6
|
+
import type { ModelColumnAccessor } from '../orm-types';
|
|
7
|
+
import { buildWhereExpr } from '../selection/predicates';
|
|
8
|
+
import { createDeleteAst, createTableRef } from '../utils/ast';
|
|
9
|
+
import { errorFailedToBuildWhereClause, errorModelNotFound } from '../utils/errors';
|
|
10
|
+
|
|
11
|
+
export function buildDeletePlan<
|
|
12
|
+
TContract extends SqlContract<SqlStorage>,
|
|
13
|
+
CodecTypes extends Record<string, { output: unknown }>,
|
|
14
|
+
ModelName extends string,
|
|
15
|
+
>(
|
|
16
|
+
context: OrmContext<TContract>,
|
|
17
|
+
modelName: ModelName,
|
|
18
|
+
where: (model: ModelColumnAccessor<TContract, CodecTypes, ModelName>) => AnyBinaryBuilder,
|
|
19
|
+
getModelAccessor: () => ModelColumnAccessor<TContract, CodecTypes, ModelName>,
|
|
20
|
+
options?: BuildOptions,
|
|
21
|
+
): SqlQueryPlan<number> {
|
|
22
|
+
const modelAccessor = getModelAccessor();
|
|
23
|
+
const wherePredicate = where(modelAccessor);
|
|
24
|
+
|
|
25
|
+
const tableName = context.contract.mappings.modelToTable?.[modelName];
|
|
26
|
+
if (!tableName) {
|
|
27
|
+
errorModelNotFound(modelName);
|
|
28
|
+
}
|
|
29
|
+
const table = createTableRef(tableName);
|
|
30
|
+
|
|
31
|
+
const paramsMap = (options?.params ?? {}) as Record<string, unknown>;
|
|
32
|
+
const paramDescriptors: ParamDescriptor[] = [];
|
|
33
|
+
const paramValues: unknown[] = [];
|
|
34
|
+
const paramCodecs: Record<string, string> = {};
|
|
35
|
+
|
|
36
|
+
const whereResult = buildWhereExpr(
|
|
37
|
+
wherePredicate,
|
|
38
|
+
context.contract,
|
|
39
|
+
paramsMap,
|
|
40
|
+
paramDescriptors,
|
|
41
|
+
paramValues,
|
|
42
|
+
);
|
|
43
|
+
const whereExpr = whereResult.expr;
|
|
44
|
+
if (!whereExpr) {
|
|
45
|
+
errorFailedToBuildWhereClause();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (whereResult?.codecId && whereResult.paramName) {
|
|
49
|
+
paramCodecs[whereResult.paramName] = whereResult.codecId;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const ast = createDeleteAst({
|
|
53
|
+
table,
|
|
54
|
+
where: whereExpr,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return Object.freeze({
|
|
58
|
+
ast,
|
|
59
|
+
params: paramValues,
|
|
60
|
+
meta: {
|
|
61
|
+
target: context.contract.target,
|
|
62
|
+
targetFamily: context.contract.targetFamily,
|
|
63
|
+
coreHash: context.contract.coreHash,
|
|
64
|
+
lane: 'orm',
|
|
65
|
+
refs: {
|
|
66
|
+
tables: [tableName],
|
|
67
|
+
columns: [],
|
|
68
|
+
},
|
|
69
|
+
projection: {},
|
|
70
|
+
paramDescriptors,
|
|
71
|
+
...(Object.keys(paramCodecs).length > 0
|
|
72
|
+
? {
|
|
73
|
+
annotations: {
|
|
74
|
+
codecs: paramCodecs,
|
|
75
|
+
intent: 'write',
|
|
76
|
+
isMutation: true,
|
|
77
|
+
},
|
|
78
|
+
}
|
|
79
|
+
: {
|
|
80
|
+
annotations: {
|
|
81
|
+
intent: 'write',
|
|
82
|
+
isMutation: true,
|
|
83
|
+
},
|
|
84
|
+
}),
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import type { ParamDescriptor } from '@prisma-next/contract/types';
|
|
2
|
+
import type { SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';
|
|
3
|
+
import type { ColumnRef, ParamRef } from '@prisma-next/sql-relational-core/ast';
|
|
4
|
+
import { param } from '@prisma-next/sql-relational-core/param';
|
|
5
|
+
import type { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';
|
|
6
|
+
import type { BuildOptions, ParamPlaceholder } from '@prisma-next/sql-relational-core/types';
|
|
7
|
+
import type { OrmContext } from '../orm/context';
|
|
8
|
+
import { createInsertAst, createParamRef, createTableRef } from '../utils/ast';
|
|
9
|
+
import {
|
|
10
|
+
assertColumnExists,
|
|
11
|
+
assertParameterExists,
|
|
12
|
+
errorCreateRequiresFields,
|
|
13
|
+
errorModelNotFound,
|
|
14
|
+
errorUnknownTable,
|
|
15
|
+
} from '../utils/errors';
|
|
16
|
+
import { createParamDescriptor } from '../utils/param-descriptor';
|
|
17
|
+
|
|
18
|
+
export function convertModelFieldsToColumns<TContract extends SqlContract<SqlStorage>>(
|
|
19
|
+
contract: TContract,
|
|
20
|
+
modelName: string,
|
|
21
|
+
fields: Record<string, unknown>,
|
|
22
|
+
): Record<string, ParamPlaceholder> {
|
|
23
|
+
const model = contract.models[modelName];
|
|
24
|
+
if (!model || typeof model !== 'object' || !('fields' in model)) {
|
|
25
|
+
throw new Error(`Model ${modelName} does not have fields`);
|
|
26
|
+
}
|
|
27
|
+
const modelFields = model.fields as Record<string, { column?: string }>;
|
|
28
|
+
|
|
29
|
+
const result: Record<string, ParamPlaceholder> = {};
|
|
30
|
+
|
|
31
|
+
for (const fieldName in fields) {
|
|
32
|
+
if (!Object.hasOwn(fields, fieldName)) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!Object.hasOwn(modelFields, fieldName)) {
|
|
37
|
+
throw new Error(`Field ${fieldName} does not exist on model ${modelName}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const field = modelFields[fieldName];
|
|
41
|
+
if (!field) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const columnName =
|
|
46
|
+
contract.mappings.fieldToColumn?.[modelName]?.[fieldName] ?? field.column ?? fieldName;
|
|
47
|
+
|
|
48
|
+
result[columnName] = param(fieldName);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function buildInsertPlan<TContract extends SqlContract<SqlStorage>>(
|
|
55
|
+
context: OrmContext<TContract>,
|
|
56
|
+
modelName: string,
|
|
57
|
+
data: Record<string, unknown>,
|
|
58
|
+
options?: BuildOptions,
|
|
59
|
+
): SqlQueryPlan<number> {
|
|
60
|
+
if (!data || Object.keys(data).length === 0) {
|
|
61
|
+
errorCreateRequiresFields();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const values = convertModelFieldsToColumns(context.contract, modelName, data);
|
|
65
|
+
|
|
66
|
+
const tableName = context.contract.mappings.modelToTable?.[modelName];
|
|
67
|
+
if (!tableName) {
|
|
68
|
+
errorModelNotFound(modelName);
|
|
69
|
+
}
|
|
70
|
+
const table = createTableRef(tableName);
|
|
71
|
+
|
|
72
|
+
const paramsMap = {
|
|
73
|
+
...(options?.params ?? {}),
|
|
74
|
+
...data,
|
|
75
|
+
} as Record<string, unknown>;
|
|
76
|
+
const paramDescriptors: ParamDescriptor[] = [];
|
|
77
|
+
const paramValues: unknown[] = [];
|
|
78
|
+
const paramCodecs: Record<string, string> = {};
|
|
79
|
+
|
|
80
|
+
const contractTable = context.contract.storage.tables[tableName];
|
|
81
|
+
if (!contractTable) {
|
|
82
|
+
errorUnknownTable(tableName);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const insertValues: Record<string, ColumnRef | ParamRef> = {};
|
|
86
|
+
for (const [columnName, placeholder] of Object.entries(values)) {
|
|
87
|
+
const columnMeta = contractTable.columns[columnName];
|
|
88
|
+
assertColumnExists(columnMeta, columnName, tableName);
|
|
89
|
+
|
|
90
|
+
const paramName = placeholder.name;
|
|
91
|
+
const value = assertParameterExists(paramsMap, paramName);
|
|
92
|
+
const index = paramValues.push(value);
|
|
93
|
+
|
|
94
|
+
const codecId = columnMeta.codecId;
|
|
95
|
+
if (paramName) {
|
|
96
|
+
paramCodecs[paramName] = codecId;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
paramDescriptors.push(
|
|
100
|
+
createParamDescriptor({
|
|
101
|
+
name: paramName,
|
|
102
|
+
table: tableName,
|
|
103
|
+
column: columnName,
|
|
104
|
+
codecId: codecId,
|
|
105
|
+
nativeType: columnMeta.nativeType,
|
|
106
|
+
nullable: columnMeta.nullable,
|
|
107
|
+
}),
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
insertValues[columnName] = createParamRef(index, paramName);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const ast = createInsertAst({
|
|
114
|
+
table,
|
|
115
|
+
values: insertValues,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
return Object.freeze({
|
|
119
|
+
ast,
|
|
120
|
+
params: paramValues,
|
|
121
|
+
meta: {
|
|
122
|
+
target: context.contract.target,
|
|
123
|
+
targetFamily: context.contract.targetFamily,
|
|
124
|
+
coreHash: context.contract.coreHash,
|
|
125
|
+
lane: 'orm',
|
|
126
|
+
refs: {
|
|
127
|
+
tables: [tableName],
|
|
128
|
+
columns: [],
|
|
129
|
+
},
|
|
130
|
+
projection: {},
|
|
131
|
+
paramDescriptors,
|
|
132
|
+
...(Object.keys(paramCodecs).length > 0
|
|
133
|
+
? {
|
|
134
|
+
annotations: {
|
|
135
|
+
codecs: paramCodecs,
|
|
136
|
+
intent: 'write',
|
|
137
|
+
isMutation: true,
|
|
138
|
+
},
|
|
139
|
+
}
|
|
140
|
+
: {
|
|
141
|
+
annotations: {
|
|
142
|
+
intent: 'write',
|
|
143
|
+
isMutation: true,
|
|
144
|
+
},
|
|
145
|
+
}),
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import type { ParamDescriptor } from '@prisma-next/contract/types';
|
|
2
|
+
import type { SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';
|
|
3
|
+
import type { ColumnRef, ParamRef } from '@prisma-next/sql-relational-core/ast';
|
|
4
|
+
import type { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';
|
|
5
|
+
import type { AnyBinaryBuilder, BuildOptions } from '@prisma-next/sql-relational-core/types';
|
|
6
|
+
import type { OrmContext } from '../orm/context';
|
|
7
|
+
import type { ModelColumnAccessor } from '../orm-types';
|
|
8
|
+
import { buildWhereExpr } from '../selection/predicates';
|
|
9
|
+
import { createParamRef, createTableRef, createUpdateAst } from '../utils/ast';
|
|
10
|
+
import {
|
|
11
|
+
assertColumnExists,
|
|
12
|
+
assertParameterExists,
|
|
13
|
+
errorFailedToBuildWhereClause,
|
|
14
|
+
errorModelNotFound,
|
|
15
|
+
errorUnknownTable,
|
|
16
|
+
errorUpdateRequiresFields,
|
|
17
|
+
} from '../utils/errors';
|
|
18
|
+
import { createParamDescriptor } from '../utils/param-descriptor';
|
|
19
|
+
import { convertModelFieldsToColumns } from './insert-builder';
|
|
20
|
+
|
|
21
|
+
export function buildUpdatePlan<
|
|
22
|
+
TContract extends SqlContract<SqlStorage>,
|
|
23
|
+
CodecTypes extends Record<string, { output: unknown }>,
|
|
24
|
+
ModelName extends string,
|
|
25
|
+
>(
|
|
26
|
+
context: OrmContext<TContract>,
|
|
27
|
+
modelName: ModelName,
|
|
28
|
+
where: (model: ModelColumnAccessor<TContract, CodecTypes, ModelName>) => AnyBinaryBuilder,
|
|
29
|
+
getModelAccessor: () => ModelColumnAccessor<TContract, CodecTypes, ModelName>,
|
|
30
|
+
data: Record<string, unknown>,
|
|
31
|
+
options?: BuildOptions,
|
|
32
|
+
): SqlQueryPlan<number> {
|
|
33
|
+
if (!data || Object.keys(data).length === 0) {
|
|
34
|
+
errorUpdateRequiresFields();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const set = convertModelFieldsToColumns(context.contract, modelName, data);
|
|
38
|
+
|
|
39
|
+
const modelAccessor = getModelAccessor();
|
|
40
|
+
const wherePredicate = where(modelAccessor);
|
|
41
|
+
|
|
42
|
+
const tableName = context.contract.mappings.modelToTable?.[modelName];
|
|
43
|
+
if (!tableName) {
|
|
44
|
+
errorModelNotFound(modelName);
|
|
45
|
+
}
|
|
46
|
+
const table = createTableRef(tableName);
|
|
47
|
+
|
|
48
|
+
const paramsMap = {
|
|
49
|
+
...(options?.params ?? {}),
|
|
50
|
+
...data,
|
|
51
|
+
} as Record<string, unknown>;
|
|
52
|
+
const paramDescriptors: ParamDescriptor[] = [];
|
|
53
|
+
const paramValues: unknown[] = [];
|
|
54
|
+
const paramCodecs: Record<string, string> = {};
|
|
55
|
+
|
|
56
|
+
const contractTable = context.contract.storage.tables[tableName];
|
|
57
|
+
if (!contractTable) {
|
|
58
|
+
errorUnknownTable(tableName);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const updateSet: Record<string, ColumnRef | ParamRef> = {};
|
|
62
|
+
for (const [columnName, placeholder] of Object.entries(set)) {
|
|
63
|
+
const columnMeta = contractTable.columns[columnName];
|
|
64
|
+
assertColumnExists(columnMeta, columnName, tableName);
|
|
65
|
+
|
|
66
|
+
const paramName = placeholder.name;
|
|
67
|
+
const value = assertParameterExists(paramsMap, paramName);
|
|
68
|
+
const index = paramValues.push(value);
|
|
69
|
+
|
|
70
|
+
const codecId = columnMeta.codecId;
|
|
71
|
+
if (paramName) {
|
|
72
|
+
paramCodecs[paramName] = codecId;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
paramDescriptors.push(
|
|
76
|
+
createParamDescriptor({
|
|
77
|
+
name: paramName,
|
|
78
|
+
table: tableName,
|
|
79
|
+
column: columnName,
|
|
80
|
+
codecId: codecId,
|
|
81
|
+
nativeType: columnMeta.nativeType,
|
|
82
|
+
nullable: columnMeta.nullable,
|
|
83
|
+
}),
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
updateSet[columnName] = createParamRef(index, paramName);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const whereResult = buildWhereExpr(
|
|
90
|
+
wherePredicate,
|
|
91
|
+
context.contract,
|
|
92
|
+
paramsMap,
|
|
93
|
+
paramDescriptors,
|
|
94
|
+
paramValues,
|
|
95
|
+
);
|
|
96
|
+
const whereExpr = whereResult.expr;
|
|
97
|
+
if (!whereExpr) {
|
|
98
|
+
errorFailedToBuildWhereClause();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (whereResult?.codecId && whereResult.paramName) {
|
|
102
|
+
paramCodecs[whereResult.paramName] = whereResult.codecId;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const ast = createUpdateAst({
|
|
106
|
+
table,
|
|
107
|
+
set: updateSet,
|
|
108
|
+
where: whereExpr,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
return Object.freeze({
|
|
112
|
+
ast,
|
|
113
|
+
params: paramValues,
|
|
114
|
+
meta: {
|
|
115
|
+
target: context.contract.target,
|
|
116
|
+
targetFamily: context.contract.targetFamily,
|
|
117
|
+
coreHash: context.contract.coreHash,
|
|
118
|
+
lane: 'orm',
|
|
119
|
+
refs: {
|
|
120
|
+
tables: [tableName],
|
|
121
|
+
columns: [],
|
|
122
|
+
},
|
|
123
|
+
projection: {},
|
|
124
|
+
paramDescriptors,
|
|
125
|
+
...(Object.keys(paramCodecs).length > 0
|
|
126
|
+
? {
|
|
127
|
+
annotations: {
|
|
128
|
+
codecs: paramCodecs,
|
|
129
|
+
intent: 'write',
|
|
130
|
+
isMutation: true,
|
|
131
|
+
},
|
|
132
|
+
}
|
|
133
|
+
: {
|
|
134
|
+
annotations: {
|
|
135
|
+
intent: 'write',
|
|
136
|
+
isMutation: true,
|
|
137
|
+
},
|
|
138
|
+
}),
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
}
|