Change endpoint from persons to people

This commit is contained in:
xfarrow
2025-03-23 21:00:08 +01:00
parent 4ae263662c
commit d005193f63
7158 changed files with 700476 additions and 735 deletions

View File

@ -0,0 +1,5 @@
import { Context } from '../context';
import { ContextItem } from './context-item';
export declare class Bail implements ContextItem {
run(context: Context): Promise<void>;
}

View File

@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Bail = void 0;
const base_1 = require("../base");
class Bail {
run(context) {
if (context.errors.length > 0) {
throw new base_1.ValidationHalt();
}
return Promise.resolve();
}
}
exports.Bail = Bail;

View File

@ -0,0 +1,9 @@
import { Meta } from '../base';
import { ContextRunner } from '../chain';
import { Context } from '../context';
import { ContextItem } from './context-item';
export declare class ChainCondition implements ContextItem {
private readonly chain;
constructor(chain: ContextRunner);
run(_context: Context, _value: any, meta: Meta): Promise<void>;
}

View File

@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChainCondition = void 0;
const base_1 = require("../base");
class ChainCondition {
constructor(chain) {
this.chain = chain;
}
async run(_context, _value, meta) {
const result = await this.chain.run(meta.req, { dryRun: true });
if (!result.isEmpty()) {
throw new base_1.ValidationHalt();
}
}
}
exports.ChainCondition = ChainCondition;

View File

@ -0,0 +1,5 @@
import { Meta } from '../base';
import { Context } from '../context';
export interface ContextItem {
run(context: Context, value: any, meta: Meta): Promise<void>;
}

View File

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@ -0,0 +1,8 @@
import { CustomValidator, Meta } from '../base';
import { Context } from '../context';
import { ContextItem } from './context-item';
export declare class CustomCondition implements ContextItem {
private readonly condition;
constructor(condition: CustomValidator);
run(_context: Context, value: any, meta: Meta): Promise<void>;
}

View File

@ -0,0 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CustomCondition = void 0;
const base_1 = require("../base");
class CustomCondition {
constructor(condition) {
this.condition = condition;
}
async run(_context, value, meta) {
try {
const result = this.condition(value, meta);
await result;
// if the promise resolved or the result is truthy somehow, then there's no validation halt.
if (!result) {
// the error thrown here is symbolic, it will be re-thrown in the catch clause anyway.
throw new Error();
}
}
catch (e) {
throw new base_1.ValidationHalt();
}
}
}
exports.CustomCondition = CustomCondition;

View File

@ -0,0 +1,10 @@
import { CustomValidator, Meta } from '../base';
import { Context } from '../context';
import { ContextItem } from './context-item';
export declare class CustomValidation implements ContextItem {
private readonly validator;
private readonly negated;
message: any;
constructor(validator: CustomValidator, negated: boolean);
run(context: Context, value: any, meta: Meta): Promise<void>;
}

View File

@ -0,0 +1,34 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CustomValidation = void 0;
class CustomValidation {
constructor(validator, negated) {
this.validator = validator;
this.negated = negated;
}
async run(context, value, meta) {
try {
const result = this.validator(value, meta);
const actualResult = await result;
const isPromise = result && result.then;
const failed = this.negated ? actualResult : !actualResult;
// A promise that was resolved only adds an error if negated.
// Otherwise it always suceeds
if ((!isPromise && failed) || (isPromise && this.negated)) {
context.addError({ type: 'field', message: this.message, value, meta });
}
}
catch (err) {
if (this.negated) {
return;
}
context.addError({
type: 'field',
message: this.message || (err instanceof Error ? err.message : err),
value,
meta,
});
}
}
}
exports.CustomValidation = CustomValidation;

View File

@ -0,0 +1,5 @@
export * from './chain-condition';
export * from './context-item';
export * from './custom-condition';
export * from './custom-validation';
export * from './standard-validation';

View File

@ -0,0 +1,21 @@
"use strict";
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 __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 });
__exportStar(require("./chain-condition"), exports);
__exportStar(require("./context-item"), exports);
__exportStar(require("./custom-condition"), exports);
__exportStar(require("./custom-validation"), exports);
__exportStar(require("./standard-validation"), exports);

View File

@ -0,0 +1,12 @@
import { Context } from '../context';
import { CustomSanitizer, Meta, StandardSanitizer } from '../base';
import { toString as toStringImpl } from '../utils';
import { ContextItem } from './context-item';
export declare class Sanitization implements ContextItem {
private readonly sanitizer;
private readonly custom;
private readonly options;
private readonly stringify;
constructor(sanitizer: StandardSanitizer | CustomSanitizer, custom: boolean, options?: any[], stringify?: typeof toStringImpl);
run(context: Context, value: any, meta: Meta): Promise<void>;
}

View File

@ -0,0 +1,34 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Sanitization = void 0;
const utils_1 = require("../utils");
class Sanitization {
constructor(sanitizer, custom, options = [],
// For testing only.
// Deliberately not calling it `toString` in order to not override `Object.prototype.toString`.
stringify = utils_1.toString) {
this.sanitizer = sanitizer;
this.custom = custom;
this.options = options;
this.stringify = stringify;
}
async run(context, value, meta) {
const { path, location } = meta;
const runCustomSanitizer = async () => {
const sanitizerValue = this.sanitizer(value, meta);
return Promise.resolve(sanitizerValue);
};
if (this.custom) {
const newValue = await runCustomSanitizer();
context.setData(path, newValue, location);
return;
}
const values = Array.isArray(value) ? value : [value];
const newValues = values.map(value => {
return this.sanitizer(this.stringify(value), ...this.options);
});
// We get only the first value of the array if the orginal value was wrapped.
context.setData(path, values !== value ? newValues[0] : newValues, location);
}
}
exports.Sanitization = Sanitization;

View File

@ -0,0 +1,13 @@
import { Meta, StandardValidator } from '../base';
import { toString as toStringImpl } from '../utils';
import { Context } from '../context';
import { ContextItem } from './context-item';
export declare class StandardValidation implements ContextItem {
private readonly validator;
private readonly negated;
private readonly options;
private readonly stringify;
message: any;
constructor(validator: StandardValidator, negated: boolean, options?: any[], stringify?: typeof toStringImpl);
run(context: Context, value: any, meta: Meta): Promise<void>;
}

View File

@ -0,0 +1,25 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StandardValidation = void 0;
const utils_1 = require("../utils");
class StandardValidation {
constructor(validator, negated, options = [],
// For testing only.
// Deliberately not calling it `toString` in order to not override `Object.prototype.toString`.
stringify = utils_1.toString) {
this.validator = validator;
this.negated = negated;
this.options = options;
this.stringify = stringify;
}
async run(context, value, meta) {
const values = Array.isArray(value) ? value : [value];
values.forEach(value => {
const result = this.validator(this.stringify(value), ...this.options);
if (this.negated ? result : !result) {
context.addError({ type: 'field', message: this.message, value, meta });
}
});
}
}
exports.StandardValidation = StandardValidation;