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
2
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.0.2 to 0.0.3

dist/lexicons.d.ts

128

dist/index.d.ts

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

import { ValidateFunction } from 'ajv';
import { AdxSchemaDefinition } from './types.js';
declare type SomeObject = Record<string, unknown>;
export interface AdxRecordValidatorDescription {
type: string | string[];
ext?: string | string[];
}
export * from './types.js';
/**
* A compiled schema.
*/
export declare class AdxSchema {
def: AdxSchemaDefinition;
id: string;
validateRecord?: ValidateFunction;
validateParams?: ValidateFunction;
validateResponse?: ValidateFunction;
get name(): string;
constructor(def: AdxSchemaDefinition);
}
/**
* A collection of compiled schemas.
*/
export declare class AdxSchemas {
schemas: Map<string, AdxSchema>;
private _locale;
get locale(): string;
set locale(v: string);
/**
* Add a schema definition.
*/
add(schemaDef: unknown): void;
/**
* Remove a schema definition.
*/
remove(key: string): void;
/**
* Get a schema definition.
*/
get(key: string): AdxSchema | undefined;
/**
* Create a record validator out of one or more schemas.
*/
createRecordValidator(desc: string | string[] | AdxRecordValidatorDescription): AdxRecordValidator;
/**
* Create a view validator out of a schema.
*/
createViewValidator(view: string): AdxViewValidator;
}
/**
* Validates records using schemas.
*/
export declare class AdxRecordValidator {
private schemas;
type: AdxSchema[];
ext: AdxSchema[];
constructor(schemas: AdxSchemas, type: AdxSchema[], ext: AdxSchema[]);
/**
* Returns detailed information about validity and compatibility.
*/
validate(value: SomeObject): AdxValidationResult;
/**
* Provides a simple boolean check of validity.
*/
isValid(value: any): boolean;
/**
* Like validate() but throws if validation fails.
*/
assertValid(value: any): AdxValidationResult;
}
/**
* Validates views using schemas.
*/
export declare class AdxViewValidator {
view: AdxSchema;
constructor(view: AdxSchema);
/**
* Returns detailed information about validity and compatibility.
*/
validateResponse(value: SomeObject): AdxValidationResult;
/**
* Provides a simple boolean check of validity.
*/
isResponseValid(value: any): boolean;
/**
* Like validateResponse() but throws if validation fails.
*/
assertResponseValid(value: any): AdxValidationResult;
}
export declare enum AdxValidationResultCode {
Full = "full",
Partial = "partial",
Incompatible = "incompatible",
Invalid = "invalid"
}
export declare class AdxValidationResult {
code: AdxValidationResultCode;
/**
* The error message (if fatal)
*/
error: string | undefined;
/**
* A collection of all fallback messages
*/
fallbacks: string[];
/**
* A collection of all messages
*/
messages: string[];
get valid(): boolean;
get fullySupported(): boolean;
get incompatible(): boolean;
/**
* Internal - used to transition the state machine.
*/
_t(to: AdxValidationResultCode, message?: string): void;
/**
* Internal - used to transition the state machine.
*/
_fail(schema: AdxSchema, validator: ValidateFunction): void;
}
export declare class AdxValidationError extends Error {
code: AdxValidationResultCode;
messages: string[];
constructor(res: AdxValidationResult);
}
export * from './types';
export * from './lexicons';
{
"name": "@atproto/lexicon",
"version": "0.0.2",
"main": "src/index.ts",
"version": "0.0.3",
"main": "dist/index.js",
"scripts": {

@@ -14,3 +14,7 @@ "test": "jest",

"build": "node ./build.js",
"postbuild": "tsc --build tsconfig.build.json"
"postbuild": "tsc --build tsconfig.build.json",
"update-main-to-dist": "node ./update-pkg.js --update-main-to-dist",
"update-main-to-src": "node ./update-pkg.js --update-main-to-src",
"prepublish": "npm run update-main-to-dist",
"postpublish": "npm run update-main-to-src"
},

@@ -20,4 +24,5 @@ "license": "MIT",

"@atproto/nsid": "*",
"iso-datestring-validator": "^2.2.2",
"zod": "^3.14.2"
}
}

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

import { isValidISODateString } from 'iso-datestring-validator'
import { Lexicons } from '../lexicons'

@@ -271,4 +272,3 @@ import {

try {
const date = new Date(Date.parse(value as string))
if (value !== date.toISOString()) {
if (typeof value !== 'string' || !isValidISODateString(value)) {
throw new ValidationError(

@@ -275,0 +275,0 @@ `${path} must be an iso8601 formatted datetime`,

@@ -379,2 +379,19 @@ export default [

},
{
lexicon: 1,
id: 'com.example.datetime',
defs: {
main: {
type: 'record',
record: {
type: 'object',
properties: {
datetime: {
type: 'datetime',
},
},
},
},
},
},
]

@@ -516,18 +516,22 @@ import { Lexicons } from '../src/index'

it('Applies datetime formatting constraint', () => {
for (const datetime of [
'2022-12-12T00:50:36.809Z',
'2022-12-12T00:50:36Z',
'2022-12-12T00:50:36.8Z',
'2022-12-12T00:50:36.80Z',
'2022-12-12T00:50:36+00:00',
'2022-12-12T00:50:36.8+00:00',
'2022-12-11T19:50:36-05:00',
'2022-12-11T19:50:36.8-05:00',
'2022-12-11T19:50:36.80-05:00',
'2022-12-11T19:50:36.809-05:00',
]) {
lex.assertValidRecord('com.example.datetime', {
$type: 'com.example.datetime',
datetime,
})
}
expect(() =>
lex.assertValidRecord('com.example.kitchenSink', {
$type: 'com.example.kitchenSink',
object: {
object: { boolean: true },
array: ['one', 'two'],
boolean: true,
number: 123.45,
integer: 123,
string: 'string',
},
array: ['one', 'two'],
boolean: true,
number: 123.45,
integer: 123,
string: 'string',
lex.assertValidRecord('com.example.datetime', {
$type: 'com.example.datetime',
datetime: 'bad date',

@@ -534,0 +538,0 @@ }),

{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist", // Your outDir,

@@ -5,0 +6,0 @@ "emitDeclarationOnly": true

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 too big to display

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