Skip to content

Commit

Permalink
Merge magicspace changes (update)
Browse files Browse the repository at this point in the history
  • Loading branch information
vilicvane committed Oct 19, 2023
2 parents c3cea65 + 494b9ae commit c96259b
Show file tree
Hide file tree
Showing 27 changed files with 117 additions and 90 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"extends": ["plugin:@mufan/javascript"],
"overrides": [
{
"files": "**/*.{js,jsx}"
"files": "**/*.{js,mjs}",
"parserOptions": {
"sourceType": "module"
}
},
{
"files": "**/*.cjs",
Expand Down
7 changes: 7 additions & 0 deletions .magicspace/boilerplate.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
"author": "vilicvane",
"type": "module",
"defaultBranch": "master",
"badges": {
"npm": true,
"repo": true,
"coverage": true,
"license": true,
"discord": "https://discord.gg/vanVrDwSkS"
},
"projects": [
{
"name": "library"
Expand Down
3 changes: 3 additions & 0 deletions .magicspace/boilerplate.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
},
"license": {
"type": "boolean"
},
"discord": {
"type": "string"
}
},
"additionalProperties": false
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Magicspace
boilerplate.schema.json
# TypeScript Build Artifacts
bld/
Expand Down
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"files.eol": "\n",
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
"typescript.preferences.importModuleSpecifier": "project-relative",
"typescript.preferences.importModuleSpecifierEnding": "js",
"typescript.tsdk": "node_modules/typescript/lib",
"eslint.workingDirectories": [".", "src/library", "src/node", "src/test"],
"eslint.validate": [
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[![NPM version](https://img.shields.io/npm/v/x-value?color=%23cb3837&style=flat-square)](https://www.npmjs.com/package/x-value)
[![Repository package.json version](https://img.shields.io/github/package-json/v/vilic/x-value?color=%230969da&label=repo&style=flat-square)](./package.json)
[![Coveralls](https://img.shields.io/coveralls/github/vilic/x-value?style=flat-square)](https://coveralls.io/github/vilic/x-value)
[![MIT license](https://img.shields.io/github/license/vilic/x-value?style=flat-square)](./LICENSE)
[![Coverage](https://img.shields.io/coveralls/github/vilic/x-value?style=flat-square)](https://coveralls.io/github/vilic/x-value)
[![MIT License](https://img.shields.io/badge/license-MIT-999999?style=flat-square)](./LICENSE)
[![Discord](https://img.shields.io/badge/chat-discord-5662f6?style=flat-square)](https://discord.gg/vanVrDwSkS)

# X-Value <!-- omit in toc -->

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"tslib": "^2.6.2"
},
"devDependencies": {
"@mufan/eslint-plugin": "^0.2.1",
"@mufan/eslint-plugin": "^0.2.6",
"@types/jest": "^29.5.3",
"@types/lodash.isequal": "^4.5.6",
"@types/node": "^20.4.4",
Expand Down
4 changes: 2 additions & 2 deletions src/library/core/@type-issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ export type TypePath = (
| {key: string | number | symbol}
)[];

export interface TypeIssue {
export type TypeIssue = {
path: TypePath;
deferrable?: true;
message: string;
}
};

export function buildIssueByError(error: unknown, path: TypePath): TypeIssue {
return {
Expand Down
12 changes: 6 additions & 6 deletions src/library/core/json-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export type JSONSchemaType =
| 'array'
| 'object';

export interface JSONSchema {
export type JSONSchema = {
id?: string;
$id?: string;
$schema?: string;
Expand Down Expand Up @@ -117,15 +117,15 @@ export interface JSONSchema {
suggestSortText?: string;
allowComments?: boolean;
allowTrailingCommas?: boolean;
}
};

export interface JSONSchemaMap {
export type JSONSchemaMap = {
[name: string]: JSONSchema;
}
};

export interface JSONSchemaSnippet {
export type JSONSchemaSnippet = {
label?: string;
description?: string;
body?: any; // a object that will be JSON stringified
bodyText?: string; // an already stringified JSON object that can contain new lines (\n) and tabs (\t)
}
};
12 changes: 6 additions & 6 deletions src/library/core/medium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ export type MediumAtomicCodecs<TMediumTypes> = {
[atomicTypeSymbol]?: __MediumAtomicCodec;
};

export interface MediumPacking<TPacked> {
export type MediumPacking<TPacked> = {
pack(unpacked: unknown): TPacked;
unpack(packed: TPacked): unknown;
}
};

export interface MediumOptions<TUsingMedium> {
export type MediumOptions<TUsingMedium> = {
packing?: MediumPacking<UsingMediumPackedType<TUsingMedium>>;
codecs?: MediumAtomicCodecs<TUsingMedium[keyof TUsingMedium]>;
}
};

export class Medium<TUsingMedium extends object = GeneralUsingMedium> {
private packing:
Expand Down Expand Up @@ -94,10 +94,10 @@ export type MediumAtomicCodec<
>;

// eslint-disable-next-line @typescript-eslint/naming-convention
interface __MediumAtomicCodec<TMediumAtomic = unknown, TValue = unknown> {
type __MediumAtomicCodec<TMediumAtomic = unknown, TValue = unknown> = {
encode(value: TValue): TMediumAtomic;
decode(value: unknown): TValue;
}
};

export function medium<TUsingMedium extends object>(
options?: MediumOptions<TUsingMedium>,
Expand Down
1 change: 1 addition & 0 deletions src/library/core/optional-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type OptionalInMediums<TType extends TypeInMediumsPartial> = {
};

declare module './type.js' {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface Type {
optional(): OptionalType<this>;
}
Expand Down
1 change: 1 addition & 0 deletions src/library/core/refined-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export class RefinedType<
}

declare module './type.js' {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface Type<TInMediums, TGeneral> {
refined<TNominalKey extends string | symbol = never, TRefinement = unknown>(
refinements: ElementOrArray<Refinement<TInMediums['value'], TGeneral>>,
Expand Down
4 changes: 2 additions & 2 deletions src/library/core/type-like.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export type TraverseCallback = (
exact: Exact,
) => [unknown, TypeIssue[]];

export interface JSONSchemaData {
export type JSONSchemaData = {
schema: JSONSchema;
optional?: boolean;
}
};
10 changes: 5 additions & 5 deletions src/library/core/type-partials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ export const __type_kind = Symbol('type kind');

export type __type_kind = typeof __type_kind;

export interface TypeKindPartial<TKind extends string = string> {
export type TypeKindPartial<TKind extends string = string> = {
[__type_kind]: TKind;
}
};

export const __type_in_mediums = Symbol('type in mediums');

export type __type_in_mediums = typeof __type_in_mediums;

export type TypeInMediums = Record<XValue.UsingName, unknown>;

export interface TypeInMediumsPartial<
export type TypeInMediumsPartial<
TInMediums extends TypeInMediums = TypeInMediums,
> {
> = {
[__type_in_mediums]: TInMediums;
}
};
4 changes: 2 additions & 2 deletions src/library/mediums/@extended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ const toString = Object.prototype.toString;

const REGEXP_LITERAL_REGEX = /^\/(.*)\/([^/]*)$/;

export interface ExtendedTypes {
export type ExtendedTypes = {
[bigintTypeSymbol]: string;
[dateTypeSymbol]: string;
[regexpTypeSymbol]: string;
}
};

export const EXTENDED_CODECS: MediumAtomicCodecs<ExtendedTypes> = {
[bigintTypeSymbol]: {
Expand Down
4 changes: 2 additions & 2 deletions src/library/mediums/@json-extended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {EXTENDED_CODECS} from './@extended.js';

const toString = Object.prototype.toString;

export interface JSONExtendedTypes extends ExtendedTypes {
export type JSONExtendedTypes = {
[undefinedTypeSymbol]: null;
}
} & ExtendedTypes;

export const JSON_EXTENDED_CODECS: MediumAtomicCodecs<JSONExtendedTypes> = {
...EXTENDED_CODECS,
Expand Down
8 changes: 4 additions & 4 deletions src/library/mediums/ecmascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
voidTypeSymbol,
} from '../types.js';

export interface ECMAScriptTypes {
export type ECMAScriptTypes = {
[neverTypeSymbol]: never;
[unknownTypeSymbol]: unknown;
[undefinedTypeSymbol]: undefined;
Expand All @@ -27,10 +27,10 @@ export interface ECMAScriptTypes {
[functionTypeSymbol]: Function;
[dateTypeSymbol]: Date;
[regexpTypeSymbol]: RegExp;
}
};

export interface UsingECMAScriptMedium {
export type UsingECMAScriptMedium = {
ecmascript: ECMAScriptTypes;
}
};

export const ecmascript = medium<UsingECMAScriptMedium>();
16 changes: 7 additions & 9 deletions src/library/mediums/json-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,26 @@ import type {
import type {JSONExtendedTypes} from './@json-extended.js';
import {JSON_EXTENDED_CODECS} from './@json-extended.js';

export interface JSONValueTypes {
export type JSONValueTypes = {
[neverTypeSymbol]: never;
[unknownTypeSymbol]: unknown;
[nullTypeSymbol]: null;
[stringTypeSymbol]: string;
[numberTypeSymbol]: number;
[booleanTypeSymbol]: boolean;
}
};

export interface UsingJSONValueMedium {
export type UsingJSONValueMedium = {
'json-value': JSONValueTypes;
}
};

export const jsonValue = medium<UsingJSONValueMedium>();

export interface ExtendedJSONValueTypes
extends JSONValueTypes,
JSONExtendedTypes {}
export type ExtendedJSONValueTypes = {} & JSONValueTypes & JSONExtendedTypes;

export interface UsingExtendedJSONValueMedium {
export type UsingExtendedJSONValueMedium = {
'extended-json-value': ExtendedJSONValueTypes;
}
};

export const extendedJSONValue = jsonValue.extend<UsingExtendedJSONValueMedium>(
{
Expand Down
14 changes: 7 additions & 7 deletions src/library/mediums/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import {medium} from '../core/index.js';
import type {JSONExtendedTypes} from './@json-extended.js';
import {JSON_EXTENDED_CODECS} from './@json-extended.js';

export interface JSONTypes {
export type JSONTypes = {
packed: string;
}
};

export interface UsingJSONMedium {
export type UsingJSONMedium = {
json: JSONTypes;
}
};

export const json = medium<UsingJSONMedium>({
packing: {
Expand All @@ -22,11 +22,11 @@ export const json = medium<UsingJSONMedium>({
},
});

export interface ExtendedJSONTypes extends JSONTypes, JSONExtendedTypes {}
export type ExtendedJSONTypes = {} & JSONTypes & JSONExtendedTypes;

export interface UsingExtendedJSONMedium {
export type UsingExtendedJSONMedium = {
'extended-json': ExtendedJSONTypes;
}
};

export const extendedJSON = json.extend<UsingExtendedJSONMedium>({
codecs: JSON_EXTENDED_CODECS,
Expand Down
16 changes: 7 additions & 9 deletions src/library/mediums/query-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {EXTENDED_CODECS} from './@extended.js';

const toString = Object.prototype.toString;

export interface QueryStringTypes {
export type QueryStringTypes = {
packed: string;
}
};

export interface UsingQueryStringMedium {
export type UsingQueryStringMedium = {
'query-string': QueryStringTypes;
}
};

export const queryString = medium<UsingQueryStringMedium>({
packing: {
Expand Down Expand Up @@ -59,13 +59,11 @@ export const queryString = medium<UsingQueryStringMedium>({
},
});

export interface ExtendedQueryStringTypes
extends QueryStringTypes,
ExtendedTypes {}
export type ExtendedQueryStringTypes = QueryStringTypes & ExtendedTypes;

export interface UsingExtendedQueryStringMedium {
export type UsingExtendedQueryStringMedium = {
'extended-query-string': ExtendedQueryStringTypes;
}
};

export const extendedQueryString =
queryString.extend<UsingExtendedQueryStringMedium>({
Expand Down
2 changes: 2 additions & 0 deletions src/library/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const toString = Object.prototype.toString;

declare global {
namespace XValue {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface Types {
[neverTypeSymbol]: never;
[unknownTypeSymbol]: unknown;
Expand All @@ -20,6 +21,7 @@ declare global {
[regexpTypeSymbol]: RegExp;
}

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface Using {
value: Types;
}
Expand Down
8 changes: 4 additions & 4 deletions src/library/x-utils/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export const Integer = number.refined<'integer'>(

export type Integer = TypeOf<typeof Integer>;

export interface IntegerRangeOptions {
export type IntegerRangeOptions = {
min?: number;
max?: number;
}
};

export function integerRange<TNominalKey extends string | symbol = never>({
min = -Infinity,
Expand All @@ -42,12 +42,12 @@ export function integerRange<TNominalKey extends string | symbol = never>({
);
}

export interface NumberRangeOptions {
export type NumberRangeOptions = {
minInclusive?: number;
minExclusive?: number;
maxInclusive?: number;
maxExclusive?: number;
}
};

export function numberRange<TNominalKey extends string | symbol = never>({
minInclusive = -Infinity,
Expand Down
Loading

0 comments on commit c96259b

Please sign in to comment.