@ragestudio/scylla-odm 0.22.9 → 0.22.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.
@@ -18,6 +18,26 @@
18
18
 
19
19
  import { QueryOperator, QueryAssignment } from "./q.js"
20
20
 
21
+ // duck-type checks to avoid instanceof failures
22
+ // caused by duplicate class references in bundled ESM/CJS output
23
+ function isQueryOperator(v) {
24
+ return (
25
+ v != null &&
26
+ typeof v === "object" &&
27
+ typeof v.key === "string" &&
28
+ "value" in v
29
+ )
30
+ }
31
+
32
+ function isQueryAssignment(v) {
33
+ return (
34
+ v != null &&
35
+ typeof v === "object" &&
36
+ typeof v.sign === "string" &&
37
+ "value" in v
38
+ )
39
+ }
40
+
21
41
  /**
22
42
  * Provides utility methods for obtaining a caching keys based on the specifics of the Mapper methods.
23
43
  * @ignore
@@ -180,11 +200,7 @@ class Cache {
180
200
  }
181
201
 
182
202
  static *_yieldOperators(value) {
183
- if (
184
- value !== null &&
185
- value !== undefined &&
186
- value instanceof QueryOperator
187
- ) {
203
+ if (value !== null && value !== undefined && isQueryOperator(value)) {
188
204
  yield value.key
189
205
  if (value.hasChildValues) {
190
206
  yield* Cache._yieldOperators(value.value[0])
@@ -200,9 +216,9 @@ class Cache {
200
216
  yield key
201
217
  const value = obj[key]
202
218
  if (value !== null && value !== undefined) {
203
- if (value instanceof QueryOperator) {
219
+ if (isQueryOperator(value)) {
204
220
  yield* Cache._yieldOperators(value)
205
- } else if (value instanceof QueryAssignment) {
221
+ } else if (isQueryAssignment(value)) {
206
222
  yield value.sign
207
223
  yield value.inverted
208
224
  }
@@ -21,6 +21,26 @@ import { QueryOperator, QueryAssignment } from "./q.js"
21
21
  import types from "../types/index.js"
22
22
  const dataTypes = types.dataTypes
23
23
 
24
+ // duck-type checks to avoid instanceof failures
25
+ // caused by duplicate class references in bundled ESM/CJS output
26
+ function isQueryOperator(v) {
27
+ return (
28
+ v != null &&
29
+ typeof v === "object" &&
30
+ typeof v.key === "string" &&
31
+ "value" in v
32
+ )
33
+ }
34
+
35
+ function isQueryAssignment(v) {
36
+ return (
37
+ v != null &&
38
+ typeof v === "object" &&
39
+ typeof v.sign === "string" &&
40
+ "value" in v
41
+ )
42
+ }
43
+
24
44
  const vmFileName = "gen-param-getter"
25
45
 
26
46
  /**
@@ -205,7 +225,7 @@ class QueryGenerator {
205
225
 
206
226
  if (
207
227
  column.type.code === dataTypes.list &&
208
- pInfo.value instanceof QueryAssignment
228
+ isQueryAssignment(pInfo.value)
209
229
  ) {
210
230
  // Its not idempotent when list append/prepend
211
231
  isIdempotent = false
@@ -269,7 +289,7 @@ class QueryGenerator {
269
289
  query += propertiesInfo
270
290
  .filter((p) => !primaryKeys.has(p.columnName))
271
291
  .map((p) => {
272
- if (p.value instanceof QueryAssignment) {
292
+ if (isQueryAssignment(p.value)) {
273
293
  if (p.value.inverted) {
274
294
  // e.g: prepend "col1 = ? + col1"
275
295
  return `"${p.columnName}" = ? ${p.value.sign} "${p.columnName}"`
@@ -482,7 +502,7 @@ class QueryGenerator {
482
502
  static _valueGetterSingle(prefix, propName, value, fromModelFn) {
483
503
  let valueGetter = prefix
484
504
 
485
- if (value instanceof QueryOperator) {
505
+ if (isQueryOperator(value)) {
486
506
  if (value.hasChildValues) {
487
507
  return (
488
508
  `${QueryGenerator._valueGetterSingle(`${prefix}.value[0]`, propName, value.value[0], fromModelFn)}` +
@@ -515,7 +535,7 @@ class QueryGenerator {
515
535
 
516
536
  return propertiesInfo
517
537
  .map((p) => {
518
- const valueGetter = `${prefix}['${p.propertyName}']${p.value instanceof QueryAssignment ? ".value" : ""}`
538
+ const valueGetter = `${prefix}['${p.propertyName}']${isQueryAssignment(p.value) ? ".value" : ""}`
519
539
  if (p.fromModel) {
520
540
  return QueryGenerator._getMappingFunctionCall(
521
541
  p.propertyName,
@@ -540,7 +560,7 @@ class QueryGenerator {
540
560
  }
541
561
 
542
562
  static _getSingleCondition(columnName, value) {
543
- if (value instanceof QueryOperator) {
563
+ if (isQueryOperator(value)) {
544
564
  if (value.hasChildValues) {
545
565
  return (
546
566
  `${QueryGenerator._getSingleCondition(columnName, value.value[0])}` +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ragestudio/scylla-odm",
3
- "version": "0.22.9",
3
+ "version": "0.22.10",
4
4
  "description": "An ODM for ScyllaDB/Cassandra",
5
5
  "license": "MIT",
6
6
  "author": "RageStudio",