@dsqlbase/core 0.1.6 → 0.2.1
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/CHANGELOG.md +199 -0
- package/LICENSE +21 -0
- package/README.md +4 -0
- package/dist/definition/base.d.ts +50 -3
- package/dist/definition/base.d.ts.map +1 -1
- package/dist/definition/base.js +34 -1
- package/dist/definition/base.js.map +1 -1
- package/dist/definition/column.d.ts +87 -14
- package/dist/definition/column.d.ts.map +1 -1
- package/dist/definition/column.js +99 -5
- package/dist/definition/column.js.map +1 -1
- package/dist/definition/constraint.d.ts +16 -15
- package/dist/definition/constraint.d.ts.map +1 -1
- package/dist/definition/constraint.js +4 -1
- package/dist/definition/constraint.js.map +1 -1
- package/dist/definition/domain.d.ts +12 -8
- package/dist/definition/domain.d.ts.map +1 -1
- package/dist/definition/domain.js +10 -2
- package/dist/definition/domain.js.map +1 -1
- package/dist/definition/embedded.d.ts +131 -0
- package/dist/definition/embedded.d.ts.map +1 -0
- package/dist/definition/embedded.js +133 -0
- package/dist/definition/embedded.js.map +1 -0
- package/dist/definition/index.d.ts +7 -4
- package/dist/definition/index.d.ts.map +1 -1
- package/dist/definition/index.js +4 -1
- package/dist/definition/index.js.map +1 -1
- package/dist/definition/indexes.d.ts +49 -19
- package/dist/definition/indexes.d.ts.map +1 -1
- package/dist/definition/indexes.js +38 -9
- package/dist/definition/indexes.js.map +1 -1
- package/dist/definition/namespace.d.ts +2 -2
- package/dist/definition/namespace.d.ts.map +1 -1
- package/dist/definition/namespace.js.map +1 -1
- package/dist/definition/relations.d.ts +47 -15
- package/dist/definition/relations.d.ts.map +1 -1
- package/dist/definition/relations.js +17 -12
- package/dist/definition/relations.js.map +1 -1
- package/dist/definition/sequence.d.ts +4 -4
- package/dist/definition/sequence.d.ts.map +1 -1
- package/dist/definition/sequence.js.map +1 -1
- package/dist/definition/table.d.ts +118 -13
- package/dist/definition/table.d.ts.map +1 -1
- package/dist/definition/table.js +137 -4
- package/dist/definition/table.js.map +1 -1
- package/dist/definition/tenant.d.ts +50 -0
- package/dist/definition/tenant.d.ts.map +1 -0
- package/dist/definition/tenant.js +73 -0
- package/dist/definition/tenant.js.map +1 -0
- package/dist/definition/union.d.ts +84 -0
- package/dist/definition/union.d.ts.map +1 -0
- package/dist/definition/union.js +89 -0
- package/dist/definition/union.js.map +1 -0
- package/dist/definition/view.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/runtime/base.d.ts +22 -4
- package/dist/runtime/base.d.ts.map +1 -1
- package/dist/runtime/base.js.map +1 -1
- package/dist/runtime/column.d.ts +54 -3
- package/dist/runtime/column.d.ts.map +1 -1
- package/dist/runtime/column.js +75 -7
- package/dist/runtime/column.js.map +1 -1
- package/dist/runtime/context.d.ts +30 -2
- package/dist/runtime/context.d.ts.map +1 -1
- package/dist/runtime/context.js +6 -0
- package/dist/runtime/context.js.map +1 -1
- package/dist/runtime/errors.d.ts +14 -0
- package/dist/runtime/errors.d.ts.map +1 -0
- package/dist/runtime/errors.js +19 -0
- package/dist/runtime/errors.js.map +1 -0
- package/dist/runtime/executor.d.ts +29 -1
- package/dist/runtime/executor.d.ts.map +1 -1
- package/dist/runtime/executor.js +23 -0
- package/dist/runtime/executor.js.map +1 -1
- package/dist/runtime/group.d.ts +54 -0
- package/dist/runtime/group.d.ts.map +1 -0
- package/dist/runtime/group.js +96 -0
- package/dist/runtime/group.js.map +1 -0
- package/dist/runtime/index.d.ts +9 -6
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +6 -3
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/operation.d.ts +227 -29
- package/dist/runtime/operation.d.ts.map +1 -1
- package/dist/runtime/operation.js +525 -49
- package/dist/runtime/operation.js.map +1 -1
- package/dist/runtime/query.d.ts +102 -34
- package/dist/runtime/query.d.ts.map +1 -1
- package/dist/runtime/query.js +140 -31
- package/dist/runtime/query.js.map +1 -1
- package/dist/runtime/registry.d.ts +114 -4
- package/dist/runtime/registry.d.ts.map +1 -1
- package/dist/runtime/registry.js +366 -9
- package/dist/runtime/registry.js.map +1 -1
- package/dist/runtime/session.d.ts +10 -4
- package/dist/runtime/session.d.ts.map +1 -1
- package/dist/runtime/session.js.map +1 -1
- package/dist/runtime/table.d.ts +87 -8
- package/dist/runtime/table.d.ts.map +1 -1
- package/dist/runtime/table.js +142 -5
- package/dist/runtime/table.js.map +1 -1
- package/dist/runtime/union.d.ts +33 -0
- package/dist/runtime/union.d.ts.map +1 -0
- package/dist/runtime/union.js +69 -0
- package/dist/runtime/union.js.map +1 -0
- package/dist/sql/index.d.ts +1 -1
- package/dist/sql/index.d.ts.map +1 -1
- package/dist/sql/index.js.map +1 -1
- package/dist/sql/nodes.d.ts +33 -6
- package/dist/sql/nodes.d.ts.map +1 -1
- package/dist/sql/nodes.js +25 -0
- package/dist/sql/nodes.js.map +1 -1
- package/dist/sql/tag.d.ts +17 -0
- package/dist/sql/tag.d.ts.map +1 -1
- package/dist/sql/tag.js +95 -0
- package/dist/sql/tag.js.map +1 -1
- package/dist/sql/utils.d.ts +2 -2
- package/dist/sql/utils.d.ts.map +1 -1
- package/dist/sql/utils.js.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/thenable.js.map +1 -1
- package/dist/utils/types.d.ts +50 -2
- package/dist/utils/types.d.ts.map +1 -1
- package/dist/utils/types.js.map +1 -1
- package/package.json +27 -22
- package/dist/sql/expressions.d.ts +0 -25
- package/dist/sql/expressions.d.ts.map +0 -1
- package/dist/sql/expressions.js +0 -79
- package/dist/sql/expressions.js.map +0 -1
package/dist/runtime/index.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
export { Column } from "./column.js";
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
2
|
+
export { ColumnGroup, } from "./group.js";
|
|
3
|
+
export { ExecutionContext, } from "./context.js";
|
|
4
|
+
export { TenancyError } from "./errors.js";
|
|
5
|
+
export { CompositeQuery, ExecutableQuery } from "./executor.js";
|
|
6
|
+
export { OperationsFactory, UnionResolver, } from "./operation.js";
|
|
5
7
|
export { QueryBuilder, } from "./query.js";
|
|
6
8
|
export { SchemaRegistry, } from "./registry.js";
|
|
7
9
|
export { Table } from "./table.js";
|
|
10
|
+
export { Union } from "./union.js";
|
|
8
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,MAAM,EAAyC,MAAM,aAAa,CAAC;AAC5E,OAAO,EACL,WAAW,GAKZ,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,gBAAgB,GAIjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,eAAe,EAAmB,MAAM,eAAe,CAAC;AACjF,OAAO,EACL,iBAAiB,EAuBjB,aAAa,GACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,YAAY,GAUb,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,cAAc,GAKf,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,KAAK,EAAiB,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,KAAK,EAAiB,MAAM,YAAY,CAAC","sourcesContent":["export type {\n AnySchema,\n DefinitionRelationsTableName,\n DefinitionTableName,\n DefinitionTableRelations,\n FieldRelationConfig,\n Schema,\n SchemaRelationDefinitions,\n SchemaTableDefinitions,\n SchemaTableRelations,\n SchemaUnionDefinitions,\n DefinitionUnionName,\n TableRelationFieldName,\n} from \"./base.js\";\nexport { Column, type AnyColumn, type ColumnRowDecoder } from \"./column.js\";\nexport {\n ColumnGroup,\n type AnyColumnGroup,\n type AnyField,\n type GroupReader,\n type GroupSelection,\n} from \"./group.js\";\nexport {\n ExecutionContext,\n type ExecutionContextOptions,\n type PaginationOptions,\n type TenancyOptions,\n} from \"./context.js\";\nexport { TenancyError } from \"./errors.js\";\nexport { CompositeQuery, ExecutableQuery, type Executable } from \"./executor.js\";\nexport {\n OperationsFactory,\n type CountOperation,\n type CountOperationArgs,\n type DeleteOperation,\n type DeleteOperationArgs,\n type FieldMutation,\n type FieldResolver,\n type FieldSelection,\n type InsertOperation,\n type InsertOperationArgs,\n type Operation,\n type OperationMode,\n type OperationRequest,\n type OperationResult,\n type OperationType,\n type SelectOperation,\n type SelectOperationArgs,\n type UpdateOperation,\n type UpdateOperationArgs,\n type UnionOrderKey,\n type UnionSelectOperationArgs,\n type UnionSelectOperation,\n type UnionCountOperationArgs,\n UnionResolver,\n} from \"./operation.js\";\nexport {\n QueryBuilder,\n type DeleteParams,\n type InsertParams,\n type JoinParams,\n type SelectParams,\n type TableJoinParams,\n type UnionBranchParams,\n type UnionJoinParams,\n type UnionSelectParams,\n type UpdateParams,\n} from \"./query.js\";\nexport {\n SchemaRegistry,\n type RuntimeTables,\n type TableByAlias,\n type TableByName,\n type TableByNameOrAlias,\n} from \"./registry.js\";\nexport type { Session, TransactionSession } from \"./session.js\";\nexport { Table, type AnyTable } from \"./table.js\";\nexport { Union, type AnyUnion } from \"./union.js\";\n"]}
|
|
@@ -1,79 +1,277 @@
|
|
|
1
1
|
import { TypedObject } from "../utils/index.js";
|
|
2
|
-
import { SQLIdentifier, SQLNode, SQLStatement, SQLValue } from "../sql/index.js";
|
|
2
|
+
import { KeysetBound, SQLIdentifier, SQLNode, SQLStatement, SQLValue } from "../sql/index.js";
|
|
3
3
|
import { ExecutionContext } from "./context.js";
|
|
4
4
|
import { AnyTable } from "./table.js";
|
|
5
5
|
import { AnyColumn } from "./column.js";
|
|
6
|
+
import { AnyColumnGroup, GroupSelection } from "./group.js";
|
|
6
7
|
import { AnySchema } from "./base.js";
|
|
8
|
+
import { Union } from "./union.js";
|
|
7
9
|
export type OperationType = "select" | "insert" | "update" | "delete";
|
|
8
10
|
export type OperationMode = "one" | "many";
|
|
9
11
|
export type OperationResult<TMode extends OperationMode, TResult> = TMode extends "one" ? TResult | null : TResult[];
|
|
10
|
-
export
|
|
12
|
+
export type Operation<TMode extends OperationMode, TArgs extends object, TResult = unknown> = {
|
|
11
13
|
type: OperationType;
|
|
12
14
|
mode: TMode;
|
|
13
15
|
name: string;
|
|
14
16
|
args: TArgs;
|
|
15
17
|
query: SQLStatement;
|
|
16
18
|
resolve: (rows: unknown[]) => OperationResult<TMode, TResult>;
|
|
17
|
-
}
|
|
19
|
+
};
|
|
18
20
|
export type AnyOperation = Operation<OperationMode, object, unknown>;
|
|
19
|
-
export
|
|
21
|
+
export type OperationRequest<TArgs extends object, TMode extends OperationMode = OperationMode> = {
|
|
20
22
|
name?: string;
|
|
21
23
|
mode: TMode;
|
|
22
24
|
args: TArgs;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* One selected field: a column, or a column group with the members selected within it — none
|
|
28
|
+
* meaning all of them.
|
|
29
|
+
*/
|
|
30
|
+
export type FieldSelection = [fieldName: string, column: AnyColumn | SQLIdentifier | FieldSelection[]] | [fieldName: string, group: AnyColumnGroup, selection?: GroupSelection];
|
|
31
|
+
/**
|
|
32
|
+
* One value a write sets: on a plain column, named by its field, or on a column directly — how a
|
|
33
|
+
* column group's member is written, since it has no field of its own on the table.
|
|
34
|
+
*/
|
|
35
|
+
export type FieldMutation = [target: string | AnyColumn, value: SQLNode | SQLValue];
|
|
36
|
+
/**
|
|
37
|
+
* How one field of a result record is produced from a driver row: read a column and decode
|
|
38
|
+
* it, or resolve a nested level.
|
|
39
|
+
*/
|
|
40
|
+
export type FieldResolver = [
|
|
25
41
|
fieldName: string,
|
|
26
|
-
|
|
42
|
+
resolver: AnyColumn | ResolverEntry[] | UnionResolver
|
|
27
43
|
];
|
|
28
|
-
export
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
44
|
+
export declare class UnionResolver {
|
|
45
|
+
readonly mode: OperationMode;
|
|
46
|
+
readonly branches: Readonly<Record<string, ResolverEntry[]>>;
|
|
47
|
+
constructor(mode: OperationMode, branches: Record<string, ResolverEntry[]>);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* How one field of a result record is produced from the driver row *itself*, rather than
|
|
51
|
+
* from a column of it. `$$meta` is the only one today.
|
|
52
|
+
*
|
|
53
|
+
* The row passed in is the raw driver row, before any codec has decoded it — the same row
|
|
54
|
+
* the column branch reads from. A resolver that needs the database's own text representation
|
|
55
|
+
* of a value (rather than the decoded one) therefore has it.
|
|
56
|
+
*/
|
|
57
|
+
export type MetaResolver = [fieldName: string, resolve: (row: Record<string, unknown>) => unknown];
|
|
58
|
+
export type ResolverEntry = FieldResolver | MetaResolver;
|
|
59
|
+
/**
|
|
60
|
+
* One order key across a union: a shared field, or `$$key` to sort by member. Structured
|
|
61
|
+
* rather than a rendered `ORDER BY` term, because each member resolves the field to its own
|
|
62
|
+
* column and the combined rows are then sorted by the hidden copy every branch projects.
|
|
63
|
+
*/
|
|
64
|
+
export type UnionOrderKey = {
|
|
65
|
+
field: string;
|
|
66
|
+
direction: "asc" | "desc";
|
|
67
|
+
/** States Postgres's default null placement explicitly — see {@link KeysetKey.nullable}. */
|
|
68
|
+
nullable?: boolean;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* A select over a union. `members` lists only the branches that run, each with its own
|
|
72
|
+
* `select` / `where` / `join` already written against that member's columns; a member left out
|
|
73
|
+
* produces no branch. Ordering, limit and offset apply across all of them.
|
|
74
|
+
*/
|
|
75
|
+
export type UnionSelectOperationArgs = {
|
|
76
|
+
members: [alias: string, args: SelectOperationArgs][];
|
|
77
|
+
orderBy?: UnionOrderKey[];
|
|
78
|
+
limit?: number;
|
|
79
|
+
offset?: number;
|
|
80
|
+
/**
|
|
81
|
+
* The direction of the keys appended to make the order total — `$$key` and the primary-key
|
|
82
|
+
* tiebreakers. Ascending when omitted; a pager passes the direction of the caller's last key.
|
|
83
|
+
*/
|
|
84
|
+
tiebreak?: "asc" | "desc";
|
|
85
|
+
/**
|
|
86
|
+
* Project every key of the total order a second time as its database text, as `__k0`,
|
|
87
|
+
* `__k1`, ..., carried to the union level — the values a keyset cursor is built from. Root
|
|
88
|
+
* level only.
|
|
89
|
+
*/
|
|
90
|
+
keys?: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Read only the rows strictly after (or before) this position in the total order, applied
|
|
93
|
+
* inside every branch where `$$key` is a constant. `before` also reverses the order.
|
|
94
|
+
*/
|
|
95
|
+
keyset?: {
|
|
96
|
+
values: (string | null)[];
|
|
97
|
+
bound: KeysetBound;
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
export type SelectOperationArgs = {
|
|
101
|
+
/**
|
|
102
|
+
* The columns to project. Omitted, every column; empty, none — a level that returns only its
|
|
103
|
+
* joins.
|
|
104
|
+
*/
|
|
105
|
+
select?: FieldSelection[];
|
|
32
106
|
where?: SQLNode | SQLNode[];
|
|
33
107
|
orderBy?: SQLNode[];
|
|
34
|
-
join?: [fieldName: string, args: SelectOperationArgs][];
|
|
108
|
+
join?: [fieldName: string, args: SelectOperationArgs | UnionSelectOperationArgs][];
|
|
35
109
|
distinct?: boolean;
|
|
36
110
|
limit?: number;
|
|
37
111
|
offset?: number;
|
|
38
|
-
|
|
39
|
-
|
|
112
|
+
/**
|
|
113
|
+
* Columns projected a second time as their database text, under the hidden names `__k0`,
|
|
114
|
+
* `__k1`, ... — the order keys a keyset cursor is built from. They reach the raw driver row
|
|
115
|
+
* only: no resolver reads them, so they never appear on a result record. Root level only.
|
|
116
|
+
*/
|
|
117
|
+
keys?: AnyColumn[];
|
|
118
|
+
};
|
|
119
|
+
export type SelectOperation<TMode extends OperationMode, TArgs extends SelectOperationArgs, TReturn = unknown> = {
|
|
40
120
|
type: "select";
|
|
41
|
-
}
|
|
42
|
-
export
|
|
121
|
+
} & Operation<TMode, TArgs, TReturn>;
|
|
122
|
+
export type UnionSelectOperation<TMode extends OperationMode, TArgs extends UnionSelectOperationArgs, TReturn = unknown> = {
|
|
123
|
+
type: "select";
|
|
124
|
+
} & Operation<TMode, TArgs, TReturn>;
|
|
125
|
+
/** A count over a union: the members that run, each with its own `where`. */
|
|
126
|
+
export type UnionCountOperationArgs = {
|
|
127
|
+
members: [alias: string, args: {
|
|
128
|
+
where?: SQLNode | SQLNode[];
|
|
129
|
+
}][];
|
|
130
|
+
};
|
|
131
|
+
export type CountOperationArgs = {
|
|
132
|
+
where?: SQLNode | SQLNode[];
|
|
133
|
+
};
|
|
134
|
+
export type CountOperation = {
|
|
135
|
+
type: "select";
|
|
136
|
+
} & Operation<"one", CountOperationArgs | UnionCountOperationArgs, number>;
|
|
137
|
+
export type InsertOperationArgs = {
|
|
43
138
|
data: FieldMutation[][];
|
|
44
139
|
return?: FieldSelection[];
|
|
45
|
-
}
|
|
46
|
-
export
|
|
140
|
+
};
|
|
141
|
+
export type InsertOperation<TMode extends OperationMode, TArgs extends InsertOperationArgs, TReturn> = {
|
|
47
142
|
type: "insert";
|
|
48
|
-
}
|
|
49
|
-
export
|
|
143
|
+
} & Operation<TMode, TArgs, TReturn>;
|
|
144
|
+
export type UpdateOperationArgs = {
|
|
50
145
|
set: FieldMutation[];
|
|
51
146
|
where?: SQLNode | SQLNode[];
|
|
52
147
|
return?: FieldSelection[];
|
|
53
|
-
}
|
|
54
|
-
export
|
|
148
|
+
};
|
|
149
|
+
export type UpdateOperation<TMode extends OperationMode, TArgs extends UpdateOperationArgs, TReturn = unknown> = {
|
|
55
150
|
type: "update";
|
|
56
|
-
}
|
|
57
|
-
export
|
|
151
|
+
} & Operation<TMode, TArgs, TReturn>;
|
|
152
|
+
export type DeleteOperationArgs = {
|
|
58
153
|
where?: SQLNode | SQLNode[];
|
|
59
154
|
return?: FieldSelection[];
|
|
60
|
-
}
|
|
61
|
-
export
|
|
155
|
+
};
|
|
156
|
+
export type DeleteOperation<TMode extends OperationMode, TArgs extends DeleteOperationArgs = DeleteOperationArgs, TReturn = unknown> = {
|
|
62
157
|
type: "delete";
|
|
63
|
-
}
|
|
158
|
+
} & Operation<TMode, TArgs, TReturn>;
|
|
64
159
|
export declare class OperationsFactory<TSchema extends AnySchema = AnySchema> implements TypedObject<TSchema> {
|
|
65
160
|
readonly __type: TSchema;
|
|
66
161
|
private readonly _ctx;
|
|
67
162
|
constructor(ctx: ExecutionContext);
|
|
68
|
-
|
|
163
|
+
/**
|
|
164
|
+
* The tenant boundary for `table`, as a condition, or `undefined` when there is none to apply.
|
|
165
|
+
*
|
|
166
|
+
* A table with no claim columns is global and always yields `undefined`. Otherwise the
|
|
167
|
+
* identity on the context decides: present, every claim becomes an equality on its column;
|
|
168
|
+
* absent, an enforcing context refuses to build the operation at all, and a non-enforcing one
|
|
169
|
+
* runs unscoped.
|
|
170
|
+
*
|
|
171
|
+
* The refusal is what makes this a boundary rather than a convenience. It fires here, below
|
|
172
|
+
* the point where callers write queries, so it also covers a tenant table reached through a
|
|
173
|
+
* join — which the types cannot see, because a nested level is named by a relation rather than
|
|
174
|
+
* by the client.
|
|
175
|
+
*/
|
|
176
|
+
private _tenantPredicate;
|
|
177
|
+
/**
|
|
178
|
+
* The single place a `WHERE` is assembled, for every select — root and every nested join
|
|
179
|
+
* level — every update and every delete. It is called unconditionally, even when the caller
|
|
180
|
+
* passed no `where`, because this is the seam predicates are injected into: a rule that only
|
|
181
|
+
* ran when the caller happened to filter would not be a rule.
|
|
182
|
+
*
|
|
183
|
+
* Several nodes are AND-ed, each wrapped so an `OR` among them keeps its precedence. A lone
|
|
184
|
+
* node is returned untouched, so the common case adds no parentheses.
|
|
185
|
+
*
|
|
186
|
+
* The tenant predicate leads, before anything the caller wrote and before anything a sibling
|
|
187
|
+
* feature appends afterwards (a join correlation, a keyset). Order is cosmetic to the planner
|
|
188
|
+
* and deliberate to a reader: the boundary is the first thing an `EXPLAIN` shows.
|
|
189
|
+
*/
|
|
190
|
+
private _resolveWhere;
|
|
69
191
|
private _validateOrderExpression;
|
|
192
|
+
/**
|
|
193
|
+
* Resolvers for one level of a result — the top level of a select, a join level, or a
|
|
194
|
+
* `return` selection. Every level is built here, which is why stamping `$$meta` once at the
|
|
195
|
+
* top of this function reaches all of them.
|
|
196
|
+
*
|
|
197
|
+
* No selection projects every column; an empty one projects none.
|
|
198
|
+
*/
|
|
70
199
|
private _resolveFields;
|
|
200
|
+
/**
|
|
201
|
+
* The value a tenant claim column is inserted with, taken from the identity.
|
|
202
|
+
*
|
|
203
|
+
* Always required, in both modes: the column is `notNull` and nothing else can fill it, so an
|
|
204
|
+
* insert without claims would write a row into no tenant. Moving a row between tenants is not
|
|
205
|
+
* a model-client operation — it is raw SQL on an unscoped client, deliberately.
|
|
206
|
+
*/
|
|
207
|
+
private _tenantValue;
|
|
208
|
+
/**
|
|
209
|
+
* The column a mutation sets: a plain column by its field, or a column given directly, which
|
|
210
|
+
* must be one of the table's own — a group's member.
|
|
211
|
+
*/
|
|
212
|
+
private _getMutationColumn;
|
|
71
213
|
private _resolveInsertEntries;
|
|
72
214
|
private _resolveUpdateEntries;
|
|
73
215
|
private _resolveSelectParams;
|
|
74
216
|
private _resolveJoinEntries;
|
|
75
|
-
|
|
217
|
+
private _resolveFromColumns;
|
|
218
|
+
/**
|
|
219
|
+
* Builds the branches of a select over a union, one per member in `args.members`, each
|
|
220
|
+
* through {@link _resolveSelectParams} with the member's own table — so every branch passes
|
|
221
|
+
* the `WHERE` seam, tenant predicate included, and gets nested joins and codec-aware filters
|
|
222
|
+
* exactly as a single-table level would. A branch cannot skip them, which is what keeps a
|
|
223
|
+
* union from becoming a way around a member's tenant boundary.
|
|
224
|
+
*
|
|
225
|
+
* Each branch also projects:
|
|
226
|
+
* - its alias as a `$$key` literal, which lands in the row's JSON and drives dispatch;
|
|
227
|
+
* - when ordered, every order key as `__o<n>`, since members may name the column differently;
|
|
228
|
+
* - when ordered and every member's primary key lines up (same arity, same types), those
|
|
229
|
+
* columns as `__pk<n>`, the tiebreakers after `$$key` that make the order total.
|
|
230
|
+
*
|
|
231
|
+
* With a `limit`, each branch is also ordered and limited to `limit + offset` rows. That is
|
|
232
|
+
* safe because every branch sorts by the same keys the combined rows are sorted by, so no
|
|
233
|
+
* row a branch drops could have made the combined page.
|
|
234
|
+
*
|
|
235
|
+
* `pairs` are the join's `to` columns per member; absent at the root of a query.
|
|
236
|
+
*/
|
|
237
|
+
private _resolveUnionParams;
|
|
238
|
+
/**
|
|
239
|
+
* The total order of a union: the caller's keys, then `$$key` unless they named it, then
|
|
240
|
+
* every primary-key column when the members' keys line up. The appended keys run in
|
|
241
|
+
* `tiebreak` — ascending unless a pager asks otherwise.
|
|
242
|
+
*
|
|
243
|
+
* A primary-key tiebreaker is written as the field `$$pk<n>`: members may name their key
|
|
244
|
+
* columns differently, so it is addressed by position rather than by field.
|
|
245
|
+
*/
|
|
246
|
+
private _getUnionOrder;
|
|
247
|
+
/** What one order key reads inside one member's branch. */
|
|
248
|
+
private _getUnionKeyExpression;
|
|
249
|
+
/**
|
|
250
|
+
* The name one order key is carried under to the union level: `"$$key"` for `$$key`, which
|
|
251
|
+
* every branch projects anyway, `__pk<n>` for a tiebreaker, `__o<n>` for a
|
|
252
|
+
* caller's key — its position, since members may name the column differently.
|
|
253
|
+
*/
|
|
254
|
+
private _getUnionKeyName;
|
|
255
|
+
/** Resolves the rows of a union level, each by the member its `$$key` names. */
|
|
256
|
+
private _resolveUnionRows;
|
|
257
|
+
_createResultResolver<TMode extends OperationMode, TResult extends object>(resolvers: ResolverEntry[], mode: TMode): (rows: unknown[]) => OperationResult<TMode, TResult>;
|
|
76
258
|
createSelectOperation<TResult extends object, TTable extends AnyTable, TMode extends OperationMode = OperationMode, TArgs extends SelectOperationArgs = SelectOperationArgs>(table: TTable, config: OperationRequest<TArgs, TMode>): SelectOperation<TMode, TArgs, TResult>;
|
|
259
|
+
/**
|
|
260
|
+
* `SELECT count(*)` over `table`, filtered by `where` through the same seam as every select,
|
|
261
|
+
* so an injected predicate bounds the count exactly as it bounds the rows.
|
|
262
|
+
*/
|
|
263
|
+
createCountOperation<TTable extends AnyTable>(table: TTable, config: OperationRequest<CountOperationArgs, "one">): CountOperation;
|
|
264
|
+
/**
|
|
265
|
+
* A top-level select over a union: the union's own `UNION ALL`, each row a JSON `data` value
|
|
266
|
+
* dispatched to its member's resolvers. With no member left to run it reads nothing, and
|
|
267
|
+
* resolves to `[]` or `null`.
|
|
268
|
+
*/
|
|
269
|
+
createUnionSelectOperation<TResult extends object, TMode extends OperationMode = OperationMode, TArgs extends UnionSelectOperationArgs = UnionSelectOperationArgs>(union: Union, config: OperationRequest<TArgs, TMode>): UnionSelectOperation<TMode, TArgs, TResult>;
|
|
270
|
+
/**
|
|
271
|
+
* Counts the rows a union's members select: one `count(*)` per member, each through the
|
|
272
|
+
* `WHERE` seam with that member's own table, added together.
|
|
273
|
+
*/
|
|
274
|
+
createUnionCountOperation(union: Union, config: OperationRequest<UnionCountOperationArgs, "one">): CountOperation;
|
|
77
275
|
createInsertOperation<TResult extends object, TTable extends AnyTable, TMode extends OperationMode, TArgs extends InsertOperationArgs>(table: TTable, config: OperationRequest<TArgs, TMode>): InsertOperation<TMode, TArgs, TResult>;
|
|
78
276
|
createUpdateOperation<TResult extends object, TMode extends OperationMode = OperationMode, TTable extends AnyTable = AnyTable, TArgs extends UpdateOperationArgs = UpdateOperationArgs>(table: TTable, config: OperationRequest<TArgs, TMode>): UpdateOperation<TMode, TArgs, TResult>;
|
|
79
277
|
createDeleteOperation<TResult extends object, TMode extends OperationMode = OperationMode, TTable extends AnyTable = AnyTable, TArgs extends DeleteOperationArgs = DeleteOperationArgs>(table: TTable, config: OperationRequest<TArgs, TMode>): DeleteOperation<TMode, TArgs, TResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../src/runtime/operation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,
|
|
1
|
+
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../src/runtime/operation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAO,MAAM,iBAAiB,CAAC;AACnG,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,SAAS,EAAU,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,cAAc,EAAyB,cAAc,EAAE,MAAM,YAAY,CAAC;AAEnF,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AACtE,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,MAAM,CAAC;AAE3C,MAAM,MAAM,eAAe,CAAC,KAAK,SAAS,aAAa,EAAE,OAAO,IAAI,KAAK,SAAS,KAAK,GACnF,OAAO,GAAG,IAAI,GACd,OAAO,EAAE,CAAC;AAEd,MAAM,MAAM,SAAS,CAAC,KAAK,SAAS,aAAa,EAAE,KAAK,SAAS,MAAM,EAAE,OAAO,GAAG,OAAO,IAAI;IAC5F,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,KAAK,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,KAAK,CAAC;IACZ,KAAK,EAAE,YAAY,CAAC;IACpB,OAAO,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