@ronin/compiler 0.7.1 → 0.8.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/index.d.ts +206 -35
- package/dist/index.js +205 -107
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
import { z } from 'zod';
|
2
2
|
|
3
|
+
declare const ExpressionSchema: z.ZodObject<{
|
4
|
+
__RONIN_EXPRESSION: z.ZodString;
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
6
|
+
__RONIN_EXPRESSION: string;
|
7
|
+
}, {
|
8
|
+
__RONIN_EXPRESSION: string;
|
9
|
+
}>;
|
3
10
|
declare const WithInstructionSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, z.ZodEffects<z.ZodObject<{
|
4
11
|
being: z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, "many">]>>;
|
5
12
|
notBeing: z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, "many">]>>;
|
@@ -1244,7 +1251,7 @@ declare const GetInstructionsSchema: z.ZodObject<Omit<{
|
|
1244
1251
|
for?: string[] | Record<string, string> | undefined;
|
1245
1252
|
}>;
|
1246
1253
|
declare const QuerySchema: z.ZodObject<{
|
1247
|
-
|
1254
|
+
get: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodObject<Omit<{
|
1248
1255
|
with: z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, z.ZodEffects<z.ZodObject<{
|
1249
1256
|
being: z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, "many">]>>;
|
1250
1257
|
notBeing: z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, "many">]>>;
|
@@ -2096,7 +2103,7 @@ declare const QuerySchema: z.ZodObject<{
|
|
2096
2103
|
limitedTo?: number | undefined;
|
2097
2104
|
for?: string[] | Record<string, string> | undefined;
|
2098
2105
|
}>>>>;
|
2099
|
-
|
2106
|
+
set: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<z.objectUtil.extendShape<{
|
2100
2107
|
with: z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, z.ZodEffects<z.ZodObject<{
|
2101
2108
|
being: z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, "many">]>>;
|
2102
2109
|
notBeing: z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, "many">]>>;
|
@@ -2915,10 +2922,11 @@ declare const QuerySchema: z.ZodObject<{
|
|
2915
2922
|
after: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNull]>>;
|
2916
2923
|
limitedTo: z.ZodOptional<z.ZodNumber>;
|
2917
2924
|
for: z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
2918
|
-
},
|
2925
|
+
}, {
|
2919
2926
|
to: z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>>, Record<string, any>, Record<string, any>>;
|
2920
2927
|
}>, "strip", z.ZodTypeAny, {
|
2921
2928
|
to: Record<string, any>;
|
2929
|
+
with?: Record<string, any> | Record<string, any>[] | undefined;
|
2922
2930
|
including?: Record<string, any> | undefined;
|
2923
2931
|
selecting?: string[] | undefined;
|
2924
2932
|
orderedBy?: {
|
@@ -2932,8 +2940,10 @@ declare const QuerySchema: z.ZodObject<{
|
|
2932
2940
|
before?: string | null | undefined;
|
2933
2941
|
after?: string | null | undefined;
|
2934
2942
|
limitedTo?: number | undefined;
|
2943
|
+
for?: string[] | Record<string, string> | undefined;
|
2935
2944
|
}, {
|
2936
2945
|
to: Record<string, any>;
|
2946
|
+
with?: Record<string, any> | Record<string, any>[] | undefined;
|
2937
2947
|
including?: Record<string, any> | undefined;
|
2938
2948
|
selecting?: string[] | undefined;
|
2939
2949
|
orderedBy?: {
|
@@ -2947,8 +2957,9 @@ declare const QuerySchema: z.ZodObject<{
|
|
2947
2957
|
before?: string | null | undefined;
|
2948
2958
|
after?: string | null | undefined;
|
2949
2959
|
limitedTo?: number | undefined;
|
2960
|
+
for?: string[] | Record<string, string> | undefined;
|
2950
2961
|
}>>>;
|
2951
|
-
|
2962
|
+
add: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<z.objectUtil.extendShape<Omit<{
|
2952
2963
|
with: z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, z.ZodEffects<z.ZodObject<{
|
2953
2964
|
being: z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, "many">]>>;
|
2954
2965
|
notBeing: z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, "many">]>>;
|
@@ -3767,8 +3778,10 @@ declare const QuerySchema: z.ZodObject<{
|
|
3767
3778
|
after: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNull]>>;
|
3768
3779
|
limitedTo: z.ZodOptional<z.ZodNumber>;
|
3769
3780
|
for: z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
3770
|
-
}, "
|
3771
|
-
|
3781
|
+
}, "with" | "for">, {
|
3782
|
+
to: z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>>, Record<string, any>, Record<string, any>>;
|
3783
|
+
}>, "strip", z.ZodTypeAny, {
|
3784
|
+
to: Record<string, any>;
|
3772
3785
|
including?: Record<string, any> | undefined;
|
3773
3786
|
selecting?: string[] | undefined;
|
3774
3787
|
orderedBy?: {
|
@@ -3782,9 +3795,8 @@ declare const QuerySchema: z.ZodObject<{
|
|
3782
3795
|
before?: string | null | undefined;
|
3783
3796
|
after?: string | null | undefined;
|
3784
3797
|
limitedTo?: number | undefined;
|
3785
|
-
for?: string[] | Record<string, string> | undefined;
|
3786
3798
|
}, {
|
3787
|
-
|
3799
|
+
to: Record<string, any>;
|
3788
3800
|
including?: Record<string, any> | undefined;
|
3789
3801
|
selecting?: string[] | undefined;
|
3790
3802
|
orderedBy?: {
|
@@ -3798,9 +3810,8 @@ declare const QuerySchema: z.ZodObject<{
|
|
3798
3810
|
before?: string | null | undefined;
|
3799
3811
|
after?: string | null | undefined;
|
3800
3812
|
limitedTo?: number | undefined;
|
3801
|
-
for?: string[] | Record<string, string> | undefined;
|
3802
3813
|
}>>>;
|
3803
|
-
|
3814
|
+
delete: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<Omit<{
|
3804
3815
|
with: z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, z.ZodEffects<z.ZodObject<{
|
3805
3816
|
being: z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, "many">]>>;
|
3806
3817
|
notBeing: z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, "many">]>>;
|
@@ -4651,8 +4662,8 @@ declare const QuerySchema: z.ZodObject<{
|
|
4651
4662
|
after?: string | null | undefined;
|
4652
4663
|
limitedTo?: number | undefined;
|
4653
4664
|
for?: string[] | Record<string, string> | undefined;
|
4654
|
-
}
|
4655
|
-
|
4665
|
+
}>>>;
|
4666
|
+
count: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodObject<Omit<{
|
4656
4667
|
with: z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, z.ZodEffects<z.ZodObject<{
|
4657
4668
|
being: z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, "many">]>>;
|
4658
4669
|
notBeing: z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>, "many">]>>;
|
@@ -5471,10 +5482,7 @@ declare const QuerySchema: z.ZodObject<{
|
|
5471
5482
|
after: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNull]>>;
|
5472
5483
|
limitedTo: z.ZodOptional<z.ZodNumber>;
|
5473
5484
|
for: z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
5474
|
-
}, {
|
5475
|
-
to: z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodAny]>>, Record<string, any>, Record<string, any>>;
|
5476
|
-
}>, "strip", z.ZodTypeAny, {
|
5477
|
-
to: Record<string, any>;
|
5485
|
+
}, "to">, "strip", z.ZodTypeAny, {
|
5478
5486
|
with?: Record<string, any> | Record<string, any>[] | undefined;
|
5479
5487
|
including?: Record<string, any> | undefined;
|
5480
5488
|
selecting?: string[] | undefined;
|
@@ -5491,7 +5499,6 @@ declare const QuerySchema: z.ZodObject<{
|
|
5491
5499
|
limitedTo?: number | undefined;
|
5492
5500
|
for?: string[] | Record<string, string> | undefined;
|
5493
5501
|
}, {
|
5494
|
-
to: Record<string, any>;
|
5495
5502
|
with?: Record<string, any> | Record<string, any>[] | undefined;
|
5496
5503
|
including?: Record<string, any> | undefined;
|
5497
5504
|
selecting?: string[] | undefined;
|
@@ -5507,7 +5514,81 @@ declare const QuerySchema: z.ZodObject<{
|
|
5507
5514
|
after?: string | null | undefined;
|
5508
5515
|
limitedTo?: number | undefined;
|
5509
5516
|
for?: string[] | Record<string, string> | undefined;
|
5510
|
-
}
|
5517
|
+
}>>>>;
|
5518
|
+
create: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
5519
|
+
model: z.ZodString;
|
5520
|
+
to: z.ZodRecord<z.ZodString, z.ZodAny>;
|
5521
|
+
}, "strip", z.ZodTypeAny, {
|
5522
|
+
to: Record<string, any>;
|
5523
|
+
model: string;
|
5524
|
+
}, {
|
5525
|
+
to: Record<string, any>;
|
5526
|
+
model: string;
|
5527
|
+
}>, z.ZodObject<{
|
5528
|
+
model: z.ZodRecord<z.ZodString, z.ZodAny>;
|
5529
|
+
}, "strip", z.ZodTypeAny, {
|
5530
|
+
model: Record<string, any>;
|
5531
|
+
}, {
|
5532
|
+
model: Record<string, any>;
|
5533
|
+
}>]>>;
|
5534
|
+
alter: z.ZodOptional<z.ZodIntersection<z.ZodObject<{
|
5535
|
+
model: z.ZodString;
|
5536
|
+
}, "strip", z.ZodTypeAny, {
|
5537
|
+
model: string;
|
5538
|
+
}, {
|
5539
|
+
model: string;
|
5540
|
+
}>, z.ZodUnion<[z.ZodObject<{
|
5541
|
+
to: z.ZodRecord<z.ZodString, z.ZodAny>;
|
5542
|
+
}, "strip", z.ZodTypeAny, {
|
5543
|
+
to: Record<string, any>;
|
5544
|
+
}, {
|
5545
|
+
to: Record<string, any>;
|
5546
|
+
}>, z.ZodObject<{
|
5547
|
+
create: z.ZodUnion<[z.ZodIntersection<z.ZodRecord<z.ZodEnum<["field", "index", "trigger", "preset"]>, z.ZodString>, z.ZodObject<{
|
5548
|
+
to: z.ZodRecord<z.ZodString, z.ZodAny>;
|
5549
|
+
}, "strip", z.ZodTypeAny, {
|
5550
|
+
to: Record<string, any>;
|
5551
|
+
}, {
|
5552
|
+
to: Record<string, any>;
|
5553
|
+
}>>, z.ZodRecord<z.ZodEnum<["field", "index", "trigger", "preset"]>, z.ZodRecord<z.ZodString, z.ZodAny>>]>;
|
5554
|
+
}, "strip", z.ZodTypeAny, {
|
5555
|
+
create: (Partial<Record<"field" | "index" | "trigger" | "preset", string>> & {
|
5556
|
+
to: Record<string, any>;
|
5557
|
+
}) | Partial<Record<"field" | "index" | "trigger" | "preset", Record<string, any>>>;
|
5558
|
+
}, {
|
5559
|
+
create: (Partial<Record<"field" | "index" | "trigger" | "preset", string>> & {
|
5560
|
+
to: Record<string, any>;
|
5561
|
+
}) | Partial<Record<"field" | "index" | "trigger" | "preset", Record<string, any>>>;
|
5562
|
+
}>, z.ZodObject<{
|
5563
|
+
alter: z.ZodIntersection<z.ZodRecord<z.ZodEnum<["field", "index", "trigger", "preset"]>, z.ZodString>, z.ZodObject<{
|
5564
|
+
to: z.ZodRecord<z.ZodString, z.ZodAny>;
|
5565
|
+
}, "strip", z.ZodTypeAny, {
|
5566
|
+
to: Record<string, any>;
|
5567
|
+
}, {
|
5568
|
+
to: Record<string, any>;
|
5569
|
+
}>>;
|
5570
|
+
}, "strip", z.ZodTypeAny, {
|
5571
|
+
alter: Partial<Record<"field" | "index" | "trigger" | "preset", string>> & {
|
5572
|
+
to: Record<string, any>;
|
5573
|
+
};
|
5574
|
+
}, {
|
5575
|
+
alter: Partial<Record<"field" | "index" | "trigger" | "preset", string>> & {
|
5576
|
+
to: Record<string, any>;
|
5577
|
+
};
|
5578
|
+
}>, z.ZodObject<{
|
5579
|
+
drop: z.ZodRecord<z.ZodEnum<["field", "index", "trigger", "preset"]>, z.ZodString>;
|
5580
|
+
}, "strip", z.ZodTypeAny, {
|
5581
|
+
drop: Partial<Record<"field" | "index" | "trigger" | "preset", string>>;
|
5582
|
+
}, {
|
5583
|
+
drop: Partial<Record<"field" | "index" | "trigger" | "preset", string>>;
|
5584
|
+
}>]>>>;
|
5585
|
+
drop: z.ZodOptional<z.ZodObject<{
|
5586
|
+
model: z.ZodString;
|
5587
|
+
}, "strip", z.ZodTypeAny, {
|
5588
|
+
model: string;
|
5589
|
+
}, {
|
5590
|
+
model: string;
|
5591
|
+
}>>;
|
5511
5592
|
}, "strip", z.ZodTypeAny, {
|
5512
5593
|
get?: Record<string, {
|
5513
5594
|
with?: Record<string, any> | Record<string, any>[] | undefined;
|
@@ -5544,8 +5625,8 @@ declare const QuerySchema: z.ZodObject<{
|
|
5544
5625
|
limitedTo?: number | undefined;
|
5545
5626
|
for?: string[] | Record<string, string> | undefined;
|
5546
5627
|
}> | undefined;
|
5547
|
-
|
5548
|
-
|
5628
|
+
add?: Record<string, {
|
5629
|
+
to: Record<string, any>;
|
5549
5630
|
including?: Record<string, any> | undefined;
|
5550
5631
|
selecting?: string[] | undefined;
|
5551
5632
|
orderedBy?: {
|
@@ -5559,10 +5640,9 @@ declare const QuerySchema: z.ZodObject<{
|
|
5559
5640
|
before?: string | null | undefined;
|
5560
5641
|
after?: string | null | undefined;
|
5561
5642
|
limitedTo?: number | undefined;
|
5562
|
-
for?: string[] | Record<string, string> | undefined;
|
5563
5643
|
}> | undefined;
|
5564
|
-
|
5565
|
-
|
5644
|
+
delete?: Record<string, {
|
5645
|
+
with?: Record<string, any> | Record<string, any>[] | undefined;
|
5566
5646
|
including?: Record<string, any> | undefined;
|
5567
5647
|
selecting?: string[] | undefined;
|
5568
5648
|
orderedBy?: {
|
@@ -5576,6 +5656,7 @@ declare const QuerySchema: z.ZodObject<{
|
|
5576
5656
|
before?: string | null | undefined;
|
5577
5657
|
after?: string | null | undefined;
|
5578
5658
|
limitedTo?: number | undefined;
|
5659
|
+
for?: string[] | Record<string, string> | undefined;
|
5579
5660
|
}> | undefined;
|
5580
5661
|
count?: Record<string, {
|
5581
5662
|
with?: Record<string, any> | Record<string, any>[] | undefined;
|
@@ -5594,6 +5675,30 @@ declare const QuerySchema: z.ZodObject<{
|
|
5594
5675
|
limitedTo?: number | undefined;
|
5595
5676
|
for?: string[] | Record<string, string> | undefined;
|
5596
5677
|
} | null> | undefined;
|
5678
|
+
create?: {
|
5679
|
+
to: Record<string, any>;
|
5680
|
+
model: string;
|
5681
|
+
} | {
|
5682
|
+
model: Record<string, any>;
|
5683
|
+
} | undefined;
|
5684
|
+
alter?: ({
|
5685
|
+
model: string;
|
5686
|
+
} & ({
|
5687
|
+
to: Record<string, any>;
|
5688
|
+
} | {
|
5689
|
+
create: (Partial<Record<"field" | "index" | "trigger" | "preset", string>> & {
|
5690
|
+
to: Record<string, any>;
|
5691
|
+
}) | Partial<Record<"field" | "index" | "trigger" | "preset", Record<string, any>>>;
|
5692
|
+
} | {
|
5693
|
+
alter: Partial<Record<"field" | "index" | "trigger" | "preset", string>> & {
|
5694
|
+
to: Record<string, any>;
|
5695
|
+
};
|
5696
|
+
} | {
|
5697
|
+
drop: Partial<Record<"field" | "index" | "trigger" | "preset", string>>;
|
5698
|
+
})) | undefined;
|
5699
|
+
drop?: {
|
5700
|
+
model: string;
|
5701
|
+
} | undefined;
|
5597
5702
|
}, {
|
5598
5703
|
get?: Record<string, {
|
5599
5704
|
with?: Record<string, any> | Record<string, any>[] | undefined;
|
@@ -5630,8 +5735,8 @@ declare const QuerySchema: z.ZodObject<{
|
|
5630
5735
|
limitedTo?: number | undefined;
|
5631
5736
|
for?: string[] | Record<string, string> | undefined;
|
5632
5737
|
}> | undefined;
|
5633
|
-
|
5634
|
-
|
5738
|
+
add?: Record<string, {
|
5739
|
+
to: Record<string, any>;
|
5635
5740
|
including?: Record<string, any> | undefined;
|
5636
5741
|
selecting?: string[] | undefined;
|
5637
5742
|
orderedBy?: {
|
@@ -5645,10 +5750,9 @@ declare const QuerySchema: z.ZodObject<{
|
|
5645
5750
|
before?: string | null | undefined;
|
5646
5751
|
after?: string | null | undefined;
|
5647
5752
|
limitedTo?: number | undefined;
|
5648
|
-
for?: string[] | Record<string, string> | undefined;
|
5649
5753
|
}> | undefined;
|
5650
|
-
|
5651
|
-
|
5754
|
+
delete?: Record<string, {
|
5755
|
+
with?: Record<string, any> | Record<string, any>[] | undefined;
|
5652
5756
|
including?: Record<string, any> | undefined;
|
5653
5757
|
selecting?: string[] | undefined;
|
5654
5758
|
orderedBy?: {
|
@@ -5662,6 +5766,7 @@ declare const QuerySchema: z.ZodObject<{
|
|
5662
5766
|
before?: string | null | undefined;
|
5663
5767
|
after?: string | null | undefined;
|
5664
5768
|
limitedTo?: number | undefined;
|
5769
|
+
for?: string[] | Record<string, string> | undefined;
|
5665
5770
|
}> | undefined;
|
5666
5771
|
count?: Record<string, {
|
5667
5772
|
with?: Record<string, any> | Record<string, any>[] | undefined;
|
@@ -5680,10 +5785,35 @@ declare const QuerySchema: z.ZodObject<{
|
|
5680
5785
|
limitedTo?: number | undefined;
|
5681
5786
|
for?: string[] | Record<string, string> | undefined;
|
5682
5787
|
} | null> | undefined;
|
5788
|
+
create?: {
|
5789
|
+
to: Record<string, any>;
|
5790
|
+
model: string;
|
5791
|
+
} | {
|
5792
|
+
model: Record<string, any>;
|
5793
|
+
} | undefined;
|
5794
|
+
alter?: ({
|
5795
|
+
model: string;
|
5796
|
+
} & ({
|
5797
|
+
to: Record<string, any>;
|
5798
|
+
} | {
|
5799
|
+
create: (Partial<Record<"field" | "index" | "trigger" | "preset", string>> & {
|
5800
|
+
to: Record<string, any>;
|
5801
|
+
}) | Partial<Record<"field" | "index" | "trigger" | "preset", Record<string, any>>>;
|
5802
|
+
} | {
|
5803
|
+
alter: Partial<Record<"field" | "index" | "trigger" | "preset", string>> & {
|
5804
|
+
to: Record<string, any>;
|
5805
|
+
};
|
5806
|
+
} | {
|
5807
|
+
drop: Partial<Record<"field" | "index" | "trigger" | "preset", string>>;
|
5808
|
+
})) | undefined;
|
5809
|
+
drop?: {
|
5810
|
+
model: string;
|
5811
|
+
} | undefined;
|
5683
5812
|
}>;
|
5684
5813
|
|
5685
5814
|
type GetInstructions = z.infer<typeof GetInstructionsSchema>;
|
5686
5815
|
type WithInstruction = z.infer<typeof WithInstructionSchema>;
|
5816
|
+
type Expression = z.infer<typeof ExpressionSchema>;
|
5687
5817
|
type Query = z.infer<typeof QuerySchema>;
|
5688
5818
|
interface Statement {
|
5689
5819
|
statement: string;
|
@@ -5691,21 +5821,58 @@ interface Statement {
|
|
5691
5821
|
returning?: boolean;
|
5692
5822
|
}
|
5693
5823
|
|
5824
|
+
type ModelFieldCollation = 'BINARY' | 'NOCASE' | 'RTRIM';
|
5694
5825
|
type ModelFieldBasics = {
|
5826
|
+
/** The label that should be used when displaying the field on the RONIN dashboard. */
|
5695
5827
|
name?: string;
|
5828
|
+
/** Allows for addressing the field programmatically. */
|
5696
5829
|
slug: string;
|
5830
|
+
/** How the field should be displayed visually on the RONIN dashboard. */
|
5697
5831
|
displayAs?: string;
|
5832
|
+
/**
|
5833
|
+
* If set, only one record of the same model will be allowed to exist with a given
|
5834
|
+
* value for the field.
|
5835
|
+
*/
|
5698
5836
|
unique?: boolean;
|
5837
|
+
/**
|
5838
|
+
* Whether a value must be provided for the field. If this attribute is set and no
|
5839
|
+
* value is provided, an error will be thrown.
|
5840
|
+
*/
|
5699
5841
|
required?: boolean;
|
5842
|
+
/**
|
5843
|
+
* The value that should be inserted into the field in the case that no value was
|
5844
|
+
* explicitly provided for it when a record is created.
|
5845
|
+
*/
|
5700
5846
|
defaultValue?: unknown;
|
5847
|
+
/**
|
5848
|
+
* An expression that should be evaluated to form the value of the field. The
|
5849
|
+
* expression can either be VIRTUAL (evaluated whenever a record is read) or STORED
|
5850
|
+
* (evaluated whenever a record is created or updated).
|
5851
|
+
*/
|
5852
|
+
computedAs?: {
|
5853
|
+
kind: 'VIRTUAL' | 'STORED';
|
5854
|
+
value: Expression;
|
5855
|
+
};
|
5856
|
+
/** An expression that gets evaluated every time a value is provided for the field. */
|
5857
|
+
check?: Expression;
|
5858
|
+
/**
|
5859
|
+
* If the field is of type `string`, setting this attribute defines the collation
|
5860
|
+
* sequence to use for the field value.
|
5861
|
+
*/
|
5862
|
+
collation?: ModelFieldCollation;
|
5863
|
+
/**
|
5864
|
+
* If the field is of type `number`, setting this attribute will automatically increment
|
5865
|
+
* the value of the field with every new record that gets inserted.
|
5866
|
+
*/
|
5867
|
+
increment?: boolean;
|
5701
5868
|
};
|
5702
5869
|
type ModelFieldNormal = ModelFieldBasics & {
|
5703
5870
|
type: 'string' | 'number' | 'boolean' | 'date' | 'json' | 'group';
|
5704
5871
|
};
|
5705
5872
|
type ModelFieldReferenceAction = 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'SET DEFAULT' | 'NO ACTION';
|
5706
5873
|
type ModelFieldReference = ModelFieldBasics & {
|
5707
|
-
type: '
|
5708
|
-
target:
|
5874
|
+
type: 'link';
|
5875
|
+
target: string;
|
5709
5876
|
kind?: 'one' | 'many';
|
5710
5877
|
actions?: {
|
5711
5878
|
onDelete?: ModelFieldReferenceAction;
|
@@ -5715,7 +5882,7 @@ type ModelFieldReference = ModelFieldBasics & {
|
|
5715
5882
|
type ModelField = ModelFieldNormal | ModelFieldReference;
|
5716
5883
|
type ModelIndexField = {
|
5717
5884
|
/** The collating sequence used for text placed inside the field. */
|
5718
|
-
collation?:
|
5885
|
+
collation?: ModelFieldCollation;
|
5719
5886
|
/** How the records in the index should be ordered. */
|
5720
5887
|
order?: 'ASC' | 'DESC';
|
5721
5888
|
} & ({
|
@@ -5730,6 +5897,10 @@ type ModelIndex = {
|
|
5730
5897
|
* The list of fields in the model for which the index should be created.
|
5731
5898
|
*/
|
5732
5899
|
fields: Array<ModelIndexField>;
|
5900
|
+
/**
|
5901
|
+
* The identifier of the index.
|
5902
|
+
*/
|
5903
|
+
slug?: string;
|
5733
5904
|
/**
|
5734
5905
|
* Whether only one record with a unique value for the provided fields will be allowed.
|
5735
5906
|
*/
|
@@ -5750,7 +5921,7 @@ type ModelTriggerField = {
|
|
5750
5921
|
type ModelTrigger = {
|
5751
5922
|
/** The type of query for which the trigger should fire. */
|
5752
5923
|
action: 'INSERT' | 'UPDATE' | 'DELETE';
|
5753
|
-
/** When the trigger should fire in the case that a
|
5924
|
+
/** When the trigger should fire in the case that a matching query is executed. */
|
5754
5925
|
when: 'BEFORE' | 'DURING' | 'AFTER';
|
5755
5926
|
/** A list of queries that should be executed when the trigger fires. */
|
5756
5927
|
effects: Array<Query>;
|
@@ -5787,11 +5958,11 @@ interface Model {
|
|
5787
5958
|
tableAlias?: string;
|
5788
5959
|
/**
|
5789
5960
|
* If the model is used to associate two models with each other (in the case of
|
5790
|
-
* many-cardinality
|
5791
|
-
* the associative model should be mounted.
|
5961
|
+
* many-cardinality link fields), this property should contain the field slug to which
|
5962
|
+
* the associative model should be mounted on the source model.
|
5792
5963
|
*/
|
5793
5964
|
associationSlug?: string;
|
5794
|
-
fields
|
5965
|
+
fields: Array<ModelField>;
|
5795
5966
|
indexes?: Array<ModelIndex>;
|
5796
5967
|
triggers?: Array<ModelTrigger>;
|
5797
5968
|
presets?: Array<ModelPreset>;
|
package/dist/index.js
CHANGED
@@ -187,14 +187,14 @@ var composeConditions = (models, model, statementParams, instructionName, value,
|
|
187
187
|
{ ...options, fieldSlug: options.fieldSlug }
|
188
188
|
);
|
189
189
|
}
|
190
|
-
if (modelField.type === "
|
190
|
+
if (modelField.type === "link" && isNested) {
|
191
191
|
const keys = Object.keys(value);
|
192
192
|
const values = Object.values(value);
|
193
193
|
let recordTarget;
|
194
194
|
if (keys.length === 1 && keys[0] === "id") {
|
195
195
|
recordTarget = values[0];
|
196
196
|
} else {
|
197
|
-
const relatedModel = getModelBySlug(models, modelField.target
|
197
|
+
const relatedModel = getModelBySlug(models, modelField.target);
|
198
198
|
const subQuery = {
|
199
199
|
get: {
|
200
200
|
[relatedModel.slug]: {
|
@@ -490,16 +490,16 @@ var SYSTEM_MODELS = [
|
|
490
490
|
{ slug: "type", type: "string", required: true },
|
491
491
|
{
|
492
492
|
slug: "model",
|
493
|
-
type: "
|
494
|
-
target:
|
493
|
+
type: "link",
|
494
|
+
target: "model",
|
495
495
|
required: true
|
496
496
|
},
|
497
497
|
{ slug: "required", type: "boolean" },
|
498
498
|
{ slug: "defaultValue", type: "string" },
|
499
499
|
{ slug: "unique", type: "boolean" },
|
500
500
|
{ slug: "autoIncrement", type: "boolean" },
|
501
|
-
// Only allowed for fields of type "
|
502
|
-
{ slug: "target", type: "
|
501
|
+
// Only allowed for fields of type "link".
|
502
|
+
{ slug: "target", type: "string" },
|
503
503
|
{ slug: "kind", type: "string" },
|
504
504
|
{ slug: "actions", type: "group" },
|
505
505
|
{ slug: "actions.onDelete", type: "string" },
|
@@ -516,8 +516,8 @@ var SYSTEM_MODELS = [
|
|
516
516
|
{ slug: "slug", type: "string", required: true },
|
517
517
|
{
|
518
518
|
slug: "model",
|
519
|
-
type: "
|
520
|
-
target:
|
519
|
+
type: "link",
|
520
|
+
target: "model",
|
521
521
|
required: true
|
522
522
|
},
|
523
523
|
{ slug: "unique", type: "boolean" },
|
@@ -535,8 +535,8 @@ var SYSTEM_MODELS = [
|
|
535
535
|
{ slug: "slug", type: "string", required: true },
|
536
536
|
{
|
537
537
|
slug: "model",
|
538
|
-
type: "
|
539
|
-
target:
|
538
|
+
type: "link",
|
539
|
+
target: "model",
|
540
540
|
required: true
|
541
541
|
},
|
542
542
|
{ slug: "when", type: "string", required: true },
|
@@ -552,8 +552,8 @@ var SYSTEM_MODELS = [
|
|
552
552
|
{ slug: "slug", type: "string", required: true },
|
553
553
|
{
|
554
554
|
slug: "model",
|
555
|
-
type: "
|
556
|
-
target:
|
555
|
+
type: "link",
|
556
|
+
target: "model",
|
557
557
|
required: true
|
558
558
|
},
|
559
559
|
{ slug: "instructions", type: "json", required: true }
|
@@ -568,8 +568,8 @@ var addSystemModels = (models) => {
|
|
568
568
|
const associativeModels = models.flatMap((model) => {
|
569
569
|
const addedModels = [];
|
570
570
|
for (const field of model.fields || []) {
|
571
|
-
if (field.type === "
|
572
|
-
const relatedModel = getModelBySlug(models, field.target
|
571
|
+
if (field.type === "link" && !field.slug.startsWith("ronin.")) {
|
572
|
+
const relatedModel = getModelBySlug(models, field.target);
|
573
573
|
let fieldSlug = relatedModel.slug;
|
574
574
|
if (field.kind === "many") {
|
575
575
|
fieldSlug = composeAssociationModelSlug(model, field);
|
@@ -580,13 +580,13 @@ var addSystemModels = (models) => {
|
|
580
580
|
fields: [
|
581
581
|
{
|
582
582
|
slug: "source",
|
583
|
-
type: "
|
584
|
-
target:
|
583
|
+
type: "link",
|
584
|
+
target: model.slug
|
585
585
|
},
|
586
586
|
{
|
587
587
|
slug: "target",
|
588
|
-
type: "
|
589
|
-
target:
|
588
|
+
type: "link",
|
589
|
+
target: relatedModel.slug
|
590
590
|
}
|
591
591
|
]
|
592
592
|
});
|
@@ -600,8 +600,8 @@ var addSystemModels = (models) => {
|
|
600
600
|
var addDefaultModelPresets = (list, model) => {
|
601
601
|
const defaultPresets = [];
|
602
602
|
for (const field of model.fields || []) {
|
603
|
-
if (field.type === "
|
604
|
-
const relatedModel = getModelBySlug(list, field.target
|
603
|
+
if (field.type === "link" && !field.slug.startsWith("ronin.")) {
|
604
|
+
const relatedModel = getModelBySlug(list, field.target);
|
605
605
|
if (field.kind === "many") continue;
|
606
606
|
defaultPresets.push({
|
607
607
|
instructions: {
|
@@ -611,7 +611,7 @@ var addDefaultModelPresets = (list, model) => {
|
|
611
611
|
get: {
|
612
612
|
[relatedModel.slug]: {
|
613
613
|
with: {
|
614
|
-
// Compare the `id` field of the related model to the
|
614
|
+
// Compare the `id` field of the related model to the link field on
|
615
615
|
// the root model (`field.slug`).
|
616
616
|
id: {
|
617
617
|
[RONIN_MODEL_SYMBOLS.EXPRESSION]: `${RONIN_MODEL_SYMBOLS.FIELD_PARENT}${field.slug}`
|
@@ -629,7 +629,7 @@ var addDefaultModelPresets = (list, model) => {
|
|
629
629
|
}
|
630
630
|
const childModels = list.map((subModel) => {
|
631
631
|
const field = subModel.fields?.find((field2) => {
|
632
|
-
return field2.type === "
|
632
|
+
return field2.type === "link" && field2.target === model.slug;
|
633
633
|
});
|
634
634
|
if (!field) return null;
|
635
635
|
return { model: subModel, field };
|
@@ -665,12 +665,12 @@ var addDefaultModelPresets = (list, model) => {
|
|
665
665
|
return model;
|
666
666
|
};
|
667
667
|
var mappedInstructions = {
|
668
|
-
|
668
|
+
add: "to",
|
669
669
|
set: "with",
|
670
|
-
|
670
|
+
delete: "with"
|
671
671
|
};
|
672
672
|
var typesInSQLite = {
|
673
|
-
|
673
|
+
link: "TEXT",
|
674
674
|
string: "TEXT",
|
675
675
|
date: "DATETIME",
|
676
676
|
blob: "TEXT",
|
@@ -678,7 +678,7 @@ var typesInSQLite = {
|
|
678
678
|
number: "INTEGER",
|
679
679
|
json: "TEXT"
|
680
680
|
};
|
681
|
-
var getFieldStatement = (field) => {
|
681
|
+
var getFieldStatement = (models, model, field) => {
|
682
682
|
if (field.type === "group") return null;
|
683
683
|
let statement = `"${field.slug}" ${typesInSQLite[field.type]}`;
|
684
684
|
if (field.slug === "id") statement += " PRIMARY KEY";
|
@@ -686,9 +686,20 @@ var getFieldStatement = (field) => {
|
|
686
686
|
if (field.required === true) statement += " NOT NULL";
|
687
687
|
if (typeof field.defaultValue !== "undefined")
|
688
688
|
statement += ` DEFAULT ${field.defaultValue}`;
|
689
|
-
if (field.
|
689
|
+
if (field.collation) statement += ` COLLATE ${field.collation}`;
|
690
|
+
if (field.increment === true) statement += " AUTOINCREMENT";
|
691
|
+
if (typeof field.check !== "undefined") {
|
692
|
+
const symbol = getSymbol(field.check);
|
693
|
+
statement += ` CHECK (${parseFieldExpression(model, "to", symbol?.value)})`;
|
694
|
+
}
|
695
|
+
if (typeof field.computedAs !== "undefined") {
|
696
|
+
const { kind, value } = field.computedAs;
|
697
|
+
const symbol = getSymbol(value);
|
698
|
+
statement += ` GENERATED ALWAYS AS (${parseFieldExpression(model, "to", symbol?.value)}) ${kind}`;
|
699
|
+
}
|
700
|
+
if (field.type === "link") {
|
690
701
|
const actions = field.actions || {};
|
691
|
-
const targetTable =
|
702
|
+
const targetTable = getModelBySlug(models, field.target).table;
|
692
703
|
statement += ` REFERENCES ${targetTable}("id")`;
|
693
704
|
for (const trigger in actions) {
|
694
705
|
const triggerName = trigger.toUpperCase().slice(2);
|
@@ -698,18 +709,17 @@ var getFieldStatement = (field) => {
|
|
698
709
|
}
|
699
710
|
return statement;
|
700
711
|
};
|
701
|
-
var addModelQueries = (models,
|
702
|
-
const { queryType, queryModel, queryInstructions
|
703
|
-
|
704
|
-
if (!
|
705
|
-
if (!SYSTEM_MODEL_SLUGS.includes(queryModel)) return queryInstructions;
|
712
|
+
var addModelQueries = (models, dependencyStatements, queryDetails) => {
|
713
|
+
const { queryType, queryModel, queryInstructions } = queryDetails;
|
714
|
+
if (!["add", "set", "delete"].includes(queryType)) return;
|
715
|
+
if (!SYSTEM_MODEL_SLUGS.includes(queryModel)) return;
|
706
716
|
const instructionName = mappedInstructions[queryType];
|
707
717
|
const instructionList = queryInstructions[instructionName];
|
708
718
|
const kind = getModelBySlug(SYSTEM_MODELS, queryModel).pluralSlug;
|
709
719
|
let tableAction = "ALTER";
|
710
720
|
let queryTypeReadable = null;
|
711
721
|
switch (queryType) {
|
712
|
-
case "
|
722
|
+
case "add": {
|
713
723
|
if (kind === "models" || kind === "indexes" || kind === "triggers") {
|
714
724
|
tableAction = "CREATE";
|
715
725
|
}
|
@@ -721,7 +731,7 @@ var addModelQueries = (models, queryDetails, dependencyStatements) => {
|
|
721
731
|
queryTypeReadable = "updating";
|
722
732
|
break;
|
723
733
|
}
|
724
|
-
case "
|
734
|
+
case "delete": {
|
725
735
|
if (kind === "models" || kind === "indexes" || kind === "triggers") {
|
726
736
|
tableAction = "DROP";
|
727
737
|
}
|
@@ -730,25 +740,11 @@ var addModelQueries = (models, queryDetails, dependencyStatements) => {
|
|
730
740
|
}
|
731
741
|
}
|
732
742
|
const slug = instructionList?.slug?.being || instructionList?.slug;
|
733
|
-
if (!slug) {
|
734
|
-
throw new RoninError({
|
735
|
-
message: `When ${queryTypeReadable} ${kind}, a \`slug\` field must be provided in the \`${instructionName}\` instruction.`,
|
736
|
-
code: "MISSING_FIELD",
|
737
|
-
fields: ["slug"]
|
738
|
-
});
|
739
|
-
}
|
740
743
|
const modelInstruction = instructionList?.model;
|
741
744
|
const modelSlug = modelInstruction?.slug?.being || modelInstruction?.slug;
|
742
|
-
if (kind !== "models" && !modelSlug) {
|
743
|
-
throw new RoninError({
|
744
|
-
message: `When ${queryTypeReadable} ${kind}, a \`model.slug\` field must be provided in the \`${instructionName}\` instruction.`,
|
745
|
-
code: "MISSING_FIELD",
|
746
|
-
fields: ["model.slug"]
|
747
|
-
});
|
748
|
-
}
|
749
745
|
const usableSlug = kind === "models" ? slug : modelSlug;
|
750
746
|
const tableName = convertToSnakeCase(pluralize(usableSlug));
|
751
|
-
const targetModel = kind === "models" && queryType === "
|
747
|
+
const targetModel = kind === "models" && queryType === "add" ? null : getModelBySlug(models, usableSlug);
|
752
748
|
if (kind === "indexes") {
|
753
749
|
const indexName = convertToSnakeCase(slug);
|
754
750
|
const unique = instructionList?.unique;
|
@@ -756,7 +752,7 @@ var addModelQueries = (models, queryDetails, dependencyStatements) => {
|
|
756
752
|
const fields = instructionList?.fields;
|
757
753
|
const params = [];
|
758
754
|
let statement2 = `${tableAction}${unique ? " UNIQUE" : ""} INDEX "${indexName}"`;
|
759
|
-
if (queryType === "
|
755
|
+
if (queryType === "add") {
|
760
756
|
const model = targetModel;
|
761
757
|
const columns = fields.map((field) => {
|
762
758
|
let fieldSelector = "";
|
@@ -781,13 +777,13 @@ var addModelQueries = (models, queryDetails, dependencyStatements) => {
|
|
781
777
|
}
|
782
778
|
}
|
783
779
|
dependencyStatements.push({ statement: statement2, params });
|
784
|
-
return
|
780
|
+
return;
|
785
781
|
}
|
786
782
|
if (kind === "triggers") {
|
787
783
|
const triggerName = convertToSnakeCase(slug);
|
788
784
|
const params = [];
|
789
785
|
let statement2 = `${tableAction} TRIGGER "${triggerName}"`;
|
790
|
-
if (queryType === "
|
786
|
+
if (queryType === "add") {
|
791
787
|
const currentModel = targetModel;
|
792
788
|
const { when, action } = instructionList;
|
793
789
|
const statementParts = [`${when} ${action}`];
|
@@ -833,26 +829,19 @@ var addModelQueries = (models, queryDetails, dependencyStatements) => {
|
|
833
829
|
statement2 += ` ${statementParts.join(" ")}`;
|
834
830
|
}
|
835
831
|
dependencyStatements.push({ statement: statement2, params });
|
836
|
-
return
|
832
|
+
return;
|
837
833
|
}
|
838
834
|
const statement = `${tableAction} TABLE "${tableName}"`;
|
839
835
|
if (kind === "models") {
|
840
|
-
if (queryType === "
|
841
|
-
const
|
842
|
-
|
843
|
-
|
844
|
-
);
|
845
|
-
const modelWithPresets = addDefaultModelPresets(models, modelWithFields);
|
846
|
-
queryInstructions.to = modelWithPresets;
|
847
|
-
}
|
848
|
-
if (queryType === "create") {
|
849
|
-
const { fields } = queryInstructions.to;
|
850
|
-
const columns = fields.map(getFieldStatement).filter(Boolean);
|
836
|
+
if (queryType === "add") {
|
837
|
+
const newModel = queryInstructions.to;
|
838
|
+
const { fields } = newModel;
|
839
|
+
const columns = fields.map((field) => getFieldStatement(models, newModel, field)).filter(Boolean);
|
851
840
|
dependencyStatements.push({
|
852
841
|
statement: `${statement} (${columns.join(", ")})`,
|
853
842
|
params: []
|
854
843
|
});
|
855
|
-
models.push(
|
844
|
+
models.push(newModel);
|
856
845
|
} else if (queryType === "set") {
|
857
846
|
const newSlug = queryInstructions.to?.pluralSlug;
|
858
847
|
if (newSlug) {
|
@@ -863,23 +852,17 @@ var addModelQueries = (models, queryDetails, dependencyStatements) => {
|
|
863
852
|
});
|
864
853
|
}
|
865
854
|
Object.assign(targetModel, queryInstructions.to);
|
866
|
-
} else if (queryType === "
|
855
|
+
} else if (queryType === "delete") {
|
867
856
|
models.splice(models.indexOf(targetModel), 1);
|
868
857
|
dependencyStatements.push({ statement, params: [] });
|
869
858
|
}
|
870
|
-
return
|
859
|
+
return;
|
871
860
|
}
|
872
861
|
if (kind === "fields") {
|
873
|
-
if (queryType === "
|
874
|
-
if (!instructionList.type)
|
875
|
-
throw new RoninError({
|
876
|
-
message: `When ${queryTypeReadable} fields, a \`type\` field must be provided in the \`to\` instruction.`,
|
877
|
-
code: "MISSING_FIELD",
|
878
|
-
fields: ["type"]
|
879
|
-
});
|
880
|
-
}
|
862
|
+
if (queryType === "add") {
|
863
|
+
if (!instructionList.type) instructionList.type = "string";
|
881
864
|
dependencyStatements.push({
|
882
|
-
statement: `${statement} ADD COLUMN ${getFieldStatement(instructionList)}`,
|
865
|
+
statement: `${statement} ADD COLUMN ${getFieldStatement(models, targetModel, instructionList)}`,
|
883
866
|
params: []
|
884
867
|
});
|
885
868
|
} else if (queryType === "set") {
|
@@ -890,14 +873,13 @@ var addModelQueries = (models, queryDetails, dependencyStatements) => {
|
|
890
873
|
params: []
|
891
874
|
});
|
892
875
|
}
|
893
|
-
} else if (queryType === "
|
876
|
+
} else if (queryType === "delete") {
|
894
877
|
dependencyStatements.push({
|
895
878
|
statement: `${statement} DROP COLUMN "${slug}"`,
|
896
879
|
params: []
|
897
880
|
});
|
898
881
|
}
|
899
882
|
}
|
900
|
-
return queryInstructions;
|
901
883
|
};
|
902
884
|
|
903
885
|
// src/instructions/before-after.ts
|
@@ -1158,12 +1140,12 @@ var handleTo = (models, model, statementParams, queryType, dependencyStatements,
|
|
1158
1140
|
const currentTime = (/* @__PURE__ */ new Date()).toISOString();
|
1159
1141
|
const { with: withInstruction, to: toInstruction } = instructions;
|
1160
1142
|
const defaultFields = {};
|
1161
|
-
if (queryType === "
|
1143
|
+
if (queryType === "add") {
|
1162
1144
|
defaultFields.id = toInstruction.id || generateRecordId(model.idPrefix);
|
1163
1145
|
}
|
1164
1146
|
defaultFields.ronin = {
|
1165
1147
|
// If records are being created, set their creation time.
|
1166
|
-
...queryType === "
|
1148
|
+
...queryType === "add" ? { createdAt: currentTime } : {},
|
1167
1149
|
// If records are being created or updated, set their update time.
|
1168
1150
|
updatedAt: currentTime,
|
1169
1151
|
// Allow for overwriting the default values provided above.
|
@@ -1201,17 +1183,17 @@ var handleTo = (models, model, statementParams, queryType, dependencyStatements,
|
|
1201
1183
|
for (const fieldSlug in toInstruction) {
|
1202
1184
|
const fieldValue = toInstruction[fieldSlug];
|
1203
1185
|
const fieldDetails = getFieldFromModel(model, fieldSlug, "to");
|
1204
|
-
if (fieldDetails.field.type === "
|
1186
|
+
if (fieldDetails.field.type === "link" && fieldDetails.field.kind === "many") {
|
1205
1187
|
delete toInstruction[fieldSlug];
|
1206
1188
|
const associativeModelSlug = composeAssociationModelSlug(model, fieldDetails.field);
|
1207
1189
|
const composeStatement = (subQueryType, value) => {
|
1208
|
-
const source = queryType === "
|
1190
|
+
const source = queryType === "add" ? { id: toInstruction.id } : withInstruction;
|
1209
1191
|
const recordDetails = { source };
|
1210
1192
|
if (value) recordDetails.target = value;
|
1211
1193
|
return compileQueryInput(
|
1212
1194
|
{
|
1213
1195
|
[subQueryType]: {
|
1214
|
-
[associativeModelSlug]: subQueryType === "
|
1196
|
+
[associativeModelSlug]: subQueryType === "add" ? { to: recordDetails } : { with: recordDetails }
|
1215
1197
|
}
|
1216
1198
|
},
|
1217
1199
|
models,
|
@@ -1220,25 +1202,25 @@ var handleTo = (models, model, statementParams, queryType, dependencyStatements,
|
|
1220
1202
|
).main;
|
1221
1203
|
};
|
1222
1204
|
if (Array.isArray(fieldValue)) {
|
1223
|
-
dependencyStatements.push(composeStatement("
|
1205
|
+
dependencyStatements.push(composeStatement("delete"));
|
1224
1206
|
for (const record of fieldValue) {
|
1225
|
-
dependencyStatements.push(composeStatement("
|
1207
|
+
dependencyStatements.push(composeStatement("add", record));
|
1226
1208
|
}
|
1227
1209
|
} else if (isObject(fieldValue)) {
|
1228
1210
|
for (const recordToAdd of fieldValue.containing || []) {
|
1229
|
-
dependencyStatements.push(composeStatement("
|
1211
|
+
dependencyStatements.push(composeStatement("add", recordToAdd));
|
1230
1212
|
}
|
1231
1213
|
for (const recordToRemove of fieldValue.notContaining || []) {
|
1232
|
-
dependencyStatements.push(composeStatement("
|
1214
|
+
dependencyStatements.push(composeStatement("delete", recordToRemove));
|
1233
1215
|
}
|
1234
1216
|
}
|
1235
1217
|
}
|
1236
1218
|
}
|
1237
1219
|
let statement = composeConditions(models, model, statementParams, "to", toInstruction, {
|
1238
1220
|
parentModel,
|
1239
|
-
type: queryType === "
|
1221
|
+
type: queryType === "add" ? "fields" : void 0
|
1240
1222
|
});
|
1241
|
-
if (queryType === "
|
1223
|
+
if (queryType === "add") {
|
1242
1224
|
const deepStatement = composeConditions(
|
1243
1225
|
models,
|
1244
1226
|
model,
|
@@ -1266,11 +1248,6 @@ var compileQueryInput = (query, models, statementParams, options) => {
|
|
1266
1248
|
let instructions = formatIdentifiers(model, queryInstructions);
|
1267
1249
|
const dependencyStatements = [];
|
1268
1250
|
const returning = options?.returning ?? true;
|
1269
|
-
instructions = addModelQueries(
|
1270
|
-
models,
|
1271
|
-
{ queryType, queryModel, queryInstructions: instructions },
|
1272
|
-
dependencyStatements
|
1273
|
-
);
|
1274
1251
|
if (instructions && Object.hasOwn(instructions, "for")) {
|
1275
1252
|
instructions = handleFor(model, instructions);
|
1276
1253
|
}
|
@@ -1283,17 +1260,17 @@ var compileQueryInput = (query, models, statementParams, options) => {
|
|
1283
1260
|
case "get":
|
1284
1261
|
statement += `SELECT ${columns} FROM `;
|
1285
1262
|
break;
|
1286
|
-
case "
|
1287
|
-
statement +=
|
1288
|
-
break;
|
1289
|
-
case "drop":
|
1290
|
-
statement += "DELETE FROM ";
|
1263
|
+
case "set":
|
1264
|
+
statement += "UPDATE ";
|
1291
1265
|
break;
|
1292
|
-
case "
|
1266
|
+
case "add":
|
1293
1267
|
statement += "INSERT INTO ";
|
1294
1268
|
break;
|
1295
|
-
case "
|
1296
|
-
statement += "
|
1269
|
+
case "delete":
|
1270
|
+
statement += "DELETE FROM ";
|
1271
|
+
break;
|
1272
|
+
case "count":
|
1273
|
+
statement += `SELECT COUNT(${columns}) FROM `;
|
1297
1274
|
break;
|
1298
1275
|
}
|
1299
1276
|
let isJoiningMultipleRows = false;
|
@@ -1314,7 +1291,7 @@ var compileQueryInput = (query, models, statementParams, options) => {
|
|
1314
1291
|
} else {
|
1315
1292
|
statement += `"${model.table}" `;
|
1316
1293
|
}
|
1317
|
-
if (queryType === "
|
1294
|
+
if (queryType === "add" || queryType === "set") {
|
1318
1295
|
if (!isObject(instructions.to) || Object.keys(instructions.to).length === 0) {
|
1319
1296
|
throw new RoninError({
|
1320
1297
|
message: `When using a \`${queryType}\` query, the \`to\` instruction must be a non-empty object.`,
|
@@ -1334,7 +1311,7 @@ var compileQueryInput = (query, models, statementParams, options) => {
|
|
1334
1311
|
statement += `${toStatement} `;
|
1335
1312
|
}
|
1336
1313
|
const conditions = [];
|
1337
|
-
if (queryType !== "
|
1314
|
+
if (queryType !== "add" && instructions && Object.hasOwn(instructions, "with")) {
|
1338
1315
|
const withStatement = handleWith(
|
1339
1316
|
models,
|
1340
1317
|
model,
|
@@ -1387,7 +1364,7 @@ var compileQueryInput = (query, models, statementParams, options) => {
|
|
1387
1364
|
if (queryType === "get" && !isJoiningMultipleRows && (single || instructions?.limitedTo)) {
|
1388
1365
|
statement += handleLimitedTo(single, instructions?.limitedTo);
|
1389
1366
|
}
|
1390
|
-
if (["
|
1367
|
+
if (["add", "set", "delete"].includes(queryType) && returning) {
|
1391
1368
|
statement += "RETURNING * ";
|
1392
1369
|
}
|
1393
1370
|
const mainStatement = {
|
@@ -1401,6 +1378,122 @@ var compileQueryInput = (query, models, statementParams, options) => {
|
|
1401
1378
|
};
|
1402
1379
|
};
|
1403
1380
|
|
1381
|
+
// src/utils/meta.ts
|
1382
|
+
var transformMetaQuery = (models, dependencyStatements, query) => {
|
1383
|
+
if (query.create) {
|
1384
|
+
const init = query.create.model;
|
1385
|
+
const details = "to" in query.create ? { slug: init, ...query.create.to } : init;
|
1386
|
+
const modelWithFields = addDefaultModelFields(details, true);
|
1387
|
+
const modelWithPresets = addDefaultModelPresets(models, modelWithFields);
|
1388
|
+
const instructions = {
|
1389
|
+
to: modelWithPresets
|
1390
|
+
};
|
1391
|
+
addModelQueries(models, dependencyStatements, {
|
1392
|
+
queryType: "add",
|
1393
|
+
queryModel: "model",
|
1394
|
+
queryInstructions: instructions
|
1395
|
+
});
|
1396
|
+
return {
|
1397
|
+
add: {
|
1398
|
+
model: instructions
|
1399
|
+
}
|
1400
|
+
};
|
1401
|
+
}
|
1402
|
+
if (query.drop) {
|
1403
|
+
const slug = query.drop.model;
|
1404
|
+
const instructions = {
|
1405
|
+
with: { slug }
|
1406
|
+
};
|
1407
|
+
addModelQueries(models, dependencyStatements, {
|
1408
|
+
queryType: "delete",
|
1409
|
+
queryModel: "model",
|
1410
|
+
queryInstructions: instructions
|
1411
|
+
});
|
1412
|
+
return {
|
1413
|
+
delete: {
|
1414
|
+
model: instructions
|
1415
|
+
}
|
1416
|
+
};
|
1417
|
+
}
|
1418
|
+
if (query.alter) {
|
1419
|
+
const slug = query.alter.model;
|
1420
|
+
if ("to" in query.alter) {
|
1421
|
+
const modelWithFields = addDefaultModelFields(query.alter.to, false);
|
1422
|
+
const modelWithPresets = addDefaultModelPresets(models, modelWithFields);
|
1423
|
+
const instructions2 = {
|
1424
|
+
with: { slug },
|
1425
|
+
to: modelWithPresets
|
1426
|
+
};
|
1427
|
+
addModelQueries(models, dependencyStatements, {
|
1428
|
+
queryType: "set",
|
1429
|
+
queryModel: "model",
|
1430
|
+
queryInstructions: instructions2
|
1431
|
+
});
|
1432
|
+
return {
|
1433
|
+
set: {
|
1434
|
+
model: instructions2
|
1435
|
+
}
|
1436
|
+
};
|
1437
|
+
}
|
1438
|
+
if ("create" in query.alter) {
|
1439
|
+
const type2 = Object.keys(query.alter.create)[0];
|
1440
|
+
const item = query.alter.create[type2];
|
1441
|
+
const completeItem = { slug: item.slug || `${type2}_slug`, ...item };
|
1442
|
+
const instructions2 = {
|
1443
|
+
to: {
|
1444
|
+
model: { slug },
|
1445
|
+
...completeItem
|
1446
|
+
}
|
1447
|
+
};
|
1448
|
+
addModelQueries(models, dependencyStatements, {
|
1449
|
+
queryType: "add",
|
1450
|
+
queryModel: type2,
|
1451
|
+
queryInstructions: instructions2
|
1452
|
+
});
|
1453
|
+
return {
|
1454
|
+
add: {
|
1455
|
+
[type2]: instructions2
|
1456
|
+
}
|
1457
|
+
};
|
1458
|
+
}
|
1459
|
+
if ("alter" in query.alter) {
|
1460
|
+
const type2 = Object.keys(query.alter.alter)[0];
|
1461
|
+
const itemSlug2 = query.alter.alter[type2];
|
1462
|
+
const newItem = query.alter.alter.to;
|
1463
|
+
const instructions2 = {
|
1464
|
+
with: { model: { slug }, slug: itemSlug2 },
|
1465
|
+
to: newItem
|
1466
|
+
};
|
1467
|
+
addModelQueries(models, dependencyStatements, {
|
1468
|
+
queryType: "set",
|
1469
|
+
queryModel: type2,
|
1470
|
+
queryInstructions: instructions2
|
1471
|
+
});
|
1472
|
+
return {
|
1473
|
+
set: {
|
1474
|
+
[type2]: instructions2
|
1475
|
+
}
|
1476
|
+
};
|
1477
|
+
}
|
1478
|
+
const type = Object.keys(query.alter.drop)[0];
|
1479
|
+
const itemSlug = query.alter.drop[type];
|
1480
|
+
const instructions = {
|
1481
|
+
with: { model: { slug }, slug: itemSlug }
|
1482
|
+
};
|
1483
|
+
addModelQueries(models, dependencyStatements, {
|
1484
|
+
queryType: "delete",
|
1485
|
+
queryModel: type,
|
1486
|
+
queryInstructions: instructions
|
1487
|
+
});
|
1488
|
+
return {
|
1489
|
+
delete: {
|
1490
|
+
[type]: instructions
|
1491
|
+
}
|
1492
|
+
};
|
1493
|
+
}
|
1494
|
+
return query;
|
1495
|
+
};
|
1496
|
+
|
1404
1497
|
// src/index.ts
|
1405
1498
|
var compileQueries = (queries, models, options) => {
|
1406
1499
|
const modelList = addSystemModels(models).map((model) => {
|
@@ -1412,8 +1505,13 @@ var compileQueries = (queries, models, options) => {
|
|
1412
1505
|
const dependencyStatements = [];
|
1413
1506
|
const mainStatements = [];
|
1414
1507
|
for (const query of queries) {
|
1508
|
+
const transformedQuery = transformMetaQuery(
|
1509
|
+
modelListWithPresets,
|
1510
|
+
dependencyStatements,
|
1511
|
+
query
|
1512
|
+
);
|
1415
1513
|
const result = compileQueryInput(
|
1416
|
-
|
1514
|
+
transformedQuery,
|
1417
1515
|
modelListWithPresets,
|
1418
1516
|
options?.inlineParams ? null : []
|
1419
1517
|
);
|