@rawsql-ts/sql-contract 0.2.0 → 0.3.2
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/LICENSE +21 -21
- package/README.md +617 -582
- package/dist/.tsbuildinfo +1 -1
- package/dist/catalog/index.d.ts +51 -1
- package/dist/catalog/index.js +98 -32
- package/dist/catalog/index.js.map +1 -1
- package/dist/catalog/mutation.d.ts +85 -0
- package/dist/catalog/mutation.js +778 -0
- package/dist/catalog/mutation.js.map +1 -0
- package/dist/mapper/index.d.ts +4 -7
- package/dist/mapper/index.js +35 -18
- package/dist/mapper/index.js.map +1 -1
- package/dist/normalizeExecutionResult.d.ts +10 -0
- package/dist/normalizeExecutionResult.js +39 -0
- package/dist/normalizeExecutionResult.js.map +1 -0
- package/package.json +4 -3
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { QueryParams } from '../query-params';
|
|
2
|
+
type WherePolicy = {
|
|
3
|
+
requireWhereClause: boolean;
|
|
4
|
+
requireAllNamedParams: boolean;
|
|
5
|
+
};
|
|
6
|
+
type UpdateMutationConfig = {
|
|
7
|
+
subtractUndefinedAssignments: boolean;
|
|
8
|
+
failOnEmptySet: boolean;
|
|
9
|
+
where: WherePolicy;
|
|
10
|
+
};
|
|
11
|
+
type InsertMutationConfig = {
|
|
12
|
+
subtractUndefinedColumns: boolean;
|
|
13
|
+
failOnEmptyColumns: boolean;
|
|
14
|
+
};
|
|
15
|
+
type DeleteMutationConfig = {
|
|
16
|
+
where: WherePolicy;
|
|
17
|
+
affectedRowsGuard: {
|
|
18
|
+
mode: 'exactly';
|
|
19
|
+
count: number;
|
|
20
|
+
} | {
|
|
21
|
+
mode: 'none';
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export type MutationSafety = 'safe' | 'unsafe' | 'unknown';
|
|
25
|
+
export type MutationAwareRewriter = {
|
|
26
|
+
mutationSafety: 'safe';
|
|
27
|
+
};
|
|
28
|
+
export type NormalizedMutationSpec = {
|
|
29
|
+
kind: 'insert';
|
|
30
|
+
insert: InsertMutationConfig;
|
|
31
|
+
} | {
|
|
32
|
+
kind: 'update';
|
|
33
|
+
update: UpdateMutationConfig;
|
|
34
|
+
} | {
|
|
35
|
+
kind: 'delete';
|
|
36
|
+
delete: DeleteMutationConfig;
|
|
37
|
+
};
|
|
38
|
+
export type MutationCatalogSpec = {
|
|
39
|
+
id: string;
|
|
40
|
+
params: {
|
|
41
|
+
shape: 'positional' | 'named';
|
|
42
|
+
};
|
|
43
|
+
mutation?: {
|
|
44
|
+
kind: 'insert';
|
|
45
|
+
insert?: {
|
|
46
|
+
subtractUndefinedColumns?: boolean;
|
|
47
|
+
failOnEmptyColumns?: boolean;
|
|
48
|
+
};
|
|
49
|
+
} | {
|
|
50
|
+
kind: 'update';
|
|
51
|
+
update?: {
|
|
52
|
+
subtractUndefinedAssignments?: boolean;
|
|
53
|
+
failOnEmptySet?: boolean;
|
|
54
|
+
};
|
|
55
|
+
where?: {
|
|
56
|
+
requireWhereClause?: boolean;
|
|
57
|
+
requireAllNamedParams?: boolean;
|
|
58
|
+
};
|
|
59
|
+
} | {
|
|
60
|
+
kind: 'delete';
|
|
61
|
+
where?: {
|
|
62
|
+
requireWhereClause?: boolean;
|
|
63
|
+
requireAllNamedParams?: boolean;
|
|
64
|
+
};
|
|
65
|
+
delete?: {
|
|
66
|
+
affectedRowsGuard?: {
|
|
67
|
+
mode: 'exactly';
|
|
68
|
+
count: number;
|
|
69
|
+
} | {
|
|
70
|
+
mode: 'none';
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
export type MutationPreprocessResult = {
|
|
76
|
+
sql: string;
|
|
77
|
+
params: QueryParams;
|
|
78
|
+
mutation: NormalizedMutationSpec | undefined;
|
|
79
|
+
};
|
|
80
|
+
type ContractViolationLike = new (message: string, specId?: string, cause?: unknown) => Error;
|
|
81
|
+
export declare function preprocessMutationSpec(ContractViolationError: ContractViolationLike, spec: MutationCatalogSpec, sql: string, params: QueryParams): MutationPreprocessResult;
|
|
82
|
+
export declare function isMutationSafeRewriter(rewriter: unknown): rewriter is MutationAwareRewriter;
|
|
83
|
+
export declare function assertMutationSafeRewriters(ContractViolationError: ContractViolationLike, spec: MutationCatalogSpec, rewriters: readonly unknown[]): void;
|
|
84
|
+
export declare function assertDeleteGuard(ContractViolationError: ContractViolationLike, spec: MutationCatalogSpec, mutation: NormalizedMutationSpec | undefined, rowCount: number | undefined): void;
|
|
85
|
+
export {};
|