@arcote.tech/arc 0.0.23 → 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.
@@ -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
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
- const correct = Object.entries(this.data).every(([key, value]) => item[key] === value);
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
- // context/context.ts
380
- function context(version, elements, commands, listeners) {
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) {
@@ -807,8 +830,7 @@ class MasterStoreState extends StoreState {
807
830
  const results2 = Array.from(this.items.values()).filter((item) => {
808
831
  if (!item)
809
832
  return false;
810
- const notCorrect = Object.entries(data).some(([key, value]) => item[key] !== value);
811
- return !notCorrect;
833
+ return indexQueryPredicate(item, data);
812
834
  });
813
835
  return results2;
814
836
  }
@@ -974,10 +996,6 @@ class ArcAbstract {
974
996
  }
975
997
 
976
998
  // elements/object.ts
977
- function object(element) {
978
- return new ArcObject(element);
979
- }
980
-
981
999
  class ArcObject extends ArcAbstract {
982
1000
  rawShape;
983
1001
  constructor(rawShape) {
@@ -1040,12 +1058,11 @@ class ArcObject extends ArcAbstract {
1040
1058
  }, {});
1041
1059
  }
1042
1060
  }
1043
-
1044
- // elements/array.ts
1045
- function array(element) {
1046
- return new ArcArray(element);
1061
+ function object(element) {
1062
+ return new ArcObject(element);
1047
1063
  }
1048
1064
 
1065
+ // elements/array.ts
1049
1066
  class ArcArray extends ArcAbstract {
1050
1067
  parent;
1051
1068
  constructor(parent) {
@@ -1071,6 +1088,9 @@ class ArcArray extends ArcAbstract {
1071
1088
  return this.parent.deserialize(value);
1072
1089
  }
1073
1090
  }
1091
+ function array(element) {
1092
+ return new ArcArray(element);
1093
+ }
1074
1094
  // elements/abstract-primitive.ts
1075
1095
  class ArcPrimitive extends ArcAbstract {
1076
1096
  constructor() {
@@ -1088,17 +1108,12 @@ class ArcPrimitive extends ArcAbstract {
1088
1108
  }
1089
1109
 
1090
1110
  // elements/boolean.ts
1111
+ class ArcBoolean extends ArcPrimitive {
1112
+ }
1091
1113
  function boolean() {
1092
1114
  return new ArcBoolean;
1093
1115
  }
1094
-
1095
- class ArcBoolean extends ArcPrimitive {
1096
- }
1097
1116
  // elements/date.ts
1098
- function date() {
1099
- return new ArcDate;
1100
- }
1101
-
1102
1117
  class ArcDate extends ArcAbstract {
1103
1118
  constructor() {
1104
1119
  super();
@@ -1113,19 +1128,17 @@ class ArcDate extends ArcAbstract {
1113
1128
  return new Date(value);
1114
1129
  }
1115
1130
  }
1131
+ function date() {
1132
+ return new ArcDate;
1133
+ }
1116
1134
  // elements/string.ts
1135
+ class ArcString extends ArcPrimitive {
1136
+ }
1117
1137
  function string() {
1118
1138
  return new ArcString;
1119
1139
  }
1120
1140
 
1121
- class ArcString extends ArcPrimitive {
1122
- }
1123
-
1124
1141
  // elements/id.ts
1125
- function id(name) {
1126
- return new ArcId(name);
1127
- }
1128
-
1129
1142
  class ArcId extends ArcBranded {
1130
1143
  constructor(name) {
1131
1144
  super(string(), name);
@@ -1137,18 +1150,16 @@ class ArcId extends ArcBranded {
1137
1150
  }).toLowerCase();
1138
1151
  }
1139
1152
  }
1153
+ function id(name) {
1154
+ return new ArcId(name);
1155
+ }
1140
1156
  // elements/number.ts
1157
+ class ArcNumber extends ArcPrimitive {
1158
+ }
1141
1159
  function number() {
1142
1160
  return new ArcNumber;
1143
1161
  }
1144
-
1145
- class ArcNumber extends ArcPrimitive {
1146
- }
1147
1162
  // elements/record.ts
1148
- function record(key, element) {
1149
- return new ArcRecord(key, element);
1150
- }
1151
-
1152
1163
  class ArcRecord extends ArcAbstract {
1153
1164
  key;
1154
1165
  element;
@@ -1182,11 +1193,10 @@ class ArcRecord extends ArcAbstract {
1182
1193
  }, {});
1183
1194
  }
1184
1195
  }
1185
- // elements/string-enum.ts
1186
- function stringEnum(...values) {
1187
- return new ArcStringEnum(values);
1196
+ function record(key, element) {
1197
+ return new ArcRecord(key, element);
1188
1198
  }
1189
-
1199
+ // elements/string-enum.ts
1190
1200
  class ArcStringEnum extends ArcAbstract {
1191
1201
  values;
1192
1202
  constructor(values) {
@@ -1206,6 +1216,9 @@ class ArcStringEnum extends ArcAbstract {
1206
1216
  return this.values;
1207
1217
  }
1208
1218
  }
1219
+ function stringEnum(...values) {
1220
+ return new ArcStringEnum(values);
1221
+ }
1209
1222
  // rtc/client.ts
1210
1223
  class RTCClient {
1211
1224
  storage;
@@ -1366,10 +1379,6 @@ class ArcStateQueryBuilder extends ArcQueryBuilder {
1366
1379
  }
1367
1380
 
1368
1381
  // state/state.ts
1369
- function state(name, schema) {
1370
- return new ArcState(name, schema);
1371
- }
1372
-
1373
1382
  class ArcState extends ArcContextElement {
1374
1383
  name;
1375
1384
  schema;
@@ -1412,6 +1421,9 @@ class ArcState extends ArcContextElement {
1412
1421
  };
1413
1422
  }
1414
1423
  }
1424
+ function state(name, schema) {
1425
+ return new ArcState(name, schema);
1426
+ }
1415
1427
  export {
1416
1428
  stringEnum,
1417
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.23",
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.",