New:Microsoft Teams Notifications Are Now Available in Socket.Learn more →
Get Started

@amritk/helpers

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@amritk/helpers

Shared utilities for the mjst code generation ecosystem.

Source
npmnpm
Version
0.23.2
Version published
Weekly downloads
20K
101.49%
Maintainers
1
Weekly downloads
 
Created
Source

@amritk/helpers

Shared schema-traversal and runtime helpers for the mjst code generation ecosystem.

status  version  license  JSON Schema  node  vibe coded

Overview

@amritk/helpers is the shared utility belt used by mjst's generators and by the runtime code those generators produce. Each helper is published as its own subpath export so consumers (and generated output) only pull in what they need — no barrel, no incidental dependencies.

Installation

npm install @amritk/helpers
# or
pnpm add @amritk/helpers
# or
yarn add @amritk/helpers
# or
bun add @amritk/helpers

Modules

Schema traversal

SubpathExportsPurpose
@amritk/helpers/extract-refsextractRefsCollect every $ref reachable from a schema.
@amritk/helpers/resolve-refresolveRefResolve a $ref — JSON Pointer, $anchor name, or URI — against a root schema.
@amritk/helpers/build-anchor-mapbuildAnchorMapBuild a map of $anchor / $dynamicAnchor name → JSON Pointer.
@amritk/helpers/build-dynamic-ref-mapbuildDynamicRefMapBuild a map of $dynamicAnchor → resolved location.
@amritk/helpers/resolve-dynamic-refsresolveDynamicRefsReplace $dynamicRef occurrences using the map above.
@amritk/helpers/assert-id-scopesassertIdScopesReject a document whose $id-scoped fragment ref resolves to nothing in its own resource.
@amritk/helpers/max-schema-depthMAX_SCHEMA_DEPTH, assertSchemaDepthThe nesting cap every recursive walker enforces.
@amritk/helpers/upgrade-draft07-schemaupgradeDraft07Schema, isDraft07SchemaUpgrade a Draft-07 schema to 2020-12.
@amritk/helpers/ref-to-filenamerefToFilename, toKebabCaseConvert a $ref to a stable filename.
@amritk/helpers/ref-to-namerefToNameConvert a $ref to a TypeScript identifier (PascalCase).
@amritk/helpers/walk-ref-graphwalkRefGraph, RefNodeThe shared $ref-graph traversal every generator runs: upgrades draft-07, resolves each ref, rewrites $dynamicRef, derives type/file names, and hands one pre-computed node per output file to a visit callback.
@amritk/helpers/build-resource-registrybuildResourceRegistry, ResourceRegistryRead a document's $id base-URI scopes once, expressed as JSON Pointers.
@amritk/helpers/normalize-ref-scopesnormalizeRefScopesRewrite every $ref / $dynamicRef to a plain root-relative JSON Pointer, applying the $id bases in scope.
@amritk/helpers/resolve-scoped-refresolveScopedRef, ScopedRefTargetWhere a $ref lands once the $id bases in scope are applied.
@amritk/helpers/graft-external-schemasgraftExternalSchemas, GraftedSchemaFold already-loaded external documents into the document being generated so cross-document refs resolve like local ones.
@amritk/helpers/prune-external-schemaspruneExternalSchemasDrop the grafted documents nothing references.
@amritk/helpers/extract-dynamic-anchor-defsextractDynamicAnchorDefsCollect a #/... ref for every subschema carrying a $dynamicAnchor.
@amritk/helpers/fold-nullablefoldNullableRewrite OpenAPI 3.0 nullable: true into a null member of type.
@amritk/helpers/derive-root-type-namederiveRootTypeNameTurn a schema title into a PascalCase root type name.
@amritk/helpers/read-keyreadKey, declaresKeyRead an author-chosen name ($defs entry, config key) off a map, treating inherited names such as __proto__ as absent.
@amritk/helpers/assign-keyassignKeyAssign a key on a rebuilt object without letting __proto__ reach the prototype setter.
@amritk/helpers/schema-guardsisSchemaObject, hasType, hasProperties, hasOneOf, hasAnyOf, hasAllOf, hasEnum, hasConst, hasPattern, hasFormat, hasDefault, hasExamples, hasRequired, hasItems, hasAdditionalProperties, hasMinLength, hasMaxLength, hasMinimum, hasMaximum, hasExclusiveMinimum, hasExclusiveMaximum, hasMultipleOf, hasMinItems, hasMaxItems, hasUniqueItems, hasMinProperties, hasMaxProperties, …Type-narrowing predicates for JSON Schema keywords.

Codegen utilities

SubpathExportsPurpose
@amritk/helpers/generate-type-definitiongenerateTypeDefinitionRender a TypeScript type from a schema node.
@amritk/helpers/mjst-extensionMJST_EXTENSION_KEY, getMjstInstanceOf, getMjstPrimitive, getMjstBrandRead the x-mjst vendor hints (instanceOf, primitive, brand) a schema carries.
@amritk/helpers/generate-index-barrelgenerateIndexBarrelRender the index.ts barrel that re-exports every generated file.
@amritk/helpers/escape-regex-patternescapeRegexPattern, regexFlagsFor, regexLiteralEmbed a JSON Schema pattern in a generated regex literal, validating it at generation time.
@amritk/helpers/quote-js-stringquoteJsStringQuote a string as a JS literal, escaping only when needed.
@amritk/helpers/multiple-of-checkmultipleOfPassExpr, multipleOfFailExprEmit a multipleOf check that agrees with the runtime interpreter.
@amritk/helpers/numeric-bound-checkboundPassExpr, boundFailExpr, boundOperatorEmit minimum / maximum / exclusive* checks that agree with the runtime interpreter.
@amritk/helpers/string-length-checkminLengthPassExpr, maxLengthPassExpr, …Emit minLength / maxLength checks that count code points, not UTF-16 units.
@amritk/helpers/unknown-key-checkunknownKeyCheck, INLINE_KEY_LIMITEmit an unknown-key sweep — inline comparisons for small key sets, a hoisted Set past the limit.
@amritk/helpers/parse-documentationparseDocumentation, ObjectDocumentationParse one section of the OpenAPI specification markdown (selected by a commentUrl fragment such as #info-object) into a title, description, and per-property descriptions.
@amritk/helpers/safe-accessorsafeAccessor, hasOwnCheck, missingCheck, safeKeyEmit a safe JS property-access expression (dot vs bracket notation, own-property guard for Object.prototype names).

Runtime helpers (also copied into generated output)

SubpathExportsPurpose
@amritk/helpers/is-objectisObjectNarrow unknown → Record<string, unknown>.
@amritk/helpers/has-refhasRefNarrow a value to an object carrying a string $ref.
@amritk/helpers/validate-arrayvalidateArrayValidate array shape and items.
@amritk/helpers/validate-recordvalidateRecordValidate record shape and additional properties.

Usage

import { resolveRef } from '@amritk/helpers/resolve-ref'
import { isObjectSchema, hasProperties } from '@amritk/helpers/schema-guards'

const node = resolveRef('#/$defs/info', rootSchema)

if (isObjectSchema(node) && hasProperties(node)) {
  for (const [name, property] of Object.entries(node.properties)) {
    // ...
  }
}

Most helpers have a colocated test file (*.test.ts) — read those for canonical examples.

License

MIT

Keywords

json-schema

FAQs

Package last updated on 23 Sep 2026

Related posts