@ronin/compiler 0.14.1 → 0.14.2-leo-ron-1099-1-experimental-319
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 +17 -1
- package/dist/index.js +14 -18
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -36,6 +36,22 @@ declare class RoninError extends Error {
|
|
36
36
|
queries?: Details['queries'];
|
37
37
|
constructor(details: Details);
|
38
38
|
}
|
39
|
+
/**
|
40
|
+
* Checks if the provided value contains a RONIN model symbol (a represenation of a
|
41
|
+
* particular entity inside a query, such as an expression or a sub query) and returns
|
42
|
+
* its type and value.
|
43
|
+
*
|
44
|
+
* @param value - The value that should be checked.
|
45
|
+
*
|
46
|
+
* @returns The type and value of the symbol, if the provided value contains one.
|
47
|
+
*/
|
48
|
+
declare const getQuerySymbol: (value: unknown) => {
|
49
|
+
type: "query";
|
50
|
+
value: Query;
|
51
|
+
} | {
|
52
|
+
type: "expression";
|
53
|
+
value: string;
|
54
|
+
} | null;
|
39
55
|
|
40
56
|
type QueryTypeEnum = 'get' | 'set' | 'add' | 'remove' | 'count';
|
41
57
|
type ModelQueryTypeEnum = 'create' | 'alter' | 'drop';
|
@@ -378,4 +394,4 @@ declare class Transaction {
|
|
378
394
|
|
379
395
|
declare const CLEAN_ROOT_MODEL: PublicModel;
|
380
396
|
|
381
|
-
export { type AddInstructions, type AddQuery, type AddInstructions as AddQueryInstructions, type CombinedInstructions, type CountInstructions, type CountQuery, type CountInstructions as CountQueryInstructions, type GetInstructions, type GetQuery, type GetInstructions as GetQueryInstructions, type PublicModel as Model, type ModelField, type ModelIndex, type ModelPreset, type ModelTrigger, QUERY_SYMBOLS, type Query, type QueryInstructionType as QueryInstruction, type QuerySchemaType, type QueryType, CLEAN_ROOT_MODEL as ROOT_MODEL, type RemoveInstructions, type RemoveQuery, type RemoveInstructions as RemoveQueryInstructions, type Result, RoninError, type SetInstructions, type SetQuery, type SetInstructions as SetQueryInstructions, type Statement, Transaction, type WithInstruction };
|
397
|
+
export { type AddInstructions, type AddQuery, type AddInstructions as AddQueryInstructions, type CombinedInstructions, type CountInstructions, type CountQuery, type CountInstructions as CountQueryInstructions, type GetInstructions, type GetQuery, type GetInstructions as GetQueryInstructions, type PublicModel as Model, type ModelField, type ModelIndex, type ModelPreset, type ModelTrigger, QUERY_SYMBOLS, type Query, type QueryInstructionType as QueryInstruction, type QuerySchemaType, type QueryType, CLEAN_ROOT_MODEL as ROOT_MODEL, type RemoveInstructions, type RemoveQuery, type RemoveInstructions as RemoveQueryInstructions, type Result, RoninError, type SetInstructions, type SetQuery, type SetInstructions as SetQueryInstructions, type Statement, Transaction, type WithInstruction, getQuerySymbol };
|
package/dist/index.js
CHANGED
@@ -70,7 +70,7 @@ var convertToCamelCase = (str) => {
|
|
70
70
|
return sanitize(str).split(SPLIT_REGEX).map((part, index) => index === 0 ? part.toLowerCase() : capitalize(part)).join("");
|
71
71
|
};
|
72
72
|
var isObject = (value) => value != null && typeof value === "object" && Array.isArray(value) === false;
|
73
|
-
var
|
73
|
+
var getQuerySymbol = (value) => {
|
74
74
|
if (!isObject(value)) return null;
|
75
75
|
const objectValue = value;
|
76
76
|
if (QUERY_SYMBOLS.QUERY in objectValue) {
|
@@ -110,7 +110,7 @@ var flatten = (obj, prefix = "", res = {}) => {
|
|
110
110
|
if (!Object.hasOwn(obj, key)) continue;
|
111
111
|
const path = prefix ? `${prefix}.${key}` : key;
|
112
112
|
const value = obj[key];
|
113
|
-
if (typeof value === "object" && value !== null && !
|
113
|
+
if (typeof value === "object" && value !== null && !getQuerySymbol(value)) {
|
114
114
|
flatten(value, path, res);
|
115
115
|
} else {
|
116
116
|
res[path] = value;
|
@@ -304,7 +304,7 @@ var handleIncluding = (models, model, statementParams, single, instruction) => {
|
|
304
304
|
let tableSubQuery;
|
305
305
|
for (const ephemeralFieldSlug in instruction) {
|
306
306
|
if (!Object.hasOwn(instruction, ephemeralFieldSlug)) continue;
|
307
|
-
const symbol =
|
307
|
+
const symbol = getQuerySymbol(instruction[ephemeralFieldSlug]);
|
308
308
|
if (symbol?.type !== "query") continue;
|
309
309
|
const { queryType, queryModel, queryInstructions } = splitQuery(symbol.value);
|
310
310
|
let modifiableQueryInstructions = queryInstructions;
|
@@ -383,7 +383,7 @@ var handleOrderedBy = (model, instruction) => {
|
|
383
383
|
if (statement.length > 0) {
|
384
384
|
statement += ", ";
|
385
385
|
}
|
386
|
-
const symbol =
|
386
|
+
const symbol = getQuerySymbol(item.value);
|
387
387
|
const instructionName = item.order === "ASC" ? "orderedBy.ascending" : "orderedBy.descending";
|
388
388
|
if (symbol?.type === "expression") {
|
389
389
|
statement += `(${parseFieldExpression(model, instructionName, symbol.value)}) ${item.order}`;
|
@@ -419,14 +419,14 @@ var handleSelecting = (models, model, statementParams, single, instructions, opt
|
|
419
419
|
const joinedSelectedFields = [];
|
420
420
|
const joinedColumns = [];
|
421
421
|
if (instructions.including) {
|
422
|
-
const symbol =
|
422
|
+
const symbol = getQuerySymbol(instructions.including);
|
423
423
|
if (symbol?.type === "query") {
|
424
424
|
instructions.including.ronin_root = { ...instructions.including };
|
425
425
|
delete instructions.including[QUERY_SYMBOLS.QUERY];
|
426
426
|
}
|
427
427
|
const flatObject = flatten(instructions.including);
|
428
428
|
for (const [key, value] of Object.entries(flatObject)) {
|
429
|
-
const symbol2 =
|
429
|
+
const symbol2 = getQuerySymbol(value);
|
430
430
|
if (symbol2?.type === "query") {
|
431
431
|
const { queryModel, queryInstructions } = splitQuery(symbol2.value);
|
432
432
|
const subQueryModel = getModelBySlug(models, queryModel);
|
@@ -504,15 +504,10 @@ var handleTo = (models, model, statementParams, queryType, dependencyStatements,
|
|
504
504
|
...toInstruction.ronin
|
505
505
|
};
|
506
506
|
}
|
507
|
-
const symbol =
|
507
|
+
const symbol = getQuerySymbol(toInstruction);
|
508
508
|
if (symbol?.type === "query") {
|
509
509
|
const { queryModel: subQueryModelSlug, queryInstructions: subQueryInstructions } = splitQuery(symbol.value);
|
510
510
|
const subQueryModel = getModelBySlug(models, subQueryModelSlug);
|
511
|
-
if (subQueryInstructions?.selecting) {
|
512
|
-
const currentFields = new Set(subQueryInstructions.selecting);
|
513
|
-
currentFields.add("id");
|
514
|
-
subQueryInstructions.selecting = Array.from(currentFields);
|
515
|
-
}
|
516
511
|
const subQuerySelectedFields = subQueryInstructions?.selecting;
|
517
512
|
const subQueryIncludedFields = subQueryInstructions?.including;
|
518
513
|
const subQueryFields = [
|
@@ -802,7 +797,7 @@ var composeFieldValues = (models, model, statementParams, instructionName, value
|
|
802
797
|
{ instructionName }
|
803
798
|
);
|
804
799
|
const collectStatementValue = options.type !== "fields";
|
805
|
-
const symbol =
|
800
|
+
const symbol = getQuerySymbol(value);
|
806
801
|
let conditionMatcher = "=";
|
807
802
|
let conditionValue = value;
|
808
803
|
if (options.condition) {
|
@@ -848,7 +843,7 @@ var composeConditions = (models, model, statementParams, instructionName, value,
|
|
848
843
|
});
|
849
844
|
const { field: modelField } = fieldDetails || {};
|
850
845
|
const consumeJSON = modelField?.type === "json" && instructionName === "to";
|
851
|
-
if (modelField && !(isObject(value) || Array.isArray(value)) ||
|
846
|
+
if (modelField && !(isObject(value) || Array.isArray(value)) || getQuerySymbol(value) || consumeJSON) {
|
852
847
|
return composeFieldValues(
|
853
848
|
models,
|
854
849
|
model,
|
@@ -1507,7 +1502,7 @@ var getFieldStatement = (models, model, field) => {
|
|
1507
1502
|
if (field.unique === true) statement += " UNIQUE";
|
1508
1503
|
if (field.required === true) statement += " NOT NULL";
|
1509
1504
|
if (typeof field.defaultValue !== "undefined") {
|
1510
|
-
const symbol =
|
1505
|
+
const symbol = getQuerySymbol(field.defaultValue);
|
1511
1506
|
let value = typeof field.defaultValue === "string" ? `'${field.defaultValue}'` : field.defaultValue;
|
1512
1507
|
if (symbol) value = `(${parseFieldExpression(model, "to", symbol.value)})`;
|
1513
1508
|
statement += ` DEFAULT ${value}`;
|
@@ -1519,12 +1514,12 @@ var getFieldStatement = (models, model, field) => {
|
|
1519
1514
|
statement += " AUTOINCREMENT";
|
1520
1515
|
}
|
1521
1516
|
if (typeof field.check !== "undefined") {
|
1522
|
-
const symbol =
|
1517
|
+
const symbol = getQuerySymbol(field.check);
|
1523
1518
|
statement += ` CHECK (${parseFieldExpression(model, "to", symbol?.value)})`;
|
1524
1519
|
}
|
1525
1520
|
if (typeof field.computedAs !== "undefined") {
|
1526
1521
|
const { kind, value } = field.computedAs;
|
1527
|
-
const symbol =
|
1522
|
+
const symbol = getQuerySymbol(value);
|
1528
1523
|
statement += ` GENERATED ALWAYS AS (${parseFieldExpression(model, "to", symbol?.value)}) ${kind}`;
|
1529
1524
|
}
|
1530
1525
|
if (field.type === "link") {
|
@@ -2090,5 +2085,6 @@ export {
|
|
2090
2085
|
QUERY_SYMBOLS,
|
2091
2086
|
CLEAN_ROOT_MODEL as ROOT_MODEL,
|
2092
2087
|
RoninError,
|
2093
|
-
Transaction
|
2088
|
+
Transaction,
|
2089
|
+
getQuerySymbol
|
2094
2090
|
};
|