@ronin/compiler 0.7.2 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/dist/index.d.ts +193 -31
  2. package/dist/index.js +184 -91
  3. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -1251,7 +1251,7 @@ declare const GetInstructionsSchema: z.ZodObject<Omit<{
1251
1251
  for?: string[] | Record<string, string> | undefined;
1252
1252
  }>;
1253
1253
  declare const QuerySchema: z.ZodObject<{
1254
- count: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodObject<Omit<{
1254
+ get: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodObject<Omit<{
1255
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<{
1256
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">]>>;
1257
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">]>>;
@@ -2103,7 +2103,7 @@ declare const QuerySchema: z.ZodObject<{
2103
2103
  limitedTo?: number | undefined;
2104
2104
  for?: string[] | Record<string, string> | undefined;
2105
2105
  }>>>>;
2106
- create: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<z.objectUtil.extendShape<Omit<{
2106
+ set: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<z.objectUtil.extendShape<{
2107
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<{
2108
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">]>>;
2109
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">]>>;
@@ -2922,10 +2922,11 @@ declare const QuerySchema: z.ZodObject<{
2922
2922
  after: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNull]>>;
2923
2923
  limitedTo: z.ZodOptional<z.ZodNumber>;
2924
2924
  for: z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodRecord<z.ZodString, z.ZodString>]>>;
2925
- }, "with" | "for">, {
2925
+ }, {
2926
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>>;
2927
2927
  }>, "strip", z.ZodTypeAny, {
2928
2928
  to: Record<string, any>;
2929
+ with?: Record<string, any> | Record<string, any>[] | undefined;
2929
2930
  including?: Record<string, any> | undefined;
2930
2931
  selecting?: string[] | undefined;
2931
2932
  orderedBy?: {
@@ -2939,8 +2940,10 @@ declare const QuerySchema: z.ZodObject<{
2939
2940
  before?: string | null | undefined;
2940
2941
  after?: string | null | undefined;
2941
2942
  limitedTo?: number | undefined;
2943
+ for?: string[] | Record<string, string> | undefined;
2942
2944
  }, {
2943
2945
  to: Record<string, any>;
2946
+ with?: Record<string, any> | Record<string, any>[] | undefined;
2944
2947
  including?: Record<string, any> | undefined;
2945
2948
  selecting?: string[] | undefined;
2946
2949
  orderedBy?: {
@@ -2954,8 +2957,9 @@ declare const QuerySchema: z.ZodObject<{
2954
2957
  before?: string | null | undefined;
2955
2958
  after?: string | null | undefined;
2956
2959
  limitedTo?: number | undefined;
2960
+ for?: string[] | Record<string, string> | undefined;
2957
2961
  }>>>;
2958
- drop: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<Omit<{
2962
+ add: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<z.objectUtil.extendShape<Omit<{
2959
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<{
2960
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">]>>;
2961
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">]>>;
@@ -3774,8 +3778,10 @@ declare const QuerySchema: z.ZodObject<{
3774
3778
  after: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNull]>>;
3775
3779
  limitedTo: z.ZodOptional<z.ZodNumber>;
3776
3780
  for: z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodRecord<z.ZodString, z.ZodString>]>>;
3777
- }, "to">, "strip", z.ZodTypeAny, {
3778
- with?: Record<string, any> | Record<string, any>[] | undefined;
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>;
3779
3785
  including?: Record<string, any> | undefined;
3780
3786
  selecting?: string[] | undefined;
3781
3787
  orderedBy?: {
@@ -3789,9 +3795,8 @@ declare const QuerySchema: z.ZodObject<{
3789
3795
  before?: string | null | undefined;
3790
3796
  after?: string | null | undefined;
3791
3797
  limitedTo?: number | undefined;
3792
- for?: string[] | Record<string, string> | undefined;
3793
3798
  }, {
3794
- with?: Record<string, any> | Record<string, any>[] | undefined;
3799
+ to: Record<string, any>;
3795
3800
  including?: Record<string, any> | undefined;
3796
3801
  selecting?: string[] | undefined;
3797
3802
  orderedBy?: {
@@ -3805,9 +3810,8 @@ declare const QuerySchema: z.ZodObject<{
3805
3810
  before?: string | null | undefined;
3806
3811
  after?: string | null | undefined;
3807
3812
  limitedTo?: number | undefined;
3808
- for?: string[] | Record<string, string> | undefined;
3809
3813
  }>>>;
3810
- get: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodObject<Omit<{
3814
+ remove: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<Omit<{
3811
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<{
3812
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">]>>;
3813
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">]>>;
@@ -4658,8 +4662,8 @@ declare const QuerySchema: z.ZodObject<{
4658
4662
  after?: string | null | undefined;
4659
4663
  limitedTo?: number | undefined;
4660
4664
  for?: string[] | Record<string, string> | undefined;
4661
- }>>>>;
4662
- set: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<z.objectUtil.extendShape<{
4665
+ }>>>;
4666
+ count: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodObject<Omit<{
4663
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<{
4664
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">]>>;
4665
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">]>>;
@@ -5478,10 +5482,7 @@ declare const QuerySchema: z.ZodObject<{
5478
5482
  after: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNull]>>;
5479
5483
  limitedTo: z.ZodOptional<z.ZodNumber>;
5480
5484
  for: z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodRecord<z.ZodString, z.ZodString>]>>;
5481
- }, {
5482
- 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>>;
5483
- }>, "strip", z.ZodTypeAny, {
5484
- to: Record<string, any>;
5485
+ }, "to">, "strip", z.ZodTypeAny, {
5485
5486
  with?: Record<string, any> | Record<string, any>[] | undefined;
5486
5487
  including?: Record<string, any> | undefined;
5487
5488
  selecting?: string[] | undefined;
@@ -5498,7 +5499,6 @@ declare const QuerySchema: z.ZodObject<{
5498
5499
  limitedTo?: number | undefined;
5499
5500
  for?: string[] | Record<string, string> | undefined;
5500
5501
  }, {
5501
- to: Record<string, any>;
5502
5502
  with?: Record<string, any> | Record<string, any>[] | undefined;
5503
5503
  including?: Record<string, any> | undefined;
5504
5504
  selecting?: string[] | undefined;
@@ -5514,7 +5514,81 @@ declare const QuerySchema: z.ZodObject<{
5514
5514
  after?: string | null | undefined;
5515
5515
  limitedTo?: number | undefined;
5516
5516
  for?: string[] | Record<string, string> | undefined;
5517
- }>>>;
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
+ }>>;
5518
5592
  }, "strip", z.ZodTypeAny, {
5519
5593
  get?: Record<string, {
5520
5594
  with?: Record<string, any> | Record<string, any>[] | undefined;
@@ -5551,8 +5625,8 @@ declare const QuerySchema: z.ZodObject<{
5551
5625
  limitedTo?: number | undefined;
5552
5626
  for?: string[] | Record<string, string> | undefined;
5553
5627
  }> | undefined;
5554
- drop?: Record<string, {
5555
- with?: Record<string, any> | Record<string, any>[] | undefined;
5628
+ add?: Record<string, {
5629
+ to: Record<string, any>;
5556
5630
  including?: Record<string, any> | undefined;
5557
5631
  selecting?: string[] | undefined;
5558
5632
  orderedBy?: {
@@ -5566,10 +5640,9 @@ declare const QuerySchema: z.ZodObject<{
5566
5640
  before?: string | null | undefined;
5567
5641
  after?: string | null | undefined;
5568
5642
  limitedTo?: number | undefined;
5569
- for?: string[] | Record<string, string> | undefined;
5570
5643
  }> | undefined;
5571
- create?: Record<string, {
5572
- to: Record<string, any>;
5644
+ remove?: Record<string, {
5645
+ with?: Record<string, any> | Record<string, any>[] | undefined;
5573
5646
  including?: Record<string, any> | undefined;
5574
5647
  selecting?: string[] | undefined;
5575
5648
  orderedBy?: {
@@ -5583,6 +5656,7 @@ declare const QuerySchema: z.ZodObject<{
5583
5656
  before?: string | null | undefined;
5584
5657
  after?: string | null | undefined;
5585
5658
  limitedTo?: number | undefined;
5659
+ for?: string[] | Record<string, string> | undefined;
5586
5660
  }> | undefined;
5587
5661
  count?: Record<string, {
5588
5662
  with?: Record<string, any> | Record<string, any>[] | undefined;
@@ -5601,6 +5675,30 @@ declare const QuerySchema: z.ZodObject<{
5601
5675
  limitedTo?: number | undefined;
5602
5676
  for?: string[] | Record<string, string> | undefined;
5603
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;
5604
5702
  }, {
5605
5703
  get?: Record<string, {
5606
5704
  with?: Record<string, any> | Record<string, any>[] | undefined;
@@ -5637,8 +5735,8 @@ declare const QuerySchema: z.ZodObject<{
5637
5735
  limitedTo?: number | undefined;
5638
5736
  for?: string[] | Record<string, string> | undefined;
5639
5737
  }> | undefined;
5640
- drop?: Record<string, {
5641
- with?: Record<string, any> | Record<string, any>[] | undefined;
5738
+ add?: Record<string, {
5739
+ to: Record<string, any>;
5642
5740
  including?: Record<string, any> | undefined;
5643
5741
  selecting?: string[] | undefined;
5644
5742
  orderedBy?: {
@@ -5652,10 +5750,9 @@ declare const QuerySchema: z.ZodObject<{
5652
5750
  before?: string | null | undefined;
5653
5751
  after?: string | null | undefined;
5654
5752
  limitedTo?: number | undefined;
5655
- for?: string[] | Record<string, string> | undefined;
5656
5753
  }> | undefined;
5657
- create?: Record<string, {
5658
- to: Record<string, any>;
5754
+ remove?: Record<string, {
5755
+ with?: Record<string, any> | Record<string, any>[] | undefined;
5659
5756
  including?: Record<string, any> | undefined;
5660
5757
  selecting?: string[] | undefined;
5661
5758
  orderedBy?: {
@@ -5669,6 +5766,7 @@ declare const QuerySchema: z.ZodObject<{
5669
5766
  before?: string | null | undefined;
5670
5767
  after?: string | null | undefined;
5671
5768
  limitedTo?: number | undefined;
5769
+ for?: string[] | Record<string, string> | undefined;
5672
5770
  }> | undefined;
5673
5771
  count?: Record<string, {
5674
5772
  with?: Record<string, any> | Record<string, any>[] | undefined;
@@ -5687,6 +5785,30 @@ declare const QuerySchema: z.ZodObject<{
5687
5785
  limitedTo?: number | undefined;
5688
5786
  for?: string[] | Record<string, string> | undefined;
5689
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;
5690
5812
  }>;
5691
5813
 
5692
5814
  type GetInstructions = z.infer<typeof GetInstructionsSchema>;
@@ -5699,14 +5821,50 @@ interface Statement {
5699
5821
  returning?: boolean;
5700
5822
  }
5701
5823
 
5824
+ type ModelFieldCollation = 'BINARY' | 'NOCASE' | 'RTRIM';
5702
5825
  type ModelFieldBasics = {
5826
+ /** The label that should be used when displaying the field on the RONIN dashboard. */
5703
5827
  name?: string;
5828
+ /** Allows for addressing the field programmatically. */
5704
5829
  slug: string;
5830
+ /** How the field should be displayed visually on the RONIN dashboard. */
5705
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
+ */
5706
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
+ */
5707
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
+ */
5708
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. */
5709
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;
5710
5868
  };
5711
5869
  type ModelFieldNormal = ModelFieldBasics & {
5712
5870
  type: 'string' | 'number' | 'boolean' | 'date' | 'json' | 'group';
@@ -5714,7 +5872,7 @@ type ModelFieldNormal = ModelFieldBasics & {
5714
5872
  type ModelFieldReferenceAction = 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'SET DEFAULT' | 'NO ACTION';
5715
5873
  type ModelFieldReference = ModelFieldBasics & {
5716
5874
  type: 'link';
5717
- target: Omit<Partial<Model>, 'slug'> & Pick<Model, 'slug'>;
5875
+ target: string;
5718
5876
  kind?: 'one' | 'many';
5719
5877
  actions?: {
5720
5878
  onDelete?: ModelFieldReferenceAction;
@@ -5724,7 +5882,7 @@ type ModelFieldReference = ModelFieldBasics & {
5724
5882
  type ModelField = ModelFieldNormal | ModelFieldReference;
5725
5883
  type ModelIndexField = {
5726
5884
  /** The collating sequence used for text placed inside the field. */
5727
- collation?: 'BINARY' | 'NOCASE' | 'RTRIM';
5885
+ collation?: ModelFieldCollation;
5728
5886
  /** How the records in the index should be ordered. */
5729
5887
  order?: 'ASC' | 'DESC';
5730
5888
  } & ({
@@ -5739,6 +5897,10 @@ type ModelIndex = {
5739
5897
  * The list of fields in the model for which the index should be created.
5740
5898
  */
5741
5899
  fields: Array<ModelIndexField>;
5900
+ /**
5901
+ * The identifier of the index.
5902
+ */
5903
+ slug?: string;
5742
5904
  /**
5743
5905
  * Whether only one record with a unique value for the provided fields will be allowed.
5744
5906
  */
@@ -5759,7 +5921,7 @@ type ModelTriggerField = {
5759
5921
  type ModelTrigger = {
5760
5922
  /** The type of query for which the trigger should fire. */
5761
5923
  action: 'INSERT' | 'UPDATE' | 'DELETE';
5762
- /** When the trigger should fire in the case that a maching query is executed. */
5924
+ /** When the trigger should fire in the case that a matching query is executed. */
5763
5925
  when: 'BEFORE' | 'DURING' | 'AFTER';
5764
5926
  /** A list of queries that should be executed when the trigger fires. */
5765
5927
  effects: Array<Query>;
package/dist/index.js CHANGED
@@ -194,7 +194,7 @@ var composeConditions = (models, model, statementParams, instructionName, value,
194
194
  if (keys.length === 1 && keys[0] === "id") {
195
195
  recordTarget = values[0];
196
196
  } else {
197
- const relatedModel = getModelBySlug(models, modelField.target.slug);
197
+ const relatedModel = getModelBySlug(models, modelField.target);
198
198
  const subQuery = {
199
199
  get: {
200
200
  [relatedModel.slug]: {
@@ -491,7 +491,7 @@ var SYSTEM_MODELS = [
491
491
  {
492
492
  slug: "model",
493
493
  type: "link",
494
- target: { slug: "model" },
494
+ target: "model",
495
495
  required: true
496
496
  },
497
497
  { slug: "required", type: "boolean" },
@@ -499,7 +499,7 @@ var SYSTEM_MODELS = [
499
499
  { slug: "unique", type: "boolean" },
500
500
  { slug: "autoIncrement", type: "boolean" },
501
501
  // Only allowed for fields of type "link".
502
- { slug: "target", type: "link", target: { slug: "model" } },
502
+ { slug: "target", type: "string" },
503
503
  { slug: "kind", type: "string" },
504
504
  { slug: "actions", type: "group" },
505
505
  { slug: "actions.onDelete", type: "string" },
@@ -517,7 +517,7 @@ var SYSTEM_MODELS = [
517
517
  {
518
518
  slug: "model",
519
519
  type: "link",
520
- target: { slug: "model" },
520
+ target: "model",
521
521
  required: true
522
522
  },
523
523
  { slug: "unique", type: "boolean" },
@@ -536,7 +536,7 @@ var SYSTEM_MODELS = [
536
536
  {
537
537
  slug: "model",
538
538
  type: "link",
539
- target: { slug: "model" },
539
+ target: "model",
540
540
  required: true
541
541
  },
542
542
  { slug: "when", type: "string", required: true },
@@ -553,7 +553,7 @@ var SYSTEM_MODELS = [
553
553
  {
554
554
  slug: "model",
555
555
  type: "link",
556
- target: { slug: "model" },
556
+ target: "model",
557
557
  required: true
558
558
  },
559
559
  { slug: "instructions", type: "json", required: true }
@@ -569,7 +569,7 @@ var addSystemModels = (models) => {
569
569
  const addedModels = [];
570
570
  for (const field of model.fields || []) {
571
571
  if (field.type === "link" && !field.slug.startsWith("ronin.")) {
572
- const relatedModel = getModelBySlug(models, field.target.slug);
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);
@@ -581,12 +581,12 @@ var addSystemModels = (models) => {
581
581
  {
582
582
  slug: "source",
583
583
  type: "link",
584
- target: { slug: model.slug }
584
+ target: model.slug
585
585
  },
586
586
  {
587
587
  slug: "target",
588
588
  type: "link",
589
- target: { slug: relatedModel.slug }
589
+ target: relatedModel.slug
590
590
  }
591
591
  ]
592
592
  });
@@ -601,7 +601,7 @@ var addDefaultModelPresets = (list, model) => {
601
601
  const defaultPresets = [];
602
602
  for (const field of model.fields || []) {
603
603
  if (field.type === "link" && !field.slug.startsWith("ronin.")) {
604
- const relatedModel = getModelBySlug(list, field.target.slug);
604
+ const relatedModel = getModelBySlug(list, field.target);
605
605
  if (field.kind === "many") continue;
606
606
  defaultPresets.push({
607
607
  instructions: {
@@ -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 === "link" && field2.target.slug === model.slug;
632
+ return field2.type === "link" && field2.target === model.slug;
633
633
  });
634
634
  if (!field) return null;
635
635
  return { model: subModel, field };
@@ -665,9 +665,9 @@ var addDefaultModelPresets = (list, model) => {
665
665
  return model;
666
666
  };
667
667
  var mappedInstructions = {
668
- create: "to",
668
+ add: "to",
669
669
  set: "with",
670
- drop: "with"
670
+ remove: "with"
671
671
  };
672
672
  var typesInSQLite = {
673
673
  link: "TEXT",
@@ -678,7 +678,7 @@ var typesInSQLite = {
678
678
  number: "INTEGER",
679
679
  json: "TEXT"
680
680
  };
681
- var getFieldStatement = (model, 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,13 +686,20 @@ var getFieldStatement = (model, 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.collation) statement += ` COLLATE ${field.collation}`;
690
+ if (field.increment === true) statement += " AUTOINCREMENT";
689
691
  if (typeof field.check !== "undefined") {
690
692
  const symbol = getSymbol(field.check);
691
693
  statement += ` CHECK (${parseFieldExpression(model, "to", symbol?.value)})`;
692
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
+ }
693
700
  if (field.type === "link") {
694
701
  const actions = field.actions || {};
695
- const targetTable = convertToSnakeCase(pluralize(field.target.slug));
702
+ const targetTable = getModelBySlug(models, field.target).table;
696
703
  statement += ` REFERENCES ${targetTable}("id")`;
697
704
  for (const trigger in actions) {
698
705
  const triggerName = trigger.toUpperCase().slice(2);
@@ -702,18 +709,17 @@ var getFieldStatement = (model, field) => {
702
709
  }
703
710
  return statement;
704
711
  };
705
- var addModelQueries = (models, queryDetails, dependencyStatements) => {
706
- const { queryType, queryModel, queryInstructions: queryInstructionsRaw } = queryDetails;
707
- const queryInstructions = queryInstructionsRaw;
708
- if (!["create", "set", "drop"].includes(queryType)) return queryInstructions;
709
- if (!SYSTEM_MODEL_SLUGS.includes(queryModel)) return queryInstructions;
712
+ var addModelQueries = (models, dependencyStatements, queryDetails) => {
713
+ const { queryType, queryModel, queryInstructions } = queryDetails;
714
+ if (!["add", "set", "remove"].includes(queryType)) return;
715
+ if (!SYSTEM_MODEL_SLUGS.includes(queryModel)) return;
710
716
  const instructionName = mappedInstructions[queryType];
711
717
  const instructionList = queryInstructions[instructionName];
712
718
  const kind = getModelBySlug(SYSTEM_MODELS, queryModel).pluralSlug;
713
719
  let tableAction = "ALTER";
714
720
  let queryTypeReadable = null;
715
721
  switch (queryType) {
716
- case "create": {
722
+ case "add": {
717
723
  if (kind === "models" || kind === "indexes" || kind === "triggers") {
718
724
  tableAction = "CREATE";
719
725
  }
@@ -725,7 +731,7 @@ var addModelQueries = (models, queryDetails, dependencyStatements) => {
725
731
  queryTypeReadable = "updating";
726
732
  break;
727
733
  }
728
- case "drop": {
734
+ case "remove": {
729
735
  if (kind === "models" || kind === "indexes" || kind === "triggers") {
730
736
  tableAction = "DROP";
731
737
  }
@@ -734,25 +740,11 @@ var addModelQueries = (models, queryDetails, dependencyStatements) => {
734
740
  }
735
741
  }
736
742
  const slug = instructionList?.slug?.being || instructionList?.slug;
737
- if (!slug) {
738
- throw new RoninError({
739
- message: `When ${queryTypeReadable} ${kind}, a \`slug\` field must be provided in the \`${instructionName}\` instruction.`,
740
- code: "MISSING_FIELD",
741
- fields: ["slug"]
742
- });
743
- }
744
743
  const modelInstruction = instructionList?.model;
745
744
  const modelSlug = modelInstruction?.slug?.being || modelInstruction?.slug;
746
- if (kind !== "models" && !modelSlug) {
747
- throw new RoninError({
748
- message: `When ${queryTypeReadable} ${kind}, a \`model.slug\` field must be provided in the \`${instructionName}\` instruction.`,
749
- code: "MISSING_FIELD",
750
- fields: ["model.slug"]
751
- });
752
- }
753
745
  const usableSlug = kind === "models" ? slug : modelSlug;
754
746
  const tableName = convertToSnakeCase(pluralize(usableSlug));
755
- const targetModel = kind === "models" && queryType === "create" ? null : getModelBySlug(models, usableSlug);
747
+ const targetModel = kind === "models" && queryType === "add" ? null : getModelBySlug(models, usableSlug);
756
748
  if (kind === "indexes") {
757
749
  const indexName = convertToSnakeCase(slug);
758
750
  const unique = instructionList?.unique;
@@ -760,7 +752,7 @@ var addModelQueries = (models, queryDetails, dependencyStatements) => {
760
752
  const fields = instructionList?.fields;
761
753
  const params = [];
762
754
  let statement2 = `${tableAction}${unique ? " UNIQUE" : ""} INDEX "${indexName}"`;
763
- if (queryType === "create") {
755
+ if (queryType === "add") {
764
756
  const model = targetModel;
765
757
  const columns = fields.map((field) => {
766
758
  let fieldSelector = "";
@@ -785,13 +777,13 @@ var addModelQueries = (models, queryDetails, dependencyStatements) => {
785
777
  }
786
778
  }
787
779
  dependencyStatements.push({ statement: statement2, params });
788
- return queryInstructions;
780
+ return;
789
781
  }
790
782
  if (kind === "triggers") {
791
783
  const triggerName = convertToSnakeCase(slug);
792
784
  const params = [];
793
785
  let statement2 = `${tableAction} TRIGGER "${triggerName}"`;
794
- if (queryType === "create") {
786
+ if (queryType === "add") {
795
787
  const currentModel = targetModel;
796
788
  const { when, action } = instructionList;
797
789
  const statementParts = [`${when} ${action}`];
@@ -837,22 +829,14 @@ var addModelQueries = (models, queryDetails, dependencyStatements) => {
837
829
  statement2 += ` ${statementParts.join(" ")}`;
838
830
  }
839
831
  dependencyStatements.push({ statement: statement2, params });
840
- return queryInstructions;
832
+ return;
841
833
  }
842
834
  const statement = `${tableAction} TABLE "${tableName}"`;
843
835
  if (kind === "models") {
844
- if (queryType === "create" || queryType === "set") {
845
- const modelWithFields = addDefaultModelFields(
846
- queryInstructions.to,
847
- queryType === "create"
848
- );
849
- const modelWithPresets = addDefaultModelPresets(models, modelWithFields);
850
- queryInstructions.to = modelWithPresets;
851
- }
852
- if (queryType === "create") {
836
+ if (queryType === "add") {
853
837
  const newModel = queryInstructions.to;
854
838
  const { fields } = newModel;
855
- const columns = fields.map((field) => getFieldStatement(newModel, field)).filter(Boolean);
839
+ const columns = fields.map((field) => getFieldStatement(models, newModel, field)).filter(Boolean);
856
840
  dependencyStatements.push({
857
841
  statement: `${statement} (${columns.join(", ")})`,
858
842
  params: []
@@ -868,23 +852,17 @@ var addModelQueries = (models, queryDetails, dependencyStatements) => {
868
852
  });
869
853
  }
870
854
  Object.assign(targetModel, queryInstructions.to);
871
- } else if (queryType === "drop") {
855
+ } else if (queryType === "remove") {
872
856
  models.splice(models.indexOf(targetModel), 1);
873
857
  dependencyStatements.push({ statement, params: [] });
874
858
  }
875
- return queryInstructions;
859
+ return;
876
860
  }
877
861
  if (kind === "fields") {
878
- if (queryType === "create") {
879
- if (!instructionList.type) {
880
- throw new RoninError({
881
- message: `When ${queryTypeReadable} fields, a \`type\` field must be provided in the \`to\` instruction.`,
882
- code: "MISSING_FIELD",
883
- fields: ["type"]
884
- });
885
- }
862
+ if (queryType === "add") {
863
+ if (!instructionList.type) instructionList.type = "string";
886
864
  dependencyStatements.push({
887
- statement: `${statement} ADD COLUMN ${getFieldStatement(targetModel, instructionList)}`,
865
+ statement: `${statement} ADD COLUMN ${getFieldStatement(models, targetModel, instructionList)}`,
888
866
  params: []
889
867
  });
890
868
  } else if (queryType === "set") {
@@ -895,14 +873,13 @@ var addModelQueries = (models, queryDetails, dependencyStatements) => {
895
873
  params: []
896
874
  });
897
875
  }
898
- } else if (queryType === "drop") {
876
+ } else if (queryType === "remove") {
899
877
  dependencyStatements.push({
900
878
  statement: `${statement} DROP COLUMN "${slug}"`,
901
879
  params: []
902
880
  });
903
881
  }
904
882
  }
905
- return queryInstructions;
906
883
  };
907
884
 
908
885
  // src/instructions/before-after.ts
@@ -1163,12 +1140,12 @@ var handleTo = (models, model, statementParams, queryType, dependencyStatements,
1163
1140
  const currentTime = (/* @__PURE__ */ new Date()).toISOString();
1164
1141
  const { with: withInstruction, to: toInstruction } = instructions;
1165
1142
  const defaultFields = {};
1166
- if (queryType === "create") {
1143
+ if (queryType === "add") {
1167
1144
  defaultFields.id = toInstruction.id || generateRecordId(model.idPrefix);
1168
1145
  }
1169
1146
  defaultFields.ronin = {
1170
1147
  // If records are being created, set their creation time.
1171
- ...queryType === "create" ? { createdAt: currentTime } : {},
1148
+ ...queryType === "add" ? { createdAt: currentTime } : {},
1172
1149
  // If records are being created or updated, set their update time.
1173
1150
  updatedAt: currentTime,
1174
1151
  // Allow for overwriting the default values provided above.
@@ -1210,13 +1187,13 @@ var handleTo = (models, model, statementParams, queryType, dependencyStatements,
1210
1187
  delete toInstruction[fieldSlug];
1211
1188
  const associativeModelSlug = composeAssociationModelSlug(model, fieldDetails.field);
1212
1189
  const composeStatement = (subQueryType, value) => {
1213
- const source = queryType === "create" ? { id: toInstruction.id } : withInstruction;
1190
+ const source = queryType === "add" ? { id: toInstruction.id } : withInstruction;
1214
1191
  const recordDetails = { source };
1215
1192
  if (value) recordDetails.target = value;
1216
1193
  return compileQueryInput(
1217
1194
  {
1218
1195
  [subQueryType]: {
1219
- [associativeModelSlug]: subQueryType === "create" ? { to: recordDetails } : { with: recordDetails }
1196
+ [associativeModelSlug]: subQueryType === "add" ? { to: recordDetails } : { with: recordDetails }
1220
1197
  }
1221
1198
  },
1222
1199
  models,
@@ -1225,25 +1202,25 @@ var handleTo = (models, model, statementParams, queryType, dependencyStatements,
1225
1202
  ).main;
1226
1203
  };
1227
1204
  if (Array.isArray(fieldValue)) {
1228
- dependencyStatements.push(composeStatement("drop"));
1205
+ dependencyStatements.push(composeStatement("remove"));
1229
1206
  for (const record of fieldValue) {
1230
- dependencyStatements.push(composeStatement("create", record));
1207
+ dependencyStatements.push(composeStatement("add", record));
1231
1208
  }
1232
1209
  } else if (isObject(fieldValue)) {
1233
1210
  for (const recordToAdd of fieldValue.containing || []) {
1234
- dependencyStatements.push(composeStatement("create", recordToAdd));
1211
+ dependencyStatements.push(composeStatement("add", recordToAdd));
1235
1212
  }
1236
1213
  for (const recordToRemove of fieldValue.notContaining || []) {
1237
- dependencyStatements.push(composeStatement("drop", recordToRemove));
1214
+ dependencyStatements.push(composeStatement("remove", recordToRemove));
1238
1215
  }
1239
1216
  }
1240
1217
  }
1241
1218
  }
1242
1219
  let statement = composeConditions(models, model, statementParams, "to", toInstruction, {
1243
1220
  parentModel,
1244
- type: queryType === "create" ? "fields" : void 0
1221
+ type: queryType === "add" ? "fields" : void 0
1245
1222
  });
1246
- if (queryType === "create") {
1223
+ if (queryType === "add") {
1247
1224
  const deepStatement = composeConditions(
1248
1225
  models,
1249
1226
  model,
@@ -1271,11 +1248,6 @@ var compileQueryInput = (query, models, statementParams, options) => {
1271
1248
  let instructions = formatIdentifiers(model, queryInstructions);
1272
1249
  const dependencyStatements = [];
1273
1250
  const returning = options?.returning ?? true;
1274
- instructions = addModelQueries(
1275
- models,
1276
- { queryType, queryModel, queryInstructions: instructions },
1277
- dependencyStatements
1278
- );
1279
1251
  if (instructions && Object.hasOwn(instructions, "for")) {
1280
1252
  instructions = handleFor(model, instructions);
1281
1253
  }
@@ -1288,17 +1260,17 @@ var compileQueryInput = (query, models, statementParams, options) => {
1288
1260
  case "get":
1289
1261
  statement += `SELECT ${columns} FROM `;
1290
1262
  break;
1291
- case "count":
1292
- statement += `SELECT COUNT(${columns}) FROM `;
1293
- break;
1294
- case "drop":
1295
- statement += "DELETE FROM ";
1263
+ case "set":
1264
+ statement += "UPDATE ";
1296
1265
  break;
1297
- case "create":
1266
+ case "add":
1298
1267
  statement += "INSERT INTO ";
1299
1268
  break;
1300
- case "set":
1301
- statement += "UPDATE ";
1269
+ case "remove":
1270
+ statement += "DELETE FROM ";
1271
+ break;
1272
+ case "count":
1273
+ statement += `SELECT COUNT(${columns}) FROM `;
1302
1274
  break;
1303
1275
  }
1304
1276
  let isJoiningMultipleRows = false;
@@ -1319,7 +1291,7 @@ var compileQueryInput = (query, models, statementParams, options) => {
1319
1291
  } else {
1320
1292
  statement += `"${model.table}" `;
1321
1293
  }
1322
- if (queryType === "create" || queryType === "set") {
1294
+ if (queryType === "add" || queryType === "set") {
1323
1295
  if (!isObject(instructions.to) || Object.keys(instructions.to).length === 0) {
1324
1296
  throw new RoninError({
1325
1297
  message: `When using a \`${queryType}\` query, the \`to\` instruction must be a non-empty object.`,
@@ -1339,7 +1311,7 @@ var compileQueryInput = (query, models, statementParams, options) => {
1339
1311
  statement += `${toStatement} `;
1340
1312
  }
1341
1313
  const conditions = [];
1342
- if (queryType !== "create" && instructions && Object.hasOwn(instructions, "with")) {
1314
+ if (queryType !== "add" && instructions && Object.hasOwn(instructions, "with")) {
1343
1315
  const withStatement = handleWith(
1344
1316
  models,
1345
1317
  model,
@@ -1392,7 +1364,7 @@ var compileQueryInput = (query, models, statementParams, options) => {
1392
1364
  if (queryType === "get" && !isJoiningMultipleRows && (single || instructions?.limitedTo)) {
1393
1365
  statement += handleLimitedTo(single, instructions?.limitedTo);
1394
1366
  }
1395
- if (["create", "set", "drop"].includes(queryType) && returning) {
1367
+ if (["add", "set", "remove"].includes(queryType) && returning) {
1396
1368
  statement += "RETURNING * ";
1397
1369
  }
1398
1370
  const mainStatement = {
@@ -1406,6 +1378,122 @@ var compileQueryInput = (query, models, statementParams, options) => {
1406
1378
  };
1407
1379
  };
1408
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: "remove",
1409
+ queryModel: "model",
1410
+ queryInstructions: instructions
1411
+ });
1412
+ return {
1413
+ remove: {
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: "remove",
1485
+ queryModel: type,
1486
+ queryInstructions: instructions
1487
+ });
1488
+ return {
1489
+ remove: {
1490
+ [type]: instructions
1491
+ }
1492
+ };
1493
+ }
1494
+ return query;
1495
+ };
1496
+
1409
1497
  // src/index.ts
1410
1498
  var compileQueries = (queries, models, options) => {
1411
1499
  const modelList = addSystemModels(models).map((model) => {
@@ -1417,8 +1505,13 @@ var compileQueries = (queries, models, options) => {
1417
1505
  const dependencyStatements = [];
1418
1506
  const mainStatements = [];
1419
1507
  for (const query of queries) {
1508
+ const transformedQuery = transformMetaQuery(
1509
+ modelListWithPresets,
1510
+ dependencyStatements,
1511
+ query
1512
+ );
1420
1513
  const result = compileQueryInput(
1421
- query,
1514
+ transformedQuery,
1422
1515
  modelListWithPresets,
1423
1516
  options?.inlineParams ? null : []
1424
1517
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.7.2",
3
+ "version": "0.8.1",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {