@ronin/compiler 0.14.6-corny-ron-1099-experimental-333 → 0.14.6-leo-ron-1099-1-experimental-336

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 CHANGED
@@ -199,7 +199,7 @@ type ModelFieldBasics = {
199
199
  * The value that should be inserted into the field in the case that no value was
200
200
  * explicitly provided for it when a record is created.
201
201
  */
202
- defaultValue?: Expression | unknown | (() => string);
202
+ defaultValue?: Expression | unknown;
203
203
  /**
204
204
  * An expression that should be evaluated to form the value of the field. The
205
205
  * expression can either be VIRTUAL (evaluated whenever a record is read) or STORED
@@ -207,10 +207,10 @@ type ModelFieldBasics = {
207
207
  */
208
208
  computedAs?: {
209
209
  kind: 'VIRTUAL' | 'STORED';
210
- value: ((fields: Record<string, string>) => string) | string | Expression;
210
+ value: Expression;
211
211
  };
212
212
  /** An expression that gets evaluated every time a value is provided for the field. */
213
- check?: Expression | ((fields: Record<string, string>) => string);
213
+ check?: Expression;
214
214
  };
215
215
  type ModelField = ModelFieldBasics & ({
216
216
  /** The kind of value that should be stored inside the field. */
package/dist/index.js CHANGED
@@ -557,10 +557,10 @@ var handleTo = (models, model, statementParams, queryType, dependencyStatements,
557
557
  delete toInstruction[fieldSlug];
558
558
  const associativeModelSlug = composeAssociationModelSlug(model, fieldDetails.field);
559
559
  const composeStatement = (subQueryType, value) => {
560
- const source = queryType === "add" ? { id: toInstruction.id } : withInstruction;
560
+ const source = queryType === "add" ? toInstruction : withInstruction;
561
561
  const recordDetails = { source };
562
562
  if (value) recordDetails.target = value;
563
- return compileQueryInput(
563
+ const query = compileQueryInput(
564
564
  {
565
565
  [subQueryType]: {
566
566
  [associativeModelSlug]: subQueryType === "add" ? { to: recordDetails } : { with: recordDetails }
@@ -570,19 +570,24 @@ var handleTo = (models, model, statementParams, queryType, dependencyStatements,
570
570
  [],
571
571
  { returning: false }
572
572
  ).main;
573
+ const details = { ...query };
574
+ if (queryType === "add" && subQueryType === "add") {
575
+ details.after = true;
576
+ }
577
+ dependencyStatements.push(details);
573
578
  };
574
579
  if (Array.isArray(fieldValue)) {
575
- dependencyStatements.push(composeStatement("remove"));
580
+ if (queryType === "set") composeStatement("remove");
576
581
  for (const record of fieldValue) {
577
- dependencyStatements.push(composeStatement("add", record));
582
+ composeStatement("add", record);
578
583
  }
579
584
  } else if (isObject(fieldValue)) {
580
585
  const value = fieldValue;
581
586
  for (const recordToAdd of value.containing || []) {
582
- dependencyStatements.push(composeStatement("add", recordToAdd));
587
+ composeStatement("add", recordToAdd);
583
588
  }
584
589
  for (const recordToRemove of value.notContaining || []) {
585
- dependencyStatements.push(composeStatement("remove", recordToRemove));
590
+ composeStatement("remove", recordToRemove);
586
591
  }
587
592
  }
588
593
  }
@@ -1984,19 +1989,21 @@ var Transaction = class {
1984
1989
  });
1985
1990
  const statements = [];
1986
1991
  for (const query of queries) {
1987
- const result = compileQueryInput(
1992
+ const { dependencies, main, selectedFields } = compileQueryInput(
1988
1993
  query,
1989
1994
  modelsWithPresets,
1990
1995
  options?.inlineParams ? null : [],
1991
1996
  { expandColumns: options?.expandColumns }
1992
1997
  );
1993
- const subStatements = [...result.dependencies, result.main];
1998
+ const preDependencies = dependencies.filter(({ after }) => !after);
1999
+ const postDependencies = dependencies.map(({ after, ...rest }) => after ? rest : null).filter((item) => item != null);
2000
+ const subStatements = [...preDependencies, main, ...postDependencies];
1994
2001
  this.statements.push(...subStatements);
1995
2002
  this.#internalStatements.push(
1996
2003
  ...subStatements.map((statement) => ({
1997
2004
  ...statement,
1998
2005
  query,
1999
- selectedFields: result.selectedFields
2006
+ selectedFields
2000
2007
  }))
2001
2008
  );
2002
2009
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.14.6-corny-ron-1099-experimental-333",
3
+ "version": "0.14.6-leo-ron-1099-1-experimental-336",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {