@arcote.tech/arc 0.0.16 → 0.0.17

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.
Files changed (40) hide show
  1. package/dist/collection/collection.d.ts +16 -12
  2. package/dist/collection/queries/abstract-collection-query.d.ts +7 -8
  3. package/dist/collection/queries/one-item.d.ts +1 -1
  4. package/dist/collection/queries/util.d.ts +2 -2
  5. package/dist/context/context.d.ts +4 -2
  6. package/dist/context/query.d.ts +6 -3
  7. package/dist/data-storage/ForkStoreState.d.ts +1 -1
  8. package/dist/data-storage/StoreState.d.ts +37 -22
  9. package/dist/data-storage/data-storage-forked.d.ts +2 -2
  10. package/dist/data-storage/data-storage-master.d.ts +5 -3
  11. package/dist/data-storage/data-storage.abstract.d.ts +47 -0
  12. package/dist/data-storage/data-storage.interface.d.ts +14 -5
  13. package/dist/data-storage/deep-merge.d.ts +6 -0
  14. package/dist/data-storage/index.d.ts +1 -1
  15. package/dist/data-storage/master-store-state.d.ts +26 -13
  16. package/dist/data-storage/store-state-fork.d.ts +1 -1
  17. package/dist/data-storage/store-state-master.d.ts +1 -1
  18. package/dist/data-storage/store-state.abstract.d.ts +7 -3
  19. package/dist/data-storage/store-state.d.ts +37 -22
  20. package/dist/elements/date.d.ts +1 -1
  21. package/dist/elements/index.d.ts +1 -0
  22. package/dist/elements/object copy.d.ts +29 -0
  23. package/dist/elements/object.d.ts +15 -0
  24. package/dist/elements/record.d.ts +19 -0
  25. package/dist/elements/state.d.ts +2 -0
  26. package/dist/index.d.ts +1 -0
  27. package/dist/index.js +342 -43
  28. package/dist/rtc/index.d.ts +1 -0
  29. package/dist/rtc/messages.d.ts +3 -3
  30. package/dist/rtc/rtc.d.ts +4 -3
  31. package/dist/state/db.d.ts +1 -0
  32. package/dist/state/index.d.ts +1 -2
  33. package/dist/state/query-builder.d.ts +3 -2
  34. package/dist/state/query.d.ts +10 -17
  35. package/dist/state/state-change.d.ts +1 -0
  36. package/dist/state/state.d.ts +20 -16
  37. package/dist/state/util.d.ts +1 -0
  38. package/dist/utils/deep-merge.d.ts +6 -0
  39. package/dist/utils.d.ts +10 -1
  40. package/package.json +1 -1
@@ -1,3 +1,2 @@
1
- export * from "./db";
2
1
  export * from "./state";
3
- export * from "./state-change";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -2,7 +2,8 @@ import { ArcQueryBuilder } from "../context/query-builders";
2
2
  import { ArcStateQuery } from "./query";
3
3
  import type { ArcStateAny } from "./state";
4
4
  export declare class ArcStateQueryBuilder<S extends ArcStateAny> extends ArcQueryBuilder {
5
- private collection;
6
- constructor(collection: S);
5
+ private state;
6
+ constructor(state: S);
7
7
  toQuery(): ArcStateQuery<S>;
8
8
  }
9
+ //# sourceMappingURL=query-builder.d.ts.map
@@ -1,22 +1,15 @@
1
- import { Subject } from "rxjs";
2
- import type { ArcQuery } from "../context/query";
3
- import type { DatabaseAdapter } from "../db";
4
- import { StateReadTransaction } from "./db";
5
- import type { ArcStateAny } from "./state";
6
- import type { StateChange } from "./state-change";
7
- import type { StateItem } from "./util";
8
- export declare class ArcStateQuery<State extends ArcStateAny> implements ArcQuery<StateItem<State>> {
1
+ import { ArcQuery, type ArcQueryListener } from "../context/query";
2
+ import type { DataStorage, ListenerEvent } from "../data-storage";
3
+ import type { ArcStateAny, StateItem } from "./state";
4
+ export declare class ArcStateQuery<State extends ArcStateAny> extends ArcQuery<StateItem<State>> {
9
5
  protected state: State;
10
- result$: Subject<StateItem<State>>;
11
- private resultQueue$?;
12
- private subscriptions;
6
+ private bindedChangeHandler;
7
+ private store;
13
8
  constructor(state: State);
14
- getLastResult(): StateItem<State>;
15
- run(db: DatabaseAdapter, changes$: Subject<StateChange>): Promise<void>;
16
- protected onChange(change: StateChange): any;
17
- protected fetch(transaction: StateReadTransaction): Promise<ReturnType<State["deserialize"]> | undefined>;
18
- private changeHandler;
9
+ run(dataStorage: DataStorage, listener?: ArcQueryListener<StateItem<State>>): Promise<ReturnType<State["deserialize"]> extends infer T ? { [KeyType in keyof T]: ReturnType<State["deserialize"]>[KeyType]; } : never>;
10
+ protected onChange(change: ListenerEvent<StateItem<State>>): false | (ReturnType<State["deserialize"]> extends infer T ? { [KeyType in keyof T]: ReturnType<State["deserialize"]>[KeyType]; } : never);
11
+ protected changeHandler(changes: ListenerEvent<StateItem<State>>[]): void;
19
12
  unsubscribe(): void;
20
13
  private nextResult;
21
- isUnsubscribed(): boolean;
22
14
  }
15
+ //# sourceMappingURL=query.d.ts.map
@@ -11,3 +11,4 @@ export type StateChange = {
11
11
  export type StateEvent = Exclude<StateChange, {
12
12
  type: "mutate";
13
13
  }>;
14
+ //# sourceMappingURL=state-change.d.ts.map
@@ -1,28 +1,32 @@
1
- import type { ArcContextElement } from "../context/element";
2
- import type { ReadTransaction, ReadWriteTransaction } from "../db";
1
+ import { ArcContextElement } from "../context/element";
2
+ import type { DataStorage } from "../data-storage";
3
3
  import { type ArcObjectAny } from "../elements/object";
4
- import { objectUtil, type util } from "../utils";
4
+ import { objectUtil, type DeepPartial, type util } from "../utils";
5
5
  import { ArcStateQueryBuilder } from "./query-builder";
6
- import type { StateChange, StateEvent } from "./state-change";
7
- import type { StateItem } from "./util";
8
- type StateCommandContext<State extends ArcStateAny> = {
9
- context: {
10
- get: () => StateItem<State>;
11
- };
12
- finalize: () => StateChange[];
13
- };
14
- export declare class ArcState<Name extends string, Schema extends ArcObjectAny> implements ArcContextElement<StateChange, StateEvent> {
6
+ export type StateItem<S extends ArcStateAny> = objectUtil.simplify<ReturnType<S["deserialize"]>>;
7
+ export type StateItemWithId<S extends ArcStateAny> = objectUtil.simplify<{
8
+ _id: string;
9
+ } & ReturnType<S["deserialize"]>>;
10
+ export declare class ArcState<Name extends string, Schema extends ArcObjectAny> extends ArcContextElement<{
11
+ type: "modify";
12
+ from: StateItem<ArcState<Name, Schema>>;
13
+ to: StateItem<ArcState<Name, Schema>>;
14
+ changes: objectUtil.simplify<Partial<util.FirstArgument<Schema["serialize"]>>>;
15
+ }> {
15
16
  readonly name: Name;
16
17
  readonly schema: Schema;
17
18
  constructor(name: Name, schema: Schema);
18
19
  serialize(data: objectUtil.simplify<objectUtil.addQuestionMarks<util.FirstArgument<Schema["serialize"]>>>): {
19
- [x: string]: any;
20
+ _id: Name;
20
21
  };
21
22
  deserialize(data: objectUtil.simplify<objectUtil.addQuestionMarks<util.FirstArgument<Schema["deserialize"]>>>): ReturnType<Schema["deserialize"]>;
22
23
  queryBuilder(): ArcStateQueryBuilder<this>;
23
- commandContext(transaction: ReadTransaction): StateCommandContext<this>;
24
- applyChange(transaction: ReadWriteTransaction, change: StateChange, events: StateChange[]): Promise<void>;
24
+ commandContext(dataStorage: DataStorage, publishEvent: (event: this["$event"]) => Promise<void>): {
25
+ get: () => Promise<StateItem<ArcState<Name, Schema>>>;
26
+ modify: (data: DeepPartial<StateItem<ArcState<Name, Schema>>>) => Promise<void>;
27
+ edit: (editCallback: (item: StateItem<ArcState<Name, Schema>>) => Promise<void> | void) => Promise<void>;
28
+ };
25
29
  }
26
30
  export type ArcStateAny = ArcState<any, any>;
27
31
  export declare function state<Name extends string, Schema extends ArcObjectAny>(name: Name, schema: Schema): ArcState<Name, Schema>;
28
- export {};
32
+ //# sourceMappingURL=state.d.ts.map
@@ -1,2 +1,3 @@
1
1
  import type { ArcStateAny } from "./state";
2
2
  export type StateItem<S extends ArcStateAny> = ReturnType<S["deserialize"]>;
3
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1,6 @@
1
+ type DeepMergeable = {
2
+ [key: string]: any;
3
+ };
4
+ export declare function deepMerge<T extends DeepMergeable>(target: T, source: Partial<T>): T;
5
+ export {};
6
+ //# sourceMappingURL=deep-merge.d.ts.map
package/dist/utils.d.ts CHANGED
@@ -59,7 +59,16 @@ export type ContextTypes<Ctx extends {
59
59
  [Collection in Ctx["elements"][number] as `${Collection["name"]}.queryCollectionResult`]: Omit<QueryCollectionResult<Collection>, "result">;
60
60
  } : never;
61
61
  }[keyof Ctx["elements"]];
62
- export type infer<E extends {
62
+ export type DeepPartial<T> = {
63
+ [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
64
+ };
65
+ export type $type<E extends {
63
66
  deserialize: (...args: any) => any;
64
67
  }> = ReturnType<E["deserialize"]>;
68
+ export type $omit<E extends {
69
+ deserialize: (...args: any) => any;
70
+ }, K extends keyof ReturnType<E["deserialize"]>> = objectUtil.addQuestionMarks<Omit<objectUtil.simplify<ReturnType<E["deserialize"]>>, K>>;
71
+ export type $partial<E extends {
72
+ deserialize: (...args: any) => any;
73
+ }, K extends keyof ReturnType<E["deserialize"]> = never> = DeepPartial<objectUtil.addQuestionMarks<Omit<objectUtil.simplify<ReturnType<E["deserialize"]>>, K>>>;
65
74
  //# sourceMappingURL=utils.d.ts.map
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
7
- "version": "0.0.16",
7
+ "version": "0.0.17",
8
8
  "private": false,
9
9
  "author": "Przemysław Krasiński [arcote.tech]",
10
10
  "description": "Arc is a framework designed to align code closely with business logic, streamlining development and enhancing productivity.",