kdx
Version:
kintone CLI for development & deployment, with Developer Experience
1,874 lines (1,550 loc) • 976 kB
JavaScript
#!/usr/bin/env node
// modules are defined as an array
// [ module function, map of requires ]
//
// map of requires is short require name -> numeric require
//
// anything defined in a previous bundle is accessed via the
// orig method which is the require for previous bundles
parcelRequire = (function (modules, cache, entry, globalName) {
// Save the require from previous bundle to this closure if any
var previousRequire = typeof parcelRequire === 'function' && parcelRequire;
var nodeRequire = typeof require === 'function' && require;
function newRequire(name, jumped) {
if (!cache[name]) {
if (!modules[name]) {
// if we cannot find the module within our internal map or
// cache jump to the current global require ie. the last bundle
// that was added to the page.
var currentRequire = typeof parcelRequire === 'function' && parcelRequire;
if (!jumped && currentRequire) {
return currentRequire(name, true);
}
// If there are other bundles on this page the require from the
// previous one is saved to 'previousRequire'. Repeat this as
// many times as there are bundles until the module is found or
// we exhaust the require chain.
if (previousRequire) {
return previousRequire(name, true);
}
// Try the node require function if it exists.
if (nodeRequire && typeof name === 'string') {
return nodeRequire(name);
}
var err = new Error('Cannot find module \'' + name + '\'');
err.code = 'MODULE_NOT_FOUND';
throw err;
}
localRequire.resolve = resolve;
localRequire.cache = {};
var module = cache[name] = new newRequire.Module(name);
modules[name][0].call(module.exports, localRequire, module, module.exports, this);
}
return cache[name].exports;
function localRequire(x){
return newRequire(localRequire.resolve(x));
}
function resolve(x){
return modules[name][1][x] || x;
}
}
function Module(moduleName) {
this.id = moduleName;
this.bundle = newRequire;
this.exports = {};
}
newRequire.isParcelRequire = true;
newRequire.Module = Module;
newRequire.modules = modules;
newRequire.cache = cache;
newRequire.parent = previousRequire;
newRequire.register = function (id, exports) {
modules[id] = [function (require, module) {
module.exports = exports;
}, {}];
};
var error;
for (var i = 0; i < entry.length; i++) {
try {
newRequire(entry[i]);
} catch (e) {
// Save first error but execute all entries
if (!error) {
error = e;
}
}
}
if (entry.length) {
// Expose entry point to Node, AMD or browser globals
// Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
var mainExports = newRequire(entry[entry.length - 1]);
// CommonJS
if (typeof exports === "object" && typeof module !== "undefined") {
module.exports = mainExports;
// RequireJS
} else if (typeof define === "function" && define.amd) {
define(function () {
return mainExports;
});
// <script>
} else if (globalName) {
this[globalName] = mainExports;
}
}
// Override the current require with this new one
parcelRequire = newRequire;
if (error) {
// throw error from earlier, _after updating parcelRequire_
throw error;
}
return newRequire;
})({"YF8F":[function(require,module,exports) {
/*::
type DotenvParseOptions = {
debug?: boolean
}
// keys and values from src
type DotenvParseOutput = { [string]: string }
type DotenvConfigOptions = {
path?: string, // path to .env file
encoding?: string, // encoding of .env file
debug?: string // turn on logging for debugging purposes
}
type DotenvConfigOutput = {
parsed?: DotenvParseOutput,
error?: Error
}
*/
const fs = require('fs');
const path = require('path');
function log(message
/*: string */
) {
console.log(`[dotenv][DEBUG] ${message}`);
}
const NEWLINE = '\n';
const RE_INI_KEY_VAL = /^\s*([\w.-]+)\s*=\s*(.*)?\s*$/;
const RE_NEWLINES = /\\n/g;
const NEWLINES_MATCH = /\n|\r|\r\n/; // Parses src into an Object
function parse(src
/*: string | Buffer */
, options
/*: ?DotenvParseOptions */
)
/*: DotenvParseOutput */
{
const debug = Boolean(options && options.debug);
const obj = {}; // convert Buffers before splitting into lines and processing
src.toString().split(NEWLINES_MATCH).forEach(function (line, idx) {
// matching "KEY' and 'VAL' in 'KEY=VAL'
const keyValueArr = line.match(RE_INI_KEY_VAL); // matched?
if (keyValueArr != null) {
const key = keyValueArr[1]; // default undefined or missing values to empty string
let val = keyValueArr[2] || '';
const end = val.length - 1;
const isDoubleQuoted = val[0] === '"' && val[end] === '"';
const isSingleQuoted = val[0] === "'" && val[end] === "'"; // if single or double quoted, remove quotes
if (isSingleQuoted || isDoubleQuoted) {
val = val.substring(1, end); // if double quoted, expand newlines
if (isDoubleQuoted) {
val = val.replace(RE_NEWLINES, NEWLINE);
}
} else {
// remove surrounding whitespace
val = val.trim();
}
obj[key] = val;
} else if (debug) {
log(`did not match key and value when parsing line ${idx + 1}: ${line}`);
}
});
return obj;
} // Populates process.env from .env file
function config(options
/*: ?DotenvConfigOptions */
)
/*: DotenvConfigOutput */
{
let dotenvPath = path.resolve(process.cwd(), '.env');
let encoding
/*: string */
= 'utf8';
let debug = false;
if (options) {
if (options.path != null) {
dotenvPath = options.path;
}
if (options.encoding != null) {
encoding = options.encoding;
}
if (options.debug != null) {
debug = true;
}
}
try {
// specifying an encoding returns a string instead of a buffer
const parsed = parse(fs.readFileSync(dotenvPath, {
encoding
}), {
debug
});
Object.keys(parsed).forEach(function (key) {
if (!Object.prototype.hasOwnProperty.call(process.env, key)) {
process.env[key] = parsed[key];
} else if (debug) {
log(`"${key}" is already defined in \`process.env\` and will not be overwritten`);
}
});
return {
parsed
};
} catch (e) {
return {
error: e
};
}
}
module.exports.config = config;
module.exports.parse = parse;
},{}],"qf2u":[function(require,module,exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isUnsafeVarNames = isUnsafeVarNames;
exports.nvl = nvl;
exports.nvl2 = nvl2;
exports.dummyTargetObject = exports.DateTimeNoTzPattern = exports.DateTimePattern = exports.DatePattern = exports.NumberPattern = exports.SymbolPattern = void 0;
// Copyright (c) 2020 Shellyl_N and Authors
// license: ISC
// https://github.com/shellyln
// tslint:disable-next-line:function-constructor
const globalObj = Function('return this')();
const objConstructor = {}.constructor; // NOTE: objConstructor === Object
const funConstructor = Function; // NOTE: ({}).toString.constructor === Function
const SymbolPattern = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
exports.SymbolPattern = SymbolPattern;
const NumberPattern = /^([\+\-]?\d*\.?\d+(?:[Ee][\+\-]?\d+)?)$/;
exports.NumberPattern = NumberPattern;
const DatePattern = /^(\d{4}-[01]\d-[0-3]\d)$/;
exports.DatePattern = DatePattern;
const DateTimePattern = /^((?:(?:\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+)|(?:\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d)|(?:\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d))(?:[+-][0-2]\d:[0-5]\d|Z))$/;
exports.DateTimePattern = DateTimePattern;
const DateTimeNoTzPattern = /^((?:\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+)|(?:\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d)|(?:\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d))$/;
exports.DateTimeNoTzPattern = DateTimeNoTzPattern;
const dummyTargetObject = {};
exports.dummyTargetObject = dummyTargetObject;
function isUnsafeVarNames(target, varName) {
if (target === globalObj || varName === '__proto__' || varName === '__defineGetter__' || varName === '__defineSetter__' || varName === '__lookupGetter__' || varName === '__lookupSetter__') {
return true;
}
if (varName === 'prototype' || varName === 'constructor') {
if (target === null || target === void 0 || typeof target === 'function') {
return true;
}
}
if (target === null || target === void 0 || target === objConstructor) {
if (objConstructor.hasOwnProperty(varName)) {
return true;
}
}
if (target === null || target === void 0 || target === funConstructor) {
// checking 'call', 'arguments', 'caller', ...
let con = funConstructor;
while (con) {
if (con.hasOwnProperty(varName)) {
return true;
}
con = con.__proto__;
}
}
if (typeof target === 'function') {
if (!target.hasOwnProperty(varName)) {
// function's prototypes' members
return true;
}
}
return false;
}
function nvl(v, alt) {
return v !== null && v !== void 0 ? v : alt;
}
function nvl2(v, f, alt) {
return v !== null && v !== void 0 ? f(v) : alt;
}
},{}],"ZikL":[function(require,module,exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.picked = picked;
exports.omit = omit;
exports.partial = partial;
exports.intersect = intersect;
exports.oneOf = oneOf;
exports.subtract = subtract;
exports.primitive = primitive;
exports.regexpPatternStringType = regexpPatternStringType;
exports.primitiveValue = primitiveValue;
exports.optional = optional;
exports.repeated = repeated;
exports.sequenceOf = sequenceOf;
exports.spread = spread;
exports.enumType = enumType;
exports.objectType = objectType;
exports.derived = derived;
exports.symlinkType = symlinkType;
exports.withName = withName;
exports.withTypeName = withTypeName;
exports.withOriginalTypeName = withOriginalTypeName;
exports.withDocComment = withDocComment;
exports.withRange = withRange;
exports.withMinValue = withMinValue;
exports.withMaxValue = withMaxValue;
exports.withGreaterThan = withGreaterThan;
exports.withLessThan = withLessThan;
exports.withMinLength = withMinLength;
exports.withMaxLength = withMaxLength;
exports.withMatch = withMatch;
exports.withStereotype = withStereotype;
exports.withConstraint = withConstraint;
exports.withForceCast = withForceCast;
exports.withRecordType = withRecordType;
exports.withMeta = withMeta;
exports.withMsg = withMsg;
exports.withMsgId = withMsgId;
var _util = require("./lib/util");
// Copyright (c) 2019 Shellyl_N and Authors
// license: ISC
// https://github.com/shellyln
// emulate Pick<T> // ex. Pick<Foo, 'a' | 'b'>
function picked(ty, ...names) {
switch (ty.kind) {
case 'object':
{
const members = [];
for (const name of names) {
const member = ty.members.find(x => x[0] === name);
if (member) {
if (member[2]) {
const m2 = [...member];
if (3 < m2.length) {
m2[2] = false;
} else {
m2.length = 2;
}
members.push(m2);
} else {
members.push(member);
}
}
}
return {
kind: 'object',
members
};
}
case 'symlink':
case 'operator':
{
return {
kind: 'operator',
operator: 'picked',
operands: [ty, ...names]
};
}
default:
return {
kind: 'object',
members: []
};
}
} // emulate Omit<T> // ex. Omit<Foo, 'a' | 'b'>
function omit(ty, ...names) {
switch (ty.kind) {
case 'object':
{
const members = [];
for (const member of ty.members) {
if (!names.find(name => member[0] === name)) {
if (member[2]) {
const m2 = [...member];
if (3 < m2.length) {
m2[2] = false;
} else {
m2.length = 2;
}
members.push(m2);
} else {
members.push(member);
}
}
}
return {
kind: 'object',
members
};
}
case 'symlink':
case 'operator':
{
return {
kind: 'operator',
operator: 'omit',
operands: [ty, ...names]
};
}
default:
return {
kind: 'object',
members: []
};
}
} // emulate Partial<T>
function partial(ty) {
switch (ty.kind) {
case 'object':
{
const members = [];
for (const member of ty.members) {
let m = member[1].kind === 'optional' ? member : [member[0], optional(member[1]), ...member.slice(2)];
if (m[2]) {
m = [...m];
if (3 < m.length) {
m[2] = false;
} else {
m.length = 2;
}
}
m[1].name = m[0];
const optTy = Object.assign({}, m[1].optional);
m[1].optional = optTy;
if (optTy.name && optTy.name !== optTy.typeName) {
delete optTy.name;
}
if (!optTy.name && optTy.typeName) {
optTy.name = optTy.typeName;
}
members.push(m);
}
return {
kind: 'object',
members
};
}
case 'symlink':
case 'operator':
{
return {
kind: 'operator',
operator: 'partial',
operands: [ty]
};
}
default:
return ty;
}
} // intersection (a & b)
function intersect(...types) {
if (types.length === 0) {
throw new Error(`Empty intersection type is not allowed.`);
}
if (0 < types.filter(x => x && typeof x === 'object' && (x.kind === 'symlink' || x.kind === 'operator')).length) {
return {
kind: 'operator',
operator: 'intersect',
operands: types.slice()
};
}
let lastTy = null;
const members = new Map();
for (const ty of types) {
if (ty && typeof ty === 'object') {
if (lastTy && lastTy.kind !== ty.kind) {
return {
kind: 'never'
};
}
lastTy = ty;
if (ty.kind === 'object') {
for (const m of ty.members) {
if (m[2]) {
const m2 = [...m];
if (3 < m2.length) {
m2[2] = false;
} else {
m2.length = 2;
}
members.set(m[0], m2); // Overwrite if exists
} else {
members.set(m[0], m); // Overwrite if exists
}
}
}
} else {
return {
kind: 'never'
};
}
}
if (lastTy && lastTy.kind !== 'object') {
return lastTy;
} else {
return {
kind: 'object',
members: Array.from(members.values())
};
}
} // union (a | b)
function oneOf(...types) {
if (types.length === 0) {
throw new Error(`Empty union type is not allowed.`);
}
if (types.length === 1) {
const ty = types[0];
if (ty && typeof ty === 'object') {
return ty;
} else {
return primitiveValue(ty);
}
}
const ret = {
kind: 'one-of',
oneOf: []
};
for (const ty of types) {
// TODO: remove same type
if (ty && typeof ty === 'object') {
if (ty.kind === 'one-of') {
ret.oneOf = ret.oneOf.concat(ty.oneOf);
} else {
ret.oneOf.push(ty);
}
} else {
ret.oneOf.push(primitiveValue(ty));
}
}
return ret;
} // subtraction (a - b)
function subtract(...types) {
if (types.length === 0) {
throw new Error(`Empty subtraction type is not allowed.`);
}
if (0 < types.filter(x => x && typeof x === 'object' && (x.kind === 'symlink' || x.kind === 'operator')).length) {
return {
kind: 'operator',
operator: 'subtract',
operands: types.slice()
};
}
let ret = types[0];
if (!ret || typeof ret !== 'object' || ret.kind !== 'object') {
throw new Error(`First parameter of subtraction type should be 'object'.`);
}
for (const ty of types.slice(1)) {
if (ty && typeof ty === 'object' && ty.kind === 'object') {
ret = omit(ret, ...ty.members.map(m => m[0]));
}
}
return ret;
}
function primitive(typeName) {
switch (typeName) {
case 'never':
return {
kind: 'never'
};
case 'any':
return {
kind: 'any'
};
case 'unknown':
return {
kind: 'unknown'
};
case 'number': // FALL_THRU
case 'integer': // FALL_THRU
case 'bigint': // FALL_THRU
case 'string': // FALL_THRU
case 'boolean': // FALL_THRU
case 'null': // FALL_THRU
case 'undefined':
return {
kind: 'primitive',
primitiveName: typeName
};
case 'never?':
return optional({
kind: 'never'
});
case 'any?':
return optional({
kind: 'any'
});
case 'unknown?':
return optional({
kind: 'unknown'
});
case 'number?': // FALL_THRU
case 'integer?': // FALL_THRU
case 'bigint?': // FALL_THRU
case 'string?': // FALL_THRU
case 'boolean?': // FALL_THRU
case 'null?': // FALL_THRU
case 'undefined?':
return optional({
kind: 'primitive',
primitiveName: typeName.substring(0, typeName.length - 1)
});
default:
throw new Error(`Unknown primitive type assertion: ${typeName}`);
} // TODO: Function, DateStr, DateTimeStr, Funtion?, DateStr?, DateTimeStr?
}
function regexpPatternStringType(pattern) {
return {
kind: 'primitive',
primitiveName: 'string',
pattern
};
}
function primitiveValue(value) {
if (value === null || value === void 0) {
return {
kind: 'primitive-value',
value
};
} else switch (typeof value) {
case 'number': // FALL_THRU
case 'bigint': // FALL_THRU
case 'string': // FALL_THRU
case 'boolean':
return {
kind: 'primitive-value',
value
};
default:
throw new Error(`Unknown primitive value assertion: ${value}`);
}
}
function optional(ty) {
if (ty && typeof ty === 'object' && ty.kind) {
if (ty.kind === 'optional') {
return ty;
} else {
return Object.assign({
kind: 'optional',
optional: ty
}, ty.typeName ? {
typeName: ty.typeName
} : {});
}
} else {
return {
kind: 'optional',
optional: primitiveValue(ty)
};
}
}
function repeated(ty, option) {
if (ty && typeof ty === 'object' && ty.kind) {
return {
kind: 'repeated',
min: option && typeof option.min === 'number' ? option.min : null,
max: option && typeof option.max === 'number' ? option.max : null,
repeated: ty
};
} else {
return {
kind: 'repeated',
min: option && typeof option.min === 'number' ? option.min : null,
max: option && typeof option.max === 'number' ? option.max : null,
repeated: primitive(ty)
};
}
}
function sequenceOf(...seq) {
return {
kind: 'sequence',
sequence: seq.map(ty => ty && typeof ty === 'object' && ty.kind ? ty : primitiveValue(ty))
};
}
function spread(ty, option) {
if (ty && typeof ty === 'object' && ty.kind) {
return {
kind: 'spread',
min: option && typeof option.min === 'number' ? option.min : null,
max: option && typeof option.max === 'number' ? option.max : null,
spread: ty
};
} else {
return {
kind: 'spread',
min: option && typeof option.min === 'number' ? option.min : null,
max: option && typeof option.max === 'number' ? option.max : null,
spread: primitiveValue(ty)
};
}
}
function enumType(...values) {
const ar = values.slice();
let value = 0;
for (let i = 0; i < ar.length; i++) {
if ((0, _util.isUnsafeVarNames)(_util.dummyTargetObject, ar[i][0])) {
throw new Error(`Unsafe symbol name is appeared in enum assertion: ${ar[i][0]}`);
}
if (ar[i][1] === null || ar[i][1] === void 0) {
ar[i][1] = value++;
} else if (typeof ar[i][1] === 'number') {
value = ar[i][1] + 1;
}
if (!ar[i][2]) {
ar[i].length = 2;
}
}
return {
kind: 'enum',
values: ar
};
}
function objectType(...members) {
const revMembers = members.slice().reverse();
for (const x of members) {
if (typeof x[0] === 'string') {
if ((0, _util.isUnsafeVarNames)(_util.dummyTargetObject, x[0])) {
throw new Error(`Unsafe symbol name is appeared in object assertion: ${x[0]}`);
}
if (members.find(m => m[0] === x[0]) !== revMembers.find(m => m[0] === x[0])) {
throw new Error(`Duplicated member is found: ${x[0]}`);
}
}
}
const membersProps = members.filter(x => typeof x[0] === 'string').map(x => x[1] && typeof x[1] === 'object' && x[1].kind ? [x[0], withName(x[1], x[0]), x[2]] : [x[0], withName(primitiveValue(x[1]), x[0]), x[2]]).map(x => x[2] ? [x[0], x[1], false, ...x.slice(2)] : [x[0], x[1]]);
const additionalProps = members.filter(x => typeof x[0] !== 'string').map(x => x[1] && typeof x[1] === 'object' && x[1].kind ? x : [x[0], primitiveValue(x[1]), x[2]]).map(x => x[2] ? [x[0], x[1], false, ...x.slice(2)] : [x[0], x[1]]);
return Object.assign({
kind: 'object',
members: membersProps
}, 0 < additionalProps.length ? {
additionalProps
} : {});
}
function checkRecursiveExtends(ty, base) {
if (ty === base) {
return false;
}
if (ty.typeName && (ty.typeName === base.typeName || base.kind === 'symlink' && ty.typeName === base.symlinkTargetName)) {
return false;
}
if (base.kind === 'object' && base.baseTypes) {
for (const z of base.baseTypes) {
if (!checkRecursiveExtends(ty, z)) {
return false;
}
}
}
return true;
}
function derived(ty, ...exts) {
const ret = {
kind: 'object',
members: [],
baseTypes: []
};
for (const ext of exts) {
switch (ext.kind) {
case 'object':
if (!checkRecursiveExtends(ty, ext)) {
throw new Error(`Recursive extend is found: ${ty.name || '(unnamed)'}`);
}
for (const m of ext.members) {
if (!ret.members.find(x => x[0] === m[0])) {
ret.members.push([m[0], m[1], true, ...m.slice(3)]);
} // TODO: Check for different types with the same name.
}
// FALL_THRU
case 'symlink':
ret.baseTypes.push(ext);
break;
case 'operator':
{
throw new Error(`Unresolved type operator is found: ${ext.operator}`);
}
} // NOTE: 'symlink' base types will resolved by calling `resolveSymbols()`.
// `resolveSymbols()` will call `derived()` after resolve symlink exts.
}
ret.members = ty.members.concat(ret.members);
if (ty.baseTypes) {
ret.baseTypes = ty.baseTypes.filter(x => x.kind !== 'symlink').concat(ret.baseTypes);
}
if (ret.baseTypes.length === 0) {
delete ret.baseTypes;
}
const revMembers = ret.members.slice().reverse();
for (const x of ret.members) {
if (ret.members.find(m => m[0] === x[0]) !== revMembers.find(m => m[0] === x[0])) {
throw new Error(`Duplicated member is found: ${x[0]} in ${ty.name || '(unnamed)'}`);
}
}
let additionalProps = [];
if (ret.baseTypes) {
for (const base of ret.baseTypes) {
if (base.kind === 'object') {
if (base.additionalProps && 0 < base.additionalProps.length) {
additionalProps = additionalProps.concat(base.additionalProps.map(x => [x[0], x[1], true, ...x.slice(3)]));
}
} // NOTE: 'symlink' base types will resolved by calling `resolveSymbols()`.
// `resolveSymbols()` will call `derived()` after resolve symlink exts.
}
}
if (ty.additionalProps && 0 < ty.additionalProps.length) {
additionalProps = additionalProps.concat(ty.additionalProps); // TODO: concat order
}
if (0 < additionalProps.length) {
ret.additionalProps = additionalProps;
}
return ret;
}
function symlinkType(name) {
return {
kind: 'symlink',
symlinkTargetName: name
};
}
function withName(ty, name) {
if (!name) {
return ty;
}
return Object.assign(Object.assign({}, ty), {
name
});
}
function withTypeName(ty, typeName) {
if (!typeName) {
return ty;
}
return Object.assign(Object.assign({}, ty), {
typeName
});
}
function withOriginalTypeName(ty, originalTypeName) {
if (!originalTypeName) {
return ty;
}
return Object.assign(Object.assign({}, ty), {
originalTypeName
});
}
function withDocComment(ty, docComment) {
if (!docComment) {
return ty;
}
return Object.assign(Object.assign({}, ty), {
docComment
});
}
function withRange(minValue, maxValue) {
return ty => {
if (typeof minValue !== 'number' && typeof minValue !== 'string') {
throw new Error(`Decorator '@range' parameter 'minValue' should be number or string.`);
}
if (typeof maxValue !== 'number' && typeof maxValue !== 'string') {
throw new Error(`Decorator '@range' parameter 'maxValue' should be number or string.`);
}
if (ty.kind === 'optional') {
const opt = ty.optional;
if (opt.kind !== 'primitive') {
throw new Error(`Decorator '@range' cannot be applied to anything other than 'primitive'.`);
}
return Object.assign(Object.assign({}, ty), {
optional: Object.assign(Object.assign({}, opt), {
minValue,
maxValue
})
});
} else {
if (!ty || ty.kind !== 'primitive') {
throw new Error(`Decorator '@range' cannot be applied to anything other than 'primitive'.`);
}
return Object.assign(Object.assign({}, ty), {
minValue,
maxValue
});
}
};
}
function withMinValue(minValue) {
return ty => {
if (typeof minValue !== 'number' && typeof minValue !== 'string') {
throw new Error(`Decorator '@minValue' parameter 'minValue' should be number or string.`);
}
if (ty.kind === 'optional') {
const opt = ty.optional;
if (opt.kind !== 'primitive') {
throw new Error(`Decorator '@minValue' cannot be applied to anything other than 'primitive'.`);
}
return Object.assign(Object.assign({}, ty), {
optional: Object.assign(Object.assign({}, opt), {
minValue
})
});
} else {
if (!ty || ty.kind !== 'primitive') {
throw new Error(`Decorator '@minValue' cannot be applied to anything other than 'primitive'.`);
}
return Object.assign(Object.assign({}, ty), {
minValue
});
}
};
}
function withMaxValue(maxValue) {
return ty => {
if (typeof maxValue !== 'number' && typeof maxValue !== 'string') {
throw new Error(`Decorator '@maxValue' parameter 'maxValue' should be number or string.`);
}
if (ty.kind === 'optional') {
const opt = ty.optional;
if (opt.kind !== 'primitive') {
throw new Error(`Decorator '@maxValue' cannot be applied to anything other than 'primitive'.`);
}
return Object.assign(Object.assign({}, ty), {
optional: Object.assign(Object.assign({}, opt), {
maxValue
})
});
} else {
if (!ty || ty.kind !== 'primitive') {
throw new Error(`Decorator '@maxValue' cannot be applied to anything other than 'primitive'.`);
}
return Object.assign(Object.assign({}, ty), {
maxValue
});
}
};
}
function withGreaterThan(greaterThanValue) {
return ty => {
if (typeof greaterThanValue !== 'number' && typeof greaterThanValue !== 'string') {
throw new Error(`Decorator '@greaterThan' parameter 'greaterThan' should be number or string.`);
}
if (ty.kind === 'optional') {
const opt = ty.optional;
if (opt.kind !== 'primitive') {
throw new Error(`Decorator '@greaterThan' cannot be applied to anything other than 'primitive'.`);
}
return Object.assign(Object.assign({}, ty), {
optional: Object.assign(Object.assign({}, opt), {
greaterThanValue
})
});
} else {
if (!ty || ty.kind !== 'primitive') {
throw new Error(`Decorator '@greaterThan' cannot be applied to anything other than 'primitive'.`);
}
return Object.assign(Object.assign({}, ty), {
greaterThanValue
});
}
};
}
function withLessThan(lessThanValue) {
return ty => {
if (typeof lessThanValue !== 'number' && typeof lessThanValue !== 'string') {
throw new Error(`Decorator '@lessThan' parameter 'lessThan' should be number or string.`);
}
if (ty.kind === 'optional') {
const opt = ty.optional;
if (opt.kind !== 'primitive') {
throw new Error(`Decorator '@lessThan' cannot be applied to anything other than 'primitive'.`);
}
return Object.assign(Object.assign({}, ty), {
optional: Object.assign(Object.assign({}, opt), {
lessThanValue
})
});
} else {
if (!ty || ty.kind !== 'primitive') {
throw new Error(`Decorator '@lessThan' cannot be applied to anything other than 'primitive'.`);
}
return Object.assign(Object.assign({}, ty), {
lessThanValue
});
}
};
}
function withMinLength(minLength) {
return ty => {
if (typeof minLength !== 'number') {
throw new Error(`Decorator '@minLength' parameter 'minLength' should be number.`);
}
if (ty.kind === 'optional') {
const opt = ty.optional;
if (opt.kind !== 'primitive') {
throw new Error(`Decorator '@minLength' cannot be applied to anything other than 'primitive'.`);
}
return Object.assign(Object.assign({}, ty), {
optional: Object.assign(Object.assign({}, opt), {
minLength
})
});
} else {
if (!ty || ty.kind !== 'primitive') {
throw new Error(`Decorator '@minLength' cannot be applied to anything other than 'primitive'.`);
}
return Object.assign(Object.assign({}, ty), {
minLength
});
}
};
}
function withMaxLength(maxLength) {
return ty => {
if (typeof maxLength !== 'number') {
throw new Error(`Decorator '@maxLength' parameter 'maxLength' should be number.`);
}
if (ty.kind === 'optional') {
const opt = ty.optional;
if (opt.kind !== 'primitive') {
throw new Error(`Decorator '@maxLength' cannot be applied to anything other than 'primitive'.`);
}
return Object.assign(Object.assign({}, ty), {
optional: Object.assign(Object.assign({}, opt), {
maxLength
})
});
} else {
if (!ty || ty.kind !== 'primitive') {
throw new Error(`Decorator '@maxLength' cannot be applied to anything other than 'primitive'.`);
}
return Object.assign(Object.assign({}, ty), {
maxLength
});
}
};
}
function withMatch(pattern) {
return ty => {
if (typeof pattern !== 'object') {
throw new Error(`Decorator '@match' parameter 'pattern' should be RegExp.`);
}
if (ty.kind === 'optional') {
const opt = ty.optional;
if (opt.kind !== 'primitive') {
throw new Error(`Decorator '@match' cannot be applied to anything other than 'primitive'.`);
}
return Object.assign(Object.assign({}, ty), {
optional: Object.assign(Object.assign({}, opt), {
pattern
})
});
} else {
if (!ty || ty.kind !== 'primitive' || ty.primitiveName !== 'string') {
throw new Error(`Decorator '@match' cannot be applied to anything other than 'primitive'.`);
}
return Object.assign(Object.assign({}, ty), {
pattern
});
}
};
}
function withStereotype(stereotype) {
if (typeof stereotype !== 'string') {
throw new Error(`Decorator '@stereotype' parameter 'stereotype' should be string.`);
}
if ((0, _util.isUnsafeVarNames)(_util.dummyTargetObject, stereotype)) {
throw new Error(`Unsafe symbol name is appeared in stereotype assertion: ${stereotype}`);
}
return ty => {
if (ty.kind === 'optional') {
const ret = Object.assign(Object.assign({}, ty), {
optional: Object.assign(Object.assign({}, ty.optional), {
stereotype
})
});
return ret;
} else {
const ret = Object.assign(Object.assign({}, ty), {
stereotype
});
return ret;
}
};
}
function withConstraint(name, args) {
if (typeof name !== 'string') {
throw new Error(`Decorator '@constraint' parameter 'name' should be string.`);
}
if ((0, _util.isUnsafeVarNames)(_util.dummyTargetObject, name)) {
throw new Error(`Unsafe symbol name is appeared in constraint assertion: ${name}`);
}
return ty => {
if (ty.kind === 'optional') {
const opt = ty.optional;
const ret = Object.assign(Object.assign({}, ty), {
optional: Object.assign(Object.assign({}, opt), {
customConstraints: opt.customConstraints ? opt.customConstraints.slice().push(name) : [name],
customConstraintsArgs: opt.customConstraintsArgs ? Object.assign(Object.assign({}, opt.customConstraintsArgs), {
[name]: args
}) : {
[name]: args
}
})
});
return ret;
} else {
const ret = Object.assign(Object.assign({}, ty), {
customConstraints: ty.customConstraints ? ty.customConstraints.slice().push(name) : [name],
customConstraintsArgs: ty.customConstraintsArgs ? Object.assign(Object.assign({}, ty.customConstraintsArgs), {
[name]: args
}) : {
[name]: args
}
});
return ret;
}
};
}
function withForceCast() {
return ty => {
if (ty.kind === 'optional') {
const ret = Object.assign(Object.assign({}, ty), {
optional: Object.assign(Object.assign({}, ty.optional), {
forceCast: true
})
});
return ret;
} else {
const ret = Object.assign(Object.assign({}, ty), {
forceCast: true
});
return ret;
}
};
}
function withRecordType() {
return ty => {
if (ty.kind === 'optional') {
const ret = Object.assign(Object.assign({}, ty), {
optional: Object.assign(Object.assign({}, ty.optional), {
isRecordTypeField: true
})
});
return ret;
} else {
const ret = Object.assign(Object.assign({}, ty), {
isRecordTypeField: true
});
return ret;
}
};
}
function withMeta(meta) {
return ty => {
const ret = Object.assign(Object.assign({}, ty), {
meta
});
return ret;
};
}
function withMsg(messages) {
return ty => {
if (ty.kind === 'optional') {
if (typeof messages === 'string') {
const ret = Object.assign(Object.assign({}, ty), {
message: messages,
optional: Object.assign(Object.assign({}, ty.optional), {
message: messages
})
});
delete ret.messages;
delete ret.optional.messages;
return ret;
} else {
const ret = Object.assign(Object.assign({}, ty), {
messages,
optional: Object.assign(Object.assign({}, ty.optional), {
messages
})
});
delete ret.message;
delete ret.optional.message;
return ret;
}
} else {
if (typeof messages === 'string') {
const ret = Object.assign(Object.assign({}, ty), {
message: messages
});
delete ret.messages;
return ret;
} else {
const ret = Object.assign(Object.assign({}, ty), {
messages
});
delete ret.message;
return ret;
}
}
};
}
function withMsgId(messageId) {
return ty => {
if (ty.kind === 'optional') {
return Object.assign(Object.assign({}, ty), {
messageId,
optional: Object.assign(Object.assign({}, ty.optional), {
messageId
})
});
} else {
return Object.assign(Object.assign({}, ty), {
messageId
});
}
};
}
},{"./lib/util":"qf2u"}],"DUcg":[function(require,module,exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.resolveMemberNames = resolveMemberNames;
exports.resolveSymbols = resolveSymbols;
exports.resolveSchema = resolveSchema;
var operators = _interopRequireWildcard(require("../operators"));
var _util = require("../lib/util");
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
// Copyright (c) 2019 Shellyl_N and Authors
// license: ISC
// https://github.com/shellyln
function mergeTypeAndSymlink(ty, link) {
const link2 = Object.assign({}, link);
delete link2.kind;
delete link2.symlinkTargetName;
delete link2.memberTree;
return Object.assign(Object.assign({}, ty), link2);
}
function updateSchema(original, schema, ty, typeName) {
if (typeName && schema.has(typeName)) {
const z = schema.get(typeName);
if (z.ty === original) {
schema.set(typeName, Object.assign(Object.assign({}, z), {
ty,
resolved: true
}));
}
}
return ty;
}
function resolveMemberNames(ty, rootSym, memberTreeSymbols, memberPos) {
const addTypeName = (mt, typeName, memberSym) => {
if (typeName) {
return Object.assign(Object.assign({}, mt), {
typeName: memberPos === 0 ? `${rootSym}.${memberTreeSymbols.join('.')}` : `${typeName}.${memberSym}`
});
} else {
return mt;
}
};
for (let i = memberPos; i < memberTreeSymbols.length; i++) {
const memberSym = memberTreeSymbols[i];
switch (ty.kind) {
case 'optional':
return resolveMemberNames(ty.optional, rootSym, memberTreeSymbols, i + 1);
case 'object':
for (const m of ty.members) {
if (memberSym === m[0]) {
return addTypeName(resolveMemberNames(m[1], rootSym, memberTreeSymbols, i + 1), ty.typeName, memberSym);
}
}
if (ty.additionalProps) {
for (const m of ty.additionalProps) {
for (const k of m[0]) {
switch (k) {
case 'number':
if (_util.NumberPattern.test(memberSym)) {
return resolveMemberNames(m[1], rootSym, memberTreeSymbols, i + 1);
}
break;
case 'string':
return resolveMemberNames(m[1], rootSym, memberTreeSymbols, i + 1);
default:
if (k.test(memberSym)) {
return resolveMemberNames(m[1], rootSym, memberTreeSymbols, i + 1);
}
break;
}
}
}
}
throw new Error(`Undefined member name is appeared: ${memberSym}`);
case 'symlink':
if (!ty.typeName) {
throw new Error(`Reference of anonymous type is appeared: ${memberSym}`);
}
return Object.assign({
kind: 'symlink',
symlinkTargetName: rootSym,
name: memberSym,
typeName: rootSym
}, 0 < memberTreeSymbols.length ? {
memberTree: memberTreeSymbols
} : {});
default:
// TODO: kind === 'operator'
throw new Error(`Unsupported type kind is appeared: (kind:${ty.kind}).${memberSym}`);
}
}
return ty;
}
function resolveSymbols(schema, ty, ctx) {
var _a;
const ctx2 = Object.assign(Object.assign({}, ctx), {
nestLevel: ctx.nestLevel + 1
});
switch (ty.kind) {
case 'symlink':
{
const x = schema.get(ty.symlinkTargetName);
if (!x) {
throw new Error(`Undefined symbol '${ty.symlinkTargetName}' is referred.`);
}
if (0 <= ctx.symlinkStack.findIndex(s => s === ty.symlinkTargetName)) {
return ty;
}
const ty2 = Object.assign({}, ty);
let xTy = x.ty;
if (ty.memberTree && 0 < ty.memberTree.length) {
xTy = Object.assign({}, resolveMemberNames(xTy, ty.symlinkTargetName, ty.memberTree, 0));
ty2.typeName = xTy.typeName;
}
return resolveSymbols(schema, mergeTypeAndSymlink(xTy, ty2), Object.assign(Object.assign({}, ctx2), {
symlinkStack: [...ctx2.symlinkStack, ty2.symlinkTargetName]
}));
}
case 'repeated':
return updateSchema(ty, schema, Object.assign(Object.assign({}, ty), {
repeated: resolveSymbols(schema, ty.repeated, ctx2)
}), ty.typeName);
case 'spread':
return updateSchema(ty, schema, Object.assign(Object.assign({}, ty), {
spread: resolveSymbols(schema, ty.spread, ctx2)
}), ty.typeName);
case 'sequence':
return updateSchema(ty, schema, Object.assign(Object.assign({}, ty), {
sequence: ty.sequence.map(x => resolveSymbols(schema, x, ctx2))
}), ty.typeName);
case 'one-of':
return updateSchema(ty, schema, Object.assign(Object.assign({}, ty), {
oneOf: ty.oneOf.map(x => resolveSymbols(schema, x, ctx2))
}), ty.typeName);
case 'optional':
return updateSchema(ty, schema, Object.assign(Object.assign({}, ty), {
optional: resolveSymbols(schema, ty.optional, ctx2)
}), ty.typeName);
case 'object':
{
if (0 < ctx.nestLevel && ty.typeName && 0 <= ctx.symlinkStack.findIndex(s => s === ty.typeName)) {
if (schema.has(ty.typeName)) {
const z = schema.get(ty.typeName);
if (z.resolved) {
return z.ty;
}
}
}
const baseSymlinks = (_a = ty.baseTypes) === null || _a === void 0 ? void 0 : _a.filter(x => x.kind === 'symlink');
if (baseSymlinks && baseSymlinks.length > 0 && !ctx.isDeserialization) {
const exts = baseSymlinks.map(x => resolveSymbols(schema, x, ctx2)).filter(x => x.kind === 'object'); // TODO: if x.kind !== 'object' items exist -> error?
const d2 = resolveSymbols(schema, operators.derived(Object.assign(Object.assign({}, ty), ty.baseTypes ? {
baseTypes: ty.baseTypes.filter(x => x.kind !== 'symlink')
} : {}), ...exts), ty.typeName ? Object.assign(Object.assign({}, ctx2), {
symlinkStack: [...ctx2.symlinkStack, ty.typeName]
}) : ctx2);
return updateSchema(ty, schema, Object.assign(Object.assign({}, ty), d2), ty.typeName);
} else {
return updateSchema(ty, schema, Object.assign(Object.assign(Object.assign({}, Object.assign(Object.assign({}, ty), {
members: ty.members.map(x => [x[0], resolveSymbols(schema, x[1], ty.typeName ? Object.assign(Object.assign({}, ctx2), {
symlinkStack: [...ctx2.symlinkStack, ty.typeName]
}) : ctx2), ...x.slice(2)])
})), ty.additionalProps && 0 < ty.additionalProps.length ? {
additionalProps: ty.additionalProps.map(x => [x[0], resolveSymbols(schema, x[1], ty.typeName ? Object.assign(Object.assign({}, ctx2), {
symlinkStack: [...ctx2.symlinkStack, ty.typeName]
}) : ctx2), ...x.slice(2)])
} : {}), ty.baseTypes && 0 < ty.baseTypes.length ? {
baseTypes: ctx.isDeserialization ? ty.baseTypes.map(x => x.kind === 'symlink' ? resolveSymbols(schema, x, ctx2) : x).filter(x => x.kind === 'object') : ty.baseTypes
} : {}), ty.typeName);
}
}
case 'operator':
if (ctx2.operators) {
const ctx3 = ty.typeName ? Object.assign(Object.assign({}, ctx2), {
symlinkStack: [...ctx2.symlinkStack, ty.typeName]
}) : ctx2;
const operands = ty.operands.map(x => {
if (typeof x === 'object' && x.kind) {
return resolveSymbols(schema, x, ctx3);
}
return x;
});
if (0 < operands.filter(x => x && typeof x === 'object' && (x.kind === 'symlink' || x.kind === 'operator')).length) {
throw new Error(`Unresolved type operator is found: ${ty.operator}`);
}
if (!ctx2.operators[ty.operator]) {
throw new Error(`Undefined type operator is found: ${ty.operator}`);
}
const ty2 = Object.assign({}, ty);
delete ty2.operator;
delete ty2.operands;
return updateSchema(ty, schema, Object.assign(Object.assign({}, ty2), resolveSymbols(schema, ctx2.operators[ty.operator](...operands), ctx3)), ty.typeName);
} else {
return ty;
}
default:
return ty;
}
}
const resolverOps = {
picked: operators.picked,
omit: operators.omit,
partial: operators.partial,
intersect: operators.intersect,
subtract: operators.subtract
};
function resolveSchema(schema, opts) {
for (const ent of schema.entries()) {
const ty = resolveSymbols(schema, ent[1].ty, Object.assign(Object.assign({}, opts), {
nestLevel: 0,
symlinkStack: [ent[0]],
operators: resolverOps
}));
ent[1].ty = ty;
}
return schema;
}
},{"../operators":"ZikL","../lib/util":"qf2u"}],"T6V6":[function(require,module,exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.serializeToObject = serializeToObject;
exports.serialize = serialize;
exports.deserializeFromObject = deserializeFromObject;
exports.deserialize = deserialize;
exports.TynderSchemaVersion = void 0;
var _resolver = require("./lib/resolver");
// Copyright (c) 2019 Shellyl_N and Authors
// license: ISC
// https://github.com/shellyln
const TynderSchemaVersion = 'tynder/1.0';
exports.TynderSchemaVersion = TynderSchemaVersion;
function hasMetaInfo(ty) {
let hasInfo = false;
if (ty.messages) {
hasInfo = true;
}
if (ty.message) {
hasInfo = true;
}
if (ty.messageId) {
hasInfo = true;
}
switch (ty.kind) {
case 'repeated':
if (typeof ty.min === 'number') {
hasInfo = true;
}
if (typeof ty.max === 'number') {
hasInfo = true;
}
break;
case 'primitive':
if (typeof ty.minValue === 'number') {
hasInfo = true;
}
if (typeof ty.maxValue === 'number') {
hasInfo = true;
}
if (typeof ty.greaterThanValue === 'number') {
hasInfo = true;
}
if (typeof ty.lessThanValue === 'number') {
hasInfo = true;
}
if (typeof ty.minLength === 'number') {
hasInfo = true;
}
if (typeof ty.maxLength === 'number') {
hasInfo = true;
}
if (ty.pattern) {
hasInfo = true;
}
break;
}
return hasInfo;
}
function serializeInner(ty, nestLevel) {
if (0 < nestLevel && ty.typeName && !hasMetaInfo(ty)) {
switch (ty.kind) {
case 'optional':
// nothing to do.
break;
default:
return Object.assign(Object.assign({
kind: 'symlink',
symlinkTargetName: ty.typeName,
typeName: ty.typeName
}, ty.name ? {
name: ty.name
} : {}), ty.docComment ? {
docComment: ty.docComment
} : {});
}
}
const ret = Object.assign({}, ty);
switch (ret.kind) {
case 'never':
case 'any':
case 'unknown':
case 'symlink':
case 'operator':
break;
case 'primitive-value':
if (typeof ret.value === 'bigint') {
ret.value = String(ret.value);
ret.primitiveName = 'bigint';
}
break;
case 'primitive':
if (ret.pattern) {
ret.pattern = `/${ret.pattern.source}/${ret.pattern.flags}`;
}
break;
case 'repeated':
ret.repeated = serializeInner(ret.repeated, nestLevel + 1);
break;
case 'spread':
ret.spread = serializeInner(ret.spread, nestLevel + 1);
break;
case 'sequence':
ret.sequence = ret.sequence.map(x => serializeInner(x, nestLevel + 1));
break;
case 'one-of':
ret.oneOf = ret.oneOf.map(x => serializeInner(x, nestLevel + 1));
break;
case 'optional':
ret.optional = serializeInner(ret.optional, nestLevel + 1);
break;
case 'enum':
ret.values = ret.values.slice().map(x => x[2] === null || x[2] === void 0 ? x.slice(0, 2) : x);
break;
case 'object':
ret.members = ret.members.map(x => [x[0], serializeInner(x[1], nestLevel + 1), ...x.slice(2)]);
if (ret.additionalProps) {
ret.additionalProps = ret.additionalProps.map(x => [x[0].map(p => typeof p === 'string' ? p : `/${p.source}/${p.flags}`), serializeInner(x[1], nestLevel + 1), ...x.slice(2)]);
}
if (ret.baseTypes) {
// NOTE: convert 'baseTypes' to 'symlink'.
ret.baseTypes = ret.baseTypes.map(x => serializeInner(x, nestLevel + 1));
}
break;