@equinor/fusion-framework-module-context 8.0.3 → 9.0.0-next.0

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 (123) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/README.md +78 -2
  3. package/dist/esm/ContextModuleConfig.js +2 -0
  4. package/dist/esm/ContextModuleConfig.js.map +1 -0
  5. package/dist/esm/ContextModuleConfigurator.interface.js +2 -0
  6. package/dist/esm/ContextModuleConfigurator.interface.js.map +1 -0
  7. package/dist/esm/ContextModuleConfigurator.js +211 -0
  8. package/dist/esm/ContextModuleConfigurator.js.map +1 -0
  9. package/dist/esm/ContextProvider.js +1 -1
  10. package/dist/esm/ContextProvider.js.map +1 -1
  11. package/dist/esm/__tests__/ContextModuleConfigurator.test.js +282 -0
  12. package/dist/esm/__tests__/ContextModuleConfigurator.test.js.map +1 -0
  13. package/dist/esm/__tests__/mock/context-mock.test.js +101 -0
  14. package/dist/esm/__tests__/mock/context-mock.test.js.map +1 -0
  15. package/dist/esm/__tests__/mock/create-context-item-factory.test.js +45 -0
  16. package/dist/esm/__tests__/mock/create-context-item-factory.test.js.map +1 -0
  17. package/dist/esm/__tests__/mock/create-context-items.test.js +46 -0
  18. package/dist/esm/__tests__/mock/create-context-items.test.js.map +1 -0
  19. package/dist/esm/index.js +1 -1
  20. package/dist/esm/index.js.map +1 -1
  21. package/dist/esm/mock/ContextMockConfigurator.js +206 -0
  22. package/dist/esm/mock/ContextMockConfigurator.js.map +1 -0
  23. package/dist/esm/mock/fixtures/create-context-item-factory.js +50 -0
  24. package/dist/esm/mock/fixtures/create-context-item-factory.js.map +1 -0
  25. package/dist/esm/mock/fixtures/create-context-items.js +53 -0
  26. package/dist/esm/mock/fixtures/create-context-items.js.map +1 -0
  27. package/dist/esm/mock/fixtures/index.js +22 -0
  28. package/dist/esm/mock/fixtures/index.js.map +1 -0
  29. package/dist/esm/mock/fixtures/string-to-seed.js +15 -0
  30. package/dist/esm/mock/fixtures/string-to-seed.js.map +1 -0
  31. package/dist/esm/mock/index.js +31 -0
  32. package/dist/esm/mock/index.js.map +1 -0
  33. package/dist/esm/mock/module.js +41 -0
  34. package/dist/esm/mock/module.js.map +1 -0
  35. package/dist/esm/module.js +35 -6
  36. package/dist/esm/module.js.map +1 -1
  37. package/dist/esm/{get-context-selector.js → selectors/get-context-selector.js} +1 -4
  38. package/dist/esm/selectors/get-context-selector.js.map +1 -0
  39. package/dist/esm/selectors/index.js +13 -0
  40. package/dist/esm/selectors/index.js.map +1 -0
  41. package/dist/esm/{query-context-selector.js → selectors/query-context-selector.js} +1 -1
  42. package/dist/esm/selectors/query-context-selector.js.map +1 -0
  43. package/dist/esm/{related-context-selector.js → selectors/related-context-selector.js} +1 -1
  44. package/dist/esm/selectors/related-context-selector.js.map +1 -0
  45. package/dist/esm/utils/enable-context.js +1 -1
  46. package/dist/esm/utils/enable-context.js.map +1 -1
  47. package/dist/esm/utils/index.js +2 -0
  48. package/dist/esm/utils/index.js.map +1 -1
  49. package/dist/esm/utils/parse-context-item.js.map +1 -0
  50. package/dist/esm/utils/resolve-initial-context.js +3 -1
  51. package/dist/esm/utils/resolve-initial-context.js.map +1 -1
  52. package/dist/esm/version.js +1 -1
  53. package/dist/esm/version.js.map +1 -1
  54. package/dist/tsconfig.tsbuildinfo +1 -1
  55. package/dist/types/{configurator.d.ts → ContextModuleConfig.d.ts} +4 -64
  56. package/dist/types/ContextModuleConfigurator.d.ts +97 -0
  57. package/dist/types/{ContextConfigBuilder.d.ts → ContextModuleConfigurator.interface.d.ts} +27 -47
  58. package/dist/types/ContextProvider.d.ts +1 -1
  59. package/dist/types/__tests__/ContextModuleConfigurator.test.d.ts +1 -0
  60. package/dist/types/__tests__/mock/context-mock.test.d.ts +1 -0
  61. package/dist/types/__tests__/mock/create-context-item-factory.test.d.ts +1 -0
  62. package/dist/types/__tests__/mock/create-context-items.test.d.ts +1 -0
  63. package/dist/types/index.d.ts +3 -1
  64. package/dist/types/mock/ContextMockConfigurator.d.ts +155 -0
  65. package/dist/types/mock/fixtures/create-context-item-factory.d.ts +40 -0
  66. package/dist/types/mock/fixtures/create-context-items.d.ts +59 -0
  67. package/dist/types/mock/fixtures/index.d.ts +21 -0
  68. package/dist/types/mock/fixtures/string-to-seed.d.ts +12 -0
  69. package/dist/types/mock/index.d.ts +30 -0
  70. package/dist/types/mock/module.d.ts +38 -0
  71. package/dist/types/module.d.ts +5 -3
  72. package/dist/types/{get-context-selector.d.ts → selectors/get-context-selector.d.ts} +1 -3
  73. package/dist/types/selectors/index.d.ts +12 -0
  74. package/dist/types/{query-context-selector.d.ts → selectors/query-context-selector.d.ts} +1 -1
  75. package/dist/types/{related-context-selector.d.ts → selectors/related-context-selector.d.ts} +1 -1
  76. package/dist/types/utils/enable-context.d.ts +4 -5
  77. package/dist/types/utils/index.d.ts +2 -0
  78. package/dist/types/{parse-context-item.d.ts → utils/parse-context-item.d.ts} +1 -1
  79. package/dist/types/utils/resolve-initial-context.d.ts +1 -1
  80. package/dist/types/version.d.ts +1 -1
  81. package/docs/data-model.md +134 -0
  82. package/docs/lifecycle.md +163 -0
  83. package/docs/recipes.md +89 -0
  84. package/package.json +36 -8
  85. package/src/ContextModuleConfig.ts +147 -0
  86. package/src/ContextModuleConfigurator.interface.ts +145 -0
  87. package/src/ContextModuleConfigurator.ts +295 -0
  88. package/src/ContextProvider.ts +1 -2
  89. package/src/__tests__/ContextModuleConfigurator.test.ts +412 -0
  90. package/src/__tests__/mock/context-mock.test.ts +137 -0
  91. package/src/__tests__/mock/create-context-item-factory.test.ts +60 -0
  92. package/src/__tests__/mock/create-context-items.test.ts +58 -0
  93. package/src/index.ts +3 -5
  94. package/src/mock/ContextMockConfigurator.ts +244 -0
  95. package/src/mock/fixtures/create-context-item-factory.ts +62 -0
  96. package/src/mock/fixtures/create-context-items.ts +80 -0
  97. package/src/mock/fixtures/index.ts +28 -0
  98. package/src/mock/fixtures/string-to-seed.ts +18 -0
  99. package/src/mock/index.ts +33 -0
  100. package/src/mock/module.ts +54 -0
  101. package/src/module.ts +45 -17
  102. package/src/{get-context-selector.ts → selectors/get-context-selector.ts} +2 -6
  103. package/src/selectors/index.ts +12 -0
  104. package/src/{query-context-selector.ts → selectors/query-context-selector.ts} +2 -2
  105. package/src/{related-context-selector.ts → selectors/related-context-selector.ts} +2 -2
  106. package/src/utils/enable-context.ts +6 -10
  107. package/src/utils/index.ts +2 -0
  108. package/src/{parse-context-item.ts → utils/parse-context-item.ts} +1 -1
  109. package/src/utils/resolve-initial-context.ts +5 -2
  110. package/src/version.ts +1 -1
  111. package/tsconfig.json +6 -0
  112. package/vitest.config.ts +11 -0
  113. package/dist/esm/ContextConfigBuilder.js +0 -175
  114. package/dist/esm/ContextConfigBuilder.js.map +0 -1
  115. package/dist/esm/configurator.js +0 -104
  116. package/dist/esm/configurator.js.map +0 -1
  117. package/dist/esm/get-context-selector.js.map +0 -1
  118. package/dist/esm/parse-context-item.js.map +0 -1
  119. package/dist/esm/query-context-selector.js.map +0 -1
  120. package/dist/esm/related-context-selector.js.map +0 -1
  121. package/src/ContextConfigBuilder.ts +0 -258
  122. package/src/configurator.ts +0 -300
  123. /package/dist/esm/{parse-context-item.js → utils/parse-context-item.js} +0 -0
@@ -1,7 +1,7 @@
1
1
  import type { QueryContextResponse } from '@equinor/fusion-framework-module-services/context/query';
2
2
 
3
- import { parseContextItem } from './parse-context-item';
4
- import type { ContextItem } from './types';
3
+ import { parseContextItem } from '../utils/parse-context-item';
4
+ import type { ContextItem } from '../types';
5
5
 
6
6
  /**
7
7
  * Parse the response from the QueryContext API into an array of context items.
@@ -1,7 +1,7 @@
1
1
  import type { RelatedContextResponse } from '@equinor/fusion-framework-module-services/context/related';
2
2
 
3
- import { parseContextItem } from './parse-context-item';
4
- import type { ContextItem } from './types';
3
+ import { parseContextItem } from '../utils/parse-context-item';
4
+ import type { ContextItem } from '../types';
5
5
 
6
6
  /**
7
7
  * Parse the response from the RelatedContext API into an array of context items.
@@ -1,10 +1,8 @@
1
+ import type { IModulesConfigurator } from '@equinor/fusion-framework-module';
1
2
  import type {
2
- IModulesConfigurator,
3
- AnyModule,
4
- ModuleInitializerArgs,
5
- } from '@equinor/fusion-framework-module';
6
- import type { IContextModuleConfigurator } from '../configurator';
7
- import type { ContextConfigBuilder } from '../ContextConfigBuilder';
3
+ ContextConfigBuilderCallback,
4
+ IContextModuleConfigurator,
5
+ } from '../ContextModuleConfigurator.interface';
8
6
 
9
7
  import { module } from '../module';
10
8
 
@@ -12,7 +10,7 @@ import { module } from '../module';
12
10
  * Enables context configuration for a given modules configurator.
13
11
  *
14
12
  * @param configurator - The modules configurator instance to which the context module will be added.
15
- * @param builder - An optional function that receives a context configuration builder. This function can be used to further configure the context module. It can be asynchronous.
13
+ * @param builder - An optional function that receives the {@link IContextModuleConfigurator}. This function can be used to further configure the context module. It can be asynchronous.
16
14
  *
17
15
  * @remarks
18
16
  * This utility function adds the context module to the provided configurator and optionally applies additional configuration using the provided builder function.
@@ -31,9 +29,7 @@ import { module } from '../module';
31
29
  export const enableContext = (
32
30
  // biome-ignore lint/suspicious/noExplicitAny: must be any to support all module types
33
31
  configurator: IModulesConfigurator<any, any>,
34
- builder?: <TDeps extends Array<AnyModule> = []>(
35
- builder: ContextConfigBuilder<TDeps, ModuleInitializerArgs<IContextModuleConfigurator, TDeps>>,
36
- ) => void | Promise<void>,
32
+ builder?: ContextConfigBuilderCallback,
37
33
  ): void => {
38
34
  configurator.addConfig({
39
35
  module,
@@ -5,9 +5,11 @@
5
5
  * - {@link resolveInitialContext} — default initial-context resolver (path → parent fallback).
6
6
  * - {@link extractContextIdFromPath} — extract a GUID context ID from a URL path.
7
7
  * - {@link resolveContextFromPath} — resolve a context item from a URL path.
8
+ * - {@link parseContextItem} — parse a raw API context entity into a `ContextItem`.
8
9
  *
9
10
  * @packageDocumentation
10
11
  */
11
12
  export { enableContext } from './enable-context';
12
13
  export { resolveInitialContext } from './resolve-initial-context';
13
14
  export { extractContextIdFromPath, resolveContextFromPath } from './resolve-context-from-path';
15
+ export { parseContextItem } from './parse-context-item';
@@ -4,7 +4,7 @@ import type {
4
4
  } from '@equinor/fusion-framework-module-services/context';
5
5
  import type { GetContextResponse } from '@equinor/fusion-framework-module-services/context/get';
6
6
 
7
- import type { ContextItem, ContextItemType } from './types';
7
+ import type { ContextItem, ContextItemType } from '../types';
8
8
 
9
9
  /**
10
10
  * Parses the context type from the response of the GetContext API.
@@ -1,6 +1,6 @@
1
1
  import type { ModulesInstance } from '@equinor/fusion-framework-module';
2
2
  import type { ContextModule } from '../module';
3
- import type { ContextModuleConfig } from '../configurator';
3
+ import type { ContextModuleConfig } from '../ContextModuleConfig';
4
4
  import { concat, EMPTY, first, of } from 'rxjs';
5
5
  import resolveContextFromPath, { type ContextPathResolveArgs } from './resolve-context-from-path';
6
6
  import type { NavigationModule } from '@equinor/fusion-framework-module-navigation';
@@ -49,7 +49,10 @@ export const resolveInitialContext =
49
49
  return concat(
50
50
  pathname ? pathResolver(pathname) : EMPTY,
51
51
  resolveContextFromParent({ ref, modules }),
52
- ).pipe(first());
52
+ ).pipe(
53
+ // having no initial context is valid; a default avoids first() throwing EmptyError for it
54
+ first(undefined, undefined),
55
+ );
53
56
  };
54
57
 
55
58
  export default resolveInitialContext;
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '8.0.3';
2
+ export const version = '9.0.0-next.0';
package/tsconfig.json CHANGED
@@ -18,8 +18,14 @@
18
18
  {
19
19
  "path": "../event"
20
20
  },
21
+ {
22
+ "path": "../http"
23
+ },
21
24
  {
22
25
  "path": "../services"
26
+ },
27
+ {
28
+ "path": "../telemetry"
23
29
  }
24
30
  ],
25
31
  "include": ["src/**/*"],
@@ -0,0 +1,11 @@
1
+ import { defineProject } from 'vitest/config';
2
+
3
+ import { name, version } from './package.json' with { type: 'json' };
4
+
5
+ export default defineProject({
6
+ test: {
7
+ environment: 'node',
8
+ include: ['src/__tests__/**/*.test.ts'],
9
+ name: `${name}@${version}`,
10
+ },
11
+ });
@@ -1,175 +0,0 @@
1
- /**
2
- * A builder class for configuring and customizing context module behavior within the Fusion Framework.
3
- *
4
- * `ContextConfigBuilder` provides a fluent API for setting up various aspects of context management,
5
- * including context type, filtering, parent context connection, parameter resolution, validation,
6
- * path extraction/generation, and client configuration for fetching context items.
7
- *
8
- * @typeParam TModules - An array of modules that extend `AnyModule`. Defaults to an empty array.
9
- * @typeParam TInit - The initializer arguments for the module, extending `ModuleInitializerArgs`.
10
- *
11
- * @example
12
- * ```typescript
13
- * const builder = new ContextConfigBuilder(init);
14
- * builder.setContextType(['ProjectMaster']);
15
- * builder.setContextFilter(items => items.filter(ctx => ctx.isActive));
16
- * builder.setContextClient({ get: fetchContextItem, query: fetchContextItems });
17
- * ```
18
- *
19
- * @remarks
20
- * - Use the provided setter methods to customize context behavior as needed.
21
- * - The builder pattern allows chaining configuration methods for clarity and convenience.
22
- * - The `requireInstance` method enables asynchronous retrieval of module instances by name.
23
- *
24
- * @todo(#5120) - this should extend the BaseConfigBuilder
25
- *
26
- * @see ContextModuleConfig
27
- * @see ModuleInitializerArgs
28
- */
29
- export class ContextConfigBuilder {
30
- config;
31
- #init;
32
- /**
33
- * Creates a new `ContextConfigBuilder`.
34
- * @param init - Module initializer arguments used to resolve module instances.
35
- * @param config - The partial context module config to build upon.
36
- */
37
- constructor(init, config = {}) {
38
- this.config = config;
39
- this.#init = init;
40
- }
41
- /**
42
- * Requires a module instance by key or name.
43
- * @param module - The key or name of the module to resolve.
44
- * @returns A promise that resolves to the requested module instance.
45
- */
46
- requireInstance(module) {
47
- return this.#init.requireInstance(module);
48
- }
49
- /**
50
- * Sets the context type for the current configuration.
51
- *
52
- * @param type - The context type to assign, as defined by `ContextModuleConfig['contextType']`.
53
- */
54
- setContextType(type) {
55
- this.config.contextType = type;
56
- }
57
- /**
58
- * Sets the context filter function for the configuration.
59
- *
60
- * @param filter - A function that determines whether a context should be included, as defined by `ContextModuleConfig['contextFilter']`.
61
- */
62
- setContextFilter(filter) {
63
- this.config.contextFilter = filter;
64
- }
65
- /**
66
- * Sets the function or configuration used to connect to a parent context.
67
- *
68
- * @param connect - The function or configuration that defines how to connect to the parent context.
69
- */
70
- connectParentContext(connect) {
71
- this.config.connectParentContext = connect;
72
- }
73
- /**
74
- * Sets the function used to provide context parameters for the module configuration.
75
- *
76
- * @param fn - A function conforming to the `contextParameterFn` type defined in `ContextModuleConfig`.
77
- */
78
- setContextParameterFn(fn) {
79
- this.config.contextParameterFn = fn;
80
- }
81
- /**
82
- * Sets the function used to validate the context within the configuration.
83
- *
84
- * @param fn - A function that implements the `validateContext` signature from `ContextModuleConfig`.
85
- */
86
- setValidateContext(fn) {
87
- this.config.validateContext = fn;
88
- }
89
- /**
90
- * Sets the function used to resolve the context for the module configuration.
91
- *
92
- * @param fn - A function that defines how the context should be resolved, conforming to the `resolveContext` type from `ContextModuleConfig`.
93
- */
94
- setResolveContext(fn) {
95
- this.config.resolveContext = fn;
96
- }
97
- /**
98
- * Sets the function responsible for extracting the context ID from a given path.
99
- *
100
- * @param fn - A function that defines how to extract the context ID from a path.
101
- * This function should match the type defined in `ContextModuleConfig['extractContextIdFromPath']`.
102
- */
103
- setContextPathExtractor(fn) {
104
- this.config.extractContextIdFromPath = fn;
105
- }
106
- /**
107
- * Sets the function responsible for generating a path from the context.
108
- *
109
- * @param fn - A function that takes a context and generates a corresponding path.
110
- */
111
- setContextPathGenerator(fn) {
112
- this.config.generatePathFromContext = fn;
113
- }
114
- /**
115
- * Sets the function used to resolve the initial context during module post-initialization.
116
- *
117
- * @param fn - A function that returns an observable input emitting the initial context item.
118
- * The default resolver extracts a context ID from the navigation path, falling
119
- * back to the parent provider's current context.
120
- */
121
- setResolveInitialContext(fn) {
122
- this.config.resolveInitialContext = fn;
123
- }
124
- /**
125
- * Sets the context client configuration for fetching context items.
126
- *
127
- * This method allows you to provide custom query functions or query constructor options
128
- * for retrieving single context items (`get`), querying multiple context items (`query`),
129
- * and optionally fetching related context items (`related`). Each query can be provided
130
- * as either a function or a configuration object. The expiration time for cached results
131
- * can also be specified.
132
- *
133
- * @param client - An object containing the query functions or options for `get`, `query`, and optionally `related` context items.
134
- * @param expire - Optional. The expiration time (in milliseconds) for cached query results. Defaults to 1 minute.
135
- */
136
- setContextClient(client, expire = 1 * 60 * 1000) {
137
- const clientConfig = {
138
- get: typeof client.get === 'function'
139
- ? {
140
- key: ({ id }) => id,
141
- client: {
142
- fn: client.get,
143
- },
144
- expire,
145
- }
146
- : client.get,
147
- query: typeof client.query === 'function'
148
- ? {
149
- // TODO(#5118) - might cast to checksum
150
- key: (args) => JSON.stringify(args),
151
- client: {
152
- fn: client.query,
153
- },
154
- expire,
155
- }
156
- : client.query,
157
- };
158
- this.config.client = clientConfig;
159
- // only override the related-context client config if one was provided
160
- if (client.related) {
161
- clientConfig.related =
162
- typeof client.related === 'function'
163
- ? {
164
- // TODO(#5118) - might cast to checksum
165
- key: (args) => JSON.stringify(args),
166
- client: {
167
- fn: client.related,
168
- },
169
- expire,
170
- }
171
- : client.related;
172
- }
173
- }
174
- }
175
- //# sourceMappingURL=ContextConfigBuilder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ContextConfigBuilder.js","sourceRoot":"","sources":["../../src/ContextConfigBuilder.ts"],"names":[],"mappings":"AA+BA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,OAAO,oBAAoB;IAgBtB,MAAM;IARf,KAAK,CAAQ;IACb;;;;OAIG;IACH,YACE,IAAW,EACJ,MAAM,GAAiC,EAAE;sBAAzC,MAAM;QAEb,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAkBD;;;;OAIG;IACH,eAAe,CACb,MAAc;QAGd,OAAO,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;IAC5C,CAAC;IAED;;;;OAIG;IACH,cAAc,CAAC,IAAwC;QACrD,IAAI,CAAC,MAAM,CAAC,WA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;oBACD,MAAM;iBACP;gBACH,CAAC,CAAC,MAAM,CAAC,GAAG;YAChB,KAAK,EACH,OAAO,MAAM,CAAC,KAAK,KAAK,UAAU;gBAChC,CAAC,CAAC;oBACE,uCAAuC;oBACvC,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;oBACnC,MAAM,EAAE;wBACN,EAAE,EAAE,MAAM,CAAC,KAAK;qBACjB;oBACD,MAAM;iBACP;gBACH,CAAC,CAAC,MAAM,CAAC,KAAK;SACnB,CAAC;QACF,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,YAAY,CAAC;QAClC,sEAAsE;QACtE,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,YAAY,CAAC,OAAO;gBAClB,OAAO,MAAM,CAAC,OAAO,KAAK,UAAU;oBAClC,CAAC,CAAC;wBACE,uCAAuC;wBACvC,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;wBACnC,MAAM,EAAE;4BACN,EAAE,EAAE,MAAM,CAAC,OAAO;yBACnB;wBACD,MAAM;qBACP;oBACH,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;QACvB,CAAC;IACH,CAAC;CACF"}
@@ -1,104 +0,0 @@
1
- import { getContextSelector, queryContextSelector, relatedContextSelector, } from './get-context-selector';
2
- import { ContextConfigBuilder } from './ContextConfigBuilder';
3
- import resolveInitialContext from './utils/resolve-initial-context';
4
- /**
5
- * Default implementation of {@link IContextModuleConfigurator}.
6
- *
7
- * Collects {@link ContextConfigBuilderCallback} registrations and, when
8
- * {@link createConfig} is called, runs them in order against a
9
- * {@link ContextConfigBuilder} to produce the final {@link ContextModuleConfig}.
10
- *
11
- * If no custom client is configured, the configurator falls back to
12
- * creating one from the {@link ServicesModule} API provider.
13
- */
14
- export class ContextModuleConfigurator {
15
- /** Default cache TTL (in ms) for context query results. */
16
- defaultExpireTime = 1 * 60 * 1000;
17
- #configBuilders = [];
18
- /** @inheritdoc */
19
- addConfigBuilder(init) {
20
- this.#configBuilders.push(init);
21
- }
22
- /**
23
- * Resolves the services API provider, preferring the local module
24
- * instance and falling back to the parent module.
25
- *
26
- * @param init - Module initializer arguments.
27
- * @returns The resolved API provider.
28
- * @throws Error if no services module is available.
29
- */
30
- async _getServiceProvider(init) {
31
- // prefer the local services module instance if available
32
- if (init.hasModule('services')) {
33
- return init.requireInstance('services');
34
- }
35
- const parentServiceModule = init.ref?.services;
36
- // fall back to the parent module's services instance
37
- if (!parentServiceModule) {
38
- throw Error('no service services provider configures [ServicesModule]');
39
- }
40
- return parentServiceModule;
41
- }
42
- /**
43
- * Runs all registered config builders and produces the final
44
- * {@link ContextModuleConfig}.
45
- *
46
- * If no `resolveInitialContext` was set, the default path + parent
47
- * resolver is used. If no `client` was set, one is created from the
48
- * {@link ServicesModule} API provider.
49
- *
50
- * @param init - Module initializer arguments including dependency instances.
51
- * @returns The fully resolved context module configuration.
52
- */
53
- async createConfig(init) {
54
- // run each registered config builder in sequence, merging results into the accumulated config
55
- const config = await this.#configBuilders.reduce(async (cur, cb) => {
56
- // biome-ignore lint/suspicious/noExplicitAny: builder generics are erased here — `unknown` breaks assignability of the concrete `ContextConfigBuilder` instance passed to consumer callbacks
57
- const builder = new ContextConfigBuilder(init, await cur);
58
- await Promise.resolve(cb(builder));
59
- // Merge this builder's config into the accumulator for the next iteration.
60
- return Object.assign(cur, builder.config);
61
- }, Promise.resolve({}));
62
- config.resolveInitialContext ??= resolveInitialContext({
63
- path: {
64
- extract: config.extractContextIdFromPath,
65
- validate: config.extractContextIdFromPath ? () => true : undefined,
66
- },
67
- });
68
- // TODO(#5119) - make less lazy
69
- config.client ??= await (async () => {
70
- const apiProvider = await this._getServiceProvider(init);
71
- const contextClient = await apiProvider.createContextClient('json$');
72
- return {
73
- get: {
74
- client: {
75
- fn: (args) => contextClient.get('v1', args, { selector: getContextSelector }),
76
- },
77
- key: ({ id }) => id,
78
- expire: this.defaultExpireTime,
79
- },
80
- query: {
81
- client: {
82
- fn: (query) => contextClient.query('v1', { query }, { selector: queryContextSelector }),
83
- },
84
- // TODO(#5118) - might cast to checksum
85
- key: (args) => JSON.stringify(args),
86
- expire: this.defaultExpireTime,
87
- },
88
- related: {
89
- client: {
90
- fn: (args) => {
91
- return contextClient.related('v1', { id: args.item.id, query: { filter: args.filter } }, { selector: relatedContextSelector });
92
- },
93
- },
94
- // TODO(#5118) - might cast to checksum
95
- key: (args) => JSON.stringify(args),
96
- expire: this.defaultExpireTime,
97
- },
98
- };
99
- })();
100
- return config;
101
- }
102
- }
103
- export default ContextModuleConfigurator;
104
- //# sourceMappingURL=configurator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"configurator.js","sourceRoot":"","sources":["../../src/configurator.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAShC,OAAO,EAAE,oBAAoB,EAAqC,MAAM,wBAAwB,CAAC;AAEjG,OAAO,qBAAqB,MAAM,iCAAiC,CAAC;AA4JpE;;;;;;;;;GASG;AACH,MAAM,OAAO,yBAAyB;IACpC,2DAA2D;IAC3D,iBAAiB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;IAElC,eAAe,GAAwC,EAAE,CAAC;IAE1D,kBAAkB;IAClB,gBAAgB,CAAC,IAAkC;QACjD,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAED;;;;;;;OAOG;IACO,KAAK,CAAC,mBAAmB,CACjC,IAAyE;QAEzE,yDAAyD;QACzD,IAAI,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC;YAC/B,OAAO,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;QAC1C,CAAC;QACD,MAAM,mBAAmB,GAAI,IAAI,CAAC,GAA6C,EAAE,QAAQ,CAA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AAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"query-context-selector.js","sourceRoot":"","sources":["../../src/query-context-selector.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAGxD;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,EAAE,QAAkB,EAA0B,EAAE;IACvF,MAAM,MAAM,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAA+B,CAAC;IACrE,8CAA8C;IAC9C,OAAO,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;AACtC,CAAC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"related-context-selector.js","sourceRoot":"","sources":["../../src/related-context-selector.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAGxD;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,EAAE,QAAkB,EAA0B,EAAE;IACzF,MAAM,MAAM,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAiC,CAAC;IACvE,8CAA8C;IAC9C,OAAO,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;AACtC,CAAC,CAAC"}