Skip to content

Commit 0a51a0a

Browse files
authored
Merge pull request #80 from rimbu-org/fix/path-update-fix
fix(deep): fix Path.update not updating values correctly
2 parents b87eb80 + 8534f71 commit 0a51a0a

File tree

113 files changed

+443
-139
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+443
-139
lines changed

deno_dist/base/plain-object.ts

+11
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,19 @@ export type IsPlainObj<T> = T extends
3333
? false
3434
: IsObjWithoutFunctions<T>;
3535

36+
/**
37+
* Utility type that will only accept objects that are considered 'plain objects' according
38+
* to the `IsPlainObj` predicate type.
39+
* @typeparam T - the value type to test
40+
*/
3641
export type PlainObj<T> = IsPlainObj<T> extends true ? T : never;
3742

43+
/**
44+
* Utility type that will only return true if the input type T is equal to `any`.
45+
* @typeparam T - the value type to test
46+
*/
47+
export type IsAny<T> = 0 extends 1 & T ? true : false;
48+
3849
/**
3950
* Companion function to the `IsRecord<T>` type that checks whether the given object is a pure
4051
* data object.

deno_dist/deep/path.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Update } from '../common/mod.ts';
22
import type { IsPlainObj, PlainObj } from '../base/mod.ts';
33

4-
import { patch } from './internal.ts';
4+
import { patch, patchNested } from './internal.ts';
55

66
/**
77
* A string representing a path into an (nested) object of type T.
@@ -92,8 +92,9 @@ export namespace Path {
9292
let current = root;
9393

9494
for (const item of items) {
95-
current[item] = {};
96-
current = current[item];
95+
const next = {};
96+
current[item] = patchNested(next);
97+
current = next;
9798
}
9899

99100
current[last] = value;

deno_dist/deep/protected.ts

+25-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
import type { IsPlainObj } from '../base/mod.ts';
1+
import type { IsAny, IsPlainObj } from '../base/mod.ts';
22

33
/**
44
* A deep readonly typed version of given type T. Makes all properties or elements read only.
5+
* It maps types using the following rules:
6+
* - arrays and tuples become readonly counterparts, and all element types are wrapped in `Protected` if applicable
7+
* - Maps of key type K and value type V become Maps of key type `Protected<K>` and value type `Protected<V>`
8+
* - Sets of element type E become Sets of element type `Protected<E>`
9+
* - Promises of value type E become Promises of value type `Protected<E>`
10+
* - Objects that have only simple properties (no functions or iterators) will have all the properties as Protected if applicable
11+
* - Any other type will not be mapped
512
* @typeparam T - the input type
613
*/
7-
export type Protected<T> = T extends readonly (infer E)[]
8-
? readonly Protected<E>[]
14+
export type Protected<T> = IsAny<T> extends true
15+
? T
16+
: T extends readonly any[] & infer A
17+
? { readonly [K in keyof A]: Protected<A[K]> }
918
: T extends Map<infer K, infer V>
1019
? Map<Protected<K>, Protected<V>>
1120
: T extends Set<infer E>
@@ -17,8 +26,20 @@ export type Protected<T> = T extends readonly (infer E)[]
1726
: T;
1827

1928
/**
20-
* Returns the same value wrapped in the Protected type
29+
* Returns the same value wrapped in the `Protected` type.
2130
* @param value - the value to wrap
31+
* @note does not perform any runtime protection, it is only a utility to easily add the `Protected`
32+
* type to a value
33+
* @example
34+
* ```ts
35+
* const obj = Protected({ a: 1, b: { c: true, d: [1] } })
36+
* obj.a = 2 // compiler error: a is readonly
37+
* obj.b.c = false // compiler error: c is readonly
38+
* obj.b.d.push(2) // compiler error: d is a readonly array
39+
* (obj as any).b.d.push(2) // will actually mutate the object
40+
* ```
41+
42+
* '
2243
*/
2344
export function Protected<T>(value: T): Protected<T> {
2445
return value as any;

packages/actor/jest.config.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"preset": "ts-jest",
33
"testEnvironment": "node",
4-
"testMatch": ["**/test/**.test.ts"]
4+
"testMatch": ["**/test/**.test.ts"],
5+
"moduleNameMapper": {
6+
"@rimbu/actor": ["<rootDir>/src/index.ts"]
7+
},
8+
"collectCoverageFrom": ["src/**"]
59
}

packages/actor/test/actor.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Actor, Obs } from '../src';
1+
import { Actor, Obs } from '@rimbu/actor';
22

33
describe('Actor', () => {
44
it('sets initial state', () => {

packages/actor/test/command.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Obs, Command } from '../src';
1+
import { Obs, Command } from '@rimbu/actor';
22

33
describe('Command', () => {
44
it('executes command', () => {

packages/actor/test/obs.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Obs } from '../src';
1+
import { Obs } from '@rimbu/actor';
22
import { OrderedHashMap } from '@rimbu/core';
33
import { Patch, patchNested as $ } from '@rimbu/deep';
44

packages/actor/test/process-queue.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ProcessQueue } from '../src';
1+
import { ProcessQueue } from '@rimbu/actor';
22

33
async function wait() {
44
return new Promise((res) => setTimeout(res, 100));

packages/actor/tsconfig.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
{
22
"extends": "../../config/tsconfig.base.json",
3-
"include": ["src"],
3+
"include": ["src", "test"],
44
"rootDir": "./src",
55
"compilerOptions": {
66
"outDir": "./dist",
77
"noEmit": true,
8+
"paths": {
9+
"@rimbu/actor": ["./src/index.ts"]
10+
}
811
}
912
}

packages/actor/tsconfig.main.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"include": ["src"],
44
"rootDir": "./src",
55
"compilerOptions": {
6-
"outDir": "./dist/main"
6+
"outDir": "./dist/main",
7+
"paths": {
8+
"@rimbu/actor": ["./src/index.ts"]
9+
}
710
}
811
}

packages/actor/tsconfig.module.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"include": ["src"],
44
"rootDir": "./src",
55
"compilerOptions": {
6-
"outDir": "./dist/module"
6+
"outDir": "./dist/module",
7+
"paths": {
8+
"@rimbu/actor": ["./src/index.ts"]
9+
}
710
}
811
}

packages/actor/tsconfig.types.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"include": ["src"],
44
"rootDir": "./src",
55
"compilerOptions": {
6-
"outDir": "./dist/types"
6+
"outDir": "./dist/types",
7+
"paths": {
8+
"@rimbu/actor": ["./src/index.ts"]
9+
}
710
}
811
}

packages/base/jest.config.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"preset": "ts-jest",
33
"testEnvironment": "node",
4-
"testMatch": ["**/test/**.test.ts"]
4+
"testMatch": ["**/test/**.test.ts"],
5+
"moduleNameMapper": {
6+
"@rimbu/base": ["<rootDir>/src/index.ts"]
7+
},
8+
"collectCoverageFrom": ["src/**"]
59
}

packages/base/src/plain-object.ts

+11
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,19 @@ export type IsPlainObj<T> = T extends
3333
? false
3434
: IsObjWithoutFunctions<T>;
3535

36+
/**
37+
* Utility type that will only accept objects that are considered 'plain objects' according
38+
* to the `IsPlainObj` predicate type.
39+
* @typeparam T - the value type to test
40+
*/
3641
export type PlainObj<T> = IsPlainObj<T> extends true ? T : never;
3742

43+
/**
44+
* Utility type that will only return true if the input type T is equal to `any`.
45+
* @typeparam T - the value type to test
46+
*/
47+
export type IsAny<T> = 0 extends 1 & T ? true : false;
48+
3849
/**
3950
* Companion function to the `IsRecord<T>` type that checks whether the given object is a pure
4051
* data object.

packages/base/test/arr.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { TraverseState } from '@rimbu/common';
2-
import { Arr } from '../src';
2+
import { Arr } from '@rimbu/base';
33

44
const empty: number[] = [];
55

packages/base/test/entry.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Entry } from '../src';
1+
import { Entry } from '@rimbu/base';
22

33
describe('Entry', () => {
44
it('first', () => {

packages/base/test/rimbu-error.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RimbuError } from '../src';
1+
import { RimbuError } from '@rimbu/base';
22

33
describe('RimbuError', () => {
44
it('throwEmptyCollectionAssumedNonEmptyError', () => {

packages/base/tsconfig.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
{
22
"extends": "../../config/tsconfig.base.json",
3-
"include": ["src"],
3+
"include": ["src", "test"],
44
"rootDir": "./src",
55
"compilerOptions": {
66
"outDir": "./dist",
7-
"noEmit": true
7+
"noEmit": true,
8+
"paths": {
9+
"@rimbu/base": ["./src/index.ts"]
10+
}
811
}
912
}

packages/base/tsconfig.main.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"include": ["src"],
44
"rootDir": "./src",
55
"compilerOptions": {
6-
"outDir": "./dist/main"
6+
"outDir": "./dist/main",
7+
"paths": {
8+
"@rimbu/base": ["./src/index.ts"]
9+
}
710
}
811
}

packages/base/tsconfig.module.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"include": ["src"],
44
"rootDir": "./src",
55
"compilerOptions": {
6-
"outDir": "./dist/module"
6+
"outDir": "./dist/module",
7+
"paths": {
8+
"@rimbu/base": ["./src/index.ts"]
9+
}
710
}
811
}

packages/base/tsconfig.types.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"include": ["src"],
44
"rootDir": "./src",
55
"compilerOptions": {
6-
"outDir": "./dist/types"
6+
"outDir": "./dist/types",
7+
"paths": {
8+
"@rimbu/base": ["./src/index.ts"]
9+
}
710
}
811
}

packages/bimap/jest.config.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
22
"preset": "ts-jest",
33
"testEnvironment": "node",
4-
"testMatch": ["**/test/**.test.ts"]
4+
"testMatch": ["**/test/**.test.ts"],
5+
"moduleNameMapper": {
6+
"@rimbu/bimap/custom": ["<rootDir>/src/custom/index.ts"],
7+
"@rimbu/bimap": ["<rootDir>/src/main/index.ts"]
8+
},
9+
"collectCoverageFrom": ["src/**"]
510
}

packages/bimap/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"extends": "../../config/tsconfig.base.json",
3-
"include": ["src"],
3+
"include": ["src", "test"],
44
"rootDir": "./src",
55
"compilerOptions": {
66
"outDir": "./dist",

packages/bimultimap/jest.config.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
22
"preset": "ts-jest",
33
"testEnvironment": "node",
4-
"testMatch": ["**/test/**.test.ts"]
4+
"testMatch": ["**/test/**.test.ts"],
5+
"moduleNameMapper": {
6+
"@rimbu/bimultimap/custom": ["<rootDir>/src/custom/index.ts"],
7+
"@rimbu/bimultimap": ["<rootDir>/src/main/index.ts"]
8+
},
9+
"collectCoverageFrom": ["src/**"]
510
}

packages/bimultimap/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"extends": "../../config/tsconfig.base.json",
3-
"include": ["src"],
3+
"include": ["src", "test"],
44
"rootDir": "./src",
55
"compilerOptions": {
66
"outDir": "./dist",

packages/collection-types/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"@rimbu/collection-types/map-custom": ["./src/map-custom/index.ts"],
1111
"@rimbu/collection-types/set-custom": ["./src/set-custom/index.ts"],
1212
"@rimbu/collection-types/map": ["./src/map/index.ts"],
13-
"@rimbu/collection-types/set": ["./src/set/index.ts"]
13+
"@rimbu/collection-types/set": ["./src/set/index.ts"],
14+
"@rimbu/collection-types": ["./src/main/index.ts"]
1415
}
1516
}
1617
}

packages/collection-types/tsconfig.main.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"@rimbu/collection-types/map-custom": ["./src/map-custom/index.ts"],
1010
"@rimbu/collection-types/set-custom": ["./src/set-custom/index.ts"],
1111
"@rimbu/collection-types/map": ["./src/map/index.ts"],
12-
"@rimbu/collection-types/set": ["./src/set/index.ts"]
12+
"@rimbu/collection-types/set": ["./src/set/index.ts"],
13+
"@rimbu/collection-types": ["./src/main/index.ts"]
1314
}
1415
}
1516
}

packages/collection-types/tsconfig.module.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"@rimbu/collection-types/map-custom": ["./src/map-custom/index.ts"],
1010
"@rimbu/collection-types/set-custom": ["./src/set-custom/index.ts"],
1111
"@rimbu/collection-types/map": ["./src/map/index.ts"],
12-
"@rimbu/collection-types/set": ["./src/set/index.ts"]
12+
"@rimbu/collection-types/set": ["./src/set/index.ts"],
13+
"@rimbu/collection-types": ["./src/main/index.ts"]
1314
}
1415
}
1516
}

packages/collection-types/tsconfig.types.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"@rimbu/collection-types/map-custom": ["./src/map-custom/index.ts"],
1010
"@rimbu/collection-types/set-custom": ["./src/set-custom/index.ts"],
1111
"@rimbu/collection-types/map": ["./src/map/index.ts"],
12-
"@rimbu/collection-types/set": ["./src/set/index.ts"]
12+
"@rimbu/collection-types/set": ["./src/set/index.ts"],
13+
"@rimbu/collection-types": ["./src/main/index.ts"]
1314
}
1415
}
1516
}

packages/common/jest.config.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"preset": "ts-jest",
33
"testEnvironment": "node",
4-
"testMatch": ["**/test/**.test.ts"]
4+
"testMatch": ["**/test/**.test.ts"],
5+
"moduleNameMapper": {
6+
"@rimbu/common": "<rootDir>/src/index.ts"
7+
},
8+
"collectCoverageFrom": ["src/**"]
59
}

packages/common/test/async-optlazy.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AsyncOptLazy } from '../src';
1+
import { AsyncOptLazy } from '@rimbu/common';
22

33
describe('AsyncOptLazy', () => {
44
it('toMaybePromise', async () => {

packages/common/test/async-reducer.test.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { AsyncStream } from '@rimbu/stream';
2-
import { AsyncReducer } from '..';
3-
// import { AsyncReducer } from '../src';
2+
import { AsyncReducer } from '@rimbu/common';
43

54
describe('AsyncReducer', () => {
65
it('create', async () => {

packages/common/test/comp.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Comp } from '../src';
1+
import { Comp } from '@rimbu/common';
22

33
describe('Comp', () => {
44
it('stringComp', () => {

packages/common/test/eq.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Eq } from '../src';
1+
import { Eq } from '@rimbu/common';
22

33
describe('Eq', () => {
44
it('objectIs', () => {

packages/common/test/err.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Err, ErrBase } from '../src';
1+
import { Err, ErrBase } from '@rimbu/common';
22

33
describe('Err/Base', () => {
44
it('throws error', () => {

packages/common/test/index-range.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IndexRange } from '../src';
1+
import { IndexRange } from '@rimbu/common';
22

33
describe('IndexRange', () => {
44
it('getIndexRangeIndices', () => {

0 commit comments

Comments
 (0)