@peridotvault/peridotbase-sdk 0.0.0-stage → 0.2.0
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/auth.d.ts +33 -0
- package/dist/auth.js +72 -0
- package/dist/client.d.ts +1149 -0
- package/dist/client.js +6030 -0
- package/dist/ddl.d.ts +31 -0
- package/dist/ddl.js +28 -0
- package/dist/errors.d.ts +32 -0
- package/dist/errors.js +187 -0
- package/dist/expr.d.ts +127 -0
- package/dist/expr.js +1177 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +28 -0
- package/dist/org-multisig.d.ts +29 -0
- package/dist/org-multisig.js +90 -0
- package/dist/pda.d.ts +95 -0
- package/dist/pda.js +327 -0
- package/dist/sql.d.ts +244 -0
- package/dist/sql.js +1523 -0
- package/dist/tooling.d.ts +68 -0
- package/dist/tooling.js +432 -0
- package/dist/v3.d.ts +357 -0
- package/dist/v3.js +1649 -0
- package/dist/values.d.ts +229 -0
- package/dist/values.js +1362 -0
- package/dist/verify.d.ts +37 -0
- package/dist/verify.js +210 -0
- package/idl/peridotbase_core.json +17404 -0
- package/package.json +43 -4
- package/README.md +0 -3
package/dist/ddl.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** DDL event kinds emitted by the program (`instructions/audit.rs`). */
|
|
2
|
+
export declare const DDL_ACTION: {
|
|
3
|
+
readonly createEnum: 1;
|
|
4
|
+
readonly createDomain: 2;
|
|
5
|
+
readonly createSchema: 3;
|
|
6
|
+
readonly createTable: 4;
|
|
7
|
+
readonly alterTable: 5;
|
|
8
|
+
readonly alterColumnDefault: 6;
|
|
9
|
+
readonly renameTable: 7;
|
|
10
|
+
readonly createIndex: 8;
|
|
11
|
+
readonly createIndexBucket: 9;
|
|
12
|
+
readonly setPolicy: 10;
|
|
13
|
+
readonly setIndexNulls: 11;
|
|
14
|
+
readonly setTableGuard: 12;
|
|
15
|
+
readonly setPolicyMultisig: 13;
|
|
16
|
+
readonly setPolicyTimelock: 14;
|
|
17
|
+
readonly proposePolicy: 15;
|
|
18
|
+
readonly approvePolicy: 16;
|
|
19
|
+
readonly applyPolicy: 17;
|
|
20
|
+
readonly cancelPolicy: 18;
|
|
21
|
+
readonly softDropTable: 19;
|
|
22
|
+
readonly restoreTable: 20;
|
|
23
|
+
readonly createForeignKey: 21;
|
|
24
|
+
readonly dropForeignKey: 22;
|
|
25
|
+
};
|
|
26
|
+
export interface DdlEvent {
|
|
27
|
+
database: import("@solana/web3.js").PublicKey;
|
|
28
|
+
table: import("@solana/web3.js").PublicKey;
|
|
29
|
+
action: number;
|
|
30
|
+
actor: import("@solana/web3.js").PublicKey;
|
|
31
|
+
}
|
package/dist/ddl.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DDL_ACTION = void 0;
|
|
4
|
+
/** DDL event kinds emitted by the program (`instructions/audit.rs`). */
|
|
5
|
+
exports.DDL_ACTION = {
|
|
6
|
+
createEnum: 1,
|
|
7
|
+
createDomain: 2,
|
|
8
|
+
createSchema: 3,
|
|
9
|
+
createTable: 4,
|
|
10
|
+
alterTable: 5,
|
|
11
|
+
alterColumnDefault: 6,
|
|
12
|
+
renameTable: 7,
|
|
13
|
+
createIndex: 8,
|
|
14
|
+
createIndexBucket: 9,
|
|
15
|
+
setPolicy: 10,
|
|
16
|
+
setIndexNulls: 11,
|
|
17
|
+
setTableGuard: 12,
|
|
18
|
+
setPolicyMultisig: 13,
|
|
19
|
+
setPolicyTimelock: 14,
|
|
20
|
+
proposePolicy: 15,
|
|
21
|
+
approvePolicy: 16,
|
|
22
|
+
applyPolicy: 17,
|
|
23
|
+
cancelPolicy: 18,
|
|
24
|
+
softDropTable: 19,
|
|
25
|
+
restoreTable: 20,
|
|
26
|
+
createForeignKey: 21,
|
|
27
|
+
dropForeignKey: 22,
|
|
28
|
+
};
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured SDK errors.
|
|
3
|
+
*
|
|
4
|
+
* Anchor surfaces on-chain failures as nested RPC errors. This module folds
|
|
5
|
+
* them into a stable shape so callers can branch on `code` and `retryable`
|
|
6
|
+
* instead of parsing log strings.
|
|
7
|
+
*
|
|
8
|
+
* `code` keeps the program's own error name (`DuplicateKey`, `RowTooLarge`, …)
|
|
9
|
+
* because it is the most precise signal. `canonicalCode` maps it onto the
|
|
10
|
+
* stable product vocabulary documented in PRD §9.2, and `category` separates
|
|
11
|
+
* caller mistakes from contention and transient network failures.
|
|
12
|
+
*/
|
|
13
|
+
export type ErrorCategory = "CONSTRAINT" | "AUTH" | "STORAGE" | "CONTENTION" | "TRANSIENT" | "CLIENT";
|
|
14
|
+
/** PostgreSQL-compatible SQLSTATE classes for the operations we support. */
|
|
15
|
+
export type SqlState = {
|
|
16
|
+
code: string;
|
|
17
|
+
name: string;
|
|
18
|
+
};
|
|
19
|
+
/** Stable product codes from PRD §9.2. */
|
|
20
|
+
export type CanonicalCode = "DATABASE_NOT_FOUND" | "TABLE_NOT_FOUND" | "TABLE_ALREADY_EXISTS" | "ROW_NOT_FOUND" | "DUPLICATE_PRIMARY_KEY" | "UNIQUE_CONSTRAINT_VIOLATION" | "NOT_NULL_VIOLATION" | "SCHEMA_VALIDATION_FAILED" | "ROW_TOO_LARGE" | "PAGE_CAPACITY_EXCEEDED" | "INDEX_CAPACITY_EXCEEDED" | "UNAUTHORIZED" | "ACCOUNT_RESOLUTION_FAILED" | "TRANSACTION_TOO_LARGE" | "COMPUTE_BUDGET_EXCEEDED" | "ACCOUNT_CONTENTION" | "CONFIRMATION_UNCERTAIN" | "UNKNOWN";
|
|
21
|
+
export declare class PeridotBaseError extends Error {
|
|
22
|
+
readonly code: string;
|
|
23
|
+
readonly canonicalCode: CanonicalCode;
|
|
24
|
+
readonly sqlState: SqlState;
|
|
25
|
+
readonly category: ErrorCategory;
|
|
26
|
+
readonly retryable: boolean;
|
|
27
|
+
readonly logs: string[];
|
|
28
|
+
constructor(code: string, message: string, retryable?: boolean, logs?: string[]);
|
|
29
|
+
static from(error: unknown): PeridotBaseError;
|
|
30
|
+
}
|
|
31
|
+
/** Ascending backoff for bounded retries; index is the attempt number. */
|
|
32
|
+
export declare function retryDelayMs(attempt: number): number;
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PeridotBaseError = void 0;
|
|
4
|
+
exports.retryDelayMs = retryDelayMs;
|
|
5
|
+
const SQLSTATE_BY_CODE = {
|
|
6
|
+
DuplicateKey: { code: "23505", name: "unique_violation" },
|
|
7
|
+
NotNullViolation: { code: "23502", name: "not_null_violation" },
|
|
8
|
+
CheckViolation: { code: "23514", name: "check_violation" },
|
|
9
|
+
TypeMismatch: { code: "22003", name: "numeric_value_out_of_range" },
|
|
10
|
+
ValueCountMismatch: { code: "42601", name: "syntax_error" },
|
|
11
|
+
InvalidColumn: { code: "42703", name: "undefined_column" },
|
|
12
|
+
InvalidExpression: { code: "42601", name: "syntax_error" },
|
|
13
|
+
ExpressionTypeMismatch: { code: "42804", name: "datatype_mismatch" },
|
|
14
|
+
ExpressionLimitExceeded: { code: "54001", name: "statement_too_complex" },
|
|
15
|
+
PrimaryKeyImmutable: { code: "23514", name: "check_violation" },
|
|
16
|
+
DuplicateTableName: { code: "42P07", name: "duplicate_table" },
|
|
17
|
+
TableDropped: { code: "42P01", name: "undefined_table" },
|
|
18
|
+
InvalidSchema: { code: "42601", name: "syntax_error" },
|
|
19
|
+
InvalidName: { code: "42601", name: "syntax_error" },
|
|
20
|
+
RowTooLarge: { code: "54000", name: "program_limit_exceeded" },
|
|
21
|
+
PageCapacityExceeded: { code: "54000", name: "program_limit_exceeded" },
|
|
22
|
+
IndexCapacityExceeded: { code: "54000", name: "program_limit_exceeded" },
|
|
23
|
+
AccountTooLarge: { code: "54000", name: "program_limit_exceeded" },
|
|
24
|
+
RowNotFound: { code: "02000", name: "no_data" },
|
|
25
|
+
StaleLocator: { code: "40001", name: "serialization_failure" },
|
|
26
|
+
WriteConflict: { code: "40001", name: "serialization_failure" },
|
|
27
|
+
Unauthorized: { code: "42501", name: "insufficient_privilege" },
|
|
28
|
+
OwnerOnly: { code: "42501", name: "insufficient_privilege" },
|
|
29
|
+
MissingOrganization: { code: "42501", name: "insufficient_privilege" },
|
|
30
|
+
NotOrganizationMember: { code: "42501", name: "insufficient_privilege" },
|
|
31
|
+
DatabaseNotMutable: { code: "25006", name: "read_only_sql_transaction" },
|
|
32
|
+
TableImmutable: { code: "42501", name: "insufficient_privilege" },
|
|
33
|
+
AppendOnlyViolation: { code: "42501", name: "insufficient_privilege" },
|
|
34
|
+
GuardViolation: { code: "42501", name: "insufficient_privilege" },
|
|
35
|
+
GuardIrreversible: { code: "42501", name: "insufficient_privilege" },
|
|
36
|
+
InvalidGuard: { code: "42601", name: "syntax_error" },
|
|
37
|
+
IndexBackfillUnsupported: { code: "0A000", name: "feature_not_supported" },
|
|
38
|
+
UnsupportedStatement: { code: "0A000", name: "feature_not_supported" },
|
|
39
|
+
AtomicStatementTooLarge: { code: "54000", name: "program_limit_exceeded" },
|
|
40
|
+
ForeignAccount: { code: "42704", name: "undefined_object" },
|
|
41
|
+
MalformedAccount: { code: "42704", name: "undefined_object" },
|
|
42
|
+
MissingIndexBucket: { code: "42704", name: "undefined_object" },
|
|
43
|
+
AccountInUse: { code: "40001", name: "serialization_failure" },
|
|
44
|
+
TransactionTooLarge: { code: "54000", name: "program_limit_exceeded" },
|
|
45
|
+
ComputeBudgetExceeded: { code: "53200", name: "out_of_memory" },
|
|
46
|
+
UncertainConfirmation: { code: "08006", name: "connection_failure" },
|
|
47
|
+
BlockhashNotFound: { code: "08006", name: "connection_failure" },
|
|
48
|
+
UnknownError: { code: "XX000", name: "internal_error" },
|
|
49
|
+
};
|
|
50
|
+
const CANONICAL = {
|
|
51
|
+
DuplicateKey: "UNIQUE_CONSTRAINT_VIOLATION",
|
|
52
|
+
DuplicateTableName: "TABLE_ALREADY_EXISTS",
|
|
53
|
+
RowNotFound: "ROW_NOT_FOUND",
|
|
54
|
+
StaleLocator: "ROW_NOT_FOUND",
|
|
55
|
+
NotNullViolation: "NOT_NULL_VIOLATION",
|
|
56
|
+
CheckViolation: "SCHEMA_VALIDATION_FAILED",
|
|
57
|
+
TypeMismatch: "SCHEMA_VALIDATION_FAILED",
|
|
58
|
+
InvalidSchema: "SCHEMA_VALIDATION_FAILED",
|
|
59
|
+
InvalidColumn: "SCHEMA_VALIDATION_FAILED",
|
|
60
|
+
ValueCountMismatch: "SCHEMA_VALIDATION_FAILED",
|
|
61
|
+
InvalidExpression: "SCHEMA_VALIDATION_FAILED",
|
|
62
|
+
ExpressionTypeMismatch: "SCHEMA_VALIDATION_FAILED",
|
|
63
|
+
ExpressionLimitExceeded: "SCHEMA_VALIDATION_FAILED",
|
|
64
|
+
ExpressionStackUnderflow: "SCHEMA_VALIDATION_FAILED",
|
|
65
|
+
RowTooLarge: "ROW_TOO_LARGE",
|
|
66
|
+
PageCapacityExceeded: "PAGE_CAPACITY_EXCEEDED",
|
|
67
|
+
IndexCapacityExceeded: "INDEX_CAPACITY_EXCEEDED",
|
|
68
|
+
AccountTooLarge: "ROW_TOO_LARGE",
|
|
69
|
+
Unauthorized: "UNAUTHORIZED",
|
|
70
|
+
NotProtocolAdmin: "UNAUTHORIZED",
|
|
71
|
+
OwnerOnly: "UNAUTHORIZED",
|
|
72
|
+
MissingOrganization: "UNAUTHORIZED",
|
|
73
|
+
NotOrganizationMember: "UNAUTHORIZED",
|
|
74
|
+
OrganizationOwnerRequired: "UNAUTHORIZED",
|
|
75
|
+
DatabaseNotMutable: "UNAUTHORIZED",
|
|
76
|
+
TableDropped: "TABLE_NOT_FOUND",
|
|
77
|
+
MissingIndexBucket: "ACCOUNT_RESOLUTION_FAILED",
|
|
78
|
+
InvalidPage: "ACCOUNT_RESOLUTION_FAILED",
|
|
79
|
+
InvalidIndexPage: "ACCOUNT_RESOLUTION_FAILED",
|
|
80
|
+
InvalidShardDirectory: "ACCOUNT_RESOLUTION_FAILED",
|
|
81
|
+
ForeignAccount: "ACCOUNT_RESOLUTION_FAILED",
|
|
82
|
+
MalformedAccount: "ACCOUNT_RESOLUTION_FAILED",
|
|
83
|
+
HelperNotWritable: "ACCOUNT_RESOLUTION_FAILED",
|
|
84
|
+
DuplicateHelperAccount: "ACCOUNT_RESOLUTION_FAILED",
|
|
85
|
+
IncompatibleAccountVersion: "ACCOUNT_RESOLUTION_FAILED",
|
|
86
|
+
AccountInUse: "ACCOUNT_CONTENTION",
|
|
87
|
+
TransactionTooLarge: "TRANSACTION_TOO_LARGE",
|
|
88
|
+
ComputeBudgetExceeded: "COMPUTE_BUDGET_EXCEEDED",
|
|
89
|
+
UncertainConfirmation: "CONFIRMATION_UNCERTAIN",
|
|
90
|
+
BlockhashNotFound: "CONFIRMATION_UNCERTAIN",
|
|
91
|
+
};
|
|
92
|
+
const CATEGORY = {
|
|
93
|
+
DuplicateKey: "CONSTRAINT",
|
|
94
|
+
DuplicateTableName: "CONSTRAINT",
|
|
95
|
+
NotNullViolation: "CONSTRAINT",
|
|
96
|
+
CheckViolation: "CONSTRAINT",
|
|
97
|
+
TypeMismatch: "CONSTRAINT",
|
|
98
|
+
InvalidSchema: "CONSTRAINT",
|
|
99
|
+
InvalidColumn: "CONSTRAINT",
|
|
100
|
+
ValueCountMismatch: "CONSTRAINT",
|
|
101
|
+
InvalidExpression: "CONSTRAINT",
|
|
102
|
+
ExpressionTypeMismatch: "CONSTRAINT",
|
|
103
|
+
ExpressionLimitExceeded: "CONSTRAINT",
|
|
104
|
+
ExpressionStackUnderflow: "CONSTRAINT",
|
|
105
|
+
PrimaryKeyImmutable: "CONSTRAINT",
|
|
106
|
+
WrongShard: "CONSTRAINT",
|
|
107
|
+
RowTooLarge: "STORAGE",
|
|
108
|
+
PageCapacityExceeded: "STORAGE",
|
|
109
|
+
IndexCapacityExceeded: "STORAGE",
|
|
110
|
+
AccountTooLarge: "STORAGE",
|
|
111
|
+
RowNotFound: "CLIENT",
|
|
112
|
+
StaleLocator: "CLIENT",
|
|
113
|
+
Unauthorized: "AUTH",
|
|
114
|
+
NotProtocolAdmin: "AUTH",
|
|
115
|
+
OwnerOnly: "AUTH",
|
|
116
|
+
MissingOrganization: "AUTH",
|
|
117
|
+
NotOrganizationMember: "AUTH",
|
|
118
|
+
OrganizationOwnerRequired: "AUTH",
|
|
119
|
+
DatabaseNotMutable: "AUTH",
|
|
120
|
+
TableDropped: "AUTH",
|
|
121
|
+
AccountInUse: "CONTENTION",
|
|
122
|
+
MissingIndexBucket: "CONTENTION",
|
|
123
|
+
UncertainConfirmation: "TRANSIENT",
|
|
124
|
+
BlockhashNotFound: "TRANSIENT",
|
|
125
|
+
};
|
|
126
|
+
class PeridotBaseError extends Error {
|
|
127
|
+
constructor(code, message, retryable = false, logs = []) {
|
|
128
|
+
super(message);
|
|
129
|
+
this.name = "PeridotBaseError";
|
|
130
|
+
this.code = code;
|
|
131
|
+
this.canonicalCode = CANONICAL[code] ?? "UNKNOWN";
|
|
132
|
+
this.sqlState = SQLSTATE_BY_CODE[code] ?? SQLSTATE_BY_CODE.UnknownError;
|
|
133
|
+
this.category = CATEGORY[code] ?? (retryable ? "TRANSIENT" : "CLIENT");
|
|
134
|
+
this.retryable = retryable;
|
|
135
|
+
this.logs = logs;
|
|
136
|
+
}
|
|
137
|
+
static from(error) {
|
|
138
|
+
if (error instanceof PeridotBaseError)
|
|
139
|
+
return error;
|
|
140
|
+
const anyError = error;
|
|
141
|
+
const logs = [
|
|
142
|
+
...(Array.isArray(anyError?.logs) ? anyError.logs : []),
|
|
143
|
+
...(Array.isArray(anyError?.transactionLogs) ? anyError.transactionLogs : []),
|
|
144
|
+
];
|
|
145
|
+
const text = [
|
|
146
|
+
anyError?.message,
|
|
147
|
+
anyError?.error?.errorMessage,
|
|
148
|
+
anyError?.error?.errorCode?.code,
|
|
149
|
+
...logs,
|
|
150
|
+
String(error),
|
|
151
|
+
]
|
|
152
|
+
.filter(Boolean)
|
|
153
|
+
.join("\n");
|
|
154
|
+
const named = text.match(/Error Code:\s*([A-Za-z0-9_]+)/);
|
|
155
|
+
if (named) {
|
|
156
|
+
return new PeridotBaseError(named[1], `${named[1]}: ${text}`, RETRYABLE.has(named[1]), logs);
|
|
157
|
+
}
|
|
158
|
+
if (/insufficient funds|debit an account but found no record/i.test(text)) {
|
|
159
|
+
return new PeridotBaseError("InsufficientFunds", text, false, logs);
|
|
160
|
+
}
|
|
161
|
+
if (/account in use|AlreadyProcessed|already been processed/i.test(text)) {
|
|
162
|
+
return new PeridotBaseError("AccountInUse", text, true, logs);
|
|
163
|
+
}
|
|
164
|
+
if (/blockhash not found|block height exceeded|timed out|confirmation timed out/i.test(text)) {
|
|
165
|
+
return new PeridotBaseError("UncertainConfirmation", text, true, logs);
|
|
166
|
+
}
|
|
167
|
+
if (/exceeded CUs meter|ComputationalBudgetExceeded|compute budget exceeded|Program failed to complete/i.test(text)) {
|
|
168
|
+
return new PeridotBaseError("ComputeBudgetExceeded", text, false, logs);
|
|
169
|
+
}
|
|
170
|
+
if (/transaction too large|too large|exceeds the maximum/i.test(text)) {
|
|
171
|
+
return new PeridotBaseError("TransactionTooLarge", text, false, logs);
|
|
172
|
+
}
|
|
173
|
+
return new PeridotBaseError("UnknownError", text || "unknown error", false, logs);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
exports.PeridotBaseError = PeridotBaseError;
|
|
177
|
+
/** Errors where retrying the same operation is safe and may succeed. */
|
|
178
|
+
const RETRYABLE = new Set([
|
|
179
|
+
"UncertainConfirmation",
|
|
180
|
+
"BlockhashNotFound",
|
|
181
|
+
"ClusterMaintenance",
|
|
182
|
+
"AccountInUse",
|
|
183
|
+
]);
|
|
184
|
+
/** Ascending backoff for bounded retries; index is the attempt number. */
|
|
185
|
+
function retryDelayMs(attempt) {
|
|
186
|
+
return Math.min(2000, 100 * 2 ** Math.max(0, attempt));
|
|
187
|
+
}
|
package/dist/expr.d.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { ColumnSpec, ColumnTypeName, SqlValue } from "./values";
|
|
2
|
+
/** Bytecode limits mirrored from the Rust expression engine. */
|
|
3
|
+
export declare const MAX_EXPR_BYTES = 256;
|
|
4
|
+
export declare const MAX_EXPR_STEPS = 512;
|
|
5
|
+
export declare const MAX_EXPR_DEPTH = 64;
|
|
6
|
+
export type SqlFunction = "lower" | "upper" | "length" | "round" | "abs" | "trim" | "ltrim" | "rtrim";
|
|
7
|
+
/** PostgreSQL range predicates exposed by the SQL layer. */
|
|
8
|
+
export type RangePredicate = "contains" | "contained" | "overlaps" | "leftOf" | "rightOf" | "adjacent";
|
|
9
|
+
export type ExprNode = {
|
|
10
|
+
k: "lit";
|
|
11
|
+
value: any;
|
|
12
|
+
} | {
|
|
13
|
+
k: "col";
|
|
14
|
+
index: number;
|
|
15
|
+
side: "new" | "old";
|
|
16
|
+
} | {
|
|
17
|
+
k: "signer";
|
|
18
|
+
} | {
|
|
19
|
+
k: "cmp";
|
|
20
|
+
op: "eq" | "ne" | "lt" | "le" | "gt" | "ge";
|
|
21
|
+
a: ExprNode;
|
|
22
|
+
b: ExprNode;
|
|
23
|
+
} | {
|
|
24
|
+
k: "rangep";
|
|
25
|
+
op: RangePredicate;
|
|
26
|
+
a: ExprNode;
|
|
27
|
+
b: ExprNode;
|
|
28
|
+
} | {
|
|
29
|
+
k: "and" | "or";
|
|
30
|
+
a: ExprNode;
|
|
31
|
+
b: ExprNode;
|
|
32
|
+
} | {
|
|
33
|
+
k: "not";
|
|
34
|
+
a: ExprNode;
|
|
35
|
+
} | {
|
|
36
|
+
k: "isnull" | "isnotnull";
|
|
37
|
+
a: ExprNode;
|
|
38
|
+
} | {
|
|
39
|
+
k: "between";
|
|
40
|
+
a: ExprNode;
|
|
41
|
+
low: ExprNode;
|
|
42
|
+
high: ExprNode;
|
|
43
|
+
negated?: boolean;
|
|
44
|
+
} | {
|
|
45
|
+
k: "in";
|
|
46
|
+
a: ExprNode;
|
|
47
|
+
values: ExprNode[];
|
|
48
|
+
negated?: boolean;
|
|
49
|
+
} | {
|
|
50
|
+
k: "arith";
|
|
51
|
+
op: "add" | "sub" | "mul" | "div";
|
|
52
|
+
a: ExprNode;
|
|
53
|
+
b: ExprNode;
|
|
54
|
+
/** Resolved calendar right-hand kind, set at SQL bind time. */
|
|
55
|
+
calendar?: "date" | "timestamp" | "interval";
|
|
56
|
+
} | {
|
|
57
|
+
k: "case";
|
|
58
|
+
operand?: ExprNode;
|
|
59
|
+
whens: {
|
|
60
|
+
when: ExprNode;
|
|
61
|
+
then: ExprNode;
|
|
62
|
+
}[];
|
|
63
|
+
otherwise?: ExprNode;
|
|
64
|
+
} | {
|
|
65
|
+
k: "coalesce";
|
|
66
|
+
args: ExprNode[];
|
|
67
|
+
} | {
|
|
68
|
+
k: "nullif";
|
|
69
|
+
a: ExprNode;
|
|
70
|
+
b: ExprNode;
|
|
71
|
+
} | {
|
|
72
|
+
k: "cast";
|
|
73
|
+
a: ExprNode;
|
|
74
|
+
type: ColumnTypeName;
|
|
75
|
+
scale?: number;
|
|
76
|
+
maxLen?: number;
|
|
77
|
+
} | {
|
|
78
|
+
k: "func";
|
|
79
|
+
fn: SqlFunction;
|
|
80
|
+
args: ExprNode[];
|
|
81
|
+
};
|
|
82
|
+
export declare const expr: {
|
|
83
|
+
col(index: number, side?: "new" | "old"): ExprNode;
|
|
84
|
+
lit(value: SqlValue): ExprNode;
|
|
85
|
+
eq(a: ExprNode, b: ExprNode): ExprNode;
|
|
86
|
+
ne(a: ExprNode, b: ExprNode): ExprNode;
|
|
87
|
+
lt(a: ExprNode, b: ExprNode): ExprNode;
|
|
88
|
+
le(a: ExprNode, b: ExprNode): ExprNode;
|
|
89
|
+
gt(a: ExprNode, b: ExprNode): ExprNode;
|
|
90
|
+
ge(a: ExprNode, b: ExprNode): ExprNode;
|
|
91
|
+
and(a: ExprNode, b: ExprNode): ExprNode;
|
|
92
|
+
or(a: ExprNode, b: ExprNode): ExprNode;
|
|
93
|
+
not(a: ExprNode): ExprNode;
|
|
94
|
+
isNull(a: ExprNode): ExprNode;
|
|
95
|
+
isNotNull(a: ExprNode): ExprNode;
|
|
96
|
+
add(a: ExprNode, b: ExprNode): ExprNode;
|
|
97
|
+
sub(a: ExprNode, b: ExprNode): ExprNode;
|
|
98
|
+
mul(a: ExprNode, b: ExprNode): ExprNode;
|
|
99
|
+
div(a: ExprNode, b: ExprNode): ExprNode;
|
|
100
|
+
};
|
|
101
|
+
/** Compiles an expression AST into the program's stack bytecode. */
|
|
102
|
+
export declare function compileExpression(node: ExprNode, columns?: ColumnSpec[]): Buffer;
|
|
103
|
+
/**
|
|
104
|
+
* Evaluates a PostgreSQL range predicate. `null` is SQL NULL; a non-range
|
|
105
|
+
* operand where a range is required throws, mirroring the program.
|
|
106
|
+
*/
|
|
107
|
+
export declare function evalRangeOp(op: RangePredicate, a: SqlValue, b: SqlValue): boolean | null;
|
|
108
|
+
/**
|
|
109
|
+
* Arithmetic mirror shared by the predicate evaluator and the query planner.
|
|
110
|
+
* Calendar operations need the bound operand kind, which the SQL binder stores
|
|
111
|
+
* on the `arith` node.
|
|
112
|
+
*/
|
|
113
|
+
export declare function evalArithmetic(op: "add" | "sub" | "mul" | "div", a: SqlValue, b: SqlValue, kind?: "date" | "timestamp" | "interval"): SqlValue;
|
|
114
|
+
export declare function compareValues(a: SqlValue, b: SqlValue): number | null;
|
|
115
|
+
export declare function evaluate(node: ExprNode, row: SqlValue[], oldRow?: SqlValue[], actor?: SqlValue): SqlValue;
|
|
116
|
+
export declare function castValue(value: SqlValue, node: {
|
|
117
|
+
type: ColumnTypeName;
|
|
118
|
+
scale?: number;
|
|
119
|
+
maxLen?: number;
|
|
120
|
+
}): SqlValue;
|
|
121
|
+
export declare function callFunction(fn: string, args: SqlValue[]): SqlValue;
|
|
122
|
+
/** Interprets the program's policy bytecode for read-side filtering. */
|
|
123
|
+
export declare function evaluateBytecode(code: Buffer, row: SqlValue[], oldRow?: SqlValue[], actor?: SqlValue): SqlValue;
|
|
124
|
+
/** Predicate semantics: only TRUE passes. */
|
|
125
|
+
export declare function predicatePasses(node: ExprNode | undefined, row: SqlValue[], oldRow?: SqlValue[], actor?: SqlValue): boolean;
|
|
126
|
+
/** CHECK semantics: passes unless FALSE (UNKNOWN passes). */
|
|
127
|
+
export declare function checkPasses(node: ExprNode, row: SqlValue[]): boolean;
|