convex-ents 0.10.0 → 0.11.0
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/deletion.d.ts +1 -1
- package/dist/functions.d.ts +1 -1
- package/dist/functions.js +18 -491
- package/dist/functions.js.map +1 -1
- package/dist/{index-olos0Rx-.d.ts → index-kwzjMMHy.d.ts} +6 -375
- package/dist/index.d.ts +1 -1
- package/dist/index.js +15 -657
- package/dist/index.js.map +1 -1
- package/dist/writer.d.ts +2 -2
- package/dist/writer.js +8 -11
- package/dist/writer.js.map +1 -1
- package/package.json +1 -1
- package/dist/actions.d.ts +0 -6
- package/dist/actions.js +0 -662
- package/dist/actions.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -25,8 +25,6 @@ __export(src_exports, {
|
|
|
25
25
|
defineEntFromTable: () => defineEntFromTable,
|
|
26
26
|
defineEntSchema: () => defineEntSchema,
|
|
27
27
|
defineEntsFromTables: () => defineEntsFromTables,
|
|
28
|
-
entsActionReadFactory: () => entsActionReadFactory,
|
|
29
|
-
entsActionWriteFactory: () => entsActionWriteFactory,
|
|
30
28
|
entsTableFactory: () => entsTableFactory,
|
|
31
29
|
getEntDefinitions: () => getEntDefinitions,
|
|
32
30
|
scheduledDeleteFactory: () => scheduledDeleteFactory
|
|
@@ -406,636 +404,13 @@ function getEntDefinitions(schema) {
|
|
|
406
404
|
);
|
|
407
405
|
}
|
|
408
406
|
|
|
409
|
-
// src/actions.ts
|
|
410
|
-
var import_server2 = require("convex/server");
|
|
411
|
-
|
|
412
407
|
// src/shared.ts
|
|
413
408
|
function getEdgeDefinitions(entDefinitions, table) {
|
|
414
409
|
return entDefinitions[table].edges;
|
|
415
410
|
}
|
|
416
411
|
|
|
417
|
-
// src/actions.ts
|
|
418
|
-
async function entsActionReadFactory(ctx, args_) {
|
|
419
|
-
const { read } = args_;
|
|
420
|
-
let result;
|
|
421
|
-
for (const call of read) {
|
|
422
|
-
result = addMethodCall(ctx, call, result);
|
|
423
|
-
}
|
|
424
|
-
return await result;
|
|
425
|
-
}
|
|
426
|
-
async function entsActionWriteFactory(ctx, args_) {
|
|
427
|
-
const { write } = args_;
|
|
428
|
-
let result;
|
|
429
|
-
for (const call of write) {
|
|
430
|
-
result = addMethodCall(ctx, call, result);
|
|
431
|
-
}
|
|
432
|
-
return await result;
|
|
433
|
-
}
|
|
434
|
-
function addMethodCall(ctx, call, result) {
|
|
435
|
-
if ("table" in call) {
|
|
436
|
-
const [table, indexName, indexRange] = call.table;
|
|
437
|
-
return ctx.table(table, indexName, deserializeIndexRange(indexRange));
|
|
438
|
-
} else if ("search" in call) {
|
|
439
|
-
const [indexName, filters] = call.search;
|
|
440
|
-
return result.search(indexName, deserializeSearchFilter(filters));
|
|
441
|
-
} else if ("normalizeId" in call) {
|
|
442
|
-
return result.normalizeId(call.normalizeId);
|
|
443
|
-
} else if ("normalizeIdX" in call) {
|
|
444
|
-
return result.normalizeIdX(call.normalizeIdX);
|
|
445
|
-
} else if ("get" in call) {
|
|
446
|
-
return result.get(...call.get);
|
|
447
|
-
} else if ("getX" in call) {
|
|
448
|
-
return result.getX(...call.getX);
|
|
449
|
-
} else if ("getMany" in call) {
|
|
450
|
-
return result.getMany(...call.getMany);
|
|
451
|
-
} else if ("getManyX" in call) {
|
|
452
|
-
return result.getManyX(...call.getManyX);
|
|
453
|
-
} else if ("filter" in call) {
|
|
454
|
-
return result.filter(deserializeFilterPredicate(call.filter));
|
|
455
|
-
} else if ("order" in call) {
|
|
456
|
-
return result.order(...call.order);
|
|
457
|
-
} else if ("take" in call) {
|
|
458
|
-
return result.take(call.take);
|
|
459
|
-
} else if ("paginate" in call) {
|
|
460
|
-
return result.paginate(call.paginate);
|
|
461
|
-
} else if ("first" in call) {
|
|
462
|
-
return result.first();
|
|
463
|
-
} else if ("firstX" in call) {
|
|
464
|
-
return result.firstX();
|
|
465
|
-
} else if ("unique" in call) {
|
|
466
|
-
return result.unique();
|
|
467
|
-
} else if ("uniqueX" in call) {
|
|
468
|
-
return result.uniqueX();
|
|
469
|
-
} else if ("edge" in call) {
|
|
470
|
-
return result.edge(call.edge);
|
|
471
|
-
} else if ("edgeX" in call) {
|
|
472
|
-
return result.edge(call.edgeX);
|
|
473
|
-
} else if ("has" in call) {
|
|
474
|
-
return result.has(call.has);
|
|
475
|
-
} else if ("insert" in call) {
|
|
476
|
-
return result.insert(call.insert);
|
|
477
|
-
} else if ("insertMany" in call) {
|
|
478
|
-
return result.insertMany(call.insertMany);
|
|
479
|
-
} else if ("patch" in call) {
|
|
480
|
-
return result.patch(call.patch);
|
|
481
|
-
} else if ("replace" in call) {
|
|
482
|
-
return result.replace(call.replace);
|
|
483
|
-
} else if ("delete" in call) {
|
|
484
|
-
return result.delete();
|
|
485
|
-
} else {
|
|
486
|
-
call;
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
var PromiseQueryActionOrNullImpl = class _PromiseQueryActionOrNullImpl extends Promise {
|
|
490
|
-
constructor(ctx, entDefinitions, table, read) {
|
|
491
|
-
super(() => {
|
|
492
|
-
});
|
|
493
|
-
this.ctx = ctx;
|
|
494
|
-
this.entDefinitions = entDefinitions;
|
|
495
|
-
this.table = table;
|
|
496
|
-
this.read = read;
|
|
497
|
-
}
|
|
498
|
-
filter(predicate) {
|
|
499
|
-
return new _PromiseQueryActionOrNullImpl(
|
|
500
|
-
this.ctx,
|
|
501
|
-
this.entDefinitions,
|
|
502
|
-
this.table,
|
|
503
|
-
this.read.concat({ filter: serializeFilterPredicate(predicate) })
|
|
504
|
-
);
|
|
505
|
-
}
|
|
506
|
-
order(order, indexName) {
|
|
507
|
-
return new _PromiseQueryActionOrNullImpl(
|
|
508
|
-
this.ctx,
|
|
509
|
-
this.entDefinitions,
|
|
510
|
-
this.table,
|
|
511
|
-
this.read.concat({
|
|
512
|
-
order: [
|
|
513
|
-
order,
|
|
514
|
-
...indexName === void 0 ? [] : [indexName]
|
|
515
|
-
]
|
|
516
|
-
})
|
|
517
|
-
);
|
|
518
|
-
}
|
|
519
|
-
paginate(paginationOpts) {
|
|
520
|
-
return new PromisePaginationResultActionOrNullImpl(
|
|
521
|
-
this.ctx,
|
|
522
|
-
this.entDefinitions,
|
|
523
|
-
this.table,
|
|
524
|
-
this.read.concat({ paginate: paginationOpts })
|
|
525
|
-
);
|
|
526
|
-
}
|
|
527
|
-
async take(n) {
|
|
528
|
-
return await runRead(this.ctx, this.read.concat({ take: n }));
|
|
529
|
-
}
|
|
530
|
-
first() {
|
|
531
|
-
return new PromiseEntActionImpl(
|
|
532
|
-
this.ctx,
|
|
533
|
-
this.entDefinitions,
|
|
534
|
-
this.table,
|
|
535
|
-
this.read.concat({ first: true })
|
|
536
|
-
);
|
|
537
|
-
}
|
|
538
|
-
firstX() {
|
|
539
|
-
return new PromiseEntActionImpl(
|
|
540
|
-
this.ctx,
|
|
541
|
-
this.entDefinitions,
|
|
542
|
-
this.table,
|
|
543
|
-
this.read.concat({ firstX: true })
|
|
544
|
-
);
|
|
545
|
-
}
|
|
546
|
-
unique() {
|
|
547
|
-
return new PromiseEntActionImpl(
|
|
548
|
-
this.ctx,
|
|
549
|
-
this.entDefinitions,
|
|
550
|
-
this.table,
|
|
551
|
-
this.read.concat({ unique: true })
|
|
552
|
-
);
|
|
553
|
-
}
|
|
554
|
-
uniqueX() {
|
|
555
|
-
return new PromiseEntActionImpl(
|
|
556
|
-
this.ctx,
|
|
557
|
-
this.entDefinitions,
|
|
558
|
-
this.table,
|
|
559
|
-
this.read.concat({ uniqueX: true })
|
|
560
|
-
);
|
|
561
|
-
}
|
|
562
|
-
then(onfulfilled, onrejected) {
|
|
563
|
-
const docs = runRead(this.ctx, this.read);
|
|
564
|
-
return docs.then(onfulfilled, onrejected);
|
|
565
|
-
}
|
|
566
|
-
};
|
|
567
|
-
var PromiseEdgeActionOrNullImpl = class extends PromiseQueryActionOrNullImpl {
|
|
568
|
-
async has(targetId) {
|
|
569
|
-
return runRead(this.ctx, this.read.concat({ has: targetId }));
|
|
570
|
-
}
|
|
571
|
-
};
|
|
572
|
-
var PromiseTableActionImpl = class extends PromiseQueryActionOrNullImpl {
|
|
573
|
-
constructor(ctx, entDefinitions, table) {
|
|
574
|
-
super(ctx, entDefinitions, table, [{ table: [table] }]);
|
|
575
|
-
}
|
|
576
|
-
get(...args) {
|
|
577
|
-
return new PromiseEntActionImpl(
|
|
578
|
-
this.ctx,
|
|
579
|
-
this.entDefinitions,
|
|
580
|
-
this.table,
|
|
581
|
-
this.read.concat({ get: args })
|
|
582
|
-
);
|
|
583
|
-
}
|
|
584
|
-
getX(...args) {
|
|
585
|
-
return new PromiseEntActionImpl(
|
|
586
|
-
this.ctx,
|
|
587
|
-
this.entDefinitions,
|
|
588
|
-
this.table,
|
|
589
|
-
this.read.concat({ getX: args })
|
|
590
|
-
);
|
|
591
|
-
}
|
|
592
|
-
async getMany(...args) {
|
|
593
|
-
return await runRead(this.ctx, this.read.concat({ getMany: args }));
|
|
594
|
-
}
|
|
595
|
-
async getManyX(...args) {
|
|
596
|
-
return await runRead(this.ctx, this.read.concat({ getManyX: args }));
|
|
597
|
-
}
|
|
598
|
-
async normalizeId(id) {
|
|
599
|
-
return await runRead(this.ctx, this.read.concat({ normalizeId: id }));
|
|
600
|
-
}
|
|
601
|
-
async normalizeIdX(id) {
|
|
602
|
-
return await runRead(this.ctx, this.read.concat({ normalizeIdX: id }));
|
|
603
|
-
}
|
|
604
|
-
withIndex(indexName, indexRange) {
|
|
605
|
-
return new PromiseQueryActionOrNullImpl(
|
|
606
|
-
this.ctx,
|
|
607
|
-
this.entDefinitions,
|
|
608
|
-
this.table,
|
|
609
|
-
[
|
|
610
|
-
{
|
|
611
|
-
table: [
|
|
612
|
-
this.table,
|
|
613
|
-
indexName,
|
|
614
|
-
serializeIndexRange(indexRange)
|
|
615
|
-
]
|
|
616
|
-
}
|
|
617
|
-
]
|
|
618
|
-
);
|
|
619
|
-
}
|
|
620
|
-
search(indexName, searchFilter) {
|
|
621
|
-
return new PromiseQueryActionOrNullImpl(
|
|
622
|
-
this.ctx,
|
|
623
|
-
this.entDefinitions,
|
|
624
|
-
this.table,
|
|
625
|
-
this.read.concat({
|
|
626
|
-
search: [indexName, serializeSearchFilter(searchFilter)]
|
|
627
|
-
})
|
|
628
|
-
);
|
|
629
|
-
}
|
|
630
|
-
insert(value) {
|
|
631
|
-
return new PromiseEntIdActionImpl(
|
|
632
|
-
this.ctx,
|
|
633
|
-
this.entDefinitions,
|
|
634
|
-
this.table,
|
|
635
|
-
this.read.concat({ insert: value })
|
|
636
|
-
);
|
|
637
|
-
}
|
|
638
|
-
// TODO: fluent API
|
|
639
|
-
async insertMany(values) {
|
|
640
|
-
return await runWrite(
|
|
641
|
-
this.ctx,
|
|
642
|
-
this.read.concat({ insertMany: values })
|
|
643
|
-
);
|
|
644
|
-
}
|
|
645
|
-
};
|
|
646
|
-
var PromisePaginationResultActionOrNullImpl = class extends Promise {
|
|
647
|
-
constructor(ctx, entDefinitions, table, read) {
|
|
648
|
-
super(() => {
|
|
649
|
-
});
|
|
650
|
-
this.ctx = ctx;
|
|
651
|
-
this.entDefinitions = entDefinitions;
|
|
652
|
-
this.table = table;
|
|
653
|
-
this.read = read;
|
|
654
|
-
}
|
|
655
|
-
then(onfulfilled, onrejected) {
|
|
656
|
-
return runRead(this.ctx, this.read).then(onfulfilled, onrejected);
|
|
657
|
-
}
|
|
658
|
-
};
|
|
659
|
-
var PromiseEntActionImpl = class _PromiseEntActionImpl extends Promise {
|
|
660
|
-
constructor(ctx, entDefinitions, table, read) {
|
|
661
|
-
super(() => {
|
|
662
|
-
});
|
|
663
|
-
this.ctx = ctx;
|
|
664
|
-
this.entDefinitions = entDefinitions;
|
|
665
|
-
this.table = table;
|
|
666
|
-
this.read = read;
|
|
667
|
-
}
|
|
668
|
-
then(onfulfilled, onrejected) {
|
|
669
|
-
return runRead(this.ctx, this.read).then(onfulfilled, onrejected);
|
|
670
|
-
}
|
|
671
|
-
edge(edge) {
|
|
672
|
-
return this.edgeImpl(edge);
|
|
673
|
-
}
|
|
674
|
-
edgeX(edge) {
|
|
675
|
-
return this.edgeImpl(edge, true);
|
|
676
|
-
}
|
|
677
|
-
edgeImpl(edge, throwIfNull = false) {
|
|
678
|
-
const edgeDefinition = getEdgeDefinitions(this.entDefinitions, this.table)[edge];
|
|
679
|
-
const read = throwIfNull ? { edgeX: edge } : { edge };
|
|
680
|
-
if (edgeDefinition.cardinality === "multiple") {
|
|
681
|
-
if (edgeDefinition.type === "ref") {
|
|
682
|
-
return new PromiseEdgeActionOrNullImpl(
|
|
683
|
-
this.ctx,
|
|
684
|
-
this.entDefinitions,
|
|
685
|
-
edgeDefinition.to,
|
|
686
|
-
this.read.concat(read)
|
|
687
|
-
);
|
|
688
|
-
}
|
|
689
|
-
return new PromiseQueryActionOrNullImpl(
|
|
690
|
-
this.ctx,
|
|
691
|
-
this.entDefinitions,
|
|
692
|
-
edgeDefinition.to,
|
|
693
|
-
this.read.concat(read)
|
|
694
|
-
);
|
|
695
|
-
}
|
|
696
|
-
return new _PromiseEntActionImpl(
|
|
697
|
-
this.ctx,
|
|
698
|
-
this.entDefinitions,
|
|
699
|
-
edgeDefinition.to,
|
|
700
|
-
this.read.concat(read)
|
|
701
|
-
);
|
|
702
|
-
}
|
|
703
|
-
patch(value) {
|
|
704
|
-
return new PromiseEntIdActionImpl(
|
|
705
|
-
this.ctx,
|
|
706
|
-
this.entDefinitions,
|
|
707
|
-
this.table,
|
|
708
|
-
this.read.concat({ patch: value })
|
|
709
|
-
);
|
|
710
|
-
}
|
|
711
|
-
replace(value) {
|
|
712
|
-
return new PromiseEntIdActionImpl(
|
|
713
|
-
this.ctx,
|
|
714
|
-
this.entDefinitions,
|
|
715
|
-
this.table,
|
|
716
|
-
this.read.concat({ replace: value })
|
|
717
|
-
);
|
|
718
|
-
}
|
|
719
|
-
async delete() {
|
|
720
|
-
return await runWrite(
|
|
721
|
-
this.ctx,
|
|
722
|
-
this.read.concat({ delete: true })
|
|
723
|
-
);
|
|
724
|
-
}
|
|
725
|
-
};
|
|
726
|
-
var PromiseEntIdActionImpl = class extends Promise {
|
|
727
|
-
constructor(ctx, entDefinitions, table, write) {
|
|
728
|
-
super(() => {
|
|
729
|
-
});
|
|
730
|
-
this.ctx = ctx;
|
|
731
|
-
this.entDefinitions = entDefinitions;
|
|
732
|
-
this.table = table;
|
|
733
|
-
this.write = write;
|
|
734
|
-
}
|
|
735
|
-
async get() {
|
|
736
|
-
return await runWrite(this.ctx, this.write.concat({ get: [] }));
|
|
737
|
-
}
|
|
738
|
-
then(onfulfilled, onrejected) {
|
|
739
|
-
return runWrite(this.ctx, this.write).then(onfulfilled, onrejected);
|
|
740
|
-
}
|
|
741
|
-
};
|
|
742
|
-
async function runRead(ctx, read) {
|
|
743
|
-
const readRef = ctx?.actionRead ?? (0, import_server2.makeFunctionReference)("functions:read");
|
|
744
|
-
return await ctx.runQuery(readRef, { read });
|
|
745
|
-
}
|
|
746
|
-
async function runWrite(ctx, write) {
|
|
747
|
-
const writeRef = ctx?.actionRead ?? (0, import_server2.makeFunctionReference)("functions:write");
|
|
748
|
-
return await ctx.runMutation(writeRef, { write });
|
|
749
|
-
}
|
|
750
|
-
var IndexRangeBuilderImpl = class _IndexRangeBuilderImpl {
|
|
751
|
-
constructor(rangeExpressions) {
|
|
752
|
-
this.rangeExpressions = rangeExpressions;
|
|
753
|
-
}
|
|
754
|
-
static new() {
|
|
755
|
-
return new _IndexRangeBuilderImpl([]);
|
|
756
|
-
}
|
|
757
|
-
eq(fieldName, value) {
|
|
758
|
-
return new _IndexRangeBuilderImpl(
|
|
759
|
-
this.rangeExpressions.concat({
|
|
760
|
-
type: "Eq",
|
|
761
|
-
fieldPath: fieldName,
|
|
762
|
-
value: value === void 0 ? "$undefined" : value
|
|
763
|
-
})
|
|
764
|
-
);
|
|
765
|
-
}
|
|
766
|
-
gt(fieldName, value) {
|
|
767
|
-
return new _IndexRangeBuilderImpl(
|
|
768
|
-
this.rangeExpressions.concat({
|
|
769
|
-
type: "Gt",
|
|
770
|
-
fieldPath: fieldName,
|
|
771
|
-
value
|
|
772
|
-
})
|
|
773
|
-
);
|
|
774
|
-
}
|
|
775
|
-
gte(fieldName, value) {
|
|
776
|
-
return new _IndexRangeBuilderImpl(
|
|
777
|
-
this.rangeExpressions.concat({
|
|
778
|
-
type: "Gte",
|
|
779
|
-
fieldPath: fieldName,
|
|
780
|
-
value
|
|
781
|
-
})
|
|
782
|
-
);
|
|
783
|
-
}
|
|
784
|
-
lt(fieldName, value) {
|
|
785
|
-
return new _IndexRangeBuilderImpl(
|
|
786
|
-
this.rangeExpressions.concat({
|
|
787
|
-
type: "Lt",
|
|
788
|
-
fieldPath: fieldName,
|
|
789
|
-
value
|
|
790
|
-
})
|
|
791
|
-
);
|
|
792
|
-
}
|
|
793
|
-
lte(fieldName, value) {
|
|
794
|
-
return new _IndexRangeBuilderImpl(
|
|
795
|
-
this.rangeExpressions.concat({
|
|
796
|
-
type: "Lte",
|
|
797
|
-
fieldPath: fieldName,
|
|
798
|
-
value
|
|
799
|
-
})
|
|
800
|
-
);
|
|
801
|
-
}
|
|
802
|
-
};
|
|
803
|
-
function serializeIndexRange(indexRange) {
|
|
804
|
-
if (indexRange === void 0) {
|
|
805
|
-
return void 0;
|
|
806
|
-
}
|
|
807
|
-
return (indexRange?.(
|
|
808
|
-
IndexRangeBuilderImpl.new()
|
|
809
|
-
)).rangeExpressions;
|
|
810
|
-
}
|
|
811
|
-
function deserializeIndexRange(rangeExpressions) {
|
|
812
|
-
if (rangeExpressions === void 0) {
|
|
813
|
-
return void 0;
|
|
814
|
-
}
|
|
815
|
-
return (q) => {
|
|
816
|
-
for (const range of rangeExpressions) {
|
|
817
|
-
switch (range.type) {
|
|
818
|
-
case "Eq":
|
|
819
|
-
q = q.eq(
|
|
820
|
-
range.fieldPath,
|
|
821
|
-
range.value === "$undefined" ? void 0 : range.value
|
|
822
|
-
);
|
|
823
|
-
break;
|
|
824
|
-
case "Gt":
|
|
825
|
-
q = q.gt(range.fieldPath, range.value);
|
|
826
|
-
break;
|
|
827
|
-
case "Gte":
|
|
828
|
-
q = q.gte(range.fieldPath, range.value);
|
|
829
|
-
break;
|
|
830
|
-
case "Lt":
|
|
831
|
-
q = q.lt(range.fieldPath, range.value);
|
|
832
|
-
break;
|
|
833
|
-
case "Lte":
|
|
834
|
-
q = q.lte(range.fieldPath, range.value);
|
|
835
|
-
break;
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
return q;
|
|
839
|
-
};
|
|
840
|
-
}
|
|
841
|
-
function serializeFilterPredicate(predicate) {
|
|
842
|
-
return serializeExpression(predicate(filterBuilderImpl));
|
|
843
|
-
}
|
|
844
|
-
function deserializeFilterPredicate(predicate) {
|
|
845
|
-
return (q) => deserializeFilterExpression(q, predicate);
|
|
846
|
-
}
|
|
847
|
-
var binaryOps = [
|
|
848
|
-
"eq",
|
|
849
|
-
"neq",
|
|
850
|
-
"lt",
|
|
851
|
-
"lte",
|
|
852
|
-
"gt",
|
|
853
|
-
"gte",
|
|
854
|
-
"add",
|
|
855
|
-
"sub",
|
|
856
|
-
"mul",
|
|
857
|
-
"div",
|
|
858
|
-
"mod",
|
|
859
|
-
"and",
|
|
860
|
-
"or"
|
|
861
|
-
];
|
|
862
|
-
function deserializeFilterExpression(q, expression) {
|
|
863
|
-
if ("field" in expression) {
|
|
864
|
-
const fieldPath = expression["field"];
|
|
865
|
-
return q.field(fieldPath);
|
|
866
|
-
}
|
|
867
|
-
if ("literal" in expression) {
|
|
868
|
-
const literal = expression["literal"];
|
|
869
|
-
return literal === "$undefined" ? void 0 : literal;
|
|
870
|
-
}
|
|
871
|
-
if ("neg" in expression) {
|
|
872
|
-
return q.neg(deserializeFilterExpression(q, expression["neg"]));
|
|
873
|
-
}
|
|
874
|
-
if ("not" in expression) {
|
|
875
|
-
return q.not(deserializeFilterExpression(q, expression["not"]));
|
|
876
|
-
}
|
|
877
|
-
for (const op of binaryOps) {
|
|
878
|
-
if (op in expression) {
|
|
879
|
-
const [l, r] = expression[op];
|
|
880
|
-
return q[op](
|
|
881
|
-
deserializeFilterExpression(q, l),
|
|
882
|
-
deserializeFilterExpression(q, r)
|
|
883
|
-
);
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
throw new Error(
|
|
887
|
-
"Expected a valid filter expression, got " + JSON.stringify(expression)
|
|
888
|
-
);
|
|
889
|
-
}
|
|
890
|
-
var filterBuilderImpl = {
|
|
891
|
-
// Comparisons /////////////////////////////////////////////////////////////
|
|
892
|
-
eq(l, r) {
|
|
893
|
-
return new FilterExpression({
|
|
894
|
-
eq: [serializeExpression(l), serializeExpression(r)]
|
|
895
|
-
});
|
|
896
|
-
},
|
|
897
|
-
neq(l, r) {
|
|
898
|
-
return new FilterExpression({
|
|
899
|
-
neq: [serializeExpression(l), serializeExpression(r)]
|
|
900
|
-
});
|
|
901
|
-
},
|
|
902
|
-
lt(l, r) {
|
|
903
|
-
return new FilterExpression({
|
|
904
|
-
lt: [serializeExpression(l), serializeExpression(r)]
|
|
905
|
-
});
|
|
906
|
-
},
|
|
907
|
-
lte(l, r) {
|
|
908
|
-
return new FilterExpression({
|
|
909
|
-
lte: [serializeExpression(l), serializeExpression(r)]
|
|
910
|
-
});
|
|
911
|
-
},
|
|
912
|
-
gt(l, r) {
|
|
913
|
-
return new FilterExpression({
|
|
914
|
-
gt: [serializeExpression(l), serializeExpression(r)]
|
|
915
|
-
});
|
|
916
|
-
},
|
|
917
|
-
gte(l, r) {
|
|
918
|
-
return new FilterExpression({
|
|
919
|
-
gte: [serializeExpression(l), serializeExpression(r)]
|
|
920
|
-
});
|
|
921
|
-
},
|
|
922
|
-
// Arithmetic //////////////////////////////////////////////////////////////
|
|
923
|
-
add(l, r) {
|
|
924
|
-
return new FilterExpression({
|
|
925
|
-
add: [serializeExpression(l), serializeExpression(r)]
|
|
926
|
-
});
|
|
927
|
-
},
|
|
928
|
-
sub(l, r) {
|
|
929
|
-
return new FilterExpression({
|
|
930
|
-
sub: [serializeExpression(l), serializeExpression(r)]
|
|
931
|
-
});
|
|
932
|
-
},
|
|
933
|
-
mul(l, r) {
|
|
934
|
-
return new FilterExpression({
|
|
935
|
-
mul: [serializeExpression(l), serializeExpression(r)]
|
|
936
|
-
});
|
|
937
|
-
},
|
|
938
|
-
div(l, r) {
|
|
939
|
-
return new FilterExpression({
|
|
940
|
-
div: [serializeExpression(l), serializeExpression(r)]
|
|
941
|
-
});
|
|
942
|
-
},
|
|
943
|
-
mod(l, r) {
|
|
944
|
-
return new FilterExpression({
|
|
945
|
-
mod: [serializeExpression(l), serializeExpression(r)]
|
|
946
|
-
});
|
|
947
|
-
},
|
|
948
|
-
neg(x) {
|
|
949
|
-
return new FilterExpression({ neg: serializeExpression(x) });
|
|
950
|
-
},
|
|
951
|
-
// Logic ///////////////////////////////////////////////////////////////////
|
|
952
|
-
and(...exprs) {
|
|
953
|
-
return new FilterExpression({ and: exprs.map(serializeExpression) });
|
|
954
|
-
},
|
|
955
|
-
or(...exprs) {
|
|
956
|
-
return new FilterExpression({ or: exprs.map(serializeExpression) });
|
|
957
|
-
},
|
|
958
|
-
not(x) {
|
|
959
|
-
return new FilterExpression({ not: serializeExpression(x) });
|
|
960
|
-
},
|
|
961
|
-
// Other ///////////////////////////////////////////////////////////////////
|
|
962
|
-
field(fieldPath) {
|
|
963
|
-
return new FilterExpression({ field: fieldPath });
|
|
964
|
-
}
|
|
965
|
-
};
|
|
966
|
-
function serializeExpression(expr) {
|
|
967
|
-
if (expr instanceof FilterExpression) {
|
|
968
|
-
return expr.serialize();
|
|
969
|
-
} else {
|
|
970
|
-
return {
|
|
971
|
-
literal: expr === void 0 ? "$undefined" : expr
|
|
972
|
-
};
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
|
-
var FilterExpression = class {
|
|
976
|
-
inner;
|
|
977
|
-
constructor(inner) {
|
|
978
|
-
this.inner = inner;
|
|
979
|
-
}
|
|
980
|
-
serialize() {
|
|
981
|
-
return this.inner;
|
|
982
|
-
}
|
|
983
|
-
};
|
|
984
|
-
function serializeSearchFilter(searchFilter) {
|
|
985
|
-
return searchFilter(
|
|
986
|
-
SearchFilterBuilderImpl.new()
|
|
987
|
-
).export();
|
|
988
|
-
}
|
|
989
|
-
function deserializeSearchFilter(filters) {
|
|
990
|
-
return (q) => {
|
|
991
|
-
for (const filter of filters) {
|
|
992
|
-
switch (filter.type) {
|
|
993
|
-
case "Search":
|
|
994
|
-
q = q.search(filter.fieldPath, filter.value);
|
|
995
|
-
break;
|
|
996
|
-
case "Eq":
|
|
997
|
-
q = q.eq(
|
|
998
|
-
filter.fieldPath,
|
|
999
|
-
filter.value === "$undefined" ? void 0 : filter.value
|
|
1000
|
-
);
|
|
1001
|
-
break;
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
return q;
|
|
1005
|
-
};
|
|
1006
|
-
}
|
|
1007
|
-
var SearchFilterBuilderImpl = class _SearchFilterBuilderImpl {
|
|
1008
|
-
constructor(filters) {
|
|
1009
|
-
this.filters = filters;
|
|
1010
|
-
}
|
|
1011
|
-
static new() {
|
|
1012
|
-
return new _SearchFilterBuilderImpl([]);
|
|
1013
|
-
}
|
|
1014
|
-
search(fieldName, query) {
|
|
1015
|
-
return new _SearchFilterBuilderImpl(
|
|
1016
|
-
this.filters.concat({
|
|
1017
|
-
type: "Search",
|
|
1018
|
-
fieldPath: fieldName,
|
|
1019
|
-
value: query
|
|
1020
|
-
})
|
|
1021
|
-
);
|
|
1022
|
-
}
|
|
1023
|
-
eq(fieldName, value) {
|
|
1024
|
-
return new _SearchFilterBuilderImpl(
|
|
1025
|
-
this.filters.concat({
|
|
1026
|
-
type: "Eq",
|
|
1027
|
-
fieldPath: fieldName,
|
|
1028
|
-
value: value === void 0 ? "$undefiend" : value
|
|
1029
|
-
})
|
|
1030
|
-
);
|
|
1031
|
-
}
|
|
1032
|
-
export() {
|
|
1033
|
-
return this.filters;
|
|
1034
|
-
}
|
|
1035
|
-
};
|
|
1036
|
-
|
|
1037
412
|
// src/writer.ts
|
|
1038
|
-
var
|
|
413
|
+
var import_server2 = require("convex/server");
|
|
1039
414
|
var WriterImplBase = class _WriterImplBase {
|
|
1040
415
|
constructor(ctx, entDefinitions, table) {
|
|
1041
416
|
this.ctx = ctx;
|
|
@@ -1092,7 +467,7 @@ var WriterImplBase = class _WriterImplBase {
|
|
|
1092
467
|
}
|
|
1093
468
|
await this.writeEdges(id, edges, isDeletingSoftly);
|
|
1094
469
|
if (deletionConfig !== void 0 && deletionConfig.type === "scheduled") {
|
|
1095
|
-
const fnRef = this.ctx.scheduledDelete ?? (0,
|
|
470
|
+
const fnRef = this.ctx.scheduledDelete ?? (0, import_server2.makeFunctionReference)(
|
|
1096
471
|
"functions:scheduledDelete"
|
|
1097
472
|
);
|
|
1098
473
|
await this.ctx.scheduler.runAfter(deletionConfig.delayMs ?? 0, fnRef, {
|
|
@@ -2178,36 +1553,21 @@ function entsTableFactory(ctx, entDefinitions, options) {
|
|
|
2178
1553
|
if (typeof table2 !== "string") {
|
|
2179
1554
|
throw new Error(`Expected table name, got \`${table2}\``);
|
|
2180
1555
|
}
|
|
2181
|
-
if (
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
return new
|
|
1556
|
+
if (indexName !== void 0) {
|
|
1557
|
+
return new PromiseTableImpl(
|
|
1558
|
+
enrichedCtx,
|
|
1559
|
+
entDefinitions,
|
|
1560
|
+
table2
|
|
1561
|
+
).withIndex(indexName, indexRange);
|
|
1562
|
+
}
|
|
1563
|
+
if (ctx.db.insert !== void 0) {
|
|
1564
|
+
return new PromiseTableWriterImpl(
|
|
2190
1565
|
enrichedCtx,
|
|
2191
1566
|
entDefinitions,
|
|
2192
1567
|
table2
|
|
2193
1568
|
);
|
|
2194
|
-
} else {
|
|
2195
|
-
if (indexName !== void 0) {
|
|
2196
|
-
return new PromiseTableImpl(
|
|
2197
|
-
enrichedCtx,
|
|
2198
|
-
entDefinitions,
|
|
2199
|
-
table2
|
|
2200
|
-
).withIndex(indexName, indexRange);
|
|
2201
|
-
}
|
|
2202
|
-
if (ctx.db.insert !== void 0) {
|
|
2203
|
-
return new PromiseTableWriterImpl(
|
|
2204
|
-
enrichedCtx,
|
|
2205
|
-
entDefinitions,
|
|
2206
|
-
table2
|
|
2207
|
-
);
|
|
2208
|
-
}
|
|
2209
|
-
return new PromiseTableImpl(enrichedCtx, entDefinitions, table2);
|
|
2210
1569
|
}
|
|
1570
|
+
return new PromiseTableImpl(enrichedCtx, entDefinitions, table2);
|
|
2211
1571
|
};
|
|
2212
1572
|
table.system = table;
|
|
2213
1573
|
return table;
|
|
@@ -2514,14 +1874,14 @@ function isSystemTable(table) {
|
|
|
2514
1874
|
}
|
|
2515
1875
|
|
|
2516
1876
|
// src/deletion.ts
|
|
2517
|
-
var
|
|
1877
|
+
var import_server3 = require("convex/server");
|
|
2518
1878
|
var import_values2 = require("convex/values");
|
|
2519
1879
|
var vApproach = import_values2.v.union(import_values2.v.literal("cascade"), import_values2.v.literal("paginate"));
|
|
2520
1880
|
function scheduledDeleteFactory(entDefinitions, options) {
|
|
2521
|
-
const selfRef = options?.scheduledDelete ?? (0,
|
|
1881
|
+
const selfRef = options?.scheduledDelete ?? (0, import_server3.makeFunctionReference)(
|
|
2522
1882
|
"functions:scheduledDelete"
|
|
2523
1883
|
);
|
|
2524
|
-
return (0,
|
|
1884
|
+
return (0, import_server3.internalMutationGeneric)({
|
|
2525
1885
|
args: {
|
|
2526
1886
|
origin: import_values2.v.object({
|
|
2527
1887
|
id: import_values2.v.string(),
|
|
@@ -2762,8 +2122,6 @@ async function paginate(ctx, {
|
|
|
2762
2122
|
defineEntFromTable,
|
|
2763
2123
|
defineEntSchema,
|
|
2764
2124
|
defineEntsFromTables,
|
|
2765
|
-
entsActionReadFactory,
|
|
2766
|
-
entsActionWriteFactory,
|
|
2767
2125
|
entsTableFactory,
|
|
2768
2126
|
getEntDefinitions,
|
|
2769
2127
|
scheduledDeleteFactory
|