@hasura/ndc-sdk-typescript
Version:
This SDK is mostly analogous to the Rust SDK, except where necessary.
96 lines • 4.14 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.startServer = void 0;
exports.start = start;
exports.getServeCommand = getServeCommand;
// Initializing telemetry must be done before importing any other module
// Users of the SDK can choose to initialize it manually themselves, so we check that
// that hasn't already been done
const instrumentation = __importStar(require("./instrumentation"));
if (!instrumentation.isInitialized()) {
instrumentation.initTelemetry();
}
const commander_1 = require("commander");
const server_1 = require("./server");
Object.defineProperty(exports, "startServer", { enumerable: true, get: function () { return server_1.startServer; } });
__exportStar(require("./error"), exports);
__exportStar(require("./schema"), exports);
/**
* Starts the connector.
* Will read command line arguments or environment variables to determine runtime configuration.
*
* This should be the entrypoint of your connector
* @param connector An object that implements the Connector interface
*/
function start(connector) {
const program = new commander_1.Command();
program.addCommand(getServeCommand(connector));
program.parseAsync(process.argv).catch(console.error);
}
function getServeCommand(connector) {
const command = new commander_1.Command("serve")
.addOption(new commander_1.Option("--configuration <directory>")
.env("HASURA_CONFIGURATION_DIRECTORY")
.makeOptionMandatory(true))
.addOption(new commander_1.Option("--host <host>")
.env("HASURA_CONNECTOR_HOST")
.default("::"))
.addOption(new commander_1.Option("--port <port>")
.env("HASURA_CONNECTOR_PORT")
.default(8080)
.argParser(parseIntOption))
.addOption(new commander_1.Option("--service-token-secret <secret>").env("HASURA_SERVICE_TOKEN_SECRET"))
.addOption(new commander_1.Option("--log-level <level>").env("HASURA_LOG_LEVEL").default("info"))
.addOption(new commander_1.Option("--pretty-print-logs").env("HASURA_PRETTY_PRINT_LOGS").default(false));
if (connector) {
command.action(async (options) => {
await (0, server_1.startServer)(connector, options);
});
}
return command;
}
function parseIntOption(value, _previous) {
// parseInt takes a string and a radix
const parsedValue = parseInt(value, 10);
if (isNaN(parsedValue)) {
throw new commander_1.InvalidOptionArgumentError("Not a valid integer.");
}
return parsedValue;
}
//# sourceMappingURL=index.js.map