Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nmtjs/type

Package Overview
Dependencies
Maintainers
0
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nmtjs/type - npm Package Compare versions

Comparing version 0.4.2 to 0.4.3

4

dist/constants.js

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

export const typeStatic = Symbol();
export const typeSchema = Symbol();
export const typeStatic = Symbol.for('neemataType:typeStatic');
export const typeSchema = Symbol.for('neemataType:typeSchema');

@@ -15,4 +15,2 @@ import { ArrayType } from "./types/array.js";

register();
export * from "./schemas/native-enum.js";
export * from "./schemas/union-enum.js";
export * from "./schemas/nullable.js";

@@ -19,0 +17,0 @@ export { BaseType, getTypeSchema } from "./types/base.js";

import { Type } from '@sinclair/typebox/type';
export const Nullable = (schema, options = {})=>Type.Union([
export const Nullable = (schema, options = {})=>{
const { default: _default, description, examples, readOnly, title, writeOnly } = schema;
return Type.Union([
schema,
Type.Null()
], options);
], {
default: _default,
description,
examples,
readOnly,
title,
writeOnly,
...options
});
};

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

import { NativeEnum } from "../schemas/native-enum.js";
import { UnionEnum } from "../schemas/union-enum.js";
import { Enum } from '@sinclair/typebox';
import { BaseType } from "./base.js";

@@ -11,3 +10,3 @@ export class ObjectEnumType extends BaseType {

_constructSchema(options, values) {
return NativeEnum(values, options);
return Enum(values, options);
}

@@ -60,3 +59,6 @@ nullable() {

_constructSchema(options, values) {
return UnionEnum(values, options);
return Enum(Object.fromEntries(values.map((k)=>[
k,
k
])), options);
}

@@ -63,0 +65,0 @@ nullable() {

import { Type } from '@sinclair/typebox';
import { BaseType, getTypeSchema } from "./base.js";
import { EnumType, ObjectEnumType } from "./enum.js";
import { EnumType } from "./enum.js";
export class ObjectType extends BaseType {

@@ -100,11 +100,3 @@ properties;

_constructSchema(options, key, element) {
let keySchema;
if (key instanceof EnumType) {
keySchema = Type.Union(key.values.map((value)=>Type.Literal(value)));
} else if (key instanceof ObjectEnumType) {
keySchema = Type.Union(Object.values(key.values).map((value)=>Type.Literal(value)));
} else {
keySchema = getTypeSchema(key);
}
return Type.Record(keySchema, getTypeSchema(element), options);
return Type.Record(getTypeSchema(key), getTypeSchema(element), options);
}

@@ -111,0 +103,0 @@ nullable() {

@@ -24,3 +24,3 @@ {

"temporal-polyfill": "^0.2.5",
"@nmtjs/common": "0.4.2"
"@nmtjs/common": "0.4.3"
},

@@ -30,3 +30,3 @@ "devDependencies": {

"temporal-polyfill": "^0.2.5",
"@nmtjs/common": "0.4.2"
"@nmtjs/common": "0.4.3"
},

@@ -40,3 +40,3 @@ "files": [

],
"version": "0.4.2",
"version": "0.4.3",
"scripts": {

@@ -43,0 +43,0 @@ "build": "neemata-build -p neutral --root=./src './**/*.ts'",

@@ -1,5 +0,5 @@

export const typeStatic: unique symbol = Symbol()
export const typeStatic: unique symbol = Symbol.for('neemataType:typeStatic')
export type typeStatic = typeof typeStatic
export const typeSchema: unique symbol = Symbol()
export const typeSchema: unique symbol = Symbol.for('neemataType:typeSchema')
export type typeSchema = typeof typeSchema

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

import type { TLiteralValue } from '@sinclair/typebox'
import type { TLiteralValue } from '@sinclair/typebox/type'
import { ArrayType } from './types/array.ts'

@@ -31,4 +31,2 @@ import type { BaseType } from './types/base.ts'

export * from './schemas/native-enum.ts'
export * from './schemas/union-enum.ts'
export * from './schemas/nullable.ts'

@@ -35,0 +33,0 @@ export {

@@ -13,2 +13,21 @@ import {

options: SchemaOptions = {},
) => Type.Union([schema, Type.Null()], options)
) => {
const {
default: _default,
description,
examples,
readOnly,
title,
writeOnly,
} = schema
return Type.Union([schema, Type.Null()], {
default: _default,
description,
examples,
readOnly,
title,
writeOnly,
...options,
})
}

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

import type { SchemaOptions } from '@sinclair/typebox'
import type { TNativeEnum } from '../schemas/native-enum.ts'
import { NativeEnum } from '../schemas/native-enum.ts'
import { type TUnionEnum, UnionEnum } from '../schemas/union-enum.ts'
import { Enum, type SchemaOptions, type TEnum } from '@sinclair/typebox'
import { BaseType } from './base.ts'

@@ -14,5 +11,5 @@

D extends boolean = false,
> extends BaseType<TNativeEnum<T>, N, O, D> {
> extends BaseType<TEnum<T>, N, O, D> {
constructor(
readonly values: T,
private readonly values: T,
options: SchemaOptions = {},

@@ -26,7 +23,4 @@ isNullable: N = false as N,

protected _constructSchema(
options: SchemaOptions,
values: T,
): TNativeEnum<T> {
return NativeEnum(values, options)
protected _constructSchema(options: SchemaOptions, values: T): TEnum<T> {
return Enum(values, options)
}

@@ -71,3 +65,3 @@

export type AnyEnumType = EnumType<any[], boolean, boolean, boolean>
export type AnyEnumType = EnumType<any, boolean, boolean, boolean>
export class EnumType<

@@ -78,5 +72,5 @@ T extends (string | number)[] = (string | number)[],

D extends boolean = false,
> extends BaseType<TUnionEnum<T>, N, O, D> {
> extends BaseType<TEnum<Record<string, T[number]>>, N, O, D> {
constructor(
readonly values: [...T],
private readonly values: [...T],
options: SchemaOptions = {},

@@ -93,4 +87,4 @@ isNullable: N = false as N,

values: [...T],
): TUnionEnum<T> {
return UnionEnum(values, options)
): TEnum<Record<string, T[number]>> {
return Enum(Object.fromEntries(values.map((k) => [k, k])), options)
}

@@ -97,0 +91,0 @@

@@ -5,3 +5,2 @@ import {

type TRecord,
type TSchema,
Type,

@@ -12,8 +11,3 @@ } from '@sinclair/typebox'

import { BaseType, getTypeSchema } from './base.ts'
import {
type AnyEnumType,
type AnyObjectEnumType,
EnumType,
ObjectEnumType,
} from './enum.ts'
import { type AnyEnumType, type AnyObjectEnumType, EnumType } from './enum.ts'
import type { AnyLiteralType } from './literal.ts'

@@ -181,16 +175,4 @@ import type { AnyStringType } from './string.ts'

protected _constructSchema(options: ObjectOptions, key: K, element: E) {
let keySchema: TSchema
if (key instanceof EnumType) {
keySchema = Type.Union(key.values.map((value) => Type.Literal(value)))
} else if (key instanceof ObjectEnumType) {
keySchema = Type.Union(
Object.values(key.values).map((value) => Type.Literal(value as string)),
)
} else {
keySchema = getTypeSchema(key)
}
return Type.Record(
keySchema,
getTypeSchema(key),
getTypeSchema(element),

@@ -197,0 +179,0 @@ options,

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