@ws-ui/datasources
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -8,3 +8,3 @@ import { BehaviorSubject } from "rxjs"; | ||
children?: string[]; | ||
value: any; | ||
value: unknown; | ||
} | ||
@@ -68,4 +68,4 @@ export type TStringDatasource = ISource & { | ||
create(datasource: TSource, ctx: IState): void; | ||
set(path: string, value: unknown, ctx: BehaviorSubject<IState>, parent?: TSource): void; | ||
set(root: string, path: string[], value: unknown, ctx: BehaviorSubject<IState>, parent?: TSource): void; | ||
} | ||
export {}; |
export * from "./string"; | ||
export * from "./boolean"; | ||
export * from "./object"; |
import { Observable } from "rxjs"; | ||
import { IState, TSource } from "./interfaces"; | ||
export declare function selectByKey(path: string): (source: Observable<IState>) => Observable<any>; | ||
import { ConnectResponse, EnhancerOptions } from "./interfaces/devtools"; | ||
export declare function selectByKey(path: string): (source: Observable<IState>) => Observable<TSource | undefined>; | ||
export declare function normalizePath(path: string): string; | ||
export declare function getKey(id: string, namespace?: string): string; | ||
export declare class Store { | ||
private static instance; | ||
private readonly middlewares; | ||
private readonly $_state; | ||
readonly $state: Observable<IState>; | ||
constructor(); | ||
private connection?; | ||
private constructor(); | ||
inspect(opts: EnhancerOptions): ConnectResponse | undefined; | ||
static getInstance(): Store; | ||
create(datasource: TSource): void; | ||
@@ -15,3 +20,4 @@ private getSourceByKey; | ||
set(path: string, value: unknown): void; | ||
close(): void; | ||
private use; | ||
} |
{ | ||
"name": "@ws-ui/datasources", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Datasources library for the Qodly Studio project", | ||
@@ -38,2 +38,3 @@ "keywords": [ | ||
"type:check": "tsc --noEmit", | ||
"watch": "NODE_ENV=development npm run build:main -- --exec yalc publish", | ||
"format": "prettier \"src/**/*.ts\" --write", | ||
@@ -59,2 +60,3 @@ "format:check": "prettier \"src/**/*.ts\" --check", | ||
"@semantic-release/release-notes-generator": "^10.0.3", | ||
"@types/lodash": "^4.14.191", | ||
"@types/node": "^18.11.15", | ||
@@ -79,3 +81,4 @@ "@types/prompts": "^2.4.2", | ||
"typescript": "^4.9.4", | ||
"vitest": "^0.25.8" | ||
"vitest": "^0.25.8", | ||
"yalc": "^1.0.0-pre.53" | ||
}, | ||
@@ -86,2 +89,3 @@ "overrides": { | ||
"peerDependencies": { | ||
"lodash": "^4.17.21", | ||
"rxjs": "^7.x" | ||
@@ -93,3 +97,6 @@ }, | ||
"!src/__tests__" | ||
] | ||
], | ||
"dependencies": { | ||
"immer": "^9.0.16" | ||
} | ||
} |
@@ -7,8 +7,5 @@ import { BehaviorSubject } from "rxjs"; | ||
namespace?: string; | ||
type: | ||
| "entity" | ||
| "entitysel" | ||
| "scalar"; | ||
type: "entity" | "entitysel" | "scalar"; | ||
children?: string[]; | ||
value: any; | ||
value: unknown; | ||
} | ||
@@ -91,3 +88,9 @@ | ||
create(datasource: TSource, ctx: IState): void; | ||
set(path: string, value: unknown, ctx: BehaviorSubject<IState>, parent?: TSource): void; | ||
set( | ||
root: string, | ||
path: string[], | ||
value: unknown, | ||
ctx: BehaviorSubject<IState>, | ||
parent?: TSource | ||
): void; | ||
} |
@@ -0,1 +1,4 @@ | ||
import produce from "immer"; | ||
import { set as _set } from "lodash"; | ||
import { IMiddleware, TSource } from "../interfaces"; | ||
@@ -10,19 +13,14 @@ | ||
}, | ||
set(path, value, ctx) { | ||
set(root, _, value, ctx) { | ||
const { value: state } = ctx; | ||
const datasource = state.sources[path]; | ||
const datasource = state.sources[root]; | ||
if (!datasource || !BoolMiddleware.check(datasource)) return; | ||
ctx.next({ | ||
...state, | ||
sources: { | ||
...state.sources, | ||
[path]: { | ||
...state.sources[path], | ||
value: !!value, | ||
} as TSource, | ||
}, | ||
const newValue = produce(state, (draft) => { | ||
_set(draft.sources, `${root}.value`, value); | ||
}); | ||
ctx.next(newValue); | ||
}, | ||
}; |
export * from "./string"; | ||
export * from "./boolean"; | ||
export * from "./object"; |
@@ -0,1 +1,4 @@ | ||
import produce from "immer"; | ||
import { set as _set } from "lodash"; | ||
import { IMiddleware, TSource } from "../interfaces"; | ||
@@ -10,19 +13,14 @@ | ||
}, | ||
set(path, value, ctx) { | ||
set(root, _, value, ctx) { | ||
const { value: state } = ctx; | ||
const datasource = state.sources[path]; | ||
const datasource = state.sources[root]; | ||
if (!datasource || !StringMiddleware.check(datasource)) return; | ||
ctx.next({ | ||
...state, | ||
sources: { | ||
...state.sources, | ||
[path]: { | ||
...state.sources[path], | ||
value: `${value as string}`, | ||
} as TSource, | ||
}, | ||
const newValue = produce(state, (draft) => { | ||
_set(draft.sources, `${root}.value`, value); | ||
}); | ||
ctx.next(newValue); | ||
}, | ||
}; |
@@ -0,8 +1,18 @@ | ||
/* eslint-disable eslint-comments/disable-enable-pair */ | ||
/* eslint-disable eslint-comments/no-duplicate-disable */ | ||
/* eslint-disable @typescript-eslint/no-unnecessary-condition */ | ||
// eslint-disable-next-line eslint-comments/disable-enable-pair | ||
/* eslint-disable @typescript-eslint/no-unsafe-return */ | ||
import { get as _get } from "lodash"; | ||
import { BehaviorSubject, Observable } from "rxjs"; | ||
import { filter, map, distinctUntilChanged } from "rxjs/operators"; | ||
import { inspect } from "./devtools"; | ||
import { IMiddleware, IState, TSource } from "./interfaces"; | ||
import { StringMiddleware, BoolMiddleware } from "./middlewares"; | ||
import { ConnectResponse, EnhancerOptions } from "./interfaces/devtools"; | ||
import { | ||
StringMiddleware, | ||
BoolMiddleware, | ||
ObjectMiddleware, | ||
} from "./middlewares"; | ||
@@ -13,2 +23,3 @@ const DEFAULT_NS = "__default"; | ||
const key = normalizePath(path); | ||
const [root, ...chunks] = key.split("."); | ||
@@ -18,3 +29,6 @@ return function (source: Observable<IState>) { | ||
map((value) => { | ||
return value.sources[key]?.value; | ||
return _get( | ||
value.sources, | ||
`${root}.value${chunks.length > 0 ? "." : ""}${chunks.join(".")}` | ||
); | ||
}), | ||
@@ -42,2 +56,3 @@ distinctUntilChanged(), | ||
export class Store { | ||
private static instance: Store; | ||
private readonly middlewares: IMiddleware[] = []; | ||
@@ -50,8 +65,29 @@ private readonly $_state: BehaviorSubject<IState> = | ||
readonly $state: Observable<IState> = this.$_state.asObservable(); | ||
private connection?: ConnectResponse; | ||
constructor() { | ||
private constructor() { | ||
this.use(StringMiddleware); | ||
this.use(BoolMiddleware); | ||
this.use(ObjectMiddleware); | ||
} | ||
inspect(opts: EnhancerOptions) { | ||
if (!this.connection) { | ||
this.connection = inspect( | ||
opts.name ?? "Qodly Mobile", | ||
this.$_state, | ||
opts | ||
); | ||
} | ||
return this.connection; | ||
} | ||
public static getInstance(): Store { | ||
if (!Store.instance) { | ||
Store.instance = new Store(); | ||
} | ||
return Store.instance; | ||
} | ||
create(datasource: TSource) { | ||
@@ -78,3 +114,2 @@ const { id, namespace = DEFAULT_NS } = datasource; | ||
}); | ||
this.$_state.pipe(distinctUntilChanged()); | ||
@@ -95,3 +130,4 @@ } | ||
const key = normalizePath(path); | ||
const found = this.getSourceByKey(key); | ||
const [root, ...chunks] = key.split("."); | ||
const found = this.getSourceByKey(root); | ||
@@ -101,6 +137,10 @@ if (!found) return; | ||
this.middlewares.forEach(({ set }) => { | ||
set(key, value, this.$_state); | ||
set(root, chunks, value, this.$_state); | ||
}); | ||
} | ||
close() { | ||
this.$_state.complete(); | ||
} | ||
private use(middleware: IMiddleware) { | ||
@@ -107,0 +147,0 @@ this.middlewares.push(middleware); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28
2384
296220
3
29
13
+ Addedimmer@^9.0.16
+ Addedimmer@9.0.21(transitive)
+ Addedlodash@4.17.21(transitive)