Socket
Socket
Sign inDemoInstall

@ark/schema

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ark/schema - npm Package Compare versions

Comparing version 0.7.0 to 0.8.0

2

out/generic.d.ts

@@ -43,3 +43,2 @@ import { Callable, type array, type Hkt, type Json } from "@ark/util";

defIsLazy(): this is GenericRoot<params, LazyGenericBody>;
bindScope($: BaseScope): this;
protected cacheGetter<name extends keyof this>(name: name, value: this[name]): this[name];

@@ -55,2 +54,3 @@ get json(): Json;

get internal(): this;
get referencesById(): Record<string, BaseNode>;
get references(): BaseNode[];

@@ -57,0 +57,0 @@ }

@@ -38,7 +38,2 @@ import { Callable, flatMorph, snapshot, throwParseError } from "@ark/util";

}
bindScope($) {
if (this.arg$ === $)
return this;
return new GenericRoot(this.params, this.bodyDef, this.$, $);
}
cacheGetter(name, value) {

@@ -68,2 +63,5 @@ Object.defineProperty(this, name, { value });

}
get referencesById() {
return this.baseInstantiation.internal.referencesById;
}
get references() {

@@ -70,0 +68,0 @@ return this.baseInstantiation.internal.references;

@@ -11,4 +11,6 @@ import { DynamicBase, flatMorph } from "@ark/util";

alias,
hasArkKind(value, "module") ? bindModule(value, $) : value.bindScope($)
hasArkKind(value, "module") ?
bindModule(value, $)
: $.bindReference(value)
]));
export const SchemaModule = RootModule;

@@ -22,3 +22,2 @@ import { Callable, type Guardable, type Json, type Key, type array, type conform, type listable, type mutable } from "@ark/util";

constructor(attachments: UnknownAttachments, $: BaseScope);
bindScope($: BaseScope): this;
withMeta(meta: ArkEnv.meta | ((currentMeta: ArkEnv.meta) => ArkEnv.meta)): this;

@@ -25,0 +24,0 @@ abstract traverseAllows: TraverseAllows<d["prerequisite"]>;

@@ -29,7 +29,2 @@ import { Callable, appendUnique, flatMorph, includes, isArray, isEmptyObject, throwError } from "@ark/util";

}
bindScope($) {
if (this.$ === $)
return this;
return new this.constructor(this.attachments, $);
}
withMeta(meta) {

@@ -36,0 +31,0 @@ const newMeta = typeof meta === "function" ?

@@ -22,3 +22,3 @@ import { implementNode } from "../shared/implement.js";

// avoid default message like "must be non-empty (was 0)"
actual: data => (data.length === 0 ? null : `${data.length}`)
actual: data => (data.length === 0 ? "" : `${data.length}`)
},

@@ -25,0 +25,0 @@ intersections: {

@@ -50,3 +50,3 @@ import { type array, type listable, type show } from "@ark/util";

refinements: array<nodeOfKind<RefinementKind>>;
expression: string;
get expression(): string;
get shortDescription(): string;

@@ -53,0 +53,0 @@ protected innerToJsonSchema(): JsonSchema;

@@ -136,5 +136,10 @@ import { flatMorph, hasDomain, isEmptyObject, isKeyOf, throwParseError } from "@ark/util";

refinements = this.children.filter(node => node.isRefinement());
expression = this.structure?.expression ||
`${this.basis ? this.basis.nestableExpression + " " : ""}${this.refinements.join(" & ")}` ||
"unknown";
get expression() {
let expression = this.structure?.expression ||
`${this.basis ? this.basis.nestableExpression + " " : ""}${this.refinements.join(" & ")}` ||
"unknown";
if (expression === "Array == 0")
expression = "[]";
return this.cacheGetter("expression", expression);
}
get shortDescription() {

@@ -141,0 +146,0 @@ return this.basis?.shortDescription ?? "present";

@@ -317,9 +317,9 @@ import { includes, inferred, omit, throwInternalError, throwParseError } from "@ark/util";

(branch.basis?.domain === "object" ?
$ark.intrinsic.emptyStructure.bindScope(branch.$)
branch.$.bindReference($ark.intrinsic.emptyStructure)
: null));
}
if (branch.isBasis() && branch.domain === "object")
return $ark.intrinsic.emptyStructure.bindScope(branch.$);
return branch.$.bindReference($ark.intrinsic.emptyStructure);
return null;
};
export const writeNonStructuralOperandMessage = (operation, operand) => `${operation} operand must be an object (was ${operand})`;

@@ -70,3 +70,4 @@ import { domainDescriptions, domainOf, printable, throwParseError } from "@ark/util";

data => data instanceof Date && data.toISOString() === this.compiledValue
: data => data === this.unit;
: Number.isNaN(this.unit) ? data => Number.isNaN(data)
: data => data === this.unit;
}

@@ -82,3 +83,5 @@ export const Unit = {

}
if (Number.isNaN(unit))
return `${negated ? "!" : ""}Number.isNaN(data)`;
return `data ${negated ? "!" : "="}== ${serializedValue}`;
};

@@ -65,2 +65,3 @@ import { ParseError, type Json, type anyOrNever, type array, type conform, type flattenListable, type listable, type noSuggest } from "@ark/util";

node: <kinds extends NodeKind | array<RootKind>, prereduced extends boolean = false>(kinds: kinds, nodeSchema: NodeSchema<flattenListable<kinds>>, opts?: NodeParseOptions<prereduced>) => nodeOfKind<prereduced extends true ? flattenListable<kinds> : reducibleKindOf<flattenListable<kinds>>>;
bindReference<reference extends BaseNode | GenericRoot>(reference: reference): reference;
protected finalizeRootArgs(opts: NodeParseOptions, resolve: () => BaseRoot): NodeParseOptions;

@@ -67,0 +68,0 @@ resolveRoot(name: string): BaseRoot;

@@ -90,3 +90,3 @@ import { ParseError, flatMorph, hasDomain, isArray, printable, throwInternalError, throwParseError } from "@ark/util";

if (isNode(schema) && schema.kind === kind)
return schema.bindScope(this);
return schema;
if (kind === "alias" && !opts?.prereduced) {

@@ -110,3 +110,3 @@ const resolution = this.resolveRoot(normalizeAliasSchema(schema).alias);

return normalizedSchema.kind === kind ?
normalizedSchema.bindScope(this)
normalizedSchema
: throwMismatchedNodeRootError(kind, normalizedSchema.kind);

@@ -126,8 +126,15 @@ }

const preparsed = this.preparseNode(kinds, nodeSchema, opts);
const node = isNode(preparsed) ? preparsed : parseNode(preparsed).bindScope(this);
const node = isNode(preparsed) ? preparsed : parseNode(preparsed);
return this.bindReference(node);
};
bindReference(reference) {
const bound = reference.$ === this ? reference
: isNode(reference) ?
new reference.constructor(reference.attachments, this)
: new GenericRoot(reference.params, reference.bodyDef, reference.$, this);
if (this.resolved) {
// this node was not part of the original scope, so compile an anonymous scope
// including only its references
if (!this.resolvedConfig.jitless)
bindCompiledScope(node.references);
if (!bound.jit && !this.resolvedConfig.jitless)
bindCompiledScope(bound.references);
}

@@ -137,6 +144,6 @@ else {

// add the node as a reference
Object.assign(this.referencesById, node.referencesById);
Object.assign(this.referencesById, bound.referencesById);
}
return node;
};
return bound;
}
finalizeRootArgs(opts, resolve) {

@@ -171,3 +178,3 @@ const isResolution = opts.alias && opts.alias in this.aliases;

this.node("alias", { alias: resolution }, { prereduced: true })
: (resolution ?? this.maybeResolveSubalias(name));
: resolution;
}

@@ -191,6 +198,6 @@ /** If name is a valid reference to a submodule alias, return its resolution */

if (hasArkKind(preparsed, "generic"))
return (this.resolutions[name] = preparsed.bindScope(this));
return (this.resolutions[name] = this.bindReference(preparsed));
if (hasArkKind(preparsed, "module")) {
if (preparsed.root)
return (this.resolutions[name] = preparsed.root.bindScope(this));
return (this.resolutions[name] = this.bindReference(preparsed.root));
else

@@ -200,5 +207,5 @@ return throwParseError(writeMissingSubmoduleAccessMessage(name));

this.resolutions[name] = name;
return (this.resolutions[name] = this.parseRoot(preparsed, {
return (this.resolutions[name] = this.bindReference(this.parseRoot(preparsed, {
alias: name
}).bindScope(this));
})));
}

@@ -205,0 +212,0 @@ import(...names) {

@@ -17,3 +17,3 @@ import { CastableBase, ReadonlyArray, type propwiseXor, type show } from "@ark/util";

get expected(): string;
get actual(): string | null;
get actual(): string;
get problem(): string;

@@ -42,3 +42,3 @@ get message(): string;

expected: string;
actual: string | null;
actual: string;
problem: string;

@@ -72,3 +72,3 @@ message: string;

export type ExpectedWriter<code extends ArkErrorCode = ArkErrorCode> = (source: errorContext<code>) => string;
export type ActualWriter<code extends ArkErrorCode = ArkErrorCode> = (data: getAssociatedDataForError<code>) => string | null;
export type ActualWriter<code extends ArkErrorCode = ArkErrorCode> = (data: getAssociatedDataForError<code>) => string;
export {};

@@ -34,7 +34,3 @@ import { CastableBase, ReadonlyArray, defineProperties } from "@ark/util";

get actual() {
// null is a valid value of actual meaning it should be omitted, so
// check for undefined explicitly
return this.input.actual !== undefined ?
this.input.actual
: this.nodeConfig.actual?.(this.data);
return this.input.actual ?? this.nodeConfig.actual?.(this.data);
}

@@ -41,0 +37,0 @@ get problem() {

@@ -59,7 +59,13 @@ import { flatMorph, printable, throwParseError } from "@ark/util";

export const defaultValueSerializer = (v) => {
if (typeof v === "string" ||
typeof v === "boolean" ||
typeof v === "number" ||
v === null)
if (typeof v === "string" || typeof v === "boolean" || v === null)
return v;
if (typeof v === "number") {
if (Number.isNaN(v))
return "NaN";
if (v === Number.POSITIVE_INFINITY)
return "Infinity";
if (v === Number.NEGATIVE_INFINITY)
return "-Infinity";
return v;
}
return compileSerializedValue(v);

@@ -66,0 +72,0 @@ };

@@ -348,3 +348,3 @@ import { append, flatMorph, printable, spliterate, throwParseError } from "@ark/util";

if (this.undeclared === "reject")
ctx.error({ expected: "removed", actual: null, relativePath: [k] });
ctx.error({ expected: "removed", actual: "", relativePath: [k] });
else {

@@ -410,3 +410,3 @@ ctx.queueMorphs([

js
.line(`ctx.error({ expected: "removed", actual: null, relativePath: [k] })`)
.line(`ctx.error({ expected: "removed", actual: "", relativePath: [k] })`)
.if("ctx.failFast", () => js.return())

@@ -413,0 +413,0 @@ : js.line(`ctx.queueMorphs([data => { delete data[k]; return data }])`);

{
"name": "@ark/schema",
"version": "0.7.0",
"version": "0.8.0",
"license": "MIT",

@@ -32,3 +32,3 @@ "author": {

"dependencies": {
"@ark/util": "0.7.0"
"@ark/util": "0.8.0"
},

@@ -35,0 +35,0 @@ "publishConfig": {

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