@ronin/compiler 0.18.4 → 0.18.5-json-experimental-444

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.
Files changed (2) hide show
  1. package/dist/index.js +12 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1374,7 +1374,7 @@ var composeConditions = (models, model, statementParams, instructionName, value,
1374
1374
  const fieldIsJSON = (modelField?.type === "json" || modelField?.type === "blob") && instructionName === "to";
1375
1375
  const valueIsJSON = isObject(value) || (modelField?.type === "blob" ? null : Array.isArray(value));
1376
1376
  if (!valueIsJSON || getQuerySymbol(value) || fieldIsJSON) {
1377
- if (modelField && fieldIsJSON && !valueIsJSON) {
1377
+ if (modelField && fieldIsJSON && !valueIsJSON && value !== null) {
1378
1378
  const messagePrefix = "The provided field value is not";
1379
1379
  const message = modelField.type === "json" ? `${messagePrefix} valid JSON. Only objects and arrays should be provided. Other types of values should be stored in their respective primitive field types.` : `${messagePrefix} a valid Blob reference.`;
1380
1380
  throw new RoninError({
@@ -1684,7 +1684,16 @@ var getFieldStatement = (models, model, field) => {
1684
1684
  const symbol = getQuerySymbol(field.defaultValue);
1685
1685
  let value = typeof field.defaultValue === "string" ? `'${field.defaultValue}'` : field.defaultValue;
1686
1686
  if (symbol) value = `(${parseFieldExpression(model, "to", symbol.value)})`;
1687
- if (field.type === "json") value = `'${JSON.stringify(field.defaultValue)}'`;
1687
+ if (field.type === "json") {
1688
+ if (!isObject(field.defaultValue)) {
1689
+ throw new RoninError({
1690
+ message: `The default value of JSON field "${field.slug}" must be an object.`,
1691
+ code: "INVALID_MODEL_VALUE",
1692
+ field: "fields"
1693
+ });
1694
+ }
1695
+ value = `'${JSON.stringify(field.defaultValue)}'`;
1696
+ }
1688
1697
  statement += ` DEFAULT ${value}`;
1689
1698
  }
1690
1699
  if (field.type === "string" && field.collation) {
@@ -2001,7 +2010,7 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query,
2001
2010
  throw new RoninError({
2002
2011
  message: `When ${actionReadable} ${PLURAL_MODEL_ENTITIES[entity]}, at least one field must be provided.`,
2003
2012
  code: "INVALID_MODEL_VALUE",
2004
- fields: ["fields"]
2013
+ field: PLURAL_MODEL_ENTITIES[entity]
2005
2014
  });
2006
2015
  }
2007
2016
  const columns = index.fields.map((field2) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.18.4",
3
+ "version": "0.18.5-json-experimental-444",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {