Skip to content

Commit

Permalink
TypeScript v5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
surol committed Jun 29, 2024
1 parent 5d70575 commit 957d94c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 65 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"@proc7ts/async": "^2.1.0",
"@run-z/eslint-config": "^4.0.0",
"@run-z/prettier-config": "^2.0.0",
"@run-z/project-config": "^0.20.2",
"@run-z/project-config": "^0.20.3",
"@swc/core": "^1.6.5",
"@swc/jest": "^0.2.36",
"@typescript-eslint/eslint-plugin": "^7.14.1",
Expand All @@ -100,7 +100,7 @@
"ts-jest": "^29.1.5",
"tslib": "^2.6.3",
"typedoc": "^0.26.3",
"typescript": "~5.4.5"
"typescript": "~5.5.2"
},
"imports": {
"#churi/core.js": {
Expand Down
4 changes: 4 additions & 0 deletions src/schema/meta/uc-meta.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ describe('UcMeta', () => {
expect(frozen).not.toBe(meta);
expect(meta.isFrozen()).toBe(false);
expect(meta.isMutable()).toBe(true);
expect(meta.mutability).toBe('mutable');
expect(frozen.isFrozen()).toBe(true);
expect(frozen.isMutable()).toBe(false);
expect(frozen.mutability).toBe('frozen');
expect(frozen.get('foo')).toBe(1);
});

Expand All @@ -133,6 +135,7 @@ describe('UcMeta', () => {
expect(clone).not.toBe(meta);
expect(clone.isFrozen()).toBe(false);
expect(clone.isMutable()).toBe(true);
expect(clone.mutability).toBe('mutable');
expect(clone.get('foo')).toBe(1);
});
});
Expand All @@ -145,6 +148,7 @@ describe('UcMeta', () => {
expect(mutable).not.toBe(meta);
expect(mutable.isFrozen()).toBe(false);
expect(mutable.isMutable()).toBe(true);
expect(mutable.mutability).toBe('mutable');
expect(mutable.get('foo')).toBe(1);
});
});
Expand Down
10 changes: 6 additions & 4 deletions src/schema/meta/uc-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export class UcMeta {
this.#frozen = frozen;
}

get mutability(): 'frozen' | 'mutable' {
return this.#frozen ? 'frozen' : 'mutable';
}

/**
* Informs whether this metadata instance is {@link UcMeta.Frozen frozen}.
*/
Expand Down Expand Up @@ -332,8 +336,7 @@ export namespace UcMeta {
* Mutable {@link UcMeta charge metadata} instance.
*/
export interface Mutable extends UcMeta {
isMutable(): true;
isFrozen(): false;
get mutability(): 'mutable';
add(attribute: string, value: unknown): this;
add<TInput>(attribute: UcMetaAttr<unknown, TInput>, value: TInput): this;
addAll(other: UcMeta): this;
Expand All @@ -345,8 +348,7 @@ export namespace UcMeta {
* Frozen (immutable) {@link UcMeta charge metadata} instance.
*/
export interface Frozen extends UcMeta {
isMutable(): false;
isFrozen(): true;
get mutability(): 'frozen';
freeze(): this;
}
}
Expand Down
28 changes: 14 additions & 14 deletions src/schema/uri-charge/impl/uri-charge.some.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import { URICharge } from '../uri-charge.js';

abstract class URICharge$Some extends URICharge implements URICharge.Some {

override isNone(): false {
override isNone(): this is URICharge.None {
return false;
}

override isSome(): true {
override isSome(): this is URICharge.Some {
return true;
}

Expand Down Expand Up @@ -47,19 +47,19 @@ export class URICharge$Single extends URICharge$Some implements URICharge.Single
return 1;
}

override hasValues(): true {
override hasValues(): this is URICharge.WithValues {
return true;
}

override isSingle(): true {
override isSingle(): this is URICharge.Single {
return true;
}

override isList(): false {
override isList(): this is URICharge.List {
return false;
}

override isMap(): false {
override isMap(): this is URICharge.Map {
return false;
}

Expand Down Expand Up @@ -124,19 +124,19 @@ export class URICharge$Map extends URICharge$Some implements URICharge.Map {
return 0;
}

override hasValues(): false {
override hasValues(): this is URICharge.WithValues {
return false;
}

override isSingle(): false {
override isSingle(): this is URICharge.Single {
return false;
}

override isList(): false {
override isList(): this is URICharge.List {
return false;
}

override isMap(): true {
override isMap(): this is URICharge.Map {
return true;
}

Expand Down Expand Up @@ -202,19 +202,19 @@ export class URICharge$List extends URICharge$Some implements URICharge.List {
return this.#list.length;
}

override hasValues(): boolean {
override hasValues(): this is URICharge.WithValues {
return !!this.length;
}

override isSingle(): false {
override isSingle(): this is URICharge.Single {
return false;
}

override isList(): true {
override isList(): this is URICharge.List {
return true;
}

override isMap(): false {
override isMap(): this is URICharge.Map {
return false;
}

Expand Down
53 changes: 8 additions & 45 deletions src/schema/uri-charge/uri-charge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export abstract class URICharge implements Uctx {
*
* @returns `true` for any list, including zero-length one; `false` for everything else.
*/
abstract isList(): boolean;
abstract isList(): this is URICharge.List;

/**
* Checks whether this charge is a {@link URICharge.Map map}.
Expand Down Expand Up @@ -176,10 +176,6 @@ export namespace URICharge {
get value(): undefined;
get type(): undefined;

hasValues(): false;
isSingle(): false;
isList(): false;

at(index: 0 | -1): this;
at(index: number): URICharge.Some | None;
}
Expand All @@ -188,8 +184,6 @@ export namespace URICharge {
* URI charge without map entries.
*/
export interface WithoutEntries extends URICharge {
isMap(): false;

get(key: string): None;
entries(): IterableIterator<never>;
keys(): IterableIterator<never>;
Expand All @@ -205,15 +199,6 @@ export namespace URICharge {
get type(): undefined;
get length(): 0;

isNone(): true;
isSome(): false;

hasValues(): false;
isSingle(): false;
isList(): false;

isMap(): false;

at(index: 0 | -1): this;
at(index: number): None;
list(): IterableIterator<never>;
Expand All @@ -226,28 +211,20 @@ export namespace URICharge {
/**
* URI charge that represents {@link URICharge#isSome something}, in contrast to {@link URICharge.None none}.
*/
export interface Some extends URICharge {
isNone(): false;
isSome(): true;
}
export interface Some extends URICharge {}

/**
* URI charge with own value or list items.
*/
export interface WithValues extends Some {
get value(): UcUnknown | null;
get type(): string;

hasValues(): true;
isMap(): false;
}

/**
* Single-valued charge.
*/
export interface Single extends WithValues {
isList(): false;

at(index: 0 | -1): this;
at(index: number): this | None;
list(): IterableIterator<this>;
Expand All @@ -261,11 +238,6 @@ export namespace URICharge {
* URI charge list.
*/
export interface List extends Some, WithoutEntries {
isNone(): false;
isSome(): true;
isList(): true;
isMap(): false;

get(key: string): None;
entries(): IterableIterator<never>;
keys(): IterableIterator<never>;
Expand All @@ -279,15 +251,6 @@ export namespace URICharge {
get type(): undefined;
get length(): 0;

isNone(): false;
isSome(): true;

hasValues(): false;
isSingle(): false;
isList(): false;

isMap(): true;

at(index: 0 | -1): this;
at(index: number): this | None;
list(): IterableIterator<this>;
Expand All @@ -312,27 +275,27 @@ class URICharge$None extends URICharge implements URICharge.None {
return 0;
}

isNone(): true {
isNone(): this is URICharge.None {
return true;
}

isSome(): false {
isSome(): this is URICharge.Some {
return false;
}

hasValues(): false {
hasValues(): this is URICharge.WithValues {
return false;
}

isSingle(): false {
isSingle(): this is URICharge.Single {
return false;
}

isList(): false {
isList(): this is URICharge.List {
return false;
}

isMap(): false {
isMap(): this is URICharge.Map {
return false;
}

Expand Down

0 comments on commit 957d94c

Please sign in to comment.