@cascateer/core 2.3.55 → 2.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,34 +1,35 @@
1
1
  {
2
2
  "name": "@cascateer/core",
3
- "version": "2.3.55",
3
+ "version": "2.4.4",
4
4
  "repository": {
5
5
  "type": "git",
6
- "url": "https://github.com/cascateer/core.git"
6
+ "url": "git+https://github.com/cascateer/core.git"
7
7
  },
8
8
  "scripts": {
9
- "patch": "npm version patch && git push origin main --tags",
9
+ "semver-patch": "npm version patch && git push origin main --tags",
10
+ "update": "npm cache clean --force && npx npm-check-updates -u && npm i",
10
11
  "test": "vitest"
11
12
  },
12
13
  "exports": {
13
14
  ".": "./src/index.ts",
14
15
  "./jsx-runtime": "./src/jsx-runtime.ts",
15
16
  "./jsx-dev-runtime": "./src/jsx-dev-runtime.ts",
16
- "./lib": "./src/lib/index.ts",
17
17
  "./operators": "./src/operators/index.ts"
18
18
  },
19
19
  "devDependencies": {
20
- "@types/lodash": "^4.17.20",
20
+ "@types/lodash": "^4.17.24",
21
21
  "@types/object-hash": "^3.0.6",
22
- "@types/react": "^19.2.14",
23
- "typescript": "~5.8.3",
24
- "vite": "^8.0.7",
25
- "vitest": "^4.1.7"
22
+ "@types/react": "^19.2.17",
23
+ "typescript": "~6.0.3",
24
+ "vite": "^8.0.16",
25
+ "vitest": "^4.1.9"
26
26
  },
27
27
  "dependencies": {
28
- "lodash": "^4.17.21",
28
+ "@cascateer/lib": "^1.0.9",
29
+ "lodash": "^4.18.1",
29
30
  "object-hash": "^3.0.0",
30
31
  "rxjs": "^7.8.2",
31
32
  "ts-brand": "^0.2.0",
32
- "uuid": "^13.0.0"
33
+ "uuid": "^14.0.0"
33
34
  }
34
35
  }
package/src/api.ts CHANGED
@@ -1,3 +1,10 @@
1
+ import {
2
+ asObservable,
3
+ ExtendableDictionary,
4
+ MaybeArray,
5
+ MaybeObservable,
6
+ property,
7
+ } from "@cascateer/lib";
1
8
  import {
2
9
  constant,
3
10
  Dictionary,
@@ -19,10 +26,9 @@ import {
19
26
  tap,
20
27
  UnaryFunction,
21
28
  } from "rxjs";
22
- import { asObservable, ExtendableDictionary, property } from "./lib";
23
- import { memoizeHashed } from "./lib/memoizeHashed";
29
+ import { memoize } from "./lib/memoize";
24
30
  import { ProxyObservable } from "./observable";
25
- import { Action, MaybeArray, MaybeObservable, ProxyEffect } from "./types";
31
+ import { Action, ProxyEffect } from "./types";
26
32
 
27
33
  interface TagsConstructor<Args, Result> {
28
34
  (args: Args, result: Result): string[];
@@ -47,7 +53,7 @@ class Memoizable<Args, Result> {
47
53
  this.tags = isFunction(tags) ? tags : constant([tags ?? []].flat());
48
54
 
49
55
  this.subscribe = (invalidatedTags) => {
50
- const memoizedEffect: ProxyEffect<Args, Result> = memoizeHashed(
56
+ const memoizedEffect: ProxyEffect<Args, Result> = memoize(
51
57
  (args) =>
52
58
  new ProxyObservable((pending) =>
53
59
  this.predicate(args).pipe(
package/src/app.ts CHANGED
@@ -1,7 +1,7 @@
1
+ import { property } from "@cascateer/lib";
1
2
  import { Dictionary, mapValues } from "lodash";
2
3
  import { UnaryFunction } from "rxjs";
3
4
  import { createFragment } from ".";
4
- import { property } from "./lib";
5
5
  import { Slice, SliceAdapter, SliceProvider } from "./slice";
6
6
 
7
7
  export class App<
package/src/component.ts CHANGED
@@ -1,10 +1,10 @@
1
+ import { ExtendableDictionary } from "@cascateer/lib";
1
2
  import { Dictionary, kebabCase } from "lodash";
2
3
  import { defer, share, UnaryFunction } from "rxjs";
3
4
  import { createFragment } from ".";
4
5
  import { ApiAdapter, ApiEffect } from "./api";
5
6
  import { cssStyleSheets } from "./css";
6
7
  import { defineCustomElement } from "./dom";
7
- import { ExtendableDictionary } from "./lib";
8
8
  import { ComputedSignal } from "./signal";
9
9
  import { asStoreEffects, StoreAdapter, StoreEffects } from "./store";
10
10
  import { TerminalAdapter, TerminalEffect } from "./terminal";
@@ -33,7 +33,7 @@ export function createComponent(customElement?: string) {
33
33
  createFragment({
34
34
  children: defer(() =>
35
35
  Promise.all(styles).then((cssModules) =>
36
- cssStyleSheets(cssModules).then(async (cssStyleSheets) => {
36
+ cssStyleSheets(cssModules).then((cssStyleSheets) => {
37
37
  const element = constructor(ctx, ...cssModules)(props);
38
38
 
39
39
  return customElement != null
package/src/css.ts CHANGED
@@ -1,5 +1,5 @@
1
+ import { nonNullable } from "@cascateer/lib";
1
2
  import { isObject, isString, once, tap } from "lodash";
2
- import { nonNullable } from "./lib";
3
3
 
4
4
  const cssImports = once(() =>
5
5
  Promise.all(
package/src/fragment.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { asArray, asObservable } from "@cascateer/lib";
2
+ import { flatMap } from "@cascateer/lib/operators";
1
3
  import { tap } from "lodash";
2
4
  import {
3
5
  combineLatest,
@@ -12,8 +14,6 @@ import {
12
14
  Subscription,
13
15
  switchMap,
14
16
  } from "rxjs";
15
- import { asArray, asObservable } from "./lib";
16
- import { flatMap } from "./operators";
17
17
 
18
18
  export type Leaf =
19
19
  | string
package/src/index.ts CHANGED
@@ -7,4 +7,4 @@ export { Serializable, type BrandedSerializer } from "./serializable";
7
7
  export { createSlice } from "./slice";
8
8
  export { type StoreEffect } from "./store";
9
9
  export { type TerminalEffect } from "./terminal";
10
- export { type Action, type MaybeObservable } from "./types";
10
+ export { type Action, type Effect } from "./types";
@@ -1,3 +1,11 @@
1
+ import {
2
+ asArray,
3
+ asObservable,
4
+ keys,
5
+ MaybeArray,
6
+ MaybeObservable,
7
+ MaybeObservableInputTuple,
8
+ } from "@cascateer/lib";
1
9
  import { bind, camelCase, isFunction, isObject } from "lodash";
2
10
  import React, { CSSProperties } from "react";
3
11
  import {
@@ -9,13 +17,7 @@ import {
9
17
  UnaryFunction,
10
18
  } from "rxjs";
11
19
  import { Leaf, ObservableFragment } from "./fragment";
12
- import { asArray, asObservable, keys } from "./lib";
13
20
  import { sequence } from "./operators";
14
- import {
15
- MaybeArray,
16
- MaybeObservable,
17
- MaybeObservableInputTuple,
18
- } from "./types";
19
21
 
20
22
  type DocumentEventListener<EventName extends keyof DocumentEventMap> =
21
23
  | Partial<Observer<DocumentEventMap[EventName]>>
@@ -0,0 +1,5 @@
1
+ import * as lodash from "lodash";
2
+ import objectHash from "object-hash";
3
+
4
+ export const memoize = <T extends (...args: any) => any>(func: T) =>
5
+ lodash.memoize(func, (...args: Parameters<T>) => objectHash(args ?? null));
package/src/multicast.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { property } from "@cascateer/lib";
2
+ import { flatMap } from "@cascateer/lib/operators";
1
3
  import { partition, thru, uniq, uniqBy } from "lodash";
2
4
  import {
3
5
  distinct,
@@ -11,11 +13,9 @@ import {
11
13
  share,
12
14
  } from "rxjs";
13
15
  import { v4 } from "uuid";
14
- import { property } from "./lib";
15
16
  import {
16
17
  accumulate,
17
18
  exchangeWith,
18
- flatMap,
19
19
  MulticastActionMessage,
20
20
  MulticastClientMessage,
21
21
  proxyReplaySubject,
@@ -1,5 +1,5 @@
1
+ import { property } from "@cascateer/lib";
1
2
  import { fromEvent, map, Observable, OperatorFunction } from "rxjs";
2
- import { property } from "../lib";
3
3
 
4
4
  export const exchangeWith =
5
5
  <InMessage, OutMessage>(
@@ -1,7 +1,6 @@
1
1
  export { accumulate } from "./accumulate";
2
2
  export { every } from "./every";
3
3
  export { exchangeWith } from "./exchangeWith";
4
- export { flatMap } from "./flatMap";
5
4
  export {
6
5
  multicast,
7
6
  type MulticastAction,
@@ -1,7 +1,8 @@
1
+ import { EndoFunction } from "@cascateer/lib";
1
2
  import { concatMap, shareReplay, startWith, UnaryFunction } from "rxjs";
2
3
  import { v4 } from "uuid";
3
4
  import { ProxySubject } from "../observable";
4
- import { ComputedSignal, Transform } from "../signal";
5
+ import { ComputedSignal } from "../signal";
5
6
  import { exchangeWith } from "./exchangeWith";
6
7
  import { proxyReplaySubject } from "./proxyReplaySubject";
7
8
 
@@ -22,7 +23,7 @@ interface MulticastActions<Data> {
22
23
  };
23
24
  };
24
25
  transformAction: {
25
- predicate: Transform<Data>;
26
+ predicate: EndoFunction<Data>;
26
27
  data: {
27
28
  key: string;
28
29
  args: string;
@@ -1,3 +1,4 @@
1
+ import { EndoFunction } from "@cascateer/lib";
1
2
  import { identity } from "lodash";
2
3
  import {
3
4
  lastValueFrom,
@@ -8,7 +9,7 @@ import {
8
9
  toArray,
9
10
  } from "rxjs";
10
11
  import { expect, test } from "vitest";
11
- import { ComputedSignal, Transform } from ".";
12
+ import { ComputedSignal } from ".";
12
13
 
13
14
  test("projection", () => {
14
15
  const signal = new ComputedSignal({
@@ -21,7 +22,7 @@ test("projection", () => {
21
22
  });
22
23
 
23
24
  test("transformation", () => {
24
- const transforms = new ReplaySubject<Transform<any>>();
25
+ const transforms = new ReplaySubject<EndoFunction<any>>();
25
26
  const signal = new ComputedSignal({
26
27
  value: transforms.pipe(
27
28
  startWith(identity),
@@ -1,15 +1,15 @@
1
- import { clone, identity, isEqual, memoize } from "lodash";
2
- import { distinctUntilChanged, map, Observable, UnaryFunction } from "rxjs";
3
1
  import {
4
2
  asEnumerable,
3
+ EndoFunctionOperator,
5
4
  EnumerableItem,
6
5
  Enumerator,
7
6
  nonNullable,
8
7
  nthArg,
9
8
  property,
10
- } from "../lib";
9
+ } from "@cascateer/lib";
10
+ import { clone, identity, isEqual, memoize } from "lodash";
11
+ import { distinctUntilChanged, map, Observable, UnaryFunction } from "rxjs";
11
12
  import { ProxyObservable } from "../observable";
12
- import { TransformOperator } from "../signal";
13
13
 
14
14
  class SignalEnumerator<T> {
15
15
  constructor(private predicate: Enumerator<T> = nthArg(1)) {}
@@ -30,7 +30,7 @@ export class Signal<T> extends ProxyObservable<T> {
30
30
  }
31
31
 
32
32
  enumerator: SignalEnumerator<T>;
33
- pull: TransformOperator<T, unknown>;
33
+ pull: EndoFunctionOperator<T, unknown>;
34
34
 
35
35
  constructor({
36
36
  value,
@@ -39,7 +39,7 @@ export class Signal<T> extends ProxyObservable<T> {
39
39
  }: {
40
40
  value: Observable<T>;
41
41
  enumerator?: SignalEnumerator<T>;
42
- pull?: TransformOperator<T, unknown>;
42
+ pull?: EndoFunctionOperator<T, unknown>;
43
43
  }) {
44
44
  super(value);
45
45
 
@@ -49,7 +49,7 @@ export class Signal<T> extends ProxyObservable<T> {
49
49
 
50
50
  private map<U>(
51
51
  project: UnaryFunction<T, U>,
52
- lift: TransformOperator<U, T>,
52
+ lift: EndoFunctionOperator<U, T>,
53
53
  enumerate?: Enumerator<U>,
54
54
  ): Signal<U> {
55
55
  return new Signal({
@@ -1,10 +1 @@
1
- import { UnaryFunction } from "rxjs";
2
-
3
1
  export { ComputedSignal, Signal } from "./Signal";
4
-
5
- export interface Transform<T> extends UnaryFunction<T, T> {}
6
-
7
- export interface TransformOperator<T, U> extends UnaryFunction<
8
- Transform<T>,
9
- Transform<U>
10
- > {}
package/src/slice.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { ExtendableDictionary } from "@cascateer/lib";
1
2
  import { Dictionary, mapValues } from "lodash";
2
3
  import { defer, map, share, UnaryFunction } from "rxjs";
3
4
  import { createFragment } from ".";
@@ -8,7 +9,6 @@ import {
8
9
  ComponentsProvider,
9
10
  } from "./component";
10
11
  import { defineCustomElement } from "./dom";
11
- import { ExtendableDictionary } from "./lib";
12
12
  import { multicast, MulticastSubject } from "./operators";
13
13
  import { ComputedSignal } from "./signal";
14
14
  import { StoreAdapter, StoreProvider } from "./store";
package/src/store.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { EndoFunction, ExtendableDictionary } from "@cascateer/lib";
2
+ import { flatMap } from "@cascateer/lib/operators";
1
3
  import { constant, Dictionary, mapValues, tap, thru } from "lodash";
2
4
  import {
3
5
  identity,
@@ -8,15 +10,9 @@ import {
8
10
  shareReplay,
9
11
  UnaryFunction,
10
12
  } from "rxjs";
11
- import { ExtendableDictionary } from "./lib";
12
- import {
13
- flatMap,
14
- MulticastAction,
15
- MulticastSubject,
16
- sequence,
17
- } from "./operators";
13
+ import { MulticastAction, MulticastSubject, sequence } from "./operators";
18
14
  import { Serializable } from "./serializable";
19
- import { ComputedSignal, Signal, Transform } from "./signal";
15
+ import { ComputedSignal, Signal } from "./signal";
20
16
  import { Action } from "./types";
21
17
 
22
18
  export type StoreEffect<Result> = () => Signal<Result>;
@@ -70,7 +66,7 @@ export class ExtendableStoreAdapter<
70
66
  },
71
67
  void
72
68
  >;
73
- register: UnaryFunction<(args: any) => Transform<any>, void>;
69
+ register: UnaryFunction<(args: any) => EndoFunction<any>, void>;
74
70
  }
75
71
  >;
76
72
  },
@@ -115,7 +111,7 @@ export class ExtendableStoreAdapter<
115
111
  ? T
116
112
  : never,
117
113
  >(
118
- predicate: UnaryFunction<Args, Transform<T>>,
114
+ predicate: UnaryFunction<Args, EndoFunction<T>>,
119
115
  config?: { sameOrigin?: boolean },
120
116
  ) => Action<Args, any>;
121
117
  };
package/src/terminal.ts CHANGED
@@ -1,7 +1,7 @@
1
+ import { ExtendableDictionary } from "@cascateer/lib";
1
2
  import { Dictionary } from "lodash";
2
3
  import { UnaryFunction } from "rxjs";
3
4
  import { ApiAdapter, ApiEffect } from "./api";
4
- import { ExtendableDictionary } from "./lib";
5
5
  import { ComputedSignal } from "./signal";
6
6
  import { asStoreEffects, StoreAdapter, StoreEffects } from "./store";
7
7
  import {
package/src/types.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import { Dictionary, mapValues, tap } from "lodash";
2
2
  import { combineLatest, ReplaySubject, switchMap, UnaryFunction } from "rxjs";
3
3
  import { Observable } from "rxjs/internal/Observable";
4
- import { ObservableInput } from "rxjs/internal/types";
5
- import { memoizeHashed } from "./lib/memoizeHashed";
4
+ import { memoize } from "./lib/memoize";
6
5
  import { ProxyObservable } from "./observable";
7
6
  import { accumulate, every, some } from "./operators";
8
7
 
@@ -36,7 +35,7 @@ export class ProxyEffectInterceptor extends ReplaySubject<
36
35
  effects: Effects,
37
36
  ): ProxyEffects<Effects> {
38
37
  return mapValues(effects, (effect) =>
39
- memoizeHashed((args) =>
38
+ memoize((args) =>
40
39
  tap(
41
40
  new ProxyObservable(effect(args), (target, receiver) =>
42
41
  combineLatest([target.pending, receiver.refCount]).pipe(every()),
@@ -65,13 +64,3 @@ export interface Action<Args, Result> extends UnaryFunction<
65
64
  Args,
66
65
  Promise<Result>
67
66
  > {}
68
-
69
- export type MaybeArray<T> = T | T[];
70
-
71
- export type MaybeObservable<T> = T | Observable<T>;
72
-
73
- export type MaybeObservableInput<T> = T | ObservableInput<T>;
74
-
75
- export type MaybeObservableInputTuple<T> = {
76
- [K in keyof T]: MaybeObservableInput<T[K]>;
77
- };
@@ -1,23 +0,0 @@
1
- export class Enumerable<T> extends Array<
2
- T extends readonly (infer Index)[] ? Index : never
3
- > {
4
- constructor(value: T) {
5
- super();
6
-
7
- this.push(...(Array.isArray(value) ? value : []));
8
- }
9
- }
10
-
11
- export type EnumerableItem<
12
- T,
13
- Index extends number = number,
14
- > = Enumerable<T>[Index];
15
-
16
- export interface Enumerator<T> {
17
- <Index extends number>(
18
- item: EnumerableItem<T, Index>,
19
- index: Index,
20
- ): PropertyKey;
21
- }
22
-
23
- export const asEnumerable = <T>(value: T) => new Enumerable<T>(value);
@@ -1,56 +0,0 @@
1
- import { Dictionary, once } from "lodash";
2
- import { AsyncSubject, lastValueFrom, UnaryFunction } from "rxjs";
3
- import { keys } from "./keys";
4
-
5
- export type Extend<T, U> = Omit<T, keyof U> & U;
6
-
7
- export class ExtendableDictionary<T, U extends Dictionary<T>> {
8
- constructor(
9
- public currentValue: U,
10
- private value = new AsyncSubject<Dictionary<T>>(),
11
- ) {}
12
-
13
- complete = once((): U => {
14
- this.value.next(this.currentValue);
15
- this.value.complete();
16
-
17
- return this.currentValue;
18
- });
19
-
20
- extend<V extends Dictionary<T>>(
21
- value: (
22
- currentValue: U,
23
- ) => ({
24
- property,
25
- }: {
26
- property: (constructor: UnaryFunction<Promise<string>, T>) => T;
27
- }) => V,
28
- ) {
29
- return new ExtendableDictionary<T, Extend<U, V>>(
30
- {
31
- ...this.currentValue,
32
- ...value(this.currentValue)({
33
- property: (constructor) => {
34
- const property = constructor(
35
- lastValueFrom(this.value).then(
36
- (value) =>
37
- new Promise<string>((resolve, reject) => {
38
- for (const key of keys(value)) {
39
- if (value[key] === property) {
40
- return resolve(key);
41
- }
42
- }
43
-
44
- reject();
45
- }),
46
- ),
47
- );
48
-
49
- return property;
50
- },
51
- }),
52
- },
53
- this.value,
54
- );
55
- }
56
- }
@@ -1,26 +0,0 @@
1
- import { Comparator, uniqWith } from "lodash";
2
-
3
- export const chunkWith = <T>(
4
- actions: T[],
5
- comparator?: Comparator<T>,
6
- ): T[][] => [
7
- ...{
8
- *[Symbol.iterator]() {
9
- const prevActions = new Array<T>();
10
-
11
- if (actions.length == 0) {
12
- return;
13
- }
14
-
15
- for (const action of actions) {
16
- if (uniqWith([...prevActions, action], comparator).length === 1) {
17
- prevActions.push(action);
18
- } else {
19
- yield prevActions.splice(0, prevActions.length, action);
20
- }
21
- }
22
-
23
- yield prevActions;
24
- },
25
- },
26
- ];
package/src/lib/index.ts DELETED
@@ -1,29 +0,0 @@
1
- import { Observable, of } from "rxjs";
2
- import { isObservable } from "rxjs/internal/util/isObservable";
3
- import { MaybeArray, MaybeObservable } from "../types";
4
-
5
- export { chunkWith } from "./chunkWith";
6
- export {
7
- asEnumerable,
8
- type Enumerable,
9
- type EnumerableItem,
10
- type Enumerator,
11
- } from "./Enumerable";
12
- export { ExtendableDictionary } from "./ExtendableDictionary";
13
- export { keys } from "./keys";
14
- export { nthArg } from "./nthArg";
15
- export { property } from "./property";
16
-
17
- export const asArray = <T>(array: MaybeArray<T>): Array<T> =>
18
- Array.isArray(array) ? array : [array];
19
-
20
- export const asObservable = <T>(value: MaybeObservable<T>): Observable<T> =>
21
- isObservable(value) ? value : of(value);
22
-
23
- export const nonNullable = <T>(value: T): NonNullable<T> => {
24
- if (value == null) {
25
- throw null;
26
- }
27
-
28
- return value;
29
- };
package/src/lib/keys.ts DELETED
@@ -1,7 +0,0 @@
1
- export const keys = <T>(value: T) => [
2
- ...{
3
- *[Symbol.iterator]() {
4
- for (const key in value) yield key;
5
- },
6
- },
7
- ];
@@ -1,5 +0,0 @@
1
- import { memoize } from "lodash";
2
- import objectHash from "object-hash";
3
-
4
- export const memoizeHashed = <T extends (...args: any) => any>(func: T) =>
5
- memoize(func, (...args: Parameters<T>) => objectHash(args ?? null));
package/src/lib/nthArg.ts DELETED
@@ -1,6 +0,0 @@
1
- export function nthArg<T>(n: 0): (arg0: T) => T;
2
- export function nthArg<T>(n: 1): (arg0: any, arg1: T) => T;
3
- export function nthArg<T>(n: 2): (arg0: any, arg1: any, arg2: T) => T;
4
- export function nthArg<T>(n: number): (...args: any[]) => T {
5
- return (...args) => args[n];
6
- }
@@ -1,4 +0,0 @@
1
- export const property =
2
- <T, K extends keyof T = keyof T>(key: K) =>
3
- (value: T): T[K] =>
4
- value[key];
@@ -1,11 +0,0 @@
1
- import { OperatorFunction, from, map, mergeMap } from "rxjs";
2
-
3
- export const flatMap =
4
- <T, U>(
5
- project: (value: T, index: number) => U | U[],
6
- ): OperatorFunction<T, U> =>
7
- (source) =>
8
- source.pipe(
9
- map(project),
10
- mergeMap((value) => from(Array.isArray(value) ? value : [value])),
11
- );