@arcote.tech/arc 0.0.23 → 0.0.25

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.
@@ -1,5 +1,5 @@
1
1
  import { ArcContextElement } from "../context/element";
2
- import type { ArcIdAny } from "../elements/id";
2
+ import { type ArcIdAny } from "../elements/id";
3
3
  import { type ArcObjectAny } from "../elements/object";
4
4
  import { objectUtil, type DeepPartial, type util } from "../utils";
5
5
  import type { DataStorage } from "../data-storage";
@@ -0,0 +1,6 @@
1
+ import { IndexQueryArgument } from "./interface";
2
+ export declare function indexQueryPredicate<T>(
3
+ item: T,
4
+ query: IndexQueryArgument<any>,
5
+ ): boolean;
6
+ //# sourceMappingURL=index-query.d.ts.map
@@ -0,0 +1,3 @@
1
+ import { type IndexQueryArgument } from "./interface";
2
+ export declare function indexQueryPredicate<T>(item: T, query: IndexQueryArgument<any>): boolean;
3
+ //# sourceMappingURL=index-query.d.ts.map
@@ -1,10 +1,16 @@
1
1
  import type { util } from "../utils";
2
2
  import { ArcBranded } from "./branded";
3
3
  import { ArcString } from "./string";
4
+ export declare class ArcCustomId<Brand extends string | symbol, CreateFn extends (...args: any[]) => string> extends ArcBranded<ArcString, Brand> {
5
+ private createFn;
6
+ constructor(name: Brand, createFn: CreateFn);
7
+ get(...args: Parameters<CreateFn>): util.GetType<this>;
8
+ }
4
9
  export declare class ArcId<Brand extends string | symbol> extends ArcBranded<ArcString, Brand> {
5
10
  constructor(name: Brand);
6
11
  generate(): util.GetType<this>;
7
12
  }
8
- export type ArcIdAny = ArcId<any>;
13
+ export type ArcIdAny = ArcId<any> | ArcCustomId<any, any>;
9
14
  export declare function id<Brand extends string | symbol>(name: Brand): ArcId<Brand>;
15
+ export declare function customId<Brand extends string | symbol, CreateFn extends (...args: any[]) => string>(name: Brand, createFn: CreateFn): ArcCustomId<Brand, CreateFn>;
10
16
  //# sourceMappingURL=id.d.ts.map
package/dist/index.js CHANGED
@@ -3,6 +3,146 @@ class ArcContextElement {
3
3
  $event;
4
4
  }
5
5
 
6
+ // elements/optional.ts
7
+ class ArcOptional {
8
+ parent;
9
+ constructor(parent) {
10
+ this.parent = parent;
11
+ }
12
+ parse(value) {
13
+ if (!value)
14
+ return null;
15
+ return this.parent.parse(value);
16
+ }
17
+ serialize(value) {
18
+ if (value)
19
+ return this.parent.serialize(value);
20
+ return null;
21
+ }
22
+ deserialize(value) {
23
+ if (!value)
24
+ return null;
25
+ return this.parent.deserialize(value);
26
+ }
27
+ }
28
+
29
+ // elements/branded.ts
30
+ class ArcBranded {
31
+ parent;
32
+ brand;
33
+ constructor(parent, brand) {
34
+ this.parent = parent;
35
+ this.brand = brand;
36
+ }
37
+ serialize(value) {
38
+ return this.parent.serialize(value);
39
+ }
40
+ deserialize(value) {
41
+ return this.parent.deserialize(value);
42
+ }
43
+ parse(value) {
44
+ return this.parent.parse(value);
45
+ }
46
+ optional() {
47
+ return new ArcOptional(this);
48
+ }
49
+ }
50
+
51
+ // elements/default.ts
52
+ class ArcDefault {
53
+ parent;
54
+ defaultValueOrCallback;
55
+ constructor(parent, defaultValueOrCallback) {
56
+ this.parent = parent;
57
+ this.defaultValueOrCallback = defaultValueOrCallback;
58
+ }
59
+ parse(value) {
60
+ if (value)
61
+ return this.parent.parse(value);
62
+ if (typeof this.defaultValueOrCallback === "function") {
63
+ return this.defaultValueOrCallback();
64
+ } else
65
+ return this.defaultValueOrCallback;
66
+ }
67
+ serialize(value) {
68
+ return this.parent.serialize(value);
69
+ }
70
+ deserialize(value) {
71
+ if (value)
72
+ return this.parent.deserialize(value);
73
+ if (typeof this.defaultValueOrCallback === "function") {
74
+ return this.defaultValueOrCallback();
75
+ } else
76
+ return this.defaultValueOrCallback;
77
+ }
78
+ }
79
+
80
+ // elements/abstract.ts
81
+ class ArcAbstract {
82
+ default(defaultValueOrCallback) {
83
+ return new ArcDefault(this, defaultValueOrCallback);
84
+ }
85
+ optional() {
86
+ return new ArcOptional(this);
87
+ }
88
+ branded(name) {
89
+ return new ArcBranded(this, name);
90
+ }
91
+ }
92
+
93
+ // elements/abstract-primitive.ts
94
+ class ArcPrimitive extends ArcAbstract {
95
+ constructor() {
96
+ super();
97
+ }
98
+ serialize(value) {
99
+ return value;
100
+ }
101
+ parse(value) {
102
+ return value;
103
+ }
104
+ deserialize(value) {
105
+ return value;
106
+ }
107
+ }
108
+
109
+ // elements/string.ts
110
+ class ArcString extends ArcPrimitive {
111
+ }
112
+ function string() {
113
+ return new ArcString;
114
+ }
115
+
116
+ // elements/id.ts
117
+ class ArcCustomId extends ArcBranded {
118
+ createFn;
119
+ constructor(name, createFn) {
120
+ super(string(), name);
121
+ this.createFn = createFn;
122
+ }
123
+ get(...args) {
124
+ return this.createFn(...args);
125
+ }
126
+ }
127
+
128
+ class ArcId extends ArcBranded {
129
+ constructor(name) {
130
+ super(string(), name);
131
+ }
132
+ generate() {
133
+ var timestamp = (new Date().getTime() / 1000 | 0).toString(16);
134
+ return timestamp + "xxxxxxxxxxxxxxxx".replace(/[x]/g, function() {
135
+ return (Math.random() * 16 | 0).toString(16);
136
+ }).toLowerCase();
137
+ }
138
+ }
139
+ function id(name) {
140
+ return new ArcId(name);
141
+ }
142
+ function customId(name, createFn) {
143
+ return new ArcCustomId(name, createFn);
144
+ }
145
+
6
146
  // context/query.ts
7
147
  class ArcQuery {
8
148
  lastResult;
@@ -54,8 +194,8 @@ class QueryCollectionResult {
54
194
  constructor(result) {
55
195
  this.result = result;
56
196
  }
57
- get(id) {
58
- return id ? this.result.find((r) => r._id === id) : undefined;
197
+ get(id2) {
198
+ return id2 ? this.result.find((r) => r._id === id2) : undefined;
59
199
  }
60
200
  map(callbackfn) {
61
201
  return this.result.map(callbackfn);
@@ -161,6 +301,34 @@ class ArcAllItemsQueryBuilder extends ArcManyItemsQueryBuilder {
161
301
  }
162
302
  }
163
303
 
304
+ // db/index-query.ts
305
+ function indexQueryPredicate(item, query) {
306
+ if (!("$gt" in query) && !("$gte" in query) && !("$lt" in query) && !("$lte" in query)) {
307
+ return Object.entries(query).every(([key, value]) => item[key] === value);
308
+ }
309
+ if (query.$gt) {
310
+ const isGreaterThan = Object.entries(query.$gt).every(([key, value]) => item[key] > value);
311
+ if (!isGreaterThan)
312
+ return false;
313
+ }
314
+ if (query.$gte) {
315
+ const isGreaterThanOrEqual = Object.entries(query.$gte).every(([key, value]) => item[key] >= value);
316
+ if (!isGreaterThanOrEqual)
317
+ return false;
318
+ }
319
+ if (query.$lt) {
320
+ const isLessThan = Object.entries(query.$lt).every(([key, value]) => item[key] < value);
321
+ if (!isLessThan)
322
+ return false;
323
+ }
324
+ if (query.$lte) {
325
+ const isLessThanOrEqual = Object.entries(query.$lte).every(([key, value]) => item[key] <= value);
326
+ if (!isLessThanOrEqual)
327
+ return false;
328
+ }
329
+ return true;
330
+ }
331
+
164
332
  // collection/queries/indexed.ts
165
333
  class ArcIndexedItemsQuery extends ArcManyItemsQuery {
166
334
  index;
@@ -177,10 +345,7 @@ class ArcIndexedItemsQuery extends ArcManyItemsQuery {
177
345
  checkItem(item) {
178
346
  if (!super.checkItem(item))
179
347
  return false;
180
- const correct = Object.entries(this.data).every(([key, value]) => item[key] === value);
181
- if (!correct)
182
- return false;
183
- return true;
348
+ return indexQueryPredicate(item, this.data);
184
349
  }
185
350
  async fetch(store) {
186
351
  const results = await store.findByIndex(this.index, this.data, this.bindedChangeHandler);
@@ -208,10 +373,10 @@ class ArcIndexedItemsQueryBuilder extends ArcManyItemsQueryBuilder {
208
373
 
209
374
  // collection/queries/one-item.ts
210
375
  class ArcOneItemQuery extends ArcCollectionQuery {
211
- id;
212
- constructor(collection, id) {
376
+ id2;
377
+ constructor(collection, id2) {
213
378
  super(collection);
214
- this.id = id;
379
+ this.id = id2;
215
380
  }
216
381
  onChange(change) {
217
382
  if (change.id !== this.id)
@@ -231,11 +396,11 @@ class ArcOneItemQuery extends ArcCollectionQuery {
231
396
  // collection/query-builders/one-item.ts
232
397
  class ArcOneItemQueryBuilder extends ArcQueryBuilder {
233
398
  collection;
234
- id;
235
- constructor(collection, id) {
399
+ id2;
400
+ constructor(collection, id2) {
236
401
  super();
237
402
  this.collection = collection;
238
- this.id = id;
403
+ this.id = id2;
239
404
  }
240
405
  toQuery() {
241
406
  return new ArcOneItemQuery(this.collection, this.id);
@@ -243,19 +408,15 @@ class ArcOneItemQueryBuilder extends ArcQueryBuilder {
243
408
  }
244
409
 
245
410
  // collection/collection.ts
246
- function collection(name, id, schema, options = {}) {
247
- return new ArcCollection(name, id, schema, options);
248
- }
249
-
250
411
  class ArcCollection extends ArcContextElement {
251
412
  name;
252
- id;
413
+ id2;
253
414
  schema;
254
415
  options;
255
- constructor(name, id, schema, options) {
416
+ constructor(name, id2, schema, options) {
256
417
  super();
257
418
  this.name = name;
258
- this.id = id;
419
+ this.id = id2;
259
420
  this.schema = schema;
260
421
  this.options = options;
261
422
  }
@@ -274,17 +435,19 @@ class ArcCollection extends ArcContextElement {
274
435
  queryBuilder() {
275
436
  return {
276
437
  all: () => new ArcAllItemsQueryBuilder(this),
277
- one: (id) => new ArcOneItemQueryBuilder(this, id)
438
+ one: (id2) => new ArcOneItemQueryBuilder(this, id2)
278
439
  };
279
440
  }
280
441
  commandContext(dataStorage, publishEvent) {
281
442
  const store = dataStorage.getStore(this.name);
282
443
  return {
283
444
  add: async (data) => {
284
- const id = this.id.generate();
445
+ if (this.id instanceof ArcCustomId)
446
+ throw new Error("Collection with custom id not support 'add' method");
447
+ const id2 = this.id.generate();
285
448
  const parsed = this.schema.parse(data);
286
449
  const body = {
287
- _id: id,
450
+ _id: id2,
288
451
  ...parsed
289
452
  };
290
453
  await store.set(body);
@@ -292,16 +455,16 @@ class ArcCollection extends ArcContextElement {
292
455
  type: "set",
293
456
  to: body
294
457
  });
295
- return { id };
458
+ return { id: id2 };
296
459
  },
297
- remove: async (id) => {
298
- await store.remove(id);
460
+ remove: async (id2) => {
461
+ await store.remove(id2);
299
462
  return { success: true };
300
463
  },
301
- set: async (id, data) => {
464
+ set: async (id2, data) => {
302
465
  const parsed = this.schema.parse(data);
303
466
  const body = {
304
- _id: id,
467
+ _id: id2,
305
468
  ...parsed
306
469
  };
307
470
  await store.set(body);
@@ -314,12 +477,12 @@ class ArcCollection extends ArcContextElement {
314
477
  all: async () => {
315
478
  return store.findAll();
316
479
  },
317
- one: async (id) => {
318
- return store.findById(id);
480
+ one: async (id2) => {
481
+ return store.findById(id2);
319
482
  },
320
- modify: async (id, data) => {
483
+ modify: async (id2, data) => {
321
484
  const deserialized = this.schema.serializePartial(data);
322
- const { from, to } = await store.modify(id, deserialized);
485
+ const { from, to } = await store.modify(id2, deserialized);
323
486
  await publishEvent({
324
487
  type: "modify",
325
488
  changes: deserialized,
@@ -327,8 +490,8 @@ class ArcCollection extends ArcContextElement {
327
490
  to
328
491
  });
329
492
  },
330
- edit: async (id, editCallback) => {
331
- const { from, to } = await store.mutate(id, editCallback);
493
+ edit: async (id2, editCallback) => {
494
+ const { from, to } = await store.mutate(id2, editCallback);
332
495
  await publishEvent({
333
496
  type: "mutate",
334
497
  from,
@@ -344,8 +507,8 @@ class ArcCollection extends ArcContextElement {
344
507
 
345
508
  class ArcIndexedCollection extends ArcCollection {
346
509
  indexes;
347
- constructor(name, id, schema, options, indexes) {
348
- super(name, id, schema, options);
510
+ constructor(name, id2, schema, options, indexes) {
511
+ super(name, id2, schema, options);
349
512
  this.indexes = indexes;
350
513
  }
351
514
  commandContext(dataStorage, publishEvent) {
@@ -376,11 +539,10 @@ class ArcIndexedCollection extends ArcCollection {
376
539
  });
377
540
  }
378
541
  }
379
- // context/context.ts
380
- function context(version, elements, commands, listeners) {
381
- return new ArcContext(version, elements, commands, listeners);
542
+ function collection(name, id2, schema, options = {}) {
543
+ return new ArcCollection(name, id2, schema, options);
382
544
  }
383
-
545
+ // context/context.ts
384
546
  class ArcContext {
385
547
  version;
386
548
  elements;
@@ -392,16 +554,16 @@ class ArcContext {
392
554
  this.elements = elements;
393
555
  this.commands = commands;
394
556
  this.listeners = listeners;
395
- this.elementsMap = Object.fromEntries(elements.map((collection3) => [collection3.name, collection3]));
557
+ this.elementsMap = Object.fromEntries(elements.map((element) => [element.name, element]));
396
558
  }
397
559
  queryBuilder() {
398
560
  return new Proxy({}, {
399
561
  get: (target, name) => {
400
- const collection3 = this.elementsMap[name];
401
- if (!collection3) {
562
+ const element = this.elementsMap[name];
563
+ if (!element) {
402
564
  throw new Error(`Collection "${name}" not found`);
403
565
  }
404
- return collection3.queryBuilder();
566
+ return element.queryBuilder();
405
567
  }
406
568
  });
407
569
  }
@@ -447,6 +609,9 @@ class ArcContext {
447
609
  });
448
610
  }
449
611
  }
612
+ function context(version, elements, commands, listeners) {
613
+ return new ArcContext(version, elements, commands, listeners);
614
+ }
450
615
  // data-storage/data-storage.abstract.ts
451
616
  class DataStorage {
452
617
  async commitChanges(changes) {
@@ -499,30 +664,30 @@ class StoreState {
499
664
  };
500
665
  await this.applyChanges([change]);
501
666
  }
502
- async remove(id) {
667
+ async remove(id2) {
503
668
  const change = {
504
669
  type: "delete",
505
- id
670
+ id: id2
506
671
  };
507
672
  await this.applyChanges([change]);
508
673
  }
509
- async modify(id, data) {
674
+ async modify(id2, data) {
510
675
  const change = {
511
676
  type: "modify",
512
- id,
677
+ id: id2,
513
678
  data
514
679
  };
515
680
  const { from, to } = await this.applyChange(change);
516
681
  return { from, to };
517
682
  }
518
- async mutate(id, editCallback) {
519
- const object = await this.findById(id);
683
+ async mutate(id2, editCallback) {
684
+ const object = await this.findById(id2);
520
685
  const [draft, finalize] = create(object || {}, { enablePatches: true });
521
686
  await editCallback(draft);
522
687
  const [_, patches] = finalize();
523
688
  const change = {
524
689
  type: "mutate",
525
- id,
690
+ id: id2,
526
691
  patches
527
692
  };
528
693
  const { from, to } = await this.applyChange(change);
@@ -623,12 +788,12 @@ class ForkedStoreState extends StoreState {
623
788
  this.notifyListeners(events);
624
789
  }
625
790
  }
626
- async findById(id, listener) {
791
+ async findById(id2, listener) {
627
792
  if (listener)
628
- this.listeners.set(listener, { callback: listener, id });
629
- if (this.changedItems.has(id))
630
- return this.changedItems.get(id);
631
- return await this.master.findById(id);
793
+ this.listeners.set(listener, { callback: listener, id: id2 });
794
+ if (this.changedItems.has(id2))
795
+ return this.changedItems.get(id2);
796
+ return await this.master.findById(id2);
632
797
  }
633
798
  async findByIndex(index, data, listener) {
634
799
  if (listener)
@@ -636,16 +801,16 @@ class ForkedStoreState extends StoreState {
636
801
  const parentResult = await this.master.findByIndex(index, data);
637
802
  const results = new Map;
638
803
  parentResult.forEach((item) => results.set(item._id, item));
639
- for (const [id, changedItem] of this.changedItems) {
804
+ for (const [id2, changedItem] of this.changedItems) {
640
805
  if (changedItem === null) {
641
- results.delete(id);
806
+ results.delete(id2);
642
807
  continue;
643
808
  }
644
809
  const matches = Object.entries(data).every(([key, value]) => changedItem[key] === value);
645
810
  if (matches) {
646
- results.set(id, changedItem);
811
+ results.set(id2, changedItem);
647
812
  } else {
648
- results.delete(id);
813
+ results.delete(id2);
649
814
  }
650
815
  }
651
816
  return Array.from(results.values());
@@ -655,9 +820,9 @@ class ForkedStoreState extends StoreState {
655
820
  this.listeners.set(listener, { callback: listener });
656
821
  const parentResult = await this.master.findAll();
657
822
  return parentResult.map((item) => {
658
- const id = item._id;
659
- if (this.changedItems.has(id))
660
- return this.changedItems.get(id);
823
+ const id2 = item._id;
824
+ if (this.changedItems.has(id2))
825
+ return this.changedItems.get(id2);
661
826
  return item;
662
827
  });
663
828
  }
@@ -785,19 +950,19 @@ class MasterStoreState extends StoreState {
785
950
  this.notifyListeners(events);
786
951
  }
787
952
  }
788
- async findById(id, listener) {
789
- if (!id)
953
+ async findById(id2, listener) {
954
+ if (!id2)
790
955
  return;
791
956
  if (listener)
792
- this.listeners.set(listener, { callback: listener, id });
793
- if (this.items.has(id))
794
- return this.items.get(id);
957
+ this.listeners.set(listener, { callback: listener, id: id2 });
958
+ if (this.items.has(id2))
959
+ return this.items.get(id2);
795
960
  const transaction = await this.dataStorage.getReadTransaction();
796
- const result = await transaction.findById(this.storeName, id);
961
+ const result = await transaction.findById(this.storeName, id2);
797
962
  const item = result && this.deserialize ? this.deserialize(result) : result;
798
963
  if (!item)
799
964
  return;
800
- this.items.set(id, item);
965
+ this.items.set(id2, item);
801
966
  return item;
802
967
  }
803
968
  async findByIndex(index, data, listener) {
@@ -807,17 +972,16 @@ class MasterStoreState extends StoreState {
807
972
  const results2 = Array.from(this.items.values()).filter((item) => {
808
973
  if (!item)
809
974
  return false;
810
- const notCorrect = Object.entries(data).some(([key, value]) => item[key] !== value);
811
- return !notCorrect;
975
+ return indexQueryPredicate(item, data);
812
976
  });
813
977
  return results2;
814
978
  }
815
979
  const transaction = await this.dataStorage.getReadTransaction();
816
980
  const dbResults = await transaction.findByIndex(this.storeName, index, data);
817
981
  const results = dbResults.map((item) => {
818
- const id = item._id;
819
- if (this.items.has(id))
820
- return this.items.get(id);
982
+ const id2 = item._id;
983
+ if (this.items.has(id2))
984
+ return this.items.get(id2);
821
985
  const processedItem = this.deserialize ? this.deserialize(item) : item;
822
986
  return processedItem;
823
987
  });
@@ -831,9 +995,9 @@ class MasterStoreState extends StoreState {
831
995
  const transaction = await this.dataStorage.getReadTransaction();
832
996
  const dbResults = await transaction.findAll(this.storeName);
833
997
  const items = dbResults.map((item) => {
834
- const id = item._id;
835
- if (this.items.has(id))
836
- return this.items.get(id);
998
+ const id2 = item._id;
999
+ if (this.items.has(id2))
1000
+ return this.items.get(id2);
837
1001
  const processedItem = this.deserialize ? this.deserialize(item) : item;
838
1002
  this.items.set(processedItem._id, processedItem);
839
1003
  return processedItem;
@@ -886,98 +1050,7 @@ class MasterDataStorage extends DataStorage {
886
1050
  await this.rtcAdapter.sync(progressCallback);
887
1051
  }
888
1052
  }
889
- // elements/optional.ts
890
- class ArcOptional {
891
- parent;
892
- constructor(parent) {
893
- this.parent = parent;
894
- }
895
- parse(value) {
896
- if (!value)
897
- return null;
898
- return this.parent.parse(value);
899
- }
900
- serialize(value) {
901
- if (value)
902
- return this.parent.serialize(value);
903
- return null;
904
- }
905
- deserialize(value) {
906
- if (!value)
907
- return null;
908
- return this.parent.deserialize(value);
909
- }
910
- }
911
-
912
- // elements/branded.ts
913
- class ArcBranded {
914
- parent;
915
- brand;
916
- constructor(parent, brand) {
917
- this.parent = parent;
918
- this.brand = brand;
919
- }
920
- serialize(value) {
921
- return this.parent.serialize(value);
922
- }
923
- deserialize(value) {
924
- return this.parent.deserialize(value);
925
- }
926
- parse(value) {
927
- return this.parent.parse(value);
928
- }
929
- optional() {
930
- return new ArcOptional(this);
931
- }
932
- }
933
-
934
- // elements/default.ts
935
- class ArcDefault {
936
- parent;
937
- defaultValueOrCallback;
938
- constructor(parent, defaultValueOrCallback) {
939
- this.parent = parent;
940
- this.defaultValueOrCallback = defaultValueOrCallback;
941
- }
942
- parse(value) {
943
- if (value)
944
- return this.parent.parse(value);
945
- if (typeof this.defaultValueOrCallback === "function") {
946
- return this.defaultValueOrCallback();
947
- } else
948
- return this.defaultValueOrCallback;
949
- }
950
- serialize(value) {
951
- return this.parent.serialize(value);
952
- }
953
- deserialize(value) {
954
- if (value)
955
- return this.parent.deserialize(value);
956
- if (typeof this.defaultValueOrCallback === "function") {
957
- return this.defaultValueOrCallback();
958
- } else
959
- return this.defaultValueOrCallback;
960
- }
961
- }
962
-
963
- // elements/abstract.ts
964
- class ArcAbstract {
965
- default(defaultValueOrCallback) {
966
- return new ArcDefault(this, defaultValueOrCallback);
967
- }
968
- optional() {
969
- return new ArcOptional(this);
970
- }
971
- branded(name) {
972
- return new ArcBranded(this, name);
973
- }
974
- }
975
-
976
1053
  // elements/object.ts
977
- function object(element) {
978
- return new ArcObject(element);
979
- }
980
-
981
1054
  class ArcObject extends ArcAbstract {
982
1055
  rawShape;
983
1056
  constructor(rawShape) {
@@ -1040,12 +1113,11 @@ class ArcObject extends ArcAbstract {
1040
1113
  }, {});
1041
1114
  }
1042
1115
  }
1043
-
1044
- // elements/array.ts
1045
- function array(element) {
1046
- return new ArcArray(element);
1116
+ function object(element) {
1117
+ return new ArcObject(element);
1047
1118
  }
1048
1119
 
1120
+ // elements/array.ts
1049
1121
  class ArcArray extends ArcAbstract {
1050
1122
  parent;
1051
1123
  constructor(parent) {
@@ -1071,34 +1143,16 @@ class ArcArray extends ArcAbstract {
1071
1143
  return this.parent.deserialize(value);
1072
1144
  }
1073
1145
  }
1074
- // elements/abstract-primitive.ts
1075
- class ArcPrimitive extends ArcAbstract {
1076
- constructor() {
1077
- super();
1078
- }
1079
- serialize(value) {
1080
- return value;
1081
- }
1082
- parse(value) {
1083
- return value;
1084
- }
1085
- deserialize(value) {
1086
- return value;
1087
- }
1146
+ function array(element) {
1147
+ return new ArcArray(element);
1088
1148
  }
1089
-
1090
1149
  // elements/boolean.ts
1150
+ class ArcBoolean extends ArcPrimitive {
1151
+ }
1091
1152
  function boolean() {
1092
1153
  return new ArcBoolean;
1093
1154
  }
1094
-
1095
- class ArcBoolean extends ArcPrimitive {
1096
- }
1097
1155
  // elements/date.ts
1098
- function date() {
1099
- return new ArcDate;
1100
- }
1101
-
1102
1156
  class ArcDate extends ArcAbstract {
1103
1157
  constructor() {
1104
1158
  super();
@@ -1113,42 +1167,16 @@ class ArcDate extends ArcAbstract {
1113
1167
  return new Date(value);
1114
1168
  }
1115
1169
  }
1116
- // elements/string.ts
1117
- function string() {
1118
- return new ArcString;
1119
- }
1120
-
1121
- class ArcString extends ArcPrimitive {
1122
- }
1123
-
1124
- // elements/id.ts
1125
- function id(name) {
1126
- return new ArcId(name);
1127
- }
1128
-
1129
- class ArcId extends ArcBranded {
1130
- constructor(name) {
1131
- super(string(), name);
1132
- }
1133
- generate() {
1134
- var timestamp = (new Date().getTime() / 1000 | 0).toString(16);
1135
- return timestamp + "xxxxxxxxxxxxxxxx".replace(/[x]/g, function() {
1136
- return (Math.random() * 16 | 0).toString(16);
1137
- }).toLowerCase();
1138
- }
1170
+ function date() {
1171
+ return new ArcDate;
1139
1172
  }
1140
1173
  // elements/number.ts
1174
+ class ArcNumber extends ArcPrimitive {
1175
+ }
1141
1176
  function number() {
1142
1177
  return new ArcNumber;
1143
1178
  }
1144
-
1145
- class ArcNumber extends ArcPrimitive {
1146
- }
1147
1179
  // elements/record.ts
1148
- function record(key, element) {
1149
- return new ArcRecord(key, element);
1150
- }
1151
-
1152
1180
  class ArcRecord extends ArcAbstract {
1153
1181
  key;
1154
1182
  element;
@@ -1182,11 +1210,10 @@ class ArcRecord extends ArcAbstract {
1182
1210
  }, {});
1183
1211
  }
1184
1212
  }
1185
- // elements/string-enum.ts
1186
- function stringEnum(...values) {
1187
- return new ArcStringEnum(values);
1213
+ function record(key, element) {
1214
+ return new ArcRecord(key, element);
1188
1215
  }
1189
-
1216
+ // elements/string-enum.ts
1190
1217
  class ArcStringEnum extends ArcAbstract {
1191
1218
  values;
1192
1219
  constructor(values) {
@@ -1206,6 +1233,9 @@ class ArcStringEnum extends ArcAbstract {
1206
1233
  return this.values;
1207
1234
  }
1208
1235
  }
1236
+ function stringEnum(...values) {
1237
+ return new ArcStringEnum(values);
1238
+ }
1209
1239
  // rtc/client.ts
1210
1240
  class RTCClient {
1211
1241
  storage;
@@ -1366,10 +1396,6 @@ class ArcStateQueryBuilder extends ArcQueryBuilder {
1366
1396
  }
1367
1397
 
1368
1398
  // state/state.ts
1369
- function state(name, schema) {
1370
- return new ArcState(name, schema);
1371
- }
1372
-
1373
1399
  class ArcState extends ArcContextElement {
1374
1400
  name;
1375
1401
  schema;
@@ -1412,6 +1438,9 @@ class ArcState extends ArcContextElement {
1412
1438
  };
1413
1439
  }
1414
1440
  }
1441
+ function state(name, schema) {
1442
+ return new ArcState(name, schema);
1443
+ }
1415
1444
  export {
1416
1445
  stringEnum,
1417
1446
  string,
@@ -1422,6 +1451,7 @@ export {
1422
1451
  number,
1423
1452
  id,
1424
1453
  date,
1454
+ customId,
1425
1455
  context,
1426
1456
  collection,
1427
1457
  boolean,
@@ -1444,6 +1474,7 @@ export {
1444
1474
  ArcIndexedCollection,
1445
1475
  ArcId,
1446
1476
  ArcDate,
1477
+ ArcCustomId,
1447
1478
  ArcCollectionQuery,
1448
1479
  ArcCollection,
1449
1480
  ArcBranded,
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.23",
7
+ "version": "0.0.25",
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.",