envio 3.15.0 → 3.16.0-subgraph
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 +40 -34
- package/evm.schema.json +11 -2
- package/fuel.schema.json +10 -1
- package/index.d.ts +6 -0
- package/licenses/README.md +1 -1
- package/package.json +10 -9
- package/src/Batch.res.mjs +5 -5
- package/src/BatchProcessing.res +1 -0
- package/src/BatchProcessing.res.mjs +1 -0
- package/src/Bin.res +7 -0
- package/src/Bin.res.mjs +8 -0
- package/src/ChainFetching.res +450 -16
- package/src/ChainFetching.res.mjs +403 -32
- package/src/ChainState.res +124 -7
- package/src/ChainState.res.mjs +128 -67
- package/src/ChainState.resi +26 -0
- package/src/Clock.res +57 -0
- package/src/Clock.res.mjs +72 -0
- package/src/Config.res +31 -3
- package/src/Config.res.mjs +15 -4
- package/src/ContractRegisterContext.res +3 -6
- package/src/ContractRegisterContext.res.mjs +4 -2
- package/src/Core.res +95 -36
- package/src/Core.res.mjs +90 -1
- package/src/CrossChainState.res +12 -2
- package/src/CrossChainState.res.mjs +3 -3
- package/src/Ecosystem.res +7 -4
- package/src/Ecosystem.res.mjs +8 -8
- package/src/EffectCacheLookup.res +98 -0
- package/src/EffectCacheLookup.res.mjs +116 -0
- package/src/EffectState.res +10 -2
- package/src/EffectState.res.mjs +8 -4
- package/src/EffectState.resi +3 -1
- package/src/EntityId.res +2 -7
- package/src/EntityId.res.mjs +1 -8
- package/src/EntityTables.res +4 -1
- package/src/EntityTables.res.mjs +1 -1
- package/src/Env.res +20 -0
- package/src/Env.res.mjs +16 -0
- package/src/EventProcessing.res +38 -1
- package/src/EventProcessing.res.mjs +28 -1
- package/src/FetchState.res +408 -73
- package/src/FetchState.res.mjs +361 -91
- package/src/FinalizeBackfill.res +2 -4
- package/src/FinalizeBackfill.res.mjs +3 -4
- package/src/HandlerLoader.res +39 -15
- package/src/HandlerLoader.res.mjs +27 -8
- package/src/HandlerRegister.res +4 -0
- package/src/HandlerRegister.res.mjs +5 -2
- package/src/HandlerRegister.resi +2 -0
- package/src/InMemoryTable.res +17 -16
- package/src/InMemoryTable.res.mjs +14 -15
- package/src/IndexerState.res +28 -4
- package/src/IndexerState.res.mjs +19 -6
- package/src/IndexerState.resi +4 -0
- package/src/Internal.res +61 -49
- package/src/Internal.res.mjs +36 -80
- package/src/LoadLayer.res +54 -15
- package/src/LoadLayer.res.mjs +75 -45
- package/src/LoadLayer.resi +26 -0
- package/src/Main.res +14 -1
- package/src/Main.res.mjs +4 -3
- package/src/Persistence.res +3 -23
- package/src/Persistence.res.mjs +3 -3
- package/src/PreloadLookahead.res +202 -0
- package/src/PreloadLookahead.res.mjs +218 -0
- package/src/Rollback.res +0 -1
- package/src/Rollback.res.mjs +1 -1
- package/src/RunScope.res +3 -0
- package/src/SafeCheckpointTracking.res +4 -4
- package/src/SafeCheckpointTracking.res.mjs +1 -1
- package/src/SimulateItems.res +42 -26
- package/src/SimulateItems.res.mjs +40 -16
- package/src/StagedRows.res +106 -0
- package/src/StagedRows.res.mjs +102 -0
- package/src/Staging.res +32 -14
- package/src/Staging.res.mjs +17 -20
- package/src/Storage.res +303 -948
- package/src/Storage.res.mjs +229 -708
- package/src/SubgraphLog.res +19 -0
- package/src/SubgraphLog.res.mjs +26 -0
- package/src/Supervisor.res +75 -56
- package/src/Supervisor.res.mjs +55 -26
- package/src/SyncWrites.res +107 -0
- package/src/SyncWrites.res.mjs +98 -0
- package/src/TestIndexer.res +22 -27
- package/src/TestIndexer.res.mjs +20 -17
- package/src/Throttler.res +15 -8
- package/src/Throttler.res.mjs +9 -6
- package/src/Throttler.resi +1 -1
- package/src/UserContext.res +419 -46
- package/src/UserContext.res.mjs +318 -30
- package/src/Utils.res +17 -6
- package/src/Utils.res.mjs +12 -6
- package/src/Writing.res +0 -1
- package/src/Writing.res.mjs +1 -1
- package/src/bindings/ClickHouse.res +0 -322
- package/src/bindings/ClickHouse.res.mjs +0 -338
- package/src/bindings/StorageClient.res +108 -174
- package/src/bindings/StorageClient.res.mjs +19 -8
- package/src/bindings/Vitest.res +0 -26
- package/src/bindings/Vitest.res.mjs +0 -3
- package/src/db/Table.res +24 -150
- package/src/db/Table.res.mjs +38 -272
- package/src/sources/AddressSet.res +2 -0
- package/src/sources/AddressStore.res +3 -0
- package/src/sources/CallSource.res +274 -0
- package/src/sources/CallSource.res.mjs +196 -0
- package/src/sources/ChainSources.res +2 -0
- package/src/sources/ChainSources.res.mjs +2 -2
- package/src/sources/EvmChain.res +10 -1
- package/src/sources/EvmChain.res.mjs +6 -3
- package/src/sources/EvmHyperSyncSource.res +2 -2
- package/src/sources/EvmHyperSyncSource.res.mjs +1 -1
- package/src/sources/EvmRpcClient.res +13 -3
- package/src/sources/EvmRpcClient.res.mjs +4 -3
- package/src/sources/EvmRpcWs.res +4 -3
- package/src/sources/EvmRpcWs.res.mjs +2 -2
- package/src/sources/HeightFeed.res +31 -10
- package/src/sources/HeightFeed.res.mjs +10 -6
- package/src/sources/HeightStream.res +32 -17
- package/src/sources/HeightStream.res.mjs +10 -10
- package/src/sources/HyperSync.res +2 -1
- package/src/sources/HyperSync.res.mjs +2 -1
- package/src/sources/HyperSyncSSE.res +4 -6
- package/src/sources/HyperSyncSSE.res.mjs +2 -2
- package/src/sources/RpcSource.res +10 -1
- package/src/sources/RpcSource.res.mjs +4 -3
- package/src/sources/Source.res +3 -0
- package/src/sources/SourceManager.res +84 -77
- package/src/sources/SourceManager.res.mjs +17 -20
- package/src/sources/SourceManager.resi +3 -4
- package/src/sources/StartBlockResolver.res +1 -0
- package/src/sources/StartBlockResolver.res.mjs +3 -2
- package/src/sources/SvmHyperSyncSource.res +2 -2
- package/src/sources/SvmHyperSyncSource.res.mjs +1 -1
- package/src/subgraph/abi-types.ts +84 -0
- package/src/subgraph/aggregations.ts +745 -0
- package/src/subgraph/as-package.ts +143 -0
- package/src/subgraph/assemblyscript-regex.ts +67 -0
- package/src/subgraph/assemblyscript.ts +731 -0
- package/src/subgraph/blocks.ts +398 -0
- package/src/subgraph/calls-source.ts +702 -0
- package/src/subgraph/calls.ts +258 -0
- package/src/subgraph/conformance.ts +106 -0
- package/src/subgraph/errors.ts +85 -0
- package/src/subgraph/graft.ts +73 -0
- package/src/subgraph/graph-cli-worker.mjs +35 -0
- package/src/subgraph/graph-cli.ts +900 -0
- package/src/subgraph/graph-node-decimal.ts +199 -0
- package/src/subgraph/graph-ts-enums.ts +28 -0
- package/src/subgraph/graph-ts-types/VERSION +2 -0
- package/src/subgraph/graph-ts-types/chain/arweave.d.ts +70 -0
- package/src/subgraph/graph-ts-types/chain/cosmos.d.ts +327 -0
- package/src/subgraph/graph-ts-types/chain/ethereum.d.ts +233 -0
- package/src/subgraph/graph-ts-types/chain/near.d.ts +253 -0
- package/src/subgraph/graph-ts-types/chain/starknet.d.ts +32 -0
- package/src/subgraph/graph-ts-types/common/collections.d.ts +136 -0
- package/src/subgraph/graph-ts-types/common/conversion.d.ts +11 -0
- package/src/subgraph/graph-ts-types/common/datasource.d.ts +30 -0
- package/src/subgraph/graph-ts-types/common/eager-offset.d.ts +0 -0
- package/src/subgraph/graph-ts-types/common/json.d.ts +17 -0
- package/src/subgraph/graph-ts-types/common/numbers.d.ts +120 -0
- package/src/subgraph/graph-ts-types/common/value.d.ts +120 -0
- package/src/subgraph/graph-ts-types/common/yaml.d.ts +90 -0
- package/src/subgraph/graph-ts-types/global/global.d.ts +194 -0
- package/src/subgraph/graph-ts-types/helper-functions.d.ts +22 -0
- package/src/subgraph/graph-ts-types/index.d.ts +102 -0
- package/src/subgraph/graph-ts.ts +4339 -0
- package/src/subgraph/hosts.ts +554 -0
- package/src/subgraph/log.ts +28 -0
- package/src/subgraph/receipts.ts +184 -0
- package/src/subgraph/register-slots.ts +93 -0
- package/src/subgraph/rollup.ts +109 -0
- package/src/subgraph/rpc.ts +337 -0
- package/src/subgraph/runtime.ts +2059 -0
- package/src/subgraph/scope.ts +176 -0
- package/src/subgraph/stats.ts +42 -0
- package/src/subgraph/template-instances.ts +66 -0
- package/src/subgraph/toolchain.ts +327 -0
- package/src/subgraph/transient.ts +176 -0
- package/svm.schema.json +11 -2
- package/src/PgWriting.res +0 -36
- package/src/PgWriting.res.mjs +0 -34
- package/src/db/IndexDefinition.res +0 -47
- package/src/db/IndexDefinition.res.mjs +0 -67
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every host op that leaves the process — contract calls, balances, block
|
|
3
|
+
* timestamps, IPFS, Arweave, ENS — runs through `untilAnswered`.
|
|
4
|
+
*
|
|
5
|
+
* envio exits on a handler error; it has no batch retry. So a transient failure
|
|
6
|
+
* that escaped a host op would stop the whole indexer on one rate-limited call,
|
|
7
|
+
* where graph-node backs off and asks again. Only a deterministic answer — a
|
|
8
|
+
* value, a revert, a definite miss — may reach the mapping or end the run.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { warn } from "./log.ts";
|
|
12
|
+
|
|
13
|
+
const MAX_BACKOFF_MS = 30_000;
|
|
14
|
+
|
|
15
|
+
function positive(name: string, fallback: number): number {
|
|
16
|
+
const value = Number(process.env[name]);
|
|
17
|
+
return Number.isFinite(value) && value > 0 ? value : fallback;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Each attempt's deadline: a request that never answers is given up on. */
|
|
21
|
+
export function requestTimeoutMs(): number {
|
|
22
|
+
return positive("ENVIO_SUBGRAPH_REQUEST_TIMEOUT_MS", 30_000);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function firstBackoffMs(): number {
|
|
26
|
+
return positive("ENVIO_SUBGRAPH_RETRY_BACKOFF_MS", 500);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** A response status the endpoint answered with. */
|
|
30
|
+
export class HttpStatusError extends Error {
|
|
31
|
+
constructor(
|
|
32
|
+
readonly url: string,
|
|
33
|
+
readonly status: number,
|
|
34
|
+
statusText: string,
|
|
35
|
+
) {
|
|
36
|
+
super(`${url} answered ${status} ${statusText}`.trim());
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
class AttemptTimeout extends Error {
|
|
41
|
+
constructor(what: string, ms: number) {
|
|
42
|
+
super(`${what} didn't answer within ${ms}ms`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const TRANSIENT_TEXT =
|
|
47
|
+
/rate.?limit|too many requests|capacity|limit exceeded|exceeds? (the |its |defined )?limit|timed? ?out|timeout|header not found|ECONNRESET|ECONNREFUSED|EPIPE|ETIMEDOUT|EAI_AGAIN|ENOTFOUND|socket hang up|fetch failed|network|temporar|unavailable|overloaded|busy|try again/i;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* JSON-RPC codes public endpoints send for "slow down": -32005 "limit
|
|
51
|
+
* exceeded" (Infura, Tenderly), -32097 (blastapi), -32090 (Alchemy).
|
|
52
|
+
*/
|
|
53
|
+
const RATE_LIMIT_CODES = new Set([-32005, -32097, -32090]);
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The rate limits, and the node's own failure, -32603 "Internal error", which
|
|
57
|
+
* the same request answers on the next try. graph-node asks again after every
|
|
58
|
+
* eth_call error that isn't a revert (`interpret_eth_call_error`).
|
|
59
|
+
*/
|
|
60
|
+
const TRANSIENT_CODES = new Set([...RATE_LIMIT_CODES, -32603]);
|
|
61
|
+
|
|
62
|
+
function transientStatus(status: number): boolean {
|
|
63
|
+
return status === 408 || status === 425 || status === 429 || status >= 500;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const RATE_LIMIT_TEXT = /rate.?limit|too many requests|request limit|limit exceeded/i;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The endpoint saying "slow down" — HTTP 429, or a JSON-RPC rate-limit error —
|
|
70
|
+
* on an error or on a JSON-RPC error object, anywhere down its cause chain.
|
|
71
|
+
*/
|
|
72
|
+
export function isRateLimit(error: unknown): boolean {
|
|
73
|
+
let current: any = error;
|
|
74
|
+
for (let depth = 0; current && depth < 10; depth++) {
|
|
75
|
+
if (current.status === 429 || current.code === 429 || RATE_LIMIT_CODES.has(current.code)) return true;
|
|
76
|
+
if (typeof current.message === "string" && RATE_LIMIT_TEXT.test(current.message)) return true;
|
|
77
|
+
current = current.cause;
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Whether asking again could get a different answer. A status decides it when
|
|
84
|
+
* there is one; otherwise the error's own words do, down its cause chain.
|
|
85
|
+
*/
|
|
86
|
+
export function isTransient(error: unknown): boolean {
|
|
87
|
+
let current: any = error;
|
|
88
|
+
for (let depth = 0; current && depth < 10; depth++) {
|
|
89
|
+
if (current instanceof AttemptTimeout) return true;
|
|
90
|
+
if (current.name === "AbortError" || current.name === "TimeoutError") return true;
|
|
91
|
+
if (typeof current.status === "number") return transientStatus(current.status);
|
|
92
|
+
if (TRANSIENT_CODES.has(current.code)) return true;
|
|
93
|
+
if (typeof current.message === "string" && TRANSIENT_TEXT.test(current.message)) return true;
|
|
94
|
+
current = current.cause;
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* One try, given `requestTimeoutMs`. The deadline holds even if the attempt
|
|
103
|
+
* ignores its signal, so a hung request can't stall the handler waiting on it.
|
|
104
|
+
*/
|
|
105
|
+
export async function withDeadline<T>(
|
|
106
|
+
what: string,
|
|
107
|
+
attempt: (signal: AbortSignal) => Promise<T>,
|
|
108
|
+
): Promise<T> {
|
|
109
|
+
const timeout = requestTimeoutMs();
|
|
110
|
+
const controller = new AbortController();
|
|
111
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
112
|
+
const deadline = new Promise<never>((_, reject) => {
|
|
113
|
+
timer = setTimeout(() => {
|
|
114
|
+
const error = new AttemptTimeout(what, timeout);
|
|
115
|
+
controller.abort(error);
|
|
116
|
+
reject(error);
|
|
117
|
+
}, timeout);
|
|
118
|
+
});
|
|
119
|
+
try {
|
|
120
|
+
return await Promise.race([attempt(controller.signal), deadline]);
|
|
121
|
+
} finally {
|
|
122
|
+
clearTimeout(timer);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Tries `attempt` until it answers, backing off exponentially between transient
|
|
128
|
+
* failures. With `maxTries`, the last transient failure is thrown once that
|
|
129
|
+
* many attempts have failed; with `budgetMs`, once the next wait would end
|
|
130
|
+
* past that long after the first attempt.
|
|
131
|
+
*/
|
|
132
|
+
export async function untilAnswered<T>(
|
|
133
|
+
what: string,
|
|
134
|
+
attempt: (signal: AbortSignal) => Promise<T>,
|
|
135
|
+
{
|
|
136
|
+
maxTries = Infinity,
|
|
137
|
+
// An attempt that goes through a gate (`rpc.ts`) gets its deadline there,
|
|
138
|
+
// once it holds a slot: timed from here, a request still queued behind
|
|
139
|
+
// the gate would time out unsent, be asked again, and be sent twice.
|
|
140
|
+
deadline = true,
|
|
141
|
+
budgetMs = Infinity,
|
|
142
|
+
}: { maxTries?: number; deadline?: boolean; budgetMs?: number } = {},
|
|
143
|
+
): Promise<T> {
|
|
144
|
+
const started = Date.now();
|
|
145
|
+
for (let tries = 0; ; tries++) {
|
|
146
|
+
try {
|
|
147
|
+
return await (deadline ? withDeadline(what, attempt) : attempt(new AbortController().signal));
|
|
148
|
+
} catch (error) {
|
|
149
|
+
if (!isTransient(error) || tries + 1 >= maxTries) throw error;
|
|
150
|
+
const wait = Math.min(firstBackoffMs() * 2 ** tries, MAX_BACKOFF_MS);
|
|
151
|
+
if (Date.now() - started + wait > budgetMs) throw error;
|
|
152
|
+
const reason = error instanceof Error ? error.message.split("\n")[0] : String(error);
|
|
153
|
+
warn(`Envio Subgraph: ${what} failed (${reason}); asking again in ${wait}ms.`);
|
|
154
|
+
await sleep(wait);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* A revert is data: the mapping's `try_` sees `{reverted: true}`, and every
|
|
161
|
+
* node gives the same one. Geth says it in the message; Parity, OpenEthereum
|
|
162
|
+
* and older Nethermind answer -32015 "VM execution error." and say it in the
|
|
163
|
+
* error's data ("Reverted 0x…"), as graph-node reads them.
|
|
164
|
+
*/
|
|
165
|
+
export function isRevert(error: unknown): boolean {
|
|
166
|
+
let current: any = error;
|
|
167
|
+
for (let depth = 0; current && depth < 10; depth++) {
|
|
168
|
+
for (const text of [current.message, current.data]) {
|
|
169
|
+
if (typeof text === "string" && REVERT_TEXT.test(text)) return true;
|
|
170
|
+
}
|
|
171
|
+
current = current.cause;
|
|
172
|
+
}
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const REVERT_TEXT = /revert|invalid opcode|bad instruction|bad jump|out of gas/i;
|
package/svm.schema.json
CHANGED
|
@@ -219,6 +219,15 @@
|
|
|
219
219
|
"format": "uint32",
|
|
220
220
|
"minimum": 0
|
|
221
221
|
},
|
|
222
|
+
"block_throttle": {
|
|
223
|
+
"description": "Once caught up, wait for this many new slots before fetching them. Delays new instructions by up to as many slots.",
|
|
224
|
+
"type": [
|
|
225
|
+
"integer",
|
|
226
|
+
"null"
|
|
227
|
+
],
|
|
228
|
+
"format": "uint32",
|
|
229
|
+
"minimum": 0
|
|
230
|
+
},
|
|
222
231
|
"hypersync_config": {
|
|
223
232
|
"description": "HyperSync Config for fetching historical instructions on this chain. Optional for the `solana` and `solana-devnet` chain ids, which default to their public HyperSync endpoints; required for any other chain id.",
|
|
224
233
|
"anyOf": [
|
|
@@ -294,7 +303,7 @@
|
|
|
294
303
|
"type": "object",
|
|
295
304
|
"properties": {
|
|
296
305
|
"name": {
|
|
297
|
-
"description": "A unique project-wide name for this program (used in generated
|
|
306
|
+
"description": "A unique project-wide name for this program (used in the generated types).",
|
|
298
307
|
"type": "string"
|
|
299
308
|
},
|
|
300
309
|
"program_id": {
|
|
@@ -348,7 +357,7 @@
|
|
|
348
357
|
"type": "object",
|
|
349
358
|
"properties": {
|
|
350
359
|
"name": {
|
|
351
|
-
"description": "Name of the instruction in the
|
|
360
|
+
"description": "Name of the instruction in the generated types. Should be unique per program.",
|
|
352
361
|
"type": "string"
|
|
353
362
|
},
|
|
354
363
|
"discriminator": {
|
package/src/PgWriting.res
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
let columns = (fields: array<Table.field>, ~kinds: array<Staging.kind>): array<Staging.column> =>
|
|
2
|
-
fields->Array.mapWithIndex((field, index) => {
|
|
3
|
-
Staging.name: field->Table.getPgDbFieldName,
|
|
4
|
-
kind: kinds->Array.getUnsafe(index),
|
|
5
|
-
isNullable: field.isNullable,
|
|
6
|
-
})
|
|
7
|
-
|
|
8
|
-
// Lays a batch into the arena, column by column. The values are the ones the
|
|
9
|
-
// table's own schema produced — a bigint as its digits, a date as its text, a
|
|
10
|
-
// boolean as the number the statement's cast expects — so nothing here has to
|
|
11
|
-
// know what a column means, only where its values go.
|
|
12
|
-
//
|
|
13
|
-
// The rows of a column are written in order because a variable-width slot's row
|
|
14
|
-
// starts where the row before it ended.
|
|
15
|
-
let stage = (
|
|
16
|
-
arena,
|
|
17
|
-
~table,
|
|
18
|
-
~columns: array<Staging.column>,
|
|
19
|
-
~values: array<array<unknown>>,
|
|
20
|
-
~rows,
|
|
21
|
-
) => {
|
|
22
|
-
let stage = arena->Staging.begin(~table, ~rows, ~columns)
|
|
23
|
-
try {
|
|
24
|
-
for column in 0 to columns->Array.length - 1 {
|
|
25
|
-
let values = values->Array.getUnsafe(column)
|
|
26
|
-
for row in 0 to rows - 1 {
|
|
27
|
-
stage->Staging.writeValue(~column, ~row, values->Array.getUnsafe(row))
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
stage->Staging.commit
|
|
31
|
-
} catch {
|
|
32
|
-
| exn =>
|
|
33
|
-
stage->Staging.abort
|
|
34
|
-
throw(exn)
|
|
35
|
-
}
|
|
36
|
-
}
|
package/src/PgWriting.res.mjs
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
-
|
|
3
|
-
import * as Table from "./db/Table.res.mjs";
|
|
4
|
-
import * as Staging from "./Staging.res.mjs";
|
|
5
|
-
|
|
6
|
-
function columns(fields, kinds) {
|
|
7
|
-
return fields.map((field, index) => ({
|
|
8
|
-
name: Table.getPgDbFieldName(field),
|
|
9
|
-
kind: kinds[index],
|
|
10
|
-
isNullable: field.isNullable
|
|
11
|
-
}));
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function stage(arena, table, columns, values, rows) {
|
|
15
|
-
let stage$1 = Staging.begin(arena, table, rows, columns);
|
|
16
|
-
try {
|
|
17
|
-
for (let column = 0, column_finish = columns.length; column < column_finish; ++column) {
|
|
18
|
-
let values$1 = values[column];
|
|
19
|
-
for (let row = 0; row < rows; ++row) {
|
|
20
|
-
Staging.writeValue(stage$1, column, row, values$1[row]);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return Staging.commit(stage$1);
|
|
24
|
-
} catch (exn) {
|
|
25
|
-
Staging.abort(stage$1);
|
|
26
|
-
throw exn;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export {
|
|
31
|
-
columns,
|
|
32
|
-
stage,
|
|
33
|
-
}
|
|
34
|
-
/* Table Not a pure module */
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// What the indexer wants an index to be: a table, its ordered key columns with
|
|
2
|
-
// their directions, and an access method. The addon names it, matches it
|
|
3
|
-
// against what PostgreSQL holds and builds it.
|
|
4
|
-
|
|
5
|
-
type column = {
|
|
6
|
-
name: string,
|
|
7
|
-
direction: Table.indexFieldDirection,
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
type t = {
|
|
11
|
-
tableName: string,
|
|
12
|
-
columns: array<column>,
|
|
13
|
-
method: string,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
let make = (~tableName, ~columns) => {tableName, columns, method: "btree"}
|
|
17
|
-
|
|
18
|
-
let single = (~tableName, ~column) =>
|
|
19
|
-
make(~tableName, ~columns=[{name: column, direction: Table.Asc}])
|
|
20
|
-
|
|
21
|
-
let fromIndexFields = (~tableName, ~indexFields: array<Table.compositeIndexField>) =>
|
|
22
|
-
make(
|
|
23
|
-
~tableName,
|
|
24
|
-
~columns=indexFields->Array.map(({fieldName, direction}) => {name: fieldName, direction}),
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
let toInput = ({tableName, columns, method}: t): Core.pgIndexInput => {
|
|
28
|
-
tableName,
|
|
29
|
-
columns: columns->Array.map(({name, direction}): Core.pgIndexColumnInput => {
|
|
30
|
-
name,
|
|
31
|
-
direction: switch direction {
|
|
32
|
-
| Table.Asc => "Asc"
|
|
33
|
-
| Desc => "Desc"
|
|
34
|
-
},
|
|
35
|
-
}),
|
|
36
|
-
method,
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
let describe = (definition: t) =>
|
|
40
|
-
`${definition.tableName}(${definition.columns
|
|
41
|
-
->Array.map(({name, direction}) =>
|
|
42
|
-
switch direction {
|
|
43
|
-
| Asc => name
|
|
44
|
-
| Desc => `${name} DESC`
|
|
45
|
-
}
|
|
46
|
-
)
|
|
47
|
-
->Array.joinUnsafe(", ")}) using ${definition.method}`
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function make(tableName, columns) {
|
|
5
|
-
return {
|
|
6
|
-
tableName: tableName,
|
|
7
|
-
columns: columns,
|
|
8
|
-
method: "btree"
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function single(tableName, column) {
|
|
13
|
-
return {
|
|
14
|
-
tableName: tableName,
|
|
15
|
-
columns: [{
|
|
16
|
-
name: column,
|
|
17
|
-
direction: "Asc"
|
|
18
|
-
}],
|
|
19
|
-
method: "btree"
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function fromIndexFields(tableName, indexFields) {
|
|
24
|
-
return {
|
|
25
|
-
tableName: tableName,
|
|
26
|
-
columns: indexFields.map(param => ({
|
|
27
|
-
name: param.fieldName,
|
|
28
|
-
direction: param.direction
|
|
29
|
-
})),
|
|
30
|
-
method: "btree"
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function toInput(param) {
|
|
35
|
-
return {
|
|
36
|
-
tableName: param.tableName,
|
|
37
|
-
columns: param.columns.map(param => {
|
|
38
|
-
let tmp;
|
|
39
|
-
tmp = param.direction === "Asc" ? "Asc" : "Desc";
|
|
40
|
-
return {
|
|
41
|
-
name: param.name,
|
|
42
|
-
direction: tmp
|
|
43
|
-
};
|
|
44
|
-
}),
|
|
45
|
-
method: param.method
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function describe(definition) {
|
|
50
|
-
return definition.tableName + `(` + definition.columns.map(param => {
|
|
51
|
-
let name = param.name;
|
|
52
|
-
if (param.direction === "Asc") {
|
|
53
|
-
return name;
|
|
54
|
-
} else {
|
|
55
|
-
return name + ` DESC`;
|
|
56
|
-
}
|
|
57
|
-
}).join(", ") + `) using ` + definition.method;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export {
|
|
61
|
-
make,
|
|
62
|
-
single,
|
|
63
|
-
fromIndexFields,
|
|
64
|
-
toInput,
|
|
65
|
-
describe,
|
|
66
|
-
}
|
|
67
|
-
/* No side effect */
|