@ronin/compiler 0.9.0 → 0.10.0-leo-ron-1083-experimental-206

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/README.md CHANGED
@@ -52,6 +52,9 @@ const transaction = new Transaction([
52
52
 
53
53
  transaction.statements;
54
54
  // [{
55
+ // statement: 'CREATE TABLE "accounts" ...',
56
+ // params: []
57
+ // }, {
55
58
  // statement: 'SELECT * FROM "accounts"',
56
59
  // params: [],
57
60
  // returning: true,
package/dist/index.d.ts CHANGED
@@ -5919,6 +5919,10 @@ type ModelTriggerField<T extends Array<ModelField> = Array<ModelField>> = {
5919
5919
  slug: T[number]['slug'];
5920
5920
  };
5921
5921
  type ModelTrigger<T extends Array<ModelField> = Array<ModelField>> = {
5922
+ /**
5923
+ * The identifier of the trigger.
5924
+ */
5925
+ slug?: string;
5922
5926
  /** The type of query for which the trigger should fire. */
5923
5927
  action: 'INSERT' | 'UPDATE' | 'DELETE';
5924
5928
  /** When the trigger should fire in the case that a matching query is executed. */
@@ -5957,17 +5961,25 @@ interface Model<T extends Array<ModelField> = Array<ModelField>> {
5957
5961
  */
5958
5962
  tableAlias?: string;
5959
5963
  /**
5960
- * If the model is used to associate two models with each other (in the case of
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.
5964
+ * Details that identify the model as a model that was automatically created by RONIN,
5965
+ * instead of being manually created by a developer.
5963
5966
  */
5964
- associationSlug?: string;
5967
+ system?: {
5968
+ /** The model that caused the system model to get created. */
5969
+ model: string | 'root';
5970
+ /**
5971
+ * If the model is used to associate two models with each other (in the case of
5972
+ * many-cardinality link fields), this property should contain the field slug to
5973
+ * which the associative model should be mounted on the source model.
5974
+ */
5975
+ associationSlug?: string;
5976
+ };
5965
5977
  fields: T;
5966
5978
  indexes?: Array<ModelIndex<T>>;
5967
5979
  triggers?: Array<ModelTrigger<T>>;
5968
5980
  presets?: Array<ModelPreset>;
5969
5981
  }
5970
- type PublicModel<T extends Array<ModelField> = Array<ModelField>> = Omit<Partial<Model<T>>, 'slug' | 'identifiers' | 'associationSlug' | 'table' | 'tableAlias'> & {
5982
+ type PublicModel<T extends Array<ModelField> = Array<ModelField>> = Omit<Partial<Model<T>>, 'slug' | 'identifiers' | 'system' | 'table' | 'tableAlias'> & {
5971
5983
  slug: Required<Model['slug']>;
5972
5984
  identifiers?: Partial<Model['identifiers']>;
5973
5985
  };
package/dist/index.js CHANGED
@@ -20,6 +20,12 @@ var RONIN_MODEL_FIELD_REGEX = new RegExp(
20
20
  `${RONIN_MODEL_SYMBOLS.FIELD}[_a-zA-Z0-9]+`,
21
21
  "g"
22
22
  );
23
+ var MODEL_ENTITY_ERROR_CODES = {
24
+ field: "FIELD_NOT_FOUND",
25
+ index: "INDEX_NOT_FOUND",
26
+ trigger: "TRIGGER_NOT_FOUND",
27
+ preset: "PRESET_NOT_FOUND"
28
+ };
23
29
  var RoninError = class extends Error {
24
30
  code;
25
31
  field;
@@ -459,67 +465,67 @@ var SYSTEM_FIELDS = [
459
465
  slug: "ronin.updatedBy"
460
466
  }
461
467
  ];
462
- var SYSTEM_MODELS = [
463
- {
464
- slug: "model",
465
- identifiers: {
466
- name: "name",
467
- slug: "slug"
468
- },
469
- // This name mimics the `sqlite_schema` table in SQLite.
470
- table: "ronin_schema",
471
- fields: [
472
- { slug: "name", type: "string" },
473
- { slug: "pluralName", type: "string" },
474
- { slug: "slug", type: "string" },
475
- { slug: "pluralSlug", type: "string" },
476
- { slug: "idPrefix", type: "string" },
477
- { slug: "table", type: "string" },
478
- { slug: "identifiers", type: "group" },
479
- { slug: "identifiers.name", type: "string" },
480
- { slug: "identifiers.slug", type: "string" },
481
- // Providing an empty object as a default value allows us to use `json_insert`
482
- // without needing to fall back to an empty object in the insertion statement,
483
- // which makes the statement shorter.
484
- { slug: "fields", type: "json", defaultValue: "{}" },
485
- { slug: "indexes", type: "json", defaultValue: "{}" },
486
- { slug: "triggers", type: "json", defaultValue: "{}" },
487
- { slug: "presets", type: "json", defaultValue: "{}" }
488
- ]
489
- }
490
- ];
491
- var addSystemModels = (models) => {
492
- const associativeModels = models.flatMap((model) => {
493
- const addedModels = [];
494
- for (const field of model.fields || []) {
495
- if (field.type === "link" && !field.slug.startsWith("ronin.")) {
496
- const relatedModel = getModelBySlug(models, field.target);
497
- let fieldSlug = relatedModel.slug;
498
- if (field.kind === "many") {
499
- fieldSlug = composeAssociationModelSlug(model, field);
500
- addedModels.push({
501
- pluralSlug: fieldSlug,
502
- slug: fieldSlug,
503
- associationSlug: field.slug,
504
- fields: [
505
- {
506
- slug: "source",
507
- type: "link",
508
- target: model.slug
509
- },
510
- {
511
- slug: "target",
512
- type: "link",
513
- target: relatedModel.slug
514
- }
515
- ]
516
- });
517
- }
468
+ var ROOT_MODEL = {
469
+ slug: "model",
470
+ identifiers: {
471
+ name: "name",
472
+ slug: "slug"
473
+ },
474
+ // This name mimics the `sqlite_schema` table in SQLite.
475
+ table: "ronin_schema",
476
+ // Indicates that the model was automatically generated by RONIN.
477
+ system: { model: "root" },
478
+ fields: [
479
+ { slug: "name", type: "string" },
480
+ { slug: "pluralName", type: "string" },
481
+ { slug: "slug", type: "string" },
482
+ { slug: "pluralSlug", type: "string" },
483
+ { slug: "idPrefix", type: "string" },
484
+ { slug: "table", type: "string" },
485
+ { slug: "identifiers", type: "group" },
486
+ { slug: "identifiers.name", type: "string" },
487
+ { slug: "identifiers.slug", type: "string" },
488
+ // Providing an empty object as a default value allows us to use `json_insert`
489
+ // without needing to fall back to an empty object in the insertion statement,
490
+ // which makes the statement shorter.
491
+ { slug: "fields", type: "json", defaultValue: "{}" },
492
+ { slug: "indexes", type: "json", defaultValue: "{}" },
493
+ { slug: "triggers", type: "json", defaultValue: "{}" },
494
+ { slug: "presets", type: "json", defaultValue: "{}" }
495
+ ]
496
+ };
497
+ var getSystemModels = (models, model) => {
498
+ const addedModels = [];
499
+ for (const field of model.fields || []) {
500
+ if (field.type === "link" && !field.slug.startsWith("ronin.")) {
501
+ const relatedModel = getModelBySlug(models, field.target);
502
+ let fieldSlug = relatedModel.slug;
503
+ if (field.kind === "many") {
504
+ fieldSlug = composeAssociationModelSlug(model, field);
505
+ addedModels.push({
506
+ pluralSlug: fieldSlug,
507
+ slug: fieldSlug,
508
+ system: {
509
+ model: model.slug,
510
+ associationSlug: field.slug
511
+ },
512
+ fields: [
513
+ {
514
+ slug: "source",
515
+ type: "link",
516
+ target: model.slug
517
+ },
518
+ {
519
+ slug: "target",
520
+ type: "link",
521
+ target: relatedModel.slug
522
+ }
523
+ ]
524
+ });
518
525
  }
519
526
  }
520
- return addedModels;
521
- });
522
- return [...SYSTEM_MODELS, ...associativeModels, ...models];
527
+ }
528
+ return addedModels;
523
529
  };
524
530
  var addDefaultModelPresets = (list, model) => {
525
531
  const defaultPresets = [];
@@ -561,7 +567,7 @@ var addDefaultModelPresets = (list, model) => {
561
567
  for (const childMatch of childModels) {
562
568
  const { model: childModel, field: childField } = childMatch;
563
569
  const pluralSlug = childModel.pluralSlug;
564
- const presetSlug = childModel.associationSlug || pluralSlug;
570
+ const presetSlug = childModel.system?.associationSlug || pluralSlug;
565
571
  defaultPresets.push({
566
572
  instructions: {
567
573
  including: {
@@ -617,6 +623,7 @@ var getFieldStatement = (models, model, field) => {
617
623
  statement += ` GENERATED ALWAYS AS (${parseFieldExpression(model, "to", symbol?.value)}) ${kind}`;
618
624
  }
619
625
  if (field.type === "link") {
626
+ if (field.kind === "many") return null;
620
627
  const actions = field.actions || {};
621
628
  const targetTable = getModelBySlug(models, field.target).table;
622
629
  statement += ` REFERENCES ${targetTable}("id")`;
@@ -641,6 +648,18 @@ var formatModelEntity = (type, entities) => {
641
648
  });
642
649
  return entries ? Object.fromEntries(entries) : void 0;
643
650
  };
651
+ var handleSystemModel = (models, dependencyStatements, action, systemModel, newModel) => {
652
+ const { system: _, ...systemModelClean } = systemModel;
653
+ const query = {
654
+ [action]: { model: action === "create" ? systemModelClean : systemModelClean.slug }
655
+ };
656
+ if (action === "alter" && newModel) {
657
+ const { system: _2, ...newModelClean } = newModel;
658
+ query.alter.to = newModelClean;
659
+ }
660
+ const statement = compileQueryInput(query, models, []);
661
+ dependencyStatements.push(...statement.dependencies);
662
+ };
644
663
  var transformMetaQuery = (models, dependencyStatements, statementParams, query) => {
645
664
  const { queryType } = splitQuery(query);
646
665
  const subAltering = query.alter && !("to" in query.alter);
@@ -669,16 +688,16 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
669
688
  }
670
689
  }
671
690
  if (!(modelSlug && slug)) return query;
672
- const tableAction = ["model", "index", "trigger"].includes(entity) ? action.toUpperCase() : "ALTER";
673
- const tableName = convertToSnakeCase(pluralize(modelSlug));
674
691
  const model = action === "create" && entity === "model" ? null : getModelBySlug(models, modelSlug);
675
- const statement = `${tableAction} TABLE "${tableName}"`;
676
692
  if (entity === "model") {
677
693
  let queryTypeDetails;
678
694
  if (action === "create") {
679
695
  const newModel = jsonValue;
680
696
  const modelWithFields = addDefaultModelFields(newModel, true);
681
- const modelWithPresets = addDefaultModelPresets(models, modelWithFields);
697
+ const modelWithPresets = addDefaultModelPresets(
698
+ [...models, modelWithFields],
699
+ modelWithFields
700
+ );
682
701
  const entities = Object.fromEntries(
683
702
  Object.entries(PLURAL_MODEL_ENTITIES).map(([type, pluralType2]) => {
684
703
  const list = modelWithPresets[pluralType2];
@@ -687,7 +706,7 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
687
706
  );
688
707
  const columns = modelWithPresets.fields.map((field2) => getFieldStatement(models, modelWithPresets, field2)).filter(Boolean);
689
708
  dependencyStatements.push({
690
- statement: `${statement} (${columns.join(", ")})`,
709
+ statement: `CREATE TABLE "${modelWithPresets.table}" (${columns.join(", ")})`,
691
710
  params: []
692
711
  });
693
712
  models.push(modelWithPresets);
@@ -696,16 +715,18 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
696
715
  if (entities[entity2]) finalModel[entity2] = entities[entity2];
697
716
  }
698
717
  queryTypeDetails = { to: finalModel };
718
+ getSystemModels(models, modelWithPresets).map((systemModel) => {
719
+ return handleSystemModel(models, dependencyStatements, "create", systemModel);
720
+ });
699
721
  }
700
722
  if (action === "alter" && model) {
701
723
  const newModel = jsonValue;
702
724
  const modelWithFields = addDefaultModelFields(newModel, false);
703
725
  const modelWithPresets = addDefaultModelPresets(models, modelWithFields);
704
- const newSlug = modelWithPresets.pluralSlug;
705
- if (newSlug) {
706
- const newTable = convertToSnakeCase(newSlug);
726
+ const newTableName = modelWithPresets.table;
727
+ if (newTableName) {
707
728
  dependencyStatements.push({
708
- statement: `${statement} RENAME TO "${newTable}"`,
729
+ statement: `ALTER TABLE "${model.table}" RENAME TO "${newTableName}"`,
709
730
  params: []
710
731
  });
711
732
  }
@@ -719,8 +740,11 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
719
740
  }
720
741
  if (action === "drop" && model) {
721
742
  models.splice(models.indexOf(model), 1);
722
- dependencyStatements.push({ statement, params: [] });
743
+ dependencyStatements.push({ statement: `DROP TABLE "${model.table}"`, params: [] });
723
744
  queryTypeDetails = { with: { slug } };
745
+ models.filter(({ system }) => system?.model === model.slug).map((systemModel) => {
746
+ return handleSystemModel(models, dependencyStatements, "drop", systemModel);
747
+ });
724
748
  }
725
749
  const queryTypeAction = action === "create" ? "add" : action === "alter" ? "set" : "remove";
726
750
  return {
@@ -729,58 +753,78 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
729
753
  }
730
754
  };
731
755
  }
732
- if (entity === "field" && model) {
756
+ const modelBeforeUpdate = structuredClone(model);
757
+ const existingModel = model;
758
+ const pluralType = PLURAL_MODEL_ENTITIES[entity];
759
+ const targetEntityIndex = existingModel[pluralType]?.findIndex(
760
+ (entity2) => entity2.slug === slug
761
+ );
762
+ if ((action === "alter" || action === "drop") && (typeof targetEntityIndex === "undefined" || targetEntityIndex === -1)) {
763
+ throw new RoninError({
764
+ message: `No ${entity} with slug "${slug}" defined in model "${existingModel.name}".`,
765
+ code: MODEL_ENTITY_ERROR_CODES[entity]
766
+ });
767
+ }
768
+ const existingEntity = existingModel[pluralType]?.[targetEntityIndex];
769
+ if (entity === "field") {
770
+ const statement = `ALTER TABLE "${existingModel.table}"`;
771
+ const existingField = existingEntity;
772
+ const existingLinkField = existingField?.type === "link" && existingField.kind === "many";
733
773
  if (action === "create") {
734
774
  const field2 = jsonValue;
735
775
  field2.type = field2.type || "string";
736
- dependencyStatements.push({
737
- statement: `${statement} ADD COLUMN ${getFieldStatement(models, model, field2)}`,
738
- params: []
739
- });
776
+ const fieldStatement = getFieldStatement(models, existingModel, field2);
777
+ if (fieldStatement) {
778
+ dependencyStatements.push({
779
+ statement: `${statement} ADD COLUMN ${fieldStatement}`,
780
+ params: []
781
+ });
782
+ }
740
783
  } else if (action === "alter") {
741
784
  const newSlug = jsonValue?.slug;
742
- if (newSlug) {
785
+ if (newSlug && !existingLinkField) {
743
786
  dependencyStatements.push({
744
787
  statement: `${statement} RENAME COLUMN "${slug}" TO "${newSlug}"`,
745
788
  params: []
746
789
  });
747
790
  }
748
- } else if (action === "drop") {
791
+ } else if (action === "drop" && !existingLinkField) {
749
792
  dependencyStatements.push({
750
793
  statement: `${statement} DROP COLUMN "${slug}"`,
751
794
  params: []
752
795
  });
753
796
  }
754
797
  }
755
- if (entity === "index" && model) {
798
+ const statementAction = action.toUpperCase();
799
+ if (entity === "index") {
756
800
  const index = jsonValue;
757
801
  const indexName = convertToSnakeCase(slug);
758
802
  const params = [];
759
- let statement2 = `${tableAction}${index?.unique ? " UNIQUE" : ""} INDEX "${indexName}"`;
803
+ let statement = `${statementAction}${index?.unique ? " UNIQUE" : ""} INDEX "${indexName}"`;
760
804
  if (action === "create") {
761
805
  const columns = index.fields.map((field2) => {
762
806
  let fieldSelector = "";
763
807
  if ("slug" in field2) {
764
- ({ fieldSelector } = getFieldFromModel(model, field2.slug, "to"));
808
+ ({ fieldSelector } = getFieldFromModel(existingModel, field2.slug, "to"));
765
809
  } else if ("expression" in field2) {
766
- fieldSelector = parseFieldExpression(model, "to", field2.expression);
810
+ fieldSelector = parseFieldExpression(existingModel, "to", field2.expression);
767
811
  }
768
812
  if (field2.collation) fieldSelector += ` COLLATE ${field2.collation}`;
769
813
  if (field2.order) fieldSelector += ` ${field2.order}`;
770
814
  return fieldSelector;
771
815
  });
772
- statement2 += ` ON "${tableName}" (${columns.join(", ")})`;
816
+ statement += ` ON "${existingModel.table}" (${columns.join(", ")})`;
773
817
  if (index.filter) {
774
- const withStatement = handleWith(models, model, params, index.filter);
775
- statement2 += ` WHERE (${withStatement})`;
818
+ const withStatement = handleWith(models, existingModel, params, index.filter);
819
+ statement += ` WHERE (${withStatement})`;
776
820
  }
777
821
  }
778
- dependencyStatements.push({ statement: statement2, params });
822
+ dependencyStatements.push({ statement, params });
779
823
  }
780
- if (entity === "trigger" && model) {
824
+ if (entity === "trigger") {
781
825
  const triggerName = convertToSnakeCase(slug);
782
826
  const params = [];
783
- let statement2 = `${tableAction} TRIGGER "${triggerName}"`;
827
+ let statement = `${statementAction} TRIGGER "${triggerName}"`;
784
828
  if (action === "create") {
785
829
  const trigger = jsonValue;
786
830
  const statementParts = [`${trigger.when} ${trigger.action}`];
@@ -793,11 +837,11 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
793
837
  });
794
838
  }
795
839
  const fieldSelectors = trigger.fields.map((field2) => {
796
- return getFieldFromModel(model, field2.slug, "to").fieldSelector;
840
+ return getFieldFromModel(existingModel, field2.slug, "to").fieldSelector;
797
841
  });
798
842
  statementParts.push(`OF (${fieldSelectors.join(", ")})`);
799
843
  }
800
- statementParts.push("ON", `"${tableName}"`);
844
+ statementParts.push("ON", `"${existingModel.table}"`);
801
845
  if (trigger.filter || trigger.effects.some((query2) => findInObject(query2, RONIN_MODEL_SYMBOLS.FIELD))) {
802
846
  statementParts.push("FOR EACH ROW");
803
847
  }
@@ -805,7 +849,7 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
805
849
  const tableAlias = trigger.action === "DELETE" ? RONIN_MODEL_SYMBOLS.FIELD_PARENT_OLD : RONIN_MODEL_SYMBOLS.FIELD_PARENT_NEW;
806
850
  const withStatement = handleWith(
807
851
  models,
808
- { ...model, tableAlias },
852
+ { ...existingModel, tableAlias },
809
853
  params,
810
854
  trigger.filter
811
855
  );
@@ -814,34 +858,75 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
814
858
  const effectStatements = trigger.effects.map((effectQuery) => {
815
859
  return compileQueryInput(effectQuery, models, params, {
816
860
  returning: false,
817
- parentModel: model
861
+ parentModel: existingModel
818
862
  }).main.statement;
819
863
  });
820
864
  if (effectStatements.length > 1) statementParts.push("BEGIN");
821
865
  statementParts.push(effectStatements.join("; "));
822
866
  if (effectStatements.length > 1) statementParts.push("END");
823
- statement2 += ` ${statementParts.join(" ")}`;
867
+ statement += ` ${statementParts.join(" ")}`;
824
868
  }
825
- dependencyStatements.push({ statement: statement2, params });
869
+ dependencyStatements.push({ statement, params });
826
870
  }
827
- const pluralType = PLURAL_MODEL_ENTITIES[entity];
828
871
  const field = `${RONIN_MODEL_SYMBOLS.FIELD}${pluralType}`;
829
872
  let json;
830
873
  switch (action) {
831
874
  case "create": {
832
875
  const value = prepareStatementValue(statementParams, jsonValue);
833
876
  json = `json_insert(${field}, '$.${slug}', ${value})`;
877
+ existingModel[pluralType] = [
878
+ ...existingModel[pluralType] || [],
879
+ jsonValue
880
+ ];
834
881
  break;
835
882
  }
836
883
  case "alter": {
837
884
  const value = prepareStatementValue(statementParams, jsonValue);
838
885
  json = `json_set(${field}, '$.${slug}', json_patch(json_extract(${field}, '$.${slug}'), ${value}))`;
886
+ const targetEntity = existingModel[pluralType];
887
+ Object.assign(targetEntity[targetEntityIndex], jsonValue);
839
888
  break;
840
889
  }
841
890
  case "drop": {
842
891
  json = `json_remove(${field}, '$.${slug}')`;
892
+ const targetEntity = existingModel[pluralType];
893
+ targetEntity.splice(targetEntityIndex, 1);
843
894
  }
844
895
  }
896
+ const currentSystemModels = models.filter(({ system }) => {
897
+ return system?.model === existingModel.slug;
898
+ });
899
+ const newSystemModels = getSystemModels(models, existingModel);
900
+ const matchSystemModels = (oldSystemModel, newSystemModel) => {
901
+ const conditions = [
902
+ oldSystemModel.system?.model === newSystemModel.system?.model
903
+ ];
904
+ if (oldSystemModel.system?.associationSlug) {
905
+ const oldFieldIndex = modelBeforeUpdate?.fields.findIndex((item) => {
906
+ return item.slug === newSystemModel.system?.associationSlug;
907
+ });
908
+ const newFieldIndex = existingModel.fields.findIndex((item) => {
909
+ return item.slug === oldSystemModel.system?.associationSlug;
910
+ });
911
+ conditions.push(oldFieldIndex === newFieldIndex);
912
+ }
913
+ return conditions.every((condition) => condition === true);
914
+ };
915
+ for (const systemModel of currentSystemModels) {
916
+ const exists = newSystemModels.find(matchSystemModels.bind(null, systemModel));
917
+ if (exists) {
918
+ if (exists.slug !== systemModel.slug) {
919
+ handleSystemModel(models, dependencyStatements, "alter", systemModel, exists);
920
+ }
921
+ continue;
922
+ }
923
+ handleSystemModel(models, dependencyStatements, "drop", systemModel);
924
+ }
925
+ for (const systemModel of newSystemModels) {
926
+ const exists = currentSystemModels.find(matchSystemModels.bind(null, systemModel));
927
+ if (exists) continue;
928
+ handleSystemModel(models, dependencyStatements, "create", systemModel);
929
+ }
845
930
  return {
846
931
  set: {
847
932
  model: {
@@ -1212,13 +1297,19 @@ var handleTo = (models, model, statementParams, queryType, dependencyStatements,
1212
1297
  };
1213
1298
 
1214
1299
  // src/utils/index.ts
1215
- var compileQueryInput = (query, models, statementParams, options) => {
1300
+ var compileQueryInput = (defaultQuery, models, statementParams, options) => {
1301
+ const dependencyStatements = [];
1302
+ const query = transformMetaQuery(
1303
+ models,
1304
+ dependencyStatements,
1305
+ statementParams,
1306
+ defaultQuery
1307
+ );
1216
1308
  const parsedQuery = splitQuery(query);
1217
1309
  const { queryType, queryModel, queryInstructions } = parsedQuery;
1218
1310
  const model = getModelBySlug(models, queryModel);
1219
1311
  const single = queryModel !== model.pluralSlug;
1220
1312
  let instructions = formatIdentifiers(model, queryInstructions);
1221
- const dependencyStatements = [];
1222
1313
  const returning = options?.returning ?? true;
1223
1314
  if (instructions && Object.hasOwn(instructions, "for")) {
1224
1315
  instructions = handleFor(model, instructions);
@@ -1370,7 +1461,11 @@ var Transaction = class {
1370
1461
  * @returns The composed SQL statements.
1371
1462
  */
1372
1463
  compileQueries = (queries, models, options) => {
1373
- const modelList = addSystemModels(models).map((model) => {
1464
+ const modelList = [
1465
+ ROOT_MODEL,
1466
+ ...models.flatMap((model) => getSystemModels(models, model)),
1467
+ ...models
1468
+ ].map((model) => {
1374
1469
  return addDefaultModelFields(model, true);
1375
1470
  });
1376
1471
  const modelListWithPresets = modelList.map((model) => {
@@ -1379,17 +1474,10 @@ var Transaction = class {
1379
1474
  const dependencyStatements = [];
1380
1475
  const mainStatements = [];
1381
1476
  for (const query of queries) {
1382
- const statementValues = options?.inlineParams ? null : [];
1383
- const transformedQuery = transformMetaQuery(
1384
- modelListWithPresets,
1385
- dependencyStatements,
1386
- statementValues,
1387
- query
1388
- );
1389
1477
  const result = compileQueryInput(
1390
- transformedQuery,
1478
+ query,
1391
1479
  modelListWithPresets,
1392
- statementValues
1480
+ options?.inlineParams ? null : []
1393
1481
  );
1394
1482
  dependencyStatements.push(...result.dependencies);
1395
1483
  mainStatements.push(result.main);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.9.0",
3
+ "version": "0.10.0-leo-ron-1083-experimental-206",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {