rads-db 0.1.21 → 0.1.23
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 +12 -6
- package/dist/index.mjs +12 -6
- package/drivers/azureCosmos.cjs +19 -4
- package/drivers/azureCosmos.mjs +10 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -356,7 +356,8 @@ function getCosmosQuery(schema, entity, args) {
|
|
|
356
356
|
const operatorHandlers = {
|
|
357
357
|
some: (ctx, parameters, whereArgs) => {
|
|
358
358
|
const { name, namePrefix, whereVal } = whereArgs;
|
|
359
|
-
const
|
|
359
|
+
const newCtx = { ...ctx, entity: ctx.schema[ctx.entity].fields[ctx.field].type };
|
|
360
|
+
const subClause = getCosmosQueryWhere(newCtx, parameters, whereVal, `${namePrefix}${name}.`);
|
|
360
361
|
if (subClause) {
|
|
361
362
|
if (simpleSubclauseRegex.test(subClause)) {
|
|
362
363
|
const parts = subClause.split(" ");
|
|
@@ -370,7 +371,8 @@ const operatorHandlers = {
|
|
|
370
371
|
},
|
|
371
372
|
none: (ctx, parameters, whereArgs) => {
|
|
372
373
|
const { name, namePrefix, whereVal } = whereArgs;
|
|
373
|
-
const
|
|
374
|
+
const newCtx = { ...ctx, entity: ctx.schema[ctx.entity].fields[ctx.field].type };
|
|
375
|
+
const subClause = getCosmosQueryWhere(newCtx, parameters, whereVal, `${namePrefix}${name}.`);
|
|
374
376
|
if (subClause)
|
|
375
377
|
return `not exists (select ${name} from ${name} in ${namePrefix}${name} where ${subClause})`;
|
|
376
378
|
return `array_length(${namePrefix}${name}) = 0`;
|
|
@@ -453,8 +455,12 @@ const operatorHandlers = {
|
|
|
453
455
|
},
|
|
454
456
|
contains: (ctx, parameters, whereArgs) => {
|
|
455
457
|
const { name, namePrefix, paramName, paramNamePrefix, whereVal } = whereArgs;
|
|
458
|
+
const fieldType = ctx.schema[ctx.entity].fields[ctx.field];
|
|
456
459
|
const pn = `${paramNamePrefix}${paramName}`;
|
|
457
460
|
parameters[pn] = whereVal;
|
|
461
|
+
if (fieldType.isArray) {
|
|
462
|
+
return `array_contains(${namePrefix}${name}, @${pn})`;
|
|
463
|
+
}
|
|
458
464
|
return `contains(${namePrefix}${name}, @${pn})`;
|
|
459
465
|
},
|
|
460
466
|
icontains: (ctx, parameters, whereArgs) => {
|
|
@@ -503,11 +509,11 @@ function getCosmosQueryWhere(ctx, parameters, where, namePrefix = "r.", paramNam
|
|
|
503
509
|
name = `["${name}"]`;
|
|
504
510
|
namePrefix = namePrefix.slice(0, -1);
|
|
505
511
|
}
|
|
506
|
-
const paramName =
|
|
512
|
+
const paramName = key;
|
|
507
513
|
const whereVal = where[key];
|
|
508
514
|
if (whereVal == null)
|
|
509
515
|
continue;
|
|
510
|
-
const f = getCosmosQueryWhereInner(ctx, parameters, {
|
|
516
|
+
const f = getCosmosQueryWhereInner({ ...ctx, field: nameFromWhere }, parameters, {
|
|
511
517
|
operator,
|
|
512
518
|
whereVal,
|
|
513
519
|
name,
|
|
@@ -586,14 +592,14 @@ function generateMethods(schema, validators, args) {
|
|
|
586
592
|
},
|
|
587
593
|
getMany: async (args2, ctx) => {
|
|
588
594
|
args2 = args2 || {};
|
|
589
|
-
const result = await driverInstance.getMany(args2);
|
|
595
|
+
const result = await driverInstance.getMany(args2, ctx);
|
|
590
596
|
if (args2.include)
|
|
591
597
|
await handleInclude(schema, key, args2.include, result.nodes);
|
|
592
598
|
return result;
|
|
593
599
|
},
|
|
594
600
|
getAll: async (args2, ctx) => {
|
|
595
601
|
args2 = args2 || {};
|
|
596
|
-
const result = await driverInstance.getAll(args2);
|
|
602
|
+
const result = await driverInstance.getAll(args2, ctx);
|
|
597
603
|
if (args2.include)
|
|
598
604
|
await handleInclude(schema, key, args2.include, result);
|
|
599
605
|
return result;
|
package/dist/index.mjs
CHANGED
|
@@ -349,7 +349,8 @@ function getCosmosQuery(schema, entity, args) {
|
|
|
349
349
|
const operatorHandlers = {
|
|
350
350
|
some: (ctx, parameters, whereArgs) => {
|
|
351
351
|
const { name, namePrefix, whereVal } = whereArgs;
|
|
352
|
-
const
|
|
352
|
+
const newCtx = { ...ctx, entity: ctx.schema[ctx.entity].fields[ctx.field].type };
|
|
353
|
+
const subClause = getCosmosQueryWhere(newCtx, parameters, whereVal, `${namePrefix}${name}.`);
|
|
353
354
|
if (subClause) {
|
|
354
355
|
if (simpleSubclauseRegex.test(subClause)) {
|
|
355
356
|
const parts = subClause.split(" ");
|
|
@@ -363,7 +364,8 @@ const operatorHandlers = {
|
|
|
363
364
|
},
|
|
364
365
|
none: (ctx, parameters, whereArgs) => {
|
|
365
366
|
const { name, namePrefix, whereVal } = whereArgs;
|
|
366
|
-
const
|
|
367
|
+
const newCtx = { ...ctx, entity: ctx.schema[ctx.entity].fields[ctx.field].type };
|
|
368
|
+
const subClause = getCosmosQueryWhere(newCtx, parameters, whereVal, `${namePrefix}${name}.`);
|
|
367
369
|
if (subClause)
|
|
368
370
|
return `not exists (select ${name} from ${name} in ${namePrefix}${name} where ${subClause})`;
|
|
369
371
|
return `array_length(${namePrefix}${name}) = 0`;
|
|
@@ -446,8 +448,12 @@ const operatorHandlers = {
|
|
|
446
448
|
},
|
|
447
449
|
contains: (ctx, parameters, whereArgs) => {
|
|
448
450
|
const { name, namePrefix, paramName, paramNamePrefix, whereVal } = whereArgs;
|
|
451
|
+
const fieldType = ctx.schema[ctx.entity].fields[ctx.field];
|
|
449
452
|
const pn = `${paramNamePrefix}${paramName}`;
|
|
450
453
|
parameters[pn] = whereVal;
|
|
454
|
+
if (fieldType.isArray) {
|
|
455
|
+
return `array_contains(${namePrefix}${name}, @${pn})`;
|
|
456
|
+
}
|
|
451
457
|
return `contains(${namePrefix}${name}, @${pn})`;
|
|
452
458
|
},
|
|
453
459
|
icontains: (ctx, parameters, whereArgs) => {
|
|
@@ -496,11 +502,11 @@ function getCosmosQueryWhere(ctx, parameters, where, namePrefix = "r.", paramNam
|
|
|
496
502
|
name = `["${name}"]`;
|
|
497
503
|
namePrefix = namePrefix.slice(0, -1);
|
|
498
504
|
}
|
|
499
|
-
const paramName =
|
|
505
|
+
const paramName = key;
|
|
500
506
|
const whereVal = where[key];
|
|
501
507
|
if (whereVal == null)
|
|
502
508
|
continue;
|
|
503
|
-
const f = getCosmosQueryWhereInner(ctx, parameters, {
|
|
509
|
+
const f = getCosmosQueryWhereInner({ ...ctx, field: nameFromWhere }, parameters, {
|
|
504
510
|
operator,
|
|
505
511
|
whereVal,
|
|
506
512
|
name,
|
|
@@ -579,14 +585,14 @@ function generateMethods(schema, validators, args) {
|
|
|
579
585
|
},
|
|
580
586
|
getMany: async (args2, ctx) => {
|
|
581
587
|
args2 = args2 || {};
|
|
582
|
-
const result = await driverInstance.getMany(args2);
|
|
588
|
+
const result = await driverInstance.getMany(args2, ctx);
|
|
583
589
|
if (args2.include)
|
|
584
590
|
await handleInclude(schema, key, args2.include, result.nodes);
|
|
585
591
|
return result;
|
|
586
592
|
},
|
|
587
593
|
getAll: async (args2, ctx) => {
|
|
588
594
|
args2 = args2 || {};
|
|
589
|
-
const result = await driverInstance.getAll(args2);
|
|
595
|
+
const result = await driverInstance.getAll(args2, ctx);
|
|
590
596
|
if (args2.include)
|
|
591
597
|
await handleInclude(schema, key, args2.include, result);
|
|
592
598
|
return result;
|
package/drivers/azureCosmos.cjs
CHANGED
|
@@ -144,7 +144,11 @@ const operatorHandlers = {
|
|
|
144
144
|
namePrefix,
|
|
145
145
|
whereVal
|
|
146
146
|
} = whereArgs;
|
|
147
|
-
const
|
|
147
|
+
const newCtx = {
|
|
148
|
+
...ctx,
|
|
149
|
+
entity: ctx.schema[ctx.entity].fields[ctx.field].type
|
|
150
|
+
};
|
|
151
|
+
const subClause = getCosmosQueryWhere(newCtx, parameters, whereVal, `${namePrefix}${name}.`);
|
|
148
152
|
if (subClause) {
|
|
149
153
|
if (simpleSubclauseRegex.test(subClause)) {
|
|
150
154
|
const parts = subClause.split(" ");
|
|
@@ -162,7 +166,11 @@ const operatorHandlers = {
|
|
|
162
166
|
namePrefix,
|
|
163
167
|
whereVal
|
|
164
168
|
} = whereArgs;
|
|
165
|
-
const
|
|
169
|
+
const newCtx = {
|
|
170
|
+
...ctx,
|
|
171
|
+
entity: ctx.schema[ctx.entity].fields[ctx.field].type
|
|
172
|
+
};
|
|
173
|
+
const subClause = getCosmosQueryWhere(newCtx, parameters, whereVal, `${namePrefix}${name}.`);
|
|
166
174
|
if (subClause) return `not exists (select ${name} from ${name} in ${namePrefix}${name} where ${subClause})`;
|
|
167
175
|
return `array_length(${namePrefix}${name}) = 0`;
|
|
168
176
|
},
|
|
@@ -295,8 +303,12 @@ const operatorHandlers = {
|
|
|
295
303
|
paramNamePrefix,
|
|
296
304
|
whereVal
|
|
297
305
|
} = whereArgs;
|
|
306
|
+
const fieldType = ctx.schema[ctx.entity].fields[ctx.field];
|
|
298
307
|
const pn = `${paramNamePrefix}${paramName}`;
|
|
299
308
|
parameters[pn] = whereVal;
|
|
309
|
+
if (fieldType.isArray) {
|
|
310
|
+
return `array_contains(${namePrefix}${name}, @${pn})`;
|
|
311
|
+
}
|
|
300
312
|
return `contains(${namePrefix}${name}, @${pn})`;
|
|
301
313
|
},
|
|
302
314
|
icontains: (ctx, parameters, whereArgs) => {
|
|
@@ -381,10 +393,13 @@ function getCosmosQueryWhere(ctx, parameters, where, namePrefix = "r.", paramNam
|
|
|
381
393
|
name = `["${name}"]`;
|
|
382
394
|
namePrefix = namePrefix.slice(0, -1);
|
|
383
395
|
}
|
|
384
|
-
const paramName =
|
|
396
|
+
const paramName = key;
|
|
385
397
|
const whereVal = where[key];
|
|
386
398
|
if (whereVal == null) continue;
|
|
387
|
-
const f = getCosmosQueryWhereInner(
|
|
399
|
+
const f = getCosmosQueryWhereInner({
|
|
400
|
+
...ctx,
|
|
401
|
+
field: nameFromWhere
|
|
402
|
+
}, parameters, {
|
|
388
403
|
operator,
|
|
389
404
|
whereVal,
|
|
390
405
|
name,
|
package/drivers/azureCosmos.mjs
CHANGED
|
@@ -92,7 +92,8 @@ function getCosmosQuery(schema, entity, args) {
|
|
|
92
92
|
const operatorHandlers = {
|
|
93
93
|
some: (ctx, parameters, whereArgs) => {
|
|
94
94
|
const { name, namePrefix, whereVal } = whereArgs;
|
|
95
|
-
const
|
|
95
|
+
const newCtx = { ...ctx, entity: ctx.schema[ctx.entity].fields[ctx.field].type };
|
|
96
|
+
const subClause = getCosmosQueryWhere(newCtx, parameters, whereVal, `${namePrefix}${name}.`);
|
|
96
97
|
if (subClause) {
|
|
97
98
|
if (simpleSubclauseRegex.test(subClause)) {
|
|
98
99
|
const parts = subClause.split(" ");
|
|
@@ -106,7 +107,8 @@ const operatorHandlers = {
|
|
|
106
107
|
},
|
|
107
108
|
none: (ctx, parameters, whereArgs) => {
|
|
108
109
|
const { name, namePrefix, whereVal } = whereArgs;
|
|
109
|
-
const
|
|
110
|
+
const newCtx = { ...ctx, entity: ctx.schema[ctx.entity].fields[ctx.field].type };
|
|
111
|
+
const subClause = getCosmosQueryWhere(newCtx, parameters, whereVal, `${namePrefix}${name}.`);
|
|
110
112
|
if (subClause)
|
|
111
113
|
return `not exists (select ${name} from ${name} in ${namePrefix}${name} where ${subClause})`;
|
|
112
114
|
return `array_length(${namePrefix}${name}) = 0`;
|
|
@@ -189,8 +191,12 @@ const operatorHandlers = {
|
|
|
189
191
|
},
|
|
190
192
|
contains: (ctx, parameters, whereArgs) => {
|
|
191
193
|
const { name, namePrefix, paramName, paramNamePrefix, whereVal } = whereArgs;
|
|
194
|
+
const fieldType = ctx.schema[ctx.entity].fields[ctx.field];
|
|
192
195
|
const pn = `${paramNamePrefix}${paramName}`;
|
|
193
196
|
parameters[pn] = whereVal;
|
|
197
|
+
if (fieldType.isArray) {
|
|
198
|
+
return `array_contains(${namePrefix}${name}, @${pn})`;
|
|
199
|
+
}
|
|
194
200
|
return `contains(${namePrefix}${name}, @${pn})`;
|
|
195
201
|
},
|
|
196
202
|
icontains: (ctx, parameters, whereArgs) => {
|
|
@@ -239,11 +245,11 @@ function getCosmosQueryWhere(ctx, parameters, where, namePrefix = "r.", paramNam
|
|
|
239
245
|
name = `["${name}"]`;
|
|
240
246
|
namePrefix = namePrefix.slice(0, -1);
|
|
241
247
|
}
|
|
242
|
-
const paramName =
|
|
248
|
+
const paramName = key;
|
|
243
249
|
const whereVal = where[key];
|
|
244
250
|
if (whereVal == null)
|
|
245
251
|
continue;
|
|
246
|
-
const f = getCosmosQueryWhereInner(ctx, parameters, {
|
|
252
|
+
const f = getCosmosQueryWhereInner({ ...ctx, field: nameFromWhere }, parameters, {
|
|
247
253
|
operator,
|
|
248
254
|
whereVal,
|
|
249
255
|
name,
|