@arcote.tech/arc 0.0.22 → 0.0.24
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.
|
@@ -3,6 +3,7 @@ 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";
|
|
6
|
+
import type { IndexQueryArgument } from "../db";
|
|
6
7
|
import { ArcAllItemsQueryBuilder } from "./query-builders/all-items";
|
|
7
8
|
import { ArcIndexedItemsQueryBuilder } from "./query-builders/indexed";
|
|
8
9
|
import { ArcOneItemQueryBuilder } from "./query-builders/one-item";
|
|
@@ -27,6 +28,11 @@ type CollectionCommandContext<Id extends ArcIdAny, Schema extends ArcObjectAny>
|
|
|
27
28
|
edit: (id: util.GetType<Id>, editCallback: (item: Deserialize<Id, Schema>) => Promise<void> | void) => Promise<void>;
|
|
28
29
|
modify: (id: util.GetType<Id>, data: objectUtil.addQuestionMarks<DeepPartial<util.FirstArgument<Schema["serialize"]>>>) => Promise<any>;
|
|
29
30
|
};
|
|
31
|
+
type IndexValue<Schema extends ArcObjectAny, Indexes extends keyof ReturnType<Schema["deserialize"]>, I extends {
|
|
32
|
+
[name: string]: Indexes[];
|
|
33
|
+
}, func extends keyof I> = {
|
|
34
|
+
[Key in I[func][number]]: util.GetType<Schema>[Key];
|
|
35
|
+
};
|
|
30
36
|
export declare class ArcCollection<Name extends string, Id extends ArcIdAny, Schema extends ArcObjectAny> extends ArcContextElement<{
|
|
31
37
|
type: "delete";
|
|
32
38
|
from: CollectionItem<ArcCollection<Name, Id, Schema>>;
|
|
@@ -68,14 +74,10 @@ export declare class ArcIndexedCollection<Name extends string, Id extends ArcIdA
|
|
|
68
74
|
readonly indexes: I;
|
|
69
75
|
constructor(name: Name, id: Id, schema: Schema, options: ArcCollectionOptions<Id, Schema>, indexes: I);
|
|
70
76
|
commandContext(dataStorage: DataStorage, publishEvent: (event: this["$event"]) => Promise<void>): CollectionCommandContext<Id, Schema> & {
|
|
71
|
-
[func in keyof I]: (args:
|
|
72
|
-
[Key in I[func][number]]: util.GetType<Schema>[Key];
|
|
73
|
-
}) => Deserialize<Id, Schema>[];
|
|
77
|
+
[func in keyof I]: (args: IndexValue<Schema, Indexes, I, func>) => Deserialize<Id, Schema>[];
|
|
74
78
|
};
|
|
75
79
|
queryBuilder(): CollectionQueryBuilder<ArcCollection<Name, Id, Schema>> & {
|
|
76
|
-
[func in keyof I]: (args:
|
|
77
|
-
[Key in I[func][number]]: util.GetType<Schema>[Key];
|
|
78
|
-
}) => ArcIndexedItemsQueryBuilder<ArcIndexedCollection<Name, Id, Schema, Indexes, I>>;
|
|
80
|
+
[func in keyof I]: (args: objectUtil.simplify<IndexQueryArgument<objectUtil.simplify<IndexValue<Schema, Indexes, I, func>>>>) => ArcIndexedItemsQueryBuilder<ArcIndexedCollection<Name, Id, Schema, Indexes, I>>;
|
|
79
81
|
};
|
|
80
82
|
}
|
|
81
83
|
export type ArcCollectionAny = ArcCollection<any, any, any>;
|
package/dist/db/interface.d.ts
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
import type { ArcContextAny } from "../context";
|
|
2
|
+
export type IndexQueryArgument<T> = T | ({
|
|
3
|
+
$gt?: T;
|
|
4
|
+
$gte?: T;
|
|
5
|
+
$lt?: T;
|
|
6
|
+
$lte?: T;
|
|
7
|
+
} & ({
|
|
8
|
+
$gt: T;
|
|
9
|
+
} | {
|
|
10
|
+
$gte: T;
|
|
11
|
+
} | {
|
|
12
|
+
$lt: T;
|
|
13
|
+
} | {
|
|
14
|
+
$lte: T;
|
|
15
|
+
}));
|
|
2
16
|
export interface ReadTransaction {
|
|
3
17
|
findById(store: string, id: any): Promise<any | undefined>;
|
|
4
|
-
findByIndex(store: string, index: string, data: any): Promise<any[]>;
|
|
18
|
+
findByIndex(store: string, index: string, data: IndexQueryArgument<any>): Promise<any[]>;
|
|
5
19
|
findAll(store: string): Promise<any[]>;
|
|
6
20
|
}
|
|
7
21
|
export interface ReadWriteTransaction extends ReadTransaction {
|
package/dist/index.js
CHANGED
|
@@ -161,6 +161,34 @@ class ArcAllItemsQueryBuilder extends ArcManyItemsQueryBuilder {
|
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
+
// db/index-query.ts
|
|
165
|
+
function indexQueryPredicate(item, query) {
|
|
166
|
+
if (!("$gt" in query) && !("$gte" in query) && !("$lt" in query) && !("$lte" in query)) {
|
|
167
|
+
return Object.entries(query).every(([key, value]) => item[key] === value);
|
|
168
|
+
}
|
|
169
|
+
if (query.$gt) {
|
|
170
|
+
const isGreaterThan = Object.entries(query.$gt).every(([key, value]) => item[key] > value);
|
|
171
|
+
if (!isGreaterThan)
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
if (query.$gte) {
|
|
175
|
+
const isGreaterThanOrEqual = Object.entries(query.$gte).every(([key, value]) => item[key] >= value);
|
|
176
|
+
if (!isGreaterThanOrEqual)
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
if (query.$lt) {
|
|
180
|
+
const isLessThan = Object.entries(query.$lt).every(([key, value]) => item[key] < value);
|
|
181
|
+
if (!isLessThan)
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
if (query.$lte) {
|
|
185
|
+
const isLessThanOrEqual = Object.entries(query.$lte).every(([key, value]) => item[key] <= value);
|
|
186
|
+
if (!isLessThanOrEqual)
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
|
|
164
192
|
// collection/queries/indexed.ts
|
|
165
193
|
class ArcIndexedItemsQuery extends ArcManyItemsQuery {
|
|
166
194
|
index;
|
|
@@ -177,10 +205,7 @@ class ArcIndexedItemsQuery extends ArcManyItemsQuery {
|
|
|
177
205
|
checkItem(item) {
|
|
178
206
|
if (!super.checkItem(item))
|
|
179
207
|
return false;
|
|
180
|
-
|
|
181
|
-
if (!correct)
|
|
182
|
-
return false;
|
|
183
|
-
return true;
|
|
208
|
+
return indexQueryPredicate(item, this.data);
|
|
184
209
|
}
|
|
185
210
|
async fetch(store) {
|
|
186
211
|
const results = await store.findByIndex(this.index, this.data, this.bindedChangeHandler);
|
|
@@ -243,10 +268,6 @@ class ArcOneItemQueryBuilder extends ArcQueryBuilder {
|
|
|
243
268
|
}
|
|
244
269
|
|
|
245
270
|
// collection/collection.ts
|
|
246
|
-
function collection(name, id, schema, options = {}) {
|
|
247
|
-
return new ArcCollection(name, id, schema, options);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
271
|
class ArcCollection extends ArcContextElement {
|
|
251
272
|
name;
|
|
252
273
|
id;
|
|
@@ -376,11 +397,10 @@ class ArcIndexedCollection extends ArcCollection {
|
|
|
376
397
|
});
|
|
377
398
|
}
|
|
378
399
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
return new ArcContext(version, elements, commands, listeners);
|
|
400
|
+
function collection(name, id, schema, options = {}) {
|
|
401
|
+
return new ArcCollection(name, id, schema, options);
|
|
382
402
|
}
|
|
383
|
-
|
|
403
|
+
// context/context.ts
|
|
384
404
|
class ArcContext {
|
|
385
405
|
version;
|
|
386
406
|
elements;
|
|
@@ -447,6 +467,9 @@ class ArcContext {
|
|
|
447
467
|
});
|
|
448
468
|
}
|
|
449
469
|
}
|
|
470
|
+
function context(version, elements, commands, listeners) {
|
|
471
|
+
return new ArcContext(version, elements, commands, listeners);
|
|
472
|
+
}
|
|
450
473
|
// data-storage/data-storage.abstract.ts
|
|
451
474
|
class DataStorage {
|
|
452
475
|
async commitChanges(changes) {
|
|
@@ -786,6 +809,8 @@ class MasterStoreState extends StoreState {
|
|
|
786
809
|
}
|
|
787
810
|
}
|
|
788
811
|
async findById(id, listener) {
|
|
812
|
+
if (!id)
|
|
813
|
+
return;
|
|
789
814
|
if (listener)
|
|
790
815
|
this.listeners.set(listener, { callback: listener, id });
|
|
791
816
|
if (this.items.has(id))
|
|
@@ -805,8 +830,7 @@ class MasterStoreState extends StoreState {
|
|
|
805
830
|
const results2 = Array.from(this.items.values()).filter((item) => {
|
|
806
831
|
if (!item)
|
|
807
832
|
return false;
|
|
808
|
-
|
|
809
|
-
return !notCorrect;
|
|
833
|
+
return indexQueryPredicate(item, data);
|
|
810
834
|
});
|
|
811
835
|
return results2;
|
|
812
836
|
}
|
|
@@ -972,10 +996,6 @@ class ArcAbstract {
|
|
|
972
996
|
}
|
|
973
997
|
|
|
974
998
|
// elements/object.ts
|
|
975
|
-
function object(element) {
|
|
976
|
-
return new ArcObject(element);
|
|
977
|
-
}
|
|
978
|
-
|
|
979
999
|
class ArcObject extends ArcAbstract {
|
|
980
1000
|
rawShape;
|
|
981
1001
|
constructor(rawShape) {
|
|
@@ -1038,12 +1058,11 @@ class ArcObject extends ArcAbstract {
|
|
|
1038
1058
|
}, {});
|
|
1039
1059
|
}
|
|
1040
1060
|
}
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
function array(element) {
|
|
1044
|
-
return new ArcArray(element);
|
|
1061
|
+
function object(element) {
|
|
1062
|
+
return new ArcObject(element);
|
|
1045
1063
|
}
|
|
1046
1064
|
|
|
1065
|
+
// elements/array.ts
|
|
1047
1066
|
class ArcArray extends ArcAbstract {
|
|
1048
1067
|
parent;
|
|
1049
1068
|
constructor(parent) {
|
|
@@ -1069,6 +1088,9 @@ class ArcArray extends ArcAbstract {
|
|
|
1069
1088
|
return this.parent.deserialize(value);
|
|
1070
1089
|
}
|
|
1071
1090
|
}
|
|
1091
|
+
function array(element) {
|
|
1092
|
+
return new ArcArray(element);
|
|
1093
|
+
}
|
|
1072
1094
|
// elements/abstract-primitive.ts
|
|
1073
1095
|
class ArcPrimitive extends ArcAbstract {
|
|
1074
1096
|
constructor() {
|
|
@@ -1086,17 +1108,12 @@ class ArcPrimitive extends ArcAbstract {
|
|
|
1086
1108
|
}
|
|
1087
1109
|
|
|
1088
1110
|
// elements/boolean.ts
|
|
1111
|
+
class ArcBoolean extends ArcPrimitive {
|
|
1112
|
+
}
|
|
1089
1113
|
function boolean() {
|
|
1090
1114
|
return new ArcBoolean;
|
|
1091
1115
|
}
|
|
1092
|
-
|
|
1093
|
-
class ArcBoolean extends ArcPrimitive {
|
|
1094
|
-
}
|
|
1095
1116
|
// elements/date.ts
|
|
1096
|
-
function date() {
|
|
1097
|
-
return new ArcDate;
|
|
1098
|
-
}
|
|
1099
|
-
|
|
1100
1117
|
class ArcDate extends ArcAbstract {
|
|
1101
1118
|
constructor() {
|
|
1102
1119
|
super();
|
|
@@ -1111,19 +1128,17 @@ class ArcDate extends ArcAbstract {
|
|
|
1111
1128
|
return new Date(value);
|
|
1112
1129
|
}
|
|
1113
1130
|
}
|
|
1131
|
+
function date() {
|
|
1132
|
+
return new ArcDate;
|
|
1133
|
+
}
|
|
1114
1134
|
// elements/string.ts
|
|
1135
|
+
class ArcString extends ArcPrimitive {
|
|
1136
|
+
}
|
|
1115
1137
|
function string() {
|
|
1116
1138
|
return new ArcString;
|
|
1117
1139
|
}
|
|
1118
1140
|
|
|
1119
|
-
class ArcString extends ArcPrimitive {
|
|
1120
|
-
}
|
|
1121
|
-
|
|
1122
1141
|
// elements/id.ts
|
|
1123
|
-
function id(name) {
|
|
1124
|
-
return new ArcId(name);
|
|
1125
|
-
}
|
|
1126
|
-
|
|
1127
1142
|
class ArcId extends ArcBranded {
|
|
1128
1143
|
constructor(name) {
|
|
1129
1144
|
super(string(), name);
|
|
@@ -1135,18 +1150,16 @@ class ArcId extends ArcBranded {
|
|
|
1135
1150
|
}).toLowerCase();
|
|
1136
1151
|
}
|
|
1137
1152
|
}
|
|
1153
|
+
function id(name) {
|
|
1154
|
+
return new ArcId(name);
|
|
1155
|
+
}
|
|
1138
1156
|
// elements/number.ts
|
|
1157
|
+
class ArcNumber extends ArcPrimitive {
|
|
1158
|
+
}
|
|
1139
1159
|
function number() {
|
|
1140
1160
|
return new ArcNumber;
|
|
1141
1161
|
}
|
|
1142
|
-
|
|
1143
|
-
class ArcNumber extends ArcPrimitive {
|
|
1144
|
-
}
|
|
1145
1162
|
// elements/record.ts
|
|
1146
|
-
function record(key, element) {
|
|
1147
|
-
return new ArcRecord(key, element);
|
|
1148
|
-
}
|
|
1149
|
-
|
|
1150
1163
|
class ArcRecord extends ArcAbstract {
|
|
1151
1164
|
key;
|
|
1152
1165
|
element;
|
|
@@ -1180,11 +1193,10 @@ class ArcRecord extends ArcAbstract {
|
|
|
1180
1193
|
}, {});
|
|
1181
1194
|
}
|
|
1182
1195
|
}
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
return new ArcStringEnum(values);
|
|
1196
|
+
function record(key, element) {
|
|
1197
|
+
return new ArcRecord(key, element);
|
|
1186
1198
|
}
|
|
1187
|
-
|
|
1199
|
+
// elements/string-enum.ts
|
|
1188
1200
|
class ArcStringEnum extends ArcAbstract {
|
|
1189
1201
|
values;
|
|
1190
1202
|
constructor(values) {
|
|
@@ -1204,6 +1216,9 @@ class ArcStringEnum extends ArcAbstract {
|
|
|
1204
1216
|
return this.values;
|
|
1205
1217
|
}
|
|
1206
1218
|
}
|
|
1219
|
+
function stringEnum(...values) {
|
|
1220
|
+
return new ArcStringEnum(values);
|
|
1221
|
+
}
|
|
1207
1222
|
// rtc/client.ts
|
|
1208
1223
|
class RTCClient {
|
|
1209
1224
|
storage;
|
|
@@ -1364,10 +1379,6 @@ class ArcStateQueryBuilder extends ArcQueryBuilder {
|
|
|
1364
1379
|
}
|
|
1365
1380
|
|
|
1366
1381
|
// state/state.ts
|
|
1367
|
-
function state(name, schema) {
|
|
1368
|
-
return new ArcState(name, schema);
|
|
1369
|
-
}
|
|
1370
|
-
|
|
1371
1382
|
class ArcState extends ArcContextElement {
|
|
1372
1383
|
name;
|
|
1373
1384
|
schema;
|
|
@@ -1410,6 +1421,9 @@ class ArcState extends ArcContextElement {
|
|
|
1410
1421
|
};
|
|
1411
1422
|
}
|
|
1412
1423
|
}
|
|
1424
|
+
function state(name, schema) {
|
|
1425
|
+
return new ArcState(name, schema);
|
|
1426
|
+
}
|
|
1413
1427
|
export {
|
|
1414
1428
|
stringEnum,
|
|
1415
1429
|
string,
|
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
|
+
"version": "0.0.24",
|
|
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.",
|