@arcote.tech/arc 0.0.1 → 0.0.2

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 (44) hide show
  1. package/dist/collection/collection-change.d.ts +17 -0
  2. package/dist/collection/collection.d.ts +59 -0
  3. package/dist/collection/db.d.ts +18 -0
  4. package/dist/collection/index.d.ts +5 -0
  5. package/dist/collection/queries/abstract-collection-query.d.ts +20 -0
  6. package/dist/collection/queries/abstract-many-items.d.ts +20 -0
  7. package/dist/collection/queries/all-items.d.ts +6 -0
  8. package/dist/collection/queries/indexed.d.ts +13 -0
  9. package/dist/collection/queries/one-item.d.ts +11 -0
  10. package/dist/collection/queries/util.d.ts +6 -0
  11. package/dist/collection/query-builders/abstract-many-items.d.ts +9 -0
  12. package/dist/collection/query-builders/all-items.d.ts +8 -0
  13. package/dist/collection/query-builders/indexed.d.ts +10 -0
  14. package/dist/collection/query-builders/one-item.d.ts +10 -0
  15. package/dist/context/commands.d.ts +10 -0
  16. package/dist/context/context.d.ts +31 -0
  17. package/dist/context/element.d.ts +8 -0
  18. package/dist/context/index.d.ts +1 -0
  19. package/dist/context/query-builders.d.ts +4 -0
  20. package/dist/context/query.d.ts +3 -0
  21. package/dist/elements/abstract-primitive.d.ts +7 -0
  22. package/dist/elements/abstract.d.ts +12 -0
  23. package/dist/elements/array.d.ts +12 -0
  24. package/dist/elements/boolean.d.ts +4 -0
  25. package/dist/elements/branded.d.ts +20 -0
  26. package/dist/elements/date.d.ts +8 -0
  27. package/dist/elements/default.d.ts +10 -0
  28. package/dist/elements/element.d.ts +5 -0
  29. package/dist/elements/id.d.ts +9 -0
  30. package/dist/elements/index.d.ts +9 -0
  31. package/dist/elements/number.d.ts +4 -0
  32. package/dist/elements/object.d.ts +28 -0
  33. package/dist/elements/optional.d.ts +11 -0
  34. package/dist/elements/string-enum.d.ts +11 -0
  35. package/dist/elements/string.d.ts +4 -0
  36. package/dist/model/index.d.ts +3 -0
  37. package/dist/model/model.d.ts +33 -0
  38. package/dist/model/query-builder.d.ts +3 -0
  39. package/dist/model/rtc.d.ts +6 -0
  40. package/dist/rtc/client.d.ts +2 -0
  41. package/dist/rtc/deserializeChanges.d.ts +2 -0
  42. package/dist/rtc/index.d.ts +3 -0
  43. package/dist/rtc/messages.d.ts +20 -0
  44. package/package.json +3 -3
@@ -0,0 +1,17 @@
1
+ import type { Patches } from "mutative";
2
+ export type CollectionChange = {
3
+ collection: string;
4
+ } & ({
5
+ type: "set";
6
+ body: any;
7
+ } | {
8
+ type: "delete";
9
+ id: string;
10
+ } | {
11
+ type: "mutate";
12
+ id: string;
13
+ patches: Patches<any>;
14
+ });
15
+ export type CollectionChangesWithoutMutate = Exclude<CollectionChange, {
16
+ type: "mutate";
17
+ }>;
@@ -0,0 +1,59 @@
1
+ import type { GetDraft } from "../context/context";
2
+ import type { ArcContextElement } from "../context/element";
3
+ import type { ArcIdAny } from "../elements/id";
4
+ import { type ArcObjectAny } from "../elements/object";
5
+ import type { objectUtil, util } from "../utils";
6
+ import type { CollectionChange } from "./collection-change";
7
+ import type { ReadTransaction, ReadWriteTransaction } from "./db";
8
+ import { ArcAllItemsQueryBuilder } from "./query-builders/all-items";
9
+ import { ArcIndexedItemsQueryBuilder } from "./query-builders/indexed";
10
+ import { ArcOneItemQueryBuilder } from "./query-builders/one-item";
11
+ export type Deserialize<Id extends ArcIdAny, Schema extends ArcObjectAny> = objectUtil.simplify<{
12
+ _id: ReturnType<Id["deserialize"]>;
13
+ } & ReturnType<Schema["deserialize"]>>;
14
+ declare class ArcCollection<Name extends string, Id extends ArcIdAny, Schema extends ArcObjectAny> implements ArcContextElement {
15
+ readonly name: Name;
16
+ readonly id: Id;
17
+ readonly schema: Schema;
18
+ constructor(name: Name, id: Id, schema: Schema);
19
+ serialize(data: objectUtil.simplify<{
20
+ _id: util.FirstArgument<Id["serialize"]>;
21
+ } & objectUtil.addQuestionMarks<util.FirstArgument<Schema["serialize"]>>>): objectUtil.simplify<{
22
+ _id: ReturnType<Id["serialize"]>;
23
+ } & ReturnType<Schema["serialize"]>>;
24
+ deserialize(data: objectUtil.simplify<{
25
+ _id: util.FirstArgument<Id["deserialize"]>;
26
+ } & objectUtil.addQuestionMarks<util.FirstArgument<Schema["deserialize"]>>>): Deserialize<Id, Schema>;
27
+ queryBuilder(): {
28
+ all: () => ArcAllItemsQueryBuilder<ArcCollection<Name, Id, Schema>>;
29
+ one: (id: util.GetType<Id> | undefined) => ArcOneItemQueryBuilder<ArcCollection<Name, Id, Schema>>;
30
+ };
31
+ commandContext(transaction: ReadTransaction, changes: CollectionChange[], getDraft: GetDraft<any>): {
32
+ one: (id: util.GetType<Id>) => Deserialize<Id, Schema>;
33
+ remove: (id: util.GetType<Id>) => Promise<any>;
34
+ add: (data: util.FirstArgument<Schema["parse"]>) => Promise<any>;
35
+ set: (id: util.GetType<Id>, data: util.FirstArgument<Schema["deserialize"]>) => Promise<any>;
36
+ };
37
+ applyChange(transaction: ReadWriteTransaction, change: CollectionChange, events: CollectionChange[]): Promise<void>;
38
+ indexBy<Indexes extends keyof ReturnType<Schema["deserialize"]>, const I extends {
39
+ [name: string]: Indexes[];
40
+ }>(indexes: I): ArcIndexedCollection<Name, Id, Schema, keyof ReturnType<Schema["deserialize"]>, I>;
41
+ }
42
+ export declare class ArcIndexedCollection<Name extends string, Id extends ArcIdAny, Schema extends ArcObjectAny, Indexes extends keyof ReturnType<Schema["deserialize"]>, const I extends {
43
+ [name: string]: Indexes[];
44
+ }> extends ArcCollection<Name, Id, Schema> implements ArcContextElement {
45
+ readonly indexes: I;
46
+ constructor(name: Name, id: Id, schema: Schema, indexes: I);
47
+ queryBuilder(): {
48
+ all: () => ArcAllItemsQueryBuilder<ArcCollection<Name, Id, Schema>>;
49
+ one: (id: util.GetType<Id> | undefined) => ArcOneItemQueryBuilder<ArcCollection<Name, Id, Schema>>;
50
+ } & {
51
+ [func in keyof I]: (args: {
52
+ [Key in I[func][number]]: util.GetType<Schema>[Key];
53
+ }) => ArcIndexedItemsQueryBuilder<ArcIndexedCollection<Name, Id, Schema, Indexes, I>>;
54
+ };
55
+ }
56
+ export type ArcCollectionAny = ArcCollection<any, any, any>;
57
+ export type ArcIndexedCollectionAny = ArcIndexedCollection<any, any, any, any, any>;
58
+ export declare function collection<Name extends string, Id extends ArcIdAny, Schema extends ArcObjectAny>(name: Name, id: Id, schema: Schema): ArcCollection<Name, Id, Schema>;
59
+ export {};
@@ -0,0 +1,18 @@
1
+ import type { ArcContextAny } from "../context";
2
+ import type { util } from "../utils";
3
+ import type { ArcCollectionAny, ArcIndexedCollectionAny } from "./collection";
4
+ export interface ReadWriteTransaction extends ReadTransaction {
5
+ remove<C extends ArcCollectionAny>(collection: C, id: util.GetType<C["id"]>): Promise<void>;
6
+ set<C extends ArcCollectionAny>(collection: C, data: util.CollectionItemWithId<C>): Promise<void>;
7
+ commit(): Promise<void>;
8
+ }
9
+ export interface ReadTransaction {
10
+ findById<C extends ArcCollectionAny>(collection: C, id: util.GetType<C["id"]>): Promise<util.CollectionItemWithId<C>>;
11
+ findByIndex<C extends ArcIndexedCollectionAny>(collection: C, index: string, data: any): Promise<util.CollectionItemWithId<C>[]>;
12
+ findAll<C extends ArcCollectionAny>(collection: C): Promise<util.CollectionItemWithId<C>[]>;
13
+ }
14
+ export interface DatabaseAdapter {
15
+ readWriteTransaction(collections: ArcCollectionAny[]): ReadWriteTransaction;
16
+ readTransaction(collections: ArcCollectionAny[]): ReadTransaction;
17
+ }
18
+ export type DBAdapterFactory = (context: ArcContextAny) => Promise<DatabaseAdapter>;
@@ -0,0 +1,5 @@
1
+ export { collection, type ArcCollectionAny, type ArcIndexedCollectionAny, } from "./collection";
2
+ export { type CollectionChange } from "./collection-change";
3
+ export * from "./db";
4
+ export { ArcCollectionQuery } from "./queries/abstract-collection-query";
5
+ export type { GetAnyCollectionQueryResult } from "./queries/util";
@@ -0,0 +1,20 @@
1
+ import { Subject } from "rxjs";
2
+ import type { ArcQuery } from "../../context/query";
3
+ import type { ArcCollectionAny } from "../collection";
4
+ import type { CollectionChange } from "../collection-change";
5
+ import type { DatabaseAdapter, ReadTransaction } from "../db";
6
+ export declare abstract class ArcCollectionQuery<Collection extends ArcCollectionAny, Response> implements ArcQuery {
7
+ protected collection: Collection;
8
+ result$: Subject<Response>;
9
+ private resultQueue$?;
10
+ private subscriptions;
11
+ constructor(collection: Collection);
12
+ getLastResult(): Response;
13
+ run(db: DatabaseAdapter, changes$: Subject<CollectionChange>): Promise<void>;
14
+ protected abstract onChange(change: CollectionChange): Response | false;
15
+ protected abstract fetch(transaction: ReadTransaction): Promise<Response> | undefined;
16
+ private changeHandler;
17
+ unsubscribe(): void;
18
+ private nextResult;
19
+ isUnsubscribed(): boolean;
20
+ }
@@ -0,0 +1,20 @@
1
+ import type { util } from "../../utils";
2
+ import type { ArcCollectionAny } from "../collection";
3
+ import type { CollectionChangesWithoutMutate } from "../collection-change";
4
+ import { ArcCollectionQuery } from "./abstract-collection-query";
5
+ export declare class QueryCollectionResult<C extends ArcCollectionAny> {
6
+ private result;
7
+ constructor(result: util.CollectionItemWithId<C>[]);
8
+ get(id: util.GetType<C["id"]>): ReturnType<C["deserialize"]> | undefined;
9
+ map<U>(callbackfn: (value: util.CollectionItemWithId<C>, index: number, array: util.CollectionItemWithId<C>[]) => U): U[];
10
+ toArray(): ReturnType<C["deserialize"]>[];
11
+ }
12
+ export declare abstract class ArcManyItemsQuery<Collection extends ArcCollectionAny> extends ArcCollectionQuery<Collection, QueryCollectionResult<Collection>> {
13
+ protected filterFn?: ((item: util.CollectionItemWithId<Collection>) => boolean) | undefined;
14
+ protected sortFn?: ((a: util.CollectionItemWithId<Collection>, b: util.CollectionItemWithId<Collection>) => number) | undefined;
15
+ constructor(collection: Collection, filterFn?: ((item: util.CollectionItemWithId<Collection>) => boolean) | undefined, sortFn?: ((a: util.CollectionItemWithId<Collection>, b: util.CollectionItemWithId<Collection>) => number) | undefined);
16
+ protected onChange(change: CollectionChangesWithoutMutate): false | QueryCollectionResult<Collection>;
17
+ protected createResult(result: util.CollectionItemWithId<Collection>[]): QueryCollectionResult<Collection>;
18
+ protected createFiltredResult(result: util.CollectionItemWithId<Collection>[]): QueryCollectionResult<Collection>;
19
+ protected checkItem(item: util.CollectionItemWithId<Collection>): boolean;
20
+ }
@@ -0,0 +1,6 @@
1
+ import { type ArcCollectionAny } from "../collection";
2
+ import type { ReadTransaction } from "../db";
3
+ import { ArcManyItemsQuery } from "./abstract-many-items";
4
+ export declare class ArcAllItemsQuery<Collection extends ArcCollectionAny> extends ArcManyItemsQuery<Collection> {
5
+ protected fetch(transaction: ReadTransaction): Promise<import("./abstract-many-items").QueryCollectionResult<Collection>>;
6
+ }
@@ -0,0 +1,13 @@
1
+ import type { util } from "../../utils";
2
+ import type { ArcIndexedCollectionAny } from "../collection";
3
+ import type { ReadTransaction } from "../db";
4
+ import { ArcManyItemsQuery } from "./abstract-many-items";
5
+ export declare class ArcIndexedItemsQuery<Collection extends ArcIndexedCollectionAny> extends ArcManyItemsQuery<Collection> {
6
+ private index;
7
+ private data;
8
+ protected filterFn?: ((item: util.CollectionItemWithId<Collection>) => boolean) | undefined;
9
+ protected sortFn?: ((a: util.CollectionItemWithId<Collection>, b: util.CollectionItemWithId<Collection>) => number) | undefined;
10
+ constructor(collection: Collection, index: string, data: any, filterFn?: ((item: util.CollectionItemWithId<Collection>) => boolean) | undefined, sortFn?: ((a: util.CollectionItemWithId<Collection>, b: util.CollectionItemWithId<Collection>) => number) | undefined);
11
+ protected checkItem(item: util.CollectionItemWithId<Collection>): boolean;
12
+ protected fetch(transaction: ReadTransaction): Promise<import("./abstract-many-items").QueryCollectionResult<Collection>>;
13
+ }
@@ -0,0 +1,11 @@
1
+ import type { util } from "../../utils";
2
+ import type { ArcCollectionAny } from "../collection";
3
+ import type { CollectionChange } from "../collection-change";
4
+ import type { ReadTransaction } from "../db";
5
+ import { ArcCollectionQuery } from "./abstract-collection-query";
6
+ export declare class ArcOneItemQuery<Collection extends ArcCollectionAny> extends ArcCollectionQuery<Collection, util.CollectionItemWithId<Collection>> {
7
+ private id;
8
+ constructor(collection: Collection, id: util.GetType<Collection["id"]>);
9
+ protected onChange(change: CollectionChange): any;
10
+ protected fetch(transaction: ReadTransaction): Promise<ReturnType<Collection["deserialize"]>> | undefined;
11
+ }
@@ -0,0 +1,6 @@
1
+ import type { ArcContextAny } from "../../context";
2
+ import type { QueryFactoryFunction } from "../../model";
3
+ import type { objectUtil } from "../../utils";
4
+ import type { ArcCollectionAny, ArcIndexedCollectionAny } from "../collection";
5
+ import type { ArcCollectionQuery } from "./abstract-collection-query";
6
+ export type GetAnyCollectionQueryResult<QB extends QueryFactoryFunction<ArcContextAny>> = ReturnType<ReturnType<QB>["toQuery"]> extends ArcCollectionQuery<ArcCollectionAny | ArcIndexedCollectionAny, any> ? objectUtil.simplify<ReturnType<ReturnType<ReturnType<QB>["toQuery"]>["getLastResult"]>> : never;
@@ -0,0 +1,9 @@
1
+ import { ArcQueryBuilder } from "../../context/query-builders";
2
+ import type { util } from "../../utils";
3
+ import { type ArcCollectionAny } from "../collection";
4
+ export declare abstract class ArcManyItemsQueryBuilder<C extends ArcCollectionAny> extends ArcQueryBuilder {
5
+ protected filterFn?: (item: util.CollectionItemWithId<C>) => boolean;
6
+ protected sortFn?: (a: util.CollectionItemWithId<C>, b: util.CollectionItemWithId<C>) => number;
7
+ filter(callback: (item: util.CollectionItemWithId<C>) => boolean): this;
8
+ sort(callback: (a: util.CollectionItemWithId<C>, b: util.CollectionItemWithId<C>) => number): this;
9
+ }
@@ -0,0 +1,8 @@
1
+ import { type ArcCollectionAny } from "../collection";
2
+ import { ArcAllItemsQuery } from "../queries/all-items";
3
+ import { ArcManyItemsQueryBuilder } from "./abstract-many-items";
4
+ export declare class ArcAllItemsQueryBuilder<C extends ArcCollectionAny> extends ArcManyItemsQueryBuilder<C> {
5
+ private collection;
6
+ constructor(collection: C);
7
+ toQuery(): ArcAllItemsQuery<C>;
8
+ }
@@ -0,0 +1,10 @@
1
+ import type { ArcIndexedCollectionAny } from "../collection";
2
+ import { ArcIndexedItemsQuery } from "../queries/indexed";
3
+ import { ArcManyItemsQueryBuilder } from "./abstract-many-items";
4
+ export declare class ArcIndexedItemsQueryBuilder<C extends ArcIndexedCollectionAny> extends ArcManyItemsQueryBuilder<C> {
5
+ private collection;
6
+ private index;
7
+ private data;
8
+ constructor(collection: C, index: string, data: any);
9
+ toQuery(): ArcIndexedItemsQuery<C>;
10
+ }
@@ -0,0 +1,10 @@
1
+ import { ArcQueryBuilder } from "../../context/query-builders";
2
+ import type { util } from "../../utils";
3
+ import type { ArcCollectionAny } from "../collection";
4
+ import { ArcOneItemQuery } from "../queries/one-item";
5
+ export declare class ArcOneItemQueryBuilder<C extends ArcCollectionAny> extends ArcQueryBuilder {
6
+ private collection;
7
+ private id;
8
+ constructor(collection: C, id: util.GetType<C["id"]>);
9
+ toQuery(): ArcOneItemQuery<C>;
10
+ }
@@ -0,0 +1,10 @@
1
+ import type { ArcContextAny } from "./context";
2
+ type Command<C extends ArcContextAny> = (context: ReturnType<C["commandContext"]>["context"], ...args: any[]) => any;
3
+ export type Commands<C extends ArcContextAny> = {
4
+ [key: string]: Command<C>;
5
+ };
6
+ export type CommandProxy<F> = F extends (ctx: any, ...args: infer args) => infer ret ? (...args: args) => ret : never;
7
+ export type CommandsClient<Cmds extends Commands<any>> = {
8
+ [Key in keyof Cmds]: CommandProxy<Cmds[Key]>;
9
+ };
10
+ export {};
@@ -0,0 +1,31 @@
1
+ import type { CollectionChange } from "../collection/collection-change";
2
+ import type { ReadTransaction, ReadWriteTransaction } from "../collection/db";
3
+ import type { Commands } from "./commands";
4
+ import type { ArcContextElement } from "./element";
5
+ export type GetDraft<T> = (collection: string, base: T) => T;
6
+ declare class ArcContext<const C extends ArcContextElement[]> {
7
+ readonly collections: C;
8
+ collectionsMap: {
9
+ [key: string]: C[number];
10
+ };
11
+ constructor(collections: C);
12
+ queryBuilder(): {
13
+ [Collection in C[number] as Collection["name"]]: ReturnType<Collection["queryBuilder"]>;
14
+ };
15
+ commandContext(transaction: ReadTransaction): {
16
+ context: {
17
+ [Collection in C[number] as Collection["name"]]: ReturnType<Collection["commandContext"]>;
18
+ };
19
+ finalize: () => CollectionChange[];
20
+ };
21
+ applyChange(transaction: ReadWriteTransaction, change: CollectionChange, events: CollectionChange[]): Promise<void>;
22
+ withCommands<Cmds extends Commands<this>>(commands: Cmds): ArcContextWithCommands<C, Cmds>;
23
+ }
24
+ declare class ArcContextWithCommands<const C extends ArcContextElement[], Cmds extends Commands<ArcContext<C>>> extends ArcContext<C> {
25
+ readonly commands: Cmds;
26
+ constructor(context: C, commands: Cmds);
27
+ }
28
+ export type ArcContextAny = ArcContext<ArcContextElement[]>;
29
+ export type ArcContextWithCommandsAny = ArcContextWithCommands<ArcContextElement[], any>;
30
+ export declare function context<const C extends ArcContextElement[]>(...collections: C): ArcContext<C>;
31
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { CollectionChange, ReadTransaction, ReadWriteTransaction } from "../collection";
2
+ import type { GetDraft } from "./context";
3
+ export interface ArcContextElement {
4
+ name: string;
5
+ queryBuilder(): any;
6
+ commandContext(transaction: ReadTransaction, changes: CollectionChange[], getDraft: GetDraft<any>): any;
7
+ applyChange(transaction: ReadWriteTransaction, change: CollectionChange, events: CollectionChange[]): Promise<void>;
8
+ }
@@ -0,0 +1 @@
1
+ export { context, type ArcContextAny } from "./context";
@@ -0,0 +1,4 @@
1
+ import type { ArcQuery } from "./query";
2
+ export declare abstract class ArcQueryBuilder {
3
+ abstract toQuery(): ArcQuery;
4
+ }
@@ -0,0 +1,3 @@
1
+ export interface ArcQuery {
2
+ run(...args: unknown[]): void;
3
+ }
@@ -0,0 +1,7 @@
1
+ import { ArcAbstract } from "./abstract";
2
+ export declare abstract class ArcPrimitive<T> extends ArcAbstract {
3
+ constructor();
4
+ serialize(value: T): T;
5
+ parse(value: T): T;
6
+ deserialize(value: T): T;
7
+ }
@@ -0,0 +1,12 @@
1
+ import { ArcBranded } from "./branded";
2
+ import { ArcDefault } from "./default";
3
+ import type { ArcElement } from "./element";
4
+ import { ArcOptional } from "./optional";
5
+ export declare abstract class ArcAbstract implements ArcElement {
6
+ abstract serialize(value: any): any;
7
+ abstract deserialize(value: any): any;
8
+ abstract parse(value: any): any;
9
+ default(defaultValueOrCallback: (() => ReturnType<this["deserialize"]>) | ReturnType<this["deserialize"]>): ArcDefault<this>;
10
+ optional(): ArcOptional<this>;
11
+ branded<Brand extends string | symbol>(name: Brand): ArcBranded<this, Brand>;
12
+ }
@@ -0,0 +1,12 @@
1
+ import { type util } from "../utils";
2
+ import { ArcAbstract } from "./abstract";
3
+ export declare class ArcArray<E extends ArcAbstract> extends ArcAbstract {
4
+ private parent;
5
+ constructor(parent: E);
6
+ parse(value: util.FirstArgument<E["deserialize"]>[]): ReturnType<E["parse"]>[];
7
+ serialize(value: util.FirstArgument<E["serialize"]>[]): ReturnType<E["serialize"]>[];
8
+ deserialize(value: util.FirstArgument<E["deserialize"]>[]): ReturnType<E["deserialize"]>[];
9
+ deserializePath(path: string[], value: any): any;
10
+ }
11
+ export type ArcArrayAny = ArcArray<any>;
12
+ export declare function array<E extends ArcAbstract>(element: E): ArcArray<E>;
@@ -0,0 +1,4 @@
1
+ import { ArcPrimitive } from "./abstract-primitive";
2
+ export declare class ArcBoolean extends ArcPrimitive<boolean> {
3
+ }
4
+ export declare function boolean(): ArcBoolean;
@@ -0,0 +1,20 @@
1
+ import { type util } from "../utils";
2
+ import { ArcAbstract } from "./abstract";
3
+ import type { ArcElement } from "./element";
4
+ import { ArcOptional } from "./optional";
5
+ export declare class ArcBranded<E extends ArcAbstract, Brand extends string | symbol> implements ArcElement {
6
+ private parent;
7
+ private brand;
8
+ constructor(parent: E, brand: Brand);
9
+ serialize(value: util.FirstArgument<E["serialize"]> & {
10
+ __brand: Brand;
11
+ }): ReturnType<E["serialize"]>;
12
+ deserialize(value: util.FirstArgument<E["deserialize"]>): ReturnType<E["deserialize"]> & {
13
+ __brand: Brand;
14
+ };
15
+ parse(value: util.FirstArgument<E["parse"]>): ReturnType<E["parse"]> & {
16
+ __brand: Brand;
17
+ };
18
+ optional(): ArcOptional<this>;
19
+ }
20
+ export type ArcBrandedAny = ArcBranded<ArcAbstract, any>;
@@ -0,0 +1,8 @@
1
+ import { ArcAbstract } from "./abstract";
2
+ export declare class ArcDate extends ArcAbstract {
3
+ constructor();
4
+ parse(value: string | number | Date): Date;
5
+ serialize(value: Date): string;
6
+ deserialize(value: string): Date;
7
+ }
8
+ export declare function date(): ArcDate;
@@ -0,0 +1,10 @@
1
+ import { type util } from "../utils";
2
+ import type { ArcElement } from "./element";
3
+ export declare class ArcDefault<E extends ArcElement> implements ArcElement {
4
+ private parent;
5
+ private defaultValueOrCallback;
6
+ constructor(parent: E, defaultValueOrCallback: (() => ReturnType<E["deserialize"]>) | ReturnType<E["deserialize"]>);
7
+ parse(value: util.FirstArgument<E["parse"]> | undefined): ReturnType<E["parse"]>;
8
+ serialize(value: util.FirstArgument<E["serialize"]> | undefined): ReturnType<E["serialize"]>;
9
+ deserialize(value: util.FirstArgument<E["deserialize"]> | undefined): ReturnType<E["deserialize"]>;
10
+ }
@@ -0,0 +1,5 @@
1
+ export interface ArcElement {
2
+ serialize(value: unknown): unknown;
3
+ deserialize(value: unknown): unknown;
4
+ parse(value: unknown): unknown;
5
+ }
@@ -0,0 +1,9 @@
1
+ import type { util } from "../utils";
2
+ import { ArcBranded } from "./branded";
3
+ import { ArcString } from "./string";
4
+ export declare class ArcId<Brand extends string | symbol> extends ArcBranded<ArcString, Brand> {
5
+ constructor(name: Brand);
6
+ generate(): util.GetType<this>;
7
+ }
8
+ export type ArcIdAny = ArcId<any>;
9
+ export declare function id<Brand extends string | symbol>(name: Brand): ArcId<Brand>;
@@ -0,0 +1,9 @@
1
+ export { array, type ArcArrayAny } from "./array";
2
+ export { type ArcBrandedAny } from "./branded";
3
+ export { ArcDate, date } from "./date";
4
+ export { id } from "./id";
5
+ export { ArcNumber, number } from "./number";
6
+ export { object, type ArcObjectAny } from "./object";
7
+ export { type ArcOptionalAny } from "./optional";
8
+ export { ArcString, string } from "./string";
9
+ export { stringEnum, type ArcStringEnumAny } from "./string-enum";
@@ -0,0 +1,4 @@
1
+ import { ArcPrimitive } from "./abstract-primitive";
2
+ export declare class ArcNumber extends ArcPrimitive<number> {
3
+ }
4
+ export declare function number(): ArcNumber;
@@ -0,0 +1,28 @@
1
+ import { objectUtil, type util } from "../utils";
2
+ import { ArcAbstract } from "./abstract";
3
+ import type { ArcElement } from "./element";
4
+ export declare type ArcRawShape = {
5
+ [k: string]: ArcElement;
6
+ };
7
+ export declare class ArcObject<E extends ArcRawShape> extends ArcAbstract {
8
+ private rawShape;
9
+ constructor(rawShape: E);
10
+ parse(value: {
11
+ [key in keyof E]: util.FirstArgument<E[key]["parse"]>;
12
+ }): {
13
+ [key in keyof E]: ReturnType<E[key]["parse"]>;
14
+ };
15
+ serialize(value: {
16
+ [key in keyof E]: util.FirstArgument<E[key]["serialize"]>;
17
+ }): {
18
+ [key in keyof E]: ReturnType<E[key]["serialize"]>;
19
+ };
20
+ deserialize(value: objectUtil.addQuestionMarks<{
21
+ [key in keyof E]: util.FirstArgument<E[key]["deserialize"]>;
22
+ }>): {
23
+ [key in keyof E]: ReturnType<E[key]["deserialize"]>;
24
+ };
25
+ deserializePath(path: string[], value: any): any;
26
+ }
27
+ export type ArcObjectAny = ArcObject<any>;
28
+ export declare function object<E extends ArcRawShape>(element: E): ArcObject<E>;
@@ -0,0 +1,11 @@
1
+ import { type util } from "../utils";
2
+ import { ArcAbstract } from "./abstract";
3
+ import type { ArcElement } from "./element";
4
+ export declare class ArcOptional<E extends ArcElement> implements ArcElement {
5
+ private parent;
6
+ constructor(parent: E);
7
+ parse(value: util.FirstArgument<E["parse"]> | undefined): ReturnType<E["parse"]> | undefined;
8
+ serialize(value: util.FirstArgument<E["serialize"]> | undefined): ReturnType<E["serialize"]> | undefined;
9
+ deserialize(value: util.FirstArgument<E["deserialize"]> | undefined): ReturnType<E["deserialize"]> | undefined;
10
+ }
11
+ export type ArcOptionalAny = ArcOptional<ArcAbstract>;
@@ -0,0 +1,11 @@
1
+ import { ArcAbstract } from "./abstract";
2
+ export declare class ArcStringEnum<const T extends string[]> extends ArcAbstract {
3
+ private values;
4
+ constructor(values: T);
5
+ parse<Value extends T[number]>(value: Value): Value;
6
+ serialize<Value extends T[number]>(value: Value): Value;
7
+ deserialize<Value extends T[number]>(value: Value): Value;
8
+ getEnumerators(): T;
9
+ }
10
+ export type ArcStringEnumAny = ArcStringEnum<any>;
11
+ export declare function stringEnum<const T extends string[]>(...values: T): ArcStringEnum<T>;
@@ -0,0 +1,4 @@
1
+ import { ArcPrimitive } from "./abstract-primitive";
2
+ export declare class ArcString extends ArcPrimitive<string> {
3
+ }
4
+ export declare function string(): ArcString;
@@ -0,0 +1,3 @@
1
+ export { ArcModel, model, type ArcModelDependencies } from "./model";
2
+ export { type QueryFactoryFunction } from "./query-builder";
3
+ export { type RealTimeCommunicationAdapter, type RealTimeCommunicationAdapterFactory, } from "./rtc";
@@ -0,0 +1,33 @@
1
+ import { Subject } from "rxjs";
2
+ import type { ArcCollectionAny, ArcIndexedCollectionAny } from "../collection";
3
+ import type { CollectionChange } from "../collection/collection-change";
4
+ import type { DBAdapterFactory } from "../collection/db";
5
+ import type { CommandsClient } from "../context/commands";
6
+ import { type ArcContextAny, type ArcContextWithCommandsAny } from "../context/context";
7
+ import type { ArcQuery } from "../context/query";
8
+ import type { QueryFactoryFunction } from "./query-builder";
9
+ import type { RealTimeCommunicationAdapterFactory } from "./rtc";
10
+ export declare class ArcModel<C extends ArcContextWithCommandsAny> {
11
+ private context;
12
+ private rtc;
13
+ private dbAdapterPromise;
14
+ changes$: Subject<CollectionChange>;
15
+ constructor(context: C, dbAdapterFactory: DBAdapterFactory, rtcAdapterFactory: RealTimeCommunicationAdapterFactory);
16
+ query(queryFactory: QueryFactoryFunction<C>): ArcQuery;
17
+ private runQuery;
18
+ commands(): CommandsClient<C["commands"]>;
19
+ executeCommand(command: C["commands"][string], ...args: any[]): Promise<{
20
+ changes: CollectionChange[];
21
+ result: any;
22
+ }>;
23
+ private applyChangesForTransaction;
24
+ private notifyChange;
25
+ applyChanges(changes: CollectionChange[]): Promise<void>;
26
+ getCollection(name: string): ArcCollectionAny | ArcIndexedCollectionAny;
27
+ }
28
+ export type ArcModelAny = ArcModel<ArcContextWithCommandsAny>;
29
+ export type ArcModelDependencies<C extends ArcContextAny> = {
30
+ dbAdapterFactory: DBAdapterFactory;
31
+ rtcAdapterFactory: RealTimeCommunicationAdapterFactory;
32
+ };
33
+ export declare function model<C extends ArcContextWithCommandsAny>(context: C, dependencies: ArcModelDependencies<C>): ArcModel<C>;
@@ -0,0 +1,3 @@
1
+ import type { ArcContextAny } from "../context/context";
2
+ import type { ArcQueryBuilder } from "../context/query-builders";
3
+ export type QueryFactoryFunction<C extends ArcContextAny> = (queryBuilder: ReturnType<C["queryBuilder"]>) => ArcQueryBuilder;
@@ -0,0 +1,6 @@
1
+ import type { CollectionChange } from "../collection/collection-change";
2
+ import type { ArcModelAny } from "./model";
3
+ export interface RealTimeCommunicationAdapter {
4
+ commandExecuted(command: string, changes: CollectionChange[]): void;
5
+ }
6
+ export type RealTimeCommunicationAdapterFactory = (model: ArcModelAny) => RealTimeCommunicationAdapter;
@@ -0,0 +1,2 @@
1
+ import type { RealTimeCommunicationAdapterFactory } from "../model/rtc";
2
+ export declare const rtcClientFactory: RealTimeCommunicationAdapterFactory;
@@ -0,0 +1,2 @@
1
+ import type { CollectionChange } from "../collection";
2
+ export declare function deserializeChanges(changes: CollectionChange[], getCollection: (name: string) => any): CollectionChange[];
@@ -0,0 +1,3 @@
1
+ export { rtcClientFactory } from "./client";
2
+ export { deserializeChanges } from "./deserializeChanges";
3
+ export type { MessageClientToHost, MessageHostToClient } from "./messages";
@@ -0,0 +1,20 @@
1
+ import type { CollectionChange } from "../collection";
2
+ export type MessageClientToHost = {
3
+ type: "sync";
4
+ lastDate: string | null;
5
+ } | {
6
+ type: "command-executed";
7
+ command: string;
8
+ changes: CollectionChange[];
9
+ };
10
+ export type MessageHostToClient = {
11
+ type: "sync-result";
12
+ collection: string;
13
+ items: any[];
14
+ } | {
15
+ type: "collection-changes";
16
+ changes: CollectionChange[];
17
+ } | {
18
+ type: "sync-done";
19
+ date: string;
20
+ };
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.1",
7
+ "version": "0.0.2",
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.",
@@ -28,7 +28,7 @@
28
28
  "typescript": "^5.0.0"
29
29
  },
30
30
  "files": [
31
- "dist/*.js",
32
- "dist/*.d.ts"
31
+ "dist/**/*.js",
32
+ "dist/**/*.d.ts"
33
33
  ]
34
34
  }