@memberjunction/core-entities-server 6.2.0-edge.6 → 6.2.0-edge.7

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.
Files changed (159) hide show
  1. package/README.md +155 -100
  2. package/dist/custom/MJAIAgentExampleEntityServer.server.d.ts +2 -0
  3. package/dist/custom/MJAIAgentExampleEntityServer.server.d.ts.map +1 -1
  4. package/dist/custom/MJAIAgentExampleEntityServer.server.js +8 -5
  5. package/dist/custom/MJAIAgentExampleEntityServer.server.js.map +1 -1
  6. package/dist/custom/MJAIAgentNoteEntityServer.server.d.ts +2 -0
  7. package/dist/custom/MJAIAgentNoteEntityServer.server.d.ts.map +1 -1
  8. package/dist/custom/MJAIAgentNoteEntityServer.server.js +8 -5
  9. package/dist/custom/MJAIAgentNoteEntityServer.server.js.map +1 -1
  10. package/dist/custom/MJAIAgentRelationshipEntityServer.server.d.ts +17 -0
  11. package/dist/custom/MJAIAgentRelationshipEntityServer.server.d.ts.map +1 -0
  12. package/dist/custom/MJAIAgentRelationshipEntityServer.server.js +71 -0
  13. package/dist/custom/MJAIAgentRelationshipEntityServer.server.js.map +1 -0
  14. package/dist/custom/MJAIAgentSessionEntityServer.server.d.ts +8 -22
  15. package/dist/custom/MJAIAgentSessionEntityServer.server.d.ts.map +1 -1
  16. package/dist/custom/MJAIAgentSessionEntityServer.server.js +24 -1
  17. package/dist/custom/MJAIAgentSessionEntityServer.server.js.map +1 -1
  18. package/dist/custom/MJAIAgentUserPolicyEntityServer.server.d.ts +23 -0
  19. package/dist/custom/MJAIAgentUserPolicyEntityServer.server.d.ts.map +1 -0
  20. package/dist/custom/MJAIAgentUserPolicyEntityServer.server.js +53 -0
  21. package/dist/custom/MJAIAgentUserPolicyEntityServer.server.js.map +1 -0
  22. package/dist/custom/MJAIPromptEntityServer.server.d.ts.map +1 -1
  23. package/dist/custom/MJAIPromptEntityServer.server.js +2 -1
  24. package/dist/custom/MJAIPromptEntityServer.server.js.map +1 -1
  25. package/dist/custom/MJBrandKitEntityServer.server.d.ts +14 -0
  26. package/dist/custom/MJBrandKitEntityServer.server.d.ts.map +1 -0
  27. package/dist/custom/MJBrandKitEntityServer.server.js +75 -0
  28. package/dist/custom/MJBrandKitEntityServer.server.js.map +1 -0
  29. package/dist/custom/MJCompanyIntegrationEntityServer.server.d.ts.map +1 -1
  30. package/dist/custom/MJCompanyIntegrationEntityServer.server.js +1 -0
  31. package/dist/custom/MJCompanyIntegrationEntityServer.server.js.map +1 -1
  32. package/dist/custom/MJComponentEntityServer.server.d.ts +2 -0
  33. package/dist/custom/MJComponentEntityServer.server.d.ts.map +1 -1
  34. package/dist/custom/MJComponentEntityServer.server.js +5 -1
  35. package/dist/custom/MJComponentEntityServer.server.js.map +1 -1
  36. package/dist/custom/MJEntityDocumentEntityServer.server.d.ts.map +1 -1
  37. package/dist/custom/MJEntityDocumentEntityServer.server.js +1 -0
  38. package/dist/custom/MJEntityDocumentEntityServer.server.js.map +1 -1
  39. package/dist/custom/MJListDetailEntityServer.server.d.ts.map +1 -1
  40. package/dist/custom/MJListDetailEntityServer.server.js +1 -0
  41. package/dist/custom/MJListDetailEntityServer.server.js.map +1 -1
  42. package/dist/custom/MJQueryEntityServer.server.d.ts +177 -47
  43. package/dist/custom/MJQueryEntityServer.server.d.ts.map +1 -1
  44. package/dist/custom/MJQueryEntityServer.server.js +465 -162
  45. package/dist/custom/MJQueryEntityServer.server.js.map +1 -1
  46. package/dist/custom/MJQuerySQLEntityServer.server.d.ts +15 -18
  47. package/dist/custom/MJQuerySQLEntityServer.server.d.ts.map +1 -1
  48. package/dist/custom/MJQuerySQLEntityServer.server.js +34 -42
  49. package/dist/custom/MJQuerySQLEntityServer.server.js.map +1 -1
  50. package/dist/custom/MJTagEntityServer.server.d.ts +2 -0
  51. package/dist/custom/MJTagEntityServer.server.d.ts.map +1 -1
  52. package/dist/custom/MJTagEntityServer.server.js +13 -7
  53. package/dist/custom/MJTagEntityServer.server.js.map +1 -1
  54. package/dist/custom/MJUserRoutineEntityServer.server.d.ts.map +1 -1
  55. package/dist/custom/MJUserRoutineEntityServer.server.js +8 -1
  56. package/dist/custom/MJUserRoutineEntityServer.server.js.map +1 -1
  57. package/dist/custom/query-extraction/childRowWriter.d.ts +77 -0
  58. package/dist/custom/query-extraction/childRowWriter.d.ts.map +1 -0
  59. package/dist/custom/query-extraction/childRowWriter.js +277 -0
  60. package/dist/custom/query-extraction/childRowWriter.js.map +1 -0
  61. package/dist/custom/query-extraction/compositionTargets.d.ts +40 -0
  62. package/dist/custom/query-extraction/compositionTargets.d.ts.map +1 -0
  63. package/dist/custom/query-extraction/compositionTargets.js +99 -0
  64. package/dist/custom/query-extraction/compositionTargets.js.map +1 -0
  65. package/dist/custom/query-extraction/declared.d.ts +79 -0
  66. package/dist/custom/query-extraction/declared.d.ts.map +1 -0
  67. package/dist/custom/query-extraction/declared.js +91 -0
  68. package/dist/custom/query-extraction/declared.js.map +1 -0
  69. package/dist/custom/query-extraction/describeFacts.d.ts +40 -0
  70. package/dist/custom/query-extraction/describeFacts.d.ts.map +1 -0
  71. package/dist/custom/query-extraction/describeFacts.js +225 -0
  72. package/dist/custom/query-extraction/describeFacts.js.map +1 -0
  73. package/dist/custom/query-extraction/descriptionPass.d.ts +23 -0
  74. package/dist/custom/query-extraction/descriptionPass.d.ts.map +1 -0
  75. package/dist/custom/query-extraction/descriptionPass.js +95 -0
  76. package/dist/custom/query-extraction/descriptionPass.js.map +1 -0
  77. package/dist/custom/query-extraction/extractQuery.d.ts +25 -0
  78. package/dist/custom/query-extraction/extractQuery.d.ts.map +1 -0
  79. package/dist/custom/query-extraction/extractQuery.js +146 -0
  80. package/dist/custom/query-extraction/extractQuery.js.map +1 -0
  81. package/dist/custom/query-extraction/extractionTypes.d.ts +133 -0
  82. package/dist/custom/query-extraction/extractionTypes.d.ts.map +1 -0
  83. package/dist/custom/query-extraction/extractionTypes.js +2 -0
  84. package/dist/custom/query-extraction/extractionTypes.js.map +1 -0
  85. package/dist/custom/query-extraction/index.d.ts +16 -0
  86. package/dist/custom/query-extraction/index.d.ts.map +1 -1
  87. package/dist/custom/query-extraction/index.js +11 -1
  88. package/dist/custom/query-extraction/index.js.map +1 -1
  89. package/dist/custom/query-extraction/pipeline.d.ts +6 -2
  90. package/dist/custom/query-extraction/pipeline.d.ts.map +1 -1
  91. package/dist/custom/query-extraction/pipeline.js +21 -14
  92. package/dist/custom/query-extraction/pipeline.js.map +1 -1
  93. package/dist/custom/query-extraction/resolve.d.ts +7 -2
  94. package/dist/custom/query-extraction/resolve.d.ts.map +1 -1
  95. package/dist/custom/query-extraction/resolve.js +17 -14
  96. package/dist/custom/query-extraction/resolve.js.map +1 -1
  97. package/dist/custom/query-extraction/sourceBinding.d.ts +57 -0
  98. package/dist/custom/query-extraction/sourceBinding.d.ts.map +1 -0
  99. package/dist/custom/query-extraction/sourceBinding.js +104 -0
  100. package/dist/custom/query-extraction/sourceBinding.js.map +1 -0
  101. package/dist/custom/query-extraction/sync.d.ts +27 -3
  102. package/dist/custom/query-extraction/sync.d.ts.map +1 -1
  103. package/dist/custom/query-extraction/sync.js +69 -44
  104. package/dist/custom/query-extraction/sync.js.map +1 -1
  105. package/dist/custom/query-extraction/templateFacts.d.ts +62 -0
  106. package/dist/custom/query-extraction/templateFacts.d.ts.map +1 -0
  107. package/dist/custom/query-extraction/templateFacts.js +229 -0
  108. package/dist/custom/query-extraction/templateFacts.js.map +1 -0
  109. package/dist/custom/query-extraction/types.d.ts +4 -0
  110. package/dist/custom/query-extraction/types.d.ts.map +1 -1
  111. package/dist/custom/query-refresh/QueryExtractionService.d.ts +54 -0
  112. package/dist/custom/query-refresh/QueryExtractionService.d.ts.map +1 -0
  113. package/dist/custom/query-refresh/QueryExtractionService.js +207 -0
  114. package/dist/custom/query-refresh/QueryExtractionService.js.map +1 -0
  115. package/dist/custom/query-refresh/QueryRefreshExtractionServerOperation.d.ts +28 -0
  116. package/dist/custom/query-refresh/QueryRefreshExtractionServerOperation.d.ts.map +1 -0
  117. package/dist/custom/query-refresh/QueryRefreshExtractionServerOperation.js +106 -0
  118. package/dist/custom/query-refresh/QueryRefreshExtractionServerOperation.js.map +1 -0
  119. package/dist/custom/query-refresh/index.d.ts +14 -0
  120. package/dist/custom/query-refresh/index.d.ts.map +1 -0
  121. package/dist/custom/query-refresh/index.js +10 -0
  122. package/dist/custom/query-refresh/index.js.map +1 -0
  123. package/dist/custom/query-refresh/queryRebind.d.ts +33 -0
  124. package/dist/custom/query-refresh/queryRebind.d.ts.map +1 -0
  125. package/dist/custom/query-refresh/queryRebind.js +85 -0
  126. package/dist/custom/query-refresh/queryRebind.js.map +1 -0
  127. package/dist/custom/query-refresh/refreshAuthorization.d.ts +29 -0
  128. package/dist/custom/query-refresh/refreshAuthorization.d.ts.map +1 -0
  129. package/dist/custom/query-refresh/refreshAuthorization.js +66 -0
  130. package/dist/custom/query-refresh/refreshAuthorization.js.map +1 -0
  131. package/dist/custom/query-refresh/refreshFormat.d.ts +16 -0
  132. package/dist/custom/query-refresh/refreshFormat.d.ts.map +1 -0
  133. package/dist/custom/query-refresh/refreshFormat.js +67 -0
  134. package/dist/custom/query-refresh/refreshFormat.js.map +1 -0
  135. package/dist/custom/query-refresh/refreshOrder.d.ts +25 -0
  136. package/dist/custom/query-refresh/refreshOrder.d.ts.map +1 -0
  137. package/dist/custom/query-refresh/refreshOrder.js +95 -0
  138. package/dist/custom/query-refresh/refreshOrder.js.map +1 -0
  139. package/dist/custom/query-refresh/refreshSelection.d.ts +15 -0
  140. package/dist/custom/query-refresh/refreshSelection.d.ts.map +1 -0
  141. package/dist/custom/query-refresh/refreshSelection.js +99 -0
  142. package/dist/custom/query-refresh/refreshSelection.js.map +1 -0
  143. package/dist/custom/query-refresh/refreshTypes.d.ts +81 -0
  144. package/dist/custom/query-refresh/refreshTypes.d.ts.map +1 -0
  145. package/dist/custom/query-refresh/refreshTypes.js +5 -0
  146. package/dist/custom/query-refresh/refreshTypes.js.map +1 -0
  147. package/dist/custom/util.d.ts +8 -0
  148. package/dist/custom/util.d.ts.map +1 -1
  149. package/dist/custom/util.js +18 -1
  150. package/dist/custom/util.js.map +1 -1
  151. package/dist/engines/QueryEngineServer.d.ts +4 -1
  152. package/dist/engines/QueryEngineServer.d.ts.map +1 -1
  153. package/dist/engines/QueryEngineServer.js +10 -7
  154. package/dist/engines/QueryEngineServer.js.map +1 -1
  155. package/dist/index.d.ts +4 -0
  156. package/dist/index.d.ts.map +1 -1
  157. package/dist/index.js +4 -0
  158. package/dist/index.js.map +1 -1
  159. package/package.json +30 -30
@@ -0,0 +1,229 @@
1
+ import { GetQueryDialect } from "@memberjunction/sql-dialect";
2
+ import { CompositionFullPath, CompositionPathSegments, MatchCompositionPath, QueryTemplate, SqlTokens, TemplateSqlViews, } from "@memberjunction/sql-parser";
3
+ import { IndexByUUID } from "@memberjunction/global";
4
+ import { FormatQueryDiagnostic, QueryTextPosition } from "@memberjunction/core-entities";
5
+ import { ExtractAliasFromSQL } from "./resolve.js";
6
+ import { BindTableReferences, EntityObjectIndex } from "./sourceBinding.js";
7
+ /**
8
+ * Reads the query with MJ's parser: whether it is a template, its parameters (with composition
9
+ * pass-throughs), its compositions, the entities it reads, duplicate output names, doc comments
10
+ * and the save-time rules. Never touches the database.
11
+ */
12
+ export function AnalyzeQueryTemplate(input) {
13
+ const dialect = GetQueryDialect(input.Platform);
14
+ const template = QueryTemplate.Parse(input.SQL, dialect);
15
+ const validation = template.Validate({
16
+ Mode: input.Mode,
17
+ DeclaredParameters: DeclaredTemplateParameters(input.KnownParameters),
18
+ KnownParameterTypes: DetectedTemplateParameterTypes(input.KnownParameters),
19
+ QueryPath: input.QueryPath,
20
+ ResolveComposition: path => resolveTarget(path, input.Queries),
21
+ });
22
+ const docs = template.DocComments();
23
+ const resolved = resolveReferences(template.CompositionReferences().Value, input.Queries);
24
+ const structure = readStructure(input.SQL, dialect, input);
25
+ const diagnostics = [...validation.Diagnostics, ...docs.Diagnostics];
26
+ return {
27
+ Template: template,
28
+ UsesTemplate: template.Tokens.HasTemplate,
29
+ Parameters: parameterFacts(template, resolved.References, input.ParameterHints),
30
+ Dependencies: resolved.Complete ? resolved.References.map(r => dependencyFact(r, input.SQL)) : null,
31
+ Entities: structure.Entities,
32
+ DuplicateOutputNames: structure.DuplicateOutputNames,
33
+ ReadsParameterNamedSource: structure.ReadsParameterNamedSource,
34
+ FieldDocs: new Map(docs.Value.Fields.map(f => [f.Name.toLowerCase(), f.Description])),
35
+ Errors: diagnostics.filter(d => d.Severity === 'Error'),
36
+ Warnings: diagnostics.filter(d => d.Severity === 'Warning'),
37
+ Notes: [...resolved.Notes, ...structure.Notes],
38
+ };
39
+ }
40
+ /**
41
+ * The parameter rows that declare a type to the save-time rules: the rows a person wrote
42
+ * (`DetectionMethod` `Manual`), and the server-set rows, whose flag only a person sets. A row
43
+ * extraction detected records what the previous SQL implied, so it declares nothing: the SQL may
44
+ * change that parameter's filter, and the row then follows the new type.
45
+ */
46
+ export function DeclaredTemplateParameters(known) {
47
+ return known.filter(p => p.IsAuthored || p.IsServerSet).map(p => ({ Name: p.Name, Type: p.Type, IsServerSet: p.IsServerSet }));
48
+ }
49
+ /**
50
+ * The types the detected parameter rows record (the rows {@link DeclaredTemplateParameters} leaves
51
+ * out). They are not authoritative, so they never decide whether a filter fits. They only type a
52
+ * value written without a filter when the SQL gives no type. Without them, a string written
53
+ * unfiltered into a query whose rows were all detected would only be warned about, not refused.
54
+ */
55
+ export function DetectedTemplateParameterTypes(known) {
56
+ return known.filter(p => !p.IsAuthored && !p.IsServerSet).map(p => ({ Name: p.Name, Type: p.Type }));
57
+ }
58
+ /**
59
+ * Whether `sql` holds any MJ template tag (`{{ }}`, `{% %}`, `{# #}`, a composition) outside SQL
60
+ * comments, read by the lexer of `platform`'s dialect. This is what `UsesTemplate` records: a
61
+ * lexical fact, whatever extraction finds.
62
+ */
63
+ export function SQLUsesTemplate(sql, platform) {
64
+ return SqlTokens.Lex(sql, GetQueryDialect(platform)).HasTemplate;
65
+ }
66
+ /**
67
+ * A diagnostic as one line of `ExtractionMessage` or a refusal: code, location, message and fix,
68
+ * in the shared format clients read back with `ParseQueryDiagnostic`. The location is the line and
69
+ * column of the diagnostic's start in `sql`, the text it was found in; without `sql` it is left out.
70
+ */
71
+ export function DescribeDiagnostic(diagnostic, sql) {
72
+ const at = sql !== undefined ? QueryTextPosition(sql, diagnostic.Span.Start) : null;
73
+ return FormatQueryDiagnostic({
74
+ Code: diagnostic.Code,
75
+ Message: diagnostic.Message,
76
+ FixHint: diagnostic.FixHint,
77
+ Line: at?.Line ?? null,
78
+ Column: at?.Column ?? null,
79
+ });
80
+ }
81
+ // ─── Compositions ───────────────────────────────────────────────────────────
82
+ /** The composed query at a reference's full path, as `QueryTemplate.Validate` asks for it. */
83
+ function resolveTarget(fullPath, queries) {
84
+ const segments = CompositionPathSegments(fullPath);
85
+ const name = segments.pop() ?? '';
86
+ const match = MatchCompositionPath(segments, name, queries);
87
+ if (match.Kind !== 'Exact' && match.Kind !== 'PartialPath')
88
+ return null;
89
+ const query = match.Target;
90
+ return {
91
+ Exists: true,
92
+ Reusable: query.Reusable,
93
+ FullPath: match.Kind === 'PartialPath' ? match.FullPath : undefined,
94
+ // A server-set parameter is filled by the server on every run, never by an argument.
95
+ Parameters: query.QueryParameters.map(p => ({ Name: p.Name, IsRequired: p.IsRequired === true && !p.IsServerSet })),
96
+ Compositions: composedPaths(query, queries),
97
+ };
98
+ }
99
+ /** The full paths of the queries `query` composes, from its stored dependency rows. */
100
+ function composedPaths(query, queries) {
101
+ const byID = IndexByUUID(queries);
102
+ return (query.QueryDependencies ?? [])
103
+ .map(d => byID.Get(d.DependsOnQueryID))
104
+ .filter((q) => q !== undefined)
105
+ .map(q => CompositionFullPath(q));
106
+ }
107
+ /** Each composition with the query it names (exact path, or a unique partial path). */
108
+ function resolveReferences(references, queries) {
109
+ const resolved = [];
110
+ const notes = [];
111
+ for (const reference of references) {
112
+ const match = MatchCompositionPath(reference.CategoryPath, reference.Name, queries);
113
+ if (match.Kind === 'Exact' || match.Kind === 'PartialPath') {
114
+ resolved.push({ Reference: reference, Target: match.Target });
115
+ }
116
+ else {
117
+ notes.push(`The composition "${reference.FullPath}" names no single query; its dependency rows were left as they are.`);
118
+ }
119
+ }
120
+ return { References: resolved, Complete: notes.length === 0, Notes: notes };
121
+ }
122
+ function dependencyFact(resolved, sql) {
123
+ const reference = resolved.Reference;
124
+ const mapping = {};
125
+ for (const argument of reference.Arguments)
126
+ mapping[argument.Name] = argumentText(argument, sql);
127
+ return {
128
+ DependsOnQueryID: resolved.Target.ID,
129
+ ReferencePath: reference.FullPath,
130
+ Alias: ExtractAliasFromSQL(sql, sql.slice(reference.Span.Start, reference.Span.End)),
131
+ ParameterMapping: reference.Arguments.length > 0 ? JSON.stringify(mapping) : null,
132
+ };
133
+ }
134
+ /** An argument as the dependency row records it: a literal's value, `@Name` for a pass-through, else the expression text. */
135
+ function argumentText(argument, sql) {
136
+ const expression = argument.Expression;
137
+ if (expression.Kind === 'Literal')
138
+ return String(expression.Value);
139
+ if (expression.Kind === 'Name')
140
+ return `@${expression.Name}`;
141
+ return `@{${sql.slice(expression.Span.Start, expression.Span.End)}}`;
142
+ }
143
+ // ─── Parameters ─────────────────────────────────────────────────────────────
144
+ /** The template's parameters, typed and described from the composed query a pass-through argument feeds. */
145
+ function parameterFacts(template, references, hints) {
146
+ const docs = new Map(template.DocComments().Value.Parameters.map(p => [p.Name.toLowerCase(), p.Description]));
147
+ return template.Parameters().Value.map(p => {
148
+ const fed = passThroughTarget(p.Name, references);
149
+ return {
150
+ Name: p.Name,
151
+ Type: inferredType(p) ?? (fed ? fed.Type : arithmeticTargetType(p.Name, references)),
152
+ IsRequired: p.IsRequired,
153
+ DefaultValue: p.DefaultValue === null ? null : String(p.DefaultValue),
154
+ SampleValue: hintFor(p.Name, hints) ?? fed?.SampleValue ?? null,
155
+ DocDescription: docs.get(p.Name.toLowerCase()) ?? null,
156
+ InheritedDescription: fed ? inheritedDescription(fed) : null,
157
+ };
158
+ });
159
+ }
160
+ function inferredType(parameter) {
161
+ return parameter.InferredType === 'unknown' ? null : parameter.InferredType;
162
+ }
163
+ function hintFor(name, hints) {
164
+ return hints?.get(name) ?? hints?.get(name.toLowerCase()) ?? null;
165
+ }
166
+ /** The composed query's parameter an explicit `(Arg=Name)` argument passes `name` to; the first one wins. */
167
+ function passThroughTarget(name, references) {
168
+ const wanted = name.toLowerCase();
169
+ for (const { Reference, Target } of references) {
170
+ const argument = Reference.Arguments.find(a => a.Expression.Kind === 'Name' && a.Expression.Name.toLowerCase() === wanted);
171
+ const parameter = argument ? Target.QueryParameters.find(tp => tp.Name.toLowerCase() === argument.Name.toLowerCase()) : undefined;
172
+ if (parameter)
173
+ return parameter;
174
+ }
175
+ return undefined;
176
+ }
177
+ const ARITHMETIC_OPERATORS = new Set(['+', '-', '*', '/', '%']);
178
+ /**
179
+ * `number` when `name` is read by an arithmetic composition argument (`Lo=Floor + 4`) that feeds a
180
+ * number parameter of the composed query: the outer value must be a number for the arithmetic to
181
+ * mean what it says (a string value would be concatenated by `+`). Otherwise no type.
182
+ */
183
+ function arithmeticTargetType(name, references) {
184
+ const wanted = name.toLowerCase();
185
+ for (const { Reference, Target } of references) {
186
+ for (const argument of Reference.Arguments) {
187
+ const expression = argument.Expression;
188
+ if (expression.Kind !== 'Binary' || !ARITHMETIC_OPERATORS.has(expression.Operator))
189
+ continue;
190
+ if (!argument.ReferencedNames.some(n => n.toLowerCase() === wanted))
191
+ continue;
192
+ const parameter = Target.QueryParameters.find(tp => tp.Name.toLowerCase() === argument.Name.toLowerCase());
193
+ if (parameter?.Type === 'number')
194
+ return 'number';
195
+ }
196
+ }
197
+ return null;
198
+ }
199
+ function inheritedDescription(parameter) {
200
+ return parameter.Description ? `${parameter.Description} (passed through to "${parameter.Query}" as "${parameter.Name}")` : null;
201
+ }
202
+ // ─── Structure: entities read, duplicate output names ───────────────────────
203
+ /** The table references and duplicate output names of every SQL reading of the template (one per branch variant). */
204
+ function readStructure(sql, dialect, input) {
205
+ const views = TemplateSqlViews(sql, dialect);
206
+ const references = views.flatMap(v => [...v.Document.TableReferences().Value]);
207
+ const duplicates = new Map();
208
+ for (const view of views) {
209
+ for (const d of view.Document.DuplicateOutputNames().Value)
210
+ duplicates.set(d.Name.toLowerCase(), d.Name);
211
+ }
212
+ const complete = views.every(v => v.Complete);
213
+ const entities = BindTableReferences(references, new EntityObjectIndex(input.Entities), dialect.Grammar.DefaultSchema);
214
+ return {
215
+ Entities: complete ? entities : null,
216
+ DuplicateOutputNames: [...duplicates.values()],
217
+ ReadsParameterNamedSource: references.some(isParameterNamedReference),
218
+ Notes: complete ? [] : ['The SQL could not be read completely, so its Query Entities were left as they are.'],
219
+ };
220
+ }
221
+ /** The placeholder a template view writes for a `{{ }}` hole that stands where a name goes. */
222
+ const IDENTIFIER_PLACEHOLDER = /^__MJI_\w+__$/;
223
+ /** Whether a table reference's name (any part of it) is a template hole, not a name written in the SQL. */
224
+ function isParameterNamedReference(reference) {
225
+ if (reference.CTE !== null || reference.Kind !== 'Table')
226
+ return false;
227
+ return reference.Name.Parts.some(part => IDENTIFIER_PLACEHOLDER.test(part.Value));
228
+ }
229
+ //# sourceMappingURL=templateFacts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templateFacts.js","sourceRoot":"","sources":["../../../src/custom/query-extraction/templateFacts.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,EACH,mBAAmB,EACnB,uBAAuB,EACvB,oBAAoB,EACpB,aAAa,EACb,SAAS,EACT,gBAAgB,GACnB,MAAM,4BAA4B,CAAC;AAWpC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACzF,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,mBAAmB,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,EAAE,CAAC,CAAC,CAAC,CAAC,oFAAoF,CAAC;KAChH,CAAC;AACN,CAAC;AAED,+FAA+F;AAC/F,MAAM,sBAAsB,GAAG,eAAe,CAAC;AAE/C,2GAA2G;AAC3G,SAAS,yBAAyB,CAAC,SAAyB;IACxD,IAAI,SAAS,CAAC,GAAG,KAAK,IAAI,IAAI,SAAS,CAAC,IAAI,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IACvE,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AACtF,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import type { IMetadataProvider, IRunViewProvider, UserInfo, DatabasePlatform } from "@memberjunction/core";
2
2
  import type { MJQueryEntityExtended } from "@memberjunction/core-entities";
3
3
  import type { MJParameterInfo, MJParseResult, SQLSelectColumn, SQLTableReference } from "@memberjunction/sql-parser";
4
+ import type { DeclaredQueryChildren } from "./declared.js";
4
5
  /**
5
6
  * A parameter extracted from a query's SQL — the final merged result
6
7
  * combining deterministic parsing, dependency metadata, and LLM enrichment.
@@ -125,5 +126,8 @@ export interface QuerySyncContext {
125
126
  /** Skip the LLM enrichment stage, so the deterministic extraction alone decides parameters
126
127
  * and fields (with heuristic descriptions). Set from the save's `SkipEntityAIActions`. */
127
128
  SkipAIEnrichment?: boolean;
129
+ /** Child rows the same save declared through the query's collections. Extraction leaves them
130
+ * as the caller wrote them (see {@link DeclaredQueryChildren}). Absent means none. */
131
+ DeclaredChildren?: DeclaredQueryChildren;
128
132
  }
129
133
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/custom/query-extraction/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MA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AAC;IACtB,gBAAgB,EAAE,iBAAiB,CAAC;IACpC,eAAe,EAAE,gBAAgB,CAAC;IAClC;iFAC6E;IAC7E,QAAQ,EAAE,gBAAgB,CAAC;IAC3B;kGAC8F;IAC9F,cAAc,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC;+FAC2F;IAC3F,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;2FACuF;IACvF,gBAAgB,CAAC,EAAE,qBAAqB,CAAC;CAC5C"}
@@ -0,0 +1,54 @@
1
+ import type { QueryRefreshContext, QueryRefreshFilter, QueryRefreshOptions, QueryRefreshReport, QueryRefreshRunReport } from "./refreshTypes.js";
2
+ /**
3
+ * Re-establishes saved queries' facts from their SQL and the database server, on demand: the
4
+ * same extraction a save of a changed query runs, without changing the SQL. Every entry point
5
+ * (the `Query.RefreshExtraction` remote operation, `mj query refresh`, CodeGen's re-bind pass)
6
+ * goes through this service, so the same authorization applies to all of them:
7
+ *
8
+ * - the caller needs Update on `MJ: Queries` and Create, Update and Delete on its derived child
9
+ * entities, for a dry run too;
10
+ * - the caller must be able to read every entity the query reads, with no field denied on any of
11
+ * them, because the report and the written rows expose their columns;
12
+ * - a refusal of a single query reads exactly like "not found"; a bulk run reports such a query
13
+ * as `NotPermitted`, with no reason.
14
+ *
15
+ * Each query is refreshed in its own transaction on the caller's provider, and the child rows are
16
+ * written as the caller, so each write's own permission check also applies. A bulk run refreshes
17
+ * the queries a composition depends on before the queries that compose them.
18
+ */
19
+ export declare class QueryExtractionService {
20
+ private readonly context;
21
+ constructor(context: QueryRefreshContext);
22
+ /**
23
+ * Refreshes one saved query.
24
+ *
25
+ * @param queryID - The query's ID; echoed, and nothing else, when the query is unavailable.
26
+ */
27
+ RefreshQuery(queryID: string, options?: QueryRefreshOptions): Promise<QueryRefreshReport>;
28
+ /**
29
+ * Refreshes every query `filter` selects that the caller can read, dependencies first. An ID
30
+ * or name that selects nothing is reported as `Unavailable`; a selected query the caller may
31
+ * not refresh is reported as `NotPermitted`.
32
+ */
33
+ RefreshQueries(filter: QueryRefreshFilter, options?: QueryRefreshOptions): Promise<QueryRefreshRunReport>;
34
+ /**
35
+ * The queries `filter` selects; `null` when a caller who may not refresh queries cannot read
36
+ * them either, so the selection cannot be made (a caller who may refresh and still cannot read
37
+ * them meets the read's error).
38
+ */
39
+ private select;
40
+ private get userCanRefresh();
41
+ private refreshSelected;
42
+ /** The query as the caller can load it; `null` when it does not exist or the caller cannot read it. */
43
+ private loadQuery;
44
+ private refreshLoaded;
45
+ /** Writes the refresh in its own transaction on the caller's provider; any failure rolls it back. */
46
+ private applyInTransaction;
47
+ /**
48
+ * The non-disclosure guard: whether the caller can see every entity the query reads, by its
49
+ * stored links and field sources and by the facts the refresh found.
50
+ */
51
+ private userCanSeeSources;
52
+ private entityName;
53
+ }
54
+ //# sourceMappingURL=QueryExtractionService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QueryExtractionService.d.ts","sourceRoot":"","sources":["../../../src/custom/query-refresh/QueryExtractionService.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EACR,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,EACxB,MAAM,gBAAgB,CAAC;AAKxB;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,sBAAsB;IACnB,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,mBAAmB;IAEzD;;;;OAIG;IACU,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAO1G;;;;OAIG;IACU,cAAc,CAAC,MAAM,EAAE,kBAAkB,EAAE,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAe1H;;;;OAIG;YACW,MAAM;IASpB,OAAO,KAAK,cAAc,GAEzB;YAEa,eAAe;IAO7B,uGAAuG;YACzF,SAAS;YAUT,aAAa;IAuB3B,qGAAqG;YACvF,kBAAkB;IAMhC;;;OAGG;YACW,iBAAiB;IAY/B,OAAO,CAAC,UAAU;CAIrB"}
@@ -0,0 +1,207 @@
1
+ import { DatabaseProviderBase, LogError, RunInEntityTransaction } from "@memberjunction/core";
2
+ import { EscapeSQLString, NormalizeUUID } from "@memberjunction/global";
3
+ import { EntityIDsOfExtraction, QueryRefreshUnavailableMessage, UserCanRefreshQueries, UserCanSeeQuerySources, } from "./refreshAuthorization.js";
4
+ import { OrderForRefresh } from "./refreshOrder.js";
5
+ import { SelectQueriesForRefresh } from "./refreshSelection.js";
6
+ /**
7
+ * Re-establishes saved queries' facts from their SQL and the database server, on demand: the
8
+ * same extraction a save of a changed query runs, without changing the SQL. Every entry point
9
+ * (the `Query.RefreshExtraction` remote operation, `mj query refresh`, CodeGen's re-bind pass)
10
+ * goes through this service, so the same authorization applies to all of them:
11
+ *
12
+ * - the caller needs Update on `MJ: Queries` and Create, Update and Delete on its derived child
13
+ * entities, for a dry run too;
14
+ * - the caller must be able to read every entity the query reads, with no field denied on any of
15
+ * them, because the report and the written rows expose their columns;
16
+ * - a refusal of a single query reads exactly like "not found"; a bulk run reports such a query
17
+ * as `NotPermitted`, with no reason.
18
+ *
19
+ * Each query is refreshed in its own transaction on the caller's provider, and the child rows are
20
+ * written as the caller, so each write's own permission check also applies. A bulk run refreshes
21
+ * the queries a composition depends on before the queries that compose them.
22
+ */
23
+ export class QueryExtractionService {
24
+ constructor(context) {
25
+ this.context = context;
26
+ }
27
+ /**
28
+ * Refreshes one saved query.
29
+ *
30
+ * @param queryID - The query's ID; echoed, and nothing else, when the query is unavailable.
31
+ */
32
+ async RefreshQuery(queryID, options = {}) {
33
+ if (!this.userCanRefresh)
34
+ return unavailableReport(queryID, options);
35
+ const query = await this.loadQuery(queryID);
36
+ if (!query)
37
+ return unavailableReport(queryID, options);
38
+ return this.refreshLoaded(query, options, 'Unavailable', queryID);
39
+ }
40
+ /**
41
+ * Refreshes every query `filter` selects that the caller can read, dependencies first. An ID
42
+ * or name that selects nothing is reported as `Unavailable`; a selected query the caller may
43
+ * not refresh is reported as `NotPermitted`.
44
+ */
45
+ async RefreshQueries(filter, options = {}) {
46
+ const dryRun = options.DryRun === true;
47
+ const selection = await this.select(filter);
48
+ if (!selection)
49
+ return unselectableRun(filter, options);
50
+ const order = OrderForRefresh(selection.Queries, selection.Edges);
51
+ const reports = selection.Unmatched.map(label => unavailableReport(label, options));
52
+ const total = order.Order.length;
53
+ for (const [index, query] of order.Order.entries()) {
54
+ const report = await this.refreshSelected(query, options);
55
+ reports.push(report);
56
+ options.OnProgress?.({ Processed: index + 1, Total: total, Report: report });
57
+ }
58
+ return { DryRun: dryRun, Reports: reports, Cycles: order.Cycles };
59
+ }
60
+ /**
61
+ * The queries `filter` selects; `null` when a caller who may not refresh queries cannot read
62
+ * them either, so the selection cannot be made (a caller who may refresh and still cannot read
63
+ * them meets the read's error).
64
+ */
65
+ async select(filter) {
66
+ try {
67
+ return await SelectQueriesForRefresh(this.context, filter);
68
+ }
69
+ catch (e) {
70
+ if (this.userCanRefresh)
71
+ throw e;
72
+ return null;
73
+ }
74
+ }
75
+ get userCanRefresh() {
76
+ return UserCanRefreshQueries(this.context.User, this.context.Provider.Entities);
77
+ }
78
+ async refreshSelected(selected, options) {
79
+ if (!this.userCanRefresh)
80
+ return notPermittedReport(selected.ID, selected.Name, options);
81
+ const query = await this.loadQuery(selected.ID);
82
+ if (!query)
83
+ return notPermittedReport(selected.ID, selected.Name, options);
84
+ return this.refreshLoaded(query, options, 'NotPermitted', selected.ID);
85
+ }
86
+ /** The query as the caller can load it; `null` when it does not exist or the caller cannot read it. */
87
+ async loadQuery(queryID) {
88
+ try {
89
+ const query = await this.context.Provider.GetEntityObject('MJ: Queries', this.context.User);
90
+ return await query.Load(queryID) ? query : null;
91
+ }
92
+ catch (e) {
93
+ LogError(`[QueryExtractionService] query ${queryID} could not be loaded: ${e instanceof Error ? e.message : String(e)}`);
94
+ return null;
95
+ }
96
+ }
97
+ async refreshLoaded(query, options, refusal, label) {
98
+ const dryRun = options.DryRun === true;
99
+ try {
100
+ if (!query.SQL || query.SQL.trim().length === 0) {
101
+ return { ...emptyReport(query.ID, query.Name, 'Unchanged', dryRun), Diagnostics: ['The query has no SQL, so there is nothing to refresh.'] };
102
+ }
103
+ const extraction = await query.ComputeRefreshExtractionAsync();
104
+ if (!await this.userCanSeeSources(query.ID, extraction)) {
105
+ return refusal === 'Unavailable' ? unavailableReport(label, options) : notPermittedReport(query.ID, query.Name, options);
106
+ }
107
+ const rowChanges = queryRowChanges(query, extraction);
108
+ const preview = await query.PreviewRefreshAsync(extraction, id => this.entityName(id));
109
+ const summary = dryRun || !needsWrite(preview, rowChanges, options)
110
+ ? preview
111
+ : await this.applyInTransaction(query, extraction, options.WithAI === true);
112
+ return reportOf(query, extraction, summary, rowChanges, dryRun);
113
+ }
114
+ catch (e) {
115
+ const reason = e instanceof Error ? e.message : String(e);
116
+ LogError(`[QueryExtractionService] refresh of query "${query.Name}" failed: ${reason}`);
117
+ return { ...emptyReport(query.ID, query.Name, 'Failed', dryRun), Diagnostics: [`The refresh was not completed and nothing was written: ${reason}`] };
118
+ }
119
+ }
120
+ /** Writes the refresh in its own transaction on the caller's provider; any failure rolls it back. */
121
+ async applyInTransaction(query, extraction, withAI) {
122
+ const provider = this.context.Provider;
123
+ const work = () => query.ApplyRefreshAsync(extraction, withAI);
124
+ return provider instanceof DatabaseProviderBase ? RunInEntityTransaction(provider, work) : work();
125
+ }
126
+ /**
127
+ * The non-disclosure guard: whether the caller can see every entity the query reads, by its
128
+ * stored links and field sources and by the facts the refresh found.
129
+ */
130
+ async userCanSeeSources(queryID, extraction) {
131
+ const filter = `QueryID='${EscapeSQLString(queryID)}'`;
132
+ const [links, fields] = await this.context.Provider.RunViews([
133
+ { EntityName: 'MJ: Query Entities', ExtraFilter: filter, Fields: ['EntityID'], ResultType: 'simple', BypassCache: true, IgnoreMaxRows: true },
134
+ { EntityName: 'MJ: Query Fields', ExtraFilter: filter, Fields: ['SourceEntityID'], ResultType: 'simple', BypassCache: true, IgnoreMaxRows: true },
135
+ ], this.context.User);
136
+ if (!links?.Success || !fields?.Success)
137
+ return false;
138
+ const stored = [...links.Results.map(r => r.EntityID), ...fields.Results.map(r => r.SourceEntityID)]
139
+ .filter((id) => typeof id === 'string' && id.length > 0);
140
+ return UserCanSeeQuerySources(this.context.User, [...stored, ...EntityIDsOfExtraction(extraction)], this.context.Provider.Entities);
141
+ }
142
+ entityName(entityID) {
143
+ const wanted = NormalizeUUID(entityID);
144
+ return this.context.Provider.Entities.find(e => NormalizeUUID(e.ID) === wanted)?.Name ?? entityID;
145
+ }
146
+ }
147
+ /**
148
+ * Whether a refresh has anything to write: a child row or a query-row column changes, or the
149
+ * description pass was asked for and some row has no description. An unchanged query is not saved
150
+ * at all, so its timestamps and embedding stay as they are.
151
+ */
152
+ function needsWrite(preview, rowChanges, options) {
153
+ if (preview.Changes.length > 0 || rowChanges.length > 0)
154
+ return true;
155
+ return options.WithAI === true && preview.FieldsWithoutDescription.length + preview.ParametersWithoutDescription.length > 0;
156
+ }
157
+ /**
158
+ * The run for a caller who may neither refresh nor read queries:
159
+ * each ID or name it gave is reported unavailable, and nothing else is selected or disclosed.
160
+ */
161
+ function unselectableRun(filter, options) {
162
+ const labels = [...(filter.QueryIDs ?? []), ...(filter.QueryNames ?? [])];
163
+ return { DryRun: options.DryRun === true, Reports: labels.map(label => unavailableReport(label, options)), Cycles: [] };
164
+ }
165
+ /** The columns of the query row the refresh changes (`UsesTemplate` and the Extraction columns). */
166
+ function queryRowChanges(query, extraction) {
167
+ const message = extraction.Messages.length > 0 ? extraction.Messages.join('\n') : null;
168
+ const changes = [];
169
+ if (query.UsesTemplate !== extraction.UsesTemplate)
170
+ changes.push('UsesTemplate');
171
+ if (query.ExtractedSQLHash !== extraction.Hash)
172
+ changes.push('ExtractedSQLHash');
173
+ if (query.ExtractionStatus !== extraction.Status)
174
+ changes.push('ExtractionStatus');
175
+ if ((query.ExtractionMessage ?? null) !== message)
176
+ changes.push('ExtractionMessage');
177
+ return changes;
178
+ }
179
+ function reportOf(query, extraction, summary, rowChanges, dryRun) {
180
+ const changes = summary?.Changes ?? [];
181
+ const pick = (action) => changes.filter(c => c.Action === action);
182
+ return {
183
+ QueryID: query.ID,
184
+ QueryName: query.Name,
185
+ Outcome: changes.length > 0 || rowChanges.length > 0 ? 'Refreshed' : 'Unchanged',
186
+ DryRun: dryRun,
187
+ ExtractionStatus: extraction.Status,
188
+ QueryColumns: [...rowChanges],
189
+ Added: pick('Added'),
190
+ Updated: pick('Updated'),
191
+ Removed: pick('Removed'),
192
+ Flagged: summary?.FlaggedParameters ?? [],
193
+ Diagnostics: [...extraction.Messages],
194
+ };
195
+ }
196
+ function emptyReport(queryID, queryName, outcome, dryRun) {
197
+ return { QueryID: queryID, QueryName: queryName, Outcome: outcome, DryRun: dryRun, ExtractionStatus: null, QueryColumns: [], Added: [], Updated: [], Removed: [], Flagged: [], Diagnostics: [] };
198
+ }
199
+ /** A query that does not exist or that the caller may not refresh: the two read alike, echoing only `label`. */
200
+ function unavailableReport(label, options) {
201
+ return { ...emptyReport(label, '', 'Unavailable', options.DryRun === true), Diagnostics: [QueryRefreshUnavailableMessage(label)] };
202
+ }
203
+ /** A selected query a bulk run skips because the caller may not refresh it; no reason is given. */
204
+ function notPermittedReport(queryID, queryName, options) {
205
+ return { ...emptyReport(queryID, queryName, 'NotPermitted', options.DryRun === true), Diagnostics: ['Skipped: not permitted.'] };
206
+ }
207
+ //# sourceMappingURL=QueryExtractionService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QueryExtractionService.js","sourceRoot":"","sources":["../../../src/custom/query-refresh/QueryExtractionService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9F,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,wBAA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AAW,CAAC,KAAK,EAAE,EAAE,EAAE,aAAa,EAAE,OAAO,CAAC,MAAM,KAAK,IAAI,CAAC,EAAE,WAAW,EAAE,CAAC,8BAA8B,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;AACvI,CAAC;AAED,mGAAmG;AACnG,SAAS,kBAAkB,CAAC,OAAe,EAAE,SAAiB,EAAE,OAA4B;IACxF,OAAO,EAAE,GAAG,WAAW,CAAC,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,OAAO,CAAC,MAAM,KAAK,IAAI,CAAC,EAAE,WAAW,EAAE,CAAC,yBAAyB,CAAC,EAAE,CAAC;AACrI,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { IMetadataProvider, RemoteOpServerContext, UserInfo } from "@memberjunction/core";
2
+ import { QueryRefreshExtractionOperation } from "@memberjunction/core-entities";
3
+ import type { QueryRefreshExtractionInput, QueryRefreshExtractionOutput } from "@memberjunction/core-entities";
4
+ import type { QueryRefreshFilter, QueryRefreshRunReport } from "./refreshTypes.js";
5
+ /**
6
+ * Server implementation of the `Query.RefreshExtraction` remote operation: refreshes one saved
7
+ * query, or a selection, through {@link QueryExtractionService}, reporting each query as a
8
+ * progress event as it finishes.
9
+ *
10
+ * `Authorize` refuses a caller without Update on `MJ: Queries` and Create, Update and Delete on
11
+ * its child entities; the service applies the same check and the per-query non-disclosure guard
12
+ * for every entry point. An API-key caller also needs the operation's `query:refresh` scope.
13
+ * A request for exactly one query ID, and nothing else, reports a query that does not exist and
14
+ * one the caller may not refresh with the same message.
15
+ */
16
+ export declare class QueryRefreshExtractionServerOperation extends QueryRefreshExtractionOperation {
17
+ protected Authorize(_input: QueryRefreshExtractionInput, user: UserInfo): Promise<boolean>;
18
+ protected InternalExecute(input: QueryRefreshExtractionInput, provider: IMetadataProvider, user: UserInfo, context: RemoteOpServerContext): Promise<QueryRefreshExtractionOutput>;
19
+ }
20
+ /** The service filter for an operation input; only the selectors the input gives. */
21
+ export declare function RefreshFilterOf(input: QueryRefreshExtractionInput): QueryRefreshFilter;
22
+ /** Whether a filter selects anything at all. */
23
+ export declare function HasRefreshSelector(filter: QueryRefreshFilter): boolean;
24
+ /** A service run as the operation's output. */
25
+ export declare function RefreshOutputOf(run: QueryRefreshRunReport): QueryRefreshExtractionOutput;
26
+ /** Keeps the operation in the bundle: import and call it where the class must be registered. */
27
+ export declare function LoadQueryRefreshExtractionServerOperation(): void;
28
+ //# sourceMappingURL=QueryRefreshExtractionServerOperation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QueryRefreshExtractionServerOperation.d.ts","sourceRoot":"","sources":["../../../src/custom/query-refresh/QueryRefreshExtractionServerOperation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC/F,OAAO,EAAE,+BAA+B,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,KAAK,EACR,2BAA2B,EAC3B,4BAA4B,EAG/B,MAAM,+BAA+B,CAAC;AAOvC,OAAO,KAAK,EAAE,kBAAkB,EAA2C,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAEzH;;;;;;;;;;GAUG;AACH,qBACa,qCAAsC,SAAQ,+BAA+B;cAC7D,SAAS,CAAC,MAAM,EAAE,2BAA2B,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;cAIzF,eAAe,CAAC,KAAK,EAAE,2BAA2B,EAAE,QAAQ,EAAE,iBAAiB,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,4BAA4B,CAAC;CAoB1L;AAED,qFAAqF;AACrF,wBAAgB,eAAe,CAAC,KAAK,EAAE,2BAA2B,GAAG,kBAAkB,CAQtF;AAED,gDAAgD;AAChD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAGtE;AAED,+CAA+C;AAC/C,wBAAgB,eAAe,CAAC,GAAG,EAAE,qBAAqB,GAAG,4BAA4B,CAOxF;AAqBD,gGAAgG;AAChG,wBAAgB,yCAAyC,IAAI,IAAI,CAEhE"}