UNPKG

envio

Version:

A latency and sync speed optimized, developer friendly blockchain data indexer.

79 lines (73 loc) 2.21 kB
// Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; var Internal = require("./Internal.res.js"); var S$RescriptSchema = require("rescript-schema/src/S.res.js"); function durationToMs(duration) { if (typeof duration !== "number") { if (duration === "second") { return 1000; } else { return 60000; } } else { return duration; } } function createEffect(options, handler) { var outputSchema = S$RescriptSchema.schema(function (param) { return options.output; }); var itemSchema = S$RescriptSchema.schema(function (s) { return { id: s.m(S$RescriptSchema.string), output: s.m(outputSchema) }; }); var match = options.cache; var match$1 = options.rateLimit; var tmp; if (typeof match$1 !== "object") { tmp = undefined; } else { var calls = match$1.calls; tmp = { callsPerDuration: calls, durationMs: durationToMs(match$1.per), availableCalls: calls, windowStartTime: Date.now(), queueCount: 0, nextWindowPromise: undefined }; } return { name: options.name, handler: handler, storageMeta: { itemSchema: itemSchema, outputSchema: outputSchema, table: Internal.makeCacheTable(options.name) }, defaultShouldCache: match !== undefined && match ? true : false, output: outputSchema, input: S$RescriptSchema.schema(function (param) { return options.input; }), activeCallsCount: 0, prevCallStartTimerRef: null, rateLimit: tmp }; } function experimental_createEffect(options, handler) { var rateLimit = options.rateLimit; return createEffect({ name: options.name, input: options.input, output: options.output, rateLimit: rateLimit !== undefined ? rateLimit : false, cache: options.cache }, handler); } exports.durationToMs = durationToMs; exports.createEffect = createEffect; exports.experimental_createEffect = experimental_createEffect; /* Internal Not a pure module */