@arcote.tech/arc 0.0.7 → 0.0.9

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.
@@ -31,8 +31,8 @@ declare class ArcCollection<Name extends string, Id extends ArcIdAny, Schema ext
31
31
  commandContext(transaction: ReadTransaction, changes: CollectionChange[], getDraft: GetDraft<any>): {
32
32
  one: (id: util.GetType<Id>) => Deserialize<Id, Schema>;
33
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>;
34
+ add: (data: objectUtil.addQuestionMarks<util.FirstArgument<Schema["serialize"]>>) => Promise<any>;
35
+ set: (id: util.GetType<Id>, data: util.FirstArgument<Schema["serialize"]>) => Promise<any>;
36
36
  };
37
37
  applyChange(transaction: ReadWriteTransaction, change: CollectionChange, events: CollectionChange[]): Promise<void>;
38
38
  indexBy<Indexes extends keyof ReturnType<Schema["deserialize"]>, const I extends {
@@ -26,6 +26,6 @@ declare class ArcContextWithCommands<const C extends ArcContextElement[], Cmds e
26
26
  constructor(context: C, commands: Cmds);
27
27
  }
28
28
  export type ArcContextAny = ArcContext<ArcContextElement[]>;
29
- export type ArcContextWithCommandsAny = ArcContextWithCommands<ArcContextElement[], any>;
29
+ export type ArcContextWithCommandsAny = ArcContextWithCommands<any, any>;
30
30
  export declare function context<const C extends ArcContextElement[]>(...collections: C): ArcContext<C>;
31
31
  export {};
@@ -1,6 +1,7 @@
1
1
  import { type util } from "../utils";
2
2
  import { ArcAbstract } from "./abstract";
3
- export declare class ArcArray<E extends ArcAbstract> extends ArcAbstract {
3
+ import type { ArcElement } from "./element";
4
+ export declare class ArcArray<E extends ArcElement> extends ArcAbstract {
4
5
  private parent;
5
6
  constructor(parent: E);
6
7
  parse(value: util.FirstArgument<E["deserialize"]>[]): ReturnType<E["parse"]>[];
@@ -9,4 +10,4 @@ export declare class ArcArray<E extends ArcAbstract> extends ArcAbstract {
9
10
  deserializePath(path: string[], value: any): any;
10
11
  }
11
12
  export type ArcArrayAny = ArcArray<any>;
12
- export declare function array<E extends ArcAbstract>(element: E): ArcArray<E>;
13
+ export declare function array<E extends ArcElement>(element: E): ArcArray<E>;
@@ -1,4 +1,5 @@
1
1
  export * from "./array";
2
+ export * from "./boolean";
2
3
  export * from "./branded";
3
4
  export * from "./date";
4
5
  export * from "./id";
package/dist/index.js CHANGED
@@ -569,6 +569,29 @@ class ArcArray extends ArcAbstract {
569
569
  return this.parent.deserialize(value);
570
570
  }
571
571
  }
572
+ // elements/abstract-primitive.ts
573
+ class ArcPrimitive extends ArcAbstract {
574
+ constructor() {
575
+ super();
576
+ }
577
+ serialize(value) {
578
+ return value;
579
+ }
580
+ parse(value) {
581
+ return value;
582
+ }
583
+ deserialize(value) {
584
+ return value;
585
+ }
586
+ }
587
+
588
+ // elements/boolean.ts
589
+ function boolean() {
590
+ return new ArcBoolean;
591
+ }
592
+
593
+ class ArcBoolean extends ArcPrimitive {
594
+ }
572
595
  // elements/date.ts
573
596
  function date() {
574
597
  return new ArcDate;
@@ -588,22 +611,6 @@ class ArcDate extends ArcAbstract {
588
611
  return new Date(value);
589
612
  }
590
613
  }
591
- // elements/abstract-primitive.ts
592
- class ArcPrimitive extends ArcAbstract {
593
- constructor() {
594
- super();
595
- }
596
- serialize(value) {
597
- return value;
598
- }
599
- parse(value) {
600
- return value;
601
- }
602
- deserialize(value) {
603
- return value;
604
- }
605
- }
606
-
607
614
  // elements/string.ts
608
615
  function string() {
609
616
  return new ArcString;
@@ -817,16 +824,21 @@ class RTCClient {
817
824
  console.error(`Collection ${collection3} not found`);
818
825
  return;
819
826
  }
820
- const deserializedItems = items.map((item) => c.deserialize(item));
821
- this.model.executeCommand(async (ctx) => {
822
- for (const item of deserializedItems) {
823
- const id3 = item._id;
824
- if (!item)
825
- await ctx[collection3].remove(id3);
826
- else
827
- await ctx[collection3].set(id3, item);
827
+ const deserializedItems = items.map((item) => {
828
+ if (item.deleted) {
829
+ return {
830
+ collection: collection3,
831
+ type: "delete",
832
+ id: item._id
833
+ };
828
834
  }
835
+ return {
836
+ collection: collection3,
837
+ type: "set",
838
+ body: item
839
+ };
829
840
  });
841
+ this.model.applyChanges(deserializedItems);
830
842
  }
831
843
  break;
832
844
  case "sync-done":
@@ -860,6 +872,7 @@ export {
860
872
  date,
861
873
  context,
862
874
  collection,
875
+ boolean,
863
876
  array2 as array,
864
877
  ArcStringEnum,
865
878
  ArcString,
@@ -872,5 +885,6 @@ export {
872
885
  ArcDate,
873
886
  ArcCollectionQuery,
874
887
  ArcBranded,
888
+ ArcBoolean,
875
889
  ArcArray
876
890
  };
package/dist/utils.d.ts CHANGED
@@ -5,13 +5,13 @@ export declare namespace objectUtil {
5
5
  export type MergeShapes<U, V> = {
6
6
  [k in Exclude<keyof U, keyof V>]: U[k];
7
7
  } & V;
8
- type optionalKeys<T extends object> = {
8
+ type optionalKeys<T extends any> = {
9
9
  [k in keyof T]: undefined extends T[k] ? k : never;
10
10
  }[keyof T];
11
- type requiredKeys<T extends object> = {
11
+ type requiredKeys<T extends any> = {
12
12
  [k in keyof T]: undefined extends T[k] ? never : k;
13
13
  }[keyof T];
14
- export type addQuestionMarks<T extends object> = simplify<{
14
+ export type addQuestionMarks<T extends any> = simplify<{
15
15
  [K in requiredKeys<T>]: T[K];
16
16
  } & {
17
17
  [K in optionalKeys<T>]?: T[K];
@@ -49,11 +49,14 @@ export type ContextTypes<Ctx extends {
49
49
  }> = Ctx["collections"] extends (ArcCollectionAny | ArcIndexedCollectionAny)[] ? {
50
50
  [Collection in Ctx["collections"][number] as `${Collection["name"]}.bodyWithoutId`]: util.GetType<Collection["schema"]>;
51
51
  } & {
52
- [Collection in Ctx["collections"][number] as `${Collection["name"]}.setBody`]: util.FirstArgument<Collection["schema"]["parse"]>;
52
+ [Collection in Ctx["collections"][number] as `${Collection["name"]}.setBody`]: objectUtil.addQuestionMarks<util.FirstArgument<Collection["schema"]["parse"]>>;
53
53
  } & {
54
54
  [Collection in Ctx["collections"][number] as `${Collection["name"]}.id`]: util.GetType<Collection["id"]>;
55
55
  } & {
56
56
  [Collection in Ctx["collections"][number] as `${Collection["name"]}.body`]: util.CollectionItemWithId<Collection>;
57
57
  } & {
58
- [Collection in Ctx["collections"][number] as `${Collection["name"]}.queryCollectionResult`]: QueryCollectionResult<Collection>;
58
+ [Collection in Ctx["collections"][number] as `${Collection["name"]}.queryCollectionResult`]: Omit<QueryCollectionResult<Collection>, "result">;
59
59
  } : never;
60
+ export type infer<E extends {
61
+ deserialize: (...args: any) => any;
62
+ }> = ReturnType<E["deserialize"]>;
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.7",
7
+ "version": "0.0.9",
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.",