@ronin/compiler 0.10.2-leo-ron-1083-experimental-212 → 0.10.2-leo-ron-1083-experimental-213

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/README.md CHANGED
@@ -70,6 +70,24 @@ executed and their results can be formatted by the compiler as well:
70
70
  const results: Array<Result> = transaction.prepareResults(rows);
71
71
  ```
72
72
 
73
+ #### Root Model
74
+
75
+ Before you can run any statements generated by the compiler that are altering the database schema, you need to create the table of the so-called "root model", which is used to store metadata for all other models.
76
+
77
+ This table is called `ronin_master`, which mimics the default `sqlite_master` table provided by SQLite. You can generate its respective SQL statements like so:
78
+
79
+ ```typescript
80
+ import { Transaction, ROOT_MODEL } from '@ronin/compiler';
81
+
82
+ const transaction = new Transaction([
83
+ {
84
+ create: { model: ROOT_MODEL }
85
+ }
86
+ ]);
87
+ ```
88
+
89
+ Afterward, run the statements located in `transaction.statements` to create the table for the root model. Once that is done, your database is prepared to run any statements generated by the compiler.
90
+
73
91
  #### Types
74
92
 
75
93
  In total, the following types are being exported:
@@ -135,7 +153,7 @@ bun run dev
135
153
 
136
154
  Whenever you make a change to the source code, it will then automatically be transpiled again.
137
155
 
138
- ### Mental Model
156
+ ### Architecture
139
157
 
140
158
  The interface of creating new `Transaction` instances (thereby creating new transactions) was chosen in order to define the smallest workload unit that the compiler can operate on.
141
159
 
package/dist/index.d.ts CHANGED
@@ -5979,7 +5979,7 @@ interface Model<T extends Array<ModelField> = Array<ModelField>> {
5979
5979
  triggers?: Array<ModelTrigger<T>>;
5980
5980
  presets?: Array<ModelPreset>;
5981
5981
  }
5982
- type PublicModel<T extends Array<ModelField> = Array<ModelField>> = Omit<Partial<Model<T>>, 'slug' | 'identifiers' | 'system' | 'table' | 'tableAlias'> & {
5982
+ type PublicModel<T extends Array<ModelField> = Array<ModelField>> = Omit<Partial<Model<T>>, 'slug' | 'identifiers' | 'system' | 'tableAlias'> & {
5983
5983
  slug: Required<Model['slug']>;
5984
5984
  identifiers?: Partial<Model['identifiers']>;
5985
5985
  };
@@ -6035,4 +6035,6 @@ declare class Transaction {
6035
6035
  prepareResults(results: Array<Array<Row>>): Array<Result>;
6036
6036
  }
6037
6037
 
6038
- export { type PublicModel as Model, type ModelField, type ModelIndex, type ModelPreset, type ModelTrigger, type Query, type Result, type Statement, Transaction };
6038
+ declare const CLEAN_ROOT_MODEL: PublicModel;
6039
+
6040
+ export { type PublicModel as Model, type ModelField, type ModelIndex, type ModelPreset, type ModelTrigger, type Query, CLEAN_ROOT_MODEL as ROOT_MODEL, type Result, type Statement, Transaction };
package/dist/index.js CHANGED
@@ -93,6 +93,9 @@ var flatten = (obj, prefix = "", res = {}) => {
93
93
  }
94
94
  return res;
95
95
  };
96
+ var omit = (obj, properties) => Object.fromEntries(
97
+ Object.entries(obj).filter(([key]) => !properties.includes(key))
98
+ );
96
99
  var expand = (obj) => {
97
100
  return Object.entries(obj).reduce((res, [key, val]) => {
98
101
  key.split(".").reduce((acc, part, i, arr) => {
@@ -693,7 +696,7 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
693
696
  if (!(modelSlug && slug)) return query;
694
697
  const model = action === "create" && entity === "model" ? null : getModelBySlug(models, modelSlug);
695
698
  if (entity === "model") {
696
- let queryTypeDetails;
699
+ let queryTypeDetails = {};
697
700
  if (action === "create") {
698
701
  const newModel = jsonValue;
699
702
  const modelWithFields = addDefaultModelFields(newModel, true);
@@ -749,6 +752,8 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
749
752
  return handleSystemModel(models, dependencyStatements, "drop", systemModel);
750
753
  });
751
754
  }
755
+ const modelSlug2 = "to" in queryTypeDetails ? queryTypeDetails?.to?.slug : "with" in queryTypeDetails ? queryTypeDetails?.with?.slug : void 0;
756
+ if (modelSlug2 === "model") return null;
752
757
  const queryTypeAction = action === "create" ? "add" : action === "alter" ? "set" : "remove";
753
758
  return {
754
759
  [queryTypeAction]: {
@@ -1340,6 +1345,7 @@ var compileQueryInput = (defaultQuery, models, statementParams, options) => {
1340
1345
  statementParams,
1341
1346
  defaultQuery
1342
1347
  );
1348
+ if (query === null) return { dependencies: [], main: dependencyStatements[0] };
1343
1349
  const parsedQuery = splitQuery(query);
1344
1350
  const { queryType, queryModel, queryInstructions } = parsedQuery;
1345
1351
  const model = getModelBySlug(models, queryModel);
@@ -1577,6 +1583,8 @@ var Transaction = class {
1577
1583
  });
1578
1584
  }
1579
1585
  };
1586
+ var CLEAN_ROOT_MODEL = omit(ROOT_MODEL, ["system"]);
1580
1587
  export {
1588
+ CLEAN_ROOT_MODEL as ROOT_MODEL,
1581
1589
  Transaction
1582
1590
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.10.2-leo-ron-1083-experimental-212",
3
+ "version": "0.10.2-leo-ron-1083-experimental-213",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {