New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@atproto/lexicon

Package Overview
Dependencies
Maintainers
4
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@atproto/lexicon - npm Package Compare versions

Comparing version 0.4.5 to 0.4.6-next.5

2

dist/blob-refs.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BlobRef = exports.jsonBlobRef = exports.untypedJsonBlobRef = exports.typedJsonBlobRef = void 0;
const common_web_1 = require("@atproto/common-web");
const cid_1 = require("multiformats/cid");
const zod_1 = require("zod");
const common_web_1 = require("@atproto/common-web");
exports.typedJsonBlobRef = zod_1.z

@@ -8,0 +8,0 @@ .object({

@@ -1,2 +0,2 @@

import { LexiconDoc, LexUserType, ValidationResult } from './types';
import { LexUserType, LexiconDoc, ValidationResult } from './types';
/**

@@ -3,0 +3,0 @@ * A collection of compiled lexicons.

"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 __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 (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Lexicons = void 0;
const types_1 = require("./types");
const util_1 = require("./util");
const validation_1 = require("./validation");
const util_1 = require("./util");
const ComplexValidators = __importStar(require("./validators/complex"));
const complex_1 = require("./validators/complex");
/**

@@ -127,12 +104,12 @@ * A collection of compiled lexicons.

validate(lexUri, value) {
lexUri = (0, util_1.toLexUri)(lexUri);
const def = this.getDefOrThrow(lexUri, ['record', 'object']);
if (!(0, types_1.isObj)(value)) {
throw new types_1.ValidationError(`Value must be an object`);
}
const lexUriNormalized = (0, util_1.toLexUri)(lexUri);
const def = this.getDefOrThrow(lexUriNormalized, ['record', 'object']);
if (def.type === 'record') {
return ComplexValidators.object(this, 'Record', def.record, value);
return (0, complex_1.object)(this, 'Record', def.record, value);
}
else if (def.type === 'object') {
return ComplexValidators.object(this, 'Object', def, value);
return (0, complex_1.object)(this, 'Object', def, value);
}

@@ -148,14 +125,17 @@ else {

assertValidRecord(lexUri, value) {
lexUri = (0, util_1.toLexUri)(lexUri);
const def = this.getDefOrThrow(lexUri, ['record']);
if (!(0, types_1.isObj)(value)) {
throw new types_1.ValidationError(`Record must be an object`);
}
if (!(0, types_1.hasProp)(value, '$type') || typeof value.$type !== 'string') {
if (!('$type' in value)) {
throw new types_1.ValidationError(`Record/$type must be a string`);
}
const $type = value.$type || '';
if ((0, util_1.toLexUri)($type) !== lexUri) {
throw new types_1.ValidationError(`Invalid $type: must be ${lexUri}, got ${$type}`);
const { $type } = value;
if (typeof $type !== 'string') {
throw new types_1.ValidationError(`Record/$type must be a string`);
}
const lexUriNormalized = (0, util_1.toLexUri)(lexUri);
if ((0, util_1.toLexUri)($type) !== lexUriNormalized) {
throw new types_1.ValidationError(`Invalid $type: must be ${lexUriNormalized}, got ${$type}`);
}
const def = this.getDefOrThrow(lexUriNormalized, ['record']);
return (0, validation_1.assertValidRecord)(this, def, value);

@@ -162,0 +142,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.jsonStringToLex = exports.jsonToLex = exports.stringifyLex = exports.lexToJson = exports.ipldToLex = exports.lexToIpld = void 0;
const cid_1 = require("multiformats/cid");
const common_web_1 = require("@atproto/common-web");
const cid_1 = require("multiformats/cid");
const blob_refs_1 = require("./blob-refs");

@@ -7,0 +7,0 @@ // @NOTE avoiding use of check.is() here only because it makes

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LexiconDefNotFoundError = exports.InvalidLexiconError = exports.ValidationError = exports.discriminatedObject = exports.lexiconDoc = exports.lexUserType = exports.lexRecord = exports.lexXrpcSubscription = exports.lexXrpcProcedure = exports.lexXrpcQuery = exports.lexXrpcError = exports.lexXrpcSubscriptionMessage = exports.lexXrpcBody = exports.lexXrpcParameters = exports.lexObject = exports.lexToken = exports.lexPrimitiveArray = exports.lexArray = exports.lexBlob = exports.lexRefVariant = exports.lexRefUnion = exports.lexRef = exports.lexIpldType = exports.lexCidLink = exports.lexBytes = exports.lexPrimitive = exports.lexUnknown = exports.lexString = exports.lexStringFormat = exports.lexInteger = exports.lexBoolean = void 0;
exports.LexiconDefNotFoundError = exports.InvalidLexiconError = exports.ValidationError = exports.lexiconDoc = exports.lexUserType = exports.lexRecord = exports.lexXrpcSubscription = exports.lexXrpcProcedure = exports.lexXrpcQuery = exports.lexXrpcError = exports.lexXrpcSubscriptionMessage = exports.lexXrpcBody = exports.lexXrpcParameters = exports.lexObject = exports.lexToken = exports.lexPrimitiveArray = exports.lexArray = exports.lexBlob = exports.lexRefVariant = exports.lexRefUnion = exports.lexRef = exports.lexIpldType = exports.lexCidLink = exports.lexBytes = exports.lexPrimitive = exports.lexUnknown = exports.lexString = exports.lexStringFormat = exports.lexInteger = exports.lexBoolean = void 0;
exports.isValidLexiconDoc = isValidLexiconDoc;
exports.isObj = isObj;
exports.hasProp = hasProp;
exports.isDiscriminatedObject = isDiscriminatedObject;

@@ -354,12 +353,8 @@ exports.parseLexiconDoc = parseLexiconDoc;

}
function isObj(obj) {
return obj !== null && typeof obj === 'object';
function isObj(v) {
return v != null && typeof v === 'object';
}
function hasProp(data, prop) {
return prop in data;
function isDiscriminatedObject(v) {
return isObj(v) && '$type' in v && typeof v.$type === 'string';
}
exports.discriminatedObject = zod_1.z.object({ $type: zod_1.z.string() });
function isDiscriminatedObject(value) {
return exports.discriminatedObject.safeParse(value).success;
}
function parseLexiconDoc(v) {

@@ -366,0 +361,0 @@ exports.lexiconDoc.parse(v);

import { z } from 'zod';
import { Lexicons } from './lexicons';
import { LexRefVariant, LexUserType } from './types';
export declare function toLexUri(str: string, baseUri?: string): string;
export declare function toConcreteTypes(lexicons: Lexicons, def: LexRefVariant | LexUserType): LexUserType[];
export declare function requiredPropertiesRefinement<ObjectType extends {

@@ -7,0 +4,0 @@ required?: string[];

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toLexUri = toLexUri;
exports.toConcreteTypes = toConcreteTypes;
exports.requiredPropertiesRefinement = requiredPropertiesRefinement;

@@ -22,13 +21,2 @@ const zod_1 = require("zod");

}
function toConcreteTypes(lexicons, def) {
if (def.type === 'ref') {
return [lexicons.getDefOrThrow(def.ref)];
}
else if (def.type === 'union') {
return def.refs.map((ref) => lexicons.getDefOrThrow(ref)).flat();
}
else {
return [def];
}
}
function requiredPropertiesRefinement(object, ctx) {

@@ -35,0 +23,0 @@ // Required fields check

@@ -13,14 +13,2 @@ "use strict";

switch (def.type) {
case 'boolean':
return (0, primitives_1.boolean)(lexicons, path, def, value);
case 'integer':
return (0, primitives_1.integer)(lexicons, path, def, value);
case 'string':
return (0, primitives_1.string)(lexicons, path, def, value);
case 'bytes':
return (0, primitives_1.bytes)(lexicons, path, def, value);
case 'cid-link':
return (0, primitives_1.cidLink)(lexicons, path, def, value);
case 'unknown':
return (0, primitives_1.unknown)(lexicons, path, def, value);
case 'object':

@@ -33,6 +21,3 @@ return object(lexicons, path, def, value);

default:
return {
success: false,
error: new types_1.ValidationError(`Unexpected lexicon type: ${def.type}`),
};
return (0, primitives_1.validate)(lexicons, path, def, value);
}

@@ -79,5 +64,4 @@ }

function object(lexicons, path, def, value) {
def = def;
// type
if (!value || typeof value !== 'object') {
if (!(0, types_1.isObj)(value)) {
return {

@@ -88,13 +72,12 @@ success: false,

}
const requiredProps = new Set(def.required);
const nullableProps = new Set(def.nullable);
// properties
let resultValue = value;
if (typeof def.properties === 'object') {
if ('properties' in def && def.properties != null) {
for (const key in def.properties) {
if (value[key] === null && nullableProps.has(key)) {
const keyValue = value[key];
if (keyValue === null && def.nullable?.includes(key)) {
continue;
}
const propDef = def.properties[key];
if (typeof value[key] === 'undefined' && !requiredProps.has(key)) {
if (keyValue === undefined && !def.required?.includes(key)) {
// Fast path for non-required undefined props.

@@ -104,3 +87,3 @@ if (propDef.type === 'integer' ||

propDef.type === 'string') {
if (typeof propDef.default === 'undefined') {
if (propDef.default === undefined) {
continue;

@@ -115,17 +98,20 @@ }

const propPath = `${path}/${key}`;
const validated = validateOneOf(lexicons, propPath, propDef, value[key]);
const propValue = validated.success ? validated.value : value[key];
const propIsUndefined = typeof propValue === 'undefined';
const validated = validateOneOf(lexicons, propPath, propDef, keyValue);
const propValue = validated.success ? validated.value : keyValue;
// Return error for bad validation, giving required rule precedence
if (propIsUndefined && requiredProps.has(key)) {
return {
success: false,
error: new types_1.ValidationError(`${path} must have the property "${key}"`),
};
if (propValue === undefined) {
if (def.required?.includes(key)) {
return {
success: false,
error: new types_1.ValidationError(`${path} must have the property "${key}"`),
};
}
}
else if (!propIsUndefined && !validated.success) {
return validated;
else {
if (!validated.success) {
return validated;
}
}
// Adjust value based on e.g. applied defaults, cloning shallowly if there was a changed value
if (propValue !== value[key]) {
if (propValue !== keyValue) {
if (resultValue === value) {

@@ -142,4 +128,3 @@ // Lazy shallow clone

function validateOneOf(lexicons, path, def, value, mustBeObj = false) {
let error;
let concreteDefs;
let concreteDef;
if (def.type === 'union') {

@@ -162,27 +147,14 @@ if (!(0, types_1.isDiscriminatedObject)(value)) {

else {
concreteDefs = (0, util_1.toConcreteTypes)(lexicons, {
type: 'ref',
ref: value.$type,
});
concreteDef = lexicons.getDefOrThrow(value.$type);
}
}
else if (def.type === 'ref') {
concreteDef = lexicons.getDefOrThrow(def.ref);
}
else {
concreteDefs = (0, util_1.toConcreteTypes)(lexicons, def);
concreteDef = def;
}
for (const concreteDef of concreteDefs) {
const result = mustBeObj
? object(lexicons, path, concreteDef, value)
: validate(lexicons, path, concreteDef, value);
if (result.success) {
return result;
}
error ?? (error = result.error);
}
if (concreteDefs.length > 1) {
return {
success: false,
error: new types_1.ValidationError(`${path} did not match any of the expected definitions`),
};
}
return { success: false, error };
return mustBeObj
? object(lexicons, path, concreteDef, value)
: validate(lexicons, path, concreteDef, value);
}

@@ -197,3 +169,3 @@ // to avoid bugs like #0189 this needs to handle both

if (lexUri.endsWith('#main')) {
return refs.includes(lexUri.replace('#main', ''));
return refs.includes(lexUri.slice(0, -5));
}

@@ -200,0 +172,0 @@ else {

@@ -16,5 +16,5 @@ "use strict";

const cid_1 = require("multiformats/cid");
const common_web_1 = require("@atproto/common-web");
const syntax_1 = require("@atproto/syntax");
const types_1 = require("../types");
const syntax_1 = require("@atproto/syntax");
const common_web_1 = require("@atproto/common-web");
function datetime(path, value) {

@@ -132,12 +132,9 @@ try {

function tid(path, value) {
try {
(0, syntax_1.ensureValidTid)(value);
if ((0, syntax_1.isValidTid)(value)) {
return { success: true, value };
}
catch {
return {
success: false,
error: new types_1.ValidationError(`${path} must be a valid TID (timestamp identifier)`),
};
}
return { success: true, value };
return {
success: false,
error: new types_1.ValidationError(`${path} must be a valid TID`),
};
}

@@ -144,0 +141,0 @@ function recordKey(path, value) {

import { Lexicons } from '../lexicons';
import { LexUserType, ValidationResult } from '../types';
export declare function validate(lexicons: Lexicons, path: string, def: LexUserType, value: unknown): ValidationResult;
export declare function boolean(lexicons: Lexicons, path: string, def: LexUserType, value: unknown): ValidationResult;
export declare function integer(lexicons: Lexicons, path: string, def: LexUserType, value: unknown): ValidationResult;
export declare function string(lexicons: Lexicons, path: string, def: LexUserType, value: unknown): ValidationResult;
export declare function bytes(lexicons: Lexicons, path: string, def: LexUserType, value: unknown): ValidationResult;
export declare function cidLink(lexicons: Lexicons, path: string, def: LexUserType, value: unknown): ValidationResult;
export declare function unknown(lexicons: Lexicons, path: string, def: LexUserType, value: unknown): ValidationResult;
//# sourceMappingURL=primitives.d.ts.map

@@ -27,12 +27,6 @@ "use strict";

exports.validate = validate;
exports.boolean = boolean;
exports.integer = integer;
exports.string = string;
exports.bytes = bytes;
exports.cidLink = cidLink;
exports.unknown = unknown;
const cid_1 = require("multiformats/cid");
const common_web_1 = require("@atproto/common-web");
const cid_1 = require("multiformats/cid");
const types_1 = require("../types");
const formats = __importStar(require("./formats"));
const types_1 = require("../types");
function validate(lexicons, path, def, value) {

@@ -39,0 +33,0 @@ switch (def.type) {

@@ -28,4 +28,4 @@ "use strict";

const types_1 = require("../types");
const complex_1 = require("./complex");
const PrimitiveValidators = __importStar(require("./primitives"));
const complex_1 = require("./complex");
function params(lexicons, path, def, val) {

@@ -32,0 +32,0 @@ // type

@@ -6,2 +6,3 @@ /** @type {import('jest').Config} */

setupFiles: ['<rootDir>/../../jest.setup.ts'],
moduleNameMapper: { '^(\\.\\.?\\/.+)\\.js$': ['$1.ts', '$1.js'] },
}
{
"name": "@atproto/lexicon",
"version": "0.4.5",
"version": "0.4.6-next.5",
"license": "MIT",

@@ -5,0 +5,0 @@ "description": "atproto Lexicon schema language library",

@@ -1,4 +0,4 @@

import { check, ipldToJson, schema } from '@atproto/common-web'
import { CID } from 'multiformats/cid'
import { z } from 'zod'
import { check, ipldToJson, schema } from '@atproto/common-web'

@@ -5,0 +5,0 @@ export const typedJsonBlobRef = z

import {
LexiconDoc,
InvalidLexiconError,
LexRecord,
LexUserType,
LexiconDefNotFoundError,
InvalidLexiconError,
LexiconDoc,
ValidationError,
ValidationResult,
ValidationError,
isObj,
hasProp,
} from './types'
import { toLexUri } from './util'
import {
assertValidRecord,
assertValidXrpcParams,
assertValidXrpcInput,
assertValidXrpcMessage,
assertValidXrpcOutput,
assertValidXrpcMessage,
assertValidXrpcParams,
} from './validation'
import { toLexUri } from './util'
import * as ComplexValidators from './validators/complex'
import { object as validateObject } from './validators/complex'

@@ -130,11 +129,13 @@ /**

validate(lexUri: string, value: unknown): ValidationResult {
lexUri = toLexUri(lexUri)
const def = this.getDefOrThrow(lexUri, ['record', 'object'])
if (!isObj(value)) {
throw new ValidationError(`Value must be an object`)
}
const lexUriNormalized = toLexUri(lexUri)
const def = this.getDefOrThrow(lexUriNormalized, ['record', 'object'])
if (def.type === 'record') {
return ComplexValidators.object(this, 'Record', def.record, value)
return validateObject(this, 'Record', def.record, value)
} else if (def.type === 'object') {
return ComplexValidators.object(this, 'Object', def, value)
return validateObject(this, 'Object', def, value)
} else {

@@ -150,16 +151,21 @@ // shouldn't happen

assertValidRecord(lexUri: string, value: unknown) {
lexUri = toLexUri(lexUri)
const def = this.getDefOrThrow(lexUri, ['record'])
if (!isObj(value)) {
throw new ValidationError(`Record must be an object`)
}
if (!hasProp(value, '$type') || typeof value.$type !== 'string') {
if (!('$type' in value)) {
throw new ValidationError(`Record/$type must be a string`)
}
const $type = (value as Record<string, string>).$type || ''
if (toLexUri($type) !== lexUri) {
const { $type } = value
if (typeof $type !== 'string') {
throw new ValidationError(`Record/$type must be a string`)
}
const lexUriNormalized = toLexUri(lexUri)
if (toLexUri($type) !== lexUriNormalized) {
throw new ValidationError(
`Invalid $type: must be ${lexUri}, got ${$type}`,
`Invalid $type: must be ${lexUriNormalized}, got ${$type}`,
)
}
const def = this.getDefOrThrow(lexUriNormalized, ['record'])
return assertValidRecord(this, def as LexRecord, value)

@@ -166,0 +172,0 @@ }

@@ -0,9 +1,9 @@

import { CID } from 'multiformats/cid'
import {
IpldValue,
JsonValue,
check,
IpldValue,
ipldToJson,
jsonToIpld,
JsonValue,
} from '@atproto/common-web'
import { CID } from 'multiformats/cid'
import { BlobRef, jsonBlobRef } from './blob-refs'

@@ -10,0 +10,0 @@

@@ -450,21 +450,11 @@ import { z } from 'zod'

export function isObj(obj: unknown): obj is Record<string, unknown> {
return obj !== null && typeof obj === 'object'
export function isObj<V>(v: V): v is V & object {
return v != null && typeof v === 'object'
}
export function hasProp<K extends PropertyKey>(
data: object,
prop: K,
): data is Record<K, unknown> {
return prop in data
export type DiscriminatedObject = { $type: string }
export function isDiscriminatedObject(v: unknown): v is DiscriminatedObject {
return isObj(v) && '$type' in v && typeof v.$type === 'string'
}
export const discriminatedObject = z.object({ $type: z.string() })
export type DiscriminatedObject = z.infer<typeof discriminatedObject>
export function isDiscriminatedObject(
value: unknown,
): value is DiscriminatedObject {
return discriminatedObject.safeParse(value).success
}
export function parseLexiconDoc(v: unknown): LexiconDoc {

@@ -475,6 +465,6 @@ lexiconDoc.parse(v)

export type ValidationResult =
export type ValidationResult<V = unknown> =
| {
success: true
value: unknown
value: V
}

@@ -481,0 +471,0 @@ | {

import { z } from 'zod'
import { Lexicons } from './lexicons'
import { LexRefVariant, LexUserType } from './types'

@@ -22,15 +20,2 @@ export function toLexUri(str: string, baseUri?: string): string {

export function toConcreteTypes(
lexicons: Lexicons,
def: LexRefVariant | LexUserType,
): LexUserType[] {
if (def.type === 'ref') {
return [lexicons.getDefOrThrow(def.ref)]
} else if (def.type === 'union') {
return def.refs.map((ref) => lexicons.getDefOrThrow(ref)).flat()
} else {
return [def]
}
}
export function requiredPropertiesRefinement<

@@ -37,0 +22,0 @@ ObjectType extends {

@@ -10,3 +10,2 @@ import { Lexicons } from './lexicons'

} from './types'
import { object, validateOneOf } from './validators/complex'

@@ -13,0 +12,0 @@ import { params } from './validators/xrpc'

import { BlobRef } from '../blob-refs'
import { Lexicons } from '../lexicons'
import { LexUserType, ValidationResult, ValidationError } from '../types'
import { LexUserType, ValidationError, ValidationResult } from '../types'

@@ -5,0 +5,0 @@ export function blob(

import { Lexicons } from '../lexicons'
import {
LexArray,
LexObject,
LexRefVariant,

@@ -10,7 +9,7 @@ LexUserType,

isDiscriminatedObject,
isObj,
} from '../types'
import { toConcreteTypes, toLexUri } from '../util'
import { toLexUri } from '../util'
import { blob } from './blob'
import { boolean, integer, string, bytes, cidLink, unknown } from './primitives'
import { validate as validatePrimitive } from './primitives'

@@ -24,14 +23,2 @@ export function validate(

switch (def.type) {
case 'boolean':
return boolean(lexicons, path, def, value)
case 'integer':
return integer(lexicons, path, def, value)
case 'string':
return string(lexicons, path, def, value)
case 'bytes':
return bytes(lexicons, path, def, value)
case 'cid-link':
return cidLink(lexicons, path, def, value)
case 'unknown':
return unknown(lexicons, path, def, value)
case 'object':

@@ -44,6 +31,3 @@ return object(lexicons, path, def, value)

default:
return {
success: false,
error: new ValidationError(`Unexpected lexicon type: ${def.type}`),
}
return validatePrimitive(lexicons, path, def, value)
}

@@ -110,6 +94,4 @@ }

): ValidationResult {
def = def as LexObject
// type
if (!value || typeof value !== 'object') {
if (!isObj(value)) {
return {

@@ -121,14 +103,12 @@ success: false,

const requiredProps = new Set(def.required)
const nullableProps = new Set(def.nullable)
// properties
let resultValue = value
if (typeof def.properties === 'object') {
if ('properties' in def && def.properties != null) {
for (const key in def.properties) {
if (value[key] === null && nullableProps.has(key)) {
const keyValue = value[key]
if (keyValue === null && def.nullable?.includes(key)) {
continue
}
const propDef = def.properties[key]
if (typeof value[key] === 'undefined' && !requiredProps.has(key)) {
if (keyValue === undefined && !def.required?.includes(key)) {
// Fast path for non-required undefined props.

@@ -140,3 +120,3 @@ if (

) {
if (typeof propDef.default === 'undefined') {
if (propDef.default === undefined) {
continue

@@ -150,16 +130,23 @@ }

const propPath = `${path}/${key}`
const validated = validateOneOf(lexicons, propPath, propDef, value[key])
const propValue = validated.success ? validated.value : value[key]
const propIsUndefined = typeof propValue === 'undefined'
const validated = validateOneOf(lexicons, propPath, propDef, keyValue)
const propValue = validated.success ? validated.value : keyValue
// Return error for bad validation, giving required rule precedence
if (propIsUndefined && requiredProps.has(key)) {
return {
success: false,
error: new ValidationError(`${path} must have the property "${key}"`),
if (propValue === undefined) {
if (def.required?.includes(key)) {
return {
success: false,
error: new ValidationError(
`${path} must have the property "${key}"`,
),
}
}
} else if (!propIsUndefined && !validated.success) {
return validated
} else {
if (!validated.success) {
return validated
}
}
// Adjust value based on e.g. applied defaults, cloning shallowly if there was a changed value
if (propValue !== value[key]) {
if (propValue !== keyValue) {
if (resultValue === value) {

@@ -184,5 +171,4 @@ // Lazy shallow clone

): ValidationResult {
let error
let concreteDef: LexUserType
let concreteDefs
if (def.type === 'union') {

@@ -208,29 +194,13 @@ if (!isDiscriminatedObject(value)) {

} else {
concreteDefs = toConcreteTypes(lexicons, {
type: 'ref',
ref: value.$type,
})
concreteDef = lexicons.getDefOrThrow(value.$type)
}
} else if (def.type === 'ref') {
concreteDef = lexicons.getDefOrThrow(def.ref)
} else {
concreteDefs = toConcreteTypes(lexicons, def)
concreteDef = def
}
for (const concreteDef of concreteDefs) {
const result = mustBeObj
? object(lexicons, path, concreteDef, value)
: validate(lexicons, path, concreteDef, value)
if (result.success) {
return result
}
error ??= result.error
}
if (concreteDefs.length > 1) {
return {
success: false,
error: new ValidationError(
`${path} did not match any of the expected definitions`,
),
}
}
return { success: false, error }
return mustBeObj
? object(lexicons, path, concreteDef, value)
: validate(lexicons, path, concreteDef, value)
}

@@ -247,3 +217,3 @@

if (lexUri.endsWith('#main')) {
return refs.includes(lexUri.replace('#main', ''))
return refs.includes(lexUri.slice(0, -5))
} else {

@@ -250,0 +220,0 @@ return refs.includes(lexUri + '#main')

import { isValidISODateString } from 'iso-datestring-validator'
import { CID } from 'multiformats/cid'
import { ValidationResult, ValidationError } from '../types'
import { validateLanguage } from '@atproto/common-web'
import {
ensureValidAtUri,
ensureValidDid,
ensureValidHandle,
ensureValidNsid,
ensureValidAtUri,
ensureValidTid,
ensureValidRecordKey,
isValidTid,
} from '@atproto/syntax'
import { validateLanguage } from '@atproto/common-web'
import { ValidationError, ValidationResult } from '../types'

@@ -134,13 +134,10 @@ export function datetime(path: string, value: string): ValidationResult {

export function tid(path: string, value: string): ValidationResult {
try {
ensureValidTid(value)
} catch {
return {
success: false,
error: new ValidationError(
`${path} must be a valid TID (timestamp identifier)`,
),
}
if (isValidTid(value)) {
return { success: true, value }
}
return { success: true, value }
return {
success: false,
error: new ValidationError(`${path} must be a valid TID`),
}
}

@@ -147,0 +144,0 @@

@@ -1,14 +0,14 @@

import { utf8Len, graphemeLen } from '@atproto/common-web'
import { CID } from 'multiformats/cid'
import { graphemeLen, utf8Len } from '@atproto/common-web'
import { Lexicons } from '../lexicons'
import * as formats from './formats'
import {
LexUserType,
LexBoolean,
LexBytes,
LexInteger,
LexString,
LexUserType,
ValidationError,
ValidationResult,
ValidationError,
LexBytes,
} from '../types'
import * as formats from './formats'

@@ -42,3 +42,3 @@ export function validate(

export function boolean(
function boolean(
lexicons: Lexicons,

@@ -81,3 +81,3 @@ path: string,

export function integer(
function integer(
lexicons: Lexicons,

@@ -156,3 +156,3 @@ path: string,

export function string(
function string(
lexicons: Lexicons,

@@ -346,3 +346,3 @@ path: string,

export function bytes(
function bytes(
lexicons: Lexicons,

@@ -389,3 +389,3 @@ path: string,

export function cidLink(
function cidLink(
lexicons: Lexicons,

@@ -406,3 +406,3 @@ path: string,

export function unknown(
function unknown(
lexicons: Lexicons,

@@ -409,0 +409,0 @@ path: string,

import { Lexicons } from '../lexicons'
import { LexXrpcParameters, ValidationResult, ValidationError } from '../types'
import { LexXrpcParameters, ValidationError, ValidationResult } from '../types'
import { array } from './complex'
import * as PrimitiveValidators from './primitives'
import { array } from './complex'

@@ -7,0 +6,0 @@ export function params(

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc