@elyx-code/project-logic-tree 0.0.6279 → 0.0.6281

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.
@@ -30,6 +30,7 @@ export interface UUIDModule {
30
30
  fromUUID: (uuid: string) => string;
31
31
  }
32
32
  export declare enum ProjectStateEvents {
33
+ PROJECT_INITIALIZED = "project-initialized",
33
34
  DEFINITION_ENTITY_ADDED = "definition-entity-added",
34
35
  DEFINITION_ENTITY_REMOVED = "definition-entity-removed",
35
36
  DEFINITION_ENTITY_UPDATED = "definition-entity-updated",
@@ -162,7 +163,7 @@ export declare class ProjectState extends CombinedVersionedEvents implements IPr
162
163
  recursiveCaptureUpstreamVersions(_sharedTimestamp: null | string): IChangeSet<ProjectState>;
163
164
  restoreVersion(versionId: EntityVersion): Promise<IChangeSet<ProjectState>>;
164
165
  hydrateAncestors(): IChangeSet<ProjectState>;
165
- afterAllChildrenInitialized(_changeSet?: ChangeSet | null): IChangeSet<ProjectState>;
166
+ afterAllChildrenInitialized(changeSet?: ChangeSet | null): IChangeSet<ProjectState>;
166
167
  addSelfToProject(_changeSet: ChangeSet | null): IChangeSet<ProjectState>;
167
168
  get instancesList(): EntityState[];
168
169
  isOperationDeclaration(entity: ActionDescriptorState): boolean;
@@ -1,2 +1,5 @@
1
1
  export * from './search';
2
2
  export * as searchValidation from './validation/logic-validation';
3
+ export * as searchStatementUtils from './query/hydrate';
4
+ export * as searchStatementState from './query/search-statement-state';
5
+ export * as SQLAST from 'sql-parser-cst';
@@ -0,0 +1,113 @@
1
+ import { SelectStmt, Program, FromClause, TablesampleExpr, JoinExpr, LimitClause, OrderByClause, Keyword, PivotExpr, UnpivotExpr, ForSystemTimeAsOfExpr, TableFactor, SelectClause, WhereClause, Expr, PostgresqlOperatorExpr, BinaryExpr, Program as SQLAST } from 'sql-parser-cst';
2
+ import { AggregationStatement, AggregationStatementType, ColumnRef, SearchStatementState, SortStatement, WhereStatement, WhereStatementOperator } from './search-statement-state';
3
+ import { ProjectState } from '../../project';
4
+ import { DefinitionEntityState } from '../../definition-entity';
5
+ import { SearchState } from '../search';
6
+ import { PropertyState } from '../../property';
7
+
8
+ export declare const FORBIDDEN_SQL_KEYWORDS: string[];
9
+ export interface IShallowColumnMapping {
10
+ from: string;
11
+ to: string;
12
+ }
13
+ export interface IColumnMapping {
14
+ as: string;
15
+ column: {
16
+ columnName: string;
17
+ property: PropertyState | null;
18
+ };
19
+ }
20
+ export interface Table {
21
+ entity: DefinitionEntityState;
22
+ columns: {
23
+ columnName: string;
24
+ property: PropertyState | null;
25
+ }[];
26
+ }
27
+ type SupportedOperators = string | PostgresqlOperatorExpr | Keyword<'IS'> | [Keyword<'IS'>, Keyword<'NOT'>] | [Keyword<'IS'>, Keyword<'DISTINCT'>, Keyword<'FROM'>] | [Keyword<'IS'>, Keyword<'NOT'>, Keyword<'DISTINCT'>, Keyword<'FROM'>] | Keyword<'IN'> | [Keyword<'NOT'>, Keyword<'IN'>] | Keyword<'LIKE' | 'RLIKE' | 'ILIKE' | 'GLOB' | 'MATCH'> | [Keyword<'NOT'>, Keyword<'LIKE' | 'RLIKE' | 'ILIKE' | 'GLOB' | 'MATCH'>];
28
+ export declare function loadProjectDatasources(project: ProjectState): DefinitionEntityState[];
29
+ export declare function getSelectStatementFromProgram(program: Program): SelectStmt | null;
30
+ export declare function getFromClauseFromSelectStatement(selectStatement: SelectStmt): FromClause | null;
31
+ export declare function getNestedFromSubqueryFromSelectStatement(selectStatement: SelectStmt): {
32
+ selectStatement: SelectStmt;
33
+ as: string;
34
+ } | null;
35
+ export declare function getMainSourceNameFromFromClauseExpr(fromExpr: JoinExpr | PivotExpr | UnpivotExpr | TablesampleExpr | ForSystemTimeAsOfExpr | TableFactor, parentExpr?: JoinExpr): {
36
+ type: 'table';
37
+ name: string;
38
+ as: string;
39
+ } | null;
40
+ export declare function getMainSourceNameFromSelectStatement(selectStatement: SelectStmt): {
41
+ type: 'table';
42
+ name: string;
43
+ as: string;
44
+ } | null;
45
+ export declare function getMainSourceFromSelectStatement(selectStatement: SelectStmt): {
46
+ type: 'table';
47
+ name: string;
48
+ as: string;
49
+ } | {
50
+ type: 'query';
51
+ subquery: SelectStmt;
52
+ as: string;
53
+ } | null;
54
+ export declare function getSelectClauseFromSelectStatement(selectStatement: SelectStmt): SelectClause;
55
+ export declare function fromSelectClauseColumnsToColumnMappings(selectClause: SelectClause, objectName?: string): IShallowColumnMapping[];
56
+ export declare function getSelectionsConfigFromSelectClause(selectClause: SelectClause): {
57
+ columns: {
58
+ name: string;
59
+ source: string | null;
60
+ }[];
61
+ globalSelectAll: boolean;
62
+ scopedSelectAll: string[];
63
+ } | null;
64
+ export declare function getJoinTypeFromJoinClause(joinClause: JoinExpr): AggregationStatementType;
65
+ export declare function getJoinTableFromJoinClause(joinClause: JoinExpr): string;
66
+ export declare function fromSqlOperatorsExprToComparisonOperator(operator: SupportedOperators): WhereStatementOperator | 'not' | null;
67
+ export declare function fromWhereBinaryExprToComparisonOperator(binaryExpr: BinaryExpr): WhereStatementOperator | null;
68
+ export declare function fromWhereBinaryExprToAndOrOperatorValue(whereExpr: BinaryExpr): 'AND' | 'OR' | null;
69
+ export declare function flattenBinaryExprComparisonsToWhereStatements(whereExpr: BinaryExpr, parent: WhereStatement, scopeColumns: ColumnRef[], state: SearchStatementState, project: ProjectState, debug?: boolean): {
70
+ ands: WhereStatement[];
71
+ ors: WhereStatement[];
72
+ };
73
+ export declare function fromWhereExprToWhereStatement(whereExpr: Expr, scopeColumns: ColumnRef[], state: SearchStatementState, project: ProjectState, debug?: boolean): WhereStatement | null;
74
+ export declare function getJoinOnSpecificationAsWhereStatementFromJoinExpr(joinClause: JoinExpr, scopeColumns: ColumnRef[], state: SearchStatementState, project: ProjectState, debug?: boolean): WhereStatement | null;
75
+ export declare function flattenJoinExprIntoAggregationStatementsSync(joinExpr: JoinExpr, parentQuery: SelectStmt, scopeColumns: ColumnRef[], state: SearchStatementState, project: ProjectState, helpers?: {
76
+ onDescribeTable?: (tableName: string) => Table | null;
77
+ }, debug?: boolean): {
78
+ aggregations: AggregationStatement[];
79
+ columnMappings: IColumnMapping[];
80
+ errors: {
81
+ entity: 'column' | 'table';
82
+ code: 'not-found';
83
+ name: string;
84
+ }[];
85
+ };
86
+ export declare function getAggregationStatementsFromSelectStatementSync(selectStatement: SelectStmt, scopeColumns: ColumnRef[], state: SearchStatementState, project: ProjectState, helpers?: {
87
+ onDescribeTable?: (tableName: string) => Table | null;
88
+ }): {
89
+ aggregations: AggregationStatement[];
90
+ columnMappings: IColumnMapping[];
91
+ errors: {
92
+ entity: 'column' | 'table';
93
+ code: 'not-found';
94
+ name: string;
95
+ }[];
96
+ };
97
+ export declare function fromSelectClauseToLiteralValueSelections(selectClause: SelectClause, state: SearchStatementState, _debug?: boolean): ColumnRef[];
98
+ export declare function getWhereClauseFromSelectStatement(selectStatement: SelectStmt): WhereClause | null;
99
+ export declare function getWhereStatementsFromSelectStatement(selectStatement: SelectStmt, scopeColumns: ColumnRef[], state: SearchStatementState, project: ProjectState): WhereStatement | null;
100
+ export declare function getLimitClauseFromSelectStatement(selectStatement: SelectStmt): LimitClause | null;
101
+ export declare function getRawOffetFromLimitClause(limitClause: LimitClause | null): number;
102
+ export declare function getRawLimitFromLimitClause(limitClause: LimitClause | null): number | null;
103
+ export declare function getOrderByClauseFromSelectStatement(selectStatement: SelectStmt): OrderByClause | null;
104
+ export declare function fromOrderByClauseToSortStatements(orderByClause: OrderByClause, _selectStatement: SelectStmt, _allColumns: IColumnMapping[], state: SearchStatementState): SortStatement[];
105
+ export declare function hydrateSearchStatementState(ast: SQLAST | SelectStmt, project: ProjectState, entity?: SearchState | null, debug?: boolean): {
106
+ state: SearchStatementState | null;
107
+ errors: {
108
+ entity: 'column' | 'table';
109
+ code: 'not-found';
110
+ name: string;
111
+ }[];
112
+ };
113
+ export {};
@@ -0,0 +1,233 @@
1
+ import { Program as SQLAST } from 'sql-parser-cst';
2
+ import { DefinitionEntityState, InputMapState, PropertyState } from '../..';
3
+
4
+ export declare function resolveAreThereConflictingColumnsInSelectAll(allColumnsSelector: AllColumnsSelector | null): boolean;
5
+ export declare enum SearchStatementNodeType {
6
+ SearchStatement = "search-statement",
7
+ NestedSearchStatement = "nested-search-statement",
8
+ DataSource = "data-source",
9
+ ColumnRef = "column-ref",
10
+ ValueRef = "value-ref",
11
+ LiteralValue = "search-statement-literal-value",
12
+ WhereStatement = "where-statement",
13
+ AggregationStatement = "aggregation-statement",
14
+ SortStatement = "sort-statement",
15
+ AllColumnsSelector = "all-columns-selector"
16
+ }
17
+ export interface ISearchNode {
18
+ type: SearchStatementNodeType;
19
+ }
20
+ export declare enum AggregationStatementType {
21
+ Inner = "inner",
22
+ Left = "left",
23
+ Right = "right",
24
+ Full = "full",
25
+ Cross = "cross",
26
+ Self = "self",
27
+ Natural = "natural"
28
+ }
29
+ interface IDataSource {
30
+ entity: DefinitionEntityState | null;
31
+ query: NestedSearchStatement | null;
32
+ aggregation: AggregationStatement | null;
33
+ sourceType: DataSourceType | null;
34
+ as: string;
35
+ }
36
+ export declare class AggregationStatement implements ISearchNode {
37
+ owner: SearchStatementState;
38
+ dataSource: DataSource | null;
39
+ joinType: AggregationStatementType;
40
+ on: WhereStatement | null;
41
+ as: string | null;
42
+ constructor(owner: SearchStatementState);
43
+ get type(): SearchStatementNodeType.AggregationStatement;
44
+ get id(): string;
45
+ get columns(): ColumnRef[];
46
+ get isValid(): boolean;
47
+ get selections(): (ColumnRef | AllColumnsSelector)[];
48
+ get selectedColumns(): ColumnRef[];
49
+ get primaryKeys(): ColumnRef[];
50
+ get primaryKey(): ColumnRef | null;
51
+ setDataSource(dataSource: DataSource): void;
52
+ removeDataSource(): void;
53
+ editDataSource(dataSource: DataSource): void;
54
+ }
55
+ export declare enum SearchLiteralValueType {
56
+ String = "string",
57
+ Number = "number",
58
+ Boolean = "boolean",
59
+ Null = "null",
60
+ Date = "date"
61
+ }
62
+ export declare class SearchStatementLiteralValue implements ISearchNode {
63
+ owner: SearchStatementState;
64
+ valueType: SearchLiteralValueType;
65
+ value: string | number | boolean | null | Date;
66
+ _id: string;
67
+ constructor(owner: SearchStatementState);
68
+ get type(): SearchStatementNodeType.LiteralValue;
69
+ get id(): string;
70
+ toQuery(): string;
71
+ }
72
+ export declare enum WhereStatementOperator {
73
+ Like = "like",
74
+ NotLike = "not-like",
75
+ In = "in",
76
+ Equal = "=",
77
+ Between = "-",
78
+ BiggerThan = ">",
79
+ SmallerThan = "<",
80
+ BiggerThanOrEqualTo = ">=",
81
+ SmallerThanOrEqualTo = "<=",
82
+ NotEqual = "!="
83
+ }
84
+ export declare function whereStatementOperatorToSQL(operator: WhereStatementOperator): 'LIKE' | 'NOT LIKE' | 'IS NOT' | 'BETWEEN' | 'IN' | WhereStatementOperator.BiggerThan | WhereStatementOperator.SmallerThan | WhereStatementOperator.BiggerThanOrEqualTo | WhereStatementOperator.SmallerThanOrEqualTo;
85
+ export declare class WhereStatement implements ISearchNode {
86
+ owner: SearchStatementState;
87
+ parent: WhereStatement | null;
88
+ and: WhereStatement[];
89
+ or: WhereStatement[];
90
+ left: ColumnRef | InputMapState | SearchStatementLiteralValue | null;
91
+ operator: WhereStatementOperator | null;
92
+ right: ColumnRef | InputMapState | SearchStatementLiteralValue | null;
93
+ _id: string;
94
+ constructor(owner: SearchStatementState, parent?: WhereStatement);
95
+ get type(): SearchStatementNodeType.WhereStatement;
96
+ get isValid(): boolean;
97
+ get id(): string;
98
+ removeDataSource(dataSource: DataSource): void;
99
+ toQuery(): string;
100
+ sanitize(): void;
101
+ removeFromParent(): void;
102
+ remove(): void;
103
+ }
104
+ export declare class NestedSearchStatement implements ISearchNode {
105
+ owner: SearchStatementState;
106
+ statement: SearchStatementState | null;
107
+ as: string | null;
108
+ constructor(owner: SearchStatementState);
109
+ get type(): SearchStatementNodeType.NestedSearchStatement;
110
+ get id(): string;
111
+ get isValid(): boolean;
112
+ get columns(): ColumnRef[];
113
+ get mainPersistedEntity(): DefinitionEntityState | null;
114
+ get selections(): (ColumnRef | AllColumnsSelector)[];
115
+ get selectedColumns(): ColumnRef[];
116
+ get primaryKeys(): ColumnRef[];
117
+ get primaryKey(): ColumnRef | null;
118
+ toQuery(): string;
119
+ }
120
+ export declare enum DataSourceType {
121
+ Table = "table",
122
+ Query = "query",
123
+ Aggregation = "aggregation"
124
+ }
125
+ export declare class DataSource implements IDataSource, ISearchNode {
126
+ owner: SearchStatementState;
127
+ entity: DefinitionEntityState | null;
128
+ query: NestedSearchStatement | null;
129
+ aggregation: AggregationStatement | null;
130
+ sourceType: DataSourceType | null;
131
+ constructor(owner: SearchStatementState);
132
+ get id(): string;
133
+ get type(): SearchStatementNodeType.DataSource;
134
+ get isValid(): boolean;
135
+ get source(): DefinitionEntityState | NestedSearchStatement | AggregationStatement | null;
136
+ set as(as: string);
137
+ get as(): string;
138
+ get columns(): ColumnRef[];
139
+ get selections(): (ColumnRef | AllColumnsSelector)[];
140
+ get mainPersistedEntity(): DefinitionEntityState | null;
141
+ get selectedColumns(): ColumnRef[];
142
+ get primaryKeys(): ColumnRef[];
143
+ get primaryKey(): ColumnRef | null;
144
+ }
145
+ export declare class ColumnRef implements ISearchNode {
146
+ owner: SearchStatementState;
147
+ source: ColumnRef | PropertyState | SearchStatementLiteralValue | null;
148
+ parent: DataSource | null;
149
+ _id: string;
150
+ _as: string | null;
151
+ constructor(owner: SearchStatementState);
152
+ set as(as: string);
153
+ get as(): string;
154
+ get property(): PropertyState | null;
155
+ get literalValue(): SearchStatementLiteralValue | null;
156
+ get type(): SearchStatementNodeType.ColumnRef;
157
+ get id(): string;
158
+ get isValid(): boolean;
159
+ }
160
+ export declare class AllColumnsSelector implements ISearchNode {
161
+ owner: SearchStatementState;
162
+ parent: DataSource | null;
163
+ constructor(owner: SearchStatementState);
164
+ get type(): SearchStatementNodeType.AllColumnsSelector;
165
+ get id(): string;
166
+ get isValid(): boolean;
167
+ get columns(): ColumnRef[];
168
+ get selectedColumns(): ColumnRef[];
169
+ }
170
+ export declare enum SortStatementDirection {
171
+ Ascending = "asc",
172
+ Descending = "desc"
173
+ }
174
+ export declare class SortStatement implements ISearchNode {
175
+ owner: SearchStatementState;
176
+ column: ColumnRef | null;
177
+ direction: SortStatementDirection;
178
+ index: number;
179
+ constructor(owner: SearchStatementState);
180
+ get type(): SearchStatementNodeType.SortStatement;
181
+ get isValid(): boolean;
182
+ }
183
+ export declare class SearchStatementState implements ISearchNode {
184
+ id: string;
185
+ selections: (ColumnRef | AllColumnsSelector)[];
186
+ from: DataSource | null;
187
+ aggregations: AggregationStatement[];
188
+ where: WhereStatement | null;
189
+ offset: InputMapState | SearchStatementLiteralValue | null;
190
+ limit: InputMapState | SearchStatementLiteralValue | null;
191
+ asList: boolean;
192
+ sorting: SortStatement[];
193
+ dataSources: DataSource[];
194
+ constructor(id: string);
195
+ get isUntouchedEntity(): boolean;
196
+ get usedDataSources(): DataSource[];
197
+ get type(): SearchStatementNodeType.SearchStatement;
198
+ get mainPersistedEntity(): DefinitionEntityState | null;
199
+ get mainDatabaseEntity(): DefinitionEntityState | null;
200
+ get validSortings(): SortStatement[];
201
+ get selectedColumns(): ColumnRef[];
202
+ get validSelections(): (ColumnRef | AllColumnsSelector)[];
203
+ get validSelectedColumns(): ColumnRef[];
204
+ get columns(): ColumnRef[];
205
+ get isValid(): boolean;
206
+ get primaryKeys(): ColumnRef[];
207
+ get primaryKey(): ColumnRef | null;
208
+ get duplicateColumnNames(): string[];
209
+ get isOnlyAllFromSelected(): boolean;
210
+ addDataSource(dataSource: DataSource): DataSource;
211
+ getDataSource(id: string): DataSource | null;
212
+ editDataSource(dataSource: DataSource): DataSource | null;
213
+ toQuery(): string;
214
+ calculateAst(): {
215
+ ast: SQLAST | null;
216
+ query: string | null;
217
+ };
218
+ addAggregation(aggregation: AggregationStatement): void;
219
+ removeAggregation(aggregation: AggregationStatement): void;
220
+ editAggregation(aggregation: AggregationStatement): void;
221
+ addSort(sort: SortStatement): void;
222
+ removeSort(sort: SortStatement): void;
223
+ editSort(sort: SortStatement): void;
224
+ addSelection(selection: ColumnRef | AllColumnsSelector): void;
225
+ removeSelection(selection: ColumnRef | AllColumnsSelector): void;
226
+ editSelection(selection: ColumnRef | AllColumnsSelector): void;
227
+ setFrom(from: DataSource): void;
228
+ setWhere(where: WhereStatement): void;
229
+ setLimit(limit: SearchStatementLiteralValue | InputMapState): void;
230
+ setOffset(offset: SearchStatementLiteralValue | InputMapState): void;
231
+ setAsList(asList: boolean): void;
232
+ }
233
+ export {};
@@ -10,6 +10,7 @@ import { ValueDescriptorState } from '../value-descriptor';
10
10
  import { VersionedState } from '../version';
11
11
  import { ChangeSet, IChangeSet } from '../change-set';
12
12
  import { DefinitionEntityState } from '../definition-entity';
13
+ import { SearchStatementState } from './query/search-statement-state';
13
14
 
14
15
  export declare enum SearchDependencyField {
15
16
  Parent = "parent"
@@ -36,6 +37,7 @@ export declare class SearchState extends VersionedState implements ISearch, Base
36
37
  parent: EntityWithLogicScopeState | ProjectState;
37
38
  errors: EntityError[];
38
39
  project: ProjectState;
40
+ state: SearchStatementState | null;
39
41
  detachedDependents: Record<EntityId, {
40
42
  entity: UserManagedEntityState;
41
43
  field: string;
@@ -69,8 +71,14 @@ export declare class SearchState extends VersionedState implements ISearch, Base
69
71
  modifiedData: ISearchGenerationTarget;
70
72
  };
71
73
  get resultsAsList(): boolean;
74
+ queryToState(): SearchStatementState;
75
+ stateToQuery(): string;
76
+ rehydrateQuery(): string;
77
+ onProjectInitialized(_project: ProjectState, changeSet?: ChangeSet | null): SearchState;
78
+ onPersistedEntityUpdated(_updatedEntity: DefinitionEntityState, changeSet?: ChangeSet | null): SearchState;
72
79
  onPersistedEntityAdded(_newEntity: DefinitionEntityState, changeSet?: ChangeSet | null): SearchState;
73
80
  onPersistedEntityRemoved(_removedEntity: DefinitionEntityState, changeSet?: ChangeSet | null): SearchState;
81
+ onRelationalDatabaseEntityUpdated(_updatedEntity: DefinitionEntityState, changeSet?: ChangeSet | null): SearchState;
74
82
  onRelationalDatabaseEntityAdded(_newEntity: DefinitionEntityState, changeSet?: ChangeSet | null): SearchState;
75
83
  onRelationalDatabaseEntityRemoved(_removedEntity: DefinitionEntityState, changeSet?: ChangeSet | null): SearchState;
76
84
  validateGeneratedUpdate(data: Partial<ISearchGenerationTarget>): {
@@ -274,6 +274,7 @@ export declare function checkHasBaseEntity(entity: DefinitionEntityState | Built
274
274
  export declare function getPeristedEntities(project: ProjectState): DefinitionEntityState[];
275
275
  export declare function getDatabaseEntities(project: ProjectState): DefinitionEntityState[];
276
276
  export declare function resolvePrimaryKeyProperty(entity: DefinitionEntityState): PropertyState | null;
277
+ export declare function resolvePersistedDefinitionEntityDatabaseEntity(entity: DefinitionEntityState): DefinitionEntityState | null;
277
278
  export declare function getColumnProperties(entity: DefinitionEntityState): PropertyState[];
278
279
  export declare function getDatabaseEntity(entity: DefinitionEntityState): DefinitionEntityState | null;
279
280
  export declare function resolveClonedEntityProject(newParent: EntityState | null, self: EntityState): ProjectState;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyx-code/project-logic-tree",
3
- "version": "0.0.6279",
3
+ "version": "0.0.6281",
4
4
  "author": "Sergio Herrero",
5
5
  "license": "UNLICENSED",
6
6
  "description": "An installable module which contains the type definitions and ephemeral state management for a projects' logic tree data structure",
@@ -29,6 +29,7 @@
29
29
  "dayjs": "^1.11.13",
30
30
  "pluralize": "^8.0.0",
31
31
  "short-uuid": "^5.2.0",
32
+ "sql-parser-cst": "^0.33.1",
32
33
  "underscore": "^1.13.7",
33
34
  "zod": "^3.22.4",
34
35
  "zod-validation-error": "^3.3.0"