@anfenn/dync 1.0.8 → 1.0.10

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.
package/README.md CHANGED
@@ -37,9 +37,9 @@ And see how Dync compares to the alternatives [below](#hasnt-this-already-been-d
37
37
  ```js
38
38
  db.query(async (ctx) => {
39
39
  if (ctx instanceof DexieQueryContext) {
40
- return await ctx.table('items').where('value').equals('dexie-test');
40
+ return await ctx.table('items').where('value').startsWithIgnoreCase('dexie').toArray();
41
41
  } else if (ctx instanceof SqliteQueryContext) {
42
- return await ctx.queryRows('SELECT * FROM items WHERE value = ?', ['sqlite-test']);
42
+ return await ctx.queryRows('SELECT * FROM items WHERE value LIKE ?', ['sqlite%']);
43
43
  }
44
44
  });
45
45
  ```
@@ -1860,11 +1860,11 @@ var MemoryCollection = class _MemoryCollection {
1860
1860
  // src/storage/memory/MemoryWhereClause.ts
1861
1861
  var MemoryWhereClause = class {
1862
1862
  table;
1863
- index;
1863
+ column;
1864
1864
  baseCollection;
1865
- constructor(table, index, baseCollection) {
1865
+ constructor(table, column, baseCollection) {
1866
1866
  this.table = table;
1867
- this.index = index;
1867
+ this.column = column;
1868
1868
  this.baseCollection = baseCollection;
1869
1869
  }
1870
1870
  equals(value) {
@@ -1943,9 +1943,9 @@ var MemoryWhereClause = class {
1943
1943
  return this.createCollection((current) => this.table.compareValues(current, value) !== 0);
1944
1944
  }
1945
1945
  createCollection(predicate) {
1946
- const condition = (record, _key) => predicate(this.table.getIndexValue(record, this.index));
1946
+ const condition = (record, _key) => predicate(this.table.getIndexValue(record, this.column));
1947
1947
  if (this.baseCollection) {
1948
- const combined = (record, key) => this.baseCollection.matches(record, key) || predicate(this.table.getIndexValue(record, this.index));
1948
+ const combined = (record, key) => this.baseCollection.matches(record, key) || predicate(this.table.getIndexValue(record, this.column));
1949
1949
  return this.table.createCollectionFromPredicate(combined, this.baseCollection);
1950
1950
  }
1951
1951
  return this.table.createCollectionFromPredicate(condition);
@@ -1963,7 +1963,6 @@ var MemoryTable = class {
1963
1963
  name;
1964
1964
  schema = void 0;
1965
1965
  primaryKey = LOCAL_PK;
1966
- hook = Object.freeze({});
1967
1966
  raw;
1968
1967
  records = /* @__PURE__ */ new Map();
1969
1968
  constructor(name) {
@@ -2072,9 +2071,6 @@ var MemoryTable = class {
2072
2071
  limit(count) {
2073
2072
  return this.createCollection({ limit: count });
2074
2073
  }
2075
- mapToClass(_ctor) {
2076
- return this;
2077
- }
2078
2074
  async each(callback) {
2079
2075
  for (const [, record] of this.entries()) {
2080
2076
  await callback(this.cloneRecord(record));
@@ -2099,8 +2095,8 @@ var MemoryTable = class {
2099
2095
  predicate
2100
2096
  });
2101
2097
  }
2102
- createWhereClause(index, baseCollection) {
2103
- return new MemoryWhereClause(this, index, baseCollection);
2098
+ createWhereClause(column, baseCollection) {
2099
+ return new MemoryWhereClause(this, column, baseCollection);
2104
2100
  }
2105
2101
  entries() {
2106
2102
  return Array.from(this.records.entries());
@@ -2314,10 +2310,6 @@ var buildCondition = (condition) => {
2314
2310
  }
2315
2311
  return { clause: `(${subClauses.join(" OR ")})`, parameters: subParams };
2316
2312
  }
2317
- if (condition.type === "compoundEquals") {
2318
- const clauses = condition.columns.map((col2) => `${quoteIdentifier(col2)} = ?`);
2319
- return { clause: `(${clauses.join(" AND ")})`, parameters: condition.values };
2320
- }
2321
2313
  const col = quoteIdentifier(condition.column);
2322
2314
  switch (condition.type) {
2323
2315
  case "equals": {
@@ -2891,42 +2883,17 @@ var SQLiteAdapter2 = class {
2891
2883
  // src/storage/sqlite/SQLiteWhereClause.ts
2892
2884
  var SQLiteWhereClause = class {
2893
2885
  table;
2894
- index;
2886
+ column;
2895
2887
  baseCollection;
2896
- constructor(table, index, baseCollection) {
2888
+ constructor(table, column, baseCollection) {
2897
2889
  this.table = table;
2898
- this.index = index;
2890
+ this.column = column;
2899
2891
  this.baseCollection = baseCollection;
2900
2892
  }
2901
- getColumn() {
2902
- if (Array.isArray(this.index)) {
2903
- return this.index[0];
2904
- }
2905
- return this.index;
2906
- }
2907
- isCompoundIndex() {
2908
- return Array.isArray(this.index) && this.index.length > 1;
2909
- }
2910
- getCompoundColumns() {
2911
- return Array.isArray(this.index) ? this.index : [this.index];
2912
- }
2913
- getCompoundValues(value) {
2914
- if (Array.isArray(value)) {
2915
- return value;
2916
- }
2917
- return [value];
2918
- }
2919
2893
  createCollectionWithCondition(condition) {
2920
2894
  const base = this.baseCollection ?? this.table.createCollection();
2921
2895
  return base.addSqlCondition(condition);
2922
2896
  }
2923
- createCollectionWithJsPredicate(predicate) {
2924
- const base = this.baseCollection ?? this.table.createCollection();
2925
- return base.jsFilter(predicate);
2926
- }
2927
- getIndexValue(record) {
2928
- return this.table.getIndexValue(record, this.index);
2929
- }
2930
2897
  flattenArgs(args) {
2931
2898
  if (args.length === 1 && Array.isArray(args[0])) {
2932
2899
  return args[0];
@@ -2934,79 +2901,48 @@ var SQLiteWhereClause = class {
2934
2901
  return args;
2935
2902
  }
2936
2903
  equals(value) {
2937
- if (this.isCompoundIndex()) {
2938
- const columns = this.getCompoundColumns();
2939
- const values = this.getCompoundValues(value);
2940
- return this.createCollectionWithCondition({
2941
- type: "compoundEquals",
2942
- columns,
2943
- values
2944
- });
2945
- }
2946
2904
  return this.createCollectionWithCondition({
2947
2905
  type: "equals",
2948
- column: this.getColumn(),
2906
+ column: this.column,
2949
2907
  value
2950
2908
  });
2951
2909
  }
2952
2910
  above(value) {
2953
- if (this.isCompoundIndex()) {
2954
- return this.createCollectionWithJsPredicate((record) => this.table.compareValues(this.getIndexValue(record), value) > 0);
2955
- }
2956
2911
  return this.createCollectionWithCondition({
2957
2912
  type: "comparison",
2958
- column: this.getColumn(),
2913
+ column: this.column,
2959
2914
  op: ">",
2960
2915
  value
2961
2916
  });
2962
2917
  }
2963
2918
  aboveOrEqual(value) {
2964
- if (this.isCompoundIndex()) {
2965
- return this.createCollectionWithJsPredicate((record) => this.table.compareValues(this.getIndexValue(record), value) >= 0);
2966
- }
2967
2919
  return this.createCollectionWithCondition({
2968
2920
  type: "comparison",
2969
- column: this.getColumn(),
2921
+ column: this.column,
2970
2922
  op: ">=",
2971
2923
  value
2972
2924
  });
2973
2925
  }
2974
2926
  below(value) {
2975
- if (this.isCompoundIndex()) {
2976
- return this.createCollectionWithJsPredicate((record) => this.table.compareValues(this.getIndexValue(record), value) < 0);
2977
- }
2978
2927
  return this.createCollectionWithCondition({
2979
2928
  type: "comparison",
2980
- column: this.getColumn(),
2929
+ column: this.column,
2981
2930
  op: "<",
2982
2931
  value
2983
2932
  });
2984
2933
  }
2985
2934
  belowOrEqual(value) {
2986
- if (this.isCompoundIndex()) {
2987
- return this.createCollectionWithJsPredicate((record) => this.table.compareValues(this.getIndexValue(record), value) <= 0);
2988
- }
2989
2935
  return this.createCollectionWithCondition({
2990
2936
  type: "comparison",
2991
- column: this.getColumn(),
2937
+ column: this.column,
2992
2938
  op: "<=",
2993
2939
  value
2994
2940
  });
2995
2941
  }
2996
2942
  between(lower, upper, includeLower = true, includeUpper = false) {
2997
- if (this.isCompoundIndex()) {
2998
- return this.createCollectionWithJsPredicate((record) => {
2999
- const value = this.getIndexValue(record);
3000
- const lowerCmp = this.table.compareValues(value, lower);
3001
- const upperCmp = this.table.compareValues(value, upper);
3002
- const lowerPass = includeLower ? lowerCmp >= 0 : lowerCmp > 0;
3003
- const upperPass = includeUpper ? upperCmp <= 0 : upperCmp < 0;
3004
- return lowerPass && upperPass;
3005
- });
3006
- }
3007
2943
  return this.createCollectionWithCondition({
3008
2944
  type: "between",
3009
- column: this.getColumn(),
2945
+ column: this.column,
3010
2946
  lower,
3011
2947
  upper,
3012
2948
  includeLower,
@@ -3014,22 +2950,17 @@ var SQLiteWhereClause = class {
3014
2950
  });
3015
2951
  }
3016
2952
  inAnyRange(ranges, options) {
3017
- if (this.isCompoundIndex() || ranges.length === 0) {
3018
- return this.createCollectionWithJsPredicate((record) => {
3019
- const value = this.getIndexValue(record);
3020
- return ranges.some(([lower, upper]) => {
3021
- const lowerCmp = this.table.compareValues(value, lower);
3022
- const upperCmp = this.table.compareValues(value, upper);
3023
- const lowerPass = options?.includeLower !== false ? lowerCmp >= 0 : lowerCmp > 0;
3024
- const upperPass = options?.includeUpper ? upperCmp <= 0 : upperCmp < 0;
3025
- return lowerPass && upperPass;
3026
- });
3027
- });
2953
+ if (ranges.length === 0) {
2954
+ return this.createCollectionWithCondition({
2955
+ type: "comparison",
2956
+ column: this.column,
2957
+ op: "=",
2958
+ value: null
2959
+ }).jsFilter(() => false);
3028
2960
  }
3029
- const column = this.getColumn();
3030
2961
  const orConditions = ranges.map(([lower, upper]) => ({
3031
2962
  type: "between",
3032
- column,
2963
+ column: this.column,
3033
2964
  lower,
3034
2965
  upper,
3035
2966
  includeLower: options?.includeLower !== false,
@@ -3041,44 +2972,37 @@ var SQLiteWhereClause = class {
3041
2972
  });
3042
2973
  }
3043
2974
  startsWith(prefix) {
3044
- if (this.isCompoundIndex()) {
3045
- return this.createCollectionWithJsPredicate((record) => String(this.getIndexValue(record) ?? "").startsWith(prefix));
3046
- }
3047
2975
  const escapedPrefix = prefix.replace(/[%_\\]/g, "\\$&");
3048
2976
  return this.createCollectionWithCondition({
3049
2977
  type: "like",
3050
- column: this.getColumn(),
2978
+ column: this.column,
3051
2979
  pattern: `${escapedPrefix}%`
3052
2980
  });
3053
2981
  }
3054
2982
  startsWithIgnoreCase(prefix) {
3055
- if (this.isCompoundIndex()) {
3056
- return this.createCollectionWithJsPredicate(
3057
- (record) => String(this.getIndexValue(record) ?? "").toLowerCase().startsWith(prefix.toLowerCase())
3058
- );
3059
- }
3060
2983
  const escapedPrefix = prefix.replace(/[%_\\]/g, "\\$&");
3061
2984
  return this.createCollectionWithCondition({
3062
2985
  type: "like",
3063
- column: this.getColumn(),
2986
+ column: this.column,
3064
2987
  pattern: `${escapedPrefix}%`,
3065
2988
  caseInsensitive: true
3066
2989
  });
3067
2990
  }
3068
2991
  startsWithAnyOf(...args) {
3069
2992
  const prefixes = this.flattenArgs(args);
3070
- if (this.isCompoundIndex() || prefixes.length === 0) {
3071
- return this.createCollectionWithJsPredicate((record) => {
3072
- const value = String(this.getIndexValue(record) ?? "");
3073
- return prefixes.some((prefix) => value.startsWith(prefix));
3074
- });
2993
+ if (prefixes.length === 0) {
2994
+ return this.createCollectionWithCondition({
2995
+ type: "comparison",
2996
+ column: this.column,
2997
+ op: "=",
2998
+ value: null
2999
+ }).jsFilter(() => false);
3075
3000
  }
3076
- const column = this.getColumn();
3077
3001
  const orConditions = prefixes.map((prefix) => {
3078
3002
  const escapedPrefix = prefix.replace(/[%_\\]/g, "\\$&");
3079
3003
  return {
3080
3004
  type: "like",
3081
- column,
3005
+ column: this.column,
3082
3006
  pattern: `${escapedPrefix}%`
3083
3007
  };
3084
3008
  });
@@ -3089,19 +3013,19 @@ var SQLiteWhereClause = class {
3089
3013
  }
3090
3014
  startsWithAnyOfIgnoreCase(...args) {
3091
3015
  const prefixes = this.flattenArgs(args);
3092
- if (this.isCompoundIndex() || prefixes.length === 0) {
3093
- const lowerPrefixes = prefixes.map((p) => p.toLowerCase());
3094
- return this.createCollectionWithJsPredicate((record) => {
3095
- const value = String(this.getIndexValue(record) ?? "").toLowerCase();
3096
- return lowerPrefixes.some((prefix) => value.startsWith(prefix));
3097
- });
3016
+ if (prefixes.length === 0) {
3017
+ return this.createCollectionWithCondition({
3018
+ type: "comparison",
3019
+ column: this.column,
3020
+ op: "=",
3021
+ value: null
3022
+ }).jsFilter(() => false);
3098
3023
  }
3099
- const column = this.getColumn();
3100
3024
  const orConditions = prefixes.map((prefix) => {
3101
3025
  const escapedPrefix = prefix.replace(/[%_\\]/g, "\\$&");
3102
3026
  return {
3103
3027
  type: "like",
3104
- column,
3028
+ column: this.column,
3105
3029
  pattern: `${escapedPrefix}%`,
3106
3030
  caseInsensitive: true
3107
3031
  };
@@ -3112,72 +3036,42 @@ var SQLiteWhereClause = class {
3112
3036
  });
3113
3037
  }
3114
3038
  equalsIgnoreCase(value) {
3115
- if (this.isCompoundIndex()) {
3116
- return this.createCollectionWithJsPredicate((record) => String(this.getIndexValue(record) ?? "").toLowerCase() === value.toLowerCase());
3117
- }
3118
3039
  return this.createCollectionWithCondition({
3119
3040
  type: "equals",
3120
- column: this.getColumn(),
3041
+ column: this.column,
3121
3042
  value,
3122
3043
  caseInsensitive: true
3123
3044
  });
3124
3045
  }
3125
3046
  anyOf(...args) {
3126
3047
  const values = this.flattenArgs(args);
3127
- if (this.isCompoundIndex()) {
3128
- const columns = this.getCompoundColumns();
3129
- const orConditions = values.map((value) => ({
3130
- type: "compoundEquals",
3131
- columns,
3132
- values: this.getCompoundValues(value)
3133
- }));
3134
- return this.createCollectionWithCondition({
3135
- type: "or",
3136
- conditions: orConditions
3137
- });
3138
- }
3139
3048
  return this.createCollectionWithCondition({
3140
3049
  type: "in",
3141
- column: this.getColumn(),
3050
+ column: this.column,
3142
3051
  values
3143
3052
  });
3144
3053
  }
3145
3054
  anyOfIgnoreCase(...args) {
3146
3055
  const values = this.flattenArgs(args);
3147
- if (this.isCompoundIndex()) {
3148
- const lowerValues = values.map((v) => v.toLowerCase());
3149
- return this.createCollectionWithJsPredicate((record) => {
3150
- const value = String(this.getIndexValue(record) ?? "").toLowerCase();
3151
- return lowerValues.includes(value);
3152
- });
3153
- }
3154
3056
  return this.createCollectionWithCondition({
3155
3057
  type: "in",
3156
- column: this.getColumn(),
3058
+ column: this.column,
3157
3059
  values,
3158
3060
  caseInsensitive: true
3159
3061
  });
3160
3062
  }
3161
3063
  noneOf(...args) {
3162
3064
  const values = this.flattenArgs(args);
3163
- if (this.isCompoundIndex()) {
3164
- return this.createCollectionWithJsPredicate(
3165
- (record) => values.every((candidate) => this.table.compareValues(this.getIndexValue(record), candidate) !== 0)
3166
- );
3167
- }
3168
3065
  return this.createCollectionWithCondition({
3169
3066
  type: "notIn",
3170
- column: this.getColumn(),
3067
+ column: this.column,
3171
3068
  values
3172
3069
  });
3173
3070
  }
3174
3071
  notEqual(value) {
3175
- if (this.isCompoundIndex()) {
3176
- return this.createCollectionWithJsPredicate((record) => this.table.compareValues(this.getIndexValue(record), value) !== 0);
3177
- }
3178
3072
  return this.createCollectionWithCondition({
3179
3073
  type: "comparison",
3180
- column: this.getColumn(),
3074
+ column: this.column,
3181
3075
  op: "!=",
3182
3076
  value
3183
3077
  });
@@ -3188,7 +3082,6 @@ var SQLiteWhereClause = class {
3188
3082
  var SQLiteTable = class {
3189
3083
  name;
3190
3084
  schema;
3191
- hook = Object.freeze({});
3192
3085
  raw;
3193
3086
  adapter;
3194
3087
  columnNames;
@@ -3357,9 +3250,6 @@ var SQLiteTable = class {
3357
3250
  limit(count) {
3358
3251
  return this.createCollection({ limit: count });
3359
3252
  }
3360
- mapToClass(_ctor) {
3361
- return this;
3362
- }
3363
3253
  async each(callback) {
3364
3254
  const entries = await this.getEntries();
3365
3255
  for (const entry of entries) {
@@ -3381,8 +3271,8 @@ var SQLiteTable = class {
3381
3271
  jsPredicate: combinedPredicate
3382
3272
  });
3383
3273
  }
3384
- createWhereClause(index, baseCollection) {
3385
- return new SQLiteWhereClause(this, index, baseCollection);
3274
+ createWhereClause(column, baseCollection) {
3275
+ return new SQLiteWhereClause(this, column, baseCollection);
3386
3276
  }
3387
3277
  async *iterateEntries(options) {
3388
3278
  const selectClause = this.buildSelectClause();
@@ -3881,4 +3771,4 @@ export {
3881
3771
  SqliteQueryContext,
3882
3772
  SQLiteAdapter2 as SQLiteAdapter
3883
3773
  };
3884
- //# sourceMappingURL=chunk-PCA4XM2N.js.map
3774
+ //# sourceMappingURL=chunk-MOYMEJP5.js.map