@ronin/compiler 0.13.4 → 0.13.5

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
@@ -147,6 +147,7 @@ interface Statement {
147
147
  }
148
148
 
149
149
  type ModelFieldCollation = 'BINARY' | 'NOCASE' | 'RTRIM';
150
+ type ModelFieldLinkAction = 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'SET DEFAULT' | 'NO ACTION';
150
151
  type ModelFieldBasics = {
151
152
  /** The label that should be used when displaying the field on the RONIN dashboard. */
152
153
  name?: string;
@@ -180,31 +181,37 @@ type ModelFieldBasics = {
180
181
  };
181
182
  /** An expression that gets evaluated every time a value is provided for the field. */
182
183
  check?: Expression;
183
- /**
184
- * If the field is of type `string`, setting this attribute defines the collation
185
- * sequence to use for the field value.
186
- */
184
+ };
185
+ type ModelField = (ModelFieldBasics & {
186
+ /** The kind of value that should be stored inside the field. */
187
+ type?: 'boolean' | 'date' | 'json';
188
+ }) | (ModelFieldBasics & {
189
+ /** The kind of value that should be stored inside the field. */
190
+ type?: 'string';
191
+ /** The collation sequence to use for the field value. */
187
192
  collation?: ModelFieldCollation;
193
+ }) | (ModelFieldBasics & {
194
+ /** The kind of value that should be stored inside the field. */
195
+ type?: 'number';
188
196
  /**
189
- * If the field is of type `number`, setting this attribute will automatically increment
190
- * the value of the field with every new record that gets inserted.
197
+ * Automatically increments the value of the field with every new inserted record.
191
198
  */
192
199
  increment?: boolean;
193
- };
194
- type ModelFieldNormal = ModelFieldBasics & {
195
- type?: 'string' | 'number' | 'boolean' | 'date' | 'json';
196
- };
197
- type ModelFieldReferenceAction = 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'SET DEFAULT' | 'NO ACTION';
198
- type ModelFieldReference = ModelFieldBasics & {
199
- type: 'link';
200
+ }) | (ModelFieldBasics & {
201
+ /** The kind of value that should be stored inside the field. */
202
+ type?: 'link';
203
+ /** The target model of the relationship that is being established. */
200
204
  target: string;
205
+ /** Whether the field should be related to one record, or many records. */
201
206
  kind?: 'one' | 'many';
207
+ /**
208
+ * If the target record is updated or deleted, the defined actions maybe executed.
209
+ */
202
210
  actions?: {
203
- onDelete?: ModelFieldReferenceAction;
204
- onUpdate?: ModelFieldReferenceAction;
211
+ onDelete?: ModelFieldLinkAction;
212
+ onUpdate?: ModelFieldLinkAction;
205
213
  };
206
- };
207
- type ModelField = ModelFieldNormal | ModelFieldReference;
214
+ });
208
215
  type ModelIndexField<T extends Array<ModelField> = Array<ModelField>> = {
209
216
  /** The collating sequence used for text placed inside the field. */
210
217
  collation?: ModelFieldCollation;
package/dist/index.js CHANGED
@@ -840,8 +840,12 @@ var getFieldStatement = (models, model, field) => {
840
840
  if (symbol) value = `(${parseFieldExpression(model, "to", symbol.value)})`;
841
841
  statement += ` DEFAULT ${value}`;
842
842
  }
843
- if (field.collation) statement += ` COLLATE ${field.collation}`;
844
- if (field.increment === true) statement += " AUTOINCREMENT";
843
+ if (field.type === "string" && field.collation) {
844
+ statement += ` COLLATE ${field.collation}`;
845
+ }
846
+ if (field.type === "number" && field.increment === true) {
847
+ statement += " AUTOINCREMENT";
848
+ }
845
849
  if (typeof field.check !== "undefined") {
846
850
  const symbol = getSymbol(field.check);
847
851
  statement += ` CHECK (${parseFieldExpression(model, "to", symbol?.value)})`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.13.4",
3
+ "version": "0.13.5",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {