@rljson/io 0.0.46 → 0.0.48

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.
@@ -9,35 +9,47 @@
9
9
  {
10
10
  "key": "_hash",
11
11
  "type": "string",
12
- "_hash": "df4oYftB-71Njv9FprRCeg"
12
+ "titleShort": "Hash",
13
+ "titleLong": "Row Hash",
14
+ "_hash": "2QxgcOKzL6zsVCo9Yi_5Ke"
13
15
  },
14
16
  {
15
17
  "key": "table",
16
18
  "type": "string",
17
- "_hash": "FmsYjsit04XJi02Sihdwl-"
19
+ "titleShort": "Table",
20
+ "titleLong": "Table Key",
21
+ "_hash": "dxePvdUNnwg2TdHEAPlzcL"
18
22
  },
19
23
  {
20
24
  "key": "predecessor",
21
25
  "type": "string",
22
- "_hash": "RlAk7Lj-lZf2KDlUk5fekZ"
26
+ "titleShort": "Predecessor",
27
+ "titleLong": "Predecessor Revision Hash",
28
+ "_hash": "DX2BPCXbaK-WFn4Oy9hYjg"
23
29
  },
24
30
  {
25
31
  "key": "successor",
26
32
  "type": "string",
27
- "_hash": "MJlFtQVty5oUJKVzzj5hyB"
33
+ "titleShort": "Successor",
34
+ "titleLong": "Successor Revision Hash",
35
+ "_hash": "w-IMk9JjuBkgt88ddVGV7B"
28
36
  },
29
37
  {
30
38
  "key": "timestamp",
31
39
  "type": "number",
32
- "_hash": "XpKYGh23thW6vONgQuoMHf"
40
+ "titleShort": "Timestamp",
41
+ "titleLong": "Revision Timestamp",
42
+ "_hash": "G9EloAJ1OVidMrffwSVrLt"
33
43
  },
34
44
  {
35
45
  "key": "id",
36
46
  "type": "string",
37
- "_hash": "eq2P3RIaSgy81i7PomNUvn"
47
+ "titleShort": "ID",
48
+ "titleLong": "Revision ID",
49
+ "_hash": "gwBBBa7SXFx2Zfz00JYdCR"
38
50
  }
39
51
  ],
40
- "_hash": "2ztQLyMtsFFIs0z_rvT6UL"
52
+ "_hash": "KFWwSAaR3bnqCwesHeAN4k"
41
53
  },
42
54
  {
43
55
  "key": "table0",
@@ -70,7 +82,7 @@
70
82
  "_hash": "wfRMrOPA2C9ogANQmzsI7K"
71
83
  },
72
84
  {
73
- "_hash": "er5aXXmEqihTA7Y1glILb4",
85
+ "_hash": "jERNpYntKnsV66yxoS2xOg",
74
86
  "key": "tableCfgs",
75
87
  "type": "tableCfgs",
76
88
  "isHead": false,
@@ -81,42 +93,58 @@
81
93
  {
82
94
  "key": "_hash",
83
95
  "type": "string",
84
- "_hash": "df4oYftB-71Njv9FprRCeg"
96
+ "titleShort": "Hash",
97
+ "titleLong": "Row Hash",
98
+ "_hash": "2QxgcOKzL6zsVCo9Yi_5Ke"
85
99
  },
86
100
  {
87
101
  "key": "key",
88
102
  "type": "string",
89
- "_hash": "tapEY-QdaJwWhz1PPZoG35"
103
+ "titleShort": "Key",
104
+ "titleLong": "Table Key",
105
+ "_hash": "vXW6G031fGusGpEgdnVWmt"
90
106
  },
91
107
  {
92
108
  "key": "type",
93
109
  "type": "string",
94
- "_hash": "zE7ALsNzu5JPgDD4AxeRCh"
110
+ "titleShort": "Type",
111
+ "titleLong": "Content Type",
112
+ "_hash": "X2upWVtQ02TKW3mj6SqU0c"
95
113
  },
96
114
  {
97
115
  "key": "isHead",
98
116
  "type": "boolean",
99
- "_hash": "ar8Hajt2UZDn-F21QLMyC_"
117
+ "titleShort": "Is Head",
118
+ "titleLong": "Is Head Table",
119
+ "_hash": "A-q9m5MVPMRVN6hk4pAMLH"
100
120
  },
101
121
  {
102
122
  "key": "isRoot",
103
123
  "type": "boolean",
104
- "_hash": "hedsCm_HtiiTuzJyTeMqhm"
124
+ "titleShort": "Is Root",
125
+ "titleLong": "Is Root Table",
126
+ "_hash": "qYiiwGCxzUtxlqIvZeU1rh"
105
127
  },
106
128
  {
107
129
  "key": "isShared",
108
130
  "type": "boolean",
109
- "_hash": "pxXOf3-3qCo9Z3FzC9JXSH"
131
+ "titleShort": "Is Shared",
132
+ "titleLong": "Is Shared Table",
133
+ "_hash": "jS9CqQBxXDhz1IB6PET4-P"
110
134
  },
111
135
  {
112
136
  "key": "previous",
113
137
  "type": "string",
114
- "_hash": "e0TEeDmSvJcLEMtrVxc0oW"
138
+ "titleShort": "Previous",
139
+ "titleLong": "Previous Table Configuration Hash",
140
+ "_hash": "0EgSa6oJSjOqjUCqlJzb5E"
115
141
  },
116
142
  {
117
143
  "key": "columns",
118
144
  "type": "jsonArray",
119
- "_hash": "aPmGTcNng9E1RvlEj1LtxB"
145
+ "titleShort": "Columns",
146
+ "titleLong": "Column Configurations",
147
+ "_hash": "GRV_4vc3xouarDpc1ZXE2_"
120
148
  }
121
149
  ]
122
150
  }
@@ -12,38 +12,50 @@
12
12
  {
13
13
  "key": "_hash",
14
14
  "type": "string",
15
- "_hash": "df4oYftB-71Njv9FprRCeg"
15
+ "titleShort": "Hash",
16
+ "titleLong": "Row Hash",
17
+ "_hash": "2QxgcOKzL6zsVCo9Yi_5Ke"
16
18
  },
17
19
  {
18
20
  "key": "table",
19
21
  "type": "string",
20
- "_hash": "FmsYjsit04XJi02Sihdwl-"
22
+ "titleShort": "Table",
23
+ "titleLong": "Table Key",
24
+ "_hash": "dxePvdUNnwg2TdHEAPlzcL"
21
25
  },
22
26
  {
23
27
  "key": "predecessor",
24
28
  "type": "string",
25
- "_hash": "RlAk7Lj-lZf2KDlUk5fekZ"
29
+ "titleShort": "Predecessor",
30
+ "titleLong": "Predecessor Revision Hash",
31
+ "_hash": "DX2BPCXbaK-WFn4Oy9hYjg"
26
32
  },
27
33
  {
28
34
  "key": "successor",
29
35
  "type": "string",
30
- "_hash": "MJlFtQVty5oUJKVzzj5hyB"
36
+ "titleShort": "Successor",
37
+ "titleLong": "Successor Revision Hash",
38
+ "_hash": "w-IMk9JjuBkgt88ddVGV7B"
31
39
  },
32
40
  {
33
41
  "key": "timestamp",
34
42
  "type": "number",
35
- "_hash": "XpKYGh23thW6vONgQuoMHf"
43
+ "titleShort": "Timestamp",
44
+ "titleLong": "Revision Timestamp",
45
+ "_hash": "G9EloAJ1OVidMrffwSVrLt"
36
46
  },
37
47
  {
38
48
  "key": "id",
39
49
  "type": "string",
40
- "_hash": "eq2P3RIaSgy81i7PomNUvn"
50
+ "titleShort": "ID",
51
+ "titleLong": "Revision ID",
52
+ "_hash": "gwBBBa7SXFx2Zfz00JYdCR"
41
53
  }
42
54
  ],
43
- "_hash": "2ztQLyMtsFFIs0z_rvT6UL"
55
+ "_hash": "KFWwSAaR3bnqCwesHeAN4k"
44
56
  },
45
57
  {
46
- "_hash": "er5aXXmEqihTA7Y1glILb4",
58
+ "_hash": "jERNpYntKnsV66yxoS2xOg",
47
59
  "key": "tableCfgs",
48
60
  "type": "tableCfgs",
49
61
  "isHead": false,
@@ -54,47 +66,63 @@
54
66
  {
55
67
  "key": "_hash",
56
68
  "type": "string",
57
- "_hash": "df4oYftB-71Njv9FprRCeg"
69
+ "titleShort": "Hash",
70
+ "titleLong": "Row Hash",
71
+ "_hash": "2QxgcOKzL6zsVCo9Yi_5Ke"
58
72
  },
59
73
  {
60
74
  "key": "key",
61
75
  "type": "string",
62
- "_hash": "tapEY-QdaJwWhz1PPZoG35"
76
+ "titleShort": "Key",
77
+ "titleLong": "Table Key",
78
+ "_hash": "vXW6G031fGusGpEgdnVWmt"
63
79
  },
64
80
  {
65
81
  "key": "type",
66
82
  "type": "string",
67
- "_hash": "zE7ALsNzu5JPgDD4AxeRCh"
83
+ "titleShort": "Type",
84
+ "titleLong": "Content Type",
85
+ "_hash": "X2upWVtQ02TKW3mj6SqU0c"
68
86
  },
69
87
  {
70
88
  "key": "isHead",
71
89
  "type": "boolean",
72
- "_hash": "ar8Hajt2UZDn-F21QLMyC_"
90
+ "titleShort": "Is Head",
91
+ "titleLong": "Is Head Table",
92
+ "_hash": "A-q9m5MVPMRVN6hk4pAMLH"
73
93
  },
74
94
  {
75
95
  "key": "isRoot",
76
96
  "type": "boolean",
77
- "_hash": "hedsCm_HtiiTuzJyTeMqhm"
97
+ "titleShort": "Is Root",
98
+ "titleLong": "Is Root Table",
99
+ "_hash": "qYiiwGCxzUtxlqIvZeU1rh"
78
100
  },
79
101
  {
80
102
  "key": "isShared",
81
103
  "type": "boolean",
82
- "_hash": "pxXOf3-3qCo9Z3FzC9JXSH"
104
+ "titleShort": "Is Shared",
105
+ "titleLong": "Is Shared Table",
106
+ "_hash": "jS9CqQBxXDhz1IB6PET4-P"
83
107
  },
84
108
  {
85
109
  "key": "previous",
86
110
  "type": "string",
87
- "_hash": "e0TEeDmSvJcLEMtrVxc0oW"
111
+ "titleShort": "Previous",
112
+ "titleLong": "Previous Table Configuration Hash",
113
+ "_hash": "0EgSa6oJSjOqjUCqlJzb5E"
88
114
  },
89
115
  {
90
116
  "key": "columns",
91
117
  "type": "jsonArray",
92
- "_hash": "aPmGTcNng9E1RvlEj1LtxB"
118
+ "titleShort": "Columns",
119
+ "titleLong": "Column Configurations",
120
+ "_hash": "GRV_4vc3xouarDpc1ZXE2_"
93
121
  }
94
122
  ]
95
123
  }
96
124
  ],
97
- "_tableCfg": "er5aXXmEqihTA7Y1glILb4",
98
- "_hash": "_u8EEswMCQtr4EKdi4F2Ti"
125
+ "_tableCfg": "jERNpYntKnsV66yxoS2xOg",
126
+ "_hash": "6iuL4dWHnsKqfvyAdVizTC"
99
127
  }
100
128
  }
@@ -32,7 +32,6 @@ import {
32
32
  describe,
33
33
  expect,
34
34
  it,
35
- vi,
36
35
  } from 'vitest';
37
36
 
38
37
  import { Io, IoTestSetup, IoTools } from '@rljson/io';
@@ -197,7 +196,7 @@ export const runIoConformanceTests = (
197
196
  await expect(
198
197
  io.createOrExtendTable({ tableCfg: tableCfg }),
199
198
  ).rejects.toThrow(
200
- 'Hash "wrongHash" does not match the newly calculated one "uX24nHRtwkXRsq8l46cNRZ". ' +
199
+ 'Hash "wrongHash" does not match the newly calculated one "9jZWK-5WPpnlQHCWSPg80D". ' +
201
200
  'Please make sure that all systems are producing the same hashes.',
202
201
  );
203
202
 
@@ -208,7 +207,7 @@ export const runIoConformanceTests = (
208
207
  }
209
208
 
210
209
  expect(message).toBe(
211
- 'Hash "wrongHash" does not match the newly calculated one "uX24nHRtwkXRsq8l46cNRZ". ' +
210
+ 'Hash "wrongHash" does not match the newly calculated one "9jZWK-5WPpnlQHCWSPg80D". ' +
212
211
  'Please make sure that all systems are producing the same hashes.',
213
212
  );
214
213
  });
@@ -422,7 +421,7 @@ export const runIoConformanceTests = (
422
421
  b: 5,
423
422
  },
424
423
  ],
425
- _tableCfg: '_SmasX0fD_A_0sshe6lnTt',
424
+ _tableCfg: 'GUGis7DIUDWCLFUJQZwJQ1',
426
425
  _type: 'components',
427
426
  },
428
427
  };
@@ -430,9 +429,24 @@ export const runIoConformanceTests = (
430
429
 
431
430
  // Update the table by adding a new column
432
431
  const tableCfg2 = addColumnsToTableCfg(tableCfg, [
433
- { key: 'keyA1', type: 'string' },
434
- { key: 'keyA2', type: 'string' },
435
- { key: 'keyB2', type: 'string' },
432
+ {
433
+ key: 'keyA1',
434
+ type: 'string',
435
+ titleShort: 'Key A1',
436
+ titleLong: 'Key A1',
437
+ },
438
+ {
439
+ key: 'keyA2',
440
+ type: 'string',
441
+ titleShort: 'Key A2',
442
+ titleLong: 'Key A2',
443
+ },
444
+ {
445
+ key: 'keyB2',
446
+ type: 'string',
447
+ titleShort: 'Key B2',
448
+ titleLong: 'Key B2',
449
+ },
436
450
  ]);
437
451
 
438
452
  await io.createOrExtendTable({ tableCfg: tableCfg2 });
@@ -478,7 +492,7 @@ export const runIoConformanceTests = (
478
492
  keyB2: 'b2',
479
493
  },
480
494
  ],
481
- _tableCfg: 'E1tCMshAuHRJg5Gz6M-Fqd',
495
+ _tableCfg: '73RBnYL3eR5SRPx7rMFiWN',
482
496
  _type: 'components',
483
497
  },
484
498
  });
@@ -491,10 +505,30 @@ export const runIoConformanceTests = (
491
505
  const tableCfg: TableCfg = {
492
506
  ...exampleCfg,
493
507
  columns: [
494
- { key: '_hash', type: 'string' },
495
- { key: 'keyA1', type: 'string' },
496
- { key: 'keyA2', type: 'string' },
497
- { key: 'keyB2', type: 'string' },
508
+ {
509
+ key: '_hash',
510
+ type: 'string',
511
+ titleShort: 'Hash',
512
+ titleLong: 'Hash',
513
+ },
514
+ {
515
+ key: 'keyA1',
516
+ type: 'string',
517
+ titleShort: 'Key A1',
518
+ titleLong: 'Key A1',
519
+ },
520
+ {
521
+ key: 'keyA2',
522
+ type: 'string',
523
+ titleShort: 'Key A2',
524
+ titleLong: 'Key A2',
525
+ },
526
+ {
527
+ key: 'keyB2',
528
+ type: 'string',
529
+ titleShort: 'Key B2',
530
+ titleLong: 'Key B2',
531
+ },
498
532
  ],
499
533
  };
500
534
 
@@ -555,13 +589,48 @@ export const runIoConformanceTests = (
555
589
  const tableCfg: TableCfg = {
556
590
  ...exampleCfg,
557
591
  columns: [
558
- { key: '_hash', type: 'string' },
559
- { key: 'string', type: 'string' },
560
- { key: 'number', type: 'number' },
561
- { key: 'null', type: 'string' },
562
- { key: 'boolean', type: 'boolean' },
563
- { key: 'array', type: 'jsonArray' },
564
- { key: 'object', type: 'json' },
592
+ {
593
+ key: '_hash',
594
+ type: 'string',
595
+ titleShort: 'Hash',
596
+ titleLong: 'Hash',
597
+ },
598
+ {
599
+ key: 'string',
600
+ type: 'string',
601
+ titleShort: 'String',
602
+ titleLong: 'String',
603
+ },
604
+ {
605
+ key: 'number',
606
+ type: 'number',
607
+ titleShort: 'Number',
608
+ titleLong: 'Number',
609
+ },
610
+ {
611
+ key: 'null',
612
+ type: 'string',
613
+ titleShort: 'Null',
614
+ titleLong: 'Null',
615
+ },
616
+ {
617
+ key: 'boolean',
618
+ type: 'boolean',
619
+ titleShort: 'Boolean',
620
+ titleLong: 'Boolean',
621
+ },
622
+ {
623
+ key: 'array',
624
+ type: 'jsonArray',
625
+ titleShort: 'Array',
626
+ titleLong: 'Array',
627
+ },
628
+ {
629
+ key: 'object',
630
+ type: 'json',
631
+ titleShort: 'Object',
632
+ titleLong: 'Object',
633
+ },
565
634
  ],
566
635
  };
567
636
 
@@ -645,13 +714,48 @@ export const runIoConformanceTests = (
645
714
  const tableCfg: TableCfg = {
646
715
  ...exampleCfg,
647
716
  columns: [
648
- { key: '_hash', type: 'string' },
649
- { key: 'string', type: 'string' },
650
- { key: 'number', type: 'number' },
651
- { key: 'null', type: 'string' },
652
- { key: 'boolean', type: 'boolean' },
653
- { key: 'array', type: 'jsonArray' },
654
- { key: 'object', type: 'json' },
717
+ {
718
+ key: '_hash',
719
+ type: 'string',
720
+ titleShort: 'Hash',
721
+ titleLong: 'Hash',
722
+ },
723
+ {
724
+ key: 'string',
725
+ type: 'string',
726
+ titleShort: 'String',
727
+ titleLong: 'String',
728
+ },
729
+ {
730
+ key: 'number',
731
+ type: 'number',
732
+ titleShort: 'Number',
733
+ titleLong: 'Number',
734
+ },
735
+ {
736
+ key: 'null',
737
+ type: 'string',
738
+ titleShort: 'Null',
739
+ titleLong: 'Null',
740
+ },
741
+ {
742
+ key: 'boolean',
743
+ type: 'boolean',
744
+ titleShort: 'Boolean',
745
+ titleLong: 'Boolean',
746
+ },
747
+ {
748
+ key: 'array',
749
+ type: 'jsonArray',
750
+ titleShort: 'Array',
751
+ titleLong: 'Array',
752
+ },
753
+ {
754
+ key: 'object',
755
+ type: 'json',
756
+ titleShort: 'Object',
757
+ titleLong: 'Object',
758
+ },
655
759
  ],
656
760
  };
657
761
 
@@ -1028,127 +1132,6 @@ export const runIoConformanceTests = (
1028
1132
  );
1029
1133
  });
1030
1134
  });
1031
-
1032
- describe('observeTable(table, callback)', () => {
1033
- it('should call listener on table changes', async () => {
1034
- //Create example table and add initial data
1035
- await createExampleTable('table1');
1036
- await io.write({
1037
- data: {
1038
- table1: {
1039
- _type: 'components',
1040
- _data: [{ a: 'a1' }],
1041
- },
1042
- },
1043
- });
1044
-
1045
- //Create listener
1046
- const cb = vi.fn();
1047
-
1048
- //Data to write
1049
- const data = {
1050
- table1: {
1051
- _type: 'components',
1052
- _data: [{ a: 'a2' }],
1053
- },
1054
- } as Rljson;
1055
-
1056
- //Subscribe to changes
1057
- io.observeTable('table1', cb);
1058
-
1059
- //Write new data triggering the listener
1060
- await io.write({
1061
- data,
1062
- });
1063
-
1064
- //Check that the listener was called with the latest data only
1065
- expect(cb).toHaveBeenCalledTimes(1);
1066
- expect(cb).toHaveBeenCalledWith({ table1: hsh(data.table1) });
1067
- });
1068
- });
1069
-
1070
- describe('unobserveTable(table, callback) and unobserveAll(table)', () => {
1071
- it('should not call listener after unobserve', async () => {
1072
- await createExampleTable('table1');
1073
-
1074
- const cb = vi.fn();
1075
- const data = {
1076
- table1: {
1077
- _type: 'components',
1078
- _data: [{ a: 'a2' }],
1079
- },
1080
- } as Rljson;
1081
-
1082
- //Subscribe to changes
1083
- io.observeTable('table1', cb);
1084
-
1085
- await io.write({
1086
- data,
1087
- });
1088
-
1089
- //Unsubscribe
1090
- io.unobserveTable('table1', cb);
1091
-
1092
- await io.write({
1093
- data,
1094
- });
1095
-
1096
- expect(cb).toHaveBeenCalledTimes(1);
1097
- });
1098
- });
1099
- describe('unobserveAll(table)', () => {
1100
- it('should not call listener after unobserve all', async () => {
1101
- await createExampleTable('table1');
1102
-
1103
- const cb = vi.fn();
1104
- const data = {
1105
- table1: {
1106
- _type: 'components',
1107
- _data: [{ a: 'a2' }],
1108
- },
1109
- } as Rljson;
1110
-
1111
- //Subscribe to changes
1112
- io.observeTable('table1', cb);
1113
-
1114
- await io.write({
1115
- data,
1116
- });
1117
-
1118
- //Unsubscribe all listeners from table1
1119
- io.unobserveAll('table1');
1120
-
1121
- await io.write({
1122
- data,
1123
- });
1124
-
1125
- expect(cb).toHaveBeenCalledTimes(1);
1126
- });
1127
- });
1128
-
1129
- describe('observers(table)', () => {
1130
- it('get a list of all observers', async () => {
1131
- await createExampleTable('table1');
1132
- await createExampleTable('table2');
1133
-
1134
- const cb1 = vi.fn();
1135
- const cb2 = vi.fn();
1136
-
1137
- //Subscribe to changes
1138
- io.observeTable('table1', cb1);
1139
- io.observeTable('table1', cb2);
1140
- io.observeTable('table2', cb2);
1141
-
1142
- const observers = io.observers('table1');
1143
- expect(observers.length).toBe(2);
1144
- expect(observers).toContain(cb1);
1145
- expect(observers).toContain(cb2);
1146
-
1147
- const observers2 = io.observers('table2');
1148
- expect(observers2.length).toBe(1);
1149
- expect(observers2).toContain(cb2);
1150
- });
1151
- });
1152
1135
  });
1153
1136
  };
1154
1137
 
package/dist/io-mem.d.ts CHANGED
@@ -49,8 +49,4 @@ export declare class IoMem implements Io {
49
49
  private _write;
50
50
  private _readRows;
51
51
  _removeNullValues(rljson: Rljson): void;
52
- observeTable(table: string, callback: (data: Rljson) => void): void;
53
- unobserveTable(table: string, callback: (data: Rljson) => void): void;
54
- unobserveAll(table: string): void;
55
- observers(table: string): ((data: Rljson) => void)[];
56
52
  }
package/dist/io-peer.d.ts CHANGED
@@ -5,7 +5,6 @@ import { Socket } from './socket.ts';
5
5
  export declare class IoPeer implements Io {
6
6
  private _socket;
7
7
  isOpen: boolean;
8
- private _ioTools;
9
8
  constructor(_socket: Socket);
10
9
  /**
11
10
  *
@@ -88,13 +87,5 @@ export declare class IoPeer implements Io {
88
87
  * @returns A promise that resolves to the number of rows in the specified table.
89
88
  */
90
89
  rowCount(table: string): Promise<number>;
91
- /** Start observing changes on a specific table */
92
- observeTable(table: string, callback: (data: Rljson) => void): Promise<void>;
93
- /** Stop observing changes on a specific table */
94
- unobserveTable(table: string, callback: (data: Rljson) => void): void;
95
- /** Stop observing all changes on a specific table */
96
- unobserveAll(table: string): void;
97
- /** Returns all observers for a specific table */
98
- observers(table: string): ((data: Rljson) => void)[];
99
90
  static example: () => Promise<IoPeer>;
100
91
  }
@@ -21,7 +21,6 @@ export declare class IoServer {
21
21
  private _addTransportLayer;
22
22
  /**
23
23
  * Creates or extends a table with the given configuration.
24
- * Also sets up observation for the new or extended table on all connected sockets.
25
24
  * @param request - An object containing the table configuration.
26
25
  */
27
26
  private createOrExtendTable;