@crossplane-org/function-sdk-typescript 0.1.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 (51) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +683 -0
  3. package/dist/example-function.d.ts +11 -0
  4. package/dist/example-function.d.ts.map +1 -0
  5. package/dist/example-function.js +93 -0
  6. package/dist/example-function.js.map +1 -0
  7. package/dist/function/function.d.ts +115 -0
  8. package/dist/function/function.d.ts.map +1 -0
  9. package/dist/function/function.js +111 -0
  10. package/dist/function/function.js.map +1 -0
  11. package/dist/index.d.ts +9 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +13 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/main.d.ts +3 -0
  16. package/dist/main.d.ts.map +1 -0
  17. package/dist/main.js +69 -0
  18. package/dist/main.js.map +1 -0
  19. package/dist/proto/google/protobuf/duration.d.ts +107 -0
  20. package/dist/proto/google/protobuf/duration.d.ts.map +1 -0
  21. package/dist/proto/google/protobuf/duration.js +90 -0
  22. package/dist/proto/google/protobuf/duration.js.map +1 -0
  23. package/dist/proto/google/protobuf/struct.d.ts +115 -0
  24. package/dist/proto/google/protobuf/struct.d.ts.map +1 -0
  25. package/dist/proto/google/protobuf/struct.js +452 -0
  26. package/dist/proto/google/protobuf/struct.js.map +1 -0
  27. package/dist/proto/run_function.d.ts +494 -0
  28. package/dist/proto/run_function.d.ts.map +1 -0
  29. package/dist/proto/run_function.js +2230 -0
  30. package/dist/proto/run_function.js.map +1 -0
  31. package/dist/request/request.d.ts +198 -0
  32. package/dist/request/request.d.ts.map +1 -0
  33. package/dist/request/request.js +219 -0
  34. package/dist/request/request.js.map +1 -0
  35. package/dist/resource/resource.d.ts +101 -0
  36. package/dist/resource/resource.d.ts.map +1 -0
  37. package/dist/resource/resource.js +98 -0
  38. package/dist/resource/resource.js.map +1 -0
  39. package/dist/response/response.d.ts +273 -0
  40. package/dist/response/response.d.ts.map +1 -0
  41. package/dist/response/response.js +339 -0
  42. package/dist/response/response.js.map +1 -0
  43. package/dist/runtime/runtime.d.ts +121 -0
  44. package/dist/runtime/runtime.d.ts.map +1 -0
  45. package/dist/runtime/runtime.js +124 -0
  46. package/dist/runtime/runtime.js.map +1 -0
  47. package/dist/vitest.config.d.ts +3 -0
  48. package/dist/vitest.config.d.ts.map +1 -0
  49. package/dist/vitest.config.js +17 -0
  50. package/dist/vitest.config.js.map +1 -0
  51. package/package.json +55 -0
@@ -0,0 +1,101 @@
1
+ import { Resource, Ready } from "../proto/run_function.js";
2
+ export type ConnectionDetails = {
3
+ [key: string]: Buffer;
4
+ };
5
+ /**
6
+ * Composite represents a Crossplane composite resource (XR) with its state
7
+ */
8
+ export interface Composite {
9
+ resource: Resource;
10
+ connectionDetails: ConnectionDetails;
11
+ ready: Ready;
12
+ }
13
+ /**
14
+ * ObservedComposed represents the observed state of a composed resource
15
+ */
16
+ export interface ObservedComposed {
17
+ resource: Resource;
18
+ connectionDetails: ConnectionDetails;
19
+ }
20
+ /**
21
+ * DesiredComposed represents the desired state of a composed resource
22
+ */
23
+ export interface DesiredComposed {
24
+ resource: Resource;
25
+ ready: Ready;
26
+ }
27
+ /**
28
+ * Create a new empty DesiredComposed resource
29
+ */
30
+ export declare function newDesiredComposed(): DesiredComposed;
31
+ /**
32
+ * Convert a protobuf Struct to a Kubernetes object (plain JavaScript object)
33
+ * This is a more efficient conversion that avoids JSON round-trips when possible
34
+ *
35
+ * @param struct - The protobuf Struct to convert
36
+ * @returns A plain JavaScript object representing the Kubernetes resource
37
+ */
38
+ export declare function asObject(struct: {
39
+ [key: string]: any;
40
+ } | undefined): {
41
+ [key: string]: any;
42
+ };
43
+ /**
44
+ * Convert a Kubernetes object to a protobuf Struct
45
+ * This is used when creating Resource objects from plain JavaScript objects
46
+ *
47
+ * @param obj - The plain JavaScript object to convert
48
+ * @returns A protobuf Struct representation
49
+ */
50
+ export declare function asStruct(obj: {
51
+ [key: string]: any;
52
+ }): {
53
+ [key: string]: any;
54
+ };
55
+ /**
56
+ * Helper function for tests: Convert an object to a Struct, panics on failure
57
+ * Only use this in test code
58
+ *
59
+ * @param obj - The object to convert
60
+ * @returns A Struct representation
61
+ * @throws Error if conversion fails
62
+ */
63
+ export declare function mustStructObject(obj: {
64
+ [key: string]: any;
65
+ }): {
66
+ [key: string]: any;
67
+ };
68
+ /**
69
+ * Helper function for tests: Parse a JSON string into a Struct, panics on failure
70
+ * Only use this in test code
71
+ *
72
+ * @param json - The JSON string to parse
73
+ * @returns A Struct representation
74
+ * @throws Error if parsing or conversion fails
75
+ */
76
+ export declare function mustStructJSON(json: string): {
77
+ [key: string]: any;
78
+ };
79
+ /**
80
+ * Create a Resource from a plain JavaScript object
81
+ * This is a convenience wrapper around Resource.fromJSON
82
+ *
83
+ * @param obj - The resource object
84
+ * @param connectionDetails - Optional connection details
85
+ * @param ready - Optional ready status
86
+ * @returns A Resource
87
+ */
88
+ export declare function fromObject(obj: {
89
+ [key: string]: any;
90
+ }, connectionDetails?: ConnectionDetails, ready?: Ready): Resource;
91
+ /**
92
+ * Get the resource object from a Resource
93
+ * This extracts the plain JavaScript object from the Resource wrapper
94
+ *
95
+ * @param resource - The Resource to extract from
96
+ * @returns The plain JavaScript object, or undefined if not present
97
+ */
98
+ export declare function toObject(resource: Resource): {
99
+ [key: string]: any;
100
+ } | undefined;
101
+ //# sourceMappingURL=resource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../src/resource/resource.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAG3D,MAAM,MAAM,iBAAiB,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,SAAS;IACtB,QAAQ,EAAE,QAAQ,CAAC;IACnB,iBAAiB,EAAE,iBAAiB,CAA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E,QAAQ,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,GAAG,SAAS,CAE/E"}
@@ -0,0 +1,98 @@
1
+ // Resource utilities for working with Kubernetes resources and protobuf conversion
2
+ import { Resource, Ready } from "../proto/run_function.js";
3
+ /**
4
+ * Create a new empty DesiredComposed resource
5
+ */
6
+ export function newDesiredComposed() {
7
+ return {
8
+ resource: Resource.fromJSON({}),
9
+ ready: Ready.READY_UNSPECIFIED,
10
+ };
11
+ }
12
+ /**
13
+ * Convert a protobuf Struct to a Kubernetes object (plain JavaScript object)
14
+ * This is a more efficient conversion that avoids JSON round-trips when possible
15
+ *
16
+ * @param struct - The protobuf Struct to convert
17
+ * @returns A plain JavaScript object representing the Kubernetes resource
18
+ */
19
+ export function asObject(struct) {
20
+ if (!struct) {
21
+ return {};
22
+ }
23
+ // The struct is already a plain object in our TypeScript implementation
24
+ // In the Go SDK, this does actual protobuf conversion
25
+ return struct;
26
+ }
27
+ /**
28
+ * Convert a Kubernetes object to a protobuf Struct
29
+ * This is used when creating Resource objects from plain JavaScript objects
30
+ *
31
+ * @param obj - The plain JavaScript object to convert
32
+ * @returns A protobuf Struct representation
33
+ */
34
+ export function asStruct(obj) {
35
+ // In our TypeScript implementation, this is essentially a pass-through
36
+ // The actual conversion happens in the protobuf serialization layer
37
+ return obj;
38
+ }
39
+ /**
40
+ * Helper function for tests: Convert an object to a Struct, panics on failure
41
+ * Only use this in test code
42
+ *
43
+ * @param obj - The object to convert
44
+ * @returns A Struct representation
45
+ * @throws Error if conversion fails
46
+ */
47
+ export function mustStructObject(obj) {
48
+ try {
49
+ return asStruct(obj);
50
+ }
51
+ catch (error) {
52
+ throw new Error(`Failed to convert object to struct: ${error instanceof Error ? error.message : String(error)}`);
53
+ }
54
+ }
55
+ /**
56
+ * Helper function for tests: Parse a JSON string into a Struct, panics on failure
57
+ * Only use this in test code
58
+ *
59
+ * @param json - The JSON string to parse
60
+ * @returns A Struct representation
61
+ * @throws Error if parsing or conversion fails
62
+ */
63
+ export function mustStructJSON(json) {
64
+ try {
65
+ const obj = JSON.parse(json);
66
+ return asStruct(obj);
67
+ }
68
+ catch (error) {
69
+ throw new Error(`Failed to parse JSON to struct: ${error instanceof Error ? error.message : String(error)}`);
70
+ }
71
+ }
72
+ /**
73
+ * Create a Resource from a plain JavaScript object
74
+ * This is a convenience wrapper around Resource.fromJSON
75
+ *
76
+ * @param obj - The resource object
77
+ * @param connectionDetails - Optional connection details
78
+ * @param ready - Optional ready status
79
+ * @returns A Resource
80
+ */
81
+ export function fromObject(obj, connectionDetails, ready) {
82
+ return Resource.fromJSON({
83
+ resource: obj,
84
+ connectionDetails: connectionDetails || {},
85
+ ready: ready !== undefined ? ready : Ready.READY_UNSPECIFIED,
86
+ });
87
+ }
88
+ /**
89
+ * Get the resource object from a Resource
90
+ * This extracts the plain JavaScript object from the Resource wrapper
91
+ *
92
+ * @param resource - The Resource to extract from
93
+ * @returns The plain JavaScript object, or undefined if not present
94
+ */
95
+ export function toObject(resource) {
96
+ return resource.resource;
97
+ }
98
+ //# sourceMappingURL=resource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource.js","sourceRoot":"","sources":["../../src/resource/resource.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AA8B3D;;GAEG;AACH,MAAM,UAAU,kBAAkB;IAC9B,OAAO;QACH,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC/B,KAAK,EAAE,KAAK,CAAC,iBAAiB;KACjC,CAAC;AACN,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CAAC,MAA0C;IAC/D,IAAI,CAAC,MAAM,EAAE,CAAC;QACV,OAAO,EAAE,CAAC;IACd,CAAC;IAED,wEAAwE;IACxE,sDAAsD;IACtD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;;;;;GAM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AQ,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,273 @@
1
+ /**
2
+ * Response utilities for working with RunFunctionResponse
3
+ *
4
+ * This module provides helper functions to build and manipulate RunFunctionResponse objects,
5
+ * including setting desired state, managing results, handling context, and working with
6
+ * composite resources and their status.
7
+ */
8
+ import { Resource, RunFunctionRequest, RunFunctionResponse, Ready } from "../proto/run_function.js";
9
+ import { Duration } from "../proto/google/protobuf/duration.js";
10
+ /**
11
+ * Default time-to-live for function responses (60 seconds).
12
+ * Crossplane will call the function again when the TTL expires.
13
+ */
14
+ declare const DEFAULT_TTL: Duration;
15
+ export { DEFAULT_TTL };
16
+ /**
17
+ * Bootstrap a response from a request.
18
+ *
19
+ * This function creates a new RunFunctionResponse with the request's tag automatically
20
+ * copied, and initializes the desired state from the request. Using this function is
21
+ * the recommended pattern to ensure proper response initialization.
22
+ *
23
+ * The response will:
24
+ * - Copy the request's tag to the response metadata
25
+ * - Initialize the desired state from the request (or create empty if not present)
26
+ * - Set the TTL (time-to-live) for caching
27
+ * - Initialize empty results and conditions arrays
28
+ *
29
+ * @param req - The RunFunctionRequest to bootstrap from
30
+ * @param ttl - Optional time-to-live duration (defaults to 60 seconds)
31
+ * @returns A new RunFunctionResponse initialized from the request
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * async RunFunction(req: RunFunctionRequest): Promise<RunFunctionResponse> {
36
+ * let rsp = to(req);
37
+ * // Add your logic here
38
+ * normal(rsp, "Processing complete");
39
+ * return rsp;
40
+ * }
41
+ * ```
42
+ */
43
+ export declare function to(req: RunFunctionRequest, ttl?: Duration): RunFunctionResponse;
44
+ type NamedResource = {
45
+ name: string;
46
+ resource: Resource;
47
+ };
48
+ /**
49
+ * Update a map of desired composed resources by adding or updating a named resource.
50
+ *
51
+ * This is a helper function to add a single resource to a map of composed resources.
52
+ * It's useful when building up desired resources before calling setDesiredComposedResources.
53
+ *
54
+ * @param cds - The current map of composed resources
55
+ * @param res - The named resource to add or update
56
+ * @returns The updated map of composed resources
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * let dcds = getDesiredComposedResources(req);
61
+ * dcds = updateDesiredComposedResources(dcds, {
62
+ * name: "my-bucket",
63
+ * resource: Resource.fromJSON({ resource: bucketConfig })
64
+ * });
65
+ * rsp = setDesiredComposedResources(rsp, dcds);
66
+ * ```
67
+ */
68
+ export declare function updateDesiredComposedResources(cds: {
69
+ [key: string]: Resource;
70
+ }, res: NamedResource): {
71
+ [key: string]: Resource;
72
+ };
73
+ /**
74
+ * Add a fatal result to the response.
75
+ *
76
+ * Fatal results cause the function pipeline run to be considered a failure.
77
+ * Subsequent functions may still run, but the first fatal result will be
78
+ * returned as an error. Fatal results should be used for errors that prevent
79
+ * the function from producing valid output.
80
+ *
81
+ * @param rsp - The RunFunctionResponse to add the result to
82
+ * @param message - The error message describing the fatal condition
83
+ * @returns The updated response
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * if (!requiredInput) {
88
+ * fatal(rsp, "Required input 'databaseSize' not provided");
89
+ * return rsp;
90
+ * }
91
+ * ```
92
+ */
93
+ export declare function fatal(rsp: RunFunctionResponse, message: string): RunFunctionResponse;
94
+ /**
95
+ * Add a normal result to the response.
96
+ *
97
+ * Normal results are informational and emitted as normal events and debug logs
98
+ * associated with the composite resource (XR) or operation. They indicate
99
+ * successful processing or expected conditions.
100
+ *
101
+ * @param rsp - The RunFunctionResponse to add the result to
102
+ * @param message - The informational message
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * normal(rsp, "Successfully configured 3 database replicas");
107
+ * ```
108
+ */
109
+ export declare function normal(rsp: RunFunctionResponse, message: string): void;
110
+ /**
111
+ * Add a warning result to the response.
112
+ *
113
+ * Warning results are non-fatal issues that should be brought to attention.
114
+ * The entire pipeline will run to completion, but warning events and debug logs
115
+ * will be emitted. Use warnings for recoverable issues or deprecated usage.
116
+ *
117
+ * @param rsp - The RunFunctionResponse to add the result to
118
+ * @param message - The warning message
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * if (input.legacyFormat) {
123
+ * warning(rsp, "Using deprecated input format, please migrate to new format");
124
+ * }
125
+ * ```
126
+ */
127
+ export declare function warning(rsp: RunFunctionResponse, message: string): void;
128
+ /**
129
+ * Set the desired composed resources in the response.
130
+ *
131
+ * This function sets or merges the desired composed resources in the response.
132
+ * It uses deep merge to combine new resources with any existing resources,
133
+ * allowing functions to add or modify resources while preserving those set
134
+ * by previous functions in the pipeline.
135
+ *
136
+ * If the desired state or resources map don't exist, they will be initialized.
137
+ *
138
+ * @param rsp - The RunFunctionResponse to update
139
+ * @param dcds - A map of resource names to Resource objects to set as desired
140
+ * @returns The updated response
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * const dcds = getDesiredComposedResources(req);
145
+ * dcds["my-deployment"] = Resource.fromJSON({
146
+ * resource: { apiVersion: "apps/v1", kind: "Deployment", ... }
147
+ * });
148
+ * rsp = setDesiredComposedResources(rsp, dcds);
149
+ * ```
150
+ */
151
+ export declare function setDesiredComposedResources(rsp: RunFunctionResponse, dcds: {
152
+ [key: string]: Resource;
153
+ }): RunFunctionResponse;
154
+ /**
155
+ * Update a resource by merging source into target.
156
+ *
157
+ * This function performs a deep merge of the source resource into the target resource,
158
+ * allowing you to update specific fields while preserving others. The merge is performed
159
+ * using the ts-deepmerge library.
160
+ *
161
+ * @param src - The source Resource containing updates
162
+ * @param tgt - The target Resource to be updated
163
+ * @returns A new Resource with merged values
164
+ *
165
+ * @example
166
+ * ```typescript
167
+ * const existing = getDesiredComposedResources(req)["my-resource"];
168
+ * const updated = update(
169
+ * Resource.fromJSON({ resource: { spec: { replicas: 5 } } }),
170
+ * existing
171
+ * );
172
+ * ```
173
+ */
174
+ export declare function update(src: Resource, tgt: Resource): Resource;
175
+ /**
176
+ * Set the desired composite resource status.
177
+ *
178
+ * This function updates only the status field of the desired composite resource.
179
+ * It merges the provided status with any existing status, allowing partial updates.
180
+ * Note that functions should only set the status of composite resources (XRs),
181
+ * not their metadata or spec.
182
+ *
183
+ * @param params - Object containing the response and status to set
184
+ * @param params.rsp - The RunFunctionResponse to update
185
+ * @param params.status - The status object to merge into the composite resource
186
+ * @returns The updated response
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * rsp = setDesiredCompositeStatus({
191
+ * rsp,
192
+ * status: {
193
+ * phase: "Ready",
194
+ * conditions: [{ type: "Synced", status: "True" }]
195
+ * }
196
+ * });
197
+ * ```
198
+ */
199
+ export declare function setDesiredCompositeStatus({ rsp, status }: {
200
+ rsp: RunFunctionResponse;
201
+ status: {
202
+ [key: string]: any;
203
+ };
204
+ }): RunFunctionResponse;
205
+ /**
206
+ * Set a context key in the response.
207
+ *
208
+ * Context allows functions to pass arbitrary data to subsequent functions in the
209
+ * pipeline. The context is initialized if it doesn't exist. Crossplane discards
210
+ * all context returned by the last function in the pipeline.
211
+ *
212
+ * @param rsp - The RunFunctionResponse to update
213
+ * @param key - The context key to set
214
+ * @param value - The value to associate with the key (can be any JSON-serializable value)
215
+ * @returns The updated response
216
+ *
217
+ * @example
218
+ * ```typescript
219
+ * // Set context for next function in pipeline
220
+ * rsp = setContextKey(rsp, "database-endpoint", "db.example.com:5432");
221
+ * rsp = setContextKey(rsp, "connection-config", { host: "db.example.com", port: 5432 });
222
+ * ```
223
+ */
224
+ export declare function setContextKey(rsp: RunFunctionResponse, key: string, value: any): RunFunctionResponse;
225
+ /**
226
+ * Set the desired composite resource in the response.
227
+ *
228
+ * This function sets the entire desired composite resource and optionally its ready status.
229
+ * The ready status can be used to override Crossplane's standard readiness detection,
230
+ * which normally determines the composite's ready state based on composed resources.
231
+ *
232
+ * Note: Ready status is only used for composition functions, not operations.
233
+ *
234
+ * @param rsp - The RunFunctionResponse to update
235
+ * @param resource - The desired composite resource to set
236
+ * @param ready - Optional ready status (READY_TRUE, READY_FALSE, or READY_UNSPECIFIED)
237
+ * @returns The updated response
238
+ *
239
+ * @example
240
+ * ```typescript
241
+ * const composite = getObservedCompositeResource(req);
242
+ * if (composite) {
243
+ * // Modify and set as desired with ready status
244
+ * rsp = setDesiredCompositeResource(rsp, composite, Ready.READY_TRUE);
245
+ * }
246
+ * ```
247
+ */
248
+ export declare function setDesiredCompositeResource(rsp: RunFunctionResponse, resource: Resource, ready?: Ready): RunFunctionResponse;
249
+ /**
250
+ * Set the function output in the response.
251
+ *
252
+ * Function output is specific to operation functions. The output must be a
253
+ * JSON-serializable object. Composite resources (XRs) will discard any function
254
+ * output, as it's only used by operations.
255
+ *
256
+ * @param rsp - The RunFunctionResponse to update
257
+ * @param output - The output object to set (must be JSON-serializable)
258
+ * @returns The updated response
259
+ *
260
+ * @example
261
+ * ```typescript
262
+ * // For operation functions
263
+ * rsp = setOutput(rsp, {
264
+ * resourcesCreated: 5,
265
+ * status: "success",
266
+ * details: { timestamp: new Date().toISOString() }
267
+ * });
268
+ * ```
269
+ */
270
+ export declare function setOutput(rsp: RunFunctionResponse, output: {
271
+ [key: string]: any;
272
+ }): RunFunctionResponse;
273
+ //# sourceMappingURL=response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../src/response/response.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,QAAQ,EACR,kBAAkB,EAClB,mBAAmB,EAEnB,KAAK,EACN,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,sCAAsC,CAAC;AAGhE;;;GAGG;AACH,QAAA,MAAM,WAAW,EAAE,QAAoC,CAAC;AAExD,OAAO,EAAE,WAAW,EAAE,CAAC;AAEvB;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,EAAE,CAAC,GAAG,EAAE,kBAAkB,EAAE,GAAG,CAAC,EAAE,QAAQ,GAAG,mBAAmB,CAsB/E;AAED,KAAK,aAAa,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,QAAQ,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wB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