@ronin/compiler 0.13.0 → 0.13.1-leo-ron-1071-experimental-279

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/LICENSE CHANGED
@@ -186,7 +186,7 @@
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright 2024 Ronin GmbH
189
+ Copyright 2025 Ronin GmbH
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
package/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # RONIN Compiler
2
2
 
3
- [![Tests](https://github.com/ronin-co/compiler/actions/workflows/validate.yml/badge.svg)](https://github.com/ronin-co/compiler/actions/workflows/validate.yml)
4
- [![Install Size](https://packagephobia.com/badge?p=@ronin/compiler)](https://packagephobia.com/result?p=@ronin/compiler)
3
+ [![tests](https://img.shields.io/github/actions/workflow/status/ronin-co/compiler/validate.yml?label=tests)](https://github.com/ronin-co/compiler/actions/workflows/validate.yml)
4
+ [![code coverage](https://img.shields.io/codecov/c/github/ronin-co/compiler)](https://codecov.io/github/ronin-co/compiler)
5
+ [![install size](https://packagephobia.com/badge?p=@ronin/compiler)](https://packagephobia.com/result?p=@ronin/compiler)
5
6
 
6
7
  This package compiles [RONIN queries](https://ronin.co/docs/queries) to [SQLite](https://www.sqlite.org) statements.
7
8
 
package/dist/index.js CHANGED
@@ -676,7 +676,12 @@ var RONIN_MODEL_FIELD_REGEX = new RegExp(
676
676
  "g"
677
677
  );
678
678
  var RAW_FIELD_TYPES = ["string", "number", "boolean"];
679
- var composeIncludedTableAlias = (fieldSlug) => `including_${fieldSlug}`;
679
+ var CURRENT_TIME_EXPRESSION = {
680
+ [QUERY_SYMBOLS.EXPRESSION]: `strftime('%Y-%m-%dT%H:%M:%f', 'now') || 'Z'`
681
+ };
682
+ var composeIncludedTableAlias = (fieldSlug) => {
683
+ return `including_${fieldSlug}`;
684
+ };
680
685
  var MODEL_ENTITY_ERROR_CODES = {
681
686
  field: "FIELD_NOT_FOUND",
682
687
  index: "INDEX_NOT_FOUND",
@@ -742,6 +747,7 @@ var getSymbol = (value) => {
742
747
  var findInObject = (obj, pattern, replacer) => {
743
748
  let found = false;
744
749
  for (const key in obj) {
750
+ if (!Object.hasOwn(obj, key)) continue;
745
751
  const value = obj[key];
746
752
  if (isObject(value)) {
747
753
  found = findInObject(value, pattern, replacer);
@@ -758,6 +764,7 @@ var findInObject = (obj, pattern, replacer) => {
758
764
  };
759
765
  var flatten = (obj, prefix = "", res = {}) => {
760
766
  for (const key in obj) {
767
+ if (!Object.hasOwn(obj, key)) continue;
761
768
  const path = prefix ? `${prefix}.${key}` : key;
762
769
  const value = obj[key];
763
770
  if (typeof value === "object" && value !== null && !getSymbol(value)) {
@@ -1329,7 +1336,8 @@ var SYSTEM_FIELDS = [
1329
1336
  {
1330
1337
  name: "RONIN - Created At",
1331
1338
  type: "date",
1332
- slug: "ronin.createdAt"
1339
+ slug: "ronin.createdAt",
1340
+ defaultValue: CURRENT_TIME_EXPRESSION
1333
1341
  },
1334
1342
  {
1335
1343
  name: "RONIN - Created By",
@@ -1339,7 +1347,8 @@ var SYSTEM_FIELDS = [
1339
1347
  {
1340
1348
  name: "RONIN - Updated At",
1341
1349
  type: "date",
1342
- slug: "ronin.updatedAt"
1350
+ slug: "ronin.updatedAt",
1351
+ defaultValue: CURRENT_TIME_EXPRESSION
1343
1352
  },
1344
1353
  {
1345
1354
  name: "RONIN - Updated By",
@@ -1489,8 +1498,12 @@ var getFieldStatement = (models, model, field) => {
1489
1498
  if (field.slug === "id") statement += " PRIMARY KEY";
1490
1499
  if (field.unique === true) statement += " UNIQUE";
1491
1500
  if (field.required === true) statement += " NOT NULL";
1492
- if (typeof field.defaultValue !== "undefined")
1493
- statement += ` DEFAULT ${typeof field.defaultValue === "string" ? `'${field.defaultValue}'` : field.defaultValue}`;
1501
+ if (typeof field.defaultValue !== "undefined") {
1502
+ const symbol = getSymbol(field.defaultValue);
1503
+ let value = typeof field.defaultValue === "string" ? `'${field.defaultValue}'` : field.defaultValue;
1504
+ if (symbol) value = `(${parseFieldExpression(model, "to", symbol.value)})`;
1505
+ statement += ` DEFAULT ${value}`;
1506
+ }
1494
1507
  if (field.collation) statement += ` COLLATE ${field.collation}`;
1495
1508
  if (field.increment === true) statement += " AUTOINCREMENT";
1496
1509
  if (typeof field.check !== "undefined") {
@@ -1509,6 +1522,7 @@ var getFieldStatement = (models, model, field) => {
1509
1522
  const targetTable = getModelBySlug(modelList, field.target).table;
1510
1523
  statement += ` REFERENCES ${targetTable}("id")`;
1511
1524
  for (const trigger in actions) {
1525
+ if (!Object.hasOwn(actions, trigger)) continue;
1512
1526
  const triggerName = trigger.toUpperCase().slice(2);
1513
1527
  const action = actions[trigger];
1514
1528
  statement += ` ON ${triggerName} ${action}`;
@@ -1601,7 +1615,8 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
1601
1615
  models.push(modelWithPresets);
1602
1616
  const modelWithObjects = Object.assign({}, modelWithPresets);
1603
1617
  for (const entity2 in entities) {
1604
- if (entities[entity2]) modelWithObjects[entity2] = entities[entity2];
1618
+ if (!Object.hasOwn(entities, entity2)) continue;
1619
+ Object.defineProperty(modelWithObjects, entity2, { value: entities[entity2] });
1605
1620
  }
1606
1621
  queryTypeDetails = { to: modelWithObjects };
1607
1622
  getSystemModels(models, modelWithPresets).map((systemModel) => {
@@ -1935,6 +1950,7 @@ var handleBeforeOrAfter = (model, statementParams, instructions) => {
1935
1950
  var handleFor = (model, instructions) => {
1936
1951
  const normalizedFor = Array.isArray(instructions.for) ? Object.fromEntries(instructions.for.map((presetSlug) => [presetSlug, null])) : instructions.for;
1937
1952
  for (const presetSlug in normalizedFor) {
1953
+ if (!Object.hasOwn(normalizedFor, presetSlug)) continue;
1938
1954
  const arg = normalizedFor[presetSlug];
1939
1955
  const preset = model.presets?.find((preset2) => preset2.slug === presetSlug);
1940
1956
  if (!preset) {
@@ -1952,6 +1968,7 @@ var handleFor = (model, instructions) => {
1952
1968
  );
1953
1969
  }
1954
1970
  for (const subInstruction in replacedForFilter) {
1971
+ if (!Object.hasOwn(replacedForFilter, subInstruction)) continue;
1955
1972
  const instructionName = subInstruction;
1956
1973
  const currentValue = instructions[instructionName];
1957
1974
  if (currentValue) {
@@ -1983,6 +2000,7 @@ var handleIncluding = (models, model, statementParams, instruction) => {
1983
2000
  let statement = "";
1984
2001
  let tableSubQuery;
1985
2002
  for (const ephemeralFieldSlug in instruction) {
2003
+ if (!Object.hasOwn(instruction, ephemeralFieldSlug)) continue;
1986
2004
  const symbol = getSymbol(instruction[ephemeralFieldSlug]);
1987
2005
  if (symbol?.type !== "query") continue;
1988
2006
  const { queryType, queryModel, queryInstructions } = splitQuery(symbol.value);
@@ -2155,20 +2173,19 @@ var handleSelecting = (models, model, statementParams, instructions, options) =>
2155
2173
 
2156
2174
  // src/instructions/to.ts
2157
2175
  var handleTo = (models, model, statementParams, queryType, dependencyStatements, instructions, parentModel) => {
2158
- const currentTime = (/* @__PURE__ */ new Date()).toISOString();
2159
2176
  const { with: withInstruction, to: toInstruction } = instructions;
2160
2177
  const defaultFields = {};
2161
2178
  if (queryType === "add") {
2162
2179
  defaultFields.id = toInstruction.id || generateRecordId(model.idPrefix);
2163
2180
  }
2164
- defaultFields.ronin = {
2165
- // If records are being created, set their creation time.
2166
- ...queryType === "add" ? { createdAt: currentTime } : {},
2167
- // If records are being created or updated, set their update time.
2168
- updatedAt: currentTime,
2169
- // Allow for overwriting the default values provided above.
2170
- ...toInstruction.ronin
2171
- };
2181
+ if (queryType === "set" || toInstruction.ronin) {
2182
+ defaultFields.ronin = {
2183
+ // If records are being updated, bump their update time.
2184
+ ...queryType === "set" ? { updatedAt: CURRENT_TIME_EXPRESSION } : {},
2185
+ // Allow for overwriting the default values provided above.
2186
+ ...toInstruction.ronin
2187
+ };
2188
+ }
2172
2189
  const symbol = getSymbol(toInstruction);
2173
2190
  if (symbol?.type === "query") {
2174
2191
  let { queryModel: subQueryModelSlug, queryInstructions: subQueryInstructions } = splitQuery(symbol.value);
@@ -2216,6 +2233,7 @@ var handleTo = (models, model, statementParams, queryType, dependencyStatements,
2216
2233
  }
2217
2234
  Object.assign(toInstruction, defaultFields);
2218
2235
  for (const fieldSlug in toInstruction) {
2236
+ if (!Object.hasOwn(toInstruction, fieldSlug)) continue;
2219
2237
  const fieldValue = toInstruction[fieldSlug];
2220
2238
  const fieldDetails = getFieldFromModel(model, fieldSlug, "to", false);
2221
2239
  if (fieldDetails?.field.type === "link" && fieldDetails.field.kind === "many") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.13.0",
3
+ "version": "0.13.1-leo-ron-1071-experimental-279",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {
@@ -13,7 +13,7 @@
13
13
  ],
14
14
  "scripts": {
15
15
  "lint": "bun run --bun lint:tsc && bun run --bun lint:biome",
16
- "lint:biome": "biome check",
16
+ "lint:biome": "biome check --error-on-warnings",
17
17
  "lint:tsc": "tsc --pretty",
18
18
  "format": "biome check --write && biome format --write",
19
19
  "test": "bun test",