@ronin/compiler
Advanced tools
Comparing version 0.7.0 to 0.7.1-leo-ron-1083-4-experimental-121
@@ -190,3 +190,3 @@ // src/utils/helpers.ts | ||
} | ||
if (modelField.type === "reference" && isNested) { | ||
if (modelField.type === "link" && isNested) { | ||
const keys = Object.keys(value); | ||
@@ -494,3 +494,3 @@ const values = Object.values(value); | ||
slug: "model", | ||
type: "reference", | ||
type: "link", | ||
target: { slug: "model" }, | ||
@@ -503,4 +503,4 @@ required: true | ||
{ slug: "autoIncrement", type: "boolean" }, | ||
// Only allowed for fields of type "reference". | ||
{ slug: "target", type: "reference", target: { slug: "model" } }, | ||
// Only allowed for fields of type "link". | ||
{ slug: "target", type: "link", target: { slug: "model" } }, | ||
{ slug: "kind", type: "string" }, | ||
@@ -522,3 +522,3 @@ { slug: "actions", type: "group" }, | ||
slug: "model", | ||
type: "reference", | ||
type: "link", | ||
target: { slug: "model" }, | ||
@@ -542,3 +542,3 @@ required: true | ||
slug: "model", | ||
type: "reference", | ||
type: "link", | ||
target: { slug: "model" }, | ||
@@ -560,3 +560,3 @@ required: true | ||
slug: "model", | ||
type: "reference", | ||
type: "link", | ||
target: { slug: "model" }, | ||
@@ -577,3 +577,3 @@ required: true | ||
for (const field of model.fields || []) { | ||
if (field.type === "reference" && !field.slug.startsWith("ronin.")) { | ||
if (field.type === "link" && !field.slug.startsWith("ronin.")) { | ||
const relatedModel = getModelBySlug(models, field.target.slug); | ||
@@ -590,3 +590,3 @@ let fieldSlug = relatedModel.slug; | ||
slug: "source", | ||
type: "reference", | ||
type: "link", | ||
target: { slug: model.slug } | ||
@@ -596,3 +596,3 @@ }, | ||
slug: "target", | ||
type: "reference", | ||
type: "link", | ||
target: { slug: relatedModel.slug } | ||
@@ -612,3 +612,3 @@ } | ||
for (const field of model.fields || []) { | ||
if (field.type === "reference" && !field.slug.startsWith("ronin.")) { | ||
if (field.type === "link" && !field.slug.startsWith("ronin.")) { | ||
const relatedModel = getModelBySlug(list, field.target.slug); | ||
@@ -624,3 +624,3 @@ if (field.kind === "many") continue; | ||
with: { | ||
// Compare the `id` field of the related model to the reference field on | ||
// Compare the `id` field of the related model to the link field on | ||
// the root model (`field.slug`). | ||
@@ -643,3 +643,3 @@ id: { | ||
const field = subModel.fields?.find((field2) => { | ||
return field2.type === "reference" && field2.target.slug === model.slug; | ||
return field2.type === "link" && field2.target.slug === model.slug; | ||
}); | ||
@@ -685,3 +685,3 @@ if (!field) return null; | ||
var typesInSQLite = { | ||
reference: "TEXT", | ||
link: "TEXT", | ||
string: "TEXT", | ||
@@ -694,3 +694,3 @@ date: "DATETIME", | ||
}; | ||
var getFieldStatement = (field) => { | ||
var getFieldStatement = (model, field) => { | ||
if (field.type === "group") return null; | ||
@@ -703,3 +703,7 @@ let statement = `"${field.slug}" ${typesInSQLite[field.type]}`; | ||
statement += ` DEFAULT ${field.defaultValue}`; | ||
if (field.type === "reference") { | ||
if (typeof field.check !== "undefined") { | ||
const symbol = getSymbol(field.check); | ||
statement += ` CHECK (${parseFieldExpression(model, "to", symbol?.value)})`; | ||
} | ||
if (field.type === "link") { | ||
const actions = field.actions || {}; | ||
@@ -864,4 +868,5 @@ const targetTable = convertToSnakeCase(pluralize(field.target.slug)); | ||
if (queryType === "create") { | ||
const { fields } = queryInstructions.to; | ||
const columns = fields.map(getFieldStatement).filter(Boolean); | ||
const newModel = queryInstructions.to; | ||
const { fields } = newModel; | ||
const columns = fields.map((field) => getFieldStatement(newModel, field)).filter(Boolean); | ||
dependencyStatements.push({ | ||
@@ -871,3 +876,3 @@ statement: `${statement} (${columns.join(", ")})`, | ||
}); | ||
models.push(queryInstructions.to); | ||
models.push(newModel); | ||
} else if (queryType === "set") { | ||
@@ -899,3 +904,3 @@ const newSlug = queryInstructions.to?.pluralSlug; | ||
dependencyStatements.push({ | ||
statement: `${statement} ADD COLUMN ${getFieldStatement(instructionList)}`, | ||
statement: `${statement} ADD COLUMN ${getFieldStatement(targetModel, instructionList)}`, | ||
params: [] | ||
@@ -1148,8 +1153,15 @@ }); | ||
if (instructions.including) { | ||
const filteredObject = Object.entries(instructions.including).filter(([_, value]) => { | ||
const filteredObject = Object.entries(instructions.including).map(([key, value]) => { | ||
const symbol = getSymbol(value); | ||
const hasQuery = symbol?.type === "query"; | ||
if (hasQuery) isJoining = true; | ||
return !hasQuery; | ||
}); | ||
if (symbol) { | ||
if (symbol.type === "query") { | ||
isJoining = true; | ||
return null; | ||
} | ||
if (symbol.type === "expression") { | ||
value = parseFieldExpression(model, "including", symbol.value); | ||
} | ||
} | ||
return [key, value]; | ||
}).filter((entry) => entry !== null); | ||
const newObjectEntries = Object.entries(flatten(Object.fromEntries(filteredObject))); | ||
@@ -1159,2 +1171,4 @@ if (newObjectEntries.length > 0) { | ||
statement += newObjectEntries.map(([key, value]) => { | ||
if (typeof value === "string" && value.startsWith('"')) | ||
return `(${value}) as "${key}"`; | ||
return `${prepareStatementValue(statementParams, value)} as "${key}"`; | ||
@@ -1215,3 +1229,3 @@ }).join(", "); | ||
const fieldDetails = getFieldFromModel(model, fieldSlug, "to"); | ||
if (fieldDetails.field.type === "reference" && fieldDetails.field.kind === "many") { | ||
if (fieldDetails.field.type === "link" && fieldDetails.field.kind === "many") { | ||
delete toInstruction[fieldSlug]; | ||
@@ -1218,0 +1232,0 @@ const associativeModelSlug = composeAssociationModelSlug(model, fieldDetails.field); |
{ | ||
"name": "@ronin/compiler", | ||
"version": "0.7.0", | ||
"version": "0.7.1-leo-ron-1083-4-experimental-121", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "description": "Compiles RONIN queries to SQL statements.", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unpublished package
Supply chain riskPackage version was not found on the registry. It may exist on a different registry and need to be configured to pull from that registry.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unpopular package
QualityThis package is not very popular.
Found 1 instance in 1 package
436258
7247
0
1