@anfenn/dync 1.0.7 → 1.0.9

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/dist/index.cjs CHANGED
@@ -1892,11 +1892,11 @@ var MemoryCollection = class _MemoryCollection {
1892
1892
  // src/storage/memory/MemoryWhereClause.ts
1893
1893
  var MemoryWhereClause = class {
1894
1894
  table;
1895
- index;
1895
+ column;
1896
1896
  baseCollection;
1897
- constructor(table, index, baseCollection) {
1897
+ constructor(table, column, baseCollection) {
1898
1898
  this.table = table;
1899
- this.index = index;
1899
+ this.column = column;
1900
1900
  this.baseCollection = baseCollection;
1901
1901
  }
1902
1902
  equals(value) {
@@ -1975,9 +1975,9 @@ var MemoryWhereClause = class {
1975
1975
  return this.createCollection((current) => this.table.compareValues(current, value) !== 0);
1976
1976
  }
1977
1977
  createCollection(predicate) {
1978
- const condition = (record, _key) => predicate(this.table.getIndexValue(record, this.index));
1978
+ const condition = (record, _key) => predicate(this.table.getIndexValue(record, this.column));
1979
1979
  if (this.baseCollection) {
1980
- const combined = (record, key) => this.baseCollection.matches(record, key) || predicate(this.table.getIndexValue(record, this.index));
1980
+ const combined = (record, key) => this.baseCollection.matches(record, key) || predicate(this.table.getIndexValue(record, this.column));
1981
1981
  return this.table.createCollectionFromPredicate(combined, this.baseCollection);
1982
1982
  }
1983
1983
  return this.table.createCollectionFromPredicate(condition);
@@ -1995,7 +1995,6 @@ var MemoryTable = class {
1995
1995
  name;
1996
1996
  schema = void 0;
1997
1997
  primaryKey = LOCAL_PK;
1998
- hook = Object.freeze({});
1999
1998
  raw;
2000
1999
  records = /* @__PURE__ */ new Map();
2001
2000
  constructor(name) {
@@ -2104,9 +2103,6 @@ var MemoryTable = class {
2104
2103
  limit(count) {
2105
2104
  return this.createCollection({ limit: count });
2106
2105
  }
2107
- mapToClass(_ctor) {
2108
- return this;
2109
- }
2110
2106
  async each(callback) {
2111
2107
  for (const [, record] of this.entries()) {
2112
2108
  await callback(this.cloneRecord(record));
@@ -2131,8 +2127,8 @@ var MemoryTable = class {
2131
2127
  predicate
2132
2128
  });
2133
2129
  }
2134
- createWhereClause(index, baseCollection) {
2135
- return new MemoryWhereClause(this, index, baseCollection);
2130
+ createWhereClause(column, baseCollection) {
2131
+ return new MemoryWhereClause(this, column, baseCollection);
2136
2132
  }
2137
2133
  entries() {
2138
2134
  return Array.from(this.records.entries());
@@ -2346,10 +2342,6 @@ var buildCondition = (condition) => {
2346
2342
  }
2347
2343
  return { clause: `(${subClauses.join(" OR ")})`, parameters: subParams };
2348
2344
  }
2349
- if (condition.type === "compoundEquals") {
2350
- const clauses = condition.columns.map((col2) => `${quoteIdentifier(col2)} = ?`);
2351
- return { clause: `(${clauses.join(" AND ")})`, parameters: condition.values };
2352
- }
2353
2345
  const col = quoteIdentifier(condition.column);
2354
2346
  switch (condition.type) {
2355
2347
  case "equals": {
@@ -2923,42 +2915,17 @@ var SQLiteAdapter2 = class {
2923
2915
  // src/storage/sqlite/SQLiteWhereClause.ts
2924
2916
  var SQLiteWhereClause = class {
2925
2917
  table;
2926
- index;
2918
+ column;
2927
2919
  baseCollection;
2928
- constructor(table, index, baseCollection) {
2920
+ constructor(table, column, baseCollection) {
2929
2921
  this.table = table;
2930
- this.index = index;
2922
+ this.column = column;
2931
2923
  this.baseCollection = baseCollection;
2932
2924
  }
2933
- getColumn() {
2934
- if (Array.isArray(this.index)) {
2935
- return this.index[0];
2936
- }
2937
- return this.index;
2938
- }
2939
- isCompoundIndex() {
2940
- return Array.isArray(this.index) && this.index.length > 1;
2941
- }
2942
- getCompoundColumns() {
2943
- return Array.isArray(this.index) ? this.index : [this.index];
2944
- }
2945
- getCompoundValues(value) {
2946
- if (Array.isArray(value)) {
2947
- return value;
2948
- }
2949
- return [value];
2950
- }
2951
2925
  createCollectionWithCondition(condition) {
2952
2926
  const base = this.baseCollection ?? this.table.createCollection();
2953
2927
  return base.addSqlCondition(condition);
2954
2928
  }
2955
- createCollectionWithJsPredicate(predicate) {
2956
- const base = this.baseCollection ?? this.table.createCollection();
2957
- return base.jsFilter(predicate);
2958
- }
2959
- getIndexValue(record) {
2960
- return this.table.getIndexValue(record, this.index);
2961
- }
2962
2929
  flattenArgs(args) {
2963
2930
  if (args.length === 1 && Array.isArray(args[0])) {
2964
2931
  return args[0];
@@ -2966,79 +2933,48 @@ var SQLiteWhereClause = class {
2966
2933
  return args;
2967
2934
  }
2968
2935
  equals(value) {
2969
- if (this.isCompoundIndex()) {
2970
- const columns = this.getCompoundColumns();
2971
- const values = this.getCompoundValues(value);
2972
- return this.createCollectionWithCondition({
2973
- type: "compoundEquals",
2974
- columns,
2975
- values
2976
- });
2977
- }
2978
2936
  return this.createCollectionWithCondition({
2979
2937
  type: "equals",
2980
- column: this.getColumn(),
2938
+ column: this.column,
2981
2939
  value
2982
2940
  });
2983
2941
  }
2984
2942
  above(value) {
2985
- if (this.isCompoundIndex()) {
2986
- return this.createCollectionWithJsPredicate((record) => this.table.compareValues(this.getIndexValue(record), value) > 0);
2987
- }
2988
2943
  return this.createCollectionWithCondition({
2989
2944
  type: "comparison",
2990
- column: this.getColumn(),
2945
+ column: this.column,
2991
2946
  op: ">",
2992
2947
  value
2993
2948
  });
2994
2949
  }
2995
2950
  aboveOrEqual(value) {
2996
- if (this.isCompoundIndex()) {
2997
- return this.createCollectionWithJsPredicate((record) => this.table.compareValues(this.getIndexValue(record), value) >= 0);
2998
- }
2999
2951
  return this.createCollectionWithCondition({
3000
2952
  type: "comparison",
3001
- column: this.getColumn(),
2953
+ column: this.column,
3002
2954
  op: ">=",
3003
2955
  value
3004
2956
  });
3005
2957
  }
3006
2958
  below(value) {
3007
- if (this.isCompoundIndex()) {
3008
- return this.createCollectionWithJsPredicate((record) => this.table.compareValues(this.getIndexValue(record), value) < 0);
3009
- }
3010
2959
  return this.createCollectionWithCondition({
3011
2960
  type: "comparison",
3012
- column: this.getColumn(),
2961
+ column: this.column,
3013
2962
  op: "<",
3014
2963
  value
3015
2964
  });
3016
2965
  }
3017
2966
  belowOrEqual(value) {
3018
- if (this.isCompoundIndex()) {
3019
- return this.createCollectionWithJsPredicate((record) => this.table.compareValues(this.getIndexValue(record), value) <= 0);
3020
- }
3021
2967
  return this.createCollectionWithCondition({
3022
2968
  type: "comparison",
3023
- column: this.getColumn(),
2969
+ column: this.column,
3024
2970
  op: "<=",
3025
2971
  value
3026
2972
  });
3027
2973
  }
3028
2974
  between(lower, upper, includeLower = true, includeUpper = false) {
3029
- if (this.isCompoundIndex()) {
3030
- return this.createCollectionWithJsPredicate((record) => {
3031
- const value = this.getIndexValue(record);
3032
- const lowerCmp = this.table.compareValues(value, lower);
3033
- const upperCmp = this.table.compareValues(value, upper);
3034
- const lowerPass = includeLower ? lowerCmp >= 0 : lowerCmp > 0;
3035
- const upperPass = includeUpper ? upperCmp <= 0 : upperCmp < 0;
3036
- return lowerPass && upperPass;
3037
- });
3038
- }
3039
2975
  return this.createCollectionWithCondition({
3040
2976
  type: "between",
3041
- column: this.getColumn(),
2977
+ column: this.column,
3042
2978
  lower,
3043
2979
  upper,
3044
2980
  includeLower,
@@ -3046,22 +2982,17 @@ var SQLiteWhereClause = class {
3046
2982
  });
3047
2983
  }
3048
2984
  inAnyRange(ranges, options) {
3049
- if (this.isCompoundIndex() || ranges.length === 0) {
3050
- return this.createCollectionWithJsPredicate((record) => {
3051
- const value = this.getIndexValue(record);
3052
- return ranges.some(([lower, upper]) => {
3053
- const lowerCmp = this.table.compareValues(value, lower);
3054
- const upperCmp = this.table.compareValues(value, upper);
3055
- const lowerPass = options?.includeLower !== false ? lowerCmp >= 0 : lowerCmp > 0;
3056
- const upperPass = options?.includeUpper ? upperCmp <= 0 : upperCmp < 0;
3057
- return lowerPass && upperPass;
3058
- });
3059
- });
2985
+ if (ranges.length === 0) {
2986
+ return this.createCollectionWithCondition({
2987
+ type: "comparison",
2988
+ column: this.column,
2989
+ op: "=",
2990
+ value: null
2991
+ }).jsFilter(() => false);
3060
2992
  }
3061
- const column = this.getColumn();
3062
2993
  const orConditions = ranges.map(([lower, upper]) => ({
3063
2994
  type: "between",
3064
- column,
2995
+ column: this.column,
3065
2996
  lower,
3066
2997
  upper,
3067
2998
  includeLower: options?.includeLower !== false,
@@ -3073,44 +3004,37 @@ var SQLiteWhereClause = class {
3073
3004
  });
3074
3005
  }
3075
3006
  startsWith(prefix) {
3076
- if (this.isCompoundIndex()) {
3077
- return this.createCollectionWithJsPredicate((record) => String(this.getIndexValue(record) ?? "").startsWith(prefix));
3078
- }
3079
3007
  const escapedPrefix = prefix.replace(/[%_\\]/g, "\\$&");
3080
3008
  return this.createCollectionWithCondition({
3081
3009
  type: "like",
3082
- column: this.getColumn(),
3010
+ column: this.column,
3083
3011
  pattern: `${escapedPrefix}%`
3084
3012
  });
3085
3013
  }
3086
3014
  startsWithIgnoreCase(prefix) {
3087
- if (this.isCompoundIndex()) {
3088
- return this.createCollectionWithJsPredicate(
3089
- (record) => String(this.getIndexValue(record) ?? "").toLowerCase().startsWith(prefix.toLowerCase())
3090
- );
3091
- }
3092
3015
  const escapedPrefix = prefix.replace(/[%_\\]/g, "\\$&");
3093
3016
  return this.createCollectionWithCondition({
3094
3017
  type: "like",
3095
- column: this.getColumn(),
3018
+ column: this.column,
3096
3019
  pattern: `${escapedPrefix}%`,
3097
3020
  caseInsensitive: true
3098
3021
  });
3099
3022
  }
3100
3023
  startsWithAnyOf(...args) {
3101
3024
  const prefixes = this.flattenArgs(args);
3102
- if (this.isCompoundIndex() || prefixes.length === 0) {
3103
- return this.createCollectionWithJsPredicate((record) => {
3104
- const value = String(this.getIndexValue(record) ?? "");
3105
- return prefixes.some((prefix) => value.startsWith(prefix));
3106
- });
3025
+ if (prefixes.length === 0) {
3026
+ return this.createCollectionWithCondition({
3027
+ type: "comparison",
3028
+ column: this.column,
3029
+ op: "=",
3030
+ value: null
3031
+ }).jsFilter(() => false);
3107
3032
  }
3108
- const column = this.getColumn();
3109
3033
  const orConditions = prefixes.map((prefix) => {
3110
3034
  const escapedPrefix = prefix.replace(/[%_\\]/g, "\\$&");
3111
3035
  return {
3112
3036
  type: "like",
3113
- column,
3037
+ column: this.column,
3114
3038
  pattern: `${escapedPrefix}%`
3115
3039
  };
3116
3040
  });
@@ -3121,19 +3045,19 @@ var SQLiteWhereClause = class {
3121
3045
  }
3122
3046
  startsWithAnyOfIgnoreCase(...args) {
3123
3047
  const prefixes = this.flattenArgs(args);
3124
- if (this.isCompoundIndex() || prefixes.length === 0) {
3125
- const lowerPrefixes = prefixes.map((p) => p.toLowerCase());
3126
- return this.createCollectionWithJsPredicate((record) => {
3127
- const value = String(this.getIndexValue(record) ?? "").toLowerCase();
3128
- return lowerPrefixes.some((prefix) => value.startsWith(prefix));
3129
- });
3048
+ if (prefixes.length === 0) {
3049
+ return this.createCollectionWithCondition({
3050
+ type: "comparison",
3051
+ column: this.column,
3052
+ op: "=",
3053
+ value: null
3054
+ }).jsFilter(() => false);
3130
3055
  }
3131
- const column = this.getColumn();
3132
3056
  const orConditions = prefixes.map((prefix) => {
3133
3057
  const escapedPrefix = prefix.replace(/[%_\\]/g, "\\$&");
3134
3058
  return {
3135
3059
  type: "like",
3136
- column,
3060
+ column: this.column,
3137
3061
  pattern: `${escapedPrefix}%`,
3138
3062
  caseInsensitive: true
3139
3063
  };
@@ -3144,72 +3068,42 @@ var SQLiteWhereClause = class {
3144
3068
  });
3145
3069
  }
3146
3070
  equalsIgnoreCase(value) {
3147
- if (this.isCompoundIndex()) {
3148
- return this.createCollectionWithJsPredicate((record) => String(this.getIndexValue(record) ?? "").toLowerCase() === value.toLowerCase());
3149
- }
3150
3071
  return this.createCollectionWithCondition({
3151
3072
  type: "equals",
3152
- column: this.getColumn(),
3073
+ column: this.column,
3153
3074
  value,
3154
3075
  caseInsensitive: true
3155
3076
  });
3156
3077
  }
3157
3078
  anyOf(...args) {
3158
3079
  const values = this.flattenArgs(args);
3159
- if (this.isCompoundIndex()) {
3160
- const columns = this.getCompoundColumns();
3161
- const orConditions = values.map((value) => ({
3162
- type: "compoundEquals",
3163
- columns,
3164
- values: this.getCompoundValues(value)
3165
- }));
3166
- return this.createCollectionWithCondition({
3167
- type: "or",
3168
- conditions: orConditions
3169
- });
3170
- }
3171
3080
  return this.createCollectionWithCondition({
3172
3081
  type: "in",
3173
- column: this.getColumn(),
3082
+ column: this.column,
3174
3083
  values
3175
3084
  });
3176
3085
  }
3177
3086
  anyOfIgnoreCase(...args) {
3178
3087
  const values = this.flattenArgs(args);
3179
- if (this.isCompoundIndex()) {
3180
- const lowerValues = values.map((v) => v.toLowerCase());
3181
- return this.createCollectionWithJsPredicate((record) => {
3182
- const value = String(this.getIndexValue(record) ?? "").toLowerCase();
3183
- return lowerValues.includes(value);
3184
- });
3185
- }
3186
3088
  return this.createCollectionWithCondition({
3187
3089
  type: "in",
3188
- column: this.getColumn(),
3090
+ column: this.column,
3189
3091
  values,
3190
3092
  caseInsensitive: true
3191
3093
  });
3192
3094
  }
3193
3095
  noneOf(...args) {
3194
3096
  const values = this.flattenArgs(args);
3195
- if (this.isCompoundIndex()) {
3196
- return this.createCollectionWithJsPredicate(
3197
- (record) => values.every((candidate) => this.table.compareValues(this.getIndexValue(record), candidate) !== 0)
3198
- );
3199
- }
3200
3097
  return this.createCollectionWithCondition({
3201
3098
  type: "notIn",
3202
- column: this.getColumn(),
3099
+ column: this.column,
3203
3100
  values
3204
3101
  });
3205
3102
  }
3206
3103
  notEqual(value) {
3207
- if (this.isCompoundIndex()) {
3208
- return this.createCollectionWithJsPredicate((record) => this.table.compareValues(this.getIndexValue(record), value) !== 0);
3209
- }
3210
3104
  return this.createCollectionWithCondition({
3211
3105
  type: "comparison",
3212
- column: this.getColumn(),
3106
+ column: this.column,
3213
3107
  op: "!=",
3214
3108
  value
3215
3109
  });
@@ -3220,7 +3114,6 @@ var SQLiteWhereClause = class {
3220
3114
  var SQLiteTable = class {
3221
3115
  name;
3222
3116
  schema;
3223
- hook = Object.freeze({});
3224
3117
  raw;
3225
3118
  adapter;
3226
3119
  columnNames;
@@ -3389,9 +3282,6 @@ var SQLiteTable = class {
3389
3282
  limit(count) {
3390
3283
  return this.createCollection({ limit: count });
3391
3284
  }
3392
- mapToClass(_ctor) {
3393
- return this;
3394
- }
3395
3285
  async each(callback) {
3396
3286
  const entries = await this.getEntries();
3397
3287
  for (const entry of entries) {
@@ -3413,8 +3303,8 @@ var SQLiteTable = class {
3413
3303
  jsPredicate: combinedPredicate
3414
3304
  });
3415
3305
  }
3416
- createWhereClause(index, baseCollection) {
3417
- return new SQLiteWhereClause(this, index, baseCollection);
3306
+ createWhereClause(column, baseCollection) {
3307
+ return new SQLiteWhereClause(this, column, baseCollection);
3418
3308
  }
3419
3309
  async *iterateEntries(options) {
3420
3310
  const selectClause = this.buildSelectClause();