@theseam/ui-common 1.0.2-beta.54 → 1.0.2-beta.57

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.
@@ -8,8 +8,10 @@ import * as apollo_angular from 'apollo-angular';
8
8
  import { QueryRef, WatchQueryOptions, Apollo } from 'apollo-angular';
9
9
  import { DataFilterState } from '@theseam/ui-common/data-filters';
10
10
  import * as i0 from '@angular/core';
11
- import { InjectionToken, EventEmitter, Provider } from '@angular/core';
11
+ import { InjectionToken, Type, Provider, EventEmitter } from '@angular/core';
12
12
  import { OperationVariables } from '@apollo/client/core/types';
13
+ import * as _fortawesome_fontawesome_common_types from '@fortawesome/fontawesome-common-types';
14
+ import { IDataExporter } from '@theseam/ui-common/data-exporter';
13
15
  import * as _theseam_ui_common_graphql from '@theseam/ui-common/graphql';
14
16
 
15
17
  interface LogQueryLinkOptions {
@@ -55,17 +57,50 @@ declare function logQueryLink(inner: ApolloLink, options?: LogQueryLinkOptions):
55
57
  * variable is not referenced anywhere in the (possibly already-transformed)
56
58
  * query body.
57
59
  * - `variables.inline`: inline named variables into the query AST.
60
+ * - `variables.orderTiebreaker`: append a fallback sort field for deterministic
61
+ * pagination.
58
62
  *
59
63
  * Hints are applied first, then config-based processing.
60
64
  */
61
65
  declare const queryProcessingLink: ApolloLink;
62
66
 
67
+ /**
68
+ * Checks whether a GraphQL document or value node contains a reference to
69
+ * the named variable.
70
+ *
71
+ * This includes references inside variable definitions — a variable that is
72
+ * defined but not used as an argument will still be found. This behavior is
73
+ * relied on by `removeIfNotUsed` processing to avoid removing variables that
74
+ * may be needed after a later inline step.
75
+ */
63
76
  declare function containsVariable(node: DocumentNode | ValueNode, variableName: string): boolean;
64
77
 
78
+ /**
79
+ * Creates a variable reference marker for use in filter objects that will be
80
+ * passed to `toGQL` and inlined into a query.
81
+ *
82
+ * When `toGQL` encounters an object with a `gqlVar` property, it emits the
83
+ * value as-is (e.g. `$search`), producing a GraphQL variable reference in the
84
+ * output rather than a string literal.
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * const filter = { name: { contains: gqlVar('search') } }
89
+ * // toGQL(filter) → '{name: {contains: $search}}'
90
+ * ```
91
+ */
65
92
  declare function gqlVar(varName: string): {
66
93
  gqlVar: string;
67
94
  };
68
95
 
96
+ /**
97
+ * Replaces all references to a variable in the query body with a literal
98
+ * value. If the value represents `undefined`, the variable references are
99
+ * removed from the query instead.
100
+ *
101
+ * This does not remove the variable definition — use `removeVariableDefinition`
102
+ * separately if needed.
103
+ */
69
104
  declare function inlineVariable(query: DocumentNode$1, variableName: string, variableValue: ValueNode$1): DocumentNode$1;
70
105
 
71
106
  declare function parseComments(ast: DocumentNode): Token[];
@@ -105,15 +140,48 @@ interface HintDefinition {
105
140
  }
106
141
 
107
142
  declare const DEFAULT_TO_REMOVE_ON_UNDEFINED: string[];
143
+ /**
144
+ * Configuration for how query variables are transformed before a GraphQL
145
+ * operation is sent. Used via `queryProcessingConfig` in Apollo context or
146
+ * passed directly to `processGql`.
147
+ */
108
148
  interface QueryProcessingVariablesConfig {
149
+ /**
150
+ * Variable names to remove from the query when their value is `null` or
151
+ * `undefined`. Removes both the variable definition and argument references.
152
+ */
109
153
  removeIfNotDefined?: string[];
154
+ /**
155
+ * Variable names whose definitions should be removed if the variable is not
156
+ * referenced anywhere in the query. A variable that still has its own
157
+ * definition is considered "present" and will not be removed — this is
158
+ * intentional because the variable may be needed after a later processing
159
+ * step (e.g. `$search` referenced inside a `$where` value that will be
160
+ * inlined).
161
+ */
110
162
  removeIfNotUsed?: string[];
163
+ /**
164
+ * Variable names to inline into the query. The variable's value is converted
165
+ * to a GraphQL literal and substituted directly into the query AST. The
166
+ * variable is then removed from both the definition and the variables map.
167
+ */
111
168
  inline?: string[];
169
+ /**
170
+ * If set, the order variable (expected to be an array of sort objects) will be
171
+ * checked and if this field name is not already present as a sort key, it will
172
+ * be appended with a default direction of DESC. This ensures deterministic
173
+ * ordering for paginated results.
174
+ */
175
+ orderTiebreaker?: string;
112
176
  }
177
+ /**
178
+ * Top-level configuration for query processing. Passed via Apollo context
179
+ * under the key `queryProcessingConfig`, or to `processGql` directly.
180
+ */
113
181
  interface QueryProcessingConfig {
114
182
  variables: QueryProcessingVariablesConfig;
115
183
  /**
116
- * If skip and take are found, they will be removed
184
+ * When enabled, paging is disabled and all records are returned.
117
185
  */
118
186
  disablePaging?: boolean;
119
187
  }
@@ -153,16 +221,62 @@ declare function createHintsToken(token: Token$1, node: HintsToken['node'], kind
153
221
  declare function getHintsToken(token: Token$1, ast: DocumentNode$1): HintsToken | null;
154
222
  declare function parseHints(ast: DocumentNode$1): HintsToken[];
155
223
 
224
+ /**
225
+ * Removes a variable's definition from the query (e.g. `$where: String` in the
226
+ * operation signature). Does not remove argument references to that variable in
227
+ * the query body.
228
+ *
229
+ * To remove both the definition and argument references, use `removeVariable`.
230
+ */
156
231
  declare function removeVariableDefinition(query: DocumentNode$1, variableName: string): DocumentNode$1;
157
232
 
233
+ /**
234
+ * Removes variable definitions from the specified operation when the variable
235
+ * does not have a corresponding value in the provided variables object (i.e.
236
+ * the value is `null` or `undefined`).
237
+ *
238
+ * Unlike `removeVariable`, this only removes the definitions — it does not
239
+ * remove argument references in the query body.
240
+ */
158
241
  declare function removeVariableDefinitionsNotDefined(query: DocumentNode$1, node: OperationDefinitionNode, variables: Operation['variables']): DocumentNode$1;
159
242
 
243
+ /**
244
+ * Removes a variable from the query by removing both the variable definition
245
+ * (e.g. `$where: String` in the operation signature) and argument references
246
+ * with the same name (e.g. `where: $where` in the field arguments).
247
+ *
248
+ * To remove only the definition without touching arguments, use
249
+ * `removeVariableDefinition`.
250
+ */
160
251
  declare function removeVariable(query: DocumentNode$1, variableName: string): DocumentNode$1;
161
252
 
162
253
  declare function toGQL(json: any): string;
163
254
 
164
255
  declare function hintsTokensContainingHint(hintsTokens: HintsToken[], hint: string): HintsToken[];
165
256
 
257
+ /**
258
+ * Transforms a GraphQL query and its variables according to the provided
259
+ * processing configuration.
260
+ *
261
+ * Two mechanisms are supported and can be combined freely:
262
+ *
263
+ * **Hint-based** — `# @gql-hint: <name>` comments in the query.
264
+ * - `remove-not-defined`: removes variables whose value is null/undefined.
265
+ * - `inline-variable`: substitutes variable values directly into the AST.
266
+ *
267
+ * **Config-based** — via `QueryProcessingConfig`:
268
+ * - `removeIfNotDefined`: remove named variables when null/undefined.
269
+ * - `removeIfNotUsed`: remove named variable definitions when unreferenced.
270
+ * - `inline`: inline named variables into the query AST.
271
+ * - `orderTiebreaker`: append a fallback sort field for deterministic pagination.
272
+ *
273
+ * Hints are applied first, then config-based processing, then cleanup.
274
+ */
275
+ declare function processGql(query: DocumentNode$1, variables: Record<string, any>, queryProcessingConfig: QueryProcessingConfig): {
276
+ query: DocumentNode$1;
277
+ variables: Record<string, any>;
278
+ };
279
+
166
280
  interface DatatableGraphQLDataMapperResult<TRow = EmptyObject> {
167
281
  rows: TRow[];
168
282
  /**
@@ -239,6 +353,20 @@ declare class DatatableGraphQLQueryRef<TData, TVariables extends DatatableGraphQ
239
353
  * Default error handler used when no subscriber is listening to `error$`.
240
354
  */
241
355
  _defaultErrorHandler?: DatatableGraphQLErrorHandler | undefined);
356
+ /**
357
+ * Returns an observable of mapped rows from the query result.
358
+ *
359
+ * The mapper transforms the raw GraphQL response data into the row format
360
+ * the datatable expects, and provides the total count for pagination.
361
+ *
362
+ * @example
363
+ * ```typescript
364
+ * this.rows$ = this._queryRef.rows((data) => ({
365
+ * rows: data.items.items,
366
+ * totalCount: data.items.totalCount,
367
+ * }))
368
+ * ```
369
+ */
242
370
  rows(mapper: DatatableGraphQLDataMapper<TData, TRow>): Observable<TRow[]>;
243
371
  private _rowsObservable;
244
372
  /**
@@ -446,6 +574,60 @@ declare const mapSearchNumericColumnsDataFilterStateToGql: (filterState: Columns
446
574
 
447
575
  declare const mapSearchTextColumnsDataFilterStateToGql: (filterState: ColumnsDataFilterState<TheSeamColumnsDataFilterTextSearchFormState>, context: MapperContext<any>) => FilterStateMapperResult;
448
576
 
577
+ interface DatatableExportPayload {
578
+ graphQlQuery: {
579
+ queryString: string;
580
+ queryVariables: Record<string, any>;
581
+ operationName: string;
582
+ columns: TheSeamDatatableColumn[];
583
+ };
584
+ exportType: string;
585
+ }
586
+ /**
587
+ * Abstract transport for server-side datatable exports.
588
+ *
589
+ * THIS SHOULD BE IMPLEMENTED AND PROVIDED BY THE APPLICATION USING 'ui-common'.
590
+ *
591
+ * Example:
592
+ * ```ts
593
+ * bootstrapApplication(AppComponent, {
594
+ * providers: [
595
+ * provideDatatableExportTransport(AppDatatableExportTransport),
596
+ * ],
597
+ * })
598
+ * ```
599
+ */
600
+ declare abstract class DatatableExportTransport {
601
+ abstract export(data: DatatableExportPayload): Observable<File>;
602
+ }
603
+ /**
604
+ * Register the application's `DatatableExportTransport` implementation.
605
+ *
606
+ * ```ts
607
+ * bootstrapApplication(AppComponent, {
608
+ * providers: [
609
+ * provideDatatableExportTransport(AppDatatableExportTransport),
610
+ * ],
611
+ * })
612
+ * ```
613
+ */
614
+ declare function provideDatatableExportTransport(transportType: Type<DatatableExportTransport>): Provider;
615
+
616
+ declare class DatatableGqlDataExporter<TData, TVariables extends DatatableGraphQLVariables = EmptyObject, TRow = EmptyObject> implements IDataExporter {
617
+ private readonly _exporterName;
618
+ private readonly _exporterLabel;
619
+ private readonly _columns;
620
+ private readonly _queryRef;
621
+ private readonly _transport;
622
+ private readonly _exportType;
623
+ get name(): string;
624
+ get label(): string;
625
+ icon: _fortawesome_fontawesome_common_types.IconDefinition;
626
+ readonly skipDataMapping: boolean;
627
+ constructor(_exporterName: string, _exporterLabel: string, _columns: TheSeamDatatableColumn[], _queryRef: DatatableGraphQLQueryRef<TData, TVariables, TRow>, _transport: DatatableExportTransport, _exportType: string);
628
+ export<T>(data: T[]): Observable<boolean>;
629
+ }
630
+
449
631
  /**
450
632
  * Inlines the variable's current value directly into the query AST and removes
451
633
  * the variable definition from the parameter list. The variable is also
@@ -615,5 +797,5 @@ interface SimpleGqlTestVariables extends SimpleGqlTestExtraVariables {
615
797
  search?: string;
616
798
  }
617
799
 
618
- export { DATATABLE_GRAPHQL_SERVICE_CONFIG, DEFAULT_PAGE_SIZE, DEFAULT_TO_REMOVE_ON_UNDEFINED, DatatableGraphQLQueryRef, DatatableGraphqlService, GQLDirection, GQLVariable, HINT_NAMES_CAPTURE_REGEX, HINT_PREFIX_REGEX, HintsKind, MAX_ERROR_RECOVERY_ATTEMPTS, MockDatatable, SIMPLE_GQL_TEST_QUERY, SIMPLE_GQL_TEST_SEARCH_QUERY, baseSchemaFragment, checkRecordsHaveValue, containsVariable, createHintsToken, createMockApolloTestingProvider, createSimpleGqlTestRecord, createSimpleGqlTestRoot, createSortsMapper, filterWhere, filteredResults, getHintsToken, getPageInfo, getTokenAppliesTo, gqlVar, hintNamesFromHintToken, hintsTokensContainingHint, inlineVariable, inlineVariableHintDef, inlineVariableTransformer, isCommentToken, isHintToken, isInlineComment, logQueryLink, mapFilterStates, mapSearchDateColumnsDataFilterStateToGql, mapSearchNumericColumnsDataFilterStateToGql, mapSearchTextColumnsDataFilterStateToGql, mockGraphQLLink, observeRowsWithGqlInputsHandling, parseAst, parseComments, parseHints, queryProcessingLink, removeNotDefinedHintDef, removeNotDefinedTransformer, removeVariable, removeVariableDefinition, removeVariableDefinitionsNotDefined, skipAndTake, sortItems, toGQL };
619
- export type { CreateSortsMapperOptions, DatatableGraphQLDataMapper, DatatableGraphQLDataMapperResult, DatatableGraphQLErrorHandler, DatatableGraphQLVariables, DatatableGraphqlServiceConfig, DatatableQueryOptions, EmptyObject, FilterStateMapper, FilterStateMapperFilter, FilterStateMapperResult, FilterStateMapperVariables, FilterStateMappers, FilteredResults, FilteredResultsPageInfo, GqlDatatableAccessor, HintDefinition, HintTransformOperation, HintTransformer, HintsToken, LogQueryLinkOptions, MapperContext, MockApolloTestingProviderOptions, MockGraphQLLinkOptions, QueryProcessingConfig, QueryProcessingVariablesConfig, SimpleGqlTestExtraVariables, SimpleGqlTestRecord, SimpleGqlTestVariables, SortClause, SortsMapper, SortsMapperFieldEntry, SortsMapperFieldMap, SortsMapperResult, TypedFilterInput, TypedFilterStateMapperResult, WhereArg };
800
+ export { DATATABLE_GRAPHQL_SERVICE_CONFIG, DEFAULT_PAGE_SIZE, DEFAULT_TO_REMOVE_ON_UNDEFINED, DatatableExportTransport, DatatableGqlDataExporter, DatatableGraphQLQueryRef, DatatableGraphqlService, GQLDirection, GQLVariable, HINT_NAMES_CAPTURE_REGEX, HINT_PREFIX_REGEX, HintsKind, MAX_ERROR_RECOVERY_ATTEMPTS, MockDatatable, SIMPLE_GQL_TEST_QUERY, SIMPLE_GQL_TEST_SEARCH_QUERY, baseSchemaFragment, checkRecordsHaveValue, containsVariable, createHintsToken, createMockApolloTestingProvider, createSimpleGqlTestRecord, createSimpleGqlTestRoot, createSortsMapper, filterWhere, filteredResults, getHintsToken, getPageInfo, getTokenAppliesTo, gqlVar, hintNamesFromHintToken, hintsTokensContainingHint, inlineVariable, inlineVariableHintDef, inlineVariableTransformer, isCommentToken, isHintToken, isInlineComment, logQueryLink, mapFilterStates, mapSearchDateColumnsDataFilterStateToGql, mapSearchNumericColumnsDataFilterStateToGql, mapSearchTextColumnsDataFilterStateToGql, mockGraphQLLink, observeRowsWithGqlInputsHandling, parseAst, parseComments, parseHints, processGql, provideDatatableExportTransport, queryProcessingLink, removeNotDefinedHintDef, removeNotDefinedTransformer, removeVariable, removeVariableDefinition, removeVariableDefinitionsNotDefined, skipAndTake, sortItems, toGQL };
801
+ export type { CreateSortsMapperOptions, DatatableExportPayload, DatatableGraphQLDataMapper, DatatableGraphQLDataMapperResult, DatatableGraphQLErrorHandler, DatatableGraphQLVariables, DatatableGraphqlServiceConfig, DatatableQueryOptions, EmptyObject, FilterStateMapper, FilterStateMapperFilter, FilterStateMapperResult, FilterStateMapperVariables, FilterStateMappers, FilteredResults, FilteredResultsPageInfo, GqlDatatableAccessor, HintDefinition, HintTransformOperation, HintTransformer, HintsToken, LogQueryLinkOptions, MapperContext, MockApolloTestingProviderOptions, MockGraphQLLinkOptions, QueryProcessingConfig, QueryProcessingVariablesConfig, SimpleGqlTestExtraVariables, SimpleGqlTestRecord, SimpleGqlTestVariables, SortClause, SortsMapper, SortsMapperFieldEntry, SortsMapperFieldMap, SortsMapperResult, TypedFilterInput, TypedFilterStateMapperResult, WhereArg };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theseam/ui-common",
3
- "version": "1.0.2-beta.54",
3
+ "version": "1.0.2-beta.57",
4
4
  "peerDependencies": {
5
5
  "@angular/cdk": "^20.2.3",
6
6
  "@angular/common": "^20.3.0",