ad4m-host
Version:
Self hosting ad4m service
1,321 lines (1,319 loc) • 21.2 MB
JavaScript
#!/usr/bin/env node
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __commonJS = (cb, mod4) => function __require() {
return mod4 || (0, cb[__getOwnPropNames(cb)[0]])((mod4 = { exports: {} }).exports, mod4), mod4.exports;
};
var __export = (target, all10) => {
for (var name11 in all10)
__defProp(target, name11, { get: all10[name11], enumerable: true });
};
var __copyProps = (to, from7, except, desc9) => {
if (from7 && typeof from7 === "object" || typeof from7 === "function") {
for (let key of __getOwnPropNames(from7))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from7[key], enumerable: !(desc9 = __getOwnPropDesc(from7, key)) || desc9.enumerable });
}
return to;
};
var __toESM = (mod4, isNodeMode, target) => (target = mod4 != null ? __create(__getProtoOf(mod4)) : {}, __copyProps(
isNodeMode || !mod4 || !mod4.__esModule ? __defProp(target, "default", { value: mod4, enumerable: true }) : target,
mod4
));
// ../core/lib/index.cjs
var require_lib = __commonJS({
"../core/lib/index.cjs"(exports, module) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var __assign = function() {
__assign = Object.assign || function __assign2(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function _typeof$3(obj) {
"@babel/helpers - typeof";
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof$3 = function _typeof2(obj2) {
return typeof obj2;
};
} else {
_typeof$3 = function _typeof2(obj2) {
return obj2 && typeof Symbol === "function" && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
};
}
return _typeof$3(obj);
}
function isObjectLike(value) {
return _typeof$3(value) == "object" && value !== null;
}
var SYMBOL_TO_STRING_TAG = typeof Symbol === "function" && Symbol.toStringTag != null ? Symbol.toStringTag : "@@toStringTag";
function getLocation(source2, position) {
var lineRegexp = /\r\n|[\n\r]/g;
var line = 1;
var column = position + 1;
var match;
while ((match = lineRegexp.exec(source2.body)) && match.index < position) {
line += 1;
column = position + 1 - (match.index + match[0].length);
}
return {
line,
column
};
}
function printLocation(location2) {
return printSourceLocation(location2.source, getLocation(location2.source, location2.start));
}
function printSourceLocation(source2, sourceLocation) {
var firstLineColumnOffset = source2.locationOffset.column - 1;
var body = whitespace(firstLineColumnOffset) + source2.body;
var lineIndex = sourceLocation.line - 1;
var lineOffset = source2.locationOffset.line - 1;
var lineNum = sourceLocation.line + lineOffset;
var columnOffset = sourceLocation.line === 1 ? firstLineColumnOffset : 0;
var columnNum = sourceLocation.column + columnOffset;
var locationStr = "".concat(source2.name, ":").concat(lineNum, ":").concat(columnNum, "\n");
var lines = body.split(/\r\n|[\n\r]/g);
var locationLine = lines[lineIndex];
if (locationLine.length > 120) {
var subLineIndex = Math.floor(columnNum / 80);
var subLineColumnNum = columnNum % 80;
var subLines = [];
for (var i = 0; i < locationLine.length; i += 80) {
subLines.push(locationLine.slice(i, i + 80));
}
return locationStr + printPrefixedLines([["".concat(lineNum), subLines[0]]].concat(subLines.slice(1, subLineIndex + 1).map(function(subLine) {
return ["", subLine];
}), [[" ", whitespace(subLineColumnNum - 1) + "^"], ["", subLines[subLineIndex + 1]]]));
}
return locationStr + printPrefixedLines([
["".concat(lineNum - 1), lines[lineIndex - 1]],
["".concat(lineNum), locationLine],
["", whitespace(columnNum - 1) + "^"],
["".concat(lineNum + 1), lines[lineIndex + 1]]
]);
}
function printPrefixedLines(lines) {
var existingLines = lines.filter(function(_ref) {
_ref[0];
var line = _ref[1];
return line !== void 0;
});
var padLen = Math.max.apply(Math, existingLines.map(function(_ref2) {
var prefix = _ref2[0];
return prefix.length;
}));
return existingLines.map(function(_ref3) {
var prefix = _ref3[0], line = _ref3[1];
return leftPad(padLen, prefix) + (line ? " | " + line : " |");
}).join("\n");
}
function whitespace(len) {
return Array(len + 1).join(" ");
}
function leftPad(len, str2) {
return whitespace(len - str2.length) + str2;
}
function _typeof$2(obj) {
"@babel/helpers - typeof";
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof$2 = function _typeof2(obj2) {
return typeof obj2;
};
} else {
_typeof$2 = function _typeof2(obj2) {
return obj2 && typeof Symbol === "function" && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
};
}
return _typeof$2(obj);
}
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly)
symbols = symbols.filter(function(sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread(target) {
for (var i = 1; i < arguments.length; i++) {
var source2 = arguments[i] != null ? arguments[i] : {};
if (i % 2) {
ownKeys(Object(source2), true).forEach(function(key) {
_defineProperty(target, key, source2[key]);
});
} else if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source2));
} else {
ownKeys(Object(source2)).forEach(function(key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source2, key));
});
}
}
return target;
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
} else {
obj[key] = value;
}
return obj;
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties$1(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor)
descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass$1(Constructor, protoProps, staticProps) {
if (protoProps)
_defineProperties$1(Constructor.prototype, protoProps);
if (staticProps)
_defineProperties$1(Constructor, staticProps);
return Constructor;
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } });
if (superClass)
_setPrototypeOf(subClass, superClass);
}
function _createSuper(Derived) {
var hasNativeReflectConstruct = _isNativeReflectConstruct();
return function _createSuperInternal() {
var Super = _getPrototypeOf(Derived), result;
if (hasNativeReflectConstruct) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
function _possibleConstructorReturn(self2, call) {
if (call && (_typeof$2(call) === "object" || typeof call === "function")) {
return call;
}
return _assertThisInitialized(self2);
}
function _assertThisInitialized(self2) {
if (self2 === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self2;
}
function _wrapNativeSuper(Class) {
var _cache = typeof Map === "function" ? /* @__PURE__ */ new Map() : void 0;
_wrapNativeSuper = function _wrapNativeSuper2(Class2) {
if (Class2 === null || !_isNativeFunction(Class2))
return Class2;
if (typeof Class2 !== "function") {
throw new TypeError("Super expression must either be null or a function");
}
if (typeof _cache !== "undefined") {
if (_cache.has(Class2))
return _cache.get(Class2);
_cache.set(Class2, Wrapper);
}
function Wrapper() {
return _construct(Class2, arguments, _getPrototypeOf(this).constructor);
}
Wrapper.prototype = Object.create(Class2.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } });
return _setPrototypeOf(Wrapper, Class2);
};
return _wrapNativeSuper(Class);
}
function _construct(Parent, args, Class) {
if (_isNativeReflectConstruct()) {
_construct = Reflect.construct;
} else {
_construct = function _construct2(Parent2, args2, Class2) {
var a = [null];
a.push.apply(a, args2);
var Constructor = Function.bind.apply(Parent2, a);
var instance = new Constructor();
if (Class2)
_setPrototypeOf(instance, Class2.prototype);
return instance;
};
}
return _construct.apply(null, arguments);
}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct)
return false;
if (Reflect.construct.sham)
return false;
if (typeof Proxy === "function")
return true;
try {
Date.prototype.toString.call(Reflect.construct(Date, [], function() {
}));
return true;
} catch (e) {
return false;
}
}
function _isNativeFunction(fn) {
return Function.toString.call(fn).indexOf("[native code]") !== -1;
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf2(o2, p2) {
o2.__proto__ = p2;
return o2;
};
return _setPrototypeOf(o, p);
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf2(o2) {
return o2.__proto__ || Object.getPrototypeOf(o2);
};
return _getPrototypeOf(o);
}
var GraphQLError = /* @__PURE__ */ function(_Error) {
_inherits(GraphQLError4, _Error);
var _super = _createSuper(GraphQLError4);
function GraphQLError4(message3, nodes, source2, positions, path21, originalError, extensions) {
var _nodeLocations, _nodeLocations2, _nodeLocations3;
var _this;
_classCallCheck(this, GraphQLError4);
_this = _super.call(this, message3);
_this.name = "GraphQLError";
_this.originalError = originalError !== null && originalError !== void 0 ? originalError : void 0;
_this.nodes = undefinedIfEmpty(Array.isArray(nodes) ? nodes : nodes ? [nodes] : void 0);
var nodeLocations = [];
for (var _i2 = 0, _ref3 = (_this$nodes = _this.nodes) !== null && _this$nodes !== void 0 ? _this$nodes : []; _i2 < _ref3.length; _i2++) {
var _this$nodes;
var _ref4 = _ref3[_i2];
var loc = _ref4.loc;
if (loc != null) {
nodeLocations.push(loc);
}
}
nodeLocations = undefinedIfEmpty(nodeLocations);
_this.source = source2 !== null && source2 !== void 0 ? source2 : (_nodeLocations = nodeLocations) === null || _nodeLocations === void 0 ? void 0 : _nodeLocations[0].source;
_this.positions = positions !== null && positions !== void 0 ? positions : (_nodeLocations2 = nodeLocations) === null || _nodeLocations2 === void 0 ? void 0 : _nodeLocations2.map(function(loc2) {
return loc2.start;
});
_this.locations = positions && source2 ? positions.map(function(pos) {
return getLocation(source2, pos);
}) : (_nodeLocations3 = nodeLocations) === null || _nodeLocations3 === void 0 ? void 0 : _nodeLocations3.map(function(loc2) {
return getLocation(loc2.source, loc2.start);
});
_this.path = path21 !== null && path21 !== void 0 ? path21 : void 0;
var originalExtensions = originalError === null || originalError === void 0 ? void 0 : originalError.extensions;
if (extensions == null && isObjectLike(originalExtensions)) {
_this.extensions = _objectSpread({}, originalExtensions);
} else {
_this.extensions = extensions !== null && extensions !== void 0 ? extensions : {};
}
Object.defineProperties(_assertThisInitialized(_this), {
message: {
enumerable: true
},
locations: {
enumerable: _this.locations != null
},
path: {
enumerable: _this.path != null
},
extensions: {
enumerable: _this.extensions != null && Object.keys(_this.extensions).length > 0
},
name: {
enumerable: false
},
nodes: {
enumerable: false
},
source: {
enumerable: false
},
positions: {
enumerable: false
},
originalError: {
enumerable: false
}
});
if (originalError !== null && originalError !== void 0 && originalError.stack) {
Object.defineProperty(_assertThisInitialized(_this), "stack", {
value: originalError.stack,
writable: true,
configurable: true
});
return _possibleConstructorReturn(_this);
}
if (Error.captureStackTrace) {
Error.captureStackTrace(_assertThisInitialized(_this), GraphQLError4);
} else {
Object.defineProperty(_assertThisInitialized(_this), "stack", {
value: Error().stack,
writable: true,
configurable: true
});
}
return _this;
}
_createClass$1(GraphQLError4, [{
key: "toString",
value: function toString12() {
return printError(this);
}
}, {
key: SYMBOL_TO_STRING_TAG,
get: function get10() {
return "Object";
}
}]);
return GraphQLError4;
}(/* @__PURE__ */ _wrapNativeSuper(Error));
function undefinedIfEmpty(array) {
return array === void 0 || array.length === 0 ? void 0 : array;
}
function printError(error2) {
var output = error2.message;
if (error2.nodes) {
for (var _i4 = 0, _error$nodes2 = error2.nodes; _i4 < _error$nodes2.length; _i4++) {
var node = _error$nodes2[_i4];
if (node.loc) {
output += "\n\n" + printLocation(node.loc);
}
}
} else if (error2.source && error2.locations) {
for (var _i6 = 0, _error$locations2 = error2.locations; _i6 < _error$locations2.length; _i6++) {
var location2 = _error$locations2[_i6];
output += "\n\n" + printSourceLocation(error2.source, location2);
}
}
return output;
}
function syntaxError(source2, position, description) {
return new GraphQLError("Syntax Error: ".concat(description), void 0, source2, [position]);
}
var Kind = Object.freeze({
NAME: "Name",
DOCUMENT: "Document",
OPERATION_DEFINITION: "OperationDefinition",
VARIABLE_DEFINITION: "VariableDefinition",
SELECTION_SET: "SelectionSet",
FIELD: "Field",
ARGUMENT: "Argument",
FRAGMENT_SPREAD: "FragmentSpread",
INLINE_FRAGMENT: "InlineFragment",
FRAGMENT_DEFINITION: "FragmentDefinition",
VARIABLE: "Variable",
INT: "IntValue",
FLOAT: "FloatValue",
STRING: "StringValue",
BOOLEAN: "BooleanValue",
NULL: "NullValue",
ENUM: "EnumValue",
LIST: "ListValue",
OBJECT: "ObjectValue",
OBJECT_FIELD: "ObjectField",
DIRECTIVE: "Directive",
NAMED_TYPE: "NamedType",
LIST_TYPE: "ListType",
NON_NULL_TYPE: "NonNullType",
SCHEMA_DEFINITION: "SchemaDefinition",
OPERATION_TYPE_DEFINITION: "OperationTypeDefinition",
SCALAR_TYPE_DEFINITION: "ScalarTypeDefinition",
OBJECT_TYPE_DEFINITION: "ObjectTypeDefinition",
FIELD_DEFINITION: "FieldDefinition",
INPUT_VALUE_DEFINITION: "InputValueDefinition",
INTERFACE_TYPE_DEFINITION: "InterfaceTypeDefinition",
UNION_TYPE_DEFINITION: "UnionTypeDefinition",
ENUM_TYPE_DEFINITION: "EnumTypeDefinition",
ENUM_VALUE_DEFINITION: "EnumValueDefinition",
INPUT_OBJECT_TYPE_DEFINITION: "InputObjectTypeDefinition",
DIRECTIVE_DEFINITION: "DirectiveDefinition",
SCHEMA_EXTENSION: "SchemaExtension",
SCALAR_TYPE_EXTENSION: "ScalarTypeExtension",
OBJECT_TYPE_EXTENSION: "ObjectTypeExtension",
INTERFACE_TYPE_EXTENSION: "InterfaceTypeExtension",
UNION_TYPE_EXTENSION: "UnionTypeExtension",
ENUM_TYPE_EXTENSION: "EnumTypeExtension",
INPUT_OBJECT_TYPE_EXTENSION: "InputObjectTypeExtension"
});
function invariant(condition, message3) {
var booleanCondition = Boolean(condition);
if (!booleanCondition) {
throw new Error(message3 != null ? message3 : "Unexpected invariant triggered.");
}
}
var nodejsCustomInspectSymbol = typeof Symbol === "function" && typeof Symbol.for === "function" ? Symbol.for("nodejs.util.inspect.custom") : void 0;
var nodejsCustomInspectSymbol$1 = nodejsCustomInspectSymbol;
function defineInspect(classObject) {
var fn = classObject.prototype.toJSON;
typeof fn === "function" || invariant(0);
classObject.prototype.inspect = fn;
if (nodejsCustomInspectSymbol$1) {
classObject.prototype[nodejsCustomInspectSymbol$1] = fn;
}
}
var Location = /* @__PURE__ */ function() {
function Location2(startToken, endToken, source2) {
this.start = startToken.start;
this.end = endToken.end;
this.startToken = startToken;
this.endToken = endToken;
this.source = source2;
}
var _proto = Location2.prototype;
_proto.toJSON = function toJSON() {
return {
start: this.start,
end: this.end
};
};
return Location2;
}();
defineInspect(Location);
var Token = /* @__PURE__ */ function() {
function Token3(kind, start, end, line, column, prev, value) {
this.kind = kind;
this.start = start;
this.end = end;
this.line = line;
this.column = column;
this.value = value;
this.prev = prev;
this.next = null;
}
var _proto2 = Token3.prototype;
_proto2.toJSON = function toJSON() {
return {
kind: this.kind,
value: this.value,
line: this.line,
column: this.column
};
};
return Token3;
}();
defineInspect(Token);
var TokenKind = Object.freeze({
SOF: "<SOF>",
EOF: "<EOF>",
BANG: "!",
DOLLAR: "$",
AMP: "&",
PAREN_L: "(",
PAREN_R: ")",
SPREAD: "...",
COLON: ":",
EQUALS: "=",
AT: "@",
BRACKET_L: "[",
BRACKET_R: "]",
BRACE_L: "{",
PIPE: "|",
BRACE_R: "}",
NAME: "Name",
INT: "Int",
FLOAT: "Float",
STRING: "String",
BLOCK_STRING: "BlockString",
COMMENT: "Comment"
});
function _typeof$1(obj) {
"@babel/helpers - typeof";
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof$1 = function _typeof2(obj2) {
return typeof obj2;
};
} else {
_typeof$1 = function _typeof2(obj2) {
return obj2 && typeof Symbol === "function" && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
};
}
return _typeof$1(obj);
}
var MAX_ARRAY_LENGTH = 10;
var MAX_RECURSIVE_DEPTH = 2;
function inspect(value) {
return formatValue(value, []);
}
function formatValue(value, seenValues) {
switch (_typeof$1(value)) {
case "string":
return JSON.stringify(value);
case "function":
return value.name ? "[function ".concat(value.name, "]") : "[function]";
case "object":
if (value === null) {
return "null";
}
return formatObjectValue(value, seenValues);
default:
return String(value);
}
}
function formatObjectValue(value, previouslySeenValues) {
if (previouslySeenValues.indexOf(value) !== -1) {
return "[Circular]";
}
var seenValues = [].concat(previouslySeenValues, [value]);
var customInspectFn = getCustomFn(value);
if (customInspectFn !== void 0) {
var customValue = customInspectFn.call(value);
if (customValue !== value) {
return typeof customValue === "string" ? customValue : formatValue(customValue, seenValues);
}
} else if (Array.isArray(value)) {
return formatArray(value, seenValues);
}
return formatObject(value, seenValues);
}
function formatObject(object, seenValues) {
var keys = Object.keys(object);
if (keys.length === 0) {
return "{}";
}
if (seenValues.length > MAX_RECURSIVE_DEPTH) {
return "[" + getObjectTag(object) + "]";
}
var properties = keys.map(function(key) {
var value = formatValue(object[key], seenValues);
return key + ": " + value;
});
return "{ " + properties.join(", ") + " }";
}
function formatArray(array, seenValues) {
if (array.length === 0) {
return "[]";
}
if (seenValues.length > MAX_RECURSIVE_DEPTH) {
return "[Array]";
}
var len = Math.min(MAX_ARRAY_LENGTH, array.length);
var remaining = array.length - len;
var items = [];
for (var i = 0; i < len; ++i) {
items.push(formatValue(array[i], seenValues));
}
if (remaining === 1) {
items.push("... 1 more item");
} else if (remaining > 1) {
items.push("... ".concat(remaining, " more items"));
}
return "[" + items.join(", ") + "]";
}
function getCustomFn(object) {
var customInspectFn = object[String(nodejsCustomInspectSymbol$1)];
if (typeof customInspectFn === "function") {
return customInspectFn;
}
if (typeof object.inspect === "function") {
return object.inspect;
}
}
function getObjectTag(object) {
var tag = Object.prototype.toString.call(object).replace(/^\[object /, "").replace(/]$/, "");
if (tag === "Object" && typeof object.constructor === "function") {
var name11 = object.constructor.name;
if (typeof name11 === "string" && name11 !== "") {
return name11;
}
}
return tag;
}
function devAssert(condition, message3) {
var booleanCondition = Boolean(condition);
if (!booleanCondition) {
throw new Error(message3);
}
}
function _typeof(obj) {
"@babel/helpers - typeof";
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof = function _typeof2(obj2) {
return typeof obj2;
};
} else {
_typeof = function _typeof2(obj2) {
return obj2 && typeof Symbol === "function" && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
};
}
return _typeof(obj);
}
var instanceOf = process.env.NODE_ENV === "production" ? function instanceOf2(value, constructor) {
return value instanceof constructor;
} : function instanceOf2(value, constructor) {
if (value instanceof constructor) {
return true;
}
if (_typeof(value) === "object" && value !== null) {
var _value$constructor;
var className = constructor.prototype[Symbol.toStringTag];
var valueClassName = Symbol.toStringTag in value ? value[Symbol.toStringTag] : (_value$constructor = value.constructor) === null || _value$constructor === void 0 ? void 0 : _value$constructor.name;
if (className === valueClassName) {
var stringifiedValue = inspect(value);
throw new Error("Cannot use ".concat(className, ' "').concat(stringifiedValue, '" from another module or realm.\n\nEnsure that there is only one instance of "graphql" in the node_modules\ndirectory. If different versions of "graphql" are the dependencies of other\nrelied on modules, use "resolutions" to ensure only one version is installed.\n\nhttps://yarnpkg.com/en/docs/selective-version-resolutions\n\nDuplicate "graphql" modules cannot be used at the same time since different\nversions may have different capabilities and behavior. The data from one\nversion used in the function from another could produce confusing and\nspurious results.'));
}
}
return false;
};
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor)
descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps)
_defineProperties(Constructor.prototype, protoProps);
if (staticProps)
_defineProperties(Constructor, staticProps);
return Constructor;
}
var Source = /* @__PURE__ */ function() {
function Source3(body) {
var name11 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "GraphQL request";
var locationOffset = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {
line: 1,
column: 1
};
typeof body === "string" || devAssert(0, "Body must be a string. Received: ".concat(inspect(body), "."));
this.body = body;
this.name = name11;
this.locationOffset = locationOffset;
this.locationOffset.line > 0 || devAssert(0, "line in locationOffset is 1-indexed and must be positive.");
this.locationOffset.column > 0 || devAssert(0, "column in locationOffset is 1-indexed and must be positive.");
}
_createClass(Source3, [{
key: SYMBOL_TO_STRING_TAG,
get: function get10() {
return "Source";
}
}]);
return Source3;
}();
function isSource(source2) {
return instanceOf(source2, Source);
}
var DirectiveLocation = Object.freeze({
QUERY: "QUERY",
MUTATION: "MUTATION",
SUBSCRIPTION: "SUBSCRIPTION",
FIELD: "FIELD",
FRAGMENT_DEFINITION: "FRAGMENT_DEFINITION",
FRAGMENT_SPREAD: "FRAGMENT_SPREAD",
INLINE_FRAGMENT: "INLINE_FRAGMENT",
VARIABLE_DEFINITION: "VARIABLE_DEFINITION",
SCHEMA: "SCHEMA",
SCALAR: "SCALAR",
OBJECT: "OBJECT",
FIELD_DEFINITION: "FIELD_DEFINITION",
ARGUMENT_DEFINITION: "ARGUMENT_DEFINITION",
INTERFACE: "INTERFACE",
UNION: "UNION",
ENUM: "ENUM",
ENUM_VALUE: "ENUM_VALUE",
INPUT_OBJECT: "INPUT_OBJECT",
INPUT_FIELD_DEFINITION: "INPUT_FIELD_DEFINITION"
});
function dedentBlockStringValue(rawString) {
var lines = rawString.split(/\r\n|[\n\r]/g);
var commonIndent = getBlockStringIndentation(rawString);
if (commonIndent !== 0) {
for (var i = 1; i < lines.length; i++) {
lines[i] = lines[i].slice(commonIndent);
}
}
var startLine = 0;
while (startLine < lines.length && isBlank(lines[startLine])) {
++startLine;
}
var endLine = lines.length;
while (endLine > startLine && isBlank(lines[endLine - 1])) {
--endLine;
}
return lines.slice(startLine, endLine).join("\n");
}
function isBlank(str2) {
for (var i = 0; i < str2.length; ++i) {
if (str2[i] !== " " && str2[i] !== " ") {
return false;
}
}
return true;
}
function getBlockStringIndentation(value) {
var _commonIndent;
var isFirstLine = true;
var isEmptyLine = true;
var indent2 = 0;
var commonIndent = null;
for (var i = 0; i < value.length; ++i) {
switch (value.charCodeAt(i)) {
case 13:
if (value.charCodeAt(i + 1) === 10) {
++i;
}
case 10:
isFirstLine = false;
isEmptyLine = true;
indent2 = 0;
break;
case 9:
case 32:
++indent2;
break;
default:
if (isEmptyLine && !isFirstLine && (commonIndent === null || indent2 < commonIndent)) {
commonIndent = indent2;
}
isEmptyLine = false;
}
}
return (_commonIndent = commonIndent) !== null && _commonIndent !== void 0 ? _commonIndent : 0;
}
var Lexer = /* @__PURE__ */ function() {
function Lexer2(source2) {
var startOfFileToken = new Token(TokenKind.SOF, 0, 0, 0, 0, null);
this.source = source2;
this.lastToken = startOfFileToken;
this.token = startOfFileToken;
this.line = 1;
this.lineStart = 0;
}
var _proto = Lexer2.prototype;
_proto.advance = function advance() {
this.lastToken = this.token;
var token = this.token = this.lookahead();
return token;
};
_proto.lookahead = function lookahead() {
var token = this.token;
if (token.kind !== TokenKind.EOF) {
do {
var _token$next;
token = (_token$next = token.next) !== null && _token$next !== void 0 ? _token$next : token.next = readToken(this, token);
} while (token.kind === TokenKind.COMMENT);
}
return token;
};
return Lexer2;
}();
function isPunctuatorTokenKind(kind) {
return kind === TokenKind.BANG || kind === TokenKind.DOLLAR || kind === TokenKind.AMP || kind === TokenKind.PAREN_L || kind === TokenKind.PAREN_R || kind === TokenKind.SPREAD || kind === TokenKind.COLON || kind === TokenKind.EQUALS || kind === TokenKind.AT || kind === TokenKind.BRACKET_L || kind === TokenKind.BRACKET_R || kind === TokenKind.BRACE_L || kind === TokenKind.PIPE || kind === TokenKind.BRACE_R;
}
function printCharCode(code10) {
return isNaN(code10) ? TokenKind.EOF : code10 < 127 ? JSON.stringify(String.fromCharCode(code10)) : '"\\u'.concat(("00" + code10.toString(16).toUpperCase()).slice(-4), '"');
}
function readToken(lexer, prev) {
var source2 = lexer.source;
var body = source2.body;
var bodyLength = body.length;
var pos = prev.end;
while (pos < bodyLength) {
var code10 = body.charCodeAt(pos);
var _line = lexer.line;
var _col = 1 + pos - lexer.lineStart;
switch (code10) {
case 65279:
case 9:
case 32:
case 44:
++pos;
continue;
case 10:
++pos;
++lexer.line;
lexer.lineStart = pos;
continue;
case 13:
if (body.charCodeAt(pos + 1) === 10) {
pos += 2;
} else {
++pos;
}
++lexer.line;
lexer.lineStart = pos;
continue;
case 33:
return new Token(TokenKind.BANG, pos, pos + 1, _line, _col, prev);
case 35:
return readComment(source2, pos, _line, _col, prev);
case 36:
return new Token(TokenKind.DOLLAR, pos, pos + 1, _line, _col, prev);
case 38:
return new Token(TokenKind.AMP, pos, pos + 1, _line, _col, prev);
case 40:
return new Token(TokenKind.PAREN_L, pos, pos + 1, _line, _col, prev);
case 41:
return new Token(TokenKind.PAREN_R, pos, pos + 1, _line, _col, prev);
case 46:
if (body.charCodeAt(pos + 1) === 46 && body.charCodeAt(pos + 2) === 46) {
return new Token(TokenKind.SPREAD, pos, pos + 3, _line, _col, prev);
}
break;
case 58:
return new Token(TokenKind.COLON, pos, pos + 1, _line, _col, prev);
case 61:
return new Token(TokenKind.EQUALS, pos, pos + 1, _line, _col, prev);
case 64:
return new Token(TokenKind.AT, pos, pos + 1, _line, _col, prev);
case 91:
return new Token(TokenKind.BRACKET_L, pos, pos + 1, _line, _col, prev);
case 93:
return new Token(TokenKind.BRACKET_R, pos, pos + 1, _line, _col, prev);
case 123:
return new Token(TokenKind.BRACE_L, pos, pos + 1, _line, _col, prev);
case 124:
return new Token(TokenKind.PIPE, pos, pos + 1, _line, _col, prev);
case 125:
return new Token(TokenKind.BRACE_R, pos, pos + 1, _line, _col, prev);
case 34:
if (body.charCodeAt(pos + 1) === 34 && body.charCodeAt(pos + 2) === 34) {
return readBlockString(source2, pos, _line, _col, prev, lexer);
}
return readString(source2, pos, _line, _col, prev);
case 45:
case 48:
case 49:
case 50:
case 51:
case 52:
case 53:
case 54:
case 55:
case 56:
case 57:
return readNumber(source2, pos, code10, _line, _col, prev);
case 65:
case 66:
case 67:
case 68:
case 69:
case 70:
case 71:
case 72:
case 73:
case 74:
case 75:
case 76:
case 77:
case 78:
case 79:
case 80:
case 81:
case 82:
case 83:
case 84:
case 85:
case 86:
case 87:
case 88:
case 89:
case 90:
case 95:
case 97:
case 98:
case 99:
case 100:
case 101:
case 102:
case 103:
case 104:
case 105:
case 106:
case 107:
case 108:
case 109:
case 110:
case 111:
case 112:
case 113:
case 114:
case 115:
case 116:
case 117:
case 118:
case 119:
case 120:
case 121:
case 122:
return readName(source2, pos, _line, _col, prev);
}
throw syntaxError(source2, pos, unexpectedCharacterMessage(code10));
}
var line = lexer.line;
var col = 1 + pos - lexer.lineStart;
return new Token(TokenKind.EOF, bodyLength, bodyLength, line, col, prev);
}
function unexpectedCharacterMessage(code10) {
if (code10 < 32 && code10 !== 9 && code10 !== 10 && code10 !== 13) {
return "Cannot contain the invalid character ".concat(printCharCode(code10), ".");
}
if (code10 === 39) {
return `Unexpected single quote character ('), did you mean to use a double quote (")?`;
}
return "Cannot parse the unexpected character ".concat(printCharCode(code10), ".");
}
function readComment(source2, start, line, col, prev) {
var body = source2.body;
var code10;
var position = start;
do {
code10 = body.charCodeAt(++position);
} while (!isNaN(code10) && (code10 > 31 || code10 === 9));
return new Token(TokenKind.COMMENT, start, position, line, col, prev, body.slice(start + 1, position));
}
function readNumber(source2, start, firstCode, line, col, prev) {
var body = source2.body;
var code10 = firstCode;
var position = start;
var isFloat2 = false;
if (code10 === 45) {
code10 = body.charCodeAt(++position);
}
if (code10 === 48) {
code10 = body.charCodeAt(++position);
if (code10 >= 48 && code10 <= 57) {
throw syntaxError(source2, position, "Invalid number, unexpected digit after 0: ".concat(printCharCode(code10), "."));
}
} else {
position = readDigits(source2, position, code10);
code10 = body.charCodeAt(position);
}
if (code10 === 46) {
isFloat2 = true;
code10 = body.charCodeAt(++position);
position = readDigits(source2, position, code10);
code10 = body.charCodeAt(position);
}
if (code10 === 69 || code10 === 101) {
isFloat2 = true;
code10 = body.charCodeAt(++position);
if (code10 === 43 || code10 === 45) {
code10 = body.charCodeAt(++position);
}
position = readDigits(source2, position, code10);
code10 = body.charCodeAt(position);
}
if (code10 === 46 || isNameStart(code10)) {
throw syntaxError(source2, position, "Invalid number, expected digit but got: ".concat(printCharCode(code10), "."));
}
return new Token(isFloat2 ? TokenKind.FLOAT : TokenKind.INT, start, position, line, col, prev, body.slice(start, position));
}
function readDigits(source2, start, firstCode) {
var body = source2.body;
var position = start;
var code10 = firstCode;
if (code10 >= 48 && code10 <= 57) {
do {
code10 = body.charCodeAt(++position);
} while (code10 >= 48 && code10 <= 57);
return position;
}
throw syntaxError(source2, position, "Invalid number, expected digit but got: ".concat(printCharCode(code10), "."));
}
function readString(source2, start, line, col, prev) {
var body = source2.body;
var position = start + 1;
var chunkStart = position;
var code10 = 0;
var value = "";
while (position < body.length && !isNaN(code10 = body.charCodeAt(position)) && code10 !== 10 && code10 !== 13) {
if (code10 === 34) {
value += body.slice(chunkStart, position);
return new Token(TokenKind.STRING, start, position + 1, line, col, prev, value);
}
if (code10 < 32 && code10 !== 9) {
throw syntaxError(source2, position, "Invalid character within String: ".concat(printCharCode(code10), "."));
}
++position;
if (code10 === 92) {
value += body.slice(chunkStart, position - 1);
code10 = body.charCodeAt(position);
switch (code10) {
case 34:
value += '"';
break;
case 47:
value += "/";
break;
case 92:
value += "\\";
break;
case 98:
value += "\b";
break;
case 102:
value += "\f";
break;
case 110:
value += "\n";
break;
case 114:
value += "\r";
break;
case 116:
value += " ";
break;
case 117: {
var charCode = uniCharCode(body.charCodeAt(position + 1), body.charCodeAt(position + 2), body.charCodeAt(position + 3), body.charCodeAt(position + 4));
if (charCode < 0) {
var invalidSequence = body.slice(position + 1, position + 5);
throw syntaxError(source2, position, "Invalid character escape sequence: \\u".concat(invalidSequence, "."));
}
value += String.fromCharCode(charCode);
position += 4;
break;
}
default:
throw syntaxError(source2, position, "Invalid character escape sequence: \\".concat(String.fromCharCode(code10), "."));
}
++position;
chunkStart = position;
}
}
throw syntaxError(source2, position, "Unterminated string.");
}
function readBlockString(source2, start, line, col, prev, lexer) {
var body = source2.body;
var position = start + 3;
var chunkStart = position;
var code10 = 0;
var rawValue = "";
while (position < body.length && !isNaN(code10 = body.charCodeAt(position))) {
if (code10 === 34 && body.charCodeAt(position + 1) === 34 && body.charCodeAt(position + 2) === 34) {
rawValue += body.slice(chunkStart, position);
return new Token(TokenKind.BLOCK_STRING, start, position + 3, line, col, prev, dedentBlockStringValue(rawValue));
}
if (code10 < 32 && code10 !== 9 && code10 !== 10 && code10 !== 13) {
throw syntaxError(source2, position, "Invalid character within String: ".concat(printCharCode(code10), "."));
}
if (code10 === 10) {
++position;
++lexer.line;
lexer.lineStart = position;
} else if (code10 === 13) {
if (body.charCodeAt(position + 1) === 10) {
position += 2;
} else {
++position;
}
++lexer.line;
lexer.lineStart = position;
} else if (code10 === 92 && body.charCodeAt(position + 1) === 34 && body.charCodeAt(position + 2) === 34 && body.charCodeAt(position + 3) === 34) {
rawValue += body.slice(chunkStart, position) + '"""';
position += 4;
chunkStart = position;
} else {
++position;
}
}
throw syntaxError(source2, position, "Unterminated string.");
}
function uniCharCode(a, b, c, d) {
return char2hex(a) << 12 | char2hex(b) << 8 | char2hex(c) << 4 | char2hex(d);
}
function char2hex(a) {
return a >= 48 && a <= 57 ? a - 48 : a >= 65 && a <= 70 ? a - 55 : a >= 97 && a <= 102 ? a - 87 : -1;
}
function readName(source2, start, line, col, prev) {
var body = source2.body;
var bodyLength = body.length;
var position = start + 1;
var code10 = 0;
while (position !== bodyLength && !isNaN(code10 = body.charCodeAt(position)) && (code10 === 95 || code10 >= 48 && code10 <= 57 || code10 >= 65 && code10 <= 90 || code10 >= 97 && code10 <= 122)) {
++position;
}
return new Token(TokenKind.NAME, start, position, line, col, prev, body.slice(start, position));
}
function isNameStart(code10) {
return code10 === 95 || code10 >= 65 && code10 <= 90 || code10 >= 97 && code10 <= 122;
}
function parse(source2, options) {
var parser3 = new Parser(source2, options);
return parser3.parseDocument();
}
var Parser = /* @__PURE__ */ function() {
function Parser4(source2, options) {
var sourceObj = isSource(source2) ? source2 : new Source(source2);
this._lexer = new Lexer(sourceObj);
this._options = options;
}
var _proto = Parser4.prototype;
_proto.parseName = function parseName() {
var token = this.expectToken(TokenKind.NAME);
return {
kind: Kind.NAME,
value: token.value,
loc: this.loc(token)
};
};
_proto.parseDocument = function parseDocument2() {
var start = this._lexer.token;
return {
kind: Kind.DOCUMENT,
definitions: this.many(TokenKind.SOF, this.parseDefinition, TokenKind.EOF),
loc: this.loc(start)
};
};
_proto.parseDefinition = function parseDefinition() {
if (this.peek(TokenKind.NAME)) {
switch (this._lexer.token.value) {
case "query":
case "mutation":
case "subscription":
return this.parseOperationDefinition();
case "fragment":
return this.parseFragmentDefinition();
case "schema":
case "scalar":
case "type":
case "interface":
case "union":
case "enum":
case "input":
case "directive":
return this.parseTypeSystemDefinition();
case "extend":
return this.parseTypeSystemExtension();
}
} else if (this.peek(TokenKind.BRACE_L)) {
return this.parseOperationDefinition();
} else if (this.peekDescription()) {
return this.parseTypeSystemDefinition();
}
throw this.unexpected();
};
_proto.parseOperationDefinition = function parseOperationDefinition() {
var start = this._lexer.token;
if (this.peek(TokenKind.BRACE_L)) {
return {
kind: Kind.OPERATION_DEFINITION,
operation: "query",
name: void 0,
variableDefinitions: [],
directives: [],
selectionSet: this.parseSelectionSet(),
loc: this.loc(start)
};
}
var operation = this.parseOperationType();
var name11;
if (this.peek(TokenKind.NAME)) {
name11 = this.parseName();
}
return {
kind: Kind.OPERATION_DEFINITION,
operation,
name: name11,
variableDefinitions: this.parseVariableDefinitions(),
directives: this.parseDirectives(false),
selectionSet: this.parseSelectionSet(),
loc: this.loc(start)
};
};
_proto.parseOperationType = function parseOperationType() {
var operationToken = this.expectToken(TokenKind.NAME);
switch (operationToken.value) {
case "query":
return "query";
case "mutation":
return "mutation";
case "subscription":
return "subscription";
}
throw this.unexpected(operationToken);
};
_proto.parseVariableDefinitions = function parseVariableDefinitions() {
return this.optionalMany(TokenKind.PAREN_L, this.parseVariableDefinition, TokenKind.PAREN_R);
};
_proto.parseVariableDefinition = function parseVariableDefinition() {
var start = this._lexer.token;
return {
kind: Kind.VARIABLE_DEFINITION,
variable: this.parseVariable(),
type: (this.expectToken(TokenKind.COLON), this.parseTypeReference()),
defaultValue: this.expectOptionalToken(TokenKind.EQUALS) ? this.parseValueLiteral(true) : void 0,
directives: this.parseDirectives(true),
loc: this.loc(start)
};
};
_proto.parseVariable = function parseVariable() {
var start = this._lexer.token;
this.expectToken(TokenKind.DOLLAR);
return {
kind: Kind.VARIABLE,
name: this.parseName(),
loc: this.loc(start)
};
};
_proto.parseSelectionSet = function parseSelectionSet() {
var start = this._lexer.token;
return {
kind: Kind.SELECTION_SET,
selections: this.many(TokenKind.BRACE_L, this.parseSelection, TokenKind.BRACE_R),
loc: this.loc(start)
};
};
_proto.parseSelection = function parseSelection() {
return this.peek(TokenKind.SPREAD) ? this.parseFragment() : this.parseField();
};
_proto.parseField = function parseField() {
var start = this._lexer.token;
var nameOrAlias = this.parseName();
var alias;
var name11;
if (this.expectOptionalToken(TokenKind.COLON)) {
alias = nameOrAlias;
name11 = this.parseName();
} else {
name11 = nameOrAlias;
}
return {
kind: Kind.FIELD,
alias,
name: name11,
arguments: this.parseArguments(false),
directives: this.parseDirectives(false),
selectionSet: this.peek(TokenKind.BRACE_L) ? this.parseSelectionSet() : void 0,
loc: this.loc(start)
};
};
_proto.parseArguments = function parseArguments(isConst) {
var item = isConst ? this.parseConstArgument : this.parseArgument;
return this.optionalMany(TokenKind.PAREN_L, item, TokenKind.PAREN_R);
};
_proto.parseArgument = function parseArgument() {
var start = this._lexer.token;